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. | |
4 | * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. | |
5 | */ | |
6 | ||
7 | #include <net/mac80211.h> | |
8 | #include <linux/etherdevice.h> | |
9 | #include "mac.h" | |
10 | #include "core.h" | |
11 | #include "debug.h" | |
12 | #include "wmi.h" | |
13 | #include "hw.h" | |
14 | #include "dp_tx.h" | |
15 | #include "dp_rx.h" | |
16 | #include "peer.h" | |
17 | ||
18 | #define CHAN2G(_channel, _freq, _flags) { \ | |
19 | .band = NL80211_BAND_2GHZ, \ | |
20 | .hw_value = (_channel), \ | |
21 | .center_freq = (_freq), \ | |
22 | .flags = (_flags), \ | |
23 | .max_antenna_gain = 0, \ | |
24 | .max_power = 30, \ | |
25 | } | |
26 | ||
27 | #define CHAN5G(_channel, _freq, _flags) { \ | |
28 | .band = NL80211_BAND_5GHZ, \ | |
29 | .hw_value = (_channel), \ | |
30 | .center_freq = (_freq), \ | |
31 | .flags = (_flags), \ | |
32 | .max_antenna_gain = 0, \ | |
33 | .max_power = 30, \ | |
34 | } | |
35 | ||
36 | #define CHAN6G(_channel, _freq, _flags) { \ | |
37 | .band = NL80211_BAND_6GHZ, \ | |
38 | .hw_value = (_channel), \ | |
39 | .center_freq = (_freq), \ | |
40 | .flags = (_flags), \ | |
41 | .max_antenna_gain = 0, \ | |
42 | .max_power = 30, \ | |
43 | } | |
44 | ||
45 | static const struct ieee80211_channel ath12k_2ghz_channels[] = { | |
46 | CHAN2G(1, 2412, 0), | |
47 | CHAN2G(2, 2417, 0), | |
48 | CHAN2G(3, 2422, 0), | |
49 | CHAN2G(4, 2427, 0), | |
50 | CHAN2G(5, 2432, 0), | |
51 | CHAN2G(6, 2437, 0), | |
52 | CHAN2G(7, 2442, 0), | |
53 | CHAN2G(8, 2447, 0), | |
54 | CHAN2G(9, 2452, 0), | |
55 | CHAN2G(10, 2457, 0), | |
56 | CHAN2G(11, 2462, 0), | |
57 | CHAN2G(12, 2467, 0), | |
58 | CHAN2G(13, 2472, 0), | |
59 | CHAN2G(14, 2484, 0), | |
60 | }; | |
61 | ||
62 | static const struct ieee80211_channel ath12k_5ghz_channels[] = { | |
63 | CHAN5G(36, 5180, 0), | |
64 | CHAN5G(40, 5200, 0), | |
65 | CHAN5G(44, 5220, 0), | |
66 | CHAN5G(48, 5240, 0), | |
67 | CHAN5G(52, 5260, 0), | |
68 | CHAN5G(56, 5280, 0), | |
69 | CHAN5G(60, 5300, 0), | |
70 | CHAN5G(64, 5320, 0), | |
71 | CHAN5G(100, 5500, 0), | |
72 | CHAN5G(104, 5520, 0), | |
73 | CHAN5G(108, 5540, 0), | |
74 | CHAN5G(112, 5560, 0), | |
75 | CHAN5G(116, 5580, 0), | |
76 | CHAN5G(120, 5600, 0), | |
77 | CHAN5G(124, 5620, 0), | |
78 | CHAN5G(128, 5640, 0), | |
79 | CHAN5G(132, 5660, 0), | |
80 | CHAN5G(136, 5680, 0), | |
81 | CHAN5G(140, 5700, 0), | |
82 | CHAN5G(144, 5720, 0), | |
83 | CHAN5G(149, 5745, 0), | |
84 | CHAN5G(153, 5765, 0), | |
85 | CHAN5G(157, 5785, 0), | |
86 | CHAN5G(161, 5805, 0), | |
87 | CHAN5G(165, 5825, 0), | |
88 | CHAN5G(169, 5845, 0), | |
89 | CHAN5G(173, 5865, 0), | |
90 | }; | |
91 | ||
92 | static const struct ieee80211_channel ath12k_6ghz_channels[] = { | |
93 | CHAN6G(1, 5955, 0), | |
94 | CHAN6G(5, 5975, 0), | |
95 | CHAN6G(9, 5995, 0), | |
96 | CHAN6G(13, 6015, 0), | |
97 | CHAN6G(17, 6035, 0), | |
98 | CHAN6G(21, 6055, 0), | |
99 | CHAN6G(25, 6075, 0), | |
100 | CHAN6G(29, 6095, 0), | |
101 | CHAN6G(33, 6115, 0), | |
102 | CHAN6G(37, 6135, 0), | |
103 | CHAN6G(41, 6155, 0), | |
104 | CHAN6G(45, 6175, 0), | |
105 | CHAN6G(49, 6195, 0), | |
106 | CHAN6G(53, 6215, 0), | |
107 | CHAN6G(57, 6235, 0), | |
108 | CHAN6G(61, 6255, 0), | |
109 | CHAN6G(65, 6275, 0), | |
110 | CHAN6G(69, 6295, 0), | |
111 | CHAN6G(73, 6315, 0), | |
112 | CHAN6G(77, 6335, 0), | |
113 | CHAN6G(81, 6355, 0), | |
114 | CHAN6G(85, 6375, 0), | |
115 | CHAN6G(89, 6395, 0), | |
116 | CHAN6G(93, 6415, 0), | |
117 | CHAN6G(97, 6435, 0), | |
118 | CHAN6G(101, 6455, 0), | |
119 | CHAN6G(105, 6475, 0), | |
120 | CHAN6G(109, 6495, 0), | |
121 | CHAN6G(113, 6515, 0), | |
122 | CHAN6G(117, 6535, 0), | |
123 | CHAN6G(121, 6555, 0), | |
124 | CHAN6G(125, 6575, 0), | |
125 | CHAN6G(129, 6595, 0), | |
126 | CHAN6G(133, 6615, 0), | |
127 | CHAN6G(137, 6635, 0), | |
128 | CHAN6G(141, 6655, 0), | |
129 | CHAN6G(145, 6675, 0), | |
130 | CHAN6G(149, 6695, 0), | |
131 | CHAN6G(153, 6715, 0), | |
132 | CHAN6G(157, 6735, 0), | |
133 | CHAN6G(161, 6755, 0), | |
134 | CHAN6G(165, 6775, 0), | |
135 | CHAN6G(169, 6795, 0), | |
136 | CHAN6G(173, 6815, 0), | |
137 | CHAN6G(177, 6835, 0), | |
138 | CHAN6G(181, 6855, 0), | |
139 | CHAN6G(185, 6875, 0), | |
140 | CHAN6G(189, 6895, 0), | |
141 | CHAN6G(193, 6915, 0), | |
142 | CHAN6G(197, 6935, 0), | |
143 | CHAN6G(201, 6955, 0), | |
144 | CHAN6G(205, 6975, 0), | |
145 | CHAN6G(209, 6995, 0), | |
146 | CHAN6G(213, 7015, 0), | |
147 | CHAN6G(217, 7035, 0), | |
148 | CHAN6G(221, 7055, 0), | |
149 | CHAN6G(225, 7075, 0), | |
150 | CHAN6G(229, 7095, 0), | |
151 | CHAN6G(233, 7115, 0), | |
152 | }; | |
153 | ||
154 | static struct ieee80211_rate ath12k_legacy_rates[] = { | |
155 | { .bitrate = 10, | |
156 | .hw_value = ATH12K_HW_RATE_CCK_LP_1M }, | |
157 | { .bitrate = 20, | |
158 | .hw_value = ATH12K_HW_RATE_CCK_LP_2M, | |
159 | .hw_value_short = ATH12K_HW_RATE_CCK_SP_2M, | |
160 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
161 | { .bitrate = 55, | |
162 | .hw_value = ATH12K_HW_RATE_CCK_LP_5_5M, | |
163 | .hw_value_short = ATH12K_HW_RATE_CCK_SP_5_5M, | |
164 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
165 | { .bitrate = 110, | |
166 | .hw_value = ATH12K_HW_RATE_CCK_LP_11M, | |
167 | .hw_value_short = ATH12K_HW_RATE_CCK_SP_11M, | |
168 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
169 | ||
170 | { .bitrate = 60, .hw_value = ATH12K_HW_RATE_OFDM_6M }, | |
171 | { .bitrate = 90, .hw_value = ATH12K_HW_RATE_OFDM_9M }, | |
172 | { .bitrate = 120, .hw_value = ATH12K_HW_RATE_OFDM_12M }, | |
173 | { .bitrate = 180, .hw_value = ATH12K_HW_RATE_OFDM_18M }, | |
174 | { .bitrate = 240, .hw_value = ATH12K_HW_RATE_OFDM_24M }, | |
175 | { .bitrate = 360, .hw_value = ATH12K_HW_RATE_OFDM_36M }, | |
176 | { .bitrate = 480, .hw_value = ATH12K_HW_RATE_OFDM_48M }, | |
177 | { .bitrate = 540, .hw_value = ATH12K_HW_RATE_OFDM_54M }, | |
178 | }; | |
179 | ||
180 | static const int | |
181 | ath12k_phymodes[NUM_NL80211_BANDS][ATH12K_CHAN_WIDTH_NUM] = { | |
182 | [NL80211_BAND_2GHZ] = { | |
183 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
184 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
185 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20_2G, | |
186 | [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20_2G, | |
187 | [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40_2G, | |
188 | [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80_2G, | |
189 | [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, | |
190 | [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN, | |
191 | }, | |
192 | [NL80211_BAND_5GHZ] = { | |
193 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
194 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
195 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20, | |
196 | [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20, | |
197 | [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40, | |
198 | [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80, | |
199 | [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160, | |
200 | [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80, | |
201 | }, | |
202 | [NL80211_BAND_6GHZ] = { | |
203 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
204 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
205 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20, | |
206 | [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20, | |
207 | [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40, | |
208 | [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80, | |
209 | [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160, | |
210 | [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80, | |
211 | }, | |
212 | ||
213 | }; | |
214 | ||
215 | const struct htt_rx_ring_tlv_filter ath12k_mac_mon_status_filter_default = { | |
216 | .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START | | |
217 | HTT_RX_FILTER_TLV_FLAGS_PPDU_END | | |
218 | HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE, | |
219 | .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0, | |
220 | .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1, | |
221 | .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2, | |
222 | .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 | | |
223 | HTT_RX_FP_CTRL_FILTER_FLASG3 | |
224 | }; | |
225 | ||
226 | #define ATH12K_MAC_FIRST_OFDM_RATE_IDX 4 | |
227 | #define ath12k_g_rates ath12k_legacy_rates | |
228 | #define ath12k_g_rates_size (ARRAY_SIZE(ath12k_legacy_rates)) | |
229 | #define ath12k_a_rates (ath12k_legacy_rates + 4) | |
230 | #define ath12k_a_rates_size (ARRAY_SIZE(ath12k_legacy_rates) - 4) | |
231 | ||
232 | #define ATH12K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */ | |
233 | ||
234 | static const u32 ath12k_smps_map[] = { | |
235 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, | |
236 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, | |
237 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, | |
238 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, | |
239 | }; | |
240 | ||
241 | static int ath12k_start_vdev_delay(struct ieee80211_hw *hw, | |
242 | struct ieee80211_vif *vif); | |
243 | ||
244 | static const char *ath12k_mac_phymode_str(enum wmi_phy_mode mode) | |
245 | { | |
246 | switch (mode) { | |
247 | case MODE_11A: | |
248 | return "11a"; | |
249 | case MODE_11G: | |
250 | return "11g"; | |
251 | case MODE_11B: | |
252 | return "11b"; | |
253 | case MODE_11GONLY: | |
254 | return "11gonly"; | |
255 | case MODE_11NA_HT20: | |
256 | return "11na-ht20"; | |
257 | case MODE_11NG_HT20: | |
258 | return "11ng-ht20"; | |
259 | case MODE_11NA_HT40: | |
260 | return "11na-ht40"; | |
261 | case MODE_11NG_HT40: | |
262 | return "11ng-ht40"; | |
263 | case MODE_11AC_VHT20: | |
264 | return "11ac-vht20"; | |
265 | case MODE_11AC_VHT40: | |
266 | return "11ac-vht40"; | |
267 | case MODE_11AC_VHT80: | |
268 | return "11ac-vht80"; | |
269 | case MODE_11AC_VHT160: | |
270 | return "11ac-vht160"; | |
271 | case MODE_11AC_VHT80_80: | |
272 | return "11ac-vht80+80"; | |
273 | case MODE_11AC_VHT20_2G: | |
274 | return "11ac-vht20-2g"; | |
275 | case MODE_11AC_VHT40_2G: | |
276 | return "11ac-vht40-2g"; | |
277 | case MODE_11AC_VHT80_2G: | |
278 | return "11ac-vht80-2g"; | |
279 | case MODE_11AX_HE20: | |
280 | return "11ax-he20"; | |
281 | case MODE_11AX_HE40: | |
282 | return "11ax-he40"; | |
283 | case MODE_11AX_HE80: | |
284 | return "11ax-he80"; | |
285 | case MODE_11AX_HE80_80: | |
286 | return "11ax-he80+80"; | |
287 | case MODE_11AX_HE160: | |
288 | return "11ax-he160"; | |
289 | case MODE_11AX_HE20_2G: | |
290 | return "11ax-he20-2g"; | |
291 | case MODE_11AX_HE40_2G: | |
292 | return "11ax-he40-2g"; | |
293 | case MODE_11AX_HE80_2G: | |
294 | return "11ax-he80-2g"; | |
295 | case MODE_UNKNOWN: | |
296 | /* skip */ | |
297 | break; | |
298 | ||
299 | /* no default handler to allow compiler to check that the | |
300 | * enum is fully handled | |
301 | */ | |
302 | } | |
303 | ||
304 | return "<unknown>"; | |
305 | } | |
306 | ||
307 | enum rate_info_bw | |
308 | ath12k_mac_bw_to_mac80211_bw(enum ath12k_supported_bw bw) | |
309 | { | |
310 | u8 ret = RATE_INFO_BW_20; | |
311 | ||
312 | switch (bw) { | |
313 | case ATH12K_BW_20: | |
314 | ret = RATE_INFO_BW_20; | |
315 | break; | |
316 | case ATH12K_BW_40: | |
317 | ret = RATE_INFO_BW_40; | |
318 | break; | |
319 | case ATH12K_BW_80: | |
320 | ret = RATE_INFO_BW_80; | |
321 | break; | |
322 | case ATH12K_BW_160: | |
323 | ret = RATE_INFO_BW_160; | |
324 | break; | |
325 | } | |
326 | ||
327 | return ret; | |
328 | } | |
329 | ||
330 | enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw(enum rate_info_bw bw) | |
331 | { | |
332 | switch (bw) { | |
333 | case RATE_INFO_BW_20: | |
334 | return ATH12K_BW_20; | |
335 | case RATE_INFO_BW_40: | |
336 | return ATH12K_BW_40; | |
337 | case RATE_INFO_BW_80: | |
338 | return ATH12K_BW_80; | |
339 | case RATE_INFO_BW_160: | |
340 | return ATH12K_BW_160; | |
341 | default: | |
342 | return ATH12K_BW_20; | |
343 | } | |
344 | } | |
345 | ||
346 | int ath12k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx, | |
347 | u16 *rate) | |
348 | { | |
349 | /* As default, it is OFDM rates */ | |
350 | int i = ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
351 | int max_rates_idx = ath12k_g_rates_size; | |
352 | ||
353 | if (preamble == WMI_RATE_PREAMBLE_CCK) { | |
354 | hw_rc &= ~ATH12K_HW_RATECODE_CCK_SHORT_PREAM_MASK; | |
355 | i = 0; | |
356 | max_rates_idx = ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
357 | } | |
358 | ||
359 | while (i < max_rates_idx) { | |
360 | if (hw_rc == ath12k_legacy_rates[i].hw_value) { | |
361 | *rateidx = i; | |
362 | *rate = ath12k_legacy_rates[i].bitrate; | |
363 | return 0; | |
364 | } | |
365 | i++; | |
366 | } | |
367 | ||
368 | return -EINVAL; | |
369 | } | |
370 | ||
371 | u8 ath12k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, | |
372 | u32 bitrate) | |
373 | { | |
374 | int i; | |
375 | ||
376 | for (i = 0; i < sband->n_bitrates; i++) | |
377 | if (sband->bitrates[i].bitrate == bitrate) | |
378 | return i; | |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | static u32 | |
384 | ath12k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | |
385 | { | |
386 | int nss; | |
387 | ||
388 | for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) | |
389 | if (ht_mcs_mask[nss]) | |
390 | return nss + 1; | |
391 | ||
392 | return 1; | |
393 | } | |
394 | ||
395 | static u32 | |
396 | ath12k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
397 | { | |
398 | int nss; | |
399 | ||
400 | for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) | |
401 | if (vht_mcs_mask[nss]) | |
402 | return nss + 1; | |
403 | ||
404 | return 1; | |
405 | } | |
406 | ||
407 | static u8 ath12k_parse_mpdudensity(u8 mpdudensity) | |
408 | { | |
409 | /* From IEEE Std 802.11-2020 defined values for "Minimum MPDU Start Spacing": | |
410 | * 0 for no restriction | |
411 | * 1 for 1/4 us | |
412 | * 2 for 1/2 us | |
413 | * 3 for 1 us | |
414 | * 4 for 2 us | |
415 | * 5 for 4 us | |
416 | * 6 for 8 us | |
417 | * 7 for 16 us | |
418 | */ | |
419 | switch (mpdudensity) { | |
420 | case 0: | |
421 | return 0; | |
422 | case 1: | |
423 | case 2: | |
424 | case 3: | |
425 | /* Our lower layer calculations limit our precision to | |
426 | * 1 microsecond | |
427 | */ | |
428 | return 1; | |
429 | case 4: | |
430 | return 2; | |
431 | case 5: | |
432 | return 4; | |
433 | case 6: | |
434 | return 8; | |
435 | case 7: | |
436 | return 16; | |
437 | default: | |
438 | return 0; | |
439 | } | |
440 | } | |
441 | ||
442 | static int ath12k_mac_vif_chan(struct ieee80211_vif *vif, | |
443 | struct cfg80211_chan_def *def) | |
444 | { | |
445 | struct ieee80211_chanctx_conf *conf; | |
446 | ||
447 | rcu_read_lock(); | |
448 | conf = rcu_dereference(vif->bss_conf.chanctx_conf); | |
449 | if (!conf) { | |
450 | rcu_read_unlock(); | |
451 | return -ENOENT; | |
452 | } | |
453 | ||
454 | *def = conf->def; | |
455 | rcu_read_unlock(); | |
456 | ||
457 | return 0; | |
458 | } | |
459 | ||
460 | static bool ath12k_mac_bitrate_is_cck(int bitrate) | |
461 | { | |
462 | switch (bitrate) { | |
463 | case 10: | |
464 | case 20: | |
465 | case 55: | |
466 | case 110: | |
467 | return true; | |
468 | } | |
469 | ||
470 | return false; | |
471 | } | |
472 | ||
473 | u8 ath12k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, | |
474 | u8 hw_rate, bool cck) | |
475 | { | |
476 | const struct ieee80211_rate *rate; | |
477 | int i; | |
478 | ||
479 | for (i = 0; i < sband->n_bitrates; i++) { | |
480 | rate = &sband->bitrates[i]; | |
481 | ||
482 | if (ath12k_mac_bitrate_is_cck(rate->bitrate) != cck) | |
483 | continue; | |
484 | ||
485 | if (rate->hw_value == hw_rate) | |
486 | return i; | |
487 | else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && | |
488 | rate->hw_value_short == hw_rate) | |
489 | return i; | |
490 | } | |
491 | ||
492 | return 0; | |
493 | } | |
494 | ||
495 | static u8 ath12k_mac_bitrate_to_rate(int bitrate) | |
496 | { | |
497 | return DIV_ROUND_UP(bitrate, 5) | | |
498 | (ath12k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); | |
499 | } | |
500 | ||
501 | static void ath12k_get_arvif_iter(void *data, u8 *mac, | |
502 | struct ieee80211_vif *vif) | |
503 | { | |
504 | struct ath12k_vif_iter *arvif_iter = data; | |
505 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
506 | ||
507 | if (arvif->vdev_id == arvif_iter->vdev_id) | |
508 | arvif_iter->arvif = arvif; | |
509 | } | |
510 | ||
511 | struct ath12k_vif *ath12k_mac_get_arvif(struct ath12k *ar, u32 vdev_id) | |
512 | { | |
513 | struct ath12k_vif_iter arvif_iter = {}; | |
514 | u32 flags; | |
515 | ||
516 | arvif_iter.vdev_id = vdev_id; | |
517 | ||
518 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; | |
519 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
520 | flags, | |
521 | ath12k_get_arvif_iter, | |
522 | &arvif_iter); | |
523 | if (!arvif_iter.arvif) { | |
524 | ath12k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id); | |
525 | return NULL; | |
526 | } | |
527 | ||
528 | return arvif_iter.arvif; | |
529 | } | |
530 | ||
531 | struct ath12k_vif *ath12k_mac_get_arvif_by_vdev_id(struct ath12k_base *ab, | |
532 | u32 vdev_id) | |
533 | { | |
534 | int i; | |
535 | struct ath12k_pdev *pdev; | |
536 | struct ath12k_vif *arvif; | |
537 | ||
538 | for (i = 0; i < ab->num_radios; i++) { | |
539 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
540 | if (pdev && pdev->ar) { | |
541 | arvif = ath12k_mac_get_arvif(pdev->ar, vdev_id); | |
542 | if (arvif) | |
543 | return arvif; | |
544 | } | |
545 | } | |
546 | ||
547 | return NULL; | |
548 | } | |
549 | ||
550 | struct ath12k *ath12k_mac_get_ar_by_vdev_id(struct ath12k_base *ab, u32 vdev_id) | |
551 | { | |
552 | int i; | |
553 | struct ath12k_pdev *pdev; | |
554 | ||
555 | for (i = 0; i < ab->num_radios; i++) { | |
556 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
557 | if (pdev && pdev->ar) { | |
558 | if (pdev->ar->allocated_vdev_map & (1LL << vdev_id)) | |
559 | return pdev->ar; | |
560 | } | |
561 | } | |
562 | ||
563 | return NULL; | |
564 | } | |
565 | ||
566 | struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id) | |
567 | { | |
568 | int i; | |
569 | struct ath12k_pdev *pdev; | |
570 | ||
571 | if (ab->hw_params->single_pdev_only) { | |
572 | pdev = rcu_dereference(ab->pdevs_active[0]); | |
573 | return pdev ? pdev->ar : NULL; | |
574 | } | |
575 | ||
576 | if (WARN_ON(pdev_id > ab->num_radios)) | |
577 | return NULL; | |
578 | ||
579 | for (i = 0; i < ab->num_radios; i++) { | |
580 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
581 | ||
582 | if (pdev && pdev->pdev_id == pdev_id) | |
583 | return (pdev->ar ? pdev->ar : NULL); | |
584 | } | |
585 | ||
586 | return NULL; | |
587 | } | |
588 | ||
589 | static void ath12k_pdev_caps_update(struct ath12k *ar) | |
590 | { | |
591 | struct ath12k_base *ab = ar->ab; | |
592 | ||
593 | ar->max_tx_power = ab->target_caps.hw_max_tx_power; | |
594 | ||
595 | /* FIXME: Set min_tx_power to ab->target_caps.hw_min_tx_power. | |
596 | * But since the received value in svcrdy is same as hw_max_tx_power, | |
597 | * we can set ar->min_tx_power to 0 currently until | |
598 | * this is fixed in firmware | |
599 | */ | |
600 | ar->min_tx_power = 0; | |
601 | ||
602 | ar->txpower_limit_2g = ar->max_tx_power; | |
603 | ar->txpower_limit_5g = ar->max_tx_power; | |
604 | ar->txpower_scale = WMI_HOST_TP_SCALE_MAX; | |
605 | } | |
606 | ||
607 | static int ath12k_mac_txpower_recalc(struct ath12k *ar) | |
608 | { | |
609 | struct ath12k_pdev *pdev = ar->pdev; | |
610 | struct ath12k_vif *arvif; | |
611 | int ret, txpower = -1; | |
612 | u32 param; | |
613 | ||
614 | lockdep_assert_held(&ar->conf_mutex); | |
615 | ||
616 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
617 | if (arvif->txpower <= 0) | |
618 | continue; | |
619 | ||
620 | if (txpower == -1) | |
621 | txpower = arvif->txpower; | |
622 | else | |
623 | txpower = min(txpower, arvif->txpower); | |
624 | } | |
625 | ||
626 | if (txpower == -1) | |
627 | return 0; | |
628 | ||
629 | /* txpwr is set as 2 units per dBm in FW*/ | |
630 | txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower), | |
631 | ar->max_tx_power) * 2; | |
632 | ||
633 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "txpower to set in hw %d\n", | |
634 | txpower / 2); | |
635 | ||
636 | if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) && | |
637 | ar->txpower_limit_2g != txpower) { | |
638 | param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G; | |
639 | ret = ath12k_wmi_pdev_set_param(ar, param, | |
640 | txpower, ar->pdev->pdev_id); | |
641 | if (ret) | |
642 | goto fail; | |
643 | ar->txpower_limit_2g = txpower; | |
644 | } | |
645 | ||
646 | if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) && | |
647 | ar->txpower_limit_5g != txpower) { | |
648 | param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G; | |
649 | ret = ath12k_wmi_pdev_set_param(ar, param, | |
650 | txpower, ar->pdev->pdev_id); | |
651 | if (ret) | |
652 | goto fail; | |
653 | ar->txpower_limit_5g = txpower; | |
654 | } | |
655 | ||
656 | return 0; | |
657 | ||
658 | fail: | |
659 | ath12k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n", | |
660 | txpower / 2, param, ret); | |
661 | return ret; | |
662 | } | |
663 | ||
664 | static int ath12k_recalc_rtscts_prot(struct ath12k_vif *arvif) | |
665 | { | |
666 | struct ath12k *ar = arvif->ar; | |
667 | u32 vdev_param, rts_cts; | |
668 | int ret; | |
669 | ||
670 | lockdep_assert_held(&ar->conf_mutex); | |
671 | ||
672 | vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS; | |
673 | ||
674 | /* Enable RTS/CTS protection for sw retries (when legacy stations | |
675 | * are in BSS) or by default only for second rate series. | |
676 | * TODO: Check if we need to enable CTS 2 Self in any case | |
677 | */ | |
678 | rts_cts = WMI_USE_RTS_CTS; | |
679 | ||
680 | if (arvif->num_legacy_stations > 0) | |
681 | rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4; | |
682 | else | |
683 | rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4; | |
684 | ||
685 | /* Need not send duplicate param value to firmware */ | |
686 | if (arvif->rtscts_prot_mode == rts_cts) | |
687 | return 0; | |
688 | ||
689 | arvif->rtscts_prot_mode = rts_cts; | |
690 | ||
691 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", | |
692 | arvif->vdev_id, rts_cts); | |
693 | ||
694 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
695 | vdev_param, rts_cts); | |
696 | if (ret) | |
697 | ath12k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n", | |
698 | arvif->vdev_id, ret); | |
699 | ||
700 | return ret; | |
701 | } | |
702 | ||
703 | static int ath12k_mac_set_kickout(struct ath12k_vif *arvif) | |
704 | { | |
705 | struct ath12k *ar = arvif->ar; | |
706 | u32 param; | |
707 | int ret; | |
708 | ||
709 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH, | |
710 | ATH12K_KICKOUT_THRESHOLD, | |
711 | ar->pdev->pdev_id); | |
712 | if (ret) { | |
713 | ath12k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n", | |
714 | arvif->vdev_id, ret); | |
715 | return ret; | |
716 | } | |
717 | ||
718 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS; | |
719 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
720 | ATH12K_KEEPALIVE_MIN_IDLE); | |
721 | if (ret) { | |
722 | ath12k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n", | |
723 | arvif->vdev_id, ret); | |
724 | return ret; | |
725 | } | |
726 | ||
727 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS; | |
728 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
729 | ATH12K_KEEPALIVE_MAX_IDLE); | |
730 | if (ret) { | |
731 | ath12k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n", | |
732 | arvif->vdev_id, ret); | |
733 | return ret; | |
734 | } | |
735 | ||
736 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS; | |
737 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
738 | ATH12K_KEEPALIVE_MAX_UNRESPONSIVE); | |
739 | if (ret) { | |
740 | ath12k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", | |
741 | arvif->vdev_id, ret); | |
742 | return ret; | |
743 | } | |
744 | ||
745 | return 0; | |
746 | } | |
747 | ||
748 | void ath12k_mac_peer_cleanup_all(struct ath12k *ar) | |
749 | { | |
750 | struct ath12k_peer *peer, *tmp; | |
751 | struct ath12k_base *ab = ar->ab; | |
752 | ||
753 | lockdep_assert_held(&ar->conf_mutex); | |
754 | ||
755 | spin_lock_bh(&ab->base_lock); | |
756 | list_for_each_entry_safe(peer, tmp, &ab->peers, list) { | |
757 | ath12k_dp_rx_peer_tid_cleanup(ar, peer); | |
758 | list_del(&peer->list); | |
759 | kfree(peer); | |
760 | } | |
761 | spin_unlock_bh(&ab->base_lock); | |
762 | ||
763 | ar->num_peers = 0; | |
764 | ar->num_stations = 0; | |
765 | } | |
766 | ||
767 | static int ath12k_mac_vdev_setup_sync(struct ath12k *ar) | |
768 | { | |
769 | lockdep_assert_held(&ar->conf_mutex); | |
770 | ||
771 | if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
772 | return -ESHUTDOWN; | |
773 | ||
774 | if (!wait_for_completion_timeout(&ar->vdev_setup_done, | |
775 | ATH12K_VDEV_SETUP_TIMEOUT_HZ)) | |
776 | return -ETIMEDOUT; | |
777 | ||
778 | return ar->last_wmi_vdev_start_status ? -EINVAL : 0; | |
779 | } | |
780 | ||
781 | static int ath12k_monitor_vdev_up(struct ath12k *ar, int vdev_id) | |
782 | { | |
783 | int ret; | |
784 | ||
785 | ret = ath12k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); | |
786 | if (ret) { | |
787 | ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", | |
788 | vdev_id, ret); | |
789 | return ret; | |
790 | } | |
791 | ||
792 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", | |
793 | vdev_id); | |
794 | return 0; | |
795 | } | |
796 | ||
797 | static int ath12k_mac_monitor_vdev_start(struct ath12k *ar, int vdev_id, | |
798 | struct cfg80211_chan_def *chandef) | |
799 | { | |
800 | struct ieee80211_channel *channel; | |
801 | struct wmi_vdev_start_req_arg arg = {}; | |
802 | int ret; | |
803 | ||
804 | lockdep_assert_held(&ar->conf_mutex); | |
805 | ||
806 | channel = chandef->chan; | |
807 | arg.vdev_id = vdev_id; | |
808 | arg.freq = channel->center_freq; | |
809 | arg.band_center_freq1 = chandef->center_freq1; | |
810 | arg.band_center_freq2 = chandef->center_freq2; | |
811 | arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; | |
812 | arg.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR); | |
813 | ||
814 | arg.min_power = 0; | |
815 | arg.max_power = channel->max_power; | |
816 | arg.max_reg_power = channel->max_reg_power; | |
817 | arg.max_antenna_gain = channel->max_antenna_gain; | |
818 | ||
819 | arg.pref_tx_streams = ar->num_tx_chains; | |
820 | arg.pref_rx_streams = ar->num_rx_chains; | |
821 | ||
822 | arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); | |
823 | ||
824 | reinit_completion(&ar->vdev_setup_done); | |
825 | reinit_completion(&ar->vdev_delete_done); | |
826 | ||
827 | ret = ath12k_wmi_vdev_start(ar, &arg, false); | |
828 | if (ret) { | |
829 | ath12k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n", | |
830 | vdev_id, ret); | |
831 | return ret; | |
832 | } | |
833 | ||
834 | ret = ath12k_mac_vdev_setup_sync(ar); | |
835 | if (ret) { | |
836 | ath12k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n", | |
837 | vdev_id, ret); | |
838 | return ret; | |
839 | } | |
840 | ||
841 | ret = ath12k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); | |
842 | if (ret) { | |
843 | ath12k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", | |
844 | vdev_id, ret); | |
845 | goto vdev_stop; | |
846 | } | |
847 | ||
848 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i started\n", | |
849 | vdev_id); | |
850 | return 0; | |
851 | ||
852 | vdev_stop: | |
853 | ret = ath12k_wmi_vdev_stop(ar, vdev_id); | |
854 | if (ret) | |
855 | ath12k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n", | |
856 | vdev_id, ret); | |
857 | return ret; | |
858 | } | |
859 | ||
860 | static int ath12k_mac_monitor_vdev_stop(struct ath12k *ar) | |
861 | { | |
862 | int ret; | |
863 | ||
864 | lockdep_assert_held(&ar->conf_mutex); | |
865 | ||
866 | reinit_completion(&ar->vdev_setup_done); | |
867 | ||
868 | ret = ath12k_wmi_vdev_stop(ar, ar->monitor_vdev_id); | |
869 | if (ret) | |
870 | ath12k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n", | |
871 | ar->monitor_vdev_id, ret); | |
872 | ||
873 | ret = ath12k_mac_vdev_setup_sync(ar); | |
874 | if (ret) | |
875 | ath12k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n", | |
876 | ar->monitor_vdev_id, ret); | |
877 | ||
878 | ret = ath12k_wmi_vdev_down(ar, ar->monitor_vdev_id); | |
879 | if (ret) | |
880 | ath12k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n", | |
881 | ar->monitor_vdev_id, ret); | |
882 | ||
883 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %i stopped\n", | |
884 | ar->monitor_vdev_id); | |
885 | return ret; | |
886 | } | |
887 | ||
888 | static int ath12k_mac_monitor_vdev_create(struct ath12k *ar) | |
889 | { | |
890 | struct ath12k_pdev *pdev = ar->pdev; | |
891 | struct ath12k_wmi_vdev_create_arg arg = {}; | |
892 | int bit, ret; | |
893 | u8 tmp_addr[6]; | |
894 | u16 nss; | |
895 | ||
896 | lockdep_assert_held(&ar->conf_mutex); | |
897 | ||
898 | if (ar->monitor_vdev_created) | |
899 | return 0; | |
900 | ||
901 | if (ar->ab->free_vdev_map == 0) { | |
902 | ath12k_warn(ar->ab, "failed to find free vdev id for monitor vdev\n"); | |
903 | return -ENOMEM; | |
904 | } | |
905 | ||
906 | bit = __ffs64(ar->ab->free_vdev_map); | |
907 | ||
908 | ar->monitor_vdev_id = bit; | |
909 | ||
910 | arg.if_id = ar->monitor_vdev_id; | |
911 | arg.type = WMI_VDEV_TYPE_MONITOR; | |
912 | arg.subtype = WMI_VDEV_SUBTYPE_NONE; | |
913 | arg.pdev_id = pdev->pdev_id; | |
914 | arg.if_stats_id = ATH12K_INVAL_VDEV_STATS_ID; | |
915 | ||
916 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
917 | arg.chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; | |
918 | arg.chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; | |
919 | } | |
920 | ||
921 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
922 | arg.chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; | |
923 | arg.chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; | |
924 | } | |
925 | ||
926 | ret = ath12k_wmi_vdev_create(ar, tmp_addr, &arg); | |
927 | if (ret) { | |
928 | ath12k_warn(ar->ab, "failed to request monitor vdev %i creation: %d\n", | |
929 | ar->monitor_vdev_id, ret); | |
930 | ar->monitor_vdev_id = -1; | |
931 | return ret; | |
932 | } | |
933 | ||
934 | nss = hweight32(ar->cfg_tx_chainmask) ? : 1; | |
935 | ret = ath12k_wmi_vdev_set_param_cmd(ar, ar->monitor_vdev_id, | |
936 | WMI_VDEV_PARAM_NSS, nss); | |
937 | if (ret) { | |
938 | ath12k_warn(ar->ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", | |
939 | ar->monitor_vdev_id, ar->cfg_tx_chainmask, nss, ret); | |
940 | return ret; | |
941 | } | |
942 | ||
943 | ret = ath12k_mac_txpower_recalc(ar); | |
944 | if (ret) | |
945 | return ret; | |
946 | ||
947 | ar->allocated_vdev_map |= 1LL << ar->monitor_vdev_id; | |
948 | ar->ab->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); | |
949 | ar->num_created_vdevs++; | |
950 | ar->monitor_vdev_created = true; | |
951 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %d created\n", | |
952 | ar->monitor_vdev_id); | |
953 | ||
954 | return 0; | |
955 | } | |
956 | ||
957 | static int ath12k_mac_monitor_vdev_delete(struct ath12k *ar) | |
958 | { | |
959 | int ret; | |
960 | unsigned long time_left; | |
961 | ||
962 | lockdep_assert_held(&ar->conf_mutex); | |
963 | ||
964 | if (!ar->monitor_vdev_created) | |
965 | return 0; | |
966 | ||
967 | reinit_completion(&ar->vdev_delete_done); | |
968 | ||
969 | ret = ath12k_wmi_vdev_delete(ar, ar->monitor_vdev_id); | |
970 | if (ret) { | |
971 | ath12k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n", | |
972 | ar->monitor_vdev_id, ret); | |
973 | return ret; | |
974 | } | |
975 | ||
976 | time_left = wait_for_completion_timeout(&ar->vdev_delete_done, | |
977 | ATH12K_VDEV_DELETE_TIMEOUT_HZ); | |
978 | if (time_left == 0) { | |
979 | ath12k_warn(ar->ab, "Timeout in receiving vdev delete response\n"); | |
980 | } else { | |
981 | ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id); | |
982 | ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id); | |
983 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor vdev %d deleted\n", | |
984 | ar->monitor_vdev_id); | |
985 | ar->num_created_vdevs--; | |
986 | ar->monitor_vdev_id = -1; | |
987 | ar->monitor_vdev_created = false; | |
988 | } | |
989 | ||
990 | return ret; | |
991 | } | |
992 | ||
993 | static void | |
994 | ath12k_mac_get_any_chandef_iter(struct ieee80211_hw *hw, | |
995 | struct ieee80211_chanctx_conf *conf, | |
996 | void *data) | |
997 | { | |
998 | struct cfg80211_chan_def **def = data; | |
999 | ||
1000 | *def = &conf->def; | |
1001 | } | |
1002 | ||
1003 | static int ath12k_mac_monitor_start(struct ath12k *ar) | |
1004 | { | |
1005 | struct cfg80211_chan_def *chandef = NULL; | |
1006 | int ret; | |
1007 | ||
1008 | lockdep_assert_held(&ar->conf_mutex); | |
1009 | ||
1010 | if (ar->monitor_started) | |
1011 | return 0; | |
1012 | ||
1013 | ieee80211_iter_chan_contexts_atomic(ar->hw, | |
1014 | ath12k_mac_get_any_chandef_iter, | |
1015 | &chandef); | |
1016 | if (!chandef) | |
1017 | return 0; | |
1018 | ||
1019 | ret = ath12k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id, chandef); | |
1020 | if (ret) { | |
1021 | ath12k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret); | |
1022 | ath12k_mac_monitor_vdev_delete(ar); | |
1023 | return ret; | |
1024 | } | |
1025 | ||
1026 | ar->monitor_started = true; | |
1027 | ar->num_started_vdevs++; | |
1028 | ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, false); | |
1029 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor started ret %d\n", ret); | |
1030 | ||
1031 | return ret; | |
1032 | } | |
1033 | ||
1034 | static int ath12k_mac_monitor_stop(struct ath12k *ar) | |
1035 | { | |
1036 | int ret; | |
1037 | ||
1038 | lockdep_assert_held(&ar->conf_mutex); | |
1039 | ||
1040 | if (!ar->monitor_started) | |
1041 | return 0; | |
1042 | ||
1043 | ret = ath12k_mac_monitor_vdev_stop(ar); | |
1044 | if (ret) { | |
1045 | ath12k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret); | |
1046 | return ret; | |
1047 | } | |
1048 | ||
1049 | ar->monitor_started = false; | |
1050 | ar->num_started_vdevs--; | |
1051 | ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, true); | |
1052 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac monitor stopped ret %d\n", ret); | |
1053 | return ret; | |
1054 | } | |
1055 | ||
1056 | static int ath12k_mac_op_config(struct ieee80211_hw *hw, u32 changed) | |
1057 | { | |
1058 | struct ath12k *ar = hw->priv; | |
1059 | struct ieee80211_conf *conf = &hw->conf; | |
d1335f0d | 1060 | int ret = 0; |
d8899132 KV |
1061 | |
1062 | mutex_lock(&ar->conf_mutex); | |
1063 | ||
1064 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { | |
1065 | ar->monitor_conf_enabled = conf->flags & IEEE80211_CONF_MONITOR; | |
1066 | if (ar->monitor_conf_enabled) { | |
1067 | if (ar->monitor_vdev_created) | |
1068 | goto exit; | |
1069 | ret = ath12k_mac_monitor_vdev_create(ar); | |
1070 | if (ret) | |
1071 | goto exit; | |
1072 | ret = ath12k_mac_monitor_start(ar); | |
1073 | if (ret) | |
1074 | goto err_mon_del; | |
1075 | } else { | |
1076 | if (!ar->monitor_vdev_created) | |
1077 | goto exit; | |
1078 | ret = ath12k_mac_monitor_stop(ar); | |
1079 | if (ret) | |
1080 | goto exit; | |
1081 | ath12k_mac_monitor_vdev_delete(ar); | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | exit: | |
1086 | mutex_unlock(&ar->conf_mutex); | |
1087 | return ret; | |
1088 | ||
1089 | err_mon_del: | |
1090 | ath12k_mac_monitor_vdev_delete(ar); | |
1091 | mutex_unlock(&ar->conf_mutex); | |
d1335f0d | 1092 | return ret; |
d8899132 KV |
1093 | } |
1094 | ||
1095 | static int ath12k_mac_setup_bcn_tmpl(struct ath12k_vif *arvif) | |
1096 | { | |
1097 | struct ath12k *ar = arvif->ar; | |
1098 | struct ath12k_base *ab = ar->ab; | |
1099 | struct ieee80211_hw *hw = ar->hw; | |
1100 | struct ieee80211_vif *vif = arvif->vif; | |
1101 | struct ieee80211_mutable_offsets offs = {}; | |
1102 | struct sk_buff *bcn; | |
1103 | struct ieee80211_mgmt *mgmt; | |
1104 | u8 *ies; | |
1105 | int ret; | |
1106 | ||
1107 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) | |
1108 | return 0; | |
1109 | ||
1110 | bcn = ieee80211_beacon_get_template(hw, vif, &offs, 0); | |
1111 | if (!bcn) { | |
1112 | ath12k_warn(ab, "failed to get beacon template from mac80211\n"); | |
1113 | return -EPERM; | |
1114 | } | |
1115 | ||
1116 | ies = bcn->data + ieee80211_get_hdrlen_from_skb(bcn); | |
1117 | ies += sizeof(mgmt->u.beacon); | |
1118 | ||
1119 | if (cfg80211_find_ie(WLAN_EID_RSN, ies, (skb_tail_pointer(bcn) - ies))) | |
1120 | arvif->rsnie_present = true; | |
1121 | ||
1122 | if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
1123 | WLAN_OUI_TYPE_MICROSOFT_WPA, | |
1124 | ies, (skb_tail_pointer(bcn) - ies))) | |
1125 | arvif->wpaie_present = true; | |
1126 | ||
1127 | ret = ath12k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn); | |
1128 | ||
1129 | kfree_skb(bcn); | |
1130 | ||
1131 | if (ret) | |
1132 | ath12k_warn(ab, "failed to submit beacon template command: %d\n", | |
1133 | ret); | |
1134 | ||
1135 | return ret; | |
1136 | } | |
1137 | ||
1138 | static void ath12k_control_beaconing(struct ath12k_vif *arvif, | |
1139 | struct ieee80211_bss_conf *info) | |
1140 | { | |
1141 | struct ath12k *ar = arvif->ar; | |
1142 | int ret; | |
1143 | ||
1144 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
1145 | ||
1146 | if (!info->enable_beacon) { | |
1147 | ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); | |
1148 | if (ret) | |
1149 | ath12k_warn(ar->ab, "failed to down vdev_id %i: %d\n", | |
1150 | arvif->vdev_id, ret); | |
1151 | ||
1152 | arvif->is_up = false; | |
1153 | return; | |
1154 | } | |
1155 | ||
1156 | /* Install the beacon template to the FW */ | |
1157 | ret = ath12k_mac_setup_bcn_tmpl(arvif); | |
1158 | if (ret) { | |
1159 | ath12k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n", | |
1160 | ret); | |
1161 | return; | |
1162 | } | |
1163 | ||
1164 | arvif->aid = 0; | |
1165 | ||
1166 | ether_addr_copy(arvif->bssid, info->bssid); | |
1167 | ||
1168 | ret = ath12k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
1169 | arvif->bssid); | |
1170 | if (ret) { | |
1171 | ath12k_warn(ar->ab, "failed to bring up vdev %d: %i\n", | |
1172 | arvif->vdev_id, ret); | |
1173 | return; | |
1174 | } | |
1175 | ||
1176 | arvif->is_up = true; | |
1177 | ||
1178 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); | |
1179 | } | |
1180 | ||
1181 | static void ath12k_peer_assoc_h_basic(struct ath12k *ar, | |
1182 | struct ieee80211_vif *vif, | |
1183 | struct ieee80211_sta *sta, | |
1184 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1185 | { | |
1186 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
1187 | u32 aid; | |
1188 | ||
1189 | lockdep_assert_held(&ar->conf_mutex); | |
1190 | ||
1191 | if (vif->type == NL80211_IFTYPE_STATION) | |
1192 | aid = vif->cfg.aid; | |
1193 | else | |
1194 | aid = sta->aid; | |
1195 | ||
1196 | ether_addr_copy(arg->peer_mac, sta->addr); | |
1197 | arg->vdev_id = arvif->vdev_id; | |
1198 | arg->peer_associd = aid; | |
1199 | arg->auth_flag = true; | |
1200 | /* TODO: STA WAR in ath10k for listen interval required? */ | |
1201 | arg->peer_listen_intval = ar->hw->conf.listen_interval; | |
1202 | arg->peer_nss = 1; | |
1203 | arg->peer_caps = vif->bss_conf.assoc_capability; | |
1204 | } | |
1205 | ||
1206 | static void ath12k_peer_assoc_h_crypto(struct ath12k *ar, | |
1207 | struct ieee80211_vif *vif, | |
1208 | struct ieee80211_sta *sta, | |
1209 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1210 | { | |
1211 | struct ieee80211_bss_conf *info = &vif->bss_conf; | |
1212 | struct cfg80211_chan_def def; | |
1213 | struct cfg80211_bss *bss; | |
1214 | struct ath12k_vif *arvif = (struct ath12k_vif *)vif->drv_priv; | |
1215 | const u8 *rsnie = NULL; | |
1216 | const u8 *wpaie = NULL; | |
1217 | ||
1218 | lockdep_assert_held(&ar->conf_mutex); | |
1219 | ||
1220 | if (WARN_ON(ath12k_mac_vif_chan(vif, &def))) | |
1221 | return; | |
1222 | ||
1223 | bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0, | |
1224 | IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); | |
1225 | ||
1226 | if (arvif->rsnie_present || arvif->wpaie_present) { | |
1227 | arg->need_ptk_4_way = true; | |
1228 | if (arvif->wpaie_present) | |
1229 | arg->need_gtk_2_way = true; | |
1230 | } else if (bss) { | |
1231 | const struct cfg80211_bss_ies *ies; | |
1232 | ||
1233 | rcu_read_lock(); | |
1234 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); | |
1235 | ||
1236 | ies = rcu_dereference(bss->ies); | |
1237 | ||
1238 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
1239 | WLAN_OUI_TYPE_MICROSOFT_WPA, | |
1240 | ies->data, | |
1241 | ies->len); | |
1242 | rcu_read_unlock(); | |
1243 | cfg80211_put_bss(ar->hw->wiphy, bss); | |
1244 | } | |
1245 | ||
1246 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ | |
1247 | if (rsnie || wpaie) { | |
1248 | ath12k_dbg(ar->ab, ATH12K_DBG_WMI, | |
1249 | "%s: rsn ie found\n", __func__); | |
1250 | arg->need_ptk_4_way = true; | |
1251 | } | |
1252 | ||
1253 | if (wpaie) { | |
1254 | ath12k_dbg(ar->ab, ATH12K_DBG_WMI, | |
1255 | "%s: wpa ie found\n", __func__); | |
1256 | arg->need_gtk_2_way = true; | |
1257 | } | |
1258 | ||
1259 | if (sta->mfp) { | |
1260 | /* TODO: Need to check if FW supports PMF? */ | |
1261 | arg->is_pmf_enabled = true; | |
1262 | } | |
1263 | ||
1264 | /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */ | |
1265 | } | |
1266 | ||
1267 | static void ath12k_peer_assoc_h_rates(struct ath12k *ar, | |
1268 | struct ieee80211_vif *vif, | |
1269 | struct ieee80211_sta *sta, | |
1270 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1271 | { | |
1272 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
1273 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; | |
1274 | struct cfg80211_chan_def def; | |
1275 | const struct ieee80211_supported_band *sband; | |
1276 | const struct ieee80211_rate *rates; | |
1277 | enum nl80211_band band; | |
1278 | u32 ratemask; | |
1279 | u8 rate; | |
1280 | int i; | |
1281 | ||
1282 | lockdep_assert_held(&ar->conf_mutex); | |
1283 | ||
1284 | if (WARN_ON(ath12k_mac_vif_chan(vif, &def))) | |
1285 | return; | |
1286 | ||
1287 | band = def.chan->band; | |
1288 | sband = ar->hw->wiphy->bands[band]; | |
1289 | ratemask = sta->deflink.supp_rates[band]; | |
1290 | ratemask &= arvif->bitrate_mask.control[band].legacy; | |
1291 | rates = sband->bitrates; | |
1292 | ||
1293 | rateset->num_rates = 0; | |
1294 | ||
1295 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { | |
1296 | if (!(ratemask & 1)) | |
1297 | continue; | |
1298 | ||
1299 | rate = ath12k_mac_bitrate_to_rate(rates->bitrate); | |
1300 | rateset->rates[rateset->num_rates] = rate; | |
1301 | rateset->num_rates++; | |
1302 | } | |
1303 | } | |
1304 | ||
1305 | static bool | |
1306 | ath12k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | |
1307 | { | |
1308 | int nss; | |
1309 | ||
1310 | for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) | |
1311 | if (ht_mcs_mask[nss]) | |
1312 | return false; | |
1313 | ||
1314 | return true; | |
1315 | } | |
1316 | ||
1317 | static bool | |
1318 | ath12k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
1319 | { | |
1320 | int nss; | |
1321 | ||
1322 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) | |
1323 | if (vht_mcs_mask[nss]) | |
1324 | return false; | |
1325 | ||
1326 | return true; | |
1327 | } | |
1328 | ||
1329 | static void ath12k_peer_assoc_h_ht(struct ath12k *ar, | |
1330 | struct ieee80211_vif *vif, | |
1331 | struct ieee80211_sta *sta, | |
1332 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1333 | { | |
1334 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap; | |
1335 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
1336 | struct cfg80211_chan_def def; | |
1337 | enum nl80211_band band; | |
1338 | const u8 *ht_mcs_mask; | |
1339 | int i, n; | |
1340 | u8 max_nss; | |
1341 | u32 stbc; | |
1342 | ||
1343 | lockdep_assert_held(&ar->conf_mutex); | |
1344 | ||
1345 | if (WARN_ON(ath12k_mac_vif_chan(vif, &def))) | |
1346 | return; | |
1347 | ||
1348 | if (!ht_cap->ht_supported) | |
1349 | return; | |
1350 | ||
1351 | band = def.chan->band; | |
1352 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
1353 | ||
1354 | if (ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) | |
1355 | return; | |
1356 | ||
1357 | arg->ht_flag = true; | |
1358 | ||
1359 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
1360 | ht_cap->ampdu_factor)) - 1; | |
1361 | ||
1362 | arg->peer_mpdu_density = | |
1363 | ath12k_parse_mpdudensity(ht_cap->ampdu_density); | |
1364 | ||
1365 | arg->peer_ht_caps = ht_cap->cap; | |
1366 | arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG; | |
1367 | ||
1368 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) | |
1369 | arg->ldpc_flag = true; | |
1370 | ||
1371 | if (sta->deflink.bandwidth >= IEEE80211_STA_RX_BW_40) { | |
1372 | arg->bw_40 = true; | |
1373 | arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG; | |
1374 | } | |
1375 | ||
1376 | if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { | |
1377 | if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | | |
1378 | IEEE80211_HT_CAP_SGI_40)) | |
1379 | arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG; | |
1380 | } | |
1381 | ||
1382 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { | |
1383 | arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG; | |
1384 | arg->stbc_flag = true; | |
1385 | } | |
1386 | ||
1387 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { | |
1388 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; | |
1389 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
1390 | stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S; | |
1391 | arg->peer_rate_caps |= stbc; | |
1392 | arg->stbc_flag = true; | |
1393 | } | |
1394 | ||
1395 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) | |
1396 | arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG; | |
1397 | else if (ht_cap->mcs.rx_mask[1]) | |
1398 | arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG; | |
1399 | ||
1400 | for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) | |
1401 | if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && | |
1402 | (ht_mcs_mask[i / 8] & BIT(i % 8))) { | |
1403 | max_nss = (i / 8) + 1; | |
1404 | arg->peer_ht_rates.rates[n++] = i; | |
1405 | } | |
1406 | ||
1407 | /* This is a workaround for HT-enabled STAs which break the spec | |
1408 | * and have no HT capabilities RX mask (no HT RX MCS map). | |
1409 | * | |
1410 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), | |
1411 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. | |
1412 | * | |
1413 | * Firmware asserts if such situation occurs. | |
1414 | */ | |
1415 | if (n == 0) { | |
1416 | arg->peer_ht_rates.num_rates = 8; | |
1417 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) | |
1418 | arg->peer_ht_rates.rates[i] = i; | |
1419 | } else { | |
1420 | arg->peer_ht_rates.num_rates = n; | |
1421 | arg->peer_nss = min(sta->deflink.rx_nss, max_nss); | |
1422 | } | |
1423 | ||
1424 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", | |
1425 | arg->peer_mac, | |
1426 | arg->peer_ht_rates.num_rates, | |
1427 | arg->peer_nss); | |
1428 | } | |
1429 | ||
1430 | static int ath12k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) | |
1431 | { | |
1432 | switch ((mcs_map >> (2 * nss)) & 0x3) { | |
1433 | case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; | |
1434 | case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; | |
1435 | case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; | |
1436 | } | |
1437 | return 0; | |
1438 | } | |
1439 | ||
1440 | static u16 | |
1441 | ath12k_peer_assoc_h_vht_limit(u16 tx_mcs_set, | |
1442 | const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) | |
1443 | { | |
1444 | int idx_limit; | |
1445 | int nss; | |
1446 | u16 mcs_map; | |
1447 | u16 mcs; | |
1448 | ||
1449 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
1450 | mcs_map = ath12k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & | |
1451 | vht_mcs_limit[nss]; | |
1452 | ||
1453 | if (mcs_map) | |
1454 | idx_limit = fls(mcs_map) - 1; | |
1455 | else | |
1456 | idx_limit = -1; | |
1457 | ||
1458 | switch (idx_limit) { | |
1459 | case 0: | |
1460 | case 1: | |
1461 | case 2: | |
1462 | case 3: | |
1463 | case 4: | |
1464 | case 5: | |
1465 | case 6: | |
1466 | case 7: | |
1467 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; | |
1468 | break; | |
1469 | case 8: | |
1470 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; | |
1471 | break; | |
1472 | case 9: | |
1473 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; | |
1474 | break; | |
1475 | default: | |
1476 | WARN_ON(1); | |
1477 | fallthrough; | |
1478 | case -1: | |
1479 | mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; | |
1480 | break; | |
1481 | } | |
1482 | ||
1483 | tx_mcs_set &= ~(0x3 << (nss * 2)); | |
1484 | tx_mcs_set |= mcs << (nss * 2); | |
1485 | } | |
1486 | ||
1487 | return tx_mcs_set; | |
1488 | } | |
1489 | ||
1490 | static void ath12k_peer_assoc_h_vht(struct ath12k *ar, | |
1491 | struct ieee80211_vif *vif, | |
1492 | struct ieee80211_sta *sta, | |
1493 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1494 | { | |
1495 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->deflink.vht_cap; | |
1496 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
1497 | struct cfg80211_chan_def def; | |
1498 | enum nl80211_band band; | |
1499 | const u16 *vht_mcs_mask; | |
1500 | u16 tx_mcs_map; | |
1501 | u8 ampdu_factor; | |
1502 | u8 max_nss, vht_mcs; | |
1503 | int i; | |
1504 | ||
1505 | if (WARN_ON(ath12k_mac_vif_chan(vif, &def))) | |
1506 | return; | |
1507 | ||
1508 | if (!vht_cap->vht_supported) | |
1509 | return; | |
1510 | ||
1511 | band = def.chan->band; | |
1512 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
1513 | ||
1514 | if (ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) | |
1515 | return; | |
1516 | ||
1517 | arg->vht_flag = true; | |
1518 | ||
1519 | /* TODO: similar flags required? */ | |
1520 | arg->vht_capable = true; | |
1521 | ||
1522 | if (def.chan->band == NL80211_BAND_2GHZ) | |
1523 | arg->vht_ng_flag = true; | |
1524 | ||
1525 | arg->peer_vht_caps = vht_cap->cap; | |
1526 | ||
1527 | ampdu_factor = (vht_cap->cap & | |
1528 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> | |
1529 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
1530 | ||
1531 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to | |
1532 | * zero in VHT IE. Using it would result in degraded throughput. | |
1533 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep | |
1534 | * it if VHT max_mpdu is smaller. | |
1535 | */ | |
1536 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, | |
1537 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
1538 | ampdu_factor)) - 1); | |
1539 | ||
1540 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80) | |
1541 | arg->bw_80 = true; | |
1542 | ||
1543 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) | |
1544 | arg->bw_160 = true; | |
1545 | ||
1546 | /* Calculate peer NSS capability from VHT capabilities if STA | |
1547 | * supports VHT. | |
1548 | */ | |
1549 | for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
1550 | vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> | |
1551 | (2 * i) & 3; | |
1552 | ||
1553 | if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED && | |
1554 | vht_mcs_mask[i]) | |
1555 | max_nss = i + 1; | |
1556 | } | |
1557 | arg->peer_nss = min(sta->deflink.rx_nss, max_nss); | |
1558 | arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest); | |
1559 | arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); | |
1560 | arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest); | |
1561 | ||
1562 | tx_mcs_map = __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); | |
1563 | arg->tx_mcs_set = ath12k_peer_assoc_h_vht_limit(tx_mcs_map, vht_mcs_mask); | |
1564 | ||
1565 | /* In QCN9274 platform, VHT MCS rate 10 and 11 is enabled by default. | |
1566 | * VHT MCS rate 10 and 11 is not supported in 11ac standard. | |
1567 | * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode. | |
1568 | */ | |
1569 | arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK; | |
1570 | arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11; | |
1571 | ||
1572 | if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) == | |
1573 | IEEE80211_VHT_MCS_NOT_SUPPORTED) | |
1574 | arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; | |
1575 | ||
1576 | /* TODO: Check */ | |
1577 | arg->tx_max_mcs_nss = 0xFF; | |
1578 | ||
1579 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", | |
1580 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); | |
1581 | ||
1582 | /* TODO: rxnss_override */ | |
1583 | } | |
1584 | ||
1585 | static void ath12k_peer_assoc_h_he(struct ath12k *ar, | |
1586 | struct ieee80211_vif *vif, | |
1587 | struct ieee80211_sta *sta, | |
1588 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1589 | { | |
1590 | const struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap; | |
1591 | int i; | |
1592 | u8 ampdu_factor, rx_mcs_80, rx_mcs_160, max_nss; | |
1593 | u16 mcs_160_map, mcs_80_map; | |
1594 | bool support_160; | |
1595 | u16 v; | |
1596 | ||
1597 | if (!he_cap->has_he) | |
1598 | return; | |
1599 | ||
1600 | arg->he_flag = true; | |
1601 | ||
1602 | support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] & | |
1603 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G); | |
1604 | ||
1605 | /* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */ | |
1606 | mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); | |
1607 | mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); | |
1608 | ||
1609 | if (support_160) { | |
1610 | for (i = 7; i >= 0; i--) { | |
1611 | u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3; | |
1612 | ||
1613 | if (mcs_160 != IEEE80211_HE_MCS_NOT_SUPPORTED) { | |
1614 | rx_mcs_160 = i + 1; | |
1615 | break; | |
1616 | } | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | for (i = 7; i >= 0; i--) { | |
1621 | u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3; | |
1622 | ||
1623 | if (mcs_80 != IEEE80211_HE_MCS_NOT_SUPPORTED) { | |
1624 | rx_mcs_80 = i + 1; | |
1625 | break; | |
1626 | } | |
1627 | } | |
1628 | ||
1629 | if (support_160) | |
1630 | max_nss = min(rx_mcs_80, rx_mcs_160); | |
1631 | else | |
1632 | max_nss = rx_mcs_80; | |
1633 | ||
1634 | arg->peer_nss = min(sta->deflink.rx_nss, max_nss); | |
1635 | ||
1636 | memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info, | |
1637 | sizeof(arg->peer_he_cap_macinfo)); | |
1638 | memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info, | |
1639 | sizeof(arg->peer_he_cap_phyinfo)); | |
1640 | arg->peer_he_ops = vif->bss_conf.he_oper.params; | |
1641 | ||
1642 | /* the top most byte is used to indicate BSS color info */ | |
1643 | arg->peer_he_ops &= 0xffffff; | |
1644 | ||
1645 | /* As per section 26.6.1 IEEE Std 802.11ax‐2022, if the Max AMPDU | |
1646 | * Exponent Extension in HE cap is zero, use the arg->peer_max_mpdu | |
1647 | * as calculated while parsing VHT caps(if VHT caps is present) | |
1648 | * or HT caps (if VHT caps is not present). | |
1649 | * | |
1650 | * For non-zero value of Max AMPDU Exponent Extension in HE MAC caps, | |
1651 | * if a HE STA sends VHT cap and HE cap IE in assoc request then, use | |
1652 | * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length. | |
1653 | * If a HE STA that does not send VHT cap, but HE and HT cap in assoc | |
1654 | * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu | |
1655 | * length. | |
1656 | */ | |
1657 | ampdu_factor = (he_cap->he_cap_elem.mac_cap_info[3] & | |
1658 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) >> | |
1659 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK; | |
1660 | ||
1661 | if (ampdu_factor) { | |
1662 | if (sta->deflink.vht_cap.vht_supported) | |
1663 | arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR + | |
1664 | ampdu_factor)) - 1; | |
1665 | else if (sta->deflink.ht_cap.ht_supported) | |
1666 | arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR + | |
1667 | ampdu_factor)) - 1; | |
1668 | } | |
1669 | ||
1670 | if (he_cap->he_cap_elem.phy_cap_info[6] & | |
1671 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { | |
1672 | int bit = 7; | |
1673 | int nss, ru; | |
1674 | ||
1675 | arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] & | |
1676 | IEEE80211_PPE_THRES_NSS_MASK; | |
1677 | arg->peer_ppet.ru_bit_mask = | |
1678 | (he_cap->ppe_thres[0] & | |
1679 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> | |
1680 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; | |
1681 | ||
1682 | for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) { | |
1683 | for (ru = 0; ru < 4; ru++) { | |
1684 | u32 val = 0; | |
1685 | int i; | |
1686 | ||
1687 | if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0) | |
1688 | continue; | |
1689 | for (i = 0; i < 6; i++) { | |
1690 | val >>= 1; | |
1691 | val |= ((he_cap->ppe_thres[bit / 8] >> | |
1692 | (bit % 8)) & 0x1) << 5; | |
1693 | bit++; | |
1694 | } | |
1695 | arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |= | |
1696 | val << (ru * 6); | |
1697 | } | |
1698 | } | |
1699 | } | |
1700 | ||
1701 | if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES) | |
1702 | arg->twt_responder = true; | |
1703 | if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ) | |
1704 | arg->twt_requester = true; | |
1705 | ||
1706 | switch (sta->deflink.bandwidth) { | |
1707 | case IEEE80211_STA_RX_BW_160: | |
1708 | if (he_cap->he_cap_elem.phy_cap_info[0] & | |
1709 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) { | |
1710 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80); | |
1711 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; | |
1712 | ||
1713 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80); | |
1714 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; | |
1715 | ||
1716 | arg->peer_he_mcs_count++; | |
1717 | } | |
1718 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); | |
1719 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; | |
1720 | ||
1721 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160); | |
1722 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; | |
1723 | ||
1724 | arg->peer_he_mcs_count++; | |
1725 | fallthrough; | |
1726 | ||
1727 | default: | |
1728 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); | |
1729 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; | |
1730 | ||
1731 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); | |
1732 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; | |
1733 | ||
1734 | arg->peer_he_mcs_count++; | |
1735 | break; | |
1736 | } | |
1737 | } | |
1738 | ||
1739 | static void ath12k_peer_assoc_h_smps(struct ieee80211_sta *sta, | |
1740 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1741 | { | |
1742 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap; | |
1743 | int smps; | |
1744 | ||
1745 | if (!ht_cap->ht_supported) | |
1746 | return; | |
1747 | ||
1748 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; | |
1749 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
1750 | ||
1751 | switch (smps) { | |
1752 | case WLAN_HT_CAP_SM_PS_STATIC: | |
1753 | arg->static_mimops_flag = true; | |
1754 | break; | |
1755 | case WLAN_HT_CAP_SM_PS_DYNAMIC: | |
1756 | arg->dynamic_mimops_flag = true; | |
1757 | break; | |
1758 | case WLAN_HT_CAP_SM_PS_DISABLED: | |
1759 | arg->spatial_mux_flag = true; | |
1760 | break; | |
1761 | default: | |
1762 | break; | |
1763 | } | |
1764 | } | |
1765 | ||
1766 | static void ath12k_peer_assoc_h_qos(struct ath12k *ar, | |
1767 | struct ieee80211_vif *vif, | |
1768 | struct ieee80211_sta *sta, | |
1769 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1770 | { | |
1771 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
1772 | ||
1773 | switch (arvif->vdev_type) { | |
1774 | case WMI_VDEV_TYPE_AP: | |
1775 | if (sta->wme) { | |
1776 | /* TODO: Check WME vs QoS */ | |
1777 | arg->is_wme_set = true; | |
1778 | arg->qos_flag = true; | |
1779 | } | |
1780 | ||
1781 | if (sta->wme && sta->uapsd_queues) { | |
1782 | /* TODO: Check WME vs QoS */ | |
1783 | arg->is_wme_set = true; | |
1784 | arg->apsd_flag = true; | |
1785 | arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG; | |
1786 | } | |
1787 | break; | |
1788 | case WMI_VDEV_TYPE_STA: | |
1789 | if (sta->wme) { | |
1790 | arg->is_wme_set = true; | |
1791 | arg->qos_flag = true; | |
1792 | } | |
1793 | break; | |
1794 | default: | |
1795 | break; | |
1796 | } | |
1797 | ||
1798 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM qos %d\n", | |
1799 | sta->addr, arg->qos_flag); | |
1800 | } | |
1801 | ||
1802 | static int ath12k_peer_assoc_qos_ap(struct ath12k *ar, | |
1803 | struct ath12k_vif *arvif, | |
1804 | struct ieee80211_sta *sta) | |
1805 | { | |
1806 | struct ath12k_wmi_ap_ps_arg arg; | |
1807 | u32 max_sp; | |
1808 | u32 uapsd; | |
1809 | int ret; | |
1810 | ||
1811 | lockdep_assert_held(&ar->conf_mutex); | |
1812 | ||
1813 | arg.vdev_id = arvif->vdev_id; | |
1814 | ||
1815 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", | |
1816 | sta->uapsd_queues, sta->max_sp); | |
1817 | ||
1818 | uapsd = 0; | |
1819 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) | |
1820 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | | |
1821 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; | |
1822 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) | |
1823 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | | |
1824 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; | |
1825 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) | |
1826 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | | |
1827 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; | |
1828 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) | |
1829 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | | |
1830 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; | |
1831 | ||
1832 | max_sp = 0; | |
1833 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) | |
1834 | max_sp = sta->max_sp; | |
1835 | ||
1836 | arg.param = WMI_AP_PS_PEER_PARAM_UAPSD; | |
1837 | arg.value = uapsd; | |
1838 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, &arg); | |
1839 | if (ret) | |
1840 | goto err; | |
1841 | ||
1842 | arg.param = WMI_AP_PS_PEER_PARAM_MAX_SP; | |
1843 | arg.value = max_sp; | |
1844 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, &arg); | |
1845 | if (ret) | |
1846 | goto err; | |
1847 | ||
1848 | /* TODO: revisit during testing */ | |
1849 | arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE; | |
1850 | arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; | |
1851 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, &arg); | |
1852 | if (ret) | |
1853 | goto err; | |
1854 | ||
1855 | arg.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD; | |
1856 | arg.value = DISABLE_SIFS_RESPONSE_TRIGGER; | |
1857 | ret = ath12k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, &arg); | |
1858 | if (ret) | |
1859 | goto err; | |
1860 | ||
1861 | return 0; | |
1862 | ||
1863 | err: | |
1864 | ath12k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n", | |
1865 | arg.param, arvif->vdev_id, ret); | |
1866 | return ret; | |
1867 | } | |
1868 | ||
1869 | static bool ath12k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta) | |
1870 | { | |
1871 | return sta->deflink.supp_rates[NL80211_BAND_2GHZ] >> | |
1872 | ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
1873 | } | |
1874 | ||
1875 | static enum wmi_phy_mode ath12k_mac_get_phymode_vht(struct ath12k *ar, | |
1876 | struct ieee80211_sta *sta) | |
1877 | { | |
1878 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) { | |
1879 | switch (sta->deflink.vht_cap.cap & | |
1880 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { | |
1881 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: | |
1882 | return MODE_11AC_VHT160; | |
1883 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: | |
1884 | return MODE_11AC_VHT80_80; | |
1885 | default: | |
1886 | /* not sure if this is a valid case? */ | |
1887 | return MODE_11AC_VHT160; | |
1888 | } | |
1889 | } | |
1890 | ||
1891 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80) | |
1892 | return MODE_11AC_VHT80; | |
1893 | ||
1894 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40) | |
1895 | return MODE_11AC_VHT40; | |
1896 | ||
1897 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20) | |
1898 | return MODE_11AC_VHT20; | |
1899 | ||
1900 | return MODE_UNKNOWN; | |
1901 | } | |
1902 | ||
1903 | static enum wmi_phy_mode ath12k_mac_get_phymode_he(struct ath12k *ar, | |
1904 | struct ieee80211_sta *sta) | |
1905 | { | |
1906 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) { | |
1907 | if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[0] & | |
1908 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) | |
1909 | return MODE_11AX_HE160; | |
1910 | else if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[0] & | |
1911 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) | |
1912 | return MODE_11AX_HE80_80; | |
1913 | /* not sure if this is a valid case? */ | |
1914 | return MODE_11AX_HE160; | |
1915 | } | |
1916 | ||
1917 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80) | |
1918 | return MODE_11AX_HE80; | |
1919 | ||
1920 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40) | |
1921 | return MODE_11AX_HE40; | |
1922 | ||
1923 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20) | |
1924 | return MODE_11AX_HE20; | |
1925 | ||
1926 | return MODE_UNKNOWN; | |
1927 | } | |
1928 | ||
1929 | static void ath12k_peer_assoc_h_phymode(struct ath12k *ar, | |
1930 | struct ieee80211_vif *vif, | |
1931 | struct ieee80211_sta *sta, | |
1932 | struct ath12k_wmi_peer_assoc_arg *arg) | |
1933 | { | |
1934 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
1935 | struct cfg80211_chan_def def; | |
1936 | enum nl80211_band band; | |
1937 | const u8 *ht_mcs_mask; | |
1938 | const u16 *vht_mcs_mask; | |
1939 | enum wmi_phy_mode phymode = MODE_UNKNOWN; | |
1940 | ||
1941 | if (WARN_ON(ath12k_mac_vif_chan(vif, &def))) | |
1942 | return; | |
1943 | ||
1944 | band = def.chan->band; | |
1945 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
1946 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
1947 | ||
1948 | switch (band) { | |
1949 | case NL80211_BAND_2GHZ: | |
1950 | if (sta->deflink.he_cap.has_he) { | |
1951 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80) | |
1952 | phymode = MODE_11AX_HE80_2G; | |
1953 | else if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40) | |
1954 | phymode = MODE_11AX_HE40_2G; | |
1955 | else | |
1956 | phymode = MODE_11AX_HE20_2G; | |
1957 | } else if (sta->deflink.vht_cap.vht_supported && | |
1958 | !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { | |
1959 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40) | |
1960 | phymode = MODE_11AC_VHT40; | |
1961 | else | |
1962 | phymode = MODE_11AC_VHT20; | |
1963 | } else if (sta->deflink.ht_cap.ht_supported && | |
1964 | !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { | |
1965 | if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40) | |
1966 | phymode = MODE_11NG_HT40; | |
1967 | else | |
1968 | phymode = MODE_11NG_HT20; | |
1969 | } else if (ath12k_mac_sta_has_ofdm_only(sta)) { | |
1970 | phymode = MODE_11G; | |
1971 | } else { | |
1972 | phymode = MODE_11B; | |
1973 | } | |
1974 | break; | |
1975 | case NL80211_BAND_5GHZ: | |
1976 | case NL80211_BAND_6GHZ: | |
1977 | /* Check HE first */ | |
1978 | if (sta->deflink.he_cap.has_he) { | |
1979 | phymode = ath12k_mac_get_phymode_he(ar, sta); | |
1980 | } else if (sta->deflink.vht_cap.vht_supported && | |
1981 | !ath12k_peer_assoc_h_vht_masked(vht_mcs_mask)) { | |
1982 | phymode = ath12k_mac_get_phymode_vht(ar, sta); | |
1983 | } else if (sta->deflink.ht_cap.ht_supported && | |
1984 | !ath12k_peer_assoc_h_ht_masked(ht_mcs_mask)) { | |
1985 | if (sta->deflink.bandwidth >= IEEE80211_STA_RX_BW_40) | |
1986 | phymode = MODE_11NA_HT40; | |
1987 | else | |
1988 | phymode = MODE_11NA_HT20; | |
1989 | } else { | |
1990 | phymode = MODE_11A; | |
1991 | } | |
1992 | break; | |
1993 | default: | |
1994 | break; | |
1995 | } | |
1996 | ||
1997 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac peer %pM phymode %s\n", | |
1998 | sta->addr, ath12k_mac_phymode_str(phymode)); | |
1999 | ||
2000 | arg->peer_phymode = phymode; | |
2001 | WARN_ON(phymode == MODE_UNKNOWN); | |
2002 | } | |
2003 | ||
2004 | static void ath12k_peer_assoc_prepare(struct ath12k *ar, | |
2005 | struct ieee80211_vif *vif, | |
2006 | struct ieee80211_sta *sta, | |
2007 | struct ath12k_wmi_peer_assoc_arg *arg, | |
2008 | bool reassoc) | |
2009 | { | |
2010 | lockdep_assert_held(&ar->conf_mutex); | |
2011 | ||
2012 | memset(arg, 0, sizeof(*arg)); | |
2013 | ||
2014 | reinit_completion(&ar->peer_assoc_done); | |
2015 | ||
2016 | arg->peer_new_assoc = !reassoc; | |
2017 | ath12k_peer_assoc_h_basic(ar, vif, sta, arg); | |
2018 | ath12k_peer_assoc_h_crypto(ar, vif, sta, arg); | |
2019 | ath12k_peer_assoc_h_rates(ar, vif, sta, arg); | |
2020 | ath12k_peer_assoc_h_ht(ar, vif, sta, arg); | |
2021 | ath12k_peer_assoc_h_vht(ar, vif, sta, arg); | |
2022 | ath12k_peer_assoc_h_he(ar, vif, sta, arg); | |
2023 | ath12k_peer_assoc_h_qos(ar, vif, sta, arg); | |
2024 | ath12k_peer_assoc_h_phymode(ar, vif, sta, arg); | |
2025 | ath12k_peer_assoc_h_smps(sta, arg); | |
2026 | ||
2027 | /* TODO: amsdu_disable req? */ | |
2028 | } | |
2029 | ||
2030 | static int ath12k_setup_peer_smps(struct ath12k *ar, struct ath12k_vif *arvif, | |
2031 | const u8 *addr, | |
2032 | const struct ieee80211_sta_ht_cap *ht_cap) | |
2033 | { | |
2034 | int smps; | |
2035 | ||
2036 | if (!ht_cap->ht_supported) | |
2037 | return 0; | |
2038 | ||
2039 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; | |
2040 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
2041 | ||
2042 | if (smps >= ARRAY_SIZE(ath12k_smps_map)) | |
2043 | return -EINVAL; | |
2044 | ||
2045 | return ath12k_wmi_set_peer_param(ar, addr, arvif->vdev_id, | |
2046 | WMI_PEER_MIMO_PS_STATE, | |
2047 | ath12k_smps_map[smps]); | |
2048 | } | |
2049 | ||
2050 | static void ath12k_bss_assoc(struct ieee80211_hw *hw, | |
2051 | struct ieee80211_vif *vif, | |
2052 | struct ieee80211_bss_conf *bss_conf) | |
2053 | { | |
2054 | struct ath12k *ar = hw->priv; | |
2055 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
2056 | struct ath12k_wmi_peer_assoc_arg peer_arg; | |
2057 | struct ieee80211_sta *ap_sta; | |
2058 | struct ath12k_peer *peer; | |
2059 | bool is_auth = false; | |
2060 | int ret; | |
2061 | ||
2062 | lockdep_assert_held(&ar->conf_mutex); | |
2063 | ||
2064 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", | |
2065 | arvif->vdev_id, arvif->bssid, arvif->aid); | |
2066 | ||
2067 | rcu_read_lock(); | |
2068 | ||
2069 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
2070 | if (!ap_sta) { | |
2071 | ath12k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n", | |
2072 | bss_conf->bssid, arvif->vdev_id); | |
2073 | rcu_read_unlock(); | |
2074 | return; | |
2075 | } | |
2076 | ||
2077 | ath12k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false); | |
2078 | ||
2079 | rcu_read_unlock(); | |
2080 | ||
2081 | ret = ath12k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
2082 | if (ret) { | |
2083 | ath12k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n", | |
2084 | bss_conf->bssid, arvif->vdev_id, ret); | |
2085 | return; | |
2086 | } | |
2087 | ||
2088 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
2089 | ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
2090 | bss_conf->bssid, arvif->vdev_id); | |
2091 | return; | |
2092 | } | |
2093 | ||
2094 | ret = ath12k_setup_peer_smps(ar, arvif, bss_conf->bssid, | |
2095 | &ap_sta->deflink.ht_cap); | |
2096 | if (ret) { | |
2097 | ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
2098 | arvif->vdev_id, ret); | |
2099 | return; | |
2100 | } | |
2101 | ||
2102 | WARN_ON(arvif->is_up); | |
2103 | ||
2104 | arvif->aid = vif->cfg.aid; | |
2105 | ether_addr_copy(arvif->bssid, bss_conf->bssid); | |
2106 | ||
2107 | ret = ath12k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); | |
2108 | if (ret) { | |
2109 | ath12k_warn(ar->ab, "failed to set vdev %d up: %d\n", | |
2110 | arvif->vdev_id, ret); | |
2111 | return; | |
2112 | } | |
2113 | ||
2114 | arvif->is_up = true; | |
2115 | ||
2116 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2117 | "mac vdev %d up (associated) bssid %pM aid %d\n", | |
2118 | arvif->vdev_id, bss_conf->bssid, vif->cfg.aid); | |
2119 | ||
2120 | spin_lock_bh(&ar->ab->base_lock); | |
2121 | ||
2122 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, arvif->bssid); | |
2123 | if (peer && peer->is_authorized) | |
2124 | is_auth = true; | |
2125 | ||
2126 | spin_unlock_bh(&ar->ab->base_lock); | |
2127 | ||
2128 | /* Authorize BSS Peer */ | |
2129 | if (is_auth) { | |
2130 | ret = ath12k_wmi_set_peer_param(ar, arvif->bssid, | |
2131 | arvif->vdev_id, | |
2132 | WMI_PEER_AUTHORIZE, | |
2133 | 1); | |
2134 | if (ret) | |
2135 | ath12k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret); | |
2136 | } | |
2137 | ||
2138 | ret = ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
2139 | &bss_conf->he_obss_pd); | |
2140 | if (ret) | |
2141 | ath12k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n", | |
2142 | arvif->vdev_id, ret); | |
2143 | } | |
2144 | ||
2145 | static void ath12k_bss_disassoc(struct ieee80211_hw *hw, | |
2146 | struct ieee80211_vif *vif) | |
2147 | { | |
2148 | struct ath12k *ar = hw->priv; | |
2149 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
2150 | int ret; | |
2151 | ||
2152 | lockdep_assert_held(&ar->conf_mutex); | |
2153 | ||
2154 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", | |
2155 | arvif->vdev_id, arvif->bssid); | |
2156 | ||
2157 | ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); | |
2158 | if (ret) | |
2159 | ath12k_warn(ar->ab, "failed to down vdev %i: %d\n", | |
2160 | arvif->vdev_id, ret); | |
2161 | ||
2162 | arvif->is_up = false; | |
2163 | ||
2164 | /* TODO: cancel connection_loss_work */ | |
2165 | } | |
2166 | ||
2167 | static u32 ath12k_mac_get_rate_hw_value(int bitrate) | |
2168 | { | |
2169 | u32 preamble; | |
2170 | u16 hw_value; | |
2171 | int rate; | |
2172 | size_t i; | |
2173 | ||
2174 | if (ath12k_mac_bitrate_is_cck(bitrate)) | |
2175 | preamble = WMI_RATE_PREAMBLE_CCK; | |
2176 | else | |
2177 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
2178 | ||
2179 | for (i = 0; i < ARRAY_SIZE(ath12k_legacy_rates); i++) { | |
2180 | if (ath12k_legacy_rates[i].bitrate != bitrate) | |
2181 | continue; | |
2182 | ||
2183 | hw_value = ath12k_legacy_rates[i].hw_value; | |
2184 | rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); | |
2185 | ||
2186 | return rate; | |
2187 | } | |
2188 | ||
2189 | return -EINVAL; | |
2190 | } | |
2191 | ||
2192 | static void ath12k_recalculate_mgmt_rate(struct ath12k *ar, | |
2193 | struct ieee80211_vif *vif, | |
2194 | struct cfg80211_chan_def *def) | |
2195 | { | |
2196 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
2197 | const struct ieee80211_supported_band *sband; | |
2198 | u8 basic_rate_idx; | |
2199 | int hw_rate_code; | |
2200 | u32 vdev_param; | |
2201 | u16 bitrate; | |
2202 | int ret; | |
2203 | ||
2204 | lockdep_assert_held(&ar->conf_mutex); | |
2205 | ||
2206 | sband = ar->hw->wiphy->bands[def->chan->band]; | |
2207 | basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1; | |
2208 | bitrate = sband->bitrates[basic_rate_idx].bitrate; | |
2209 | ||
2210 | hw_rate_code = ath12k_mac_get_rate_hw_value(bitrate); | |
2211 | if (hw_rate_code < 0) { | |
2212 | ath12k_warn(ar->ab, "bitrate not supported %d\n", bitrate); | |
2213 | return; | |
2214 | } | |
2215 | ||
2216 | vdev_param = WMI_VDEV_PARAM_MGMT_RATE; | |
2217 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, | |
2218 | hw_rate_code); | |
2219 | if (ret) | |
2220 | ath12k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret); | |
2221 | ||
2222 | vdev_param = WMI_VDEV_PARAM_BEACON_RATE; | |
2223 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, | |
2224 | hw_rate_code); | |
2225 | if (ret) | |
2226 | ath12k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret); | |
2227 | } | |
2228 | ||
2229 | static int ath12k_mac_fils_discovery(struct ath12k_vif *arvif, | |
2230 | struct ieee80211_bss_conf *info) | |
2231 | { | |
2232 | struct ath12k *ar = arvif->ar; | |
2233 | struct sk_buff *tmpl; | |
2234 | int ret; | |
2235 | u32 interval; | |
2236 | bool unsol_bcast_probe_resp_enabled = false; | |
2237 | ||
2238 | if (info->fils_discovery.max_interval) { | |
2239 | interval = info->fils_discovery.max_interval; | |
2240 | ||
2241 | tmpl = ieee80211_get_fils_discovery_tmpl(ar->hw, arvif->vif); | |
2242 | if (tmpl) | |
2243 | ret = ath12k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id, | |
2244 | tmpl); | |
2245 | } else if (info->unsol_bcast_probe_resp_interval) { | |
2246 | unsol_bcast_probe_resp_enabled = 1; | |
2247 | interval = info->unsol_bcast_probe_resp_interval; | |
2248 | ||
2249 | tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(ar->hw, | |
2250 | arvif->vif); | |
2251 | if (tmpl) | |
2252 | ret = ath12k_wmi_probe_resp_tmpl(ar, arvif->vdev_id, | |
2253 | tmpl); | |
2254 | } else { /* Disable */ | |
2255 | return ath12k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false); | |
2256 | } | |
2257 | ||
2258 | if (!tmpl) { | |
2259 | ath12k_warn(ar->ab, | |
2260 | "mac vdev %i failed to retrieve %s template\n", | |
2261 | arvif->vdev_id, (unsol_bcast_probe_resp_enabled ? | |
2262 | "unsolicited broadcast probe response" : | |
2263 | "FILS discovery")); | |
2264 | return -EPERM; | |
2265 | } | |
2266 | kfree_skb(tmpl); | |
2267 | ||
2268 | if (!ret) | |
2269 | ret = ath12k_wmi_fils_discovery(ar, arvif->vdev_id, interval, | |
2270 | unsol_bcast_probe_resp_enabled); | |
2271 | ||
2272 | return ret; | |
2273 | } | |
2274 | ||
2275 | static void ath12k_mac_op_bss_info_changed(struct ieee80211_hw *hw, | |
2276 | struct ieee80211_vif *vif, | |
2277 | struct ieee80211_bss_conf *info, | |
2278 | u64 changed) | |
2279 | { | |
2280 | struct ath12k *ar = hw->priv; | |
2281 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
2282 | struct cfg80211_chan_def def; | |
2283 | u32 param_id, param_value; | |
2284 | enum nl80211_band band; | |
2285 | u32 vdev_param; | |
2286 | int mcast_rate; | |
2287 | u32 preamble; | |
2288 | u16 hw_value; | |
2289 | u16 bitrate; | |
2290 | int ret; | |
2291 | u8 rateidx; | |
2292 | u32 rate; | |
2293 | ||
2294 | mutex_lock(&ar->conf_mutex); | |
2295 | ||
2296 | if (changed & BSS_CHANGED_BEACON_INT) { | |
2297 | arvif->beacon_interval = info->beacon_int; | |
2298 | ||
2299 | param_id = WMI_VDEV_PARAM_BEACON_INTERVAL; | |
2300 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2301 | param_id, | |
2302 | arvif->beacon_interval); | |
2303 | if (ret) | |
2304 | ath12k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n", | |
2305 | arvif->vdev_id); | |
2306 | else | |
2307 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2308 | "Beacon interval: %d set for VDEV: %d\n", | |
2309 | arvif->beacon_interval, arvif->vdev_id); | |
2310 | } | |
2311 | ||
2312 | if (changed & BSS_CHANGED_BEACON) { | |
2313 | param_id = WMI_PDEV_PARAM_BEACON_TX_MODE; | |
2314 | param_value = WMI_BEACON_STAGGERED_MODE; | |
2315 | ret = ath12k_wmi_pdev_set_param(ar, param_id, | |
2316 | param_value, ar->pdev->pdev_id); | |
2317 | if (ret) | |
2318 | ath12k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n", | |
2319 | arvif->vdev_id); | |
2320 | else | |
2321 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2322 | "Set staggered beacon mode for VDEV: %d\n", | |
2323 | arvif->vdev_id); | |
2324 | ||
2325 | ret = ath12k_mac_setup_bcn_tmpl(arvif); | |
2326 | if (ret) | |
2327 | ath12k_warn(ar->ab, "failed to update bcn template: %d\n", | |
2328 | ret); | |
2329 | } | |
2330 | ||
2331 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { | |
2332 | arvif->dtim_period = info->dtim_period; | |
2333 | ||
2334 | param_id = WMI_VDEV_PARAM_DTIM_PERIOD; | |
2335 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2336 | param_id, | |
2337 | arvif->dtim_period); | |
2338 | ||
2339 | if (ret) | |
2340 | ath12k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n", | |
2341 | arvif->vdev_id, ret); | |
2342 | else | |
2343 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2344 | "DTIM period: %d set for VDEV: %d\n", | |
2345 | arvif->dtim_period, arvif->vdev_id); | |
2346 | } | |
2347 | ||
2348 | if (changed & BSS_CHANGED_SSID && | |
2349 | vif->type == NL80211_IFTYPE_AP) { | |
2350 | arvif->u.ap.ssid_len = vif->cfg.ssid_len; | |
2351 | if (vif->cfg.ssid_len) | |
2352 | memcpy(arvif->u.ap.ssid, vif->cfg.ssid, vif->cfg.ssid_len); | |
2353 | arvif->u.ap.hidden_ssid = info->hidden_ssid; | |
2354 | } | |
2355 | ||
2356 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) | |
2357 | ether_addr_copy(arvif->bssid, info->bssid); | |
2358 | ||
2359 | if (changed & BSS_CHANGED_BEACON_ENABLED) { | |
2360 | ath12k_control_beaconing(arvif, info); | |
2361 | ||
2362 | if (arvif->is_up && vif->bss_conf.he_support && | |
2363 | vif->bss_conf.he_oper.params) { | |
2364 | /* TODO: Extend to support 1024 BA Bitmap size */ | |
2365 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2366 | WMI_VDEV_PARAM_BA_MODE, | |
2367 | WMI_BA_MODE_BUFFER_SIZE_256); | |
2368 | if (ret) | |
2369 | ath12k_warn(ar->ab, | |
2370 | "failed to set BA BUFFER SIZE 256 for vdev: %d\n", | |
2371 | arvif->vdev_id); | |
2372 | ||
2373 | param_id = WMI_VDEV_PARAM_HEOPS_0_31; | |
2374 | param_value = vif->bss_conf.he_oper.params; | |
2375 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2376 | param_id, param_value); | |
2377 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2378 | "he oper param: %x set for VDEV: %d\n", | |
2379 | param_value, arvif->vdev_id); | |
2380 | ||
2381 | if (ret) | |
2382 | ath12k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n", | |
2383 | param_value, arvif->vdev_id, ret); | |
2384 | } | |
2385 | } | |
2386 | ||
2387 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
2388 | u32 cts_prot; | |
2389 | ||
2390 | cts_prot = !!(info->use_cts_prot); | |
2391 | param_id = WMI_VDEV_PARAM_PROTECTION_MODE; | |
2392 | ||
2393 | if (arvif->is_started) { | |
2394 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2395 | param_id, cts_prot); | |
2396 | if (ret) | |
2397 | ath12k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n", | |
2398 | arvif->vdev_id); | |
2399 | else | |
2400 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n", | |
2401 | cts_prot, arvif->vdev_id); | |
2402 | } else { | |
2403 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n"); | |
2404 | } | |
2405 | } | |
2406 | ||
2407 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
2408 | u32 slottime; | |
2409 | ||
2410 | if (info->use_short_slot) | |
2411 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ | |
2412 | ||
2413 | else | |
2414 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ | |
2415 | ||
2416 | param_id = WMI_VDEV_PARAM_SLOT_TIME; | |
2417 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2418 | param_id, slottime); | |
2419 | if (ret) | |
2420 | ath12k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n", | |
2421 | arvif->vdev_id); | |
2422 | else | |
2423 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2424 | "Set slottime: %d for VDEV: %d\n", | |
2425 | slottime, arvif->vdev_id); | |
2426 | } | |
2427 | ||
2428 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
2429 | u32 preamble; | |
2430 | ||
2431 | if (info->use_short_preamble) | |
2432 | preamble = WMI_VDEV_PREAMBLE_SHORT; | |
2433 | else | |
2434 | preamble = WMI_VDEV_PREAMBLE_LONG; | |
2435 | ||
2436 | param_id = WMI_VDEV_PARAM_PREAMBLE; | |
2437 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2438 | param_id, preamble); | |
2439 | if (ret) | |
2440 | ath12k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n", | |
2441 | arvif->vdev_id); | |
2442 | else | |
2443 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2444 | "Set preamble: %d for VDEV: %d\n", | |
2445 | preamble, arvif->vdev_id); | |
2446 | } | |
2447 | ||
2448 | if (changed & BSS_CHANGED_ASSOC) { | |
2449 | if (vif->cfg.assoc) | |
2450 | ath12k_bss_assoc(hw, vif, info); | |
2451 | else | |
2452 | ath12k_bss_disassoc(hw, vif); | |
2453 | } | |
2454 | ||
2455 | if (changed & BSS_CHANGED_TXPOWER) { | |
2456 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac vdev_id %i txpower %d\n", | |
2457 | arvif->vdev_id, info->txpower); | |
2458 | ||
2459 | arvif->txpower = info->txpower; | |
2460 | ath12k_mac_txpower_recalc(ar); | |
2461 | } | |
2462 | ||
2463 | if (changed & BSS_CHANGED_MCAST_RATE && | |
2464 | !ath12k_mac_vif_chan(arvif->vif, &def)) { | |
2465 | band = def.chan->band; | |
2466 | mcast_rate = vif->bss_conf.mcast_rate[band]; | |
2467 | ||
2468 | if (mcast_rate > 0) | |
2469 | rateidx = mcast_rate - 1; | |
2470 | else | |
2471 | rateidx = ffs(vif->bss_conf.basic_rates) - 1; | |
2472 | ||
2473 | if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) | |
2474 | rateidx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
2475 | ||
2476 | bitrate = ath12k_legacy_rates[rateidx].bitrate; | |
2477 | hw_value = ath12k_legacy_rates[rateidx].hw_value; | |
2478 | ||
2479 | if (ath12k_mac_bitrate_is_cck(bitrate)) | |
2480 | preamble = WMI_RATE_PREAMBLE_CCK; | |
2481 | else | |
2482 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
2483 | ||
2484 | rate = ATH12K_HW_RATE_CODE(hw_value, 0, preamble); | |
2485 | ||
2486 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
2487 | "mac vdev %d mcast_rate %x\n", | |
2488 | arvif->vdev_id, rate); | |
2489 | ||
2490 | vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE; | |
2491 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2492 | vdev_param, rate); | |
2493 | if (ret) | |
2494 | ath12k_warn(ar->ab, | |
2495 | "failed to set mcast rate on vdev %i: %d\n", | |
2496 | arvif->vdev_id, ret); | |
2497 | ||
2498 | vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE; | |
2499 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
2500 | vdev_param, rate); | |
2501 | if (ret) | |
2502 | ath12k_warn(ar->ab, | |
2503 | "failed to set bcast rate on vdev %i: %d\n", | |
2504 | arvif->vdev_id, ret); | |
2505 | } | |
2506 | ||
2507 | if (changed & BSS_CHANGED_BASIC_RATES && | |
2508 | !ath12k_mac_vif_chan(arvif->vif, &def)) | |
2509 | ath12k_recalculate_mgmt_rate(ar, vif, &def); | |
2510 | ||
2511 | if (changed & BSS_CHANGED_TWT) { | |
2512 | if (info->twt_requester || info->twt_responder) | |
2513 | ath12k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id); | |
2514 | else | |
2515 | ath12k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id); | |
2516 | } | |
2517 | ||
2518 | if (changed & BSS_CHANGED_HE_OBSS_PD) | |
2519 | ath12k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
2520 | &info->he_obss_pd); | |
2521 | ||
2522 | if (changed & BSS_CHANGED_HE_BSS_COLOR) { | |
2523 | if (vif->type == NL80211_IFTYPE_AP) { | |
2524 | ret = ath12k_wmi_obss_color_cfg_cmd(ar, | |
2525 | arvif->vdev_id, | |
2526 | info->he_bss_color.color, | |
2527 | ATH12K_BSS_COLOR_AP_PERIODS, | |
2528 | info->he_bss_color.enabled); | |
2529 | if (ret) | |
2530 | ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", | |
2531 | arvif->vdev_id, ret); | |
2532 | } else if (vif->type == NL80211_IFTYPE_STATION) { | |
2533 | ret = ath12k_wmi_send_bss_color_change_enable_cmd(ar, | |
2534 | arvif->vdev_id, | |
2535 | 1); | |
2536 | if (ret) | |
2537 | ath12k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n", | |
2538 | arvif->vdev_id, ret); | |
2539 | ret = ath12k_wmi_obss_color_cfg_cmd(ar, | |
2540 | arvif->vdev_id, | |
2541 | 0, | |
2542 | ATH12K_BSS_COLOR_STA_PERIODS, | |
2543 | 1); | |
2544 | if (ret) | |
2545 | ath12k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n", | |
2546 | arvif->vdev_id, ret); | |
2547 | } | |
2548 | } | |
2549 | ||
2550 | if (changed & BSS_CHANGED_FILS_DISCOVERY || | |
2551 | changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP) | |
2552 | ath12k_mac_fils_discovery(arvif, info); | |
2553 | ||
2554 | mutex_unlock(&ar->conf_mutex); | |
2555 | } | |
2556 | ||
2557 | void __ath12k_mac_scan_finish(struct ath12k *ar) | |
2558 | { | |
2559 | lockdep_assert_held(&ar->data_lock); | |
2560 | ||
2561 | switch (ar->scan.state) { | |
2562 | case ATH12K_SCAN_IDLE: | |
2563 | break; | |
2564 | case ATH12K_SCAN_RUNNING: | |
2565 | case ATH12K_SCAN_ABORTING: | |
2566 | if (!ar->scan.is_roc) { | |
2567 | struct cfg80211_scan_info info = { | |
2568 | .aborted = (ar->scan.state == | |
2569 | ATH12K_SCAN_ABORTING), | |
2570 | }; | |
2571 | ||
2572 | ieee80211_scan_completed(ar->hw, &info); | |
2573 | } else if (ar->scan.roc_notify) { | |
2574 | ieee80211_remain_on_channel_expired(ar->hw); | |
2575 | } | |
2576 | fallthrough; | |
2577 | case ATH12K_SCAN_STARTING: | |
2578 | ar->scan.state = ATH12K_SCAN_IDLE; | |
2579 | ar->scan_channel = NULL; | |
2580 | ar->scan.roc_freq = 0; | |
2581 | cancel_delayed_work(&ar->scan.timeout); | |
2582 | complete(&ar->scan.completed); | |
2583 | break; | |
2584 | } | |
2585 | } | |
2586 | ||
2587 | void ath12k_mac_scan_finish(struct ath12k *ar) | |
2588 | { | |
2589 | spin_lock_bh(&ar->data_lock); | |
2590 | __ath12k_mac_scan_finish(ar); | |
2591 | spin_unlock_bh(&ar->data_lock); | |
2592 | } | |
2593 | ||
2594 | static int ath12k_scan_stop(struct ath12k *ar) | |
2595 | { | |
2596 | struct ath12k_wmi_scan_cancel_arg arg = { | |
2597 | .req_type = WLAN_SCAN_CANCEL_SINGLE, | |
2598 | .scan_id = ATH12K_SCAN_ID, | |
2599 | }; | |
2600 | int ret; | |
2601 | ||
2602 | lockdep_assert_held(&ar->conf_mutex); | |
2603 | ||
2604 | /* TODO: Fill other STOP Params */ | |
2605 | arg.pdev_id = ar->pdev->pdev_id; | |
2606 | ||
2607 | ret = ath12k_wmi_send_scan_stop_cmd(ar, &arg); | |
2608 | if (ret) { | |
2609 | ath12k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret); | |
2610 | goto out; | |
2611 | } | |
2612 | ||
2613 | ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); | |
2614 | if (ret == 0) { | |
2615 | ath12k_warn(ar->ab, | |
2616 | "failed to receive scan abort comple: timed out\n"); | |
2617 | ret = -ETIMEDOUT; | |
2618 | } else if (ret > 0) { | |
2619 | ret = 0; | |
2620 | } | |
2621 | ||
2622 | out: | |
2623 | /* Scan state should be updated upon scan completion but in case | |
2624 | * firmware fails to deliver the event (for whatever reason) it is | |
2625 | * desired to clean up scan state anyway. Firmware may have just | |
2626 | * dropped the scan completion event delivery due to transport pipe | |
2627 | * being overflown with data and/or it can recover on its own before | |
2628 | * next scan request is submitted. | |
2629 | */ | |
2630 | spin_lock_bh(&ar->data_lock); | |
2631 | if (ar->scan.state != ATH12K_SCAN_IDLE) | |
2632 | __ath12k_mac_scan_finish(ar); | |
2633 | spin_unlock_bh(&ar->data_lock); | |
2634 | ||
2635 | return ret; | |
2636 | } | |
2637 | ||
2638 | static void ath12k_scan_abort(struct ath12k *ar) | |
2639 | { | |
2640 | int ret; | |
2641 | ||
2642 | lockdep_assert_held(&ar->conf_mutex); | |
2643 | ||
2644 | spin_lock_bh(&ar->data_lock); | |
2645 | ||
2646 | switch (ar->scan.state) { | |
2647 | case ATH12K_SCAN_IDLE: | |
2648 | /* This can happen if timeout worker kicked in and called | |
2649 | * abortion while scan completion was being processed. | |
2650 | */ | |
2651 | break; | |
2652 | case ATH12K_SCAN_STARTING: | |
2653 | case ATH12K_SCAN_ABORTING: | |
2654 | ath12k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n", | |
2655 | ar->scan.state); | |
2656 | break; | |
2657 | case ATH12K_SCAN_RUNNING: | |
2658 | ar->scan.state = ATH12K_SCAN_ABORTING; | |
2659 | spin_unlock_bh(&ar->data_lock); | |
2660 | ||
2661 | ret = ath12k_scan_stop(ar); | |
2662 | if (ret) | |
2663 | ath12k_warn(ar->ab, "failed to abort scan: %d\n", ret); | |
2664 | ||
2665 | spin_lock_bh(&ar->data_lock); | |
2666 | break; | |
2667 | } | |
2668 | ||
2669 | spin_unlock_bh(&ar->data_lock); | |
2670 | } | |
2671 | ||
2672 | static void ath12k_scan_timeout_work(struct work_struct *work) | |
2673 | { | |
2674 | struct ath12k *ar = container_of(work, struct ath12k, | |
2675 | scan.timeout.work); | |
2676 | ||
2677 | mutex_lock(&ar->conf_mutex); | |
2678 | ath12k_scan_abort(ar); | |
2679 | mutex_unlock(&ar->conf_mutex); | |
2680 | } | |
2681 | ||
2682 | static int ath12k_start_scan(struct ath12k *ar, | |
2683 | struct ath12k_wmi_scan_req_arg *arg) | |
2684 | { | |
2685 | int ret; | |
2686 | ||
2687 | lockdep_assert_held(&ar->conf_mutex); | |
2688 | ||
2689 | ret = ath12k_wmi_send_scan_start_cmd(ar, arg); | |
2690 | if (ret) | |
2691 | return ret; | |
2692 | ||
2693 | ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); | |
2694 | if (ret == 0) { | |
2695 | ret = ath12k_scan_stop(ar); | |
2696 | if (ret) | |
2697 | ath12k_warn(ar->ab, "failed to stop scan: %d\n", ret); | |
2698 | ||
2699 | return -ETIMEDOUT; | |
2700 | } | |
2701 | ||
2702 | /* If we failed to start the scan, return error code at | |
2703 | * this point. This is probably due to some issue in the | |
2704 | * firmware, but no need to wedge the driver due to that... | |
2705 | */ | |
2706 | spin_lock_bh(&ar->data_lock); | |
2707 | if (ar->scan.state == ATH12K_SCAN_IDLE) { | |
2708 | spin_unlock_bh(&ar->data_lock); | |
2709 | return -EINVAL; | |
2710 | } | |
2711 | spin_unlock_bh(&ar->data_lock); | |
2712 | ||
2713 | return 0; | |
2714 | } | |
2715 | ||
2716 | static int ath12k_mac_op_hw_scan(struct ieee80211_hw *hw, | |
2717 | struct ieee80211_vif *vif, | |
2718 | struct ieee80211_scan_request *hw_req) | |
2719 | { | |
2720 | struct ath12k *ar = hw->priv; | |
2721 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
2722 | struct cfg80211_scan_request *req = &hw_req->req; | |
2723 | struct ath12k_wmi_scan_req_arg arg = {}; | |
2724 | int ret; | |
2725 | int i; | |
2726 | ||
2727 | mutex_lock(&ar->conf_mutex); | |
2728 | ||
2729 | spin_lock_bh(&ar->data_lock); | |
2730 | switch (ar->scan.state) { | |
2731 | case ATH12K_SCAN_IDLE: | |
2732 | reinit_completion(&ar->scan.started); | |
2733 | reinit_completion(&ar->scan.completed); | |
2734 | ar->scan.state = ATH12K_SCAN_STARTING; | |
2735 | ar->scan.is_roc = false; | |
2736 | ar->scan.vdev_id = arvif->vdev_id; | |
2737 | ret = 0; | |
2738 | break; | |
2739 | case ATH12K_SCAN_STARTING: | |
2740 | case ATH12K_SCAN_RUNNING: | |
2741 | case ATH12K_SCAN_ABORTING: | |
2742 | ret = -EBUSY; | |
2743 | break; | |
2744 | } | |
2745 | spin_unlock_bh(&ar->data_lock); | |
2746 | ||
2747 | if (ret) | |
2748 | goto exit; | |
2749 | ||
2750 | ath12k_wmi_start_scan_init(ar, &arg); | |
2751 | arg.vdev_id = arvif->vdev_id; | |
2752 | arg.scan_id = ATH12K_SCAN_ID; | |
2753 | ||
2754 | if (req->ie_len) { | |
2755 | arg.extraie.len = req->ie_len; | |
2756 | arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL); | |
2757 | memcpy(arg.extraie.ptr, req->ie, req->ie_len); | |
2758 | } | |
2759 | ||
2760 | if (req->n_ssids) { | |
2761 | arg.num_ssids = req->n_ssids; | |
2762 | for (i = 0; i < arg.num_ssids; i++) | |
2763 | arg.ssid[i] = req->ssids[i]; | |
2764 | } else { | |
2765 | arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE; | |
2766 | } | |
2767 | ||
2768 | if (req->n_channels) { | |
2769 | arg.num_chan = req->n_channels; | |
2770 | for (i = 0; i < arg.num_chan; i++) | |
2771 | arg.chan_list[i] = req->channels[i]->center_freq; | |
2772 | } | |
2773 | ||
2774 | ret = ath12k_start_scan(ar, &arg); | |
2775 | if (ret) { | |
2776 | ath12k_warn(ar->ab, "failed to start hw scan: %d\n", ret); | |
2777 | spin_lock_bh(&ar->data_lock); | |
2778 | ar->scan.state = ATH12K_SCAN_IDLE; | |
2779 | spin_unlock_bh(&ar->data_lock); | |
2780 | } | |
2781 | ||
2782 | /* Add a margin to account for event/command processing */ | |
2783 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, | |
2784 | msecs_to_jiffies(arg.max_scan_time + | |
2785 | ATH12K_MAC_SCAN_TIMEOUT_MSECS)); | |
2786 | ||
2787 | exit: | |
2788 | if (req->ie_len) | |
2789 | kfree(arg.extraie.ptr); | |
2790 | ||
2791 | mutex_unlock(&ar->conf_mutex); | |
2792 | return ret; | |
2793 | } | |
2794 | ||
2795 | static void ath12k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw, | |
2796 | struct ieee80211_vif *vif) | |
2797 | { | |
2798 | struct ath12k *ar = hw->priv; | |
2799 | ||
2800 | mutex_lock(&ar->conf_mutex); | |
2801 | ath12k_scan_abort(ar); | |
2802 | mutex_unlock(&ar->conf_mutex); | |
2803 | ||
2804 | cancel_delayed_work_sync(&ar->scan.timeout); | |
2805 | } | |
2806 | ||
2807 | static int ath12k_install_key(struct ath12k_vif *arvif, | |
2808 | struct ieee80211_key_conf *key, | |
2809 | enum set_key_cmd cmd, | |
2810 | const u8 *macaddr, u32 flags) | |
2811 | { | |
2812 | int ret; | |
2813 | struct ath12k *ar = arvif->ar; | |
2814 | struct wmi_vdev_install_key_arg arg = { | |
2815 | .vdev_id = arvif->vdev_id, | |
2816 | .key_idx = key->keyidx, | |
2817 | .key_len = key->keylen, | |
2818 | .key_data = key->key, | |
2819 | .key_flags = flags, | |
2820 | .macaddr = macaddr, | |
2821 | }; | |
2822 | ||
2823 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
2824 | ||
2825 | reinit_completion(&ar->install_key_done); | |
2826 | ||
2827 | if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags)) | |
2828 | return 0; | |
2829 | ||
2830 | if (cmd == DISABLE_KEY) { | |
2831 | /* TODO: Check if FW expects value other than NONE for del */ | |
2832 | /* arg.key_cipher = WMI_CIPHER_NONE; */ | |
2833 | arg.key_len = 0; | |
2834 | arg.key_data = NULL; | |
2835 | goto install; | |
2836 | } | |
2837 | ||
2838 | switch (key->cipher) { | |
2839 | case WLAN_CIPHER_SUITE_CCMP: | |
2840 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
2841 | /* TODO: Re-check if flag is valid */ | |
2842 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; | |
2843 | break; | |
2844 | case WLAN_CIPHER_SUITE_TKIP: | |
2845 | arg.key_cipher = WMI_CIPHER_TKIP; | |
2846 | arg.key_txmic_len = 8; | |
2847 | arg.key_rxmic_len = 8; | |
2848 | break; | |
2849 | case WLAN_CIPHER_SUITE_CCMP_256: | |
2850 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
2851 | break; | |
2852 | case WLAN_CIPHER_SUITE_GCMP: | |
2853 | case WLAN_CIPHER_SUITE_GCMP_256: | |
2854 | arg.key_cipher = WMI_CIPHER_AES_GCM; | |
2855 | break; | |
2856 | default: | |
2857 | ath12k_warn(ar->ab, "cipher %d is not supported\n", key->cipher); | |
2858 | return -EOPNOTSUPP; | |
2859 | } | |
2860 | ||
2861 | if (test_bit(ATH12K_FLAG_RAW_MODE, &ar->ab->dev_flags)) | |
2862 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV | | |
2863 | IEEE80211_KEY_FLAG_RESERVE_TAILROOM; | |
2864 | ||
2865 | install: | |
2866 | ret = ath12k_wmi_vdev_install_key(arvif->ar, &arg); | |
2867 | ||
2868 | if (ret) | |
2869 | return ret; | |
2870 | ||
2871 | if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ)) | |
2872 | return -ETIMEDOUT; | |
2873 | ||
2874 | if (ether_addr_equal(macaddr, arvif->vif->addr)) | |
2875 | arvif->key_cipher = key->cipher; | |
2876 | ||
2877 | return ar->install_key_status ? -EINVAL : 0; | |
2878 | } | |
2879 | ||
2880 | static int ath12k_clear_peer_keys(struct ath12k_vif *arvif, | |
2881 | const u8 *addr) | |
2882 | { | |
2883 | struct ath12k *ar = arvif->ar; | |
2884 | struct ath12k_base *ab = ar->ab; | |
2885 | struct ath12k_peer *peer; | |
2886 | int first_errno = 0; | |
2887 | int ret; | |
2888 | int i; | |
2889 | u32 flags = 0; | |
2890 | ||
2891 | lockdep_assert_held(&ar->conf_mutex); | |
2892 | ||
2893 | spin_lock_bh(&ab->base_lock); | |
2894 | peer = ath12k_peer_find(ab, arvif->vdev_id, addr); | |
2895 | spin_unlock_bh(&ab->base_lock); | |
2896 | ||
2897 | if (!peer) | |
2898 | return -ENOENT; | |
2899 | ||
2900 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
2901 | if (!peer->keys[i]) | |
2902 | continue; | |
2903 | ||
2904 | /* key flags are not required to delete the key */ | |
2905 | ret = ath12k_install_key(arvif, peer->keys[i], | |
2906 | DISABLE_KEY, addr, flags); | |
2907 | if (ret < 0 && first_errno == 0) | |
2908 | first_errno = ret; | |
2909 | ||
2910 | if (ret < 0) | |
2911 | ath12k_warn(ab, "failed to remove peer key %d: %d\n", | |
2912 | i, ret); | |
2913 | ||
2914 | spin_lock_bh(&ab->base_lock); | |
2915 | peer->keys[i] = NULL; | |
2916 | spin_unlock_bh(&ab->base_lock); | |
2917 | } | |
2918 | ||
2919 | return first_errno; | |
2920 | } | |
2921 | ||
2922 | static int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
2923 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
2924 | struct ieee80211_key_conf *key) | |
2925 | { | |
2926 | struct ath12k *ar = hw->priv; | |
2927 | struct ath12k_base *ab = ar->ab; | |
2928 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
2929 | struct ath12k_peer *peer; | |
2930 | struct ath12k_sta *arsta; | |
2931 | const u8 *peer_addr; | |
2932 | int ret = 0; | |
2933 | u32 flags = 0; | |
2934 | ||
2935 | /* BIP needs to be done in software */ | |
2936 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || | |
2937 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
2938 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || | |
2939 | key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) | |
2940 | return 1; | |
2941 | ||
2942 | if (test_bit(ATH12K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags)) | |
2943 | return 1; | |
2944 | ||
2945 | if (key->keyidx > WMI_MAX_KEY_INDEX) | |
2946 | return -ENOSPC; | |
2947 | ||
2948 | mutex_lock(&ar->conf_mutex); | |
2949 | ||
2950 | if (sta) | |
2951 | peer_addr = sta->addr; | |
2952 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
2953 | peer_addr = vif->bss_conf.bssid; | |
2954 | else | |
2955 | peer_addr = vif->addr; | |
2956 | ||
2957 | key->hw_key_idx = key->keyidx; | |
2958 | ||
2959 | /* the peer should not disappear in mid-way (unless FW goes awry) since | |
2960 | * we already hold conf_mutex. we just make sure its there now. | |
2961 | */ | |
2962 | spin_lock_bh(&ab->base_lock); | |
2963 | peer = ath12k_peer_find(ab, arvif->vdev_id, peer_addr); | |
2964 | spin_unlock_bh(&ab->base_lock); | |
2965 | ||
2966 | if (!peer) { | |
2967 | if (cmd == SET_KEY) { | |
2968 | ath12k_warn(ab, "cannot install key for non-existent peer %pM\n", | |
2969 | peer_addr); | |
2970 | ret = -EOPNOTSUPP; | |
2971 | goto exit; | |
2972 | } else { | |
2973 | /* if the peer doesn't exist there is no key to disable | |
2974 | * anymore | |
2975 | */ | |
2976 | goto exit; | |
2977 | } | |
2978 | } | |
2979 | ||
2980 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
2981 | flags |= WMI_KEY_PAIRWISE; | |
2982 | else | |
2983 | flags |= WMI_KEY_GROUP; | |
2984 | ||
2985 | ret = ath12k_install_key(arvif, key, cmd, peer_addr, flags); | |
2986 | if (ret) { | |
2987 | ath12k_warn(ab, "ath12k_install_key failed (%d)\n", ret); | |
2988 | goto exit; | |
2989 | } | |
2990 | ||
2991 | ret = ath12k_dp_rx_peer_pn_replay_config(arvif, peer_addr, cmd, key); | |
2992 | if (ret) { | |
2993 | ath12k_warn(ab, "failed to offload PN replay detection %d\n", ret); | |
2994 | goto exit; | |
2995 | } | |
2996 | ||
2997 | spin_lock_bh(&ab->base_lock); | |
2998 | peer = ath12k_peer_find(ab, arvif->vdev_id, peer_addr); | |
2999 | if (peer && cmd == SET_KEY) { | |
3000 | peer->keys[key->keyidx] = key; | |
3001 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { | |
3002 | peer->ucast_keyidx = key->keyidx; | |
3003 | peer->sec_type = ath12k_dp_tx_get_encrypt_type(key->cipher); | |
3004 | } else { | |
3005 | peer->mcast_keyidx = key->keyidx; | |
3006 | peer->sec_type_grp = ath12k_dp_tx_get_encrypt_type(key->cipher); | |
3007 | } | |
3008 | } else if (peer && cmd == DISABLE_KEY) { | |
3009 | peer->keys[key->keyidx] = NULL; | |
3010 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
3011 | peer->ucast_keyidx = 0; | |
3012 | else | |
3013 | peer->mcast_keyidx = 0; | |
3014 | } else if (!peer) | |
3015 | /* impossible unless FW goes crazy */ | |
3016 | ath12k_warn(ab, "peer %pM disappeared!\n", peer_addr); | |
3017 | ||
3018 | if (sta) { | |
3019 | arsta = (struct ath12k_sta *)sta->drv_priv; | |
3020 | ||
3021 | switch (key->cipher) { | |
3022 | case WLAN_CIPHER_SUITE_TKIP: | |
3023 | case WLAN_CIPHER_SUITE_CCMP: | |
3024 | case WLAN_CIPHER_SUITE_CCMP_256: | |
3025 | case WLAN_CIPHER_SUITE_GCMP: | |
3026 | case WLAN_CIPHER_SUITE_GCMP_256: | |
3027 | if (cmd == SET_KEY) | |
3028 | arsta->pn_type = HAL_PN_TYPE_WPA; | |
3029 | else | |
3030 | arsta->pn_type = HAL_PN_TYPE_NONE; | |
3031 | break; | |
3032 | default: | |
3033 | arsta->pn_type = HAL_PN_TYPE_NONE; | |
3034 | break; | |
3035 | } | |
3036 | } | |
3037 | ||
3038 | spin_unlock_bh(&ab->base_lock); | |
3039 | ||
3040 | exit: | |
3041 | mutex_unlock(&ar->conf_mutex); | |
3042 | return ret; | |
3043 | } | |
3044 | ||
3045 | static int | |
3046 | ath12k_mac_bitrate_mask_num_vht_rates(struct ath12k *ar, | |
3047 | enum nl80211_band band, | |
3048 | const struct cfg80211_bitrate_mask *mask) | |
3049 | { | |
3050 | int num_rates = 0; | |
3051 | int i; | |
3052 | ||
3053 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) | |
3054 | num_rates += hweight16(mask->control[band].vht_mcs[i]); | |
3055 | ||
3056 | return num_rates; | |
3057 | } | |
3058 | ||
3059 | static int | |
3060 | ath12k_mac_set_peer_vht_fixed_rate(struct ath12k_vif *arvif, | |
3061 | struct ieee80211_sta *sta, | |
3062 | const struct cfg80211_bitrate_mask *mask, | |
3063 | enum nl80211_band band) | |
3064 | { | |
3065 | struct ath12k *ar = arvif->ar; | |
3066 | u8 vht_rate, nss; | |
3067 | u32 rate_code; | |
3068 | int ret, i; | |
3069 | ||
3070 | lockdep_assert_held(&ar->conf_mutex); | |
3071 | ||
3072 | nss = 0; | |
3073 | ||
3074 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
3075 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { | |
3076 | nss = i + 1; | |
3077 | vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1; | |
3078 | } | |
3079 | } | |
3080 | ||
3081 | if (!nss) { | |
3082 | ath12k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM", | |
3083 | sta->addr); | |
3084 | return -EINVAL; | |
3085 | } | |
3086 | ||
3087 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3088 | "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates", | |
3089 | sta->addr); | |
3090 | ||
3091 | rate_code = ATH12K_HW_RATE_CODE(vht_rate, nss - 1, | |
3092 | WMI_RATE_PREAMBLE_VHT); | |
3093 | ret = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3094 | arvif->vdev_id, | |
3095 | WMI_PEER_PARAM_FIXED_RATE, | |
3096 | rate_code); | |
3097 | if (ret) | |
3098 | ath12k_warn(ar->ab, | |
3099 | "failed to update STA %pM Fixed Rate %d: %d\n", | |
3100 | sta->addr, rate_code, ret); | |
3101 | ||
3102 | return ret; | |
3103 | } | |
3104 | ||
3105 | static int ath12k_station_assoc(struct ath12k *ar, | |
3106 | struct ieee80211_vif *vif, | |
3107 | struct ieee80211_sta *sta, | |
3108 | bool reassoc) | |
3109 | { | |
3110 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
3111 | struct ath12k_wmi_peer_assoc_arg peer_arg; | |
3112 | int ret; | |
3113 | struct cfg80211_chan_def def; | |
3114 | enum nl80211_band band; | |
3115 | struct cfg80211_bitrate_mask *mask; | |
3116 | u8 num_vht_rates; | |
3117 | ||
3118 | lockdep_assert_held(&ar->conf_mutex); | |
3119 | ||
3120 | if (WARN_ON(ath12k_mac_vif_chan(vif, &def))) | |
3121 | return -EPERM; | |
3122 | ||
3123 | band = def.chan->band; | |
3124 | mask = &arvif->bitrate_mask; | |
3125 | ||
3126 | ath12k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc); | |
3127 | ||
3128 | ret = ath12k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
3129 | if (ret) { | |
3130 | ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
3131 | sta->addr, arvif->vdev_id, ret); | |
3132 | return ret; | |
3133 | } | |
3134 | ||
3135 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
3136 | ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
3137 | sta->addr, arvif->vdev_id); | |
3138 | return -ETIMEDOUT; | |
3139 | } | |
3140 | ||
3141 | num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask); | |
3142 | ||
3143 | /* If single VHT rate is configured (by set_bitrate_mask()), | |
3144 | * peer_assoc will disable VHT. This is now enabled by a peer specific | |
3145 | * fixed param. | |
3146 | * Note that all other rates and NSS will be disabled for this peer. | |
3147 | */ | |
3148 | if (sta->deflink.vht_cap.vht_supported && num_vht_rates == 1) { | |
3149 | ret = ath12k_mac_set_peer_vht_fixed_rate(arvif, sta, mask, | |
3150 | band); | |
3151 | if (ret) | |
3152 | return ret; | |
3153 | } | |
3154 | ||
3155 | /* Re-assoc is run only to update supported rates for given station. It | |
3156 | * doesn't make much sense to reconfigure the peer completely. | |
3157 | */ | |
3158 | if (reassoc) | |
3159 | return 0; | |
3160 | ||
3161 | ret = ath12k_setup_peer_smps(ar, arvif, sta->addr, | |
3162 | &sta->deflink.ht_cap); | |
3163 | if (ret) { | |
3164 | ath12k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
3165 | arvif->vdev_id, ret); | |
3166 | return ret; | |
3167 | } | |
3168 | ||
3169 | if (!sta->wme) { | |
3170 | arvif->num_legacy_stations++; | |
3171 | ret = ath12k_recalc_rtscts_prot(arvif); | |
3172 | if (ret) | |
3173 | return ret; | |
3174 | } | |
3175 | ||
3176 | if (sta->wme && sta->uapsd_queues) { | |
3177 | ret = ath12k_peer_assoc_qos_ap(ar, arvif, sta); | |
3178 | if (ret) { | |
3179 | ath12k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n", | |
3180 | sta->addr, arvif->vdev_id, ret); | |
3181 | return ret; | |
3182 | } | |
3183 | } | |
3184 | ||
3185 | return 0; | |
3186 | } | |
3187 | ||
3188 | static int ath12k_station_disassoc(struct ath12k *ar, | |
3189 | struct ieee80211_vif *vif, | |
3190 | struct ieee80211_sta *sta) | |
3191 | { | |
3192 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
3193 | int ret; | |
3194 | ||
3195 | lockdep_assert_held(&ar->conf_mutex); | |
3196 | ||
3197 | if (!sta->wme) { | |
3198 | arvif->num_legacy_stations--; | |
3199 | ret = ath12k_recalc_rtscts_prot(arvif); | |
3200 | if (ret) | |
3201 | return ret; | |
3202 | } | |
3203 | ||
3204 | ret = ath12k_clear_peer_keys(arvif, sta->addr); | |
3205 | if (ret) { | |
3206 | ath12k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n", | |
3207 | arvif->vdev_id, ret); | |
3208 | return ret; | |
3209 | } | |
3210 | return 0; | |
3211 | } | |
3212 | ||
3213 | static void ath12k_sta_rc_update_wk(struct work_struct *wk) | |
3214 | { | |
3215 | struct ath12k *ar; | |
3216 | struct ath12k_vif *arvif; | |
3217 | struct ath12k_sta *arsta; | |
3218 | struct ieee80211_sta *sta; | |
3219 | struct cfg80211_chan_def def; | |
3220 | enum nl80211_band band; | |
3221 | const u8 *ht_mcs_mask; | |
3222 | const u16 *vht_mcs_mask; | |
cbc0008c | 3223 | u32 changed, bw, nss, smps, bw_prev; |
d8899132 KV |
3224 | int err, num_vht_rates; |
3225 | const struct cfg80211_bitrate_mask *mask; | |
3226 | struct ath12k_wmi_peer_assoc_arg peer_arg; | |
cbc0008c | 3227 | enum wmi_phy_mode peer_phymode; |
d8899132 KV |
3228 | |
3229 | arsta = container_of(wk, struct ath12k_sta, update_wk); | |
3230 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); | |
3231 | arvif = arsta->arvif; | |
3232 | ar = arvif->ar; | |
3233 | ||
3234 | if (WARN_ON(ath12k_mac_vif_chan(arvif->vif, &def))) | |
3235 | return; | |
3236 | ||
3237 | band = def.chan->band; | |
3238 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
3239 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
3240 | ||
3241 | spin_lock_bh(&ar->data_lock); | |
3242 | ||
3243 | changed = arsta->changed; | |
3244 | arsta->changed = 0; | |
3245 | ||
3246 | bw = arsta->bw; | |
cbc0008c | 3247 | bw_prev = arsta->bw_prev; |
d8899132 KV |
3248 | nss = arsta->nss; |
3249 | smps = arsta->smps; | |
3250 | ||
3251 | spin_unlock_bh(&ar->data_lock); | |
3252 | ||
3253 | mutex_lock(&ar->conf_mutex); | |
3254 | ||
3255 | nss = max_t(u32, 1, nss); | |
3256 | nss = min(nss, max(ath12k_mac_max_ht_nss(ht_mcs_mask), | |
3257 | ath12k_mac_max_vht_nss(vht_mcs_mask))); | |
3258 | ||
3259 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
cbc0008c AKS |
3260 | ath12k_peer_assoc_h_phymode(ar, arvif->vif, sta, &peer_arg); |
3261 | peer_phymode = peer_arg.peer_phymode; | |
3262 | ||
3263 | if (bw > bw_prev) { | |
3264 | /* Phymode shows maximum supported channel width, if we | |
3265 | * upgrade bandwidth then due to sanity check of firmware, | |
3266 | * we have to send WMI_PEER_PHYMODE followed by | |
3267 | * WMI_PEER_CHWIDTH | |
3268 | */ | |
3269 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth upgrade for sta %pM new %d old %d\n", | |
3270 | sta->addr, bw, bw_prev); | |
3271 | err = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3272 | arvif->vdev_id, WMI_PEER_PHYMODE, | |
3273 | peer_phymode); | |
3274 | if (err) { | |
3275 | ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", | |
3276 | sta->addr, peer_phymode, err); | |
3277 | goto err_rc_bw_changed; | |
3278 | } | |
3279 | err = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3280 | arvif->vdev_id, WMI_PEER_CHWIDTH, | |
3281 | bw); | |
3282 | if (err) | |
3283 | ath12k_warn(ar->ab, "failed to update STA %pM to peer bandwidth %d: %d\n", | |
3284 | sta->addr, bw, err); | |
3285 | } else { | |
3286 | /* When we downgrade bandwidth this will conflict with phymode | |
3287 | * and cause to trigger firmware crash. In this case we send | |
3288 | * WMI_PEER_CHWIDTH followed by WMI_PEER_PHYMODE | |
3289 | */ | |
3290 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac bandwidth downgrade for sta %pM new %d old %d\n", | |
3291 | sta->addr, bw, bw_prev); | |
3292 | err = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3293 | arvif->vdev_id, WMI_PEER_CHWIDTH, | |
3294 | bw); | |
3295 | if (err) { | |
3296 | ath12k_warn(ar->ab, "failed to update STA %pM peer to bandwidth %d: %d\n", | |
3297 | sta->addr, bw, err); | |
3298 | goto err_rc_bw_changed; | |
3299 | } | |
3300 | err = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3301 | arvif->vdev_id, WMI_PEER_PHYMODE, | |
3302 | peer_phymode); | |
3303 | if (err) | |
3304 | ath12k_warn(ar->ab, "failed to update STA %pM to peer phymode %d: %d\n", | |
3305 | sta->addr, peer_phymode, err); | |
3306 | } | |
d8899132 KV |
3307 | } |
3308 | ||
3309 | if (changed & IEEE80211_RC_NSS_CHANGED) { | |
3310 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM nss %d\n", | |
3311 | sta->addr, nss); | |
3312 | ||
3313 | err = ath12k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
3314 | WMI_PEER_NSS, nss); | |
3315 | if (err) | |
3316 | ath12k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n", | |
3317 | sta->addr, nss, err); | |
3318 | } | |
3319 | ||
3320 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
3321 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac update sta %pM smps %d\n", | |
3322 | sta->addr, smps); | |
3323 | ||
3324 | err = ath12k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
3325 | WMI_PEER_MIMO_PS_STATE, smps); | |
3326 | if (err) | |
3327 | ath12k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n", | |
3328 | sta->addr, smps, err); | |
3329 | } | |
3330 | ||
3331 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { | |
3332 | mask = &arvif->bitrate_mask; | |
3333 | num_vht_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, | |
3334 | mask); | |
3335 | ||
3336 | /* Peer_assoc_prepare will reject vht rates in | |
3337 | * bitrate_mask if its not available in range format and | |
3338 | * sets vht tx_rateset as unsupported. So multiple VHT MCS | |
3339 | * setting(eg. MCS 4,5,6) per peer is not supported here. | |
3340 | * But, Single rate in VHT mask can be set as per-peer | |
3341 | * fixed rate. But even if any HT rates are configured in | |
3342 | * the bitrate mask, device will not switch to those rates | |
3343 | * when per-peer Fixed rate is set. | |
3344 | * TODO: Check RATEMASK_CMDID to support auto rates selection | |
3345 | * across HT/VHT and for multiple VHT MCS support. | |
3346 | */ | |
3347 | if (sta->deflink.vht_cap.vht_supported && num_vht_rates == 1) { | |
3348 | ath12k_mac_set_peer_vht_fixed_rate(arvif, sta, mask, | |
3349 | band); | |
3350 | } else { | |
3351 | /* If the peer is non-VHT or no fixed VHT rate | |
3352 | * is provided in the new bitrate mask we set the | |
3353 | * other rates using peer_assoc command. | |
3354 | */ | |
3355 | ath12k_peer_assoc_prepare(ar, arvif->vif, sta, | |
3356 | &peer_arg, true); | |
3357 | ||
3358 | err = ath12k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
3359 | if (err) | |
3360 | ath12k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
3361 | sta->addr, arvif->vdev_id, err); | |
3362 | ||
3363 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) | |
3364 | ath12k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
3365 | sta->addr, arvif->vdev_id); | |
3366 | } | |
3367 | } | |
cbc0008c | 3368 | err_rc_bw_changed: |
d8899132 KV |
3369 | mutex_unlock(&ar->conf_mutex); |
3370 | } | |
3371 | ||
3372 | static int ath12k_mac_inc_num_stations(struct ath12k_vif *arvif, | |
3373 | struct ieee80211_sta *sta) | |
3374 | { | |
3375 | struct ath12k *ar = arvif->ar; | |
3376 | ||
3377 | lockdep_assert_held(&ar->conf_mutex); | |
3378 | ||
3379 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) | |
3380 | return 0; | |
3381 | ||
3382 | if (ar->num_stations >= ar->max_num_stations) | |
3383 | return -ENOBUFS; | |
3384 | ||
3385 | ar->num_stations++; | |
3386 | ||
3387 | return 0; | |
3388 | } | |
3389 | ||
3390 | static void ath12k_mac_dec_num_stations(struct ath12k_vif *arvif, | |
3391 | struct ieee80211_sta *sta) | |
3392 | { | |
3393 | struct ath12k *ar = arvif->ar; | |
3394 | ||
3395 | lockdep_assert_held(&ar->conf_mutex); | |
3396 | ||
3397 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) | |
3398 | return; | |
3399 | ||
3400 | ar->num_stations--; | |
3401 | } | |
3402 | ||
3403 | static int ath12k_mac_station_add(struct ath12k *ar, | |
3404 | struct ieee80211_vif *vif, | |
3405 | struct ieee80211_sta *sta) | |
3406 | { | |
3407 | struct ath12k_base *ab = ar->ab; | |
3408 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
3409 | struct ath12k_sta *arsta = (struct ath12k_sta *)sta->drv_priv; | |
3410 | struct ath12k_wmi_peer_create_arg peer_param; | |
3411 | int ret; | |
3412 | ||
3413 | lockdep_assert_held(&ar->conf_mutex); | |
3414 | ||
3415 | ret = ath12k_mac_inc_num_stations(arvif, sta); | |
3416 | if (ret) { | |
3417 | ath12k_warn(ab, "refusing to associate station: too many connected already (%d)\n", | |
3418 | ar->max_num_stations); | |
3419 | goto exit; | |
3420 | } | |
3421 | ||
3422 | arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL); | |
3423 | if (!arsta->rx_stats) { | |
3424 | ret = -ENOMEM; | |
3425 | goto dec_num_station; | |
3426 | } | |
3427 | ||
3428 | peer_param.vdev_id = arvif->vdev_id; | |
3429 | peer_param.peer_addr = sta->addr; | |
3430 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
3431 | ||
3432 | ret = ath12k_peer_create(ar, arvif, sta, &peer_param); | |
3433 | if (ret) { | |
3434 | ath12k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n", | |
3435 | sta->addr, arvif->vdev_id); | |
3436 | goto free_peer; | |
3437 | } | |
3438 | ||
3439 | ath12k_dbg(ab, ATH12K_DBG_MAC, "Added peer: %pM for VDEV: %d\n", | |
3440 | sta->addr, arvif->vdev_id); | |
3441 | ||
3442 | if (ieee80211_vif_is_mesh(vif)) { | |
3443 | ret = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3444 | arvif->vdev_id, | |
3445 | WMI_PEER_USE_4ADDR, 1); | |
3446 | if (ret) { | |
3447 | ath12k_warn(ab, "failed to STA %pM 4addr capability: %d\n", | |
3448 | sta->addr, ret); | |
3449 | goto free_peer; | |
3450 | } | |
3451 | } | |
3452 | ||
3453 | ret = ath12k_dp_peer_setup(ar, arvif->vdev_id, sta->addr); | |
3454 | if (ret) { | |
3455 | ath12k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n", | |
3456 | sta->addr, arvif->vdev_id, ret); | |
3457 | goto free_peer; | |
3458 | } | |
3459 | ||
3460 | if (ab->hw_params->vdev_start_delay && | |
3461 | !arvif->is_started && | |
3462 | arvif->vdev_type != WMI_VDEV_TYPE_AP) { | |
3463 | ret = ath12k_start_vdev_delay(ar->hw, vif); | |
3464 | if (ret) { | |
3465 | ath12k_warn(ab, "failed to delay vdev start: %d\n", ret); | |
3466 | goto free_peer; | |
3467 | } | |
3468 | } | |
3469 | ||
3470 | return 0; | |
3471 | ||
3472 | free_peer: | |
3473 | ath12k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
3474 | dec_num_station: | |
3475 | ath12k_mac_dec_num_stations(arvif, sta); | |
3476 | exit: | |
3477 | return ret; | |
3478 | } | |
3479 | ||
cbc0008c AKS |
3480 | static u32 ath12k_mac_ieee80211_sta_bw_to_wmi(struct ath12k *ar, |
3481 | struct ieee80211_sta *sta) | |
3482 | { | |
3483 | u32 bw = WMI_PEER_CHWIDTH_20MHZ; | |
3484 | ||
3485 | switch (sta->deflink.bandwidth) { | |
3486 | case IEEE80211_STA_RX_BW_20: | |
3487 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
3488 | break; | |
3489 | case IEEE80211_STA_RX_BW_40: | |
3490 | bw = WMI_PEER_CHWIDTH_40MHZ; | |
3491 | break; | |
3492 | case IEEE80211_STA_RX_BW_80: | |
3493 | bw = WMI_PEER_CHWIDTH_80MHZ; | |
3494 | break; | |
3495 | case IEEE80211_STA_RX_BW_160: | |
3496 | bw = WMI_PEER_CHWIDTH_160MHZ; | |
3497 | break; | |
3498 | default: | |
3499 | ath12k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n", | |
3500 | sta->deflink.bandwidth, sta->addr); | |
3501 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
3502 | break; | |
3503 | } | |
3504 | ||
3505 | return bw; | |
3506 | } | |
3507 | ||
d8899132 KV |
3508 | static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, |
3509 | struct ieee80211_vif *vif, | |
3510 | struct ieee80211_sta *sta, | |
3511 | enum ieee80211_sta_state old_state, | |
3512 | enum ieee80211_sta_state new_state) | |
3513 | { | |
3514 | struct ath12k *ar = hw->priv; | |
3515 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
3516 | struct ath12k_sta *arsta = (struct ath12k_sta *)sta->drv_priv; | |
3517 | struct ath12k_peer *peer; | |
3518 | int ret = 0; | |
3519 | ||
3520 | /* cancel must be done outside the mutex to avoid deadlock */ | |
3521 | if ((old_state == IEEE80211_STA_NONE && | |
3522 | new_state == IEEE80211_STA_NOTEXIST)) | |
3523 | cancel_work_sync(&arsta->update_wk); | |
3524 | ||
3525 | mutex_lock(&ar->conf_mutex); | |
3526 | ||
3527 | if (old_state == IEEE80211_STA_NOTEXIST && | |
3528 | new_state == IEEE80211_STA_NONE) { | |
3529 | memset(arsta, 0, sizeof(*arsta)); | |
3530 | arsta->arvif = arvif; | |
3531 | INIT_WORK(&arsta->update_wk, ath12k_sta_rc_update_wk); | |
3532 | ||
3533 | ret = ath12k_mac_station_add(ar, vif, sta); | |
3534 | if (ret) | |
3535 | ath12k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n", | |
3536 | sta->addr, arvif->vdev_id); | |
3537 | } else if ((old_state == IEEE80211_STA_NONE && | |
3538 | new_state == IEEE80211_STA_NOTEXIST)) { | |
3539 | ath12k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr); | |
3540 | ||
3541 | ret = ath12k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
3542 | if (ret) | |
3543 | ath12k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n", | |
3544 | sta->addr, arvif->vdev_id); | |
3545 | else | |
3546 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n", | |
3547 | sta->addr, arvif->vdev_id); | |
3548 | ||
3549 | ath12k_mac_dec_num_stations(arvif, sta); | |
3550 | spin_lock_bh(&ar->ab->base_lock); | |
3551 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, sta->addr); | |
3552 | if (peer && peer->sta == sta) { | |
3553 | ath12k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n", | |
3554 | vif->addr, arvif->vdev_id); | |
3555 | peer->sta = NULL; | |
3556 | list_del(&peer->list); | |
3557 | kfree(peer); | |
3558 | ar->num_peers--; | |
3559 | } | |
3560 | spin_unlock_bh(&ar->ab->base_lock); | |
3561 | ||
3562 | kfree(arsta->rx_stats); | |
3563 | arsta->rx_stats = NULL; | |
3564 | } else if (old_state == IEEE80211_STA_AUTH && | |
3565 | new_state == IEEE80211_STA_ASSOC && | |
3566 | (vif->type == NL80211_IFTYPE_AP || | |
3567 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
3568 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
3569 | ret = ath12k_station_assoc(ar, vif, sta, false); | |
3570 | if (ret) | |
3571 | ath12k_warn(ar->ab, "Failed to associate station: %pM\n", | |
3572 | sta->addr); | |
cbc0008c AKS |
3573 | |
3574 | spin_lock_bh(&ar->data_lock); | |
3575 | ||
3576 | arsta->bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, sta); | |
3577 | arsta->bw_prev = sta->deflink.bandwidth; | |
3578 | ||
3579 | spin_unlock_bh(&ar->data_lock); | |
d8899132 KV |
3580 | } else if (old_state == IEEE80211_STA_ASSOC && |
3581 | new_state == IEEE80211_STA_AUTHORIZED) { | |
3582 | spin_lock_bh(&ar->ab->base_lock); | |
3583 | ||
3584 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, sta->addr); | |
3585 | if (peer) | |
3586 | peer->is_authorized = true; | |
3587 | ||
3588 | spin_unlock_bh(&ar->ab->base_lock); | |
3589 | ||
3590 | if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) { | |
3591 | ret = ath12k_wmi_set_peer_param(ar, sta->addr, | |
3592 | arvif->vdev_id, | |
3593 | WMI_PEER_AUTHORIZE, | |
3594 | 1); | |
3595 | if (ret) | |
3596 | ath12k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n", | |
3597 | sta->addr, arvif->vdev_id, ret); | |
3598 | } | |
3599 | } else if (old_state == IEEE80211_STA_AUTHORIZED && | |
3600 | new_state == IEEE80211_STA_ASSOC) { | |
3601 | spin_lock_bh(&ar->ab->base_lock); | |
3602 | ||
3603 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, sta->addr); | |
3604 | if (peer) | |
3605 | peer->is_authorized = false; | |
3606 | ||
3607 | spin_unlock_bh(&ar->ab->base_lock); | |
3608 | } else if (old_state == IEEE80211_STA_ASSOC && | |
3609 | new_state == IEEE80211_STA_AUTH && | |
3610 | (vif->type == NL80211_IFTYPE_AP || | |
3611 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
3612 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
3613 | ret = ath12k_station_disassoc(ar, vif, sta); | |
3614 | if (ret) | |
3615 | ath12k_warn(ar->ab, "Failed to disassociate station: %pM\n", | |
3616 | sta->addr); | |
3617 | } | |
3618 | ||
3619 | mutex_unlock(&ar->conf_mutex); | |
3620 | return ret; | |
3621 | } | |
3622 | ||
3623 | static int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw, | |
3624 | struct ieee80211_vif *vif, | |
3625 | struct ieee80211_sta *sta) | |
3626 | { | |
3627 | struct ath12k *ar = hw->priv; | |
3628 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
3629 | int ret; | |
3630 | s16 txpwr; | |
3631 | ||
3632 | if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) { | |
3633 | txpwr = 0; | |
3634 | } else { | |
3635 | txpwr = sta->deflink.txpwr.power; | |
3636 | if (!txpwr) | |
3637 | return -EINVAL; | |
3638 | } | |
3639 | ||
3640 | if (txpwr > ATH12K_TX_POWER_MAX_VAL || txpwr < ATH12K_TX_POWER_MIN_VAL) | |
3641 | return -EINVAL; | |
3642 | ||
3643 | mutex_lock(&ar->conf_mutex); | |
3644 | ||
3645 | ret = ath12k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
3646 | WMI_PEER_USE_FIXED_PWR, txpwr); | |
3647 | if (ret) { | |
3648 | ath12k_warn(ar->ab, "failed to set tx power for station ret: %d\n", | |
3649 | ret); | |
3650 | goto out; | |
3651 | } | |
3652 | ||
3653 | out: | |
3654 | mutex_unlock(&ar->conf_mutex); | |
3655 | return ret; | |
3656 | } | |
3657 | ||
3658 | static void ath12k_mac_op_sta_rc_update(struct ieee80211_hw *hw, | |
3659 | struct ieee80211_vif *vif, | |
3660 | struct ieee80211_sta *sta, | |
3661 | u32 changed) | |
3662 | { | |
3663 | struct ath12k *ar = hw->priv; | |
3664 | struct ath12k_sta *arsta = (struct ath12k_sta *)sta->drv_priv; | |
3665 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
3666 | struct ath12k_peer *peer; | |
3667 | u32 bw, smps; | |
3668 | ||
3669 | spin_lock_bh(&ar->ab->base_lock); | |
3670 | ||
3671 | peer = ath12k_peer_find(ar->ab, arvif->vdev_id, sta->addr); | |
3672 | if (!peer) { | |
3673 | spin_unlock_bh(&ar->ab->base_lock); | |
3674 | ath12k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n", | |
3675 | sta->addr, arvif->vdev_id); | |
3676 | return; | |
3677 | } | |
3678 | ||
3679 | spin_unlock_bh(&ar->ab->base_lock); | |
3680 | ||
3681 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
3682 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", | |
3683 | sta->addr, changed, sta->deflink.bandwidth, sta->deflink.rx_nss, | |
3684 | sta->deflink.smps_mode); | |
3685 | ||
3686 | spin_lock_bh(&ar->data_lock); | |
3687 | ||
3688 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
cbc0008c AKS |
3689 | bw = ath12k_mac_ieee80211_sta_bw_to_wmi(ar, sta); |
3690 | arsta->bw_prev = arsta->bw; | |
d8899132 KV |
3691 | arsta->bw = bw; |
3692 | } | |
3693 | ||
3694 | if (changed & IEEE80211_RC_NSS_CHANGED) | |
3695 | arsta->nss = sta->deflink.rx_nss; | |
3696 | ||
3697 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
3698 | smps = WMI_PEER_SMPS_PS_NONE; | |
3699 | ||
3700 | switch (sta->deflink.smps_mode) { | |
3701 | case IEEE80211_SMPS_AUTOMATIC: | |
3702 | case IEEE80211_SMPS_OFF: | |
3703 | smps = WMI_PEER_SMPS_PS_NONE; | |
3704 | break; | |
3705 | case IEEE80211_SMPS_STATIC: | |
3706 | smps = WMI_PEER_SMPS_STATIC; | |
3707 | break; | |
3708 | case IEEE80211_SMPS_DYNAMIC: | |
3709 | smps = WMI_PEER_SMPS_DYNAMIC; | |
3710 | break; | |
3711 | default: | |
3712 | ath12k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n", | |
3713 | sta->deflink.smps_mode, sta->addr); | |
3714 | smps = WMI_PEER_SMPS_PS_NONE; | |
3715 | break; | |
3716 | } | |
3717 | ||
3718 | arsta->smps = smps; | |
3719 | } | |
3720 | ||
3721 | arsta->changed |= changed; | |
3722 | ||
3723 | spin_unlock_bh(&ar->data_lock); | |
3724 | ||
3725 | ieee80211_queue_work(hw, &arsta->update_wk); | |
3726 | } | |
3727 | ||
3728 | static int ath12k_conf_tx_uapsd(struct ath12k *ar, struct ieee80211_vif *vif, | |
3729 | u16 ac, bool enable) | |
3730 | { | |
3731 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
3732 | u32 value; | |
3733 | int ret; | |
3734 | ||
3735 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) | |
3736 | return 0; | |
3737 | ||
3738 | switch (ac) { | |
3739 | case IEEE80211_AC_VO: | |
3740 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | | |
3741 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; | |
3742 | break; | |
3743 | case IEEE80211_AC_VI: | |
3744 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | | |
3745 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; | |
3746 | break; | |
3747 | case IEEE80211_AC_BE: | |
3748 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | | |
3749 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; | |
3750 | break; | |
3751 | case IEEE80211_AC_BK: | |
3752 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | | |
3753 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; | |
3754 | break; | |
3755 | } | |
3756 | ||
3757 | if (enable) | |
3758 | arvif->u.sta.uapsd |= value; | |
3759 | else | |
3760 | arvif->u.sta.uapsd &= ~value; | |
3761 | ||
3762 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3763 | WMI_STA_PS_PARAM_UAPSD, | |
3764 | arvif->u.sta.uapsd); | |
3765 | if (ret) { | |
3766 | ath12k_warn(ar->ab, "could not set uapsd params %d\n", ret); | |
3767 | goto exit; | |
3768 | } | |
3769 | ||
3770 | if (arvif->u.sta.uapsd) | |
3771 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; | |
3772 | else | |
3773 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
3774 | ||
3775 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3776 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, | |
3777 | value); | |
3778 | if (ret) | |
3779 | ath12k_warn(ar->ab, "could not set rx wake param %d\n", ret); | |
3780 | ||
3781 | exit: | |
3782 | return ret; | |
3783 | } | |
3784 | ||
3785 | static int ath12k_mac_op_conf_tx(struct ieee80211_hw *hw, | |
3786 | struct ieee80211_vif *vif, | |
3787 | unsigned int link_id, u16 ac, | |
3788 | const struct ieee80211_tx_queue_params *params) | |
3789 | { | |
3790 | struct ath12k *ar = hw->priv; | |
3791 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
3792 | struct wmi_wmm_params_arg *p = NULL; | |
3793 | int ret; | |
3794 | ||
3795 | mutex_lock(&ar->conf_mutex); | |
3796 | ||
3797 | switch (ac) { | |
3798 | case IEEE80211_AC_VO: | |
3799 | p = &arvif->wmm_params.ac_vo; | |
3800 | break; | |
3801 | case IEEE80211_AC_VI: | |
3802 | p = &arvif->wmm_params.ac_vi; | |
3803 | break; | |
3804 | case IEEE80211_AC_BE: | |
3805 | p = &arvif->wmm_params.ac_be; | |
3806 | break; | |
3807 | case IEEE80211_AC_BK: | |
3808 | p = &arvif->wmm_params.ac_bk; | |
3809 | break; | |
3810 | } | |
3811 | ||
3812 | if (WARN_ON(!p)) { | |
3813 | ret = -EINVAL; | |
3814 | goto exit; | |
3815 | } | |
3816 | ||
3817 | p->cwmin = params->cw_min; | |
3818 | p->cwmax = params->cw_max; | |
3819 | p->aifs = params->aifs; | |
3820 | p->txop = params->txop; | |
3821 | ||
3822 | ret = ath12k_wmi_send_wmm_update_cmd(ar, arvif->vdev_id, | |
3823 | &arvif->wmm_params); | |
3824 | if (ret) { | |
3825 | ath12k_warn(ar->ab, "failed to set wmm params: %d\n", ret); | |
3826 | goto exit; | |
3827 | } | |
3828 | ||
3829 | ret = ath12k_conf_tx_uapsd(ar, vif, ac, params->uapsd); | |
3830 | ||
3831 | if (ret) | |
3832 | ath12k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret); | |
3833 | ||
3834 | exit: | |
3835 | mutex_unlock(&ar->conf_mutex); | |
3836 | return ret; | |
3837 | } | |
3838 | ||
3839 | static struct ieee80211_sta_ht_cap | |
3840 | ath12k_create_ht_cap(struct ath12k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask) | |
3841 | { | |
3842 | int i; | |
3843 | struct ieee80211_sta_ht_cap ht_cap = {0}; | |
3844 | u32 ar_vht_cap = ar->pdev->cap.vht_cap; | |
3845 | ||
3846 | if (!(ar_ht_cap & WMI_HT_CAP_ENABLED)) | |
3847 | return ht_cap; | |
3848 | ||
3849 | ht_cap.ht_supported = 1; | |
3850 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
3851 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; | |
3852 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
3853 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
3854 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; | |
3855 | ||
3856 | if (ar_ht_cap & WMI_HT_CAP_HT20_SGI) | |
3857 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
3858 | ||
3859 | if (ar_ht_cap & WMI_HT_CAP_HT40_SGI) | |
3860 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
3861 | ||
3862 | if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) { | |
3863 | u32 smps; | |
3864 | ||
3865 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | |
3866 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
3867 | ||
3868 | ht_cap.cap |= smps; | |
3869 | } | |
3870 | ||
3871 | if (ar_ht_cap & WMI_HT_CAP_TX_STBC) | |
3872 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; | |
3873 | ||
3874 | if (ar_ht_cap & WMI_HT_CAP_RX_STBC) { | |
3875 | u32 stbc; | |
3876 | ||
3877 | stbc = ar_ht_cap; | |
3878 | stbc &= WMI_HT_CAP_RX_STBC; | |
3879 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; | |
3880 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
3881 | stbc &= IEEE80211_HT_CAP_RX_STBC; | |
3882 | ||
3883 | ht_cap.cap |= stbc; | |
3884 | } | |
3885 | ||
3886 | if (ar_ht_cap & WMI_HT_CAP_RX_LDPC) | |
3887 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; | |
3888 | ||
3889 | if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT) | |
3890 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; | |
3891 | ||
3892 | if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) | |
3893 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; | |
3894 | ||
3895 | for (i = 0; i < ar->num_rx_chains; i++) { | |
3896 | if (rate_cap_rx_chainmask & BIT(i)) | |
3897 | ht_cap.mcs.rx_mask[i] = 0xFF; | |
3898 | } | |
3899 | ||
3900 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; | |
3901 | ||
3902 | return ht_cap; | |
3903 | } | |
3904 | ||
3905 | static int ath12k_mac_set_txbf_conf(struct ath12k_vif *arvif) | |
3906 | { | |
3907 | u32 value = 0; | |
3908 | struct ath12k *ar = arvif->ar; | |
3909 | int nsts; | |
3910 | int sound_dim; | |
3911 | u32 vht_cap = ar->pdev->cap.vht_cap; | |
3912 | u32 vdev_param = WMI_VDEV_PARAM_TXBF; | |
3913 | ||
3914 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) { | |
3915 | nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
3916 | nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
3917 | value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); | |
3918 | } | |
3919 | ||
3920 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { | |
3921 | sound_dim = vht_cap & | |
3922 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3923 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3924 | if (sound_dim > (ar->num_tx_chains - 1)) | |
3925 | sound_dim = ar->num_tx_chains - 1; | |
3926 | value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); | |
3927 | } | |
3928 | ||
3929 | if (!value) | |
3930 | return 0; | |
3931 | ||
3932 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) { | |
3933 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
3934 | ||
3935 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && | |
3936 | arvif->vdev_type == WMI_VDEV_TYPE_AP) | |
3937 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; | |
3938 | } | |
3939 | ||
3940 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) { | |
3941 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
3942 | ||
3943 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && | |
3944 | arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
3945 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; | |
3946 | } | |
3947 | ||
3948 | return ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3949 | vdev_param, value); | |
3950 | } | |
3951 | ||
3952 | static void ath12k_set_vht_txbf_cap(struct ath12k *ar, u32 *vht_cap) | |
3953 | { | |
3954 | bool subfer, subfee; | |
3955 | int sound_dim = 0; | |
3956 | ||
3957 | subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)); | |
3958 | subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)); | |
3959 | ||
3960 | if (ar->num_tx_chains < 2) { | |
3961 | *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); | |
3962 | subfer = false; | |
3963 | } | |
3964 | ||
3965 | /* If SU Beaformer is not set, then disable MU Beamformer Capability */ | |
3966 | if (!subfer) | |
3967 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); | |
3968 | ||
3969 | /* If SU Beaformee is not set, then disable MU Beamformee Capability */ | |
3970 | if (!subfee) | |
3971 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); | |
3972 | ||
3973 | sound_dim = u32_get_bits(*vht_cap, | |
3974 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
3975 | *vht_cap = u32_replace_bits(*vht_cap, 0, | |
3976 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
3977 | ||
3978 | /* TODO: Need to check invalid STS and Sound_dim values set by FW? */ | |
3979 | ||
3980 | /* Enable Sounding Dimension Field only if SU BF is enabled */ | |
3981 | if (subfer) { | |
3982 | if (sound_dim > (ar->num_tx_chains - 1)) | |
3983 | sound_dim = ar->num_tx_chains - 1; | |
3984 | ||
3985 | *vht_cap = u32_replace_bits(*vht_cap, sound_dim, | |
3986 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
3987 | } | |
3988 | ||
3989 | /* Use the STS advertised by FW unless SU Beamformee is not supported*/ | |
3990 | if (!subfee) | |
3991 | *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); | |
3992 | } | |
3993 | ||
3994 | static struct ieee80211_sta_vht_cap | |
3995 | ath12k_create_vht_cap(struct ath12k *ar, u32 rate_cap_tx_chainmask, | |
3996 | u32 rate_cap_rx_chainmask) | |
3997 | { | |
3998 | struct ieee80211_sta_vht_cap vht_cap = {0}; | |
3999 | u16 txmcs_map, rxmcs_map; | |
4000 | int i; | |
4001 | ||
4002 | vht_cap.vht_supported = 1; | |
4003 | vht_cap.cap = ar->pdev->cap.vht_cap; | |
4004 | ||
4005 | ath12k_set_vht_txbf_cap(ar, &vht_cap.cap); | |
4006 | ||
4007 | /* TODO: Enable back VHT160 mode once association issues are fixed */ | |
4008 | /* Disabling VHT160 and VHT80+80 modes */ | |
4009 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; | |
4010 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; | |
4011 | ||
4012 | rxmcs_map = 0; | |
4013 | txmcs_map = 0; | |
4014 | for (i = 0; i < 8; i++) { | |
4015 | if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i)) | |
4016 | txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
4017 | else | |
4018 | txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
4019 | ||
4020 | if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i)) | |
4021 | rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
4022 | else | |
4023 | rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
4024 | } | |
4025 | ||
4026 | if (rate_cap_tx_chainmask <= 1) | |
4027 | vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; | |
4028 | ||
4029 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map); | |
4030 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map); | |
4031 | ||
4032 | return vht_cap; | |
4033 | } | |
4034 | ||
4035 | static void ath12k_mac_setup_ht_vht_cap(struct ath12k *ar, | |
4036 | struct ath12k_pdev_cap *cap, | |
4037 | u32 *ht_cap_info) | |
4038 | { | |
4039 | struct ieee80211_supported_band *band; | |
4040 | u32 rate_cap_tx_chainmask; | |
4041 | u32 rate_cap_rx_chainmask; | |
4042 | u32 ht_cap; | |
4043 | ||
4044 | rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift; | |
4045 | rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift; | |
4046 | ||
4047 | if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
4048 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
4049 | ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info; | |
4050 | if (ht_cap_info) | |
4051 | *ht_cap_info = ht_cap; | |
4052 | band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, | |
4053 | rate_cap_rx_chainmask); | |
4054 | } | |
4055 | ||
4056 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP && | |
4057 | (ar->ab->hw_params->single_pdev_only || | |
4058 | !ar->supports_6ghz)) { | |
4059 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
4060 | ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info; | |
4061 | if (ht_cap_info) | |
4062 | *ht_cap_info = ht_cap; | |
4063 | band->ht_cap = ath12k_create_ht_cap(ar, ht_cap, | |
4064 | rate_cap_rx_chainmask); | |
4065 | band->vht_cap = ath12k_create_vht_cap(ar, rate_cap_tx_chainmask, | |
4066 | rate_cap_rx_chainmask); | |
4067 | } | |
4068 | } | |
4069 | ||
4070 | static int ath12k_check_chain_mask(struct ath12k *ar, u32 ant, bool is_tx_ant) | |
4071 | { | |
4072 | /* TODO: Check the request chainmask against the supported | |
4073 | * chainmask table which is advertised in extented_service_ready event | |
4074 | */ | |
4075 | ||
4076 | return 0; | |
4077 | } | |
4078 | ||
4079 | static void ath12k_gen_ppe_thresh(struct ath12k_wmi_ppe_threshold_arg *fw_ppet, | |
4080 | u8 *he_ppet) | |
4081 | { | |
4082 | int nss, ru; | |
4083 | u8 bit = 7; | |
4084 | ||
4085 | he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK; | |
4086 | he_ppet[0] |= (fw_ppet->ru_bit_mask << | |
4087 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) & | |
4088 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK; | |
4089 | for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { | |
4090 | for (ru = 0; ru < 4; ru++) { | |
4091 | u8 val; | |
4092 | int i; | |
4093 | ||
4094 | if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) | |
4095 | continue; | |
4096 | val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) & | |
4097 | 0x3f; | |
4098 | val = ((val >> 3) & 0x7) | ((val & 0x7) << 3); | |
4099 | for (i = 5; i >= 0; i--) { | |
4100 | he_ppet[bit / 8] |= | |
4101 | ((val >> i) & 0x1) << ((bit % 8)); | |
4102 | bit++; | |
4103 | } | |
4104 | } | |
4105 | } | |
4106 | } | |
4107 | ||
4108 | static void | |
4109 | ath12k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem) | |
4110 | { | |
4111 | u8 m; | |
4112 | ||
4113 | m = IEEE80211_HE_MAC_CAP0_TWT_RES | | |
4114 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
4115 | he_cap_elem->mac_cap_info[0] &= ~m; | |
4116 | ||
4117 | m = IEEE80211_HE_MAC_CAP2_TRS | | |
4118 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
4119 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
4120 | he_cap_elem->mac_cap_info[2] &= ~m; | |
4121 | ||
4122 | m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED | | |
4123 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
4124 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
4125 | he_cap_elem->mac_cap_info[3] &= ~m; | |
4126 | ||
4127 | m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG | | |
4128 | IEEE80211_HE_MAC_CAP4_BQR; | |
4129 | he_cap_elem->mac_cap_info[4] &= ~m; | |
4130 | ||
4131 | m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION | | |
4132 | IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU | | |
4133 | IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING | | |
4134 | IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX; | |
4135 | he_cap_elem->mac_cap_info[5] &= ~m; | |
4136 | ||
4137 | m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4138 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; | |
4139 | he_cap_elem->phy_cap_info[2] &= ~m; | |
4140 | ||
4141 | m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU | | |
4142 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK | | |
4143 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK; | |
4144 | he_cap_elem->phy_cap_info[3] &= ~m; | |
4145 | ||
4146 | m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; | |
4147 | he_cap_elem->phy_cap_info[4] &= ~m; | |
4148 | ||
4149 | m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; | |
4150 | he_cap_elem->phy_cap_info[5] &= ~m; | |
4151 | ||
4152 | m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | | |
4153 | IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB | | |
4154 | IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | | |
4155 | IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; | |
4156 | he_cap_elem->phy_cap_info[6] &= ~m; | |
4157 | ||
4158 | m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR | | |
4159 | IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP | | |
4160 | IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | | |
4161 | IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; | |
4162 | he_cap_elem->phy_cap_info[7] &= ~m; | |
4163 | ||
4164 | m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | | |
4165 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | | |
4166 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | | |
4167 | IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU; | |
4168 | he_cap_elem->phy_cap_info[8] &= ~m; | |
4169 | ||
4170 | m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | | |
4171 | IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | | |
4172 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | | |
4173 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | | |
4174 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | | |
4175 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; | |
4176 | he_cap_elem->phy_cap_info[9] &= ~m; | |
4177 | } | |
4178 | ||
4179 | static __le16 ath12k_mac_setup_he_6ghz_cap(struct ath12k_pdev_cap *pcap, | |
4180 | struct ath12k_band_cap *bcap) | |
4181 | { | |
4182 | u8 val; | |
4183 | ||
4184 | bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE; | |
4185 | if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) | |
4186 | bcap->he_6ghz_capa |= | |
4187 | u32_encode_bits(WLAN_HT_CAP_SM_PS_DYNAMIC, | |
4188 | IEEE80211_HE_6GHZ_CAP_SM_PS); | |
4189 | else | |
4190 | bcap->he_6ghz_capa |= | |
4191 | u32_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED, | |
4192 | IEEE80211_HE_6GHZ_CAP_SM_PS); | |
4193 | val = u32_get_bits(pcap->vht_cap, | |
4194 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK); | |
4195 | bcap->he_6ghz_capa |= | |
4196 | u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); | |
4197 | val = u32_get_bits(pcap->vht_cap, | |
4198 | IEEE80211_VHT_CAP_MAX_MPDU_MASK); | |
4199 | bcap->he_6ghz_capa |= | |
4200 | u32_encode_bits(val, IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN); | |
4201 | if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN) | |
4202 | bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS; | |
4203 | if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN) | |
4204 | bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS; | |
4205 | ||
4206 | return cpu_to_le16(bcap->he_6ghz_capa); | |
4207 | } | |
4208 | ||
4209 | static int ath12k_mac_copy_he_cap(struct ath12k *ar, | |
4210 | struct ath12k_pdev_cap *cap, | |
4211 | struct ieee80211_sband_iftype_data *data, | |
4212 | int band) | |
4213 | { | |
4214 | int i, idx = 0; | |
4215 | ||
4216 | for (i = 0; i < NUM_NL80211_IFTYPES; i++) { | |
4217 | struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; | |
4218 | struct ath12k_band_cap *band_cap = &cap->band[band]; | |
4219 | struct ieee80211_he_cap_elem *he_cap_elem = | |
4220 | &he_cap->he_cap_elem; | |
4221 | ||
4222 | switch (i) { | |
4223 | case NL80211_IFTYPE_STATION: | |
4224 | case NL80211_IFTYPE_AP: | |
4225 | case NL80211_IFTYPE_MESH_POINT: | |
4226 | break; | |
4227 | ||
4228 | default: | |
4229 | continue; | |
4230 | } | |
4231 | ||
4232 | data[idx].types_mask = BIT(i); | |
4233 | he_cap->has_he = true; | |
4234 | memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info, | |
4235 | sizeof(he_cap_elem->mac_cap_info)); | |
4236 | memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info, | |
4237 | sizeof(he_cap_elem->phy_cap_info)); | |
4238 | ||
4239 | he_cap_elem->mac_cap_info[1] &= | |
4240 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK; | |
4241 | ||
4242 | he_cap_elem->phy_cap_info[5] &= | |
4243 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK; | |
4244 | he_cap_elem->phy_cap_info[5] &= | |
4245 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK; | |
4246 | he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1; | |
4247 | ||
4248 | switch (i) { | |
4249 | case NL80211_IFTYPE_AP: | |
4250 | he_cap_elem->phy_cap_info[3] &= | |
4251 | ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK; | |
4252 | he_cap_elem->phy_cap_info[9] |= | |
4253 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; | |
4254 | break; | |
4255 | case NL80211_IFTYPE_STATION: | |
4256 | he_cap_elem->mac_cap_info[0] &= | |
4257 | ~IEEE80211_HE_MAC_CAP0_TWT_RES; | |
4258 | he_cap_elem->mac_cap_info[0] |= | |
4259 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
4260 | he_cap_elem->phy_cap_info[9] |= | |
4261 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU; | |
4262 | break; | |
4263 | case NL80211_IFTYPE_MESH_POINT: | |
4264 | ath12k_mac_filter_he_cap_mesh(he_cap_elem); | |
4265 | break; | |
4266 | } | |
4267 | ||
4268 | he_cap->he_mcs_nss_supp.rx_mcs_80 = | |
4269 | cpu_to_le16(band_cap->he_mcs & 0xffff); | |
4270 | he_cap->he_mcs_nss_supp.tx_mcs_80 = | |
4271 | cpu_to_le16(band_cap->he_mcs & 0xffff); | |
4272 | he_cap->he_mcs_nss_supp.rx_mcs_160 = | |
4273 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
4274 | he_cap->he_mcs_nss_supp.tx_mcs_160 = | |
4275 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
4276 | he_cap->he_mcs_nss_supp.rx_mcs_80p80 = | |
4277 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
4278 | he_cap->he_mcs_nss_supp.tx_mcs_80p80 = | |
4279 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
4280 | ||
4281 | memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); | |
4282 | if (he_cap_elem->phy_cap_info[6] & | |
4283 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) | |
4284 | ath12k_gen_ppe_thresh(&band_cap->he_ppet, | |
4285 | he_cap->ppe_thres); | |
4286 | ||
4287 | if (band == NL80211_BAND_6GHZ) { | |
4288 | data[idx].he_6ghz_capa.capa = | |
4289 | ath12k_mac_setup_he_6ghz_cap(cap, band_cap); | |
4290 | } | |
4291 | idx++; | |
4292 | } | |
4293 | ||
4294 | return idx; | |
4295 | } | |
4296 | ||
4297 | static void ath12k_mac_setup_he_cap(struct ath12k *ar, | |
4298 | struct ath12k_pdev_cap *cap) | |
4299 | { | |
4300 | struct ieee80211_supported_band *band; | |
4301 | int count; | |
4302 | ||
4303 | if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
4304 | count = ath12k_mac_copy_he_cap(ar, cap, | |
4305 | ar->mac.iftype[NL80211_BAND_2GHZ], | |
4306 | NL80211_BAND_2GHZ); | |
4307 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
4308 | band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ]; | |
4309 | band->n_iftype_data = count; | |
4310 | } | |
4311 | ||
4312 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
4313 | count = ath12k_mac_copy_he_cap(ar, cap, | |
4314 | ar->mac.iftype[NL80211_BAND_5GHZ], | |
4315 | NL80211_BAND_5GHZ); | |
4316 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
4317 | band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ]; | |
4318 | band->n_iftype_data = count; | |
4319 | } | |
4320 | ||
4321 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP && | |
4322 | ar->supports_6ghz) { | |
4323 | count = ath12k_mac_copy_he_cap(ar, cap, | |
4324 | ar->mac.iftype[NL80211_BAND_6GHZ], | |
4325 | NL80211_BAND_6GHZ); | |
4326 | band = &ar->mac.sbands[NL80211_BAND_6GHZ]; | |
4327 | band->iftype_data = ar->mac.iftype[NL80211_BAND_6GHZ]; | |
4328 | band->n_iftype_data = count; | |
4329 | } | |
4330 | } | |
4331 | ||
4332 | static int __ath12k_set_antenna(struct ath12k *ar, u32 tx_ant, u32 rx_ant) | |
4333 | { | |
4334 | int ret; | |
4335 | ||
4336 | lockdep_assert_held(&ar->conf_mutex); | |
4337 | ||
4338 | if (ath12k_check_chain_mask(ar, tx_ant, true)) | |
4339 | return -EINVAL; | |
4340 | ||
4341 | if (ath12k_check_chain_mask(ar, rx_ant, false)) | |
4342 | return -EINVAL; | |
4343 | ||
4344 | ar->cfg_tx_chainmask = tx_ant; | |
4345 | ar->cfg_rx_chainmask = rx_ant; | |
4346 | ||
4347 | if (ar->state != ATH12K_STATE_ON && | |
4348 | ar->state != ATH12K_STATE_RESTARTED) | |
4349 | return 0; | |
4350 | ||
4351 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK, | |
4352 | tx_ant, ar->pdev->pdev_id); | |
4353 | if (ret) { | |
4354 | ath12k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n", | |
4355 | ret, tx_ant); | |
4356 | return ret; | |
4357 | } | |
4358 | ||
4359 | ar->num_tx_chains = hweight32(tx_ant); | |
4360 | ||
4361 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK, | |
4362 | rx_ant, ar->pdev->pdev_id); | |
4363 | if (ret) { | |
4364 | ath12k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n", | |
4365 | ret, rx_ant); | |
4366 | return ret; | |
4367 | } | |
4368 | ||
4369 | ar->num_rx_chains = hweight32(rx_ant); | |
4370 | ||
4371 | /* Reload HT/VHT/HE capability */ | |
4372 | ath12k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL); | |
4373 | ath12k_mac_setup_he_cap(ar, &ar->pdev->cap); | |
4374 | ||
4375 | return 0; | |
4376 | } | |
4377 | ||
5189a8db K |
4378 | static void ath12k_mgmt_over_wmi_tx_drop(struct ath12k *ar, struct sk_buff *skb) |
4379 | { | |
4380 | int num_mgmt; | |
4381 | ||
4382 | ieee80211_free_txskb(ar->hw, skb); | |
4383 | ||
4384 | num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx); | |
4385 | ||
4386 | if (num_mgmt < 0) | |
4387 | WARN_ON_ONCE(1); | |
4388 | ||
4389 | if (!num_mgmt) | |
4390 | wake_up(&ar->txmgmt_empty_waitq); | |
4391 | } | |
4392 | ||
d8899132 KV |
4393 | int ath12k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) |
4394 | { | |
4395 | struct sk_buff *msdu = skb; | |
4396 | struct ieee80211_tx_info *info; | |
4397 | struct ath12k *ar = ctx; | |
4398 | struct ath12k_base *ab = ar->ab; | |
4399 | ||
4400 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
4401 | idr_remove(&ar->txmgmt_idr, buf_id); | |
4402 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
4403 | dma_unmap_single(ab->dev, ATH12K_SKB_CB(msdu)->paddr, msdu->len, | |
4404 | DMA_TO_DEVICE); | |
4405 | ||
4406 | info = IEEE80211_SKB_CB(msdu); | |
4407 | memset(&info->status, 0, sizeof(info->status)); | |
4408 | ||
5189a8db | 4409 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
4410 | |
4411 | return 0; | |
4412 | } | |
4413 | ||
4414 | static int ath12k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) | |
4415 | { | |
4416 | struct ieee80211_vif *vif = ctx; | |
4417 | struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); | |
4418 | struct sk_buff *msdu = skb; | |
4419 | struct ath12k *ar = skb_cb->ar; | |
4420 | struct ath12k_base *ab = ar->ab; | |
4421 | ||
4422 | if (skb_cb->vif == vif) { | |
4423 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
4424 | idr_remove(&ar->txmgmt_idr, buf_id); | |
4425 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
4426 | dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, | |
4427 | DMA_TO_DEVICE); | |
4428 | } | |
4429 | ||
4430 | return 0; | |
4431 | } | |
4432 | ||
4433 | static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_vif *arvif, | |
4434 | struct sk_buff *skb) | |
4435 | { | |
4436 | struct ath12k_base *ab = ar->ab; | |
4437 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
4438 | struct ieee80211_tx_info *info; | |
4439 | dma_addr_t paddr; | |
4440 | int buf_id; | |
4441 | int ret; | |
4442 | ||
4443 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
4444 | buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, | |
4445 | ATH12K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); | |
4446 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
4447 | if (buf_id < 0) | |
4448 | return -ENOSPC; | |
4449 | ||
4450 | info = IEEE80211_SKB_CB(skb); | |
4451 | if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) { | |
4452 | if ((ieee80211_is_action(hdr->frame_control) || | |
4453 | ieee80211_is_deauth(hdr->frame_control) || | |
4454 | ieee80211_is_disassoc(hdr->frame_control)) && | |
4455 | ieee80211_has_protected(hdr->frame_control)) { | |
4456 | skb_put(skb, IEEE80211_CCMP_MIC_LEN); | |
4457 | } | |
4458 | } | |
4459 | ||
4460 | paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE); | |
4461 | if (dma_mapping_error(ab->dev, paddr)) { | |
4462 | ath12k_warn(ab, "failed to DMA map mgmt Tx buffer\n"); | |
4463 | ret = -EIO; | |
4464 | goto err_free_idr; | |
4465 | } | |
4466 | ||
4467 | ATH12K_SKB_CB(skb)->paddr = paddr; | |
4468 | ||
4469 | ret = ath12k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb); | |
4470 | if (ret) { | |
4471 | ath12k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret); | |
4472 | goto err_unmap_buf; | |
4473 | } | |
4474 | ||
4475 | return 0; | |
4476 | ||
4477 | err_unmap_buf: | |
4478 | dma_unmap_single(ab->dev, ATH12K_SKB_CB(skb)->paddr, | |
4479 | skb->len, DMA_TO_DEVICE); | |
4480 | err_free_idr: | |
4481 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
4482 | idr_remove(&ar->txmgmt_idr, buf_id); | |
4483 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
4484 | ||
4485 | return ret; | |
4486 | } | |
4487 | ||
4488 | static void ath12k_mgmt_over_wmi_tx_purge(struct ath12k *ar) | |
4489 | { | |
4490 | struct sk_buff *skb; | |
4491 | ||
4492 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) | |
5189a8db | 4493 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
4494 | } |
4495 | ||
4496 | static void ath12k_mgmt_over_wmi_tx_work(struct work_struct *work) | |
4497 | { | |
4498 | struct ath12k *ar = container_of(work, struct ath12k, wmi_mgmt_tx_work); | |
4499 | struct ath12k_skb_cb *skb_cb; | |
4500 | struct ath12k_vif *arvif; | |
4501 | struct sk_buff *skb; | |
4502 | int ret; | |
4503 | ||
4504 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) { | |
4505 | skb_cb = ATH12K_SKB_CB(skb); | |
4506 | if (!skb_cb->vif) { | |
4507 | ath12k_warn(ar->ab, "no vif found for mgmt frame\n"); | |
5189a8db | 4508 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
4509 | continue; |
4510 | } | |
4511 | ||
4512 | arvif = ath12k_vif_to_arvif(skb_cb->vif); | |
4513 | if (ar->allocated_vdev_map & (1LL << arvif->vdev_id) && | |
4514 | arvif->is_started) { | |
4515 | ret = ath12k_mac_mgmt_tx_wmi(ar, arvif, skb); | |
4516 | if (ret) { | |
4517 | ath12k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n", | |
4518 | arvif->vdev_id, ret); | |
5189a8db | 4519 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
4520 | } |
4521 | } else { | |
4522 | ath12k_warn(ar->ab, | |
4523 | "dropping mgmt frame for vdev %d, is_started %d\n", | |
4524 | arvif->vdev_id, | |
4525 | arvif->is_started); | |
5189a8db | 4526 | ath12k_mgmt_over_wmi_tx_drop(ar, skb); |
d8899132 KV |
4527 | } |
4528 | } | |
4529 | } | |
4530 | ||
4531 | static int ath12k_mac_mgmt_tx(struct ath12k *ar, struct sk_buff *skb, | |
4532 | bool is_prb_rsp) | |
4533 | { | |
4534 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; | |
4535 | ||
4536 | if (test_bit(ATH12K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
4537 | return -ESHUTDOWN; | |
4538 | ||
4539 | /* Drop probe response packets when the pending management tx | |
4540 | * count has reached a certain threshold, so as to prioritize | |
4541 | * other mgmt packets like auth and assoc to be sent on time | |
4542 | * for establishing successful connections. | |
4543 | */ | |
4544 | if (is_prb_rsp && | |
4545 | atomic_read(&ar->num_pending_mgmt_tx) > ATH12K_PRB_RSP_DROP_THRESHOLD) { | |
4546 | ath12k_warn(ar->ab, | |
4547 | "dropping probe response as pending queue is almost full\n"); | |
4548 | return -ENOSPC; | |
4549 | } | |
4550 | ||
4551 | if (skb_queue_len(q) == ATH12K_TX_MGMT_NUM_PENDING_MAX) { | |
4552 | ath12k_warn(ar->ab, "mgmt tx queue is full\n"); | |
4553 | return -ENOSPC; | |
4554 | } | |
4555 | ||
4556 | skb_queue_tail(q, skb); | |
5189a8db | 4557 | atomic_inc(&ar->num_pending_mgmt_tx); |
d8899132 KV |
4558 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); |
4559 | ||
4560 | return 0; | |
4561 | } | |
4562 | ||
4563 | static void ath12k_mac_op_tx(struct ieee80211_hw *hw, | |
4564 | struct ieee80211_tx_control *control, | |
4565 | struct sk_buff *skb) | |
4566 | { | |
4567 | struct ath12k_skb_cb *skb_cb = ATH12K_SKB_CB(skb); | |
4568 | struct ath12k *ar = hw->priv; | |
4569 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
4570 | struct ieee80211_vif *vif = info->control.vif; | |
4571 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
4572 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
4573 | struct ieee80211_key_conf *key = info->control.hw_key; | |
4574 | u32 info_flags = info->flags; | |
4575 | bool is_prb_rsp; | |
4576 | int ret; | |
4577 | ||
4578 | memset(skb_cb, 0, sizeof(*skb_cb)); | |
4579 | skb_cb->vif = vif; | |
4580 | ||
4581 | if (key) { | |
4582 | skb_cb->cipher = key->cipher; | |
4583 | skb_cb->flags |= ATH12K_SKB_CIPHER_SET; | |
4584 | } | |
4585 | ||
4586 | if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { | |
4587 | skb_cb->flags |= ATH12K_SKB_HW_80211_ENCAP; | |
4588 | } else if (ieee80211_is_mgmt(hdr->frame_control)) { | |
4589 | is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control); | |
4590 | ret = ath12k_mac_mgmt_tx(ar, skb, is_prb_rsp); | |
4591 | if (ret) { | |
4592 | ath12k_warn(ar->ab, "failed to queue management frame %d\n", | |
4593 | ret); | |
4594 | ieee80211_free_txskb(ar->hw, skb); | |
4595 | } | |
4596 | return; | |
4597 | } | |
4598 | ||
4599 | ret = ath12k_dp_tx(ar, arvif, skb); | |
4600 | if (ret) { | |
4601 | ath12k_warn(ar->ab, "failed to transmit frame %d\n", ret); | |
4602 | ieee80211_free_txskb(ar->hw, skb); | |
4603 | } | |
4604 | } | |
4605 | ||
4606 | void ath12k_mac_drain_tx(struct ath12k *ar) | |
4607 | { | |
4608 | /* make sure rcu-protected mac80211 tx path itself is drained */ | |
4609 | synchronize_net(); | |
4610 | ||
4611 | cancel_work_sync(&ar->wmi_mgmt_tx_work); | |
4612 | ath12k_mgmt_over_wmi_tx_purge(ar); | |
4613 | } | |
4614 | ||
4615 | static int ath12k_mac_config_mon_status_default(struct ath12k *ar, bool enable) | |
4616 | { | |
4617 | return -ENOTSUPP; | |
4618 | /* TODO: Need to support new monitor mode */ | |
4619 | } | |
4620 | ||
4621 | static void ath12k_mac_wait_reconfigure(struct ath12k_base *ab) | |
4622 | { | |
4623 | int recovery_start_count; | |
4624 | ||
4625 | if (!ab->is_reset) | |
4626 | return; | |
4627 | ||
4628 | recovery_start_count = atomic_inc_return(&ab->recovery_start_count); | |
4629 | ||
4630 | ath12k_dbg(ab, ATH12K_DBG_MAC, "recovery start count %d\n", recovery_start_count); | |
4631 | ||
4632 | if (recovery_start_count == ab->num_radios) { | |
4633 | complete(&ab->recovery_start); | |
4634 | ath12k_dbg(ab, ATH12K_DBG_MAC, "recovery started success\n"); | |
4635 | } | |
4636 | ||
4637 | ath12k_dbg(ab, ATH12K_DBG_MAC, "waiting reconfigure...\n"); | |
4638 | ||
4639 | wait_for_completion_timeout(&ab->reconfigure_complete, | |
4640 | ATH12K_RECONFIGURE_TIMEOUT_HZ); | |
4641 | } | |
4642 | ||
4643 | static int ath12k_mac_op_start(struct ieee80211_hw *hw) | |
4644 | { | |
4645 | struct ath12k *ar = hw->priv; | |
4646 | struct ath12k_base *ab = ar->ab; | |
4647 | struct ath12k_pdev *pdev = ar->pdev; | |
4648 | int ret; | |
4649 | ||
4650 | ath12k_mac_drain_tx(ar); | |
4651 | mutex_lock(&ar->conf_mutex); | |
4652 | ||
4653 | switch (ar->state) { | |
4654 | case ATH12K_STATE_OFF: | |
4655 | ar->state = ATH12K_STATE_ON; | |
4656 | break; | |
4657 | case ATH12K_STATE_RESTARTING: | |
4658 | ar->state = ATH12K_STATE_RESTARTED; | |
4659 | ath12k_mac_wait_reconfigure(ab); | |
4660 | break; | |
4661 | case ATH12K_STATE_RESTARTED: | |
4662 | case ATH12K_STATE_WEDGED: | |
4663 | case ATH12K_STATE_ON: | |
4664 | WARN_ON(1); | |
4665 | ret = -EINVAL; | |
4666 | goto err; | |
4667 | } | |
4668 | ||
4669 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, | |
4670 | 1, pdev->pdev_id); | |
4671 | ||
4672 | if (ret) { | |
4673 | ath12k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret); | |
4674 | goto err; | |
4675 | } | |
4676 | ||
4677 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1, | |
4678 | pdev->pdev_id); | |
4679 | if (ret) { | |
4680 | ath12k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret); | |
4681 | goto err; | |
4682 | } | |
4683 | ||
4684 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE, | |
4685 | 0, pdev->pdev_id); | |
4686 | if (ret) { | |
4687 | ath12k_err(ab, "failed to set ac override for ARP: %d\n", | |
4688 | ret); | |
4689 | goto err; | |
4690 | } | |
4691 | ||
4692 | ret = ath12k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id); | |
4693 | if (ret) { | |
4694 | ath12k_err(ab, "failed to offload radar detection: %d\n", | |
4695 | ret); | |
4696 | goto err; | |
4697 | } | |
4698 | ||
4699 | ret = ath12k_dp_tx_htt_h2t_ppdu_stats_req(ar, | |
4700 | HTT_PPDU_STATS_TAG_DEFAULT); | |
4701 | if (ret) { | |
4702 | ath12k_err(ab, "failed to req ppdu stats: %d\n", ret); | |
4703 | goto err; | |
4704 | } | |
4705 | ||
4706 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE, | |
4707 | 1, pdev->pdev_id); | |
4708 | ||
4709 | if (ret) { | |
4710 | ath12k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret); | |
4711 | goto err; | |
4712 | } | |
4713 | ||
4714 | __ath12k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); | |
4715 | ||
4716 | /* TODO: Do we need to enable ANI? */ | |
4717 | ||
4718 | ath12k_reg_update_chan_list(ar); | |
4719 | ||
4720 | ar->num_started_vdevs = 0; | |
4721 | ar->num_created_vdevs = 0; | |
4722 | ar->num_peers = 0; | |
4723 | ar->allocated_vdev_map = 0; | |
4724 | ||
4725 | /* Configure monitor status ring with default rx_filter to get rx status | |
4726 | * such as rssi, rx_duration. | |
4727 | */ | |
4728 | ret = ath12k_mac_config_mon_status_default(ar, true); | |
4729 | if (ret && (ret != -ENOTSUPP)) { | |
4730 | ath12k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n", | |
4731 | ret); | |
4732 | goto err; | |
4733 | } | |
4734 | ||
4735 | if (ret == -ENOTSUPP) | |
4736 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
4737 | "monitor status config is not yet supported"); | |
4738 | ||
4739 | /* Configure the hash seed for hash based reo dest ring selection */ | |
4740 | ath12k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id); | |
4741 | ||
4742 | /* allow device to enter IMPS */ | |
4743 | if (ab->hw_params->idle_ps) { | |
4744 | ret = ath12k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG, | |
4745 | 1, pdev->pdev_id); | |
4746 | if (ret) { | |
4747 | ath12k_err(ab, "failed to enable idle ps: %d\n", ret); | |
4748 | goto err; | |
4749 | } | |
4750 | } | |
4751 | ||
4752 | mutex_unlock(&ar->conf_mutex); | |
4753 | ||
4754 | rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], | |
4755 | &ab->pdevs[ar->pdev_idx]); | |
4756 | ||
4757 | return 0; | |
4758 | ||
4759 | err: | |
4760 | ar->state = ATH12K_STATE_OFF; | |
4761 | mutex_unlock(&ar->conf_mutex); | |
4762 | ||
4763 | return ret; | |
4764 | } | |
4765 | ||
4766 | static void ath12k_mac_op_stop(struct ieee80211_hw *hw) | |
4767 | { | |
4768 | struct ath12k *ar = hw->priv; | |
4769 | struct htt_ppdu_stats_info *ppdu_stats, *tmp; | |
4770 | int ret; | |
4771 | ||
4772 | ath12k_mac_drain_tx(ar); | |
4773 | ||
4774 | mutex_lock(&ar->conf_mutex); | |
4775 | ret = ath12k_mac_config_mon_status_default(ar, false); | |
4776 | if (ret && (ret != -ENOTSUPP)) | |
4777 | ath12k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n", | |
4778 | ret); | |
4779 | ||
4780 | clear_bit(ATH12K_CAC_RUNNING, &ar->dev_flags); | |
4781 | ar->state = ATH12K_STATE_OFF; | |
4782 | mutex_unlock(&ar->conf_mutex); | |
4783 | ||
4784 | cancel_delayed_work_sync(&ar->scan.timeout); | |
4785 | cancel_work_sync(&ar->regd_update_work); | |
4786 | ||
4787 | spin_lock_bh(&ar->data_lock); | |
4788 | list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) { | |
4789 | list_del(&ppdu_stats->list); | |
4790 | kfree(ppdu_stats); | |
4791 | } | |
4792 | spin_unlock_bh(&ar->data_lock); | |
4793 | ||
4794 | rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL); | |
4795 | ||
4796 | synchronize_rcu(); | |
4797 | ||
4798 | atomic_set(&ar->num_pending_mgmt_tx, 0); | |
4799 | } | |
4800 | ||
4801 | static u8 | |
4802 | ath12k_mac_get_vdev_stats_id(struct ath12k_vif *arvif) | |
4803 | { | |
4804 | struct ath12k_base *ab = arvif->ar->ab; | |
4805 | u8 vdev_stats_id = 0; | |
4806 | ||
4807 | do { | |
4808 | if (ab->free_vdev_stats_id_map & (1LL << vdev_stats_id)) { | |
4809 | vdev_stats_id++; | |
4810 | if (vdev_stats_id <= ATH12K_INVAL_VDEV_STATS_ID) { | |
4811 | vdev_stats_id = ATH12K_INVAL_VDEV_STATS_ID; | |
4812 | break; | |
4813 | } | |
4814 | } else { | |
4815 | ab->free_vdev_stats_id_map |= (1LL << vdev_stats_id); | |
4816 | break; | |
4817 | } | |
4818 | } while (vdev_stats_id); | |
4819 | ||
4820 | arvif->vdev_stats_id = vdev_stats_id; | |
4821 | return vdev_stats_id; | |
4822 | } | |
4823 | ||
4824 | static void ath12k_mac_setup_vdev_create_arg(struct ath12k_vif *arvif, | |
4825 | struct ath12k_wmi_vdev_create_arg *arg) | |
4826 | { | |
4827 | struct ath12k *ar = arvif->ar; | |
4828 | struct ath12k_pdev *pdev = ar->pdev; | |
4829 | ||
4830 | arg->if_id = arvif->vdev_id; | |
4831 | arg->type = arvif->vdev_type; | |
4832 | arg->subtype = arvif->vdev_subtype; | |
4833 | arg->pdev_id = pdev->pdev_id; | |
4834 | ||
4835 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
4836 | arg->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; | |
4837 | arg->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; | |
4838 | } | |
4839 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
4840 | arg->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; | |
4841 | arg->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; | |
4842 | } | |
4843 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP && | |
4844 | ar->supports_6ghz) { | |
4845 | arg->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains; | |
4846 | arg->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains; | |
4847 | } | |
4848 | ||
4849 | arg->if_stats_id = ath12k_mac_get_vdev_stats_id(arvif); | |
4850 | } | |
4851 | ||
4852 | static u32 | |
4853 | ath12k_mac_prepare_he_mode(struct ath12k_pdev *pdev, u32 viftype) | |
4854 | { | |
4855 | struct ath12k_pdev_cap *pdev_cap = &pdev->cap; | |
4856 | struct ath12k_band_cap *cap_band = NULL; | |
4857 | u32 *hecap_phy_ptr = NULL; | |
4858 | u32 hemode; | |
4859 | ||
4860 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) | |
4861 | cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; | |
4862 | else | |
4863 | cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; | |
4864 | ||
4865 | hecap_phy_ptr = &cap_band->he_cap_phy_info[0]; | |
4866 | ||
4867 | hemode = u32_encode_bits(HE_SU_BFEE_ENABLE, HE_MODE_SU_TX_BFEE) | | |
4868 | u32_encode_bits(HECAP_PHY_SUBFMR_GET(hecap_phy_ptr), | |
4869 | HE_MODE_SU_TX_BFER) | | |
4870 | u32_encode_bits(HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr), | |
4871 | HE_MODE_UL_MUMIMO); | |
4872 | ||
4873 | /* TODO: WDS and other modes */ | |
4874 | if (viftype == NL80211_IFTYPE_AP) { | |
4875 | hemode |= u32_encode_bits(HECAP_PHY_MUBFMR_GET(hecap_phy_ptr), | |
4876 | HE_MODE_MU_TX_BFER) | | |
4877 | u32_encode_bits(HE_DL_MUOFDMA_ENABLE, HE_MODE_DL_OFDMA) | | |
4878 | u32_encode_bits(HE_UL_MUOFDMA_ENABLE, HE_MODE_UL_OFDMA); | |
4879 | } else { | |
4880 | hemode |= u32_encode_bits(HE_MU_BFEE_ENABLE, HE_MODE_MU_TX_BFEE); | |
4881 | } | |
4882 | ||
4883 | return hemode; | |
4884 | } | |
4885 | ||
4886 | static int ath12k_set_he_mu_sounding_mode(struct ath12k *ar, | |
4887 | struct ath12k_vif *arvif) | |
4888 | { | |
4889 | u32 param_id, param_value; | |
4890 | struct ath12k_base *ab = ar->ab; | |
4891 | int ret; | |
4892 | ||
4893 | param_id = WMI_VDEV_PARAM_SET_HEMU_MODE; | |
4894 | param_value = ath12k_mac_prepare_he_mode(ar->pdev, arvif->vif->type); | |
4895 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4896 | param_id, param_value); | |
4897 | if (ret) { | |
4898 | ath12k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n", | |
4899 | arvif->vdev_id, ret, param_value); | |
4900 | return ret; | |
4901 | } | |
4902 | param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE; | |
4903 | param_value = | |
4904 | u32_encode_bits(HE_VHT_SOUNDING_MODE_ENABLE, HE_VHT_SOUNDING_MODE) | | |
4905 | u32_encode_bits(HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE, | |
4906 | HE_TRIG_NONTRIG_SOUNDING_MODE); | |
4907 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4908 | param_id, param_value); | |
4909 | if (ret) { | |
4910 | ath12k_warn(ab, "failed to set vdev %d HE MU mode: %d\n", | |
4911 | arvif->vdev_id, ret); | |
4912 | return ret; | |
4913 | } | |
4914 | return ret; | |
4915 | } | |
4916 | ||
4917 | static void ath12k_mac_op_update_vif_offload(struct ieee80211_hw *hw, | |
4918 | struct ieee80211_vif *vif) | |
4919 | { | |
4920 | struct ath12k *ar = hw->priv; | |
4921 | struct ath12k_base *ab = ar->ab; | |
4922 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
4923 | u32 param_id, param_value; | |
4924 | int ret; | |
4925 | ||
4926 | param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE; | |
4927 | if (vif->type != NL80211_IFTYPE_STATION && | |
4928 | vif->type != NL80211_IFTYPE_AP) | |
4929 | vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED | | |
4930 | IEEE80211_OFFLOAD_DECAP_ENABLED); | |
4931 | ||
4932 | if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED) | |
4933 | arvif->tx_encap_type = ATH12K_HW_TXRX_ETHERNET; | |
4934 | else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) | |
4935 | arvif->tx_encap_type = ATH12K_HW_TXRX_RAW; | |
4936 | else | |
4937 | arvif->tx_encap_type = ATH12K_HW_TXRX_NATIVE_WIFI; | |
4938 | ||
4939 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4940 | param_id, arvif->tx_encap_type); | |
4941 | if (ret) { | |
4942 | ath12k_warn(ab, "failed to set vdev %d tx encap mode: %d\n", | |
4943 | arvif->vdev_id, ret); | |
4944 | vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; | |
4945 | } | |
4946 | ||
4947 | param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE; | |
4948 | if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED) | |
4949 | param_value = ATH12K_HW_TXRX_ETHERNET; | |
4950 | else if (test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) | |
4951 | param_value = ATH12K_HW_TXRX_RAW; | |
4952 | else | |
4953 | param_value = ATH12K_HW_TXRX_NATIVE_WIFI; | |
4954 | ||
4955 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4956 | param_id, param_value); | |
4957 | if (ret) { | |
4958 | ath12k_warn(ab, "failed to set vdev %d rx decap mode: %d\n", | |
4959 | arvif->vdev_id, ret); | |
4960 | vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED; | |
4961 | } | |
4962 | } | |
4963 | ||
4964 | static int ath12k_mac_op_add_interface(struct ieee80211_hw *hw, | |
4965 | struct ieee80211_vif *vif) | |
4966 | { | |
4967 | struct ath12k *ar = hw->priv; | |
4968 | struct ath12k_base *ab = ar->ab; | |
4969 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
4970 | struct ath12k_wmi_vdev_create_arg vdev_arg = {0}; | |
4971 | struct ath12k_wmi_peer_create_arg peer_param; | |
4972 | u32 param_id, param_value; | |
4973 | u16 nss; | |
4974 | int i; | |
4975 | int ret; | |
4976 | int bit; | |
4977 | ||
4978 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; | |
4979 | ||
4980 | mutex_lock(&ar->conf_mutex); | |
4981 | ||
4982 | if (vif->type == NL80211_IFTYPE_AP && | |
4983 | ar->num_peers > (ar->max_num_peers - 1)) { | |
4984 | ath12k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n"); | |
4985 | ret = -ENOBUFS; | |
4986 | goto err; | |
4987 | } | |
4988 | ||
4989 | if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) { | |
4990 | ath12k_warn(ab, "failed to create vdev, reached max vdev limit %d\n", | |
4991 | TARGET_NUM_VDEVS); | |
4992 | ret = -EBUSY; | |
4993 | goto err; | |
4994 | } | |
4995 | ||
4996 | memset(arvif, 0, sizeof(*arvif)); | |
4997 | ||
4998 | arvif->ar = ar; | |
4999 | arvif->vif = vif; | |
5000 | ||
5001 | INIT_LIST_HEAD(&arvif->list); | |
5002 | ||
5003 | /* Should we initialize any worker to handle connection loss indication | |
5004 | * from firmware in sta mode? | |
5005 | */ | |
5006 | ||
5007 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { | |
5008 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; | |
5009 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, | |
5010 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); | |
5011 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, | |
5012 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); | |
5013 | } | |
5014 | ||
5015 | bit = __ffs64(ab->free_vdev_map); | |
5016 | ||
5017 | arvif->vdev_id = bit; | |
5018 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; | |
5019 | ||
5020 | switch (vif->type) { | |
5021 | case NL80211_IFTYPE_UNSPECIFIED: | |
5022 | case NL80211_IFTYPE_STATION: | |
5023 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
5024 | break; | |
5025 | case NL80211_IFTYPE_MESH_POINT: | |
5026 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S; | |
5027 | fallthrough; | |
5028 | case NL80211_IFTYPE_AP: | |
5029 | arvif->vdev_type = WMI_VDEV_TYPE_AP; | |
5030 | break; | |
5031 | case NL80211_IFTYPE_MONITOR: | |
5032 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; | |
5033 | ar->monitor_vdev_id = bit; | |
5034 | break; | |
5035 | default: | |
5036 | WARN_ON(1); | |
5037 | break; | |
5038 | } | |
5039 | ||
5040 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n", | |
5041 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, | |
5042 | ab->free_vdev_map); | |
5043 | ||
5044 | vif->cab_queue = arvif->vdev_id % (ATH12K_HW_MAX_QUEUES - 1); | |
5045 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) | |
5046 | vif->hw_queue[i] = i % (ATH12K_HW_MAX_QUEUES - 1); | |
5047 | ||
5048 | ath12k_mac_setup_vdev_create_arg(arvif, &vdev_arg); | |
5049 | ||
5050 | ret = ath12k_wmi_vdev_create(ar, vif->addr, &vdev_arg); | |
5051 | if (ret) { | |
5052 | ath12k_warn(ab, "failed to create WMI vdev %d: %d\n", | |
5053 | arvif->vdev_id, ret); | |
5054 | goto err; | |
5055 | } | |
5056 | ||
5057 | ar->num_created_vdevs++; | |
5058 | ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM created, vdev_id %d\n", | |
5059 | vif->addr, arvif->vdev_id); | |
5060 | ar->allocated_vdev_map |= 1LL << arvif->vdev_id; | |
5061 | ab->free_vdev_map &= ~(1LL << arvif->vdev_id); | |
5062 | ||
5063 | spin_lock_bh(&ar->data_lock); | |
5064 | list_add(&arvif->list, &ar->arvifs); | |
5065 | spin_unlock_bh(&ar->data_lock); | |
5066 | ||
5067 | ath12k_mac_op_update_vif_offload(hw, vif); | |
5068 | ||
5069 | nss = hweight32(ar->cfg_tx_chainmask) ? : 1; | |
5070 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5071 | WMI_VDEV_PARAM_NSS, nss); | |
5072 | if (ret) { | |
5073 | ath12k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", | |
5074 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret); | |
5075 | goto err_vdev_del; | |
5076 | } | |
5077 | ||
5078 | switch (arvif->vdev_type) { | |
5079 | case WMI_VDEV_TYPE_AP: | |
5080 | peer_param.vdev_id = arvif->vdev_id; | |
5081 | peer_param.peer_addr = vif->addr; | |
5082 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
5083 | ret = ath12k_peer_create(ar, arvif, NULL, &peer_param); | |
5084 | if (ret) { | |
5085 | ath12k_warn(ab, "failed to vdev %d create peer for AP: %d\n", | |
5086 | arvif->vdev_id, ret); | |
5087 | goto err_vdev_del; | |
5088 | } | |
5089 | ||
5090 | ret = ath12k_mac_set_kickout(arvif); | |
5091 | if (ret) { | |
5092 | ath12k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n", | |
5093 | arvif->vdev_id, ret); | |
5094 | goto err_peer_del; | |
5095 | } | |
5096 | break; | |
5097 | case WMI_VDEV_TYPE_STA: | |
5098 | param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY; | |
5099 | param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
5100 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
5101 | param_id, param_value); | |
5102 | if (ret) { | |
5103 | ath12k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n", | |
5104 | arvif->vdev_id, ret); | |
5105 | goto err_peer_del; | |
5106 | } | |
5107 | ||
5108 | param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; | |
5109 | param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; | |
5110 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
5111 | param_id, param_value); | |
5112 | if (ret) { | |
5113 | ath12k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n", | |
5114 | arvif->vdev_id, ret); | |
5115 | goto err_peer_del; | |
5116 | } | |
5117 | ||
5118 | param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT; | |
5119 | param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; | |
5120 | ret = ath12k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
5121 | param_id, param_value); | |
5122 | if (ret) { | |
5123 | ath12k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n", | |
5124 | arvif->vdev_id, ret); | |
5125 | goto err_peer_del; | |
5126 | } | |
5127 | ||
5128 | ret = ath12k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false); | |
5129 | if (ret) { | |
5130 | ath12k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n", | |
5131 | arvif->vdev_id, ret); | |
5132 | goto err_peer_del; | |
5133 | } | |
5134 | break; | |
5135 | default: | |
5136 | break; | |
5137 | } | |
5138 | ||
5139 | arvif->txpower = vif->bss_conf.txpower; | |
5140 | ret = ath12k_mac_txpower_recalc(ar); | |
5141 | if (ret) | |
5142 | goto err_peer_del; | |
5143 | ||
5144 | param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
5145 | param_value = ar->hw->wiphy->rts_threshold; | |
5146 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5147 | param_id, param_value); | |
5148 | if (ret) { | |
5149 | ath12k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n", | |
5150 | arvif->vdev_id, ret); | |
5151 | } | |
5152 | ||
5153 | ath12k_dp_vdev_tx_attach(ar, arvif); | |
5154 | ||
5155 | if (vif->type != NL80211_IFTYPE_MONITOR && ar->monitor_conf_enabled) | |
5156 | ath12k_mac_monitor_vdev_create(ar); | |
5157 | ||
5158 | mutex_unlock(&ar->conf_mutex); | |
5159 | ||
5160 | return ret; | |
5161 | ||
5162 | err_peer_del: | |
5163 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
5164 | reinit_completion(&ar->peer_delete_done); | |
5165 | ||
5166 | ret = ath12k_wmi_send_peer_delete_cmd(ar, vif->addr, | |
5167 | arvif->vdev_id); | |
5168 | if (ret) { | |
5169 | ath12k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n", | |
5170 | arvif->vdev_id, vif->addr); | |
5171 | goto err; | |
5172 | } | |
5173 | ||
5174 | ret = ath12k_wait_for_peer_delete_done(ar, arvif->vdev_id, | |
5175 | vif->addr); | |
5176 | if (ret) | |
5177 | goto err; | |
5178 | ||
5179 | ar->num_peers--; | |
5180 | } | |
5181 | ||
5182 | err_vdev_del: | |
5183 | ath12k_wmi_vdev_delete(ar, arvif->vdev_id); | |
5184 | ar->num_created_vdevs--; | |
5185 | ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); | |
5186 | ab->free_vdev_map |= 1LL << arvif->vdev_id; | |
5187 | ab->free_vdev_stats_id_map &= ~(1LL << arvif->vdev_stats_id); | |
5188 | spin_lock_bh(&ar->data_lock); | |
5189 | list_del(&arvif->list); | |
5190 | spin_unlock_bh(&ar->data_lock); | |
5191 | ||
5192 | err: | |
5193 | mutex_unlock(&ar->conf_mutex); | |
5194 | ||
5195 | return ret; | |
5196 | } | |
5197 | ||
5198 | static void ath12k_mac_vif_unref(struct ath12k_dp *dp, struct ieee80211_vif *vif) | |
5199 | { | |
5200 | struct ath12k_tx_desc_info *tx_desc_info, *tmp1; | |
5201 | struct ath12k_skb_cb *skb_cb; | |
5202 | struct sk_buff *skb; | |
5203 | int i; | |
5204 | ||
5205 | for (i = 0; i < ATH12K_HW_MAX_QUEUES; i++) { | |
5206 | spin_lock_bh(&dp->tx_desc_lock[i]); | |
5207 | ||
5208 | list_for_each_entry_safe(tx_desc_info, tmp1, &dp->tx_desc_used_list[i], | |
5209 | list) { | |
5210 | skb = tx_desc_info->skb; | |
5211 | if (!skb) | |
5212 | continue; | |
5213 | ||
5214 | skb_cb = ATH12K_SKB_CB(skb); | |
5215 | if (skb_cb->vif == vif) | |
5216 | skb_cb->vif = NULL; | |
5217 | } | |
5218 | ||
5219 | spin_unlock_bh(&dp->tx_desc_lock[i]); | |
5220 | } | |
5221 | } | |
5222 | ||
5223 | static void ath12k_mac_op_remove_interface(struct ieee80211_hw *hw, | |
5224 | struct ieee80211_vif *vif) | |
5225 | { | |
5226 | struct ath12k *ar = hw->priv; | |
5227 | struct ath12k_vif *arvif = ath12k_vif_to_arvif(vif); | |
5228 | struct ath12k_base *ab = ar->ab; | |
5229 | unsigned long time_left; | |
5230 | int ret; | |
5231 | ||
5232 | mutex_lock(&ar->conf_mutex); | |
5233 | ||
5234 | ath12k_dbg(ab, ATH12K_DBG_MAC, "mac remove interface (vdev %d)\n", | |
5235 | arvif->vdev_id); | |
5236 | ||
5237 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
5238 | ret = ath12k_peer_delete(ar, arvif->vdev_id, vif->addr); | |
5239 | if (ret) | |
5240 | ath12k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n", | |
5241 | arvif->vdev_id, ret); | |
5242 | } | |
5243 | ||
5244 | reinit_completion(&ar->vdev_delete_done); | |
5245 | ||
5246 | ret = ath12k_wmi_vdev_delete(ar, arvif->vdev_id); | |
5247 | if (ret) { | |
5248 | ath12k_warn(ab, "failed to delete WMI vdev %d: %d\n", | |
5249 | arvif->vdev_id, ret); | |
5250 | goto err_vdev_del; | |
5251 | } | |
5252 | ||
5253 | time_left = wait_for_completion_timeout(&ar->vdev_delete_done, | |
5254 | ATH12K_VDEV_DELETE_TIMEOUT_HZ); | |
5255 | if (time_left == 0) { | |
5256 | ath12k_warn(ab, "Timeout in receiving vdev delete response\n"); | |
5257 | goto err_vdev_del; | |
5258 | } | |
5259 | ||
5260 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { | |
5261 | ar->monitor_vdev_id = -1; | |
5262 | ar->monitor_vdev_created = false; | |
5263 | } else if (ar->monitor_vdev_created && !ar->monitor_started) { | |
5264 | ret = ath12k_mac_monitor_vdev_delete(ar); | |
5265 | } | |
5266 | ||
5267 | ab->free_vdev_map |= 1LL << (arvif->vdev_id); | |
5268 | ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id); | |
5269 | ab->free_vdev_stats_id_map &= ~(1LL << arvif->vdev_stats_id); | |
5270 | ar->num_created_vdevs--; | |
5271 | ||
5272 | ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n", | |
5273 | vif->addr, arvif->vdev_id); | |
5274 | ||
5275 | err_vdev_del: | |
5276 | spin_lock_bh(&ar->data_lock); | |
5277 | list_del(&arvif->list); | |
5278 | spin_unlock_bh(&ar->data_lock); | |
5279 | ||
5280 | ath12k_peer_cleanup(ar, arvif->vdev_id); | |
5281 | ||
5282 | idr_for_each(&ar->txmgmt_idr, | |
5283 | ath12k_mac_vif_txmgmt_idr_remove, vif); | |
5284 | ||
5285 | ath12k_mac_vif_unref(&ab->dp, vif); | |
5286 | ath12k_dp_tx_put_bank_profile(&ab->dp, arvif->bank_id); | |
5287 | ||
5288 | /* Recalc txpower for remaining vdev */ | |
5289 | ath12k_mac_txpower_recalc(ar); | |
5290 | clear_bit(ATH12K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
5291 | ||
5292 | /* TODO: recal traffic pause state based on the available vdevs */ | |
5293 | ||
5294 | mutex_unlock(&ar->conf_mutex); | |
5295 | } | |
5296 | ||
5297 | /* FIXME: Has to be verified. */ | |
5298 | #define SUPPORTED_FILTERS \ | |
5299 | (FIF_ALLMULTI | \ | |
5300 | FIF_CONTROL | \ | |
5301 | FIF_PSPOLL | \ | |
5302 | FIF_OTHER_BSS | \ | |
5303 | FIF_BCN_PRBRESP_PROMISC | \ | |
5304 | FIF_PROBE_REQ | \ | |
5305 | FIF_FCSFAIL) | |
5306 | ||
5307 | static void ath12k_mac_op_configure_filter(struct ieee80211_hw *hw, | |
5308 | unsigned int changed_flags, | |
5309 | unsigned int *total_flags, | |
5310 | u64 multicast) | |
5311 | { | |
5312 | struct ath12k *ar = hw->priv; | |
5313 | bool reset_flag; | |
5314 | int ret; | |
5315 | ||
5316 | mutex_lock(&ar->conf_mutex); | |
5317 | ||
5318 | changed_flags &= SUPPORTED_FILTERS; | |
5319 | *total_flags &= SUPPORTED_FILTERS; | |
5320 | ar->filter_flags = *total_flags; | |
5321 | ||
5322 | /* For monitor mode */ | |
5323 | reset_flag = !(ar->filter_flags & FIF_BCN_PRBRESP_PROMISC); | |
5324 | ||
5325 | ret = ath12k_dp_tx_htt_monitor_mode_ring_config(ar, reset_flag); | |
5326 | if (!ret) { | |
5327 | if (!reset_flag) | |
5328 | set_bit(ATH12K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
5329 | else | |
5330 | clear_bit(ATH12K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
5331 | } else { | |
5332 | ath12k_warn(ar->ab, | |
5333 | "fail to set monitor filter: %d\n", ret); | |
5334 | } | |
5335 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
5336 | "changed_flags:0x%x, total_flags:0x%x, reset_flag:%d\n", | |
5337 | changed_flags, *total_flags, reset_flag); | |
5338 | ||
5339 | mutex_unlock(&ar->conf_mutex); | |
5340 | } | |
5341 | ||
5342 | static int ath12k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) | |
5343 | { | |
5344 | struct ath12k *ar = hw->priv; | |
5345 | ||
5346 | mutex_lock(&ar->conf_mutex); | |
5347 | ||
5348 | *tx_ant = ar->cfg_tx_chainmask; | |
5349 | *rx_ant = ar->cfg_rx_chainmask; | |
5350 | ||
5351 | mutex_unlock(&ar->conf_mutex); | |
5352 | ||
5353 | return 0; | |
5354 | } | |
5355 | ||
5356 | static int ath12k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) | |
5357 | { | |
5358 | struct ath12k *ar = hw->priv; | |
5359 | int ret; | |
5360 | ||
5361 | mutex_lock(&ar->conf_mutex); | |
5362 | ret = __ath12k_set_antenna(ar, tx_ant, rx_ant); | |
5363 | mutex_unlock(&ar->conf_mutex); | |
5364 | ||
5365 | return ret; | |
5366 | } | |
5367 | ||
5368 | static int ath12k_mac_op_ampdu_action(struct ieee80211_hw *hw, | |
5369 | struct ieee80211_vif *vif, | |
5370 | struct ieee80211_ampdu_params *params) | |
5371 | { | |
5372 | struct ath12k *ar = hw->priv; | |
5373 | int ret = -EINVAL; | |
5374 | ||
5375 | mutex_lock(&ar->conf_mutex); | |
5376 | ||
5377 | switch (params->action) { | |
5378 | case IEEE80211_AMPDU_RX_START: | |
5379 | ret = ath12k_dp_rx_ampdu_start(ar, params); | |
5380 | break; | |
5381 | case IEEE80211_AMPDU_RX_STOP: | |
5382 | ret = ath12k_dp_rx_ampdu_stop(ar, params); | |
5383 | break; | |
5384 | case IEEE80211_AMPDU_TX_START: | |
5385 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
5386 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
5387 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
5388 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
5389 | /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211 | |
5390 | * Tx aggregation requests. | |
5391 | */ | |
5392 | ret = -EOPNOTSUPP; | |
5393 | break; | |
5394 | } | |
5395 | ||
5396 | mutex_unlock(&ar->conf_mutex); | |
5397 | ||
5398 | return ret; | |
5399 | } | |
5400 | ||
5401 | static int ath12k_mac_op_add_chanctx(struct ieee80211_hw *hw, | |
5402 | struct ieee80211_chanctx_conf *ctx) | |
5403 | { | |
5404 | struct ath12k *ar = hw->priv; | |
5405 | struct ath12k_base *ab = ar->ab; | |
5406 | ||
5407 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5408 | "mac chanctx add freq %u width %d ptr %pK\n", | |
5409 | ctx->def.chan->center_freq, ctx->def.width, ctx); | |
5410 | ||
5411 | mutex_lock(&ar->conf_mutex); | |
5412 | ||
5413 | spin_lock_bh(&ar->data_lock); | |
5414 | /* TODO: In case of multiple channel context, populate rx_channel from | |
5415 | * Rx PPDU desc information. | |
5416 | */ | |
5417 | ar->rx_channel = ctx->def.chan; | |
5418 | spin_unlock_bh(&ar->data_lock); | |
5419 | ||
5420 | mutex_unlock(&ar->conf_mutex); | |
5421 | ||
5422 | return 0; | |
5423 | } | |
5424 | ||
5425 | static void ath12k_mac_op_remove_chanctx(struct ieee80211_hw *hw, | |
5426 | struct ieee80211_chanctx_conf *ctx) | |
5427 | { | |
5428 | struct ath12k *ar = hw->priv; | |
5429 | struct ath12k_base *ab = ar->ab; | |
5430 | ||
5431 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5432 | "mac chanctx remove freq %u width %d ptr %pK\n", | |
5433 | ctx->def.chan->center_freq, ctx->def.width, ctx); | |
5434 | ||
5435 | mutex_lock(&ar->conf_mutex); | |
5436 | ||
5437 | spin_lock_bh(&ar->data_lock); | |
5438 | /* TODO: In case of there is one more channel context left, populate | |
5439 | * rx_channel with the channel of that remaining channel context. | |
5440 | */ | |
5441 | ar->rx_channel = NULL; | |
5442 | spin_unlock_bh(&ar->data_lock); | |
5443 | ||
5444 | mutex_unlock(&ar->conf_mutex); | |
5445 | } | |
5446 | ||
5447 | static int | |
5448 | ath12k_mac_vdev_start_restart(struct ath12k_vif *arvif, | |
5449 | const struct cfg80211_chan_def *chandef, | |
5450 | bool restart) | |
5451 | { | |
5452 | struct ath12k *ar = arvif->ar; | |
5453 | struct ath12k_base *ab = ar->ab; | |
5454 | struct wmi_vdev_start_req_arg arg = {}; | |
5455 | int he_support = arvif->vif->bss_conf.he_support; | |
5456 | int ret; | |
5457 | ||
5458 | lockdep_assert_held(&ar->conf_mutex); | |
5459 | ||
5460 | reinit_completion(&ar->vdev_setup_done); | |
5461 | ||
5462 | arg.vdev_id = arvif->vdev_id; | |
5463 | arg.dtim_period = arvif->dtim_period; | |
5464 | arg.bcn_intval = arvif->beacon_interval; | |
5465 | ||
5466 | arg.freq = chandef->chan->center_freq; | |
5467 | arg.band_center_freq1 = chandef->center_freq1; | |
5468 | arg.band_center_freq2 = chandef->center_freq2; | |
5469 | arg.mode = ath12k_phymodes[chandef->chan->band][chandef->width]; | |
5470 | ||
5471 | arg.min_power = 0; | |
5472 | arg.max_power = chandef->chan->max_power * 2; | |
5473 | arg.max_reg_power = chandef->chan->max_reg_power * 2; | |
5474 | arg.max_antenna_gain = chandef->chan->max_antenna_gain * 2; | |
5475 | ||
5476 | arg.pref_tx_streams = ar->num_tx_chains; | |
5477 | arg.pref_rx_streams = ar->num_rx_chains; | |
5478 | ||
5479 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
5480 | arg.ssid = arvif->u.ap.ssid; | |
5481 | arg.ssid_len = arvif->u.ap.ssid_len; | |
5482 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; | |
5483 | ||
5484 | /* For now allow DFS for AP mode */ | |
5485 | arg.chan_radar = !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); | |
5486 | ||
5487 | arg.passive = arg.chan_radar; | |
5488 | ||
5489 | spin_lock_bh(&ab->base_lock); | |
5490 | arg.regdomain = ar->ab->dfs_region; | |
5491 | spin_unlock_bh(&ab->base_lock); | |
5492 | ||
5493 | /* TODO: Notify if secondary 80Mhz also needs radar detection */ | |
5494 | if (he_support) { | |
5495 | ret = ath12k_set_he_mu_sounding_mode(ar, arvif); | |
5496 | if (ret) { | |
5497 | ath12k_warn(ar->ab, "failed to set he mode vdev %i\n", | |
5498 | arg.vdev_id); | |
5499 | return ret; | |
5500 | } | |
5501 | } | |
5502 | } | |
5503 | ||
5504 | arg.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); | |
5505 | ||
5506 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5507 | "mac vdev %d start center_freq %d phymode %s\n", | |
5508 | arg.vdev_id, arg.freq, | |
5509 | ath12k_mac_phymode_str(arg.mode)); | |
5510 | ||
5511 | ret = ath12k_wmi_vdev_start(ar, &arg, restart); | |
5512 | if (ret) { | |
5513 | ath12k_warn(ar->ab, "failed to %s WMI vdev %i\n", | |
5514 | restart ? "restart" : "start", arg.vdev_id); | |
5515 | return ret; | |
5516 | } | |
5517 | ||
5518 | ret = ath12k_mac_vdev_setup_sync(ar); | |
5519 | if (ret) { | |
5520 | ath12k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n", | |
5521 | arg.vdev_id, restart ? "restart" : "start", ret); | |
5522 | return ret; | |
5523 | } | |
5524 | ||
5525 | ar->num_started_vdevs++; | |
5526 | ath12k_dbg(ab, ATH12K_DBG_MAC, "vdev %pM started, vdev_id %d\n", | |
5527 | arvif->vif->addr, arvif->vdev_id); | |
5528 | ||
5529 | /* Enable CAC Flag in the driver by checking the channel DFS cac time, | |
5530 | * i.e dfs_cac_ms value which will be valid only for radar channels | |
5531 | * and state as NL80211_DFS_USABLE which indicates CAC needs to be | |
5532 | * done before channel usage. This flags is used to drop rx packets. | |
5533 | * during CAC. | |
5534 | */ | |
5535 | /* TODO: Set the flag for other interface types as required */ | |
5536 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP && | |
5537 | chandef->chan->dfs_cac_ms && | |
5538 | chandef->chan->dfs_state == NL80211_DFS_USABLE) { | |
5539 | set_bit(ATH12K_CAC_RUNNING, &ar->dev_flags); | |
5540 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5541 | "CAC Started in chan_freq %d for vdev %d\n", | |
5542 | arg.freq, arg.vdev_id); | |
5543 | } | |
5544 | ||
5545 | ret = ath12k_mac_set_txbf_conf(arvif); | |
5546 | if (ret) | |
5547 | ath12k_warn(ab, "failed to set txbf conf for vdev %d: %d\n", | |
5548 | arvif->vdev_id, ret); | |
5549 | ||
5550 | return 0; | |
5551 | } | |
5552 | ||
5553 | static int ath12k_mac_vdev_stop(struct ath12k_vif *arvif) | |
5554 | { | |
5555 | struct ath12k *ar = arvif->ar; | |
5556 | int ret; | |
5557 | ||
5558 | lockdep_assert_held(&ar->conf_mutex); | |
5559 | ||
5560 | reinit_completion(&ar->vdev_setup_done); | |
5561 | ||
5562 | ret = ath12k_wmi_vdev_stop(ar, arvif->vdev_id); | |
5563 | if (ret) { | |
5564 | ath12k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n", | |
5565 | arvif->vdev_id, ret); | |
5566 | goto err; | |
5567 | } | |
5568 | ||
5569 | ret = ath12k_mac_vdev_setup_sync(ar); | |
5570 | if (ret) { | |
5571 | ath12k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n", | |
5572 | arvif->vdev_id, ret); | |
5573 | goto err; | |
5574 | } | |
5575 | ||
5576 | WARN_ON(ar->num_started_vdevs == 0); | |
5577 | ||
5578 | ar->num_started_vdevs--; | |
5579 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n", | |
5580 | arvif->vif->addr, arvif->vdev_id); | |
5581 | ||
5582 | if (test_bit(ATH12K_CAC_RUNNING, &ar->dev_flags)) { | |
5583 | clear_bit(ATH12K_CAC_RUNNING, &ar->dev_flags); | |
5584 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "CAC Stopped for vdev %d\n", | |
5585 | arvif->vdev_id); | |
5586 | } | |
5587 | ||
5588 | return 0; | |
5589 | err: | |
5590 | return ret; | |
5591 | } | |
5592 | ||
5593 | static int ath12k_mac_vdev_start(struct ath12k_vif *arvif, | |
5594 | const struct cfg80211_chan_def *chandef) | |
5595 | { | |
5596 | return ath12k_mac_vdev_start_restart(arvif, chandef, false); | |
5597 | } | |
5598 | ||
5599 | static int ath12k_mac_vdev_restart(struct ath12k_vif *arvif, | |
5600 | const struct cfg80211_chan_def *chandef) | |
5601 | { | |
5602 | return ath12k_mac_vdev_start_restart(arvif, chandef, true); | |
5603 | } | |
5604 | ||
5605 | struct ath12k_mac_change_chanctx_arg { | |
5606 | struct ieee80211_chanctx_conf *ctx; | |
5607 | struct ieee80211_vif_chanctx_switch *vifs; | |
5608 | int n_vifs; | |
5609 | int next_vif; | |
5610 | }; | |
5611 | ||
5612 | static void | |
5613 | ath12k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, | |
5614 | struct ieee80211_vif *vif) | |
5615 | { | |
5616 | struct ath12k_mac_change_chanctx_arg *arg = data; | |
5617 | ||
5618 | if (rcu_access_pointer(vif->bss_conf.chanctx_conf) != arg->ctx) | |
5619 | return; | |
5620 | ||
5621 | arg->n_vifs++; | |
5622 | } | |
5623 | ||
5624 | static void | |
5625 | ath12k_mac_change_chanctx_fill_iter(void *data, u8 *mac, | |
5626 | struct ieee80211_vif *vif) | |
5627 | { | |
5628 | struct ath12k_mac_change_chanctx_arg *arg = data; | |
5629 | struct ieee80211_chanctx_conf *ctx; | |
5630 | ||
5631 | ctx = rcu_access_pointer(vif->bss_conf.chanctx_conf); | |
5632 | if (ctx != arg->ctx) | |
5633 | return; | |
5634 | ||
5635 | if (WARN_ON(arg->next_vif == arg->n_vifs)) | |
5636 | return; | |
5637 | ||
5638 | arg->vifs[arg->next_vif].vif = vif; | |
5639 | arg->vifs[arg->next_vif].old_ctx = ctx; | |
5640 | arg->vifs[arg->next_vif].new_ctx = ctx; | |
5641 | arg->next_vif++; | |
5642 | } | |
5643 | ||
5644 | static void | |
5645 | ath12k_mac_update_vif_chan(struct ath12k *ar, | |
5646 | struct ieee80211_vif_chanctx_switch *vifs, | |
5647 | int n_vifs) | |
5648 | { | |
5649 | struct ath12k_base *ab = ar->ab; | |
5650 | struct ath12k_vif *arvif; | |
5651 | int ret; | |
5652 | int i; | |
5653 | bool monitor_vif = false; | |
5654 | ||
5655 | lockdep_assert_held(&ar->conf_mutex); | |
5656 | ||
5657 | for (i = 0; i < n_vifs; i++) { | |
5658 | arvif = (void *)vifs[i].vif->drv_priv; | |
5659 | ||
5660 | if (vifs[i].vif->type == NL80211_IFTYPE_MONITOR) | |
5661 | monitor_vif = true; | |
5662 | ||
5663 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5664 | "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n", | |
5665 | arvif->vdev_id, | |
5666 | vifs[i].old_ctx->def.chan->center_freq, | |
5667 | vifs[i].new_ctx->def.chan->center_freq, | |
5668 | vifs[i].old_ctx->def.width, | |
5669 | vifs[i].new_ctx->def.width); | |
5670 | ||
5671 | if (WARN_ON(!arvif->is_started)) | |
5672 | continue; | |
5673 | ||
5674 | if (WARN_ON(!arvif->is_up)) | |
5675 | continue; | |
5676 | ||
5677 | ret = ath12k_wmi_vdev_down(ar, arvif->vdev_id); | |
5678 | if (ret) { | |
5679 | ath12k_warn(ab, "failed to down vdev %d: %d\n", | |
5680 | arvif->vdev_id, ret); | |
5681 | continue; | |
5682 | } | |
5683 | } | |
5684 | ||
5685 | /* All relevant vdevs are downed and associated channel resources | |
5686 | * should be available for the channel switch now. | |
5687 | */ | |
5688 | ||
5689 | /* TODO: Update ar->rx_channel */ | |
5690 | ||
5691 | for (i = 0; i < n_vifs; i++) { | |
5692 | arvif = (void *)vifs[i].vif->drv_priv; | |
5693 | ||
5694 | if (WARN_ON(!arvif->is_started)) | |
5695 | continue; | |
5696 | ||
5697 | if (WARN_ON(!arvif->is_up)) | |
5698 | continue; | |
5699 | ||
5700 | ret = ath12k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def); | |
5701 | if (ret) { | |
5702 | ath12k_warn(ab, "failed to restart vdev %d: %d\n", | |
5703 | arvif->vdev_id, ret); | |
5704 | continue; | |
5705 | } | |
5706 | ||
5707 | ret = ath12k_mac_setup_bcn_tmpl(arvif); | |
5708 | if (ret) | |
5709 | ath12k_warn(ab, "failed to update bcn tmpl during csa: %d\n", | |
5710 | ret); | |
5711 | ||
5712 | ret = ath12k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
5713 | arvif->bssid); | |
5714 | if (ret) { | |
5715 | ath12k_warn(ab, "failed to bring vdev up %d: %d\n", | |
5716 | arvif->vdev_id, ret); | |
5717 | continue; | |
5718 | } | |
5719 | } | |
5720 | ||
5721 | /* Restart the internal monitor vdev on new channel */ | |
5722 | if (!monitor_vif && ar->monitor_vdev_created) { | |
5723 | if (!ath12k_mac_monitor_stop(ar)) | |
5724 | ath12k_mac_monitor_start(ar); | |
5725 | } | |
5726 | } | |
5727 | ||
5728 | static void | |
5729 | ath12k_mac_update_active_vif_chan(struct ath12k *ar, | |
5730 | struct ieee80211_chanctx_conf *ctx) | |
5731 | { | |
5732 | struct ath12k_mac_change_chanctx_arg arg = { .ctx = ctx }; | |
5733 | ||
5734 | lockdep_assert_held(&ar->conf_mutex); | |
5735 | ||
5736 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
5737 | IEEE80211_IFACE_ITER_NORMAL, | |
5738 | ath12k_mac_change_chanctx_cnt_iter, | |
5739 | &arg); | |
5740 | if (arg.n_vifs == 0) | |
5741 | return; | |
5742 | ||
5743 | arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL); | |
5744 | if (!arg.vifs) | |
5745 | return; | |
5746 | ||
5747 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
5748 | IEEE80211_IFACE_ITER_NORMAL, | |
5749 | ath12k_mac_change_chanctx_fill_iter, | |
5750 | &arg); | |
5751 | ||
5752 | ath12k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); | |
5753 | ||
5754 | kfree(arg.vifs); | |
5755 | } | |
5756 | ||
5757 | static void ath12k_mac_op_change_chanctx(struct ieee80211_hw *hw, | |
5758 | struct ieee80211_chanctx_conf *ctx, | |
5759 | u32 changed) | |
5760 | { | |
5761 | struct ath12k *ar = hw->priv; | |
5762 | struct ath12k_base *ab = ar->ab; | |
5763 | ||
5764 | mutex_lock(&ar->conf_mutex); | |
5765 | ||
5766 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5767 | "mac chanctx change freq %u width %d ptr %pK changed %x\n", | |
5768 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); | |
5769 | ||
5770 | /* This shouldn't really happen because channel switching should use | |
5771 | * switch_vif_chanctx(). | |
5772 | */ | |
5773 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) | |
5774 | goto unlock; | |
5775 | ||
5776 | if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) | |
5777 | ath12k_mac_update_active_vif_chan(ar, ctx); | |
5778 | ||
5779 | /* TODO: Recalc radar detection */ | |
5780 | ||
5781 | unlock: | |
5782 | mutex_unlock(&ar->conf_mutex); | |
5783 | } | |
5784 | ||
5785 | static int ath12k_start_vdev_delay(struct ieee80211_hw *hw, | |
5786 | struct ieee80211_vif *vif) | |
5787 | { | |
5788 | struct ath12k *ar = hw->priv; | |
5789 | struct ath12k_base *ab = ar->ab; | |
5790 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
5791 | int ret; | |
5792 | ||
5793 | if (WARN_ON(arvif->is_started)) | |
5794 | return -EBUSY; | |
5795 | ||
5796 | ret = ath12k_mac_vdev_start(arvif, &arvif->chanctx.def); | |
5797 | if (ret) { | |
5798 | ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
5799 | arvif->vdev_id, vif->addr, | |
5800 | arvif->chanctx.def.chan->center_freq, ret); | |
5801 | return ret; | |
5802 | } | |
5803 | ||
5804 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { | |
5805 | ret = ath12k_monitor_vdev_up(ar, arvif->vdev_id); | |
5806 | if (ret) { | |
5807 | ath12k_warn(ab, "failed put monitor up: %d\n", ret); | |
5808 | return ret; | |
5809 | } | |
5810 | } | |
5811 | ||
5812 | arvif->is_started = true; | |
5813 | ||
5814 | /* TODO: Setup ps and cts/rts protection */ | |
5815 | return 0; | |
5816 | } | |
5817 | ||
5818 | static int | |
5819 | ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, | |
5820 | struct ieee80211_vif *vif, | |
5821 | struct ieee80211_bss_conf *link_conf, | |
5822 | struct ieee80211_chanctx_conf *ctx) | |
5823 | { | |
5824 | struct ath12k *ar = hw->priv; | |
5825 | struct ath12k_base *ab = ar->ab; | |
5826 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
5827 | int ret; | |
5828 | struct ath12k_wmi_peer_create_arg param; | |
5829 | ||
5830 | mutex_lock(&ar->conf_mutex); | |
5831 | ||
5832 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5833 | "mac chanctx assign ptr %pK vdev_id %i\n", | |
5834 | ctx, arvif->vdev_id); | |
5835 | ||
5836 | /* for some targets bss peer must be created before vdev_start */ | |
5837 | if (ab->hw_params->vdev_start_delay && | |
5838 | arvif->vdev_type != WMI_VDEV_TYPE_AP && | |
5839 | arvif->vdev_type != WMI_VDEV_TYPE_MONITOR && | |
5840 | !ath12k_peer_exist_by_vdev_id(ab, arvif->vdev_id)) { | |
5841 | memcpy(&arvif->chanctx, ctx, sizeof(*ctx)); | |
5842 | ret = 0; | |
5843 | goto out; | |
5844 | } | |
5845 | ||
5846 | if (WARN_ON(arvif->is_started)) { | |
5847 | ret = -EBUSY; | |
5848 | goto out; | |
5849 | } | |
5850 | ||
5851 | if (ab->hw_params->vdev_start_delay && | |
5852 | (arvif->vdev_type == WMI_VDEV_TYPE_AP || | |
5853 | arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)) { | |
5854 | param.vdev_id = arvif->vdev_id; | |
5855 | param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
5856 | param.peer_addr = ar->mac_addr; | |
5857 | ||
5858 | ret = ath12k_peer_create(ar, arvif, NULL, ¶m); | |
5859 | if (ret) { | |
5860 | ath12k_warn(ab, "failed to create peer after vdev start delay: %d", | |
5861 | ret); | |
5862 | goto out; | |
5863 | } | |
5864 | } | |
5865 | ||
5866 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { | |
5867 | ret = ath12k_mac_monitor_start(ar); | |
5868 | if (ret) | |
5869 | goto out; | |
5870 | arvif->is_started = true; | |
5871 | goto out; | |
5872 | } | |
5873 | ||
5874 | ret = ath12k_mac_vdev_start(arvif, &ctx->def); | |
5875 | if (ret) { | |
5876 | ath12k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
5877 | arvif->vdev_id, vif->addr, | |
5878 | ctx->def.chan->center_freq, ret); | |
5879 | goto out; | |
5880 | } | |
5881 | ||
5882 | if (arvif->vdev_type != WMI_VDEV_TYPE_MONITOR && ar->monitor_vdev_created) | |
5883 | ath12k_mac_monitor_start(ar); | |
5884 | ||
5885 | arvif->is_started = true; | |
5886 | ||
5887 | /* TODO: Setup ps and cts/rts protection */ | |
5888 | ||
5889 | out: | |
5890 | mutex_unlock(&ar->conf_mutex); | |
5891 | ||
5892 | return ret; | |
5893 | } | |
5894 | ||
5895 | static void | |
5896 | ath12k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
5897 | struct ieee80211_vif *vif, | |
5898 | struct ieee80211_bss_conf *link_conf, | |
5899 | struct ieee80211_chanctx_conf *ctx) | |
5900 | { | |
5901 | struct ath12k *ar = hw->priv; | |
5902 | struct ath12k_base *ab = ar->ab; | |
5903 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
5904 | int ret; | |
5905 | ||
5906 | mutex_lock(&ar->conf_mutex); | |
5907 | ||
5908 | ath12k_dbg(ab, ATH12K_DBG_MAC, | |
5909 | "mac chanctx unassign ptr %pK vdev_id %i\n", | |
5910 | ctx, arvif->vdev_id); | |
5911 | ||
5912 | WARN_ON(!arvif->is_started); | |
5913 | ||
5914 | if (ab->hw_params->vdev_start_delay && | |
5915 | arvif->vdev_type == WMI_VDEV_TYPE_MONITOR && | |
5916 | ath12k_peer_find_by_addr(ab, ar->mac_addr)) | |
5917 | ath12k_peer_delete(ar, arvif->vdev_id, ar->mac_addr); | |
5918 | ||
5919 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { | |
5920 | ret = ath12k_mac_monitor_stop(ar); | |
5921 | if (ret) { | |
5922 | mutex_unlock(&ar->conf_mutex); | |
5923 | return; | |
5924 | } | |
5925 | ||
5926 | arvif->is_started = false; | |
5927 | mutex_unlock(&ar->conf_mutex); | |
5928 | } | |
5929 | ||
5930 | ret = ath12k_mac_vdev_stop(arvif); | |
5931 | if (ret) | |
5932 | ath12k_warn(ab, "failed to stop vdev %i: %d\n", | |
5933 | arvif->vdev_id, ret); | |
5934 | ||
5935 | arvif->is_started = false; | |
5936 | ||
5937 | if (ab->hw_params->vdev_start_delay && | |
5938 | arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) | |
5939 | ath12k_wmi_vdev_down(ar, arvif->vdev_id); | |
5940 | ||
5941 | if (arvif->vdev_type != WMI_VDEV_TYPE_MONITOR && | |
5942 | ar->num_started_vdevs == 1 && ar->monitor_vdev_created) | |
5943 | ath12k_mac_monitor_stop(ar); | |
5944 | ||
5945 | mutex_unlock(&ar->conf_mutex); | |
5946 | } | |
5947 | ||
5948 | static int | |
5949 | ath12k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, | |
5950 | struct ieee80211_vif_chanctx_switch *vifs, | |
5951 | int n_vifs, | |
5952 | enum ieee80211_chanctx_switch_mode mode) | |
5953 | { | |
5954 | struct ath12k *ar = hw->priv; | |
5955 | ||
5956 | mutex_lock(&ar->conf_mutex); | |
5957 | ||
5958 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
5959 | "mac chanctx switch n_vifs %d mode %d\n", | |
5960 | n_vifs, mode); | |
5961 | ath12k_mac_update_vif_chan(ar, vifs, n_vifs); | |
5962 | ||
5963 | mutex_unlock(&ar->conf_mutex); | |
5964 | ||
5965 | return 0; | |
5966 | } | |
5967 | ||
5968 | static int | |
5969 | ath12k_set_vdev_param_to_all_vifs(struct ath12k *ar, int param, u32 value) | |
5970 | { | |
5971 | struct ath12k_vif *arvif; | |
5972 | int ret = 0; | |
5973 | ||
5974 | mutex_lock(&ar->conf_mutex); | |
5975 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
5976 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "setting mac vdev %d param %d value %d\n", | |
5977 | param, arvif->vdev_id, value); | |
5978 | ||
5979 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5980 | param, value); | |
5981 | if (ret) { | |
5982 | ath12k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n", | |
5983 | param, arvif->vdev_id, ret); | |
5984 | break; | |
5985 | } | |
5986 | } | |
5987 | mutex_unlock(&ar->conf_mutex); | |
5988 | return ret; | |
5989 | } | |
5990 | ||
5991 | /* mac80211 stores device specific RTS/Fragmentation threshold value, | |
5992 | * this is set interface specific to firmware from ath12k driver | |
5993 | */ | |
5994 | static int ath12k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
5995 | { | |
5996 | struct ath12k *ar = hw->priv; | |
5997 | int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
5998 | ||
5999 | return ath12k_set_vdev_param_to_all_vifs(ar, param_id, value); | |
6000 | } | |
6001 | ||
6002 | static int ath12k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) | |
6003 | { | |
6004 | /* Even though there's a WMI vdev param for fragmentation threshold no | |
6005 | * known firmware actually implements it. Moreover it is not possible to | |
6006 | * rely frame fragmentation to mac80211 because firmware clears the | |
6007 | * "more fragments" bit in frame control making it impossible for remote | |
6008 | * devices to reassemble frames. | |
6009 | * | |
6010 | * Hence implement a dummy callback just to say fragmentation isn't | |
6011 | * supported. This effectively prevents mac80211 from doing frame | |
6012 | * fragmentation in software. | |
6013 | */ | |
6014 | return -EOPNOTSUPP; | |
6015 | } | |
6016 | ||
6017 | static void ath12k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |
6018 | u32 queues, bool drop) | |
6019 | { | |
6020 | struct ath12k *ar = hw->priv; | |
6021 | long time_left; | |
6022 | ||
6023 | if (drop) | |
6024 | return; | |
6025 | ||
6026 | time_left = wait_event_timeout(ar->dp.tx_empty_waitq, | |
6027 | (atomic_read(&ar->dp.num_tx_pending) == 0), | |
6028 | ATH12K_FLUSH_TIMEOUT); | |
6029 | if (time_left == 0) | |
6030 | ath12k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left); | |
5189a8db K |
6031 | |
6032 | time_left = wait_event_timeout(ar->txmgmt_empty_waitq, | |
6033 | (atomic_read(&ar->num_pending_mgmt_tx) == 0), | |
6034 | ATH12K_FLUSH_TIMEOUT); | |
6035 | if (time_left == 0) | |
6036 | ath12k_warn(ar->ab, "failed to flush mgmt transmit queue %ld\n", | |
6037 | time_left); | |
d8899132 KV |
6038 | } |
6039 | ||
6040 | static int | |
6041 | ath12k_mac_bitrate_mask_num_ht_rates(struct ath12k *ar, | |
6042 | enum nl80211_band band, | |
6043 | const struct cfg80211_bitrate_mask *mask) | |
6044 | { | |
6045 | int num_rates = 0; | |
6046 | int i; | |
6047 | ||
6048 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) | |
6049 | num_rates += hweight16(mask->control[band].ht_mcs[i]); | |
6050 | ||
6051 | return num_rates; | |
6052 | } | |
6053 | ||
6054 | static bool | |
6055 | ath12k_mac_has_single_legacy_rate(struct ath12k *ar, | |
6056 | enum nl80211_band band, | |
6057 | const struct cfg80211_bitrate_mask *mask) | |
6058 | { | |
6059 | int num_rates = 0; | |
6060 | ||
6061 | num_rates = hweight32(mask->control[band].legacy); | |
6062 | ||
6063 | if (ath12k_mac_bitrate_mask_num_ht_rates(ar, band, mask)) | |
6064 | return false; | |
6065 | ||
6066 | if (ath12k_mac_bitrate_mask_num_vht_rates(ar, band, mask)) | |
6067 | return false; | |
6068 | ||
6069 | return num_rates == 1; | |
6070 | } | |
6071 | ||
6072 | static bool | |
6073 | ath12k_mac_bitrate_mask_get_single_nss(struct ath12k *ar, | |
6074 | enum nl80211_band band, | |
6075 | const struct cfg80211_bitrate_mask *mask, | |
6076 | int *nss) | |
6077 | { | |
6078 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; | |
6079 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
6080 | u8 ht_nss_mask = 0; | |
6081 | u8 vht_nss_mask = 0; | |
6082 | int i; | |
6083 | ||
6084 | /* No need to consider legacy here. Basic rates are always present | |
6085 | * in bitrate mask | |
6086 | */ | |
6087 | ||
6088 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { | |
6089 | if (mask->control[band].ht_mcs[i] == 0) | |
6090 | continue; | |
6091 | else if (mask->control[band].ht_mcs[i] == | |
6092 | sband->ht_cap.mcs.rx_mask[i]) | |
6093 | ht_nss_mask |= BIT(i); | |
6094 | else | |
6095 | return false; | |
6096 | } | |
6097 | ||
6098 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
6099 | if (mask->control[band].vht_mcs[i] == 0) | |
6100 | continue; | |
6101 | else if (mask->control[band].vht_mcs[i] == | |
6102 | ath12k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) | |
6103 | vht_nss_mask |= BIT(i); | |
6104 | else | |
6105 | return false; | |
6106 | } | |
6107 | ||
6108 | if (ht_nss_mask != vht_nss_mask) | |
6109 | return false; | |
6110 | ||
6111 | if (ht_nss_mask == 0) | |
6112 | return false; | |
6113 | ||
6114 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) | |
6115 | return false; | |
6116 | ||
6117 | *nss = fls(ht_nss_mask); | |
6118 | ||
6119 | return true; | |
6120 | } | |
6121 | ||
6122 | static int | |
6123 | ath12k_mac_get_single_legacy_rate(struct ath12k *ar, | |
6124 | enum nl80211_band band, | |
6125 | const struct cfg80211_bitrate_mask *mask, | |
6126 | u32 *rate, u8 *nss) | |
6127 | { | |
6128 | int rate_idx; | |
6129 | u16 bitrate; | |
6130 | u8 preamble; | |
6131 | u8 hw_rate; | |
6132 | ||
6133 | if (hweight32(mask->control[band].legacy) != 1) | |
6134 | return -EINVAL; | |
6135 | ||
6136 | rate_idx = ffs(mask->control[band].legacy) - 1; | |
6137 | ||
6138 | if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ) | |
6139 | rate_idx += ATH12K_MAC_FIRST_OFDM_RATE_IDX; | |
6140 | ||
6141 | hw_rate = ath12k_legacy_rates[rate_idx].hw_value; | |
6142 | bitrate = ath12k_legacy_rates[rate_idx].bitrate; | |
6143 | ||
6144 | if (ath12k_mac_bitrate_is_cck(bitrate)) | |
6145 | preamble = WMI_RATE_PREAMBLE_CCK; | |
6146 | else | |
6147 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
6148 | ||
6149 | *nss = 1; | |
6150 | *rate = ATH12K_HW_RATE_CODE(hw_rate, 0, preamble); | |
6151 | ||
6152 | return 0; | |
6153 | } | |
6154 | ||
6155 | static int ath12k_mac_set_fixed_rate_params(struct ath12k_vif *arvif, | |
6156 | u32 rate, u8 nss, u8 sgi, u8 ldpc) | |
6157 | { | |
6158 | struct ath12k *ar = arvif->ar; | |
6159 | u32 vdev_param; | |
6160 | int ret; | |
6161 | ||
6162 | lockdep_assert_held(&ar->conf_mutex); | |
6163 | ||
6164 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n", | |
6165 | arvif->vdev_id, rate, nss, sgi); | |
6166 | ||
6167 | vdev_param = WMI_VDEV_PARAM_FIXED_RATE; | |
6168 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
6169 | vdev_param, rate); | |
6170 | if (ret) { | |
6171 | ath12k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n", | |
6172 | rate, ret); | |
6173 | return ret; | |
6174 | } | |
6175 | ||
6176 | vdev_param = WMI_VDEV_PARAM_NSS; | |
6177 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
6178 | vdev_param, nss); | |
6179 | if (ret) { | |
6180 | ath12k_warn(ar->ab, "failed to set nss param %d: %d\n", | |
6181 | nss, ret); | |
6182 | return ret; | |
6183 | } | |
6184 | ||
6185 | vdev_param = WMI_VDEV_PARAM_SGI; | |
6186 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
6187 | vdev_param, sgi); | |
6188 | if (ret) { | |
6189 | ath12k_warn(ar->ab, "failed to set sgi param %d: %d\n", | |
6190 | sgi, ret); | |
6191 | return ret; | |
6192 | } | |
6193 | ||
6194 | vdev_param = WMI_VDEV_PARAM_LDPC; | |
6195 | ret = ath12k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
6196 | vdev_param, ldpc); | |
6197 | if (ret) { | |
6198 | ath12k_warn(ar->ab, "failed to set ldpc param %d: %d\n", | |
6199 | ldpc, ret); | |
6200 | return ret; | |
6201 | } | |
6202 | ||
6203 | return 0; | |
6204 | } | |
6205 | ||
6206 | static bool | |
6207 | ath12k_mac_vht_mcs_range_present(struct ath12k *ar, | |
6208 | enum nl80211_band band, | |
6209 | const struct cfg80211_bitrate_mask *mask) | |
6210 | { | |
6211 | int i; | |
6212 | u16 vht_mcs; | |
6213 | ||
6214 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
6215 | vht_mcs = mask->control[band].vht_mcs[i]; | |
6216 | ||
6217 | switch (vht_mcs) { | |
6218 | case 0: | |
6219 | case BIT(8) - 1: | |
6220 | case BIT(9) - 1: | |
6221 | case BIT(10) - 1: | |
6222 | break; | |
6223 | default: | |
6224 | return false; | |
6225 | } | |
6226 | } | |
6227 | ||
6228 | return true; | |
6229 | } | |
6230 | ||
6231 | static void ath12k_mac_set_bitrate_mask_iter(void *data, | |
6232 | struct ieee80211_sta *sta) | |
6233 | { | |
6234 | struct ath12k_vif *arvif = data; | |
6235 | struct ath12k_sta *arsta = (struct ath12k_sta *)sta->drv_priv; | |
6236 | struct ath12k *ar = arvif->ar; | |
6237 | ||
6238 | spin_lock_bh(&ar->data_lock); | |
6239 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; | |
6240 | spin_unlock_bh(&ar->data_lock); | |
6241 | ||
6242 | ieee80211_queue_work(ar->hw, &arsta->update_wk); | |
6243 | } | |
6244 | ||
6245 | static void ath12k_mac_disable_peer_fixed_rate(void *data, | |
6246 | struct ieee80211_sta *sta) | |
6247 | { | |
6248 | struct ath12k_vif *arvif = data; | |
6249 | struct ath12k *ar = arvif->ar; | |
6250 | int ret; | |
6251 | ||
6252 | ret = ath12k_wmi_set_peer_param(ar, sta->addr, | |
6253 | arvif->vdev_id, | |
6254 | WMI_PEER_PARAM_FIXED_RATE, | |
6255 | WMI_FIXED_RATE_NONE); | |
6256 | if (ret) | |
6257 | ath12k_warn(ar->ab, | |
6258 | "failed to disable peer fixed rate for STA %pM ret %d\n", | |
6259 | sta->addr, ret); | |
6260 | } | |
6261 | ||
6262 | static int | |
6263 | ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, | |
6264 | struct ieee80211_vif *vif, | |
6265 | const struct cfg80211_bitrate_mask *mask) | |
6266 | { | |
6267 | struct ath12k_vif *arvif = (void *)vif->drv_priv; | |
6268 | struct cfg80211_chan_def def; | |
6269 | struct ath12k *ar = arvif->ar; | |
6270 | enum nl80211_band band; | |
6271 | const u8 *ht_mcs_mask; | |
6272 | const u16 *vht_mcs_mask; | |
6273 | u32 rate; | |
6274 | u8 nss; | |
6275 | u8 sgi; | |
6276 | u8 ldpc; | |
6277 | int single_nss; | |
6278 | int ret; | |
6279 | int num_rates; | |
6280 | ||
6281 | if (ath12k_mac_vif_chan(vif, &def)) | |
6282 | return -EPERM; | |
6283 | ||
6284 | band = def.chan->band; | |
6285 | ht_mcs_mask = mask->control[band].ht_mcs; | |
6286 | vht_mcs_mask = mask->control[band].vht_mcs; | |
6287 | ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); | |
6288 | ||
6289 | sgi = mask->control[band].gi; | |
6290 | if (sgi == NL80211_TXRATE_FORCE_LGI) | |
6291 | return -EINVAL; | |
6292 | ||
6293 | /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it | |
6294 | * requires passing at least one of used basic rates along with them. | |
6295 | * Fixed rate setting across different preambles(legacy, HT, VHT) is | |
6296 | * not supported by the FW. Hence use of FIXED_RATE vdev param is not | |
6297 | * suitable for setting single HT/VHT rates. | |
6298 | * But, there could be a single basic rate passed from userspace which | |
6299 | * can be done through the FIXED_RATE param. | |
6300 | */ | |
6301 | if (ath12k_mac_has_single_legacy_rate(ar, band, mask)) { | |
6302 | ret = ath12k_mac_get_single_legacy_rate(ar, band, mask, &rate, | |
6303 | &nss); | |
6304 | if (ret) { | |
6305 | ath12k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n", | |
6306 | arvif->vdev_id, ret); | |
6307 | return ret; | |
6308 | } | |
6309 | ieee80211_iterate_stations_atomic(ar->hw, | |
6310 | ath12k_mac_disable_peer_fixed_rate, | |
6311 | arvif); | |
6312 | } else if (ath12k_mac_bitrate_mask_get_single_nss(ar, band, mask, | |
6313 | &single_nss)) { | |
6314 | rate = WMI_FIXED_RATE_NONE; | |
6315 | nss = single_nss; | |
6316 | } else { | |
6317 | rate = WMI_FIXED_RATE_NONE; | |
6318 | nss = min_t(u32, ar->num_tx_chains, | |
6319 | max(ath12k_mac_max_ht_nss(ht_mcs_mask), | |
6320 | ath12k_mac_max_vht_nss(vht_mcs_mask))); | |
6321 | ||
6322 | /* If multiple rates across different preambles are given | |
6323 | * we can reconfigure this info with all peers using PEER_ASSOC | |
6324 | * command with the below exception cases. | |
6325 | * - Single VHT Rate : peer_assoc command accommodates only MCS | |
6326 | * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211 | |
6327 | * mandates passing basic rates along with HT/VHT rates, FW | |
6328 | * doesn't allow switching from VHT to Legacy. Hence instead of | |
6329 | * setting legacy and VHT rates using RATEMASK_CMD vdev cmd, | |
6330 | * we could set this VHT rate as peer fixed rate param, which | |
6331 | * will override FIXED rate and FW rate control algorithm. | |
6332 | * If single VHT rate is passed along with HT rates, we select | |
6333 | * the VHT rate as fixed rate for vht peers. | |
6334 | * - Multiple VHT Rates : When Multiple VHT rates are given,this | |
6335 | * can be set using RATEMASK CMD which uses FW rate-ctl alg. | |
6336 | * TODO: Setting multiple VHT MCS and replacing peer_assoc with | |
6337 | * RATEMASK_CMDID can cover all use cases of setting rates | |
6338 | * across multiple preambles and rates within same type. | |
6339 | * But requires more validation of the command at this point. | |
6340 | */ | |
6341 | ||
6342 | num_rates = ath12k_mac_bitrate_mask_num_vht_rates(ar, band, | |
6343 | mask); | |
6344 | ||
6345 | if (!ath12k_mac_vht_mcs_range_present(ar, band, mask) && | |
6346 | num_rates > 1) { | |
6347 | /* TODO: Handle multiple VHT MCS values setting using | |
6348 | * RATEMASK CMD | |
6349 | */ | |
6350 | ath12k_warn(ar->ab, | |
6351 | "Setting more than one MCS Value in bitrate mask not supported\n"); | |
6352 | return -EINVAL; | |
6353 | } | |
6354 | ||
6355 | ieee80211_iterate_stations_atomic(ar->hw, | |
6356 | ath12k_mac_disable_peer_fixed_rate, | |
6357 | arvif); | |
6358 | ||
6359 | mutex_lock(&ar->conf_mutex); | |
6360 | ||
6361 | arvif->bitrate_mask = *mask; | |
6362 | ieee80211_iterate_stations_atomic(ar->hw, | |
6363 | ath12k_mac_set_bitrate_mask_iter, | |
6364 | arvif); | |
6365 | ||
6366 | mutex_unlock(&ar->conf_mutex); | |
6367 | } | |
6368 | ||
6369 | mutex_lock(&ar->conf_mutex); | |
6370 | ||
6371 | ret = ath12k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); | |
6372 | if (ret) { | |
6373 | ath12k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n", | |
6374 | arvif->vdev_id, ret); | |
6375 | } | |
6376 | ||
6377 | mutex_unlock(&ar->conf_mutex); | |
6378 | ||
6379 | return ret; | |
6380 | } | |
6381 | ||
6382 | static void | |
6383 | ath12k_mac_op_reconfig_complete(struct ieee80211_hw *hw, | |
6384 | enum ieee80211_reconfig_type reconfig_type) | |
6385 | { | |
6386 | struct ath12k *ar = hw->priv; | |
6387 | struct ath12k_base *ab = ar->ab; | |
6388 | int recovery_count; | |
6389 | ||
6390 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) | |
6391 | return; | |
6392 | ||
6393 | mutex_lock(&ar->conf_mutex); | |
6394 | ||
6395 | if (ar->state == ATH12K_STATE_RESTARTED) { | |
6396 | ath12k_warn(ar->ab, "pdev %d successfully recovered\n", | |
6397 | ar->pdev->pdev_id); | |
6398 | ar->state = ATH12K_STATE_ON; | |
6399 | ieee80211_wake_queues(ar->hw); | |
6400 | ||
6401 | if (ab->is_reset) { | |
6402 | recovery_count = atomic_inc_return(&ab->recovery_count); | |
6403 | ath12k_dbg(ab, ATH12K_DBG_BOOT, "recovery count %d\n", | |
6404 | recovery_count); | |
6405 | /* When there are multiple radios in an SOC, | |
6406 | * the recovery has to be done for each radio | |
6407 | */ | |
6408 | if (recovery_count == ab->num_radios) { | |
6409 | atomic_dec(&ab->reset_count); | |
6410 | complete(&ab->reset_complete); | |
6411 | ab->is_reset = false; | |
6412 | atomic_set(&ab->fail_cont_count, 0); | |
6413 | ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset success\n"); | |
6414 | } | |
6415 | } | |
6416 | } | |
6417 | ||
6418 | mutex_unlock(&ar->conf_mutex); | |
6419 | } | |
6420 | ||
6421 | static void | |
6422 | ath12k_mac_update_bss_chan_survey(struct ath12k *ar, | |
6423 | struct ieee80211_channel *channel) | |
6424 | { | |
6425 | int ret; | |
6426 | enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; | |
6427 | ||
6428 | lockdep_assert_held(&ar->conf_mutex); | |
6429 | ||
6430 | if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) || | |
6431 | ar->rx_channel != channel) | |
6432 | return; | |
6433 | ||
6434 | if (ar->scan.state != ATH12K_SCAN_IDLE) { | |
6435 | ath12k_dbg(ar->ab, ATH12K_DBG_MAC, | |
6436 | "ignoring bss chan info req while scanning..\n"); | |
6437 | return; | |
6438 | } | |
6439 | ||
6440 | reinit_completion(&ar->bss_survey_done); | |
6441 | ||
6442 | ret = ath12k_wmi_pdev_bss_chan_info_request(ar, type); | |
6443 | if (ret) { | |
6444 | ath12k_warn(ar->ab, "failed to send pdev bss chan info request\n"); | |
6445 | return; | |
6446 | } | |
6447 | ||
6448 | ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); | |
6449 | if (ret == 0) | |
6450 | ath12k_warn(ar->ab, "bss channel survey timed out\n"); | |
6451 | } | |
6452 | ||
6453 | static int ath12k_mac_op_get_survey(struct ieee80211_hw *hw, int idx, | |
6454 | struct survey_info *survey) | |
6455 | { | |
6456 | struct ath12k *ar = hw->priv; | |
6457 | struct ieee80211_supported_band *sband; | |
6458 | struct survey_info *ar_survey; | |
6459 | int ret = 0; | |
6460 | ||
6461 | if (idx >= ATH12K_NUM_CHANS) | |
6462 | return -ENOENT; | |
6463 | ||
6464 | ar_survey = &ar->survey[idx]; | |
6465 | ||
6466 | mutex_lock(&ar->conf_mutex); | |
6467 | ||
6468 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; | |
6469 | if (sband && idx >= sband->n_channels) { | |
6470 | idx -= sband->n_channels; | |
6471 | sband = NULL; | |
6472 | } | |
6473 | ||
6474 | if (!sband) | |
6475 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; | |
6476 | ||
6477 | if (!sband || idx >= sband->n_channels) { | |
6478 | ret = -ENOENT; | |
6479 | goto exit; | |
6480 | } | |
6481 | ||
6482 | ath12k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); | |
6483 | ||
6484 | spin_lock_bh(&ar->data_lock); | |
6485 | memcpy(survey, ar_survey, sizeof(*survey)); | |
6486 | spin_unlock_bh(&ar->data_lock); | |
6487 | ||
6488 | survey->channel = &sband->channels[idx]; | |
6489 | ||
6490 | if (ar->rx_channel == survey->channel) | |
6491 | survey->filled |= SURVEY_INFO_IN_USE; | |
6492 | ||
6493 | exit: | |
6494 | mutex_unlock(&ar->conf_mutex); | |
6495 | return ret; | |
6496 | } | |
6497 | ||
6498 | static void ath12k_mac_op_sta_statistics(struct ieee80211_hw *hw, | |
6499 | struct ieee80211_vif *vif, | |
6500 | struct ieee80211_sta *sta, | |
6501 | struct station_info *sinfo) | |
6502 | { | |
6503 | struct ath12k_sta *arsta = (struct ath12k_sta *)sta->drv_priv; | |
6504 | ||
6505 | sinfo->rx_duration = arsta->rx_duration; | |
6506 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); | |
6507 | ||
6508 | sinfo->tx_duration = arsta->tx_duration; | |
6509 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); | |
6510 | ||
6511 | if (!arsta->txrate.legacy && !arsta->txrate.nss) | |
6512 | return; | |
6513 | ||
6514 | if (arsta->txrate.legacy) { | |
6515 | sinfo->txrate.legacy = arsta->txrate.legacy; | |
6516 | } else { | |
6517 | sinfo->txrate.mcs = arsta->txrate.mcs; | |
6518 | sinfo->txrate.nss = arsta->txrate.nss; | |
6519 | sinfo->txrate.bw = arsta->txrate.bw; | |
6520 | sinfo->txrate.he_gi = arsta->txrate.he_gi; | |
6521 | sinfo->txrate.he_dcm = arsta->txrate.he_dcm; | |
6522 | sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc; | |
6523 | } | |
6524 | sinfo->txrate.flags = arsta->txrate.flags; | |
6525 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); | |
6526 | ||
6527 | /* TODO: Use real NF instead of default one. */ | |
6528 | sinfo->signal = arsta->rssi_comb + ATH12K_DEFAULT_NOISE_FLOOR; | |
6529 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); | |
6530 | } | |
6531 | ||
6532 | static const struct ieee80211_ops ath12k_ops = { | |
6533 | .tx = ath12k_mac_op_tx, | |
6534 | .wake_tx_queue = ieee80211_handle_wake_tx_queue, | |
6535 | .start = ath12k_mac_op_start, | |
6536 | .stop = ath12k_mac_op_stop, | |
6537 | .reconfig_complete = ath12k_mac_op_reconfig_complete, | |
6538 | .add_interface = ath12k_mac_op_add_interface, | |
6539 | .remove_interface = ath12k_mac_op_remove_interface, | |
6540 | .update_vif_offload = ath12k_mac_op_update_vif_offload, | |
6541 | .config = ath12k_mac_op_config, | |
6542 | .bss_info_changed = ath12k_mac_op_bss_info_changed, | |
6543 | .configure_filter = ath12k_mac_op_configure_filter, | |
6544 | .hw_scan = ath12k_mac_op_hw_scan, | |
6545 | .cancel_hw_scan = ath12k_mac_op_cancel_hw_scan, | |
6546 | .set_key = ath12k_mac_op_set_key, | |
6547 | .sta_state = ath12k_mac_op_sta_state, | |
6548 | .sta_set_txpwr = ath12k_mac_op_sta_set_txpwr, | |
6549 | .sta_rc_update = ath12k_mac_op_sta_rc_update, | |
6550 | .conf_tx = ath12k_mac_op_conf_tx, | |
6551 | .set_antenna = ath12k_mac_op_set_antenna, | |
6552 | .get_antenna = ath12k_mac_op_get_antenna, | |
6553 | .ampdu_action = ath12k_mac_op_ampdu_action, | |
6554 | .add_chanctx = ath12k_mac_op_add_chanctx, | |
6555 | .remove_chanctx = ath12k_mac_op_remove_chanctx, | |
6556 | .change_chanctx = ath12k_mac_op_change_chanctx, | |
6557 | .assign_vif_chanctx = ath12k_mac_op_assign_vif_chanctx, | |
6558 | .unassign_vif_chanctx = ath12k_mac_op_unassign_vif_chanctx, | |
6559 | .switch_vif_chanctx = ath12k_mac_op_switch_vif_chanctx, | |
6560 | .set_rts_threshold = ath12k_mac_op_set_rts_threshold, | |
6561 | .set_frag_threshold = ath12k_mac_op_set_frag_threshold, | |
6562 | .set_bitrate_mask = ath12k_mac_op_set_bitrate_mask, | |
6563 | .get_survey = ath12k_mac_op_get_survey, | |
6564 | .flush = ath12k_mac_op_flush, | |
6565 | .sta_statistics = ath12k_mac_op_sta_statistics, | |
6566 | }; | |
6567 | ||
6568 | static void ath12k_mac_update_ch_list(struct ath12k *ar, | |
6569 | struct ieee80211_supported_band *band, | |
6570 | u32 freq_low, u32 freq_high) | |
6571 | { | |
6572 | int i; | |
6573 | ||
6574 | if (!(freq_low && freq_high)) | |
6575 | return; | |
6576 | ||
6577 | for (i = 0; i < band->n_channels; i++) { | |
6578 | if (band->channels[i].center_freq < freq_low || | |
6579 | band->channels[i].center_freq > freq_high) | |
6580 | band->channels[i].flags |= IEEE80211_CHAN_DISABLED; | |
6581 | } | |
6582 | } | |
6583 | ||
6584 | static u32 ath12k_get_phy_id(struct ath12k *ar, u32 band) | |
6585 | { | |
6586 | struct ath12k_pdev *pdev = ar->pdev; | |
6587 | struct ath12k_pdev_cap *pdev_cap = &pdev->cap; | |
6588 | ||
6589 | if (band == WMI_HOST_WLAN_2G_CAP) | |
6590 | return pdev_cap->band[NL80211_BAND_2GHZ].phy_id; | |
6591 | ||
6592 | if (band == WMI_HOST_WLAN_5G_CAP) | |
6593 | return pdev_cap->band[NL80211_BAND_5GHZ].phy_id; | |
6594 | ||
6595 | ath12k_warn(ar->ab, "unsupported phy cap:%d\n", band); | |
6596 | ||
6597 | return 0; | |
6598 | } | |
6599 | ||
6600 | static int ath12k_mac_setup_channels_rates(struct ath12k *ar, | |
6601 | u32 supported_bands) | |
6602 | { | |
6603 | struct ieee80211_supported_band *band; | |
6604 | struct ath12k_wmi_hal_reg_capabilities_ext_arg *reg_cap; | |
6605 | void *channels; | |
6606 | u32 phy_id; | |
6607 | ||
6608 | BUILD_BUG_ON((ARRAY_SIZE(ath12k_2ghz_channels) + | |
6609 | ARRAY_SIZE(ath12k_5ghz_channels) + | |
6610 | ARRAY_SIZE(ath12k_6ghz_channels)) != | |
6611 | ATH12K_NUM_CHANS); | |
6612 | ||
6613 | reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx]; | |
6614 | ||
6615 | if (supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
6616 | channels = kmemdup(ath12k_2ghz_channels, | |
6617 | sizeof(ath12k_2ghz_channels), | |
6618 | GFP_KERNEL); | |
6619 | if (!channels) | |
6620 | return -ENOMEM; | |
6621 | ||
6622 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
6623 | band->band = NL80211_BAND_2GHZ; | |
6624 | band->n_channels = ARRAY_SIZE(ath12k_2ghz_channels); | |
6625 | band->channels = channels; | |
6626 | band->n_bitrates = ath12k_g_rates_size; | |
6627 | band->bitrates = ath12k_g_rates; | |
6628 | ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band; | |
6629 | ||
6630 | if (ar->ab->hw_params->single_pdev_only) { | |
6631 | phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_2G_CAP); | |
6632 | reg_cap = &ar->ab->hal_reg_cap[phy_id]; | |
6633 | } | |
6634 | ath12k_mac_update_ch_list(ar, band, | |
6635 | reg_cap->low_2ghz_chan, | |
6636 | reg_cap->high_2ghz_chan); | |
6637 | } | |
6638 | ||
6639 | if (supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
6640 | if (reg_cap->high_5ghz_chan >= ATH12K_MAX_6G_FREQ) { | |
6641 | channels = kmemdup(ath12k_6ghz_channels, | |
6642 | sizeof(ath12k_6ghz_channels), GFP_KERNEL); | |
6643 | if (!channels) { | |
6644 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
6645 | return -ENOMEM; | |
6646 | } | |
6647 | ||
6648 | ar->supports_6ghz = true; | |
6649 | band = &ar->mac.sbands[NL80211_BAND_6GHZ]; | |
6650 | band->band = NL80211_BAND_6GHZ; | |
6651 | band->n_channels = ARRAY_SIZE(ath12k_6ghz_channels); | |
6652 | band->channels = channels; | |
6653 | band->n_bitrates = ath12k_a_rates_size; | |
6654 | band->bitrates = ath12k_a_rates; | |
6655 | ar->hw->wiphy->bands[NL80211_BAND_6GHZ] = band; | |
6656 | ath12k_mac_update_ch_list(ar, band, | |
6657 | reg_cap->low_5ghz_chan, | |
6658 | reg_cap->high_5ghz_chan); | |
6659 | } | |
6660 | ||
6661 | if (reg_cap->low_5ghz_chan < ATH12K_MIN_6G_FREQ) { | |
6662 | channels = kmemdup(ath12k_5ghz_channels, | |
6663 | sizeof(ath12k_5ghz_channels), | |
6664 | GFP_KERNEL); | |
6665 | if (!channels) { | |
6666 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
6667 | kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); | |
6668 | return -ENOMEM; | |
6669 | } | |
6670 | ||
6671 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
6672 | band->band = NL80211_BAND_5GHZ; | |
6673 | band->n_channels = ARRAY_SIZE(ath12k_5ghz_channels); | |
6674 | band->channels = channels; | |
6675 | band->n_bitrates = ath12k_a_rates_size; | |
6676 | band->bitrates = ath12k_a_rates; | |
6677 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band; | |
6678 | ||
6679 | if (ar->ab->hw_params->single_pdev_only) { | |
6680 | phy_id = ath12k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP); | |
6681 | reg_cap = &ar->ab->hal_reg_cap[phy_id]; | |
6682 | } | |
6683 | ||
6684 | ath12k_mac_update_ch_list(ar, band, | |
6685 | reg_cap->low_5ghz_chan, | |
6686 | reg_cap->high_5ghz_chan); | |
6687 | } | |
6688 | } | |
6689 | ||
6690 | return 0; | |
6691 | } | |
6692 | ||
6693 | static int ath12k_mac_setup_iface_combinations(struct ath12k *ar) | |
6694 | { | |
6695 | struct ath12k_base *ab = ar->ab; | |
6696 | struct ieee80211_iface_combination *combinations; | |
6697 | struct ieee80211_iface_limit *limits; | |
6698 | int n_limits, max_interfaces; | |
6699 | bool ap, mesh; | |
6700 | ||
6701 | ap = ab->hw_params->interface_modes & BIT(NL80211_IFTYPE_AP); | |
6702 | ||
6703 | mesh = IS_ENABLED(CONFIG_MAC80211_MESH) && | |
6704 | ab->hw_params->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT); | |
6705 | ||
6706 | combinations = kzalloc(sizeof(*combinations), GFP_KERNEL); | |
6707 | if (!combinations) | |
6708 | return -ENOMEM; | |
6709 | ||
6710 | if (ap || mesh) { | |
6711 | n_limits = 2; | |
6712 | max_interfaces = 16; | |
6713 | } else { | |
6714 | n_limits = 1; | |
6715 | max_interfaces = 1; | |
6716 | } | |
6717 | ||
6718 | limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL); | |
6719 | if (!limits) { | |
6720 | kfree(combinations); | |
6721 | return -ENOMEM; | |
6722 | } | |
6723 | ||
6724 | limits[0].max = 1; | |
6725 | limits[0].types |= BIT(NL80211_IFTYPE_STATION); | |
6726 | ||
6727 | if (ap) { | |
6728 | limits[1].max = max_interfaces; | |
6729 | limits[1].types |= BIT(NL80211_IFTYPE_AP); | |
6730 | } | |
6731 | ||
6732 | if (mesh) | |
6733 | limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT); | |
6734 | ||
6735 | combinations[0].limits = limits; | |
6736 | combinations[0].n_limits = n_limits; | |
6737 | combinations[0].max_interfaces = max_interfaces; | |
6738 | combinations[0].num_different_channels = 1; | |
6739 | combinations[0].beacon_int_infra_match = true; | |
6740 | combinations[0].beacon_int_min_gcd = 100; | |
6741 | combinations[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
6742 | BIT(NL80211_CHAN_WIDTH_20) | | |
6743 | BIT(NL80211_CHAN_WIDTH_40) | | |
6744 | BIT(NL80211_CHAN_WIDTH_80); | |
6745 | ||
6746 | ar->hw->wiphy->iface_combinations = combinations; | |
6747 | ar->hw->wiphy->n_iface_combinations = 1; | |
6748 | ||
6749 | return 0; | |
6750 | } | |
6751 | ||
6752 | static const u8 ath12k_if_types_ext_capa[] = { | |
6753 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
6754 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
6755 | }; | |
6756 | ||
6757 | static const u8 ath12k_if_types_ext_capa_sta[] = { | |
6758 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
6759 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
6760 | [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, | |
6761 | }; | |
6762 | ||
6763 | static const u8 ath12k_if_types_ext_capa_ap[] = { | |
6764 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
6765 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
6766 | [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, | |
6767 | }; | |
6768 | ||
6769 | static const struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = { | |
6770 | { | |
6771 | .extended_capabilities = ath12k_if_types_ext_capa, | |
6772 | .extended_capabilities_mask = ath12k_if_types_ext_capa, | |
6773 | .extended_capabilities_len = sizeof(ath12k_if_types_ext_capa), | |
6774 | }, { | |
6775 | .iftype = NL80211_IFTYPE_STATION, | |
6776 | .extended_capabilities = ath12k_if_types_ext_capa_sta, | |
6777 | .extended_capabilities_mask = ath12k_if_types_ext_capa_sta, | |
6778 | .extended_capabilities_len = | |
6779 | sizeof(ath12k_if_types_ext_capa_sta), | |
6780 | }, { | |
6781 | .iftype = NL80211_IFTYPE_AP, | |
6782 | .extended_capabilities = ath12k_if_types_ext_capa_ap, | |
6783 | .extended_capabilities_mask = ath12k_if_types_ext_capa_ap, | |
6784 | .extended_capabilities_len = | |
6785 | sizeof(ath12k_if_types_ext_capa_ap), | |
6786 | }, | |
6787 | }; | |
6788 | ||
6789 | static void __ath12k_mac_unregister(struct ath12k *ar) | |
6790 | { | |
6791 | cancel_work_sync(&ar->regd_update_work); | |
6792 | ||
6793 | ieee80211_unregister_hw(ar->hw); | |
6794 | ||
6795 | idr_for_each(&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar); | |
6796 | idr_destroy(&ar->txmgmt_idr); | |
6797 | ||
6798 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
6799 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
6800 | kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); | |
6801 | ||
6802 | kfree(ar->hw->wiphy->iface_combinations[0].limits); | |
6803 | kfree(ar->hw->wiphy->iface_combinations); | |
6804 | ||
6805 | SET_IEEE80211_DEV(ar->hw, NULL); | |
6806 | } | |
6807 | ||
6808 | void ath12k_mac_unregister(struct ath12k_base *ab) | |
6809 | { | |
6810 | struct ath12k *ar; | |
6811 | struct ath12k_pdev *pdev; | |
6812 | int i; | |
6813 | ||
6814 | for (i = 0; i < ab->num_radios; i++) { | |
6815 | pdev = &ab->pdevs[i]; | |
6816 | ar = pdev->ar; | |
6817 | if (!ar) | |
6818 | continue; | |
6819 | ||
6820 | __ath12k_mac_unregister(ar); | |
6821 | } | |
6822 | } | |
6823 | ||
6824 | static int __ath12k_mac_register(struct ath12k *ar) | |
6825 | { | |
6826 | struct ath12k_base *ab = ar->ab; | |
6827 | struct ath12k_pdev_cap *cap = &ar->pdev->cap; | |
6828 | static const u32 cipher_suites[] = { | |
6829 | WLAN_CIPHER_SUITE_TKIP, | |
6830 | WLAN_CIPHER_SUITE_CCMP, | |
6831 | WLAN_CIPHER_SUITE_AES_CMAC, | |
6832 | WLAN_CIPHER_SUITE_BIP_CMAC_256, | |
6833 | WLAN_CIPHER_SUITE_BIP_GMAC_128, | |
6834 | WLAN_CIPHER_SUITE_BIP_GMAC_256, | |
6835 | WLAN_CIPHER_SUITE_GCMP, | |
6836 | WLAN_CIPHER_SUITE_GCMP_256, | |
6837 | WLAN_CIPHER_SUITE_CCMP_256, | |
6838 | }; | |
6839 | int ret; | |
6840 | u32 ht_cap = 0; | |
6841 | ||
6842 | ath12k_pdev_caps_update(ar); | |
6843 | ||
6844 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); | |
6845 | ||
6846 | SET_IEEE80211_DEV(ar->hw, ab->dev); | |
6847 | ||
6848 | ret = ath12k_mac_setup_channels_rates(ar, | |
6849 | cap->supported_bands); | |
6850 | if (ret) | |
6851 | goto err; | |
6852 | ||
6853 | ath12k_mac_setup_ht_vht_cap(ar, cap, &ht_cap); | |
6854 | ath12k_mac_setup_he_cap(ar, cap); | |
6855 | ||
6856 | ret = ath12k_mac_setup_iface_combinations(ar); | |
6857 | if (ret) { | |
6858 | ath12k_err(ar->ab, "failed to setup interface combinations: %d\n", ret); | |
6859 | goto err_free_channels; | |
6860 | } | |
6861 | ||
6862 | ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask; | |
6863 | ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask; | |
6864 | ||
6865 | ar->hw->wiphy->interface_modes = ab->hw_params->interface_modes; | |
6866 | ||
6867 | ieee80211_hw_set(ar->hw, SIGNAL_DBM); | |
6868 | ieee80211_hw_set(ar->hw, SUPPORTS_PS); | |
6869 | ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS); | |
6870 | ieee80211_hw_set(ar->hw, MFP_CAPABLE); | |
6871 | ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS); | |
6872 | ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL); | |
6873 | ieee80211_hw_set(ar->hw, AP_LINK_PS); | |
6874 | ieee80211_hw_set(ar->hw, SPECTRUM_MGMT); | |
6875 | ieee80211_hw_set(ar->hw, CONNECTION_MONITOR); | |
6876 | ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK); | |
6877 | ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA); | |
6878 | ieee80211_hw_set(ar->hw, QUEUE_CONTROL); | |
6879 | ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG); | |
6880 | ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK); | |
6881 | ||
6882 | if (ht_cap & WMI_HT_CAP_ENABLED) { | |
6883 | ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION); | |
6884 | ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW); | |
6885 | ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER); | |
6886 | ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU); | |
6887 | ieee80211_hw_set(ar->hw, USES_RSS); | |
6888 | } | |
6889 | ||
6890 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; | |
6891 | ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; | |
6892 | ||
6893 | /* TODO: Check if HT capability advertised from firmware is different | |
6894 | * for each band for a dual band capable radio. It will be tricky to | |
6895 | * handle it when the ht capability different for each band. | |
6896 | */ | |
6897 | if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) | |
6898 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; | |
6899 | ||
6900 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; | |
6901 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; | |
6902 | ||
6903 | ar->hw->max_listen_interval = ATH12K_MAX_HW_LISTEN_INTERVAL; | |
6904 | ||
6905 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; | |
6906 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; | |
6907 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; | |
6908 | ||
6909 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
6910 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | | |
6911 | NL80211_FEATURE_AP_SCAN; | |
6912 | ||
6913 | ar->max_num_stations = TARGET_NUM_STATIONS; | |
6914 | ar->max_num_peers = TARGET_NUM_PEERS_PDEV; | |
6915 | ||
6916 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; | |
6917 | ||
6918 | ar->hw->queues = ATH12K_HW_MAX_QUEUES; | |
6919 | ar->hw->wiphy->tx_queue_len = ATH12K_QUEUE_LEN; | |
6920 | ar->hw->offchannel_tx_hw_queue = ATH12K_HW_MAX_QUEUES - 1; | |
6921 | ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE; | |
6922 | ||
6923 | ar->hw->vif_data_size = sizeof(struct ath12k_vif); | |
6924 | ar->hw->sta_data_size = sizeof(struct ath12k_sta); | |
6925 | ||
6926 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); | |
6927 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); | |
6928 | ||
6929 | ar->hw->wiphy->cipher_suites = cipher_suites; | |
6930 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
6931 | ||
6932 | ar->hw->wiphy->iftype_ext_capab = ath12k_iftypes_ext_capa; | |
6933 | ar->hw->wiphy->num_iftype_ext_capab = | |
6934 | ARRAY_SIZE(ath12k_iftypes_ext_capa); | |
6935 | ||
6936 | if (ar->supports_6ghz) { | |
6937 | wiphy_ext_feature_set(ar->hw->wiphy, | |
6938 | NL80211_EXT_FEATURE_FILS_DISCOVERY); | |
6939 | wiphy_ext_feature_set(ar->hw->wiphy, | |
6940 | NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP); | |
6941 | } | |
6942 | ||
6943 | ath12k_reg_init(ar); | |
6944 | ||
6945 | if (!test_bit(ATH12K_FLAG_RAW_MODE, &ab->dev_flags)) { | |
6946 | ar->hw->netdev_features = NETIF_F_HW_CSUM; | |
6947 | ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL); | |
6948 | ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT); | |
6949 | } | |
6950 | ||
6951 | ret = ieee80211_register_hw(ar->hw); | |
6952 | if (ret) { | |
6953 | ath12k_err(ar->ab, "ieee80211 registration failed: %d\n", ret); | |
6954 | goto err_free_if_combs; | |
6955 | } | |
6956 | ||
6957 | if (!ab->hw_params->supports_monitor) | |
6958 | /* There's a race between calling ieee80211_register_hw() | |
6959 | * and here where the monitor mode is enabled for a little | |
6960 | * while. But that time is so short and in practise it make | |
6961 | * a difference in real life. | |
6962 | */ | |
6963 | ar->hw->wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR); | |
6964 | ||
6965 | /* Apply the regd received during initialization */ | |
6966 | ret = ath12k_regd_update(ar, true); | |
6967 | if (ret) { | |
6968 | ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret); | |
6969 | goto err_unregister_hw; | |
6970 | } | |
6971 | ||
6972 | return 0; | |
6973 | ||
6974 | err_unregister_hw: | |
6975 | ieee80211_unregister_hw(ar->hw); | |
6976 | ||
6977 | err_free_if_combs: | |
6978 | kfree(ar->hw->wiphy->iface_combinations[0].limits); | |
6979 | kfree(ar->hw->wiphy->iface_combinations); | |
6980 | ||
6981 | err_free_channels: | |
6982 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
6983 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
6984 | kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); | |
6985 | ||
6986 | err: | |
6987 | SET_IEEE80211_DEV(ar->hw, NULL); | |
6988 | return ret; | |
6989 | } | |
6990 | ||
6991 | int ath12k_mac_register(struct ath12k_base *ab) | |
6992 | { | |
6993 | struct ath12k *ar; | |
6994 | struct ath12k_pdev *pdev; | |
6995 | int i; | |
6996 | int ret; | |
6997 | ||
6998 | if (test_bit(ATH12K_FLAG_REGISTERED, &ab->dev_flags)) | |
6999 | return 0; | |
7000 | ||
7001 | for (i = 0; i < ab->num_radios; i++) { | |
7002 | pdev = &ab->pdevs[i]; | |
7003 | ar = pdev->ar; | |
7004 | if (ab->pdevs_macaddr_valid) { | |
7005 | ether_addr_copy(ar->mac_addr, pdev->mac_addr); | |
7006 | } else { | |
7007 | ether_addr_copy(ar->mac_addr, ab->mac_addr); | |
7008 | ar->mac_addr[4] += i; | |
7009 | } | |
7010 | ||
7011 | ret = __ath12k_mac_register(ar); | |
7012 | if (ret) | |
7013 | goto err_cleanup; | |
7014 | ||
5189a8db | 7015 | init_waitqueue_head(&ar->txmgmt_empty_waitq); |
d8899132 KV |
7016 | idr_init(&ar->txmgmt_idr); |
7017 | spin_lock_init(&ar->txmgmt_idr_lock); | |
7018 | } | |
7019 | ||
7020 | /* Initialize channel counters frequency value in hertz */ | |
7021 | ab->cc_freq_hz = 320000; | |
7022 | ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1; | |
7023 | ||
7024 | return 0; | |
7025 | ||
7026 | err_cleanup: | |
7027 | for (i = i - 1; i >= 0; i--) { | |
7028 | pdev = &ab->pdevs[i]; | |
7029 | ar = pdev->ar; | |
7030 | __ath12k_mac_unregister(ar); | |
7031 | } | |
7032 | ||
7033 | return ret; | |
7034 | } | |
7035 | ||
7036 | int ath12k_mac_allocate(struct ath12k_base *ab) | |
7037 | { | |
7038 | struct ieee80211_hw *hw; | |
7039 | struct ath12k *ar; | |
7040 | struct ath12k_pdev *pdev; | |
7041 | int ret; | |
7042 | int i; | |
7043 | ||
7044 | if (test_bit(ATH12K_FLAG_REGISTERED, &ab->dev_flags)) | |
7045 | return 0; | |
7046 | ||
7047 | for (i = 0; i < ab->num_radios; i++) { | |
7048 | pdev = &ab->pdevs[i]; | |
7049 | hw = ieee80211_alloc_hw(sizeof(struct ath12k), &ath12k_ops); | |
7050 | if (!hw) { | |
7051 | ath12k_warn(ab, "failed to allocate mac80211 hw device\n"); | |
7052 | ret = -ENOMEM; | |
7053 | goto err_free_mac; | |
7054 | } | |
7055 | ||
7056 | ar = hw->priv; | |
7057 | ar->hw = hw; | |
7058 | ar->ab = ab; | |
7059 | ar->pdev = pdev; | |
7060 | ar->pdev_idx = i; | |
7061 | ar->lmac_id = ath12k_hw_get_mac_from_pdev_id(ab->hw_params, i); | |
7062 | ||
7063 | ar->wmi = &ab->wmi_ab.wmi[i]; | |
7064 | /* FIXME: wmi[0] is already initialized during attach, | |
7065 | * Should we do this again? | |
7066 | */ | |
7067 | ath12k_wmi_pdev_attach(ab, i); | |
7068 | ||
7069 | ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask; | |
7070 | ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask; | |
7071 | ar->num_tx_chains = hweight32(pdev->cap.tx_chain_mask); | |
7072 | ar->num_rx_chains = hweight32(pdev->cap.rx_chain_mask); | |
7073 | ||
7074 | pdev->ar = ar; | |
7075 | spin_lock_init(&ar->data_lock); | |
7076 | INIT_LIST_HEAD(&ar->arvifs); | |
7077 | INIT_LIST_HEAD(&ar->ppdu_stats_info); | |
7078 | mutex_init(&ar->conf_mutex); | |
7079 | init_completion(&ar->vdev_setup_done); | |
7080 | init_completion(&ar->vdev_delete_done); | |
7081 | init_completion(&ar->peer_assoc_done); | |
7082 | init_completion(&ar->peer_delete_done); | |
7083 | init_completion(&ar->install_key_done); | |
7084 | init_completion(&ar->bss_survey_done); | |
7085 | init_completion(&ar->scan.started); | |
7086 | init_completion(&ar->scan.completed); | |
7087 | ||
7088 | INIT_DELAYED_WORK(&ar->scan.timeout, ath12k_scan_timeout_work); | |
7089 | INIT_WORK(&ar->regd_update_work, ath12k_regd_update_work); | |
7090 | ||
7091 | INIT_WORK(&ar->wmi_mgmt_tx_work, ath12k_mgmt_over_wmi_tx_work); | |
7092 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); | |
7093 | clear_bit(ATH12K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
7094 | } | |
7095 | ||
7096 | return 0; | |
7097 | ||
7098 | err_free_mac: | |
7099 | ath12k_mac_destroy(ab); | |
7100 | ||
7101 | return ret; | |
7102 | } | |
7103 | ||
7104 | void ath12k_mac_destroy(struct ath12k_base *ab) | |
7105 | { | |
7106 | struct ath12k *ar; | |
7107 | struct ath12k_pdev *pdev; | |
7108 | int i; | |
7109 | ||
7110 | for (i = 0; i < ab->num_radios; i++) { | |
7111 | pdev = &ab->pdevs[i]; | |
7112 | ar = pdev->ar; | |
7113 | if (!ar) | |
7114 | continue; | |
7115 | ||
7116 | ieee80211_free_hw(ar->hw); | |
7117 | pdev->ar = NULL; | |
7118 | } | |
7119 | } |