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); | |
1761 | } | |
1762 | ||
1763 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { | |
1764 | arvif->dtim_period = info->dtim_period; | |
1765 | ||
1766 | param_id = WMI_VDEV_PARAM_DTIM_PERIOD; | |
1767 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1768 | param_id, | |
1769 | arvif->dtim_period); | |
1770 | ||
1771 | if (ret) | |
1772 | ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n", | |
1773 | arvif->vdev_id, ret); | |
1774 | else | |
1775 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1776 | "DTIM period: %d set for VDEV: %d\n", | |
1777 | arvif->dtim_period, arvif->vdev_id); | |
1778 | } | |
1779 | ||
1780 | if (changed & BSS_CHANGED_SSID && | |
1781 | vif->type == NL80211_IFTYPE_AP) { | |
1782 | arvif->u.ap.ssid_len = info->ssid_len; | |
1783 | if (info->ssid_len) | |
1784 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); | |
1785 | arvif->u.ap.hidden_ssid = info->hidden_ssid; | |
1786 | } | |
1787 | ||
1788 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) | |
1789 | ether_addr_copy(arvif->bssid, info->bssid); | |
1790 | ||
1791 | if (changed & BSS_CHANGED_BEACON_ENABLED) | |
1792 | ath11k_control_beaconing(arvif, info); | |
1793 | ||
1794 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
1795 | u32 cts_prot; | |
1796 | ||
1797 | cts_prot = !!(info->use_cts_prot); | |
1798 | param_id = WMI_VDEV_PARAM_PROTECTION_MODE; | |
1799 | ||
1800 | if (arvif->is_started) { | |
1801 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1802 | param_id, cts_prot); | |
1803 | if (ret) | |
1804 | ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n", | |
1805 | arvif->vdev_id); | |
1806 | else | |
1807 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n", | |
1808 | cts_prot, arvif->vdev_id); | |
1809 | } else { | |
1810 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n"); | |
1811 | } | |
1812 | } | |
1813 | ||
1814 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
1815 | u32 slottime; | |
1816 | ||
1817 | if (info->use_short_slot) | |
1818 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ | |
1819 | ||
1820 | else | |
1821 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ | |
1822 | ||
1823 | param_id = WMI_VDEV_PARAM_SLOT_TIME; | |
1824 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1825 | param_id, slottime); | |
1826 | if (ret) | |
1827 | ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n", | |
1828 | arvif->vdev_id); | |
1829 | else | |
1830 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1831 | "Set slottime: %d for VDEV: %d\n", | |
1832 | slottime, arvif->vdev_id); | |
1833 | } | |
1834 | ||
1835 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
1836 | u32 preamble; | |
1837 | ||
1838 | if (info->use_short_preamble) | |
1839 | preamble = WMI_VDEV_PREAMBLE_SHORT; | |
1840 | else | |
1841 | preamble = WMI_VDEV_PREAMBLE_LONG; | |
1842 | ||
1843 | param_id = WMI_VDEV_PARAM_PREAMBLE; | |
1844 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1845 | param_id, preamble); | |
1846 | if (ret) | |
1847 | ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n", | |
1848 | arvif->vdev_id); | |
1849 | else | |
1850 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1851 | "Set preamble: %d for VDEV: %d\n", | |
1852 | preamble, arvif->vdev_id); | |
1853 | } | |
1854 | ||
1855 | if (changed & BSS_CHANGED_ASSOC) { | |
1856 | if (info->assoc) | |
1857 | ath11k_bss_assoc(hw, vif, info); | |
1858 | else | |
1859 | ath11k_bss_disassoc(hw, vif); | |
1860 | } | |
1861 | ||
1862 | if (changed & BSS_CHANGED_TXPOWER) { | |
1863 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n", | |
1864 | arvif->vdev_id, info->txpower); | |
1865 | ||
1866 | arvif->txpower = info->txpower; | |
1867 | ath11k_mac_txpower_recalc(ar); | |
1868 | } | |
1869 | ||
1870 | if (changed & BSS_CHANGED_MCAST_RATE && | |
1871 | !ath11k_mac_vif_chan(arvif->vif, &def)) { | |
1872 | band = def.chan->band; | |
1873 | mcast_rate = vif->bss_conf.mcast_rate[band]; | |
1874 | ||
1875 | if (mcast_rate > 0) | |
1876 | rateidx = mcast_rate - 1; | |
1877 | else | |
1878 | rateidx = ffs(vif->bss_conf.basic_rates) - 1; | |
1879 | ||
1880 | if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) | |
1881 | rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
1882 | ||
1883 | bitrate = ath11k_legacy_rates[rateidx].bitrate; | |
1884 | hw_value = ath11k_legacy_rates[rateidx].hw_value; | |
1885 | ||
1886 | if (ath11k_mac_bitrate_is_cck(bitrate)) | |
1887 | preamble = WMI_RATE_PREAMBLE_CCK; | |
1888 | else | |
1889 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
1890 | ||
1891 | rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble); | |
1892 | ||
1893 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
1894 | "mac vdev %d mcast_rate %x\n", | |
1895 | arvif->vdev_id, rate); | |
1896 | ||
1897 | vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE; | |
1898 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1899 | vdev_param, rate); | |
1900 | if (ret) | |
1901 | ath11k_warn(ar->ab, | |
1902 | "failed to set mcast rate on vdev %i: %d\n", | |
1903 | arvif->vdev_id, ret); | |
1904 | ||
1905 | vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE; | |
1906 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
1907 | vdev_param, rate); | |
1908 | if (ret) | |
1909 | ath11k_warn(ar->ab, | |
1910 | "failed to set bcast rate on vdev %i: %d\n", | |
1911 | arvif->vdev_id, ret); | |
1912 | } | |
1913 | ||
1914 | if (changed & BSS_CHANGED_BASIC_RATES && | |
1915 | !ath11k_mac_vif_chan(arvif->vif, &def)) | |
1916 | ath11k_recalculate_mgmt_rate(ar, vif, &def); | |
1917 | ||
6d293d44 JC |
1918 | if (changed & BSS_CHANGED_TWT) { |
1919 | if (info->twt_requester || info->twt_responder) | |
485add35 | 1920 | ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id); |
6d293d44 | 1921 | else |
485add35 | 1922 | ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id); |
6d293d44 JC |
1923 | } |
1924 | ||
3f8be640 JC |
1925 | if (changed & BSS_CHANGED_HE_OBSS_PD) |
1926 | ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id, | |
1927 | &info->he_obss_pd); | |
1928 | ||
d5c65159 KV |
1929 | mutex_unlock(&ar->conf_mutex); |
1930 | } | |
1931 | ||
1932 | void __ath11k_mac_scan_finish(struct ath11k *ar) | |
1933 | { | |
1934 | lockdep_assert_held(&ar->data_lock); | |
1935 | ||
1936 | switch (ar->scan.state) { | |
1937 | case ATH11K_SCAN_IDLE: | |
1938 | break; | |
1939 | case ATH11K_SCAN_RUNNING: | |
1940 | case ATH11K_SCAN_ABORTING: | |
1941 | if (!ar->scan.is_roc) { | |
1942 | struct cfg80211_scan_info info = { | |
1943 | .aborted = (ar->scan.state == | |
1944 | ATH11K_SCAN_ABORTING), | |
1945 | }; | |
1946 | ||
1947 | ieee80211_scan_completed(ar->hw, &info); | |
1948 | } else if (ar->scan.roc_notify) { | |
1949 | ieee80211_remain_on_channel_expired(ar->hw); | |
1950 | } | |
1951 | /* fall through */ | |
1952 | case ATH11K_SCAN_STARTING: | |
1953 | ar->scan.state = ATH11K_SCAN_IDLE; | |
1954 | ar->scan_channel = NULL; | |
1955 | ar->scan.roc_freq = 0; | |
1956 | cancel_delayed_work(&ar->scan.timeout); | |
1957 | complete(&ar->scan.completed); | |
1958 | break; | |
1959 | } | |
1960 | } | |
1961 | ||
1962 | void ath11k_mac_scan_finish(struct ath11k *ar) | |
1963 | { | |
1964 | spin_lock_bh(&ar->data_lock); | |
1965 | __ath11k_mac_scan_finish(ar); | |
1966 | spin_unlock_bh(&ar->data_lock); | |
1967 | } | |
1968 | ||
1969 | static int ath11k_scan_stop(struct ath11k *ar) | |
1970 | { | |
1971 | struct scan_cancel_param arg = { | |
1972 | .req_type = WLAN_SCAN_CANCEL_SINGLE, | |
1973 | .scan_id = ATH11K_SCAN_ID, | |
1974 | }; | |
1975 | int ret; | |
1976 | ||
1977 | lockdep_assert_held(&ar->conf_mutex); | |
1978 | ||
1979 | /* TODO: Fill other STOP Params */ | |
1980 | arg.pdev_id = ar->pdev->pdev_id; | |
1981 | ||
1982 | ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg); | |
1983 | if (ret) { | |
1984 | ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret); | |
1985 | goto out; | |
1986 | } | |
1987 | ||
1988 | ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); | |
1989 | if (ret == 0) { | |
1990 | ath11k_warn(ar->ab, | |
1991 | "failed to receive scan abort comple: timed out\n"); | |
1992 | ret = -ETIMEDOUT; | |
1993 | } else if (ret > 0) { | |
1994 | ret = 0; | |
1995 | } | |
1996 | ||
1997 | out: | |
1998 | /* Scan state should be updated upon scan completion but in case | |
1999 | * firmware fails to deliver the event (for whatever reason) it is | |
2000 | * desired to clean up scan state anyway. Firmware may have just | |
2001 | * dropped the scan completion event delivery due to transport pipe | |
2002 | * being overflown with data and/or it can recover on its own before | |
2003 | * next scan request is submitted. | |
2004 | */ | |
2005 | spin_lock_bh(&ar->data_lock); | |
2006 | if (ar->scan.state != ATH11K_SCAN_IDLE) | |
2007 | __ath11k_mac_scan_finish(ar); | |
2008 | spin_unlock_bh(&ar->data_lock); | |
2009 | ||
2010 | return ret; | |
2011 | } | |
2012 | ||
2013 | static void ath11k_scan_abort(struct ath11k *ar) | |
2014 | { | |
2015 | int ret; | |
2016 | ||
2017 | lockdep_assert_held(&ar->conf_mutex); | |
2018 | ||
2019 | spin_lock_bh(&ar->data_lock); | |
2020 | ||
2021 | switch (ar->scan.state) { | |
2022 | case ATH11K_SCAN_IDLE: | |
2023 | /* This can happen if timeout worker kicked in and called | |
2024 | * abortion while scan completion was being processed. | |
2025 | */ | |
2026 | break; | |
2027 | case ATH11K_SCAN_STARTING: | |
2028 | case ATH11K_SCAN_ABORTING: | |
2029 | ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n", | |
2030 | ar->scan.state); | |
2031 | break; | |
2032 | case ATH11K_SCAN_RUNNING: | |
2033 | ar->scan.state = ATH11K_SCAN_ABORTING; | |
2034 | spin_unlock_bh(&ar->data_lock); | |
2035 | ||
2036 | ret = ath11k_scan_stop(ar); | |
2037 | if (ret) | |
2038 | ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret); | |
2039 | ||
2040 | spin_lock_bh(&ar->data_lock); | |
2041 | break; | |
2042 | } | |
2043 | ||
2044 | spin_unlock_bh(&ar->data_lock); | |
2045 | } | |
2046 | ||
2047 | static void ath11k_scan_timeout_work(struct work_struct *work) | |
2048 | { | |
2049 | struct ath11k *ar = container_of(work, struct ath11k, | |
2050 | scan.timeout.work); | |
2051 | ||
2052 | mutex_lock(&ar->conf_mutex); | |
2053 | ath11k_scan_abort(ar); | |
2054 | mutex_unlock(&ar->conf_mutex); | |
2055 | } | |
2056 | ||
2057 | static int ath11k_start_scan(struct ath11k *ar, | |
2058 | struct scan_req_params *arg) | |
2059 | { | |
2060 | int ret; | |
2061 | ||
2062 | lockdep_assert_held(&ar->conf_mutex); | |
2063 | ||
2064 | ret = ath11k_wmi_send_scan_start_cmd(ar, arg); | |
2065 | if (ret) | |
2066 | return ret; | |
2067 | ||
2068 | ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); | |
2069 | if (ret == 0) { | |
2070 | ret = ath11k_scan_stop(ar); | |
2071 | if (ret) | |
2072 | ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret); | |
2073 | ||
2074 | return -ETIMEDOUT; | |
2075 | } | |
2076 | ||
2077 | /* If we failed to start the scan, return error code at | |
2078 | * this point. This is probably due to some issue in the | |
2079 | * firmware, but no need to wedge the driver due to that... | |
2080 | */ | |
2081 | spin_lock_bh(&ar->data_lock); | |
2082 | if (ar->scan.state == ATH11K_SCAN_IDLE) { | |
2083 | spin_unlock_bh(&ar->data_lock); | |
2084 | return -EINVAL; | |
2085 | } | |
2086 | spin_unlock_bh(&ar->data_lock); | |
2087 | ||
2088 | return 0; | |
2089 | } | |
2090 | ||
2091 | static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw, | |
2092 | struct ieee80211_vif *vif, | |
2093 | struct ieee80211_scan_request *hw_req) | |
2094 | { | |
2095 | struct ath11k *ar = hw->priv; | |
2096 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2097 | struct cfg80211_scan_request *req = &hw_req->req; | |
2098 | struct scan_req_params arg; | |
2099 | int ret = 0; | |
2100 | int i; | |
2101 | ||
2102 | mutex_lock(&ar->conf_mutex); | |
2103 | ||
2104 | spin_lock_bh(&ar->data_lock); | |
2105 | switch (ar->scan.state) { | |
2106 | case ATH11K_SCAN_IDLE: | |
2107 | reinit_completion(&ar->scan.started); | |
2108 | reinit_completion(&ar->scan.completed); | |
2109 | ar->scan.state = ATH11K_SCAN_STARTING; | |
2110 | ar->scan.is_roc = false; | |
2111 | ar->scan.vdev_id = arvif->vdev_id; | |
2112 | ret = 0; | |
2113 | break; | |
2114 | case ATH11K_SCAN_STARTING: | |
2115 | case ATH11K_SCAN_RUNNING: | |
2116 | case ATH11K_SCAN_ABORTING: | |
2117 | ret = -EBUSY; | |
2118 | break; | |
2119 | } | |
2120 | spin_unlock_bh(&ar->data_lock); | |
2121 | ||
2122 | if (ret) | |
2123 | goto exit; | |
2124 | ||
2125 | memset(&arg, 0, sizeof(arg)); | |
2126 | ath11k_wmi_start_scan_init(ar, &arg); | |
2127 | arg.vdev_id = arvif->vdev_id; | |
2128 | arg.scan_id = ATH11K_SCAN_ID; | |
2129 | ||
2130 | if (req->ie_len) { | |
2131 | arg.extraie.len = req->ie_len; | |
2132 | arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL); | |
2133 | memcpy(arg.extraie.ptr, req->ie, req->ie_len); | |
2134 | } | |
2135 | ||
2136 | if (req->n_ssids) { | |
2137 | arg.num_ssids = req->n_ssids; | |
2138 | for (i = 0; i < arg.num_ssids; i++) { | |
2139 | arg.ssid[i].length = req->ssids[i].ssid_len; | |
2140 | memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid, | |
2141 | req->ssids[i].ssid_len); | |
2142 | } | |
2143 | } else { | |
2144 | arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE; | |
2145 | } | |
2146 | ||
2147 | if (req->n_channels) { | |
2148 | arg.num_chan = req->n_channels; | |
2149 | for (i = 0; i < arg.num_chan; i++) | |
2150 | arg.chan_list[i] = req->channels[i]->center_freq; | |
2151 | } | |
2152 | ||
2153 | ret = ath11k_start_scan(ar, &arg); | |
2154 | if (ret) { | |
2155 | ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret); | |
2156 | spin_lock_bh(&ar->data_lock); | |
2157 | ar->scan.state = ATH11K_SCAN_IDLE; | |
2158 | spin_unlock_bh(&ar->data_lock); | |
2159 | } | |
2160 | ||
2161 | /* Add a 200ms margin to account for event/command processing */ | |
2162 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, | |
2163 | msecs_to_jiffies(arg.max_scan_time + | |
2164 | ATH11K_MAC_SCAN_TIMEOUT_MSECS)); | |
2165 | ||
2166 | exit: | |
2167 | if (req->ie_len) | |
2168 | kfree(arg.extraie.ptr); | |
2169 | ||
2170 | mutex_unlock(&ar->conf_mutex); | |
2171 | return ret; | |
2172 | } | |
2173 | ||
2174 | static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw, | |
2175 | struct ieee80211_vif *vif) | |
2176 | { | |
2177 | struct ath11k *ar = hw->priv; | |
2178 | ||
2179 | mutex_lock(&ar->conf_mutex); | |
2180 | ath11k_scan_abort(ar); | |
2181 | mutex_unlock(&ar->conf_mutex); | |
2182 | ||
2183 | cancel_delayed_work_sync(&ar->scan.timeout); | |
2184 | } | |
2185 | ||
2186 | static int ath11k_install_key(struct ath11k_vif *arvif, | |
2187 | struct ieee80211_key_conf *key, | |
2188 | enum set_key_cmd cmd, | |
2189 | const u8 *macaddr, u32 flags) | |
2190 | { | |
2191 | int ret; | |
2192 | struct ath11k *ar = arvif->ar; | |
2193 | struct wmi_vdev_install_key_arg arg = { | |
2194 | .vdev_id = arvif->vdev_id, | |
2195 | .key_idx = key->keyidx, | |
2196 | .key_len = key->keylen, | |
2197 | .key_data = key->key, | |
2198 | .key_flags = flags, | |
2199 | .macaddr = macaddr, | |
2200 | }; | |
2201 | ||
2202 | lockdep_assert_held(&arvif->ar->conf_mutex); | |
2203 | ||
2204 | reinit_completion(&ar->install_key_done); | |
2205 | ||
2206 | if (cmd == DISABLE_KEY) { | |
2207 | /* TODO: Check if FW expects value other than NONE for del */ | |
2208 | /* arg.key_cipher = WMI_CIPHER_NONE; */ | |
2209 | arg.key_len = 0; | |
2210 | arg.key_data = NULL; | |
2211 | goto install; | |
2212 | } | |
2213 | ||
2214 | switch (key->cipher) { | |
2215 | case WLAN_CIPHER_SUITE_CCMP: | |
2216 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
2217 | /* TODO: Re-check if flag is valid */ | |
2218 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; | |
2219 | break; | |
2220 | case WLAN_CIPHER_SUITE_TKIP: | |
2221 | arg.key_cipher = WMI_CIPHER_TKIP; | |
2222 | arg.key_txmic_len = 8; | |
2223 | arg.key_rxmic_len = 8; | |
2224 | break; | |
2225 | case WLAN_CIPHER_SUITE_CCMP_256: | |
2226 | arg.key_cipher = WMI_CIPHER_AES_CCM; | |
2227 | break; | |
2228 | case WLAN_CIPHER_SUITE_GCMP: | |
2229 | case WLAN_CIPHER_SUITE_GCMP_256: | |
2230 | arg.key_cipher = WMI_CIPHER_AES_GCM; | |
2231 | break; | |
2232 | default: | |
2233 | ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher); | |
2234 | return -EOPNOTSUPP; | |
2235 | } | |
2236 | ||
2237 | install: | |
2238 | ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg); | |
2239 | if (ret) | |
2240 | return ret; | |
2241 | ||
2242 | if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ)) | |
2243 | return -ETIMEDOUT; | |
2244 | ||
2245 | return ar->install_key_status ? -EINVAL : 0; | |
2246 | } | |
2247 | ||
2248 | static int ath11k_clear_peer_keys(struct ath11k_vif *arvif, | |
2249 | const u8 *addr) | |
2250 | { | |
2251 | struct ath11k *ar = arvif->ar; | |
2252 | struct ath11k_base *ab = ar->ab; | |
2253 | struct ath11k_peer *peer; | |
2254 | int first_errno = 0; | |
2255 | int ret; | |
2256 | int i; | |
2257 | u32 flags = 0; | |
2258 | ||
2259 | lockdep_assert_held(&ar->conf_mutex); | |
2260 | ||
2261 | spin_lock_bh(&ab->base_lock); | |
2262 | peer = ath11k_peer_find(ab, arvif->vdev_id, addr); | |
2263 | spin_unlock_bh(&ab->base_lock); | |
2264 | ||
2265 | if (!peer) | |
2266 | return -ENOENT; | |
2267 | ||
2268 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { | |
2269 | if (!peer->keys[i]) | |
2270 | continue; | |
2271 | ||
2272 | /* key flags are not required to delete the key */ | |
2273 | ret = ath11k_install_key(arvif, peer->keys[i], | |
2274 | DISABLE_KEY, addr, flags); | |
2275 | if (ret < 0 && first_errno == 0) | |
2276 | first_errno = ret; | |
2277 | ||
2278 | if (ret < 0) | |
2279 | ath11k_warn(ab, "failed to remove peer key %d: %d\n", | |
2280 | i, ret); | |
2281 | ||
2282 | spin_lock_bh(&ab->base_lock); | |
2283 | peer->keys[i] = NULL; | |
2284 | spin_unlock_bh(&ab->base_lock); | |
2285 | } | |
2286 | ||
2287 | return first_errno; | |
2288 | } | |
2289 | ||
2290 | static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
2291 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
2292 | struct ieee80211_key_conf *key) | |
2293 | { | |
2294 | struct ath11k *ar = hw->priv; | |
2295 | struct ath11k_base *ab = ar->ab; | |
2296 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2297 | struct ath11k_peer *peer; | |
2298 | const u8 *peer_addr; | |
2299 | int ret = 0; | |
2300 | u32 flags = 0; | |
2301 | ||
2302 | /* BIP needs to be done in software */ | |
2303 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || | |
2304 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
2305 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || | |
2306 | key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) | |
2307 | return 1; | |
2308 | ||
2309 | if (key->keyidx > WMI_MAX_KEY_INDEX) | |
2310 | return -ENOSPC; | |
2311 | ||
2312 | mutex_lock(&ar->conf_mutex); | |
2313 | ||
2314 | if (sta) | |
2315 | peer_addr = sta->addr; | |
2316 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
2317 | peer_addr = vif->bss_conf.bssid; | |
2318 | else | |
2319 | peer_addr = vif->addr; | |
2320 | ||
2321 | key->hw_key_idx = key->keyidx; | |
2322 | ||
2323 | /* the peer should not disappear in mid-way (unless FW goes awry) since | |
2324 | * we already hold conf_mutex. we just make sure its there now. | |
2325 | */ | |
2326 | spin_lock_bh(&ab->base_lock); | |
2327 | peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr); | |
2328 | spin_unlock_bh(&ab->base_lock); | |
2329 | ||
2330 | if (!peer) { | |
2331 | if (cmd == SET_KEY) { | |
2332 | ath11k_warn(ab, "cannot install key for non-existent peer %pM\n", | |
2333 | peer_addr); | |
2334 | ret = -EOPNOTSUPP; | |
2335 | goto exit; | |
2336 | } else { | |
2337 | /* if the peer doesn't exist there is no key to disable | |
2338 | * anymore | |
2339 | */ | |
2340 | goto exit; | |
2341 | } | |
2342 | } | |
2343 | ||
2344 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
2345 | flags |= WMI_KEY_PAIRWISE; | |
2346 | else | |
2347 | flags |= WMI_KEY_GROUP; | |
2348 | ||
2349 | ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags); | |
2350 | if (ret) { | |
2351 | ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret); | |
2352 | goto exit; | |
2353 | } | |
2354 | ||
2355 | spin_lock_bh(&ab->base_lock); | |
2356 | peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr); | |
2357 | if (peer && cmd == SET_KEY) | |
2358 | peer->keys[key->keyidx] = key; | |
2359 | else if (peer && cmd == DISABLE_KEY) | |
2360 | peer->keys[key->keyidx] = NULL; | |
2361 | else if (!peer) | |
2362 | /* impossible unless FW goes crazy */ | |
2363 | ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr); | |
2364 | spin_unlock_bh(&ab->base_lock); | |
2365 | ||
2366 | exit: | |
2367 | mutex_unlock(&ar->conf_mutex); | |
2368 | return ret; | |
2369 | } | |
2370 | ||
2371 | static int | |
2372 | ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar, | |
2373 | enum nl80211_band band, | |
2374 | const struct cfg80211_bitrate_mask *mask) | |
2375 | { | |
2376 | int num_rates = 0; | |
2377 | int i; | |
2378 | ||
2379 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) | |
2380 | num_rates += hweight16(mask->control[band].vht_mcs[i]); | |
2381 | ||
2382 | return num_rates; | |
2383 | } | |
2384 | ||
2385 | static int | |
2386 | ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif, | |
2387 | struct ieee80211_sta *sta, | |
2388 | const struct cfg80211_bitrate_mask *mask, | |
2389 | enum nl80211_band band) | |
2390 | { | |
2391 | struct ath11k *ar = arvif->ar; | |
2392 | u8 vht_rate, nss; | |
2393 | u32 rate_code; | |
2394 | int ret, i; | |
2395 | ||
2396 | lockdep_assert_held(&ar->conf_mutex); | |
2397 | ||
2398 | nss = 0; | |
2399 | ||
2400 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
2401 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { | |
2402 | nss = i + 1; | |
2403 | vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1; | |
2404 | } | |
2405 | } | |
2406 | ||
2407 | if (!nss) { | |
2408 | ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM", | |
2409 | sta->addr); | |
2410 | return -EINVAL; | |
2411 | } | |
2412 | ||
2413 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
2414 | "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates", | |
2415 | sta->addr); | |
2416 | ||
2417 | rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1, | |
2418 | WMI_RATE_PREAMBLE_VHT); | |
2419 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, | |
2420 | arvif->vdev_id, | |
2421 | WMI_PEER_PARAM_FIXED_RATE, | |
2422 | rate_code); | |
2423 | if (ret) | |
2424 | ath11k_warn(ar->ab, | |
2425 | "failed to update STA %pM Fixed Rate %d: %d\n", | |
2426 | sta->addr, rate_code, ret); | |
2427 | ||
2428 | return ret; | |
2429 | } | |
2430 | ||
2431 | static int ath11k_station_assoc(struct ath11k *ar, | |
2432 | struct ieee80211_vif *vif, | |
2433 | struct ieee80211_sta *sta, | |
2434 | bool reassoc) | |
2435 | { | |
2436 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2437 | struct peer_assoc_params peer_arg; | |
2438 | int ret = 0; | |
2439 | struct cfg80211_chan_def def; | |
2440 | enum nl80211_band band; | |
2441 | struct cfg80211_bitrate_mask *mask; | |
2442 | u8 num_vht_rates; | |
2443 | ||
2444 | lockdep_assert_held(&ar->conf_mutex); | |
2445 | ||
2446 | if (WARN_ON(ath11k_mac_vif_chan(vif, &def))) | |
2447 | return -EPERM; | |
2448 | ||
2449 | band = def.chan->band; | |
2450 | mask = &arvif->bitrate_mask; | |
2451 | ||
2452 | ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc); | |
2453 | ||
2454 | ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
2455 | if (ret) { | |
2456 | ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
2457 | sta->addr, arvif->vdev_id, ret); | |
2458 | return ret; | |
2459 | } | |
2460 | ||
2461 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) { | |
2462 | ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
2463 | sta->addr, arvif->vdev_id); | |
2464 | return -ETIMEDOUT; | |
2465 | } | |
2466 | ||
2467 | num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask); | |
2468 | ||
2469 | /* If single VHT rate is configured (by set_bitrate_mask()), | |
2470 | * peer_assoc will disable VHT. This is now enabled by a peer specific | |
2471 | * fixed param. | |
2472 | * Note that all other rates and NSS will be disabled for this peer. | |
2473 | */ | |
2474 | if (sta->vht_cap.vht_supported && num_vht_rates == 1) { | |
2475 | ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask, | |
2476 | band); | |
2477 | if (ret) | |
2478 | return ret; | |
2479 | } | |
2480 | ||
2481 | /* Re-assoc is run only to update supported rates for given station. It | |
2482 | * doesn't make much sense to reconfigure the peer completely. | |
2483 | */ | |
2484 | if (reassoc) | |
2485 | return 0; | |
2486 | ||
2487 | ret = ath11k_setup_peer_smps(ar, arvif, sta->addr, | |
2488 | &sta->ht_cap); | |
2489 | if (ret) { | |
2490 | ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n", | |
2491 | arvif->vdev_id, ret); | |
2492 | return ret; | |
2493 | } | |
2494 | ||
2495 | if (!sta->wme) { | |
2496 | arvif->num_legacy_stations++; | |
2497 | ret = ath11k_recalc_rtscts_prot(arvif); | |
2498 | if (ret) | |
2499 | return ret; | |
2500 | } | |
2501 | ||
2502 | if (sta->wme && sta->uapsd_queues) { | |
2503 | ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta); | |
2504 | if (ret) { | |
2505 | ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n", | |
2506 | sta->addr, arvif->vdev_id, ret); | |
2507 | return ret; | |
2508 | } | |
2509 | } | |
2510 | ||
2511 | return 0; | |
2512 | } | |
2513 | ||
2514 | static int ath11k_station_disassoc(struct ath11k *ar, | |
2515 | struct ieee80211_vif *vif, | |
2516 | struct ieee80211_sta *sta) | |
2517 | { | |
2518 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
2519 | int ret = 0; | |
2520 | ||
2521 | lockdep_assert_held(&ar->conf_mutex); | |
2522 | ||
2523 | if (!sta->wme) { | |
2524 | arvif->num_legacy_stations--; | |
2525 | ret = ath11k_recalc_rtscts_prot(arvif); | |
2526 | if (ret) | |
2527 | return ret; | |
2528 | } | |
2529 | ||
2530 | ret = ath11k_clear_peer_keys(arvif, sta->addr); | |
2531 | if (ret) { | |
2532 | ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n", | |
2533 | arvif->vdev_id, ret); | |
2534 | return ret; | |
2535 | } | |
2536 | return 0; | |
2537 | } | |
2538 | ||
2539 | static void ath11k_sta_rc_update_wk(struct work_struct *wk) | |
2540 | { | |
2541 | struct ath11k *ar; | |
2542 | struct ath11k_vif *arvif; | |
2543 | struct ath11k_sta *arsta; | |
2544 | struct ieee80211_sta *sta; | |
2545 | struct cfg80211_chan_def def; | |
2546 | enum nl80211_band band; | |
2547 | const u8 *ht_mcs_mask; | |
2548 | const u16 *vht_mcs_mask; | |
2549 | u32 changed, bw, nss, smps; | |
2550 | int err, num_vht_rates; | |
2551 | const struct cfg80211_bitrate_mask *mask; | |
2552 | struct peer_assoc_params peer_arg; | |
2553 | ||
2554 | arsta = container_of(wk, struct ath11k_sta, update_wk); | |
2555 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); | |
2556 | arvif = arsta->arvif; | |
2557 | ar = arvif->ar; | |
2558 | ||
2559 | if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def))) | |
2560 | return; | |
2561 | ||
2562 | band = def.chan->band; | |
2563 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; | |
2564 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; | |
2565 | ||
2566 | spin_lock_bh(&ar->data_lock); | |
2567 | ||
2568 | changed = arsta->changed; | |
2569 | arsta->changed = 0; | |
2570 | ||
2571 | bw = arsta->bw; | |
2572 | nss = arsta->nss; | |
2573 | smps = arsta->smps; | |
2574 | ||
2575 | spin_unlock_bh(&ar->data_lock); | |
2576 | ||
2577 | mutex_lock(&ar->conf_mutex); | |
2578 | ||
2579 | nss = max_t(u32, 1, nss); | |
2580 | nss = min(nss, max(ath11k_mac_max_ht_nss(ht_mcs_mask), | |
2581 | ath11k_mac_max_vht_nss(vht_mcs_mask))); | |
2582 | ||
2583 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
2584 | err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2585 | WMI_PEER_CHWIDTH, bw); | |
2586 | if (err) | |
2587 | ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n", | |
2588 | sta->addr, bw, err); | |
2589 | } | |
2590 | ||
2591 | if (changed & IEEE80211_RC_NSS_CHANGED) { | |
2592 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n", | |
2593 | sta->addr, nss); | |
2594 | ||
2595 | err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2596 | WMI_PEER_NSS, nss); | |
2597 | if (err) | |
2598 | ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n", | |
2599 | sta->addr, nss, err); | |
2600 | } | |
2601 | ||
2602 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
2603 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n", | |
2604 | sta->addr, smps); | |
2605 | ||
2606 | err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2607 | WMI_PEER_MIMO_PS_STATE, smps); | |
2608 | if (err) | |
2609 | ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n", | |
2610 | sta->addr, smps, err); | |
2611 | } | |
2612 | ||
2613 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { | |
2614 | mask = &arvif->bitrate_mask; | |
2615 | num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, | |
2616 | mask); | |
2617 | ||
2618 | /* Peer_assoc_prepare will reject vht rates in | |
2619 | * bitrate_mask if its not available in range format and | |
2620 | * sets vht tx_rateset as unsupported. So multiple VHT MCS | |
2621 | * setting(eg. MCS 4,5,6) per peer is not supported here. | |
2622 | * But, Single rate in VHT mask can be set as per-peer | |
2623 | * fixed rate. But even if any HT rates are configured in | |
2624 | * the bitrate mask, device will not switch to those rates | |
2625 | * when per-peer Fixed rate is set. | |
2626 | * TODO: Check RATEMASK_CMDID to support auto rates selection | |
2627 | * across HT/VHT and for multiple VHT MCS support. | |
2628 | */ | |
2629 | if (sta->vht_cap.vht_supported && num_vht_rates == 1) { | |
2630 | ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask, | |
2631 | band); | |
2632 | } else { | |
2633 | /* If the peer is non-VHT or no fixed VHT rate | |
2634 | * is provided in the new bitrate mask we set the | |
2635 | * other rates using peer_assoc command. | |
2636 | */ | |
2637 | ath11k_peer_assoc_prepare(ar, arvif->vif, sta, | |
2638 | &peer_arg, true); | |
2639 | ||
2640 | err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg); | |
2641 | if (err) | |
2642 | ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n", | |
2643 | sta->addr, arvif->vdev_id, err); | |
2644 | ||
2645 | if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) | |
2646 | ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n", | |
2647 | sta->addr, arvif->vdev_id); | |
2648 | } | |
2649 | } | |
2650 | ||
2651 | mutex_unlock(&ar->conf_mutex); | |
2652 | } | |
2653 | ||
2654 | static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif, | |
2655 | struct ieee80211_sta *sta) | |
2656 | { | |
2657 | struct ath11k *ar = arvif->ar; | |
2658 | ||
2659 | lockdep_assert_held(&ar->conf_mutex); | |
2660 | ||
2661 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) | |
2662 | return 0; | |
2663 | ||
2664 | if (ar->num_stations >= ar->max_num_stations) | |
2665 | return -ENOBUFS; | |
2666 | ||
2667 | ar->num_stations++; | |
2668 | ||
2669 | return 0; | |
2670 | } | |
2671 | ||
2672 | static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif, | |
2673 | struct ieee80211_sta *sta) | |
2674 | { | |
2675 | struct ath11k *ar = arvif->ar; | |
2676 | ||
2677 | lockdep_assert_held(&ar->conf_mutex); | |
2678 | ||
2679 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) | |
2680 | return; | |
2681 | ||
2682 | ar->num_stations--; | |
2683 | } | |
2684 | ||
5e971287 KP |
2685 | static int ath11k_mac_station_add(struct ath11k *ar, |
2686 | struct ieee80211_vif *vif, | |
2687 | struct ieee80211_sta *sta) | |
2688 | { | |
2689 | struct ath11k_base *ab = ar->ab; | |
2690 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2691 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
2692 | struct peer_create_params peer_param; | |
2693 | int ret; | |
2694 | ||
2695 | lockdep_assert_held(&ar->conf_mutex); | |
2696 | ||
2697 | ret = ath11k_mac_inc_num_stations(arvif, sta); | |
2698 | if (ret) { | |
2699 | ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n", | |
2700 | ar->max_num_stations); | |
2701 | goto exit; | |
2702 | } | |
2703 | ||
2704 | arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL); | |
2705 | if (!arsta->rx_stats) { | |
2706 | ret = -ENOMEM; | |
2707 | goto dec_num_station; | |
2708 | } | |
2709 | ||
2710 | peer_param.vdev_id = arvif->vdev_id; | |
2711 | peer_param.peer_addr = sta->addr; | |
2712 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
2713 | ||
2714 | ret = ath11k_peer_create(ar, arvif, sta, &peer_param); | |
2715 | if (ret) { | |
2716 | ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n", | |
2717 | sta->addr, arvif->vdev_id); | |
2718 | goto free_rx_stats; | |
2719 | } | |
2720 | ||
2721 | ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n", | |
2722 | sta->addr, arvif->vdev_id); | |
2723 | ||
2724 | if (ath11k_debug_is_extd_tx_stats_enabled(ar)) { | |
2725 | arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL); | |
2726 | if (!arsta->tx_stats) { | |
2727 | ret = -ENOMEM; | |
2728 | goto free_peer; | |
2729 | } | |
2730 | } | |
2731 | ||
2732 | if (ieee80211_vif_is_mesh(vif)) { | |
2733 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, | |
2734 | arvif->vdev_id, | |
2735 | WMI_PEER_USE_4ADDR, 1); | |
2736 | if (ret) { | |
2737 | ath11k_warn(ab, "failed to STA %pM 4addr capability: %d\n", | |
2738 | sta->addr, ret); | |
2739 | goto free_tx_stats; | |
2740 | } | |
2741 | } | |
2742 | ||
2743 | ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr); | |
2744 | if (ret) { | |
2745 | ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n", | |
2746 | sta->addr, arvif->vdev_id, ret); | |
2747 | goto free_tx_stats; | |
2748 | } | |
2749 | ||
2750 | return 0; | |
2751 | ||
2752 | free_tx_stats: | |
2753 | kfree(arsta->tx_stats); | |
2754 | arsta->tx_stats = NULL; | |
2755 | free_peer: | |
2756 | ath11k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
2757 | free_rx_stats: | |
2758 | kfree(arsta->rx_stats); | |
2759 | arsta->rx_stats = NULL; | |
2760 | dec_num_station: | |
2761 | ath11k_mac_dec_num_stations(arvif, sta); | |
2762 | exit: | |
2763 | return ret; | |
2764 | } | |
2765 | ||
d5c65159 KV |
2766 | static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw, |
2767 | struct ieee80211_vif *vif, | |
2768 | struct ieee80211_sta *sta, | |
2769 | enum ieee80211_sta_state old_state, | |
2770 | enum ieee80211_sta_state new_state) | |
2771 | { | |
2772 | struct ath11k *ar = hw->priv; | |
2773 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2774 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
d5c65159 KV |
2775 | int ret = 0; |
2776 | ||
2777 | /* cancel must be done outside the mutex to avoid deadlock */ | |
2778 | if ((old_state == IEEE80211_STA_NONE && | |
2779 | new_state == IEEE80211_STA_NOTEXIST)) | |
2780 | cancel_work_sync(&arsta->update_wk); | |
2781 | ||
2782 | mutex_lock(&ar->conf_mutex); | |
2783 | ||
2784 | if (old_state == IEEE80211_STA_NOTEXIST && | |
2785 | new_state == IEEE80211_STA_NONE) { | |
2786 | memset(arsta, 0, sizeof(*arsta)); | |
2787 | arsta->arvif = arvif; | |
2788 | INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk); | |
2789 | ||
5e971287 KP |
2790 | ret = ath11k_mac_station_add(ar, vif, sta); |
2791 | if (ret) | |
2792 | ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n", | |
d5c65159 | 2793 | sta->addr, arvif->vdev_id); |
d5c65159 KV |
2794 | } else if ((old_state == IEEE80211_STA_NONE && |
2795 | new_state == IEEE80211_STA_NOTEXIST)) { | |
2796 | ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr); | |
2797 | ||
2798 | ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr); | |
2799 | if (ret) | |
2800 | ath11k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n", | |
2801 | sta->addr, arvif->vdev_id); | |
2802 | else | |
5e971287 KP |
2803 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n", |
2804 | sta->addr, arvif->vdev_id); | |
d5c65159 KV |
2805 | |
2806 | ath11k_mac_dec_num_stations(arvif, sta); | |
2807 | ||
2808 | kfree(arsta->tx_stats); | |
2809 | arsta->tx_stats = NULL; | |
2810 | ||
2811 | kfree(arsta->rx_stats); | |
2812 | arsta->rx_stats = NULL; | |
2813 | } else if (old_state == IEEE80211_STA_AUTH && | |
2814 | new_state == IEEE80211_STA_ASSOC && | |
2815 | (vif->type == NL80211_IFTYPE_AP || | |
2816 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
2817 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
2818 | ret = ath11k_station_assoc(ar, vif, sta, false); | |
2819 | if (ret) | |
2820 | ath11k_warn(ar->ab, "Failed to associate station: %pM\n", | |
2821 | sta->addr); | |
2822 | else | |
2823 | ath11k_info(ar->ab, | |
2824 | "Station %pM moved to assoc state\n", | |
2825 | sta->addr); | |
2826 | } else if (old_state == IEEE80211_STA_ASSOC && | |
2827 | new_state == IEEE80211_STA_AUTH && | |
2828 | (vif->type == NL80211_IFTYPE_AP || | |
2829 | vif->type == NL80211_IFTYPE_MESH_POINT || | |
2830 | vif->type == NL80211_IFTYPE_ADHOC)) { | |
2831 | ret = ath11k_station_disassoc(ar, vif, sta); | |
2832 | if (ret) | |
2833 | ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n", | |
2834 | sta->addr); | |
2835 | else | |
2836 | ath11k_info(ar->ab, | |
2837 | "Station %pM moved to disassociated state\n", | |
2838 | sta->addr); | |
2839 | } | |
2840 | ||
d5c65159 KV |
2841 | mutex_unlock(&ar->conf_mutex); |
2842 | return ret; | |
2843 | } | |
2844 | ||
64f1d7e9 MK |
2845 | static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw, |
2846 | struct ieee80211_vif *vif, | |
2847 | struct ieee80211_sta *sta) | |
2848 | { | |
2849 | struct ath11k *ar = hw->priv; | |
2850 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
2851 | int ret = 0; | |
2852 | s16 txpwr; | |
2853 | ||
2854 | if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) { | |
2855 | txpwr = 0; | |
2856 | } else { | |
2857 | txpwr = sta->txpwr.power; | |
2858 | if (!txpwr) | |
2859 | return -EINVAL; | |
2860 | } | |
2861 | ||
2862 | if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL) | |
2863 | return -EINVAL; | |
2864 | ||
2865 | mutex_lock(&ar->conf_mutex); | |
2866 | ||
2867 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id, | |
2868 | WMI_PEER_USE_FIXED_PWR, txpwr); | |
2869 | if (ret) { | |
2870 | ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n", | |
2871 | ret); | |
2872 | goto out; | |
2873 | } | |
2874 | ||
2875 | out: | |
2876 | mutex_unlock(&ar->conf_mutex); | |
2877 | return ret; | |
2878 | } | |
2879 | ||
d5c65159 KV |
2880 | static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw, |
2881 | struct ieee80211_vif *vif, | |
2882 | struct ieee80211_sta *sta, | |
2883 | u32 changed) | |
2884 | { | |
2885 | struct ath11k *ar = hw->priv; | |
2886 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
2887 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
2888 | struct ath11k_peer *peer; | |
2889 | u32 bw, smps; | |
2890 | ||
2891 | spin_lock_bh(&ar->ab->base_lock); | |
2892 | ||
2893 | peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr); | |
2894 | if (!peer) { | |
2895 | spin_unlock_bh(&ar->ab->base_lock); | |
2896 | ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n", | |
2897 | sta->addr, arvif->vdev_id); | |
2898 | return; | |
2899 | } | |
2900 | ||
2901 | spin_unlock_bh(&ar->ab->base_lock); | |
2902 | ||
2903 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
2904 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", | |
2905 | sta->addr, changed, sta->bandwidth, sta->rx_nss, | |
2906 | sta->smps_mode); | |
2907 | ||
2908 | spin_lock_bh(&ar->data_lock); | |
2909 | ||
2910 | if (changed & IEEE80211_RC_BW_CHANGED) { | |
2911 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
2912 | ||
2913 | switch (sta->bandwidth) { | |
2914 | case IEEE80211_STA_RX_BW_20: | |
2915 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
2916 | break; | |
2917 | case IEEE80211_STA_RX_BW_40: | |
2918 | bw = WMI_PEER_CHWIDTH_40MHZ; | |
2919 | break; | |
2920 | case IEEE80211_STA_RX_BW_80: | |
2921 | bw = WMI_PEER_CHWIDTH_80MHZ; | |
2922 | break; | |
2923 | case IEEE80211_STA_RX_BW_160: | |
2924 | bw = WMI_PEER_CHWIDTH_160MHZ; | |
2925 | break; | |
2926 | default: | |
2927 | ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n", | |
2928 | sta->bandwidth, sta->addr); | |
2929 | bw = WMI_PEER_CHWIDTH_20MHZ; | |
2930 | break; | |
2931 | } | |
2932 | ||
2933 | arsta->bw = bw; | |
2934 | } | |
2935 | ||
2936 | if (changed & IEEE80211_RC_NSS_CHANGED) | |
2937 | arsta->nss = sta->rx_nss; | |
2938 | ||
2939 | if (changed & IEEE80211_RC_SMPS_CHANGED) { | |
2940 | smps = WMI_PEER_SMPS_PS_NONE; | |
2941 | ||
2942 | switch (sta->smps_mode) { | |
2943 | case IEEE80211_SMPS_AUTOMATIC: | |
2944 | case IEEE80211_SMPS_OFF: | |
2945 | smps = WMI_PEER_SMPS_PS_NONE; | |
2946 | break; | |
2947 | case IEEE80211_SMPS_STATIC: | |
2948 | smps = WMI_PEER_SMPS_STATIC; | |
2949 | break; | |
2950 | case IEEE80211_SMPS_DYNAMIC: | |
2951 | smps = WMI_PEER_SMPS_DYNAMIC; | |
2952 | break; | |
2953 | default: | |
2954 | ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n", | |
2955 | sta->smps_mode, sta->addr); | |
2956 | smps = WMI_PEER_SMPS_PS_NONE; | |
2957 | break; | |
2958 | } | |
2959 | ||
2960 | arsta->smps = smps; | |
2961 | } | |
2962 | ||
2963 | arsta->changed |= changed; | |
2964 | ||
2965 | spin_unlock_bh(&ar->data_lock); | |
2966 | ||
2967 | ieee80211_queue_work(hw, &arsta->update_wk); | |
2968 | } | |
2969 | ||
2970 | static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif, | |
2971 | u16 ac, bool enable) | |
2972 | { | |
2973 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
2974 | u32 value = 0; | |
2975 | int ret = 0; | |
2976 | ||
2977 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) | |
2978 | return 0; | |
2979 | ||
2980 | switch (ac) { | |
2981 | case IEEE80211_AC_VO: | |
2982 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | | |
2983 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; | |
2984 | break; | |
2985 | case IEEE80211_AC_VI: | |
2986 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | | |
2987 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; | |
2988 | break; | |
2989 | case IEEE80211_AC_BE: | |
2990 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | | |
2991 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; | |
2992 | break; | |
2993 | case IEEE80211_AC_BK: | |
2994 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | | |
2995 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; | |
2996 | break; | |
2997 | } | |
2998 | ||
2999 | if (enable) | |
3000 | arvif->u.sta.uapsd |= value; | |
3001 | else | |
3002 | arvif->u.sta.uapsd &= ~value; | |
3003 | ||
3004 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3005 | WMI_STA_PS_PARAM_UAPSD, | |
3006 | arvif->u.sta.uapsd); | |
3007 | if (ret) { | |
3008 | ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret); | |
3009 | goto exit; | |
3010 | } | |
3011 | ||
3012 | if (arvif->u.sta.uapsd) | |
3013 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; | |
3014 | else | |
3015 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
3016 | ||
3017 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
3018 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, | |
3019 | value); | |
3020 | if (ret) | |
3021 | ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret); | |
3022 | ||
3023 | exit: | |
3024 | return ret; | |
3025 | } | |
3026 | ||
3027 | static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw, | |
3028 | struct ieee80211_vif *vif, u16 ac, | |
3029 | const struct ieee80211_tx_queue_params *params) | |
3030 | { | |
3031 | struct ath11k *ar = hw->priv; | |
3032 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
3033 | struct wmi_wmm_params_arg *p = NULL; | |
3034 | int ret; | |
3035 | ||
3036 | mutex_lock(&ar->conf_mutex); | |
3037 | ||
3038 | switch (ac) { | |
3039 | case IEEE80211_AC_VO: | |
3040 | p = &arvif->wmm_params.ac_vo; | |
3041 | break; | |
3042 | case IEEE80211_AC_VI: | |
3043 | p = &arvif->wmm_params.ac_vi; | |
3044 | break; | |
3045 | case IEEE80211_AC_BE: | |
3046 | p = &arvif->wmm_params.ac_be; | |
3047 | break; | |
3048 | case IEEE80211_AC_BK: | |
3049 | p = &arvif->wmm_params.ac_bk; | |
3050 | break; | |
3051 | } | |
3052 | ||
3053 | if (WARN_ON(!p)) { | |
3054 | ret = -EINVAL; | |
3055 | goto exit; | |
3056 | } | |
3057 | ||
3058 | p->cwmin = params->cw_min; | |
3059 | p->cwmax = params->cw_max; | |
3060 | p->aifs = params->aifs; | |
f425078b | 3061 | p->txop = params->txop; |
d5c65159 KV |
3062 | |
3063 | ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id, | |
3064 | &arvif->wmm_params); | |
3065 | if (ret) { | |
3066 | ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret); | |
3067 | goto exit; | |
3068 | } | |
3069 | ||
3070 | ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd); | |
3071 | ||
3072 | if (ret) | |
3073 | ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret); | |
3074 | ||
3075 | exit: | |
3076 | mutex_unlock(&ar->conf_mutex); | |
3077 | return ret; | |
3078 | } | |
3079 | ||
3080 | static struct ieee80211_sta_ht_cap | |
3081 | ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask) | |
3082 | { | |
3083 | int i; | |
3084 | struct ieee80211_sta_ht_cap ht_cap = {0}; | |
3085 | u32 ar_vht_cap = ar->pdev->cap.vht_cap; | |
3086 | ||
3087 | if (!(ar_ht_cap & WMI_HT_CAP_ENABLED)) | |
3088 | return ht_cap; | |
3089 | ||
3090 | ht_cap.ht_supported = 1; | |
3091 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
c000e56e | 3092 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; |
d5c65159 KV |
3093 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
3094 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; | |
3095 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; | |
3096 | ||
3097 | if (ar_ht_cap & WMI_HT_CAP_HT20_SGI) | |
3098 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; | |
3099 | ||
3100 | if (ar_ht_cap & WMI_HT_CAP_HT40_SGI) | |
3101 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; | |
3102 | ||
3103 | if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) { | |
3104 | u32 smps; | |
3105 | ||
3106 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | |
3107 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | |
3108 | ||
3109 | ht_cap.cap |= smps; | |
3110 | } | |
3111 | ||
3112 | if (ar_ht_cap & WMI_HT_CAP_TX_STBC) | |
3113 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; | |
3114 | ||
3115 | if (ar_ht_cap & WMI_HT_CAP_RX_STBC) { | |
3116 | u32 stbc; | |
3117 | ||
3118 | stbc = ar_ht_cap; | |
3119 | stbc &= WMI_HT_CAP_RX_STBC; | |
3120 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; | |
3121 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; | |
3122 | stbc &= IEEE80211_HT_CAP_RX_STBC; | |
3123 | ||
3124 | ht_cap.cap |= stbc; | |
3125 | } | |
3126 | ||
3127 | if (ar_ht_cap & WMI_HT_CAP_RX_LDPC) | |
3128 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; | |
3129 | ||
3130 | if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT) | |
3131 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; | |
3132 | ||
3133 | if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) | |
3134 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; | |
3135 | ||
3136 | for (i = 0; i < ar->num_rx_chains; i++) { | |
3137 | if (rate_cap_rx_chainmask & BIT(i)) | |
3138 | ht_cap.mcs.rx_mask[i] = 0xFF; | |
3139 | } | |
3140 | ||
3141 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; | |
3142 | ||
3143 | return ht_cap; | |
3144 | } | |
3145 | ||
3146 | static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif) | |
3147 | { | |
3148 | u32 value = 0; | |
3149 | struct ath11k *ar = arvif->ar; | |
3150 | int nsts; | |
3151 | int sound_dim; | |
3152 | u32 vht_cap = ar->pdev->cap.vht_cap; | |
3153 | u32 vdev_param = WMI_VDEV_PARAM_TXBF; | |
3154 | ||
3155 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) { | |
3156 | nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; | |
3157 | nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; | |
3158 | value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); | |
3159 | } | |
3160 | ||
3161 | if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { | |
3162 | sound_dim = vht_cap & | |
3163 | IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3164 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3165 | if (sound_dim > (ar->num_tx_chains - 1)) | |
3166 | sound_dim = ar->num_tx_chains - 1; | |
3167 | value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); | |
3168 | } | |
3169 | ||
3170 | if (!value) | |
3171 | return 0; | |
3172 | ||
3173 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) { | |
3174 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; | |
3175 | ||
3176 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && | |
3177 | arvif->vdev_type == WMI_VDEV_TYPE_AP) | |
3178 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; | |
3179 | } | |
3180 | ||
3181 | /* TODO: SUBFEE not validated in HK, disable here until validated? */ | |
3182 | ||
3183 | if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) { | |
3184 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; | |
3185 | ||
3186 | if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && | |
3187 | arvif->vdev_type == WMI_VDEV_TYPE_STA) | |
3188 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; | |
3189 | } | |
3190 | ||
3191 | return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3192 | vdev_param, value); | |
3193 | } | |
3194 | ||
3195 | static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap) | |
3196 | { | |
3197 | bool subfer, subfee; | |
3198 | int sound_dim = 0; | |
3199 | ||
3200 | subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)); | |
3201 | subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)); | |
3202 | ||
3203 | if (ar->num_tx_chains < 2) { | |
3204 | *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); | |
3205 | subfer = false; | |
3206 | } | |
3207 | ||
3208 | /* If SU Beaformer is not set, then disable MU Beamformer Capability */ | |
3209 | if (!subfer) | |
3210 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); | |
3211 | ||
3212 | /* If SU Beaformee is not set, then disable MU Beamformee Capability */ | |
3213 | if (!subfee) | |
3214 | *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); | |
3215 | ||
3216 | sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK); | |
3217 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3218 | *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3219 | ||
3220 | /* TODO: Need to check invalid STS and Sound_dim values set by FW? */ | |
3221 | ||
3222 | /* Enable Sounding Dimension Field only if SU BF is enabled */ | |
3223 | if (subfer) { | |
3224 | if (sound_dim > (ar->num_tx_chains - 1)) | |
3225 | sound_dim = ar->num_tx_chains - 1; | |
3226 | ||
3227 | sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; | |
3228 | sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; | |
3229 | *vht_cap |= sound_dim; | |
3230 | } | |
3231 | ||
3232 | /* Use the STS advertised by FW unless SU Beamformee is not supported*/ | |
3233 | if (!subfee) | |
3234 | *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK); | |
3235 | } | |
3236 | ||
3237 | static struct ieee80211_sta_vht_cap | |
3238 | ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask, | |
3239 | u32 rate_cap_rx_chainmask) | |
3240 | { | |
3241 | struct ieee80211_sta_vht_cap vht_cap = {0}; | |
3242 | u16 txmcs_map, rxmcs_map; | |
3243 | int i; | |
3244 | ||
3245 | vht_cap.vht_supported = 1; | |
3246 | vht_cap.cap = ar->pdev->cap.vht_cap; | |
3247 | ||
3248 | ath11k_set_vht_txbf_cap(ar, &vht_cap.cap); | |
3249 | ||
3250 | /* TODO: Enable back VHT160 mode once association issues are fixed */ | |
3251 | /* Disabling VHT160 and VHT80+80 modes */ | |
3252 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; | |
3253 | vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; | |
3254 | ||
3255 | rxmcs_map = 0; | |
3256 | txmcs_map = 0; | |
3257 | for (i = 0; i < 8; i++) { | |
3258 | if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i)) | |
3259 | txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
3260 | else | |
3261 | txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
3262 | ||
3263 | if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i)) | |
3264 | rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); | |
3265 | else | |
3266 | rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); | |
3267 | } | |
3268 | ||
3269 | if (rate_cap_tx_chainmask <= 1) | |
3270 | vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; | |
3271 | ||
3272 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map); | |
3273 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map); | |
3274 | ||
3275 | return vht_cap; | |
3276 | } | |
3277 | ||
3278 | static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar, | |
3279 | struct ath11k_pdev_cap *cap, | |
3280 | u32 *ht_cap_info) | |
3281 | { | |
3282 | struct ieee80211_supported_band *band; | |
3283 | u32 rate_cap_tx_chainmask; | |
3284 | u32 rate_cap_rx_chainmask; | |
3285 | u32 ht_cap; | |
3286 | ||
3287 | rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift; | |
3288 | rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift; | |
3289 | ||
3290 | if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
3291 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
3292 | ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info; | |
3293 | if (ht_cap_info) | |
3294 | *ht_cap_info = ht_cap; | |
3295 | band->ht_cap = ath11k_create_ht_cap(ar, ht_cap, | |
3296 | rate_cap_rx_chainmask); | |
3297 | } | |
3298 | ||
3299 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
3300 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
3301 | ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info; | |
3302 | if (ht_cap_info) | |
3303 | *ht_cap_info = ht_cap; | |
3304 | band->ht_cap = ath11k_create_ht_cap(ar, ht_cap, | |
3305 | rate_cap_rx_chainmask); | |
3306 | band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask, | |
3307 | rate_cap_rx_chainmask); | |
3308 | } | |
3309 | } | |
3310 | ||
3311 | static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant) | |
3312 | { | |
3313 | /* TODO: Check the request chainmask against the supported | |
3314 | * chainmask table which is advertised in extented_service_ready event | |
3315 | */ | |
3316 | ||
3317 | return 0; | |
3318 | } | |
3319 | ||
9f056ed8 JC |
3320 | static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet, |
3321 | u8 *he_ppet) | |
3322 | { | |
3323 | int nss, ru; | |
3324 | u8 bit = 7; | |
3325 | ||
3326 | he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK; | |
3327 | he_ppet[0] |= (fw_ppet->ru_bit_mask << | |
3328 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) & | |
3329 | IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK; | |
3330 | for (nss = 0; nss <= fw_ppet->numss_m1; nss++) { | |
3331 | for (ru = 0; ru < 4; ru++) { | |
3332 | u8 val; | |
3333 | int i; | |
3334 | ||
3335 | if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0) | |
3336 | continue; | |
3337 | val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) & | |
3338 | 0x3f; | |
3339 | val = ((val >> 3) & 0x7) | ((val & 0x7) << 3); | |
3340 | for (i = 5; i >= 0; i--) { | |
3341 | he_ppet[bit / 8] |= | |
3342 | ((val >> i) & 0x1) << ((bit % 8)); | |
3343 | bit++; | |
3344 | } | |
3345 | } | |
3346 | } | |
3347 | } | |
3348 | ||
13591a1c SE |
3349 | static void |
3350 | ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem) | |
3351 | { | |
3352 | u8 m; | |
3353 | ||
3354 | m = IEEE80211_HE_MAC_CAP0_TWT_RES | | |
3355 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
3356 | he_cap_elem->mac_cap_info[0] &= ~m; | |
3357 | ||
3358 | m = IEEE80211_HE_MAC_CAP2_TRS | | |
3359 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
3360 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
3361 | he_cap_elem->mac_cap_info[2] &= ~m; | |
3362 | ||
3363 | m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED | | |
3364 | IEEE80211_HE_MAC_CAP2_BCAST_TWT | | |
3365 | IEEE80211_HE_MAC_CAP2_MU_CASCADING; | |
3366 | he_cap_elem->mac_cap_info[3] &= ~m; | |
3367 | ||
3368 | m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG | | |
3369 | IEEE80211_HE_MAC_CAP4_BQR; | |
3370 | he_cap_elem->mac_cap_info[4] &= ~m; | |
3371 | ||
3372 | m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECVITE_TRANSMISSION | | |
3373 | IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU | | |
3374 | IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING | | |
3375 | IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX; | |
3376 | he_cap_elem->mac_cap_info[5] &= ~m; | |
3377 | ||
3378 | m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
3379 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; | |
3380 | he_cap_elem->phy_cap_info[2] &= ~m; | |
3381 | ||
3382 | m = IEEE80211_HE_PHY_CAP3_RX_HE_MU_PPDU_FROM_NON_AP_STA | | |
3383 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK | | |
3384 | IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK; | |
3385 | he_cap_elem->phy_cap_info[3] &= ~m; | |
3386 | ||
3387 | m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; | |
3388 | he_cap_elem->phy_cap_info[4] &= ~m; | |
3389 | ||
3390 | m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK; | |
3391 | he_cap_elem->phy_cap_info[5] &= ~m; | |
3392 | ||
3393 | m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU | | |
3394 | IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB | | |
3395 | IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | | |
3396 | IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; | |
3397 | he_cap_elem->phy_cap_info[6] &= ~m; | |
3398 | ||
3399 | m = IEEE80211_HE_PHY_CAP7_SRP_BASED_SR | | |
3400 | IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR | | |
3401 | IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ | | |
3402 | IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ; | |
3403 | he_cap_elem->phy_cap_info[7] &= ~m; | |
3404 | ||
3405 | m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI | | |
3406 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | | |
3407 | IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | | |
3408 | IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU; | |
3409 | he_cap_elem->phy_cap_info[8] &= ~m; | |
3410 | ||
3411 | m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | | |
3412 | IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | | |
3413 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | | |
3414 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | | |
3415 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | | |
3416 | IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; | |
3417 | he_cap_elem->phy_cap_info[9] &= ~m; | |
3418 | } | |
3419 | ||
9f056ed8 JC |
3420 | static int ath11k_mac_copy_he_cap(struct ath11k *ar, |
3421 | struct ath11k_pdev_cap *cap, | |
3422 | struct ieee80211_sband_iftype_data *data, | |
3423 | int band) | |
3424 | { | |
3425 | int i, idx = 0; | |
3426 | ||
3427 | for (i = 0; i < NUM_NL80211_IFTYPES; i++) { | |
3428 | struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; | |
3429 | struct ath11k_band_cap *band_cap = &cap->band[band]; | |
3430 | struct ieee80211_he_cap_elem *he_cap_elem = | |
3431 | &he_cap->he_cap_elem; | |
3432 | ||
3433 | switch (i) { | |
3434 | case NL80211_IFTYPE_STATION: | |
3435 | case NL80211_IFTYPE_AP: | |
13591a1c | 3436 | case NL80211_IFTYPE_MESH_POINT: |
9f056ed8 JC |
3437 | break; |
3438 | ||
3439 | default: | |
3440 | continue; | |
3441 | } | |
3442 | ||
3443 | data[idx].types_mask = BIT(i); | |
3444 | he_cap->has_he = true; | |
3445 | memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info, | |
3446 | sizeof(he_cap_elem->mac_cap_info)); | |
3447 | memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info, | |
3448 | sizeof(he_cap_elem->phy_cap_info)); | |
3449 | ||
3450 | he_cap_elem->mac_cap_info[1] |= | |
3451 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK; | |
3452 | he_cap_elem->phy_cap_info[4] &= | |
3453 | ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK; | |
3454 | he_cap_elem->phy_cap_info[4] &= | |
3455 | ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK; | |
3456 | he_cap_elem->phy_cap_info[4] |= (ar->num_tx_chains - 1) << 2; | |
3457 | ||
3458 | he_cap_elem->phy_cap_info[5] &= | |
3459 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK; | |
3460 | he_cap_elem->phy_cap_info[5] &= | |
3461 | ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK; | |
3462 | he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1; | |
3463 | ||
3464 | switch (i) { | |
3465 | case NL80211_IFTYPE_AP: | |
3466 | he_cap_elem->phy_cap_info[9] |= | |
3467 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU; | |
3468 | break; | |
3469 | case NL80211_IFTYPE_STATION: | |
3470 | he_cap_elem->mac_cap_info[0] &= | |
3471 | ~IEEE80211_HE_MAC_CAP0_TWT_RES; | |
3472 | he_cap_elem->mac_cap_info[0] |= | |
3473 | IEEE80211_HE_MAC_CAP0_TWT_REQ; | |
3474 | he_cap_elem->phy_cap_info[9] |= | |
3475 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU; | |
3476 | break; | |
13591a1c SE |
3477 | case NL80211_IFTYPE_MESH_POINT: |
3478 | ath11k_mac_filter_he_cap_mesh(he_cap_elem); | |
3479 | break; | |
9f056ed8 JC |
3480 | } |
3481 | ||
3482 | he_cap->he_mcs_nss_supp.rx_mcs_80 = | |
3483 | cpu_to_le16(band_cap->he_mcs & 0xffff); | |
3484 | he_cap->he_mcs_nss_supp.tx_mcs_80 = | |
3485 | cpu_to_le16(band_cap->he_mcs & 0xffff); | |
3486 | he_cap->he_mcs_nss_supp.rx_mcs_160 = | |
3487 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3488 | he_cap->he_mcs_nss_supp.tx_mcs_160 = | |
3489 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3490 | he_cap->he_mcs_nss_supp.rx_mcs_80p80 = | |
3491 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3492 | he_cap->he_mcs_nss_supp.tx_mcs_80p80 = | |
3493 | cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff); | |
3494 | ||
3495 | memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); | |
3496 | if (he_cap_elem->phy_cap_info[6] & | |
3497 | IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) | |
3498 | ath11k_gen_ppe_thresh(&band_cap->he_ppet, | |
3499 | he_cap->ppe_thres); | |
3500 | idx++; | |
3501 | } | |
3502 | ||
3503 | return idx; | |
3504 | } | |
3505 | ||
3506 | static void ath11k_mac_setup_he_cap(struct ath11k *ar, | |
3507 | struct ath11k_pdev_cap *cap) | |
3508 | { | |
3509 | struct ieee80211_supported_band *band = NULL; | |
3510 | int count = 0; | |
3511 | ||
3512 | if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
3513 | count = ath11k_mac_copy_he_cap(ar, cap, | |
3514 | ar->mac.iftype[NL80211_BAND_2GHZ], | |
3515 | NL80211_BAND_2GHZ); | |
3516 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
3517 | band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ]; | |
3518 | } | |
3519 | ||
3520 | if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
3521 | count = ath11k_mac_copy_he_cap(ar, cap, | |
3522 | ar->mac.iftype[NL80211_BAND_5GHZ], | |
3523 | NL80211_BAND_5GHZ); | |
3524 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
3525 | band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ]; | |
3526 | } | |
3527 | ||
3528 | band->n_iftype_data = count; | |
3529 | } | |
3530 | ||
d5c65159 KV |
3531 | static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant) |
3532 | { | |
3533 | int ret; | |
3534 | ||
3535 | lockdep_assert_held(&ar->conf_mutex); | |
3536 | ||
3537 | if (ath11k_check_chain_mask(ar, tx_ant, true)) | |
3538 | return -EINVAL; | |
3539 | ||
3540 | if (ath11k_check_chain_mask(ar, rx_ant, false)) | |
3541 | return -EINVAL; | |
3542 | ||
3543 | ar->cfg_tx_chainmask = tx_ant; | |
3544 | ar->cfg_rx_chainmask = rx_ant; | |
3545 | ||
3546 | if (ar->state != ATH11K_STATE_ON && | |
3547 | ar->state != ATH11K_STATE_RESTARTED) | |
3548 | return 0; | |
3549 | ||
3550 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK, | |
3551 | tx_ant, ar->pdev->pdev_id); | |
3552 | if (ret) { | |
3553 | ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n", | |
3554 | ret, tx_ant); | |
3555 | return ret; | |
3556 | } | |
3557 | ||
a3c5195a S |
3558 | ar->num_tx_chains = get_num_chains(tx_ant); |
3559 | ||
d5c65159 KV |
3560 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK, |
3561 | rx_ant, ar->pdev->pdev_id); | |
3562 | if (ret) { | |
3563 | ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n", | |
3564 | ret, rx_ant); | |
3565 | return ret; | |
3566 | } | |
3567 | ||
a3c5195a S |
3568 | ar->num_rx_chains = get_num_chains(rx_ant); |
3569 | ||
9f056ed8 | 3570 | /* Reload HT/VHT/HE capability */ |
d5c65159 | 3571 | ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL); |
9f056ed8 | 3572 | ath11k_mac_setup_he_cap(ar, &ar->pdev->cap); |
d5c65159 KV |
3573 | |
3574 | return 0; | |
3575 | } | |
3576 | ||
3577 | int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx) | |
3578 | { | |
3579 | struct ath11k *ar = ctx; | |
3580 | struct ath11k_base *ab = ar->ab; | |
3581 | struct sk_buff *msdu = skb; | |
3582 | struct ieee80211_tx_info *info; | |
3583 | ||
3584 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3585 | idr_remove(&ar->txmgmt_idr, buf_id); | |
3586 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3587 | dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len, | |
3588 | DMA_TO_DEVICE); | |
3589 | ||
3590 | info = IEEE80211_SKB_CB(msdu); | |
3591 | memset(&info->status, 0, sizeof(info->status)); | |
3592 | ||
3593 | ieee80211_free_txskb(ar->hw, msdu); | |
3594 | ||
3595 | return 0; | |
3596 | } | |
3597 | ||
3598 | static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx) | |
3599 | { | |
3600 | struct ieee80211_vif *vif = ctx; | |
3601 | struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb); | |
3602 | struct sk_buff *msdu = skb; | |
3603 | struct ath11k *ar = skb_cb->ar; | |
3604 | struct ath11k_base *ab = ar->ab; | |
3605 | ||
3606 | if (skb_cb->vif == vif) { | |
3607 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3608 | idr_remove(&ar->txmgmt_idr, buf_id); | |
3609 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3610 | dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, | |
3611 | DMA_TO_DEVICE); | |
3612 | } | |
3613 | ||
3614 | return 0; | |
3615 | } | |
3616 | ||
3617 | static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif, | |
3618 | struct sk_buff *skb) | |
3619 | { | |
3620 | struct ath11k_base *ab = ar->ab; | |
3621 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
3622 | dma_addr_t paddr; | |
3623 | int buf_id; | |
3624 | int ret; | |
3625 | ||
3626 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3627 | buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0, | |
3628 | ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC); | |
3629 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3630 | if (buf_id < 0) | |
3631 | return -ENOSPC; | |
3632 | ||
3633 | if ((ieee80211_is_action(hdr->frame_control) || | |
3634 | ieee80211_is_deauth(hdr->frame_control) || | |
3635 | ieee80211_is_disassoc(hdr->frame_control)) && | |
3636 | ieee80211_has_protected(hdr->frame_control)) { | |
3637 | skb_put(skb, IEEE80211_CCMP_MIC_LEN); | |
3638 | } | |
3639 | ||
3640 | paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE); | |
3641 | if (dma_mapping_error(ab->dev, paddr)) { | |
3642 | ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n"); | |
3643 | ret = -EIO; | |
3644 | goto err_free_idr; | |
3645 | } | |
3646 | ||
3647 | ATH11K_SKB_CB(skb)->paddr = paddr; | |
3648 | ||
3649 | ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb); | |
3650 | if (ret) { | |
3651 | ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret); | |
3652 | goto err_unmap_buf; | |
3653 | } | |
3654 | ||
3655 | return 0; | |
3656 | ||
3657 | err_unmap_buf: | |
3658 | dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr, | |
3659 | skb->len, DMA_TO_DEVICE); | |
3660 | err_free_idr: | |
3661 | spin_lock_bh(&ar->txmgmt_idr_lock); | |
3662 | idr_remove(&ar->txmgmt_idr, buf_id); | |
3663 | spin_unlock_bh(&ar->txmgmt_idr_lock); | |
3664 | ||
3665 | return ret; | |
3666 | } | |
3667 | ||
3668 | static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar) | |
3669 | { | |
3670 | struct sk_buff *skb; | |
3671 | ||
3672 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) | |
3673 | ieee80211_free_txskb(ar->hw, skb); | |
3674 | } | |
3675 | ||
3676 | static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work) | |
3677 | { | |
3678 | struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work); | |
3679 | struct ieee80211_tx_info *info; | |
3680 | struct ath11k_vif *arvif; | |
3681 | struct sk_buff *skb; | |
3682 | int ret; | |
3683 | ||
3684 | while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) { | |
3685 | info = IEEE80211_SKB_CB(skb); | |
3686 | arvif = ath11k_vif_to_arvif(info->control.vif); | |
3687 | ||
3688 | ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb); | |
3689 | if (ret) { | |
3690 | ath11k_warn(ar->ab, "failed to transmit management frame %d\n", | |
3691 | ret); | |
3692 | ieee80211_free_txskb(ar->hw, skb); | |
3693 | } else { | |
3694 | atomic_inc(&ar->num_pending_mgmt_tx); | |
3695 | } | |
3696 | } | |
3697 | } | |
3698 | ||
3699 | static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb, | |
3700 | bool is_prb_rsp) | |
3701 | { | |
3702 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; | |
3703 | ||
3704 | if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
3705 | return -ESHUTDOWN; | |
3706 | ||
3707 | /* Drop probe response packets when the pending management tx | |
3708 | * count has reached a certain threshold, so as to prioritize | |
3709 | * other mgmt packets like auth and assoc to be sent on time | |
3710 | * for establishing successful connections. | |
3711 | */ | |
3712 | if (is_prb_rsp && | |
3713 | atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) { | |
3714 | ath11k_warn(ar->ab, | |
3715 | "dropping probe response as pending queue is almost full\n"); | |
3716 | return -ENOSPC; | |
3717 | } | |
3718 | ||
3719 | if (skb_queue_len(q) == ATH11K_TX_MGMT_NUM_PENDING_MAX) { | |
3720 | ath11k_warn(ar->ab, "mgmt tx queue is full\n"); | |
3721 | return -ENOSPC; | |
3722 | } | |
3723 | ||
3724 | skb_queue_tail(q, skb); | |
3725 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); | |
3726 | ||
3727 | return 0; | |
3728 | } | |
3729 | ||
3730 | static void ath11k_mac_op_tx(struct ieee80211_hw *hw, | |
3731 | struct ieee80211_tx_control *control, | |
3732 | struct sk_buff *skb) | |
3733 | { | |
3734 | struct ath11k *ar = hw->priv; | |
3735 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
3736 | struct ieee80211_vif *vif = info->control.vif; | |
3737 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
3738 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
3739 | bool is_prb_rsp; | |
3740 | int ret; | |
3741 | ||
3742 | if (ieee80211_is_mgmt(hdr->frame_control)) { | |
3743 | is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control); | |
3744 | ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp); | |
3745 | if (ret) { | |
3746 | ath11k_warn(ar->ab, "failed to queue management frame %d\n", | |
3747 | ret); | |
3748 | ieee80211_free_txskb(ar->hw, skb); | |
3749 | } | |
3750 | return; | |
3751 | } | |
3752 | ||
3753 | ret = ath11k_dp_tx(ar, arvif, skb); | |
3754 | if (ret) { | |
3755 | ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret); | |
3756 | ieee80211_free_txskb(ar->hw, skb); | |
3757 | } | |
3758 | } | |
3759 | ||
3760 | void ath11k_mac_drain_tx(struct ath11k *ar) | |
3761 | { | |
3762 | /* make sure rcu-protected mac80211 tx path itself is drained */ | |
3763 | synchronize_net(); | |
3764 | ||
3765 | cancel_work_sync(&ar->wmi_mgmt_tx_work); | |
3766 | ath11k_mgmt_over_wmi_tx_purge(ar); | |
3767 | } | |
3768 | ||
3769 | static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable) | |
3770 | { | |
3771 | struct htt_rx_ring_tlv_filter tlv_filter = {0}; | |
3772 | u32 ring_id; | |
3773 | ||
3774 | if (enable) | |
3775 | tlv_filter = ath11k_mac_mon_status_filter_default; | |
3776 | ||
3777 | ring_id = ar->dp.rx_mon_status_refill_ring.refill_buf_ring.ring_id; | |
3778 | ||
3779 | return ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id, ar->dp.mac_id, | |
3780 | HAL_RXDMA_MONITOR_STATUS, | |
3781 | DP_RX_BUFFER_SIZE, &tlv_filter); | |
3782 | } | |
3783 | ||
3784 | static int ath11k_mac_op_start(struct ieee80211_hw *hw) | |
3785 | { | |
3786 | struct ath11k *ar = hw->priv; | |
3787 | struct ath11k_base *ab = ar->ab; | |
3788 | struct ath11k_pdev *pdev = ar->pdev; | |
3789 | int ret; | |
3790 | ||
3791 | ath11k_mac_drain_tx(ar); | |
3792 | mutex_lock(&ar->conf_mutex); | |
3793 | ||
3794 | switch (ar->state) { | |
3795 | case ATH11K_STATE_OFF: | |
3796 | ar->state = ATH11K_STATE_ON; | |
3797 | break; | |
3798 | case ATH11K_STATE_RESTARTING: | |
3799 | ar->state = ATH11K_STATE_RESTARTED; | |
3800 | break; | |
3801 | case ATH11K_STATE_RESTARTED: | |
3802 | case ATH11K_STATE_WEDGED: | |
3803 | case ATH11K_STATE_ON: | |
3804 | WARN_ON(1); | |
3805 | ret = -EINVAL; | |
3806 | goto err; | |
3807 | } | |
3808 | ||
3809 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, | |
3810 | 1, pdev->pdev_id); | |
3811 | ||
3812 | if (ret) { | |
3813 | ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret); | |
3814 | goto err; | |
3815 | } | |
3816 | ||
3817 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1, | |
3818 | pdev->pdev_id); | |
3819 | if (ret) { | |
3820 | ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret); | |
3821 | goto err; | |
3822 | } | |
3823 | ||
3824 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE, | |
3825 | 0, pdev->pdev_id); | |
3826 | if (ret) { | |
3827 | ath11k_err(ab, "failed to set ac override for ARP: %d\n", | |
3828 | ret); | |
3829 | goto err; | |
3830 | } | |
3831 | ||
3832 | ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id); | |
3833 | if (ret) { | |
3834 | ath11k_err(ab, "failed to offload radar detection: %d\n", | |
3835 | ret); | |
3836 | goto err; | |
3837 | } | |
3838 | ||
3839 | ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar, | |
3840 | HTT_PPDU_STATS_TAG_DEFAULT); | |
3841 | if (ret) { | |
3842 | ath11k_err(ab, "failed to req ppdu stats: %d\n", ret); | |
3843 | goto err; | |
3844 | } | |
3845 | ||
3846 | ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE, | |
3847 | 1, pdev->pdev_id); | |
3848 | ||
3849 | if (ret) { | |
3850 | ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret); | |
3851 | goto err; | |
3852 | } | |
3853 | ||
3854 | __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); | |
3855 | ||
3856 | /* TODO: Do we need to enable ANI? */ | |
3857 | ||
3858 | ath11k_reg_update_chan_list(ar); | |
3859 | ||
3860 | ar->num_started_vdevs = 0; | |
3861 | ar->num_created_vdevs = 0; | |
3862 | ar->num_peers = 0; | |
3863 | ||
3864 | /* Configure monitor status ring with default rx_filter to get rx status | |
3865 | * such as rssi, rx_duration. | |
3866 | */ | |
3867 | ret = ath11k_mac_config_mon_status_default(ar, true); | |
3868 | if (ret) { | |
3869 | ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n", | |
3870 | ret); | |
3871 | goto err; | |
3872 | } | |
3873 | ||
3874 | mutex_unlock(&ar->conf_mutex); | |
3875 | ||
3876 | rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], | |
3877 | &ab->pdevs[ar->pdev_idx]); | |
3878 | ||
3879 | return 0; | |
3880 | ||
3881 | err: | |
3882 | ar->state = ATH11K_STATE_OFF; | |
3883 | mutex_unlock(&ar->conf_mutex); | |
3884 | ||
3885 | return ret; | |
3886 | } | |
3887 | ||
3888 | static void ath11k_mac_op_stop(struct ieee80211_hw *hw) | |
3889 | { | |
3890 | struct ath11k *ar = hw->priv; | |
3891 | struct htt_ppdu_stats_info *ppdu_stats, *tmp; | |
3892 | int ret; | |
3893 | ||
3894 | ath11k_mac_drain_tx(ar); | |
3895 | ||
3896 | mutex_lock(&ar->conf_mutex); | |
3897 | ret = ath11k_mac_config_mon_status_default(ar, false); | |
3898 | if (ret) | |
3899 | ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n", | |
3900 | ret); | |
3901 | ||
3902 | clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags); | |
3903 | ar->state = ATH11K_STATE_OFF; | |
3904 | mutex_unlock(&ar->conf_mutex); | |
3905 | ||
3906 | cancel_delayed_work_sync(&ar->scan.timeout); | |
3907 | cancel_work_sync(&ar->regd_update_work); | |
3908 | ||
3909 | spin_lock_bh(&ar->data_lock); | |
3910 | list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) { | |
3911 | list_del(&ppdu_stats->list); | |
3912 | kfree(ppdu_stats); | |
3913 | } | |
3914 | spin_unlock_bh(&ar->data_lock); | |
3915 | ||
3916 | rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL); | |
3917 | ||
3918 | synchronize_rcu(); | |
3919 | ||
3920 | atomic_set(&ar->num_pending_mgmt_tx, 0); | |
3921 | } | |
3922 | ||
3923 | static void | |
3924 | ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif, | |
3925 | struct vdev_create_params *params) | |
3926 | { | |
3927 | struct ath11k *ar = arvif->ar; | |
3928 | struct ath11k_pdev *pdev = ar->pdev; | |
3929 | ||
3930 | params->if_id = arvif->vdev_id; | |
3931 | params->type = arvif->vdev_type; | |
3932 | params->subtype = arvif->vdev_subtype; | |
3933 | params->pdev_id = pdev->pdev_id; | |
3934 | ||
3935 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
3936 | params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains; | |
3937 | params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains; | |
3938 | } | |
3939 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
3940 | params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains; | |
3941 | params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains; | |
3942 | } | |
3943 | } | |
3944 | ||
3945 | static u32 | |
3946 | ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype) | |
3947 | { | |
3948 | struct ath11k_pdev_cap *pdev_cap = &pdev->cap; | |
3949 | struct ath11k_band_cap *cap_band = NULL; | |
3950 | u32 *hecap_phy_ptr = NULL; | |
3951 | u32 hemode = 0; | |
3952 | ||
3953 | if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) | |
3954 | cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; | |
3955 | else | |
3956 | cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; | |
3957 | ||
3958 | hecap_phy_ptr = &cap_band->he_cap_phy_info[0]; | |
3959 | ||
3960 | hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) | | |
fcaf49d0 JC |
3961 | FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) | |
3962 | FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr)); | |
d5c65159 KV |
3963 | |
3964 | /* TODO WDS and other modes */ | |
3965 | if (viftype == NL80211_IFTYPE_AP) { | |
3966 | hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER, | |
fcaf49d0 JC |
3967 | HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) | |
3968 | FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) | | |
3969 | FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE); | |
d5c65159 KV |
3970 | } else { |
3971 | hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE); | |
3972 | } | |
3973 | ||
3974 | return hemode; | |
3975 | } | |
3976 | ||
3977 | static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar, | |
3978 | struct ath11k_vif *arvif) | |
3979 | { | |
3980 | u32 param_id, param_value; | |
3981 | struct ath11k_base *ab = ar->ab; | |
3982 | int ret = 0; | |
3983 | ||
3984 | param_id = WMI_VDEV_PARAM_SET_HEMU_MODE; | |
3985 | param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type); | |
3986 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3987 | param_id, param_value); | |
3988 | if (ret) { | |
3989 | ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n", | |
3990 | arvif->vdev_id, ret, param_value); | |
3991 | return ret; | |
3992 | } | |
3993 | param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE; | |
3994 | param_value = | |
3995 | FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) | | |
3996 | FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE, | |
3997 | HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE); | |
3998 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
3999 | param_id, param_value); | |
4000 | if (ret) { | |
4001 | ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n", | |
4002 | arvif->vdev_id, ret); | |
4003 | return ret; | |
4004 | } | |
4005 | return ret; | |
4006 | } | |
4007 | ||
4008 | static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw, | |
4009 | struct ieee80211_vif *vif) | |
4010 | { | |
4011 | struct ath11k *ar = hw->priv; | |
4012 | struct ath11k_base *ab = ar->ab; | |
4013 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
4014 | struct vdev_create_params vdev_param = {0}; | |
4015 | struct peer_create_params peer_param; | |
4016 | u32 param_id, param_value; | |
4017 | u16 nss; | |
4018 | int i; | |
4019 | int ret; | |
4020 | int bit; | |
4021 | ||
4022 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; | |
4023 | ||
4024 | mutex_lock(&ar->conf_mutex); | |
4025 | ||
4026 | if (vif->type == NL80211_IFTYPE_AP && | |
4027 | ar->num_peers > (ar->max_num_peers - 1)) { | |
4028 | ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n"); | |
4029 | ret = -ENOBUFS; | |
4030 | goto err; | |
4031 | } | |
4032 | ||
4033 | if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) { | |
4034 | ath11k_warn(ab, "failed to create vdev, reached max vdev limit %d\n", | |
4035 | TARGET_NUM_VDEVS); | |
4036 | ret = -EBUSY; | |
4037 | goto err; | |
4038 | } | |
4039 | ||
4040 | memset(arvif, 0, sizeof(*arvif)); | |
4041 | ||
4042 | arvif->ar = ar; | |
4043 | arvif->vif = vif; | |
4044 | ||
4045 | INIT_LIST_HEAD(&arvif->list); | |
4046 | ||
4047 | /* Should we initialize any worker to handle connection loss indication | |
4048 | * from firmware in sta mode? | |
4049 | */ | |
4050 | ||
4051 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { | |
4052 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; | |
4053 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, | |
4054 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); | |
4055 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, | |
4056 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); | |
4057 | } | |
4058 | ||
4059 | bit = __ffs64(ab->free_vdev_map); | |
4060 | ||
4061 | arvif->vdev_id = bit; | |
4062 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; | |
4063 | ||
4064 | switch (vif->type) { | |
4065 | case NL80211_IFTYPE_UNSPECIFIED: | |
4066 | case NL80211_IFTYPE_STATION: | |
4067 | arvif->vdev_type = WMI_VDEV_TYPE_STA; | |
4068 | break; | |
4069 | case NL80211_IFTYPE_MESH_POINT: | |
4070 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S; | |
4071 | /* fall through */ | |
4072 | case NL80211_IFTYPE_AP: | |
4073 | arvif->vdev_type = WMI_VDEV_TYPE_AP; | |
4074 | break; | |
4075 | case NL80211_IFTYPE_MONITOR: | |
4076 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; | |
4077 | break; | |
4078 | default: | |
4079 | WARN_ON(1); | |
4080 | break; | |
4081 | } | |
4082 | ||
4083 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n", | |
4084 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, | |
4085 | ab->free_vdev_map); | |
4086 | ||
4087 | vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1); | |
4088 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) | |
4089 | vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1); | |
4090 | ||
4091 | ath11k_mac_setup_vdev_create_params(arvif, &vdev_param); | |
4092 | ||
4093 | ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param); | |
4094 | if (ret) { | |
4095 | ath11k_warn(ab, "failed to create WMI vdev %d: %d\n", | |
4096 | arvif->vdev_id, ret); | |
4097 | goto err; | |
4098 | } | |
4099 | ||
4100 | ar->num_created_vdevs++; | |
4101 | ||
4102 | ab->free_vdev_map &= ~(1LL << arvif->vdev_id); | |
4103 | spin_lock_bh(&ar->data_lock); | |
4104 | list_add(&arvif->list, &ar->arvifs); | |
4105 | spin_unlock_bh(&ar->data_lock); | |
4106 | ||
4107 | param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE; | |
4108 | param_value = ATH11K_HW_TXRX_NATIVE_WIFI; | |
4109 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4110 | param_id, param_value); | |
4111 | if (ret) { | |
4112 | ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n", | |
4113 | arvif->vdev_id, ret); | |
4114 | goto err_vdev_del; | |
4115 | } | |
4116 | ||
4117 | nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1; | |
4118 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4119 | WMI_VDEV_PARAM_NSS, nss); | |
4120 | if (ret) { | |
4121 | ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n", | |
4122 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret); | |
4123 | goto err_vdev_del; | |
4124 | } | |
4125 | ||
4126 | switch (arvif->vdev_type) { | |
4127 | case WMI_VDEV_TYPE_AP: | |
4128 | peer_param.vdev_id = arvif->vdev_id; | |
4129 | peer_param.peer_addr = vif->addr; | |
4130 | peer_param.peer_type = WMI_PEER_TYPE_DEFAULT; | |
4131 | ret = ath11k_peer_create(ar, arvif, NULL, &peer_param); | |
4132 | if (ret) { | |
4133 | ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n", | |
4134 | arvif->vdev_id, ret); | |
4135 | goto err_vdev_del; | |
4136 | } | |
4137 | ||
4138 | ret = ath11k_mac_set_kickout(arvif); | |
4139 | if (ret) { | |
4140 | ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n", | |
4141 | arvif->vdev_id, ret); | |
4142 | goto err_peer_del; | |
4143 | } | |
4144 | break; | |
4145 | case WMI_VDEV_TYPE_STA: | |
4146 | param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY; | |
4147 | param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; | |
4148 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4149 | param_id, param_value); | |
4150 | if (ret) { | |
4151 | ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n", | |
4152 | arvif->vdev_id, ret); | |
4153 | goto err_peer_del; | |
4154 | } | |
4155 | ||
4156 | param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; | |
4157 | param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; | |
4158 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4159 | param_id, param_value); | |
4160 | if (ret) { | |
4161 | ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n", | |
4162 | arvif->vdev_id, ret); | |
4163 | goto err_peer_del; | |
4164 | } | |
4165 | ||
4166 | param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT; | |
4167 | param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; | |
4168 | ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, | |
4169 | param_id, param_value); | |
4170 | if (ret) { | |
4171 | ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n", | |
4172 | arvif->vdev_id, ret); | |
4173 | goto err_peer_del; | |
4174 | } | |
6bfebd4b JC |
4175 | |
4176 | ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false); | |
4177 | if (ret) { | |
4178 | ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n", | |
4179 | arvif->vdev_id, ret); | |
4180 | goto err_peer_del; | |
4181 | } | |
d5c65159 KV |
4182 | break; |
4183 | default: | |
4184 | break; | |
4185 | } | |
4186 | ||
4187 | arvif->txpower = vif->bss_conf.txpower; | |
4188 | ret = ath11k_mac_txpower_recalc(ar); | |
4189 | if (ret) | |
4190 | goto err_peer_del; | |
4191 | ||
4192 | param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
4193 | param_value = ar->hw->wiphy->rts_threshold; | |
4194 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4195 | param_id, param_value); | |
4196 | if (ret) { | |
4197 | ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n", | |
4198 | arvif->vdev_id, ret); | |
4199 | } | |
4200 | ||
4201 | ret = ath11k_mac_set_txbf_conf(arvif); | |
4202 | if (ret) { | |
4203 | ath11k_warn(ar->ab, "failed to set txbf conf for vdev %d: %d\n", | |
4204 | arvif->vdev_id, ret); | |
4205 | } | |
4206 | ||
4207 | ath11k_dp_vdev_tx_attach(ar, arvif); | |
4208 | ||
4209 | mutex_unlock(&ar->conf_mutex); | |
4210 | ||
4211 | return 0; | |
4212 | ||
4213 | err_peer_del: | |
4214 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
4215 | ar->num_peers--; | |
4216 | ath11k_wmi_send_peer_delete_cmd(ar, vif->addr, arvif->vdev_id); | |
4217 | } | |
4218 | ||
4219 | err_vdev_del: | |
4220 | ath11k_wmi_vdev_delete(ar, arvif->vdev_id); | |
4221 | ar->num_created_vdevs--; | |
4222 | ab->free_vdev_map |= 1LL << arvif->vdev_id; | |
4223 | spin_lock_bh(&ar->data_lock); | |
4224 | list_del(&arvif->list); | |
4225 | spin_unlock_bh(&ar->data_lock); | |
4226 | ||
4227 | err: | |
4228 | mutex_unlock(&ar->conf_mutex); | |
4229 | ||
4230 | return ret; | |
4231 | } | |
4232 | ||
4233 | static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx) | |
4234 | { | |
4235 | struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx; | |
4236 | struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb); | |
4237 | ||
4238 | if (skb_cb->vif == vif) | |
4239 | skb_cb->vif = NULL; | |
4240 | ||
4241 | return 0; | |
4242 | } | |
4243 | ||
4244 | static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw, | |
4245 | struct ieee80211_vif *vif) | |
4246 | { | |
4247 | struct ath11k *ar = hw->priv; | |
4248 | struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif); | |
4249 | struct ath11k_base *ab = ar->ab; | |
4250 | int ret; | |
4251 | int i; | |
4252 | ||
4253 | mutex_lock(&ar->conf_mutex); | |
4254 | ||
4255 | ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n", | |
4256 | arvif->vdev_id); | |
4257 | ||
4258 | ab->free_vdev_map |= 1LL << (arvif->vdev_id); | |
4259 | spin_lock_bh(&ar->data_lock); | |
4260 | list_del(&arvif->list); | |
4261 | spin_unlock_bh(&ar->data_lock); | |
4262 | ||
4263 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
4264 | ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr); | |
4265 | if (ret) | |
4266 | ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n", | |
4267 | arvif->vdev_id, ret); | |
4268 | } | |
4269 | ||
4270 | ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id); | |
4271 | if (ret) | |
4272 | ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n", | |
4273 | arvif->vdev_id, ret); | |
4274 | ||
4275 | ar->num_created_vdevs--; | |
4276 | ||
4277 | ath11k_peer_cleanup(ar, arvif->vdev_id); | |
4278 | ||
4279 | idr_for_each(&ar->txmgmt_idr, | |
4280 | ath11k_mac_vif_txmgmt_idr_remove, vif); | |
4281 | ||
4282 | for (i = 0; i < DP_TCL_NUM_RING_MAX; i++) { | |
4283 | spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock); | |
4284 | idr_for_each(&ab->dp.tx_ring[i].txbuf_idr, | |
4285 | ath11k_mac_vif_unref, vif); | |
4286 | spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock); | |
4287 | } | |
4288 | ||
4289 | /* Recalc txpower for remaining vdev */ | |
4290 | ath11k_mac_txpower_recalc(ar); | |
4291 | clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
4292 | ||
4293 | /* TODO: recal traffic pause state based on the available vdevs */ | |
4294 | ||
4295 | mutex_unlock(&ar->conf_mutex); | |
4296 | } | |
4297 | ||
4298 | /* FIXME: Has to be verified. */ | |
4299 | #define SUPPORTED_FILTERS \ | |
4300 | (FIF_ALLMULTI | \ | |
4301 | FIF_CONTROL | \ | |
4302 | FIF_PSPOLL | \ | |
4303 | FIF_OTHER_BSS | \ | |
4304 | FIF_BCN_PRBRESP_PROMISC | \ | |
4305 | FIF_PROBE_REQ | \ | |
4306 | FIF_FCSFAIL) | |
4307 | ||
4308 | static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw, | |
4309 | unsigned int changed_flags, | |
4310 | unsigned int *total_flags, | |
4311 | u64 multicast) | |
4312 | { | |
4313 | struct ath11k *ar = hw->priv; | |
4314 | bool reset_flag = false; | |
4315 | int ret = 0; | |
4316 | ||
4317 | mutex_lock(&ar->conf_mutex); | |
4318 | ||
4319 | changed_flags &= SUPPORTED_FILTERS; | |
4320 | *total_flags &= SUPPORTED_FILTERS; | |
4321 | ar->filter_flags = *total_flags; | |
4322 | ||
4323 | /* For monitor mode */ | |
4324 | reset_flag = !(ar->filter_flags & FIF_BCN_PRBRESP_PROMISC); | |
4325 | ||
4326 | ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, reset_flag); | |
4327 | if (!ret) { | |
4328 | if (!reset_flag) | |
4329 | set_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
4330 | else | |
4331 | clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
4332 | } else { | |
4333 | ath11k_warn(ar->ab, | |
4334 | "fail to set monitor filter: %d\n", ret); | |
4335 | } | |
4336 | mutex_unlock(&ar->conf_mutex); | |
4337 | } | |
4338 | ||
4339 | static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) | |
4340 | { | |
4341 | struct ath11k *ar = hw->priv; | |
4342 | ||
4343 | mutex_lock(&ar->conf_mutex); | |
4344 | ||
4345 | *tx_ant = ar->cfg_tx_chainmask; | |
4346 | *rx_ant = ar->cfg_rx_chainmask; | |
4347 | ||
4348 | mutex_unlock(&ar->conf_mutex); | |
4349 | ||
4350 | return 0; | |
4351 | } | |
4352 | ||
4353 | static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) | |
4354 | { | |
4355 | struct ath11k *ar = hw->priv; | |
4356 | int ret; | |
4357 | ||
4358 | mutex_lock(&ar->conf_mutex); | |
4359 | ret = __ath11k_set_antenna(ar, tx_ant, rx_ant); | |
4360 | mutex_unlock(&ar->conf_mutex); | |
4361 | ||
4362 | return ret; | |
4363 | } | |
4364 | ||
4365 | static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw, | |
4366 | struct ieee80211_vif *vif, | |
4367 | struct ieee80211_ampdu_params *params) | |
4368 | { | |
4369 | struct ath11k *ar = hw->priv; | |
4370 | int ret = -EINVAL; | |
4371 | ||
4372 | mutex_lock(&ar->conf_mutex); | |
4373 | ||
4374 | switch (params->action) { | |
4375 | case IEEE80211_AMPDU_RX_START: | |
4376 | ret = ath11k_dp_rx_ampdu_start(ar, params); | |
4377 | break; | |
4378 | case IEEE80211_AMPDU_RX_STOP: | |
4379 | ret = ath11k_dp_rx_ampdu_stop(ar, params); | |
4380 | break; | |
4381 | case IEEE80211_AMPDU_TX_START: | |
4382 | case IEEE80211_AMPDU_TX_STOP_CONT: | |
4383 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
4384 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
4385 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
4386 | /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211 | |
4387 | * Tx aggregation requests. | |
4388 | */ | |
4389 | ret = -EOPNOTSUPP; | |
4390 | break; | |
4391 | } | |
4392 | ||
4393 | mutex_unlock(&ar->conf_mutex); | |
4394 | ||
4395 | return ret; | |
4396 | } | |
4397 | ||
4398 | static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw, | |
4399 | struct ieee80211_chanctx_conf *ctx) | |
4400 | { | |
4401 | struct ath11k *ar = hw->priv; | |
4402 | struct ath11k_base *ab = ar->ab; | |
4403 | ||
4404 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4405 | "mac chanctx add freq %hu width %d ptr %pK\n", | |
4406 | ctx->def.chan->center_freq, ctx->def.width, ctx); | |
4407 | ||
4408 | mutex_lock(&ar->conf_mutex); | |
4409 | ||
4410 | spin_lock_bh(&ar->data_lock); | |
4411 | /* TODO: In case of multiple channel context, populate rx_channel from | |
4412 | * Rx PPDU desc information. | |
4413 | */ | |
4414 | ar->rx_channel = ctx->def.chan; | |
4415 | spin_unlock_bh(&ar->data_lock); | |
4416 | ||
4417 | mutex_unlock(&ar->conf_mutex); | |
4418 | ||
4419 | return 0; | |
4420 | } | |
4421 | ||
4422 | static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw, | |
4423 | struct ieee80211_chanctx_conf *ctx) | |
4424 | { | |
4425 | struct ath11k *ar = hw->priv; | |
4426 | struct ath11k_base *ab = ar->ab; | |
4427 | ||
4428 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4429 | "mac chanctx remove freq %hu width %d ptr %pK\n", | |
4430 | ctx->def.chan->center_freq, ctx->def.width, ctx); | |
4431 | ||
4432 | mutex_lock(&ar->conf_mutex); | |
4433 | ||
4434 | spin_lock_bh(&ar->data_lock); | |
4435 | /* TODO: In case of there is one more channel context left, populate | |
4436 | * rx_channel with the channel of that remaining channel context. | |
4437 | */ | |
4438 | ar->rx_channel = NULL; | |
4439 | spin_unlock_bh(&ar->data_lock); | |
4440 | ||
4441 | mutex_unlock(&ar->conf_mutex); | |
4442 | } | |
4443 | ||
4444 | static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar) | |
4445 | { | |
4446 | lockdep_assert_held(&ar->conf_mutex); | |
4447 | ||
4448 | if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags)) | |
4449 | return -ESHUTDOWN; | |
4450 | ||
4451 | if (!wait_for_completion_timeout(&ar->vdev_setup_done, | |
4452 | ATH11K_VDEV_SETUP_TIMEOUT_HZ)) | |
4453 | return -ETIMEDOUT; | |
4454 | ||
4455 | return ar->last_wmi_vdev_start_status ? -EINVAL : 0; | |
4456 | } | |
4457 | ||
4458 | static int | |
4459 | ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif, | |
4460 | const struct cfg80211_chan_def *chandef, | |
4461 | bool restart) | |
4462 | { | |
4463 | struct ath11k *ar = arvif->ar; | |
4464 | struct ath11k_base *ab = ar->ab; | |
4465 | struct wmi_vdev_start_req_arg arg = {}; | |
4466 | int he_support = arvif->vif->bss_conf.he_support; | |
4467 | int ret = 0; | |
4468 | ||
4469 | lockdep_assert_held(&ar->conf_mutex); | |
4470 | ||
4471 | reinit_completion(&ar->vdev_setup_done); | |
4472 | ||
4473 | arg.vdev_id = arvif->vdev_id; | |
4474 | arg.dtim_period = arvif->dtim_period; | |
4475 | arg.bcn_intval = arvif->beacon_interval; | |
4476 | ||
4477 | arg.channel.freq = chandef->chan->center_freq; | |
4478 | arg.channel.band_center_freq1 = chandef->center_freq1; | |
4479 | arg.channel.band_center_freq2 = chandef->center_freq2; | |
4480 | arg.channel.mode = | |
4481 | ath11k_phymodes[chandef->chan->band][chandef->width]; | |
4482 | ||
4483 | arg.channel.min_power = 0; | |
4484 | arg.channel.max_power = chandef->chan->max_power * 2; | |
4485 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; | |
4486 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; | |
4487 | ||
4488 | arg.pref_tx_streams = ar->num_tx_chains; | |
4489 | arg.pref_rx_streams = ar->num_rx_chains; | |
4490 | ||
4491 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { | |
4492 | arg.ssid = arvif->u.ap.ssid; | |
4493 | arg.ssid_len = arvif->u.ap.ssid_len; | |
4494 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; | |
4495 | ||
4496 | /* For now allow DFS for AP mode */ | |
4497 | arg.channel.chan_radar = | |
4498 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); | |
4499 | ||
4500 | arg.channel.passive = arg.channel.chan_radar; | |
4501 | ||
4502 | spin_lock_bh(&ab->base_lock); | |
4503 | arg.regdomain = ar->ab->dfs_region; | |
4504 | spin_unlock_bh(&ab->base_lock); | |
4505 | ||
4506 | /* TODO: Notify if secondary 80Mhz also needs radar detection */ | |
4507 | if (he_support) { | |
4508 | ret = ath11k_set_he_mu_sounding_mode(ar, arvif); | |
4509 | if (ret) { | |
4510 | ath11k_warn(ar->ab, "failed to set he mode vdev %i\n", | |
4511 | arg.vdev_id); | |
4512 | return ret; | |
4513 | } | |
4514 | } | |
4515 | } | |
4516 | ||
4517 | arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR); | |
4518 | ||
4519 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4520 | "mac vdev %d start center_freq %d phymode %s\n", | |
4521 | arg.vdev_id, arg.channel.freq, | |
4522 | ath11k_wmi_phymode_str(arg.channel.mode)); | |
4523 | ||
4524 | ret = ath11k_wmi_vdev_start(ar, &arg, restart); | |
4525 | if (ret) { | |
4526 | ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n", | |
4527 | restart ? "restart" : "start", arg.vdev_id); | |
4528 | return ret; | |
4529 | } | |
4530 | ||
4531 | ret = ath11k_mac_vdev_setup_sync(ar); | |
4532 | if (ret) { | |
4533 | ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n", | |
4534 | arg.vdev_id, restart ? "restart" : "start", ret); | |
4535 | return ret; | |
4536 | } | |
4537 | ||
4538 | ar->num_started_vdevs++; | |
4539 | ||
4540 | /* Enable CAC Flag in the driver by checking the channel DFS cac time, | |
4541 | * i.e dfs_cac_ms value which will be valid only for radar channels | |
4542 | * and state as NL80211_DFS_USABLE which indicates CAC needs to be | |
4543 | * done before channel usage. This flags is used to drop rx packets. | |
4544 | * during CAC. | |
4545 | */ | |
4546 | /* TODO Set the flag for other interface types as required */ | |
4547 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP && | |
4548 | chandef->chan->dfs_cac_ms && | |
4549 | chandef->chan->dfs_state == NL80211_DFS_USABLE) { | |
4550 | set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags); | |
4551 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4552 | "CAC Started in chan_freq %d for vdev %d\n", | |
4553 | arg.channel.freq, arg.vdev_id); | |
4554 | } | |
4555 | ||
4556 | return 0; | |
4557 | } | |
4558 | ||
4559 | static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif) | |
4560 | { | |
4561 | struct ath11k *ar = arvif->ar; | |
4562 | int ret; | |
4563 | ||
4564 | lockdep_assert_held(&ar->conf_mutex); | |
4565 | ||
4566 | reinit_completion(&ar->vdev_setup_done); | |
4567 | ||
4568 | spin_lock_bh(&ar->data_lock); | |
4569 | ||
4570 | ar->vdev_stop_status.stop_in_progress = true; | |
4571 | ar->vdev_stop_status.vdev_id = arvif->vdev_id; | |
4572 | ||
4573 | spin_unlock_bh(&ar->data_lock); | |
4574 | ||
4575 | ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id); | |
4576 | if (ret) { | |
4577 | ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n", | |
4578 | arvif->vdev_id, ret); | |
4579 | goto err; | |
4580 | } | |
4581 | ||
4582 | ret = ath11k_mac_vdev_setup_sync(ar); | |
4583 | if (ret) { | |
4584 | ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n", | |
4585 | arvif->vdev_id, ret); | |
4586 | goto err; | |
4587 | } | |
4588 | ||
4589 | WARN_ON(ar->num_started_vdevs == 0); | |
4590 | ||
4591 | ar->num_started_vdevs--; | |
4592 | ||
4593 | if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) { | |
4594 | clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags); | |
4595 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n", | |
4596 | arvif->vdev_id); | |
4597 | } | |
4598 | ||
4599 | return 0; | |
4600 | err: | |
4601 | spin_lock_bh(&ar->data_lock); | |
4602 | ar->vdev_stop_status.stop_in_progress = false; | |
4603 | spin_unlock_bh(&ar->data_lock); | |
4604 | ||
4605 | return ret; | |
4606 | } | |
4607 | ||
4608 | static int ath11k_mac_vdev_start(struct ath11k_vif *arvif, | |
4609 | const struct cfg80211_chan_def *chandef) | |
4610 | { | |
4611 | return ath11k_mac_vdev_start_restart(arvif, chandef, false); | |
4612 | } | |
4613 | ||
4614 | static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif, | |
4615 | const struct cfg80211_chan_def *chandef) | |
4616 | { | |
4617 | return ath11k_mac_vdev_start_restart(arvif, chandef, true); | |
4618 | } | |
4619 | ||
4620 | struct ath11k_mac_change_chanctx_arg { | |
4621 | struct ieee80211_chanctx_conf *ctx; | |
4622 | struct ieee80211_vif_chanctx_switch *vifs; | |
4623 | int n_vifs; | |
4624 | int next_vif; | |
4625 | }; | |
4626 | ||
4627 | static void | |
4628 | ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, | |
4629 | struct ieee80211_vif *vif) | |
4630 | { | |
4631 | struct ath11k_mac_change_chanctx_arg *arg = data; | |
4632 | ||
4633 | if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx) | |
4634 | return; | |
4635 | ||
4636 | arg->n_vifs++; | |
4637 | } | |
4638 | ||
4639 | static void | |
4640 | ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac, | |
4641 | struct ieee80211_vif *vif) | |
4642 | { | |
4643 | struct ath11k_mac_change_chanctx_arg *arg = data; | |
4644 | struct ieee80211_chanctx_conf *ctx; | |
4645 | ||
4646 | ctx = rcu_access_pointer(vif->chanctx_conf); | |
4647 | if (ctx != arg->ctx) | |
4648 | return; | |
4649 | ||
4650 | if (WARN_ON(arg->next_vif == arg->n_vifs)) | |
4651 | return; | |
4652 | ||
4653 | arg->vifs[arg->next_vif].vif = vif; | |
4654 | arg->vifs[arg->next_vif].old_ctx = ctx; | |
4655 | arg->vifs[arg->next_vif].new_ctx = ctx; | |
4656 | arg->next_vif++; | |
4657 | } | |
4658 | ||
4659 | static void | |
4660 | ath11k_mac_update_vif_chan(struct ath11k *ar, | |
4661 | struct ieee80211_vif_chanctx_switch *vifs, | |
4662 | int n_vifs) | |
4663 | { | |
4664 | struct ath11k_base *ab = ar->ab; | |
4665 | struct ath11k_vif *arvif; | |
4666 | int ret; | |
4667 | int i; | |
4668 | ||
4669 | lockdep_assert_held(&ar->conf_mutex); | |
4670 | ||
4671 | for (i = 0; i < n_vifs; i++) { | |
4672 | arvif = (void *)vifs[i].vif->drv_priv; | |
4673 | ||
4674 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4675 | "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n", | |
4676 | arvif->vdev_id, | |
4677 | vifs[i].old_ctx->def.chan->center_freq, | |
4678 | vifs[i].new_ctx->def.chan->center_freq, | |
4679 | vifs[i].old_ctx->def.width, | |
4680 | vifs[i].new_ctx->def.width); | |
4681 | ||
4682 | if (WARN_ON(!arvif->is_started)) | |
4683 | continue; | |
4684 | ||
4685 | if (WARN_ON(!arvif->is_up)) | |
4686 | continue; | |
4687 | ||
4688 | ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id); | |
4689 | if (ret) { | |
4690 | ath11k_warn(ab, "failed to down vdev %d: %d\n", | |
4691 | arvif->vdev_id, ret); | |
4692 | continue; | |
4693 | } | |
4694 | } | |
4695 | ||
4696 | /* All relevant vdevs are downed and associated channel resources | |
4697 | * should be available for the channel switch now. | |
4698 | */ | |
4699 | ||
4700 | /* TODO: Update ar->rx_channel */ | |
4701 | ||
4702 | for (i = 0; i < n_vifs; i++) { | |
4703 | arvif = (void *)vifs[i].vif->drv_priv; | |
4704 | ||
4705 | if (WARN_ON(!arvif->is_started)) | |
4706 | continue; | |
4707 | ||
4708 | if (WARN_ON(!arvif->is_up)) | |
4709 | continue; | |
4710 | ||
4711 | ret = ath11k_mac_setup_bcn_tmpl(arvif); | |
4712 | if (ret) | |
4713 | ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n", | |
4714 | ret); | |
4715 | ||
4716 | ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def); | |
4717 | if (ret) { | |
4718 | ath11k_warn(ab, "failed to restart vdev %d: %d\n", | |
4719 | arvif->vdev_id, ret); | |
4720 | continue; | |
4721 | } | |
4722 | ||
4723 | ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, | |
4724 | arvif->bssid); | |
4725 | if (ret) { | |
4726 | ath11k_warn(ab, "failed to bring vdev up %d: %d\n", | |
4727 | arvif->vdev_id, ret); | |
4728 | continue; | |
4729 | } | |
4730 | } | |
4731 | } | |
4732 | ||
4733 | static void | |
4734 | ath11k_mac_update_active_vif_chan(struct ath11k *ar, | |
4735 | struct ieee80211_chanctx_conf *ctx) | |
4736 | { | |
4737 | struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx }; | |
4738 | ||
4739 | lockdep_assert_held(&ar->conf_mutex); | |
4740 | ||
4741 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
4742 | IEEE80211_IFACE_ITER_NORMAL, | |
4743 | ath11k_mac_change_chanctx_cnt_iter, | |
4744 | &arg); | |
4745 | if (arg.n_vifs == 0) | |
4746 | return; | |
4747 | ||
4748 | arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL); | |
4749 | if (!arg.vifs) | |
4750 | return; | |
4751 | ||
4752 | ieee80211_iterate_active_interfaces_atomic(ar->hw, | |
4753 | IEEE80211_IFACE_ITER_NORMAL, | |
4754 | ath11k_mac_change_chanctx_fill_iter, | |
4755 | &arg); | |
4756 | ||
4757 | ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); | |
4758 | ||
4759 | kfree(arg.vifs); | |
4760 | } | |
4761 | ||
4762 | static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw, | |
4763 | struct ieee80211_chanctx_conf *ctx, | |
4764 | u32 changed) | |
4765 | { | |
4766 | struct ath11k *ar = hw->priv; | |
4767 | struct ath11k_base *ab = ar->ab; | |
4768 | ||
4769 | mutex_lock(&ar->conf_mutex); | |
4770 | ||
4771 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4772 | "mac chanctx change freq %hu width %d ptr %pK changed %x\n", | |
4773 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); | |
4774 | ||
4775 | /* This shouldn't really happen because channel switching should use | |
4776 | * switch_vif_chanctx(). | |
4777 | */ | |
4778 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) | |
4779 | goto unlock; | |
4780 | ||
4781 | if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) | |
4782 | ath11k_mac_update_active_vif_chan(ar, ctx); | |
4783 | ||
4784 | /* TODO: Recalc radar detection */ | |
4785 | ||
4786 | unlock: | |
4787 | mutex_unlock(&ar->conf_mutex); | |
4788 | } | |
4789 | ||
4790 | static int | |
4791 | ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, | |
4792 | struct ieee80211_vif *vif, | |
4793 | struct ieee80211_chanctx_conf *ctx) | |
4794 | { | |
4795 | struct ath11k *ar = hw->priv; | |
4796 | struct ath11k_base *ab = ar->ab; | |
4797 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
4798 | int ret; | |
4799 | ||
4800 | mutex_lock(&ar->conf_mutex); | |
4801 | ||
4802 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4803 | "mac chanctx assign ptr %pK vdev_id %i\n", | |
4804 | ctx, arvif->vdev_id); | |
4805 | ||
4806 | if (WARN_ON(arvif->is_started)) { | |
4807 | mutex_unlock(&ar->conf_mutex); | |
4808 | return -EBUSY; | |
4809 | } | |
4810 | ||
4811 | ret = ath11k_mac_vdev_start(arvif, &ctx->def); | |
4812 | if (ret) { | |
4813 | ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n", | |
4814 | arvif->vdev_id, vif->addr, | |
4815 | ctx->def.chan->center_freq, ret); | |
4816 | goto err; | |
4817 | } | |
4818 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) { | |
4819 | ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id); | |
4820 | if (ret) | |
4821 | goto err; | |
4822 | } | |
4823 | ||
4824 | arvif->is_started = true; | |
4825 | ||
4826 | /* TODO: Setup ps and cts/rts protection */ | |
4827 | ||
4828 | mutex_unlock(&ar->conf_mutex); | |
4829 | ||
4830 | return 0; | |
4831 | ||
4832 | err: | |
4833 | mutex_unlock(&ar->conf_mutex); | |
4834 | ||
4835 | return ret; | |
4836 | } | |
4837 | ||
4838 | static void | |
4839 | ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
4840 | struct ieee80211_vif *vif, | |
4841 | struct ieee80211_chanctx_conf *ctx) | |
4842 | { | |
4843 | struct ath11k *ar = hw->priv; | |
4844 | struct ath11k_base *ab = ar->ab; | |
4845 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
4846 | int ret; | |
4847 | ||
4848 | mutex_lock(&ar->conf_mutex); | |
4849 | ||
4850 | ath11k_dbg(ab, ATH11K_DBG_MAC, | |
4851 | "mac chanctx unassign ptr %pK vdev_id %i\n", | |
4852 | ctx, arvif->vdev_id); | |
4853 | ||
4854 | WARN_ON(!arvif->is_started); | |
4855 | ||
4856 | ret = ath11k_mac_vdev_stop(arvif); | |
4857 | if (ret) | |
4858 | ath11k_warn(ab, "failed to stop vdev %i: %d\n", | |
4859 | arvif->vdev_id, ret); | |
4860 | ||
4861 | arvif->is_started = false; | |
4862 | ||
4863 | mutex_unlock(&ar->conf_mutex); | |
4864 | } | |
4865 | ||
4866 | static int | |
4867 | ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, | |
4868 | struct ieee80211_vif_chanctx_switch *vifs, | |
4869 | int n_vifs, | |
4870 | enum ieee80211_chanctx_switch_mode mode) | |
4871 | { | |
4872 | struct ath11k *ar = hw->priv; | |
4873 | ||
4874 | mutex_lock(&ar->conf_mutex); | |
4875 | ||
4876 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
4877 | "mac chanctx switch n_vifs %d mode %d\n", | |
4878 | n_vifs, mode); | |
4879 | ath11k_mac_update_vif_chan(ar, vifs, n_vifs); | |
4880 | ||
4881 | mutex_unlock(&ar->conf_mutex); | |
4882 | ||
4883 | return 0; | |
4884 | } | |
4885 | ||
4886 | static int | |
4887 | ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value) | |
4888 | { | |
4889 | struct ath11k_vif *arvif; | |
4890 | int ret = 0; | |
4891 | ||
4892 | mutex_lock(&ar->conf_mutex); | |
4893 | list_for_each_entry(arvif, &ar->arvifs, list) { | |
4894 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n", | |
4895 | param, arvif->vdev_id, value); | |
4896 | ||
4897 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
4898 | param, value); | |
4899 | if (ret) { | |
4900 | ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n", | |
4901 | param, arvif->vdev_id, ret); | |
4902 | break; | |
4903 | } | |
4904 | } | |
4905 | mutex_unlock(&ar->conf_mutex); | |
4906 | return ret; | |
4907 | } | |
4908 | ||
4909 | /* mac80211 stores device specific RTS/Fragmentation threshold value, | |
4910 | * this is set interface specific to firmware from ath11k driver | |
4911 | */ | |
4912 | static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | |
4913 | { | |
4914 | struct ath11k *ar = hw->priv; | |
4915 | int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD; | |
4916 | ||
4917 | return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value); | |
4918 | } | |
4919 | ||
4920 | static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) | |
4921 | { | |
4922 | /* Even though there's a WMI vdev param for fragmentation threshold no | |
4923 | * known firmware actually implements it. Moreover it is not possible to | |
4924 | * rely frame fragmentation to mac80211 because firmware clears the | |
4925 | * "more fragments" bit in frame control making it impossible for remote | |
4926 | * devices to reassemble frames. | |
4927 | * | |
4928 | * Hence implement a dummy callback just to say fragmentation isn't | |
4929 | * supported. This effectively prevents mac80211 from doing frame | |
4930 | * fragmentation in software. | |
4931 | */ | |
4932 | return -EOPNOTSUPP; | |
4933 | } | |
4934 | ||
4935 | static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |
4936 | u32 queues, bool drop) | |
4937 | { | |
4938 | struct ath11k *ar = hw->priv; | |
4939 | long time_left; | |
4940 | ||
4941 | if (drop) | |
4942 | return; | |
4943 | ||
4944 | time_left = wait_event_timeout(ar->dp.tx_empty_waitq, | |
4945 | (atomic_read(&ar->dp.num_tx_pending) == 0), | |
4946 | ATH11K_FLUSH_TIMEOUT); | |
4947 | if (time_left == 0) | |
4948 | ath11k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left); | |
4949 | } | |
4950 | ||
4951 | static int | |
4952 | ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar, | |
4953 | enum nl80211_band band, | |
4954 | const struct cfg80211_bitrate_mask *mask) | |
4955 | { | |
4956 | int num_rates = 0; | |
4957 | int i; | |
4958 | ||
4959 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) | |
4960 | num_rates += hweight16(mask->control[band].ht_mcs[i]); | |
4961 | ||
4962 | return num_rates; | |
4963 | } | |
4964 | ||
4965 | static bool | |
4966 | ath11k_mac_has_single_legacy_rate(struct ath11k *ar, | |
4967 | enum nl80211_band band, | |
4968 | const struct cfg80211_bitrate_mask *mask) | |
4969 | { | |
4970 | int num_rates = 0; | |
4971 | ||
4972 | num_rates = hweight32(mask->control[band].legacy); | |
4973 | ||
4974 | if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask)) | |
4975 | return false; | |
4976 | ||
4977 | if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask)) | |
4978 | return false; | |
4979 | ||
4980 | return num_rates == 1; | |
4981 | } | |
4982 | ||
4983 | static bool | |
4984 | ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar, | |
4985 | enum nl80211_band band, | |
4986 | const struct cfg80211_bitrate_mask *mask, | |
4987 | int *nss) | |
4988 | { | |
4989 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; | |
4990 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
4991 | u8 ht_nss_mask = 0; | |
4992 | u8 vht_nss_mask = 0; | |
4993 | int i; | |
4994 | ||
4995 | /* No need to consider legacy here. Basic rates are always present | |
4996 | * in bitrate mask | |
4997 | */ | |
4998 | ||
4999 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { | |
5000 | if (mask->control[band].ht_mcs[i] == 0) | |
5001 | continue; | |
5002 | else if (mask->control[band].ht_mcs[i] == | |
5003 | sband->ht_cap.mcs.rx_mask[i]) | |
5004 | ht_nss_mask |= BIT(i); | |
5005 | else | |
5006 | return false; | |
5007 | } | |
5008 | ||
5009 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { | |
5010 | if (mask->control[band].vht_mcs[i] == 0) | |
5011 | continue; | |
5012 | else if (mask->control[band].vht_mcs[i] == | |
5013 | ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) | |
5014 | vht_nss_mask |= BIT(i); | |
5015 | else | |
5016 | return false; | |
5017 | } | |
5018 | ||
5019 | if (ht_nss_mask != vht_nss_mask) | |
5020 | return false; | |
5021 | ||
5022 | if (ht_nss_mask == 0) | |
5023 | return false; | |
5024 | ||
5025 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) | |
5026 | return false; | |
5027 | ||
5028 | *nss = fls(ht_nss_mask); | |
5029 | ||
5030 | return true; | |
5031 | } | |
5032 | ||
5033 | static int | |
5034 | ath11k_mac_get_single_legacy_rate(struct ath11k *ar, | |
5035 | enum nl80211_band band, | |
5036 | const struct cfg80211_bitrate_mask *mask, | |
5037 | u32 *rate, u8 *nss) | |
5038 | { | |
5039 | int rate_idx; | |
5040 | u16 bitrate; | |
5041 | u8 preamble; | |
5042 | u8 hw_rate; | |
5043 | ||
5044 | if (hweight32(mask->control[band].legacy) != 1) | |
5045 | return -EINVAL; | |
5046 | ||
5047 | rate_idx = ffs(mask->control[band].legacy) - 1; | |
5048 | ||
5049 | if (band == NL80211_BAND_5GHZ) | |
5050 | rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX; | |
5051 | ||
5052 | hw_rate = ath11k_legacy_rates[rate_idx].hw_value; | |
5053 | bitrate = ath11k_legacy_rates[rate_idx].bitrate; | |
5054 | ||
5055 | if (ath11k_mac_bitrate_is_cck(bitrate)) | |
5056 | preamble = WMI_RATE_PREAMBLE_CCK; | |
5057 | else | |
5058 | preamble = WMI_RATE_PREAMBLE_OFDM; | |
5059 | ||
5060 | *nss = 1; | |
5061 | *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble); | |
5062 | ||
5063 | return 0; | |
5064 | } | |
5065 | ||
5066 | static int ath11k_mac_set_fixed_rate_params(struct ath11k_vif *arvif, | |
5067 | u32 rate, u8 nss, u8 sgi, u8 ldpc) | |
5068 | { | |
5069 | struct ath11k *ar = arvif->ar; | |
5070 | u32 vdev_param; | |
5071 | int ret; | |
5072 | ||
5073 | lockdep_assert_held(&ar->conf_mutex); | |
5074 | ||
5075 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n", | |
5076 | arvif->vdev_id, rate, nss, sgi); | |
5077 | ||
5078 | vdev_param = WMI_VDEV_PARAM_FIXED_RATE; | |
5079 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5080 | vdev_param, rate); | |
5081 | if (ret) { | |
5082 | ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n", | |
5083 | rate, ret); | |
5084 | return ret; | |
5085 | } | |
5086 | ||
5087 | vdev_param = WMI_VDEV_PARAM_NSS; | |
5088 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5089 | vdev_param, nss); | |
5090 | if (ret) { | |
5091 | ath11k_warn(ar->ab, "failed to set nss param %d: %d\n", | |
5092 | nss, ret); | |
5093 | return ret; | |
5094 | } | |
5095 | ||
5096 | vdev_param = WMI_VDEV_PARAM_SGI; | |
5097 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5098 | vdev_param, sgi); | |
5099 | if (ret) { | |
5100 | ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n", | |
5101 | sgi, ret); | |
5102 | return ret; | |
5103 | } | |
5104 | ||
5105 | vdev_param = WMI_VDEV_PARAM_LDPC; | |
5106 | ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, | |
5107 | vdev_param, ldpc); | |
5108 | if (ret) { | |
5109 | ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n", | |
5110 | ldpc, ret); | |
5111 | return ret; | |
5112 | } | |
5113 | ||
5114 | return 0; | |
5115 | } | |
5116 | ||
5117 | static bool | |
5118 | ath11k_mac_vht_mcs_range_present(struct ath11k *ar, | |
5119 | enum nl80211_band band, | |
5120 | const struct cfg80211_bitrate_mask *mask) | |
5121 | { | |
5122 | int i; | |
5123 | u16 vht_mcs; | |
5124 | ||
5125 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
5126 | vht_mcs = mask->control[band].vht_mcs[i]; | |
5127 | ||
5128 | switch (vht_mcs) { | |
5129 | case 0: | |
5130 | case BIT(8) - 1: | |
5131 | case BIT(9) - 1: | |
5132 | case BIT(10) - 1: | |
5133 | break; | |
5134 | default: | |
5135 | return false; | |
5136 | } | |
5137 | } | |
5138 | ||
5139 | return true; | |
5140 | } | |
5141 | ||
5142 | static void ath11k_mac_set_bitrate_mask_iter(void *data, | |
5143 | struct ieee80211_sta *sta) | |
5144 | { | |
5145 | struct ath11k_vif *arvif = data; | |
5146 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
5147 | struct ath11k *ar = arvif->ar; | |
5148 | ||
5149 | spin_lock_bh(&ar->data_lock); | |
5150 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; | |
5151 | spin_unlock_bh(&ar->data_lock); | |
5152 | ||
5153 | ieee80211_queue_work(ar->hw, &arsta->update_wk); | |
5154 | } | |
5155 | ||
5156 | static void ath11k_mac_disable_peer_fixed_rate(void *data, | |
5157 | struct ieee80211_sta *sta) | |
5158 | { | |
5159 | struct ath11k_vif *arvif = data; | |
5160 | struct ath11k *ar = arvif->ar; | |
5161 | int ret; | |
5162 | ||
5163 | ret = ath11k_wmi_set_peer_param(ar, sta->addr, | |
5164 | arvif->vdev_id, | |
5165 | WMI_PEER_PARAM_FIXED_RATE, | |
5166 | WMI_FIXED_RATE_NONE); | |
5167 | if (ret) | |
5168 | ath11k_warn(ar->ab, | |
5169 | "failed to disable peer fixed rate for STA %pM ret %d\n", | |
5170 | sta->addr, ret); | |
5171 | } | |
5172 | ||
5173 | static int | |
5174 | ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, | |
5175 | struct ieee80211_vif *vif, | |
5176 | const struct cfg80211_bitrate_mask *mask) | |
5177 | { | |
5178 | struct ath11k_vif *arvif = (void *)vif->drv_priv; | |
5179 | struct cfg80211_chan_def def; | |
5180 | struct ath11k *ar = arvif->ar; | |
5181 | enum nl80211_band band; | |
5182 | const u8 *ht_mcs_mask; | |
5183 | const u16 *vht_mcs_mask; | |
5184 | u32 rate; | |
5185 | u8 nss; | |
5186 | u8 sgi; | |
5187 | u8 ldpc; | |
5188 | int single_nss; | |
5189 | int ret; | |
5190 | int num_rates; | |
5191 | ||
5192 | if (ath11k_mac_vif_chan(vif, &def)) | |
5193 | return -EPERM; | |
5194 | ||
5195 | band = def.chan->band; | |
5196 | ht_mcs_mask = mask->control[band].ht_mcs; | |
5197 | vht_mcs_mask = mask->control[band].vht_mcs; | |
5198 | ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); | |
5199 | ||
5200 | sgi = mask->control[band].gi; | |
5201 | if (sgi == NL80211_TXRATE_FORCE_LGI) | |
5202 | return -EINVAL; | |
5203 | ||
5204 | /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it | |
5205 | * requires passing atleast one of used basic rates along with them. | |
5206 | * Fixed rate setting across different preambles(legacy, HT, VHT) is | |
5207 | * not supported by the FW. Hence use of FIXED_RATE vdev param is not | |
5208 | * suitable for setting single HT/VHT rates. | |
5209 | * But, there could be a single basic rate passed from userspace which | |
5210 | * can be done through the FIXED_RATE param. | |
5211 | */ | |
5212 | if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) { | |
5213 | ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate, | |
5214 | &nss); | |
5215 | if (ret) { | |
5216 | ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n", | |
5217 | arvif->vdev_id, ret); | |
5218 | return ret; | |
5219 | } | |
5220 | ieee80211_iterate_stations_atomic(ar->hw, | |
5221 | ath11k_mac_disable_peer_fixed_rate, | |
5222 | arvif); | |
5223 | } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask, | |
5224 | &single_nss)) { | |
5225 | rate = WMI_FIXED_RATE_NONE; | |
5226 | nss = single_nss; | |
5227 | } else { | |
5228 | rate = WMI_FIXED_RATE_NONE; | |
5229 | nss = min_t(u32, ar->num_tx_chains, | |
5230 | max(ath11k_mac_max_ht_nss(ht_mcs_mask), | |
5231 | ath11k_mac_max_vht_nss(vht_mcs_mask))); | |
5232 | ||
5233 | /* If multiple rates across different preambles are given | |
5234 | * we can reconfigure this info with all peers using PEER_ASSOC | |
5235 | * command with the below exception cases. | |
5236 | * - Single VHT Rate : peer_assoc command accommodates only MCS | |
5237 | * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211 | |
5238 | * mandates passing basic rates along with HT/VHT rates, FW | |
5239 | * doesn't allow switching from VHT to Legacy. Hence instead of | |
5240 | * setting legacy and VHT rates using RATEMASK_CMD vdev cmd, | |
5241 | * we could set this VHT rate as peer fixed rate param, which | |
5242 | * will override FIXED rate and FW rate control algorithm. | |
5243 | * If single VHT rate is passed along with HT rates, we select | |
5244 | * the VHT rate as fixed rate for vht peers. | |
5245 | * - Multiple VHT Rates : When Multiple VHT rates are given,this | |
5246 | * can be set using RATEMASK CMD which uses FW rate-ctl alg. | |
5247 | * TODO: Setting multiple VHT MCS and replacing peer_assoc with | |
5248 | * RATEMASK_CMDID can cover all use cases of setting rates | |
5249 | * across multiple preambles and rates within same type. | |
5250 | * But requires more validation of the command at this point. | |
5251 | */ | |
5252 | ||
5253 | num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, | |
5254 | mask); | |
5255 | ||
5256 | if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) && | |
5257 | num_rates > 1) { | |
5258 | /* TODO: Handle multiple VHT MCS values setting using | |
5259 | * RATEMASK CMD | |
5260 | */ | |
5261 | ath11k_warn(ar->ab, | |
5262 | "Setting more than one MCS Value in bitrate mask not supported\n"); | |
5263 | return -EINVAL; | |
5264 | } | |
5265 | ||
5266 | ieee80211_iterate_stations_atomic(ar->hw, | |
5267 | ath11k_mac_disable_peer_fixed_rate, | |
5268 | arvif); | |
5269 | ||
5270 | mutex_lock(&ar->conf_mutex); | |
5271 | ||
5272 | arvif->bitrate_mask = *mask; | |
5273 | ieee80211_iterate_stations_atomic(ar->hw, | |
5274 | ath11k_mac_set_bitrate_mask_iter, | |
5275 | arvif); | |
5276 | ||
5277 | mutex_unlock(&ar->conf_mutex); | |
5278 | } | |
5279 | ||
5280 | mutex_lock(&ar->conf_mutex); | |
5281 | ||
5282 | ret = ath11k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); | |
5283 | if (ret) { | |
5284 | ath11k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n", | |
5285 | arvif->vdev_id, ret); | |
5286 | } | |
5287 | ||
5288 | mutex_unlock(&ar->conf_mutex); | |
5289 | ||
5290 | return ret; | |
5291 | } | |
5292 | ||
5293 | static void | |
5294 | ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw, | |
5295 | enum ieee80211_reconfig_type reconfig_type) | |
5296 | { | |
5297 | struct ath11k *ar = hw->priv; | |
5298 | ||
5299 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) | |
5300 | return; | |
5301 | ||
5302 | mutex_lock(&ar->conf_mutex); | |
5303 | ||
5304 | if (ar->state == ATH11K_STATE_RESTARTED) { | |
5305 | ath11k_warn(ar->ab, "pdev %d successfully recovered\n", | |
5306 | ar->pdev->pdev_id); | |
5307 | ar->state = ATH11K_STATE_ON; | |
5308 | ieee80211_wake_queues(ar->hw); | |
5309 | } | |
5310 | ||
5311 | mutex_unlock(&ar->conf_mutex); | |
5312 | } | |
5313 | ||
5314 | static void | |
5315 | ath11k_mac_update_bss_chan_survey(struct ath11k *ar, | |
5316 | struct ieee80211_channel *channel) | |
5317 | { | |
5318 | int ret; | |
5319 | enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ; | |
5320 | ||
5321 | lockdep_assert_held(&ar->conf_mutex); | |
5322 | ||
6bc9d6f7 | 5323 | if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) || |
d5c65159 KV |
5324 | ar->rx_channel != channel) |
5325 | return; | |
5326 | ||
5327 | if (ar->scan.state != ATH11K_SCAN_IDLE) { | |
5328 | ath11k_dbg(ar->ab, ATH11K_DBG_MAC, | |
5329 | "ignoring bss chan info req while scanning..\n"); | |
5330 | return; | |
5331 | } | |
5332 | ||
5333 | reinit_completion(&ar->bss_survey_done); | |
5334 | ||
5335 | ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type); | |
5336 | if (ret) { | |
5337 | ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n"); | |
5338 | return; | |
5339 | } | |
5340 | ||
5341 | ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); | |
5342 | if (ret == 0) | |
5343 | ath11k_warn(ar->ab, "bss channel survey timed out\n"); | |
5344 | } | |
5345 | ||
5346 | static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx, | |
5347 | struct survey_info *survey) | |
5348 | { | |
5349 | struct ath11k *ar = hw->priv; | |
5350 | struct ieee80211_supported_band *sband; | |
5351 | struct survey_info *ar_survey; | |
5352 | int ret = 0; | |
5353 | ||
5354 | if (idx >= ATH11K_NUM_CHANS) | |
5355 | return -ENOENT; | |
5356 | ||
5357 | ar_survey = &ar->survey[idx]; | |
5358 | ||
5359 | mutex_lock(&ar->conf_mutex); | |
5360 | ||
5361 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; | |
5362 | if (sband && idx >= sband->n_channels) { | |
5363 | idx -= sband->n_channels; | |
5364 | sband = NULL; | |
5365 | } | |
5366 | ||
5367 | if (!sband) | |
5368 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; | |
5369 | ||
5370 | if (!sband || idx >= sband->n_channels) { | |
5371 | ret = -ENOENT; | |
5372 | goto exit; | |
5373 | } | |
5374 | ||
5375 | ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); | |
5376 | ||
5377 | spin_lock_bh(&ar->data_lock); | |
5378 | memcpy(survey, ar_survey, sizeof(*survey)); | |
5379 | spin_unlock_bh(&ar->data_lock); | |
5380 | ||
5381 | survey->channel = &sband->channels[idx]; | |
5382 | ||
5383 | if (ar->rx_channel == survey->channel) | |
5384 | survey->filled |= SURVEY_INFO_IN_USE; | |
5385 | ||
5386 | exit: | |
5387 | mutex_unlock(&ar->conf_mutex); | |
5388 | return ret; | |
5389 | } | |
5390 | ||
5391 | static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw, | |
5392 | struct ieee80211_vif *vif, | |
5393 | struct ieee80211_sta *sta, | |
5394 | struct station_info *sinfo) | |
5395 | { | |
5396 | struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv; | |
5397 | ||
5398 | sinfo->rx_duration = arsta->rx_duration; | |
5399 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); | |
5400 | ||
a9e945ea VN |
5401 | sinfo->tx_duration = arsta->tx_duration; |
5402 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION); | |
5403 | ||
d5c65159 KV |
5404 | if (!arsta->txrate.legacy && !arsta->txrate.nss) |
5405 | return; | |
5406 | ||
5407 | if (arsta->txrate.legacy) { | |
5408 | sinfo->txrate.legacy = arsta->txrate.legacy; | |
5409 | } else { | |
5410 | sinfo->txrate.mcs = arsta->txrate.mcs; | |
5411 | sinfo->txrate.nss = arsta->txrate.nss; | |
5412 | sinfo->txrate.bw = arsta->txrate.bw; | |
5413 | sinfo->txrate.he_gi = arsta->txrate.he_gi; | |
5414 | sinfo->txrate.he_dcm = arsta->txrate.he_dcm; | |
5415 | sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc; | |
5416 | } | |
5417 | sinfo->txrate.flags = arsta->txrate.flags; | |
5418 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); | |
5419 | ||
5420 | /* TODO: Use real NF instead of default one. */ | |
5421 | sinfo->signal = arsta->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR; | |
5422 | } | |
5423 | ||
5424 | static const struct ieee80211_ops ath11k_ops = { | |
5425 | .tx = ath11k_mac_op_tx, | |
5426 | .start = ath11k_mac_op_start, | |
5427 | .stop = ath11k_mac_op_stop, | |
5428 | .reconfig_complete = ath11k_mac_op_reconfig_complete, | |
5429 | .add_interface = ath11k_mac_op_add_interface, | |
5430 | .remove_interface = ath11k_mac_op_remove_interface, | |
5431 | .config = ath11k_mac_op_config, | |
5432 | .bss_info_changed = ath11k_mac_op_bss_info_changed, | |
5433 | .configure_filter = ath11k_mac_op_configure_filter, | |
5434 | .hw_scan = ath11k_mac_op_hw_scan, | |
5435 | .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan, | |
5436 | .set_key = ath11k_mac_op_set_key, | |
5437 | .sta_state = ath11k_mac_op_sta_state, | |
64f1d7e9 | 5438 | .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr, |
d5c65159 KV |
5439 | .sta_rc_update = ath11k_mac_op_sta_rc_update, |
5440 | .conf_tx = ath11k_mac_op_conf_tx, | |
5441 | .set_antenna = ath11k_mac_op_set_antenna, | |
5442 | .get_antenna = ath11k_mac_op_get_antenna, | |
5443 | .ampdu_action = ath11k_mac_op_ampdu_action, | |
5444 | .add_chanctx = ath11k_mac_op_add_chanctx, | |
5445 | .remove_chanctx = ath11k_mac_op_remove_chanctx, | |
5446 | .change_chanctx = ath11k_mac_op_change_chanctx, | |
5447 | .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx, | |
5448 | .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx, | |
5449 | .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx, | |
5450 | .set_rts_threshold = ath11k_mac_op_set_rts_threshold, | |
5451 | .set_frag_threshold = ath11k_mac_op_set_frag_threshold, | |
5452 | .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask, | |
5453 | .get_survey = ath11k_mac_op_get_survey, | |
5454 | .flush = ath11k_mac_op_flush, | |
5455 | .sta_statistics = ath11k_mac_op_sta_statistics, | |
5456 | CFG80211_TESTMODE_CMD(ath11k_tm_cmd) | |
5457 | #ifdef CONFIG_MAC80211_DEBUGFS | |
5458 | .sta_add_debugfs = ath11k_sta_add_debugfs, | |
5459 | #endif | |
5460 | }; | |
5461 | ||
5462 | static const struct ieee80211_iface_limit ath11k_if_limits[] = { | |
5463 | { | |
5464 | .max = 1, | |
5465 | .types = BIT(NL80211_IFTYPE_STATION), | |
5466 | }, | |
5467 | { | |
5468 | .max = 16, | |
5469 | .types = BIT(NL80211_IFTYPE_AP) | |
5470 | #ifdef CONFIG_MAC80211_MESH | |
5471 | | BIT(NL80211_IFTYPE_MESH_POINT) | |
5472 | #endif | |
5473 | }, | |
5474 | }; | |
5475 | ||
5476 | static const struct ieee80211_iface_combination ath11k_if_comb[] = { | |
5477 | { | |
5478 | .limits = ath11k_if_limits, | |
5479 | .n_limits = ARRAY_SIZE(ath11k_if_limits), | |
5480 | .max_interfaces = 16, | |
5481 | .num_different_channels = 1, | |
5482 | .beacon_int_infra_match = true, | |
5483 | .beacon_int_min_gcd = 100, | |
5484 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
5485 | BIT(NL80211_CHAN_WIDTH_20) | | |
5486 | BIT(NL80211_CHAN_WIDTH_40) | | |
5487 | BIT(NL80211_CHAN_WIDTH_80), | |
5488 | }, | |
5489 | }; | |
5490 | ||
5491 | static void ath11k_mac_update_ch_list(struct ath11k *ar, | |
5492 | struct ieee80211_supported_band *band, | |
5493 | u32 freq_low, u32 freq_high) | |
5494 | { | |
5495 | int i; | |
5496 | ||
5497 | if (!(freq_low && freq_high)) | |
5498 | return; | |
5499 | ||
5500 | for (i = 0; i < band->n_channels; i++) { | |
5501 | if (band->channels[i].center_freq < freq_low || | |
5502 | band->channels[i].center_freq > freq_high) | |
5503 | band->channels[i].flags |= IEEE80211_CHAN_DISABLED; | |
5504 | } | |
5505 | } | |
5506 | ||
5507 | static int ath11k_mac_setup_channels_rates(struct ath11k *ar, | |
5508 | u32 supported_bands) | |
5509 | { | |
5510 | struct ieee80211_supported_band *band; | |
5511 | struct ath11k_hal_reg_capabilities_ext *reg_cap; | |
5512 | void *channels; | |
5513 | ||
5514 | BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) + | |
5515 | ARRAY_SIZE(ath11k_5ghz_channels)) != | |
5516 | ATH11K_NUM_CHANS); | |
5517 | ||
5518 | reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx]; | |
5519 | ||
5520 | if (supported_bands & WMI_HOST_WLAN_2G_CAP) { | |
5521 | channels = kmemdup(ath11k_2ghz_channels, | |
5522 | sizeof(ath11k_2ghz_channels), | |
5523 | GFP_KERNEL); | |
5524 | if (!channels) | |
5525 | return -ENOMEM; | |
5526 | ||
5527 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; | |
5528 | band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels); | |
5529 | band->channels = channels; | |
5530 | band->n_bitrates = ath11k_g_rates_size; | |
5531 | band->bitrates = ath11k_g_rates; | |
5532 | ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band; | |
5533 | ath11k_mac_update_ch_list(ar, band, | |
5534 | reg_cap->low_2ghz_chan, | |
5535 | reg_cap->high_2ghz_chan); | |
5536 | } | |
5537 | ||
5538 | if (supported_bands & WMI_HOST_WLAN_5G_CAP) { | |
5539 | channels = kmemdup(ath11k_5ghz_channels, | |
5540 | sizeof(ath11k_5ghz_channels), | |
5541 | GFP_KERNEL); | |
5542 | if (!channels) { | |
5543 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
5544 | return -ENOMEM; | |
5545 | } | |
5546 | ||
5547 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; | |
5548 | band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels); | |
5549 | band->channels = channels; | |
5550 | band->n_bitrates = ath11k_a_rates_size; | |
5551 | band->bitrates = ath11k_a_rates; | |
5552 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band; | |
5553 | ath11k_mac_update_ch_list(ar, band, | |
5554 | reg_cap->low_5ghz_chan, | |
5555 | reg_cap->high_5ghz_chan); | |
5556 | } | |
5557 | ||
5558 | return 0; | |
5559 | } | |
5560 | ||
5561 | static const u8 ath11k_if_types_ext_capa[] = { | |
5562 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5563 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
5564 | }; | |
5565 | ||
5566 | static const u8 ath11k_if_types_ext_capa_sta[] = { | |
5567 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5568 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
5569 | [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, | |
5570 | }; | |
5571 | ||
5572 | static const u8 ath11k_if_types_ext_capa_ap[] = { | |
5573 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5574 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, | |
5575 | [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, | |
5576 | }; | |
5577 | ||
5578 | static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = { | |
5579 | { | |
5580 | .extended_capabilities = ath11k_if_types_ext_capa, | |
5581 | .extended_capabilities_mask = ath11k_if_types_ext_capa, | |
5582 | .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa), | |
5583 | }, { | |
5584 | .iftype = NL80211_IFTYPE_STATION, | |
5585 | .extended_capabilities = ath11k_if_types_ext_capa_sta, | |
5586 | .extended_capabilities_mask = ath11k_if_types_ext_capa_sta, | |
5587 | .extended_capabilities_len = | |
5588 | sizeof(ath11k_if_types_ext_capa_sta), | |
5589 | }, { | |
5590 | .iftype = NL80211_IFTYPE_AP, | |
5591 | .extended_capabilities = ath11k_if_types_ext_capa_ap, | |
5592 | .extended_capabilities_mask = ath11k_if_types_ext_capa_ap, | |
5593 | .extended_capabilities_len = | |
5594 | sizeof(ath11k_if_types_ext_capa_ap), | |
5595 | }, | |
5596 | }; | |
5597 | ||
0366f426 VT |
5598 | static void __ath11k_mac_unregister(struct ath11k *ar) |
5599 | { | |
5600 | cancel_work_sync(&ar->regd_update_work); | |
5601 | ||
5602 | ieee80211_unregister_hw(ar->hw); | |
5603 | ||
5604 | idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar); | |
5605 | idr_destroy(&ar->txmgmt_idr); | |
5606 | ||
5607 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
5608 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
5609 | ||
5610 | SET_IEEE80211_DEV(ar->hw, NULL); | |
5611 | } | |
5612 | ||
5613 | void ath11k_mac_unregister(struct ath11k_base *ab) | |
5614 | { | |
5615 | struct ath11k *ar; | |
5616 | struct ath11k_pdev *pdev; | |
5617 | int i; | |
5618 | ||
5619 | for (i = 0; i < ab->num_radios; i++) { | |
5620 | pdev = &ab->pdevs[i]; | |
5621 | ar = pdev->ar; | |
5622 | if (!ar) | |
5623 | continue; | |
5624 | ||
5625 | __ath11k_mac_unregister(ar); | |
5626 | } | |
5627 | } | |
5628 | ||
5629 | static int __ath11k_mac_register(struct ath11k *ar) | |
d5c65159 KV |
5630 | { |
5631 | struct ath11k_base *ab = ar->ab; | |
5632 | struct ath11k_pdev_cap *cap = &ar->pdev->cap; | |
5633 | static const u32 cipher_suites[] = { | |
5634 | WLAN_CIPHER_SUITE_TKIP, | |
5635 | WLAN_CIPHER_SUITE_CCMP, | |
5636 | WLAN_CIPHER_SUITE_AES_CMAC, | |
5637 | WLAN_CIPHER_SUITE_BIP_CMAC_256, | |
5638 | WLAN_CIPHER_SUITE_BIP_GMAC_128, | |
5639 | WLAN_CIPHER_SUITE_BIP_GMAC_256, | |
5640 | WLAN_CIPHER_SUITE_GCMP, | |
5641 | WLAN_CIPHER_SUITE_GCMP_256, | |
5642 | WLAN_CIPHER_SUITE_CCMP_256, | |
5643 | }; | |
5644 | int ret; | |
5645 | u32 ht_cap = 0; | |
5646 | ||
5647 | ath11k_pdev_caps_update(ar); | |
5648 | ||
5649 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); | |
5650 | ||
5651 | SET_IEEE80211_DEV(ar->hw, ab->dev); | |
5652 | ||
5653 | ret = ath11k_mac_setup_channels_rates(ar, | |
5654 | cap->supported_bands); | |
5655 | if (ret) | |
5656 | goto err_free; | |
5657 | ||
5658 | ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap); | |
9f056ed8 | 5659 | ath11k_mac_setup_he_cap(ar, cap); |
d5c65159 KV |
5660 | |
5661 | ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask; | |
5662 | ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask; | |
5663 | ||
5664 | ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
5665 | BIT(NL80211_IFTYPE_AP) | | |
5666 | BIT(NL80211_IFTYPE_MESH_POINT); | |
5667 | ||
5668 | ieee80211_hw_set(ar->hw, SIGNAL_DBM); | |
5669 | ieee80211_hw_set(ar->hw, SUPPORTS_PS); | |
5670 | ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS); | |
5671 | ieee80211_hw_set(ar->hw, MFP_CAPABLE); | |
5672 | ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS); | |
5673 | ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL); | |
5674 | ieee80211_hw_set(ar->hw, AP_LINK_PS); | |
5675 | ieee80211_hw_set(ar->hw, SPECTRUM_MGMT); | |
5676 | ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT); | |
5677 | ieee80211_hw_set(ar->hw, CONNECTION_MONITOR); | |
5678 | ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK); | |
5679 | ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF); | |
5680 | ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA); | |
5681 | ieee80211_hw_set(ar->hw, QUEUE_CONTROL); | |
5682 | ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG); | |
5683 | ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK); | |
5684 | if (ht_cap & WMI_HT_CAP_ENABLED) { | |
5685 | ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION); | |
5686 | ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW); | |
5687 | ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER); | |
5688 | ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU); | |
5689 | } | |
5690 | ||
5691 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; | |
5692 | ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; | |
5693 | ||
5694 | /* TODO: Check if HT capability advertised from firmware is different | |
5695 | * for each band for a dual band capable radio. It will be tricky to | |
5696 | * handle it when the ht capability different for each band. | |
5697 | */ | |
5698 | if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) | |
5699 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; | |
5700 | ||
5701 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; | |
5702 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; | |
5703 | ||
5704 | ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL; | |
5705 | ||
5706 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; | |
5707 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; | |
5708 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; | |
5709 | ||
5710 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; | |
5711 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | | |
5712 | NL80211_FEATURE_AP_SCAN; | |
5713 | ||
5714 | ar->max_num_stations = TARGET_NUM_STATIONS; | |
5715 | ar->max_num_peers = TARGET_NUM_PEERS_PDEV; | |
5716 | ||
5717 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; | |
5718 | ||
5719 | ar->hw->queues = ATH11K_HW_MAX_QUEUES; | |
5720 | ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1; | |
5721 | ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; | |
5722 | ||
5723 | ar->hw->vif_data_size = sizeof(struct ath11k_vif); | |
5724 | ar->hw->sta_data_size = sizeof(struct ath11k_sta); | |
5725 | ||
5726 | ar->hw->wiphy->iface_combinations = ath11k_if_comb; | |
5727 | ar->hw->wiphy->n_iface_combinations = ARRAY_SIZE(ath11k_if_comb); | |
5728 | ||
5729 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); | |
64f1d7e9 | 5730 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR); |
d5c65159 KV |
5731 | |
5732 | ar->hw->wiphy->cipher_suites = cipher_suites; | |
5733 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
5734 | ||
5735 | ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa; | |
5736 | ar->hw->wiphy->num_iftype_ext_capab = | |
5737 | ARRAY_SIZE(ath11k_iftypes_ext_capa); | |
5738 | ||
5739 | ath11k_reg_init(ar); | |
5740 | ||
5741 | /* advertise HW checksum offload capabilities */ | |
5742 | ar->hw->netdev_features = NETIF_F_HW_CSUM; | |
5743 | ||
5744 | ret = ieee80211_register_hw(ar->hw); | |
5745 | if (ret) { | |
5746 | ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret); | |
5747 | goto err_free; | |
5748 | } | |
5749 | ||
5750 | /* Apply the regd received during initialization */ | |
5751 | ret = ath11k_regd_update(ar, true); | |
5752 | if (ret) { | |
5753 | ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret); | |
5754 | goto err_free; | |
5755 | } | |
5756 | ||
5757 | ret = ath11k_debug_register(ar); | |
5758 | if (ret) { | |
5759 | ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret); | |
5760 | goto err_free; | |
5761 | } | |
5762 | ||
5763 | return 0; | |
5764 | ||
5765 | err_free: | |
5766 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); | |
5767 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); | |
5768 | ||
5769 | SET_IEEE80211_DEV(ar->hw, NULL); | |
5770 | return ret; | |
5771 | } | |
5772 | ||
0366f426 | 5773 | int ath11k_mac_register(struct ath11k_base *ab) |
d5c65159 KV |
5774 | { |
5775 | struct ath11k *ar; | |
5776 | struct ath11k_pdev *pdev; | |
5777 | int i; | |
0366f426 | 5778 | int ret; |
d5c65159 KV |
5779 | |
5780 | for (i = 0; i < ab->num_radios; i++) { | |
5781 | pdev = &ab->pdevs[i]; | |
5782 | ar = pdev->ar; | |
0366f426 VT |
5783 | if (ab->pdevs_macaddr_valid) { |
5784 | ether_addr_copy(ar->mac_addr, pdev->mac_addr); | |
5785 | } else { | |
5786 | ether_addr_copy(ar->mac_addr, ab->mac_addr); | |
5787 | ar->mac_addr[4] += i; | |
5788 | } | |
d5c65159 | 5789 | |
0366f426 VT |
5790 | ret = __ath11k_mac_register(ar); |
5791 | if (ret) | |
5792 | goto err_cleanup; | |
d5c65159 | 5793 | |
0366f426 VT |
5794 | idr_init(&ar->txmgmt_idr); |
5795 | spin_lock_init(&ar->txmgmt_idr_lock); | |
5796 | } | |
d5c65159 | 5797 | |
0366f426 VT |
5798 | /* Initialize channel counters frequency value in hertz */ |
5799 | ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ; | |
5800 | ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1; | |
5801 | ||
5802 | return 0; | |
d5c65159 | 5803 | |
0366f426 VT |
5804 | err_cleanup: |
5805 | for (i = i - 1; i >= 0; i--) { | |
5806 | pdev = &ab->pdevs[i]; | |
5807 | ar = pdev->ar; | |
5808 | __ath11k_mac_unregister(ar); | |
d5c65159 | 5809 | } |
0366f426 VT |
5810 | |
5811 | return ret; | |
d5c65159 KV |
5812 | } |
5813 | ||
0366f426 | 5814 | int ath11k_mac_allocate(struct ath11k_base *ab) |
d5c65159 KV |
5815 | { |
5816 | struct ieee80211_hw *hw; | |
5817 | struct ath11k *ar; | |
5818 | struct ath11k_pdev *pdev; | |
5819 | int ret; | |
5820 | int i; | |
5821 | ||
5822 | if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) | |
5823 | return 0; | |
5824 | ||
5825 | for (i = 0; i < ab->num_radios; i++) { | |
5826 | pdev = &ab->pdevs[i]; | |
5827 | hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops); | |
5828 | if (!hw) { | |
5829 | ath11k_warn(ab, "failed to allocate mac80211 hw device\n"); | |
5830 | ret = -ENOMEM; | |
0366f426 | 5831 | goto err_free_mac; |
d5c65159 KV |
5832 | } |
5833 | ||
5834 | ar = hw->priv; | |
5835 | ar->hw = hw; | |
5836 | ar->ab = ab; | |
5837 | ar->pdev = pdev; | |
5838 | ar->pdev_idx = i; | |
5839 | ar->lmac_id = ath11k_core_get_hw_mac_id(ab, i); | |
5840 | ||
6bc9d6f7 | 5841 | ar->wmi = &ab->wmi_ab.wmi[i]; |
d5c65159 KV |
5842 | /* FIXME wmi[0] is already initialized during attach, |
5843 | * Should we do this again? | |
5844 | */ | |
5845 | ath11k_wmi_pdev_attach(ab, i); | |
5846 | ||
5847 | ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask; | |
5848 | ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask; | |
5849 | ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask); | |
5850 | ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask); | |
5851 | ||
d5c65159 KV |
5852 | pdev->ar = ar; |
5853 | spin_lock_init(&ar->data_lock); | |
5854 | INIT_LIST_HEAD(&ar->arvifs); | |
5855 | INIT_LIST_HEAD(&ar->ppdu_stats_info); | |
5856 | mutex_init(&ar->conf_mutex); | |
5857 | init_completion(&ar->vdev_setup_done); | |
5858 | init_completion(&ar->peer_assoc_done); | |
5859 | init_completion(&ar->install_key_done); | |
5860 | init_completion(&ar->bss_survey_done); | |
5861 | init_completion(&ar->scan.started); | |
5862 | init_completion(&ar->scan.completed); | |
5863 | INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work); | |
5864 | INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work); | |
5865 | ||
5866 | INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work); | |
5867 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); | |
5868 | clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags); | |
d5c65159 KV |
5869 | } |
5870 | ||
d5c65159 KV |
5871 | return 0; |
5872 | ||
0366f426 | 5873 | err_free_mac: |
d5c65159 KV |
5874 | ath11k_mac_destroy(ab); |
5875 | ||
5876 | return ret; | |
5877 | } | |
5878 | ||
5879 | void ath11k_mac_destroy(struct ath11k_base *ab) | |
5880 | { | |
5881 | struct ath11k *ar; | |
5882 | struct ath11k_pdev *pdev; | |
5883 | int i; | |
5884 | ||
5885 | for (i = 0; i < ab->num_radios; i++) { | |
5886 | pdev = &ab->pdevs[i]; | |
5887 | ar = pdev->ar; | |
5888 | if (!ar) | |
5889 | continue; | |
5890 | ||
5891 | ieee80211_free_hw(ar->hw); | |
5892 | pdev->ar = NULL; | |
5893 | } | |
5894 | } |