xref: /openbmc/linux/drivers/net/wireless/ath/ath11k/wmi.c (revision 3d40aed8)
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 
24 struct wmi_tlv_policy {
25 	size_t min_len;
26 };
27 
28 struct wmi_tlv_svc_ready_parse {
29 	bool wmi_svc_bitmap_done;
30 };
31 
32 struct wmi_tlv_dma_ring_caps_parse {
33 	struct wmi_dma_ring_capabilities *dma_ring_caps;
34 	u32 n_dma_ring_caps;
35 };
36 
37 struct 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 
59 struct 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 
64 struct wmi_tlv_rdy_parse {
65 	u32 num_extra_mac_addr;
66 };
67 
68 struct 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 
78 struct 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 
86 struct 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 
92 static 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 
162 static 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 
173 static int
174 ath11k_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 
223 static 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 
234 static 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 
241 const 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 
260 static 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 
287 err_pull:
288 	skb_pull(skb, sizeof(struct wmi_cmd_hdr));
289 	return ret;
290 }
291 
292 int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
293 			u32 cmd_id)
294 {
295 	struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab;
296 	int ret = -EOPNOTSUPP;
297 	struct ath11k_base *ab = wmi_sc->ab;
298 
299 	might_sleep();
300 
301 	if (ab->hw_params.credit_flow) {
302 		wait_event_timeout(wmi_sc->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_sc->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_sc->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_sc->ab, "wmi command %d timeout\n", cmd_id);
325 
326 	if (ret == -ENOBUFS)
327 		ath11k_warn(wmi_sc->ab, "ce desc not available for wmi command %d\n",
328 			    cmd_id);
329 
330 	return ret;
331 }
332 
333 static 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(&param->ppet, &ev->ppet, sizeof(param->ppet));
349 
350 	return 0;
351 }
352 
353 static int
354 ath11k_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 
480 static int
481 ath11k_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 
512 static 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  */
549 static 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 
562 static 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 
596 static 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 
614 struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len)
615 {
616 	struct sk_buff *skb;
617 	struct ath11k_base *ab = wmi_sc->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 
634 static 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 
648 int 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 
700 int 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 
780 int 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 
807 int 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 
835 int 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 
863 static 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 
917 int 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 
1008 int 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 
1062 int 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 
1095 int 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 
1127 int 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 
1167 int 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 
1200 int 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 
1235 int 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 
1278 int
1279 ath11k_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 
1315 int 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 
1347 int 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 
1378 int 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 
1410 int 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  */
1443 int 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 
1477 int 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 
1512 int 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 
1546 int 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 
1578 int 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 
1612 int 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 
1645 int 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 
1673 int 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 
1707 int 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 
1778 int 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 
1830 static inline void
1831 ath11k_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 
1914 int 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, &param->peer_he_cap_phyinfo,
1977 	       sizeof(param->peer_he_cap_phyinfo));
1978 	memcpy(&cmd->peer_ppet, &param->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 
2075 void 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 
2116 static inline void
2117 ath11k_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 
2193 int 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 = (u32 *)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(&params->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 
2382 int 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 
2432 int 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 
2556 int 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 = &param->ac_be;
2582 			break;
2583 		case WME_AC_BK:
2584 			wmi_wmm_arg = &param->ac_bk;
2585 			break;
2586 		case WME_AC_VI:
2587 			wmi_wmm_arg = &param->ac_vi;
2588 			break;
2589 		case WME_AC_VO:
2590 			wmi_wmm_arg = &param->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 
2627 int 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 
2661 int 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 
2697 int 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 
2733 int 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 
2768 int 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 
2801 int 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 
2851 int
2852 ath11k_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 
2906 err:
2907 	dev_kfree_skb(skb);
2908 	return ret;
2909 }
2910 
2911 int 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, &param->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 
2947 int
2948 ath11k_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 
3011 int 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 
3048 int 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 
3080 int 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 
3112 int 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 
3142 void 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 
3168 int 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 
3218 int
3219 ath11k_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 
3252 int 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 
3306 int 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 
3345 int 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 
3385 int 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 
3428 int
3429 ath11k_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 
3467 int
3468 ath11k_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 
3505 int
3506 ath11k_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 
3544 int
3545 ath11k_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 
3583 int
3584 ath11k_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 
3622 int
3623 ath11k_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 
3661 int
3662 ath11k_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 
3700 int
3701 ath11k_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 
3746 int 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 
3782 int 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 
3829 int 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 
3886 int 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 
3925 static void
3926 ath11k_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 
3973 exit:
3974 	kfree(tb);
3975 	rcu_read_unlock();
3976 }
3977 
3978 static void
3979 ath11k_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 
4010 static void
4011 ath11k_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 
4081 static 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 = (struct wmi_pdev_set_hw_mode_cmd_param *)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 = (void *)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 
4198 int 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;
4228 err:
4229 	dev_kfree_skb(skb);
4230 	return ret;
4231 }
4232 
4233 int 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 
4245 int 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 
4257 int 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 
4292 int ath11k_wmi_cmd_init(struct ath11k_base *ab)
4293 {
4294 	struct ath11k_wmi_base *wmi_sc = &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_sc->wlan_resource_config, &config, sizeof(config));
4308 
4309 	init_param.res_cfg = &wmi_sc->wlan_resource_config;
4310 	init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
4311 	init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
4312 	init_param.mem_chunks = wmi_sc->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_sc->wmi[0], &init_param);
4321 }
4322 
4323 int 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;
4354 err:
4355 	dev_kfree_skb(skb);
4356 	return ret;
4357 }
4358 
4359 int 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;
4392 err:
4393 	dev_kfree_skb(skb);
4394 	return ret;
4395 }
4396 
4397 int 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;
4438 err:
4439 	dev_kfree_skb(skb);
4440 	return ret;
4441 }
4442 
4443 static 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 
4459 static 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 
4475 static 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 
4525 static 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, &param);
4549 	if (ret) {
4550 		ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
4551 		return;
4552 	}
4553 }
4554 
4555 static 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 
4582 static 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 
4623 static 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 
4648 static 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 
4664 static 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 						      &reg_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 		       &reg_cap, sizeof(reg_cap));
4695 	}
4696 	return 0;
4697 }
4698 
4699 static 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 
4755 static 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 
4768 static 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 
4785 static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
4786 {
4787 	kfree(ab->db_caps);
4788 	ab->db_caps = NULL;
4789 }
4790 
4791 static 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 
4839 free_dir_buff:
4840 	ath11k_wmi_free_dbring_caps(ab);
4841 	return ret;
4842 }
4843 
4844 static 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 
4922 static 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 
4944 err:
4945 	ath11k_wmi_free_dbring_caps(ab);
4946 	return ret;
4947 }
4948 
4949 static 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 
4974 static 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 
4994 err:
4995 	ath11k_wmi_free_dbring_caps(ab);
4996 	return ret;
4997 }
4998 
4999 static 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 
5036 static 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 
5056 static 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 
5093 static 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 
5206 static 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 
5248 static u8
5249 ath11k_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 
5266 static 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 dsf %d BW: min_2ghz %d max_2ghz %d min_5ghz %d max_5ghz %d",
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 
5448 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5449 		   "num_2ghz_reg_rules %d num_5ghz_reg_rules %d",
5450 		   num_2ghz_reg_rules, num_5ghz_reg_rules);
5451 
5452 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5453 		   "num_6ghz_reg_rules_ap_lpi: %d num_6ghz_reg_rules_ap_sp: %d num_6ghz_reg_rules_ap_vlp: %d",
5454 		   num_6ghz_reg_rules_ap[WMI_REG_INDOOR_AP],
5455 		   num_6ghz_reg_rules_ap[WMI_REG_STANDARD_POWER_AP],
5456 		   num_6ghz_reg_rules_ap[WMI_REG_VERY_LOW_POWER_AP]);
5457 
5458 	j = WMI_REG_DEFAULT_CLIENT;
5459 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5460 		   "6 GHz Regular client: num_6ghz_reg_rules_lpi: %d num_6ghz_reg_rules_sp: %d num_6ghz_reg_rules_vlp: %d",
5461 		   num_6ghz_client[WMI_REG_INDOOR_AP][j],
5462 		   num_6ghz_client[WMI_REG_STANDARD_POWER_AP][j],
5463 		   num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][j]);
5464 
5465 	j = WMI_REG_SUBORDINATE_CLIENT;
5466 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5467 		   "6 GHz Subordinate client: num_6ghz_reg_rules_lpi: %d num_6ghz_reg_rules_sp: %d num_6ghz_reg_rules_vlp: %d",
5468 		   num_6ghz_client[WMI_REG_INDOOR_AP][j],
5469 		   num_6ghz_client[WMI_REG_STANDARD_POWER_AP][j],
5470 		   num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][j]);
5471 
5472 	ext_wmi_reg_rule =
5473 		(struct wmi_regulatory_ext_rule *)((u8 *)ev + sizeof(*ev) +
5474 						   sizeof(struct wmi_tlv));
5475 	if (num_2ghz_reg_rules) {
5476 		reg_info->reg_rules_2ghz_ptr =
5477 			create_ext_reg_rules_from_wmi(num_2ghz_reg_rules,
5478 						      ext_wmi_reg_rule);
5479 
5480 		if (!reg_info->reg_rules_2ghz_ptr) {
5481 			kfree(tb);
5482 			ath11k_warn(ab, "Unable to Allocate memory for 2 GHz rules\n");
5483 			return -ENOMEM;
5484 		}
5485 
5486 		ath11k_print_reg_rule(ab, "2 GHz",
5487 				      num_2ghz_reg_rules,
5488 				      reg_info->reg_rules_2ghz_ptr);
5489 	}
5490 
5491 	ext_wmi_reg_rule += num_2ghz_reg_rules;
5492 
5493 	/* Firmware might include 6 GHz reg rule in 5 GHz rule list
5494 	 * for few countries along with separate 6 GHz rule.
5495 	 * Having same 6 GHz reg rule in 5 GHz and 6 GHz rules list
5496 	 * causes intersect check to be true, and same rules will be
5497 	 * shown multiple times in iw cmd.
5498 	 * Hence, avoid parsing 6 GHz rule from 5 GHz reg rule list
5499 	 */
5500 	num_invalid_5ghz_ext_rules =
5501 		ath11k_invalid_5ghz_reg_ext_rules_from_wmi(num_5ghz_reg_rules,
5502 							   ext_wmi_reg_rule);
5503 
5504 	if (num_invalid_5ghz_ext_rules) {
5505 		ath11k_dbg(ab, ATH11K_DBG_WMI,
5506 			   "CC: %s 5 GHz reg rules number %d from fw, %d number of invalid 5 GHz rules",
5507 			   reg_info->alpha2, reg_info->num_5ghz_reg_rules,
5508 			   num_invalid_5ghz_ext_rules);
5509 
5510 		num_5ghz_reg_rules = num_5ghz_reg_rules - num_invalid_5ghz_ext_rules;
5511 		reg_info->num_5ghz_reg_rules = num_5ghz_reg_rules;
5512 	}
5513 
5514 	if (num_5ghz_reg_rules) {
5515 		reg_info->reg_rules_5ghz_ptr =
5516 			create_ext_reg_rules_from_wmi(num_5ghz_reg_rules,
5517 						      ext_wmi_reg_rule);
5518 
5519 		if (!reg_info->reg_rules_5ghz_ptr) {
5520 			kfree(tb);
5521 			ath11k_warn(ab, "Unable to Allocate memory for 5 GHz rules\n");
5522 			return -ENOMEM;
5523 		}
5524 
5525 		ath11k_print_reg_rule(ab, "5 GHz",
5526 				      num_5ghz_reg_rules,
5527 				      reg_info->reg_rules_5ghz_ptr);
5528 	}
5529 
5530 	/* We have adjusted the number of 5 GHz reg rules above. But still those
5531 	 * many rules needs to be adjusted in ext_wmi_reg_rule.
5532 	 *
5533 	 * NOTE: num_invalid_5ghz_ext_rules will be 0 for rest other cases.
5534 	 */
5535 	ext_wmi_reg_rule += (num_5ghz_reg_rules + num_invalid_5ghz_ext_rules);
5536 
5537 	for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++) {
5538 		reg_info->reg_rules_6ghz_ap_ptr[i] =
5539 			create_ext_reg_rules_from_wmi(num_6ghz_reg_rules_ap[i],
5540 						      ext_wmi_reg_rule);
5541 
5542 		if (!reg_info->reg_rules_6ghz_ap_ptr[i]) {
5543 			kfree(tb);
5544 			ath11k_warn(ab, "Unable to Allocate memory for 6 GHz AP rules\n");
5545 			return -ENOMEM;
5546 		}
5547 
5548 		ath11k_print_reg_rule(ab, ath11k_6ghz_ap_type_to_str(i),
5549 				      num_6ghz_reg_rules_ap[i],
5550 				      reg_info->reg_rules_6ghz_ap_ptr[i]);
5551 
5552 		ext_wmi_reg_rule += num_6ghz_reg_rules_ap[i];
5553 	}
5554 
5555 	for (j = 0; j < WMI_REG_CURRENT_MAX_AP_TYPE; j++) {
5556 		ath11k_dbg(ab, ATH11K_DBG_WMI,
5557 			   "6 GHz AP type %s", ath11k_6ghz_ap_type_to_str(j));
5558 
5559 		for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5560 			reg_info->reg_rules_6ghz_client_ptr[j][i] =
5561 				create_ext_reg_rules_from_wmi(num_6ghz_client[j][i],
5562 							      ext_wmi_reg_rule);
5563 
5564 			if (!reg_info->reg_rules_6ghz_client_ptr[j][i]) {
5565 				kfree(tb);
5566 				ath11k_warn(ab, "Unable to Allocate memory for 6 GHz client rules\n");
5567 				return -ENOMEM;
5568 			}
5569 
5570 			ath11k_print_reg_rule(ab,
5571 					      ath11k_6ghz_client_type_to_str(i),
5572 					      num_6ghz_client[j][i],
5573 					      reg_info->reg_rules_6ghz_client_ptr[j][i]);
5574 
5575 			ext_wmi_reg_rule += num_6ghz_client[j][i];
5576 		}
5577 	}
5578 
5579 	reg_info->client_type = ev->client_type;
5580 	reg_info->rnr_tpe_usable = ev->rnr_tpe_usable;
5581 	reg_info->unspecified_ap_usable =
5582 			ev->unspecified_ap_usable;
5583 	reg_info->domain_code_6ghz_ap[WMI_REG_INDOOR_AP] =
5584 			ev->domain_code_6ghz_ap_lpi;
5585 	reg_info->domain_code_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5586 			ev->domain_code_6ghz_ap_sp;
5587 	reg_info->domain_code_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5588 			ev->domain_code_6ghz_ap_vlp;
5589 
5590 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5591 		   "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",
5592 		   ath11k_6ghz_client_type_to_str(reg_info->client_type),
5593 		   reg_info->rnr_tpe_usable,
5594 		   reg_info->unspecified_ap_usable,
5595 		   ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_lpi),
5596 		   ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_sp),
5597 		   ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_vlp));
5598 
5599 	for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
5600 		reg_info->domain_code_6ghz_client[WMI_REG_INDOOR_AP][i] =
5601 				ev->domain_code_6ghz_client_lpi[i];
5602 		reg_info->domain_code_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5603 				ev->domain_code_6ghz_client_sp[i];
5604 		reg_info->domain_code_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5605 				ev->domain_code_6ghz_client_vlp[i];
5606 
5607 		ath11k_dbg(ab, ATH11K_DBG_WMI,
5608 			   "6 GHz client type %s client sub domain: lpi %s, sp %s, vlp %s\n",
5609 			   ath11k_6ghz_client_type_to_str(i),
5610 			   ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_lpi[i]),
5611 			   ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_sp[i]),
5612 			   ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_vlp[i])
5613 			  );
5614 	}
5615 
5616 	reg_info->domain_code_6ghz_super_id = ev->domain_code_6ghz_super_id;
5617 
5618 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5619 		   "6 GHz client_type %s 6 GHz super domain %s",
5620 		   ath11k_6ghz_client_type_to_str(reg_info->client_type),
5621 		   ath11k_super_reg_6ghz_to_str(reg_info->domain_code_6ghz_super_id));
5622 
5623 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory ext channel list\n");
5624 
5625 	kfree(tb);
5626 	return 0;
5627 }
5628 
5629 static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
5630 					struct wmi_peer_delete_resp_event *peer_del_resp)
5631 {
5632 	const void **tb;
5633 	const struct wmi_peer_delete_resp_event *ev;
5634 	int ret;
5635 
5636 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5637 	if (IS_ERR(tb)) {
5638 		ret = PTR_ERR(tb);
5639 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5640 		return ret;
5641 	}
5642 
5643 	ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
5644 	if (!ev) {
5645 		ath11k_warn(ab, "failed to fetch peer delete resp ev");
5646 		kfree(tb);
5647 		return -EPROTO;
5648 	}
5649 
5650 	memset(peer_del_resp, 0, sizeof(*peer_del_resp));
5651 
5652 	peer_del_resp->vdev_id = ev->vdev_id;
5653 	ether_addr_copy(peer_del_resp->peer_macaddr.addr,
5654 			ev->peer_macaddr.addr);
5655 
5656 	kfree(tb);
5657 	return 0;
5658 }
5659 
5660 static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab,
5661 					struct sk_buff *skb,
5662 					u32 *vdev_id)
5663 {
5664 	const void **tb;
5665 	const struct wmi_vdev_delete_resp_event *ev;
5666 	int ret;
5667 
5668 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5669 	if (IS_ERR(tb)) {
5670 		ret = PTR_ERR(tb);
5671 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5672 		return ret;
5673 	}
5674 
5675 	ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT];
5676 	if (!ev) {
5677 		ath11k_warn(ab, "failed to fetch vdev delete resp ev");
5678 		kfree(tb);
5679 		return -EPROTO;
5680 	}
5681 
5682 	*vdev_id = ev->vdev_id;
5683 
5684 	kfree(tb);
5685 	return 0;
5686 }
5687 
5688 static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
5689 					u32 len, u32 *vdev_id,
5690 					u32 *tx_status)
5691 {
5692 	const void **tb;
5693 	const struct wmi_bcn_tx_status_event *ev;
5694 	int ret;
5695 
5696 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5697 	if (IS_ERR(tb)) {
5698 		ret = PTR_ERR(tb);
5699 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5700 		return ret;
5701 	}
5702 
5703 	ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
5704 	if (!ev) {
5705 		ath11k_warn(ab, "failed to fetch bcn tx status ev");
5706 		kfree(tb);
5707 		return -EPROTO;
5708 	}
5709 
5710 	*vdev_id   = ev->vdev_id;
5711 	*tx_status = ev->tx_status;
5712 
5713 	kfree(tb);
5714 	return 0;
5715 }
5716 
5717 static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5718 					      u32 *vdev_id)
5719 {
5720 	const void **tb;
5721 	const struct wmi_vdev_stopped_event *ev;
5722 	int ret;
5723 
5724 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5725 	if (IS_ERR(tb)) {
5726 		ret = PTR_ERR(tb);
5727 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5728 		return ret;
5729 	}
5730 
5731 	ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
5732 	if (!ev) {
5733 		ath11k_warn(ab, "failed to fetch vdev stop ev");
5734 		kfree(tb);
5735 		return -EPROTO;
5736 	}
5737 
5738 	*vdev_id =  ev->vdev_id;
5739 
5740 	kfree(tb);
5741 	return 0;
5742 }
5743 
5744 static int ath11k_wmi_tlv_mgmt_rx_parse(struct ath11k_base *ab,
5745 					u16 tag, u16 len,
5746 					const void *ptr, void *data)
5747 {
5748 	struct wmi_tlv_mgmt_rx_parse *parse = data;
5749 
5750 	switch (tag) {
5751 	case WMI_TAG_MGMT_RX_HDR:
5752 		parse->fixed = ptr;
5753 		break;
5754 	case WMI_TAG_ARRAY_BYTE:
5755 		if (!parse->frame_buf_done) {
5756 			parse->frame_buf = ptr;
5757 			parse->frame_buf_done = true;
5758 		}
5759 		break;
5760 	}
5761 	return 0;
5762 }
5763 
5764 static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
5765 					  struct sk_buff *skb,
5766 					  struct mgmt_rx_event_params *hdr)
5767 {
5768 	struct wmi_tlv_mgmt_rx_parse parse = { };
5769 	const struct wmi_mgmt_rx_hdr *ev;
5770 	const u8 *frame;
5771 	int ret;
5772 
5773 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
5774 				  ath11k_wmi_tlv_mgmt_rx_parse,
5775 				  &parse);
5776 	if (ret) {
5777 		ath11k_warn(ab, "failed to parse mgmt rx tlv %d\n",
5778 			    ret);
5779 		return ret;
5780 	}
5781 
5782 	ev = parse.fixed;
5783 	frame = parse.frame_buf;
5784 
5785 	if (!ev || !frame) {
5786 		ath11k_warn(ab, "failed to fetch mgmt rx hdr");
5787 		return -EPROTO;
5788 	}
5789 
5790 	hdr->pdev_id =  ev->pdev_id;
5791 	hdr->chan_freq = ev->chan_freq;
5792 	hdr->channel =  ev->channel;
5793 	hdr->snr =  ev->snr;
5794 	hdr->rate =  ev->rate;
5795 	hdr->phy_mode =  ev->phy_mode;
5796 	hdr->buf_len =  ev->buf_len;
5797 	hdr->status =  ev->status;
5798 	hdr->flags =  ev->flags;
5799 	hdr->rssi =  ev->rssi;
5800 	hdr->tsf_delta =  ev->tsf_delta;
5801 	memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
5802 
5803 	if (skb->len < (frame - skb->data) + hdr->buf_len) {
5804 		ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
5805 		return -EPROTO;
5806 	}
5807 
5808 	/* shift the sk_buff to point to `frame` */
5809 	skb_trim(skb, 0);
5810 	skb_put(skb, frame - skb->data);
5811 	skb_pull(skb, frame - skb->data);
5812 	skb_put(skb, hdr->buf_len);
5813 
5814 	ath11k_ce_byte_swap(skb->data, hdr->buf_len);
5815 
5816 	return 0;
5817 }
5818 
5819 static int wmi_process_mgmt_tx_comp(struct ath11k *ar,
5820 				    struct wmi_mgmt_tx_compl_event *tx_compl_param)
5821 {
5822 	struct sk_buff *msdu;
5823 	struct ieee80211_tx_info *info;
5824 	struct ath11k_skb_cb *skb_cb;
5825 	int num_mgmt;
5826 
5827 	spin_lock_bh(&ar->txmgmt_idr_lock);
5828 	msdu = idr_find(&ar->txmgmt_idr, tx_compl_param->desc_id);
5829 
5830 	if (!msdu) {
5831 		ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
5832 			    tx_compl_param->desc_id);
5833 		spin_unlock_bh(&ar->txmgmt_idr_lock);
5834 		return -ENOENT;
5835 	}
5836 
5837 	idr_remove(&ar->txmgmt_idr, tx_compl_param->desc_id);
5838 	spin_unlock_bh(&ar->txmgmt_idr_lock);
5839 
5840 	skb_cb = ATH11K_SKB_CB(msdu);
5841 	dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
5842 
5843 	info = IEEE80211_SKB_CB(msdu);
5844 	if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) &&
5845 	    !tx_compl_param->status) {
5846 		info->flags |= IEEE80211_TX_STAT_ACK;
5847 		if (test_bit(WMI_TLV_SERVICE_TX_DATA_MGMT_ACK_RSSI,
5848 			     ar->ab->wmi_ab.svc_map))
5849 			info->status.ack_signal = tx_compl_param->ack_rssi;
5850 	}
5851 
5852 	ieee80211_tx_status_irqsafe(ar->hw, msdu);
5853 
5854 	num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5855 
5856 	/* WARN when we received this event without doing any mgmt tx */
5857 	if (num_mgmt < 0)
5858 		WARN_ON_ONCE(1);
5859 
5860 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5861 		   "mgmt tx comp pending %d desc id %d\n",
5862 		   num_mgmt, tx_compl_param->desc_id);
5863 
5864 	if (!num_mgmt)
5865 		wake_up(&ar->txmgmt_empty_waitq);
5866 
5867 	return 0;
5868 }
5869 
5870 static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
5871 					       struct sk_buff *skb,
5872 					       struct wmi_mgmt_tx_compl_event *param)
5873 {
5874 	const void **tb;
5875 	const struct wmi_mgmt_tx_compl_event *ev;
5876 	int ret;
5877 
5878 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5879 	if (IS_ERR(tb)) {
5880 		ret = PTR_ERR(tb);
5881 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5882 		return ret;
5883 	}
5884 
5885 	ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
5886 	if (!ev) {
5887 		ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
5888 		kfree(tb);
5889 		return -EPROTO;
5890 	}
5891 
5892 	param->pdev_id = ev->pdev_id;
5893 	param->desc_id = ev->desc_id;
5894 	param->status = ev->status;
5895 	param->ack_rssi = ev->ack_rssi;
5896 
5897 	kfree(tb);
5898 	return 0;
5899 }
5900 
5901 static void ath11k_wmi_event_scan_started(struct ath11k *ar)
5902 {
5903 	lockdep_assert_held(&ar->data_lock);
5904 
5905 	switch (ar->scan.state) {
5906 	case ATH11K_SCAN_IDLE:
5907 	case ATH11K_SCAN_RUNNING:
5908 	case ATH11K_SCAN_ABORTING:
5909 		ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
5910 			    ath11k_scan_state_str(ar->scan.state),
5911 			    ar->scan.state);
5912 		break;
5913 	case ATH11K_SCAN_STARTING:
5914 		ar->scan.state = ATH11K_SCAN_RUNNING;
5915 		if (ar->scan.is_roc)
5916 			ieee80211_ready_on_channel(ar->hw);
5917 		complete(&ar->scan.started);
5918 		break;
5919 	}
5920 }
5921 
5922 static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
5923 {
5924 	lockdep_assert_held(&ar->data_lock);
5925 
5926 	switch (ar->scan.state) {
5927 	case ATH11K_SCAN_IDLE:
5928 	case ATH11K_SCAN_RUNNING:
5929 	case ATH11K_SCAN_ABORTING:
5930 		ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
5931 			    ath11k_scan_state_str(ar->scan.state),
5932 			    ar->scan.state);
5933 		break;
5934 	case ATH11K_SCAN_STARTING:
5935 		complete(&ar->scan.started);
5936 		__ath11k_mac_scan_finish(ar);
5937 		break;
5938 	}
5939 }
5940 
5941 static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
5942 {
5943 	lockdep_assert_held(&ar->data_lock);
5944 
5945 	switch (ar->scan.state) {
5946 	case ATH11K_SCAN_IDLE:
5947 	case ATH11K_SCAN_STARTING:
5948 		/* One suspected reason scan can be completed while starting is
5949 		 * if firmware fails to deliver all scan events to the host,
5950 		 * e.g. when transport pipe is full. This has been observed
5951 		 * with spectral scan phyerr events starving wmi transport
5952 		 * pipe. In such case the "scan completed" event should be (and
5953 		 * is) ignored by the host as it may be just firmware's scan
5954 		 * state machine recovering.
5955 		 */
5956 		ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
5957 			    ath11k_scan_state_str(ar->scan.state),
5958 			    ar->scan.state);
5959 		break;
5960 	case ATH11K_SCAN_RUNNING:
5961 	case ATH11K_SCAN_ABORTING:
5962 		__ath11k_mac_scan_finish(ar);
5963 		break;
5964 	}
5965 }
5966 
5967 static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
5968 {
5969 	lockdep_assert_held(&ar->data_lock);
5970 
5971 	switch (ar->scan.state) {
5972 	case ATH11K_SCAN_IDLE:
5973 	case ATH11K_SCAN_STARTING:
5974 		ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
5975 			    ath11k_scan_state_str(ar->scan.state),
5976 			    ar->scan.state);
5977 		break;
5978 	case ATH11K_SCAN_RUNNING:
5979 	case ATH11K_SCAN_ABORTING:
5980 		ar->scan_channel = NULL;
5981 		break;
5982 	}
5983 }
5984 
5985 static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
5986 {
5987 	lockdep_assert_held(&ar->data_lock);
5988 
5989 	switch (ar->scan.state) {
5990 	case ATH11K_SCAN_IDLE:
5991 	case ATH11K_SCAN_STARTING:
5992 		ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
5993 			    ath11k_scan_state_str(ar->scan.state),
5994 			    ar->scan.state);
5995 		break;
5996 	case ATH11K_SCAN_RUNNING:
5997 	case ATH11K_SCAN_ABORTING:
5998 		ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
5999 		if (ar->scan.is_roc && ar->scan.roc_freq == freq)
6000 			complete(&ar->scan.on_channel);
6001 		break;
6002 	}
6003 }
6004 
6005 static const char *
6006 ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
6007 			       enum wmi_scan_completion_reason reason)
6008 {
6009 	switch (type) {
6010 	case WMI_SCAN_EVENT_STARTED:
6011 		return "started";
6012 	case WMI_SCAN_EVENT_COMPLETED:
6013 		switch (reason) {
6014 		case WMI_SCAN_REASON_COMPLETED:
6015 			return "completed";
6016 		case WMI_SCAN_REASON_CANCELLED:
6017 			return "completed [cancelled]";
6018 		case WMI_SCAN_REASON_PREEMPTED:
6019 			return "completed [preempted]";
6020 		case WMI_SCAN_REASON_TIMEDOUT:
6021 			return "completed [timedout]";
6022 		case WMI_SCAN_REASON_INTERNAL_FAILURE:
6023 			return "completed [internal err]";
6024 		case WMI_SCAN_REASON_MAX:
6025 			break;
6026 		}
6027 		return "completed [unknown]";
6028 	case WMI_SCAN_EVENT_BSS_CHANNEL:
6029 		return "bss channel";
6030 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
6031 		return "foreign channel";
6032 	case WMI_SCAN_EVENT_DEQUEUED:
6033 		return "dequeued";
6034 	case WMI_SCAN_EVENT_PREEMPTED:
6035 		return "preempted";
6036 	case WMI_SCAN_EVENT_START_FAILED:
6037 		return "start failed";
6038 	case WMI_SCAN_EVENT_RESTARTED:
6039 		return "restarted";
6040 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
6041 		return "foreign channel exit";
6042 	default:
6043 		return "unknown";
6044 	}
6045 }
6046 
6047 static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
6048 			       struct wmi_scan_event *scan_evt_param)
6049 {
6050 	const void **tb;
6051 	const struct wmi_scan_event *ev;
6052 	int ret;
6053 
6054 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6055 	if (IS_ERR(tb)) {
6056 		ret = PTR_ERR(tb);
6057 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6058 		return ret;
6059 	}
6060 
6061 	ev = tb[WMI_TAG_SCAN_EVENT];
6062 	if (!ev) {
6063 		ath11k_warn(ab, "failed to fetch scan ev");
6064 		kfree(tb);
6065 		return -EPROTO;
6066 	}
6067 
6068 	scan_evt_param->event_type = ev->event_type;
6069 	scan_evt_param->reason = ev->reason;
6070 	scan_evt_param->channel_freq = ev->channel_freq;
6071 	scan_evt_param->scan_req_id = ev->scan_req_id;
6072 	scan_evt_param->scan_id = ev->scan_id;
6073 	scan_evt_param->vdev_id = ev->vdev_id;
6074 	scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
6075 
6076 	kfree(tb);
6077 	return 0;
6078 }
6079 
6080 static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
6081 					   struct wmi_peer_sta_kickout_arg *arg)
6082 {
6083 	const void **tb;
6084 	const struct wmi_peer_sta_kickout_event *ev;
6085 	int ret;
6086 
6087 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6088 	if (IS_ERR(tb)) {
6089 		ret = PTR_ERR(tb);
6090 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6091 		return ret;
6092 	}
6093 
6094 	ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
6095 	if (!ev) {
6096 		ath11k_warn(ab, "failed to fetch peer sta kickout ev");
6097 		kfree(tb);
6098 		return -EPROTO;
6099 	}
6100 
6101 	arg->mac_addr = ev->peer_macaddr.addr;
6102 
6103 	kfree(tb);
6104 	return 0;
6105 }
6106 
6107 static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
6108 			       struct wmi_roam_event *roam_ev)
6109 {
6110 	const void **tb;
6111 	const struct wmi_roam_event *ev;
6112 	int ret;
6113 
6114 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6115 	if (IS_ERR(tb)) {
6116 		ret = PTR_ERR(tb);
6117 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6118 		return ret;
6119 	}
6120 
6121 	ev = tb[WMI_TAG_ROAM_EVENT];
6122 	if (!ev) {
6123 		ath11k_warn(ab, "failed to fetch roam ev");
6124 		kfree(tb);
6125 		return -EPROTO;
6126 	}
6127 
6128 	roam_ev->vdev_id = ev->vdev_id;
6129 	roam_ev->reason = ev->reason;
6130 	roam_ev->rssi = ev->rssi;
6131 
6132 	kfree(tb);
6133 	return 0;
6134 }
6135 
6136 static int freq_to_idx(struct ath11k *ar, int freq)
6137 {
6138 	struct ieee80211_supported_band *sband;
6139 	int band, ch, idx = 0;
6140 
6141 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
6142 		sband = ar->hw->wiphy->bands[band];
6143 		if (!sband)
6144 			continue;
6145 
6146 		for (ch = 0; ch < sband->n_channels; ch++, idx++)
6147 			if (sband->channels[ch].center_freq == freq)
6148 				goto exit;
6149 	}
6150 
6151 exit:
6152 	return idx;
6153 }
6154 
6155 static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
6156 				    u32 len, struct wmi_chan_info_event *ch_info_ev)
6157 {
6158 	const void **tb;
6159 	const struct wmi_chan_info_event *ev;
6160 	int ret;
6161 
6162 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
6163 	if (IS_ERR(tb)) {
6164 		ret = PTR_ERR(tb);
6165 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6166 		return ret;
6167 	}
6168 
6169 	ev = tb[WMI_TAG_CHAN_INFO_EVENT];
6170 	if (!ev) {
6171 		ath11k_warn(ab, "failed to fetch chan info ev");
6172 		kfree(tb);
6173 		return -EPROTO;
6174 	}
6175 
6176 	ch_info_ev->err_code = ev->err_code;
6177 	ch_info_ev->freq = ev->freq;
6178 	ch_info_ev->cmd_flags = ev->cmd_flags;
6179 	ch_info_ev->noise_floor = ev->noise_floor;
6180 	ch_info_ev->rx_clear_count = ev->rx_clear_count;
6181 	ch_info_ev->cycle_count = ev->cycle_count;
6182 	ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
6183 	ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
6184 	ch_info_ev->rx_frame_count = ev->rx_frame_count;
6185 	ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
6186 	ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
6187 	ch_info_ev->vdev_id = ev->vdev_id;
6188 
6189 	kfree(tb);
6190 	return 0;
6191 }
6192 
6193 static int
6194 ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
6195 				  struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
6196 {
6197 	const void **tb;
6198 	const struct wmi_pdev_bss_chan_info_event *ev;
6199 	int ret;
6200 
6201 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6202 	if (IS_ERR(tb)) {
6203 		ret = PTR_ERR(tb);
6204 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6205 		return ret;
6206 	}
6207 
6208 	ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
6209 	if (!ev) {
6210 		ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
6211 		kfree(tb);
6212 		return -EPROTO;
6213 	}
6214 
6215 	bss_ch_info_ev->pdev_id = ev->pdev_id;
6216 	bss_ch_info_ev->freq = ev->freq;
6217 	bss_ch_info_ev->noise_floor = ev->noise_floor;
6218 	bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
6219 	bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
6220 	bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
6221 	bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
6222 	bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
6223 	bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
6224 	bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
6225 	bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
6226 	bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
6227 	bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
6228 
6229 	kfree(tb);
6230 	return 0;
6231 }
6232 
6233 static int
6234 ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
6235 				      struct wmi_vdev_install_key_complete_arg *arg)
6236 {
6237 	const void **tb;
6238 	const struct wmi_vdev_install_key_compl_event *ev;
6239 	int ret;
6240 
6241 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6242 	if (IS_ERR(tb)) {
6243 		ret = PTR_ERR(tb);
6244 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6245 		return ret;
6246 	}
6247 
6248 	ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
6249 	if (!ev) {
6250 		ath11k_warn(ab, "failed to fetch vdev install key compl ev");
6251 		kfree(tb);
6252 		return -EPROTO;
6253 	}
6254 
6255 	arg->vdev_id = ev->vdev_id;
6256 	arg->macaddr = ev->peer_macaddr.addr;
6257 	arg->key_idx = ev->key_idx;
6258 	arg->key_flags = ev->key_flags;
6259 	arg->status = ev->status;
6260 
6261 	kfree(tb);
6262 	return 0;
6263 }
6264 
6265 static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
6266 					  struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
6267 {
6268 	const void **tb;
6269 	const struct wmi_peer_assoc_conf_event *ev;
6270 	int ret;
6271 
6272 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6273 	if (IS_ERR(tb)) {
6274 		ret = PTR_ERR(tb);
6275 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6276 		return ret;
6277 	}
6278 
6279 	ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
6280 	if (!ev) {
6281 		ath11k_warn(ab, "failed to fetch peer assoc conf ev");
6282 		kfree(tb);
6283 		return -EPROTO;
6284 	}
6285 
6286 	peer_assoc_conf->vdev_id = ev->vdev_id;
6287 	peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
6288 
6289 	kfree(tb);
6290 	return 0;
6291 }
6292 
6293 static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
6294 					    struct ath11k_fw_stats_pdev *dst)
6295 {
6296 	dst->ch_noise_floor = src->chan_nf;
6297 	dst->tx_frame_count = src->tx_frame_count;
6298 	dst->rx_frame_count = src->rx_frame_count;
6299 	dst->rx_clear_count = src->rx_clear_count;
6300 	dst->cycle_count = src->cycle_count;
6301 	dst->phy_err_count = src->phy_err_count;
6302 	dst->chan_tx_power = src->chan_tx_pwr;
6303 }
6304 
6305 static void
6306 ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
6307 			      struct ath11k_fw_stats_pdev *dst)
6308 {
6309 	dst->comp_queued = src->comp_queued;
6310 	dst->comp_delivered = src->comp_delivered;
6311 	dst->msdu_enqued = src->msdu_enqued;
6312 	dst->mpdu_enqued = src->mpdu_enqued;
6313 	dst->wmm_drop = src->wmm_drop;
6314 	dst->local_enqued = src->local_enqued;
6315 	dst->local_freed = src->local_freed;
6316 	dst->hw_queued = src->hw_queued;
6317 	dst->hw_reaped = src->hw_reaped;
6318 	dst->underrun = src->underrun;
6319 	dst->hw_paused = src->hw_paused;
6320 	dst->tx_abort = src->tx_abort;
6321 	dst->mpdus_requeued = src->mpdus_requeued;
6322 	dst->tx_ko = src->tx_ko;
6323 	dst->tx_xretry = src->tx_xretry;
6324 	dst->data_rc = src->data_rc;
6325 	dst->self_triggers = src->self_triggers;
6326 	dst->sw_retry_failure = src->sw_retry_failure;
6327 	dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
6328 	dst->pdev_cont_xretry = src->pdev_cont_xretry;
6329 	dst->pdev_tx_timeout = src->pdev_tx_timeout;
6330 	dst->pdev_resets = src->pdev_resets;
6331 	dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
6332 	dst->phy_underrun = src->phy_underrun;
6333 	dst->txop_ovf = src->txop_ovf;
6334 	dst->seq_posted = src->seq_posted;
6335 	dst->seq_failed_queueing = src->seq_failed_queueing;
6336 	dst->seq_completed = src->seq_completed;
6337 	dst->seq_restarted = src->seq_restarted;
6338 	dst->mu_seq_posted = src->mu_seq_posted;
6339 	dst->mpdus_sw_flush = src->mpdus_sw_flush;
6340 	dst->mpdus_hw_filter = src->mpdus_hw_filter;
6341 	dst->mpdus_truncated = src->mpdus_truncated;
6342 	dst->mpdus_ack_failed = src->mpdus_ack_failed;
6343 	dst->mpdus_expired = src->mpdus_expired;
6344 }
6345 
6346 static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
6347 					  struct ath11k_fw_stats_pdev *dst)
6348 {
6349 	dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
6350 	dst->status_rcvd = src->status_rcvd;
6351 	dst->r0_frags = src->r0_frags;
6352 	dst->r1_frags = src->r1_frags;
6353 	dst->r2_frags = src->r2_frags;
6354 	dst->r3_frags = src->r3_frags;
6355 	dst->htt_msdus = src->htt_msdus;
6356 	dst->htt_mpdus = src->htt_mpdus;
6357 	dst->loc_msdus = src->loc_msdus;
6358 	dst->loc_mpdus = src->loc_mpdus;
6359 	dst->oversize_amsdu = src->oversize_amsdu;
6360 	dst->phy_errs = src->phy_errs;
6361 	dst->phy_err_drop = src->phy_err_drop;
6362 	dst->mpdu_errs = src->mpdu_errs;
6363 	dst->rx_ovfl_errs = src->rx_ovfl_errs;
6364 }
6365 
6366 static void
6367 ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
6368 			   struct ath11k_fw_stats_vdev *dst)
6369 {
6370 	int i;
6371 
6372 	dst->vdev_id = src->vdev_id;
6373 	dst->beacon_snr = src->beacon_snr;
6374 	dst->data_snr = src->data_snr;
6375 	dst->num_rx_frames = src->num_rx_frames;
6376 	dst->num_rts_fail = src->num_rts_fail;
6377 	dst->num_rts_success = src->num_rts_success;
6378 	dst->num_rx_err = src->num_rx_err;
6379 	dst->num_rx_discard = src->num_rx_discard;
6380 	dst->num_tx_not_acked = src->num_tx_not_acked;
6381 
6382 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
6383 		dst->num_tx_frames[i] = src->num_tx_frames[i];
6384 
6385 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
6386 		dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
6387 
6388 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
6389 		dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
6390 
6391 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
6392 		dst->tx_rate_history[i] = src->tx_rate_history[i];
6393 
6394 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
6395 		dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
6396 }
6397 
6398 static void
6399 ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
6400 			  struct ath11k_fw_stats_bcn *dst)
6401 {
6402 	dst->vdev_id = src->vdev_id;
6403 	dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
6404 	dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
6405 }
6406 
6407 static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
6408 					   u16 tag, u16 len,
6409 					   const void *ptr, void *data)
6410 {
6411 	struct wmi_tlv_fw_stats_parse *parse = data;
6412 	const struct wmi_stats_event *ev = parse->ev;
6413 	struct ath11k_fw_stats *stats = parse->stats;
6414 	struct ath11k *ar;
6415 	struct ath11k_vif *arvif;
6416 	struct ieee80211_sta *sta;
6417 	struct ath11k_sta *arsta;
6418 	const struct wmi_rssi_stats *stats_rssi = (const struct wmi_rssi_stats *)ptr;
6419 	int j, ret = 0;
6420 
6421 	if (tag != WMI_TAG_RSSI_STATS)
6422 		return -EPROTO;
6423 
6424 	rcu_read_lock();
6425 
6426 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6427 	stats->stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
6428 
6429 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6430 		   "stats vdev id %d mac %pM\n",
6431 		   stats_rssi->vdev_id, stats_rssi->peer_macaddr.addr);
6432 
6433 	arvif = ath11k_mac_get_arvif(ar, stats_rssi->vdev_id);
6434 	if (!arvif) {
6435 		ath11k_warn(ab, "not found vif for vdev id %d\n",
6436 			    stats_rssi->vdev_id);
6437 		ret = -EPROTO;
6438 		goto exit;
6439 	}
6440 
6441 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6442 		   "stats bssid %pM vif %p\n",
6443 		   arvif->bssid, arvif->vif);
6444 
6445 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
6446 					   arvif->bssid,
6447 					   NULL);
6448 	if (!sta) {
6449 		ath11k_dbg(ab, ATH11K_DBG_WMI,
6450 			   "not found station of bssid %pM for rssi chain\n",
6451 			   arvif->bssid);
6452 		goto exit;
6453 	}
6454 
6455 	arsta = (struct ath11k_sta *)sta->drv_priv;
6456 
6457 	BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
6458 		     ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
6459 
6460 	for (j = 0; j < ARRAY_SIZE(arsta->chain_signal); j++) {
6461 		arsta->chain_signal[j] = stats_rssi->rssi_avg_beacon[j];
6462 		ath11k_dbg(ab, ATH11K_DBG_WMI,
6463 			   "stats beacon rssi[%d] %d data rssi[%d] %d\n",
6464 			   j,
6465 			   stats_rssi->rssi_avg_beacon[j],
6466 			   j,
6467 			   stats_rssi->rssi_avg_data[j]);
6468 	}
6469 
6470 exit:
6471 	rcu_read_unlock();
6472 	return ret;
6473 }
6474 
6475 static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
6476 					      struct wmi_tlv_fw_stats_parse *parse,
6477 					      const void *ptr,
6478 					      u16 len)
6479 {
6480 	struct ath11k_fw_stats *stats = parse->stats;
6481 	const struct wmi_stats_event *ev = parse->ev;
6482 	struct ath11k *ar;
6483 	struct ath11k_vif *arvif;
6484 	struct ieee80211_sta *sta;
6485 	struct ath11k_sta *arsta;
6486 	int i, ret = 0;
6487 	const void *data = ptr;
6488 
6489 	if (!ev) {
6490 		ath11k_warn(ab, "failed to fetch update stats ev");
6491 		return -EPROTO;
6492 	}
6493 
6494 	stats->stats_id = 0;
6495 
6496 	rcu_read_lock();
6497 
6498 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6499 
6500 	for (i = 0; i < ev->num_pdev_stats; i++) {
6501 		const struct wmi_pdev_stats *src;
6502 		struct ath11k_fw_stats_pdev *dst;
6503 
6504 		src = data;
6505 		if (len < sizeof(*src)) {
6506 			ret = -EPROTO;
6507 			goto exit;
6508 		}
6509 
6510 		stats->stats_id = WMI_REQUEST_PDEV_STAT;
6511 
6512 		data += sizeof(*src);
6513 		len -= sizeof(*src);
6514 
6515 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6516 		if (!dst)
6517 			continue;
6518 
6519 		ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
6520 		ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
6521 		ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
6522 		list_add_tail(&dst->list, &stats->pdevs);
6523 	}
6524 
6525 	for (i = 0; i < ev->num_vdev_stats; i++) {
6526 		const struct wmi_vdev_stats *src;
6527 		struct ath11k_fw_stats_vdev *dst;
6528 
6529 		src = data;
6530 		if (len < sizeof(*src)) {
6531 			ret = -EPROTO;
6532 			goto exit;
6533 		}
6534 
6535 		stats->stats_id = WMI_REQUEST_VDEV_STAT;
6536 
6537 		arvif = ath11k_mac_get_arvif(ar, src->vdev_id);
6538 		if (arvif) {
6539 			sta = ieee80211_find_sta_by_ifaddr(ar->hw,
6540 							   arvif->bssid,
6541 							   NULL);
6542 			if (sta) {
6543 				arsta = (struct ath11k_sta *)sta->drv_priv;
6544 				arsta->rssi_beacon = src->beacon_snr;
6545 				ath11k_dbg(ab, ATH11K_DBG_WMI,
6546 					   "stats vdev id %d snr %d\n",
6547 					   src->vdev_id, src->beacon_snr);
6548 			} else {
6549 				ath11k_dbg(ab, ATH11K_DBG_WMI,
6550 					   "not found station of bssid %pM for vdev stat\n",
6551 					   arvif->bssid);
6552 			}
6553 		}
6554 
6555 		data += sizeof(*src);
6556 		len -= sizeof(*src);
6557 
6558 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6559 		if (!dst)
6560 			continue;
6561 
6562 		ath11k_wmi_pull_vdev_stats(src, dst);
6563 		list_add_tail(&dst->list, &stats->vdevs);
6564 	}
6565 
6566 	for (i = 0; i < ev->num_bcn_stats; i++) {
6567 		const struct wmi_bcn_stats *src;
6568 		struct ath11k_fw_stats_bcn *dst;
6569 
6570 		src = data;
6571 		if (len < sizeof(*src)) {
6572 			ret = -EPROTO;
6573 			goto exit;
6574 		}
6575 
6576 		stats->stats_id = WMI_REQUEST_BCN_STAT;
6577 
6578 		data += sizeof(*src);
6579 		len -= sizeof(*src);
6580 
6581 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6582 		if (!dst)
6583 			continue;
6584 
6585 		ath11k_wmi_pull_bcn_stats(src, dst);
6586 		list_add_tail(&dst->list, &stats->bcn);
6587 	}
6588 
6589 exit:
6590 	rcu_read_unlock();
6591 	return ret;
6592 }
6593 
6594 static int ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base *ab,
6595 					 u16 tag, u16 len,
6596 					 const void *ptr, void *data)
6597 {
6598 	struct wmi_tlv_fw_stats_parse *parse = data;
6599 	int ret = 0;
6600 
6601 	switch (tag) {
6602 	case WMI_TAG_STATS_EVENT:
6603 		parse->ev = (struct wmi_stats_event *)ptr;
6604 		parse->stats->pdev_id = parse->ev->pdev_id;
6605 		break;
6606 	case WMI_TAG_ARRAY_BYTE:
6607 		ret = ath11k_wmi_tlv_fw_stats_data_parse(ab, parse, ptr, len);
6608 		break;
6609 	case WMI_TAG_PER_CHAIN_RSSI_STATS:
6610 		parse->rssi = (struct wmi_per_chain_rssi_stats *)ptr;
6611 
6612 		if (parse->ev->stats_id & WMI_REQUEST_RSSI_PER_CHAIN_STAT)
6613 			parse->rssi_num = parse->rssi->num_per_chain_rssi_stats;
6614 
6615 		ath11k_dbg(ab, ATH11K_DBG_WMI,
6616 			   "stats id 0x%x num chain %d\n",
6617 			   parse->ev->stats_id,
6618 			   parse->rssi_num);
6619 		break;
6620 	case WMI_TAG_ARRAY_STRUCT:
6621 		if (parse->rssi_num && !parse->chain_rssi_done) {
6622 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
6623 						  ath11k_wmi_tlv_rssi_chain_parse,
6624 						  parse);
6625 			if (ret) {
6626 				ath11k_warn(ab, "failed to parse rssi chain %d\n",
6627 					    ret);
6628 				return ret;
6629 			}
6630 			parse->chain_rssi_done = true;
6631 		}
6632 		break;
6633 	default:
6634 		break;
6635 	}
6636 	return ret;
6637 }
6638 
6639 int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
6640 			     struct ath11k_fw_stats *stats)
6641 {
6642 	struct wmi_tlv_fw_stats_parse parse = { };
6643 
6644 	stats->stats_id = 0;
6645 	parse.stats = stats;
6646 
6647 	return ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6648 				   ath11k_wmi_tlv_fw_stats_parse,
6649 				   &parse);
6650 }
6651 
6652 static void
6653 ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6654 				   char *buf, u32 *length)
6655 {
6656 	u32 len = *length;
6657 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6658 
6659 	len += scnprintf(buf + len, buf_len - len, "\n");
6660 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
6661 			"ath11k PDEV stats");
6662 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6663 			"=================");
6664 
6665 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6666 			"Channel noise floor", pdev->ch_noise_floor);
6667 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6668 			"Channel TX power", pdev->chan_tx_power);
6669 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6670 			"TX frame count", pdev->tx_frame_count);
6671 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6672 			"RX frame count", pdev->rx_frame_count);
6673 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6674 			"RX clear count", pdev->rx_clear_count);
6675 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6676 			"Cycle count", pdev->cycle_count);
6677 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6678 			"PHY error count", pdev->phy_err_count);
6679 
6680 	*length = len;
6681 }
6682 
6683 static void
6684 ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6685 				 char *buf, u32 *length)
6686 {
6687 	u32 len = *length;
6688 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6689 
6690 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6691 			 "ath11k PDEV TX stats");
6692 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6693 			 "====================");
6694 
6695 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6696 			 "HTT cookies queued", pdev->comp_queued);
6697 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6698 			 "HTT cookies disp.", pdev->comp_delivered);
6699 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6700 			 "MSDU queued", pdev->msdu_enqued);
6701 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6702 			 "MPDU queued", pdev->mpdu_enqued);
6703 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6704 			 "MSDUs dropped", pdev->wmm_drop);
6705 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6706 			 "Local enqued", pdev->local_enqued);
6707 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6708 			 "Local freed", pdev->local_freed);
6709 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6710 			 "HW queued", pdev->hw_queued);
6711 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6712 			 "PPDUs reaped", pdev->hw_reaped);
6713 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6714 			 "Num underruns", pdev->underrun);
6715 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6716 			 "Num HW Paused", pdev->hw_paused);
6717 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6718 			 "PPDUs cleaned", pdev->tx_abort);
6719 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6720 			 "MPDUs requeued", pdev->mpdus_requeued);
6721 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6722 			 "PPDU OK", pdev->tx_ko);
6723 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6724 			 "Excessive retries", pdev->tx_xretry);
6725 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6726 			 "HW rate", pdev->data_rc);
6727 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6728 			 "Sched self triggers", pdev->self_triggers);
6729 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6730 			 "Dropped due to SW retries",
6731 			 pdev->sw_retry_failure);
6732 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6733 			 "Illegal rate phy errors",
6734 			 pdev->illgl_rate_phy_err);
6735 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6736 			 "PDEV continuous xretry", pdev->pdev_cont_xretry);
6737 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6738 			 "TX timeout", pdev->pdev_tx_timeout);
6739 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6740 			 "PDEV resets", pdev->pdev_resets);
6741 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6742 			 "Stateless TIDs alloc failures",
6743 			 pdev->stateless_tid_alloc_failure);
6744 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6745 			 "PHY underrun", pdev->phy_underrun);
6746 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6747 			 "MPDU is more than txop limit", pdev->txop_ovf);
6748 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6749 			 "Num sequences posted", pdev->seq_posted);
6750 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6751 			 "Num seq failed queueing ", pdev->seq_failed_queueing);
6752 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6753 			 "Num sequences completed ", pdev->seq_completed);
6754 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6755 			 "Num sequences restarted ", pdev->seq_restarted);
6756 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6757 			 "Num of MU sequences posted ", pdev->mu_seq_posted);
6758 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6759 			 "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush);
6760 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6761 			 "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter);
6762 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6763 			 "Num of MPDUS truncated ", pdev->mpdus_truncated);
6764 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6765 			 "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed);
6766 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6767 			 "Num of MPDUS expired ", pdev->mpdus_expired);
6768 	*length = len;
6769 }
6770 
6771 static void
6772 ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6773 				 char *buf, u32 *length)
6774 {
6775 	u32 len = *length;
6776 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6777 
6778 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6779 			 "ath11k PDEV RX stats");
6780 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6781 			 "====================");
6782 
6783 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6784 			 "Mid PPDU route change",
6785 			 pdev->mid_ppdu_route_change);
6786 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6787 			 "Tot. number of statuses", pdev->status_rcvd);
6788 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6789 			 "Extra frags on rings 0", pdev->r0_frags);
6790 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6791 			 "Extra frags on rings 1", pdev->r1_frags);
6792 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6793 			 "Extra frags on rings 2", pdev->r2_frags);
6794 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6795 			 "Extra frags on rings 3", pdev->r3_frags);
6796 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6797 			 "MSDUs delivered to HTT", pdev->htt_msdus);
6798 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6799 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
6800 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6801 			 "MSDUs delivered to stack", pdev->loc_msdus);
6802 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6803 			 "MPDUs delivered to stack", pdev->loc_mpdus);
6804 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6805 			 "Oversized AMSUs", pdev->oversize_amsdu);
6806 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6807 			 "PHY errors", pdev->phy_errs);
6808 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6809 			 "PHY errors drops", pdev->phy_err_drop);
6810 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6811 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
6812 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6813 			 "Overflow errors", pdev->rx_ovfl_errs);
6814 	*length = len;
6815 }
6816 
6817 static void
6818 ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
6819 			      const struct ath11k_fw_stats_vdev *vdev,
6820 			      char *buf, u32 *length)
6821 {
6822 	u32 len = *length;
6823 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6824 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
6825 	u8 *vif_macaddr;
6826 	int i;
6827 
6828 	/* VDEV stats has all the active VDEVs of other PDEVs as well,
6829 	 * ignoring those not part of requested PDEV
6830 	 */
6831 	if (!arvif)
6832 		return;
6833 
6834 	vif_macaddr = arvif->vif->addr;
6835 
6836 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6837 			 "VDEV ID", vdev->vdev_id);
6838 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6839 			 "VDEV MAC address", vif_macaddr);
6840 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6841 			 "beacon snr", vdev->beacon_snr);
6842 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6843 			 "data snr", vdev->data_snr);
6844 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6845 			 "num rx frames", vdev->num_rx_frames);
6846 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6847 			 "num rts fail", vdev->num_rts_fail);
6848 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6849 			 "num rts success", vdev->num_rts_success);
6850 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6851 			 "num rx err", vdev->num_rx_err);
6852 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6853 			 "num rx discard", vdev->num_rx_discard);
6854 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6855 			 "num tx not acked", vdev->num_tx_not_acked);
6856 
6857 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
6858 		len += scnprintf(buf + len, buf_len - len,
6859 				"%25s [%02d] %u\n",
6860 				"num tx frames", i,
6861 				vdev->num_tx_frames[i]);
6862 
6863 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
6864 		len += scnprintf(buf + len, buf_len - len,
6865 				"%25s [%02d] %u\n",
6866 				"num tx frames retries", i,
6867 				vdev->num_tx_frames_retries[i]);
6868 
6869 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
6870 		len += scnprintf(buf + len, buf_len - len,
6871 				"%25s [%02d] %u\n",
6872 				"num tx frames failures", i,
6873 				vdev->num_tx_frames_failures[i]);
6874 
6875 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
6876 		len += scnprintf(buf + len, buf_len - len,
6877 				"%25s [%02d] 0x%08x\n",
6878 				"tx rate history", i,
6879 				vdev->tx_rate_history[i]);
6880 
6881 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
6882 		len += scnprintf(buf + len, buf_len - len,
6883 				"%25s [%02d] %u\n",
6884 				"beacon rssi history", i,
6885 				vdev->beacon_rssi_history[i]);
6886 
6887 	len += scnprintf(buf + len, buf_len - len, "\n");
6888 	*length = len;
6889 }
6890 
6891 static void
6892 ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
6893 			     const struct ath11k_fw_stats_bcn *bcn,
6894 			     char *buf, u32 *length)
6895 {
6896 	u32 len = *length;
6897 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6898 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
6899 	u8 *vdev_macaddr;
6900 
6901 	if (!arvif) {
6902 		ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
6903 			    bcn->vdev_id);
6904 		return;
6905 	}
6906 
6907 	vdev_macaddr = arvif->vif->addr;
6908 
6909 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6910 			 "VDEV ID", bcn->vdev_id);
6911 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6912 			 "VDEV MAC address", vdev_macaddr);
6913 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6914 			 "================");
6915 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6916 			 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
6917 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6918 			 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
6919 
6920 	len += scnprintf(buf + len, buf_len - len, "\n");
6921 	*length = len;
6922 }
6923 
6924 void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
6925 			      struct ath11k_fw_stats *fw_stats,
6926 			      u32 stats_id, char *buf)
6927 {
6928 	u32 len = 0;
6929 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6930 	const struct ath11k_fw_stats_pdev *pdev;
6931 	const struct ath11k_fw_stats_vdev *vdev;
6932 	const struct ath11k_fw_stats_bcn *bcn;
6933 	size_t num_bcn;
6934 
6935 	spin_lock_bh(&ar->data_lock);
6936 
6937 	if (stats_id == WMI_REQUEST_PDEV_STAT) {
6938 		pdev = list_first_entry_or_null(&fw_stats->pdevs,
6939 						struct ath11k_fw_stats_pdev, list);
6940 		if (!pdev) {
6941 			ath11k_warn(ar->ab, "failed to get pdev stats\n");
6942 			goto unlock;
6943 		}
6944 
6945 		ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
6946 		ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
6947 		ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
6948 	}
6949 
6950 	if (stats_id == WMI_REQUEST_VDEV_STAT) {
6951 		len += scnprintf(buf + len, buf_len - len, "\n");
6952 		len += scnprintf(buf + len, buf_len - len, "%30s\n",
6953 				 "ath11k VDEV stats");
6954 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6955 				 "=================");
6956 
6957 		list_for_each_entry(vdev, &fw_stats->vdevs, list)
6958 			ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
6959 	}
6960 
6961 	if (stats_id == WMI_REQUEST_BCN_STAT) {
6962 		num_bcn = list_count_nodes(&fw_stats->bcn);
6963 
6964 		len += scnprintf(buf + len, buf_len - len, "\n");
6965 		len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
6966 				 "ath11k Beacon stats", num_bcn);
6967 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6968 				 "===================");
6969 
6970 		list_for_each_entry(bcn, &fw_stats->bcn, list)
6971 			ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
6972 	}
6973 
6974 unlock:
6975 	spin_unlock_bh(&ar->data_lock);
6976 
6977 	if (len >= buf_len)
6978 		buf[len - 1] = 0;
6979 	else
6980 		buf[len] = 0;
6981 }
6982 
6983 static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
6984 {
6985 	/* try to send pending beacons first. they take priority */
6986 	wake_up(&ab->wmi_ab.tx_credits_wq);
6987 }
6988 
6989 static int ath11k_reg_11d_new_cc_event(struct ath11k_base *ab, struct sk_buff *skb)
6990 {
6991 	const struct wmi_11d_new_cc_ev *ev;
6992 	struct ath11k *ar;
6993 	struct ath11k_pdev *pdev;
6994 	const void **tb;
6995 	int ret, i;
6996 
6997 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6998 	if (IS_ERR(tb)) {
6999 		ret = PTR_ERR(tb);
7000 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7001 		return ret;
7002 	}
7003 
7004 	ev = tb[WMI_TAG_11D_NEW_COUNTRY_EVENT];
7005 	if (!ev) {
7006 		kfree(tb);
7007 		ath11k_warn(ab, "failed to fetch 11d new cc ev");
7008 		return -EPROTO;
7009 	}
7010 
7011 	spin_lock_bh(&ab->base_lock);
7012 	memcpy(&ab->new_alpha2, &ev->new_alpha2, 2);
7013 	spin_unlock_bh(&ab->base_lock);
7014 
7015 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event 11d new cc %c%c\n",
7016 		   ab->new_alpha2[0],
7017 		   ab->new_alpha2[1]);
7018 
7019 	kfree(tb);
7020 
7021 	for (i = 0; i < ab->num_radios; i++) {
7022 		pdev = &ab->pdevs[i];
7023 		ar = pdev->ar;
7024 		ar->state_11d = ATH11K_11D_IDLE;
7025 		complete(&ar->completed_11d_scan);
7026 	}
7027 
7028 	queue_work(ab->workqueue, &ab->update_11d_work);
7029 
7030 	return 0;
7031 }
7032 
7033 static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
7034 				       struct sk_buff *skb)
7035 {
7036 	struct ath11k_pdev_wmi *wmi = NULL;
7037 	u32 i;
7038 	u8 wmi_ep_count;
7039 	u8 eid;
7040 
7041 	eid = ATH11K_SKB_CB(skb)->eid;
7042 	dev_kfree_skb(skb);
7043 
7044 	if (eid >= ATH11K_HTC_EP_COUNT)
7045 		return;
7046 
7047 	wmi_ep_count = ab->htc.wmi_ep_count;
7048 	if (wmi_ep_count > ab->hw_params.max_radios)
7049 		return;
7050 
7051 	for (i = 0; i < ab->htc.wmi_ep_count; i++) {
7052 		if (ab->wmi_ab.wmi[i].eid == eid) {
7053 			wmi = &ab->wmi_ab.wmi[i];
7054 			break;
7055 		}
7056 	}
7057 
7058 	if (wmi)
7059 		wake_up(&wmi->tx_ce_desc_wq);
7060 }
7061 
7062 static bool ath11k_reg_is_world_alpha(char *alpha)
7063 {
7064 	if (alpha[0] == '0' && alpha[1] == '0')
7065 		return true;
7066 
7067 	if (alpha[0] == 'n' && alpha[1] == 'a')
7068 		return true;
7069 
7070 	return false;
7071 }
7072 
7073 static int ath11k_reg_chan_list_event(struct ath11k_base *ab,
7074 				      struct sk_buff *skb,
7075 				      enum wmi_reg_chan_list_cmd_type id)
7076 {
7077 	struct cur_regulatory_info *reg_info = NULL;
7078 	struct ieee80211_regdomain *regd = NULL;
7079 	bool intersect = false;
7080 	int ret = 0, pdev_idx, i, j;
7081 	struct ath11k *ar;
7082 
7083 	reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
7084 	if (!reg_info) {
7085 		ret = -ENOMEM;
7086 		goto fallback;
7087 	}
7088 
7089 	if (id == WMI_REG_CHAN_LIST_CC_ID)
7090 		ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
7091 	else
7092 		ret = ath11k_pull_reg_chan_list_ext_update_ev(ab, skb, reg_info);
7093 
7094 	if (ret) {
7095 		ath11k_warn(ab, "failed to extract regulatory info from received event\n");
7096 		goto fallback;
7097 	}
7098 
7099 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event reg chan list id %d", id);
7100 
7101 	if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
7102 		/* In case of failure to set the requested ctry,
7103 		 * fw retains the current regd. We print a failure info
7104 		 * and return from here.
7105 		 */
7106 		ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
7107 		goto mem_free;
7108 	}
7109 
7110 	pdev_idx = reg_info->phy_id;
7111 
7112 	/* Avoid default reg rule updates sent during FW recovery if
7113 	 * it is already available
7114 	 */
7115 	spin_lock(&ab->base_lock);
7116 	if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) &&
7117 	    ab->default_regd[pdev_idx]) {
7118 		spin_unlock(&ab->base_lock);
7119 		goto mem_free;
7120 	}
7121 	spin_unlock(&ab->base_lock);
7122 
7123 	if (pdev_idx >= ab->num_radios) {
7124 		/* Process the event for phy0 only if single_pdev_only
7125 		 * is true. If pdev_idx is valid but not 0, discard the
7126 		 * event. Otherwise, it goes to fallback.
7127 		 */
7128 		if (ab->hw_params.single_pdev_only &&
7129 		    pdev_idx < ab->hw_params.num_rxmda_per_pdev)
7130 			goto mem_free;
7131 		else
7132 			goto fallback;
7133 	}
7134 
7135 	/* Avoid multiple overwrites to default regd, during core
7136 	 * stop-start after mac registration.
7137 	 */
7138 	if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
7139 	    !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
7140 		    (char *)reg_info->alpha2, 2))
7141 		goto mem_free;
7142 
7143 	/* Intersect new rules with default regd if a new country setting was
7144 	 * requested, i.e a default regd was already set during initialization
7145 	 * and the regd coming from this event has a valid country info.
7146 	 */
7147 	if (ab->default_regd[pdev_idx] &&
7148 	    !ath11k_reg_is_world_alpha((char *)
7149 		ab->default_regd[pdev_idx]->alpha2) &&
7150 	    !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
7151 		intersect = true;
7152 
7153 	regd = ath11k_reg_build_regd(ab, reg_info, intersect);
7154 	if (!regd) {
7155 		ath11k_warn(ab, "failed to build regd from reg_info\n");
7156 		goto fallback;
7157 	}
7158 
7159 	spin_lock(&ab->base_lock);
7160 	if (ab->default_regd[pdev_idx]) {
7161 		/* The initial rules from FW after WMI Init is to build
7162 		 * the default regd. From then on, any rules updated for
7163 		 * the pdev could be due to user reg changes.
7164 		 * Free previously built regd before assigning the newly
7165 		 * generated regd to ar. NULL pointer handling will be
7166 		 * taken care by kfree itself.
7167 		 */
7168 		ar = ab->pdevs[pdev_idx].ar;
7169 		kfree(ab->new_regd[pdev_idx]);
7170 		ab->new_regd[pdev_idx] = regd;
7171 		queue_work(ab->workqueue, &ar->regd_update_work);
7172 	} else {
7173 		/* This regd would be applied during mac registration and is
7174 		 * held constant throughout for regd intersection purpose
7175 		 */
7176 		ab->default_regd[pdev_idx] = regd;
7177 	}
7178 	ab->dfs_region = reg_info->dfs_region;
7179 	spin_unlock(&ab->base_lock);
7180 
7181 	goto mem_free;
7182 
7183 fallback:
7184 	/* Fallback to older reg (by sending previous country setting
7185 	 * again if fw has succeeded and we failed to process here.
7186 	 * The Regdomain should be uniform across driver and fw. Since the
7187 	 * FW has processed the command and sent a success status, we expect
7188 	 * this function to succeed as well. If it doesn't, CTRY needs to be
7189 	 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
7190 	 */
7191 	/* TODO: This is rare, but still should also be handled */
7192 	WARN_ON(1);
7193 mem_free:
7194 	if (reg_info) {
7195 		kfree(reg_info->reg_rules_2ghz_ptr);
7196 		kfree(reg_info->reg_rules_5ghz_ptr);
7197 		if (reg_info->is_ext_reg_event) {
7198 			for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++)
7199 				kfree(reg_info->reg_rules_6ghz_ap_ptr[i]);
7200 
7201 			for (j = 0; j < WMI_REG_CURRENT_MAX_AP_TYPE; j++)
7202 				for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++)
7203 					kfree(reg_info->reg_rules_6ghz_client_ptr[j][i]);
7204 		}
7205 		kfree(reg_info);
7206 	}
7207 	return ret;
7208 }
7209 
7210 static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
7211 				    const void *ptr, void *data)
7212 {
7213 	struct wmi_tlv_rdy_parse *rdy_parse = data;
7214 	struct wmi_ready_event fixed_param;
7215 	struct wmi_mac_addr *addr_list;
7216 	struct ath11k_pdev *pdev;
7217 	u32 num_mac_addr;
7218 	int i;
7219 
7220 	switch (tag) {
7221 	case WMI_TAG_READY_EVENT:
7222 		memset(&fixed_param, 0, sizeof(fixed_param));
7223 		memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
7224 		       min_t(u16, sizeof(fixed_param), len));
7225 		ab->wlan_init_status = fixed_param.ready_event_min.status;
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 		ab->wmi_ready = true;
7233 		break;
7234 	case WMI_TAG_ARRAY_FIXED_STRUCT:
7235 		addr_list = (struct wmi_mac_addr *)ptr;
7236 		num_mac_addr = rdy_parse->num_extra_mac_addr;
7237 
7238 		if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
7239 			break;
7240 
7241 		for (i = 0; i < ab->num_radios; i++) {
7242 			pdev = &ab->pdevs[i];
7243 			ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
7244 		}
7245 		ab->pdevs_macaddr_valid = true;
7246 		break;
7247 	default:
7248 		break;
7249 	}
7250 
7251 	return 0;
7252 }
7253 
7254 static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
7255 {
7256 	struct wmi_tlv_rdy_parse rdy_parse = { };
7257 	int ret;
7258 
7259 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7260 				  ath11k_wmi_tlv_rdy_parse, &rdy_parse);
7261 	if (ret) {
7262 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
7263 		return ret;
7264 	}
7265 
7266 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event ready");
7267 
7268 	complete(&ab->wmi_ab.unified_ready);
7269 	return 0;
7270 }
7271 
7272 static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
7273 {
7274 	struct wmi_peer_delete_resp_event peer_del_resp;
7275 	struct ath11k *ar;
7276 
7277 	if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
7278 		ath11k_warn(ab, "failed to extract peer delete resp");
7279 		return;
7280 	}
7281 
7282 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event peer delete resp");
7283 
7284 	rcu_read_lock();
7285 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id);
7286 	if (!ar) {
7287 		ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d",
7288 			    peer_del_resp.vdev_id);
7289 		rcu_read_unlock();
7290 		return;
7291 	}
7292 
7293 	complete(&ar->peer_delete_done);
7294 	rcu_read_unlock();
7295 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n",
7296 		   peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr);
7297 }
7298 
7299 static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab,
7300 					  struct sk_buff *skb)
7301 {
7302 	struct ath11k *ar;
7303 	u32 vdev_id = 0;
7304 
7305 	if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) {
7306 		ath11k_warn(ab, "failed to extract vdev delete resp");
7307 		return;
7308 	}
7309 
7310 	rcu_read_lock();
7311 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7312 	if (!ar) {
7313 		ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d",
7314 			    vdev_id);
7315 		rcu_read_unlock();
7316 		return;
7317 	}
7318 
7319 	complete(&ar->vdev_delete_done);
7320 
7321 	rcu_read_unlock();
7322 
7323 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event vdev delete resp for vdev id %d\n",
7324 		   vdev_id);
7325 }
7326 
7327 static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
7328 {
7329 	switch (vdev_resp_status) {
7330 	case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
7331 		return "invalid vdev id";
7332 	case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
7333 		return "not supported";
7334 	case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
7335 		return "dfs violation";
7336 	case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
7337 		return "invalid regdomain";
7338 	default:
7339 		return "unknown";
7340 	}
7341 }
7342 
7343 static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
7344 {
7345 	struct wmi_vdev_start_resp_event vdev_start_resp;
7346 	struct ath11k *ar;
7347 	u32 status;
7348 
7349 	if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
7350 		ath11k_warn(ab, "failed to extract vdev start resp");
7351 		return;
7352 	}
7353 
7354 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event start resp event");
7355 
7356 	rcu_read_lock();
7357 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
7358 	if (!ar) {
7359 		ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
7360 			    vdev_start_resp.vdev_id);
7361 		rcu_read_unlock();
7362 		return;
7363 	}
7364 
7365 	ar->last_wmi_vdev_start_status = 0;
7366 
7367 	status = vdev_start_resp.status;
7368 
7369 	if (WARN_ON_ONCE(status)) {
7370 		ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
7371 			    status, ath11k_wmi_vdev_resp_print(status));
7372 		ar->last_wmi_vdev_start_status = status;
7373 	}
7374 
7375 	complete(&ar->vdev_setup_done);
7376 
7377 	rcu_read_unlock();
7378 
7379 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
7380 		   vdev_start_resp.vdev_id);
7381 }
7382 
7383 static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
7384 {
7385 	struct ath11k_vif *arvif;
7386 	u32 vdev_id, tx_status;
7387 
7388 	if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
7389 					 &vdev_id, &tx_status) != 0) {
7390 		ath11k_warn(ab, "failed to extract bcn tx status");
7391 		return;
7392 	}
7393 
7394 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event offload bcn tx status");
7395 
7396 	rcu_read_lock();
7397 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_id);
7398 	if (!arvif) {
7399 		ath11k_warn(ab, "invalid vdev id %d in bcn_tx_status",
7400 			    vdev_id);
7401 		rcu_read_unlock();
7402 		return;
7403 	}
7404 	ath11k_mac_bcn_tx_event(arvif);
7405 	rcu_read_unlock();
7406 }
7407 
7408 static void ath11k_wmi_event_peer_sta_ps_state_chg(struct ath11k_base *ab,
7409 						   struct sk_buff *skb)
7410 {
7411 	const struct wmi_peer_sta_ps_state_chg_event *ev;
7412 	struct ieee80211_sta *sta;
7413 	struct ath11k_peer *peer;
7414 	struct ath11k *ar;
7415 	struct ath11k_sta *arsta;
7416 	const void **tb;
7417 	enum ath11k_wmi_peer_ps_state peer_previous_ps_state;
7418 	int ret;
7419 
7420 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7421 	if (IS_ERR(tb)) {
7422 		ret = PTR_ERR(tb);
7423 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7424 		return;
7425 	}
7426 
7427 	ev = tb[WMI_TAG_PEER_STA_PS_STATECHANGE_EVENT];
7428 	if (!ev) {
7429 		ath11k_warn(ab, "failed to fetch sta ps change ev");
7430 		kfree(tb);
7431 		return;
7432 	}
7433 
7434 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7435 		   "event peer sta ps change ev addr %pM state %u sup_bitmap %x ps_valid %u ts %u\n",
7436 		   ev->peer_macaddr.addr, ev->peer_ps_state,
7437 		   ev->ps_supported_bitmap, ev->peer_ps_valid,
7438 		   ev->peer_ps_timestamp);
7439 
7440 	rcu_read_lock();
7441 
7442 	spin_lock_bh(&ab->base_lock);
7443 
7444 	peer = ath11k_peer_find_by_addr(ab, ev->peer_macaddr.addr);
7445 
7446 	if (!peer) {
7447 		spin_unlock_bh(&ab->base_lock);
7448 		ath11k_warn(ab, "peer not found %pM\n", ev->peer_macaddr.addr);
7449 		goto exit;
7450 	}
7451 
7452 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id);
7453 
7454 	if (!ar) {
7455 		spin_unlock_bh(&ab->base_lock);
7456 		ath11k_warn(ab, "invalid vdev id in peer sta ps state change ev %d",
7457 			    peer->vdev_id);
7458 
7459 		goto exit;
7460 	}
7461 
7462 	sta = peer->sta;
7463 
7464 	spin_unlock_bh(&ab->base_lock);
7465 
7466 	if (!sta) {
7467 		ath11k_warn(ab, "failed to find station entry %pM\n",
7468 			    ev->peer_macaddr.addr);
7469 		goto exit;
7470 	}
7471 
7472 	arsta = (struct ath11k_sta *)sta->drv_priv;
7473 
7474 	spin_lock_bh(&ar->data_lock);
7475 
7476 	peer_previous_ps_state = arsta->peer_ps_state;
7477 	arsta->peer_ps_state = ev->peer_ps_state;
7478 	arsta->peer_current_ps_valid = !!ev->peer_ps_valid;
7479 
7480 	if (test_bit(WMI_TLV_SERVICE_PEER_POWER_SAVE_DURATION_SUPPORT,
7481 		     ar->ab->wmi_ab.svc_map)) {
7482 		if (!(ev->ps_supported_bitmap & WMI_PEER_PS_VALID) ||
7483 		    !(ev->ps_supported_bitmap & WMI_PEER_PS_STATE_TIMESTAMP) ||
7484 		    !ev->peer_ps_valid)
7485 			goto out;
7486 
7487 		if (arsta->peer_ps_state == WMI_PEER_PS_STATE_ON) {
7488 			arsta->ps_start_time = ev->peer_ps_timestamp;
7489 			arsta->ps_start_jiffies = jiffies;
7490 		} else if (arsta->peer_ps_state == WMI_PEER_PS_STATE_OFF &&
7491 			   peer_previous_ps_state == WMI_PEER_PS_STATE_ON) {
7492 			arsta->ps_total_duration = arsta->ps_total_duration +
7493 					(ev->peer_ps_timestamp - arsta->ps_start_time);
7494 		}
7495 
7496 		if (ar->ps_timekeeper_enable)
7497 			trace_ath11k_ps_timekeeper(ar, ev->peer_macaddr.addr,
7498 						   ev->peer_ps_timestamp,
7499 						   arsta->peer_ps_state);
7500 	}
7501 
7502 out:
7503 	spin_unlock_bh(&ar->data_lock);
7504 exit:
7505 	rcu_read_unlock();
7506 	kfree(tb);
7507 }
7508 
7509 static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
7510 {
7511 	struct ath11k *ar;
7512 	u32 vdev_id = 0;
7513 
7514 	if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
7515 		ath11k_warn(ab, "failed to extract vdev stopped event");
7516 		return;
7517 	}
7518 
7519 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event vdev stopped");
7520 
7521 	rcu_read_lock();
7522 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7523 	if (!ar) {
7524 		ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
7525 			    vdev_id);
7526 		rcu_read_unlock();
7527 		return;
7528 	}
7529 
7530 	complete(&ar->vdev_setup_done);
7531 
7532 	rcu_read_unlock();
7533 
7534 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
7535 }
7536 
7537 static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
7538 {
7539 	struct mgmt_rx_event_params rx_ev = {0};
7540 	struct ath11k *ar;
7541 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
7542 	struct ieee80211_hdr *hdr;
7543 	u16 fc;
7544 	struct ieee80211_supported_band *sband;
7545 
7546 	if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
7547 		ath11k_warn(ab, "failed to extract mgmt rx event");
7548 		dev_kfree_skb(skb);
7549 		return;
7550 	}
7551 
7552 	memset(status, 0, sizeof(*status));
7553 
7554 	ath11k_dbg(ab, ATH11K_DBG_MGMT, "event mgmt rx status %08x\n",
7555 		   rx_ev.status);
7556 
7557 	rcu_read_lock();
7558 	ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
7559 
7560 	if (!ar) {
7561 		ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
7562 			    rx_ev.pdev_id);
7563 		dev_kfree_skb(skb);
7564 		goto exit;
7565 	}
7566 
7567 	if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
7568 	    (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
7569 	    WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
7570 		dev_kfree_skb(skb);
7571 		goto exit;
7572 	}
7573 
7574 	if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
7575 		status->flag |= RX_FLAG_MMIC_ERROR;
7576 
7577 	if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ &&
7578 	    rx_ev.chan_freq <= ATH11K_MAX_6G_FREQ) {
7579 		status->band = NL80211_BAND_6GHZ;
7580 		status->freq = rx_ev.chan_freq;
7581 	} else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
7582 		status->band = NL80211_BAND_2GHZ;
7583 	} else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
7584 		status->band = NL80211_BAND_5GHZ;
7585 	} else {
7586 		/* Shouldn't happen unless list of advertised channels to
7587 		 * mac80211 has been changed.
7588 		 */
7589 		WARN_ON_ONCE(1);
7590 		dev_kfree_skb(skb);
7591 		goto exit;
7592 	}
7593 
7594 	if (rx_ev.phy_mode == MODE_11B &&
7595 	    (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
7596 		ath11k_dbg(ab, ATH11K_DBG_WMI,
7597 			   "mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
7598 
7599 	sband = &ar->mac.sbands[status->band];
7600 
7601 	if (status->band != NL80211_BAND_6GHZ)
7602 		status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
7603 							      status->band);
7604 
7605 	status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
7606 	status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
7607 
7608 	hdr = (struct ieee80211_hdr *)skb->data;
7609 	fc = le16_to_cpu(hdr->frame_control);
7610 
7611 	/* Firmware is guaranteed to report all essential management frames via
7612 	 * WMI while it can deliver some extra via HTT. Since there can be
7613 	 * duplicates split the reporting wrt monitor/sniffing.
7614 	 */
7615 	status->flag |= RX_FLAG_SKIP_MONITOR;
7616 
7617 	/* In case of PMF, FW delivers decrypted frames with Protected Bit set.
7618 	 * Don't clear that. Also, FW delivers broadcast management frames
7619 	 * (ex: group privacy action frames in mesh) as encrypted payload.
7620 	 */
7621 	if (ieee80211_has_protected(hdr->frame_control) &&
7622 	    !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
7623 		status->flag |= RX_FLAG_DECRYPTED;
7624 
7625 		if (!ieee80211_is_robust_mgmt_frame(skb)) {
7626 			status->flag |= RX_FLAG_IV_STRIPPED |
7627 					RX_FLAG_MMIC_STRIPPED;
7628 			hdr->frame_control = __cpu_to_le16(fc &
7629 					     ~IEEE80211_FCTL_PROTECTED);
7630 		}
7631 	}
7632 
7633 	if (ieee80211_is_beacon(hdr->frame_control))
7634 		ath11k_mac_handle_beacon(ar, skb);
7635 
7636 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
7637 		   "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
7638 		   skb, skb->len,
7639 		   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
7640 
7641 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
7642 		   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
7643 		   status->freq, status->band, status->signal,
7644 		   status->rate_idx);
7645 
7646 	ieee80211_rx_ni(ar->hw, skb);
7647 
7648 exit:
7649 	rcu_read_unlock();
7650 }
7651 
7652 static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
7653 {
7654 	struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
7655 	struct ath11k *ar;
7656 
7657 	if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
7658 		ath11k_warn(ab, "failed to extract mgmt tx compl event");
7659 		return;
7660 	}
7661 
7662 	rcu_read_lock();
7663 	ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
7664 	if (!ar) {
7665 		ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
7666 			    tx_compl_param.pdev_id);
7667 		goto exit;
7668 	}
7669 
7670 	wmi_process_mgmt_tx_comp(ar, &tx_compl_param);
7671 
7672 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
7673 		   "event mgmt tx compl ev pdev_id %d, desc_id %d, status %d ack_rssi %d",
7674 		   tx_compl_param.pdev_id, tx_compl_param.desc_id,
7675 		   tx_compl_param.status, tx_compl_param.ack_rssi);
7676 
7677 exit:
7678 	rcu_read_unlock();
7679 }
7680 
7681 static struct ath11k *ath11k_get_ar_on_scan_state(struct ath11k_base *ab,
7682 						  u32 vdev_id,
7683 						  enum ath11k_scan_state state)
7684 {
7685 	int i;
7686 	struct ath11k_pdev *pdev;
7687 	struct ath11k *ar;
7688 
7689 	for (i = 0; i < ab->num_radios; i++) {
7690 		pdev = rcu_dereference(ab->pdevs_active[i]);
7691 		if (pdev && pdev->ar) {
7692 			ar = pdev->ar;
7693 
7694 			spin_lock_bh(&ar->data_lock);
7695 			if (ar->scan.state == state &&
7696 			    ar->scan.vdev_id == vdev_id) {
7697 				spin_unlock_bh(&ar->data_lock);
7698 				return ar;
7699 			}
7700 			spin_unlock_bh(&ar->data_lock);
7701 		}
7702 	}
7703 	return NULL;
7704 }
7705 
7706 static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
7707 {
7708 	struct ath11k *ar;
7709 	struct wmi_scan_event scan_ev = {0};
7710 
7711 	if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
7712 		ath11k_warn(ab, "failed to extract scan event");
7713 		return;
7714 	}
7715 
7716 	rcu_read_lock();
7717 
7718 	/* In case the scan was cancelled, ex. during interface teardown,
7719 	 * the interface will not be found in active interfaces.
7720 	 * Rather, in such scenarios, iterate over the active pdev's to
7721 	 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
7722 	 * aborting scan's vdev id matches this event info.
7723 	 */
7724 	if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
7725 	    scan_ev.reason == WMI_SCAN_REASON_CANCELLED) {
7726 		ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7727 						 ATH11K_SCAN_ABORTING);
7728 		if (!ar)
7729 			ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7730 							 ATH11K_SCAN_RUNNING);
7731 	} else {
7732 		ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
7733 	}
7734 
7735 	if (!ar) {
7736 		ath11k_warn(ab, "Received scan event for unknown vdev");
7737 		rcu_read_unlock();
7738 		return;
7739 	}
7740 
7741 	spin_lock_bh(&ar->data_lock);
7742 
7743 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7744 		   "event scan %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
7745 		   ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
7746 		   scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
7747 		   scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
7748 		   ath11k_scan_state_str(ar->scan.state), ar->scan.state);
7749 
7750 	switch (scan_ev.event_type) {
7751 	case WMI_SCAN_EVENT_STARTED:
7752 		ath11k_wmi_event_scan_started(ar);
7753 		break;
7754 	case WMI_SCAN_EVENT_COMPLETED:
7755 		ath11k_wmi_event_scan_completed(ar);
7756 		break;
7757 	case WMI_SCAN_EVENT_BSS_CHANNEL:
7758 		ath11k_wmi_event_scan_bss_chan(ar);
7759 		break;
7760 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
7761 		ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
7762 		break;
7763 	case WMI_SCAN_EVENT_START_FAILED:
7764 		ath11k_warn(ab, "received scan start failure event\n");
7765 		ath11k_wmi_event_scan_start_failed(ar);
7766 		break;
7767 	case WMI_SCAN_EVENT_DEQUEUED:
7768 		__ath11k_mac_scan_finish(ar);
7769 		break;
7770 	case WMI_SCAN_EVENT_PREEMPTED:
7771 	case WMI_SCAN_EVENT_RESTARTED:
7772 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
7773 	default:
7774 		break;
7775 	}
7776 
7777 	spin_unlock_bh(&ar->data_lock);
7778 
7779 	rcu_read_unlock();
7780 }
7781 
7782 static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
7783 {
7784 	struct wmi_peer_sta_kickout_arg arg = {};
7785 	struct ieee80211_sta *sta;
7786 	struct ath11k_peer *peer;
7787 	struct ath11k *ar;
7788 	u32 vdev_id;
7789 
7790 	if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
7791 		ath11k_warn(ab, "failed to extract peer sta kickout event");
7792 		return;
7793 	}
7794 
7795 	rcu_read_lock();
7796 
7797 	spin_lock_bh(&ab->base_lock);
7798 
7799 	peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
7800 
7801 	if (!peer) {
7802 		ath11k_warn(ab, "peer not found %pM\n",
7803 			    arg.mac_addr);
7804 		spin_unlock_bh(&ab->base_lock);
7805 		goto exit;
7806 	}
7807 
7808 	vdev_id = peer->vdev_id;
7809 
7810 	spin_unlock_bh(&ab->base_lock);
7811 
7812 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7813 	if (!ar) {
7814 		ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
7815 			    peer->vdev_id);
7816 		goto exit;
7817 	}
7818 
7819 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
7820 					   arg.mac_addr, NULL);
7821 	if (!sta) {
7822 		ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
7823 			    arg.mac_addr);
7824 		goto exit;
7825 	}
7826 
7827 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event peer sta kickout %pM",
7828 		   arg.mac_addr);
7829 
7830 	ieee80211_report_low_ack(sta, 10);
7831 
7832 exit:
7833 	rcu_read_unlock();
7834 }
7835 
7836 static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
7837 {
7838 	struct wmi_roam_event roam_ev = {};
7839 	struct ath11k *ar;
7840 
7841 	if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
7842 		ath11k_warn(ab, "failed to extract roam event");
7843 		return;
7844 	}
7845 
7846 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7847 		   "event roam vdev %u reason 0x%08x rssi %d\n",
7848 		   roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
7849 
7850 	rcu_read_lock();
7851 	ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
7852 	if (!ar) {
7853 		ath11k_warn(ab, "invalid vdev id in roam ev %d",
7854 			    roam_ev.vdev_id);
7855 		rcu_read_unlock();
7856 		return;
7857 	}
7858 
7859 	if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
7860 		ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
7861 			    roam_ev.reason, roam_ev.vdev_id);
7862 
7863 	switch (roam_ev.reason) {
7864 	case WMI_ROAM_REASON_BEACON_MISS:
7865 		ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id);
7866 		break;
7867 	case WMI_ROAM_REASON_BETTER_AP:
7868 	case WMI_ROAM_REASON_LOW_RSSI:
7869 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
7870 	case WMI_ROAM_REASON_HO_FAILED:
7871 		ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
7872 			    roam_ev.reason, roam_ev.vdev_id);
7873 		break;
7874 	}
7875 
7876 	rcu_read_unlock();
7877 }
7878 
7879 static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7880 {
7881 	struct wmi_chan_info_event ch_info_ev = {0};
7882 	struct ath11k *ar;
7883 	struct survey_info *survey;
7884 	int idx;
7885 	/* HW channel counters frequency value in hertz */
7886 	u32 cc_freq_hz = ab->cc_freq_hz;
7887 
7888 	if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
7889 		ath11k_warn(ab, "failed to extract chan info event");
7890 		return;
7891 	}
7892 
7893 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7894 		   "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",
7895 		   ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
7896 		   ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
7897 		   ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
7898 		   ch_info_ev.mac_clk_mhz);
7899 
7900 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
7901 		ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
7902 		return;
7903 	}
7904 
7905 	rcu_read_lock();
7906 	ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
7907 	if (!ar) {
7908 		ath11k_warn(ab, "invalid vdev id in chan info ev %d",
7909 			    ch_info_ev.vdev_id);
7910 		rcu_read_unlock();
7911 		return;
7912 	}
7913 	spin_lock_bh(&ar->data_lock);
7914 
7915 	switch (ar->scan.state) {
7916 	case ATH11K_SCAN_IDLE:
7917 	case ATH11K_SCAN_STARTING:
7918 		ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
7919 		goto exit;
7920 	case ATH11K_SCAN_RUNNING:
7921 	case ATH11K_SCAN_ABORTING:
7922 		break;
7923 	}
7924 
7925 	idx = freq_to_idx(ar, ch_info_ev.freq);
7926 	if (idx >= ARRAY_SIZE(ar->survey)) {
7927 		ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
7928 			    ch_info_ev.freq, idx);
7929 		goto exit;
7930 	}
7931 
7932 	/* If FW provides MAC clock frequency in Mhz, overriding the initialized
7933 	 * HW channel counters frequency value
7934 	 */
7935 	if (ch_info_ev.mac_clk_mhz)
7936 		cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
7937 
7938 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
7939 		survey = &ar->survey[idx];
7940 		memset(survey, 0, sizeof(*survey));
7941 		survey->noise = ch_info_ev.noise_floor;
7942 		survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
7943 				 SURVEY_INFO_TIME_BUSY;
7944 		survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
7945 		survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
7946 	}
7947 exit:
7948 	spin_unlock_bh(&ar->data_lock);
7949 	rcu_read_unlock();
7950 }
7951 
7952 static void
7953 ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7954 {
7955 	struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
7956 	struct survey_info *survey;
7957 	struct ath11k *ar;
7958 	u32 cc_freq_hz = ab->cc_freq_hz;
7959 	u64 busy, total, tx, rx, rx_bss;
7960 	int idx;
7961 
7962 	if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
7963 		ath11k_warn(ab, "failed to extract pdev bss chan info event");
7964 		return;
7965 	}
7966 
7967 	busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
7968 			bss_ch_info_ev.rx_clear_count_low;
7969 
7970 	total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
7971 			bss_ch_info_ev.cycle_count_low;
7972 
7973 	tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
7974 			bss_ch_info_ev.tx_cycle_count_low;
7975 
7976 	rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
7977 			bss_ch_info_ev.rx_cycle_count_low;
7978 
7979 	rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
7980 			bss_ch_info_ev.rx_bss_cycle_count_low;
7981 
7982 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7983 		   "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",
7984 		   bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
7985 		   bss_ch_info_ev.noise_floor, busy, total,
7986 		   tx, rx, rx_bss);
7987 
7988 	rcu_read_lock();
7989 	ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
7990 
7991 	if (!ar) {
7992 		ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
7993 			    bss_ch_info_ev.pdev_id);
7994 		rcu_read_unlock();
7995 		return;
7996 	}
7997 
7998 	spin_lock_bh(&ar->data_lock);
7999 	idx = freq_to_idx(ar, bss_ch_info_ev.freq);
8000 	if (idx >= ARRAY_SIZE(ar->survey)) {
8001 		ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
8002 			    bss_ch_info_ev.freq, idx);
8003 		goto exit;
8004 	}
8005 
8006 	survey = &ar->survey[idx];
8007 
8008 	survey->noise     = bss_ch_info_ev.noise_floor;
8009 	survey->time      = div_u64(total, cc_freq_hz);
8010 	survey->time_busy = div_u64(busy, cc_freq_hz);
8011 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
8012 	survey->time_tx   = div_u64(tx, cc_freq_hz);
8013 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
8014 			     SURVEY_INFO_TIME |
8015 			     SURVEY_INFO_TIME_BUSY |
8016 			     SURVEY_INFO_TIME_RX |
8017 			     SURVEY_INFO_TIME_TX);
8018 exit:
8019 	spin_unlock_bh(&ar->data_lock);
8020 	complete(&ar->bss_survey_done);
8021 
8022 	rcu_read_unlock();
8023 }
8024 
8025 static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
8026 						struct sk_buff *skb)
8027 {
8028 	struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
8029 	struct ath11k *ar;
8030 
8031 	if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
8032 		ath11k_warn(ab, "failed to extract install key compl event");
8033 		return;
8034 	}
8035 
8036 	ath11k_dbg(ab, ATH11K_DBG_WMI,
8037 		   "event vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
8038 		   install_key_compl.key_idx, install_key_compl.key_flags,
8039 		   install_key_compl.macaddr, install_key_compl.status);
8040 
8041 	rcu_read_lock();
8042 	ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
8043 	if (!ar) {
8044 		ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
8045 			    install_key_compl.vdev_id);
8046 		rcu_read_unlock();
8047 		return;
8048 	}
8049 
8050 	ar->install_key_status = 0;
8051 
8052 	if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
8053 		ath11k_warn(ab, "install key failed for %pM status %d\n",
8054 			    install_key_compl.macaddr, install_key_compl.status);
8055 		ar->install_key_status = install_key_compl.status;
8056 	}
8057 
8058 	complete(&ar->install_key_done);
8059 	rcu_read_unlock();
8060 }
8061 
8062 static int  ath11k_wmi_tlv_services_parser(struct ath11k_base *ab,
8063 					   u16 tag, u16 len,
8064 					   const void *ptr, void *data)
8065 {
8066 	const struct wmi_service_available_event *ev;
8067 	u32 *wmi_ext2_service_bitmap;
8068 	int i, j;
8069 
8070 	switch (tag) {
8071 	case WMI_TAG_SERVICE_AVAILABLE_EVENT:
8072 		ev = (struct wmi_service_available_event *)ptr;
8073 		for (i = 0, j = WMI_MAX_SERVICE;
8074 			i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
8075 			i++) {
8076 			do {
8077 				if (ev->wmi_service_segment_bitmap[i] &
8078 				    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
8079 					set_bit(j, ab->wmi_ab.svc_map);
8080 			} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
8081 		}
8082 
8083 		ath11k_dbg(ab, ATH11K_DBG_WMI,
8084 			   "wmi_ext_service_bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
8085 			   ev->wmi_service_segment_bitmap[0],
8086 			   ev->wmi_service_segment_bitmap[1],
8087 			   ev->wmi_service_segment_bitmap[2],
8088 			   ev->wmi_service_segment_bitmap[3]);
8089 		break;
8090 	case WMI_TAG_ARRAY_UINT32:
8091 		wmi_ext2_service_bitmap = (u32 *)ptr;
8092 		for (i = 0, j = WMI_MAX_EXT_SERVICE;
8093 			i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT2_SERVICE;
8094 			i++) {
8095 			do {
8096 				if (wmi_ext2_service_bitmap[i] &
8097 				    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
8098 					set_bit(j, ab->wmi_ab.svc_map);
8099 			} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
8100 		}
8101 
8102 		ath11k_dbg(ab, ATH11K_DBG_WMI,
8103 			   "wmi_ext2_service__bitmap  0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
8104 			   wmi_ext2_service_bitmap[0], wmi_ext2_service_bitmap[1],
8105 			   wmi_ext2_service_bitmap[2], wmi_ext2_service_bitmap[3]);
8106 		break;
8107 	}
8108 	return 0;
8109 }
8110 
8111 static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
8112 {
8113 	int ret;
8114 
8115 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
8116 				  ath11k_wmi_tlv_services_parser,
8117 				  NULL);
8118 	if (ret)
8119 		ath11k_warn(ab, "failed to parse services available tlv %d\n", ret);
8120 
8121 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event service available");
8122 }
8123 
8124 static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
8125 {
8126 	struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
8127 	struct ath11k *ar;
8128 
8129 	if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
8130 		ath11k_warn(ab, "failed to extract peer assoc conf event");
8131 		return;
8132 	}
8133 
8134 	ath11k_dbg(ab, ATH11K_DBG_WMI,
8135 		   "event peer assoc conf ev vdev id %d macaddr %pM\n",
8136 		   peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
8137 
8138 	rcu_read_lock();
8139 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
8140 
8141 	if (!ar) {
8142 		ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
8143 			    peer_assoc_conf.vdev_id);
8144 		rcu_read_unlock();
8145 		return;
8146 	}
8147 
8148 	complete(&ar->peer_assoc_done);
8149 	rcu_read_unlock();
8150 }
8151 
8152 static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
8153 {
8154 	struct ath11k_fw_stats stats = {};
8155 	struct ath11k *ar;
8156 	int ret;
8157 
8158 	INIT_LIST_HEAD(&stats.pdevs);
8159 	INIT_LIST_HEAD(&stats.vdevs);
8160 	INIT_LIST_HEAD(&stats.bcn);
8161 
8162 	ret = ath11k_wmi_pull_fw_stats(ab, skb, &stats);
8163 	if (ret) {
8164 		ath11k_warn(ab, "failed to pull fw stats: %d\n", ret);
8165 		goto free;
8166 	}
8167 
8168 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event update stats");
8169 
8170 	rcu_read_lock();
8171 	ar = ath11k_mac_get_ar_by_pdev_id(ab, stats.pdev_id);
8172 	if (!ar) {
8173 		rcu_read_unlock();
8174 		ath11k_warn(ab, "failed to get ar for pdev_id %d: %d\n",
8175 			    stats.pdev_id, ret);
8176 		goto free;
8177 	}
8178 
8179 	spin_lock_bh(&ar->data_lock);
8180 
8181 	/* WMI_REQUEST_PDEV_STAT can be requested via .get_txpower mac ops or via
8182 	 * debugfs fw stats. Therefore, processing it separately.
8183 	 */
8184 	if (stats.stats_id == WMI_REQUEST_PDEV_STAT) {
8185 		list_splice_tail_init(&stats.pdevs, &ar->fw_stats.pdevs);
8186 		ar->fw_stats_done = true;
8187 		goto complete;
8188 	}
8189 
8190 	/* WMI_REQUEST_VDEV_STAT, WMI_REQUEST_BCN_STAT and WMI_REQUEST_RSSI_PER_CHAIN_STAT
8191 	 * are currently requested only via debugfs fw stats. Hence, processing these
8192 	 * in debugfs context
8193 	 */
8194 	ath11k_debugfs_fw_stats_process(ar, &stats);
8195 
8196 complete:
8197 	complete(&ar->fw_stats_complete);
8198 	rcu_read_unlock();
8199 	spin_unlock_bh(&ar->data_lock);
8200 
8201 	/* Since the stats's pdev, vdev and beacon list are spliced and reinitialised
8202 	 * at this point, no need to free the individual list.
8203 	 */
8204 	return;
8205 
8206 free:
8207 	ath11k_fw_stats_free(&stats);
8208 }
8209 
8210 /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
8211  * is not part of BDF CTL(Conformance test limits) table entries.
8212  */
8213 static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
8214 						 struct sk_buff *skb)
8215 {
8216 	const void **tb;
8217 	const struct wmi_pdev_ctl_failsafe_chk_event *ev;
8218 	int ret;
8219 
8220 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8221 	if (IS_ERR(tb)) {
8222 		ret = PTR_ERR(tb);
8223 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8224 		return;
8225 	}
8226 
8227 	ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
8228 	if (!ev) {
8229 		ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
8230 		kfree(tb);
8231 		return;
8232 	}
8233 
8234 	ath11k_dbg(ab, ATH11K_DBG_WMI,
8235 		   "event pdev ctl failsafe check status %d\n",
8236 		   ev->ctl_failsafe_status);
8237 
8238 	/* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
8239 	 * to 10 dBm else the CTL power entry in the BDF would be picked up.
8240 	 */
8241 	if (ev->ctl_failsafe_status != 0)
8242 		ath11k_warn(ab, "pdev ctl failsafe failure status %d",
8243 			    ev->ctl_failsafe_status);
8244 
8245 	kfree(tb);
8246 }
8247 
8248 static void
8249 ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
8250 					  const struct wmi_pdev_csa_switch_ev *ev,
8251 					  const u32 *vdev_ids)
8252 {
8253 	int i;
8254 	struct ath11k_vif *arvif;
8255 
8256 	/* Finish CSA once the switch count becomes NULL */
8257 	if (ev->current_switch_count)
8258 		return;
8259 
8260 	rcu_read_lock();
8261 	for (i = 0; i < ev->num_vdevs; i++) {
8262 		arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
8263 
8264 		if (!arvif) {
8265 			ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
8266 				    vdev_ids[i]);
8267 			continue;
8268 		}
8269 
8270 		if (arvif->is_up && arvif->vif->bss_conf.csa_active)
8271 			ieee80211_csa_finish(arvif->vif);
8272 	}
8273 	rcu_read_unlock();
8274 }
8275 
8276 static void
8277 ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
8278 					      struct sk_buff *skb)
8279 {
8280 	const void **tb;
8281 	const struct wmi_pdev_csa_switch_ev *ev;
8282 	const u32 *vdev_ids;
8283 	int ret;
8284 
8285 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8286 	if (IS_ERR(tb)) {
8287 		ret = PTR_ERR(tb);
8288 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8289 		return;
8290 	}
8291 
8292 	ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
8293 	vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
8294 
8295 	if (!ev || !vdev_ids) {
8296 		ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
8297 		kfree(tb);
8298 		return;
8299 	}
8300 
8301 	ath11k_dbg(ab, ATH11K_DBG_WMI,
8302 		   "event pdev csa switch count %d for pdev %d, num_vdevs %d",
8303 		   ev->current_switch_count, ev->pdev_id,
8304 		   ev->num_vdevs);
8305 
8306 	ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
8307 
8308 	kfree(tb);
8309 }
8310 
8311 static void
8312 ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
8313 {
8314 	const void **tb;
8315 	const struct wmi_pdev_radar_ev *ev;
8316 	struct ath11k *ar;
8317 	int ret;
8318 
8319 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8320 	if (IS_ERR(tb)) {
8321 		ret = PTR_ERR(tb);
8322 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8323 		return;
8324 	}
8325 
8326 	ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
8327 
8328 	if (!ev) {
8329 		ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
8330 		kfree(tb);
8331 		return;
8332 	}
8333 
8334 	ath11k_dbg(ab, ATH11K_DBG_WMI,
8335 		   "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",
8336 		   ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
8337 		   ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
8338 		   ev->freq_offset, ev->sidx);
8339 
8340 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
8341 
8342 	if (!ar) {
8343 		ath11k_warn(ab, "radar detected in invalid pdev %d\n",
8344 			    ev->pdev_id);
8345 		goto exit;
8346 	}
8347 
8348 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
8349 		   ev->pdev_id);
8350 
8351 	if (ar->dfs_block_radar_events)
8352 		ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
8353 	else
8354 		ieee80211_radar_detected(ar->hw);
8355 
8356 exit:
8357 	kfree(tb);
8358 }
8359 
8360 static void
8361 ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
8362 				  struct sk_buff *skb)
8363 {
8364 	struct ath11k *ar;
8365 	const void **tb;
8366 	const struct wmi_pdev_temperature_event *ev;
8367 	int ret;
8368 
8369 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8370 	if (IS_ERR(tb)) {
8371 		ret = PTR_ERR(tb);
8372 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8373 		return;
8374 	}
8375 
8376 	ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
8377 	if (!ev) {
8378 		ath11k_warn(ab, "failed to fetch pdev temp ev");
8379 		kfree(tb);
8380 		return;
8381 	}
8382 
8383 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev temperature ev temp %d pdev_id %d\n",
8384 		   ev->temp, ev->pdev_id);
8385 
8386 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
8387 	if (!ar) {
8388 		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
8389 		kfree(tb);
8390 		return;
8391 	}
8392 
8393 	ath11k_thermal_event_temperature(ar, ev->temp);
8394 
8395 	kfree(tb);
8396 }
8397 
8398 static void ath11k_fils_discovery_event(struct ath11k_base *ab,
8399 					struct sk_buff *skb)
8400 {
8401 	const void **tb;
8402 	const struct wmi_fils_discovery_event *ev;
8403 	int ret;
8404 
8405 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8406 	if (IS_ERR(tb)) {
8407 		ret = PTR_ERR(tb);
8408 		ath11k_warn(ab,
8409 			    "failed to parse FILS discovery event tlv %d\n",
8410 			    ret);
8411 		return;
8412 	}
8413 
8414 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event fils discovery");
8415 
8416 	ev = tb[WMI_TAG_HOST_SWFDA_EVENT];
8417 	if (!ev) {
8418 		ath11k_warn(ab, "failed to fetch FILS discovery event\n");
8419 		kfree(tb);
8420 		return;
8421 	}
8422 
8423 	ath11k_warn(ab,
8424 		    "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n",
8425 		    ev->vdev_id, ev->fils_tt, ev->tbtt);
8426 
8427 	kfree(tb);
8428 }
8429 
8430 static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab,
8431 					      struct sk_buff *skb)
8432 {
8433 	const void **tb;
8434 	const struct wmi_probe_resp_tx_status_event *ev;
8435 	int ret;
8436 
8437 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8438 	if (IS_ERR(tb)) {
8439 		ret = PTR_ERR(tb);
8440 		ath11k_warn(ab,
8441 			    "failed to parse probe response transmission status event tlv: %d\n",
8442 			    ret);
8443 		return;
8444 	}
8445 
8446 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event probe resp tx status");
8447 
8448 	ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT];
8449 	if (!ev) {
8450 		ath11k_warn(ab,
8451 			    "failed to fetch probe response transmission status event");
8452 		kfree(tb);
8453 		return;
8454 	}
8455 
8456 	if (ev->tx_status)
8457 		ath11k_warn(ab,
8458 			    "Probe response transmission failed for vdev_id %u, status %u\n",
8459 			    ev->vdev_id, ev->tx_status);
8460 
8461 	kfree(tb);
8462 }
8463 
8464 static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab,
8465 						u16 tag, u16 len,
8466 						const void *ptr, void *data)
8467 {
8468 	struct wmi_wow_ev_arg *ev = data;
8469 	const char *wow_pg_fault;
8470 	int wow_pg_len;
8471 
8472 	switch (tag) {
8473 	case WMI_TAG_WOW_EVENT_INFO:
8474 		memcpy(ev, ptr, sizeof(*ev));
8475 		ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n",
8476 			   ev->wake_reason, wow_reason(ev->wake_reason));
8477 		break;
8478 
8479 	case WMI_TAG_ARRAY_BYTE:
8480 		if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) {
8481 			wow_pg_fault = ptr;
8482 			/* the first 4 bytes are length */
8483 			wow_pg_len = *(int *)wow_pg_fault;
8484 			wow_pg_fault += sizeof(int);
8485 			ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n",
8486 				   wow_pg_len);
8487 			ath11k_dbg_dump(ab, ATH11K_DBG_WMI,
8488 					"wow_event_info_type packet present",
8489 					"wow_pg_fault ",
8490 					wow_pg_fault,
8491 					wow_pg_len);
8492 		}
8493 		break;
8494 	default:
8495 		break;
8496 	}
8497 
8498 	return 0;
8499 }
8500 
8501 static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb)
8502 {
8503 	struct wmi_wow_ev_arg ev = { };
8504 	int ret;
8505 
8506 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
8507 				  ath11k_wmi_tlv_wow_wakeup_host_parse,
8508 				  &ev);
8509 	if (ret) {
8510 		ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret);
8511 		return;
8512 	}
8513 
8514 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event wow wakeup host");
8515 
8516 	complete(&ab->wow.wakeup_completed);
8517 }
8518 
8519 static void
8520 ath11k_wmi_diag_event(struct ath11k_base *ab,
8521 		      struct sk_buff *skb)
8522 {
8523 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event diag");
8524 
8525 	trace_ath11k_wmi_diag(ab, skb->data, skb->len);
8526 }
8527 
8528 static const char *ath11k_wmi_twt_add_dialog_event_status(u32 status)
8529 {
8530 	switch (status) {
8531 	case WMI_ADD_TWT_STATUS_OK:
8532 		return "ok";
8533 	case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
8534 		return "twt disabled";
8535 	case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
8536 		return "dialog id in use";
8537 	case WMI_ADD_TWT_STATUS_INVALID_PARAM:
8538 		return "invalid parameters";
8539 	case WMI_ADD_TWT_STATUS_NOT_READY:
8540 		return "not ready";
8541 	case WMI_ADD_TWT_STATUS_NO_RESOURCE:
8542 		return "resource unavailable";
8543 	case WMI_ADD_TWT_STATUS_NO_ACK:
8544 		return "no ack";
8545 	case WMI_ADD_TWT_STATUS_NO_RESPONSE:
8546 		return "no response";
8547 	case WMI_ADD_TWT_STATUS_DENIED:
8548 		return "denied";
8549 	case WMI_ADD_TWT_STATUS_UNKNOWN_ERROR:
8550 		fallthrough;
8551 	default:
8552 		return "unknown error";
8553 	}
8554 }
8555 
8556 static void ath11k_wmi_twt_add_dialog_event(struct ath11k_base *ab,
8557 					    struct sk_buff *skb)
8558 {
8559 	const void **tb;
8560 	const struct wmi_twt_add_dialog_event *ev;
8561 	int ret;
8562 
8563 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8564 	if (IS_ERR(tb)) {
8565 		ret = PTR_ERR(tb);
8566 		ath11k_warn(ab,
8567 			    "failed to parse wmi twt add dialog status event tlv: %d\n",
8568 			    ret);
8569 		return;
8570 	}
8571 
8572 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event twt add dialog");
8573 
8574 	ev = tb[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT];
8575 	if (!ev) {
8576 		ath11k_warn(ab, "failed to fetch twt add dialog wmi event\n");
8577 		goto exit;
8578 	}
8579 
8580 	if (ev->status)
8581 		ath11k_warn(ab,
8582 			    "wmi add twt dialog event vdev %d dialog id %d status %s\n",
8583 			    ev->vdev_id, ev->dialog_id,
8584 			    ath11k_wmi_twt_add_dialog_event_status(ev->status));
8585 
8586 exit:
8587 	kfree(tb);
8588 }
8589 
8590 static void ath11k_wmi_gtk_offload_status_event(struct ath11k_base *ab,
8591 						struct sk_buff *skb)
8592 {
8593 	const void **tb;
8594 	const struct wmi_gtk_offload_status_event *ev;
8595 	struct ath11k_vif *arvif;
8596 	__be64 replay_ctr_be;
8597 	u64    replay_ctr;
8598 	int ret;
8599 
8600 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8601 	if (IS_ERR(tb)) {
8602 		ret = PTR_ERR(tb);
8603 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8604 		return;
8605 	}
8606 
8607 	ev = tb[WMI_TAG_GTK_OFFLOAD_STATUS_EVENT];
8608 	if (!ev) {
8609 		ath11k_warn(ab, "failed to fetch gtk offload status ev");
8610 		kfree(tb);
8611 		return;
8612 	}
8613 
8614 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
8615 	if (!arvif) {
8616 		ath11k_warn(ab, "failed to get arvif for vdev_id:%d\n",
8617 			    ev->vdev_id);
8618 		kfree(tb);
8619 		return;
8620 	}
8621 
8622 	ath11k_dbg(ab, ATH11K_DBG_WMI, "event gtk offload refresh_cnt %d\n",
8623 		   ev->refresh_cnt);
8624 	ath11k_dbg_dump(ab, ATH11K_DBG_WMI, "replay_cnt",
8625 			NULL, ev->replay_ctr.counter, GTK_REPLAY_COUNTER_BYTES);
8626 
8627 	replay_ctr =  ev->replay_ctr.word1;
8628 	replay_ctr = (replay_ctr << 32) | ev->replay_ctr.word0;
8629 	arvif->rekey_data.replay_ctr = replay_ctr;
8630 
8631 	/* supplicant expects big-endian replay counter */
8632 	replay_ctr_be = cpu_to_be64(replay_ctr);
8633 
8634 	ieee80211_gtk_rekey_notify(arvif->vif, arvif->bssid,
8635 				   (void *)&replay_ctr_be, GFP_ATOMIC);
8636 
8637 	kfree(tb);
8638 }
8639 
8640 static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
8641 {
8642 	struct wmi_cmd_hdr *cmd_hdr;
8643 	enum wmi_tlv_event_id id;
8644 
8645 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
8646 	id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
8647 
8648 	trace_ath11k_wmi_event(ab, id, skb->data, skb->len);
8649 
8650 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
8651 		goto out;
8652 
8653 	switch (id) {
8654 		/* Process all the WMI events here */
8655 	case WMI_SERVICE_READY_EVENTID:
8656 		ath11k_service_ready_event(ab, skb);
8657 		break;
8658 	case WMI_SERVICE_READY_EXT_EVENTID:
8659 		ath11k_service_ready_ext_event(ab, skb);
8660 		break;
8661 	case WMI_SERVICE_READY_EXT2_EVENTID:
8662 		ath11k_service_ready_ext2_event(ab, skb);
8663 		break;
8664 	case WMI_REG_CHAN_LIST_CC_EVENTID:
8665 		ath11k_reg_chan_list_event(ab, skb, WMI_REG_CHAN_LIST_CC_ID);
8666 		break;
8667 	case WMI_REG_CHAN_LIST_CC_EXT_EVENTID:
8668 		ath11k_reg_chan_list_event(ab, skb, WMI_REG_CHAN_LIST_CC_EXT_ID);
8669 		break;
8670 	case WMI_READY_EVENTID:
8671 		ath11k_ready_event(ab, skb);
8672 		break;
8673 	case WMI_PEER_DELETE_RESP_EVENTID:
8674 		ath11k_peer_delete_resp_event(ab, skb);
8675 		break;
8676 	case WMI_VDEV_START_RESP_EVENTID:
8677 		ath11k_vdev_start_resp_event(ab, skb);
8678 		break;
8679 	case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
8680 		ath11k_bcn_tx_status_event(ab, skb);
8681 		break;
8682 	case WMI_VDEV_STOPPED_EVENTID:
8683 		ath11k_vdev_stopped_event(ab, skb);
8684 		break;
8685 	case WMI_MGMT_RX_EVENTID:
8686 		ath11k_mgmt_rx_event(ab, skb);
8687 		/* mgmt_rx_event() owns the skb now! */
8688 		return;
8689 	case WMI_MGMT_TX_COMPLETION_EVENTID:
8690 		ath11k_mgmt_tx_compl_event(ab, skb);
8691 		break;
8692 	case WMI_SCAN_EVENTID:
8693 		ath11k_scan_event(ab, skb);
8694 		break;
8695 	case WMI_PEER_STA_KICKOUT_EVENTID:
8696 		ath11k_peer_sta_kickout_event(ab, skb);
8697 		break;
8698 	case WMI_ROAM_EVENTID:
8699 		ath11k_roam_event(ab, skb);
8700 		break;
8701 	case WMI_CHAN_INFO_EVENTID:
8702 		ath11k_chan_info_event(ab, skb);
8703 		break;
8704 	case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
8705 		ath11k_pdev_bss_chan_info_event(ab, skb);
8706 		break;
8707 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
8708 		ath11k_vdev_install_key_compl_event(ab, skb);
8709 		break;
8710 	case WMI_SERVICE_AVAILABLE_EVENTID:
8711 		ath11k_service_available_event(ab, skb);
8712 		break;
8713 	case WMI_PEER_ASSOC_CONF_EVENTID:
8714 		ath11k_peer_assoc_conf_event(ab, skb);
8715 		break;
8716 	case WMI_UPDATE_STATS_EVENTID:
8717 		ath11k_update_stats_event(ab, skb);
8718 		break;
8719 	case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
8720 		ath11k_pdev_ctl_failsafe_check_event(ab, skb);
8721 		break;
8722 	case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
8723 		ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
8724 		break;
8725 	case WMI_PDEV_UTF_EVENTID:
8726 		ath11k_tm_wmi_event(ab, id, skb);
8727 		break;
8728 	case WMI_PDEV_TEMPERATURE_EVENTID:
8729 		ath11k_wmi_pdev_temperature_event(ab, skb);
8730 		break;
8731 	case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
8732 		ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
8733 		break;
8734 	case WMI_HOST_FILS_DISCOVERY_EVENTID:
8735 		ath11k_fils_discovery_event(ab, skb);
8736 		break;
8737 	case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID:
8738 		ath11k_probe_resp_tx_status_event(ab, skb);
8739 		break;
8740 	case WMI_OBSS_COLOR_COLLISION_DETECTION_EVENTID:
8741 		ath11k_wmi_obss_color_collision_event(ab, skb);
8742 		break;
8743 	case WMI_TWT_ADD_DIALOG_EVENTID:
8744 		ath11k_wmi_twt_add_dialog_event(ab, skb);
8745 		break;
8746 	case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
8747 		ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
8748 		break;
8749 	case WMI_VDEV_DELETE_RESP_EVENTID:
8750 		ath11k_vdev_delete_resp_event(ab, skb);
8751 		break;
8752 	case WMI_WOW_WAKEUP_HOST_EVENTID:
8753 		ath11k_wmi_event_wow_wakeup_host(ab, skb);
8754 		break;
8755 	case WMI_11D_NEW_COUNTRY_EVENTID:
8756 		ath11k_reg_11d_new_cc_event(ab, skb);
8757 		break;
8758 	case WMI_DIAG_EVENTID:
8759 		ath11k_wmi_diag_event(ab, skb);
8760 		break;
8761 	case WMI_PEER_STA_PS_STATECHG_EVENTID:
8762 		ath11k_wmi_event_peer_sta_ps_state_chg(ab, skb);
8763 		break;
8764 	case WMI_GTK_OFFLOAD_STATUS_EVENTID:
8765 		ath11k_wmi_gtk_offload_status_event(ab, skb);
8766 		break;
8767 	default:
8768 		ath11k_dbg(ab, ATH11K_DBG_WMI, "unsupported event id 0x%x\n", id);
8769 		break;
8770 	}
8771 
8772 out:
8773 	dev_kfree_skb(skb);
8774 }
8775 
8776 static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
8777 					   u32 pdev_idx)
8778 {
8779 	int status;
8780 	u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
8781 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
8782 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
8783 
8784 	struct ath11k_htc_svc_conn_req conn_req;
8785 	struct ath11k_htc_svc_conn_resp conn_resp;
8786 
8787 	memset(&conn_req, 0, sizeof(conn_req));
8788 	memset(&conn_resp, 0, sizeof(conn_resp));
8789 
8790 	/* these fields are the same for all service endpoints */
8791 	conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
8792 	conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
8793 	conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
8794 
8795 	/* connect to control service */
8796 	conn_req.service_id = svc_id[pdev_idx];
8797 
8798 	status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
8799 	if (status) {
8800 		ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
8801 			    status);
8802 		return status;
8803 	}
8804 
8805 	ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
8806 	ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
8807 	ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
8808 	init_waitqueue_head(&ab->wmi_ab.wmi[pdev_idx].tx_ce_desc_wq);
8809 
8810 	return 0;
8811 }
8812 
8813 static int
8814 ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
8815 			      struct wmi_unit_test_cmd ut_cmd,
8816 			      u32 *test_args)
8817 {
8818 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8819 	struct wmi_unit_test_cmd *cmd;
8820 	struct sk_buff *skb;
8821 	struct wmi_tlv *tlv;
8822 	void *ptr;
8823 	u32 *ut_cmd_args;
8824 	int buf_len, arg_len;
8825 	int ret;
8826 	int i;
8827 
8828 	arg_len = sizeof(u32) * ut_cmd.num_args;
8829 	buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
8830 
8831 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
8832 	if (!skb)
8833 		return -ENOMEM;
8834 
8835 	cmd = (struct wmi_unit_test_cmd *)skb->data;
8836 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
8837 			  FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
8838 
8839 	cmd->vdev_id = ut_cmd.vdev_id;
8840 	cmd->module_id = ut_cmd.module_id;
8841 	cmd->num_args = ut_cmd.num_args;
8842 	cmd->diag_token = ut_cmd.diag_token;
8843 
8844 	ptr = skb->data + sizeof(ut_cmd);
8845 
8846 	tlv = ptr;
8847 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8848 		      FIELD_PREP(WMI_TLV_LEN, arg_len);
8849 
8850 	ptr += TLV_HDR_SIZE;
8851 
8852 	ut_cmd_args = ptr;
8853 	for (i = 0; i < ut_cmd.num_args; i++)
8854 		ut_cmd_args[i] = test_args[i];
8855 
8856 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
8857 
8858 	if (ret) {
8859 		ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
8860 			    ret);
8861 		dev_kfree_skb(skb);
8862 	}
8863 
8864 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8865 		   "cmd unit test module %d vdev %d n_args %d token %d\n",
8866 		   cmd->module_id, cmd->vdev_id, cmd->num_args,
8867 		   cmd->diag_token);
8868 
8869 	return ret;
8870 }
8871 
8872 int ath11k_wmi_simulate_radar(struct ath11k *ar)
8873 {
8874 	struct ath11k_vif *arvif;
8875 	u32 dfs_args[DFS_MAX_TEST_ARGS];
8876 	struct wmi_unit_test_cmd wmi_ut;
8877 	bool arvif_found = false;
8878 
8879 	list_for_each_entry(arvif, &ar->arvifs, list) {
8880 		if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
8881 			arvif_found = true;
8882 			break;
8883 		}
8884 	}
8885 
8886 	if (!arvif_found)
8887 		return -EINVAL;
8888 
8889 	dfs_args[DFS_TEST_CMDID] = 0;
8890 	dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
8891 	/* Currently we could pass segment_id(b0 - b1), chirp(b2)
8892 	 * freq offset (b3 - b10) to unit test. For simulation
8893 	 * purpose this can be set to 0 which is valid.
8894 	 */
8895 	dfs_args[DFS_TEST_RADAR_PARAM] = 0;
8896 
8897 	wmi_ut.vdev_id = arvif->vdev_id;
8898 	wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
8899 	wmi_ut.num_args = DFS_MAX_TEST_ARGS;
8900 	wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
8901 
8902 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
8903 
8904 	return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
8905 }
8906 
8907 int ath11k_wmi_fw_dbglog_cfg(struct ath11k *ar, u32 *module_id_bitmap,
8908 			     struct ath11k_fw_dbglog *dbglog)
8909 {
8910 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8911 	struct wmi_debug_log_config_cmd_fixed_param *cmd;
8912 	struct sk_buff *skb;
8913 	struct wmi_tlv *tlv;
8914 	int ret, len;
8915 
8916 	len = sizeof(*cmd) + TLV_HDR_SIZE + (MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8917 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8918 	if (!skb)
8919 		return -ENOMEM;
8920 
8921 	cmd = (struct wmi_debug_log_config_cmd_fixed_param *)skb->data;
8922 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DEBUG_LOG_CONFIG_CMD) |
8923 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8924 	cmd->dbg_log_param = dbglog->param;
8925 
8926 	tlv = (struct wmi_tlv *)((u8 *)cmd + sizeof(*cmd));
8927 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8928 		      FIELD_PREP(WMI_TLV_LEN, MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8929 
8930 	switch (dbglog->param) {
8931 	case WMI_DEBUG_LOG_PARAM_LOG_LEVEL:
8932 	case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE:
8933 	case WMI_DEBUG_LOG_PARAM_VDEV_DISABLE:
8934 	case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE_BITMAP:
8935 		cmd->value = dbglog->value;
8936 		break;
8937 	case WMI_DEBUG_LOG_PARAM_MOD_ENABLE_BITMAP:
8938 	case WMI_DEBUG_LOG_PARAM_WOW_MOD_ENABLE_BITMAP:
8939 		cmd->value = dbglog->value;
8940 		memcpy(tlv->value, module_id_bitmap,
8941 		       MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8942 		/* clear current config to be used for next user config */
8943 		memset(module_id_bitmap, 0,
8944 		       MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8945 		break;
8946 	default:
8947 		dev_kfree_skb(skb);
8948 		return -EINVAL;
8949 	}
8950 
8951 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DBGLOG_CFG_CMDID);
8952 	if (ret) {
8953 		ath11k_warn(ar->ab,
8954 			    "failed to send WMI_DBGLOG_CFG_CMDID\n");
8955 		dev_kfree_skb(skb);
8956 	}
8957 
8958 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd dbglog cfg");
8959 
8960 	return ret;
8961 }
8962 
8963 int ath11k_wmi_connect(struct ath11k_base *ab)
8964 {
8965 	u32 i;
8966 	u8 wmi_ep_count;
8967 
8968 	wmi_ep_count = ab->htc.wmi_ep_count;
8969 	if (wmi_ep_count > ab->hw_params.max_radios)
8970 		return -1;
8971 
8972 	for (i = 0; i < wmi_ep_count; i++)
8973 		ath11k_connect_pdev_htc_service(ab, i);
8974 
8975 	return 0;
8976 }
8977 
8978 static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
8979 {
8980 	if (WARN_ON(pdev_id >= MAX_RADIOS))
8981 		return;
8982 
8983 	/* TODO: Deinit any pdev specific wmi resource */
8984 }
8985 
8986 int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
8987 			   u8 pdev_id)
8988 {
8989 	struct ath11k_pdev_wmi *wmi_handle;
8990 
8991 	if (pdev_id >= ab->hw_params.max_radios)
8992 		return -EINVAL;
8993 
8994 	wmi_handle = &ab->wmi_ab.wmi[pdev_id];
8995 
8996 	wmi_handle->wmi_ab = &ab->wmi_ab;
8997 
8998 	ab->wmi_ab.ab = ab;
8999 	/* TODO: Init remaining resource specific to pdev */
9000 
9001 	return 0;
9002 }
9003 
9004 int ath11k_wmi_attach(struct ath11k_base *ab)
9005 {
9006 	int ret;
9007 
9008 	ret = ath11k_wmi_pdev_attach(ab, 0);
9009 	if (ret)
9010 		return ret;
9011 
9012 	ab->wmi_ab.ab = ab;
9013 	ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
9014 
9015 	/* It's overwritten when service_ext_ready is handled */
9016 	if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1)
9017 		ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
9018 
9019 	/* TODO: Init remaining wmi soc resources required */
9020 	init_completion(&ab->wmi_ab.service_ready);
9021 	init_completion(&ab->wmi_ab.unified_ready);
9022 
9023 	return 0;
9024 }
9025 
9026 void ath11k_wmi_detach(struct ath11k_base *ab)
9027 {
9028 	int i;
9029 
9030 	/* TODO: Deinit wmi resource specific to SOC as required */
9031 
9032 	for (i = 0; i < ab->htc.wmi_ep_count; i++)
9033 		ath11k_wmi_pdev_detach(ab, i);
9034 
9035 	ath11k_wmi_free_dbring_caps(ab);
9036 }
9037 
9038 int ath11k_wmi_hw_data_filter_cmd(struct ath11k *ar, u32 vdev_id,
9039 				  u32 filter_bitmap, bool enable)
9040 {
9041 	struct wmi_hw_data_filter_cmd *cmd;
9042 	struct sk_buff *skb;
9043 	int len;
9044 
9045 	len = sizeof(*cmd);
9046 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9047 
9048 	if (!skb)
9049 		return -ENOMEM;
9050 
9051 	cmd = (struct wmi_hw_data_filter_cmd *)skb->data;
9052 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_HW_DATA_FILTER_CMD) |
9053 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9054 
9055 	cmd->vdev_id = vdev_id;
9056 	cmd->enable = enable;
9057 
9058 	/* Set all modes in case of disable */
9059 	if (cmd->enable)
9060 		cmd->hw_filter_bitmap = filter_bitmap;
9061 	else
9062 		cmd->hw_filter_bitmap = ((u32)~0U);
9063 
9064 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9065 		   "hw data filter enable %d filter_bitmap 0x%x\n",
9066 		   enable, filter_bitmap);
9067 
9068 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_HW_DATA_FILTER_CMDID);
9069 }
9070 
9071 int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar)
9072 {
9073 	struct wmi_wow_host_wakeup_ind *cmd;
9074 	struct sk_buff *skb;
9075 	size_t len;
9076 
9077 	len = sizeof(*cmd);
9078 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9079 	if (!skb)
9080 		return -ENOMEM;
9081 
9082 	cmd = (struct wmi_wow_host_wakeup_ind *)skb->data;
9083 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9084 				     WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) |
9085 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9086 
9087 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow host wakeup ind\n");
9088 
9089 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
9090 }
9091 
9092 int ath11k_wmi_wow_enable(struct ath11k *ar)
9093 {
9094 	struct wmi_wow_enable_cmd *cmd;
9095 	struct sk_buff *skb;
9096 	int len;
9097 
9098 	len = sizeof(*cmd);
9099 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9100 	if (!skb)
9101 		return -ENOMEM;
9102 
9103 	cmd = (struct wmi_wow_enable_cmd *)skb->data;
9104 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) |
9105 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9106 
9107 	cmd->enable = 1;
9108 	cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
9109 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow enable\n");
9110 
9111 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID);
9112 }
9113 
9114 int ath11k_wmi_scan_prob_req_oui(struct ath11k *ar,
9115 				 const u8 mac_addr[ETH_ALEN])
9116 {
9117 	struct sk_buff *skb;
9118 	struct wmi_scan_prob_req_oui_cmd *cmd;
9119 	u32 prob_req_oui;
9120 	int len;
9121 
9122 	prob_req_oui = (((u32)mac_addr[0]) << 16) |
9123 		       (((u32)mac_addr[1]) << 8) | mac_addr[2];
9124 
9125 	len = sizeof(*cmd);
9126 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9127 	if (!skb)
9128 		return -ENOMEM;
9129 
9130 	cmd = (struct wmi_scan_prob_req_oui_cmd *)skb->data;
9131 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9132 				     WMI_TAG_SCAN_PROB_REQ_OUI_CMD) |
9133 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9134 	cmd->prob_req_oui = prob_req_oui;
9135 
9136 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "scan prob req oui %d\n",
9137 		   prob_req_oui);
9138 
9139 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SCAN_PROB_REQ_OUI_CMDID);
9140 }
9141 
9142 int ath11k_wmi_wow_add_wakeup_event(struct ath11k *ar, u32 vdev_id,
9143 				    enum wmi_wow_wakeup_event event,
9144 				u32 enable)
9145 {
9146 	struct wmi_wow_add_del_event_cmd *cmd;
9147 	struct sk_buff *skb;
9148 	size_t len;
9149 
9150 	len = sizeof(*cmd);
9151 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9152 	if (!skb)
9153 		return -ENOMEM;
9154 
9155 	cmd = (struct wmi_wow_add_del_event_cmd *)skb->data;
9156 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ADD_DEL_EVT_CMD) |
9157 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9158 
9159 	cmd->vdev_id = vdev_id;
9160 	cmd->is_add = enable;
9161 	cmd->event_bitmap = (1 << event);
9162 
9163 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow add wakeup event %s enable %d vdev_id %d\n",
9164 		   wow_wakeup_event(event), enable, vdev_id);
9165 
9166 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
9167 }
9168 
9169 int ath11k_wmi_wow_add_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id,
9170 			       const u8 *pattern, const u8 *mask,
9171 			   int pattern_len, int pattern_offset)
9172 {
9173 	struct wmi_wow_add_pattern_cmd *cmd;
9174 	struct wmi_wow_bitmap_pattern *bitmap;
9175 	struct wmi_tlv *tlv;
9176 	struct sk_buff *skb;
9177 	u8 *ptr;
9178 	size_t len;
9179 
9180 	len = sizeof(*cmd) +
9181 	      sizeof(*tlv) +			/* array struct */
9182 	      sizeof(*bitmap) +			/* bitmap */
9183 	      sizeof(*tlv) +			/* empty ipv4 sync */
9184 	      sizeof(*tlv) +			/* empty ipv6 sync */
9185 	      sizeof(*tlv) +			/* empty magic */
9186 	      sizeof(*tlv) +			/* empty info timeout */
9187 	      sizeof(*tlv) + sizeof(u32);	/* ratelimit interval */
9188 
9189 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9190 	if (!skb)
9191 		return -ENOMEM;
9192 
9193 	/* cmd */
9194 	ptr = (u8 *)skb->data;
9195 	cmd = (struct wmi_wow_add_pattern_cmd *)ptr;
9196 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9197 				     WMI_TAG_WOW_ADD_PATTERN_CMD) |
9198 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9199 
9200 	cmd->vdev_id = vdev_id;
9201 	cmd->pattern_id = pattern_id;
9202 	cmd->pattern_type = WOW_BITMAP_PATTERN;
9203 
9204 	ptr += sizeof(*cmd);
9205 
9206 	/* bitmap */
9207 	tlv = (struct wmi_tlv *)ptr;
9208 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9209 				 WMI_TAG_ARRAY_STRUCT) |
9210 		      FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap));
9211 
9212 	ptr += sizeof(*tlv);
9213 
9214 	bitmap = (struct wmi_wow_bitmap_pattern *)ptr;
9215 	bitmap->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9216 					WMI_TAG_WOW_BITMAP_PATTERN_T) |
9217 			     FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap) - TLV_HDR_SIZE);
9218 
9219 	memcpy(bitmap->patternbuf, pattern, pattern_len);
9220 	ath11k_ce_byte_swap(bitmap->patternbuf, roundup(pattern_len, 4));
9221 	memcpy(bitmap->bitmaskbuf, mask, pattern_len);
9222 	ath11k_ce_byte_swap(bitmap->bitmaskbuf, roundup(pattern_len, 4));
9223 	bitmap->pattern_offset = pattern_offset;
9224 	bitmap->pattern_len = pattern_len;
9225 	bitmap->bitmask_len = pattern_len;
9226 	bitmap->pattern_id = pattern_id;
9227 
9228 	ptr += sizeof(*bitmap);
9229 
9230 	/* ipv4 sync */
9231 	tlv = (struct wmi_tlv *)ptr;
9232 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9233 				 WMI_TAG_ARRAY_STRUCT) |
9234 		      FIELD_PREP(WMI_TLV_LEN, 0);
9235 
9236 	ptr += sizeof(*tlv);
9237 
9238 	/* ipv6 sync */
9239 	tlv = (struct wmi_tlv *)ptr;
9240 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9241 				 WMI_TAG_ARRAY_STRUCT) |
9242 		      FIELD_PREP(WMI_TLV_LEN, 0);
9243 
9244 	ptr += sizeof(*tlv);
9245 
9246 	/* magic */
9247 	tlv = (struct wmi_tlv *)ptr;
9248 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9249 				 WMI_TAG_ARRAY_STRUCT) |
9250 		      FIELD_PREP(WMI_TLV_LEN, 0);
9251 
9252 	ptr += sizeof(*tlv);
9253 
9254 	/* pattern info timeout */
9255 	tlv = (struct wmi_tlv *)ptr;
9256 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9257 				 WMI_TAG_ARRAY_UINT32) |
9258 		      FIELD_PREP(WMI_TLV_LEN, 0);
9259 
9260 	ptr += sizeof(*tlv);
9261 
9262 	/* ratelimit interval */
9263 	tlv = (struct wmi_tlv *)ptr;
9264 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9265 				 WMI_TAG_ARRAY_UINT32) |
9266 		      FIELD_PREP(WMI_TLV_LEN, sizeof(u32));
9267 
9268 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow add pattern vdev_id %d pattern_id %d pattern_offset %d\n",
9269 		   vdev_id, pattern_id, pattern_offset);
9270 
9271 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ADD_WAKE_PATTERN_CMDID);
9272 }
9273 
9274 int ath11k_wmi_wow_del_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id)
9275 {
9276 	struct wmi_wow_del_pattern_cmd *cmd;
9277 	struct sk_buff *skb;
9278 	size_t len;
9279 
9280 	len = sizeof(*cmd);
9281 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9282 	if (!skb)
9283 		return -ENOMEM;
9284 
9285 	cmd = (struct wmi_wow_del_pattern_cmd *)skb->data;
9286 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9287 				     WMI_TAG_WOW_DEL_PATTERN_CMD) |
9288 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9289 
9290 	cmd->vdev_id = vdev_id;
9291 	cmd->pattern_id = pattern_id;
9292 	cmd->pattern_type = WOW_BITMAP_PATTERN;
9293 
9294 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow del pattern vdev_id %d pattern_id %d\n",
9295 		   vdev_id, pattern_id);
9296 
9297 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_DEL_WAKE_PATTERN_CMDID);
9298 }
9299 
9300 static struct sk_buff *
9301 ath11k_wmi_op_gen_config_pno_start(struct ath11k *ar,
9302 				   u32 vdev_id,
9303 				       struct wmi_pno_scan_req *pno)
9304 {
9305 	struct nlo_configured_parameters *nlo_list;
9306 	struct wmi_wow_nlo_config_cmd *cmd;
9307 	struct wmi_tlv *tlv;
9308 	struct sk_buff *skb;
9309 	u32 *channel_list;
9310 	size_t len, nlo_list_len, channel_list_len;
9311 	u8 *ptr;
9312 	u32 i;
9313 
9314 	len = sizeof(*cmd) +
9315 	      sizeof(*tlv) +
9316 	      /* TLV place holder for array of structures
9317 	       * nlo_configured_parameters(nlo_list)
9318 	       */
9319 	      sizeof(*tlv);
9320 	      /* TLV place holder for array of uint32 channel_list */
9321 
9322 	channel_list_len = sizeof(u32) * pno->a_networks[0].channel_count;
9323 	len += channel_list_len;
9324 
9325 	nlo_list_len = sizeof(*nlo_list) * pno->uc_networks_count;
9326 	len += nlo_list_len;
9327 
9328 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9329 	if (!skb)
9330 		return ERR_PTR(-ENOMEM);
9331 
9332 	ptr = (u8 *)skb->data;
9333 	cmd = (struct wmi_wow_nlo_config_cmd *)ptr;
9334 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
9335 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9336 
9337 	cmd->vdev_id = pno->vdev_id;
9338 	cmd->flags = WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN;
9339 
9340 	/* current FW does not support min-max range for dwell time */
9341 	cmd->active_dwell_time = pno->active_max_time;
9342 	cmd->passive_dwell_time = pno->passive_max_time;
9343 
9344 	if (pno->do_passive_scan)
9345 		cmd->flags |= WMI_NLO_CONFIG_SCAN_PASSIVE;
9346 
9347 	cmd->fast_scan_period = pno->fast_scan_period;
9348 	cmd->slow_scan_period = pno->slow_scan_period;
9349 	cmd->fast_scan_max_cycles = pno->fast_scan_max_cycles;
9350 	cmd->delay_start_time = pno->delay_start_time;
9351 
9352 	if (pno->enable_pno_scan_randomization) {
9353 		cmd->flags |= WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
9354 				WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ;
9355 		ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
9356 		ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
9357 		ath11k_ce_byte_swap(cmd->mac_addr.addr, 8);
9358 		ath11k_ce_byte_swap(cmd->mac_mask.addr, 8);
9359 	}
9360 
9361 	ptr += sizeof(*cmd);
9362 
9363 	/* nlo_configured_parameters(nlo_list) */
9364 	cmd->no_of_ssids = pno->uc_networks_count;
9365 	tlv = (struct wmi_tlv *)ptr;
9366 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
9367 				 WMI_TAG_ARRAY_STRUCT) |
9368 		      FIELD_PREP(WMI_TLV_LEN, nlo_list_len);
9369 
9370 	ptr += sizeof(*tlv);
9371 	nlo_list = (struct nlo_configured_parameters *)ptr;
9372 	for (i = 0; i < cmd->no_of_ssids; i++) {
9373 		tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
9374 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9375 			      FIELD_PREP(WMI_TLV_LEN, sizeof(*nlo_list) - sizeof(*tlv));
9376 
9377 		nlo_list[i].ssid.valid = true;
9378 		nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
9379 		memcpy(nlo_list[i].ssid.ssid.ssid,
9380 		       pno->a_networks[i].ssid.ssid,
9381 		       nlo_list[i].ssid.ssid.ssid_len);
9382 		ath11k_ce_byte_swap(nlo_list[i].ssid.ssid.ssid,
9383 				    roundup(nlo_list[i].ssid.ssid.ssid_len, 4));
9384 
9385 		if (pno->a_networks[i].rssi_threshold &&
9386 		    pno->a_networks[i].rssi_threshold > -300) {
9387 			nlo_list[i].rssi_cond.valid = true;
9388 			nlo_list[i].rssi_cond.rssi =
9389 				pno->a_networks[i].rssi_threshold;
9390 		}
9391 
9392 		nlo_list[i].bcast_nw_type.valid = true;
9393 		nlo_list[i].bcast_nw_type.bcast_nw_type =
9394 			pno->a_networks[i].bcast_nw_type;
9395 	}
9396 
9397 	ptr += nlo_list_len;
9398 	cmd->num_of_channels = pno->a_networks[0].channel_count;
9399 	tlv = (struct wmi_tlv *)ptr;
9400 	tlv->header =  FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
9401 		       FIELD_PREP(WMI_TLV_LEN, channel_list_len);
9402 	ptr += sizeof(*tlv);
9403 	channel_list = (u32 *)ptr;
9404 	for (i = 0; i < cmd->num_of_channels; i++)
9405 		channel_list[i] = pno->a_networks[0].channels[i];
9406 
9407 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv start pno config vdev_id %d\n",
9408 		   vdev_id);
9409 
9410 	return skb;
9411 }
9412 
9413 static struct sk_buff *ath11k_wmi_op_gen_config_pno_stop(struct ath11k *ar,
9414 							 u32 vdev_id)
9415 {
9416 	struct wmi_wow_nlo_config_cmd *cmd;
9417 	struct sk_buff *skb;
9418 	size_t len;
9419 
9420 	len = sizeof(*cmd);
9421 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9422 	if (!skb)
9423 		return ERR_PTR(-ENOMEM);
9424 
9425 	cmd = (struct wmi_wow_nlo_config_cmd *)skb->data;
9426 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
9427 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
9428 
9429 	cmd->vdev_id = vdev_id;
9430 	cmd->flags = WMI_NLO_CONFIG_STOP;
9431 
9432 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9433 		   "tlv stop pno config vdev_id %d\n", vdev_id);
9434 	return skb;
9435 }
9436 
9437 int ath11k_wmi_wow_config_pno(struct ath11k *ar, u32 vdev_id,
9438 			      struct wmi_pno_scan_req  *pno_scan)
9439 {
9440 	struct sk_buff *skb;
9441 
9442 	if (pno_scan->enable)
9443 		skb = ath11k_wmi_op_gen_config_pno_start(ar, vdev_id, pno_scan);
9444 	else
9445 		skb = ath11k_wmi_op_gen_config_pno_stop(ar, vdev_id);
9446 
9447 	if (IS_ERR_OR_NULL(skb))
9448 		return -ENOMEM;
9449 
9450 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
9451 }
9452 
9453 static void ath11k_wmi_fill_ns_offload(struct ath11k *ar,
9454 				       struct ath11k_arp_ns_offload *offload,
9455 				       u8 **ptr,
9456 				       bool enable,
9457 				       bool ext)
9458 {
9459 	struct wmi_ns_offload_tuple *ns;
9460 	struct wmi_tlv *tlv;
9461 	u8 *buf_ptr = *ptr;
9462 	u32 ns_cnt, ns_ext_tuples;
9463 	int i, max_offloads;
9464 
9465 	ns_cnt = offload->ipv6_count;
9466 
9467 	tlv  = (struct wmi_tlv *)buf_ptr;
9468 
9469 	if (ext) {
9470 		ns_ext_tuples = offload->ipv6_count - WMI_MAX_NS_OFFLOADS;
9471 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9472 			      FIELD_PREP(WMI_TLV_LEN, ns_ext_tuples * sizeof(*ns));
9473 		i = WMI_MAX_NS_OFFLOADS;
9474 		max_offloads = offload->ipv6_count;
9475 	} else {
9476 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9477 			      FIELD_PREP(WMI_TLV_LEN, WMI_MAX_NS_OFFLOADS * sizeof(*ns));
9478 		i = 0;
9479 		max_offloads = WMI_MAX_NS_OFFLOADS;
9480 	}
9481 
9482 	buf_ptr += sizeof(*tlv);
9483 
9484 	for (; i < max_offloads; i++) {
9485 		ns = (struct wmi_ns_offload_tuple *)buf_ptr;
9486 		ns->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NS_OFFLOAD_TUPLE) |
9487 				 FIELD_PREP(WMI_TLV_LEN, sizeof(*ns) - TLV_HDR_SIZE);
9488 
9489 		if (enable) {
9490 			if (i < ns_cnt)
9491 				ns->flags |= WMI_NSOL_FLAGS_VALID;
9492 
9493 			memcpy(ns->target_ipaddr[0], offload->ipv6_addr[i], 16);
9494 			memcpy(ns->solicitation_ipaddr, offload->self_ipv6_addr[i], 16);
9495 			ath11k_ce_byte_swap(ns->target_ipaddr[0], 16);
9496 			ath11k_ce_byte_swap(ns->solicitation_ipaddr, 16);
9497 
9498 			if (offload->ipv6_type[i])
9499 				ns->flags |= WMI_NSOL_FLAGS_IS_IPV6_ANYCAST;
9500 
9501 			memcpy(ns->target_mac.addr, offload->mac_addr, ETH_ALEN);
9502 			ath11k_ce_byte_swap(ns->target_mac.addr, 8);
9503 
9504 			if (ns->target_mac.word0 != 0 ||
9505 			    ns->target_mac.word1 != 0) {
9506 				ns->flags |= WMI_NSOL_FLAGS_MAC_VALID;
9507 			}
9508 
9509 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9510 				   "index %d ns_solicited %pI6 target %pI6",
9511 				   i, ns->solicitation_ipaddr,
9512 				   ns->target_ipaddr[0]);
9513 		}
9514 
9515 		buf_ptr += sizeof(*ns);
9516 	}
9517 
9518 	*ptr = buf_ptr;
9519 }
9520 
9521 static void ath11k_wmi_fill_arp_offload(struct ath11k *ar,
9522 					struct ath11k_arp_ns_offload *offload,
9523 					u8 **ptr,
9524 					bool enable)
9525 {
9526 	struct wmi_arp_offload_tuple *arp;
9527 	struct wmi_tlv *tlv;
9528 	u8 *buf_ptr = *ptr;
9529 	int i;
9530 
9531 	/* fill arp tuple */
9532 	tlv = (struct wmi_tlv *)buf_ptr;
9533 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9534 		      FIELD_PREP(WMI_TLV_LEN, WMI_MAX_ARP_OFFLOADS * sizeof(*arp));
9535 	buf_ptr += sizeof(*tlv);
9536 
9537 	for (i = 0; i < WMI_MAX_ARP_OFFLOADS; i++) {
9538 		arp = (struct wmi_arp_offload_tuple *)buf_ptr;
9539 		arp->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARP_OFFLOAD_TUPLE) |
9540 				  FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9541 
9542 		if (enable && i < offload->ipv4_count) {
9543 			/* Copy the target ip addr and flags */
9544 			arp->flags = WMI_ARPOL_FLAGS_VALID;
9545 			memcpy(arp->target_ipaddr, offload->ipv4_addr[i], 4);
9546 			ath11k_ce_byte_swap(arp->target_ipaddr, 4);
9547 
9548 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "arp offload address %pI4",
9549 				   arp->target_ipaddr);
9550 		}
9551 
9552 		buf_ptr += sizeof(*arp);
9553 	}
9554 
9555 	*ptr = buf_ptr;
9556 }
9557 
9558 int ath11k_wmi_arp_ns_offload(struct ath11k *ar,
9559 			      struct ath11k_vif *arvif, bool enable)
9560 {
9561 	struct ath11k_arp_ns_offload *offload;
9562 	struct wmi_set_arp_ns_offload_cmd *cmd;
9563 	struct wmi_tlv *tlv;
9564 	struct sk_buff *skb;
9565 	u8 *buf_ptr;
9566 	size_t len;
9567 	u8 ns_cnt, ns_ext_tuples = 0;
9568 
9569 	offload = &arvif->arp_ns_offload;
9570 	ns_cnt = offload->ipv6_count;
9571 
9572 	len = sizeof(*cmd) +
9573 	      sizeof(*tlv) +
9574 	      WMI_MAX_NS_OFFLOADS * sizeof(struct wmi_ns_offload_tuple) +
9575 	      sizeof(*tlv) +
9576 	      WMI_MAX_ARP_OFFLOADS * sizeof(struct wmi_arp_offload_tuple);
9577 
9578 	if (ns_cnt > WMI_MAX_NS_OFFLOADS) {
9579 		ns_ext_tuples = ns_cnt - WMI_MAX_NS_OFFLOADS;
9580 		len += sizeof(*tlv) +
9581 		       ns_ext_tuples * sizeof(struct wmi_ns_offload_tuple);
9582 	}
9583 
9584 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9585 	if (!skb)
9586 		return -ENOMEM;
9587 
9588 	buf_ptr = skb->data;
9589 	cmd = (struct wmi_set_arp_ns_offload_cmd *)buf_ptr;
9590 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9591 				     WMI_TAG_SET_ARP_NS_OFFLOAD_CMD) |
9592 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9593 
9594 	cmd->flags = 0;
9595 	cmd->vdev_id = arvif->vdev_id;
9596 	cmd->num_ns_ext_tuples = ns_ext_tuples;
9597 
9598 	buf_ptr += sizeof(*cmd);
9599 
9600 	ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 0);
9601 	ath11k_wmi_fill_arp_offload(ar, offload, &buf_ptr, enable);
9602 
9603 	if (ns_ext_tuples)
9604 		ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 1);
9605 
9606 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SET_ARP_NS_OFFLOAD_CMDID);
9607 }
9608 
9609 int ath11k_wmi_gtk_rekey_offload(struct ath11k *ar,
9610 				 struct ath11k_vif *arvif, bool enable)
9611 {
9612 	struct wmi_gtk_rekey_offload_cmd *cmd;
9613 	struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
9614 	int len;
9615 	struct sk_buff *skb;
9616 	__le64 replay_ctr;
9617 
9618 	len = sizeof(*cmd);
9619 	skb =  ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9620 	if (!skb)
9621 		return -ENOMEM;
9622 
9623 	cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9624 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9625 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9626 
9627 	cmd->vdev_id = arvif->vdev_id;
9628 
9629 	if (enable) {
9630 		cmd->flags = GTK_OFFLOAD_ENABLE_OPCODE;
9631 
9632 		/* the length in rekey_data and cmd is equal */
9633 		memcpy(cmd->kck, rekey_data->kck, sizeof(cmd->kck));
9634 		ath11k_ce_byte_swap(cmd->kck, GTK_OFFLOAD_KEK_BYTES);
9635 		memcpy(cmd->kek, rekey_data->kek, sizeof(cmd->kek));
9636 		ath11k_ce_byte_swap(cmd->kek, GTK_OFFLOAD_KEK_BYTES);
9637 
9638 		replay_ctr = cpu_to_le64(rekey_data->replay_ctr);
9639 		memcpy(cmd->replay_ctr, &replay_ctr,
9640 		       sizeof(replay_ctr));
9641 		ath11k_ce_byte_swap(cmd->replay_ctr, GTK_REPLAY_COUNTER_BYTES);
9642 	} else {
9643 		cmd->flags = GTK_OFFLOAD_DISABLE_OPCODE;
9644 	}
9645 
9646 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "offload gtk rekey vdev: %d %d\n",
9647 		   arvif->vdev_id, enable);
9648 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9649 }
9650 
9651 int ath11k_wmi_gtk_rekey_getinfo(struct ath11k *ar,
9652 				 struct ath11k_vif *arvif)
9653 {
9654 	struct wmi_gtk_rekey_offload_cmd *cmd;
9655 	int len;
9656 	struct sk_buff *skb;
9657 
9658 	len = sizeof(*cmd);
9659 	skb =  ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9660 	if (!skb)
9661 		return -ENOMEM;
9662 
9663 	cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9664 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9665 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9666 
9667 	cmd->vdev_id = arvif->vdev_id;
9668 	cmd->flags = GTK_OFFLOAD_REQUEST_STATUS_OPCODE;
9669 
9670 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "get gtk rekey vdev_id: %d\n",
9671 		   arvif->vdev_id);
9672 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9673 }
9674 
9675 int ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k *ar, const u8 *sar_val)
9676 {	struct ath11k_pdev_wmi *wmi = ar->wmi;
9677 	struct wmi_pdev_set_sar_table_cmd *cmd;
9678 	struct wmi_tlv *tlv;
9679 	struct sk_buff *skb;
9680 	u8 *buf_ptr;
9681 	u32 len, sar_len_aligned, rsvd_len_aligned;
9682 
9683 	sar_len_aligned = roundup(BIOS_SAR_TABLE_LEN, sizeof(u32));
9684 	rsvd_len_aligned = roundup(BIOS_SAR_RSVD1_LEN, sizeof(u32));
9685 	len = sizeof(*cmd) +
9686 	      TLV_HDR_SIZE + sar_len_aligned +
9687 	      TLV_HDR_SIZE + rsvd_len_aligned;
9688 
9689 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9690 	if (!skb)
9691 		return -ENOMEM;
9692 
9693 	cmd = (struct wmi_pdev_set_sar_table_cmd *)skb->data;
9694 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_SAR_TABLE_CMD) |
9695 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9696 	cmd->pdev_id = ar->pdev->pdev_id;
9697 	cmd->sar_len = BIOS_SAR_TABLE_LEN;
9698 	cmd->rsvd_len = BIOS_SAR_RSVD1_LEN;
9699 
9700 	buf_ptr = skb->data + sizeof(*cmd);
9701 	tlv = (struct wmi_tlv *)buf_ptr;
9702 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9703 		      FIELD_PREP(WMI_TLV_LEN, sar_len_aligned);
9704 	buf_ptr += TLV_HDR_SIZE;
9705 	memcpy(buf_ptr, sar_val, BIOS_SAR_TABLE_LEN);
9706 
9707 	buf_ptr += sar_len_aligned;
9708 	tlv = (struct wmi_tlv *)buf_ptr;
9709 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9710 		      FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9711 
9712 	return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_SAR_TABLE_CMDID);
9713 }
9714 
9715 int ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k *ar)
9716 {
9717 	struct ath11k_pdev_wmi *wmi = ar->wmi;
9718 	struct wmi_pdev_set_geo_table_cmd *cmd;
9719 	struct wmi_tlv *tlv;
9720 	struct sk_buff *skb;
9721 	u8 *buf_ptr;
9722 	u32 len, rsvd_len_aligned;
9723 
9724 	rsvd_len_aligned = roundup(BIOS_SAR_RSVD2_LEN, sizeof(u32));
9725 	len = sizeof(*cmd) + TLV_HDR_SIZE + rsvd_len_aligned;
9726 
9727 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9728 	if (!skb)
9729 		return -ENOMEM;
9730 
9731 	cmd = (struct wmi_pdev_set_geo_table_cmd *)skb->data;
9732 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_GEO_TABLE_CMD) |
9733 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9734 	cmd->pdev_id = ar->pdev->pdev_id;
9735 	cmd->rsvd_len = BIOS_SAR_RSVD2_LEN;
9736 
9737 	buf_ptr = skb->data + sizeof(*cmd);
9738 	tlv = (struct wmi_tlv *)buf_ptr;
9739 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9740 		      FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9741 
9742 	return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_GEO_TABLE_CMDID);
9743 }
9744 
9745 int ath11k_wmi_sta_keepalive(struct ath11k *ar,
9746 			     const struct wmi_sta_keepalive_arg *arg)
9747 {
9748 	struct ath11k_pdev_wmi *wmi = ar->wmi;
9749 	struct wmi_sta_keepalive_cmd *cmd;
9750 	struct wmi_sta_keepalive_arp_resp *arp;
9751 	struct sk_buff *skb;
9752 	size_t len;
9753 
9754 	len = sizeof(*cmd) + sizeof(*arp);
9755 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9756 	if (!skb)
9757 		return -ENOMEM;
9758 
9759 	cmd = (struct wmi_sta_keepalive_cmd *)skb->data;
9760 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9761 				     WMI_TAG_STA_KEEPALIVE_CMD) |
9762 				     FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9763 	cmd->vdev_id = arg->vdev_id;
9764 	cmd->enabled = arg->enabled;
9765 	cmd->interval = arg->interval;
9766 	cmd->method = arg->method;
9767 
9768 	arp = (struct wmi_sta_keepalive_arp_resp *)(cmd + 1);
9769 	arp->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9770 				     WMI_TAG_STA_KEEPALIVE_ARP_RESPONSE) |
9771 			 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9772 
9773 	if (arg->method == WMI_STA_KEEPALIVE_METHOD_UNSOLICITED_ARP_RESPONSE ||
9774 	    arg->method == WMI_STA_KEEPALIVE_METHOD_GRATUITOUS_ARP_REQUEST) {
9775 		arp->src_ip4_addr = arg->src_ip4_addr;
9776 		arp->dest_ip4_addr = arg->dest_ip4_addr;
9777 		ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
9778 	}
9779 
9780 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9781 		   "sta keepalive vdev %d enabled %d method %d interval %d\n",
9782 		   arg->vdev_id, arg->enabled, arg->method, arg->interval);
9783 
9784 	return ath11k_wmi_cmd_send(wmi, skb, WMI_STA_KEEPALIVE_CMDID);
9785 }
9786