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