Commit | Line | Data |
---|---|---|
5e3dd157 KV |
1 | /* |
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 | ||
8cd13cad | 23 | #include "hif.h" |
5e3dd157 KV |
24 | #include "core.h" |
25 | #include "debug.h" | |
26 | #include "wmi.h" | |
27 | #include "htt.h" | |
28 | #include "txrx.h" | |
43d2a30f | 29 | #include "testmode.h" |
d7579d12 MK |
30 | #include "wmi.h" |
31 | #include "wmi-ops.h" | |
5e3dd157 KV |
32 | |
33 | /**********/ | |
34 | /* Crypto */ | |
35 | /**********/ | |
36 | ||
37 | static int ath10k_send_key(struct ath10k_vif *arvif, | |
38 | struct ieee80211_key_conf *key, | |
39 | enum set_key_cmd cmd, | |
370e5673 | 40 | const u8 *macaddr, u32 flags) |
5e3dd157 | 41 | { |
7aa7a72a | 42 | struct ath10k *ar = arvif->ar; |
5e3dd157 KV |
43 | struct wmi_vdev_install_key_arg arg = { |
44 | .vdev_id = arvif->vdev_id, | |
45 | .key_idx = key->keyidx, | |
46 | .key_len = key->keylen, | |
47 | .key_data = key->key, | |
370e5673 | 48 | .key_flags = flags, |
5e3dd157 KV |
49 | .macaddr = macaddr, |
50 | }; | |
51 | ||
548db54c MK |
52 | lockdep_assert_held(&arvif->ar->conf_mutex); |
53 | ||
5e3dd157 KV |
54 | switch (key->cipher) { |
55 | case WLAN_CIPHER_SUITE_CCMP: | |
56 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
e4e82e9a | 57 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
5e3dd157 KV |
58 | break; |
59 | case WLAN_CIPHER_SUITE_TKIP: | |
5e3dd157 KV |
60 | arg.key_cipher = WMI_CIPHER_TKIP; |
61 | arg.key_txmic_len = 8; | |
62 | arg.key_rxmic_len = 8; | |
63 | break; | |
64 | case WLAN_CIPHER_SUITE_WEP40: | |
65 | case WLAN_CIPHER_SUITE_WEP104: | |
66 | arg.key_cipher = WMI_CIPHER_WEP; | |
5e3dd157 | 67 | break; |
3cb10943 | 68 | case WLAN_CIPHER_SUITE_AES_CMAC: |
d7131c04 BM |
69 | WARN_ON(1); |
70 | return -EINVAL; | |
5e3dd157 | 71 | default: |
7aa7a72a | 72 | ath10k_warn(ar, "cipher %d is not supported\n", key->cipher); |
5e3dd157 KV |
73 | return -EOPNOTSUPP; |
74 | } | |
75 | ||
76 | if (cmd == DISABLE_KEY) { | |
77 | arg.key_cipher = WMI_CIPHER_NONE; | |
78 | arg.key_data = NULL; | |
79 | } | |
80 | ||
81 | return ath10k_wmi_vdev_install_key(arvif->ar, &arg); | |
82 | } | |
83 | ||
84 | static int ath10k_install_key(struct ath10k_vif *arvif, | |
85 | struct ieee80211_key_conf *key, | |
86 | enum set_key_cmd cmd, | |
370e5673 | 87 | const u8 *macaddr, u32 flags) |
5e3dd157 KV |
88 | { |
89 | struct ath10k *ar = arvif->ar; | |
90 | int ret; | |
91 | ||
548db54c MK |
92 | lockdep_assert_held(&ar->conf_mutex); |
93 | ||
16735d02 | 94 | reinit_completion(&ar->install_key_done); |
5e3dd157 | 95 | |
370e5673 | 96 | ret = ath10k_send_key(arvif, key, cmd, macaddr, flags); |
5e3dd157 KV |
97 | if (ret) |
98 | return ret; | |
99 | ||
100 | ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ); | |
101 | if (ret == 0) | |
102 | return -ETIMEDOUT; | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
107 | static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif, | |
108 | const u8 *addr) | |
109 | { | |
110 | struct ath10k *ar = arvif->ar; | |
111 | struct ath10k_peer *peer; | |
112 | int ret; | |
113 | int i; | |
370e5673 | 114 | u32 flags; |
5e3dd157 KV |
115 | |
116 | lockdep_assert_held(&ar->conf_mutex); | |
117 | ||
118 | spin_lock_bh(&ar->data_lock); | |
119 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); | |
120 | spin_unlock_bh(&ar->data_lock); | |
121 | ||
122 | if (!peer) | |
123 | return -ENOENT; | |
124 | ||
125 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { | |
126 | if (arvif->wep_keys[i] == NULL) | |
127 | continue; | |
370e5673 MK |
128 | |
129 | flags = 0; | |
130 | flags |= WMI_KEY_PAIRWISE; | |
131 | ||
627613f8 SJ |
132 | /* set TX_USAGE flag for default key id */ |
133 | if (arvif->def_wep_key_idx == i) | |
370e5673 | 134 | flags |= WMI_KEY_TX_USAGE; |
5e3dd157 KV |
135 | |
136 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY, | |
370e5673 | 137 | addr, flags); |
5e3dd157 KV |
138 | if (ret) |
139 | return ret; | |
140 | ||
ae167131 | 141 | spin_lock_bh(&ar->data_lock); |
5e3dd157 | 142 | peer->keys[i] = arvif->wep_keys[i]; |
ae167131 | 143 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 KV |
144 | } |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | static int ath10k_clear_peer_keys(struct ath10k_vif *arvif, | |
150 | const u8 *addr) | |
151 | { | |
152 | struct ath10k *ar = arvif->ar; | |
153 | struct ath10k_peer *peer; | |
154 | int first_errno = 0; | |
155 | int ret; | |
156 | int i; | |
370e5673 | 157 | u32 flags = 0; |
5e3dd157 KV |
158 | |
159 | lockdep_assert_held(&ar->conf_mutex); | |
160 | ||
161 | spin_lock_bh(&ar->data_lock); | |
162 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); | |
163 | spin_unlock_bh(&ar->data_lock); | |
164 | ||
165 | if (!peer) | |
166 | return -ENOENT; | |
167 | ||
168 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
169 | if (peer->keys[i] == NULL) | |
170 | continue; | |
171 | ||
627613f8 | 172 | /* key flags are not required to delete the key */ |
5e3dd157 | 173 | ret = ath10k_install_key(arvif, peer->keys[i], |
370e5673 | 174 | DISABLE_KEY, addr, flags); |
5e3dd157 KV |
175 | if (ret && first_errno == 0) |
176 | first_errno = ret; | |
177 | ||
178 | if (ret) | |
7aa7a72a | 179 | ath10k_warn(ar, "failed to remove peer wep key %d: %d\n", |
5e3dd157 KV |
180 | i, ret); |
181 | ||
ae167131 | 182 | spin_lock_bh(&ar->data_lock); |
5e3dd157 | 183 | peer->keys[i] = NULL; |
ae167131 | 184 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 KV |
185 | } |
186 | ||
187 | return first_errno; | |
188 | } | |
189 | ||
504f6cdf SM |
190 | bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr, |
191 | u8 keyidx) | |
192 | { | |
193 | struct ath10k_peer *peer; | |
194 | int i; | |
195 | ||
196 | lockdep_assert_held(&ar->data_lock); | |
197 | ||
198 | /* We don't know which vdev this peer belongs to, | |
199 | * since WMI doesn't give us that information. | |
200 | * | |
201 | * FIXME: multi-bss needs to be handled. | |
202 | */ | |
203 | peer = ath10k_peer_find(ar, 0, addr); | |
204 | if (!peer) | |
205 | return false; | |
206 | ||
207 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
208 | if (peer->keys[i] && peer->keys[i]->keyidx == keyidx) | |
209 | return true; | |
210 | } | |
211 | ||
212 | return false; | |
213 | } | |
214 | ||
5e3dd157 KV |
215 | static int ath10k_clear_vdev_key(struct ath10k_vif *arvif, |
216 | struct ieee80211_key_conf *key) | |
217 | { | |
218 | struct ath10k *ar = arvif->ar; | |
219 | struct ath10k_peer *peer; | |
220 | u8 addr[ETH_ALEN]; | |
221 | int first_errno = 0; | |
222 | int ret; | |
223 | int i; | |
370e5673 | 224 | u32 flags = 0; |
5e3dd157 KV |
225 | |
226 | lockdep_assert_held(&ar->conf_mutex); | |
227 | ||
228 | for (;;) { | |
229 | /* since ath10k_install_key we can't hold data_lock all the | |
230 | * time, so we try to remove the keys incrementally */ | |
231 | spin_lock_bh(&ar->data_lock); | |
232 | i = 0; | |
233 | list_for_each_entry(peer, &ar->peers, list) { | |
234 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
235 | if (peer->keys[i] == key) { | |
b25f32cb | 236 | ether_addr_copy(addr, peer->addr); |
5e3dd157 KV |
237 | peer->keys[i] = NULL; |
238 | break; | |
239 | } | |
240 | } | |
241 | ||
242 | if (i < ARRAY_SIZE(peer->keys)) | |
243 | break; | |
244 | } | |
245 | spin_unlock_bh(&ar->data_lock); | |
246 | ||
247 | if (i == ARRAY_SIZE(peer->keys)) | |
248 | break; | |
627613f8 | 249 | /* key flags are not required to delete the key */ |
370e5673 | 250 | ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags); |
5e3dd157 KV |
251 | if (ret && first_errno == 0) |
252 | first_errno = ret; | |
253 | ||
254 | if (ret) | |
7aa7a72a | 255 | ath10k_warn(ar, "failed to remove key for %pM: %d\n", |
be6546fc | 256 | addr, ret); |
5e3dd157 KV |
257 | } |
258 | ||
259 | return first_errno; | |
260 | } | |
261 | ||
370e5673 MK |
262 | static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif) |
263 | { | |
264 | struct ath10k *ar = arvif->ar; | |
265 | enum nl80211_iftype iftype = arvif->vif->type; | |
266 | struct ieee80211_key_conf *key; | |
267 | u32 flags = 0; | |
268 | int num = 0; | |
269 | int i; | |
270 | int ret; | |
271 | ||
272 | lockdep_assert_held(&ar->conf_mutex); | |
273 | ||
274 | if (iftype != NL80211_IFTYPE_STATION) | |
275 | return 0; | |
276 | ||
277 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { | |
278 | if (arvif->wep_keys[i]) { | |
279 | key = arvif->wep_keys[i]; | |
280 | ++num; | |
281 | } | |
282 | } | |
283 | ||
284 | if (num != 1) | |
285 | return 0; | |
286 | ||
287 | flags |= WMI_KEY_PAIRWISE; | |
288 | flags |= WMI_KEY_TX_USAGE; | |
289 | ||
290 | ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags); | |
291 | if (ret) { | |
292 | ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n", | |
293 | key->keyidx, arvif->vdev_id, ret); | |
294 | return ret; | |
295 | } | |
296 | ||
297 | return 0; | |
298 | } | |
299 | ||
ad325cb5 MK |
300 | static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif, |
301 | struct ieee80211_key_conf *key) | |
302 | { | |
303 | struct ath10k *ar = arvif->ar; | |
304 | struct ath10k_peer *peer; | |
305 | int ret; | |
306 | ||
307 | lockdep_assert_held(&ar->conf_mutex); | |
308 | ||
309 | list_for_each_entry(peer, &ar->peers, list) { | |
310 | if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN)) | |
311 | continue; | |
312 | ||
313 | if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN)) | |
314 | continue; | |
315 | ||
316 | if (peer->keys[key->keyidx] == key) | |
317 | continue; | |
318 | ||
319 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n", | |
320 | arvif->vdev_id, key->keyidx); | |
321 | ||
322 | ret = ath10k_install_peer_wep_keys(arvif, peer->addr); | |
323 | if (ret) { | |
324 | ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n", | |
325 | arvif->vdev_id, peer->addr, ret); | |
326 | return ret; | |
327 | } | |
328 | } | |
329 | ||
330 | return 0; | |
331 | } | |
332 | ||
5e3dd157 KV |
333 | /*********************/ |
334 | /* General utilities */ | |
335 | /*********************/ | |
336 | ||
337 | static inline enum wmi_phy_mode | |
338 | chan_to_phymode(const struct cfg80211_chan_def *chandef) | |
339 | { | |
340 | enum wmi_phy_mode phymode = MODE_UNKNOWN; | |
341 | ||
342 | switch (chandef->chan->band) { | |
343 | case IEEE80211_BAND_2GHZ: | |
344 | switch (chandef->width) { | |
345 | case NL80211_CHAN_WIDTH_20_NOHT: | |
6faab127 PO |
346 | if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM) |
347 | phymode = MODE_11B; | |
348 | else | |
349 | phymode = MODE_11G; | |
5e3dd157 KV |
350 | break; |
351 | case NL80211_CHAN_WIDTH_20: | |
352 | phymode = MODE_11NG_HT20; | |
353 | break; | |
354 | case NL80211_CHAN_WIDTH_40: | |
355 | phymode = MODE_11NG_HT40; | |
356 | break; | |
0f817ed5 JL |
357 | case NL80211_CHAN_WIDTH_5: |
358 | case NL80211_CHAN_WIDTH_10: | |
5e3dd157 KV |
359 | case NL80211_CHAN_WIDTH_80: |
360 | case NL80211_CHAN_WIDTH_80P80: | |
361 | case NL80211_CHAN_WIDTH_160: | |
362 | phymode = MODE_UNKNOWN; | |
363 | break; | |
364 | } | |
365 | break; | |
366 | case IEEE80211_BAND_5GHZ: | |
367 | switch (chandef->width) { | |
368 | case NL80211_CHAN_WIDTH_20_NOHT: | |
369 | phymode = MODE_11A; | |
370 | break; | |
371 | case NL80211_CHAN_WIDTH_20: | |
372 | phymode = MODE_11NA_HT20; | |
373 | break; | |
374 | case NL80211_CHAN_WIDTH_40: | |
375 | phymode = MODE_11NA_HT40; | |
376 | break; | |
377 | case NL80211_CHAN_WIDTH_80: | |
378 | phymode = MODE_11AC_VHT80; | |
379 | break; | |
0f817ed5 JL |
380 | case NL80211_CHAN_WIDTH_5: |
381 | case NL80211_CHAN_WIDTH_10: | |
5e3dd157 KV |
382 | case NL80211_CHAN_WIDTH_80P80: |
383 | case NL80211_CHAN_WIDTH_160: | |
384 | phymode = MODE_UNKNOWN; | |
385 | break; | |
386 | } | |
387 | break; | |
388 | default: | |
389 | break; | |
390 | } | |
391 | ||
392 | WARN_ON(phymode == MODE_UNKNOWN); | |
393 | return phymode; | |
394 | } | |
395 | ||
396 | static u8 ath10k_parse_mpdudensity(u8 mpdudensity) | |
397 | { | |
398 | /* | |
399 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": | |
400 | * 0 for no restriction | |
401 | * 1 for 1/4 us | |
402 | * 2 for 1/2 us | |
403 | * 3 for 1 us | |
404 | * 4 for 2 us | |
405 | * 5 for 4 us | |
406 | * 6 for 8 us | |
407 | * 7 for 16 us | |
408 | */ | |
409 | switch (mpdudensity) { | |
410 | case 0: | |
411 | return 0; | |
412 | case 1: | |
413 | case 2: | |
414 | case 3: | |
415 | /* Our lower layer calculations limit our precision to | |
416 | 1 microsecond */ | |
417 | return 1; | |
418 | case 4: | |
419 | return 2; | |
420 | case 5: | |
421 | return 4; | |
422 | case 6: | |
423 | return 8; | |
424 | case 7: | |
425 | return 16; | |
426 | default: | |
427 | return 0; | |
428 | } | |
429 | } | |
430 | ||
431 | static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr) | |
432 | { | |
433 | int ret; | |
434 | ||
435 | lockdep_assert_held(&ar->conf_mutex); | |
436 | ||
cfd1061e MK |
437 | if (ar->num_peers >= ar->max_num_peers) |
438 | return -ENOBUFS; | |
439 | ||
5e3dd157 | 440 | ret = ath10k_wmi_peer_create(ar, vdev_id, addr); |
479398b0 | 441 | if (ret) { |
7aa7a72a | 442 | ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n", |
69244e56 | 443 | addr, vdev_id, ret); |
5e3dd157 | 444 | return ret; |
479398b0 | 445 | } |
5e3dd157 KV |
446 | |
447 | ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); | |
479398b0 | 448 | if (ret) { |
7aa7a72a | 449 | ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n", |
69244e56 | 450 | addr, vdev_id, ret); |
5e3dd157 | 451 | return ret; |
479398b0 | 452 | } |
292a753d | 453 | |
0e759f36 | 454 | ar->num_peers++; |
5e3dd157 KV |
455 | |
456 | return 0; | |
457 | } | |
458 | ||
5a13e76e KV |
459 | static int ath10k_mac_set_kickout(struct ath10k_vif *arvif) |
460 | { | |
461 | struct ath10k *ar = arvif->ar; | |
462 | u32 param; | |
463 | int ret; | |
464 | ||
465 | param = ar->wmi.pdev_param->sta_kickout_th; | |
466 | ret = ath10k_wmi_pdev_set_param(ar, param, | |
467 | ATH10K_KICKOUT_THRESHOLD); | |
468 | if (ret) { | |
7aa7a72a | 469 | ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n", |
69244e56 | 470 | arvif->vdev_id, ret); |
5a13e76e KV |
471 | return ret; |
472 | } | |
473 | ||
474 | param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs; | |
475 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, | |
476 | ATH10K_KEEPALIVE_MIN_IDLE); | |
477 | if (ret) { | |
7aa7a72a | 478 | ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n", |
69244e56 | 479 | arvif->vdev_id, ret); |
5a13e76e KV |
480 | return ret; |
481 | } | |
482 | ||
483 | param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs; | |
484 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, | |
485 | ATH10K_KEEPALIVE_MAX_IDLE); | |
486 | if (ret) { | |
7aa7a72a | 487 | ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n", |
69244e56 | 488 | arvif->vdev_id, ret); |
5a13e76e KV |
489 | return ret; |
490 | } | |
491 | ||
492 | param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs; | |
493 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, | |
494 | ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); | |
495 | if (ret) { | |
7aa7a72a | 496 | ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", |
69244e56 | 497 | arvif->vdev_id, ret); |
5a13e76e KV |
498 | return ret; |
499 | } | |
500 | ||
501 | return 0; | |
502 | } | |
503 | ||
acab6400 | 504 | static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value) |
424121c3 | 505 | { |
6d1506e7 BM |
506 | struct ath10k *ar = arvif->ar; |
507 | u32 vdev_param; | |
508 | ||
6d1506e7 BM |
509 | vdev_param = ar->wmi.vdev_param->rts_threshold; |
510 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value); | |
424121c3 MK |
511 | } |
512 | ||
513 | static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value) | |
514 | { | |
6d1506e7 BM |
515 | struct ath10k *ar = arvif->ar; |
516 | u32 vdev_param; | |
517 | ||
424121c3 MK |
518 | if (value != 0xFFFFFFFF) |
519 | value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold, | |
520 | ATH10K_FRAGMT_THRESHOLD_MIN, | |
521 | ATH10K_FRAGMT_THRESHOLD_MAX); | |
522 | ||
6d1506e7 BM |
523 | vdev_param = ar->wmi.vdev_param->fragmentation_threshold; |
524 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value); | |
424121c3 MK |
525 | } |
526 | ||
5e3dd157 KV |
527 | static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
528 | { | |
529 | int ret; | |
530 | ||
531 | lockdep_assert_held(&ar->conf_mutex); | |
532 | ||
533 | ret = ath10k_wmi_peer_delete(ar, vdev_id, addr); | |
534 | if (ret) | |
535 | return ret; | |
536 | ||
537 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); | |
538 | if (ret) | |
539 | return ret; | |
540 | ||
0e759f36 | 541 | ar->num_peers--; |
0e759f36 | 542 | |
5e3dd157 KV |
543 | return 0; |
544 | } | |
545 | ||
546 | static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id) | |
547 | { | |
548 | struct ath10k_peer *peer, *tmp; | |
549 | ||
550 | lockdep_assert_held(&ar->conf_mutex); | |
551 | ||
552 | spin_lock_bh(&ar->data_lock); | |
553 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { | |
554 | if (peer->vdev_id != vdev_id) | |
555 | continue; | |
556 | ||
7aa7a72a | 557 | ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n", |
5e3dd157 KV |
558 | peer->addr, vdev_id); |
559 | ||
560 | list_del(&peer->list); | |
561 | kfree(peer); | |
0e759f36 | 562 | ar->num_peers--; |
5e3dd157 KV |
563 | } |
564 | spin_unlock_bh(&ar->data_lock); | |
565 | } | |
566 | ||
a96d7745 MK |
567 | static void ath10k_peer_cleanup_all(struct ath10k *ar) |
568 | { | |
569 | struct ath10k_peer *peer, *tmp; | |
570 | ||
571 | lockdep_assert_held(&ar->conf_mutex); | |
572 | ||
573 | spin_lock_bh(&ar->data_lock); | |
574 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { | |
575 | list_del(&peer->list); | |
576 | kfree(peer); | |
577 | } | |
578 | spin_unlock_bh(&ar->data_lock); | |
292a753d MK |
579 | |
580 | ar->num_peers = 0; | |
cfd1061e | 581 | ar->num_stations = 0; |
a96d7745 MK |
582 | } |
583 | ||
5e3dd157 KV |
584 | /************************/ |
585 | /* Interface management */ | |
586 | /************************/ | |
587 | ||
64badcb6 MK |
588 | void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif) |
589 | { | |
590 | struct ath10k *ar = arvif->ar; | |
591 | ||
592 | lockdep_assert_held(&ar->data_lock); | |
593 | ||
594 | if (!arvif->beacon) | |
595 | return; | |
596 | ||
597 | if (!arvif->beacon_buf) | |
598 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr, | |
599 | arvif->beacon->len, DMA_TO_DEVICE); | |
600 | ||
af21319f MK |
601 | if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED && |
602 | arvif->beacon_state != ATH10K_BEACON_SENT)) | |
603 | return; | |
604 | ||
64badcb6 MK |
605 | dev_kfree_skb_any(arvif->beacon); |
606 | ||
607 | arvif->beacon = NULL; | |
af21319f | 608 | arvif->beacon_state = ATH10K_BEACON_SCHEDULED; |
64badcb6 MK |
609 | } |
610 | ||
611 | static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif) | |
612 | { | |
613 | struct ath10k *ar = arvif->ar; | |
614 | ||
615 | lockdep_assert_held(&ar->data_lock); | |
616 | ||
617 | ath10k_mac_vif_beacon_free(arvif); | |
618 | ||
619 | if (arvif->beacon_buf) { | |
620 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, | |
621 | arvif->beacon_buf, arvif->beacon_paddr); | |
622 | arvif->beacon_buf = NULL; | |
623 | } | |
624 | } | |
625 | ||
5e3dd157 KV |
626 | static inline int ath10k_vdev_setup_sync(struct ath10k *ar) |
627 | { | |
628 | int ret; | |
629 | ||
548db54c MK |
630 | lockdep_assert_held(&ar->conf_mutex); |
631 | ||
7962b0d8 MK |
632 | if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) |
633 | return -ESHUTDOWN; | |
634 | ||
5e3dd157 KV |
635 | ret = wait_for_completion_timeout(&ar->vdev_setup_done, |
636 | ATH10K_VDEV_SETUP_TIMEOUT_HZ); | |
637 | if (ret == 0) | |
638 | return -ETIMEDOUT; | |
639 | ||
640 | return 0; | |
641 | } | |
642 | ||
1bbc0975 | 643 | static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id) |
5e3dd157 | 644 | { |
c930f744 MK |
645 | struct cfg80211_chan_def *chandef = &ar->chandef; |
646 | struct ieee80211_channel *channel = chandef->chan; | |
5e3dd157 | 647 | struct wmi_vdev_start_request_arg arg = {}; |
5e3dd157 KV |
648 | int ret = 0; |
649 | ||
650 | lockdep_assert_held(&ar->conf_mutex); | |
651 | ||
5e3dd157 KV |
652 | arg.vdev_id = vdev_id; |
653 | arg.channel.freq = channel->center_freq; | |
c930f744 | 654 | arg.channel.band_center_freq1 = chandef->center_freq1; |
5e3dd157 KV |
655 | |
656 | /* TODO setup this dynamically, what in case we | |
657 | don't have any vifs? */ | |
c930f744 | 658 | arg.channel.mode = chan_to_phymode(chandef); |
e8a50f8b MP |
659 | arg.channel.chan_radar = |
660 | !!(channel->flags & IEEE80211_CHAN_RADAR); | |
5e3dd157 | 661 | |
89c5c843 | 662 | arg.channel.min_power = 0; |
02256930 MK |
663 | arg.channel.max_power = channel->max_power * 2; |
664 | arg.channel.max_reg_power = channel->max_reg_power * 2; | |
665 | arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; | |
5e3dd157 | 666 | |
7962b0d8 MK |
667 | reinit_completion(&ar->vdev_setup_done); |
668 | ||
5e3dd157 KV |
669 | ret = ath10k_wmi_vdev_start(ar, &arg); |
670 | if (ret) { | |
7aa7a72a | 671 | ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n", |
69244e56 | 672 | vdev_id, ret); |
5e3dd157 KV |
673 | return ret; |
674 | } | |
675 | ||
676 | ret = ath10k_vdev_setup_sync(ar); | |
677 | if (ret) { | |
60028a81 | 678 | ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n", |
69244e56 | 679 | vdev_id, ret); |
5e3dd157 KV |
680 | return ret; |
681 | } | |
682 | ||
683 | ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); | |
684 | if (ret) { | |
7aa7a72a | 685 | ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n", |
69244e56 | 686 | vdev_id, ret); |
5e3dd157 KV |
687 | goto vdev_stop; |
688 | } | |
689 | ||
690 | ar->monitor_vdev_id = vdev_id; | |
5e3dd157 | 691 | |
7aa7a72a | 692 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n", |
1bbc0975 | 693 | ar->monitor_vdev_id); |
5e3dd157 KV |
694 | return 0; |
695 | ||
696 | vdev_stop: | |
697 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); | |
698 | if (ret) | |
7aa7a72a | 699 | ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n", |
69244e56 | 700 | ar->monitor_vdev_id, ret); |
5e3dd157 KV |
701 | |
702 | return ret; | |
703 | } | |
704 | ||
1bbc0975 | 705 | static int ath10k_monitor_vdev_stop(struct ath10k *ar) |
5e3dd157 KV |
706 | { |
707 | int ret = 0; | |
708 | ||
709 | lockdep_assert_held(&ar->conf_mutex); | |
710 | ||
52fa0191 MP |
711 | ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
712 | if (ret) | |
7aa7a72a | 713 | ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n", |
69244e56 | 714 | ar->monitor_vdev_id, ret); |
5e3dd157 | 715 | |
7962b0d8 MK |
716 | reinit_completion(&ar->vdev_setup_done); |
717 | ||
5e3dd157 KV |
718 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
719 | if (ret) | |
7aa7a72a | 720 | ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n", |
69244e56 | 721 | ar->monitor_vdev_id, ret); |
5e3dd157 KV |
722 | |
723 | ret = ath10k_vdev_setup_sync(ar); | |
724 | if (ret) | |
60028a81 | 725 | ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n", |
69244e56 | 726 | ar->monitor_vdev_id, ret); |
5e3dd157 | 727 | |
7aa7a72a | 728 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n", |
1bbc0975 | 729 | ar->monitor_vdev_id); |
5e3dd157 KV |
730 | return ret; |
731 | } | |
732 | ||
1bbc0975 | 733 | static int ath10k_monitor_vdev_create(struct ath10k *ar) |
5e3dd157 KV |
734 | { |
735 | int bit, ret = 0; | |
736 | ||
737 | lockdep_assert_held(&ar->conf_mutex); | |
738 | ||
a9aefb3b | 739 | if (ar->free_vdev_map == 0) { |
7aa7a72a | 740 | ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n"); |
5e3dd157 KV |
741 | return -ENOMEM; |
742 | } | |
743 | ||
16c11176 | 744 | bit = __ffs64(ar->free_vdev_map); |
a9aefb3b | 745 | |
16c11176 | 746 | ar->monitor_vdev_id = bit; |
5e3dd157 KV |
747 | |
748 | ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, | |
749 | WMI_VDEV_TYPE_MONITOR, | |
750 | 0, ar->mac_addr); | |
751 | if (ret) { | |
7aa7a72a | 752 | ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n", |
69244e56 | 753 | ar->monitor_vdev_id, ret); |
a9aefb3b | 754 | return ret; |
5e3dd157 KV |
755 | } |
756 | ||
16c11176 | 757 | ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); |
7aa7a72a | 758 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n", |
5e3dd157 KV |
759 | ar->monitor_vdev_id); |
760 | ||
5e3dd157 | 761 | return 0; |
5e3dd157 KV |
762 | } |
763 | ||
1bbc0975 | 764 | static int ath10k_monitor_vdev_delete(struct ath10k *ar) |
5e3dd157 KV |
765 | { |
766 | int ret = 0; | |
767 | ||
768 | lockdep_assert_held(&ar->conf_mutex); | |
769 | ||
5e3dd157 KV |
770 | ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
771 | if (ret) { | |
7aa7a72a | 772 | ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n", |
69244e56 | 773 | ar->monitor_vdev_id, ret); |
5e3dd157 KV |
774 | return ret; |
775 | } | |
776 | ||
16c11176 | 777 | ar->free_vdev_map |= 1LL << ar->monitor_vdev_id; |
5e3dd157 | 778 | |
7aa7a72a | 779 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", |
5e3dd157 KV |
780 | ar->monitor_vdev_id); |
781 | return ret; | |
782 | } | |
783 | ||
1bbc0975 MK |
784 | static int ath10k_monitor_start(struct ath10k *ar) |
785 | { | |
786 | int ret; | |
787 | ||
788 | lockdep_assert_held(&ar->conf_mutex); | |
789 | ||
1bbc0975 MK |
790 | ret = ath10k_monitor_vdev_create(ar); |
791 | if (ret) { | |
7aa7a72a | 792 | ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret); |
1bbc0975 MK |
793 | return ret; |
794 | } | |
795 | ||
796 | ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id); | |
797 | if (ret) { | |
7aa7a72a | 798 | ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret); |
1bbc0975 MK |
799 | ath10k_monitor_vdev_delete(ar); |
800 | return ret; | |
801 | } | |
802 | ||
803 | ar->monitor_started = true; | |
7aa7a72a | 804 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n"); |
1bbc0975 MK |
805 | |
806 | return 0; | |
807 | } | |
808 | ||
1933747f | 809 | static int ath10k_monitor_stop(struct ath10k *ar) |
1bbc0975 MK |
810 | { |
811 | int ret; | |
812 | ||
813 | lockdep_assert_held(&ar->conf_mutex); | |
814 | ||
1bbc0975 | 815 | ret = ath10k_monitor_vdev_stop(ar); |
1933747f | 816 | if (ret) { |
7aa7a72a | 817 | ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret); |
1933747f MK |
818 | return ret; |
819 | } | |
1bbc0975 MK |
820 | |
821 | ret = ath10k_monitor_vdev_delete(ar); | |
1933747f | 822 | if (ret) { |
7aa7a72a | 823 | ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret); |
1933747f MK |
824 | return ret; |
825 | } | |
1bbc0975 MK |
826 | |
827 | ar->monitor_started = false; | |
7aa7a72a | 828 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n"); |
1933747f MK |
829 | |
830 | return 0; | |
831 | } | |
832 | ||
54846213 VT |
833 | static bool ath10k_mac_should_disable_promisc(struct ath10k *ar) |
834 | { | |
835 | struct ath10k_vif *arvif; | |
836 | ||
837 | if (!(ar->filter_flags & FIF_PROMISC_IN_BSS)) | |
838 | return true; | |
839 | ||
840 | if (!ar->num_started_vdevs) | |
841 | return false; | |
842 | ||
843 | list_for_each_entry(arvif, &ar->arvifs, list) | |
844 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) | |
845 | return false; | |
846 | ||
847 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
848 | "mac disabling promiscuous mode because vdev is started\n"); | |
849 | return true; | |
850 | } | |
851 | ||
1933747f MK |
852 | static int ath10k_monitor_recalc(struct ath10k *ar) |
853 | { | |
854 | bool should_start; | |
855 | ||
856 | lockdep_assert_held(&ar->conf_mutex); | |
857 | ||
858 | should_start = ar->monitor || | |
bff414c3 | 859 | !ath10k_mac_should_disable_promisc(ar) || |
1933747f MK |
860 | test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
861 | ||
862 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
863 | "mac monitor recalc started? %d should? %d\n", | |
864 | ar->monitor_started, should_start); | |
865 | ||
866 | if (should_start == ar->monitor_started) | |
867 | return 0; | |
868 | ||
869 | if (should_start) | |
870 | return ath10k_monitor_start(ar); | |
d8bb26b9 KV |
871 | |
872 | return ath10k_monitor_stop(ar); | |
1bbc0975 MK |
873 | } |
874 | ||
e81bd104 MK |
875 | static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif) |
876 | { | |
877 | struct ath10k *ar = arvif->ar; | |
878 | u32 vdev_param, rts_cts = 0; | |
879 | ||
880 | lockdep_assert_held(&ar->conf_mutex); | |
881 | ||
882 | vdev_param = ar->wmi.vdev_param->enable_rtscts; | |
883 | ||
9a5ab0f4 | 884 | rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET); |
e81bd104 MK |
885 | |
886 | if (arvif->num_legacy_stations > 0) | |
887 | rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES, | |
888 | WMI_RTSCTS_PROFILE); | |
9a5ab0f4 RM |
889 | else |
890 | rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES, | |
891 | WMI_RTSCTS_PROFILE); | |
e81bd104 MK |
892 | |
893 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
894 | rts_cts); | |
895 | } | |
896 | ||
e8a50f8b MP |
897 | static int ath10k_start_cac(struct ath10k *ar) |
898 | { | |
899 | int ret; | |
900 | ||
901 | lockdep_assert_held(&ar->conf_mutex); | |
902 | ||
903 | set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); | |
904 | ||
1933747f | 905 | ret = ath10k_monitor_recalc(ar); |
e8a50f8b | 906 | if (ret) { |
7aa7a72a | 907 | ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret); |
e8a50f8b MP |
908 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
909 | return ret; | |
910 | } | |
911 | ||
7aa7a72a | 912 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n", |
e8a50f8b MP |
913 | ar->monitor_vdev_id); |
914 | ||
915 | return 0; | |
916 | } | |
917 | ||
918 | static int ath10k_stop_cac(struct ath10k *ar) | |
919 | { | |
920 | lockdep_assert_held(&ar->conf_mutex); | |
921 | ||
922 | /* CAC is not running - do nothing */ | |
923 | if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) | |
924 | return 0; | |
925 | ||
e8a50f8b | 926 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
1bbc0975 | 927 | ath10k_monitor_stop(ar); |
e8a50f8b | 928 | |
7aa7a72a | 929 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n"); |
e8a50f8b MP |
930 | |
931 | return 0; | |
932 | } | |
933 | ||
d650097b | 934 | static void ath10k_recalc_radar_detection(struct ath10k *ar) |
e8a50f8b | 935 | { |
e8a50f8b MP |
936 | int ret; |
937 | ||
938 | lockdep_assert_held(&ar->conf_mutex); | |
939 | ||
e8a50f8b MP |
940 | ath10k_stop_cac(ar); |
941 | ||
d650097b | 942 | if (!ar->radar_enabled) |
e8a50f8b MP |
943 | return; |
944 | ||
d650097b | 945 | if (ar->num_started_vdevs > 0) |
e8a50f8b MP |
946 | return; |
947 | ||
948 | ret = ath10k_start_cac(ar); | |
949 | if (ret) { | |
950 | /* | |
951 | * Not possible to start CAC on current channel so starting | |
952 | * radiation is not allowed, make this channel DFS_UNAVAILABLE | |
953 | * by indicating that radar was detected. | |
954 | */ | |
7aa7a72a | 955 | ath10k_warn(ar, "failed to start CAC: %d\n", ret); |
e8a50f8b MP |
956 | ieee80211_radar_detected(ar->hw); |
957 | } | |
958 | } | |
959 | ||
822b7e0b VT |
960 | static int ath10k_vdev_stop(struct ath10k_vif *arvif) |
961 | { | |
962 | struct ath10k *ar = arvif->ar; | |
963 | int ret; | |
964 | ||
965 | lockdep_assert_held(&ar->conf_mutex); | |
966 | ||
967 | reinit_completion(&ar->vdev_setup_done); | |
968 | ||
969 | ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); | |
970 | if (ret) { | |
971 | ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n", | |
972 | arvif->vdev_id, ret); | |
973 | return ret; | |
974 | } | |
975 | ||
976 | ret = ath10k_vdev_setup_sync(ar); | |
977 | if (ret) { | |
978 | ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n", | |
979 | arvif->vdev_id, ret); | |
980 | return ret; | |
981 | } | |
982 | ||
983 | WARN_ON(ar->num_started_vdevs == 0); | |
984 | ||
985 | if (ar->num_started_vdevs != 0) { | |
986 | ar->num_started_vdevs--; | |
987 | ath10k_recalc_radar_detection(ar); | |
988 | } | |
989 | ||
990 | return ret; | |
991 | } | |
992 | ||
dc55e307 | 993 | static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart) |
72654fa7 MK |
994 | { |
995 | struct ath10k *ar = arvif->ar; | |
996 | struct cfg80211_chan_def *chandef = &ar->chandef; | |
997 | struct wmi_vdev_start_request_arg arg = {}; | |
54846213 | 998 | int ret = 0, ret2; |
72654fa7 MK |
999 | |
1000 | lockdep_assert_held(&ar->conf_mutex); | |
1001 | ||
1002 | reinit_completion(&ar->vdev_setup_done); | |
1003 | ||
1004 | arg.vdev_id = arvif->vdev_id; | |
1005 | arg.dtim_period = arvif->dtim_period; | |
1006 | arg.bcn_intval = arvif->beacon_interval; | |
1007 | ||
1008 | arg.channel.freq = chandef->chan->center_freq; | |
1009 | arg.channel.band_center_freq1 = chandef->center_freq1; | |
1010 | arg.channel.mode = chan_to_phymode(chandef); | |
1011 | ||
1012 | arg.channel.min_power = 0; | |
1013 | arg.channel.max_power = chandef->chan->max_power * 2; | |
1014 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; | |
1015 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; | |
1016 | ||
1017 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
1018 | arg.ssid = arvif->u.ap.ssid; | |
1019 | arg.ssid_len = arvif->u.ap.ssid_len; | |
1020 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; | |
1021 | ||
1022 | /* For now allow DFS for AP mode */ | |
1023 | arg.channel.chan_radar = | |
1024 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); | |
1025 | } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { | |
1026 | arg.ssid = arvif->vif->bss_conf.ssid; | |
1027 | arg.ssid_len = arvif->vif->bss_conf.ssid_len; | |
1028 | } | |
1029 | ||
7aa7a72a | 1030 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
72654fa7 MK |
1031 | "mac vdev %d start center_freq %d phymode %s\n", |
1032 | arg.vdev_id, arg.channel.freq, | |
1033 | ath10k_wmi_phymode_str(arg.channel.mode)); | |
1034 | ||
dc55e307 MK |
1035 | if (restart) |
1036 | ret = ath10k_wmi_vdev_restart(ar, &arg); | |
1037 | else | |
1038 | ret = ath10k_wmi_vdev_start(ar, &arg); | |
1039 | ||
72654fa7 | 1040 | if (ret) { |
7aa7a72a | 1041 | ath10k_warn(ar, "failed to start WMI vdev %i: %d\n", |
72654fa7 MK |
1042 | arg.vdev_id, ret); |
1043 | return ret; | |
1044 | } | |
1045 | ||
1046 | ret = ath10k_vdev_setup_sync(ar); | |
1047 | if (ret) { | |
60028a81 BG |
1048 | ath10k_warn(ar, |
1049 | "failed to synchronize setup for vdev %i restart %d: %d\n", | |
1050 | arg.vdev_id, restart, ret); | |
72654fa7 MK |
1051 | return ret; |
1052 | } | |
1053 | ||
d650097b MK |
1054 | ar->num_started_vdevs++; |
1055 | ath10k_recalc_radar_detection(ar); | |
1056 | ||
54846213 VT |
1057 | ret = ath10k_monitor_recalc(ar); |
1058 | if (ret) { | |
1059 | ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n", | |
1060 | arg.vdev_id, restart, ret); | |
1061 | ret2 = ath10k_vdev_stop(arvif); | |
1062 | if (ret2) | |
1063 | ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n", | |
1064 | arg.vdev_id, restart, ret2); | |
1065 | } | |
1066 | ||
72654fa7 MK |
1067 | return ret; |
1068 | } | |
1069 | ||
dc55e307 MK |
1070 | static int ath10k_vdev_start(struct ath10k_vif *arvif) |
1071 | { | |
1072 | return ath10k_vdev_start_restart(arvif, false); | |
1073 | } | |
1074 | ||
1075 | static int ath10k_vdev_restart(struct ath10k_vif *arvif) | |
1076 | { | |
1077 | return ath10k_vdev_start_restart(arvif, true); | |
1078 | } | |
1079 | ||
fbb8f1b7 MK |
1080 | static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif, |
1081 | struct sk_buff *bcn) | |
1082 | { | |
1083 | struct ath10k *ar = arvif->ar; | |
1084 | struct ieee80211_mgmt *mgmt; | |
1085 | const u8 *p2p_ie; | |
1086 | int ret; | |
1087 | ||
1088 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) | |
1089 | return 0; | |
1090 | ||
1091 | if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) | |
1092 | return 0; | |
1093 | ||
1094 | mgmt = (void *)bcn->data; | |
1095 | p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, | |
1096 | mgmt->u.beacon.variable, | |
1097 | bcn->len - (mgmt->u.beacon.variable - | |
1098 | bcn->data)); | |
1099 | if (!p2p_ie) | |
1100 | return -ENOENT; | |
1101 | ||
1102 | ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); | |
1103 | if (ret) { | |
1104 | ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n", | |
1105 | arvif->vdev_id, ret); | |
1106 | return ret; | |
1107 | } | |
1108 | ||
1109 | return 0; | |
1110 | } | |
1111 | ||
1112 | static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, | |
1113 | u8 oui_type, size_t ie_offset) | |
1114 | { | |
1115 | size_t len; | |
1116 | const u8 *next; | |
1117 | const u8 *end; | |
1118 | u8 *ie; | |
1119 | ||
1120 | if (WARN_ON(skb->len < ie_offset)) | |
1121 | return -EINVAL; | |
1122 | ||
1123 | ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, | |
1124 | skb->data + ie_offset, | |
1125 | skb->len - ie_offset); | |
1126 | if (!ie) | |
1127 | return -ENOENT; | |
1128 | ||
1129 | len = ie[1] + 2; | |
1130 | end = skb->data + skb->len; | |
1131 | next = ie + len; | |
1132 | ||
1133 | if (WARN_ON(next > end)) | |
1134 | return -EINVAL; | |
1135 | ||
1136 | memmove(ie, next, end - next); | |
1137 | skb_trim(skb, skb->len - len); | |
1138 | ||
1139 | return 0; | |
1140 | } | |
1141 | ||
1142 | static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif) | |
1143 | { | |
1144 | struct ath10k *ar = arvif->ar; | |
1145 | struct ieee80211_hw *hw = ar->hw; | |
1146 | struct ieee80211_vif *vif = arvif->vif; | |
1147 | struct ieee80211_mutable_offsets offs = {}; | |
1148 | struct sk_buff *bcn; | |
1149 | int ret; | |
1150 | ||
1151 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) | |
1152 | return 0; | |
1153 | ||
81a9a17d MK |
1154 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
1155 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) | |
1156 | return 0; | |
1157 | ||
fbb8f1b7 MK |
1158 | bcn = ieee80211_beacon_get_template(hw, vif, &offs); |
1159 | if (!bcn) { | |
1160 | ath10k_warn(ar, "failed to get beacon template from mac80211\n"); | |
1161 | return -EPERM; | |
1162 | } | |
1163 | ||
1164 | ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn); | |
1165 | if (ret) { | |
1166 | ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret); | |
1167 | kfree_skb(bcn); | |
1168 | return ret; | |
1169 | } | |
1170 | ||
1171 | /* P2P IE is inserted by firmware automatically (as configured above) | |
1172 | * so remove it from the base beacon template to avoid duplicate P2P | |
1173 | * IEs in beacon frames. | |
1174 | */ | |
1175 | ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, | |
1176 | offsetof(struct ieee80211_mgmt, | |
1177 | u.beacon.variable)); | |
1178 | ||
1179 | ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0, | |
1180 | 0, NULL, 0); | |
1181 | kfree_skb(bcn); | |
1182 | ||
1183 | if (ret) { | |
1184 | ath10k_warn(ar, "failed to submit beacon template command: %d\n", | |
1185 | ret); | |
1186 | return ret; | |
1187 | } | |
1188 | ||
1189 | return 0; | |
1190 | } | |
1191 | ||
1192 | static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif) | |
1193 | { | |
1194 | struct ath10k *ar = arvif->ar; | |
1195 | struct ieee80211_hw *hw = ar->hw; | |
1196 | struct ieee80211_vif *vif = arvif->vif; | |
1197 | struct sk_buff *prb; | |
1198 | int ret; | |
1199 | ||
1200 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) | |
1201 | return 0; | |
1202 | ||
81a9a17d MK |
1203 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
1204 | return 0; | |
1205 | ||
fbb8f1b7 MK |
1206 | prb = ieee80211_proberesp_get(hw, vif); |
1207 | if (!prb) { | |
1208 | ath10k_warn(ar, "failed to get probe resp template from mac80211\n"); | |
1209 | return -EPERM; | |
1210 | } | |
1211 | ||
1212 | ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb); | |
1213 | kfree_skb(prb); | |
1214 | ||
1215 | if (ret) { | |
1216 | ath10k_warn(ar, "failed to submit probe resp template command: %d\n", | |
1217 | ret); | |
1218 | return ret; | |
1219 | } | |
1220 | ||
1221 | return 0; | |
1222 | } | |
1223 | ||
5e3dd157 | 1224 | static void ath10k_control_beaconing(struct ath10k_vif *arvif, |
5b07e07f | 1225 | struct ieee80211_bss_conf *info) |
5e3dd157 | 1226 | { |
7aa7a72a | 1227 | struct ath10k *ar = arvif->ar; |
5e3dd157 KV |
1228 | int ret = 0; |
1229 | ||
548db54c MK |
1230 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1231 | ||
5e3dd157 KV |
1232 | if (!info->enable_beacon) { |
1233 | ath10k_vdev_stop(arvif); | |
c930f744 MK |
1234 | |
1235 | arvif->is_started = false; | |
1236 | arvif->is_up = false; | |
8513d95b MK |
1237 | |
1238 | spin_lock_bh(&arvif->ar->data_lock); | |
64badcb6 | 1239 | ath10k_mac_vif_beacon_free(arvif); |
748afc47 MK |
1240 | spin_unlock_bh(&arvif->ar->data_lock); |
1241 | ||
5e3dd157 KV |
1242 | return; |
1243 | } | |
1244 | ||
1245 | arvif->tx_seq_no = 0x1000; | |
1246 | ||
1247 | ret = ath10k_vdev_start(arvif); | |
1248 | if (ret) | |
1249 | return; | |
1250 | ||
c930f744 | 1251 | arvif->aid = 0; |
b25f32cb | 1252 | ether_addr_copy(arvif->bssid, info->bssid); |
c930f744 MK |
1253 | |
1254 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
1255 | arvif->bssid); | |
5e3dd157 | 1256 | if (ret) { |
7aa7a72a | 1257 | ath10k_warn(ar, "failed to bring up vdev %d: %i\n", |
69244e56 | 1258 | arvif->vdev_id, ret); |
c930f744 | 1259 | ath10k_vdev_stop(arvif); |
5e3dd157 KV |
1260 | return; |
1261 | } | |
c930f744 MK |
1262 | |
1263 | arvif->is_started = true; | |
1264 | arvif->is_up = true; | |
1265 | ||
7aa7a72a | 1266 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); |
5e3dd157 KV |
1267 | } |
1268 | ||
1269 | static void ath10k_control_ibss(struct ath10k_vif *arvif, | |
1270 | struct ieee80211_bss_conf *info, | |
1271 | const u8 self_peer[ETH_ALEN]) | |
1272 | { | |
7aa7a72a | 1273 | struct ath10k *ar = arvif->ar; |
6d1506e7 | 1274 | u32 vdev_param; |
5e3dd157 KV |
1275 | int ret = 0; |
1276 | ||
548db54c MK |
1277 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1278 | ||
5e3dd157 KV |
1279 | if (!info->ibss_joined) { |
1280 | ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer); | |
1281 | if (ret) | |
7aa7a72a | 1282 | ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n", |
5e3dd157 KV |
1283 | self_peer, arvif->vdev_id, ret); |
1284 | ||
c930f744 | 1285 | if (is_zero_ether_addr(arvif->bssid)) |
5e3dd157 KV |
1286 | return; |
1287 | ||
c930f744 | 1288 | memset(arvif->bssid, 0, ETH_ALEN); |
5e3dd157 KV |
1289 | |
1290 | return; | |
1291 | } | |
1292 | ||
1293 | ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer); | |
1294 | if (ret) { | |
7aa7a72a | 1295 | ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n", |
5e3dd157 KV |
1296 | self_peer, arvif->vdev_id, ret); |
1297 | return; | |
1298 | } | |
1299 | ||
6d1506e7 BM |
1300 | vdev_param = arvif->ar->wmi.vdev_param->atim_window; |
1301 | ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
1302 | ATH10K_DEFAULT_ATIM); |
1303 | if (ret) | |
7aa7a72a | 1304 | ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n", |
5e3dd157 KV |
1305 | arvif->vdev_id, ret); |
1306 | } | |
1307 | ||
9f9b5746 MK |
1308 | static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif) |
1309 | { | |
1310 | struct ath10k *ar = arvif->ar; | |
1311 | u32 param; | |
1312 | u32 value; | |
1313 | int ret; | |
1314 | ||
1315 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1316 | ||
1317 | if (arvif->u.sta.uapsd) | |
1318 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER; | |
1319 | else | |
1320 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; | |
1321 | ||
1322 | param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; | |
1323 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value); | |
1324 | if (ret) { | |
1325 | ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n", | |
1326 | value, arvif->vdev_id, ret); | |
1327 | return ret; | |
1328 | } | |
1329 | ||
1330 | return 0; | |
1331 | } | |
1332 | ||
1333 | static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif) | |
1334 | { | |
1335 | struct ath10k *ar = arvif->ar; | |
1336 | u32 param; | |
1337 | u32 value; | |
1338 | int ret; | |
1339 | ||
1340 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1341 | ||
1342 | if (arvif->u.sta.uapsd) | |
1343 | value = WMI_STA_PS_PSPOLL_COUNT_UAPSD; | |
1344 | else | |
1345 | value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; | |
1346 | ||
1347 | param = WMI_STA_PS_PARAM_PSPOLL_COUNT; | |
1348 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
1349 | param, value); | |
1350 | if (ret) { | |
1351 | ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n", | |
1352 | value, arvif->vdev_id, ret); | |
1353 | return ret; | |
1354 | } | |
1355 | ||
1356 | return 0; | |
1357 | } | |
1358 | ||
cffb41f3 MK |
1359 | static int ath10k_mac_ps_vif_count(struct ath10k *ar) |
1360 | { | |
1361 | struct ath10k_vif *arvif; | |
1362 | int num = 0; | |
1363 | ||
1364 | lockdep_assert_held(&ar->conf_mutex); | |
1365 | ||
1366 | list_for_each_entry(arvif, &ar->arvifs, list) | |
1367 | if (arvif->ps) | |
1368 | num++; | |
1369 | ||
1370 | return num; | |
1371 | } | |
1372 | ||
ad088bfa | 1373 | static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif) |
5e3dd157 | 1374 | { |
ad088bfa | 1375 | struct ath10k *ar = arvif->ar; |
526549a8 | 1376 | struct ieee80211_vif *vif = arvif->vif; |
ad088bfa | 1377 | struct ieee80211_conf *conf = &ar->hw->conf; |
5e3dd157 KV |
1378 | enum wmi_sta_powersave_param param; |
1379 | enum wmi_sta_ps_mode psmode; | |
1380 | int ret; | |
526549a8 | 1381 | int ps_timeout; |
cffb41f3 | 1382 | bool enable_ps; |
5e3dd157 | 1383 | |
548db54c MK |
1384 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1385 | ||
ad088bfa MK |
1386 | if (arvif->vif->type != NL80211_IFTYPE_STATION) |
1387 | return 0; | |
5e3dd157 | 1388 | |
cffb41f3 MK |
1389 | enable_ps = arvif->ps; |
1390 | ||
1391 | if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 && | |
1392 | !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT, | |
1393 | ar->fw_features)) { | |
1394 | ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n", | |
1395 | arvif->vdev_id); | |
1396 | enable_ps = false; | |
1397 | } | |
1398 | ||
1399 | if (enable_ps) { | |
5e3dd157 KV |
1400 | psmode = WMI_STA_PS_MODE_ENABLED; |
1401 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; | |
1402 | ||
526549a8 MK |
1403 | ps_timeout = conf->dynamic_ps_timeout; |
1404 | if (ps_timeout == 0) { | |
1405 | /* Firmware doesn't like 0 */ | |
1406 | ps_timeout = ieee80211_tu_to_usec( | |
1407 | vif->bss_conf.beacon_int) / 1000; | |
1408 | } | |
1409 | ||
ad088bfa | 1410 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
526549a8 | 1411 | ps_timeout); |
5e3dd157 | 1412 | if (ret) { |
7aa7a72a | 1413 | ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n", |
69244e56 | 1414 | arvif->vdev_id, ret); |
ad088bfa | 1415 | return ret; |
5e3dd157 | 1416 | } |
5e3dd157 KV |
1417 | } else { |
1418 | psmode = WMI_STA_PS_MODE_DISABLED; | |
1419 | } | |
1420 | ||
7aa7a72a | 1421 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n", |
60c3daa8 KV |
1422 | arvif->vdev_id, psmode ? "enable" : "disable"); |
1423 | ||
ad088bfa MK |
1424 | ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode); |
1425 | if (ret) { | |
7aa7a72a | 1426 | ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n", |
be6546fc | 1427 | psmode, arvif->vdev_id, ret); |
ad088bfa MK |
1428 | return ret; |
1429 | } | |
1430 | ||
1431 | return 0; | |
5e3dd157 KV |
1432 | } |
1433 | ||
46725b15 MK |
1434 | static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif) |
1435 | { | |
1436 | struct ath10k *ar = arvif->ar; | |
1437 | struct wmi_sta_keepalive_arg arg = {}; | |
1438 | int ret; | |
1439 | ||
1440 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1441 | ||
1442 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) | |
1443 | return 0; | |
1444 | ||
1445 | if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map)) | |
1446 | return 0; | |
1447 | ||
1448 | /* Some firmware revisions have a bug and ignore the `enabled` field. | |
1449 | * Instead use the interval to disable the keepalive. | |
1450 | */ | |
1451 | arg.vdev_id = arvif->vdev_id; | |
1452 | arg.enabled = 1; | |
1453 | arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME; | |
1454 | arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE; | |
1455 | ||
1456 | ret = ath10k_wmi_sta_keepalive(ar, &arg); | |
1457 | if (ret) { | |
1458 | ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n", | |
1459 | arvif->vdev_id, ret); | |
1460 | return ret; | |
1461 | } | |
1462 | ||
1463 | return 0; | |
1464 | } | |
1465 | ||
81a9a17d MK |
1466 | static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif) |
1467 | { | |
1468 | struct ath10k *ar = arvif->ar; | |
1469 | struct ieee80211_vif *vif = arvif->vif; | |
1470 | int ret; | |
1471 | ||
8513d95b MK |
1472 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1473 | ||
1474 | if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))) | |
1475 | return; | |
1476 | ||
81a9a17d MK |
1477 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
1478 | return; | |
1479 | ||
1480 | if (!vif->csa_active) | |
1481 | return; | |
1482 | ||
1483 | if (!arvif->is_up) | |
1484 | return; | |
1485 | ||
1486 | if (!ieee80211_csa_is_complete(vif)) { | |
1487 | ieee80211_csa_update_counter(vif); | |
1488 | ||
1489 | ret = ath10k_mac_setup_bcn_tmpl(arvif); | |
1490 | if (ret) | |
1491 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", | |
1492 | ret); | |
1493 | ||
1494 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
1495 | if (ret) | |
1496 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", | |
1497 | ret); | |
1498 | } else { | |
1499 | ieee80211_csa_finish(vif); | |
1500 | } | |
1501 | } | |
1502 | ||
1503 | static void ath10k_mac_vif_ap_csa_work(struct work_struct *work) | |
1504 | { | |
1505 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, | |
1506 | ap_csa_work); | |
1507 | struct ath10k *ar = arvif->ar; | |
1508 | ||
1509 | mutex_lock(&ar->conf_mutex); | |
1510 | ath10k_mac_vif_ap_csa_count_down(arvif); | |
1511 | mutex_unlock(&ar->conf_mutex); | |
1512 | } | |
1513 | ||
cc9904e6 MK |
1514 | static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac, |
1515 | struct ieee80211_vif *vif) | |
1516 | { | |
1517 | struct sk_buff *skb = data; | |
1518 | struct ieee80211_mgmt *mgmt = (void *)skb->data; | |
1519 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
1520 | ||
1521 | if (vif->type != NL80211_IFTYPE_STATION) | |
1522 | return; | |
1523 | ||
1524 | if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) | |
1525 | return; | |
1526 | ||
1527 | cancel_delayed_work(&arvif->connection_loss_work); | |
1528 | } | |
1529 | ||
1530 | void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb) | |
1531 | { | |
1532 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
1533 | IEEE80211_IFACE_ITER_NORMAL, | |
1534 | ath10k_mac_handle_beacon_iter, | |
1535 | skb); | |
1536 | } | |
1537 | ||
1538 | static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac, | |
1539 | struct ieee80211_vif *vif) | |
1540 | { | |
1541 | u32 *vdev_id = data; | |
1542 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
1543 | struct ath10k *ar = arvif->ar; | |
1544 | struct ieee80211_hw *hw = ar->hw; | |
1545 | ||
1546 | if (arvif->vdev_id != *vdev_id) | |
1547 | return; | |
1548 | ||
1549 | if (!arvif->is_up) | |
1550 | return; | |
1551 | ||
1552 | ieee80211_beacon_loss(vif); | |
1553 | ||
1554 | /* Firmware doesn't report beacon loss events repeatedly. If AP probe | |
1555 | * (done by mac80211) succeeds but beacons do not resume then it | |
1556 | * doesn't make sense to continue operation. Queue connection loss work | |
1557 | * which can be cancelled when beacon is received. | |
1558 | */ | |
1559 | ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, | |
1560 | ATH10K_CONNECTION_LOSS_HZ); | |
1561 | } | |
1562 | ||
1563 | void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id) | |
1564 | { | |
1565 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
1566 | IEEE80211_IFACE_ITER_NORMAL, | |
1567 | ath10k_mac_handle_beacon_miss_iter, | |
1568 | &vdev_id); | |
1569 | } | |
1570 | ||
1571 | static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work) | |
1572 | { | |
1573 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, | |
1574 | connection_loss_work.work); | |
1575 | struct ieee80211_vif *vif = arvif->vif; | |
1576 | ||
1577 | if (!arvif->is_up) | |
1578 | return; | |
1579 | ||
1580 | ieee80211_connection_loss(vif); | |
1581 | } | |
1582 | ||
5e3dd157 KV |
1583 | /**********************/ |
1584 | /* Station management */ | |
1585 | /**********************/ | |
1586 | ||
590922a8 MK |
1587 | static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar, |
1588 | struct ieee80211_vif *vif) | |
1589 | { | |
1590 | /* Some firmware revisions have unstable STA powersave when listen | |
1591 | * interval is set too high (e.g. 5). The symptoms are firmware doesn't | |
1592 | * generate NullFunc frames properly even if buffered frames have been | |
1593 | * indicated in Beacon TIM. Firmware would seldom wake up to pull | |
1594 | * buffered frames. Often pinging the device from AP would simply fail. | |
1595 | * | |
1596 | * As a workaround set it to 1. | |
1597 | */ | |
1598 | if (vif->type == NL80211_IFTYPE_STATION) | |
1599 | return 1; | |
1600 | ||
1601 | return ar->hw->conf.listen_interval; | |
1602 | } | |
1603 | ||
5e3dd157 | 1604 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
590922a8 | 1605 | struct ieee80211_vif *vif, |
5e3dd157 | 1606 | struct ieee80211_sta *sta, |
5e3dd157 KV |
1607 | struct wmi_peer_assoc_complete_arg *arg) |
1608 | { | |
590922a8 MK |
1609 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
1610 | ||
548db54c MK |
1611 | lockdep_assert_held(&ar->conf_mutex); |
1612 | ||
b25f32cb | 1613 | ether_addr_copy(arg->addr, sta->addr); |
5e3dd157 KV |
1614 | arg->vdev_id = arvif->vdev_id; |
1615 | arg->peer_aid = sta->aid; | |
1616 | arg->peer_flags |= WMI_PEER_AUTH; | |
590922a8 | 1617 | arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif); |
5e3dd157 | 1618 | arg->peer_num_spatial_streams = 1; |
590922a8 | 1619 | arg->peer_caps = vif->bss_conf.assoc_capability; |
5e3dd157 KV |
1620 | } |
1621 | ||
1622 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, | |
590922a8 | 1623 | struct ieee80211_vif *vif, |
5e3dd157 KV |
1624 | struct wmi_peer_assoc_complete_arg *arg) |
1625 | { | |
5e3dd157 KV |
1626 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
1627 | struct cfg80211_bss *bss; | |
1628 | const u8 *rsnie = NULL; | |
1629 | const u8 *wpaie = NULL; | |
1630 | ||
548db54c MK |
1631 | lockdep_assert_held(&ar->conf_mutex); |
1632 | ||
5e3dd157 KV |
1633 | bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan, |
1634 | info->bssid, NULL, 0, 0, 0); | |
1635 | if (bss) { | |
1636 | const struct cfg80211_bss_ies *ies; | |
1637 | ||
1638 | rcu_read_lock(); | |
1639 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); | |
1640 | ||
1641 | ies = rcu_dereference(bss->ies); | |
1642 | ||
1643 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
5b07e07f KV |
1644 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
1645 | ies->data, | |
1646 | ies->len); | |
5e3dd157 KV |
1647 | rcu_read_unlock(); |
1648 | cfg80211_put_bss(ar->hw->wiphy, bss); | |
1649 | } | |
1650 | ||
1651 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ | |
1652 | if (rsnie || wpaie) { | |
7aa7a72a | 1653 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
5e3dd157 KV |
1654 | arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; |
1655 | } | |
1656 | ||
1657 | if (wpaie) { | |
7aa7a72a | 1658 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
5e3dd157 KV |
1659 | arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; |
1660 | } | |
1661 | } | |
1662 | ||
1663 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, | |
1664 | struct ieee80211_sta *sta, | |
1665 | struct wmi_peer_assoc_complete_arg *arg) | |
1666 | { | |
1667 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; | |
1668 | const struct ieee80211_supported_band *sband; | |
1669 | const struct ieee80211_rate *rates; | |
1670 | u32 ratemask; | |
1671 | int i; | |
1672 | ||
548db54c MK |
1673 | lockdep_assert_held(&ar->conf_mutex); |
1674 | ||
5e3dd157 KV |
1675 | sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band]; |
1676 | ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band]; | |
1677 | rates = sband->bitrates; | |
1678 | ||
1679 | rateset->num_rates = 0; | |
1680 | ||
1681 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { | |
1682 | if (!(ratemask & 1)) | |
1683 | continue; | |
1684 | ||
1685 | rateset->rates[rateset->num_rates] = rates->hw_value; | |
1686 | rateset->num_rates++; | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, | |
1691 | struct ieee80211_sta *sta, | |
1692 | struct wmi_peer_assoc_complete_arg *arg) | |
1693 | { | |
1694 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | |
5e3dd157 | 1695 | int i, n; |
af762c0b | 1696 | u32 stbc; |
5e3dd157 | 1697 | |
548db54c MK |
1698 | lockdep_assert_held(&ar->conf_mutex); |
1699 | ||
5e3dd157 KV |
1700 | if (!ht_cap->ht_supported) |
1701 | return; | |
1702 | ||
1703 | arg->peer_flags |= WMI_PEER_HT; | |
1704 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
1705 | ht_cap->ampdu_factor)) - 1; | |
1706 | ||
1707 | arg->peer_mpdu_density = | |
1708 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); | |
1709 | ||
1710 | arg->peer_ht_caps = ht_cap->cap; | |
1711 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; | |
1712 | ||
1713 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) | |
1714 | arg->peer_flags |= WMI_PEER_LDPC; | |
1715 | ||
1716 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { | |
1717 | arg->peer_flags |= WMI_PEER_40MHZ; | |
1718 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; | |
1719 | } | |
1720 | ||
1721 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) | |
1722 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; | |
1723 | ||
1724 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) | |
1725 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; | |
1726 | ||
1727 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { | |
1728 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; | |
1729 | arg->peer_flags |= WMI_PEER_STBC; | |
1730 | } | |
1731 | ||
1732 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { | |
5e3dd157 KV |
1733 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
1734 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
1735 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; | |
1736 | arg->peer_rate_caps |= stbc; | |
1737 | arg->peer_flags |= WMI_PEER_STBC; | |
1738 | } | |
1739 | ||
5e3dd157 KV |
1740 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
1741 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; | |
1742 | else if (ht_cap->mcs.rx_mask[1]) | |
1743 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; | |
1744 | ||
1745 | for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++) | |
1746 | if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8)) | |
1747 | arg->peer_ht_rates.rates[n++] = i; | |
1748 | ||
fd71f807 BM |
1749 | /* |
1750 | * This is a workaround for HT-enabled STAs which break the spec | |
1751 | * and have no HT capabilities RX mask (no HT RX MCS map). | |
1752 | * | |
1753 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), | |
1754 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. | |
1755 | * | |
1756 | * Firmware asserts if such situation occurs. | |
1757 | */ | |
1758 | if (n == 0) { | |
1759 | arg->peer_ht_rates.num_rates = 8; | |
1760 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) | |
1761 | arg->peer_ht_rates.rates[i] = i; | |
1762 | } else { | |
1763 | arg->peer_ht_rates.num_rates = n; | |
1764 | arg->peer_num_spatial_streams = sta->rx_nss; | |
1765 | } | |
5e3dd157 | 1766 | |
7aa7a72a | 1767 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", |
60c3daa8 | 1768 | arg->addr, |
5e3dd157 KV |
1769 | arg->peer_ht_rates.num_rates, |
1770 | arg->peer_num_spatial_streams); | |
1771 | } | |
1772 | ||
d3d3ff42 JD |
1773 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
1774 | struct ath10k_vif *arvif, | |
1775 | struct ieee80211_sta *sta) | |
5e3dd157 KV |
1776 | { |
1777 | u32 uapsd = 0; | |
1778 | u32 max_sp = 0; | |
d3d3ff42 | 1779 | int ret = 0; |
5e3dd157 | 1780 | |
548db54c MK |
1781 | lockdep_assert_held(&ar->conf_mutex); |
1782 | ||
5e3dd157 | 1783 | if (sta->wme && sta->uapsd_queues) { |
7aa7a72a | 1784 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", |
5e3dd157 KV |
1785 | sta->uapsd_queues, sta->max_sp); |
1786 | ||
5e3dd157 KV |
1787 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
1788 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | | |
1789 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; | |
1790 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) | |
1791 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | | |
1792 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; | |
1793 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) | |
1794 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | | |
1795 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; | |
1796 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) | |
1797 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | | |
1798 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; | |
1799 | ||
5e3dd157 KV |
1800 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
1801 | max_sp = sta->max_sp; | |
1802 | ||
d3d3ff42 JD |
1803 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
1804 | sta->addr, | |
1805 | WMI_AP_PS_PEER_PARAM_UAPSD, | |
1806 | uapsd); | |
1807 | if (ret) { | |
7aa7a72a | 1808 | ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n", |
69244e56 | 1809 | arvif->vdev_id, ret); |
d3d3ff42 JD |
1810 | return ret; |
1811 | } | |
5e3dd157 | 1812 | |
d3d3ff42 JD |
1813 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
1814 | sta->addr, | |
1815 | WMI_AP_PS_PEER_PARAM_MAX_SP, | |
1816 | max_sp); | |
1817 | if (ret) { | |
7aa7a72a | 1818 | ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n", |
69244e56 | 1819 | arvif->vdev_id, ret); |
d3d3ff42 JD |
1820 | return ret; |
1821 | } | |
5e3dd157 KV |
1822 | |
1823 | /* TODO setup this based on STA listen interval and | |
1824 | beacon interval. Currently we don't know | |
1825 | sta->listen_interval - mac80211 patch required. | |
1826 | Currently use 10 seconds */ | |
d3d3ff42 | 1827 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr, |
5b07e07f KV |
1828 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, |
1829 | 10); | |
d3d3ff42 | 1830 | if (ret) { |
7aa7a72a | 1831 | ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n", |
69244e56 | 1832 | arvif->vdev_id, ret); |
d3d3ff42 JD |
1833 | return ret; |
1834 | } | |
5e3dd157 | 1835 | } |
5e3dd157 | 1836 | |
d3d3ff42 | 1837 | return 0; |
5e3dd157 KV |
1838 | } |
1839 | ||
1840 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, | |
1841 | struct ieee80211_sta *sta, | |
1842 | struct wmi_peer_assoc_complete_arg *arg) | |
1843 | { | |
1844 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; | |
a24b88b5 | 1845 | u8 ampdu_factor; |
5e3dd157 KV |
1846 | |
1847 | if (!vht_cap->vht_supported) | |
1848 | return; | |
1849 | ||
1850 | arg->peer_flags |= WMI_PEER_VHT; | |
d68bb12a YL |
1851 | |
1852 | if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) | |
1853 | arg->peer_flags |= WMI_PEER_VHT_2G; | |
1854 | ||
5e3dd157 KV |
1855 | arg->peer_vht_caps = vht_cap->cap; |
1856 | ||
a24b88b5 SM |
1857 | ampdu_factor = (vht_cap->cap & |
1858 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> | |
1859 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
1860 | ||
1861 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to | |
1862 | * zero in VHT IE. Using it would result in degraded throughput. | |
1863 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep | |
1864 | * it if VHT max_mpdu is smaller. */ | |
1865 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, | |
1866 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
1867 | ampdu_factor)) - 1); | |
1868 | ||
5e3dd157 KV |
1869 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
1870 | arg->peer_flags |= WMI_PEER_80MHZ; | |
1871 | ||
1872 | arg->peer_vht_rates.rx_max_rate = | |
1873 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); | |
1874 | arg->peer_vht_rates.rx_mcs_set = | |
1875 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); | |
1876 | arg->peer_vht_rates.tx_max_rate = | |
1877 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); | |
1878 | arg->peer_vht_rates.tx_mcs_set = | |
1879 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); | |
1880 | ||
7aa7a72a | 1881 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", |
60c3daa8 | 1882 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
5e3dd157 KV |
1883 | } |
1884 | ||
1885 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, | |
590922a8 | 1886 | struct ieee80211_vif *vif, |
5e3dd157 | 1887 | struct ieee80211_sta *sta, |
5e3dd157 KV |
1888 | struct wmi_peer_assoc_complete_arg *arg) |
1889 | { | |
590922a8 MK |
1890 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
1891 | ||
5e3dd157 KV |
1892 | switch (arvif->vdev_type) { |
1893 | case WMI_VDEV_TYPE_AP: | |
d3d3ff42 JD |
1894 | if (sta->wme) |
1895 | arg->peer_flags |= WMI_PEER_QOS; | |
1896 | ||
1897 | if (sta->wme && sta->uapsd_queues) { | |
1898 | arg->peer_flags |= WMI_PEER_APSD; | |
1899 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; | |
1900 | } | |
5e3dd157 KV |
1901 | break; |
1902 | case WMI_VDEV_TYPE_STA: | |
590922a8 | 1903 | if (vif->bss_conf.qos) |
d3d3ff42 | 1904 | arg->peer_flags |= WMI_PEER_QOS; |
5e3dd157 | 1905 | break; |
627d9841 JD |
1906 | case WMI_VDEV_TYPE_IBSS: |
1907 | if (sta->wme) | |
1908 | arg->peer_flags |= WMI_PEER_QOS; | |
1909 | break; | |
5e3dd157 KV |
1910 | default: |
1911 | break; | |
1912 | } | |
627d9841 JD |
1913 | |
1914 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n", | |
1915 | sta->addr, !!(arg->peer_flags & WMI_PEER_QOS)); | |
5e3dd157 KV |
1916 | } |
1917 | ||
91b12089 MK |
1918 | static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta) |
1919 | { | |
1920 | /* First 4 rates in ath10k_rates are CCK (11b) rates. */ | |
1921 | return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4; | |
1922 | } | |
1923 | ||
5e3dd157 | 1924 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
590922a8 | 1925 | struct ieee80211_vif *vif, |
5e3dd157 KV |
1926 | struct ieee80211_sta *sta, |
1927 | struct wmi_peer_assoc_complete_arg *arg) | |
1928 | { | |
1929 | enum wmi_phy_mode phymode = MODE_UNKNOWN; | |
1930 | ||
5e3dd157 KV |
1931 | switch (ar->hw->conf.chandef.chan->band) { |
1932 | case IEEE80211_BAND_2GHZ: | |
d68bb12a YL |
1933 | if (sta->vht_cap.vht_supported) { |
1934 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1935 | phymode = MODE_11AC_VHT40; | |
1936 | else | |
1937 | phymode = MODE_11AC_VHT20; | |
1938 | } else if (sta->ht_cap.ht_supported) { | |
5e3dd157 KV |
1939 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
1940 | phymode = MODE_11NG_HT40; | |
1941 | else | |
1942 | phymode = MODE_11NG_HT20; | |
91b12089 | 1943 | } else if (ath10k_mac_sta_has_11g_rates(sta)) { |
5e3dd157 | 1944 | phymode = MODE_11G; |
91b12089 MK |
1945 | } else { |
1946 | phymode = MODE_11B; | |
5e3dd157 KV |
1947 | } |
1948 | ||
1949 | break; | |
1950 | case IEEE80211_BAND_5GHZ: | |
7cc45e98 SM |
1951 | /* |
1952 | * Check VHT first. | |
1953 | */ | |
1954 | if (sta->vht_cap.vht_supported) { | |
1955 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) | |
1956 | phymode = MODE_11AC_VHT80; | |
1957 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1958 | phymode = MODE_11AC_VHT40; | |
1959 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_20) | |
1960 | phymode = MODE_11AC_VHT20; | |
1961 | } else if (sta->ht_cap.ht_supported) { | |
5e3dd157 KV |
1962 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
1963 | phymode = MODE_11NA_HT40; | |
1964 | else | |
1965 | phymode = MODE_11NA_HT20; | |
1966 | } else { | |
1967 | phymode = MODE_11A; | |
1968 | } | |
1969 | ||
1970 | break; | |
1971 | default: | |
1972 | break; | |
1973 | } | |
1974 | ||
7aa7a72a | 1975 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
38a1d47e | 1976 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
60c3daa8 | 1977 | |
5e3dd157 KV |
1978 | arg->peer_phymode = phymode; |
1979 | WARN_ON(phymode == MODE_UNKNOWN); | |
1980 | } | |
1981 | ||
b9ada65d | 1982 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
590922a8 | 1983 | struct ieee80211_vif *vif, |
b9ada65d | 1984 | struct ieee80211_sta *sta, |
b9ada65d | 1985 | struct wmi_peer_assoc_complete_arg *arg) |
5e3dd157 | 1986 | { |
548db54c MK |
1987 | lockdep_assert_held(&ar->conf_mutex); |
1988 | ||
b9ada65d | 1989 | memset(arg, 0, sizeof(*arg)); |
5e3dd157 | 1990 | |
590922a8 MK |
1991 | ath10k_peer_assoc_h_basic(ar, vif, sta, arg); |
1992 | ath10k_peer_assoc_h_crypto(ar, vif, arg); | |
b9ada65d KV |
1993 | ath10k_peer_assoc_h_rates(ar, sta, arg); |
1994 | ath10k_peer_assoc_h_ht(ar, sta, arg); | |
1995 | ath10k_peer_assoc_h_vht(ar, sta, arg); | |
590922a8 MK |
1996 | ath10k_peer_assoc_h_qos(ar, vif, sta, arg); |
1997 | ath10k_peer_assoc_h_phymode(ar, vif, sta, arg); | |
5e3dd157 | 1998 | |
b9ada65d | 1999 | return 0; |
5e3dd157 KV |
2000 | } |
2001 | ||
90046f50 MK |
2002 | static const u32 ath10k_smps_map[] = { |
2003 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, | |
2004 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, | |
2005 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, | |
2006 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, | |
2007 | }; | |
2008 | ||
2009 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, | |
2010 | const u8 *addr, | |
2011 | const struct ieee80211_sta_ht_cap *ht_cap) | |
2012 | { | |
2013 | int smps; | |
2014 | ||
2015 | if (!ht_cap->ht_supported) | |
2016 | return 0; | |
2017 | ||
2018 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; | |
2019 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
2020 | ||
2021 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) | |
2022 | return -EINVAL; | |
2023 | ||
2024 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, | |
2025 | WMI_PEER_SMPS_STATE, | |
2026 | ath10k_smps_map[smps]); | |
2027 | } | |
2028 | ||
139e170d MK |
2029 | static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, |
2030 | struct ieee80211_vif *vif, | |
2031 | struct ieee80211_sta_vht_cap vht_cap) | |
2032 | { | |
2033 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
2034 | int ret; | |
2035 | u32 param; | |
2036 | u32 value; | |
2037 | ||
2038 | if (!(ar->vht_cap_info & | |
2039 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
2040 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | | |
2041 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
2042 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) | |
2043 | return 0; | |
2044 | ||
2045 | param = ar->wmi.vdev_param->txbf; | |
2046 | value = 0; | |
2047 | ||
2048 | if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED)) | |
2049 | return 0; | |
2050 | ||
2051 | /* The following logic is correct. If a remote STA advertises support | |
2052 | * for being a beamformer then we should enable us being a beamformee. | |
2053 | */ | |
2054 | ||
2055 | if (ar->vht_cap_info & | |
2056 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
2057 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { | |
2058 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) | |
2059 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
2060 | ||
2061 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) | |
2062 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; | |
2063 | } | |
2064 | ||
2065 | if (ar->vht_cap_info & | |
2066 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
2067 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { | |
2068 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) | |
2069 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
2070 | ||
2071 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) | |
2072 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; | |
2073 | } | |
2074 | ||
2075 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE) | |
2076 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
2077 | ||
2078 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER) | |
2079 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
2080 | ||
2081 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value); | |
2082 | if (ret) { | |
2083 | ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n", | |
2084 | value, ret); | |
2085 | return ret; | |
2086 | } | |
2087 | ||
2088 | return 0; | |
2089 | } | |
2090 | ||
5e3dd157 KV |
2091 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
2092 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, | |
2093 | struct ieee80211_vif *vif, | |
2094 | struct ieee80211_bss_conf *bss_conf) | |
2095 | { | |
2096 | struct ath10k *ar = hw->priv; | |
2097 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
90046f50 | 2098 | struct ieee80211_sta_ht_cap ht_cap; |
139e170d | 2099 | struct ieee80211_sta_vht_cap vht_cap; |
b9ada65d | 2100 | struct wmi_peer_assoc_complete_arg peer_arg; |
5e3dd157 KV |
2101 | struct ieee80211_sta *ap_sta; |
2102 | int ret; | |
2103 | ||
548db54c MK |
2104 | lockdep_assert_held(&ar->conf_mutex); |
2105 | ||
077efc8c MK |
2106 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", |
2107 | arvif->vdev_id, arvif->bssid, arvif->aid); | |
2108 | ||
5e3dd157 KV |
2109 | rcu_read_lock(); |
2110 | ||
2111 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
2112 | if (!ap_sta) { | |
7aa7a72a | 2113 | ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n", |
69244e56 | 2114 | bss_conf->bssid, arvif->vdev_id); |
5e3dd157 KV |
2115 | rcu_read_unlock(); |
2116 | return; | |
2117 | } | |
2118 | ||
90046f50 MK |
2119 | /* ap_sta must be accessed only within rcu section which must be left |
2120 | * before calling ath10k_setup_peer_smps() which might sleep. */ | |
2121 | ht_cap = ap_sta->ht_cap; | |
139e170d | 2122 | vht_cap = ap_sta->vht_cap; |
90046f50 | 2123 | |
590922a8 | 2124 | ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg); |
5e3dd157 | 2125 | if (ret) { |
7aa7a72a | 2126 | ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n", |
69244e56 | 2127 | bss_conf->bssid, arvif->vdev_id, ret); |
5e3dd157 KV |
2128 | rcu_read_unlock(); |
2129 | return; | |
2130 | } | |
2131 | ||
2132 | rcu_read_unlock(); | |
2133 | ||
b9ada65d KV |
2134 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
2135 | if (ret) { | |
7aa7a72a | 2136 | ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n", |
69244e56 | 2137 | bss_conf->bssid, arvif->vdev_id, ret); |
b9ada65d KV |
2138 | return; |
2139 | } | |
2140 | ||
90046f50 MK |
2141 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
2142 | if (ret) { | |
7aa7a72a | 2143 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n", |
69244e56 | 2144 | arvif->vdev_id, ret); |
90046f50 MK |
2145 | return; |
2146 | } | |
2147 | ||
139e170d MK |
2148 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
2149 | if (ret) { | |
2150 | ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n", | |
2151 | arvif->vdev_id, bss_conf->bssid, ret); | |
2152 | return; | |
2153 | } | |
2154 | ||
7aa7a72a | 2155 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
2156 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
2157 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); | |
2158 | ||
077efc8c MK |
2159 | WARN_ON(arvif->is_up); |
2160 | ||
c930f744 | 2161 | arvif->aid = bss_conf->aid; |
b25f32cb | 2162 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
c930f744 MK |
2163 | |
2164 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); | |
2165 | if (ret) { | |
7aa7a72a | 2166 | ath10k_warn(ar, "failed to set vdev %d up: %d\n", |
5e3dd157 | 2167 | arvif->vdev_id, ret); |
c930f744 MK |
2168 | return; |
2169 | } | |
2170 | ||
2171 | arvif->is_up = true; | |
0a987fb0 MK |
2172 | |
2173 | /* Workaround: Some firmware revisions (tested with qca6174 | |
2174 | * WLAN.RM.2.0-00073) have buggy powersave state machine and must be | |
2175 | * poked with peer param command. | |
2176 | */ | |
2177 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid, | |
2178 | WMI_PEER_DUMMY_VAR, 1); | |
2179 | if (ret) { | |
2180 | ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n", | |
2181 | arvif->bssid, arvif->vdev_id, ret); | |
2182 | return; | |
2183 | } | |
5e3dd157 KV |
2184 | } |
2185 | ||
5e3dd157 KV |
2186 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
2187 | struct ieee80211_vif *vif) | |
2188 | { | |
2189 | struct ath10k *ar = hw->priv; | |
2190 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
139e170d | 2191 | struct ieee80211_sta_vht_cap vht_cap = {}; |
5e3dd157 KV |
2192 | int ret; |
2193 | ||
548db54c MK |
2194 | lockdep_assert_held(&ar->conf_mutex); |
2195 | ||
077efc8c MK |
2196 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
2197 | arvif->vdev_id, arvif->bssid); | |
60c3daa8 | 2198 | |
5e3dd157 | 2199 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
077efc8c MK |
2200 | if (ret) |
2201 | ath10k_warn(ar, "faield to down vdev %i: %d\n", | |
2202 | arvif->vdev_id, ret); | |
5e3dd157 | 2203 | |
627613f8 SJ |
2204 | arvif->def_wep_key_idx = -1; |
2205 | ||
139e170d MK |
2206 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
2207 | if (ret) { | |
2208 | ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n", | |
2209 | arvif->vdev_id, ret); | |
2210 | return; | |
2211 | } | |
2212 | ||
c930f744 | 2213 | arvif->is_up = false; |
cc9904e6 MK |
2214 | |
2215 | cancel_delayed_work_sync(&arvif->connection_loss_work); | |
5e3dd157 KV |
2216 | } |
2217 | ||
590922a8 MK |
2218 | static int ath10k_station_assoc(struct ath10k *ar, |
2219 | struct ieee80211_vif *vif, | |
2220 | struct ieee80211_sta *sta, | |
2221 | bool reassoc) | |
5e3dd157 | 2222 | { |
590922a8 | 2223 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
b9ada65d | 2224 | struct wmi_peer_assoc_complete_arg peer_arg; |
5e3dd157 KV |
2225 | int ret = 0; |
2226 | ||
548db54c MK |
2227 | lockdep_assert_held(&ar->conf_mutex); |
2228 | ||
590922a8 | 2229 | ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg); |
b9ada65d | 2230 | if (ret) { |
7aa7a72a | 2231 | ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n", |
69244e56 | 2232 | sta->addr, arvif->vdev_id, ret); |
b9ada65d KV |
2233 | return ret; |
2234 | } | |
2235 | ||
44d6fa90 | 2236 | peer_arg.peer_reassoc = reassoc; |
b9ada65d | 2237 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
5e3dd157 | 2238 | if (ret) { |
7aa7a72a | 2239 | ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n", |
69244e56 | 2240 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 KV |
2241 | return ret; |
2242 | } | |
2243 | ||
b1ecde36 MK |
2244 | /* Re-assoc is run only to update supported rates for given station. It |
2245 | * doesn't make much sense to reconfigure the peer completely. | |
2246 | */ | |
2247 | if (!reassoc) { | |
2248 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, | |
2249 | &sta->ht_cap); | |
e81bd104 | 2250 | if (ret) { |
b1ecde36 | 2251 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n", |
e81bd104 MK |
2252 | arvif->vdev_id, ret); |
2253 | return ret; | |
2254 | } | |
e81bd104 | 2255 | |
b1ecde36 MK |
2256 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
2257 | if (ret) { | |
2258 | ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", | |
2259 | sta->addr, arvif->vdev_id, ret); | |
2260 | return ret; | |
2261 | } | |
5e3dd157 | 2262 | |
b1ecde36 MK |
2263 | if (!sta->wme) { |
2264 | arvif->num_legacy_stations++; | |
2265 | ret = ath10k_recalc_rtscts_prot(arvif); | |
2266 | if (ret) { | |
2267 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", | |
2268 | arvif->vdev_id, ret); | |
2269 | return ret; | |
2270 | } | |
2271 | } | |
2272 | ||
627613f8 SJ |
2273 | /* Plumb cached keys only for static WEP */ |
2274 | if (arvif->def_wep_key_idx != -1) { | |
2275 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); | |
2276 | if (ret) { | |
2277 | ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", | |
2278 | arvif->vdev_id, ret); | |
2279 | return ret; | |
2280 | } | |
b1ecde36 | 2281 | } |
d3d3ff42 JD |
2282 | } |
2283 | ||
5e3dd157 KV |
2284 | return ret; |
2285 | } | |
2286 | ||
590922a8 MK |
2287 | static int ath10k_station_disassoc(struct ath10k *ar, |
2288 | struct ieee80211_vif *vif, | |
5e3dd157 KV |
2289 | struct ieee80211_sta *sta) |
2290 | { | |
590922a8 | 2291 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
5e3dd157 KV |
2292 | int ret = 0; |
2293 | ||
548db54c MK |
2294 | lockdep_assert_held(&ar->conf_mutex); |
2295 | ||
e81bd104 MK |
2296 | if (!sta->wme) { |
2297 | arvif->num_legacy_stations--; | |
2298 | ret = ath10k_recalc_rtscts_prot(arvif); | |
2299 | if (ret) { | |
7aa7a72a | 2300 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
e81bd104 MK |
2301 | arvif->vdev_id, ret); |
2302 | return ret; | |
2303 | } | |
2304 | } | |
2305 | ||
5e3dd157 KV |
2306 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
2307 | if (ret) { | |
7aa7a72a | 2308 | ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n", |
69244e56 | 2309 | arvif->vdev_id, ret); |
5e3dd157 KV |
2310 | return ret; |
2311 | } | |
2312 | ||
2313 | return ret; | |
2314 | } | |
2315 | ||
2316 | /**************/ | |
2317 | /* Regulatory */ | |
2318 | /**************/ | |
2319 | ||
2320 | static int ath10k_update_channel_list(struct ath10k *ar) | |
2321 | { | |
2322 | struct ieee80211_hw *hw = ar->hw; | |
2323 | struct ieee80211_supported_band **bands; | |
2324 | enum ieee80211_band band; | |
2325 | struct ieee80211_channel *channel; | |
2326 | struct wmi_scan_chan_list_arg arg = {0}; | |
2327 | struct wmi_channel_arg *ch; | |
2328 | bool passive; | |
2329 | int len; | |
2330 | int ret; | |
2331 | int i; | |
2332 | ||
548db54c MK |
2333 | lockdep_assert_held(&ar->conf_mutex); |
2334 | ||
5e3dd157 KV |
2335 | bands = hw->wiphy->bands; |
2336 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
2337 | if (!bands[band]) | |
2338 | continue; | |
2339 | ||
2340 | for (i = 0; i < bands[band]->n_channels; i++) { | |
2341 | if (bands[band]->channels[i].flags & | |
2342 | IEEE80211_CHAN_DISABLED) | |
2343 | continue; | |
2344 | ||
2345 | arg.n_channels++; | |
2346 | } | |
2347 | } | |
2348 | ||
2349 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; | |
2350 | arg.channels = kzalloc(len, GFP_KERNEL); | |
2351 | if (!arg.channels) | |
2352 | return -ENOMEM; | |
2353 | ||
2354 | ch = arg.channels; | |
2355 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
2356 | if (!bands[band]) | |
2357 | continue; | |
2358 | ||
2359 | for (i = 0; i < bands[band]->n_channels; i++) { | |
2360 | channel = &bands[band]->channels[i]; | |
2361 | ||
2362 | if (channel->flags & IEEE80211_CHAN_DISABLED) | |
2363 | continue; | |
2364 | ||
2365 | ch->allow_ht = true; | |
2366 | ||
2367 | /* FIXME: when should we really allow VHT? */ | |
2368 | ch->allow_vht = true; | |
2369 | ||
2370 | ch->allow_ibss = | |
8fe02e16 | 2371 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
5e3dd157 KV |
2372 | |
2373 | ch->ht40plus = | |
2374 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); | |
2375 | ||
e8a50f8b MP |
2376 | ch->chan_radar = |
2377 | !!(channel->flags & IEEE80211_CHAN_RADAR); | |
2378 | ||
8fe02e16 | 2379 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
5e3dd157 KV |
2380 | ch->passive = passive; |
2381 | ||
2382 | ch->freq = channel->center_freq; | |
2d66721c | 2383 | ch->band_center_freq1 = channel->center_freq; |
89c5c843 | 2384 | ch->min_power = 0; |
02256930 MK |
2385 | ch->max_power = channel->max_power * 2; |
2386 | ch->max_reg_power = channel->max_reg_power * 2; | |
2387 | ch->max_antenna_gain = channel->max_antenna_gain * 2; | |
5e3dd157 KV |
2388 | ch->reg_class_id = 0; /* FIXME */ |
2389 | ||
2390 | /* FIXME: why use only legacy modes, why not any | |
2391 | * HT/VHT modes? Would that even make any | |
2392 | * difference? */ | |
2393 | if (channel->band == IEEE80211_BAND_2GHZ) | |
2394 | ch->mode = MODE_11G; | |
2395 | else | |
2396 | ch->mode = MODE_11A; | |
2397 | ||
2398 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) | |
2399 | continue; | |
2400 | ||
7aa7a72a | 2401 | ath10k_dbg(ar, ATH10K_DBG_WMI, |
60c3daa8 KV |
2402 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
2403 | ch - arg.channels, arg.n_channels, | |
5e3dd157 KV |
2404 | ch->freq, ch->max_power, ch->max_reg_power, |
2405 | ch->max_antenna_gain, ch->mode); | |
2406 | ||
2407 | ch++; | |
2408 | } | |
2409 | } | |
2410 | ||
2411 | ret = ath10k_wmi_scan_chan_list(ar, &arg); | |
2412 | kfree(arg.channels); | |
2413 | ||
2414 | return ret; | |
2415 | } | |
2416 | ||
821af6ae MP |
2417 | static enum wmi_dfs_region |
2418 | ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region) | |
2419 | { | |
2420 | switch (dfs_region) { | |
2421 | case NL80211_DFS_UNSET: | |
2422 | return WMI_UNINIT_DFS_DOMAIN; | |
2423 | case NL80211_DFS_FCC: | |
2424 | return WMI_FCC_DFS_DOMAIN; | |
2425 | case NL80211_DFS_ETSI: | |
2426 | return WMI_ETSI_DFS_DOMAIN; | |
2427 | case NL80211_DFS_JP: | |
2428 | return WMI_MKK4_DFS_DOMAIN; | |
2429 | } | |
2430 | return WMI_UNINIT_DFS_DOMAIN; | |
2431 | } | |
2432 | ||
f7843d7f | 2433 | static void ath10k_regd_update(struct ath10k *ar) |
5e3dd157 | 2434 | { |
5e3dd157 | 2435 | struct reg_dmn_pair_mapping *regpair; |
5e3dd157 | 2436 | int ret; |
821af6ae MP |
2437 | enum wmi_dfs_region wmi_dfs_reg; |
2438 | enum nl80211_dfs_regions nl_dfs_reg; | |
5e3dd157 | 2439 | |
f7843d7f | 2440 | lockdep_assert_held(&ar->conf_mutex); |
5e3dd157 KV |
2441 | |
2442 | ret = ath10k_update_channel_list(ar); | |
2443 | if (ret) | |
7aa7a72a | 2444 | ath10k_warn(ar, "failed to update channel list: %d\n", ret); |
5e3dd157 KV |
2445 | |
2446 | regpair = ar->ath_common.regulatory.regpair; | |
f7843d7f | 2447 | |
821af6ae MP |
2448 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
2449 | nl_dfs_reg = ar->dfs_detector->region; | |
2450 | wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg); | |
2451 | } else { | |
2452 | wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN; | |
2453 | } | |
2454 | ||
5e3dd157 KV |
2455 | /* Target allows setting up per-band regdomain but ath_common provides |
2456 | * a combined one only */ | |
2457 | ret = ath10k_wmi_pdev_set_regdomain(ar, | |
ef8c0017 KV |
2458 | regpair->reg_domain, |
2459 | regpair->reg_domain, /* 2ghz */ | |
2460 | regpair->reg_domain, /* 5ghz */ | |
5e3dd157 | 2461 | regpair->reg_2ghz_ctl, |
821af6ae MP |
2462 | regpair->reg_5ghz_ctl, |
2463 | wmi_dfs_reg); | |
5e3dd157 | 2464 | if (ret) |
7aa7a72a | 2465 | ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret); |
f7843d7f | 2466 | } |
548db54c | 2467 | |
f7843d7f MK |
2468 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
2469 | struct regulatory_request *request) | |
2470 | { | |
2471 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); | |
2472 | struct ath10k *ar = hw->priv; | |
9702c686 | 2473 | bool result; |
f7843d7f MK |
2474 | |
2475 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); | |
2476 | ||
9702c686 | 2477 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
7aa7a72a | 2478 | ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
9702c686 JD |
2479 | request->dfs_region); |
2480 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, | |
2481 | request->dfs_region); | |
2482 | if (!result) | |
7aa7a72a | 2483 | ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n", |
9702c686 JD |
2484 | request->dfs_region); |
2485 | } | |
2486 | ||
f7843d7f MK |
2487 | mutex_lock(&ar->conf_mutex); |
2488 | if (ar->state == ATH10K_STATE_ON) | |
2489 | ath10k_regd_update(ar); | |
548db54c | 2490 | mutex_unlock(&ar->conf_mutex); |
5e3dd157 KV |
2491 | } |
2492 | ||
2493 | /***************/ | |
2494 | /* TX handlers */ | |
2495 | /***************/ | |
2496 | ||
42c3aa6f MK |
2497 | static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr) |
2498 | { | |
2499 | if (ieee80211_is_mgmt(hdr->frame_control)) | |
2500 | return HTT_DATA_TX_EXT_TID_MGMT; | |
2501 | ||
2502 | if (!ieee80211_is_data_qos(hdr->frame_control)) | |
2503 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; | |
2504 | ||
2505 | if (!is_unicast_ether_addr(ieee80211_get_DA(hdr))) | |
2506 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; | |
2507 | ||
2508 | return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; | |
2509 | } | |
2510 | ||
2b37c295 | 2511 | static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif) |
ddb6ad77 | 2512 | { |
2b37c295 MK |
2513 | if (vif) |
2514 | return ath10k_vif_to_arvif(vif)->vdev_id; | |
ddb6ad77 | 2515 | |
1bbc0975 | 2516 | if (ar->monitor_started) |
ddb6ad77 MK |
2517 | return ar->monitor_vdev_id; |
2518 | ||
7aa7a72a | 2519 | ath10k_warn(ar, "failed to resolve vdev id\n"); |
ddb6ad77 MK |
2520 | return 0; |
2521 | } | |
2522 | ||
4b604558 MK |
2523 | /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS |
2524 | * Control in the header. | |
5e3dd157 | 2525 | */ |
4b604558 | 2526 | static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb) |
5e3dd157 KV |
2527 | { |
2528 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
c21c64d1 | 2529 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
5e3dd157 KV |
2530 | u8 *qos_ctl; |
2531 | ||
2532 | if (!ieee80211_is_data_qos(hdr->frame_control)) | |
2533 | return; | |
2534 | ||
2535 | qos_ctl = ieee80211_get_qos_ctl(hdr); | |
ba0ccd7a MK |
2536 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
2537 | skb->data, (void *)qos_ctl - (void *)skb->data); | |
2538 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); | |
c21c64d1 | 2539 | |
8bad8dcd MK |
2540 | /* Some firmware revisions don't handle sending QoS NullFunc well. |
2541 | * These frames are mainly used for CQM purposes so it doesn't really | |
2542 | * matter whether QoS NullFunc or NullFunc are sent. | |
c21c64d1 | 2543 | */ |
bf0a26d3 | 2544 | hdr = (void *)skb->data; |
8bad8dcd | 2545 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
c21c64d1 | 2546 | cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
8bad8dcd MK |
2547 | |
2548 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA); | |
5e3dd157 KV |
2549 | } |
2550 | ||
4b604558 MK |
2551 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, |
2552 | struct ieee80211_vif *vif, | |
2553 | struct sk_buff *skb) | |
5e3dd157 KV |
2554 | { |
2555 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
5e3dd157 KV |
2556 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
2557 | ||
2558 | /* This is case only for P2P_GO */ | |
2559 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP || | |
2560 | arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) | |
2561 | return; | |
2562 | ||
2563 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { | |
2564 | spin_lock_bh(&ar->data_lock); | |
2565 | if (arvif->u.ap.noa_data) | |
2566 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, | |
2567 | GFP_ATOMIC)) | |
2568 | memcpy(skb_put(skb, arvif->u.ap.noa_len), | |
2569 | arvif->u.ap.noa_data, | |
2570 | arvif->u.ap.noa_len); | |
2571 | spin_unlock_bh(&ar->data_lock); | |
2572 | } | |
2573 | } | |
2574 | ||
8d6d3624 MK |
2575 | static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar) |
2576 | { | |
2577 | /* FIXME: Not really sure since when the behaviour changed. At some | |
2578 | * point new firmware stopped requiring creation of peer entries for | |
2579 | * offchannel tx (and actually creating them causes issues with wmi-htc | |
2580 | * tx credit replenishment and reliability). Assuming it's at least 3.4 | |
2581 | * because that's when the `freq` was introduced to TX_FRM HTT command. | |
2582 | */ | |
2583 | return !(ar->htt.target_version_major >= 3 && | |
2584 | ar->htt.target_version_minor >= 4); | |
2585 | } | |
2586 | ||
5e3dd157 KV |
2587 | static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb) |
2588 | { | |
2589 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
5e00d31a | 2590 | int ret = 0; |
5e3dd157 | 2591 | |
961d4c38 MK |
2592 | if (ar->htt.target_version_major >= 3) { |
2593 | /* Since HTT 3.0 there is no separate mgmt tx command */ | |
2594 | ret = ath10k_htt_tx(&ar->htt, skb); | |
2595 | goto exit; | |
2596 | } | |
2597 | ||
5e00d31a BM |
2598 | if (ieee80211_is_mgmt(hdr->frame_control)) { |
2599 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, | |
2600 | ar->fw_features)) { | |
2601 | if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >= | |
2602 | ATH10K_MAX_NUM_MGMT_PENDING) { | |
7aa7a72a | 2603 | ath10k_warn(ar, "reached WMI management transmit queue limit\n"); |
5e00d31a BM |
2604 | ret = -EBUSY; |
2605 | goto exit; | |
2606 | } | |
2607 | ||
2608 | skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb); | |
2609 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); | |
2610 | } else { | |
2611 | ret = ath10k_htt_mgmt_tx(&ar->htt, skb); | |
2612 | } | |
2613 | } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, | |
2614 | ar->fw_features) && | |
2615 | ieee80211_is_nullfunc(hdr->frame_control)) { | |
5e3dd157 KV |
2616 | /* FW does not report tx status properly for NullFunc frames |
2617 | * unless they are sent through mgmt tx path. mac80211 sends | |
5e00d31a BM |
2618 | * those frames when it detects link/beacon loss and depends |
2619 | * on the tx status to be correct. */ | |
edb8236d | 2620 | ret = ath10k_htt_mgmt_tx(&ar->htt, skb); |
5e00d31a | 2621 | } else { |
edb8236d | 2622 | ret = ath10k_htt_tx(&ar->htt, skb); |
5e00d31a | 2623 | } |
5e3dd157 | 2624 | |
961d4c38 | 2625 | exit: |
5e3dd157 | 2626 | if (ret) { |
7aa7a72a MK |
2627 | ath10k_warn(ar, "failed to transmit packet, dropping: %d\n", |
2628 | ret); | |
5e3dd157 KV |
2629 | ieee80211_free_txskb(ar->hw, skb); |
2630 | } | |
2631 | } | |
2632 | ||
2633 | void ath10k_offchan_tx_purge(struct ath10k *ar) | |
2634 | { | |
2635 | struct sk_buff *skb; | |
2636 | ||
2637 | for (;;) { | |
2638 | skb = skb_dequeue(&ar->offchan_tx_queue); | |
2639 | if (!skb) | |
2640 | break; | |
2641 | ||
2642 | ieee80211_free_txskb(ar->hw, skb); | |
2643 | } | |
2644 | } | |
2645 | ||
2646 | void ath10k_offchan_tx_work(struct work_struct *work) | |
2647 | { | |
2648 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); | |
2649 | struct ath10k_peer *peer; | |
2650 | struct ieee80211_hdr *hdr; | |
2651 | struct sk_buff *skb; | |
2652 | const u8 *peer_addr; | |
2653 | int vdev_id; | |
2654 | int ret; | |
2655 | ||
2656 | /* FW requirement: We must create a peer before FW will send out | |
2657 | * an offchannel frame. Otherwise the frame will be stuck and | |
2658 | * never transmitted. We delete the peer upon tx completion. | |
2659 | * It is unlikely that a peer for offchannel tx will already be | |
2660 | * present. However it may be in some rare cases so account for that. | |
2661 | * Otherwise we might remove a legitimate peer and break stuff. */ | |
2662 | ||
2663 | for (;;) { | |
2664 | skb = skb_dequeue(&ar->offchan_tx_queue); | |
2665 | if (!skb) | |
2666 | break; | |
2667 | ||
2668 | mutex_lock(&ar->conf_mutex); | |
2669 | ||
7aa7a72a | 2670 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n", |
5e3dd157 KV |
2671 | skb); |
2672 | ||
2673 | hdr = (struct ieee80211_hdr *)skb->data; | |
2674 | peer_addr = ieee80211_get_DA(hdr); | |
5e00d31a | 2675 | vdev_id = ATH10K_SKB_CB(skb)->vdev_id; |
5e3dd157 KV |
2676 | |
2677 | spin_lock_bh(&ar->data_lock); | |
2678 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); | |
2679 | spin_unlock_bh(&ar->data_lock); | |
2680 | ||
2681 | if (peer) | |
60c3daa8 | 2682 | /* FIXME: should this use ath10k_warn()? */ |
7aa7a72a | 2683 | ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n", |
5e3dd157 KV |
2684 | peer_addr, vdev_id); |
2685 | ||
2686 | if (!peer) { | |
2687 | ret = ath10k_peer_create(ar, vdev_id, peer_addr); | |
2688 | if (ret) | |
7aa7a72a | 2689 | ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n", |
5e3dd157 KV |
2690 | peer_addr, vdev_id, ret); |
2691 | } | |
2692 | ||
2693 | spin_lock_bh(&ar->data_lock); | |
16735d02 | 2694 | reinit_completion(&ar->offchan_tx_completed); |
5e3dd157 KV |
2695 | ar->offchan_tx_skb = skb; |
2696 | spin_unlock_bh(&ar->data_lock); | |
2697 | ||
2698 | ath10k_tx_htt(ar, skb); | |
2699 | ||
2700 | ret = wait_for_completion_timeout(&ar->offchan_tx_completed, | |
2701 | 3 * HZ); | |
38e2a644 | 2702 | if (ret == 0) |
7aa7a72a | 2703 | ath10k_warn(ar, "timed out waiting for offchannel skb %p\n", |
5e3dd157 KV |
2704 | skb); |
2705 | ||
2706 | if (!peer) { | |
2707 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); | |
2708 | if (ret) | |
7aa7a72a | 2709 | ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n", |
5e3dd157 KV |
2710 | peer_addr, vdev_id, ret); |
2711 | } | |
2712 | ||
2713 | mutex_unlock(&ar->conf_mutex); | |
2714 | } | |
2715 | } | |
2716 | ||
5e00d31a BM |
2717 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
2718 | { | |
2719 | struct sk_buff *skb; | |
2720 | ||
2721 | for (;;) { | |
2722 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); | |
2723 | if (!skb) | |
2724 | break; | |
2725 | ||
2726 | ieee80211_free_txskb(ar->hw, skb); | |
2727 | } | |
2728 | } | |
2729 | ||
2730 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) | |
2731 | { | |
2732 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); | |
2733 | struct sk_buff *skb; | |
2734 | int ret; | |
2735 | ||
2736 | for (;;) { | |
2737 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); | |
2738 | if (!skb) | |
2739 | break; | |
2740 | ||
2741 | ret = ath10k_wmi_mgmt_tx(ar, skb); | |
5fb5e41f | 2742 | if (ret) { |
7aa7a72a | 2743 | ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n", |
be6546fc | 2744 | ret); |
5fb5e41f MK |
2745 | ieee80211_free_txskb(ar->hw, skb); |
2746 | } | |
5e00d31a BM |
2747 | } |
2748 | } | |
2749 | ||
5e3dd157 KV |
2750 | /************/ |
2751 | /* Scanning */ | |
2752 | /************/ | |
2753 | ||
5c81c7fd | 2754 | void __ath10k_scan_finish(struct ath10k *ar) |
5e3dd157 | 2755 | { |
5c81c7fd | 2756 | lockdep_assert_held(&ar->data_lock); |
5e3dd157 | 2757 | |
5c81c7fd MK |
2758 | switch (ar->scan.state) { |
2759 | case ATH10K_SCAN_IDLE: | |
2760 | break; | |
2761 | case ATH10K_SCAN_RUNNING: | |
5c81c7fd MK |
2762 | if (ar->scan.is_roc) |
2763 | ieee80211_remain_on_channel_expired(ar->hw); | |
f6eaf1e0 | 2764 | /* fall through */ |
7305d3e0 MK |
2765 | case ATH10K_SCAN_ABORTING: |
2766 | if (!ar->scan.is_roc) | |
5c81c7fd MK |
2767 | ieee80211_scan_completed(ar->hw, |
2768 | (ar->scan.state == | |
2769 | ATH10K_SCAN_ABORTING)); | |
2770 | /* fall through */ | |
2771 | case ATH10K_SCAN_STARTING: | |
2772 | ar->scan.state = ATH10K_SCAN_IDLE; | |
2773 | ar->scan_channel = NULL; | |
2774 | ath10k_offchan_tx_purge(ar); | |
2775 | cancel_delayed_work(&ar->scan.timeout); | |
2776 | complete_all(&ar->scan.completed); | |
2777 | break; | |
5e3dd157 | 2778 | } |
5c81c7fd | 2779 | } |
5e3dd157 | 2780 | |
5c81c7fd MK |
2781 | void ath10k_scan_finish(struct ath10k *ar) |
2782 | { | |
2783 | spin_lock_bh(&ar->data_lock); | |
2784 | __ath10k_scan_finish(ar); | |
5e3dd157 KV |
2785 | spin_unlock_bh(&ar->data_lock); |
2786 | } | |
2787 | ||
5c81c7fd | 2788 | static int ath10k_scan_stop(struct ath10k *ar) |
5e3dd157 KV |
2789 | { |
2790 | struct wmi_stop_scan_arg arg = { | |
2791 | .req_id = 1, /* FIXME */ | |
2792 | .req_type = WMI_SCAN_STOP_ONE, | |
2793 | .u.scan_id = ATH10K_SCAN_ID, | |
2794 | }; | |
2795 | int ret; | |
2796 | ||
2797 | lockdep_assert_held(&ar->conf_mutex); | |
2798 | ||
5e3dd157 KV |
2799 | ret = ath10k_wmi_stop_scan(ar, &arg); |
2800 | if (ret) { | |
7aa7a72a | 2801 | ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret); |
5c81c7fd | 2802 | goto out; |
5e3dd157 KV |
2803 | } |
2804 | ||
5e3dd157 | 2805 | ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); |
5c81c7fd | 2806 | if (ret == 0) { |
7aa7a72a | 2807 | ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n"); |
5c81c7fd MK |
2808 | ret = -ETIMEDOUT; |
2809 | } else if (ret > 0) { | |
2810 | ret = 0; | |
2811 | } | |
5e3dd157 | 2812 | |
5c81c7fd MK |
2813 | out: |
2814 | /* Scan state should be updated upon scan completion but in case | |
2815 | * firmware fails to deliver the event (for whatever reason) it is | |
2816 | * desired to clean up scan state anyway. Firmware may have just | |
2817 | * dropped the scan completion event delivery due to transport pipe | |
2818 | * being overflown with data and/or it can recover on its own before | |
2819 | * next scan request is submitted. | |
2820 | */ | |
2821 | spin_lock_bh(&ar->data_lock); | |
2822 | if (ar->scan.state != ATH10K_SCAN_IDLE) | |
2823 | __ath10k_scan_finish(ar); | |
2824 | spin_unlock_bh(&ar->data_lock); | |
2825 | ||
2826 | return ret; | |
2827 | } | |
2828 | ||
2829 | static void ath10k_scan_abort(struct ath10k *ar) | |
2830 | { | |
2831 | int ret; | |
2832 | ||
2833 | lockdep_assert_held(&ar->conf_mutex); | |
5e3dd157 KV |
2834 | |
2835 | spin_lock_bh(&ar->data_lock); | |
5c81c7fd MK |
2836 | |
2837 | switch (ar->scan.state) { | |
2838 | case ATH10K_SCAN_IDLE: | |
2839 | /* This can happen if timeout worker kicked in and called | |
2840 | * abortion while scan completion was being processed. | |
2841 | */ | |
2842 | break; | |
2843 | case ATH10K_SCAN_STARTING: | |
2844 | case ATH10K_SCAN_ABORTING: | |
7aa7a72a | 2845 | ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n", |
5c81c7fd MK |
2846 | ath10k_scan_state_str(ar->scan.state), |
2847 | ar->scan.state); | |
2848 | break; | |
2849 | case ATH10K_SCAN_RUNNING: | |
2850 | ar->scan.state = ATH10K_SCAN_ABORTING; | |
2851 | spin_unlock_bh(&ar->data_lock); | |
2852 | ||
2853 | ret = ath10k_scan_stop(ar); | |
2854 | if (ret) | |
7aa7a72a | 2855 | ath10k_warn(ar, "failed to abort scan: %d\n", ret); |
5c81c7fd MK |
2856 | |
2857 | spin_lock_bh(&ar->data_lock); | |
2858 | break; | |
5e3dd157 | 2859 | } |
5c81c7fd | 2860 | |
5e3dd157 | 2861 | spin_unlock_bh(&ar->data_lock); |
5c81c7fd | 2862 | } |
5e3dd157 | 2863 | |
5c81c7fd MK |
2864 | void ath10k_scan_timeout_work(struct work_struct *work) |
2865 | { | |
2866 | struct ath10k *ar = container_of(work, struct ath10k, | |
2867 | scan.timeout.work); | |
2868 | ||
2869 | mutex_lock(&ar->conf_mutex); | |
2870 | ath10k_scan_abort(ar); | |
2871 | mutex_unlock(&ar->conf_mutex); | |
5e3dd157 KV |
2872 | } |
2873 | ||
2874 | static int ath10k_start_scan(struct ath10k *ar, | |
2875 | const struct wmi_start_scan_arg *arg) | |
2876 | { | |
2877 | int ret; | |
2878 | ||
2879 | lockdep_assert_held(&ar->conf_mutex); | |
2880 | ||
2881 | ret = ath10k_wmi_start_scan(ar, arg); | |
2882 | if (ret) | |
2883 | return ret; | |
2884 | ||
5e3dd157 KV |
2885 | ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); |
2886 | if (ret == 0) { | |
5c81c7fd MK |
2887 | ret = ath10k_scan_stop(ar); |
2888 | if (ret) | |
7aa7a72a | 2889 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
5c81c7fd MK |
2890 | |
2891 | return -ETIMEDOUT; | |
5e3dd157 KV |
2892 | } |
2893 | ||
2f9eec0b BG |
2894 | /* If we failed to start the scan, return error code at |
2895 | * this point. This is probably due to some issue in the | |
2896 | * firmware, but no need to wedge the driver due to that... | |
2897 | */ | |
2898 | spin_lock_bh(&ar->data_lock); | |
2899 | if (ar->scan.state == ATH10K_SCAN_IDLE) { | |
2900 | spin_unlock_bh(&ar->data_lock); | |
2901 | return -EINVAL; | |
2902 | } | |
2903 | spin_unlock_bh(&ar->data_lock); | |
2904 | ||
5c81c7fd MK |
2905 | /* Add a 200ms margin to account for event/command processing */ |
2906 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, | |
2907 | msecs_to_jiffies(arg->max_scan_time+200)); | |
5e3dd157 KV |
2908 | return 0; |
2909 | } | |
2910 | ||
2911 | /**********************/ | |
2912 | /* mac80211 callbacks */ | |
2913 | /**********************/ | |
2914 | ||
2915 | static void ath10k_tx(struct ieee80211_hw *hw, | |
2916 | struct ieee80211_tx_control *control, | |
2917 | struct sk_buff *skb) | |
2918 | { | |
4b604558 | 2919 | struct ath10k *ar = hw->priv; |
5e3dd157 | 2920 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
4b604558 | 2921 | struct ieee80211_vif *vif = info->control.vif; |
5e3dd157 | 2922 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
5e3dd157 KV |
2923 | |
2924 | /* We should disable CCK RATE due to P2P */ | |
2925 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) | |
7aa7a72a | 2926 | ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n"); |
5e3dd157 | 2927 | |
4b604558 MK |
2928 | ATH10K_SKB_CB(skb)->htt.is_offchan = false; |
2929 | ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr); | |
2b37c295 | 2930 | ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif); |
5e3dd157 | 2931 | |
cf84bd4d | 2932 | /* it makes no sense to process injected frames like that */ |
4b604558 MK |
2933 | if (vif && vif->type != NL80211_IFTYPE_MONITOR) { |
2934 | ath10k_tx_h_nwifi(hw, skb); | |
4b604558 MK |
2935 | ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb); |
2936 | ath10k_tx_h_seq_no(vif, skb); | |
cf84bd4d | 2937 | } |
5e3dd157 | 2938 | |
5e3dd157 KV |
2939 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { |
2940 | spin_lock_bh(&ar->data_lock); | |
8d6d3624 | 2941 | ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq; |
5e00d31a | 2942 | ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id; |
5e3dd157 KV |
2943 | spin_unlock_bh(&ar->data_lock); |
2944 | ||
8d6d3624 MK |
2945 | if (ath10k_mac_need_offchan_tx_work(ar)) { |
2946 | ATH10K_SKB_CB(skb)->htt.freq = 0; | |
2947 | ATH10K_SKB_CB(skb)->htt.is_offchan = true; | |
5e3dd157 | 2948 | |
8d6d3624 MK |
2949 | ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n", |
2950 | skb); | |
2951 | ||
2952 | skb_queue_tail(&ar->offchan_tx_queue, skb); | |
2953 | ieee80211_queue_work(hw, &ar->offchan_tx_work); | |
2954 | return; | |
2955 | } | |
5e3dd157 KV |
2956 | } |
2957 | ||
2958 | ath10k_tx_htt(ar, skb); | |
2959 | } | |
2960 | ||
bca7bafb | 2961 | /* Must not be called with conf_mutex held as workers can use that also. */ |
7962b0d8 | 2962 | void ath10k_drain_tx(struct ath10k *ar) |
bca7bafb MK |
2963 | { |
2964 | /* make sure rcu-protected mac80211 tx path itself is drained */ | |
2965 | synchronize_net(); | |
2966 | ||
2967 | ath10k_offchan_tx_purge(ar); | |
2968 | ath10k_mgmt_over_wmi_tx_purge(ar); | |
2969 | ||
2970 | cancel_work_sync(&ar->offchan_tx_work); | |
2971 | cancel_work_sync(&ar->wmi_mgmt_tx_work); | |
2972 | } | |
2973 | ||
affd3217 | 2974 | void ath10k_halt(struct ath10k *ar) |
818bdd16 | 2975 | { |
d9bc4b9b MK |
2976 | struct ath10k_vif *arvif; |
2977 | ||
818bdd16 MK |
2978 | lockdep_assert_held(&ar->conf_mutex); |
2979 | ||
1933747f MK |
2980 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
2981 | ar->filter_flags = 0; | |
2982 | ar->monitor = false; | |
2983 | ||
2984 | if (ar->monitor_started) | |
1bbc0975 | 2985 | ath10k_monitor_stop(ar); |
1933747f MK |
2986 | |
2987 | ar->monitor_started = false; | |
1bbc0975 | 2988 | |
5c81c7fd | 2989 | ath10k_scan_finish(ar); |
818bdd16 MK |
2990 | ath10k_peer_cleanup_all(ar); |
2991 | ath10k_core_stop(ar); | |
2992 | ath10k_hif_power_down(ar); | |
2993 | ||
2994 | spin_lock_bh(&ar->data_lock); | |
64badcb6 MK |
2995 | list_for_each_entry(arvif, &ar->arvifs, list) |
2996 | ath10k_mac_vif_beacon_cleanup(arvif); | |
818bdd16 MK |
2997 | spin_unlock_bh(&ar->data_lock); |
2998 | } | |
2999 | ||
46acf7bb BG |
3000 | static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
3001 | { | |
3002 | struct ath10k *ar = hw->priv; | |
3003 | ||
3004 | mutex_lock(&ar->conf_mutex); | |
3005 | ||
3006 | if (ar->cfg_tx_chainmask) { | |
3007 | *tx_ant = ar->cfg_tx_chainmask; | |
3008 | *rx_ant = ar->cfg_rx_chainmask; | |
3009 | } else { | |
3010 | *tx_ant = ar->supp_tx_chainmask; | |
3011 | *rx_ant = ar->supp_rx_chainmask; | |
3012 | } | |
3013 | ||
3014 | mutex_unlock(&ar->conf_mutex); | |
3015 | ||
3016 | return 0; | |
3017 | } | |
3018 | ||
5572a95b BG |
3019 | static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg) |
3020 | { | |
3021 | /* It is not clear that allowing gaps in chainmask | |
3022 | * is helpful. Probably it will not do what user | |
3023 | * is hoping for, so warn in that case. | |
3024 | */ | |
3025 | if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0) | |
3026 | return; | |
3027 | ||
3028 | ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n", | |
3029 | dbg, cm); | |
3030 | } | |
3031 | ||
46acf7bb BG |
3032 | static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant) |
3033 | { | |
3034 | int ret; | |
3035 | ||
3036 | lockdep_assert_held(&ar->conf_mutex); | |
3037 | ||
5572a95b BG |
3038 | ath10k_check_chain_mask(ar, tx_ant, "tx"); |
3039 | ath10k_check_chain_mask(ar, rx_ant, "rx"); | |
3040 | ||
46acf7bb BG |
3041 | ar->cfg_tx_chainmask = tx_ant; |
3042 | ar->cfg_rx_chainmask = rx_ant; | |
3043 | ||
3044 | if ((ar->state != ATH10K_STATE_ON) && | |
3045 | (ar->state != ATH10K_STATE_RESTARTED)) | |
3046 | return 0; | |
3047 | ||
3048 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask, | |
3049 | tx_ant); | |
3050 | if (ret) { | |
7aa7a72a | 3051 | ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n", |
46acf7bb BG |
3052 | ret, tx_ant); |
3053 | return ret; | |
3054 | } | |
3055 | ||
3056 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask, | |
3057 | rx_ant); | |
3058 | if (ret) { | |
7aa7a72a | 3059 | ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n", |
46acf7bb BG |
3060 | ret, rx_ant); |
3061 | return ret; | |
3062 | } | |
3063 | ||
3064 | return 0; | |
3065 | } | |
3066 | ||
3067 | static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) | |
3068 | { | |
3069 | struct ath10k *ar = hw->priv; | |
3070 | int ret; | |
3071 | ||
3072 | mutex_lock(&ar->conf_mutex); | |
3073 | ret = __ath10k_set_antenna(ar, tx_ant, rx_ant); | |
3074 | mutex_unlock(&ar->conf_mutex); | |
3075 | return ret; | |
3076 | } | |
3077 | ||
5e3dd157 KV |
3078 | static int ath10k_start(struct ieee80211_hw *hw) |
3079 | { | |
3080 | struct ath10k *ar = hw->priv; | |
818bdd16 | 3081 | int ret = 0; |
5e3dd157 | 3082 | |
bca7bafb MK |
3083 | /* |
3084 | * This makes sense only when restarting hw. It is harmless to call | |
3085 | * uncoditionally. This is necessary to make sure no HTT/WMI tx | |
3086 | * commands will be submitted while restarting. | |
3087 | */ | |
3088 | ath10k_drain_tx(ar); | |
3089 | ||
548db54c MK |
3090 | mutex_lock(&ar->conf_mutex); |
3091 | ||
c5058f5b MK |
3092 | switch (ar->state) { |
3093 | case ATH10K_STATE_OFF: | |
3094 | ar->state = ATH10K_STATE_ON; | |
3095 | break; | |
3096 | case ATH10K_STATE_RESTARTING: | |
3097 | ath10k_halt(ar); | |
3098 | ar->state = ATH10K_STATE_RESTARTED; | |
3099 | break; | |
3100 | case ATH10K_STATE_ON: | |
3101 | case ATH10K_STATE_RESTARTED: | |
3102 | case ATH10K_STATE_WEDGED: | |
3103 | WARN_ON(1); | |
818bdd16 | 3104 | ret = -EINVAL; |
ae254433 | 3105 | goto err; |
43d2a30f KV |
3106 | case ATH10K_STATE_UTF: |
3107 | ret = -EBUSY; | |
3108 | goto err; | |
818bdd16 MK |
3109 | } |
3110 | ||
3111 | ret = ath10k_hif_power_up(ar); | |
3112 | if (ret) { | |
7aa7a72a | 3113 | ath10k_err(ar, "Could not init hif: %d\n", ret); |
ae254433 | 3114 | goto err_off; |
818bdd16 MK |
3115 | } |
3116 | ||
43d2a30f | 3117 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL); |
818bdd16 | 3118 | if (ret) { |
7aa7a72a | 3119 | ath10k_err(ar, "Could not init core: %d\n", ret); |
ae254433 | 3120 | goto err_power_down; |
818bdd16 MK |
3121 | } |
3122 | ||
226a339b | 3123 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1); |
ae254433 | 3124 | if (ret) { |
7aa7a72a | 3125 | ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret); |
ae254433 MK |
3126 | goto err_core_stop; |
3127 | } | |
5e3dd157 | 3128 | |
c4dd0d01 | 3129 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1); |
ae254433 | 3130 | if (ret) { |
7aa7a72a | 3131 | ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret); |
ae254433 MK |
3132 | goto err_core_stop; |
3133 | } | |
5e3dd157 | 3134 | |
46acf7bb BG |
3135 | if (ar->cfg_tx_chainmask) |
3136 | __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, | |
3137 | ar->cfg_rx_chainmask); | |
3138 | ||
ab6258ed MP |
3139 | /* |
3140 | * By default FW set ARP frames ac to voice (6). In that case ARP | |
3141 | * exchange is not working properly for UAPSD enabled AP. ARP requests | |
3142 | * which arrives with access category 0 are processed by network stack | |
3143 | * and send back with access category 0, but FW changes access category | |
3144 | * to 6. Set ARP frames access category to best effort (0) solves | |
3145 | * this problem. | |
3146 | */ | |
3147 | ||
3148 | ret = ath10k_wmi_pdev_set_param(ar, | |
3149 | ar->wmi.pdev_param->arp_ac_override, 0); | |
3150 | if (ret) { | |
7aa7a72a | 3151 | ath10k_warn(ar, "failed to set arp ac override parameter: %d\n", |
ab6258ed | 3152 | ret); |
ae254433 | 3153 | goto err_core_stop; |
ab6258ed MP |
3154 | } |
3155 | ||
d650097b | 3156 | ar->num_started_vdevs = 0; |
f7843d7f MK |
3157 | ath10k_regd_update(ar); |
3158 | ||
855aed12 SW |
3159 | ath10k_spectral_start(ar); |
3160 | ||
ae254433 MK |
3161 | mutex_unlock(&ar->conf_mutex); |
3162 | return 0; | |
3163 | ||
3164 | err_core_stop: | |
3165 | ath10k_core_stop(ar); | |
3166 | ||
3167 | err_power_down: | |
3168 | ath10k_hif_power_down(ar); | |
3169 | ||
3170 | err_off: | |
3171 | ar->state = ATH10K_STATE_OFF; | |
3172 | ||
3173 | err: | |
548db54c | 3174 | mutex_unlock(&ar->conf_mutex); |
c60bdd83 | 3175 | return ret; |
5e3dd157 KV |
3176 | } |
3177 | ||
3178 | static void ath10k_stop(struct ieee80211_hw *hw) | |
3179 | { | |
3180 | struct ath10k *ar = hw->priv; | |
3181 | ||
bca7bafb MK |
3182 | ath10k_drain_tx(ar); |
3183 | ||
548db54c | 3184 | mutex_lock(&ar->conf_mutex); |
c5058f5b | 3185 | if (ar->state != ATH10K_STATE_OFF) { |
818bdd16 | 3186 | ath10k_halt(ar); |
c5058f5b MK |
3187 | ar->state = ATH10K_STATE_OFF; |
3188 | } | |
548db54c MK |
3189 | mutex_unlock(&ar->conf_mutex); |
3190 | ||
5c81c7fd | 3191 | cancel_delayed_work_sync(&ar->scan.timeout); |
affd3217 | 3192 | cancel_work_sync(&ar->restart_work); |
5e3dd157 KV |
3193 | } |
3194 | ||
ad088bfa | 3195 | static int ath10k_config_ps(struct ath10k *ar) |
5e3dd157 | 3196 | { |
ad088bfa MK |
3197 | struct ath10k_vif *arvif; |
3198 | int ret = 0; | |
affd3217 MK |
3199 | |
3200 | lockdep_assert_held(&ar->conf_mutex); | |
3201 | ||
ad088bfa MK |
3202 | list_for_each_entry(arvif, &ar->arvifs, list) { |
3203 | ret = ath10k_mac_vif_setup_ps(arvif); | |
3204 | if (ret) { | |
7aa7a72a | 3205 | ath10k_warn(ar, "failed to setup powersave: %d\n", ret); |
ad088bfa MK |
3206 | break; |
3207 | } | |
3208 | } | |
affd3217 | 3209 | |
ad088bfa | 3210 | return ret; |
affd3217 MK |
3211 | } |
3212 | ||
c930f744 MK |
3213 | static const char *chandef_get_width(enum nl80211_chan_width width) |
3214 | { | |
3215 | switch (width) { | |
3216 | case NL80211_CHAN_WIDTH_20_NOHT: | |
3217 | return "20 (noht)"; | |
3218 | case NL80211_CHAN_WIDTH_20: | |
3219 | return "20"; | |
3220 | case NL80211_CHAN_WIDTH_40: | |
3221 | return "40"; | |
3222 | case NL80211_CHAN_WIDTH_80: | |
3223 | return "80"; | |
3224 | case NL80211_CHAN_WIDTH_80P80: | |
3225 | return "80+80"; | |
3226 | case NL80211_CHAN_WIDTH_160: | |
3227 | return "160"; | |
3228 | case NL80211_CHAN_WIDTH_5: | |
3229 | return "5"; | |
3230 | case NL80211_CHAN_WIDTH_10: | |
3231 | return "10"; | |
3232 | } | |
3233 | return "?"; | |
3234 | } | |
3235 | ||
3236 | static void ath10k_config_chan(struct ath10k *ar) | |
3237 | { | |
3238 | struct ath10k_vif *arvif; | |
c930f744 MK |
3239 | int ret; |
3240 | ||
3241 | lockdep_assert_held(&ar->conf_mutex); | |
3242 | ||
7aa7a72a | 3243 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
c930f744 MK |
3244 | "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n", |
3245 | ar->chandef.chan->center_freq, | |
3246 | ar->chandef.center_freq1, | |
3247 | ar->chandef.center_freq2, | |
3248 | chandef_get_width(ar->chandef.width)); | |
3249 | ||
3250 | /* First stop monitor interface. Some FW versions crash if there's a | |
3251 | * lone monitor interface. */ | |
1bbc0975 | 3252 | if (ar->monitor_started) |
1933747f | 3253 | ath10k_monitor_stop(ar); |
c930f744 MK |
3254 | |
3255 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
3256 | if (!arvif->is_started) | |
3257 | continue; | |
3258 | ||
dc55e307 MK |
3259 | if (!arvif->is_up) |
3260 | continue; | |
3261 | ||
c930f744 MK |
3262 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
3263 | continue; | |
3264 | ||
dc55e307 | 3265 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
c930f744 | 3266 | if (ret) { |
7aa7a72a | 3267 | ath10k_warn(ar, "failed to down vdev %d: %d\n", |
c930f744 MK |
3268 | arvif->vdev_id, ret); |
3269 | continue; | |
3270 | } | |
3271 | } | |
3272 | ||
dc55e307 | 3273 | /* all vdevs are downed now - attempt to restart and re-up them */ |
c930f744 MK |
3274 | |
3275 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
3276 | if (!arvif->is_started) | |
3277 | continue; | |
3278 | ||
3279 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) | |
3280 | continue; | |
3281 | ||
81a9a17d MK |
3282 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
3283 | if (ret) | |
3284 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", | |
3285 | ret); | |
3286 | ||
3287 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
3288 | if (ret) | |
3289 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", | |
3290 | ret); | |
3291 | ||
dc55e307 | 3292 | ret = ath10k_vdev_restart(arvif); |
c930f744 | 3293 | if (ret) { |
7aa7a72a | 3294 | ath10k_warn(ar, "failed to restart vdev %d: %d\n", |
c930f744 MK |
3295 | arvif->vdev_id, ret); |
3296 | continue; | |
3297 | } | |
3298 | ||
3299 | if (!arvif->is_up) | |
3300 | continue; | |
3301 | ||
3302 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
3303 | arvif->bssid); | |
3304 | if (ret) { | |
7aa7a72a | 3305 | ath10k_warn(ar, "failed to bring vdev up %d: %d\n", |
c930f744 MK |
3306 | arvif->vdev_id, ret); |
3307 | continue; | |
3308 | } | |
3309 | } | |
3310 | ||
1933747f | 3311 | ath10k_monitor_recalc(ar); |
c930f744 MK |
3312 | } |
3313 | ||
7d9d5587 MK |
3314 | static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower) |
3315 | { | |
3316 | int ret; | |
3317 | u32 param; | |
3318 | ||
3319 | lockdep_assert_held(&ar->conf_mutex); | |
3320 | ||
3321 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower); | |
3322 | ||
3323 | param = ar->wmi.pdev_param->txpower_limit2g; | |
3324 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); | |
3325 | if (ret) { | |
3326 | ath10k_warn(ar, "failed to set 2g txpower %d: %d\n", | |
3327 | txpower, ret); | |
3328 | return ret; | |
3329 | } | |
3330 | ||
3331 | param = ar->wmi.pdev_param->txpower_limit5g; | |
3332 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); | |
3333 | if (ret) { | |
3334 | ath10k_warn(ar, "failed to set 5g txpower %d: %d\n", | |
3335 | txpower, ret); | |
3336 | return ret; | |
3337 | } | |
3338 | ||
3339 | return 0; | |
3340 | } | |
3341 | ||
3342 | static int ath10k_mac_txpower_recalc(struct ath10k *ar) | |
3343 | { | |
3344 | struct ath10k_vif *arvif; | |
3345 | int ret, txpower = -1; | |
3346 | ||
3347 | lockdep_assert_held(&ar->conf_mutex); | |
3348 | ||
3349 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
3350 | WARN_ON(arvif->txpower < 0); | |
3351 | ||
3352 | if (txpower == -1) | |
3353 | txpower = arvif->txpower; | |
3354 | else | |
3355 | txpower = min(txpower, arvif->txpower); | |
3356 | } | |
3357 | ||
3358 | if (WARN_ON(txpower == -1)) | |
3359 | return -EINVAL; | |
3360 | ||
3361 | ret = ath10k_mac_txpower_setup(ar, txpower); | |
3362 | if (ret) { | |
3363 | ath10k_warn(ar, "failed to setup tx power %d: %d\n", | |
3364 | txpower, ret); | |
3365 | return ret; | |
3366 | } | |
3367 | ||
3368 | return 0; | |
3369 | } | |
3370 | ||
affd3217 MK |
3371 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
3372 | { | |
5e3dd157 KV |
3373 | struct ath10k *ar = hw->priv; |
3374 | struct ieee80211_conf *conf = &hw->conf; | |
3375 | int ret = 0; | |
5e3dd157 KV |
3376 | |
3377 | mutex_lock(&ar->conf_mutex); | |
3378 | ||
3379 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { | |
7aa7a72a | 3380 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
d650097b | 3381 | "mac config channel %dMHz flags 0x%x radar %d\n", |
e8a50f8b | 3382 | conf->chandef.chan->center_freq, |
d650097b MK |
3383 | conf->chandef.chan->flags, |
3384 | conf->radar_enabled); | |
e8a50f8b | 3385 | |
5e3dd157 KV |
3386 | spin_lock_bh(&ar->data_lock); |
3387 | ar->rx_channel = conf->chandef.chan; | |
3388 | spin_unlock_bh(&ar->data_lock); | |
e8a50f8b | 3389 | |
d650097b MK |
3390 | ar->radar_enabled = conf->radar_enabled; |
3391 | ath10k_recalc_radar_detection(ar); | |
c930f744 MK |
3392 | |
3393 | if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) { | |
3394 | ar->chandef = conf->chandef; | |
3395 | ath10k_config_chan(ar); | |
3396 | } | |
5e3dd157 KV |
3397 | } |
3398 | ||
affd3217 MK |
3399 | if (changed & IEEE80211_CONF_CHANGE_PS) |
3400 | ath10k_config_ps(ar); | |
5e3dd157 KV |
3401 | |
3402 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { | |
1933747f MK |
3403 | ar->monitor = conf->flags & IEEE80211_CONF_MONITOR; |
3404 | ret = ath10k_monitor_recalc(ar); | |
3405 | if (ret) | |
3406 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); | |
5e3dd157 KV |
3407 | } |
3408 | ||
3409 | mutex_unlock(&ar->conf_mutex); | |
3410 | return ret; | |
3411 | } | |
3412 | ||
5572a95b BG |
3413 | static u32 get_nss_from_chainmask(u16 chain_mask) |
3414 | { | |
3415 | if ((chain_mask & 0x15) == 0x15) | |
3416 | return 4; | |
3417 | else if ((chain_mask & 0x7) == 0x7) | |
3418 | return 3; | |
3419 | else if ((chain_mask & 0x3) == 0x3) | |
3420 | return 2; | |
3421 | return 1; | |
3422 | } | |
3423 | ||
5e3dd157 KV |
3424 | /* |
3425 | * TODO: | |
3426 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, | |
3427 | * because we will send mgmt frames without CCK. This requirement | |
3428 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag | |
3429 | * in the TX packet. | |
3430 | */ | |
3431 | static int ath10k_add_interface(struct ieee80211_hw *hw, | |
3432 | struct ieee80211_vif *vif) | |
3433 | { | |
3434 | struct ath10k *ar = hw->priv; | |
3435 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
3436 | enum wmi_sta_powersave_param param; | |
3437 | int ret = 0; | |
5a13e76e | 3438 | u32 value; |
5e3dd157 | 3439 | int bit; |
6d1506e7 | 3440 | u32 vdev_param; |
5e3dd157 | 3441 | |
848955cc JB |
3442 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
3443 | ||
5e3dd157 KV |
3444 | mutex_lock(&ar->conf_mutex); |
3445 | ||
0dbd09e6 MK |
3446 | memset(arvif, 0, sizeof(*arvif)); |
3447 | ||
5e3dd157 KV |
3448 | arvif->ar = ar; |
3449 | arvif->vif = vif; | |
3450 | ||
e63b33f3 | 3451 | INIT_LIST_HEAD(&arvif->list); |
81a9a17d | 3452 | INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work); |
cc9904e6 MK |
3453 | INIT_DELAYED_WORK(&arvif->connection_loss_work, |
3454 | ath10k_mac_vif_sta_connection_loss_work); | |
cc4827b9 | 3455 | |
a9aefb3b | 3456 | if (ar->free_vdev_map == 0) { |
7aa7a72a | 3457 | ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n"); |
5e3dd157 | 3458 | ret = -EBUSY; |
9dad14ae | 3459 | goto err; |
5e3dd157 | 3460 | } |
16c11176 | 3461 | bit = __ffs64(ar->free_vdev_map); |
5e3dd157 | 3462 | |
16c11176 BG |
3463 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n", |
3464 | bit, ar->free_vdev_map); | |
5e3dd157 | 3465 | |
16c11176 | 3466 | arvif->vdev_id = bit; |
5e3dd157 | 3467 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; |
5e3dd157 | 3468 | |
5e3dd157 | 3469 | switch (vif->type) { |
75d2bd48 MK |
3470 | case NL80211_IFTYPE_P2P_DEVICE: |
3471 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
3472 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; | |
3473 | break; | |
5e3dd157 KV |
3474 | case NL80211_IFTYPE_UNSPECIFIED: |
3475 | case NL80211_IFTYPE_STATION: | |
3476 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
3477 | if (vif->p2p) | |
3478 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; | |
3479 | break; | |
3480 | case NL80211_IFTYPE_ADHOC: | |
3481 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; | |
3482 | break; | |
3483 | case NL80211_IFTYPE_AP: | |
3484 | arvif->vdev_type = WMI_VDEV_TYPE_AP; | |
3485 | ||
3486 | if (vif->p2p) | |
3487 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; | |
3488 | break; | |
3489 | case NL80211_IFTYPE_MONITOR: | |
3490 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; | |
3491 | break; | |
3492 | default: | |
3493 | WARN_ON(1); | |
3494 | break; | |
3495 | } | |
3496 | ||
64badcb6 MK |
3497 | /* Some firmware revisions don't wait for beacon tx completion before |
3498 | * sending another SWBA event. This could lead to hardware using old | |
3499 | * (freed) beacon data in some cases, e.g. tx credit starvation | |
3500 | * combined with missed TBTT. This is very very rare. | |
3501 | * | |
3502 | * On non-IOMMU-enabled hosts this could be a possible security issue | |
3503 | * because hw could beacon some random data on the air. On | |
3504 | * IOMMU-enabled hosts DMAR faults would occur in most cases and target | |
3505 | * device would crash. | |
3506 | * | |
3507 | * Since there are no beacon tx completions (implicit nor explicit) | |
3508 | * propagated to host the only workaround for this is to allocate a | |
3509 | * DMA-coherent buffer for a lifetime of a vif and use it for all | |
3510 | * beacon tx commands. Worst case for this approach is some beacons may | |
3511 | * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap. | |
3512 | */ | |
3513 | if (vif->type == NL80211_IFTYPE_ADHOC || | |
3514 | vif->type == NL80211_IFTYPE_AP) { | |
3515 | arvif->beacon_buf = dma_zalloc_coherent(ar->dev, | |
3516 | IEEE80211_MAX_FRAME_LEN, | |
3517 | &arvif->beacon_paddr, | |
82d7aba7 | 3518 | GFP_ATOMIC); |
64badcb6 MK |
3519 | if (!arvif->beacon_buf) { |
3520 | ret = -ENOMEM; | |
3521 | ath10k_warn(ar, "failed to allocate beacon buffer: %d\n", | |
3522 | ret); | |
3523 | goto err; | |
3524 | } | |
3525 | } | |
3526 | ||
3527 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n", | |
3528 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, | |
3529 | arvif->beacon_buf ? "single-buf" : "per-skb"); | |
5e3dd157 KV |
3530 | |
3531 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, | |
3532 | arvif->vdev_subtype, vif->addr); | |
3533 | if (ret) { | |
7aa7a72a | 3534 | ath10k_warn(ar, "failed to create WMI vdev %i: %d\n", |
69244e56 | 3535 | arvif->vdev_id, ret); |
9dad14ae | 3536 | goto err; |
5e3dd157 KV |
3537 | } |
3538 | ||
16c11176 | 3539 | ar->free_vdev_map &= ~(1LL << arvif->vdev_id); |
0579119f | 3540 | list_add(&arvif->list, &ar->arvifs); |
9dad14ae | 3541 | |
46725b15 MK |
3542 | /* It makes no sense to have firmware do keepalives. mac80211 already |
3543 | * takes care of this with idle connection polling. | |
3544 | */ | |
3545 | ret = ath10k_mac_vif_disable_keepalive(arvif); | |
9dad14ae | 3546 | if (ret) { |
46725b15 | 3547 | ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n", |
69244e56 | 3548 | arvif->vdev_id, ret); |
9dad14ae MK |
3549 | goto err_vdev_delete; |
3550 | } | |
5e3dd157 | 3551 | |
627613f8 | 3552 | arvif->def_wep_key_idx = -1; |
5e3dd157 | 3553 | |
6d1506e7 BM |
3554 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
3555 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 | 3556 | ATH10K_HW_TXRX_NATIVE_WIFI); |
ebc9abdd | 3557 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
9dad14ae | 3558 | if (ret && ret != -EOPNOTSUPP) { |
7aa7a72a | 3559 | ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n", |
69244e56 | 3560 | arvif->vdev_id, ret); |
9dad14ae MK |
3561 | goto err_vdev_delete; |
3562 | } | |
5e3dd157 | 3563 | |
5572a95b BG |
3564 | if (ar->cfg_tx_chainmask) { |
3565 | u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); | |
3566 | ||
3567 | vdev_param = ar->wmi.vdev_param->nss; | |
3568 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
3569 | nss); | |
3570 | if (ret) { | |
3571 | ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n", | |
3572 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, | |
3573 | ret); | |
3574 | goto err_vdev_delete; | |
3575 | } | |
3576 | } | |
3577 | ||
5e3dd157 KV |
3578 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
3579 | ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr); | |
3580 | if (ret) { | |
7aa7a72a | 3581 | ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n", |
69244e56 | 3582 | arvif->vdev_id, ret); |
9dad14ae | 3583 | goto err_vdev_delete; |
5e3dd157 | 3584 | } |
cdf07409 | 3585 | |
5a13e76e KV |
3586 | ret = ath10k_mac_set_kickout(arvif); |
3587 | if (ret) { | |
7aa7a72a | 3588 | ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n", |
69244e56 | 3589 | arvif->vdev_id, ret); |
5a13e76e KV |
3590 | goto err_peer_delete; |
3591 | } | |
5e3dd157 KV |
3592 | } |
3593 | ||
3594 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { | |
3595 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; | |
3596 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
3597 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3598 | param, value); | |
9dad14ae | 3599 | if (ret) { |
7aa7a72a | 3600 | ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n", |
69244e56 | 3601 | arvif->vdev_id, ret); |
9dad14ae MK |
3602 | goto err_peer_delete; |
3603 | } | |
5e3dd157 | 3604 | |
9f9b5746 | 3605 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
9dad14ae | 3606 | if (ret) { |
9f9b5746 | 3607 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
69244e56 | 3608 | arvif->vdev_id, ret); |
9dad14ae MK |
3609 | goto err_peer_delete; |
3610 | } | |
5e3dd157 | 3611 | |
9f9b5746 | 3612 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
9dad14ae | 3613 | if (ret) { |
9f9b5746 | 3614 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
69244e56 | 3615 | arvif->vdev_id, ret); |
9dad14ae MK |
3616 | goto err_peer_delete; |
3617 | } | |
5e3dd157 KV |
3618 | } |
3619 | ||
424121c3 | 3620 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
9dad14ae | 3621 | if (ret) { |
7aa7a72a | 3622 | ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n", |
679c54a6 | 3623 | arvif->vdev_id, ret); |
9dad14ae MK |
3624 | goto err_peer_delete; |
3625 | } | |
679c54a6 | 3626 | |
424121c3 | 3627 | ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold); |
9dad14ae | 3628 | if (ret) { |
7aa7a72a | 3629 | ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n", |
679c54a6 | 3630 | arvif->vdev_id, ret); |
9dad14ae MK |
3631 | goto err_peer_delete; |
3632 | } | |
679c54a6 | 3633 | |
7d9d5587 MK |
3634 | arvif->txpower = vif->bss_conf.txpower; |
3635 | ret = ath10k_mac_txpower_recalc(ar); | |
3636 | if (ret) { | |
3637 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); | |
3638 | goto err_peer_delete; | |
3639 | } | |
3640 | ||
5e3dd157 | 3641 | mutex_unlock(&ar->conf_mutex); |
9dad14ae MK |
3642 | return 0; |
3643 | ||
3644 | err_peer_delete: | |
3645 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) | |
3646 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); | |
3647 | ||
3648 | err_vdev_delete: | |
3649 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); | |
16c11176 | 3650 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
0579119f | 3651 | list_del(&arvif->list); |
9dad14ae MK |
3652 | |
3653 | err: | |
64badcb6 MK |
3654 | if (arvif->beacon_buf) { |
3655 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, | |
3656 | arvif->beacon_buf, arvif->beacon_paddr); | |
3657 | arvif->beacon_buf = NULL; | |
3658 | } | |
3659 | ||
9dad14ae MK |
3660 | mutex_unlock(&ar->conf_mutex); |
3661 | ||
5e3dd157 KV |
3662 | return ret; |
3663 | } | |
3664 | ||
3665 | static void ath10k_remove_interface(struct ieee80211_hw *hw, | |
3666 | struct ieee80211_vif *vif) | |
3667 | { | |
3668 | struct ath10k *ar = hw->priv; | |
3669 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
3670 | int ret; | |
3671 | ||
81a9a17d | 3672 | cancel_work_sync(&arvif->ap_csa_work); |
cc9904e6 | 3673 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
81a9a17d | 3674 | |
5d011f5c SM |
3675 | mutex_lock(&ar->conf_mutex); |
3676 | ||
ed54388a | 3677 | spin_lock_bh(&ar->data_lock); |
64badcb6 | 3678 | ath10k_mac_vif_beacon_cleanup(arvif); |
ed54388a MK |
3679 | spin_unlock_bh(&ar->data_lock); |
3680 | ||
855aed12 SW |
3681 | ret = ath10k_spectral_vif_stop(arvif); |
3682 | if (ret) | |
7aa7a72a | 3683 | ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", |
855aed12 SW |
3684 | arvif->vdev_id, ret); |
3685 | ||
16c11176 | 3686 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
0579119f | 3687 | list_del(&arvif->list); |
5e3dd157 KV |
3688 | |
3689 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
2c512059 MK |
3690 | ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id, |
3691 | vif->addr); | |
5e3dd157 | 3692 | if (ret) |
2c512059 | 3693 | ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n", |
69244e56 | 3694 | arvif->vdev_id, ret); |
5e3dd157 KV |
3695 | |
3696 | kfree(arvif->u.ap.noa_data); | |
3697 | } | |
3698 | ||
7aa7a72a | 3699 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n", |
60c3daa8 KV |
3700 | arvif->vdev_id); |
3701 | ||
5e3dd157 KV |
3702 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
3703 | if (ret) | |
7aa7a72a | 3704 | ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n", |
69244e56 | 3705 | arvif->vdev_id, ret); |
5e3dd157 | 3706 | |
2c512059 MK |
3707 | /* Some firmware revisions don't notify host about self-peer removal |
3708 | * until after associated vdev is deleted. | |
3709 | */ | |
3710 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
3711 | ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id, | |
3712 | vif->addr); | |
3713 | if (ret) | |
3714 | ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n", | |
3715 | arvif->vdev_id, ret); | |
3716 | ||
3717 | spin_lock_bh(&ar->data_lock); | |
3718 | ar->num_peers--; | |
3719 | spin_unlock_bh(&ar->data_lock); | |
3720 | } | |
3721 | ||
5e3dd157 KV |
3722 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
3723 | ||
3724 | mutex_unlock(&ar->conf_mutex); | |
3725 | } | |
3726 | ||
3727 | /* | |
3728 | * FIXME: Has to be verified. | |
3729 | */ | |
3730 | #define SUPPORTED_FILTERS \ | |
3731 | (FIF_PROMISC_IN_BSS | \ | |
3732 | FIF_ALLMULTI | \ | |
3733 | FIF_CONTROL | \ | |
3734 | FIF_PSPOLL | \ | |
3735 | FIF_OTHER_BSS | \ | |
3736 | FIF_BCN_PRBRESP_PROMISC | \ | |
3737 | FIF_PROBE_REQ | \ | |
3738 | FIF_FCSFAIL) | |
3739 | ||
3740 | static void ath10k_configure_filter(struct ieee80211_hw *hw, | |
3741 | unsigned int changed_flags, | |
3742 | unsigned int *total_flags, | |
3743 | u64 multicast) | |
3744 | { | |
3745 | struct ath10k *ar = hw->priv; | |
3746 | int ret; | |
3747 | ||
3748 | mutex_lock(&ar->conf_mutex); | |
3749 | ||
3750 | changed_flags &= SUPPORTED_FILTERS; | |
3751 | *total_flags &= SUPPORTED_FILTERS; | |
3752 | ar->filter_flags = *total_flags; | |
3753 | ||
1933747f MK |
3754 | ret = ath10k_monitor_recalc(ar); |
3755 | if (ret) | |
3756 | ath10k_warn(ar, "failed to recalc montior: %d\n", ret); | |
5e3dd157 KV |
3757 | |
3758 | mutex_unlock(&ar->conf_mutex); | |
3759 | } | |
3760 | ||
3761 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, | |
3762 | struct ieee80211_vif *vif, | |
3763 | struct ieee80211_bss_conf *info, | |
3764 | u32 changed) | |
3765 | { | |
3766 | struct ath10k *ar = hw->priv; | |
3767 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
3768 | int ret = 0; | |
af762c0b | 3769 | u32 vdev_param, pdev_param, slottime, preamble; |
5e3dd157 KV |
3770 | |
3771 | mutex_lock(&ar->conf_mutex); | |
3772 | ||
3773 | if (changed & BSS_CHANGED_IBSS) | |
3774 | ath10k_control_ibss(arvif, info, vif->addr); | |
3775 | ||
3776 | if (changed & BSS_CHANGED_BEACON_INT) { | |
3777 | arvif->beacon_interval = info->beacon_int; | |
6d1506e7 BM |
3778 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
3779 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 | 3780 | arvif->beacon_interval); |
7aa7a72a | 3781 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
3782 | "mac vdev %d beacon_interval %d\n", |
3783 | arvif->vdev_id, arvif->beacon_interval); | |
3784 | ||
5e3dd157 | 3785 | if (ret) |
7aa7a72a | 3786 | ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n", |
69244e56 | 3787 | arvif->vdev_id, ret); |
5e3dd157 KV |
3788 | } |
3789 | ||
3790 | if (changed & BSS_CHANGED_BEACON) { | |
7aa7a72a | 3791 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
3792 | "vdev %d set beacon tx mode to staggered\n", |
3793 | arvif->vdev_id); | |
3794 | ||
226a339b BM |
3795 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
3796 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, | |
5e3dd157 KV |
3797 | WMI_BEACON_STAGGERED_MODE); |
3798 | if (ret) | |
7aa7a72a | 3799 | ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n", |
69244e56 | 3800 | arvif->vdev_id, ret); |
fbb8f1b7 MK |
3801 | |
3802 | ret = ath10k_mac_setup_bcn_tmpl(arvif); | |
3803 | if (ret) | |
3804 | ath10k_warn(ar, "failed to update beacon template: %d\n", | |
3805 | ret); | |
3806 | } | |
3807 | ||
3808 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { | |
3809 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
3810 | if (ret) | |
3811 | ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n", | |
3812 | arvif->vdev_id, ret); | |
5e3dd157 KV |
3813 | } |
3814 | ||
ba2479fe | 3815 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
5e3dd157 KV |
3816 | arvif->dtim_period = info->dtim_period; |
3817 | ||
7aa7a72a | 3818 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
3819 | "mac vdev %d dtim_period %d\n", |
3820 | arvif->vdev_id, arvif->dtim_period); | |
3821 | ||
6d1506e7 BM |
3822 | vdev_param = ar->wmi.vdev_param->dtim_period; |
3823 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
3824 | arvif->dtim_period); |
3825 | if (ret) | |
7aa7a72a | 3826 | ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n", |
69244e56 | 3827 | arvif->vdev_id, ret); |
5e3dd157 KV |
3828 | } |
3829 | ||
3830 | if (changed & BSS_CHANGED_SSID && | |
3831 | vif->type == NL80211_IFTYPE_AP) { | |
3832 | arvif->u.ap.ssid_len = info->ssid_len; | |
3833 | if (info->ssid_len) | |
3834 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); | |
3835 | arvif->u.ap.hidden_ssid = info->hidden_ssid; | |
3836 | } | |
3837 | ||
077efc8c MK |
3838 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
3839 | ether_addr_copy(arvif->bssid, info->bssid); | |
5e3dd157 KV |
3840 | |
3841 | if (changed & BSS_CHANGED_BEACON_ENABLED) | |
3842 | ath10k_control_beaconing(arvif, info); | |
3843 | ||
3844 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
e81bd104 | 3845 | arvif->use_cts_prot = info->use_cts_prot; |
7aa7a72a | 3846 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n", |
e81bd104 | 3847 | arvif->vdev_id, info->use_cts_prot); |
60c3daa8 | 3848 | |
e81bd104 | 3849 | ret = ath10k_recalc_rtscts_prot(arvif); |
5e3dd157 | 3850 | if (ret) |
7aa7a72a | 3851 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
69244e56 | 3852 | arvif->vdev_id, ret); |
a87fd4b9 MK |
3853 | |
3854 | vdev_param = ar->wmi.vdev_param->protection_mode; | |
3855 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
3856 | info->use_cts_prot ? 1 : 0); | |
3857 | if (ret) | |
3858 | ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n", | |
3859 | info->use_cts_prot, arvif->vdev_id, ret); | |
5e3dd157 KV |
3860 | } |
3861 | ||
3862 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
5e3dd157 KV |
3863 | if (info->use_short_slot) |
3864 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ | |
3865 | ||
3866 | else | |
3867 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ | |
3868 | ||
7aa7a72a | 3869 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n", |
60c3daa8 KV |
3870 | arvif->vdev_id, slottime); |
3871 | ||
6d1506e7 BM |
3872 | vdev_param = ar->wmi.vdev_param->slot_time; |
3873 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
3874 | slottime); |
3875 | if (ret) | |
7aa7a72a | 3876 | ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n", |
69244e56 | 3877 | arvif->vdev_id, ret); |
5e3dd157 KV |
3878 | } |
3879 | ||
3880 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
5e3dd157 KV |
3881 | if (info->use_short_preamble) |
3882 | preamble = WMI_VDEV_PREAMBLE_SHORT; | |
3883 | else | |
3884 | preamble = WMI_VDEV_PREAMBLE_LONG; | |
3885 | ||
7aa7a72a | 3886 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
3887 | "mac vdev %d preamble %dn", |
3888 | arvif->vdev_id, preamble); | |
3889 | ||
6d1506e7 BM |
3890 | vdev_param = ar->wmi.vdev_param->preamble; |
3891 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
3892 | preamble); |
3893 | if (ret) | |
7aa7a72a | 3894 | ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n", |
69244e56 | 3895 | arvif->vdev_id, ret); |
5e3dd157 KV |
3896 | } |
3897 | ||
3898 | if (changed & BSS_CHANGED_ASSOC) { | |
e556f111 MK |
3899 | if (info->assoc) { |
3900 | /* Workaround: Make sure monitor vdev is not running | |
3901 | * when associating to prevent some firmware revisions | |
3902 | * (e.g. 10.1 and 10.2) from crashing. | |
3903 | */ | |
3904 | if (ar->monitor_started) | |
3905 | ath10k_monitor_stop(ar); | |
5e3dd157 | 3906 | ath10k_bss_assoc(hw, vif, info); |
e556f111 | 3907 | ath10k_monitor_recalc(ar); |
077efc8c MK |
3908 | } else { |
3909 | ath10k_bss_disassoc(hw, vif); | |
e556f111 | 3910 | } |
5e3dd157 KV |
3911 | } |
3912 | ||
7d9d5587 MK |
3913 | if (changed & BSS_CHANGED_TXPOWER) { |
3914 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n", | |
3915 | arvif->vdev_id, info->txpower); | |
3916 | ||
3917 | arvif->txpower = info->txpower; | |
3918 | ret = ath10k_mac_txpower_recalc(ar); | |
3919 | if (ret) | |
3920 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); | |
3921 | } | |
3922 | ||
bf14e65c | 3923 | if (changed & BSS_CHANGED_PS) { |
cffb41f3 MK |
3924 | arvif->ps = vif->bss_conf.ps; |
3925 | ||
3926 | ret = ath10k_config_ps(ar); | |
bf14e65c MK |
3927 | if (ret) |
3928 | ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n", | |
3929 | arvif->vdev_id, ret); | |
3930 | } | |
3931 | ||
5e3dd157 KV |
3932 | mutex_unlock(&ar->conf_mutex); |
3933 | } | |
3934 | ||
3935 | static int ath10k_hw_scan(struct ieee80211_hw *hw, | |
3936 | struct ieee80211_vif *vif, | |
c56ef672 | 3937 | struct ieee80211_scan_request *hw_req) |
5e3dd157 KV |
3938 | { |
3939 | struct ath10k *ar = hw->priv; | |
3940 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
c56ef672 | 3941 | struct cfg80211_scan_request *req = &hw_req->req; |
5e3dd157 KV |
3942 | struct wmi_start_scan_arg arg; |
3943 | int ret = 0; | |
3944 | int i; | |
3945 | ||
3946 | mutex_lock(&ar->conf_mutex); | |
3947 | ||
3948 | spin_lock_bh(&ar->data_lock); | |
5c81c7fd MK |
3949 | switch (ar->scan.state) { |
3950 | case ATH10K_SCAN_IDLE: | |
3951 | reinit_completion(&ar->scan.started); | |
3952 | reinit_completion(&ar->scan.completed); | |
3953 | ar->scan.state = ATH10K_SCAN_STARTING; | |
3954 | ar->scan.is_roc = false; | |
3955 | ar->scan.vdev_id = arvif->vdev_id; | |
3956 | ret = 0; | |
3957 | break; | |
3958 | case ATH10K_SCAN_STARTING: | |
3959 | case ATH10K_SCAN_RUNNING: | |
3960 | case ATH10K_SCAN_ABORTING: | |
5e3dd157 | 3961 | ret = -EBUSY; |
5c81c7fd | 3962 | break; |
5e3dd157 | 3963 | } |
5e3dd157 KV |
3964 | spin_unlock_bh(&ar->data_lock); |
3965 | ||
5c81c7fd MK |
3966 | if (ret) |
3967 | goto exit; | |
3968 | ||
5e3dd157 KV |
3969 | memset(&arg, 0, sizeof(arg)); |
3970 | ath10k_wmi_start_scan_init(ar, &arg); | |
3971 | arg.vdev_id = arvif->vdev_id; | |
3972 | arg.scan_id = ATH10K_SCAN_ID; | |
3973 | ||
3974 | if (!req->no_cck) | |
3975 | arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES; | |
3976 | ||
3977 | if (req->ie_len) { | |
3978 | arg.ie_len = req->ie_len; | |
3979 | memcpy(arg.ie, req->ie, arg.ie_len); | |
3980 | } | |
3981 | ||
3982 | if (req->n_ssids) { | |
3983 | arg.n_ssids = req->n_ssids; | |
3984 | for (i = 0; i < arg.n_ssids; i++) { | |
3985 | arg.ssids[i].len = req->ssids[i].ssid_len; | |
3986 | arg.ssids[i].ssid = req->ssids[i].ssid; | |
3987 | } | |
dcd4a561 MK |
3988 | } else { |
3989 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; | |
5e3dd157 KV |
3990 | } |
3991 | ||
3992 | if (req->n_channels) { | |
3993 | arg.n_channels = req->n_channels; | |
3994 | for (i = 0; i < arg.n_channels; i++) | |
3995 | arg.channels[i] = req->channels[i]->center_freq; | |
3996 | } | |
3997 | ||
3998 | ret = ath10k_start_scan(ar, &arg); | |
3999 | if (ret) { | |
7aa7a72a | 4000 | ath10k_warn(ar, "failed to start hw scan: %d\n", ret); |
5e3dd157 | 4001 | spin_lock_bh(&ar->data_lock); |
5c81c7fd | 4002 | ar->scan.state = ATH10K_SCAN_IDLE; |
5e3dd157 KV |
4003 | spin_unlock_bh(&ar->data_lock); |
4004 | } | |
4005 | ||
4006 | exit: | |
4007 | mutex_unlock(&ar->conf_mutex); | |
4008 | return ret; | |
4009 | } | |
4010 | ||
4011 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, | |
4012 | struct ieee80211_vif *vif) | |
4013 | { | |
4014 | struct ath10k *ar = hw->priv; | |
5e3dd157 KV |
4015 | |
4016 | mutex_lock(&ar->conf_mutex); | |
5c81c7fd | 4017 | ath10k_scan_abort(ar); |
5e3dd157 | 4018 | mutex_unlock(&ar->conf_mutex); |
4eb2e164 MK |
4019 | |
4020 | cancel_delayed_work_sync(&ar->scan.timeout); | |
5e3dd157 KV |
4021 | } |
4022 | ||
cfb27d29 MK |
4023 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
4024 | struct ath10k_vif *arvif, | |
4025 | enum set_key_cmd cmd, | |
4026 | struct ieee80211_key_conf *key) | |
4027 | { | |
4028 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; | |
4029 | int ret; | |
4030 | ||
4031 | /* 10.1 firmware branch requires default key index to be set to group | |
4032 | * key index after installing it. Otherwise FW/HW Txes corrupted | |
4033 | * frames with multi-vif APs. This is not required for main firmware | |
4034 | * branch (e.g. 636). | |
4035 | * | |
4036 | * FIXME: This has been tested only in AP. It remains unknown if this | |
4037 | * is required for multi-vif STA interfaces on 10.1 */ | |
4038 | ||
4039 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) | |
4040 | return; | |
4041 | ||
4042 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) | |
4043 | return; | |
4044 | ||
4045 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) | |
4046 | return; | |
4047 | ||
4048 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
4049 | return; | |
4050 | ||
4051 | if (cmd != SET_KEY) | |
4052 | return; | |
4053 | ||
4054 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
4055 | key->keyidx); | |
4056 | if (ret) | |
7aa7a72a | 4057 | ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n", |
69244e56 | 4058 | arvif->vdev_id, ret); |
cfb27d29 MK |
4059 | } |
4060 | ||
5e3dd157 KV |
4061 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
4062 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
4063 | struct ieee80211_key_conf *key) | |
4064 | { | |
4065 | struct ath10k *ar = hw->priv; | |
4066 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
4067 | struct ath10k_peer *peer; | |
4068 | const u8 *peer_addr; | |
4069 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || | |
4070 | key->cipher == WLAN_CIPHER_SUITE_WEP104; | |
4071 | int ret = 0; | |
370e5673 | 4072 | u32 flags = 0; |
5e3dd157 | 4073 | |
d7131c04 BM |
4074 | /* this one needs to be done in software */ |
4075 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) | |
4076 | return 1; | |
4077 | ||
5e3dd157 KV |
4078 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
4079 | return -ENOSPC; | |
4080 | ||
4081 | mutex_lock(&ar->conf_mutex); | |
4082 | ||
4083 | if (sta) | |
4084 | peer_addr = sta->addr; | |
4085 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
4086 | peer_addr = vif->bss_conf.bssid; | |
4087 | else | |
4088 | peer_addr = vif->addr; | |
4089 | ||
4090 | key->hw_key_idx = key->keyidx; | |
4091 | ||
4092 | /* the peer should not disappear in mid-way (unless FW goes awry) since | |
4093 | * we already hold conf_mutex. we just make sure its there now. */ | |
4094 | spin_lock_bh(&ar->data_lock); | |
4095 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); | |
4096 | spin_unlock_bh(&ar->data_lock); | |
4097 | ||
4098 | if (!peer) { | |
4099 | if (cmd == SET_KEY) { | |
7aa7a72a | 4100 | ath10k_warn(ar, "failed to install key for non-existent peer %pM\n", |
5e3dd157 KV |
4101 | peer_addr); |
4102 | ret = -EOPNOTSUPP; | |
4103 | goto exit; | |
4104 | } else { | |
4105 | /* if the peer doesn't exist there is no key to disable | |
4106 | * anymore */ | |
4107 | goto exit; | |
4108 | } | |
4109 | } | |
4110 | ||
7cc4573e MK |
4111 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
4112 | flags |= WMI_KEY_PAIRWISE; | |
4113 | else | |
4114 | flags |= WMI_KEY_GROUP; | |
4115 | ||
5e3dd157 KV |
4116 | if (is_wep) { |
4117 | if (cmd == SET_KEY) | |
4118 | arvif->wep_keys[key->keyidx] = key; | |
4119 | else | |
4120 | arvif->wep_keys[key->keyidx] = NULL; | |
4121 | ||
4122 | if (cmd == DISABLE_KEY) | |
4123 | ath10k_clear_vdev_key(arvif, key); | |
370e5673 | 4124 | |
ad325cb5 MK |
4125 | /* When WEP keys are uploaded it's possible that there are |
4126 | * stations associated already (e.g. when merging) without any | |
4127 | * keys. Static WEP needs an explicit per-peer key upload. | |
4128 | */ | |
4129 | if (vif->type == NL80211_IFTYPE_ADHOC && | |
4130 | cmd == SET_KEY) | |
4131 | ath10k_mac_vif_update_wep_key(arvif, key); | |
4132 | ||
370e5673 MK |
4133 | /* 802.1x never sets the def_wep_key_idx so each set_key() |
4134 | * call changes default tx key. | |
4135 | * | |
4136 | * Static WEP sets def_wep_key_idx via .set_default_unicast_key | |
4137 | * after first set_key(). | |
4138 | */ | |
4139 | if (cmd == SET_KEY && arvif->def_wep_key_idx == -1) | |
4140 | flags |= WMI_KEY_TX_USAGE; | |
5e3dd157 | 4141 | |
7cc4573e MK |
4142 | /* mac80211 uploads static WEP keys as groupwise while fw/hw |
4143 | * requires pairwise keys for non-self peers, i.e. BSSID in STA | |
4144 | * mode and associated stations in AP/IBSS. | |
4145 | * | |
4146 | * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys | |
4147 | * work fine when mapped directly from mac80211. | |
4148 | * | |
4149 | * Note: When installing first static WEP groupwise key (which | |
4150 | * should be pairwise) def_wep_key_idx isn't known yet (it's | |
4151 | * equal to -1). Since .set_default_unicast_key is called only | |
4152 | * for static WEP it's used to re-upload the key as pairwise. | |
4153 | */ | |
4154 | if (arvif->def_wep_key_idx >= 0 && | |
4155 | memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) { | |
4156 | flags &= ~WMI_KEY_GROUP; | |
4157 | flags |= WMI_KEY_PAIRWISE; | |
4158 | } | |
370e5673 | 4159 | } |
627613f8 | 4160 | |
370e5673 | 4161 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags); |
5e3dd157 | 4162 | if (ret) { |
7aa7a72a | 4163 | ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n", |
69244e56 | 4164 | arvif->vdev_id, peer_addr, ret); |
5e3dd157 KV |
4165 | goto exit; |
4166 | } | |
4167 | ||
cfb27d29 MK |
4168 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
4169 | ||
5e3dd157 KV |
4170 | spin_lock_bh(&ar->data_lock); |
4171 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); | |
4172 | if (peer && cmd == SET_KEY) | |
4173 | peer->keys[key->keyidx] = key; | |
4174 | else if (peer && cmd == DISABLE_KEY) | |
4175 | peer->keys[key->keyidx] = NULL; | |
4176 | else if (peer == NULL) | |
4177 | /* impossible unless FW goes crazy */ | |
7aa7a72a | 4178 | ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr); |
5e3dd157 KV |
4179 | spin_unlock_bh(&ar->data_lock); |
4180 | ||
4181 | exit: | |
4182 | mutex_unlock(&ar->conf_mutex); | |
4183 | return ret; | |
4184 | } | |
4185 | ||
627613f8 SJ |
4186 | static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw, |
4187 | struct ieee80211_vif *vif, | |
4188 | int keyidx) | |
4189 | { | |
4190 | struct ath10k *ar = hw->priv; | |
4191 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
4192 | int ret; | |
4193 | ||
4194 | mutex_lock(&arvif->ar->conf_mutex); | |
4195 | ||
4196 | if (arvif->ar->state != ATH10K_STATE_ON) | |
4197 | goto unlock; | |
4198 | ||
4199 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", | |
4200 | arvif->vdev_id, keyidx); | |
4201 | ||
4202 | ret = ath10k_wmi_vdev_set_param(arvif->ar, | |
4203 | arvif->vdev_id, | |
4204 | arvif->ar->wmi.vdev_param->def_keyid, | |
4205 | keyidx); | |
4206 | ||
4207 | if (ret) { | |
4208 | ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n", | |
4209 | arvif->vdev_id, | |
4210 | ret); | |
4211 | goto unlock; | |
4212 | } | |
4213 | ||
4214 | arvif->def_wep_key_idx = keyidx; | |
370e5673 MK |
4215 | |
4216 | ret = ath10k_mac_vif_sta_fix_wep_key(arvif); | |
4217 | if (ret) { | |
4218 | ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n", | |
4219 | arvif->vdev_id, ret); | |
4220 | goto unlock; | |
4221 | } | |
4222 | ||
627613f8 SJ |
4223 | unlock: |
4224 | mutex_unlock(&arvif->ar->conf_mutex); | |
4225 | } | |
4226 | ||
9797febc MK |
4227 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
4228 | { | |
4229 | struct ath10k *ar; | |
4230 | struct ath10k_vif *arvif; | |
4231 | struct ath10k_sta *arsta; | |
4232 | struct ieee80211_sta *sta; | |
4233 | u32 changed, bw, nss, smps; | |
4234 | int err; | |
4235 | ||
4236 | arsta = container_of(wk, struct ath10k_sta, update_wk); | |
4237 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); | |
4238 | arvif = arsta->arvif; | |
4239 | ar = arvif->ar; | |
4240 | ||
4241 | spin_lock_bh(&ar->data_lock); | |
4242 | ||
4243 | changed = arsta->changed; | |
4244 | arsta->changed = 0; | |
4245 | ||
4246 | bw = arsta->bw; | |
4247 | nss = arsta->nss; | |
4248 | smps = arsta->smps; | |
4249 | ||
4250 | spin_unlock_bh(&ar->data_lock); | |
4251 | ||
4252 | mutex_lock(&ar->conf_mutex); | |
4253 | ||
4254 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
7aa7a72a | 4255 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n", |
9797febc MK |
4256 | sta->addr, bw); |
4257 | ||
4258 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
4259 | WMI_PEER_CHAN_WIDTH, bw); | |
4260 | if (err) | |
7aa7a72a | 4261 | ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n", |
9797febc MK |
4262 | sta->addr, bw, err); |
4263 | } | |
4264 | ||
4265 | if (changed & IEEE80211_RC_NSS_CHANGED) { | |
7aa7a72a | 4266 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n", |
9797febc MK |
4267 | sta->addr, nss); |
4268 | ||
4269 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
4270 | WMI_PEER_NSS, nss); | |
4271 | if (err) | |
7aa7a72a | 4272 | ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n", |
9797febc MK |
4273 | sta->addr, nss, err); |
4274 | } | |
4275 | ||
4276 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
7aa7a72a | 4277 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n", |
9797febc MK |
4278 | sta->addr, smps); |
4279 | ||
4280 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
4281 | WMI_PEER_SMPS_STATE, smps); | |
4282 | if (err) | |
7aa7a72a | 4283 | ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n", |
9797febc MK |
4284 | sta->addr, smps, err); |
4285 | } | |
4286 | ||
55884c04 JD |
4287 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED || |
4288 | changed & IEEE80211_RC_NSS_CHANGED) { | |
4289 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n", | |
44d6fa90 CYY |
4290 | sta->addr); |
4291 | ||
590922a8 | 4292 | err = ath10k_station_assoc(ar, arvif->vif, sta, true); |
44d6fa90 | 4293 | if (err) |
7aa7a72a | 4294 | ath10k_warn(ar, "failed to reassociate station: %pM\n", |
44d6fa90 CYY |
4295 | sta->addr); |
4296 | } | |
4297 | ||
9797febc MK |
4298 | mutex_unlock(&ar->conf_mutex); |
4299 | } | |
4300 | ||
cfd1061e MK |
4301 | static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif) |
4302 | { | |
4303 | struct ath10k *ar = arvif->ar; | |
4304 | ||
4305 | lockdep_assert_held(&ar->conf_mutex); | |
4306 | ||
4307 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && | |
4308 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) | |
4309 | return 0; | |
4310 | ||
4311 | if (ar->num_stations >= ar->max_num_stations) | |
4312 | return -ENOBUFS; | |
4313 | ||
4314 | ar->num_stations++; | |
4315 | ||
4316 | return 0; | |
4317 | } | |
4318 | ||
4319 | static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif) | |
4320 | { | |
4321 | struct ath10k *ar = arvif->ar; | |
4322 | ||
4323 | lockdep_assert_held(&ar->conf_mutex); | |
4324 | ||
4325 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && | |
4326 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) | |
4327 | return; | |
4328 | ||
4329 | ar->num_stations--; | |
4330 | } | |
4331 | ||
5e3dd157 KV |
4332 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
4333 | struct ieee80211_vif *vif, | |
4334 | struct ieee80211_sta *sta, | |
4335 | enum ieee80211_sta_state old_state, | |
4336 | enum ieee80211_sta_state new_state) | |
4337 | { | |
4338 | struct ath10k *ar = hw->priv; | |
4339 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
9797febc | 4340 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
5e3dd157 KV |
4341 | int ret = 0; |
4342 | ||
76f90024 MK |
4343 | if (old_state == IEEE80211_STA_NOTEXIST && |
4344 | new_state == IEEE80211_STA_NONE) { | |
4345 | memset(arsta, 0, sizeof(*arsta)); | |
4346 | arsta->arvif = arvif; | |
4347 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); | |
4348 | } | |
4349 | ||
9797febc MK |
4350 | /* cancel must be done outside the mutex to avoid deadlock */ |
4351 | if ((old_state == IEEE80211_STA_NONE && | |
4352 | new_state == IEEE80211_STA_NOTEXIST)) | |
4353 | cancel_work_sync(&arsta->update_wk); | |
4354 | ||
5e3dd157 KV |
4355 | mutex_lock(&ar->conf_mutex); |
4356 | ||
4357 | if (old_state == IEEE80211_STA_NOTEXIST && | |
077efc8c | 4358 | new_state == IEEE80211_STA_NONE) { |
5e3dd157 KV |
4359 | /* |
4360 | * New station addition. | |
4361 | */ | |
cfd1061e MK |
4362 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
4363 | "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n", | |
4364 | arvif->vdev_id, sta->addr, | |
4365 | ar->num_stations + 1, ar->max_num_stations, | |
4366 | ar->num_peers + 1, ar->max_num_peers); | |
0e759f36 | 4367 | |
cfd1061e MK |
4368 | ret = ath10k_mac_inc_num_stations(arvif); |
4369 | if (ret) { | |
4370 | ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n", | |
4371 | ar->max_num_stations); | |
0e759f36 BM |
4372 | goto exit; |
4373 | } | |
4374 | ||
5e3dd157 | 4375 | ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr); |
a52c0282 | 4376 | if (ret) { |
7aa7a72a | 4377 | ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n", |
479398b0 | 4378 | sta->addr, arvif->vdev_id, ret); |
cfd1061e | 4379 | ath10k_mac_dec_num_stations(arvif); |
a52c0282 MK |
4380 | goto exit; |
4381 | } | |
077efc8c MK |
4382 | |
4383 | if (vif->type == NL80211_IFTYPE_STATION) { | |
4384 | WARN_ON(arvif->is_started); | |
4385 | ||
4386 | ret = ath10k_vdev_start(arvif); | |
4387 | if (ret) { | |
4388 | ath10k_warn(ar, "failed to start vdev %i: %d\n", | |
4389 | arvif->vdev_id, ret); | |
4390 | WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id, | |
4391 | sta->addr)); | |
cfd1061e | 4392 | ath10k_mac_dec_num_stations(arvif); |
077efc8c MK |
4393 | goto exit; |
4394 | } | |
4395 | ||
4396 | arvif->is_started = true; | |
4397 | } | |
5e3dd157 KV |
4398 | } else if ((old_state == IEEE80211_STA_NONE && |
4399 | new_state == IEEE80211_STA_NOTEXIST)) { | |
4400 | /* | |
4401 | * Existing station deletion. | |
4402 | */ | |
7aa7a72a | 4403 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
4404 | "mac vdev %d peer delete %pM (sta gone)\n", |
4405 | arvif->vdev_id, sta->addr); | |
077efc8c MK |
4406 | |
4407 | if (vif->type == NL80211_IFTYPE_STATION) { | |
4408 | WARN_ON(!arvif->is_started); | |
4409 | ||
4410 | ret = ath10k_vdev_stop(arvif); | |
4411 | if (ret) | |
4412 | ath10k_warn(ar, "failed to stop vdev %i: %d\n", | |
4413 | arvif->vdev_id, ret); | |
4414 | ||
4415 | arvif->is_started = false; | |
4416 | } | |
4417 | ||
5e3dd157 KV |
4418 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
4419 | if (ret) | |
7aa7a72a | 4420 | ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n", |
69244e56 | 4421 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 | 4422 | |
cfd1061e | 4423 | ath10k_mac_dec_num_stations(arvif); |
5e3dd157 KV |
4424 | } else if (old_state == IEEE80211_STA_AUTH && |
4425 | new_state == IEEE80211_STA_ASSOC && | |
4426 | (vif->type == NL80211_IFTYPE_AP || | |
4427 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
4428 | /* | |
4429 | * New association. | |
4430 | */ | |
7aa7a72a | 4431 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", |
60c3daa8 KV |
4432 | sta->addr); |
4433 | ||
590922a8 | 4434 | ret = ath10k_station_assoc(ar, vif, sta, false); |
5e3dd157 | 4435 | if (ret) |
7aa7a72a | 4436 | ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n", |
69244e56 | 4437 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 KV |
4438 | } else if (old_state == IEEE80211_STA_ASSOC && |
4439 | new_state == IEEE80211_STA_AUTH && | |
4440 | (vif->type == NL80211_IFTYPE_AP || | |
4441 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
4442 | /* | |
4443 | * Disassociation. | |
4444 | */ | |
7aa7a72a | 4445 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
60c3daa8 KV |
4446 | sta->addr); |
4447 | ||
590922a8 | 4448 | ret = ath10k_station_disassoc(ar, vif, sta); |
5e3dd157 | 4449 | if (ret) |
7aa7a72a | 4450 | ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", |
69244e56 | 4451 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 | 4452 | } |
0e759f36 | 4453 | exit: |
5e3dd157 KV |
4454 | mutex_unlock(&ar->conf_mutex); |
4455 | return ret; | |
4456 | } | |
4457 | ||
4458 | static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif, | |
5b07e07f | 4459 | u16 ac, bool enable) |
5e3dd157 KV |
4460 | { |
4461 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
b0e56154 MK |
4462 | struct wmi_sta_uapsd_auto_trig_arg arg = {}; |
4463 | u32 prio = 0, acc = 0; | |
5e3dd157 KV |
4464 | u32 value = 0; |
4465 | int ret = 0; | |
4466 | ||
548db54c MK |
4467 | lockdep_assert_held(&ar->conf_mutex); |
4468 | ||
5e3dd157 KV |
4469 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
4470 | return 0; | |
4471 | ||
4472 | switch (ac) { | |
4473 | case IEEE80211_AC_VO: | |
4474 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | | |
4475 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; | |
b0e56154 MK |
4476 | prio = 7; |
4477 | acc = 3; | |
5e3dd157 KV |
4478 | break; |
4479 | case IEEE80211_AC_VI: | |
4480 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | | |
4481 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; | |
b0e56154 MK |
4482 | prio = 5; |
4483 | acc = 2; | |
5e3dd157 KV |
4484 | break; |
4485 | case IEEE80211_AC_BE: | |
4486 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | | |
4487 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; | |
b0e56154 MK |
4488 | prio = 2; |
4489 | acc = 1; | |
5e3dd157 KV |
4490 | break; |
4491 | case IEEE80211_AC_BK: | |
4492 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | | |
4493 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; | |
b0e56154 MK |
4494 | prio = 0; |
4495 | acc = 0; | |
5e3dd157 KV |
4496 | break; |
4497 | } | |
4498 | ||
4499 | if (enable) | |
4500 | arvif->u.sta.uapsd |= value; | |
4501 | else | |
4502 | arvif->u.sta.uapsd &= ~value; | |
4503 | ||
4504 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4505 | WMI_STA_PS_PARAM_UAPSD, | |
4506 | arvif->u.sta.uapsd); | |
4507 | if (ret) { | |
7aa7a72a | 4508 | ath10k_warn(ar, "failed to set uapsd params: %d\n", ret); |
5e3dd157 KV |
4509 | goto exit; |
4510 | } | |
4511 | ||
4512 | if (arvif->u.sta.uapsd) | |
4513 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; | |
4514 | else | |
4515 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
4516 | ||
4517 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4518 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, | |
4519 | value); | |
4520 | if (ret) | |
7aa7a72a | 4521 | ath10k_warn(ar, "failed to set rx wake param: %d\n", ret); |
5e3dd157 | 4522 | |
9f9b5746 MK |
4523 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
4524 | if (ret) { | |
4525 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", | |
4526 | arvif->vdev_id, ret); | |
4527 | return ret; | |
4528 | } | |
4529 | ||
4530 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); | |
4531 | if (ret) { | |
4532 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", | |
4533 | arvif->vdev_id, ret); | |
4534 | return ret; | |
4535 | } | |
4536 | ||
b0e56154 MK |
4537 | if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) || |
4538 | test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) { | |
4539 | /* Only userspace can make an educated decision when to send | |
4540 | * trigger frame. The following effectively disables u-UAPSD | |
4541 | * autotrigger in firmware (which is enabled by default | |
4542 | * provided the autotrigger service is available). | |
4543 | */ | |
4544 | ||
4545 | arg.wmm_ac = acc; | |
4546 | arg.user_priority = prio; | |
4547 | arg.service_interval = 0; | |
4548 | arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; | |
4549 | arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; | |
4550 | ||
4551 | ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id, | |
4552 | arvif->bssid, &arg, 1); | |
4553 | if (ret) { | |
4554 | ath10k_warn(ar, "failed to set uapsd auto trigger %d\n", | |
4555 | ret); | |
4556 | return ret; | |
4557 | } | |
4558 | } | |
4559 | ||
5e3dd157 KV |
4560 | exit: |
4561 | return ret; | |
4562 | } | |
4563 | ||
4564 | static int ath10k_conf_tx(struct ieee80211_hw *hw, | |
4565 | struct ieee80211_vif *vif, u16 ac, | |
4566 | const struct ieee80211_tx_queue_params *params) | |
4567 | { | |
4568 | struct ath10k *ar = hw->priv; | |
5e752e42 | 4569 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
5e3dd157 KV |
4570 | struct wmi_wmm_params_arg *p = NULL; |
4571 | int ret; | |
4572 | ||
4573 | mutex_lock(&ar->conf_mutex); | |
4574 | ||
4575 | switch (ac) { | |
4576 | case IEEE80211_AC_VO: | |
5e752e42 | 4577 | p = &arvif->wmm_params.ac_vo; |
5e3dd157 KV |
4578 | break; |
4579 | case IEEE80211_AC_VI: | |
5e752e42 | 4580 | p = &arvif->wmm_params.ac_vi; |
5e3dd157 KV |
4581 | break; |
4582 | case IEEE80211_AC_BE: | |
5e752e42 | 4583 | p = &arvif->wmm_params.ac_be; |
5e3dd157 KV |
4584 | break; |
4585 | case IEEE80211_AC_BK: | |
5e752e42 | 4586 | p = &arvif->wmm_params.ac_bk; |
5e3dd157 KV |
4587 | break; |
4588 | } | |
4589 | ||
4590 | if (WARN_ON(!p)) { | |
4591 | ret = -EINVAL; | |
4592 | goto exit; | |
4593 | } | |
4594 | ||
4595 | p->cwmin = params->cw_min; | |
4596 | p->cwmax = params->cw_max; | |
4597 | p->aifs = params->aifs; | |
4598 | ||
4599 | /* | |
4600 | * The channel time duration programmed in the HW is in absolute | |
4601 | * microseconds, while mac80211 gives the txop in units of | |
4602 | * 32 microseconds. | |
4603 | */ | |
4604 | p->txop = params->txop * 32; | |
4605 | ||
7fc979a7 MK |
4606 | if (ar->wmi.ops->gen_vdev_wmm_conf) { |
4607 | ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id, | |
4608 | &arvif->wmm_params); | |
4609 | if (ret) { | |
4610 | ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n", | |
4611 | arvif->vdev_id, ret); | |
4612 | goto exit; | |
4613 | } | |
4614 | } else { | |
4615 | /* This won't work well with multi-interface cases but it's | |
4616 | * better than nothing. | |
4617 | */ | |
4618 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params); | |
4619 | if (ret) { | |
4620 | ath10k_warn(ar, "failed to set wmm params: %d\n", ret); | |
4621 | goto exit; | |
4622 | } | |
5e3dd157 KV |
4623 | } |
4624 | ||
4625 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); | |
4626 | if (ret) | |
7aa7a72a | 4627 | ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret); |
5e3dd157 KV |
4628 | |
4629 | exit: | |
4630 | mutex_unlock(&ar->conf_mutex); | |
4631 | return ret; | |
4632 | } | |
4633 | ||
4634 | #define ATH10K_ROC_TIMEOUT_HZ (2*HZ) | |
4635 | ||
4636 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, | |
4637 | struct ieee80211_vif *vif, | |
4638 | struct ieee80211_channel *chan, | |
4639 | int duration, | |
4640 | enum ieee80211_roc_type type) | |
4641 | { | |
4642 | struct ath10k *ar = hw->priv; | |
4643 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
4644 | struct wmi_start_scan_arg arg; | |
5c81c7fd | 4645 | int ret = 0; |
5e3dd157 KV |
4646 | |
4647 | mutex_lock(&ar->conf_mutex); | |
4648 | ||
4649 | spin_lock_bh(&ar->data_lock); | |
5c81c7fd MK |
4650 | switch (ar->scan.state) { |
4651 | case ATH10K_SCAN_IDLE: | |
4652 | reinit_completion(&ar->scan.started); | |
4653 | reinit_completion(&ar->scan.completed); | |
4654 | reinit_completion(&ar->scan.on_channel); | |
4655 | ar->scan.state = ATH10K_SCAN_STARTING; | |
4656 | ar->scan.is_roc = true; | |
4657 | ar->scan.vdev_id = arvif->vdev_id; | |
4658 | ar->scan.roc_freq = chan->center_freq; | |
4659 | ret = 0; | |
4660 | break; | |
4661 | case ATH10K_SCAN_STARTING: | |
4662 | case ATH10K_SCAN_RUNNING: | |
4663 | case ATH10K_SCAN_ABORTING: | |
5e3dd157 | 4664 | ret = -EBUSY; |
5c81c7fd | 4665 | break; |
5e3dd157 | 4666 | } |
5e3dd157 KV |
4667 | spin_unlock_bh(&ar->data_lock); |
4668 | ||
5c81c7fd MK |
4669 | if (ret) |
4670 | goto exit; | |
4671 | ||
dcca0bdb MK |
4672 | duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC); |
4673 | ||
5e3dd157 KV |
4674 | memset(&arg, 0, sizeof(arg)); |
4675 | ath10k_wmi_start_scan_init(ar, &arg); | |
4676 | arg.vdev_id = arvif->vdev_id; | |
4677 | arg.scan_id = ATH10K_SCAN_ID; | |
4678 | arg.n_channels = 1; | |
4679 | arg.channels[0] = chan->center_freq; | |
4680 | arg.dwell_time_active = duration; | |
4681 | arg.dwell_time_passive = duration; | |
4682 | arg.max_scan_time = 2 * duration; | |
4683 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; | |
4684 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; | |
4685 | ||
4686 | ret = ath10k_start_scan(ar, &arg); | |
4687 | if (ret) { | |
7aa7a72a | 4688 | ath10k_warn(ar, "failed to start roc scan: %d\n", ret); |
5e3dd157 | 4689 | spin_lock_bh(&ar->data_lock); |
5c81c7fd | 4690 | ar->scan.state = ATH10K_SCAN_IDLE; |
5e3dd157 KV |
4691 | spin_unlock_bh(&ar->data_lock); |
4692 | goto exit; | |
4693 | } | |
4694 | ||
4695 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ); | |
4696 | if (ret == 0) { | |
7aa7a72a | 4697 | ath10k_warn(ar, "failed to switch to channel for roc scan\n"); |
5c81c7fd MK |
4698 | |
4699 | ret = ath10k_scan_stop(ar); | |
4700 | if (ret) | |
7aa7a72a | 4701 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
5c81c7fd | 4702 | |
5e3dd157 KV |
4703 | ret = -ETIMEDOUT; |
4704 | goto exit; | |
4705 | } | |
4706 | ||
4707 | ret = 0; | |
4708 | exit: | |
4709 | mutex_unlock(&ar->conf_mutex); | |
4710 | return ret; | |
4711 | } | |
4712 | ||
4713 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw) | |
4714 | { | |
4715 | struct ath10k *ar = hw->priv; | |
4716 | ||
4717 | mutex_lock(&ar->conf_mutex); | |
5c81c7fd | 4718 | ath10k_scan_abort(ar); |
5e3dd157 KV |
4719 | mutex_unlock(&ar->conf_mutex); |
4720 | ||
4eb2e164 MK |
4721 | cancel_delayed_work_sync(&ar->scan.timeout); |
4722 | ||
5e3dd157 KV |
4723 | return 0; |
4724 | } | |
4725 | ||
4726 | /* | |
4727 | * Both RTS and Fragmentation threshold are interface-specific | |
4728 | * in ath10k, but device-specific in mac80211. | |
4729 | */ | |
5e3dd157 | 4730 | |
ad088bfa MK |
4731 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
4732 | { | |
4733 | struct ath10k *ar = hw->priv; | |
4734 | struct ath10k_vif *arvif; | |
4735 | int ret = 0; | |
548db54c | 4736 | |
5e3dd157 | 4737 | mutex_lock(&ar->conf_mutex); |
ad088bfa | 4738 | list_for_each_entry(arvif, &ar->arvifs, list) { |
7aa7a72a | 4739 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n", |
ad088bfa MK |
4740 | arvif->vdev_id, value); |
4741 | ||
4742 | ret = ath10k_mac_set_rts(arvif, value); | |
4743 | if (ret) { | |
7aa7a72a | 4744 | ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n", |
ad088bfa MK |
4745 | arvif->vdev_id, ret); |
4746 | break; | |
4747 | } | |
4748 | } | |
5e3dd157 KV |
4749 | mutex_unlock(&ar->conf_mutex); |
4750 | ||
ad088bfa | 4751 | return ret; |
5e3dd157 KV |
4752 | } |
4753 | ||
77be2c54 EG |
4754 | static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
4755 | u32 queues, bool drop) | |
5e3dd157 KV |
4756 | { |
4757 | struct ath10k *ar = hw->priv; | |
affd3217 | 4758 | bool skip; |
5e3dd157 KV |
4759 | int ret; |
4760 | ||
4761 | /* mac80211 doesn't care if we really xmit queued frames or not | |
4762 | * we'll collect those frames either way if we stop/delete vdevs */ | |
4763 | if (drop) | |
4764 | return; | |
4765 | ||
548db54c MK |
4766 | mutex_lock(&ar->conf_mutex); |
4767 | ||
affd3217 MK |
4768 | if (ar->state == ATH10K_STATE_WEDGED) |
4769 | goto skip; | |
4770 | ||
edb8236d | 4771 | ret = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
5e3dd157 | 4772 | bool empty; |
affd3217 | 4773 | |
edb8236d | 4774 | spin_lock_bh(&ar->htt.tx_lock); |
0945baf7 | 4775 | empty = (ar->htt.num_pending_tx == 0); |
edb8236d | 4776 | spin_unlock_bh(&ar->htt.tx_lock); |
affd3217 | 4777 | |
7962b0d8 MK |
4778 | skip = (ar->state == ATH10K_STATE_WEDGED) || |
4779 | test_bit(ATH10K_FLAG_CRASH_FLUSH, | |
4780 | &ar->dev_flags); | |
affd3217 MK |
4781 | |
4782 | (empty || skip); | |
5e3dd157 | 4783 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
affd3217 MK |
4784 | |
4785 | if (ret <= 0 || skip) | |
7aa7a72a | 4786 | ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n", |
9ba4c787 | 4787 | skip, ar->state, ret); |
548db54c | 4788 | |
affd3217 | 4789 | skip: |
548db54c | 4790 | mutex_unlock(&ar->conf_mutex); |
5e3dd157 KV |
4791 | } |
4792 | ||
4793 | /* TODO: Implement this function properly | |
4794 | * For now it is needed to reply to Probe Requests in IBSS mode. | |
4795 | * Propably we need this information from FW. | |
4796 | */ | |
4797 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) | |
4798 | { | |
4799 | return 1; | |
4800 | } | |
4801 | ||
8cd13cad MK |
4802 | #ifdef CONFIG_PM |
4803 | static int ath10k_suspend(struct ieee80211_hw *hw, | |
4804 | struct cfg80211_wowlan *wowlan) | |
4805 | { | |
4806 | struct ath10k *ar = hw->priv; | |
4807 | int ret; | |
4808 | ||
9042e17d MP |
4809 | mutex_lock(&ar->conf_mutex); |
4810 | ||
00f5482b | 4811 | ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND); |
8cd13cad | 4812 | if (ret) { |
00f5482b MP |
4813 | if (ret == -ETIMEDOUT) |
4814 | goto resume; | |
9042e17d MP |
4815 | ret = 1; |
4816 | goto exit; | |
8cd13cad MK |
4817 | } |
4818 | ||
8cd13cad MK |
4819 | ret = ath10k_hif_suspend(ar); |
4820 | if (ret) { | |
7aa7a72a | 4821 | ath10k_warn(ar, "failed to suspend hif: %d\n", ret); |
8cd13cad MK |
4822 | goto resume; |
4823 | } | |
4824 | ||
9042e17d MP |
4825 | ret = 0; |
4826 | goto exit; | |
8cd13cad MK |
4827 | resume: |
4828 | ret = ath10k_wmi_pdev_resume_target(ar); | |
4829 | if (ret) | |
7aa7a72a | 4830 | ath10k_warn(ar, "failed to resume target: %d\n", ret); |
9042e17d MP |
4831 | |
4832 | ret = 1; | |
4833 | exit: | |
4834 | mutex_unlock(&ar->conf_mutex); | |
4835 | return ret; | |
8cd13cad MK |
4836 | } |
4837 | ||
4838 | static int ath10k_resume(struct ieee80211_hw *hw) | |
4839 | { | |
4840 | struct ath10k *ar = hw->priv; | |
4841 | int ret; | |
4842 | ||
9042e17d MP |
4843 | mutex_lock(&ar->conf_mutex); |
4844 | ||
8cd13cad MK |
4845 | ret = ath10k_hif_resume(ar); |
4846 | if (ret) { | |
7aa7a72a | 4847 | ath10k_warn(ar, "failed to resume hif: %d\n", ret); |
9042e17d MP |
4848 | ret = 1; |
4849 | goto exit; | |
8cd13cad MK |
4850 | } |
4851 | ||
4852 | ret = ath10k_wmi_pdev_resume_target(ar); | |
4853 | if (ret) { | |
7aa7a72a | 4854 | ath10k_warn(ar, "failed to resume target: %d\n", ret); |
9042e17d MP |
4855 | ret = 1; |
4856 | goto exit; | |
8cd13cad MK |
4857 | } |
4858 | ||
9042e17d MP |
4859 | ret = 0; |
4860 | exit: | |
4861 | mutex_unlock(&ar->conf_mutex); | |
4862 | return ret; | |
8cd13cad MK |
4863 | } |
4864 | #endif | |
4865 | ||
cf2c92d8 EP |
4866 | static void ath10k_reconfig_complete(struct ieee80211_hw *hw, |
4867 | enum ieee80211_reconfig_type reconfig_type) | |
affd3217 MK |
4868 | { |
4869 | struct ath10k *ar = hw->priv; | |
4870 | ||
cf2c92d8 EP |
4871 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
4872 | return; | |
4873 | ||
affd3217 MK |
4874 | mutex_lock(&ar->conf_mutex); |
4875 | ||
4876 | /* If device failed to restart it will be in a different state, e.g. | |
4877 | * ATH10K_STATE_WEDGED */ | |
4878 | if (ar->state == ATH10K_STATE_RESTARTED) { | |
7aa7a72a | 4879 | ath10k_info(ar, "device successfully recovered\n"); |
affd3217 | 4880 | ar->state = ATH10K_STATE_ON; |
7962b0d8 | 4881 | ieee80211_wake_queues(ar->hw); |
affd3217 MK |
4882 | } |
4883 | ||
4884 | mutex_unlock(&ar->conf_mutex); | |
4885 | } | |
4886 | ||
2e1dea40 MK |
4887 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
4888 | struct survey_info *survey) | |
4889 | { | |
4890 | struct ath10k *ar = hw->priv; | |
4891 | struct ieee80211_supported_band *sband; | |
4892 | struct survey_info *ar_survey = &ar->survey[idx]; | |
4893 | int ret = 0; | |
4894 | ||
4895 | mutex_lock(&ar->conf_mutex); | |
4896 | ||
4897 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; | |
4898 | if (sband && idx >= sband->n_channels) { | |
4899 | idx -= sband->n_channels; | |
4900 | sband = NULL; | |
4901 | } | |
4902 | ||
4903 | if (!sband) | |
4904 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; | |
4905 | ||
4906 | if (!sband || idx >= sband->n_channels) { | |
4907 | ret = -ENOENT; | |
4908 | goto exit; | |
4909 | } | |
4910 | ||
4911 | spin_lock_bh(&ar->data_lock); | |
4912 | memcpy(survey, ar_survey, sizeof(*survey)); | |
4913 | spin_unlock_bh(&ar->data_lock); | |
4914 | ||
4915 | survey->channel = &sband->channels[idx]; | |
4916 | ||
fa1d4df8 FF |
4917 | if (ar->rx_channel == survey->channel) |
4918 | survey->filled |= SURVEY_INFO_IN_USE; | |
4919 | ||
2e1dea40 MK |
4920 | exit: |
4921 | mutex_unlock(&ar->conf_mutex); | |
4922 | return ret; | |
4923 | } | |
4924 | ||
51ab1a0a JD |
4925 | /* Helper table for legacy fixed_rate/bitrate_mask */ |
4926 | static const u8 cck_ofdm_rate[] = { | |
4927 | /* CCK */ | |
4928 | 3, /* 1Mbps */ | |
4929 | 2, /* 2Mbps */ | |
4930 | 1, /* 5.5Mbps */ | |
4931 | 0, /* 11Mbps */ | |
4932 | /* OFDM */ | |
4933 | 3, /* 6Mbps */ | |
4934 | 7, /* 9Mbps */ | |
4935 | 2, /* 12Mbps */ | |
4936 | 6, /* 18Mbps */ | |
4937 | 1, /* 24Mbps */ | |
4938 | 5, /* 36Mbps */ | |
4939 | 0, /* 48Mbps */ | |
4940 | 4, /* 54Mbps */ | |
4941 | }; | |
4942 | ||
4943 | /* Check if only one bit set */ | |
4944 | static int ath10k_check_single_mask(u32 mask) | |
4945 | { | |
4946 | int bit; | |
4947 | ||
4948 | bit = ffs(mask); | |
4949 | if (!bit) | |
4950 | return 0; | |
4951 | ||
4952 | mask &= ~BIT(bit - 1); | |
4953 | if (mask) | |
4954 | return 2; | |
4955 | ||
4956 | return 1; | |
4957 | } | |
4958 | ||
4959 | static bool | |
4960 | ath10k_default_bitrate_mask(struct ath10k *ar, | |
4961 | enum ieee80211_band band, | |
4962 | const struct cfg80211_bitrate_mask *mask) | |
4963 | { | |
4964 | u32 legacy = 0x00ff; | |
4965 | u8 ht = 0xff, i; | |
4966 | u16 vht = 0x3ff; | |
b116ea19 BG |
4967 | u16 nrf = ar->num_rf_chains; |
4968 | ||
4969 | if (ar->cfg_tx_chainmask) | |
4970 | nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask); | |
51ab1a0a JD |
4971 | |
4972 | switch (band) { | |
4973 | case IEEE80211_BAND_2GHZ: | |
4974 | legacy = 0x00fff; | |
4975 | vht = 0; | |
4976 | break; | |
4977 | case IEEE80211_BAND_5GHZ: | |
4978 | break; | |
4979 | default: | |
4980 | return false; | |
4981 | } | |
4982 | ||
4983 | if (mask->control[band].legacy != legacy) | |
4984 | return false; | |
4985 | ||
b116ea19 | 4986 | for (i = 0; i < nrf; i++) |
51ab1a0a JD |
4987 | if (mask->control[band].ht_mcs[i] != ht) |
4988 | return false; | |
4989 | ||
b116ea19 | 4990 | for (i = 0; i < nrf; i++) |
51ab1a0a JD |
4991 | if (mask->control[band].vht_mcs[i] != vht) |
4992 | return false; | |
4993 | ||
4994 | return true; | |
4995 | } | |
4996 | ||
4997 | static bool | |
4998 | ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask, | |
4999 | enum ieee80211_band band, | |
5000 | u8 *fixed_nss) | |
5001 | { | |
5002 | int ht_nss = 0, vht_nss = 0, i; | |
5003 | ||
5004 | /* check legacy */ | |
5005 | if (ath10k_check_single_mask(mask->control[band].legacy)) | |
5006 | return false; | |
5007 | ||
5008 | /* check HT */ | |
5009 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
5010 | if (mask->control[band].ht_mcs[i] == 0xff) | |
5011 | continue; | |
5012 | else if (mask->control[band].ht_mcs[i] == 0x00) | |
5013 | break; | |
d8bb26b9 KV |
5014 | |
5015 | return false; | |
51ab1a0a JD |
5016 | } |
5017 | ||
5018 | ht_nss = i; | |
5019 | ||
5020 | /* check VHT */ | |
5021 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
5022 | if (mask->control[band].vht_mcs[i] == 0x03ff) | |
5023 | continue; | |
5024 | else if (mask->control[band].vht_mcs[i] == 0x0000) | |
5025 | break; | |
d8bb26b9 KV |
5026 | |
5027 | return false; | |
51ab1a0a JD |
5028 | } |
5029 | ||
5030 | vht_nss = i; | |
5031 | ||
5032 | if (ht_nss > 0 && vht_nss > 0) | |
5033 | return false; | |
5034 | ||
5035 | if (ht_nss) | |
5036 | *fixed_nss = ht_nss; | |
5037 | else if (vht_nss) | |
5038 | *fixed_nss = vht_nss; | |
5039 | else | |
5040 | return false; | |
5041 | ||
5042 | return true; | |
5043 | } | |
5044 | ||
5045 | static bool | |
5046 | ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask, | |
5047 | enum ieee80211_band band, | |
5048 | enum wmi_rate_preamble *preamble) | |
5049 | { | |
5050 | int legacy = 0, ht = 0, vht = 0, i; | |
5051 | ||
5052 | *preamble = WMI_RATE_PREAMBLE_OFDM; | |
5053 | ||
5054 | /* check legacy */ | |
5055 | legacy = ath10k_check_single_mask(mask->control[band].legacy); | |
5056 | if (legacy > 1) | |
5057 | return false; | |
5058 | ||
5059 | /* check HT */ | |
5060 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
5061 | ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]); | |
5062 | if (ht > 1) | |
5063 | return false; | |
5064 | ||
5065 | /* check VHT */ | |
5066 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
5067 | vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]); | |
5068 | if (vht > 1) | |
5069 | return false; | |
5070 | ||
5071 | /* Currently we support only one fixed_rate */ | |
5072 | if ((legacy + ht + vht) != 1) | |
5073 | return false; | |
5074 | ||
5075 | if (ht) | |
5076 | *preamble = WMI_RATE_PREAMBLE_HT; | |
5077 | else if (vht) | |
5078 | *preamble = WMI_RATE_PREAMBLE_VHT; | |
5079 | ||
5080 | return true; | |
5081 | } | |
5082 | ||
5083 | static bool | |
7aa7a72a MK |
5084 | ath10k_bitrate_mask_rate(struct ath10k *ar, |
5085 | const struct cfg80211_bitrate_mask *mask, | |
51ab1a0a JD |
5086 | enum ieee80211_band band, |
5087 | u8 *fixed_rate, | |
5088 | u8 *fixed_nss) | |
5089 | { | |
5090 | u8 rate = 0, pream = 0, nss = 0, i; | |
5091 | enum wmi_rate_preamble preamble; | |
5092 | ||
5093 | /* Check if single rate correct */ | |
5094 | if (!ath10k_bitrate_mask_correct(mask, band, &preamble)) | |
5095 | return false; | |
5096 | ||
5097 | pream = preamble; | |
5098 | ||
5099 | switch (preamble) { | |
5100 | case WMI_RATE_PREAMBLE_CCK: | |
5101 | case WMI_RATE_PREAMBLE_OFDM: | |
5102 | i = ffs(mask->control[band].legacy) - 1; | |
5103 | ||
5104 | if (band == IEEE80211_BAND_2GHZ && i < 4) | |
5105 | pream = WMI_RATE_PREAMBLE_CCK; | |
5106 | ||
5107 | if (band == IEEE80211_BAND_5GHZ) | |
5108 | i += 4; | |
5109 | ||
5110 | if (i >= ARRAY_SIZE(cck_ofdm_rate)) | |
5111 | return false; | |
5112 | ||
5113 | rate = cck_ofdm_rate[i]; | |
5114 | break; | |
5115 | case WMI_RATE_PREAMBLE_HT: | |
5116 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
5117 | if (mask->control[band].ht_mcs[i]) | |
5118 | break; | |
5119 | ||
5120 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
5121 | return false; | |
5122 | ||
5123 | rate = ffs(mask->control[band].ht_mcs[i]) - 1; | |
5124 | nss = i; | |
5125 | break; | |
5126 | case WMI_RATE_PREAMBLE_VHT: | |
5127 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
5128 | if (mask->control[band].vht_mcs[i]) | |
5129 | break; | |
5130 | ||
5131 | if (i == NL80211_VHT_NSS_MAX) | |
5132 | return false; | |
5133 | ||
5134 | rate = ffs(mask->control[band].vht_mcs[i]) - 1; | |
5135 | nss = i; | |
5136 | break; | |
5137 | } | |
5138 | ||
5139 | *fixed_nss = nss + 1; | |
5140 | nss <<= 4; | |
5141 | pream <<= 6; | |
5142 | ||
7aa7a72a | 5143 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n", |
51ab1a0a JD |
5144 | pream, nss, rate); |
5145 | ||
5146 | *fixed_rate = pream | nss | rate; | |
5147 | ||
5148 | return true; | |
5149 | } | |
5150 | ||
7aa7a72a MK |
5151 | static bool ath10k_get_fixed_rate_nss(struct ath10k *ar, |
5152 | const struct cfg80211_bitrate_mask *mask, | |
51ab1a0a JD |
5153 | enum ieee80211_band band, |
5154 | u8 *fixed_rate, | |
5155 | u8 *fixed_nss) | |
5156 | { | |
5157 | /* First check full NSS mask, if we can simply limit NSS */ | |
5158 | if (ath10k_bitrate_mask_nss(mask, band, fixed_nss)) | |
5159 | return true; | |
5160 | ||
5161 | /* Next Check single rate is set */ | |
7aa7a72a | 5162 | return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss); |
51ab1a0a JD |
5163 | } |
5164 | ||
5165 | static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif, | |
5166 | u8 fixed_rate, | |
9f81f725 JD |
5167 | u8 fixed_nss, |
5168 | u8 force_sgi) | |
51ab1a0a JD |
5169 | { |
5170 | struct ath10k *ar = arvif->ar; | |
5171 | u32 vdev_param; | |
5172 | int ret = 0; | |
5173 | ||
5174 | mutex_lock(&ar->conf_mutex); | |
5175 | ||
5176 | if (arvif->fixed_rate == fixed_rate && | |
9f81f725 JD |
5177 | arvif->fixed_nss == fixed_nss && |
5178 | arvif->force_sgi == force_sgi) | |
51ab1a0a JD |
5179 | goto exit; |
5180 | ||
5181 | if (fixed_rate == WMI_FIXED_RATE_NONE) | |
7aa7a72a | 5182 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n"); |
51ab1a0a | 5183 | |
9f81f725 | 5184 | if (force_sgi) |
7aa7a72a | 5185 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n"); |
9f81f725 | 5186 | |
51ab1a0a JD |
5187 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
5188 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | |
5189 | vdev_param, fixed_rate); | |
5190 | if (ret) { | |
7aa7a72a | 5191 | ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n", |
51ab1a0a JD |
5192 | fixed_rate, ret); |
5193 | ret = -EINVAL; | |
5194 | goto exit; | |
5195 | } | |
5196 | ||
5197 | arvif->fixed_rate = fixed_rate; | |
5198 | ||
5199 | vdev_param = ar->wmi.vdev_param->nss; | |
5200 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | |
5201 | vdev_param, fixed_nss); | |
5202 | ||
5203 | if (ret) { | |
7aa7a72a | 5204 | ath10k_warn(ar, "failed to set fixed nss param %d: %d\n", |
51ab1a0a JD |
5205 | fixed_nss, ret); |
5206 | ret = -EINVAL; | |
5207 | goto exit; | |
5208 | } | |
5209 | ||
5210 | arvif->fixed_nss = fixed_nss; | |
5211 | ||
9f81f725 JD |
5212 | vdev_param = ar->wmi.vdev_param->sgi; |
5213 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5214 | force_sgi); | |
5215 | ||
5216 | if (ret) { | |
7aa7a72a | 5217 | ath10k_warn(ar, "failed to set sgi param %d: %d\n", |
9f81f725 JD |
5218 | force_sgi, ret); |
5219 | ret = -EINVAL; | |
5220 | goto exit; | |
5221 | } | |
5222 | ||
5223 | arvif->force_sgi = force_sgi; | |
5224 | ||
51ab1a0a JD |
5225 | exit: |
5226 | mutex_unlock(&ar->conf_mutex); | |
5227 | return ret; | |
5228 | } | |
5229 | ||
5230 | static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw, | |
5231 | struct ieee80211_vif *vif, | |
5232 | const struct cfg80211_bitrate_mask *mask) | |
5233 | { | |
5234 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
5235 | struct ath10k *ar = arvif->ar; | |
5236 | enum ieee80211_band band = ar->hw->conf.chandef.chan->band; | |
5237 | u8 fixed_rate = WMI_FIXED_RATE_NONE; | |
5238 | u8 fixed_nss = ar->num_rf_chains; | |
9f81f725 JD |
5239 | u8 force_sgi; |
5240 | ||
b116ea19 BG |
5241 | if (ar->cfg_tx_chainmask) |
5242 | fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); | |
5243 | ||
9f81f725 JD |
5244 | force_sgi = mask->control[band].gi; |
5245 | if (force_sgi == NL80211_TXRATE_FORCE_LGI) | |
5246 | return -EINVAL; | |
51ab1a0a JD |
5247 | |
5248 | if (!ath10k_default_bitrate_mask(ar, band, mask)) { | |
7aa7a72a | 5249 | if (!ath10k_get_fixed_rate_nss(ar, mask, band, |
51ab1a0a JD |
5250 | &fixed_rate, |
5251 | &fixed_nss)) | |
5252 | return -EINVAL; | |
5253 | } | |
5254 | ||
9f81f725 | 5255 | if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) { |
7aa7a72a | 5256 | ath10k_warn(ar, "failed to force SGI usage for default rate settings\n"); |
9f81f725 JD |
5257 | return -EINVAL; |
5258 | } | |
5259 | ||
5260 | return ath10k_set_fixed_rate_param(arvif, fixed_rate, | |
5261 | fixed_nss, force_sgi); | |
51ab1a0a JD |
5262 | } |
5263 | ||
9797febc MK |
5264 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
5265 | struct ieee80211_vif *vif, | |
5266 | struct ieee80211_sta *sta, | |
5267 | u32 changed) | |
5268 | { | |
5269 | struct ath10k *ar = hw->priv; | |
5270 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; | |
5271 | u32 bw, smps; | |
5272 | ||
5273 | spin_lock_bh(&ar->data_lock); | |
5274 | ||
7aa7a72a | 5275 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
9797febc MK |
5276 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
5277 | sta->addr, changed, sta->bandwidth, sta->rx_nss, | |
5278 | sta->smps_mode); | |
5279 | ||
5280 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
5281 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
5282 | ||
5283 | switch (sta->bandwidth) { | |
5284 | case IEEE80211_STA_RX_BW_20: | |
5285 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
5286 | break; | |
5287 | case IEEE80211_STA_RX_BW_40: | |
5288 | bw = WMI_PEER_CHWIDTH_40MHZ; | |
5289 | break; | |
5290 | case IEEE80211_STA_RX_BW_80: | |
5291 | bw = WMI_PEER_CHWIDTH_80MHZ; | |
5292 | break; | |
5293 | case IEEE80211_STA_RX_BW_160: | |
7aa7a72a | 5294 | ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n", |
be6546fc | 5295 | sta->bandwidth, sta->addr); |
9797febc MK |
5296 | bw = WMI_PEER_CHWIDTH_20MHZ; |
5297 | break; | |
5298 | } | |
5299 | ||
5300 | arsta->bw = bw; | |
5301 | } | |
5302 | ||
5303 | if (changed & IEEE80211_RC_NSS_CHANGED) | |
5304 | arsta->nss = sta->rx_nss; | |
5305 | ||
5306 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
5307 | smps = WMI_PEER_SMPS_PS_NONE; | |
5308 | ||
5309 | switch (sta->smps_mode) { | |
5310 | case IEEE80211_SMPS_AUTOMATIC: | |
5311 | case IEEE80211_SMPS_OFF: | |
5312 | smps = WMI_PEER_SMPS_PS_NONE; | |
5313 | break; | |
5314 | case IEEE80211_SMPS_STATIC: | |
5315 | smps = WMI_PEER_SMPS_STATIC; | |
5316 | break; | |
5317 | case IEEE80211_SMPS_DYNAMIC: | |
5318 | smps = WMI_PEER_SMPS_DYNAMIC; | |
5319 | break; | |
5320 | case IEEE80211_SMPS_NUM_MODES: | |
7aa7a72a | 5321 | ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n", |
be6546fc | 5322 | sta->smps_mode, sta->addr); |
9797febc MK |
5323 | smps = WMI_PEER_SMPS_PS_NONE; |
5324 | break; | |
5325 | } | |
5326 | ||
5327 | arsta->smps = smps; | |
5328 | } | |
5329 | ||
9797febc MK |
5330 | arsta->changed |= changed; |
5331 | ||
5332 | spin_unlock_bh(&ar->data_lock); | |
5333 | ||
5334 | ieee80211_queue_work(hw, &arsta->update_wk); | |
5335 | } | |
5336 | ||
26ebbccf CYY |
5337 | static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
5338 | { | |
5339 | /* | |
5340 | * FIXME: Return 0 for time being. Need to figure out whether FW | |
5341 | * has the API to fetch 64-bit local TSF | |
5342 | */ | |
5343 | ||
5344 | return 0; | |
5345 | } | |
5346 | ||
aa5b4fbc MK |
5347 | static int ath10k_ampdu_action(struct ieee80211_hw *hw, |
5348 | struct ieee80211_vif *vif, | |
5349 | enum ieee80211_ampdu_mlme_action action, | |
5350 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, | |
5351 | u8 buf_size) | |
5352 | { | |
7aa7a72a | 5353 | struct ath10k *ar = hw->priv; |
aa5b4fbc MK |
5354 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
5355 | ||
7aa7a72a | 5356 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n", |
aa5b4fbc MK |
5357 | arvif->vdev_id, sta->addr, tid, action); |
5358 | ||
5359 | switch (action) { | |
5360 | case IEEE80211_AMPDU_RX_START: | |
5361 | case IEEE80211_AMPDU_RX_STOP: | |
5362 | /* HTT AddBa/DelBa events trigger mac80211 Rx BA session | |
5363 | * creation/removal. Do we need to verify this? | |
5364 | */ | |
5365 | return 0; | |
5366 | case IEEE80211_AMPDU_TX_START: | |
5367 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
5368 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
5369 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
5370 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
5371 | /* Firmware offloads Tx aggregation entirely so deny mac80211 | |
5372 | * Tx aggregation requests. | |
5373 | */ | |
5374 | return -EOPNOTSUPP; | |
5375 | } | |
5376 | ||
5377 | return -EINVAL; | |
5378 | } | |
5379 | ||
5e3dd157 KV |
5380 | static const struct ieee80211_ops ath10k_ops = { |
5381 | .tx = ath10k_tx, | |
5382 | .start = ath10k_start, | |
5383 | .stop = ath10k_stop, | |
5384 | .config = ath10k_config, | |
5385 | .add_interface = ath10k_add_interface, | |
5386 | .remove_interface = ath10k_remove_interface, | |
5387 | .configure_filter = ath10k_configure_filter, | |
5388 | .bss_info_changed = ath10k_bss_info_changed, | |
5389 | .hw_scan = ath10k_hw_scan, | |
5390 | .cancel_hw_scan = ath10k_cancel_hw_scan, | |
5391 | .set_key = ath10k_set_key, | |
627613f8 | 5392 | .set_default_unicast_key = ath10k_set_default_unicast_key, |
5e3dd157 KV |
5393 | .sta_state = ath10k_sta_state, |
5394 | .conf_tx = ath10k_conf_tx, | |
5395 | .remain_on_channel = ath10k_remain_on_channel, | |
5396 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, | |
5397 | .set_rts_threshold = ath10k_set_rts_threshold, | |
5e3dd157 KV |
5398 | .flush = ath10k_flush, |
5399 | .tx_last_beacon = ath10k_tx_last_beacon, | |
46acf7bb BG |
5400 | .set_antenna = ath10k_set_antenna, |
5401 | .get_antenna = ath10k_get_antenna, | |
cf2c92d8 | 5402 | .reconfig_complete = ath10k_reconfig_complete, |
2e1dea40 | 5403 | .get_survey = ath10k_get_survey, |
51ab1a0a | 5404 | .set_bitrate_mask = ath10k_set_bitrate_mask, |
9797febc | 5405 | .sta_rc_update = ath10k_sta_rc_update, |
26ebbccf | 5406 | .get_tsf = ath10k_get_tsf, |
aa5b4fbc | 5407 | .ampdu_action = ath10k_ampdu_action, |
6cddcc7a BG |
5408 | .get_et_sset_count = ath10k_debug_get_et_sset_count, |
5409 | .get_et_stats = ath10k_debug_get_et_stats, | |
5410 | .get_et_strings = ath10k_debug_get_et_strings, | |
43d2a30f KV |
5411 | |
5412 | CFG80211_TESTMODE_CMD(ath10k_tm_cmd) | |
5413 | ||
8cd13cad MK |
5414 | #ifdef CONFIG_PM |
5415 | .suspend = ath10k_suspend, | |
5416 | .resume = ath10k_resume, | |
5417 | #endif | |
f5045988 RM |
5418 | #ifdef CONFIG_MAC80211_DEBUGFS |
5419 | .sta_add_debugfs = ath10k_sta_add_debugfs, | |
5420 | #endif | |
5e3dd157 KV |
5421 | }; |
5422 | ||
5423 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ | |
5424 | .bitrate = (_rate), \ | |
5425 | .flags = (_flags), \ | |
5426 | .hw_value = (_rateid), \ | |
5427 | } | |
5428 | ||
5429 | #define CHAN2G(_channel, _freq, _flags) { \ | |
5430 | .band = IEEE80211_BAND_2GHZ, \ | |
5431 | .hw_value = (_channel), \ | |
5432 | .center_freq = (_freq), \ | |
5433 | .flags = (_flags), \ | |
5434 | .max_antenna_gain = 0, \ | |
5435 | .max_power = 30, \ | |
5436 | } | |
5437 | ||
5438 | #define CHAN5G(_channel, _freq, _flags) { \ | |
5439 | .band = IEEE80211_BAND_5GHZ, \ | |
5440 | .hw_value = (_channel), \ | |
5441 | .center_freq = (_freq), \ | |
5442 | .flags = (_flags), \ | |
5443 | .max_antenna_gain = 0, \ | |
5444 | .max_power = 30, \ | |
5445 | } | |
5446 | ||
5447 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { | |
5448 | CHAN2G(1, 2412, 0), | |
5449 | CHAN2G(2, 2417, 0), | |
5450 | CHAN2G(3, 2422, 0), | |
5451 | CHAN2G(4, 2427, 0), | |
5452 | CHAN2G(5, 2432, 0), | |
5453 | CHAN2G(6, 2437, 0), | |
5454 | CHAN2G(7, 2442, 0), | |
5455 | CHAN2G(8, 2447, 0), | |
5456 | CHAN2G(9, 2452, 0), | |
5457 | CHAN2G(10, 2457, 0), | |
5458 | CHAN2G(11, 2462, 0), | |
5459 | CHAN2G(12, 2467, 0), | |
5460 | CHAN2G(13, 2472, 0), | |
5461 | CHAN2G(14, 2484, 0), | |
5462 | }; | |
5463 | ||
5464 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { | |
429ff56a MK |
5465 | CHAN5G(36, 5180, 0), |
5466 | CHAN5G(40, 5200, 0), | |
5467 | CHAN5G(44, 5220, 0), | |
5468 | CHAN5G(48, 5240, 0), | |
5469 | CHAN5G(52, 5260, 0), | |
5470 | CHAN5G(56, 5280, 0), | |
5471 | CHAN5G(60, 5300, 0), | |
5472 | CHAN5G(64, 5320, 0), | |
5473 | CHAN5G(100, 5500, 0), | |
5474 | CHAN5G(104, 5520, 0), | |
5475 | CHAN5G(108, 5540, 0), | |
5476 | CHAN5G(112, 5560, 0), | |
5477 | CHAN5G(116, 5580, 0), | |
5478 | CHAN5G(120, 5600, 0), | |
5479 | CHAN5G(124, 5620, 0), | |
5480 | CHAN5G(128, 5640, 0), | |
5481 | CHAN5G(132, 5660, 0), | |
5482 | CHAN5G(136, 5680, 0), | |
5483 | CHAN5G(140, 5700, 0), | |
5484 | CHAN5G(149, 5745, 0), | |
5485 | CHAN5G(153, 5765, 0), | |
5486 | CHAN5G(157, 5785, 0), | |
5487 | CHAN5G(161, 5805, 0), | |
5488 | CHAN5G(165, 5825, 0), | |
5e3dd157 KV |
5489 | }; |
5490 | ||
91b12089 MK |
5491 | /* Note: Be careful if you re-order these. There is code which depends on this |
5492 | * ordering. | |
5493 | */ | |
5e3dd157 KV |
5494 | static struct ieee80211_rate ath10k_rates[] = { |
5495 | /* CCK */ | |
5496 | RATETAB_ENT(10, 0x82, 0), | |
5497 | RATETAB_ENT(20, 0x84, 0), | |
5498 | RATETAB_ENT(55, 0x8b, 0), | |
5499 | RATETAB_ENT(110, 0x96, 0), | |
5500 | /* OFDM */ | |
5501 | RATETAB_ENT(60, 0x0c, 0), | |
5502 | RATETAB_ENT(90, 0x12, 0), | |
5503 | RATETAB_ENT(120, 0x18, 0), | |
5504 | RATETAB_ENT(180, 0x24, 0), | |
5505 | RATETAB_ENT(240, 0x30, 0), | |
5506 | RATETAB_ENT(360, 0x48, 0), | |
5507 | RATETAB_ENT(480, 0x60, 0), | |
5508 | RATETAB_ENT(540, 0x6c, 0), | |
5509 | }; | |
5510 | ||
5511 | #define ath10k_a_rates (ath10k_rates + 4) | |
5512 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4) | |
5513 | #define ath10k_g_rates (ath10k_rates + 0) | |
5514 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) | |
5515 | ||
e7b54194 | 5516 | struct ath10k *ath10k_mac_create(size_t priv_size) |
5e3dd157 KV |
5517 | { |
5518 | struct ieee80211_hw *hw; | |
5519 | struct ath10k *ar; | |
5520 | ||
e7b54194 | 5521 | hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops); |
5e3dd157 KV |
5522 | if (!hw) |
5523 | return NULL; | |
5524 | ||
5525 | ar = hw->priv; | |
5526 | ar->hw = hw; | |
5527 | ||
5528 | return ar; | |
5529 | } | |
5530 | ||
5531 | void ath10k_mac_destroy(struct ath10k *ar) | |
5532 | { | |
5533 | ieee80211_free_hw(ar->hw); | |
5534 | } | |
5535 | ||
5536 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { | |
5537 | { | |
5538 | .max = 8, | |
5539 | .types = BIT(NL80211_IFTYPE_STATION) | |
5540 | | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
d531cb85 MK |
5541 | }, |
5542 | { | |
5543 | .max = 3, | |
5544 | .types = BIT(NL80211_IFTYPE_P2P_GO) | |
5545 | }, | |
5546 | { | |
75d2bd48 MK |
5547 | .max = 1, |
5548 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) | |
5549 | }, | |
5550 | { | |
d531cb85 MK |
5551 | .max = 7, |
5552 | .types = BIT(NL80211_IFTYPE_AP) | |
5553 | }, | |
5e3dd157 KV |
5554 | }; |
5555 | ||
f259509b | 5556 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
e8a50f8b MP |
5557 | { |
5558 | .max = 8, | |
5559 | .types = BIT(NL80211_IFTYPE_AP) | |
5560 | }, | |
5561 | }; | |
e8a50f8b MP |
5562 | |
5563 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { | |
5564 | { | |
5565 | .limits = ath10k_if_limits, | |
5566 | .n_limits = ARRAY_SIZE(ath10k_if_limits), | |
5567 | .max_interfaces = 8, | |
5568 | .num_different_channels = 1, | |
5569 | .beacon_int_infra_match = true, | |
5570 | }, | |
f259509b BM |
5571 | }; |
5572 | ||
5573 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { | |
e8a50f8b | 5574 | { |
f259509b BM |
5575 | .limits = ath10k_10x_if_limits, |
5576 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), | |
e8a50f8b MP |
5577 | .max_interfaces = 8, |
5578 | .num_different_channels = 1, | |
5579 | .beacon_int_infra_match = true, | |
f259509b | 5580 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
e8a50f8b MP |
5581 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
5582 | BIT(NL80211_CHAN_WIDTH_20) | | |
5583 | BIT(NL80211_CHAN_WIDTH_40) | | |
5584 | BIT(NL80211_CHAN_WIDTH_80), | |
e8a50f8b | 5585 | #endif |
f259509b | 5586 | }, |
5e3dd157 KV |
5587 | }; |
5588 | ||
5589 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) | |
5590 | { | |
5591 | struct ieee80211_sta_vht_cap vht_cap = {0}; | |
5592 | u16 mcs_map; | |
bc657a36 | 5593 | u32 val; |
8865bee4 | 5594 | int i; |
5e3dd157 KV |
5595 | |
5596 | vht_cap.vht_supported = 1; | |
5597 | vht_cap.cap = ar->vht_cap_info; | |
5598 | ||
bc657a36 MK |
5599 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
5600 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { | |
5601 | val = ar->num_rf_chains - 1; | |
5602 | val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
5603 | val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
5604 | ||
5605 | vht_cap.cap |= val; | |
5606 | } | |
5607 | ||
5608 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
5609 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { | |
5610 | val = ar->num_rf_chains - 1; | |
5611 | val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
5612 | val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
5613 | ||
5614 | vht_cap.cap |= val; | |
5615 | } | |
5616 | ||
8865bee4 MK |
5617 | mcs_map = 0; |
5618 | for (i = 0; i < 8; i++) { | |
5619 | if (i < ar->num_rf_chains) | |
5620 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2); | |
5621 | else | |
5622 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2); | |
5623 | } | |
5e3dd157 KV |
5624 | |
5625 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); | |
5626 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); | |
5627 | ||
5628 | return vht_cap; | |
5629 | } | |
5630 | ||
5631 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) | |
5632 | { | |
5633 | int i; | |
5634 | struct ieee80211_sta_ht_cap ht_cap = {0}; | |
5635 | ||
5636 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) | |
5637 | return ht_cap; | |
5638 | ||
5639 | ht_cap.ht_supported = 1; | |
5640 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
5641 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; | |
5642 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
5643 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
5644 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; | |
5645 | ||
5646 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) | |
5647 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
5648 | ||
5649 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) | |
5650 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
5651 | ||
5652 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { | |
5653 | u32 smps; | |
5654 | ||
5655 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | |
5656 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
5657 | ||
5658 | ht_cap.cap |= smps; | |
5659 | } | |
5660 | ||
5661 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC) | |
5662 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; | |
5663 | ||
5664 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { | |
5665 | u32 stbc; | |
5666 | ||
5667 | stbc = ar->ht_cap_info; | |
5668 | stbc &= WMI_HT_CAP_RX_STBC; | |
5669 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; | |
5670 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
5671 | stbc &= IEEE80211_HT_CAP_RX_STBC; | |
5672 | ||
5673 | ht_cap.cap |= stbc; | |
5674 | } | |
5675 | ||
5676 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC) | |
5677 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; | |
5678 | ||
5679 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) | |
5680 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; | |
5681 | ||
5682 | /* max AMSDU is implicitly taken from vht_cap_info */ | |
5683 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) | |
5684 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; | |
5685 | ||
8865bee4 | 5686 | for (i = 0; i < ar->num_rf_chains; i++) |
5e3dd157 KV |
5687 | ht_cap.mcs.rx_mask[i] = 0xFF; |
5688 | ||
5689 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; | |
5690 | ||
5691 | return ht_cap; | |
5692 | } | |
5693 | ||
5e3dd157 KV |
5694 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
5695 | struct ieee80211_vif *vif) | |
5696 | { | |
5697 | struct ath10k_vif_iter *arvif_iter = data; | |
5698 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); | |
5699 | ||
5700 | if (arvif->vdev_id == arvif_iter->vdev_id) | |
5701 | arvif_iter->arvif = arvif; | |
5702 | } | |
5703 | ||
5704 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) | |
5705 | { | |
5706 | struct ath10k_vif_iter arvif_iter; | |
5707 | u32 flags; | |
5708 | ||
5709 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); | |
5710 | arvif_iter.vdev_id = vdev_id; | |
5711 | ||
5712 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; | |
5713 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
5714 | flags, | |
5715 | ath10k_get_arvif_iter, | |
5716 | &arvif_iter); | |
5717 | if (!arvif_iter.arvif) { | |
7aa7a72a | 5718 | ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id); |
5e3dd157 KV |
5719 | return NULL; |
5720 | } | |
5721 | ||
5722 | return arvif_iter.arvif; | |
5723 | } | |
5724 | ||
5725 | int ath10k_mac_register(struct ath10k *ar) | |
5726 | { | |
3cb10943 JB |
5727 | static const u32 cipher_suites[] = { |
5728 | WLAN_CIPHER_SUITE_WEP40, | |
5729 | WLAN_CIPHER_SUITE_WEP104, | |
5730 | WLAN_CIPHER_SUITE_TKIP, | |
5731 | WLAN_CIPHER_SUITE_CCMP, | |
5732 | WLAN_CIPHER_SUITE_AES_CMAC, | |
5733 | }; | |
5e3dd157 KV |
5734 | struct ieee80211_supported_band *band; |
5735 | struct ieee80211_sta_vht_cap vht_cap; | |
5736 | struct ieee80211_sta_ht_cap ht_cap; | |
5737 | void *channels; | |
5738 | int ret; | |
5739 | ||
5740 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); | |
5741 | ||
5742 | SET_IEEE80211_DEV(ar->hw, ar->dev); | |
5743 | ||
5744 | ht_cap = ath10k_get_ht_cap(ar); | |
5745 | vht_cap = ath10k_create_vht_cap(ar); | |
5746 | ||
5747 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { | |
5748 | channels = kmemdup(ath10k_2ghz_channels, | |
5749 | sizeof(ath10k_2ghz_channels), | |
5750 | GFP_KERNEL); | |
d6015b27 MK |
5751 | if (!channels) { |
5752 | ret = -ENOMEM; | |
5753 | goto err_free; | |
5754 | } | |
5e3dd157 KV |
5755 | |
5756 | band = &ar->mac.sbands[IEEE80211_BAND_2GHZ]; | |
5757 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); | |
5758 | band->channels = channels; | |
5759 | band->n_bitrates = ath10k_g_rates_size; | |
5760 | band->bitrates = ath10k_g_rates; | |
5761 | band->ht_cap = ht_cap; | |
5762 | ||
d68bb12a YL |
5763 | /* Enable the VHT support at 2.4 GHz */ |
5764 | band->vht_cap = vht_cap; | |
5e3dd157 KV |
5765 | |
5766 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band; | |
5767 | } | |
5768 | ||
5769 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { | |
5770 | channels = kmemdup(ath10k_5ghz_channels, | |
5771 | sizeof(ath10k_5ghz_channels), | |
5772 | GFP_KERNEL); | |
5773 | if (!channels) { | |
d6015b27 MK |
5774 | ret = -ENOMEM; |
5775 | goto err_free; | |
5e3dd157 KV |
5776 | } |
5777 | ||
5778 | band = &ar->mac.sbands[IEEE80211_BAND_5GHZ]; | |
5779 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); | |
5780 | band->channels = channels; | |
5781 | band->n_bitrates = ath10k_a_rates_size; | |
5782 | band->bitrates = ath10k_a_rates; | |
5783 | band->ht_cap = ht_cap; | |
5784 | band->vht_cap = vht_cap; | |
5785 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band; | |
5786 | } | |
5787 | ||
5788 | ar->hw->wiphy->interface_modes = | |
5789 | BIT(NL80211_IFTYPE_STATION) | | |
d354181f BM |
5790 | BIT(NL80211_IFTYPE_AP); |
5791 | ||
46acf7bb BG |
5792 | ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask; |
5793 | ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask; | |
5794 | ||
d354181f BM |
5795 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features)) |
5796 | ar->hw->wiphy->interface_modes |= | |
75d2bd48 | 5797 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
d354181f BM |
5798 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
5799 | BIT(NL80211_IFTYPE_P2P_GO); | |
5e3dd157 KV |
5800 | |
5801 | ar->hw->flags = IEEE80211_HW_SIGNAL_DBM | | |
5802 | IEEE80211_HW_SUPPORTS_PS | | |
5803 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | | |
5e3dd157 KV |
5804 | IEEE80211_HW_MFP_CAPABLE | |
5805 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | | |
5806 | IEEE80211_HW_HAS_RATE_CONTROL | | |
2f0f1121 | 5807 | IEEE80211_HW_AP_LINK_PS | |
3cb10943 | 5808 | IEEE80211_HW_SPECTRUM_MGMT | |
cc9904e6 MK |
5809 | IEEE80211_HW_SW_CRYPTO_CONTROL | |
5810 | IEEE80211_HW_CONNECTION_MONITOR; | |
5e3dd157 | 5811 | |
0d8614b4 EP |
5812 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
5813 | ||
5e3dd157 | 5814 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
0d8614b4 | 5815 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
5e3dd157 KV |
5816 | |
5817 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { | |
5818 | ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; | |
5819 | ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW; | |
5820 | } | |
5821 | ||
5822 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; | |
5823 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; | |
5824 | ||
5825 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); | |
9797febc | 5826 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
5e3dd157 | 5827 | |
5e3dd157 KV |
5828 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
5829 | ||
fbb8f1b7 MK |
5830 | if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) { |
5831 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; | |
5832 | ||
5833 | /* Firmware delivers WPS/P2P Probe Requests frames to driver so | |
5834 | * that userspace (e.g. wpa_supplicant/hostapd) can generate | |
5835 | * correct Probe Responses. This is more of a hack advert.. | |
5836 | */ | |
5837 | ar->hw->wiphy->probe_resp_offload |= | |
5838 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | | |
5839 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | | |
5840 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; | |
5841 | } | |
5842 | ||
5e3dd157 | 5843 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
c2df44b3 | 5844 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
5e3dd157 KV |
5845 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
5846 | ||
5847 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
78157a1c RM |
5848 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE; |
5849 | ||
37a0b394 JD |
5850 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; |
5851 | ||
5e3dd157 KV |
5852 | /* |
5853 | * on LL hardware queues are managed entirely by the FW | |
5854 | * so we only advertise to mac we can do the queues thing | |
5855 | */ | |
5856 | ar->hw->queues = 4; | |
5857 | ||
5cc7caf4 KV |
5858 | switch (ar->wmi.op_version) { |
5859 | case ATH10K_FW_WMI_OP_VERSION_MAIN: | |
5860 | case ATH10K_FW_WMI_OP_VERSION_TLV: | |
f259509b BM |
5861 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
5862 | ar->hw->wiphy->n_iface_combinations = | |
5863 | ARRAY_SIZE(ath10k_if_comb); | |
cf850d1d | 5864 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
5cc7caf4 KV |
5865 | break; |
5866 | case ATH10K_FW_WMI_OP_VERSION_10_1: | |
5867 | case ATH10K_FW_WMI_OP_VERSION_10_2: | |
4a16fbec | 5868 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
5cc7caf4 KV |
5869 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
5870 | ar->hw->wiphy->n_iface_combinations = | |
5871 | ARRAY_SIZE(ath10k_10x_if_comb); | |
5872 | break; | |
5873 | case ATH10K_FW_WMI_OP_VERSION_UNSET: | |
5874 | case ATH10K_FW_WMI_OP_VERSION_MAX: | |
5875 | WARN_ON(1); | |
5876 | ret = -EINVAL; | |
5877 | goto err_free; | |
f259509b | 5878 | } |
5e3dd157 | 5879 | |
7c199997 MK |
5880 | ar->hw->netdev_features = NETIF_F_HW_CSUM; |
5881 | ||
9702c686 JD |
5882 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
5883 | /* Init ath dfs pattern detector */ | |
5884 | ar->ath_common.debug_mask = ATH_DBG_DFS; | |
5885 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, | |
5886 | NL80211_DFS_UNSET); | |
5887 | ||
5888 | if (!ar->dfs_detector) | |
7aa7a72a | 5889 | ath10k_warn(ar, "failed to initialise DFS pattern detector\n"); |
9702c686 JD |
5890 | } |
5891 | ||
5e3dd157 KV |
5892 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
5893 | ath10k_reg_notifier); | |
5894 | if (ret) { | |
7aa7a72a | 5895 | ath10k_err(ar, "failed to initialise regulatory: %i\n", ret); |
d6015b27 | 5896 | goto err_free; |
5e3dd157 KV |
5897 | } |
5898 | ||
3cb10943 JB |
5899 | ar->hw->wiphy->cipher_suites = cipher_suites; |
5900 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
5901 | ||
5e3dd157 KV |
5902 | ret = ieee80211_register_hw(ar->hw); |
5903 | if (ret) { | |
7aa7a72a | 5904 | ath10k_err(ar, "failed to register ieee80211: %d\n", ret); |
d6015b27 | 5905 | goto err_free; |
5e3dd157 KV |
5906 | } |
5907 | ||
5908 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { | |
5909 | ret = regulatory_hint(ar->hw->wiphy, | |
5910 | ar->ath_common.regulatory.alpha2); | |
5911 | if (ret) | |
d6015b27 | 5912 | goto err_unregister; |
5e3dd157 KV |
5913 | } |
5914 | ||
5915 | return 0; | |
d6015b27 MK |
5916 | |
5917 | err_unregister: | |
5e3dd157 | 5918 | ieee80211_unregister_hw(ar->hw); |
d6015b27 MK |
5919 | err_free: |
5920 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); | |
5921 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); | |
5922 | ||
5e3dd157 KV |
5923 | return ret; |
5924 | } | |
5925 | ||
5926 | void ath10k_mac_unregister(struct ath10k *ar) | |
5927 | { | |
5928 | ieee80211_unregister_hw(ar->hw); | |
5929 | ||
9702c686 JD |
5930 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
5931 | ar->dfs_detector->exit(ar->dfs_detector); | |
5932 | ||
5e3dd157 KV |
5933 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
5934 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); | |
5935 | ||
5936 | SET_IEEE80211_DEV(ar->hw, NULL); | |
5937 | } |