Commit | Line | Data |
---|---|---|
d5c65159 KV |
1 | // SPDX-License-Identifier: BSD-3-Clause-Clear |
2 | /* | |
3 | * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. | |
4 | */ | |
5 | ||
6 | #include <net/mac80211.h> | |
7 | #include <linux/etherdevice.h> | |
8 | #include "mac.h" | |
9 | #include "core.h" | |
10 | #include "debug.h" | |
11 | #include "wmi.h" | |
12 | #include "hw.h" | |
13 | #include "dp_tx.h" | |
14 | #include "dp_rx.h" | |
15 | #include "testmode.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 | static const struct ieee80211_channel ath11k_2ghz_channels[] = { | |
37 | CHAN2G(1, 2412, 0), | |
38 | CHAN2G(2, 2417, 0), | |
39 | CHAN2G(3, 2422, 0), | |
40 | CHAN2G(4, 2427, 0), | |
41 | CHAN2G(5, 2432, 0), | |
42 | CHAN2G(6, 2437, 0), | |
43 | CHAN2G(7, 2442, 0), | |
44 | CHAN2G(8, 2447, 0), | |
45 | CHAN2G(9, 2452, 0), | |
46 | CHAN2G(10, 2457, 0), | |
47 | CHAN2G(11, 2462, 0), | |
48 | CHAN2G(12, 2467, 0), | |
49 | CHAN2G(13, 2472, 0), | |
50 | CHAN2G(14, 2484, 0), | |
51 | }; | |
52 | ||
53 | static const struct ieee80211_channel ath11k_5ghz_channels[] = { | |
54 | CHAN5G(36, 5180, 0), | |
55 | CHAN5G(40, 5200, 0), | |
56 | CHAN5G(44, 5220, 0), | |
57 | CHAN5G(48, 5240, 0), | |
58 | CHAN5G(52, 5260, 0), | |
59 | CHAN5G(56, 5280, 0), | |
60 | CHAN5G(60, 5300, 0), | |
61 | CHAN5G(64, 5320, 0), | |
62 | CHAN5G(100, 5500, 0), | |
63 | CHAN5G(104, 5520, 0), | |
64 | CHAN5G(108, 5540, 0), | |
65 | CHAN5G(112, 5560, 0), | |
66 | CHAN5G(116, 5580, 0), | |
67 | CHAN5G(120, 5600, 0), | |
68 | CHAN5G(124, 5620, 0), | |
69 | CHAN5G(128, 5640, 0), | |
70 | CHAN5G(132, 5660, 0), | |
71 | CHAN5G(136, 5680, 0), | |
72 | CHAN5G(140, 5700, 0), | |
73 | CHAN5G(144, 5720, 0), | |
74 | CHAN5G(149, 5745, 0), | |
75 | CHAN5G(153, 5765, 0), | |
76 | CHAN5G(157, 5785, 0), | |
77 | CHAN5G(161, 5805, 0), | |
78 | CHAN5G(165, 5825, 0), | |
79 | CHAN5G(169, 5845, 0), | |
80 | CHAN5G(173, 5865, 0), | |
81 | }; | |
82 | ||
83 | static struct ieee80211_rate ath11k_legacy_rates[] = { | |
84 | { .bitrate = 10, | |
85 | .hw_value = ATH11K_HW_RATE_CCK_LP_1M }, | |
86 | { .bitrate = 20, | |
87 | .hw_value = ATH11K_HW_RATE_CCK_LP_2M, | |
88 | .hw_value_short = ATH11K_HW_RATE_CCK_SP_2M, | |
89 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
90 | { .bitrate = 55, | |
91 | .hw_value = ATH11K_HW_RATE_CCK_LP_5_5M, | |
92 | .hw_value_short = ATH11K_HW_RATE_CCK_SP_5_5M, | |
93 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
94 | { .bitrate = 110, | |
95 | .hw_value = ATH11K_HW_RATE_CCK_LP_11M, | |
96 | .hw_value_short = ATH11K_HW_RATE_CCK_SP_11M, | |
97 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
98 | ||
99 | { .bitrate = 60, .hw_value = ATH11K_HW_RATE_OFDM_6M }, | |
100 | { .bitrate = 90, .hw_value = ATH11K_HW_RATE_OFDM_9M }, | |
101 | { .bitrate = 120, .hw_value = ATH11K_HW_RATE_OFDM_12M }, | |
102 | { .bitrate = 180, .hw_value = ATH11K_HW_RATE_OFDM_18M }, | |
103 | { .bitrate = 240, .hw_value = ATH11K_HW_RATE_OFDM_24M }, | |
104 | { .bitrate = 360, .hw_value = ATH11K_HW_RATE_OFDM_36M }, | |
105 | { .bitrate = 480, .hw_value = ATH11K_HW_RATE_OFDM_48M }, | |
106 | { .bitrate = 540, .hw_value = ATH11K_HW_RATE_OFDM_54M }, | |
107 | }; | |
108 | ||
109 | static const int | |
110 | ath11k_phymodes[NUM_NL80211_BANDS][ATH11K_CHAN_WIDTH_NUM] = { | |
111 | [NL80211_BAND_2GHZ] = { | |
112 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
113 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
114 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20_2G, | |
115 | [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20_2G, | |
116 | [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40_2G, | |
117 | [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80_2G, | |
118 | [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN, | |
119 | [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN, | |
120 | }, | |
121 | [NL80211_BAND_5GHZ] = { | |
122 | [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN, | |
123 | [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN, | |
124 | [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20, | |
125 | [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20, | |
126 | [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40, | |
127 | [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80, | |
128 | [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160, | |
129 | [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80, | |
130 | }, | |
131 | }; | |
132 | ||
133 | const struct htt_rx_ring_tlv_filter ath11k_mac_mon_status_filter_default = { | |
134 | .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START | | |
135 | HTT_RX_FILTER_TLV_FLAGS_PPDU_END | | |
136 | HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE, | |
137 | .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0, | |
138 | .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1, | |
139 | .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2, | |
140 | .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 | | |
141 | HTT_RX_FP_CTRL_FILTER_FLASG3 | |
142 | }; | |
143 | ||
144 | #define ATH11K_MAC_FIRST_OFDM_RATE_IDX 4 | |
145 | #define ath11k_g_rates ath11k_legacy_rates | |
146 | #define ath11k_g_rates_size (ARRAY_SIZE(ath11k_legacy_rates)) | |
147 | #define ath11k_a_rates (ath11k_legacy_rates + 4) | |
148 | #define ath11k_a_rates_size (ARRAY_SIZE(ath11k_legacy_rates) - 4) | |
149 | ||
150 | #define ATH11K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */ | |
151 | ||
152 | static const u32 ath11k_smps_map[] = { | |
153 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, | |
154 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, | |
155 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, | |
156 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, | |
157 | }; | |
158 | ||
39e81c6a T |
159 | u8 ath11k_mac_bw_to_mac80211_bw(u8 bw) |
160 | { | |
161 | u8 ret = 0; | |
162 | ||
163 | switch (bw) { | |
164 | case ATH11K_BW_20: | |
165 | ret = RATE_INFO_BW_20; | |
166 | break; | |
167 | case ATH11K_BW_40: | |
168 | ret = RATE_INFO_BW_40; | |
169 | break; | |
170 | case ATH11K_BW_80: | |
171 | ret = RATE_INFO_BW_80; | |
172 | break; | |
173 | case ATH11K_BW_160: | |
174 | ret = RATE_INFO_BW_160; | |
175 | break; | |
176 | } | |
177 | ||
178 | return ret; | |
179 | } | |
180 | ||
d5c65159 KV |
181 | int ath11k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx, |
182 | u16 *rate) | |
183 | { | |
184 | /* As default, it is OFDM rates */ | |
185 | int i = ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
186 | int max_rates_idx = ath11k_g_rates_size; | |
187 | ||
188 | if (preamble == WMI_RATE_PREAMBLE_CCK) { | |
189 | hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK; | |
190 | i = 0; | |
191 | max_rates_idx = ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
192 | } | |
193 | ||
194 | while (i < max_rates_idx) { | |
195 | if (hw_rc == ath11k_legacy_rates[i].hw_value) { | |
196 | *rateidx = i; | |
197 | *rate = ath11k_legacy_rates[i].bitrate; | |
198 | return 0; | |
199 | } | |
200 | i++; | |
201 | } | |
202 | ||
203 | return -EINVAL; | |
204 | } | |
205 | ||
206 | static int get_num_chains(u32 mask) | |
207 | { | |
208 | int num_chains = 0; | |
209 | ||
210 | while (mask) { | |
211 | if (mask & BIT(0)) | |
212 | num_chains++; | |
213 | mask >>= 1; | |
214 | } | |
215 | ||
216 | return num_chains; | |
217 | } | |
218 | ||
219 | u8 ath11k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, | |
220 | u32 bitrate) | |
221 | { | |
222 | int i; | |
223 | ||
224 | for (i = 0; i < sband->n_bitrates; i++) | |
225 | if (sband->bitrates[i].bitrate == bitrate) | |
226 | return i; | |
227 | ||
228 | return 0; | |
229 | } | |
230 | ||
231 | static u32 | |
232 | ath11k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | |
233 | { | |
234 | int nss; | |
235 | ||
236 | for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) | |
237 | if (ht_mcs_mask[nss]) | |
238 | return nss + 1; | |
239 | ||
240 | return 1; | |
241 | } | |
242 | ||
243 | static u32 | |
244 | ath11k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
245 | { | |
246 | int nss; | |
247 | ||
248 | for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) | |
249 | if (vht_mcs_mask[nss]) | |
250 | return nss + 1; | |
251 | ||
252 | return 1; | |
253 | } | |
254 | ||
255 | static u8 ath11k_parse_mpdudensity(u8 mpdudensity) | |
256 | { | |
257 | /* 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": | |
258 | * 0 for no restriction | |
259 | * 1 for 1/4 us | |
260 | * 2 for 1/2 us | |
261 | * 3 for 1 us | |
262 | * 4 for 2 us | |
263 | * 5 for 4 us | |
264 | * 6 for 8 us | |
265 | * 7 for 16 us | |
266 | */ | |
267 | switch (mpdudensity) { | |
268 | case 0: | |
269 | return 0; | |
270 | case 1: | |
271 | case 2: | |
272 | case 3: | |
273 | /* Our lower layer calculations limit our precision to | |
274 | * 1 microsecond | |
275 | */ | |
276 | return 1; | |
277 | case 4: | |
278 | return 2; | |
279 | case 5: | |
280 | return 4; | |
281 | case 6: | |
282 | return 8; | |
283 | case 7: | |
284 | return 16; | |
285 | default: | |
286 | return 0; | |
287 | } | |
288 | } | |
289 | ||
290 | static int ath11k_mac_vif_chan(struct ieee80211_vif *vif, | |
291 | struct cfg80211_chan_def *def) | |
292 | { | |
293 | struct ieee80211_chanctx_conf *conf; | |
294 | ||
295 | rcu_read_lock(); | |
296 | conf = rcu_dereference(vif->chanctx_conf); | |
297 | if (!conf) { | |
298 | rcu_read_unlock(); | |
299 | return -ENOENT; | |
300 | } | |
301 | ||
302 | *def = conf->def; | |
303 | rcu_read_unlock(); | |
304 | ||
305 | return 0; | |
306 | } | |
307 | ||
308 | static bool ath11k_mac_bitrate_is_cck(int bitrate) | |
309 | { | |
310 | switch (bitrate) { | |
311 | case 10: | |
312 | case 20: | |
313 | case 55: | |
314 | case 110: | |
315 | return true; | |
316 | } | |
317 | ||
318 | return false; | |
319 | } | |
320 | ||
321 | u8 ath11k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, | |
322 | u8 hw_rate, bool cck) | |
323 | { | |
324 | const struct ieee80211_rate *rate; | |
325 | int i; | |
326 | ||
327 | for (i = 0; i < sband->n_bitrates; i++) { | |
328 | rate = &sband->bitrates[i]; | |
329 | ||
330 | if (ath11k_mac_bitrate_is_cck(rate->bitrate) != cck) | |
331 | continue; | |
332 | ||
333 | if (rate->hw_value == hw_rate) | |
334 | return i; | |
335 | else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && | |
336 | rate->hw_value_short == hw_rate) | |
337 | return i; | |
338 | } | |
339 | ||
340 | return 0; | |
341 | } | |
342 | ||
343 | static u8 ath11k_mac_bitrate_to_rate(int bitrate) | |
344 | { | |
345 | return DIV_ROUND_UP(bitrate, 5) | | |
346 | (ath11k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); | |
347 | } | |
348 | ||
349 | static void ath11k_get_arvif_iter(void *data, u8 *mac, | |
350 | struct ieee80211_vif *vif) | |
351 | { | |
352 | struct ath11k_vif_iter *arvif_iter = data; | |
353 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
354 | ||
355 | if (arvif->vdev_id == arvif_iter->vdev_id) | |
356 | arvif_iter->arvif = arvif; | |
357 | } | |
358 | ||
359 | struct ath11k_vif *ath11k_mac_get_arvif(struct ath11k *ar, u32 vdev_id) | |
360 | { | |
361 | struct ath11k_vif_iter arvif_iter; | |
362 | u32 flags; | |
363 | ||
364 | memset(&arvif_iter, 0, sizeof(struct ath11k_vif_iter)); | |
365 | arvif_iter.vdev_id = vdev_id; | |
366 | ||
367 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; | |
368 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
369 | flags, | |
370 | ath11k_get_arvif_iter, | |
371 | &arvif_iter); | |
372 | if (!arvif_iter.arvif) | |
373 | return NULL; | |
374 | ||
375 | return arvif_iter.arvif; | |
376 | } | |
377 | ||
378 | struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id(struct ath11k_base *ab, | |
379 | u32 vdev_id) | |
380 | { | |
381 | int i; | |
382 | struct ath11k_pdev *pdev; | |
383 | struct ath11k_vif *arvif; | |
384 | ||
385 | for (i = 0; i < ab->num_radios; i++) { | |
386 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
387 | if (pdev && pdev->ar) { | |
388 | arvif = ath11k_mac_get_arvif(pdev->ar, vdev_id); | |
389 | if (arvif) | |
390 | return arvif; | |
391 | } | |
392 | } | |
393 | ||
394 | return NULL; | |
395 | } | |
396 | ||
397 | struct ath11k *ath11k_mac_get_ar_by_vdev_id(struct ath11k_base *ab, u32 vdev_id) | |
398 | { | |
399 | int i; | |
400 | struct ath11k_pdev *pdev; | |
401 | struct ath11k_vif *arvif; | |
402 | ||
403 | for (i = 0; i < ab->num_radios; i++) { | |
404 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
405 | if (pdev && pdev->ar) { | |
406 | arvif = ath11k_mac_get_arvif(pdev->ar, vdev_id); | |
407 | if (arvif) | |
408 | return arvif->ar; | |
409 | } | |
410 | } | |
411 | ||
412 | return NULL; | |
413 | } | |
414 | ||
415 | struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id) | |
416 | { | |
417 | int i; | |
418 | struct ath11k_pdev *pdev; | |
419 | ||
420 | if (WARN_ON(pdev_id > ab->num_radios)) | |
421 | return NULL; | |
422 | ||
423 | for (i = 0; i < ab->num_radios; i++) { | |
424 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
425 | ||
426 | if (pdev && pdev->pdev_id == pdev_id) | |
427 | return (pdev->ar ? pdev->ar : NULL); | |
428 | } | |
429 | ||
430 | return NULL; | |
431 | } | |
432 | ||
433 | struct ath11k *ath11k_mac_get_ar_vdev_stop_status(struct ath11k_base *ab, | |
434 | u32 vdev_id) | |
435 | { | |
436 | int i; | |
437 | struct ath11k_pdev *pdev; | |
438 | struct ath11k *ar; | |
439 | ||
440 | for (i = 0; i < ab->num_radios; i++) { | |
441 | pdev = rcu_dereference(ab->pdevs_active[i]); | |
442 | if (pdev && pdev->ar) { | |
443 | ar = pdev->ar; | |
444 | ||
445 | spin_lock_bh(&ar->data_lock); | |
446 | if (ar->vdev_stop_status.stop_in_progress && | |
447 | ar->vdev_stop_status.vdev_id == vdev_id) { | |
448 | ar->vdev_stop_status.stop_in_progress = false; | |
449 | spin_unlock_bh(&ar->data_lock); | |
450 | return ar; | |
451 | } | |
452 | spin_unlock_bh(&ar->data_lock); | |
453 | } | |
454 | } | |
455 | return NULL; | |
456 | } | |
457 | ||
458 | static void ath11k_pdev_caps_update(struct ath11k *ar) | |
459 | { | |
460 | struct ath11k_base *ab = ar->ab; | |
461 | ||
462 | ar->max_tx_power = ab->target_caps.hw_max_tx_power; | |
463 | ||
464 | /* FIXME Set min_tx_power to ab->target_caps.hw_min_tx_power. | |
465 | * But since the received value in svcrdy is same as hw_max_tx_power, | |
466 | * we can set ar->min_tx_power to 0 currently until | |
467 | * this is fixed in firmware | |
468 | */ | |
469 | ar->min_tx_power = 0; | |
470 | ||
471 | ar->txpower_limit_2g = ar->max_tx_power; | |
472 | ar->txpower_limit_5g = ar->max_tx_power; | |
473 | ar->txpower_scale = WMI_HOST_TP_SCALE_MAX; | |
474 | } | |
475 | ||
476 | static int ath11k_mac_txpower_recalc(struct ath11k *ar) | |
477 | { | |
478 | struct ath11k_pdev *pdev = ar->pdev; | |
479 | struct ath11k_vif *arvif; | |
480 | int ret, txpower = -1; | |
481 | u32 param; | |
482 | ||
483 | lockdep_assert_held(&ar->conf_mutex); | |
484 | ||
485 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
486 | if (arvif->txpower <= 0) | |
487 | continue; | |
488 | ||
489 | if (txpower == -1) | |
490 | txpower = arvif->txpower; | |
491 | else | |
492 | txpower = min(txpower, arvif->txpower); | |
493 | } | |
494 | ||
495 | if (txpower == -1) | |
496 | return 0; | |
497 | ||
498 | /* txpwr is set as 2 units per dBm in FW*/ | |
499 | txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower), | |
500 | ar->max_tx_power) * 2; | |
501 | ||
502 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "txpower to set in hw %d\n", | |
503 | txpower / 2); | |
504 | ||
505 | if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) && | |
506 | ar->txpower_limit_2g != txpower) { | |
507 | param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G; | |
508 | ret = ath11k_wmi_pdev_set_param(ar, param, | |
509 | txpower, ar->pdev->pdev_id); | |
510 | if (ret) | |
511 | goto fail; | |
512 | ar->txpower_limit_2g = txpower; | |
513 | } | |
514 | ||
515 | if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) && | |
516 | ar->txpower_limit_5g != txpower) { | |
517 | param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G; | |
518 | ret = ath11k_wmi_pdev_set_param(ar, param, | |
519 | txpower, ar->pdev->pdev_id); | |
520 | if (ret) | |
521 | goto fail; | |
522 | ar->txpower_limit_5g = txpower; | |
523 | } | |
524 | ||
525 | return 0; | |
526 | ||
527 | fail: | |
528 | ath11k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n", | |
529 | txpower / 2, param, ret); | |
530 | return ret; | |
531 | } | |
532 | ||
533 | static int ath11k_recalc_rtscts_prot(struct ath11k_vif *arvif) | |
534 | { | |
535 | struct ath11k *ar = arvif->ar; | |
536 | u32 vdev_param, rts_cts = 0; | |
537 | int ret; | |
538 | ||
539 | lockdep_assert_held(&ar->conf_mutex); | |
540 | ||
541 | vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS; | |
542 | ||
543 | /* Enable RTS/CTS protection for sw retries (when legacy stations | |
544 | * are in BSS) or by default only for second rate series. | |
545 | * TODO: Check if we need to enable CTS 2 Self in any case | |
546 | */ | |
547 | rts_cts = WMI_USE_RTS_CTS; | |
548 | ||
549 | if (arvif->num_legacy_stations > 0) | |
550 | rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4; | |
551 | else | |
552 | rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4; | |
553 | ||
554 | /* Need not send duplicate param value to firmware */ | |
555 | if (arvif->rtscts_prot_mode == rts_cts) | |
556 | return 0; | |
557 | ||
558 | arvif->rtscts_prot_mode = rts_cts; | |
559 | ||
560 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", | |
561 | arvif->vdev_id, rts_cts); | |
562 | ||
563 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
564 | vdev_param, rts_cts); | |
565 | if (ret) | |
566 | ath11k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n", | |
567 | arvif->vdev_id, ret); | |
568 | ||
569 | return ret; | |
570 | } | |
571 | ||
572 | static int ath11k_mac_set_kickout(struct ath11k_vif *arvif) | |
573 | { | |
574 | struct ath11k *ar = arvif->ar; | |
575 | u32 param; | |
576 | int ret; | |
577 | ||
578 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH, | |
579 | ATH11K_KICKOUT_THRESHOLD, | |
580 | ar->pdev->pdev_id); | |
581 | if (ret) { | |
582 | ath11k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n", | |
583 | arvif->vdev_id, ret); | |
584 | return ret; | |
585 | } | |
586 | ||
587 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS; | |
588 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
589 | ATH11K_KEEPALIVE_MIN_IDLE); | |
590 | if (ret) { | |
591 | ath11k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n", | |
592 | arvif->vdev_id, ret); | |
593 | return ret; | |
594 | } | |
595 | ||
596 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS; | |
597 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
598 | ATH11K_KEEPALIVE_MAX_IDLE); | |
599 | if (ret) { | |
600 | ath11k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n", | |
601 | arvif->vdev_id, ret); | |
602 | return ret; | |
603 | } | |
604 | ||
605 | param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS; | |
606 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param, | |
607 | ATH11K_KEEPALIVE_MAX_UNRESPONSIVE); | |
608 | if (ret) { | |
609 | ath11k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", | |
610 | arvif->vdev_id, ret); | |
611 | return ret; | |
612 | } | |
613 | ||
614 | return 0; | |
615 | } | |
616 | ||
617 | void ath11k_mac_peer_cleanup_all(struct ath11k *ar) | |
618 | { | |
619 | struct ath11k_peer *peer, *tmp; | |
620 | struct ath11k_base *ab = ar->ab; | |
621 | ||
622 | lockdep_assert_held(&ar->conf_mutex); | |
623 | ||
624 | spin_lock_bh(&ab->base_lock); | |
625 | list_for_each_entry_safe(peer, tmp, &ab->peers, list) { | |
626 | ath11k_peer_rx_tid_cleanup(ar, peer); | |
627 | list_del(&peer->list); | |
628 | kfree(peer); | |
629 | } | |
630 | spin_unlock_bh(&ab->base_lock); | |
631 | ||
632 | ar->num_peers = 0; | |
633 | ar->num_stations = 0; | |
634 | } | |
635 | ||
636 | static int ath11k_monitor_vdev_up(struct ath11k *ar, int vdev_id) | |
637 | { | |
638 | int ret = 0; | |
639 | ||
640 | ret = ath11k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); | |
641 | if (ret) { | |
642 | ath11k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n", | |
643 | vdev_id, ret); | |
644 | return ret; | |
645 | } | |
646 | ||
647 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i started\n", | |
648 | vdev_id); | |
649 | return 0; | |
650 | } | |
651 | ||
652 | static int ath11k_mac_op_config(struct ieee80211_hw *hw, u32 changed) | |
653 | { | |
654 | struct ath11k *ar = hw->priv; | |
655 | int ret = 0; | |
656 | ||
657 | /* mac80211 requires this op to be present and that's why | |
658 | * there's an empty function, this can be extended when | |
659 | * required. | |
660 | */ | |
661 | ||
662 | mutex_lock(&ar->conf_mutex); | |
663 | ||
664 | /* TODO: Handle configuration changes as appropriate */ | |
665 | ||
666 | mutex_unlock(&ar->conf_mutex); | |
667 | ||
668 | return ret; | |
669 | } | |
670 | ||
671 | static int ath11k_mac_setup_bcn_tmpl(struct ath11k_vif *arvif) | |
672 | { | |
673 | struct ath11k *ar = arvif->ar; | |
674 | struct ath11k_base *ab = ar->ab; | |
675 | struct ieee80211_hw *hw = ar->hw; | |
676 | struct ieee80211_vif *vif = arvif->vif; | |
677 | struct ieee80211_mutable_offsets offs = {}; | |
678 | struct sk_buff *bcn; | |
679 | int ret; | |
680 | ||
681 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) | |
682 | return 0; | |
683 | ||
684 | bcn = ieee80211_beacon_get_template(hw, vif, &offs); | |
685 | if (!bcn) { | |
686 | ath11k_warn(ab, "failed to get beacon template from mac80211\n"); | |
687 | return -EPERM; | |
688 | } | |
689 | ||
690 | ret = ath11k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn); | |
691 | ||
692 | kfree_skb(bcn); | |
693 | ||
694 | if (ret) | |
695 | ath11k_warn(ab, "failed to submit beacon template command: %d\n", | |
696 | ret); | |
697 | ||
698 | return ret; | |
699 | } | |
700 | ||
701 | static void ath11k_control_beaconing(struct ath11k_vif *arvif, | |
702 | struct ieee80211_bss_conf *info) | |
703 | { | |
704 | struct ath11k *ar = arvif->ar; | |
705 | int ret = 0; | |
706 | ||
707 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
708 | ||
709 | if (!info->enable_beacon) { | |
710 | ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id); | |
711 | if (ret) | |
712 | ath11k_warn(ar->ab, "failed to down vdev_id %i: %d\n", | |
713 | arvif->vdev_id, ret); | |
714 | ||
715 | arvif->is_up = false; | |
716 | return; | |
717 | } | |
718 | ||
719 | /* Install the beacon template to the FW */ | |
720 | ret = ath11k_mac_setup_bcn_tmpl(arvif); | |
721 | if (ret) { | |
722 | ath11k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n", | |
723 | ret); | |
724 | return; | |
725 | } | |
726 | ||
727 | arvif->tx_seq_no = 0x1000; | |
728 | ||
729 | arvif->aid = 0; | |
730 | ||
731 | ether_addr_copy(arvif->bssid, info->bssid); | |
732 | ||
733 | ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
734 | arvif->bssid); | |
735 | if (ret) { | |
736 | ath11k_warn(ar->ab, "failed to bring up vdev %d: %i\n", | |
737 | arvif->vdev_id, ret); | |
738 | return; | |
739 | } | |
740 | ||
741 | arvif->is_up = true; | |
742 | ||
743 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); | |
744 | } | |
745 | ||
746 | static void ath11k_peer_assoc_h_basic(struct ath11k *ar, | |
747 | struct ieee80211_vif *vif, | |
748 | struct ieee80211_sta *sta, | |
749 | struct peer_assoc_params *arg) | |
750 | { | |
751 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
752 | u32 aid; | |
753 | ||
754 | lockdep_assert_held(&ar->conf_mutex); | |
755 | ||
756 | if (vif->type == NL80211_IFTYPE_STATION) | |
757 | aid = vif->bss_conf.aid; | |
758 | else | |
759 | aid = sta->aid; | |
760 | ||
761 | ether_addr_copy(arg->peer_mac, sta->addr); | |
762 | arg->vdev_id = arvif->vdev_id; | |
763 | arg->peer_associd = aid; | |
764 | arg->auth_flag = true; | |
765 | /* TODO: STA WAR in ath10k for listen interval required? */ | |
766 | arg->peer_listen_intval = ar->hw->conf.listen_interval; | |
767 | arg->peer_nss = 1; | |
768 | arg->peer_caps = vif->bss_conf.assoc_capability; | |
769 | } | |
770 | ||
771 | static void ath11k_peer_assoc_h_crypto(struct ath11k *ar, | |
772 | struct ieee80211_vif *vif, | |
773 | struct ieee80211_sta *sta, | |
774 | struct peer_assoc_params *arg) | |
775 | { | |
776 | struct ieee80211_bss_conf *info = &vif->bss_conf; | |
777 | struct cfg80211_chan_def def; | |
778 | struct cfg80211_bss *bss; | |
779 | const u8 *rsnie = NULL; | |
780 | const u8 *wpaie = NULL; | |
781 | ||
782 | lockdep_assert_held(&ar->conf_mutex); | |
783 | ||
784 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
785 | return; | |
786 | ||
787 | bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0, | |
788 | IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); | |
789 | if (bss) { | |
790 | const struct cfg80211_bss_ies *ies; | |
791 | ||
792 | rcu_read_lock(); | |
793 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); | |
794 | ||
795 | ies = rcu_dereference(bss->ies); | |
796 | ||
797 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
798 | WLAN_OUI_TYPE_MICROSOFT_WPA, | |
799 | ies->data, | |
800 | ies->len); | |
801 | rcu_read_unlock(); | |
802 | cfg80211_put_bss(ar->hw->wiphy, bss); | |
803 | } | |
804 | ||
805 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ | |
806 | if (rsnie || wpaie) { | |
807 | ath11k_dbg(ar->ab, ATH11K_DBG_WMI, | |
808 | "%s: rsn ie found\n", __func__); | |
809 | arg->need_ptk_4_way = true; | |
810 | } | |
811 | ||
812 | if (wpaie) { | |
813 | ath11k_dbg(ar->ab, ATH11K_DBG_WMI, | |
814 | "%s: wpa ie found\n", __func__); | |
815 | arg->need_gtk_2_way = true; | |
816 | } | |
817 | ||
818 | if (sta->mfp) { | |
819 | /* TODO: Need to check if FW supports PMF? */ | |
820 | arg->is_pmf_enabled = true; | |
821 | } | |
822 | ||
823 | /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */ | |
824 | } | |
825 | ||
826 | static void ath11k_peer_assoc_h_rates(struct ath11k *ar, | |
827 | struct ieee80211_vif *vif, | |
828 | struct ieee80211_sta *sta, | |
829 | struct peer_assoc_params *arg) | |
830 | { | |
831 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
832 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; | |
833 | struct cfg80211_chan_def def; | |
834 | const struct ieee80211_supported_band *sband; | |
835 | const struct ieee80211_rate *rates; | |
836 | enum nl80211_band band; | |
837 | u32 ratemask; | |
838 | u8 rate; | |
839 | int i; | |
840 | ||
841 | lockdep_assert_held(&ar->conf_mutex); | |
842 | ||
843 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
844 | return; | |
845 | ||
846 | band = def.chan->band; | |
847 | sband = ar->hw->wiphy->bands[band]; | |
848 | ratemask = sta->supp_rates[band]; | |
849 | ratemask &= arvif->bitrate_mask.control[band].legacy; | |
850 | rates = sband->bitrates; | |
851 | ||
852 | rateset->num_rates = 0; | |
853 | ||
854 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { | |
855 | if (!(ratemask & 1)) | |
856 | continue; | |
857 | ||
858 | rate = ath11k_mac_bitrate_to_rate(rates->bitrate); | |
859 | rateset->rates[rateset->num_rates] = rate; | |
860 | rateset->num_rates++; | |
861 | } | |
862 | } | |
863 | ||
864 | static bool | |
865 | ath11k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) | |
866 | { | |
867 | int nss; | |
868 | ||
869 | for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) | |
870 | if (ht_mcs_mask[nss]) | |
871 | return false; | |
872 | ||
873 | return true; | |
874 | } | |
875 | ||
876 | static bool | |
877 | ath11k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
878 | { | |
879 | int nss; | |
880 | ||
881 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) | |
882 | if (vht_mcs_mask[nss]) | |
883 | return false; | |
884 | ||
885 | return true; | |
886 | } | |
887 | ||
888 | static void ath11k_peer_assoc_h_ht(struct ath11k *ar, | |
889 | struct ieee80211_vif *vif, | |
890 | struct ieee80211_sta *sta, | |
891 | struct peer_assoc_params *arg) | |
892 | { | |
893 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | |
894 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
895 | struct cfg80211_chan_def def; | |
896 | enum nl80211_band band; | |
897 | const u8 *ht_mcs_mask; | |
898 | int i, n; | |
899 | u8 max_nss; | |
900 | u32 stbc; | |
901 | ||
902 | lockdep_assert_held(&ar->conf_mutex); | |
903 | ||
904 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
905 | return; | |
906 | ||
907 | if (!ht_cap->ht_supported) | |
908 | return; | |
909 | ||
910 | band = def.chan->band; | |
911 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
912 | ||
913 | if (ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) | |
914 | return; | |
915 | ||
916 | arg->ht_flag = true; | |
917 | ||
918 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
919 | ht_cap->ampdu_factor)) - 1; | |
920 | ||
921 | arg->peer_mpdu_density = | |
922 | ath11k_parse_mpdudensity(ht_cap->ampdu_density); | |
923 | ||
924 | arg->peer_ht_caps = ht_cap->cap; | |
925 | arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG; | |
926 | ||
927 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) | |
928 | arg->ldpc_flag = true; | |
929 | ||
930 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { | |
931 | arg->bw_40 = true; | |
932 | arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG; | |
933 | } | |
934 | ||
935 | if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { | |
936 | if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 | | |
937 | IEEE80211_HT_CAP_SGI_40)) | |
938 | arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG; | |
939 | } | |
940 | ||
941 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { | |
942 | arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG; | |
943 | arg->stbc_flag = true; | |
944 | } | |
945 | ||
946 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { | |
947 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; | |
948 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
949 | stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S; | |
950 | arg->peer_rate_caps |= stbc; | |
951 | arg->stbc_flag = true; | |
952 | } | |
953 | ||
954 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) | |
955 | arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG; | |
956 | else if (ht_cap->mcs.rx_mask[1]) | |
957 | arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG; | |
958 | ||
959 | for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) | |
960 | if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && | |
961 | (ht_mcs_mask[i / 8] & BIT(i % 8))) { | |
962 | max_nss = (i / 8) + 1; | |
963 | arg->peer_ht_rates.rates[n++] = i; | |
964 | } | |
965 | ||
966 | /* This is a workaround for HT-enabled STAs which break the spec | |
967 | * and have no HT capabilities RX mask (no HT RX MCS map). | |
968 | * | |
969 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), | |
970 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. | |
971 | * | |
972 | * Firmware asserts if such situation occurs. | |
973 | */ | |
974 | if (n == 0) { | |
975 | arg->peer_ht_rates.num_rates = 8; | |
976 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) | |
977 | arg->peer_ht_rates.rates[i] = i; | |
978 | } else { | |
979 | arg->peer_ht_rates.num_rates = n; | |
980 | arg->peer_nss = min(sta->rx_nss, max_nss); | |
981 | } | |
982 | ||
983 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", | |
984 | arg->peer_mac, | |
985 | arg->peer_ht_rates.num_rates, | |
986 | arg->peer_nss); | |
987 | } | |
988 | ||
989 | static int ath11k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) | |
990 | { | |
991 | switch ((mcs_map >> (2 * nss)) & 0x3) { | |
992 | case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; | |
993 | case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; | |
994 | case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; | |
995 | } | |
996 | return 0; | |
997 | } | |
998 | ||
999 | static u16 | |
1000 | ath11k_peer_assoc_h_vht_limit(u16 tx_mcs_set, | |
1001 | const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) | |
1002 | { | |
1003 | int idx_limit; | |
1004 | int nss; | |
1005 | u16 mcs_map; | |
1006 | u16 mcs; | |
1007 | ||
1008 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
1009 | mcs_map = ath11k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & | |
1010 | vht_mcs_limit[nss]; | |
1011 | ||
1012 | if (mcs_map) | |
1013 | idx_limit = fls(mcs_map) - 1; | |
1014 | else | |
1015 | idx_limit = -1; | |
1016 | ||
1017 | switch (idx_limit) { | |
1018 | case 0: /* fall through */ | |
1019 | case 1: /* fall through */ | |
1020 | case 2: /* fall through */ | |
1021 | case 3: /* fall through */ | |
1022 | case 4: /* fall through */ | |
1023 | case 5: /* fall through */ | |
1024 | case 6: /* fall through */ | |
1025 | case 7: | |
1026 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; | |
1027 | break; | |
1028 | case 8: | |
1029 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; | |
1030 | break; | |
1031 | case 9: | |
1032 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; | |
1033 | break; | |
1034 | default: | |
1035 | WARN_ON(1); | |
1036 | /* fall through */ | |
1037 | case -1: | |
1038 | mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; | |
1039 | break; | |
1040 | } | |
1041 | ||
1042 | tx_mcs_set &= ~(0x3 << (nss * 2)); | |
1043 | tx_mcs_set |= mcs << (nss * 2); | |
1044 | } | |
1045 | ||
1046 | return tx_mcs_set; | |
1047 | } | |
1048 | ||
1049 | static void ath11k_peer_assoc_h_vht(struct ath11k *ar, | |
1050 | struct ieee80211_vif *vif, | |
1051 | struct ieee80211_sta *sta, | |
1052 | struct peer_assoc_params *arg) | |
1053 | { | |
1054 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; | |
1055 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
1056 | struct cfg80211_chan_def def; | |
1057 | enum nl80211_band band; | |
1058 | const u16 *vht_mcs_mask; | |
1059 | u8 ampdu_factor; | |
1060 | u8 max_nss, vht_mcs; | |
1061 | int i; | |
1062 | ||
1063 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
1064 | return; | |
1065 | ||
1066 | if (!vht_cap->vht_supported) | |
1067 | return; | |
1068 | ||
1069 | band = def.chan->band; | |
1070 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
1071 | ||
1072 | if (ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) | |
1073 | return; | |
1074 | ||
1075 | arg->vht_flag = true; | |
1076 | ||
1077 | /* TODO: similar flags required? */ | |
1078 | arg->vht_capable = true; | |
1079 | ||
1080 | if (def.chan->band == NL80211_BAND_2GHZ) | |
1081 | arg->vht_ng_flag = true; | |
1082 | ||
1083 | arg->peer_vht_caps = vht_cap->cap; | |
1084 | ||
1085 | ampdu_factor = (vht_cap->cap & | |
1086 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> | |
1087 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
1088 | ||
1089 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to | |
1090 | * zero in VHT IE. Using it would result in degraded throughput. | |
1091 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep | |
1092 | * it if VHT max_mpdu is smaller. | |
1093 | */ | |
1094 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, | |
1095 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + | |
1096 | ampdu_factor)) - 1); | |
1097 | ||
1098 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) | |
1099 | arg->bw_80 = true; | |
1100 | ||
1101 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) | |
1102 | arg->bw_160 = true; | |
1103 | ||
1104 | /* Calculate peer NSS capability from VHT capabilities if STA | |
1105 | * supports VHT. | |
1106 | */ | |
1107 | for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
1108 | vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> | |
1109 | (2 * i) & 3; | |
1110 | ||
1111 | if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED && | |
1112 | vht_mcs_mask[i]) | |
1113 | max_nss = i + 1; | |
1114 | } | |
1115 | arg->peer_nss = min(sta->rx_nss, max_nss); | |
1116 | arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest); | |
1117 | arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); | |
1118 | arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest); | |
1119 | arg->tx_mcs_set = ath11k_peer_assoc_h_vht_limit( | |
1120 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask); | |
1121 | ||
1122 | /* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default. | |
1123 | * VHT mcs rate 10 and 11 is not suppoerted in 11ac standard. | |
1124 | * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode. | |
1125 | */ | |
1126 | arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK; | |
1127 | arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11; | |
1128 | ||
1129 | /* TODO: Check */ | |
1130 | arg->tx_max_mcs_nss = 0xFF; | |
1131 | ||
1132 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", | |
1133 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); | |
1134 | ||
1135 | /* TODO: rxnss_override */ | |
1136 | } | |
1137 | ||
1138 | static void ath11k_peer_assoc_h_he(struct ath11k *ar, | |
1139 | struct ieee80211_vif *vif, | |
1140 | struct ieee80211_sta *sta, | |
1141 | struct peer_assoc_params *arg) | |
1142 | { | |
9f056ed8 JC |
1143 | const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap; |
1144 | u16 v; | |
1145 | ||
1146 | if (!he_cap->has_he) | |
1147 | return; | |
1148 | ||
1149 | arg->he_flag = true; | |
1150 | ||
1151 | memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info, | |
1152 | sizeof(arg->peer_he_cap_macinfo)); | |
1153 | memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info, | |
1154 | sizeof(arg->peer_he_cap_phyinfo)); | |
1155 | memcpy(&arg->peer_he_ops, &vif->bss_conf.he_operation, | |
1156 | sizeof(arg->peer_he_ops)); | |
1157 | ||
1158 | /* the top most byte is used to indicate BSS color info */ | |
1159 | arg->peer_he_ops &= 0xffffff; | |
1160 | ||
1161 | if (he_cap->he_cap_elem.phy_cap_info[6] & | |
1162 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { | |
1163 | int bit = 7; | |
1164 | int nss, ru; | |
1165 | ||
1166 | arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] & | |
1167 | IEEE80211_PPE_THRES_NSS_MASK; | |
1168 | arg->peer_ppet.ru_bit_mask = | |
1169 | (he_cap->ppe_thres[0] & | |
1170 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> | |
1171 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; | |
1172 | ||
1173 | for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) { | |
1174 | for (ru = 0; ru < 4; ru++) { | |
1175 | u32 val = 0; | |
1176 | int i; | |
1177 | ||
1178 | if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0) | |
1179 | continue; | |
1180 | for (i = 0; i < 6; i++) { | |
1181 | val >>= 1; | |
1182 | val |= ((he_cap->ppe_thres[bit / 8] >> | |
1183 | (bit % 8)) & 0x1) << 5; | |
1184 | bit++; | |
1185 | } | |
1186 | arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |= | |
1187 | val << (ru * 6); | |
1188 | } | |
1189 | } | |
1190 | } | |
1191 | ||
6d293d44 JC |
1192 | if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES) |
1193 | arg->twt_responder = true; | |
1194 | if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ) | |
1195 | arg->twt_requester = true; | |
1196 | ||
9f056ed8 JC |
1197 | switch (sta->bandwidth) { |
1198 | case IEEE80211_STA_RX_BW_160: | |
1199 | if (he_cap->he_cap_elem.phy_cap_info[0] & | |
1200 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) { | |
1201 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80); | |
1202 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; | |
1203 | ||
1204 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80); | |
1205 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v; | |
1206 | ||
1207 | arg->peer_he_mcs_count++; | |
1208 | } | |
1209 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160); | |
1210 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; | |
1211 | ||
1212 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160); | |
1213 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v; | |
1214 | ||
1215 | arg->peer_he_mcs_count++; | |
1216 | /* fall through */ | |
1217 | ||
1218 | default: | |
1219 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80); | |
1220 | arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; | |
1221 | ||
1222 | v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); | |
1223 | arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v; | |
1224 | ||
1225 | arg->peer_he_mcs_count++; | |
1226 | break; | |
1227 | } | |
d5c65159 KV |
1228 | } |
1229 | ||
1230 | static void ath11k_peer_assoc_h_smps(struct ieee80211_sta *sta, | |
1231 | struct peer_assoc_params *arg) | |
1232 | { | |
1233 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; | |
1234 | int smps; | |
1235 | ||
1236 | if (!ht_cap->ht_supported) | |
1237 | return; | |
1238 | ||
1239 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; | |
1240 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
1241 | ||
1242 | switch (smps) { | |
1243 | case WLAN_HT_CAP_SM_PS_STATIC: | |
1244 | arg->static_mimops_flag = true; | |
1245 | break; | |
1246 | case WLAN_HT_CAP_SM_PS_DYNAMIC: | |
1247 | arg->dynamic_mimops_flag = true; | |
1248 | break; | |
1249 | case WLAN_HT_CAP_SM_PS_DISABLED: | |
1250 | arg->spatial_mux_flag = true; | |
1251 | break; | |
1252 | default: | |
1253 | break; | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | static void ath11k_peer_assoc_h_qos(struct ath11k *ar, | |
1258 | struct ieee80211_vif *vif, | |
1259 | struct ieee80211_sta *sta, | |
1260 | struct peer_assoc_params *arg) | |
1261 | { | |
1262 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
1263 | ||
1264 | switch (arvif->vdev_type) { | |
1265 | case WMI_VDEV_TYPE_AP: | |
1266 | if (sta->wme) { | |
1267 | /* TODO: Check WME vs QoS */ | |
1268 | arg->is_wme_set = true; | |
1269 | arg->qos_flag = true; | |
1270 | } | |
1271 | ||
1272 | if (sta->wme && sta->uapsd_queues) { | |
1273 | /* TODO: Check WME vs QoS */ | |
1274 | arg->is_wme_set = true; | |
1275 | arg->apsd_flag = true; | |
1276 | arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG; | |
1277 | } | |
1278 | break; | |
1279 | case WMI_VDEV_TYPE_STA: | |
1280 | if (sta->wme) { | |
1281 | arg->is_wme_set = true; | |
1282 | arg->qos_flag = true; | |
1283 | } | |
1284 | break; | |
1285 | default: | |
1286 | break; | |
1287 | } | |
1288 | ||
1289 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM qos %d\n", | |
1290 | sta->addr, arg->qos_flag); | |
1291 | } | |
1292 | ||
1293 | static int ath11k_peer_assoc_qos_ap(struct ath11k *ar, | |
1294 | struct ath11k_vif *arvif, | |
1295 | struct ieee80211_sta *sta) | |
1296 | { | |
1297 | struct ap_ps_params params; | |
1298 | u32 max_sp; | |
1299 | u32 uapsd; | |
1300 | int ret; | |
1301 | ||
1302 | lockdep_assert_held(&ar->conf_mutex); | |
1303 | ||
1304 | params.vdev_id = arvif->vdev_id; | |
1305 | ||
1306 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", | |
1307 | sta->uapsd_queues, sta->max_sp); | |
1308 | ||
1309 | uapsd = 0; | |
1310 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) | |
1311 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | | |
1312 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; | |
1313 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) | |
1314 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | | |
1315 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; | |
1316 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) | |
1317 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | | |
1318 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; | |
1319 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) | |
1320 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | | |
1321 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; | |
1322 | ||
1323 | max_sp = 0; | |
1324 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) | |
1325 | max_sp = sta->max_sp; | |
1326 | ||
1327 | params.param = WMI_AP_PS_PEER_PARAM_UAPSD; | |
1328 | params.value = uapsd; | |
1329 | ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms); | |
1330 | if (ret) | |
1331 | goto err; | |
1332 | ||
1333 | params.param = WMI_AP_PS_PEER_PARAM_MAX_SP; | |
1334 | params.value = max_sp; | |
1335 | ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms); | |
1336 | if (ret) | |
1337 | goto err; | |
1338 | ||
1339 | /* TODO revisit during testing */ | |
1340 | params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE; | |
1341 | params.value = DISABLE_SIFS_RESPONSE_TRIGGER; | |
1342 | ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms); | |
1343 | if (ret) | |
1344 | goto err; | |
1345 | ||
1346 | params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD; | |
1347 | params.value = DISABLE_SIFS_RESPONSE_TRIGGER; | |
1348 | ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms); | |
1349 | if (ret) | |
1350 | goto err; | |
1351 | ||
1352 | return 0; | |
1353 | ||
1354 | err: | |
1355 | ath11k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n", | |
1356 | params.param, arvif->vdev_id, ret); | |
1357 | return ret; | |
1358 | } | |
1359 | ||
1360 | static bool ath11k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta) | |
1361 | { | |
1362 | return sta->supp_rates[NL80211_BAND_2GHZ] >> | |
1363 | ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
1364 | } | |
1365 | ||
1366 | static enum wmi_phy_mode ath11k_mac_get_phymode_vht(struct ath11k *ar, | |
1367 | struct ieee80211_sta *sta) | |
1368 | { | |
1369 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) { | |
1370 | switch (sta->vht_cap.cap & | |
1371 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { | |
1372 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: | |
1373 | return MODE_11AC_VHT160; | |
1374 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: | |
1375 | return MODE_11AC_VHT80_80; | |
1376 | default: | |
1377 | /* not sure if this is a valid case? */ | |
1378 | return MODE_11AC_VHT160; | |
1379 | } | |
1380 | } | |
1381 | ||
1382 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) | |
1383 | return MODE_11AC_VHT80; | |
1384 | ||
1385 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1386 | return MODE_11AC_VHT40; | |
1387 | ||
1388 | if (sta->bandwidth == IEEE80211_STA_RX_BW_20) | |
1389 | return MODE_11AC_VHT20; | |
1390 | ||
1391 | return MODE_UNKNOWN; | |
1392 | } | |
1393 | ||
9f056ed8 JC |
1394 | static enum wmi_phy_mode ath11k_mac_get_phymode_he(struct ath11k *ar, |
1395 | struct ieee80211_sta *sta) | |
1396 | { | |
1397 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) { | |
1398 | if (sta->he_cap.he_cap_elem.phy_cap_info[0] & | |
1399 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) | |
1400 | return MODE_11AX_HE160; | |
1401 | else if (sta->he_cap.he_cap_elem.phy_cap_info[0] & | |
1402 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) | |
1403 | return MODE_11AX_HE80_80; | |
1404 | /* not sure if this is a valid case? */ | |
1405 | return MODE_11AX_HE160; | |
1406 | } | |
1407 | ||
1408 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) | |
1409 | return MODE_11AX_HE80; | |
1410 | ||
1411 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1412 | return MODE_11AX_HE40; | |
1413 | ||
1414 | if (sta->bandwidth == IEEE80211_STA_RX_BW_20) | |
1415 | return MODE_11AX_HE20; | |
1416 | ||
1417 | return MODE_UNKNOWN; | |
1418 | } | |
1419 | ||
d5c65159 KV |
1420 | static void ath11k_peer_assoc_h_phymode(struct ath11k *ar, |
1421 | struct ieee80211_vif *vif, | |
1422 | struct ieee80211_sta *sta, | |
1423 | struct peer_assoc_params *arg) | |
1424 | { | |
1425 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
1426 | struct cfg80211_chan_def def; | |
1427 | enum nl80211_band band; | |
1428 | const u8 *ht_mcs_mask; | |
1429 | const u16 *vht_mcs_mask; | |
1430 | enum wmi_phy_mode phymode = MODE_UNKNOWN; | |
1431 | ||
1432 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
1433 | return; | |
1434 | ||
1435 | band = def.chan->band; | |
1436 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
1437 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
1438 | ||
1439 | switch (band) { | |
1440 | case NL80211_BAND_2GHZ: | |
9f056ed8 JC |
1441 | if (sta->he_cap.has_he) { |
1442 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) | |
1443 | phymode = MODE_11AX_HE80_2G; | |
1444 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1445 | phymode = MODE_11AX_HE40_2G; | |
1446 | else | |
1447 | phymode = MODE_11AX_HE20_2G; | |
1448 | } else if (sta->vht_cap.vht_supported && | |
d5c65159 KV |
1449 | !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
1450 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1451 | phymode = MODE_11AC_VHT40; | |
1452 | else | |
1453 | phymode = MODE_11AC_VHT20; | |
1454 | } else if (sta->ht_cap.ht_supported && | |
1455 | !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) { | |
1456 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) | |
1457 | phymode = MODE_11NG_HT40; | |
1458 | else | |
1459 | phymode = MODE_11NG_HT20; | |
1460 | } else if (ath11k_mac_sta_has_ofdm_only(sta)) { | |
1461 | phymode = MODE_11G; | |
1462 | } else { | |
1463 | phymode = MODE_11B; | |
1464 | } | |
d5c65159 KV |
1465 | break; |
1466 | case NL80211_BAND_5GHZ: | |
9f056ed8 JC |
1467 | /* Check HE first */ |
1468 | if (sta->he_cap.has_he) { | |
1469 | phymode = ath11k_mac_get_phymode_he(ar, sta); | |
1470 | } else if (sta->vht_cap.vht_supported && | |
d5c65159 KV |
1471 | !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
1472 | phymode = ath11k_mac_get_phymode_vht(ar, sta); | |
1473 | } else if (sta->ht_cap.ht_supported && | |
1474 | !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) { | |
1475 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) | |
1476 | phymode = MODE_11NA_HT40; | |
1477 | else | |
1478 | phymode = MODE_11NA_HT20; | |
1479 | } else { | |
1480 | phymode = MODE_11A; | |
1481 | } | |
d5c65159 KV |
1482 | break; |
1483 | default: | |
1484 | break; | |
1485 | } | |
1486 | ||
1487 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM phymode %s\n", | |
1488 | sta->addr, ath11k_wmi_phymode_str(phymode)); | |
1489 | ||
1490 | arg->peer_phymode = phymode; | |
1491 | WARN_ON(phymode == MODE_UNKNOWN); | |
1492 | } | |
1493 | ||
1494 | static void ath11k_peer_assoc_prepare(struct ath11k *ar, | |
1495 | struct ieee80211_vif *vif, | |
1496 | struct ieee80211_sta *sta, | |
1497 | struct peer_assoc_params *arg, | |
1498 | bool reassoc) | |
1499 | { | |
1500 | lockdep_assert_held(&ar->conf_mutex); | |
1501 | ||
1502 | memset(arg, 0, sizeof(*arg)); | |
1503 | ||
1504 | reinit_completion(&ar->peer_assoc_done); | |
1505 | ||
1506 | arg->peer_new_assoc = !reassoc; | |
1507 | ath11k_peer_assoc_h_basic(ar, vif, sta, arg); | |
1508 | ath11k_peer_assoc_h_crypto(ar, vif, sta, arg); | |
1509 | ath11k_peer_assoc_h_rates(ar, vif, sta, arg); | |
1510 | ath11k_peer_assoc_h_ht(ar, vif, sta, arg); | |
1511 | ath11k_peer_assoc_h_vht(ar, vif, sta, arg); | |
1512 | ath11k_peer_assoc_h_he(ar, vif, sta, arg); | |
1513 | ath11k_peer_assoc_h_qos(ar, vif, sta, arg); | |
1514 | ath11k_peer_assoc_h_phymode(ar, vif, sta, arg); | |
1515 | ath11k_peer_assoc_h_smps(sta, arg); | |
1516 | ||
1517 | /* TODO: amsdu_disable req? */ | |
1518 | } | |
1519 | ||
1520 | static int ath11k_setup_peer_smps(struct ath11k *ar, struct ath11k_vif *arvif, | |
1521 | const u8 *addr, | |
1522 | const struct ieee80211_sta_ht_cap *ht_cap) | |
1523 | { | |
1524 | int smps; | |
1525 | ||
1526 | if (!ht_cap->ht_supported) | |
1527 | return 0; | |
1528 | ||
1529 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; | |
1530 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
1531 | ||
1532 | if (smps >= ARRAY_SIZE(ath11k_smps_map)) | |
1533 | return -EINVAL; | |
1534 | ||
1535 | return ath11k_wmi_set_peer_param(ar, addr, arvif->vdev_id, | |
1536 | WMI_PEER_MIMO_PS_STATE, | |
1537 | ath11k_smps_map[smps]); | |
1538 | } | |
1539 | ||
1540 | static void ath11k_bss_assoc(struct ieee80211_hw *hw, | |
1541 | struct ieee80211_vif *vif, | |
1542 | struct ieee80211_bss_conf *bss_conf) | |
1543 | { | |
1544 | struct ath11k *ar = hw->priv; | |
1545 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
1546 | struct peer_assoc_params peer_arg; | |
1547 | struct ieee80211_sta *ap_sta; | |
1548 | int ret; | |
1549 | ||
1550 | lockdep_assert_held(&ar->conf_mutex); | |
1551 | ||
1552 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", | |
1553 | arvif->vdev_id, arvif->bssid, arvif->aid); | |
1554 | ||
1555 | rcu_read_lock(); | |
1556 | ||
1557 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
1558 | if (!ap_sta) { | |
1559 | ath11k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n", | |
1560 | bss_conf->bssid, arvif->vdev_id); | |
1561 | rcu_read_unlock(); | |
1562 | return; | |
1563 | } | |
1564 | ||
1565 | ath11k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false); | |
1566 | ||
1567 | rcu_read_unlock(); | |
1568 | ||
1569 | ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
1570 | if (ret) { | |
1571 | ath11k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n", | |
1572 | bss_conf->bssid, arvif->vdev_id, ret); | |
1573 | return; | |
1574 | } | |
1575 | ||
1576 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
1577 | ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
1578 | bss_conf->bssid, arvif->vdev_id); | |
1579 | return; | |
1580 | } | |
1581 | ||
1582 | ret = ath11k_setup_peer_smps(ar, arvif, bss_conf->bssid, | |
1583 | &ap_sta->ht_cap); | |
1584 | if (ret) { | |
1585 | ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
1586 | arvif->vdev_id, ret); | |
1587 | return; | |
1588 | } | |
1589 | ||
1590 | WARN_ON(arvif->is_up); | |
1591 | ||
1592 | arvif->aid = bss_conf->aid; | |
1593 | ether_addr_copy(arvif->bssid, bss_conf->bssid); | |
1594 | ||
1595 | ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); | |
1596 | if (ret) { | |
1597 | ath11k_warn(ar->ab, "failed to set vdev %d up: %d\n", | |
1598 | arvif->vdev_id, ret); | |
1599 | return; | |
1600 | } | |
1601 | ||
1602 | arvif->is_up = true; | |
1603 | ||
1604 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1605 | "mac vdev %d up (associated) bssid %pM aid %d\n", | |
1606 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); | |
1607 | ||
1608 | /* Authorize BSS Peer */ | |
1609 | ret = ath11k_wmi_set_peer_param(ar, arvif->bssid, | |
1610 | arvif->vdev_id, | |
1611 | WMI_PEER_AUTHORIZE, | |
1612 | 1); | |
1613 | if (ret) | |
1614 | ath11k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret); | |
3f8be640 JC |
1615 | |
1616 | ret = ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
1617 | &bss_conf->he_obss_pd); | |
1618 | if (ret) | |
1619 | ath11k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n", | |
1620 | arvif->vdev_id, ret); | |
d5c65159 KV |
1621 | } |
1622 | ||
1623 | static void ath11k_bss_disassoc(struct ieee80211_hw *hw, | |
1624 | struct ieee80211_vif *vif) | |
1625 | { | |
1626 | struct ath11k *ar = hw->priv; | |
1627 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
1628 | int ret; | |
1629 | ||
1630 | lockdep_assert_held(&ar->conf_mutex); | |
1631 | ||
1632 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", | |
1633 | arvif->vdev_id, arvif->bssid); | |
1634 | ||
1635 | ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id); | |
1636 | if (ret) | |
1637 | ath11k_warn(ar->ab, "failed to down vdev %i: %d\n", | |
1638 | arvif->vdev_id, ret); | |
1639 | ||
1640 | arvif->is_up = false; | |
1641 | ||
1642 | /* TODO: cancel connection_loss_work */ | |
1643 | } | |
1644 | ||
1645 | static u32 ath11k_mac_get_rate_hw_value(int bitrate) | |
1646 | { | |
1647 | u32 preamble; | |
1648 | u16 hw_value; | |
1649 | int rate; | |
1650 | size_t i; | |
1651 | ||
1652 | if (ath11k_mac_bitrate_is_cck(bitrate)) | |
1653 | preamble = WMI_RATE_PREAMBLE_CCK; | |
1654 | else | |
1655 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
1656 | ||
1657 | for (i = 0; i < ARRAY_SIZE(ath11k_legacy_rates); i++) { | |
1658 | if (ath11k_legacy_rates[i].bitrate != bitrate) | |
1659 | continue; | |
1660 | ||
1661 | hw_value = ath11k_legacy_rates[i].hw_value; | |
1662 | rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble); | |
1663 | ||
1664 | return rate; | |
1665 | } | |
1666 | ||
1667 | return -EINVAL; | |
1668 | } | |
1669 | ||
1670 | static void ath11k_recalculate_mgmt_rate(struct ath11k *ar, | |
1671 | struct ieee80211_vif *vif, | |
1672 | struct cfg80211_chan_def *def) | |
1673 | { | |
1674 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
1675 | const struct ieee80211_supported_band *sband; | |
1676 | u8 basic_rate_idx; | |
1677 | int hw_rate_code; | |
1678 | u32 vdev_param; | |
1679 | u16 bitrate; | |
1680 | int ret; | |
1681 | ||
1682 | lockdep_assert_held(&ar->conf_mutex); | |
1683 | ||
1684 | sband = ar->hw->wiphy->bands[def->chan->band]; | |
1685 | basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1; | |
1686 | bitrate = sband->bitrates[basic_rate_idx].bitrate; | |
1687 | ||
1688 | hw_rate_code = ath11k_mac_get_rate_hw_value(bitrate); | |
1689 | if (hw_rate_code < 0) { | |
1690 | ath11k_warn(ar->ab, "bitrate not supported %d\n", bitrate); | |
1691 | return; | |
1692 | } | |
1693 | ||
1694 | vdev_param = WMI_VDEV_PARAM_MGMT_RATE; | |
1695 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, | |
1696 | hw_rate_code); | |
1697 | if (ret) | |
1698 | ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret); | |
1699 | ||
1700 | vdev_param = WMI_VDEV_PARAM_BEACON_RATE; | |
1701 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param, | |
1702 | hw_rate_code); | |
1703 | if (ret) | |
1704 | ath11k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret); | |
1705 | } | |
1706 | ||
1707 | static void ath11k_mac_op_bss_info_changed(struct ieee80211_hw *hw, | |
1708 | struct ieee80211_vif *vif, | |
1709 | struct ieee80211_bss_conf *info, | |
1710 | u32 changed) | |
1711 | { | |
1712 | struct ath11k *ar = hw->priv; | |
1713 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
1714 | struct cfg80211_chan_def def; | |
1715 | u32 param_id, param_value; | |
1716 | enum nl80211_band band; | |
1717 | u32 vdev_param; | |
1718 | int mcast_rate; | |
1719 | u32 preamble; | |
1720 | u16 hw_value; | |
1721 | u16 bitrate; | |
1722 | int ret = 0; | |
1723 | u8 rateidx; | |
1724 | u32 rate; | |
1725 | ||
1726 | mutex_lock(&ar->conf_mutex); | |
1727 | ||
1728 | if (changed & BSS_CHANGED_BEACON_INT) { | |
1729 | arvif->beacon_interval = info->beacon_int; | |
1730 | ||
1731 | param_id = WMI_VDEV_PARAM_BEACON_INTERVAL; | |
1732 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1733 | param_id, | |
1734 | arvif->beacon_interval); | |
1735 | if (ret) | |
1736 | ath11k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n", | |
1737 | arvif->vdev_id); | |
1738 | else | |
1739 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1740 | "Beacon interval: %d set for VDEV: %d\n", | |
1741 | arvif->beacon_interval, arvif->vdev_id); | |
1742 | } | |
1743 | ||
1744 | if (changed & BSS_CHANGED_BEACON) { | |
1745 | param_id = WMI_PDEV_PARAM_BEACON_TX_MODE; | |
1746 | param_value = WMI_BEACON_STAGGERED_MODE; | |
1747 | ret = ath11k_wmi_pdev_set_param(ar, param_id, | |
1748 | param_value, ar->pdev->pdev_id); | |
1749 | if (ret) | |
1750 | ath11k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n", | |
1751 | arvif->vdev_id); | |
1752 | else | |
1753 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1754 | "Set staggered beacon mode for VDEV: %d\n", | |
1755 | arvif->vdev_id); | |
1756 | ||
1757 | ret = ath11k_mac_setup_bcn_tmpl(arvif); | |
1758 | if (ret) | |
1759 | ath11k_warn(ar->ab, "failed to update bcn template: %d\n", | |
1760 | ret); | |
aacb4622 PKC |
1761 | |
1762 | if (vif->bss_conf.he_support) { | |
1763 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1764 | WMI_VDEV_PARAM_BA_MODE, | |
1765 | WMI_BA_MODE_BUFFER_SIZE_256); | |
1766 | if (ret) | |
1767 | ath11k_warn(ar->ab, | |
1768 | "failed to set BA BUFFER SIZE 256 for vdev: %d\n", | |
1769 | arvif->vdev_id); | |
1770 | else | |
1771 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1772 | "Set BA BUFFER SIZE 256 for VDEV: %d\n", | |
1773 | arvif->vdev_id); | |
1774 | } | |
d5c65159 KV |
1775 | } |
1776 | ||
1777 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { | |
1778 | arvif->dtim_period = info->dtim_period; | |
1779 | ||
1780 | param_id = WMI_VDEV_PARAM_DTIM_PERIOD; | |
1781 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1782 | param_id, | |
1783 | arvif->dtim_period); | |
1784 | ||
1785 | if (ret) | |
1786 | ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n", | |
1787 | arvif->vdev_id, ret); | |
1788 | else | |
1789 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1790 | "DTIM period: %d set for VDEV: %d\n", | |
1791 | arvif->dtim_period, arvif->vdev_id); | |
1792 | } | |
1793 | ||
1794 | if (changed & BSS_CHANGED_SSID && | |
1795 | vif->type == NL80211_IFTYPE_AP) { | |
1796 | arvif->u.ap.ssid_len = info->ssid_len; | |
1797 | if (info->ssid_len) | |
1798 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); | |
1799 | arvif->u.ap.hidden_ssid = info->hidden_ssid; | |
1800 | } | |
1801 | ||
1802 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) | |
1803 | ether_addr_copy(arvif->bssid, info->bssid); | |
1804 | ||
1805 | if (changed & BSS_CHANGED_BEACON_ENABLED) | |
1806 | ath11k_control_beaconing(arvif, info); | |
1807 | ||
1808 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
1809 | u32 cts_prot; | |
1810 | ||
1811 | cts_prot = !!(info->use_cts_prot); | |
1812 | param_id = WMI_VDEV_PARAM_PROTECTION_MODE; | |
1813 | ||
1814 | if (arvif->is_started) { | |
1815 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1816 | param_id, cts_prot); | |
1817 | if (ret) | |
1818 | ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n", | |
1819 | arvif->vdev_id); | |
1820 | else | |
1821 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n", | |
1822 | cts_prot, arvif->vdev_id); | |
1823 | } else { | |
1824 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n"); | |
1825 | } | |
1826 | } | |
1827 | ||
1828 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
1829 | u32 slottime; | |
1830 | ||
1831 | if (info->use_short_slot) | |
1832 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ | |
1833 | ||
1834 | else | |
1835 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ | |
1836 | ||
1837 | param_id = WMI_VDEV_PARAM_SLOT_TIME; | |
1838 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1839 | param_id, slottime); | |
1840 | if (ret) | |
1841 | ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n", | |
1842 | arvif->vdev_id); | |
1843 | else | |
1844 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1845 | "Set slottime: %d for VDEV: %d\n", | |
1846 | slottime, arvif->vdev_id); | |
1847 | } | |
1848 | ||
1849 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
1850 | u32 preamble; | |
1851 | ||
1852 | if (info->use_short_preamble) | |
1853 | preamble = WMI_VDEV_PREAMBLE_SHORT; | |
1854 | else | |
1855 | preamble = WMI_VDEV_PREAMBLE_LONG; | |
1856 | ||
1857 | param_id = WMI_VDEV_PARAM_PREAMBLE; | |
1858 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1859 | param_id, preamble); | |
1860 | if (ret) | |
1861 | ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n", | |
1862 | arvif->vdev_id); | |
1863 | else | |
1864 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1865 | "Set preamble: %d for VDEV: %d\n", | |
1866 | preamble, arvif->vdev_id); | |
1867 | } | |
1868 | ||
1869 | if (changed & BSS_CHANGED_ASSOC) { | |
1870 | if (info->assoc) | |
1871 | ath11k_bss_assoc(hw, vif, info); | |
1872 | else | |
1873 | ath11k_bss_disassoc(hw, vif); | |
1874 | } | |
1875 | ||
1876 | if (changed & BSS_CHANGED_TXPOWER) { | |
1877 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n", | |
1878 | arvif->vdev_id, info->txpower); | |
1879 | ||
1880 | arvif->txpower = info->txpower; | |
1881 | ath11k_mac_txpower_recalc(ar); | |
1882 | } | |
1883 | ||
1884 | if (changed & BSS_CHANGED_MCAST_RATE && | |
1885 | !ath11k_mac_vif_chan(arvif->vif, &def)) { | |
1886 | band = def.chan->band; | |
1887 | mcast_rate = vif->bss_conf.mcast_rate[band]; | |
1888 | ||
1889 | if (mcast_rate > 0) | |
1890 | rateidx = mcast_rate - 1; | |
1891 | else | |
1892 | rateidx = ffs(vif->bss_conf.basic_rates) - 1; | |
1893 | ||
1894 | if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) | |
1895 | rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
1896 | ||
1897 | bitrate = ath11k_legacy_rates[rateidx].bitrate; | |
1898 | hw_value = ath11k_legacy_rates[rateidx].hw_value; | |
1899 | ||
1900 | if (ath11k_mac_bitrate_is_cck(bitrate)) | |
1901 | preamble = WMI_RATE_PREAMBLE_CCK; | |
1902 | else | |
1903 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
1904 | ||
1905 | rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble); | |
1906 | ||
1907 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1908 | "mac vdev %d mcast_rate %x\n", | |
1909 | arvif->vdev_id, rate); | |
1910 | ||
1911 | vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE; | |
1912 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1913 | vdev_param, rate); | |
1914 | if (ret) | |
1915 | ath11k_warn(ar->ab, | |
1916 | "failed to set mcast rate on vdev %i: %d\n", | |
1917 | arvif->vdev_id, ret); | |
1918 | ||
1919 | vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE; | |
1920 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1921 | vdev_param, rate); | |
1922 | if (ret) | |
1923 | ath11k_warn(ar->ab, | |
1924 | "failed to set bcast rate on vdev %i: %d\n", | |
1925 | arvif->vdev_id, ret); | |
1926 | } | |
1927 | ||
1928 | if (changed & BSS_CHANGED_BASIC_RATES && | |
1929 | !ath11k_mac_vif_chan(arvif->vif, &def)) | |
1930 | ath11k_recalculate_mgmt_rate(ar, vif, &def); | |
1931 | ||
6d293d44 JC |
1932 | if (changed & BSS_CHANGED_TWT) { |
1933 | if (info->twt_requester || info->twt_responder) | |
485add35 | 1934 | ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id); |
6d293d44 | 1935 | else |
485add35 | 1936 | ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id); |
6d293d44 JC |
1937 | } |
1938 | ||
3f8be640 JC |
1939 | if (changed & BSS_CHANGED_HE_OBSS_PD) |
1940 | ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
1941 | &info->he_obss_pd); | |
1942 | ||
d5c65159 KV |
1943 | mutex_unlock(&ar->conf_mutex); |
1944 | } | |
1945 | ||
1946 | void __ath11k_mac_scan_finish(struct ath11k *ar) | |
1947 | { | |
1948 | lockdep_assert_held(&ar->data_lock); | |
1949 | ||
1950 | switch (ar->scan.state) { | |
1951 | case ATH11K_SCAN_IDLE: | |
1952 | break; | |
1953 | case ATH11K_SCAN_RUNNING: | |
1954 | case ATH11K_SCAN_ABORTING: | |
1955 | if (!ar->scan.is_roc) { | |
1956 | struct cfg80211_scan_info info = { | |
1957 | .aborted = (ar->scan.state == | |
1958 | ATH11K_SCAN_ABORTING), | |
1959 | }; | |
1960 | ||
1961 | ieee80211_scan_completed(ar->hw, &info); | |
1962 | } else if (ar->scan.roc_notify) { | |
1963 | ieee80211_remain_on_channel_expired(ar->hw); | |
1964 | } | |
1965 | /* fall through */ | |
1966 | case ATH11K_SCAN_STARTING: | |
1967 | ar->scan.state = ATH11K_SCAN_IDLE; | |
1968 | ar->scan_channel = NULL; | |
1969 | ar->scan.roc_freq = 0; | |
1970 | cancel_delayed_work(&ar->scan.timeout); | |
1971 | complete(&ar->scan.completed); | |
1972 | break; | |
1973 | } | |
1974 | } | |
1975 | ||
1976 | void ath11k_mac_scan_finish(struct ath11k *ar) | |
1977 | { | |
1978 | spin_lock_bh(&ar->data_lock); | |
1979 | __ath11k_mac_scan_finish(ar); | |
1980 | spin_unlock_bh(&ar->data_lock); | |
1981 | } | |
1982 | ||
1983 | static int ath11k_scan_stop(struct ath11k *ar) | |
1984 | { | |
1985 | struct scan_cancel_param arg = { | |
1986 | .req_type = WLAN_SCAN_CANCEL_SINGLE, | |
1987 | .scan_id = ATH11K_SCAN_ID, | |
1988 | }; | |
1989 | int ret; | |
1990 | ||
1991 | lockdep_assert_held(&ar->conf_mutex); | |
1992 | ||
1993 | /* TODO: Fill other STOP Params */ | |
1994 | arg.pdev_id = ar->pdev->pdev_id; | |
1995 | ||
1996 | ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg); | |
1997 | if (ret) { | |
1998 | ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret); | |
1999 | goto out; | |
2000 | } | |
2001 | ||
2002 | ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); | |
2003 | if (ret == 0) { | |
2004 | ath11k_warn(ar->ab, | |
2005 | "failed to receive scan abort comple: timed out\n"); | |
2006 | ret = -ETIMEDOUT; | |
2007 | } else if (ret > 0) { | |
2008 | ret = 0; | |
2009 | } | |
2010 | ||
2011 | out: | |
2012 | /* Scan state should be updated upon scan completion but in case | |
2013 | * firmware fails to deliver the event (for whatever reason) it is | |
2014 | * desired to clean up scan state anyway. Firmware may have just | |
2015 | * dropped the scan completion event delivery due to transport pipe | |
2016 | * being overflown with data and/or it can recover on its own before | |
2017 | * next scan request is submitted. | |
2018 | */ | |
2019 | spin_lock_bh(&ar->data_lock); | |
2020 | if (ar->scan.state != ATH11K_SCAN_IDLE) | |
2021 | __ath11k_mac_scan_finish(ar); | |
2022 | spin_unlock_bh(&ar->data_lock); | |
2023 | ||
2024 | return ret; | |
2025 | } | |
2026 | ||
2027 | static void ath11k_scan_abort(struct ath11k *ar) | |
2028 | { | |
2029 | int ret; | |
2030 | ||
2031 | lockdep_assert_held(&ar->conf_mutex); | |
2032 | ||
2033 | spin_lock_bh(&ar->data_lock); | |
2034 | ||
2035 | switch (ar->scan.state) { | |
2036 | case ATH11K_SCAN_IDLE: | |
2037 | /* This can happen if timeout worker kicked in and called | |
2038 | * abortion while scan completion was being processed. | |
2039 | */ | |
2040 | break; | |
2041 | case ATH11K_SCAN_STARTING: | |
2042 | case ATH11K_SCAN_ABORTING: | |
2043 | ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n", | |
2044 | ar->scan.state); | |
2045 | break; | |
2046 | case ATH11K_SCAN_RUNNING: | |
2047 | ar->scan.state = ATH11K_SCAN_ABORTING; | |
2048 | spin_unlock_bh(&ar->data_lock); | |
2049 | ||
2050 | ret = ath11k_scan_stop(ar); | |
2051 | if (ret) | |
2052 | ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret); | |
2053 | ||
2054 | spin_lock_bh(&ar->data_lock); | |
2055 | break; | |
2056 | } | |
2057 | ||
2058 | spin_unlock_bh(&ar->data_lock); | |
2059 | } | |
2060 | ||
2061 | static void ath11k_scan_timeout_work(struct work_struct *work) | |
2062 | { | |
2063 | struct ath11k *ar = container_of(work, struct ath11k, | |
2064 | scan.timeout.work); | |
2065 | ||
2066 | mutex_lock(&ar->conf_mutex); | |
2067 | ath11k_scan_abort(ar); | |
2068 | mutex_unlock(&ar->conf_mutex); | |
2069 | } | |
2070 | ||
2071 | static int ath11k_start_scan(struct ath11k *ar, | |
2072 | struct scan_req_params *arg) | |
2073 | { | |
2074 | int ret; | |
2075 | ||
2076 | lockdep_assert_held(&ar->conf_mutex); | |
2077 | ||
2078 | ret = ath11k_wmi_send_scan_start_cmd(ar, arg); | |
2079 | if (ret) | |
2080 | return ret; | |
2081 | ||
2082 | ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); | |
2083 | if (ret == 0) { | |
2084 | ret = ath11k_scan_stop(ar); | |
2085 | if (ret) | |
2086 | ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret); | |
2087 | ||
2088 | return -ETIMEDOUT; | |
2089 | } | |
2090 | ||
2091 | /* If we failed to start the scan, return error code at | |
2092 | * this point. This is probably due to some issue in the | |
2093 | * firmware, but no need to wedge the driver due to that... | |
2094 | */ | |
2095 | spin_lock_bh(&ar->data_lock); | |
2096 | if (ar->scan.state == ATH11K_SCAN_IDLE) { | |
2097 | spin_unlock_bh(&ar->data_lock); | |
2098 | return -EINVAL; | |
2099 | } | |
2100 | spin_unlock_bh(&ar->data_lock); | |
2101 | ||
2102 | return 0; | |
2103 | } | |
2104 | ||
2105 | static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw, | |
2106 | struct ieee80211_vif *vif, | |
2107 | struct ieee80211_scan_request *hw_req) | |
2108 | { | |
2109 | struct ath11k *ar = hw->priv; | |
2110 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2111 | struct cfg80211_scan_request *req = &hw_req->req; | |
2112 | struct scan_req_params arg; | |
2113 | int ret = 0; | |
2114 | int i; | |
2115 | ||
2116 | mutex_lock(&ar->conf_mutex); | |
2117 | ||
2118 | spin_lock_bh(&ar->data_lock); | |
2119 | switch (ar->scan.state) { | |
2120 | case ATH11K_SCAN_IDLE: | |
2121 | reinit_completion(&ar->scan.started); | |
2122 | reinit_completion(&ar->scan.completed); | |
2123 | ar->scan.state = ATH11K_SCAN_STARTING; | |
2124 | ar->scan.is_roc = false; | |
2125 | ar->scan.vdev_id = arvif->vdev_id; | |
2126 | ret = 0; | |
2127 | break; | |
2128 | case ATH11K_SCAN_STARTING: | |
2129 | case ATH11K_SCAN_RUNNING: | |
2130 | case ATH11K_SCAN_ABORTING: | |
2131 | ret = -EBUSY; | |
2132 | break; | |
2133 | } | |
2134 | spin_unlock_bh(&ar->data_lock); | |
2135 | ||
2136 | if (ret) | |
2137 | goto exit; | |
2138 | ||
2139 | memset(&arg, 0, sizeof(arg)); | |
2140 | ath11k_wmi_start_scan_init(ar, &arg); | |
2141 | arg.vdev_id = arvif->vdev_id; | |
2142 | arg.scan_id = ATH11K_SCAN_ID; | |
2143 | ||
2144 | if (req->ie_len) { | |
2145 | arg.extraie.len = req->ie_len; | |
2146 | arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL); | |
2147 | memcpy(arg.extraie.ptr, req->ie, req->ie_len); | |
2148 | } | |
2149 | ||
2150 | if (req->n_ssids) { | |
2151 | arg.num_ssids = req->n_ssids; | |
2152 | for (i = 0; i < arg.num_ssids; i++) { | |
2153 | arg.ssid[i].length = req->ssids[i].ssid_len; | |
2154 | memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid, | |
2155 | req->ssids[i].ssid_len); | |
2156 | } | |
2157 | } else { | |
2158 | arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE; | |
2159 | } | |
2160 | ||
2161 | if (req->n_channels) { | |
2162 | arg.num_chan = req->n_channels; | |
2163 | for (i = 0; i < arg.num_chan; i++) | |
2164 | arg.chan_list[i] = req->channels[i]->center_freq; | |
2165 | } | |
2166 | ||
2167 | ret = ath11k_start_scan(ar, &arg); | |
2168 | if (ret) { | |
2169 | ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret); | |
2170 | spin_lock_bh(&ar->data_lock); | |
2171 | ar->scan.state = ATH11K_SCAN_IDLE; | |
2172 | spin_unlock_bh(&ar->data_lock); | |
2173 | } | |
2174 | ||
2175 | /* Add a 200ms margin to account for event/command processing */ | |
2176 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, | |
2177 | msecs_to_jiffies(arg.max_scan_time + | |
2178 | ATH11K_MAC_SCAN_TIMEOUT_MSECS)); | |
2179 | ||
2180 | exit: | |
2181 | if (req->ie_len) | |
2182 | kfree(arg.extraie.ptr); | |
2183 | ||
2184 | mutex_unlock(&ar->conf_mutex); | |
2185 | return ret; | |
2186 | } | |
2187 | ||
2188 | static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw, | |
2189 | struct ieee80211_vif *vif) | |
2190 | { | |
2191 | struct ath11k *ar = hw->priv; | |
2192 | ||
2193 | mutex_lock(&ar->conf_mutex); | |
2194 | ath11k_scan_abort(ar); | |
2195 | mutex_unlock(&ar->conf_mutex); | |
2196 | ||
2197 | cancel_delayed_work_sync(&ar->scan.timeout); | |
2198 | } | |
2199 | ||
2200 | static int ath11k_install_key(struct ath11k_vif *arvif, | |
2201 | struct ieee80211_key_conf *key, | |
2202 | enum set_key_cmd cmd, | |
2203 | const u8 *macaddr, u32 flags) | |
2204 | { | |
2205 | int ret; | |
2206 | struct ath11k *ar = arvif->ar; | |
2207 | struct wmi_vdev_install_key_arg arg = { | |
2208 | .vdev_id = arvif->vdev_id, | |
2209 | .key_idx = key->keyidx, | |
2210 | .key_len = key->keylen, | |
2211 | .key_data = key->key, | |
2212 | .key_flags = flags, | |
2213 | .macaddr = macaddr, | |
2214 | }; | |
2215 | ||
2216 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
2217 | ||
2218 | reinit_completion(&ar->install_key_done); | |
2219 | ||
2220 | if (cmd == DISABLE_KEY) { | |
2221 | /* TODO: Check if FW expects value other than NONE for del */ | |
2222 | /* arg.key_cipher = WMI_CIPHER_NONE; */ | |
2223 | arg.key_len = 0; | |
2224 | arg.key_data = NULL; | |
2225 | goto install; | |
2226 | } | |
2227 | ||
2228 | switch (key->cipher) { | |
2229 | case WLAN_CIPHER_SUITE_CCMP: | |
2230 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
2231 | /* TODO: Re-check if flag is valid */ | |
2232 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; | |
2233 | break; | |
2234 | case WLAN_CIPHER_SUITE_TKIP: | |
2235 | arg.key_cipher = WMI_CIPHER_TKIP; | |
2236 | arg.key_txmic_len = 8; | |
2237 | arg.key_rxmic_len = 8; | |
2238 | break; | |
2239 | case WLAN_CIPHER_SUITE_CCMP_256: | |
2240 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
2241 | break; | |
2242 | case WLAN_CIPHER_SUITE_GCMP: | |
2243 | case WLAN_CIPHER_SUITE_GCMP_256: | |
2244 | arg.key_cipher = WMI_CIPHER_AES_GCM; | |
2245 | break; | |
2246 | default: | |
2247 | ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher); | |
2248 | return -EOPNOTSUPP; | |
2249 | } | |
2250 | ||
2251 | install: | |
2252 | ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg); | |
2253 | if (ret) | |
2254 | return ret; | |
2255 | ||
2256 | if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ)) | |
2257 | return -ETIMEDOUT; | |
2258 | ||
2259 | return ar->install_key_status ? -EINVAL : 0; | |
2260 | } | |
2261 | ||
2262 | static int ath11k_clear_peer_keys(struct ath11k_vif *arvif, | |
2263 | const u8 *addr) | |
2264 | { | |
2265 | struct ath11k *ar = arvif->ar; | |
2266 | struct ath11k_base *ab = ar->ab; | |
2267 | struct ath11k_peer *peer; | |
2268 | int first_errno = 0; | |
2269 | int ret; | |
2270 | int i; | |
2271 | u32 flags = 0; | |
2272 | ||
2273 | lockdep_assert_held(&ar->conf_mutex); | |
2274 | ||
2275 | spin_lock_bh(&ab->base_lock); | |
2276 | peer = ath11k_peer_find(ab, arvif->vdev_id, addr); | |
2277 | spin_unlock_bh(&ab->base_lock); | |
2278 | ||
2279 | if (!peer) | |
2280 | return -ENOENT; | |
2281 | ||
2282 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
2283 | if (!peer->keys[i]) | |
2284 | continue; | |
2285 | ||
2286 | /* key flags are not required to delete the key */ | |
2287 | ret = ath11k_install_key(arvif, peer->keys[i], | |
2288 | DISABLE_KEY, addr, flags); | |
2289 | if (ret < 0 && first_errno == 0) | |
2290 | first_errno = ret; | |
2291 | ||
2292 | if (ret < 0) | |
2293 | ath11k_warn(ab, "failed to remove peer key %d: %d\n", | |
2294 | i, ret); | |
2295 | ||
2296 | spin_lock_bh(&ab->base_lock); | |
2297 | peer->keys[i] = NULL; | |
2298 | spin_unlock_bh(&ab->base_lock); | |
2299 | } | |
2300 | ||
2301 | return first_errno; | |
2302 | } | |
2303 | ||
2304 | static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
2305 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
2306 | struct ieee80211_key_conf *key) | |
2307 | { | |
2308 | struct ath11k *ar = hw->priv; | |
2309 | struct ath11k_base *ab = ar->ab; | |
2310 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2311 | struct ath11k_peer *peer; | |
2312 | const u8 *peer_addr; | |
2313 | int ret = 0; | |
2314 | u32 flags = 0; | |
2315 | ||
2316 | /* BIP needs to be done in software */ | |
2317 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || | |
2318 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
2319 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || | |
2320 | key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) | |
2321 | return 1; | |
2322 | ||
2323 | if (key->keyidx > WMI_MAX_KEY_INDEX) | |
2324 | return -ENOSPC; | |
2325 | ||
2326 | mutex_lock(&ar->conf_mutex); | |
2327 | ||
2328 | if (sta) | |
2329 | peer_addr = sta->addr; | |
2330 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
2331 | peer_addr = vif->bss_conf.bssid; | |
2332 | else | |
2333 | peer_addr = vif->addr; | |
2334 | ||
2335 | key->hw_key_idx = key->keyidx; | |
2336 | ||
2337 | /* the peer should not disappear in mid-way (unless FW goes awry) since | |
2338 | * we already hold conf_mutex. we just make sure its there now. | |
2339 | */ | |
2340 | spin_lock_bh(&ab->base_lock); | |
2341 | peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr); | |
2342 | spin_unlock_bh(&ab->base_lock); | |
2343 | ||
2344 | if (!peer) { | |
2345 | if (cmd == SET_KEY) { | |
2346 | ath11k_warn(ab, "cannot install key for non-existent peer %pM\n", | |
2347 | peer_addr); | |
2348 | ret = -EOPNOTSUPP; | |
2349 | goto exit; | |
2350 | } else { | |
2351 | /* if the peer doesn't exist there is no key to disable | |
2352 | * anymore | |
2353 | */ | |
2354 | goto exit; | |
2355 | } | |
2356 | } | |
2357 | ||
2358 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
2359 | flags |= WMI_KEY_PAIRWISE; | |
2360 | else | |
2361 | flags |= WMI_KEY_GROUP; | |
2362 | ||
2363 | ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags); | |
2364 | if (ret) { | |
2365 | ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret); | |
2366 | goto exit; | |
2367 | } | |
2368 | ||
2369 | spin_lock_bh(&ab->base_lock); | |
2370 | peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr); | |
2371 | if (peer && cmd == SET_KEY) | |
2372 | peer->keys[key->keyidx] = key; | |
2373 | else if (peer && cmd == DISABLE_KEY) | |
2374 | peer->keys[key->keyidx] = NULL; | |
2375 | else if (!peer) | |
2376 | /* impossible unless FW goes crazy */ | |
2377 | ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr); | |
2378 | spin_unlock_bh(&ab->base_lock); | |
2379 | ||
2380 | exit: | |
2381 | mutex_unlock(&ar->conf_mutex); | |
2382 | return ret; | |
2383 | } | |
2384 | ||
2385 | static int | |
2386 | ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar, | |
2387 | enum nl80211_band band, | |
2388 | const struct cfg80211_bitrate_mask *mask) | |
2389 | { | |
2390 | int num_rates = 0; | |
2391 | int i; | |
2392 | ||
2393 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) | |
2394 | num_rates += hweight16(mask->control[band].vht_mcs[i]); | |
2395 | ||
2396 | return num_rates; | |
2397 | } | |
2398 | ||
2399 | static int | |
2400 | ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif, | |
2401 | struct ieee80211_sta *sta, | |
2402 | const struct cfg80211_bitrate_mask *mask, | |
2403 | enum nl80211_band band) | |
2404 | { | |
2405 | struct ath11k *ar = arvif->ar; | |
2406 | u8 vht_rate, nss; | |
2407 | u32 rate_code; | |
2408 | int ret, i; | |
2409 | ||
2410 | lockdep_assert_held(&ar->conf_mutex); | |
2411 | ||
2412 | nss = 0; | |
2413 | ||
2414 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
2415 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { | |
2416 | nss = i + 1; | |
2417 | vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1; | |
2418 | } | |
2419 | } | |
2420 | ||
2421 | if (!nss) { | |
2422 | ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM", | |
2423 | sta->addr); | |
2424 | return -EINVAL; | |
2425 | } | |
2426 | ||
2427 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
2428 | "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates", | |
2429 | sta->addr); | |
2430 | ||
2431 | rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1, | |
2432 | WMI_RATE_PREAMBLE_VHT); | |
2433 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, | |
2434 | arvif->vdev_id, | |
2435 | WMI_PEER_PARAM_FIXED_RATE, | |
2436 | rate_code); | |
2437 | if (ret) | |
2438 | ath11k_warn(ar->ab, | |
2439 | "failed to update STA %pM Fixed Rate %d: %d\n", | |
2440 | sta->addr, rate_code, ret); | |
2441 | ||
2442 | return ret; | |
2443 | } | |
2444 | ||
2445 | static int ath11k_station_assoc(struct ath11k *ar, | |
2446 | struct ieee80211_vif *vif, | |
2447 | struct ieee80211_sta *sta, | |
2448 | bool reassoc) | |
2449 | { | |
2450 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2451 | struct peer_assoc_params peer_arg; | |
2452 | int ret = 0; | |
2453 | struct cfg80211_chan_def def; | |
2454 | enum nl80211_band band; | |
2455 | struct cfg80211_bitrate_mask *mask; | |
2456 | u8 num_vht_rates; | |
2457 | ||
2458 | lockdep_assert_held(&ar->conf_mutex); | |
2459 | ||
2460 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
2461 | return -EPERM; | |
2462 | ||
2463 | band = def.chan->band; | |
2464 | mask = &arvif->bitrate_mask; | |
2465 | ||
2466 | ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc); | |
2467 | ||
2468 | ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
2469 | if (ret) { | |
2470 | ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
2471 | sta->addr, arvif->vdev_id, ret); | |
2472 | return ret; | |
2473 | } | |
2474 | ||
2475 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
2476 | ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
2477 | sta->addr, arvif->vdev_id); | |
2478 | return -ETIMEDOUT; | |
2479 | } | |
2480 | ||
2481 | num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask); | |
2482 | ||
2483 | /* If single VHT rate is configured (by set_bitrate_mask()), | |
2484 | * peer_assoc will disable VHT. This is now enabled by a peer specific | |
2485 | * fixed param. | |
2486 | * Note that all other rates and NSS will be disabled for this peer. | |
2487 | */ | |
2488 | if (sta->vht_cap.vht_supported && num_vht_rates == 1) { | |
2489 | ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask, | |
2490 | band); | |
2491 | if (ret) | |
2492 | return ret; | |
2493 | } | |
2494 | ||
2495 | /* Re-assoc is run only to update supported rates for given station. It | |
2496 | * doesn't make much sense to reconfigure the peer completely. | |
2497 | */ | |
2498 | if (reassoc) | |
2499 | return 0; | |
2500 | ||
2501 | ret = ath11k_setup_peer_smps(ar, arvif, sta->addr, | |
2502 | &sta->ht_cap); | |
2503 | if (ret) { | |
2504 | ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
2505 | arvif->vdev_id, ret); | |
2506 | return ret; | |
2507 | } | |
2508 | ||
2509 | if (!sta->wme) { | |
2510 | arvif->num_legacy_stations++; | |
2511 | ret = ath11k_recalc_rtscts_prot(arvif); | |
2512 | if (ret) | |
2513 | return ret; | |
2514 | } | |
2515 | ||
2516 | if (sta->wme && sta->uapsd_queues) { | |
2517 | ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta); | |
2518 | if (ret) { | |
2519 | ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n", | |
2520 | sta->addr, arvif->vdev_id, ret); | |
2521 | return ret; | |
2522 | } | |
2523 | } | |
2524 | ||
2525 | return 0; | |
2526 | } | |
2527 | ||
2528 | static int ath11k_station_disassoc(struct ath11k *ar, | |
2529 | struct ieee80211_vif *vif, | |
2530 | struct ieee80211_sta *sta) | |
2531 | { | |
2532 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
2533 | int ret = 0; | |
2534 | ||
2535 | lockdep_assert_held(&ar->conf_mutex); | |
2536 | ||
2537 | if (!sta->wme) { | |
2538 | arvif->num_legacy_stations--; | |
2539 | ret = ath11k_recalc_rtscts_prot(arvif); | |
2540 | if (ret) | |
2541 | return ret; | |
2542 | } | |
2543 | ||
2544 | ret = ath11k_clear_peer_keys(arvif, sta->addr); | |
2545 | if (ret) { | |
2546 | ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n", | |
2547 | arvif->vdev_id, ret); | |
2548 | return ret; | |
2549 | } | |
2550 | return 0; | |
2551 | } | |
2552 | ||
2553 | static void ath11k_sta_rc_update_wk(struct work_struct *wk) | |
2554 | { | |
2555 | struct ath11k *ar; | |
2556 | struct ath11k_vif *arvif; | |
2557 | struct ath11k_sta *arsta; | |
2558 | struct ieee80211_sta *sta; | |
2559 | struct cfg80211_chan_def def; | |
2560 | enum nl80211_band band; | |
2561 | const u8 *ht_mcs_mask; | |
2562 | const u16 *vht_mcs_mask; | |
2563 | u32 changed, bw, nss, smps; | |
2564 | int err, num_vht_rates; | |
2565 | const struct cfg80211_bitrate_mask *mask; | |
2566 | struct peer_assoc_params peer_arg; | |
2567 | ||
2568 | arsta = container_of(wk, struct ath11k_sta, update_wk); | |
2569 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); | |
2570 | arvif = arsta->arvif; | |
2571 | ar = arvif->ar; | |
2572 | ||
2573 | if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def))) | |
2574 | return; | |
2575 | ||
2576 | band = def.chan->band; | |
2577 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
2578 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2579 | ||
2580 | spin_lock_bh(&ar->data_lock); | |
2581 | ||
2582 | changed = arsta->changed; | |
2583 | arsta->changed = 0; | |
2584 | ||
2585 | bw = arsta->bw; | |
2586 | nss = arsta->nss; | |
2587 | smps = arsta->smps; | |
2588 | ||
2589 | spin_unlock_bh(&ar->data_lock); | |
2590 | ||
2591 | mutex_lock(&ar->conf_mutex); | |
2592 | ||
2593 | nss = max_t(u32, 1, nss); | |
2594 | nss = min(nss, max(ath11k_mac_max_ht_nss(ht_mcs_mask), | |
2595 | ath11k_mac_max_vht_nss(vht_mcs_mask))); | |
2596 | ||
2597 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
2598 | err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2599 | WMI_PEER_CHWIDTH, bw); | |
2600 | if (err) | |
2601 | ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n", | |
2602 | sta->addr, bw, err); | |
2603 | } | |
2604 | ||
2605 | if (changed & IEEE80211_RC_NSS_CHANGED) { | |
2606 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n", | |
2607 | sta->addr, nss); | |
2608 | ||
2609 | err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2610 | WMI_PEER_NSS, nss); | |
2611 | if (err) | |
2612 | ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n", | |
2613 | sta->addr, nss, err); | |
2614 | } | |
2615 | ||
2616 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
2617 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n", | |
2618 | sta->addr, smps); | |
2619 | ||
2620 | err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2621 | WMI_PEER_MIMO_PS_STATE, smps); | |
2622 | if (err) | |
2623 | ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n", | |
2624 | sta->addr, smps, err); | |
2625 | } | |
2626 | ||
2627 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { | |
2628 | mask = &arvif->bitrate_mask; | |
2629 | num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, | |
2630 | mask); | |
2631 | ||
2632 | /* Peer_assoc_prepare will reject vht rates in | |
2633 | * bitrate_mask if its not available in range format and | |
2634 | * sets vht tx_rateset as unsupported. So multiple VHT MCS | |
2635 | * setting(eg. MCS 4,5,6) per peer is not supported here. | |
2636 | * But, Single rate in VHT mask can be set as per-peer | |
2637 | * fixed rate. But even if any HT rates are configured in | |
2638 | * the bitrate mask, device will not switch to those rates | |
2639 | * when per-peer Fixed rate is set. | |
2640 | * TODO: Check RATEMASK_CMDID to support auto rates selection | |
2641 | * across HT/VHT and for multiple VHT MCS support. | |
2642 | */ | |
2643 | if (sta->vht_cap.vht_supported && num_vht_rates == 1) { | |
2644 | ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask, | |
2645 | band); | |
2646 | } else { | |
2647 | /* If the peer is non-VHT or no fixed VHT rate | |
2648 | * is provided in the new bitrate mask we set the | |
2649 | * other rates using peer_assoc command. | |
2650 | */ | |
2651 | ath11k_peer_assoc_prepare(ar, arvif->vif, sta, | |
2652 | &peer_arg, true); | |
2653 | ||
2654 | err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
2655 | if (err) | |
2656 | ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
2657 | sta->addr, arvif->vdev_id, err); | |
2658 | ||
2659 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) | |
2660 | ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
2661 | sta->addr, arvif->vdev_id); | |
2662 | } | |
2663 | } | |
2664 | ||
2665 | mutex_unlock(&ar->conf_mutex); | |
2666 | } | |
2667 | ||
2668 | static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif, | |
2669 | struct ieee80211_sta *sta) | |
2670 | { | |
2671 | struct ath11k *ar = arvif->ar; | |
2672 | ||
2673 | lockdep_assert_held(&ar->conf_mutex); | |
2674 | ||
2675 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) | |
2676 | return 0; | |
2677 | ||
2678 | if (ar->num_stations >= ar->max_num_stations) | |
2679 | return -ENOBUFS; | |
2680 | ||
2681 | ar->num_stations++; | |
2682 | ||
2683 | return 0; | |
2684 | } | |
2685 | ||
2686 | static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif, | |
2687 | struct ieee80211_sta *sta) | |
2688 | { | |
2689 | struct ath11k *ar = arvif->ar; | |
2690 | ||
2691 | lockdep_assert_held(&ar->conf_mutex); | |
2692 | ||
2693 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) | |
2694 | return; | |
2695 | ||
2696 | ar->num_stations--; | |
2697 | } | |
2698 | ||
5e971287 KP |
2699 | static int ath11k_mac_station_add(struct ath11k *ar, |
2700 | struct ieee80211_vif *vif, | |
2701 | struct ieee80211_sta *sta) | |
2702 | { | |
2703 | struct ath11k_base *ab = ar->ab; | |
2704 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2705 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
2706 | struct peer_create_params peer_param; | |
2707 | int ret; | |
2708 | ||
2709 | lockdep_assert_held(&ar->conf_mutex); | |
2710 | ||
2711 | ret = ath11k_mac_inc_num_stations(arvif, sta); | |
2712 | if (ret) { | |
2713 | ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n", | |
2714 | ar->max_num_stations); | |
2715 | goto exit; | |
2716 | } | |
2717 | ||
2718 | arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL); | |
2719 | if (!arsta->rx_stats) { | |
2720 | ret = -ENOMEM; | |
2721 | goto dec_num_station; | |
2722 | } | |
2723 | ||
2724 | peer_param.vdev_id = arvif->vdev_id; | |
2725 | peer_param.peer_addr = sta->addr; | |
2726 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
2727 | ||
2728 | ret = ath11k_peer_create(ar, arvif, sta, &peer_param); | |
2729 | if (ret) { | |
2730 | ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n", | |
2731 | sta->addr, arvif->vdev_id); | |
2732 | goto free_rx_stats; | |
2733 | } | |
2734 | ||
2735 | ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n", | |
2736 | sta->addr, arvif->vdev_id); | |
2737 | ||
2738 | if (ath11k_debug_is_extd_tx_stats_enabled(ar)) { | |
2739 | arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL); | |
2740 | if (!arsta->tx_stats) { | |
2741 | ret = -ENOMEM; | |
2742 | goto free_peer; | |
2743 | } | |
2744 | } | |
2745 | ||
2746 | if (ieee80211_vif_is_mesh(vif)) { | |
2747 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, | |
2748 | arvif->vdev_id, | |
2749 | WMI_PEER_USE_4ADDR, 1); | |
2750 | if (ret) { | |
2751 | ath11k_warn(ab, "failed to STA %pM 4addr capability: %d\n", | |
2752 | sta->addr, ret); | |
2753 | goto free_tx_stats; | |
2754 | } | |
2755 | } | |
2756 | ||
2757 | ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr); | |
2758 | if (ret) { | |
2759 | ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n", | |
2760 | sta->addr, arvif->vdev_id, ret); | |
2761 | goto free_tx_stats; | |
2762 | } | |
2763 | ||
2764 | return 0; | |
2765 | ||
2766 | free_tx_stats: | |
2767 | kfree(arsta->tx_stats); | |
2768 | arsta->tx_stats = NULL; | |
2769 | free_peer: | |
2770 | ath11k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
2771 | free_rx_stats: | |
2772 | kfree(arsta->rx_stats); | |
2773 | arsta->rx_stats = NULL; | |
2774 | dec_num_station: | |
2775 | ath11k_mac_dec_num_stations(arvif, sta); | |
2776 | exit: | |
2777 | return ret; | |
2778 | } | |
2779 | ||
d5c65159 KV |
2780 | static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw, |
2781 | struct ieee80211_vif *vif, | |
2782 | struct ieee80211_sta *sta, | |
2783 | enum ieee80211_sta_state old_state, | |
2784 | enum ieee80211_sta_state new_state) | |
2785 | { | |
2786 | struct ath11k *ar = hw->priv; | |
2787 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2788 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
d5c65159 KV |
2789 | int ret = 0; |
2790 | ||
2791 | /* cancel must be done outside the mutex to avoid deadlock */ | |
2792 | if ((old_state == IEEE80211_STA_NONE && | |
2793 | new_state == IEEE80211_STA_NOTEXIST)) | |
2794 | cancel_work_sync(&arsta->update_wk); | |
2795 | ||
2796 | mutex_lock(&ar->conf_mutex); | |
2797 | ||
2798 | if (old_state == IEEE80211_STA_NOTEXIST && | |
2799 | new_state == IEEE80211_STA_NONE) { | |
2800 | memset(arsta, 0, sizeof(*arsta)); | |
2801 | arsta->arvif = arvif; | |
2802 | INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk); | |
2803 | ||
5e971287 KP |
2804 | ret = ath11k_mac_station_add(ar, vif, sta); |
2805 | if (ret) | |
2806 | ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n", | |
d5c65159 | 2807 | sta->addr, arvif->vdev_id); |
d5c65159 KV |
2808 | } else if ((old_state == IEEE80211_STA_NONE && |
2809 | new_state == IEEE80211_STA_NOTEXIST)) { | |
2810 | ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr); | |
2811 | ||
2812 | ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
2813 | if (ret) | |
2814 | ath11k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n", | |
2815 | sta->addr, arvif->vdev_id); | |
2816 | else | |
5e971287 KP |
2817 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n", |
2818 | sta->addr, arvif->vdev_id); | |
d5c65159 KV |
2819 | |
2820 | ath11k_mac_dec_num_stations(arvif, sta); | |
2821 | ||
2822 | kfree(arsta->tx_stats); | |
2823 | arsta->tx_stats = NULL; | |
2824 | ||
2825 | kfree(arsta->rx_stats); | |
2826 | arsta->rx_stats = NULL; | |
2827 | } else if (old_state == IEEE80211_STA_AUTH && | |
2828 | new_state == IEEE80211_STA_ASSOC && | |
2829 | (vif->type == NL80211_IFTYPE_AP || | |
2830 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
2831 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
2832 | ret = ath11k_station_assoc(ar, vif, sta, false); | |
2833 | if (ret) | |
2834 | ath11k_warn(ar->ab, "Failed to associate station: %pM\n", | |
2835 | sta->addr); | |
2836 | else | |
2837 | ath11k_info(ar->ab, | |
2838 | "Station %pM moved to assoc state\n", | |
2839 | sta->addr); | |
2840 | } else if (old_state == IEEE80211_STA_ASSOC && | |
2841 | new_state == IEEE80211_STA_AUTH && | |
2842 | (vif->type == NL80211_IFTYPE_AP || | |
2843 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
2844 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
2845 | ret = ath11k_station_disassoc(ar, vif, sta); | |
2846 | if (ret) | |
2847 | ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n", | |
2848 | sta->addr); | |
2849 | else | |
2850 | ath11k_info(ar->ab, | |
2851 | "Station %pM moved to disassociated state\n", | |
2852 | sta->addr); | |
2853 | } | |
2854 | ||
d5c65159 KV |
2855 | mutex_unlock(&ar->conf_mutex); |
2856 | return ret; | |
2857 | } | |
2858 | ||
64f1d7e9 MK |
2859 | static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw, |
2860 | struct ieee80211_vif *vif, | |
2861 | struct ieee80211_sta *sta) | |
2862 | { | |
2863 | struct ath11k *ar = hw->priv; | |
2864 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
2865 | int ret = 0; | |
2866 | s16 txpwr; | |
2867 | ||
2868 | if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) { | |
2869 | txpwr = 0; | |
2870 | } else { | |
2871 | txpwr = sta->txpwr.power; | |
2872 | if (!txpwr) | |
2873 | return -EINVAL; | |
2874 | } | |
2875 | ||
2876 | if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL) | |
2877 | return -EINVAL; | |
2878 | ||
2879 | mutex_lock(&ar->conf_mutex); | |
2880 | ||
2881 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2882 | WMI_PEER_USE_FIXED_PWR, txpwr); | |
2883 | if (ret) { | |
2884 | ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n", | |
2885 | ret); | |
2886 | goto out; | |
2887 | } | |
2888 | ||
2889 | out: | |
2890 | mutex_unlock(&ar->conf_mutex); | |
2891 | return ret; | |
2892 | } | |
2893 | ||
d5c65159 KV |
2894 | static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw, |
2895 | struct ieee80211_vif *vif, | |
2896 | struct ieee80211_sta *sta, | |
2897 | u32 changed) | |
2898 | { | |
2899 | struct ath11k *ar = hw->priv; | |
2900 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
2901 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
2902 | struct ath11k_peer *peer; | |
2903 | u32 bw, smps; | |
2904 | ||
2905 | spin_lock_bh(&ar->ab->base_lock); | |
2906 | ||
2907 | peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr); | |
2908 | if (!peer) { | |
2909 | spin_unlock_bh(&ar->ab->base_lock); | |
2910 | ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n", | |
2911 | sta->addr, arvif->vdev_id); | |
2912 | return; | |
2913 | } | |
2914 | ||
2915 | spin_unlock_bh(&ar->ab->base_lock); | |
2916 | ||
2917 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
2918 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", | |
2919 | sta->addr, changed, sta->bandwidth, sta->rx_nss, | |
2920 | sta->smps_mode); | |
2921 | ||
2922 | spin_lock_bh(&ar->data_lock); | |
2923 | ||
2924 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
2925 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
2926 | ||
2927 | switch (sta->bandwidth) { | |
2928 | case IEEE80211_STA_RX_BW_20: | |
2929 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
2930 | break; | |
2931 | case IEEE80211_STA_RX_BW_40: | |
2932 | bw = WMI_PEER_CHWIDTH_40MHZ; | |
2933 | break; | |
2934 | case IEEE80211_STA_RX_BW_80: | |
2935 | bw = WMI_PEER_CHWIDTH_80MHZ; | |
2936 | break; | |
2937 | case IEEE80211_STA_RX_BW_160: | |
2938 | bw = WMI_PEER_CHWIDTH_160MHZ; | |
2939 | break; | |
2940 | default: | |
2941 | ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n", | |
2942 | sta->bandwidth, sta->addr); | |
2943 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
2944 | break; | |
2945 | } | |
2946 | ||
2947 | arsta->bw = bw; | |
2948 | } | |
2949 | ||
2950 | if (changed & IEEE80211_RC_NSS_CHANGED) | |
2951 | arsta->nss = sta->rx_nss; | |
2952 | ||
2953 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
2954 | smps = WMI_PEER_SMPS_PS_NONE; | |
2955 | ||
2956 | switch (sta->smps_mode) { | |
2957 | case IEEE80211_SMPS_AUTOMATIC: | |
2958 | case IEEE80211_SMPS_OFF: | |
2959 | smps = WMI_PEER_SMPS_PS_NONE; | |
2960 | break; | |
2961 | case IEEE80211_SMPS_STATIC: | |
2962 | smps = WMI_PEER_SMPS_STATIC; | |
2963 | break; | |
2964 | case IEEE80211_SMPS_DYNAMIC: | |
2965 | smps = WMI_PEER_SMPS_DYNAMIC; | |
2966 | break; | |
2967 | default: | |
2968 | ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n", | |
2969 | sta->smps_mode, sta->addr); | |
2970 | smps = WMI_PEER_SMPS_PS_NONE; | |
2971 | break; | |
2972 | } | |
2973 | ||
2974 | arsta->smps = smps; | |
2975 | } | |
2976 | ||
2977 | arsta->changed |= changed; | |
2978 | ||
2979 | spin_unlock_bh(&ar->data_lock); | |
2980 | ||
2981 | ieee80211_queue_work(hw, &arsta->update_wk); | |
2982 | } | |
2983 | ||
2984 | static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif, | |
2985 | u16 ac, bool enable) | |
2986 | { | |
2987 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2988 | u32 value = 0; | |
2989 | int ret = 0; | |
2990 | ||
2991 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) | |
2992 | return 0; | |
2993 | ||
2994 | switch (ac) { | |
2995 | case IEEE80211_AC_VO: | |
2996 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | | |
2997 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; | |
2998 | break; | |
2999 | case IEEE80211_AC_VI: | |
3000 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | | |
3001 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; | |
3002 | break; | |
3003 | case IEEE80211_AC_BE: | |
3004 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | | |
3005 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; | |
3006 | break; | |
3007 | case IEEE80211_AC_BK: | |
3008 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | | |
3009 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; | |
3010 | break; | |
3011 | } | |
3012 | ||
3013 | if (enable) | |
3014 | arvif->u.sta.uapsd |= value; | |
3015 | else | |
3016 | arvif->u.sta.uapsd &= ~value; | |
3017 | ||
3018 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3019 | WMI_STA_PS_PARAM_UAPSD, | |
3020 | arvif->u.sta.uapsd); | |
3021 | if (ret) { | |
3022 | ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret); | |
3023 | goto exit; | |
3024 | } | |
3025 | ||
3026 | if (arvif->u.sta.uapsd) | |
3027 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; | |
3028 | else | |
3029 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
3030 | ||
3031 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3032 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, | |
3033 | value); | |
3034 | if (ret) | |
3035 | ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret); | |
3036 | ||
3037 | exit: | |
3038 | return ret; | |
3039 | } | |
3040 | ||
3041 | static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw, | |
3042 | struct ieee80211_vif *vif, u16 ac, | |
3043 | const struct ieee80211_tx_queue_params *params) | |
3044 | { | |
3045 | struct ath11k *ar = hw->priv; | |
3046 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
3047 | struct wmi_wmm_params_arg *p = NULL; | |
3048 | int ret; | |
3049 | ||
3050 | mutex_lock(&ar->conf_mutex); | |
3051 | ||
3052 | switch (ac) { | |
3053 | case IEEE80211_AC_VO: | |
3054 | p = &arvif->wmm_params.ac_vo; | |
3055 | break; | |
3056 | case IEEE80211_AC_VI: | |
3057 | p = &arvif->wmm_params.ac_vi; | |
3058 | break; | |
3059 | case IEEE80211_AC_BE: | |
3060 | p = &arvif->wmm_params.ac_be; | |
3061 | break; | |
3062 | case IEEE80211_AC_BK: | |
3063 | p = &arvif->wmm_params.ac_bk; | |
3064 | break; | |
3065 | } | |
3066 | ||
3067 | if (WARN_ON(!p)) { | |
3068 | ret = -EINVAL; | |
3069 | goto exit; | |
3070 | } | |
3071 | ||
3072 | p->cwmin = params->cw_min; | |
3073 | p->cwmax = params->cw_max; | |
3074 | p->aifs = params->aifs; | |
f425078b | 3075 | p->txop = params->txop; |
d5c65159 KV |
3076 | |
3077 | ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id, | |
3078 | &arvif->wmm_params); | |
3079 | if (ret) { | |
3080 | ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret); | |
3081 | goto exit; | |
3082 | } | |
3083 | ||
3084 | ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd); | |
3085 | ||
3086 | if (ret) | |
3087 | ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret); | |
3088 | ||
3089 | exit: | |
3090 | mutex_unlock(&ar->conf_mutex); | |
3091 | return ret; | |
3092 | } | |
3093 | ||
3094 | static struct ieee80211_sta_ht_cap | |
3095 | ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask) | |
3096 | { | |
3097 | int i; | |
3098 | struct ieee80211_sta_ht_cap ht_cap = {0}; | |
3099 | u32 ar_vht_cap = ar->pdev->cap.vht_cap; | |
3100 | ||
3101 | if (!(ar_ht_cap & WMI_HT_CAP_ENABLED)) | |
3102 | return ht_cap; | |
3103 | ||
3104 | ht_cap.ht_supported = 1; | |
3105 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
c000e56e | 3106 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
d5c65159 KV |
3107 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
3108 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
3109 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; | |
3110 | ||
3111 | if (ar_ht_cap & WMI_HT_CAP_HT20_SGI) | |
3112 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
3113 | ||
3114 | if (ar_ht_cap & WMI_HT_CAP_HT40_SGI) | |
3115 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
3116 | ||
3117 | if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) { | |
3118 | u32 smps; | |
3119 | ||
3120 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | |
3121 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
3122 | ||
3123 | ht_cap.cap |= smps; | |
3124 | } | |
3125 | ||
3126 | if (ar_ht_cap & WMI_HT_CAP_TX_STBC) | |
3127 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; | |
3128 | ||
3129 | if (ar_ht_cap & WMI_HT_CAP_RX_STBC) { | |
3130 | u32 stbc; | |
3131 | ||
3132 | stbc = ar_ht_cap; | |
3133 | stbc &= WMI_HT_CAP_RX_STBC; | |
3134 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; | |
3135 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
3136 | stbc &= IEEE80211_HT_CAP_RX_STBC; | |
3137 | ||
3138 | ht_cap.cap |= stbc; | |
3139 | } | |
3140 | ||
3141 | if (ar_ht_cap & WMI_HT_CAP_RX_LDPC) | |
3142 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; | |
3143 | ||
3144 | if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT) | |
3145 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; | |
3146 | ||
3147 | if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) | |
3148 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; | |
3149 | ||
3150 | for (i = 0; i < ar->num_rx_chains; i++) { | |
3151 | if (rate_cap_rx_chainmask & BIT(i)) | |
3152 | ht_cap.mcs.rx_mask[i] = 0xFF; | |
3153 | } | |
3154 | ||
3155 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; | |
3156 | ||
3157 | return ht_cap; | |
3158 | } | |
3159 | ||
3160 | static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif) | |
3161 | { | |
3162 | u32 value = 0; | |
3163 | struct ath11k *ar = arvif->ar; | |
3164 | int nsts; | |
3165 | int sound_dim; | |
3166 | u32 vht_cap = ar->pdev->cap.vht_cap; | |
3167 | u32 vdev_param = WMI_VDEV_PARAM_TXBF; | |
3168 | ||
3169 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) { | |
3170 | nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
3171 | nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
3172 | value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); | |
3173 | } | |
3174 | ||
3175 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { | |
3176 | sound_dim = vht_cap & | |
3177 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3178 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3179 | if (sound_dim > (ar->num_tx_chains - 1)) | |
3180 | sound_dim = ar->num_tx_chains - 1; | |
3181 | value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); | |
3182 | } | |
3183 | ||
3184 | if (!value) | |
3185 | return 0; | |
3186 | ||
3187 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) { | |
3188 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
3189 | ||
3190 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && | |
3191 | arvif->vdev_type == WMI_VDEV_TYPE_AP) | |
3192 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; | |
3193 | } | |
3194 | ||
3195 | /* TODO: SUBFEE not validated in HK, disable here until validated? */ | |
3196 | ||
3197 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) { | |
3198 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
3199 | ||
3200 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && | |
3201 | arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
3202 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; | |
3203 | } | |
3204 | ||
3205 | return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3206 | vdev_param, value); | |
3207 | } | |
3208 | ||
3209 | static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap) | |
3210 | { | |
3211 | bool subfer, subfee; | |
3212 | int sound_dim = 0; | |
3213 | ||
3214 | subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)); | |
3215 | subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)); | |
3216 | ||
3217 | if (ar->num_tx_chains < 2) { | |
3218 | *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); | |
3219 | subfer = false; | |
3220 | } | |
3221 | ||
3222 | /* If SU Beaformer is not set, then disable MU Beamformer Capability */ | |
3223 | if (!subfer) | |
3224 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); | |
3225 | ||
3226 | /* If SU Beaformee is not set, then disable MU Beamformee Capability */ | |
3227 | if (!subfee) | |
3228 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); | |
3229 | ||
3230 | sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
3231 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3232 | *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3233 | ||
3234 | /* TODO: Need to check invalid STS and Sound_dim values set by FW? */ | |
3235 | ||
3236 | /* Enable Sounding Dimension Field only if SU BF is enabled */ | |
3237 | if (subfer) { | |
3238 | if (sound_dim > (ar->num_tx_chains - 1)) | |
3239 | sound_dim = ar->num_tx_chains - 1; | |
3240 | ||
3241 | sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3242 | sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3243 | *vht_cap |= sound_dim; | |
3244 | } | |
3245 | ||
3246 | /* Use the STS advertised by FW unless SU Beamformee is not supported*/ | |
3247 | if (!subfee) | |
3248 | *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); | |
3249 | } | |
3250 | ||
3251 | static struct ieee80211_sta_vht_cap | |
3252 | ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask, | |
3253 | u32 rate_cap_rx_chainmask) | |
3254 | { | |
3255 | struct ieee80211_sta_vht_cap vht_cap = {0}; | |
3256 | u16 txmcs_map, rxmcs_map; | |
3257 | int i; | |
3258 | ||
3259 | vht_cap.vht_supported = 1; | |
3260 | vht_cap.cap = ar->pdev->cap.vht_cap; | |
3261 | ||
3262 | ath11k_set_vht_txbf_cap(ar, &vht_cap.cap); | |
3263 | ||
3264 | /* TODO: Enable back VHT160 mode once association issues are fixed */ | |
3265 | /* Disabling VHT160 and VHT80+80 modes */ | |
3266 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; | |
3267 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; | |
3268 | ||
3269 | rxmcs_map = 0; | |
3270 | txmcs_map = 0; | |
3271 | for (i = 0; i < 8; i++) { | |
3272 | if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i)) | |
3273 | txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
3274 | else | |
3275 | txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
3276 | ||
3277 | if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i)) | |
3278 | rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
3279 | else | |
3280 | rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
3281 | } | |
3282 | ||
3283 | if (rate_cap_tx_chainmask <= 1) | |
3284 | vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; | |
3285 | ||
3286 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map); | |
3287 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map); | |
3288 | ||
3289 | return vht_cap; | |
3290 | } | |
3291 | ||
3292 | static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar, | |
3293 | struct ath11k_pdev_cap *cap, | |
3294 | u32 *ht_cap_info) | |
3295 | { | |
3296 | struct ieee80211_supported_band *band; | |
3297 | u32 rate_cap_tx_chainmask; | |
3298 | u32 rate_cap_rx_chainmask; | |
3299 | u32 ht_cap; | |
3300 | ||
3301 | rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift; | |
3302 | rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift; | |
3303 | ||
3304 | if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
3305 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
3306 | ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info; | |
3307 | if (ht_cap_info) | |
3308 | *ht_cap_info = ht_cap; | |
3309 | band->ht_cap = ath11k_create_ht_cap(ar, ht_cap, | |
3310 | rate_cap_rx_chainmask); | |
3311 | } | |
3312 | ||
3313 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
3314 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
3315 | ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info; | |
3316 | if (ht_cap_info) | |
3317 | *ht_cap_info = ht_cap; | |
3318 | band->ht_cap = ath11k_create_ht_cap(ar, ht_cap, | |
3319 | rate_cap_rx_chainmask); | |
3320 | band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask, | |
3321 | rate_cap_rx_chainmask); | |
3322 | } | |
3323 | } | |
3324 | ||
3325 | static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant) | |
3326 | { | |
3327 | /* TODO: Check the request chainmask against the supported | |
3328 | * chainmask table which is advertised in extented_service_ready event | |
3329 | */ | |
3330 | ||
3331 | return 0; | |
3332 | } | |
3333 | ||
9f056ed8 JC |
3334 | static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet, |
3335 | u8 *he_ppet) | |
3336 | { | |
3337 | int nss, ru; | |
3338 | u8 bit = 7; | |
3339 | ||
3340 | he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK; | |
3341 | he_ppet[0] |= (fw_ppet->ru_bit_mask << | |
3342 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) & | |
3343 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK; | |
3344 | for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { | |
3345 | for (ru = 0; ru < 4; ru++) { | |
3346 | u8 val; | |
3347 | int i; | |
3348 | ||
3349 | if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) | |
3350 | continue; | |
3351 | val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) & | |
3352 | 0x3f; | |
3353 | val = ((val >> 3) & 0x7) | ((val & 0x7) << 3); | |
3354 | for (i = 5; i >= 0; i--) { | |
3355 | he_ppet[bit / 8] |= | |
3356 | ((val >> i) & 0x1) << ((bit % 8)); | |
3357 | bit++; | |
3358 | } | |
3359 | } | |
3360 | } | |
3361 | } | |
3362 | ||
13591a1c SE |
3363 | static void |
3364 | ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem) | |
3365 | { | |
3366 | u8 m; | |
3367 | ||
3368 | m = IEEE80211_HE_MAC_CAP0_TWT_RES | | |
3369 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
3370 | he_cap_elem->mac_cap_info[0] &= ~m; | |
3371 | ||
3372 | m = IEEE80211_HE_MAC_CAP2_TRS | | |
3373 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
3374 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
3375 | he_cap_elem->mac_cap_info[2] &= ~m; | |
3376 | ||
3377 | m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED | | |
3378 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
3379 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
3380 | he_cap_elem->mac_cap_info[3] &= ~m; | |
3381 | ||
3382 | m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG | | |
3383 | IEEE80211_HE_MAC_CAP4_BQR; | |
3384 | he_cap_elem->mac_cap_info[4] &= ~m; | |
3385 | ||
3386 | m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECVITE_TRANSMISSION | | |
3387 | IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU | | |
3388 | IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING | | |
3389 | IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX; | |
3390 | he_cap_elem->mac_cap_info[5] &= ~m; | |
3391 | ||
3392 | m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
3393 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; | |
3394 | he_cap_elem->phy_cap_info[2] &= ~m; | |
3395 | ||
3396 | m = IEEE80211_HE_PHY_CAP3_RX_HE_MU_PPDU_FROM_NON_AP_STA | | |
3397 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK | | |
3398 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK; | |
3399 | he_cap_elem->phy_cap_info[3] &= ~m; | |
3400 | ||
3401 | m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; | |
3402 | he_cap_elem->phy_cap_info[4] &= ~m; | |
3403 | ||
3404 | m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; | |
3405 | he_cap_elem->phy_cap_info[5] &= ~m; | |
3406 | ||
3407 | m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | | |
3408 | IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB | | |
3409 | IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | | |
3410 | IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; | |
3411 | he_cap_elem->phy_cap_info[6] &= ~m; | |
3412 | ||
3413 | m = IEEE80211_HE_PHY_CAP7_SRP_BASED_SR | | |
3414 | IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR | | |
3415 | IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | | |
3416 | IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; | |
3417 | he_cap_elem->phy_cap_info[7] &= ~m; | |
3418 | ||
3419 | m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | | |
3420 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | | |
3421 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | | |
3422 | IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU; | |
3423 | he_cap_elem->phy_cap_info[8] &= ~m; | |
3424 | ||
3425 | m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | | |
3426 | IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | | |
3427 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | | |
3428 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | | |
3429 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | | |
3430 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; | |
3431 | he_cap_elem->phy_cap_info[9] &= ~m; | |
3432 | } | |
3433 | ||
9f056ed8 JC |
3434 | static int ath11k_mac_copy_he_cap(struct ath11k *ar, |
3435 | struct ath11k_pdev_cap *cap, | |
3436 | struct ieee80211_sband_iftype_data *data, | |
3437 | int band) | |
3438 | { | |
3439 | int i, idx = 0; | |
3440 | ||
3441 | for (i = 0; i < NUM_NL80211_IFTYPES; i++) { | |
3442 | struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; | |
3443 | struct ath11k_band_cap *band_cap = &cap->band[band]; | |
3444 | struct ieee80211_he_cap_elem *he_cap_elem = | |
3445 | &he_cap->he_cap_elem; | |
3446 | ||
3447 | switch (i) { | |
3448 | case NL80211_IFTYPE_STATION: | |
3449 | case NL80211_IFTYPE_AP: | |
13591a1c | 3450 | case NL80211_IFTYPE_MESH_POINT: |
9f056ed8 JC |
3451 | break; |
3452 | ||
3453 | default: | |
3454 | continue; | |
3455 | } | |
3456 | ||
3457 | data[idx].types_mask = BIT(i); | |
3458 | he_cap->has_he = true; | |
3459 | memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info, | |
3460 | sizeof(he_cap_elem->mac_cap_info)); | |
3461 | memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info, | |
3462 | sizeof(he_cap_elem->phy_cap_info)); | |
3463 | ||
3464 | he_cap_elem->mac_cap_info[1] |= | |
3465 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK; | |
3466 | he_cap_elem->phy_cap_info[4] &= | |
3467 | ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK; | |
3468 | he_cap_elem->phy_cap_info[4] &= | |
3469 | ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK; | |
3470 | he_cap_elem->phy_cap_info[4] |= (ar->num_tx_chains - 1) << 2; | |
3471 | ||
3472 | he_cap_elem->phy_cap_info[5] &= | |
3473 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK; | |
3474 | he_cap_elem->phy_cap_info[5] &= | |
3475 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK; | |
3476 | he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1; | |
3477 | ||
3478 | switch (i) { | |
3479 | case NL80211_IFTYPE_AP: | |
3480 | he_cap_elem->phy_cap_info[9] |= | |
3481 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; | |
3482 | break; | |
3483 | case NL80211_IFTYPE_STATION: | |
3484 | he_cap_elem->mac_cap_info[0] &= | |
3485 | ~IEEE80211_HE_MAC_CAP0_TWT_RES; | |
3486 | he_cap_elem->mac_cap_info[0] |= | |
3487 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
3488 | he_cap_elem->phy_cap_info[9] |= | |
3489 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU; | |
3490 | break; | |
13591a1c SE |
3491 | case NL80211_IFTYPE_MESH_POINT: |
3492 | ath11k_mac_filter_he_cap_mesh(he_cap_elem); | |
3493 | break; | |
9f056ed8 JC |
3494 | } |
3495 | ||
3496 | he_cap->he_mcs_nss_supp.rx_mcs_80 = | |
3497 | cpu_to_le16(band_cap->he_mcs & 0xffff); | |
3498 | he_cap->he_mcs_nss_supp.tx_mcs_80 = | |
3499 | cpu_to_le16(band_cap->he_mcs & 0xffff); | |
3500 | he_cap->he_mcs_nss_supp.rx_mcs_160 = | |
3501 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3502 | he_cap->he_mcs_nss_supp.tx_mcs_160 = | |
3503 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3504 | he_cap->he_mcs_nss_supp.rx_mcs_80p80 = | |
3505 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3506 | he_cap->he_mcs_nss_supp.tx_mcs_80p80 = | |
3507 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3508 | ||
3509 | memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); | |
3510 | if (he_cap_elem->phy_cap_info[6] & | |
3511 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) | |
3512 | ath11k_gen_ppe_thresh(&band_cap->he_ppet, | |
3513 | he_cap->ppe_thres); | |
3514 | idx++; | |
3515 | } | |
3516 | ||
3517 | return idx; | |
3518 | } | |
3519 | ||
3520 | static void ath11k_mac_setup_he_cap(struct ath11k *ar, | |
3521 | struct ath11k_pdev_cap *cap) | |
3522 | { | |
3523 | struct ieee80211_supported_band *band = NULL; | |
3524 | int count = 0; | |
3525 | ||
3526 | if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
3527 | count = ath11k_mac_copy_he_cap(ar, cap, | |
3528 | ar->mac.iftype[NL80211_BAND_2GHZ], | |
3529 | NL80211_BAND_2GHZ); | |
3530 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
3531 | band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ]; | |
3532 | } | |
3533 | ||
3534 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
3535 | count = ath11k_mac_copy_he_cap(ar, cap, | |
3536 | ar->mac.iftype[NL80211_BAND_5GHZ], | |
3537 | NL80211_BAND_5GHZ); | |
3538 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
3539 | band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ]; | |
3540 | } | |
3541 | ||
3542 | band->n_iftype_data = count; | |
3543 | } | |
3544 | ||
d5c65159 KV |
3545 | static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant) |
3546 | { | |
3547 | int ret; | |
3548 | ||
3549 | lockdep_assert_held(&ar->conf_mutex); | |
3550 | ||
3551 | if (ath11k_check_chain_mask(ar, tx_ant, true)) | |
3552 | return -EINVAL; | |
3553 | ||
3554 | if (ath11k_check_chain_mask(ar, rx_ant, false)) | |
3555 | return -EINVAL; | |
3556 | ||
3557 | ar->cfg_tx_chainmask = tx_ant; | |
3558 | ar->cfg_rx_chainmask = rx_ant; | |
3559 | ||
3560 | if (ar->state != ATH11K_STATE_ON && | |
3561 | ar->state != ATH11K_STATE_RESTARTED) | |
3562 | return 0; | |
3563 | ||
3564 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK, | |
3565 | tx_ant, ar->pdev->pdev_id); | |
3566 | if (ret) { | |
3567 | ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n", | |
3568 | ret, tx_ant); | |
3569 | return ret; | |
3570 | } | |
3571 | ||
a3c5195a S |
3572 | ar->num_tx_chains = get_num_chains(tx_ant); |
3573 | ||
d5c65159 KV |
3574 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK, |
3575 | rx_ant, ar->pdev->pdev_id); | |
3576 | if (ret) { | |
3577 | ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n", | |
3578 | ret, rx_ant); | |
3579 | return ret; | |
3580 | } | |
3581 | ||
a3c5195a S |
3582 | ar->num_rx_chains = get_num_chains(rx_ant); |
3583 | ||
9f056ed8 | 3584 | /* Reload HT/VHT/HE capability */ |
d5c65159 | 3585 | ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL); |
9f056ed8 | 3586 | ath11k_mac_setup_he_cap(ar, &ar->pdev->cap); |
d5c65159 KV |
3587 | |
3588 | return 0; | |
3589 | } | |
3590 | ||
3591 | int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) | |
3592 | { | |
3593 | struct ath11k *ar = ctx; | |
3594 | struct ath11k_base *ab = ar->ab; | |
3595 | struct sk_buff *msdu = skb; | |
3596 | struct ieee80211_tx_info *info; | |
3597 | ||
3598 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3599 | idr_remove(&ar->txmgmt_idr, buf_id); | |
3600 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3601 | dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len, | |
3602 | DMA_TO_DEVICE); | |
3603 | ||
3604 | info = IEEE80211_SKB_CB(msdu); | |
3605 | memset(&info->status, 0, sizeof(info->status)); | |
3606 | ||
3607 | ieee80211_free_txskb(ar->hw, msdu); | |
3608 | ||
3609 | return 0; | |
3610 | } | |
3611 | ||
3612 | static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) | |
3613 | { | |
3614 | struct ieee80211_vif *vif = ctx; | |
3615 | struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb); | |
3616 | struct sk_buff *msdu = skb; | |
3617 | struct ath11k *ar = skb_cb->ar; | |
3618 | struct ath11k_base *ab = ar->ab; | |
3619 | ||
3620 | if (skb_cb->vif == vif) { | |
3621 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3622 | idr_remove(&ar->txmgmt_idr, buf_id); | |
3623 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3624 | dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, | |
3625 | DMA_TO_DEVICE); | |
3626 | } | |
3627 | ||
3628 | return 0; | |
3629 | } | |
3630 | ||
3631 | static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif, | |
3632 | struct sk_buff *skb) | |
3633 | { | |
3634 | struct ath11k_base *ab = ar->ab; | |
3635 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
3636 | dma_addr_t paddr; | |
3637 | int buf_id; | |
3638 | int ret; | |
3639 | ||
3640 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3641 | buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, | |
3642 | ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); | |
3643 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3644 | if (buf_id < 0) | |
3645 | return -ENOSPC; | |
3646 | ||
3647 | if ((ieee80211_is_action(hdr->frame_control) || | |
3648 | ieee80211_is_deauth(hdr->frame_control) || | |
3649 | ieee80211_is_disassoc(hdr->frame_control)) && | |
3650 | ieee80211_has_protected(hdr->frame_control)) { | |
3651 | skb_put(skb, IEEE80211_CCMP_MIC_LEN); | |
3652 | } | |
3653 | ||
3654 | paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE); | |
3655 | if (dma_mapping_error(ab->dev, paddr)) { | |
3656 | ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n"); | |
3657 | ret = -EIO; | |
3658 | goto err_free_idr; | |
3659 | } | |
3660 | ||
3661 | ATH11K_SKB_CB(skb)->paddr = paddr; | |
3662 | ||
3663 | ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb); | |
3664 | if (ret) { | |
3665 | ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret); | |
3666 | goto err_unmap_buf; | |
3667 | } | |
3668 | ||
3669 | return 0; | |
3670 | ||
3671 | err_unmap_buf: | |
3672 | dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr, | |
3673 | skb->len, DMA_TO_DEVICE); | |
3674 | err_free_idr: | |
3675 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3676 | idr_remove(&ar->txmgmt_idr, buf_id); | |
3677 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3678 | ||
3679 | return ret; | |
3680 | } | |
3681 | ||
3682 | static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar) | |
3683 | { | |
3684 | struct sk_buff *skb; | |
3685 | ||
3686 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) | |
3687 | ieee80211_free_txskb(ar->hw, skb); | |
3688 | } | |
3689 | ||
3690 | static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work) | |
3691 | { | |
3692 | struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work); | |
3693 | struct ieee80211_tx_info *info; | |
3694 | struct ath11k_vif *arvif; | |
3695 | struct sk_buff *skb; | |
3696 | int ret; | |
3697 | ||
3698 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) { | |
3699 | info = IEEE80211_SKB_CB(skb); | |
3700 | arvif = ath11k_vif_to_arvif(info->control.vif); | |
3701 | ||
3702 | ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb); | |
3703 | if (ret) { | |
3704 | ath11k_warn(ar->ab, "failed to transmit management frame %d\n", | |
3705 | ret); | |
3706 | ieee80211_free_txskb(ar->hw, skb); | |
3707 | } else { | |
3708 | atomic_inc(&ar->num_pending_mgmt_tx); | |
3709 | } | |
3710 | } | |
3711 | } | |
3712 | ||
3713 | static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb, | |
3714 | bool is_prb_rsp) | |
3715 | { | |
3716 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; | |
3717 | ||
3718 | if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
3719 | return -ESHUTDOWN; | |
3720 | ||
3721 | /* Drop probe response packets when the pending management tx | |
3722 | * count has reached a certain threshold, so as to prioritize | |
3723 | * other mgmt packets like auth and assoc to be sent on time | |
3724 | * for establishing successful connections. | |
3725 | */ | |
3726 | if (is_prb_rsp && | |
3727 | atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) { | |
3728 | ath11k_warn(ar->ab, | |
3729 | "dropping probe response as pending queue is almost full\n"); | |
3730 | return -ENOSPC; | |
3731 | } | |
3732 | ||
3733 | if (skb_queue_len(q) == ATH11K_TX_MGMT_NUM_PENDING_MAX) { | |
3734 | ath11k_warn(ar->ab, "mgmt tx queue is full\n"); | |
3735 | return -ENOSPC; | |
3736 | } | |
3737 | ||
3738 | skb_queue_tail(q, skb); | |
3739 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); | |
3740 | ||
3741 | return 0; | |
3742 | } | |
3743 | ||
3744 | static void ath11k_mac_op_tx(struct ieee80211_hw *hw, | |
3745 | struct ieee80211_tx_control *control, | |
3746 | struct sk_buff *skb) | |
3747 | { | |
3748 | struct ath11k *ar = hw->priv; | |
3749 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
3750 | struct ieee80211_vif *vif = info->control.vif; | |
3751 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
3752 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
3753 | bool is_prb_rsp; | |
3754 | int ret; | |
3755 | ||
3756 | if (ieee80211_is_mgmt(hdr->frame_control)) { | |
3757 | is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control); | |
3758 | ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp); | |
3759 | if (ret) { | |
3760 | ath11k_warn(ar->ab, "failed to queue management frame %d\n", | |
3761 | ret); | |
3762 | ieee80211_free_txskb(ar->hw, skb); | |
3763 | } | |
3764 | return; | |
3765 | } | |
3766 | ||
3767 | ret = ath11k_dp_tx(ar, arvif, skb); | |
3768 | if (ret) { | |
3769 | ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret); | |
3770 | ieee80211_free_txskb(ar->hw, skb); | |
3771 | } | |
3772 | } | |
3773 | ||
3774 | void ath11k_mac_drain_tx(struct ath11k *ar) | |
3775 | { | |
3776 | /* make sure rcu-protected mac80211 tx path itself is drained */ | |
3777 | synchronize_net(); | |
3778 | ||
3779 | cancel_work_sync(&ar->wmi_mgmt_tx_work); | |
3780 | ath11k_mgmt_over_wmi_tx_purge(ar); | |
3781 | } | |
3782 | ||
3783 | static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable) | |
3784 | { | |
3785 | struct htt_rx_ring_tlv_filter tlv_filter = {0}; | |
3786 | u32 ring_id; | |
3787 | ||
3788 | if (enable) | |
3789 | tlv_filter = ath11k_mac_mon_status_filter_default; | |
3790 | ||
3791 | ring_id = ar->dp.rx_mon_status_refill_ring.refill_buf_ring.ring_id; | |
3792 | ||
3793 | return ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id, ar->dp.mac_id, | |
3794 | HAL_RXDMA_MONITOR_STATUS, | |
3795 | DP_RX_BUFFER_SIZE, &tlv_filter); | |
3796 | } | |
3797 | ||
3798 | static int ath11k_mac_op_start(struct ieee80211_hw *hw) | |
3799 | { | |
3800 | struct ath11k *ar = hw->priv; | |
3801 | struct ath11k_base *ab = ar->ab; | |
3802 | struct ath11k_pdev *pdev = ar->pdev; | |
3803 | int ret; | |
3804 | ||
3805 | ath11k_mac_drain_tx(ar); | |
3806 | mutex_lock(&ar->conf_mutex); | |
3807 | ||
3808 | switch (ar->state) { | |
3809 | case ATH11K_STATE_OFF: | |
3810 | ar->state = ATH11K_STATE_ON; | |
3811 | break; | |
3812 | case ATH11K_STATE_RESTARTING: | |
3813 | ar->state = ATH11K_STATE_RESTARTED; | |
3814 | break; | |
3815 | case ATH11K_STATE_RESTARTED: | |
3816 | case ATH11K_STATE_WEDGED: | |
3817 | case ATH11K_STATE_ON: | |
3818 | WARN_ON(1); | |
3819 | ret = -EINVAL; | |
3820 | goto err; | |
3821 | } | |
3822 | ||
3823 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, | |
3824 | 1, pdev->pdev_id); | |
3825 | ||
3826 | if (ret) { | |
3827 | ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret); | |
3828 | goto err; | |
3829 | } | |
3830 | ||
3831 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1, | |
3832 | pdev->pdev_id); | |
3833 | if (ret) { | |
3834 | ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret); | |
3835 | goto err; | |
3836 | } | |
3837 | ||
3838 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE, | |
3839 | 0, pdev->pdev_id); | |
3840 | if (ret) { | |
3841 | ath11k_err(ab, "failed to set ac override for ARP: %d\n", | |
3842 | ret); | |
3843 | goto err; | |
3844 | } | |
3845 | ||
3846 | ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id); | |
3847 | if (ret) { | |
3848 | ath11k_err(ab, "failed to offload radar detection: %d\n", | |
3849 | ret); | |
3850 | goto err; | |
3851 | } | |
3852 | ||
3853 | ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar, | |
3854 | HTT_PPDU_STATS_TAG_DEFAULT); | |
3855 | if (ret) { | |
3856 | ath11k_err(ab, "failed to req ppdu stats: %d\n", ret); | |
3857 | goto err; | |
3858 | } | |
3859 | ||
3860 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE, | |
3861 | 1, pdev->pdev_id); | |
3862 | ||
3863 | if (ret) { | |
3864 | ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret); | |
3865 | goto err; | |
3866 | } | |
3867 | ||
3868 | __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); | |
3869 | ||
3870 | /* TODO: Do we need to enable ANI? */ | |
3871 | ||
3872 | ath11k_reg_update_chan_list(ar); | |
3873 | ||
3874 | ar->num_started_vdevs = 0; | |
3875 | ar->num_created_vdevs = 0; | |
3876 | ar->num_peers = 0; | |
3877 | ||
3878 | /* Configure monitor status ring with default rx_filter to get rx status | |
3879 | * such as rssi, rx_duration. | |
3880 | */ | |
3881 | ret = ath11k_mac_config_mon_status_default(ar, true); | |
3882 | if (ret) { | |
3883 | ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n", | |
3884 | ret); | |
3885 | goto err; | |
3886 | } | |
3887 | ||
3888 | mutex_unlock(&ar->conf_mutex); | |
3889 | ||
3890 | rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], | |
3891 | &ab->pdevs[ar->pdev_idx]); | |
3892 | ||
3893 | return 0; | |
3894 | ||
3895 | err: | |
3896 | ar->state = ATH11K_STATE_OFF; | |
3897 | mutex_unlock(&ar->conf_mutex); | |
3898 | ||
3899 | return ret; | |
3900 | } | |
3901 | ||
3902 | static void ath11k_mac_op_stop(struct ieee80211_hw *hw) | |
3903 | { | |
3904 | struct ath11k *ar = hw->priv; | |
3905 | struct htt_ppdu_stats_info *ppdu_stats, *tmp; | |
3906 | int ret; | |
3907 | ||
3908 | ath11k_mac_drain_tx(ar); | |
3909 | ||
3910 | mutex_lock(&ar->conf_mutex); | |
3911 | ret = ath11k_mac_config_mon_status_default(ar, false); | |
3912 | if (ret) | |
3913 | ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n", | |
3914 | ret); | |
3915 | ||
3916 | clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags); | |
3917 | ar->state = ATH11K_STATE_OFF; | |
3918 | mutex_unlock(&ar->conf_mutex); | |
3919 | ||
3920 | cancel_delayed_work_sync(&ar->scan.timeout); | |
3921 | cancel_work_sync(&ar->regd_update_work); | |
3922 | ||
3923 | spin_lock_bh(&ar->data_lock); | |
3924 | list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) { | |
3925 | list_del(&ppdu_stats->list); | |
3926 | kfree(ppdu_stats); | |
3927 | } | |
3928 | spin_unlock_bh(&ar->data_lock); | |
3929 | ||
3930 | rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL); | |
3931 | ||
3932 | synchronize_rcu(); | |
3933 | ||
3934 | atomic_set(&ar->num_pending_mgmt_tx, 0); | |
3935 | } | |
3936 | ||
3937 | static void | |
3938 | ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif, | |
3939 | struct vdev_create_params *params) | |
3940 | { | |
3941 | struct ath11k *ar = arvif->ar; | |
3942 | struct ath11k_pdev *pdev = ar->pdev; | |
3943 | ||
3944 | params->if_id = arvif->vdev_id; | |
3945 | params->type = arvif->vdev_type; | |
3946 | params->subtype = arvif->vdev_subtype; | |
3947 | params->pdev_id = pdev->pdev_id; | |
3948 | ||
3949 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
3950 | params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; | |
3951 | params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; | |
3952 | } | |
3953 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
3954 | params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; | |
3955 | params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; | |
3956 | } | |
3957 | } | |
3958 | ||
3959 | static u32 | |
3960 | ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype) | |
3961 | { | |
3962 | struct ath11k_pdev_cap *pdev_cap = &pdev->cap; | |
3963 | struct ath11k_band_cap *cap_band = NULL; | |
3964 | u32 *hecap_phy_ptr = NULL; | |
3965 | u32 hemode = 0; | |
3966 | ||
3967 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) | |
3968 | cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; | |
3969 | else | |
3970 | cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; | |
3971 | ||
3972 | hecap_phy_ptr = &cap_band->he_cap_phy_info[0]; | |
3973 | ||
3974 | hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) | | |
fcaf49d0 JC |
3975 | FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) | |
3976 | FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr)); | |
d5c65159 KV |
3977 | |
3978 | /* TODO WDS and other modes */ | |
3979 | if (viftype == NL80211_IFTYPE_AP) { | |
3980 | hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER, | |
fcaf49d0 JC |
3981 | HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) | |
3982 | FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) | | |
3983 | FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE); | |
d5c65159 KV |
3984 | } else { |
3985 | hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE); | |
3986 | } | |
3987 | ||
3988 | return hemode; | |
3989 | } | |
3990 | ||
3991 | static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar, | |
3992 | struct ath11k_vif *arvif) | |
3993 | { | |
3994 | u32 param_id, param_value; | |
3995 | struct ath11k_base *ab = ar->ab; | |
3996 | int ret = 0; | |
3997 | ||
3998 | param_id = WMI_VDEV_PARAM_SET_HEMU_MODE; | |
3999 | param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type); | |
4000 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4001 | param_id, param_value); | |
4002 | if (ret) { | |
4003 | ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n", | |
4004 | arvif->vdev_id, ret, param_value); | |
4005 | return ret; | |
4006 | } | |
4007 | param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE; | |
4008 | param_value = | |
4009 | FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) | | |
4010 | FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE, | |
4011 | HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE); | |
4012 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4013 | param_id, param_value); | |
4014 | if (ret) { | |
4015 | ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n", | |
4016 | arvif->vdev_id, ret); | |
4017 | return ret; | |
4018 | } | |
4019 | return ret; | |
4020 | } | |
4021 | ||
4022 | static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw, | |
4023 | struct ieee80211_vif *vif) | |
4024 | { | |
4025 | struct ath11k *ar = hw->priv; | |
4026 | struct ath11k_base *ab = ar->ab; | |
4027 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
4028 | struct vdev_create_params vdev_param = {0}; | |
4029 | struct peer_create_params peer_param; | |
4030 | u32 param_id, param_value; | |
4031 | u16 nss; | |
4032 | int i; | |
4033 | int ret; | |
4034 | int bit; | |
4035 | ||
4036 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; | |
4037 | ||
4038 | mutex_lock(&ar->conf_mutex); | |
4039 | ||
4040 | if (vif->type == NL80211_IFTYPE_AP && | |
4041 | ar->num_peers > (ar->max_num_peers - 1)) { | |
4042 | ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n"); | |
4043 | ret = -ENOBUFS; | |
4044 | goto err; | |
4045 | } | |
4046 | ||
4047 | if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) { | |
4048 | ath11k_warn(ab, "failed to create vdev, reached max vdev limit %d\n", | |
4049 | TARGET_NUM_VDEVS); | |
4050 | ret = -EBUSY; | |
4051 | goto err; | |
4052 | } | |
4053 | ||
4054 | memset(arvif, 0, sizeof(*arvif)); | |
4055 | ||
4056 | arvif->ar = ar; | |
4057 | arvif->vif = vif; | |
4058 | ||
4059 | INIT_LIST_HEAD(&arvif->list); | |
4060 | ||
4061 | /* Should we initialize any worker to handle connection loss indication | |
4062 | * from firmware in sta mode? | |
4063 | */ | |
4064 | ||
4065 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { | |
4066 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; | |
4067 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, | |
4068 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); | |
4069 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, | |
4070 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); | |
4071 | } | |
4072 | ||
4073 | bit = __ffs64(ab->free_vdev_map); | |
4074 | ||
4075 | arvif->vdev_id = bit; | |
4076 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; | |
4077 | ||
4078 | switch (vif->type) { | |
4079 | case NL80211_IFTYPE_UNSPECIFIED: | |
4080 | case NL80211_IFTYPE_STATION: | |
4081 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
4082 | break; | |
4083 | case NL80211_IFTYPE_MESH_POINT: | |
4084 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S; | |
4085 | /* fall through */ | |
4086 | case NL80211_IFTYPE_AP: | |
4087 | arvif->vdev_type = WMI_VDEV_TYPE_AP; | |
4088 | break; | |
4089 | case NL80211_IFTYPE_MONITOR: | |
4090 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; | |
4091 | break; | |
4092 | default: | |
4093 | WARN_ON(1); | |
4094 | break; | |
4095 | } | |
4096 | ||
4097 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n", | |
4098 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, | |
4099 | ab->free_vdev_map); | |
4100 | ||
4101 | vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1); | |
4102 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) | |
4103 | vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1); | |
4104 | ||
4105 | ath11k_mac_setup_vdev_create_params(arvif, &vdev_param); | |
4106 | ||
4107 | ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param); | |
4108 | if (ret) { | |
4109 | ath11k_warn(ab, "failed to create WMI vdev %d: %d\n", | |
4110 | arvif->vdev_id, ret); | |
4111 | goto err; | |
4112 | } | |
4113 | ||
4114 | ar->num_created_vdevs++; | |
4115 | ||
4116 | ab->free_vdev_map &= ~(1LL << arvif->vdev_id); | |
4117 | spin_lock_bh(&ar->data_lock); | |
4118 | list_add(&arvif->list, &ar->arvifs); | |
4119 | spin_unlock_bh(&ar->data_lock); | |
4120 | ||
4121 | param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE; | |
4122 | param_value = ATH11K_HW_TXRX_NATIVE_WIFI; | |
4123 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4124 | param_id, param_value); | |
4125 | if (ret) { | |
4126 | ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n", | |
4127 | arvif->vdev_id, ret); | |
4128 | goto err_vdev_del; | |
4129 | } | |
4130 | ||
4131 | nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1; | |
4132 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4133 | WMI_VDEV_PARAM_NSS, nss); | |
4134 | if (ret) { | |
4135 | ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", | |
4136 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret); | |
4137 | goto err_vdev_del; | |
4138 | } | |
4139 | ||
4140 | switch (arvif->vdev_type) { | |
4141 | case WMI_VDEV_TYPE_AP: | |
4142 | peer_param.vdev_id = arvif->vdev_id; | |
4143 | peer_param.peer_addr = vif->addr; | |
4144 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
4145 | ret = ath11k_peer_create(ar, arvif, NULL, &peer_param); | |
4146 | if (ret) { | |
4147 | ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n", | |
4148 | arvif->vdev_id, ret); | |
4149 | goto err_vdev_del; | |
4150 | } | |
4151 | ||
4152 | ret = ath11k_mac_set_kickout(arvif); | |
4153 | if (ret) { | |
4154 | ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n", | |
4155 | arvif->vdev_id, ret); | |
4156 | goto err_peer_del; | |
4157 | } | |
4158 | break; | |
4159 | case WMI_VDEV_TYPE_STA: | |
4160 | param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY; | |
4161 | param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
4162 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4163 | param_id, param_value); | |
4164 | if (ret) { | |
4165 | ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n", | |
4166 | arvif->vdev_id, ret); | |
4167 | goto err_peer_del; | |
4168 | } | |
4169 | ||
4170 | param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; | |
4171 | param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; | |
4172 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4173 | param_id, param_value); | |
4174 | if (ret) { | |
4175 | ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n", | |
4176 | arvif->vdev_id, ret); | |
4177 | goto err_peer_del; | |
4178 | } | |
4179 | ||
4180 | param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT; | |
4181 | param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; | |
4182 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4183 | param_id, param_value); | |
4184 | if (ret) { | |
4185 | ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n", | |
4186 | arvif->vdev_id, ret); | |
4187 | goto err_peer_del; | |
4188 | } | |
6bfebd4b JC |
4189 | |
4190 | ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false); | |
4191 | if (ret) { | |
4192 | ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n", | |
4193 | arvif->vdev_id, ret); | |
4194 | goto err_peer_del; | |
4195 | } | |
d5c65159 KV |
4196 | break; |
4197 | default: | |
4198 | break; | |
4199 | } | |
4200 | ||
4201 | arvif->txpower = vif->bss_conf.txpower; | |
4202 | ret = ath11k_mac_txpower_recalc(ar); | |
4203 | if (ret) | |
4204 | goto err_peer_del; | |
4205 | ||
4206 | param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
4207 | param_value = ar->hw->wiphy->rts_threshold; | |
4208 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4209 | param_id, param_value); | |
4210 | if (ret) { | |
4211 | ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n", | |
4212 | arvif->vdev_id, ret); | |
4213 | } | |
4214 | ||
4215 | ret = ath11k_mac_set_txbf_conf(arvif); | |
4216 | if (ret) { | |
4217 | ath11k_warn(ar->ab, "failed to set txbf conf for vdev %d: %d\n", | |
4218 | arvif->vdev_id, ret); | |
4219 | } | |
4220 | ||
4221 | ath11k_dp_vdev_tx_attach(ar, arvif); | |
4222 | ||
4223 | mutex_unlock(&ar->conf_mutex); | |
4224 | ||
4225 | return 0; | |
4226 | ||
4227 | err_peer_del: | |
4228 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
4229 | ar->num_peers--; | |
4230 | ath11k_wmi_send_peer_delete_cmd(ar, vif->addr, arvif->vdev_id); | |
4231 | } | |
4232 | ||
4233 | err_vdev_del: | |
4234 | ath11k_wmi_vdev_delete(ar, arvif->vdev_id); | |
4235 | ar->num_created_vdevs--; | |
4236 | ab->free_vdev_map |= 1LL << arvif->vdev_id; | |
4237 | spin_lock_bh(&ar->data_lock); | |
4238 | list_del(&arvif->list); | |
4239 | spin_unlock_bh(&ar->data_lock); | |
4240 | ||
4241 | err: | |
4242 | mutex_unlock(&ar->conf_mutex); | |
4243 | ||
4244 | return ret; | |
4245 | } | |
4246 | ||
4247 | static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx) | |
4248 | { | |
4249 | struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx; | |
4250 | struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb); | |
4251 | ||
4252 | if (skb_cb->vif == vif) | |
4253 | skb_cb->vif = NULL; | |
4254 | ||
4255 | return 0; | |
4256 | } | |
4257 | ||
4258 | static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw, | |
4259 | struct ieee80211_vif *vif) | |
4260 | { | |
4261 | struct ath11k *ar = hw->priv; | |
4262 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
4263 | struct ath11k_base *ab = ar->ab; | |
4264 | int ret; | |
4265 | int i; | |
4266 | ||
4267 | mutex_lock(&ar->conf_mutex); | |
4268 | ||
4269 | ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n", | |
4270 | arvif->vdev_id); | |
4271 | ||
4272 | ab->free_vdev_map |= 1LL << (arvif->vdev_id); | |
4273 | spin_lock_bh(&ar->data_lock); | |
4274 | list_del(&arvif->list); | |
4275 | spin_unlock_bh(&ar->data_lock); | |
4276 | ||
4277 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
4278 | ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr); | |
4279 | if (ret) | |
4280 | ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n", | |
4281 | arvif->vdev_id, ret); | |
4282 | } | |
4283 | ||
4284 | ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id); | |
4285 | if (ret) | |
4286 | ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n", | |
4287 | arvif->vdev_id, ret); | |
4288 | ||
4289 | ar->num_created_vdevs--; | |
4290 | ||
4291 | ath11k_peer_cleanup(ar, arvif->vdev_id); | |
4292 | ||
4293 | idr_for_each(&ar->txmgmt_idr, | |
4294 | ath11k_mac_vif_txmgmt_idr_remove, vif); | |
4295 | ||
4296 | for (i = 0; i < DP_TCL_NUM_RING_MAX; i++) { | |
4297 | spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock); | |
4298 | idr_for_each(&ab->dp.tx_ring[i].txbuf_idr, | |
4299 | ath11k_mac_vif_unref, vif); | |
4300 | spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock); | |
4301 | } | |
4302 | ||
4303 | /* Recalc txpower for remaining vdev */ | |
4304 | ath11k_mac_txpower_recalc(ar); | |
4305 | clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
4306 | ||
4307 | /* TODO: recal traffic pause state based on the available vdevs */ | |
4308 | ||
4309 | mutex_unlock(&ar->conf_mutex); | |
4310 | } | |
4311 | ||
4312 | /* FIXME: Has to be verified. */ | |
4313 | #define SUPPORTED_FILTERS \ | |
4314 | (FIF_ALLMULTI | \ | |
4315 | FIF_CONTROL | \ | |
4316 | FIF_PSPOLL | \ | |
4317 | FIF_OTHER_BSS | \ | |
4318 | FIF_BCN_PRBRESP_PROMISC | \ | |
4319 | FIF_PROBE_REQ | \ | |
4320 | FIF_FCSFAIL) | |
4321 | ||
4322 | static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw, | |
4323 | unsigned int changed_flags, | |
4324 | unsigned int *total_flags, | |
4325 | u64 multicast) | |
4326 | { | |
4327 | struct ath11k *ar = hw->priv; | |
4328 | bool reset_flag = false; | |
4329 | int ret = 0; | |
4330 | ||
4331 | mutex_lock(&ar->conf_mutex); | |
4332 | ||
4333 | changed_flags &= SUPPORTED_FILTERS; | |
4334 | *total_flags &= SUPPORTED_FILTERS; | |
4335 | ar->filter_flags = *total_flags; | |
4336 | ||
4337 | /* For monitor mode */ | |
4338 | reset_flag = !(ar->filter_flags & FIF_BCN_PRBRESP_PROMISC); | |
4339 | ||
4340 | ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, reset_flag); | |
4341 | if (!ret) { | |
4342 | if (!reset_flag) | |
4343 | set_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
4344 | else | |
4345 | clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
4346 | } else { | |
4347 | ath11k_warn(ar->ab, | |
4348 | "fail to set monitor filter: %d\n", ret); | |
4349 | } | |
4350 | mutex_unlock(&ar->conf_mutex); | |
4351 | } | |
4352 | ||
4353 | static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) | |
4354 | { | |
4355 | struct ath11k *ar = hw->priv; | |
4356 | ||
4357 | mutex_lock(&ar->conf_mutex); | |
4358 | ||
4359 | *tx_ant = ar->cfg_tx_chainmask; | |
4360 | *rx_ant = ar->cfg_rx_chainmask; | |
4361 | ||
4362 | mutex_unlock(&ar->conf_mutex); | |
4363 | ||
4364 | return 0; | |
4365 | } | |
4366 | ||
4367 | static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) | |
4368 | { | |
4369 | struct ath11k *ar = hw->priv; | |
4370 | int ret; | |
4371 | ||
4372 | mutex_lock(&ar->conf_mutex); | |
4373 | ret = __ath11k_set_antenna(ar, tx_ant, rx_ant); | |
4374 | mutex_unlock(&ar->conf_mutex); | |
4375 | ||
4376 | return ret; | |
4377 | } | |
4378 | ||
4379 | static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw, | |
4380 | struct ieee80211_vif *vif, | |
4381 | struct ieee80211_ampdu_params *params) | |
4382 | { | |
4383 | struct ath11k *ar = hw->priv; | |
4384 | int ret = -EINVAL; | |
4385 | ||
4386 | mutex_lock(&ar->conf_mutex); | |
4387 | ||
4388 | switch (params->action) { | |
4389 | case IEEE80211_AMPDU_RX_START: | |
4390 | ret = ath11k_dp_rx_ampdu_start(ar, params); | |
4391 | break; | |
4392 | case IEEE80211_AMPDU_RX_STOP: | |
4393 | ret = ath11k_dp_rx_ampdu_stop(ar, params); | |
4394 | break; | |
4395 | case IEEE80211_AMPDU_TX_START: | |
4396 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
4397 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
4398 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
4399 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
4400 | /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211 | |
4401 | * Tx aggregation requests. | |
4402 | */ | |
4403 | ret = -EOPNOTSUPP; | |
4404 | break; | |
4405 | } | |
4406 | ||
4407 | mutex_unlock(&ar->conf_mutex); | |
4408 | ||
4409 | return ret; | |
4410 | } | |
4411 | ||
4412 | static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw, | |
4413 | struct ieee80211_chanctx_conf *ctx) | |
4414 | { | |
4415 | struct ath11k *ar = hw->priv; | |
4416 | struct ath11k_base *ab = ar->ab; | |
4417 | ||
4418 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4419 | "mac chanctx add freq %hu width %d ptr %pK\n", | |
4420 | ctx->def.chan->center_freq, ctx->def.width, ctx); | |
4421 | ||
4422 | mutex_lock(&ar->conf_mutex); | |
4423 | ||
4424 | spin_lock_bh(&ar->data_lock); | |
4425 | /* TODO: In case of multiple channel context, populate rx_channel from | |
4426 | * Rx PPDU desc information. | |
4427 | */ | |
4428 | ar->rx_channel = ctx->def.chan; | |
4429 | spin_unlock_bh(&ar->data_lock); | |
4430 | ||
4431 | mutex_unlock(&ar->conf_mutex); | |
4432 | ||
4433 | return 0; | |
4434 | } | |
4435 | ||
4436 | static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw, | |
4437 | struct ieee80211_chanctx_conf *ctx) | |
4438 | { | |
4439 | struct ath11k *ar = hw->priv; | |
4440 | struct ath11k_base *ab = ar->ab; | |
4441 | ||
4442 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4443 | "mac chanctx remove freq %hu width %d ptr %pK\n", | |
4444 | ctx->def.chan->center_freq, ctx->def.width, ctx); | |
4445 | ||
4446 | mutex_lock(&ar->conf_mutex); | |
4447 | ||
4448 | spin_lock_bh(&ar->data_lock); | |
4449 | /* TODO: In case of there is one more channel context left, populate | |
4450 | * rx_channel with the channel of that remaining channel context. | |
4451 | */ | |
4452 | ar->rx_channel = NULL; | |
4453 | spin_unlock_bh(&ar->data_lock); | |
4454 | ||
4455 | mutex_unlock(&ar->conf_mutex); | |
4456 | } | |
4457 | ||
4458 | static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar) | |
4459 | { | |
4460 | lockdep_assert_held(&ar->conf_mutex); | |
4461 | ||
4462 | if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
4463 | return -ESHUTDOWN; | |
4464 | ||
4465 | if (!wait_for_completion_timeout(&ar->vdev_setup_done, | |
4466 | ATH11K_VDEV_SETUP_TIMEOUT_HZ)) | |
4467 | return -ETIMEDOUT; | |
4468 | ||
4469 | return ar->last_wmi_vdev_start_status ? -EINVAL : 0; | |
4470 | } | |
4471 | ||
4472 | static int | |
4473 | ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif, | |
4474 | const struct cfg80211_chan_def *chandef, | |
4475 | bool restart) | |
4476 | { | |
4477 | struct ath11k *ar = arvif->ar; | |
4478 | struct ath11k_base *ab = ar->ab; | |
4479 | struct wmi_vdev_start_req_arg arg = {}; | |
4480 | int he_support = arvif->vif->bss_conf.he_support; | |
4481 | int ret = 0; | |
4482 | ||
4483 | lockdep_assert_held(&ar->conf_mutex); | |
4484 | ||
4485 | reinit_completion(&ar->vdev_setup_done); | |
4486 | ||
4487 | arg.vdev_id = arvif->vdev_id; | |
4488 | arg.dtim_period = arvif->dtim_period; | |
4489 | arg.bcn_intval = arvif->beacon_interval; | |
4490 | ||
4491 | arg.channel.freq = chandef->chan->center_freq; | |
4492 | arg.channel.band_center_freq1 = chandef->center_freq1; | |
4493 | arg.channel.band_center_freq2 = chandef->center_freq2; | |
4494 | arg.channel.mode = | |
4495 | ath11k_phymodes[chandef->chan->band][chandef->width]; | |
4496 | ||
4497 | arg.channel.min_power = 0; | |
4498 | arg.channel.max_power = chandef->chan->max_power * 2; | |
4499 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; | |
4500 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; | |
4501 | ||
4502 | arg.pref_tx_streams = ar->num_tx_chains; | |
4503 | arg.pref_rx_streams = ar->num_rx_chains; | |
4504 | ||
4505 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
4506 | arg.ssid = arvif->u.ap.ssid; | |
4507 | arg.ssid_len = arvif->u.ap.ssid_len; | |
4508 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; | |
4509 | ||
4510 | /* For now allow DFS for AP mode */ | |
4511 | arg.channel.chan_radar = | |
4512 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); | |
4513 | ||
4514 | arg.channel.passive = arg.channel.chan_radar; | |
4515 | ||
4516 | spin_lock_bh(&ab->base_lock); | |
4517 | arg.regdomain = ar->ab->dfs_region; | |
4518 | spin_unlock_bh(&ab->base_lock); | |
4519 | ||
4520 | /* TODO: Notify if secondary 80Mhz also needs radar detection */ | |
4521 | if (he_support) { | |
4522 | ret = ath11k_set_he_mu_sounding_mode(ar, arvif); | |
4523 | if (ret) { | |
4524 | ath11k_warn(ar->ab, "failed to set he mode vdev %i\n", | |
4525 | arg.vdev_id); | |
4526 | return ret; | |
4527 | } | |
4528 | } | |
4529 | } | |
4530 | ||
4531 | arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); | |
4532 | ||
4533 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4534 | "mac vdev %d start center_freq %d phymode %s\n", | |
4535 | arg.vdev_id, arg.channel.freq, | |
4536 | ath11k_wmi_phymode_str(arg.channel.mode)); | |
4537 | ||
4538 | ret = ath11k_wmi_vdev_start(ar, &arg, restart); | |
4539 | if (ret) { | |
4540 | ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n", | |
4541 | restart ? "restart" : "start", arg.vdev_id); | |
4542 | return ret; | |
4543 | } | |
4544 | ||
4545 | ret = ath11k_mac_vdev_setup_sync(ar); | |
4546 | if (ret) { | |
4547 | ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n", | |
4548 | arg.vdev_id, restart ? "restart" : "start", ret); | |
4549 | return ret; | |
4550 | } | |
4551 | ||
4552 | ar->num_started_vdevs++; | |
4553 | ||
4554 | /* Enable CAC Flag in the driver by checking the channel DFS cac time, | |
4555 | * i.e dfs_cac_ms value which will be valid only for radar channels | |
4556 | * and state as NL80211_DFS_USABLE which indicates CAC needs to be | |
4557 | * done before channel usage. This flags is used to drop rx packets. | |
4558 | * during CAC. | |
4559 | */ | |
4560 | /* TODO Set the flag for other interface types as required */ | |
4561 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP && | |
4562 | chandef->chan->dfs_cac_ms && | |
4563 | chandef->chan->dfs_state == NL80211_DFS_USABLE) { | |
4564 | set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags); | |
4565 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4566 | "CAC Started in chan_freq %d for vdev %d\n", | |
4567 | arg.channel.freq, arg.vdev_id); | |
4568 | } | |
4569 | ||
4570 | return 0; | |
4571 | } | |
4572 | ||
4573 | static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif) | |
4574 | { | |
4575 | struct ath11k *ar = arvif->ar; | |
4576 | int ret; | |
4577 | ||
4578 | lockdep_assert_held(&ar->conf_mutex); | |
4579 | ||
4580 | reinit_completion(&ar->vdev_setup_done); | |
4581 | ||
4582 | spin_lock_bh(&ar->data_lock); | |
4583 | ||
4584 | ar->vdev_stop_status.stop_in_progress = true; | |
4585 | ar->vdev_stop_status.vdev_id = arvif->vdev_id; | |
4586 | ||
4587 | spin_unlock_bh(&ar->data_lock); | |
4588 | ||
4589 | ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id); | |
4590 | if (ret) { | |
4591 | ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n", | |
4592 | arvif->vdev_id, ret); | |
4593 | goto err; | |
4594 | } | |
4595 | ||
4596 | ret = ath11k_mac_vdev_setup_sync(ar); | |
4597 | if (ret) { | |
4598 | ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n", | |
4599 | arvif->vdev_id, ret); | |
4600 | goto err; | |
4601 | } | |
4602 | ||
4603 | WARN_ON(ar->num_started_vdevs == 0); | |
4604 | ||
4605 | ar->num_started_vdevs--; | |
4606 | ||
4607 | if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) { | |
4608 | clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags); | |
4609 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n", | |
4610 | arvif->vdev_id); | |
4611 | } | |
4612 | ||
4613 | return 0; | |
4614 | err: | |
4615 | spin_lock_bh(&ar->data_lock); | |
4616 | ar->vdev_stop_status.stop_in_progress = false; | |
4617 | spin_unlock_bh(&ar->data_lock); | |
4618 | ||
4619 | return ret; | |
4620 | } | |
4621 | ||
4622 | static int ath11k_mac_vdev_start(struct ath11k_vif *arvif, | |
4623 | const struct cfg80211_chan_def *chandef) | |
4624 | { | |
4625 | return ath11k_mac_vdev_start_restart(arvif, chandef, false); | |
4626 | } | |
4627 | ||
4628 | static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif, | |
4629 | const struct cfg80211_chan_def *chandef) | |
4630 | { | |
4631 | return ath11k_mac_vdev_start_restart(arvif, chandef, true); | |
4632 | } | |
4633 | ||
4634 | struct ath11k_mac_change_chanctx_arg { | |
4635 | struct ieee80211_chanctx_conf *ctx; | |
4636 | struct ieee80211_vif_chanctx_switch *vifs; | |
4637 | int n_vifs; | |
4638 | int next_vif; | |
4639 | }; | |
4640 | ||
4641 | static void | |
4642 | ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, | |
4643 | struct ieee80211_vif *vif) | |
4644 | { | |
4645 | struct ath11k_mac_change_chanctx_arg *arg = data; | |
4646 | ||
4647 | if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx) | |
4648 | return; | |
4649 | ||
4650 | arg->n_vifs++; | |
4651 | } | |
4652 | ||
4653 | static void | |
4654 | ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac, | |
4655 | struct ieee80211_vif *vif) | |
4656 | { | |
4657 | struct ath11k_mac_change_chanctx_arg *arg = data; | |
4658 | struct ieee80211_chanctx_conf *ctx; | |
4659 | ||
4660 | ctx = rcu_access_pointer(vif->chanctx_conf); | |
4661 | if (ctx != arg->ctx) | |
4662 | return; | |
4663 | ||
4664 | if (WARN_ON(arg->next_vif == arg->n_vifs)) | |
4665 | return; | |
4666 | ||
4667 | arg->vifs[arg->next_vif].vif = vif; | |
4668 | arg->vifs[arg->next_vif].old_ctx = ctx; | |
4669 | arg->vifs[arg->next_vif].new_ctx = ctx; | |
4670 | arg->next_vif++; | |
4671 | } | |
4672 | ||
4673 | static void | |
4674 | ath11k_mac_update_vif_chan(struct ath11k *ar, | |
4675 | struct ieee80211_vif_chanctx_switch *vifs, | |
4676 | int n_vifs) | |
4677 | { | |
4678 | struct ath11k_base *ab = ar->ab; | |
4679 | struct ath11k_vif *arvif; | |
4680 | int ret; | |
4681 | int i; | |
4682 | ||
4683 | lockdep_assert_held(&ar->conf_mutex); | |
4684 | ||
4685 | for (i = 0; i < n_vifs; i++) { | |
4686 | arvif = (void *)vifs[i].vif->drv_priv; | |
4687 | ||
4688 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4689 | "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n", | |
4690 | arvif->vdev_id, | |
4691 | vifs[i].old_ctx->def.chan->center_freq, | |
4692 | vifs[i].new_ctx->def.chan->center_freq, | |
4693 | vifs[i].old_ctx->def.width, | |
4694 | vifs[i].new_ctx->def.width); | |
4695 | ||
4696 | if (WARN_ON(!arvif->is_started)) | |
4697 | continue; | |
4698 | ||
4699 | if (WARN_ON(!arvif->is_up)) | |
4700 | continue; | |
4701 | ||
4702 | ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id); | |
4703 | if (ret) { | |
4704 | ath11k_warn(ab, "failed to down vdev %d: %d\n", | |
4705 | arvif->vdev_id, ret); | |
4706 | continue; | |
4707 | } | |
4708 | } | |
4709 | ||
4710 | /* All relevant vdevs are downed and associated channel resources | |
4711 | * should be available for the channel switch now. | |
4712 | */ | |
4713 | ||
4714 | /* TODO: Update ar->rx_channel */ | |
4715 | ||
4716 | for (i = 0; i < n_vifs; i++) { | |
4717 | arvif = (void *)vifs[i].vif->drv_priv; | |
4718 | ||
4719 | if (WARN_ON(!arvif->is_started)) | |
4720 | continue; | |
4721 | ||
4722 | if (WARN_ON(!arvif->is_up)) | |
4723 | continue; | |
4724 | ||
4725 | ret = ath11k_mac_setup_bcn_tmpl(arvif); | |
4726 | if (ret) | |
4727 | ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n", | |
4728 | ret); | |
4729 | ||
4730 | ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def); | |
4731 | if (ret) { | |
4732 | ath11k_warn(ab, "failed to restart vdev %d: %d\n", | |
4733 | arvif->vdev_id, ret); | |
4734 | continue; | |
4735 | } | |
4736 | ||
4737 | ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
4738 | arvif->bssid); | |
4739 | if (ret) { | |
4740 | ath11k_warn(ab, "failed to bring vdev up %d: %d\n", | |
4741 | arvif->vdev_id, ret); | |
4742 | continue; | |
4743 | } | |
4744 | } | |
4745 | } | |
4746 | ||
4747 | static void | |
4748 | ath11k_mac_update_active_vif_chan(struct ath11k *ar, | |
4749 | struct ieee80211_chanctx_conf *ctx) | |
4750 | { | |
4751 | struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx }; | |
4752 | ||
4753 | lockdep_assert_held(&ar->conf_mutex); | |
4754 | ||
4755 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
4756 | IEEE80211_IFACE_ITER_NORMAL, | |
4757 | ath11k_mac_change_chanctx_cnt_iter, | |
4758 | &arg); | |
4759 | if (arg.n_vifs == 0) | |
4760 | return; | |
4761 | ||
4762 | arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL); | |
4763 | if (!arg.vifs) | |
4764 | return; | |
4765 | ||
4766 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
4767 | IEEE80211_IFACE_ITER_NORMAL, | |
4768 | ath11k_mac_change_chanctx_fill_iter, | |
4769 | &arg); | |
4770 | ||
4771 | ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); | |
4772 | ||
4773 | kfree(arg.vifs); | |
4774 | } | |
4775 | ||
4776 | static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw, | |
4777 | struct ieee80211_chanctx_conf *ctx, | |
4778 | u32 changed) | |
4779 | { | |
4780 | struct ath11k *ar = hw->priv; | |
4781 | struct ath11k_base *ab = ar->ab; | |
4782 | ||
4783 | mutex_lock(&ar->conf_mutex); | |
4784 | ||
4785 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4786 | "mac chanctx change freq %hu width %d ptr %pK changed %x\n", | |
4787 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); | |
4788 | ||
4789 | /* This shouldn't really happen because channel switching should use | |
4790 | * switch_vif_chanctx(). | |
4791 | */ | |
4792 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) | |
4793 | goto unlock; | |
4794 | ||
4795 | if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) | |
4796 | ath11k_mac_update_active_vif_chan(ar, ctx); | |
4797 | ||
4798 | /* TODO: Recalc radar detection */ | |
4799 | ||
4800 | unlock: | |
4801 | mutex_unlock(&ar->conf_mutex); | |
4802 | } | |
4803 | ||
4804 | static int | |
4805 | ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, | |
4806 | struct ieee80211_vif *vif, | |
4807 | struct ieee80211_chanctx_conf *ctx) | |
4808 | { | |
4809 | struct ath11k *ar = hw->priv; | |
4810 | struct ath11k_base *ab = ar->ab; | |
4811 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
4812 | int ret; | |
4813 | ||
4814 | mutex_lock(&ar->conf_mutex); | |
4815 | ||
4816 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4817 | "mac chanctx assign ptr %pK vdev_id %i\n", | |
4818 | ctx, arvif->vdev_id); | |
4819 | ||
4820 | if (WARN_ON(arvif->is_started)) { | |
4821 | mutex_unlock(&ar->conf_mutex); | |
4822 | return -EBUSY; | |
4823 | } | |
4824 | ||
4825 | ret = ath11k_mac_vdev_start(arvif, &ctx->def); | |
4826 | if (ret) { | |
4827 | ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
4828 | arvif->vdev_id, vif->addr, | |
4829 | ctx->def.chan->center_freq, ret); | |
4830 | goto err; | |
4831 | } | |
4832 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { | |
4833 | ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id); | |
4834 | if (ret) | |
4835 | goto err; | |
4836 | } | |
4837 | ||
4838 | arvif->is_started = true; | |
4839 | ||
4840 | /* TODO: Setup ps and cts/rts protection */ | |
4841 | ||
4842 | mutex_unlock(&ar->conf_mutex); | |
4843 | ||
4844 | return 0; | |
4845 | ||
4846 | err: | |
4847 | mutex_unlock(&ar->conf_mutex); | |
4848 | ||
4849 | return ret; | |
4850 | } | |
4851 | ||
4852 | static void | |
4853 | ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
4854 | struct ieee80211_vif *vif, | |
4855 | struct ieee80211_chanctx_conf *ctx) | |
4856 | { | |
4857 | struct ath11k *ar = hw->priv; | |
4858 | struct ath11k_base *ab = ar->ab; | |
4859 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
4860 | int ret; | |
4861 | ||
4862 | mutex_lock(&ar->conf_mutex); | |
4863 | ||
4864 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4865 | "mac chanctx unassign ptr %pK vdev_id %i\n", | |
4866 | ctx, arvif->vdev_id); | |
4867 | ||
4868 | WARN_ON(!arvif->is_started); | |
4869 | ||
4870 | ret = ath11k_mac_vdev_stop(arvif); | |
4871 | if (ret) | |
4872 | ath11k_warn(ab, "failed to stop vdev %i: %d\n", | |
4873 | arvif->vdev_id, ret); | |
4874 | ||
4875 | arvif->is_started = false; | |
4876 | ||
4877 | mutex_unlock(&ar->conf_mutex); | |
4878 | } | |
4879 | ||
4880 | static int | |
4881 | ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, | |
4882 | struct ieee80211_vif_chanctx_switch *vifs, | |
4883 | int n_vifs, | |
4884 | enum ieee80211_chanctx_switch_mode mode) | |
4885 | { | |
4886 | struct ath11k *ar = hw->priv; | |
4887 | ||
4888 | mutex_lock(&ar->conf_mutex); | |
4889 | ||
4890 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
4891 | "mac chanctx switch n_vifs %d mode %d\n", | |
4892 | n_vifs, mode); | |
4893 | ath11k_mac_update_vif_chan(ar, vifs, n_vifs); | |
4894 | ||
4895 | mutex_unlock(&ar->conf_mutex); | |
4896 | ||
4897 | return 0; | |
4898 | } | |
4899 | ||
4900 | static int | |
4901 | ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value) | |
4902 | { | |
4903 | struct ath11k_vif *arvif; | |
4904 | int ret = 0; | |
4905 | ||
4906 | mutex_lock(&ar->conf_mutex); | |
4907 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
4908 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n", | |
4909 | param, arvif->vdev_id, value); | |
4910 | ||
4911 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4912 | param, value); | |
4913 | if (ret) { | |
4914 | ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n", | |
4915 | param, arvif->vdev_id, ret); | |
4916 | break; | |
4917 | } | |
4918 | } | |
4919 | mutex_unlock(&ar->conf_mutex); | |
4920 | return ret; | |
4921 | } | |
4922 | ||
4923 | /* mac80211 stores device specific RTS/Fragmentation threshold value, | |
4924 | * this is set interface specific to firmware from ath11k driver | |
4925 | */ | |
4926 | static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
4927 | { | |
4928 | struct ath11k *ar = hw->priv; | |
4929 | int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
4930 | ||
4931 | return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value); | |
4932 | } | |
4933 | ||
4934 | static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) | |
4935 | { | |
4936 | /* Even though there's a WMI vdev param for fragmentation threshold no | |
4937 | * known firmware actually implements it. Moreover it is not possible to | |
4938 | * rely frame fragmentation to mac80211 because firmware clears the | |
4939 | * "more fragments" bit in frame control making it impossible for remote | |
4940 | * devices to reassemble frames. | |
4941 | * | |
4942 | * Hence implement a dummy callback just to say fragmentation isn't | |
4943 | * supported. This effectively prevents mac80211 from doing frame | |
4944 | * fragmentation in software. | |
4945 | */ | |
4946 | return -EOPNOTSUPP; | |
4947 | } | |
4948 | ||
4949 | static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |
4950 | u32 queues, bool drop) | |
4951 | { | |
4952 | struct ath11k *ar = hw->priv; | |
4953 | long time_left; | |
4954 | ||
4955 | if (drop) | |
4956 | return; | |
4957 | ||
4958 | time_left = wait_event_timeout(ar->dp.tx_empty_waitq, | |
4959 | (atomic_read(&ar->dp.num_tx_pending) == 0), | |
4960 | ATH11K_FLUSH_TIMEOUT); | |
4961 | if (time_left == 0) | |
4962 | ath11k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left); | |
4963 | } | |
4964 | ||
4965 | static int | |
4966 | ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar, | |
4967 | enum nl80211_band band, | |
4968 | const struct cfg80211_bitrate_mask *mask) | |
4969 | { | |
4970 | int num_rates = 0; | |
4971 | int i; | |
4972 | ||
4973 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) | |
4974 | num_rates += hweight16(mask->control[band].ht_mcs[i]); | |
4975 | ||
4976 | return num_rates; | |
4977 | } | |
4978 | ||
4979 | static bool | |
4980 | ath11k_mac_has_single_legacy_rate(struct ath11k *ar, | |
4981 | enum nl80211_band band, | |
4982 | const struct cfg80211_bitrate_mask *mask) | |
4983 | { | |
4984 | int num_rates = 0; | |
4985 | ||
4986 | num_rates = hweight32(mask->control[band].legacy); | |
4987 | ||
4988 | if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask)) | |
4989 | return false; | |
4990 | ||
4991 | if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask)) | |
4992 | return false; | |
4993 | ||
4994 | return num_rates == 1; | |
4995 | } | |
4996 | ||
4997 | static bool | |
4998 | ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar, | |
4999 | enum nl80211_band band, | |
5000 | const struct cfg80211_bitrate_mask *mask, | |
5001 | int *nss) | |
5002 | { | |
5003 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; | |
5004 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
5005 | u8 ht_nss_mask = 0; | |
5006 | u8 vht_nss_mask = 0; | |
5007 | int i; | |
5008 | ||
5009 | /* No need to consider legacy here. Basic rates are always present | |
5010 | * in bitrate mask | |
5011 | */ | |
5012 | ||
5013 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { | |
5014 | if (mask->control[band].ht_mcs[i] == 0) | |
5015 | continue; | |
5016 | else if (mask->control[band].ht_mcs[i] == | |
5017 | sband->ht_cap.mcs.rx_mask[i]) | |
5018 | ht_nss_mask |= BIT(i); | |
5019 | else | |
5020 | return false; | |
5021 | } | |
5022 | ||
5023 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
5024 | if (mask->control[band].vht_mcs[i] == 0) | |
5025 | continue; | |
5026 | else if (mask->control[band].vht_mcs[i] == | |
5027 | ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) | |
5028 | vht_nss_mask |= BIT(i); | |
5029 | else | |
5030 | return false; | |
5031 | } | |
5032 | ||
5033 | if (ht_nss_mask != vht_nss_mask) | |
5034 | return false; | |
5035 | ||
5036 | if (ht_nss_mask == 0) | |
5037 | return false; | |
5038 | ||
5039 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) | |
5040 | return false; | |
5041 | ||
5042 | *nss = fls(ht_nss_mask); | |
5043 | ||
5044 | return true; | |
5045 | } | |
5046 | ||
5047 | static int | |
5048 | ath11k_mac_get_single_legacy_rate(struct ath11k *ar, | |
5049 | enum nl80211_band band, | |
5050 | const struct cfg80211_bitrate_mask *mask, | |
5051 | u32 *rate, u8 *nss) | |
5052 | { | |
5053 | int rate_idx; | |
5054 | u16 bitrate; | |
5055 | u8 preamble; | |
5056 | u8 hw_rate; | |
5057 | ||
5058 | if (hweight32(mask->control[band].legacy) != 1) | |
5059 | return -EINVAL; | |
5060 | ||
5061 | rate_idx = ffs(mask->control[band].legacy) - 1; | |
5062 | ||
5063 | if (band == NL80211_BAND_5GHZ) | |
5064 | rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
5065 | ||
5066 | hw_rate = ath11k_legacy_rates[rate_idx].hw_value; | |
5067 | bitrate = ath11k_legacy_rates[rate_idx].bitrate; | |
5068 | ||
5069 | if (ath11k_mac_bitrate_is_cck(bitrate)) | |
5070 | preamble = WMI_RATE_PREAMBLE_CCK; | |
5071 | else | |
5072 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
5073 | ||
5074 | *nss = 1; | |
5075 | *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble); | |
5076 | ||
5077 | return 0; | |
5078 | } | |
5079 | ||
5080 | static int ath11k_mac_set_fixed_rate_params(struct ath11k_vif *arvif, | |
5081 | u32 rate, u8 nss, u8 sgi, u8 ldpc) | |
5082 | { | |
5083 | struct ath11k *ar = arvif->ar; | |
5084 | u32 vdev_param; | |
5085 | int ret; | |
5086 | ||
5087 | lockdep_assert_held(&ar->conf_mutex); | |
5088 | ||
5089 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n", | |
5090 | arvif->vdev_id, rate, nss, sgi); | |
5091 | ||
5092 | vdev_param = WMI_VDEV_PARAM_FIXED_RATE; | |
5093 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5094 | vdev_param, rate); | |
5095 | if (ret) { | |
5096 | ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n", | |
5097 | rate, ret); | |
5098 | return ret; | |
5099 | } | |
5100 | ||
5101 | vdev_param = WMI_VDEV_PARAM_NSS; | |
5102 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5103 | vdev_param, nss); | |
5104 | if (ret) { | |
5105 | ath11k_warn(ar->ab, "failed to set nss param %d: %d\n", | |
5106 | nss, ret); | |
5107 | return ret; | |
5108 | } | |
5109 | ||
5110 | vdev_param = WMI_VDEV_PARAM_SGI; | |
5111 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5112 | vdev_param, sgi); | |
5113 | if (ret) { | |
5114 | ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n", | |
5115 | sgi, ret); | |
5116 | return ret; | |
5117 | } | |
5118 | ||
5119 | vdev_param = WMI_VDEV_PARAM_LDPC; | |
5120 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5121 | vdev_param, ldpc); | |
5122 | if (ret) { | |
5123 | ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n", | |
5124 | ldpc, ret); | |
5125 | return ret; | |
5126 | } | |
5127 | ||
5128 | return 0; | |
5129 | } | |
5130 | ||
5131 | static bool | |
5132 | ath11k_mac_vht_mcs_range_present(struct ath11k *ar, | |
5133 | enum nl80211_band band, | |
5134 | const struct cfg80211_bitrate_mask *mask) | |
5135 | { | |
5136 | int i; | |
5137 | u16 vht_mcs; | |
5138 | ||
5139 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
5140 | vht_mcs = mask->control[band].vht_mcs[i]; | |
5141 | ||
5142 | switch (vht_mcs) { | |
5143 | case 0: | |
5144 | case BIT(8) - 1: | |
5145 | case BIT(9) - 1: | |
5146 | case BIT(10) - 1: | |
5147 | break; | |
5148 | default: | |
5149 | return false; | |
5150 | } | |
5151 | } | |
5152 | ||
5153 | return true; | |
5154 | } | |
5155 | ||
5156 | static void ath11k_mac_set_bitrate_mask_iter(void *data, | |
5157 | struct ieee80211_sta *sta) | |
5158 | { | |
5159 | struct ath11k_vif *arvif = data; | |
5160 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
5161 | struct ath11k *ar = arvif->ar; | |
5162 | ||
5163 | spin_lock_bh(&ar->data_lock); | |
5164 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; | |
5165 | spin_unlock_bh(&ar->data_lock); | |
5166 | ||
5167 | ieee80211_queue_work(ar->hw, &arsta->update_wk); | |
5168 | } | |
5169 | ||
5170 | static void ath11k_mac_disable_peer_fixed_rate(void *data, | |
5171 | struct ieee80211_sta *sta) | |
5172 | { | |
5173 | struct ath11k_vif *arvif = data; | |
5174 | struct ath11k *ar = arvif->ar; | |
5175 | int ret; | |
5176 | ||
5177 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, | |
5178 | arvif->vdev_id, | |
5179 | WMI_PEER_PARAM_FIXED_RATE, | |
5180 | WMI_FIXED_RATE_NONE); | |
5181 | if (ret) | |
5182 | ath11k_warn(ar->ab, | |
5183 | "failed to disable peer fixed rate for STA %pM ret %d\n", | |
5184 | sta->addr, ret); | |
5185 | } | |
5186 | ||
5187 | static int | |
5188 | ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, | |
5189 | struct ieee80211_vif *vif, | |
5190 | const struct cfg80211_bitrate_mask *mask) | |
5191 | { | |
5192 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
5193 | struct cfg80211_chan_def def; | |
5194 | struct ath11k *ar = arvif->ar; | |
5195 | enum nl80211_band band; | |
5196 | const u8 *ht_mcs_mask; | |
5197 | const u16 *vht_mcs_mask; | |
5198 | u32 rate; | |
5199 | u8 nss; | |
5200 | u8 sgi; | |
5201 | u8 ldpc; | |
5202 | int single_nss; | |
5203 | int ret; | |
5204 | int num_rates; | |
5205 | ||
5206 | if (ath11k_mac_vif_chan(vif, &def)) | |
5207 | return -EPERM; | |
5208 | ||
5209 | band = def.chan->band; | |
5210 | ht_mcs_mask = mask->control[band].ht_mcs; | |
5211 | vht_mcs_mask = mask->control[band].vht_mcs; | |
5212 | ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); | |
5213 | ||
5214 | sgi = mask->control[band].gi; | |
5215 | if (sgi == NL80211_TXRATE_FORCE_LGI) | |
5216 | return -EINVAL; | |
5217 | ||
5218 | /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it | |
5219 | * requires passing atleast one of used basic rates along with them. | |
5220 | * Fixed rate setting across different preambles(legacy, HT, VHT) is | |
5221 | * not supported by the FW. Hence use of FIXED_RATE vdev param is not | |
5222 | * suitable for setting single HT/VHT rates. | |
5223 | * But, there could be a single basic rate passed from userspace which | |
5224 | * can be done through the FIXED_RATE param. | |
5225 | */ | |
5226 | if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) { | |
5227 | ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate, | |
5228 | &nss); | |
5229 | if (ret) { | |
5230 | ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n", | |
5231 | arvif->vdev_id, ret); | |
5232 | return ret; | |
5233 | } | |
5234 | ieee80211_iterate_stations_atomic(ar->hw, | |
5235 | ath11k_mac_disable_peer_fixed_rate, | |
5236 | arvif); | |
5237 | } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask, | |
5238 | &single_nss)) { | |
5239 | rate = WMI_FIXED_RATE_NONE; | |
5240 | nss = single_nss; | |
5241 | } else { | |
5242 | rate = WMI_FIXED_RATE_NONE; | |
5243 | nss = min_t(u32, ar->num_tx_chains, | |
5244 | max(ath11k_mac_max_ht_nss(ht_mcs_mask), | |
5245 | ath11k_mac_max_vht_nss(vht_mcs_mask))); | |
5246 | ||
5247 | /* If multiple rates across different preambles are given | |
5248 | * we can reconfigure this info with all peers using PEER_ASSOC | |
5249 | * command with the below exception cases. | |
5250 | * - Single VHT Rate : peer_assoc command accommodates only MCS | |
5251 | * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211 | |
5252 | * mandates passing basic rates along with HT/VHT rates, FW | |
5253 | * doesn't allow switching from VHT to Legacy. Hence instead of | |
5254 | * setting legacy and VHT rates using RATEMASK_CMD vdev cmd, | |
5255 | * we could set this VHT rate as peer fixed rate param, which | |
5256 | * will override FIXED rate and FW rate control algorithm. | |
5257 | * If single VHT rate is passed along with HT rates, we select | |
5258 | * the VHT rate as fixed rate for vht peers. | |
5259 | * - Multiple VHT Rates : When Multiple VHT rates are given,this | |
5260 | * can be set using RATEMASK CMD which uses FW rate-ctl alg. | |
5261 | * TODO: Setting multiple VHT MCS and replacing peer_assoc with | |
5262 | * RATEMASK_CMDID can cover all use cases of setting rates | |
5263 | * across multiple preambles and rates within same type. | |
5264 | * But requires more validation of the command at this point. | |
5265 | */ | |
5266 | ||
5267 | num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, | |
5268 | mask); | |
5269 | ||
5270 | if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) && | |
5271 | num_rates > 1) { | |
5272 | /* TODO: Handle multiple VHT MCS values setting using | |
5273 | * RATEMASK CMD | |
5274 | */ | |
5275 | ath11k_warn(ar->ab, | |
5276 | "Setting more than one MCS Value in bitrate mask not supported\n"); | |
5277 | return -EINVAL; | |
5278 | } | |
5279 | ||
5280 | ieee80211_iterate_stations_atomic(ar->hw, | |
5281 | ath11k_mac_disable_peer_fixed_rate, | |
5282 | arvif); | |
5283 | ||
5284 | mutex_lock(&ar->conf_mutex); | |
5285 | ||
5286 | arvif->bitrate_mask = *mask; | |
5287 | ieee80211_iterate_stations_atomic(ar->hw, | |
5288 | ath11k_mac_set_bitrate_mask_iter, | |
5289 | arvif); | |
5290 | ||
5291 | mutex_unlock(&ar->conf_mutex); | |
5292 | } | |
5293 | ||
5294 | mutex_lock(&ar->conf_mutex); | |
5295 | ||
5296 | ret = ath11k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); | |
5297 | if (ret) { | |
5298 | ath11k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n", | |
5299 | arvif->vdev_id, ret); | |
5300 | } | |
5301 | ||
5302 | mutex_unlock(&ar->conf_mutex); | |
5303 | ||
5304 | return ret; | |
5305 | } | |
5306 | ||
5307 | static void | |
5308 | ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw, | |
5309 | enum ieee80211_reconfig_type reconfig_type) | |
5310 | { | |
5311 | struct ath11k *ar = hw->priv; | |
5312 | ||
5313 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) | |
5314 | return; | |
5315 | ||
5316 | mutex_lock(&ar->conf_mutex); | |
5317 | ||
5318 | if (ar->state == ATH11K_STATE_RESTARTED) { | |
5319 | ath11k_warn(ar->ab, "pdev %d successfully recovered\n", | |
5320 | ar->pdev->pdev_id); | |
5321 | ar->state = ATH11K_STATE_ON; | |
5322 | ieee80211_wake_queues(ar->hw); | |
5323 | } | |
5324 | ||
5325 | mutex_unlock(&ar->conf_mutex); | |
5326 | } | |
5327 | ||
5328 | static void | |
5329 | ath11k_mac_update_bss_chan_survey(struct ath11k *ar, | |
5330 | struct ieee80211_channel *channel) | |
5331 | { | |
5332 | int ret; | |
5333 | enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; | |
5334 | ||
5335 | lockdep_assert_held(&ar->conf_mutex); | |
5336 | ||
6bc9d6f7 | 5337 | if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) || |
d5c65159 KV |
5338 | ar->rx_channel != channel) |
5339 | return; | |
5340 | ||
5341 | if (ar->scan.state != ATH11K_SCAN_IDLE) { | |
5342 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
5343 | "ignoring bss chan info req while scanning..\n"); | |
5344 | return; | |
5345 | } | |
5346 | ||
5347 | reinit_completion(&ar->bss_survey_done); | |
5348 | ||
5349 | ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type); | |
5350 | if (ret) { | |
5351 | ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n"); | |
5352 | return; | |
5353 | } | |
5354 | ||
5355 | ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); | |
5356 | if (ret == 0) | |
5357 | ath11k_warn(ar->ab, "bss channel survey timed out\n"); | |
5358 | } | |
5359 | ||
5360 | static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx, | |
5361 | struct survey_info *survey) | |
5362 | { | |
5363 | struct ath11k *ar = hw->priv; | |
5364 | struct ieee80211_supported_band *sband; | |
5365 | struct survey_info *ar_survey; | |
5366 | int ret = 0; | |
5367 | ||
5368 | if (idx >= ATH11K_NUM_CHANS) | |
5369 | return -ENOENT; | |
5370 | ||
5371 | ar_survey = &ar->survey[idx]; | |
5372 | ||
5373 | mutex_lock(&ar->conf_mutex); | |
5374 | ||
5375 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; | |
5376 | if (sband && idx >= sband->n_channels) { | |
5377 | idx -= sband->n_channels; | |
5378 | sband = NULL; | |
5379 | } | |
5380 | ||
5381 | if (!sband) | |
5382 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; | |
5383 | ||
5384 | if (!sband || idx >= sband->n_channels) { | |
5385 | ret = -ENOENT; | |
5386 | goto exit; | |
5387 | } | |
5388 | ||
5389 | ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); | |
5390 | ||
5391 | spin_lock_bh(&ar->data_lock); | |
5392 | memcpy(survey, ar_survey, sizeof(*survey)); | |
5393 | spin_unlock_bh(&ar->data_lock); | |
5394 | ||
5395 | survey->channel = &sband->channels[idx]; | |
5396 | ||
5397 | if (ar->rx_channel == survey->channel) | |
5398 | survey->filled |= SURVEY_INFO_IN_USE; | |
5399 | ||
5400 | exit: | |
5401 | mutex_unlock(&ar->conf_mutex); | |
5402 | return ret; | |
5403 | } | |
5404 | ||
5405 | static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw, | |
5406 | struct ieee80211_vif *vif, | |
5407 | struct ieee80211_sta *sta, | |
5408 | struct station_info *sinfo) | |
5409 | { | |
5410 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
5411 | ||
5412 | sinfo->rx_duration = arsta->rx_duration; | |
5413 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); | |
5414 | ||
a9e945ea VN |
5415 | sinfo->tx_duration = arsta->tx_duration; |
5416 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); | |
5417 | ||
d5c65159 KV |
5418 | if (!arsta->txrate.legacy && !arsta->txrate.nss) |
5419 | return; | |
5420 | ||
5421 | if (arsta->txrate.legacy) { | |
5422 | sinfo->txrate.legacy = arsta->txrate.legacy; | |
5423 | } else { | |
5424 | sinfo->txrate.mcs = arsta->txrate.mcs; | |
5425 | sinfo->txrate.nss = arsta->txrate.nss; | |
5426 | sinfo->txrate.bw = arsta->txrate.bw; | |
5427 | sinfo->txrate.he_gi = arsta->txrate.he_gi; | |
5428 | sinfo->txrate.he_dcm = arsta->txrate.he_dcm; | |
5429 | sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc; | |
5430 | } | |
5431 | sinfo->txrate.flags = arsta->txrate.flags; | |
5432 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); | |
5433 | ||
5434 | /* TODO: Use real NF instead of default one. */ | |
5435 | sinfo->signal = arsta->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR; | |
5436 | } | |
5437 | ||
5438 | static const struct ieee80211_ops ath11k_ops = { | |
5439 | .tx = ath11k_mac_op_tx, | |
5440 | .start = ath11k_mac_op_start, | |
5441 | .stop = ath11k_mac_op_stop, | |
5442 | .reconfig_complete = ath11k_mac_op_reconfig_complete, | |
5443 | .add_interface = ath11k_mac_op_add_interface, | |
5444 | .remove_interface = ath11k_mac_op_remove_interface, | |
5445 | .config = ath11k_mac_op_config, | |
5446 | .bss_info_changed = ath11k_mac_op_bss_info_changed, | |
5447 | .configure_filter = ath11k_mac_op_configure_filter, | |
5448 | .hw_scan = ath11k_mac_op_hw_scan, | |
5449 | .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan, | |
5450 | .set_key = ath11k_mac_op_set_key, | |
5451 | .sta_state = ath11k_mac_op_sta_state, | |
64f1d7e9 | 5452 | .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr, |
d5c65159 KV |
5453 | .sta_rc_update = ath11k_mac_op_sta_rc_update, |
5454 | .conf_tx = ath11k_mac_op_conf_tx, | |
5455 | .set_antenna = ath11k_mac_op_set_antenna, | |
5456 | .get_antenna = ath11k_mac_op_get_antenna, | |
5457 | .ampdu_action = ath11k_mac_op_ampdu_action, | |
5458 | .add_chanctx = ath11k_mac_op_add_chanctx, | |
5459 | .remove_chanctx = ath11k_mac_op_remove_chanctx, | |
5460 | .change_chanctx = ath11k_mac_op_change_chanctx, | |
5461 | .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx, | |
5462 | .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx, | |
5463 | .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx, | |
5464 | .set_rts_threshold = ath11k_mac_op_set_rts_threshold, | |
5465 | .set_frag_threshold = ath11k_mac_op_set_frag_threshold, | |
5466 | .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask, | |
5467 | .get_survey = ath11k_mac_op_get_survey, | |
5468 | .flush = ath11k_mac_op_flush, | |
5469 | .sta_statistics = ath11k_mac_op_sta_statistics, | |
5470 | CFG80211_TESTMODE_CMD(ath11k_tm_cmd) | |
5471 | #ifdef CONFIG_MAC80211_DEBUGFS | |
5472 | .sta_add_debugfs = ath11k_sta_add_debugfs, | |
5473 | #endif | |
5474 | }; | |
5475 | ||
5476 | static const struct ieee80211_iface_limit ath11k_if_limits[] = { | |
5477 | { | |
5478 | .max = 1, | |
5479 | .types = BIT(NL80211_IFTYPE_STATION), | |
5480 | }, | |
5481 | { | |
5482 | .max = 16, | |
5483 | .types = BIT(NL80211_IFTYPE_AP) | |
5484 | #ifdef CONFIG_MAC80211_MESH | |
5485 | | BIT(NL80211_IFTYPE_MESH_POINT) | |
5486 | #endif | |
5487 | }, | |
5488 | }; | |
5489 | ||
5490 | static const struct ieee80211_iface_combination ath11k_if_comb[] = { | |
5491 | { | |
5492 | .limits = ath11k_if_limits, | |
5493 | .n_limits = ARRAY_SIZE(ath11k_if_limits), | |
5494 | .max_interfaces = 16, | |
5495 | .num_different_channels = 1, | |
5496 | .beacon_int_infra_match = true, | |
5497 | .beacon_int_min_gcd = 100, | |
5498 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
5499 | BIT(NL80211_CHAN_WIDTH_20) | | |
5500 | BIT(NL80211_CHAN_WIDTH_40) | | |
5501 | BIT(NL80211_CHAN_WIDTH_80), | |
5502 | }, | |
5503 | }; | |
5504 | ||
5505 | static void ath11k_mac_update_ch_list(struct ath11k *ar, | |
5506 | struct ieee80211_supported_band *band, | |
5507 | u32 freq_low, u32 freq_high) | |
5508 | { | |
5509 | int i; | |
5510 | ||
5511 | if (!(freq_low && freq_high)) | |
5512 | return; | |
5513 | ||
5514 | for (i = 0; i < band->n_channels; i++) { | |
5515 | if (band->channels[i].center_freq < freq_low || | |
5516 | band->channels[i].center_freq > freq_high) | |
5517 | band->channels[i].flags |= IEEE80211_CHAN_DISABLED; | |
5518 | } | |
5519 | } | |
5520 | ||
5521 | static int ath11k_mac_setup_channels_rates(struct ath11k *ar, | |
5522 | u32 supported_bands) | |
5523 | { | |
5524 | struct ieee80211_supported_band *band; | |
5525 | struct ath11k_hal_reg_capabilities_ext *reg_cap; | |
5526 | void *channels; | |
5527 | ||
5528 | BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) + | |
5529 | ARRAY_SIZE(ath11k_5ghz_channels)) != | |
5530 | ATH11K_NUM_CHANS); | |
5531 | ||
5532 | reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx]; | |
5533 | ||
5534 | if (supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
5535 | channels = kmemdup(ath11k_2ghz_channels, | |
5536 | sizeof(ath11k_2ghz_channels), | |
5537 | GFP_KERNEL); | |
5538 | if (!channels) | |
5539 | return -ENOMEM; | |
5540 | ||
5541 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
5542 | band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels); | |
5543 | band->channels = channels; | |
5544 | band->n_bitrates = ath11k_g_rates_size; | |
5545 | band->bitrates = ath11k_g_rates; | |
5546 | ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band; | |
5547 | ath11k_mac_update_ch_list(ar, band, | |
5548 | reg_cap->low_2ghz_chan, | |
5549 | reg_cap->high_2ghz_chan); | |
5550 | } | |
5551 | ||
5552 | if (supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
5553 | channels = kmemdup(ath11k_5ghz_channels, | |
5554 | sizeof(ath11k_5ghz_channels), | |
5555 | GFP_KERNEL); | |
5556 | if (!channels) { | |
5557 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
5558 | return -ENOMEM; | |
5559 | } | |
5560 | ||
5561 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
5562 | band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels); | |
5563 | band->channels = channels; | |
5564 | band->n_bitrates = ath11k_a_rates_size; | |
5565 | band->bitrates = ath11k_a_rates; | |
5566 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band; | |
5567 | ath11k_mac_update_ch_list(ar, band, | |
5568 | reg_cap->low_5ghz_chan, | |
5569 | reg_cap->high_5ghz_chan); | |
5570 | } | |
5571 | ||
5572 | return 0; | |
5573 | } | |
5574 | ||
5575 | static const u8 ath11k_if_types_ext_capa[] = { | |
5576 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5577 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
5578 | }; | |
5579 | ||
5580 | static const u8 ath11k_if_types_ext_capa_sta[] = { | |
5581 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5582 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
5583 | [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, | |
5584 | }; | |
5585 | ||
5586 | static const u8 ath11k_if_types_ext_capa_ap[] = { | |
5587 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5588 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
5589 | [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, | |
5590 | }; | |
5591 | ||
5592 | static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = { | |
5593 | { | |
5594 | .extended_capabilities = ath11k_if_types_ext_capa, | |
5595 | .extended_capabilities_mask = ath11k_if_types_ext_capa, | |
5596 | .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa), | |
5597 | }, { | |
5598 | .iftype = NL80211_IFTYPE_STATION, | |
5599 | .extended_capabilities = ath11k_if_types_ext_capa_sta, | |
5600 | .extended_capabilities_mask = ath11k_if_types_ext_capa_sta, | |
5601 | .extended_capabilities_len = | |
5602 | sizeof(ath11k_if_types_ext_capa_sta), | |
5603 | }, { | |
5604 | .iftype = NL80211_IFTYPE_AP, | |
5605 | .extended_capabilities = ath11k_if_types_ext_capa_ap, | |
5606 | .extended_capabilities_mask = ath11k_if_types_ext_capa_ap, | |
5607 | .extended_capabilities_len = | |
5608 | sizeof(ath11k_if_types_ext_capa_ap), | |
5609 | }, | |
5610 | }; | |
5611 | ||
0366f426 VT |
5612 | static void __ath11k_mac_unregister(struct ath11k *ar) |
5613 | { | |
5614 | cancel_work_sync(&ar->regd_update_work); | |
5615 | ||
5616 | ieee80211_unregister_hw(ar->hw); | |
5617 | ||
5618 | idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar); | |
5619 | idr_destroy(&ar->txmgmt_idr); | |
5620 | ||
5621 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
5622 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
5623 | ||
5624 | SET_IEEE80211_DEV(ar->hw, NULL); | |
5625 | } | |
5626 | ||
5627 | void ath11k_mac_unregister(struct ath11k_base *ab) | |
5628 | { | |
5629 | struct ath11k *ar; | |
5630 | struct ath11k_pdev *pdev; | |
5631 | int i; | |
5632 | ||
5633 | for (i = 0; i < ab->num_radios; i++) { | |
5634 | pdev = &ab->pdevs[i]; | |
5635 | ar = pdev->ar; | |
5636 | if (!ar) | |
5637 | continue; | |
5638 | ||
5639 | __ath11k_mac_unregister(ar); | |
5640 | } | |
5641 | } | |
5642 | ||
5643 | static int __ath11k_mac_register(struct ath11k *ar) | |
d5c65159 KV |
5644 | { |
5645 | struct ath11k_base *ab = ar->ab; | |
5646 | struct ath11k_pdev_cap *cap = &ar->pdev->cap; | |
5647 | static const u32 cipher_suites[] = { | |
5648 | WLAN_CIPHER_SUITE_TKIP, | |
5649 | WLAN_CIPHER_SUITE_CCMP, | |
5650 | WLAN_CIPHER_SUITE_AES_CMAC, | |
5651 | WLAN_CIPHER_SUITE_BIP_CMAC_256, | |
5652 | WLAN_CIPHER_SUITE_BIP_GMAC_128, | |
5653 | WLAN_CIPHER_SUITE_BIP_GMAC_256, | |
5654 | WLAN_CIPHER_SUITE_GCMP, | |
5655 | WLAN_CIPHER_SUITE_GCMP_256, | |
5656 | WLAN_CIPHER_SUITE_CCMP_256, | |
5657 | }; | |
5658 | int ret; | |
5659 | u32 ht_cap = 0; | |
5660 | ||
5661 | ath11k_pdev_caps_update(ar); | |
5662 | ||
5663 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); | |
5664 | ||
5665 | SET_IEEE80211_DEV(ar->hw, ab->dev); | |
5666 | ||
5667 | ret = ath11k_mac_setup_channels_rates(ar, | |
5668 | cap->supported_bands); | |
5669 | if (ret) | |
5670 | goto err_free; | |
5671 | ||
5672 | ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap); | |
9f056ed8 | 5673 | ath11k_mac_setup_he_cap(ar, cap); |
d5c65159 KV |
5674 | |
5675 | ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask; | |
5676 | ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask; | |
5677 | ||
5678 | ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
5679 | BIT(NL80211_IFTYPE_AP) | | |
5680 | BIT(NL80211_IFTYPE_MESH_POINT); | |
5681 | ||
5682 | ieee80211_hw_set(ar->hw, SIGNAL_DBM); | |
5683 | ieee80211_hw_set(ar->hw, SUPPORTS_PS); | |
5684 | ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS); | |
5685 | ieee80211_hw_set(ar->hw, MFP_CAPABLE); | |
5686 | ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS); | |
5687 | ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL); | |
5688 | ieee80211_hw_set(ar->hw, AP_LINK_PS); | |
5689 | ieee80211_hw_set(ar->hw, SPECTRUM_MGMT); | |
5690 | ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT); | |
5691 | ieee80211_hw_set(ar->hw, CONNECTION_MONITOR); | |
5692 | ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK); | |
5693 | ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF); | |
5694 | ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA); | |
5695 | ieee80211_hw_set(ar->hw, QUEUE_CONTROL); | |
5696 | ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG); | |
5697 | ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK); | |
5698 | if (ht_cap & WMI_HT_CAP_ENABLED) { | |
5699 | ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION); | |
5700 | ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW); | |
5701 | ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER); | |
5702 | ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU); | |
5703 | } | |
5704 | ||
5705 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; | |
5706 | ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; | |
5707 | ||
5708 | /* TODO: Check if HT capability advertised from firmware is different | |
5709 | * for each band for a dual band capable radio. It will be tricky to | |
5710 | * handle it when the ht capability different for each band. | |
5711 | */ | |
5712 | if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) | |
5713 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; | |
5714 | ||
5715 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; | |
5716 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; | |
5717 | ||
5718 | ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL; | |
5719 | ||
5720 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; | |
5721 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; | |
5722 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; | |
5723 | ||
5724 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
5725 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | | |
5726 | NL80211_FEATURE_AP_SCAN; | |
5727 | ||
5728 | ar->max_num_stations = TARGET_NUM_STATIONS; | |
5729 | ar->max_num_peers = TARGET_NUM_PEERS_PDEV; | |
5730 | ||
5731 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; | |
5732 | ||
5733 | ar->hw->queues = ATH11K_HW_MAX_QUEUES; | |
5734 | ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1; | |
5735 | ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; | |
5736 | ||
5737 | ar->hw->vif_data_size = sizeof(struct ath11k_vif); | |
5738 | ar->hw->sta_data_size = sizeof(struct ath11k_sta); | |
5739 | ||
5740 | ar->hw->wiphy->iface_combinations = ath11k_if_comb; | |
5741 | ar->hw->wiphy->n_iface_combinations = ARRAY_SIZE(ath11k_if_comb); | |
5742 | ||
5743 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); | |
64f1d7e9 | 5744 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); |
d5c65159 KV |
5745 | |
5746 | ar->hw->wiphy->cipher_suites = cipher_suites; | |
5747 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
5748 | ||
5749 | ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa; | |
5750 | ar->hw->wiphy->num_iftype_ext_capab = | |
5751 | ARRAY_SIZE(ath11k_iftypes_ext_capa); | |
5752 | ||
5753 | ath11k_reg_init(ar); | |
5754 | ||
5755 | /* advertise HW checksum offload capabilities */ | |
5756 | ar->hw->netdev_features = NETIF_F_HW_CSUM; | |
5757 | ||
5758 | ret = ieee80211_register_hw(ar->hw); | |
5759 | if (ret) { | |
5760 | ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret); | |
5761 | goto err_free; | |
5762 | } | |
5763 | ||
5764 | /* Apply the regd received during initialization */ | |
5765 | ret = ath11k_regd_update(ar, true); | |
5766 | if (ret) { | |
5767 | ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret); | |
5768 | goto err_free; | |
5769 | } | |
5770 | ||
5771 | ret = ath11k_debug_register(ar); | |
5772 | if (ret) { | |
5773 | ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret); | |
5774 | goto err_free; | |
5775 | } | |
5776 | ||
5777 | return 0; | |
5778 | ||
5779 | err_free: | |
5780 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
5781 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
5782 | ||
5783 | SET_IEEE80211_DEV(ar->hw, NULL); | |
5784 | return ret; | |
5785 | } | |
5786 | ||
0366f426 | 5787 | int ath11k_mac_register(struct ath11k_base *ab) |
d5c65159 KV |
5788 | { |
5789 | struct ath11k *ar; | |
5790 | struct ath11k_pdev *pdev; | |
5791 | int i; | |
0366f426 | 5792 | int ret; |
d5c65159 KV |
5793 | |
5794 | for (i = 0; i < ab->num_radios; i++) { | |
5795 | pdev = &ab->pdevs[i]; | |
5796 | ar = pdev->ar; | |
0366f426 VT |
5797 | if (ab->pdevs_macaddr_valid) { |
5798 | ether_addr_copy(ar->mac_addr, pdev->mac_addr); | |
5799 | } else { | |
5800 | ether_addr_copy(ar->mac_addr, ab->mac_addr); | |
5801 | ar->mac_addr[4] += i; | |
5802 | } | |
d5c65159 | 5803 | |
0366f426 VT |
5804 | ret = __ath11k_mac_register(ar); |
5805 | if (ret) | |
5806 | goto err_cleanup; | |
d5c65159 | 5807 | |
0366f426 VT |
5808 | idr_init(&ar->txmgmt_idr); |
5809 | spin_lock_init(&ar->txmgmt_idr_lock); | |
5810 | } | |
d5c65159 | 5811 | |
0366f426 VT |
5812 | /* Initialize channel counters frequency value in hertz */ |
5813 | ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ; | |
5814 | ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1; | |
5815 | ||
5816 | return 0; | |
d5c65159 | 5817 | |
0366f426 VT |
5818 | err_cleanup: |
5819 | for (i = i - 1; i >= 0; i--) { | |
5820 | pdev = &ab->pdevs[i]; | |
5821 | ar = pdev->ar; | |
5822 | __ath11k_mac_unregister(ar); | |
d5c65159 | 5823 | } |
0366f426 VT |
5824 | |
5825 | return ret; | |
d5c65159 KV |
5826 | } |
5827 | ||
0366f426 | 5828 | int ath11k_mac_allocate(struct ath11k_base *ab) |
d5c65159 KV |
5829 | { |
5830 | struct ieee80211_hw *hw; | |
5831 | struct ath11k *ar; | |
5832 | struct ath11k_pdev *pdev; | |
5833 | int ret; | |
5834 | int i; | |
5835 | ||
5836 | if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) | |
5837 | return 0; | |
5838 | ||
5839 | for (i = 0; i < ab->num_radios; i++) { | |
5840 | pdev = &ab->pdevs[i]; | |
5841 | hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops); | |
5842 | if (!hw) { | |
5843 | ath11k_warn(ab, "failed to allocate mac80211 hw device\n"); | |
5844 | ret = -ENOMEM; | |
0366f426 | 5845 | goto err_free_mac; |
d5c65159 KV |
5846 | } |
5847 | ||
5848 | ar = hw->priv; | |
5849 | ar->hw = hw; | |
5850 | ar->ab = ab; | |
5851 | ar->pdev = pdev; | |
5852 | ar->pdev_idx = i; | |
5853 | ar->lmac_id = ath11k_core_get_hw_mac_id(ab, i); | |
5854 | ||
6bc9d6f7 | 5855 | ar->wmi = &ab->wmi_ab.wmi[i]; |
d5c65159 KV |
5856 | /* FIXME wmi[0] is already initialized during attach, |
5857 | * Should we do this again? | |
5858 | */ | |
5859 | ath11k_wmi_pdev_attach(ab, i); | |
5860 | ||
5861 | ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask; | |
5862 | ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask; | |
5863 | ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask); | |
5864 | ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask); | |
5865 | ||
d5c65159 KV |
5866 | pdev->ar = ar; |
5867 | spin_lock_init(&ar->data_lock); | |
5868 | INIT_LIST_HEAD(&ar->arvifs); | |
5869 | INIT_LIST_HEAD(&ar->ppdu_stats_info); | |
5870 | mutex_init(&ar->conf_mutex); | |
5871 | init_completion(&ar->vdev_setup_done); | |
5872 | init_completion(&ar->peer_assoc_done); | |
5873 | init_completion(&ar->install_key_done); | |
5874 | init_completion(&ar->bss_survey_done); | |
5875 | init_completion(&ar->scan.started); | |
5876 | init_completion(&ar->scan.completed); | |
5877 | INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work); | |
5878 | INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work); | |
5879 | ||
5880 | INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work); | |
5881 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); | |
5882 | clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
d5c65159 KV |
5883 | } |
5884 | ||
d5c65159 KV |
5885 | return 0; |
5886 | ||
0366f426 | 5887 | err_free_mac: |
d5c65159 KV |
5888 | ath11k_mac_destroy(ab); |
5889 | ||
5890 | return ret; | |
5891 | } | |
5892 | ||
5893 | void ath11k_mac_destroy(struct ath11k_base *ab) | |
5894 | { | |
5895 | struct ath11k *ar; | |
5896 | struct ath11k_pdev *pdev; | |
5897 | int i; | |
5898 | ||
5899 | for (i = 0; i < ab->num_radios; i++) { | |
5900 | pdev = &ab->pdevs[i]; | |
5901 | ar = pdev->ar; | |
5902 | if (!ar) | |
5903 | continue; | |
5904 | ||
5905 | ieee80211_free_hw(ar->hw); | |
5906 | pdev->ar = NULL; | |
5907 | } | |
5908 | } |