Commit | Line | Data |
---|---|---|
d8899132 KV |
1 | // SPDX-License-Identifier: BSD-3-Clause-Clear |
2 | /* | |
3 | * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. | |
54fcdcf0 | 4 | * Copyright (c) 2021-2025 Qualcomm Innovation Center, Inc. All rights reserved. |
d8899132 KV |
5 | */ |
6 | ||
7 | #include <net/mac80211.h> | |
11b86e2c | 8 | #include <net/cfg80211.h> |
d8899132 | 9 | #include <linux/etherdevice.h> |
1666108c | 10 | |
d8899132 KV |
11 | #include "mac.h" |
12 | #include "core.h" | |
13 | #include "debug.h" | |
14 | #include "wmi.h" | |
15 | #include "hw.h" | |
16 | #include "dp_tx.h" | |
17 | #include "dp_rx.h" | |
3bc374cb | 18 | #include "testmode.h" |
d8899132 | 19 | #include "peer.h" |
f8bde02a | 20 | #include "debugfs.h" |
4a3c212e BQ |
21 | #include "hif.h" |
22 | #include "wow.h" | |
a412547f | 23 | #include "debugfs_sta.h" |
d8899132 KV |
24 | |
25 | #define CHAN2G(_channel, _freq, _flags) { \ | |
26 | .band = NL80211_BAND_2GHZ, \ | |
27 | .hw_value = (_channel), \ | |
28 | .center_freq = (_freq), \ | |
29 | .flags = (_flags), \ | |
30 | .max_antenna_gain = 0, \ | |
31 | .max_power = 30, \ | |
32 | } | |
33 | ||
34 | #define CHAN5G(_channel, _freq, _flags) { \ | |
35 | .band = NL80211_BAND_5GHZ, \ | |
36 | .hw_value = (_channel), \ | |
37 | .center_freq = (_freq), \ | |
38 | .flags = (_flags), \ | |
39 | .max_antenna_gain = 0, \ | |
40 | .max_power = 30, \ | |
41 | } | |
42 | ||
43 | #define CHAN6G(_channel, _freq, _flags) { \ | |
44 | .band = NL80211_BAND_6GHZ, \ | |
45 | .hw_value = (_channel), \ | |
46 | .center_freq = (_freq), \ | |
47 | .flags = (_flags), \ | |
48 | .max_antenna_gain = 0, \ | |
49 | .max_power = 30, \ | |
50 | } | |
51 | ||
52 | static const struct ieee80211_channel ath12k_2ghz_channels[] = { | |
53 | CHAN2G(1, 2412, 0), | |
54 | CHAN2G(2, 2417, 0), | |
55 | CHAN2G(3, 2422, 0), | |
56 | CHAN2G(4, 2427, 0), | |
57 | CHAN2G(5, 2432, 0), | |
58 | CHAN2G(6, 2437, 0), | |
59 | CHAN2G(7, 2442, 0), | |
60 | CHAN2G(8, 2447, 0), | |
61 | CHAN2G(9, 2452, 0), | |
62 | CHAN2G(10, 2457, 0), | |
63 | CHAN2G(11, 2462, 0), | |
64 | CHAN2G(12, 2467, 0), | |
65 | CHAN2G(13, 2472, 0), | |
66 | CHAN2G(14, 2484, 0), | |
67 | }; | |
68 | ||
69 | static const struct ieee80211_channel ath12k_5ghz_channels[] = { | |
70 | CHAN5G(36, 5180, 0), | |
71 | CHAN5G(40, 5200, 0), | |
72 | CHAN5G(44, 5220, 0), | |
73 | CHAN5G(48, 5240, 0), | |
74 | CHAN5G(52, 5260, 0), | |
75 | CHAN5G(56, 5280, 0), | |
76 | CHAN5G(60, 5300, 0), | |
77 | CHAN5G(64, 5320, 0), | |
78 | CHAN5G(100, 5500, 0), | |
79 | CHAN5G(104, 5520, 0), | |
80 | CHAN5G(108, 5540, 0), | |
81 | CHAN5G(112, 5560, 0), | |
82 | CHAN5G(116, 5580, 0), | |
83 | CHAN5G(120, 5600, 0), | |
84 | CHAN5G(124, 5620, 0), | |
85 | CHAN5G(128, 5640, 0), | |
86 | CHAN5G(132, 5660, 0), | |
87 | CHAN5G(136, 5680, 0), | |
88 | CHAN5G(140, 5700, 0), | |
89 | CHAN5G(144, 5720, 0), | |
90 | CHAN5G(149, 5745, 0), | |
91 | CHAN5G(153, 5765, 0), | |
92 | CHAN5G(157, 5785, 0), | |
93 | CHAN5G(161, 5805, 0), | |
94 | CHAN5G(165, 5825, 0), | |
95 | CHAN5G(169, 5845, 0), | |
96 | CHAN5G(173, 5865, 0), | |
97 | }; | |
98 | ||
99 | static const struct ieee80211_channel ath12k_6ghz_channels[] = { | |
3745d796 PKC |
100 | /* Operating Class 136 */ |
101 | CHAN6G(2, 5935, 0), | |
102 | ||
103 | /* Operating Classes 131-135 */ | |
d8899132 KV |
104 | CHAN6G(1, 5955, 0), |
105 | CHAN6G(5, 5975, 0), | |
106 | CHAN6G(9, 5995, 0), | |
107 | CHAN6G(13, 6015, 0), | |
108 | CHAN6G(17, 6035, 0), | |
109 | CHAN6G(21, 6055, 0), | |
110 | CHAN6G(25, 6075, 0), | |
111 | CHAN6G(29, 6095, 0), | |
112 | CHAN6G(33, 6115, 0), | |
113 | CHAN6G(37, 6135, 0), | |
114 | CHAN6G(41, 6155, 0), | |
115 | CHAN6G(45, 6175, 0), | |
116 | CHAN6G(49, 6195, 0), | |
117 | CHAN6G(53, 6215, 0), | |
118 | CHAN6G(57, 6235, 0), | |
119 | CHAN6G(61, 6255, 0), | |
120 | CHAN6G(65, 6275, 0), | |
121 | CHAN6G(69, 6295, 0), | |
122 | CHAN6G(73, 6315, 0), | |
123 | CHAN6G(77, 6335, 0), | |
124 | CHAN6G(81, 6355, 0), | |
125 | CHAN6G(85, 6375, 0), | |
126 | CHAN6G(89, 6395, 0), | |
127 | CHAN6G(93, 6415, 0), | |
128 | CHAN6G(97, 6435, 0), | |
129 | CHAN6G(101, 6455, 0), | |
130 | CHAN6G(105, 6475, 0), | |
131 | CHAN6G(109, 6495, 0), | |
132 | CHAN6G(113, 6515, 0), | |
133 | CHAN6G(117, 6535, 0), | |
134 | CHAN6G(121, 6555, 0), | |
135 | CHAN6G(125, 6575, 0), | |
136 | CHAN6G(129, 6595, 0), | |
137 | CHAN6G(133, 6615, 0), | |
138 | CHAN6G(137, 6635, 0), | |
139 | CHAN6G(141, 6655, 0), | |
140 | CHAN6G(145, 6675, 0), | |
141 | CHAN6G(149, 6695, 0), | |
142 | CHAN6G(153, 6715, 0), | |
143 | CHAN6G(157, 6735, 0), | |
144 | CHAN6G(161, 6755, 0), | |
145 | CHAN6G(165, 6775, 0), | |
146 | CHAN6G(169, 6795, 0), | |
147 | CHAN6G(173, 6815, 0), | |
148 | CHAN6G(177, 6835, 0), | |
149 | CHAN6G(181, 6855, 0), | |
150 | CHAN6G(185, 6875, 0), | |
151 | CHAN6G(189, 6895, 0), | |
152 | CHAN6G(193, 6915, 0), | |
153 | CHAN6G(197, 6935, 0), | |
154 | CHAN6G(201, 6955, 0), | |
155 | CHAN6G(205, 6975, 0), | |
156 | CHAN6G(209, 6995, 0), | |
157 | CHAN6G(213, 7015, 0), | |
158 | CHAN6G(217, 7035, 0), | |
159 | CHAN6G(221, 7055, 0), | |
160 | CHAN6G(225, 7075, 0), | |
161 | CHAN6G(229, 7095, 0), | |
162 | CHAN6G(233, 7115, 0), | |
163 | }; | |
164 | ||
165 | static struct ieee80211_rate ath12k_legacy_rates[] = { | |
166 | { .bitrate = 10, | |
167 | .hw_value = ATH12K_HW_RATE_CCK_LP_1M }, | |
168 | { .bitrate = 20, | |
169 | .hw_value = ATH12K_HW_RATE_CCK_LP_2M, | |
170 | .hw_value_short = ATH12K_HW_RATE_CCK_SP_2M, | |
171 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
172 | { .bitrate = 55, | |
173 | .hw_value = ATH12K_HW_RATE_CCK_LP_5_5M, | |
174 | .hw_value_short = ATH12K_HW_RATE_CCK_SP_5_5M, | |
175 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
176 | { .bitrate = 110, | |
177 | .hw_value = ATH12K_HW_RATE_CCK_LP_11M, | |
178 | .hw_value_short = ATH12K_HW_RATE_CCK_SP_11M, | |
179 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
180 | ||
181 | { .bitrate = 60, .hw_value = ATH12K_HW_RATE_OFDM_6M }, | |
182 | { .bitrate = 90, .hw_value = ATH12K_HW_RATE_OFDM_9M }, | |
183 | { .bitrate = 120, .hw_value = ATH12K_HW_RATE_OFDM_12M }, | |
184 | { .bitrate = 180, .hw_value = ATH12K_HW_RATE_OFDM_18M }, | |
185 | { .bitrate = 240, .hw_value = ATH12K_HW_RATE_OFDM_24M }, | |
186 | { .bitrate = 360, .hw_value = ATH12K_HW_RATE_OFDM_36M }, | |
187 | { .bitrate = 480, .hw_value = ATH12K_HW_RATE_OFDM_48M }, | |
188 | { .bitrate = 540, .hw_value = ATH12K_HW_RATE_OFDM_54M }, | |
189 | }; | |
190 | ||
191 | static const int | |
192 | ath12k_phymodes[NUM_NL80211_BANDS][ATH12K_CHAN_WIDTH_NUM] = { | |
193 | [NL80211_BAND_2GHZ] = { | |
194 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
195 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
38013653 MS |
196 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20_2G, |
197 | [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20_2G, | |
198 | [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40_2G, | |
199 | [NL80211_CHAN_WIDTH_80] = MODE_UNKNOWN, | |
d8899132 KV |
200 | [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, |
201 | [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN, | |
38013653 | 202 | [NL80211_CHAN_WIDTH_320] = MODE_UNKNOWN, |
d8899132 KV |
203 | }, |
204 | [NL80211_BAND_5GHZ] = { | |
205 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
206 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
38013653 MS |
207 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20, |
208 | [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20, | |
209 | [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40, | |
210 | [NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80, | |
211 | [NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160, | |
212 | [NL80211_CHAN_WIDTH_80P80] = MODE_11BE_EHT80_80, | |
213 | [NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320, | |
d8899132 KV |
214 | }, |
215 | [NL80211_BAND_6GHZ] = { | |
216 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
217 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
38013653 MS |
218 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11BE_EHT20, |
219 | [NL80211_CHAN_WIDTH_20] = MODE_11BE_EHT20, | |
220 | [NL80211_CHAN_WIDTH_40] = MODE_11BE_EHT40, | |
221 | [NL80211_CHAN_WIDTH_80] = MODE_11BE_EHT80, | |
222 | [NL80211_CHAN_WIDTH_160] = MODE_11BE_EHT160, | |
223 | [NL80211_CHAN_WIDTH_80P80] = MODE_11BE_EHT80_80, | |
224 | [NL80211_CHAN_WIDTH_320] = MODE_11BE_EHT320, | |
d8899132 KV |
225 | }, |
226 | ||
227 | }; | |
228 | ||
229 | const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default = { | |
230 | .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START | | |
231 | HTT_RX_FILTER_TLV_FLAGS_PPDU_END | | |
3126f1c5 P |
232 | HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE | |
233 | HTT_RX_FILTER_TLV_FLAGS_PPDU_START_USER_INFO, | |
d8899132 KV |
234 | .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0, |
235 | .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1, | |
236 | .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2, | |
237 | .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 | | |
238 | HTT_RX_FP_CTRL_FILTER_FLASG3 | |
239 | }; | |
240 | ||
241 | #define ATH12K_MAC_FIRST_OFDM_RATE_IDX 4 | |
242 | #define ath12k_g_rates ath12k_legacy_rates | |
243 | #define ath12k_g_rates_size (ARRAY_SIZE(ath12k_legacy_rates)) | |
244 | #define ath12k_a_rates (ath12k_legacy_rates + 4) | |
245 | #define ath12k_a_rates_size (ARRAY_SIZE(ath12k_legacy_rates) - 4) | |
246 | ||
247 | #define ATH12K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */ | |
248 | ||
249 | static const u32 ath12k_smps_map[] = { | |
250 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, | |
251 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, | |
252 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, | |
253 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, | |
254 | }; | |
255 | ||
5bdfb8c9 | 256 | static int ath12k_start_vdev_delay(struct ath12k *ar, |
3dd2c68f | 257 | struct ath12k_link_vif *arvif); |
b8ce837e | 258 | static void ath12k_mac_stop(struct ath12k *ar); |
005fe43b S |
259 | static int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif); |
260 | static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif); | |
d8899132 KV |
261 | |
262 | static const char *ath12k_mac_phymode_str(enum wmi_phy_mode mode) | |
263 | { | |
264 | switch (mode) { | |
265 | case MODE_11A: | |
266 | return "11a"; | |
267 | case MODE_11G: | |
268 | return "11g"; | |
269 | case MODE_11B: | |
270 | return "11b"; | |
271 | case MODE_11GONLY: | |
272 | return "11gonly"; | |
273 | case MODE_11NA_HT20: | |
274 | return "11na-ht20"; | |
275 | case MODE_11NG_HT20: | |
276 | return "11ng-ht20"; | |
277 | case MODE_11NA_HT40: | |
278 | return "11na-ht40"; | |
279 | case MODE_11NG_HT40: | |
280 | return "11ng-ht40"; | |
281 | case MODE_11AC_VHT20: | |
282 | return "11ac-vht20"; | |
283 | case MODE_11AC_VHT40: | |
284 | return "11ac-vht40"; | |
285 | case MODE_11AC_VHT80: | |
286 | return "11ac-vht80"; | |
287 | case MODE_11AC_VHT160: | |
288 | return "11ac-vht160"; | |
289 | case MODE_11AC_VHT80_80: | |
290 | return "11ac-vht80+80"; | |
291 | case MODE_11AC_VHT20_2G: | |
292 | return "11ac-vht20-2g"; | |
293 | case MODE_11AC_VHT40_2G: | |
294 | return "11ac-vht40-2g"; | |
295 | case MODE_11AC_VHT80_2G: | |
296 | return "11ac-vht80-2g"; | |
297 | case MODE_11AX_HE20: | |
298 | return "11ax-he20"; | |
299 | case MODE_11AX_HE40: | |
300 | return "11ax-he40"; | |
301 | case MODE_11AX_HE80: | |
302 | return "11ax-he80"; | |
303 | case MODE_11AX_HE80_80: | |
304 | return "11ax-he80+80"; | |
305 | case MODE_11AX_HE160: | |
306 | return "11ax-he160"; | |
307 | case MODE_11AX_HE20_2G: | |
308 | return "11ax-he20-2g"; | |
309 | case MODE_11AX_HE40_2G: | |
310 | return "11ax-he40-2g"; | |
311 | case MODE_11AX_HE80_2G: | |
312 | return "11ax-he80-2g"; | |
38013653 MS |
313 | case MODE_11BE_EHT20: |
314 | return "11be-eht20"; | |
315 | case MODE_11BE_EHT40: | |
316 | return "11be-eht40"; | |
317 | case MODE_11BE_EHT80: | |
318 | return "11be-eht80"; | |
319 | case MODE_11BE_EHT80_80: | |
320 | return "11be-eht80+80"; | |
321 | case MODE_11BE_EHT160: | |
322 | return "11be-eht160"; | |
323 | case MODE_11BE_EHT160_160: | |
324 | return "11be-eht160+160"; | |
325 | case MODE_11BE_EHT320: | |
326 | return "11be-eht320"; | |
327 | case MODE_11BE_EHT20_2G: | |
328 | return "11be-eht20-2g"; | |
329 | case MODE_11BE_EHT40_2G: | |
330 | return "11be-eht40-2g"; | |
d8899132 KV |
331 | case MODE_UNKNOWN: |
332 | /* skip */ | |
333 | break; | |
334 | ||
335 | /* no default handler to allow compiler to check that the | |
336 | * enum is fully handled | |
337 | */ | |
338 | } | |
339 | ||
340 | return "<unknown>"; | |
341 | } | |
342 | ||
8a9c06b4 LK |
343 | u16 ath12k_mac_he_convert_tones_to_ru_tones(u16 tones) |
344 | { | |
345 | switch (tones) { | |
346 | case 26: | |
347 | return RU_26; | |
348 | case 52: | |
349 | return RU_52; | |
350 | case 106: | |
351 | return RU_106; | |
352 | case 242: | |
353 | return RU_242; | |
354 | case 484: | |
355 | return RU_484; | |
356 | case 996: | |
357 | return RU_996; | |
358 | case (996 * 2): | |
359 | return RU_2X996; | |
360 | default: | |
361 | return RU_26; | |
362 | } | |
363 | } | |
364 | ||
365 | enum nl80211_eht_gi ath12k_mac_eht_gi_to_nl80211_eht_gi(u8 sgi) | |
366 | { | |
367 | switch (sgi) { | |
368 | case RX_MSDU_START_SGI_0_8_US: | |
369 | return NL80211_RATE_INFO_EHT_GI_0_8; | |
370 | case RX_MSDU_START_SGI_1_6_US: | |
371 | return NL80211_RATE_INFO_EHT_GI_1_6; | |
372 | case RX_MSDU_START_SGI_3_2_US: | |
373 | return NL80211_RATE_INFO_EHT_GI_3_2; | |
374 | default: | |
375 | return NL80211_RATE_INFO_EHT_GI_0_8; | |
376 | } | |
377 | } | |
378 | ||
379 | enum nl80211_eht_ru_alloc ath12k_mac_eht_ru_tones_to_nl80211_eht_ru_alloc(u16 ru_tones) | |
380 | { | |
381 | switch (ru_tones) { | |
382 | case 26: | |
383 | return NL80211_RATE_INFO_EHT_RU_ALLOC_26; | |
384 | case 52: | |
385 | return NL80211_RATE_INFO_EHT_RU_ALLOC_52; | |
386 | case (52 + 26): | |
387 | return NL80211_RATE_INFO_EHT_RU_ALLOC_52P26; | |
388 | case 106: | |
389 | return NL80211_RATE_INFO_EHT_RU_ALLOC_106; | |
390 | case (106 + 26): | |
391 | return NL80211_RATE_INFO_EHT_RU_ALLOC_106P26; | |
392 | case 242: | |
393 | return NL80211_RATE_INFO_EHT_RU_ALLOC_242; | |
394 | case 484: | |
395 | return NL80211_RATE_INFO_EHT_RU_ALLOC_484; | |
396 | case (484 + 242): | |
397 | return NL80211_RATE_INFO_EHT_RU_ALLOC_484P242; | |
398 | case 996: | |
399 | return NL80211_RATE_INFO_EHT_RU_ALLOC_996; | |
400 | case (996 + 484): | |
401 | return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484; | |
402 | case (996 + 484 + 242): | |
403 | return NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242; | |
404 | case (2 * 996): | |
405 | return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996; | |
406 | case (2 * 996 + 484): | |
407 | return NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484; | |
408 | case (3 * 996): | |
409 | return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996; | |
410 | case (3 * 996 + 484): | |
411 | return NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484; | |
412 | case (4 * 996): | |
413 | return NL80211_RATE_INFO_EHT_RU_ALLOC_4x996; | |
414 | default: | |
415 | return NL80211_RATE_INFO_EHT_RU_ALLOC_26; | |
416 | } | |
417 | } | |
418 | ||
d8899132 KV |
419 | enum rate_info_bw |
420 | ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw) | |
421 | { | |
422 | u8 ret = RATE_INFO_BW_20; | |
423 | ||
424 | switch (bw) { | |
425 | case ATH12K_BW_20: | |
426 | ret = RATE_INFO_BW_20; | |
427 | break; | |
428 | case ATH12K_BW_40: | |
429 | ret = RATE_INFO_BW_40; | |
430 | break; | |
431 | case ATH12K_BW_80: | |
432 | ret = RATE_INFO_BW_80; | |
433 | break; | |
434 | case ATH12K_BW_160: | |
435 | ret = RATE_INFO_BW_160; | |
436 | break; | |
37a0dd61 MS |
437 | case ATH12K_BW_320: |
438 | ret = RATE_INFO_BW_320; | |
439 | break; | |
d8899132 KV |
440 | } |
441 | ||
442 | return ret; | |
443 | } | |
444 | ||
445 | enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw) | |
446 | { | |
447 | switch (bw) { | |
448 | case RATE_INFO_BW_20: | |
449 | return ATH12K_BW_20; | |
450 | case RATE_INFO_BW_40: | |
451 | return ATH12K_BW_40; | |
452 | case RATE_INFO_BW_80: | |
453 | return ATH12K_BW_80; | |
454 | case RATE_INFO_BW_160: | |
455 | return ATH12K_BW_160; | |
37a0dd61 MS |
456 | case RATE_INFO_BW_320: |
457 | return ATH12K_BW_320; | |
d8899132 KV |
458 | default: |
459 | return ATH12K_BW_20; | |
460 | } | |
461 | } | |
462 | ||
463 | int ath12k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx, | |
464 | u16 *rate) | |
465 | { | |
466 | /* As default, it is OFDM rates */ | |
467 | int i = ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
468 | int max_rates_idx = ath12k_g_rates_size; | |
469 | ||
470 | if (preamble == WMI_RATE_PREAMBLE_CCK) { | |
471 | hw_rc &= ~ATH12K_HW_RATECODE_CCK_SHORT_PREAM_MASK; | |
472 | i = 0; | |
473 | max_rates_idx = ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
474 | } | |
475 | ||
476 | while (i < max_rates_idx) { | |
477 | if (hw_rc == ath12k_legacy_rates[i].hw_value) { | |
478 | *rateidx = i; | |
479 | *rate = ath12k_legacy_rates[i].bitrate; | |
480 | return 0; | |
481 | } | |
482 | i++; | |
483 | } | |
484 | ||
485 | return -EINVAL; | |
486 | } | |
487 | ||
488 | u8 ath12k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, | |
489 | u32 bitrate) | |
490 | { | |
491 | int i; | |
492 | ||
493 | for (i = 0; i < sband->n_bitrates; i++) | |
494 | if (sband->bitrates[i].bitrate == bitrate) | |
495 | return i; | |
496 | ||
497 | return 0; | |
498 | } | |
499 | ||
500 | static u32 | |
695df2f4 | 501 | ath12k_mac_max_ht_nss(const u8 *ht_mcs_mask) |
d8899132 KV |
502 | { |
503 | int nss; | |
504 | ||
505 | for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) | |
506 | if (ht_mcs_mask[nss]) | |
507 | return nss + 1; | |
508 | ||
509 | return 1; | |
510 | } | |
511 | ||
512 | static u32 | |
695df2f4 | 513 | ath12k_mac_max_vht_nss(const u16 *vht_mcs_mask) |
d8899132 KV |
514 | { |
515 | int nss; | |
516 | ||
517 | for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) | |
518 | if (vht_mcs_mask[nss]) | |
519 | return nss + 1; | |
520 | ||
521 | return 1; | |
522 | } | |
523 | ||
524 | static u8 ath12k_parse_mpdudensity(u8 mpdudensity) | |
525 | { | |
526 | /* From IEEE Std 802.11-2020 defined values for "Minimum MPDU Start Spacing": | |
527 | * 0 for no restriction | |
528 | * 1 for 1/4 us | |
529 | * 2 for 1/2 us | |
530 | * 3 for 1 us | |
531 | * 4 for 2 us | |
532 | * 5 for 4 us | |
533 | * 6 for 8 us | |
534 | * 7 for 16 us | |
535 | */ | |
536 | switch (mpdudensity) { | |
537 | case 0: | |
538 | return 0; | |
539 | case 1: | |
540 | case 2: | |
541 | case 3: | |
542 | /* Our lower layer calculations limit our precision to | |
543 | * 1 microsecond | |
544 | */ | |
545 | return 1; | |
546 | case 4: | |
547 | return 2; | |
548 | case 5: | |
549 | return 4; | |
550 | case 6: | |
551 | return 8; | |
552 | case 7: | |
553 | return 16; | |
554 | default: | |
555 | return 0; | |
556 | } | |
557 | } | |
558 | ||
abaadb93 RS |
559 | static int ath12k_mac_vif_link_chan(struct ieee80211_vif *vif, u8 link_id, |
560 | struct cfg80211_chan_def *def) | |
d8899132 | 561 | { |
abaadb93 | 562 | struct ieee80211_bss_conf *link_conf; |
d8899132 KV |
563 | struct ieee80211_chanctx_conf *conf; |
564 | ||
565 | rcu_read_lock(); | |
abaadb93 RS |
566 | link_conf = rcu_dereference(vif->link_conf[link_id]); |
567 | ||
568 | if (!link_conf) { | |
569 | rcu_read_unlock(); | |
570 | return -ENOLINK; | |
571 | } | |
572 | ||
573 | conf = rcu_dereference(link_conf->chanctx_conf); | |
d8899132 KV |
574 | if (!conf) { |
575 | rcu_read_unlock(); | |
576 | return -ENOENT; | |
577 | } | |
d8899132 KV |
578 | *def = conf->def; |
579 | rcu_read_unlock(); | |
580 | ||
581 | return 0; | |
582 | } | |
583 | ||
172e1570 AD |
584 | static struct ath12k_link_vif * |
585 | ath12k_mac_get_tx_arvif(struct ath12k_link_vif *arvif, | |
586 | struct ieee80211_bss_conf *link_conf) | |
20fe6390 | 587 | { |
172e1570 | 588 | struct ieee80211_bss_conf *tx_bss_conf; |
f6008327 | 589 | struct ath12k *ar = arvif->ar; |
20fe6390 AD |
590 | struct ath12k_vif *tx_ahvif; |
591 | ||
f6008327 RS |
592 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
593 | ||
f6008327 RS |
594 | tx_bss_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
595 | link_conf->tx_bss_conf); | |
596 | if (tx_bss_conf) { | |
597 | tx_ahvif = ath12k_vif_to_ahvif(tx_bss_conf->vif); | |
598 | return wiphy_dereference(tx_ahvif->ah->hw->wiphy, | |
599 | tx_ahvif->link[tx_bss_conf->link_id]); | |
20fe6390 AD |
600 | } |
601 | ||
602 | return NULL; | |
603 | } | |
604 | ||
f9c88d65 | 605 | struct ieee80211_bss_conf * |
39526578 S |
606 | ath12k_mac_get_link_bss_conf(struct ath12k_link_vif *arvif) |
607 | { | |
608 | struct ieee80211_vif *vif = arvif->ahvif->vif; | |
609 | struct ieee80211_bss_conf *link_conf; | |
610 | struct ath12k *ar = arvif->ar; | |
611 | ||
612 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
613 | ||
614 | if (arvif->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) | |
615 | return NULL; | |
616 | ||
617 | link_conf = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, | |
618 | vif->link_conf[arvif->link_id]); | |
619 | ||
620 | return link_conf; | |
621 | } | |
622 | ||
63fdb906 S |
623 | static struct ieee80211_link_sta *ath12k_mac_get_link_sta(struct ath12k_link_sta *arsta) |
624 | { | |
625 | struct ath12k_sta *ahsta = arsta->ahsta; | |
626 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); | |
627 | struct ieee80211_link_sta *link_sta; | |
628 | ||
629 | lockdep_assert_wiphy(ahsta->ahvif->ah->hw->wiphy); | |
630 | ||
631 | if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) | |
632 | return NULL; | |
633 | ||
634 | link_sta = wiphy_dereference(ahsta->ahvif->ah->hw->wiphy, | |
635 | sta->link[arsta->link_id]); | |
636 | ||
637 | return link_sta; | |
638 | } | |
639 | ||
d8899132 KV |
640 | static bool ath12k_mac_bitrate_is_cck(int bitrate) |
641 | { | |
642 | switch (bitrate) { | |
643 | case 10: | |
644 | case 20: | |
645 | case 55: | |
646 | case 110: | |
647 | return true; | |
648 | } | |
649 | ||
650 | return false; | |
651 | } | |
652 | ||
653 | u8 ath12k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, | |
654 | u8 hw_rate, bool cck) | |
655 | { | |
656 | const struct ieee80211_rate *rate; | |
657 | int i; | |
658 | ||
659 | for (i = 0; i < sband->n_bitrates; i++) { | |
660 | rate = &sband->bitrates[i]; | |
661 | ||
662 | if (ath12k_mac_bitrate_is_cck(rate->bitrate) != cck) | |
663 | continue; | |
664 | ||
665 | if (rate->hw_value == hw_rate) | |
666 | return i; | |
667 | else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && | |
668 | rate->hw_value_short == hw_rate) | |
669 | return i; | |
670 | } | |
671 | ||
672 | return 0; | |
673 | } | |
674 | ||
675 | static u8 ath12k_mac_bitrate_to_rate(int bitrate) | |
676 | { | |
677 | return DIV_ROUND_UP(bitrate, 5) | | |
678 | (ath12k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); | |
679 | } | |
680 | ||
681 | static void ath12k_get_arvif_iter(void *data, u8 *mac, | |
682 | struct ieee80211_vif *vif) | |
683 | { | |
684 | struct ath12k_vif_iter *arvif_iter = data; | |
3dd2c68f | 685 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
94a2712f RS |
686 | unsigned long links_map = ahvif->links_map; |
687 | struct ath12k_link_vif *arvif; | |
688 | u8 link_id; | |
689 | ||
690 | for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { | |
691 | arvif = rcu_dereference(ahvif->link[link_id]); | |
692 | ||
693 | if (WARN_ON(!arvif)) | |
694 | continue; | |
d8899132 | 695 | |
94a2712f RS |
696 | if (arvif->vdev_id == arvif_iter->vdev_id && |
697 | arvif->ar == arvif_iter->ar) { | |
698 | arvif_iter->arvif = arvif; | |
699 | break; | |
700 | } | |
701 | } | |
d8899132 KV |
702 | } |
703 | ||
3dd2c68f | 704 | struct ath12k_link_vif *ath12k_mac_get_arvif(struct ath12k *ar, u32 vdev_id) |
d8899132 KV |
705 | { |
706 | struct ath12k_vif_iter arvif_iter = {}; | |
707 | u32 flags; | |
708 | ||
3dd2c68f S |
709 | /* To use the arvif returned, caller must have held rcu read lock. |
710 | */ | |
711 | WARN_ON(!rcu_read_lock_any_held()); | |
d8899132 | 712 | arvif_iter.vdev_id = vdev_id; |
cec77a25 | 713 | arvif_iter.ar = ar; |
d8899132 KV |
714 | |
715 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; | |
b856f023 | 716 | ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), |
d8899132 KV |
717 | flags, |
718 | ath12k_get_arvif_iter, | |
719 | &arvif_iter); | |
720 | if (!arvif_iter.arvif) { | |
721 | ath12k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id); | |
722 | return NULL; | |
723 | } | |
724 | ||
725 | return arvif_iter.arvif; | |
726 | } | |
727 | ||
3dd2c68f S |
728 | struct ath12k_link_vif *ath12k_mac_get_arvif_by_vdev_id(struct ath12k_base *ab, |
729 | u32 vdev_id) | |
d8899132 KV |
730 | { |
731 | int i; | |
732 | struct ath12k_pdev *pdev; | |
3dd2c68f | 733 | struct ath12k_link_vif *arvif; |
d8899132 KV |
734 | |
735 | for (i = 0; i < ab->num_radios; i++) { | |
736 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
af9bc78d GBJ |
737 | if (pdev && pdev->ar && |
738 | (pdev->ar->allocated_vdev_map & (1LL << vdev_id))) { | |
d8899132 KV |
739 | arvif = ath12k_mac_get_arvif(pdev->ar, vdev_id); |
740 | if (arvif) | |
741 | return arvif; | |
742 | } | |
743 | } | |
744 | ||
745 | return NULL; | |
746 | } | |
747 | ||
748 | struct ath12k *ath12k_mac_get_ar_by_vdev_id(struct ath12k_base *ab, u32 vdev_id) | |
749 | { | |
750 | int i; | |
751 | struct ath12k_pdev *pdev; | |
752 | ||
753 | for (i = 0; i < ab->num_radios; i++) { | |
754 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
755 | if (pdev && pdev->ar) { | |
756 | if (pdev->ar->allocated_vdev_map & (1LL << vdev_id)) | |
757 | return pdev->ar; | |
758 | } | |
759 | } | |
760 | ||
761 | return NULL; | |
762 | } | |
763 | ||
764 | struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id) | |
765 | { | |
766 | int i; | |
767 | struct ath12k_pdev *pdev; | |
768 | ||
769 | if (ab->hw_params->single_pdev_only) { | |
770 | pdev = rcu_dereference(ab->pdevs_active[0]); | |
771 | return pdev ? pdev->ar : NULL; | |
772 | } | |
773 | ||
774 | if (WARN_ON(pdev_id > ab->num_radios)) | |
775 | return NULL; | |
776 | ||
777 | for (i = 0; i < ab->num_radios; i++) { | |
3bc374cb AS |
778 | if (ab->fw_mode == ATH12K_FIRMWARE_MODE_FTM) |
779 | pdev = &ab->pdevs[i]; | |
780 | else | |
781 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
d8899132 KV |
782 | |
783 | if (pdev && pdev->pdev_id == pdev_id) | |
784 | return (pdev->ar ? pdev->ar : NULL); | |
785 | } | |
786 | ||
787 | return NULL; | |
788 | } | |
789 | ||
1ea0cdee S |
790 | static bool ath12k_mac_is_ml_arvif(struct ath12k_link_vif *arvif) |
791 | { | |
792 | struct ath12k_vif *ahvif = arvif->ahvif; | |
793 | ||
794 | lockdep_assert_wiphy(ahvif->ah->hw->wiphy); | |
795 | ||
796 | if (ahvif->vif->valid_links & BIT(arvif->link_id)) | |
797 | return true; | |
798 | ||
799 | return false; | |
800 | } | |
801 | ||
d01c08ed S |
802 | static struct ath12k *ath12k_mac_get_ar_by_chan(struct ieee80211_hw *hw, |
803 | struct ieee80211_channel *channel) | |
804 | { | |
805 | struct ath12k_hw *ah = hw->priv; | |
806 | struct ath12k *ar; | |
807 | int i; | |
808 | ||
809 | ar = ah->radio; | |
810 | ||
811 | if (ah->num_radio == 1) | |
812 | return ar; | |
813 | ||
814 | for_each_ar(ah, ar, i) { | |
3c9bc818 KP |
815 | if (channel->center_freq >= KHZ_TO_MHZ(ar->freq_range.start_freq) && |
816 | channel->center_freq <= KHZ_TO_MHZ(ar->freq_range.end_freq)) | |
d01c08ed S |
817 | return ar; |
818 | } | |
819 | return NULL; | |
820 | } | |
821 | ||
822 | static struct ath12k *ath12k_get_ar_by_ctx(struct ieee80211_hw *hw, | |
823 | struct ieee80211_chanctx_conf *ctx) | |
824 | { | |
825 | if (!ctx) | |
826 | return NULL; | |
827 | ||
828 | return ath12k_mac_get_ar_by_chan(hw, ctx->def.chan); | |
829 | } | |
830 | ||
a412547f KP |
831 | struct ath12k *ath12k_get_ar_by_vif(struct ieee80211_hw *hw, |
832 | struct ieee80211_vif *vif, | |
833 | u8 link_id) | |
0148e40c | 834 | { |
3dd2c68f | 835 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
0148e40c | 836 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
5419ef95 S |
837 | struct ath12k_link_vif *arvif; |
838 | ||
839 | lockdep_assert_wiphy(hw->wiphy); | |
0148e40c S |
840 | |
841 | /* If there is one pdev within ah, then we return | |
842 | * ar directly. | |
843 | */ | |
844 | if (ah->num_radio == 1) | |
845 | return ah->radio; | |
846 | ||
5419ef95 S |
847 | if (!(ahvif->links_map & BIT(link_id))) |
848 | return NULL; | |
849 | ||
850 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
851 | if (arvif && arvif->is_created) | |
0148e40c S |
852 | return arvif->ar; |
853 | ||
854 | return NULL; | |
855 | } | |
856 | ||
40562e84 AKS |
857 | void ath12k_mac_get_any_chanctx_conf_iter(struct ieee80211_hw *hw, |
858 | struct ieee80211_chanctx_conf *conf, | |
859 | void *data) | |
860 | { | |
861 | struct ath12k_mac_get_any_chanctx_conf_arg *arg = data; | |
862 | struct ath12k *ctx_ar = ath12k_get_ar_by_ctx(hw, conf); | |
863 | ||
864 | if (ctx_ar == arg->ar) | |
865 | arg->chanctx_conf = conf; | |
866 | } | |
867 | ||
3dd2c68f | 868 | static struct ath12k_link_vif *ath12k_mac_get_vif_up(struct ath12k *ar) |
2c785767 | 869 | { |
3dd2c68f | 870 | struct ath12k_link_vif *arvif; |
2c785767 | 871 | |
b8c67509 | 872 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
2c785767 | 873 | |
2c785767 LK |
874 | list_for_each_entry(arvif, &ar->arvifs, list) { |
875 | if (arvif->is_up) | |
876 | return arvif; | |
877 | } | |
878 | ||
879 | return NULL; | |
880 | } | |
881 | ||
882 | static bool ath12k_mac_band_match(enum nl80211_band band1, enum WMI_HOST_WLAN_BAND band2) | |
883 | { | |
884 | switch (band1) { | |
885 | case NL80211_BAND_2GHZ: | |
6a88093f | 886 | if (band2 & WMI_HOST_WLAN_2GHZ_CAP) |
2c785767 LK |
887 | return true; |
888 | break; | |
889 | case NL80211_BAND_5GHZ: | |
890 | case NL80211_BAND_6GHZ: | |
6a88093f | 891 | if (band2 & WMI_HOST_WLAN_5GHZ_CAP) |
2c785767 LK |
892 | return true; |
893 | break; | |
894 | default: | |
895 | return false; | |
896 | } | |
897 | ||
898 | return false; | |
899 | } | |
900 | ||
3dd2c68f | 901 | static u8 ath12k_mac_get_target_pdev_id_from_vif(struct ath12k_link_vif *arvif) |
2c785767 LK |
902 | { |
903 | struct ath12k *ar = arvif->ar; | |
904 | struct ath12k_base *ab = ar->ab; | |
3dd2c68f | 905 | struct ieee80211_vif *vif = arvif->ahvif->vif; |
2c785767 LK |
906 | struct cfg80211_chan_def def; |
907 | enum nl80211_band band; | |
908 | u8 pdev_id = ab->fw_pdev[0].pdev_id; | |
909 | int i; | |
910 | ||
abaadb93 | 911 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
2c785767 LK |
912 | return pdev_id; |
913 | ||
914 | band = def.chan->band; | |
915 | ||
916 | for (i = 0; i < ab->fw_pdev_count; i++) { | |
917 | if (ath12k_mac_band_match(band, ab->fw_pdev[i].supported_bands)) | |
918 | return ab->fw_pdev[i].pdev_id; | |
919 | } | |
920 | ||
921 | return pdev_id; | |
922 | } | |
923 | ||
924 | u8 ath12k_mac_get_target_pdev_id(struct ath12k *ar) | |
925 | { | |
3dd2c68f | 926 | struct ath12k_link_vif *arvif; |
2c785767 LK |
927 | struct ath12k_base *ab = ar->ab; |
928 | ||
929 | if (!ab->hw_params->single_pdev_only) | |
930 | return ar->pdev->pdev_id; | |
931 | ||
932 | arvif = ath12k_mac_get_vif_up(ar); | |
933 | ||
934 | /* fw_pdev array has pdev ids derived from phy capability | |
935 | * service ready event (pdev_and_hw_link_ids). | |
936 | * If no vif is active, return default first index. | |
937 | */ | |
938 | if (!arvif) | |
939 | return ar->ab->fw_pdev[0].pdev_id; | |
940 | ||
941 | /* If active vif is found, return the pdev id matching chandef band */ | |
942 | return ath12k_mac_get_target_pdev_id_from_vif(arvif); | |
943 | } | |
944 | ||
d8899132 KV |
945 | static void ath12k_pdev_caps_update(struct ath12k *ar) |
946 | { | |
947 | struct ath12k_base *ab = ar->ab; | |
948 | ||
949 | ar->max_tx_power = ab->target_caps.hw_max_tx_power; | |
950 | ||
951 | /* FIXME: Set min_tx_power to ab->target_caps.hw_min_tx_power. | |
952 | * But since the received value in svcrdy is same as hw_max_tx_power, | |
953 | * we can set ar->min_tx_power to 0 currently until | |
954 | * this is fixed in firmware | |
955 | */ | |
956 | ar->min_tx_power = 0; | |
957 | ||
958 | ar->txpower_limit_2g = ar->max_tx_power; | |
959 | ar->txpower_limit_5g = ar->max_tx_power; | |
960 | ar->txpower_scale = WMI_HOST_TP_SCALE_MAX; | |
961 | } | |
962 | ||
963 | static int ath12k_mac_txpower_recalc(struct ath12k *ar) | |
964 | { | |
965 | struct ath12k_pdev *pdev = ar->pdev; | |
3dd2c68f | 966 | struct ath12k_link_vif *arvif; |
d8899132 KV |
967 | int ret, txpower = -1; |
968 | u32 param; | |
969 | ||
b8c67509 | 970 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
971 | |
972 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
973 | if (arvif->txpower <= 0) | |
974 | continue; | |
975 | ||
976 | if (txpower == -1) | |
977 | txpower = arvif->txpower; | |
978 | else | |
979 | txpower = min(txpower, arvif->txpower); | |
980 | } | |
981 | ||
982 | if (txpower == -1) | |
983 | return 0; | |
984 | ||
985 | /* txpwr is set as 2 units per dBm in FW*/ | |
986 | txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower), | |
987 | ar->max_tx_power) * 2; | |
988 | ||
989 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower to set in hw %d\n", | |
990 | txpower / 2); | |
991 | ||
6a88093f | 992 | if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) && |
d8899132 KV |
993 | ar->txpower_limit_2g != txpower) { |
994 | param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G; | |
995 | ret = ath12k_wmi_pdev_set_param(ar, param, | |
996 | txpower, ar->pdev->pdev_id); | |
997 | if (ret) | |
998 | goto fail; | |
999 | ar->txpower_limit_2g = txpower; | |
1000 | } | |
1001 | ||
6a88093f | 1002 | if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) && |
d8899132 KV |
1003 | ar->txpower_limit_5g != txpower) { |
1004 | param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G; | |
1005 | ret = ath12k_wmi_pdev_set_param(ar, param, | |
1006 | txpower, ar->pdev->pdev_id); | |
1007 | if (ret) | |
1008 | goto fail; | |
1009 | ar->txpower_limit_5g = txpower; | |
1010 | } | |
1011 | ||
1012 | return 0; | |
1013 | ||
1014 | fail: | |
1015 | ath12k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n", | |
1016 | txpower / 2, param, ret); | |
1017 | return ret; | |
1018 | } | |
1019 | ||
3dd2c68f | 1020 | static int ath12k_recalc_rtscts_prot(struct ath12k_link_vif *arvif) |
d8899132 KV |
1021 | { |
1022 | struct ath12k *ar = arvif->ar; | |
1023 | u32 vdev_param, rts_cts; | |
1024 | int ret; | |
1025 | ||
b8c67509 | 1026 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1027 | |
1028 | vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS; | |
1029 | ||
1030 | /* Enable RTS/CTS protection for sw retries (when legacy stations | |
1031 | * are in BSS) or by default only for second rate series. | |
1032 | * TODO: Check if we need to enable CTS 2 Self in any case | |
1033 | */ | |
1034 | rts_cts = WMI_USE_RTS_CTS; | |
1035 | ||
1036 | if (arvif->num_legacy_stations > 0) | |
1037 | rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4; | |
1038 | else | |
1039 | rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4; | |
1040 | ||
1041 | /* Need not send duplicate param value to firmware */ | |
1042 | if (arvif->rtscts_prot_mode == rts_cts) | |
1043 | return 0; | |
1044 | ||
1045 | arvif->rtscts_prot_mode = rts_cts; | |
1046 | ||
1047 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", | |
1048 | arvif->vdev_id, rts_cts); | |
1049 | ||
1050 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1051 | vdev_param, rts_cts); | |
1052 | if (ret) | |
1053 | ath12k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n", | |
1054 | arvif->vdev_id, ret); | |
1055 | ||
1056 | return ret; | |
1057 | } | |
1058 | ||
3dd2c68f | 1059 | static int ath12k_mac_set_kickout(struct ath12k_link_vif *arvif) |
d8899132 KV |
1060 | { |
1061 | struct ath12k *ar = arvif->ar; | |
1062 | u32 param; | |
1063 | int ret; | |
1064 | ||
1065 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH, | |
1066 | ATH12K_KICKOUT_THRESHOLD, | |
1067 | ar->pdev->pdev_id); | |
1068 | if (ret) { | |
1069 | ath12k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n", | |
1070 | arvif->vdev_id, ret); | |
1071 | return ret; | |
1072 | } | |
1073 | ||
1074 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS; | |
1075 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
1076 | ATH12K_KEEPALIVE_MIN_IDLE); | |
1077 | if (ret) { | |
1078 | ath12k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n", | |
1079 | arvif->vdev_id, ret); | |
1080 | return ret; | |
1081 | } | |
1082 | ||
1083 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS; | |
1084 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
1085 | ATH12K_KEEPALIVE_MAX_IDLE); | |
1086 | if (ret) { | |
1087 | ath12k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n", | |
1088 | arvif->vdev_id, ret); | |
1089 | return ret; | |
1090 | } | |
1091 | ||
1092 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS; | |
1093 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
1094 | ATH12K_KEEPALIVE_MAX_UNRESPONSIVE); | |
1095 | if (ret) { | |
1096 | ath12k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", | |
1097 | arvif->vdev_id, ret); | |
1098 | return ret; | |
1099 | } | |
1100 | ||
1101 | return 0; | |
1102 | } | |
1103 | ||
1104 | void ath12k_mac_peer_cleanup_all(struct ath12k *ar) | |
1105 | { | |
1106 | struct ath12k_peer *peer, *tmp; | |
1107 | struct ath12k_base *ab = ar->ab; | |
1108 | ||
b8c67509 | 1109 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1110 | |
1111 | spin_lock_bh(&ab->base_lock); | |
1112 | list_for_each_entry_safe(peer, tmp, &ab->peers, list) { | |
1a0c640c RG |
1113 | /* Skip Rx TID cleanup for self peer */ |
1114 | if (peer->sta) | |
1115 | ath12k_dp_rx_peer_tid_cleanup(ar, peer); | |
1116 | ||
d8899132 KV |
1117 | list_del(&peer->list); |
1118 | kfree(peer); | |
1119 | } | |
1120 | spin_unlock_bh(&ab->base_lock); | |
1121 | ||
1122 | ar->num_peers = 0; | |
1123 | ar->num_stations = 0; | |
1124 | } | |
1125 | ||
1126 | static int ath12k_mac_vdev_setup_sync(struct ath12k *ar) | |
1127 | { | |
b8c67509 | 1128 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1129 | |
1130 | if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
1131 | return -ESHUTDOWN; | |
1132 | ||
1fd2c3f9 A |
1133 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev setup timeout %d\n", |
1134 | ATH12K_VDEV_SETUP_TIMEOUT_HZ); | |
1135 | ||
d8899132 KV |
1136 | if (!wait_for_completion_timeout(&ar->vdev_setup_done, |
1137 | ATH12K_VDEV_SETUP_TIMEOUT_HZ)) | |
1138 | return -ETIMEDOUT; | |
1139 | ||
1140 | return ar->last_wmi_vdev_start_status ? -EINVAL : 0; | |
1141 | } | |
1142 | ||
1143 | static int ath12k_monitor_vdev_up(struct ath12k *ar, int vdev_id) | |
1144 | { | |
51c47463 | 1145 | struct ath12k_wmi_vdev_up_params params = {}; |
d8899132 KV |
1146 | int ret; |
1147 | ||
51c47463 AD |
1148 | params.vdev_id = vdev_id; |
1149 | params.bssid = ar->mac_addr; | |
1150 | ret = ath12k_wmi_vdev_up(ar, ¶ms); | |
d8899132 KV |
1151 | if (ret) { |
1152 | ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", | |
1153 | vdev_id, ret); | |
1154 | return ret; | |
1155 | } | |
1156 | ||
1157 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", | |
1158 | vdev_id); | |
1159 | return 0; | |
1160 | } | |
1161 | ||
1162 | static int ath12k_mac_monitor_vdev_start(struct ath12k *ar, int vdev_id, | |
1163 | struct cfg80211_chan_def *chandef) | |
1164 | { | |
1165 | struct ieee80211_channel *channel; | |
1166 | struct wmi_vdev_start_req_arg arg = {}; | |
51c47463 | 1167 | struct ath12k_wmi_vdev_up_params params = {}; |
d8899132 KV |
1168 | int ret; |
1169 | ||
b8c67509 | 1170 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1171 | |
1172 | channel = chandef->chan; | |
1173 | arg.vdev_id = vdev_id; | |
1174 | arg.freq = channel->center_freq; | |
1175 | arg.band_center_freq1 = chandef->center_freq1; | |
1176 | arg.band_center_freq2 = chandef->center_freq2; | |
1177 | arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; | |
1178 | arg.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR); | |
1179 | ||
1180 | arg.min_power = 0; | |
1181 | arg.max_power = channel->max_power; | |
1182 | arg.max_reg_power = channel->max_reg_power; | |
1183 | arg.max_antenna_gain = channel->max_antenna_gain; | |
1184 | ||
1185 | arg.pref_tx_streams = ar->num_tx_chains; | |
1186 | arg.pref_rx_streams = ar->num_rx_chains; | |
07c01b86 | 1187 | arg.punct_bitmap = 0xFFFFFFFF; |
d8899132 KV |
1188 | |
1189 | arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); | |
1190 | ||
1191 | reinit_completion(&ar->vdev_setup_done); | |
1192 | reinit_completion(&ar->vdev_delete_done); | |
1193 | ||
1194 | ret = ath12k_wmi_vdev_start(ar, &arg, false); | |
1195 | if (ret) { | |
1196 | ath12k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n", | |
1197 | vdev_id, ret); | |
1198 | return ret; | |
1199 | } | |
1200 | ||
1201 | ret = ath12k_mac_vdev_setup_sync(ar); | |
1202 | if (ret) { | |
1203 | ath12k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n", | |
1204 | vdev_id, ret); | |
1205 | return ret; | |
1206 | } | |
1207 | ||
51c47463 AD |
1208 | params.vdev_id = vdev_id; |
1209 | params.bssid = ar->mac_addr; | |
1210 | ret = ath12k_wmi_vdev_up(ar, ¶ms); | |
d8899132 KV |
1211 | if (ret) { |
1212 | ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", | |
1213 | vdev_id, ret); | |
1214 | goto vdev_stop; | |
1215 | } | |
1216 | ||
1217 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", | |
1218 | vdev_id); | |
1219 | return 0; | |
1220 | ||
1221 | vdev_stop: | |
1222 | ret = ath12k_wmi_vdev_stop(ar, vdev_id); | |
1223 | if (ret) | |
1224 | ath12k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n", | |
1225 | vdev_id, ret); | |
1226 | return ret; | |
1227 | } | |
1228 | ||
1229 | static int ath12k_mac_monitor_vdev_stop(struct ath12k *ar) | |
1230 | { | |
1231 | int ret; | |
1232 | ||
b8c67509 | 1233 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1234 | |
1235 | reinit_completion(&ar->vdev_setup_done); | |
1236 | ||
1237 | ret = ath12k_wmi_vdev_stop(ar, ar->monitor_vdev_id); | |
1238 | if (ret) | |
1239 | ath12k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n", | |
1240 | ar->monitor_vdev_id, ret); | |
1241 | ||
1242 | ret = ath12k_mac_vdev_setup_sync(ar); | |
1243 | if (ret) | |
1244 | ath12k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n", | |
1245 | ar->monitor_vdev_id, ret); | |
1246 | ||
1247 | ret = ath12k_wmi_vdev_down(ar, ar->monitor_vdev_id); | |
1248 | if (ret) | |
1249 | ath12k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n", | |
1250 | ar->monitor_vdev_id, ret); | |
1251 | ||
1252 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i stopped\n", | |
1253 | ar->monitor_vdev_id); | |
1254 | return ret; | |
1255 | } | |
1256 | ||
d8899132 KV |
1257 | static int ath12k_mac_monitor_vdev_delete(struct ath12k *ar) |
1258 | { | |
1259 | int ret; | |
1260 | unsigned long time_left; | |
1261 | ||
b8c67509 | 1262 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1263 | |
1264 | if (!ar->monitor_vdev_created) | |
1265 | return 0; | |
1266 | ||
1267 | reinit_completion(&ar->vdev_delete_done); | |
1268 | ||
1269 | ret = ath12k_wmi_vdev_delete(ar, ar->monitor_vdev_id); | |
1270 | if (ret) { | |
1271 | ath12k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n", | |
1272 | ar->monitor_vdev_id, ret); | |
1273 | return ret; | |
1274 | } | |
1275 | ||
1276 | time_left = wait_for_completion_timeout(&ar->vdev_delete_done, | |
1277 | ATH12K_VDEV_DELETE_TIMEOUT_HZ); | |
1278 | if (time_left == 0) { | |
1279 | ath12k_warn(ar->ab, "Timeout in receiving vdev delete response\n"); | |
1280 | } else { | |
1281 | ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id); | |
1282 | ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id); | |
1283 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %d deleted\n", | |
1284 | ar->monitor_vdev_id); | |
1285 | ar->num_created_vdevs--; | |
1286 | ar->monitor_vdev_id = -1; | |
1287 | ar->monitor_vdev_created = false; | |
1288 | } | |
1289 | ||
1290 | return ret; | |
1291 | } | |
1292 | ||
d8899132 KV |
1293 | static int ath12k_mac_monitor_start(struct ath12k *ar) |
1294 | { | |
1dfa44db | 1295 | struct ath12k_mac_get_any_chanctx_conf_arg arg; |
d8899132 KV |
1296 | int ret; |
1297 | ||
b8c67509 | 1298 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1299 | |
1300 | if (ar->monitor_started) | |
1301 | return 0; | |
1302 | ||
1dfa44db KP |
1303 | arg.ar = ar; |
1304 | arg.chanctx_conf = NULL; | |
b856f023 | 1305 | ieee80211_iter_chan_contexts_atomic(ath12k_ar_to_hw(ar), |
1dfa44db KP |
1306 | ath12k_mac_get_any_chanctx_conf_iter, |
1307 | &arg); | |
1308 | if (!arg.chanctx_conf) | |
d8899132 KV |
1309 | return 0; |
1310 | ||
1dfa44db KP |
1311 | ret = ath12k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id, |
1312 | &arg.chanctx_conf->def); | |
d8899132 KV |
1313 | if (ret) { |
1314 | ath12k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret); | |
d8899132 KV |
1315 | return ret; |
1316 | } | |
1317 | ||
2c4c3aff P |
1318 | ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, false); |
1319 | if (ret) { | |
1320 | ath12k_warn(ar->ab, "fail to set monitor filter: %d\n", ret); | |
d8899132 KV |
1321 | return ret; |
1322 | } | |
1323 | ||
1324 | ar->monitor_started = true; | |
1325 | ar->num_started_vdevs++; | |
d8899132 | 1326 | |
2c4c3aff P |
1327 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor started\n"); |
1328 | ||
1329 | return 0; | |
d8899132 KV |
1330 | } |
1331 | ||
1332 | static int ath12k_mac_monitor_stop(struct ath12k *ar) | |
1333 | { | |
1334 | int ret; | |
1335 | ||
b8c67509 | 1336 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
1337 | |
1338 | if (!ar->monitor_started) | |
1339 | return 0; | |
1340 | ||
1341 | ret = ath12k_mac_monitor_vdev_stop(ar); | |
1342 | if (ret) { | |
1343 | ath12k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret); | |
1344 | return ret; | |
1345 | } | |
1346 | ||
1347 | ar->monitor_started = false; | |
1348 | ar->num_started_vdevs--; | |
1349 | ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, true); | |
1350 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor stopped ret %d\n", ret); | |
1351 | return ret; | |
1352 | } | |
1353 | ||
8e6f8bc2 | 1354 | int ath12k_mac_vdev_stop(struct ath12k_link_vif *arvif) |
c9e4e41e | 1355 | { |
3dd2c68f | 1356 | struct ath12k_vif *ahvif = arvif->ahvif; |
c9e4e41e KY |
1357 | struct ath12k *ar = arvif->ar; |
1358 | int ret; | |
1359 | ||
b8c67509 | 1360 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
c9e4e41e KY |
1361 | |
1362 | reinit_completion(&ar->vdev_setup_done); | |
1363 | ||
1364 | ret = ath12k_wmi_vdev_stop(ar, arvif->vdev_id); | |
1365 | if (ret) { | |
1366 | ath12k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n", | |
1367 | arvif->vdev_id, ret); | |
1368 | goto err; | |
1369 | } | |
1370 | ||
1371 | ret = ath12k_mac_vdev_setup_sync(ar); | |
1372 | if (ret) { | |
1373 | ath12k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n", | |
1374 | arvif->vdev_id, ret); | |
1375 | goto err; | |
1376 | } | |
1377 | ||
1378 | WARN_ON(ar->num_started_vdevs == 0); | |
1379 | ||
1380 | ar->num_started_vdevs--; | |
1381 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n", | |
3dd2c68f | 1382 | ahvif->vif->addr, arvif->vdev_id); |
c9e4e41e | 1383 | |
d31241cb AKS |
1384 | if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) { |
1385 | clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); | |
c9e4e41e KY |
1386 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "CAC Stopped for vdev %d\n", |
1387 | arvif->vdev_id); | |
1388 | } | |
1389 | ||
1390 | return 0; | |
1391 | err: | |
1392 | return ret; | |
1393 | } | |
1394 | ||
3e141f00 KP |
1395 | static int ath12k_mac_op_config(struct ieee80211_hw *hw, u32 changed) |
1396 | { | |
7423b641 | 1397 | return 0; |
3e141f00 KP |
1398 | } |
1399 | ||
3dd2c68f | 1400 | static int ath12k_mac_setup_bcn_p2p_ie(struct ath12k_link_vif *arvif, |
575ec73c KY |
1401 | struct sk_buff *bcn) |
1402 | { | |
1403 | struct ath12k *ar = arvif->ar; | |
1404 | struct ieee80211_mgmt *mgmt; | |
1405 | const u8 *p2p_ie; | |
1406 | int ret; | |
1407 | ||
1408 | mgmt = (void *)bcn->data; | |
1409 | p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, | |
1410 | mgmt->u.beacon.variable, | |
1411 | bcn->len - (mgmt->u.beacon.variable - | |
1412 | bcn->data)); | |
1413 | if (!p2p_ie) { | |
1414 | ath12k_warn(ar->ab, "no P2P ie found in beacon\n"); | |
1415 | return -ENOENT; | |
1416 | } | |
1417 | ||
1418 | ret = ath12k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); | |
1419 | if (ret) { | |
1420 | ath12k_warn(ar->ab, "failed to submit P2P GO bcn ie for vdev %i: %d\n", | |
1421 | arvif->vdev_id, ret); | |
1422 | return ret; | |
1423 | } | |
1424 | ||
1425 | return 0; | |
1426 | } | |
1427 | ||
1428 | static int ath12k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, | |
1429 | u8 oui_type, size_t ie_offset) | |
1430 | { | |
1431 | const u8 *next, *end; | |
1432 | size_t len; | |
1433 | u8 *ie; | |
1434 | ||
1435 | if (WARN_ON(skb->len < ie_offset)) | |
1436 | return -EINVAL; | |
1437 | ||
1438 | ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, | |
1439 | skb->data + ie_offset, | |
1440 | skb->len - ie_offset); | |
1441 | if (!ie) | |
1442 | return -ENOENT; | |
1443 | ||
1444 | len = ie[1] + 2; | |
1445 | end = skb->data + skb->len; | |
1446 | next = ie + len; | |
1447 | ||
1448 | if (WARN_ON(next > end)) | |
1449 | return -EINVAL; | |
1450 | ||
1451 | memmove(ie, next, end - next); | |
1452 | skb_trim(skb, skb->len - len); | |
1453 | ||
1454 | return 0; | |
1455 | } | |
1456 | ||
3dd2c68f | 1457 | static void ath12k_mac_set_arvif_ies(struct ath12k_link_vif *arvif, struct sk_buff *bcn, |
8c6faa56 | 1458 | u8 bssid_index, bool *nontx_profile_found) |
9fd28936 AD |
1459 | { |
1460 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)bcn->data; | |
8c6faa56 | 1461 | const struct element *elem, *nontx, *index, *nie; |
9fd28936 AD |
1462 | const u8 *start, *tail; |
1463 | u16 rem_len; | |
8c6faa56 | 1464 | u8 i; |
9fd28936 AD |
1465 | |
1466 | start = bcn->data + ieee80211_get_hdrlen_from_skb(bcn) + sizeof(mgmt->u.beacon); | |
1467 | tail = skb_tail_pointer(bcn); | |
1468 | rem_len = tail - start; | |
1469 | ||
1470 | arvif->rsnie_present = false; | |
1471 | arvif->wpaie_present = false; | |
1472 | ||
1473 | if (cfg80211_find_ie(WLAN_EID_RSN, start, rem_len)) | |
1474 | arvif->rsnie_present = true; | |
1475 | if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, WLAN_OUI_TYPE_MICROSOFT_WPA, | |
1476 | start, rem_len)) | |
1477 | arvif->wpaie_present = true; | |
8c6faa56 AD |
1478 | |
1479 | /* Return from here for the transmitted profile */ | |
1480 | if (!bssid_index) | |
1481 | return; | |
1482 | ||
1483 | /* Initial rsnie_present for the nontransmitted profile is set to be same as that | |
1484 | * of the transmitted profile. It will be changed if security configurations are | |
1485 | * different. | |
1486 | */ | |
1487 | *nontx_profile_found = false; | |
1488 | for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, rem_len) { | |
1489 | /* Fixed minimum MBSSID element length with at least one | |
1490 | * nontransmitted BSSID profile is 12 bytes as given below; | |
1491 | * 1 (max BSSID indicator) + | |
1492 | * 2 (Nontransmitted BSSID profile: Subelement ID + length) + | |
1493 | * 4 (Nontransmitted BSSID Capabilities: tag + length + info) | |
1494 | * 2 (Nontransmitted BSSID SSID: tag + length) | |
1495 | * 3 (Nontransmitted BSSID Index: tag + length + BSSID index | |
1496 | */ | |
1497 | if (elem->datalen < 12 || elem->data[0] < 1) | |
1498 | continue; /* Max BSSID indicator must be >=1 */ | |
1499 | ||
1500 | for_each_element(nontx, elem->data + 1, elem->datalen - 1) { | |
1501 | start = nontx->data; | |
1502 | ||
1503 | if (nontx->id != 0 || nontx->datalen < 4) | |
1504 | continue; /* Invalid nontransmitted profile */ | |
1505 | ||
1506 | if (nontx->data[0] != WLAN_EID_NON_TX_BSSID_CAP || | |
1507 | nontx->data[1] != 2) { | |
1508 | continue; /* Missing nontransmitted BSS capabilities */ | |
1509 | } | |
1510 | ||
1511 | if (nontx->data[4] != WLAN_EID_SSID) | |
1512 | continue; /* Missing SSID for nontransmitted BSS */ | |
1513 | ||
1514 | index = cfg80211_find_elem(WLAN_EID_MULTI_BSSID_IDX, | |
1515 | start, nontx->datalen); | |
1516 | if (!index || index->datalen < 1 || index->data[0] == 0) | |
1517 | continue; /* Invalid MBSSID Index element */ | |
1518 | ||
1519 | if (index->data[0] == bssid_index) { | |
1520 | *nontx_profile_found = true; | |
1521 | if (cfg80211_find_ie(WLAN_EID_RSN, | |
1522 | nontx->data, | |
1523 | nontx->datalen)) { | |
1524 | arvif->rsnie_present = true; | |
1525 | return; | |
1526 | } else if (!arvif->rsnie_present) { | |
1527 | return; /* Both tx and nontx BSS are open */ | |
1528 | } | |
1529 | ||
1530 | nie = cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, | |
1531 | nontx->data, | |
1532 | nontx->datalen); | |
1533 | if (!nie || nie->datalen < 2) | |
1534 | return; /* Invalid non-inheritance element */ | |
1535 | ||
1536 | for (i = 1; i < nie->datalen - 1; i++) { | |
1537 | if (nie->data[i] == WLAN_EID_RSN) { | |
1538 | arvif->rsnie_present = false; | |
1539 | break; | |
1540 | } | |
1541 | } | |
1542 | ||
1543 | return; | |
1544 | } | |
1545 | } | |
1546 | } | |
9fd28936 AD |
1547 | } |
1548 | ||
5f1e9f2c | 1549 | static int ath12k_mac_setup_bcn_tmpl_ema(struct ath12k_link_vif *arvif, |
f4f5ee5e AD |
1550 | struct ath12k_link_vif *tx_arvif, |
1551 | u8 bssid_index) | |
f27fbd76 | 1552 | { |
f27fbd76 AD |
1553 | struct ath12k_wmi_bcn_tmpl_ema_arg ema_args; |
1554 | struct ieee80211_ema_beacons *beacons; | |
f27fbd76 AD |
1555 | bool nontx_profile_found = false; |
1556 | int ret = 0; | |
1557 | u8 i; | |
1558 | ||
f27fbd76 | 1559 | beacons = ieee80211_beacon_get_template_ema_list(ath12k_ar_to_hw(tx_arvif->ar), |
20fe6390 | 1560 | tx_arvif->ahvif->vif, |
1ea0cdee | 1561 | tx_arvif->link_id); |
f27fbd76 AD |
1562 | if (!beacons || !beacons->cnt) { |
1563 | ath12k_warn(arvif->ar->ab, | |
1564 | "failed to get ema beacon templates from mac80211\n"); | |
1565 | return -EPERM; | |
1566 | } | |
1567 | ||
1568 | if (tx_arvif == arvif) | |
1569 | ath12k_mac_set_arvif_ies(arvif, beacons->bcn[0].skb, 0, NULL); | |
1570 | ||
1571 | for (i = 0; i < beacons->cnt; i++) { | |
1572 | if (tx_arvif != arvif && !nontx_profile_found) | |
1573 | ath12k_mac_set_arvif_ies(arvif, beacons->bcn[i].skb, | |
f4f5ee5e | 1574 | bssid_index, |
f27fbd76 AD |
1575 | &nontx_profile_found); |
1576 | ||
1577 | ema_args.bcn_cnt = beacons->cnt; | |
1578 | ema_args.bcn_index = i; | |
40944459 | 1579 | ret = ath12k_wmi_bcn_tmpl(tx_arvif, &beacons->bcn[i].offs, |
f27fbd76 AD |
1580 | beacons->bcn[i].skb, &ema_args); |
1581 | if (ret) { | |
1582 | ath12k_warn(tx_arvif->ar->ab, | |
1583 | "failed to set ema beacon template id %i error %d\n", | |
1584 | i, ret); | |
1585 | break; | |
1586 | } | |
1587 | } | |
1588 | ||
1589 | if (tx_arvif != arvif && !nontx_profile_found) | |
1590 | ath12k_warn(arvif->ar->ab, | |
1591 | "nontransmitted bssid index %u not found in beacon template\n", | |
f4f5ee5e | 1592 | bssid_index); |
f27fbd76 AD |
1593 | |
1594 | ieee80211_beacon_free_ema_list(beacons); | |
1595 | return ret; | |
1596 | } | |
1597 | ||
3dd2c68f | 1598 | static int ath12k_mac_setup_bcn_tmpl(struct ath12k_link_vif *arvif) |
d8899132 | 1599 | { |
3dd2c68f S |
1600 | struct ath12k_vif *ahvif = arvif->ahvif; |
1601 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
39526578 | 1602 | struct ieee80211_bss_conf *link_conf; |
20fe6390 | 1603 | struct ath12k_link_vif *tx_arvif; |
d8899132 KV |
1604 | struct ath12k *ar = arvif->ar; |
1605 | struct ath12k_base *ab = ar->ab; | |
d8899132 | 1606 | struct ieee80211_mutable_offsets offs = {}; |
8c6faa56 | 1607 | bool nontx_profile_found = false; |
d8899132 | 1608 | struct sk_buff *bcn; |
d8899132 KV |
1609 | int ret; |
1610 | ||
3dd2c68f | 1611 | if (ahvif->vdev_type != WMI_VDEV_TYPE_AP) |
d8899132 KV |
1612 | return 0; |
1613 | ||
39526578 S |
1614 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
1615 | if (!link_conf) { | |
1616 | ath12k_warn(ar->ab, "unable to access bss link conf to set bcn tmpl for vif %pM link %u\n", | |
1617 | vif->addr, arvif->link_id); | |
1618 | return -ENOLINK; | |
1619 | } | |
1620 | ||
172e1570 | 1621 | tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); |
20fe6390 | 1622 | if (tx_arvif) { |
8c6faa56 AD |
1623 | if (tx_arvif != arvif && arvif->is_up) |
1624 | return 0; | |
f27fbd76 | 1625 | |
39526578 | 1626 | if (link_conf->ema_ap) |
f4f5ee5e AD |
1627 | return ath12k_mac_setup_bcn_tmpl_ema(arvif, tx_arvif, |
1628 | link_conf->bssid_index); | |
20fe6390 AD |
1629 | } else { |
1630 | tx_arvif = arvif; | |
8c6faa56 AD |
1631 | } |
1632 | ||
20fe6390 AD |
1633 | bcn = ieee80211_beacon_get_template(ath12k_ar_to_hw(tx_arvif->ar), |
1634 | tx_arvif->ahvif->vif, | |
1ea0cdee | 1635 | &offs, tx_arvif->link_id); |
d8899132 KV |
1636 | if (!bcn) { |
1637 | ath12k_warn(ab, "failed to get beacon template from mac80211\n"); | |
1638 | return -EPERM; | |
1639 | } | |
1640 | ||
8c6faa56 AD |
1641 | if (tx_arvif == arvif) { |
1642 | ath12k_mac_set_arvif_ies(arvif, bcn, 0, NULL); | |
1643 | } else { | |
1644 | ath12k_mac_set_arvif_ies(arvif, bcn, | |
39526578 | 1645 | link_conf->bssid_index, |
8c6faa56 AD |
1646 | &nontx_profile_found); |
1647 | if (!nontx_profile_found) | |
1648 | ath12k_warn(ab, | |
1649 | "nontransmitted profile not found in beacon template\n"); | |
1650 | } | |
d8899132 | 1651 | |
3dd2c68f | 1652 | if (ahvif->vif->type == NL80211_IFTYPE_AP && ahvif->vif->p2p) { |
575ec73c KY |
1653 | ret = ath12k_mac_setup_bcn_p2p_ie(arvif, bcn); |
1654 | if (ret) { | |
1655 | ath12k_warn(ab, "failed to setup P2P GO bcn ie: %d\n", | |
1656 | ret); | |
1657 | goto free_bcn_skb; | |
1658 | } | |
d8899132 | 1659 | |
575ec73c KY |
1660 | /* P2P IE is inserted by firmware automatically (as |
1661 | * configured above) so remove it from the base beacon | |
1662 | * template to avoid duplicate P2P IEs in beacon frames. | |
1663 | */ | |
1664 | ret = ath12k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, | |
1665 | WLAN_OUI_TYPE_WFA_P2P, | |
1666 | offsetof(struct ieee80211_mgmt, | |
1667 | u.beacon.variable)); | |
1668 | if (ret) { | |
1669 | ath12k_warn(ab, "failed to remove P2P vendor ie: %d\n", | |
1670 | ret); | |
1671 | goto free_bcn_skb; | |
1672 | } | |
1673 | } | |
1674 | ||
40944459 | 1675 | ret = ath12k_wmi_bcn_tmpl(arvif, &offs, bcn, NULL); |
d8899132 KV |
1676 | |
1677 | if (ret) | |
1678 | ath12k_warn(ab, "failed to submit beacon template command: %d\n", | |
1679 | ret); | |
1680 | ||
575ec73c KY |
1681 | free_bcn_skb: |
1682 | kfree_skb(bcn); | |
d8899132 KV |
1683 | return ret; |
1684 | } | |
1685 | ||
3dd2c68f | 1686 | static void ath12k_control_beaconing(struct ath12k_link_vif *arvif, |
d8899132 KV |
1687 | struct ieee80211_bss_conf *info) |
1688 | { | |
51c47463 | 1689 | struct ath12k_wmi_vdev_up_params params = {}; |
3dd2c68f | 1690 | struct ath12k_vif *ahvif = arvif->ahvif; |
172e1570 | 1691 | struct ieee80211_bss_conf *link_conf; |
20fe6390 | 1692 | struct ath12k_link_vif *tx_arvif; |
d8899132 KV |
1693 | struct ath12k *ar = arvif->ar; |
1694 | int ret; | |
1695 | ||
b8c67509 | 1696 | lockdep_assert_wiphy(ath12k_ar_to_hw(arvif->ar)->wiphy); |
d8899132 KV |
1697 | |
1698 | if (!info->enable_beacon) { | |
1699 | ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); | |
1700 | if (ret) | |
1701 | ath12k_warn(ar->ab, "failed to down vdev_id %i: %d\n", | |
1702 | arvif->vdev_id, ret); | |
1703 | ||
1704 | arvif->is_up = false; | |
1705 | return; | |
1706 | } | |
1707 | ||
1708 | /* Install the beacon template to the FW */ | |
1709 | ret = ath12k_mac_setup_bcn_tmpl(arvif); | |
1710 | if (ret) { | |
1711 | ath12k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n", | |
1712 | ret); | |
1713 | return; | |
1714 | } | |
1715 | ||
3dd2c68f | 1716 | ahvif->aid = 0; |
d8899132 | 1717 | |
1ea0cdee | 1718 | ether_addr_copy(arvif->bssid, info->addr); |
d8899132 | 1719 | |
51c47463 | 1720 | params.vdev_id = arvif->vdev_id; |
3dd2c68f | 1721 | params.aid = ahvif->aid; |
51c47463 | 1722 | params.bssid = arvif->bssid; |
3dd2c68f | 1723 | |
172e1570 AD |
1724 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
1725 | if (!link_conf) { | |
1726 | ath12k_warn(ar->ab, | |
1727 | "unable to access bss link conf for link %u required to retrieve transmitting link conf\n", | |
1728 | arvif->link_id); | |
1729 | return; | |
1730 | } | |
1731 | ||
1732 | tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); | |
20fe6390 | 1733 | if (tx_arvif) { |
3dd2c68f | 1734 | params.tx_bssid = tx_arvif->bssid; |
84edf47b AD |
1735 | params.nontx_profile_idx = info->bssid_index; |
1736 | params.nontx_profile_cnt = 1 << info->bssid_indicator; | |
1737 | } | |
51c47463 | 1738 | ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); |
d8899132 KV |
1739 | if (ret) { |
1740 | ath12k_warn(ar->ab, "failed to bring up vdev %d: %i\n", | |
1741 | arvif->vdev_id, ret); | |
1742 | return; | |
1743 | } | |
1744 | ||
1745 | arvif->is_up = true; | |
1746 | ||
1747 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); | |
1748 | } | |
1749 | ||
b0afabc4 KY |
1750 | static void ath12k_mac_handle_beacon_iter(void *data, u8 *mac, |
1751 | struct ieee80211_vif *vif) | |
1752 | { | |
1753 | struct sk_buff *skb = data; | |
1754 | struct ieee80211_mgmt *mgmt = (void *)skb->data; | |
3dd2c68f S |
1755 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
1756 | struct ath12k_link_vif *arvif = &ahvif->deflink; | |
b0afabc4 KY |
1757 | |
1758 | if (vif->type != NL80211_IFTYPE_STATION) | |
1759 | return; | |
1760 | ||
1761 | if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) | |
1762 | return; | |
1763 | ||
1764 | cancel_delayed_work(&arvif->connection_loss_work); | |
1765 | } | |
1766 | ||
1767 | void ath12k_mac_handle_beacon(struct ath12k *ar, struct sk_buff *skb) | |
1768 | { | |
1769 | ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), | |
1770 | IEEE80211_IFACE_ITER_NORMAL, | |
1771 | ath12k_mac_handle_beacon_iter, | |
1772 | skb); | |
1773 | } | |
1774 | ||
1775 | static void ath12k_mac_handle_beacon_miss_iter(void *data, u8 *mac, | |
1776 | struct ieee80211_vif *vif) | |
1777 | { | |
1778 | u32 *vdev_id = data; | |
3dd2c68f S |
1779 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
1780 | struct ath12k_link_vif *arvif = &ahvif->deflink; | |
b0afabc4 KY |
1781 | struct ath12k *ar = arvif->ar; |
1782 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); | |
1783 | ||
1784 | if (arvif->vdev_id != *vdev_id) | |
1785 | return; | |
1786 | ||
1787 | if (!arvif->is_up) | |
1788 | return; | |
1789 | ||
1790 | ieee80211_beacon_loss(vif); | |
1791 | ||
1792 | /* Firmware doesn't report beacon loss events repeatedly. If AP probe | |
1793 | * (done by mac80211) succeeds but beacons do not resume then it | |
1794 | * doesn't make sense to continue operation. Queue connection loss work | |
1795 | * which can be cancelled when beacon is received. | |
1796 | */ | |
1797 | ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, | |
1798 | ATH12K_CONNECTION_LOSS_HZ); | |
1799 | } | |
1800 | ||
1801 | void ath12k_mac_handle_beacon_miss(struct ath12k *ar, u32 vdev_id) | |
1802 | { | |
1803 | ieee80211_iterate_active_interfaces_atomic(ath12k_ar_to_hw(ar), | |
1804 | IEEE80211_IFACE_ITER_NORMAL, | |
1805 | ath12k_mac_handle_beacon_miss_iter, | |
1806 | &vdev_id); | |
1807 | } | |
1808 | ||
1809 | static void ath12k_mac_vif_sta_connection_loss_work(struct work_struct *work) | |
1810 | { | |
3dd2c68f S |
1811 | struct ath12k_link_vif *arvif = container_of(work, struct ath12k_link_vif, |
1812 | connection_loss_work.work); | |
1813 | struct ieee80211_vif *vif = arvif->ahvif->vif; | |
b0afabc4 KY |
1814 | |
1815 | if (!arvif->is_up) | |
1816 | return; | |
1817 | ||
1818 | ieee80211_connection_loss(vif); | |
1819 | } | |
1820 | ||
d8899132 | 1821 | static void ath12k_peer_assoc_h_basic(struct ath12k *ar, |
005fe43b | 1822 | struct ath12k_link_vif *arvif, |
b89b5dbe | 1823 | struct ath12k_link_sta *arsta, |
d8899132 KV |
1824 | struct ath12k_wmi_peer_assoc_arg *arg) |
1825 | { | |
005fe43b | 1826 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 1827 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
b856f023 | 1828 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
39526578 | 1829 | struct ieee80211_bss_conf *bss_conf; |
d8899132 KV |
1830 | u32 aid; |
1831 | ||
b8c67509 | 1832 | lockdep_assert_wiphy(hw->wiphy); |
d8899132 KV |
1833 | |
1834 | if (vif->type == NL80211_IFTYPE_STATION) | |
1835 | aid = vif->cfg.aid; | |
1836 | else | |
1837 | aid = sta->aid; | |
1838 | ||
061097e5 | 1839 | ether_addr_copy(arg->peer_mac, arsta->addr); |
d8899132 KV |
1840 | arg->vdev_id = arvif->vdev_id; |
1841 | arg->peer_associd = aid; | |
1842 | arg->auth_flag = true; | |
1843 | /* TODO: STA WAR in ath10k for listen interval required? */ | |
b856f023 | 1844 | arg->peer_listen_intval = hw->conf.listen_interval; |
d8899132 | 1845 | arg->peer_nss = 1; |
39526578 S |
1846 | |
1847 | bss_conf = ath12k_mac_get_link_bss_conf(arvif); | |
1848 | if (!bss_conf) { | |
1849 | ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc for vif %pM link %u\n", | |
1850 | vif->addr, arvif->link_id); | |
1851 | return; | |
1852 | } | |
1853 | ||
1854 | arg->peer_caps = bss_conf->assoc_capability; | |
d8899132 KV |
1855 | } |
1856 | ||
1857 | static void ath12k_peer_assoc_h_crypto(struct ath12k *ar, | |
005fe43b | 1858 | struct ath12k_link_vif *arvif, |
b89b5dbe | 1859 | struct ath12k_link_sta *arsta, |
d8899132 KV |
1860 | struct ath12k_wmi_peer_assoc_arg *arg) |
1861 | { | |
005fe43b | 1862 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 1863 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
39526578 | 1864 | struct ieee80211_bss_conf *info; |
d8899132 KV |
1865 | struct cfg80211_chan_def def; |
1866 | struct cfg80211_bss *bss; | |
b856f023 | 1867 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
d8899132 KV |
1868 | const u8 *rsnie = NULL; |
1869 | const u8 *wpaie = NULL; | |
1870 | ||
b8c67509 | 1871 | lockdep_assert_wiphy(hw->wiphy); |
d8899132 | 1872 | |
39526578 S |
1873 | info = ath12k_mac_get_link_bss_conf(arvif); |
1874 | if (!info) { | |
1875 | ath12k_warn(ar->ab, "unable to access bss link conf for peer assoc crypto for vif %pM link %u\n", | |
1876 | vif->addr, arvif->link_id); | |
1877 | return; | |
1878 | } | |
1879 | ||
abaadb93 | 1880 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
1881 | return; |
1882 | ||
b856f023 | 1883 | bss = cfg80211_get_bss(hw->wiphy, def.chan, info->bssid, NULL, 0, |
d8899132 KV |
1884 | IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); |
1885 | ||
1886 | if (arvif->rsnie_present || arvif->wpaie_present) { | |
1887 | arg->need_ptk_4_way = true; | |
1888 | if (arvif->wpaie_present) | |
1889 | arg->need_gtk_2_way = true; | |
1890 | } else if (bss) { | |
1891 | const struct cfg80211_bss_ies *ies; | |
1892 | ||
1893 | rcu_read_lock(); | |
1894 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); | |
1895 | ||
1896 | ies = rcu_dereference(bss->ies); | |
1897 | ||
1898 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
1899 | WLAN_OUI_TYPE_MICROSOFT_WPA, | |
1900 | ies->data, | |
1901 | ies->len); | |
1902 | rcu_read_unlock(); | |
b856f023 | 1903 | cfg80211_put_bss(hw->wiphy, bss); |
d8899132 KV |
1904 | } |
1905 | ||
1906 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ | |
1907 | if (rsnie || wpaie) { | |
1908 | ath12k_dbg(ar->ab, ATH12K_DBG_WMI, | |
1909 | "%s: rsn ie found\n", __func__); | |
1910 | arg->need_ptk_4_way = true; | |
1911 | } | |
1912 | ||
1913 | if (wpaie) { | |
1914 | ath12k_dbg(ar->ab, ATH12K_DBG_WMI, | |
1915 | "%s: wpa ie found\n", __func__); | |
1916 | arg->need_gtk_2_way = true; | |
1917 | } | |
1918 | ||
1919 | if (sta->mfp) { | |
1920 | /* TODO: Need to check if FW supports PMF? */ | |
1921 | arg->is_pmf_enabled = true; | |
1922 | } | |
1923 | ||
1924 | /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */ | |
1925 | } | |
1926 | ||
1927 | static void ath12k_peer_assoc_h_rates(struct ath12k *ar, | |
005fe43b | 1928 | struct ath12k_link_vif *arvif, |
b89b5dbe | 1929 | struct ath12k_link_sta *arsta, |
d8899132 KV |
1930 | struct ath12k_wmi_peer_assoc_arg *arg) |
1931 | { | |
005fe43b | 1932 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 1933 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
d8899132 | 1934 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
63fdb906 | 1935 | struct ieee80211_link_sta *link_sta; |
d8899132 KV |
1936 | struct cfg80211_chan_def def; |
1937 | const struct ieee80211_supported_band *sband; | |
1938 | const struct ieee80211_rate *rates; | |
b856f023 | 1939 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
d8899132 KV |
1940 | enum nl80211_band band; |
1941 | u32 ratemask; | |
1942 | u8 rate; | |
1943 | int i; | |
1944 | ||
b8c67509 | 1945 | lockdep_assert_wiphy(hw->wiphy); |
d8899132 | 1946 | |
abaadb93 | 1947 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
1948 | return; |
1949 | ||
63fdb906 S |
1950 | link_sta = ath12k_mac_get_link_sta(arsta); |
1951 | if (!link_sta) { | |
1952 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc rates for sta %pM link %u\n", | |
1953 | sta->addr, arsta->link_id); | |
1954 | return; | |
1955 | } | |
1956 | ||
d8899132 | 1957 | band = def.chan->band; |
b856f023 | 1958 | sband = hw->wiphy->bands[band]; |
63fdb906 | 1959 | ratemask = link_sta->supp_rates[band]; |
d8899132 KV |
1960 | ratemask &= arvif->bitrate_mask.control[band].legacy; |
1961 | rates = sband->bitrates; | |
1962 | ||
1963 | rateset->num_rates = 0; | |
1964 | ||
1965 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { | |
1966 | if (!(ratemask & 1)) | |
1967 | continue; | |
1968 | ||
1969 | rate = ath12k_mac_bitrate_to_rate(rates->bitrate); | |
1970 | rateset->rates[rateset->num_rates] = rate; | |
1971 | rateset->num_rates++; | |
1972 | } | |
1973 | } | |
1974 | ||
1975 | static bool | |
695df2f4 | 1976 | ath12k_peer_assoc_h_ht_masked(const u8 *ht_mcs_mask) |
d8899132 KV |
1977 | { |
1978 | int nss; | |
1979 | ||
1980 | for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) | |
1981 | if (ht_mcs_mask[nss]) | |
1982 | return false; | |
1983 | ||
1984 | return true; | |
1985 | } | |
1986 | ||
1987 | static bool | |
695df2f4 | 1988 | ath12k_peer_assoc_h_vht_masked(const u16 *vht_mcs_mask) |
d8899132 KV |
1989 | { |
1990 | int nss; | |
1991 | ||
1992 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) | |
1993 | if (vht_mcs_mask[nss]) | |
1994 | return false; | |
1995 | ||
1996 | return true; | |
1997 | } | |
1998 | ||
1999 | static void ath12k_peer_assoc_h_ht(struct ath12k *ar, | |
005fe43b | 2000 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2001 | struct ath12k_link_sta *arsta, |
d8899132 KV |
2002 | struct ath12k_wmi_peer_assoc_arg *arg) |
2003 | { | |
005fe43b | 2004 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 2005 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
63fdb906 S |
2006 | const struct ieee80211_sta_ht_cap *ht_cap; |
2007 | struct ieee80211_link_sta *link_sta; | |
d8899132 KV |
2008 | struct cfg80211_chan_def def; |
2009 | enum nl80211_band band; | |
2010 | const u8 *ht_mcs_mask; | |
2011 | int i, n; | |
2012 | u8 max_nss; | |
2013 | u32 stbc; | |
2014 | ||
b8c67509 | 2015 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 2016 | |
abaadb93 | 2017 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
2018 | return; |
2019 | ||
63fdb906 S |
2020 | link_sta = ath12k_mac_get_link_sta(arsta); |
2021 | if (!link_sta) { | |
2022 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc ht for sta %pM link %u\n", | |
2023 | sta->addr, arsta->link_id); | |
2024 | return; | |
2025 | } | |
2026 | ||
2027 | ht_cap = &link_sta->ht_cap; | |
d8899132 KV |
2028 | if (!ht_cap->ht_supported) |
2029 | return; | |
2030 | ||
2031 | band = def.chan->band; | |
2032 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
2033 | ||
2034 | if (ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) | |
2035 | return; | |
2036 | ||
2037 | arg->ht_flag = true; | |
2038 | ||
2039 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
2040 | ht_cap->ampdu_factor)) - 1; | |
2041 | ||
2042 | arg->peer_mpdu_density = | |
2043 | ath12k_parse_mpdudensity(ht_cap->ampdu_density); | |
2044 | ||
2045 | arg->peer_ht_caps = ht_cap->cap; | |
2046 | arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG; | |
2047 | ||
2048 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) | |
2049 | arg->ldpc_flag = true; | |
2050 | ||
63fdb906 | 2051 | if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
d8899132 KV |
2052 | arg->bw_40 = true; |
2053 | arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG; | |
2054 | } | |
2055 | ||
2056 | if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { | |
2057 | if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | | |
2058 | IEEE80211_HT_CAP_SGI_40)) | |
2059 | arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG; | |
2060 | } | |
2061 | ||
2062 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { | |
2063 | arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG; | |
2064 | arg->stbc_flag = true; | |
2065 | } | |
2066 | ||
2067 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { | |
2068 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; | |
2069 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
2070 | stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S; | |
2071 | arg->peer_rate_caps |= stbc; | |
2072 | arg->stbc_flag = true; | |
2073 | } | |
2074 | ||
2075 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) | |
2076 | arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG; | |
2077 | else if (ht_cap->mcs.rx_mask[1]) | |
2078 | arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG; | |
2079 | ||
2080 | for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) | |
2081 | if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && | |
2082 | (ht_mcs_mask[i / 8] & BIT(i % 8))) { | |
2083 | max_nss = (i / 8) + 1; | |
2084 | arg->peer_ht_rates.rates[n++] = i; | |
2085 | } | |
2086 | ||
2087 | /* This is a workaround for HT-enabled STAs which break the spec | |
2088 | * and have no HT capabilities RX mask (no HT RX MCS map). | |
2089 | * | |
2090 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), | |
2091 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. | |
2092 | * | |
2093 | * Firmware asserts if such situation occurs. | |
2094 | */ | |
2095 | if (n == 0) { | |
2096 | arg->peer_ht_rates.num_rates = 8; | |
2097 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) | |
2098 | arg->peer_ht_rates.rates[i] = i; | |
2099 | } else { | |
2100 | arg->peer_ht_rates.num_rates = n; | |
63fdb906 | 2101 | arg->peer_nss = min(link_sta->rx_nss, max_nss); |
d8899132 KV |
2102 | } |
2103 | ||
2104 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", | |
2105 | arg->peer_mac, | |
2106 | arg->peer_ht_rates.num_rates, | |
2107 | arg->peer_nss); | |
2108 | } | |
2109 | ||
2110 | static int ath12k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) | |
2111 | { | |
2112 | switch ((mcs_map >> (2 * nss)) & 0x3) { | |
2113 | case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; | |
2114 | case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; | |
2115 | case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; | |
2116 | } | |
2117 | return 0; | |
2118 | } | |
2119 | ||
2120 | static u16 | |
2121 | ath12k_peer_assoc_h_vht_limit(u16 tx_mcs_set, | |
2122 | const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) | |
2123 | { | |
2124 | int idx_limit; | |
2125 | int nss; | |
2126 | u16 mcs_map; | |
2127 | u16 mcs; | |
2128 | ||
2129 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
2130 | mcs_map = ath12k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & | |
2131 | vht_mcs_limit[nss]; | |
2132 | ||
2133 | if (mcs_map) | |
2134 | idx_limit = fls(mcs_map) - 1; | |
2135 | else | |
2136 | idx_limit = -1; | |
2137 | ||
2138 | switch (idx_limit) { | |
2139 | case 0: | |
2140 | case 1: | |
2141 | case 2: | |
2142 | case 3: | |
2143 | case 4: | |
2144 | case 5: | |
2145 | case 6: | |
2146 | case 7: | |
2147 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; | |
2148 | break; | |
2149 | case 8: | |
2150 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; | |
2151 | break; | |
2152 | case 9: | |
2153 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; | |
2154 | break; | |
2155 | default: | |
2156 | WARN_ON(1); | |
2157 | fallthrough; | |
2158 | case -1: | |
2159 | mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; | |
2160 | break; | |
2161 | } | |
2162 | ||
2163 | tx_mcs_set &= ~(0x3 << (nss * 2)); | |
2164 | tx_mcs_set |= mcs << (nss * 2); | |
2165 | } | |
2166 | ||
2167 | return tx_mcs_set; | |
2168 | } | |
2169 | ||
2170 | static void ath12k_peer_assoc_h_vht(struct ath12k *ar, | |
005fe43b | 2171 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2172 | struct ath12k_link_sta *arsta, |
d8899132 KV |
2173 | struct ath12k_wmi_peer_assoc_arg *arg) |
2174 | { | |
005fe43b | 2175 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 2176 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
63fdb906 S |
2177 | const struct ieee80211_sta_vht_cap *vht_cap; |
2178 | struct ieee80211_link_sta *link_sta; | |
d8899132 KV |
2179 | struct cfg80211_chan_def def; |
2180 | enum nl80211_band band; | |
2181 | const u16 *vht_mcs_mask; | |
2182 | u16 tx_mcs_map; | |
2183 | u8 ampdu_factor; | |
2184 | u8 max_nss, vht_mcs; | |
2185 | int i; | |
2186 | ||
3dd2c68f S |
2187 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
2188 | ||
abaadb93 | 2189 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
2190 | return; |
2191 | ||
63fdb906 S |
2192 | link_sta = ath12k_mac_get_link_sta(arsta); |
2193 | if (!link_sta) { | |
2194 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc vht for sta %pM link %u\n", | |
2195 | sta->addr, arsta->link_id); | |
2196 | return; | |
2197 | } | |
2198 | ||
2199 | vht_cap = &link_sta->vht_cap; | |
d8899132 KV |
2200 | if (!vht_cap->vht_supported) |
2201 | return; | |
2202 | ||
2203 | band = def.chan->band; | |
2204 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2205 | ||
2206 | if (ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) | |
2207 | return; | |
2208 | ||
2209 | arg->vht_flag = true; | |
2210 | ||
2211 | /* TODO: similar flags required? */ | |
2212 | arg->vht_capable = true; | |
2213 | ||
2214 | if (def.chan->band == NL80211_BAND_2GHZ) | |
2215 | arg->vht_ng_flag = true; | |
2216 | ||
2217 | arg->peer_vht_caps = vht_cap->cap; | |
2218 | ||
2219 | ampdu_factor = (vht_cap->cap & | |
2220 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> | |
2221 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
2222 | ||
2223 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to | |
2224 | * zero in VHT IE. Using it would result in degraded throughput. | |
2225 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep | |
2226 | * it if VHT max_mpdu is smaller. | |
2227 | */ | |
2228 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, | |
2229 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
2230 | ampdu_factor)) - 1); | |
2231 | ||
63fdb906 | 2232 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
d8899132 KV |
2233 | arg->bw_80 = true; |
2234 | ||
63fdb906 | 2235 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) |
d8899132 KV |
2236 | arg->bw_160 = true; |
2237 | ||
2238 | /* Calculate peer NSS capability from VHT capabilities if STA | |
2239 | * supports VHT. | |
2240 | */ | |
2241 | for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
2242 | vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> | |
2243 | (2 * i) & 3; | |
2244 | ||
2245 | if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED && | |
2246 | vht_mcs_mask[i]) | |
2247 | max_nss = i + 1; | |
2248 | } | |
63fdb906 | 2249 | arg->peer_nss = min(link_sta->rx_nss, max_nss); |
d8899132 KV |
2250 | arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
2251 | arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); | |
2252 | arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest); | |
2253 | ||
2254 | tx_mcs_map = __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); | |
2255 | arg->tx_mcs_set = ath12k_peer_assoc_h_vht_limit(tx_mcs_map, vht_mcs_mask); | |
2256 | ||
2257 | /* In QCN9274 platform, VHT MCS rate 10 and 11 is enabled by default. | |
2258 | * VHT MCS rate 10 and 11 is not supported in 11ac standard. | |
2259 | * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode. | |
2260 | */ | |
2261 | arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK; | |
2262 | arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11; | |
2263 | ||
2264 | if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) == | |
2265 | IEEE80211_VHT_MCS_NOT_SUPPORTED) | |
2266 | arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; | |
2267 | ||
2268 | /* TODO: Check */ | |
2269 | arg->tx_max_mcs_nss = 0xFF; | |
2270 | ||
2271 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", | |
061097e5 | 2272 | arsta->addr, arg->peer_max_mpdu, arg->peer_flags); |
d8899132 KV |
2273 | |
2274 | /* TODO: rxnss_override */ | |
2275 | } | |
2276 | ||
2277 | static void ath12k_peer_assoc_h_he(struct ath12k *ar, | |
005fe43b | 2278 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2279 | struct ath12k_link_sta *arsta, |
d8899132 KV |
2280 | struct ath12k_wmi_peer_assoc_arg *arg) |
2281 | { | |
005fe43b | 2282 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 2283 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
63fdb906 | 2284 | const struct ieee80211_sta_he_cap *he_cap; |
39526578 | 2285 | struct ieee80211_bss_conf *link_conf; |
63fdb906 | 2286 | struct ieee80211_link_sta *link_sta; |
d8899132 | 2287 | int i; |
19b77e7c AS |
2288 | u8 ampdu_factor, max_nss; |
2289 | u8 rx_mcs_80 = IEEE80211_HE_MCS_NOT_SUPPORTED; | |
2290 | u8 rx_mcs_160 = IEEE80211_HE_MCS_NOT_SUPPORTED; | |
d8899132 KV |
2291 | u16 mcs_160_map, mcs_80_map; |
2292 | bool support_160; | |
2293 | u16 v; | |
2294 | ||
39526578 S |
2295 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
2296 | if (!link_conf) { | |
2297 | ath12k_warn(ar->ab, "unable to access bss link conf in peer assoc he for vif %pM link %u", | |
2298 | vif->addr, arvif->link_id); | |
2299 | return; | |
2300 | } | |
2301 | ||
63fdb906 S |
2302 | link_sta = ath12k_mac_get_link_sta(arsta); |
2303 | if (!link_sta) { | |
2304 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", | |
2305 | sta->addr, arsta->link_id); | |
2306 | return; | |
2307 | } | |
2308 | ||
2309 | he_cap = &link_sta->he_cap; | |
d8899132 KV |
2310 | if (!he_cap->has_he) |
2311 | return; | |
2312 | ||
2313 | arg->he_flag = true; | |
2314 | ||
2315 | support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] & | |
2316 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G); | |
2317 | ||
2318 | /* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */ | |
2319 | mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); | |
2320 | mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); | |
2321 | ||
2322 | if (support_160) { | |
2323 | for (i = 7; i >= 0; i--) { | |
2324 | u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3; | |
2325 | ||
2326 | if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) { | |
2327 | rx_mcs_160 = i + 1; | |
2328 | break; | |
2329 | } | |
2330 | } | |
2331 | } | |
2332 | ||
2333 | for (i = 7; i >= 0; i--) { | |
2334 | u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3; | |
2335 | ||
2336 | if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) { | |
2337 | rx_mcs_80 = i + 1; | |
2338 | break; | |
2339 | } | |
2340 | } | |
2341 | ||
2342 | if (support_160) | |
2343 | max_nss = min(rx_mcs_80, rx_mcs_160); | |
2344 | else | |
2345 | max_nss = rx_mcs_80; | |
2346 | ||
63fdb906 | 2347 | arg->peer_nss = min(link_sta->rx_nss, max_nss); |
d8899132 KV |
2348 | |
2349 | memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info, | |
603cf6c2 | 2350 | sizeof(he_cap->he_cap_elem.mac_cap_info)); |
d8899132 | 2351 | memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info, |
603cf6c2 | 2352 | sizeof(he_cap->he_cap_elem.phy_cap_info)); |
39526578 | 2353 | arg->peer_he_ops = link_conf->he_oper.params; |
d8899132 KV |
2354 | |
2355 | /* the top most byte is used to indicate BSS color info */ | |
2356 | arg->peer_he_ops &= 0xffffff; | |
2357 | ||
2358 | /* As per section 26.6.1 IEEE Std 802.11ax‐2022, if the Max AMPDU | |
2359 | * Exponent Extension in HE cap is zero, use the arg->peer_max_mpdu | |
2360 | * as calculated while parsing VHT caps(if VHT caps is present) | |
2361 | * or HT caps (if VHT caps is not present). | |
2362 | * | |
2363 | * For non-zero value of Max AMPDU Exponent Extension in HE MAC caps, | |
2364 | * if a HE STA sends VHT cap and HE cap IE in assoc request then, use | |
2365 | * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length. | |
2366 | * If a HE STA that does not send VHT cap, but HE and HT cap in assoc | |
2367 | * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu | |
2368 | * length. | |
2369 | */ | |
a66de2d0 BQ |
2370 | ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3], |
2371 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK); | |
d8899132 KV |
2372 | |
2373 | if (ampdu_factor) { | |
63fdb906 | 2374 | if (link_sta->vht_cap.vht_supported) |
d8899132 KV |
2375 | arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR + |
2376 | ampdu_factor)) - 1; | |
63fdb906 | 2377 | else if (link_sta->ht_cap.ht_supported) |
d8899132 KV |
2378 | arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR + |
2379 | ampdu_factor)) - 1; | |
2380 | } | |
2381 | ||
2382 | if (he_cap->he_cap_elem.phy_cap_info[6] & | |
2383 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { | |
2384 | int bit = 7; | |
2385 | int nss, ru; | |
2386 | ||
2387 | arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] & | |
2388 | IEEE80211_PPE_THRES_NSS_MASK; | |
2389 | arg->peer_ppet.ru_bit_mask = | |
2390 | (he_cap->ppe_thres[0] & | |
2391 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> | |
2392 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; | |
2393 | ||
2394 | for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) { | |
2395 | for (ru = 0; ru < 4; ru++) { | |
2396 | u32 val = 0; | |
2397 | int i; | |
2398 | ||
2399 | if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0) | |
2400 | continue; | |
2401 | for (i = 0; i < 6; i++) { | |
2402 | val >>= 1; | |
2403 | val |= ((he_cap->ppe_thres[bit / 8] >> | |
2404 | (bit % 8)) & 0x1) << 5; | |
2405 | bit++; | |
2406 | } | |
2407 | arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |= | |
2408 | val << (ru * 6); | |
2409 | } | |
2410 | } | |
2411 | } | |
2412 | ||
2413 | if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES) | |
2414 | arg->twt_responder = true; | |
2415 | if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ) | |
2416 | arg->twt_requester = true; | |
2417 | ||
63fdb906 | 2418 | switch (link_sta->bandwidth) { |
d8899132 KV |
2419 | case IEEE80211_STA_RX_BW_160: |
2420 | if (he_cap->he_cap_elem.phy_cap_info[0] & | |
2421 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) { | |
2422 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80); | |
2423 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; | |
2424 | ||
2425 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80); | |
2426 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; | |
2427 | ||
2428 | arg->peer_he_mcs_count++; | |
2429 | } | |
2430 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); | |
2431 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; | |
2432 | ||
2433 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160); | |
2434 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; | |
2435 | ||
2436 | arg->peer_he_mcs_count++; | |
2437 | fallthrough; | |
2438 | ||
2439 | default: | |
2440 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); | |
2441 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; | |
2442 | ||
2443 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); | |
2444 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; | |
2445 | ||
2446 | arg->peer_he_mcs_count++; | |
2447 | break; | |
2448 | } | |
2449 | } | |
2450 | ||
112dbc6a | 2451 | static void ath12k_peer_assoc_h_he_6ghz(struct ath12k *ar, |
005fe43b | 2452 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2453 | struct ath12k_link_sta *arsta, |
112dbc6a PKC |
2454 | struct ath12k_wmi_peer_assoc_arg *arg) |
2455 | { | |
005fe43b | 2456 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 2457 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
63fdb906 S |
2458 | const struct ieee80211_sta_he_cap *he_cap; |
2459 | struct ieee80211_link_sta *link_sta; | |
112dbc6a PKC |
2460 | struct cfg80211_chan_def def; |
2461 | enum nl80211_band band; | |
2462 | u8 ampdu_factor, mpdu_density; | |
2463 | ||
abaadb93 | 2464 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
112dbc6a PKC |
2465 | return; |
2466 | ||
2467 | band = def.chan->band; | |
2468 | ||
63fdb906 S |
2469 | link_sta = ath12k_mac_get_link_sta(arsta); |
2470 | if (!link_sta) { | |
2471 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc he 6ghz for sta %pM link %u\n", | |
2472 | sta->addr, arsta->link_id); | |
2473 | return; | |
2474 | } | |
2475 | ||
2476 | he_cap = &link_sta->he_cap; | |
2477 | ||
2478 | if (!arg->he_flag || band != NL80211_BAND_6GHZ || !link_sta->he_6ghz_capa.capa) | |
112dbc6a PKC |
2479 | return; |
2480 | ||
63fdb906 | 2481 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
112dbc6a PKC |
2482 | arg->bw_40 = true; |
2483 | ||
63fdb906 | 2484 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
112dbc6a PKC |
2485 | arg->bw_80 = true; |
2486 | ||
63fdb906 | 2487 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) |
112dbc6a PKC |
2488 | arg->bw_160 = true; |
2489 | ||
63fdb906 | 2490 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320) |
112dbc6a PKC |
2491 | arg->bw_320 = true; |
2492 | ||
63fdb906 | 2493 | arg->peer_he_caps_6ghz = le16_to_cpu(link_sta->he_6ghz_capa.capa); |
112dbc6a PKC |
2494 | |
2495 | mpdu_density = u32_get_bits(arg->peer_he_caps_6ghz, | |
2496 | IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START); | |
2497 | arg->peer_mpdu_density = ath12k_parse_mpdudensity(mpdu_density); | |
2498 | ||
2499 | /* From IEEE Std 802.11ax-2021 - Section 10.12.2: An HE STA shall be capable of | |
2500 | * receiving A-MPDU where the A-MPDU pre-EOF padding length is up to the value | |
2501 | * indicated by the Maximum A-MPDU Length Exponent Extension field in the HE | |
2502 | * Capabilities element and the Maximum A-MPDU Length Exponent field in HE 6 GHz | |
2503 | * Band Capabilities element in the 6 GHz band. | |
2504 | * | |
2505 | * Here, we are extracting the Max A-MPDU Exponent Extension from HE caps and | |
2506 | * factor is the Maximum A-MPDU Length Exponent from HE 6 GHZ Band capability. | |
2507 | */ | |
2508 | ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3], | |
2509 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) + | |
2510 | u32_get_bits(arg->peer_he_caps_6ghz, | |
2511 | IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); | |
2512 | ||
2513 | arg->peer_max_mpdu = (1u << (IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR + | |
2514 | ampdu_factor)) - 1; | |
2515 | } | |
2516 | ||
f0e61dc7 | 2517 | static int ath12k_get_smps_from_capa(const struct ieee80211_sta_ht_cap *ht_cap, |
97b7cbb7 | 2518 | const struct ieee80211_he_6ghz_capa *he_6ghz_capa, |
f0e61dc7 PKC |
2519 | int *smps) |
2520 | { | |
97b7cbb7 PKC |
2521 | if (ht_cap->ht_supported) |
2522 | *smps = u16_get_bits(ht_cap->cap, IEEE80211_HT_CAP_SM_PS); | |
2523 | else | |
2524 | *smps = le16_get_bits(he_6ghz_capa->capa, | |
2525 | IEEE80211_HE_6GHZ_CAP_SM_PS); | |
f0e61dc7 PKC |
2526 | |
2527 | if (*smps >= ARRAY_SIZE(ath12k_smps_map)) | |
2528 | return -EINVAL; | |
2529 | ||
2530 | return 0; | |
2531 | } | |
2532 | ||
b89b5dbe | 2533 | static void ath12k_peer_assoc_h_smps(struct ath12k_link_sta *arsta, |
d8899132 KV |
2534 | struct ath12k_wmi_peer_assoc_arg *arg) |
2535 | { | |
b89b5dbe | 2536 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
63fdb906 S |
2537 | const struct ieee80211_he_6ghz_capa *he_6ghz_capa; |
2538 | struct ath12k_link_vif *arvif = arsta->arvif; | |
2539 | const struct ieee80211_sta_ht_cap *ht_cap; | |
2540 | struct ieee80211_link_sta *link_sta; | |
2541 | struct ath12k *ar = arvif->ar; | |
d8899132 KV |
2542 | int smps; |
2543 | ||
63fdb906 S |
2544 | link_sta = ath12k_mac_get_link_sta(arsta); |
2545 | if (!link_sta) { | |
2546 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", | |
2547 | sta->addr, arsta->link_id); | |
2548 | return; | |
2549 | } | |
2550 | ||
2551 | he_6ghz_capa = &link_sta->he_6ghz_capa; | |
2552 | ht_cap = &link_sta->ht_cap; | |
2553 | ||
3005c63a PKC |
2554 | if (!ht_cap->ht_supported && !he_6ghz_capa->capa) |
2555 | return; | |
2556 | ||
97b7cbb7 | 2557 | if (ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps)) |
d8899132 KV |
2558 | return; |
2559 | ||
d8899132 KV |
2560 | switch (smps) { |
2561 | case WLAN_HT_CAP_SM_PS_STATIC: | |
2562 | arg->static_mimops_flag = true; | |
2563 | break; | |
2564 | case WLAN_HT_CAP_SM_PS_DYNAMIC: | |
2565 | arg->dynamic_mimops_flag = true; | |
2566 | break; | |
2567 | case WLAN_HT_CAP_SM_PS_DISABLED: | |
2568 | arg->spatial_mux_flag = true; | |
2569 | break; | |
2570 | default: | |
2571 | break; | |
2572 | } | |
2573 | } | |
2574 | ||
2575 | static void ath12k_peer_assoc_h_qos(struct ath12k *ar, | |
005fe43b | 2576 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2577 | struct ath12k_link_sta *arsta, |
d8899132 KV |
2578 | struct ath12k_wmi_peer_assoc_arg *arg) |
2579 | { | |
b89b5dbe | 2580 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
d8899132 | 2581 | |
005fe43b | 2582 | switch (arvif->ahvif->vdev_type) { |
d8899132 KV |
2583 | case WMI_VDEV_TYPE_AP: |
2584 | if (sta->wme) { | |
2585 | /* TODO: Check WME vs QoS */ | |
2586 | arg->is_wme_set = true; | |
2587 | arg->qos_flag = true; | |
2588 | } | |
2589 | ||
2590 | if (sta->wme && sta->uapsd_queues) { | |
2591 | /* TODO: Check WME vs QoS */ | |
2592 | arg->is_wme_set = true; | |
2593 | arg->apsd_flag = true; | |
2594 | arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG; | |
2595 | } | |
2596 | break; | |
2597 | case WMI_VDEV_TYPE_STA: | |
2598 | if (sta->wme) { | |
2599 | arg->is_wme_set = true; | |
2600 | arg->qos_flag = true; | |
2601 | } | |
2602 | break; | |
2603 | default: | |
2604 | break; | |
2605 | } | |
2606 | ||
2607 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM qos %d\n", | |
061097e5 | 2608 | arsta->addr, arg->qos_flag); |
d8899132 KV |
2609 | } |
2610 | ||
2611 | static int ath12k_peer_assoc_qos_ap(struct ath12k *ar, | |
3dd2c68f | 2612 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2613 | struct ath12k_link_sta *arsta) |
d8899132 | 2614 | { |
b89b5dbe | 2615 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
d8899132 KV |
2616 | struct ath12k_wmi_ap_ps_arg arg; |
2617 | u32 max_sp; | |
2618 | u32 uapsd; | |
2619 | int ret; | |
2620 | ||
b8c67509 | 2621 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
2622 | |
2623 | arg.vdev_id = arvif->vdev_id; | |
2624 | ||
2625 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", | |
2626 | sta->uapsd_queues, sta->max_sp); | |
2627 | ||
2628 | uapsd = 0; | |
2629 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) | |
2630 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | | |
2631 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; | |
2632 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) | |
2633 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | | |
2634 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; | |
2635 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) | |
2636 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | | |
2637 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; | |
2638 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) | |
2639 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | | |
2640 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; | |
2641 | ||
2642 | max_sp = 0; | |
2643 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) | |
2644 | max_sp = sta->max_sp; | |
2645 | ||
2646 | arg.param = WMI_AP_PS_PEER_PARAM_UAPSD; | |
2647 | arg.value = uapsd; | |
061097e5 | 2648 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
d8899132 KV |
2649 | if (ret) |
2650 | goto err; | |
2651 | ||
2652 | arg.param = WMI_AP_PS_PEER_PARAM_MAX_SP; | |
2653 | arg.value = max_sp; | |
061097e5 | 2654 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
d8899132 KV |
2655 | if (ret) |
2656 | goto err; | |
2657 | ||
2658 | /* TODO: revisit during testing */ | |
2659 | arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE; | |
2660 | arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; | |
061097e5 | 2661 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
d8899132 KV |
2662 | if (ret) |
2663 | goto err; | |
2664 | ||
2665 | arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD; | |
2666 | arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; | |
061097e5 | 2667 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, arsta->addr, &arg); |
d8899132 KV |
2668 | if (ret) |
2669 | goto err; | |
2670 | ||
2671 | return 0; | |
2672 | ||
2673 | err: | |
2674 | ath12k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n", | |
2675 | arg.param, arvif->vdev_id, ret); | |
2676 | return ret; | |
2677 | } | |
2678 | ||
63fdb906 | 2679 | static bool ath12k_mac_sta_has_ofdm_only(struct ieee80211_link_sta *sta) |
d8899132 | 2680 | { |
63fdb906 | 2681 | return sta->supp_rates[NL80211_BAND_2GHZ] >> |
d8899132 KV |
2682 | ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
2683 | } | |
2684 | ||
2685 | static enum wmi_phy_mode ath12k_mac_get_phymode_vht(struct ath12k *ar, | |
63fdb906 | 2686 | struct ieee80211_link_sta *link_sta) |
d8899132 | 2687 | { |
63fdb906 S |
2688 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
2689 | switch (link_sta->vht_cap.cap & | |
d8899132 KV |
2690 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { |
2691 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: | |
2692 | return MODE_11AC_VHT160; | |
2693 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: | |
2694 | return MODE_11AC_VHT80_80; | |
2695 | default: | |
2696 | /* not sure if this is a valid case? */ | |
2697 | return MODE_11AC_VHT160; | |
2698 | } | |
2699 | } | |
2700 | ||
63fdb906 | 2701 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
d8899132 KV |
2702 | return MODE_11AC_VHT80; |
2703 | ||
63fdb906 | 2704 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
d8899132 KV |
2705 | return MODE_11AC_VHT40; |
2706 | ||
63fdb906 | 2707 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
d8899132 KV |
2708 | return MODE_11AC_VHT20; |
2709 | ||
2710 | return MODE_UNKNOWN; | |
2711 | } | |
2712 | ||
2713 | static enum wmi_phy_mode ath12k_mac_get_phymode_he(struct ath12k *ar, | |
63fdb906 | 2714 | struct ieee80211_link_sta *link_sta) |
d8899132 | 2715 | { |
63fdb906 S |
2716 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
2717 | if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & | |
d8899132 KV |
2718 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
2719 | return MODE_11AX_HE160; | |
63fdb906 | 2720 | else if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & |
d8899132 KV |
2721 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) |
2722 | return MODE_11AX_HE80_80; | |
2723 | /* not sure if this is a valid case? */ | |
2724 | return MODE_11AX_HE160; | |
2725 | } | |
2726 | ||
63fdb906 | 2727 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
d8899132 KV |
2728 | return MODE_11AX_HE80; |
2729 | ||
63fdb906 | 2730 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
d8899132 KV |
2731 | return MODE_11AX_HE40; |
2732 | ||
63fdb906 | 2733 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
d8899132 KV |
2734 | return MODE_11AX_HE20; |
2735 | ||
2736 | return MODE_UNKNOWN; | |
2737 | } | |
2738 | ||
38013653 | 2739 | static enum wmi_phy_mode ath12k_mac_get_phymode_eht(struct ath12k *ar, |
63fdb906 | 2740 | struct ieee80211_link_sta *link_sta) |
38013653 | 2741 | { |
63fdb906 S |
2742 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_320) |
2743 | if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[0] & | |
38013653 MS |
2744 | IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) |
2745 | return MODE_11BE_EHT320; | |
2746 | ||
63fdb906 S |
2747 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
2748 | if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & | |
38013653 MS |
2749 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) |
2750 | return MODE_11BE_EHT160; | |
2751 | ||
63fdb906 | 2752 | if (link_sta->he_cap.he_cap_elem.phy_cap_info[0] & |
38013653 MS |
2753 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) |
2754 | return MODE_11BE_EHT80_80; | |
2755 | ||
2756 | ath12k_warn(ar->ab, "invalid EHT PHY capability info for 160 Mhz: %d\n", | |
63fdb906 | 2757 | link_sta->he_cap.he_cap_elem.phy_cap_info[0]); |
38013653 MS |
2758 | |
2759 | return MODE_11BE_EHT160; | |
2760 | } | |
2761 | ||
63fdb906 | 2762 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) |
38013653 MS |
2763 | return MODE_11BE_EHT80; |
2764 | ||
63fdb906 | 2765 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
38013653 MS |
2766 | return MODE_11BE_EHT40; |
2767 | ||
63fdb906 | 2768 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
38013653 MS |
2769 | return MODE_11BE_EHT20; |
2770 | ||
2771 | return MODE_UNKNOWN; | |
2772 | } | |
2773 | ||
d8899132 | 2774 | static void ath12k_peer_assoc_h_phymode(struct ath12k *ar, |
005fe43b | 2775 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2776 | struct ath12k_link_sta *arsta, |
d8899132 KV |
2777 | struct ath12k_wmi_peer_assoc_arg *arg) |
2778 | { | |
63fdb906 | 2779 | struct ieee80211_link_sta *link_sta; |
d8899132 KV |
2780 | struct cfg80211_chan_def def; |
2781 | enum nl80211_band band; | |
2782 | const u8 *ht_mcs_mask; | |
2783 | const u16 *vht_mcs_mask; | |
2784 | enum wmi_phy_mode phymode = MODE_UNKNOWN; | |
2785 | ||
3dd2c68f | 2786 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 2787 | |
005fe43b | 2788 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 2789 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
005fe43b | 2790 | |
abaadb93 | 2791 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
2792 | return; |
2793 | ||
2794 | band = def.chan->band; | |
2795 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
2796 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2797 | ||
63fdb906 S |
2798 | link_sta = ath12k_mac_get_link_sta(arsta); |
2799 | if (!link_sta) { | |
2800 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", | |
2801 | sta->addr, arsta->link_id); | |
2802 | return; | |
2803 | } | |
2804 | ||
d8899132 KV |
2805 | switch (band) { |
2806 | case NL80211_BAND_2GHZ: | |
63fdb906 S |
2807 | if (link_sta->eht_cap.has_eht) { |
2808 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
38013653 MS |
2809 | phymode = MODE_11BE_EHT40_2G; |
2810 | else | |
2811 | phymode = MODE_11BE_EHT20_2G; | |
63fdb906 S |
2812 | } else if (link_sta->he_cap.has_he) { |
2813 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_80) | |
d8899132 | 2814 | phymode = MODE_11AX_HE80_2G; |
63fdb906 | 2815 | else if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
d8899132 KV |
2816 | phymode = MODE_11AX_HE40_2G; |
2817 | else | |
2818 | phymode = MODE_11AX_HE20_2G; | |
63fdb906 | 2819 | } else if (link_sta->vht_cap.vht_supported && |
d8899132 | 2820 | !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
63fdb906 | 2821 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
d8899132 KV |
2822 | phymode = MODE_11AC_VHT40; |
2823 | else | |
2824 | phymode = MODE_11AC_VHT20; | |
63fdb906 | 2825 | } else if (link_sta->ht_cap.ht_supported && |
d8899132 | 2826 | !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
63fdb906 | 2827 | if (link_sta->bandwidth == IEEE80211_STA_RX_BW_40) |
d8899132 KV |
2828 | phymode = MODE_11NG_HT40; |
2829 | else | |
2830 | phymode = MODE_11NG_HT20; | |
63fdb906 | 2831 | } else if (ath12k_mac_sta_has_ofdm_only(link_sta)) { |
d8899132 KV |
2832 | phymode = MODE_11G; |
2833 | } else { | |
2834 | phymode = MODE_11B; | |
2835 | } | |
2836 | break; | |
2837 | case NL80211_BAND_5GHZ: | |
2838 | case NL80211_BAND_6GHZ: | |
38013653 | 2839 | /* Check EHT first */ |
63fdb906 S |
2840 | if (link_sta->eht_cap.has_eht) { |
2841 | phymode = ath12k_mac_get_phymode_eht(ar, link_sta); | |
2842 | } else if (link_sta->he_cap.has_he) { | |
2843 | phymode = ath12k_mac_get_phymode_he(ar, link_sta); | |
2844 | } else if (link_sta->vht_cap.vht_supported && | |
d8899132 | 2845 | !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
63fdb906 S |
2846 | phymode = ath12k_mac_get_phymode_vht(ar, link_sta); |
2847 | } else if (link_sta->ht_cap.ht_supported && | |
d8899132 | 2848 | !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
63fdb906 | 2849 | if (link_sta->bandwidth >= IEEE80211_STA_RX_BW_40) |
d8899132 KV |
2850 | phymode = MODE_11NA_HT40; |
2851 | else | |
2852 | phymode = MODE_11NA_HT20; | |
2853 | } else { | |
2854 | phymode = MODE_11A; | |
2855 | } | |
2856 | break; | |
2857 | default: | |
2858 | break; | |
2859 | } | |
2860 | ||
2861 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM phymode %s\n", | |
061097e5 | 2862 | arsta->addr, ath12k_mac_phymode_str(phymode)); |
d8899132 KV |
2863 | |
2864 | arg->peer_phymode = phymode; | |
2865 | WARN_ON(phymode == MODE_UNKNOWN); | |
2866 | } | |
2867 | ||
17bbb8aa AD |
2868 | static void ath12k_mac_set_eht_mcs(u8 rx_tx_mcs7, u8 rx_tx_mcs9, |
2869 | u8 rx_tx_mcs11, u8 rx_tx_mcs13, | |
2870 | u32 *rx_mcs, u32 *tx_mcs) | |
2871 | { | |
2872 | *rx_mcs = 0; | |
2873 | u32p_replace_bits(rx_mcs, | |
2874 | u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_RX), | |
2875 | WMI_EHT_MCS_NSS_0_7); | |
2876 | u32p_replace_bits(rx_mcs, | |
2877 | u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_RX), | |
2878 | WMI_EHT_MCS_NSS_8_9); | |
2879 | u32p_replace_bits(rx_mcs, | |
2880 | u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_RX), | |
2881 | WMI_EHT_MCS_NSS_10_11); | |
2882 | u32p_replace_bits(rx_mcs, | |
2883 | u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_RX), | |
2884 | WMI_EHT_MCS_NSS_12_13); | |
2885 | ||
2886 | *tx_mcs = 0; | |
2887 | u32p_replace_bits(tx_mcs, | |
2888 | u8_get_bits(rx_tx_mcs7, IEEE80211_EHT_MCS_NSS_TX), | |
2889 | WMI_EHT_MCS_NSS_0_7); | |
2890 | u32p_replace_bits(tx_mcs, | |
2891 | u8_get_bits(rx_tx_mcs9, IEEE80211_EHT_MCS_NSS_TX), | |
2892 | WMI_EHT_MCS_NSS_8_9); | |
2893 | u32p_replace_bits(tx_mcs, | |
2894 | u8_get_bits(rx_tx_mcs11, IEEE80211_EHT_MCS_NSS_TX), | |
2895 | WMI_EHT_MCS_NSS_10_11); | |
2896 | u32p_replace_bits(tx_mcs, | |
2897 | u8_get_bits(rx_tx_mcs13, IEEE80211_EHT_MCS_NSS_TX), | |
2898 | WMI_EHT_MCS_NSS_12_13); | |
2899 | } | |
2900 | ||
2901 | static void ath12k_mac_set_eht_ppe_threshold(const u8 *ppe_thres, | |
2902 | struct ath12k_wmi_ppe_threshold_arg *ppet) | |
2903 | { | |
2904 | u32 bit_pos = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE, val; | |
2905 | u8 nss, ru, i; | |
2906 | u8 ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2; | |
2907 | ||
2908 | ppet->numss_m1 = u8_get_bits(ppe_thres[0], IEEE80211_EHT_PPE_THRES_NSS_MASK); | |
2909 | ppet->ru_bit_mask = u16_get_bits(get_unaligned_le16(ppe_thres), | |
2910 | IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); | |
2911 | ||
2912 | for (nss = 0; nss <= ppet->numss_m1; nss++) { | |
2913 | for (ru = 0; | |
2914 | ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); | |
2915 | ru++) { | |
2916 | if ((ppet->ru_bit_mask & BIT(ru)) == 0) | |
2917 | continue; | |
2918 | ||
2919 | val = 0; | |
2920 | for (i = 0; i < ppet_bit_len_per_ru; i++) { | |
2921 | val |= (((ppe_thres[bit_pos / 8] >> | |
2922 | (bit_pos % 8)) & 0x1) << i); | |
2923 | bit_pos++; | |
2924 | } | |
2925 | ppet->ppet16_ppet8_ru3_ru0[nss] |= | |
2926 | (val << (ru * ppet_bit_len_per_ru)); | |
2927 | } | |
2928 | } | |
2929 | } | |
2930 | ||
2931 | static void ath12k_peer_assoc_h_eht(struct ath12k *ar, | |
005fe43b | 2932 | struct ath12k_link_vif *arvif, |
b89b5dbe | 2933 | struct ath12k_link_sta *arsta, |
17bbb8aa AD |
2934 | struct ath12k_wmi_peer_assoc_arg *arg) |
2935 | { | |
b89b5dbe | 2936 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
17bbb8aa AD |
2937 | const struct ieee80211_eht_mcs_nss_supp_20mhz_only *bw_20; |
2938 | const struct ieee80211_eht_mcs_nss_supp_bw *bw; | |
63fdb906 S |
2939 | const struct ieee80211_sta_eht_cap *eht_cap; |
2940 | const struct ieee80211_sta_he_cap *he_cap; | |
2941 | struct ieee80211_link_sta *link_sta; | |
e66396cd | 2942 | struct ieee80211_bss_conf *link_conf; |
17bbb8aa AD |
2943 | u32 *rx_mcs, *tx_mcs; |
2944 | ||
3dd2c68f S |
2945 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
2946 | ||
63fdb906 S |
2947 | link_sta = ath12k_mac_get_link_sta(arsta); |
2948 | if (!link_sta) { | |
2949 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc eht for sta %pM link %u\n", | |
2950 | sta->addr, arsta->link_id); | |
2951 | return; | |
2952 | } | |
2953 | ||
e66396cd MK |
2954 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
2955 | if (!link_conf) { | |
2956 | ath12k_warn(ar->ab, "unable to access link_conf in peer assoc eht set\n"); | |
2957 | return; | |
2958 | } | |
2959 | ||
63fdb906 S |
2960 | eht_cap = &link_sta->eht_cap; |
2961 | he_cap = &link_sta->he_cap; | |
2962 | if (!he_cap->has_he || !eht_cap->has_eht) | |
17bbb8aa AD |
2963 | return; |
2964 | ||
2965 | arg->eht_flag = true; | |
2966 | ||
2967 | if ((eht_cap->eht_cap_elem.phy_cap_info[5] & | |
2968 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) && | |
2969 | eht_cap->eht_ppe_thres[0] != 0) | |
2970 | ath12k_mac_set_eht_ppe_threshold(eht_cap->eht_ppe_thres, | |
2971 | &arg->peer_eht_ppet); | |
2972 | ||
2973 | memcpy(arg->peer_eht_cap_mac, eht_cap->eht_cap_elem.mac_cap_info, | |
2974 | sizeof(eht_cap->eht_cap_elem.mac_cap_info)); | |
2975 | memcpy(arg->peer_eht_cap_phy, eht_cap->eht_cap_elem.phy_cap_info, | |
2976 | sizeof(eht_cap->eht_cap_elem.phy_cap_info)); | |
2977 | ||
2978 | rx_mcs = arg->peer_eht_rx_mcs_set; | |
2979 | tx_mcs = arg->peer_eht_tx_mcs_set; | |
2980 | ||
63fdb906 | 2981 | switch (link_sta->bandwidth) { |
17bbb8aa AD |
2982 | case IEEE80211_STA_RX_BW_320: |
2983 | bw = &eht_cap->eht_mcs_nss_supp.bw._320; | |
2984 | ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, | |
2985 | bw->rx_tx_mcs9_max_nss, | |
2986 | bw->rx_tx_mcs11_max_nss, | |
2987 | bw->rx_tx_mcs13_max_nss, | |
2988 | &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320], | |
2989 | &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_320]); | |
2990 | arg->peer_eht_mcs_count++; | |
2991 | fallthrough; | |
2992 | case IEEE80211_STA_RX_BW_160: | |
2993 | bw = &eht_cap->eht_mcs_nss_supp.bw._160; | |
2994 | ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, | |
2995 | bw->rx_tx_mcs9_max_nss, | |
2996 | bw->rx_tx_mcs11_max_nss, | |
2997 | bw->rx_tx_mcs13_max_nss, | |
2998 | &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160], | |
2999 | &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_160]); | |
3000 | arg->peer_eht_mcs_count++; | |
3001 | fallthrough; | |
3002 | default: | |
3003 | if ((he_cap->he_cap_elem.phy_cap_info[0] & | |
3004 | (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | | |
3005 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
3006 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
3007 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)) == 0) { | |
3008 | bw_20 = &eht_cap->eht_mcs_nss_supp.only_20mhz; | |
3009 | ||
3010 | ath12k_mac_set_eht_mcs(bw_20->rx_tx_mcs7_max_nss, | |
3011 | bw_20->rx_tx_mcs9_max_nss, | |
3012 | bw_20->rx_tx_mcs11_max_nss, | |
3013 | bw_20->rx_tx_mcs13_max_nss, | |
3014 | &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], | |
3015 | &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80]); | |
3016 | } else { | |
3017 | bw = &eht_cap->eht_mcs_nss_supp.bw._80; | |
3018 | ath12k_mac_set_eht_mcs(bw->rx_tx_mcs9_max_nss, | |
3019 | bw->rx_tx_mcs9_max_nss, | |
3020 | bw->rx_tx_mcs11_max_nss, | |
3021 | bw->rx_tx_mcs13_max_nss, | |
3022 | &rx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80], | |
3023 | &tx_mcs[WMI_EHTCAP_TXRX_MCS_NSS_IDX_80]); | |
3024 | } | |
3025 | ||
3026 | arg->peer_eht_mcs_count++; | |
3027 | break; | |
3028 | } | |
07c01b86 AD |
3029 | |
3030 | arg->punct_bitmap = ~arvif->punct_bitmap; | |
e66396cd | 3031 | arg->eht_disable_mcs15 = link_conf->eht_disable_mcs15; |
17bbb8aa AD |
3032 | } |
3033 | ||
507f8e73 S |
3034 | static void ath12k_peer_assoc_h_mlo(struct ath12k_link_sta *arsta, |
3035 | struct ath12k_wmi_peer_assoc_arg *arg) | |
3036 | { | |
3037 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); | |
3038 | struct peer_assoc_mlo_params *ml = &arg->ml; | |
3039 | struct ath12k_sta *ahsta = arsta->ahsta; | |
3040 | struct ath12k_link_sta *arsta_p; | |
3041 | struct ath12k_link_vif *arvif; | |
3042 | unsigned long links; | |
3043 | u8 link_id; | |
3044 | int i; | |
3045 | ||
3046 | if (!sta->mlo || ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) | |
3047 | return; | |
3048 | ||
3049 | ml->enabled = true; | |
3050 | ml->assoc_link = arsta->is_assoc_link; | |
3051 | ||
3052 | /* For now considering the primary umac based on assoc link */ | |
3053 | ml->primary_umac = arsta->is_assoc_link; | |
3054 | ml->peer_id_valid = true; | |
3055 | ml->logical_link_idx_valid = true; | |
3056 | ||
3057 | ether_addr_copy(ml->mld_addr, sta->addr); | |
3058 | ml->logical_link_idx = arsta->link_idx; | |
3059 | ml->ml_peer_id = ahsta->ml_peer_id; | |
3060 | ml->ieee_link_id = arsta->link_id; | |
3061 | ml->num_partner_links = 0; | |
4bcf9525 | 3062 | ml->eml_cap = sta->eml_cap; |
507f8e73 S |
3063 | links = ahsta->links_map; |
3064 | ||
3065 | rcu_read_lock(); | |
3066 | ||
3067 | i = 0; | |
3068 | ||
3069 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
3070 | if (i >= ATH12K_WMI_MLO_MAX_LINKS) | |
3071 | break; | |
3072 | ||
3073 | arsta_p = rcu_dereference(ahsta->link[link_id]); | |
3074 | arvif = rcu_dereference(ahsta->ahvif->link[link_id]); | |
3075 | ||
3076 | if (arsta_p == arsta) | |
3077 | continue; | |
3078 | ||
3079 | if (!arvif->is_started) | |
3080 | continue; | |
3081 | ||
3082 | ml->partner_info[i].vdev_id = arvif->vdev_id; | |
3083 | ml->partner_info[i].hw_link_id = arvif->ar->pdev->hw_link_id; | |
3084 | ml->partner_info[i].assoc_link = arsta_p->is_assoc_link; | |
3085 | ml->partner_info[i].primary_umac = arsta_p->is_assoc_link; | |
3086 | ml->partner_info[i].logical_link_idx_valid = true; | |
3087 | ml->partner_info[i].logical_link_idx = arsta_p->link_idx; | |
3088 | ml->num_partner_links++; | |
3089 | ||
3090 | i++; | |
3091 | } | |
3092 | ||
3093 | rcu_read_unlock(); | |
3094 | } | |
3095 | ||
d8899132 | 3096 | static void ath12k_peer_assoc_prepare(struct ath12k *ar, |
005fe43b | 3097 | struct ath12k_link_vif *arvif, |
b89b5dbe | 3098 | struct ath12k_link_sta *arsta, |
d8899132 KV |
3099 | struct ath12k_wmi_peer_assoc_arg *arg, |
3100 | bool reassoc) | |
3101 | { | |
b8c67509 | 3102 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
3103 | |
3104 | memset(arg, 0, sizeof(*arg)); | |
3105 | ||
3106 | reinit_completion(&ar->peer_assoc_done); | |
3107 | ||
3108 | arg->peer_new_assoc = !reassoc; | |
b89b5dbe S |
3109 | ath12k_peer_assoc_h_basic(ar, arvif, arsta, arg); |
3110 | ath12k_peer_assoc_h_crypto(ar, arvif, arsta, arg); | |
3111 | ath12k_peer_assoc_h_rates(ar, arvif, arsta, arg); | |
3112 | ath12k_peer_assoc_h_ht(ar, arvif, arsta, arg); | |
3113 | ath12k_peer_assoc_h_vht(ar, arvif, arsta, arg); | |
3114 | ath12k_peer_assoc_h_he(ar, arvif, arsta, arg); | |
3115 | ath12k_peer_assoc_h_he_6ghz(ar, arvif, arsta, arg); | |
3116 | ath12k_peer_assoc_h_eht(ar, arvif, arsta, arg); | |
3117 | ath12k_peer_assoc_h_qos(ar, arvif, arsta, arg); | |
3118 | ath12k_peer_assoc_h_phymode(ar, arvif, arsta, arg); | |
3119 | ath12k_peer_assoc_h_smps(arsta, arg); | |
507f8e73 | 3120 | ath12k_peer_assoc_h_mlo(arsta, arg); |
d8899132 | 3121 | |
8a9c06b4 | 3122 | arsta->peer_nss = arg->peer_nss; |
d8899132 KV |
3123 | /* TODO: amsdu_disable req? */ |
3124 | } | |
3125 | ||
3dd2c68f | 3126 | static int ath12k_setup_peer_smps(struct ath12k *ar, struct ath12k_link_vif *arvif, |
d8899132 | 3127 | const u8 *addr, |
97b7cbb7 PKC |
3128 | const struct ieee80211_sta_ht_cap *ht_cap, |
3129 | const struct ieee80211_he_6ghz_capa *he_6ghz_capa) | |
d8899132 | 3130 | { |
f0e61dc7 | 3131 | int smps, ret = 0; |
d8899132 | 3132 | |
3005c63a PKC |
3133 | if (!ht_cap->ht_supported && !he_6ghz_capa) |
3134 | return 0; | |
3135 | ||
97b7cbb7 | 3136 | ret = ath12k_get_smps_from_capa(ht_cap, he_6ghz_capa, &smps); |
f0e61dc7 PKC |
3137 | if (ret < 0) |
3138 | return ret; | |
d8899132 KV |
3139 | |
3140 | return ath12k_wmi_set_peer_param(ar, addr, arvif->vdev_id, | |
3141 | WMI_PEER_MIMO_PS_STATE, | |
3142 | ath12k_smps_map[smps]); | |
3143 | } | |
3144 | ||
090c645b | 3145 | static u32 ath12k_mac_ieee80211_sta_bw_to_wmi(struct ath12k *ar, |
2fc98b24 | 3146 | struct ieee80211_link_sta *link_sta) |
090c645b | 3147 | { |
2fc98b24 | 3148 | u32 bw; |
090c645b | 3149 | |
2fc98b24 | 3150 | switch (link_sta->bandwidth) { |
090c645b AKS |
3151 | case IEEE80211_STA_RX_BW_20: |
3152 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
3153 | break; | |
3154 | case IEEE80211_STA_RX_BW_40: | |
3155 | bw = WMI_PEER_CHWIDTH_40MHZ; | |
3156 | break; | |
3157 | case IEEE80211_STA_RX_BW_80: | |
3158 | bw = WMI_PEER_CHWIDTH_80MHZ; | |
3159 | break; | |
3160 | case IEEE80211_STA_RX_BW_160: | |
3161 | bw = WMI_PEER_CHWIDTH_160MHZ; | |
3162 | break; | |
3163 | case IEEE80211_STA_RX_BW_320: | |
3164 | bw = WMI_PEER_CHWIDTH_320MHZ; | |
3165 | break; | |
3166 | default: | |
2fc98b24 AKS |
3167 | ath12k_warn(ar->ab, "Invalid bandwidth %d for link station %pM\n", |
3168 | link_sta->bandwidth, link_sta->addr); | |
090c645b AKS |
3169 | bw = WMI_PEER_CHWIDTH_20MHZ; |
3170 | break; | |
3171 | } | |
3172 | ||
3173 | return bw; | |
3174 | } | |
3175 | ||
ce20a10f | 3176 | static void ath12k_bss_assoc(struct ath12k *ar, |
3dd2c68f | 3177 | struct ath12k_link_vif *arvif, |
d8899132 KV |
3178 | struct ieee80211_bss_conf *bss_conf) |
3179 | { | |
3dd2c68f S |
3180 | struct ath12k_vif *ahvif = arvif->ahvif; |
3181 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
51c47463 | 3182 | struct ath12k_wmi_vdev_up_params params = {}; |
1833a2ce AKS |
3183 | struct ieee80211_link_sta *link_sta; |
3184 | u8 link_id = bss_conf->link_id; | |
b89b5dbe | 3185 | struct ath12k_link_sta *arsta; |
d8899132 | 3186 | struct ieee80211_sta *ap_sta; |
b89b5dbe | 3187 | struct ath12k_sta *ahsta; |
d8899132 KV |
3188 | struct ath12k_peer *peer; |
3189 | bool is_auth = false; | |
3190 | int ret; | |
3191 | ||
b8c67509 | 3192 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 3193 | |
445718c9 JJ |
3194 | struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = |
3195 | kzalloc(sizeof(*peer_arg), GFP_KERNEL); | |
3196 | if (!peer_arg) | |
3197 | return; | |
3198 | ||
1833a2ce AKS |
3199 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
3200 | "mac vdev %i link id %u assoc bssid %pM aid %d\n", | |
3201 | arvif->vdev_id, link_id, arvif->bssid, ahvif->aid); | |
d8899132 KV |
3202 | |
3203 | rcu_read_lock(); | |
3204 | ||
1833a2ce AKS |
3205 | /* During ML connection, cfg.ap_addr has the MLD address. For |
3206 | * non-ML connection, it has the BSSID. | |
3207 | */ | |
3208 | ap_sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); | |
d8899132 KV |
3209 | if (!ap_sta) { |
3210 | ath12k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n", | |
1833a2ce | 3211 | vif->cfg.ap_addr, arvif->vdev_id); |
d8899132 KV |
3212 | rcu_read_unlock(); |
3213 | return; | |
3214 | } | |
3215 | ||
b89b5dbe | 3216 | ahsta = ath12k_sta_to_ahsta(ap_sta); |
b89b5dbe | 3217 | |
1833a2ce AKS |
3218 | arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, |
3219 | ahsta->link[link_id]); | |
b89b5dbe S |
3220 | if (WARN_ON(!arsta)) { |
3221 | rcu_read_unlock(); | |
3222 | return; | |
3223 | } | |
3224 | ||
1833a2ce AKS |
3225 | link_sta = ath12k_mac_get_link_sta(arsta); |
3226 | if (WARN_ON(!link_sta)) { | |
3227 | rcu_read_unlock(); | |
3228 | return; | |
3229 | } | |
3230 | ||
445718c9 | 3231 | ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, false); |
d8899132 KV |
3232 | |
3233 | rcu_read_unlock(); | |
3234 | ||
445718c9 | 3235 | ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); |
d8899132 KV |
3236 | if (ret) { |
3237 | ath12k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n", | |
3238 | bss_conf->bssid, arvif->vdev_id, ret); | |
3239 | return; | |
3240 | } | |
3241 | ||
3242 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
3243 | ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
3244 | bss_conf->bssid, arvif->vdev_id); | |
3245 | return; | |
3246 | } | |
3247 | ||
3248 | ret = ath12k_setup_peer_smps(ar, arvif, bss_conf->bssid, | |
1833a2ce | 3249 | &link_sta->ht_cap, &link_sta->he_6ghz_capa); |
d8899132 KV |
3250 | if (ret) { |
3251 | ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
3252 | arvif->vdev_id, ret); | |
3253 | return; | |
3254 | } | |
3255 | ||
3256 | WARN_ON(arvif->is_up); | |
3257 | ||
3dd2c68f | 3258 | ahvif->aid = vif->cfg.aid; |
d8899132 KV |
3259 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
3260 | ||
51c47463 | 3261 | params.vdev_id = arvif->vdev_id; |
3dd2c68f | 3262 | params.aid = ahvif->aid; |
51c47463 AD |
3263 | params.bssid = arvif->bssid; |
3264 | ret = ath12k_wmi_vdev_up(ar, ¶ms); | |
d8899132 KV |
3265 | if (ret) { |
3266 | ath12k_warn(ar->ab, "failed to set vdev %d up: %d\n", | |
3267 | arvif->vdev_id, ret); | |
3268 | return; | |
3269 | } | |
3270 | ||
3271 | arvif->is_up = true; | |
aab4ae56 | 3272 | arvif->rekey_data.enable_offload = false; |
d8899132 KV |
3273 | |
3274 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3275 | "mac vdev %d up (associated) bssid %pM aid %d\n", | |
3276 | arvif->vdev_id, bss_conf->bssid, vif->cfg.aid); | |
3277 | ||
3278 | spin_lock_bh(&ar->ab->base_lock); | |
3279 | ||
3280 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arvif->bssid); | |
3281 | if (peer && peer->is_authorized) | |
3282 | is_auth = true; | |
3283 | ||
3284 | spin_unlock_bh(&ar->ab->base_lock); | |
3285 | ||
3286 | /* Authorize BSS Peer */ | |
3287 | if (is_auth) { | |
3288 | ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, | |
3289 | arvif->vdev_id, | |
3290 | WMI_PEER_AUTHORIZE, | |
3291 | 1); | |
3292 | if (ret) | |
3293 | ath12k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret); | |
3294 | } | |
3295 | ||
3296 | ret = ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
3297 | &bss_conf->he_obss_pd); | |
3298 | if (ret) | |
3299 | ath12k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n", | |
3300 | arvif->vdev_id, ret); | |
591de41d WG |
3301 | |
3302 | if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) && | |
3303 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
3304 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) | |
3305 | ath12k_mac_11d_scan_stop_all(ar->ab); | |
d8899132 KV |
3306 | } |
3307 | ||
ce20a10f | 3308 | static void ath12k_bss_disassoc(struct ath12k *ar, |
3dd2c68f | 3309 | struct ath12k_link_vif *arvif) |
d8899132 | 3310 | { |
d8899132 KV |
3311 | int ret; |
3312 | ||
b8c67509 | 3313 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
3314 | |
3315 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", | |
3316 | arvif->vdev_id, arvif->bssid); | |
3317 | ||
3318 | ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); | |
3319 | if (ret) | |
3320 | ath12k_warn(ar->ab, "failed to down vdev %i: %d\n", | |
3321 | arvif->vdev_id, ret); | |
3322 | ||
3323 | arvif->is_up = false; | |
3324 | ||
aab4ae56 BQ |
3325 | memset(&arvif->rekey_data, 0, sizeof(arvif->rekey_data)); |
3326 | ||
b0afabc4 | 3327 | cancel_delayed_work(&arvif->connection_loss_work); |
d8899132 KV |
3328 | } |
3329 | ||
3330 | static u32 ath12k_mac_get_rate_hw_value(int bitrate) | |
3331 | { | |
3332 | u32 preamble; | |
3333 | u16 hw_value; | |
3334 | int rate; | |
3335 | size_t i; | |
3336 | ||
3337 | if (ath12k_mac_bitrate_is_cck(bitrate)) | |
3338 | preamble = WMI_RATE_PREAMBLE_CCK; | |
3339 | else | |
3340 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
3341 | ||
3342 | for (i = 0; i < ARRAY_SIZE(ath12k_legacy_rates); i++) { | |
3343 | if (ath12k_legacy_rates[i].bitrate != bitrate) | |
3344 | continue; | |
3345 | ||
3346 | hw_value = ath12k_legacy_rates[i].hw_value; | |
3347 | rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); | |
3348 | ||
3349 | return rate; | |
3350 | } | |
3351 | ||
3352 | return -EINVAL; | |
3353 | } | |
3354 | ||
3355 | static void ath12k_recalculate_mgmt_rate(struct ath12k *ar, | |
005fe43b | 3356 | struct ath12k_link_vif *arvif, |
d8899132 KV |
3357 | struct cfg80211_chan_def *def) |
3358 | { | |
005fe43b | 3359 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b856f023 | 3360 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
d8899132 | 3361 | const struct ieee80211_supported_band *sband; |
39526578 | 3362 | struct ieee80211_bss_conf *bss_conf; |
d8899132 KV |
3363 | u8 basic_rate_idx; |
3364 | int hw_rate_code; | |
3365 | u32 vdev_param; | |
3366 | u16 bitrate; | |
3367 | int ret; | |
3368 | ||
b8c67509 | 3369 | lockdep_assert_wiphy(hw->wiphy); |
d8899132 | 3370 | |
39526578 S |
3371 | bss_conf = ath12k_mac_get_link_bss_conf(arvif); |
3372 | if (!bss_conf) { | |
3373 | ath12k_warn(ar->ab, "unable to access bss link conf in mgmt rate calc for vif %pM link %u\n", | |
3374 | vif->addr, arvif->link_id); | |
3375 | return; | |
3376 | } | |
3377 | ||
b856f023 | 3378 | sband = hw->wiphy->bands[def->chan->band]; |
cb179024 PKC |
3379 | if (bss_conf->basic_rates) |
3380 | basic_rate_idx = __ffs(bss_conf->basic_rates); | |
3381 | else | |
3382 | basic_rate_idx = 0; | |
d8899132 KV |
3383 | bitrate = sband->bitrates[basic_rate_idx].bitrate; |
3384 | ||
3385 | hw_rate_code = ath12k_mac_get_rate_hw_value(bitrate); | |
3386 | if (hw_rate_code < 0) { | |
3387 | ath12k_warn(ar->ab, "bitrate not supported %d\n", bitrate); | |
3388 | return; | |
3389 | } | |
3390 | ||
3391 | vdev_param = WMI_VDEV_PARAM_MGMT_RATE; | |
3392 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, | |
3393 | hw_rate_code); | |
3394 | if (ret) | |
3395 | ath12k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret); | |
3396 | ||
3397 | vdev_param = WMI_VDEV_PARAM_BEACON_RATE; | |
3398 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, | |
3399 | hw_rate_code); | |
3400 | if (ret) | |
3401 | ath12k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret); | |
3402 | } | |
3403 | ||
b81c39d6 AKS |
3404 | static void ath12k_mac_init_arvif(struct ath12k_vif *ahvif, |
3405 | struct ath12k_link_vif *arvif, int link_id) | |
3406 | { | |
3407 | struct ath12k_hw *ah = ahvif->ah; | |
3408 | u8 _link_id; | |
3409 | int i; | |
3410 | ||
3411 | lockdep_assert_wiphy(ah->hw->wiphy); | |
3412 | ||
3413 | if (WARN_ON(!arvif)) | |
3414 | return; | |
3415 | ||
3416 | if (WARN_ON(link_id >= ATH12K_NUM_MAX_LINKS)) | |
3417 | return; | |
3418 | ||
3419 | if (link_id < 0) | |
3420 | _link_id = 0; | |
3421 | else | |
3422 | _link_id = link_id; | |
3423 | ||
3424 | arvif->ahvif = ahvif; | |
3425 | arvif->link_id = _link_id; | |
3426 | ||
5e009751 BM |
3427 | /* Protects the datapath stats update on a per link basis */ |
3428 | spin_lock_init(&arvif->link_stats_lock); | |
3429 | ||
b81c39d6 AKS |
3430 | INIT_LIST_HEAD(&arvif->list); |
3431 | INIT_DELAYED_WORK(&arvif->connection_loss_work, | |
3432 | ath12k_mac_vif_sta_connection_loss_work); | |
3433 | ||
3434 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { | |
3435 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; | |
3436 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, | |
3437 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); | |
3438 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, | |
3439 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); | |
3440 | } | |
3441 | ||
3442 | /* Handle MLO related assignments */ | |
3443 | if (link_id >= 0) { | |
3444 | rcu_assign_pointer(ahvif->link[arvif->link_id], arvif); | |
3445 | ahvif->links_map |= BIT(_link_id); | |
3446 | } | |
3447 | ||
3448 | ath12k_generic_dbg(ATH12K_DBG_MAC, | |
3449 | "mac init link arvif (link_id %d%s) for vif %pM. links_map 0x%x", | |
3450 | _link_id, (link_id < 0) ? " deflink" : "", ahvif->vif->addr, | |
3451 | ahvif->links_map); | |
3452 | } | |
3453 | ||
3454 | static void ath12k_mac_remove_link_interface(struct ieee80211_hw *hw, | |
3455 | struct ath12k_link_vif *arvif) | |
3456 | { | |
3457 | struct ath12k_vif *ahvif = arvif->ahvif; | |
3458 | struct ath12k_hw *ah = hw->priv; | |
3459 | struct ath12k *ar = arvif->ar; | |
3460 | int ret; | |
3461 | ||
3462 | lockdep_assert_wiphy(ah->hw->wiphy); | |
3463 | ||
3464 | cancel_delayed_work_sync(&arvif->connection_loss_work); | |
3465 | ||
3466 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac remove link interface (vdev %d link id %d)", | |
3467 | arvif->vdev_id, arvif->link_id); | |
3468 | ||
591de41d WG |
3469 | if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map) && |
3470 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
3471 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) | |
3472 | ath12k_mac_11d_scan_stop(ar); | |
3473 | ||
b81c39d6 AKS |
3474 | if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
3475 | ret = ath12k_peer_delete(ar, arvif->vdev_id, arvif->bssid); | |
3476 | if (ret) | |
3477 | ath12k_warn(ar->ab, "failed to submit AP self-peer removal on vdev %d link id %d: %d", | |
3478 | arvif->vdev_id, arvif->link_id, ret); | |
3479 | } | |
3480 | ath12k_mac_vdev_delete(ar, arvif); | |
3481 | } | |
3482 | ||
3483 | static struct ath12k_link_vif *ath12k_mac_assign_link_vif(struct ath12k_hw *ah, | |
3484 | struct ieee80211_vif *vif, | |
3485 | u8 link_id) | |
3486 | { | |
3487 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
3488 | struct ath12k_link_vif *arvif; | |
3489 | ||
3490 | lockdep_assert_wiphy(ah->hw->wiphy); | |
3491 | ||
3492 | arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); | |
3493 | if (arvif) | |
3494 | return arvif; | |
3495 | ||
88c3aaf4 AKS |
3496 | /* If this is the first link arvif being created for an ML VIF |
3497 | * use the preallocated deflink memory except for scan arvifs | |
3498 | */ | |
3499 | if (!ahvif->links_map && link_id != ATH12K_DEFAULT_SCAN_LINK) { | |
b81c39d6 | 3500 | arvif = &ahvif->deflink; |
88c3aaf4 AKS |
3501 | |
3502 | if (vif->type == NL80211_IFTYPE_STATION) | |
3503 | arvif->is_sta_assoc_link = true; | |
b81c39d6 | 3504 | } else { |
88c3aaf4 AKS |
3505 | arvif = kzalloc(sizeof(*arvif), GFP_KERNEL); |
3506 | if (!arvif) | |
3507 | return NULL; | |
b81c39d6 AKS |
3508 | } |
3509 | ||
3510 | ath12k_mac_init_arvif(ahvif, arvif, link_id); | |
3511 | ||
3512 | return arvif; | |
3513 | } | |
3514 | ||
3515 | static void ath12k_mac_unassign_link_vif(struct ath12k_link_vif *arvif) | |
3516 | { | |
3517 | struct ath12k_vif *ahvif = arvif->ahvif; | |
3518 | struct ath12k_hw *ah = ahvif->ah; | |
3519 | ||
3520 | lockdep_assert_wiphy(ah->hw->wiphy); | |
3521 | ||
3522 | rcu_assign_pointer(ahvif->link[arvif->link_id], NULL); | |
3523 | synchronize_rcu(); | |
3524 | ahvif->links_map &= ~BIT(arvif->link_id); | |
3525 | ||
3526 | if (arvif != &ahvif->deflink) | |
3527 | kfree(arvif); | |
3528 | else | |
3529 | memset(arvif, 0, sizeof(*arvif)); | |
3530 | } | |
3531 | ||
477cabfd S |
3532 | static int |
3533 | ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw, | |
3534 | struct ieee80211_vif *vif, | |
3535 | u16 old_links, u16 new_links, | |
3536 | struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS]) | |
3537 | { | |
315d80be | 3538 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
81e4be30 | 3539 | unsigned long to_remove = old_links & ~new_links; |
315d80be AKS |
3540 | unsigned long to_add = ~old_links & new_links; |
3541 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); | |
3542 | struct ath12k_link_vif *arvif; | |
3543 | u8 link_id; | |
3544 | ||
3545 | lockdep_assert_wiphy(hw->wiphy); | |
3546 | ||
3547 | ath12k_generic_dbg(ATH12K_DBG_MAC, | |
3548 | "mac vif link changed for MLD %pM old_links 0x%x new_links 0x%x\n", | |
3549 | vif->addr, old_links, new_links); | |
3550 | ||
3551 | for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) { | |
3552 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
3553 | /* mac80211 wants to add link but driver already has the | |
3554 | * link. This should not happen ideally. | |
3555 | */ | |
3556 | if (WARN_ON(arvif)) | |
3557 | return -EINVAL; | |
3558 | ||
3559 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); | |
3560 | if (WARN_ON(!arvif)) | |
3561 | return -EINVAL; | |
3562 | } | |
3563 | ||
81e4be30 AKS |
3564 | for_each_set_bit(link_id, &to_remove, IEEE80211_MLD_MAX_NUM_LINKS) { |
3565 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
3566 | if (WARN_ON(!arvif)) | |
3567 | return -EINVAL; | |
3568 | ||
3569 | if (!arvif->is_created) | |
3570 | continue; | |
3571 | ||
3572 | if (WARN_ON(!arvif->ar)) | |
3573 | return -EINVAL; | |
3574 | ||
3575 | ath12k_mac_remove_link_interface(hw, arvif); | |
3576 | ath12k_mac_unassign_link_vif(arvif); | |
3577 | } | |
3578 | ||
477cabfd S |
3579 | return 0; |
3580 | } | |
3581 | ||
3dd2c68f | 3582 | static int ath12k_mac_fils_discovery(struct ath12k_link_vif *arvif, |
d8899132 KV |
3583 | struct ieee80211_bss_conf *info) |
3584 | { | |
3dd2c68f | 3585 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
d8899132 | 3586 | struct ath12k *ar = arvif->ar; |
b856f023 | 3587 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
d8899132 KV |
3588 | struct sk_buff *tmpl; |
3589 | int ret; | |
3590 | u32 interval; | |
3591 | bool unsol_bcast_probe_resp_enabled = false; | |
3592 | ||
3593 | if (info->fils_discovery.max_interval) { | |
3594 | interval = info->fils_discovery.max_interval; | |
3595 | ||
3dd2c68f | 3596 | tmpl = ieee80211_get_fils_discovery_tmpl(hw, vif); |
d8899132 KV |
3597 | if (tmpl) |
3598 | ret = ath12k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id, | |
3599 | tmpl); | |
3600 | } else if (info->unsol_bcast_probe_resp_interval) { | |
3601 | unsol_bcast_probe_resp_enabled = 1; | |
3602 | interval = info->unsol_bcast_probe_resp_interval; | |
3603 | ||
3dd2c68f | 3604 | tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(hw, vif); |
d8899132 KV |
3605 | if (tmpl) |
3606 | ret = ath12k_wmi_probe_resp_tmpl(ar, arvif->vdev_id, | |
3607 | tmpl); | |
3608 | } else { /* Disable */ | |
3609 | return ath12k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false); | |
3610 | } | |
3611 | ||
3612 | if (!tmpl) { | |
3613 | ath12k_warn(ar->ab, | |
3614 | "mac vdev %i failed to retrieve %s template\n", | |
3615 | arvif->vdev_id, (unsol_bcast_probe_resp_enabled ? | |
3616 | "unsolicited broadcast probe response" : | |
3617 | "FILS discovery")); | |
3618 | return -EPERM; | |
3619 | } | |
3620 | kfree_skb(tmpl); | |
3621 | ||
3622 | if (!ret) | |
3623 | ret = ath12k_wmi_fils_discovery(ar, arvif->vdev_id, interval, | |
3624 | unsol_bcast_probe_resp_enabled); | |
3625 | ||
3626 | return ret; | |
3627 | } | |
3628 | ||
afbab6e4 S |
3629 | static void ath12k_mac_op_vif_cfg_changed(struct ieee80211_hw *hw, |
3630 | struct ieee80211_vif *vif, | |
3631 | u64 changed) | |
3632 | { | |
3633 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
3634 | unsigned long links = ahvif->links_map; | |
39526578 | 3635 | struct ieee80211_bss_conf *info; |
afbab6e4 | 3636 | struct ath12k_link_vif *arvif; |
ead6d411 BQ |
3637 | struct ieee80211_sta *sta; |
3638 | struct ath12k_sta *ahsta; | |
afbab6e4 S |
3639 | struct ath12k *ar; |
3640 | u8 link_id; | |
3641 | ||
3642 | lockdep_assert_wiphy(hw->wiphy); | |
3643 | ||
3644 | if (changed & BSS_CHANGED_SSID && vif->type == NL80211_IFTYPE_AP) { | |
3645 | ahvif->u.ap.ssid_len = vif->cfg.ssid_len; | |
3646 | if (vif->cfg.ssid_len) | |
3647 | memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); | |
3648 | } | |
3649 | ||
3650 | if (changed & BSS_CHANGED_ASSOC) { | |
ead6d411 BQ |
3651 | if (vif->cfg.assoc) { |
3652 | /* only in station mode we can get here, so it's safe | |
3653 | * to use ap_addr | |
3654 | */ | |
3655 | rcu_read_lock(); | |
3656 | sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); | |
3657 | if (!sta) { | |
3658 | rcu_read_unlock(); | |
3659 | WARN_ONCE(1, "failed to find sta with addr %pM\n", | |
3660 | vif->cfg.ap_addr); | |
3661 | return; | |
3662 | } | |
3663 | ||
3664 | ahsta = ath12k_sta_to_ahsta(sta); | |
3665 | arvif = wiphy_dereference(hw->wiphy, | |
3666 | ahvif->link[ahsta->assoc_link_id]); | |
3667 | rcu_read_unlock(); | |
3668 | ||
3669 | ar = arvif->ar; | |
3670 | /* there is no reason for which an assoc link's | |
3671 | * bss info does not exist | |
3672 | */ | |
3673 | info = ath12k_mac_get_link_bss_conf(arvif); | |
3674 | ath12k_bss_assoc(ar, arvif, info); | |
3675 | ||
3676 | /* exclude assoc link as it is done above */ | |
3677 | links &= ~BIT(ahsta->assoc_link_id); | |
3678 | } | |
3679 | ||
afbab6e4 S |
3680 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { |
3681 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
3682 | if (!arvif || !arvif->ar) | |
3683 | continue; | |
3684 | ||
3685 | ar = arvif->ar; | |
3686 | ||
39526578 S |
3687 | if (vif->cfg.assoc) { |
3688 | info = ath12k_mac_get_link_bss_conf(arvif); | |
3689 | if (!info) | |
3690 | continue; | |
3691 | ||
3692 | ath12k_bss_assoc(ar, arvif, info); | |
3693 | } else { | |
afbab6e4 | 3694 | ath12k_bss_disassoc(ar, arvif); |
39526578 | 3695 | } |
afbab6e4 S |
3696 | } |
3697 | } | |
3698 | } | |
3699 | ||
3dd2c68f | 3700 | static void ath12k_mac_vif_setup_ps(struct ath12k_link_vif *arvif) |
54ca3308 BQ |
3701 | { |
3702 | struct ath12k *ar = arvif->ar; | |
3dd2c68f | 3703 | struct ieee80211_vif *vif = arvif->ahvif->vif; |
54ca3308 BQ |
3704 | struct ieee80211_conf *conf = &ath12k_ar_to_hw(ar)->conf; |
3705 | enum wmi_sta_powersave_param param; | |
39526578 | 3706 | struct ieee80211_bss_conf *info; |
54ca3308 BQ |
3707 | enum wmi_sta_ps_mode psmode; |
3708 | int ret; | |
3709 | int timeout; | |
3710 | bool enable_ps; | |
3711 | ||
b8c67509 | 3712 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
54ca3308 BQ |
3713 | |
3714 | if (vif->type != NL80211_IFTYPE_STATION) | |
3715 | return; | |
3716 | ||
3dd2c68f | 3717 | enable_ps = arvif->ahvif->ps; |
54ca3308 BQ |
3718 | if (enable_ps) { |
3719 | psmode = WMI_STA_PS_MODE_ENABLED; | |
3720 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; | |
3721 | ||
3722 | timeout = conf->dynamic_ps_timeout; | |
3723 | if (timeout == 0) { | |
39526578 S |
3724 | info = ath12k_mac_get_link_bss_conf(arvif); |
3725 | if (!info) { | |
3726 | ath12k_warn(ar->ab, "unable to access bss link conf in setup ps for vif %pM link %u\n", | |
3727 | vif->addr, arvif->link_id); | |
3728 | return; | |
3729 | } | |
3730 | ||
54ca3308 | 3731 | /* firmware doesn't like 0 */ |
39526578 | 3732 | timeout = ieee80211_tu_to_usec(info->beacon_int) / 1000; |
54ca3308 BQ |
3733 | } |
3734 | ||
3735 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, | |
3736 | timeout); | |
3737 | if (ret) { | |
3738 | ath12k_warn(ar->ab, "failed to set inactivity time for vdev %d: %i\n", | |
3739 | arvif->vdev_id, ret); | |
3740 | return; | |
3741 | } | |
3742 | } else { | |
3743 | psmode = WMI_STA_PS_MODE_DISABLED; | |
3744 | } | |
3745 | ||
3746 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d psmode %s\n", | |
3747 | arvif->vdev_id, psmode ? "enable" : "disable"); | |
3748 | ||
3749 | ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, psmode); | |
3750 | if (ret) | |
3751 | ath12k_warn(ar->ab, "failed to set sta power save mode %d for vdev %d: %d\n", | |
3752 | psmode, arvif->vdev_id, ret); | |
3753 | } | |
3754 | ||
29cb3d26 BQ |
3755 | static bool ath12k_mac_supports_station_tpc(struct ath12k *ar, |
3756 | struct ath12k_vif *ahvif, | |
3757 | const struct cfg80211_chan_def *chandef) | |
3758 | { | |
3759 | return ath12k_wmi_supports_6ghz_cc_ext(ar) && | |
3760 | test_bit(WMI_TLV_SERVICE_EXT_TPC_REG_SUPPORT, ar->ab->wmi_ab.svc_map) && | |
3761 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
3762 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE && | |
3763 | chandef->chan && | |
3764 | chandef->chan->band == NL80211_BAND_6GHZ; | |
3765 | } | |
3766 | ||
ce20a10f | 3767 | static void ath12k_mac_bss_info_changed(struct ath12k *ar, |
3dd2c68f | 3768 | struct ath12k_link_vif *arvif, |
ce20a10f KP |
3769 | struct ieee80211_bss_conf *info, |
3770 | u64 changed) | |
d8899132 | 3771 | { |
3dd2c68f S |
3772 | struct ath12k_vif *ahvif = arvif->ahvif; |
3773 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
54ca3308 | 3774 | struct ieee80211_vif_cfg *vif_cfg = &vif->cfg; |
d8899132 KV |
3775 | struct cfg80211_chan_def def; |
3776 | u32 param_id, param_value; | |
3777 | enum nl80211_band band; | |
3778 | u32 vdev_param; | |
3779 | int mcast_rate; | |
3780 | u32 preamble; | |
3781 | u16 hw_value; | |
3782 | u16 bitrate; | |
3783 | int ret; | |
3784 | u8 rateidx; | |
3785 | u32 rate; | |
3786 | ||
b8c67509 | 3787 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
3788 | |
3789 | if (changed & BSS_CHANGED_BEACON_INT) { | |
3790 | arvif->beacon_interval = info->beacon_int; | |
3791 | ||
3792 | param_id = WMI_VDEV_PARAM_BEACON_INTERVAL; | |
3793 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3794 | param_id, | |
3795 | arvif->beacon_interval); | |
3796 | if (ret) | |
3797 | ath12k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n", | |
3798 | arvif->vdev_id); | |
3799 | else | |
3800 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3801 | "Beacon interval: %d set for VDEV: %d\n", | |
3802 | arvif->beacon_interval, arvif->vdev_id); | |
3803 | } | |
3804 | ||
3805 | if (changed & BSS_CHANGED_BEACON) { | |
3806 | param_id = WMI_PDEV_PARAM_BEACON_TX_MODE; | |
c4cb46df | 3807 | param_value = WMI_BEACON_BURST_MODE; |
d8899132 KV |
3808 | ret = ath12k_wmi_pdev_set_param(ar, param_id, |
3809 | param_value, ar->pdev->pdev_id); | |
3810 | if (ret) | |
3811 | ath12k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n", | |
3812 | arvif->vdev_id); | |
3813 | else | |
3814 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
c4cb46df | 3815 | "Set burst beacon mode for VDEV: %d\n", |
d8899132 KV |
3816 | arvif->vdev_id); |
3817 | ||
3818 | ret = ath12k_mac_setup_bcn_tmpl(arvif); | |
3819 | if (ret) | |
3820 | ath12k_warn(ar->ab, "failed to update bcn template: %d\n", | |
3821 | ret); | |
3822 | } | |
3823 | ||
3824 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { | |
3825 | arvif->dtim_period = info->dtim_period; | |
3826 | ||
3827 | param_id = WMI_VDEV_PARAM_DTIM_PERIOD; | |
3828 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3829 | param_id, | |
3830 | arvif->dtim_period); | |
3831 | ||
3832 | if (ret) | |
3833 | ath12k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n", | |
3834 | arvif->vdev_id, ret); | |
3835 | else | |
3836 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3837 | "DTIM period: %d set for VDEV: %d\n", | |
3838 | arvif->dtim_period, arvif->vdev_id); | |
3839 | } | |
3840 | ||
3841 | if (changed & BSS_CHANGED_SSID && | |
3842 | vif->type == NL80211_IFTYPE_AP) { | |
3dd2c68f | 3843 | ahvif->u.ap.ssid_len = vif->cfg.ssid_len; |
d8899132 | 3844 | if (vif->cfg.ssid_len) |
3dd2c68f S |
3845 | memcpy(ahvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); |
3846 | ahvif->u.ap.hidden_ssid = info->hidden_ssid; | |
d8899132 KV |
3847 | } |
3848 | ||
3849 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) | |
3850 | ether_addr_copy(arvif->bssid, info->bssid); | |
3851 | ||
3852 | if (changed & BSS_CHANGED_BEACON_ENABLED) { | |
3853 | ath12k_control_beaconing(arvif, info); | |
3854 | ||
39526578 S |
3855 | if (arvif->is_up && info->he_support && |
3856 | info->he_oper.params) { | |
d8899132 KV |
3857 | /* TODO: Extend to support 1024 BA Bitmap size */ |
3858 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3859 | WMI_VDEV_PARAM_BA_MODE, | |
3860 | WMI_BA_MODE_BUFFER_SIZE_256); | |
3861 | if (ret) | |
3862 | ath12k_warn(ar->ab, | |
3863 | "failed to set BA BUFFER SIZE 256 for vdev: %d\n", | |
3864 | arvif->vdev_id); | |
3865 | ||
3866 | param_id = WMI_VDEV_PARAM_HEOPS_0_31; | |
39526578 | 3867 | param_value = info->he_oper.params; |
d8899132 KV |
3868 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
3869 | param_id, param_value); | |
3870 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3871 | "he oper param: %x set for VDEV: %d\n", | |
3872 | param_value, arvif->vdev_id); | |
3873 | ||
3874 | if (ret) | |
3875 | ath12k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n", | |
3876 | param_value, arvif->vdev_id, ret); | |
3877 | } | |
3878 | } | |
3879 | ||
3880 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
3881 | u32 cts_prot; | |
3882 | ||
3883 | cts_prot = !!(info->use_cts_prot); | |
3884 | param_id = WMI_VDEV_PARAM_PROTECTION_MODE; | |
3885 | ||
3886 | if (arvif->is_started) { | |
3887 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3888 | param_id, cts_prot); | |
3889 | if (ret) | |
3890 | ath12k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n", | |
3891 | arvif->vdev_id); | |
3892 | else | |
3893 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n", | |
3894 | cts_prot, arvif->vdev_id); | |
3895 | } else { | |
3896 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n"); | |
3897 | } | |
3898 | } | |
3899 | ||
3900 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
3901 | u32 slottime; | |
3902 | ||
3903 | if (info->use_short_slot) | |
3904 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ | |
3905 | ||
3906 | else | |
3907 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ | |
3908 | ||
3909 | param_id = WMI_VDEV_PARAM_SLOT_TIME; | |
3910 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3911 | param_id, slottime); | |
3912 | if (ret) | |
3913 | ath12k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n", | |
3914 | arvif->vdev_id); | |
3915 | else | |
3916 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3917 | "Set slottime: %d for VDEV: %d\n", | |
3918 | slottime, arvif->vdev_id); | |
3919 | } | |
3920 | ||
3921 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
3922 | u32 preamble; | |
3923 | ||
3924 | if (info->use_short_preamble) | |
3925 | preamble = WMI_VDEV_PREAMBLE_SHORT; | |
3926 | else | |
3927 | preamble = WMI_VDEV_PREAMBLE_LONG; | |
3928 | ||
3929 | param_id = WMI_VDEV_PARAM_PREAMBLE; | |
3930 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3931 | param_id, preamble); | |
3932 | if (ret) | |
3933 | ath12k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n", | |
3934 | arvif->vdev_id); | |
3935 | else | |
3936 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3937 | "Set preamble: %d for VDEV: %d\n", | |
3938 | preamble, arvif->vdev_id); | |
3939 | } | |
3940 | ||
3941 | if (changed & BSS_CHANGED_ASSOC) { | |
3942 | if (vif->cfg.assoc) | |
ce20a10f | 3943 | ath12k_bss_assoc(ar, arvif, info); |
d8899132 | 3944 | else |
ce20a10f | 3945 | ath12k_bss_disassoc(ar, arvif); |
d8899132 KV |
3946 | } |
3947 | ||
3948 | if (changed & BSS_CHANGED_TXPOWER) { | |
3949 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev_id %i txpower %d\n", | |
3950 | arvif->vdev_id, info->txpower); | |
3951 | ||
3952 | arvif->txpower = info->txpower; | |
3953 | ath12k_mac_txpower_recalc(ar); | |
3954 | } | |
3955 | ||
3956 | if (changed & BSS_CHANGED_MCAST_RATE && | |
abaadb93 | 3957 | !ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) { |
d8899132 | 3958 | band = def.chan->band; |
39526578 | 3959 | mcast_rate = info->mcast_rate[band]; |
d8899132 | 3960 | |
cb179024 | 3961 | if (mcast_rate > 0) { |
d8899132 | 3962 | rateidx = mcast_rate - 1; |
cb179024 PKC |
3963 | } else { |
3964 | if (info->basic_rates) | |
3965 | rateidx = __ffs(info->basic_rates); | |
3966 | else | |
3967 | rateidx = 0; | |
3968 | } | |
d8899132 | 3969 | |
6a88093f | 3970 | if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) |
d8899132 KV |
3971 | rateidx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; |
3972 | ||
3973 | bitrate = ath12k_legacy_rates[rateidx].bitrate; | |
3974 | hw_value = ath12k_legacy_rates[rateidx].hw_value; | |
3975 | ||
3976 | if (ath12k_mac_bitrate_is_cck(bitrate)) | |
3977 | preamble = WMI_RATE_PREAMBLE_CCK; | |
3978 | else | |
3979 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
3980 | ||
3981 | rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); | |
3982 | ||
3983 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3984 | "mac vdev %d mcast_rate %x\n", | |
3985 | arvif->vdev_id, rate); | |
3986 | ||
3987 | vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE; | |
3988 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3989 | vdev_param, rate); | |
3990 | if (ret) | |
3991 | ath12k_warn(ar->ab, | |
3992 | "failed to set mcast rate on vdev %i: %d\n", | |
3993 | arvif->vdev_id, ret); | |
3994 | ||
3995 | vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE; | |
3996 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3997 | vdev_param, rate); | |
3998 | if (ret) | |
3999 | ath12k_warn(ar->ab, | |
4000 | "failed to set bcast rate on vdev %i: %d\n", | |
4001 | arvif->vdev_id, ret); | |
4002 | } | |
4003 | ||
4004 | if (changed & BSS_CHANGED_BASIC_RATES && | |
abaadb93 | 4005 | !ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) |
005fe43b | 4006 | ath12k_recalculate_mgmt_rate(ar, arvif, &def); |
d8899132 KV |
4007 | |
4008 | if (changed & BSS_CHANGED_TWT) { | |
4009 | if (info->twt_requester || info->twt_responder) | |
4010 | ath12k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id); | |
4011 | else | |
4012 | ath12k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id); | |
4013 | } | |
4014 | ||
4015 | if (changed & BSS_CHANGED_HE_OBSS_PD) | |
4016 | ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
4017 | &info->he_obss_pd); | |
4018 | ||
4019 | if (changed & BSS_CHANGED_HE_BSS_COLOR) { | |
4020 | if (vif->type == NL80211_IFTYPE_AP) { | |
4021 | ret = ath12k_wmi_obss_color_cfg_cmd(ar, | |
4022 | arvif->vdev_id, | |
4023 | info->he_bss_color.color, | |
4024 | ATH12K_BSS_COLOR_AP_PERIODS, | |
4025 | info->he_bss_color.enabled); | |
4026 | if (ret) | |
4027 | ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", | |
4028 | arvif->vdev_id, ret); | |
4029 | } else if (vif->type == NL80211_IFTYPE_STATION) { | |
4030 | ret = ath12k_wmi_send_bss_color_change_enable_cmd(ar, | |
4031 | arvif->vdev_id, | |
4032 | 1); | |
4033 | if (ret) | |
4034 | ath12k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n", | |
4035 | arvif->vdev_id, ret); | |
4036 | ret = ath12k_wmi_obss_color_cfg_cmd(ar, | |
4037 | arvif->vdev_id, | |
4038 | 0, | |
4039 | ATH12K_BSS_COLOR_STA_PERIODS, | |
4040 | 1); | |
4041 | if (ret) | |
4042 | ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", | |
4043 | arvif->vdev_id, ret); | |
4044 | } | |
4045 | } | |
4046 | ||
43a10990 | 4047 | ath12k_mac_fils_discovery(arvif, info); |
d8899132 | 4048 | |
54ca3308 BQ |
4049 | if (changed & BSS_CHANGED_PS && |
4050 | ar->ab->hw_params->supports_sta_ps) { | |
3dd2c68f | 4051 | ahvif->ps = vif_cfg->ps; |
54ca3308 BQ |
4052 | ath12k_mac_vif_setup_ps(arvif); |
4053 | } | |
ce20a10f KP |
4054 | } |
4055 | ||
84c59710 RS |
4056 | static struct ath12k_vif_cache *ath12k_ahvif_get_link_cache(struct ath12k_vif *ahvif, |
4057 | u8 link_id) | |
b5068bc9 | 4058 | { |
25e18b9d | 4059 | if (!ahvif->cache[link_id]) { |
84c59710 | 4060 | ahvif->cache[link_id] = kzalloc(sizeof(*ahvif->cache[0]), GFP_KERNEL); |
25e18b9d RS |
4061 | if (ahvif->cache[link_id]) |
4062 | INIT_LIST_HEAD(&ahvif->cache[link_id]->key_conf.list); | |
4063 | } | |
b5068bc9 | 4064 | |
84c59710 | 4065 | return ahvif->cache[link_id]; |
b5068bc9 S |
4066 | } |
4067 | ||
25e18b9d | 4068 | static void ath12k_ahvif_put_link_key_cache(struct ath12k_vif_cache *cache) |
b5068bc9 | 4069 | { |
25e18b9d | 4070 | struct ath12k_key_conf *key_conf, *tmp; |
b5068bc9 | 4071 | |
25e18b9d RS |
4072 | if (!cache || list_empty(&cache->key_conf.list)) |
4073 | return; | |
4074 | list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { | |
4075 | list_del(&key_conf->list); | |
4076 | kfree(key_conf); | |
4077 | } | |
b5068bc9 S |
4078 | } |
4079 | ||
84c59710 | 4080 | static void ath12k_ahvif_put_link_cache(struct ath12k_vif *ahvif, u8 link_id) |
b5068bc9 | 4081 | { |
90570ba4 S |
4082 | if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
4083 | return; | |
4084 | ||
25e18b9d | 4085 | ath12k_ahvif_put_link_key_cache(ahvif->cache[link_id]); |
84c59710 RS |
4086 | kfree(ahvif->cache[link_id]); |
4087 | ahvif->cache[link_id] = NULL; | |
b5068bc9 S |
4088 | } |
4089 | ||
afbab6e4 S |
4090 | static void ath12k_mac_op_link_info_changed(struct ieee80211_hw *hw, |
4091 | struct ieee80211_vif *vif, | |
4092 | struct ieee80211_bss_conf *info, | |
4093 | u64 changed) | |
ce20a10f | 4094 | { |
6db6e70a | 4095 | struct ath12k *ar; |
3dd2c68f | 4096 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
b5068bc9 | 4097 | struct ath12k_vif_cache *cache; |
3dd2c68f | 4098 | struct ath12k_link_vif *arvif; |
afbab6e4 | 4099 | u8 link_id = info->link_id; |
ce20a10f | 4100 | |
c347f181 KV |
4101 | lockdep_assert_wiphy(hw->wiphy); |
4102 | ||
afbab6e4 | 4103 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
0148e40c | 4104 | |
b5068bc9 | 4105 | /* if the vdev is not created on a certain radio, |
0148e40c S |
4106 | * cache the info to be updated later on vdev creation |
4107 | */ | |
4108 | ||
afbab6e4 S |
4109 | if (!arvif || !arvif->is_created) { |
4110 | cache = ath12k_ahvif_get_link_cache(ahvif, link_id); | |
b5068bc9 S |
4111 | if (!cache) |
4112 | return; | |
3dd2c68f | 4113 | |
84c59710 | 4114 | cache->bss_conf_changed |= changed; |
3dd2c68f | 4115 | |
0148e40c | 4116 | return; |
b5068bc9 | 4117 | } |
6db6e70a | 4118 | |
afbab6e4 | 4119 | ar = arvif->ar; |
ce20a10f KP |
4120 | |
4121 | ath12k_mac_bss_info_changed(ar, arvif, info, changed); | |
d8899132 KV |
4122 | } |
4123 | ||
0d6e6736 S |
4124 | static struct ath12k* |
4125 | ath12k_mac_select_scan_device(struct ieee80211_hw *hw, | |
4126 | struct ieee80211_vif *vif, | |
4938ba73 | 4127 | u32 center_freq) |
0d6e6736 S |
4128 | { |
4129 | struct ath12k_hw *ah = hw->priv; | |
4130 | enum nl80211_band band; | |
4131 | struct ath12k *ar; | |
4132 | int i; | |
4133 | ||
4134 | if (ah->num_radio == 1) | |
4135 | return ah->radio; | |
4136 | ||
4137 | /* Currently mac80211 supports splitting scan requests into | |
4138 | * multiple scan requests per band. | |
4139 | * Loop through first channel and determine the scan radio | |
4140 | * TODO: There could be 5 GHz low/high channels in that case | |
4141 | * split the hw request and perform multiple scans | |
4142 | */ | |
4143 | ||
6a88093f | 4144 | if (center_freq < ATH12K_MIN_5GHZ_FREQ) |
0d6e6736 | 4145 | band = NL80211_BAND_2GHZ; |
6a88093f | 4146 | else if (center_freq < ATH12K_MIN_6GHZ_FREQ) |
0d6e6736 S |
4147 | band = NL80211_BAND_5GHZ; |
4148 | else | |
4149 | band = NL80211_BAND_6GHZ; | |
4150 | ||
4151 | for_each_ar(ah, ar, i) { | |
4152 | /* TODO 5 GHz low high split changes */ | |
4153 | if (ar->mac.sbands[band].channels) | |
4154 | return ar; | |
4155 | } | |
4156 | ||
4157 | return NULL; | |
4158 | } | |
4159 | ||
d8899132 KV |
4160 | void __ath12k_mac_scan_finish(struct ath12k *ar) |
4161 | { | |
b856f023 KP |
4162 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
4163 | ||
d8899132 KV |
4164 | lockdep_assert_held(&ar->data_lock); |
4165 | ||
4166 | switch (ar->scan.state) { | |
4167 | case ATH12K_SCAN_IDLE: | |
4168 | break; | |
4169 | case ATH12K_SCAN_RUNNING: | |
4170 | case ATH12K_SCAN_ABORTING: | |
c2ebb1d1 | 4171 | if (ar->scan.is_roc && ar->scan.roc_notify) |
b856f023 | 4172 | ieee80211_remain_on_channel_expired(hw); |
c2ebb1d1 WG |
4173 | fallthrough; |
4174 | case ATH12K_SCAN_STARTING: | |
d8899132 | 4175 | cancel_delayed_work(&ar->scan.timeout); |
591de41d | 4176 | complete_all(&ar->scan.completed); |
3863f014 | 4177 | wiphy_work_queue(ar->ah->hw->wiphy, &ar->scan.vdev_clean_wk); |
d8899132 KV |
4178 | break; |
4179 | } | |
4180 | } | |
4181 | ||
4182 | void ath12k_mac_scan_finish(struct ath12k *ar) | |
4183 | { | |
4184 | spin_lock_bh(&ar->data_lock); | |
4185 | __ath12k_mac_scan_finish(ar); | |
4186 | spin_unlock_bh(&ar->data_lock); | |
4187 | } | |
4188 | ||
4189 | static int ath12k_scan_stop(struct ath12k *ar) | |
4190 | { | |
4191 | struct ath12k_wmi_scan_cancel_arg arg = { | |
4192 | .req_type = WLAN_SCAN_CANCEL_SINGLE, | |
4193 | .scan_id = ATH12K_SCAN_ID, | |
4194 | }; | |
4195 | int ret; | |
4196 | ||
b8c67509 | 4197 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
4198 | |
4199 | /* TODO: Fill other STOP Params */ | |
4200 | arg.pdev_id = ar->pdev->pdev_id; | |
4201 | ||
4202 | ret = ath12k_wmi_send_scan_stop_cmd(ar, &arg); | |
4203 | if (ret) { | |
4204 | ath12k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret); | |
4205 | goto out; | |
4206 | } | |
4207 | ||
4208 | ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); | |
4209 | if (ret == 0) { | |
4210 | ath12k_warn(ar->ab, | |
4211 | "failed to receive scan abort comple: timed out\n"); | |
4212 | ret = -ETIMEDOUT; | |
4213 | } else if (ret > 0) { | |
4214 | ret = 0; | |
4215 | } | |
4216 | ||
4217 | out: | |
3863f014 AKS |
4218 | /* Scan state should be updated in scan completion worker but in |
4219 | * case firmware fails to deliver the event (for whatever reason) | |
4220 | * it is desired to clean up scan state anyway. Firmware may have | |
4221 | * just dropped the scan completion event delivery due to transport | |
4222 | * pipe being overflown with data and/or it can recover on its own | |
4223 | * before next scan request is submitted. | |
d8899132 KV |
4224 | */ |
4225 | spin_lock_bh(&ar->data_lock); | |
3863f014 | 4226 | if (ret) |
d8899132 KV |
4227 | __ath12k_mac_scan_finish(ar); |
4228 | spin_unlock_bh(&ar->data_lock); | |
4229 | ||
4230 | return ret; | |
4231 | } | |
4232 | ||
4233 | static void ath12k_scan_abort(struct ath12k *ar) | |
4234 | { | |
4235 | int ret; | |
4236 | ||
b8c67509 | 4237 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
4238 | |
4239 | spin_lock_bh(&ar->data_lock); | |
4240 | ||
4241 | switch (ar->scan.state) { | |
4242 | case ATH12K_SCAN_IDLE: | |
4243 | /* This can happen if timeout worker kicked in and called | |
4244 | * abortion while scan completion was being processed. | |
4245 | */ | |
4246 | break; | |
4247 | case ATH12K_SCAN_STARTING: | |
4248 | case ATH12K_SCAN_ABORTING: | |
4249 | ath12k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n", | |
4250 | ar->scan.state); | |
4251 | break; | |
4252 | case ATH12K_SCAN_RUNNING: | |
4253 | ar->scan.state = ATH12K_SCAN_ABORTING; | |
4254 | spin_unlock_bh(&ar->data_lock); | |
4255 | ||
4256 | ret = ath12k_scan_stop(ar); | |
4257 | if (ret) | |
4258 | ath12k_warn(ar->ab, "failed to abort scan: %d\n", ret); | |
4259 | ||
4260 | spin_lock_bh(&ar->data_lock); | |
4261 | break; | |
4262 | } | |
4263 | ||
4264 | spin_unlock_bh(&ar->data_lock); | |
4265 | } | |
4266 | ||
4267 | static void ath12k_scan_timeout_work(struct work_struct *work) | |
4268 | { | |
4269 | struct ath12k *ar = container_of(work, struct ath12k, | |
4270 | scan.timeout.work); | |
4271 | ||
b8c67509 | 4272 | wiphy_lock(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 4273 | ath12k_scan_abort(ar); |
b8c67509 | 4274 | wiphy_unlock(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
4275 | } |
4276 | ||
3863f014 AKS |
4277 | static void ath12k_scan_vdev_clean_work(struct wiphy *wiphy, struct wiphy_work *work) |
4278 | { | |
4279 | struct ath12k *ar = container_of(work, struct ath12k, | |
4280 | scan.vdev_clean_wk); | |
4281 | struct ath12k_hw *ah = ar->ah; | |
4282 | struct ath12k_link_vif *arvif; | |
4283 | ||
4284 | lockdep_assert_wiphy(wiphy); | |
4285 | ||
4286 | arvif = ar->scan.arvif; | |
4287 | ||
4288 | /* The scan vdev has already been deleted. This can occur when a | |
4289 | * new scan request is made on the same vif with a different | |
4290 | * frequency, causing the scan arvif to move from one radio to | |
4291 | * another. Or, scan was abrupted and via remove interface, the | |
4292 | * arvif is already deleted. Alternatively, if the scan vdev is not | |
4293 | * being used as an actual vdev, then do not delete it. | |
4294 | */ | |
4295 | if (!arvif || arvif->is_started) | |
4296 | goto work_complete; | |
4297 | ||
4298 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac clean scan vdev (link id %u)", | |
4299 | arvif->link_id); | |
4300 | ||
4301 | ath12k_mac_remove_link_interface(ah->hw, arvif); | |
4302 | ath12k_mac_unassign_link_vif(arvif); | |
4303 | ||
4304 | work_complete: | |
4305 | spin_lock_bh(&ar->data_lock); | |
4306 | ar->scan.arvif = NULL; | |
4307 | if (!ar->scan.is_roc) { | |
4308 | struct cfg80211_scan_info info = { | |
4309 | .aborted = ((ar->scan.state == | |
4310 | ATH12K_SCAN_ABORTING) || | |
4311 | (ar->scan.state == | |
4312 | ATH12K_SCAN_STARTING)), | |
4313 | }; | |
4314 | ||
4315 | ieee80211_scan_completed(ar->ah->hw, &info); | |
4316 | } | |
4317 | ||
4318 | ar->scan.state = ATH12K_SCAN_IDLE; | |
4319 | ar->scan_channel = NULL; | |
4320 | ar->scan.roc_freq = 0; | |
4321 | spin_unlock_bh(&ar->data_lock); | |
4322 | } | |
4323 | ||
d8899132 KV |
4324 | static int ath12k_start_scan(struct ath12k *ar, |
4325 | struct ath12k_wmi_scan_req_arg *arg) | |
4326 | { | |
4327 | int ret; | |
4328 | ||
b8c67509 | 4329 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
4330 | |
4331 | ret = ath12k_wmi_send_scan_start_cmd(ar, arg); | |
4332 | if (ret) | |
4333 | return ret; | |
4334 | ||
4335 | ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); | |
4336 | if (ret == 0) { | |
4337 | ret = ath12k_scan_stop(ar); | |
4338 | if (ret) | |
4339 | ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); | |
4340 | ||
4341 | return -ETIMEDOUT; | |
4342 | } | |
4343 | ||
4344 | /* If we failed to start the scan, return error code at | |
4345 | * this point. This is probably due to some issue in the | |
4346 | * firmware, but no need to wedge the driver due to that... | |
4347 | */ | |
4348 | spin_lock_bh(&ar->data_lock); | |
4349 | if (ar->scan.state == ATH12K_SCAN_IDLE) { | |
4350 | spin_unlock_bh(&ar->data_lock); | |
4351 | return -EINVAL; | |
4352 | } | |
4353 | spin_unlock_bh(&ar->data_lock); | |
4354 | ||
4355 | return 0; | |
4356 | } | |
4357 | ||
e92c658b AKS |
4358 | int ath12k_mac_get_fw_stats(struct ath12k *ar, |
4359 | struct ath12k_fw_stats_req_params *param) | |
4360 | { | |
4361 | struct ath12k_base *ab = ar->ab; | |
4362 | struct ath12k_hw *ah = ath12k_ar_to_ah(ar); | |
9a353a4a | 4363 | unsigned long time_left; |
e92c658b AKS |
4364 | int ret; |
4365 | ||
4366 | guard(mutex)(&ah->hw_mutex); | |
4367 | ||
4368 | if (ah->state != ATH12K_HW_STATE_ON) | |
4369 | return -ENETDOWN; | |
4370 | ||
e92c658b AKS |
4371 | ath12k_fw_stats_reset(ar); |
4372 | ||
4373 | reinit_completion(&ar->fw_stats_complete); | |
9a353a4a | 4374 | reinit_completion(&ar->fw_stats_done); |
e92c658b AKS |
4375 | |
4376 | ret = ath12k_wmi_send_stats_request_cmd(ar, param->stats_id, | |
4377 | param->vdev_id, param->pdev_id); | |
e92c658b AKS |
4378 | if (ret) { |
4379 | ath12k_warn(ab, "failed to request fw stats: %d\n", ret); | |
4380 | return ret; | |
4381 | } | |
4382 | ||
4383 | ath12k_dbg(ab, ATH12K_DBG_WMI, | |
4384 | "get fw stat pdev id %d vdev id %d stats id 0x%x\n", | |
4385 | param->pdev_id, param->vdev_id, param->stats_id); | |
4386 | ||
4387 | time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ); | |
e92c658b AKS |
4388 | if (!time_left) { |
4389 | ath12k_warn(ab, "time out while waiting for get fw stats\n"); | |
4390 | return -ETIMEDOUT; | |
4391 | } | |
4392 | ||
4393 | /* Firmware sends WMI_UPDATE_STATS_EVENTID back-to-back | |
4394 | * when stats data buffer limit is reached. fw_stats_complete | |
4395 | * is completed once host receives first event from firmware, but | |
9a353a4a | 4396 | * still there could be more events following. Below is to wait |
a48a931a | 4397 | * until firmware completes sending all the events. |
e92c658b | 4398 | */ |
9a353a4a BQ |
4399 | time_left = wait_for_completion_timeout(&ar->fw_stats_done, 3 * HZ); |
4400 | if (!time_left) { | |
4401 | ath12k_warn(ab, "time out while waiting for fw stats done\n"); | |
4402 | return -ETIMEDOUT; | |
e92c658b | 4403 | } |
9a353a4a | 4404 | |
e92c658b AKS |
4405 | return 0; |
4406 | } | |
4407 | ||
4408 | static int ath12k_mac_op_get_txpower(struct ieee80211_hw *hw, | |
4409 | struct ieee80211_vif *vif, | |
4410 | unsigned int link_id, | |
4411 | int *dbm) | |
4412 | { | |
4413 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
4414 | struct ath12k_fw_stats_req_params params = {}; | |
4415 | struct ath12k_fw_stats_pdev *pdev; | |
4416 | struct ath12k_hw *ah = hw->priv; | |
4417 | struct ath12k_link_vif *arvif; | |
4418 | struct ath12k_base *ab; | |
4419 | struct ath12k *ar; | |
4420 | int ret; | |
4421 | ||
4422 | /* Final Tx power is minimum of Target Power, CTL power, Regulatory | |
4423 | * Power, PSD EIRP Power. We just know the Regulatory power from the | |
4424 | * regulatory rules obtained. FW knows all these power and sets the min | |
4425 | * of these. Hence, we request the FW pdev stats in which FW reports | |
4426 | * the minimum of all vdev's channel Tx power. | |
4427 | */ | |
4428 | lockdep_assert_wiphy(hw->wiphy); | |
4429 | ||
4430 | arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); | |
4431 | if (!arvif || !arvif->ar) | |
4432 | return -EINVAL; | |
4433 | ||
4434 | ar = arvif->ar; | |
4435 | ab = ar->ab; | |
4436 | if (ah->state != ATH12K_HW_STATE_ON) | |
4437 | goto err_fallback; | |
4438 | ||
4439 | if (test_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags)) | |
4440 | return -EAGAIN; | |
4441 | ||
4442 | /* Limit the requests to Firmware for fetching the tx power */ | |
4443 | if (ar->chan_tx_pwr != ATH12K_PDEV_TX_POWER_INVALID && | |
4444 | time_before(jiffies, | |
4445 | msecs_to_jiffies(ATH12K_PDEV_TX_POWER_REFRESH_TIME_MSECS) + | |
4446 | ar->last_tx_power_update)) | |
4447 | goto send_tx_power; | |
4448 | ||
4449 | params.pdev_id = ar->pdev->pdev_id; | |
4450 | params.vdev_id = arvif->vdev_id; | |
4451 | params.stats_id = WMI_REQUEST_PDEV_STAT; | |
4452 | ret = ath12k_mac_get_fw_stats(ar, ¶ms); | |
4453 | if (ret) { | |
4454 | ath12k_warn(ab, "failed to request fw pdev stats: %d\n", ret); | |
4455 | goto err_fallback; | |
4456 | } | |
4457 | ||
4458 | spin_lock_bh(&ar->data_lock); | |
4459 | pdev = list_first_entry_or_null(&ar->fw_stats.pdevs, | |
4460 | struct ath12k_fw_stats_pdev, list); | |
4461 | if (!pdev) { | |
4462 | spin_unlock_bh(&ar->data_lock); | |
4463 | goto err_fallback; | |
4464 | } | |
4465 | ||
4466 | /* tx power reported by firmware is in units of 0.5 dBm */ | |
4467 | ar->chan_tx_pwr = pdev->chan_tx_power / 2; | |
4468 | spin_unlock_bh(&ar->data_lock); | |
4469 | ar->last_tx_power_update = jiffies; | |
4470 | ||
4471 | send_tx_power: | |
4472 | *dbm = ar->chan_tx_pwr; | |
4473 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower fetched from firmware %d dBm\n", | |
4474 | *dbm); | |
4475 | return 0; | |
4476 | ||
4477 | err_fallback: | |
4478 | /* We didn't get txpower from FW. Hence, relying on vif->bss_conf.txpower */ | |
4479 | *dbm = vif->bss_conf.txpower; | |
4480 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower from firmware NaN, reported %d dBm\n", | |
4481 | *dbm); | |
4482 | return 0; | |
4483 | } | |
4484 | ||
477cabfd S |
4485 | static u8 |
4486 | ath12k_mac_find_link_id_by_ar(struct ath12k_vif *ahvif, struct ath12k *ar) | |
4487 | { | |
4488 | struct ath12k_link_vif *arvif; | |
4489 | struct ath12k_hw *ah = ahvif->ah; | |
4490 | unsigned long links = ahvif->links_map; | |
4491 | u8 link_id; | |
4492 | ||
4493 | lockdep_assert_wiphy(ah->hw->wiphy); | |
4494 | ||
4495 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
4496 | arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); | |
4497 | ||
4498 | if (!arvif || !arvif->is_created) | |
4499 | continue; | |
4500 | ||
4501 | if (ar == arvif->ar) | |
4502 | return link_id; | |
4503 | } | |
4504 | ||
90570ba4 S |
4505 | /* input ar is not assigned to any of the links of ML VIF, use scan |
4506 | * link (15) for scan vdev creation. | |
477cabfd | 4507 | */ |
90570ba4 | 4508 | return ATH12K_DEFAULT_SCAN_LINK; |
477cabfd S |
4509 | } |
4510 | ||
d8899132 KV |
4511 | static int ath12k_mac_op_hw_scan(struct ieee80211_hw *hw, |
4512 | struct ieee80211_vif *vif, | |
4513 | struct ieee80211_scan_request *hw_req) | |
4514 | { | |
6db6e70a | 4515 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
477cabfd | 4516 | struct ath12k *ar; |
3dd2c68f S |
4517 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
4518 | struct ath12k_link_vif *arvif; | |
d8899132 | 4519 | struct cfg80211_scan_request *req = &hw_req->req; |
6274df25 | 4520 | struct ath12k_wmi_scan_req_arg *arg = NULL; |
477cabfd | 4521 | u8 link_id; |
d8899132 KV |
4522 | int ret; |
4523 | int i; | |
0d6e6736 | 4524 | bool create = true; |
d8899132 | 4525 | |
b8c67509 KV |
4526 | lockdep_assert_wiphy(hw->wiphy); |
4527 | ||
3dd2c68f | 4528 | arvif = &ahvif->deflink; |
0d6e6736 S |
4529 | |
4530 | /* Since the targeted scan device could depend on the frequency | |
4531 | * requested in the hw_req, select the corresponding radio | |
4532 | */ | |
4938ba73 | 4533 | ar = ath12k_mac_select_scan_device(hw, vif, hw_req->req.channels[0]->center_freq); |
0d6e6736 S |
4534 | if (!ar) |
4535 | return -EINVAL; | |
4536 | ||
477cabfd | 4537 | /* check if any of the links of ML VIF is already started on |
15293c18 | 4538 | * radio(ar) corresponding to given scan frequency and use it, |
90570ba4 | 4539 | * if not use scan link (link 15) for scan purpose. |
477cabfd S |
4540 | */ |
4541 | link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar); | |
4542 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); | |
4543 | ||
3863f014 AKS |
4544 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac link ID %d selected for scan", |
4545 | arvif->link_id); | |
4546 | ||
0d6e6736 S |
4547 | /* If the vif is already assigned to a specific vdev of an ar, |
4548 | * check whether its already started, vdev which is started | |
4549 | * are not allowed to switch to a new radio. | |
4550 | * If the vdev is not started, but was earlier created on a | |
4551 | * different ar, delete that vdev and create a new one. We don't | |
4552 | * delete at the scan stop as an optimization to avoid redundant | |
4553 | * delete-create vdev's for the same ar, in case the request is | |
4554 | * always on the same band for the vif | |
4555 | */ | |
4556 | if (arvif->is_created) { | |
4557 | if (WARN_ON(!arvif->ar)) | |
4558 | return -EINVAL; | |
4559 | ||
4560 | if (ar != arvif->ar && arvif->is_started) | |
4561 | return -EINVAL; | |
6db6e70a | 4562 | |
0d6e6736 | 4563 | if (ar != arvif->ar) { |
477cabfd S |
4564 | ath12k_mac_remove_link_interface(hw, arvif); |
4565 | ath12k_mac_unassign_link_vif(arvif); | |
0d6e6736 S |
4566 | } else { |
4567 | create = false; | |
4568 | } | |
4569 | } | |
3863f014 | 4570 | |
0d6e6736 | 4571 | if (create) { |
477cabfd S |
4572 | /* Previous arvif would've been cleared in radio switch block |
4573 | * above, assign arvif again for create. | |
4574 | */ | |
4575 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); | |
4576 | ||
005fe43b | 4577 | ret = ath12k_mac_vdev_create(ar, arvif); |
0d6e6736 S |
4578 | if (ret) { |
4579 | ath12k_warn(ar->ab, "unable to create scan vdev %d\n", ret); | |
4580 | return -EINVAL; | |
4581 | } | |
4582 | } | |
d8899132 KV |
4583 | |
4584 | spin_lock_bh(&ar->data_lock); | |
4585 | switch (ar->scan.state) { | |
4586 | case ATH12K_SCAN_IDLE: | |
4587 | reinit_completion(&ar->scan.started); | |
4588 | reinit_completion(&ar->scan.completed); | |
4589 | ar->scan.state = ATH12K_SCAN_STARTING; | |
4590 | ar->scan.is_roc = false; | |
3863f014 | 4591 | ar->scan.arvif = arvif; |
d8899132 KV |
4592 | ret = 0; |
4593 | break; | |
4594 | case ATH12K_SCAN_STARTING: | |
4595 | case ATH12K_SCAN_RUNNING: | |
4596 | case ATH12K_SCAN_ABORTING: | |
4597 | ret = -EBUSY; | |
4598 | break; | |
4599 | } | |
4600 | spin_unlock_bh(&ar->data_lock); | |
4601 | ||
4602 | if (ret) | |
4603 | goto exit; | |
4604 | ||
6274df25 MP |
4605 | arg = kzalloc(sizeof(*arg), GFP_KERNEL); |
4606 | if (!arg) { | |
4607 | ret = -ENOMEM; | |
4608 | goto exit; | |
4609 | } | |
4610 | ||
4611 | ath12k_wmi_start_scan_init(ar, arg); | |
4612 | arg->vdev_id = arvif->vdev_id; | |
4613 | arg->scan_id = ATH12K_SCAN_ID; | |
d8899132 KV |
4614 | |
4615 | if (req->ie_len) { | |
6274df25 MP |
4616 | arg->extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL); |
4617 | if (!arg->extraie.ptr) { | |
8ad314da WG |
4618 | ret = -ENOMEM; |
4619 | goto exit; | |
4620 | } | |
6274df25 | 4621 | arg->extraie.len = req->ie_len; |
d8899132 KV |
4622 | } |
4623 | ||
4624 | if (req->n_ssids) { | |
6274df25 MP |
4625 | arg->num_ssids = req->n_ssids; |
4626 | for (i = 0; i < arg->num_ssids; i++) | |
4627 | arg->ssid[i] = req->ssids[i]; | |
d8899132 | 4628 | } else { |
6274df25 | 4629 | arg->scan_f_passive = 1; |
d8899132 KV |
4630 | } |
4631 | ||
4632 | if (req->n_channels) { | |
6274df25 MP |
4633 | arg->num_chan = req->n_channels; |
4634 | arg->chan_list = kcalloc(arg->num_chan, sizeof(*arg->chan_list), | |
4635 | GFP_KERNEL); | |
4636 | if (!arg->chan_list) { | |
3742928a WG |
4637 | ret = -ENOMEM; |
4638 | goto exit; | |
4639 | } | |
4640 | ||
6274df25 MP |
4641 | for (i = 0; i < arg->num_chan; i++) |
4642 | arg->chan_list[i] = req->channels[i]->center_freq; | |
d8899132 KV |
4643 | } |
4644 | ||
6274df25 | 4645 | ret = ath12k_start_scan(ar, arg); |
d8899132 | 4646 | if (ret) { |
591de41d WG |
4647 | if (ret == -EBUSY) |
4648 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
4649 | "scan engine is busy 11d state %d\n", ar->state_11d); | |
4650 | else | |
4651 | ath12k_warn(ar->ab, "failed to start hw scan: %d\n", ret); | |
4652 | ||
d8899132 KV |
4653 | spin_lock_bh(&ar->data_lock); |
4654 | ar->scan.state = ATH12K_SCAN_IDLE; | |
4655 | spin_unlock_bh(&ar->data_lock); | |
241dfac9 | 4656 | goto exit; |
d8899132 KV |
4657 | } |
4658 | ||
3863f014 AKS |
4659 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac scan started"); |
4660 | ||
90570ba4 S |
4661 | /* As per cfg80211/mac80211 scan design, it allows only one |
4662 | * scan at a time. Hence last_scan link id is used for | |
4663 | * tracking the link id on which the scan is been done on | |
4664 | * this vif. | |
4665 | */ | |
4666 | ahvif->last_scan_link = arvif->link_id; | |
4667 | ||
d8899132 | 4668 | /* Add a margin to account for event/command processing */ |
b856f023 | 4669 | ieee80211_queue_delayed_work(ath12k_ar_to_hw(ar), &ar->scan.timeout, |
6274df25 | 4670 | msecs_to_jiffies(arg->max_scan_time + |
d8899132 KV |
4671 | ATH12K_MAC_SCAN_TIMEOUT_MSECS)); |
4672 | ||
4673 | exit: | |
6274df25 MP |
4674 | if (arg) { |
4675 | kfree(arg->chan_list); | |
4676 | kfree(arg->extraie.ptr); | |
4677 | kfree(arg); | |
4678 | } | |
d8899132 | 4679 | |
591de41d WG |
4680 | if (ar->state_11d == ATH12K_11D_PREPARING && |
4681 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
4682 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) | |
4683 | ath12k_mac_11d_scan_start(ar, arvif->vdev_id); | |
4684 | ||
d8899132 KV |
4685 | return ret; |
4686 | } | |
4687 | ||
4688 | static void ath12k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw, | |
4689 | struct ieee80211_vif *vif) | |
4690 | { | |
3dd2c68f | 4691 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
90570ba4 | 4692 | u16 link_id = ahvif->last_scan_link; |
3dd2c68f | 4693 | struct ath12k_link_vif *arvif; |
6db6e70a KP |
4694 | struct ath12k *ar; |
4695 | ||
c347f181 KV |
4696 | lockdep_assert_wiphy(hw->wiphy); |
4697 | ||
90570ba4 | 4698 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
3863f014 | 4699 | if (!arvif || arvif->is_started) |
0d6e6736 S |
4700 | return; |
4701 | ||
4702 | ar = arvif->ar; | |
d8899132 | 4703 | |
d8899132 | 4704 | ath12k_scan_abort(ar); |
d8899132 KV |
4705 | |
4706 | cancel_delayed_work_sync(&ar->scan.timeout); | |
4707 | } | |
4708 | ||
3dd2c68f | 4709 | static int ath12k_install_key(struct ath12k_link_vif *arvif, |
d8899132 KV |
4710 | struct ieee80211_key_conf *key, |
4711 | enum set_key_cmd cmd, | |
4712 | const u8 *macaddr, u32 flags) | |
4713 | { | |
4714 | int ret; | |
4715 | struct ath12k *ar = arvif->ar; | |
4716 | struct wmi_vdev_install_key_arg arg = { | |
4717 | .vdev_id = arvif->vdev_id, | |
4718 | .key_idx = key->keyidx, | |
4719 | .key_len = key->keylen, | |
4720 | .key_data = key->key, | |
4721 | .key_flags = flags, | |
4722 | .macaddr = macaddr, | |
4723 | }; | |
3dd2c68f | 4724 | struct ath12k_vif *ahvif = arvif->ahvif; |
d8899132 | 4725 | |
b8c67509 | 4726 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
4727 | |
4728 | reinit_completion(&ar->install_key_done); | |
4729 | ||
4730 | if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags)) | |
4731 | return 0; | |
4732 | ||
4733 | if (cmd == DISABLE_KEY) { | |
4734 | /* TODO: Check if FW expects value other than NONE for del */ | |
4735 | /* arg.key_cipher = WMI_CIPHER_NONE; */ | |
4736 | arg.key_len = 0; | |
4737 | arg.key_data = NULL; | |
4738 | goto install; | |
4739 | } | |
4740 | ||
4741 | switch (key->cipher) { | |
4742 | case WLAN_CIPHER_SUITE_CCMP: | |
f5d6b15d | 4743 | case WLAN_CIPHER_SUITE_CCMP_256: |
d8899132 | 4744 | arg.key_cipher = WMI_CIPHER_AES_CCM; |
d8899132 KV |
4745 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
4746 | break; | |
4747 | case WLAN_CIPHER_SUITE_TKIP: | |
4748 | arg.key_cipher = WMI_CIPHER_TKIP; | |
4749 | arg.key_txmic_len = 8; | |
4750 | arg.key_rxmic_len = 8; | |
4751 | break; | |
d8899132 KV |
4752 | case WLAN_CIPHER_SUITE_GCMP: |
4753 | case WLAN_CIPHER_SUITE_GCMP_256: | |
4754 | arg.key_cipher = WMI_CIPHER_AES_GCM; | |
f5d6b15d | 4755 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
d8899132 KV |
4756 | break; |
4757 | default: | |
4758 | ath12k_warn(ar->ab, "cipher %d is not supported\n", key->cipher); | |
4759 | return -EOPNOTSUPP; | |
4760 | } | |
4761 | ||
4762 | if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) | |
4763 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV | | |
4764 | IEEE80211_KEY_FLAG_RESERVE_TAILROOM; | |
4765 | ||
4766 | install: | |
4767 | ret = ath12k_wmi_vdev_install_key(arvif->ar, &arg); | |
4768 | ||
4769 | if (ret) | |
4770 | return ret; | |
4771 | ||
4772 | if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ)) | |
4773 | return -ETIMEDOUT; | |
4774 | ||
d61c0b3c | 4775 | if (ether_addr_equal(macaddr, arvif->bssid)) |
3dd2c68f | 4776 | ahvif->key_cipher = key->cipher; |
d8899132 KV |
4777 | |
4778 | return ar->install_key_status ? -EINVAL : 0; | |
4779 | } | |
4780 | ||
3dd2c68f | 4781 | static int ath12k_clear_peer_keys(struct ath12k_link_vif *arvif, |
d8899132 KV |
4782 | const u8 *addr) |
4783 | { | |
4784 | struct ath12k *ar = arvif->ar; | |
4785 | struct ath12k_base *ab = ar->ab; | |
4786 | struct ath12k_peer *peer; | |
4787 | int first_errno = 0; | |
4788 | int ret; | |
4789 | int i; | |
4790 | u32 flags = 0; | |
4791 | ||
b8c67509 | 4792 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
4793 | |
4794 | spin_lock_bh(&ab->base_lock); | |
4795 | peer = ath12k_peer_find(ab, arvif->vdev_id, addr); | |
4796 | spin_unlock_bh(&ab->base_lock); | |
4797 | ||
4798 | if (!peer) | |
4799 | return -ENOENT; | |
4800 | ||
4801 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
4802 | if (!peer->keys[i]) | |
4803 | continue; | |
4804 | ||
4805 | /* key flags are not required to delete the key */ | |
4806 | ret = ath12k_install_key(arvif, peer->keys[i], | |
4807 | DISABLE_KEY, addr, flags); | |
4808 | if (ret < 0 && first_errno == 0) | |
4809 | first_errno = ret; | |
4810 | ||
4811 | if (ret < 0) | |
4812 | ath12k_warn(ab, "failed to remove peer key %d: %d\n", | |
4813 | i, ret); | |
4814 | ||
4815 | spin_lock_bh(&ab->base_lock); | |
4816 | peer->keys[i] = NULL; | |
4817 | spin_unlock_bh(&ab->base_lock); | |
4818 | } | |
4819 | ||
4820 | return first_errno; | |
4821 | } | |
4822 | ||
b5068bc9 | 4823 | static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd, |
b89b5dbe S |
4824 | struct ath12k_link_vif *arvif, |
4825 | struct ath12k_link_sta *arsta, | |
b5068bc9 | 4826 | struct ieee80211_key_conf *key) |
d8899132 | 4827 | { |
b89b5dbe | 4828 | struct ieee80211_sta *sta = NULL; |
b5068bc9 | 4829 | struct ath12k_base *ab = ar->ab; |
d8899132 | 4830 | struct ath12k_peer *peer; |
b89b5dbe | 4831 | struct ath12k_sta *ahsta; |
d8899132 | 4832 | const u8 *peer_addr; |
37d06d71 | 4833 | int ret; |
d8899132 KV |
4834 | u32 flags = 0; |
4835 | ||
b8c67509 | 4836 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
6db6e70a | 4837 | |
b89b5dbe S |
4838 | if (arsta) |
4839 | sta = ath12k_ahsta_to_sta(arsta->ahsta); | |
6db6e70a | 4840 | |
b5068bc9 | 4841 | if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ab->dev_flags)) |
d8899132 KV |
4842 | return 1; |
4843 | ||
d8899132 | 4844 | if (sta) |
061097e5 | 4845 | peer_addr = arsta->addr; |
d8899132 | 4846 | else |
00e4dc11 | 4847 | peer_addr = arvif->bssid; |
d8899132 KV |
4848 | |
4849 | key->hw_key_idx = key->keyidx; | |
4850 | ||
4851 | /* the peer should not disappear in mid-way (unless FW goes awry) since | |
b8c67509 | 4852 | * we already hold wiphy lock. we just make sure its there now. |
d8899132 KV |
4853 | */ |
4854 | spin_lock_bh(&ab->base_lock); | |
4855 | peer = ath12k_peer_find(ab, arvif->vdev_id, peer_addr); | |
4856 | spin_unlock_bh(&ab->base_lock); | |
4857 | ||
4858 | if (!peer) { | |
4859 | if (cmd == SET_KEY) { | |
4860 | ath12k_warn(ab, "cannot install key for non-existent peer %pM\n", | |
4861 | peer_addr); | |
37d06d71 | 4862 | return -EOPNOTSUPP; |
d8899132 | 4863 | } |
37d06d71 KV |
4864 | |
4865 | /* if the peer doesn't exist there is no key to disable | |
4866 | * anymore | |
4867 | */ | |
4868 | return 0; | |
d8899132 KV |
4869 | } |
4870 | ||
4871 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
4872 | flags |= WMI_KEY_PAIRWISE; | |
4873 | else | |
4874 | flags |= WMI_KEY_GROUP; | |
4875 | ||
4876 | ret = ath12k_install_key(arvif, key, cmd, peer_addr, flags); | |
4877 | if (ret) { | |
4878 | ath12k_warn(ab, "ath12k_install_key failed (%d)\n", ret); | |
37d06d71 | 4879 | return ret; |
d8899132 KV |
4880 | } |
4881 | ||
4882 | ret = ath12k_dp_rx_peer_pn_replay_config(arvif, peer_addr, cmd, key); | |
4883 | if (ret) { | |
4884 | ath12k_warn(ab, "failed to offload PN replay detection %d\n", ret); | |
37d06d71 | 4885 | return ret; |
d8899132 KV |
4886 | } |
4887 | ||
4888 | spin_lock_bh(&ab->base_lock); | |
4889 | peer = ath12k_peer_find(ab, arvif->vdev_id, peer_addr); | |
4890 | if (peer && cmd == SET_KEY) { | |
4891 | peer->keys[key->keyidx] = key; | |
4892 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { | |
4893 | peer->ucast_keyidx = key->keyidx; | |
4894 | peer->sec_type = ath12k_dp_tx_get_encrypt_type(key->cipher); | |
4895 | } else { | |
4896 | peer->mcast_keyidx = key->keyidx; | |
4897 | peer->sec_type_grp = ath12k_dp_tx_get_encrypt_type(key->cipher); | |
4898 | } | |
4899 | } else if (peer && cmd == DISABLE_KEY) { | |
4900 | peer->keys[key->keyidx] = NULL; | |
4901 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
4902 | peer->ucast_keyidx = 0; | |
4903 | else | |
4904 | peer->mcast_keyidx = 0; | |
4905 | } else if (!peer) | |
4906 | /* impossible unless FW goes crazy */ | |
4907 | ath12k_warn(ab, "peer %pM disappeared!\n", peer_addr); | |
4908 | ||
4909 | if (sta) { | |
b89b5dbe | 4910 | ahsta = ath12k_sta_to_ahsta(sta); |
d8899132 KV |
4911 | |
4912 | switch (key->cipher) { | |
4913 | case WLAN_CIPHER_SUITE_TKIP: | |
4914 | case WLAN_CIPHER_SUITE_CCMP: | |
4915 | case WLAN_CIPHER_SUITE_CCMP_256: | |
4916 | case WLAN_CIPHER_SUITE_GCMP: | |
4917 | case WLAN_CIPHER_SUITE_GCMP_256: | |
4918 | if (cmd == SET_KEY) | |
b89b5dbe | 4919 | ahsta->pn_type = HAL_PN_TYPE_WPA; |
d8899132 | 4920 | else |
b89b5dbe | 4921 | ahsta->pn_type = HAL_PN_TYPE_NONE; |
d8899132 KV |
4922 | break; |
4923 | default: | |
b89b5dbe | 4924 | ahsta->pn_type = HAL_PN_TYPE_NONE; |
d8899132 KV |
4925 | break; |
4926 | } | |
4927 | } | |
4928 | ||
4929 | spin_unlock_bh(&ab->base_lock); | |
4930 | ||
37d06d71 | 4931 | return 0; |
b5068bc9 S |
4932 | } |
4933 | ||
25e18b9d RS |
4934 | static int ath12k_mac_update_key_cache(struct ath12k_vif_cache *cache, |
4935 | enum set_key_cmd cmd, | |
4936 | struct ieee80211_sta *sta, | |
4937 | struct ieee80211_key_conf *key) | |
4938 | { | |
336097d7 AKS |
4939 | struct ath12k_key_conf *key_conf, *tmp; |
4940 | ||
4941 | list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { | |
4942 | if (key_conf->key != key) | |
4943 | continue; | |
4944 | ||
4945 | /* If SET key entry is already present in cache, nothing to do, | |
4946 | * just return | |
4947 | */ | |
4948 | if (cmd == SET_KEY) | |
4949 | return 0; | |
4950 | ||
4951 | /* DEL key for an old SET key which driver hasn't flushed yet. | |
4952 | */ | |
4953 | list_del(&key_conf->list); | |
4954 | kfree(key_conf); | |
4955 | } | |
25e18b9d RS |
4956 | |
4957 | if (cmd == SET_KEY) { | |
4958 | key_conf = kzalloc(sizeof(*key_conf), GFP_KERNEL); | |
4959 | ||
4960 | if (!key_conf) | |
4961 | return -ENOMEM; | |
4962 | ||
4963 | key_conf->cmd = cmd; | |
4964 | key_conf->sta = sta; | |
4965 | key_conf->key = key; | |
4966 | list_add_tail(&key_conf->list, | |
4967 | &cache->key_conf.list); | |
4968 | } | |
336097d7 | 4969 | |
25e18b9d | 4970 | return 0; |
b5068bc9 S |
4971 | } |
4972 | ||
4973 | static int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
4974 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
4975 | struct ieee80211_key_conf *key) | |
4976 | { | |
3dd2c68f S |
4977 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
4978 | struct ath12k_link_vif *arvif; | |
b89b5dbe | 4979 | struct ath12k_link_sta *arsta = NULL; |
b5068bc9 | 4980 | struct ath12k_vif_cache *cache; |
b89b5dbe | 4981 | struct ath12k_sta *ahsta; |
25e18b9d RS |
4982 | unsigned long links; |
4983 | u8 link_id; | |
b5068bc9 S |
4984 | int ret; |
4985 | ||
b8c67509 KV |
4986 | lockdep_assert_wiphy(hw->wiphy); |
4987 | ||
b5068bc9 S |
4988 | /* BIP needs to be done in software */ |
4989 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || | |
4990 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
4991 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || | |
3dd2c68f | 4992 | key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) { |
b5068bc9 | 4993 | return 1; |
3dd2c68f | 4994 | } |
b5068bc9 S |
4995 | |
4996 | if (key->keyidx > WMI_MAX_KEY_INDEX) | |
4997 | return -ENOSPC; | |
4998 | ||
25e18b9d RS |
4999 | if (sta) { |
5000 | ahsta = ath12k_sta_to_ahsta(sta); | |
ad969bc9 | 5001 | |
25e18b9d RS |
5002 | /* For an ML STA Pairwise key is same for all associated link Stations, |
5003 | * hence do set key for all link STAs which are active. | |
5004 | */ | |
5005 | if (sta->mlo) { | |
5006 | links = ahsta->links_map; | |
5007 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
5008 | arvif = wiphy_dereference(hw->wiphy, | |
5009 | ahvif->link[link_id]); | |
5010 | arsta = wiphy_dereference(hw->wiphy, | |
5011 | ahsta->link[link_id]); | |
5012 | ||
5013 | if (WARN_ON(!arvif || !arsta)) | |
5014 | /* arvif and arsta are expected to be valid when | |
5015 | * STA is present. | |
5016 | */ | |
5017 | continue; | |
5018 | ||
5019 | ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, | |
5020 | arsta, key); | |
5021 | if (ret) | |
5022 | break; | |
5023 | } | |
25e18b9d | 5024 | |
ad969bc9 | 5025 | return 0; |
b5068bc9 S |
5026 | } |
5027 | ||
ad969bc9 KV |
5028 | arsta = &ahsta->deflink; |
5029 | arvif = arsta->arvif; | |
5030 | if (WARN_ON(!arvif)) | |
5031 | return -EINVAL; | |
5032 | ||
5033 | ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, arsta, key); | |
5034 | if (ret) | |
5035 | return ret; | |
3dd2c68f | 5036 | |
ad969bc9 KV |
5037 | return 0; |
5038 | } | |
3dd2c68f | 5039 | |
ad969bc9 KV |
5040 | if (key->link_id >= 0 && key->link_id < IEEE80211_MLD_MAX_NUM_LINKS) { |
5041 | link_id = key->link_id; | |
5042 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
5043 | } else { | |
5044 | link_id = 0; | |
5045 | arvif = &ahvif->deflink; | |
5046 | } | |
5047 | ||
5048 | if (!arvif || !arvif->is_created) { | |
5049 | cache = ath12k_ahvif_get_link_cache(ahvif, link_id); | |
5050 | if (!cache) | |
5051 | return -ENOSPC; | |
5052 | ||
5053 | ret = ath12k_mac_update_key_cache(cache, cmd, sta, key); | |
5054 | if (ret) | |
25e18b9d | 5055 | return ret; |
b5068bc9 | 5056 | |
ad969bc9 | 5057 | return 0; |
b5068bc9 S |
5058 | } |
5059 | ||
ad969bc9 KV |
5060 | ret = ath12k_mac_set_key(arvif->ar, cmd, arvif, NULL, key); |
5061 | if (ret) | |
5062 | return ret; | |
3dd2c68f | 5063 | |
ad969bc9 | 5064 | return 0; |
d8899132 KV |
5065 | } |
5066 | ||
5067 | static int | |
5068 | ath12k_mac_bitrate_mask_num_vht_rates(struct ath12k *ar, | |
5069 | enum nl80211_band band, | |
5070 | const struct cfg80211_bitrate_mask *mask) | |
5071 | { | |
5072 | int num_rates = 0; | |
5073 | int i; | |
5074 | ||
5075 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) | |
5076 | num_rates += hweight16(mask->control[band].vht_mcs[i]); | |
5077 | ||
5078 | return num_rates; | |
5079 | } | |
5080 | ||
5081 | static int | |
3dd2c68f | 5082 | ath12k_mac_set_peer_vht_fixed_rate(struct ath12k_link_vif *arvif, |
b89b5dbe | 5083 | struct ath12k_link_sta *arsta, |
d8899132 KV |
5084 | const struct cfg80211_bitrate_mask *mask, |
5085 | enum nl80211_band band) | |
5086 | { | |
5087 | struct ath12k *ar = arvif->ar; | |
5088 | u8 vht_rate, nss; | |
5089 | u32 rate_code; | |
5090 | int ret, i; | |
5091 | ||
b8c67509 | 5092 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
5093 | |
5094 | nss = 0; | |
5095 | ||
5096 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
5097 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { | |
5098 | nss = i + 1; | |
5099 | vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1; | |
5100 | } | |
5101 | } | |
5102 | ||
5103 | if (!nss) { | |
5104 | ath12k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM", | |
061097e5 | 5105 | arsta->addr); |
d8899132 KV |
5106 | return -EINVAL; |
5107 | } | |
5108 | ||
5109 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
5110 | "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates", | |
061097e5 | 5111 | arsta->addr); |
d8899132 KV |
5112 | |
5113 | rate_code = ATH12K_HW_RATE_CODE(vht_rate, nss - 1, | |
5114 | WMI_RATE_PREAMBLE_VHT); | |
061097e5 | 5115 | ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
d8899132 KV |
5116 | arvif->vdev_id, |
5117 | WMI_PEER_PARAM_FIXED_RATE, | |
5118 | rate_code); | |
5119 | if (ret) | |
5120 | ath12k_warn(ar->ab, | |
5121 | "failed to update STA %pM Fixed Rate %d: %d\n", | |
061097e5 | 5122 | arsta->addr, rate_code, ret); |
d8899132 KV |
5123 | |
5124 | return ret; | |
5125 | } | |
5126 | ||
c8a98ed1 S |
5127 | static int ath12k_mac_station_assoc(struct ath12k *ar, |
5128 | struct ath12k_link_vif *arvif, | |
5129 | struct ath12k_link_sta *arsta, | |
5130 | bool reassoc) | |
d8899132 | 5131 | { |
005fe43b | 5132 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 5133 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
63fdb906 | 5134 | struct ieee80211_link_sta *link_sta; |
d8899132 KV |
5135 | int ret; |
5136 | struct cfg80211_chan_def def; | |
5137 | enum nl80211_band band; | |
5138 | struct cfg80211_bitrate_mask *mask; | |
5139 | u8 num_vht_rates; | |
061097e5 | 5140 | u8 link_id = arvif->link_id; |
d8899132 | 5141 | |
b8c67509 | 5142 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 5143 | |
abaadb93 | 5144 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
5145 | return -EPERM; |
5146 | ||
061097e5 S |
5147 | if (WARN_ON(!rcu_access_pointer(sta->link[link_id]))) |
5148 | return -EINVAL; | |
5149 | ||
d8899132 KV |
5150 | band = def.chan->band; |
5151 | mask = &arvif->bitrate_mask; | |
5152 | ||
bf2da5c4 JJ |
5153 | struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = |
5154 | kzalloc(sizeof(*peer_arg), GFP_KERNEL); | |
5155 | if (!peer_arg) | |
5156 | return -ENOMEM; | |
d8899132 | 5157 | |
bf2da5c4 JJ |
5158 | ath12k_peer_assoc_prepare(ar, arvif, arsta, peer_arg, reassoc); |
5159 | ||
5160 | if (peer_arg->peer_nss < 1) { | |
db163a46 | 5161 | ath12k_warn(ar->ab, |
bf2da5c4 | 5162 | "invalid peer NSS %d\n", peer_arg->peer_nss); |
db163a46 A |
5163 | return -EINVAL; |
5164 | } | |
bf2da5c4 | 5165 | ret = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); |
d8899132 KV |
5166 | if (ret) { |
5167 | ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
061097e5 | 5168 | arsta->addr, arvif->vdev_id, ret); |
d8899132 KV |
5169 | return ret; |
5170 | } | |
5171 | ||
5172 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
5173 | ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
061097e5 | 5174 | arsta->addr, arvif->vdev_id); |
d8899132 KV |
5175 | return -ETIMEDOUT; |
5176 | } | |
5177 | ||
5178 | num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask); | |
5179 | ||
5180 | /* If single VHT rate is configured (by set_bitrate_mask()), | |
5181 | * peer_assoc will disable VHT. This is now enabled by a peer specific | |
5182 | * fixed param. | |
5183 | * Note that all other rates and NSS will be disabled for this peer. | |
5184 | */ | |
63fdb906 S |
5185 | link_sta = ath12k_mac_get_link_sta(arsta); |
5186 | if (!link_sta) { | |
5187 | ath12k_warn(ar->ab, "unable to access link sta in station assoc\n"); | |
5188 | return -EINVAL; | |
5189 | } | |
5190 | ||
2fc98b24 AKS |
5191 | spin_lock_bh(&ar->data_lock); |
5192 | arsta->bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta); | |
5193 | arsta->bw_prev = link_sta->bandwidth; | |
5194 | spin_unlock_bh(&ar->data_lock); | |
5195 | ||
63fdb906 | 5196 | if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) { |
b89b5dbe | 5197 | ret = ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, |
d8899132 KV |
5198 | band); |
5199 | if (ret) | |
5200 | return ret; | |
5201 | } | |
5202 | ||
5203 | /* Re-assoc is run only to update supported rates for given station. It | |
5204 | * doesn't make much sense to reconfigure the peer completely. | |
5205 | */ | |
5206 | if (reassoc) | |
5207 | return 0; | |
5208 | ||
061097e5 | 5209 | ret = ath12k_setup_peer_smps(ar, arvif, arsta->addr, |
63fdb906 | 5210 | &link_sta->ht_cap, &link_sta->he_6ghz_capa); |
d8899132 KV |
5211 | if (ret) { |
5212 | ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
5213 | arvif->vdev_id, ret); | |
5214 | return ret; | |
5215 | } | |
5216 | ||
5217 | if (!sta->wme) { | |
5218 | arvif->num_legacy_stations++; | |
5219 | ret = ath12k_recalc_rtscts_prot(arvif); | |
5220 | if (ret) | |
5221 | return ret; | |
5222 | } | |
5223 | ||
5224 | if (sta->wme && sta->uapsd_queues) { | |
b89b5dbe | 5225 | ret = ath12k_peer_assoc_qos_ap(ar, arvif, arsta); |
d8899132 KV |
5226 | if (ret) { |
5227 | ath12k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n", | |
061097e5 | 5228 | arsta->addr, arvif->vdev_id, ret); |
d8899132 KV |
5229 | return ret; |
5230 | } | |
5231 | } | |
5232 | ||
5233 | return 0; | |
5234 | } | |
5235 | ||
c8a98ed1 S |
5236 | static int ath12k_mac_station_disassoc(struct ath12k *ar, |
5237 | struct ath12k_link_vif *arvif, | |
5238 | struct ath12k_link_sta *arsta) | |
d8899132 | 5239 | { |
b89b5dbe | 5240 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
d8899132 | 5241 | |
b8c67509 | 5242 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
5243 | |
5244 | if (!sta->wme) { | |
5245 | arvif->num_legacy_stations--; | |
c8a98ed1 | 5246 | return ath12k_recalc_rtscts_prot(arvif); |
d8899132 KV |
5247 | } |
5248 | ||
d8899132 KV |
5249 | return 0; |
5250 | } | |
5251 | ||
58550cdd | 5252 | static void ath12k_sta_rc_update_wk(struct wiphy *wiphy, struct wiphy_work *wk) |
d8899132 | 5253 | { |
63fdb906 | 5254 | struct ieee80211_link_sta *link_sta; |
d8899132 | 5255 | struct ath12k *ar; |
3dd2c68f | 5256 | struct ath12k_link_vif *arvif; |
d8899132 KV |
5257 | struct ieee80211_sta *sta; |
5258 | struct cfg80211_chan_def def; | |
5259 | enum nl80211_band band; | |
5260 | const u8 *ht_mcs_mask; | |
5261 | const u16 *vht_mcs_mask; | |
cbc0008c | 5262 | u32 changed, bw, nss, smps, bw_prev; |
d8899132 KV |
5263 | int err, num_vht_rates; |
5264 | const struct cfg80211_bitrate_mask *mask; | |
cbc0008c | 5265 | enum wmi_phy_mode peer_phymode; |
b89b5dbe | 5266 | struct ath12k_link_sta *arsta; |
3dd2c68f | 5267 | struct ieee80211_vif *vif; |
d8899132 | 5268 | |
58550cdd KV |
5269 | lockdep_assert_wiphy(wiphy); |
5270 | ||
b89b5dbe S |
5271 | arsta = container_of(wk, struct ath12k_link_sta, update_wk); |
5272 | sta = ath12k_ahsta_to_sta(arsta->ahsta); | |
d8899132 | 5273 | arvif = arsta->arvif; |
3dd2c68f | 5274 | vif = ath12k_ahvif_to_vif(arvif->ahvif); |
d8899132 KV |
5275 | ar = arvif->ar; |
5276 | ||
abaadb93 | 5277 | if (WARN_ON(ath12k_mac_vif_link_chan(vif, arvif->link_id, &def))) |
d8899132 KV |
5278 | return; |
5279 | ||
5280 | band = def.chan->band; | |
5281 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
5282 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
5283 | ||
5284 | spin_lock_bh(&ar->data_lock); | |
5285 | ||
5286 | changed = arsta->changed; | |
5287 | arsta->changed = 0; | |
5288 | ||
5289 | bw = arsta->bw; | |
cbc0008c | 5290 | bw_prev = arsta->bw_prev; |
d8899132 KV |
5291 | nss = arsta->nss; |
5292 | smps = arsta->smps; | |
5293 | ||
5294 | spin_unlock_bh(&ar->data_lock); | |
5295 | ||
d8899132 KV |
5296 | nss = max_t(u32, 1, nss); |
5297 | nss = min(nss, max(ath12k_mac_max_ht_nss(ht_mcs_mask), | |
5298 | ath12k_mac_max_vht_nss(vht_mcs_mask))); | |
5299 | ||
6ff41242 JJ |
5300 | struct ath12k_wmi_peer_assoc_arg *peer_arg __free(kfree) = |
5301 | kzalloc(sizeof(*peer_arg), GFP_KERNEL); | |
5302 | if (!peer_arg) | |
5303 | return; | |
5304 | ||
d8899132 | 5305 | if (changed & IEEE80211_RC_BW_CHANGED) { |
6ff41242 JJ |
5306 | ath12k_peer_assoc_h_phymode(ar, arvif, arsta, peer_arg); |
5307 | peer_phymode = peer_arg->peer_phymode; | |
cbc0008c AKS |
5308 | |
5309 | if (bw > bw_prev) { | |
5310 | /* Phymode shows maximum supported channel width, if we | |
5311 | * upgrade bandwidth then due to sanity check of firmware, | |
5312 | * we have to send WMI_PEER_PHYMODE followed by | |
5313 | * WMI_PEER_CHWIDTH | |
5314 | */ | |
5315 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth upgrade for sta %pM new %d old %d\n", | |
061097e5 S |
5316 | arsta->addr, bw, bw_prev); |
5317 | err = ath12k_wmi_set_peer_param(ar, arsta->addr, | |
cbc0008c AKS |
5318 | arvif->vdev_id, WMI_PEER_PHYMODE, |
5319 | peer_phymode); | |
5320 | if (err) { | |
5321 | ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", | |
061097e5 | 5322 | arsta->addr, peer_phymode, err); |
b8c67509 | 5323 | return; |
cbc0008c | 5324 | } |
061097e5 | 5325 | err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
cbc0008c AKS |
5326 | arvif->vdev_id, WMI_PEER_CHWIDTH, |
5327 | bw); | |
5328 | if (err) | |
5329 | ath12k_warn(ar->ab, "failed to update STA %pM to peer bandwidth %d: %d\n", | |
061097e5 | 5330 | arsta->addr, bw, err); |
cbc0008c AKS |
5331 | } else { |
5332 | /* When we downgrade bandwidth this will conflict with phymode | |
5333 | * and cause to trigger firmware crash. In this case we send | |
5334 | * WMI_PEER_CHWIDTH followed by WMI_PEER_PHYMODE | |
5335 | */ | |
5336 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth downgrade for sta %pM new %d old %d\n", | |
061097e5 S |
5337 | arsta->addr, bw, bw_prev); |
5338 | err = ath12k_wmi_set_peer_param(ar, arsta->addr, | |
cbc0008c AKS |
5339 | arvif->vdev_id, WMI_PEER_CHWIDTH, |
5340 | bw); | |
5341 | if (err) { | |
5342 | ath12k_warn(ar->ab, "failed to update STA %pM peer to bandwidth %d: %d\n", | |
061097e5 | 5343 | arsta->addr, bw, err); |
b8c67509 | 5344 | return; |
cbc0008c | 5345 | } |
061097e5 | 5346 | err = ath12k_wmi_set_peer_param(ar, arsta->addr, |
cbc0008c AKS |
5347 | arvif->vdev_id, WMI_PEER_PHYMODE, |
5348 | peer_phymode); | |
5349 | if (err) | |
5350 | ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", | |
061097e5 | 5351 | arsta->addr, peer_phymode, err); |
cbc0008c | 5352 | } |
d8899132 KV |
5353 | } |
5354 | ||
5355 | if (changed & IEEE80211_RC_NSS_CHANGED) { | |
5356 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM nss %d\n", | |
061097e5 | 5357 | arsta->addr, nss); |
d8899132 | 5358 | |
061097e5 | 5359 | err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, |
d8899132 KV |
5360 | WMI_PEER_NSS, nss); |
5361 | if (err) | |
5362 | ath12k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n", | |
061097e5 | 5363 | arsta->addr, nss, err); |
d8899132 KV |
5364 | } |
5365 | ||
5366 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
5367 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM smps %d\n", | |
061097e5 | 5368 | arsta->addr, smps); |
d8899132 | 5369 | |
061097e5 | 5370 | err = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, |
d8899132 KV |
5371 | WMI_PEER_MIMO_PS_STATE, smps); |
5372 | if (err) | |
5373 | ath12k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n", | |
061097e5 | 5374 | arsta->addr, smps, err); |
d8899132 KV |
5375 | } |
5376 | ||
5377 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { | |
5378 | mask = &arvif->bitrate_mask; | |
5379 | num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, | |
5380 | mask); | |
5381 | ||
5382 | /* Peer_assoc_prepare will reject vht rates in | |
5383 | * bitrate_mask if its not available in range format and | |
5384 | * sets vht tx_rateset as unsupported. So multiple VHT MCS | |
5385 | * setting(eg. MCS 4,5,6) per peer is not supported here. | |
5386 | * But, Single rate in VHT mask can be set as per-peer | |
5387 | * fixed rate. But even if any HT rates are configured in | |
5388 | * the bitrate mask, device will not switch to those rates | |
5389 | * when per-peer Fixed rate is set. | |
5390 | * TODO: Check RATEMASK_CMDID to support auto rates selection | |
5391 | * across HT/VHT and for multiple VHT MCS support. | |
5392 | */ | |
63fdb906 S |
5393 | link_sta = ath12k_mac_get_link_sta(arsta); |
5394 | if (!link_sta) { | |
5395 | ath12k_warn(ar->ab, "unable to access link sta in peer assoc he for sta %pM link %u\n", | |
5396 | sta->addr, arsta->link_id); | |
5397 | return; | |
5398 | } | |
5399 | ||
5400 | if (link_sta->vht_cap.vht_supported && num_vht_rates == 1) { | |
b89b5dbe | 5401 | ath12k_mac_set_peer_vht_fixed_rate(arvif, arsta, mask, |
d8899132 KV |
5402 | band); |
5403 | } else { | |
5404 | /* If the peer is non-VHT or no fixed VHT rate | |
5405 | * is provided in the new bitrate mask we set the | |
5406 | * other rates using peer_assoc command. | |
5407 | */ | |
b89b5dbe | 5408 | ath12k_peer_assoc_prepare(ar, arvif, arsta, |
6ff41242 | 5409 | peer_arg, true); |
d8899132 | 5410 | |
6ff41242 | 5411 | err = ath12k_wmi_send_peer_assoc_cmd(ar, peer_arg); |
d8899132 KV |
5412 | if (err) |
5413 | ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
061097e5 | 5414 | arsta->addr, arvif->vdev_id, err); |
d8899132 KV |
5415 | |
5416 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) | |
5417 | ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
061097e5 | 5418 | arsta->addr, arvif->vdev_id); |
d8899132 KV |
5419 | } |
5420 | } | |
d8899132 KV |
5421 | } |
5422 | ||
8e6f8bc2 S |
5423 | static void ath12k_mac_free_unassign_link_sta(struct ath12k_hw *ah, |
5424 | struct ath12k_sta *ahsta, | |
5425 | u8 link_id) | |
5426 | { | |
5427 | struct ath12k_link_sta *arsta; | |
5428 | ||
5429 | lockdep_assert_wiphy(ah->hw->wiphy); | |
5430 | ||
5431 | if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) | |
5432 | return; | |
5433 | ||
5434 | arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); | |
5435 | if (WARN_ON(!arsta)) | |
5436 | return; | |
5437 | ||
5438 | ahsta->links_map &= ~BIT(link_id); | |
5439 | rcu_assign_pointer(ahsta->link[link_id], NULL); | |
5440 | synchronize_rcu(); | |
5441 | ||
5442 | if (arsta == &ahsta->deflink) { | |
5443 | arsta->link_id = ATH12K_INVALID_LINK_ID; | |
5444 | arsta->ahsta = NULL; | |
5445 | arsta->arvif = NULL; | |
5446 | return; | |
5447 | } | |
5448 | ||
5449 | kfree(arsta); | |
5450 | } | |
5451 | ||
3dd2c68f | 5452 | static int ath12k_mac_inc_num_stations(struct ath12k_link_vif *arvif, |
b89b5dbe | 5453 | struct ath12k_link_sta *arsta) |
d8899132 | 5454 | { |
b89b5dbe | 5455 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
d8899132 KV |
5456 | struct ath12k *ar = arvif->ar; |
5457 | ||
b8c67509 | 5458 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 5459 | |
3dd2c68f | 5460 | if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
d8899132 KV |
5461 | return 0; |
5462 | ||
5463 | if (ar->num_stations >= ar->max_num_stations) | |
5464 | return -ENOBUFS; | |
5465 | ||
5466 | ar->num_stations++; | |
5467 | ||
5468 | return 0; | |
5469 | } | |
5470 | ||
3dd2c68f | 5471 | static void ath12k_mac_dec_num_stations(struct ath12k_link_vif *arvif, |
b89b5dbe | 5472 | struct ath12k_link_sta *arsta) |
d8899132 | 5473 | { |
b89b5dbe | 5474 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
d8899132 KV |
5475 | struct ath12k *ar = arvif->ar; |
5476 | ||
b8c67509 | 5477 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 5478 | |
3dd2c68f | 5479 | if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
d8899132 KV |
5480 | return; |
5481 | ||
5482 | ar->num_stations--; | |
5483 | } | |
5484 | ||
c8a98ed1 S |
5485 | static void ath12k_mac_station_post_remove(struct ath12k *ar, |
5486 | struct ath12k_link_vif *arvif, | |
5487 | struct ath12k_link_sta *arsta) | |
5488 | { | |
5489 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); | |
5490 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); | |
c8a98ed1 S |
5491 | struct ath12k_peer *peer; |
5492 | ||
5493 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
5494 | ||
5495 | ath12k_mac_dec_num_stations(arvif, arsta); | |
5496 | ||
5497 | spin_lock_bh(&ar->ab->base_lock); | |
5498 | ||
061097e5 | 5499 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); |
c8a98ed1 S |
5500 | if (peer && peer->sta == sta) { |
5501 | ath12k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n", | |
5502 | vif->addr, arvif->vdev_id); | |
5503 | peer->sta = NULL; | |
5504 | list_del(&peer->list); | |
5505 | kfree(peer); | |
5506 | ar->num_peers--; | |
5507 | } | |
5508 | ||
5509 | spin_unlock_bh(&ar->ab->base_lock); | |
5510 | ||
5511 | kfree(arsta->rx_stats); | |
5512 | arsta->rx_stats = NULL; | |
c8a98ed1 S |
5513 | } |
5514 | ||
5515 | static int ath12k_mac_station_unauthorize(struct ath12k *ar, | |
5516 | struct ath12k_link_vif *arvif, | |
5517 | struct ath12k_link_sta *arsta) | |
5518 | { | |
5519 | struct ath12k_peer *peer; | |
5520 | int ret; | |
5521 | ||
5522 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
5523 | ||
5524 | spin_lock_bh(&ar->ab->base_lock); | |
5525 | ||
5526 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); | |
5527 | if (peer) | |
5528 | peer->is_authorized = false; | |
5529 | ||
5530 | spin_unlock_bh(&ar->ab->base_lock); | |
5531 | ||
5532 | /* Driver must clear the keys during the state change from | |
5533 | * IEEE80211_STA_AUTHORIZED to IEEE80211_STA_ASSOC, since after | |
5534 | * returning from here, mac80211 is going to delete the keys | |
5535 | * in __sta_info_destroy_part2(). This will ensure that the driver does | |
5536 | * not retain stale key references after mac80211 deletes the keys. | |
5537 | */ | |
5538 | ret = ath12k_clear_peer_keys(arvif, arsta->addr); | |
5539 | if (ret) { | |
5540 | ath12k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n", | |
5541 | arvif->vdev_id, ret); | |
5542 | return ret; | |
5543 | } | |
5544 | ||
5545 | return 0; | |
5546 | } | |
5547 | ||
5548 | static int ath12k_mac_station_authorize(struct ath12k *ar, | |
5549 | struct ath12k_link_vif *arvif, | |
5550 | struct ath12k_link_sta *arsta) | |
5551 | { | |
5552 | struct ath12k_peer *peer; | |
5553 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); | |
c8a98ed1 S |
5554 | int ret; |
5555 | ||
5556 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
5557 | ||
5558 | spin_lock_bh(&ar->ab->base_lock); | |
5559 | ||
061097e5 | 5560 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); |
c8a98ed1 S |
5561 | if (peer) |
5562 | peer->is_authorized = true; | |
5563 | ||
5564 | spin_unlock_bh(&ar->ab->base_lock); | |
5565 | ||
5566 | if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) { | |
061097e5 | 5567 | ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
c8a98ed1 S |
5568 | arvif->vdev_id, |
5569 | WMI_PEER_AUTHORIZE, | |
5570 | 1); | |
5571 | if (ret) { | |
5572 | ath12k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n", | |
061097e5 | 5573 | arsta->addr, arvif->vdev_id, ret); |
c8a98ed1 S |
5574 | return ret; |
5575 | } | |
5576 | } | |
5577 | ||
5578 | return 0; | |
5579 | } | |
5580 | ||
5581 | static int ath12k_mac_station_remove(struct ath12k *ar, | |
5582 | struct ath12k_link_vif *arvif, | |
5583 | struct ath12k_link_sta *arsta) | |
5584 | { | |
5585 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); | |
5586 | struct ath12k_vif *ahvif = arvif->ahvif; | |
8e6f8bc2 | 5587 | int ret = 0; |
c8a98ed1 S |
5588 | |
5589 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
5590 | ||
5591 | wiphy_work_cancel(ar->ah->hw->wiphy, &arsta->update_wk); | |
5592 | ||
5593 | if (ahvif->vdev_type == WMI_VDEV_TYPE_STA) { | |
5594 | ath12k_bss_disassoc(ar, arvif); | |
5595 | ret = ath12k_mac_vdev_stop(arvif); | |
5596 | if (ret) | |
5597 | ath12k_warn(ar->ab, "failed to stop vdev %i: %d\n", | |
5598 | arvif->vdev_id, ret); | |
5599 | } | |
5600 | ||
8e6f8bc2 S |
5601 | if (sta->mlo) |
5602 | return ret; | |
5603 | ||
061097e5 | 5604 | ath12k_dp_peer_cleanup(ar, arvif->vdev_id, arsta->addr); |
c8a98ed1 | 5605 | |
061097e5 | 5606 | ret = ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr); |
c8a98ed1 S |
5607 | if (ret) |
5608 | ath12k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n", | |
061097e5 | 5609 | arsta->addr, arvif->vdev_id); |
c8a98ed1 S |
5610 | else |
5611 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n", | |
061097e5 | 5612 | arsta->addr, arvif->vdev_id); |
c8a98ed1 S |
5613 | |
5614 | ath12k_mac_station_post_remove(ar, arvif, arsta); | |
5615 | ||
8e6f8bc2 S |
5616 | if (sta->valid_links) |
5617 | ath12k_mac_free_unassign_link_sta(ahvif->ah, | |
5618 | arsta->ahsta, arsta->link_id); | |
5619 | ||
c8a98ed1 S |
5620 | return ret; |
5621 | } | |
5622 | ||
d8899132 | 5623 | static int ath12k_mac_station_add(struct ath12k *ar, |
005fe43b | 5624 | struct ath12k_link_vif *arvif, |
b89b5dbe | 5625 | struct ath12k_link_sta *arsta) |
d8899132 KV |
5626 | { |
5627 | struct ath12k_base *ab = ar->ab; | |
005fe43b | 5628 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
b89b5dbe | 5629 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(arsta->ahsta); |
061097e5 | 5630 | struct ath12k_wmi_peer_create_arg peer_param = {0}; |
d8899132 KV |
5631 | int ret; |
5632 | ||
b8c67509 | 5633 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 5634 | |
b89b5dbe | 5635 | ret = ath12k_mac_inc_num_stations(arvif, arsta); |
d8899132 KV |
5636 | if (ret) { |
5637 | ath12k_warn(ab, "refusing to associate station: too many connected already (%d)\n", | |
5638 | ar->max_num_stations); | |
5639 | goto exit; | |
5640 | } | |
c426497f | 5641 | |
25be5d1d | 5642 | if (ath12k_debugfs_is_extd_rx_stats_enabled(ar) && !arsta->rx_stats) { |
c426497f SS |
5643 | arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL); |
5644 | if (!arsta->rx_stats) { | |
5645 | ret = -ENOMEM; | |
5646 | goto dec_num_station; | |
5647 | } | |
d8899132 KV |
5648 | } |
5649 | ||
5650 | peer_param.vdev_id = arvif->vdev_id; | |
0660e1e2 | 5651 | peer_param.peer_addr = arsta->addr; |
d8899132 | 5652 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; |
0660e1e2 | 5653 | peer_param.ml_enabled = sta->mlo; |
d8899132 KV |
5654 | |
5655 | ret = ath12k_peer_create(ar, arvif, sta, &peer_param); | |
5656 | if (ret) { | |
5657 | ath12k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n", | |
061097e5 | 5658 | arsta->addr, arvif->vdev_id); |
d8899132 KV |
5659 | goto free_peer; |
5660 | } | |
5661 | ||
5662 | ath12k_dbg(ab, ATH12K_DBG_MAC, "Added peer: %pM for VDEV: %d\n", | |
061097e5 | 5663 | arsta->addr, arvif->vdev_id); |
d8899132 KV |
5664 | |
5665 | if (ieee80211_vif_is_mesh(vif)) { | |
061097e5 | 5666 | ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
d8899132 KV |
5667 | arvif->vdev_id, |
5668 | WMI_PEER_USE_4ADDR, 1); | |
5669 | if (ret) { | |
5670 | ath12k_warn(ab, "failed to STA %pM 4addr capability: %d\n", | |
061097e5 | 5671 | arsta->addr, ret); |
d8899132 KV |
5672 | goto free_peer; |
5673 | } | |
5674 | } | |
5675 | ||
061097e5 | 5676 | ret = ath12k_dp_peer_setup(ar, arvif->vdev_id, arsta->addr); |
d8899132 KV |
5677 | if (ret) { |
5678 | ath12k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n", | |
061097e5 | 5679 | arsta->addr, arvif->vdev_id, ret); |
d8899132 KV |
5680 | goto free_peer; |
5681 | } | |
5682 | ||
5683 | if (ab->hw_params->vdev_start_delay && | |
5684 | !arvif->is_started && | |
3dd2c68f | 5685 | arvif->ahvif->vdev_type != WMI_VDEV_TYPE_AP) { |
5bdfb8c9 | 5686 | ret = ath12k_start_vdev_delay(ar, arvif); |
d8899132 KV |
5687 | if (ret) { |
5688 | ath12k_warn(ab, "failed to delay vdev start: %d\n", ret); | |
5689 | goto free_peer; | |
5690 | } | |
5691 | } | |
5692 | ||
cb53a678 | 5693 | ewma_avg_rssi_init(&arsta->avg_rssi); |
d8899132 KV |
5694 | return 0; |
5695 | ||
5696 | free_peer: | |
061097e5 | 5697 | ath12k_peer_delete(ar, arvif->vdev_id, arsta->addr); |
85edf163 RS |
5698 | kfree(arsta->rx_stats); |
5699 | arsta->rx_stats = NULL; | |
d8899132 | 5700 | dec_num_station: |
b89b5dbe | 5701 | ath12k_mac_dec_num_stations(arvif, arsta); |
d8899132 KV |
5702 | exit: |
5703 | return ret; | |
5704 | } | |
5705 | ||
8e6f8bc2 S |
5706 | static int ath12k_mac_assign_link_sta(struct ath12k_hw *ah, |
5707 | struct ath12k_sta *ahsta, | |
5708 | struct ath12k_link_sta *arsta, | |
5709 | struct ath12k_vif *ahvif, | |
5710 | u8 link_id) | |
5711 | { | |
5712 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); | |
5713 | struct ieee80211_link_sta *link_sta; | |
5714 | struct ath12k_link_vif *arvif; | |
5715 | ||
5716 | lockdep_assert_wiphy(ah->hw->wiphy); | |
5717 | ||
5718 | if (!arsta || link_id >= IEEE80211_MLD_MAX_NUM_LINKS) | |
5719 | return -EINVAL; | |
5720 | ||
5721 | arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); | |
5722 | if (!arvif) | |
5723 | return -EINVAL; | |
5724 | ||
5725 | memset(arsta, 0, sizeof(*arsta)); | |
5726 | ||
5727 | link_sta = wiphy_dereference(ah->hw->wiphy, sta->link[link_id]); | |
5728 | if (!link_sta) | |
5729 | return -EINVAL; | |
5730 | ||
5731 | ether_addr_copy(arsta->addr, link_sta->addr); | |
5732 | ||
5733 | /* logical index of the link sta in order of creation */ | |
5734 | arsta->link_idx = ahsta->num_peer++; | |
5735 | ||
5736 | arsta->link_id = link_id; | |
5737 | ahsta->links_map |= BIT(arsta->link_id); | |
5738 | arsta->arvif = arvif; | |
5739 | arsta->ahsta = ahsta; | |
061097e5 S |
5740 | ahsta->ahvif = ahvif; |
5741 | ||
8e6f8bc2 S |
5742 | wiphy_work_init(&arsta->update_wk, ath12k_sta_rc_update_wk); |
5743 | ||
5744 | rcu_assign_pointer(ahsta->link[link_id], arsta); | |
5745 | ||
5746 | return 0; | |
5747 | } | |
5748 | ||
5749 | static void ath12k_mac_ml_station_remove(struct ath12k_vif *ahvif, | |
5750 | struct ath12k_sta *ahsta) | |
5751 | { | |
5752 | struct ieee80211_sta *sta = ath12k_ahsta_to_sta(ahsta); | |
5753 | struct ath12k_hw *ah = ahvif->ah; | |
5754 | struct ath12k_link_vif *arvif; | |
5755 | struct ath12k_link_sta *arsta; | |
5756 | unsigned long links; | |
5757 | struct ath12k *ar; | |
5758 | u8 link_id; | |
5759 | ||
5760 | lockdep_assert_wiphy(ah->hw->wiphy); | |
5761 | ||
5762 | ath12k_peer_mlo_link_peers_delete(ahvif, ahsta); | |
5763 | ||
5764 | /* validate link station removal and clear arsta links */ | |
5765 | links = ahsta->links_map; | |
5766 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
5767 | arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[link_id]); | |
5768 | arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); | |
5769 | if (!arvif || !arsta) | |
5770 | continue; | |
5771 | ||
5772 | ar = arvif->ar; | |
5773 | ||
5774 | ath12k_mac_station_post_remove(ar, arvif, arsta); | |
5775 | ||
5776 | ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); | |
5777 | } | |
5778 | ||
5779 | ath12k_peer_ml_delete(ah, sta); | |
5780 | } | |
5781 | ||
c8a98ed1 S |
5782 | static int ath12k_mac_handle_link_sta_state(struct ieee80211_hw *hw, |
5783 | struct ath12k_link_vif *arvif, | |
5784 | struct ath12k_link_sta *arsta, | |
5785 | enum ieee80211_sta_state old_state, | |
5786 | enum ieee80211_sta_state new_state) | |
d8899132 | 5787 | { |
c8a98ed1 | 5788 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); |
7ed3e886 | 5789 | struct ieee80211_bss_conf *link_conf; |
8e6f8bc2 | 5790 | struct ath12k *ar = arvif->ar; |
7ed3e886 BQ |
5791 | struct ath12k_reg_info *reg_info; |
5792 | struct ath12k_base *ab = ar->ab; | |
d8899132 KV |
5793 | int ret = 0; |
5794 | ||
c347f181 KV |
5795 | lockdep_assert_wiphy(hw->wiphy); |
5796 | ||
7ed3e886 | 5797 | ath12k_dbg(ab, ATH12K_DBG_MAC, "mac handle link %u sta %pM state %d -> %d\n", |
8e6f8bc2 S |
5798 | arsta->link_id, arsta->addr, old_state, new_state); |
5799 | ||
c8a98ed1 S |
5800 | /* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: Remove the station |
5801 | * from driver | |
5802 | */ | |
5803 | if ((old_state == IEEE80211_STA_NONE && | |
5804 | new_state == IEEE80211_STA_NOTEXIST)) { | |
c8a98ed1 S |
5805 | ret = ath12k_mac_station_remove(ar, arvif, arsta); |
5806 | if (ret) { | |
7ed3e886 | 5807 | ath12k_warn(ab, "Failed to remove station: %pM for VDEV: %d\n", |
c8a98ed1 | 5808 | arsta->addr, arvif->vdev_id); |
8e6f8bc2 | 5809 | goto exit; |
c8a98ed1 | 5810 | } |
0148e40c | 5811 | } |
6db6e70a | 5812 | |
c8a98ed1 | 5813 | /* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: Add new station to driver */ |
d8899132 KV |
5814 | if (old_state == IEEE80211_STA_NOTEXIST && |
5815 | new_state == IEEE80211_STA_NONE) { | |
b89b5dbe | 5816 | ret = ath12k_mac_station_add(ar, arvif, arsta); |
d8899132 | 5817 | if (ret) |
7ed3e886 | 5818 | ath12k_warn(ab, "Failed to add station: %pM for VDEV: %d\n", |
061097e5 | 5819 | arsta->addr, arvif->vdev_id); |
e805272f | 5820 | |
c8a98ed1 S |
5821 | /* IEEE80211_STA_AUTH -> IEEE80211_STA_ASSOC: Send station assoc command for |
5822 | * peer associated to AP/Mesh/ADHOC vif type. | |
5823 | */ | |
d8899132 KV |
5824 | } else if (old_state == IEEE80211_STA_AUTH && |
5825 | new_state == IEEE80211_STA_ASSOC && | |
5826 | (vif->type == NL80211_IFTYPE_AP || | |
5827 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
5828 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
c8a98ed1 | 5829 | ret = ath12k_mac_station_assoc(ar, arvif, arsta, false); |
d8899132 | 5830 | if (ret) |
7ed3e886 | 5831 | ath12k_warn(ab, "Failed to associate station: %pM\n", |
061097e5 | 5832 | arsta->addr); |
cbc0008c | 5833 | |
c8a98ed1 S |
5834 | /* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTHORIZED: set peer status as |
5835 | * authorized | |
5836 | */ | |
d8899132 KV |
5837 | } else if (old_state == IEEE80211_STA_ASSOC && |
5838 | new_state == IEEE80211_STA_AUTHORIZED) { | |
c8a98ed1 | 5839 | ret = ath12k_mac_station_authorize(ar, arvif, arsta); |
7ed3e886 BQ |
5840 | if (ret) { |
5841 | ath12k_warn(ab, "Failed to authorize station: %pM\n", | |
061097e5 | 5842 | arsta->addr); |
7ed3e886 BQ |
5843 | goto exit; |
5844 | } | |
5845 | ||
5846 | if (ath12k_wmi_supports_6ghz_cc_ext(ar) && | |
5847 | arvif->ahvif->vdev_type == WMI_VDEV_TYPE_STA) { | |
5848 | link_conf = ath12k_mac_get_link_bss_conf(arvif); | |
5849 | reg_info = ab->reg_info[ar->pdev_idx]; | |
5850 | ath12k_dbg(ab, ATH12K_DBG_MAC, "connection done, update reg rules\n"); | |
886bb362 | 5851 | ath12k_hw_to_ah(hw)->regd_updated = false; |
7ed3e886 BQ |
5852 | ath12k_reg_handle_chan_list(ab, reg_info, arvif->ahvif->vdev_type, |
5853 | link_conf->power_type); | |
5854 | } | |
d8899132 | 5855 | |
c8a98ed1 S |
5856 | /* IEEE80211_STA_AUTHORIZED -> IEEE80211_STA_ASSOC: station may be in removal, |
5857 | * deauthorize it. | |
5858 | */ | |
d8899132 KV |
5859 | } else if (old_state == IEEE80211_STA_AUTHORIZED && |
5860 | new_state == IEEE80211_STA_ASSOC) { | |
c8a98ed1 | 5861 | ath12k_mac_station_unauthorize(ar, arvif, arsta); |
8e6f8bc2 | 5862 | |
c8a98ed1 S |
5863 | /* IEEE80211_STA_ASSOC -> IEEE80211_STA_AUTH: disassoc peer connected to |
5864 | * AP/mesh/ADHOC vif type. | |
5865 | */ | |
d8899132 KV |
5866 | } else if (old_state == IEEE80211_STA_ASSOC && |
5867 | new_state == IEEE80211_STA_AUTH && | |
5868 | (vif->type == NL80211_IFTYPE_AP || | |
5869 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
5870 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
c8a98ed1 | 5871 | ret = ath12k_mac_station_disassoc(ar, arvif, arsta); |
d8899132 | 5872 | if (ret) |
7ed3e886 | 5873 | ath12k_warn(ab, "Failed to disassociate station: %pM\n", |
061097e5 | 5874 | arsta->addr); |
d8899132 KV |
5875 | } |
5876 | ||
8e6f8bc2 | 5877 | exit: |
d8899132 KV |
5878 | return ret; |
5879 | } | |
5880 | ||
2296038f BQ |
5881 | static bool ath12k_mac_is_freq_on_mac(struct ath12k_hw_mode_freq_range_arg *freq_range, |
5882 | u32 freq, u8 mac_id) | |
5883 | { | |
5884 | return (freq >= freq_range[mac_id].low_2ghz_freq && | |
5885 | freq <= freq_range[mac_id].high_2ghz_freq) || | |
5886 | (freq >= freq_range[mac_id].low_5ghz_freq && | |
5887 | freq <= freq_range[mac_id].high_5ghz_freq); | |
5888 | } | |
5889 | ||
5890 | static bool | |
5891 | ath12k_mac_2_freq_same_mac_in_freq_range(struct ath12k_base *ab, | |
5892 | struct ath12k_hw_mode_freq_range_arg *freq_range, | |
5893 | u32 freq_link1, u32 freq_link2) | |
5894 | { | |
5895 | u8 i; | |
5896 | ||
5897 | for (i = 0; i < MAX_RADIOS; i++) { | |
5898 | if (ath12k_mac_is_freq_on_mac(freq_range, freq_link1, i) && | |
5899 | ath12k_mac_is_freq_on_mac(freq_range, freq_link2, i)) | |
5900 | return true; | |
5901 | } | |
5902 | ||
5903 | return false; | |
5904 | } | |
5905 | ||
5906 | static bool ath12k_mac_is_hw_dbs_capable(struct ath12k_base *ab) | |
5907 | { | |
5908 | return test_bit(WMI_TLV_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT, | |
5909 | ab->wmi_ab.svc_map) && | |
5910 | ab->wmi_ab.hw_mode_info.support_dbs; | |
5911 | } | |
5912 | ||
5913 | static bool ath12k_mac_2_freq_same_mac_in_dbs(struct ath12k_base *ab, | |
5914 | u32 freq_link1, u32 freq_link2) | |
5915 | { | |
5916 | struct ath12k_hw_mode_freq_range_arg *freq_range; | |
5917 | ||
5918 | if (!ath12k_mac_is_hw_dbs_capable(ab)) | |
5919 | return true; | |
5920 | ||
5921 | freq_range = ab->wmi_ab.hw_mode_info.freq_range_caps[ATH12K_HW_MODE_DBS]; | |
5922 | return ath12k_mac_2_freq_same_mac_in_freq_range(ab, freq_range, | |
5923 | freq_link1, freq_link2); | |
5924 | } | |
5925 | ||
5926 | static bool ath12k_mac_is_hw_sbs_capable(struct ath12k_base *ab) | |
5927 | { | |
5928 | return test_bit(WMI_TLV_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT, | |
5929 | ab->wmi_ab.svc_map) && | |
5930 | ab->wmi_ab.hw_mode_info.support_sbs; | |
5931 | } | |
5932 | ||
5933 | static bool ath12k_mac_2_freq_same_mac_in_sbs(struct ath12k_base *ab, | |
5934 | u32 freq_link1, u32 freq_link2) | |
5935 | { | |
5936 | struct ath12k_hw_mode_info *info = &ab->wmi_ab.hw_mode_info; | |
5937 | struct ath12k_hw_mode_freq_range_arg *sbs_uppr_share; | |
5938 | struct ath12k_hw_mode_freq_range_arg *sbs_low_share; | |
5939 | struct ath12k_hw_mode_freq_range_arg *sbs_range; | |
5940 | ||
5941 | if (!ath12k_mac_is_hw_sbs_capable(ab)) | |
5942 | return true; | |
5943 | ||
5944 | if (ab->wmi_ab.sbs_lower_band_end_freq) { | |
5945 | sbs_uppr_share = info->freq_range_caps[ATH12K_HW_MODE_SBS_UPPER_SHARE]; | |
5946 | sbs_low_share = info->freq_range_caps[ATH12K_HW_MODE_SBS_LOWER_SHARE]; | |
5947 | ||
5948 | return ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_low_share, | |
5949 | freq_link1, freq_link2) || | |
5950 | ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_uppr_share, | |
5951 | freq_link1, freq_link2); | |
5952 | } | |
5953 | ||
5954 | sbs_range = info->freq_range_caps[ATH12K_HW_MODE_SBS]; | |
5955 | return ath12k_mac_2_freq_same_mac_in_freq_range(ab, sbs_range, | |
5956 | freq_link1, freq_link2); | |
5957 | } | |
5958 | ||
5959 | static bool ath12k_mac_freqs_on_same_mac(struct ath12k_base *ab, | |
5960 | u32 freq_link1, u32 freq_link2) | |
5961 | { | |
5962 | return ath12k_mac_2_freq_same_mac_in_dbs(ab, freq_link1, freq_link2) && | |
5963 | ath12k_mac_2_freq_same_mac_in_sbs(ab, freq_link1, freq_link2); | |
5964 | } | |
5965 | ||
5966 | static int ath12k_mac_mlo_sta_set_link_active(struct ath12k_base *ab, | |
5967 | enum wmi_mlo_link_force_reason reason, | |
5968 | enum wmi_mlo_link_force_mode mode, | |
5969 | u8 *mlo_vdev_id_lst, | |
5970 | u8 num_mlo_vdev, | |
5971 | u8 *mlo_inactive_vdev_lst, | |
5972 | u8 num_mlo_inactive_vdev) | |
5973 | { | |
5974 | struct wmi_mlo_link_set_active_arg param = {0}; | |
5975 | u32 entry_idx, entry_offset, vdev_idx; | |
5976 | u8 vdev_id; | |
5977 | ||
5978 | param.reason = reason; | |
5979 | param.force_mode = mode; | |
5980 | ||
5981 | for (vdev_idx = 0; vdev_idx < num_mlo_vdev; vdev_idx++) { | |
5982 | vdev_id = mlo_vdev_id_lst[vdev_idx]; | |
5983 | entry_idx = vdev_id / 32; | |
5984 | entry_offset = vdev_id % 32; | |
5985 | if (entry_idx >= WMI_MLO_LINK_NUM_SZ) { | |
5986 | ath12k_warn(ab, "Invalid entry_idx %d num_mlo_vdev %d vdev %d", | |
5987 | entry_idx, num_mlo_vdev, vdev_id); | |
5988 | return -EINVAL; | |
5989 | } | |
5990 | param.vdev_bitmap[entry_idx] |= 1 << entry_offset; | |
5991 | /* update entry number if entry index changed */ | |
5992 | if (param.num_vdev_bitmap < entry_idx + 1) | |
5993 | param.num_vdev_bitmap = entry_idx + 1; | |
5994 | } | |
5995 | ||
5996 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5997 | "num_vdev_bitmap %d vdev_bitmap[0] = 0x%x, vdev_bitmap[1] = 0x%x", | |
5998 | param.num_vdev_bitmap, param.vdev_bitmap[0], param.vdev_bitmap[1]); | |
5999 | ||
6000 | if (mode == WMI_MLO_LINK_FORCE_MODE_ACTIVE_INACTIVE) { | |
6001 | for (vdev_idx = 0; vdev_idx < num_mlo_inactive_vdev; vdev_idx++) { | |
6002 | vdev_id = mlo_inactive_vdev_lst[vdev_idx]; | |
6003 | entry_idx = vdev_id / 32; | |
6004 | entry_offset = vdev_id % 32; | |
6005 | if (entry_idx >= WMI_MLO_LINK_NUM_SZ) { | |
6006 | ath12k_warn(ab, "Invalid entry_idx %d num_mlo_vdev %d vdev %d", | |
6007 | entry_idx, num_mlo_inactive_vdev, vdev_id); | |
6008 | return -EINVAL; | |
6009 | } | |
6010 | param.inactive_vdev_bitmap[entry_idx] |= 1 << entry_offset; | |
6011 | /* update entry number if entry index changed */ | |
6012 | if (param.num_inactive_vdev_bitmap < entry_idx + 1) | |
6013 | param.num_inactive_vdev_bitmap = entry_idx + 1; | |
6014 | } | |
6015 | ||
6016 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
6017 | "num_vdev_bitmap %d inactive_vdev_bitmap[0] = 0x%x, inactive_vdev_bitmap[1] = 0x%x", | |
6018 | param.num_inactive_vdev_bitmap, | |
6019 | param.inactive_vdev_bitmap[0], | |
6020 | param.inactive_vdev_bitmap[1]); | |
6021 | } | |
6022 | ||
6023 | if (mode == WMI_MLO_LINK_FORCE_MODE_ACTIVE_LINK_NUM || | |
6024 | mode == WMI_MLO_LINK_FORCE_MODE_INACTIVE_LINK_NUM) { | |
6025 | param.num_link_entry = 1; | |
6026 | param.link_num[0].num_of_link = num_mlo_vdev - 1; | |
6027 | } | |
6028 | ||
6029 | return ath12k_wmi_send_mlo_link_set_active_cmd(ab, ¶m); | |
6030 | } | |
6031 | ||
6032 | static int ath12k_mac_mlo_sta_update_link_active(struct ath12k_base *ab, | |
6033 | struct ieee80211_hw *hw, | |
6034 | struct ath12k_vif *ahvif) | |
6035 | { | |
6036 | u8 mlo_vdev_id_lst[IEEE80211_MLD_MAX_NUM_LINKS] = {0}; | |
6037 | u32 mlo_freq_list[IEEE80211_MLD_MAX_NUM_LINKS] = {0}; | |
6038 | unsigned long links = ahvif->links_map; | |
6039 | enum wmi_mlo_link_force_reason reason; | |
6040 | struct ieee80211_chanctx_conf *conf; | |
6041 | enum wmi_mlo_link_force_mode mode; | |
6042 | struct ieee80211_bss_conf *info; | |
6043 | struct ath12k_link_vif *arvif; | |
6044 | u8 num_mlo_vdev = 0; | |
6045 | u8 link_id; | |
6046 | ||
6047 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
6048 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
6049 | /* make sure vdev is created on this device */ | |
6050 | if (!arvif || !arvif->is_created || arvif->ar->ab != ab) | |
6051 | continue; | |
6052 | ||
6053 | info = ath12k_mac_get_link_bss_conf(arvif); | |
6054 | conf = wiphy_dereference(hw->wiphy, info->chanctx_conf); | |
6055 | mlo_freq_list[num_mlo_vdev] = conf->def.chan->center_freq; | |
6056 | ||
6057 | mlo_vdev_id_lst[num_mlo_vdev] = arvif->vdev_id; | |
6058 | num_mlo_vdev++; | |
6059 | } | |
6060 | ||
6061 | /* It is not allowed to activate more links than a single device | |
6062 | * supported. Something goes wrong if we reach here. | |
6063 | */ | |
6064 | if (num_mlo_vdev > ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE) { | |
6065 | WARN_ON_ONCE(1); | |
6066 | return -EINVAL; | |
6067 | } | |
6068 | ||
6069 | /* if 2 links are established and both link channels fall on the | |
6070 | * same hardware MAC, send command to firmware to deactivate one | |
6071 | * of them. | |
6072 | */ | |
6073 | if (num_mlo_vdev == 2 && | |
6074 | ath12k_mac_freqs_on_same_mac(ab, mlo_freq_list[0], | |
6075 | mlo_freq_list[1])) { | |
6076 | mode = WMI_MLO_LINK_FORCE_MODE_INACTIVE_LINK_NUM; | |
6077 | reason = WMI_MLO_LINK_FORCE_REASON_NEW_CONNECT; | |
6078 | return ath12k_mac_mlo_sta_set_link_active(ab, reason, mode, | |
6079 | mlo_vdev_id_lst, num_mlo_vdev, | |
6080 | NULL, 0); | |
6081 | } | |
6082 | ||
6083 | return 0; | |
6084 | } | |
6085 | ||
d9dbc6b8 BQ |
6086 | static bool ath12k_mac_are_sbs_chan(struct ath12k_base *ab, u32 freq_1, u32 freq_2) |
6087 | { | |
6088 | if (!ath12k_mac_is_hw_sbs_capable(ab)) | |
6089 | return false; | |
6090 | ||
6091 | if (ath12k_is_2ghz_channel_freq(freq_1) || | |
6092 | ath12k_is_2ghz_channel_freq(freq_2)) | |
6093 | return false; | |
6094 | ||
6095 | return !ath12k_mac_2_freq_same_mac_in_sbs(ab, freq_1, freq_2); | |
6096 | } | |
6097 | ||
6098 | static bool ath12k_mac_are_dbs_chan(struct ath12k_base *ab, u32 freq_1, u32 freq_2) | |
6099 | { | |
6100 | if (!ath12k_mac_is_hw_dbs_capable(ab)) | |
6101 | return false; | |
6102 | ||
6103 | return !ath12k_mac_2_freq_same_mac_in_dbs(ab, freq_1, freq_2); | |
6104 | } | |
6105 | ||
6106 | static int ath12k_mac_select_links(struct ath12k_base *ab, | |
6107 | struct ieee80211_vif *vif, | |
6108 | struct ieee80211_hw *hw, | |
6109 | u16 *selected_links) | |
6110 | { | |
6111 | unsigned long useful_links = ieee80211_vif_usable_links(vif); | |
6112 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
6113 | u8 num_useful_links = hweight_long(useful_links); | |
6114 | struct ieee80211_chanctx_conf *chanctx; | |
6115 | struct ath12k_link_vif *assoc_arvif; | |
6116 | u32 assoc_link_freq, partner_freq; | |
6117 | u16 sbs_links = 0, dbs_links = 0; | |
6118 | struct ieee80211_bss_conf *info; | |
6119 | struct ieee80211_channel *chan; | |
6120 | struct ieee80211_sta *sta; | |
6121 | struct ath12k_sta *ahsta; | |
6122 | u8 link_id; | |
6123 | ||
6124 | /* activate all useful links if less than max supported */ | |
6125 | if (num_useful_links <= ATH12K_NUM_MAX_ACTIVE_LINKS_PER_DEVICE) { | |
6126 | *selected_links = useful_links; | |
6127 | return 0; | |
6128 | } | |
6129 | ||
6130 | /* only in station mode we can get here, so it's safe | |
6131 | * to use ap_addr | |
6132 | */ | |
6133 | rcu_read_lock(); | |
6134 | sta = ieee80211_find_sta(vif, vif->cfg.ap_addr); | |
6135 | if (!sta) { | |
6136 | rcu_read_unlock(); | |
6137 | ath12k_warn(ab, "failed to find sta with addr %pM\n", vif->cfg.ap_addr); | |
6138 | return -EINVAL; | |
6139 | } | |
6140 | ||
6141 | ahsta = ath12k_sta_to_ahsta(sta); | |
6142 | assoc_arvif = wiphy_dereference(hw->wiphy, ahvif->link[ahsta->assoc_link_id]); | |
6143 | info = ath12k_mac_get_link_bss_conf(assoc_arvif); | |
6144 | chanctx = rcu_dereference(info->chanctx_conf); | |
6145 | assoc_link_freq = chanctx->def.chan->center_freq; | |
6146 | rcu_read_unlock(); | |
6147 | ath12k_dbg(ab, ATH12K_DBG_MAC, "assoc link %u freq %u\n", | |
6148 | assoc_arvif->link_id, assoc_link_freq); | |
6149 | ||
6150 | /* assoc link is already activated and has to be kept active, | |
6151 | * only need to select a partner link from others. | |
6152 | */ | |
6153 | useful_links &= ~BIT(assoc_arvif->link_id); | |
6154 | for_each_set_bit(link_id, &useful_links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
6155 | info = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]); | |
6156 | if (!info) { | |
6157 | ath12k_warn(ab, "failed to get link info for link: %u\n", | |
6158 | link_id); | |
6159 | return -ENOLINK; | |
6160 | } | |
6161 | ||
6162 | chan = info->chanreq.oper.chan; | |
6163 | if (!chan) { | |
6164 | ath12k_warn(ab, "failed to get chan for link: %u\n", link_id); | |
6165 | return -EINVAL; | |
6166 | } | |
6167 | ||
6168 | partner_freq = chan->center_freq; | |
6169 | if (ath12k_mac_are_sbs_chan(ab, assoc_link_freq, partner_freq)) { | |
6170 | sbs_links |= BIT(link_id); | |
6171 | ath12k_dbg(ab, ATH12K_DBG_MAC, "new SBS link %u freq %u\n", | |
6172 | link_id, partner_freq); | |
6173 | continue; | |
6174 | } | |
6175 | ||
6176 | if (ath12k_mac_are_dbs_chan(ab, assoc_link_freq, partner_freq)) { | |
6177 | dbs_links |= BIT(link_id); | |
6178 | ath12k_dbg(ab, ATH12K_DBG_MAC, "new DBS link %u freq %u\n", | |
6179 | link_id, partner_freq); | |
6180 | continue; | |
6181 | } | |
6182 | ||
6183 | ath12k_dbg(ab, ATH12K_DBG_MAC, "non DBS/SBS link %u freq %u\n", | |
6184 | link_id, partner_freq); | |
6185 | } | |
6186 | ||
6187 | /* choose the first candidate no matter how many is in the list */ | |
6188 | if (sbs_links) | |
6189 | link_id = __ffs(sbs_links); | |
6190 | else if (dbs_links) | |
6191 | link_id = __ffs(dbs_links); | |
6192 | else | |
6193 | link_id = ffs(useful_links) - 1; | |
6194 | ||
6195 | ath12k_dbg(ab, ATH12K_DBG_MAC, "select partner link %u\n", link_id); | |
6196 | ||
6197 | *selected_links = BIT(assoc_arvif->link_id) | BIT(link_id); | |
6198 | ||
6199 | return 0; | |
6200 | } | |
6201 | ||
c8a98ed1 S |
6202 | static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, |
6203 | struct ieee80211_vif *vif, | |
6204 | struct ieee80211_sta *sta, | |
6205 | enum ieee80211_sta_state old_state, | |
6206 | enum ieee80211_sta_state new_state) | |
6207 | { | |
6208 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
6209 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); | |
8e6f8bc2 | 6210 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
2296038f | 6211 | struct ath12k_base *prev_ab = NULL, *ab; |
c8a98ed1 S |
6212 | struct ath12k_link_vif *arvif; |
6213 | struct ath12k_link_sta *arsta; | |
8e6f8bc2 | 6214 | unsigned long valid_links; |
d9dbc6b8 | 6215 | u16 selected_links = 0; |
2296038f BQ |
6216 | u8 link_id = 0, i; |
6217 | struct ath12k *ar; | |
8e6f8bc2 | 6218 | int ret; |
c8a98ed1 S |
6219 | |
6220 | lockdep_assert_wiphy(hw->wiphy); | |
6221 | ||
6222 | if (ieee80211_vif_is_mld(vif) && sta->valid_links) { | |
6223 | WARN_ON(!sta->mlo && hweight16(sta->valid_links) != 1); | |
6224 | link_id = ffs(sta->valid_links) - 1; | |
6225 | } | |
6226 | ||
8e6f8bc2 S |
6227 | /* IEEE80211_STA_NOTEXIST -> IEEE80211_STA_NONE: |
6228 | * New station add received. If this is a ML station then | |
6229 | * ahsta->links_map will be zero and sta->valid_links will be 1. | |
6230 | * Assign default link to the first link sta. | |
6231 | */ | |
6232 | if (old_state == IEEE80211_STA_NOTEXIST && | |
6233 | new_state == IEEE80211_STA_NONE) { | |
6234 | memset(ahsta, 0, sizeof(*ahsta)); | |
6235 | ||
c8a98ed1 | 6236 | arsta = &ahsta->deflink; |
c8a98ed1 | 6237 | |
8e6f8bc2 S |
6238 | /* ML sta */ |
6239 | if (sta->mlo && !ahsta->links_map && | |
6240 | (hweight16(sta->valid_links) == 1)) { | |
6241 | ret = ath12k_peer_ml_create(ah, sta); | |
6242 | if (ret) { | |
6243 | ath12k_hw_warn(ah, "unable to create ML peer for sta %pM", | |
6244 | sta->addr); | |
6245 | goto exit; | |
6246 | } | |
c8a98ed1 S |
6247 | } |
6248 | ||
8e6f8bc2 S |
6249 | ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, |
6250 | link_id); | |
6251 | if (ret) { | |
6252 | ath12k_hw_warn(ah, "unable assign link %d for sta %pM", | |
6253 | link_id, sta->addr); | |
c8a98ed1 S |
6254 | goto exit; |
6255 | } | |
6256 | ||
8e6f8bc2 S |
6257 | /* above arsta will get memset, hence do this after assign |
6258 | * link sta | |
6259 | */ | |
6260 | if (sta->mlo) { | |
0cd46d1f BQ |
6261 | /* For station mode, arvif->is_sta_assoc_link has been set when |
6262 | * vdev starts. Make sure the arvif/arsta pair have same setting | |
6263 | */ | |
6264 | if (vif->type == NL80211_IFTYPE_STATION && | |
6265 | !arsta->arvif->is_sta_assoc_link) { | |
6266 | ath12k_hw_warn(ah, "failed to verify assoc link setting with link id %u\n", | |
6267 | link_id); | |
6268 | ret = -EINVAL; | |
6269 | goto exit; | |
6270 | } | |
6271 | ||
8e6f8bc2 S |
6272 | arsta->is_assoc_link = true; |
6273 | ahsta->assoc_link_id = link_id; | |
6274 | } | |
6275 | } | |
6276 | ||
6792b3ca AKS |
6277 | /* In the ML station scenario, activate all partner links once the |
6278 | * client is transitioning to the associated state. | |
6279 | * | |
6280 | * FIXME: Ideally, this activation should occur when the client | |
6281 | * transitions to the authorized state. However, there are some | |
6282 | * issues with handling this in the firmware. Until the firmware | |
6283 | * can manage it properly, activate the links when the client is | |
6284 | * about to move to the associated state. | |
6285 | */ | |
6286 | if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION && | |
d9dbc6b8 BQ |
6287 | old_state == IEEE80211_STA_AUTH && new_state == IEEE80211_STA_ASSOC) { |
6288 | /* TODO: for now only do link selection for single device | |
6289 | * MLO case. Other cases would be handled in the future. | |
6290 | */ | |
6291 | ab = ah->radio[0].ab; | |
6292 | if (ab->ag->num_devices == 1) { | |
6293 | ret = ath12k_mac_select_links(ab, vif, hw, &selected_links); | |
6294 | if (ret) { | |
6295 | ath12k_warn(ab, | |
6296 | "failed to get selected links: %d\n", ret); | |
6297 | goto exit; | |
6298 | } | |
6299 | } else { | |
6300 | selected_links = ieee80211_vif_usable_links(vif); | |
6301 | } | |
6302 | ||
6303 | ieee80211_set_active_links(vif, selected_links); | |
6304 | } | |
6792b3ca | 6305 | |
8e6f8bc2 S |
6306 | /* Handle all the other state transitions in generic way */ |
6307 | valid_links = ahsta->links_map; | |
6308 | for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
6309 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
6310 | arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]); | |
6311 | /* some assumptions went wrong! */ | |
6312 | if (WARN_ON(!arvif || !arsta)) | |
6313 | continue; | |
6314 | ||
6315 | /* vdev might be in deleted */ | |
6316 | if (WARN_ON(!arvif->ar)) | |
6317 | continue; | |
6318 | ||
c8a98ed1 S |
6319 | ret = ath12k_mac_handle_link_sta_state(hw, arvif, arsta, |
6320 | old_state, new_state); | |
8e6f8bc2 S |
6321 | if (ret) { |
6322 | ath12k_hw_warn(ah, "unable to move link sta %d of sta %pM from state %d to %d", | |
6323 | link_id, arsta->addr, old_state, new_state); | |
c8a98ed1 | 6324 | goto exit; |
8e6f8bc2 | 6325 | } |
c8a98ed1 S |
6326 | } |
6327 | ||
2296038f BQ |
6328 | if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION && |
6329 | old_state == IEEE80211_STA_ASSOC && new_state == IEEE80211_STA_AUTHORIZED) { | |
6330 | for_each_ar(ah, ar, i) { | |
6331 | ab = ar->ab; | |
6332 | if (prev_ab == ab) | |
6333 | continue; | |
6334 | ||
6335 | ret = ath12k_mac_mlo_sta_update_link_active(ab, hw, ahvif); | |
6336 | if (ret) { | |
6337 | ath12k_warn(ab, | |
6338 | "failed to update link active state on connect %d\n", | |
6339 | ret); | |
6340 | goto exit; | |
6341 | } | |
6342 | ||
6343 | prev_ab = ab; | |
6344 | } | |
6345 | } | |
8e6f8bc2 S |
6346 | /* IEEE80211_STA_NONE -> IEEE80211_STA_NOTEXIST: |
6347 | * Remove the station from driver (handle ML sta here since that | |
6348 | * needs special handling. Normal sta will be handled in generic | |
6349 | * handler below | |
6350 | */ | |
6351 | if (old_state == IEEE80211_STA_NONE && | |
6352 | new_state == IEEE80211_STA_NOTEXIST && sta->mlo) | |
6353 | ath12k_mac_ml_station_remove(ahvif, ahsta); | |
6354 | ||
c8a98ed1 S |
6355 | ret = 0; |
6356 | ||
6357 | exit: | |
8e6f8bc2 S |
6358 | /* update the state if everything went well */ |
6359 | if (!ret) | |
6360 | ahsta->state = new_state; | |
6361 | ||
c8a98ed1 S |
6362 | return ret; |
6363 | } | |
6364 | ||
d8899132 KV |
6365 | static int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw, |
6366 | struct ieee80211_vif *vif, | |
6367 | struct ieee80211_sta *sta) | |
6368 | { | |
061097e5 | 6369 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
6db6e70a | 6370 | struct ath12k *ar; |
3dd2c68f S |
6371 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
6372 | struct ath12k_link_vif *arvif; | |
061097e5 S |
6373 | struct ath12k_link_sta *arsta; |
6374 | u8 link_id; | |
d8899132 KV |
6375 | int ret; |
6376 | s16 txpwr; | |
6377 | ||
c347f181 KV |
6378 | lockdep_assert_wiphy(hw->wiphy); |
6379 | ||
061097e5 S |
6380 | /* TODO: use link id from mac80211 once that's implemented */ |
6381 | link_id = 0; | |
6382 | ||
6383 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
6384 | arsta = wiphy_dereference(hw->wiphy, ahsta->link[link_id]); | |
3dd2c68f | 6385 | |
d8899132 KV |
6386 | if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) { |
6387 | txpwr = 0; | |
6388 | } else { | |
6389 | txpwr = sta->deflink.txpwr.power; | |
3dd2c68f S |
6390 | if (!txpwr) { |
6391 | ret = -EINVAL; | |
6392 | goto out; | |
6393 | } | |
d8899132 KV |
6394 | } |
6395 | ||
3dd2c68f S |
6396 | if (txpwr > ATH12K_TX_POWER_MAX_VAL || txpwr < ATH12K_TX_POWER_MIN_VAL) { |
6397 | ret = -EINVAL; | |
6398 | goto out; | |
6399 | } | |
d8899132 | 6400 | |
061097e5 | 6401 | ar = arvif->ar; |
6db6e70a | 6402 | |
061097e5 | 6403 | ret = ath12k_wmi_set_peer_param(ar, arsta->addr, arvif->vdev_id, |
d8899132 KV |
6404 | WMI_PEER_USE_FIXED_PWR, txpwr); |
6405 | if (ret) { | |
6406 | ath12k_warn(ar->ab, "failed to set tx power for station ret: %d\n", | |
6407 | ret); | |
6408 | goto out; | |
6409 | } | |
6410 | ||
6411 | out: | |
d8899132 KV |
6412 | return ret; |
6413 | } | |
6414 | ||
8c214370 KV |
6415 | static void ath12k_mac_op_link_sta_rc_update(struct ieee80211_hw *hw, |
6416 | struct ieee80211_vif *vif, | |
6417 | struct ieee80211_link_sta *link_sta, | |
6418 | u32 changed) | |
d8899132 | 6419 | { |
88b67e91 | 6420 | struct ieee80211_sta *sta = link_sta->sta; |
6db6e70a | 6421 | struct ath12k *ar; |
b89b5dbe | 6422 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
3dd2c68f | 6423 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
5419ef95 | 6424 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
b89b5dbe | 6425 | struct ath12k_link_sta *arsta; |
3dd2c68f | 6426 | struct ath12k_link_vif *arvif; |
d8899132 KV |
6427 | struct ath12k_peer *peer; |
6428 | u32 bw, smps; | |
6429 | ||
3dd2c68f | 6430 | rcu_read_lock(); |
8c214370 | 6431 | arvif = rcu_dereference(ahvif->link[link_sta->link_id]); |
3dd2c68f | 6432 | if (!arvif) { |
5419ef95 | 6433 | ath12k_hw_warn(ah, "mac sta rc update failed to fetch link vif on link id %u for peer %pM\n", |
8c214370 | 6434 | link_sta->link_id, sta->addr); |
3dd2c68f S |
6435 | rcu_read_unlock(); |
6436 | return; | |
6437 | } | |
5419ef95 S |
6438 | |
6439 | ar = arvif->ar; | |
6440 | ||
8c214370 | 6441 | arsta = rcu_dereference(ahsta->link[link_sta->link_id]); |
b89b5dbe S |
6442 | if (!arsta) { |
6443 | rcu_read_unlock(); | |
6444 | ath12k_warn(ar->ab, "mac sta rc update failed to fetch link sta on link id %u for peer %pM\n", | |
8c214370 | 6445 | link_sta->link_id, sta->addr); |
b89b5dbe S |
6446 | return; |
6447 | } | |
d8899132 KV |
6448 | spin_lock_bh(&ar->ab->base_lock); |
6449 | ||
061097e5 | 6450 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arsta->addr); |
d8899132 KV |
6451 | if (!peer) { |
6452 | spin_unlock_bh(&ar->ab->base_lock); | |
3dd2c68f | 6453 | rcu_read_unlock(); |
d8899132 | 6454 | ath12k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n", |
061097e5 | 6455 | arsta->addr, arvif->vdev_id); |
d8899132 KV |
6456 | return; |
6457 | } | |
6458 | ||
6459 | spin_unlock_bh(&ar->ab->base_lock); | |
6460 | ||
63fdb906 S |
6461 | if (arsta->link_id >= IEEE80211_MLD_MAX_NUM_LINKS) { |
6462 | rcu_read_unlock(); | |
6463 | return; | |
6464 | } | |
6465 | ||
6466 | link_sta = rcu_dereference(sta->link[arsta->link_id]); | |
6467 | if (!link_sta) { | |
6468 | rcu_read_unlock(); | |
6469 | ath12k_warn(ar->ab, "unable to access link sta in rc update for sta %pM link %u\n", | |
6470 | sta->addr, arsta->link_id); | |
6471 | return; | |
6472 | } | |
6473 | ||
d8899132 KV |
6474 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
6475 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", | |
63fdb906 S |
6476 | arsta->addr, changed, link_sta->bandwidth, link_sta->rx_nss, |
6477 | link_sta->smps_mode); | |
d8899132 KV |
6478 | |
6479 | spin_lock_bh(&ar->data_lock); | |
6480 | ||
6481 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
2fc98b24 | 6482 | bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, link_sta); |
cbc0008c | 6483 | arsta->bw_prev = arsta->bw; |
d8899132 KV |
6484 | arsta->bw = bw; |
6485 | } | |
6486 | ||
6487 | if (changed & IEEE80211_RC_NSS_CHANGED) | |
63fdb906 | 6488 | arsta->nss = link_sta->rx_nss; |
d8899132 KV |
6489 | |
6490 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
6491 | smps = WMI_PEER_SMPS_PS_NONE; | |
6492 | ||
63fdb906 | 6493 | switch (link_sta->smps_mode) { |
d8899132 KV |
6494 | case IEEE80211_SMPS_AUTOMATIC: |
6495 | case IEEE80211_SMPS_OFF: | |
6496 | smps = WMI_PEER_SMPS_PS_NONE; | |
6497 | break; | |
6498 | case IEEE80211_SMPS_STATIC: | |
6499 | smps = WMI_PEER_SMPS_STATIC; | |
6500 | break; | |
6501 | case IEEE80211_SMPS_DYNAMIC: | |
6502 | smps = WMI_PEER_SMPS_DYNAMIC; | |
6503 | break; | |
6504 | default: | |
63fdb906 S |
6505 | ath12k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM link %u\n", |
6506 | link_sta->smps_mode, arsta->addr, link_sta->link_id); | |
d8899132 KV |
6507 | smps = WMI_PEER_SMPS_PS_NONE; |
6508 | break; | |
6509 | } | |
6510 | ||
6511 | arsta->smps = smps; | |
6512 | } | |
6513 | ||
6514 | arsta->changed |= changed; | |
6515 | ||
6516 | spin_unlock_bh(&ar->data_lock); | |
6517 | ||
58550cdd | 6518 | wiphy_work_queue(hw->wiphy, &arsta->update_wk); |
3dd2c68f S |
6519 | |
6520 | rcu_read_unlock(); | |
d8899132 KV |
6521 | } |
6522 | ||
a27fa614 S |
6523 | static struct ath12k_link_sta *ath12k_mac_alloc_assign_link_sta(struct ath12k_hw *ah, |
6524 | struct ath12k_sta *ahsta, | |
6525 | struct ath12k_vif *ahvif, | |
6526 | u8 link_id) | |
6527 | { | |
6528 | struct ath12k_link_sta *arsta; | |
6529 | int ret; | |
6530 | ||
6531 | lockdep_assert_wiphy(ah->hw->wiphy); | |
6532 | ||
6533 | if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) | |
6534 | return NULL; | |
6535 | ||
6536 | arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]); | |
6537 | if (arsta) | |
6538 | return NULL; | |
6539 | ||
6540 | arsta = kmalloc(sizeof(*arsta), GFP_KERNEL); | |
6541 | if (!arsta) | |
6542 | return NULL; | |
6543 | ||
6544 | ret = ath12k_mac_assign_link_sta(ah, ahsta, arsta, ahvif, link_id); | |
6545 | if (ret) { | |
6546 | kfree(arsta); | |
6547 | return NULL; | |
6548 | } | |
6549 | ||
6550 | return arsta; | |
6551 | } | |
6552 | ||
6553 | static int ath12k_mac_op_change_sta_links(struct ieee80211_hw *hw, | |
6554 | struct ieee80211_vif *vif, | |
6555 | struct ieee80211_sta *sta, | |
6556 | u16 old_links, u16 new_links) | |
6557 | { | |
6558 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
6559 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); | |
6560 | struct ath12k_hw *ah = hw->priv; | |
6561 | struct ath12k_link_vif *arvif; | |
6562 | struct ath12k_link_sta *arsta; | |
6563 | unsigned long valid_links; | |
6564 | struct ath12k *ar; | |
6565 | u8 link_id; | |
6566 | int ret; | |
6567 | ||
6568 | lockdep_assert_wiphy(hw->wiphy); | |
6569 | ||
6570 | if (!sta->valid_links) | |
6571 | return -EINVAL; | |
6572 | ||
6573 | /* Firmware does not support removal of one of link stas. All sta | |
6574 | * would be removed during ML STA delete in sta_state(), hence link | |
6575 | * sta removal is not handled here. | |
6576 | */ | |
6577 | if (new_links < old_links) | |
6578 | return 0; | |
6579 | ||
6580 | if (ahsta->ml_peer_id == ATH12K_MLO_PEER_ID_INVALID) { | |
6581 | ath12k_hw_warn(ah, "unable to add link for ml sta %pM", sta->addr); | |
6582 | return -EINVAL; | |
6583 | } | |
6584 | ||
6585 | /* this op is expected only after initial sta insertion with default link */ | |
6586 | if (WARN_ON(ahsta->links_map == 0)) | |
6587 | return -EINVAL; | |
6588 | ||
6589 | valid_links = new_links; | |
6590 | for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
6591 | if (ahsta->links_map & BIT(link_id)) | |
6592 | continue; | |
6593 | ||
6594 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
6595 | arsta = ath12k_mac_alloc_assign_link_sta(ah, ahsta, ahvif, link_id); | |
6596 | ||
6597 | if (!arvif || !arsta) { | |
6598 | ath12k_hw_warn(ah, "Failed to alloc/assign link sta"); | |
6599 | continue; | |
6600 | } | |
6601 | ||
6602 | ar = arvif->ar; | |
6603 | if (!ar) | |
6604 | continue; | |
6605 | ||
6606 | ret = ath12k_mac_station_add(ar, arvif, arsta); | |
6607 | if (ret) { | |
6608 | ath12k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n", | |
6609 | arsta->addr, arvif->vdev_id); | |
6610 | ath12k_mac_free_unassign_link_sta(ah, ahsta, link_id); | |
6611 | return ret; | |
6612 | } | |
6613 | } | |
6614 | ||
6615 | return 0; | |
6616 | } | |
6617 | ||
6792b3ca AKS |
6618 | static bool ath12k_mac_op_can_activate_links(struct ieee80211_hw *hw, |
6619 | struct ieee80211_vif *vif, | |
6620 | u16 active_links) | |
6621 | { | |
6622 | /* TODO: Handle recovery case */ | |
6623 | ||
6624 | return true; | |
6625 | } | |
6626 | ||
3dd2c68f | 6627 | static int ath12k_conf_tx_uapsd(struct ath12k_link_vif *arvif, |
d8899132 KV |
6628 | u16 ac, bool enable) |
6629 | { | |
00c9b1a6 | 6630 | struct ath12k *ar = arvif->ar; |
3dd2c68f | 6631 | struct ath12k_vif *ahvif = arvif->ahvif; |
d8899132 KV |
6632 | u32 value; |
6633 | int ret; | |
6634 | ||
3dd2c68f | 6635 | if (ahvif->vdev_type != WMI_VDEV_TYPE_STA) |
d8899132 KV |
6636 | return 0; |
6637 | ||
6638 | switch (ac) { | |
6639 | case IEEE80211_AC_VO: | |
6640 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | | |
6641 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; | |
6642 | break; | |
6643 | case IEEE80211_AC_VI: | |
6644 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | | |
6645 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; | |
6646 | break; | |
6647 | case IEEE80211_AC_BE: | |
6648 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | | |
6649 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; | |
6650 | break; | |
6651 | case IEEE80211_AC_BK: | |
6652 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | | |
6653 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; | |
6654 | break; | |
6655 | } | |
6656 | ||
6657 | if (enable) | |
3dd2c68f | 6658 | ahvif->u.sta.uapsd |= value; |
d8899132 | 6659 | else |
3dd2c68f | 6660 | ahvif->u.sta.uapsd &= ~value; |
d8899132 KV |
6661 | |
6662 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
6663 | WMI_STA_PS_PARAM_UAPSD, | |
3dd2c68f | 6664 | ahvif->u.sta.uapsd); |
d8899132 KV |
6665 | if (ret) { |
6666 | ath12k_warn(ar->ab, "could not set uapsd params %d\n", ret); | |
6667 | goto exit; | |
6668 | } | |
6669 | ||
3dd2c68f | 6670 | if (ahvif->u.sta.uapsd) |
d8899132 KV |
6671 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
6672 | else | |
6673 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
6674 | ||
6675 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
6676 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, | |
6677 | value); | |
6678 | if (ret) | |
6679 | ath12k_warn(ar->ab, "could not set rx wake param %d\n", ret); | |
6680 | ||
6681 | exit: | |
6682 | return ret; | |
6683 | } | |
6684 | ||
af41f908 | 6685 | static int ath12k_mac_conf_tx(struct ath12k_link_vif *arvif, u16 ac, |
00c9b1a6 | 6686 | const struct ieee80211_tx_queue_params *params) |
d8899132 | 6687 | { |
d8899132 | 6688 | struct wmi_wmm_params_arg *p = NULL; |
00c9b1a6 KP |
6689 | struct ath12k *ar = arvif->ar; |
6690 | struct ath12k_base *ab = ar->ab; | |
d8899132 KV |
6691 | int ret; |
6692 | ||
b8c67509 | 6693 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
6694 | |
6695 | switch (ac) { | |
6696 | case IEEE80211_AC_VO: | |
6697 | p = &arvif->wmm_params.ac_vo; | |
6698 | break; | |
6699 | case IEEE80211_AC_VI: | |
6700 | p = &arvif->wmm_params.ac_vi; | |
6701 | break; | |
6702 | case IEEE80211_AC_BE: | |
6703 | p = &arvif->wmm_params.ac_be; | |
6704 | break; | |
6705 | case IEEE80211_AC_BK: | |
6706 | p = &arvif->wmm_params.ac_bk; | |
6707 | break; | |
6708 | } | |
6709 | ||
6710 | if (WARN_ON(!p)) { | |
6711 | ret = -EINVAL; | |
6712 | goto exit; | |
6713 | } | |
6714 | ||
6715 | p->cwmin = params->cw_min; | |
6716 | p->cwmax = params->cw_max; | |
6717 | p->aifs = params->aifs; | |
6718 | p->txop = params->txop; | |
6719 | ||
6720 | ret = ath12k_wmi_send_wmm_update_cmd(ar, arvif->vdev_id, | |
6721 | &arvif->wmm_params); | |
6722 | if (ret) { | |
00c9b1a6 KP |
6723 | ath12k_warn(ab, "pdev idx %d failed to set wmm params: %d\n", |
6724 | ar->pdev_idx, ret); | |
d8899132 KV |
6725 | goto exit; |
6726 | } | |
6727 | ||
00c9b1a6 | 6728 | ret = ath12k_conf_tx_uapsd(arvif, ac, params->uapsd); |
d8899132 | 6729 | if (ret) |
00c9b1a6 KP |
6730 | ath12k_warn(ab, "pdev idx %d failed to set sta uapsd: %d\n", |
6731 | ar->pdev_idx, ret); | |
d8899132 KV |
6732 | |
6733 | exit: | |
00c9b1a6 KP |
6734 | return ret; |
6735 | } | |
6736 | ||
6737 | static int ath12k_mac_op_conf_tx(struct ieee80211_hw *hw, | |
6738 | struct ieee80211_vif *vif, | |
6739 | unsigned int link_id, u16 ac, | |
6740 | const struct ieee80211_tx_queue_params *params) | |
6741 | { | |
3dd2c68f S |
6742 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
6743 | struct ath12k_link_vif *arvif; | |
6744 | struct ath12k_vif_cache *cache; | |
00c9b1a6 KP |
6745 | int ret; |
6746 | ||
b8c67509 KV |
6747 | lockdep_assert_wiphy(hw->wiphy); |
6748 | ||
af41f908 S |
6749 | if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) |
6750 | return -EINVAL; | |
6751 | ||
6752 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
6753 | if (!arvif || !arvif->is_created) { | |
6754 | cache = ath12k_ahvif_get_link_cache(ahvif, link_id); | |
b5068bc9 S |
6755 | if (!cache) |
6756 | return -ENOSPC; | |
3dd2c68f | 6757 | |
b5068bc9 S |
6758 | cache->tx_conf.changed = true; |
6759 | cache->tx_conf.ac = ac; | |
6760 | cache->tx_conf.tx_queue_params = *params; | |
3dd2c68f | 6761 | |
b5068bc9 | 6762 | return 0; |
0148e40c | 6763 | } |
6db6e70a | 6764 | |
af41f908 | 6765 | ret = ath12k_mac_conf_tx(arvif, ac, params); |
00c9b1a6 | 6766 | |
d8899132 KV |
6767 | return ret; |
6768 | } | |
6769 | ||
6770 | static struct ieee80211_sta_ht_cap | |
6771 | ath12k_create_ht_cap(struct ath12k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask) | |
6772 | { | |
6773 | int i; | |
6774 | struct ieee80211_sta_ht_cap ht_cap = {0}; | |
6775 | u32 ar_vht_cap = ar->pdev->cap.vht_cap; | |
6776 | ||
6777 | if (!(ar_ht_cap & WMI_HT_CAP_ENABLED)) | |
6778 | return ht_cap; | |
6779 | ||
6780 | ht_cap.ht_supported = 1; | |
6781 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
6782 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; | |
6783 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
6784 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
6785 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; | |
6786 | ||
6787 | if (ar_ht_cap & WMI_HT_CAP_HT20_SGI) | |
6788 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
6789 | ||
6790 | if (ar_ht_cap & WMI_HT_CAP_HT40_SGI) | |
6791 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
6792 | ||
6793 | if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) { | |
6794 | u32 smps; | |
6795 | ||
6796 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | |
6797 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
6798 | ||
6799 | ht_cap.cap |= smps; | |
6800 | } | |
6801 | ||
6802 | if (ar_ht_cap & WMI_HT_CAP_TX_STBC) | |
6803 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; | |
6804 | ||
6805 | if (ar_ht_cap & WMI_HT_CAP_RX_STBC) { | |
6806 | u32 stbc; | |
6807 | ||
6808 | stbc = ar_ht_cap; | |
6809 | stbc &= WMI_HT_CAP_RX_STBC; | |
6810 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; | |
6811 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
6812 | stbc &= IEEE80211_HT_CAP_RX_STBC; | |
6813 | ||
6814 | ht_cap.cap |= stbc; | |
6815 | } | |
6816 | ||
6817 | if (ar_ht_cap & WMI_HT_CAP_RX_LDPC) | |
6818 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; | |
6819 | ||
6820 | if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT) | |
6821 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; | |
6822 | ||
6823 | if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) | |
6824 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; | |
6825 | ||
6826 | for (i = 0; i < ar->num_rx_chains; i++) { | |
6827 | if (rate_cap_rx_chainmask & BIT(i)) | |
6828 | ht_cap.mcs.rx_mask[i] = 0xFF; | |
6829 | } | |
6830 | ||
6831 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; | |
6832 | ||
6833 | return ht_cap; | |
6834 | } | |
6835 | ||
3dd2c68f | 6836 | static int ath12k_mac_set_txbf_conf(struct ath12k_link_vif *arvif) |
d8899132 KV |
6837 | { |
6838 | u32 value = 0; | |
6839 | struct ath12k *ar = arvif->ar; | |
3dd2c68f | 6840 | struct ath12k_vif *ahvif = arvif->ahvif; |
d8899132 KV |
6841 | int nsts; |
6842 | int sound_dim; | |
6843 | u32 vht_cap = ar->pdev->cap.vht_cap; | |
6844 | u32 vdev_param = WMI_VDEV_PARAM_TXBF; | |
6845 | ||
6846 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) { | |
6847 | nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
6848 | nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
6849 | value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); | |
6850 | } | |
6851 | ||
6852 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { | |
6853 | sound_dim = vht_cap & | |
6854 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
6855 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
6856 | if (sound_dim > (ar->num_tx_chains - 1)) | |
6857 | sound_dim = ar->num_tx_chains - 1; | |
6858 | value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); | |
6859 | } | |
6860 | ||
6861 | if (!value) | |
6862 | return 0; | |
6863 | ||
6864 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) { | |
6865 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
6866 | ||
6867 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && | |
3dd2c68f | 6868 | ahvif->vdev_type == WMI_VDEV_TYPE_AP) |
d8899132 KV |
6869 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; |
6870 | } | |
6871 | ||
6872 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) { | |
6873 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
6874 | ||
6875 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && | |
3dd2c68f | 6876 | ahvif->vdev_type == WMI_VDEV_TYPE_STA) |
d8899132 KV |
6877 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; |
6878 | } | |
6879 | ||
6880 | return ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
6881 | vdev_param, value); | |
6882 | } | |
6883 | ||
6884 | static void ath12k_set_vht_txbf_cap(struct ath12k *ar, u32 *vht_cap) | |
6885 | { | |
6886 | bool subfer, subfee; | |
6887 | int sound_dim = 0; | |
6888 | ||
6889 | subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)); | |
6890 | subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)); | |
6891 | ||
6892 | if (ar->num_tx_chains < 2) { | |
6893 | *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); | |
6894 | subfer = false; | |
6895 | } | |
6896 | ||
6897 | /* If SU Beaformer is not set, then disable MU Beamformer Capability */ | |
6898 | if (!subfer) | |
6899 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); | |
6900 | ||
6901 | /* If SU Beaformee is not set, then disable MU Beamformee Capability */ | |
6902 | if (!subfee) | |
6903 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); | |
6904 | ||
6905 | sound_dim = u32_get_bits(*vht_cap, | |
6906 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
6907 | *vht_cap = u32_replace_bits(*vht_cap, 0, | |
6908 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
6909 | ||
6910 | /* TODO: Need to check invalid STS and Sound_dim values set by FW? */ | |
6911 | ||
6912 | /* Enable Sounding Dimension Field only if SU BF is enabled */ | |
6913 | if (subfer) { | |
6914 | if (sound_dim > (ar->num_tx_chains - 1)) | |
6915 | sound_dim = ar->num_tx_chains - 1; | |
6916 | ||
6917 | *vht_cap = u32_replace_bits(*vht_cap, sound_dim, | |
6918 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
6919 | } | |
6920 | ||
6921 | /* Use the STS advertised by FW unless SU Beamformee is not supported*/ | |
6922 | if (!subfee) | |
6923 | *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); | |
6924 | } | |
6925 | ||
6926 | static struct ieee80211_sta_vht_cap | |
6927 | ath12k_create_vht_cap(struct ath12k *ar, u32 rate_cap_tx_chainmask, | |
6928 | u32 rate_cap_rx_chainmask) | |
6929 | { | |
6930 | struct ieee80211_sta_vht_cap vht_cap = {0}; | |
6931 | u16 txmcs_map, rxmcs_map; | |
6932 | int i; | |
6933 | ||
6934 | vht_cap.vht_supported = 1; | |
6935 | vht_cap.cap = ar->pdev->cap.vht_cap; | |
6936 | ||
6937 | ath12k_set_vht_txbf_cap(ar, &vht_cap.cap); | |
6938 | ||
6939 | /* TODO: Enable back VHT160 mode once association issues are fixed */ | |
6940 | /* Disabling VHT160 and VHT80+80 modes */ | |
6941 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; | |
6942 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; | |
6943 | ||
6944 | rxmcs_map = 0; | |
6945 | txmcs_map = 0; | |
6946 | for (i = 0; i < 8; i++) { | |
6947 | if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i)) | |
6948 | txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
6949 | else | |
6950 | txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
6951 | ||
6952 | if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i)) | |
6953 | rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
6954 | else | |
6955 | rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
6956 | } | |
6957 | ||
6958 | if (rate_cap_tx_chainmask <= 1) | |
6959 | vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; | |
6960 | ||
6961 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map); | |
6962 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map); | |
6963 | ||
6964 | return vht_cap; | |
6965 | } | |
6966 | ||
6967 | static void ath12k_mac_setup_ht_vht_cap(struct ath12k *ar, | |
6968 | struct ath12k_pdev_cap *cap, | |
6969 | u32 *ht_cap_info) | |
6970 | { | |
6971 | struct ieee80211_supported_band *band; | |
6972 | u32 rate_cap_tx_chainmask; | |
6973 | u32 rate_cap_rx_chainmask; | |
6974 | u32 ht_cap; | |
6975 | ||
6976 | rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift; | |
6977 | rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift; | |
6978 | ||
6a88093f | 6979 | if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
d8899132 KV |
6980 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
6981 | ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info; | |
6982 | if (ht_cap_info) | |
6983 | *ht_cap_info = ht_cap; | |
6984 | band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, | |
6985 | rate_cap_rx_chainmask); | |
6986 | } | |
6987 | ||
6a88093f | 6988 | if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP && |
d8899132 KV |
6989 | (ar->ab->hw_params->single_pdev_only || |
6990 | !ar->supports_6ghz)) { | |
6991 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
6992 | ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info; | |
6993 | if (ht_cap_info) | |
6994 | *ht_cap_info = ht_cap; | |
6995 | band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, | |
6996 | rate_cap_rx_chainmask); | |
6997 | band->vht_cap = ath12k_create_vht_cap(ar, rate_cap_tx_chainmask, | |
6998 | rate_cap_rx_chainmask); | |
6999 | } | |
7000 | } | |
7001 | ||
7002 | static int ath12k_check_chain_mask(struct ath12k *ar, u32 ant, bool is_tx_ant) | |
7003 | { | |
7004 | /* TODO: Check the request chainmask against the supported | |
7005 | * chainmask table which is advertised in extented_service_ready event | |
7006 | */ | |
7007 | ||
7008 | return 0; | |
7009 | } | |
7010 | ||
7011 | static void ath12k_gen_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, | |
7012 | u8 *he_ppet) | |
7013 | { | |
7014 | int nss, ru; | |
7015 | u8 bit = 7; | |
7016 | ||
7017 | he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK; | |
7018 | he_ppet[0] |= (fw_ppet->ru_bit_mask << | |
7019 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) & | |
7020 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK; | |
7021 | for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { | |
7022 | for (ru = 0; ru < 4; ru++) { | |
7023 | u8 val; | |
7024 | int i; | |
7025 | ||
7026 | if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) | |
7027 | continue; | |
7028 | val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) & | |
7029 | 0x3f; | |
7030 | val = ((val >> 3) & 0x7) | ((val & 0x7) << 3); | |
7031 | for (i = 5; i >= 0; i--) { | |
7032 | he_ppet[bit / 8] |= | |
7033 | ((val >> i) & 0x1) << ((bit % 8)); | |
7034 | bit++; | |
7035 | } | |
7036 | } | |
7037 | } | |
7038 | } | |
7039 | ||
7040 | static void | |
7041 | ath12k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem) | |
7042 | { | |
7043 | u8 m; | |
7044 | ||
7045 | m = IEEE80211_HE_MAC_CAP0_TWT_RES | | |
7046 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
7047 | he_cap_elem->mac_cap_info[0] &= ~m; | |
7048 | ||
7049 | m = IEEE80211_HE_MAC_CAP2_TRS | | |
7050 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
7051 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
7052 | he_cap_elem->mac_cap_info[2] &= ~m; | |
7053 | ||
7054 | m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED | | |
7055 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
7056 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
7057 | he_cap_elem->mac_cap_info[3] &= ~m; | |
7058 | ||
7059 | m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG | | |
7060 | IEEE80211_HE_MAC_CAP4_BQR; | |
7061 | he_cap_elem->mac_cap_info[4] &= ~m; | |
7062 | ||
7063 | m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION | | |
7064 | IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU | | |
7065 | IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING | | |
7066 | IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX; | |
7067 | he_cap_elem->mac_cap_info[5] &= ~m; | |
7068 | ||
7069 | m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
7070 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; | |
7071 | he_cap_elem->phy_cap_info[2] &= ~m; | |
7072 | ||
7073 | m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU | | |
7074 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK | | |
7075 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK; | |
7076 | he_cap_elem->phy_cap_info[3] &= ~m; | |
7077 | ||
7078 | m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; | |
7079 | he_cap_elem->phy_cap_info[4] &= ~m; | |
7080 | ||
7081 | m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; | |
7082 | he_cap_elem->phy_cap_info[5] &= ~m; | |
7083 | ||
7084 | m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | | |
7085 | IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB | | |
7086 | IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | | |
7087 | IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; | |
7088 | he_cap_elem->phy_cap_info[6] &= ~m; | |
7089 | ||
7090 | m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR | | |
7091 | IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | | |
7092 | IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | | |
7093 | IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; | |
7094 | he_cap_elem->phy_cap_info[7] &= ~m; | |
7095 | ||
7096 | m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | | |
7097 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | | |
7098 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | | |
7099 | IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU; | |
7100 | he_cap_elem->phy_cap_info[8] &= ~m; | |
7101 | ||
7102 | m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | | |
7103 | IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | | |
7104 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | | |
7105 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | | |
7106 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | | |
7107 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; | |
7108 | he_cap_elem->phy_cap_info[9] &= ~m; | |
7109 | } | |
7110 | ||
7111 | static __le16 ath12k_mac_setup_he_6ghz_cap(struct ath12k_pdev_cap *pcap, | |
7112 | struct ath12k_band_cap *bcap) | |
7113 | { | |
7114 | u8 val; | |
7115 | ||
7116 | bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE; | |
7117 | if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) | |
7118 | bcap->he_6ghz_capa |= | |
7119 | u32_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC, | |
7120 | IEEE80211_HE_6GHZ_CAP_SM_PS); | |
7121 | else | |
7122 | bcap->he_6ghz_capa |= | |
7123 | u32_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED, | |
7124 | IEEE80211_HE_6GHZ_CAP_SM_PS); | |
7125 | val = u32_get_bits(pcap->vht_cap, | |
7126 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK); | |
7127 | bcap->he_6ghz_capa |= | |
7128 | u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); | |
7129 | val = u32_get_bits(pcap->vht_cap, | |
7130 | IEEE80211_VHT_CAP_MAX_MPDU_MASK); | |
7131 | bcap->he_6ghz_capa |= | |
7132 | u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN); | |
7133 | if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN) | |
7134 | bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS; | |
7135 | if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN) | |
7136 | bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS; | |
7137 | ||
7138 | return cpu_to_le16(bcap->he_6ghz_capa); | |
7139 | } | |
7140 | ||
a7a6a45d AD |
7141 | static void ath12k_mac_copy_he_cap(struct ath12k_band_cap *band_cap, |
7142 | int iftype, u8 num_tx_chains, | |
7143 | struct ieee80211_sta_he_cap *he_cap) | |
7144 | { | |
7145 | struct ieee80211_he_cap_elem *he_cap_elem = &he_cap->he_cap_elem; | |
7146 | struct ieee80211_he_mcs_nss_supp *mcs_nss = &he_cap->he_mcs_nss_supp; | |
7147 | ||
7148 | he_cap->has_he = true; | |
7149 | memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info, | |
7150 | sizeof(he_cap_elem->mac_cap_info)); | |
7151 | memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info, | |
7152 | sizeof(he_cap_elem->phy_cap_info)); | |
7153 | ||
7154 | he_cap_elem->mac_cap_info[1] &= | |
7155 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK; | |
7156 | ||
7157 | he_cap_elem->phy_cap_info[5] &= | |
7158 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK; | |
7159 | he_cap_elem->phy_cap_info[5] &= | |
7160 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK; | |
7161 | he_cap_elem->phy_cap_info[5] |= num_tx_chains - 1; | |
7162 | ||
7163 | switch (iftype) { | |
7164 | case NL80211_IFTYPE_AP: | |
cfe8af4b TW |
7165 | he_cap_elem->mac_cap_info[2] &= |
7166 | ~IEEE80211_HE_MAC_CAP2_BCAST_TWT; | |
a7a6a45d AD |
7167 | he_cap_elem->phy_cap_info[3] &= |
7168 | ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK; | |
7169 | he_cap_elem->phy_cap_info[9] |= | |
7170 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; | |
7171 | break; | |
7172 | case NL80211_IFTYPE_STATION: | |
7173 | he_cap_elem->mac_cap_info[0] &= ~IEEE80211_HE_MAC_CAP0_TWT_RES; | |
7174 | he_cap_elem->mac_cap_info[0] |= IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
7175 | he_cap_elem->phy_cap_info[9] |= | |
7176 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU; | |
7177 | break; | |
7178 | case NL80211_IFTYPE_MESH_POINT: | |
7179 | ath12k_mac_filter_he_cap_mesh(he_cap_elem); | |
7180 | break; | |
7181 | } | |
7182 | ||
7183 | mcs_nss->rx_mcs_80 = cpu_to_le16(band_cap->he_mcs & 0xffff); | |
7184 | mcs_nss->tx_mcs_80 = cpu_to_le16(band_cap->he_mcs & 0xffff); | |
7185 | mcs_nss->rx_mcs_160 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
7186 | mcs_nss->tx_mcs_160 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
7187 | mcs_nss->rx_mcs_80p80 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
7188 | mcs_nss->tx_mcs_80p80 = cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
7189 | ||
7190 | memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); | |
7191 | if (he_cap_elem->phy_cap_info[6] & | |
7192 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) | |
7193 | ath12k_gen_ppe_thresh(&band_cap->he_ppet, he_cap->ppe_thres); | |
7194 | } | |
7195 | ||
dbe90679 AD |
7196 | static void |
7197 | ath12k_mac_copy_eht_mcs_nss(struct ath12k_band_cap *band_cap, | |
7198 | struct ieee80211_eht_mcs_nss_supp *mcs_nss, | |
7199 | const struct ieee80211_he_cap_elem *he_cap, | |
7200 | const struct ieee80211_eht_cap_elem_fixed *eht_cap) | |
7201 | { | |
7202 | if ((he_cap->phy_cap_info[0] & | |
7203 | (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | | |
7204 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
7205 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
7206 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)) == 0) | |
7207 | memcpy(&mcs_nss->only_20mhz, &band_cap->eht_mcs_20_only, | |
7208 | sizeof(struct ieee80211_eht_mcs_nss_supp_20mhz_only)); | |
7209 | ||
7210 | if (he_cap->phy_cap_info[0] & | |
7211 | (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G | | |
7212 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) | |
7213 | memcpy(&mcs_nss->bw._80, &band_cap->eht_mcs_80, | |
7214 | sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); | |
7215 | ||
7216 | if (he_cap->phy_cap_info[0] & | |
7217 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) | |
7218 | memcpy(&mcs_nss->bw._160, &band_cap->eht_mcs_160, | |
7219 | sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); | |
7220 | ||
7221 | if (eht_cap->phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) | |
7222 | memcpy(&mcs_nss->bw._320, &band_cap->eht_mcs_320, | |
7223 | sizeof(struct ieee80211_eht_mcs_nss_supp_bw)); | |
7224 | } | |
7225 | ||
7226 | static void ath12k_mac_copy_eht_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, | |
7227 | struct ieee80211_sta_eht_cap *cap) | |
7228 | { | |
7229 | u16 bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; | |
7230 | u8 i, nss, ru, ppet_bit_len_per_ru = IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE * 2; | |
7231 | ||
7232 | u8p_replace_bits(&cap->eht_ppe_thres[0], fw_ppet->numss_m1, | |
7233 | IEEE80211_EHT_PPE_THRES_NSS_MASK); | |
7234 | ||
7235 | u16p_replace_bits((u16 *)&cap->eht_ppe_thres[0], fw_ppet->ru_bit_mask, | |
7236 | IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); | |
7237 | ||
7238 | for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { | |
7239 | for (ru = 0; | |
7240 | ru < hweight16(IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); | |
7241 | ru++) { | |
7242 | u32 val = 0; | |
7243 | ||
7244 | if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) | |
7245 | continue; | |
7246 | ||
7247 | u32p_replace_bits(&val, fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> | |
7248 | (ru * ppet_bit_len_per_ru), | |
7249 | GENMASK(ppet_bit_len_per_ru - 1, 0)); | |
7250 | ||
7251 | for (i = 0; i < ppet_bit_len_per_ru; i++) { | |
7252 | cap->eht_ppe_thres[bit / 8] |= | |
7253 | (((val >> i) & 0x1) << ((bit % 8))); | |
7254 | bit++; | |
7255 | } | |
7256 | } | |
7257 | } | |
7258 | } | |
7259 | ||
6b819f89 RG |
7260 | static void |
7261 | ath12k_mac_filter_eht_cap_mesh(struct ieee80211_eht_cap_elem_fixed | |
7262 | *eht_cap_elem) | |
7263 | { | |
7264 | u8 m; | |
7265 | ||
7266 | m = IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS; | |
7267 | eht_cap_elem->mac_cap_info[0] &= ~m; | |
7268 | ||
7269 | m = IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO; | |
7270 | eht_cap_elem->phy_cap_info[0] &= ~m; | |
7271 | ||
7272 | m = IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
7273 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
7274 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
7275 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK; | |
7276 | eht_cap_elem->phy_cap_info[3] &= ~m; | |
7277 | ||
7278 | m = IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
7279 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
7280 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
7281 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI; | |
7282 | eht_cap_elem->phy_cap_info[4] &= ~m; | |
7283 | ||
7284 | m = IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
7285 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
7286 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
7287 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK; | |
7288 | eht_cap_elem->phy_cap_info[5] &= ~m; | |
7289 | ||
7290 | m = IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK; | |
7291 | eht_cap_elem->phy_cap_info[6] &= ~m; | |
7292 | ||
7293 | m = IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | | |
7294 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | | |
7295 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ | | |
7296 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
7297 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | | |
7298 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ; | |
7299 | eht_cap_elem->phy_cap_info[7] &= ~m; | |
7300 | } | |
7301 | ||
972754bf WG |
7302 | static void ath12k_mac_copy_eht_cap(struct ath12k *ar, |
7303 | struct ath12k_band_cap *band_cap, | |
dbe90679 AD |
7304 | struct ieee80211_he_cap_elem *he_cap_elem, |
7305 | int iftype, | |
7306 | struct ieee80211_sta_eht_cap *eht_cap) | |
7307 | { | |
7308 | struct ieee80211_eht_cap_elem_fixed *eht_cap_elem = &eht_cap->eht_cap_elem; | |
7309 | ||
7310 | memset(eht_cap, 0, sizeof(struct ieee80211_sta_eht_cap)); | |
972754bf | 7311 | |
c6a7c0b0 LK |
7312 | if (!(test_bit(WMI_TLV_SERVICE_11BE, ar->ab->wmi_ab.svc_map)) || |
7313 | ath12k_acpi_get_disable_11be(ar->ab)) | |
972754bf WG |
7314 | return; |
7315 | ||
dbe90679 AD |
7316 | eht_cap->has_eht = true; |
7317 | memcpy(eht_cap_elem->mac_cap_info, band_cap->eht_cap_mac_info, | |
7318 | sizeof(eht_cap_elem->mac_cap_info)); | |
7319 | memcpy(eht_cap_elem->phy_cap_info, band_cap->eht_cap_phy_info, | |
7320 | sizeof(eht_cap_elem->phy_cap_info)); | |
7321 | ||
7322 | switch (iftype) { | |
7323 | case NL80211_IFTYPE_AP: | |
7324 | eht_cap_elem->phy_cap_info[0] &= | |
7325 | ~IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ; | |
7326 | eht_cap_elem->phy_cap_info[4] &= | |
7327 | ~IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO; | |
7328 | eht_cap_elem->phy_cap_info[5] &= | |
7329 | ~IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP; | |
7330 | break; | |
7331 | case NL80211_IFTYPE_STATION: | |
7332 | eht_cap_elem->phy_cap_info[7] &= | |
7333 | ~(IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | | |
7334 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | | |
7335 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ); | |
7336 | eht_cap_elem->phy_cap_info[7] &= | |
7337 | ~(IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
7338 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | | |
7339 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ); | |
7340 | break; | |
6b819f89 RG |
7341 | case NL80211_IFTYPE_MESH_POINT: |
7342 | ath12k_mac_filter_eht_cap_mesh(eht_cap_elem); | |
7343 | break; | |
dbe90679 AD |
7344 | default: |
7345 | break; | |
7346 | } | |
7347 | ||
7348 | ath12k_mac_copy_eht_mcs_nss(band_cap, &eht_cap->eht_mcs_nss_supp, | |
7349 | he_cap_elem, eht_cap_elem); | |
7350 | ||
7351 | if (eht_cap_elem->phy_cap_info[5] & | |
7352 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) | |
7353 | ath12k_mac_copy_eht_ppe_thresh(&band_cap->eht_ppet, eht_cap); | |
7354 | } | |
7355 | ||
e22f5b78 AD |
7356 | static int ath12k_mac_copy_sband_iftype_data(struct ath12k *ar, |
7357 | struct ath12k_pdev_cap *cap, | |
7358 | struct ieee80211_sband_iftype_data *data, | |
7359 | int band) | |
d8899132 | 7360 | { |
a7a6a45d | 7361 | struct ath12k_band_cap *band_cap = &cap->band[band]; |
d8899132 KV |
7362 | int i, idx = 0; |
7363 | ||
7364 | for (i = 0; i < NUM_NL80211_IFTYPES; i++) { | |
7365 | struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; | |
d8899132 KV |
7366 | |
7367 | switch (i) { | |
7368 | case NL80211_IFTYPE_STATION: | |
7369 | case NL80211_IFTYPE_AP: | |
7370 | case NL80211_IFTYPE_MESH_POINT: | |
7371 | break; | |
7372 | ||
7373 | default: | |
7374 | continue; | |
7375 | } | |
7376 | ||
7377 | data[idx].types_mask = BIT(i); | |
d8899132 | 7378 | |
a7a6a45d | 7379 | ath12k_mac_copy_he_cap(band_cap, i, ar->num_tx_chains, he_cap); |
d8899132 KV |
7380 | if (band == NL80211_BAND_6GHZ) { |
7381 | data[idx].he_6ghz_capa.capa = | |
7382 | ath12k_mac_setup_he_6ghz_cap(cap, band_cap); | |
7383 | } | |
972754bf | 7384 | ath12k_mac_copy_eht_cap(ar, band_cap, &he_cap->he_cap_elem, i, |
dbe90679 | 7385 | &data[idx].eht_cap); |
d8899132 KV |
7386 | idx++; |
7387 | } | |
7388 | ||
7389 | return idx; | |
7390 | } | |
7391 | ||
e22f5b78 AD |
7392 | static void ath12k_mac_setup_sband_iftype_data(struct ath12k *ar, |
7393 | struct ath12k_pdev_cap *cap) | |
d8899132 | 7394 | { |
e22f5b78 AD |
7395 | struct ieee80211_supported_band *sband; |
7396 | enum nl80211_band band; | |
d8899132 KV |
7397 | int count; |
7398 | ||
6a88093f | 7399 | if (cap->supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
e22f5b78 AD |
7400 | band = NL80211_BAND_2GHZ; |
7401 | count = ath12k_mac_copy_sband_iftype_data(ar, cap, | |
7402 | ar->mac.iftype[band], | |
7403 | band); | |
7404 | sband = &ar->mac.sbands[band]; | |
e8c18412 JB |
7405 | _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], |
7406 | count); | |
d8899132 KV |
7407 | } |
7408 | ||
6a88093f | 7409 | if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { |
e22f5b78 AD |
7410 | band = NL80211_BAND_5GHZ; |
7411 | count = ath12k_mac_copy_sband_iftype_data(ar, cap, | |
7412 | ar->mac.iftype[band], | |
7413 | band); | |
7414 | sband = &ar->mac.sbands[band]; | |
e8c18412 JB |
7415 | _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], |
7416 | count); | |
d8899132 KV |
7417 | } |
7418 | ||
6a88093f | 7419 | if (cap->supported_bands & WMI_HOST_WLAN_5GHZ_CAP && |
d8899132 | 7420 | ar->supports_6ghz) { |
e22f5b78 AD |
7421 | band = NL80211_BAND_6GHZ; |
7422 | count = ath12k_mac_copy_sband_iftype_data(ar, cap, | |
7423 | ar->mac.iftype[band], | |
7424 | band); | |
7425 | sband = &ar->mac.sbands[band]; | |
e8c18412 JB |
7426 | _ieee80211_set_sband_iftype_data(sband, ar->mac.iftype[band], |
7427 | count); | |
d8899132 KV |
7428 | } |
7429 | } | |
7430 | ||
7431 | static int __ath12k_set_antenna(struct ath12k *ar, u32 tx_ant, u32 rx_ant) | |
7432 | { | |
9b4e5caa | 7433 | struct ath12k_hw *ah = ath12k_ar_to_ah(ar); |
d8899132 KV |
7434 | int ret; |
7435 | ||
b8c67509 | 7436 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
7437 | |
7438 | if (ath12k_check_chain_mask(ar, tx_ant, true)) | |
7439 | return -EINVAL; | |
7440 | ||
7441 | if (ath12k_check_chain_mask(ar, rx_ant, false)) | |
7442 | return -EINVAL; | |
7443 | ||
5a6af83c S |
7444 | /* Since we advertised the max cap of all radios combined during wiphy |
7445 | * registration, ensure we don't set the antenna config higher than the | |
7446 | * limits | |
7447 | */ | |
7448 | tx_ant = min_t(u32, tx_ant, ar->pdev->cap.tx_chain_mask); | |
7449 | rx_ant = min_t(u32, rx_ant, ar->pdev->cap.rx_chain_mask); | |
7450 | ||
d8899132 KV |
7451 | ar->cfg_tx_chainmask = tx_ant; |
7452 | ar->cfg_rx_chainmask = rx_ant; | |
7453 | ||
9b4e5caa KP |
7454 | if (ah->state != ATH12K_HW_STATE_ON && |
7455 | ah->state != ATH12K_HW_STATE_RESTARTED) | |
d8899132 KV |
7456 | return 0; |
7457 | ||
7458 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK, | |
7459 | tx_ant, ar->pdev->pdev_id); | |
7460 | if (ret) { | |
7461 | ath12k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n", | |
7462 | ret, tx_ant); | |
7463 | return ret; | |
7464 | } | |
7465 | ||
7466 | ar->num_tx_chains = hweight32(tx_ant); | |
7467 | ||
7468 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK, | |
7469 | rx_ant, ar->pdev->pdev_id); | |
7470 | if (ret) { | |
7471 | ath12k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n", | |
7472 | ret, rx_ant); | |
7473 | return ret; | |
7474 | } | |
7475 | ||
7476 | ar->num_rx_chains = hweight32(rx_ant); | |
7477 | ||
7478 | /* Reload HT/VHT/HE capability */ | |
7479 | ath12k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL); | |
e22f5b78 | 7480 | ath12k_mac_setup_sband_iftype_data(ar, &ar->pdev->cap); |
d8899132 KV |
7481 | |
7482 | return 0; | |
7483 | } | |
7484 | ||
5189a8db K |
7485 | static void ath12k_mgmt_over_wmi_tx_drop(struct ath12k *ar, struct sk_buff *skb) |
7486 | { | |
7487 | int num_mgmt; | |
7488 | ||
56dcbf0b KV |
7489 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
7490 | ||
b856f023 | 7491 | ieee80211_free_txskb(ath12k_ar_to_hw(ar), skb); |
5189a8db K |
7492 | |
7493 | num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx); | |
7494 | ||
7495 | if (num_mgmt < 0) | |
7496 | WARN_ON_ONCE(1); | |
7497 | ||
7498 | if (!num_mgmt) | |
7499 | wake_up(&ar->txmgmt_empty_waitq); | |
7500 | } | |
7501 | ||
d8899132 KV |
7502 | int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) |
7503 | { | |
7504 | struct sk_buff *msdu = skb; | |
7505 | struct ieee80211_tx_info *info; | |
7506 | struct ath12k *ar = ctx; | |
7507 | struct ath12k_base *ab = ar->ab; | |
7508 | ||
7509 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
7510 | idr_remove(&ar->txmgmt_idr, buf_id); | |
7511 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
7512 | dma_unmap_single(ab->dev, ATH12K_SKB_CB(msdu)->paddr, msdu->len, | |
7513 | DMA_TO_DEVICE); | |
7514 | ||
7515 | info = IEEE80211_SKB_CB(msdu); | |
7516 | memset(&info->status, 0, sizeof(info->status)); | |
7517 | ||
5189a8db | 7518 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
7519 | |
7520 | return 0; | |
7521 | } | |
7522 | ||
7523 | static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) | |
7524 | { | |
7525 | struct ieee80211_vif *vif = ctx; | |
7526 | struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); | |
7527 | struct sk_buff *msdu = skb; | |
7528 | struct ath12k *ar = skb_cb->ar; | |
7529 | struct ath12k_base *ab = ar->ab; | |
7530 | ||
7531 | if (skb_cb->vif == vif) { | |
7532 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
7533 | idr_remove(&ar->txmgmt_idr, buf_id); | |
7534 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
7535 | dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, | |
7536 | DMA_TO_DEVICE); | |
7537 | } | |
7538 | ||
7539 | return 0; | |
7540 | } | |
7541 | ||
3dd2c68f | 7542 | static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_link_vif *arvif, |
d8899132 KV |
7543 | struct sk_buff *skb) |
7544 | { | |
7545 | struct ath12k_base *ab = ar->ab; | |
7546 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
0ca04ad0 | 7547 | struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); |
d8899132 | 7548 | struct ieee80211_tx_info *info; |
f5d6b15d RS |
7549 | enum hal_encrypt_type enctype; |
7550 | unsigned int mic_len; | |
d8899132 KV |
7551 | dma_addr_t paddr; |
7552 | int buf_id; | |
7553 | int ret; | |
7554 | ||
56dcbf0b KV |
7555 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
7556 | ||
0ca04ad0 | 7557 | skb_cb->ar = ar; |
d8899132 KV |
7558 | spin_lock_bh(&ar->txmgmt_idr_lock); |
7559 | buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, | |
7560 | ATH12K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); | |
7561 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
7562 | if (buf_id < 0) | |
7563 | return -ENOSPC; | |
7564 | ||
7565 | info = IEEE80211_SKB_CB(skb); | |
0ca04ad0 | 7566 | if ((skb_cb->flags & ATH12K_SKB_CIPHER_SET) && |
f5d6b15d | 7567 | !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) { |
d8899132 KV |
7568 | if ((ieee80211_is_action(hdr->frame_control) || |
7569 | ieee80211_is_deauth(hdr->frame_control) || | |
7570 | ieee80211_is_disassoc(hdr->frame_control)) && | |
7571 | ieee80211_has_protected(hdr->frame_control)) { | |
0ca04ad0 | 7572 | enctype = ath12k_dp_tx_get_encrypt_type(skb_cb->cipher); |
f5d6b15d RS |
7573 | mic_len = ath12k_dp_rx_crypto_mic_len(ar, enctype); |
7574 | skb_put(skb, mic_len); | |
d8899132 KV |
7575 | } |
7576 | } | |
7577 | ||
7578 | paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE); | |
7579 | if (dma_mapping_error(ab->dev, paddr)) { | |
7580 | ath12k_warn(ab, "failed to DMA map mgmt Tx buffer\n"); | |
7581 | ret = -EIO; | |
7582 | goto err_free_idr; | |
7583 | } | |
7584 | ||
0ca04ad0 | 7585 | skb_cb->paddr = paddr; |
d8899132 KV |
7586 | |
7587 | ret = ath12k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb); | |
7588 | if (ret) { | |
7589 | ath12k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret); | |
7590 | goto err_unmap_buf; | |
7591 | } | |
7592 | ||
7593 | return 0; | |
7594 | ||
7595 | err_unmap_buf: | |
0ca04ad0 | 7596 | dma_unmap_single(ab->dev, skb_cb->paddr, |
d8899132 KV |
7597 | skb->len, DMA_TO_DEVICE); |
7598 | err_free_idr: | |
7599 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
7600 | idr_remove(&ar->txmgmt_idr, buf_id); | |
7601 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
7602 | ||
7603 | return ret; | |
7604 | } | |
7605 | ||
7606 | static void ath12k_mgmt_over_wmi_tx_purge(struct ath12k *ar) | |
7607 | { | |
7608 | struct sk_buff *skb; | |
7609 | ||
7610 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) | |
5189a8db | 7611 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
7612 | } |
7613 | ||
56dcbf0b | 7614 | static void ath12k_mgmt_over_wmi_tx_work(struct wiphy *wiphy, struct wiphy_work *work) |
d8899132 KV |
7615 | { |
7616 | struct ath12k *ar = container_of(work, struct ath12k, wmi_mgmt_tx_work); | |
648a121b | 7617 | struct ath12k_hw *ah = ar->ah; |
d8899132 | 7618 | struct ath12k_skb_cb *skb_cb; |
3dd2c68f S |
7619 | struct ath12k_vif *ahvif; |
7620 | struct ath12k_link_vif *arvif; | |
d8899132 KV |
7621 | struct sk_buff *skb; |
7622 | int ret; | |
7623 | ||
56dcbf0b KV |
7624 | lockdep_assert_wiphy(wiphy); |
7625 | ||
d8899132 KV |
7626 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) { |
7627 | skb_cb = ATH12K_SKB_CB(skb); | |
7628 | if (!skb_cb->vif) { | |
7629 | ath12k_warn(ar->ab, "no vif found for mgmt frame\n"); | |
5189a8db | 7630 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
7631 | continue; |
7632 | } | |
7633 | ||
3dd2c68f | 7634 | ahvif = ath12k_vif_to_ahvif(skb_cb->vif); |
648a121b S |
7635 | if (!(ahvif->links_map & BIT(skb_cb->link_id))) { |
7636 | ath12k_warn(ar->ab, | |
7637 | "invalid linkid %u in mgmt over wmi tx with linkmap 0x%x\n", | |
7638 | skb_cb->link_id, ahvif->links_map); | |
7639 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); | |
7640 | continue; | |
7641 | } | |
7642 | ||
7643 | arvif = wiphy_dereference(ah->hw->wiphy, ahvif->link[skb_cb->link_id]); | |
32e7b12e | 7644 | if (ar->allocated_vdev_map & (1LL << arvif->vdev_id)) { |
d8899132 KV |
7645 | ret = ath12k_mac_mgmt_tx_wmi(ar, arvif, skb); |
7646 | if (ret) { | |
7647 | ath12k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n", | |
7648 | arvif->vdev_id, ret); | |
5189a8db | 7649 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
7650 | } |
7651 | } else { | |
7652 | ath12k_warn(ar->ab, | |
648a121b | 7653 | "dropping mgmt frame for vdev %d link %u is_started %d\n", |
d8899132 | 7654 | arvif->vdev_id, |
648a121b | 7655 | skb_cb->link_id, |
d8899132 | 7656 | arvif->is_started); |
5189a8db | 7657 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
7658 | } |
7659 | } | |
7660 | } | |
7661 | ||
7662 | static int ath12k_mac_mgmt_tx(struct ath12k *ar, struct sk_buff *skb, | |
7663 | bool is_prb_rsp) | |
7664 | { | |
7665 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; | |
7666 | ||
7667 | if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
7668 | return -ESHUTDOWN; | |
7669 | ||
7670 | /* Drop probe response packets when the pending management tx | |
7671 | * count has reached a certain threshold, so as to prioritize | |
7672 | * other mgmt packets like auth and assoc to be sent on time | |
7673 | * for establishing successful connections. | |
7674 | */ | |
7675 | if (is_prb_rsp && | |
7676 | atomic_read(&ar->num_pending_mgmt_tx) > ATH12K_PRB_RSP_DROP_THRESHOLD) { | |
7677 | ath12k_warn(ar->ab, | |
7678 | "dropping probe response as pending queue is almost full\n"); | |
7679 | return -ENOSPC; | |
7680 | } | |
7681 | ||
e995f3f6 | 7682 | if (skb_queue_len_lockless(q) >= ATH12K_TX_MGMT_NUM_PENDING_MAX) { |
d8899132 KV |
7683 | ath12k_warn(ar->ab, "mgmt tx queue is full\n"); |
7684 | return -ENOSPC; | |
7685 | } | |
7686 | ||
7687 | skb_queue_tail(q, skb); | |
5189a8db | 7688 | atomic_inc(&ar->num_pending_mgmt_tx); |
56dcbf0b | 7689 | wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work); |
d8899132 KV |
7690 | |
7691 | return 0; | |
7692 | } | |
7693 | ||
9411eecb KY |
7694 | static void ath12k_mac_add_p2p_noa_ie(struct ath12k *ar, |
7695 | struct ieee80211_vif *vif, | |
7696 | struct sk_buff *skb, | |
7697 | bool is_prb_rsp) | |
7698 | { | |
3dd2c68f | 7699 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
9411eecb KY |
7700 | |
7701 | if (likely(!is_prb_rsp)) | |
7702 | return; | |
7703 | ||
7704 | spin_lock_bh(&ar->data_lock); | |
7705 | ||
3dd2c68f S |
7706 | if (ahvif->u.ap.noa_data && |
7707 | !pskb_expand_head(skb, 0, ahvif->u.ap.noa_len, | |
9411eecb | 7708 | GFP_ATOMIC)) |
3dd2c68f S |
7709 | skb_put_data(skb, ahvif->u.ap.noa_data, |
7710 | ahvif->u.ap.noa_len); | |
9411eecb KY |
7711 | |
7712 | spin_unlock_bh(&ar->data_lock); | |
7713 | } | |
7714 | ||
2f50de72 BM |
7715 | /* Note: called under rcu_read_lock() */ |
7716 | static void ath12k_mlo_mcast_update_tx_link_address(struct ieee80211_vif *vif, | |
7717 | u8 link_id, struct sk_buff *skb, | |
7718 | u32 info_flags) | |
7719 | { | |
7720 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
7721 | struct ieee80211_bss_conf *bss_conf; | |
7722 | ||
7723 | if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) | |
7724 | return; | |
7725 | ||
7726 | bss_conf = rcu_dereference(vif->link_conf[link_id]); | |
7727 | if (bss_conf) | |
7728 | ether_addr_copy(hdr->addr2, bss_conf->addr); | |
7729 | } | |
7730 | ||
648a121b S |
7731 | /* Note: called under rcu_read_lock() */ |
7732 | static u8 ath12k_mac_get_tx_link(struct ieee80211_sta *sta, struct ieee80211_vif *vif, | |
7733 | u8 link, struct sk_buff *skb, u32 info_flags) | |
7734 | { | |
7735 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
7736 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
7737 | struct ieee80211_link_sta *link_sta; | |
7738 | struct ieee80211_bss_conf *bss_conf; | |
7739 | struct ath12k_sta *ahsta; | |
7740 | ||
7741 | /* Use the link id passed or the default vif link */ | |
7742 | if (!sta) { | |
7743 | if (link != IEEE80211_LINK_UNSPECIFIED) | |
7744 | return link; | |
7745 | ||
7746 | return ahvif->deflink.link_id; | |
7747 | } | |
7748 | ||
7749 | ahsta = ath12k_sta_to_ahsta(sta); | |
7750 | ||
7751 | /* Below translation ensures we pass proper A2 & A3 for non ML clients. | |
7752 | * Also it assumes for now support only for MLO AP in this path | |
7753 | */ | |
7754 | if (!sta->mlo) { | |
7755 | link = ahsta->deflink.link_id; | |
7756 | ||
7757 | if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) | |
7758 | return link; | |
7759 | ||
7760 | bss_conf = rcu_dereference(vif->link_conf[link]); | |
7761 | if (bss_conf) { | |
7762 | ether_addr_copy(hdr->addr2, bss_conf->addr); | |
7763 | if (!ieee80211_has_tods(hdr->frame_control) && | |
7764 | !ieee80211_has_fromds(hdr->frame_control)) | |
7765 | ether_addr_copy(hdr->addr3, bss_conf->addr); | |
7766 | } | |
7767 | ||
7768 | return link; | |
7769 | } | |
7770 | ||
7771 | /* enqueue eth enacap & data frames on primary link, FW does link | |
7772 | * selection and address translation. | |
7773 | */ | |
7774 | if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP || | |
7775 | ieee80211_is_data(hdr->frame_control)) | |
7776 | return ahsta->assoc_link_id; | |
7777 | ||
7778 | /* 802.11 frame cases */ | |
7779 | if (link == IEEE80211_LINK_UNSPECIFIED) | |
7780 | link = ahsta->deflink.link_id; | |
7781 | ||
7782 | if (!ieee80211_is_mgmt(hdr->frame_control)) | |
7783 | return link; | |
7784 | ||
7785 | /* Perform address conversion for ML STA Tx */ | |
7786 | bss_conf = rcu_dereference(vif->link_conf[link]); | |
7787 | link_sta = rcu_dereference(sta->link[link]); | |
7788 | ||
7789 | if (bss_conf && link_sta) { | |
7790 | ether_addr_copy(hdr->addr1, link_sta->addr); | |
7791 | ether_addr_copy(hdr->addr2, bss_conf->addr); | |
7792 | ||
7793 | if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid) | |
7794 | ether_addr_copy(hdr->addr3, bss_conf->bssid); | |
7795 | else if (vif->type == NL80211_IFTYPE_AP) | |
7796 | ether_addr_copy(hdr->addr3, bss_conf->addr); | |
7797 | ||
7798 | return link; | |
7799 | } | |
7800 | ||
7801 | if (bss_conf) { | |
7802 | /* In certain cases where a ML sta associated and added subset of | |
7803 | * links on which the ML AP is active, but now sends some frame | |
7804 | * (ex. Probe request) on a different link which is active in our | |
7805 | * MLD but was not added during previous association, we can | |
7806 | * still honor the Tx to that ML STA via the requested link. | |
7807 | * The control would reach here in such case only when that link | |
7808 | * address is same as the MLD address or in worst case clients | |
7809 | * used MLD address at TA wrongly which would have helped | |
7810 | * identify the ML sta object and pass it here. | |
7811 | * If the link address of that STA is different from MLD address, | |
7812 | * then the sta object would be NULL and control won't reach | |
7813 | * here but return at the start of the function itself with !sta | |
7814 | * check. Also this would not need any translation at hdr->addr1 | |
7815 | * from MLD to link address since the RA is the MLD address | |
7816 | * (same as that link address ideally) already. | |
7817 | */ | |
7818 | ether_addr_copy(hdr->addr2, bss_conf->addr); | |
7819 | ||
7820 | if (vif->type == NL80211_IFTYPE_STATION && bss_conf->bssid) | |
7821 | ether_addr_copy(hdr->addr3, bss_conf->bssid); | |
7822 | else if (vif->type == NL80211_IFTYPE_AP) | |
7823 | ether_addr_copy(hdr->addr3, bss_conf->addr); | |
7824 | } | |
7825 | ||
7826 | return link; | |
7827 | } | |
7828 | ||
7829 | /* Note: called under rcu_read_lock() */ | |
d8899132 KV |
7830 | static void ath12k_mac_op_tx(struct ieee80211_hw *hw, |
7831 | struct ieee80211_tx_control *control, | |
7832 | struct sk_buff *skb) | |
7833 | { | |
7834 | struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); | |
d8899132 KV |
7835 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
7836 | struct ieee80211_vif *vif = info->control.vif; | |
3dd2c68f S |
7837 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
7838 | struct ath12k_link_vif *arvif = &ahvif->deflink; | |
d8899132 KV |
7839 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
7840 | struct ieee80211_key_conf *key = info->control.hw_key; | |
648a121b | 7841 | struct ieee80211_sta *sta = control->sta; |
2f50de72 | 7842 | struct ath12k_link_vif *tmp_arvif; |
d8899132 | 7843 | u32 info_flags = info->flags; |
2f50de72 BM |
7844 | struct sk_buff *msdu_copied; |
7845 | struct ath12k *ar, *tmp_ar; | |
7846 | struct ath12k_peer *peer; | |
7847 | unsigned long links_map; | |
7848 | bool is_mcast = false; | |
a5f95d3d | 7849 | bool is_dvlan = false; |
2f50de72 | 7850 | struct ethhdr *eth; |
d8899132 | 7851 | bool is_prb_rsp; |
2f50de72 | 7852 | u16 mcbc_gsn; |
648a121b | 7853 | u8 link_id; |
d8899132 KV |
7854 | int ret; |
7855 | ||
2c4c3aff P |
7856 | if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
7857 | ieee80211_free_txskb(hw, skb); | |
7858 | return; | |
7859 | } | |
7860 | ||
648a121b | 7861 | link_id = u32_get_bits(info->control.flags, IEEE80211_TX_CTRL_MLO_LINK); |
d8899132 KV |
7862 | memset(skb_cb, 0, sizeof(*skb_cb)); |
7863 | skb_cb->vif = vif; | |
7864 | ||
7865 | if (key) { | |
7866 | skb_cb->cipher = key->cipher; | |
7867 | skb_cb->flags |= ATH12K_SKB_CIPHER_SET; | |
7868 | } | |
7869 | ||
648a121b S |
7870 | /* handle only for MLO case, use deflink for non MLO case */ |
7871 | if (ieee80211_vif_is_mld(vif)) { | |
7872 | link_id = ath12k_mac_get_tx_link(sta, vif, link_id, skb, info_flags); | |
7873 | if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) { | |
7874 | ieee80211_free_txskb(hw, skb); | |
7875 | return; | |
7876 | } | |
7877 | } else { | |
7878 | link_id = 0; | |
7879 | } | |
7880 | ||
7881 | arvif = rcu_dereference(ahvif->link[link_id]); | |
7882 | if (!arvif || !arvif->ar) { | |
7883 | ath12k_warn(ahvif->ah, "failed to find arvif link id %u for frame transmission", | |
7884 | link_id); | |
7885 | ieee80211_free_txskb(hw, skb); | |
7886 | return; | |
7887 | } | |
7888 | ||
7889 | ar = arvif->ar; | |
7890 | skb_cb->link_id = link_id; | |
9411eecb KY |
7891 | is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control); |
7892 | ||
d8899132 | 7893 | if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { |
2f50de72 BM |
7894 | eth = (struct ethhdr *)skb->data; |
7895 | is_mcast = is_multicast_ether_addr(eth->h_dest); | |
7896 | ||
d8899132 KV |
7897 | skb_cb->flags |= ATH12K_SKB_HW_80211_ENCAP; |
7898 | } else if (ieee80211_is_mgmt(hdr->frame_control)) { | |
d8899132 KV |
7899 | ret = ath12k_mac_mgmt_tx(ar, skb, is_prb_rsp); |
7900 | if (ret) { | |
7901 | ath12k_warn(ar->ab, "failed to queue management frame %d\n", | |
7902 | ret); | |
842addae | 7903 | ieee80211_free_txskb(hw, skb); |
d8899132 KV |
7904 | } |
7905 | return; | |
7906 | } | |
7907 | ||
2f50de72 BM |
7908 | if (!(info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) |
7909 | is_mcast = is_multicast_ether_addr(hdr->addr1); | |
7910 | ||
9411eecb KY |
7911 | /* This is case only for P2P_GO */ |
7912 | if (vif->type == NL80211_IFTYPE_AP && vif->p2p) | |
7913 | ath12k_mac_add_p2p_noa_ie(ar, vif, skb, is_prb_rsp); | |
7914 | ||
a5f95d3d MS |
7915 | /* Checking if it is a DVLAN frame */ |
7916 | if (!test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags) && | |
7917 | !(skb_cb->flags & ATH12K_SKB_HW_80211_ENCAP) && | |
7918 | !(skb_cb->flags & ATH12K_SKB_CIPHER_SET) && | |
7919 | ieee80211_has_protected(hdr->frame_control)) | |
7920 | is_dvlan = true; | |
7921 | ||
7922 | if (!vif->valid_links || !is_mcast || is_dvlan || | |
2f50de72 | 7923 | test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) { |
5e009751 | 7924 | ret = ath12k_dp_tx(ar, arvif, skb, false, 0, is_mcast); |
2f50de72 BM |
7925 | if (unlikely(ret)) { |
7926 | ath12k_warn(ar->ab, "failed to transmit frame %d\n", ret); | |
7927 | ieee80211_free_txskb(ar->ah->hw, skb); | |
7928 | return; | |
7929 | } | |
7930 | } else { | |
7931 | mcbc_gsn = atomic_inc_return(&ahvif->mcbc_gsn) & 0xfff; | |
7932 | ||
7933 | links_map = ahvif->links_map; | |
7934 | for_each_set_bit(link_id, &links_map, | |
7935 | IEEE80211_MLD_MAX_NUM_LINKS) { | |
7936 | tmp_arvif = rcu_dereference(ahvif->link[link_id]); | |
7937 | if (!tmp_arvif || !tmp_arvif->is_up) | |
7938 | continue; | |
7939 | ||
7940 | tmp_ar = tmp_arvif->ar; | |
7941 | msdu_copied = skb_copy(skb, GFP_ATOMIC); | |
7942 | if (!msdu_copied) { | |
7943 | ath12k_err(ar->ab, | |
7944 | "skb copy failure link_id 0x%X vdevid 0x%X\n", | |
7945 | link_id, tmp_arvif->vdev_id); | |
7946 | continue; | |
7947 | } | |
7948 | ||
7949 | ath12k_mlo_mcast_update_tx_link_address(vif, link_id, | |
7950 | msdu_copied, | |
7951 | info_flags); | |
7952 | ||
7953 | skb_cb = ATH12K_SKB_CB(msdu_copied); | |
2f50de72 BM |
7954 | skb_cb->link_id = link_id; |
7955 | ||
7956 | /* For open mode, skip peer find logic */ | |
4f4b067d | 7957 | if (unlikely(!ahvif->key_cipher)) |
2f50de72 BM |
7958 | goto skip_peer_find; |
7959 | ||
7960 | spin_lock_bh(&tmp_ar->ab->base_lock); | |
7961 | peer = ath12k_peer_find_by_addr(tmp_ar->ab, tmp_arvif->bssid); | |
7962 | if (!peer) { | |
7963 | spin_unlock_bh(&tmp_ar->ab->base_lock); | |
7964 | ath12k_warn(tmp_ar->ab, | |
7965 | "failed to find peer for vdev_id 0x%X addr %pM link_map 0x%X\n", | |
7966 | tmp_arvif->vdev_id, tmp_arvif->bssid, | |
7967 | ahvif->links_map); | |
7968 | dev_kfree_skb_any(msdu_copied); | |
7969 | continue; | |
7970 | } | |
7971 | ||
7972 | key = peer->keys[peer->mcast_keyidx]; | |
7973 | if (key) { | |
7974 | skb_cb->cipher = key->cipher; | |
7975 | skb_cb->flags |= ATH12K_SKB_CIPHER_SET; | |
2f50de72 BM |
7976 | |
7977 | hdr = (struct ieee80211_hdr *)msdu_copied->data; | |
7978 | if (!ieee80211_has_protected(hdr->frame_control)) | |
7979 | hdr->frame_control |= | |
7980 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
7981 | } | |
7982 | spin_unlock_bh(&tmp_ar->ab->base_lock); | |
7983 | ||
7984 | skip_peer_find: | |
7985 | ret = ath12k_dp_tx(tmp_ar, tmp_arvif, | |
5e009751 | 7986 | msdu_copied, true, mcbc_gsn, is_mcast); |
2f50de72 BM |
7987 | if (unlikely(ret)) { |
7988 | if (ret == -ENOMEM) { | |
7989 | /* Drops are expected during heavy multicast | |
7990 | * frame flood. Print with debug log | |
7991 | * level to avoid lot of console prints | |
7992 | */ | |
7993 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
7994 | "failed to transmit frame %d\n", | |
7995 | ret); | |
7996 | } else { | |
7997 | ath12k_warn(ar->ab, | |
7998 | "failed to transmit frame %d\n", | |
7999 | ret); | |
8000 | } | |
8001 | ||
8002 | dev_kfree_skb_any(msdu_copied); | |
8003 | } | |
8004 | } | |
8005 | ieee80211_free_txskb(ar->ah->hw, skb); | |
d8899132 KV |
8006 | } |
8007 | } | |
8008 | ||
8009 | void ath12k_mac_drain_tx(struct ath12k *ar) | |
8010 | { | |
56dcbf0b KV |
8011 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
8012 | ||
d8899132 KV |
8013 | /* make sure rcu-protected mac80211 tx path itself is drained */ |
8014 | synchronize_net(); | |
8015 | ||
56dcbf0b | 8016 | wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->wmi_mgmt_tx_work); |
d8899132 KV |
8017 | ath12k_mgmt_over_wmi_tx_purge(ar); |
8018 | } | |
8019 | ||
8020 | static int ath12k_mac_config_mon_status_default(struct ath12k *ar, bool enable) | |
8021 | { | |
6e8c9ba7 P |
8022 | struct htt_rx_ring_tlv_filter tlv_filter = {}; |
8023 | struct ath12k_base *ab = ar->ab; | |
8024 | u32 ring_id, i; | |
8025 | int ret = 0; | |
8026 | ||
8027 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
8028 | ||
8029 | if (!ab->hw_params->rxdma1_enable) | |
8030 | return ret; | |
8031 | ||
a412547f | 8032 | if (enable) { |
6e8c9ba7 | 8033 | tlv_filter = ath12k_mac_mon_status_filter_default; |
a412547f KP |
8034 | |
8035 | if (ath12k_debugfs_rx_filter(ar)) | |
8036 | tlv_filter.rx_filter = ath12k_debugfs_rx_filter(ar); | |
8037 | } else { | |
6e8c9ba7 | 8038 | tlv_filter.rxmon_disable = true; |
a412547f | 8039 | } |
6e8c9ba7 P |
8040 | |
8041 | for (i = 0; i < ab->hw_params->num_rxdma_per_pdev; i++) { | |
8042 | ring_id = ar->dp.rxdma_mon_dst_ring[i].ring_id; | |
8043 | ret = ath12k_dp_tx_htt_rx_filter_setup(ab, ring_id, | |
8044 | ar->dp.mac_id + i, | |
8045 | HAL_RXDMA_MONITOR_DST, | |
8046 | DP_RXDMA_REFILL_RING_SIZE, | |
8047 | &tlv_filter); | |
8048 | if (ret) { | |
8049 | ath12k_err(ab, | |
8050 | "failed to setup filter for monitor buf %d\n", | |
8051 | ret); | |
8052 | } | |
8053 | } | |
8054 | ||
8055 | return ret; | |
d8899132 KV |
8056 | } |
8057 | ||
e1e275a6 | 8058 | static int ath12k_mac_start(struct ath12k *ar) |
d8899132 | 8059 | { |
acaa8400 | 8060 | struct ath12k_hw *ah = ar->ah; |
d8899132 KV |
8061 | struct ath12k_base *ab = ar->ab; |
8062 | struct ath12k_pdev *pdev = ar->pdev; | |
8063 | int ret; | |
8064 | ||
acaa8400 | 8065 | lockdep_assert_held(&ah->hw_mutex); |
b8c67509 | 8066 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 8067 | |
d8899132 KV |
8068 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, |
8069 | 1, pdev->pdev_id); | |
8070 | ||
8071 | if (ret) { | |
47c91531 | 8072 | ath12k_err(ab, "failed to enable PMF QOS: %d\n", ret); |
d8899132 KV |
8073 | goto err; |
8074 | } | |
8075 | ||
8076 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1, | |
8077 | pdev->pdev_id); | |
8078 | if (ret) { | |
e1e275a6 | 8079 | ath12k_err(ab, "failed to enable dynamic bw: %d\n", ret); |
d8899132 KV |
8080 | goto err; |
8081 | } | |
8082 | ||
8083 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE, | |
8084 | 0, pdev->pdev_id); | |
8085 | if (ret) { | |
8086 | ath12k_err(ab, "failed to set ac override for ARP: %d\n", | |
8087 | ret); | |
8088 | goto err; | |
8089 | } | |
8090 | ||
8091 | ret = ath12k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id); | |
8092 | if (ret) { | |
8093 | ath12k_err(ab, "failed to offload radar detection: %d\n", | |
8094 | ret); | |
8095 | goto err; | |
8096 | } | |
8097 | ||
8098 | ret = ath12k_dp_tx_htt_h2t_ppdu_stats_req(ar, | |
8099 | HTT_PPDU_STATS_TAG_DEFAULT); | |
8100 | if (ret) { | |
8101 | ath12k_err(ab, "failed to req ppdu stats: %d\n", ret); | |
8102 | goto err; | |
8103 | } | |
8104 | ||
8105 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE, | |
8106 | 1, pdev->pdev_id); | |
8107 | ||
8108 | if (ret) { | |
e1e275a6 | 8109 | ath12k_err(ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret); |
d8899132 KV |
8110 | goto err; |
8111 | } | |
8112 | ||
8113 | __ath12k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); | |
8114 | ||
8115 | /* TODO: Do we need to enable ANI? */ | |
8116 | ||
591de41d | 8117 | ath12k_reg_update_chan_list(ar, false); |
d8899132 KV |
8118 | |
8119 | ar->num_started_vdevs = 0; | |
8120 | ar->num_created_vdevs = 0; | |
8121 | ar->num_peers = 0; | |
8122 | ar->allocated_vdev_map = 0; | |
e92c658b | 8123 | ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; |
d8899132 KV |
8124 | |
8125 | /* Configure monitor status ring with default rx_filter to get rx status | |
8126 | * such as rssi, rx_duration. | |
8127 | */ | |
8128 | ret = ath12k_mac_config_mon_status_default(ar, true); | |
49b88e5f | 8129 | if (ret && (ret != -EOPNOTSUPP)) { |
d8899132 KV |
8130 | ath12k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n", |
8131 | ret); | |
8132 | goto err; | |
8133 | } | |
8134 | ||
49b88e5f | 8135 | if (ret == -EOPNOTSUPP) |
e1e275a6 | 8136 | ath12k_dbg(ab, ATH12K_DBG_MAC, |
d8899132 KV |
8137 | "monitor status config is not yet supported"); |
8138 | ||
8139 | /* Configure the hash seed for hash based reo dest ring selection */ | |
8140 | ath12k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id); | |
8141 | ||
8142 | /* allow device to enter IMPS */ | |
8143 | if (ab->hw_params->idle_ps) { | |
8144 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG, | |
8145 | 1, pdev->pdev_id); | |
8146 | if (ret) { | |
8147 | ath12k_err(ab, "failed to enable idle ps: %d\n", ret); | |
8148 | goto err; | |
8149 | } | |
8150 | } | |
8151 | ||
d8899132 KV |
8152 | rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], |
8153 | &ab->pdevs[ar->pdev_idx]); | |
8154 | ||
8155 | return 0; | |
d8899132 | 8156 | err: |
d8899132 KV |
8157 | |
8158 | return ret; | |
8159 | } | |
8160 | ||
b8ce837e S |
8161 | static void ath12k_drain_tx(struct ath12k_hw *ah) |
8162 | { | |
3bc374cb | 8163 | struct ath12k *ar = ah->radio; |
b8ce837e S |
8164 | int i; |
8165 | ||
3bc374cb AS |
8166 | if (ath12k_ftm_mode) { |
8167 | ath12k_err(ar->ab, "fail to start mac operations in ftm mode\n"); | |
8168 | return; | |
8169 | } | |
8170 | ||
56dcbf0b KV |
8171 | lockdep_assert_wiphy(ah->hw->wiphy); |
8172 | ||
b8ce837e S |
8173 | for_each_ar(ah, ar, i) |
8174 | ath12k_mac_drain_tx(ar); | |
8175 | } | |
8176 | ||
e1e275a6 KP |
8177 | static int ath12k_mac_op_start(struct ieee80211_hw *hw) |
8178 | { | |
6db6e70a | 8179 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
b8ce837e S |
8180 | struct ath12k *ar; |
8181 | int ret, i; | |
e1e275a6 | 8182 | |
c347f181 KV |
8183 | lockdep_assert_wiphy(hw->wiphy); |
8184 | ||
b8ce837e | 8185 | ath12k_drain_tx(ah); |
e1e275a6 | 8186 | |
acaa8400 KP |
8187 | guard(mutex)(&ah->hw_mutex); |
8188 | ||
9b4e5caa KP |
8189 | switch (ah->state) { |
8190 | case ATH12K_HW_STATE_OFF: | |
8191 | ah->state = ATH12K_HW_STATE_ON; | |
8192 | break; | |
8193 | case ATH12K_HW_STATE_RESTARTING: | |
8194 | ah->state = ATH12K_HW_STATE_RESTARTED; | |
9b4e5caa KP |
8195 | break; |
8196 | case ATH12K_HW_STATE_RESTARTED: | |
8197 | case ATH12K_HW_STATE_WEDGED: | |
8198 | case ATH12K_HW_STATE_ON: | |
3bc374cb | 8199 | case ATH12K_HW_STATE_TM: |
9b4e5caa KP |
8200 | ah->state = ATH12K_HW_STATE_OFF; |
8201 | ||
8202 | WARN_ON(1); | |
8203 | return -EINVAL; | |
8204 | } | |
8205 | ||
b8ce837e S |
8206 | for_each_ar(ah, ar, i) { |
8207 | ret = ath12k_mac_start(ar); | |
8208 | if (ret) { | |
9b4e5caa KP |
8209 | ah->state = ATH12K_HW_STATE_OFF; |
8210 | ||
b8ce837e S |
8211 | ath12k_err(ar->ab, "fail to start mac operations in pdev idx %d ret %d\n", |
8212 | ar->pdev_idx, ret); | |
8213 | goto fail_start; | |
8214 | } | |
e1e275a6 KP |
8215 | } |
8216 | ||
8217 | return 0; | |
9b4e5caa | 8218 | |
b8ce837e S |
8219 | fail_start: |
8220 | for (; i > 0; i--) { | |
8221 | ar = ath12k_ah_to_ar(ah, i - 1); | |
8222 | ath12k_mac_stop(ar); | |
8223 | } | |
9b4e5caa | 8224 | |
b8ce837e | 8225 | return ret; |
e1e275a6 KP |
8226 | } |
8227 | ||
004ccbc0 LK |
8228 | int ath12k_mac_rfkill_config(struct ath12k *ar) |
8229 | { | |
8230 | struct ath12k_base *ab = ar->ab; | |
8231 | u32 param; | |
8232 | int ret; | |
8233 | ||
8234 | if (ab->hw_params->rfkill_pin == 0) | |
8235 | return -EOPNOTSUPP; | |
8236 | ||
8237 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
8238 | "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d", | |
8239 | ab->hw_params->rfkill_pin, ab->hw_params->rfkill_cfg, | |
8240 | ab->hw_params->rfkill_on_level); | |
8241 | ||
8242 | param = u32_encode_bits(ab->hw_params->rfkill_on_level, | |
8243 | WMI_RFKILL_CFG_RADIO_LEVEL) | | |
8244 | u32_encode_bits(ab->hw_params->rfkill_pin, | |
8245 | WMI_RFKILL_CFG_GPIO_PIN_NUM) | | |
8246 | u32_encode_bits(ab->hw_params->rfkill_cfg, | |
8247 | WMI_RFKILL_CFG_PIN_AS_GPIO); | |
8248 | ||
8249 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_HW_RFKILL_CONFIG, | |
8250 | param, ar->pdev->pdev_id); | |
8251 | if (ret) { | |
8252 | ath12k_warn(ab, | |
8253 | "failed to set rfkill config 0x%x: %d\n", | |
8254 | param, ret); | |
8255 | return ret; | |
8256 | } | |
8257 | ||
8258 | return 0; | |
8259 | } | |
8260 | ||
8261 | int ath12k_mac_rfkill_enable_radio(struct ath12k *ar, bool enable) | |
8262 | { | |
8263 | enum wmi_rfkill_enable_radio param; | |
8264 | int ret; | |
8265 | ||
8266 | if (enable) | |
8267 | param = WMI_RFKILL_ENABLE_RADIO_ON; | |
8268 | else | |
8269 | param = WMI_RFKILL_ENABLE_RADIO_OFF; | |
8270 | ||
8271 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac %d rfkill enable %d", | |
8272 | ar->pdev_idx, param); | |
8273 | ||
8274 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RFKILL_ENABLE, | |
8275 | param, ar->pdev->pdev_id); | |
8276 | if (ret) { | |
8277 | ath12k_warn(ar->ab, "failed to set rfkill enable param %d: %d\n", | |
8278 | param, ret); | |
8279 | return ret; | |
8280 | } | |
8281 | ||
8282 | return 0; | |
8283 | } | |
8284 | ||
3bbc9c74 | 8285 | static void ath12k_mac_stop(struct ath12k *ar) |
d8899132 | 8286 | { |
acaa8400 | 8287 | struct ath12k_hw *ah = ar->ah; |
d8899132 KV |
8288 | struct htt_ppdu_stats_info *ppdu_stats, *tmp; |
8289 | int ret; | |
8290 | ||
acaa8400 | 8291 | lockdep_assert_held(&ah->hw_mutex); |
b8c67509 | 8292 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
acaa8400 | 8293 | |
d8899132 | 8294 | ret = ath12k_mac_config_mon_status_default(ar, false); |
49b88e5f | 8295 | if (ret && (ret != -EOPNOTSUPP)) |
d8899132 KV |
8296 | ath12k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n", |
8297 | ret); | |
8298 | ||
d31241cb | 8299 | clear_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); |
d8899132 KV |
8300 | |
8301 | cancel_delayed_work_sync(&ar->scan.timeout); | |
3863f014 | 8302 | wiphy_work_cancel(ath12k_ar_to_hw(ar)->wiphy, &ar->scan.vdev_clean_wk); |
d8899132 | 8303 | cancel_work_sync(&ar->regd_update_work); |
004ccbc0 | 8304 | cancel_work_sync(&ar->ab->rfkill_work); |
591de41d WG |
8305 | cancel_work_sync(&ar->ab->update_11d_work); |
8306 | ar->state_11d = ATH12K_11D_IDLE; | |
8307 | complete(&ar->completed_11d_scan); | |
d8899132 KV |
8308 | |
8309 | spin_lock_bh(&ar->data_lock); | |
8310 | list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) { | |
8311 | list_del(&ppdu_stats->list); | |
8312 | kfree(ppdu_stats); | |
8313 | } | |
8314 | spin_unlock_bh(&ar->data_lock); | |
8315 | ||
8316 | rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL); | |
8317 | ||
8318 | synchronize_rcu(); | |
8319 | ||
8320 | atomic_set(&ar->num_pending_mgmt_tx, 0); | |
8321 | } | |
8322 | ||
1decf05d | 8323 | static void ath12k_mac_op_stop(struct ieee80211_hw *hw, bool suspend) |
3bbc9c74 | 8324 | { |
6db6e70a | 8325 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
b8ce837e S |
8326 | struct ath12k *ar; |
8327 | int i; | |
3bbc9c74 | 8328 | |
c347f181 KV |
8329 | lockdep_assert_wiphy(hw->wiphy); |
8330 | ||
b8ce837e | 8331 | ath12k_drain_tx(ah); |
3bbc9c74 | 8332 | |
acaa8400 KP |
8333 | mutex_lock(&ah->hw_mutex); |
8334 | ||
9b4e5caa KP |
8335 | ah->state = ATH12K_HW_STATE_OFF; |
8336 | ||
b8ce837e S |
8337 | for_each_ar(ah, ar, i) |
8338 | ath12k_mac_stop(ar); | |
acaa8400 KP |
8339 | |
8340 | mutex_unlock(&ah->hw_mutex); | |
3bbc9c74 KP |
8341 | } |
8342 | ||
d8899132 | 8343 | static u8 |
3dd2c68f | 8344 | ath12k_mac_get_vdev_stats_id(struct ath12k_link_vif *arvif) |
d8899132 KV |
8345 | { |
8346 | struct ath12k_base *ab = arvif->ar->ab; | |
8347 | u8 vdev_stats_id = 0; | |
8348 | ||
8349 | do { | |
8350 | if (ab->free_vdev_stats_id_map & (1LL << vdev_stats_id)) { | |
8351 | vdev_stats_id++; | |
019b58dc | 8352 | if (vdev_stats_id >= ATH12K_MAX_VDEV_STATS_ID) { |
d8899132 KV |
8353 | vdev_stats_id = ATH12K_INVAL_VDEV_STATS_ID; |
8354 | break; | |
8355 | } | |
8356 | } else { | |
8357 | ab->free_vdev_stats_id_map |= (1LL << vdev_stats_id); | |
8358 | break; | |
8359 | } | |
8360 | } while (vdev_stats_id); | |
8361 | ||
8362 | arvif->vdev_stats_id = vdev_stats_id; | |
8363 | return vdev_stats_id; | |
8364 | } | |
8365 | ||
3dd2c68f | 8366 | static int ath12k_mac_setup_vdev_params_mbssid(struct ath12k_link_vif *arvif, |
ea68f1bb AD |
8367 | u32 *flags, u32 *tx_vdev_id) |
8368 | { | |
3dd2c68f | 8369 | struct ath12k_vif *ahvif = arvif->ahvif; |
39526578 | 8370 | struct ieee80211_bss_conf *link_conf; |
ea68f1bb | 8371 | struct ath12k *ar = arvif->ar; |
3dd2c68f | 8372 | struct ath12k_link_vif *tx_arvif; |
ea68f1bb | 8373 | |
39526578 S |
8374 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
8375 | if (!link_conf) { | |
8376 | ath12k_warn(ar->ab, "unable to access bss link conf in set mbssid params for vif %pM link %u\n", | |
8377 | ahvif->vif->addr, arvif->link_id); | |
8378 | return -ENOLINK; | |
8379 | } | |
8380 | ||
172e1570 | 8381 | tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); |
20fe6390 AD |
8382 | if (!tx_arvif) |
8383 | return 0; | |
ea68f1bb | 8384 | |
39526578 | 8385 | if (link_conf->nontransmitted) { |
20fe6390 AD |
8386 | if (ath12k_ar_to_hw(ar)->wiphy != |
8387 | ath12k_ar_to_hw(tx_arvif->ar)->wiphy) | |
ea68f1bb AD |
8388 | return -EINVAL; |
8389 | ||
8390 | *flags = WMI_VDEV_MBSSID_FLAGS_NON_TRANSMIT_AP; | |
8391 | *tx_vdev_id = tx_arvif->vdev_id; | |
8392 | } else if (tx_arvif == arvif) { | |
8393 | *flags = WMI_VDEV_MBSSID_FLAGS_TRANSMIT_AP; | |
8394 | } else { | |
8395 | return -EINVAL; | |
8396 | } | |
8397 | ||
39526578 | 8398 | if (link_conf->ema_ap) |
ea68f1bb AD |
8399 | *flags |= WMI_VDEV_MBSSID_FLAGS_EMA_MODE; |
8400 | ||
8401 | return 0; | |
8402 | } | |
8403 | ||
3dd2c68f | 8404 | static int ath12k_mac_setup_vdev_create_arg(struct ath12k_link_vif *arvif, |
ea68f1bb | 8405 | struct ath12k_wmi_vdev_create_arg *arg) |
d8899132 KV |
8406 | { |
8407 | struct ath12k *ar = arvif->ar; | |
8408 | struct ath12k_pdev *pdev = ar->pdev; | |
3dd2c68f | 8409 | struct ath12k_vif *ahvif = arvif->ahvif; |
ea68f1bb | 8410 | int ret; |
d8899132 | 8411 | |
1ea0cdee S |
8412 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
8413 | ||
d8899132 | 8414 | arg->if_id = arvif->vdev_id; |
3dd2c68f S |
8415 | arg->type = ahvif->vdev_type; |
8416 | arg->subtype = ahvif->vdev_subtype; | |
d8899132 KV |
8417 | arg->pdev_id = pdev->pdev_id; |
8418 | ||
ea68f1bb AD |
8419 | arg->mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP; |
8420 | arg->mbssid_tx_vdev_id = 0; | |
8421 | if (!test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT, | |
8422 | ar->ab->wmi_ab.svc_map)) { | |
8423 | ret = ath12k_mac_setup_vdev_params_mbssid(arvif, | |
8424 | &arg->mbssid_flags, | |
8425 | &arg->mbssid_tx_vdev_id); | |
8426 | if (ret) | |
8427 | return ret; | |
8428 | } | |
8429 | ||
6a88093f | 8430 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
d8899132 KV |
8431 | arg->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; |
8432 | arg->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; | |
8433 | } | |
6a88093f | 8434 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { |
d8899132 KV |
8435 | arg->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; |
8436 | arg->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; | |
8437 | } | |
6a88093f | 8438 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5GHZ_CAP && |
d8899132 KV |
8439 | ar->supports_6ghz) { |
8440 | arg->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains; | |
8441 | arg->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains; | |
8442 | } | |
8443 | ||
8444 | arg->if_stats_id = ath12k_mac_get_vdev_stats_id(arvif); | |
1ea0cdee S |
8445 | |
8446 | if (ath12k_mac_is_ml_arvif(arvif)) { | |
8447 | if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) { | |
8448 | ath12k_warn(ar->ab, "too many MLO links during setting up vdev: %d", | |
8449 | ahvif->vif->valid_links); | |
8450 | return -EINVAL; | |
8451 | } | |
8452 | ||
8453 | ether_addr_copy(arg->mld_addr, ahvif->vif->addr); | |
8454 | } | |
8455 | ||
ea68f1bb | 8456 | return 0; |
d8899132 KV |
8457 | } |
8458 | ||
8459 | static u32 | |
8460 | ath12k_mac_prepare_he_mode(struct ath12k_pdev *pdev, u32 viftype) | |
8461 | { | |
8462 | struct ath12k_pdev_cap *pdev_cap = &pdev->cap; | |
8463 | struct ath12k_band_cap *cap_band = NULL; | |
8464 | u32 *hecap_phy_ptr = NULL; | |
8465 | u32 hemode; | |
8466 | ||
6a88093f | 8467 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2GHZ_CAP) |
d8899132 KV |
8468 | cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; |
8469 | else | |
8470 | cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; | |
8471 | ||
8472 | hecap_phy_ptr = &cap_band->he_cap_phy_info[0]; | |
8473 | ||
8474 | hemode = u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE) | | |
8475 | u32_encode_bits(HECAP_PHY_SUBFMR_GET(hecap_phy_ptr), | |
8476 | HE_MODE_SU_TX_BFER) | | |
8477 | u32_encode_bits(HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr), | |
8478 | HE_MODE_UL_MUMIMO); | |
8479 | ||
8480 | /* TODO: WDS and other modes */ | |
8481 | if (viftype == NL80211_IFTYPE_AP) { | |
8482 | hemode |= u32_encode_bits(HECAP_PHY_MUBFMR_GET(hecap_phy_ptr), | |
8483 | HE_MODE_MU_TX_BFER) | | |
8484 | u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) | | |
8485 | u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA); | |
8486 | } else { | |
8487 | hemode |= u32_encode_bits(HE_MU_BFEE_ENABLE, HE_MODE_MU_TX_BFEE); | |
8488 | } | |
8489 | ||
8490 | return hemode; | |
8491 | } | |
8492 | ||
8493 | static int ath12k_set_he_mu_sounding_mode(struct ath12k *ar, | |
3dd2c68f | 8494 | struct ath12k_link_vif *arvif) |
d8899132 KV |
8495 | { |
8496 | u32 param_id, param_value; | |
8497 | struct ath12k_base *ab = ar->ab; | |
3dd2c68f | 8498 | struct ath12k_vif *ahvif = arvif->ahvif; |
d8899132 KV |
8499 | int ret; |
8500 | ||
8501 | param_id = WMI_VDEV_PARAM_SET_HEMU_MODE; | |
3dd2c68f | 8502 | param_value = ath12k_mac_prepare_he_mode(ar->pdev, ahvif->vif->type); |
d8899132 KV |
8503 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
8504 | param_id, param_value); | |
8505 | if (ret) { | |
8506 | ath12k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n", | |
8507 | arvif->vdev_id, ret, param_value); | |
8508 | return ret; | |
8509 | } | |
8510 | param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE; | |
8511 | param_value = | |
8512 | u32_encode_bits(HE_VHT_SOUNDING_MODE_ENABLE, HE_VHT_SOUNDING_MODE) | | |
8513 | u32_encode_bits(HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE, | |
8514 | HE_TRIG_NONTRIG_SOUNDING_MODE); | |
8515 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
8516 | param_id, param_value); | |
8517 | if (ret) { | |
8518 | ath12k_warn(ab, "failed to set vdev %d HE MU mode: %d\n", | |
8519 | arvif->vdev_id, ret); | |
8520 | return ret; | |
8521 | } | |
8522 | return ret; | |
8523 | } | |
8524 | ||
3dd2c68f | 8525 | static void ath12k_mac_update_vif_offload(struct ath12k_link_vif *arvif) |
d8899132 | 8526 | { |
3dd2c68f S |
8527 | struct ath12k_vif *ahvif = arvif->ahvif; |
8528 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
92b30bb3 | 8529 | struct ath12k *ar = arvif->ar; |
d8899132 | 8530 | struct ath12k_base *ab = ar->ab; |
d8899132 KV |
8531 | u32 param_id, param_value; |
8532 | int ret; | |
8533 | ||
8534 | param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE; | |
8535 | if (vif->type != NL80211_IFTYPE_STATION && | |
8536 | vif->type != NL80211_IFTYPE_AP) | |
8537 | vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED | | |
8538 | IEEE80211_OFFLOAD_DECAP_ENABLED); | |
8539 | ||
8540 | if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED) | |
3dd2c68f | 8541 | ahvif->tx_encap_type = ATH12K_HW_TXRX_ETHERNET; |
d8899132 | 8542 | else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) |
3dd2c68f | 8543 | ahvif->tx_encap_type = ATH12K_HW_TXRX_RAW; |
d8899132 | 8544 | else |
3dd2c68f | 8545 | ahvif->tx_encap_type = ATH12K_HW_TXRX_NATIVE_WIFI; |
d8899132 KV |
8546 | |
8547 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3dd2c68f | 8548 | param_id, ahvif->tx_encap_type); |
d8899132 KV |
8549 | if (ret) { |
8550 | ath12k_warn(ab, "failed to set vdev %d tx encap mode: %d\n", | |
8551 | arvif->vdev_id, ret); | |
8552 | vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; | |
8553 | } | |
8554 | ||
8555 | param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE; | |
8556 | if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED) | |
8557 | param_value = ATH12K_HW_TXRX_ETHERNET; | |
8558 | else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) | |
8559 | param_value = ATH12K_HW_TXRX_RAW; | |
8560 | else | |
8561 | param_value = ATH12K_HW_TXRX_NATIVE_WIFI; | |
8562 | ||
8563 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
8564 | param_id, param_value); | |
8565 | if (ret) { | |
8566 | ath12k_warn(ab, "failed to set vdev %d rx decap mode: %d\n", | |
8567 | arvif->vdev_id, ret); | |
8568 | vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED; | |
8569 | } | |
8570 | } | |
8571 | ||
92b30bb3 KP |
8572 | static void ath12k_mac_op_update_vif_offload(struct ieee80211_hw *hw, |
8573 | struct ieee80211_vif *vif) | |
8574 | { | |
3dd2c68f | 8575 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
f4adb07e S |
8576 | struct ath12k_link_vif *arvif; |
8577 | unsigned long links; | |
8578 | int link_id; | |
92b30bb3 | 8579 | |
c347f181 KV |
8580 | lockdep_assert_wiphy(hw->wiphy); |
8581 | ||
f4adb07e S |
8582 | if (vif->valid_links) { |
8583 | links = vif->valid_links; | |
8584 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
8585 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
8586 | if (!(arvif && arvif->ar)) | |
8587 | continue; | |
8588 | ||
8589 | ath12k_mac_update_vif_offload(arvif); | |
8590 | } | |
8591 | ||
8592 | return; | |
8593 | } | |
8594 | ||
3dd2c68f | 8595 | ath12k_mac_update_vif_offload(&ahvif->deflink); |
92b30bb3 KP |
8596 | } |
8597 | ||
591de41d WG |
8598 | static bool ath12k_mac_vif_ap_active_any(struct ath12k_base *ab) |
8599 | { | |
8600 | struct ath12k *ar; | |
8601 | struct ath12k_pdev *pdev; | |
8602 | struct ath12k_link_vif *arvif; | |
8603 | int i; | |
8604 | ||
8605 | for (i = 0; i < ab->num_radios; i++) { | |
8606 | pdev = &ab->pdevs[i]; | |
8607 | ar = pdev->ar; | |
8608 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
8609 | if (arvif->is_up && | |
8610 | arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP) | |
8611 | return true; | |
8612 | } | |
8613 | } | |
8614 | return false; | |
8615 | } | |
8616 | ||
8617 | void ath12k_mac_11d_scan_start(struct ath12k *ar, u32 vdev_id) | |
8618 | { | |
8619 | struct wmi_11d_scan_start_arg arg; | |
8620 | int ret; | |
8621 | ||
8622 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
8623 | ||
8624 | if (ar->regdom_set_by_user) | |
8625 | goto fin; | |
8626 | ||
8627 | if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) | |
8628 | goto fin; | |
8629 | ||
8630 | if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) | |
8631 | goto fin; | |
8632 | ||
8633 | if (ath12k_mac_vif_ap_active_any(ar->ab)) | |
8634 | goto fin; | |
8635 | ||
8636 | arg.vdev_id = vdev_id; | |
8637 | arg.start_interval_msec = 0; | |
8638 | arg.scan_period_msec = ATH12K_SCAN_11D_INTERVAL; | |
8639 | ||
8640 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
8641 | "mac start 11d scan for vdev %d\n", vdev_id); | |
8642 | ||
8643 | ret = ath12k_wmi_send_11d_scan_start_cmd(ar, &arg); | |
8644 | if (ret) { | |
8645 | ath12k_warn(ar->ab, "failed to start 11d scan vdev %d ret: %d\n", | |
8646 | vdev_id, ret); | |
8647 | } else { | |
8648 | ar->vdev_id_11d_scan = vdev_id; | |
8649 | if (ar->state_11d == ATH12K_11D_PREPARING) | |
8650 | ar->state_11d = ATH12K_11D_RUNNING; | |
8651 | } | |
8652 | ||
8653 | fin: | |
8654 | if (ar->state_11d == ATH12K_11D_PREPARING) { | |
8655 | ar->state_11d = ATH12K_11D_IDLE; | |
8656 | complete(&ar->completed_11d_scan); | |
8657 | } | |
8658 | } | |
8659 | ||
8660 | void ath12k_mac_11d_scan_stop(struct ath12k *ar) | |
8661 | { | |
8662 | int ret; | |
8663 | u32 vdev_id; | |
8664 | ||
8665 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); | |
8666 | ||
8667 | if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) | |
8668 | return; | |
8669 | ||
8670 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac stop 11d for vdev %d\n", | |
8671 | ar->vdev_id_11d_scan); | |
8672 | ||
8673 | if (ar->state_11d == ATH12K_11D_PREPARING) { | |
8674 | ar->state_11d = ATH12K_11D_IDLE; | |
8675 | complete(&ar->completed_11d_scan); | |
8676 | } | |
8677 | ||
8678 | if (ar->vdev_id_11d_scan != ATH12K_11D_INVALID_VDEV_ID) { | |
8679 | vdev_id = ar->vdev_id_11d_scan; | |
8680 | ||
8681 | ret = ath12k_wmi_send_11d_scan_stop_cmd(ar, vdev_id); | |
8682 | if (ret) { | |
8683 | ath12k_warn(ar->ab, | |
8684 | "failed to stopt 11d scan vdev %d ret: %d\n", | |
8685 | vdev_id, ret); | |
8686 | } else { | |
8687 | ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID; | |
8688 | ar->state_11d = ATH12K_11D_IDLE; | |
8689 | complete(&ar->completed_11d_scan); | |
8690 | } | |
8691 | } | |
8692 | } | |
8693 | ||
8694 | void ath12k_mac_11d_scan_stop_all(struct ath12k_base *ab) | |
8695 | { | |
8696 | struct ath12k *ar; | |
8697 | struct ath12k_pdev *pdev; | |
8698 | int i; | |
8699 | ||
8700 | ath12k_dbg(ab, ATH12K_DBG_MAC, "mac stop soc 11d scan\n"); | |
8701 | ||
8702 | for (i = 0; i < ab->num_radios; i++) { | |
8703 | pdev = &ab->pdevs[i]; | |
8704 | ar = pdev->ar; | |
8705 | ||
8706 | ath12k_mac_11d_scan_stop(ar); | |
8707 | } | |
8708 | } | |
8709 | ||
ee2fc1f7 BQ |
8710 | static void ath12k_mac_determine_vdev_type(struct ieee80211_vif *vif, |
8711 | struct ath12k_vif *ahvif) | |
8712 | { | |
8713 | ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; | |
8714 | ||
8715 | switch (vif->type) { | |
8716 | case NL80211_IFTYPE_UNSPECIFIED: | |
8717 | case NL80211_IFTYPE_STATION: | |
8718 | ahvif->vdev_type = WMI_VDEV_TYPE_STA; | |
8719 | ||
8720 | if (vif->p2p) | |
8721 | ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; | |
8722 | ||
8723 | break; | |
8724 | case NL80211_IFTYPE_MESH_POINT: | |
8725 | ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S; | |
8726 | fallthrough; | |
8727 | case NL80211_IFTYPE_AP: | |
8728 | ahvif->vdev_type = WMI_VDEV_TYPE_AP; | |
8729 | ||
8730 | if (vif->p2p) | |
8731 | ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; | |
8732 | ||
8733 | break; | |
8734 | case NL80211_IFTYPE_MONITOR: | |
8735 | ahvif->vdev_type = WMI_VDEV_TYPE_MONITOR; | |
8736 | break; | |
8737 | case NL80211_IFTYPE_P2P_DEVICE: | |
8738 | ahvif->vdev_type = WMI_VDEV_TYPE_STA; | |
8739 | ahvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; | |
8740 | break; | |
8741 | default: | |
8742 | WARN_ON(1); | |
8743 | break; | |
8744 | } | |
8745 | } | |
8746 | ||
005fe43b | 8747 | int ath12k_mac_vdev_create(struct ath12k *ar, struct ath12k_link_vif *arvif) |
d8899132 | 8748 | { |
31487688 S |
8749 | struct ath12k_hw *ah = ar->ah; |
8750 | struct ath12k_base *ab = ar->ab; | |
8751 | struct ieee80211_hw *hw = ah->hw; | |
005fe43b S |
8752 | struct ath12k_vif *ahvif = arvif->ahvif; |
8753 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
d8899132 | 8754 | struct ath12k_wmi_vdev_create_arg vdev_arg = {0}; |
0660e1e2 | 8755 | struct ath12k_wmi_peer_create_arg peer_param = {0}; |
8dc8340c | 8756 | struct ieee80211_bss_conf *link_conf = NULL; |
d8899132 KV |
8757 | u32 param_id, param_value; |
8758 | u16 nss; | |
8759 | int i; | |
31487688 | 8760 | int ret, vdev_id; |
90570ba4 | 8761 | u8 link_id; |
d8899132 | 8762 | |
b8c67509 | 8763 | lockdep_assert_wiphy(hw->wiphy); |
d8899132 | 8764 | |
2c4c3aff P |
8765 | /* In NO_VIRTUAL_MONITOR, its necessary to restrict only one monitor |
8766 | * interface in each radio | |
8767 | */ | |
8768 | if (vif->type == NL80211_IFTYPE_MONITOR && ar->monitor_vdev_created) | |
8769 | return -EINVAL; | |
8770 | ||
8dc8340c | 8771 | link_id = arvif->link_id; |
90570ba4 | 8772 | |
8dc8340c AKS |
8773 | if (link_id < IEEE80211_MLD_MAX_NUM_LINKS) { |
8774 | link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]); | |
8775 | if (!link_conf) { | |
8776 | ath12k_warn(ar->ab, "unable to access bss link conf in vdev create for vif %pM link %u\n", | |
8777 | vif->addr, arvif->link_id); | |
8778 | return -ENOLINK; | |
8779 | } | |
477cabfd S |
8780 | } |
8781 | ||
8dc8340c AKS |
8782 | if (link_conf) |
8783 | memcpy(arvif->bssid, link_conf->addr, ETH_ALEN); | |
8784 | else | |
8785 | memcpy(arvif->bssid, vif->addr, ETH_ALEN); | |
d8899132 KV |
8786 | |
8787 | arvif->ar = ar; | |
31487688 S |
8788 | vdev_id = __ffs64(ab->free_vdev_map); |
8789 | arvif->vdev_id = vdev_id; | |
ee2fc1f7 | 8790 | if (vif->type == NL80211_IFTYPE_MONITOR) |
31487688 | 8791 | ar->monitor_vdev_id = vdev_id; |
d8899132 | 8792 | |
31487688 | 8793 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev create id %d type %d subtype %d map %llx\n", |
3dd2c68f | 8794 | arvif->vdev_id, ahvif->vdev_type, ahvif->vdev_subtype, |
d8899132 KV |
8795 | ab->free_vdev_map); |
8796 | ||
8797 | vif->cab_queue = arvif->vdev_id % (ATH12K_HW_MAX_QUEUES - 1); | |
8798 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) | |
8799 | vif->hw_queue[i] = i % (ATH12K_HW_MAX_QUEUES - 1); | |
8800 | ||
ea68f1bb AD |
8801 | ret = ath12k_mac_setup_vdev_create_arg(arvif, &vdev_arg); |
8802 | if (ret) { | |
8803 | ath12k_warn(ab, "failed to create vdev parameters %d: %d\n", | |
8804 | arvif->vdev_id, ret); | |
8805 | goto err; | |
8806 | } | |
d8899132 | 8807 | |
477cabfd | 8808 | ret = ath12k_wmi_vdev_create(ar, arvif->bssid, &vdev_arg); |
d8899132 KV |
8809 | if (ret) { |
8810 | ath12k_warn(ab, "failed to create WMI vdev %d: %d\n", | |
8811 | arvif->vdev_id, ret); | |
31489439 | 8812 | return ret; |
d8899132 KV |
8813 | } |
8814 | ||
8815 | ar->num_created_vdevs++; | |
31487688 | 8816 | arvif->is_created = true; |
d8899132 KV |
8817 | ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM created, vdev_id %d\n", |
8818 | vif->addr, arvif->vdev_id); | |
8819 | ar->allocated_vdev_map |= 1LL << arvif->vdev_id; | |
8820 | ab->free_vdev_map &= ~(1LL << arvif->vdev_id); | |
8821 | ||
8822 | spin_lock_bh(&ar->data_lock); | |
8823 | list_add(&arvif->list, &ar->arvifs); | |
8824 | spin_unlock_bh(&ar->data_lock); | |
8825 | ||
92b30bb3 | 8826 | ath12k_mac_update_vif_offload(arvif); |
d8899132 KV |
8827 | |
8828 | nss = hweight32(ar->cfg_tx_chainmask) ? : 1; | |
8829 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
8830 | WMI_VDEV_PARAM_NSS, nss); | |
8831 | if (ret) { | |
8832 | ath12k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", | |
8833 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret); | |
8834 | goto err_vdev_del; | |
8835 | } | |
8836 | ||
3dd2c68f | 8837 | switch (ahvif->vdev_type) { |
d8899132 KV |
8838 | case WMI_VDEV_TYPE_AP: |
8839 | peer_param.vdev_id = arvif->vdev_id; | |
477cabfd | 8840 | peer_param.peer_addr = arvif->bssid; |
d8899132 KV |
8841 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; |
8842 | ret = ath12k_peer_create(ar, arvif, NULL, &peer_param); | |
8843 | if (ret) { | |
8844 | ath12k_warn(ab, "failed to vdev %d create peer for AP: %d\n", | |
8845 | arvif->vdev_id, ret); | |
8846 | goto err_vdev_del; | |
8847 | } | |
8848 | ||
8849 | ret = ath12k_mac_set_kickout(arvif); | |
8850 | if (ret) { | |
8851 | ath12k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n", | |
8852 | arvif->vdev_id, ret); | |
8853 | goto err_peer_del; | |
8854 | } | |
591de41d | 8855 | ath12k_mac_11d_scan_stop_all(ar->ab); |
d8899132 KV |
8856 | break; |
8857 | case WMI_VDEV_TYPE_STA: | |
8858 | param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY; | |
8859 | param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
8860 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
8861 | param_id, param_value); | |
8862 | if (ret) { | |
8863 | ath12k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n", | |
8864 | arvif->vdev_id, ret); | |
8865 | goto err_peer_del; | |
8866 | } | |
8867 | ||
8868 | param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; | |
8869 | param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; | |
8870 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
8871 | param_id, param_value); | |
8872 | if (ret) { | |
8873 | ath12k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n", | |
8874 | arvif->vdev_id, ret); | |
8875 | goto err_peer_del; | |
8876 | } | |
8877 | ||
8878 | param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT; | |
8879 | param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; | |
8880 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
8881 | param_id, param_value); | |
8882 | if (ret) { | |
8883 | ath12k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n", | |
8884 | arvif->vdev_id, ret); | |
8885 | goto err_peer_del; | |
8886 | } | |
8887 | ||
8888 | ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false); | |
8889 | if (ret) { | |
8890 | ath12k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n", | |
8891 | arvif->vdev_id, ret); | |
8892 | goto err_peer_del; | |
8893 | } | |
591de41d WG |
8894 | |
8895 | if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) && | |
8896 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
8897 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) { | |
8898 | reinit_completion(&ar->completed_11d_scan); | |
8899 | ar->state_11d = ATH12K_11D_PREPARING; | |
8900 | } | |
d8899132 | 8901 | break; |
2c4c3aff P |
8902 | case WMI_VDEV_TYPE_MONITOR: |
8903 | ar->monitor_vdev_created = true; | |
d8899132 KV |
8904 | break; |
8905 | default: | |
8906 | break; | |
8907 | } | |
8908 | ||
8dc8340c AKS |
8909 | if (link_conf) |
8910 | arvif->txpower = link_conf->txpower; | |
8911 | else | |
8912 | arvif->txpower = NL80211_TX_POWER_AUTOMATIC; | |
8913 | ||
d8899132 KV |
8914 | ret = ath12k_mac_txpower_recalc(ar); |
8915 | if (ret) | |
8916 | goto err_peer_del; | |
8917 | ||
8918 | param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
842addae | 8919 | param_value = hw->wiphy->rts_threshold; |
d8899132 KV |
8920 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, |
8921 | param_id, param_value); | |
8922 | if (ret) { | |
8923 | ath12k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n", | |
8924 | arvif->vdev_id, ret); | |
8925 | } | |
8926 | ||
8927 | ath12k_dp_vdev_tx_attach(ar, arvif); | |
d8899132 | 8928 | |
d8899132 KV |
8929 | return ret; |
8930 | ||
8931 | err_peer_del: | |
3dd2c68f | 8932 | if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
d8899132 KV |
8933 | reinit_completion(&ar->peer_delete_done); |
8934 | ||
477cabfd | 8935 | ret = ath12k_wmi_send_peer_delete_cmd(ar, arvif->bssid, |
d8899132 KV |
8936 | arvif->vdev_id); |
8937 | if (ret) { | |
8938 | ath12k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n", | |
477cabfd | 8939 | arvif->vdev_id, arvif->bssid); |
d8899132 KV |
8940 | goto err; |
8941 | } | |
8942 | ||
8943 | ret = ath12k_wait_for_peer_delete_done(ar, arvif->vdev_id, | |
477cabfd | 8944 | arvif->bssid); |
d8899132 | 8945 | if (ret) |
757cc465 | 8946 | goto err_vdev_del; |
d8899132 KV |
8947 | |
8948 | ar->num_peers--; | |
8949 | } | |
8950 | ||
8951 | err_vdev_del: | |
2c4c3aff P |
8952 | if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
8953 | ar->monitor_vdev_id = -1; | |
8954 | ar->monitor_vdev_created = false; | |
8955 | } | |
8956 | ||
d8899132 KV |
8957 | ath12k_wmi_vdev_delete(ar, arvif->vdev_id); |
8958 | ar->num_created_vdevs--; | |
31487688 | 8959 | arvif->is_created = false; |
0d6e6736 | 8960 | arvif->ar = NULL; |
d8899132 KV |
8961 | ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); |
8962 | ab->free_vdev_map |= 1LL << arvif->vdev_id; | |
8963 | ab->free_vdev_stats_id_map &= ~(1LL << arvif->vdev_stats_id); | |
8964 | spin_lock_bh(&ar->data_lock); | |
8965 | list_del(&arvif->list); | |
8966 | spin_unlock_bh(&ar->data_lock); | |
8967 | ||
8968 | err: | |
31487688 S |
8969 | arvif->ar = NULL; |
8970 | return ret; | |
8971 | } | |
8972 | ||
25e18b9d RS |
8973 | static void ath12k_mac_vif_flush_key_cache(struct ath12k_link_vif *arvif) |
8974 | { | |
8975 | struct ath12k_key_conf *key_conf, *tmp; | |
8976 | struct ath12k_vif *ahvif = arvif->ahvif; | |
8977 | struct ath12k_hw *ah = ahvif->ah; | |
8978 | struct ath12k_sta *ahsta; | |
8979 | struct ath12k_link_sta *arsta; | |
8980 | struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id]; | |
8981 | int ret; | |
8982 | ||
8983 | lockdep_assert_wiphy(ah->hw->wiphy); | |
8984 | ||
8985 | list_for_each_entry_safe(key_conf, tmp, &cache->key_conf.list, list) { | |
8986 | arsta = NULL; | |
8987 | if (key_conf->sta) { | |
8988 | ahsta = ath12k_sta_to_ahsta(key_conf->sta); | |
8989 | arsta = wiphy_dereference(ah->hw->wiphy, | |
8990 | ahsta->link[arvif->link_id]); | |
8991 | if (!arsta) | |
8992 | goto free_cache; | |
8993 | } | |
8994 | ||
8995 | ret = ath12k_mac_set_key(arvif->ar, key_conf->cmd, | |
8996 | arvif, arsta, | |
8997 | key_conf->key); | |
8998 | if (ret) | |
8999 | ath12k_warn(arvif->ar->ab, "unable to apply set key param to vdev %d ret %d\n", | |
9000 | arvif->vdev_id, ret); | |
9001 | free_cache: | |
9002 | list_del(&key_conf->list); | |
9003 | kfree(key_conf); | |
9004 | } | |
9005 | } | |
9006 | ||
84c59710 | 9007 | static void ath12k_mac_vif_cache_flush(struct ath12k *ar, struct ath12k_link_vif *arvif) |
b5068bc9 | 9008 | { |
84c59710 RS |
9009 | struct ath12k_vif *ahvif = arvif->ahvif; |
9010 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
9011 | struct ath12k_vif_cache *cache = ahvif->cache[arvif->link_id]; | |
b5068bc9 | 9012 | struct ath12k_base *ab = ar->ab; |
11d963d4 | 9013 | struct ieee80211_bss_conf *link_conf; |
b5068bc9 S |
9014 | |
9015 | int ret; | |
9016 | ||
b8c67509 | 9017 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
b5068bc9 S |
9018 | |
9019 | if (!cache) | |
9020 | return; | |
9021 | ||
9022 | if (cache->tx_conf.changed) { | |
af41f908 | 9023 | ret = ath12k_mac_conf_tx(arvif, cache->tx_conf.ac, |
b5068bc9 S |
9024 | &cache->tx_conf.tx_queue_params); |
9025 | if (ret) | |
9026 | ath12k_warn(ab, | |
9027 | "unable to apply tx config parameters to vdev %d\n", | |
9028 | ret); | |
9029 | } | |
9030 | ||
9031 | if (cache->bss_conf_changed) { | |
11d963d4 BQ |
9032 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
9033 | if (!link_conf) { | |
9034 | ath12k_warn(ar->ab, "unable to access bss link conf in cache flush for vif %pM link %u\n", | |
9035 | vif->addr, arvif->link_id); | |
9036 | return; | |
9037 | } | |
9038 | ath12k_mac_bss_info_changed(ar, arvif, link_conf, | |
b5068bc9 S |
9039 | cache->bss_conf_changed); |
9040 | } | |
9041 | ||
25e18b9d RS |
9042 | if (!list_empty(&cache->key_conf.list)) |
9043 | ath12k_mac_vif_flush_key_cache(arvif); | |
9044 | ||
84c59710 | 9045 | ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); |
b5068bc9 S |
9046 | } |
9047 | ||
31487688 | 9048 | static struct ath12k *ath12k_mac_assign_vif_to_vdev(struct ieee80211_hw *hw, |
005fe43b | 9049 | struct ath12k_link_vif *arvif, |
31487688 S |
9050 | struct ieee80211_chanctx_conf *ctx) |
9051 | { | |
90570ba4 S |
9052 | struct ath12k_vif *ahvif = arvif->ahvif; |
9053 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
9054 | struct ath12k_link_vif *scan_arvif; | |
31487688 | 9055 | struct ath12k_hw *ah = hw->priv; |
477cabfd | 9056 | struct ath12k *ar; |
31487688 | 9057 | struct ath12k_base *ab; |
477cabfd | 9058 | u8 link_id = arvif->link_id; |
31487688 S |
9059 | int ret; |
9060 | ||
b8c67509 KV |
9061 | lockdep_assert_wiphy(hw->wiphy); |
9062 | ||
31487688 S |
9063 | if (ah->num_radio == 1) |
9064 | ar = ah->radio; | |
9065 | else if (ctx) | |
9066 | ar = ath12k_get_ar_by_ctx(hw, ctx); | |
9067 | else | |
9068 | return NULL; | |
9069 | ||
9070 | if (!ar) | |
9071 | return NULL; | |
9072 | ||
90570ba4 S |
9073 | /* cleanup the scan vdev if we are done scan on that ar |
9074 | * and now we want to create for actual usage. | |
9075 | */ | |
9076 | if (ieee80211_vif_is_mld(vif)) { | |
9077 | scan_arvif = wiphy_dereference(hw->wiphy, | |
9078 | ahvif->link[ATH12K_DEFAULT_SCAN_LINK]); | |
9079 | if (scan_arvif && scan_arvif->ar == ar) { | |
3863f014 | 9080 | ar->scan.arvif = NULL; |
90570ba4 S |
9081 | ath12k_mac_remove_link_interface(hw, scan_arvif); |
9082 | ath12k_mac_unassign_link_vif(scan_arvif); | |
9083 | } | |
9084 | } | |
9085 | ||
0d6e6736 S |
9086 | if (arvif->ar) { |
9087 | /* This is not expected really */ | |
9088 | if (WARN_ON(!arvif->is_created)) { | |
9089 | arvif->ar = NULL; | |
9090 | return NULL; | |
9091 | } | |
9092 | ||
9093 | if (ah->num_radio == 1) | |
9094 | return arvif->ar; | |
9095 | ||
9096 | /* This can happen as scan vdev gets created during multiple scans | |
9097 | * across different radios before a vdev is brought up in | |
9098 | * a certain radio. | |
9099 | */ | |
9100 | if (ar != arvif->ar) { | |
9101 | if (WARN_ON(arvif->is_started)) | |
9102 | return NULL; | |
9103 | ||
477cabfd S |
9104 | ath12k_mac_remove_link_interface(hw, arvif); |
9105 | ath12k_mac_unassign_link_vif(arvif); | |
0d6e6736 S |
9106 | } |
9107 | } | |
9108 | ||
31487688 S |
9109 | ab = ar->ab; |
9110 | ||
477cabfd S |
9111 | /* Assign arvif again here since previous radio switch block |
9112 | * would've unassigned and cleared it. | |
9113 | */ | |
9114 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); | |
31487688 S |
9115 | if (vif->type == NL80211_IFTYPE_AP && |
9116 | ar->num_peers > (ar->max_num_peers - 1)) { | |
9117 | ath12k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n"); | |
9118 | goto unlock; | |
9119 | } | |
9120 | ||
5a10971c AKS |
9121 | if (arvif->is_created) |
9122 | goto flush; | |
9123 | ||
31487688 S |
9124 | if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) { |
9125 | ath12k_warn(ab, "failed to create vdev, reached max vdev limit %d\n", | |
9126 | TARGET_NUM_VDEVS); | |
9127 | goto unlock; | |
9128 | } | |
9129 | ||
005fe43b | 9130 | ret = ath12k_mac_vdev_create(ar, arvif); |
31487688 S |
9131 | if (ret) { |
9132 | ath12k_warn(ab, "failed to create vdev %pM ret %d", vif->addr, ret); | |
9133 | goto unlock; | |
9134 | } | |
9135 | ||
b5068bc9 S |
9136 | flush: |
9137 | /* If the vdev is created during channel assign and not during | |
31487688 S |
9138 | * add_interface(), Apply any parameters for the vdev which were received |
9139 | * after add_interface, corresponding to this vif. | |
9140 | */ | |
005fe43b | 9141 | ath12k_mac_vif_cache_flush(ar, arvif); |
31487688 | 9142 | unlock: |
31487688 S |
9143 | return arvif->ar; |
9144 | } | |
d8899132 | 9145 | |
31487688 S |
9146 | static int ath12k_mac_op_add_interface(struct ieee80211_hw *hw, |
9147 | struct ieee80211_vif *vif) | |
9148 | { | |
3dd2c68f S |
9149 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
9150 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); | |
4c546023 | 9151 | struct ath12k_reg_info *reg_info; |
3dd2c68f | 9152 | struct ath12k_link_vif *arvif; |
4c546023 BQ |
9153 | struct ath12k_base *ab; |
9154 | struct ath12k *ar; | |
31487688 S |
9155 | int i; |
9156 | ||
b8c67509 | 9157 | lockdep_assert_wiphy(hw->wiphy); |
31487688 | 9158 | |
3dd2c68f | 9159 | memset(ahvif, 0, sizeof(*ahvif)); |
31487688 | 9160 | |
3dd2c68f S |
9161 | ahvif->ah = ah; |
9162 | ahvif->vif = vif; | |
9163 | arvif = &ahvif->deflink; | |
31487688 | 9164 | |
8acc7ec5 | 9165 | ath12k_mac_init_arvif(ahvif, arvif, -1); |
31487688 S |
9166 | |
9167 | /* Allocate Default Queue now and reassign during actual vdev create */ | |
9168 | vif->cab_queue = ATH12K_HW_DEFAULT_QUEUE; | |
9169 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) | |
9170 | vif->hw_queue[i] = ATH12K_HW_DEFAULT_QUEUE; | |
9171 | ||
9172 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; | |
ee2fc1f7 BQ |
9173 | |
9174 | ath12k_mac_determine_vdev_type(vif, ahvif); | |
9175 | ||
4c546023 BQ |
9176 | for_each_ar(ah, ar, i) { |
9177 | if (!ath12k_wmi_supports_6ghz_cc_ext(ar)) | |
9178 | continue; | |
9179 | ||
9180 | ab = ar->ab; | |
9181 | reg_info = ab->reg_info[ar->pdev_idx]; | |
9182 | ath12k_dbg(ab, ATH12K_DBG_MAC, "interface added to change reg rules\n"); | |
37e775a0 | 9183 | ah->regd_updated = false; |
4c546023 BQ |
9184 | ath12k_reg_handle_chan_list(ab, reg_info, ahvif->vdev_type, |
9185 | IEEE80211_REG_UNSET_AP); | |
9186 | break; | |
9187 | } | |
9188 | ||
aa80f12f | 9189 | /* Defer vdev creation until assign_chanctx or hw_scan is initiated as driver |
477cabfd | 9190 | * will not know if this interface is an ML vif at this point. |
31487688 | 9191 | */ |
31487688 | 9192 | return 0; |
d8899132 KV |
9193 | } |
9194 | ||
9195 | static void ath12k_mac_vif_unref(struct ath12k_dp *dp, struct ieee80211_vif *vif) | |
9196 | { | |
89a9dda1 | 9197 | struct ath12k_tx_desc_info *tx_desc_info; |
d8899132 KV |
9198 | struct ath12k_skb_cb *skb_cb; |
9199 | struct sk_buff *skb; | |
9200 | int i; | |
9201 | ||
9202 | for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) { | |
9203 | spin_lock_bh(&dp->tx_desc_lock[i]); | |
9204 | ||
89a9dda1 DA |
9205 | list_for_each_entry(tx_desc_info, &dp->tx_desc_used_list[i], |
9206 | list) { | |
d8899132 KV |
9207 | skb = tx_desc_info->skb; |
9208 | if (!skb) | |
9209 | continue; | |
9210 | ||
9211 | skb_cb = ATH12K_SKB_CB(skb); | |
9212 | if (skb_cb->vif == vif) | |
9213 | skb_cb->vif = NULL; | |
9214 | } | |
9215 | ||
9216 | spin_unlock_bh(&dp->tx_desc_lock[i]); | |
9217 | } | |
9218 | } | |
9219 | ||
005fe43b | 9220 | static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvif) |
d8899132 | 9221 | { |
005fe43b S |
9222 | struct ath12k_vif *ahvif = arvif->ahvif; |
9223 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(ahvif); | |
0d6e6736 | 9224 | struct ath12k_base *ab = ar->ab; |
d8899132 KV |
9225 | unsigned long time_left; |
9226 | int ret; | |
9227 | ||
b8c67509 | 9228 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
3dd2c68f | 9229 | |
d8899132 KV |
9230 | reinit_completion(&ar->vdev_delete_done); |
9231 | ||
9232 | ret = ath12k_wmi_vdev_delete(ar, arvif->vdev_id); | |
9233 | if (ret) { | |
9234 | ath12k_warn(ab, "failed to delete WMI vdev %d: %d\n", | |
9235 | arvif->vdev_id, ret); | |
9236 | goto err_vdev_del; | |
9237 | } | |
9238 | ||
9239 | time_left = wait_for_completion_timeout(&ar->vdev_delete_done, | |
9240 | ATH12K_VDEV_DELETE_TIMEOUT_HZ); | |
9241 | if (time_left == 0) { | |
9242 | ath12k_warn(ab, "Timeout in receiving vdev delete response\n"); | |
9243 | goto err_vdev_del; | |
9244 | } | |
9245 | ||
0d6e6736 S |
9246 | ab->free_vdev_map |= 1LL << arvif->vdev_id; |
9247 | ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); | |
9248 | ar->num_created_vdevs--; | |
9249 | ||
3dd2c68f | 9250 | if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
d8899132 KV |
9251 | ar->monitor_vdev_id = -1; |
9252 | ar->monitor_vdev_created = false; | |
d8899132 KV |
9253 | } |
9254 | ||
d8899132 KV |
9255 | ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n", |
9256 | vif->addr, arvif->vdev_id); | |
9257 | ||
9258 | err_vdev_del: | |
9259 | spin_lock_bh(&ar->data_lock); | |
9260 | list_del(&arvif->list); | |
9261 | spin_unlock_bh(&ar->data_lock); | |
9262 | ||
9263 | ath12k_peer_cleanup(ar, arvif->vdev_id); | |
84c59710 | 9264 | ath12k_ahvif_put_link_cache(ahvif, arvif->link_id); |
d8899132 KV |
9265 | |
9266 | idr_for_each(&ar->txmgmt_idr, | |
9267 | ath12k_mac_vif_txmgmt_idr_remove, vif); | |
9268 | ||
9269 | ath12k_mac_vif_unref(&ab->dp, vif); | |
9270 | ath12k_dp_tx_put_bank_profile(&ab->dp, arvif->bank_id); | |
9271 | ||
9272 | /* Recalc txpower for remaining vdev */ | |
9273 | ath12k_mac_txpower_recalc(ar); | |
d8899132 KV |
9274 | |
9275 | /* TODO: recal traffic pause state based on the available vdevs */ | |
0d6e6736 S |
9276 | arvif->is_created = false; |
9277 | arvif->ar = NULL; | |
9278 | ||
9279 | return ret; | |
9280 | } | |
9281 | ||
9282 | static void ath12k_mac_op_remove_interface(struct ieee80211_hw *hw, | |
9283 | struct ieee80211_vif *vif) | |
9284 | { | |
3dd2c68f S |
9285 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
9286 | struct ath12k_link_vif *arvif; | |
3863f014 | 9287 | struct ath12k *ar; |
477cabfd | 9288 | u8 link_id; |
0d6e6736 | 9289 | |
b8c67509 KV |
9290 | lockdep_assert_wiphy(hw->wiphy); |
9291 | ||
90570ba4 | 9292 | for (link_id = 0; link_id < ATH12K_NUM_MAX_LINKS; link_id++) { |
b5068bc9 S |
9293 | /* if we cached some config but never received assign chanctx, |
9294 | * free the allocated cache. | |
9295 | */ | |
477cabfd S |
9296 | ath12k_ahvif_put_link_cache(ahvif, link_id); |
9297 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
9298 | if (!arvif || !arvif->is_created) | |
9299 | continue; | |
0d6e6736 | 9300 | |
3863f014 AKS |
9301 | ar = arvif->ar; |
9302 | ||
9303 | /* Scan abortion is in progress since before this, cancel_hw_scan() | |
9304 | * is expected to be executed. Since link is anyways going to be removed | |
9305 | * now, just cancel the worker and send the scan aborted to user space | |
9306 | */ | |
9307 | if (ar->scan.arvif == arvif) { | |
9308 | wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk); | |
9309 | ||
9310 | spin_lock_bh(&ar->data_lock); | |
9311 | ar->scan.arvif = NULL; | |
9312 | if (!ar->scan.is_roc) { | |
9313 | struct cfg80211_scan_info info = { | |
9314 | .aborted = true, | |
9315 | }; | |
9316 | ||
9317 | ieee80211_scan_completed(ar->ah->hw, &info); | |
9318 | } | |
9319 | ||
9320 | ar->scan.state = ATH12K_SCAN_IDLE; | |
9321 | ar->scan_channel = NULL; | |
9322 | ar->scan.roc_freq = 0; | |
9323 | spin_unlock_bh(&ar->data_lock); | |
9324 | } | |
9325 | ||
477cabfd S |
9326 | ath12k_mac_remove_link_interface(hw, arvif); |
9327 | ath12k_mac_unassign_link_vif(arvif); | |
0d6e6736 | 9328 | } |
d8899132 KV |
9329 | } |
9330 | ||
9331 | /* FIXME: Has to be verified. */ | |
9332 | #define SUPPORTED_FILTERS \ | |
9333 | (FIF_ALLMULTI | \ | |
9334 | FIF_CONTROL | \ | |
9335 | FIF_PSPOLL | \ | |
9336 | FIF_OTHER_BSS | \ | |
9337 | FIF_BCN_PRBRESP_PROMISC | \ | |
9338 | FIF_PROBE_REQ | \ | |
9339 | FIF_FCSFAIL) | |
9340 | ||
d629b0c1 KP |
9341 | static void ath12k_mac_op_configure_filter(struct ieee80211_hw *hw, |
9342 | unsigned int changed_flags, | |
9343 | unsigned int *total_flags, | |
9344 | u64 multicast) | |
9345 | { | |
6db6e70a KP |
9346 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
9347 | struct ath12k *ar; | |
9348 | ||
b8c67509 | 9349 | lockdep_assert_wiphy(hw->wiphy); |
d629b0c1 | 9350 | |
c347f181 | 9351 | ar = ath12k_ah_to_ar(ah, 0); |
d629b0c1 KP |
9352 | |
9353 | *total_flags &= SUPPORTED_FILTERS; | |
6e8c9ba7 | 9354 | ar->filter_flags = *total_flags; |
d8899132 KV |
9355 | } |
9356 | ||
9357 | static int ath12k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) | |
9358 | { | |
6db6e70a | 9359 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
5a6af83c | 9360 | int antennas_rx = 0, antennas_tx = 0; |
6db6e70a | 9361 | struct ath12k *ar; |
5a6af83c | 9362 | int i; |
6db6e70a | 9363 | |
b8c67509 KV |
9364 | lockdep_assert_wiphy(hw->wiphy); |
9365 | ||
5a6af83c | 9366 | for_each_ar(ah, ar, i) { |
5a6af83c S |
9367 | antennas_rx = max_t(u32, antennas_rx, ar->cfg_rx_chainmask); |
9368 | antennas_tx = max_t(u32, antennas_tx, ar->cfg_tx_chainmask); | |
5a6af83c | 9369 | } |
d8899132 | 9370 | |
5a6af83c S |
9371 | *tx_ant = antennas_tx; |
9372 | *rx_ant = antennas_rx; | |
d8899132 KV |
9373 | |
9374 | return 0; | |
9375 | } | |
9376 | ||
9377 | static int ath12k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) | |
9378 | { | |
6db6e70a KP |
9379 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
9380 | struct ath12k *ar; | |
5a6af83c S |
9381 | int ret = 0; |
9382 | int i; | |
6db6e70a | 9383 | |
b8c67509 KV |
9384 | lockdep_assert_wiphy(hw->wiphy); |
9385 | ||
5a6af83c | 9386 | for_each_ar(ah, ar, i) { |
5a6af83c | 9387 | ret = __ath12k_set_antenna(ar, tx_ant, rx_ant); |
5a6af83c S |
9388 | if (ret) |
9389 | break; | |
9390 | } | |
d8899132 KV |
9391 | |
9392 | return ret; | |
9393 | } | |
9394 | ||
5419ef95 S |
9395 | static int ath12k_mac_ampdu_action(struct ieee80211_hw *hw, |
9396 | struct ieee80211_vif *vif, | |
9397 | struct ieee80211_ampdu_params *params, | |
9398 | u8 link_id) | |
d8899132 | 9399 | { |
5419ef95 | 9400 | struct ath12k *ar; |
d8899132 KV |
9401 | int ret = -EINVAL; |
9402 | ||
5419ef95 S |
9403 | lockdep_assert_wiphy(hw->wiphy); |
9404 | ||
9405 | ar = ath12k_get_ar_by_vif(hw, vif, link_id); | |
9406 | if (!ar) | |
9407 | return -EINVAL; | |
d8899132 KV |
9408 | |
9409 | switch (params->action) { | |
9410 | case IEEE80211_AMPDU_RX_START: | |
5419ef95 | 9411 | ret = ath12k_dp_rx_ampdu_start(ar, params, link_id); |
d8899132 KV |
9412 | break; |
9413 | case IEEE80211_AMPDU_RX_STOP: | |
5419ef95 | 9414 | ret = ath12k_dp_rx_ampdu_stop(ar, params, link_id); |
d8899132 KV |
9415 | break; |
9416 | case IEEE80211_AMPDU_TX_START: | |
9417 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
9418 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
9419 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
9420 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
9421 | /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211 | |
9422 | * Tx aggregation requests. | |
9423 | */ | |
9424 | ret = -EOPNOTSUPP; | |
9425 | break; | |
9426 | } | |
9427 | ||
5419ef95 S |
9428 | if (ret) |
9429 | ath12k_warn(ar->ab, "unable to perform ampdu action %d for vif %pM link %u ret %d\n", | |
9430 | params->action, vif->addr, link_id, ret); | |
9431 | ||
5b1b5dbf KP |
9432 | return ret; |
9433 | } | |
9434 | ||
9435 | static int ath12k_mac_op_ampdu_action(struct ieee80211_hw *hw, | |
9436 | struct ieee80211_vif *vif, | |
9437 | struct ieee80211_ampdu_params *params) | |
9438 | { | |
5419ef95 S |
9439 | struct ieee80211_sta *sta = params->sta; |
9440 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); | |
9441 | unsigned long links_map = ahsta->links_map; | |
5b1b5dbf | 9442 | int ret = -EINVAL; |
5419ef95 | 9443 | u8 link_id; |
5b1b5dbf | 9444 | |
c347f181 KV |
9445 | lockdep_assert_wiphy(hw->wiphy); |
9446 | ||
5419ef95 S |
9447 | if (WARN_ON(!links_map)) |
9448 | return ret; | |
6db6e70a | 9449 | |
5419ef95 S |
9450 | for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { |
9451 | ret = ath12k_mac_ampdu_action(hw, vif, params, link_id); | |
9452 | if (ret) | |
9453 | return ret; | |
9454 | } | |
5b1b5dbf | 9455 | |
5419ef95 | 9456 | return 0; |
d8899132 KV |
9457 | } |
9458 | ||
9459 | static int ath12k_mac_op_add_chanctx(struct ieee80211_hw *hw, | |
9460 | struct ieee80211_chanctx_conf *ctx) | |
9461 | { | |
6db6e70a KP |
9462 | struct ath12k *ar; |
9463 | struct ath12k_base *ab; | |
9464 | ||
c347f181 KV |
9465 | lockdep_assert_wiphy(hw->wiphy); |
9466 | ||
d01c08ed S |
9467 | ar = ath12k_get_ar_by_ctx(hw, ctx); |
9468 | if (!ar) | |
9469 | return -EINVAL; | |
9470 | ||
6db6e70a | 9471 | ab = ar->ab; |
d8899132 KV |
9472 | |
9473 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
2372c6d2 | 9474 | "mac chanctx add freq %u width %d ptr %p\n", |
d8899132 KV |
9475 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
9476 | ||
d8899132 KV |
9477 | spin_lock_bh(&ar->data_lock); |
9478 | /* TODO: In case of multiple channel context, populate rx_channel from | |
9479 | * Rx PPDU desc information. | |
9480 | */ | |
9481 | ar->rx_channel = ctx->def.chan; | |
9482 | spin_unlock_bh(&ar->data_lock); | |
e92c658b | 9483 | ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; |
d8899132 | 9484 | |
d8899132 KV |
9485 | return 0; |
9486 | } | |
9487 | ||
9488 | static void ath12k_mac_op_remove_chanctx(struct ieee80211_hw *hw, | |
9489 | struct ieee80211_chanctx_conf *ctx) | |
9490 | { | |
6db6e70a KP |
9491 | struct ath12k *ar; |
9492 | struct ath12k_base *ab; | |
9493 | ||
c347f181 KV |
9494 | lockdep_assert_wiphy(hw->wiphy); |
9495 | ||
d01c08ed S |
9496 | ar = ath12k_get_ar_by_ctx(hw, ctx); |
9497 | if (!ar) | |
9498 | return; | |
9499 | ||
6db6e70a | 9500 | ab = ar->ab; |
d8899132 KV |
9501 | |
9502 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
2372c6d2 | 9503 | "mac chanctx remove freq %u width %d ptr %p\n", |
d8899132 KV |
9504 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
9505 | ||
d8899132 KV |
9506 | spin_lock_bh(&ar->data_lock); |
9507 | /* TODO: In case of there is one more channel context left, populate | |
9508 | * rx_channel with the channel of that remaining channel context. | |
9509 | */ | |
9510 | ar->rx_channel = NULL; | |
9511 | spin_unlock_bh(&ar->data_lock); | |
e92c658b | 9512 | ar->chan_tx_pwr = ATH12K_PDEV_TX_POWER_INVALID; |
d8899132 KV |
9513 | } |
9514 | ||
972754bf WG |
9515 | static enum wmi_phy_mode |
9516 | ath12k_mac_check_down_grade_phy_mode(struct ath12k *ar, | |
9517 | enum wmi_phy_mode mode, | |
9518 | enum nl80211_band band, | |
9519 | enum nl80211_iftype type) | |
9520 | { | |
bf76b144 | 9521 | struct ieee80211_sta_eht_cap *eht_cap = NULL; |
972754bf | 9522 | enum wmi_phy_mode down_mode; |
bf76b144 LK |
9523 | int n = ar->mac.sbands[band].n_iftype_data; |
9524 | int i; | |
9525 | struct ieee80211_sband_iftype_data *data; | |
972754bf WG |
9526 | |
9527 | if (mode < MODE_11BE_EHT20) | |
9528 | return mode; | |
9529 | ||
bf76b144 LK |
9530 | data = ar->mac.iftype[band]; |
9531 | for (i = 0; i < n; i++) { | |
9532 | if (data[i].types_mask & BIT(type)) { | |
9533 | eht_cap = &data[i].eht_cap; | |
9534 | break; | |
9535 | } | |
9536 | } | |
9537 | ||
9538 | if (eht_cap && eht_cap->has_eht) | |
972754bf WG |
9539 | return mode; |
9540 | ||
9541 | switch (mode) { | |
9542 | case MODE_11BE_EHT20: | |
9543 | down_mode = MODE_11AX_HE20; | |
9544 | break; | |
9545 | case MODE_11BE_EHT40: | |
9546 | down_mode = MODE_11AX_HE40; | |
9547 | break; | |
9548 | case MODE_11BE_EHT80: | |
9549 | down_mode = MODE_11AX_HE80; | |
9550 | break; | |
9551 | case MODE_11BE_EHT80_80: | |
9552 | down_mode = MODE_11AX_HE80_80; | |
9553 | break; | |
9554 | case MODE_11BE_EHT160: | |
9555 | case MODE_11BE_EHT160_160: | |
9556 | case MODE_11BE_EHT320: | |
9557 | down_mode = MODE_11AX_HE160; | |
9558 | break; | |
9559 | case MODE_11BE_EHT20_2G: | |
9560 | down_mode = MODE_11AX_HE20_2G; | |
9561 | break; | |
9562 | case MODE_11BE_EHT40_2G: | |
9563 | down_mode = MODE_11AX_HE40_2G; | |
9564 | break; | |
9565 | default: | |
9566 | down_mode = mode; | |
9567 | break; | |
9568 | } | |
9569 | ||
9570 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
9571 | "mac vdev start phymode %s downgrade to %s\n", | |
9572 | ath12k_mac_phymode_str(mode), | |
9573 | ath12k_mac_phymode_str(down_mode)); | |
9574 | ||
9575 | return down_mode; | |
9576 | } | |
9577 | ||
1ea0cdee S |
9578 | static void |
9579 | ath12k_mac_mlo_get_vdev_args(struct ath12k_link_vif *arvif, | |
9580 | struct wmi_ml_arg *ml_arg) | |
9581 | { | |
9582 | struct ath12k_vif *ahvif = arvif->ahvif; | |
9583 | struct wmi_ml_partner_info *partner_info; | |
9584 | struct ieee80211_bss_conf *link_conf; | |
9585 | struct ath12k_link_vif *arvif_p; | |
9586 | unsigned long links; | |
9587 | u8 link_id; | |
9588 | ||
9589 | lockdep_assert_wiphy(ahvif->ah->hw->wiphy); | |
9590 | ||
9591 | if (!ath12k_mac_is_ml_arvif(arvif)) | |
9592 | return; | |
9593 | ||
9594 | if (hweight16(ahvif->vif->valid_links) > ATH12K_WMI_MLO_MAX_LINKS) | |
9595 | return; | |
9596 | ||
9597 | ml_arg->enabled = true; | |
9598 | ||
9599 | /* Driver always add a new link via VDEV START, FW takes | |
9600 | * care of internally adding this link to existing | |
9601 | * link vdevs which are advertised as partners below | |
9602 | */ | |
9603 | ml_arg->link_add = true; | |
0cd46d1f BQ |
9604 | |
9605 | ml_arg->assoc_link = arvif->is_sta_assoc_link; | |
9606 | ||
1ea0cdee S |
9607 | partner_info = ml_arg->partner_info; |
9608 | ||
9609 | links = ahvif->links_map; | |
9610 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
9611 | arvif_p = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); | |
9612 | ||
9613 | if (WARN_ON(!arvif_p)) | |
9614 | continue; | |
9615 | ||
9616 | if (arvif == arvif_p) | |
9617 | continue; | |
9618 | ||
315d80be AKS |
9619 | if (!arvif_p->is_created) |
9620 | continue; | |
9621 | ||
1ea0cdee S |
9622 | link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, |
9623 | ahvif->vif->link_conf[arvif_p->link_id]); | |
9624 | ||
9625 | if (!link_conf) | |
9626 | continue; | |
9627 | ||
9628 | partner_info->vdev_id = arvif_p->vdev_id; | |
9629 | partner_info->hw_link_id = arvif_p->ar->pdev->hw_link_id; | |
9630 | ether_addr_copy(partner_info->addr, link_conf->addr); | |
9631 | ml_arg->num_partner_links++; | |
9632 | partner_info++; | |
9633 | } | |
9634 | } | |
9635 | ||
d8899132 | 9636 | static int |
3dd2c68f | 9637 | ath12k_mac_vdev_start_restart(struct ath12k_link_vif *arvif, |
3f53624f | 9638 | struct ieee80211_chanctx_conf *ctx, |
d8899132 KV |
9639 | bool restart) |
9640 | { | |
9641 | struct ath12k *ar = arvif->ar; | |
9642 | struct ath12k_base *ab = ar->ab; | |
9643 | struct wmi_vdev_start_req_arg arg = {}; | |
3f53624f | 9644 | const struct cfg80211_chan_def *chandef = &ctx->def; |
11b86e2c | 9645 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
3dd2c68f | 9646 | struct ath12k_vif *ahvif = arvif->ahvif; |
39526578 | 9647 | struct ieee80211_bss_conf *link_conf; |
11b86e2c | 9648 | unsigned int dfs_cac_time; |
d8899132 KV |
9649 | int ret; |
9650 | ||
11b86e2c | 9651 | lockdep_assert_wiphy(hw->wiphy); |
d8899132 | 9652 | |
39526578 S |
9653 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
9654 | if (!link_conf) { | |
9655 | ath12k_warn(ar->ab, "unable to access bss link conf in vdev start for vif %pM link %u\n", | |
9656 | ahvif->vif->addr, arvif->link_id); | |
9657 | return -ENOLINK; | |
9658 | } | |
9659 | ||
d8899132 KV |
9660 | reinit_completion(&ar->vdev_setup_done); |
9661 | ||
9662 | arg.vdev_id = arvif->vdev_id; | |
9663 | arg.dtim_period = arvif->dtim_period; | |
9664 | arg.bcn_intval = arvif->beacon_interval; | |
07c01b86 | 9665 | arg.punct_bitmap = ~arvif->punct_bitmap; |
d8899132 KV |
9666 | |
9667 | arg.freq = chandef->chan->center_freq; | |
9668 | arg.band_center_freq1 = chandef->center_freq1; | |
9669 | arg.band_center_freq2 = chandef->center_freq2; | |
9670 | arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; | |
9671 | ||
972754bf WG |
9672 | arg.mode = ath12k_mac_check_down_grade_phy_mode(ar, arg.mode, |
9673 | chandef->chan->band, | |
3dd2c68f | 9674 | ahvif->vif->type); |
d8899132 | 9675 | arg.min_power = 0; |
3540bba8 SM |
9676 | arg.max_power = chandef->chan->max_power; |
9677 | arg.max_reg_power = chandef->chan->max_reg_power; | |
9678 | arg.max_antenna_gain = chandef->chan->max_antenna_gain; | |
d8899132 KV |
9679 | |
9680 | arg.pref_tx_streams = ar->num_tx_chains; | |
9681 | arg.pref_rx_streams = ar->num_rx_chains; | |
9682 | ||
6925eba5 | 9683 | arg.mbssid_flags = WMI_VDEV_MBSSID_FLAGS_NON_MBSSID_AP; |
ea68f1bb AD |
9684 | arg.mbssid_tx_vdev_id = 0; |
9685 | if (test_bit(WMI_TLV_SERVICE_MBSS_PARAM_IN_VDEV_START_SUPPORT, | |
9686 | ar->ab->wmi_ab.svc_map)) { | |
9687 | ret = ath12k_mac_setup_vdev_params_mbssid(arvif, | |
9688 | &arg.mbssid_flags, | |
9689 | &arg.mbssid_tx_vdev_id); | |
9690 | if (ret) | |
9691 | return ret; | |
9692 | } | |
6925eba5 | 9693 | |
3dd2c68f S |
9694 | if (ahvif->vdev_type == WMI_VDEV_TYPE_AP) { |
9695 | arg.ssid = ahvif->u.ap.ssid; | |
9696 | arg.ssid_len = ahvif->u.ap.ssid_len; | |
9697 | arg.hidden_ssid = ahvif->u.ap.hidden_ssid; | |
d8899132 KV |
9698 | |
9699 | /* For now allow DFS for AP mode */ | |
9700 | arg.chan_radar = !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); | |
9701 | ||
3f53624f MD |
9702 | arg.freq2_radar = ctx->radar_enabled; |
9703 | ||
d8899132 KV |
9704 | arg.passive = arg.chan_radar; |
9705 | ||
9706 | spin_lock_bh(&ab->base_lock); | |
9707 | arg.regdomain = ar->ab->dfs_region; | |
9708 | spin_unlock_bh(&ab->base_lock); | |
9709 | ||
9710 | /* TODO: Notify if secondary 80Mhz also needs radar detection */ | |
39526578 | 9711 | if (link_conf->he_support) { |
d8899132 KV |
9712 | ret = ath12k_set_he_mu_sounding_mode(ar, arvif); |
9713 | if (ret) { | |
9714 | ath12k_warn(ar->ab, "failed to set he mode vdev %i\n", | |
9715 | arg.vdev_id); | |
9716 | return ret; | |
9717 | } | |
9718 | } | |
9719 | } | |
9720 | ||
9721 | arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); | |
9722 | ||
1ea0cdee S |
9723 | if (!restart) |
9724 | ath12k_mac_mlo_get_vdev_args(arvif, &arg.ml); | |
9725 | ||
d8899132 | 9726 | ath12k_dbg(ab, ATH12K_DBG_MAC, |
07c01b86 | 9727 | "mac vdev %d start center_freq %d phymode %s punct_bitmap 0x%x\n", |
d8899132 | 9728 | arg.vdev_id, arg.freq, |
07c01b86 | 9729 | ath12k_mac_phymode_str(arg.mode), arg.punct_bitmap); |
d8899132 KV |
9730 | |
9731 | ret = ath12k_wmi_vdev_start(ar, &arg, restart); | |
9732 | if (ret) { | |
9733 | ath12k_warn(ar->ab, "failed to %s WMI vdev %i\n", | |
9734 | restart ? "restart" : "start", arg.vdev_id); | |
9735 | return ret; | |
9736 | } | |
9737 | ||
9738 | ret = ath12k_mac_vdev_setup_sync(ar); | |
9739 | if (ret) { | |
9740 | ath12k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n", | |
9741 | arg.vdev_id, restart ? "restart" : "start", ret); | |
9742 | return ret; | |
9743 | } | |
9744 | ||
29cb3d26 BQ |
9745 | /* TODO: For now we only set TPC power here. However when |
9746 | * channel changes, say CSA, it should be updated again. | |
9747 | */ | |
9748 | if (ath12k_mac_supports_station_tpc(ar, ahvif, chandef)) { | |
9749 | ath12k_mac_fill_reg_tpc_info(ar, arvif, ctx); | |
9750 | ath12k_wmi_send_vdev_set_tpc_power(ar, arvif->vdev_id, | |
9751 | &arvif->reg_tpc_info); | |
9752 | } | |
9753 | ||
d8899132 KV |
9754 | ar->num_started_vdevs++; |
9755 | ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM started, vdev_id %d\n", | |
3dd2c68f | 9756 | ahvif->vif->addr, arvif->vdev_id); |
d8899132 | 9757 | |
11b86e2c AKS |
9758 | /* Enable CAC Running Flag in the driver by checking all sub-channel's DFS |
9759 | * state as NL80211_DFS_USABLE which indicates CAC needs to be | |
9760 | * done before channel usage. This flag is used to drop rx packets. | |
d8899132 KV |
9761 | * during CAC. |
9762 | */ | |
9763 | /* TODO: Set the flag for other interface types as required */ | |
11b86e2c AKS |
9764 | if (arvif->ahvif->vdev_type == WMI_VDEV_TYPE_AP && ctx->radar_enabled && |
9765 | cfg80211_chandef_dfs_usable(hw->wiphy, chandef)) { | |
d31241cb | 9766 | set_bit(ATH12K_FLAG_CAC_RUNNING, &ar->dev_flags); |
11b86e2c AKS |
9767 | dfs_cac_time = cfg80211_chandef_dfs_cac_time(hw->wiphy, chandef); |
9768 | ||
d8899132 | 9769 | ath12k_dbg(ab, ATH12K_DBG_MAC, |
11b86e2c AKS |
9770 | "CAC started dfs_cac_time %u center_freq %d center_freq1 %d for vdev %d\n", |
9771 | dfs_cac_time, arg.freq, arg.band_center_freq1, arg.vdev_id); | |
d8899132 KV |
9772 | } |
9773 | ||
9774 | ret = ath12k_mac_set_txbf_conf(arvif); | |
9775 | if (ret) | |
9776 | ath12k_warn(ab, "failed to set txbf conf for vdev %d: %d\n", | |
9777 | arvif->vdev_id, ret); | |
9778 | ||
9779 | return 0; | |
9780 | } | |
9781 | ||
3dd2c68f | 9782 | static int ath12k_mac_vdev_start(struct ath12k_link_vif *arvif, |
3f53624f | 9783 | struct ieee80211_chanctx_conf *ctx) |
d8899132 | 9784 | { |
3f53624f | 9785 | return ath12k_mac_vdev_start_restart(arvif, ctx, false); |
d8899132 KV |
9786 | } |
9787 | ||
3dd2c68f | 9788 | static int ath12k_mac_vdev_restart(struct ath12k_link_vif *arvif, |
3f53624f | 9789 | struct ieee80211_chanctx_conf *ctx) |
d8899132 | 9790 | { |
3f53624f | 9791 | return ath12k_mac_vdev_start_restart(arvif, ctx, true); |
d8899132 KV |
9792 | } |
9793 | ||
9794 | struct ath12k_mac_change_chanctx_arg { | |
9795 | struct ieee80211_chanctx_conf *ctx; | |
9796 | struct ieee80211_vif_chanctx_switch *vifs; | |
9797 | int n_vifs; | |
9798 | int next_vif; | |
cec77a25 | 9799 | struct ath12k *ar; |
d8899132 KV |
9800 | }; |
9801 | ||
9802 | static void | |
9803 | ath12k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, | |
9804 | struct ieee80211_vif *vif) | |
9805 | { | |
3dd2c68f | 9806 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
d8899132 | 9807 | struct ath12k_mac_change_chanctx_arg *arg = data; |
aaac8850 | 9808 | struct ieee80211_bss_conf *link_conf; |
3dd2c68f | 9809 | struct ath12k_link_vif *arvif; |
aaac8850 RS |
9810 | unsigned long links_map; |
9811 | u8 link_id; | |
3dd2c68f S |
9812 | |
9813 | lockdep_assert_wiphy(ahvif->ah->hw->wiphy); | |
9814 | ||
aaac8850 RS |
9815 | links_map = ahvif->links_map; |
9816 | for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { | |
9817 | arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); | |
9818 | if (WARN_ON(!arvif)) | |
9819 | continue; | |
d8899132 | 9820 | |
aaac8850 RS |
9821 | if (arvif->ar != arg->ar) |
9822 | continue; | |
cec77a25 | 9823 | |
aaac8850 RS |
9824 | link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, |
9825 | vif->link_conf[link_id]); | |
9826 | if (WARN_ON(!link_conf)) | |
9827 | continue; | |
9828 | ||
9829 | if (rcu_access_pointer(link_conf->chanctx_conf) != arg->ctx) | |
9830 | continue; | |
d8899132 | 9831 | |
aaac8850 RS |
9832 | arg->n_vifs++; |
9833 | } | |
d8899132 KV |
9834 | } |
9835 | ||
9836 | static void | |
9837 | ath12k_mac_change_chanctx_fill_iter(void *data, u8 *mac, | |
9838 | struct ieee80211_vif *vif) | |
9839 | { | |
3dd2c68f | 9840 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
d8899132 | 9841 | struct ath12k_mac_change_chanctx_arg *arg = data; |
aaac8850 | 9842 | struct ieee80211_bss_conf *link_conf; |
d8899132 | 9843 | struct ieee80211_chanctx_conf *ctx; |
3dd2c68f | 9844 | struct ath12k_link_vif *arvif; |
aaac8850 RS |
9845 | unsigned long links_map; |
9846 | u8 link_id; | |
3dd2c68f S |
9847 | |
9848 | lockdep_assert_wiphy(ahvif->ah->hw->wiphy); | |
9849 | ||
aaac8850 RS |
9850 | links_map = ahvif->links_map; |
9851 | for_each_set_bit(link_id, &links_map, IEEE80211_MLD_MAX_NUM_LINKS) { | |
9852 | arvif = wiphy_dereference(ahvif->ah->hw->wiphy, ahvif->link[link_id]); | |
9853 | if (WARN_ON(!arvif)) | |
9854 | continue; | |
d8899132 | 9855 | |
aaac8850 RS |
9856 | if (arvif->ar != arg->ar) |
9857 | continue; | |
cec77a25 | 9858 | |
aaac8850 RS |
9859 | link_conf = wiphy_dereference(ahvif->ah->hw->wiphy, |
9860 | vif->link_conf[arvif->link_id]); | |
9861 | if (WARN_ON(!link_conf)) | |
9862 | continue; | |
d8899132 | 9863 | |
aaac8850 RS |
9864 | ctx = rcu_access_pointer(link_conf->chanctx_conf); |
9865 | if (ctx != arg->ctx) | |
9866 | continue; | |
9867 | ||
9868 | if (WARN_ON(arg->next_vif == arg->n_vifs)) | |
9869 | return; | |
d8899132 | 9870 | |
aaac8850 RS |
9871 | arg->vifs[arg->next_vif].vif = vif; |
9872 | arg->vifs[arg->next_vif].old_ctx = ctx; | |
9873 | arg->vifs[arg->next_vif].new_ctx = ctx; | |
9874 | arg->vifs[arg->next_vif].link_conf = link_conf; | |
9875 | arg->next_vif++; | |
9876 | } | |
d8899132 KV |
9877 | } |
9878 | ||
05318254 KY |
9879 | static u32 ath12k_mac_nlwidth_to_wmiwidth(enum nl80211_chan_width width) |
9880 | { | |
9881 | switch (width) { | |
9882 | case NL80211_CHAN_WIDTH_20: | |
9883 | return WMI_CHAN_WIDTH_20; | |
9884 | case NL80211_CHAN_WIDTH_40: | |
9885 | return WMI_CHAN_WIDTH_40; | |
9886 | case NL80211_CHAN_WIDTH_80: | |
9887 | return WMI_CHAN_WIDTH_80; | |
9888 | case NL80211_CHAN_WIDTH_160: | |
9889 | return WMI_CHAN_WIDTH_160; | |
9890 | case NL80211_CHAN_WIDTH_80P80: | |
9891 | return WMI_CHAN_WIDTH_80P80; | |
9892 | case NL80211_CHAN_WIDTH_5: | |
9893 | return WMI_CHAN_WIDTH_5; | |
9894 | case NL80211_CHAN_WIDTH_10: | |
9895 | return WMI_CHAN_WIDTH_10; | |
9896 | case NL80211_CHAN_WIDTH_320: | |
9897 | return WMI_CHAN_WIDTH_320; | |
9898 | default: | |
9899 | WARN_ON(1); | |
9900 | return WMI_CHAN_WIDTH_20; | |
9901 | } | |
9902 | } | |
9903 | ||
9904 | static int ath12k_mac_update_peer_puncturing_width(struct ath12k *ar, | |
3dd2c68f | 9905 | struct ath12k_link_vif *arvif, |
05318254 KY |
9906 | struct cfg80211_chan_def def) |
9907 | { | |
9908 | u32 param_id, param_value; | |
9909 | int ret; | |
9910 | ||
3dd2c68f | 9911 | if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA) |
05318254 KY |
9912 | return 0; |
9913 | ||
9914 | param_id = WMI_PEER_CHWIDTH_PUNCTURE_20MHZ_BITMAP; | |
9915 | param_value = ath12k_mac_nlwidth_to_wmiwidth(def.width) | | |
9916 | u32_encode_bits((~def.punctured), | |
9917 | WMI_PEER_PUNCTURE_BITMAP); | |
9918 | ||
9919 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
9920 | "punctured bitmap %02x width %d vdev %d\n", | |
9921 | def.punctured, def.width, arvif->vdev_id); | |
9922 | ||
9923 | ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, | |
9924 | arvif->vdev_id, param_id, | |
9925 | param_value); | |
9926 | ||
9927 | return ret; | |
9928 | } | |
9929 | ||
d8899132 KV |
9930 | static void |
9931 | ath12k_mac_update_vif_chan(struct ath12k *ar, | |
9932 | struct ieee80211_vif_chanctx_switch *vifs, | |
9933 | int n_vifs) | |
9934 | { | |
51c47463 | 9935 | struct ath12k_wmi_vdev_up_params params = {}; |
20fe6390 | 9936 | struct ath12k_link_vif *arvif, *tx_arvif; |
aaac8850 | 9937 | struct ieee80211_bss_conf *link_conf; |
d8899132 | 9938 | struct ath12k_base *ab = ar->ab; |
84edf47b | 9939 | struct ieee80211_vif *vif; |
3dd2c68f | 9940 | struct ath12k_vif *ahvif; |
aaac8850 | 9941 | u8 link_id; |
d8899132 KV |
9942 | int ret; |
9943 | int i; | |
9944 | bool monitor_vif = false; | |
9945 | ||
b8c67509 | 9946 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
9947 | |
9948 | for (i = 0; i < n_vifs; i++) { | |
c740a18f | 9949 | vif = vifs[i].vif; |
3dd2c68f | 9950 | ahvif = ath12k_vif_to_ahvif(vif); |
aaac8850 RS |
9951 | link_conf = vifs[i].link_conf; |
9952 | link_id = link_conf->link_id; | |
9953 | arvif = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, | |
9954 | ahvif->link[link_id]); | |
d8899132 | 9955 | |
7423b641 | 9956 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
d8899132 | 9957 | monitor_vif = true; |
7423b641 KP |
9958 | continue; |
9959 | } | |
d8899132 KV |
9960 | |
9961 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
9962 | "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n", | |
9963 | arvif->vdev_id, | |
9964 | vifs[i].old_ctx->def.chan->center_freq, | |
9965 | vifs[i].new_ctx->def.chan->center_freq, | |
9966 | vifs[i].old_ctx->def.width, | |
9967 | vifs[i].new_ctx->def.width); | |
9968 | ||
d8899132 KV |
9969 | if (WARN_ON(!arvif->is_started)) |
9970 | continue; | |
9971 | ||
b82730bf JB |
9972 | arvif->punct_bitmap = vifs[i].new_ctx->def.punctured; |
9973 | ||
8b8b990f MD |
9974 | /* Firmware expect vdev_restart only if vdev is up. |
9975 | * If vdev is down then it expect vdev_stop->vdev_start. | |
9976 | */ | |
9977 | if (arvif->is_up) { | |
3f53624f | 9978 | ret = ath12k_mac_vdev_restart(arvif, vifs[i].new_ctx); |
8b8b990f MD |
9979 | if (ret) { |
9980 | ath12k_warn(ab, "failed to restart vdev %d: %d\n", | |
9981 | arvif->vdev_id, ret); | |
9982 | continue; | |
9983 | } | |
9984 | } else { | |
9985 | ret = ath12k_mac_vdev_stop(arvif); | |
9986 | if (ret) { | |
9987 | ath12k_warn(ab, "failed to stop vdev %d: %d\n", | |
9988 | arvif->vdev_id, ret); | |
9989 | continue; | |
9990 | } | |
d8899132 | 9991 | |
3f53624f | 9992 | ret = ath12k_mac_vdev_start(arvif, vifs[i].new_ctx); |
8b8b990f MD |
9993 | if (ret) |
9994 | ath12k_warn(ab, "failed to start vdev %d: %d\n", | |
9995 | arvif->vdev_id, ret); | |
d8899132 KV |
9996 | continue; |
9997 | } | |
9998 | ||
9999 | ret = ath12k_mac_setup_bcn_tmpl(arvif); | |
10000 | if (ret) | |
10001 | ath12k_warn(ab, "failed to update bcn tmpl during csa: %d\n", | |
10002 | ret); | |
10003 | ||
84edf47b | 10004 | memset(¶ms, 0, sizeof(params)); |
51c47463 | 10005 | params.vdev_id = arvif->vdev_id; |
3dd2c68f | 10006 | params.aid = ahvif->aid; |
51c47463 | 10007 | params.bssid = arvif->bssid; |
3dd2c68f | 10008 | |
172e1570 | 10009 | tx_arvif = ath12k_mac_get_tx_arvif(arvif, link_conf); |
20fe6390 | 10010 | if (tx_arvif) { |
aaac8850 RS |
10011 | params.tx_bssid = tx_arvif->bssid; |
10012 | params.nontx_profile_idx = link_conf->bssid_index; | |
10013 | params.nontx_profile_cnt = 1 << link_conf->bssid_indicator; | |
84edf47b | 10014 | } |
51c47463 | 10015 | ret = ath12k_wmi_vdev_up(arvif->ar, ¶ms); |
d8899132 KV |
10016 | if (ret) { |
10017 | ath12k_warn(ab, "failed to bring vdev up %d: %d\n", | |
10018 | arvif->vdev_id, ret); | |
10019 | continue; | |
10020 | } | |
05318254 KY |
10021 | |
10022 | ret = ath12k_mac_update_peer_puncturing_width(arvif->ar, arvif, | |
10023 | vifs[i].new_ctx->def); | |
10024 | if (ret) { | |
10025 | ath12k_warn(ar->ab, | |
10026 | "failed to update puncturing bitmap %02x and width %d: %d\n", | |
10027 | vifs[i].new_ctx->def.punctured, | |
10028 | vifs[i].new_ctx->def.width, ret); | |
10029 | continue; | |
10030 | } | |
d8899132 KV |
10031 | } |
10032 | ||
10033 | /* Restart the internal monitor vdev on new channel */ | |
10034 | if (!monitor_vif && ar->monitor_vdev_created) { | |
10035 | if (!ath12k_mac_monitor_stop(ar)) | |
10036 | ath12k_mac_monitor_start(ar); | |
10037 | } | |
10038 | } | |
10039 | ||
10040 | static void | |
10041 | ath12k_mac_update_active_vif_chan(struct ath12k *ar, | |
10042 | struct ieee80211_chanctx_conf *ctx) | |
10043 | { | |
cec77a25 | 10044 | struct ath12k_mac_change_chanctx_arg arg = { .ctx = ctx, .ar = ar }; |
b856f023 | 10045 | struct ieee80211_hw *hw = ath12k_ar_to_hw(ar); |
d8899132 | 10046 | |
b8c67509 | 10047 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 | 10048 | |
940b57fd | 10049 | ieee80211_iterate_active_interfaces_atomic(hw, |
d8899132 KV |
10050 | IEEE80211_IFACE_ITER_NORMAL, |
10051 | ath12k_mac_change_chanctx_cnt_iter, | |
10052 | &arg); | |
10053 | if (arg.n_vifs == 0) | |
10054 | return; | |
10055 | ||
10056 | arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL); | |
10057 | if (!arg.vifs) | |
10058 | return; | |
10059 | ||
940b57fd | 10060 | ieee80211_iterate_active_interfaces_atomic(hw, |
d8899132 KV |
10061 | IEEE80211_IFACE_ITER_NORMAL, |
10062 | ath12k_mac_change_chanctx_fill_iter, | |
10063 | &arg); | |
10064 | ||
10065 | ath12k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); | |
10066 | ||
10067 | kfree(arg.vifs); | |
10068 | } | |
10069 | ||
10070 | static void ath12k_mac_op_change_chanctx(struct ieee80211_hw *hw, | |
10071 | struct ieee80211_chanctx_conf *ctx, | |
10072 | u32 changed) | |
10073 | { | |
6db6e70a KP |
10074 | struct ath12k *ar; |
10075 | struct ath12k_base *ab; | |
10076 | ||
c347f181 KV |
10077 | lockdep_assert_wiphy(hw->wiphy); |
10078 | ||
d01c08ed S |
10079 | ar = ath12k_get_ar_by_ctx(hw, ctx); |
10080 | if (!ar) | |
10081 | return; | |
10082 | ||
6db6e70a | 10083 | ab = ar->ab; |
d8899132 | 10084 | |
d8899132 | 10085 | ath12k_dbg(ab, ATH12K_DBG_MAC, |
2372c6d2 | 10086 | "mac chanctx change freq %u width %d ptr %p changed %x\n", |
d8899132 KV |
10087 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); |
10088 | ||
10089 | /* This shouldn't really happen because channel switching should use | |
10090 | * switch_vif_chanctx(). | |
10091 | */ | |
10092 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) | |
b8c67509 | 10093 | return; |
d8899132 | 10094 | |
3f53624f | 10095 | if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH || |
b82730bf JB |
10096 | changed & IEEE80211_CHANCTX_CHANGE_RADAR || |
10097 | changed & IEEE80211_CHANCTX_CHANGE_PUNCTURING) | |
d8899132 KV |
10098 | ath12k_mac_update_active_vif_chan(ar, ctx); |
10099 | ||
10100 | /* TODO: Recalc radar detection */ | |
d8899132 KV |
10101 | } |
10102 | ||
5bdfb8c9 | 10103 | static int ath12k_start_vdev_delay(struct ath12k *ar, |
3dd2c68f | 10104 | struct ath12k_link_vif *arvif) |
d8899132 | 10105 | { |
d8899132 | 10106 | struct ath12k_base *ab = ar->ab; |
3dd2c68f S |
10107 | struct ath12k_vif *ahvif = arvif->ahvif; |
10108 | struct ieee80211_vif *vif = ath12k_ahvif_to_vif(arvif->ahvif); | |
ce077937 BQ |
10109 | struct ieee80211_chanctx_conf *chanctx; |
10110 | struct ieee80211_bss_conf *link_conf; | |
d8899132 KV |
10111 | int ret; |
10112 | ||
10113 | if (WARN_ON(arvif->is_started)) | |
10114 | return -EBUSY; | |
10115 | ||
ce077937 BQ |
10116 | link_conf = ath12k_mac_get_link_bss_conf(arvif); |
10117 | if (!link_conf) { | |
10118 | ath12k_warn(ab, "failed to get link conf for vdev %u\n", arvif->vdev_id); | |
10119 | return -EINVAL; | |
10120 | } | |
10121 | ||
10122 | chanctx = wiphy_dereference(ath12k_ar_to_hw(arvif->ar)->wiphy, | |
10123 | link_conf->chanctx_conf); | |
10124 | ret = ath12k_mac_vdev_start(arvif, chanctx); | |
d8899132 KV |
10125 | if (ret) { |
10126 | ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
10127 | arvif->vdev_id, vif->addr, | |
ce077937 | 10128 | chanctx->def.chan->center_freq, ret); |
d8899132 KV |
10129 | return ret; |
10130 | } | |
10131 | ||
3dd2c68f | 10132 | if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
d8899132 KV |
10133 | ret = ath12k_monitor_vdev_up(ar, arvif->vdev_id); |
10134 | if (ret) { | |
10135 | ath12k_warn(ab, "failed put monitor up: %d\n", ret); | |
10136 | return ret; | |
10137 | } | |
10138 | } | |
10139 | ||
10140 | arvif->is_started = true; | |
10141 | ||
10142 | /* TODO: Setup ps and cts/rts protection */ | |
10143 | return 0; | |
10144 | } | |
10145 | ||
aeda163b BQ |
10146 | static u8 ath12k_mac_get_num_pwr_levels(struct cfg80211_chan_def *chan_def) |
10147 | { | |
10148 | if (chan_def->chan->flags & IEEE80211_CHAN_PSD) { | |
10149 | switch (chan_def->width) { | |
10150 | case NL80211_CHAN_WIDTH_20: | |
10151 | return 1; | |
10152 | case NL80211_CHAN_WIDTH_40: | |
10153 | return 2; | |
10154 | case NL80211_CHAN_WIDTH_80: | |
10155 | return 4; | |
10156 | case NL80211_CHAN_WIDTH_160: | |
10157 | return 8; | |
10158 | case NL80211_CHAN_WIDTH_320: | |
10159 | return 16; | |
10160 | default: | |
10161 | return 1; | |
10162 | } | |
10163 | } else { | |
10164 | switch (chan_def->width) { | |
10165 | case NL80211_CHAN_WIDTH_20: | |
10166 | return 1; | |
10167 | case NL80211_CHAN_WIDTH_40: | |
10168 | return 2; | |
10169 | case NL80211_CHAN_WIDTH_80: | |
10170 | return 3; | |
10171 | case NL80211_CHAN_WIDTH_160: | |
10172 | return 4; | |
10173 | case NL80211_CHAN_WIDTH_320: | |
10174 | return 5; | |
10175 | default: | |
10176 | return 1; | |
10177 | } | |
10178 | } | |
10179 | } | |
10180 | ||
10181 | static u16 ath12k_mac_get_6ghz_start_frequency(struct cfg80211_chan_def *chan_def) | |
10182 | { | |
10183 | u16 diff_seq; | |
10184 | ||
10185 | /* It is to get the lowest channel number's center frequency of the chan. | |
10186 | * For example, | |
10187 | * bandwidth=40 MHz, center frequency is 5965, lowest channel is 1 | |
10188 | * with center frequency 5955, its diff is 5965 - 5955 = 10. | |
10189 | * bandwidth=80 MHz, center frequency is 5985, lowest channel is 1 | |
10190 | * with center frequency 5955, its diff is 5985 - 5955 = 30. | |
10191 | * bandwidth=160 MHz, center frequency is 6025, lowest channel is 1 | |
10192 | * with center frequency 5955, its diff is 6025 - 5955 = 70. | |
10193 | * bandwidth=320 MHz, center frequency is 6105, lowest channel is 1 | |
10194 | * with center frequency 5955, its diff is 6105 - 5955 = 70. | |
10195 | */ | |
10196 | switch (chan_def->width) { | |
10197 | case NL80211_CHAN_WIDTH_320: | |
10198 | diff_seq = 150; | |
10199 | break; | |
10200 | case NL80211_CHAN_WIDTH_160: | |
10201 | diff_seq = 70; | |
10202 | break; | |
10203 | case NL80211_CHAN_WIDTH_80: | |
10204 | diff_seq = 30; | |
10205 | break; | |
10206 | case NL80211_CHAN_WIDTH_40: | |
10207 | diff_seq = 10; | |
10208 | break; | |
10209 | default: | |
10210 | diff_seq = 0; | |
10211 | } | |
10212 | ||
10213 | return chan_def->center_freq1 - diff_seq; | |
10214 | } | |
10215 | ||
10216 | static u16 ath12k_mac_get_seg_freq(struct cfg80211_chan_def *chan_def, | |
10217 | u16 start_seq, u8 seq) | |
10218 | { | |
10219 | u16 seg_seq; | |
10220 | ||
10221 | /* It is to get the center frequency of the specific bandwidth. | |
10222 | * start_seq means the lowest channel number's center frequency. | |
10223 | * seq 0/1/2/3 means 20 MHz/40 MHz/80 MHz/160 MHz. | |
10224 | * For example, | |
10225 | * lowest channel is 1, its center frequency 5955, | |
10226 | * center frequency is 5955 when bandwidth=20 MHz, its diff is 5955 - 5955 = 0. | |
10227 | * lowest channel is 1, its center frequency 5955, | |
10228 | * center frequency is 5965 when bandwidth=40 MHz, its diff is 5965 - 5955 = 10. | |
10229 | * lowest channel is 1, its center frequency 5955, | |
10230 | * center frequency is 5985 when bandwidth=80 MHz, its diff is 5985 - 5955 = 30. | |
10231 | * lowest channel is 1, its center frequency 5955, | |
10232 | * center frequency is 6025 when bandwidth=160 MHz, its diff is 6025 - 5955 = 70. | |
10233 | */ | |
10234 | seg_seq = 10 * (BIT(seq) - 1); | |
10235 | return seg_seq + start_seq; | |
10236 | } | |
10237 | ||
10238 | static void ath12k_mac_get_psd_channel(struct ath12k *ar, | |
10239 | u16 step_freq, | |
10240 | u16 *start_freq, | |
10241 | u16 *center_freq, | |
10242 | u8 i, | |
10243 | struct ieee80211_channel **temp_chan, | |
10244 | s8 *tx_power) | |
10245 | { | |
10246 | /* It is to get the center frequency for each 20 MHz. | |
10247 | * For example, if the chan is 160 MHz and center frequency is 6025, | |
10248 | * then it include 8 channels, they are 1/5/9/13/17/21/25/29, | |
10249 | * channel number 1's center frequency is 5955, it is parameter start_freq. | |
10250 | * parameter i is the step of the 8 channels. i is 0~7 for the 8 channels. | |
10251 | * the channel 1/5/9/13/17/21/25/29 maps i=0/1/2/3/4/5/6/7, | |
10252 | * and maps its center frequency is 5955/5975/5995/6015/6035/6055/6075/6095, | |
10253 | * the gap is 20 for each channel, parameter step_freq means the gap. | |
10254 | * after get the center frequency of each channel, it is easy to find the | |
10255 | * struct ieee80211_channel of it and get the max_reg_power. | |
10256 | */ | |
10257 | *center_freq = *start_freq + i * step_freq; | |
10258 | *temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq); | |
10259 | *tx_power = (*temp_chan)->max_reg_power; | |
10260 | } | |
10261 | ||
10262 | static void ath12k_mac_get_eirp_power(struct ath12k *ar, | |
10263 | u16 *start_freq, | |
10264 | u16 *center_freq, | |
10265 | u8 i, | |
10266 | struct ieee80211_channel **temp_chan, | |
10267 | struct cfg80211_chan_def *def, | |
10268 | s8 *tx_power) | |
10269 | { | |
10270 | /* It is to get the center frequency for 20 MHz/40 MHz/80 MHz/ | |
10271 | * 160 MHz bandwidth, and then plus 10 to the center frequency, | |
10272 | * it is the center frequency of a channel number. | |
10273 | * For example, when configured channel number is 1. | |
10274 | * center frequency is 5965 when bandwidth=40 MHz, after plus 10, it is 5975, | |
10275 | * then it is channel number 5. | |
10276 | * center frequency is 5985 when bandwidth=80 MHz, after plus 10, it is 5995, | |
10277 | * then it is channel number 9. | |
10278 | * center frequency is 6025 when bandwidth=160 MHz, after plus 10, it is 6035, | |
10279 | * then it is channel number 17. | |
10280 | * after get the center frequency of each channel, it is easy to find the | |
10281 | * struct ieee80211_channel of it and get the max_reg_power. | |
10282 | */ | |
10283 | *center_freq = ath12k_mac_get_seg_freq(def, *start_freq, i); | |
10284 | ||
10285 | /* For the 20 MHz, its center frequency is same with same channel */ | |
10286 | if (i != 0) | |
10287 | *center_freq += 10; | |
10288 | ||
10289 | *temp_chan = ieee80211_get_channel(ar->ah->hw->wiphy, *center_freq); | |
10290 | *tx_power = (*temp_chan)->max_reg_power; | |
10291 | } | |
10292 | ||
10293 | void ath12k_mac_fill_reg_tpc_info(struct ath12k *ar, | |
10294 | struct ath12k_link_vif *arvif, | |
10295 | struct ieee80211_chanctx_conf *ctx) | |
10296 | { | |
10297 | struct ath12k_base *ab = ar->ab; | |
10298 | struct ath12k_reg_tpc_power_info *reg_tpc_info = &arvif->reg_tpc_info; | |
10299 | struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif); | |
10300 | struct ieee80211_channel *chan, *temp_chan; | |
10301 | u8 pwr_lvl_idx, num_pwr_levels, pwr_reduction; | |
10302 | bool is_psd_power = false, is_tpe_present = false; | |
10303 | s8 max_tx_power[ATH12K_NUM_PWR_LEVELS], | |
10304 | psd_power, tx_power, eirp_power; | |
10305 | u16 start_freq, center_freq; | |
10306 | ||
10307 | chan = ctx->def.chan; | |
10308 | start_freq = ath12k_mac_get_6ghz_start_frequency(&ctx->def); | |
10309 | pwr_reduction = bss_conf->pwr_reduction; | |
10310 | ||
10311 | if (arvif->reg_tpc_info.num_pwr_levels) { | |
10312 | is_tpe_present = true; | |
10313 | num_pwr_levels = arvif->reg_tpc_info.num_pwr_levels; | |
10314 | } else { | |
10315 | num_pwr_levels = ath12k_mac_get_num_pwr_levels(&ctx->def); | |
10316 | } | |
10317 | ||
10318 | for (pwr_lvl_idx = 0; pwr_lvl_idx < num_pwr_levels; pwr_lvl_idx++) { | |
10319 | /* STA received TPE IE*/ | |
10320 | if (is_tpe_present) { | |
10321 | /* local power is PSD power*/ | |
10322 | if (chan->flags & IEEE80211_CHAN_PSD) { | |
10323 | /* Connecting AP is psd power */ | |
10324 | if (reg_tpc_info->is_psd_power) { | |
10325 | is_psd_power = true; | |
10326 | ath12k_mac_get_psd_channel(ar, 20, | |
10327 | &start_freq, | |
10328 | ¢er_freq, | |
10329 | pwr_lvl_idx, | |
10330 | &temp_chan, | |
10331 | &tx_power); | |
10332 | psd_power = temp_chan->psd; | |
10333 | eirp_power = tx_power; | |
10334 | max_tx_power[pwr_lvl_idx] = | |
10335 | min_t(s8, | |
10336 | psd_power, | |
10337 | reg_tpc_info->tpe[pwr_lvl_idx]); | |
10338 | /* Connecting AP is not psd power */ | |
10339 | } else { | |
10340 | ath12k_mac_get_eirp_power(ar, | |
10341 | &start_freq, | |
10342 | ¢er_freq, | |
10343 | pwr_lvl_idx, | |
10344 | &temp_chan, | |
10345 | &ctx->def, | |
10346 | &tx_power); | |
10347 | psd_power = temp_chan->psd; | |
10348 | /* convert psd power to EIRP power based | |
10349 | * on channel width | |
10350 | */ | |
10351 | tx_power = | |
10352 | min_t(s8, tx_power, | |
10353 | psd_power + 13 + pwr_lvl_idx * 3); | |
10354 | max_tx_power[pwr_lvl_idx] = | |
10355 | min_t(s8, | |
10356 | tx_power, | |
10357 | reg_tpc_info->tpe[pwr_lvl_idx]); | |
10358 | } | |
10359 | /* local power is not PSD power */ | |
10360 | } else { | |
10361 | /* Connecting AP is psd power */ | |
10362 | if (reg_tpc_info->is_psd_power) { | |
10363 | is_psd_power = true; | |
10364 | ath12k_mac_get_psd_channel(ar, 20, | |
10365 | &start_freq, | |
10366 | ¢er_freq, | |
10367 | pwr_lvl_idx, | |
10368 | &temp_chan, | |
10369 | &tx_power); | |
10370 | eirp_power = tx_power; | |
10371 | max_tx_power[pwr_lvl_idx] = | |
10372 | reg_tpc_info->tpe[pwr_lvl_idx]; | |
10373 | /* Connecting AP is not psd power */ | |
10374 | } else { | |
10375 | ath12k_mac_get_eirp_power(ar, | |
10376 | &start_freq, | |
10377 | ¢er_freq, | |
10378 | pwr_lvl_idx, | |
10379 | &temp_chan, | |
10380 | &ctx->def, | |
10381 | &tx_power); | |
10382 | max_tx_power[pwr_lvl_idx] = | |
10383 | min_t(s8, | |
10384 | tx_power, | |
10385 | reg_tpc_info->tpe[pwr_lvl_idx]); | |
10386 | } | |
10387 | } | |
10388 | /* STA not received TPE IE */ | |
10389 | } else { | |
10390 | /* local power is PSD power*/ | |
10391 | if (chan->flags & IEEE80211_CHAN_PSD) { | |
10392 | is_psd_power = true; | |
10393 | ath12k_mac_get_psd_channel(ar, 20, | |
10394 | &start_freq, | |
10395 | ¢er_freq, | |
10396 | pwr_lvl_idx, | |
10397 | &temp_chan, | |
10398 | &tx_power); | |
10399 | psd_power = temp_chan->psd; | |
10400 | eirp_power = tx_power; | |
10401 | max_tx_power[pwr_lvl_idx] = psd_power; | |
10402 | } else { | |
10403 | ath12k_mac_get_eirp_power(ar, | |
10404 | &start_freq, | |
10405 | ¢er_freq, | |
10406 | pwr_lvl_idx, | |
10407 | &temp_chan, | |
10408 | &ctx->def, | |
10409 | &tx_power); | |
10410 | max_tx_power[pwr_lvl_idx] = tx_power; | |
10411 | } | |
10412 | } | |
10413 | ||
10414 | if (is_psd_power) { | |
10415 | /* If AP local power constraint is present */ | |
10416 | if (pwr_reduction) | |
10417 | eirp_power = eirp_power - pwr_reduction; | |
10418 | ||
10419 | /* If firmware updated max tx power is non zero, then take | |
10420 | * the min of firmware updated ap tx power | |
10421 | * and max power derived from above mentioned parameters. | |
10422 | */ | |
10423 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
10424 | "eirp power : %d firmware report power : %d\n", | |
10425 | eirp_power, ar->max_allowed_tx_power); | |
10426 | /* Firmware reports lower max_allowed_tx_power during vdev | |
10427 | * start response. In case of 6 GHz, firmware is not aware | |
10428 | * of EIRP power unless driver sets EIRP power through WMI | |
10429 | * TPC command. So radio which does not support idle power | |
10430 | * save can set maximum calculated EIRP power directly to | |
10431 | * firmware through TPC command without min comparison with | |
10432 | * vdev start response's max_allowed_tx_power. | |
10433 | */ | |
10434 | if (ar->max_allowed_tx_power && ab->hw_params->idle_ps) | |
10435 | eirp_power = min_t(s8, | |
10436 | eirp_power, | |
10437 | ar->max_allowed_tx_power); | |
10438 | } else { | |
10439 | /* If AP local power constraint is present */ | |
10440 | if (pwr_reduction) | |
10441 | max_tx_power[pwr_lvl_idx] = | |
10442 | max_tx_power[pwr_lvl_idx] - pwr_reduction; | |
10443 | /* If firmware updated max tx power is non zero, then take | |
10444 | * the min of firmware updated ap tx power | |
10445 | * and max power derived from above mentioned parameters. | |
10446 | */ | |
10447 | if (ar->max_allowed_tx_power && ab->hw_params->idle_ps) | |
10448 | max_tx_power[pwr_lvl_idx] = | |
10449 | min_t(s8, | |
10450 | max_tx_power[pwr_lvl_idx], | |
10451 | ar->max_allowed_tx_power); | |
10452 | } | |
10453 | reg_tpc_info->chan_power_info[pwr_lvl_idx].chan_cfreq = center_freq; | |
10454 | reg_tpc_info->chan_power_info[pwr_lvl_idx].tx_power = | |
10455 | max_tx_power[pwr_lvl_idx]; | |
10456 | } | |
10457 | ||
10458 | reg_tpc_info->num_pwr_levels = num_pwr_levels; | |
10459 | reg_tpc_info->is_psd_power = is_psd_power; | |
10460 | reg_tpc_info->eirp_power = eirp_power; | |
10461 | reg_tpc_info->ap_power_type = | |
10462 | ath12k_reg_ap_pwr_convert(bss_conf->power_type); | |
10463 | } | |
10464 | ||
cccbb9d0 BQ |
10465 | static void ath12k_mac_parse_tx_pwr_env(struct ath12k *ar, |
10466 | struct ath12k_link_vif *arvif) | |
10467 | { | |
10468 | struct ieee80211_bss_conf *bss_conf = ath12k_mac_get_link_bss_conf(arvif); | |
10469 | struct ath12k_reg_tpc_power_info *tpc_info = &arvif->reg_tpc_info; | |
10470 | struct ieee80211_parsed_tpe_eirp *local_non_psd, *reg_non_psd; | |
10471 | struct ieee80211_parsed_tpe_psd *local_psd, *reg_psd; | |
10472 | struct ieee80211_parsed_tpe *tpe = &bss_conf->tpe; | |
10473 | enum wmi_reg_6g_client_type client_type; | |
10474 | struct ath12k_reg_info *reg_info; | |
10475 | struct ath12k_base *ab = ar->ab; | |
10476 | bool psd_valid, non_psd_valid; | |
10477 | int i; | |
10478 | ||
10479 | reg_info = ab->reg_info[ar->pdev_idx]; | |
10480 | client_type = reg_info->client_type; | |
10481 | ||
10482 | local_psd = &tpe->psd_local[client_type]; | |
10483 | reg_psd = &tpe->psd_reg_client[client_type]; | |
10484 | local_non_psd = &tpe->max_local[client_type]; | |
10485 | reg_non_psd = &tpe->max_reg_client[client_type]; | |
10486 | ||
10487 | psd_valid = local_psd->valid | reg_psd->valid; | |
10488 | non_psd_valid = local_non_psd->valid | reg_non_psd->valid; | |
10489 | ||
10490 | if (!psd_valid && !non_psd_valid) { | |
10491 | ath12k_warn(ab, | |
10492 | "no transmit power envelope match client power type %d\n", | |
10493 | client_type); | |
10494 | return; | |
10495 | }; | |
10496 | ||
10497 | if (psd_valid) { | |
10498 | tpc_info->is_psd_power = true; | |
10499 | ||
10500 | tpc_info->num_pwr_levels = max(local_psd->count, | |
10501 | reg_psd->count); | |
10502 | if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS) | |
10503 | tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS; | |
10504 | ||
10505 | for (i = 0; i < tpc_info->num_pwr_levels; i++) { | |
10506 | tpc_info->tpe[i] = min(local_psd->power[i], | |
10507 | reg_psd->power[i]) / 2; | |
10508 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
10509 | "TPE PSD power[%d] : %d\n", | |
10510 | i, tpc_info->tpe[i]); | |
10511 | } | |
10512 | } else { | |
10513 | tpc_info->is_psd_power = false; | |
10514 | tpc_info->eirp_power = 0; | |
10515 | ||
10516 | tpc_info->num_pwr_levels = max(local_non_psd->count, | |
10517 | reg_non_psd->count); | |
10518 | if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS) | |
10519 | tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS; | |
10520 | ||
10521 | for (i = 0; i < tpc_info->num_pwr_levels; i++) { | |
10522 | tpc_info->tpe[i] = min(local_non_psd->power[i], | |
10523 | reg_non_psd->power[i]) / 2; | |
10524 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
10525 | "non PSD power[%d] : %d\n", | |
10526 | i, tpc_info->tpe[i]); | |
10527 | } | |
10528 | } | |
10529 | } | |
10530 | ||
d8899132 KV |
10531 | static int |
10532 | ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, | |
10533 | struct ieee80211_vif *vif, | |
10534 | struct ieee80211_bss_conf *link_conf, | |
10535 | struct ieee80211_chanctx_conf *ctx) | |
10536 | { | |
477cabfd | 10537 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
6db6e70a KP |
10538 | struct ath12k *ar; |
10539 | struct ath12k_base *ab; | |
3dd2c68f | 10540 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
477cabfd | 10541 | u8 link_id = link_conf->link_id; |
3dd2c68f | 10542 | struct ath12k_link_vif *arvif; |
d8899132 | 10543 | int ret; |
d8899132 | 10544 | |
b8c67509 KV |
10545 | lockdep_assert_wiphy(hw->wiphy); |
10546 | ||
31487688 S |
10547 | /* For multi radio wiphy, the vdev was not created during add_interface |
10548 | * create now since we have a channel ctx now to assign to a specific ar/fw | |
10549 | */ | |
477cabfd S |
10550 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
10551 | if (!arvif) { | |
31487688 | 10552 | WARN_ON(1); |
477cabfd S |
10553 | return -ENOMEM; |
10554 | } | |
3dd2c68f | 10555 | |
90570ba4 S |
10556 | ar = ath12k_mac_assign_vif_to_vdev(hw, arvif, ctx); |
10557 | if (!ar) { | |
ea24531d KP |
10558 | ath12k_hw_warn(ah, "failed to assign chanctx for vif %pM link id %u link vif is already started", |
10559 | vif->addr, link_id); | |
31487688 S |
10560 | return -EINVAL; |
10561 | } | |
10562 | ||
6db6e70a KP |
10563 | ab = ar->ab; |
10564 | ||
d8899132 | 10565 | ath12k_dbg(ab, ATH12K_DBG_MAC, |
2372c6d2 | 10566 | "mac chanctx assign ptr %p vdev_id %i\n", |
d8899132 KV |
10567 | ctx, arvif->vdev_id); |
10568 | ||
cccbb9d0 BQ |
10569 | if (ath12k_wmi_supports_6ghz_cc_ext(ar) && |
10570 | ctx->def.chan->band == NL80211_BAND_6GHZ && | |
10571 | ahvif->vdev_type == WMI_VDEV_TYPE_STA) | |
10572 | ath12k_mac_parse_tx_pwr_env(ar, arvif); | |
10573 | ||
b82730bf | 10574 | arvif->punct_bitmap = ctx->def.punctured; |
07c01b86 | 10575 | |
d8899132 KV |
10576 | /* for some targets bss peer must be created before vdev_start */ |
10577 | if (ab->hw_params->vdev_start_delay && | |
3dd2c68f S |
10578 | ahvif->vdev_type != WMI_VDEV_TYPE_AP && |
10579 | ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR && | |
d8899132 | 10580 | !ath12k_peer_exist_by_vdev_id(ab, arvif->vdev_id)) { |
d8899132 KV |
10581 | ret = 0; |
10582 | goto out; | |
10583 | } | |
10584 | ||
10585 | if (WARN_ON(arvif->is_started)) { | |
10586 | ret = -EBUSY; | |
10587 | goto out; | |
10588 | } | |
10589 | ||
3dd2c68f | 10590 | if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
d8899132 | 10591 | ret = ath12k_mac_monitor_start(ar); |
7423b641 KP |
10592 | if (ret) { |
10593 | ath12k_mac_monitor_vdev_delete(ar); | |
d8899132 | 10594 | goto out; |
7423b641 | 10595 | } |
3dd2c68f | 10596 | |
d8899132 KV |
10597 | arvif->is_started = true; |
10598 | goto out; | |
10599 | } | |
10600 | ||
3f53624f | 10601 | ret = ath12k_mac_vdev_start(arvif, ctx); |
d8899132 KV |
10602 | if (ret) { |
10603 | ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
10604 | arvif->vdev_id, vif->addr, | |
10605 | ctx->def.chan->center_freq, ret); | |
10606 | goto out; | |
10607 | } | |
10608 | ||
d8899132 KV |
10609 | arvif->is_started = true; |
10610 | ||
10611 | /* TODO: Setup ps and cts/rts protection */ | |
10612 | ||
10613 | out: | |
d8899132 KV |
10614 | return ret; |
10615 | } | |
10616 | ||
10617 | static void | |
10618 | ath12k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
10619 | struct ieee80211_vif *vif, | |
10620 | struct ieee80211_bss_conf *link_conf, | |
10621 | struct ieee80211_chanctx_conf *ctx) | |
10622 | { | |
6db6e70a KP |
10623 | struct ath12k *ar; |
10624 | struct ath12k_base *ab; | |
3dd2c68f S |
10625 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
10626 | struct ath12k_link_vif *arvif; | |
477cabfd | 10627 | u8 link_id = link_conf->link_id; |
d8899132 KV |
10628 | int ret; |
10629 | ||
c347f181 KV |
10630 | lockdep_assert_wiphy(hw->wiphy); |
10631 | ||
477cabfd | 10632 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); |
3dd2c68f | 10633 | |
31487688 S |
10634 | /* The vif is expected to be attached to an ar's VDEV. |
10635 | * We leave the vif/vdev in this function as is | |
10636 | * and not delete the vdev symmetric to assign_vif_chanctx() | |
10637 | * the VDEV will be deleted and unassigned either during | |
10638 | * remove_interface() or when there is a change in channel | |
10639 | * that moves the vif to a new ar | |
10640 | */ | |
477cabfd | 10641 | if (!arvif || !arvif->is_created) |
31487688 S |
10642 | return; |
10643 | ||
10644 | ar = arvif->ar; | |
6db6e70a KP |
10645 | ab = ar->ab; |
10646 | ||
d8899132 | 10647 | ath12k_dbg(ab, ATH12K_DBG_MAC, |
2372c6d2 | 10648 | "mac chanctx unassign ptr %p vdev_id %i\n", |
d8899132 KV |
10649 | ctx, arvif->vdev_id); |
10650 | ||
10651 | WARN_ON(!arvif->is_started); | |
10652 | ||
3dd2c68f | 10653 | if (ahvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { |
d8899132 | 10654 | ret = ath12k_mac_monitor_stop(ar); |
b8c67509 | 10655 | if (ret) |
d8899132 | 10656 | return; |
d8899132 KV |
10657 | |
10658 | arvif->is_started = false; | |
d8899132 KV |
10659 | } |
10660 | ||
3dd2c68f S |
10661 | if (ahvif->vdev_type != WMI_VDEV_TYPE_STA && |
10662 | ahvif->vdev_type != WMI_VDEV_TYPE_MONITOR) { | |
c9e4e41e KY |
10663 | ath12k_bss_disassoc(ar, arvif); |
10664 | ret = ath12k_mac_vdev_stop(arvif); | |
10665 | if (ret) | |
10666 | ath12k_warn(ab, "failed to stop vdev %i: %d\n", | |
10667 | arvif->vdev_id, ret); | |
10668 | } | |
d8899132 KV |
10669 | arvif->is_started = false; |
10670 | ||
591de41d WG |
10671 | if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map) && |
10672 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
10673 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE && | |
10674 | ar->state_11d != ATH12K_11D_PREPARING) { | |
10675 | reinit_completion(&ar->completed_11d_scan); | |
10676 | ar->state_11d = ATH12K_11D_PREPARING; | |
10677 | } | |
1ab2e904 LK |
10678 | |
10679 | if (ar->scan.arvif == arvif && ar->scan.state == ATH12K_SCAN_RUNNING) { | |
10680 | ath12k_scan_abort(ar); | |
10681 | ar->scan.arvif = NULL; | |
10682 | } | |
d8899132 KV |
10683 | } |
10684 | ||
10685 | static int | |
10686 | ath12k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, | |
10687 | struct ieee80211_vif_chanctx_switch *vifs, | |
10688 | int n_vifs, | |
10689 | enum ieee80211_chanctx_switch_mode mode) | |
10690 | { | |
6db6e70a KP |
10691 | struct ath12k *ar; |
10692 | ||
c347f181 KV |
10693 | lockdep_assert_wiphy(hw->wiphy); |
10694 | ||
31487688 S |
10695 | ar = ath12k_get_ar_by_ctx(hw, vifs->old_ctx); |
10696 | if (!ar) | |
10697 | return -EINVAL; | |
d8899132 | 10698 | |
31487688 | 10699 | /* Switching channels across radio is not allowed */ |
b8c67509 | 10700 | if (ar != ath12k_get_ar_by_ctx(hw, vifs->new_ctx)) |
31487688 | 10701 | return -EINVAL; |
31487688 | 10702 | |
d8899132 KV |
10703 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, |
10704 | "mac chanctx switch n_vifs %d mode %d\n", | |
10705 | n_vifs, mode); | |
10706 | ath12k_mac_update_vif_chan(ar, vifs, n_vifs); | |
10707 | ||
d8899132 KV |
10708 | return 0; |
10709 | } | |
10710 | ||
10711 | static int | |
10712 | ath12k_set_vdev_param_to_all_vifs(struct ath12k *ar, int param, u32 value) | |
10713 | { | |
3dd2c68f | 10714 | struct ath12k_link_vif *arvif; |
d8899132 KV |
10715 | int ret = 0; |
10716 | ||
b8c67509 KV |
10717 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
10718 | ||
d8899132 KV |
10719 | list_for_each_entry(arvif, &ar->arvifs, list) { |
10720 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "setting mac vdev %d param %d value %d\n", | |
10721 | param, arvif->vdev_id, value); | |
10722 | ||
10723 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
10724 | param, value); | |
10725 | if (ret) { | |
10726 | ath12k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n", | |
10727 | param, arvif->vdev_id, ret); | |
10728 | break; | |
10729 | } | |
10730 | } | |
b8c67509 | 10731 | |
d8899132 KV |
10732 | return ret; |
10733 | } | |
10734 | ||
10735 | /* mac80211 stores device specific RTS/Fragmentation threshold value, | |
10736 | * this is set interface specific to firmware from ath12k driver | |
10737 | */ | |
10738 | static int ath12k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
10739 | { | |
6db6e70a KP |
10740 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
10741 | struct ath12k *ar; | |
d258f16b | 10742 | int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD, ret = 0, i; |
d8899132 | 10743 | |
c347f181 KV |
10744 | lockdep_assert_wiphy(hw->wiphy); |
10745 | ||
d258f16b S |
10746 | /* Currently we set the rts threshold value to all the vifs across |
10747 | * all radios of the single wiphy. | |
10748 | * TODO Once support for vif specific RTS threshold in mac80211 is | |
10749 | * available, ath12k can make use of it. | |
10750 | */ | |
10751 | for_each_ar(ah, ar, i) { | |
10752 | ret = ath12k_set_vdev_param_to_all_vifs(ar, param_id, value); | |
10753 | if (ret) { | |
10754 | ath12k_warn(ar->ab, "failed to set RTS config for all vdevs of pdev %d", | |
10755 | ar->pdev->pdev_id); | |
10756 | break; | |
10757 | } | |
10758 | } | |
6db6e70a KP |
10759 | |
10760 | return ret; | |
d8899132 KV |
10761 | } |
10762 | ||
10763 | static int ath12k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) | |
10764 | { | |
10765 | /* Even though there's a WMI vdev param for fragmentation threshold no | |
10766 | * known firmware actually implements it. Moreover it is not possible to | |
10767 | * rely frame fragmentation to mac80211 because firmware clears the | |
10768 | * "more fragments" bit in frame control making it impossible for remote | |
10769 | * devices to reassemble frames. | |
10770 | * | |
10771 | * Hence implement a dummy callback just to say fragmentation isn't | |
10772 | * supported. This effectively prevents mac80211 from doing frame | |
10773 | * fragmentation in software. | |
10774 | */ | |
c347f181 KV |
10775 | |
10776 | lockdep_assert_wiphy(hw->wiphy); | |
10777 | ||
d8899132 KV |
10778 | return -EOPNOTSUPP; |
10779 | } | |
10780 | ||
692921ea | 10781 | static int ath12k_mac_flush(struct ath12k *ar) |
d8899132 | 10782 | { |
d8899132 | 10783 | long time_left; |
692921ea | 10784 | int ret = 0; |
d8899132 | 10785 | |
d8899132 KV |
10786 | time_left = wait_event_timeout(ar->dp.tx_empty_waitq, |
10787 | (atomic_read(&ar->dp.num_tx_pending) == 0), | |
10788 | ATH12K_FLUSH_TIMEOUT); | |
692921ea BQ |
10789 | if (time_left == 0) { |
10790 | ath12k_warn(ar->ab, | |
10791 | "failed to flush transmit queue, data pkts pending %d\n", | |
10792 | atomic_read(&ar->dp.num_tx_pending)); | |
10793 | ret = -ETIMEDOUT; | |
10794 | } | |
5189a8db K |
10795 | |
10796 | time_left = wait_event_timeout(ar->txmgmt_empty_waitq, | |
10797 | (atomic_read(&ar->num_pending_mgmt_tx) == 0), | |
10798 | ATH12K_FLUSH_TIMEOUT); | |
692921ea BQ |
10799 | if (time_left == 0) { |
10800 | ath12k_warn(ar->ab, | |
10801 | "failed to flush mgmt transmit queue, mgmt pkts pending %d\n", | |
10802 | atomic_read(&ar->num_pending_mgmt_tx)); | |
10803 | ret = -ETIMEDOUT; | |
10804 | } | |
10805 | ||
10806 | return ret; | |
10807 | } | |
10808 | ||
10809 | int ath12k_mac_wait_tx_complete(struct ath12k *ar) | |
10810 | { | |
56dcbf0b KV |
10811 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
10812 | ||
692921ea BQ |
10813 | ath12k_mac_drain_tx(ar); |
10814 | return ath12k_mac_flush(ar); | |
d8899132 KV |
10815 | } |
10816 | ||
b33dcbe8 KP |
10817 | static void ath12k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
10818 | u32 queues, bool drop) | |
10819 | { | |
6db6e70a | 10820 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
2197feb0 S |
10821 | struct ath12k_link_vif *arvif; |
10822 | struct ath12k_vif *ahvif; | |
10823 | unsigned long links; | |
0148e40c | 10824 | struct ath12k *ar; |
2197feb0 | 10825 | u8 link_id; |
0148e40c | 10826 | int i; |
b33dcbe8 | 10827 | |
c347f181 KV |
10828 | lockdep_assert_wiphy(hw->wiphy); |
10829 | ||
b33dcbe8 KP |
10830 | if (drop) |
10831 | return; | |
10832 | ||
0148e40c S |
10833 | /* vif can be NULL when flush() is considered for hw */ |
10834 | if (!vif) { | |
10835 | for_each_ar(ah, ar, i) | |
10836 | ath12k_mac_flush(ar); | |
10837 | return; | |
10838 | } | |
10839 | ||
2197feb0 S |
10840 | for_each_ar(ah, ar, i) |
10841 | wiphy_work_flush(hw->wiphy, &ar->wmi_mgmt_tx_work); | |
0148e40c | 10842 | |
2197feb0 S |
10843 | ahvif = ath12k_vif_to_ahvif(vif); |
10844 | links = ahvif->links_map; | |
10845 | for_each_set_bit(link_id, &links, IEEE80211_MLD_MAX_NUM_LINKS) { | |
10846 | arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]); | |
10847 | if (!(arvif && arvif->ar)) | |
10848 | continue; | |
0148e40c | 10849 | |
2197feb0 S |
10850 | ath12k_mac_flush(arvif->ar); |
10851 | } | |
b33dcbe8 KP |
10852 | } |
10853 | ||
d8899132 KV |
10854 | static int |
10855 | ath12k_mac_bitrate_mask_num_ht_rates(struct ath12k *ar, | |
10856 | enum nl80211_band band, | |
10857 | const struct cfg80211_bitrate_mask *mask) | |
10858 | { | |
10859 | int num_rates = 0; | |
10860 | int i; | |
10861 | ||
10862 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) | |
10863 | num_rates += hweight16(mask->control[band].ht_mcs[i]); | |
10864 | ||
10865 | return num_rates; | |
10866 | } | |
10867 | ||
10868 | static bool | |
10869 | ath12k_mac_has_single_legacy_rate(struct ath12k *ar, | |
10870 | enum nl80211_band band, | |
10871 | const struct cfg80211_bitrate_mask *mask) | |
10872 | { | |
10873 | int num_rates = 0; | |
10874 | ||
10875 | num_rates = hweight32(mask->control[band].legacy); | |
10876 | ||
10877 | if (ath12k_mac_bitrate_mask_num_ht_rates(ar, band, mask)) | |
10878 | return false; | |
10879 | ||
10880 | if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask)) | |
10881 | return false; | |
10882 | ||
10883 | return num_rates == 1; | |
10884 | } | |
10885 | ||
10886 | static bool | |
10887 | ath12k_mac_bitrate_mask_get_single_nss(struct ath12k *ar, | |
10888 | enum nl80211_band band, | |
10889 | const struct cfg80211_bitrate_mask *mask, | |
10890 | int *nss) | |
10891 | { | |
10892 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; | |
10893 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
10894 | u8 ht_nss_mask = 0; | |
10895 | u8 vht_nss_mask = 0; | |
10896 | int i; | |
10897 | ||
10898 | /* No need to consider legacy here. Basic rates are always present | |
10899 | * in bitrate mask | |
10900 | */ | |
10901 | ||
10902 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { | |
10903 | if (mask->control[band].ht_mcs[i] == 0) | |
10904 | continue; | |
10905 | else if (mask->control[band].ht_mcs[i] == | |
10906 | sband->ht_cap.mcs.rx_mask[i]) | |
10907 | ht_nss_mask |= BIT(i); | |
10908 | else | |
10909 | return false; | |
10910 | } | |
10911 | ||
10912 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
10913 | if (mask->control[band].vht_mcs[i] == 0) | |
10914 | continue; | |
10915 | else if (mask->control[band].vht_mcs[i] == | |
10916 | ath12k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) | |
10917 | vht_nss_mask |= BIT(i); | |
10918 | else | |
10919 | return false; | |
10920 | } | |
10921 | ||
10922 | if (ht_nss_mask != vht_nss_mask) | |
10923 | return false; | |
10924 | ||
10925 | if (ht_nss_mask == 0) | |
10926 | return false; | |
10927 | ||
10928 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) | |
10929 | return false; | |
10930 | ||
10931 | *nss = fls(ht_nss_mask); | |
10932 | ||
10933 | return true; | |
10934 | } | |
10935 | ||
10936 | static int | |
10937 | ath12k_mac_get_single_legacy_rate(struct ath12k *ar, | |
10938 | enum nl80211_band band, | |
10939 | const struct cfg80211_bitrate_mask *mask, | |
10940 | u32 *rate, u8 *nss) | |
10941 | { | |
10942 | int rate_idx; | |
10943 | u16 bitrate; | |
10944 | u8 preamble; | |
10945 | u8 hw_rate; | |
10946 | ||
10947 | if (hweight32(mask->control[band].legacy) != 1) | |
10948 | return -EINVAL; | |
10949 | ||
10950 | rate_idx = ffs(mask->control[band].legacy) - 1; | |
10951 | ||
10952 | if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ) | |
10953 | rate_idx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
10954 | ||
10955 | hw_rate = ath12k_legacy_rates[rate_idx].hw_value; | |
10956 | bitrate = ath12k_legacy_rates[rate_idx].bitrate; | |
10957 | ||
10958 | if (ath12k_mac_bitrate_is_cck(bitrate)) | |
10959 | preamble = WMI_RATE_PREAMBLE_CCK; | |
10960 | else | |
10961 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
10962 | ||
10963 | *nss = 1; | |
10964 | *rate = ATH12K_HW_RATE_CODE(hw_rate, 0, preamble); | |
10965 | ||
10966 | return 0; | |
10967 | } | |
10968 | ||
3dd2c68f | 10969 | static int ath12k_mac_set_fixed_rate_params(struct ath12k_link_vif *arvif, |
d8899132 KV |
10970 | u32 rate, u8 nss, u8 sgi, u8 ldpc) |
10971 | { | |
10972 | struct ath12k *ar = arvif->ar; | |
10973 | u32 vdev_param; | |
10974 | int ret; | |
10975 | ||
b8c67509 | 10976 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
10977 | |
10978 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n", | |
10979 | arvif->vdev_id, rate, nss, sgi); | |
10980 | ||
10981 | vdev_param = WMI_VDEV_PARAM_FIXED_RATE; | |
10982 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
10983 | vdev_param, rate); | |
10984 | if (ret) { | |
10985 | ath12k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n", | |
10986 | rate, ret); | |
10987 | return ret; | |
10988 | } | |
10989 | ||
10990 | vdev_param = WMI_VDEV_PARAM_NSS; | |
10991 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
10992 | vdev_param, nss); | |
10993 | if (ret) { | |
10994 | ath12k_warn(ar->ab, "failed to set nss param %d: %d\n", | |
10995 | nss, ret); | |
10996 | return ret; | |
10997 | } | |
10998 | ||
10999 | vdev_param = WMI_VDEV_PARAM_SGI; | |
11000 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
11001 | vdev_param, sgi); | |
11002 | if (ret) { | |
11003 | ath12k_warn(ar->ab, "failed to set sgi param %d: %d\n", | |
11004 | sgi, ret); | |
11005 | return ret; | |
11006 | } | |
11007 | ||
11008 | vdev_param = WMI_VDEV_PARAM_LDPC; | |
11009 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
11010 | vdev_param, ldpc); | |
11011 | if (ret) { | |
11012 | ath12k_warn(ar->ab, "failed to set ldpc param %d: %d\n", | |
11013 | ldpc, ret); | |
11014 | return ret; | |
11015 | } | |
11016 | ||
11017 | return 0; | |
11018 | } | |
11019 | ||
11020 | static bool | |
11021 | ath12k_mac_vht_mcs_range_present(struct ath12k *ar, | |
11022 | enum nl80211_band band, | |
11023 | const struct cfg80211_bitrate_mask *mask) | |
11024 | { | |
11025 | int i; | |
11026 | u16 vht_mcs; | |
11027 | ||
11028 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
11029 | vht_mcs = mask->control[band].vht_mcs[i]; | |
11030 | ||
11031 | switch (vht_mcs) { | |
11032 | case 0: | |
11033 | case BIT(8) - 1: | |
11034 | case BIT(9) - 1: | |
11035 | case BIT(10) - 1: | |
11036 | break; | |
11037 | default: | |
11038 | return false; | |
11039 | } | |
11040 | } | |
11041 | ||
11042 | return true; | |
11043 | } | |
11044 | ||
11045 | static void ath12k_mac_set_bitrate_mask_iter(void *data, | |
11046 | struct ieee80211_sta *sta) | |
11047 | { | |
3dd2c68f | 11048 | struct ath12k_link_vif *arvif = data; |
b89b5dbe | 11049 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
63fdb906 | 11050 | struct ath12k_link_sta *arsta; |
d8899132 KV |
11051 | struct ath12k *ar = arvif->ar; |
11052 | ||
63fdb906 S |
11053 | arsta = rcu_dereference(ahsta->link[arvif->link_id]); |
11054 | if (!arsta || arsta->arvif != arvif) | |
cec77a25 S |
11055 | return; |
11056 | ||
d8899132 KV |
11057 | spin_lock_bh(&ar->data_lock); |
11058 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; | |
11059 | spin_unlock_bh(&ar->data_lock); | |
11060 | ||
58550cdd | 11061 | wiphy_work_queue(ath12k_ar_to_hw(ar)->wiphy, &arsta->update_wk); |
d8899132 KV |
11062 | } |
11063 | ||
11064 | static void ath12k_mac_disable_peer_fixed_rate(void *data, | |
11065 | struct ieee80211_sta *sta) | |
11066 | { | |
3dd2c68f | 11067 | struct ath12k_link_vif *arvif = data; |
b89b5dbe | 11068 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
63fdb906 | 11069 | struct ath12k_link_sta *arsta; |
d8899132 KV |
11070 | struct ath12k *ar = arvif->ar; |
11071 | int ret; | |
11072 | ||
63fdb906 S |
11073 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
11074 | ||
11075 | arsta = wiphy_dereference(ath12k_ar_to_hw(ar)->wiphy, | |
11076 | ahsta->link[arvif->link_id]); | |
11077 | ||
11078 | if (!arsta || arsta->arvif != arvif) | |
cec77a25 S |
11079 | return; |
11080 | ||
061097e5 | 11081 | ret = ath12k_wmi_set_peer_param(ar, arsta->addr, |
d8899132 KV |
11082 | arvif->vdev_id, |
11083 | WMI_PEER_PARAM_FIXED_RATE, | |
11084 | WMI_FIXED_RATE_NONE); | |
11085 | if (ret) | |
11086 | ath12k_warn(ar->ab, | |
11087 | "failed to disable peer fixed rate for STA %pM ret %d\n", | |
061097e5 | 11088 | arsta->addr, ret); |
d8899132 KV |
11089 | } |
11090 | ||
11091 | static int | |
11092 | ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, | |
11093 | struct ieee80211_vif *vif, | |
11094 | const struct cfg80211_bitrate_mask *mask) | |
11095 | { | |
3dd2c68f S |
11096 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
11097 | struct ath12k_link_vif *arvif; | |
d8899132 | 11098 | struct cfg80211_chan_def def; |
3dd2c68f | 11099 | struct ath12k *ar; |
d8899132 KV |
11100 | enum nl80211_band band; |
11101 | const u8 *ht_mcs_mask; | |
11102 | const u16 *vht_mcs_mask; | |
11103 | u32 rate; | |
11104 | u8 nss; | |
11105 | u8 sgi; | |
11106 | u8 ldpc; | |
11107 | int single_nss; | |
11108 | int ret; | |
11109 | int num_rates; | |
11110 | ||
b8c67509 KV |
11111 | lockdep_assert_wiphy(hw->wiphy); |
11112 | ||
3dd2c68f S |
11113 | arvif = &ahvif->deflink; |
11114 | ||
11115 | ar = arvif->ar; | |
abaadb93 | 11116 | if (ath12k_mac_vif_link_chan(vif, arvif->link_id, &def)) { |
3dd2c68f S |
11117 | ret = -EPERM; |
11118 | goto out; | |
11119 | } | |
d8899132 KV |
11120 | |
11121 | band = def.chan->band; | |
11122 | ht_mcs_mask = mask->control[band].ht_mcs; | |
11123 | vht_mcs_mask = mask->control[band].vht_mcs; | |
11124 | ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); | |
11125 | ||
11126 | sgi = mask->control[band].gi; | |
6db6e70a KP |
11127 | if (sgi == NL80211_TXRATE_FORCE_LGI) { |
11128 | ret = -EINVAL; | |
11129 | goto out; | |
11130 | } | |
d8899132 KV |
11131 | |
11132 | /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it | |
11133 | * requires passing at least one of used basic rates along with them. | |
11134 | * Fixed rate setting across different preambles(legacy, HT, VHT) is | |
11135 | * not supported by the FW. Hence use of FIXED_RATE vdev param is not | |
11136 | * suitable for setting single HT/VHT rates. | |
11137 | * But, there could be a single basic rate passed from userspace which | |
11138 | * can be done through the FIXED_RATE param. | |
11139 | */ | |
11140 | if (ath12k_mac_has_single_legacy_rate(ar, band, mask)) { | |
11141 | ret = ath12k_mac_get_single_legacy_rate(ar, band, mask, &rate, | |
11142 | &nss); | |
11143 | if (ret) { | |
11144 | ath12k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n", | |
11145 | arvif->vdev_id, ret); | |
6db6e70a | 11146 | goto out; |
d8899132 | 11147 | } |
8fac3266 KV |
11148 | ieee80211_iterate_stations_mtx(hw, |
11149 | ath12k_mac_disable_peer_fixed_rate, | |
11150 | arvif); | |
d8899132 KV |
11151 | } else if (ath12k_mac_bitrate_mask_get_single_nss(ar, band, mask, |
11152 | &single_nss)) { | |
11153 | rate = WMI_FIXED_RATE_NONE; | |
11154 | nss = single_nss; | |
11155 | } else { | |
11156 | rate = WMI_FIXED_RATE_NONE; | |
11157 | nss = min_t(u32, ar->num_tx_chains, | |
11158 | max(ath12k_mac_max_ht_nss(ht_mcs_mask), | |
11159 | ath12k_mac_max_vht_nss(vht_mcs_mask))); | |
11160 | ||
11161 | /* If multiple rates across different preambles are given | |
11162 | * we can reconfigure this info with all peers using PEER_ASSOC | |
11163 | * command with the below exception cases. | |
11164 | * - Single VHT Rate : peer_assoc command accommodates only MCS | |
11165 | * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211 | |
11166 | * mandates passing basic rates along with HT/VHT rates, FW | |
11167 | * doesn't allow switching from VHT to Legacy. Hence instead of | |
11168 | * setting legacy and VHT rates using RATEMASK_CMD vdev cmd, | |
11169 | * we could set this VHT rate as peer fixed rate param, which | |
11170 | * will override FIXED rate and FW rate control algorithm. | |
11171 | * If single VHT rate is passed along with HT rates, we select | |
11172 | * the VHT rate as fixed rate for vht peers. | |
11173 | * - Multiple VHT Rates : When Multiple VHT rates are given,this | |
11174 | * can be set using RATEMASK CMD which uses FW rate-ctl alg. | |
11175 | * TODO: Setting multiple VHT MCS and replacing peer_assoc with | |
11176 | * RATEMASK_CMDID can cover all use cases of setting rates | |
11177 | * across multiple preambles and rates within same type. | |
11178 | * But requires more validation of the command at this point. | |
11179 | */ | |
11180 | ||
11181 | num_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, | |
11182 | mask); | |
11183 | ||
11184 | if (!ath12k_mac_vht_mcs_range_present(ar, band, mask) && | |
11185 | num_rates > 1) { | |
11186 | /* TODO: Handle multiple VHT MCS values setting using | |
11187 | * RATEMASK CMD | |
11188 | */ | |
11189 | ath12k_warn(ar->ab, | |
11190 | "Setting more than one MCS Value in bitrate mask not supported\n"); | |
31489439 | 11191 | return -EINVAL; |
d8899132 KV |
11192 | } |
11193 | ||
8fac3266 KV |
11194 | ieee80211_iterate_stations_mtx(hw, |
11195 | ath12k_mac_disable_peer_fixed_rate, | |
11196 | arvif); | |
d8899132 KV |
11197 | |
11198 | arvif->bitrate_mask = *mask; | |
8fac3266 KV |
11199 | ieee80211_iterate_stations_mtx(hw, |
11200 | ath12k_mac_set_bitrate_mask_iter, | |
11201 | arvif); | |
d8899132 KV |
11202 | } |
11203 | ||
d8899132 KV |
11204 | ret = ath12k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); |
11205 | if (ret) { | |
11206 | ath12k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n", | |
11207 | arvif->vdev_id, ret); | |
11208 | } | |
11209 | ||
6db6e70a | 11210 | out: |
d8899132 KV |
11211 | return ret; |
11212 | } | |
11213 | ||
11214 | static void | |
11215 | ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw, | |
11216 | enum ieee80211_reconfig_type reconfig_type) | |
11217 | { | |
6db6e70a KP |
11218 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
11219 | struct ath12k *ar; | |
11220 | struct ath12k_base *ab; | |
3dd2c68f S |
11221 | struct ath12k_vif *ahvif; |
11222 | struct ath12k_link_vif *arvif; | |
ecd509b6 | 11223 | int recovery_count, i; |
d8899132 | 11224 | |
b8c67509 KV |
11225 | lockdep_assert_wiphy(hw->wiphy); |
11226 | ||
d8899132 KV |
11227 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
11228 | return; | |
11229 | ||
acaa8400 KP |
11230 | guard(mutex)(&ah->hw_mutex); |
11231 | ||
9b4e5caa KP |
11232 | if (ah->state != ATH12K_HW_STATE_RESTARTED) |
11233 | return; | |
11234 | ||
11235 | ah->state = ATH12K_HW_STATE_ON; | |
11236 | ieee80211_wake_queues(hw); | |
11237 | ||
ecd509b6 | 11238 | for_each_ar(ah, ar, i) { |
ecd509b6 | 11239 | ab = ar->ab; |
d8899132 | 11240 | |
d8899132 KV |
11241 | ath12k_warn(ar->ab, "pdev %d successfully recovered\n", |
11242 | ar->pdev->pdev_id); | |
ecd509b6 | 11243 | |
dcfebfd4 WG |
11244 | if (ar->ab->hw_params->current_cc_support && |
11245 | ar->alpha2[0] != 0 && ar->alpha2[1] != 0) { | |
11246 | struct wmi_set_current_country_arg arg = {}; | |
11247 | ||
11248 | memcpy(&arg.alpha2, ar->alpha2, 2); | |
11249 | ath12k_wmi_send_set_current_country_cmd(ar, &arg); | |
11250 | } | |
11251 | ||
d8899132 KV |
11252 | if (ab->is_reset) { |
11253 | recovery_count = atomic_inc_return(&ab->recovery_count); | |
ecd509b6 | 11254 | |
d8899132 KV |
11255 | ath12k_dbg(ab, ATH12K_DBG_BOOT, "recovery count %d\n", |
11256 | recovery_count); | |
ecd509b6 | 11257 | |
d8899132 KV |
11258 | /* When there are multiple radios in an SOC, |
11259 | * the recovery has to be done for each radio | |
11260 | */ | |
11261 | if (recovery_count == ab->num_radios) { | |
11262 | atomic_dec(&ab->reset_count); | |
11263 | complete(&ab->reset_complete); | |
11264 | ab->is_reset = false; | |
11265 | atomic_set(&ab->fail_cont_count, 0); | |
11266 | ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset success\n"); | |
11267 | } | |
11268 | } | |
68c35cc3 WG |
11269 | |
11270 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
3dd2c68f | 11271 | ahvif = arvif->ahvif; |
68c35cc3 WG |
11272 | ath12k_dbg(ab, ATH12K_DBG_BOOT, |
11273 | "reconfig cipher %d up %d vdev type %d\n", | |
3dd2c68f | 11274 | ahvif->key_cipher, |
68c35cc3 | 11275 | arvif->is_up, |
3dd2c68f | 11276 | ahvif->vdev_type); |
ecd509b6 | 11277 | |
68c35cc3 WG |
11278 | /* After trigger disconnect, then upper layer will |
11279 | * trigger connect again, then the PN number of | |
11280 | * upper layer will be reset to keep up with AP | |
4f1dbb49 | 11281 | * side, hence PN number mismatch will not happen. |
68c35cc3 WG |
11282 | */ |
11283 | if (arvif->is_up && | |
3dd2c68f S |
11284 | ahvif->vdev_type == WMI_VDEV_TYPE_STA && |
11285 | ahvif->vdev_subtype == WMI_VDEV_SUBTYPE_NONE) { | |
11286 | ieee80211_hw_restart_disconnect(ahvif->vif); | |
ecd509b6 | 11287 | |
68c35cc3 WG |
11288 | ath12k_dbg(ab, ATH12K_DBG_BOOT, |
11289 | "restart disconnect\n"); | |
11290 | } | |
11291 | } | |
ecd509b6 | 11292 | } |
d8899132 KV |
11293 | } |
11294 | ||
11295 | static void | |
11296 | ath12k_mac_update_bss_chan_survey(struct ath12k *ar, | |
11297 | struct ieee80211_channel *channel) | |
11298 | { | |
11299 | int ret; | |
11300 | enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; | |
11301 | ||
b8c67509 | 11302 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
d8899132 KV |
11303 | |
11304 | if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) || | |
11305 | ar->rx_channel != channel) | |
11306 | return; | |
11307 | ||
11308 | if (ar->scan.state != ATH12K_SCAN_IDLE) { | |
11309 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
11310 | "ignoring bss chan info req while scanning..\n"); | |
11311 | return; | |
11312 | } | |
11313 | ||
11314 | reinit_completion(&ar->bss_survey_done); | |
11315 | ||
11316 | ret = ath12k_wmi_pdev_bss_chan_info_request(ar, type); | |
11317 | if (ret) { | |
11318 | ath12k_warn(ar->ab, "failed to send pdev bss chan info request\n"); | |
11319 | return; | |
11320 | } | |
11321 | ||
11322 | ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); | |
11323 | if (ret == 0) | |
11324 | ath12k_warn(ar->ab, "bss channel survey timed out\n"); | |
11325 | } | |
11326 | ||
11327 | static int ath12k_mac_op_get_survey(struct ieee80211_hw *hw, int idx, | |
11328 | struct survey_info *survey) | |
11329 | { | |
6db6e70a | 11330 | struct ath12k *ar; |
d8899132 KV |
11331 | struct ieee80211_supported_band *sband; |
11332 | struct survey_info *ar_survey; | |
d8899132 | 11333 | |
b8c67509 KV |
11334 | lockdep_assert_wiphy(hw->wiphy); |
11335 | ||
d8899132 KV |
11336 | if (idx >= ATH12K_NUM_CHANS) |
11337 | return -ENOENT; | |
11338 | ||
d8899132 KV |
11339 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; |
11340 | if (sband && idx >= sband->n_channels) { | |
11341 | idx -= sband->n_channels; | |
11342 | sband = NULL; | |
11343 | } | |
11344 | ||
11345 | if (!sband) | |
11346 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; | |
70e3be54 PKC |
11347 | if (sband && idx >= sband->n_channels) { |
11348 | idx -= sband->n_channels; | |
11349 | sband = NULL; | |
11350 | } | |
11351 | ||
11352 | if (!sband) | |
11353 | sband = hw->wiphy->bands[NL80211_BAND_6GHZ]; | |
d8899132 | 11354 | |
4f242b1d S |
11355 | if (!sband || idx >= sband->n_channels) |
11356 | return -ENOENT; | |
11357 | ||
11358 | ar = ath12k_mac_get_ar_by_chan(hw, &sband->channels[idx]); | |
11359 | if (!ar) { | |
11360 | if (sband->channels[idx].flags & IEEE80211_CHAN_DISABLED) { | |
11361 | memset(survey, 0, sizeof(*survey)); | |
11362 | return 0; | |
11363 | } | |
11364 | return -ENOENT; | |
d8899132 KV |
11365 | } |
11366 | ||
4f242b1d S |
11367 | ar_survey = &ar->survey[idx]; |
11368 | ||
d8899132 KV |
11369 | ath12k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); |
11370 | ||
11371 | spin_lock_bh(&ar->data_lock); | |
11372 | memcpy(survey, ar_survey, sizeof(*survey)); | |
11373 | spin_unlock_bh(&ar->data_lock); | |
11374 | ||
11375 | survey->channel = &sband->channels[idx]; | |
11376 | ||
11377 | if (ar->rx_channel == survey->channel) | |
11378 | survey->filled |= SURVEY_INFO_IN_USE; | |
11379 | ||
4f242b1d | 11380 | return 0; |
d8899132 KV |
11381 | } |
11382 | ||
11383 | static void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, | |
11384 | struct ieee80211_vif *vif, | |
11385 | struct ieee80211_sta *sta, | |
11386 | struct station_info *sinfo) | |
11387 | { | |
b89b5dbe | 11388 | struct ath12k_sta *ahsta = ath12k_sta_to_ahsta(sta); |
b8a0d83f | 11389 | struct ath12k_fw_stats_req_params params = {}; |
b89b5dbe | 11390 | struct ath12k_link_sta *arsta; |
79e7b04b LK |
11391 | struct ath12k *ar; |
11392 | s8 signal; | |
11393 | bool db2dbm; | |
d8899132 | 11394 | |
c347f181 KV |
11395 | lockdep_assert_wiphy(hw->wiphy); |
11396 | ||
b89b5dbe | 11397 | arsta = &ahsta->deflink; |
79e7b04b LK |
11398 | ar = ath12k_get_ar_by_vif(hw, vif, arsta->link_id); |
11399 | if (!ar) | |
11400 | return; | |
11401 | ||
11402 | db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT, | |
11403 | ar->ab->wmi_ab.svc_map); | |
d8899132 KV |
11404 | |
11405 | sinfo->rx_duration = arsta->rx_duration; | |
11406 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); | |
11407 | ||
11408 | sinfo->tx_duration = arsta->tx_duration; | |
11409 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); | |
11410 | ||
8a5ad319 RP |
11411 | if (arsta->txrate.legacy || arsta->txrate.nss) { |
11412 | if (arsta->txrate.legacy) { | |
11413 | sinfo->txrate.legacy = arsta->txrate.legacy; | |
11414 | } else { | |
11415 | sinfo->txrate.mcs = arsta->txrate.mcs; | |
11416 | sinfo->txrate.nss = arsta->txrate.nss; | |
11417 | sinfo->txrate.bw = arsta->txrate.bw; | |
11418 | sinfo->txrate.he_gi = arsta->txrate.he_gi; | |
11419 | sinfo->txrate.he_dcm = arsta->txrate.he_dcm; | |
11420 | sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc; | |
11421 | sinfo->txrate.eht_gi = arsta->txrate.eht_gi; | |
11422 | sinfo->txrate.eht_ru_alloc = arsta->txrate.eht_ru_alloc; | |
11423 | } | |
11424 | sinfo->txrate.flags = arsta->txrate.flags; | |
11425 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); | |
11426 | } | |
d8899132 KV |
11427 | |
11428 | /* TODO: Use real NF instead of default one. */ | |
79e7b04b LK |
11429 | signal = arsta->rssi_comb; |
11430 | ||
b8a0d83f AKS |
11431 | params.pdev_id = ar->pdev->pdev_id; |
11432 | params.vdev_id = 0; | |
11433 | params.stats_id = WMI_REQUEST_VDEV_STAT; | |
11434 | ||
79e7b04b LK |
11435 | if (!signal && |
11436 | ahsta->ahvif->vdev_type == WMI_VDEV_TYPE_STA && | |
b8a0d83f | 11437 | !(ath12k_mac_get_fw_stats(ar, ¶ms))) |
79e7b04b LK |
11438 | signal = arsta->rssi_beacon; |
11439 | ||
11440 | if (signal) { | |
11441 | sinfo->signal = db2dbm ? signal : signal + ATH12K_DEFAULT_NOISE_FLOOR; | |
11442 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); | |
11443 | } | |
cb53a678 NE |
11444 | |
11445 | sinfo->signal_avg = ewma_avg_rssi_read(&arsta->avg_rssi); | |
11446 | ||
11447 | if (!db2dbm) | |
11448 | sinfo->signal_avg += ATH12K_DEFAULT_NOISE_FLOOR; | |
11449 | ||
11450 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); | |
d8899132 KV |
11451 | } |
11452 | ||
2830bc9e KY |
11453 | static int ath12k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw, |
11454 | struct ieee80211_vif *vif) | |
11455 | { | |
11456 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); | |
11457 | struct ath12k *ar; | |
11458 | ||
ba12f08f | 11459 | ar = ath12k_ah_to_ar(ah, 0); |
2830bc9e | 11460 | |
b8c67509 | 11461 | lockdep_assert_wiphy(hw->wiphy); |
2830bc9e KY |
11462 | |
11463 | spin_lock_bh(&ar->data_lock); | |
11464 | ar->scan.roc_notify = false; | |
11465 | spin_unlock_bh(&ar->data_lock); | |
11466 | ||
11467 | ath12k_scan_abort(ar); | |
11468 | ||
2830bc9e | 11469 | cancel_delayed_work_sync(&ar->scan.timeout); |
3863f014 | 11470 | wiphy_work_cancel(hw->wiphy, &ar->scan.vdev_clean_wk); |
2830bc9e KY |
11471 | |
11472 | return 0; | |
11473 | } | |
11474 | ||
11475 | static int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw, | |
11476 | struct ieee80211_vif *vif, | |
11477 | struct ieee80211_channel *chan, | |
11478 | int duration, | |
11479 | enum ieee80211_roc_type type) | |
11480 | { | |
3dd2c68f | 11481 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
2830bc9e | 11482 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
3dd2c68f | 11483 | struct ath12k_link_vif *arvif; |
477cabfd | 11484 | struct ath12k *ar; |
2830bc9e | 11485 | u32 scan_time_msec; |
4938ba73 | 11486 | bool create = true; |
477cabfd | 11487 | u8 link_id; |
2830bc9e KY |
11488 | int ret; |
11489 | ||
b8c67509 | 11490 | lockdep_assert_wiphy(hw->wiphy); |
4938ba73 RS |
11491 | |
11492 | ar = ath12k_mac_select_scan_device(hw, vif, chan->center_freq); | |
aa21668a JJ |
11493 | if (!ar) |
11494 | return -EINVAL; | |
4938ba73 | 11495 | |
477cabfd | 11496 | /* check if any of the links of ML VIF is already started on |
15293c18 | 11497 | * radio(ar) corresponding to given scan frequency and use it, |
477cabfd S |
11498 | * if not use deflink(link 0) for scan purpose. |
11499 | */ | |
11500 | ||
11501 | link_id = ath12k_mac_find_link_id_by_ar(ahvif, ar); | |
11502 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); | |
4938ba73 RS |
11503 | /* If the vif is already assigned to a specific vdev of an ar, |
11504 | * check whether its already started, vdev which is started | |
11505 | * are not allowed to switch to a new radio. | |
11506 | * If the vdev is not started, but was earlier created on a | |
11507 | * different ar, delete that vdev and create a new one. We don't | |
11508 | * delete at the scan stop as an optimization to avoid redundant | |
11509 | * delete-create vdev's for the same ar, in case the request is | |
11510 | * always on the same band for the vif | |
11511 | */ | |
11512 | if (arvif->is_created) { | |
aa21668a JJ |
11513 | if (WARN_ON(!arvif->ar)) |
11514 | return -EINVAL; | |
4938ba73 | 11515 | |
aa21668a JJ |
11516 | if (ar != arvif->ar && arvif->is_started) |
11517 | return -EBUSY; | |
2830bc9e | 11518 | |
4938ba73 | 11519 | if (ar != arvif->ar) { |
477cabfd S |
11520 | ath12k_mac_remove_link_interface(hw, arvif); |
11521 | ath12k_mac_unassign_link_vif(arvif); | |
4938ba73 RS |
11522 | } else { |
11523 | create = false; | |
11524 | } | |
11525 | } | |
11526 | ||
11527 | if (create) { | |
477cabfd S |
11528 | arvif = ath12k_mac_assign_link_vif(ah, vif, link_id); |
11529 | ||
005fe43b | 11530 | ret = ath12k_mac_vdev_create(ar, arvif); |
4938ba73 RS |
11531 | if (ret) { |
11532 | ath12k_warn(ar->ab, "unable to create scan vdev for roc: %d\n", | |
11533 | ret); | |
aa21668a | 11534 | return ret; |
4938ba73 RS |
11535 | } |
11536 | } | |
2830bc9e | 11537 | |
2830bc9e KY |
11538 | spin_lock_bh(&ar->data_lock); |
11539 | ||
11540 | switch (ar->scan.state) { | |
11541 | case ATH12K_SCAN_IDLE: | |
11542 | reinit_completion(&ar->scan.started); | |
11543 | reinit_completion(&ar->scan.completed); | |
11544 | reinit_completion(&ar->scan.on_channel); | |
11545 | ar->scan.state = ATH12K_SCAN_STARTING; | |
11546 | ar->scan.is_roc = true; | |
3863f014 | 11547 | ar->scan.arvif = arvif; |
2830bc9e KY |
11548 | ar->scan.roc_freq = chan->center_freq; |
11549 | ar->scan.roc_notify = true; | |
11550 | ret = 0; | |
11551 | break; | |
11552 | case ATH12K_SCAN_STARTING: | |
11553 | case ATH12K_SCAN_RUNNING: | |
11554 | case ATH12K_SCAN_ABORTING: | |
11555 | ret = -EBUSY; | |
11556 | break; | |
11557 | } | |
11558 | ||
11559 | spin_unlock_bh(&ar->data_lock); | |
11560 | ||
11561 | if (ret) | |
aa21668a | 11562 | return ret; |
2830bc9e KY |
11563 | |
11564 | scan_time_msec = hw->wiphy->max_remain_on_channel_duration * 2; | |
11565 | ||
aa21668a JJ |
11566 | struct ath12k_wmi_scan_req_arg *arg __free(kfree) = |
11567 | kzalloc(sizeof(*arg), GFP_KERNEL); | |
11568 | if (!arg) | |
11569 | return -ENOMEM; | |
2830bc9e | 11570 | |
aa21668a JJ |
11571 | ath12k_wmi_start_scan_init(ar, arg); |
11572 | arg->num_chan = 1; | |
11573 | ||
11574 | u32 *chan_list __free(kfree) = kcalloc(arg->num_chan, sizeof(*chan_list), | |
11575 | GFP_KERNEL); | |
11576 | if (!chan_list) | |
11577 | return -ENOMEM; | |
11578 | ||
11579 | arg->chan_list = chan_list; | |
11580 | arg->vdev_id = arvif->vdev_id; | |
11581 | arg->scan_id = ATH12K_SCAN_ID; | |
11582 | arg->chan_list[0] = chan->center_freq; | |
11583 | arg->dwell_time_active = scan_time_msec; | |
11584 | arg->dwell_time_passive = scan_time_msec; | |
11585 | arg->max_scan_time = scan_time_msec; | |
11586 | arg->scan_f_passive = 1; | |
11587 | arg->burst_duration = duration; | |
11588 | ||
11589 | ret = ath12k_start_scan(ar, arg); | |
2830bc9e KY |
11590 | if (ret) { |
11591 | ath12k_warn(ar->ab, "failed to start roc scan: %d\n", ret); | |
11592 | ||
11593 | spin_lock_bh(&ar->data_lock); | |
11594 | ar->scan.state = ATH12K_SCAN_IDLE; | |
11595 | spin_unlock_bh(&ar->data_lock); | |
aa21668a | 11596 | return ret; |
2830bc9e KY |
11597 | } |
11598 | ||
11599 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ); | |
11600 | if (ret == 0) { | |
11601 | ath12k_warn(ar->ab, "failed to switch to channel for roc scan\n"); | |
11602 | ret = ath12k_scan_stop(ar); | |
11603 | if (ret) | |
11604 | ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); | |
aa21668a | 11605 | return -ETIMEDOUT; |
2830bc9e KY |
11606 | } |
11607 | ||
11608 | ieee80211_queue_delayed_work(hw, &ar->scan.timeout, | |
11609 | msecs_to_jiffies(duration)); | |
11610 | ||
aa21668a | 11611 | return 0; |
2830bc9e KY |
11612 | } |
11613 | ||
aab4ae56 BQ |
11614 | static void ath12k_mac_op_set_rekey_data(struct ieee80211_hw *hw, |
11615 | struct ieee80211_vif *vif, | |
11616 | struct cfg80211_gtk_rekey_data *data) | |
11617 | { | |
3dd2c68f S |
11618 | struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif); |
11619 | struct ath12k_rekey_data *rekey_data; | |
aab4ae56 BQ |
11620 | struct ath12k_hw *ah = ath12k_hw_to_ah(hw); |
11621 | struct ath12k *ar = ath12k_ah_to_ar(ah, 0); | |
3dd2c68f | 11622 | struct ath12k_link_vif *arvif; |
aab4ae56 | 11623 | |
b8c67509 KV |
11624 | lockdep_assert_wiphy(hw->wiphy); |
11625 | ||
3dd2c68f S |
11626 | arvif = &ahvif->deflink; |
11627 | rekey_data = &arvif->rekey_data; | |
aab4ae56 BQ |
11628 | |
11629 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set rekey data vdev %d\n", | |
11630 | arvif->vdev_id); | |
11631 | ||
aab4ae56 BQ |
11632 | memcpy(rekey_data->kck, data->kck, NL80211_KCK_LEN); |
11633 | memcpy(rekey_data->kek, data->kek, NL80211_KEK_LEN); | |
11634 | ||
11635 | /* The supplicant works on big-endian, the firmware expects it on | |
11636 | * little endian. | |
11637 | */ | |
11638 | rekey_data->replay_ctr = get_unaligned_be64(data->replay_ctr); | |
11639 | ||
11640 | arvif->rekey_data.enable_offload = true; | |
11641 | ||
11642 | ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kck", NULL, | |
11643 | rekey_data->kck, NL80211_KCK_LEN); | |
11644 | ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "kek", NULL, | |
11645 | rekey_data->kck, NL80211_KEK_LEN); | |
11646 | ath12k_dbg_dump(ar->ab, ATH12K_DBG_MAC, "replay ctr", NULL, | |
11647 | &rekey_data->replay_ctr, sizeof(rekey_data->replay_ctr)); | |
aab4ae56 BQ |
11648 | } |
11649 | ||
d8899132 KV |
11650 | static const struct ieee80211_ops ath12k_ops = { |
11651 | .tx = ath12k_mac_op_tx, | |
11652 | .wake_tx_queue = ieee80211_handle_wake_tx_queue, | |
11653 | .start = ath12k_mac_op_start, | |
11654 | .stop = ath12k_mac_op_stop, | |
11655 | .reconfig_complete = ath12k_mac_op_reconfig_complete, | |
11656 | .add_interface = ath12k_mac_op_add_interface, | |
11657 | .remove_interface = ath12k_mac_op_remove_interface, | |
11658 | .update_vif_offload = ath12k_mac_op_update_vif_offload, | |
11659 | .config = ath12k_mac_op_config, | |
afbab6e4 S |
11660 | .link_info_changed = ath12k_mac_op_link_info_changed, |
11661 | .vif_cfg_changed = ath12k_mac_op_vif_cfg_changed, | |
477cabfd | 11662 | .change_vif_links = ath12k_mac_op_change_vif_links, |
d8899132 KV |
11663 | .configure_filter = ath12k_mac_op_configure_filter, |
11664 | .hw_scan = ath12k_mac_op_hw_scan, | |
11665 | .cancel_hw_scan = ath12k_mac_op_cancel_hw_scan, | |
11666 | .set_key = ath12k_mac_op_set_key, | |
aab4ae56 | 11667 | .set_rekey_data = ath12k_mac_op_set_rekey_data, |
d8899132 KV |
11668 | .sta_state = ath12k_mac_op_sta_state, |
11669 | .sta_set_txpwr = ath12k_mac_op_sta_set_txpwr, | |
8c214370 | 11670 | .link_sta_rc_update = ath12k_mac_op_link_sta_rc_update, |
d8899132 KV |
11671 | .conf_tx = ath12k_mac_op_conf_tx, |
11672 | .set_antenna = ath12k_mac_op_set_antenna, | |
11673 | .get_antenna = ath12k_mac_op_get_antenna, | |
11674 | .ampdu_action = ath12k_mac_op_ampdu_action, | |
11675 | .add_chanctx = ath12k_mac_op_add_chanctx, | |
11676 | .remove_chanctx = ath12k_mac_op_remove_chanctx, | |
11677 | .change_chanctx = ath12k_mac_op_change_chanctx, | |
11678 | .assign_vif_chanctx = ath12k_mac_op_assign_vif_chanctx, | |
11679 | .unassign_vif_chanctx = ath12k_mac_op_unassign_vif_chanctx, | |
11680 | .switch_vif_chanctx = ath12k_mac_op_switch_vif_chanctx, | |
e92c658b | 11681 | .get_txpower = ath12k_mac_op_get_txpower, |
d8899132 KV |
11682 | .set_rts_threshold = ath12k_mac_op_set_rts_threshold, |
11683 | .set_frag_threshold = ath12k_mac_op_set_frag_threshold, | |
11684 | .set_bitrate_mask = ath12k_mac_op_set_bitrate_mask, | |
11685 | .get_survey = ath12k_mac_op_get_survey, | |
11686 | .flush = ath12k_mac_op_flush, | |
11687 | .sta_statistics = ath12k_mac_op_sta_statistics, | |
2830bc9e KY |
11688 | .remain_on_channel = ath12k_mac_op_remain_on_channel, |
11689 | .cancel_remain_on_channel = ath12k_mac_op_cancel_remain_on_channel, | |
a27fa614 | 11690 | .change_sta_links = ath12k_mac_op_change_sta_links, |
6792b3ca | 11691 | .can_activate_links = ath12k_mac_op_can_activate_links, |
4a3c212e BQ |
11692 | #ifdef CONFIG_PM |
11693 | .suspend = ath12k_wow_op_suspend, | |
11694 | .resume = ath12k_wow_op_resume, | |
11695 | .set_wakeup = ath12k_wow_op_set_wakeup, | |
5e009751 BM |
11696 | #endif |
11697 | #ifdef CONFIG_ATH12K_DEBUGFS | |
11698 | .vif_add_debugfs = ath12k_debugfs_op_vif_add, | |
4a3c212e | 11699 | #endif |
3bc374cb | 11700 | CFG80211_TESTMODE_CMD(ath12k_tm_cmd) |
a412547f KP |
11701 | #ifdef CONFIG_ATH12K_DEBUGFS |
11702 | .link_sta_add_debugfs = ath12k_debugfs_link_sta_op_add, | |
11703 | #endif | |
d8899132 KV |
11704 | }; |
11705 | ||
b7544de8 RS |
11706 | void ath12k_mac_update_freq_range(struct ath12k *ar, |
11707 | u32 freq_low, u32 freq_high) | |
11708 | { | |
11709 | if (!(freq_low && freq_high)) | |
11710 | return; | |
11711 | ||
0d777aa2 AKS |
11712 | if (ar->freq_range.start_freq || ar->freq_range.end_freq) { |
11713 | ar->freq_range.start_freq = min(ar->freq_range.start_freq, | |
11714 | MHZ_TO_KHZ(freq_low)); | |
11715 | ar->freq_range.end_freq = max(ar->freq_range.end_freq, | |
11716 | MHZ_TO_KHZ(freq_high)); | |
11717 | } else { | |
11718 | ar->freq_range.start_freq = MHZ_TO_KHZ(freq_low); | |
11719 | ar->freq_range.end_freq = MHZ_TO_KHZ(freq_high); | |
11720 | } | |
11721 | ||
11722 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
11723 | "mac pdev %u freq limit updated. New range %u->%u MHz\n", | |
11724 | ar->pdev->pdev_id, KHZ_TO_MHZ(ar->freq_range.start_freq), | |
11725 | KHZ_TO_MHZ(ar->freq_range.end_freq)); | |
b7544de8 RS |
11726 | } |
11727 | ||
d8899132 KV |
11728 | static void ath12k_mac_update_ch_list(struct ath12k *ar, |
11729 | struct ieee80211_supported_band *band, | |
11730 | u32 freq_low, u32 freq_high) | |
11731 | { | |
11732 | int i; | |
11733 | ||
11734 | if (!(freq_low && freq_high)) | |
11735 | return; | |
11736 | ||
11737 | for (i = 0; i < band->n_channels; i++) { | |
11738 | if (band->channels[i].center_freq < freq_low || | |
11739 | band->channels[i].center_freq > freq_high) | |
11740 | band->channels[i].flags |= IEEE80211_CHAN_DISABLED; | |
11741 | } | |
11742 | } | |
11743 | ||
11744 | static u32 ath12k_get_phy_id(struct ath12k *ar, u32 band) | |
11745 | { | |
11746 | struct ath12k_pdev *pdev = ar->pdev; | |
11747 | struct ath12k_pdev_cap *pdev_cap = &pdev->cap; | |
11748 | ||
6a88093f | 11749 | if (band == WMI_HOST_WLAN_2GHZ_CAP) |
d8899132 KV |
11750 | return pdev_cap->band[NL80211_BAND_2GHZ].phy_id; |
11751 | ||
6a88093f | 11752 | if (band == WMI_HOST_WLAN_5GHZ_CAP) |
d8899132 KV |
11753 | return pdev_cap->band[NL80211_BAND_5GHZ].phy_id; |
11754 | ||
11755 | ath12k_warn(ar->ab, "unsupported phy cap:%d\n", band); | |
11756 | ||
11757 | return 0; | |
11758 | } | |
11759 | ||
11760 | static int ath12k_mac_setup_channels_rates(struct ath12k *ar, | |
d2b7a6e5 KP |
11761 | u32 supported_bands, |
11762 | struct ieee80211_supported_band *bands[]) | |
d8899132 KV |
11763 | { |
11764 | struct ieee80211_supported_band *band; | |
11765 | struct ath12k_wmi_hal_reg_capabilities_ext_arg *reg_cap; | |
657b0c72 AKS |
11766 | struct ath12k_base *ab = ar->ab; |
11767 | u32 phy_id, freq_low, freq_high; | |
0da00e45 | 11768 | struct ath12k_hw *ah = ar->ah; |
d8899132 | 11769 | void *channels; |
d8899132 KV |
11770 | |
11771 | BUILD_BUG_ON((ARRAY_SIZE(ath12k_2ghz_channels) + | |
11772 | ARRAY_SIZE(ath12k_5ghz_channels) + | |
11773 | ARRAY_SIZE(ath12k_6ghz_channels)) != | |
11774 | ATH12K_NUM_CHANS); | |
11775 | ||
657b0c72 | 11776 | reg_cap = &ab->hal_reg_cap[ar->pdev_idx]; |
d8899132 | 11777 | |
6a88093f | 11778 | if (supported_bands & WMI_HOST_WLAN_2GHZ_CAP) { |
d8899132 KV |
11779 | channels = kmemdup(ath12k_2ghz_channels, |
11780 | sizeof(ath12k_2ghz_channels), | |
11781 | GFP_KERNEL); | |
11782 | if (!channels) | |
11783 | return -ENOMEM; | |
11784 | ||
11785 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
11786 | band->band = NL80211_BAND_2GHZ; | |
11787 | band->n_channels = ARRAY_SIZE(ath12k_2ghz_channels); | |
11788 | band->channels = channels; | |
11789 | band->n_bitrates = ath12k_g_rates_size; | |
11790 | band->bitrates = ath12k_g_rates; | |
d2b7a6e5 | 11791 | bands[NL80211_BAND_2GHZ] = band; |
d8899132 | 11792 | |
657b0c72 | 11793 | if (ab->hw_params->single_pdev_only) { |
6a88093f | 11794 | phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_2GHZ_CAP); |
657b0c72 | 11795 | reg_cap = &ab->hal_reg_cap[phy_id]; |
d8899132 | 11796 | } |
657b0c72 AKS |
11797 | |
11798 | freq_low = max(reg_cap->low_2ghz_chan, | |
11799 | ab->reg_freq_2ghz.start_freq); | |
11800 | freq_high = min(reg_cap->high_2ghz_chan, | |
11801 | ab->reg_freq_2ghz.end_freq); | |
11802 | ||
d8899132 KV |
11803 | ath12k_mac_update_ch_list(ar, band, |
11804 | reg_cap->low_2ghz_chan, | |
11805 | reg_cap->high_2ghz_chan); | |
b7544de8 | 11806 | |
657b0c72 | 11807 | ath12k_mac_update_freq_range(ar, freq_low, freq_high); |
d8899132 KV |
11808 | } |
11809 | ||
6a88093f KP |
11810 | if (supported_bands & WMI_HOST_WLAN_5GHZ_CAP) { |
11811 | if (reg_cap->high_5ghz_chan >= ATH12K_MIN_6GHZ_FREQ) { | |
d8899132 KV |
11812 | channels = kmemdup(ath12k_6ghz_channels, |
11813 | sizeof(ath12k_6ghz_channels), GFP_KERNEL); | |
11814 | if (!channels) { | |
11815 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
11816 | return -ENOMEM; | |
11817 | } | |
11818 | ||
11819 | ar->supports_6ghz = true; | |
11820 | band = &ar->mac.sbands[NL80211_BAND_6GHZ]; | |
11821 | band->band = NL80211_BAND_6GHZ; | |
11822 | band->n_channels = ARRAY_SIZE(ath12k_6ghz_channels); | |
11823 | band->channels = channels; | |
11824 | band->n_bitrates = ath12k_a_rates_size; | |
11825 | band->bitrates = ath12k_a_rates; | |
d2b7a6e5 | 11826 | bands[NL80211_BAND_6GHZ] = band; |
657b0c72 AKS |
11827 | |
11828 | freq_low = max(reg_cap->low_5ghz_chan, | |
11829 | ab->reg_freq_6ghz.start_freq); | |
11830 | freq_high = min(reg_cap->high_5ghz_chan, | |
11831 | ab->reg_freq_6ghz.end_freq); | |
11832 | ||
d8899132 KV |
11833 | ath12k_mac_update_ch_list(ar, band, |
11834 | reg_cap->low_5ghz_chan, | |
11835 | reg_cap->high_5ghz_chan); | |
b7544de8 | 11836 | |
657b0c72 | 11837 | ath12k_mac_update_freq_range(ar, freq_low, freq_high); |
0da00e45 | 11838 | ah->use_6ghz_regd = true; |
d8899132 KV |
11839 | } |
11840 | ||
6a88093f | 11841 | if (reg_cap->low_5ghz_chan < ATH12K_MIN_6GHZ_FREQ) { |
d8899132 KV |
11842 | channels = kmemdup(ath12k_5ghz_channels, |
11843 | sizeof(ath12k_5ghz_channels), | |
11844 | GFP_KERNEL); | |
11845 | if (!channels) { | |
11846 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
11847 | kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); | |
11848 | return -ENOMEM; | |
11849 | } | |
11850 | ||
11851 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
11852 | band->band = NL80211_BAND_5GHZ; | |
11853 | band->n_channels = ARRAY_SIZE(ath12k_5ghz_channels); | |
11854 | band->channels = channels; | |
11855 | band->n_bitrates = ath12k_a_rates_size; | |
11856 | band->bitrates = ath12k_a_rates; | |
d2b7a6e5 | 11857 | bands[NL80211_BAND_5GHZ] = band; |
d8899132 | 11858 | |
657b0c72 | 11859 | if (ab->hw_params->single_pdev_only) { |
6a88093f | 11860 | phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_5GHZ_CAP); |
657b0c72 | 11861 | reg_cap = &ab->hal_reg_cap[phy_id]; |
d8899132 KV |
11862 | } |
11863 | ||
657b0c72 AKS |
11864 | freq_low = max(reg_cap->low_5ghz_chan, |
11865 | ab->reg_freq_5ghz.start_freq); | |
11866 | freq_high = min(reg_cap->high_5ghz_chan, | |
11867 | ab->reg_freq_5ghz.end_freq); | |
11868 | ||
d8899132 KV |
11869 | ath12k_mac_update_ch_list(ar, band, |
11870 | reg_cap->low_5ghz_chan, | |
11871 | reg_cap->high_5ghz_chan); | |
b7544de8 | 11872 | |
657b0c72 | 11873 | ath12k_mac_update_freq_range(ar, freq_low, freq_high); |
d8899132 KV |
11874 | } |
11875 | } | |
11876 | ||
11877 | return 0; | |
11878 | } | |
11879 | ||
6db6e70a | 11880 | static u16 ath12k_mac_get_ifmodes(struct ath12k_hw *ah) |
d8899132 | 11881 | { |
ba12f08f KP |
11882 | struct ath12k *ar; |
11883 | int i; | |
6db6e70a KP |
11884 | u16 interface_modes = U16_MAX; |
11885 | ||
ba12f08f KP |
11886 | for_each_ar(ah, ar, i) |
11887 | interface_modes &= ar->ab->hw_params->interface_modes; | |
6db6e70a KP |
11888 | |
11889 | return interface_modes == U16_MAX ? 0 : interface_modes; | |
11890 | } | |
11891 | ||
11892 | static bool ath12k_mac_is_iface_mode_enable(struct ath12k_hw *ah, | |
11893 | enum nl80211_iftype type) | |
11894 | { | |
ba12f08f KP |
11895 | struct ath12k *ar; |
11896 | int i; | |
ae6b0652 KP |
11897 | u16 interface_modes, mode = 0; |
11898 | bool is_enable = false; | |
11899 | ||
11900 | if (type == NL80211_IFTYPE_MESH_POINT) { | |
11901 | if (IS_ENABLED(CONFIG_MAC80211_MESH)) | |
11902 | mode = BIT(type); | |
11903 | } else { | |
11904 | mode = BIT(type); | |
11905 | } | |
6db6e70a | 11906 | |
ba12f08f KP |
11907 | for_each_ar(ah, ar, i) { |
11908 | interface_modes = ar->ab->hw_params->interface_modes; | |
ae6b0652 KP |
11909 | if (interface_modes & mode) { |
11910 | is_enable = true; | |
ba12f08f KP |
11911 | break; |
11912 | } | |
11913 | } | |
6db6e70a KP |
11914 | |
11915 | return is_enable; | |
11916 | } | |
11917 | ||
ae6b0652 KP |
11918 | static int |
11919 | ath12k_mac_setup_radio_iface_comb(struct ath12k *ar, | |
11920 | struct ieee80211_iface_combination *comb) | |
6db6e70a | 11921 | { |
ae6b0652 | 11922 | u16 interface_modes = ar->ab->hw_params->interface_modes; |
d8899132 KV |
11923 | struct ieee80211_iface_limit *limits; |
11924 | int n_limits, max_interfaces; | |
ef860c6a | 11925 | bool ap, mesh, p2p; |
d8899132 | 11926 | |
ae6b0652 KP |
11927 | ap = interface_modes & BIT(NL80211_IFTYPE_AP); |
11928 | p2p = interface_modes & BIT(NL80211_IFTYPE_P2P_DEVICE); | |
d8899132 KV |
11929 | |
11930 | mesh = IS_ENABLED(CONFIG_MAC80211_MESH) && | |
ae6b0652 | 11931 | (interface_modes & BIT(NL80211_IFTYPE_MESH_POINT)); |
d8899132 | 11932 | |
ef860c6a | 11933 | if ((ap || mesh) && !p2p) { |
d8899132 KV |
11934 | n_limits = 2; |
11935 | max_interfaces = 16; | |
ef860c6a KY |
11936 | } else if (p2p) { |
11937 | n_limits = 3; | |
11938 | if (ap || mesh) | |
11939 | max_interfaces = 16; | |
11940 | else | |
11941 | max_interfaces = 3; | |
d8899132 KV |
11942 | } else { |
11943 | n_limits = 1; | |
11944 | max_interfaces = 1; | |
11945 | } | |
11946 | ||
11947 | limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL); | |
ae6b0652 | 11948 | if (!limits) |
d8899132 | 11949 | return -ENOMEM; |
d8899132 KV |
11950 | |
11951 | limits[0].max = 1; | |
11952 | limits[0].types |= BIT(NL80211_IFTYPE_STATION); | |
11953 | ||
ef860c6a | 11954 | if (ap || mesh || p2p) |
d8899132 | 11955 | limits[1].max = max_interfaces; |
ef860c6a KY |
11956 | |
11957 | if (ap) | |
d8899132 | 11958 | limits[1].types |= BIT(NL80211_IFTYPE_AP); |
d8899132 KV |
11959 | |
11960 | if (mesh) | |
11961 | limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT); | |
11962 | ||
ef860c6a KY |
11963 | if (p2p) { |
11964 | limits[1].types |= BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
ae6b0652 | 11965 | BIT(NL80211_IFTYPE_P2P_GO); |
ef860c6a KY |
11966 | limits[2].max = 1; |
11967 | limits[2].types |= BIT(NL80211_IFTYPE_P2P_DEVICE); | |
11968 | } | |
11969 | ||
ae6b0652 KP |
11970 | comb[0].limits = limits; |
11971 | comb[0].n_limits = n_limits; | |
11972 | comb[0].max_interfaces = max_interfaces; | |
ae6b0652 KP |
11973 | comb[0].beacon_int_infra_match = true; |
11974 | comb[0].beacon_int_min_gcd = 100; | |
176f3009 BQ |
11975 | |
11976 | if (ar->ab->hw_params->single_pdev_only) { | |
11977 | comb[0].num_different_channels = 2; | |
11978 | } else { | |
11979 | comb[0].num_different_channels = 1; | |
11980 | comb[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
11981 | BIT(NL80211_CHAN_WIDTH_20) | | |
11982 | BIT(NL80211_CHAN_WIDTH_40) | | |
11983 | BIT(NL80211_CHAN_WIDTH_80); | |
11984 | } | |
ae6b0652 KP |
11985 | |
11986 | return 0; | |
11987 | } | |
11988 | ||
11989 | static int | |
11990 | ath12k_mac_setup_global_iface_comb(struct ath12k_hw *ah, | |
11991 | struct wiphy_radio *radio, | |
11992 | u8 n_radio, | |
11993 | struct ieee80211_iface_combination *comb) | |
11994 | { | |
11995 | const struct ieee80211_iface_combination *iter_comb; | |
11996 | struct ieee80211_iface_limit *limits; | |
11997 | int i, j, n_limits; | |
11998 | bool ap, mesh, p2p; | |
11999 | ||
12000 | if (!n_radio) | |
12001 | return 0; | |
12002 | ||
12003 | ap = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_AP); | |
12004 | p2p = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_P2P_DEVICE); | |
12005 | mesh = ath12k_mac_is_iface_mode_enable(ah, NL80211_IFTYPE_MESH_POINT); | |
12006 | ||
12007 | if ((ap || mesh) && !p2p) | |
12008 | n_limits = 2; | |
12009 | else if (p2p) | |
12010 | n_limits = 3; | |
12011 | else | |
12012 | n_limits = 1; | |
12013 | ||
12014 | limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL); | |
12015 | if (!limits) | |
12016 | return -ENOMEM; | |
12017 | ||
12018 | for (i = 0; i < n_radio; i++) { | |
12019 | iter_comb = radio[i].iface_combinations; | |
12020 | for (j = 0; j < iter_comb->n_limits && j < n_limits; j++) { | |
12021 | limits[j].types |= iter_comb->limits[j].types; | |
12022 | limits[j].max += iter_comb->limits[j].max; | |
12023 | } | |
12024 | ||
12025 | comb->max_interfaces += iter_comb->max_interfaces; | |
12026 | comb->num_different_channels += iter_comb->num_different_channels; | |
12027 | comb->radar_detect_widths |= iter_comb->radar_detect_widths; | |
12028 | } | |
12029 | ||
12030 | comb->limits = limits; | |
12031 | comb->n_limits = n_limits; | |
12032 | comb->beacon_int_infra_match = true; | |
12033 | comb->beacon_int_min_gcd = 100; | |
12034 | ||
12035 | return 0; | |
12036 | } | |
12037 | ||
12038 | static | |
12039 | void ath12k_mac_cleanup_iface_comb(const struct ieee80211_iface_combination *iface_comb) | |
12040 | { | |
12041 | kfree(iface_comb[0].limits); | |
12042 | kfree(iface_comb); | |
12043 | } | |
d8899132 | 12044 | |
ae6b0652 KP |
12045 | static void ath12k_mac_cleanup_iface_combinations(struct ath12k_hw *ah) |
12046 | { | |
12047 | struct wiphy *wiphy = ah->hw->wiphy; | |
12048 | const struct wiphy_radio *radio; | |
12049 | int i; | |
12050 | ||
12051 | if (wiphy->n_radio > 0) { | |
12052 | radio = wiphy->radio; | |
12053 | for (i = 0; i < wiphy->n_radio; i++) | |
12054 | ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations); | |
12055 | ||
12056 | kfree(wiphy->radio); | |
12057 | } | |
12058 | ||
12059 | ath12k_mac_cleanup_iface_comb(wiphy->iface_combinations); | |
12060 | } | |
12061 | ||
12062 | static int ath12k_mac_setup_iface_combinations(struct ath12k_hw *ah) | |
12063 | { | |
12064 | struct ieee80211_iface_combination *combinations, *comb; | |
12065 | struct wiphy *wiphy = ah->hw->wiphy; | |
12066 | struct wiphy_radio *radio; | |
12067 | struct ath12k *ar; | |
12068 | int i, ret; | |
12069 | ||
12070 | combinations = kzalloc(sizeof(*combinations), GFP_KERNEL); | |
12071 | if (!combinations) | |
12072 | return -ENOMEM; | |
12073 | ||
12074 | if (ah->num_radio == 1) { | |
12075 | ret = ath12k_mac_setup_radio_iface_comb(&ah->radio[0], | |
12076 | combinations); | |
12077 | if (ret) { | |
12078 | ath12k_hw_warn(ah, "failed to setup radio interface combinations for one radio: %d", | |
12079 | ret); | |
12080 | goto err_free_combinations; | |
12081 | } | |
12082 | ||
12083 | goto out; | |
12084 | } | |
12085 | ||
12086 | /* there are multiple radios */ | |
12087 | ||
12088 | radio = kcalloc(ah->num_radio, sizeof(*radio), GFP_KERNEL); | |
12089 | if (!radio) { | |
12090 | ret = -ENOMEM; | |
12091 | goto err_free_combinations; | |
12092 | } | |
12093 | ||
12094 | for_each_ar(ah, ar, i) { | |
12095 | comb = kzalloc(sizeof(*comb), GFP_KERNEL); | |
12096 | if (!comb) { | |
12097 | ret = -ENOMEM; | |
12098 | goto err_free_radios; | |
12099 | } | |
12100 | ||
12101 | ret = ath12k_mac_setup_radio_iface_comb(ar, comb); | |
12102 | if (ret) { | |
12103 | ath12k_hw_warn(ah, "failed to setup radio interface combinations for radio %d: %d", | |
12104 | i, ret); | |
12105 | kfree(comb); | |
12106 | goto err_free_radios; | |
12107 | } | |
12108 | ||
12109 | radio[i].freq_range = &ar->freq_range; | |
12110 | radio[i].n_freq_range = 1; | |
12111 | ||
12112 | radio[i].iface_combinations = comb; | |
12113 | radio[i].n_iface_combinations = 1; | |
12114 | } | |
12115 | ||
12116 | ret = ath12k_mac_setup_global_iface_comb(ah, radio, ah->num_radio, combinations); | |
12117 | if (ret) { | |
12118 | ath12k_hw_warn(ah, "failed to setup global interface combinations: %d", | |
12119 | ret); | |
12120 | goto err_free_all_radios; | |
12121 | } | |
12122 | ||
12123 | wiphy->radio = radio; | |
12124 | wiphy->n_radio = ah->num_radio; | |
12125 | ||
12126 | out: | |
c8a5f34a KP |
12127 | wiphy->iface_combinations = combinations; |
12128 | wiphy->n_iface_combinations = 1; | |
d8899132 KV |
12129 | |
12130 | return 0; | |
ae6b0652 KP |
12131 | |
12132 | err_free_all_radios: | |
12133 | i = ah->num_radio; | |
12134 | ||
12135 | err_free_radios: | |
12136 | while (i--) | |
12137 | ath12k_mac_cleanup_iface_comb(radio[i].iface_combinations); | |
12138 | ||
12139 | kfree(radio); | |
12140 | ||
12141 | err_free_combinations: | |
12142 | kfree(combinations); | |
12143 | ||
12144 | return ret; | |
d8899132 KV |
12145 | } |
12146 | ||
12147 | static const u8 ath12k_if_types_ext_capa[] = { | |
12148 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
519a545c | 12149 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
d8899132 KV |
12150 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
12151 | }; | |
12152 | ||
12153 | static const u8 ath12k_if_types_ext_capa_sta[] = { | |
12154 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
519a545c | 12155 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
d8899132 KV |
12156 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
12157 | [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, | |
12158 | }; | |
12159 | ||
12160 | static const u8 ath12k_if_types_ext_capa_ap[] = { | |
12161 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
519a545c | 12162 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, |
d8899132 KV |
12163 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, |
12164 | [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, | |
519a545c | 12165 | [10] = WLAN_EXT_CAPA11_EMA_SUPPORT, |
d8899132 KV |
12166 | }; |
12167 | ||
d33bc467 | 12168 | static struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = { |
d8899132 KV |
12169 | { |
12170 | .extended_capabilities = ath12k_if_types_ext_capa, | |
12171 | .extended_capabilities_mask = ath12k_if_types_ext_capa, | |
12172 | .extended_capabilities_len = sizeof(ath12k_if_types_ext_capa), | |
12173 | }, { | |
12174 | .iftype = NL80211_IFTYPE_STATION, | |
12175 | .extended_capabilities = ath12k_if_types_ext_capa_sta, | |
12176 | .extended_capabilities_mask = ath12k_if_types_ext_capa_sta, | |
12177 | .extended_capabilities_len = | |
12178 | sizeof(ath12k_if_types_ext_capa_sta), | |
12179 | }, { | |
12180 | .iftype = NL80211_IFTYPE_AP, | |
12181 | .extended_capabilities = ath12k_if_types_ext_capa_ap, | |
12182 | .extended_capabilities_mask = ath12k_if_types_ext_capa_ap, | |
12183 | .extended_capabilities_len = | |
12184 | sizeof(ath12k_if_types_ext_capa_ap), | |
d33bc467 RS |
12185 | .eml_capabilities = 0, |
12186 | .mld_capa_and_ops = 0, | |
d8899132 KV |
12187 | }, |
12188 | }; | |
12189 | ||
d786c9f5 KP |
12190 | static void ath12k_mac_cleanup_unregister(struct ath12k *ar) |
12191 | { | |
12192 | idr_for_each(&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar); | |
12193 | idr_destroy(&ar->txmgmt_idr); | |
12194 | ||
12195 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
12196 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
12197 | kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); | |
12198 | } | |
12199 | ||
6db6e70a | 12200 | static void ath12k_mac_hw_unregister(struct ath12k_hw *ah) |
d8899132 | 12201 | { |
6db6e70a | 12202 | struct ieee80211_hw *hw = ah->hw; |
ba12f08f KP |
12203 | struct ath12k *ar; |
12204 | int i; | |
940b57fd | 12205 | |
4e1eff38 | 12206 | for_each_ar(ah, ar, i) { |
ba12f08f | 12207 | cancel_work_sync(&ar->regd_update_work); |
4e1eff38 | 12208 | ath12k_debugfs_unregister(ar); |
246eb353 | 12209 | ath12k_fw_stats_reset(ar); |
4e1eff38 | 12210 | } |
d8899132 | 12211 | |
940b57fd | 12212 | ieee80211_unregister_hw(hw); |
d8899132 | 12213 | |
ba12f08f KP |
12214 | for_each_ar(ah, ar, i) |
12215 | ath12k_mac_cleanup_unregister(ar); | |
d8899132 | 12216 | |
8fea0066 | 12217 | ath12k_mac_cleanup_iface_combinations(ah); |
d8899132 | 12218 | |
940b57fd | 12219 | SET_IEEE80211_DEV(hw, NULL); |
d8899132 KV |
12220 | } |
12221 | ||
d786c9f5 KP |
12222 | static int ath12k_mac_setup_register(struct ath12k *ar, |
12223 | u32 *ht_cap, | |
12224 | struct ieee80211_supported_band *bands[]) | |
d8899132 | 12225 | { |
d786c9f5 KP |
12226 | struct ath12k_pdev_cap *cap = &ar->pdev->cap; |
12227 | int ret; | |
d8899132 | 12228 | |
d786c9f5 KP |
12229 | init_waitqueue_head(&ar->txmgmt_empty_waitq); |
12230 | idr_init(&ar->txmgmt_idr); | |
12231 | spin_lock_init(&ar->txmgmt_idr_lock); | |
d8899132 | 12232 | |
d786c9f5 KP |
12233 | ath12k_pdev_caps_update(ar); |
12234 | ||
12235 | ret = ath12k_mac_setup_channels_rates(ar, | |
12236 | cap->supported_bands, | |
12237 | bands); | |
12238 | if (ret) | |
12239 | return ret; | |
12240 | ||
12241 | ath12k_mac_setup_ht_vht_cap(ar, cap, ht_cap); | |
12242 | ath12k_mac_setup_sband_iftype_data(ar, cap); | |
12243 | ||
664a1c96 AS |
12244 | ar->max_num_stations = ath12k_core_get_max_station_per_radio(ar->ab); |
12245 | ar->max_num_peers = ath12k_core_get_max_peers_per_radio(ar->ab); | |
d786c9f5 KP |
12246 | |
12247 | return 0; | |
d8899132 KV |
12248 | } |
12249 | ||
6db6e70a | 12250 | static int ath12k_mac_hw_register(struct ath12k_hw *ah) |
d8899132 | 12251 | { |
6db6e70a | 12252 | struct ieee80211_hw *hw = ah->hw; |
c8a5f34a | 12253 | struct wiphy *wiphy = hw->wiphy; |
ba12f08f | 12254 | struct ath12k *ar = ath12k_ah_to_ar(ah, 0); |
6db6e70a KP |
12255 | struct ath12k_base *ab = ar->ab; |
12256 | struct ath12k_pdev *pdev; | |
12257 | struct ath12k_pdev_cap *cap; | |
d8899132 KV |
12258 | static const u32 cipher_suites[] = { |
12259 | WLAN_CIPHER_SUITE_TKIP, | |
12260 | WLAN_CIPHER_SUITE_CCMP, | |
12261 | WLAN_CIPHER_SUITE_AES_CMAC, | |
12262 | WLAN_CIPHER_SUITE_BIP_CMAC_256, | |
12263 | WLAN_CIPHER_SUITE_BIP_GMAC_128, | |
12264 | WLAN_CIPHER_SUITE_BIP_GMAC_256, | |
12265 | WLAN_CIPHER_SUITE_GCMP, | |
12266 | WLAN_CIPHER_SUITE_GCMP_256, | |
12267 | WLAN_CIPHER_SUITE_CCMP_256, | |
12268 | }; | |
ba12f08f KP |
12269 | int ret, i, j; |
12270 | u32 ht_cap = U32_MAX, antennas_rx = 0, antennas_tx = 0; | |
12271 | bool is_6ghz = false, is_raw_mode = false, is_monitor_disable = false; | |
12272 | u8 *mac_addr = NULL; | |
253ec89c | 12273 | u8 mbssid_max_interfaces = 0; |
d8899132 | 12274 | |
ba12f08f | 12275 | wiphy->max_ap_assoc_sta = 0; |
6db6e70a | 12276 | |
ba12f08f KP |
12277 | for_each_ar(ah, ar, i) { |
12278 | u32 ht_cap_info = 0; | |
d8899132 | 12279 | |
ba12f08f KP |
12280 | pdev = ar->pdev; |
12281 | if (ar->ab->pdevs_macaddr_valid) { | |
12282 | ether_addr_copy(ar->mac_addr, pdev->mac_addr); | |
12283 | } else { | |
12284 | ether_addr_copy(ar->mac_addr, ar->ab->mac_addr); | |
12285 | ar->mac_addr[4] += ar->pdev_idx; | |
12286 | } | |
d8899132 | 12287 | |
ba12f08f KP |
12288 | ret = ath12k_mac_setup_register(ar, &ht_cap_info, hw->wiphy->bands); |
12289 | if (ret) | |
12290 | goto err_cleanup_unregister; | |
12291 | ||
72c24b1b AKS |
12292 | /* 6 GHz does not support HT Cap, hence do not consider it */ |
12293 | if (!ar->supports_6ghz) | |
12294 | ht_cap &= ht_cap_info; | |
12295 | ||
ba12f08f KP |
12296 | wiphy->max_ap_assoc_sta += ar->max_num_stations; |
12297 | ||
12298 | /* Advertise the max antenna support of all radios, driver can handle | |
12299 | * per pdev specific antenna setting based on pdev cap when antenna | |
12300 | * changes are made | |
12301 | */ | |
12302 | cap = &pdev->cap; | |
12303 | ||
12304 | antennas_rx = max_t(u32, antennas_rx, cap->rx_chain_mask); | |
12305 | antennas_tx = max_t(u32, antennas_tx, cap->tx_chain_mask); | |
12306 | ||
12307 | if (ar->supports_6ghz) | |
12308 | is_6ghz = true; | |
12309 | ||
12310 | if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) | |
12311 | is_raw_mode = true; | |
12312 | ||
12313 | if (!ar->ab->hw_params->supports_monitor) | |
12314 | is_monitor_disable = true; | |
6db6e70a | 12315 | |
ba12f08f KP |
12316 | if (i == 0) |
12317 | mac_addr = ar->mac_addr; | |
12318 | else | |
12319 | mac_addr = ab->mac_addr; | |
253ec89c KP |
12320 | |
12321 | mbssid_max_interfaces += TARGET_NUM_VDEVS; | |
ba12f08f | 12322 | } |
6db6e70a | 12323 | |
ba12f08f KP |
12324 | wiphy->available_antennas_rx = antennas_rx; |
12325 | wiphy->available_antennas_tx = antennas_tx; | |
6db6e70a | 12326 | |
ba12f08f | 12327 | SET_IEEE80211_PERM_ADDR(hw, mac_addr); |
d786c9f5 | 12328 | SET_IEEE80211_DEV(hw, ab->dev); |
d8899132 | 12329 | |
6db6e70a | 12330 | ret = ath12k_mac_setup_iface_combinations(ah); |
d8899132 | 12331 | if (ret) { |
6db6e70a | 12332 | ath12k_err(ab, "failed to setup interface combinations: %d\n", ret); |
ba12f08f | 12333 | goto err_complete_cleanup_unregister; |
d8899132 KV |
12334 | } |
12335 | ||
6db6e70a | 12336 | wiphy->interface_modes = ath12k_mac_get_ifmodes(ah); |
d8899132 | 12337 | |
ba12f08f KP |
12338 | if (ah->num_radio == 1 && |
12339 | wiphy->bands[NL80211_BAND_2GHZ] && | |
c8a5f34a KP |
12340 | wiphy->bands[NL80211_BAND_5GHZ] && |
12341 | wiphy->bands[NL80211_BAND_6GHZ]) | |
940b57fd | 12342 | ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); |
a1e09eb3 | 12343 | |
940b57fd KP |
12344 | ieee80211_hw_set(hw, SIGNAL_DBM); |
12345 | ieee80211_hw_set(hw, SUPPORTS_PS); | |
12346 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); | |
12347 | ieee80211_hw_set(hw, MFP_CAPABLE); | |
12348 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); | |
12349 | ieee80211_hw_set(hw, HAS_RATE_CONTROL); | |
12350 | ieee80211_hw_set(hw, AP_LINK_PS); | |
12351 | ieee80211_hw_set(hw, SPECTRUM_MGMT); | |
12352 | ieee80211_hw_set(hw, CONNECTION_MONITOR); | |
12353 | ieee80211_hw_set(hw, SUPPORTS_PER_STA_GTK); | |
12354 | ieee80211_hw_set(hw, CHANCTX_STA_CSA); | |
12355 | ieee80211_hw_set(hw, QUEUE_CONTROL); | |
12356 | ieee80211_hw_set(hw, SUPPORTS_TX_FRAG); | |
12357 | ieee80211_hw_set(hw, REPORTS_LOW_ACK); | |
2c4c3aff | 12358 | ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); |
d8899132 | 12359 | |
72c24b1b | 12360 | if ((ht_cap & WMI_HT_CAP_ENABLED) || is_6ghz) { |
940b57fd KP |
12361 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
12362 | ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); | |
12363 | ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); | |
12364 | ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); | |
12365 | ieee80211_hw_set(hw, USES_RSS); | |
d8899132 KV |
12366 | } |
12367 | ||
c8a5f34a KP |
12368 | wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
12369 | wiphy->flags |= WIPHY_FLAG_IBSS_RSN; | |
d8899132 KV |
12370 | |
12371 | /* TODO: Check if HT capability advertised from firmware is different | |
12372 | * for each band for a dual band capable radio. It will be tricky to | |
12373 | * handle it when the ht capability different for each band. | |
12374 | */ | |
97b7cbb7 | 12375 | if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS || |
72c24b1b | 12376 | (is_6ghz && ab->hw_params->supports_dynamic_smps_6ghz)) |
c8a5f34a | 12377 | wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
d8899132 | 12378 | |
c8a5f34a KP |
12379 | wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
12380 | wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; | |
d8899132 | 12381 | |
940b57fd | 12382 | hw->max_listen_interval = ATH12K_MAX_HW_LISTEN_INTERVAL; |
d8899132 | 12383 | |
c8a5f34a KP |
12384 | wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
12385 | wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; | |
12386 | wiphy->max_remain_on_channel_duration = 5000; | |
d8899132 | 12387 | |
c8a5f34a KP |
12388 | wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
12389 | wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | | |
d8899132 KV |
12390 | NL80211_FEATURE_AP_SCAN; |
12391 | ||
03a50974 KV |
12392 | /* MLO is not yet supported so disable Wireless Extensions for now |
12393 | * to make sure ath12k users don't use it. This flag can be removed | |
12394 | * once WIPHY_FLAG_SUPPORTS_MLO is enabled. | |
12395 | */ | |
12396 | wiphy->flags |= WIPHY_FLAG_DISABLE_WEXT; | |
12397 | ||
d33bc467 RS |
12398 | /* Copy over MLO related capabilities received from |
12399 | * WMI_SERVICE_READY_EXT2_EVENT if single_chip_mlo_supp is set. | |
12400 | */ | |
12401 | if (ab->ag->mlo_capable) { | |
12402 | ath12k_iftypes_ext_capa[2].eml_capabilities = cap->eml_cap; | |
12403 | ath12k_iftypes_ext_capa[2].mld_capa_and_ops = cap->mld_cap; | |
12404 | wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; | |
2f50de72 BM |
12405 | |
12406 | ieee80211_hw_set(hw, MLO_MCAST_MULTI_LINK_TX); | |
d33bc467 RS |
12407 | } |
12408 | ||
940b57fd | 12409 | hw->queues = ATH12K_HW_MAX_QUEUES; |
c8a5f34a | 12410 | wiphy->tx_queue_len = ATH12K_QUEUE_LEN; |
940b57fd | 12411 | hw->offchannel_tx_hw_queue = ATH12K_HW_MAX_QUEUES - 1; |
b0970f50 | 12412 | hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT; |
d8899132 | 12413 | |
940b57fd KP |
12414 | hw->vif_data_size = sizeof(struct ath12k_vif); |
12415 | hw->sta_data_size = sizeof(struct ath12k_sta); | |
38055789 | 12416 | hw->extra_tx_headroom = ab->hw_params->iova_mask; |
d8899132 | 12417 | |
c8a5f34a KP |
12418 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); |
12419 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); | |
d8899132 | 12420 | |
c8a5f34a KP |
12421 | wiphy->cipher_suites = cipher_suites; |
12422 | wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
d8899132 | 12423 | |
c8a5f34a KP |
12424 | wiphy->iftype_ext_capab = ath12k_iftypes_ext_capa; |
12425 | wiphy->num_iftype_ext_capab = ARRAY_SIZE(ath12k_iftypes_ext_capa); | |
d8899132 | 12426 | |
253ec89c | 12427 | wiphy->mbssid_max_interfaces = mbssid_max_interfaces; |
519a545c AD |
12428 | wiphy->ema_max_profile_periodicity = TARGET_EMA_MAX_PROFILE_PERIOD; |
12429 | ||
ba12f08f | 12430 | if (is_6ghz) { |
c8a5f34a | 12431 | wiphy_ext_feature_set(wiphy, |
d8899132 | 12432 | NL80211_EXT_FEATURE_FILS_DISCOVERY); |
c8a5f34a | 12433 | wiphy_ext_feature_set(wiphy, |
d8899132 KV |
12434 | NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP); |
12435 | } | |
12436 | ||
c8a5f34a | 12437 | wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PUNCT); |
07c01b86 | 12438 | |
940b57fd | 12439 | ath12k_reg_init(hw); |
d8899132 | 12440 | |
ba12f08f | 12441 | if (!is_raw_mode) { |
940b57fd KP |
12442 | hw->netdev_features = NETIF_F_HW_CSUM; |
12443 | ieee80211_hw_set(hw, SW_CRYPTO_CONTROL); | |
12444 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); | |
d8899132 KV |
12445 | } |
12446 | ||
16f474d6 BQ |
12447 | if (test_bit(WMI_TLV_SERVICE_NLO, ar->wmi->wmi_ab->svc_map)) { |
12448 | wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS; | |
12449 | wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS; | |
12450 | wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH; | |
12451 | wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS; | |
12452 | wiphy->max_sched_scan_plan_interval = | |
12453 | WMI_PNO_MAX_SCHED_SCAN_PLAN_INT; | |
12454 | wiphy->max_sched_scan_plan_iterations = | |
12455 | WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS; | |
12456 | wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
12457 | } | |
12458 | ||
4a3c212e BQ |
12459 | ret = ath12k_wow_init(ar); |
12460 | if (ret) { | |
12461 | ath12k_warn(ar->ab, "failed to init wow: %d\n", ret); | |
8fea0066 | 12462 | goto err_cleanup_if_combs; |
4a3c212e BQ |
12463 | } |
12464 | ||
940b57fd | 12465 | ret = ieee80211_register_hw(hw); |
d8899132 | 12466 | if (ret) { |
6db6e70a | 12467 | ath12k_err(ab, "ieee80211 registration failed: %d\n", ret); |
8fea0066 | 12468 | goto err_cleanup_if_combs; |
d8899132 KV |
12469 | } |
12470 | ||
ba12f08f | 12471 | if (is_monitor_disable) |
d8899132 KV |
12472 | /* There's a race between calling ieee80211_register_hw() |
12473 | * and here where the monitor mode is enabled for a little | |
12474 | * while. But that time is so short and in practise it make | |
12475 | * a difference in real life. | |
12476 | */ | |
c8a5f34a | 12477 | wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR); |
d8899132 | 12478 | |
ba12f08f KP |
12479 | for_each_ar(ah, ar, i) { |
12480 | /* Apply the regd received during initialization */ | |
12481 | ret = ath12k_regd_update(ar, true); | |
12482 | if (ret) { | |
12483 | ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret); | |
12484 | goto err_unregister_hw; | |
12485 | } | |
d8899132 | 12486 | |
31d48b93 WG |
12487 | if (ar->ab->hw_params->current_cc_support && ab->new_alpha2[0]) { |
12488 | struct wmi_set_current_country_arg current_cc = {}; | |
12489 | ||
12490 | memcpy(¤t_cc.alpha2, ab->new_alpha2, 2); | |
12491 | memcpy(&ar->alpha2, ab->new_alpha2, 2); | |
12492 | ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); | |
12493 | if (ret) | |
12494 | ath12k_warn(ar->ab, | |
12495 | "failed set cc code for mac register: %d\n", | |
12496 | ret); | |
12497 | } | |
12498 | ||
e92c658b | 12499 | ath12k_fw_stats_init(ar); |
8dd65ccb AKS |
12500 | ath12k_debugfs_register(ar); |
12501 | } | |
f8bde02a | 12502 | |
d8899132 KV |
12503 | return 0; |
12504 | ||
12505 | err_unregister_hw: | |
4e1eff38 AKS |
12506 | for_each_ar(ah, ar, i) |
12507 | ath12k_debugfs_unregister(ar); | |
12508 | ||
940b57fd | 12509 | ieee80211_unregister_hw(hw); |
d8899132 | 12510 | |
8fea0066 KP |
12511 | err_cleanup_if_combs: |
12512 | ath12k_mac_cleanup_iface_combinations(ah); | |
d8899132 | 12513 | |
ba12f08f KP |
12514 | err_complete_cleanup_unregister: |
12515 | i = ah->num_radio; | |
12516 | ||
6db6e70a | 12517 | err_cleanup_unregister: |
ba12f08f KP |
12518 | for (j = 0; j < i; j++) { |
12519 | ar = ath12k_ah_to_ar(ah, j); | |
12520 | ath12k_mac_cleanup_unregister(ar); | |
12521 | } | |
d8899132 | 12522 | |
940b57fd | 12523 | SET_IEEE80211_DEV(hw, NULL); |
d8899132 KV |
12524 | |
12525 | return ret; | |
12526 | } | |
12527 | ||
8a742a79 KP |
12528 | static void ath12k_mac_setup(struct ath12k *ar) |
12529 | { | |
12530 | struct ath12k_base *ab = ar->ab; | |
12531 | struct ath12k_pdev *pdev = ar->pdev; | |
12532 | u8 pdev_idx = ar->pdev_idx; | |
12533 | ||
12534 | ar->lmac_id = ath12k_hw_get_mac_from_pdev_id(ab->hw_params, pdev_idx); | |
12535 | ||
12536 | ar->wmi = &ab->wmi_ab.wmi[pdev_idx]; | |
12537 | /* FIXME: wmi[0] is already initialized during attach, | |
12538 | * Should we do this again? | |
12539 | */ | |
12540 | ath12k_wmi_pdev_attach(ab, pdev_idx); | |
12541 | ||
12542 | ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask; | |
12543 | ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask; | |
12544 | ar->num_tx_chains = hweight32(pdev->cap.tx_chain_mask); | |
12545 | ar->num_rx_chains = hweight32(pdev->cap.rx_chain_mask); | |
3863f014 | 12546 | ar->scan.arvif = NULL; |
591de41d | 12547 | ar->vdev_id_11d_scan = ATH12K_11D_INVALID_VDEV_ID; |
8a742a79 KP |
12548 | |
12549 | spin_lock_init(&ar->data_lock); | |
12550 | INIT_LIST_HEAD(&ar->arvifs); | |
12551 | INIT_LIST_HEAD(&ar->ppdu_stats_info); | |
b8c67509 | 12552 | |
8a742a79 KP |
12553 | init_completion(&ar->vdev_setup_done); |
12554 | init_completion(&ar->vdev_delete_done); | |
12555 | init_completion(&ar->peer_assoc_done); | |
12556 | init_completion(&ar->peer_delete_done); | |
12557 | init_completion(&ar->install_key_done); | |
12558 | init_completion(&ar->bss_survey_done); | |
12559 | init_completion(&ar->scan.started); | |
12560 | init_completion(&ar->scan.completed); | |
2830bc9e | 12561 | init_completion(&ar->scan.on_channel); |
b716a10d | 12562 | init_completion(&ar->mlo_setup_done); |
591de41d | 12563 | init_completion(&ar->completed_11d_scan); |
8a742a79 KP |
12564 | |
12565 | INIT_DELAYED_WORK(&ar->scan.timeout, ath12k_scan_timeout_work); | |
3863f014 | 12566 | wiphy_work_init(&ar->scan.vdev_clean_wk, ath12k_scan_vdev_clean_work); |
8a742a79 KP |
12567 | INIT_WORK(&ar->regd_update_work, ath12k_regd_update_work); |
12568 | ||
56dcbf0b | 12569 | wiphy_work_init(&ar->wmi_mgmt_tx_work, ath12k_mgmt_over_wmi_tx_work); |
8a742a79 | 12570 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); |
2c4c3aff P |
12571 | |
12572 | ar->monitor_vdev_id = -1; | |
12573 | ar->monitor_vdev_created = false; | |
12574 | ar->monitor_started = false; | |
8a742a79 KP |
12575 | } |
12576 | ||
b716a10d KP |
12577 | static int __ath12k_mac_mlo_setup(struct ath12k *ar) |
12578 | { | |
12579 | u8 num_link = 0, partner_link_id[ATH12K_GROUP_MAX_RADIO] = {}; | |
12580 | struct ath12k_base *partner_ab, *ab = ar->ab; | |
12581 | struct ath12k_hw_group *ag = ab->ag; | |
12582 | struct wmi_mlo_setup_arg mlo = {}; | |
12583 | struct ath12k_pdev *pdev; | |
12584 | unsigned long time_left; | |
12585 | int i, j, ret; | |
12586 | ||
12587 | lockdep_assert_held(&ag->mutex); | |
12588 | ||
12589 | reinit_completion(&ar->mlo_setup_done); | |
12590 | ||
12591 | for (i = 0; i < ag->num_devices; i++) { | |
12592 | partner_ab = ag->ab[i]; | |
12593 | ||
12594 | for (j = 0; j < partner_ab->num_radios; j++) { | |
12595 | pdev = &partner_ab->pdevs[j]; | |
12596 | ||
12597 | /* Avoid the self link */ | |
12598 | if (ar == pdev->ar) | |
12599 | continue; | |
12600 | ||
12601 | partner_link_id[num_link] = pdev->hw_link_id; | |
12602 | num_link++; | |
12603 | ||
12604 | ath12k_dbg(ab, ATH12K_DBG_MAC, "device %d pdev %d hw_link_id %d num_link %d\n", | |
12605 | i, j, pdev->hw_link_id, num_link); | |
12606 | } | |
12607 | } | |
12608 | ||
5cec2d86 AS |
12609 | if (num_link == 0) |
12610 | return 0; | |
12611 | ||
b716a10d KP |
12612 | mlo.group_id = cpu_to_le32(ag->id); |
12613 | mlo.partner_link_id = partner_link_id; | |
12614 | mlo.num_partner_links = num_link; | |
12615 | ar->mlo_setup_status = 0; | |
12616 | ||
12617 | ath12k_dbg(ab, ATH12K_DBG_MAC, "group id %d num_link %d\n", ag->id, num_link); | |
12618 | ||
12619 | ret = ath12k_wmi_mlo_setup(ar, &mlo); | |
12620 | if (ret) { | |
12621 | ath12k_err(ab, "failed to send setup MLO WMI command for pdev %d: %d\n", | |
12622 | ar->pdev_idx, ret); | |
12623 | return ret; | |
12624 | } | |
12625 | ||
12626 | time_left = wait_for_completion_timeout(&ar->mlo_setup_done, | |
12627 | WMI_MLO_CMD_TIMEOUT_HZ); | |
12628 | ||
12629 | if (!time_left || ar->mlo_setup_status) | |
12630 | return ar->mlo_setup_status ? : -ETIMEDOUT; | |
12631 | ||
12632 | ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo setup done for pdev %d\n", ar->pdev_idx); | |
12633 | ||
12634 | return 0; | |
12635 | } | |
12636 | ||
12637 | static int __ath12k_mac_mlo_teardown(struct ath12k *ar) | |
12638 | { | |
12639 | struct ath12k_base *ab = ar->ab; | |
12640 | int ret; | |
5cec2d86 | 12641 | u8 num_link; |
b716a10d KP |
12642 | |
12643 | if (test_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags)) | |
12644 | return 0; | |
12645 | ||
5cec2d86 AS |
12646 | num_link = ath12k_get_num_partner_link(ar); |
12647 | ||
12648 | if (num_link == 0) | |
12649 | return 0; | |
12650 | ||
b716a10d KP |
12651 | ret = ath12k_wmi_mlo_teardown(ar); |
12652 | if (ret) { | |
12653 | ath12k_warn(ab, "failed to send MLO teardown WMI command for pdev %d: %d\n", | |
12654 | ar->pdev_idx, ret); | |
12655 | return ret; | |
12656 | } | |
12657 | ||
12658 | ath12k_dbg(ab, ATH12K_DBG_MAC, "mlo teardown for pdev %d\n", ar->pdev_idx); | |
12659 | ||
12660 | return 0; | |
12661 | } | |
12662 | ||
12663 | int ath12k_mac_mlo_setup(struct ath12k_hw_group *ag) | |
12664 | { | |
12665 | struct ath12k_hw *ah; | |
12666 | struct ath12k *ar; | |
12667 | int ret; | |
12668 | int i, j; | |
12669 | ||
12670 | for (i = 0; i < ag->num_hw; i++) { | |
12671 | ah = ag->ah[i]; | |
12672 | if (!ah) | |
12673 | continue; | |
12674 | ||
12675 | for_each_ar(ah, ar, j) { | |
12676 | ar = &ah->radio[j]; | |
12677 | ret = __ath12k_mac_mlo_setup(ar); | |
12678 | if (ret) { | |
12679 | ath12k_err(ar->ab, "failed to setup MLO: %d\n", ret); | |
12680 | goto err_setup; | |
12681 | } | |
12682 | } | |
12683 | } | |
12684 | ||
12685 | return 0; | |
12686 | ||
12687 | err_setup: | |
12688 | for (i = i - 1; i >= 0; i--) { | |
12689 | ah = ag->ah[i]; | |
12690 | if (!ah) | |
12691 | continue; | |
12692 | ||
12693 | for (j = j - 1; j >= 0; j--) { | |
12694 | ar = &ah->radio[j]; | |
12695 | if (!ar) | |
12696 | continue; | |
12697 | ||
12698 | __ath12k_mac_mlo_teardown(ar); | |
12699 | } | |
12700 | } | |
12701 | ||
12702 | return ret; | |
12703 | } | |
12704 | ||
12705 | void ath12k_mac_mlo_teardown(struct ath12k_hw_group *ag) | |
12706 | { | |
12707 | struct ath12k_hw *ah; | |
12708 | struct ath12k *ar; | |
12709 | int ret, i, j; | |
12710 | ||
12711 | for (i = 0; i < ag->num_hw; i++) { | |
12712 | ah = ag->ah[i]; | |
12713 | if (!ah) | |
12714 | continue; | |
12715 | ||
12716 | for_each_ar(ah, ar, j) { | |
12717 | ar = &ah->radio[j]; | |
12718 | ret = __ath12k_mac_mlo_teardown(ar); | |
12719 | if (ret) { | |
12720 | ath12k_err(ar->ab, "failed to teardown MLO: %d\n", ret); | |
12721 | break; | |
12722 | } | |
12723 | } | |
12724 | } | |
12725 | } | |
12726 | ||
a343d97f | 12727 | int ath12k_mac_register(struct ath12k_hw_group *ag) |
d786c9f5 | 12728 | { |
6db6e70a | 12729 | struct ath12k_hw *ah; |
d786c9f5 KP |
12730 | int i; |
12731 | int ret; | |
12732 | ||
54fcdcf0 | 12733 | for (i = 0; i < ag->num_hw; i++) { |
812a3027 | 12734 | ah = ath12k_ag_to_ah(ag, i); |
d786c9f5 | 12735 | |
6db6e70a | 12736 | ret = ath12k_mac_hw_register(ah); |
d786c9f5 | 12737 | if (ret) |
6db6e70a | 12738 | goto err; |
d786c9f5 KP |
12739 | } |
12740 | ||
12741 | return 0; | |
12742 | ||
6db6e70a | 12743 | err: |
d786c9f5 | 12744 | for (i = i - 1; i >= 0; i--) { |
812a3027 | 12745 | ah = ath12k_ag_to_ah(ag, i); |
6db6e70a KP |
12746 | if (!ah) |
12747 | continue; | |
12748 | ||
12749 | ath12k_mac_hw_unregister(ah); | |
d786c9f5 KP |
12750 | } |
12751 | ||
12752 | return ret; | |
12753 | } | |
12754 | ||
a343d97f | 12755 | void ath12k_mac_unregister(struct ath12k_hw_group *ag) |
d786c9f5 | 12756 | { |
6db6e70a | 12757 | struct ath12k_hw *ah; |
d786c9f5 KP |
12758 | int i; |
12759 | ||
54fcdcf0 | 12760 | for (i = ag->num_hw - 1; i >= 0; i--) { |
812a3027 | 12761 | ah = ath12k_ag_to_ah(ag, i); |
6db6e70a | 12762 | if (!ah) |
d786c9f5 KP |
12763 | continue; |
12764 | ||
6db6e70a | 12765 | ath12k_mac_hw_unregister(ah); |
d786c9f5 KP |
12766 | } |
12767 | } | |
12768 | ||
6db6e70a | 12769 | static void ath12k_mac_hw_destroy(struct ath12k_hw *ah) |
8a742a79 | 12770 | { |
6db6e70a | 12771 | ieee80211_free_hw(ah->hw); |
8a742a79 KP |
12772 | } |
12773 | ||
a343d97f | 12774 | static struct ath12k_hw *ath12k_mac_hw_allocate(struct ath12k_hw_group *ag, |
6db6e70a KP |
12775 | struct ath12k_pdev_map *pdev_map, |
12776 | u8 num_pdev_map) | |
d8899132 KV |
12777 | { |
12778 | struct ieee80211_hw *hw; | |
12779 | struct ath12k *ar; | |
a343d97f | 12780 | struct ath12k_base *ab; |
d8899132 | 12781 | struct ath12k_pdev *pdev; |
6db6e70a | 12782 | struct ath12k_hw *ah; |
d8899132 | 12783 | int i; |
6db6e70a | 12784 | u8 pdev_idx; |
d8899132 | 12785 | |
6db6e70a KP |
12786 | hw = ieee80211_alloc_hw(struct_size(ah, radio, num_pdev_map), |
12787 | &ath12k_ops); | |
12788 | if (!hw) | |
12789 | return NULL; | |
12790 | ||
12791 | ah = ath12k_hw_to_ah(hw); | |
12792 | ah->hw = hw; | |
12793 | ah->num_radio = num_pdev_map; | |
12794 | ||
acaa8400 | 12795 | mutex_init(&ah->hw_mutex); |
7fd8b4cb | 12796 | INIT_LIST_HEAD(&ah->ml_peers); |
acaa8400 | 12797 | |
6db6e70a KP |
12798 | for (i = 0; i < num_pdev_map; i++) { |
12799 | ab = pdev_map[i].ab; | |
12800 | pdev_idx = pdev_map[i].pdev_idx; | |
12801 | pdev = &ab->pdevs[pdev_idx]; | |
d8899132 | 12802 | |
ba12f08f | 12803 | ar = ath12k_ah_to_ar(ah, i); |
6db6e70a | 12804 | ar->ah = ah; |
d8899132 | 12805 | ar->ab = ab; |
22767241 | 12806 | ar->hw_link_id = pdev->hw_link_id; |
d8899132 | 12807 | ar->pdev = pdev; |
6db6e70a | 12808 | ar->pdev_idx = pdev_idx; |
d8899132 | 12809 | pdev->ar = ar; |
d8899132 | 12810 | |
1a73acb5 KP |
12811 | ag->hw_links[ar->hw_link_id].device_id = ab->device_id; |
12812 | ag->hw_links[ar->hw_link_id].pdev_idx = pdev_idx; | |
12813 | ||
8a742a79 | 12814 | ath12k_mac_setup(ar); |
a343d97f | 12815 | ath12k_dp_pdev_pre_alloc(ar); |
8a742a79 | 12816 | } |
eaf9f17b | 12817 | |
6db6e70a | 12818 | return ah; |
d8899132 KV |
12819 | } |
12820 | ||
a343d97f | 12821 | void ath12k_mac_destroy(struct ath12k_hw_group *ag) |
d8899132 | 12822 | { |
6db6e70a | 12823 | struct ath12k_pdev *pdev; |
a343d97f KP |
12824 | struct ath12k_base *ab = ag->ab[0]; |
12825 | int i, j; | |
016abac2 | 12826 | struct ath12k_hw *ah; |
6db6e70a | 12827 | |
a343d97f KP |
12828 | for (i = 0; i < ag->num_devices; i++) { |
12829 | ab = ag->ab[i]; | |
12830 | if (!ab) | |
6db6e70a KP |
12831 | continue; |
12832 | ||
a343d97f KP |
12833 | for (j = 0; j < ab->num_radios; j++) { |
12834 | pdev = &ab->pdevs[j]; | |
12835 | if (!pdev->ar) | |
12836 | continue; | |
12837 | pdev->ar = NULL; | |
12838 | } | |
6db6e70a KP |
12839 | } |
12840 | ||
54fcdcf0 | 12841 | for (i = 0; i < ag->num_hw; i++) { |
812a3027 | 12842 | ah = ath12k_ag_to_ah(ag, i); |
016abac2 | 12843 | if (!ah) |
6db6e70a KP |
12844 | continue; |
12845 | ||
016abac2 | 12846 | ath12k_mac_hw_destroy(ah); |
21261e4d | 12847 | ath12k_ag_set_ah(ag, i, NULL); |
6db6e70a | 12848 | } |
8a742a79 | 12849 | } |
d8899132 | 12850 | |
a343d97f KP |
12851 | static void ath12k_mac_set_device_defaults(struct ath12k_base *ab) |
12852 | { | |
12853 | /* Initialize channel counters frequency value in hertz */ | |
12854 | ab->cc_freq_hz = 320000; | |
12855 | ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1; | |
12856 | } | |
12857 | ||
12858 | int ath12k_mac_allocate(struct ath12k_hw_group *ag) | |
8a742a79 | 12859 | { |
a343d97f KP |
12860 | struct ath12k_pdev_map pdev_map[ATH12K_GROUP_MAX_RADIO]; |
12861 | int mac_id, device_id, total_radio, num_hw; | |
12862 | struct ath12k_base *ab; | |
6db6e70a | 12863 | struct ath12k_hw *ah; |
6db6e70a KP |
12864 | int ret, i, j; |
12865 | u8 radio_per_hw; | |
d8899132 | 12866 | |
a343d97f | 12867 | total_radio = 0; |
4aae8698 KP |
12868 | for (i = 0; i < ag->num_devices; i++) { |
12869 | ab = ag->ab[i]; | |
12870 | if (!ab) | |
12871 | continue; | |
12872 | ||
7971bda2 | 12873 | ath12k_debugfs_pdev_create(ab); |
4aae8698 KP |
12874 | ath12k_mac_set_device_defaults(ab); |
12875 | total_radio += ab->num_radios; | |
12876 | } | |
12877 | ||
12878 | if (!total_radio) | |
12879 | return -EINVAL; | |
12880 | ||
12881 | if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO)) | |
12882 | return -ENOSPC; | |
8a742a79 | 12883 | |
a343d97f KP |
12884 | /* All pdev get combined and register as single wiphy based on |
12885 | * hardware group which participate in multi-link operation else | |
12886 | * each pdev get register separately. | |
a343d97f | 12887 | */ |
da865679 KP |
12888 | if (ag->mlo_capable) |
12889 | radio_per_hw = total_radio; | |
12890 | else | |
12891 | radio_per_hw = 1; | |
12892 | ||
a343d97f | 12893 | num_hw = total_radio / radio_per_hw; |
6db6e70a | 12894 | |
a343d97f KP |
12895 | ag->num_hw = 0; |
12896 | device_id = 0; | |
12897 | mac_id = 0; | |
12898 | for (i = 0; i < num_hw; i++) { | |
6db6e70a | 12899 | for (j = 0; j < radio_per_hw; j++) { |
4aae8698 KP |
12900 | if (device_id >= ag->num_devices || !ag->ab[device_id]) { |
12901 | ret = -ENOSPC; | |
12902 | goto err; | |
12903 | } | |
12904 | ||
a343d97f | 12905 | ab = ag->ab[device_id]; |
6db6e70a | 12906 | pdev_map[j].ab = ab; |
a343d97f KP |
12907 | pdev_map[j].pdev_idx = mac_id; |
12908 | mac_id++; | |
12909 | ||
12910 | /* If mac_id falls beyond the current device MACs then | |
12911 | * move to next device | |
12912 | */ | |
12913 | if (mac_id >= ab->num_radios) { | |
12914 | mac_id = 0; | |
12915 | device_id++; | |
a343d97f | 12916 | } |
6db6e70a KP |
12917 | } |
12918 | ||
4aae8698 KP |
12919 | ab = pdev_map->ab; |
12920 | ||
a343d97f | 12921 | ah = ath12k_mac_hw_allocate(ag, pdev_map, radio_per_hw); |
6db6e70a KP |
12922 | if (!ah) { |
12923 | ath12k_warn(ab, "failed to allocate mac80211 hw device for hw_idx %d\n", | |
12924 | i); | |
04edb5dc | 12925 | ret = -ENOMEM; |
6db6e70a KP |
12926 | goto err; |
12927 | } | |
12928 | ||
a2189d2b KV |
12929 | ah->dev = ab->dev; |
12930 | ||
a343d97f KP |
12931 | ag->ah[i] = ah; |
12932 | ag->num_hw++; | |
6db6e70a | 12933 | } |
8a742a79 | 12934 | |
8a742a79 | 12935 | return 0; |
6db6e70a KP |
12936 | |
12937 | err: | |
12938 | for (i = i - 1; i >= 0; i--) { | |
812a3027 | 12939 | ah = ath12k_ag_to_ah(ag, i); |
016abac2 | 12940 | if (!ah) |
6db6e70a KP |
12941 | continue; |
12942 | ||
016abac2 | 12943 | ath12k_mac_hw_destroy(ah); |
21261e4d | 12944 | ath12k_ag_set_ah(ag, i, NULL); |
6db6e70a KP |
12945 | } |
12946 | ||
12947 | return ret; | |
d8899132 | 12948 | } |
7af01e56 | 12949 | |
3dd2c68f | 12950 | int ath12k_mac_vif_set_keepalive(struct ath12k_link_vif *arvif, |
7af01e56 BQ |
12951 | enum wmi_sta_keepalive_method method, |
12952 | u32 interval) | |
12953 | { | |
12954 | struct wmi_sta_keepalive_arg arg = {}; | |
12955 | struct ath12k *ar = arvif->ar; | |
12956 | int ret; | |
12957 | ||
b8c67509 | 12958 | lockdep_assert_wiphy(ath12k_ar_to_hw(ar)->wiphy); |
7af01e56 | 12959 | |
3dd2c68f | 12960 | if (arvif->ahvif->vdev_type != WMI_VDEV_TYPE_STA) |
7af01e56 BQ |
12961 | return 0; |
12962 | ||
12963 | if (!test_bit(WMI_TLV_SERVICE_STA_KEEP_ALIVE, ar->ab->wmi_ab.svc_map)) | |
12964 | return 0; | |
12965 | ||
12966 | arg.vdev_id = arvif->vdev_id; | |
12967 | arg.enabled = 1; | |
12968 | arg.method = method; | |
12969 | arg.interval = interval; | |
12970 | ||
12971 | ret = ath12k_wmi_sta_keepalive(ar, &arg); | |
12972 | if (ret) { | |
12973 | ath12k_warn(ar->ab, "failed to set keepalive on vdev %i: %d\n", | |
12974 | arvif->vdev_id, ret); | |
12975 | return ret; | |
12976 | } | |
12977 | ||
12978 | return 0; | |
12979 | } |