Loading...
Note: File does not exist in v4.10.11.
1// SPDX-License-Identifier: BSD-3-Clause-Clear
2/*
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
5 */
6#include <linux/skbuff.h>
7#include <linux/ctype.h>
8#include <net/mac80211.h>
9#include <net/cfg80211.h>
10#include <linux/completion.h>
11#include <linux/if_ether.h>
12#include <linux/types.h>
13#include <linux/pci.h>
14#include <linux/uuid.h>
15#include <linux/time.h>
16#include <linux/of.h>
17#include "core.h"
18#include "debug.h"
19#include "mac.h"
20#include "hw.h"
21#include "peer.h"
22#include "testmode.h"
23
24struct wmi_tlv_policy {
25 size_t min_len;
26};
27
28struct wmi_tlv_svc_ready_parse {
29 bool wmi_svc_bitmap_done;
30};
31
32struct wmi_tlv_dma_ring_caps_parse {
33 struct wmi_dma_ring_capabilities *dma_ring_caps;
34 u32 n_dma_ring_caps;
35};
36
37struct wmi_tlv_svc_rdy_ext_parse {
38 struct ath11k_service_ext_param param;
39 struct wmi_soc_mac_phy_hw_mode_caps *hw_caps;
40 struct wmi_hw_mode_capabilities *hw_mode_caps;
41 u32 n_hw_mode_caps;
42 u32 tot_phy_id;
43 struct wmi_hw_mode_capabilities pref_hw_mode_caps;
44 struct wmi_mac_phy_capabilities *mac_phy_caps;
45 u32 n_mac_phy_caps;
46 struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps;
47 struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps;
48 u32 n_ext_hal_reg_caps;
49 struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
50 bool hw_mode_done;
51 bool mac_phy_done;
52 bool ext_hal_reg_done;
53 bool mac_phy_chainmask_combo_done;
54 bool mac_phy_chainmask_cap_done;
55 bool oem_dma_ring_cap_done;
56 bool dma_ring_cap_done;
57};
58
59struct wmi_tlv_svc_rdy_ext2_parse {
60 struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
61 bool dma_ring_cap_done;
62};
63
64struct wmi_tlv_rdy_parse {
65 u32 num_extra_mac_addr;
66};
67
68struct wmi_tlv_dma_buf_release_parse {
69 struct ath11k_wmi_dma_buf_release_fixed_param fixed;
70 struct wmi_dma_buf_release_entry *buf_entry;
71 struct wmi_dma_buf_release_meta_data *meta_data;
72 u32 num_buf_entry;
73 u32 num_meta;
74 bool buf_entry_done;
75 bool meta_data_done;
76};
77
78struct wmi_tlv_fw_stats_parse {
79 const struct wmi_stats_event *ev;
80 const struct wmi_per_chain_rssi_stats *rssi;
81 struct ath11k_fw_stats *stats;
82 int rssi_num;
83 bool chain_rssi_done;
84};
85
86struct wmi_tlv_mgmt_rx_parse {
87 const struct wmi_mgmt_rx_hdr *fixed;
88 const u8 *frame_buf;
89 bool frame_buf_done;
90};
91
92static const struct wmi_tlv_policy wmi_tlv_policies[] = {
93 [WMI_TAG_ARRAY_BYTE]
94 = { .min_len = 0 },
95 [WMI_TAG_ARRAY_UINT32]
96 = { .min_len = 0 },
97 [WMI_TAG_SERVICE_READY_EVENT]
98 = { .min_len = sizeof(struct wmi_service_ready_event) },
99 [WMI_TAG_SERVICE_READY_EXT_EVENT]
100 = { .min_len = sizeof(struct wmi_service_ready_ext_event) },
101 [WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS]
102 = { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) },
103 [WMI_TAG_SOC_HAL_REG_CAPABILITIES]
104 = { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) },
105 [WMI_TAG_VDEV_START_RESPONSE_EVENT]
106 = { .min_len = sizeof(struct wmi_vdev_start_resp_event) },
107 [WMI_TAG_PEER_DELETE_RESP_EVENT]
108 = { .min_len = sizeof(struct wmi_peer_delete_resp_event) },
109 [WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]
110 = { .min_len = sizeof(struct wmi_bcn_tx_status_event) },
111 [WMI_TAG_VDEV_STOPPED_EVENT]
112 = { .min_len = sizeof(struct wmi_vdev_stopped_event) },
113 [WMI_TAG_REG_CHAN_LIST_CC_EVENT]
114 = { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) },
115 [WMI_TAG_REG_CHAN_LIST_CC_EXT_EVENT]
116 = { .min_len = sizeof(struct wmi_reg_chan_list_cc_ext_event) },
117 [WMI_TAG_MGMT_RX_HDR]
118 = { .min_len = sizeof(struct wmi_mgmt_rx_hdr) },
119 [WMI_TAG_MGMT_TX_COMPL_EVENT]
120 = { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) },
121 [WMI_TAG_SCAN_EVENT]
122 = { .min_len = sizeof(struct wmi_scan_event) },
123 [WMI_TAG_PEER_STA_KICKOUT_EVENT]
124 = { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
125 [WMI_TAG_ROAM_EVENT]
126 = { .min_len = sizeof(struct wmi_roam_event) },
127 [WMI_TAG_CHAN_INFO_EVENT]
128 = { .min_len = sizeof(struct wmi_chan_info_event) },
129 [WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]
130 = { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) },
131 [WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]
132 = { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) },
133 [WMI_TAG_READY_EVENT] = {
134 .min_len = sizeof(struct wmi_ready_event_min) },
135 [WMI_TAG_SERVICE_AVAILABLE_EVENT]
136 = {.min_len = sizeof(struct wmi_service_available_event) },
137 [WMI_TAG_PEER_ASSOC_CONF_EVENT]
138 = { .min_len = sizeof(struct wmi_peer_assoc_conf_event) },
139 [WMI_TAG_STATS_EVENT]
140 = { .min_len = sizeof(struct wmi_stats_event) },
141 [WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]
142 = { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) },
143 [WMI_TAG_HOST_SWFDA_EVENT] = {
144 .min_len = sizeof(struct wmi_fils_discovery_event) },
145 [WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT] = {
146 .min_len = sizeof(struct wmi_probe_resp_tx_status_event) },
147 [WMI_TAG_VDEV_DELETE_RESP_EVENT] = {
148 .min_len = sizeof(struct wmi_vdev_delete_resp_event) },
149 [WMI_TAG_OBSS_COLOR_COLLISION_EVT] = {
150 .min_len = sizeof(struct wmi_obss_color_collision_event) },
151 [WMI_TAG_11D_NEW_COUNTRY_EVENT] = {
152 .min_len = sizeof(struct wmi_11d_new_cc_ev) },
153 [WMI_TAG_PER_CHAIN_RSSI_STATS] = {
154 .min_len = sizeof(struct wmi_per_chain_rssi_stats) },
155 [WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT] = {
156 .min_len = sizeof(struct wmi_twt_add_dialog_event) },
157};
158
159#define PRIMAP(_hw_mode_) \
160 [_hw_mode_] = _hw_mode_##_PRI
161
162static const int ath11k_hw_mode_pri_map[] = {
163 PRIMAP(WMI_HOST_HW_MODE_SINGLE),
164 PRIMAP(WMI_HOST_HW_MODE_DBS),
165 PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE),
166 PRIMAP(WMI_HOST_HW_MODE_SBS),
167 PRIMAP(WMI_HOST_HW_MODE_DBS_SBS),
168 PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS),
169 /* keep last */
170 PRIMAP(WMI_HOST_HW_MODE_MAX),
171};
172
173static int
174ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
175 int (*iter)(struct ath11k_base *ab, u16 tag, u16 len,
176 const void *ptr, void *data),
177 void *data)
178{
179 const void *begin = ptr;
180 const struct wmi_tlv *tlv;
181 u16 tlv_tag, tlv_len;
182 int ret;
183
184 while (len > 0) {
185 if (len < sizeof(*tlv)) {
186 ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
187 ptr - begin, len, sizeof(*tlv));
188 return -EINVAL;
189 }
190
191 tlv = ptr;
192 tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header);
193 tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header);
194 ptr += sizeof(*tlv);
195 len -= sizeof(*tlv);
196
197 if (tlv_len > len) {
198 ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n",
199 tlv_tag, ptr - begin, len, tlv_len);
200 return -EINVAL;
201 }
202
203 if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
204 wmi_tlv_policies[tlv_tag].min_len &&
205 wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
206 ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%u bytes is less than min length %zu)\n",
207 tlv_tag, ptr - begin, tlv_len,
208 wmi_tlv_policies[tlv_tag].min_len);
209 return -EINVAL;
210 }
211
212 ret = iter(ab, tlv_tag, tlv_len, ptr, data);
213 if (ret)
214 return ret;
215
216 ptr += tlv_len;
217 len -= tlv_len;
218 }
219
220 return 0;
221}
222
223static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len,
224 const void *ptr, void *data)
225{
226 const void **tb = data;
227
228 if (tag < WMI_TAG_MAX)
229 tb[tag] = ptr;
230
231 return 0;
232}
233
234static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb,
235 const void *ptr, size_t len)
236{
237 return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse,
238 (void *)tb);
239}
240
241const void **ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr,
242 size_t len, gfp_t gfp)
243{
244 const void **tb;
245 int ret;
246
247 tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp);
248 if (!tb)
249 return ERR_PTR(-ENOMEM);
250
251 ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len);
252 if (ret) {
253 kfree(tb);
254 return ERR_PTR(ret);
255 }
256
257 return tb;
258}
259
260static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
261 u32 cmd_id)
262{
263 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
264 struct ath11k_base *ab = wmi->wmi_ab->ab;
265 struct wmi_cmd_hdr *cmd_hdr;
266 int ret;
267 u32 cmd = 0;
268
269 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
270 return -ENOMEM;
271
272 cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id);
273
274 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
275 cmd_hdr->cmd_id = cmd;
276
277 trace_ath11k_wmi_cmd(ab, cmd_id, skb->data, skb->len);
278
279 memset(skb_cb, 0, sizeof(*skb_cb));
280 ret = ath11k_htc_send(&ab->htc, wmi->eid, skb);
281
282 if (ret)
283 goto err_pull;
284
285 return 0;
286
287err_pull:
288 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
289 return ret;
290}
291
292int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
293 u32 cmd_id)
294{
295 struct ath11k_wmi_base *wmi_ab = wmi->wmi_ab;
296 int ret = -EOPNOTSUPP;
297 struct ath11k_base *ab = wmi_ab->ab;
298
299 might_sleep();
300
301 if (ab->hw_params.credit_flow) {
302 wait_event_timeout(wmi_ab->tx_credits_wq, ({
303 ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
304
305 if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
306 &wmi_ab->ab->dev_flags))
307 ret = -ESHUTDOWN;
308
309 (ret != -EAGAIN);
310 }), WMI_SEND_TIMEOUT_HZ);
311 } else {
312 wait_event_timeout(wmi->tx_ce_desc_wq, ({
313 ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
314
315 if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
316 &wmi_ab->ab->dev_flags))
317 ret = -ESHUTDOWN;
318
319 (ret != -ENOBUFS);
320 }), WMI_SEND_TIMEOUT_HZ);
321 }
322
323 if (ret == -EAGAIN)
324 ath11k_warn(wmi_ab->ab, "wmi command %d timeout\n", cmd_id);
325
326 if (ret == -ENOBUFS)
327 ath11k_warn(wmi_ab->ab, "ce desc not available for wmi command %d\n",
328 cmd_id);
329
330 return ret;
331}
332
333static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
334 const void *ptr,
335 struct ath11k_service_ext_param *param)
336{
337 const struct wmi_service_ready_ext_event *ev = ptr;
338
339 if (!ev)
340 return -EINVAL;
341
342 /* Move this to host based bitmap */
343 param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits;
344 param->default_fw_config_bits = ev->default_fw_config_bits;
345 param->he_cap_info = ev->he_cap_info;
346 param->mpdu_density = ev->mpdu_density;
347 param->max_bssid_rx_filters = ev->max_bssid_rx_filters;
348 memcpy(¶m->ppet, &ev->ppet, sizeof(param->ppet));
349
350 return 0;
351}
352
353static int
354ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
355 struct wmi_soc_mac_phy_hw_mode_caps *hw_caps,
356 struct wmi_hw_mode_capabilities *wmi_hw_mode_caps,
357 struct wmi_soc_hal_reg_capabilities *hal_reg_caps,
358 struct wmi_mac_phy_capabilities *wmi_mac_phy_caps,
359 u8 hw_mode_id, u8 phy_id,
360 struct ath11k_pdev *pdev)
361{
362 struct wmi_mac_phy_capabilities *mac_phy_caps;
363 struct ath11k_base *ab = wmi_handle->wmi_ab->ab;
364 struct ath11k_band_cap *cap_band;
365 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
366 u32 phy_map;
367 u32 hw_idx, phy_idx = 0;
368
369 if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps)
370 return -EINVAL;
371
372 for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) {
373 if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id)
374 break;
375
376 phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map;
377 while (phy_map) {
378 phy_map >>= 1;
379 phy_idx++;
380 }
381 }
382
383 if (hw_idx == hw_caps->num_hw_modes)
384 return -EINVAL;
385
386 phy_idx += phy_id;
387 if (phy_id >= hal_reg_caps->num_phy)
388 return -EINVAL;
389
390 mac_phy_caps = wmi_mac_phy_caps + phy_idx;
391
392 pdev->pdev_id = mac_phy_caps->pdev_id;
393 pdev_cap->supported_bands |= mac_phy_caps->supported_bands;
394 pdev_cap->ampdu_density = mac_phy_caps->ampdu_density;
395 ab->target_pdev_ids[ab->target_pdev_count].supported_bands =
396 mac_phy_caps->supported_bands;
397 ab->target_pdev_ids[ab->target_pdev_count].pdev_id = mac_phy_caps->pdev_id;
398 ab->target_pdev_count++;
399
400 if (!(mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) &&
401 !(mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP))
402 return -EINVAL;
403
404 /* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from
405 * band to band for a single radio, need to see how this should be
406 * handled.
407 */
408 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
409 pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g;
410 pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g;
411 }
412
413 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
414 pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g;
415 pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g;
416 pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g;
417 pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g;
418 pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g;
419 pdev_cap->nss_ratio_enabled =
420 WMI_NSS_RATIO_ENABLE_DISABLE_GET(mac_phy_caps->nss_ratio);
421 pdev_cap->nss_ratio_info =
422 WMI_NSS_RATIO_INFO_GET(mac_phy_caps->nss_ratio);
423 }
424
425 /* tx/rx chainmask reported from fw depends on the actual hw chains used,
426 * For example, for 4x4 capable macphys, first 4 chains can be used for first
427 * mac and the remaining 4 chains can be used for the second mac or vice-versa.
428 * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0
429 * will be advertised for second mac or vice-versa. Compute the shift value
430 * for tx/rx chainmask which will be used to advertise supported ht/vht rates to
431 * mac80211.
432 */
433 pdev_cap->tx_chain_mask_shift =
434 find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32);
435 pdev_cap->rx_chain_mask_shift =
436 find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32);
437
438 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
439 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
440 cap_band->phy_id = mac_phy_caps->phy_id;
441 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g;
442 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g;
443 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g;
444 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext;
445 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g;
446 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g,
447 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
448 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g,
449 sizeof(struct ath11k_ppe_threshold));
450 }
451
452 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
453 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
454 cap_band->phy_id = mac_phy_caps->phy_id;
455 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
456 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
457 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
458 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
459 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
460 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
461 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
462 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
463 sizeof(struct ath11k_ppe_threshold));
464
465 cap_band = &pdev_cap->band[NL80211_BAND_6GHZ];
466 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
467 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
468 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
469 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
470 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
471 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
472 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
473 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
474 sizeof(struct ath11k_ppe_threshold));
475 }
476
477 return 0;
478}
479
480static int
481ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle,
482 struct wmi_soc_hal_reg_capabilities *reg_caps,
483 struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap,
484 u8 phy_idx,
485 struct ath11k_hal_reg_capabilities_ext *param)
486{
487 struct wmi_hal_reg_capabilities_ext *ext_reg_cap;
488
489 if (!reg_caps || !wmi_ext_reg_cap)
490 return -EINVAL;
491
492 if (phy_idx >= reg_caps->num_phy)
493 return -EINVAL;
494
495 ext_reg_cap = &wmi_ext_reg_cap[phy_idx];
496
497 param->phy_id = ext_reg_cap->phy_id;
498 param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain;
499 param->eeprom_reg_domain_ext =
500 ext_reg_cap->eeprom_reg_domain_ext;
501 param->regcap1 = ext_reg_cap->regcap1;
502 param->regcap2 = ext_reg_cap->regcap2;
503 /* check if param->wireless_mode is needed */
504 param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan;
505 param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan;
506 param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan;
507 param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan;
508
509 return 0;
510}
511
512static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab,
513 const void *evt_buf,
514 struct ath11k_targ_cap *cap)
515{
516 const struct wmi_service_ready_event *ev = evt_buf;
517
518 if (!ev) {
519 ath11k_err(ab, "%s: failed by NULL param\n",
520 __func__);
521 return -EINVAL;
522 }
523
524 cap->phy_capability = ev->phy_capability;
525 cap->max_frag_entry = ev->max_frag_entry;
526 cap->num_rf_chains = ev->num_rf_chains;
527 cap->ht_cap_info = ev->ht_cap_info;
528 cap->vht_cap_info = ev->vht_cap_info;
529 cap->vht_supp_mcs = ev->vht_supp_mcs;
530 cap->hw_min_tx_power = ev->hw_min_tx_power;
531 cap->hw_max_tx_power = ev->hw_max_tx_power;
532 cap->sys_cap_info = ev->sys_cap_info;
533 cap->min_pkt_size_enable = ev->min_pkt_size_enable;
534 cap->max_bcn_ie_size = ev->max_bcn_ie_size;
535 cap->max_num_scan_channels = ev->max_num_scan_channels;
536 cap->max_supported_macs = ev->max_supported_macs;
537 cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps;
538 cap->txrx_chainmask = ev->txrx_chainmask;
539 cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index;
540 cap->num_msdu_desc = ev->num_msdu_desc;
541
542 return 0;
543}
544
545/* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in
546 * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each
547 * 4-byte word.
548 */
549static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi,
550 const u32 *wmi_svc_bm)
551{
552 int i, j;
553
554 for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) {
555 do {
556 if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32))
557 set_bit(j, wmi->wmi_ab->svc_map);
558 } while (++j % WMI_SERVICE_BITS_IN_SIZE32);
559 }
560}
561
562static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
563 const void *ptr, void *data)
564{
565 struct wmi_tlv_svc_ready_parse *svc_ready = data;
566 struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
567 u16 expect_len;
568
569 switch (tag) {
570 case WMI_TAG_SERVICE_READY_EVENT:
571 if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps))
572 return -EINVAL;
573 break;
574
575 case WMI_TAG_ARRAY_UINT32:
576 if (!svc_ready->wmi_svc_bitmap_done) {
577 expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32);
578 if (len < expect_len) {
579 ath11k_warn(ab, "invalid len %d for the tag 0x%x\n",
580 len, tag);
581 return -EINVAL;
582 }
583
584 ath11k_wmi_service_bitmap_copy(wmi_handle, ptr);
585
586 svc_ready->wmi_svc_bitmap_done = true;
587 }
588 break;
589 default:
590 break;
591 }
592
593 return 0;
594}
595
596static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
597{
598 struct wmi_tlv_svc_ready_parse svc_ready = { };
599 int ret;
600
601 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
602 ath11k_wmi_tlv_svc_rdy_parse,
603 &svc_ready);
604 if (ret) {
605 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
606 return ret;
607 }
608
609 ath11k_dbg(ab, ATH11K_DBG_WMI, "event service ready");
610
611 return 0;
612}
613
614struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_ab, u32 len)
615{
616 struct sk_buff *skb;
617 struct ath11k_base *ab = wmi_ab->ab;
618 u32 round_len = roundup(len, 4);
619
620 skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len);
621 if (!skb)
622 return NULL;
623
624 skb_reserve(skb, WMI_SKB_HEADROOM);
625 if (!IS_ALIGNED((unsigned long)skb->data, 4))
626 ath11k_warn(ab, "unaligned WMI skb data\n");
627
628 skb_put(skb, round_len);
629 memset(skb->data, 0, round_len);
630
631 return skb;
632}
633
634static u32 ath11k_wmi_mgmt_get_freq(struct ath11k *ar,
635 struct ieee80211_tx_info *info)
636{
637 struct ath11k_base *ab = ar->ab;
638 u32 freq = 0;
639
640 if (ab->hw_params.support_off_channel_tx &&
641 ar->scan.is_roc &&
642 (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
643 freq = ar->scan.roc_freq;
644
645 return freq;
646}
647
648int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id,
649 struct sk_buff *frame)
650{
651 struct ath11k_pdev_wmi *wmi = ar->wmi;
652 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(frame);
653 struct wmi_mgmt_send_cmd *cmd;
654 struct wmi_tlv *frame_tlv;
655 struct sk_buff *skb;
656 u32 buf_len;
657 int ret, len;
658
659 buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ?
660 frame->len : WMI_MGMT_SEND_DOWNLD_LEN;
661
662 len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4);
663
664 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
665 if (!skb)
666 return -ENOMEM;
667
668 cmd = (struct wmi_mgmt_send_cmd *)skb->data;
669 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) |
670 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
671 cmd->vdev_id = vdev_id;
672 cmd->desc_id = buf_id;
673 cmd->chanfreq = ath11k_wmi_mgmt_get_freq(ar, info);
674 cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr);
675 cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr);
676 cmd->frame_len = frame->len;
677 cmd->buf_len = buf_len;
678 cmd->tx_params_valid = 0;
679
680 frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
681 frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
682 FIELD_PREP(WMI_TLV_LEN, buf_len);
683
684 memcpy(frame_tlv->value, frame->data, buf_len);
685
686 ath11k_ce_byte_swap(frame_tlv->value, buf_len);
687
688 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID);
689 if (ret) {
690 ath11k_warn(ar->ab,
691 "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n");
692 dev_kfree_skb(skb);
693 }
694
695 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd mgmt tx send");
696
697 return ret;
698}
699
700int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr,
701 struct vdev_create_params *param)
702{
703 struct ath11k_pdev_wmi *wmi = ar->wmi;
704 struct wmi_vdev_create_cmd *cmd;
705 struct sk_buff *skb;
706 struct wmi_vdev_txrx_streams *txrx_streams;
707 struct wmi_tlv *tlv;
708 int ret, len;
709 void *ptr;
710
711 /* It can be optimized my sending tx/rx chain configuration
712 * only for supported bands instead of always sending it for
713 * both the bands.
714 */
715 len = sizeof(*cmd) + TLV_HDR_SIZE +
716 (WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams));
717
718 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
719 if (!skb)
720 return -ENOMEM;
721
722 cmd = (struct wmi_vdev_create_cmd *)skb->data;
723 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) |
724 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
725
726 cmd->vdev_id = param->if_id;
727 cmd->vdev_type = param->type;
728 cmd->vdev_subtype = param->subtype;
729 cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX;
730 cmd->pdev_id = param->pdev_id;
731 cmd->mbssid_flags = param->mbssid_flags;
732 cmd->mbssid_tx_vdev_id = param->mbssid_tx_vdev_id;
733
734 ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
735
736 ptr = skb->data + sizeof(*cmd);
737 len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams);
738
739 tlv = ptr;
740 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
741 FIELD_PREP(WMI_TLV_LEN, len);
742
743 ptr += TLV_HDR_SIZE;
744 txrx_streams = ptr;
745 len = sizeof(*txrx_streams);
746 txrx_streams->tlv_header =
747 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
748 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
749 txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G;
750 txrx_streams->supported_tx_streams =
751 param->chains[NL80211_BAND_2GHZ].tx;
752 txrx_streams->supported_rx_streams =
753 param->chains[NL80211_BAND_2GHZ].rx;
754
755 txrx_streams++;
756 txrx_streams->tlv_header =
757 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
758 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
759 txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G;
760 txrx_streams->supported_tx_streams =
761 param->chains[NL80211_BAND_5GHZ].tx;
762 txrx_streams->supported_rx_streams =
763 param->chains[NL80211_BAND_5GHZ].rx;
764
765 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID);
766 if (ret) {
767 ath11k_warn(ar->ab,
768 "failed to submit WMI_VDEV_CREATE_CMDID\n");
769 dev_kfree_skb(skb);
770 }
771
772 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
773 "cmd vdev create id %d type %d subtype %d macaddr %pM pdevid %d\n",
774 param->if_id, param->type, param->subtype,
775 macaddr, param->pdev_id);
776
777 return ret;
778}
779
780int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id)
781{
782 struct ath11k_pdev_wmi *wmi = ar->wmi;
783 struct wmi_vdev_delete_cmd *cmd;
784 struct sk_buff *skb;
785 int ret;
786
787 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
788 if (!skb)
789 return -ENOMEM;
790
791 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
792 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) |
793 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
794 cmd->vdev_id = vdev_id;
795
796 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID);
797 if (ret) {
798 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n");
799 dev_kfree_skb(skb);
800 }
801
802 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev delete id %d\n", vdev_id);
803
804 return ret;
805}
806
807int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id)
808{
809 struct ath11k_pdev_wmi *wmi = ar->wmi;
810 struct wmi_vdev_stop_cmd *cmd;
811 struct sk_buff *skb;
812 int ret;
813
814 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
815 if (!skb)
816 return -ENOMEM;
817
818 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
819
820 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) |
821 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
822 cmd->vdev_id = vdev_id;
823
824 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID);
825 if (ret) {
826 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n");
827 dev_kfree_skb(skb);
828 }
829
830 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev stop id 0x%x\n", vdev_id);
831
832 return ret;
833}
834
835int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id)
836{
837 struct ath11k_pdev_wmi *wmi = ar->wmi;
838 struct wmi_vdev_down_cmd *cmd;
839 struct sk_buff *skb;
840 int ret;
841
842 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
843 if (!skb)
844 return -ENOMEM;
845
846 cmd = (struct wmi_vdev_down_cmd *)skb->data;
847
848 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) |
849 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
850 cmd->vdev_id = vdev_id;
851
852 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID);
853 if (ret) {
854 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n");
855 dev_kfree_skb(skb);
856 }
857
858 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev down id 0x%x\n", vdev_id);
859
860 return ret;
861}
862
863static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan,
864 struct wmi_vdev_start_req_arg *arg)
865{
866 u32 center_freq1 = arg->channel.band_center_freq1;
867
868 memset(chan, 0, sizeof(*chan));
869
870 chan->mhz = arg->channel.freq;
871 chan->band_center_freq1 = arg->channel.band_center_freq1;
872
873 if (arg->channel.mode == MODE_11AX_HE160) {
874 if (arg->channel.freq > arg->channel.band_center_freq1)
875 chan->band_center_freq1 = center_freq1 + 40;
876 else
877 chan->band_center_freq1 = center_freq1 - 40;
878
879 chan->band_center_freq2 = arg->channel.band_center_freq1;
880
881 } else if ((arg->channel.mode == MODE_11AC_VHT80_80) ||
882 (arg->channel.mode == MODE_11AX_HE80_80)) {
883 chan->band_center_freq2 = arg->channel.band_center_freq2;
884 } else {
885 chan->band_center_freq2 = 0;
886 }
887
888 chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode);
889 if (arg->channel.passive)
890 chan->info |= WMI_CHAN_INFO_PASSIVE;
891 if (arg->channel.allow_ibss)
892 chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED;
893 if (arg->channel.allow_ht)
894 chan->info |= WMI_CHAN_INFO_ALLOW_HT;
895 if (arg->channel.allow_vht)
896 chan->info |= WMI_CHAN_INFO_ALLOW_VHT;
897 if (arg->channel.allow_he)
898 chan->info |= WMI_CHAN_INFO_ALLOW_HE;
899 if (arg->channel.ht40plus)
900 chan->info |= WMI_CHAN_INFO_HT40_PLUS;
901 if (arg->channel.chan_radar)
902 chan->info |= WMI_CHAN_INFO_DFS;
903 if (arg->channel.freq2_radar)
904 chan->info |= WMI_CHAN_INFO_DFS_FREQ2;
905
906 chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
907 arg->channel.max_power) |
908 FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
909 arg->channel.max_reg_power);
910
911 chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
912 arg->channel.max_antenna_gain) |
913 FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
914 arg->channel.max_power);
915}
916
917int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg,
918 bool restart)
919{
920 struct ath11k_pdev_wmi *wmi = ar->wmi;
921 struct wmi_vdev_start_request_cmd *cmd;
922 struct sk_buff *skb;
923 struct wmi_channel *chan;
924 struct wmi_tlv *tlv;
925 void *ptr;
926 int ret, len;
927
928 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
929 return -EINVAL;
930
931 len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE;
932
933 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
934 if (!skb)
935 return -ENOMEM;
936
937 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
938 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
939 WMI_TAG_VDEV_START_REQUEST_CMD) |
940 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
941 cmd->vdev_id = arg->vdev_id;
942 cmd->beacon_interval = arg->bcn_intval;
943 cmd->bcn_tx_rate = arg->bcn_tx_rate;
944 cmd->dtim_period = arg->dtim_period;
945 cmd->num_noa_descriptors = arg->num_noa_descriptors;
946 cmd->preferred_rx_streams = arg->pref_rx_streams;
947 cmd->preferred_tx_streams = arg->pref_tx_streams;
948 cmd->cac_duration_ms = arg->cac_duration_ms;
949 cmd->regdomain = arg->regdomain;
950 cmd->he_ops = arg->he_ops;
951 cmd->mbssid_flags = arg->mbssid_flags;
952 cmd->mbssid_tx_vdev_id = arg->mbssid_tx_vdev_id;
953
954 if (!restart) {
955 if (arg->ssid) {
956 cmd->ssid.ssid_len = arg->ssid_len;
957 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
958 }
959 if (arg->hidden_ssid)
960 cmd->flags |= WMI_VDEV_START_HIDDEN_SSID;
961 if (arg->pmf_enabled)
962 cmd->flags |= WMI_VDEV_START_PMF_ENABLED;
963 }
964
965 cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED;
966 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
967 cmd->flags |= WMI_VDEV_START_HW_ENCRYPTION_DISABLED;
968
969 ptr = skb->data + sizeof(*cmd);
970 chan = ptr;
971
972 ath11k_wmi_put_wmi_channel(chan, arg);
973
974 chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) |
975 FIELD_PREP(WMI_TLV_LEN,
976 sizeof(*chan) - TLV_HDR_SIZE);
977 ptr += sizeof(*chan);
978
979 tlv = ptr;
980 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
981 FIELD_PREP(WMI_TLV_LEN, 0);
982
983 /* Note: This is a nested TLV containing:
984 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
985 */
986
987 ptr += sizeof(*tlv);
988
989 if (restart)
990 ret = ath11k_wmi_cmd_send(wmi, skb,
991 WMI_VDEV_RESTART_REQUEST_CMDID);
992 else
993 ret = ath11k_wmi_cmd_send(wmi, skb,
994 WMI_VDEV_START_REQUEST_CMDID);
995 if (ret) {
996 ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n",
997 restart ? "restart" : "start");
998 dev_kfree_skb(skb);
999 }
1000
1001 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev %s id 0x%x freq 0x%x mode 0x%x\n",
1002 restart ? "restart" : "start", arg->vdev_id,
1003 arg->channel.freq, arg->channel.mode);
1004
1005 return ret;
1006}
1007
1008int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid,
1009 u8 *tx_bssid, u32 nontx_profile_idx, u32 nontx_profile_cnt)
1010{
1011 struct ath11k_pdev_wmi *wmi = ar->wmi;
1012 struct wmi_vdev_up_cmd *cmd;
1013 struct ieee80211_bss_conf *bss_conf;
1014 struct ath11k_vif *arvif;
1015 struct sk_buff *skb;
1016 int ret;
1017
1018 arvif = ath11k_mac_get_arvif(ar, vdev_id);
1019
1020 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1021 if (!skb)
1022 return -ENOMEM;
1023
1024 cmd = (struct wmi_vdev_up_cmd *)skb->data;
1025
1026 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) |
1027 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1028 cmd->vdev_id = vdev_id;
1029 cmd->vdev_assoc_id = aid;
1030
1031 ether_addr_copy(cmd->vdev_bssid.addr, bssid);
1032
1033 cmd->nontx_profile_idx = nontx_profile_idx;
1034 cmd->nontx_profile_cnt = nontx_profile_cnt;
1035 if (tx_bssid)
1036 ether_addr_copy(cmd->tx_vdev_bssid.addr, tx_bssid);
1037
1038 if (arvif && arvif->vif->type == NL80211_IFTYPE_STATION) {
1039 bss_conf = &arvif->vif->bss_conf;
1040
1041 if (bss_conf->nontransmitted) {
1042 ether_addr_copy(cmd->tx_vdev_bssid.addr,
1043 bss_conf->transmitter_bssid);
1044 cmd->nontx_profile_idx = bss_conf->bssid_index;
1045 cmd->nontx_profile_cnt = bss_conf->bssid_indicator;
1046 }
1047 }
1048
1049 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID);
1050 if (ret) {
1051 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n");
1052 dev_kfree_skb(skb);
1053 }
1054
1055 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1056 "cmd vdev up id 0x%x assoc id %d bssid %pM\n",
1057 vdev_id, aid, bssid);
1058
1059 return ret;
1060}
1061
1062int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar,
1063 struct peer_create_params *param)
1064{
1065 struct ath11k_pdev_wmi *wmi = ar->wmi;
1066 struct wmi_peer_create_cmd *cmd;
1067 struct sk_buff *skb;
1068 int ret;
1069
1070 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1071 if (!skb)
1072 return -ENOMEM;
1073
1074 cmd = (struct wmi_peer_create_cmd *)skb->data;
1075 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) |
1076 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1077
1078 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr);
1079 cmd->peer_type = param->peer_type;
1080 cmd->vdev_id = param->vdev_id;
1081
1082 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID);
1083 if (ret) {
1084 ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n");
1085 dev_kfree_skb(skb);
1086 }
1087
1088 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1089 "cmd peer create vdev_id %d peer_addr %pM\n",
1090 param->vdev_id, param->peer_addr);
1091
1092 return ret;
1093}
1094
1095int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar,
1096 const u8 *peer_addr, u8 vdev_id)
1097{
1098 struct ath11k_pdev_wmi *wmi = ar->wmi;
1099 struct wmi_peer_delete_cmd *cmd;
1100 struct sk_buff *skb;
1101 int ret;
1102
1103 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1104 if (!skb)
1105 return -ENOMEM;
1106
1107 cmd = (struct wmi_peer_delete_cmd *)skb->data;
1108 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) |
1109 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1110
1111 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1112 cmd->vdev_id = vdev_id;
1113
1114 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID);
1115 if (ret) {
1116 ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n");
1117 dev_kfree_skb(skb);
1118 }
1119
1120 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1121 "cmd peer delete vdev_id %d peer_addr %pM\n",
1122 vdev_id, peer_addr);
1123
1124 return ret;
1125}
1126
1127int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar,
1128 struct pdev_set_regdomain_params *param)
1129{
1130 struct ath11k_pdev_wmi *wmi = ar->wmi;
1131 struct wmi_pdev_set_regdomain_cmd *cmd;
1132 struct sk_buff *skb;
1133 int ret;
1134
1135 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1136 if (!skb)
1137 return -ENOMEM;
1138
1139 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1140 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1141 WMI_TAG_PDEV_SET_REGDOMAIN_CMD) |
1142 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1143
1144 cmd->reg_domain = param->current_rd_in_use;
1145 cmd->reg_domain_2g = param->current_rd_2g;
1146 cmd->reg_domain_5g = param->current_rd_5g;
1147 cmd->conformance_test_limit_2g = param->ctl_2g;
1148 cmd->conformance_test_limit_5g = param->ctl_5g;
1149 cmd->dfs_domain = param->dfs_domain;
1150 cmd->pdev_id = param->pdev_id;
1151
1152 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1153 if (ret) {
1154 ath11k_warn(ar->ab,
1155 "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n");
1156 dev_kfree_skb(skb);
1157 }
1158
1159 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1160 "cmd pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n",
1161 param->current_rd_in_use, param->current_rd_2g,
1162 param->current_rd_5g, param->dfs_domain, param->pdev_id);
1163
1164 return ret;
1165}
1166
1167int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr,
1168 u32 vdev_id, u32 param_id, u32 param_val)
1169{
1170 struct ath11k_pdev_wmi *wmi = ar->wmi;
1171 struct wmi_peer_set_param_cmd *cmd;
1172 struct sk_buff *skb;
1173 int ret;
1174
1175 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1176 if (!skb)
1177 return -ENOMEM;
1178
1179 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1180 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) |
1181 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1182 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1183 cmd->vdev_id = vdev_id;
1184 cmd->param_id = param_id;
1185 cmd->param_value = param_val;
1186
1187 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID);
1188 if (ret) {
1189 ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n");
1190 dev_kfree_skb(skb);
1191 }
1192
1193 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1194 "cmd peer set param vdev %d peer 0x%pM set param %d value %d\n",
1195 vdev_id, peer_addr, param_id, param_val);
1196
1197 return ret;
1198}
1199
1200int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar,
1201 u8 peer_addr[ETH_ALEN],
1202 struct peer_flush_params *param)
1203{
1204 struct ath11k_pdev_wmi *wmi = ar->wmi;
1205 struct wmi_peer_flush_tids_cmd *cmd;
1206 struct sk_buff *skb;
1207 int ret;
1208
1209 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1210 if (!skb)
1211 return -ENOMEM;
1212
1213 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1214 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) |
1215 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1216
1217 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1218 cmd->peer_tid_bitmap = param->peer_tid_bitmap;
1219 cmd->vdev_id = param->vdev_id;
1220
1221 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1222 if (ret) {
1223 ath11k_warn(ar->ab,
1224 "failed to send WMI_PEER_FLUSH_TIDS cmd\n");
1225 dev_kfree_skb(skb);
1226 }
1227
1228 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1229 "cmd peer flush tids vdev_id %d peer_addr %pM tids %08x\n",
1230 param->vdev_id, peer_addr, param->peer_tid_bitmap);
1231
1232 return ret;
1233}
1234
1235int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar,
1236 int vdev_id, const u8 *addr,
1237 dma_addr_t paddr, u8 tid,
1238 u8 ba_window_size_valid,
1239 u32 ba_window_size)
1240{
1241 struct wmi_peer_reorder_queue_setup_cmd *cmd;
1242 struct sk_buff *skb;
1243 int ret;
1244
1245 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
1246 if (!skb)
1247 return -ENOMEM;
1248
1249 cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data;
1250 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1251 WMI_TAG_REORDER_QUEUE_SETUP_CMD) |
1252 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1253
1254 ether_addr_copy(cmd->peer_macaddr.addr, addr);
1255 cmd->vdev_id = vdev_id;
1256 cmd->tid = tid;
1257 cmd->queue_ptr_lo = lower_32_bits(paddr);
1258 cmd->queue_ptr_hi = upper_32_bits(paddr);
1259 cmd->queue_no = tid;
1260 cmd->ba_window_size_valid = ba_window_size_valid;
1261 cmd->ba_window_size = ba_window_size;
1262
1263 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
1264 WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1265 if (ret) {
1266 ath11k_warn(ar->ab,
1267 "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n");
1268 dev_kfree_skb(skb);
1269 }
1270
1271 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1272 "cmd peer reorder queue setup addr %pM vdev_id %d tid %d\n",
1273 addr, vdev_id, tid);
1274
1275 return ret;
1276}
1277
1278int
1279ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar,
1280 struct rx_reorder_queue_remove_params *param)
1281{
1282 struct ath11k_pdev_wmi *wmi = ar->wmi;
1283 struct wmi_peer_reorder_queue_remove_cmd *cmd;
1284 struct sk_buff *skb;
1285 int ret;
1286
1287 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1288 if (!skb)
1289 return -ENOMEM;
1290
1291 cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data;
1292 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1293 WMI_TAG_REORDER_QUEUE_REMOVE_CMD) |
1294 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1295
1296 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr);
1297 cmd->vdev_id = param->vdev_id;
1298 cmd->tid_mask = param->peer_tid_bitmap;
1299
1300 ret = ath11k_wmi_cmd_send(wmi, skb,
1301 WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
1302 if (ret) {
1303 ath11k_warn(ar->ab,
1304 "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID");
1305 dev_kfree_skb(skb);
1306 }
1307
1308 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1309 "cmd peer reorder queue remove peer_macaddr %pM vdev_id %d tid_map %d",
1310 param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap);
1311
1312 return ret;
1313}
1314
1315int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id,
1316 u32 param_value, u8 pdev_id)
1317{
1318 struct ath11k_pdev_wmi *wmi = ar->wmi;
1319 struct wmi_pdev_set_param_cmd *cmd;
1320 struct sk_buff *skb;
1321 int ret;
1322
1323 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1324 if (!skb)
1325 return -ENOMEM;
1326
1327 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1328 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) |
1329 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1330 cmd->pdev_id = pdev_id;
1331 cmd->param_id = param_id;
1332 cmd->param_value = param_value;
1333
1334 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID);
1335 if (ret) {
1336 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1337 dev_kfree_skb(skb);
1338 }
1339
1340 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1341 "cmd pdev set param %d pdev id %d value %d\n",
1342 param_id, pdev_id, param_value);
1343
1344 return ret;
1345}
1346
1347int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id,
1348 enum wmi_sta_ps_mode psmode)
1349{
1350 struct ath11k_pdev_wmi *wmi = ar->wmi;
1351 struct wmi_pdev_set_ps_mode_cmd *cmd;
1352 struct sk_buff *skb;
1353 int ret;
1354
1355 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1356 if (!skb)
1357 return -ENOMEM;
1358
1359 cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data;
1360 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) |
1361 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1362 cmd->vdev_id = vdev_id;
1363 cmd->sta_ps_mode = psmode;
1364
1365 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID);
1366 if (ret) {
1367 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1368 dev_kfree_skb(skb);
1369 }
1370
1371 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1372 "cmd sta powersave mode psmode %d vdev id %d\n",
1373 psmode, vdev_id);
1374
1375 return ret;
1376}
1377
1378int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt,
1379 u32 pdev_id)
1380{
1381 struct ath11k_pdev_wmi *wmi = ar->wmi;
1382 struct wmi_pdev_suspend_cmd *cmd;
1383 struct sk_buff *skb;
1384 int ret;
1385
1386 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1387 if (!skb)
1388 return -ENOMEM;
1389
1390 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1391
1392 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) |
1393 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1394
1395 cmd->suspend_opt = suspend_opt;
1396 cmd->pdev_id = pdev_id;
1397
1398 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID);
1399 if (ret) {
1400 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n");
1401 dev_kfree_skb(skb);
1402 }
1403
1404 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1405 "cmd pdev suspend pdev_id %d\n", pdev_id);
1406
1407 return ret;
1408}
1409
1410int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id)
1411{
1412 struct ath11k_pdev_wmi *wmi = ar->wmi;
1413 struct wmi_pdev_resume_cmd *cmd;
1414 struct sk_buff *skb;
1415 int ret;
1416
1417 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1418 if (!skb)
1419 return -ENOMEM;
1420
1421 cmd = (struct wmi_pdev_resume_cmd *)skb->data;
1422
1423 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) |
1424 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1425 cmd->pdev_id = pdev_id;
1426
1427 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID);
1428 if (ret) {
1429 ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n");
1430 dev_kfree_skb(skb);
1431 }
1432
1433 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1434 "cmd pdev resume pdev id %d\n", pdev_id);
1435
1436 return ret;
1437}
1438
1439/* TODO FW Support for the cmd is not available yet.
1440 * Can be tested once the command and corresponding
1441 * event is implemented in FW
1442 */
1443int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar,
1444 enum wmi_bss_chan_info_req_type type)
1445{
1446 struct ath11k_pdev_wmi *wmi = ar->wmi;
1447 struct wmi_pdev_bss_chan_info_req_cmd *cmd;
1448 struct sk_buff *skb;
1449 int ret;
1450
1451 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1452 if (!skb)
1453 return -ENOMEM;
1454
1455 cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data;
1456
1457 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1458 WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) |
1459 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1460 cmd->req_type = type;
1461 cmd->pdev_id = ar->pdev->pdev_id;
1462
1463 ret = ath11k_wmi_cmd_send(wmi, skb,
1464 WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID);
1465 if (ret) {
1466 ath11k_warn(ar->ab,
1467 "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n");
1468 dev_kfree_skb(skb);
1469 }
1470
1471 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1472 "cmd pdev bss chan info request type %d\n", type);
1473
1474 return ret;
1475}
1476
1477int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr,
1478 struct ap_ps_params *param)
1479{
1480 struct ath11k_pdev_wmi *wmi = ar->wmi;
1481 struct wmi_ap_ps_peer_cmd *cmd;
1482 struct sk_buff *skb;
1483 int ret;
1484
1485 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1486 if (!skb)
1487 return -ENOMEM;
1488
1489 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1490 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) |
1491 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1492
1493 cmd->vdev_id = param->vdev_id;
1494 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1495 cmd->param = param->param;
1496 cmd->value = param->value;
1497
1498 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1499 if (ret) {
1500 ath11k_warn(ar->ab,
1501 "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n");
1502 dev_kfree_skb(skb);
1503 }
1504
1505 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1506 "cmd ap ps peer param vdev id %d peer %pM param %d value %d\n",
1507 param->vdev_id, peer_addr, param->param, param->value);
1508
1509 return ret;
1510}
1511
1512int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id,
1513 u32 param, u32 param_value)
1514{
1515 struct ath11k_pdev_wmi *wmi = ar->wmi;
1516 struct wmi_sta_powersave_param_cmd *cmd;
1517 struct sk_buff *skb;
1518 int ret;
1519
1520 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1521 if (!skb)
1522 return -ENOMEM;
1523
1524 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1525 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1526 WMI_TAG_STA_POWERSAVE_PARAM_CMD) |
1527 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1528
1529 cmd->vdev_id = vdev_id;
1530 cmd->param = param;
1531 cmd->value = param_value;
1532
1533 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1534 if (ret) {
1535 ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID");
1536 dev_kfree_skb(skb);
1537 }
1538
1539 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1540 "cmd set powersave param vdev_id %d param %d value %d\n",
1541 vdev_id, param, param_value);
1542
1543 return ret;
1544}
1545
1546int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms)
1547{
1548 struct ath11k_pdev_wmi *wmi = ar->wmi;
1549 struct wmi_force_fw_hang_cmd *cmd;
1550 struct sk_buff *skb;
1551 int ret, len;
1552
1553 len = sizeof(*cmd);
1554
1555 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1556 if (!skb)
1557 return -ENOMEM;
1558
1559 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
1560 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) |
1561 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1562
1563 cmd->type = type;
1564 cmd->delay_time_ms = delay_time_ms;
1565
1566 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID);
1567
1568 if (ret) {
1569 ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID");
1570 dev_kfree_skb(skb);
1571 }
1572
1573 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd force fw hang");
1574
1575 return ret;
1576}
1577
1578int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id,
1579 u32 param_id, u32 param_value)
1580{
1581 struct ath11k_pdev_wmi *wmi = ar->wmi;
1582 struct wmi_vdev_set_param_cmd *cmd;
1583 struct sk_buff *skb;
1584 int ret;
1585
1586 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1587 if (!skb)
1588 return -ENOMEM;
1589
1590 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1591 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) |
1592 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1593
1594 cmd->vdev_id = vdev_id;
1595 cmd->param_id = param_id;
1596 cmd->param_value = param_value;
1597
1598 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID);
1599 if (ret) {
1600 ath11k_warn(ar->ab,
1601 "failed to send WMI_VDEV_SET_PARAM_CMDID\n");
1602 dev_kfree_skb(skb);
1603 }
1604
1605 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1606 "cmd vdev set param vdev 0x%x param %d value %d\n",
1607 vdev_id, param_id, param_value);
1608
1609 return ret;
1610}
1611
1612int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar,
1613 struct stats_request_params *param)
1614{
1615 struct ath11k_pdev_wmi *wmi = ar->wmi;
1616 struct wmi_request_stats_cmd *cmd;
1617 struct sk_buff *skb;
1618 int ret;
1619
1620 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1621 if (!skb)
1622 return -ENOMEM;
1623
1624 cmd = (struct wmi_request_stats_cmd *)skb->data;
1625 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) |
1626 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1627
1628 cmd->stats_id = param->stats_id;
1629 cmd->vdev_id = param->vdev_id;
1630 cmd->pdev_id = param->pdev_id;
1631
1632 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID);
1633 if (ret) {
1634 ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n");
1635 dev_kfree_skb(skb);
1636 }
1637
1638 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1639 "cmd request stats 0x%x vdev id %d pdev id %d\n",
1640 param->stats_id, param->vdev_id, param->pdev_id);
1641
1642 return ret;
1643}
1644
1645int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar)
1646{
1647 struct ath11k_pdev_wmi *wmi = ar->wmi;
1648 struct wmi_get_pdev_temperature_cmd *cmd;
1649 struct sk_buff *skb;
1650 int ret;
1651
1652 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1653 if (!skb)
1654 return -ENOMEM;
1655
1656 cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data;
1657 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) |
1658 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1659 cmd->pdev_id = ar->pdev->pdev_id;
1660
1661 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID);
1662 if (ret) {
1663 ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n");
1664 dev_kfree_skb(skb);
1665 }
1666
1667 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1668 "cmd pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id);
1669
1670 return ret;
1671}
1672
1673int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar,
1674 u32 vdev_id, u32 bcn_ctrl_op)
1675{
1676 struct ath11k_pdev_wmi *wmi = ar->wmi;
1677 struct wmi_bcn_offload_ctrl_cmd *cmd;
1678 struct sk_buff *skb;
1679 int ret;
1680
1681 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1682 if (!skb)
1683 return -ENOMEM;
1684
1685 cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data;
1686 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1687 WMI_TAG_BCN_OFFLOAD_CTRL_CMD) |
1688 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1689
1690 cmd->vdev_id = vdev_id;
1691 cmd->bcn_ctrl_op = bcn_ctrl_op;
1692
1693 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID);
1694 if (ret) {
1695 ath11k_warn(ar->ab,
1696 "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n");
1697 dev_kfree_skb(skb);
1698 }
1699
1700 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1701 "cmd bcn offload ctrl vdev id %d ctrl_op %d\n",
1702 vdev_id, bcn_ctrl_op);
1703
1704 return ret;
1705}
1706
1707int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id,
1708 struct ieee80211_mutable_offsets *offs,
1709 struct sk_buff *bcn, u32 ema_params)
1710{
1711 struct ath11k_pdev_wmi *wmi = ar->wmi;
1712 struct wmi_bcn_tmpl_cmd *cmd;
1713 struct wmi_bcn_prb_info *bcn_prb_info;
1714 struct wmi_tlv *tlv;
1715 struct sk_buff *skb;
1716 void *ptr;
1717 int ret, len;
1718 size_t aligned_len = roundup(bcn->len, 4);
1719 struct ieee80211_vif *vif;
1720 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev_id);
1721
1722 if (!arvif) {
1723 ath11k_warn(ar->ab, "failed to find arvif with vdev id %d\n", vdev_id);
1724 return -EINVAL;
1725 }
1726
1727 vif = arvif->vif;
1728
1729 len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len;
1730
1731 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1732 if (!skb)
1733 return -ENOMEM;
1734
1735 cmd = (struct wmi_bcn_tmpl_cmd *)skb->data;
1736 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) |
1737 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1738 cmd->vdev_id = vdev_id;
1739 cmd->tim_ie_offset = offs->tim_offset;
1740
1741 if (vif->bss_conf.csa_active) {
1742 cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0];
1743 cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1];
1744 }
1745
1746 cmd->buf_len = bcn->len;
1747 cmd->mbssid_ie_offset = offs->mbssid_off;
1748 cmd->ema_params = ema_params;
1749
1750 ptr = skb->data + sizeof(*cmd);
1751
1752 bcn_prb_info = ptr;
1753 len = sizeof(*bcn_prb_info);
1754 bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1755 WMI_TAG_BCN_PRB_INFO) |
1756 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1757 bcn_prb_info->caps = 0;
1758 bcn_prb_info->erp = 0;
1759
1760 ptr += sizeof(*bcn_prb_info);
1761
1762 tlv = ptr;
1763 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1764 FIELD_PREP(WMI_TLV_LEN, aligned_len);
1765 memcpy(tlv->value, bcn->data, bcn->len);
1766
1767 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID);
1768 if (ret) {
1769 ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n");
1770 dev_kfree_skb(skb);
1771 }
1772
1773 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd bcn tmpl");
1774
1775 return ret;
1776}
1777
1778int ath11k_wmi_vdev_install_key(struct ath11k *ar,
1779 struct wmi_vdev_install_key_arg *arg)
1780{
1781 struct ath11k_pdev_wmi *wmi = ar->wmi;
1782 struct wmi_vdev_install_key_cmd *cmd;
1783 struct wmi_tlv *tlv;
1784 struct sk_buff *skb;
1785 int ret, len;
1786 int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t));
1787
1788 len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned;
1789
1790 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1791 if (!skb)
1792 return -ENOMEM;
1793
1794 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1795 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) |
1796 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1797 cmd->vdev_id = arg->vdev_id;
1798 ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1799 cmd->key_idx = arg->key_idx;
1800 cmd->key_flags = arg->key_flags;
1801 cmd->key_cipher = arg->key_cipher;
1802 cmd->key_len = arg->key_len;
1803 cmd->key_txmic_len = arg->key_txmic_len;
1804 cmd->key_rxmic_len = arg->key_rxmic_len;
1805
1806 if (arg->key_rsc_counter)
1807 memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter,
1808 sizeof(struct wmi_key_seq_counter));
1809
1810 tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
1811 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1812 FIELD_PREP(WMI_TLV_LEN, key_len_aligned);
1813 if (arg->key_data)
1814 memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned);
1815
1816 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1817 if (ret) {
1818 ath11k_warn(ar->ab,
1819 "failed to send WMI_VDEV_INSTALL_KEY cmd\n");
1820 dev_kfree_skb(skb);
1821 }
1822
1823 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1824 "cmd vdev install key idx %d cipher %d len %d\n",
1825 arg->key_idx, arg->key_cipher, arg->key_len);
1826
1827 return ret;
1828}
1829
1830static inline void
1831ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd,
1832 struct peer_assoc_params *param,
1833 bool hw_crypto_disabled)
1834{
1835 cmd->peer_flags = 0;
1836
1837 if (param->is_wme_set) {
1838 if (param->qos_flag)
1839 cmd->peer_flags |= WMI_PEER_QOS;
1840 if (param->apsd_flag)
1841 cmd->peer_flags |= WMI_PEER_APSD;
1842 if (param->ht_flag)
1843 cmd->peer_flags |= WMI_PEER_HT;
1844 if (param->bw_40)
1845 cmd->peer_flags |= WMI_PEER_40MHZ;
1846 if (param->bw_80)
1847 cmd->peer_flags |= WMI_PEER_80MHZ;
1848 if (param->bw_160)
1849 cmd->peer_flags |= WMI_PEER_160MHZ;
1850
1851 /* Typically if STBC is enabled for VHT it should be enabled
1852 * for HT as well
1853 **/
1854 if (param->stbc_flag)
1855 cmd->peer_flags |= WMI_PEER_STBC;
1856
1857 /* Typically if LDPC is enabled for VHT it should be enabled
1858 * for HT as well
1859 **/
1860 if (param->ldpc_flag)
1861 cmd->peer_flags |= WMI_PEER_LDPC;
1862
1863 if (param->static_mimops_flag)
1864 cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1865 if (param->dynamic_mimops_flag)
1866 cmd->peer_flags |= WMI_PEER_DYN_MIMOPS;
1867 if (param->spatial_mux_flag)
1868 cmd->peer_flags |= WMI_PEER_SPATIAL_MUX;
1869 if (param->vht_flag)
1870 cmd->peer_flags |= WMI_PEER_VHT;
1871 if (param->he_flag)
1872 cmd->peer_flags |= WMI_PEER_HE;
1873 if (param->twt_requester)
1874 cmd->peer_flags |= WMI_PEER_TWT_REQ;
1875 if (param->twt_responder)
1876 cmd->peer_flags |= WMI_PEER_TWT_RESP;
1877 }
1878
1879 /* Suppress authorization for all AUTH modes that need 4-way handshake
1880 * (during re-association).
1881 * Authorization will be done for these modes on key installation.
1882 */
1883 if (param->auth_flag)
1884 cmd->peer_flags |= WMI_PEER_AUTH;
1885 if (param->need_ptk_4_way) {
1886 cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1887 if (!hw_crypto_disabled && param->is_assoc)
1888 cmd->peer_flags &= ~WMI_PEER_AUTH;
1889 }
1890 if (param->need_gtk_2_way)
1891 cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1892 /* safe mode bypass the 4-way handshake */
1893 if (param->safe_mode_enabled)
1894 cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY |
1895 WMI_PEER_NEED_GTK_2_WAY);
1896
1897 if (param->is_pmf_enabled)
1898 cmd->peer_flags |= WMI_PEER_PMF;
1899
1900 /* Disable AMSDU for station transmit, if user configures it */
1901 /* Disable AMSDU for AP transmit to 11n Stations, if user configures
1902 * it
1903 * if (param->amsdu_disable) Add after FW support
1904 **/
1905
1906 /* Target asserts if node is marked HT and all MCS is set to 0.
1907 * Mark the node as non-HT if all the mcs rates are disabled through
1908 * iwpriv
1909 **/
1910 if (param->peer_ht_rates.num_rates == 0)
1911 cmd->peer_flags &= ~WMI_PEER_HT;
1912}
1913
1914int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar,
1915 struct peer_assoc_params *param)
1916{
1917 struct ath11k_pdev_wmi *wmi = ar->wmi;
1918 struct wmi_peer_assoc_complete_cmd *cmd;
1919 struct wmi_vht_rate_set *mcs;
1920 struct wmi_he_rate_set *he_mcs;
1921 struct sk_buff *skb;
1922 struct wmi_tlv *tlv;
1923 void *ptr;
1924 u32 peer_legacy_rates_align;
1925 u32 peer_ht_rates_align;
1926 int i, ret, len;
1927
1928 peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates,
1929 sizeof(u32));
1930 peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates,
1931 sizeof(u32));
1932
1933 len = sizeof(*cmd) +
1934 TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) +
1935 TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) +
1936 sizeof(*mcs) + TLV_HDR_SIZE +
1937 (sizeof(*he_mcs) * param->peer_he_mcs_count);
1938
1939 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1940 if (!skb)
1941 return -ENOMEM;
1942
1943 ptr = skb->data;
1944
1945 cmd = ptr;
1946 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1947 WMI_TAG_PEER_ASSOC_COMPLETE_CMD) |
1948 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1949
1950 cmd->vdev_id = param->vdev_id;
1951
1952 cmd->peer_new_assoc = param->peer_new_assoc;
1953 cmd->peer_associd = param->peer_associd;
1954
1955 ath11k_wmi_copy_peer_flags(cmd, param,
1956 test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED,
1957 &ar->ab->dev_flags));
1958
1959 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac);
1960
1961 cmd->peer_rate_caps = param->peer_rate_caps;
1962 cmd->peer_caps = param->peer_caps;
1963 cmd->peer_listen_intval = param->peer_listen_intval;
1964 cmd->peer_ht_caps = param->peer_ht_caps;
1965 cmd->peer_max_mpdu = param->peer_max_mpdu;
1966 cmd->peer_mpdu_density = param->peer_mpdu_density;
1967 cmd->peer_vht_caps = param->peer_vht_caps;
1968 cmd->peer_phymode = param->peer_phymode;
1969
1970 /* Update 11ax capabilities */
1971 cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0];
1972 cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1];
1973 cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal;
1974 cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz;
1975 cmd->peer_he_ops = param->peer_he_ops;
1976 memcpy(&cmd->peer_he_cap_phy, ¶m->peer_he_cap_phyinfo,
1977 sizeof(param->peer_he_cap_phyinfo));
1978 memcpy(&cmd->peer_ppet, ¶m->peer_ppet,
1979 sizeof(param->peer_ppet));
1980
1981 /* Update peer legacy rate information */
1982 ptr += sizeof(*cmd);
1983
1984 tlv = ptr;
1985 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1986 FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align);
1987
1988 ptr += TLV_HDR_SIZE;
1989
1990 cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates;
1991 memcpy(ptr, param->peer_legacy_rates.rates,
1992 param->peer_legacy_rates.num_rates);
1993
1994 /* Update peer HT rate information */
1995 ptr += peer_legacy_rates_align;
1996
1997 tlv = ptr;
1998 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1999 FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align);
2000 ptr += TLV_HDR_SIZE;
2001 cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates;
2002 memcpy(ptr, param->peer_ht_rates.rates,
2003 param->peer_ht_rates.num_rates);
2004
2005 /* VHT Rates */
2006 ptr += peer_ht_rates_align;
2007
2008 mcs = ptr;
2009
2010 mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) |
2011 FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE);
2012
2013 cmd->peer_nss = param->peer_nss;
2014
2015 /* Update bandwidth-NSS mapping */
2016 cmd->peer_bw_rxnss_override = 0;
2017 cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override;
2018
2019 if (param->vht_capable) {
2020 mcs->rx_max_rate = param->rx_max_rate;
2021 mcs->rx_mcs_set = param->rx_mcs_set;
2022 mcs->tx_max_rate = param->tx_max_rate;
2023 mcs->tx_mcs_set = param->tx_mcs_set;
2024 }
2025
2026 /* HE Rates */
2027 cmd->peer_he_mcs = param->peer_he_mcs_count;
2028 cmd->min_data_rate = param->min_data_rate;
2029
2030 ptr += sizeof(*mcs);
2031
2032 len = param->peer_he_mcs_count * sizeof(*he_mcs);
2033
2034 tlv = ptr;
2035 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2036 FIELD_PREP(WMI_TLV_LEN, len);
2037 ptr += TLV_HDR_SIZE;
2038
2039 /* Loop through the HE rate set */
2040 for (i = 0; i < param->peer_he_mcs_count; i++) {
2041 he_mcs = ptr;
2042 he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2043 WMI_TAG_HE_RATE_SET) |
2044 FIELD_PREP(WMI_TLV_LEN,
2045 sizeof(*he_mcs) - TLV_HDR_SIZE);
2046
2047 he_mcs->rx_mcs_set = param->peer_he_tx_mcs_set[i];
2048 he_mcs->tx_mcs_set = param->peer_he_rx_mcs_set[i];
2049 ptr += sizeof(*he_mcs);
2050 }
2051
2052 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID);
2053 if (ret) {
2054 ath11k_warn(ar->ab,
2055 "failed to send WMI_PEER_ASSOC_CMDID\n");
2056 dev_kfree_skb(skb);
2057 }
2058
2059 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2060 "cmd peer assoc vdev id %d assoc id %d peer mac %pM peer_flags %x rate_caps %x peer_caps %x listen_intval %d ht_caps %x max_mpdu %d nss %d phymode %d peer_mpdu_density %d vht_caps %x he cap_info %x he ops %x he cap_info_ext %x he phy %x %x %x peer_bw_rxnss_override %x\n",
2061 cmd->vdev_id, cmd->peer_associd, param->peer_mac,
2062 cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps,
2063 cmd->peer_listen_intval, cmd->peer_ht_caps,
2064 cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode,
2065 cmd->peer_mpdu_density,
2066 cmd->peer_vht_caps, cmd->peer_he_cap_info,
2067 cmd->peer_he_ops, cmd->peer_he_cap_info_ext,
2068 cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1],
2069 cmd->peer_he_cap_phy[2],
2070 cmd->peer_bw_rxnss_override);
2071
2072 return ret;
2073}
2074
2075void ath11k_wmi_start_scan_init(struct ath11k *ar,
2076 struct scan_req_params *arg)
2077{
2078 /* setup commonly used values */
2079 arg->scan_req_id = 1;
2080 if (ar->state_11d == ATH11K_11D_PREPARING)
2081 arg->scan_priority = WMI_SCAN_PRIORITY_MEDIUM;
2082 else
2083 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
2084 arg->dwell_time_active = 50;
2085 arg->dwell_time_active_2g = 0;
2086 arg->dwell_time_passive = 150;
2087 arg->dwell_time_active_6g = 40;
2088 arg->dwell_time_passive_6g = 30;
2089 arg->min_rest_time = 50;
2090 arg->max_rest_time = 500;
2091 arg->repeat_probe_time = 0;
2092 arg->probe_spacing_time = 0;
2093 arg->idle_time = 0;
2094 arg->max_scan_time = 20000;
2095 arg->probe_delay = 5;
2096 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED |
2097 WMI_SCAN_EVENT_COMPLETED |
2098 WMI_SCAN_EVENT_BSS_CHANNEL |
2099 WMI_SCAN_EVENT_FOREIGN_CHAN |
2100 WMI_SCAN_EVENT_DEQUEUED;
2101 arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2102
2103 if (test_bit(WMI_TLV_SERVICE_PASSIVE_SCAN_START_TIME_ENHANCE,
2104 ar->ab->wmi_ab.svc_map))
2105 arg->scan_ctrl_flags_ext |=
2106 WMI_SCAN_FLAG_EXT_PASSIVE_SCAN_START_TIME_ENHANCE;
2107
2108 arg->num_bssid = 1;
2109
2110 /* fill bssid_list[0] with 0xff, otherwise bssid and RA will be
2111 * ZEROs in probe request
2112 */
2113 eth_broadcast_addr(arg->bssid_list[0].addr);
2114}
2115
2116static inline void
2117ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
2118 struct scan_req_params *param)
2119{
2120 /* Scan events subscription */
2121 if (param->scan_ev_started)
2122 cmd->notify_scan_events |= WMI_SCAN_EVENT_STARTED;
2123 if (param->scan_ev_completed)
2124 cmd->notify_scan_events |= WMI_SCAN_EVENT_COMPLETED;
2125 if (param->scan_ev_bss_chan)
2126 cmd->notify_scan_events |= WMI_SCAN_EVENT_BSS_CHANNEL;
2127 if (param->scan_ev_foreign_chan)
2128 cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN;
2129 if (param->scan_ev_dequeued)
2130 cmd->notify_scan_events |= WMI_SCAN_EVENT_DEQUEUED;
2131 if (param->scan_ev_preempted)
2132 cmd->notify_scan_events |= WMI_SCAN_EVENT_PREEMPTED;
2133 if (param->scan_ev_start_failed)
2134 cmd->notify_scan_events |= WMI_SCAN_EVENT_START_FAILED;
2135 if (param->scan_ev_restarted)
2136 cmd->notify_scan_events |= WMI_SCAN_EVENT_RESTARTED;
2137 if (param->scan_ev_foreign_chn_exit)
2138 cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
2139 if (param->scan_ev_suspended)
2140 cmd->notify_scan_events |= WMI_SCAN_EVENT_SUSPENDED;
2141 if (param->scan_ev_resumed)
2142 cmd->notify_scan_events |= WMI_SCAN_EVENT_RESUMED;
2143
2144 /** Set scan control flags */
2145 cmd->scan_ctrl_flags = 0;
2146 if (param->scan_f_passive)
2147 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2148 if (param->scan_f_strict_passive_pch)
2149 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
2150 if (param->scan_f_promisc_mode)
2151 cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROMISCUOS;
2152 if (param->scan_f_capture_phy_err)
2153 cmd->scan_ctrl_flags |= WMI_SCAN_CAPTURE_PHY_ERROR;
2154 if (param->scan_f_half_rate)
2155 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
2156 if (param->scan_f_quarter_rate)
2157 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
2158 if (param->scan_f_cck_rates)
2159 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2160 if (param->scan_f_ofdm_rates)
2161 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
2162 if (param->scan_f_chan_stat_evnt)
2163 cmd->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2164 if (param->scan_f_filter_prb_req)
2165 cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2166 if (param->scan_f_bcast_probe)
2167 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_BCAST_PROBE_REQ;
2168 if (param->scan_f_offchan_mgmt_tx)
2169 cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_MGMT_TX;
2170 if (param->scan_f_offchan_data_tx)
2171 cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_DATA_TX;
2172 if (param->scan_f_force_active_dfs_chn)
2173 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
2174 if (param->scan_f_add_tpc_ie_in_probe)
2175 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
2176 if (param->scan_f_add_ds_ie_in_probe)
2177 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
2178 if (param->scan_f_add_spoofed_mac_in_probe)
2179 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
2180 if (param->scan_f_add_rand_seq_in_probe)
2181 cmd->scan_ctrl_flags |= WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
2182 if (param->scan_f_en_ie_whitelist_in_probe)
2183 cmd->scan_ctrl_flags |=
2184 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
2185
2186 /* for adaptive scan mode using 3 bits (21 - 23 bits) */
2187 WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
2188 param->adaptive_dwell_time_mode);
2189
2190 cmd->scan_ctrl_flags_ext = param->scan_ctrl_flags_ext;
2191}
2192
2193int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
2194 struct scan_req_params *params)
2195{
2196 struct ath11k_pdev_wmi *wmi = ar->wmi;
2197 struct wmi_start_scan_cmd *cmd;
2198 struct wmi_ssid *ssid = NULL;
2199 struct wmi_mac_addr *bssid;
2200 struct sk_buff *skb;
2201 struct wmi_tlv *tlv;
2202 void *ptr;
2203 int i, ret, len;
2204 u32 *tmp_ptr;
2205 u16 extraie_len_with_pad = 0;
2206 struct hint_short_ssid *s_ssid = NULL;
2207 struct hint_bssid *hint_bssid = NULL;
2208
2209 len = sizeof(*cmd);
2210
2211 len += TLV_HDR_SIZE;
2212 if (params->num_chan)
2213 len += params->num_chan * sizeof(u32);
2214
2215 len += TLV_HDR_SIZE;
2216 if (params->num_ssids)
2217 len += params->num_ssids * sizeof(*ssid);
2218
2219 len += TLV_HDR_SIZE;
2220 if (params->num_bssid)
2221 len += sizeof(*bssid) * params->num_bssid;
2222
2223 len += TLV_HDR_SIZE;
2224 if (params->extraie.len && params->extraie.len <= 0xFFFF)
2225 extraie_len_with_pad =
2226 roundup(params->extraie.len, sizeof(u32));
2227 len += extraie_len_with_pad;
2228
2229 if (params->num_hint_bssid)
2230 len += TLV_HDR_SIZE +
2231 params->num_hint_bssid * sizeof(struct hint_bssid);
2232
2233 if (params->num_hint_s_ssid)
2234 len += TLV_HDR_SIZE +
2235 params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
2236
2237 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2238 if (!skb)
2239 return -ENOMEM;
2240
2241 ptr = skb->data;
2242
2243 cmd = ptr;
2244 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
2245 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2246
2247 cmd->scan_id = params->scan_id;
2248 cmd->scan_req_id = params->scan_req_id;
2249 cmd->vdev_id = params->vdev_id;
2250 cmd->scan_priority = params->scan_priority;
2251 cmd->notify_scan_events = params->notify_scan_events;
2252
2253 ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
2254
2255 cmd->dwell_time_active = params->dwell_time_active;
2256 cmd->dwell_time_active_2g = params->dwell_time_active_2g;
2257 cmd->dwell_time_passive = params->dwell_time_passive;
2258 cmd->dwell_time_active_6g = params->dwell_time_active_6g;
2259 cmd->dwell_time_passive_6g = params->dwell_time_passive_6g;
2260 cmd->min_rest_time = params->min_rest_time;
2261 cmd->max_rest_time = params->max_rest_time;
2262 cmd->repeat_probe_time = params->repeat_probe_time;
2263 cmd->probe_spacing_time = params->probe_spacing_time;
2264 cmd->idle_time = params->idle_time;
2265 cmd->max_scan_time = params->max_scan_time;
2266 cmd->probe_delay = params->probe_delay;
2267 cmd->burst_duration = params->burst_duration;
2268 cmd->num_chan = params->num_chan;
2269 cmd->num_bssid = params->num_bssid;
2270 cmd->num_ssids = params->num_ssids;
2271 cmd->ie_len = params->extraie.len;
2272 cmd->n_probes = params->n_probes;
2273 ether_addr_copy(cmd->mac_addr.addr, params->mac_addr.addr);
2274 ether_addr_copy(cmd->mac_mask.addr, params->mac_mask.addr);
2275
2276 ptr += sizeof(*cmd);
2277
2278 len = params->num_chan * sizeof(u32);
2279
2280 tlv = ptr;
2281 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
2282 FIELD_PREP(WMI_TLV_LEN, len);
2283 ptr += TLV_HDR_SIZE;
2284 tmp_ptr = ptr;
2285
2286 for (i = 0; i < params->num_chan; ++i)
2287 tmp_ptr[i] = params->chan_list[i];
2288
2289 ptr += len;
2290
2291 len = params->num_ssids * sizeof(*ssid);
2292 tlv = ptr;
2293 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2294 FIELD_PREP(WMI_TLV_LEN, len);
2295
2296 ptr += TLV_HDR_SIZE;
2297
2298 if (params->num_ssids) {
2299 ssid = ptr;
2300 for (i = 0; i < params->num_ssids; ++i) {
2301 ssid->ssid_len = params->ssid[i].length;
2302 memcpy(ssid->ssid, params->ssid[i].ssid,
2303 params->ssid[i].length);
2304 ssid++;
2305 }
2306 }
2307
2308 ptr += (params->num_ssids * sizeof(*ssid));
2309 len = params->num_bssid * sizeof(*bssid);
2310 tlv = ptr;
2311 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2312 FIELD_PREP(WMI_TLV_LEN, len);
2313
2314 ptr += TLV_HDR_SIZE;
2315 bssid = ptr;
2316
2317 if (params->num_bssid) {
2318 for (i = 0; i < params->num_bssid; ++i) {
2319 ether_addr_copy(bssid->addr,
2320 params->bssid_list[i].addr);
2321 bssid++;
2322 }
2323 }
2324
2325 ptr += params->num_bssid * sizeof(*bssid);
2326
2327 len = extraie_len_with_pad;
2328 tlv = ptr;
2329 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2330 FIELD_PREP(WMI_TLV_LEN, len);
2331 ptr += TLV_HDR_SIZE;
2332
2333 if (extraie_len_with_pad)
2334 memcpy(ptr, params->extraie.ptr,
2335 params->extraie.len);
2336
2337 ptr += extraie_len_with_pad;
2338
2339 if (params->num_hint_s_ssid) {
2340 len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
2341 tlv = ptr;
2342 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2343 FIELD_PREP(WMI_TLV_LEN, len);
2344 ptr += TLV_HDR_SIZE;
2345 s_ssid = ptr;
2346 for (i = 0; i < params->num_hint_s_ssid; ++i) {
2347 s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
2348 s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
2349 s_ssid++;
2350 }
2351 ptr += len;
2352 }
2353
2354 if (params->num_hint_bssid) {
2355 len = params->num_hint_bssid * sizeof(struct hint_bssid);
2356 tlv = ptr;
2357 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2358 FIELD_PREP(WMI_TLV_LEN, len);
2359 ptr += TLV_HDR_SIZE;
2360 hint_bssid = ptr;
2361 for (i = 0; i < params->num_hint_bssid; ++i) {
2362 hint_bssid->freq_flags =
2363 params->hint_bssid[i].freq_flags;
2364 ether_addr_copy(¶ms->hint_bssid[i].bssid.addr[0],
2365 &hint_bssid->bssid.addr[0]);
2366 hint_bssid++;
2367 }
2368 }
2369
2370 ret = ath11k_wmi_cmd_send(wmi, skb,
2371 WMI_START_SCAN_CMDID);
2372 if (ret) {
2373 ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2374 dev_kfree_skb(skb);
2375 }
2376
2377 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd start scan");
2378
2379 return ret;
2380}
2381
2382int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2383 struct scan_cancel_param *param)
2384{
2385 struct ath11k_pdev_wmi *wmi = ar->wmi;
2386 struct wmi_stop_scan_cmd *cmd;
2387 struct sk_buff *skb;
2388 int ret;
2389
2390 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2391 if (!skb)
2392 return -ENOMEM;
2393
2394 cmd = (struct wmi_stop_scan_cmd *)skb->data;
2395
2396 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2397 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2398
2399 cmd->vdev_id = param->vdev_id;
2400 cmd->requestor = param->requester;
2401 cmd->scan_id = param->scan_id;
2402 cmd->pdev_id = param->pdev_id;
2403 /* stop the scan with the corresponding scan_id */
2404 if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2405 /* Cancelling all scans */
2406 cmd->req_type = WMI_SCAN_STOP_ALL;
2407 } else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2408 /* Cancelling VAP scans */
2409 cmd->req_type = WMI_SCN_STOP_VAP_ALL;
2410 } else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2411 /* Cancelling specific scan */
2412 cmd->req_type = WMI_SCAN_STOP_ONE;
2413 } else {
2414 ath11k_warn(ar->ab, "invalid scan cancel param %d",
2415 param->req_type);
2416 dev_kfree_skb(skb);
2417 return -EINVAL;
2418 }
2419
2420 ret = ath11k_wmi_cmd_send(wmi, skb,
2421 WMI_STOP_SCAN_CMDID);
2422 if (ret) {
2423 ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2424 dev_kfree_skb(skb);
2425 }
2426
2427 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd stop scan");
2428
2429 return ret;
2430}
2431
2432int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2433 struct scan_chan_list_params *chan_list)
2434{
2435 struct ath11k_pdev_wmi *wmi = ar->wmi;
2436 struct wmi_scan_chan_list_cmd *cmd;
2437 struct sk_buff *skb;
2438 struct wmi_channel *chan_info;
2439 struct channel_param *tchan_info;
2440 struct wmi_tlv *tlv;
2441 void *ptr;
2442 int i, ret, len;
2443 u16 num_send_chans, num_sends = 0, max_chan_limit = 0;
2444 u32 *reg1, *reg2;
2445
2446 tchan_info = chan_list->ch_param;
2447 while (chan_list->nallchans) {
2448 len = sizeof(*cmd) + TLV_HDR_SIZE;
2449 max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) /
2450 sizeof(*chan_info);
2451
2452 if (chan_list->nallchans > max_chan_limit)
2453 num_send_chans = max_chan_limit;
2454 else
2455 num_send_chans = chan_list->nallchans;
2456
2457 chan_list->nallchans -= num_send_chans;
2458 len += sizeof(*chan_info) * num_send_chans;
2459
2460 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2461 if (!skb)
2462 return -ENOMEM;
2463
2464 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2465 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2466 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2467 cmd->pdev_id = chan_list->pdev_id;
2468 cmd->num_scan_chans = num_send_chans;
2469 if (num_sends)
2470 cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG;
2471
2472 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2473 "no.of chan = %d len = %d pdev_id = %d num_sends = %d\n",
2474 num_send_chans, len, cmd->pdev_id, num_sends);
2475
2476 ptr = skb->data + sizeof(*cmd);
2477
2478 len = sizeof(*chan_info) * num_send_chans;
2479 tlv = ptr;
2480 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2481 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2482 ptr += TLV_HDR_SIZE;
2483
2484 for (i = 0; i < num_send_chans; ++i) {
2485 chan_info = ptr;
2486 memset(chan_info, 0, sizeof(*chan_info));
2487 len = sizeof(*chan_info);
2488 chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2489 WMI_TAG_CHANNEL) |
2490 FIELD_PREP(WMI_TLV_LEN,
2491 len - TLV_HDR_SIZE);
2492
2493 reg1 = &chan_info->reg_info_1;
2494 reg2 = &chan_info->reg_info_2;
2495 chan_info->mhz = tchan_info->mhz;
2496 chan_info->band_center_freq1 = tchan_info->cfreq1;
2497 chan_info->band_center_freq2 = tchan_info->cfreq2;
2498
2499 if (tchan_info->is_chan_passive)
2500 chan_info->info |= WMI_CHAN_INFO_PASSIVE;
2501 if (tchan_info->allow_he)
2502 chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
2503 else if (tchan_info->allow_vht)
2504 chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2505 else if (tchan_info->allow_ht)
2506 chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2507 if (tchan_info->half_rate)
2508 chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2509 if (tchan_info->quarter_rate)
2510 chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2511 if (tchan_info->psc_channel)
2512 chan_info->info |= WMI_CHAN_INFO_PSC;
2513 if (tchan_info->dfs_set)
2514 chan_info->info |= WMI_CHAN_INFO_DFS;
2515
2516 chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2517 tchan_info->phy_mode);
2518 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2519 tchan_info->minpower);
2520 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2521 tchan_info->maxpower);
2522 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2523 tchan_info->maxregpower);
2524 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2525 tchan_info->reg_class_id);
2526 *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2527 tchan_info->antennamax);
2528 *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
2529 tchan_info->maxregpower);
2530
2531 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2532 "chan scan list chan[%d] = %u, chan_info->info %8x\n",
2533 i, chan_info->mhz, chan_info->info);
2534
2535 ptr += sizeof(*chan_info);
2536
2537 tchan_info++;
2538 }
2539
2540 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2541 if (ret) {
2542 ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2543 dev_kfree_skb(skb);
2544 return ret;
2545 }
2546
2547 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd scan chan list channels %d",
2548 num_send_chans);
2549
2550 num_sends++;
2551 }
2552
2553 return 0;
2554}
2555
2556int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2557 struct wmi_wmm_params_all_arg *param)
2558{
2559 struct ath11k_pdev_wmi *wmi = ar->wmi;
2560 struct wmi_vdev_set_wmm_params_cmd *cmd;
2561 struct wmi_wmm_params *wmm_param;
2562 struct wmi_wmm_params_arg *wmi_wmm_arg;
2563 struct sk_buff *skb;
2564 int ret, ac;
2565
2566 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2567 if (!skb)
2568 return -ENOMEM;
2569
2570 cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2571 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2572 WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2573 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2574
2575 cmd->vdev_id = vdev_id;
2576 cmd->wmm_param_type = 0;
2577
2578 for (ac = 0; ac < WME_NUM_AC; ac++) {
2579 switch (ac) {
2580 case WME_AC_BE:
2581 wmi_wmm_arg = ¶m->ac_be;
2582 break;
2583 case WME_AC_BK:
2584 wmi_wmm_arg = ¶m->ac_bk;
2585 break;
2586 case WME_AC_VI:
2587 wmi_wmm_arg = ¶m->ac_vi;
2588 break;
2589 case WME_AC_VO:
2590 wmi_wmm_arg = ¶m->ac_vo;
2591 break;
2592 }
2593
2594 wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2595 wmm_param->tlv_header =
2596 FIELD_PREP(WMI_TLV_TAG,
2597 WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2598 FIELD_PREP(WMI_TLV_LEN,
2599 sizeof(*wmm_param) - TLV_HDR_SIZE);
2600
2601 wmm_param->aifs = wmi_wmm_arg->aifs;
2602 wmm_param->cwmin = wmi_wmm_arg->cwmin;
2603 wmm_param->cwmax = wmi_wmm_arg->cwmax;
2604 wmm_param->txoplimit = wmi_wmm_arg->txop;
2605 wmm_param->acm = wmi_wmm_arg->acm;
2606 wmm_param->no_ack = wmi_wmm_arg->no_ack;
2607
2608 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2609 "wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2610 ac, wmm_param->aifs, wmm_param->cwmin,
2611 wmm_param->cwmax, wmm_param->txoplimit,
2612 wmm_param->acm, wmm_param->no_ack);
2613 }
2614 ret = ath11k_wmi_cmd_send(wmi, skb,
2615 WMI_VDEV_SET_WMM_PARAMS_CMDID);
2616 if (ret) {
2617 ath11k_warn(ar->ab,
2618 "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2619 dev_kfree_skb(skb);
2620 }
2621
2622 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev set wmm params");
2623
2624 return ret;
2625}
2626
2627int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2628 u32 pdev_id)
2629{
2630 struct ath11k_pdev_wmi *wmi = ar->wmi;
2631 struct wmi_dfs_phyerr_offload_cmd *cmd;
2632 struct sk_buff *skb;
2633 int ret;
2634
2635 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2636 if (!skb)
2637 return -ENOMEM;
2638
2639 cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2640 cmd->tlv_header =
2641 FIELD_PREP(WMI_TLV_TAG,
2642 WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2643 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2644
2645 cmd->pdev_id = pdev_id;
2646
2647 ret = ath11k_wmi_cmd_send(wmi, skb,
2648 WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2649 if (ret) {
2650 ath11k_warn(ar->ab,
2651 "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2652 dev_kfree_skb(skb);
2653 }
2654
2655 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2656 "cmd pdev dfs phyerr offload enable pdev id %d\n", pdev_id);
2657
2658 return ret;
2659}
2660
2661int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
2662 u32 tid, u32 initiator, u32 reason)
2663{
2664 struct ath11k_pdev_wmi *wmi = ar->wmi;
2665 struct wmi_delba_send_cmd *cmd;
2666 struct sk_buff *skb;
2667 int ret;
2668
2669 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2670 if (!skb)
2671 return -ENOMEM;
2672
2673 cmd = (struct wmi_delba_send_cmd *)skb->data;
2674 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) |
2675 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2676 cmd->vdev_id = vdev_id;
2677 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2678 cmd->tid = tid;
2679 cmd->initiator = initiator;
2680 cmd->reasoncode = reason;
2681
2682 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID);
2683
2684 if (ret) {
2685 ath11k_warn(ar->ab,
2686 "failed to send WMI_DELBA_SEND_CMDID cmd\n");
2687 dev_kfree_skb(skb);
2688 }
2689
2690 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2691 "cmd delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
2692 vdev_id, mac, tid, initiator, reason);
2693
2694 return ret;
2695}
2696
2697int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac,
2698 u32 tid, u32 status)
2699{
2700 struct ath11k_pdev_wmi *wmi = ar->wmi;
2701 struct wmi_addba_setresponse_cmd *cmd;
2702 struct sk_buff *skb;
2703 int ret;
2704
2705 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2706 if (!skb)
2707 return -ENOMEM;
2708
2709 cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
2710 cmd->tlv_header =
2711 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) |
2712 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2713 cmd->vdev_id = vdev_id;
2714 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2715 cmd->tid = tid;
2716 cmd->statuscode = status;
2717
2718 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID);
2719
2720 if (ret) {
2721 ath11k_warn(ar->ab,
2722 "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n");
2723 dev_kfree_skb(skb);
2724 }
2725
2726 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2727 "cmd addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
2728 vdev_id, mac, tid, status);
2729
2730 return ret;
2731}
2732
2733int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
2734 u32 tid, u32 buf_size)
2735{
2736 struct ath11k_pdev_wmi *wmi = ar->wmi;
2737 struct wmi_addba_send_cmd *cmd;
2738 struct sk_buff *skb;
2739 int ret;
2740
2741 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2742 if (!skb)
2743 return -ENOMEM;
2744
2745 cmd = (struct wmi_addba_send_cmd *)skb->data;
2746 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) |
2747 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2748 cmd->vdev_id = vdev_id;
2749 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2750 cmd->tid = tid;
2751 cmd->buffersize = buf_size;
2752
2753 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID);
2754
2755 if (ret) {
2756 ath11k_warn(ar->ab,
2757 "failed to send WMI_ADDBA_SEND_CMDID cmd\n");
2758 dev_kfree_skb(skb);
2759 }
2760
2761 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2762 "cmd addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
2763 vdev_id, mac, tid, buf_size);
2764
2765 return ret;
2766}
2767
2768int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac)
2769{
2770 struct ath11k_pdev_wmi *wmi = ar->wmi;
2771 struct wmi_addba_clear_resp_cmd *cmd;
2772 struct sk_buff *skb;
2773 int ret;
2774
2775 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2776 if (!skb)
2777 return -ENOMEM;
2778
2779 cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
2780 cmd->tlv_header =
2781 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) |
2782 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2783 cmd->vdev_id = vdev_id;
2784 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2785
2786 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID);
2787
2788 if (ret) {
2789 ath11k_warn(ar->ab,
2790 "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n");
2791 dev_kfree_skb(skb);
2792 }
2793
2794 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2795 "cmd addba clear resp vdev_id 0x%X mac_addr %pM\n",
2796 vdev_id, mac);
2797
2798 return ret;
2799}
2800
2801int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2802{
2803 struct ath11k_pdev_wmi *wmi = ar->wmi;
2804 struct wmi_pdev_pktlog_filter_cmd *cmd;
2805 struct wmi_pdev_pktlog_filter_info *info;
2806 struct sk_buff *skb;
2807 struct wmi_tlv *tlv;
2808 void *ptr;
2809 int ret, len;
2810
2811 len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
2812 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2813 if (!skb)
2814 return -ENOMEM;
2815
2816 cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2817
2818 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2819 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2820
2821 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2822 cmd->num_mac = 1;
2823 cmd->enable = enable;
2824
2825 ptr = skb->data + sizeof(*cmd);
2826
2827 tlv = ptr;
2828 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2829 FIELD_PREP(WMI_TLV_LEN, sizeof(*info));
2830
2831 ptr += TLV_HDR_SIZE;
2832 info = ptr;
2833
2834 ether_addr_copy(info->peer_macaddr.addr, addr);
2835 info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2836 FIELD_PREP(WMI_TLV_LEN,
2837 sizeof(*info) - TLV_HDR_SIZE);
2838
2839 ret = ath11k_wmi_cmd_send(wmi, skb,
2840 WMI_PDEV_PKTLOG_FILTER_CMDID);
2841 if (ret) {
2842 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2843 dev_kfree_skb(skb);
2844 }
2845
2846 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd pdev pktlog filter");
2847
2848 return ret;
2849}
2850
2851int
2852ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2853 struct wmi_init_country_params init_cc_params)
2854{
2855 struct ath11k_pdev_wmi *wmi = ar->wmi;
2856 struct wmi_init_country_cmd *cmd;
2857 struct sk_buff *skb;
2858 int ret;
2859
2860 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2861 if (!skb)
2862 return -ENOMEM;
2863
2864 cmd = (struct wmi_init_country_cmd *)skb->data;
2865 cmd->tlv_header =
2866 FIELD_PREP(WMI_TLV_TAG,
2867 WMI_TAG_SET_INIT_COUNTRY_CMD) |
2868 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2869
2870 cmd->pdev_id = ar->pdev->pdev_id;
2871
2872 switch (init_cc_params.flags) {
2873 case ALPHA_IS_SET:
2874 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2875 memcpy((u8 *)&cmd->cc_info.alpha2,
2876 init_cc_params.cc_info.alpha2, 3);
2877 break;
2878 case CC_IS_SET:
2879 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2880 cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2881 break;
2882 case REGDMN_IS_SET:
2883 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2884 cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2885 break;
2886 default:
2887 ath11k_warn(ar->ab, "unknown cc params flags: 0x%x",
2888 init_cc_params.flags);
2889 ret = -EINVAL;
2890 goto err;
2891 }
2892
2893 ret = ath11k_wmi_cmd_send(wmi, skb,
2894 WMI_SET_INIT_COUNTRY_CMDID);
2895 if (ret) {
2896 ath11k_warn(ar->ab,
2897 "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2898 ret);
2899 goto err;
2900 }
2901
2902 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd set init country");
2903
2904 return 0;
2905
2906err:
2907 dev_kfree_skb(skb);
2908 return ret;
2909}
2910
2911int ath11k_wmi_send_set_current_country_cmd(struct ath11k *ar,
2912 struct wmi_set_current_country_params *param)
2913{
2914 struct ath11k_pdev_wmi *wmi = ar->wmi;
2915 struct wmi_set_current_country_cmd *cmd;
2916 struct sk_buff *skb;
2917 int ret;
2918
2919 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2920 if (!skb)
2921 return -ENOMEM;
2922
2923 cmd = (struct wmi_set_current_country_cmd *)skb->data;
2924 cmd->tlv_header =
2925 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SET_CURRENT_COUNTRY_CMD) |
2926 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2927
2928 cmd->pdev_id = ar->pdev->pdev_id;
2929 memcpy(&cmd->new_alpha2, ¶m->alpha2, 3);
2930
2931 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SET_CURRENT_COUNTRY_CMDID);
2932 if (ret) {
2933 ath11k_warn(ar->ab,
2934 "failed to send WMI_SET_CURRENT_COUNTRY_CMDID: %d\n", ret);
2935 dev_kfree_skb(skb);
2936 }
2937
2938 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2939 "cmd set current country pdev id %d alpha2 %c%c\n",
2940 ar->pdev->pdev_id,
2941 param->alpha2[0],
2942 param->alpha2[1]);
2943
2944 return ret;
2945}
2946
2947int
2948ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar,
2949 struct thermal_mitigation_params *param)
2950{
2951 struct ath11k_pdev_wmi *wmi = ar->wmi;
2952 struct wmi_therm_throt_config_request_cmd *cmd;
2953 struct wmi_therm_throt_level_config_info *lvl_conf;
2954 struct wmi_tlv *tlv;
2955 struct sk_buff *skb;
2956 int i, ret, len;
2957
2958 len = sizeof(*cmd) + TLV_HDR_SIZE +
2959 THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info);
2960
2961 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2962 if (!skb)
2963 return -ENOMEM;
2964
2965 cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data;
2966
2967 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) |
2968 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2969
2970 cmd->pdev_id = ar->pdev->pdev_id;
2971 cmd->enable = param->enable;
2972 cmd->dc = param->dc;
2973 cmd->dc_per_event = param->dc_per_event;
2974 cmd->therm_throt_levels = THERMAL_LEVELS;
2975
2976 tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
2977 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2978 FIELD_PREP(WMI_TLV_LEN,
2979 (THERMAL_LEVELS *
2980 sizeof(struct wmi_therm_throt_level_config_info)));
2981
2982 lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data +
2983 sizeof(*cmd) +
2984 TLV_HDR_SIZE);
2985 for (i = 0; i < THERMAL_LEVELS; i++) {
2986 lvl_conf->tlv_header =
2987 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) |
2988 FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE);
2989
2990 lvl_conf->temp_lwm = param->levelconf[i].tmplwm;
2991 lvl_conf->temp_hwm = param->levelconf[i].tmphwm;
2992 lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent;
2993 lvl_conf->prio = param->levelconf[i].priority;
2994 lvl_conf++;
2995 }
2996
2997 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID);
2998 if (ret) {
2999 ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n");
3000 dev_kfree_skb(skb);
3001 }
3002
3003 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3004 "cmd therm throt set conf pdev_id %d enable %d dc %d dc_per_event %x levels %d\n",
3005 ar->pdev->pdev_id, param->enable, param->dc,
3006 param->dc_per_event, THERMAL_LEVELS);
3007
3008 return ret;
3009}
3010
3011int ath11k_wmi_send_11d_scan_start_cmd(struct ath11k *ar,
3012 struct wmi_11d_scan_start_params *param)
3013{
3014 struct ath11k_pdev_wmi *wmi = ar->wmi;
3015 struct wmi_11d_scan_start_cmd *cmd;
3016 struct sk_buff *skb;
3017 int ret;
3018
3019 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3020 if (!skb)
3021 return -ENOMEM;
3022
3023 cmd = (struct wmi_11d_scan_start_cmd *)skb->data;
3024 cmd->tlv_header =
3025 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_START_CMD) |
3026 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3027
3028 cmd->vdev_id = param->vdev_id;
3029 cmd->scan_period_msec = param->scan_period_msec;
3030 cmd->start_interval_msec = param->start_interval_msec;
3031
3032 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_START_CMDID);
3033 if (ret) {
3034 ath11k_warn(ar->ab,
3035 "failed to send WMI_11D_SCAN_START_CMDID: %d\n", ret);
3036 dev_kfree_skb(skb);
3037 }
3038
3039 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3040 "cmd 11d scan start vdev id %d period %d ms internal %d ms\n",
3041 cmd->vdev_id,
3042 cmd->scan_period_msec,
3043 cmd->start_interval_msec);
3044
3045 return ret;
3046}
3047
3048int ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k *ar, u32 vdev_id)
3049{
3050 struct ath11k_pdev_wmi *wmi = ar->wmi;
3051 struct wmi_11d_scan_stop_cmd *cmd;
3052 struct sk_buff *skb;
3053 int ret;
3054
3055 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3056 if (!skb)
3057 return -ENOMEM;
3058
3059 cmd = (struct wmi_11d_scan_stop_cmd *)skb->data;
3060 cmd->tlv_header =
3061 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_STOP_CMD) |
3062 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3063
3064 cmd->vdev_id = vdev_id;
3065
3066 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_STOP_CMDID);
3067 if (ret) {
3068 ath11k_warn(ar->ab,
3069 "failed to send WMI_11D_SCAN_STOP_CMDID: %d\n", ret);
3070 dev_kfree_skb(skb);
3071 }
3072
3073 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3074 "cmd 11d scan stop vdev id %d\n",
3075 cmd->vdev_id);
3076
3077 return ret;
3078}
3079
3080int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
3081{
3082 struct ath11k_pdev_wmi *wmi = ar->wmi;
3083 struct wmi_pktlog_enable_cmd *cmd;
3084 struct sk_buff *skb;
3085 int ret;
3086
3087 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3088 if (!skb)
3089 return -ENOMEM;
3090
3091 cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
3092
3093 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
3094 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3095
3096 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3097 cmd->evlist = pktlog_filter;
3098 cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
3099
3100 ret = ath11k_wmi_cmd_send(wmi, skb,
3101 WMI_PDEV_PKTLOG_ENABLE_CMDID);
3102 if (ret) {
3103 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3104 dev_kfree_skb(skb);
3105 }
3106
3107 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd pdev pktlog enable");
3108
3109 return ret;
3110}
3111
3112int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
3113{
3114 struct ath11k_pdev_wmi *wmi = ar->wmi;
3115 struct wmi_pktlog_disable_cmd *cmd;
3116 struct sk_buff *skb;
3117 int ret;
3118
3119 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3120 if (!skb)
3121 return -ENOMEM;
3122
3123 cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
3124
3125 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
3126 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3127
3128 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3129
3130 ret = ath11k_wmi_cmd_send(wmi, skb,
3131 WMI_PDEV_PKTLOG_DISABLE_CMDID);
3132 if (ret) {
3133 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3134 dev_kfree_skb(skb);
3135 }
3136
3137 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd pdev pktlog disable");
3138
3139 return ret;
3140}
3141
3142void ath11k_wmi_fill_default_twt_params(struct wmi_twt_enable_params *twt_params)
3143{
3144 twt_params->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
3145 twt_params->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
3146 twt_params->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
3147 twt_params->congestion_thresh_teardown =
3148 ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
3149 twt_params->congestion_thresh_critical =
3150 ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
3151 twt_params->interference_thresh_teardown =
3152 ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
3153 twt_params->interference_thresh_setup =
3154 ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
3155 twt_params->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
3156 twt_params->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
3157 twt_params->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
3158 twt_params->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
3159 twt_params->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
3160 twt_params->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
3161 twt_params->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
3162 twt_params->remove_sta_slot_interval =
3163 ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
3164 /* TODO add MBSSID support */
3165 twt_params->mbss_support = 0;
3166}
3167
3168int ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id,
3169 struct wmi_twt_enable_params *params)
3170{
3171 struct ath11k_pdev_wmi *wmi = ar->wmi;
3172 struct ath11k_base *ab = wmi->wmi_ab->ab;
3173 struct wmi_twt_enable_params_cmd *cmd;
3174 struct sk_buff *skb;
3175 int ret, len;
3176
3177 len = sizeof(*cmd);
3178
3179 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3180 if (!skb)
3181 return -ENOMEM;
3182
3183 cmd = (struct wmi_twt_enable_params_cmd *)skb->data;
3184 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
3185 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3186 cmd->pdev_id = pdev_id;
3187 cmd->sta_cong_timer_ms = params->sta_cong_timer_ms;
3188 cmd->default_slot_size = params->default_slot_size;
3189 cmd->congestion_thresh_setup = params->congestion_thresh_setup;
3190 cmd->congestion_thresh_teardown = params->congestion_thresh_teardown;
3191 cmd->congestion_thresh_critical = params->congestion_thresh_critical;
3192 cmd->interference_thresh_teardown = params->interference_thresh_teardown;
3193 cmd->interference_thresh_setup = params->interference_thresh_setup;
3194 cmd->min_no_sta_setup = params->min_no_sta_setup;
3195 cmd->min_no_sta_teardown = params->min_no_sta_teardown;
3196 cmd->no_of_bcast_mcast_slots = params->no_of_bcast_mcast_slots;
3197 cmd->min_no_twt_slots = params->min_no_twt_slots;
3198 cmd->max_no_sta_twt = params->max_no_sta_twt;
3199 cmd->mode_check_interval = params->mode_check_interval;
3200 cmd->add_sta_slot_interval = params->add_sta_slot_interval;
3201 cmd->remove_sta_slot_interval = params->remove_sta_slot_interval;
3202 cmd->mbss_support = params->mbss_support;
3203
3204 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ENABLE_CMDID);
3205 if (ret) {
3206 ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
3207 dev_kfree_skb(skb);
3208 return ret;
3209 }
3210
3211 ar->twt_enabled = 1;
3212
3213 ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd twt enable");
3214
3215 return 0;
3216}
3217
3218int
3219ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
3220{
3221 struct ath11k_pdev_wmi *wmi = ar->wmi;
3222 struct ath11k_base *ab = wmi->wmi_ab->ab;
3223 struct wmi_twt_disable_params_cmd *cmd;
3224 struct sk_buff *skb;
3225 int ret, len;
3226
3227 len = sizeof(*cmd);
3228
3229 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3230 if (!skb)
3231 return -ENOMEM;
3232
3233 cmd = (struct wmi_twt_disable_params_cmd *)skb->data;
3234 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
3235 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3236 cmd->pdev_id = pdev_id;
3237
3238 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DISABLE_CMDID);
3239 if (ret) {
3240 ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID");
3241 dev_kfree_skb(skb);
3242 return ret;
3243 }
3244
3245 ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd twt disable");
3246
3247 ar->twt_enabled = 0;
3248
3249 return 0;
3250}
3251
3252int ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k *ar,
3253 struct wmi_twt_add_dialog_params *params)
3254{
3255 struct ath11k_pdev_wmi *wmi = ar->wmi;
3256 struct ath11k_base *ab = wmi->wmi_ab->ab;
3257 struct wmi_twt_add_dialog_params_cmd *cmd;
3258 struct sk_buff *skb;
3259 int ret, len;
3260
3261 len = sizeof(*cmd);
3262
3263 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3264 if (!skb)
3265 return -ENOMEM;
3266
3267 cmd = (struct wmi_twt_add_dialog_params_cmd *)skb->data;
3268 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ADD_DIALOG_CMD) |
3269 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3270
3271 cmd->vdev_id = params->vdev_id;
3272 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3273 cmd->dialog_id = params->dialog_id;
3274 cmd->wake_intvl_us = params->wake_intvl_us;
3275 cmd->wake_intvl_mantis = params->wake_intvl_mantis;
3276 cmd->wake_dura_us = params->wake_dura_us;
3277 cmd->sp_offset_us = params->sp_offset_us;
3278 cmd->flags = params->twt_cmd;
3279 if (params->flag_bcast)
3280 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_BCAST;
3281 if (params->flag_trigger)
3282 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_TRIGGER;
3283 if (params->flag_flow_type)
3284 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_FLOW_TYPE;
3285 if (params->flag_protection)
3286 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_PROTECTION;
3287
3288 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ADD_DIALOG_CMDID);
3289 if (ret) {
3290 ath11k_warn(ab,
3291 "failed to send wmi command to add twt dialog: %d",
3292 ret);
3293 dev_kfree_skb(skb);
3294 return ret;
3295 }
3296
3297 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3298 "cmd twt add dialog vdev %u dialog id %u wake interval %u mantissa %u wake duration %u service period offset %u flags 0x%x\n",
3299 cmd->vdev_id, cmd->dialog_id, cmd->wake_intvl_us,
3300 cmd->wake_intvl_mantis, cmd->wake_dura_us, cmd->sp_offset_us,
3301 cmd->flags);
3302
3303 return 0;
3304}
3305
3306int ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k *ar,
3307 struct wmi_twt_del_dialog_params *params)
3308{
3309 struct ath11k_pdev_wmi *wmi = ar->wmi;
3310 struct ath11k_base *ab = wmi->wmi_ab->ab;
3311 struct wmi_twt_del_dialog_params_cmd *cmd;
3312 struct sk_buff *skb;
3313 int ret, len;
3314
3315 len = sizeof(*cmd);
3316
3317 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3318 if (!skb)
3319 return -ENOMEM;
3320
3321 cmd = (struct wmi_twt_del_dialog_params_cmd *)skb->data;
3322 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DEL_DIALOG_CMD) |
3323 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3324
3325 cmd->vdev_id = params->vdev_id;
3326 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3327 cmd->dialog_id = params->dialog_id;
3328
3329 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DEL_DIALOG_CMDID);
3330 if (ret) {
3331 ath11k_warn(ab,
3332 "failed to send wmi command to delete twt dialog: %d",
3333 ret);
3334 dev_kfree_skb(skb);
3335 return ret;
3336 }
3337
3338 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3339 "cmd twt del dialog vdev %u dialog id %u\n",
3340 cmd->vdev_id, cmd->dialog_id);
3341
3342 return 0;
3343}
3344
3345int ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k *ar,
3346 struct wmi_twt_pause_dialog_params *params)
3347{
3348 struct ath11k_pdev_wmi *wmi = ar->wmi;
3349 struct ath11k_base *ab = wmi->wmi_ab->ab;
3350 struct wmi_twt_pause_dialog_params_cmd *cmd;
3351 struct sk_buff *skb;
3352 int ret, len;
3353
3354 len = sizeof(*cmd);
3355
3356 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3357 if (!skb)
3358 return -ENOMEM;
3359
3360 cmd = (struct wmi_twt_pause_dialog_params_cmd *)skb->data;
3361 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3362 WMI_TAG_TWT_PAUSE_DIALOG_CMD) |
3363 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3364
3365 cmd->vdev_id = params->vdev_id;
3366 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3367 cmd->dialog_id = params->dialog_id;
3368
3369 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_PAUSE_DIALOG_CMDID);
3370 if (ret) {
3371 ath11k_warn(ab,
3372 "failed to send wmi command to pause twt dialog: %d",
3373 ret);
3374 dev_kfree_skb(skb);
3375 return ret;
3376 }
3377
3378 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3379 "cmd twt pause dialog vdev %u dialog id %u\n",
3380 cmd->vdev_id, cmd->dialog_id);
3381
3382 return 0;
3383}
3384
3385int ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k *ar,
3386 struct wmi_twt_resume_dialog_params *params)
3387{
3388 struct ath11k_pdev_wmi *wmi = ar->wmi;
3389 struct ath11k_base *ab = wmi->wmi_ab->ab;
3390 struct wmi_twt_resume_dialog_params_cmd *cmd;
3391 struct sk_buff *skb;
3392 int ret, len;
3393
3394 len = sizeof(*cmd);
3395
3396 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3397 if (!skb)
3398 return -ENOMEM;
3399
3400 cmd = (struct wmi_twt_resume_dialog_params_cmd *)skb->data;
3401 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3402 WMI_TAG_TWT_RESUME_DIALOG_CMD) |
3403 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3404
3405 cmd->vdev_id = params->vdev_id;
3406 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3407 cmd->dialog_id = params->dialog_id;
3408 cmd->sp_offset_us = params->sp_offset_us;
3409 cmd->next_twt_size = params->next_twt_size;
3410
3411 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_RESUME_DIALOG_CMDID);
3412 if (ret) {
3413 ath11k_warn(ab,
3414 "failed to send wmi command to resume twt dialog: %d",
3415 ret);
3416 dev_kfree_skb(skb);
3417 return ret;
3418 }
3419
3420 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3421 "cmd twt resume dialog vdev %u dialog id %u service period offset %u next twt subfield size %u\n",
3422 cmd->vdev_id, cmd->dialog_id, cmd->sp_offset_us,
3423 cmd->next_twt_size);
3424
3425 return 0;
3426}
3427
3428int
3429ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
3430 struct ieee80211_he_obss_pd *he_obss_pd)
3431{
3432 struct ath11k_pdev_wmi *wmi = ar->wmi;
3433 struct ath11k_base *ab = wmi->wmi_ab->ab;
3434 struct wmi_obss_spatial_reuse_params_cmd *cmd;
3435 struct sk_buff *skb;
3436 int ret, len;
3437
3438 len = sizeof(*cmd);
3439
3440 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3441 if (!skb)
3442 return -ENOMEM;
3443
3444 cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data;
3445 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3446 WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
3447 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3448 cmd->vdev_id = vdev_id;
3449 cmd->enable = he_obss_pd->enable;
3450 cmd->obss_min = he_obss_pd->min_offset;
3451 cmd->obss_max = he_obss_pd->max_offset;
3452
3453 ret = ath11k_wmi_cmd_send(wmi, skb,
3454 WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
3455 if (ret) {
3456 ath11k_warn(ab,
3457 "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
3458 dev_kfree_skb(skb);
3459 return ret;
3460 }
3461
3462 ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd pdev obss pd spatial reuse");
3463
3464 return 0;
3465}
3466
3467int
3468ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k *ar, u32 *bitmap)
3469{
3470 struct ath11k_pdev_wmi *wmi = ar->wmi;
3471 struct ath11k_base *ab = wmi->wmi_ab->ab;
3472 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3473 struct sk_buff *skb;
3474 int ret, len;
3475
3476 len = sizeof(*cmd);
3477
3478 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3479 if (!skb)
3480 return -ENOMEM;
3481
3482 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3483 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3484 WMI_TAG_PDEV_SRG_BSS_COLOR_BITMAP_CMD) |
3485 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3486 cmd->pdev_id = ar->pdev->pdev_id;
3487 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3488
3489 ret = ath11k_wmi_cmd_send(wmi, skb,
3490 WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID);
3491 if (ret) {
3492 ath11k_warn(ab,
3493 "failed to send WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID");
3494 dev_kfree_skb(skb);
3495 return ret;
3496 }
3497
3498 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3499 "cmd pdev set srg bss color bitmap pdev_id %d bss color bitmap %08x %08x\n",
3500 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3501
3502 return 0;
3503}
3504
3505int
3506ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k *ar, u32 *bitmap)
3507{
3508 struct ath11k_pdev_wmi *wmi = ar->wmi;
3509 struct ath11k_base *ab = wmi->wmi_ab->ab;
3510 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3511 struct sk_buff *skb;
3512 int ret, len;
3513
3514 len = sizeof(*cmd);
3515
3516 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3517 if (!skb)
3518 return -ENOMEM;
3519
3520 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3521 cmd->tlv_header =
3522 FIELD_PREP(WMI_TLV_TAG,
3523 WMI_TAG_PDEV_SRG_PARTIAL_BSSID_BITMAP_CMD) |
3524 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3525 cmd->pdev_id = ar->pdev->pdev_id;
3526 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3527
3528 ret = ath11k_wmi_cmd_send(wmi, skb,
3529 WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID);
3530 if (ret) {
3531 ath11k_warn(ab,
3532 "failed to send WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID");
3533 dev_kfree_skb(skb);
3534 return ret;
3535 }
3536
3537 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3538 "cmd pdev set srg partial bssid bitmap pdev_id %d partial bssid bitmap %08x %08x\n",
3539 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3540
3541 return 0;
3542}
3543
3544int
3545ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3546{
3547 struct ath11k_pdev_wmi *wmi = ar->wmi;
3548 struct ath11k_base *ab = wmi->wmi_ab->ab;
3549 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3550 struct sk_buff *skb;
3551 int ret, len;
3552
3553 len = sizeof(*cmd);
3554
3555 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3556 if (!skb)
3557 return -ENOMEM;
3558
3559 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3560 cmd->tlv_header =
3561 FIELD_PREP(WMI_TLV_TAG,
3562 WMI_TAG_PDEV_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3563 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3564 cmd->pdev_id = ar->pdev->pdev_id;
3565 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3566
3567 ret = ath11k_wmi_cmd_send(wmi, skb,
3568 WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3569 if (ret) {
3570 ath11k_warn(ab,
3571 "failed to send WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3572 dev_kfree_skb(skb);
3573 return ret;
3574 }
3575
3576 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3577 "cmd pdev set srg obsscolor enable pdev_id %d bss color enable bitmap %08x %08x\n",
3578 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3579
3580 return 0;
3581}
3582
3583int
3584ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3585{
3586 struct ath11k_pdev_wmi *wmi = ar->wmi;
3587 struct ath11k_base *ab = wmi->wmi_ab->ab;
3588 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3589 struct sk_buff *skb;
3590 int ret, len;
3591
3592 len = sizeof(*cmd);
3593
3594 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3595 if (!skb)
3596 return -ENOMEM;
3597
3598 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3599 cmd->tlv_header =
3600 FIELD_PREP(WMI_TLV_TAG,
3601 WMI_TAG_PDEV_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3602 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3603 cmd->pdev_id = ar->pdev->pdev_id;
3604 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3605
3606 ret = ath11k_wmi_cmd_send(wmi, skb,
3607 WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3608 if (ret) {
3609 ath11k_warn(ab,
3610 "failed to send WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3611 dev_kfree_skb(skb);
3612 return ret;
3613 }
3614
3615 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3616 "cmd pdev set srg obss bssid enable bitmap pdev_id %d bssid enable bitmap %08x %08x\n",
3617 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3618
3619 return 0;
3620}
3621
3622int
3623ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3624{
3625 struct ath11k_pdev_wmi *wmi = ar->wmi;
3626 struct ath11k_base *ab = wmi->wmi_ab->ab;
3627 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3628 struct sk_buff *skb;
3629 int ret, len;
3630
3631 len = sizeof(*cmd);
3632
3633 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3634 if (!skb)
3635 return -ENOMEM;
3636
3637 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3638 cmd->tlv_header =
3639 FIELD_PREP(WMI_TLV_TAG,
3640 WMI_TAG_PDEV_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3641 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3642 cmd->pdev_id = ar->pdev->pdev_id;
3643 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3644
3645 ret = ath11k_wmi_cmd_send(wmi, skb,
3646 WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3647 if (ret) {
3648 ath11k_warn(ab,
3649 "failed to send WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3650 dev_kfree_skb(skb);
3651 return ret;
3652 }
3653
3654 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3655 "cmd pdev set non srg obss color enable bitmap pdev_id %d bss color enable bitmap %08x %08x\n",
3656 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3657
3658 return 0;
3659}
3660
3661int
3662ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3663{
3664 struct ath11k_pdev_wmi *wmi = ar->wmi;
3665 struct ath11k_base *ab = wmi->wmi_ab->ab;
3666 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3667 struct sk_buff *skb;
3668 int ret, len;
3669
3670 len = sizeof(*cmd);
3671
3672 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3673 if (!skb)
3674 return -ENOMEM;
3675
3676 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3677 cmd->tlv_header =
3678 FIELD_PREP(WMI_TLV_TAG,
3679 WMI_TAG_PDEV_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3680 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3681 cmd->pdev_id = ar->pdev->pdev_id;
3682 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3683
3684 ret = ath11k_wmi_cmd_send(wmi, skb,
3685 WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3686 if (ret) {
3687 ath11k_warn(ab,
3688 "failed to send WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3689 dev_kfree_skb(skb);
3690 return ret;
3691 }
3692
3693 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3694 "cmd pdev set non srg obss bssid enable bitmap pdev_id %d bssid enable bitmap %08x %08x\n",
3695 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3696
3697 return 0;
3698}
3699
3700int
3701ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id,
3702 u8 bss_color, u32 period,
3703 bool enable)
3704{
3705 struct ath11k_pdev_wmi *wmi = ar->wmi;
3706 struct ath11k_base *ab = wmi->wmi_ab->ab;
3707 struct wmi_obss_color_collision_cfg_params_cmd *cmd;
3708 struct sk_buff *skb;
3709 int ret, len;
3710
3711 len = sizeof(*cmd);
3712
3713 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3714 if (!skb)
3715 return -ENOMEM;
3716
3717 cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data;
3718 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3719 WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) |
3720 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3721 cmd->vdev_id = vdev_id;
3722 cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION :
3723 ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE;
3724 cmd->current_bss_color = bss_color;
3725 cmd->detection_period_ms = period;
3726 cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS;
3727 cmd->free_slot_expiry_time_ms = 0;
3728 cmd->flags = 0;
3729
3730 ret = ath11k_wmi_cmd_send(wmi, skb,
3731 WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID);
3732 if (ret) {
3733 ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID");
3734 dev_kfree_skb(skb);
3735 return ret;
3736 }
3737
3738 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3739 "cmd obss color collision det config id %d type %d bss_color %d detect_period %d scan_period %d\n",
3740 cmd->vdev_id, cmd->evt_type, cmd->current_bss_color,
3741 cmd->detection_period_ms, cmd->scan_period_ms);
3742
3743 return 0;
3744}
3745
3746int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id,
3747 bool enable)
3748{
3749 struct ath11k_pdev_wmi *wmi = ar->wmi;
3750 struct ath11k_base *ab = wmi->wmi_ab->ab;
3751 struct wmi_bss_color_change_enable_params_cmd *cmd;
3752 struct sk_buff *skb;
3753 int ret, len;
3754
3755 len = sizeof(*cmd);
3756
3757 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3758 if (!skb)
3759 return -ENOMEM;
3760
3761 cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data;
3762 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) |
3763 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3764 cmd->vdev_id = vdev_id;
3765 cmd->enable = enable ? 1 : 0;
3766
3767 ret = ath11k_wmi_cmd_send(wmi, skb,
3768 WMI_BSS_COLOR_CHANGE_ENABLE_CMDID);
3769 if (ret) {
3770 ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID");
3771 dev_kfree_skb(skb);
3772 return ret;
3773 }
3774
3775 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3776 "cmd bss color change enable id %d enable %d\n",
3777 cmd->vdev_id, cmd->enable);
3778
3779 return 0;
3780}
3781
3782int ath11k_wmi_fils_discovery_tmpl(struct ath11k *ar, u32 vdev_id,
3783 struct sk_buff *tmpl)
3784{
3785 struct wmi_tlv *tlv;
3786 struct sk_buff *skb;
3787 void *ptr;
3788 int ret, len;
3789 size_t aligned_len;
3790 struct wmi_fils_discovery_tmpl_cmd *cmd;
3791
3792 aligned_len = roundup(tmpl->len, 4);
3793 len = sizeof(*cmd) + TLV_HDR_SIZE + aligned_len;
3794
3795 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3796 "vdev %i set FILS discovery template\n", vdev_id);
3797
3798 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3799 if (!skb)
3800 return -ENOMEM;
3801
3802 cmd = (struct wmi_fils_discovery_tmpl_cmd *)skb->data;
3803 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3804 WMI_TAG_FILS_DISCOVERY_TMPL_CMD) |
3805 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3806 cmd->vdev_id = vdev_id;
3807 cmd->buf_len = tmpl->len;
3808 ptr = skb->data + sizeof(*cmd);
3809
3810 tlv = ptr;
3811 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3812 FIELD_PREP(WMI_TLV_LEN, aligned_len);
3813 memcpy(tlv->value, tmpl->data, tmpl->len);
3814
3815 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_FILS_DISCOVERY_TMPL_CMDID);
3816 if (ret) {
3817 ath11k_warn(ar->ab,
3818 "WMI vdev %i failed to send FILS discovery template command\n",
3819 vdev_id);
3820 dev_kfree_skb(skb);
3821 return ret;
3822 }
3823
3824 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd fils discovery tmpl");
3825
3826 return 0;
3827}
3828
3829int ath11k_wmi_probe_resp_tmpl(struct ath11k *ar, u32 vdev_id,
3830 struct sk_buff *tmpl)
3831{
3832 struct wmi_probe_tmpl_cmd *cmd;
3833 struct wmi_bcn_prb_info *probe_info;
3834 struct wmi_tlv *tlv;
3835 struct sk_buff *skb;
3836 void *ptr;
3837 int ret, len;
3838 size_t aligned_len = roundup(tmpl->len, 4);
3839
3840 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3841 "vdev %i set probe response template\n", vdev_id);
3842
3843 len = sizeof(*cmd) + sizeof(*probe_info) + TLV_HDR_SIZE + aligned_len;
3844
3845 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3846 if (!skb)
3847 return -ENOMEM;
3848
3849 cmd = (struct wmi_probe_tmpl_cmd *)skb->data;
3850 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PRB_TMPL_CMD) |
3851 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3852 cmd->vdev_id = vdev_id;
3853 cmd->buf_len = tmpl->len;
3854
3855 ptr = skb->data + sizeof(*cmd);
3856
3857 probe_info = ptr;
3858 len = sizeof(*probe_info);
3859 probe_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3860 WMI_TAG_BCN_PRB_INFO) |
3861 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3862 probe_info->caps = 0;
3863 probe_info->erp = 0;
3864
3865 ptr += sizeof(*probe_info);
3866
3867 tlv = ptr;
3868 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3869 FIELD_PREP(WMI_TLV_LEN, aligned_len);
3870 memcpy(tlv->value, tmpl->data, tmpl->len);
3871
3872 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_PRB_TMPL_CMDID);
3873 if (ret) {
3874 ath11k_warn(ar->ab,
3875 "WMI vdev %i failed to send probe response template command\n",
3876 vdev_id);
3877 dev_kfree_skb(skb);
3878 return ret;
3879 }
3880
3881 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd ");
3882
3883 return 0;
3884}
3885
3886int ath11k_wmi_fils_discovery(struct ath11k *ar, u32 vdev_id, u32 interval,
3887 bool unsol_bcast_probe_resp_enabled)
3888{
3889 struct sk_buff *skb;
3890 int ret, len;
3891 struct wmi_fils_discovery_cmd *cmd;
3892
3893 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3894 "vdev %i set %s interval to %u TU\n",
3895 vdev_id, unsol_bcast_probe_resp_enabled ?
3896 "unsolicited broadcast probe response" : "FILS discovery",
3897 interval);
3898
3899 len = sizeof(*cmd);
3900 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3901 if (!skb)
3902 return -ENOMEM;
3903
3904 cmd = (struct wmi_fils_discovery_cmd *)skb->data;
3905 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ENABLE_FILS_CMD) |
3906 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3907 cmd->vdev_id = vdev_id;
3908 cmd->interval = interval;
3909 cmd->config = unsol_bcast_probe_resp_enabled;
3910
3911 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_ENABLE_FILS_CMDID);
3912 if (ret) {
3913 ath11k_warn(ar->ab,
3914 "WMI vdev %i failed to send FILS discovery enable/disable command\n",
3915 vdev_id);
3916 dev_kfree_skb(skb);
3917 return ret;
3918 }
3919
3920 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd enable fils");
3921
3922 return 0;
3923}
3924
3925static void
3926ath11k_wmi_obss_color_collision_event(struct ath11k_base *ab, struct sk_buff *skb)
3927{
3928 const void **tb;
3929 const struct wmi_obss_color_collision_event *ev;
3930 struct ath11k_vif *arvif;
3931 int ret;
3932
3933 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3934 if (IS_ERR(tb)) {
3935 ret = PTR_ERR(tb);
3936 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3937 return;
3938 }
3939
3940 ath11k_dbg(ab, ATH11K_DBG_WMI, "event obss color collision");
3941
3942 rcu_read_lock();
3943
3944 ev = tb[WMI_TAG_OBSS_COLOR_COLLISION_EVT];
3945 if (!ev) {
3946 ath11k_warn(ab, "failed to fetch obss color collision ev");
3947 goto exit;
3948 }
3949
3950 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
3951 if (!arvif) {
3952 ath11k_warn(ab, "failed to find arvif with vedv id %d in obss_color_collision_event\n",
3953 ev->vdev_id);
3954 goto exit;
3955 }
3956
3957 switch (ev->evt_type) {
3958 case WMI_BSS_COLOR_COLLISION_DETECTION:
3959 ieee80211_obss_color_collision_notify(arvif->vif, ev->obss_color_bitmap,
3960 GFP_KERNEL);
3961 ath11k_dbg(ab, ATH11K_DBG_WMI,
3962 "OBSS color collision detected vdev:%d, event:%d, bitmap:%08llx\n",
3963 ev->vdev_id, ev->evt_type, ev->obss_color_bitmap);
3964 break;
3965 case WMI_BSS_COLOR_COLLISION_DISABLE:
3966 case WMI_BSS_COLOR_FREE_SLOT_TIMER_EXPIRY:
3967 case WMI_BSS_COLOR_FREE_SLOT_AVAILABLE:
3968 break;
3969 default:
3970 ath11k_warn(ab, "received unknown obss color collision detection event\n");
3971 }
3972
3973exit:
3974 kfree(tb);
3975 rcu_read_unlock();
3976}
3977
3978static void
3979ath11k_fill_band_to_mac_param(struct ath11k_base *soc,
3980 struct wmi_host_pdev_band_to_mac *band_to_mac)
3981{
3982 u8 i;
3983 struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
3984 struct ath11k_pdev *pdev;
3985
3986 for (i = 0; i < soc->num_radios; i++) {
3987 pdev = &soc->pdevs[i];
3988 hal_reg_cap = &soc->hal_reg_cap[i];
3989 band_to_mac[i].pdev_id = pdev->pdev_id;
3990
3991 switch (pdev->cap.supported_bands) {
3992 case WMI_HOST_WLAN_2G_5G_CAP:
3993 band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3994 band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3995 break;
3996 case WMI_HOST_WLAN_2G_CAP:
3997 band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3998 band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
3999 break;
4000 case WMI_HOST_WLAN_5G_CAP:
4001 band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
4002 band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
4003 break;
4004 default:
4005 break;
4006 }
4007 }
4008}
4009
4010static void
4011ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
4012 struct target_resource_config *tg_cfg)
4013{
4014 wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
4015 wmi_cfg->num_peers = tg_cfg->num_peers;
4016 wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
4017 wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
4018 wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
4019 wmi_cfg->num_tids = tg_cfg->num_tids;
4020 wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
4021 wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
4022 wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
4023 wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
4024 wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
4025 wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
4026 wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
4027 wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
4028 wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
4029 wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
4030 wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
4031 wmi_cfg->roam_offload_max_ap_profiles =
4032 tg_cfg->roam_offload_max_ap_profiles;
4033 wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
4034 wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
4035 wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
4036 wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
4037 wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
4038 wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
4039 wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
4040 wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
4041 tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
4042 wmi_cfg->vow_config = tg_cfg->vow_config;
4043 wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
4044 wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
4045 wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
4046 wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
4047 wmi_cfg->num_tdls_conn_table_entries =
4048 tg_cfg->num_tdls_conn_table_entries;
4049 wmi_cfg->beacon_tx_offload_max_vdev =
4050 tg_cfg->beacon_tx_offload_max_vdev;
4051 wmi_cfg->num_multicast_filter_entries =
4052 tg_cfg->num_multicast_filter_entries;
4053 wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
4054 wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
4055 wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
4056 wmi_cfg->max_tdls_concurrent_sleep_sta =
4057 tg_cfg->max_tdls_concurrent_sleep_sta;
4058 wmi_cfg->max_tdls_concurrent_buffer_sta =
4059 tg_cfg->max_tdls_concurrent_buffer_sta;
4060 wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
4061 wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
4062 wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
4063 wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
4064 wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
4065 wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
4066 wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
4067 wmi_cfg->flag1 = tg_cfg->flag1;
4068 wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
4069 wmi_cfg->sched_params = tg_cfg->sched_params;
4070 wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
4071 wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
4072 wmi_cfg->host_service_flags &=
4073 ~(1 << WMI_CFG_HOST_SERVICE_FLAG_REG_CC_EXT);
4074 wmi_cfg->host_service_flags |= (tg_cfg->is_reg_cc_ext_event_supported <<
4075 WMI_CFG_HOST_SERVICE_FLAG_REG_CC_EXT);
4076 wmi_cfg->flags2 = WMI_RSRC_CFG_FLAG2_CALC_NEXT_DTIM_COUNT_SET;
4077 wmi_cfg->ema_max_vap_cnt = tg_cfg->ema_max_vap_cnt;
4078 wmi_cfg->ema_max_profile_period = tg_cfg->ema_max_profile_period;
4079}
4080
4081static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
4082 struct wmi_init_cmd_param *param)
4083{
4084 struct ath11k_base *ab = wmi->wmi_ab->ab;
4085 struct sk_buff *skb;
4086 struct wmi_init_cmd *cmd;
4087 struct wmi_resource_config *cfg;
4088 struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
4089 struct wmi_pdev_band_to_mac *band_to_mac;
4090 struct wlan_host_mem_chunk *host_mem_chunks;
4091 struct wmi_tlv *tlv;
4092 size_t ret, len;
4093 void *ptr;
4094 u32 hw_mode_len = 0;
4095 u16 idx;
4096
4097 if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
4098 hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
4099 (param->num_band_to_mac * sizeof(*band_to_mac));
4100
4101 len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
4102 (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0);
4103
4104 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
4105 if (!skb)
4106 return -ENOMEM;
4107
4108 cmd = (struct wmi_init_cmd *)skb->data;
4109
4110 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
4111 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4112
4113 ptr = skb->data + sizeof(*cmd);
4114 cfg = ptr;
4115
4116 ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
4117
4118 cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
4119 FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
4120
4121 ptr += sizeof(*cfg);
4122 host_mem_chunks = ptr + TLV_HDR_SIZE;
4123 len = sizeof(struct wlan_host_mem_chunk);
4124
4125 for (idx = 0; idx < param->num_mem_chunks; ++idx) {
4126 host_mem_chunks[idx].tlv_header =
4127 FIELD_PREP(WMI_TLV_TAG,
4128 WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
4129 FIELD_PREP(WMI_TLV_LEN, len);
4130
4131 host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
4132 host_mem_chunks[idx].size = param->mem_chunks[idx].len;
4133 host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
4134
4135 ath11k_dbg(ab, ATH11K_DBG_WMI,
4136 "host mem chunk req_id %d paddr 0x%llx len %d\n",
4137 param->mem_chunks[idx].req_id,
4138 (u64)param->mem_chunks[idx].paddr,
4139 param->mem_chunks[idx].len);
4140 }
4141 cmd->num_host_mem_chunks = param->num_mem_chunks;
4142 len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
4143
4144 /* num_mem_chunks is zero */
4145 tlv = ptr;
4146 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4147 FIELD_PREP(WMI_TLV_LEN, len);
4148 ptr += TLV_HDR_SIZE + len;
4149
4150 if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
4151 hw_mode = ptr;
4152 hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4153 WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4154 FIELD_PREP(WMI_TLV_LEN,
4155 sizeof(*hw_mode) - TLV_HDR_SIZE);
4156
4157 hw_mode->hw_mode_index = param->hw_mode_id;
4158 hw_mode->num_band_to_mac = param->num_band_to_mac;
4159
4160 ptr += sizeof(*hw_mode);
4161
4162 len = param->num_band_to_mac * sizeof(*band_to_mac);
4163 tlv = ptr;
4164 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4165 FIELD_PREP(WMI_TLV_LEN, len);
4166
4167 ptr += TLV_HDR_SIZE;
4168 len = sizeof(*band_to_mac);
4169
4170 for (idx = 0; idx < param->num_band_to_mac; idx++) {
4171 band_to_mac = ptr;
4172
4173 band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4174 WMI_TAG_PDEV_BAND_TO_MAC) |
4175 FIELD_PREP(WMI_TLV_LEN,
4176 len - TLV_HDR_SIZE);
4177 band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
4178 band_to_mac->start_freq =
4179 param->band_to_mac[idx].start_freq;
4180 band_to_mac->end_freq =
4181 param->band_to_mac[idx].end_freq;
4182 ptr += sizeof(*band_to_mac);
4183 }
4184 }
4185
4186 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
4187 if (ret) {
4188 ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
4189 dev_kfree_skb(skb);
4190 return ret;
4191 }
4192
4193 ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd wmi init");
4194
4195 return 0;
4196}
4197
4198int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar,
4199 int pdev_id)
4200{
4201 struct ath11k_wmi_pdev_lro_config_cmd *cmd;
4202 struct sk_buff *skb;
4203 int ret;
4204
4205 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4206 if (!skb)
4207 return -ENOMEM;
4208
4209 cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data;
4210 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) |
4211 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4212
4213 get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE);
4214 get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE);
4215
4216 cmd->pdev_id = pdev_id;
4217
4218 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID);
4219 if (ret) {
4220 ath11k_warn(ar->ab,
4221 "failed to send lro cfg req wmi cmd\n");
4222 goto err;
4223 }
4224
4225 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4226 "cmd lro config pdev_id 0x%x\n", pdev_id);
4227 return 0;
4228err:
4229 dev_kfree_skb(skb);
4230 return ret;
4231}
4232
4233int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
4234{
4235 unsigned long time_left;
4236
4237 time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready,
4238 WMI_SERVICE_READY_TIMEOUT_HZ);
4239 if (!time_left)
4240 return -ETIMEDOUT;
4241
4242 return 0;
4243}
4244
4245int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
4246{
4247 unsigned long time_left;
4248
4249 time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready,
4250 WMI_SERVICE_READY_TIMEOUT_HZ);
4251 if (!time_left)
4252 return -ETIMEDOUT;
4253
4254 return 0;
4255}
4256
4257int ath11k_wmi_set_hw_mode(struct ath11k_base *ab,
4258 enum wmi_host_hw_mode_config_type mode)
4259{
4260 struct wmi_pdev_set_hw_mode_cmd_param *cmd;
4261 struct sk_buff *skb;
4262 struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab;
4263 int len;
4264 int ret;
4265
4266 len = sizeof(*cmd);
4267
4268 skb = ath11k_wmi_alloc_skb(wmi_ab, len);
4269 if (!skb)
4270 return -ENOMEM;
4271
4272 cmd = (struct wmi_pdev_set_hw_mode_cmd_param *)skb->data;
4273
4274 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4275 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4276
4277 cmd->pdev_id = WMI_PDEV_ID_SOC;
4278 cmd->hw_mode_index = mode;
4279
4280 ret = ath11k_wmi_cmd_send(&wmi_ab->wmi[0], skb, WMI_PDEV_SET_HW_MODE_CMDID);
4281 if (ret) {
4282 ath11k_warn(ab, "failed to send WMI_PDEV_SET_HW_MODE_CMDID\n");
4283 dev_kfree_skb(skb);
4284 return ret;
4285 }
4286
4287 ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd pdev set hw mode %d", cmd->hw_mode_index);
4288
4289 return 0;
4290}
4291
4292int ath11k_wmi_cmd_init(struct ath11k_base *ab)
4293{
4294 struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab;
4295 struct wmi_init_cmd_param init_param;
4296 struct target_resource_config config;
4297
4298 memset(&init_param, 0, sizeof(init_param));
4299 memset(&config, 0, sizeof(config));
4300
4301 ab->hw_params.hw_ops->wmi_init_config(ab, &config);
4302
4303 if (test_bit(WMI_TLV_SERVICE_REG_CC_EXT_EVENT_SUPPORT,
4304 ab->wmi_ab.svc_map))
4305 config.is_reg_cc_ext_event_supported = 1;
4306
4307 memcpy(&wmi_ab->wlan_resource_config, &config, sizeof(config));
4308
4309 init_param.res_cfg = &wmi_ab->wlan_resource_config;
4310 init_param.num_mem_chunks = wmi_ab->num_mem_chunks;
4311 init_param.hw_mode_id = wmi_ab->preferred_hw_mode;
4312 init_param.mem_chunks = wmi_ab->mem_chunks;
4313
4314 if (ab->hw_params.single_pdev_only)
4315 init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
4316
4317 init_param.num_band_to_mac = ab->num_radios;
4318 ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
4319
4320 return ath11k_init_cmd_send(&wmi_ab->wmi[0], &init_param);
4321}
4322
4323int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar,
4324 struct ath11k_wmi_vdev_spectral_conf_param *param)
4325{
4326 struct ath11k_wmi_vdev_spectral_conf_cmd *cmd;
4327 struct sk_buff *skb;
4328 int ret;
4329
4330 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4331 if (!skb)
4332 return -ENOMEM;
4333
4334 cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data;
4335 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4336 WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) |
4337 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4338
4339 memcpy(&cmd->param, param, sizeof(*param));
4340
4341 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4342 WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
4343 if (ret) {
4344 ath11k_warn(ar->ab,
4345 "failed to send spectral scan config wmi cmd\n");
4346 goto err;
4347 }
4348
4349 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4350 "cmd vdev spectral scan configure vdev_id 0x%x\n",
4351 param->vdev_id);
4352
4353 return 0;
4354err:
4355 dev_kfree_skb(skb);
4356 return ret;
4357}
4358
4359int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id,
4360 u32 trigger, u32 enable)
4361{
4362 struct ath11k_wmi_vdev_spectral_enable_cmd *cmd;
4363 struct sk_buff *skb;
4364 int ret;
4365
4366 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4367 if (!skb)
4368 return -ENOMEM;
4369
4370 cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data;
4371 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4372 WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) |
4373 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4374
4375 cmd->vdev_id = vdev_id;
4376 cmd->trigger_cmd = trigger;
4377 cmd->enable_cmd = enable;
4378
4379 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4380 WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
4381 if (ret) {
4382 ath11k_warn(ar->ab,
4383 "failed to send spectral enable wmi cmd\n");
4384 goto err;
4385 }
4386
4387 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4388 "cmd vdev spectral scan enable vdev id 0x%x\n",
4389 vdev_id);
4390
4391 return 0;
4392err:
4393 dev_kfree_skb(skb);
4394 return ret;
4395}
4396
4397int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar,
4398 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param)
4399{
4400 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd;
4401 struct sk_buff *skb;
4402 int ret;
4403
4404 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4405 if (!skb)
4406 return -ENOMEM;
4407
4408 cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data;
4409 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) |
4410 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4411
4412 cmd->pdev_id = param->pdev_id;
4413 cmd->module_id = param->module_id;
4414 cmd->base_paddr_lo = param->base_paddr_lo;
4415 cmd->base_paddr_hi = param->base_paddr_hi;
4416 cmd->head_idx_paddr_lo = param->head_idx_paddr_lo;
4417 cmd->head_idx_paddr_hi = param->head_idx_paddr_hi;
4418 cmd->tail_idx_paddr_lo = param->tail_idx_paddr_lo;
4419 cmd->tail_idx_paddr_hi = param->tail_idx_paddr_hi;
4420 cmd->num_elems = param->num_elems;
4421 cmd->buf_size = param->buf_size;
4422 cmd->num_resp_per_event = param->num_resp_per_event;
4423 cmd->event_timeout_ms = param->event_timeout_ms;
4424
4425 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4426 WMI_PDEV_DMA_RING_CFG_REQ_CMDID);
4427 if (ret) {
4428 ath11k_warn(ar->ab,
4429 "failed to send dma ring cfg req wmi cmd\n");
4430 goto err;
4431 }
4432
4433 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4434 "cmd pdev dma ring cfg req pdev_id 0x%x\n",
4435 param->pdev_id);
4436
4437 return 0;
4438err:
4439 dev_kfree_skb(skb);
4440 return ret;
4441}
4442
4443static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc,
4444 u16 tag, u16 len,
4445 const void *ptr, void *data)
4446{
4447 struct wmi_tlv_dma_buf_release_parse *parse = data;
4448
4449 if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY)
4450 return -EPROTO;
4451
4452 if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry)
4453 return -ENOBUFS;
4454
4455 parse->num_buf_entry++;
4456 return 0;
4457}
4458
4459static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc,
4460 u16 tag, u16 len,
4461 const void *ptr, void *data)
4462{
4463 struct wmi_tlv_dma_buf_release_parse *parse = data;
4464
4465 if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA)
4466 return -EPROTO;
4467
4468 if (parse->num_meta >= parse->fixed.num_meta_data_entry)
4469 return -ENOBUFS;
4470
4471 parse->num_meta++;
4472 return 0;
4473}
4474
4475static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab,
4476 u16 tag, u16 len,
4477 const void *ptr, void *data)
4478{
4479 struct wmi_tlv_dma_buf_release_parse *parse = data;
4480 int ret;
4481
4482 switch (tag) {
4483 case WMI_TAG_DMA_BUF_RELEASE:
4484 memcpy(&parse->fixed, ptr,
4485 sizeof(struct ath11k_wmi_dma_buf_release_fixed_param));
4486 parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id);
4487 break;
4488 case WMI_TAG_ARRAY_STRUCT:
4489 if (!parse->buf_entry_done) {
4490 parse->num_buf_entry = 0;
4491 parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr;
4492
4493 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4494 ath11k_wmi_tlv_dma_buf_entry_parse,
4495 parse);
4496 if (ret) {
4497 ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n",
4498 ret);
4499 return ret;
4500 }
4501
4502 parse->buf_entry_done = true;
4503 } else if (!parse->meta_data_done) {
4504 parse->num_meta = 0;
4505 parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr;
4506
4507 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4508 ath11k_wmi_tlv_dma_buf_meta_parse,
4509 parse);
4510 if (ret) {
4511 ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n",
4512 ret);
4513 return ret;
4514 }
4515
4516 parse->meta_data_done = true;
4517 }
4518 break;
4519 default:
4520 break;
4521 }
4522 return 0;
4523}
4524
4525static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab,
4526 struct sk_buff *skb)
4527{
4528 struct wmi_tlv_dma_buf_release_parse parse = { };
4529 struct ath11k_dbring_buf_release_event param;
4530 int ret;
4531
4532 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4533 ath11k_wmi_tlv_dma_buf_parse,
4534 &parse);
4535 if (ret) {
4536 ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret);
4537 return;
4538 }
4539
4540 ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev dma ring buf release");
4541
4542 param.fixed = parse.fixed;
4543 param.buf_entry = parse.buf_entry;
4544 param.num_buf_entry = parse.num_buf_entry;
4545 param.meta_data = parse.meta_data;
4546 param.num_meta = parse.num_meta;
4547
4548 ret = ath11k_dbring_buffer_release_event(ab, ¶m);
4549 if (ret) {
4550 ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
4551 return;
4552 }
4553}
4554
4555static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
4556 u16 tag, u16 len,
4557 const void *ptr, void *data)
4558{
4559 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4560 struct wmi_hw_mode_capabilities *hw_mode_cap;
4561 u32 phy_map = 0;
4562
4563 if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
4564 return -EPROTO;
4565
4566 if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
4567 return -ENOBUFS;
4568
4569 hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
4570 hw_mode_id);
4571 svc_rdy_ext->n_hw_mode_caps++;
4572
4573 phy_map = hw_mode_cap->phy_id_map;
4574 while (phy_map) {
4575 svc_rdy_ext->tot_phy_id++;
4576 phy_map = phy_map >> 1;
4577 }
4578
4579 return 0;
4580}
4581
4582static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
4583 u16 len, const void *ptr, void *data)
4584{
4585 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4586 struct wmi_hw_mode_capabilities *hw_mode_caps;
4587 enum wmi_host_hw_mode_config_type mode, pref;
4588 u32 i;
4589 int ret;
4590
4591 svc_rdy_ext->n_hw_mode_caps = 0;
4592 svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
4593
4594 ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4595 ath11k_wmi_tlv_hw_mode_caps_parse,
4596 svc_rdy_ext);
4597 if (ret) {
4598 ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4599 return ret;
4600 }
4601
4602 i = 0;
4603 while (i < svc_rdy_ext->n_hw_mode_caps) {
4604 hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
4605 mode = hw_mode_caps->hw_mode_id;
4606 pref = soc->wmi_ab.preferred_hw_mode;
4607
4608 if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
4609 svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
4610 soc->wmi_ab.preferred_hw_mode = mode;
4611 }
4612 i++;
4613 }
4614
4615 ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n",
4616 soc->wmi_ab.preferred_hw_mode);
4617 if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
4618 return -EINVAL;
4619
4620 return 0;
4621}
4622
4623static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
4624 u16 tag, u16 len,
4625 const void *ptr, void *data)
4626{
4627 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4628
4629 if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
4630 return -EPROTO;
4631
4632 if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
4633 return -ENOBUFS;
4634
4635 len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
4636 if (!svc_rdy_ext->n_mac_phy_caps) {
4637 svc_rdy_ext->mac_phy_caps = kcalloc(svc_rdy_ext->tot_phy_id,
4638 len, GFP_ATOMIC);
4639 if (!svc_rdy_ext->mac_phy_caps)
4640 return -ENOMEM;
4641 }
4642
4643 memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
4644 svc_rdy_ext->n_mac_phy_caps++;
4645 return 0;
4646}
4647
4648static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
4649 u16 tag, u16 len,
4650 const void *ptr, void *data)
4651{
4652 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4653
4654 if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
4655 return -EPROTO;
4656
4657 if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
4658 return -ENOBUFS;
4659
4660 svc_rdy_ext->n_ext_hal_reg_caps++;
4661 return 0;
4662}
4663
4664static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
4665 u16 len, const void *ptr, void *data)
4666{
4667 struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4668 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4669 struct ath11k_hal_reg_capabilities_ext reg_cap;
4670 int ret;
4671 u32 i;
4672
4673 svc_rdy_ext->n_ext_hal_reg_caps = 0;
4674 svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
4675 ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4676 ath11k_wmi_tlv_ext_hal_reg_caps_parse,
4677 svc_rdy_ext);
4678 if (ret) {
4679 ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4680 return ret;
4681 }
4682
4683 for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
4684 ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
4685 svc_rdy_ext->soc_hal_reg_caps,
4686 svc_rdy_ext->ext_hal_reg_caps, i,
4687 ®_cap);
4688 if (ret) {
4689 ath11k_warn(soc, "failed to extract reg cap %d\n", i);
4690 return ret;
4691 }
4692
4693 memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
4694 ®_cap, sizeof(reg_cap));
4695 }
4696 return 0;
4697}
4698
4699static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
4700 u16 len, const void *ptr,
4701 void *data)
4702{
4703 struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4704 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4705 u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
4706 u32 phy_id_map;
4707 int pdev_index = 0;
4708 int ret;
4709
4710 svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
4711 svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
4712
4713 soc->num_radios = 0;
4714 soc->target_pdev_count = 0;
4715 phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
4716
4717 while (phy_id_map && soc->num_radios < MAX_RADIOS) {
4718 ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
4719 svc_rdy_ext->hw_caps,
4720 svc_rdy_ext->hw_mode_caps,
4721 svc_rdy_ext->soc_hal_reg_caps,
4722 svc_rdy_ext->mac_phy_caps,
4723 hw_mode_id, soc->num_radios,
4724 &soc->pdevs[pdev_index]);
4725 if (ret) {
4726 ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
4727 soc->num_radios);
4728 return ret;
4729 }
4730
4731 soc->num_radios++;
4732
4733 /* For QCA6390, save mac_phy capability in the same pdev */
4734 if (soc->hw_params.single_pdev_only)
4735 pdev_index = 0;
4736 else
4737 pdev_index = soc->num_radios;
4738
4739 /* TODO: mac_phy_cap prints */
4740 phy_id_map >>= 1;
4741 }
4742
4743 /* For QCA6390, set num_radios to 1 because host manages
4744 * both 2G and 5G radio in one pdev.
4745 * Set pdev_id = 0 and 0 means soc level.
4746 */
4747 if (soc->hw_params.single_pdev_only) {
4748 soc->num_radios = 1;
4749 soc->pdevs[0].pdev_id = 0;
4750 }
4751
4752 return 0;
4753}
4754
4755static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc,
4756 u16 tag, u16 len,
4757 const void *ptr, void *data)
4758{
4759 struct wmi_tlv_dma_ring_caps_parse *parse = data;
4760
4761 if (tag != WMI_TAG_DMA_RING_CAPABILITIES)
4762 return -EPROTO;
4763
4764 parse->n_dma_ring_caps++;
4765 return 0;
4766}
4767
4768static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab,
4769 u32 num_cap)
4770{
4771 size_t sz;
4772 void *ptr;
4773
4774 sz = num_cap * sizeof(struct ath11k_dbring_cap);
4775 ptr = kzalloc(sz, GFP_ATOMIC);
4776 if (!ptr)
4777 return -ENOMEM;
4778
4779 ab->db_caps = ptr;
4780 ab->num_db_cap = num_cap;
4781
4782 return 0;
4783}
4784
4785static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
4786{
4787 kfree(ab->db_caps);
4788 ab->db_caps = NULL;
4789}
4790
4791static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab,
4792 u16 len, const void *ptr, void *data)
4793{
4794 struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data;
4795 struct wmi_dma_ring_capabilities *dma_caps;
4796 struct ath11k_dbring_cap *dir_buff_caps;
4797 int ret;
4798 u32 i;
4799
4800 dma_caps_parse->n_dma_ring_caps = 0;
4801 dma_caps = (struct wmi_dma_ring_capabilities *)ptr;
4802 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4803 ath11k_wmi_tlv_dma_ring_caps_parse,
4804 dma_caps_parse);
4805 if (ret) {
4806 ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret);
4807 return ret;
4808 }
4809
4810 if (!dma_caps_parse->n_dma_ring_caps)
4811 return 0;
4812
4813 if (ab->num_db_cap) {
4814 ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n");
4815 return 0;
4816 }
4817
4818 ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps);
4819 if (ret)
4820 return ret;
4821
4822 dir_buff_caps = ab->db_caps;
4823 for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) {
4824 if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) {
4825 ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id);
4826 ret = -EINVAL;
4827 goto free_dir_buff;
4828 }
4829
4830 dir_buff_caps[i].id = dma_caps[i].module_id;
4831 dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id);
4832 dir_buff_caps[i].min_elem = dma_caps[i].min_elem;
4833 dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz;
4834 dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align;
4835 }
4836
4837 return 0;
4838
4839free_dir_buff:
4840 ath11k_wmi_free_dbring_caps(ab);
4841 return ret;
4842}
4843
4844static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
4845 u16 tag, u16 len,
4846 const void *ptr, void *data)
4847{
4848 struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
4849 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4850 int ret;
4851
4852 switch (tag) {
4853 case WMI_TAG_SERVICE_READY_EXT_EVENT:
4854 ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
4855 &svc_rdy_ext->param);
4856 if (ret) {
4857 ath11k_warn(ab, "unable to extract ext params\n");
4858 return ret;
4859 }
4860 break;
4861
4862 case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
4863 svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
4864 svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
4865 break;
4866
4867 case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
4868 ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
4869 svc_rdy_ext);
4870 if (ret)
4871 return ret;
4872 break;
4873
4874 case WMI_TAG_ARRAY_STRUCT:
4875 if (!svc_rdy_ext->hw_mode_done) {
4876 ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
4877 svc_rdy_ext);
4878 if (ret)
4879 return ret;
4880
4881 svc_rdy_ext->hw_mode_done = true;
4882 } else if (!svc_rdy_ext->mac_phy_done) {
4883 svc_rdy_ext->n_mac_phy_caps = 0;
4884 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4885 ath11k_wmi_tlv_mac_phy_caps_parse,
4886 svc_rdy_ext);
4887 if (ret) {
4888 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4889 return ret;
4890 }
4891
4892 svc_rdy_ext->mac_phy_done = true;
4893 } else if (!svc_rdy_ext->ext_hal_reg_done) {
4894 ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
4895 svc_rdy_ext);
4896 if (ret)
4897 return ret;
4898
4899 svc_rdy_ext->ext_hal_reg_done = true;
4900 } else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) {
4901 svc_rdy_ext->mac_phy_chainmask_combo_done = true;
4902 } else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) {
4903 svc_rdy_ext->mac_phy_chainmask_cap_done = true;
4904 } else if (!svc_rdy_ext->oem_dma_ring_cap_done) {
4905 svc_rdy_ext->oem_dma_ring_cap_done = true;
4906 } else if (!svc_rdy_ext->dma_ring_cap_done) {
4907 ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4908 &svc_rdy_ext->dma_caps_parse);
4909 if (ret)
4910 return ret;
4911
4912 svc_rdy_ext->dma_ring_cap_done = true;
4913 }
4914 break;
4915
4916 default:
4917 break;
4918 }
4919 return 0;
4920}
4921
4922static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
4923 struct sk_buff *skb)
4924{
4925 struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
4926 int ret;
4927
4928 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4929 ath11k_wmi_tlv_svc_rdy_ext_parse,
4930 &svc_rdy_ext);
4931 if (ret) {
4932 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4933 goto err;
4934 }
4935
4936 ath11k_dbg(ab, ATH11K_DBG_WMI, "event service ready ext");
4937
4938 if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map))
4939 complete(&ab->wmi_ab.service_ready);
4940
4941 kfree(svc_rdy_ext.mac_phy_caps);
4942 return 0;
4943
4944err:
4945 ath11k_wmi_free_dbring_caps(ab);
4946 return ret;
4947}
4948
4949static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab,
4950 u16 tag, u16 len,
4951 const void *ptr, void *data)
4952{
4953 struct wmi_tlv_svc_rdy_ext2_parse *parse = data;
4954 int ret;
4955
4956 switch (tag) {
4957 case WMI_TAG_ARRAY_STRUCT:
4958 if (!parse->dma_ring_cap_done) {
4959 ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4960 &parse->dma_caps_parse);
4961 if (ret)
4962 return ret;
4963
4964 parse->dma_ring_cap_done = true;
4965 }
4966 break;
4967 default:
4968 break;
4969 }
4970
4971 return 0;
4972}
4973
4974static int ath11k_service_ready_ext2_event(struct ath11k_base *ab,
4975 struct sk_buff *skb)
4976{
4977 struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { };
4978 int ret;
4979
4980 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4981 ath11k_wmi_tlv_svc_rdy_ext2_parse,
4982 &svc_rdy_ext2);
4983 if (ret) {
4984 ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret);
4985 goto err;
4986 }
4987
4988 ath11k_dbg(ab, ATH11K_DBG_WMI, "event service ready ext2");
4989
4990 complete(&ab->wmi_ab.service_ready);
4991
4992 return 0;
4993
4994err:
4995 ath11k_wmi_free_dbring_caps(ab);
4996 return ret;
4997}
4998
4999static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5000 struct wmi_vdev_start_resp_event *vdev_rsp)
5001{
5002 const void **tb;
5003 const struct wmi_vdev_start_resp_event *ev;
5004 int ret;
5005
5006 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5007 if (IS_ERR(tb)) {
5008 ret = PTR_ERR(tb);
5009 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5010 return ret;
5011 }
5012
5013 ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
5014 if (!ev) {
5015 ath11k_warn(ab, "failed to fetch vdev start resp ev");
5016 kfree(tb);
5017 return -EPROTO;
5018 }
5019
5020 memset(vdev_rsp, 0, sizeof(*vdev_rsp));
5021
5022 vdev_rsp->vdev_id = ev->vdev_id;
5023 vdev_rsp->requestor_id = ev->requestor_id;
5024 vdev_rsp->resp_type = ev->resp_type;
5025 vdev_rsp->status = ev->status;
5026 vdev_rsp->chain_mask = ev->chain_mask;
5027 vdev_rsp->smps_mode = ev->smps_mode;
5028 vdev_rsp->mac_id = ev->mac_id;
5029 vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
5030 vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
5031
5032 kfree(tb);
5033 return 0;
5034}
5035
5036static void ath11k_print_reg_rule(struct ath11k_base *ab, const char *band,
5037 u32 num_reg_rules,
5038 struct cur_reg_rule *reg_rule_ptr)
5039{
5040 struct cur_reg_rule *reg_rule = reg_rule_ptr;
5041 u32 count;
5042
5043 ath11k_dbg(ab, ATH11K_DBG_WMI, "number of reg rules in %s band: %d\n",
5044 band, num_reg_rules);
5045
5046 for (count = 0; count < num_reg_rules; count++) {
5047 ath11k_dbg(ab, ATH11K_DBG_WMI,
5048 "reg rule %d: (%d - %d @ %d) (%d, %d) (FLAGS %d)\n",
5049 count + 1, reg_rule->start_freq, reg_rule->end_freq,
5050 reg_rule->max_bw, reg_rule->ant_gain,
5051 reg_rule->reg_power, reg_rule->flags);
5052 reg_rule++;
5053 }
5054}
5055
5056static struct cur_reg_rule
5057*create_reg_rules_from_wmi(u32 num_reg_rules,
5058 struct wmi_regulatory_rule_struct *wmi_reg_rule)
5059{
5060 struct cur_reg_rule *reg_rule_ptr;
5061 u32 count;
5062
5063 reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr),
5064 GFP_ATOMIC);
5065
5066 if (!reg_rule_ptr)
5067 return NULL;
5068
5069 for (count = 0; count < num_reg_rules; count++) {
5070 reg_rule_ptr[count].start_freq =
5071 FIELD_GET(REG_RULE_START_FREQ,
5072 wmi_reg_rule[count].freq_info);
5073 reg_rule_ptr[count].end_freq =
5074 FIELD_GET(REG_RULE_END_FREQ,
5075 wmi_reg_rule[count].freq_info);
5076 reg_rule_ptr[count].max_bw =
5077 FIELD_GET(REG_RULE_MAX_BW,
5078 wmi_reg_rule[count].bw_pwr_info);
5079 reg_rule_ptr[count].reg_power =
5080 FIELD_GET(REG_RULE_REG_PWR,
5081 wmi_reg_rule[count].bw_pwr_info);
5082 reg_rule_ptr[count].ant_gain =
5083 FIELD_GET(REG_RULE_ANT_GAIN,
5084 wmi_reg_rule[count].bw_pwr_info);
5085 reg_rule_ptr[count].flags =
5086 FIELD_GET(REG_RULE_FLAGS,
5087 wmi_reg_rule[count].flag_info);
5088 }
5089
5090 return reg_rule_ptr;
5091}
5092
5093static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
5094 struct sk_buff *skb,
5095 struct cur_regulatory_info *reg_info)
5096{
5097 const void **tb;
5098 const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
5099 struct wmi_regulatory_rule_struct *wmi_reg_rule;
5100 u32 num_2ghz_reg_rules, num_5ghz_reg_rules;
5101 int ret;
5102
5103 ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
5104
5105 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5106 if (IS_ERR(tb)) {
5107 ret = PTR_ERR(tb);
5108 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5109 return ret;
5110 }
5111
5112 chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
5113 if (!chan_list_event_hdr) {
5114 ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
5115 kfree(tb);
5116 return -EPROTO;
5117 }
5118
5119 reg_info->num_2ghz_reg_rules = chan_list_event_hdr->num_2ghz_reg_rules;
5120 reg_info->num_5ghz_reg_rules = chan_list_event_hdr->num_5ghz_reg_rules;
5121
5122 if (!(reg_info->num_2ghz_reg_rules + reg_info->num_5ghz_reg_rules)) {
5123 ath11k_warn(ab, "No regulatory rules available in the event info\n");
5124 kfree(tb);
5125 return -EINVAL;
5126 }
5127
5128 memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
5129 REG_ALPHA2_LEN);
5130 reg_info->dfs_region = chan_list_event_hdr->dfs_region;
5131 reg_info->phybitmap = chan_list_event_hdr->phybitmap;
5132 reg_info->num_phy = chan_list_event_hdr->num_phy;
5133 reg_info->phy_id = chan_list_event_hdr->phy_id;
5134 reg_info->ctry_code = chan_list_event_hdr->country_id;
5135 reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
5136
5137 ath11k_dbg(ab, ATH11K_DBG_WMI,
5138 "status_code %s",
5139 ath11k_cc_status_to_str(reg_info->status_code));
5140
5141 reg_info->status_code =
5142 ath11k_wmi_cc_setting_code_to_reg(chan_list_event_hdr->status_code);
5143
5144 reg_info->is_ext_reg_event = false;
5145
5146 reg_info->min_bw_2ghz = chan_list_event_hdr->min_bw_2ghz;
5147 reg_info->max_bw_2ghz = chan_list_event_hdr->max_bw_2ghz;
5148 reg_info->min_bw_5ghz = chan_list_event_hdr->min_bw_5ghz;
5149 reg_info->max_bw_5ghz = chan_list_event_hdr->max_bw_5ghz;
5150
5151 num_2ghz_reg_rules = reg_info->num_2ghz_reg_rules;
5152 num_5ghz_reg_rules = reg_info->num_5ghz_reg_rules;
5153
5154 ath11k_dbg(ab, ATH11K_DBG_WMI,
5155 "cc %s dsf %d BW: min_2ghz %d max_2ghz %d min_5ghz %d max_5ghz %d",
5156 reg_info->alpha2, reg_info->dfs_region,
5157 reg_info->min_bw_2ghz, reg_info->max_bw_2ghz,
5158 reg_info->min_bw_5ghz, reg_info->max_bw_5ghz);
5159
5160 ath11k_dbg(ab, ATH11K_DBG_WMI,
5161 "num_2ghz_reg_rules %d num_5ghz_reg_rules %d",
5162 num_2ghz_reg_rules, num_5ghz_reg_rules);
5163
5164 wmi_reg_rule =
5165 (struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
5166 + sizeof(*chan_list_event_hdr)
5167 + sizeof(struct wmi_tlv));
5168
5169 if (num_2ghz_reg_rules) {
5170 reg_info->reg_rules_2ghz_ptr =
5171 create_reg_rules_from_wmi(num_2ghz_reg_rules,
5172 wmi_reg_rule);
5173 if (!reg_info->reg_rules_2ghz_ptr) {
5174 kfree(tb);
5175 ath11k_warn(ab, "Unable to Allocate memory for 2 GHz rules\n");
5176 return -ENOMEM;
5177 }
5178
5179 ath11k_print_reg_rule(ab, "2 GHz",
5180 num_2ghz_reg_rules,
5181 reg_info->reg_rules_2ghz_ptr);
5182 }
5183
5184 if (num_5ghz_reg_rules) {
5185 wmi_reg_rule += num_2ghz_reg_rules;
5186 reg_info->reg_rules_5ghz_ptr =
5187 create_reg_rules_from_wmi(num_5ghz_reg_rules,
5188 wmi_reg_rule);
5189 if (!reg_info->reg_rules_5ghz_ptr) {
5190 kfree(tb);
5191 ath11k_warn(ab, "Unable to Allocate memory for 5 GHz rules\n");
5192 return -ENOMEM;
5193 }
5194
5195 ath11k_print_reg_rule(ab, "5 GHz",
5196 num_5ghz_reg_rules,
5197 reg_info->reg_rules_5ghz_ptr);
5198 }
5199
5200 ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
5201
5202 kfree(tb);
5203 return 0;
5204}
5205
5206static struct cur_reg_rule
5207*create_ext_reg_rules_from_wmi(u32 num_reg_rules,
5208 struct wmi_regulatory_ext_rule *wmi_reg_rule)
5209{
5210 struct cur_reg_rule *reg_rule_ptr;
5211 u32 count;
5212
5213 reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr), GFP_ATOMIC);
5214
5215 if (!reg_rule_ptr)
5216 return NULL;
5217
5218 for (count = 0; count < num_reg_rules; count++) {
5219 reg_rule_ptr[count].start_freq =
5220 u32_get_bits(wmi_reg_rule[count].freq_info,
5221 REG_RULE_START_FREQ);
5222 reg_rule_ptr[count].end_freq =
5223 u32_get_bits(wmi_reg_rule[count].freq_info,
5224 REG_RULE_END_FREQ);
5225 reg_rule_ptr[count].max_bw =
5226 u32_get_bits(wmi_reg_rule[count].bw_pwr_info,
5227 REG_RULE_MAX_BW);
5228 reg_rule_ptr[count].reg_power =
5229 u32_get_bits(wmi_reg_rule[count].bw_pwr_info,
5230 REG_RULE_REG_PWR);
5231 reg_rule_ptr[count].ant_gain =
5232 u32_get_bits(wmi_reg_rule[count].bw_pwr_info,
5233 REG_RULE_ANT_GAIN);
5234 reg_rule_ptr[count].flags =
5235 u32_get_bits(wmi_reg_rule[count].flag_info,
5236 REG_RULE_FLAGS);
5237 reg_rule_ptr[count].psd_flag =
5238 u32_get_bits(wmi_reg_rule[count].psd_power_info,
5239 REG_RULE_PSD_INFO);
5240 reg_rule_ptr[count].psd_eirp =
5241 u32_get_bits(wmi_reg_rule[count].psd_power_info,
5242 REG_RULE_PSD_EIRP);
5243 }
5244
5245 return reg_rule_ptr;
5246}
5247
5248static u8
5249ath11k_invalid_5ghz_reg_ext_rules_from_wmi(u32 num_reg_rules,
5250 const struct wmi_regulatory_ext_rule *rule)
5251{
5252 u8 num_invalid_5ghz_rules = 0;
5253 u32 count, start_freq;
5254
5255 for (count = 0; count < num_reg_rules; count++) {
5256 start_freq = u32_get_bits(rule[count].freq_info,
5257 REG_RULE_START_FREQ);
5258
5259 if (start_freq >= ATH11K_MIN_6G_FREQ)
5260 num_invalid_5ghz_rules++;
5261 }
5262
5263 return num_invalid_5ghz_rules;
5264}
5265
5266static int ath11k_pull_reg_chan_list_ext_update_ev(struct ath11k_base *ab,
5267 struct sk_buff *skb,
5268 struct cur_regulatory_info *reg_info)
5269{
5270 const void **tb;
5271 const struct wmi_reg_chan_list_cc_ext_event *ev;
5272 struct wmi_regulatory_ext_rule *ext_wmi_reg_rule;
5273 u32 num_2ghz_reg_rules, num_5ghz_reg_rules;
5274 u32 num_6ghz_reg_rules_ap[WMI_REG_CURRENT_MAX_AP_TYPE];
5275 u32 num_6ghz_client[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
5276 u32 total_reg_rules = 0;
5277 int ret, i, j, num_invalid_5ghz_ext_rules = 0;
5278
5279 ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory ext channel list\n");
5280
5281 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5282 if (IS_ERR(tb)) {
5283 ret = PTR_ERR(tb);
5284 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5285 return ret;
5286 }
5287
5288 ev = tb[WMI_TAG_REG_CHAN_LIST_CC_EXT_EVENT];
5289 if (!ev) {
5290 ath11k_warn(ab, "failed to fetch reg chan list ext update ev\n");
5291 kfree(tb);
5292 return -EPROTO;
5293 }
5294
5295 reg_info->num_2ghz_reg_rules = ev->num_2ghz_reg_rules;
5296 reg_info->num_5ghz_reg_rules = ev->num_5ghz_reg_rules;
5297 reg_info->num_6ghz_rules_ap[WMI_REG_INDOOR_AP] =
5298 ev->num_6ghz_reg_rules_ap_lpi;
5299 reg_info->num_6ghz_rules_ap[WMI_REG_STANDARD_POWER_AP] =
5300 ev->num_6ghz_reg_rules_ap_sp;
5301 reg_info->num_6ghz_rules_ap[WMI_REG_VERY_LOW_POWER_AP] =
5302 ev->num_6ghz_reg_rules_ap_vlp;
5303
5304 for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5305 reg_info->num_6ghz_rules_client[WMI_REG_INDOOR_AP][i] =
5306 ev->num_6ghz_reg_rules_client_lpi[i];
5307 reg_info->num_6ghz_rules_client[WMI_REG_STANDARD_POWER_AP][i] =
5308 ev->num_6ghz_reg_rules_client_sp[i];
5309 reg_info->num_6ghz_rules_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5310 ev->num_6ghz_reg_rules_client_vlp[i];
5311 }
5312
5313 num_2ghz_reg_rules = reg_info->num_2ghz_reg_rules;
5314 num_5ghz_reg_rules = reg_info->num_5ghz_reg_rules;
5315
5316 total_reg_rules += num_2ghz_reg_rules;
5317 total_reg_rules += num_5ghz_reg_rules;
5318
5319 if ((num_2ghz_reg_rules > MAX_REG_RULES) ||
5320 (num_5ghz_reg_rules > MAX_REG_RULES)) {
5321 ath11k_warn(ab, "Num reg rules for 2.4 GHz/5 GHz exceeds max limit (num_2ghz_reg_rules: %d num_5ghz_reg_rules: %d max_rules: %d)\n",
5322 num_2ghz_reg_rules, num_5ghz_reg_rules, MAX_REG_RULES);
5323 kfree(tb);
5324 return -EINVAL;
5325 }
5326
5327 for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++) {
5328 num_6ghz_reg_rules_ap[i] = reg_info->num_6ghz_rules_ap[i];
5329
5330 if (num_6ghz_reg_rules_ap[i] > MAX_6GHZ_REG_RULES) {
5331 ath11k_warn(ab, "Num 6 GHz reg rules for AP mode(%d) exceeds max limit (num_6ghz_reg_rules_ap: %d, max_rules: %d)\n",
5332 i, num_6ghz_reg_rules_ap[i], MAX_6GHZ_REG_RULES);
5333 kfree(tb);
5334 return -EINVAL;
5335 }
5336
5337 total_reg_rules += num_6ghz_reg_rules_ap[i];
5338 }
5339
5340 for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5341 num_6ghz_client[WMI_REG_INDOOR_AP][i] =
5342 reg_info->num_6ghz_rules_client[WMI_REG_INDOOR_AP][i];
5343 total_reg_rules += num_6ghz_client[WMI_REG_INDOOR_AP][i];
5344
5345 num_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5346 reg_info->num_6ghz_rules_client[WMI_REG_STANDARD_POWER_AP][i];
5347 total_reg_rules += num_6ghz_client[WMI_REG_STANDARD_POWER_AP][i];
5348
5349 num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5350 reg_info->num_6ghz_rules_client[WMI_REG_VERY_LOW_POWER_AP][i];
5351 total_reg_rules += num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i];
5352
5353 if ((num_6ghz_client[WMI_REG_INDOOR_AP][i] > MAX_6GHZ_REG_RULES) ||
5354 (num_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] >
5355 MAX_6GHZ_REG_RULES) ||
5356 (num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] >
5357 MAX_6GHZ_REG_RULES)) {
5358 ath11k_warn(ab,
5359 "Num 6 GHz client reg rules exceeds max limit, for client(type: %d)\n",
5360 i);
5361 kfree(tb);
5362 return -EINVAL;
5363 }
5364 }
5365
5366 if (!total_reg_rules) {
5367 ath11k_warn(ab, "No reg rules available\n");
5368 kfree(tb);
5369 return -EINVAL;
5370 }
5371
5372 memcpy(reg_info->alpha2, &ev->alpha2, REG_ALPHA2_LEN);
5373
5374 reg_info->dfs_region = ev->dfs_region;
5375 reg_info->phybitmap = ev->phybitmap;
5376 reg_info->num_phy = ev->num_phy;
5377 reg_info->phy_id = ev->phy_id;
5378 reg_info->ctry_code = ev->country_id;
5379 reg_info->reg_dmn_pair = ev->domain_code;
5380
5381 ath11k_dbg(ab, ATH11K_DBG_WMI,
5382 "status_code %s",
5383 ath11k_cc_status_to_str(reg_info->status_code));
5384
5385 reg_info->status_code =
5386 ath11k_wmi_cc_setting_code_to_reg(ev->status_code);
5387
5388 reg_info->is_ext_reg_event = true;
5389
5390 reg_info->min_bw_2ghz = ev->min_bw_2ghz;
5391 reg_info->max_bw_2ghz = ev->max_bw_2ghz;
5392 reg_info->min_bw_5ghz = ev->min_bw_5ghz;
5393 reg_info->max_bw_5ghz = ev->max_bw_5ghz;
5394
5395 reg_info->min_bw_6ghz_ap[WMI_REG_INDOOR_AP] =
5396 ev->min_bw_6ghz_ap_lpi;
5397 reg_info->max_bw_6ghz_ap[WMI_REG_INDOOR_AP] =
5398 ev->max_bw_6ghz_ap_lpi;
5399 reg_info->min_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5400 ev->min_bw_6ghz_ap_sp;
5401 reg_info->max_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5402 ev->max_bw_6ghz_ap_sp;
5403 reg_info->min_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5404 ev->min_bw_6ghz_ap_vlp;
5405 reg_info->max_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5406 ev->max_bw_6ghz_ap_vlp;
5407
5408 ath11k_dbg(ab, ATH11K_DBG_WMI,
5409 "6 GHz AP BW: LPI (%d - %d), SP (%d - %d), VLP (%d - %d)\n",
5410 reg_info->min_bw_6ghz_ap[WMI_REG_INDOOR_AP],
5411 reg_info->max_bw_6ghz_ap[WMI_REG_INDOOR_AP],
5412 reg_info->min_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP],
5413 reg_info->max_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP],
5414 reg_info->min_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP],
5415 reg_info->max_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP]);
5416
5417 for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5418 reg_info->min_bw_6ghz_client[WMI_REG_INDOOR_AP][i] =
5419 ev->min_bw_6ghz_client_lpi[i];
5420 reg_info->max_bw_6ghz_client[WMI_REG_INDOOR_AP][i] =
5421 ev->max_bw_6ghz_client_lpi[i];
5422 reg_info->min_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5423 ev->min_bw_6ghz_client_sp[i];
5424 reg_info->max_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5425 ev->max_bw_6ghz_client_sp[i];
5426 reg_info->min_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5427 ev->min_bw_6ghz_client_vlp[i];
5428 reg_info->max_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5429 ev->max_bw_6ghz_client_vlp[i];
5430
5431 ath11k_dbg(ab, ATH11K_DBG_WMI,
5432 "6 GHz %s BW: LPI (%d - %d), SP (%d - %d), VLP (%d - %d)\n",
5433 ath11k_6ghz_client_type_to_str(i),
5434 reg_info->min_bw_6ghz_client[WMI_REG_INDOOR_AP][i],
5435 reg_info->max_bw_6ghz_client[WMI_REG_INDOOR_AP][i],
5436 reg_info->min_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i],
5437 reg_info->max_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i],
5438 reg_info->min_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i],
5439 reg_info->max_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i]);
5440 }
5441
5442 ath11k_dbg(ab, ATH11K_DBG_WMI,
5443 "cc_ext %s dfs %d BW: min_2ghz %d max_2ghz %d min_5ghz %d max_5ghz %d phy_bitmap 0x%x",
5444 reg_info->alpha2, reg_info->dfs_region,
5445 reg_info->min_bw_2ghz, reg_info->max_bw_2ghz,
5446 reg_info->min_bw_5ghz, reg_info->max_bw_5ghz,
5447 reg_info->phybitmap);
5448
5449 ath11k_dbg(ab, ATH11K_DBG_WMI,
5450 "num_2ghz_reg_rules %d num_5ghz_reg_rules %d",
5451 num_2ghz_reg_rules, num_5ghz_reg_rules);
5452
5453 ath11k_dbg(ab, ATH11K_DBG_WMI,
5454 "num_6ghz_reg_rules_ap_lpi: %d num_6ghz_reg_rules_ap_sp: %d num_6ghz_reg_rules_ap_vlp: %d",
5455 num_6ghz_reg_rules_ap[WMI_REG_INDOOR_AP],
5456 num_6ghz_reg_rules_ap[WMI_REG_STANDARD_POWER_AP],
5457 num_6ghz_reg_rules_ap[WMI_REG_VERY_LOW_POWER_AP]);
5458
5459 j = WMI_REG_DEFAULT_CLIENT;
5460 ath11k_dbg(ab, ATH11K_DBG_WMI,
5461 "6 GHz Regular client: num_6ghz_reg_rules_lpi: %d num_6ghz_reg_rules_sp: %d num_6ghz_reg_rules_vlp: %d",
5462 num_6ghz_client[WMI_REG_INDOOR_AP][j],
5463 num_6ghz_client[WMI_REG_STANDARD_POWER_AP][j],
5464 num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][j]);
5465
5466 j = WMI_REG_SUBORDINATE_CLIENT;
5467 ath11k_dbg(ab, ATH11K_DBG_WMI,
5468 "6 GHz Subordinate client: num_6ghz_reg_rules_lpi: %d num_6ghz_reg_rules_sp: %d num_6ghz_reg_rules_vlp: %d",
5469 num_6ghz_client[WMI_REG_INDOOR_AP][j],
5470 num_6ghz_client[WMI_REG_STANDARD_POWER_AP][j],
5471 num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][j]);
5472
5473 ext_wmi_reg_rule =
5474 (struct wmi_regulatory_ext_rule *)((u8 *)ev + sizeof(*ev) +
5475 sizeof(struct wmi_tlv));
5476 if (num_2ghz_reg_rules) {
5477 reg_info->reg_rules_2ghz_ptr =
5478 create_ext_reg_rules_from_wmi(num_2ghz_reg_rules,
5479 ext_wmi_reg_rule);
5480
5481 if (!reg_info->reg_rules_2ghz_ptr) {
5482 kfree(tb);
5483 ath11k_warn(ab, "Unable to Allocate memory for 2 GHz rules\n");
5484 return -ENOMEM;
5485 }
5486
5487 ath11k_print_reg_rule(ab, "2 GHz",
5488 num_2ghz_reg_rules,
5489 reg_info->reg_rules_2ghz_ptr);
5490 }
5491
5492 ext_wmi_reg_rule += num_2ghz_reg_rules;
5493
5494 /* Firmware might include 6 GHz reg rule in 5 GHz rule list
5495 * for few countries along with separate 6 GHz rule.
5496 * Having same 6 GHz reg rule in 5 GHz and 6 GHz rules list
5497 * causes intersect check to be true, and same rules will be
5498 * shown multiple times in iw cmd.
5499 * Hence, avoid parsing 6 GHz rule from 5 GHz reg rule list
5500 */
5501 num_invalid_5ghz_ext_rules =
5502 ath11k_invalid_5ghz_reg_ext_rules_from_wmi(num_5ghz_reg_rules,
5503 ext_wmi_reg_rule);
5504
5505 if (num_invalid_5ghz_ext_rules) {
5506 ath11k_dbg(ab, ATH11K_DBG_WMI,
5507 "CC: %s 5 GHz reg rules number %d from fw, %d number of invalid 5 GHz rules",
5508 reg_info->alpha2, reg_info->num_5ghz_reg_rules,
5509 num_invalid_5ghz_ext_rules);
5510
5511 num_5ghz_reg_rules = num_5ghz_reg_rules - num_invalid_5ghz_ext_rules;
5512 reg_info->num_5ghz_reg_rules = num_5ghz_reg_rules;
5513 }
5514
5515 if (num_5ghz_reg_rules) {
5516 reg_info->reg_rules_5ghz_ptr =
5517 create_ext_reg_rules_from_wmi(num_5ghz_reg_rules,
5518 ext_wmi_reg_rule);
5519
5520 if (!reg_info->reg_rules_5ghz_ptr) {
5521 kfree(tb);
5522 ath11k_warn(ab, "Unable to Allocate memory for 5 GHz rules\n");
5523 return -ENOMEM;
5524 }
5525
5526 ath11k_print_reg_rule(ab, "5 GHz",
5527 num_5ghz_reg_rules,
5528 reg_info->reg_rules_5ghz_ptr);
5529 }
5530
5531 /* We have adjusted the number of 5 GHz reg rules above. But still those
5532 * many rules needs to be adjusted in ext_wmi_reg_rule.
5533 *
5534 * NOTE: num_invalid_5ghz_ext_rules will be 0 for rest other cases.
5535 */
5536 ext_wmi_reg_rule += (num_5ghz_reg_rules + num_invalid_5ghz_ext_rules);
5537
5538 for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++) {
5539 reg_info->reg_rules_6ghz_ap_ptr[i] =
5540 create_ext_reg_rules_from_wmi(num_6ghz_reg_rules_ap[i],
5541 ext_wmi_reg_rule);
5542
5543 if (!reg_info->reg_rules_6ghz_ap_ptr[i]) {
5544 kfree(tb);
5545 ath11k_warn(ab, "Unable to Allocate memory for 6 GHz AP rules\n");
5546 return -ENOMEM;
5547 }
5548
5549 ath11k_print_reg_rule(ab, ath11k_6ghz_ap_type_to_str(i),
5550 num_6ghz_reg_rules_ap[i],
5551 reg_info->reg_rules_6ghz_ap_ptr[i]);
5552
5553 ext_wmi_reg_rule += num_6ghz_reg_rules_ap[i];
5554 }
5555
5556 for (j = 0; j < WMI_REG_CURRENT_MAX_AP_TYPE; j++) {
5557 ath11k_dbg(ab, ATH11K_DBG_WMI,
5558 "6 GHz AP type %s", ath11k_6ghz_ap_type_to_str(j));
5559
5560 for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5561 reg_info->reg_rules_6ghz_client_ptr[j][i] =
5562 create_ext_reg_rules_from_wmi(num_6ghz_client[j][i],
5563 ext_wmi_reg_rule);
5564
5565 if (!reg_info->reg_rules_6ghz_client_ptr[j][i]) {
5566 kfree(tb);
5567 ath11k_warn(ab, "Unable to Allocate memory for 6 GHz client rules\n");
5568 return -ENOMEM;
5569 }
5570
5571 ath11k_print_reg_rule(ab,
5572 ath11k_6ghz_client_type_to_str(i),
5573 num_6ghz_client[j][i],
5574 reg_info->reg_rules_6ghz_client_ptr[j][i]);
5575
5576 ext_wmi_reg_rule += num_6ghz_client[j][i];
5577 }
5578 }
5579
5580 reg_info->client_type = ev->client_type;
5581 reg_info->rnr_tpe_usable = ev->rnr_tpe_usable;
5582 reg_info->unspecified_ap_usable =
5583 ev->unspecified_ap_usable;
5584 reg_info->domain_code_6ghz_ap[WMI_REG_INDOOR_AP] =
5585 ev->domain_code_6ghz_ap_lpi;
5586 reg_info->domain_code_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5587 ev->domain_code_6ghz_ap_sp;
5588 reg_info->domain_code_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5589 ev->domain_code_6ghz_ap_vlp;
5590
5591 ath11k_dbg(ab, ATH11K_DBG_WMI,
5592 "6 GHz reg info client type %s rnr_tpe_usable %d unspecified_ap_usable %d AP sub domain: lpi %s, sp %s, vlp %s\n",
5593 ath11k_6ghz_client_type_to_str(reg_info->client_type),
5594 reg_info->rnr_tpe_usable,
5595 reg_info->unspecified_ap_usable,
5596 ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_lpi),
5597 ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_sp),
5598 ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_vlp));
5599
5600 for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5601 reg_info->domain_code_6ghz_client[WMI_REG_INDOOR_AP][i] =
5602 ev->domain_code_6ghz_client_lpi[i];
5603 reg_info->domain_code_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5604 ev->domain_code_6ghz_client_sp[i];
5605 reg_info->domain_code_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5606 ev->domain_code_6ghz_client_vlp[i];
5607
5608 ath11k_dbg(ab, ATH11K_DBG_WMI,
5609 "6 GHz client type %s client sub domain: lpi %s, sp %s, vlp %s\n",
5610 ath11k_6ghz_client_type_to_str(i),
5611 ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_lpi[i]),
5612 ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_sp[i]),
5613 ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_vlp[i])
5614 );
5615 }
5616
5617 reg_info->domain_code_6ghz_super_id = ev->domain_code_6ghz_super_id;
5618
5619 ath11k_dbg(ab, ATH11K_DBG_WMI,
5620 "6 GHz client_type %s 6 GHz super domain %s",
5621 ath11k_6ghz_client_type_to_str(reg_info->client_type),
5622 ath11k_super_reg_6ghz_to_str(reg_info->domain_code_6ghz_super_id));
5623
5624 ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory ext channel list\n");
5625
5626 kfree(tb);
5627 return 0;
5628}
5629
5630static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
5631 struct wmi_peer_delete_resp_event *peer_del_resp)
5632{
5633 const void **tb;
5634 const struct wmi_peer_delete_resp_event *ev;
5635 int ret;
5636
5637 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5638 if (IS_ERR(tb)) {
5639 ret = PTR_ERR(tb);
5640 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5641 return ret;
5642 }
5643
5644 ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
5645 if (!ev) {
5646 ath11k_warn(ab, "failed to fetch peer delete resp ev");
5647 kfree(tb);
5648 return -EPROTO;
5649 }
5650
5651 memset(peer_del_resp, 0, sizeof(*peer_del_resp));
5652
5653 peer_del_resp->vdev_id = ev->vdev_id;
5654 ether_addr_copy(peer_del_resp->peer_macaddr.addr,
5655 ev->peer_macaddr.addr);
5656
5657 kfree(tb);
5658 return 0;
5659}
5660
5661static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab,
5662 struct sk_buff *skb,
5663 u32 *vdev_id)
5664{
5665 const void **tb;
5666 const struct wmi_vdev_delete_resp_event *ev;
5667 int ret;
5668
5669 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5670 if (IS_ERR(tb)) {
5671 ret = PTR_ERR(tb);
5672 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5673 return ret;
5674 }
5675
5676 ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT];
5677 if (!ev) {
5678 ath11k_warn(ab, "failed to fetch vdev delete resp ev");
5679 kfree(tb);
5680 return -EPROTO;
5681 }
5682
5683 *vdev_id = ev->vdev_id;
5684
5685 kfree(tb);
5686 return 0;
5687}
5688
5689static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
5690 u32 len, u32 *vdev_id,
5691 u32 *tx_status)
5692{
5693 const void **tb;
5694 const struct wmi_bcn_tx_status_event *ev;
5695 int ret;
5696
5697 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5698 if (IS_ERR(tb)) {
5699 ret = PTR_ERR(tb);
5700 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5701 return ret;
5702 }
5703
5704 ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
5705 if (!ev) {
5706 ath11k_warn(ab, "failed to fetch bcn tx status ev");
5707 kfree(tb);
5708 return -EPROTO;
5709 }
5710
5711 *vdev_id = ev->vdev_id;
5712 *tx_status = ev->tx_status;
5713
5714 kfree(tb);
5715 return 0;
5716}
5717
5718static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5719 u32 *vdev_id)
5720{
5721 const void **tb;
5722 const struct wmi_vdev_stopped_event *ev;
5723 int ret;
5724
5725 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5726 if (IS_ERR(tb)) {
5727 ret = PTR_ERR(tb);
5728 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5729 return ret;
5730 }
5731
5732 ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
5733 if (!ev) {
5734 ath11k_warn(ab, "failed to fetch vdev stop ev");
5735 kfree(tb);
5736 return -EPROTO;
5737 }
5738
5739 *vdev_id = ev->vdev_id;
5740
5741 kfree(tb);
5742 return 0;
5743}
5744
5745static int ath11k_wmi_tlv_mgmt_rx_parse(struct ath11k_base *ab,
5746 u16 tag, u16 len,
5747 const void *ptr, void *data)
5748{
5749 struct wmi_tlv_mgmt_rx_parse *parse = data;
5750
5751 switch (tag) {
5752 case WMI_TAG_MGMT_RX_HDR:
5753 parse->fixed = ptr;
5754 break;
5755 case WMI_TAG_ARRAY_BYTE:
5756 if (!parse->frame_buf_done) {
5757 parse->frame_buf = ptr;
5758 parse->frame_buf_done = true;
5759 }
5760 break;
5761 }
5762 return 0;
5763}
5764
5765static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
5766 struct sk_buff *skb,
5767 struct mgmt_rx_event_params *hdr)
5768{
5769 struct wmi_tlv_mgmt_rx_parse parse = { };
5770 const struct wmi_mgmt_rx_hdr *ev;
5771 const u8 *frame;
5772 int ret;
5773
5774 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
5775 ath11k_wmi_tlv_mgmt_rx_parse,
5776 &parse);
5777 if (ret) {
5778 ath11k_warn(ab, "failed to parse mgmt rx tlv %d\n",
5779 ret);
5780 return ret;
5781 }
5782
5783 ev = parse.fixed;
5784 frame = parse.frame_buf;
5785
5786 if (!ev || !frame) {
5787 ath11k_warn(ab, "failed to fetch mgmt rx hdr");
5788 return -EPROTO;
5789 }
5790
5791 hdr->pdev_id = ev->pdev_id;
5792 hdr->chan_freq = ev->chan_freq;
5793 hdr->channel = ev->channel;
5794 hdr->snr = ev->snr;
5795 hdr->rate = ev->rate;
5796 hdr->phy_mode = ev->phy_mode;
5797 hdr->buf_len = ev->buf_len;
5798 hdr->status = ev->status;
5799 hdr->flags = ev->flags;
5800 hdr->rssi = ev->rssi;
5801 hdr->tsf_delta = ev->tsf_delta;
5802 memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
5803
5804 if (skb->len < (frame - skb->data) + hdr->buf_len) {
5805 ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
5806 return -EPROTO;
5807 }
5808
5809 /* shift the sk_buff to point to `frame` */
5810 skb_trim(skb, 0);
5811 skb_put(skb, frame - skb->data);
5812 skb_pull(skb, frame - skb->data);
5813 skb_put(skb, hdr->buf_len);
5814
5815 ath11k_ce_byte_swap(skb->data, hdr->buf_len);
5816
5817 return 0;
5818}
5819
5820static int wmi_process_mgmt_tx_comp(struct ath11k *ar,
5821 struct wmi_mgmt_tx_compl_event *tx_compl_param)
5822{
5823 struct sk_buff *msdu;
5824 struct ieee80211_tx_info *info;
5825 struct ath11k_skb_cb *skb_cb;
5826 int num_mgmt;
5827
5828 spin_lock_bh(&ar->txmgmt_idr_lock);
5829 msdu = idr_find(&ar->txmgmt_idr, tx_compl_param->desc_id);
5830
5831 if (!msdu) {
5832 ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
5833 tx_compl_param->desc_id);
5834 spin_unlock_bh(&ar->txmgmt_idr_lock);
5835 return -ENOENT;
5836 }
5837
5838 idr_remove(&ar->txmgmt_idr, tx_compl_param->desc_id);
5839 spin_unlock_bh(&ar->txmgmt_idr_lock);
5840
5841 skb_cb = ATH11K_SKB_CB(msdu);
5842 dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
5843
5844 info = IEEE80211_SKB_CB(msdu);
5845 if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) &&
5846 !tx_compl_param->status) {
5847 info->flags |= IEEE80211_TX_STAT_ACK;
5848 if (test_bit(WMI_TLV_SERVICE_TX_DATA_MGMT_ACK_RSSI,
5849 ar->ab->wmi_ab.svc_map))
5850 info->status.ack_signal = tx_compl_param->ack_rssi;
5851 }
5852
5853 ieee80211_tx_status_irqsafe(ar->hw, msdu);
5854
5855 num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5856
5857 /* WARN when we received this event without doing any mgmt tx */
5858 if (num_mgmt < 0)
5859 WARN_ON_ONCE(1);
5860
5861 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5862 "mgmt tx comp pending %d desc id %d\n",
5863 num_mgmt, tx_compl_param->desc_id);
5864
5865 if (!num_mgmt)
5866 wake_up(&ar->txmgmt_empty_waitq);
5867
5868 return 0;
5869}
5870
5871static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
5872 struct sk_buff *skb,
5873 struct wmi_mgmt_tx_compl_event *param)
5874{
5875 const void **tb;
5876 const struct wmi_mgmt_tx_compl_event *ev;
5877 int ret;
5878
5879 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5880 if (IS_ERR(tb)) {
5881 ret = PTR_ERR(tb);
5882 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5883 return ret;
5884 }
5885
5886 ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
5887 if (!ev) {
5888 ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
5889 kfree(tb);
5890 return -EPROTO;
5891 }
5892
5893 param->pdev_id = ev->pdev_id;
5894 param->desc_id = ev->desc_id;
5895 param->status = ev->status;
5896 param->ack_rssi = ev->ack_rssi;
5897
5898 kfree(tb);
5899 return 0;
5900}
5901
5902static void ath11k_wmi_event_scan_started(struct ath11k *ar)
5903{
5904 lockdep_assert_held(&ar->data_lock);
5905
5906 switch (ar->scan.state) {
5907 case ATH11K_SCAN_IDLE:
5908 case ATH11K_SCAN_RUNNING:
5909 case ATH11K_SCAN_ABORTING:
5910 ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
5911 ath11k_scan_state_str(ar->scan.state),
5912 ar->scan.state);
5913 break;
5914 case ATH11K_SCAN_STARTING:
5915 ar->scan.state = ATH11K_SCAN_RUNNING;
5916 if (ar->scan.is_roc)
5917 ieee80211_ready_on_channel(ar->hw);
5918 complete(&ar->scan.started);
5919 break;
5920 }
5921}
5922
5923static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
5924{
5925 lockdep_assert_held(&ar->data_lock);
5926
5927 switch (ar->scan.state) {
5928 case ATH11K_SCAN_IDLE:
5929 case ATH11K_SCAN_RUNNING:
5930 case ATH11K_SCAN_ABORTING:
5931 ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
5932 ath11k_scan_state_str(ar->scan.state),
5933 ar->scan.state);
5934 break;
5935 case ATH11K_SCAN_STARTING:
5936 complete(&ar->scan.started);
5937 __ath11k_mac_scan_finish(ar);
5938 break;
5939 }
5940}
5941
5942static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
5943{
5944 lockdep_assert_held(&ar->data_lock);
5945
5946 switch (ar->scan.state) {
5947 case ATH11K_SCAN_IDLE:
5948 case ATH11K_SCAN_STARTING:
5949 /* One suspected reason scan can be completed while starting is
5950 * if firmware fails to deliver all scan events to the host,
5951 * e.g. when transport pipe is full. This has been observed
5952 * with spectral scan phyerr events starving wmi transport
5953 * pipe. In such case the "scan completed" event should be (and
5954 * is) ignored by the host as it may be just firmware's scan
5955 * state machine recovering.
5956 */
5957 ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
5958 ath11k_scan_state_str(ar->scan.state),
5959 ar->scan.state);
5960 break;
5961 case ATH11K_SCAN_RUNNING:
5962 case ATH11K_SCAN_ABORTING:
5963 __ath11k_mac_scan_finish(ar);
5964 break;
5965 }
5966}
5967
5968static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
5969{
5970 lockdep_assert_held(&ar->data_lock);
5971
5972 switch (ar->scan.state) {
5973 case ATH11K_SCAN_IDLE:
5974 case ATH11K_SCAN_STARTING:
5975 ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
5976 ath11k_scan_state_str(ar->scan.state),
5977 ar->scan.state);
5978 break;
5979 case ATH11K_SCAN_RUNNING:
5980 case ATH11K_SCAN_ABORTING:
5981 ar->scan_channel = NULL;
5982 break;
5983 }
5984}
5985
5986static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
5987{
5988 lockdep_assert_held(&ar->data_lock);
5989
5990 switch (ar->scan.state) {
5991 case ATH11K_SCAN_IDLE:
5992 case ATH11K_SCAN_STARTING:
5993 ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
5994 ath11k_scan_state_str(ar->scan.state),
5995 ar->scan.state);
5996 break;
5997 case ATH11K_SCAN_RUNNING:
5998 case ATH11K_SCAN_ABORTING:
5999 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
6000 if (ar->scan.is_roc && ar->scan.roc_freq == freq)
6001 complete(&ar->scan.on_channel);
6002 break;
6003 }
6004}
6005
6006static const char *
6007ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
6008 enum wmi_scan_completion_reason reason)
6009{
6010 switch (type) {
6011 case WMI_SCAN_EVENT_STARTED:
6012 return "started";
6013 case WMI_SCAN_EVENT_COMPLETED:
6014 switch (reason) {
6015 case WMI_SCAN_REASON_COMPLETED:
6016 return "completed";
6017 case WMI_SCAN_REASON_CANCELLED:
6018 return "completed [cancelled]";
6019 case WMI_SCAN_REASON_PREEMPTED:
6020 return "completed [preempted]";
6021 case WMI_SCAN_REASON_TIMEDOUT:
6022 return "completed [timedout]";
6023 case WMI_SCAN_REASON_INTERNAL_FAILURE:
6024 return "completed [internal err]";
6025 case WMI_SCAN_REASON_MAX:
6026 break;
6027 }
6028 return "completed [unknown]";
6029 case WMI_SCAN_EVENT_BSS_CHANNEL:
6030 return "bss channel";
6031 case WMI_SCAN_EVENT_FOREIGN_CHAN:
6032 return "foreign channel";
6033 case WMI_SCAN_EVENT_DEQUEUED:
6034 return "dequeued";
6035 case WMI_SCAN_EVENT_PREEMPTED:
6036 return "preempted";
6037 case WMI_SCAN_EVENT_START_FAILED:
6038 return "start failed";
6039 case WMI_SCAN_EVENT_RESTARTED:
6040 return "restarted";
6041 case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
6042 return "foreign channel exit";
6043 default:
6044 return "unknown";
6045 }
6046}
6047
6048static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
6049 struct wmi_scan_event *scan_evt_param)
6050{
6051 const void **tb;
6052 const struct wmi_scan_event *ev;
6053 int ret;
6054
6055 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6056 if (IS_ERR(tb)) {
6057 ret = PTR_ERR(tb);
6058 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6059 return ret;
6060 }
6061
6062 ev = tb[WMI_TAG_SCAN_EVENT];
6063 if (!ev) {
6064 ath11k_warn(ab, "failed to fetch scan ev");
6065 kfree(tb);
6066 return -EPROTO;
6067 }
6068
6069 scan_evt_param->event_type = ev->event_type;
6070 scan_evt_param->reason = ev->reason;
6071 scan_evt_param->channel_freq = ev->channel_freq;
6072 scan_evt_param->scan_req_id = ev->scan_req_id;
6073 scan_evt_param->scan_id = ev->scan_id;
6074 scan_evt_param->vdev_id = ev->vdev_id;
6075 scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
6076
6077 kfree(tb);
6078 return 0;
6079}
6080
6081static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
6082 struct wmi_peer_sta_kickout_arg *arg)
6083{
6084 const void **tb;
6085 const struct wmi_peer_sta_kickout_event *ev;
6086 int ret;
6087
6088 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6089 if (IS_ERR(tb)) {
6090 ret = PTR_ERR(tb);
6091 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6092 return ret;
6093 }
6094
6095 ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
6096 if (!ev) {
6097 ath11k_warn(ab, "failed to fetch peer sta kickout ev");
6098 kfree(tb);
6099 return -EPROTO;
6100 }
6101
6102 arg->mac_addr = ev->peer_macaddr.addr;
6103
6104 kfree(tb);
6105 return 0;
6106}
6107
6108static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
6109 struct wmi_roam_event *roam_ev)
6110{
6111 const void **tb;
6112 const struct wmi_roam_event *ev;
6113 int ret;
6114
6115 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6116 if (IS_ERR(tb)) {
6117 ret = PTR_ERR(tb);
6118 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6119 return ret;
6120 }
6121
6122 ev = tb[WMI_TAG_ROAM_EVENT];
6123 if (!ev) {
6124 ath11k_warn(ab, "failed to fetch roam ev");
6125 kfree(tb);
6126 return -EPROTO;
6127 }
6128
6129 roam_ev->vdev_id = ev->vdev_id;
6130 roam_ev->reason = ev->reason;
6131 roam_ev->rssi = ev->rssi;
6132
6133 kfree(tb);
6134 return 0;
6135}
6136
6137static int freq_to_idx(struct ath11k *ar, int freq)
6138{
6139 struct ieee80211_supported_band *sband;
6140 int band, ch, idx = 0;
6141
6142 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
6143 sband = ar->hw->wiphy->bands[band];
6144 if (!sband)
6145 continue;
6146
6147 for (ch = 0; ch < sband->n_channels; ch++, idx++)
6148 if (sband->channels[ch].center_freq == freq)
6149 goto exit;
6150 }
6151
6152exit:
6153 return idx;
6154}
6155
6156static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
6157 u32 len, struct wmi_chan_info_event *ch_info_ev)
6158{
6159 const void **tb;
6160 const struct wmi_chan_info_event *ev;
6161 int ret;
6162
6163 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
6164 if (IS_ERR(tb)) {
6165 ret = PTR_ERR(tb);
6166 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6167 return ret;
6168 }
6169
6170 ev = tb[WMI_TAG_CHAN_INFO_EVENT];
6171 if (!ev) {
6172 ath11k_warn(ab, "failed to fetch chan info ev");
6173 kfree(tb);
6174 return -EPROTO;
6175 }
6176
6177 ch_info_ev->err_code = ev->err_code;
6178 ch_info_ev->freq = ev->freq;
6179 ch_info_ev->cmd_flags = ev->cmd_flags;
6180 ch_info_ev->noise_floor = ev->noise_floor;
6181 ch_info_ev->rx_clear_count = ev->rx_clear_count;
6182 ch_info_ev->cycle_count = ev->cycle_count;
6183 ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
6184 ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
6185 ch_info_ev->rx_frame_count = ev->rx_frame_count;
6186 ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
6187 ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
6188 ch_info_ev->vdev_id = ev->vdev_id;
6189
6190 kfree(tb);
6191 return 0;
6192}
6193
6194static int
6195ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
6196 struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
6197{
6198 const void **tb;
6199 const struct wmi_pdev_bss_chan_info_event *ev;
6200 int ret;
6201
6202 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6203 if (IS_ERR(tb)) {
6204 ret = PTR_ERR(tb);
6205 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6206 return ret;
6207 }
6208
6209 ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
6210 if (!ev) {
6211 ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
6212 kfree(tb);
6213 return -EPROTO;
6214 }
6215
6216 bss_ch_info_ev->pdev_id = ev->pdev_id;
6217 bss_ch_info_ev->freq = ev->freq;
6218 bss_ch_info_ev->noise_floor = ev->noise_floor;
6219 bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
6220 bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
6221 bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
6222 bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
6223 bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
6224 bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
6225 bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
6226 bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
6227 bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
6228 bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
6229
6230 kfree(tb);
6231 return 0;
6232}
6233
6234static int
6235ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
6236 struct wmi_vdev_install_key_complete_arg *arg)
6237{
6238 const void **tb;
6239 const struct wmi_vdev_install_key_compl_event *ev;
6240 int ret;
6241
6242 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6243 if (IS_ERR(tb)) {
6244 ret = PTR_ERR(tb);
6245 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6246 return ret;
6247 }
6248
6249 ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
6250 if (!ev) {
6251 ath11k_warn(ab, "failed to fetch vdev install key compl ev");
6252 kfree(tb);
6253 return -EPROTO;
6254 }
6255
6256 arg->vdev_id = ev->vdev_id;
6257 arg->macaddr = ev->peer_macaddr.addr;
6258 arg->key_idx = ev->key_idx;
6259 arg->key_flags = ev->key_flags;
6260 arg->status = ev->status;
6261
6262 kfree(tb);
6263 return 0;
6264}
6265
6266static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
6267 struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
6268{
6269 const void **tb;
6270 const struct wmi_peer_assoc_conf_event *ev;
6271 int ret;
6272
6273 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6274 if (IS_ERR(tb)) {
6275 ret = PTR_ERR(tb);
6276 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6277 return ret;
6278 }
6279
6280 ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
6281 if (!ev) {
6282 ath11k_warn(ab, "failed to fetch peer assoc conf ev");
6283 kfree(tb);
6284 return -EPROTO;
6285 }
6286
6287 peer_assoc_conf->vdev_id = ev->vdev_id;
6288 peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
6289
6290 kfree(tb);
6291 return 0;
6292}
6293
6294static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
6295 struct ath11k_fw_stats_pdev *dst)
6296{
6297 dst->ch_noise_floor = src->chan_nf;
6298 dst->tx_frame_count = src->tx_frame_count;
6299 dst->rx_frame_count = src->rx_frame_count;
6300 dst->rx_clear_count = src->rx_clear_count;
6301 dst->cycle_count = src->cycle_count;
6302 dst->phy_err_count = src->phy_err_count;
6303 dst->chan_tx_power = src->chan_tx_pwr;
6304}
6305
6306static void
6307ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
6308 struct ath11k_fw_stats_pdev *dst)
6309{
6310 dst->comp_queued = src->comp_queued;
6311 dst->comp_delivered = src->comp_delivered;
6312 dst->msdu_enqued = src->msdu_enqued;
6313 dst->mpdu_enqued = src->mpdu_enqued;
6314 dst->wmm_drop = src->wmm_drop;
6315 dst->local_enqued = src->local_enqued;
6316 dst->local_freed = src->local_freed;
6317 dst->hw_queued = src->hw_queued;
6318 dst->hw_reaped = src->hw_reaped;
6319 dst->underrun = src->underrun;
6320 dst->hw_paused = src->hw_paused;
6321 dst->tx_abort = src->tx_abort;
6322 dst->mpdus_requeued = src->mpdus_requeued;
6323 dst->tx_ko = src->tx_ko;
6324 dst->tx_xretry = src->tx_xretry;
6325 dst->data_rc = src->data_rc;
6326 dst->self_triggers = src->self_triggers;
6327 dst->sw_retry_failure = src->sw_retry_failure;
6328 dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
6329 dst->pdev_cont_xretry = src->pdev_cont_xretry;
6330 dst->pdev_tx_timeout = src->pdev_tx_timeout;
6331 dst->pdev_resets = src->pdev_resets;
6332 dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
6333 dst->phy_underrun = src->phy_underrun;
6334 dst->txop_ovf = src->txop_ovf;
6335 dst->seq_posted = src->seq_posted;
6336 dst->seq_failed_queueing = src->seq_failed_queueing;
6337 dst->seq_completed = src->seq_completed;
6338 dst->seq_restarted = src->seq_restarted;
6339 dst->mu_seq_posted = src->mu_seq_posted;
6340 dst->mpdus_sw_flush = src->mpdus_sw_flush;
6341 dst->mpdus_hw_filter = src->mpdus_hw_filter;
6342 dst->mpdus_truncated = src->mpdus_truncated;
6343 dst->mpdus_ack_failed = src->mpdus_ack_failed;
6344 dst->mpdus_expired = src->mpdus_expired;
6345}
6346
6347static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
6348 struct ath11k_fw_stats_pdev *dst)
6349{
6350 dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
6351 dst->status_rcvd = src->status_rcvd;
6352 dst->r0_frags = src->r0_frags;
6353 dst->r1_frags = src->r1_frags;
6354 dst->r2_frags = src->r2_frags;
6355 dst->r3_frags = src->r3_frags;
6356 dst->htt_msdus = src->htt_msdus;
6357 dst->htt_mpdus = src->htt_mpdus;
6358 dst->loc_msdus = src->loc_msdus;
6359 dst->loc_mpdus = src->loc_mpdus;
6360 dst->oversize_amsdu = src->oversize_amsdu;
6361 dst->phy_errs = src->phy_errs;
6362 dst->phy_err_drop = src->phy_err_drop;
6363 dst->mpdu_errs = src->mpdu_errs;
6364 dst->rx_ovfl_errs = src->rx_ovfl_errs;
6365}
6366
6367static void
6368ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
6369 struct ath11k_fw_stats_vdev *dst)
6370{
6371 int i;
6372
6373 dst->vdev_id = src->vdev_id;
6374 dst->beacon_snr = src->beacon_snr;
6375 dst->data_snr = src->data_snr;
6376 dst->num_rx_frames = src->num_rx_frames;
6377 dst->num_rts_fail = src->num_rts_fail;
6378 dst->num_rts_success = src->num_rts_success;
6379 dst->num_rx_err = src->num_rx_err;
6380 dst->num_rx_discard = src->num_rx_discard;
6381 dst->num_tx_not_acked = src->num_tx_not_acked;
6382
6383 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
6384 dst->num_tx_frames[i] = src->num_tx_frames[i];
6385
6386 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
6387 dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
6388
6389 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
6390 dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
6391
6392 for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
6393 dst->tx_rate_history[i] = src->tx_rate_history[i];
6394
6395 for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
6396 dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
6397}
6398
6399static void
6400ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
6401 struct ath11k_fw_stats_bcn *dst)
6402{
6403 dst->vdev_id = src->vdev_id;
6404 dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
6405 dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
6406}
6407
6408static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
6409 u16 tag, u16 len,
6410 const void *ptr, void *data)
6411{
6412 struct wmi_tlv_fw_stats_parse *parse = data;
6413 const struct wmi_stats_event *ev = parse->ev;
6414 struct ath11k_fw_stats *stats = parse->stats;
6415 struct ath11k *ar;
6416 struct ath11k_vif *arvif;
6417 struct ieee80211_sta *sta;
6418 struct ath11k_sta *arsta;
6419 const struct wmi_rssi_stats *stats_rssi = (const struct wmi_rssi_stats *)ptr;
6420 int j, ret = 0;
6421
6422 if (tag != WMI_TAG_RSSI_STATS)
6423 return -EPROTO;
6424
6425 rcu_read_lock();
6426
6427 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6428 stats->stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
6429
6430 ath11k_dbg(ab, ATH11K_DBG_WMI,
6431 "stats vdev id %d mac %pM\n",
6432 stats_rssi->vdev_id, stats_rssi->peer_macaddr.addr);
6433
6434 arvif = ath11k_mac_get_arvif(ar, stats_rssi->vdev_id);
6435 if (!arvif) {
6436 ath11k_warn(ab, "not found vif for vdev id %d\n",
6437 stats_rssi->vdev_id);
6438 ret = -EPROTO;
6439 goto exit;
6440 }
6441
6442 ath11k_dbg(ab, ATH11K_DBG_WMI,
6443 "stats bssid %pM vif %p\n",
6444 arvif->bssid, arvif->vif);
6445
6446 sta = ieee80211_find_sta_by_ifaddr(ar->hw,
6447 arvif->bssid,
6448 NULL);
6449 if (!sta) {
6450 ath11k_dbg(ab, ATH11K_DBG_WMI,
6451 "not found station of bssid %pM for rssi chain\n",
6452 arvif->bssid);
6453 goto exit;
6454 }
6455
6456 arsta = ath11k_sta_to_arsta(sta);
6457
6458 BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
6459 ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
6460
6461 for (j = 0; j < ARRAY_SIZE(arsta->chain_signal); j++) {
6462 arsta->chain_signal[j] = stats_rssi->rssi_avg_beacon[j];
6463 ath11k_dbg(ab, ATH11K_DBG_WMI,
6464 "stats beacon rssi[%d] %d data rssi[%d] %d\n",
6465 j,
6466 stats_rssi->rssi_avg_beacon[j],
6467 j,
6468 stats_rssi->rssi_avg_data[j]);
6469 }
6470
6471exit:
6472 rcu_read_unlock();
6473 return ret;
6474}
6475
6476static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
6477 struct wmi_tlv_fw_stats_parse *parse,
6478 const void *ptr,
6479 u16 len)
6480{
6481 struct ath11k_fw_stats *stats = parse->stats;
6482 const struct wmi_stats_event *ev = parse->ev;
6483 struct ath11k *ar;
6484 struct ath11k_vif *arvif;
6485 struct ieee80211_sta *sta;
6486 struct ath11k_sta *arsta;
6487 int i, ret = 0;
6488 const void *data = ptr;
6489
6490 if (!ev) {
6491 ath11k_warn(ab, "failed to fetch update stats ev");
6492 return -EPROTO;
6493 }
6494
6495 stats->stats_id = 0;
6496
6497 rcu_read_lock();
6498
6499 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6500
6501 for (i = 0; i < ev->num_pdev_stats; i++) {
6502 const struct wmi_pdev_stats *src;
6503 struct ath11k_fw_stats_pdev *dst;
6504
6505 src = data;
6506 if (len < sizeof(*src)) {
6507 ret = -EPROTO;
6508 goto exit;
6509 }
6510
6511 stats->stats_id = WMI_REQUEST_PDEV_STAT;
6512
6513 data += sizeof(*src);
6514 len -= sizeof(*src);
6515
6516 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6517 if (!dst)
6518 continue;
6519
6520 ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
6521 ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
6522 ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
6523 list_add_tail(&dst->list, &stats->pdevs);
6524 }
6525
6526 for (i = 0; i < ev->num_vdev_stats; i++) {
6527 const struct wmi_vdev_stats *src;
6528 struct ath11k_fw_stats_vdev *dst;
6529
6530 src = data;
6531 if (len < sizeof(*src)) {
6532 ret = -EPROTO;
6533 goto exit;
6534 }
6535
6536 stats->stats_id = WMI_REQUEST_VDEV_STAT;
6537
6538 arvif = ath11k_mac_get_arvif(ar, src->vdev_id);
6539 if (arvif) {
6540 sta = ieee80211_find_sta_by_ifaddr(ar->hw,
6541 arvif->bssid,
6542 NULL);
6543 if (sta) {
6544 arsta = ath11k_sta_to_arsta(sta);
6545 arsta->rssi_beacon = src->beacon_snr;
6546 ath11k_dbg(ab, ATH11K_DBG_WMI,
6547 "stats vdev id %d snr %d\n",
6548 src->vdev_id, src->beacon_snr);
6549 } else {
6550 ath11k_dbg(ab, ATH11K_DBG_WMI,
6551 "not found station of bssid %pM for vdev stat\n",
6552 arvif->bssid);
6553 }
6554 }
6555
6556 data += sizeof(*src);
6557 len -= sizeof(*src);
6558
6559 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6560 if (!dst)
6561 continue;
6562
6563 ath11k_wmi_pull_vdev_stats(src, dst);
6564 list_add_tail(&dst->list, &stats->vdevs);
6565 }
6566
6567 for (i = 0; i < ev->num_bcn_stats; i++) {
6568 const struct wmi_bcn_stats *src;
6569 struct ath11k_fw_stats_bcn *dst;
6570
6571 src = data;
6572 if (len < sizeof(*src)) {
6573 ret = -EPROTO;
6574 goto exit;
6575 }
6576
6577 stats->stats_id = WMI_REQUEST_BCN_STAT;
6578
6579 data += sizeof(*src);
6580 len -= sizeof(*src);
6581
6582 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6583 if (!dst)
6584 continue;
6585
6586 ath11k_wmi_pull_bcn_stats(src, dst);
6587 list_add_tail(&dst->list, &stats->bcn);
6588 }
6589
6590exit:
6591 rcu_read_unlock();
6592 return ret;
6593}
6594
6595static int ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base *ab,
6596 u16 tag, u16 len,
6597 const void *ptr, void *data)
6598{
6599 struct wmi_tlv_fw_stats_parse *parse = data;
6600 int ret = 0;
6601
6602 switch (tag) {
6603 case WMI_TAG_STATS_EVENT:
6604 parse->ev = (struct wmi_stats_event *)ptr;
6605 parse->stats->pdev_id = parse->ev->pdev_id;
6606 break;
6607 case WMI_TAG_ARRAY_BYTE:
6608 ret = ath11k_wmi_tlv_fw_stats_data_parse(ab, parse, ptr, len);
6609 break;
6610 case WMI_TAG_PER_CHAIN_RSSI_STATS:
6611 parse->rssi = (struct wmi_per_chain_rssi_stats *)ptr;
6612
6613 if (parse->ev->stats_id & WMI_REQUEST_RSSI_PER_CHAIN_STAT)
6614 parse->rssi_num = parse->rssi->num_per_chain_rssi_stats;
6615
6616 ath11k_dbg(ab, ATH11K_DBG_WMI,
6617 "stats id 0x%x num chain %d\n",
6618 parse->ev->stats_id,
6619 parse->rssi_num);
6620 break;
6621 case WMI_TAG_ARRAY_STRUCT:
6622 if (parse->rssi_num && !parse->chain_rssi_done) {
6623 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
6624 ath11k_wmi_tlv_rssi_chain_parse,
6625 parse);
6626 if (ret) {
6627 ath11k_warn(ab, "failed to parse rssi chain %d\n",
6628 ret);
6629 return ret;
6630 }
6631 parse->chain_rssi_done = true;
6632 }
6633 break;
6634 default:
6635 break;
6636 }
6637 return ret;
6638}
6639
6640int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
6641 struct ath11k_fw_stats *stats)
6642{
6643 struct wmi_tlv_fw_stats_parse parse = { };
6644
6645 stats->stats_id = 0;
6646 parse.stats = stats;
6647
6648 return ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6649 ath11k_wmi_tlv_fw_stats_parse,
6650 &parse);
6651}
6652
6653static void
6654ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6655 char *buf, u32 *length)
6656{
6657 u32 len = *length;
6658 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6659
6660 len += scnprintf(buf + len, buf_len - len, "\n");
6661 len += scnprintf(buf + len, buf_len - len, "%30s\n",
6662 "ath11k PDEV stats");
6663 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6664 "=================");
6665
6666 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6667 "Channel noise floor", pdev->ch_noise_floor);
6668 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6669 "Channel TX power", pdev->chan_tx_power);
6670 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6671 "TX frame count", pdev->tx_frame_count);
6672 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6673 "RX frame count", pdev->rx_frame_count);
6674 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6675 "RX clear count", pdev->rx_clear_count);
6676 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6677 "Cycle count", pdev->cycle_count);
6678 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6679 "PHY error count", pdev->phy_err_count);
6680
6681 *length = len;
6682}
6683
6684static void
6685ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6686 char *buf, u32 *length)
6687{
6688 u32 len = *length;
6689 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6690
6691 len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6692 "ath11k PDEV TX stats");
6693 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6694 "====================");
6695
6696 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6697 "HTT cookies queued", pdev->comp_queued);
6698 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6699 "HTT cookies disp.", pdev->comp_delivered);
6700 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6701 "MSDU queued", pdev->msdu_enqued);
6702 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6703 "MPDU queued", pdev->mpdu_enqued);
6704 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6705 "MSDUs dropped", pdev->wmm_drop);
6706 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6707 "Local enqued", pdev->local_enqued);
6708 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6709 "Local freed", pdev->local_freed);
6710 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6711 "HW queued", pdev->hw_queued);
6712 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6713 "PPDUs reaped", pdev->hw_reaped);
6714 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6715 "Num underruns", pdev->underrun);
6716 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6717 "Num HW Paused", pdev->hw_paused);
6718 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6719 "PPDUs cleaned", pdev->tx_abort);
6720 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6721 "MPDUs requeued", pdev->mpdus_requeued);
6722 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6723 "PPDU OK", pdev->tx_ko);
6724 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6725 "Excessive retries", pdev->tx_xretry);
6726 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6727 "HW rate", pdev->data_rc);
6728 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6729 "Sched self triggers", pdev->self_triggers);
6730 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6731 "Dropped due to SW retries",
6732 pdev->sw_retry_failure);
6733 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6734 "Illegal rate phy errors",
6735 pdev->illgl_rate_phy_err);
6736 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6737 "PDEV continuous xretry", pdev->pdev_cont_xretry);
6738 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6739 "TX timeout", pdev->pdev_tx_timeout);
6740 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6741 "PDEV resets", pdev->pdev_resets);
6742 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6743 "Stateless TIDs alloc failures",
6744 pdev->stateless_tid_alloc_failure);
6745 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6746 "PHY underrun", pdev->phy_underrun);
6747 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6748 "MPDU is more than txop limit", pdev->txop_ovf);
6749 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6750 "Num sequences posted", pdev->seq_posted);
6751 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6752 "Num seq failed queueing ", pdev->seq_failed_queueing);
6753 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6754 "Num sequences completed ", pdev->seq_completed);
6755 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6756 "Num sequences restarted ", pdev->seq_restarted);
6757 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6758 "Num of MU sequences posted ", pdev->mu_seq_posted);
6759 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6760 "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush);
6761 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6762 "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter);
6763 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6764 "Num of MPDUS truncated ", pdev->mpdus_truncated);
6765 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6766 "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed);
6767 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6768 "Num of MPDUS expired ", pdev->mpdus_expired);
6769 *length = len;
6770}
6771
6772static void
6773ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6774 char *buf, u32 *length)
6775{
6776 u32 len = *length;
6777 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6778
6779 len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6780 "ath11k PDEV RX stats");
6781 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6782 "====================");
6783
6784 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6785 "Mid PPDU route change",
6786 pdev->mid_ppdu_route_change);
6787 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6788 "Tot. number of statuses", pdev->status_rcvd);
6789 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6790 "Extra frags on rings 0", pdev->r0_frags);
6791 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6792 "Extra frags on rings 1", pdev->r1_frags);
6793 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6794 "Extra frags on rings 2", pdev->r2_frags);
6795 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6796 "Extra frags on rings 3", pdev->r3_frags);
6797 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6798 "MSDUs delivered to HTT", pdev->htt_msdus);
6799 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6800 "MPDUs delivered to HTT", pdev->htt_mpdus);
6801 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6802 "MSDUs delivered to stack", pdev->loc_msdus);
6803 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6804 "MPDUs delivered to stack", pdev->loc_mpdus);
6805 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6806 "Oversized AMSUs", pdev->oversize_amsdu);
6807 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6808 "PHY errors", pdev->phy_errs);
6809 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6810 "PHY errors drops", pdev->phy_err_drop);
6811 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6812 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
6813 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6814 "Overflow errors", pdev->rx_ovfl_errs);
6815 *length = len;
6816}
6817
6818static void
6819ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
6820 const struct ath11k_fw_stats_vdev *vdev,
6821 char *buf, u32 *length)
6822{
6823 u32 len = *length;
6824 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6825 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
6826 u8 *vif_macaddr;
6827 int i;
6828
6829 /* VDEV stats has all the active VDEVs of other PDEVs as well,
6830 * ignoring those not part of requested PDEV
6831 */
6832 if (!arvif)
6833 return;
6834
6835 vif_macaddr = arvif->vif->addr;
6836
6837 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6838 "VDEV ID", vdev->vdev_id);
6839 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6840 "VDEV MAC address", vif_macaddr);
6841 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6842 "beacon snr", vdev->beacon_snr);
6843 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6844 "data snr", vdev->data_snr);
6845 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6846 "num rx frames", vdev->num_rx_frames);
6847 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6848 "num rts fail", vdev->num_rts_fail);
6849 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6850 "num rts success", vdev->num_rts_success);
6851 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6852 "num rx err", vdev->num_rx_err);
6853 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6854 "num rx discard", vdev->num_rx_discard);
6855 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6856 "num tx not acked", vdev->num_tx_not_acked);
6857
6858 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
6859 len += scnprintf(buf + len, buf_len - len,
6860 "%25s [%02d] %u\n",
6861 "num tx frames", i,
6862 vdev->num_tx_frames[i]);
6863
6864 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
6865 len += scnprintf(buf + len, buf_len - len,
6866 "%25s [%02d] %u\n",
6867 "num tx frames retries", i,
6868 vdev->num_tx_frames_retries[i]);
6869
6870 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
6871 len += scnprintf(buf + len, buf_len - len,
6872 "%25s [%02d] %u\n",
6873 "num tx frames failures", i,
6874 vdev->num_tx_frames_failures[i]);
6875
6876 for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
6877 len += scnprintf(buf + len, buf_len - len,
6878 "%25s [%02d] 0x%08x\n",
6879 "tx rate history", i,
6880 vdev->tx_rate_history[i]);
6881
6882 for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
6883 len += scnprintf(buf + len, buf_len - len,
6884 "%25s [%02d] %u\n",
6885 "beacon rssi history", i,
6886 vdev->beacon_rssi_history[i]);
6887
6888 len += scnprintf(buf + len, buf_len - len, "\n");
6889 *length = len;
6890}
6891
6892static void
6893ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
6894 const struct ath11k_fw_stats_bcn *bcn,
6895 char *buf, u32 *length)
6896{
6897 u32 len = *length;
6898 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6899 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
6900 u8 *vdev_macaddr;
6901
6902 if (!arvif) {
6903 ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
6904 bcn->vdev_id);
6905 return;
6906 }
6907
6908 vdev_macaddr = arvif->vif->addr;
6909
6910 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6911 "VDEV ID", bcn->vdev_id);
6912 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6913 "VDEV MAC address", vdev_macaddr);
6914 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6915 "================");
6916 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6917 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
6918 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6919 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
6920
6921 len += scnprintf(buf + len, buf_len - len, "\n");
6922 *length = len;
6923}
6924
6925void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
6926 struct ath11k_fw_stats *fw_stats,
6927 u32 stats_id, char *buf)
6928{
6929 u32 len = 0;
6930 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6931 const struct ath11k_fw_stats_pdev *pdev;
6932 const struct ath11k_fw_stats_vdev *vdev;
6933 const struct ath11k_fw_stats_bcn *bcn;
6934 size_t num_bcn;
6935
6936 spin_lock_bh(&ar->data_lock);
6937
6938 if (stats_id == WMI_REQUEST_PDEV_STAT) {
6939 pdev = list_first_entry_or_null(&fw_stats->pdevs,
6940 struct ath11k_fw_stats_pdev, list);
6941 if (!pdev) {
6942 ath11k_warn(ar->ab, "failed to get pdev stats\n");
6943 goto unlock;
6944 }
6945
6946 ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
6947 ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
6948 ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
6949 }
6950
6951 if (stats_id == WMI_REQUEST_VDEV_STAT) {
6952 len += scnprintf(buf + len, buf_len - len, "\n");
6953 len += scnprintf(buf + len, buf_len - len, "%30s\n",
6954 "ath11k VDEV stats");
6955 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6956 "=================");
6957
6958 list_for_each_entry(vdev, &fw_stats->vdevs, list)
6959 ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
6960 }
6961
6962 if (stats_id == WMI_REQUEST_BCN_STAT) {
6963 num_bcn = list_count_nodes(&fw_stats->bcn);
6964
6965 len += scnprintf(buf + len, buf_len - len, "\n");
6966 len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
6967 "ath11k Beacon stats", num_bcn);
6968 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6969 "===================");
6970
6971 list_for_each_entry(bcn, &fw_stats->bcn, list)
6972 ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
6973 }
6974
6975unlock:
6976 spin_unlock_bh(&ar->data_lock);
6977
6978 if (len >= buf_len)
6979 buf[len - 1] = 0;
6980 else
6981 buf[len] = 0;
6982}
6983
6984static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
6985{
6986 /* try to send pending beacons first. they take priority */
6987 wake_up(&ab->wmi_ab.tx_credits_wq);
6988}
6989
6990static int ath11k_reg_11d_new_cc_event(struct ath11k_base *ab, struct sk_buff *skb)
6991{
6992 const struct wmi_11d_new_cc_ev *ev;
6993 struct ath11k *ar;
6994 struct ath11k_pdev *pdev;
6995 const void **tb;
6996 int ret, i;
6997
6998 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6999 if (IS_ERR(tb)) {
7000 ret = PTR_ERR(tb);
7001 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7002 return ret;
7003 }
7004
7005 ev = tb[WMI_TAG_11D_NEW_COUNTRY_EVENT];
7006 if (!ev) {
7007 kfree(tb);
7008 ath11k_warn(ab, "failed to fetch 11d new cc ev");
7009 return -EPROTO;
7010 }
7011
7012 spin_lock_bh(&ab->base_lock);
7013 memcpy(&ab->new_alpha2, &ev->new_alpha2, 2);
7014 spin_unlock_bh(&ab->base_lock);
7015
7016 ath11k_dbg(ab, ATH11K_DBG_WMI, "event 11d new cc %c%c\n",
7017 ab->new_alpha2[0],
7018 ab->new_alpha2[1]);
7019
7020 kfree(tb);
7021
7022 for (i = 0; i < ab->num_radios; i++) {
7023 pdev = &ab->pdevs[i];
7024 ar = pdev->ar;
7025 ar->state_11d = ATH11K_11D_IDLE;
7026 complete(&ar->completed_11d_scan);
7027 }
7028
7029 queue_work(ab->workqueue, &ab->update_11d_work);
7030
7031 return 0;
7032}
7033
7034static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
7035 struct sk_buff *skb)
7036{
7037 struct ath11k_pdev_wmi *wmi = NULL;
7038 u32 i;
7039 u8 wmi_ep_count;
7040 u8 eid;
7041
7042 eid = ATH11K_SKB_CB(skb)->eid;
7043 dev_kfree_skb(skb);
7044
7045 if (eid >= ATH11K_HTC_EP_COUNT)
7046 return;
7047
7048 wmi_ep_count = ab->htc.wmi_ep_count;
7049 if (wmi_ep_count > ab->hw_params.max_radios)
7050 return;
7051
7052 for (i = 0; i < ab->htc.wmi_ep_count; i++) {
7053 if (ab->wmi_ab.wmi[i].eid == eid) {
7054 wmi = &ab->wmi_ab.wmi[i];
7055 break;
7056 }
7057 }
7058
7059 if (wmi)
7060 wake_up(&wmi->tx_ce_desc_wq);
7061}
7062
7063static bool ath11k_reg_is_world_alpha(char *alpha)
7064{
7065 if (alpha[0] == '0' && alpha[1] == '0')
7066 return true;
7067
7068 if (alpha[0] == 'n' && alpha[1] == 'a')
7069 return true;
7070
7071 return false;
7072}
7073
7074static int ath11k_reg_chan_list_event(struct ath11k_base *ab,
7075 struct sk_buff *skb,
7076 enum wmi_reg_chan_list_cmd_type id)
7077{
7078 struct cur_regulatory_info *reg_info = NULL;
7079 struct ieee80211_regdomain *regd = NULL;
7080 bool intersect = false;
7081 int ret = 0, pdev_idx, i, j;
7082 struct ath11k *ar;
7083
7084 reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
7085 if (!reg_info) {
7086 ret = -ENOMEM;
7087 goto fallback;
7088 }
7089
7090 if (id == WMI_REG_CHAN_LIST_CC_ID)
7091 ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
7092 else
7093 ret = ath11k_pull_reg_chan_list_ext_update_ev(ab, skb, reg_info);
7094
7095 if (ret) {
7096 ath11k_warn(ab, "failed to extract regulatory info from received event\n");
7097 goto fallback;
7098 }
7099
7100 ath11k_dbg(ab, ATH11K_DBG_WMI, "event reg chan list id %d", id);
7101
7102 if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
7103 /* In case of failure to set the requested ctry,
7104 * fw retains the current regd. We print a failure info
7105 * and return from here.
7106 */
7107 ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
7108 goto mem_free;
7109 }
7110
7111 pdev_idx = reg_info->phy_id;
7112
7113 /* Avoid default reg rule updates sent during FW recovery if
7114 * it is already available
7115 */
7116 spin_lock(&ab->base_lock);
7117 if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) &&
7118 ab->default_regd[pdev_idx]) {
7119 spin_unlock(&ab->base_lock);
7120 goto mem_free;
7121 }
7122 spin_unlock(&ab->base_lock);
7123
7124 if (pdev_idx >= ab->num_radios) {
7125 /* Process the event for phy0 only if single_pdev_only
7126 * is true. If pdev_idx is valid but not 0, discard the
7127 * event. Otherwise, it goes to fallback.
7128 */
7129 if (ab->hw_params.single_pdev_only &&
7130 pdev_idx < ab->hw_params.num_rxmda_per_pdev)
7131 goto mem_free;
7132 else
7133 goto fallback;
7134 }
7135
7136 /* Avoid multiple overwrites to default regd, during core
7137 * stop-start after mac registration.
7138 */
7139 if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
7140 !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
7141 (char *)reg_info->alpha2, 2))
7142 goto mem_free;
7143
7144 /* Intersect new rules with default regd if a new country setting was
7145 * requested, i.e a default regd was already set during initialization
7146 * and the regd coming from this event has a valid country info.
7147 */
7148 if (ab->default_regd[pdev_idx] &&
7149 !ath11k_reg_is_world_alpha((char *)
7150 ab->default_regd[pdev_idx]->alpha2) &&
7151 !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
7152 intersect = true;
7153
7154 regd = ath11k_reg_build_regd(ab, reg_info, intersect);
7155 if (!regd) {
7156 ath11k_warn(ab, "failed to build regd from reg_info\n");
7157 goto fallback;
7158 }
7159
7160 spin_lock(&ab->base_lock);
7161 if (ab->default_regd[pdev_idx]) {
7162 /* The initial rules from FW after WMI Init is to build
7163 * the default regd. From then on, any rules updated for
7164 * the pdev could be due to user reg changes.
7165 * Free previously built regd before assigning the newly
7166 * generated regd to ar. NULL pointer handling will be
7167 * taken care by kfree itself.
7168 */
7169 ar = ab->pdevs[pdev_idx].ar;
7170 kfree(ab->new_regd[pdev_idx]);
7171 ab->new_regd[pdev_idx] = regd;
7172 queue_work(ab->workqueue, &ar->regd_update_work);
7173 } else {
7174 /* This regd would be applied during mac registration and is
7175 * held constant throughout for regd intersection purpose
7176 */
7177 ab->default_regd[pdev_idx] = regd;
7178 }
7179 ab->dfs_region = reg_info->dfs_region;
7180 spin_unlock(&ab->base_lock);
7181
7182 goto mem_free;
7183
7184fallback:
7185 /* Fallback to older reg (by sending previous country setting
7186 * again if fw has succeeded and we failed to process here.
7187 * The Regdomain should be uniform across driver and fw. Since the
7188 * FW has processed the command and sent a success status, we expect
7189 * this function to succeed as well. If it doesn't, CTRY needs to be
7190 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
7191 */
7192 /* TODO: This is rare, but still should also be handled */
7193 WARN_ON(1);
7194mem_free:
7195 if (reg_info) {
7196 kfree(reg_info->reg_rules_2ghz_ptr);
7197 kfree(reg_info->reg_rules_5ghz_ptr);
7198 if (reg_info->is_ext_reg_event) {
7199 for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++)
7200 kfree(reg_info->reg_rules_6ghz_ap_ptr[i]);
7201
7202 for (j = 0; j < WMI_REG_CURRENT_MAX_AP_TYPE; j++)
7203 for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++)
7204 kfree(reg_info->reg_rules_6ghz_client_ptr[j][i]);
7205 }
7206 kfree(reg_info);
7207 }
7208 return ret;
7209}
7210
7211static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
7212 const void *ptr, void *data)
7213{
7214 struct wmi_tlv_rdy_parse *rdy_parse = data;
7215 struct wmi_ready_event fixed_param;
7216 struct wmi_mac_addr *addr_list;
7217 struct ath11k_pdev *pdev;
7218 u32 num_mac_addr;
7219 int i;
7220
7221 switch (tag) {
7222 case WMI_TAG_READY_EVENT:
7223 memset(&fixed_param, 0, sizeof(fixed_param));
7224 memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
7225 min_t(u16, sizeof(fixed_param), len));
7226 rdy_parse->num_extra_mac_addr =
7227 fixed_param.ready_event_min.num_extra_mac_addr;
7228
7229 ether_addr_copy(ab->mac_addr,
7230 fixed_param.ready_event_min.mac_addr.addr);
7231 ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum;
7232 break;
7233 case WMI_TAG_ARRAY_FIXED_STRUCT:
7234 addr_list = (struct wmi_mac_addr *)ptr;
7235 num_mac_addr = rdy_parse->num_extra_mac_addr;
7236
7237 if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
7238 break;
7239
7240 for (i = 0; i < ab->num_radios; i++) {
7241 pdev = &ab->pdevs[i];
7242 ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
7243 }
7244 ab->pdevs_macaddr_valid = true;
7245 break;
7246 default:
7247 break;
7248 }
7249
7250 return 0;
7251}
7252
7253static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
7254{
7255 struct wmi_tlv_rdy_parse rdy_parse = { };
7256 int ret;
7257
7258 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7259 ath11k_wmi_tlv_rdy_parse, &rdy_parse);
7260 if (ret) {
7261 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
7262 return ret;
7263 }
7264
7265 ath11k_dbg(ab, ATH11K_DBG_WMI, "event ready");
7266
7267 complete(&ab->wmi_ab.unified_ready);
7268 return 0;
7269}
7270
7271static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
7272{
7273 struct wmi_peer_delete_resp_event peer_del_resp;
7274 struct ath11k *ar;
7275
7276 if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
7277 ath11k_warn(ab, "failed to extract peer delete resp");
7278 return;
7279 }
7280
7281 ath11k_dbg(ab, ATH11K_DBG_WMI, "event peer delete resp");
7282
7283 rcu_read_lock();
7284 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id);
7285 if (!ar) {
7286 ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d",
7287 peer_del_resp.vdev_id);
7288 rcu_read_unlock();
7289 return;
7290 }
7291
7292 complete(&ar->peer_delete_done);
7293 rcu_read_unlock();
7294 ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n",
7295 peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr);
7296}
7297
7298static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab,
7299 struct sk_buff *skb)
7300{
7301 struct ath11k *ar;
7302 u32 vdev_id = 0;
7303
7304 if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) {
7305 ath11k_warn(ab, "failed to extract vdev delete resp");
7306 return;
7307 }
7308
7309 rcu_read_lock();
7310 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7311 if (!ar) {
7312 ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d",
7313 vdev_id);
7314 rcu_read_unlock();
7315 return;
7316 }
7317
7318 complete(&ar->vdev_delete_done);
7319
7320 rcu_read_unlock();
7321
7322 ath11k_dbg(ab, ATH11K_DBG_WMI, "event vdev delete resp for vdev id %d\n",
7323 vdev_id);
7324}
7325
7326static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
7327{
7328 switch (vdev_resp_status) {
7329 case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
7330 return "invalid vdev id";
7331 case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
7332 return "not supported";
7333 case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
7334 return "dfs violation";
7335 case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
7336 return "invalid regdomain";
7337 default:
7338 return "unknown";
7339 }
7340}
7341
7342static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
7343{
7344 struct wmi_vdev_start_resp_event vdev_start_resp;
7345 struct ath11k *ar;
7346 u32 status;
7347
7348 if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
7349 ath11k_warn(ab, "failed to extract vdev start resp");
7350 return;
7351 }
7352
7353 ath11k_dbg(ab, ATH11K_DBG_WMI, "event start resp event");
7354
7355 rcu_read_lock();
7356 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
7357 if (!ar) {
7358 ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
7359 vdev_start_resp.vdev_id);
7360 rcu_read_unlock();
7361 return;
7362 }
7363
7364 ar->last_wmi_vdev_start_status = 0;
7365
7366 status = vdev_start_resp.status;
7367
7368 if (WARN_ON_ONCE(status)) {
7369 ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
7370 status, ath11k_wmi_vdev_resp_print(status));
7371 ar->last_wmi_vdev_start_status = status;
7372 }
7373
7374 complete(&ar->vdev_setup_done);
7375
7376 rcu_read_unlock();
7377
7378 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
7379 vdev_start_resp.vdev_id);
7380}
7381
7382static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
7383{
7384 struct ath11k_vif *arvif;
7385 u32 vdev_id, tx_status;
7386
7387 if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
7388 &vdev_id, &tx_status) != 0) {
7389 ath11k_warn(ab, "failed to extract bcn tx status");
7390 return;
7391 }
7392
7393 ath11k_dbg(ab, ATH11K_DBG_WMI, "event offload bcn tx status");
7394
7395 rcu_read_lock();
7396 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_id);
7397 if (!arvif) {
7398 ath11k_warn(ab, "invalid vdev id %d in bcn_tx_status",
7399 vdev_id);
7400 rcu_read_unlock();
7401 return;
7402 }
7403 ath11k_mac_bcn_tx_event(arvif);
7404 rcu_read_unlock();
7405}
7406
7407static void ath11k_wmi_event_peer_sta_ps_state_chg(struct ath11k_base *ab,
7408 struct sk_buff *skb)
7409{
7410 const struct wmi_peer_sta_ps_state_chg_event *ev;
7411 struct ieee80211_sta *sta;
7412 struct ath11k_peer *peer;
7413 struct ath11k *ar;
7414 struct ath11k_sta *arsta;
7415 const void **tb;
7416 enum ath11k_wmi_peer_ps_state peer_previous_ps_state;
7417 int ret;
7418
7419 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7420 if (IS_ERR(tb)) {
7421 ret = PTR_ERR(tb);
7422 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7423 return;
7424 }
7425
7426 ev = tb[WMI_TAG_PEER_STA_PS_STATECHANGE_EVENT];
7427 if (!ev) {
7428 ath11k_warn(ab, "failed to fetch sta ps change ev");
7429 kfree(tb);
7430 return;
7431 }
7432
7433 ath11k_dbg(ab, ATH11K_DBG_WMI,
7434 "event peer sta ps change ev addr %pM state %u sup_bitmap %x ps_valid %u ts %u\n",
7435 ev->peer_macaddr.addr, ev->peer_ps_state,
7436 ev->ps_supported_bitmap, ev->peer_ps_valid,
7437 ev->peer_ps_timestamp);
7438
7439 rcu_read_lock();
7440
7441 spin_lock_bh(&ab->base_lock);
7442
7443 peer = ath11k_peer_find_by_addr(ab, ev->peer_macaddr.addr);
7444
7445 if (!peer) {
7446 spin_unlock_bh(&ab->base_lock);
7447 ath11k_warn(ab, "peer not found %pM\n", ev->peer_macaddr.addr);
7448 goto exit;
7449 }
7450
7451 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id);
7452
7453 if (!ar) {
7454 spin_unlock_bh(&ab->base_lock);
7455 ath11k_warn(ab, "invalid vdev id in peer sta ps state change ev %d",
7456 peer->vdev_id);
7457
7458 goto exit;
7459 }
7460
7461 sta = peer->sta;
7462
7463 spin_unlock_bh(&ab->base_lock);
7464
7465 if (!sta) {
7466 ath11k_warn(ab, "failed to find station entry %pM\n",
7467 ev->peer_macaddr.addr);
7468 goto exit;
7469 }
7470
7471 arsta = ath11k_sta_to_arsta(sta);
7472
7473 spin_lock_bh(&ar->data_lock);
7474
7475 peer_previous_ps_state = arsta->peer_ps_state;
7476 arsta->peer_ps_state = ev->peer_ps_state;
7477 arsta->peer_current_ps_valid = !!ev->peer_ps_valid;
7478
7479 if (test_bit(WMI_TLV_SERVICE_PEER_POWER_SAVE_DURATION_SUPPORT,
7480 ar->ab->wmi_ab.svc_map)) {
7481 if (!(ev->ps_supported_bitmap & WMI_PEER_PS_VALID) ||
7482 !(ev->ps_supported_bitmap & WMI_PEER_PS_STATE_TIMESTAMP) ||
7483 !ev->peer_ps_valid)
7484 goto out;
7485
7486 if (arsta->peer_ps_state == WMI_PEER_PS_STATE_ON) {
7487 arsta->ps_start_time = ev->peer_ps_timestamp;
7488 arsta->ps_start_jiffies = jiffies;
7489 } else if (arsta->peer_ps_state == WMI_PEER_PS_STATE_OFF &&
7490 peer_previous_ps_state == WMI_PEER_PS_STATE_ON) {
7491 arsta->ps_total_duration = arsta->ps_total_duration +
7492 (ev->peer_ps_timestamp - arsta->ps_start_time);
7493 }
7494
7495 if (ar->ps_timekeeper_enable)
7496 trace_ath11k_ps_timekeeper(ar, ev->peer_macaddr.addr,
7497 ev->peer_ps_timestamp,
7498 arsta->peer_ps_state);
7499 }
7500
7501out:
7502 spin_unlock_bh(&ar->data_lock);
7503exit:
7504 rcu_read_unlock();
7505 kfree(tb);
7506}
7507
7508static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
7509{
7510 struct ath11k *ar;
7511 u32 vdev_id = 0;
7512
7513 if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
7514 ath11k_warn(ab, "failed to extract vdev stopped event");
7515 return;
7516 }
7517
7518 ath11k_dbg(ab, ATH11K_DBG_WMI, "event vdev stopped");
7519
7520 rcu_read_lock();
7521 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7522 if (!ar) {
7523 ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
7524 vdev_id);
7525 rcu_read_unlock();
7526 return;
7527 }
7528
7529 complete(&ar->vdev_setup_done);
7530
7531 rcu_read_unlock();
7532
7533 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
7534}
7535
7536static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
7537{
7538 struct mgmt_rx_event_params rx_ev = {0};
7539 struct ath11k *ar;
7540 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
7541 struct ieee80211_hdr *hdr;
7542 u16 fc;
7543 struct ieee80211_supported_band *sband;
7544
7545 if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
7546 ath11k_warn(ab, "failed to extract mgmt rx event");
7547 dev_kfree_skb(skb);
7548 return;
7549 }
7550
7551 memset(status, 0, sizeof(*status));
7552
7553 ath11k_dbg(ab, ATH11K_DBG_MGMT, "event mgmt rx status %08x\n",
7554 rx_ev.status);
7555
7556 rcu_read_lock();
7557 ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
7558
7559 if (!ar) {
7560 ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
7561 rx_ev.pdev_id);
7562 dev_kfree_skb(skb);
7563 goto exit;
7564 }
7565
7566 if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
7567 (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
7568 WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
7569 dev_kfree_skb(skb);
7570 goto exit;
7571 }
7572
7573 if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
7574 status->flag |= RX_FLAG_MMIC_ERROR;
7575
7576 if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ &&
7577 rx_ev.chan_freq <= ATH11K_MAX_6G_FREQ) {
7578 status->band = NL80211_BAND_6GHZ;
7579 status->freq = rx_ev.chan_freq;
7580 } else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
7581 status->band = NL80211_BAND_2GHZ;
7582 } else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
7583 status->band = NL80211_BAND_5GHZ;
7584 } else {
7585 /* Shouldn't happen unless list of advertised channels to
7586 * mac80211 has been changed.
7587 */
7588 WARN_ON_ONCE(1);
7589 dev_kfree_skb(skb);
7590 goto exit;
7591 }
7592
7593 if (rx_ev.phy_mode == MODE_11B &&
7594 (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
7595 ath11k_dbg(ab, ATH11K_DBG_WMI,
7596 "mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
7597
7598 sband = &ar->mac.sbands[status->band];
7599
7600 if (status->band != NL80211_BAND_6GHZ)
7601 status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
7602 status->band);
7603
7604 status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
7605 status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
7606
7607 hdr = (struct ieee80211_hdr *)skb->data;
7608 fc = le16_to_cpu(hdr->frame_control);
7609
7610 /* Firmware is guaranteed to report all essential management frames via
7611 * WMI while it can deliver some extra via HTT. Since there can be
7612 * duplicates split the reporting wrt monitor/sniffing.
7613 */
7614 status->flag |= RX_FLAG_SKIP_MONITOR;
7615
7616 /* In case of PMF, FW delivers decrypted frames with Protected Bit set.
7617 * Don't clear that. Also, FW delivers broadcast management frames
7618 * (ex: group privacy action frames in mesh) as encrypted payload.
7619 */
7620 if (ieee80211_has_protected(hdr->frame_control) &&
7621 !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
7622 status->flag |= RX_FLAG_DECRYPTED;
7623
7624 if (!ieee80211_is_robust_mgmt_frame(skb)) {
7625 status->flag |= RX_FLAG_IV_STRIPPED |
7626 RX_FLAG_MMIC_STRIPPED;
7627 hdr->frame_control = __cpu_to_le16(fc &
7628 ~IEEE80211_FCTL_PROTECTED);
7629 }
7630 }
7631
7632 if (ieee80211_is_beacon(hdr->frame_control))
7633 ath11k_mac_handle_beacon(ar, skb);
7634
7635 ath11k_dbg(ab, ATH11K_DBG_MGMT,
7636 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
7637 skb, skb->len,
7638 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
7639
7640 ath11k_dbg(ab, ATH11K_DBG_MGMT,
7641 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
7642 status->freq, status->band, status->signal,
7643 status->rate_idx);
7644
7645 ieee80211_rx_ni(ar->hw, skb);
7646
7647exit:
7648 rcu_read_unlock();
7649}
7650
7651static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
7652{
7653 struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
7654 struct ath11k *ar;
7655
7656 if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
7657 ath11k_warn(ab, "failed to extract mgmt tx compl event");
7658 return;
7659 }
7660
7661 rcu_read_lock();
7662 ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
7663 if (!ar) {
7664 ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
7665 tx_compl_param.pdev_id);
7666 goto exit;
7667 }
7668
7669 wmi_process_mgmt_tx_comp(ar, &tx_compl_param);
7670
7671 ath11k_dbg(ab, ATH11K_DBG_MGMT,
7672 "event mgmt tx compl ev pdev_id %d, desc_id %d, status %d ack_rssi %d",
7673 tx_compl_param.pdev_id, tx_compl_param.desc_id,
7674 tx_compl_param.status, tx_compl_param.ack_rssi);
7675
7676exit:
7677 rcu_read_unlock();
7678}
7679
7680static struct ath11k *ath11k_get_ar_on_scan_state(struct ath11k_base *ab,
7681 u32 vdev_id,
7682 enum ath11k_scan_state state)
7683{
7684 int i;
7685 struct ath11k_pdev *pdev;
7686 struct ath11k *ar;
7687
7688 for (i = 0; i < ab->num_radios; i++) {
7689 pdev = rcu_dereference(ab->pdevs_active[i]);
7690 if (pdev && pdev->ar) {
7691 ar = pdev->ar;
7692
7693 spin_lock_bh(&ar->data_lock);
7694 if (ar->scan.state == state &&
7695 ar->scan.vdev_id == vdev_id) {
7696 spin_unlock_bh(&ar->data_lock);
7697 return ar;
7698 }
7699 spin_unlock_bh(&ar->data_lock);
7700 }
7701 }
7702 return NULL;
7703}
7704
7705static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
7706{
7707 struct ath11k *ar;
7708 struct wmi_scan_event scan_ev = {0};
7709
7710 if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
7711 ath11k_warn(ab, "failed to extract scan event");
7712 return;
7713 }
7714
7715 rcu_read_lock();
7716
7717 /* In case the scan was cancelled, ex. during interface teardown,
7718 * the interface will not be found in active interfaces.
7719 * Rather, in such scenarios, iterate over the active pdev's to
7720 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
7721 * aborting scan's vdev id matches this event info.
7722 */
7723 if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
7724 scan_ev.reason == WMI_SCAN_REASON_CANCELLED) {
7725 ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7726 ATH11K_SCAN_ABORTING);
7727 if (!ar)
7728 ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7729 ATH11K_SCAN_RUNNING);
7730 } else {
7731 ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
7732 }
7733
7734 if (!ar) {
7735 ath11k_warn(ab, "Received scan event for unknown vdev");
7736 rcu_read_unlock();
7737 return;
7738 }
7739
7740 spin_lock_bh(&ar->data_lock);
7741
7742 ath11k_dbg(ab, ATH11K_DBG_WMI,
7743 "event scan %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
7744 ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
7745 scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
7746 scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
7747 ath11k_scan_state_str(ar->scan.state), ar->scan.state);
7748
7749 switch (scan_ev.event_type) {
7750 case WMI_SCAN_EVENT_STARTED:
7751 ath11k_wmi_event_scan_started(ar);
7752 break;
7753 case WMI_SCAN_EVENT_COMPLETED:
7754 ath11k_wmi_event_scan_completed(ar);
7755 break;
7756 case WMI_SCAN_EVENT_BSS_CHANNEL:
7757 ath11k_wmi_event_scan_bss_chan(ar);
7758 break;
7759 case WMI_SCAN_EVENT_FOREIGN_CHAN:
7760 ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
7761 break;
7762 case WMI_SCAN_EVENT_START_FAILED:
7763 ath11k_warn(ab, "received scan start failure event\n");
7764 ath11k_wmi_event_scan_start_failed(ar);
7765 break;
7766 case WMI_SCAN_EVENT_DEQUEUED:
7767 __ath11k_mac_scan_finish(ar);
7768 break;
7769 case WMI_SCAN_EVENT_PREEMPTED:
7770 case WMI_SCAN_EVENT_RESTARTED:
7771 case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
7772 default:
7773 break;
7774 }
7775
7776 spin_unlock_bh(&ar->data_lock);
7777
7778 rcu_read_unlock();
7779}
7780
7781static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
7782{
7783 struct wmi_peer_sta_kickout_arg arg = {};
7784 struct ieee80211_sta *sta;
7785 struct ath11k_peer *peer;
7786 struct ath11k *ar;
7787 u32 vdev_id;
7788
7789 if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
7790 ath11k_warn(ab, "failed to extract peer sta kickout event");
7791 return;
7792 }
7793
7794 rcu_read_lock();
7795
7796 spin_lock_bh(&ab->base_lock);
7797
7798 peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
7799
7800 if (!peer) {
7801 ath11k_warn(ab, "peer not found %pM\n",
7802 arg.mac_addr);
7803 spin_unlock_bh(&ab->base_lock);
7804 goto exit;
7805 }
7806
7807 vdev_id = peer->vdev_id;
7808
7809 spin_unlock_bh(&ab->base_lock);
7810
7811 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7812 if (!ar) {
7813 ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
7814 peer->vdev_id);
7815 goto exit;
7816 }
7817
7818 sta = ieee80211_find_sta_by_ifaddr(ar->hw,
7819 arg.mac_addr, NULL);
7820 if (!sta) {
7821 ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
7822 arg.mac_addr);
7823 goto exit;
7824 }
7825
7826 ath11k_dbg(ab, ATH11K_DBG_WMI, "event peer sta kickout %pM",
7827 arg.mac_addr);
7828
7829 ieee80211_report_low_ack(sta, 10);
7830
7831exit:
7832 rcu_read_unlock();
7833}
7834
7835static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
7836{
7837 struct wmi_roam_event roam_ev = {};
7838 struct ath11k *ar;
7839
7840 if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
7841 ath11k_warn(ab, "failed to extract roam event");
7842 return;
7843 }
7844
7845 ath11k_dbg(ab, ATH11K_DBG_WMI,
7846 "event roam vdev %u reason 0x%08x rssi %d\n",
7847 roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
7848
7849 rcu_read_lock();
7850 ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
7851 if (!ar) {
7852 ath11k_warn(ab, "invalid vdev id in roam ev %d",
7853 roam_ev.vdev_id);
7854 rcu_read_unlock();
7855 return;
7856 }
7857
7858 if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
7859 ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
7860 roam_ev.reason, roam_ev.vdev_id);
7861
7862 switch (roam_ev.reason) {
7863 case WMI_ROAM_REASON_BEACON_MISS:
7864 ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id);
7865 break;
7866 case WMI_ROAM_REASON_BETTER_AP:
7867 case WMI_ROAM_REASON_LOW_RSSI:
7868 case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
7869 case WMI_ROAM_REASON_HO_FAILED:
7870 ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
7871 roam_ev.reason, roam_ev.vdev_id);
7872 break;
7873 }
7874
7875 rcu_read_unlock();
7876}
7877
7878static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7879{
7880 struct wmi_chan_info_event ch_info_ev = {0};
7881 struct ath11k *ar;
7882 struct survey_info *survey;
7883 int idx;
7884 /* HW channel counters frequency value in hertz */
7885 u32 cc_freq_hz = ab->cc_freq_hz;
7886
7887 if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
7888 ath11k_warn(ab, "failed to extract chan info event");
7889 return;
7890 }
7891
7892 ath11k_dbg(ab, ATH11K_DBG_WMI,
7893 "event chan info vdev_id %d err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d mac_clk_mhz %d\n",
7894 ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
7895 ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
7896 ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
7897 ch_info_ev.mac_clk_mhz);
7898
7899 if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
7900 ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
7901 return;
7902 }
7903
7904 rcu_read_lock();
7905 ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
7906 if (!ar) {
7907 ath11k_warn(ab, "invalid vdev id in chan info ev %d",
7908 ch_info_ev.vdev_id);
7909 rcu_read_unlock();
7910 return;
7911 }
7912 spin_lock_bh(&ar->data_lock);
7913
7914 switch (ar->scan.state) {
7915 case ATH11K_SCAN_IDLE:
7916 case ATH11K_SCAN_STARTING:
7917 ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
7918 goto exit;
7919 case ATH11K_SCAN_RUNNING:
7920 case ATH11K_SCAN_ABORTING:
7921 break;
7922 }
7923
7924 idx = freq_to_idx(ar, ch_info_ev.freq);
7925 if (idx >= ARRAY_SIZE(ar->survey)) {
7926 ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
7927 ch_info_ev.freq, idx);
7928 goto exit;
7929 }
7930
7931 /* If FW provides MAC clock frequency in Mhz, overriding the initialized
7932 * HW channel counters frequency value
7933 */
7934 if (ch_info_ev.mac_clk_mhz)
7935 cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
7936
7937 if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
7938 survey = &ar->survey[idx];
7939 memset(survey, 0, sizeof(*survey));
7940 survey->noise = ch_info_ev.noise_floor;
7941 survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
7942 SURVEY_INFO_TIME_BUSY;
7943 survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
7944 survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
7945 }
7946exit:
7947 spin_unlock_bh(&ar->data_lock);
7948 rcu_read_unlock();
7949}
7950
7951static void
7952ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7953{
7954 struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
7955 struct survey_info *survey;
7956 struct ath11k *ar;
7957 u32 cc_freq_hz = ab->cc_freq_hz;
7958 u64 busy, total, tx, rx, rx_bss;
7959 int idx;
7960
7961 if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
7962 ath11k_warn(ab, "failed to extract pdev bss chan info event");
7963 return;
7964 }
7965
7966 busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
7967 bss_ch_info_ev.rx_clear_count_low;
7968
7969 total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
7970 bss_ch_info_ev.cycle_count_low;
7971
7972 tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
7973 bss_ch_info_ev.tx_cycle_count_low;
7974
7975 rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
7976 bss_ch_info_ev.rx_cycle_count_low;
7977
7978 rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
7979 bss_ch_info_ev.rx_bss_cycle_count_low;
7980
7981 ath11k_dbg(ab, ATH11K_DBG_WMI,
7982 "event pdev bss chan info:\n pdev_id: %d freq: %d noise: %d cycle: busy %llu total %llu tx %llu rx %llu rx_bss %llu\n",
7983 bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
7984 bss_ch_info_ev.noise_floor, busy, total,
7985 tx, rx, rx_bss);
7986
7987 rcu_read_lock();
7988 ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
7989
7990 if (!ar) {
7991 ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
7992 bss_ch_info_ev.pdev_id);
7993 rcu_read_unlock();
7994 return;
7995 }
7996
7997 spin_lock_bh(&ar->data_lock);
7998 idx = freq_to_idx(ar, bss_ch_info_ev.freq);
7999 if (idx >= ARRAY_SIZE(ar->survey)) {
8000 ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
8001 bss_ch_info_ev.freq, idx);
8002 goto exit;
8003 }
8004
8005 survey = &ar->survey[idx];
8006
8007 survey->noise = bss_ch_info_ev.noise_floor;
8008 survey->time = div_u64(total, cc_freq_hz);
8009 survey->time_busy = div_u64(busy, cc_freq_hz);
8010 survey->time_rx = div_u64(rx_bss, cc_freq_hz);
8011 survey->time_tx = div_u64(tx, cc_freq_hz);
8012 survey->filled |= (SURVEY_INFO_NOISE_DBM |
8013 SURVEY_INFO_TIME |
8014 SURVEY_INFO_TIME_BUSY |
8015 SURVEY_INFO_TIME_RX |
8016 SURVEY_INFO_TIME_TX);
8017exit:
8018 spin_unlock_bh(&ar->data_lock);
8019 complete(&ar->bss_survey_done);
8020
8021 rcu_read_unlock();
8022}
8023
8024static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
8025 struct sk_buff *skb)
8026{
8027 struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
8028 struct ath11k *ar;
8029
8030 if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
8031 ath11k_warn(ab, "failed to extract install key compl event");
8032 return;
8033 }
8034
8035 ath11k_dbg(ab, ATH11K_DBG_WMI,
8036 "event vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
8037 install_key_compl.key_idx, install_key_compl.key_flags,
8038 install_key_compl.macaddr, install_key_compl.status);
8039
8040 rcu_read_lock();
8041 ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
8042 if (!ar) {
8043 ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
8044 install_key_compl.vdev_id);
8045 rcu_read_unlock();
8046 return;
8047 }
8048
8049 ar->install_key_status = 0;
8050
8051 if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
8052 ath11k_warn(ab, "install key failed for %pM status %d\n",
8053 install_key_compl.macaddr, install_key_compl.status);
8054 ar->install_key_status = install_key_compl.status;
8055 }
8056
8057 complete(&ar->install_key_done);
8058 rcu_read_unlock();
8059}
8060
8061static int ath11k_wmi_tlv_services_parser(struct ath11k_base *ab,
8062 u16 tag, u16 len,
8063 const void *ptr, void *data)
8064{
8065 const struct wmi_service_available_event *ev;
8066 u32 *wmi_ext2_service_bitmap;
8067 int i, j;
8068
8069 switch (tag) {
8070 case WMI_TAG_SERVICE_AVAILABLE_EVENT:
8071 ev = (struct wmi_service_available_event *)ptr;
8072 for (i = 0, j = WMI_MAX_SERVICE;
8073 i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
8074 i++) {
8075 do {
8076 if (ev->wmi_service_segment_bitmap[i] &
8077 BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
8078 set_bit(j, ab->wmi_ab.svc_map);
8079 } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
8080 }
8081
8082 ath11k_dbg(ab, ATH11K_DBG_WMI,
8083 "wmi_ext_service_bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
8084 ev->wmi_service_segment_bitmap[0],
8085 ev->wmi_service_segment_bitmap[1],
8086 ev->wmi_service_segment_bitmap[2],
8087 ev->wmi_service_segment_bitmap[3]);
8088 break;
8089 case WMI_TAG_ARRAY_UINT32:
8090 wmi_ext2_service_bitmap = (u32 *)ptr;
8091 for (i = 0, j = WMI_MAX_EXT_SERVICE;
8092 i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT2_SERVICE;
8093 i++) {
8094 do {
8095 if (wmi_ext2_service_bitmap[i] &
8096 BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
8097 set_bit(j, ab->wmi_ab.svc_map);
8098 } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
8099 }
8100
8101 ath11k_dbg(ab, ATH11K_DBG_WMI,
8102 "wmi_ext2_service__bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
8103 wmi_ext2_service_bitmap[0], wmi_ext2_service_bitmap[1],
8104 wmi_ext2_service_bitmap[2], wmi_ext2_service_bitmap[3]);
8105 break;
8106 }
8107 return 0;
8108}
8109
8110static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
8111{
8112 int ret;
8113
8114 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
8115 ath11k_wmi_tlv_services_parser,
8116 NULL);
8117 if (ret)
8118 ath11k_warn(ab, "failed to parse services available tlv %d\n", ret);
8119
8120 ath11k_dbg(ab, ATH11K_DBG_WMI, "event service available");
8121}
8122
8123static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
8124{
8125 struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
8126 struct ath11k *ar;
8127
8128 if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
8129 ath11k_warn(ab, "failed to extract peer assoc conf event");
8130 return;
8131 }
8132
8133 ath11k_dbg(ab, ATH11K_DBG_WMI,
8134 "event peer assoc conf ev vdev id %d macaddr %pM\n",
8135 peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
8136
8137 rcu_read_lock();
8138 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
8139
8140 if (!ar) {
8141 ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
8142 peer_assoc_conf.vdev_id);
8143 rcu_read_unlock();
8144 return;
8145 }
8146
8147 complete(&ar->peer_assoc_done);
8148 rcu_read_unlock();
8149}
8150
8151static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
8152{
8153 struct ath11k_fw_stats stats = {};
8154 struct ath11k *ar;
8155 int ret;
8156
8157 INIT_LIST_HEAD(&stats.pdevs);
8158 INIT_LIST_HEAD(&stats.vdevs);
8159 INIT_LIST_HEAD(&stats.bcn);
8160
8161 ret = ath11k_wmi_pull_fw_stats(ab, skb, &stats);
8162 if (ret) {
8163 ath11k_warn(ab, "failed to pull fw stats: %d\n", ret);
8164 goto free;
8165 }
8166
8167 ath11k_dbg(ab, ATH11K_DBG_WMI, "event update stats");
8168
8169 rcu_read_lock();
8170 ar = ath11k_mac_get_ar_by_pdev_id(ab, stats.pdev_id);
8171 if (!ar) {
8172 rcu_read_unlock();
8173 ath11k_warn(ab, "failed to get ar for pdev_id %d: %d\n",
8174 stats.pdev_id, ret);
8175 goto free;
8176 }
8177
8178 spin_lock_bh(&ar->data_lock);
8179
8180 /* WMI_REQUEST_PDEV_STAT can be requested via .get_txpower mac ops or via
8181 * debugfs fw stats. Therefore, processing it separately.
8182 */
8183 if (stats.stats_id == WMI_REQUEST_PDEV_STAT) {
8184 list_splice_tail_init(&stats.pdevs, &ar->fw_stats.pdevs);
8185 ar->fw_stats_done = true;
8186 goto complete;
8187 }
8188
8189 /* WMI_REQUEST_VDEV_STAT, WMI_REQUEST_BCN_STAT and WMI_REQUEST_RSSI_PER_CHAIN_STAT
8190 * are currently requested only via debugfs fw stats. Hence, processing these
8191 * in debugfs context
8192 */
8193 ath11k_debugfs_fw_stats_process(ar, &stats);
8194
8195complete:
8196 complete(&ar->fw_stats_complete);
8197 rcu_read_unlock();
8198 spin_unlock_bh(&ar->data_lock);
8199
8200 /* Since the stats's pdev, vdev and beacon list are spliced and reinitialised
8201 * at this point, no need to free the individual list.
8202 */
8203 return;
8204
8205free:
8206 ath11k_fw_stats_free(&stats);
8207}
8208
8209/* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
8210 * is not part of BDF CTL(Conformance test limits) table entries.
8211 */
8212static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
8213 struct sk_buff *skb)
8214{
8215 const void **tb;
8216 const struct wmi_pdev_ctl_failsafe_chk_event *ev;
8217 int ret;
8218
8219 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8220 if (IS_ERR(tb)) {
8221 ret = PTR_ERR(tb);
8222 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8223 return;
8224 }
8225
8226 ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
8227 if (!ev) {
8228 ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
8229 kfree(tb);
8230 return;
8231 }
8232
8233 ath11k_dbg(ab, ATH11K_DBG_WMI,
8234 "event pdev ctl failsafe check status %d\n",
8235 ev->ctl_failsafe_status);
8236
8237 /* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
8238 * to 10 dBm else the CTL power entry in the BDF would be picked up.
8239 */
8240 if (ev->ctl_failsafe_status != 0)
8241 ath11k_warn(ab, "pdev ctl failsafe failure status %d",
8242 ev->ctl_failsafe_status);
8243
8244 kfree(tb);
8245}
8246
8247static void
8248ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
8249 const struct wmi_pdev_csa_switch_ev *ev,
8250 const u32 *vdev_ids)
8251{
8252 int i;
8253 struct ath11k_vif *arvif;
8254
8255 /* Finish CSA once the switch count becomes NULL */
8256 if (ev->current_switch_count)
8257 return;
8258
8259 rcu_read_lock();
8260 for (i = 0; i < ev->num_vdevs; i++) {
8261 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
8262
8263 if (!arvif) {
8264 ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
8265 vdev_ids[i]);
8266 continue;
8267 }
8268
8269 if (arvif->is_up && arvif->vif->bss_conf.csa_active)
8270 ieee80211_csa_finish(arvif->vif);
8271 }
8272 rcu_read_unlock();
8273}
8274
8275static void
8276ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
8277 struct sk_buff *skb)
8278{
8279 const void **tb;
8280 const struct wmi_pdev_csa_switch_ev *ev;
8281 const u32 *vdev_ids;
8282 int ret;
8283
8284 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8285 if (IS_ERR(tb)) {
8286 ret = PTR_ERR(tb);
8287 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8288 return;
8289 }
8290
8291 ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
8292 vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
8293
8294 if (!ev || !vdev_ids) {
8295 ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
8296 kfree(tb);
8297 return;
8298 }
8299
8300 ath11k_dbg(ab, ATH11K_DBG_WMI,
8301 "event pdev csa switch count %d for pdev %d, num_vdevs %d",
8302 ev->current_switch_count, ev->pdev_id,
8303 ev->num_vdevs);
8304
8305 ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
8306
8307 kfree(tb);
8308}
8309
8310static void
8311ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
8312{
8313 const void **tb;
8314 const struct wmi_pdev_radar_ev *ev;
8315 struct ath11k *ar;
8316 int ret;
8317
8318 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8319 if (IS_ERR(tb)) {
8320 ret = PTR_ERR(tb);
8321 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8322 return;
8323 }
8324
8325 ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
8326
8327 if (!ev) {
8328 ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
8329 kfree(tb);
8330 return;
8331 }
8332
8333 ath11k_dbg(ab, ATH11K_DBG_WMI,
8334 "event pdev dfs radar detected on pdev %d, detection mode %d, chan freq %d, chan_width %d, detector id %d, seg id %d, timestamp %d, chirp %d, freq offset %d, sidx %d",
8335 ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
8336 ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
8337 ev->freq_offset, ev->sidx);
8338
8339 rcu_read_lock();
8340
8341 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
8342
8343 if (!ar) {
8344 ath11k_warn(ab, "radar detected in invalid pdev %d\n",
8345 ev->pdev_id);
8346 goto exit;
8347 }
8348
8349 ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
8350 ev->pdev_id);
8351
8352 if (ar->dfs_block_radar_events)
8353 ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
8354 else
8355 ieee80211_radar_detected(ar->hw);
8356
8357exit:
8358 rcu_read_unlock();
8359
8360 kfree(tb);
8361}
8362
8363static void
8364ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
8365 struct sk_buff *skb)
8366{
8367 struct ath11k *ar;
8368 const void **tb;
8369 const struct wmi_pdev_temperature_event *ev;
8370 int ret;
8371
8372 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8373 if (IS_ERR(tb)) {
8374 ret = PTR_ERR(tb);
8375 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8376 return;
8377 }
8378
8379 ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
8380 if (!ev) {
8381 ath11k_warn(ab, "failed to fetch pdev temp ev");
8382 kfree(tb);
8383 return;
8384 }
8385
8386 ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev temperature ev temp %d pdev_id %d\n",
8387 ev->temp, ev->pdev_id);
8388
8389 rcu_read_lock();
8390
8391 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
8392 if (!ar) {
8393 ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
8394 goto exit;
8395 }
8396
8397 ath11k_thermal_event_temperature(ar, ev->temp);
8398
8399exit:
8400 rcu_read_unlock();
8401
8402 kfree(tb);
8403}
8404
8405static void ath11k_fils_discovery_event(struct ath11k_base *ab,
8406 struct sk_buff *skb)
8407{
8408 const void **tb;
8409 const struct wmi_fils_discovery_event *ev;
8410 int ret;
8411
8412 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8413 if (IS_ERR(tb)) {
8414 ret = PTR_ERR(tb);
8415 ath11k_warn(ab,
8416 "failed to parse FILS discovery event tlv %d\n",
8417 ret);
8418 return;
8419 }
8420
8421 ath11k_dbg(ab, ATH11K_DBG_WMI, "event fils discovery");
8422
8423 ev = tb[WMI_TAG_HOST_SWFDA_EVENT];
8424 if (!ev) {
8425 ath11k_warn(ab, "failed to fetch FILS discovery event\n");
8426 kfree(tb);
8427 return;
8428 }
8429
8430 ath11k_warn(ab,
8431 "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n",
8432 ev->vdev_id, ev->fils_tt, ev->tbtt);
8433
8434 kfree(tb);
8435}
8436
8437static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab,
8438 struct sk_buff *skb)
8439{
8440 const void **tb;
8441 const struct wmi_probe_resp_tx_status_event *ev;
8442 int ret;
8443
8444 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8445 if (IS_ERR(tb)) {
8446 ret = PTR_ERR(tb);
8447 ath11k_warn(ab,
8448 "failed to parse probe response transmission status event tlv: %d\n",
8449 ret);
8450 return;
8451 }
8452
8453 ath11k_dbg(ab, ATH11K_DBG_WMI, "event probe resp tx status");
8454
8455 ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT];
8456 if (!ev) {
8457 ath11k_warn(ab,
8458 "failed to fetch probe response transmission status event");
8459 kfree(tb);
8460 return;
8461 }
8462
8463 if (ev->tx_status)
8464 ath11k_warn(ab,
8465 "Probe response transmission failed for vdev_id %u, status %u\n",
8466 ev->vdev_id, ev->tx_status);
8467
8468 kfree(tb);
8469}
8470
8471static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab,
8472 u16 tag, u16 len,
8473 const void *ptr, void *data)
8474{
8475 struct wmi_wow_ev_arg *ev = data;
8476 const char *wow_pg_fault;
8477 int wow_pg_len;
8478
8479 switch (tag) {
8480 case WMI_TAG_WOW_EVENT_INFO:
8481 memcpy(ev, ptr, sizeof(*ev));
8482 ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n",
8483 ev->wake_reason, wow_reason(ev->wake_reason));
8484 break;
8485
8486 case WMI_TAG_ARRAY_BYTE:
8487 if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) {
8488 wow_pg_fault = ptr;
8489 /* the first 4 bytes are length */
8490 wow_pg_len = *(int *)wow_pg_fault;
8491 wow_pg_fault += sizeof(int);
8492 ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n",
8493 wow_pg_len);
8494 ath11k_dbg_dump(ab, ATH11K_DBG_WMI,
8495 "wow_event_info_type packet present",
8496 "wow_pg_fault ",
8497 wow_pg_fault,
8498 wow_pg_len);
8499 }
8500 break;
8501 default:
8502 break;
8503 }
8504
8505 return 0;
8506}
8507
8508static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb)
8509{
8510 struct wmi_wow_ev_arg ev = { };
8511 int ret;
8512
8513 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
8514 ath11k_wmi_tlv_wow_wakeup_host_parse,
8515 &ev);
8516 if (ret) {
8517 ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret);
8518 return;
8519 }
8520
8521 ath11k_dbg(ab, ATH11K_DBG_WMI, "event wow wakeup host");
8522
8523 complete(&ab->wow.wakeup_completed);
8524}
8525
8526static void
8527ath11k_wmi_diag_event(struct ath11k_base *ab,
8528 struct sk_buff *skb)
8529{
8530 ath11k_dbg(ab, ATH11K_DBG_WMI, "event diag");
8531
8532 trace_ath11k_wmi_diag(ab, skb->data, skb->len);
8533}
8534
8535static const char *ath11k_wmi_twt_add_dialog_event_status(u32 status)
8536{
8537 switch (status) {
8538 case WMI_ADD_TWT_STATUS_OK:
8539 return "ok";
8540 case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
8541 return "twt disabled";
8542 case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
8543 return "dialog id in use";
8544 case WMI_ADD_TWT_STATUS_INVALID_PARAM:
8545 return "invalid parameters";
8546 case WMI_ADD_TWT_STATUS_NOT_READY:
8547 return "not ready";
8548 case WMI_ADD_TWT_STATUS_NO_RESOURCE:
8549 return "resource unavailable";
8550 case WMI_ADD_TWT_STATUS_NO_ACK:
8551 return "no ack";
8552 case WMI_ADD_TWT_STATUS_NO_RESPONSE:
8553 return "no response";
8554 case WMI_ADD_TWT_STATUS_DENIED:
8555 return "denied";
8556 case WMI_ADD_TWT_STATUS_UNKNOWN_ERROR:
8557 fallthrough;
8558 default:
8559 return "unknown error";
8560 }
8561}
8562
8563static void ath11k_wmi_twt_add_dialog_event(struct ath11k_base *ab,
8564 struct sk_buff *skb)
8565{
8566 const void **tb;
8567 const struct wmi_twt_add_dialog_event *ev;
8568 int ret;
8569
8570 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8571 if (IS_ERR(tb)) {
8572 ret = PTR_ERR(tb);
8573 ath11k_warn(ab,
8574 "failed to parse wmi twt add dialog status event tlv: %d\n",
8575 ret);
8576 return;
8577 }
8578
8579 ath11k_dbg(ab, ATH11K_DBG_WMI, "event twt add dialog");
8580
8581 ev = tb[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT];
8582 if (!ev) {
8583 ath11k_warn(ab, "failed to fetch twt add dialog wmi event\n");
8584 goto exit;
8585 }
8586
8587 if (ev->status)
8588 ath11k_warn(ab,
8589 "wmi add twt dialog event vdev %d dialog id %d status %s\n",
8590 ev->vdev_id, ev->dialog_id,
8591 ath11k_wmi_twt_add_dialog_event_status(ev->status));
8592
8593exit:
8594 kfree(tb);
8595}
8596
8597static void ath11k_wmi_gtk_offload_status_event(struct ath11k_base *ab,
8598 struct sk_buff *skb)
8599{
8600 const void **tb;
8601 const struct wmi_gtk_offload_status_event *ev;
8602 struct ath11k_vif *arvif;
8603 __be64 replay_ctr_be;
8604 u64 replay_ctr;
8605 int ret;
8606
8607 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8608 if (IS_ERR(tb)) {
8609 ret = PTR_ERR(tb);
8610 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8611 return;
8612 }
8613
8614 ev = tb[WMI_TAG_GTK_OFFLOAD_STATUS_EVENT];
8615 if (!ev) {
8616 ath11k_warn(ab, "failed to fetch gtk offload status ev");
8617 kfree(tb);
8618 return;
8619 }
8620
8621 rcu_read_lock();
8622
8623 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
8624 if (!arvif) {
8625 ath11k_warn(ab, "failed to get arvif for vdev_id:%d\n",
8626 ev->vdev_id);
8627 goto exit;
8628 }
8629
8630 ath11k_dbg(ab, ATH11K_DBG_WMI, "event gtk offload refresh_cnt %d\n",
8631 ev->refresh_cnt);
8632 ath11k_dbg_dump(ab, ATH11K_DBG_WMI, "replay_cnt",
8633 NULL, ev->replay_ctr.counter, GTK_REPLAY_COUNTER_BYTES);
8634
8635 replay_ctr = ev->replay_ctr.word1;
8636 replay_ctr = (replay_ctr << 32) | ev->replay_ctr.word0;
8637 arvif->rekey_data.replay_ctr = replay_ctr;
8638
8639 /* supplicant expects big-endian replay counter */
8640 replay_ctr_be = cpu_to_be64(replay_ctr);
8641
8642 ieee80211_gtk_rekey_notify(arvif->vif, arvif->bssid,
8643 (void *)&replay_ctr_be, GFP_ATOMIC);
8644exit:
8645 rcu_read_unlock();
8646
8647 kfree(tb);
8648}
8649
8650static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
8651{
8652 struct wmi_cmd_hdr *cmd_hdr;
8653 enum wmi_tlv_event_id id;
8654
8655 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
8656 id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
8657
8658 trace_ath11k_wmi_event(ab, id, skb->data, skb->len);
8659
8660 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
8661 goto out;
8662
8663 switch (id) {
8664 /* Process all the WMI events here */
8665 case WMI_SERVICE_READY_EVENTID:
8666 ath11k_service_ready_event(ab, skb);
8667 break;
8668 case WMI_SERVICE_READY_EXT_EVENTID:
8669 ath11k_service_ready_ext_event(ab, skb);
8670 break;
8671 case WMI_SERVICE_READY_EXT2_EVENTID:
8672 ath11k_service_ready_ext2_event(ab, skb);
8673 break;
8674 case WMI_REG_CHAN_LIST_CC_EVENTID:
8675 ath11k_reg_chan_list_event(ab, skb, WMI_REG_CHAN_LIST_CC_ID);
8676 break;
8677 case WMI_REG_CHAN_LIST_CC_EXT_EVENTID:
8678 ath11k_reg_chan_list_event(ab, skb, WMI_REG_CHAN_LIST_CC_EXT_ID);
8679 break;
8680 case WMI_READY_EVENTID:
8681 ath11k_ready_event(ab, skb);
8682 break;
8683 case WMI_PEER_DELETE_RESP_EVENTID:
8684 ath11k_peer_delete_resp_event(ab, skb);
8685 break;
8686 case WMI_VDEV_START_RESP_EVENTID:
8687 ath11k_vdev_start_resp_event(ab, skb);
8688 break;
8689 case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
8690 ath11k_bcn_tx_status_event(ab, skb);
8691 break;
8692 case WMI_VDEV_STOPPED_EVENTID:
8693 ath11k_vdev_stopped_event(ab, skb);
8694 break;
8695 case WMI_MGMT_RX_EVENTID:
8696 ath11k_mgmt_rx_event(ab, skb);
8697 /* mgmt_rx_event() owns the skb now! */
8698 return;
8699 case WMI_MGMT_TX_COMPLETION_EVENTID:
8700 ath11k_mgmt_tx_compl_event(ab, skb);
8701 break;
8702 case WMI_SCAN_EVENTID:
8703 ath11k_scan_event(ab, skb);
8704 break;
8705 case WMI_PEER_STA_KICKOUT_EVENTID:
8706 ath11k_peer_sta_kickout_event(ab, skb);
8707 break;
8708 case WMI_ROAM_EVENTID:
8709 ath11k_roam_event(ab, skb);
8710 break;
8711 case WMI_CHAN_INFO_EVENTID:
8712 ath11k_chan_info_event(ab, skb);
8713 break;
8714 case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
8715 ath11k_pdev_bss_chan_info_event(ab, skb);
8716 break;
8717 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
8718 ath11k_vdev_install_key_compl_event(ab, skb);
8719 break;
8720 case WMI_SERVICE_AVAILABLE_EVENTID:
8721 ath11k_service_available_event(ab, skb);
8722 break;
8723 case WMI_PEER_ASSOC_CONF_EVENTID:
8724 ath11k_peer_assoc_conf_event(ab, skb);
8725 break;
8726 case WMI_UPDATE_STATS_EVENTID:
8727 ath11k_update_stats_event(ab, skb);
8728 break;
8729 case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
8730 ath11k_pdev_ctl_failsafe_check_event(ab, skb);
8731 break;
8732 case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
8733 ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
8734 break;
8735 case WMI_PDEV_UTF_EVENTID:
8736 ath11k_tm_wmi_event(ab, id, skb);
8737 break;
8738 case WMI_PDEV_TEMPERATURE_EVENTID:
8739 ath11k_wmi_pdev_temperature_event(ab, skb);
8740 break;
8741 case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
8742 ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
8743 break;
8744 case WMI_HOST_FILS_DISCOVERY_EVENTID:
8745 ath11k_fils_discovery_event(ab, skb);
8746 break;
8747 case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID:
8748 ath11k_probe_resp_tx_status_event(ab, skb);
8749 break;
8750 case WMI_OBSS_COLOR_COLLISION_DETECTION_EVENTID:
8751 ath11k_wmi_obss_color_collision_event(ab, skb);
8752 break;
8753 case WMI_TWT_ADD_DIALOG_EVENTID:
8754 ath11k_wmi_twt_add_dialog_event(ab, skb);
8755 break;
8756 case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
8757 ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
8758 break;
8759 case WMI_VDEV_DELETE_RESP_EVENTID:
8760 ath11k_vdev_delete_resp_event(ab, skb);
8761 break;
8762 case WMI_WOW_WAKEUP_HOST_EVENTID:
8763 ath11k_wmi_event_wow_wakeup_host(ab, skb);
8764 break;
8765 case WMI_11D_NEW_COUNTRY_EVENTID:
8766 ath11k_reg_11d_new_cc_event(ab, skb);
8767 break;
8768 case WMI_DIAG_EVENTID:
8769 ath11k_wmi_diag_event(ab, skb);
8770 break;
8771 case WMI_PEER_STA_PS_STATECHG_EVENTID:
8772 ath11k_wmi_event_peer_sta_ps_state_chg(ab, skb);
8773 break;
8774 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
8775 ath11k_wmi_gtk_offload_status_event(ab, skb);
8776 break;
8777 default:
8778 ath11k_dbg(ab, ATH11K_DBG_WMI, "unsupported event id 0x%x\n", id);
8779 break;
8780 }
8781
8782out:
8783 dev_kfree_skb(skb);
8784}
8785
8786static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
8787 u32 pdev_idx)
8788{
8789 int status;
8790 u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
8791 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
8792 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
8793
8794 struct ath11k_htc_svc_conn_req conn_req;
8795 struct ath11k_htc_svc_conn_resp conn_resp;
8796
8797 memset(&conn_req, 0, sizeof(conn_req));
8798 memset(&conn_resp, 0, sizeof(conn_resp));
8799
8800 /* these fields are the same for all service endpoints */
8801 conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
8802 conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
8803 conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
8804
8805 /* connect to control service */
8806 conn_req.service_id = svc_id[pdev_idx];
8807
8808 status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
8809 if (status) {
8810 ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
8811 status);
8812 return status;
8813 }
8814
8815 ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
8816 ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
8817 ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
8818 init_waitqueue_head(&ab->wmi_ab.wmi[pdev_idx].tx_ce_desc_wq);
8819
8820 return 0;
8821}
8822
8823static int
8824ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
8825 struct wmi_unit_test_cmd ut_cmd,
8826 u32 *test_args)
8827{
8828 struct ath11k_pdev_wmi *wmi = ar->wmi;
8829 struct wmi_unit_test_cmd *cmd;
8830 struct sk_buff *skb;
8831 struct wmi_tlv *tlv;
8832 void *ptr;
8833 u32 *ut_cmd_args;
8834 int buf_len, arg_len;
8835 int ret;
8836 int i;
8837
8838 arg_len = sizeof(u32) * ut_cmd.num_args;
8839 buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
8840
8841 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
8842 if (!skb)
8843 return -ENOMEM;
8844
8845 cmd = (struct wmi_unit_test_cmd *)skb->data;
8846 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
8847 FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
8848
8849 cmd->vdev_id = ut_cmd.vdev_id;
8850 cmd->module_id = ut_cmd.module_id;
8851 cmd->num_args = ut_cmd.num_args;
8852 cmd->diag_token = ut_cmd.diag_token;
8853
8854 ptr = skb->data + sizeof(ut_cmd);
8855
8856 tlv = ptr;
8857 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8858 FIELD_PREP(WMI_TLV_LEN, arg_len);
8859
8860 ptr += TLV_HDR_SIZE;
8861
8862 ut_cmd_args = ptr;
8863 for (i = 0; i < ut_cmd.num_args; i++)
8864 ut_cmd_args[i] = test_args[i];
8865
8866 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
8867
8868 if (ret) {
8869 ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
8870 ret);
8871 dev_kfree_skb(skb);
8872 }
8873
8874 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8875 "cmd unit test module %d vdev %d n_args %d token %d\n",
8876 cmd->module_id, cmd->vdev_id, cmd->num_args,
8877 cmd->diag_token);
8878
8879 return ret;
8880}
8881
8882int ath11k_wmi_simulate_radar(struct ath11k *ar)
8883{
8884 struct ath11k_vif *arvif;
8885 u32 dfs_args[DFS_MAX_TEST_ARGS];
8886 struct wmi_unit_test_cmd wmi_ut;
8887 bool arvif_found = false;
8888
8889 list_for_each_entry(arvif, &ar->arvifs, list) {
8890 if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
8891 arvif_found = true;
8892 break;
8893 }
8894 }
8895
8896 if (!arvif_found)
8897 return -EINVAL;
8898
8899 dfs_args[DFS_TEST_CMDID] = 0;
8900 dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
8901 /* Currently we could pass segment_id(b0 - b1), chirp(b2)
8902 * freq offset (b3 - b10) to unit test. For simulation
8903 * purpose this can be set to 0 which is valid.
8904 */
8905 dfs_args[DFS_TEST_RADAR_PARAM] = 0;
8906
8907 wmi_ut.vdev_id = arvif->vdev_id;
8908 wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
8909 wmi_ut.num_args = DFS_MAX_TEST_ARGS;
8910 wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
8911
8912 ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
8913
8914 return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
8915}
8916
8917int ath11k_wmi_fw_dbglog_cfg(struct ath11k *ar, u32 *module_id_bitmap,
8918 struct ath11k_fw_dbglog *dbglog)
8919{
8920 struct ath11k_pdev_wmi *wmi = ar->wmi;
8921 struct wmi_debug_log_config_cmd_fixed_param *cmd;
8922 struct sk_buff *skb;
8923 struct wmi_tlv *tlv;
8924 int ret, len;
8925
8926 len = sizeof(*cmd) + TLV_HDR_SIZE + (MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8927 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8928 if (!skb)
8929 return -ENOMEM;
8930
8931 cmd = (struct wmi_debug_log_config_cmd_fixed_param *)skb->data;
8932 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DEBUG_LOG_CONFIG_CMD) |
8933 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8934 cmd->dbg_log_param = dbglog->param;
8935
8936 tlv = (struct wmi_tlv *)((u8 *)cmd + sizeof(*cmd));
8937 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8938 FIELD_PREP(WMI_TLV_LEN, MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8939
8940 switch (dbglog->param) {
8941 case WMI_DEBUG_LOG_PARAM_LOG_LEVEL:
8942 case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE:
8943 case WMI_DEBUG_LOG_PARAM_VDEV_DISABLE:
8944 case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE_BITMAP:
8945 cmd->value = dbglog->value;
8946 break;
8947 case WMI_DEBUG_LOG_PARAM_MOD_ENABLE_BITMAP:
8948 case WMI_DEBUG_LOG_PARAM_WOW_MOD_ENABLE_BITMAP:
8949 cmd->value = dbglog->value;
8950 memcpy(tlv->value, module_id_bitmap,
8951 MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8952 /* clear current config to be used for next user config */
8953 memset(module_id_bitmap, 0,
8954 MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8955 break;
8956 default:
8957 dev_kfree_skb(skb);
8958 return -EINVAL;
8959 }
8960
8961 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DBGLOG_CFG_CMDID);
8962 if (ret) {
8963 ath11k_warn(ar->ab,
8964 "failed to send WMI_DBGLOG_CFG_CMDID\n");
8965 dev_kfree_skb(skb);
8966 }
8967
8968 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd dbglog cfg");
8969
8970 return ret;
8971}
8972
8973int ath11k_wmi_connect(struct ath11k_base *ab)
8974{
8975 u32 i;
8976 u8 wmi_ep_count;
8977
8978 wmi_ep_count = ab->htc.wmi_ep_count;
8979 if (wmi_ep_count > ab->hw_params.max_radios)
8980 return -1;
8981
8982 for (i = 0; i < wmi_ep_count; i++)
8983 ath11k_connect_pdev_htc_service(ab, i);
8984
8985 return 0;
8986}
8987
8988static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
8989{
8990 if (WARN_ON(pdev_id >= MAX_RADIOS))
8991 return;
8992
8993 /* TODO: Deinit any pdev specific wmi resource */
8994}
8995
8996int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
8997 u8 pdev_id)
8998{
8999 struct ath11k_pdev_wmi *wmi_handle;
9000
9001 if (pdev_id >= ab->hw_params.max_radios)
9002 return -EINVAL;
9003
9004 wmi_handle = &ab->wmi_ab.wmi[pdev_id];
9005
9006 wmi_handle->wmi_ab = &ab->wmi_ab;
9007
9008 ab->wmi_ab.ab = ab;
9009 /* TODO: Init remaining resource specific to pdev */
9010
9011 return 0;
9012}
9013
9014int ath11k_wmi_attach(struct ath11k_base *ab)
9015{
9016 int ret;
9017
9018 ret = ath11k_wmi_pdev_attach(ab, 0);
9019 if (ret)
9020 return ret;
9021
9022 ab->wmi_ab.ab = ab;
9023 ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
9024
9025 /* It's overwritten when service_ext_ready is handled */
9026 if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1)
9027 ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
9028
9029 /* TODO: Init remaining wmi soc resources required */
9030 init_completion(&ab->wmi_ab.service_ready);
9031 init_completion(&ab->wmi_ab.unified_ready);
9032
9033 return 0;
9034}
9035
9036void ath11k_wmi_detach(struct ath11k_base *ab)
9037{
9038 int i;
9039
9040 /* TODO: Deinit wmi resource specific to SOC as required */
9041
9042 for (i = 0; i < ab->htc.wmi_ep_count; i++)
9043 ath11k_wmi_pdev_detach(ab, i);
9044
9045 ath11k_wmi_free_dbring_caps(ab);
9046}
9047
9048int ath11k_wmi_hw_data_filter_cmd(struct ath11k *ar, u32 vdev_id,
9049 u32 filter_bitmap, bool enable)
9050{
9051 struct wmi_hw_data_filter_cmd *cmd;
9052 struct sk_buff *skb;
9053 int len;
9054
9055 len = sizeof(*cmd);
9056 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9057
9058 if (!skb)
9059 return -ENOMEM;
9060
9061 cmd = (struct wmi_hw_data_filter_cmd *)skb->data;
9062 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_HW_DATA_FILTER_CMD) |
9063 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9064
9065 cmd->vdev_id = vdev_id;
9066 cmd->enable = enable;
9067
9068 /* Set all modes in case of disable */
9069 if (cmd->enable)
9070 cmd->hw_filter_bitmap = filter_bitmap;
9071 else
9072 cmd->hw_filter_bitmap = ((u32)~0U);
9073
9074 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9075 "hw data filter enable %d filter_bitmap 0x%x\n",
9076 enable, filter_bitmap);
9077
9078 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_HW_DATA_FILTER_CMDID);
9079}
9080
9081int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar)
9082{
9083 struct wmi_wow_host_wakeup_ind *cmd;
9084 struct sk_buff *skb;
9085 size_t len;
9086
9087 len = sizeof(*cmd);
9088 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9089 if (!skb)
9090 return -ENOMEM;
9091
9092 cmd = (struct wmi_wow_host_wakeup_ind *)skb->data;
9093 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9094 WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) |
9095 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9096
9097 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow host wakeup ind\n");
9098
9099 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
9100}
9101
9102int ath11k_wmi_wow_enable(struct ath11k *ar)
9103{
9104 struct wmi_wow_enable_cmd *cmd;
9105 struct sk_buff *skb;
9106 int len;
9107
9108 len = sizeof(*cmd);
9109 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9110 if (!skb)
9111 return -ENOMEM;
9112
9113 cmd = (struct wmi_wow_enable_cmd *)skb->data;
9114 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) |
9115 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9116
9117 cmd->enable = 1;
9118 cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
9119 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow enable\n");
9120
9121 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID);
9122}
9123
9124int ath11k_wmi_scan_prob_req_oui(struct ath11k *ar,
9125 const u8 mac_addr[ETH_ALEN])
9126{
9127 struct sk_buff *skb;
9128 struct wmi_scan_prob_req_oui_cmd *cmd;
9129 u32 prob_req_oui;
9130 int len;
9131
9132 prob_req_oui = (((u32)mac_addr[0]) << 16) |
9133 (((u32)mac_addr[1]) << 8) | mac_addr[2];
9134
9135 len = sizeof(*cmd);
9136 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9137 if (!skb)
9138 return -ENOMEM;
9139
9140 cmd = (struct wmi_scan_prob_req_oui_cmd *)skb->data;
9141 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9142 WMI_TAG_SCAN_PROB_REQ_OUI_CMD) |
9143 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9144 cmd->prob_req_oui = prob_req_oui;
9145
9146 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "scan prob req oui %d\n",
9147 prob_req_oui);
9148
9149 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SCAN_PROB_REQ_OUI_CMDID);
9150}
9151
9152int ath11k_wmi_wow_add_wakeup_event(struct ath11k *ar, u32 vdev_id,
9153 enum wmi_wow_wakeup_event event,
9154 u32 enable)
9155{
9156 struct wmi_wow_add_del_event_cmd *cmd;
9157 struct sk_buff *skb;
9158 size_t len;
9159
9160 len = sizeof(*cmd);
9161 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9162 if (!skb)
9163 return -ENOMEM;
9164
9165 cmd = (struct wmi_wow_add_del_event_cmd *)skb->data;
9166 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ADD_DEL_EVT_CMD) |
9167 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9168
9169 cmd->vdev_id = vdev_id;
9170 cmd->is_add = enable;
9171 cmd->event_bitmap = (1 << event);
9172
9173 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow add wakeup event %s enable %d vdev_id %d\n",
9174 wow_wakeup_event(event), enable, vdev_id);
9175
9176 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
9177}
9178
9179int ath11k_wmi_wow_add_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id,
9180 const u8 *pattern, const u8 *mask,
9181 int pattern_len, int pattern_offset)
9182{
9183 struct wmi_wow_add_pattern_cmd *cmd;
9184 struct wmi_wow_bitmap_pattern *bitmap;
9185 struct wmi_tlv *tlv;
9186 struct sk_buff *skb;
9187 u8 *ptr;
9188 size_t len;
9189
9190 len = sizeof(*cmd) +
9191 sizeof(*tlv) + /* array struct */
9192 sizeof(*bitmap) + /* bitmap */
9193 sizeof(*tlv) + /* empty ipv4 sync */
9194 sizeof(*tlv) + /* empty ipv6 sync */
9195 sizeof(*tlv) + /* empty magic */
9196 sizeof(*tlv) + /* empty info timeout */
9197 sizeof(*tlv) + sizeof(u32); /* ratelimit interval */
9198
9199 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9200 if (!skb)
9201 return -ENOMEM;
9202
9203 /* cmd */
9204 ptr = (u8 *)skb->data;
9205 cmd = (struct wmi_wow_add_pattern_cmd *)ptr;
9206 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9207 WMI_TAG_WOW_ADD_PATTERN_CMD) |
9208 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9209
9210 cmd->vdev_id = vdev_id;
9211 cmd->pattern_id = pattern_id;
9212 cmd->pattern_type = WOW_BITMAP_PATTERN;
9213
9214 ptr += sizeof(*cmd);
9215
9216 /* bitmap */
9217 tlv = (struct wmi_tlv *)ptr;
9218 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9219 WMI_TAG_ARRAY_STRUCT) |
9220 FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap));
9221
9222 ptr += sizeof(*tlv);
9223
9224 bitmap = (struct wmi_wow_bitmap_pattern *)ptr;
9225 bitmap->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9226 WMI_TAG_WOW_BITMAP_PATTERN_T) |
9227 FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap) - TLV_HDR_SIZE);
9228
9229 memcpy(bitmap->patternbuf, pattern, pattern_len);
9230 ath11k_ce_byte_swap(bitmap->patternbuf, roundup(pattern_len, 4));
9231 memcpy(bitmap->bitmaskbuf, mask, pattern_len);
9232 ath11k_ce_byte_swap(bitmap->bitmaskbuf, roundup(pattern_len, 4));
9233 bitmap->pattern_offset = pattern_offset;
9234 bitmap->pattern_len = pattern_len;
9235 bitmap->bitmask_len = pattern_len;
9236 bitmap->pattern_id = pattern_id;
9237
9238 ptr += sizeof(*bitmap);
9239
9240 /* ipv4 sync */
9241 tlv = (struct wmi_tlv *)ptr;
9242 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9243 WMI_TAG_ARRAY_STRUCT) |
9244 FIELD_PREP(WMI_TLV_LEN, 0);
9245
9246 ptr += sizeof(*tlv);
9247
9248 /* ipv6 sync */
9249 tlv = (struct wmi_tlv *)ptr;
9250 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9251 WMI_TAG_ARRAY_STRUCT) |
9252 FIELD_PREP(WMI_TLV_LEN, 0);
9253
9254 ptr += sizeof(*tlv);
9255
9256 /* magic */
9257 tlv = (struct wmi_tlv *)ptr;
9258 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9259 WMI_TAG_ARRAY_STRUCT) |
9260 FIELD_PREP(WMI_TLV_LEN, 0);
9261
9262 ptr += sizeof(*tlv);
9263
9264 /* pattern info timeout */
9265 tlv = (struct wmi_tlv *)ptr;
9266 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9267 WMI_TAG_ARRAY_UINT32) |
9268 FIELD_PREP(WMI_TLV_LEN, 0);
9269
9270 ptr += sizeof(*tlv);
9271
9272 /* ratelimit interval */
9273 tlv = (struct wmi_tlv *)ptr;
9274 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9275 WMI_TAG_ARRAY_UINT32) |
9276 FIELD_PREP(WMI_TLV_LEN, sizeof(u32));
9277
9278 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow add pattern vdev_id %d pattern_id %d pattern_offset %d\n",
9279 vdev_id, pattern_id, pattern_offset);
9280
9281 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ADD_WAKE_PATTERN_CMDID);
9282}
9283
9284int ath11k_wmi_wow_del_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id)
9285{
9286 struct wmi_wow_del_pattern_cmd *cmd;
9287 struct sk_buff *skb;
9288 size_t len;
9289
9290 len = sizeof(*cmd);
9291 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9292 if (!skb)
9293 return -ENOMEM;
9294
9295 cmd = (struct wmi_wow_del_pattern_cmd *)skb->data;
9296 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9297 WMI_TAG_WOW_DEL_PATTERN_CMD) |
9298 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9299
9300 cmd->vdev_id = vdev_id;
9301 cmd->pattern_id = pattern_id;
9302 cmd->pattern_type = WOW_BITMAP_PATTERN;
9303
9304 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow del pattern vdev_id %d pattern_id %d\n",
9305 vdev_id, pattern_id);
9306
9307 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_DEL_WAKE_PATTERN_CMDID);
9308}
9309
9310static struct sk_buff *
9311ath11k_wmi_op_gen_config_pno_start(struct ath11k *ar,
9312 u32 vdev_id,
9313 struct wmi_pno_scan_req *pno)
9314{
9315 struct nlo_configured_parameters *nlo_list;
9316 struct wmi_wow_nlo_config_cmd *cmd;
9317 struct wmi_tlv *tlv;
9318 struct sk_buff *skb;
9319 u32 *channel_list;
9320 size_t len, nlo_list_len, channel_list_len;
9321 u8 *ptr;
9322 u32 i;
9323
9324 len = sizeof(*cmd) +
9325 sizeof(*tlv) +
9326 /* TLV place holder for array of structures
9327 * nlo_configured_parameters(nlo_list)
9328 */
9329 sizeof(*tlv);
9330 /* TLV place holder for array of uint32 channel_list */
9331
9332 channel_list_len = sizeof(u32) * pno->a_networks[0].channel_count;
9333 len += channel_list_len;
9334
9335 nlo_list_len = sizeof(*nlo_list) * pno->uc_networks_count;
9336 len += nlo_list_len;
9337
9338 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9339 if (!skb)
9340 return ERR_PTR(-ENOMEM);
9341
9342 ptr = (u8 *)skb->data;
9343 cmd = (struct wmi_wow_nlo_config_cmd *)ptr;
9344 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
9345 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9346
9347 cmd->vdev_id = pno->vdev_id;
9348 cmd->flags = WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN;
9349
9350 /* current FW does not support min-max range for dwell time */
9351 cmd->active_dwell_time = pno->active_max_time;
9352 cmd->passive_dwell_time = pno->passive_max_time;
9353
9354 if (pno->do_passive_scan)
9355 cmd->flags |= WMI_NLO_CONFIG_SCAN_PASSIVE;
9356
9357 cmd->fast_scan_period = pno->fast_scan_period;
9358 cmd->slow_scan_period = pno->slow_scan_period;
9359 cmd->fast_scan_max_cycles = pno->fast_scan_max_cycles;
9360 cmd->delay_start_time = pno->delay_start_time;
9361
9362 if (pno->enable_pno_scan_randomization) {
9363 cmd->flags |= WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
9364 WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ;
9365 ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
9366 ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
9367 ath11k_ce_byte_swap(cmd->mac_addr.addr, 8);
9368 ath11k_ce_byte_swap(cmd->mac_mask.addr, 8);
9369 }
9370
9371 ptr += sizeof(*cmd);
9372
9373 /* nlo_configured_parameters(nlo_list) */
9374 cmd->no_of_ssids = pno->uc_networks_count;
9375 tlv = (struct wmi_tlv *)ptr;
9376 tlv->header = FIELD_PREP(WMI_TLV_TAG,
9377 WMI_TAG_ARRAY_STRUCT) |
9378 FIELD_PREP(WMI_TLV_LEN, nlo_list_len);
9379
9380 ptr += sizeof(*tlv);
9381 nlo_list = (struct nlo_configured_parameters *)ptr;
9382 for (i = 0; i < cmd->no_of_ssids; i++) {
9383 tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
9384 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9385 FIELD_PREP(WMI_TLV_LEN, sizeof(*nlo_list) - sizeof(*tlv));
9386
9387 nlo_list[i].ssid.valid = true;
9388 nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
9389 memcpy(nlo_list[i].ssid.ssid.ssid,
9390 pno->a_networks[i].ssid.ssid,
9391 nlo_list[i].ssid.ssid.ssid_len);
9392 ath11k_ce_byte_swap(nlo_list[i].ssid.ssid.ssid,
9393 roundup(nlo_list[i].ssid.ssid.ssid_len, 4));
9394
9395 if (pno->a_networks[i].rssi_threshold &&
9396 pno->a_networks[i].rssi_threshold > -300) {
9397 nlo_list[i].rssi_cond.valid = true;
9398 nlo_list[i].rssi_cond.rssi =
9399 pno->a_networks[i].rssi_threshold;
9400 }
9401
9402 nlo_list[i].bcast_nw_type.valid = true;
9403 nlo_list[i].bcast_nw_type.bcast_nw_type =
9404 pno->a_networks[i].bcast_nw_type;
9405 }
9406
9407 ptr += nlo_list_len;
9408 cmd->num_of_channels = pno->a_networks[0].channel_count;
9409 tlv = (struct wmi_tlv *)ptr;
9410 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
9411 FIELD_PREP(WMI_TLV_LEN, channel_list_len);
9412 ptr += sizeof(*tlv);
9413 channel_list = (u32 *)ptr;
9414 for (i = 0; i < cmd->num_of_channels; i++)
9415 channel_list[i] = pno->a_networks[0].channels[i];
9416
9417 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv start pno config vdev_id %d\n",
9418 vdev_id);
9419
9420 return skb;
9421}
9422
9423static struct sk_buff *ath11k_wmi_op_gen_config_pno_stop(struct ath11k *ar,
9424 u32 vdev_id)
9425{
9426 struct wmi_wow_nlo_config_cmd *cmd;
9427 struct sk_buff *skb;
9428 size_t len;
9429
9430 len = sizeof(*cmd);
9431 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9432 if (!skb)
9433 return ERR_PTR(-ENOMEM);
9434
9435 cmd = (struct wmi_wow_nlo_config_cmd *)skb->data;
9436 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
9437 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
9438
9439 cmd->vdev_id = vdev_id;
9440 cmd->flags = WMI_NLO_CONFIG_STOP;
9441
9442 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9443 "tlv stop pno config vdev_id %d\n", vdev_id);
9444 return skb;
9445}
9446
9447int ath11k_wmi_wow_config_pno(struct ath11k *ar, u32 vdev_id,
9448 struct wmi_pno_scan_req *pno_scan)
9449{
9450 struct sk_buff *skb;
9451
9452 if (pno_scan->enable)
9453 skb = ath11k_wmi_op_gen_config_pno_start(ar, vdev_id, pno_scan);
9454 else
9455 skb = ath11k_wmi_op_gen_config_pno_stop(ar, vdev_id);
9456
9457 if (IS_ERR_OR_NULL(skb))
9458 return -ENOMEM;
9459
9460 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
9461}
9462
9463static void ath11k_wmi_fill_ns_offload(struct ath11k *ar,
9464 struct ath11k_arp_ns_offload *offload,
9465 u8 **ptr,
9466 bool enable,
9467 bool ext)
9468{
9469 struct wmi_ns_offload_tuple *ns;
9470 struct wmi_tlv *tlv;
9471 u8 *buf_ptr = *ptr;
9472 u32 ns_cnt, ns_ext_tuples;
9473 int i, max_offloads;
9474
9475 ns_cnt = offload->ipv6_count;
9476
9477 tlv = (struct wmi_tlv *)buf_ptr;
9478
9479 if (ext) {
9480 ns_ext_tuples = offload->ipv6_count - WMI_MAX_NS_OFFLOADS;
9481 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9482 FIELD_PREP(WMI_TLV_LEN, ns_ext_tuples * sizeof(*ns));
9483 i = WMI_MAX_NS_OFFLOADS;
9484 max_offloads = offload->ipv6_count;
9485 } else {
9486 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9487 FIELD_PREP(WMI_TLV_LEN, WMI_MAX_NS_OFFLOADS * sizeof(*ns));
9488 i = 0;
9489 max_offloads = WMI_MAX_NS_OFFLOADS;
9490 }
9491
9492 buf_ptr += sizeof(*tlv);
9493
9494 for (; i < max_offloads; i++) {
9495 ns = (struct wmi_ns_offload_tuple *)buf_ptr;
9496 ns->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NS_OFFLOAD_TUPLE) |
9497 FIELD_PREP(WMI_TLV_LEN, sizeof(*ns) - TLV_HDR_SIZE);
9498
9499 if (enable) {
9500 if (i < ns_cnt)
9501 ns->flags |= WMI_NSOL_FLAGS_VALID;
9502
9503 memcpy(ns->target_ipaddr[0], offload->ipv6_addr[i], 16);
9504 memcpy(ns->solicitation_ipaddr, offload->self_ipv6_addr[i], 16);
9505 ath11k_ce_byte_swap(ns->target_ipaddr[0], 16);
9506 ath11k_ce_byte_swap(ns->solicitation_ipaddr, 16);
9507
9508 if (offload->ipv6_type[i])
9509 ns->flags |= WMI_NSOL_FLAGS_IS_IPV6_ANYCAST;
9510
9511 memcpy(ns->target_mac.addr, offload->mac_addr, ETH_ALEN);
9512 ath11k_ce_byte_swap(ns->target_mac.addr, 8);
9513
9514 if (ns->target_mac.word0 != 0 ||
9515 ns->target_mac.word1 != 0) {
9516 ns->flags |= WMI_NSOL_FLAGS_MAC_VALID;
9517 }
9518
9519 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9520 "index %d ns_solicited %pI6 target %pI6",
9521 i, ns->solicitation_ipaddr,
9522 ns->target_ipaddr[0]);
9523 }
9524
9525 buf_ptr += sizeof(*ns);
9526 }
9527
9528 *ptr = buf_ptr;
9529}
9530
9531static void ath11k_wmi_fill_arp_offload(struct ath11k *ar,
9532 struct ath11k_arp_ns_offload *offload,
9533 u8 **ptr,
9534 bool enable)
9535{
9536 struct wmi_arp_offload_tuple *arp;
9537 struct wmi_tlv *tlv;
9538 u8 *buf_ptr = *ptr;
9539 int i;
9540
9541 /* fill arp tuple */
9542 tlv = (struct wmi_tlv *)buf_ptr;
9543 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9544 FIELD_PREP(WMI_TLV_LEN, WMI_MAX_ARP_OFFLOADS * sizeof(*arp));
9545 buf_ptr += sizeof(*tlv);
9546
9547 for (i = 0; i < WMI_MAX_ARP_OFFLOADS; i++) {
9548 arp = (struct wmi_arp_offload_tuple *)buf_ptr;
9549 arp->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARP_OFFLOAD_TUPLE) |
9550 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9551
9552 if (enable && i < offload->ipv4_count) {
9553 /* Copy the target ip addr and flags */
9554 arp->flags = WMI_ARPOL_FLAGS_VALID;
9555 memcpy(arp->target_ipaddr, offload->ipv4_addr[i], 4);
9556 ath11k_ce_byte_swap(arp->target_ipaddr, 4);
9557
9558 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "arp offload address %pI4",
9559 arp->target_ipaddr);
9560 }
9561
9562 buf_ptr += sizeof(*arp);
9563 }
9564
9565 *ptr = buf_ptr;
9566}
9567
9568int ath11k_wmi_arp_ns_offload(struct ath11k *ar,
9569 struct ath11k_vif *arvif, bool enable)
9570{
9571 struct ath11k_arp_ns_offload *offload;
9572 struct wmi_set_arp_ns_offload_cmd *cmd;
9573 struct wmi_tlv *tlv;
9574 struct sk_buff *skb;
9575 u8 *buf_ptr;
9576 size_t len;
9577 u8 ns_cnt, ns_ext_tuples = 0;
9578
9579 offload = &arvif->arp_ns_offload;
9580 ns_cnt = offload->ipv6_count;
9581
9582 len = sizeof(*cmd) +
9583 sizeof(*tlv) +
9584 WMI_MAX_NS_OFFLOADS * sizeof(struct wmi_ns_offload_tuple) +
9585 sizeof(*tlv) +
9586 WMI_MAX_ARP_OFFLOADS * sizeof(struct wmi_arp_offload_tuple);
9587
9588 if (ns_cnt > WMI_MAX_NS_OFFLOADS) {
9589 ns_ext_tuples = ns_cnt - WMI_MAX_NS_OFFLOADS;
9590 len += sizeof(*tlv) +
9591 ns_ext_tuples * sizeof(struct wmi_ns_offload_tuple);
9592 }
9593
9594 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9595 if (!skb)
9596 return -ENOMEM;
9597
9598 buf_ptr = skb->data;
9599 cmd = (struct wmi_set_arp_ns_offload_cmd *)buf_ptr;
9600 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9601 WMI_TAG_SET_ARP_NS_OFFLOAD_CMD) |
9602 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9603
9604 cmd->flags = 0;
9605 cmd->vdev_id = arvif->vdev_id;
9606 cmd->num_ns_ext_tuples = ns_ext_tuples;
9607
9608 buf_ptr += sizeof(*cmd);
9609
9610 ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 0);
9611 ath11k_wmi_fill_arp_offload(ar, offload, &buf_ptr, enable);
9612
9613 if (ns_ext_tuples)
9614 ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 1);
9615
9616 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SET_ARP_NS_OFFLOAD_CMDID);
9617}
9618
9619int ath11k_wmi_gtk_rekey_offload(struct ath11k *ar,
9620 struct ath11k_vif *arvif, bool enable)
9621{
9622 struct wmi_gtk_rekey_offload_cmd *cmd;
9623 struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
9624 int len;
9625 struct sk_buff *skb;
9626 __le64 replay_ctr;
9627
9628 len = sizeof(*cmd);
9629 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9630 if (!skb)
9631 return -ENOMEM;
9632
9633 cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9634 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9635 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9636
9637 cmd->vdev_id = arvif->vdev_id;
9638
9639 if (enable) {
9640 cmd->flags = GTK_OFFLOAD_ENABLE_OPCODE;
9641
9642 /* the length in rekey_data and cmd is equal */
9643 memcpy(cmd->kck, rekey_data->kck, sizeof(cmd->kck));
9644 ath11k_ce_byte_swap(cmd->kck, GTK_OFFLOAD_KEK_BYTES);
9645 memcpy(cmd->kek, rekey_data->kek, sizeof(cmd->kek));
9646 ath11k_ce_byte_swap(cmd->kek, GTK_OFFLOAD_KEK_BYTES);
9647
9648 replay_ctr = cpu_to_le64(rekey_data->replay_ctr);
9649 memcpy(cmd->replay_ctr, &replay_ctr,
9650 sizeof(replay_ctr));
9651 ath11k_ce_byte_swap(cmd->replay_ctr, GTK_REPLAY_COUNTER_BYTES);
9652 } else {
9653 cmd->flags = GTK_OFFLOAD_DISABLE_OPCODE;
9654 }
9655
9656 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "offload gtk rekey vdev: %d %d\n",
9657 arvif->vdev_id, enable);
9658 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9659}
9660
9661int ath11k_wmi_gtk_rekey_getinfo(struct ath11k *ar,
9662 struct ath11k_vif *arvif)
9663{
9664 struct wmi_gtk_rekey_offload_cmd *cmd;
9665 int len;
9666 struct sk_buff *skb;
9667
9668 len = sizeof(*cmd);
9669 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9670 if (!skb)
9671 return -ENOMEM;
9672
9673 cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9674 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9675 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9676
9677 cmd->vdev_id = arvif->vdev_id;
9678 cmd->flags = GTK_OFFLOAD_REQUEST_STATUS_OPCODE;
9679
9680 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "get gtk rekey vdev_id: %d\n",
9681 arvif->vdev_id);
9682 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9683}
9684
9685int ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k *ar, const u8 *sar_val)
9686{ struct ath11k_pdev_wmi *wmi = ar->wmi;
9687 struct wmi_pdev_set_sar_table_cmd *cmd;
9688 struct wmi_tlv *tlv;
9689 struct sk_buff *skb;
9690 u8 *buf_ptr;
9691 u32 len, sar_len_aligned, rsvd_len_aligned;
9692
9693 sar_len_aligned = roundup(BIOS_SAR_TABLE_LEN, sizeof(u32));
9694 rsvd_len_aligned = roundup(BIOS_SAR_RSVD1_LEN, sizeof(u32));
9695 len = sizeof(*cmd) +
9696 TLV_HDR_SIZE + sar_len_aligned +
9697 TLV_HDR_SIZE + rsvd_len_aligned;
9698
9699 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9700 if (!skb)
9701 return -ENOMEM;
9702
9703 cmd = (struct wmi_pdev_set_sar_table_cmd *)skb->data;
9704 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_SAR_TABLE_CMD) |
9705 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9706 cmd->pdev_id = ar->pdev->pdev_id;
9707 cmd->sar_len = BIOS_SAR_TABLE_LEN;
9708 cmd->rsvd_len = BIOS_SAR_RSVD1_LEN;
9709
9710 buf_ptr = skb->data + sizeof(*cmd);
9711 tlv = (struct wmi_tlv *)buf_ptr;
9712 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9713 FIELD_PREP(WMI_TLV_LEN, sar_len_aligned);
9714 buf_ptr += TLV_HDR_SIZE;
9715 memcpy(buf_ptr, sar_val, BIOS_SAR_TABLE_LEN);
9716
9717 buf_ptr += sar_len_aligned;
9718 tlv = (struct wmi_tlv *)buf_ptr;
9719 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9720 FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9721
9722 return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_SAR_TABLE_CMDID);
9723}
9724
9725int ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k *ar)
9726{
9727 struct ath11k_pdev_wmi *wmi = ar->wmi;
9728 struct wmi_pdev_set_geo_table_cmd *cmd;
9729 struct wmi_tlv *tlv;
9730 struct sk_buff *skb;
9731 u8 *buf_ptr;
9732 u32 len, rsvd_len_aligned;
9733
9734 rsvd_len_aligned = roundup(BIOS_SAR_RSVD2_LEN, sizeof(u32));
9735 len = sizeof(*cmd) + TLV_HDR_SIZE + rsvd_len_aligned;
9736
9737 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9738 if (!skb)
9739 return -ENOMEM;
9740
9741 cmd = (struct wmi_pdev_set_geo_table_cmd *)skb->data;
9742 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_GEO_TABLE_CMD) |
9743 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9744 cmd->pdev_id = ar->pdev->pdev_id;
9745 cmd->rsvd_len = BIOS_SAR_RSVD2_LEN;
9746
9747 buf_ptr = skb->data + sizeof(*cmd);
9748 tlv = (struct wmi_tlv *)buf_ptr;
9749 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9750 FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9751
9752 return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_GEO_TABLE_CMDID);
9753}
9754
9755int ath11k_wmi_sta_keepalive(struct ath11k *ar,
9756 const struct wmi_sta_keepalive_arg *arg)
9757{
9758 struct ath11k_pdev_wmi *wmi = ar->wmi;
9759 struct wmi_sta_keepalive_cmd *cmd;
9760 struct wmi_sta_keepalive_arp_resp *arp;
9761 struct sk_buff *skb;
9762 size_t len;
9763
9764 len = sizeof(*cmd) + sizeof(*arp);
9765 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9766 if (!skb)
9767 return -ENOMEM;
9768
9769 cmd = (struct wmi_sta_keepalive_cmd *)skb->data;
9770 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9771 WMI_TAG_STA_KEEPALIVE_CMD) |
9772 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9773 cmd->vdev_id = arg->vdev_id;
9774 cmd->enabled = arg->enabled;
9775 cmd->interval = arg->interval;
9776 cmd->method = arg->method;
9777
9778 arp = (struct wmi_sta_keepalive_arp_resp *)(cmd + 1);
9779 arp->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9780 WMI_TAG_STA_KEEPALIVE_ARP_RESPONSE) |
9781 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9782
9783 if (arg->method == WMI_STA_KEEPALIVE_METHOD_UNSOLICITED_ARP_RESPONSE ||
9784 arg->method == WMI_STA_KEEPALIVE_METHOD_GRATUITOUS_ARP_REQUEST) {
9785 arp->src_ip4_addr = arg->src_ip4_addr;
9786 arp->dest_ip4_addr = arg->dest_ip4_addr;
9787 ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
9788 }
9789
9790 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9791 "sta keepalive vdev %d enabled %d method %d interval %d\n",
9792 arg->vdev_id, arg->enabled, arg->method, arg->interval);
9793
9794 return ath11k_wmi_cmd_send(wmi, skb, WMI_STA_KEEPALIVE_CMDID);
9795}