]>
Commit | Line | Data |
---|---|---|
5e3dd157 KV |
1 | /* |
2 | * Copyright (c) 2005-2011 Atheros Communications Inc. | |
8b1083d6 | 3 | * Copyright (c) 2011-2017 Qualcomm Atheros, Inc. |
38a1390e | 4 | * Copyright (c) 2018, The Linux Foundation. All rights reserved. |
5e3dd157 KV |
5 | * |
6 | * Permission to use, copy, modify, and/or distribute this software for any | |
7 | * purpose with or without fee is hereby granted, provided that the above | |
8 | * copyright notice and this permission notice appear in all copies. | |
9 | * | |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 | */ | |
18 | ||
19 | #include "mac.h" | |
20 | ||
34d5629d | 21 | #include <net/cfg80211.h> |
5e3dd157 KV |
22 | #include <net/mac80211.h> |
23 | #include <linux/etherdevice.h> | |
209b2a68 | 24 | #include <linux/acpi.h> |
84758d4d | 25 | #include <linux/of.h> |
5e3dd157 | 26 | |
8cd13cad | 27 | #include "hif.h" |
5e3dd157 KV |
28 | #include "core.h" |
29 | #include "debug.h" | |
30 | #include "wmi.h" | |
31 | #include "htt.h" | |
32 | #include "txrx.h" | |
43d2a30f | 33 | #include "testmode.h" |
b4aa539d | 34 | #include "wmi-tlv.h" |
d7579d12 | 35 | #include "wmi-ops.h" |
5fd3ac3c | 36 | #include "wow.h" |
5e3dd157 | 37 | |
dcc33098 MK |
38 | /*********/ |
39 | /* Rates */ | |
40 | /*********/ | |
41 | ||
dcc33098 | 42 | static struct ieee80211_rate ath10k_rates[] = { |
5528e032 MK |
43 | { .bitrate = 10, |
44 | .hw_value = ATH10K_HW_RATE_CCK_LP_1M }, | |
45 | { .bitrate = 20, | |
46 | .hw_value = ATH10K_HW_RATE_CCK_LP_2M, | |
47 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M, | |
48 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
49 | { .bitrate = 55, | |
50 | .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M, | |
51 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M, | |
52 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
53 | { .bitrate = 110, | |
54 | .hw_value = ATH10K_HW_RATE_CCK_LP_11M, | |
55 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M, | |
56 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
af00148f MK |
57 | |
58 | { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M }, | |
59 | { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M }, | |
60 | { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M }, | |
61 | { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M }, | |
62 | { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M }, | |
63 | { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M }, | |
64 | { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M }, | |
65 | { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M }, | |
dcc33098 MK |
66 | }; |
67 | ||
5269c659 MSS |
68 | static struct ieee80211_rate ath10k_rates_rev2[] = { |
69 | { .bitrate = 10, | |
70 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M }, | |
71 | { .bitrate = 20, | |
72 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M, | |
73 | .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M, | |
74 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
75 | { .bitrate = 55, | |
76 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M, | |
77 | .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M, | |
78 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
79 | { .bitrate = 110, | |
80 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M, | |
81 | .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M, | |
82 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
83 | ||
84 | { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M }, | |
85 | { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M }, | |
86 | { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M }, | |
87 | { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M }, | |
88 | { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M }, | |
89 | { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M }, | |
90 | { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M }, | |
91 | { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M }, | |
92 | }; | |
93 | ||
8d7aa6bc MK |
94 | #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4 |
95 | ||
96 | #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX) | |
97 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \ | |
98 | ATH10K_MAC_FIRST_OFDM_RATE_IDX) | |
dcc33098 MK |
99 | #define ath10k_g_rates (ath10k_rates + 0) |
100 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) | |
101 | ||
5269c659 MSS |
102 | #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0) |
103 | #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2)) | |
104 | ||
cd93b83a PKC |
105 | #define ath10k_wmi_legacy_rates ath10k_rates |
106 | ||
486017cc MK |
107 | static bool ath10k_mac_bitrate_is_cck(int bitrate) |
108 | { | |
109 | switch (bitrate) { | |
110 | case 10: | |
111 | case 20: | |
112 | case 55: | |
113 | case 110: | |
114 | return true; | |
115 | } | |
116 | ||
117 | return false; | |
118 | } | |
119 | ||
120 | static u8 ath10k_mac_bitrate_to_rate(int bitrate) | |
121 | { | |
122 | return DIV_ROUND_UP(bitrate, 5) | | |
123 | (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); | |
124 | } | |
125 | ||
5528e032 | 126 | u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, |
4b7f353b | 127 | u8 hw_rate, bool cck) |
5528e032 MK |
128 | { |
129 | const struct ieee80211_rate *rate; | |
130 | int i; | |
131 | ||
132 | for (i = 0; i < sband->n_bitrates; i++) { | |
133 | rate = &sband->bitrates[i]; | |
134 | ||
4b7f353b YL |
135 | if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck) |
136 | continue; | |
137 | ||
5528e032 MK |
138 | if (rate->hw_value == hw_rate) |
139 | return i; | |
140 | else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && | |
141 | rate->hw_value_short == hw_rate) | |
142 | return i; | |
143 | } | |
144 | ||
145 | return 0; | |
146 | } | |
147 | ||
01cebe1c MK |
148 | u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, |
149 | u32 bitrate) | |
150 | { | |
151 | int i; | |
152 | ||
153 | for (i = 0; i < sband->n_bitrates; i++) | |
154 | if (sband->bitrates[i].bitrate == bitrate) | |
155 | return i; | |
156 | ||
157 | return 0; | |
158 | } | |
159 | ||
f279294e S |
160 | static int ath10k_mac_get_rate_hw_value(int bitrate) |
161 | { | |
162 | int i; | |
163 | u8 hw_value_prefix = 0; | |
164 | ||
165 | if (ath10k_mac_bitrate_is_cck(bitrate)) | |
166 | hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6; | |
167 | ||
34e141ee | 168 | for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) { |
f279294e S |
169 | if (ath10k_rates[i].bitrate == bitrate) |
170 | return hw_value_prefix | ath10k_rates[i].hw_value; | |
171 | } | |
172 | ||
173 | return -EINVAL; | |
174 | } | |
175 | ||
3ae54225 MK |
176 | static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) |
177 | { | |
178 | switch ((mcs_map >> (2 * nss)) & 0x3) { | |
179 | case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; | |
180 | case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; | |
181 | case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; | |
182 | } | |
183 | return 0; | |
184 | } | |
185 | ||
45c9abc0 MK |
186 | static u32 |
187 | ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | |
188 | { | |
189 | int nss; | |
190 | ||
191 | for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) | |
192 | if (ht_mcs_mask[nss]) | |
193 | return nss + 1; | |
194 | ||
195 | return 1; | |
196 | } | |
197 | ||
198 | static u32 | |
199 | ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
200 | { | |
201 | int nss; | |
202 | ||
203 | for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) | |
204 | if (vht_mcs_mask[nss]) | |
205 | return nss + 1; | |
206 | ||
207 | return 1; | |
208 | } | |
5e3dd157 | 209 | |
7e247a9e RM |
210 | int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val) |
211 | { | |
212 | enum wmi_host_platform_type platform_type; | |
213 | int ret; | |
214 | ||
215 | if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map)) | |
216 | platform_type = WMI_HOST_PLATFORM_LOW_PERF; | |
217 | else | |
218 | platform_type = WMI_HOST_PLATFORM_HIGH_PERF; | |
219 | ||
220 | ret = ath10k_wmi_ext_resource_config(ar, platform_type, val); | |
221 | ||
222 | if (ret && ret != -EOPNOTSUPP) { | |
223 | ath10k_warn(ar, "failed to configure ext resource: %d\n", ret); | |
224 | return ret; | |
225 | } | |
226 | ||
227 | return 0; | |
228 | } | |
229 | ||
5e3dd157 KV |
230 | /**********/ |
231 | /* Crypto */ | |
232 | /**********/ | |
233 | ||
234 | static int ath10k_send_key(struct ath10k_vif *arvif, | |
235 | struct ieee80211_key_conf *key, | |
236 | enum set_key_cmd cmd, | |
370e5673 | 237 | const u8 *macaddr, u32 flags) |
5e3dd157 | 238 | { |
7aa7a72a | 239 | struct ath10k *ar = arvif->ar; |
5e3dd157 KV |
240 | struct wmi_vdev_install_key_arg arg = { |
241 | .vdev_id = arvif->vdev_id, | |
242 | .key_idx = key->keyidx, | |
243 | .key_len = key->keylen, | |
244 | .key_data = key->key, | |
370e5673 | 245 | .key_flags = flags, |
5e3dd157 KV |
246 | .macaddr = macaddr, |
247 | }; | |
248 | ||
548db54c MK |
249 | lockdep_assert_held(&arvif->ar->conf_mutex); |
250 | ||
5e3dd157 KV |
251 | switch (key->cipher) { |
252 | case WLAN_CIPHER_SUITE_CCMP: | |
253 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
e4e82e9a | 254 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
5e3dd157 KV |
255 | break; |
256 | case WLAN_CIPHER_SUITE_TKIP: | |
5e3dd157 KV |
257 | arg.key_cipher = WMI_CIPHER_TKIP; |
258 | arg.key_txmic_len = 8; | |
259 | arg.key_rxmic_len = 8; | |
260 | break; | |
261 | case WLAN_CIPHER_SUITE_WEP40: | |
262 | case WLAN_CIPHER_SUITE_WEP104: | |
263 | arg.key_cipher = WMI_CIPHER_WEP; | |
5e3dd157 | 264 | break; |
2ea9f12c RM |
265 | case WLAN_CIPHER_SUITE_CCMP_256: |
266 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
267 | break; | |
268 | case WLAN_CIPHER_SUITE_GCMP: | |
269 | case WLAN_CIPHER_SUITE_GCMP_256: | |
270 | arg.key_cipher = WMI_CIPHER_AES_GCM; | |
271 | break; | |
272 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: | |
273 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
274 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: | |
3cb10943 | 275 | case WLAN_CIPHER_SUITE_AES_CMAC: |
d7131c04 BM |
276 | WARN_ON(1); |
277 | return -EINVAL; | |
5e3dd157 | 278 | default: |
7aa7a72a | 279 | ath10k_warn(ar, "cipher %d is not supported\n", key->cipher); |
5e3dd157 KV |
280 | return -EOPNOTSUPP; |
281 | } | |
282 | ||
b9e284e5 | 283 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
ccec9038 | 284 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
ccec9038 | 285 | |
5e3dd157 KV |
286 | if (cmd == DISABLE_KEY) { |
287 | arg.key_cipher = WMI_CIPHER_NONE; | |
288 | arg.key_data = NULL; | |
289 | } | |
290 | ||
291 | return ath10k_wmi_vdev_install_key(arvif->ar, &arg); | |
292 | } | |
293 | ||
294 | static int ath10k_install_key(struct ath10k_vif *arvif, | |
295 | struct ieee80211_key_conf *key, | |
296 | enum set_key_cmd cmd, | |
370e5673 | 297 | const u8 *macaddr, u32 flags) |
5e3dd157 KV |
298 | { |
299 | struct ath10k *ar = arvif->ar; | |
300 | int ret; | |
8e9904f5 | 301 | unsigned long time_left; |
5e3dd157 | 302 | |
548db54c MK |
303 | lockdep_assert_held(&ar->conf_mutex); |
304 | ||
16735d02 | 305 | reinit_completion(&ar->install_key_done); |
5e3dd157 | 306 | |
ccec9038 DL |
307 | if (arvif->nohwcrypt) |
308 | return 1; | |
309 | ||
370e5673 | 310 | ret = ath10k_send_key(arvif, key, cmd, macaddr, flags); |
5e3dd157 KV |
311 | if (ret) |
312 | return ret; | |
313 | ||
8e9904f5 NMG |
314 | time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ); |
315 | if (time_left == 0) | |
5e3dd157 KV |
316 | return -ETIMEDOUT; |
317 | ||
318 | return 0; | |
319 | } | |
320 | ||
321 | static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif, | |
322 | const u8 *addr) | |
323 | { | |
324 | struct ath10k *ar = arvif->ar; | |
325 | struct ath10k_peer *peer; | |
326 | int ret; | |
327 | int i; | |
370e5673 | 328 | u32 flags; |
5e3dd157 KV |
329 | |
330 | lockdep_assert_held(&ar->conf_mutex); | |
331 | ||
8674d909 | 332 | if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP && |
7c97b72a PO |
333 | arvif->vif->type != NL80211_IFTYPE_ADHOC && |
334 | arvif->vif->type != NL80211_IFTYPE_MESH_POINT)) | |
8674d909 MK |
335 | return -EINVAL; |
336 | ||
5e3dd157 KV |
337 | spin_lock_bh(&ar->data_lock); |
338 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); | |
339 | spin_unlock_bh(&ar->data_lock); | |
340 | ||
341 | if (!peer) | |
342 | return -ENOENT; | |
343 | ||
344 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { | |
345 | if (arvif->wep_keys[i] == NULL) | |
346 | continue; | |
370e5673 | 347 | |
8674d909 MK |
348 | switch (arvif->vif->type) { |
349 | case NL80211_IFTYPE_AP: | |
350 | flags = WMI_KEY_PAIRWISE; | |
351 | ||
352 | if (arvif->def_wep_key_idx == i) | |
353 | flags |= WMI_KEY_TX_USAGE; | |
354 | ||
355 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], | |
356 | SET_KEY, addr, flags); | |
357 | if (ret < 0) | |
358 | return ret; | |
359 | break; | |
360 | case NL80211_IFTYPE_ADHOC: | |
361 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], | |
362 | SET_KEY, addr, | |
363 | WMI_KEY_PAIRWISE); | |
364 | if (ret < 0) | |
365 | return ret; | |
366 | ||
367 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], | |
368 | SET_KEY, addr, WMI_KEY_GROUP); | |
369 | if (ret < 0) | |
370 | return ret; | |
371 | break; | |
372 | default: | |
373 | WARN_ON(1); | |
374 | return -EINVAL; | |
375 | } | |
5e3dd157 | 376 | |
ae167131 | 377 | spin_lock_bh(&ar->data_lock); |
5e3dd157 | 378 | peer->keys[i] = arvif->wep_keys[i]; |
ae167131 | 379 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 KV |
380 | } |
381 | ||
ce90b271 MK |
382 | /* In some cases (notably with static WEP IBSS with multiple keys) |
383 | * multicast Tx becomes broken. Both pairwise and groupwise keys are | |
384 | * installed already. Using WMI_KEY_TX_USAGE in different combinations | |
385 | * didn't seem help. Using def_keyid vdev parameter seems to be | |
386 | * effective so use that. | |
387 | * | |
388 | * FIXME: Revisit. Perhaps this can be done in a less hacky way. | |
389 | */ | |
8674d909 MK |
390 | if (arvif->vif->type != NL80211_IFTYPE_ADHOC) |
391 | return 0; | |
392 | ||
ce90b271 MK |
393 | if (arvif->def_wep_key_idx == -1) |
394 | return 0; | |
395 | ||
396 | ret = ath10k_wmi_vdev_set_param(arvif->ar, | |
397 | arvif->vdev_id, | |
398 | arvif->ar->wmi.vdev_param->def_keyid, | |
399 | arvif->def_wep_key_idx); | |
400 | if (ret) { | |
401 | ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n", | |
402 | arvif->vdev_id, ret); | |
403 | return ret; | |
404 | } | |
405 | ||
5e3dd157 KV |
406 | return 0; |
407 | } | |
408 | ||
409 | static int ath10k_clear_peer_keys(struct ath10k_vif *arvif, | |
410 | const u8 *addr) | |
411 | { | |
412 | struct ath10k *ar = arvif->ar; | |
413 | struct ath10k_peer *peer; | |
414 | int first_errno = 0; | |
415 | int ret; | |
416 | int i; | |
370e5673 | 417 | u32 flags = 0; |
5e3dd157 KV |
418 | |
419 | lockdep_assert_held(&ar->conf_mutex); | |
420 | ||
421 | spin_lock_bh(&ar->data_lock); | |
422 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); | |
423 | spin_unlock_bh(&ar->data_lock); | |
424 | ||
425 | if (!peer) | |
426 | return -ENOENT; | |
427 | ||
428 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
429 | if (peer->keys[i] == NULL) | |
430 | continue; | |
431 | ||
627613f8 | 432 | /* key flags are not required to delete the key */ |
5e3dd157 | 433 | ret = ath10k_install_key(arvif, peer->keys[i], |
370e5673 | 434 | DISABLE_KEY, addr, flags); |
ccec9038 | 435 | if (ret < 0 && first_errno == 0) |
5e3dd157 KV |
436 | first_errno = ret; |
437 | ||
ccec9038 | 438 | if (ret < 0) |
7aa7a72a | 439 | ath10k_warn(ar, "failed to remove peer wep key %d: %d\n", |
5e3dd157 KV |
440 | i, ret); |
441 | ||
ae167131 | 442 | spin_lock_bh(&ar->data_lock); |
5e3dd157 | 443 | peer->keys[i] = NULL; |
ae167131 | 444 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 KV |
445 | } |
446 | ||
447 | return first_errno; | |
448 | } | |
449 | ||
504f6cdf SM |
450 | bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr, |
451 | u8 keyidx) | |
452 | { | |
453 | struct ath10k_peer *peer; | |
454 | int i; | |
455 | ||
456 | lockdep_assert_held(&ar->data_lock); | |
457 | ||
458 | /* We don't know which vdev this peer belongs to, | |
459 | * since WMI doesn't give us that information. | |
460 | * | |
461 | * FIXME: multi-bss needs to be handled. | |
462 | */ | |
463 | peer = ath10k_peer_find(ar, 0, addr); | |
464 | if (!peer) | |
465 | return false; | |
466 | ||
467 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
468 | if (peer->keys[i] && peer->keys[i]->keyidx == keyidx) | |
469 | return true; | |
470 | } | |
471 | ||
472 | return false; | |
473 | } | |
474 | ||
5e3dd157 KV |
475 | static int ath10k_clear_vdev_key(struct ath10k_vif *arvif, |
476 | struct ieee80211_key_conf *key) | |
477 | { | |
478 | struct ath10k *ar = arvif->ar; | |
479 | struct ath10k_peer *peer; | |
480 | u8 addr[ETH_ALEN]; | |
481 | int first_errno = 0; | |
482 | int ret; | |
483 | int i; | |
370e5673 | 484 | u32 flags = 0; |
5e3dd157 KV |
485 | |
486 | lockdep_assert_held(&ar->conf_mutex); | |
487 | ||
488 | for (;;) { | |
489 | /* since ath10k_install_key we can't hold data_lock all the | |
d6dfe25c MR |
490 | * time, so we try to remove the keys incrementally |
491 | */ | |
5e3dd157 KV |
492 | spin_lock_bh(&ar->data_lock); |
493 | i = 0; | |
494 | list_for_each_entry(peer, &ar->peers, list) { | |
495 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
496 | if (peer->keys[i] == key) { | |
b25f32cb | 497 | ether_addr_copy(addr, peer->addr); |
5e3dd157 KV |
498 | peer->keys[i] = NULL; |
499 | break; | |
500 | } | |
501 | } | |
502 | ||
503 | if (i < ARRAY_SIZE(peer->keys)) | |
504 | break; | |
505 | } | |
506 | spin_unlock_bh(&ar->data_lock); | |
507 | ||
508 | if (i == ARRAY_SIZE(peer->keys)) | |
509 | break; | |
627613f8 | 510 | /* key flags are not required to delete the key */ |
370e5673 | 511 | ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags); |
ccec9038 | 512 | if (ret < 0 && first_errno == 0) |
5e3dd157 KV |
513 | first_errno = ret; |
514 | ||
515 | if (ret) | |
7aa7a72a | 516 | ath10k_warn(ar, "failed to remove key for %pM: %d\n", |
be6546fc | 517 | addr, ret); |
5e3dd157 KV |
518 | } |
519 | ||
520 | return first_errno; | |
521 | } | |
522 | ||
ad325cb5 MK |
523 | static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif, |
524 | struct ieee80211_key_conf *key) | |
525 | { | |
526 | struct ath10k *ar = arvif->ar; | |
527 | struct ath10k_peer *peer; | |
528 | int ret; | |
529 | ||
530 | lockdep_assert_held(&ar->conf_mutex); | |
531 | ||
532 | list_for_each_entry(peer, &ar->peers, list) { | |
c178da58 | 533 | if (ether_addr_equal(peer->addr, arvif->vif->addr)) |
ad325cb5 MK |
534 | continue; |
535 | ||
c178da58 | 536 | if (ether_addr_equal(peer->addr, arvif->bssid)) |
ad325cb5 MK |
537 | continue; |
538 | ||
539 | if (peer->keys[key->keyidx] == key) | |
540 | continue; | |
541 | ||
542 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n", | |
543 | arvif->vdev_id, key->keyidx); | |
544 | ||
545 | ret = ath10k_install_peer_wep_keys(arvif, peer->addr); | |
546 | if (ret) { | |
547 | ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n", | |
548 | arvif->vdev_id, peer->addr, ret); | |
549 | return ret; | |
550 | } | |
551 | } | |
552 | ||
553 | return 0; | |
554 | } | |
555 | ||
5e3dd157 KV |
556 | /*********************/ |
557 | /* General utilities */ | |
558 | /*********************/ | |
559 | ||
560 | static inline enum wmi_phy_mode | |
561 | chan_to_phymode(const struct cfg80211_chan_def *chandef) | |
562 | { | |
563 | enum wmi_phy_mode phymode = MODE_UNKNOWN; | |
564 | ||
565 | switch (chandef->chan->band) { | |
57fbcce3 | 566 | case NL80211_BAND_2GHZ: |
5e3dd157 KV |
567 | switch (chandef->width) { |
568 | case NL80211_CHAN_WIDTH_20_NOHT: | |
6faab127 PO |
569 | if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM) |
570 | phymode = MODE_11B; | |
571 | else | |
572 | phymode = MODE_11G; | |
5e3dd157 KV |
573 | break; |
574 | case NL80211_CHAN_WIDTH_20: | |
575 | phymode = MODE_11NG_HT20; | |
576 | break; | |
577 | case NL80211_CHAN_WIDTH_40: | |
578 | phymode = MODE_11NG_HT40; | |
579 | break; | |
0f817ed5 JL |
580 | case NL80211_CHAN_WIDTH_5: |
581 | case NL80211_CHAN_WIDTH_10: | |
5e3dd157 KV |
582 | case NL80211_CHAN_WIDTH_80: |
583 | case NL80211_CHAN_WIDTH_80P80: | |
584 | case NL80211_CHAN_WIDTH_160: | |
585 | phymode = MODE_UNKNOWN; | |
586 | break; | |
587 | } | |
588 | break; | |
57fbcce3 | 589 | case NL80211_BAND_5GHZ: |
5e3dd157 KV |
590 | switch (chandef->width) { |
591 | case NL80211_CHAN_WIDTH_20_NOHT: | |
592 | phymode = MODE_11A; | |
593 | break; | |
594 | case NL80211_CHAN_WIDTH_20: | |
595 | phymode = MODE_11NA_HT20; | |
596 | break; | |
597 | case NL80211_CHAN_WIDTH_40: | |
598 | phymode = MODE_11NA_HT40; | |
599 | break; | |
600 | case NL80211_CHAN_WIDTH_80: | |
601 | phymode = MODE_11AC_VHT80; | |
602 | break; | |
bc1efd73 SG |
603 | case NL80211_CHAN_WIDTH_160: |
604 | phymode = MODE_11AC_VHT160; | |
605 | break; | |
606 | case NL80211_CHAN_WIDTH_80P80: | |
607 | phymode = MODE_11AC_VHT80_80; | |
608 | break; | |
0f817ed5 JL |
609 | case NL80211_CHAN_WIDTH_5: |
610 | case NL80211_CHAN_WIDTH_10: | |
5e3dd157 KV |
611 | phymode = MODE_UNKNOWN; |
612 | break; | |
613 | } | |
614 | break; | |
615 | default: | |
616 | break; | |
617 | } | |
618 | ||
619 | WARN_ON(phymode == MODE_UNKNOWN); | |
620 | return phymode; | |
621 | } | |
622 | ||
623 | static u8 ath10k_parse_mpdudensity(u8 mpdudensity) | |
624 | { | |
625 | /* | |
626 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": | |
627 | * 0 for no restriction | |
628 | * 1 for 1/4 us | |
629 | * 2 for 1/2 us | |
630 | * 3 for 1 us | |
631 | * 4 for 2 us | |
632 | * 5 for 4 us | |
633 | * 6 for 8 us | |
634 | * 7 for 16 us | |
635 | */ | |
636 | switch (mpdudensity) { | |
637 | case 0: | |
638 | return 0; | |
639 | case 1: | |
640 | case 2: | |
641 | case 3: | |
642 | /* Our lower layer calculations limit our precision to | |
d6dfe25c MR |
643 | * 1 microsecond |
644 | */ | |
5e3dd157 KV |
645 | return 1; |
646 | case 4: | |
647 | return 2; | |
648 | case 5: | |
649 | return 4; | |
650 | case 6: | |
651 | return 8; | |
652 | case 7: | |
653 | return 16; | |
654 | default: | |
655 | return 0; | |
656 | } | |
657 | } | |
658 | ||
500ff9f9 MK |
659 | int ath10k_mac_vif_chan(struct ieee80211_vif *vif, |
660 | struct cfg80211_chan_def *def) | |
661 | { | |
662 | struct ieee80211_chanctx_conf *conf; | |
663 | ||
664 | rcu_read_lock(); | |
665 | conf = rcu_dereference(vif->chanctx_conf); | |
666 | if (!conf) { | |
667 | rcu_read_unlock(); | |
668 | return -ENOENT; | |
669 | } | |
670 | ||
671 | *def = conf->def; | |
672 | rcu_read_unlock(); | |
673 | ||
674 | return 0; | |
675 | } | |
676 | ||
677 | static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw, | |
678 | struct ieee80211_chanctx_conf *conf, | |
679 | void *data) | |
680 | { | |
681 | int *num = data; | |
682 | ||
683 | (*num)++; | |
684 | } | |
685 | ||
686 | static int ath10k_mac_num_chanctxs(struct ath10k *ar) | |
687 | { | |
688 | int num = 0; | |
689 | ||
690 | ieee80211_iter_chan_contexts_atomic(ar->hw, | |
691 | ath10k_mac_num_chanctxs_iter, | |
692 | &num); | |
693 | ||
694 | return num; | |
695 | } | |
696 | ||
697 | static void | |
698 | ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw, | |
699 | struct ieee80211_chanctx_conf *conf, | |
700 | void *data) | |
701 | { | |
702 | struct cfg80211_chan_def **def = data; | |
703 | ||
704 | *def = &conf->def; | |
705 | } | |
706 | ||
6942726f MK |
707 | static int ath10k_peer_create(struct ath10k *ar, |
708 | struct ieee80211_vif *vif, | |
709 | struct ieee80211_sta *sta, | |
710 | u32 vdev_id, | |
711 | const u8 *addr, | |
7390ed34 | 712 | enum wmi_peer_type peer_type) |
5e3dd157 | 713 | { |
e04cafbc | 714 | struct ath10k_vif *arvif; |
6942726f | 715 | struct ath10k_peer *peer; |
e04cafbc | 716 | int num_peers = 0; |
5e3dd157 KV |
717 | int ret; |
718 | ||
719 | lockdep_assert_held(&ar->conf_mutex); | |
720 | ||
e04cafbc MK |
721 | num_peers = ar->num_peers; |
722 | ||
723 | /* Each vdev consumes a peer entry as well */ | |
724 | list_for_each_entry(arvif, &ar->arvifs, list) | |
725 | num_peers++; | |
726 | ||
727 | if (num_peers >= ar->max_num_peers) | |
cfd1061e MK |
728 | return -ENOBUFS; |
729 | ||
7390ed34 | 730 | ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type); |
479398b0 | 731 | if (ret) { |
7aa7a72a | 732 | ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n", |
69244e56 | 733 | addr, vdev_id, ret); |
5e3dd157 | 734 | return ret; |
479398b0 | 735 | } |
5e3dd157 KV |
736 | |
737 | ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); | |
479398b0 | 738 | if (ret) { |
7aa7a72a | 739 | ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n", |
69244e56 | 740 | addr, vdev_id, ret); |
5e3dd157 | 741 | return ret; |
479398b0 | 742 | } |
292a753d | 743 | |
6942726f MK |
744 | spin_lock_bh(&ar->data_lock); |
745 | ||
746 | peer = ath10k_peer_find(ar, vdev_id, addr); | |
747 | if (!peer) { | |
fee48cf8 | 748 | spin_unlock_bh(&ar->data_lock); |
6942726f MK |
749 | ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n", |
750 | addr, vdev_id); | |
751 | ath10k_wmi_peer_delete(ar, vdev_id, addr); | |
6942726f MK |
752 | return -ENOENT; |
753 | } | |
754 | ||
755 | peer->vif = vif; | |
756 | peer->sta = sta; | |
757 | ||
758 | spin_unlock_bh(&ar->data_lock); | |
759 | ||
0e759f36 | 760 | ar->num_peers++; |
5e3dd157 KV |
761 | |
762 | return 0; | |
763 | } | |
764 | ||
5a13e76e KV |
765 | static int ath10k_mac_set_kickout(struct ath10k_vif *arvif) |
766 | { | |
767 | struct ath10k *ar = arvif->ar; | |
768 | u32 param; | |
769 | int ret; | |
770 | ||
771 | param = ar->wmi.pdev_param->sta_kickout_th; | |
772 | ret = ath10k_wmi_pdev_set_param(ar, param, | |
773 | ATH10K_KICKOUT_THRESHOLD); | |
774 | if (ret) { | |
7aa7a72a | 775 | ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n", |
69244e56 | 776 | arvif->vdev_id, ret); |
5a13e76e KV |
777 | return ret; |
778 | } | |
779 | ||
780 | param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs; | |
781 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, | |
782 | ATH10K_KEEPALIVE_MIN_IDLE); | |
783 | if (ret) { | |
7aa7a72a | 784 | ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n", |
69244e56 | 785 | arvif->vdev_id, ret); |
5a13e76e KV |
786 | return ret; |
787 | } | |
788 | ||
789 | param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs; | |
790 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, | |
791 | ATH10K_KEEPALIVE_MAX_IDLE); | |
792 | if (ret) { | |
7aa7a72a | 793 | ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n", |
69244e56 | 794 | arvif->vdev_id, ret); |
5a13e76e KV |
795 | return ret; |
796 | } | |
797 | ||
798 | param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs; | |
799 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, | |
800 | ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); | |
801 | if (ret) { | |
7aa7a72a | 802 | ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", |
69244e56 | 803 | arvif->vdev_id, ret); |
5a13e76e KV |
804 | return ret; |
805 | } | |
806 | ||
807 | return 0; | |
808 | } | |
809 | ||
acab6400 | 810 | static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value) |
424121c3 | 811 | { |
6d1506e7 BM |
812 | struct ath10k *ar = arvif->ar; |
813 | u32 vdev_param; | |
814 | ||
6d1506e7 BM |
815 | vdev_param = ar->wmi.vdev_param->rts_threshold; |
816 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value); | |
424121c3 MK |
817 | } |
818 | ||
5e3dd157 KV |
819 | static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
820 | { | |
821 | int ret; | |
822 | ||
823 | lockdep_assert_held(&ar->conf_mutex); | |
824 | ||
825 | ret = ath10k_wmi_peer_delete(ar, vdev_id, addr); | |
826 | if (ret) | |
827 | return ret; | |
828 | ||
829 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); | |
830 | if (ret) | |
831 | return ret; | |
832 | ||
0e759f36 | 833 | ar->num_peers--; |
0e759f36 | 834 | |
5e3dd157 KV |
835 | return 0; |
836 | } | |
837 | ||
838 | static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id) | |
839 | { | |
840 | struct ath10k_peer *peer, *tmp; | |
6942726f | 841 | int peer_id; |
6d68f790 | 842 | int i; |
5e3dd157 KV |
843 | |
844 | lockdep_assert_held(&ar->conf_mutex); | |
845 | ||
846 | spin_lock_bh(&ar->data_lock); | |
847 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { | |
848 | if (peer->vdev_id != vdev_id) | |
849 | continue; | |
850 | ||
7aa7a72a | 851 | ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n", |
5e3dd157 KV |
852 | peer->addr, vdev_id); |
853 | ||
6942726f MK |
854 | for_each_set_bit(peer_id, peer->peer_ids, |
855 | ATH10K_MAX_NUM_PEER_IDS) { | |
856 | ar->peer_map[peer_id] = NULL; | |
857 | } | |
858 | ||
6d68f790 BG |
859 | /* Double check that peer is properly un-referenced from |
860 | * the peer_map | |
861 | */ | |
862 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) { | |
863 | if (ar->peer_map[i] == peer) { | |
75b34800 | 864 | ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n", |
6d68f790 BG |
865 | peer->addr, peer, i); |
866 | ar->peer_map[i] = NULL; | |
867 | } | |
868 | } | |
869 | ||
5e3dd157 KV |
870 | list_del(&peer->list); |
871 | kfree(peer); | |
0e759f36 | 872 | ar->num_peers--; |
5e3dd157 KV |
873 | } |
874 | spin_unlock_bh(&ar->data_lock); | |
875 | } | |
876 | ||
a96d7745 MK |
877 | static void ath10k_peer_cleanup_all(struct ath10k *ar) |
878 | { | |
879 | struct ath10k_peer *peer, *tmp; | |
6d68f790 | 880 | int i; |
a96d7745 MK |
881 | |
882 | lockdep_assert_held(&ar->conf_mutex); | |
883 | ||
884 | spin_lock_bh(&ar->data_lock); | |
885 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { | |
886 | list_del(&peer->list); | |
887 | kfree(peer); | |
888 | } | |
6d68f790 BG |
889 | |
890 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) | |
891 | ar->peer_map[i] = NULL; | |
892 | ||
a96d7745 | 893 | spin_unlock_bh(&ar->data_lock); |
292a753d MK |
894 | |
895 | ar->num_peers = 0; | |
cfd1061e | 896 | ar->num_stations = 0; |
a96d7745 MK |
897 | } |
898 | ||
75d85fd9 MP |
899 | static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id, |
900 | struct ieee80211_sta *sta, | |
901 | enum wmi_tdls_peer_state state) | |
902 | { | |
903 | int ret; | |
904 | struct wmi_tdls_peer_update_cmd_arg arg = {}; | |
905 | struct wmi_tdls_peer_capab_arg cap = {}; | |
906 | struct wmi_channel_arg chan_arg = {}; | |
907 | ||
908 | lockdep_assert_held(&ar->conf_mutex); | |
909 | ||
910 | arg.vdev_id = vdev_id; | |
911 | arg.peer_state = state; | |
912 | ether_addr_copy(arg.addr, sta->addr); | |
913 | ||
914 | cap.peer_max_sp = sta->max_sp; | |
915 | cap.peer_uapsd_queues = sta->uapsd_queues; | |
916 | ||
917 | if (state == WMI_TDLS_PEER_STATE_CONNECTED && | |
918 | !sta->tdls_initiator) | |
919 | cap.is_peer_responder = 1; | |
920 | ||
921 | ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg); | |
922 | if (ret) { | |
923 | ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n", | |
924 | arg.addr, vdev_id, ret); | |
925 | return ret; | |
926 | } | |
927 | ||
928 | return 0; | |
929 | } | |
930 | ||
5e3dd157 KV |
931 | /************************/ |
932 | /* Interface management */ | |
933 | /************************/ | |
934 | ||
64badcb6 MK |
935 | void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif) |
936 | { | |
937 | struct ath10k *ar = arvif->ar; | |
938 | ||
939 | lockdep_assert_held(&ar->data_lock); | |
940 | ||
941 | if (!arvif->beacon) | |
942 | return; | |
943 | ||
944 | if (!arvif->beacon_buf) | |
945 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr, | |
946 | arvif->beacon->len, DMA_TO_DEVICE); | |
947 | ||
af21319f MK |
948 | if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED && |
949 | arvif->beacon_state != ATH10K_BEACON_SENT)) | |
950 | return; | |
951 | ||
64badcb6 MK |
952 | dev_kfree_skb_any(arvif->beacon); |
953 | ||
954 | arvif->beacon = NULL; | |
af21319f | 955 | arvif->beacon_state = ATH10K_BEACON_SCHEDULED; |
64badcb6 MK |
956 | } |
957 | ||
958 | static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif) | |
959 | { | |
960 | struct ath10k *ar = arvif->ar; | |
961 | ||
962 | lockdep_assert_held(&ar->data_lock); | |
963 | ||
964 | ath10k_mac_vif_beacon_free(arvif); | |
965 | ||
966 | if (arvif->beacon_buf) { | |
967 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, | |
968 | arvif->beacon_buf, arvif->beacon_paddr); | |
969 | arvif->beacon_buf = NULL; | |
970 | } | |
971 | } | |
972 | ||
5e3dd157 KV |
973 | static inline int ath10k_vdev_setup_sync(struct ath10k *ar) |
974 | { | |
8e9904f5 | 975 | unsigned long time_left; |
5e3dd157 | 976 | |
548db54c MK |
977 | lockdep_assert_held(&ar->conf_mutex); |
978 | ||
7962b0d8 MK |
979 | if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) |
980 | return -ESHUTDOWN; | |
981 | ||
8e9904f5 NMG |
982 | time_left = wait_for_completion_timeout(&ar->vdev_setup_done, |
983 | ATH10K_VDEV_SETUP_TIMEOUT_HZ); | |
984 | if (time_left == 0) | |
5e3dd157 KV |
985 | return -ETIMEDOUT; |
986 | ||
833fd34d | 987 | return ar->last_wmi_vdev_start_status; |
5e3dd157 KV |
988 | } |
989 | ||
1bbc0975 | 990 | static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id) |
5e3dd157 | 991 | { |
500ff9f9 | 992 | struct cfg80211_chan_def *chandef = NULL; |
19be9e9a | 993 | struct ieee80211_channel *channel = NULL; |
5e3dd157 | 994 | struct wmi_vdev_start_request_arg arg = {}; |
5e3dd157 KV |
995 | int ret = 0; |
996 | ||
997 | lockdep_assert_held(&ar->conf_mutex); | |
998 | ||
500ff9f9 MK |
999 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
1000 | ath10k_mac_get_any_chandef_iter, | |
1001 | &chandef); | |
1002 | if (WARN_ON_ONCE(!chandef)) | |
1003 | return -ENOENT; | |
1004 | ||
1005 | channel = chandef->chan; | |
1006 | ||
5e3dd157 KV |
1007 | arg.vdev_id = vdev_id; |
1008 | arg.channel.freq = channel->center_freq; | |
c930f744 | 1009 | arg.channel.band_center_freq1 = chandef->center_freq1; |
bc1efd73 | 1010 | arg.channel.band_center_freq2 = chandef->center_freq2; |
5e3dd157 KV |
1011 | |
1012 | /* TODO setup this dynamically, what in case we | |
d6dfe25c MR |
1013 | * don't have any vifs? |
1014 | */ | |
c930f744 | 1015 | arg.channel.mode = chan_to_phymode(chandef); |
e8a50f8b MP |
1016 | arg.channel.chan_radar = |
1017 | !!(channel->flags & IEEE80211_CHAN_RADAR); | |
5e3dd157 | 1018 | |
89c5c843 | 1019 | arg.channel.min_power = 0; |
02256930 MK |
1020 | arg.channel.max_power = channel->max_power * 2; |
1021 | arg.channel.max_reg_power = channel->max_reg_power * 2; | |
1022 | arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; | |
5e3dd157 | 1023 | |
7962b0d8 MK |
1024 | reinit_completion(&ar->vdev_setup_done); |
1025 | ||
5e3dd157 KV |
1026 | ret = ath10k_wmi_vdev_start(ar, &arg); |
1027 | if (ret) { | |
7aa7a72a | 1028 | ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n", |
69244e56 | 1029 | vdev_id, ret); |
5e3dd157 KV |
1030 | return ret; |
1031 | } | |
1032 | ||
1033 | ret = ath10k_vdev_setup_sync(ar); | |
1034 | if (ret) { | |
60028a81 | 1035 | ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n", |
69244e56 | 1036 | vdev_id, ret); |
5e3dd157 KV |
1037 | return ret; |
1038 | } | |
1039 | ||
1040 | ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); | |
1041 | if (ret) { | |
7aa7a72a | 1042 | ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n", |
69244e56 | 1043 | vdev_id, ret); |
5e3dd157 KV |
1044 | goto vdev_stop; |
1045 | } | |
1046 | ||
1047 | ar->monitor_vdev_id = vdev_id; | |
5e3dd157 | 1048 | |
7aa7a72a | 1049 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n", |
1bbc0975 | 1050 | ar->monitor_vdev_id); |
5e3dd157 KV |
1051 | return 0; |
1052 | ||
1053 | vdev_stop: | |
1054 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); | |
1055 | if (ret) | |
7aa7a72a | 1056 | ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n", |
69244e56 | 1057 | ar->monitor_vdev_id, ret); |
5e3dd157 KV |
1058 | |
1059 | return ret; | |
1060 | } | |
1061 | ||
1bbc0975 | 1062 | static int ath10k_monitor_vdev_stop(struct ath10k *ar) |
5e3dd157 KV |
1063 | { |
1064 | int ret = 0; | |
1065 | ||
1066 | lockdep_assert_held(&ar->conf_mutex); | |
1067 | ||
52fa0191 MP |
1068 | ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
1069 | if (ret) | |
7aa7a72a | 1070 | ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n", |
69244e56 | 1071 | ar->monitor_vdev_id, ret); |
5e3dd157 | 1072 | |
7962b0d8 MK |
1073 | reinit_completion(&ar->vdev_setup_done); |
1074 | ||
5e3dd157 KV |
1075 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
1076 | if (ret) | |
7aa7a72a | 1077 | ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n", |
69244e56 | 1078 | ar->monitor_vdev_id, ret); |
5e3dd157 KV |
1079 | |
1080 | ret = ath10k_vdev_setup_sync(ar); | |
1081 | if (ret) | |
60028a81 | 1082 | ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n", |
69244e56 | 1083 | ar->monitor_vdev_id, ret); |
5e3dd157 | 1084 | |
7aa7a72a | 1085 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n", |
1bbc0975 | 1086 | ar->monitor_vdev_id); |
5e3dd157 KV |
1087 | return ret; |
1088 | } | |
1089 | ||
1bbc0975 | 1090 | static int ath10k_monitor_vdev_create(struct ath10k *ar) |
5e3dd157 KV |
1091 | { |
1092 | int bit, ret = 0; | |
1093 | ||
1094 | lockdep_assert_held(&ar->conf_mutex); | |
1095 | ||
a9aefb3b | 1096 | if (ar->free_vdev_map == 0) { |
7aa7a72a | 1097 | ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n"); |
5e3dd157 KV |
1098 | return -ENOMEM; |
1099 | } | |
1100 | ||
16c11176 | 1101 | bit = __ffs64(ar->free_vdev_map); |
a9aefb3b | 1102 | |
16c11176 | 1103 | ar->monitor_vdev_id = bit; |
5e3dd157 KV |
1104 | |
1105 | ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, | |
1106 | WMI_VDEV_TYPE_MONITOR, | |
1107 | 0, ar->mac_addr); | |
1108 | if (ret) { | |
7aa7a72a | 1109 | ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n", |
69244e56 | 1110 | ar->monitor_vdev_id, ret); |
a9aefb3b | 1111 | return ret; |
5e3dd157 KV |
1112 | } |
1113 | ||
16c11176 | 1114 | ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); |
7aa7a72a | 1115 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n", |
5e3dd157 KV |
1116 | ar->monitor_vdev_id); |
1117 | ||
5e3dd157 | 1118 | return 0; |
5e3dd157 KV |
1119 | } |
1120 | ||
1bbc0975 | 1121 | static int ath10k_monitor_vdev_delete(struct ath10k *ar) |
5e3dd157 KV |
1122 | { |
1123 | int ret = 0; | |
1124 | ||
1125 | lockdep_assert_held(&ar->conf_mutex); | |
1126 | ||
5e3dd157 KV |
1127 | ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
1128 | if (ret) { | |
7aa7a72a | 1129 | ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n", |
69244e56 | 1130 | ar->monitor_vdev_id, ret); |
5e3dd157 KV |
1131 | return ret; |
1132 | } | |
1133 | ||
16c11176 | 1134 | ar->free_vdev_map |= 1LL << ar->monitor_vdev_id; |
5e3dd157 | 1135 | |
7aa7a72a | 1136 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", |
5e3dd157 KV |
1137 | ar->monitor_vdev_id); |
1138 | return ret; | |
1139 | } | |
1140 | ||
1bbc0975 MK |
1141 | static int ath10k_monitor_start(struct ath10k *ar) |
1142 | { | |
1143 | int ret; | |
1144 | ||
1145 | lockdep_assert_held(&ar->conf_mutex); | |
1146 | ||
1bbc0975 MK |
1147 | ret = ath10k_monitor_vdev_create(ar); |
1148 | if (ret) { | |
7aa7a72a | 1149 | ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret); |
1bbc0975 MK |
1150 | return ret; |
1151 | } | |
1152 | ||
1153 | ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id); | |
1154 | if (ret) { | |
7aa7a72a | 1155 | ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret); |
1bbc0975 MK |
1156 | ath10k_monitor_vdev_delete(ar); |
1157 | return ret; | |
1158 | } | |
1159 | ||
1160 | ar->monitor_started = true; | |
7aa7a72a | 1161 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n"); |
1bbc0975 MK |
1162 | |
1163 | return 0; | |
1164 | } | |
1165 | ||
1933747f | 1166 | static int ath10k_monitor_stop(struct ath10k *ar) |
1bbc0975 MK |
1167 | { |
1168 | int ret; | |
1169 | ||
1170 | lockdep_assert_held(&ar->conf_mutex); | |
1171 | ||
1bbc0975 | 1172 | ret = ath10k_monitor_vdev_stop(ar); |
1933747f | 1173 | if (ret) { |
7aa7a72a | 1174 | ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret); |
1933747f MK |
1175 | return ret; |
1176 | } | |
1bbc0975 MK |
1177 | |
1178 | ret = ath10k_monitor_vdev_delete(ar); | |
1933747f | 1179 | if (ret) { |
7aa7a72a | 1180 | ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret); |
1933747f MK |
1181 | return ret; |
1182 | } | |
1bbc0975 MK |
1183 | |
1184 | ar->monitor_started = false; | |
7aa7a72a | 1185 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n"); |
1933747f MK |
1186 | |
1187 | return 0; | |
1188 | } | |
1189 | ||
500ff9f9 MK |
1190 | static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar) |
1191 | { | |
1192 | int num_ctx; | |
1193 | ||
1194 | /* At least one chanctx is required to derive a channel to start | |
1195 | * monitor vdev on. | |
1196 | */ | |
1197 | num_ctx = ath10k_mac_num_chanctxs(ar); | |
1198 | if (num_ctx == 0) | |
1199 | return false; | |
1200 | ||
1201 | /* If there's already an existing special monitor interface then don't | |
1202 | * bother creating another monitor vdev. | |
1203 | */ | |
1204 | if (ar->monitor_arvif) | |
1205 | return false; | |
1206 | ||
1207 | return ar->monitor || | |
705d7aa0 MR |
1208 | (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST, |
1209 | ar->running_fw->fw_file.fw_features) && | |
1210 | (ar->filter_flags & FIF_OTHER_BSS)) || | |
500ff9f9 MK |
1211 | test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
1212 | } | |
1213 | ||
1214 | static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar) | |
1215 | { | |
1216 | int num_ctx; | |
1217 | ||
1218 | num_ctx = ath10k_mac_num_chanctxs(ar); | |
1219 | ||
1220 | /* FIXME: Current interface combinations and cfg80211/mac80211 code | |
1221 | * shouldn't allow this but make sure to prevent handling the following | |
1222 | * case anyway since multi-channel DFS hasn't been tested at all. | |
1223 | */ | |
1224 | if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1) | |
1225 | return false; | |
1226 | ||
1227 | return true; | |
1228 | } | |
1229 | ||
1933747f MK |
1230 | static int ath10k_monitor_recalc(struct ath10k *ar) |
1231 | { | |
500ff9f9 MK |
1232 | bool needed; |
1233 | bool allowed; | |
1234 | int ret; | |
1933747f MK |
1235 | |
1236 | lockdep_assert_held(&ar->conf_mutex); | |
1237 | ||
500ff9f9 MK |
1238 | needed = ath10k_mac_monitor_vdev_is_needed(ar); |
1239 | allowed = ath10k_mac_monitor_vdev_is_allowed(ar); | |
1933747f MK |
1240 | |
1241 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
500ff9f9 MK |
1242 | "mac monitor recalc started? %d needed? %d allowed? %d\n", |
1243 | ar->monitor_started, needed, allowed); | |
1933747f | 1244 | |
500ff9f9 MK |
1245 | if (WARN_ON(needed && !allowed)) { |
1246 | if (ar->monitor_started) { | |
1247 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n"); | |
1248 | ||
1249 | ret = ath10k_monitor_stop(ar); | |
1250 | if (ret) | |
2a995088 KV |
1251 | ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", |
1252 | ret); | |
500ff9f9 MK |
1253 | /* not serious */ |
1254 | } | |
1933747f | 1255 | |
500ff9f9 MK |
1256 | return -EPERM; |
1257 | } | |
1933747f | 1258 | |
500ff9f9 | 1259 | if (needed == ar->monitor_started) |
1933747f MK |
1260 | return 0; |
1261 | ||
500ff9f9 | 1262 | if (needed) |
1933747f | 1263 | return ath10k_monitor_start(ar); |
500ff9f9 MK |
1264 | else |
1265 | return ath10k_monitor_stop(ar); | |
1bbc0975 MK |
1266 | } |
1267 | ||
7cfe0455 BM |
1268 | static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif) |
1269 | { | |
1270 | struct ath10k *ar = arvif->ar; | |
1271 | ||
1272 | lockdep_assert_held(&ar->conf_mutex); | |
1273 | ||
1274 | if (!arvif->is_started) { | |
1275 | ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n"); | |
1276 | return false; | |
1277 | } | |
1278 | ||
1279 | return true; | |
1280 | } | |
1281 | ||
1282 | static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif) | |
1283 | { | |
1284 | struct ath10k *ar = arvif->ar; | |
1285 | u32 vdev_param; | |
1286 | ||
1287 | lockdep_assert_held(&ar->conf_mutex); | |
1288 | ||
1289 | vdev_param = ar->wmi.vdev_param->protection_mode; | |
1290 | ||
1291 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n", | |
1292 | arvif->vdev_id, arvif->use_cts_prot); | |
1293 | ||
1294 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
1295 | arvif->use_cts_prot ? 1 : 0); | |
1296 | } | |
1297 | ||
e81bd104 MK |
1298 | static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif) |
1299 | { | |
1300 | struct ath10k *ar = arvif->ar; | |
1301 | u32 vdev_param, rts_cts = 0; | |
1302 | ||
1303 | lockdep_assert_held(&ar->conf_mutex); | |
1304 | ||
1305 | vdev_param = ar->wmi.vdev_param->enable_rtscts; | |
1306 | ||
9a5ab0f4 | 1307 | rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET); |
e81bd104 MK |
1308 | |
1309 | if (arvif->num_legacy_stations > 0) | |
1310 | rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES, | |
1311 | WMI_RTSCTS_PROFILE); | |
9a5ab0f4 RM |
1312 | else |
1313 | rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES, | |
1314 | WMI_RTSCTS_PROFILE); | |
e81bd104 | 1315 | |
86176901 BM |
1316 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", |
1317 | arvif->vdev_id, rts_cts); | |
1318 | ||
e81bd104 MK |
1319 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
1320 | rts_cts); | |
1321 | } | |
1322 | ||
e8a50f8b MP |
1323 | static int ath10k_start_cac(struct ath10k *ar) |
1324 | { | |
1325 | int ret; | |
1326 | ||
1327 | lockdep_assert_held(&ar->conf_mutex); | |
1328 | ||
1329 | set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); | |
1330 | ||
1933747f | 1331 | ret = ath10k_monitor_recalc(ar); |
e8a50f8b | 1332 | if (ret) { |
7aa7a72a | 1333 | ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret); |
e8a50f8b MP |
1334 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
1335 | return ret; | |
1336 | } | |
1337 | ||
7aa7a72a | 1338 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n", |
e8a50f8b MP |
1339 | ar->monitor_vdev_id); |
1340 | ||
1341 | return 0; | |
1342 | } | |
1343 | ||
1344 | static int ath10k_stop_cac(struct ath10k *ar) | |
1345 | { | |
1346 | lockdep_assert_held(&ar->conf_mutex); | |
1347 | ||
1348 | /* CAC is not running - do nothing */ | |
1349 | if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) | |
1350 | return 0; | |
1351 | ||
e8a50f8b | 1352 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
1bbc0975 | 1353 | ath10k_monitor_stop(ar); |
e8a50f8b | 1354 | |
7aa7a72a | 1355 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n"); |
e8a50f8b MP |
1356 | |
1357 | return 0; | |
1358 | } | |
1359 | ||
500ff9f9 MK |
1360 | static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw, |
1361 | struct ieee80211_chanctx_conf *conf, | |
1362 | void *data) | |
1363 | { | |
1364 | bool *ret = data; | |
1365 | ||
1366 | if (!*ret && conf->radar_enabled) | |
1367 | *ret = true; | |
1368 | } | |
1369 | ||
1370 | static bool ath10k_mac_has_radar_enabled(struct ath10k *ar) | |
1371 | { | |
1372 | bool has_radar = false; | |
1373 | ||
1374 | ieee80211_iter_chan_contexts_atomic(ar->hw, | |
1375 | ath10k_mac_has_radar_iter, | |
1376 | &has_radar); | |
1377 | ||
1378 | return has_radar; | |
1379 | } | |
1380 | ||
d650097b | 1381 | static void ath10k_recalc_radar_detection(struct ath10k *ar) |
e8a50f8b | 1382 | { |
e8a50f8b MP |
1383 | int ret; |
1384 | ||
1385 | lockdep_assert_held(&ar->conf_mutex); | |
1386 | ||
e8a50f8b MP |
1387 | ath10k_stop_cac(ar); |
1388 | ||
500ff9f9 | 1389 | if (!ath10k_mac_has_radar_enabled(ar)) |
e8a50f8b MP |
1390 | return; |
1391 | ||
d650097b | 1392 | if (ar->num_started_vdevs > 0) |
e8a50f8b MP |
1393 | return; |
1394 | ||
1395 | ret = ath10k_start_cac(ar); | |
1396 | if (ret) { | |
1397 | /* | |
1398 | * Not possible to start CAC on current channel so starting | |
1399 | * radiation is not allowed, make this channel DFS_UNAVAILABLE | |
1400 | * by indicating that radar was detected. | |
1401 | */ | |
7aa7a72a | 1402 | ath10k_warn(ar, "failed to start CAC: %d\n", ret); |
e8a50f8b MP |
1403 | ieee80211_radar_detected(ar->hw); |
1404 | } | |
1405 | } | |
1406 | ||
822b7e0b VT |
1407 | static int ath10k_vdev_stop(struct ath10k_vif *arvif) |
1408 | { | |
1409 | struct ath10k *ar = arvif->ar; | |
1410 | int ret; | |
1411 | ||
1412 | lockdep_assert_held(&ar->conf_mutex); | |
1413 | ||
1414 | reinit_completion(&ar->vdev_setup_done); | |
1415 | ||
1416 | ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); | |
1417 | if (ret) { | |
1418 | ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n", | |
1419 | arvif->vdev_id, ret); | |
1420 | return ret; | |
1421 | } | |
1422 | ||
1423 | ret = ath10k_vdev_setup_sync(ar); | |
1424 | if (ret) { | |
23de5797 | 1425 | ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n", |
822b7e0b VT |
1426 | arvif->vdev_id, ret); |
1427 | return ret; | |
1428 | } | |
1429 | ||
1430 | WARN_ON(ar->num_started_vdevs == 0); | |
1431 | ||
1432 | if (ar->num_started_vdevs != 0) { | |
1433 | ar->num_started_vdevs--; | |
1434 | ath10k_recalc_radar_detection(ar); | |
1435 | } | |
1436 | ||
1437 | return ret; | |
1438 | } | |
1439 | ||
500ff9f9 MK |
1440 | static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, |
1441 | const struct cfg80211_chan_def *chandef, | |
1442 | bool restart) | |
72654fa7 MK |
1443 | { |
1444 | struct ath10k *ar = arvif->ar; | |
72654fa7 MK |
1445 | struct wmi_vdev_start_request_arg arg = {}; |
1446 | int ret = 0; | |
1447 | ||
1448 | lockdep_assert_held(&ar->conf_mutex); | |
1449 | ||
1450 | reinit_completion(&ar->vdev_setup_done); | |
1451 | ||
1452 | arg.vdev_id = arvif->vdev_id; | |
1453 | arg.dtim_period = arvif->dtim_period; | |
1454 | arg.bcn_intval = arvif->beacon_interval; | |
1455 | ||
1456 | arg.channel.freq = chandef->chan->center_freq; | |
1457 | arg.channel.band_center_freq1 = chandef->center_freq1; | |
bc1efd73 | 1458 | arg.channel.band_center_freq2 = chandef->center_freq2; |
72654fa7 MK |
1459 | arg.channel.mode = chan_to_phymode(chandef); |
1460 | ||
1461 | arg.channel.min_power = 0; | |
1462 | arg.channel.max_power = chandef->chan->max_power * 2; | |
1463 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; | |
1464 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; | |
1465 | ||
1466 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
1467 | arg.ssid = arvif->u.ap.ssid; | |
1468 | arg.ssid_len = arvif->u.ap.ssid_len; | |
1469 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; | |
1470 | ||
1471 | /* For now allow DFS for AP mode */ | |
1472 | arg.channel.chan_radar = | |
1473 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); | |
1474 | } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { | |
1475 | arg.ssid = arvif->vif->bss_conf.ssid; | |
1476 | arg.ssid_len = arvif->vif->bss_conf.ssid_len; | |
1477 | } | |
1478 | ||
7aa7a72a | 1479 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
72654fa7 MK |
1480 | "mac vdev %d start center_freq %d phymode %s\n", |
1481 | arg.vdev_id, arg.channel.freq, | |
1482 | ath10k_wmi_phymode_str(arg.channel.mode)); | |
1483 | ||
dc55e307 MK |
1484 | if (restart) |
1485 | ret = ath10k_wmi_vdev_restart(ar, &arg); | |
1486 | else | |
1487 | ret = ath10k_wmi_vdev_start(ar, &arg); | |
1488 | ||
72654fa7 | 1489 | if (ret) { |
7aa7a72a | 1490 | ath10k_warn(ar, "failed to start WMI vdev %i: %d\n", |
72654fa7 MK |
1491 | arg.vdev_id, ret); |
1492 | return ret; | |
1493 | } | |
1494 | ||
1495 | ret = ath10k_vdev_setup_sync(ar); | |
1496 | if (ret) { | |
60028a81 BG |
1497 | ath10k_warn(ar, |
1498 | "failed to synchronize setup for vdev %i restart %d: %d\n", | |
1499 | arg.vdev_id, restart, ret); | |
72654fa7 MK |
1500 | return ret; |
1501 | } | |
1502 | ||
d650097b MK |
1503 | ar->num_started_vdevs++; |
1504 | ath10k_recalc_radar_detection(ar); | |
1505 | ||
72654fa7 MK |
1506 | return ret; |
1507 | } | |
1508 | ||
500ff9f9 MK |
1509 | static int ath10k_vdev_start(struct ath10k_vif *arvif, |
1510 | const struct cfg80211_chan_def *def) | |
dc55e307 | 1511 | { |
500ff9f9 | 1512 | return ath10k_vdev_start_restart(arvif, def, false); |
dc55e307 MK |
1513 | } |
1514 | ||
500ff9f9 MK |
1515 | static int ath10k_vdev_restart(struct ath10k_vif *arvif, |
1516 | const struct cfg80211_chan_def *def) | |
72654fa7 | 1517 | { |
500ff9f9 | 1518 | return ath10k_vdev_start_restart(arvif, def, true); |
72654fa7 MK |
1519 | } |
1520 | ||
fbb8f1b7 MK |
1521 | static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif, |
1522 | struct sk_buff *bcn) | |
1523 | { | |
1524 | struct ath10k *ar = arvif->ar; | |
1525 | struct ieee80211_mgmt *mgmt; | |
1526 | const u8 *p2p_ie; | |
1527 | int ret; | |
1528 | ||
08c27be1 | 1529 | if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p) |
fbb8f1b7 MK |
1530 | return 0; |
1531 | ||
1532 | mgmt = (void *)bcn->data; | |
1533 | p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, | |
1534 | mgmt->u.beacon.variable, | |
1535 | bcn->len - (mgmt->u.beacon.variable - | |
1536 | bcn->data)); | |
1537 | if (!p2p_ie) | |
1538 | return -ENOENT; | |
1539 | ||
1540 | ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); | |
1541 | if (ret) { | |
1542 | ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n", | |
1543 | arvif->vdev_id, ret); | |
1544 | return ret; | |
1545 | } | |
1546 | ||
1547 | return 0; | |
1548 | } | |
1549 | ||
1550 | static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, | |
1551 | u8 oui_type, size_t ie_offset) | |
1552 | { | |
1553 | size_t len; | |
1554 | const u8 *next; | |
1555 | const u8 *end; | |
1556 | u8 *ie; | |
1557 | ||
1558 | if (WARN_ON(skb->len < ie_offset)) | |
1559 | return -EINVAL; | |
1560 | ||
1561 | ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, | |
1562 | skb->data + ie_offset, | |
1563 | skb->len - ie_offset); | |
1564 | if (!ie) | |
1565 | return -ENOENT; | |
1566 | ||
1567 | len = ie[1] + 2; | |
1568 | end = skb->data + skb->len; | |
1569 | next = ie + len; | |
1570 | ||
1571 | if (WARN_ON(next > end)) | |
1572 | return -EINVAL; | |
1573 | ||
1574 | memmove(ie, next, end - next); | |
1575 | skb_trim(skb, skb->len - len); | |
1576 | ||
1577 | return 0; | |
1578 | } | |
1579 | ||
1580 | static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif) | |
1581 | { | |
1582 | struct ath10k *ar = arvif->ar; | |
1583 | struct ieee80211_hw *hw = ar->hw; | |
1584 | struct ieee80211_vif *vif = arvif->vif; | |
1585 | struct ieee80211_mutable_offsets offs = {}; | |
1586 | struct sk_buff *bcn; | |
1587 | int ret; | |
1588 | ||
1589 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) | |
1590 | return 0; | |
1591 | ||
81a9a17d MK |
1592 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
1593 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) | |
1594 | return 0; | |
1595 | ||
fbb8f1b7 MK |
1596 | bcn = ieee80211_beacon_get_template(hw, vif, &offs); |
1597 | if (!bcn) { | |
1598 | ath10k_warn(ar, "failed to get beacon template from mac80211\n"); | |
1599 | return -EPERM; | |
1600 | } | |
1601 | ||
1602 | ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn); | |
1603 | if (ret) { | |
1604 | ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret); | |
1605 | kfree_skb(bcn); | |
1606 | return ret; | |
1607 | } | |
1608 | ||
1609 | /* P2P IE is inserted by firmware automatically (as configured above) | |
1610 | * so remove it from the base beacon template to avoid duplicate P2P | |
1611 | * IEs in beacon frames. | |
1612 | */ | |
1613 | ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, | |
1614 | offsetof(struct ieee80211_mgmt, | |
1615 | u.beacon.variable)); | |
1616 | ||
1617 | ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0, | |
1618 | 0, NULL, 0); | |
1619 | kfree_skb(bcn); | |
1620 | ||
1621 | if (ret) { | |
1622 | ath10k_warn(ar, "failed to submit beacon template command: %d\n", | |
1623 | ret); | |
1624 | return ret; | |
1625 | } | |
1626 | ||
1627 | return 0; | |
1628 | } | |
1629 | ||
1630 | static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif) | |
1631 | { | |
1632 | struct ath10k *ar = arvif->ar; | |
1633 | struct ieee80211_hw *hw = ar->hw; | |
1634 | struct ieee80211_vif *vif = arvif->vif; | |
1635 | struct sk_buff *prb; | |
1636 | int ret; | |
1637 | ||
1638 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) | |
1639 | return 0; | |
1640 | ||
81a9a17d MK |
1641 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
1642 | return 0; | |
1643 | ||
fbb8f1b7 MK |
1644 | prb = ieee80211_proberesp_get(hw, vif); |
1645 | if (!prb) { | |
1646 | ath10k_warn(ar, "failed to get probe resp template from mac80211\n"); | |
1647 | return -EPERM; | |
1648 | } | |
1649 | ||
1650 | ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb); | |
1651 | kfree_skb(prb); | |
1652 | ||
1653 | if (ret) { | |
1654 | ath10k_warn(ar, "failed to submit probe resp template command: %d\n", | |
1655 | ret); | |
1656 | return ret; | |
1657 | } | |
1658 | ||
1659 | return 0; | |
1660 | } | |
1661 | ||
500ff9f9 MK |
1662 | static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif) |
1663 | { | |
1664 | struct ath10k *ar = arvif->ar; | |
1665 | struct cfg80211_chan_def def; | |
1666 | int ret; | |
1667 | ||
1668 | /* When originally vdev is started during assign_vif_chanctx() some | |
1669 | * information is missing, notably SSID. Firmware revisions with beacon | |
1670 | * offloading require the SSID to be provided during vdev (re)start to | |
1671 | * handle hidden SSID properly. | |
1672 | * | |
1673 | * Vdev restart must be done after vdev has been both started and | |
1674 | * upped. Otherwise some firmware revisions (at least 10.2) fail to | |
1675 | * deliver vdev restart response event causing timeouts during vdev | |
1676 | * syncing in ath10k. | |
1677 | * | |
1678 | * Note: The vdev down/up and template reinstallation could be skipped | |
1679 | * since only wmi-tlv firmware are known to have beacon offload and | |
1680 | * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart | |
1681 | * response delivery. It's probably more robust to keep it as is. | |
1682 | */ | |
1683 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) | |
1684 | return 0; | |
1685 | ||
1686 | if (WARN_ON(!arvif->is_started)) | |
1687 | return -EINVAL; | |
1688 | ||
1689 | if (WARN_ON(!arvif->is_up)) | |
1690 | return -EINVAL; | |
1691 | ||
1692 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) | |
1693 | return -EINVAL; | |
1694 | ||
1695 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); | |
1696 | if (ret) { | |
1697 | ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n", | |
1698 | arvif->vdev_id, ret); | |
1699 | return ret; | |
1700 | } | |
1701 | ||
1702 | /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise | |
1703 | * firmware will crash upon vdev up. | |
1704 | */ | |
1705 | ||
1706 | ret = ath10k_mac_setup_bcn_tmpl(arvif); | |
1707 | if (ret) { | |
1708 | ath10k_warn(ar, "failed to update beacon template: %d\n", ret); | |
1709 | return ret; | |
1710 | } | |
1711 | ||
1712 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
1713 | if (ret) { | |
1714 | ath10k_warn(ar, "failed to update presp template: %d\n", ret); | |
1715 | return ret; | |
1716 | } | |
1717 | ||
1718 | ret = ath10k_vdev_restart(arvif, &def); | |
1719 | if (ret) { | |
1720 | ath10k_warn(ar, "failed to restart ap vdev %i: %d\n", | |
1721 | arvif->vdev_id, ret); | |
1722 | return ret; | |
1723 | } | |
1724 | ||
1725 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
1726 | arvif->bssid); | |
1727 | if (ret) { | |
1728 | ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n", | |
1729 | arvif->vdev_id, ret); | |
1730 | return ret; | |
1731 | } | |
1732 | ||
1733 | return 0; | |
1734 | } | |
1735 | ||
5e3dd157 | 1736 | static void ath10k_control_beaconing(struct ath10k_vif *arvif, |
5b07e07f | 1737 | struct ieee80211_bss_conf *info) |
5e3dd157 | 1738 | { |
7aa7a72a | 1739 | struct ath10k *ar = arvif->ar; |
5e3dd157 KV |
1740 | int ret = 0; |
1741 | ||
548db54c MK |
1742 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1743 | ||
5e3dd157 | 1744 | if (!info->enable_beacon) { |
500ff9f9 MK |
1745 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
1746 | if (ret) | |
1747 | ath10k_warn(ar, "failed to down vdev_id %i: %d\n", | |
1748 | arvif->vdev_id, ret); | |
c930f744 | 1749 | |
c930f744 MK |
1750 | arvif->is_up = false; |
1751 | ||
748afc47 | 1752 | spin_lock_bh(&arvif->ar->data_lock); |
64badcb6 | 1753 | ath10k_mac_vif_beacon_free(arvif); |
748afc47 MK |
1754 | spin_unlock_bh(&arvif->ar->data_lock); |
1755 | ||
5e3dd157 KV |
1756 | return; |
1757 | } | |
1758 | ||
1759 | arvif->tx_seq_no = 0x1000; | |
1760 | ||
c930f744 | 1761 | arvif->aid = 0; |
b25f32cb | 1762 | ether_addr_copy(arvif->bssid, info->bssid); |
c930f744 MK |
1763 | |
1764 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
1765 | arvif->bssid); | |
5e3dd157 | 1766 | if (ret) { |
7aa7a72a | 1767 | ath10k_warn(ar, "failed to bring up vdev %d: %i\n", |
69244e56 | 1768 | arvif->vdev_id, ret); |
5e3dd157 KV |
1769 | return; |
1770 | } | |
c930f744 | 1771 | |
c930f744 MK |
1772 | arvif->is_up = true; |
1773 | ||
500ff9f9 MK |
1774 | ret = ath10k_mac_vif_fix_hidden_ssid(arvif); |
1775 | if (ret) { | |
1776 | ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n", | |
1777 | arvif->vdev_id, ret); | |
1778 | return; | |
1779 | } | |
1780 | ||
7aa7a72a | 1781 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); |
5e3dd157 KV |
1782 | } |
1783 | ||
1784 | static void ath10k_control_ibss(struct ath10k_vif *arvif, | |
1785 | struct ieee80211_bss_conf *info, | |
1786 | const u8 self_peer[ETH_ALEN]) | |
1787 | { | |
7aa7a72a | 1788 | struct ath10k *ar = arvif->ar; |
6d1506e7 | 1789 | u32 vdev_param; |
5e3dd157 KV |
1790 | int ret = 0; |
1791 | ||
548db54c MK |
1792 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1793 | ||
5e3dd157 | 1794 | if (!info->ibss_joined) { |
c930f744 | 1795 | if (is_zero_ether_addr(arvif->bssid)) |
5e3dd157 KV |
1796 | return; |
1797 | ||
93803b33 | 1798 | eth_zero_addr(arvif->bssid); |
5e3dd157 KV |
1799 | |
1800 | return; | |
1801 | } | |
1802 | ||
6d1506e7 BM |
1803 | vdev_param = arvif->ar->wmi.vdev_param->atim_window; |
1804 | ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
1805 | ATH10K_DEFAULT_ATIM); |
1806 | if (ret) | |
7aa7a72a | 1807 | ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n", |
5e3dd157 KV |
1808 | arvif->vdev_id, ret); |
1809 | } | |
1810 | ||
9f9b5746 MK |
1811 | static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif) |
1812 | { | |
1813 | struct ath10k *ar = arvif->ar; | |
1814 | u32 param; | |
1815 | u32 value; | |
1816 | int ret; | |
1817 | ||
1818 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1819 | ||
1820 | if (arvif->u.sta.uapsd) | |
1821 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER; | |
1822 | else | |
1823 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; | |
1824 | ||
1825 | param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; | |
1826 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value); | |
1827 | if (ret) { | |
1828 | ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n", | |
1829 | value, arvif->vdev_id, ret); | |
1830 | return ret; | |
1831 | } | |
1832 | ||
1833 | return 0; | |
1834 | } | |
1835 | ||
1836 | static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif) | |
1837 | { | |
1838 | struct ath10k *ar = arvif->ar; | |
1839 | u32 param; | |
1840 | u32 value; | |
1841 | int ret; | |
1842 | ||
1843 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1844 | ||
1845 | if (arvif->u.sta.uapsd) | |
1846 | value = WMI_STA_PS_PSPOLL_COUNT_UAPSD; | |
1847 | else | |
1848 | value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; | |
1849 | ||
1850 | param = WMI_STA_PS_PARAM_PSPOLL_COUNT; | |
1851 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
1852 | param, value); | |
1853 | if (ret) { | |
1854 | ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n", | |
1855 | value, arvif->vdev_id, ret); | |
1856 | return ret; | |
1857 | } | |
1858 | ||
1859 | return 0; | |
1860 | } | |
1861 | ||
424f2630 | 1862 | static int ath10k_mac_num_vifs_started(struct ath10k *ar) |
cffb41f3 MK |
1863 | { |
1864 | struct ath10k_vif *arvif; | |
1865 | int num = 0; | |
1866 | ||
1867 | lockdep_assert_held(&ar->conf_mutex); | |
1868 | ||
1869 | list_for_each_entry(arvif, &ar->arvifs, list) | |
424f2630 | 1870 | if (arvif->is_started) |
cffb41f3 MK |
1871 | num++; |
1872 | ||
1873 | return num; | |
1874 | } | |
1875 | ||
ad088bfa | 1876 | static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif) |
5e3dd157 | 1877 | { |
ad088bfa | 1878 | struct ath10k *ar = arvif->ar; |
526549a8 | 1879 | struct ieee80211_vif *vif = arvif->vif; |
ad088bfa | 1880 | struct ieee80211_conf *conf = &ar->hw->conf; |
5e3dd157 KV |
1881 | enum wmi_sta_powersave_param param; |
1882 | enum wmi_sta_ps_mode psmode; | |
1883 | int ret; | |
526549a8 | 1884 | int ps_timeout; |
cffb41f3 | 1885 | bool enable_ps; |
5e3dd157 | 1886 | |
548db54c MK |
1887 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1888 | ||
ad088bfa MK |
1889 | if (arvif->vif->type != NL80211_IFTYPE_STATION) |
1890 | return 0; | |
5e3dd157 | 1891 | |
cffb41f3 MK |
1892 | enable_ps = arvif->ps; |
1893 | ||
424f2630 | 1894 | if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 && |
cffb41f3 | 1895 | !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT, |
c4cdf753 | 1896 | ar->running_fw->fw_file.fw_features)) { |
cffb41f3 MK |
1897 | ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n", |
1898 | arvif->vdev_id); | |
1899 | enable_ps = false; | |
1900 | } | |
1901 | ||
917826be JD |
1902 | if (!arvif->is_started) { |
1903 | /* mac80211 can update vif powersave state while disconnected. | |
1904 | * Firmware doesn't behave nicely and consumes more power than | |
1905 | * necessary if PS is disabled on a non-started vdev. Hence | |
1906 | * force-enable PS for non-running vdevs. | |
1907 | */ | |
1908 | psmode = WMI_STA_PS_MODE_ENABLED; | |
1909 | } else if (enable_ps) { | |
5e3dd157 KV |
1910 | psmode = WMI_STA_PS_MODE_ENABLED; |
1911 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; | |
1912 | ||
526549a8 MK |
1913 | ps_timeout = conf->dynamic_ps_timeout; |
1914 | if (ps_timeout == 0) { | |
1915 | /* Firmware doesn't like 0 */ | |
1916 | ps_timeout = ieee80211_tu_to_usec( | |
1917 | vif->bss_conf.beacon_int) / 1000; | |
1918 | } | |
1919 | ||
ad088bfa | 1920 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
526549a8 | 1921 | ps_timeout); |
5e3dd157 | 1922 | if (ret) { |
7aa7a72a | 1923 | ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n", |
69244e56 | 1924 | arvif->vdev_id, ret); |
ad088bfa | 1925 | return ret; |
5e3dd157 | 1926 | } |
5e3dd157 KV |
1927 | } else { |
1928 | psmode = WMI_STA_PS_MODE_DISABLED; | |
1929 | } | |
1930 | ||
7aa7a72a | 1931 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n", |
60c3daa8 KV |
1932 | arvif->vdev_id, psmode ? "enable" : "disable"); |
1933 | ||
ad088bfa MK |
1934 | ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode); |
1935 | if (ret) { | |
7aa7a72a | 1936 | ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n", |
be6546fc | 1937 | psmode, arvif->vdev_id, ret); |
ad088bfa MK |
1938 | return ret; |
1939 | } | |
1940 | ||
1941 | return 0; | |
5e3dd157 KV |
1942 | } |
1943 | ||
46725b15 MK |
1944 | static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif) |
1945 | { | |
1946 | struct ath10k *ar = arvif->ar; | |
1947 | struct wmi_sta_keepalive_arg arg = {}; | |
1948 | int ret; | |
1949 | ||
1950 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1951 | ||
1952 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) | |
1953 | return 0; | |
1954 | ||
1955 | if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map)) | |
1956 | return 0; | |
1957 | ||
1958 | /* Some firmware revisions have a bug and ignore the `enabled` field. | |
1959 | * Instead use the interval to disable the keepalive. | |
1960 | */ | |
1961 | arg.vdev_id = arvif->vdev_id; | |
1962 | arg.enabled = 1; | |
1963 | arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME; | |
1964 | arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE; | |
1965 | ||
1966 | ret = ath10k_wmi_sta_keepalive(ar, &arg); | |
1967 | if (ret) { | |
1968 | ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n", | |
1969 | arvif->vdev_id, ret); | |
1970 | return ret; | |
1971 | } | |
1972 | ||
1973 | return 0; | |
1974 | } | |
1975 | ||
81a9a17d MK |
1976 | static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif) |
1977 | { | |
1978 | struct ath10k *ar = arvif->ar; | |
1979 | struct ieee80211_vif *vif = arvif->vif; | |
1980 | int ret; | |
1981 | ||
8513d95b MK |
1982 | lockdep_assert_held(&arvif->ar->conf_mutex); |
1983 | ||
1984 | if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))) | |
1985 | return; | |
1986 | ||
81a9a17d MK |
1987 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
1988 | return; | |
1989 | ||
1990 | if (!vif->csa_active) | |
1991 | return; | |
1992 | ||
1993 | if (!arvif->is_up) | |
1994 | return; | |
1995 | ||
1996 | if (!ieee80211_csa_is_complete(vif)) { | |
1997 | ieee80211_csa_update_counter(vif); | |
1998 | ||
1999 | ret = ath10k_mac_setup_bcn_tmpl(arvif); | |
2000 | if (ret) | |
2001 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", | |
2002 | ret); | |
2003 | ||
2004 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
2005 | if (ret) | |
2006 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", | |
2007 | ret); | |
2008 | } else { | |
2009 | ieee80211_csa_finish(vif); | |
2010 | } | |
2011 | } | |
2012 | ||
2013 | static void ath10k_mac_vif_ap_csa_work(struct work_struct *work) | |
2014 | { | |
2015 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, | |
2016 | ap_csa_work); | |
2017 | struct ath10k *ar = arvif->ar; | |
2018 | ||
2019 | mutex_lock(&ar->conf_mutex); | |
2020 | ath10k_mac_vif_ap_csa_count_down(arvif); | |
2021 | mutex_unlock(&ar->conf_mutex); | |
2022 | } | |
2023 | ||
cc9904e6 MK |
2024 | static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac, |
2025 | struct ieee80211_vif *vif) | |
2026 | { | |
2027 | struct sk_buff *skb = data; | |
2028 | struct ieee80211_mgmt *mgmt = (void *)skb->data; | |
56ac13bf | 2029 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
cc9904e6 MK |
2030 | |
2031 | if (vif->type != NL80211_IFTYPE_STATION) | |
2032 | return; | |
2033 | ||
2034 | if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) | |
2035 | return; | |
2036 | ||
2037 | cancel_delayed_work(&arvif->connection_loss_work); | |
2038 | } | |
2039 | ||
2040 | void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb) | |
2041 | { | |
2042 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
2043 | IEEE80211_IFACE_ITER_NORMAL, | |
2044 | ath10k_mac_handle_beacon_iter, | |
2045 | skb); | |
2046 | } | |
2047 | ||
2048 | static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac, | |
2049 | struct ieee80211_vif *vif) | |
2050 | { | |
2051 | u32 *vdev_id = data; | |
56ac13bf | 2052 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
cc9904e6 MK |
2053 | struct ath10k *ar = arvif->ar; |
2054 | struct ieee80211_hw *hw = ar->hw; | |
2055 | ||
2056 | if (arvif->vdev_id != *vdev_id) | |
2057 | return; | |
2058 | ||
2059 | if (!arvif->is_up) | |
2060 | return; | |
2061 | ||
2062 | ieee80211_beacon_loss(vif); | |
2063 | ||
2064 | /* Firmware doesn't report beacon loss events repeatedly. If AP probe | |
2065 | * (done by mac80211) succeeds but beacons do not resume then it | |
2066 | * doesn't make sense to continue operation. Queue connection loss work | |
2067 | * which can be cancelled when beacon is received. | |
2068 | */ | |
2069 | ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, | |
2070 | ATH10K_CONNECTION_LOSS_HZ); | |
2071 | } | |
2072 | ||
2073 | void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id) | |
2074 | { | |
2075 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
2076 | IEEE80211_IFACE_ITER_NORMAL, | |
2077 | ath10k_mac_handle_beacon_miss_iter, | |
2078 | &vdev_id); | |
2079 | } | |
2080 | ||
2081 | static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work) | |
2082 | { | |
2083 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, | |
2084 | connection_loss_work.work); | |
2085 | struct ieee80211_vif *vif = arvif->vif; | |
2086 | ||
2087 | if (!arvif->is_up) | |
2088 | return; | |
2089 | ||
2090 | ieee80211_connection_loss(vif); | |
2091 | } | |
2092 | ||
5e3dd157 KV |
2093 | /**********************/ |
2094 | /* Station management */ | |
2095 | /**********************/ | |
2096 | ||
590922a8 MK |
2097 | static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar, |
2098 | struct ieee80211_vif *vif) | |
2099 | { | |
2100 | /* Some firmware revisions have unstable STA powersave when listen | |
2101 | * interval is set too high (e.g. 5). The symptoms are firmware doesn't | |
2102 | * generate NullFunc frames properly even if buffered frames have been | |
2103 | * indicated in Beacon TIM. Firmware would seldom wake up to pull | |
2104 | * buffered frames. Often pinging the device from AP would simply fail. | |
2105 | * | |
2106 | * As a workaround set it to 1. | |
2107 | */ | |
2108 | if (vif->type == NL80211_IFTYPE_STATION) | |
2109 | return 1; | |
2110 | ||
2111 | return ar->hw->conf.listen_interval; | |
2112 | } | |
2113 | ||
5e3dd157 | 2114 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
590922a8 | 2115 | struct ieee80211_vif *vif, |
5e3dd157 | 2116 | struct ieee80211_sta *sta, |
5e3dd157 KV |
2117 | struct wmi_peer_assoc_complete_arg *arg) |
2118 | { | |
56ac13bf | 2119 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
c51880ea | 2120 | u32 aid; |
590922a8 | 2121 | |
548db54c MK |
2122 | lockdep_assert_held(&ar->conf_mutex); |
2123 | ||
c51880ea MK |
2124 | if (vif->type == NL80211_IFTYPE_STATION) |
2125 | aid = vif->bss_conf.aid; | |
2126 | else | |
2127 | aid = sta->aid; | |
2128 | ||
b25f32cb | 2129 | ether_addr_copy(arg->addr, sta->addr); |
5e3dd157 | 2130 | arg->vdev_id = arvif->vdev_id; |
c51880ea | 2131 | arg->peer_aid = aid; |
3fab30f7 | 2132 | arg->peer_flags |= arvif->ar->wmi.peer_flags->auth; |
590922a8 | 2133 | arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif); |
5e3dd157 | 2134 | arg->peer_num_spatial_streams = 1; |
590922a8 | 2135 | arg->peer_caps = vif->bss_conf.assoc_capability; |
5e3dd157 KV |
2136 | } |
2137 | ||
2138 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, | |
590922a8 | 2139 | struct ieee80211_vif *vif, |
90eceb3b | 2140 | struct ieee80211_sta *sta, |
5e3dd157 KV |
2141 | struct wmi_peer_assoc_complete_arg *arg) |
2142 | { | |
5e3dd157 | 2143 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
500ff9f9 | 2144 | struct cfg80211_chan_def def; |
5e3dd157 KV |
2145 | struct cfg80211_bss *bss; |
2146 | const u8 *rsnie = NULL; | |
2147 | const u8 *wpaie = NULL; | |
2148 | ||
548db54c MK |
2149 | lockdep_assert_held(&ar->conf_mutex); |
2150 | ||
500ff9f9 MK |
2151 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
2152 | return; | |
2153 | ||
2154 | bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0, | |
2155 | IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); | |
5e3dd157 KV |
2156 | if (bss) { |
2157 | const struct cfg80211_bss_ies *ies; | |
2158 | ||
2159 | rcu_read_lock(); | |
2160 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); | |
2161 | ||
2162 | ies = rcu_dereference(bss->ies); | |
2163 | ||
2164 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
5b07e07f KV |
2165 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
2166 | ies->data, | |
2167 | ies->len); | |
5e3dd157 KV |
2168 | rcu_read_unlock(); |
2169 | cfg80211_put_bss(ar->hw->wiphy, bss); | |
2170 | } | |
2171 | ||
2172 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ | |
2173 | if (rsnie || wpaie) { | |
7aa7a72a | 2174 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
3fab30f7 | 2175 | arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way; |
5e3dd157 KV |
2176 | } |
2177 | ||
2178 | if (wpaie) { | |
7aa7a72a | 2179 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
3fab30f7 | 2180 | arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way; |
5e3dd157 | 2181 | } |
90eceb3b T |
2182 | |
2183 | if (sta->mfp && | |
c4cdf753 KV |
2184 | test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT, |
2185 | ar->running_fw->fw_file.fw_features)) { | |
90eceb3b | 2186 | arg->peer_flags |= ar->wmi.peer_flags->pmf; |
5e3dd157 KV |
2187 | } |
2188 | } | |
2189 | ||
2190 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, | |
500ff9f9 | 2191 | struct ieee80211_vif *vif, |
5e3dd157 KV |
2192 | struct ieee80211_sta *sta, |
2193 | struct wmi_peer_assoc_complete_arg *arg) | |
2194 | { | |
56ac13bf | 2195 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 | 2196 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
500ff9f9 | 2197 | struct cfg80211_chan_def def; |
5e3dd157 KV |
2198 | const struct ieee80211_supported_band *sband; |
2199 | const struct ieee80211_rate *rates; | |
57fbcce3 | 2200 | enum nl80211_band band; |
5e3dd157 | 2201 | u32 ratemask; |
486017cc | 2202 | u8 rate; |
5e3dd157 KV |
2203 | int i; |
2204 | ||
548db54c MK |
2205 | lockdep_assert_held(&ar->conf_mutex); |
2206 | ||
500ff9f9 MK |
2207 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
2208 | return; | |
2209 | ||
45c9abc0 MK |
2210 | band = def.chan->band; |
2211 | sband = ar->hw->wiphy->bands[band]; | |
2212 | ratemask = sta->supp_rates[band]; | |
2213 | ratemask &= arvif->bitrate_mask.control[band].legacy; | |
5e3dd157 KV |
2214 | rates = sband->bitrates; |
2215 | ||
2216 | rateset->num_rates = 0; | |
2217 | ||
2218 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { | |
2219 | if (!(ratemask & 1)) | |
2220 | continue; | |
2221 | ||
486017cc MK |
2222 | rate = ath10k_mac_bitrate_to_rate(rates->bitrate); |
2223 | rateset->rates[rateset->num_rates] = rate; | |
5e3dd157 KV |
2224 | rateset->num_rates++; |
2225 | } | |
2226 | } | |
2227 | ||
45c9abc0 MK |
2228 | static bool |
2229 | ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | |
2230 | { | |
2231 | int nss; | |
2232 | ||
2233 | for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) | |
2234 | if (ht_mcs_mask[nss]) | |
2235 | return false; | |
2236 | ||
2237 | return true; | |
2238 | } | |
2239 | ||
2240 | static bool | |
2241 | ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
2242 | { | |
2243 | int nss; | |
2244 | ||
2245 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) | |
2246 | if (vht_mcs_mask[nss]) | |
2247 | return false; | |
2248 | ||
2249 | return true; | |
2250 | } | |
2251 | ||
5e3dd157 | 2252 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, |
45c9abc0 | 2253 | struct ieee80211_vif *vif, |
5e3dd157 KV |
2254 | struct ieee80211_sta *sta, |
2255 | struct wmi_peer_assoc_complete_arg *arg) | |
2256 | { | |
2257 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | |
56ac13bf | 2258 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
45c9abc0 | 2259 | struct cfg80211_chan_def def; |
57fbcce3 | 2260 | enum nl80211_band band; |
45c9abc0 MK |
2261 | const u8 *ht_mcs_mask; |
2262 | const u16 *vht_mcs_mask; | |
72f8cef5 VN |
2263 | int i, n; |
2264 | u8 max_nss; | |
af762c0b | 2265 | u32 stbc; |
5e3dd157 | 2266 | |
548db54c MK |
2267 | lockdep_assert_held(&ar->conf_mutex); |
2268 | ||
45c9abc0 MK |
2269 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
2270 | return; | |
2271 | ||
5e3dd157 KV |
2272 | if (!ht_cap->ht_supported) |
2273 | return; | |
2274 | ||
45c9abc0 MK |
2275 | band = def.chan->band; |
2276 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
2277 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2278 | ||
2279 | if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) && | |
2280 | ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) | |
2281 | return; | |
2282 | ||
3fab30f7 | 2283 | arg->peer_flags |= ar->wmi.peer_flags->ht; |
5e3dd157 KV |
2284 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
2285 | ht_cap->ampdu_factor)) - 1; | |
2286 | ||
2287 | arg->peer_mpdu_density = | |
2288 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); | |
2289 | ||
2290 | arg->peer_ht_caps = ht_cap->cap; | |
2291 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; | |
2292 | ||
2293 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) | |
3fab30f7 | 2294 | arg->peer_flags |= ar->wmi.peer_flags->ldbc; |
5e3dd157 KV |
2295 | |
2296 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { | |
3fab30f7 | 2297 | arg->peer_flags |= ar->wmi.peer_flags->bw40; |
5e3dd157 KV |
2298 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; |
2299 | } | |
2300 | ||
45c9abc0 MK |
2301 | if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { |
2302 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) | |
2303 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; | |
5e3dd157 | 2304 | |
45c9abc0 MK |
2305 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) |
2306 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; | |
2307 | } | |
5e3dd157 KV |
2308 | |
2309 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { | |
2310 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; | |
3fab30f7 | 2311 | arg->peer_flags |= ar->wmi.peer_flags->stbc; |
5e3dd157 KV |
2312 | } |
2313 | ||
2314 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { | |
5e3dd157 KV |
2315 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
2316 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
2317 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; | |
2318 | arg->peer_rate_caps |= stbc; | |
3fab30f7 | 2319 | arg->peer_flags |= ar->wmi.peer_flags->stbc; |
5e3dd157 KV |
2320 | } |
2321 | ||
5e3dd157 KV |
2322 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
2323 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; | |
2324 | else if (ht_cap->mcs.rx_mask[1]) | |
2325 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; | |
2326 | ||
45c9abc0 MK |
2327 | for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) |
2328 | if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && | |
2329 | (ht_mcs_mask[i / 8] & BIT(i % 8))) { | |
2330 | max_nss = (i / 8) + 1; | |
5e3dd157 | 2331 | arg->peer_ht_rates.rates[n++] = i; |
45c9abc0 | 2332 | } |
5e3dd157 | 2333 | |
fd71f807 BM |
2334 | /* |
2335 | * This is a workaround for HT-enabled STAs which break the spec | |
2336 | * and have no HT capabilities RX mask (no HT RX MCS map). | |
2337 | * | |
2338 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), | |
2339 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. | |
2340 | * | |
2341 | * Firmware asserts if such situation occurs. | |
2342 | */ | |
2343 | if (n == 0) { | |
2344 | arg->peer_ht_rates.num_rates = 8; | |
2345 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) | |
2346 | arg->peer_ht_rates.rates[i] = i; | |
2347 | } else { | |
2348 | arg->peer_ht_rates.num_rates = n; | |
72f8cef5 | 2349 | arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss); |
fd71f807 | 2350 | } |
5e3dd157 | 2351 | |
7aa7a72a | 2352 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", |
60c3daa8 | 2353 | arg->addr, |
5e3dd157 KV |
2354 | arg->peer_ht_rates.num_rates, |
2355 | arg->peer_num_spatial_streams); | |
2356 | } | |
2357 | ||
d3d3ff42 JD |
2358 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
2359 | struct ath10k_vif *arvif, | |
2360 | struct ieee80211_sta *sta) | |
5e3dd157 KV |
2361 | { |
2362 | u32 uapsd = 0; | |
2363 | u32 max_sp = 0; | |
d3d3ff42 | 2364 | int ret = 0; |
5e3dd157 | 2365 | |
548db54c MK |
2366 | lockdep_assert_held(&ar->conf_mutex); |
2367 | ||
5e3dd157 | 2368 | if (sta->wme && sta->uapsd_queues) { |
7aa7a72a | 2369 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", |
5e3dd157 KV |
2370 | sta->uapsd_queues, sta->max_sp); |
2371 | ||
5e3dd157 KV |
2372 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
2373 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | | |
2374 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; | |
2375 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) | |
2376 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | | |
2377 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; | |
2378 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) | |
2379 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | | |
2380 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; | |
2381 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) | |
2382 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | | |
2383 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; | |
2384 | ||
5e3dd157 KV |
2385 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
2386 | max_sp = sta->max_sp; | |
2387 | ||
d3d3ff42 JD |
2388 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
2389 | sta->addr, | |
2390 | WMI_AP_PS_PEER_PARAM_UAPSD, | |
2391 | uapsd); | |
2392 | if (ret) { | |
7aa7a72a | 2393 | ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n", |
69244e56 | 2394 | arvif->vdev_id, ret); |
d3d3ff42 JD |
2395 | return ret; |
2396 | } | |
5e3dd157 | 2397 | |
d3d3ff42 JD |
2398 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
2399 | sta->addr, | |
2400 | WMI_AP_PS_PEER_PARAM_MAX_SP, | |
2401 | max_sp); | |
2402 | if (ret) { | |
7aa7a72a | 2403 | ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n", |
69244e56 | 2404 | arvif->vdev_id, ret); |
d3d3ff42 JD |
2405 | return ret; |
2406 | } | |
5e3dd157 KV |
2407 | |
2408 | /* TODO setup this based on STA listen interval and | |
d6dfe25c MR |
2409 | * beacon interval. Currently we don't know |
2410 | * sta->listen_interval - mac80211 patch required. | |
2411 | * Currently use 10 seconds | |
2412 | */ | |
d3d3ff42 | 2413 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr, |
5b07e07f KV |
2414 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, |
2415 | 10); | |
d3d3ff42 | 2416 | if (ret) { |
7aa7a72a | 2417 | ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n", |
69244e56 | 2418 | arvif->vdev_id, ret); |
d3d3ff42 JD |
2419 | return ret; |
2420 | } | |
5e3dd157 | 2421 | } |
5e3dd157 | 2422 | |
d3d3ff42 | 2423 | return 0; |
5e3dd157 KV |
2424 | } |
2425 | ||
45c9abc0 MK |
2426 | static u16 |
2427 | ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set, | |
2428 | const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) | |
2429 | { | |
2430 | int idx_limit; | |
2431 | int nss; | |
2432 | u16 mcs_map; | |
2433 | u16 mcs; | |
2434 | ||
2435 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
2436 | mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & | |
2437 | vht_mcs_limit[nss]; | |
2438 | ||
2439 | if (mcs_map) | |
2440 | idx_limit = fls(mcs_map) - 1; | |
2441 | else | |
2442 | idx_limit = -1; | |
2443 | ||
2444 | switch (idx_limit) { | |
2445 | case 0: /* fall through */ | |
2446 | case 1: /* fall through */ | |
2447 | case 2: /* fall through */ | |
2448 | case 3: /* fall through */ | |
2449 | case 4: /* fall through */ | |
2450 | case 5: /* fall through */ | |
2451 | case 6: /* fall through */ | |
2452 | default: | |
2453 | /* see ath10k_mac_can_set_bitrate_mask() */ | |
2454 | WARN_ON(1); | |
2455 | /* fall through */ | |
2456 | case -1: | |
2457 | mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; | |
2458 | break; | |
2459 | case 7: | |
2460 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; | |
2461 | break; | |
2462 | case 8: | |
2463 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; | |
2464 | break; | |
2465 | case 9: | |
2466 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; | |
2467 | break; | |
2468 | } | |
2469 | ||
2470 | tx_mcs_set &= ~(0x3 << (nss * 2)); | |
2471 | tx_mcs_set |= mcs << (nss * 2); | |
2472 | } | |
2473 | ||
2474 | return tx_mcs_set; | |
2475 | } | |
2476 | ||
5e3dd157 | 2477 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, |
500ff9f9 | 2478 | struct ieee80211_vif *vif, |
5e3dd157 KV |
2479 | struct ieee80211_sta *sta, |
2480 | struct wmi_peer_assoc_complete_arg *arg) | |
2481 | { | |
2482 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; | |
56ac13bf | 2483 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
500ff9f9 | 2484 | struct cfg80211_chan_def def; |
57fbcce3 | 2485 | enum nl80211_band band; |
45c9abc0 | 2486 | const u16 *vht_mcs_mask; |
a24b88b5 | 2487 | u8 ampdu_factor; |
fefcd115 VRN |
2488 | u8 max_nss, vht_mcs; |
2489 | int i; | |
5e3dd157 | 2490 | |
500ff9f9 MK |
2491 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
2492 | return; | |
2493 | ||
5e3dd157 KV |
2494 | if (!vht_cap->vht_supported) |
2495 | return; | |
2496 | ||
45c9abc0 MK |
2497 | band = def.chan->band; |
2498 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2499 | ||
2500 | if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) | |
2501 | return; | |
2502 | ||
3fab30f7 | 2503 | arg->peer_flags |= ar->wmi.peer_flags->vht; |
d68bb12a | 2504 | |
57fbcce3 | 2505 | if (def.chan->band == NL80211_BAND_2GHZ) |
3fab30f7 | 2506 | arg->peer_flags |= ar->wmi.peer_flags->vht_2g; |
d68bb12a | 2507 | |
5e3dd157 KV |
2508 | arg->peer_vht_caps = vht_cap->cap; |
2509 | ||
a24b88b5 SM |
2510 | ampdu_factor = (vht_cap->cap & |
2511 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> | |
2512 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
2513 | ||
2514 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to | |
2515 | * zero in VHT IE. Using it would result in degraded throughput. | |
2516 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep | |
d6dfe25c MR |
2517 | * it if VHT max_mpdu is smaller. |
2518 | */ | |
a24b88b5 SM |
2519 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
2520 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
2521 | ampdu_factor)) - 1); | |
2522 | ||
5e3dd157 | 2523 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
3fab30f7 | 2524 | arg->peer_flags |= ar->wmi.peer_flags->bw80; |
5e3dd157 | 2525 | |
bc1efd73 SG |
2526 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) |
2527 | arg->peer_flags |= ar->wmi.peer_flags->bw160; | |
2528 | ||
fefcd115 VRN |
2529 | /* Calculate peer NSS capability from VHT capabilities if STA |
2530 | * supports VHT. | |
2531 | */ | |
2532 | for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
2533 | vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> | |
2534 | (2 * i) & 3; | |
2535 | ||
2536 | if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) && | |
2537 | vht_mcs_mask[i]) | |
2538 | max_nss = i + 1; | |
2539 | } | |
2540 | arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss); | |
5e3dd157 KV |
2541 | arg->peer_vht_rates.rx_max_rate = |
2542 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); | |
2543 | arg->peer_vht_rates.rx_mcs_set = | |
2544 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); | |
2545 | arg->peer_vht_rates.tx_max_rate = | |
2546 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); | |
45c9abc0 MK |
2547 | arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit( |
2548 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask); | |
5e3dd157 | 2549 | |
7aa7a72a | 2550 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", |
60c3daa8 | 2551 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
cc914a55 BG |
2552 | |
2553 | if (arg->peer_vht_rates.rx_max_rate && | |
2554 | (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) { | |
2555 | switch (arg->peer_vht_rates.rx_max_rate) { | |
2556 | case 1560: | |
2557 | /* Must be 2x2 at 160Mhz is all it can do. */ | |
2558 | arg->peer_bw_rxnss_override = 2; | |
2559 | break; | |
2560 | case 780: | |
2561 | /* Can only do 1x1 at 160Mhz (Long Guard Interval) */ | |
2562 | arg->peer_bw_rxnss_override = 1; | |
2563 | break; | |
2564 | } | |
2565 | } | |
5e3dd157 KV |
2566 | } |
2567 | ||
2568 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, | |
590922a8 | 2569 | struct ieee80211_vif *vif, |
5e3dd157 | 2570 | struct ieee80211_sta *sta, |
5e3dd157 KV |
2571 | struct wmi_peer_assoc_complete_arg *arg) |
2572 | { | |
56ac13bf | 2573 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
590922a8 | 2574 | |
5e3dd157 KV |
2575 | switch (arvif->vdev_type) { |
2576 | case WMI_VDEV_TYPE_AP: | |
d3d3ff42 | 2577 | if (sta->wme) |
3fab30f7 | 2578 | arg->peer_flags |= arvif->ar->wmi.peer_flags->qos; |
d3d3ff42 JD |
2579 | |
2580 | if (sta->wme && sta->uapsd_queues) { | |
3fab30f7 | 2581 | arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd; |
d3d3ff42 JD |
2582 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; |
2583 | } | |
5e3dd157 KV |
2584 | break; |
2585 | case WMI_VDEV_TYPE_STA: | |
07ffb449 | 2586 | if (sta->wme) |
3fab30f7 | 2587 | arg->peer_flags |= arvif->ar->wmi.peer_flags->qos; |
5e3dd157 | 2588 | break; |
627d9841 JD |
2589 | case WMI_VDEV_TYPE_IBSS: |
2590 | if (sta->wme) | |
3fab30f7 | 2591 | arg->peer_flags |= arvif->ar->wmi.peer_flags->qos; |
627d9841 | 2592 | break; |
5e3dd157 KV |
2593 | default: |
2594 | break; | |
2595 | } | |
627d9841 JD |
2596 | |
2597 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n", | |
3fab30f7 T |
2598 | sta->addr, !!(arg->peer_flags & |
2599 | arvif->ar->wmi.peer_flags->qos)); | |
5e3dd157 KV |
2600 | } |
2601 | ||
8d7aa6bc | 2602 | static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta) |
91b12089 | 2603 | { |
57fbcce3 | 2604 | return sta->supp_rates[NL80211_BAND_2GHZ] >> |
8d7aa6bc | 2605 | ATH10K_MAC_FIRST_OFDM_RATE_IDX; |
91b12089 MK |
2606 | } |
2607 | ||
06efdbe7 KV |
2608 | static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar, |
2609 | struct ieee80211_sta *sta) | |
2610 | { | |
bc1efd73 SG |
2611 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
2612 | switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { | |
2613 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: | |
2614 | return MODE_11AC_VHT160; | |
2615 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: | |
2616 | return MODE_11AC_VHT80_80; | |
2617 | default: | |
2618 | /* not sure if this is a valid case? */ | |
2619 | return MODE_11AC_VHT160; | |
2620 | } | |
2621 | } | |
2622 | ||
06efdbe7 KV |
2623 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
2624 | return MODE_11AC_VHT80; | |
2625 | ||
2626 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
2627 | return MODE_11AC_VHT40; | |
2628 | ||
2629 | if (sta->bandwidth == IEEE80211_STA_RX_BW_20) | |
2630 | return MODE_11AC_VHT20; | |
2631 | ||
2632 | return MODE_UNKNOWN; | |
2633 | } | |
2634 | ||
5e3dd157 | 2635 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
590922a8 | 2636 | struct ieee80211_vif *vif, |
5e3dd157 KV |
2637 | struct ieee80211_sta *sta, |
2638 | struct wmi_peer_assoc_complete_arg *arg) | |
2639 | { | |
56ac13bf | 2640 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
500ff9f9 | 2641 | struct cfg80211_chan_def def; |
57fbcce3 | 2642 | enum nl80211_band band; |
45c9abc0 MK |
2643 | const u8 *ht_mcs_mask; |
2644 | const u16 *vht_mcs_mask; | |
5e3dd157 KV |
2645 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
2646 | ||
500ff9f9 MK |
2647 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
2648 | return; | |
2649 | ||
45c9abc0 MK |
2650 | band = def.chan->band; |
2651 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
2652 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2653 | ||
2654 | switch (band) { | |
57fbcce3 | 2655 | case NL80211_BAND_2GHZ: |
45c9abc0 MK |
2656 | if (sta->vht_cap.vht_supported && |
2657 | !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) { | |
d68bb12a YL |
2658 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
2659 | phymode = MODE_11AC_VHT40; | |
2660 | else | |
2661 | phymode = MODE_11AC_VHT20; | |
45c9abc0 MK |
2662 | } else if (sta->ht_cap.ht_supported && |
2663 | !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) { | |
5e3dd157 KV |
2664 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
2665 | phymode = MODE_11NG_HT40; | |
2666 | else | |
2667 | phymode = MODE_11NG_HT20; | |
8d7aa6bc | 2668 | } else if (ath10k_mac_sta_has_ofdm_only(sta)) { |
5e3dd157 | 2669 | phymode = MODE_11G; |
91b12089 MK |
2670 | } else { |
2671 | phymode = MODE_11B; | |
5e3dd157 KV |
2672 | } |
2673 | ||
2674 | break; | |
57fbcce3 | 2675 | case NL80211_BAND_5GHZ: |
7cc45e98 SM |
2676 | /* |
2677 | * Check VHT first. | |
2678 | */ | |
45c9abc0 MK |
2679 | if (sta->vht_cap.vht_supported && |
2680 | !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) { | |
06efdbe7 | 2681 | phymode = ath10k_mac_get_phymode_vht(ar, sta); |
45c9abc0 MK |
2682 | } else if (sta->ht_cap.ht_supported && |
2683 | !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) { | |
2684 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) | |
5e3dd157 KV |
2685 | phymode = MODE_11NA_HT40; |
2686 | else | |
2687 | phymode = MODE_11NA_HT20; | |
2688 | } else { | |
2689 | phymode = MODE_11A; | |
2690 | } | |
2691 | ||
2692 | break; | |
2693 | default: | |
2694 | break; | |
2695 | } | |
2696 | ||
7aa7a72a | 2697 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
38a1d47e | 2698 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
60c3daa8 | 2699 | |
5e3dd157 KV |
2700 | arg->peer_phymode = phymode; |
2701 | WARN_ON(phymode == MODE_UNKNOWN); | |
2702 | } | |
2703 | ||
b9ada65d | 2704 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
590922a8 | 2705 | struct ieee80211_vif *vif, |
b9ada65d | 2706 | struct ieee80211_sta *sta, |
b9ada65d | 2707 | struct wmi_peer_assoc_complete_arg *arg) |
5e3dd157 | 2708 | { |
548db54c MK |
2709 | lockdep_assert_held(&ar->conf_mutex); |
2710 | ||
b9ada65d | 2711 | memset(arg, 0, sizeof(*arg)); |
5e3dd157 | 2712 | |
590922a8 | 2713 | ath10k_peer_assoc_h_basic(ar, vif, sta, arg); |
90eceb3b | 2714 | ath10k_peer_assoc_h_crypto(ar, vif, sta, arg); |
500ff9f9 | 2715 | ath10k_peer_assoc_h_rates(ar, vif, sta, arg); |
45c9abc0 | 2716 | ath10k_peer_assoc_h_ht(ar, vif, sta, arg); |
500ff9f9 | 2717 | ath10k_peer_assoc_h_vht(ar, vif, sta, arg); |
590922a8 MK |
2718 | ath10k_peer_assoc_h_qos(ar, vif, sta, arg); |
2719 | ath10k_peer_assoc_h_phymode(ar, vif, sta, arg); | |
5e3dd157 | 2720 | |
b9ada65d | 2721 | return 0; |
5e3dd157 KV |
2722 | } |
2723 | ||
90046f50 MK |
2724 | static const u32 ath10k_smps_map[] = { |
2725 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, | |
2726 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, | |
2727 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, | |
2728 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, | |
2729 | }; | |
2730 | ||
2731 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, | |
2732 | const u8 *addr, | |
2733 | const struct ieee80211_sta_ht_cap *ht_cap) | |
2734 | { | |
2735 | int smps; | |
2736 | ||
2737 | if (!ht_cap->ht_supported) | |
2738 | return 0; | |
2739 | ||
2740 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; | |
2741 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
2742 | ||
2743 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) | |
2744 | return -EINVAL; | |
2745 | ||
2746 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, | |
2747 | WMI_PEER_SMPS_STATE, | |
2748 | ath10k_smps_map[smps]); | |
2749 | } | |
2750 | ||
139e170d MK |
2751 | static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, |
2752 | struct ieee80211_vif *vif, | |
2753 | struct ieee80211_sta_vht_cap vht_cap) | |
2754 | { | |
56ac13bf | 2755 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
139e170d MK |
2756 | int ret; |
2757 | u32 param; | |
2758 | u32 value; | |
2759 | ||
08e75ea8 VN |
2760 | if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC) |
2761 | return 0; | |
2762 | ||
139e170d MK |
2763 | if (!(ar->vht_cap_info & |
2764 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
2765 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | | |
2766 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
2767 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) | |
2768 | return 0; | |
2769 | ||
2770 | param = ar->wmi.vdev_param->txbf; | |
2771 | value = 0; | |
2772 | ||
2773 | if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED)) | |
2774 | return 0; | |
2775 | ||
2776 | /* The following logic is correct. If a remote STA advertises support | |
2777 | * for being a beamformer then we should enable us being a beamformee. | |
2778 | */ | |
2779 | ||
2780 | if (ar->vht_cap_info & | |
2781 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
2782 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { | |
2783 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) | |
2784 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
2785 | ||
2786 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) | |
2787 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; | |
2788 | } | |
2789 | ||
2790 | if (ar->vht_cap_info & | |
2791 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
2792 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { | |
2793 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) | |
2794 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
2795 | ||
2796 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) | |
2797 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; | |
2798 | } | |
2799 | ||
2800 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE) | |
2801 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
2802 | ||
2803 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER) | |
2804 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
2805 | ||
2806 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value); | |
2807 | if (ret) { | |
2808 | ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n", | |
2809 | value, ret); | |
2810 | return ret; | |
2811 | } | |
2812 | ||
2813 | return 0; | |
2814 | } | |
2815 | ||
5e3dd157 KV |
2816 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
2817 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, | |
2818 | struct ieee80211_vif *vif, | |
2819 | struct ieee80211_bss_conf *bss_conf) | |
2820 | { | |
2821 | struct ath10k *ar = hw->priv; | |
56ac13bf | 2822 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
90046f50 | 2823 | struct ieee80211_sta_ht_cap ht_cap; |
139e170d | 2824 | struct ieee80211_sta_vht_cap vht_cap; |
b9ada65d | 2825 | struct wmi_peer_assoc_complete_arg peer_arg; |
5e3dd157 KV |
2826 | struct ieee80211_sta *ap_sta; |
2827 | int ret; | |
2828 | ||
548db54c MK |
2829 | lockdep_assert_held(&ar->conf_mutex); |
2830 | ||
077efc8c MK |
2831 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", |
2832 | arvif->vdev_id, arvif->bssid, arvif->aid); | |
2833 | ||
5e3dd157 KV |
2834 | rcu_read_lock(); |
2835 | ||
2836 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
2837 | if (!ap_sta) { | |
7aa7a72a | 2838 | ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n", |
69244e56 | 2839 | bss_conf->bssid, arvif->vdev_id); |
5e3dd157 KV |
2840 | rcu_read_unlock(); |
2841 | return; | |
2842 | } | |
2843 | ||
90046f50 | 2844 | /* ap_sta must be accessed only within rcu section which must be left |
d6dfe25c MR |
2845 | * before calling ath10k_setup_peer_smps() which might sleep. |
2846 | */ | |
90046f50 | 2847 | ht_cap = ap_sta->ht_cap; |
139e170d | 2848 | vht_cap = ap_sta->vht_cap; |
90046f50 | 2849 | |
590922a8 | 2850 | ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg); |
5e3dd157 | 2851 | if (ret) { |
7aa7a72a | 2852 | ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n", |
69244e56 | 2853 | bss_conf->bssid, arvif->vdev_id, ret); |
5e3dd157 KV |
2854 | rcu_read_unlock(); |
2855 | return; | |
2856 | } | |
2857 | ||
2858 | rcu_read_unlock(); | |
2859 | ||
b9ada65d KV |
2860 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
2861 | if (ret) { | |
7aa7a72a | 2862 | ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n", |
69244e56 | 2863 | bss_conf->bssid, arvif->vdev_id, ret); |
b9ada65d KV |
2864 | return; |
2865 | } | |
2866 | ||
90046f50 MK |
2867 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
2868 | if (ret) { | |
7aa7a72a | 2869 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n", |
69244e56 | 2870 | arvif->vdev_id, ret); |
90046f50 MK |
2871 | return; |
2872 | } | |
2873 | ||
139e170d MK |
2874 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
2875 | if (ret) { | |
2876 | ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n", | |
2877 | arvif->vdev_id, bss_conf->bssid, ret); | |
2878 | return; | |
2879 | } | |
2880 | ||
7aa7a72a | 2881 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
2882 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
2883 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); | |
2884 | ||
077efc8c MK |
2885 | WARN_ON(arvif->is_up); |
2886 | ||
c930f744 | 2887 | arvif->aid = bss_conf->aid; |
b25f32cb | 2888 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
c930f744 MK |
2889 | |
2890 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); | |
2891 | if (ret) { | |
7aa7a72a | 2892 | ath10k_warn(ar, "failed to set vdev %d up: %d\n", |
5e3dd157 | 2893 | arvif->vdev_id, ret); |
c930f744 MK |
2894 | return; |
2895 | } | |
2896 | ||
2897 | arvif->is_up = true; | |
0a987fb0 MK |
2898 | |
2899 | /* Workaround: Some firmware revisions (tested with qca6174 | |
2900 | * WLAN.RM.2.0-00073) have buggy powersave state machine and must be | |
2901 | * poked with peer param command. | |
2902 | */ | |
2903 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid, | |
2904 | WMI_PEER_DUMMY_VAR, 1); | |
2905 | if (ret) { | |
2906 | ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n", | |
2907 | arvif->bssid, arvif->vdev_id, ret); | |
2908 | return; | |
2909 | } | |
5e3dd157 KV |
2910 | } |
2911 | ||
5e3dd157 KV |
2912 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
2913 | struct ieee80211_vif *vif) | |
2914 | { | |
2915 | struct ath10k *ar = hw->priv; | |
56ac13bf | 2916 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
139e170d | 2917 | struct ieee80211_sta_vht_cap vht_cap = {}; |
5e3dd157 KV |
2918 | int ret; |
2919 | ||
548db54c MK |
2920 | lockdep_assert_held(&ar->conf_mutex); |
2921 | ||
077efc8c MK |
2922 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
2923 | arvif->vdev_id, arvif->bssid); | |
60c3daa8 | 2924 | |
5e3dd157 | 2925 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
077efc8c | 2926 | if (ret) |
aa66ba0c | 2927 | ath10k_warn(ar, "failed to down vdev %i: %d\n", |
077efc8c | 2928 | arvif->vdev_id, ret); |
5e3dd157 | 2929 | |
627613f8 SJ |
2930 | arvif->def_wep_key_idx = -1; |
2931 | ||
139e170d MK |
2932 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
2933 | if (ret) { | |
2934 | ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n", | |
2935 | arvif->vdev_id, ret); | |
2936 | return; | |
2937 | } | |
2938 | ||
c930f744 | 2939 | arvif->is_up = false; |
cc9904e6 MK |
2940 | |
2941 | cancel_delayed_work_sync(&arvif->connection_loss_work); | |
5e3dd157 KV |
2942 | } |
2943 | ||
590922a8 MK |
2944 | static int ath10k_station_assoc(struct ath10k *ar, |
2945 | struct ieee80211_vif *vif, | |
2946 | struct ieee80211_sta *sta, | |
2947 | bool reassoc) | |
5e3dd157 | 2948 | { |
56ac13bf | 2949 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
b9ada65d | 2950 | struct wmi_peer_assoc_complete_arg peer_arg; |
5e3dd157 KV |
2951 | int ret = 0; |
2952 | ||
548db54c MK |
2953 | lockdep_assert_held(&ar->conf_mutex); |
2954 | ||
590922a8 | 2955 | ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg); |
b9ada65d | 2956 | if (ret) { |
7aa7a72a | 2957 | ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n", |
69244e56 | 2958 | sta->addr, arvif->vdev_id, ret); |
b9ada65d KV |
2959 | return ret; |
2960 | } | |
2961 | ||
2962 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); | |
5e3dd157 | 2963 | if (ret) { |
7aa7a72a | 2964 | ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n", |
69244e56 | 2965 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 KV |
2966 | return ret; |
2967 | } | |
2968 | ||
b1ecde36 MK |
2969 | /* Re-assoc is run only to update supported rates for given station. It |
2970 | * doesn't make much sense to reconfigure the peer completely. | |
2971 | */ | |
2972 | if (!reassoc) { | |
2973 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, | |
2974 | &sta->ht_cap); | |
e81bd104 | 2975 | if (ret) { |
b1ecde36 | 2976 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n", |
e81bd104 MK |
2977 | arvif->vdev_id, ret); |
2978 | return ret; | |
2979 | } | |
e81bd104 | 2980 | |
b1ecde36 MK |
2981 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
2982 | if (ret) { | |
2983 | ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", | |
2984 | sta->addr, arvif->vdev_id, ret); | |
2985 | return ret; | |
2986 | } | |
5e3dd157 | 2987 | |
b1ecde36 MK |
2988 | if (!sta->wme) { |
2989 | arvif->num_legacy_stations++; | |
2990 | ret = ath10k_recalc_rtscts_prot(arvif); | |
2991 | if (ret) { | |
2992 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", | |
2993 | arvif->vdev_id, ret); | |
2994 | return ret; | |
2995 | } | |
2996 | } | |
2997 | ||
627613f8 | 2998 | /* Plumb cached keys only for static WEP */ |
c3816c9e | 2999 | if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) { |
627613f8 SJ |
3000 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); |
3001 | if (ret) { | |
3002 | ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", | |
3003 | arvif->vdev_id, ret); | |
3004 | return ret; | |
3005 | } | |
b1ecde36 | 3006 | } |
d3d3ff42 JD |
3007 | } |
3008 | ||
5e3dd157 KV |
3009 | return ret; |
3010 | } | |
3011 | ||
590922a8 MK |
3012 | static int ath10k_station_disassoc(struct ath10k *ar, |
3013 | struct ieee80211_vif *vif, | |
5e3dd157 KV |
3014 | struct ieee80211_sta *sta) |
3015 | { | |
56ac13bf | 3016 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 KV |
3017 | int ret = 0; |
3018 | ||
548db54c MK |
3019 | lockdep_assert_held(&ar->conf_mutex); |
3020 | ||
e81bd104 MK |
3021 | if (!sta->wme) { |
3022 | arvif->num_legacy_stations--; | |
3023 | ret = ath10k_recalc_rtscts_prot(arvif); | |
3024 | if (ret) { | |
7aa7a72a | 3025 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
e81bd104 MK |
3026 | arvif->vdev_id, ret); |
3027 | return ret; | |
3028 | } | |
3029 | } | |
3030 | ||
5e3dd157 KV |
3031 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
3032 | if (ret) { | |
7aa7a72a | 3033 | ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n", |
69244e56 | 3034 | arvif->vdev_id, ret); |
5e3dd157 KV |
3035 | return ret; |
3036 | } | |
3037 | ||
3038 | return ret; | |
3039 | } | |
3040 | ||
3041 | /**************/ | |
3042 | /* Regulatory */ | |
3043 | /**************/ | |
3044 | ||
3045 | static int ath10k_update_channel_list(struct ath10k *ar) | |
3046 | { | |
3047 | struct ieee80211_hw *hw = ar->hw; | |
3048 | struct ieee80211_supported_band **bands; | |
57fbcce3 | 3049 | enum nl80211_band band; |
5e3dd157 KV |
3050 | struct ieee80211_channel *channel; |
3051 | struct wmi_scan_chan_list_arg arg = {0}; | |
3052 | struct wmi_channel_arg *ch; | |
3053 | bool passive; | |
3054 | int len; | |
3055 | int ret; | |
3056 | int i; | |
3057 | ||
548db54c MK |
3058 | lockdep_assert_held(&ar->conf_mutex); |
3059 | ||
5e3dd157 | 3060 | bands = hw->wiphy->bands; |
57fbcce3 | 3061 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
5e3dd157 KV |
3062 | if (!bands[band]) |
3063 | continue; | |
3064 | ||
3065 | for (i = 0; i < bands[band]->n_channels; i++) { | |
3066 | if (bands[band]->channels[i].flags & | |
3067 | IEEE80211_CHAN_DISABLED) | |
3068 | continue; | |
3069 | ||
3070 | arg.n_channels++; | |
3071 | } | |
3072 | } | |
3073 | ||
3074 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; | |
3075 | arg.channels = kzalloc(len, GFP_KERNEL); | |
3076 | if (!arg.channels) | |
3077 | return -ENOMEM; | |
3078 | ||
3079 | ch = arg.channels; | |
57fbcce3 | 3080 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
5e3dd157 KV |
3081 | if (!bands[band]) |
3082 | continue; | |
3083 | ||
3084 | for (i = 0; i < bands[band]->n_channels; i++) { | |
3085 | channel = &bands[band]->channels[i]; | |
3086 | ||
3087 | if (channel->flags & IEEE80211_CHAN_DISABLED) | |
3088 | continue; | |
3089 | ||
9802977d | 3090 | ch->allow_ht = true; |
5e3dd157 KV |
3091 | |
3092 | /* FIXME: when should we really allow VHT? */ | |
3093 | ch->allow_vht = true; | |
3094 | ||
3095 | ch->allow_ibss = | |
8fe02e16 | 3096 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
5e3dd157 KV |
3097 | |
3098 | ch->ht40plus = | |
3099 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); | |
3100 | ||
e8a50f8b MP |
3101 | ch->chan_radar = |
3102 | !!(channel->flags & IEEE80211_CHAN_RADAR); | |
3103 | ||
8fe02e16 | 3104 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
5e3dd157 KV |
3105 | ch->passive = passive; |
3106 | ||
3f259111 SE |
3107 | /* the firmware is ignoring the "radar" flag of the |
3108 | * channel and is scanning actively using Probe Requests | |
3109 | * on "Radar detection"/DFS channels which are not | |
3110 | * marked as "available" | |
3111 | */ | |
3112 | ch->passive |= ch->chan_radar; | |
3113 | ||
5e3dd157 | 3114 | ch->freq = channel->center_freq; |
2d66721c | 3115 | ch->band_center_freq1 = channel->center_freq; |
89c5c843 | 3116 | ch->min_power = 0; |
02256930 MK |
3117 | ch->max_power = channel->max_power * 2; |
3118 | ch->max_reg_power = channel->max_reg_power * 2; | |
3119 | ch->max_antenna_gain = channel->max_antenna_gain * 2; | |
5e3dd157 KV |
3120 | ch->reg_class_id = 0; /* FIXME */ |
3121 | ||
3122 | /* FIXME: why use only legacy modes, why not any | |
3123 | * HT/VHT modes? Would that even make any | |
d6dfe25c MR |
3124 | * difference? |
3125 | */ | |
57fbcce3 | 3126 | if (channel->band == NL80211_BAND_2GHZ) |
5e3dd157 KV |
3127 | ch->mode = MODE_11G; |
3128 | else | |
3129 | ch->mode = MODE_11A; | |
3130 | ||
3131 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) | |
3132 | continue; | |
3133 | ||
7aa7a72a | 3134 | ath10k_dbg(ar, ATH10K_DBG_WMI, |
60c3daa8 KV |
3135 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
3136 | ch - arg.channels, arg.n_channels, | |
5e3dd157 KV |
3137 | ch->freq, ch->max_power, ch->max_reg_power, |
3138 | ch->max_antenna_gain, ch->mode); | |
3139 | ||
3140 | ch++; | |
3141 | } | |
3142 | } | |
3143 | ||
3144 | ret = ath10k_wmi_scan_chan_list(ar, &arg); | |
3145 | kfree(arg.channels); | |
3146 | ||
3147 | return ret; | |
3148 | } | |
3149 | ||
821af6ae MP |
3150 | static enum wmi_dfs_region |
3151 | ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region) | |
3152 | { | |
3153 | switch (dfs_region) { | |
3154 | case NL80211_DFS_UNSET: | |
3155 | return WMI_UNINIT_DFS_DOMAIN; | |
3156 | case NL80211_DFS_FCC: | |
3157 | return WMI_FCC_DFS_DOMAIN; | |
3158 | case NL80211_DFS_ETSI: | |
3159 | return WMI_ETSI_DFS_DOMAIN; | |
3160 | case NL80211_DFS_JP: | |
3161 | return WMI_MKK4_DFS_DOMAIN; | |
3162 | } | |
3163 | return WMI_UNINIT_DFS_DOMAIN; | |
3164 | } | |
3165 | ||
f7843d7f | 3166 | static void ath10k_regd_update(struct ath10k *ar) |
5e3dd157 | 3167 | { |
5e3dd157 | 3168 | struct reg_dmn_pair_mapping *regpair; |
5e3dd157 | 3169 | int ret; |
821af6ae MP |
3170 | enum wmi_dfs_region wmi_dfs_reg; |
3171 | enum nl80211_dfs_regions nl_dfs_reg; | |
5e3dd157 | 3172 | |
f7843d7f | 3173 | lockdep_assert_held(&ar->conf_mutex); |
5e3dd157 KV |
3174 | |
3175 | ret = ath10k_update_channel_list(ar); | |
3176 | if (ret) | |
7aa7a72a | 3177 | ath10k_warn(ar, "failed to update channel list: %d\n", ret); |
5e3dd157 KV |
3178 | |
3179 | regpair = ar->ath_common.regulatory.regpair; | |
f7843d7f | 3180 | |
97f2645f | 3181 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
821af6ae MP |
3182 | nl_dfs_reg = ar->dfs_detector->region; |
3183 | wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg); | |
3184 | } else { | |
3185 | wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN; | |
3186 | } | |
3187 | ||
5e3dd157 | 3188 | /* Target allows setting up per-band regdomain but ath_common provides |
d6dfe25c MR |
3189 | * a combined one only |
3190 | */ | |
5e3dd157 | 3191 | ret = ath10k_wmi_pdev_set_regdomain(ar, |
ef8c0017 KV |
3192 | regpair->reg_domain, |
3193 | regpair->reg_domain, /* 2ghz */ | |
3194 | regpair->reg_domain, /* 5ghz */ | |
5e3dd157 | 3195 | regpair->reg_2ghz_ctl, |
821af6ae MP |
3196 | regpair->reg_5ghz_ctl, |
3197 | wmi_dfs_reg); | |
5e3dd157 | 3198 | if (ret) |
7aa7a72a | 3199 | ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret); |
f7843d7f | 3200 | } |
548db54c | 3201 | |
46bc92be KV |
3202 | static void ath10k_mac_update_channel_list(struct ath10k *ar, |
3203 | struct ieee80211_supported_band *band) | |
523f6701 T |
3204 | { |
3205 | int i; | |
3206 | ||
3207 | if (ar->low_5ghz_chan && ar->high_5ghz_chan) { | |
3208 | for (i = 0; i < band->n_channels; i++) { | |
3209 | if (band->channels[i].center_freq < ar->low_5ghz_chan || | |
3210 | band->channels[i].center_freq > ar->high_5ghz_chan) | |
3211 | band->channels[i].flags |= | |
3212 | IEEE80211_CHAN_DISABLED; | |
3213 | } | |
3214 | } | |
3215 | } | |
3216 | ||
f7843d7f MK |
3217 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
3218 | struct regulatory_request *request) | |
3219 | { | |
3220 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); | |
3221 | struct ath10k *ar = hw->priv; | |
9702c686 | 3222 | bool result; |
f7843d7f MK |
3223 | |
3224 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); | |
3225 | ||
97f2645f | 3226 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
7aa7a72a | 3227 | ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
9702c686 JD |
3228 | request->dfs_region); |
3229 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, | |
3230 | request->dfs_region); | |
3231 | if (!result) | |
7aa7a72a | 3232 | ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n", |
9702c686 JD |
3233 | request->dfs_region); |
3234 | } | |
3235 | ||
f7843d7f MK |
3236 | mutex_lock(&ar->conf_mutex); |
3237 | if (ar->state == ATH10K_STATE_ON) | |
3238 | ath10k_regd_update(ar); | |
548db54c | 3239 | mutex_unlock(&ar->conf_mutex); |
523f6701 T |
3240 | |
3241 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) | |
3242 | ath10k_mac_update_channel_list(ar, | |
46bc92be | 3243 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ]); |
5e3dd157 KV |
3244 | } |
3245 | ||
6f6eb1bc S |
3246 | static void ath10k_stop_radar_confirmation(struct ath10k *ar) |
3247 | { | |
3248 | spin_lock_bh(&ar->data_lock); | |
3249 | ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED; | |
3250 | spin_unlock_bh(&ar->data_lock); | |
3251 | ||
3252 | cancel_work_sync(&ar->radar_confirmation_work); | |
3253 | } | |
3254 | ||
5e3dd157 KV |
3255 | /***************/ |
3256 | /* TX handlers */ | |
3257 | /***************/ | |
3258 | ||
a30c7d00 MK |
3259 | enum ath10k_mac_tx_path { |
3260 | ATH10K_MAC_TX_HTT, | |
3261 | ATH10K_MAC_TX_HTT_MGMT, | |
3262 | ATH10K_MAC_TX_WMI_MGMT, | |
3263 | ATH10K_MAC_TX_UNKNOWN, | |
3264 | }; | |
3265 | ||
96d828d4 | 3266 | void ath10k_mac_tx_lock(struct ath10k *ar, int reason) |
42c3aa6f | 3267 | { |
96d828d4 | 3268 | lockdep_assert_held(&ar->htt.tx_lock); |
42c3aa6f | 3269 | |
96d828d4 MK |
3270 | WARN_ON(reason >= ATH10K_TX_PAUSE_MAX); |
3271 | ar->tx_paused |= BIT(reason); | |
3272 | ieee80211_stop_queues(ar->hw); | |
42c3aa6f MK |
3273 | } |
3274 | ||
96d828d4 MK |
3275 | static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac, |
3276 | struct ieee80211_vif *vif) | |
ddb6ad77 | 3277 | { |
96d828d4 | 3278 | struct ath10k *ar = data; |
56ac13bf | 3279 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
ddb6ad77 | 3280 | |
96d828d4 MK |
3281 | if (arvif->tx_paused) |
3282 | return; | |
ddb6ad77 | 3283 | |
96d828d4 | 3284 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); |
ddb6ad77 MK |
3285 | } |
3286 | ||
96d828d4 | 3287 | void ath10k_mac_tx_unlock(struct ath10k *ar, int reason) |
5e3dd157 | 3288 | { |
96d828d4 | 3289 | lockdep_assert_held(&ar->htt.tx_lock); |
5e3dd157 | 3290 | |
96d828d4 MK |
3291 | WARN_ON(reason >= ATH10K_TX_PAUSE_MAX); |
3292 | ar->tx_paused &= ~BIT(reason); | |
5e3dd157 | 3293 | |
96d828d4 MK |
3294 | if (ar->tx_paused) |
3295 | return; | |
c21c64d1 | 3296 | |
96d828d4 MK |
3297 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
3298 | IEEE80211_IFACE_ITER_RESUME_ALL, | |
3299 | ath10k_mac_tx_unlock_iter, | |
3300 | ar); | |
3a73d1a6 MK |
3301 | |
3302 | ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue); | |
5e3dd157 KV |
3303 | } |
3304 | ||
96d828d4 | 3305 | void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason) |
5e3dd157 | 3306 | { |
96d828d4 | 3307 | struct ath10k *ar = arvif->ar; |
5e3dd157 | 3308 | |
96d828d4 | 3309 | lockdep_assert_held(&ar->htt.tx_lock); |
5e3dd157 | 3310 | |
96d828d4 MK |
3311 | WARN_ON(reason >= BITS_PER_LONG); |
3312 | arvif->tx_paused |= BIT(reason); | |
3313 | ieee80211_stop_queue(ar->hw, arvif->vdev_id); | |
3314 | } | |
3315 | ||
3316 | void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason) | |
3317 | { | |
3318 | struct ath10k *ar = arvif->ar; | |
3319 | ||
3320 | lockdep_assert_held(&ar->htt.tx_lock); | |
3321 | ||
3322 | WARN_ON(reason >= BITS_PER_LONG); | |
3323 | arvif->tx_paused &= ~BIT(reason); | |
3324 | ||
3325 | if (ar->tx_paused) | |
3326 | return; | |
3327 | ||
3328 | if (arvif->tx_paused) | |
3329 | return; | |
3330 | ||
3331 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); | |
3332 | } | |
3333 | ||
b4aa539d MK |
3334 | static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif, |
3335 | enum wmi_tlv_tx_pause_id pause_id, | |
3336 | enum wmi_tlv_tx_pause_action action) | |
3337 | { | |
3338 | struct ath10k *ar = arvif->ar; | |
3339 | ||
3340 | lockdep_assert_held(&ar->htt.tx_lock); | |
3341 | ||
acd0b27b MK |
3342 | switch (action) { |
3343 | case WMI_TLV_TX_PAUSE_ACTION_STOP: | |
3344 | ath10k_mac_vif_tx_lock(arvif, pause_id); | |
3345 | break; | |
3346 | case WMI_TLV_TX_PAUSE_ACTION_WAKE: | |
3347 | ath10k_mac_vif_tx_unlock(arvif, pause_id); | |
b4aa539d | 3348 | break; |
b4aa539d | 3349 | default: |
209b2a68 BM |
3350 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
3351 | "received unknown tx pause action %d on vdev %i, ignoring\n", | |
acd0b27b | 3352 | action, arvif->vdev_id); |
b4aa539d MK |
3353 | break; |
3354 | } | |
3355 | } | |
3356 | ||
3357 | struct ath10k_mac_tx_pause { | |
3358 | u32 vdev_id; | |
3359 | enum wmi_tlv_tx_pause_id pause_id; | |
3360 | enum wmi_tlv_tx_pause_action action; | |
3361 | }; | |
3362 | ||
3363 | static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac, | |
3364 | struct ieee80211_vif *vif) | |
3365 | { | |
56ac13bf | 3366 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
b4aa539d MK |
3367 | struct ath10k_mac_tx_pause *arg = data; |
3368 | ||
acd0b27b MK |
3369 | if (arvif->vdev_id != arg->vdev_id) |
3370 | return; | |
3371 | ||
b4aa539d MK |
3372 | ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action); |
3373 | } | |
3374 | ||
acd0b27b MK |
3375 | void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id, |
3376 | enum wmi_tlv_tx_pause_id pause_id, | |
3377 | enum wmi_tlv_tx_pause_action action) | |
b4aa539d MK |
3378 | { |
3379 | struct ath10k_mac_tx_pause arg = { | |
3380 | .vdev_id = vdev_id, | |
3381 | .pause_id = pause_id, | |
3382 | .action = action, | |
3383 | }; | |
3384 | ||
3385 | spin_lock_bh(&ar->htt.tx_lock); | |
3386 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
3387 | IEEE80211_IFACE_ITER_RESUME_ALL, | |
3388 | ath10k_mac_handle_tx_pause_iter, | |
3389 | &arg); | |
3390 | spin_unlock_bh(&ar->htt.tx_lock); | |
3391 | } | |
3392 | ||
d740d8fd | 3393 | static enum ath10k_hw_txrx_mode |
6a2636d8 MK |
3394 | ath10k_mac_tx_h_get_txmode(struct ath10k *ar, |
3395 | struct ieee80211_vif *vif, | |
3396 | struct ieee80211_sta *sta, | |
3397 | struct sk_buff *skb) | |
d740d8fd MK |
3398 | { |
3399 | const struct ieee80211_hdr *hdr = (void *)skb->data; | |
3400 | __le16 fc = hdr->frame_control; | |
3401 | ||
3402 | if (!vif || vif->type == NL80211_IFTYPE_MONITOR) | |
3403 | return ATH10K_HW_TXRX_RAW; | |
3404 | ||
3405 | if (ieee80211_is_mgmt(fc)) | |
3406 | return ATH10K_HW_TXRX_MGMT; | |
3407 | ||
3408 | /* Workaround: | |
3409 | * | |
3410 | * NullFunc frames are mostly used to ping if a client or AP are still | |
3411 | * reachable and responsive. This implies tx status reports must be | |
3412 | * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can | |
3413 | * come to a conclusion that the other end disappeared and tear down | |
3414 | * BSS connection or it can never disconnect from BSS/client (which is | |
3415 | * the case). | |
3416 | * | |
3417 | * Firmware with HTT older than 3.0 delivers incorrect tx status for | |
3418 | * NullFunc frames to driver. However there's a HTT Mgmt Tx command | |
3419 | * which seems to deliver correct tx reports for NullFunc frames. The | |
3420 | * downside of using it is it ignores client powersave state so it can | |
3421 | * end up disconnecting sleeping clients in AP mode. It should fix STA | |
3422 | * mode though because AP don't sleep. | |
3423 | */ | |
3424 | if (ar->htt.target_version_major < 3 && | |
3425 | (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) && | |
c4cdf753 KV |
3426 | !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
3427 | ar->running_fw->fw_file.fw_features)) | |
d740d8fd MK |
3428 | return ATH10K_HW_TXRX_MGMT; |
3429 | ||
75d85fd9 MP |
3430 | /* Workaround: |
3431 | * | |
3432 | * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for | |
3433 | * NativeWifi txmode - it selects AP key instead of peer key. It seems | |
3434 | * to work with Ethernet txmode so use it. | |
ccec9038 DL |
3435 | * |
3436 | * FIXME: Check if raw mode works with TDLS. | |
75d85fd9 MP |
3437 | */ |
3438 | if (ieee80211_is_data_present(fc) && sta && sta->tdls) | |
3439 | return ATH10K_HW_TXRX_ETHERNET; | |
3440 | ||
ccec9038 DL |
3441 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
3442 | return ATH10K_HW_TXRX_RAW; | |
3443 | ||
d740d8fd MK |
3444 | return ATH10K_HW_TXRX_NATIVE_WIFI; |
3445 | } | |
3446 | ||
ccec9038 | 3447 | static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif, |
fd12cb32 MK |
3448 | struct sk_buff *skb) |
3449 | { | |
3450 | const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
3451 | const struct ieee80211_hdr *hdr = (void *)skb->data; | |
ccec9038 DL |
3452 | const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT | |
3453 | IEEE80211_TX_CTL_INJECTED; | |
fd12cb32 MK |
3454 | |
3455 | if (!ieee80211_has_protected(hdr->frame_control)) | |
3456 | return false; | |
3457 | ||
ccec9038 DL |
3458 | if ((info->flags & mask) == mask) |
3459 | return false; | |
fd12cb32 | 3460 | |
ccec9038 | 3461 | if (vif) |
56ac13bf | 3462 | return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt; |
fd12cb32 | 3463 | |
ccec9038 DL |
3464 | return true; |
3465 | } | |
3466 | ||
4b604558 MK |
3467 | /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS |
3468 | * Control in the header. | |
5e3dd157 | 3469 | */ |
4b604558 | 3470 | static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb) |
5e3dd157 KV |
3471 | { |
3472 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
c21c64d1 | 3473 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
5e3dd157 KV |
3474 | u8 *qos_ctl; |
3475 | ||
3476 | if (!ieee80211_is_data_qos(hdr->frame_control)) | |
3477 | return; | |
3478 | ||
3479 | qos_ctl = ieee80211_get_qos_ctl(hdr); | |
ba0ccd7a MK |
3480 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
3481 | skb->data, (void *)qos_ctl - (void *)skb->data); | |
3482 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); | |
c21c64d1 | 3483 | |
8bad8dcd MK |
3484 | /* Some firmware revisions don't handle sending QoS NullFunc well. |
3485 | * These frames are mainly used for CQM purposes so it doesn't really | |
3486 | * matter whether QoS NullFunc or NullFunc are sent. | |
c21c64d1 | 3487 | */ |
bf0a26d3 | 3488 | hdr = (void *)skb->data; |
8bad8dcd | 3489 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
609db229 | 3490 | cb->flags &= ~ATH10K_SKB_F_QOS; |
8bad8dcd MK |
3491 | |
3492 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA); | |
5e3dd157 KV |
3493 | } |
3494 | ||
d740d8fd MK |
3495 | static void ath10k_tx_h_8023(struct sk_buff *skb) |
3496 | { | |
3497 | struct ieee80211_hdr *hdr; | |
3498 | struct rfc1042_hdr *rfc1042; | |
3499 | struct ethhdr *eth; | |
3500 | size_t hdrlen; | |
3501 | u8 da[ETH_ALEN]; | |
3502 | u8 sa[ETH_ALEN]; | |
3503 | __be16 type; | |
3504 | ||
3505 | hdr = (void *)skb->data; | |
3506 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
3507 | rfc1042 = (void *)skb->data + hdrlen; | |
3508 | ||
3509 | ether_addr_copy(da, ieee80211_get_DA(hdr)); | |
3510 | ether_addr_copy(sa, ieee80211_get_SA(hdr)); | |
3511 | type = rfc1042->snap_type; | |
3512 | ||
3513 | skb_pull(skb, hdrlen + sizeof(*rfc1042)); | |
3514 | skb_push(skb, sizeof(*eth)); | |
3515 | ||
3516 | eth = (void *)skb->data; | |
3517 | ether_addr_copy(eth->h_dest, da); | |
3518 | ether_addr_copy(eth->h_source, sa); | |
3519 | eth->h_proto = type; | |
5e3dd157 KV |
3520 | } |
3521 | ||
4b604558 MK |
3522 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, |
3523 | struct ieee80211_vif *vif, | |
3524 | struct sk_buff *skb) | |
5e3dd157 KV |
3525 | { |
3526 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
56ac13bf | 3527 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 KV |
3528 | |
3529 | /* This is case only for P2P_GO */ | |
08c27be1 | 3530 | if (vif->type != NL80211_IFTYPE_AP || !vif->p2p) |
5e3dd157 KV |
3531 | return; |
3532 | ||
3533 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { | |
3534 | spin_lock_bh(&ar->data_lock); | |
3535 | if (arvif->u.ap.noa_data) | |
3536 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, | |
3537 | GFP_ATOMIC)) | |
59ae1d12 JB |
3538 | skb_put_data(skb, arvif->u.ap.noa_data, |
3539 | arvif->u.ap.noa_len); | |
5e3dd157 KV |
3540 | spin_unlock_bh(&ar->data_lock); |
3541 | } | |
3542 | } | |
3543 | ||
f2f6ecab MK |
3544 | static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar, |
3545 | struct ieee80211_vif *vif, | |
dd4717b6 | 3546 | struct ieee80211_txq *txq, |
f2f6ecab MK |
3547 | struct sk_buff *skb) |
3548 | { | |
3549 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
3550 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); | |
3551 | ||
3552 | cb->flags = 0; | |
3553 | if (!ath10k_tx_h_use_hwcrypto(vif, skb)) | |
3554 | cb->flags |= ATH10K_SKB_F_NO_HWCRYPT; | |
3555 | ||
3556 | if (ieee80211_is_mgmt(hdr->frame_control)) | |
3557 | cb->flags |= ATH10K_SKB_F_MGMT; | |
3558 | ||
3559 | if (ieee80211_is_data_qos(hdr->frame_control)) | |
3560 | cb->flags |= ATH10K_SKB_F_QOS; | |
3561 | ||
3562 | cb->vif = vif; | |
dd4717b6 | 3563 | cb->txq = txq; |
f2f6ecab MK |
3564 | } |
3565 | ||
d39de991 | 3566 | bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar) |
8d6d3624 MK |
3567 | { |
3568 | /* FIXME: Not really sure since when the behaviour changed. At some | |
3569 | * point new firmware stopped requiring creation of peer entries for | |
3570 | * offchannel tx (and actually creating them causes issues with wmi-htc | |
3571 | * tx credit replenishment and reliability). Assuming it's at least 3.4 | |
3572 | * because that's when the `freq` was introduced to TX_FRM HTT command. | |
3573 | */ | |
8921f5f7 | 3574 | return (ar->htt.target_version_major >= 3 && |
d39de991 | 3575 | ar->htt.target_version_minor >= 4 && |
77561f93 | 3576 | ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV); |
8d6d3624 MK |
3577 | } |
3578 | ||
d740d8fd | 3579 | static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb) |
5e3dd157 | 3580 | { |
d740d8fd | 3581 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; |
5e00d31a | 3582 | int ret = 0; |
5e3dd157 | 3583 | |
d740d8fd MK |
3584 | spin_lock_bh(&ar->data_lock); |
3585 | ||
3586 | if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) { | |
3587 | ath10k_warn(ar, "wmi mgmt tx queue is full\n"); | |
3588 | ret = -ENOSPC; | |
3589 | goto unlock; | |
961d4c38 MK |
3590 | } |
3591 | ||
d740d8fd MK |
3592 | __skb_queue_tail(q, skb); |
3593 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); | |
5e00d31a | 3594 | |
d740d8fd MK |
3595 | unlock: |
3596 | spin_unlock_bh(&ar->data_lock); | |
3597 | ||
3598 | return ret; | |
3599 | } | |
3600 | ||
a30c7d00 MK |
3601 | static enum ath10k_mac_tx_path |
3602 | ath10k_mac_tx_h_get_txpath(struct ath10k *ar, | |
3603 | struct sk_buff *skb, | |
3604 | enum ath10k_hw_txrx_mode txmode) | |
d740d8fd | 3605 | { |
8a933964 | 3606 | switch (txmode) { |
d740d8fd MK |
3607 | case ATH10K_HW_TXRX_RAW: |
3608 | case ATH10K_HW_TXRX_NATIVE_WIFI: | |
3609 | case ATH10K_HW_TXRX_ETHERNET: | |
a30c7d00 | 3610 | return ATH10K_MAC_TX_HTT; |
d740d8fd MK |
3611 | case ATH10K_HW_TXRX_MGMT: |
3612 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, | |
229329ff RP |
3613 | ar->running_fw->fw_file.fw_features) || |
3614 | test_bit(WMI_SERVICE_MGMT_TX_WMI, | |
3615 | ar->wmi.svc_map)) | |
a30c7d00 | 3616 | return ATH10K_MAC_TX_WMI_MGMT; |
d740d8fd | 3617 | else if (ar->htt.target_version_major >= 3) |
a30c7d00 | 3618 | return ATH10K_MAC_TX_HTT; |
d740d8fd | 3619 | else |
a30c7d00 MK |
3620 | return ATH10K_MAC_TX_HTT_MGMT; |
3621 | } | |
3622 | ||
3623 | return ATH10K_MAC_TX_UNKNOWN; | |
3624 | } | |
3625 | ||
3626 | static int ath10k_mac_tx_submit(struct ath10k *ar, | |
3627 | enum ath10k_hw_txrx_mode txmode, | |
6421969f | 3628 | enum ath10k_mac_tx_path txpath, |
a30c7d00 MK |
3629 | struct sk_buff *skb) |
3630 | { | |
3631 | struct ath10k_htt *htt = &ar->htt; | |
6421969f | 3632 | int ret = -EINVAL; |
a30c7d00 MK |
3633 | |
3634 | switch (txpath) { | |
3635 | case ATH10K_MAC_TX_HTT: | |
5df6e131 | 3636 | ret = ath10k_htt_tx(htt, txmode, skb); |
a30c7d00 MK |
3637 | break; |
3638 | case ATH10K_MAC_TX_HTT_MGMT: | |
3639 | ret = ath10k_htt_mgmt_tx(htt, skb); | |
3640 | break; | |
3641 | case ATH10K_MAC_TX_WMI_MGMT: | |
3642 | ret = ath10k_mac_tx_wmi_mgmt(ar, skb); | |
3643 | break; | |
3644 | case ATH10K_MAC_TX_UNKNOWN: | |
3645 | WARN_ON_ONCE(1); | |
3646 | ret = -EINVAL; | |
d740d8fd | 3647 | break; |
5e00d31a | 3648 | } |
5e3dd157 KV |
3649 | |
3650 | if (ret) { | |
7aa7a72a MK |
3651 | ath10k_warn(ar, "failed to transmit packet, dropping: %d\n", |
3652 | ret); | |
5e3dd157 KV |
3653 | ieee80211_free_txskb(ar->hw, skb); |
3654 | } | |
f2f6ecab MK |
3655 | |
3656 | return ret; | |
3657 | } | |
3658 | ||
3659 | /* This function consumes the sk_buff regardless of return value as far as | |
3660 | * caller is concerned so no freeing is necessary afterwards. | |
3661 | */ | |
3662 | static int ath10k_mac_tx(struct ath10k *ar, | |
3663 | struct ieee80211_vif *vif, | |
f2f6ecab | 3664 | enum ath10k_hw_txrx_mode txmode, |
6421969f | 3665 | enum ath10k_mac_tx_path txpath, |
f2f6ecab MK |
3666 | struct sk_buff *skb) |
3667 | { | |
3668 | struct ieee80211_hw *hw = ar->hw; | |
3669 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
3670 | int ret; | |
3671 | ||
3672 | /* We should disable CCK RATE due to P2P */ | |
3673 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) | |
3674 | ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n"); | |
3675 | ||
3676 | switch (txmode) { | |
3677 | case ATH10K_HW_TXRX_MGMT: | |
3678 | case ATH10K_HW_TXRX_NATIVE_WIFI: | |
3679 | ath10k_tx_h_nwifi(hw, skb); | |
3680 | ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb); | |
3681 | ath10k_tx_h_seq_no(vif, skb); | |
3682 | break; | |
3683 | case ATH10K_HW_TXRX_ETHERNET: | |
3684 | ath10k_tx_h_8023(skb); | |
3685 | break; | |
3686 | case ATH10K_HW_TXRX_RAW: | |
3687 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { | |
3688 | WARN_ON_ONCE(1); | |
3689 | ieee80211_free_txskb(hw, skb); | |
3690 | return -ENOTSUPP; | |
3691 | } | |
3692 | } | |
3693 | ||
3694 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { | |
3695 | if (!ath10k_mac_tx_frm_has_freq(ar)) { | |
75b34800 | 3696 | ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n", |
f2f6ecab MK |
3697 | skb); |
3698 | ||
3699 | skb_queue_tail(&ar->offchan_tx_queue, skb); | |
3700 | ieee80211_queue_work(hw, &ar->offchan_tx_work); | |
3701 | return 0; | |
3702 | } | |
3703 | } | |
3704 | ||
6421969f | 3705 | ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb); |
f2f6ecab MK |
3706 | if (ret) { |
3707 | ath10k_warn(ar, "failed to submit frame: %d\n", ret); | |
3708 | return ret; | |
3709 | } | |
3710 | ||
3711 | return 0; | |
5e3dd157 KV |
3712 | } |
3713 | ||
3714 | void ath10k_offchan_tx_purge(struct ath10k *ar) | |
3715 | { | |
3716 | struct sk_buff *skb; | |
3717 | ||
3718 | for (;;) { | |
3719 | skb = skb_dequeue(&ar->offchan_tx_queue); | |
3720 | if (!skb) | |
3721 | break; | |
3722 | ||
3723 | ieee80211_free_txskb(ar->hw, skb); | |
3724 | } | |
3725 | } | |
3726 | ||
3727 | void ath10k_offchan_tx_work(struct work_struct *work) | |
3728 | { | |
3729 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); | |
3730 | struct ath10k_peer *peer; | |
8a933964 | 3731 | struct ath10k_vif *arvif; |
f2f6ecab | 3732 | enum ath10k_hw_txrx_mode txmode; |
6421969f | 3733 | enum ath10k_mac_tx_path txpath; |
5e3dd157 | 3734 | struct ieee80211_hdr *hdr; |
8a933964 MK |
3735 | struct ieee80211_vif *vif; |
3736 | struct ieee80211_sta *sta; | |
5e3dd157 KV |
3737 | struct sk_buff *skb; |
3738 | const u8 *peer_addr; | |
3739 | int vdev_id; | |
3740 | int ret; | |
8e9904f5 | 3741 | unsigned long time_left; |
adaeed74 | 3742 | bool tmp_peer_created = false; |
5e3dd157 KV |
3743 | |
3744 | /* FW requirement: We must create a peer before FW will send out | |
3745 | * an offchannel frame. Otherwise the frame will be stuck and | |
3746 | * never transmitted. We delete the peer upon tx completion. | |
3747 | * It is unlikely that a peer for offchannel tx will already be | |
3748 | * present. However it may be in some rare cases so account for that. | |
d6dfe25c MR |
3749 | * Otherwise we might remove a legitimate peer and break stuff. |
3750 | */ | |
5e3dd157 KV |
3751 | |
3752 | for (;;) { | |
3753 | skb = skb_dequeue(&ar->offchan_tx_queue); | |
3754 | if (!skb) | |
3755 | break; | |
3756 | ||
3757 | mutex_lock(&ar->conf_mutex); | |
3758 | ||
75b34800 | 3759 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n", |
5e3dd157 KV |
3760 | skb); |
3761 | ||
3762 | hdr = (struct ieee80211_hdr *)skb->data; | |
3763 | peer_addr = ieee80211_get_DA(hdr); | |
5e3dd157 KV |
3764 | |
3765 | spin_lock_bh(&ar->data_lock); | |
609db229 | 3766 | vdev_id = ar->scan.vdev_id; |
5e3dd157 KV |
3767 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); |
3768 | spin_unlock_bh(&ar->data_lock); | |
3769 | ||
3770 | if (peer) | |
60c3daa8 | 3771 | /* FIXME: should this use ath10k_warn()? */ |
7aa7a72a | 3772 | ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n", |
5e3dd157 KV |
3773 | peer_addr, vdev_id); |
3774 | ||
3775 | if (!peer) { | |
6942726f MK |
3776 | ret = ath10k_peer_create(ar, NULL, NULL, vdev_id, |
3777 | peer_addr, | |
7390ed34 | 3778 | WMI_PEER_TYPE_DEFAULT); |
5e3dd157 | 3779 | if (ret) |
7aa7a72a | 3780 | ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n", |
5e3dd157 | 3781 | peer_addr, vdev_id, ret); |
adaeed74 | 3782 | tmp_peer_created = (ret == 0); |
5e3dd157 KV |
3783 | } |
3784 | ||
3785 | spin_lock_bh(&ar->data_lock); | |
16735d02 | 3786 | reinit_completion(&ar->offchan_tx_completed); |
5e3dd157 KV |
3787 | ar->offchan_tx_skb = skb; |
3788 | spin_unlock_bh(&ar->data_lock); | |
3789 | ||
8a933964 MK |
3790 | /* It's safe to access vif and sta - conf_mutex guarantees that |
3791 | * sta_state() and remove_interface() are locked exclusively | |
3792 | * out wrt to this offchannel worker. | |
3793 | */ | |
3794 | arvif = ath10k_get_arvif(ar, vdev_id); | |
3795 | if (arvif) { | |
3796 | vif = arvif->vif; | |
3797 | sta = ieee80211_find_sta(vif, peer_addr); | |
3798 | } else { | |
3799 | vif = NULL; | |
3800 | sta = NULL; | |
3801 | } | |
3802 | ||
3803 | txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb); | |
6421969f | 3804 | txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode); |
8a933964 | 3805 | |
a7773b5d | 3806 | ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb); |
f2f6ecab MK |
3807 | if (ret) { |
3808 | ath10k_warn(ar, "failed to transmit offchannel frame: %d\n", | |
3809 | ret); | |
3810 | /* not serious */ | |
3811 | } | |
5e3dd157 | 3812 | |
8e9904f5 NMG |
3813 | time_left = |
3814 | wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ); | |
3815 | if (time_left == 0) | |
75b34800 | 3816 | ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n", |
5e3dd157 KV |
3817 | skb); |
3818 | ||
adaeed74 | 3819 | if (!peer && tmp_peer_created) { |
5e3dd157 KV |
3820 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); |
3821 | if (ret) | |
7aa7a72a | 3822 | ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n", |
5e3dd157 KV |
3823 | peer_addr, vdev_id, ret); |
3824 | } | |
3825 | ||
3826 | mutex_unlock(&ar->conf_mutex); | |
3827 | } | |
3828 | } | |
3829 | ||
5e00d31a BM |
3830 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
3831 | { | |
3832 | struct sk_buff *skb; | |
3833 | ||
3834 | for (;;) { | |
3835 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); | |
3836 | if (!skb) | |
3837 | break; | |
3838 | ||
3839 | ieee80211_free_txskb(ar->hw, skb); | |
3840 | } | |
3841 | } | |
3842 | ||
3843 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) | |
3844 | { | |
3845 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); | |
3846 | struct sk_buff *skb; | |
38a1390e | 3847 | dma_addr_t paddr; |
5e00d31a BM |
3848 | int ret; |
3849 | ||
3850 | for (;;) { | |
3851 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); | |
3852 | if (!skb) | |
3853 | break; | |
3854 | ||
38a1390e RP |
3855 | if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF, |
3856 | ar->running_fw->fw_file.fw_features)) { | |
3857 | paddr = dma_map_single(ar->dev, skb->data, | |
3858 | skb->len, DMA_TO_DEVICE); | |
3859 | if (!paddr) | |
3860 | continue; | |
3861 | ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr); | |
3862 | if (ret) { | |
3863 | ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n", | |
3864 | ret); | |
3865 | dma_unmap_single(ar->dev, paddr, skb->len, | |
3866 | DMA_FROM_DEVICE); | |
3867 | ieee80211_free_txskb(ar->hw, skb); | |
3868 | } | |
3869 | } else { | |
3870 | ret = ath10k_wmi_mgmt_tx(ar, skb); | |
3871 | if (ret) { | |
3872 | ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n", | |
3873 | ret); | |
3874 | ieee80211_free_txskb(ar->hw, skb); | |
3875 | } | |
5fb5e41f | 3876 | } |
5e00d31a BM |
3877 | } |
3878 | } | |
3879 | ||
29946878 MK |
3880 | static void ath10k_mac_txq_init(struct ieee80211_txq *txq) |
3881 | { | |
a66cd733 | 3882 | struct ath10k_txq *artxq; |
29946878 MK |
3883 | |
3884 | if (!txq) | |
3885 | return; | |
3886 | ||
a66cd733 | 3887 | artxq = (void *)txq->drv_priv; |
29946878 MK |
3888 | INIT_LIST_HEAD(&artxq->list); |
3889 | } | |
3890 | ||
3891 | static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq) | |
3892 | { | |
a66cd733 | 3893 | struct ath10k_txq *artxq; |
dd4717b6 MK |
3894 | struct ath10k_skb_cb *cb; |
3895 | struct sk_buff *msdu; | |
3896 | int msdu_id; | |
29946878 MK |
3897 | |
3898 | if (!txq) | |
3899 | return; | |
3900 | ||
a66cd733 | 3901 | artxq = (void *)txq->drv_priv; |
29946878 MK |
3902 | spin_lock_bh(&ar->txqs_lock); |
3903 | if (!list_empty(&artxq->list)) | |
3904 | list_del_init(&artxq->list); | |
3905 | spin_unlock_bh(&ar->txqs_lock); | |
dd4717b6 MK |
3906 | |
3907 | spin_lock_bh(&ar->htt.tx_lock); | |
3908 | idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) { | |
3909 | cb = ATH10K_SKB_CB(msdu); | |
3910 | if (cb->txq == txq) | |
3911 | cb->txq = NULL; | |
3912 | } | |
3913 | spin_unlock_bh(&ar->htt.tx_lock); | |
29946878 MK |
3914 | } |
3915 | ||
426e10ea MK |
3916 | struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar, |
3917 | u16 peer_id, | |
3918 | u8 tid) | |
3919 | { | |
3920 | struct ath10k_peer *peer; | |
3921 | ||
3922 | lockdep_assert_held(&ar->data_lock); | |
3923 | ||
3924 | peer = ar->peer_map[peer_id]; | |
3925 | if (!peer) | |
3926 | return NULL; | |
3927 | ||
0a744d92 MK |
3928 | if (peer->removed) |
3929 | return NULL; | |
3930 | ||
426e10ea MK |
3931 | if (peer->sta) |
3932 | return peer->sta->txq[tid]; | |
3933 | else if (peer->vif) | |
3934 | return peer->vif->txq; | |
3935 | else | |
3936 | return NULL; | |
3937 | } | |
3938 | ||
29946878 MK |
3939 | static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw, |
3940 | struct ieee80211_txq *txq) | |
3941 | { | |
426e10ea MK |
3942 | struct ath10k *ar = hw->priv; |
3943 | struct ath10k_txq *artxq = (void *)txq->drv_priv; | |
3944 | ||
3945 | /* No need to get locks */ | |
3946 | ||
3947 | if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH) | |
3948 | return true; | |
3949 | ||
3950 | if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed) | |
3951 | return true; | |
3952 | ||
3953 | if (artxq->num_fw_queued < artxq->num_push_allowed) | |
3954 | return true; | |
3955 | ||
3956 | return false; | |
29946878 MK |
3957 | } |
3958 | ||
426e10ea MK |
3959 | int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, |
3960 | struct ieee80211_txq *txq) | |
29946878 | 3961 | { |
29946878 MK |
3962 | struct ath10k *ar = hw->priv; |
3963 | struct ath10k_htt *htt = &ar->htt; | |
3cc0fef6 | 3964 | struct ath10k_txq *artxq = (void *)txq->drv_priv; |
29946878 MK |
3965 | struct ieee80211_vif *vif = txq->vif; |
3966 | struct ieee80211_sta *sta = txq->sta; | |
3967 | enum ath10k_hw_txrx_mode txmode; | |
3968 | enum ath10k_mac_tx_path txpath; | |
3969 | struct sk_buff *skb; | |
e4fd726f | 3970 | struct ieee80211_hdr *hdr; |
426e10ea | 3971 | size_t skb_len; |
e4fd726f | 3972 | bool is_mgmt, is_presp; |
29946878 MK |
3973 | int ret; |
3974 | ||
3975 | spin_lock_bh(&ar->htt.tx_lock); | |
cac08552 | 3976 | ret = ath10k_htt_tx_inc_pending(htt); |
29946878 MK |
3977 | spin_unlock_bh(&ar->htt.tx_lock); |
3978 | ||
3979 | if (ret) | |
3980 | return ret; | |
3981 | ||
3982 | skb = ieee80211_tx_dequeue(hw, txq); | |
3983 | if (!skb) { | |
3984 | spin_lock_bh(&ar->htt.tx_lock); | |
cac08552 | 3985 | ath10k_htt_tx_dec_pending(htt); |
29946878 MK |
3986 | spin_unlock_bh(&ar->htt.tx_lock); |
3987 | ||
3988 | return -ENOENT; | |
3989 | } | |
3990 | ||
dd4717b6 | 3991 | ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb); |
29946878 | 3992 | |
426e10ea | 3993 | skb_len = skb->len; |
29946878 MK |
3994 | txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb); |
3995 | txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode); | |
e4fd726f ARN |
3996 | is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT); |
3997 | ||
3998 | if (is_mgmt) { | |
3999 | hdr = (struct ieee80211_hdr *)skb->data; | |
4000 | is_presp = ieee80211_is_probe_resp(hdr->frame_control); | |
4001 | ||
4002 | spin_lock_bh(&ar->htt.tx_lock); | |
4003 | ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp); | |
4004 | ||
4005 | if (ret) { | |
4006 | ath10k_htt_tx_dec_pending(htt); | |
4007 | spin_unlock_bh(&ar->htt.tx_lock); | |
4008 | return ret; | |
4009 | } | |
4010 | spin_unlock_bh(&ar->htt.tx_lock); | |
4011 | } | |
29946878 | 4012 | |
a7773b5d | 4013 | ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb); |
29946878 MK |
4014 | if (unlikely(ret)) { |
4015 | ath10k_warn(ar, "failed to push frame: %d\n", ret); | |
4016 | ||
4017 | spin_lock_bh(&ar->htt.tx_lock); | |
cac08552 | 4018 | ath10k_htt_tx_dec_pending(htt); |
e4fd726f ARN |
4019 | if (is_mgmt) |
4020 | ath10k_htt_tx_mgmt_dec_pending(htt); | |
29946878 MK |
4021 | spin_unlock_bh(&ar->htt.tx_lock); |
4022 | ||
4023 | return ret; | |
4024 | } | |
4025 | ||
3cc0fef6 MK |
4026 | spin_lock_bh(&ar->htt.tx_lock); |
4027 | artxq->num_fw_queued++; | |
4028 | spin_unlock_bh(&ar->htt.tx_lock); | |
4029 | ||
426e10ea | 4030 | return skb_len; |
29946878 MK |
4031 | } |
4032 | ||
4033 | void ath10k_mac_tx_push_pending(struct ath10k *ar) | |
4034 | { | |
4035 | struct ieee80211_hw *hw = ar->hw; | |
4036 | struct ieee80211_txq *txq; | |
4037 | struct ath10k_txq *artxq; | |
4038 | struct ath10k_txq *last; | |
4039 | int ret; | |
4040 | int max; | |
4041 | ||
7a0adc83 MK |
4042 | if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2)) |
4043 | return; | |
4044 | ||
29946878 MK |
4045 | spin_lock_bh(&ar->txqs_lock); |
4046 | rcu_read_lock(); | |
4047 | ||
4048 | last = list_last_entry(&ar->txqs, struct ath10k_txq, list); | |
4049 | while (!list_empty(&ar->txqs)) { | |
4050 | artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list); | |
4051 | txq = container_of((void *)artxq, struct ieee80211_txq, | |
4052 | drv_priv); | |
4053 | ||
4054 | /* Prevent aggressive sta/tid taking over tx queue */ | |
e4568eac | 4055 | max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE; |
750eeed8 MK |
4056 | ret = 0; |
4057 | while (ath10k_mac_tx_can_push(hw, txq) && max--) { | |
29946878 MK |
4058 | ret = ath10k_mac_tx_push_txq(hw, txq); |
4059 | if (ret < 0) | |
4060 | break; | |
4061 | } | |
4062 | ||
4063 | list_del_init(&artxq->list); | |
9d71d47e MK |
4064 | if (ret != -ENOENT) |
4065 | list_add_tail(&artxq->list, &ar->txqs); | |
4066 | ||
c1a43d97 | 4067 | ath10k_htt_tx_txq_update(hw, txq); |
29946878 | 4068 | |
9d71d47e | 4069 | if (artxq == last || (ret < 0 && ret != -ENOENT)) |
29946878 | 4070 | break; |
29946878 MK |
4071 | } |
4072 | ||
4073 | rcu_read_unlock(); | |
4074 | spin_unlock_bh(&ar->txqs_lock); | |
4075 | } | |
3f04950f | 4076 | EXPORT_SYMBOL(ath10k_mac_tx_push_pending); |
29946878 | 4077 | |
5e3dd157 KV |
4078 | /************/ |
4079 | /* Scanning */ | |
4080 | /************/ | |
4081 | ||
5c81c7fd | 4082 | void __ath10k_scan_finish(struct ath10k *ar) |
5e3dd157 | 4083 | { |
5c81c7fd | 4084 | lockdep_assert_held(&ar->data_lock); |
5e3dd157 | 4085 | |
5c81c7fd MK |
4086 | switch (ar->scan.state) { |
4087 | case ATH10K_SCAN_IDLE: | |
4088 | break; | |
4089 | case ATH10K_SCAN_RUNNING: | |
7305d3e0 | 4090 | case ATH10K_SCAN_ABORTING: |
7947d3e0 AS |
4091 | if (!ar->scan.is_roc) { |
4092 | struct cfg80211_scan_info info = { | |
4093 | .aborted = (ar->scan.state == | |
4094 | ATH10K_SCAN_ABORTING), | |
4095 | }; | |
4096 | ||
4097 | ieee80211_scan_completed(ar->hw, &info); | |
4098 | } else if (ar->scan.roc_notify) { | |
d710e75d | 4099 | ieee80211_remain_on_channel_expired(ar->hw); |
7947d3e0 | 4100 | } |
5c81c7fd MK |
4101 | /* fall through */ |
4102 | case ATH10K_SCAN_STARTING: | |
4103 | ar->scan.state = ATH10K_SCAN_IDLE; | |
4104 | ar->scan_channel = NULL; | |
bd877440 | 4105 | ar->scan.roc_freq = 0; |
5c81c7fd MK |
4106 | ath10k_offchan_tx_purge(ar); |
4107 | cancel_delayed_work(&ar->scan.timeout); | |
881ed54e | 4108 | complete(&ar->scan.completed); |
5c81c7fd | 4109 | break; |
5e3dd157 | 4110 | } |
5c81c7fd | 4111 | } |
5e3dd157 | 4112 | |
5c81c7fd MK |
4113 | void ath10k_scan_finish(struct ath10k *ar) |
4114 | { | |
4115 | spin_lock_bh(&ar->data_lock); | |
4116 | __ath10k_scan_finish(ar); | |
5e3dd157 KV |
4117 | spin_unlock_bh(&ar->data_lock); |
4118 | } | |
4119 | ||
5c81c7fd | 4120 | static int ath10k_scan_stop(struct ath10k *ar) |
5e3dd157 KV |
4121 | { |
4122 | struct wmi_stop_scan_arg arg = { | |
4123 | .req_id = 1, /* FIXME */ | |
4124 | .req_type = WMI_SCAN_STOP_ONE, | |
4125 | .u.scan_id = ATH10K_SCAN_ID, | |
4126 | }; | |
4127 | int ret; | |
4128 | ||
4129 | lockdep_assert_held(&ar->conf_mutex); | |
4130 | ||
5e3dd157 KV |
4131 | ret = ath10k_wmi_stop_scan(ar, &arg); |
4132 | if (ret) { | |
7aa7a72a | 4133 | ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret); |
5c81c7fd | 4134 | goto out; |
5e3dd157 KV |
4135 | } |
4136 | ||
14e105cd | 4137 | ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); |
5c81c7fd | 4138 | if (ret == 0) { |
7aa7a72a | 4139 | ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n"); |
5c81c7fd MK |
4140 | ret = -ETIMEDOUT; |
4141 | } else if (ret > 0) { | |
4142 | ret = 0; | |
4143 | } | |
5e3dd157 | 4144 | |
5c81c7fd MK |
4145 | out: |
4146 | /* Scan state should be updated upon scan completion but in case | |
4147 | * firmware fails to deliver the event (for whatever reason) it is | |
4148 | * desired to clean up scan state anyway. Firmware may have just | |
4149 | * dropped the scan completion event delivery due to transport pipe | |
4150 | * being overflown with data and/or it can recover on its own before | |
4151 | * next scan request is submitted. | |
4152 | */ | |
4153 | spin_lock_bh(&ar->data_lock); | |
4154 | if (ar->scan.state != ATH10K_SCAN_IDLE) | |
4155 | __ath10k_scan_finish(ar); | |
4156 | spin_unlock_bh(&ar->data_lock); | |
4157 | ||
4158 | return ret; | |
4159 | } | |
4160 | ||
4161 | static void ath10k_scan_abort(struct ath10k *ar) | |
4162 | { | |
4163 | int ret; | |
4164 | ||
4165 | lockdep_assert_held(&ar->conf_mutex); | |
5e3dd157 KV |
4166 | |
4167 | spin_lock_bh(&ar->data_lock); | |
5c81c7fd MK |
4168 | |
4169 | switch (ar->scan.state) { | |
4170 | case ATH10K_SCAN_IDLE: | |
4171 | /* This can happen if timeout worker kicked in and called | |
4172 | * abortion while scan completion was being processed. | |
4173 | */ | |
4174 | break; | |
4175 | case ATH10K_SCAN_STARTING: | |
4176 | case ATH10K_SCAN_ABORTING: | |
7aa7a72a | 4177 | ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n", |
5c81c7fd MK |
4178 | ath10k_scan_state_str(ar->scan.state), |
4179 | ar->scan.state); | |
4180 | break; | |
4181 | case ATH10K_SCAN_RUNNING: | |
4182 | ar->scan.state = ATH10K_SCAN_ABORTING; | |
4183 | spin_unlock_bh(&ar->data_lock); | |
4184 | ||
4185 | ret = ath10k_scan_stop(ar); | |
4186 | if (ret) | |
7aa7a72a | 4187 | ath10k_warn(ar, "failed to abort scan: %d\n", ret); |
5c81c7fd MK |
4188 | |
4189 | spin_lock_bh(&ar->data_lock); | |
4190 | break; | |
5e3dd157 | 4191 | } |
5c81c7fd | 4192 | |
5e3dd157 | 4193 | spin_unlock_bh(&ar->data_lock); |
5c81c7fd | 4194 | } |
5e3dd157 | 4195 | |
5c81c7fd MK |
4196 | void ath10k_scan_timeout_work(struct work_struct *work) |
4197 | { | |
4198 | struct ath10k *ar = container_of(work, struct ath10k, | |
4199 | scan.timeout.work); | |
4200 | ||
4201 | mutex_lock(&ar->conf_mutex); | |
4202 | ath10k_scan_abort(ar); | |
4203 | mutex_unlock(&ar->conf_mutex); | |
5e3dd157 KV |
4204 | } |
4205 | ||
4206 | static int ath10k_start_scan(struct ath10k *ar, | |
4207 | const struct wmi_start_scan_arg *arg) | |
4208 | { | |
4209 | int ret; | |
4210 | ||
4211 | lockdep_assert_held(&ar->conf_mutex); | |
4212 | ||
4213 | ret = ath10k_wmi_start_scan(ar, arg); | |
4214 | if (ret) | |
4215 | return ret; | |
4216 | ||
14e105cd | 4217 | ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); |
5e3dd157 | 4218 | if (ret == 0) { |
5c81c7fd MK |
4219 | ret = ath10k_scan_stop(ar); |
4220 | if (ret) | |
7aa7a72a | 4221 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
5c81c7fd MK |
4222 | |
4223 | return -ETIMEDOUT; | |
5e3dd157 KV |
4224 | } |
4225 | ||
2f9eec0b BG |
4226 | /* If we failed to start the scan, return error code at |
4227 | * this point. This is probably due to some issue in the | |
4228 | * firmware, but no need to wedge the driver due to that... | |
4229 | */ | |
4230 | spin_lock_bh(&ar->data_lock); | |
4231 | if (ar->scan.state == ATH10K_SCAN_IDLE) { | |
4232 | spin_unlock_bh(&ar->data_lock); | |
4233 | return -EINVAL; | |
4234 | } | |
4235 | spin_unlock_bh(&ar->data_lock); | |
4236 | ||
5e3dd157 KV |
4237 | return 0; |
4238 | } | |
4239 | ||
4240 | /**********************/ | |
4241 | /* mac80211 callbacks */ | |
4242 | /**********************/ | |
4243 | ||
f2f6ecab MK |
4244 | static void ath10k_mac_op_tx(struct ieee80211_hw *hw, |
4245 | struct ieee80211_tx_control *control, | |
4246 | struct sk_buff *skb) | |
5e3dd157 | 4247 | { |
4b604558 | 4248 | struct ath10k *ar = hw->priv; |
6421969f | 4249 | struct ath10k_htt *htt = &ar->htt; |
5e3dd157 | 4250 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
4b604558 | 4251 | struct ieee80211_vif *vif = info->control.vif; |
75d85fd9 | 4252 | struct ieee80211_sta *sta = control->sta; |
dd4717b6 | 4253 | struct ieee80211_txq *txq = NULL; |
6421969f | 4254 | struct ieee80211_hdr *hdr = (void *)skb->data; |
8a933964 | 4255 | enum ath10k_hw_txrx_mode txmode; |
6421969f MK |
4256 | enum ath10k_mac_tx_path txpath; |
4257 | bool is_htt; | |
4258 | bool is_mgmt; | |
4259 | bool is_presp; | |
f2f6ecab | 4260 | int ret; |
5e3dd157 | 4261 | |
dd4717b6 | 4262 | ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb); |
5e3dd157 | 4263 | |
8a933964 | 4264 | txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb); |
6421969f MK |
4265 | txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode); |
4266 | is_htt = (txpath == ATH10K_MAC_TX_HTT || | |
4267 | txpath == ATH10K_MAC_TX_HTT_MGMT); | |
cac08552 | 4268 | is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT); |
5e3dd157 | 4269 | |
6421969f MK |
4270 | if (is_htt) { |
4271 | spin_lock_bh(&ar->htt.tx_lock); | |
6421969f MK |
4272 | is_presp = ieee80211_is_probe_resp(hdr->frame_control); |
4273 | ||
cac08552 | 4274 | ret = ath10k_htt_tx_inc_pending(htt); |
6421969f MK |
4275 | if (ret) { |
4276 | ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n", | |
4277 | ret); | |
4278 | spin_unlock_bh(&ar->htt.tx_lock); | |
4279 | ieee80211_free_txskb(ar->hw, skb); | |
4280 | return; | |
4281 | } | |
4282 | ||
cac08552 RM |
4283 | ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp); |
4284 | if (ret) { | |
dd7c280f RM |
4285 | ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n", |
4286 | ret); | |
cac08552 RM |
4287 | ath10k_htt_tx_dec_pending(htt); |
4288 | spin_unlock_bh(&ar->htt.tx_lock); | |
4289 | ieee80211_free_txskb(ar->hw, skb); | |
4290 | return; | |
4291 | } | |
6421969f MK |
4292 | spin_unlock_bh(&ar->htt.tx_lock); |
4293 | } | |
4294 | ||
a7773b5d | 4295 | ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb); |
6421969f | 4296 | if (ret) { |
f2f6ecab | 4297 | ath10k_warn(ar, "failed to transmit frame: %d\n", ret); |
6421969f MK |
4298 | if (is_htt) { |
4299 | spin_lock_bh(&ar->htt.tx_lock); | |
cac08552 RM |
4300 | ath10k_htt_tx_dec_pending(htt); |
4301 | if (is_mgmt) | |
4302 | ath10k_htt_tx_mgmt_dec_pending(htt); | |
6421969f MK |
4303 | spin_unlock_bh(&ar->htt.tx_lock); |
4304 | } | |
4305 | return; | |
4306 | } | |
5e3dd157 KV |
4307 | } |
4308 | ||
29946878 MK |
4309 | static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw, |
4310 | struct ieee80211_txq *txq) | |
4311 | { | |
4312 | struct ath10k *ar = hw->priv; | |
4313 | struct ath10k_txq *artxq = (void *)txq->drv_priv; | |
83e164b7 RM |
4314 | struct ieee80211_txq *f_txq; |
4315 | struct ath10k_txq *f_artxq; | |
4316 | int ret = 0; | |
e4568eac | 4317 | int max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE; |
29946878 | 4318 | |
750eeed8 MK |
4319 | spin_lock_bh(&ar->txqs_lock); |
4320 | if (list_empty(&artxq->list)) | |
4321 | list_add_tail(&artxq->list, &ar->txqs); | |
83e164b7 RM |
4322 | |
4323 | f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list); | |
4324 | f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv); | |
4325 | list_del_init(&f_artxq->list); | |
4326 | ||
4327 | while (ath10k_mac_tx_can_push(hw, f_txq) && max--) { | |
4328 | ret = ath10k_mac_tx_push_txq(hw, f_txq); | |
e3148cc5 | 4329 | if (ret < 0) |
83e164b7 RM |
4330 | break; |
4331 | } | |
4332 | if (ret != -ENOENT) | |
4333 | list_add_tail(&f_artxq->list, &ar->txqs); | |
750eeed8 | 4334 | spin_unlock_bh(&ar->txqs_lock); |
29946878 | 4335 | |
83e164b7 | 4336 | ath10k_htt_tx_txq_update(hw, f_txq); |
c1a43d97 | 4337 | ath10k_htt_tx_txq_update(hw, txq); |
29946878 MK |
4338 | } |
4339 | ||
bca7bafb | 4340 | /* Must not be called with conf_mutex held as workers can use that also. */ |
7962b0d8 | 4341 | void ath10k_drain_tx(struct ath10k *ar) |
bca7bafb MK |
4342 | { |
4343 | /* make sure rcu-protected mac80211 tx path itself is drained */ | |
4344 | synchronize_net(); | |
4345 | ||
4346 | ath10k_offchan_tx_purge(ar); | |
4347 | ath10k_mgmt_over_wmi_tx_purge(ar); | |
4348 | ||
4349 | cancel_work_sync(&ar->offchan_tx_work); | |
4350 | cancel_work_sync(&ar->wmi_mgmt_tx_work); | |
4351 | } | |
4352 | ||
affd3217 | 4353 | void ath10k_halt(struct ath10k *ar) |
818bdd16 | 4354 | { |
d9bc4b9b MK |
4355 | struct ath10k_vif *arvif; |
4356 | ||
818bdd16 MK |
4357 | lockdep_assert_held(&ar->conf_mutex); |
4358 | ||
1933747f MK |
4359 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
4360 | ar->filter_flags = 0; | |
4361 | ar->monitor = false; | |
500ff9f9 | 4362 | ar->monitor_arvif = NULL; |
1933747f MK |
4363 | |
4364 | if (ar->monitor_started) | |
1bbc0975 | 4365 | ath10k_monitor_stop(ar); |
1933747f MK |
4366 | |
4367 | ar->monitor_started = false; | |
96d828d4 | 4368 | ar->tx_paused = 0; |
1bbc0975 | 4369 | |
5c81c7fd | 4370 | ath10k_scan_finish(ar); |
818bdd16 | 4371 | ath10k_peer_cleanup_all(ar); |
6f6eb1bc | 4372 | ath10k_stop_radar_confirmation(ar); |
818bdd16 MK |
4373 | ath10k_core_stop(ar); |
4374 | ath10k_hif_power_down(ar); | |
4375 | ||
4376 | spin_lock_bh(&ar->data_lock); | |
64badcb6 MK |
4377 | list_for_each_entry(arvif, &ar->arvifs, list) |
4378 | ath10k_mac_vif_beacon_cleanup(arvif); | |
818bdd16 MK |
4379 | spin_unlock_bh(&ar->data_lock); |
4380 | } | |
4381 | ||
46acf7bb BG |
4382 | static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
4383 | { | |
4384 | struct ath10k *ar = hw->priv; | |
4385 | ||
4386 | mutex_lock(&ar->conf_mutex); | |
4387 | ||
166de3f1 RM |
4388 | *tx_ant = ar->cfg_tx_chainmask; |
4389 | *rx_ant = ar->cfg_rx_chainmask; | |
46acf7bb BG |
4390 | |
4391 | mutex_unlock(&ar->conf_mutex); | |
4392 | ||
4393 | return 0; | |
4394 | } | |
4395 | ||
5572a95b BG |
4396 | static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg) |
4397 | { | |
4398 | /* It is not clear that allowing gaps in chainmask | |
4399 | * is helpful. Probably it will not do what user | |
4400 | * is hoping for, so warn in that case. | |
4401 | */ | |
4402 | if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0) | |
4403 | return; | |
4404 | ||
4405 | ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n", | |
4406 | dbg, cm); | |
4407 | } | |
4408 | ||
f58512f3 RM |
4409 | static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar) |
4410 | { | |
4411 | int nsts = ar->vht_cap_info; | |
4412 | ||
4413 | nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
4414 | nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
4415 | ||
4416 | /* If firmware does not deliver to host number of space-time | |
4417 | * streams supported, assume it support up to 4 BF STS and return | |
4418 | * the value for VHT CAP: nsts-1) | |
4419 | */ | |
4420 | if (nsts == 0) | |
4421 | return 3; | |
4422 | ||
4423 | return nsts; | |
4424 | } | |
4425 | ||
4426 | static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar) | |
4427 | { | |
4428 | int sound_dim = ar->vht_cap_info; | |
4429 | ||
4430 | sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
4431 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
4432 | ||
4433 | /* If the sounding dimension is not advertised by the firmware, | |
4434 | * let's use a default value of 1 | |
4435 | */ | |
4436 | if (sound_dim == 0) | |
4437 | return 1; | |
4438 | ||
4439 | return sound_dim; | |
4440 | } | |
4441 | ||
4442 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) | |
4443 | { | |
4444 | struct ieee80211_sta_vht_cap vht_cap = {0}; | |
cc914a55 | 4445 | struct ath10k_hw_params *hw = &ar->hw_params; |
f58512f3 RM |
4446 | u16 mcs_map; |
4447 | u32 val; | |
4448 | int i; | |
4449 | ||
4450 | vht_cap.vht_supported = 1; | |
4451 | vht_cap.cap = ar->vht_cap_info; | |
4452 | ||
4453 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
4454 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { | |
4455 | val = ath10k_mac_get_vht_cap_bf_sts(ar); | |
4456 | val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
4457 | val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
4458 | ||
4459 | vht_cap.cap |= val; | |
4460 | } | |
4461 | ||
4462 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
4463 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { | |
4464 | val = ath10k_mac_get_vht_cap_bf_sound_dim(ar); | |
4465 | val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
4466 | val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
4467 | ||
4468 | vht_cap.cap |= val; | |
4469 | } | |
4470 | ||
bc1efd73 SG |
4471 | /* Currently the firmware seems to be buggy, don't enable 80+80 |
4472 | * mode until that's resolved. | |
4473 | */ | |
4474 | if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) && | |
e509e594 | 4475 | (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0) |
bc1efd73 SG |
4476 | vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
4477 | ||
f58512f3 RM |
4478 | mcs_map = 0; |
4479 | for (i = 0; i < 8; i++) { | |
4480 | if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i))) | |
4481 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
4482 | else | |
4483 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
4484 | } | |
4485 | ||
34663241 MSS |
4486 | if (ar->cfg_tx_chainmask <= 1) |
4487 | vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; | |
4488 | ||
f58512f3 RM |
4489 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
4490 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); | |
4491 | ||
cc914a55 BG |
4492 | /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do |
4493 | * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give | |
4494 | * user-space a clue if that is the case. | |
4495 | */ | |
4496 | if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) && | |
4497 | (hw->vht160_mcs_rx_highest != 0 || | |
4498 | hw->vht160_mcs_tx_highest != 0)) { | |
4499 | vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest); | |
4500 | vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest); | |
4501 | } | |
4502 | ||
f58512f3 RM |
4503 | return vht_cap; |
4504 | } | |
4505 | ||
4506 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) | |
4507 | { | |
4508 | int i; | |
4509 | struct ieee80211_sta_ht_cap ht_cap = {0}; | |
4510 | ||
4511 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) | |
4512 | return ht_cap; | |
4513 | ||
4514 | ht_cap.ht_supported = 1; | |
4515 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
4516 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; | |
4517 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
4518 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
e33a99e2 PO |
4519 | ht_cap.cap |= |
4520 | WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT; | |
f58512f3 RM |
4521 | |
4522 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) | |
4523 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
4524 | ||
4525 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) | |
4526 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
4527 | ||
4528 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { | |
4529 | u32 smps; | |
4530 | ||
4531 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | |
4532 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
4533 | ||
4534 | ht_cap.cap |= smps; | |
4535 | } | |
4536 | ||
34663241 | 4537 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1)) |
f58512f3 RM |
4538 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
4539 | ||
4540 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { | |
4541 | u32 stbc; | |
4542 | ||
4543 | stbc = ar->ht_cap_info; | |
4544 | stbc &= WMI_HT_CAP_RX_STBC; | |
4545 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; | |
4546 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
4547 | stbc &= IEEE80211_HT_CAP_RX_STBC; | |
4548 | ||
4549 | ht_cap.cap |= stbc; | |
4550 | } | |
4551 | ||
4552 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC) | |
4553 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; | |
4554 | ||
4555 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) | |
4556 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; | |
4557 | ||
4558 | /* max AMSDU is implicitly taken from vht_cap_info */ | |
4559 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) | |
4560 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; | |
4561 | ||
4562 | for (i = 0; i < ar->num_rf_chains; i++) { | |
4563 | if (ar->cfg_rx_chainmask & BIT(i)) | |
4564 | ht_cap.mcs.rx_mask[i] = 0xFF; | |
4565 | } | |
4566 | ||
4567 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; | |
4568 | ||
4569 | return ht_cap; | |
4570 | } | |
4571 | ||
5036fe0f RM |
4572 | static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar) |
4573 | { | |
4574 | struct ieee80211_supported_band *band; | |
4575 | struct ieee80211_sta_vht_cap vht_cap; | |
4576 | struct ieee80211_sta_ht_cap ht_cap; | |
4577 | ||
4578 | ht_cap = ath10k_get_ht_cap(ar); | |
4579 | vht_cap = ath10k_create_vht_cap(ar); | |
4580 | ||
4581 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { | |
57fbcce3 | 4582 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
5036fe0f | 4583 | band->ht_cap = ht_cap; |
5036fe0f RM |
4584 | } |
4585 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { | |
57fbcce3 | 4586 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; |
5036fe0f RM |
4587 | band->ht_cap = ht_cap; |
4588 | band->vht_cap = vht_cap; | |
4589 | } | |
4590 | } | |
4591 | ||
46acf7bb BG |
4592 | static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant) |
4593 | { | |
4594 | int ret; | |
4595 | ||
4596 | lockdep_assert_held(&ar->conf_mutex); | |
4597 | ||
5572a95b BG |
4598 | ath10k_check_chain_mask(ar, tx_ant, "tx"); |
4599 | ath10k_check_chain_mask(ar, rx_ant, "rx"); | |
4600 | ||
46acf7bb BG |
4601 | ar->cfg_tx_chainmask = tx_ant; |
4602 | ar->cfg_rx_chainmask = rx_ant; | |
4603 | ||
4604 | if ((ar->state != ATH10K_STATE_ON) && | |
4605 | (ar->state != ATH10K_STATE_RESTARTED)) | |
4606 | return 0; | |
4607 | ||
4608 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask, | |
4609 | tx_ant); | |
4610 | if (ret) { | |
7aa7a72a | 4611 | ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n", |
46acf7bb BG |
4612 | ret, tx_ant); |
4613 | return ret; | |
4614 | } | |
4615 | ||
4616 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask, | |
4617 | rx_ant); | |
4618 | if (ret) { | |
7aa7a72a | 4619 | ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n", |
46acf7bb BG |
4620 | ret, rx_ant); |
4621 | return ret; | |
4622 | } | |
4623 | ||
5036fe0f RM |
4624 | /* Reload HT/VHT capability */ |
4625 | ath10k_mac_setup_ht_vht_cap(ar); | |
4626 | ||
46acf7bb BG |
4627 | return 0; |
4628 | } | |
4629 | ||
4630 | static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) | |
4631 | { | |
4632 | struct ath10k *ar = hw->priv; | |
4633 | int ret; | |
4634 | ||
4635 | mutex_lock(&ar->conf_mutex); | |
4636 | ret = __ath10k_set_antenna(ar, tx_ant, rx_ant); | |
4637 | mutex_unlock(&ar->conf_mutex); | |
4638 | return ret; | |
4639 | } | |
4640 | ||
84758d4d BP |
4641 | static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar, |
4642 | struct wmi_bb_timing_cfg_arg *bb_timing) | |
4643 | { | |
4644 | struct device_node *node; | |
4645 | const char *fem_name; | |
4646 | int ret; | |
4647 | ||
4648 | node = ar->dev->of_node; | |
4649 | if (!node) | |
4650 | return -ENOENT; | |
4651 | ||
4652 | ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name); | |
4653 | if (ret) | |
4654 | return -ENOENT; | |
4655 | ||
4656 | /* | |
4657 | * If external Front End module used in hardware, then default base band timing | |
4658 | * parameter cannot be used since they were fine tuned for reference hardware, | |
4659 | * so choosing different value suitable for that external FEM. | |
4660 | */ | |
4661 | if (!strcmp("microsemi-lx5586", fem_name)) { | |
4662 | bb_timing->bb_tx_timing = 0x00; | |
4663 | bb_timing->bb_xpa_timing = 0x0101; | |
4664 | } else { | |
4665 | return -ENOENT; | |
4666 | } | |
4667 | ||
4668 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n", | |
4669 | bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing); | |
4670 | return 0; | |
4671 | } | |
4672 | ||
5e3dd157 KV |
4673 | static int ath10k_start(struct ieee80211_hw *hw) |
4674 | { | |
4675 | struct ath10k *ar = hw->priv; | |
1fe374f5 | 4676 | u32 param; |
818bdd16 | 4677 | int ret = 0; |
84758d4d | 4678 | struct wmi_bb_timing_cfg_arg bb_timing = {0}; |
5e3dd157 | 4679 | |
bca7bafb MK |
4680 | /* |
4681 | * This makes sense only when restarting hw. It is harmless to call | |
6dfdbfc7 | 4682 | * unconditionally. This is necessary to make sure no HTT/WMI tx |
bca7bafb MK |
4683 | * commands will be submitted while restarting. |
4684 | */ | |
4685 | ath10k_drain_tx(ar); | |
4686 | ||
548db54c MK |
4687 | mutex_lock(&ar->conf_mutex); |
4688 | ||
c5058f5b MK |
4689 | switch (ar->state) { |
4690 | case ATH10K_STATE_OFF: | |
4691 | ar->state = ATH10K_STATE_ON; | |
4692 | break; | |
4693 | case ATH10K_STATE_RESTARTING: | |
c5058f5b MK |
4694 | ar->state = ATH10K_STATE_RESTARTED; |
4695 | break; | |
4696 | case ATH10K_STATE_ON: | |
4697 | case ATH10K_STATE_RESTARTED: | |
4698 | case ATH10K_STATE_WEDGED: | |
4699 | WARN_ON(1); | |
818bdd16 | 4700 | ret = -EINVAL; |
ae254433 | 4701 | goto err; |
43d2a30f KV |
4702 | case ATH10K_STATE_UTF: |
4703 | ret = -EBUSY; | |
4704 | goto err; | |
818bdd16 MK |
4705 | } |
4706 | ||
4707 | ret = ath10k_hif_power_up(ar); | |
4708 | if (ret) { | |
7aa7a72a | 4709 | ath10k_err(ar, "Could not init hif: %d\n", ret); |
ae254433 | 4710 | goto err_off; |
818bdd16 MK |
4711 | } |
4712 | ||
7ebf721d KV |
4713 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL, |
4714 | &ar->normal_mode_fw); | |
818bdd16 | 4715 | if (ret) { |
7aa7a72a | 4716 | ath10k_err(ar, "Could not init core: %d\n", ret); |
ae254433 | 4717 | goto err_power_down; |
818bdd16 MK |
4718 | } |
4719 | ||
1fe374f5 MSS |
4720 | param = ar->wmi.pdev_param->pmf_qos; |
4721 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); | |
ae254433 | 4722 | if (ret) { |
7aa7a72a | 4723 | ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret); |
ae254433 MK |
4724 | goto err_core_stop; |
4725 | } | |
5e3dd157 | 4726 | |
1fe374f5 MSS |
4727 | param = ar->wmi.pdev_param->dynamic_bw; |
4728 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); | |
ae254433 | 4729 | if (ret) { |
7aa7a72a | 4730 | ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret); |
ae254433 MK |
4731 | goto err_core_stop; |
4732 | } | |
5e3dd157 | 4733 | |
f1157695 RP |
4734 | if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) { |
4735 | ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr); | |
4736 | if (ret) { | |
4737 | ath10k_err(ar, "failed to set prob req oui: %i\n", ret); | |
4738 | goto err_core_stop; | |
4739 | } | |
4740 | } | |
4741 | ||
cf32784c MK |
4742 | if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) { |
4743 | ret = ath10k_wmi_adaptive_qcs(ar, true); | |
4744 | if (ret) { | |
4745 | ath10k_warn(ar, "failed to enable adaptive qcs: %d\n", | |
4746 | ret); | |
4747 | goto err_core_stop; | |
4748 | } | |
4749 | } | |
4750 | ||
24ab13ef | 4751 | if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) { |
1fe374f5 MSS |
4752 | param = ar->wmi.pdev_param->burst_enable; |
4753 | ret = ath10k_wmi_pdev_set_param(ar, param, 0); | |
24ab13ef JD |
4754 | if (ret) { |
4755 | ath10k_warn(ar, "failed to disable burst: %d\n", ret); | |
4756 | goto err_core_stop; | |
4757 | } | |
4758 | } | |
4759 | ||
d5cded16 GS |
4760 | param = ar->wmi.pdev_param->idle_ps_config; |
4761 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); | |
4762 | if (ret && ret != -EOPNOTSUPP) { | |
4763 | ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret); | |
4764 | goto err_core_stop; | |
4765 | } | |
4766 | ||
166de3f1 | 4767 | __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); |
46acf7bb | 4768 | |
ab6258ed MP |
4769 | /* |
4770 | * By default FW set ARP frames ac to voice (6). In that case ARP | |
4771 | * exchange is not working properly for UAPSD enabled AP. ARP requests | |
4772 | * which arrives with access category 0 are processed by network stack | |
4773 | * and send back with access category 0, but FW changes access category | |
4774 | * to 6. Set ARP frames access category to best effort (0) solves | |
4775 | * this problem. | |
4776 | */ | |
4777 | ||
1fe374f5 MSS |
4778 | param = ar->wmi.pdev_param->arp_ac_override; |
4779 | ret = ath10k_wmi_pdev_set_param(ar, param, 0); | |
ab6258ed | 4780 | if (ret) { |
7aa7a72a | 4781 | ath10k_warn(ar, "failed to set arp ac override parameter: %d\n", |
ab6258ed | 4782 | ret); |
ae254433 | 4783 | goto err_core_stop; |
ab6258ed MP |
4784 | } |
4785 | ||
62f77f09 | 4786 | if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA, |
c4cdf753 | 4787 | ar->running_fw->fw_file.fw_features)) { |
62f77f09 M |
4788 | ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1, |
4789 | WMI_CCA_DETECT_LEVEL_AUTO, | |
4790 | WMI_CCA_DETECT_MARGIN_AUTO); | |
4791 | if (ret) { | |
4792 | ath10k_warn(ar, "failed to enable adaptive cca: %d\n", | |
4793 | ret); | |
4794 | goto err_core_stop; | |
4795 | } | |
4796 | } | |
4797 | ||
1fe374f5 MSS |
4798 | param = ar->wmi.pdev_param->ani_enable; |
4799 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); | |
575f1c3d ARN |
4800 | if (ret) { |
4801 | ath10k_warn(ar, "failed to enable ani by default: %d\n", | |
4802 | ret); | |
4803 | goto err_core_stop; | |
4804 | } | |
4805 | ||
b3e71d7a ARN |
4806 | ar->ani_enabled = true; |
4807 | ||
cc61a1bb | 4808 | if (ath10k_peer_stats_enabled(ar)) { |
8351c052 MSS |
4809 | param = ar->wmi.pdev_param->peer_stats_update_period; |
4810 | ret = ath10k_wmi_pdev_set_param(ar, param, | |
4811 | PEER_DEFAULT_STATS_UPDATE_PERIOD); | |
4812 | if (ret) { | |
4813 | ath10k_warn(ar, | |
4814 | "failed to set peer stats period : %d\n", | |
4815 | ret); | |
4816 | goto err_core_stop; | |
4817 | } | |
4818 | } | |
4819 | ||
39136248 RM |
4820 | param = ar->wmi.pdev_param->enable_btcoex; |
4821 | if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) && | |
4822 | test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM, | |
4823 | ar->running_fw->fw_file.fw_features)) { | |
4824 | ret = ath10k_wmi_pdev_set_param(ar, param, 0); | |
4825 | if (ret) { | |
4826 | ath10k_warn(ar, | |
4827 | "failed to set btcoex param: %d\n", ret); | |
4828 | goto err_core_stop; | |
4829 | } | |
4830 | clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); | |
4831 | } | |
4832 | ||
84758d4d BP |
4833 | if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) { |
4834 | ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing); | |
4835 | if (!ret) { | |
4836 | ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing); | |
4837 | if (ret) { | |
4838 | ath10k_warn(ar, | |
4839 | "failed to set bb timings: %d\n", | |
4840 | ret); | |
4841 | goto err_core_stop; | |
4842 | } | |
4843 | } | |
4844 | } | |
4845 | ||
d650097b | 4846 | ar->num_started_vdevs = 0; |
f7843d7f MK |
4847 | ath10k_regd_update(ar); |
4848 | ||
855aed12 | 4849 | ath10k_spectral_start(ar); |
8515b5c7 | 4850 | ath10k_thermal_set_throttling(ar); |
855aed12 | 4851 | |
6f6eb1bc S |
4852 | ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE; |
4853 | ||
ae254433 MK |
4854 | mutex_unlock(&ar->conf_mutex); |
4855 | return 0; | |
4856 | ||
4857 | err_core_stop: | |
4858 | ath10k_core_stop(ar); | |
4859 | ||
4860 | err_power_down: | |
4861 | ath10k_hif_power_down(ar); | |
4862 | ||
4863 | err_off: | |
4864 | ar->state = ATH10K_STATE_OFF; | |
4865 | ||
4866 | err: | |
548db54c | 4867 | mutex_unlock(&ar->conf_mutex); |
c60bdd83 | 4868 | return ret; |
5e3dd157 KV |
4869 | } |
4870 | ||
4871 | static void ath10k_stop(struct ieee80211_hw *hw) | |
4872 | { | |
4873 | struct ath10k *ar = hw->priv; | |
4874 | ||
bca7bafb MK |
4875 | ath10k_drain_tx(ar); |
4876 | ||
548db54c | 4877 | mutex_lock(&ar->conf_mutex); |
c5058f5b | 4878 | if (ar->state != ATH10K_STATE_OFF) { |
818bdd16 | 4879 | ath10k_halt(ar); |
c5058f5b MK |
4880 | ar->state = ATH10K_STATE_OFF; |
4881 | } | |
548db54c MK |
4882 | mutex_unlock(&ar->conf_mutex); |
4883 | ||
d94475c2 | 4884 | cancel_work_sync(&ar->set_coverage_class_work); |
5c81c7fd | 4885 | cancel_delayed_work_sync(&ar->scan.timeout); |
affd3217 | 4886 | cancel_work_sync(&ar->restart_work); |
5e3dd157 KV |
4887 | } |
4888 | ||
ad088bfa | 4889 | static int ath10k_config_ps(struct ath10k *ar) |
5e3dd157 | 4890 | { |
ad088bfa MK |
4891 | struct ath10k_vif *arvif; |
4892 | int ret = 0; | |
affd3217 MK |
4893 | |
4894 | lockdep_assert_held(&ar->conf_mutex); | |
4895 | ||
ad088bfa MK |
4896 | list_for_each_entry(arvif, &ar->arvifs, list) { |
4897 | ret = ath10k_mac_vif_setup_ps(arvif); | |
4898 | if (ret) { | |
7aa7a72a | 4899 | ath10k_warn(ar, "failed to setup powersave: %d\n", ret); |
ad088bfa MK |
4900 | break; |
4901 | } | |
4902 | } | |
affd3217 | 4903 | |
ad088bfa | 4904 | return ret; |
affd3217 MK |
4905 | } |
4906 | ||
7d9d5587 MK |
4907 | static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower) |
4908 | { | |
4909 | int ret; | |
4910 | u32 param; | |
4911 | ||
4912 | lockdep_assert_held(&ar->conf_mutex); | |
4913 | ||
4914 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower); | |
4915 | ||
4916 | param = ar->wmi.pdev_param->txpower_limit2g; | |
4917 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); | |
4918 | if (ret) { | |
4919 | ath10k_warn(ar, "failed to set 2g txpower %d: %d\n", | |
4920 | txpower, ret); | |
4921 | return ret; | |
4922 | } | |
4923 | ||
4924 | param = ar->wmi.pdev_param->txpower_limit5g; | |
4925 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); | |
4926 | if (ret) { | |
4927 | ath10k_warn(ar, "failed to set 5g txpower %d: %d\n", | |
4928 | txpower, ret); | |
4929 | return ret; | |
4930 | } | |
4931 | ||
4932 | return 0; | |
4933 | } | |
4934 | ||
4935 | static int ath10k_mac_txpower_recalc(struct ath10k *ar) | |
4936 | { | |
4937 | struct ath10k_vif *arvif; | |
4938 | int ret, txpower = -1; | |
4939 | ||
4940 | lockdep_assert_held(&ar->conf_mutex); | |
4941 | ||
4942 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
88407beb RH |
4943 | if (arvif->txpower <= 0) |
4944 | continue; | |
7d9d5587 MK |
4945 | |
4946 | if (txpower == -1) | |
4947 | txpower = arvif->txpower; | |
4948 | else | |
4949 | txpower = min(txpower, arvif->txpower); | |
4950 | } | |
4951 | ||
88407beb RH |
4952 | if (txpower == -1) |
4953 | return 0; | |
7d9d5587 MK |
4954 | |
4955 | ret = ath10k_mac_txpower_setup(ar, txpower); | |
4956 | if (ret) { | |
4957 | ath10k_warn(ar, "failed to setup tx power %d: %d\n", | |
4958 | txpower, ret); | |
4959 | return ret; | |
4960 | } | |
4961 | ||
4962 | return 0; | |
4963 | } | |
4964 | ||
affd3217 MK |
4965 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
4966 | { | |
5e3dd157 KV |
4967 | struct ath10k *ar = hw->priv; |
4968 | struct ieee80211_conf *conf = &hw->conf; | |
4969 | int ret = 0; | |
5e3dd157 KV |
4970 | |
4971 | mutex_lock(&ar->conf_mutex); | |
4972 | ||
affd3217 MK |
4973 | if (changed & IEEE80211_CONF_CHANGE_PS) |
4974 | ath10k_config_ps(ar); | |
5e3dd157 KV |
4975 | |
4976 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { | |
1933747f MK |
4977 | ar->monitor = conf->flags & IEEE80211_CONF_MONITOR; |
4978 | ret = ath10k_monitor_recalc(ar); | |
4979 | if (ret) | |
4980 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); | |
5e3dd157 KV |
4981 | } |
4982 | ||
4983 | mutex_unlock(&ar->conf_mutex); | |
4984 | return ret; | |
4985 | } | |
4986 | ||
5572a95b BG |
4987 | static u32 get_nss_from_chainmask(u16 chain_mask) |
4988 | { | |
f680f70a | 4989 | if ((chain_mask & 0xf) == 0xf) |
5572a95b BG |
4990 | return 4; |
4991 | else if ((chain_mask & 0x7) == 0x7) | |
4992 | return 3; | |
4993 | else if ((chain_mask & 0x3) == 0x3) | |
4994 | return 2; | |
4995 | return 1; | |
4996 | } | |
4997 | ||
a48e2cc8 VN |
4998 | static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif) |
4999 | { | |
5000 | u32 value = 0; | |
5001 | struct ath10k *ar = arvif->ar; | |
707a0c81 | 5002 | int nsts; |
0c6d6f26 | 5003 | int sound_dim; |
a48e2cc8 VN |
5004 | |
5005 | if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC) | |
5006 | return 0; | |
5007 | ||
707a0c81 | 5008 | nsts = ath10k_mac_get_vht_cap_bf_sts(ar); |
a48e2cc8 VN |
5009 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
5010 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) | |
707a0c81 | 5011 | value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); |
a48e2cc8 | 5012 | |
0c6d6f26 | 5013 | sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar); |
a48e2cc8 VN |
5014 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
5015 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) | |
0c6d6f26 | 5016 | value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); |
a48e2cc8 VN |
5017 | |
5018 | if (!value) | |
5019 | return 0; | |
5020 | ||
5021 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) | |
5022 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
5023 | ||
5024 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) | |
5025 | value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER | | |
5026 | WMI_VDEV_PARAM_TXBF_SU_TX_BFER); | |
5027 | ||
5028 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) | |
5029 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
5030 | ||
5031 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) | |
5032 | value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE | | |
5033 | WMI_VDEV_PARAM_TXBF_SU_TX_BFEE); | |
5034 | ||
5035 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | |
5036 | ar->wmi.vdev_param->txbf, value); | |
5037 | } | |
5038 | ||
5e3dd157 KV |
5039 | /* |
5040 | * TODO: | |
5041 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, | |
5042 | * because we will send mgmt frames without CCK. This requirement | |
5043 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag | |
5044 | * in the TX packet. | |
5045 | */ | |
5046 | static int ath10k_add_interface(struct ieee80211_hw *hw, | |
5047 | struct ieee80211_vif *vif) | |
5048 | { | |
5049 | struct ath10k *ar = hw->priv; | |
56ac13bf | 5050 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
bb8f0c6a | 5051 | struct ath10k_peer *peer; |
5e3dd157 KV |
5052 | enum wmi_sta_powersave_param param; |
5053 | int ret = 0; | |
5a13e76e | 5054 | u32 value; |
5e3dd157 | 5055 | int bit; |
96d828d4 | 5056 | int i; |
6d1506e7 | 5057 | u32 vdev_param; |
5e3dd157 | 5058 | |
848955cc JB |
5059 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
5060 | ||
5e3dd157 KV |
5061 | mutex_lock(&ar->conf_mutex); |
5062 | ||
0dbd09e6 | 5063 | memset(arvif, 0, sizeof(*arvif)); |
29946878 | 5064 | ath10k_mac_txq_init(vif->txq); |
0dbd09e6 | 5065 | |
5e3dd157 KV |
5066 | arvif->ar = ar; |
5067 | arvif->vif = vif; | |
5068 | ||
e63b33f3 | 5069 | INIT_LIST_HEAD(&arvif->list); |
81a9a17d | 5070 | INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work); |
cc9904e6 MK |
5071 | INIT_DELAYED_WORK(&arvif->connection_loss_work, |
5072 | ath10k_mac_vif_sta_connection_loss_work); | |
cc4827b9 | 5073 | |
45c9abc0 MK |
5074 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { |
5075 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; | |
5076 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, | |
5077 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); | |
5078 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, | |
5079 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); | |
5080 | } | |
cc4827b9 | 5081 | |
e04cafbc MK |
5082 | if (ar->num_peers >= ar->max_num_peers) { |
5083 | ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n"); | |
503422d9 MK |
5084 | ret = -ENOBUFS; |
5085 | goto err; | |
e04cafbc MK |
5086 | } |
5087 | ||
a9aefb3b | 5088 | if (ar->free_vdev_map == 0) { |
7aa7a72a | 5089 | ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n"); |
5e3dd157 | 5090 | ret = -EBUSY; |
9dad14ae | 5091 | goto err; |
5e3dd157 | 5092 | } |
16c11176 | 5093 | bit = __ffs64(ar->free_vdev_map); |
5e3dd157 | 5094 | |
16c11176 BG |
5095 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n", |
5096 | bit, ar->free_vdev_map); | |
5e3dd157 | 5097 | |
16c11176 | 5098 | arvif->vdev_id = bit; |
6e4de1a4 PO |
5099 | arvif->vdev_subtype = |
5100 | ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE); | |
5e3dd157 | 5101 | |
5e3dd157 | 5102 | switch (vif->type) { |
75d2bd48 MK |
5103 | case NL80211_IFTYPE_P2P_DEVICE: |
5104 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
6e4de1a4 PO |
5105 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
5106 | (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE); | |
75d2bd48 | 5107 | break; |
5e3dd157 KV |
5108 | case NL80211_IFTYPE_UNSPECIFIED: |
5109 | case NL80211_IFTYPE_STATION: | |
5110 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
5111 | if (vif->p2p) | |
6e4de1a4 PO |
5112 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
5113 | (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT); | |
5e3dd157 KV |
5114 | break; |
5115 | case NL80211_IFTYPE_ADHOC: | |
5116 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; | |
5117 | break; | |
b6c7bafa | 5118 | case NL80211_IFTYPE_MESH_POINT: |
0b3d76e9 | 5119 | if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) { |
6e4de1a4 PO |
5120 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
5121 | (ar, WMI_VDEV_SUBTYPE_MESH_11S); | |
bb58b89c | 5122 | } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
b6c7bafa BC |
5123 | ret = -EINVAL; |
5124 | ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n"); | |
5125 | goto err; | |
5126 | } | |
5127 | arvif->vdev_type = WMI_VDEV_TYPE_AP; | |
5128 | break; | |
5e3dd157 KV |
5129 | case NL80211_IFTYPE_AP: |
5130 | arvif->vdev_type = WMI_VDEV_TYPE_AP; | |
5131 | ||
5132 | if (vif->p2p) | |
6e4de1a4 PO |
5133 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
5134 | (ar, WMI_VDEV_SUBTYPE_P2P_GO); | |
5e3dd157 KV |
5135 | break; |
5136 | case NL80211_IFTYPE_MONITOR: | |
5137 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; | |
5138 | break; | |
5139 | default: | |
5140 | WARN_ON(1); | |
5141 | break; | |
5142 | } | |
5143 | ||
96d828d4 MK |
5144 | /* Using vdev_id as queue number will make it very easy to do per-vif |
5145 | * tx queue locking. This shouldn't wrap due to interface combinations | |
5146 | * but do a modulo for correctness sake and prevent using offchannel tx | |
5147 | * queues for regular vif tx. | |
5148 | */ | |
5149 | vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1); | |
5150 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) | |
5151 | vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1); | |
5152 | ||
64badcb6 MK |
5153 | /* Some firmware revisions don't wait for beacon tx completion before |
5154 | * sending another SWBA event. This could lead to hardware using old | |
5155 | * (freed) beacon data in some cases, e.g. tx credit starvation | |
5156 | * combined with missed TBTT. This is very very rare. | |
5157 | * | |
5158 | * On non-IOMMU-enabled hosts this could be a possible security issue | |
5159 | * because hw could beacon some random data on the air. On | |
5160 | * IOMMU-enabled hosts DMAR faults would occur in most cases and target | |
5161 | * device would crash. | |
5162 | * | |
5163 | * Since there are no beacon tx completions (implicit nor explicit) | |
5164 | * propagated to host the only workaround for this is to allocate a | |
5165 | * DMA-coherent buffer for a lifetime of a vif and use it for all | |
5166 | * beacon tx commands. Worst case for this approach is some beacons may | |
5167 | * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap. | |
5168 | */ | |
5169 | if (vif->type == NL80211_IFTYPE_ADHOC || | |
b6c7bafa | 5170 | vif->type == NL80211_IFTYPE_MESH_POINT || |
64badcb6 | 5171 | vif->type == NL80211_IFTYPE_AP) { |
750afb08 LC |
5172 | arvif->beacon_buf = dma_alloc_coherent(ar->dev, |
5173 | IEEE80211_MAX_FRAME_LEN, | |
5174 | &arvif->beacon_paddr, | |
5175 | GFP_ATOMIC); | |
64badcb6 MK |
5176 | if (!arvif->beacon_buf) { |
5177 | ret = -ENOMEM; | |
5178 | ath10k_warn(ar, "failed to allocate beacon buffer: %d\n", | |
5179 | ret); | |
5180 | goto err; | |
5181 | } | |
5182 | } | |
ccec9038 DL |
5183 | if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags)) |
5184 | arvif->nohwcrypt = true; | |
5185 | ||
5186 | if (arvif->nohwcrypt && | |
5187 | !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { | |
5188 | ath10k_warn(ar, "cryptmode module param needed for sw crypto\n"); | |
5189 | goto err; | |
5190 | } | |
64badcb6 MK |
5191 | |
5192 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n", | |
5193 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, | |
5194 | arvif->beacon_buf ? "single-buf" : "per-skb"); | |
5e3dd157 KV |
5195 | |
5196 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, | |
5197 | arvif->vdev_subtype, vif->addr); | |
5198 | if (ret) { | |
7aa7a72a | 5199 | ath10k_warn(ar, "failed to create WMI vdev %i: %d\n", |
69244e56 | 5200 | arvif->vdev_id, ret); |
9dad14ae | 5201 | goto err; |
5e3dd157 KV |
5202 | } |
5203 | ||
68c295f2 SM |
5204 | if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT, |
5205 | ar->wmi.svc_map)) { | |
5206 | vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn; | |
5207 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5208 | WMI_VDEV_DISABLE_4_ADDR_SRC_LRN); | |
5209 | if (ret && ret != -EOPNOTSUPP) { | |
5210 | ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n", | |
5211 | arvif->vdev_id, ret); | |
5212 | } | |
5213 | } | |
5214 | ||
16c11176 | 5215 | ar->free_vdev_map &= ~(1LL << arvif->vdev_id); |
ebaa4b16 | 5216 | spin_lock_bh(&ar->data_lock); |
0579119f | 5217 | list_add(&arvif->list, &ar->arvifs); |
ebaa4b16 | 5218 | spin_unlock_bh(&ar->data_lock); |
9dad14ae | 5219 | |
46725b15 MK |
5220 | /* It makes no sense to have firmware do keepalives. mac80211 already |
5221 | * takes care of this with idle connection polling. | |
5222 | */ | |
5223 | ret = ath10k_mac_vif_disable_keepalive(arvif); | |
9dad14ae | 5224 | if (ret) { |
46725b15 | 5225 | ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n", |
69244e56 | 5226 | arvif->vdev_id, ret); |
9dad14ae MK |
5227 | goto err_vdev_delete; |
5228 | } | |
5e3dd157 | 5229 | |
627613f8 | 5230 | arvif->def_wep_key_idx = -1; |
5e3dd157 | 5231 | |
6d1506e7 BM |
5232 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
5233 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 | 5234 | ATH10K_HW_TXRX_NATIVE_WIFI); |
ebc9abdd | 5235 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
9dad14ae | 5236 | if (ret && ret != -EOPNOTSUPP) { |
7aa7a72a | 5237 | ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n", |
69244e56 | 5238 | arvif->vdev_id, ret); |
9dad14ae MK |
5239 | goto err_vdev_delete; |
5240 | } | |
5e3dd157 | 5241 | |
8a75fc54 RM |
5242 | /* Configuring number of spatial stream for monitor interface is causing |
5243 | * target assert in qca9888 and qca6174. | |
5244 | */ | |
5245 | if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) { | |
5572a95b BG |
5246 | u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
5247 | ||
5248 | vdev_param = ar->wmi.vdev_param->nss; | |
5249 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5250 | nss); | |
5251 | if (ret) { | |
5252 | ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n", | |
5253 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, | |
5254 | ret); | |
5255 | goto err_vdev_delete; | |
5256 | } | |
5257 | } | |
5258 | ||
e57e0571 MK |
5259 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
5260 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { | |
6942726f MK |
5261 | ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id, |
5262 | vif->addr, WMI_PEER_TYPE_DEFAULT); | |
5e3dd157 | 5263 | if (ret) { |
e57e0571 | 5264 | ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n", |
69244e56 | 5265 | arvif->vdev_id, ret); |
9dad14ae | 5266 | goto err_vdev_delete; |
5e3dd157 | 5267 | } |
bb8f0c6a MK |
5268 | |
5269 | spin_lock_bh(&ar->data_lock); | |
5270 | ||
5271 | peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr); | |
5272 | if (!peer) { | |
5273 | ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n", | |
5274 | vif->addr, arvif->vdev_id); | |
5275 | spin_unlock_bh(&ar->data_lock); | |
5276 | ret = -ENOENT; | |
5277 | goto err_peer_delete; | |
5278 | } | |
5279 | ||
5280 | arvif->peer_id = find_first_bit(peer->peer_ids, | |
5281 | ATH10K_MAX_NUM_PEER_IDS); | |
5282 | ||
5283 | spin_unlock_bh(&ar->data_lock); | |
5284 | } else { | |
5285 | arvif->peer_id = HTT_INVALID_PEERID; | |
e57e0571 | 5286 | } |
cdf07409 | 5287 | |
e57e0571 | 5288 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
5a13e76e KV |
5289 | ret = ath10k_mac_set_kickout(arvif); |
5290 | if (ret) { | |
7aa7a72a | 5291 | ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n", |
69244e56 | 5292 | arvif->vdev_id, ret); |
5a13e76e KV |
5293 | goto err_peer_delete; |
5294 | } | |
5e3dd157 KV |
5295 | } |
5296 | ||
5297 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { | |
5298 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; | |
5299 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
5300 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
5301 | param, value); | |
9dad14ae | 5302 | if (ret) { |
7aa7a72a | 5303 | ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n", |
69244e56 | 5304 | arvif->vdev_id, ret); |
9dad14ae MK |
5305 | goto err_peer_delete; |
5306 | } | |
5e3dd157 | 5307 | |
9f9b5746 | 5308 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
9dad14ae | 5309 | if (ret) { |
9f9b5746 | 5310 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
69244e56 | 5311 | arvif->vdev_id, ret); |
9dad14ae MK |
5312 | goto err_peer_delete; |
5313 | } | |
5e3dd157 | 5314 | |
9f9b5746 | 5315 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
9dad14ae | 5316 | if (ret) { |
9f9b5746 | 5317 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
69244e56 | 5318 | arvif->vdev_id, ret); |
9dad14ae MK |
5319 | goto err_peer_delete; |
5320 | } | |
5e3dd157 KV |
5321 | } |
5322 | ||
a48e2cc8 VN |
5323 | ret = ath10k_mac_set_txbf_conf(arvif); |
5324 | if (ret) { | |
5325 | ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n", | |
5326 | arvif->vdev_id, ret); | |
5327 | goto err_peer_delete; | |
5328 | } | |
5329 | ||
424121c3 | 5330 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
9dad14ae | 5331 | if (ret) { |
7aa7a72a | 5332 | ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n", |
679c54a6 | 5333 | arvif->vdev_id, ret); |
9dad14ae MK |
5334 | goto err_peer_delete; |
5335 | } | |
679c54a6 | 5336 | |
7d9d5587 MK |
5337 | arvif->txpower = vif->bss_conf.txpower; |
5338 | ret = ath10k_mac_txpower_recalc(ar); | |
5339 | if (ret) { | |
5340 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); | |
5341 | goto err_peer_delete; | |
5342 | } | |
5343 | ||
500ff9f9 MK |
5344 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
5345 | ar->monitor_arvif = arvif; | |
5346 | ret = ath10k_monitor_recalc(ar); | |
5347 | if (ret) { | |
5348 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); | |
5349 | goto err_peer_delete; | |
5350 | } | |
5351 | } | |
5352 | ||
6d2d51ec MK |
5353 | spin_lock_bh(&ar->htt.tx_lock); |
5354 | if (!ar->tx_paused) | |
5355 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); | |
5356 | spin_unlock_bh(&ar->htt.tx_lock); | |
5357 | ||
5e3dd157 | 5358 | mutex_unlock(&ar->conf_mutex); |
9dad14ae MK |
5359 | return 0; |
5360 | ||
5361 | err_peer_delete: | |
e57e0571 MK |
5362 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
5363 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) | |
9dad14ae MK |
5364 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); |
5365 | ||
5366 | err_vdev_delete: | |
5367 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); | |
16c11176 | 5368 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
ebaa4b16 | 5369 | spin_lock_bh(&ar->data_lock); |
0579119f | 5370 | list_del(&arvif->list); |
ebaa4b16 | 5371 | spin_unlock_bh(&ar->data_lock); |
9dad14ae MK |
5372 | |
5373 | err: | |
64badcb6 MK |
5374 | if (arvif->beacon_buf) { |
5375 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, | |
5376 | arvif->beacon_buf, arvif->beacon_paddr); | |
5377 | arvif->beacon_buf = NULL; | |
5378 | } | |
5379 | ||
9dad14ae MK |
5380 | mutex_unlock(&ar->conf_mutex); |
5381 | ||
5e3dd157 KV |
5382 | return ret; |
5383 | } | |
5384 | ||
b4aa539d MK |
5385 | static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif) |
5386 | { | |
5387 | int i; | |
5388 | ||
5389 | for (i = 0; i < BITS_PER_LONG; i++) | |
5390 | ath10k_mac_vif_tx_unlock(arvif, i); | |
5391 | } | |
5392 | ||
5e3dd157 KV |
5393 | static void ath10k_remove_interface(struct ieee80211_hw *hw, |
5394 | struct ieee80211_vif *vif) | |
5395 | { | |
5396 | struct ath10k *ar = hw->priv; | |
56ac13bf | 5397 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
6942726f | 5398 | struct ath10k_peer *peer; |
5e3dd157 | 5399 | int ret; |
6942726f | 5400 | int i; |
5e3dd157 | 5401 | |
81a9a17d | 5402 | cancel_work_sync(&arvif->ap_csa_work); |
cc9904e6 | 5403 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
81a9a17d | 5404 | |
5d011f5c SM |
5405 | mutex_lock(&ar->conf_mutex); |
5406 | ||
ed54388a | 5407 | spin_lock_bh(&ar->data_lock); |
64badcb6 | 5408 | ath10k_mac_vif_beacon_cleanup(arvif); |
ed54388a MK |
5409 | spin_unlock_bh(&ar->data_lock); |
5410 | ||
855aed12 SW |
5411 | ret = ath10k_spectral_vif_stop(arvif); |
5412 | if (ret) | |
7aa7a72a | 5413 | ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", |
855aed12 SW |
5414 | arvif->vdev_id, ret); |
5415 | ||
16c11176 | 5416 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
ebaa4b16 | 5417 | spin_lock_bh(&ar->data_lock); |
0579119f | 5418 | list_del(&arvif->list); |
ebaa4b16 | 5419 | spin_unlock_bh(&ar->data_lock); |
5e3dd157 | 5420 | |
e57e0571 MK |
5421 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
5422 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { | |
2c512059 MK |
5423 | ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id, |
5424 | vif->addr); | |
5e3dd157 | 5425 | if (ret) |
e57e0571 | 5426 | ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n", |
69244e56 | 5427 | arvif->vdev_id, ret); |
5e3dd157 KV |
5428 | |
5429 | kfree(arvif->u.ap.noa_data); | |
5430 | } | |
5431 | ||
7aa7a72a | 5432 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n", |
60c3daa8 KV |
5433 | arvif->vdev_id); |
5434 | ||
5e3dd157 KV |
5435 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
5436 | if (ret) | |
7aa7a72a | 5437 | ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n", |
69244e56 | 5438 | arvif->vdev_id, ret); |
5e3dd157 | 5439 | |
2c512059 MK |
5440 | /* Some firmware revisions don't notify host about self-peer removal |
5441 | * until after associated vdev is deleted. | |
5442 | */ | |
e57e0571 MK |
5443 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
5444 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { | |
2c512059 MK |
5445 | ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id, |
5446 | vif->addr); | |
5447 | if (ret) | |
5448 | ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n", | |
5449 | arvif->vdev_id, ret); | |
5450 | ||
5451 | spin_lock_bh(&ar->data_lock); | |
5452 | ar->num_peers--; | |
5453 | spin_unlock_bh(&ar->data_lock); | |
5454 | } | |
5455 | ||
6942726f MK |
5456 | spin_lock_bh(&ar->data_lock); |
5457 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) { | |
5458 | peer = ar->peer_map[i]; | |
5459 | if (!peer) | |
5460 | continue; | |
5461 | ||
5462 | if (peer->vif == vif) { | |
5463 | ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n", | |
5464 | vif->addr, arvif->vdev_id); | |
5465 | peer->vif = NULL; | |
5466 | } | |
5467 | } | |
5468 | spin_unlock_bh(&ar->data_lock); | |
5469 | ||
5e3dd157 | 5470 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
dd4717b6 | 5471 | ath10k_mac_txq_unref(ar, vif->txq); |
5e3dd157 | 5472 | |
500ff9f9 MK |
5473 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
5474 | ar->monitor_arvif = NULL; | |
5475 | ret = ath10k_monitor_recalc(ar); | |
5476 | if (ret) | |
5477 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); | |
5478 | } | |
5479 | ||
d679fa1b RH |
5480 | ret = ath10k_mac_txpower_recalc(ar); |
5481 | if (ret) | |
5482 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); | |
5483 | ||
b4aa539d MK |
5484 | spin_lock_bh(&ar->htt.tx_lock); |
5485 | ath10k_mac_vif_tx_unlock_all(arvif); | |
5486 | spin_unlock_bh(&ar->htt.tx_lock); | |
5487 | ||
29946878 MK |
5488 | ath10k_mac_txq_unref(ar, vif->txq); |
5489 | ||
5e3dd157 KV |
5490 | mutex_unlock(&ar->conf_mutex); |
5491 | } | |
5492 | ||
5493 | /* | |
5494 | * FIXME: Has to be verified. | |
5495 | */ | |
5496 | #define SUPPORTED_FILTERS \ | |
df140465 | 5497 | (FIF_ALLMULTI | \ |
5e3dd157 KV |
5498 | FIF_CONTROL | \ |
5499 | FIF_PSPOLL | \ | |
5500 | FIF_OTHER_BSS | \ | |
5501 | FIF_BCN_PRBRESP_PROMISC | \ | |
5502 | FIF_PROBE_REQ | \ | |
5503 | FIF_FCSFAIL) | |
5504 | ||
5505 | static void ath10k_configure_filter(struct ieee80211_hw *hw, | |
5506 | unsigned int changed_flags, | |
5507 | unsigned int *total_flags, | |
5508 | u64 multicast) | |
5509 | { | |
5510 | struct ath10k *ar = hw->priv; | |
5511 | int ret; | |
5512 | ||
5513 | mutex_lock(&ar->conf_mutex); | |
5514 | ||
5515 | changed_flags &= SUPPORTED_FILTERS; | |
5516 | *total_flags &= SUPPORTED_FILTERS; | |
5517 | ar->filter_flags = *total_flags; | |
5518 | ||
1933747f MK |
5519 | ret = ath10k_monitor_recalc(ar); |
5520 | if (ret) | |
7f03d306 | 5521 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
5e3dd157 KV |
5522 | |
5523 | mutex_unlock(&ar->conf_mutex); | |
5524 | } | |
5525 | ||
5526 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, | |
5527 | struct ieee80211_vif *vif, | |
5528 | struct ieee80211_bss_conf *info, | |
5529 | u32 changed) | |
5530 | { | |
5531 | struct ath10k *ar = hw->priv; | |
56ac13bf | 5532 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
cd93b83a | 5533 | struct cfg80211_chan_def def; |
af762c0b | 5534 | u32 vdev_param, pdev_param, slottime, preamble; |
cd93b83a | 5535 | u16 bitrate, hw_value; |
f279294e S |
5536 | u8 rate, basic_rate_idx; |
5537 | int rateidx, ret = 0, hw_rate_code; | |
cd93b83a | 5538 | enum nl80211_band band; |
f279294e | 5539 | const struct ieee80211_supported_band *sband; |
5e3dd157 KV |
5540 | |
5541 | mutex_lock(&ar->conf_mutex); | |
5542 | ||
5543 | if (changed & BSS_CHANGED_IBSS) | |
5544 | ath10k_control_ibss(arvif, info, vif->addr); | |
5545 | ||
5546 | if (changed & BSS_CHANGED_BEACON_INT) { | |
5547 | arvif->beacon_interval = info->beacon_int; | |
6d1506e7 BM |
5548 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
5549 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 | 5550 | arvif->beacon_interval); |
7aa7a72a | 5551 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
5552 | "mac vdev %d beacon_interval %d\n", |
5553 | arvif->vdev_id, arvif->beacon_interval); | |
5554 | ||
5e3dd157 | 5555 | if (ret) |
7aa7a72a | 5556 | ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n", |
69244e56 | 5557 | arvif->vdev_id, ret); |
5e3dd157 KV |
5558 | } |
5559 | ||
5560 | if (changed & BSS_CHANGED_BEACON) { | |
7aa7a72a | 5561 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
5562 | "vdev %d set beacon tx mode to staggered\n", |
5563 | arvif->vdev_id); | |
5564 | ||
226a339b BM |
5565 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
5566 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, | |
5e3dd157 KV |
5567 | WMI_BEACON_STAGGERED_MODE); |
5568 | if (ret) | |
7aa7a72a | 5569 | ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n", |
69244e56 | 5570 | arvif->vdev_id, ret); |
fbb8f1b7 MK |
5571 | |
5572 | ret = ath10k_mac_setup_bcn_tmpl(arvif); | |
5573 | if (ret) | |
5574 | ath10k_warn(ar, "failed to update beacon template: %d\n", | |
5575 | ret); | |
b6c7bafa BC |
5576 | |
5577 | if (ieee80211_vif_is_mesh(vif)) { | |
5578 | /* mesh doesn't use SSID but firmware needs it */ | |
5579 | strncpy(arvif->u.ap.ssid, "mesh", | |
5580 | sizeof(arvif->u.ap.ssid)); | |
5581 | arvif->u.ap.ssid_len = 4; | |
5582 | } | |
fbb8f1b7 MK |
5583 | } |
5584 | ||
5585 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { | |
5586 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
5587 | if (ret) | |
5588 | ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n", | |
5589 | arvif->vdev_id, ret); | |
5e3dd157 KV |
5590 | } |
5591 | ||
ba2479fe | 5592 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
5e3dd157 KV |
5593 | arvif->dtim_period = info->dtim_period; |
5594 | ||
7aa7a72a | 5595 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
5596 | "mac vdev %d dtim_period %d\n", |
5597 | arvif->vdev_id, arvif->dtim_period); | |
5598 | ||
6d1506e7 BM |
5599 | vdev_param = ar->wmi.vdev_param->dtim_period; |
5600 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
5601 | arvif->dtim_period); |
5602 | if (ret) | |
7aa7a72a | 5603 | ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n", |
69244e56 | 5604 | arvif->vdev_id, ret); |
5e3dd157 KV |
5605 | } |
5606 | ||
5607 | if (changed & BSS_CHANGED_SSID && | |
5608 | vif->type == NL80211_IFTYPE_AP) { | |
5609 | arvif->u.ap.ssid_len = info->ssid_len; | |
5610 | if (info->ssid_len) | |
5611 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); | |
5612 | arvif->u.ap.hidden_ssid = info->hidden_ssid; | |
5613 | } | |
5614 | ||
077efc8c MK |
5615 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
5616 | ether_addr_copy(arvif->bssid, info->bssid); | |
5e3dd157 KV |
5617 | |
5618 | if (changed & BSS_CHANGED_BEACON_ENABLED) | |
5619 | ath10k_control_beaconing(arvif, info); | |
5620 | ||
5621 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
e81bd104 | 5622 | arvif->use_cts_prot = info->use_cts_prot; |
60c3daa8 | 5623 | |
e81bd104 | 5624 | ret = ath10k_recalc_rtscts_prot(arvif); |
5e3dd157 | 5625 | if (ret) |
7aa7a72a | 5626 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
69244e56 | 5627 | arvif->vdev_id, ret); |
a87fd4b9 | 5628 | |
7cfe0455 BM |
5629 | if (ath10k_mac_can_set_cts_prot(arvif)) { |
5630 | ret = ath10k_mac_set_cts_prot(arvif); | |
5631 | if (ret) | |
5632 | ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n", | |
5633 | arvif->vdev_id, ret); | |
5634 | } | |
5e3dd157 KV |
5635 | } |
5636 | ||
5637 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
5e3dd157 KV |
5638 | if (info->use_short_slot) |
5639 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ | |
5640 | ||
5641 | else | |
5642 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ | |
5643 | ||
7aa7a72a | 5644 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n", |
60c3daa8 KV |
5645 | arvif->vdev_id, slottime); |
5646 | ||
6d1506e7 BM |
5647 | vdev_param = ar->wmi.vdev_param->slot_time; |
5648 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
5649 | slottime); |
5650 | if (ret) | |
7aa7a72a | 5651 | ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n", |
69244e56 | 5652 | arvif->vdev_id, ret); |
5e3dd157 KV |
5653 | } |
5654 | ||
5655 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
5e3dd157 KV |
5656 | if (info->use_short_preamble) |
5657 | preamble = WMI_VDEV_PREAMBLE_SHORT; | |
5658 | else | |
5659 | preamble = WMI_VDEV_PREAMBLE_LONG; | |
5660 | ||
7aa7a72a | 5661 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
60c3daa8 KV |
5662 | "mac vdev %d preamble %dn", |
5663 | arvif->vdev_id, preamble); | |
5664 | ||
6d1506e7 BM |
5665 | vdev_param = ar->wmi.vdev_param->preamble; |
5666 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5e3dd157 KV |
5667 | preamble); |
5668 | if (ret) | |
7aa7a72a | 5669 | ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n", |
69244e56 | 5670 | arvif->vdev_id, ret); |
5e3dd157 KV |
5671 | } |
5672 | ||
5673 | if (changed & BSS_CHANGED_ASSOC) { | |
e556f111 MK |
5674 | if (info->assoc) { |
5675 | /* Workaround: Make sure monitor vdev is not running | |
5676 | * when associating to prevent some firmware revisions | |
5677 | * (e.g. 10.1 and 10.2) from crashing. | |
5678 | */ | |
5679 | if (ar->monitor_started) | |
5680 | ath10k_monitor_stop(ar); | |
5e3dd157 | 5681 | ath10k_bss_assoc(hw, vif, info); |
e556f111 | 5682 | ath10k_monitor_recalc(ar); |
077efc8c MK |
5683 | } else { |
5684 | ath10k_bss_disassoc(hw, vif); | |
e556f111 | 5685 | } |
5e3dd157 KV |
5686 | } |
5687 | ||
7d9d5587 MK |
5688 | if (changed & BSS_CHANGED_TXPOWER) { |
5689 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n", | |
5690 | arvif->vdev_id, info->txpower); | |
5691 | ||
5692 | arvif->txpower = info->txpower; | |
5693 | ret = ath10k_mac_txpower_recalc(ar); | |
5694 | if (ret) | |
5695 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); | |
5696 | } | |
5697 | ||
bf14e65c | 5698 | if (changed & BSS_CHANGED_PS) { |
cffb41f3 MK |
5699 | arvif->ps = vif->bss_conf.ps; |
5700 | ||
5701 | ret = ath10k_config_ps(ar); | |
bf14e65c MK |
5702 | if (ret) |
5703 | ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n", | |
5704 | arvif->vdev_id, ret); | |
5705 | } | |
5706 | ||
cd93b83a PKC |
5707 | if (changed & BSS_CHANGED_MCAST_RATE && |
5708 | !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) { | |
5709 | band = def.chan->band; | |
5710 | rateidx = vif->bss_conf.mcast_rate[band] - 1; | |
5711 | ||
5712 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) | |
5713 | rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX; | |
5714 | ||
5715 | bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate; | |
5716 | hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value; | |
5717 | if (ath10k_mac_bitrate_is_cck(bitrate)) | |
5718 | preamble = WMI_RATE_PREAMBLE_CCK; | |
5719 | else | |
5720 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
5721 | ||
5722 | rate = ATH10K_HW_RATECODE(hw_value, 0, preamble); | |
5723 | ||
5724 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
5725 | "mac vdev %d mcast_rate %x\n", | |
5726 | arvif->vdev_id, rate); | |
5727 | ||
5728 | vdev_param = ar->wmi.vdev_param->mcast_data_rate; | |
5729 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | |
5730 | vdev_param, rate); | |
5731 | if (ret) | |
5732 | ath10k_warn(ar, | |
5733 | "failed to set mcast rate on vdev %i: %d\n", | |
5734 | arvif->vdev_id, ret); | |
5735 | ||
5736 | vdev_param = ar->wmi.vdev_param->bcast_data_rate; | |
5737 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, | |
5738 | vdev_param, rate); | |
5739 | if (ret) | |
5740 | ath10k_warn(ar, | |
5741 | "failed to set bcast rate on vdev %i: %d\n", | |
5742 | arvif->vdev_id, ret); | |
5743 | } | |
5744 | ||
f279294e S |
5745 | if (changed & BSS_CHANGED_BASIC_RATES) { |
5746 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) { | |
5747 | mutex_unlock(&ar->conf_mutex); | |
5748 | return; | |
5749 | } | |
5750 | ||
34e141ee S |
5751 | sband = ar->hw->wiphy->bands[def.chan->band]; |
5752 | basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1; | |
5753 | bitrate = sband->bitrates[basic_rate_idx].bitrate; | |
f279294e | 5754 | |
34e141ee S |
5755 | hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate); |
5756 | if (hw_rate_code < 0) { | |
5757 | ath10k_warn(ar, "bitrate not supported %d\n", bitrate); | |
5758 | mutex_unlock(&ar->conf_mutex); | |
5759 | return; | |
5760 | } | |
f279294e | 5761 | |
34e141ee S |
5762 | vdev_param = ar->wmi.vdev_param->mgmt_rate; |
5763 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5764 | hw_rate_code); | |
5765 | if (ret) | |
5766 | ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret); | |
f279294e S |
5767 | } |
5768 | ||
5e3dd157 KV |
5769 | mutex_unlock(&ar->conf_mutex); |
5770 | } | |
5771 | ||
ebee76f7 BB |
5772 | static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value) |
5773 | { | |
5774 | struct ath10k *ar = hw->priv; | |
5775 | ||
5776 | /* This function should never be called if setting the coverage class | |
5777 | * is not supported on this hardware. | |
5778 | */ | |
5779 | if (!ar->hw_params.hw_ops->set_coverage_class) { | |
5780 | WARN_ON_ONCE(1); | |
5781 | return; | |
5782 | } | |
5783 | ar->hw_params.hw_ops->set_coverage_class(ar, value); | |
5784 | } | |
5785 | ||
dd0f9cd6 AK |
5786 | struct ath10k_mac_tdls_iter_data { |
5787 | u32 num_tdls_stations; | |
5788 | struct ieee80211_vif *curr_vif; | |
5789 | }; | |
5790 | ||
5791 | static void ath10k_mac_tdls_vif_stations_count_iter(void *data, | |
5792 | struct ieee80211_sta *sta) | |
5793 | { | |
5794 | struct ath10k_mac_tdls_iter_data *iter_data = data; | |
5795 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; | |
5796 | struct ieee80211_vif *sta_vif = arsta->arvif->vif; | |
5797 | ||
5798 | if (sta->tdls && sta_vif == iter_data->curr_vif) | |
5799 | iter_data->num_tdls_stations++; | |
5800 | } | |
5801 | ||
5802 | static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw, | |
5803 | struct ieee80211_vif *vif) | |
5804 | { | |
5805 | struct ath10k_mac_tdls_iter_data data = {}; | |
5806 | ||
5807 | data.curr_vif = vif; | |
5808 | ||
5809 | ieee80211_iterate_stations_atomic(hw, | |
5810 | ath10k_mac_tdls_vif_stations_count_iter, | |
5811 | &data); | |
5812 | return data.num_tdls_stations; | |
5813 | } | |
5814 | ||
5e3dd157 KV |
5815 | static int ath10k_hw_scan(struct ieee80211_hw *hw, |
5816 | struct ieee80211_vif *vif, | |
c56ef672 | 5817 | struct ieee80211_scan_request *hw_req) |
5e3dd157 KV |
5818 | { |
5819 | struct ath10k *ar = hw->priv; | |
56ac13bf | 5820 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
c56ef672 | 5821 | struct cfg80211_scan_request *req = &hw_req->req; |
5e3dd157 KV |
5822 | struct wmi_start_scan_arg arg; |
5823 | int ret = 0; | |
5824 | int i; | |
be8cce96 | 5825 | u32 scan_timeout; |
5e3dd157 KV |
5826 | |
5827 | mutex_lock(&ar->conf_mutex); | |
5828 | ||
a6080931 AK |
5829 | if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) { |
5830 | ret = -EBUSY; | |
5831 | goto exit; | |
5832 | } | |
5833 | ||
5e3dd157 | 5834 | spin_lock_bh(&ar->data_lock); |
5c81c7fd MK |
5835 | switch (ar->scan.state) { |
5836 | case ATH10K_SCAN_IDLE: | |
5837 | reinit_completion(&ar->scan.started); | |
5838 | reinit_completion(&ar->scan.completed); | |
5839 | ar->scan.state = ATH10K_SCAN_STARTING; | |
5840 | ar->scan.is_roc = false; | |
5841 | ar->scan.vdev_id = arvif->vdev_id; | |
5842 | ret = 0; | |
5843 | break; | |
5844 | case ATH10K_SCAN_STARTING: | |
5845 | case ATH10K_SCAN_RUNNING: | |
5846 | case ATH10K_SCAN_ABORTING: | |
5e3dd157 | 5847 | ret = -EBUSY; |
5c81c7fd | 5848 | break; |
5e3dd157 | 5849 | } |
5e3dd157 KV |
5850 | spin_unlock_bh(&ar->data_lock); |
5851 | ||
5c81c7fd MK |
5852 | if (ret) |
5853 | goto exit; | |
5854 | ||
5e3dd157 KV |
5855 | memset(&arg, 0, sizeof(arg)); |
5856 | ath10k_wmi_start_scan_init(ar, &arg); | |
5857 | arg.vdev_id = arvif->vdev_id; | |
5858 | arg.scan_id = ATH10K_SCAN_ID; | |
5859 | ||
5e3dd157 KV |
5860 | if (req->ie_len) { |
5861 | arg.ie_len = req->ie_len; | |
5862 | memcpy(arg.ie, req->ie, arg.ie_len); | |
5863 | } | |
5864 | ||
5865 | if (req->n_ssids) { | |
5866 | arg.n_ssids = req->n_ssids; | |
5867 | for (i = 0; i < arg.n_ssids; i++) { | |
5868 | arg.ssids[i].len = req->ssids[i].ssid_len; | |
5869 | arg.ssids[i].ssid = req->ssids[i].ssid; | |
5870 | } | |
dcd4a561 MK |
5871 | } else { |
5872 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; | |
5e3dd157 KV |
5873 | } |
5874 | ||
60e1d0fb CH |
5875 | if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
5876 | arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ; | |
5877 | ether_addr_copy(arg.mac_addr.addr, req->mac_addr); | |
5878 | ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask); | |
5879 | } | |
5880 | ||
5e3dd157 KV |
5881 | if (req->n_channels) { |
5882 | arg.n_channels = req->n_channels; | |
5883 | for (i = 0; i < arg.n_channels; i++) | |
5884 | arg.channels[i] = req->channels[i]->center_freq; | |
5885 | } | |
5886 | ||
be8cce96 PKC |
5887 | /* if duration is set, default dwell times will be overwritten */ |
5888 | if (req->duration) { | |
5889 | arg.dwell_time_active = req->duration; | |
5890 | arg.dwell_time_passive = req->duration; | |
5891 | arg.burst_duration_ms = req->duration; | |
5892 | ||
5893 | scan_timeout = min_t(u32, arg.max_rest_time * | |
5894 | (arg.n_channels - 1) + (req->duration + | |
5895 | ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) * | |
5896 | arg.n_channels, arg.max_scan_time + 200); | |
5897 | ||
5898 | } else { | |
5899 | /* Add a 200ms margin to account for event/command processing */ | |
5900 | scan_timeout = arg.max_scan_time + 200; | |
5901 | } | |
5902 | ||
5e3dd157 KV |
5903 | ret = ath10k_start_scan(ar, &arg); |
5904 | if (ret) { | |
7aa7a72a | 5905 | ath10k_warn(ar, "failed to start hw scan: %d\n", ret); |
5e3dd157 | 5906 | spin_lock_bh(&ar->data_lock); |
5c81c7fd | 5907 | ar->scan.state = ATH10K_SCAN_IDLE; |
5e3dd157 KV |
5908 | spin_unlock_bh(&ar->data_lock); |
5909 | } | |
5910 | ||
634349ba | 5911 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
be8cce96 | 5912 | msecs_to_jiffies(scan_timeout)); |
634349ba | 5913 | |
5e3dd157 KV |
5914 | exit: |
5915 | mutex_unlock(&ar->conf_mutex); | |
5916 | return ret; | |
5917 | } | |
5918 | ||
5919 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, | |
5920 | struct ieee80211_vif *vif) | |
5921 | { | |
5922 | struct ath10k *ar = hw->priv; | |
5e3dd157 KV |
5923 | |
5924 | mutex_lock(&ar->conf_mutex); | |
5c81c7fd | 5925 | ath10k_scan_abort(ar); |
5e3dd157 | 5926 | mutex_unlock(&ar->conf_mutex); |
4eb2e164 MK |
5927 | |
5928 | cancel_delayed_work_sync(&ar->scan.timeout); | |
5e3dd157 KV |
5929 | } |
5930 | ||
cfb27d29 MK |
5931 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
5932 | struct ath10k_vif *arvif, | |
5933 | enum set_key_cmd cmd, | |
5934 | struct ieee80211_key_conf *key) | |
5935 | { | |
5936 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; | |
5937 | int ret; | |
5938 | ||
5939 | /* 10.1 firmware branch requires default key index to be set to group | |
5940 | * key index after installing it. Otherwise FW/HW Txes corrupted | |
5941 | * frames with multi-vif APs. This is not required for main firmware | |
5942 | * branch (e.g. 636). | |
5943 | * | |
8461baf7 MK |
5944 | * This is also needed for 636 fw for IBSS-RSN to work more reliably. |
5945 | * | |
5946 | * FIXME: It remains unknown if this is required for multi-vif STA | |
5947 | * interfaces on 10.1. | |
5948 | */ | |
cfb27d29 | 5949 | |
8461baf7 MK |
5950 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
5951 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) | |
cfb27d29 MK |
5952 | return; |
5953 | ||
5954 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) | |
5955 | return; | |
5956 | ||
5957 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) | |
5958 | return; | |
5959 | ||
5960 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
5961 | return; | |
5962 | ||
5963 | if (cmd != SET_KEY) | |
5964 | return; | |
5965 | ||
5966 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, | |
5967 | key->keyidx); | |
5968 | if (ret) | |
7aa7a72a | 5969 | ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n", |
69244e56 | 5970 | arvif->vdev_id, ret); |
cfb27d29 MK |
5971 | } |
5972 | ||
5e3dd157 KV |
5973 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
5974 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
5975 | struct ieee80211_key_conf *key) | |
5976 | { | |
5977 | struct ath10k *ar = hw->priv; | |
56ac13bf | 5978 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 KV |
5979 | struct ath10k_peer *peer; |
5980 | const u8 *peer_addr; | |
5981 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || | |
5982 | key->cipher == WLAN_CIPHER_SUITE_WEP104; | |
5983 | int ret = 0; | |
29a10006 | 5984 | int ret2; |
370e5673 | 5985 | u32 flags = 0; |
29a10006 | 5986 | u32 flags2; |
5e3dd157 | 5987 | |
d7131c04 | 5988 | /* this one needs to be done in software */ |
2ea9f12c RM |
5989 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
5990 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
5991 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || | |
5992 | key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) | |
d7131c04 | 5993 | return 1; |
5e3dd157 | 5994 | |
ccec9038 DL |
5995 | if (arvif->nohwcrypt) |
5996 | return 1; | |
5997 | ||
5e3dd157 KV |
5998 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
5999 | return -ENOSPC; | |
6000 | ||
6001 | mutex_lock(&ar->conf_mutex); | |
6002 | ||
6003 | if (sta) | |
6004 | peer_addr = sta->addr; | |
6005 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
6006 | peer_addr = vif->bss_conf.bssid; | |
6007 | else | |
6008 | peer_addr = vif->addr; | |
6009 | ||
6010 | key->hw_key_idx = key->keyidx; | |
6011 | ||
7c8cc7eb MK |
6012 | if (is_wep) { |
6013 | if (cmd == SET_KEY) | |
6014 | arvif->wep_keys[key->keyidx] = key; | |
6015 | else | |
6016 | arvif->wep_keys[key->keyidx] = NULL; | |
6017 | } | |
6018 | ||
5e3dd157 | 6019 | /* the peer should not disappear in mid-way (unless FW goes awry) since |
d6dfe25c MR |
6020 | * we already hold conf_mutex. we just make sure its there now. |
6021 | */ | |
5e3dd157 KV |
6022 | spin_lock_bh(&ar->data_lock); |
6023 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); | |
6024 | spin_unlock_bh(&ar->data_lock); | |
6025 | ||
6026 | if (!peer) { | |
6027 | if (cmd == SET_KEY) { | |
7aa7a72a | 6028 | ath10k_warn(ar, "failed to install key for non-existent peer %pM\n", |
5e3dd157 KV |
6029 | peer_addr); |
6030 | ret = -EOPNOTSUPP; | |
6031 | goto exit; | |
6032 | } else { | |
d6dfe25c | 6033 | /* if the peer doesn't exist there is no key to disable anymore */ |
5e3dd157 KV |
6034 | goto exit; |
6035 | } | |
6036 | } | |
6037 | ||
7cc4573e MK |
6038 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
6039 | flags |= WMI_KEY_PAIRWISE; | |
6040 | else | |
6041 | flags |= WMI_KEY_GROUP; | |
5e3dd157 | 6042 | |
5e3dd157 | 6043 | if (is_wep) { |
5e3dd157 KV |
6044 | if (cmd == DISABLE_KEY) |
6045 | ath10k_clear_vdev_key(arvif, key); | |
5e3dd157 | 6046 | |
ad325cb5 MK |
6047 | /* When WEP keys are uploaded it's possible that there are |
6048 | * stations associated already (e.g. when merging) without any | |
6049 | * keys. Static WEP needs an explicit per-peer key upload. | |
6050 | */ | |
6051 | if (vif->type == NL80211_IFTYPE_ADHOC && | |
6052 | cmd == SET_KEY) | |
6053 | ath10k_mac_vif_update_wep_key(arvif, key); | |
6054 | ||
370e5673 MK |
6055 | /* 802.1x never sets the def_wep_key_idx so each set_key() |
6056 | * call changes default tx key. | |
6057 | * | |
6058 | * Static WEP sets def_wep_key_idx via .set_default_unicast_key | |
6059 | * after first set_key(). | |
6060 | */ | |
6061 | if (cmd == SET_KEY && arvif->def_wep_key_idx == -1) | |
6062 | flags |= WMI_KEY_TX_USAGE; | |
370e5673 | 6063 | } |
627613f8 | 6064 | |
370e5673 | 6065 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags); |
5e3dd157 | 6066 | if (ret) { |
ccec9038 | 6067 | WARN_ON(ret > 0); |
7aa7a72a | 6068 | ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n", |
69244e56 | 6069 | arvif->vdev_id, peer_addr, ret); |
5e3dd157 KV |
6070 | goto exit; |
6071 | } | |
6072 | ||
29a10006 MK |
6073 | /* mac80211 sets static WEP keys as groupwise while firmware requires |
6074 | * them to be installed twice as both pairwise and groupwise. | |
6075 | */ | |
6076 | if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) { | |
6077 | flags2 = flags; | |
6078 | flags2 &= ~WMI_KEY_GROUP; | |
6079 | flags2 |= WMI_KEY_PAIRWISE; | |
6080 | ||
6081 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2); | |
6082 | if (ret) { | |
ccec9038 | 6083 | WARN_ON(ret > 0); |
29a10006 MK |
6084 | ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n", |
6085 | arvif->vdev_id, peer_addr, ret); | |
6086 | ret2 = ath10k_install_key(arvif, key, DISABLE_KEY, | |
6087 | peer_addr, flags); | |
ccec9038 DL |
6088 | if (ret2) { |
6089 | WARN_ON(ret2 > 0); | |
29a10006 MK |
6090 | ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n", |
6091 | arvif->vdev_id, peer_addr, ret2); | |
ccec9038 | 6092 | } |
29a10006 MK |
6093 | goto exit; |
6094 | } | |
6095 | } | |
6096 | ||
cfb27d29 MK |
6097 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
6098 | ||
5e3dd157 KV |
6099 | spin_lock_bh(&ar->data_lock); |
6100 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); | |
6101 | if (peer && cmd == SET_KEY) | |
6102 | peer->keys[key->keyidx] = key; | |
6103 | else if (peer && cmd == DISABLE_KEY) | |
6104 | peer->keys[key->keyidx] = NULL; | |
6105 | else if (peer == NULL) | |
6106 | /* impossible unless FW goes crazy */ | |
7aa7a72a | 6107 | ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr); |
5e3dd157 KV |
6108 | spin_unlock_bh(&ar->data_lock); |
6109 | ||
9cdd0057 YT |
6110 | if (sta && sta->tdls) |
6111 | ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
6112 | WMI_PEER_AUTHORIZE, 1); | |
6113 | ||
5e3dd157 KV |
6114 | exit: |
6115 | mutex_unlock(&ar->conf_mutex); | |
6116 | return ret; | |
6117 | } | |
6118 | ||
627613f8 SJ |
6119 | static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw, |
6120 | struct ieee80211_vif *vif, | |
6121 | int keyidx) | |
6122 | { | |
6123 | struct ath10k *ar = hw->priv; | |
56ac13bf | 6124 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
627613f8 SJ |
6125 | int ret; |
6126 | ||
6127 | mutex_lock(&arvif->ar->conf_mutex); | |
6128 | ||
6129 | if (arvif->ar->state != ATH10K_STATE_ON) | |
6130 | goto unlock; | |
6131 | ||
6132 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", | |
6133 | arvif->vdev_id, keyidx); | |
6134 | ||
6135 | ret = ath10k_wmi_vdev_set_param(arvif->ar, | |
6136 | arvif->vdev_id, | |
6137 | arvif->ar->wmi.vdev_param->def_keyid, | |
6138 | keyidx); | |
6139 | ||
6140 | if (ret) { | |
6141 | ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n", | |
6142 | arvif->vdev_id, | |
6143 | ret); | |
6144 | goto unlock; | |
6145 | } | |
6146 | ||
6147 | arvif->def_wep_key_idx = keyidx; | |
370e5673 | 6148 | |
627613f8 SJ |
6149 | unlock: |
6150 | mutex_unlock(&arvif->ar->conf_mutex); | |
6151 | } | |
6152 | ||
9797febc MK |
6153 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
6154 | { | |
6155 | struct ath10k *ar; | |
6156 | struct ath10k_vif *arvif; | |
6157 | struct ath10k_sta *arsta; | |
6158 | struct ieee80211_sta *sta; | |
45c9abc0 | 6159 | struct cfg80211_chan_def def; |
57fbcce3 | 6160 | enum nl80211_band band; |
45c9abc0 MK |
6161 | const u8 *ht_mcs_mask; |
6162 | const u16 *vht_mcs_mask; | |
9797febc MK |
6163 | u32 changed, bw, nss, smps; |
6164 | int err; | |
6165 | ||
6166 | arsta = container_of(wk, struct ath10k_sta, update_wk); | |
6167 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); | |
6168 | arvif = arsta->arvif; | |
6169 | ar = arvif->ar; | |
6170 | ||
45c9abc0 MK |
6171 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) |
6172 | return; | |
6173 | ||
6174 | band = def.chan->band; | |
6175 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
6176 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
6177 | ||
9797febc MK |
6178 | spin_lock_bh(&ar->data_lock); |
6179 | ||
6180 | changed = arsta->changed; | |
6181 | arsta->changed = 0; | |
6182 | ||
6183 | bw = arsta->bw; | |
6184 | nss = arsta->nss; | |
6185 | smps = arsta->smps; | |
6186 | ||
6187 | spin_unlock_bh(&ar->data_lock); | |
6188 | ||
6189 | mutex_lock(&ar->conf_mutex); | |
6190 | ||
45c9abc0 MK |
6191 | nss = max_t(u32, 1, nss); |
6192 | nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask), | |
6193 | ath10k_mac_max_vht_nss(vht_mcs_mask))); | |
6194 | ||
9797febc | 6195 | if (changed & IEEE80211_RC_BW_CHANGED) { |
9191fc2a RH |
6196 | enum wmi_phy_mode mode; |
6197 | ||
6198 | mode = chan_to_phymode(&def); | |
6199 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n", | |
ebfac1d0 | 6200 | sta->addr, bw, mode); |
9191fc2a RH |
6201 | |
6202 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
ebfac1d0 | 6203 | WMI_PEER_PHYMODE, mode); |
9191fc2a RH |
6204 | if (err) { |
6205 | ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n", | |
ebfac1d0 | 6206 | sta->addr, mode, err); |
9191fc2a RH |
6207 | goto exit; |
6208 | } | |
9797febc MK |
6209 | |
6210 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
6211 | WMI_PEER_CHAN_WIDTH, bw); | |
6212 | if (err) | |
7aa7a72a | 6213 | ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n", |
9797febc MK |
6214 | sta->addr, bw, err); |
6215 | } | |
6216 | ||
6217 | if (changed & IEEE80211_RC_NSS_CHANGED) { | |
7aa7a72a | 6218 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n", |
9797febc MK |
6219 | sta->addr, nss); |
6220 | ||
6221 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
6222 | WMI_PEER_NSS, nss); | |
6223 | if (err) | |
7aa7a72a | 6224 | ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n", |
9797febc MK |
6225 | sta->addr, nss, err); |
6226 | } | |
6227 | ||
6228 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
7aa7a72a | 6229 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n", |
9797febc MK |
6230 | sta->addr, smps); |
6231 | ||
6232 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, | |
6233 | WMI_PEER_SMPS_STATE, smps); | |
6234 | if (err) | |
7aa7a72a | 6235 | ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n", |
9797febc MK |
6236 | sta->addr, smps, err); |
6237 | } | |
6238 | ||
55cc11da KP |
6239 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { |
6240 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n", | |
44d6fa90 CYY |
6241 | sta->addr); |
6242 | ||
590922a8 | 6243 | err = ath10k_station_assoc(ar, arvif->vif, sta, true); |
44d6fa90 | 6244 | if (err) |
7aa7a72a | 6245 | ath10k_warn(ar, "failed to reassociate station: %pM\n", |
44d6fa90 CYY |
6246 | sta->addr); |
6247 | } | |
6248 | ||
9191fc2a | 6249 | exit: |
9797febc MK |
6250 | mutex_unlock(&ar->conf_mutex); |
6251 | } | |
6252 | ||
7c354242 MP |
6253 | static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif, |
6254 | struct ieee80211_sta *sta) | |
cfd1061e MK |
6255 | { |
6256 | struct ath10k *ar = arvif->ar; | |
6257 | ||
6258 | lockdep_assert_held(&ar->conf_mutex); | |
6259 | ||
7c354242 | 6260 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
cfd1061e MK |
6261 | return 0; |
6262 | ||
6263 | if (ar->num_stations >= ar->max_num_stations) | |
6264 | return -ENOBUFS; | |
6265 | ||
6266 | ar->num_stations++; | |
6267 | ||
6268 | return 0; | |
6269 | } | |
6270 | ||
7c354242 MP |
6271 | static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif, |
6272 | struct ieee80211_sta *sta) | |
cfd1061e MK |
6273 | { |
6274 | struct ath10k *ar = arvif->ar; | |
6275 | ||
6276 | lockdep_assert_held(&ar->conf_mutex); | |
6277 | ||
7c354242 | 6278 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
cfd1061e MK |
6279 | return; |
6280 | ||
6281 | ar->num_stations--; | |
6282 | } | |
6283 | ||
5e3dd157 KV |
6284 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
6285 | struct ieee80211_vif *vif, | |
6286 | struct ieee80211_sta *sta, | |
6287 | enum ieee80211_sta_state old_state, | |
6288 | enum ieee80211_sta_state new_state) | |
6289 | { | |
6290 | struct ath10k *ar = hw->priv; | |
56ac13bf | 6291 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
9797febc | 6292 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
bb8f0c6a | 6293 | struct ath10k_peer *peer; |
5e3dd157 | 6294 | int ret = 0; |
6942726f | 6295 | int i; |
5e3dd157 | 6296 | |
76f90024 MK |
6297 | if (old_state == IEEE80211_STA_NOTEXIST && |
6298 | new_state == IEEE80211_STA_NONE) { | |
6299 | memset(arsta, 0, sizeof(*arsta)); | |
6300 | arsta->arvif = arvif; | |
d70c0d46 | 6301 | arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED; |
76f90024 | 6302 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); |
29946878 MK |
6303 | |
6304 | for (i = 0; i < ARRAY_SIZE(sta->txq); i++) | |
6305 | ath10k_mac_txq_init(sta->txq[i]); | |
76f90024 MK |
6306 | } |
6307 | ||
9797febc MK |
6308 | /* cancel must be done outside the mutex to avoid deadlock */ |
6309 | if ((old_state == IEEE80211_STA_NONE && | |
6310 | new_state == IEEE80211_STA_NOTEXIST)) | |
6311 | cancel_work_sync(&arsta->update_wk); | |
6312 | ||
5e3dd157 KV |
6313 | mutex_lock(&ar->conf_mutex); |
6314 | ||
6315 | if (old_state == IEEE80211_STA_NOTEXIST && | |
077efc8c | 6316 | new_state == IEEE80211_STA_NONE) { |
5e3dd157 KV |
6317 | /* |
6318 | * New station addition. | |
6319 | */ | |
75d85fd9 MP |
6320 | enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT; |
6321 | u32 num_tdls_stations; | |
75d85fd9 | 6322 | |
cfd1061e MK |
6323 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
6324 | "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n", | |
6325 | arvif->vdev_id, sta->addr, | |
6326 | ar->num_stations + 1, ar->max_num_stations, | |
6327 | ar->num_peers + 1, ar->max_num_peers); | |
0e759f36 | 6328 | |
9a993cc1 | 6329 | num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif); |
9a993cc1 RH |
6330 | |
6331 | if (sta->tdls) { | |
6332 | if (num_tdls_stations >= ar->max_num_tdls_vdevs) { | |
6333 | ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n", | |
6334 | arvif->vdev_id, | |
6335 | ar->max_num_tdls_vdevs); | |
6336 | ret = -ELNRNG; | |
6337 | goto exit; | |
6338 | } | |
6339 | peer_type = WMI_PEER_TYPE_TDLS; | |
6340 | } | |
6341 | ||
7c354242 | 6342 | ret = ath10k_mac_inc_num_stations(arvif, sta); |
cfd1061e MK |
6343 | if (ret) { |
6344 | ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n", | |
6345 | ar->max_num_stations); | |
0e759f36 BM |
6346 | goto exit; |
6347 | } | |
6348 | ||
386f97e3 ZC |
6349 | if (ath10k_debug_is_extd_tx_stats_enabled(ar)) { |
6350 | arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), | |
6351 | GFP_KERNEL); | |
6352 | if (!arsta->tx_stats) { | |
6353 | ret = -ENOMEM; | |
6354 | goto exit; | |
6355 | } | |
6356 | } | |
6357 | ||
6942726f MK |
6358 | ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id, |
6359 | sta->addr, peer_type); | |
a52c0282 | 6360 | if (ret) { |
7aa7a72a | 6361 | ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n", |
479398b0 | 6362 | sta->addr, arvif->vdev_id, ret); |
7c354242 | 6363 | ath10k_mac_dec_num_stations(arvif, sta); |
386f97e3 | 6364 | kfree(arsta->tx_stats); |
a52c0282 MK |
6365 | goto exit; |
6366 | } | |
077efc8c | 6367 | |
bb8f0c6a MK |
6368 | spin_lock_bh(&ar->data_lock); |
6369 | ||
6370 | peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr); | |
6371 | if (!peer) { | |
6372 | ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n", | |
6373 | vif->addr, arvif->vdev_id); | |
6374 | spin_unlock_bh(&ar->data_lock); | |
6375 | ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
6376 | ath10k_mac_dec_num_stations(arvif, sta); | |
386f97e3 | 6377 | kfree(arsta->tx_stats); |
bb8f0c6a MK |
6378 | ret = -ENOENT; |
6379 | goto exit; | |
6380 | } | |
6381 | ||
6382 | arsta->peer_id = find_first_bit(peer->peer_ids, | |
6383 | ATH10K_MAX_NUM_PEER_IDS); | |
6384 | ||
6385 | spin_unlock_bh(&ar->data_lock); | |
6386 | ||
75d85fd9 MP |
6387 | if (!sta->tdls) |
6388 | goto exit; | |
6389 | ||
9a993cc1 RH |
6390 | ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
6391 | WMI_TDLS_ENABLE_ACTIVE); | |
6392 | if (ret) { | |
6393 | ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n", | |
6394 | arvif->vdev_id, ret); | |
6395 | ath10k_peer_delete(ar, arvif->vdev_id, | |
6396 | sta->addr); | |
75d85fd9 | 6397 | ath10k_mac_dec_num_stations(arvif, sta); |
386f97e3 | 6398 | kfree(arsta->tx_stats); |
a52c0282 MK |
6399 | goto exit; |
6400 | } | |
077efc8c | 6401 | |
75d85fd9 MP |
6402 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, |
6403 | WMI_TDLS_PEER_STATE_PEERING); | |
6404 | if (ret) { | |
6405 | ath10k_warn(ar, | |
6406 | "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n", | |
6407 | sta->addr, arvif->vdev_id, ret); | |
6408 | ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
6409 | ath10k_mac_dec_num_stations(arvif, sta); | |
386f97e3 | 6410 | kfree(arsta->tx_stats); |
077efc8c | 6411 | |
75d85fd9 MP |
6412 | if (num_tdls_stations != 0) |
6413 | goto exit; | |
6414 | ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, | |
6415 | WMI_TDLS_DISABLE); | |
077efc8c | 6416 | } |
5e3dd157 KV |
6417 | } else if ((old_state == IEEE80211_STA_NONE && |
6418 | new_state == IEEE80211_STA_NOTEXIST)) { | |
6419 | /* | |
6420 | * Existing station deletion. | |
6421 | */ | |
7aa7a72a | 6422 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
30404201 BG |
6423 | "mac vdev %d peer delete %pM sta %pK (sta gone)\n", |
6424 | arvif->vdev_id, sta->addr, sta); | |
077efc8c | 6425 | |
424ea0d1 MP |
6426 | if (sta->tdls) { |
6427 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, | |
6428 | sta, | |
6429 | WMI_TDLS_PEER_STATE_TEARDOWN); | |
6430 | if (ret) | |
6431 | ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n", | |
6432 | sta->addr, | |
6433 | WMI_TDLS_PEER_STATE_TEARDOWN, ret); | |
6434 | } | |
6435 | ||
5e3dd157 KV |
6436 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
6437 | if (ret) | |
7aa7a72a | 6438 | ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n", |
69244e56 | 6439 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 | 6440 | |
7c354242 | 6441 | ath10k_mac_dec_num_stations(arvif, sta); |
75d85fd9 | 6442 | |
6942726f MK |
6443 | spin_lock_bh(&ar->data_lock); |
6444 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) { | |
6445 | peer = ar->peer_map[i]; | |
6446 | if (!peer) | |
6447 | continue; | |
6448 | ||
6449 | if (peer->sta == sta) { | |
75b34800 | 6450 | ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n", |
d0eeafad | 6451 | sta->addr, peer, i, arvif->vdev_id); |
6942726f | 6452 | peer->sta = NULL; |
d0eeafad BG |
6453 | |
6454 | /* Clean up the peer object as well since we | |
6455 | * must have failed to do this above. | |
6456 | */ | |
6457 | list_del(&peer->list); | |
6458 | ar->peer_map[i] = NULL; | |
6459 | kfree(peer); | |
6460 | ar->num_peers--; | |
6942726f MK |
6461 | } |
6462 | } | |
6463 | spin_unlock_bh(&ar->data_lock); | |
6464 | ||
553a7cca KP |
6465 | if (ath10k_debug_is_extd_tx_stats_enabled(ar)) { |
6466 | kfree(arsta->tx_stats); | |
6467 | arsta->tx_stats = NULL; | |
6468 | } | |
6469 | ||
29946878 MK |
6470 | for (i = 0; i < ARRAY_SIZE(sta->txq); i++) |
6471 | ath10k_mac_txq_unref(ar, sta->txq[i]); | |
6472 | ||
75d85fd9 MP |
6473 | if (!sta->tdls) |
6474 | goto exit; | |
6475 | ||
6476 | if (ath10k_mac_tdls_vif_stations_count(hw, vif)) | |
6477 | goto exit; | |
6478 | ||
6479 | /* This was the last tdls peer in current vif */ | |
6480 | ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, | |
6481 | WMI_TDLS_DISABLE); | |
6482 | if (ret) { | |
6483 | ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n", | |
6484 | arvif->vdev_id, ret); | |
6485 | } | |
5e3dd157 KV |
6486 | } else if (old_state == IEEE80211_STA_AUTH && |
6487 | new_state == IEEE80211_STA_ASSOC && | |
6488 | (vif->type == NL80211_IFTYPE_AP || | |
b6c7bafa | 6489 | vif->type == NL80211_IFTYPE_MESH_POINT || |
5e3dd157 KV |
6490 | vif->type == NL80211_IFTYPE_ADHOC)) { |
6491 | /* | |
6492 | * New association. | |
6493 | */ | |
7aa7a72a | 6494 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", |
60c3daa8 KV |
6495 | sta->addr); |
6496 | ||
590922a8 | 6497 | ret = ath10k_station_assoc(ar, vif, sta, false); |
5e3dd157 | 6498 | if (ret) |
7aa7a72a | 6499 | ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n", |
69244e56 | 6500 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 | 6501 | } else if (old_state == IEEE80211_STA_ASSOC && |
75d85fd9 MP |
6502 | new_state == IEEE80211_STA_AUTHORIZED && |
6503 | sta->tdls) { | |
6504 | /* | |
6505 | * Tdls station authorized. | |
6506 | */ | |
6507 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n", | |
6508 | sta->addr); | |
6509 | ||
6510 | ret = ath10k_station_assoc(ar, vif, sta, false); | |
6511 | if (ret) { | |
6512 | ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n", | |
6513 | sta->addr, arvif->vdev_id, ret); | |
6514 | goto exit; | |
6515 | } | |
6516 | ||
6517 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, | |
6518 | WMI_TDLS_PEER_STATE_CONNECTED); | |
6519 | if (ret) | |
6520 | ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n", | |
6521 | sta->addr, arvif->vdev_id, ret); | |
6522 | } else if (old_state == IEEE80211_STA_ASSOC && | |
6523 | new_state == IEEE80211_STA_AUTH && | |
6524 | (vif->type == NL80211_IFTYPE_AP || | |
b6c7bafa | 6525 | vif->type == NL80211_IFTYPE_MESH_POINT || |
75d85fd9 | 6526 | vif->type == NL80211_IFTYPE_ADHOC)) { |
5e3dd157 KV |
6527 | /* |
6528 | * Disassociation. | |
6529 | */ | |
7aa7a72a | 6530 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
60c3daa8 KV |
6531 | sta->addr); |
6532 | ||
590922a8 | 6533 | ret = ath10k_station_disassoc(ar, vif, sta); |
5e3dd157 | 6534 | if (ret) |
7aa7a72a | 6535 | ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", |
69244e56 | 6536 | sta->addr, arvif->vdev_id, ret); |
5e3dd157 | 6537 | } |
0e759f36 | 6538 | exit: |
5e3dd157 KV |
6539 | mutex_unlock(&ar->conf_mutex); |
6540 | return ret; | |
6541 | } | |
6542 | ||
6543 | static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif, | |
5b07e07f | 6544 | u16 ac, bool enable) |
5e3dd157 | 6545 | { |
56ac13bf | 6546 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
b0e56154 MK |
6547 | struct wmi_sta_uapsd_auto_trig_arg arg = {}; |
6548 | u32 prio = 0, acc = 0; | |
5e3dd157 KV |
6549 | u32 value = 0; |
6550 | int ret = 0; | |
6551 | ||
548db54c MK |
6552 | lockdep_assert_held(&ar->conf_mutex); |
6553 | ||
5e3dd157 KV |
6554 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
6555 | return 0; | |
6556 | ||
6557 | switch (ac) { | |
6558 | case IEEE80211_AC_VO: | |
6559 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | | |
6560 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; | |
b0e56154 MK |
6561 | prio = 7; |
6562 | acc = 3; | |
5e3dd157 KV |
6563 | break; |
6564 | case IEEE80211_AC_VI: | |
6565 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | | |
6566 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; | |
b0e56154 MK |
6567 | prio = 5; |
6568 | acc = 2; | |
5e3dd157 KV |
6569 | break; |
6570 | case IEEE80211_AC_BE: | |
6571 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | | |
6572 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; | |
b0e56154 MK |
6573 | prio = 2; |
6574 | acc = 1; | |
5e3dd157 KV |
6575 | break; |
6576 | case IEEE80211_AC_BK: | |
6577 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | | |
6578 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; | |
b0e56154 MK |
6579 | prio = 0; |
6580 | acc = 0; | |
5e3dd157 KV |
6581 | break; |
6582 | } | |
6583 | ||
6584 | if (enable) | |
6585 | arvif->u.sta.uapsd |= value; | |
6586 | else | |
6587 | arvif->u.sta.uapsd &= ~value; | |
6588 | ||
6589 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
6590 | WMI_STA_PS_PARAM_UAPSD, | |
6591 | arvif->u.sta.uapsd); | |
6592 | if (ret) { | |
7aa7a72a | 6593 | ath10k_warn(ar, "failed to set uapsd params: %d\n", ret); |
5e3dd157 KV |
6594 | goto exit; |
6595 | } | |
6596 | ||
6597 | if (arvif->u.sta.uapsd) | |
6598 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; | |
6599 | else | |
6600 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
6601 | ||
6602 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
6603 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, | |
6604 | value); | |
6605 | if (ret) | |
7aa7a72a | 6606 | ath10k_warn(ar, "failed to set rx wake param: %d\n", ret); |
5e3dd157 | 6607 | |
9f9b5746 MK |
6608 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
6609 | if (ret) { | |
6610 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", | |
6611 | arvif->vdev_id, ret); | |
6612 | return ret; | |
6613 | } | |
6614 | ||
6615 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); | |
6616 | if (ret) { | |
6617 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", | |
6618 | arvif->vdev_id, ret); | |
6619 | return ret; | |
6620 | } | |
6621 | ||
b0e56154 MK |
6622 | if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) || |
6623 | test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) { | |
6624 | /* Only userspace can make an educated decision when to send | |
6625 | * trigger frame. The following effectively disables u-UAPSD | |
6626 | * autotrigger in firmware (which is enabled by default | |
6627 | * provided the autotrigger service is available). | |
6628 | */ | |
6629 | ||
6630 | arg.wmm_ac = acc; | |
6631 | arg.user_priority = prio; | |
6632 | arg.service_interval = 0; | |
6633 | arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; | |
6634 | arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; | |
6635 | ||
6636 | ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id, | |
6637 | arvif->bssid, &arg, 1); | |
6638 | if (ret) { | |
6639 | ath10k_warn(ar, "failed to set uapsd auto trigger %d\n", | |
6640 | ret); | |
6641 | return ret; | |
6642 | } | |
6643 | } | |
6644 | ||
5e3dd157 KV |
6645 | exit: |
6646 | return ret; | |
6647 | } | |
6648 | ||
6649 | static int ath10k_conf_tx(struct ieee80211_hw *hw, | |
6650 | struct ieee80211_vif *vif, u16 ac, | |
6651 | const struct ieee80211_tx_queue_params *params) | |
6652 | { | |
6653 | struct ath10k *ar = hw->priv; | |
56ac13bf | 6654 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 KV |
6655 | struct wmi_wmm_params_arg *p = NULL; |
6656 | int ret; | |
6657 | ||
6658 | mutex_lock(&ar->conf_mutex); | |
6659 | ||
6660 | switch (ac) { | |
6661 | case IEEE80211_AC_VO: | |
5e752e42 | 6662 | p = &arvif->wmm_params.ac_vo; |
5e3dd157 KV |
6663 | break; |
6664 | case IEEE80211_AC_VI: | |
5e752e42 | 6665 | p = &arvif->wmm_params.ac_vi; |
5e3dd157 KV |
6666 | break; |
6667 | case IEEE80211_AC_BE: | |
5e752e42 | 6668 | p = &arvif->wmm_params.ac_be; |
5e3dd157 KV |
6669 | break; |
6670 | case IEEE80211_AC_BK: | |
5e752e42 | 6671 | p = &arvif->wmm_params.ac_bk; |
5e3dd157 KV |
6672 | break; |
6673 | } | |
6674 | ||
6675 | if (WARN_ON(!p)) { | |
6676 | ret = -EINVAL; | |
6677 | goto exit; | |
6678 | } | |
6679 | ||
6680 | p->cwmin = params->cw_min; | |
6681 | p->cwmax = params->cw_max; | |
6682 | p->aifs = params->aifs; | |
6683 | ||
6684 | /* | |
6685 | * The channel time duration programmed in the HW is in absolute | |
6686 | * microseconds, while mac80211 gives the txop in units of | |
6687 | * 32 microseconds. | |
6688 | */ | |
6689 | p->txop = params->txop * 32; | |
6690 | ||
7fc979a7 MK |
6691 | if (ar->wmi.ops->gen_vdev_wmm_conf) { |
6692 | ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id, | |
6693 | &arvif->wmm_params); | |
6694 | if (ret) { | |
6695 | ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n", | |
6696 | arvif->vdev_id, ret); | |
6697 | goto exit; | |
6698 | } | |
6699 | } else { | |
6700 | /* This won't work well with multi-interface cases but it's | |
6701 | * better than nothing. | |
6702 | */ | |
6703 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params); | |
6704 | if (ret) { | |
6705 | ath10k_warn(ar, "failed to set wmm params: %d\n", ret); | |
6706 | goto exit; | |
6707 | } | |
5e3dd157 KV |
6708 | } |
6709 | ||
6710 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); | |
6711 | if (ret) | |
7aa7a72a | 6712 | ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret); |
5e3dd157 KV |
6713 | |
6714 | exit: | |
6715 | mutex_unlock(&ar->conf_mutex); | |
6716 | return ret; | |
6717 | } | |
6718 | ||
14e105cd | 6719 | #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ) |
5e3dd157 KV |
6720 | |
6721 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, | |
6722 | struct ieee80211_vif *vif, | |
6723 | struct ieee80211_channel *chan, | |
6724 | int duration, | |
6725 | enum ieee80211_roc_type type) | |
6726 | { | |
6727 | struct ath10k *ar = hw->priv; | |
56ac13bf | 6728 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 | 6729 | struct wmi_start_scan_arg arg; |
5c81c7fd | 6730 | int ret = 0; |
fcf98446 | 6731 | u32 scan_time_msec; |
5e3dd157 KV |
6732 | |
6733 | mutex_lock(&ar->conf_mutex); | |
6734 | ||
a6080931 AK |
6735 | if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) { |
6736 | ret = -EBUSY; | |
6737 | goto exit; | |
6738 | } | |
6739 | ||
5e3dd157 | 6740 | spin_lock_bh(&ar->data_lock); |
5c81c7fd MK |
6741 | switch (ar->scan.state) { |
6742 | case ATH10K_SCAN_IDLE: | |
6743 | reinit_completion(&ar->scan.started); | |
6744 | reinit_completion(&ar->scan.completed); | |
6745 | reinit_completion(&ar->scan.on_channel); | |
6746 | ar->scan.state = ATH10K_SCAN_STARTING; | |
6747 | ar->scan.is_roc = true; | |
6748 | ar->scan.vdev_id = arvif->vdev_id; | |
6749 | ar->scan.roc_freq = chan->center_freq; | |
d710e75d | 6750 | ar->scan.roc_notify = true; |
5c81c7fd MK |
6751 | ret = 0; |
6752 | break; | |
6753 | case ATH10K_SCAN_STARTING: | |
6754 | case ATH10K_SCAN_RUNNING: | |
6755 | case ATH10K_SCAN_ABORTING: | |
5e3dd157 | 6756 | ret = -EBUSY; |
5c81c7fd | 6757 | break; |
5e3dd157 | 6758 | } |
5e3dd157 KV |
6759 | spin_unlock_bh(&ar->data_lock); |
6760 | ||
5c81c7fd MK |
6761 | if (ret) |
6762 | goto exit; | |
6763 | ||
fcf98446 | 6764 | scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2; |
dcca0bdb | 6765 | |
5e3dd157 KV |
6766 | memset(&arg, 0, sizeof(arg)); |
6767 | ath10k_wmi_start_scan_init(ar, &arg); | |
6768 | arg.vdev_id = arvif->vdev_id; | |
6769 | arg.scan_id = ATH10K_SCAN_ID; | |
6770 | arg.n_channels = 1; | |
6771 | arg.channels[0] = chan->center_freq; | |
fcf98446 MK |
6772 | arg.dwell_time_active = scan_time_msec; |
6773 | arg.dwell_time_passive = scan_time_msec; | |
6774 | arg.max_scan_time = scan_time_msec; | |
5e3dd157 KV |
6775 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
6776 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; | |
dbd3f9f3 | 6777 | arg.burst_duration_ms = duration; |
5e3dd157 KV |
6778 | |
6779 | ret = ath10k_start_scan(ar, &arg); | |
6780 | if (ret) { | |
7aa7a72a | 6781 | ath10k_warn(ar, "failed to start roc scan: %d\n", ret); |
5e3dd157 | 6782 | spin_lock_bh(&ar->data_lock); |
5c81c7fd | 6783 | ar->scan.state = ATH10K_SCAN_IDLE; |
5e3dd157 KV |
6784 | spin_unlock_bh(&ar->data_lock); |
6785 | goto exit; | |
6786 | } | |
6787 | ||
14e105cd | 6788 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ); |
5e3dd157 | 6789 | if (ret == 0) { |
7aa7a72a | 6790 | ath10k_warn(ar, "failed to switch to channel for roc scan\n"); |
5c81c7fd MK |
6791 | |
6792 | ret = ath10k_scan_stop(ar); | |
6793 | if (ret) | |
7aa7a72a | 6794 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
5c81c7fd | 6795 | |
5e3dd157 KV |
6796 | ret = -ETIMEDOUT; |
6797 | goto exit; | |
6798 | } | |
6799 | ||
fcf98446 MK |
6800 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
6801 | msecs_to_jiffies(duration)); | |
6802 | ||
5e3dd157 KV |
6803 | ret = 0; |
6804 | exit: | |
6805 | mutex_unlock(&ar->conf_mutex); | |
6806 | return ret; | |
6807 | } | |
6808 | ||
6809 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw) | |
6810 | { | |
6811 | struct ath10k *ar = hw->priv; | |
6812 | ||
6813 | mutex_lock(&ar->conf_mutex); | |
d710e75d MK |
6814 | |
6815 | spin_lock_bh(&ar->data_lock); | |
6816 | ar->scan.roc_notify = false; | |
6817 | spin_unlock_bh(&ar->data_lock); | |
6818 | ||
5c81c7fd | 6819 | ath10k_scan_abort(ar); |
d710e75d | 6820 | |
5e3dd157 KV |
6821 | mutex_unlock(&ar->conf_mutex); |
6822 | ||
4eb2e164 MK |
6823 | cancel_delayed_work_sync(&ar->scan.timeout); |
6824 | ||
5e3dd157 KV |
6825 | return 0; |
6826 | } | |
6827 | ||
6828 | /* | |
6829 | * Both RTS and Fragmentation threshold are interface-specific | |
6830 | * in ath10k, but device-specific in mac80211. | |
6831 | */ | |
5e3dd157 | 6832 | |
ad088bfa MK |
6833 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
6834 | { | |
6835 | struct ath10k *ar = hw->priv; | |
6836 | struct ath10k_vif *arvif; | |
6837 | int ret = 0; | |
548db54c | 6838 | |
5e3dd157 | 6839 | mutex_lock(&ar->conf_mutex); |
ad088bfa | 6840 | list_for_each_entry(arvif, &ar->arvifs, list) { |
7aa7a72a | 6841 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n", |
ad088bfa MK |
6842 | arvif->vdev_id, value); |
6843 | ||
6844 | ret = ath10k_mac_set_rts(arvif, value); | |
6845 | if (ret) { | |
7aa7a72a | 6846 | ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n", |
ad088bfa MK |
6847 | arvif->vdev_id, ret); |
6848 | break; | |
6849 | } | |
6850 | } | |
5e3dd157 KV |
6851 | mutex_unlock(&ar->conf_mutex); |
6852 | ||
ad088bfa | 6853 | return ret; |
5e3dd157 KV |
6854 | } |
6855 | ||
92092fe5 MK |
6856 | static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
6857 | { | |
6858 | /* Even though there's a WMI enum for fragmentation threshold no known | |
6859 | * firmware actually implements it. Moreover it is not possible to rely | |
6860 | * frame fragmentation to mac80211 because firmware clears the "more | |
6861 | * fragments" bit in frame control making it impossible for remote | |
6862 | * devices to reassemble frames. | |
6863 | * | |
6864 | * Hence implement a dummy callback just to say fragmentation isn't | |
6865 | * supported. This effectively prevents mac80211 from doing frame | |
6866 | * fragmentation in software. | |
6867 | */ | |
6868 | return -EOPNOTSUPP; | |
6869 | } | |
6870 | ||
828853ac | 6871 | void ath10k_mac_wait_tx_complete(struct ath10k *ar) |
5e3dd157 | 6872 | { |
affd3217 | 6873 | bool skip; |
d4298a3a | 6874 | long time_left; |
5e3dd157 KV |
6875 | |
6876 | /* mac80211 doesn't care if we really xmit queued frames or not | |
d6dfe25c MR |
6877 | * we'll collect those frames either way if we stop/delete vdevs |
6878 | */ | |
548db54c | 6879 | |
affd3217 | 6880 | if (ar->state == ATH10K_STATE_WEDGED) |
828853ac | 6881 | return; |
affd3217 | 6882 | |
d4298a3a | 6883 | time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
5e3dd157 | 6884 | bool empty; |
affd3217 | 6885 | |
edb8236d | 6886 | spin_lock_bh(&ar->htt.tx_lock); |
0945baf7 | 6887 | empty = (ar->htt.num_pending_tx == 0); |
edb8236d | 6888 | spin_unlock_bh(&ar->htt.tx_lock); |
affd3217 | 6889 | |
7962b0d8 MK |
6890 | skip = (ar->state == ATH10K_STATE_WEDGED) || |
6891 | test_bit(ATH10K_FLAG_CRASH_FLUSH, | |
6892 | &ar->dev_flags); | |
affd3217 MK |
6893 | |
6894 | (empty || skip); | |
5e3dd157 | 6895 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
affd3217 | 6896 | |
d4298a3a NMG |
6897 | if (time_left == 0 || skip) |
6898 | ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n", | |
6899 | skip, ar->state, time_left); | |
828853ac | 6900 | } |
548db54c | 6901 | |
828853ac WG |
6902 | static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
6903 | u32 queues, bool drop) | |
6904 | { | |
6905 | struct ath10k *ar = hw->priv; | |
9de4162f WG |
6906 | struct ath10k_vif *arvif; |
6907 | u32 bitmap; | |
6908 | ||
6909 | if (drop) { | |
d987f783 | 6910 | if (vif && vif->type == NL80211_IFTYPE_STATION) { |
9de4162f WG |
6911 | bitmap = ~(1 << WMI_MGMT_TID); |
6912 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
6913 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
6914 | ath10k_wmi_peer_flush(ar, arvif->vdev_id, | |
6915 | arvif->bssid, bitmap); | |
6916 | } | |
6917 | } | |
828853ac | 6918 | return; |
9de4162f | 6919 | } |
828853ac WG |
6920 | |
6921 | mutex_lock(&ar->conf_mutex); | |
6922 | ath10k_mac_wait_tx_complete(ar); | |
548db54c | 6923 | mutex_unlock(&ar->conf_mutex); |
5e3dd157 KV |
6924 | } |
6925 | ||
6926 | /* TODO: Implement this function properly | |
6927 | * For now it is needed to reply to Probe Requests in IBSS mode. | |
6928 | * Propably we need this information from FW. | |
6929 | */ | |
6930 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) | |
6931 | { | |
6932 | return 1; | |
6933 | } | |
6934 | ||
cf2c92d8 EP |
6935 | static void ath10k_reconfig_complete(struct ieee80211_hw *hw, |
6936 | enum ieee80211_reconfig_type reconfig_type) | |
affd3217 MK |
6937 | { |
6938 | struct ath10k *ar = hw->priv; | |
6939 | ||
cf2c92d8 EP |
6940 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
6941 | return; | |
6942 | ||
affd3217 MK |
6943 | mutex_lock(&ar->conf_mutex); |
6944 | ||
6945 | /* If device failed to restart it will be in a different state, e.g. | |
d6dfe25c MR |
6946 | * ATH10K_STATE_WEDGED |
6947 | */ | |
affd3217 | 6948 | if (ar->state == ATH10K_STATE_RESTARTED) { |
7aa7a72a | 6949 | ath10k_info(ar, "device successfully recovered\n"); |
affd3217 | 6950 | ar->state = ATH10K_STATE_ON; |
7962b0d8 | 6951 | ieee80211_wake_queues(ar->hw); |
affd3217 MK |
6952 | } |
6953 | ||
6954 | mutex_unlock(&ar->conf_mutex); | |
6955 | } | |
6956 | ||
fa7937e3 RM |
6957 | static void |
6958 | ath10k_mac_update_bss_chan_survey(struct ath10k *ar, | |
6959 | struct ieee80211_channel *channel) | |
6960 | { | |
6961 | int ret; | |
6962 | enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR; | |
6963 | ||
6964 | lockdep_assert_held(&ar->conf_mutex); | |
6965 | ||
6966 | if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) || | |
6967 | (ar->rx_channel != channel)) | |
6968 | return; | |
6969 | ||
6970 | if (ar->scan.state != ATH10K_SCAN_IDLE) { | |
6971 | ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n"); | |
6972 | return; | |
6973 | } | |
6974 | ||
6975 | reinit_completion(&ar->bss_survey_done); | |
6976 | ||
6977 | ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type); | |
6978 | if (ret) { | |
6979 | ath10k_warn(ar, "failed to send pdev bss chan info request\n"); | |
6980 | return; | |
6981 | } | |
6982 | ||
6983 | ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); | |
6984 | if (!ret) { | |
6985 | ath10k_warn(ar, "bss channel survey timed out\n"); | |
6986 | return; | |
6987 | } | |
6988 | } | |
6989 | ||
2e1dea40 MK |
6990 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
6991 | struct survey_info *survey) | |
6992 | { | |
6993 | struct ath10k *ar = hw->priv; | |
6994 | struct ieee80211_supported_band *sband; | |
6995 | struct survey_info *ar_survey = &ar->survey[idx]; | |
6996 | int ret = 0; | |
6997 | ||
6998 | mutex_lock(&ar->conf_mutex); | |
6999 | ||
57fbcce3 | 7000 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; |
2e1dea40 MK |
7001 | if (sband && idx >= sband->n_channels) { |
7002 | idx -= sband->n_channels; | |
7003 | sband = NULL; | |
7004 | } | |
7005 | ||
7006 | if (!sband) | |
57fbcce3 | 7007 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; |
2e1dea40 MK |
7008 | |
7009 | if (!sband || idx >= sband->n_channels) { | |
7010 | ret = -ENOENT; | |
7011 | goto exit; | |
7012 | } | |
7013 | ||
77eb3d69 | 7014 | ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); |
fa7937e3 | 7015 | |
2e1dea40 MK |
7016 | spin_lock_bh(&ar->data_lock); |
7017 | memcpy(survey, ar_survey, sizeof(*survey)); | |
7018 | spin_unlock_bh(&ar->data_lock); | |
7019 | ||
7020 | survey->channel = &sband->channels[idx]; | |
7021 | ||
fa1d4df8 FF |
7022 | if (ar->rx_channel == survey->channel) |
7023 | survey->filled |= SURVEY_INFO_IN_USE; | |
7024 | ||
2e1dea40 MK |
7025 | exit: |
7026 | mutex_unlock(&ar->conf_mutex); | |
7027 | return ret; | |
7028 | } | |
7029 | ||
51ab1a0a | 7030 | static bool |
3ae54225 | 7031 | ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar, |
57fbcce3 | 7032 | enum nl80211_band band, |
3ae54225 | 7033 | const struct cfg80211_bitrate_mask *mask) |
51ab1a0a | 7034 | { |
3ae54225 MK |
7035 | int num_rates = 0; |
7036 | int i; | |
51ab1a0a | 7037 | |
3ae54225 | 7038 | num_rates += hweight32(mask->control[band].legacy); |
51ab1a0a | 7039 | |
3ae54225 MK |
7040 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) |
7041 | num_rates += hweight8(mask->control[band].ht_mcs[i]); | |
51ab1a0a | 7042 | |
3ae54225 MK |
7043 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) |
7044 | num_rates += hweight16(mask->control[band].vht_mcs[i]); | |
51ab1a0a | 7045 | |
3ae54225 | 7046 | return num_rates == 1; |
51ab1a0a JD |
7047 | } |
7048 | ||
7049 | static bool | |
3ae54225 | 7050 | ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar, |
57fbcce3 | 7051 | enum nl80211_band band, |
3ae54225 MK |
7052 | const struct cfg80211_bitrate_mask *mask, |
7053 | int *nss) | |
7054 | { | |
7055 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; | |
7056 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7057 | u8 ht_nss_mask = 0; | |
7058 | u8 vht_nss_mask = 0; | |
7059 | int i; | |
51ab1a0a | 7060 | |
3ae54225 | 7061 | if (mask->control[band].legacy) |
51ab1a0a JD |
7062 | return false; |
7063 | ||
3ae54225 MK |
7064 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
7065 | if (mask->control[band].ht_mcs[i] == 0) | |
51ab1a0a | 7066 | continue; |
3ae54225 MK |
7067 | else if (mask->control[band].ht_mcs[i] == |
7068 | sband->ht_cap.mcs.rx_mask[i]) | |
7069 | ht_nss_mask |= BIT(i); | |
7070 | else | |
7071 | return false; | |
51ab1a0a JD |
7072 | } |
7073 | ||
3ae54225 MK |
7074 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
7075 | if (mask->control[band].vht_mcs[i] == 0) | |
51ab1a0a | 7076 | continue; |
3ae54225 MK |
7077 | else if (mask->control[band].vht_mcs[i] == |
7078 | ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) | |
7079 | vht_nss_mask |= BIT(i); | |
7080 | else | |
7081 | return false; | |
51ab1a0a JD |
7082 | } |
7083 | ||
3ae54225 | 7084 | if (ht_nss_mask != vht_nss_mask) |
51ab1a0a JD |
7085 | return false; |
7086 | ||
3ae54225 | 7087 | if (ht_nss_mask == 0) |
51ab1a0a JD |
7088 | return false; |
7089 | ||
3ae54225 | 7090 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) |
51ab1a0a JD |
7091 | return false; |
7092 | ||
3ae54225 | 7093 | *nss = fls(ht_nss_mask); |
51ab1a0a JD |
7094 | |
7095 | return true; | |
7096 | } | |
7097 | ||
3ae54225 MK |
7098 | static int |
7099 | ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar, | |
57fbcce3 | 7100 | enum nl80211_band band, |
3ae54225 MK |
7101 | const struct cfg80211_bitrate_mask *mask, |
7102 | u8 *rate, u8 *nss) | |
51ab1a0a | 7103 | { |
3ae54225 MK |
7104 | int rate_idx; |
7105 | int i; | |
7106 | u16 bitrate; | |
7107 | u8 preamble; | |
7108 | u8 hw_rate; | |
51ab1a0a | 7109 | |
3ae54225 MK |
7110 | if (hweight32(mask->control[band].legacy) == 1) { |
7111 | rate_idx = ffs(mask->control[band].legacy) - 1; | |
51ab1a0a | 7112 | |
cd93b83a PKC |
7113 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) |
7114 | rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX; | |
7115 | ||
7116 | hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value; | |
7117 | bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate; | |
51ab1a0a | 7118 | |
3ae54225 MK |
7119 | if (ath10k_mac_bitrate_is_cck(bitrate)) |
7120 | preamble = WMI_RATE_PREAMBLE_CCK; | |
7121 | else | |
7122 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
51ab1a0a | 7123 | |
3ae54225 MK |
7124 | *nss = 1; |
7125 | *rate = preamble << 6 | | |
7126 | (*nss - 1) << 4 | | |
7127 | hw_rate << 0; | |
51ab1a0a | 7128 | |
3ae54225 | 7129 | return 0; |
51ab1a0a JD |
7130 | } |
7131 | ||
3ae54225 MK |
7132 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
7133 | if (hweight8(mask->control[band].ht_mcs[i]) == 1) { | |
7134 | *nss = i + 1; | |
7135 | *rate = WMI_RATE_PREAMBLE_HT << 6 | | |
7136 | (*nss - 1) << 4 | | |
7137 | (ffs(mask->control[band].ht_mcs[i]) - 1); | |
51ab1a0a | 7138 | |
3ae54225 MK |
7139 | return 0; |
7140 | } | |
7141 | } | |
51ab1a0a | 7142 | |
3ae54225 MK |
7143 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
7144 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { | |
7145 | *nss = i + 1; | |
7146 | *rate = WMI_RATE_PREAMBLE_VHT << 6 | | |
7147 | (*nss - 1) << 4 | | |
7148 | (ffs(mask->control[band].vht_mcs[i]) - 1); | |
51ab1a0a | 7149 | |
3ae54225 MK |
7150 | return 0; |
7151 | } | |
7152 | } | |
51ab1a0a | 7153 | |
3ae54225 | 7154 | return -EINVAL; |
51ab1a0a JD |
7155 | } |
7156 | ||
3ae54225 | 7157 | static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif, |
bd4a41e6 | 7158 | u8 rate, u8 nss, u8 sgi, u8 ldpc) |
51ab1a0a JD |
7159 | { |
7160 | struct ath10k *ar = arvif->ar; | |
7161 | u32 vdev_param; | |
3ae54225 | 7162 | int ret; |
51ab1a0a | 7163 | |
3ae54225 | 7164 | lockdep_assert_held(&ar->conf_mutex); |
51ab1a0a | 7165 | |
3ae54225 MK |
7166 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n", |
7167 | arvif->vdev_id, rate, nss, sgi); | |
9f81f725 | 7168 | |
51ab1a0a | 7169 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
3ae54225 | 7170 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate); |
51ab1a0a | 7171 | if (ret) { |
7aa7a72a | 7172 | ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n", |
3ae54225 MK |
7173 | rate, ret); |
7174 | return ret; | |
51ab1a0a JD |
7175 | } |
7176 | ||
51ab1a0a | 7177 | vdev_param = ar->wmi.vdev_param->nss; |
3ae54225 | 7178 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss); |
51ab1a0a | 7179 | if (ret) { |
3ae54225 MK |
7180 | ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret); |
7181 | return ret; | |
51ab1a0a | 7182 | } |
51ab1a0a | 7183 | |
9f81f725 | 7184 | vdev_param = ar->wmi.vdev_param->sgi; |
3ae54225 | 7185 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi); |
51ab1a0a | 7186 | if (ret) { |
3ae54225 MK |
7187 | ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret); |
7188 | return ret; | |
51ab1a0a JD |
7189 | } |
7190 | ||
bd4a41e6 RM |
7191 | vdev_param = ar->wmi.vdev_param->ldpc; |
7192 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc); | |
7193 | if (ret) { | |
7194 | ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret); | |
7195 | return ret; | |
7196 | } | |
7197 | ||
3ae54225 | 7198 | return 0; |
51ab1a0a | 7199 | } |
51ab1a0a | 7200 | |
45c9abc0 MK |
7201 | static bool |
7202 | ath10k_mac_can_set_bitrate_mask(struct ath10k *ar, | |
57fbcce3 | 7203 | enum nl80211_band band, |
45c9abc0 MK |
7204 | const struct cfg80211_bitrate_mask *mask) |
7205 | { | |
7206 | int i; | |
7207 | u16 vht_mcs; | |
9f81f725 | 7208 | |
45c9abc0 MK |
7209 | /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible |
7210 | * to express all VHT MCS rate masks. Effectively only the following | |
7211 | * ranges can be used: none, 0-7, 0-8 and 0-9. | |
7212 | */ | |
7213 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7214 | vht_mcs = mask->control[band].vht_mcs[i]; | |
7215 | ||
7216 | switch (vht_mcs) { | |
7217 | case 0: | |
7218 | case BIT(8) - 1: | |
7219 | case BIT(9) - 1: | |
7220 | case BIT(10) - 1: | |
7221 | break; | |
7222 | default: | |
7223 | ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n"); | |
7224 | return false; | |
7225 | } | |
9f81f725 JD |
7226 | } |
7227 | ||
45c9abc0 MK |
7228 | return true; |
7229 | } | |
9f81f725 | 7230 | |
45c9abc0 MK |
7231 | static void ath10k_mac_set_bitrate_mask_iter(void *data, |
7232 | struct ieee80211_sta *sta) | |
7233 | { | |
7234 | struct ath10k_vif *arvif = data; | |
7235 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; | |
7236 | struct ath10k *ar = arvif->ar; | |
7237 | ||
7238 | if (arsta->arvif != arvif) | |
7239 | return; | |
7240 | ||
7241 | spin_lock_bh(&ar->data_lock); | |
7242 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; | |
7243 | spin_unlock_bh(&ar->data_lock); | |
7244 | ||
7245 | ieee80211_queue_work(ar->hw, &arsta->update_wk); | |
51ab1a0a JD |
7246 | } |
7247 | ||
3ae54225 MK |
7248 | static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, |
7249 | struct ieee80211_vif *vif, | |
7250 | const struct cfg80211_bitrate_mask *mask) | |
51ab1a0a | 7251 | { |
56ac13bf | 7252 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
500ff9f9 | 7253 | struct cfg80211_chan_def def; |
51ab1a0a | 7254 | struct ath10k *ar = arvif->ar; |
57fbcce3 | 7255 | enum nl80211_band band; |
45c9abc0 MK |
7256 | const u8 *ht_mcs_mask; |
7257 | const u16 *vht_mcs_mask; | |
3ae54225 MK |
7258 | u8 rate; |
7259 | u8 nss; | |
7260 | u8 sgi; | |
bd4a41e6 | 7261 | u8 ldpc; |
3ae54225 MK |
7262 | int single_nss; |
7263 | int ret; | |
9f81f725 | 7264 | |
500ff9f9 MK |
7265 | if (ath10k_mac_vif_chan(vif, &def)) |
7266 | return -EPERM; | |
b116ea19 | 7267 | |
500ff9f9 | 7268 | band = def.chan->band; |
45c9abc0 MK |
7269 | ht_mcs_mask = mask->control[band].ht_mcs; |
7270 | vht_mcs_mask = mask->control[band].vht_mcs; | |
bd4a41e6 | 7271 | ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); |
b116ea19 | 7272 | |
3ae54225 MK |
7273 | sgi = mask->control[band].gi; |
7274 | if (sgi == NL80211_TXRATE_FORCE_LGI) | |
9f81f725 | 7275 | return -EINVAL; |
51ab1a0a | 7276 | |
3ae54225 MK |
7277 | if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) { |
7278 | ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask, | |
7279 | &rate, &nss); | |
7280 | if (ret) { | |
7281 | ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n", | |
7282 | arvif->vdev_id, ret); | |
7283 | return ret; | |
7284 | } | |
7285 | } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask, | |
7286 | &single_nss)) { | |
7287 | rate = WMI_FIXED_RATE_NONE; | |
7288 | nss = single_nss; | |
7289 | } else { | |
7290 | rate = WMI_FIXED_RATE_NONE; | |
45c9abc0 MK |
7291 | nss = min(ar->num_rf_chains, |
7292 | max(ath10k_mac_max_ht_nss(ht_mcs_mask), | |
7293 | ath10k_mac_max_vht_nss(vht_mcs_mask))); | |
7294 | ||
7295 | if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask)) | |
51ab1a0a | 7296 | return -EINVAL; |
45c9abc0 MK |
7297 | |
7298 | mutex_lock(&ar->conf_mutex); | |
7299 | ||
7300 | arvif->bitrate_mask = *mask; | |
7301 | ieee80211_iterate_stations_atomic(ar->hw, | |
7302 | ath10k_mac_set_bitrate_mask_iter, | |
7303 | arvif); | |
7304 | ||
7305 | mutex_unlock(&ar->conf_mutex); | |
51ab1a0a JD |
7306 | } |
7307 | ||
3ae54225 MK |
7308 | mutex_lock(&ar->conf_mutex); |
7309 | ||
bd4a41e6 | 7310 | ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); |
3ae54225 MK |
7311 | if (ret) { |
7312 | ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n", | |
7313 | arvif->vdev_id, ret); | |
7314 | goto exit; | |
9f81f725 JD |
7315 | } |
7316 | ||
3ae54225 MK |
7317 | exit: |
7318 | mutex_unlock(&ar->conf_mutex); | |
7319 | ||
7320 | return ret; | |
51ab1a0a JD |
7321 | } |
7322 | ||
9797febc MK |
7323 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
7324 | struct ieee80211_vif *vif, | |
7325 | struct ieee80211_sta *sta, | |
7326 | u32 changed) | |
7327 | { | |
7328 | struct ath10k *ar = hw->priv; | |
7329 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; | |
8b2d93dd KP |
7330 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
7331 | struct ath10k_peer *peer; | |
9797febc MK |
7332 | u32 bw, smps; |
7333 | ||
7334 | spin_lock_bh(&ar->data_lock); | |
7335 | ||
8b2d93dd KP |
7336 | peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr); |
7337 | if (!peer) { | |
7338 | spin_unlock_bh(&ar->data_lock); | |
7339 | ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n", | |
7340 | sta->addr, arvif->vdev_id); | |
7341 | return; | |
7342 | } | |
7343 | ||
7aa7a72a | 7344 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
9797febc MK |
7345 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
7346 | sta->addr, changed, sta->bandwidth, sta->rx_nss, | |
7347 | sta->smps_mode); | |
7348 | ||
7349 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
7350 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
7351 | ||
7352 | switch (sta->bandwidth) { | |
7353 | case IEEE80211_STA_RX_BW_20: | |
7354 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
7355 | break; | |
7356 | case IEEE80211_STA_RX_BW_40: | |
7357 | bw = WMI_PEER_CHWIDTH_40MHZ; | |
7358 | break; | |
7359 | case IEEE80211_STA_RX_BW_80: | |
7360 | bw = WMI_PEER_CHWIDTH_80MHZ; | |
7361 | break; | |
7362 | case IEEE80211_STA_RX_BW_160: | |
bc1efd73 SG |
7363 | bw = WMI_PEER_CHWIDTH_160MHZ; |
7364 | break; | |
7365 | default: | |
d939be3a | 7366 | ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n", |
be6546fc | 7367 | sta->bandwidth, sta->addr); |
9797febc MK |
7368 | bw = WMI_PEER_CHWIDTH_20MHZ; |
7369 | break; | |
7370 | } | |
7371 | ||
7372 | arsta->bw = bw; | |
7373 | } | |
7374 | ||
7375 | if (changed & IEEE80211_RC_NSS_CHANGED) | |
7376 | arsta->nss = sta->rx_nss; | |
7377 | ||
7378 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
7379 | smps = WMI_PEER_SMPS_PS_NONE; | |
7380 | ||
7381 | switch (sta->smps_mode) { | |
7382 | case IEEE80211_SMPS_AUTOMATIC: | |
7383 | case IEEE80211_SMPS_OFF: | |
7384 | smps = WMI_PEER_SMPS_PS_NONE; | |
7385 | break; | |
7386 | case IEEE80211_SMPS_STATIC: | |
7387 | smps = WMI_PEER_SMPS_STATIC; | |
7388 | break; | |
7389 | case IEEE80211_SMPS_DYNAMIC: | |
7390 | smps = WMI_PEER_SMPS_DYNAMIC; | |
7391 | break; | |
7392 | case IEEE80211_SMPS_NUM_MODES: | |
7aa7a72a | 7393 | ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n", |
be6546fc | 7394 | sta->smps_mode, sta->addr); |
9797febc MK |
7395 | smps = WMI_PEER_SMPS_PS_NONE; |
7396 | break; | |
7397 | } | |
7398 | ||
7399 | arsta->smps = smps; | |
7400 | } | |
7401 | ||
9797febc MK |
7402 | arsta->changed |= changed; |
7403 | ||
7404 | spin_unlock_bh(&ar->data_lock); | |
7405 | ||
7406 | ieee80211_queue_work(hw, &arsta->update_wk); | |
7407 | } | |
7408 | ||
973324ff PT |
7409 | static void ath10k_offset_tsf(struct ieee80211_hw *hw, |
7410 | struct ieee80211_vif *vif, s64 tsf_offset) | |
9f0b7e7d PO |
7411 | { |
7412 | struct ath10k *ar = hw->priv; | |
56ac13bf | 7413 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
973324ff | 7414 | u32 offset, vdev_param; |
9f0b7e7d PO |
7415 | int ret; |
7416 | ||
973324ff PT |
7417 | if (tsf_offset < 0) { |
7418 | vdev_param = ar->wmi.vdev_param->dec_tsf; | |
7419 | offset = -tsf_offset; | |
7420 | } else { | |
7421 | vdev_param = ar->wmi.vdev_param->inc_tsf; | |
7422 | offset = tsf_offset; | |
7423 | } | |
7424 | ||
9f0b7e7d | 7425 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
973324ff PT |
7426 | vdev_param, offset); |
7427 | ||
9f0b7e7d | 7428 | if (ret && ret != -EOPNOTSUPP) |
973324ff PT |
7429 | ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n", |
7430 | offset, vdev_param, ret); | |
9f0b7e7d PO |
7431 | } |
7432 | ||
aa5b4fbc MK |
7433 | static int ath10k_ampdu_action(struct ieee80211_hw *hw, |
7434 | struct ieee80211_vif *vif, | |
50ea05ef | 7435 | struct ieee80211_ampdu_params *params) |
aa5b4fbc | 7436 | { |
7aa7a72a | 7437 | struct ath10k *ar = hw->priv; |
56ac13bf | 7438 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
50ea05ef SS |
7439 | struct ieee80211_sta *sta = params->sta; |
7440 | enum ieee80211_ampdu_mlme_action action = params->action; | |
7441 | u16 tid = params->tid; | |
aa5b4fbc | 7442 | |
7aa7a72a | 7443 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n", |
aa5b4fbc MK |
7444 | arvif->vdev_id, sta->addr, tid, action); |
7445 | ||
7446 | switch (action) { | |
7447 | case IEEE80211_AMPDU_RX_START: | |
7448 | case IEEE80211_AMPDU_RX_STOP: | |
7449 | /* HTT AddBa/DelBa events trigger mac80211 Rx BA session | |
7450 | * creation/removal. Do we need to verify this? | |
7451 | */ | |
7452 | return 0; | |
7453 | case IEEE80211_AMPDU_TX_START: | |
7454 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
7455 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
7456 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
7457 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
7458 | /* Firmware offloads Tx aggregation entirely so deny mac80211 | |
7459 | * Tx aggregation requests. | |
7460 | */ | |
7461 | return -EOPNOTSUPP; | |
7462 | } | |
7463 | ||
7464 | return -EINVAL; | |
7465 | } | |
7466 | ||
500ff9f9 | 7467 | static void |
d7bf4b4a MK |
7468 | ath10k_mac_update_rx_channel(struct ath10k *ar, |
7469 | struct ieee80211_chanctx_conf *ctx, | |
7470 | struct ieee80211_vif_chanctx_switch *vifs, | |
7471 | int n_vifs) | |
500ff9f9 MK |
7472 | { |
7473 | struct cfg80211_chan_def *def = NULL; | |
7474 | ||
7475 | /* Both locks are required because ar->rx_channel is modified. This | |
7476 | * allows readers to hold either lock. | |
7477 | */ | |
7478 | lockdep_assert_held(&ar->conf_mutex); | |
7479 | lockdep_assert_held(&ar->data_lock); | |
7480 | ||
d7bf4b4a | 7481 | WARN_ON(ctx && vifs); |
c73f8c00 | 7482 | WARN_ON(vifs && !n_vifs); |
d7bf4b4a | 7483 | |
500ff9f9 MK |
7484 | /* FIXME: Sort of an optimization and a workaround. Peers and vifs are |
7485 | * on a linked list now. Doing a lookup peer -> vif -> chanctx for each | |
7486 | * ppdu on Rx may reduce performance on low-end systems. It should be | |
7487 | * possible to make tables/hashmaps to speed the lookup up (be vary of | |
7488 | * cpu data cache lines though regarding sizes) but to keep the initial | |
7489 | * implementation simple and less intrusive fallback to the slow lookup | |
7490 | * only for multi-channel cases. Single-channel cases will remain to | |
7491 | * use the old channel derival and thus performance should not be | |
7492 | * affected much. | |
7493 | */ | |
7494 | rcu_read_lock(); | |
d7bf4b4a | 7495 | if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) { |
500ff9f9 | 7496 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
617b0f4d KV |
7497 | ath10k_mac_get_any_chandef_iter, |
7498 | &def); | |
d7bf4b4a MK |
7499 | |
7500 | if (vifs) | |
7501 | def = &vifs[0].new_ctx->def; | |
7502 | ||
500ff9f9 | 7503 | ar->rx_channel = def->chan; |
1ce8c148 RM |
7504 | } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) || |
7505 | (ctx && (ar->state == ATH10K_STATE_RESTARTED))) { | |
7506 | /* During driver restart due to firmware assert, since mac80211 | |
7507 | * already has valid channel context for given radio, channel | |
7508 | * context iteration return num_chanctx > 0. So fix rx_channel | |
7509 | * when restart is in progress. | |
7510 | */ | |
d7bf4b4a | 7511 | ar->rx_channel = ctx->def.chan; |
500ff9f9 MK |
7512 | } else { |
7513 | ar->rx_channel = NULL; | |
7514 | } | |
7515 | rcu_read_unlock(); | |
7516 | } | |
7517 | ||
7be6d1b7 MK |
7518 | static void |
7519 | ath10k_mac_update_vif_chan(struct ath10k *ar, | |
7520 | struct ieee80211_vif_chanctx_switch *vifs, | |
7521 | int n_vifs) | |
7522 | { | |
7523 | struct ath10k_vif *arvif; | |
7524 | int ret; | |
7525 | int i; | |
7526 | ||
7527 | lockdep_assert_held(&ar->conf_mutex); | |
7528 | ||
7529 | /* First stop monitor interface. Some FW versions crash if there's a | |
7530 | * lone monitor interface. | |
7531 | */ | |
7532 | if (ar->monitor_started) | |
7533 | ath10k_monitor_stop(ar); | |
7534 | ||
7535 | for (i = 0; i < n_vifs; i++) { | |
56ac13bf | 7536 | arvif = (void *)vifs[i].vif->drv_priv; |
7be6d1b7 MK |
7537 | |
7538 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
7539 | "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n", | |
7540 | arvif->vdev_id, | |
7541 | vifs[i].old_ctx->def.chan->center_freq, | |
7542 | vifs[i].new_ctx->def.chan->center_freq, | |
7543 | vifs[i].old_ctx->def.width, | |
7544 | vifs[i].new_ctx->def.width); | |
7545 | ||
7546 | if (WARN_ON(!arvif->is_started)) | |
7547 | continue; | |
7548 | ||
7549 | if (WARN_ON(!arvif->is_up)) | |
7550 | continue; | |
7551 | ||
7552 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); | |
7553 | if (ret) { | |
7554 | ath10k_warn(ar, "failed to down vdev %d: %d\n", | |
7555 | arvif->vdev_id, ret); | |
7556 | continue; | |
7557 | } | |
7558 | } | |
7559 | ||
7560 | /* All relevant vdevs are downed and associated channel resources | |
7561 | * should be available for the channel switch now. | |
7562 | */ | |
7563 | ||
7564 | spin_lock_bh(&ar->data_lock); | |
7565 | ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs); | |
7566 | spin_unlock_bh(&ar->data_lock); | |
7567 | ||
7568 | for (i = 0; i < n_vifs; i++) { | |
56ac13bf | 7569 | arvif = (void *)vifs[i].vif->drv_priv; |
7be6d1b7 MK |
7570 | |
7571 | if (WARN_ON(!arvif->is_started)) | |
7572 | continue; | |
7573 | ||
7574 | if (WARN_ON(!arvif->is_up)) | |
7575 | continue; | |
7576 | ||
7577 | ret = ath10k_mac_setup_bcn_tmpl(arvif); | |
7578 | if (ret) | |
7579 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", | |
7580 | ret); | |
7581 | ||
7582 | ret = ath10k_mac_setup_prb_tmpl(arvif); | |
7583 | if (ret) | |
7584 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", | |
7585 | ret); | |
7586 | ||
7587 | ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def); | |
7588 | if (ret) { | |
7589 | ath10k_warn(ar, "failed to restart vdev %d: %d\n", | |
7590 | arvif->vdev_id, ret); | |
7591 | continue; | |
7592 | } | |
7593 | ||
7594 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
7595 | arvif->bssid); | |
7596 | if (ret) { | |
7597 | ath10k_warn(ar, "failed to bring vdev up %d: %d\n", | |
7598 | arvif->vdev_id, ret); | |
7599 | continue; | |
7600 | } | |
7601 | } | |
7602 | ||
7603 | ath10k_monitor_recalc(ar); | |
7604 | } | |
7605 | ||
500ff9f9 MK |
7606 | static int |
7607 | ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw, | |
7608 | struct ieee80211_chanctx_conf *ctx) | |
7609 | { | |
7610 | struct ath10k *ar = hw->priv; | |
500ff9f9 MK |
7611 | |
7612 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
75b34800 | 7613 | "mac chanctx add freq %hu width %d ptr %pK\n", |
500ff9f9 MK |
7614 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
7615 | ||
7616 | mutex_lock(&ar->conf_mutex); | |
7617 | ||
7618 | spin_lock_bh(&ar->data_lock); | |
d7bf4b4a | 7619 | ath10k_mac_update_rx_channel(ar, ctx, NULL, 0); |
500ff9f9 MK |
7620 | spin_unlock_bh(&ar->data_lock); |
7621 | ||
7622 | ath10k_recalc_radar_detection(ar); | |
7623 | ath10k_monitor_recalc(ar); | |
7624 | ||
7625 | mutex_unlock(&ar->conf_mutex); | |
7626 | ||
7627 | return 0; | |
7628 | } | |
7629 | ||
7630 | static void | |
7631 | ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw, | |
7632 | struct ieee80211_chanctx_conf *ctx) | |
7633 | { | |
7634 | struct ath10k *ar = hw->priv; | |
7635 | ||
7636 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
75b34800 | 7637 | "mac chanctx remove freq %hu width %d ptr %pK\n", |
500ff9f9 MK |
7638 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
7639 | ||
7640 | mutex_lock(&ar->conf_mutex); | |
7641 | ||
7642 | spin_lock_bh(&ar->data_lock); | |
d7bf4b4a | 7643 | ath10k_mac_update_rx_channel(ar, NULL, NULL, 0); |
500ff9f9 MK |
7644 | spin_unlock_bh(&ar->data_lock); |
7645 | ||
7646 | ath10k_recalc_radar_detection(ar); | |
7647 | ath10k_monitor_recalc(ar); | |
7648 | ||
7649 | mutex_unlock(&ar->conf_mutex); | |
7650 | } | |
7651 | ||
9713e3de MK |
7652 | struct ath10k_mac_change_chanctx_arg { |
7653 | struct ieee80211_chanctx_conf *ctx; | |
7654 | struct ieee80211_vif_chanctx_switch *vifs; | |
7655 | int n_vifs; | |
7656 | int next_vif; | |
7657 | }; | |
7658 | ||
7659 | static void | |
7660 | ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, | |
7661 | struct ieee80211_vif *vif) | |
7662 | { | |
7663 | struct ath10k_mac_change_chanctx_arg *arg = data; | |
7664 | ||
7665 | if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx) | |
7666 | return; | |
7667 | ||
7668 | arg->n_vifs++; | |
7669 | } | |
7670 | ||
7671 | static void | |
7672 | ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac, | |
7673 | struct ieee80211_vif *vif) | |
7674 | { | |
7675 | struct ath10k_mac_change_chanctx_arg *arg = data; | |
7676 | struct ieee80211_chanctx_conf *ctx; | |
7677 | ||
7678 | ctx = rcu_access_pointer(vif->chanctx_conf); | |
7679 | if (ctx != arg->ctx) | |
7680 | return; | |
7681 | ||
7682 | if (WARN_ON(arg->next_vif == arg->n_vifs)) | |
7683 | return; | |
7684 | ||
7685 | arg->vifs[arg->next_vif].vif = vif; | |
7686 | arg->vifs[arg->next_vif].old_ctx = ctx; | |
7687 | arg->vifs[arg->next_vif].new_ctx = ctx; | |
7688 | arg->next_vif++; | |
7689 | } | |
7690 | ||
500ff9f9 MK |
7691 | static void |
7692 | ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw, | |
7693 | struct ieee80211_chanctx_conf *ctx, | |
7694 | u32 changed) | |
7695 | { | |
7696 | struct ath10k *ar = hw->priv; | |
9713e3de | 7697 | struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx }; |
500ff9f9 MK |
7698 | |
7699 | mutex_lock(&ar->conf_mutex); | |
7700 | ||
7701 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
75b34800 | 7702 | "mac chanctx change freq %hu width %d ptr %pK changed %x\n", |
089ab7a5 | 7703 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); |
500ff9f9 MK |
7704 | |
7705 | /* This shouldn't really happen because channel switching should use | |
7706 | * switch_vif_chanctx(). | |
7707 | */ | |
7708 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) | |
7709 | goto unlock; | |
7710 | ||
9713e3de MK |
7711 | if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) { |
7712 | ieee80211_iterate_active_interfaces_atomic( | |
7713 | hw, | |
7714 | IEEE80211_IFACE_ITER_NORMAL, | |
7715 | ath10k_mac_change_chanctx_cnt_iter, | |
7716 | &arg); | |
7717 | if (arg.n_vifs == 0) | |
7718 | goto radar; | |
7719 | ||
7720 | arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), | |
7721 | GFP_KERNEL); | |
7722 | if (!arg.vifs) | |
7723 | goto radar; | |
7724 | ||
7725 | ieee80211_iterate_active_interfaces_atomic( | |
7726 | hw, | |
7727 | IEEE80211_IFACE_ITER_NORMAL, | |
7728 | ath10k_mac_change_chanctx_fill_iter, | |
7729 | &arg); | |
7730 | ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); | |
7731 | kfree(arg.vifs); | |
7732 | } | |
7733 | ||
7734 | radar: | |
500ff9f9 MK |
7735 | ath10k_recalc_radar_detection(ar); |
7736 | ||
7737 | /* FIXME: How to configure Rx chains properly? */ | |
7738 | ||
7739 | /* No other actions are actually necessary. Firmware maintains channel | |
7740 | * definitions per vdev internally and there's no host-side channel | |
7741 | * context abstraction to configure, e.g. channel width. | |
7742 | */ | |
7743 | ||
7744 | unlock: | |
7745 | mutex_unlock(&ar->conf_mutex); | |
7746 | } | |
7747 | ||
7748 | static int | |
7749 | ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, | |
7750 | struct ieee80211_vif *vif, | |
7751 | struct ieee80211_chanctx_conf *ctx) | |
7752 | { | |
7753 | struct ath10k *ar = hw->priv; | |
500ff9f9 MK |
7754 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
7755 | int ret; | |
7756 | ||
7757 | mutex_lock(&ar->conf_mutex); | |
7758 | ||
7759 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
75b34800 | 7760 | "mac chanctx assign ptr %pK vdev_id %i\n", |
500ff9f9 MK |
7761 | ctx, arvif->vdev_id); |
7762 | ||
7763 | if (WARN_ON(arvif->is_started)) { | |
7764 | mutex_unlock(&ar->conf_mutex); | |
7765 | return -EBUSY; | |
7766 | } | |
7767 | ||
089ab7a5 | 7768 | ret = ath10k_vdev_start(arvif, &ctx->def); |
500ff9f9 MK |
7769 | if (ret) { |
7770 | ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
7771 | arvif->vdev_id, vif->addr, | |
089ab7a5 | 7772 | ctx->def.chan->center_freq, ret); |
500ff9f9 MK |
7773 | goto err; |
7774 | } | |
7775 | ||
7776 | arvif->is_started = true; | |
7777 | ||
f23e587e MK |
7778 | ret = ath10k_mac_vif_setup_ps(arvif); |
7779 | if (ret) { | |
7780 | ath10k_warn(ar, "failed to update vdev %i ps: %d\n", | |
7781 | arvif->vdev_id, ret); | |
7782 | goto err_stop; | |
7783 | } | |
7784 | ||
500ff9f9 MK |
7785 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
7786 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr); | |
7787 | if (ret) { | |
7788 | ath10k_warn(ar, "failed to up monitor vdev %i: %d\n", | |
7789 | arvif->vdev_id, ret); | |
7790 | goto err_stop; | |
7791 | } | |
7792 | ||
7793 | arvif->is_up = true; | |
7794 | } | |
7795 | ||
7cfe0455 BM |
7796 | if (ath10k_mac_can_set_cts_prot(arvif)) { |
7797 | ret = ath10k_mac_set_cts_prot(arvif); | |
7798 | if (ret) | |
7799 | ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n", | |
7800 | arvif->vdev_id, ret); | |
7801 | } | |
7802 | ||
e8123bb7 AK |
7803 | if (ath10k_peer_stats_enabled(ar)) { |
7804 | ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS; | |
7805 | ret = ath10k_wmi_pdev_pktlog_enable(ar, | |
7806 | ar->pktlog_filter); | |
7807 | if (ret) { | |
7808 | ath10k_warn(ar, "failed to enable pktlog %d\n", ret); | |
7809 | goto err_stop; | |
7810 | } | |
7811 | } | |
7812 | ||
500ff9f9 MK |
7813 | mutex_unlock(&ar->conf_mutex); |
7814 | return 0; | |
7815 | ||
7816 | err_stop: | |
7817 | ath10k_vdev_stop(arvif); | |
7818 | arvif->is_started = false; | |
f23e587e | 7819 | ath10k_mac_vif_setup_ps(arvif); |
500ff9f9 MK |
7820 | |
7821 | err: | |
7822 | mutex_unlock(&ar->conf_mutex); | |
7823 | return ret; | |
7824 | } | |
7825 | ||
7826 | static void | |
7827 | ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
7828 | struct ieee80211_vif *vif, | |
7829 | struct ieee80211_chanctx_conf *ctx) | |
7830 | { | |
7831 | struct ath10k *ar = hw->priv; | |
7832 | struct ath10k_vif *arvif = (void *)vif->drv_priv; | |
7833 | int ret; | |
7834 | ||
7835 | mutex_lock(&ar->conf_mutex); | |
7836 | ||
7837 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
75b34800 | 7838 | "mac chanctx unassign ptr %pK vdev_id %i\n", |
500ff9f9 MK |
7839 | ctx, arvif->vdev_id); |
7840 | ||
7841 | WARN_ON(!arvif->is_started); | |
7842 | ||
7843 | if (vif->type == NL80211_IFTYPE_MONITOR) { | |
7844 | WARN_ON(!arvif->is_up); | |
7845 | ||
7846 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); | |
7847 | if (ret) | |
7848 | ath10k_warn(ar, "failed to down monitor vdev %i: %d\n", | |
7849 | arvif->vdev_id, ret); | |
7850 | ||
7851 | arvif->is_up = false; | |
7852 | } | |
7853 | ||
7854 | ret = ath10k_vdev_stop(arvif); | |
7855 | if (ret) | |
7856 | ath10k_warn(ar, "failed to stop vdev %i: %d\n", | |
7857 | arvif->vdev_id, ret); | |
7858 | ||
7859 | arvif->is_started = false; | |
7860 | ||
7861 | mutex_unlock(&ar->conf_mutex); | |
7862 | } | |
7863 | ||
7864 | static int | |
7865 | ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, | |
7866 | struct ieee80211_vif_chanctx_switch *vifs, | |
7867 | int n_vifs, | |
7868 | enum ieee80211_chanctx_switch_mode mode) | |
7869 | { | |
7870 | struct ath10k *ar = hw->priv; | |
500ff9f9 MK |
7871 | |
7872 | mutex_lock(&ar->conf_mutex); | |
7873 | ||
7874 | ath10k_dbg(ar, ATH10K_DBG_MAC, | |
7875 | "mac chanctx switch n_vifs %d mode %d\n", | |
7876 | n_vifs, mode); | |
7be6d1b7 | 7877 | ath10k_mac_update_vif_chan(ar, vifs, n_vifs); |
500ff9f9 MK |
7878 | |
7879 | mutex_unlock(&ar->conf_mutex); | |
7880 | return 0; | |
7881 | } | |
7882 | ||
0a744d92 MK |
7883 | static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
7884 | struct ieee80211_vif *vif, | |
7885 | struct ieee80211_sta *sta) | |
7886 | { | |
7887 | struct ath10k *ar; | |
7888 | struct ath10k_peer *peer; | |
7889 | ||
7890 | ar = hw->priv; | |
7891 | ||
7892 | list_for_each_entry(peer, &ar->peers, list) | |
7893 | if (peer->sta == sta) | |
7894 | peer->removed = true; | |
7895 | } | |
7896 | ||
6a7f8911 AK |
7897 | static void ath10k_sta_statistics(struct ieee80211_hw *hw, |
7898 | struct ieee80211_vif *vif, | |
7899 | struct ieee80211_sta *sta, | |
7900 | struct station_info *sinfo) | |
7901 | { | |
7902 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; | |
7903 | struct ath10k *ar = arsta->arvif->ar; | |
7904 | ||
7905 | if (!ath10k_peer_stats_enabled(ar)) | |
7906 | return; | |
7907 | ||
7908 | sinfo->rx_duration = arsta->rx_duration; | |
22d0d2fa | 7909 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); |
6a7f8911 AK |
7910 | |
7911 | if (!arsta->txrate.legacy && !arsta->txrate.nss) | |
7912 | return; | |
7913 | ||
7914 | if (arsta->txrate.legacy) { | |
7915 | sinfo->txrate.legacy = arsta->txrate.legacy; | |
7916 | } else { | |
7917 | sinfo->txrate.mcs = arsta->txrate.mcs; | |
7918 | sinfo->txrate.nss = arsta->txrate.nss; | |
7919 | sinfo->txrate.bw = arsta->txrate.bw; | |
7920 | } | |
7921 | sinfo->txrate.flags = arsta->txrate.flags; | |
22d0d2fa | 7922 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); |
6a7f8911 AK |
7923 | } |
7924 | ||
5e3dd157 | 7925 | static const struct ieee80211_ops ath10k_ops = { |
f2f6ecab | 7926 | .tx = ath10k_mac_op_tx, |
29946878 | 7927 | .wake_tx_queue = ath10k_mac_op_wake_tx_queue, |
5e3dd157 KV |
7928 | .start = ath10k_start, |
7929 | .stop = ath10k_stop, | |
7930 | .config = ath10k_config, | |
7931 | .add_interface = ath10k_add_interface, | |
7932 | .remove_interface = ath10k_remove_interface, | |
7933 | .configure_filter = ath10k_configure_filter, | |
7934 | .bss_info_changed = ath10k_bss_info_changed, | |
ebee76f7 | 7935 | .set_coverage_class = ath10k_mac_op_set_coverage_class, |
5e3dd157 KV |
7936 | .hw_scan = ath10k_hw_scan, |
7937 | .cancel_hw_scan = ath10k_cancel_hw_scan, | |
7938 | .set_key = ath10k_set_key, | |
627613f8 | 7939 | .set_default_unicast_key = ath10k_set_default_unicast_key, |
5e3dd157 KV |
7940 | .sta_state = ath10k_sta_state, |
7941 | .conf_tx = ath10k_conf_tx, | |
7942 | .remain_on_channel = ath10k_remain_on_channel, | |
7943 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, | |
7944 | .set_rts_threshold = ath10k_set_rts_threshold, | |
92092fe5 | 7945 | .set_frag_threshold = ath10k_mac_op_set_frag_threshold, |
5e3dd157 KV |
7946 | .flush = ath10k_flush, |
7947 | .tx_last_beacon = ath10k_tx_last_beacon, | |
46acf7bb BG |
7948 | .set_antenna = ath10k_set_antenna, |
7949 | .get_antenna = ath10k_get_antenna, | |
cf2c92d8 | 7950 | .reconfig_complete = ath10k_reconfig_complete, |
2e1dea40 | 7951 | .get_survey = ath10k_get_survey, |
3ae54225 | 7952 | .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask, |
9797febc | 7953 | .sta_rc_update = ath10k_sta_rc_update, |
973324ff | 7954 | .offset_tsf = ath10k_offset_tsf, |
aa5b4fbc | 7955 | .ampdu_action = ath10k_ampdu_action, |
6cddcc7a BG |
7956 | .get_et_sset_count = ath10k_debug_get_et_sset_count, |
7957 | .get_et_stats = ath10k_debug_get_et_stats, | |
7958 | .get_et_strings = ath10k_debug_get_et_strings, | |
500ff9f9 MK |
7959 | .add_chanctx = ath10k_mac_op_add_chanctx, |
7960 | .remove_chanctx = ath10k_mac_op_remove_chanctx, | |
7961 | .change_chanctx = ath10k_mac_op_change_chanctx, | |
7962 | .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx, | |
7963 | .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx, | |
7964 | .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx, | |
0a744d92 | 7965 | .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove, |
6a7f8911 | 7966 | .sta_statistics = ath10k_sta_statistics, |
43d2a30f KV |
7967 | |
7968 | CFG80211_TESTMODE_CMD(ath10k_tm_cmd) | |
7969 | ||
8cd13cad | 7970 | #ifdef CONFIG_PM |
5fd3ac3c JD |
7971 | .suspend = ath10k_wow_op_suspend, |
7972 | .resume = ath10k_wow_op_resume, | |
393b706c | 7973 | .set_wakeup = ath10k_wow_op_set_wakeup, |
8cd13cad | 7974 | #endif |
f5045988 RM |
7975 | #ifdef CONFIG_MAC80211_DEBUGFS |
7976 | .sta_add_debugfs = ath10k_sta_add_debugfs, | |
7977 | #endif | |
5e3dd157 KV |
7978 | }; |
7979 | ||
5e3dd157 | 7980 | #define CHAN2G(_channel, _freq, _flags) { \ |
57fbcce3 | 7981 | .band = NL80211_BAND_2GHZ, \ |
5e3dd157 KV |
7982 | .hw_value = (_channel), \ |
7983 | .center_freq = (_freq), \ | |
7984 | .flags = (_flags), \ | |
7985 | .max_antenna_gain = 0, \ | |
7986 | .max_power = 30, \ | |
7987 | } | |
7988 | ||
7989 | #define CHAN5G(_channel, _freq, _flags) { \ | |
57fbcce3 | 7990 | .band = NL80211_BAND_5GHZ, \ |
5e3dd157 KV |
7991 | .hw_value = (_channel), \ |
7992 | .center_freq = (_freq), \ | |
7993 | .flags = (_flags), \ | |
7994 | .max_antenna_gain = 0, \ | |
7995 | .max_power = 30, \ | |
7996 | } | |
7997 | ||
7998 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { | |
7999 | CHAN2G(1, 2412, 0), | |
8000 | CHAN2G(2, 2417, 0), | |
8001 | CHAN2G(3, 2422, 0), | |
8002 | CHAN2G(4, 2427, 0), | |
8003 | CHAN2G(5, 2432, 0), | |
8004 | CHAN2G(6, 2437, 0), | |
8005 | CHAN2G(7, 2442, 0), | |
8006 | CHAN2G(8, 2447, 0), | |
8007 | CHAN2G(9, 2452, 0), | |
8008 | CHAN2G(10, 2457, 0), | |
8009 | CHAN2G(11, 2462, 0), | |
8010 | CHAN2G(12, 2467, 0), | |
8011 | CHAN2G(13, 2472, 0), | |
8012 | CHAN2G(14, 2484, 0), | |
8013 | }; | |
8014 | ||
8015 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { | |
429ff56a MK |
8016 | CHAN5G(36, 5180, 0), |
8017 | CHAN5G(40, 5200, 0), | |
8018 | CHAN5G(44, 5220, 0), | |
8019 | CHAN5G(48, 5240, 0), | |
8020 | CHAN5G(52, 5260, 0), | |
8021 | CHAN5G(56, 5280, 0), | |
8022 | CHAN5G(60, 5300, 0), | |
8023 | CHAN5G(64, 5320, 0), | |
8024 | CHAN5G(100, 5500, 0), | |
8025 | CHAN5G(104, 5520, 0), | |
8026 | CHAN5G(108, 5540, 0), | |
8027 | CHAN5G(112, 5560, 0), | |
8028 | CHAN5G(116, 5580, 0), | |
8029 | CHAN5G(120, 5600, 0), | |
8030 | CHAN5G(124, 5620, 0), | |
8031 | CHAN5G(128, 5640, 0), | |
8032 | CHAN5G(132, 5660, 0), | |
8033 | CHAN5G(136, 5680, 0), | |
8034 | CHAN5G(140, 5700, 0), | |
4a7898fe | 8035 | CHAN5G(144, 5720, 0), |
429ff56a MK |
8036 | CHAN5G(149, 5745, 0), |
8037 | CHAN5G(153, 5765, 0), | |
8038 | CHAN5G(157, 5785, 0), | |
8039 | CHAN5G(161, 5805, 0), | |
8040 | CHAN5G(165, 5825, 0), | |
34c30b0a | 8041 | CHAN5G(169, 5845, 0), |
38441fb6 BG |
8042 | CHAN5G(173, 5865, 0), |
8043 | /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */ | |
8044 | /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */ | |
5e3dd157 KV |
8045 | }; |
8046 | ||
e7b54194 | 8047 | struct ath10k *ath10k_mac_create(size_t priv_size) |
5e3dd157 KV |
8048 | { |
8049 | struct ieee80211_hw *hw; | |
4ca18078 | 8050 | struct ieee80211_ops *ops; |
5e3dd157 KV |
8051 | struct ath10k *ar; |
8052 | ||
4ca18078 MK |
8053 | ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL); |
8054 | if (!ops) | |
5e3dd157 KV |
8055 | return NULL; |
8056 | ||
4ca18078 MK |
8057 | hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops); |
8058 | if (!hw) { | |
8059 | kfree(ops); | |
8060 | return NULL; | |
8061 | } | |
8062 | ||
5e3dd157 KV |
8063 | ar = hw->priv; |
8064 | ar->hw = hw; | |
4ca18078 | 8065 | ar->ops = ops; |
5e3dd157 KV |
8066 | |
8067 | return ar; | |
8068 | } | |
8069 | ||
8070 | void ath10k_mac_destroy(struct ath10k *ar) | |
8071 | { | |
4ca18078 MK |
8072 | struct ieee80211_ops *ops = ar->ops; |
8073 | ||
5e3dd157 | 8074 | ieee80211_free_hw(ar->hw); |
4ca18078 | 8075 | kfree(ops); |
5e3dd157 KV |
8076 | } |
8077 | ||
8078 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { | |
8079 | { | |
78f7aeb0 MSS |
8080 | .max = 8, |
8081 | .types = BIT(NL80211_IFTYPE_STATION) | |
8082 | | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
d531cb85 MK |
8083 | }, |
8084 | { | |
78f7aeb0 MSS |
8085 | .max = 3, |
8086 | .types = BIT(NL80211_IFTYPE_P2P_GO) | |
d531cb85 MK |
8087 | }, |
8088 | { | |
78f7aeb0 MSS |
8089 | .max = 1, |
8090 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) | |
75d2bd48 MK |
8091 | }, |
8092 | { | |
78f7aeb0 MSS |
8093 | .max = 7, |
8094 | .types = BIT(NL80211_IFTYPE_AP) | |
b6c7bafa | 8095 | #ifdef CONFIG_MAC80211_MESH |
78f7aeb0 | 8096 | | BIT(NL80211_IFTYPE_MESH_POINT) |
b6c7bafa | 8097 | #endif |
d531cb85 | 8098 | }, |
5e3dd157 KV |
8099 | }; |
8100 | ||
f259509b | 8101 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
e8a50f8b | 8102 | { |
78f7aeb0 MSS |
8103 | .max = 8, |
8104 | .types = BIT(NL80211_IFTYPE_AP) | |
b6c7bafa | 8105 | #ifdef CONFIG_MAC80211_MESH |
78f7aeb0 | 8106 | | BIT(NL80211_IFTYPE_MESH_POINT) |
b6c7bafa | 8107 | #endif |
e8a50f8b | 8108 | }, |
78f7aeb0 MSS |
8109 | { |
8110 | .max = 1, | |
8111 | .types = BIT(NL80211_IFTYPE_STATION) | |
8112 | }, | |
e8a50f8b | 8113 | }; |
e8a50f8b MP |
8114 | |
8115 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { | |
8116 | { | |
8117 | .limits = ath10k_if_limits, | |
8118 | .n_limits = ARRAY_SIZE(ath10k_if_limits), | |
8119 | .max_interfaces = 8, | |
8120 | .num_different_channels = 1, | |
8121 | .beacon_int_infra_match = true, | |
8122 | }, | |
f259509b BM |
8123 | }; |
8124 | ||
8125 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { | |
e8a50f8b | 8126 | { |
f259509b BM |
8127 | .limits = ath10k_10x_if_limits, |
8128 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), | |
e8a50f8b MP |
8129 | .max_interfaces = 8, |
8130 | .num_different_channels = 1, | |
8131 | .beacon_int_infra_match = true, | |
8ebee73b | 8132 | .beacon_int_min_gcd = 1, |
f259509b | 8133 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
e8a50f8b MP |
8134 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
8135 | BIT(NL80211_CHAN_WIDTH_20) | | |
8136 | BIT(NL80211_CHAN_WIDTH_40) | | |
8137 | BIT(NL80211_CHAN_WIDTH_80), | |
e8a50f8b | 8138 | #endif |
f259509b | 8139 | }, |
5e3dd157 KV |
8140 | }; |
8141 | ||
cf32784c MK |
8142 | static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = { |
8143 | { | |
8144 | .max = 2, | |
ed25b113 MK |
8145 | .types = BIT(NL80211_IFTYPE_STATION), |
8146 | }, | |
8147 | { | |
8148 | .max = 2, | |
8149 | .types = BIT(NL80211_IFTYPE_AP) | | |
b6c7bafa BC |
8150 | #ifdef CONFIG_MAC80211_MESH |
8151 | BIT(NL80211_IFTYPE_MESH_POINT) | | |
8152 | #endif | |
cf32784c MK |
8153 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
8154 | BIT(NL80211_IFTYPE_P2P_GO), | |
8155 | }, | |
8156 | { | |
8157 | .max = 1, | |
8158 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), | |
8159 | }, | |
8160 | }; | |
8161 | ||
ed25b113 MK |
8162 | static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = { |
8163 | { | |
8164 | .max = 2, | |
8165 | .types = BIT(NL80211_IFTYPE_STATION), | |
8166 | }, | |
8167 | { | |
8168 | .max = 2, | |
8169 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT), | |
8170 | }, | |
8171 | { | |
8172 | .max = 1, | |
8173 | .types = BIT(NL80211_IFTYPE_AP) | | |
b6c7bafa BC |
8174 | #ifdef CONFIG_MAC80211_MESH |
8175 | BIT(NL80211_IFTYPE_MESH_POINT) | | |
8176 | #endif | |
ed25b113 MK |
8177 | BIT(NL80211_IFTYPE_P2P_GO), |
8178 | }, | |
8179 | { | |
8180 | .max = 1, | |
8181 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), | |
8182 | }, | |
8183 | }; | |
8184 | ||
cf32784c MK |
8185 | static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = { |
8186 | { | |
8187 | .max = 1, | |
8188 | .types = BIT(NL80211_IFTYPE_STATION), | |
8189 | }, | |
8190 | { | |
8191 | .max = 1, | |
8192 | .types = BIT(NL80211_IFTYPE_ADHOC), | |
8193 | }, | |
8194 | }; | |
8195 | ||
8196 | /* FIXME: This is not thouroughly tested. These combinations may over- or | |
8197 | * underestimate hw/fw capabilities. | |
8198 | */ | |
8199 | static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = { | |
8200 | { | |
8201 | .limits = ath10k_tlv_if_limit, | |
8202 | .num_different_channels = 1, | |
ed25b113 | 8203 | .max_interfaces = 4, |
cf32784c MK |
8204 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit), |
8205 | }, | |
8206 | { | |
8207 | .limits = ath10k_tlv_if_limit_ibss, | |
8208 | .num_different_channels = 1, | |
8209 | .max_interfaces = 2, | |
8210 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss), | |
8211 | }, | |
8212 | }; | |
8213 | ||
8214 | static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = { | |
8215 | { | |
8216 | .limits = ath10k_tlv_if_limit, | |
ed25b113 MK |
8217 | .num_different_channels = 1, |
8218 | .max_interfaces = 4, | |
cf32784c MK |
8219 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit), |
8220 | }, | |
ed25b113 MK |
8221 | { |
8222 | .limits = ath10k_tlv_qcs_if_limit, | |
8223 | .num_different_channels = 2, | |
8224 | .max_interfaces = 4, | |
8225 | .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit), | |
8226 | }, | |
cf32784c MK |
8227 | { |
8228 | .limits = ath10k_tlv_if_limit_ibss, | |
8229 | .num_different_channels = 1, | |
8230 | .max_interfaces = 2, | |
8231 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss), | |
8232 | }, | |
8233 | }; | |
8234 | ||
cf36fef0 RM |
8235 | static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = { |
8236 | { | |
8237 | .max = 1, | |
8238 | .types = BIT(NL80211_IFTYPE_STATION), | |
8239 | }, | |
8240 | { | |
8241 | .max = 16, | |
8242 | .types = BIT(NL80211_IFTYPE_AP) | |
b6c7bafa BC |
8243 | #ifdef CONFIG_MAC80211_MESH |
8244 | | BIT(NL80211_IFTYPE_MESH_POINT) | |
8245 | #endif | |
cf36fef0 RM |
8246 | }, |
8247 | }; | |
8248 | ||
8249 | static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = { | |
8250 | { | |
8251 | .limits = ath10k_10_4_if_limits, | |
8252 | .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits), | |
8253 | .max_interfaces = 16, | |
8254 | .num_different_channels = 1, | |
8255 | .beacon_int_infra_match = true, | |
8ebee73b | 8256 | .beacon_int_min_gcd = 1, |
cf36fef0 RM |
8257 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
8258 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
8259 | BIT(NL80211_CHAN_WIDTH_20) | | |
8260 | BIT(NL80211_CHAN_WIDTH_40) | | |
8261 | BIT(NL80211_CHAN_WIDTH_80), | |
8262 | #endif | |
8263 | }, | |
8264 | }; | |
8265 | ||
4600563f MK |
8266 | static const struct |
8267 | ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = { | |
8268 | { | |
8269 | .limits = ath10k_10_4_if_limits, | |
8270 | .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits), | |
8271 | .max_interfaces = 16, | |
8272 | .num_different_channels = 1, | |
8273 | .beacon_int_infra_match = true, | |
8274 | .beacon_int_min_gcd = 100, | |
8275 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED | |
8276 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
8277 | BIT(NL80211_CHAN_WIDTH_20) | | |
8278 | BIT(NL80211_CHAN_WIDTH_40) | | |
8279 | BIT(NL80211_CHAN_WIDTH_80), | |
8280 | #endif | |
8281 | }, | |
8282 | }; | |
8283 | ||
5e3dd157 KV |
8284 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
8285 | struct ieee80211_vif *vif) | |
8286 | { | |
8287 | struct ath10k_vif_iter *arvif_iter = data; | |
56ac13bf | 8288 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
5e3dd157 KV |
8289 | |
8290 | if (arvif->vdev_id == arvif_iter->vdev_id) | |
8291 | arvif_iter->arvif = arvif; | |
8292 | } | |
8293 | ||
8294 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) | |
8295 | { | |
8296 | struct ath10k_vif_iter arvif_iter; | |
8297 | u32 flags; | |
8298 | ||
8299 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); | |
8300 | arvif_iter.vdev_id = vdev_id; | |
8301 | ||
8302 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; | |
8303 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
8304 | flags, | |
8305 | ath10k_get_arvif_iter, | |
8306 | &arvif_iter); | |
8307 | if (!arvif_iter.arvif) { | |
7aa7a72a | 8308 | ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id); |
5e3dd157 KV |
8309 | return NULL; |
8310 | } | |
8311 | ||
8312 | return arvif_iter.arvif; | |
8313 | } | |
8314 | ||
209b2a68 BM |
8315 | #define WRD_METHOD "WRDD" |
8316 | #define WRDD_WIFI (0x07) | |
8317 | ||
8318 | static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd) | |
8319 | { | |
8320 | union acpi_object *mcc_pkg; | |
8321 | union acpi_object *domain_type; | |
8322 | union acpi_object *mcc_value; | |
8323 | u32 i; | |
8324 | ||
8325 | if (wrdd->type != ACPI_TYPE_PACKAGE || | |
8326 | wrdd->package.count < 2 || | |
8327 | wrdd->package.elements[0].type != ACPI_TYPE_INTEGER || | |
8328 | wrdd->package.elements[0].integer.value != 0) { | |
8329 | ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n"); | |
8330 | return 0; | |
8331 | } | |
8332 | ||
8333 | for (i = 1; i < wrdd->package.count; ++i) { | |
8334 | mcc_pkg = &wrdd->package.elements[i]; | |
8335 | ||
8336 | if (mcc_pkg->type != ACPI_TYPE_PACKAGE) | |
8337 | continue; | |
8338 | if (mcc_pkg->package.count < 2) | |
8339 | continue; | |
8340 | if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER || | |
8341 | mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) | |
8342 | continue; | |
8343 | ||
8344 | domain_type = &mcc_pkg->package.elements[0]; | |
8345 | if (domain_type->integer.value != WRDD_WIFI) | |
8346 | continue; | |
8347 | ||
8348 | mcc_value = &mcc_pkg->package.elements[1]; | |
8349 | return mcc_value->integer.value; | |
8350 | } | |
8351 | return 0; | |
8352 | } | |
8353 | ||
8354 | static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd) | |
8355 | { | |
209b2a68 BM |
8356 | acpi_handle root_handle; |
8357 | acpi_handle handle; | |
8358 | struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL}; | |
8359 | acpi_status status; | |
8360 | u32 alpha2_code; | |
8361 | char alpha2[3]; | |
8362 | ||
79169f14 | 8363 | root_handle = ACPI_HANDLE(ar->dev); |
209b2a68 BM |
8364 | if (!root_handle) |
8365 | return -EOPNOTSUPP; | |
8366 | ||
8367 | status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle); | |
8368 | if (ACPI_FAILURE(status)) { | |
8369 | ath10k_dbg(ar, ATH10K_DBG_BOOT, | |
8370 | "failed to get wrd method %d\n", status); | |
8371 | return -EIO; | |
8372 | } | |
8373 | ||
8374 | status = acpi_evaluate_object(handle, NULL, NULL, &wrdd); | |
8375 | if (ACPI_FAILURE(status)) { | |
8376 | ath10k_dbg(ar, ATH10K_DBG_BOOT, | |
8377 | "failed to call wrdc %d\n", status); | |
8378 | return -EIO; | |
8379 | } | |
8380 | ||
8381 | alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer); | |
8382 | kfree(wrdd.pointer); | |
8383 | if (!alpha2_code) | |
8384 | return -EIO; | |
8385 | ||
8386 | alpha2[0] = (alpha2_code >> 8) & 0xff; | |
8387 | alpha2[1] = (alpha2_code >> 0) & 0xff; | |
8388 | alpha2[2] = '\0'; | |
8389 | ||
8390 | ath10k_dbg(ar, ATH10K_DBG_BOOT, | |
8391 | "regulatory hint from WRDD (alpha2-code): %s\n", alpha2); | |
8392 | ||
8393 | *rd = ath_regd_find_country_by_name(alpha2); | |
8394 | if (*rd == 0xffff) | |
8395 | return -EIO; | |
8396 | ||
8397 | *rd |= COUNTRY_ERD_FLAG; | |
8398 | return 0; | |
8399 | } | |
8400 | ||
8401 | static int ath10k_mac_init_rd(struct ath10k *ar) | |
8402 | { | |
8403 | int ret; | |
8404 | u16 rd; | |
8405 | ||
8406 | ret = ath10k_mac_get_wrdd_regulatory(ar, &rd); | |
8407 | if (ret) { | |
8408 | ath10k_dbg(ar, ATH10K_DBG_BOOT, | |
8409 | "fallback to eeprom programmed regulatory settings\n"); | |
8410 | rd = ar->hw_eeprom_rd; | |
8411 | } | |
8412 | ||
8413 | ar->ath_common.regulatory.current_rd = rd; | |
8414 | return 0; | |
8415 | } | |
8416 | ||
5e3dd157 KV |
8417 | int ath10k_mac_register(struct ath10k *ar) |
8418 | { | |
3cb10943 JB |
8419 | static const u32 cipher_suites[] = { |
8420 | WLAN_CIPHER_SUITE_WEP40, | |
8421 | WLAN_CIPHER_SUITE_WEP104, | |
8422 | WLAN_CIPHER_SUITE_TKIP, | |
8423 | WLAN_CIPHER_SUITE_CCMP, | |
2ea9f12c RM |
8424 | |
8425 | /* Do not add hardware supported ciphers before this line. | |
8426 | * Allow software encryption for all chips. Don't forget to | |
8427 | * update n_cipher_suites below. | |
8428 | */ | |
3cb10943 | 8429 | WLAN_CIPHER_SUITE_AES_CMAC, |
2ea9f12c RM |
8430 | WLAN_CIPHER_SUITE_BIP_CMAC_256, |
8431 | WLAN_CIPHER_SUITE_BIP_GMAC_128, | |
8432 | WLAN_CIPHER_SUITE_BIP_GMAC_256, | |
8433 | ||
8434 | /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256 | |
8435 | * and CCMP-256 in hardware. | |
8436 | */ | |
8437 | WLAN_CIPHER_SUITE_GCMP, | |
8438 | WLAN_CIPHER_SUITE_GCMP_256, | |
8439 | WLAN_CIPHER_SUITE_CCMP_256, | |
3cb10943 | 8440 | }; |
5e3dd157 | 8441 | struct ieee80211_supported_band *band; |
5e3dd157 KV |
8442 | void *channels; |
8443 | int ret; | |
8444 | ||
234e4307 BN |
8445 | if (!is_valid_ether_addr(ar->mac_addr)) { |
8446 | ath10k_warn(ar, "invalid MAC address; choosing random\n"); | |
8447 | eth_random_addr(ar->mac_addr); | |
8448 | } | |
5e3dd157 KV |
8449 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); |
8450 | ||
8451 | SET_IEEE80211_DEV(ar->hw, ar->dev); | |
8452 | ||
c94aa7ef MK |
8453 | BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) + |
8454 | ARRAY_SIZE(ath10k_5ghz_channels)) != | |
8455 | ATH10K_NUM_CHANS); | |
8456 | ||
5e3dd157 KV |
8457 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
8458 | channels = kmemdup(ath10k_2ghz_channels, | |
8459 | sizeof(ath10k_2ghz_channels), | |
8460 | GFP_KERNEL); | |
d6015b27 MK |
8461 | if (!channels) { |
8462 | ret = -ENOMEM; | |
8463 | goto err_free; | |
8464 | } | |
5e3dd157 | 8465 | |
57fbcce3 | 8466 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
5e3dd157 KV |
8467 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); |
8468 | band->channels = channels; | |
5269c659 MSS |
8469 | |
8470 | if (ar->hw_params.cck_rate_map_rev2) { | |
8471 | band->n_bitrates = ath10k_g_rates_rev2_size; | |
8472 | band->bitrates = ath10k_g_rates_rev2; | |
8473 | } else { | |
8474 | band->n_bitrates = ath10k_g_rates_size; | |
8475 | band->bitrates = ath10k_g_rates; | |
8476 | } | |
5e3dd157 | 8477 | |
57fbcce3 | 8478 | ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band; |
5e3dd157 KV |
8479 | } |
8480 | ||
8481 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { | |
8482 | channels = kmemdup(ath10k_5ghz_channels, | |
8483 | sizeof(ath10k_5ghz_channels), | |
8484 | GFP_KERNEL); | |
8485 | if (!channels) { | |
d6015b27 MK |
8486 | ret = -ENOMEM; |
8487 | goto err_free; | |
5e3dd157 KV |
8488 | } |
8489 | ||
57fbcce3 | 8490 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; |
5e3dd157 KV |
8491 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); |
8492 | band->channels = channels; | |
8493 | band->n_bitrates = ath10k_a_rates_size; | |
8494 | band->bitrates = ath10k_a_rates; | |
57fbcce3 | 8495 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band; |
5e3dd157 KV |
8496 | } |
8497 | ||
34d5629d | 8498 | wiphy_read_of_freq_limits(ar->hw->wiphy); |
5036fe0f RM |
8499 | ath10k_mac_setup_ht_vht_cap(ar); |
8500 | ||
5e3dd157 KV |
8501 | ar->hw->wiphy->interface_modes = |
8502 | BIT(NL80211_IFTYPE_STATION) | | |
b6c7bafa BC |
8503 | BIT(NL80211_IFTYPE_AP) | |
8504 | BIT(NL80211_IFTYPE_MESH_POINT); | |
d354181f | 8505 | |
166de3f1 RM |
8506 | ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask; |
8507 | ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask; | |
46acf7bb | 8508 | |
c4cdf753 | 8509 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features)) |
d354181f | 8510 | ar->hw->wiphy->interface_modes |= |
75d2bd48 | 8511 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
d354181f BM |
8512 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
8513 | BIT(NL80211_IFTYPE_P2P_GO); | |
5e3dd157 | 8514 | |
30686bf7 | 8515 | ieee80211_hw_set(ar->hw, SIGNAL_DBM); |
36d9cdb6 VN |
8516 | |
8517 | if (!test_bit(ATH10K_FW_FEATURE_NO_PS, | |
8518 | ar->running_fw->fw_file.fw_features)) { | |
8519 | ieee80211_hw_set(ar->hw, SUPPORTS_PS); | |
8520 | ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS); | |
8521 | } | |
8522 | ||
30686bf7 JB |
8523 | ieee80211_hw_set(ar->hw, MFP_CAPABLE); |
8524 | ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS); | |
8525 | ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL); | |
8526 | ieee80211_hw_set(ar->hw, AP_LINK_PS); | |
8527 | ieee80211_hw_set(ar->hw, SPECTRUM_MGMT); | |
30686bf7 JB |
8528 | ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT); |
8529 | ieee80211_hw_set(ar->hw, CONNECTION_MONITOR); | |
8530 | ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK); | |
8531 | ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF); | |
8532 | ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA); | |
8533 | ieee80211_hw_set(ar->hw, QUEUE_CONTROL); | |
f3fe4e93 | 8534 | ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG); |
ff32eeb8 | 8535 | ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK); |
5e3dd157 | 8536 | |
ccec9038 DL |
8537 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
8538 | ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL); | |
8539 | ||
0d8614b4 | 8540 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
0cd9bc14 | 8541 | ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
0d8614b4 | 8542 | |
5e3dd157 | 8543 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
0d8614b4 | 8544 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
5e3dd157 KV |
8545 | |
8546 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { | |
30686bf7 JB |
8547 | ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION); |
8548 | ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW); | |
5e3dd157 KV |
8549 | } |
8550 | ||
8551 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; | |
8552 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; | |
8553 | ||
ce834e28 WG |
8554 | if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) { |
8555 | ar->hw->wiphy->max_sched_scan_reqs = 1; | |
8556 | ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS; | |
8557 | ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS; | |
8558 | ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH; | |
8559 | ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS; | |
8560 | ar->hw->wiphy->max_sched_scan_plan_interval = | |
8561 | WMI_PNO_MAX_SCHED_SCAN_PLAN_INT; | |
8562 | ar->hw->wiphy->max_sched_scan_plan_iterations = | |
8563 | WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS; | |
8564 | } | |
8565 | ||
5e3dd157 | 8566 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); |
9797febc | 8567 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
29946878 | 8568 | ar->hw->txq_data_size = sizeof(struct ath10k_txq); |
5e3dd157 | 8569 | |
5e3dd157 KV |
8570 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
8571 | ||
fbb8f1b7 MK |
8572 | if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) { |
8573 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; | |
8574 | ||
8575 | /* Firmware delivers WPS/P2P Probe Requests frames to driver so | |
8576 | * that userspace (e.g. wpa_supplicant/hostapd) can generate | |
8577 | * correct Probe Responses. This is more of a hack advert.. | |
8578 | */ | |
8579 | ar->hw->wiphy->probe_resp_offload |= | |
8580 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | | |
8581 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | | |
8582 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; | |
8583 | } | |
8584 | ||
add6cd8d MP |
8585 | if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) || |
8586 | test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) { | |
75d85fd9 | 8587 | ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
14d65775 BP |
8588 | if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map)) |
8589 | ieee80211_hw_set(ar->hw, TDLS_WIDER_BW); | |
add6cd8d | 8590 | } |
75d85fd9 | 8591 | |
802ca335 YT |
8592 | if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map)) |
8593 | ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA); | |
8594 | ||
5e3dd157 | 8595 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
c2df44b3 | 8596 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
5e3dd157 KV |
8597 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
8598 | ||
8599 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
bf031bc4 VT |
8600 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
8601 | NL80211_FEATURE_AP_SCAN; | |
78157a1c | 8602 | |
37a0b394 JD |
8603 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; |
8604 | ||
5fd3ac3c JD |
8605 | ret = ath10k_wow_init(ar); |
8606 | if (ret) { | |
8607 | ath10k_warn(ar, "failed to init wow: %d\n", ret); | |
8608 | goto err_free; | |
8609 | } | |
8610 | ||
c702534a | 8611 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
be8cce96 PKC |
8612 | wiphy_ext_feature_set(ar->hw->wiphy, |
8613 | NL80211_EXT_FEATURE_SET_SCAN_DWELL); | |
c702534a | 8614 | |
6bc17950 BP |
8615 | if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) || |
8616 | test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map)) | |
c7fd8d23 | 8617 | wiphy_ext_feature_set(ar->hw->wiphy, |
6bc17950 | 8618 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); |
c7fd8d23 | 8619 | |
5e3dd157 KV |
8620 | /* |
8621 | * on LL hardware queues are managed entirely by the FW | |
8622 | * so we only advertise to mac we can do the queues thing | |
8623 | */ | |
96d828d4 MK |
8624 | ar->hw->queues = IEEE80211_MAX_QUEUES; |
8625 | ||
8626 | /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is | |
8627 | * something that vdev_ids can't reach so that we don't stop the queue | |
8628 | * accidentally. | |
8629 | */ | |
8630 | ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1; | |
5e3dd157 | 8631 | |
bf3c13ab | 8632 | switch (ar->running_fw->fw_file.wmi_op_version) { |
5cc7caf4 | 8633 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
f259509b BM |
8634 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
8635 | ar->hw->wiphy->n_iface_combinations = | |
8636 | ARRAY_SIZE(ath10k_if_comb); | |
cf850d1d | 8637 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
5cc7caf4 | 8638 | break; |
cf32784c MK |
8639 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
8640 | if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) { | |
8641 | ar->hw->wiphy->iface_combinations = | |
8642 | ath10k_tlv_qcs_if_comb; | |
8643 | ar->hw->wiphy->n_iface_combinations = | |
8644 | ARRAY_SIZE(ath10k_tlv_qcs_if_comb); | |
8645 | } else { | |
8646 | ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb; | |
8647 | ar->hw->wiphy->n_iface_combinations = | |
8648 | ARRAY_SIZE(ath10k_tlv_if_comb); | |
8649 | } | |
8650 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); | |
8651 | break; | |
5cc7caf4 KV |
8652 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
8653 | case ATH10K_FW_WMI_OP_VERSION_10_2: | |
4a16fbec | 8654 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
5cc7caf4 KV |
8655 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
8656 | ar->hw->wiphy->n_iface_combinations = | |
8657 | ARRAY_SIZE(ath10k_10x_if_comb); | |
8658 | break; | |
9bd21322 | 8659 | case ATH10K_FW_WMI_OP_VERSION_10_4: |
cf36fef0 RM |
8660 | ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb; |
8661 | ar->hw->wiphy->n_iface_combinations = | |
8662 | ARRAY_SIZE(ath10k_10_4_if_comb); | |
4600563f MK |
8663 | if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT, |
8664 | ar->wmi.svc_map)) { | |
8665 | ar->hw->wiphy->iface_combinations = | |
8666 | ath10k_10_4_bcn_int_if_comb; | |
8667 | ar->hw->wiphy->n_iface_combinations = | |
8668 | ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb); | |
8669 | } | |
9bd21322 | 8670 | break; |
5cc7caf4 KV |
8671 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
8672 | case ATH10K_FW_WMI_OP_VERSION_MAX: | |
8673 | WARN_ON(1); | |
8674 | ret = -EINVAL; | |
8675 | goto err_free; | |
f259509b | 8676 | } |
5e3dd157 | 8677 | |
ccec9038 DL |
8678 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
8679 | ar->hw->netdev_features = NETIF_F_HW_CSUM; | |
7c199997 | 8680 | |
97f2645f | 8681 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) { |
9702c686 JD |
8682 | /* Init ath dfs pattern detector */ |
8683 | ar->ath_common.debug_mask = ATH_DBG_DFS; | |
8684 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, | |
8685 | NL80211_DFS_UNSET); | |
8686 | ||
8687 | if (!ar->dfs_detector) | |
7aa7a72a | 8688 | ath10k_warn(ar, "failed to initialise DFS pattern detector\n"); |
9702c686 JD |
8689 | } |
8690 | ||
209b2a68 BM |
8691 | ret = ath10k_mac_init_rd(ar); |
8692 | if (ret) { | |
8693 | ath10k_err(ar, "failed to derive regdom: %d\n", ret); | |
8694 | goto err_dfs_detector_exit; | |
8695 | } | |
8696 | ||
ebee76f7 BB |
8697 | /* Disable set_coverage_class for chipsets that do not support it. */ |
8698 | if (!ar->hw_params.hw_ops->set_coverage_class) | |
8699 | ar->ops->set_coverage_class = NULL; | |
8700 | ||
5e3dd157 KV |
8701 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
8702 | ath10k_reg_notifier); | |
8703 | if (ret) { | |
7aa7a72a | 8704 | ath10k_err(ar, "failed to initialise regulatory: %i\n", ret); |
0e339447 | 8705 | goto err_dfs_detector_exit; |
5e3dd157 KV |
8706 | } |
8707 | ||
60e1d0fb | 8708 | if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) { |
60e1d0fb CH |
8709 | ar->hw->wiphy->features |= |
8710 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; | |
8711 | } | |
8712 | ||
3cb10943 | 8713 | ar->hw->wiphy->cipher_suites = cipher_suites; |
2ea9f12c RM |
8714 | |
8715 | /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128 | |
8716 | * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported | |
8717 | * from chip specific hw_param table. | |
8718 | */ | |
8719 | if (!ar->hw_params.n_cipher_suites || | |
8720 | ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) { | |
8721 | ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n", | |
8722 | ar->hw_params.n_cipher_suites); | |
8723 | ar->hw_params.n_cipher_suites = 8; | |
8724 | } | |
8725 | ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites; | |
ae44b502 AZ |
8726 | |
8727 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); | |
3cb10943 | 8728 | |
5e3dd157 KV |
8729 | ret = ieee80211_register_hw(ar->hw); |
8730 | if (ret) { | |
7aa7a72a | 8731 | ath10k_err(ar, "failed to register ieee80211: %d\n", ret); |
0e339447 | 8732 | goto err_dfs_detector_exit; |
5e3dd157 KV |
8733 | } |
8734 | ||
8735 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { | |
8736 | ret = regulatory_hint(ar->hw->wiphy, | |
8737 | ar->ath_common.regulatory.alpha2); | |
8738 | if (ret) | |
d6015b27 | 8739 | goto err_unregister; |
5e3dd157 KV |
8740 | } |
8741 | ||
8742 | return 0; | |
d6015b27 MK |
8743 | |
8744 | err_unregister: | |
5e3dd157 | 8745 | ieee80211_unregister_hw(ar->hw); |
0e339447 JJ |
8746 | |
8747 | err_dfs_detector_exit: | |
97f2645f | 8748 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
0e339447 JJ |
8749 | ar->dfs_detector->exit(ar->dfs_detector); |
8750 | ||
d6015b27 | 8751 | err_free: |
57fbcce3 JB |
8752 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
8753 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
d6015b27 | 8754 | |
0e339447 | 8755 | SET_IEEE80211_DEV(ar->hw, NULL); |
5e3dd157 KV |
8756 | return ret; |
8757 | } | |
8758 | ||
8759 | void ath10k_mac_unregister(struct ath10k *ar) | |
8760 | { | |
8761 | ieee80211_unregister_hw(ar->hw); | |
8762 | ||
97f2645f | 8763 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
9702c686 JD |
8764 | ar->dfs_detector->exit(ar->dfs_detector); |
8765 | ||
57fbcce3 JB |
8766 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
8767 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
5e3dd157 KV |
8768 | |
8769 | SET_IEEE80211_DEV(ar->hw, NULL); | |
8770 | } |