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