xref: /openbmc/linux/drivers/net/wireless/ath/ath11k/wmi.c (revision b7b6f86149a7e06269d61a7a5206360f5b642f80)
1d5c65159SKalle Valo // SPDX-License-Identifier: BSD-3-Clause-Clear
2d5c65159SKalle Valo /*
3d5c65159SKalle Valo  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4b6f63010SManikanta Pubbisetty  * Copyright (c) 2021, Qualcomm Innovation Center, Inc. All rights reserved.
5d5c65159SKalle Valo  */
6d5c65159SKalle Valo #include <linux/skbuff.h>
7d5c65159SKalle Valo #include <linux/ctype.h>
8d5c65159SKalle Valo #include <net/mac80211.h>
9d5c65159SKalle Valo #include <net/cfg80211.h>
10d5c65159SKalle Valo #include <linux/completion.h>
11d5c65159SKalle Valo #include <linux/if_ether.h>
12d5c65159SKalle Valo #include <linux/types.h>
13d5c65159SKalle Valo #include <linux/pci.h>
14d5c65159SKalle Valo #include <linux/uuid.h>
15d5c65159SKalle Valo #include <linux/time.h>
16d5c65159SKalle Valo #include <linux/of.h>
17d5c65159SKalle Valo #include "core.h"
18d5c65159SKalle Valo #include "debug.h"
19d5c65159SKalle Valo #include "mac.h"
20d5c65159SKalle Valo #include "hw.h"
21d5c65159SKalle Valo #include "peer.h"
22d5c65159SKalle Valo 
23d5c65159SKalle Valo struct wmi_tlv_policy {
24d5c65159SKalle Valo 	size_t min_len;
25d5c65159SKalle Valo };
26d5c65159SKalle Valo 
27d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse {
28d5c65159SKalle Valo 	bool wmi_svc_bitmap_done;
29d5c65159SKalle Valo };
30d5c65159SKalle Valo 
31bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse {
32bd647855SKarthikeyan Periyasamy 	struct wmi_dma_ring_capabilities *dma_ring_caps;
33bd647855SKarthikeyan Periyasamy 	u32 n_dma_ring_caps;
34bd647855SKarthikeyan Periyasamy };
35bd647855SKarthikeyan Periyasamy 
36d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse {
37d5c65159SKalle Valo 	struct ath11k_service_ext_param param;
38d5c65159SKalle Valo 	struct wmi_soc_mac_phy_hw_mode_caps *hw_caps;
39d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
40d5c65159SKalle Valo 	u32 n_hw_mode_caps;
41d5c65159SKalle Valo 	u32 tot_phy_id;
42d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities pref_hw_mode_caps;
43d5c65159SKalle Valo 	struct wmi_mac_phy_capabilities *mac_phy_caps;
44d5c65159SKalle Valo 	u32 n_mac_phy_caps;
45d5c65159SKalle Valo 	struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps;
46d5c65159SKalle Valo 	struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps;
47d5c65159SKalle Valo 	u32 n_ext_hal_reg_caps;
48bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
49d5c65159SKalle Valo 	bool hw_mode_done;
50d5c65159SKalle Valo 	bool mac_phy_done;
51d5c65159SKalle Valo 	bool ext_hal_reg_done;
52bd647855SKarthikeyan Periyasamy 	bool mac_phy_chainmask_combo_done;
53bd647855SKarthikeyan Periyasamy 	bool mac_phy_chainmask_cap_done;
54bd647855SKarthikeyan Periyasamy 	bool oem_dma_ring_cap_done;
55bd647855SKarthikeyan Periyasamy 	bool dma_ring_cap_done;
56bd647855SKarthikeyan Periyasamy };
57bd647855SKarthikeyan Periyasamy 
58bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse {
59bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
60bd647855SKarthikeyan Periyasamy 	bool dma_ring_cap_done;
61d5c65159SKalle Valo };
62d5c65159SKalle Valo 
63d5c65159SKalle Valo struct wmi_tlv_rdy_parse {
64d5c65159SKalle Valo 	u32 num_extra_mac_addr;
65d5c65159SKalle Valo };
66d5c65159SKalle Valo 
679d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse {
689d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_dma_buf_release_fixed_param fixed;
699d11b7bfSKarthikeyan Periyasamy 	struct wmi_dma_buf_release_entry *buf_entry;
709d11b7bfSKarthikeyan Periyasamy 	struct wmi_dma_buf_release_meta_data *meta_data;
719d11b7bfSKarthikeyan Periyasamy 	u32 num_buf_entry;
729d11b7bfSKarthikeyan Periyasamy 	u32 num_meta;
739d11b7bfSKarthikeyan Periyasamy 	bool buf_entry_done;
749d11b7bfSKarthikeyan Periyasamy 	bool meta_data_done;
759d11b7bfSKarthikeyan Periyasamy };
769d11b7bfSKarthikeyan Periyasamy 
77b488c766SWen Gong struct wmi_tlv_fw_stats_parse {
78b488c766SWen Gong 	const struct wmi_stats_event *ev;
79b488c766SWen Gong 	const struct wmi_per_chain_rssi_stats *rssi;
80b488c766SWen Gong 	struct ath11k_fw_stats *stats;
81b488c766SWen Gong 	int rssi_num;
82b488c766SWen Gong 	bool chain_rssi_done;
83b488c766SWen Gong };
84b488c766SWen Gong 
85d5c65159SKalle Valo static const struct wmi_tlv_policy wmi_tlv_policies[] = {
86d5c65159SKalle Valo 	[WMI_TAG_ARRAY_BYTE]
87d5c65159SKalle Valo 		= { .min_len = 0 },
88d5c65159SKalle Valo 	[WMI_TAG_ARRAY_UINT32]
89d5c65159SKalle Valo 		= { .min_len = 0 },
90d5c65159SKalle Valo 	[WMI_TAG_SERVICE_READY_EVENT]
91d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_service_ready_event) },
92d5c65159SKalle Valo 	[WMI_TAG_SERVICE_READY_EXT_EVENT]
93d5c65159SKalle Valo 		= { .min_len =  sizeof(struct wmi_service_ready_ext_event) },
94d5c65159SKalle Valo 	[WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS]
95d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) },
96d5c65159SKalle Valo 	[WMI_TAG_SOC_HAL_REG_CAPABILITIES]
97d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) },
98d5c65159SKalle Valo 	[WMI_TAG_VDEV_START_RESPONSE_EVENT]
99d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_start_resp_event) },
100d5c65159SKalle Valo 	[WMI_TAG_PEER_DELETE_RESP_EVENT]
101d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_delete_resp_event) },
102d5c65159SKalle Valo 	[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]
103d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_bcn_tx_status_event) },
104d5c65159SKalle Valo 	[WMI_TAG_VDEV_STOPPED_EVENT]
105d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_stopped_event) },
106d5c65159SKalle Valo 	[WMI_TAG_REG_CHAN_LIST_CC_EVENT]
107d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) },
108d5c65159SKalle Valo 	[WMI_TAG_MGMT_RX_HDR]
109d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_mgmt_rx_hdr) },
110d5c65159SKalle Valo 	[WMI_TAG_MGMT_TX_COMPL_EVENT]
111d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) },
112d5c65159SKalle Valo 	[WMI_TAG_SCAN_EVENT]
113d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_scan_event) },
114d5c65159SKalle Valo 	[WMI_TAG_PEER_STA_KICKOUT_EVENT]
115d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
116d5c65159SKalle Valo 	[WMI_TAG_ROAM_EVENT]
117d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_roam_event) },
118d5c65159SKalle Valo 	[WMI_TAG_CHAN_INFO_EVENT]
119d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_chan_info_event) },
120d5c65159SKalle Valo 	[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]
121d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) },
122d5c65159SKalle Valo 	[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]
123d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) },
12421c1b063SMaharaja Kennadyrajan 	[WMI_TAG_READY_EVENT] = {
12521c1b063SMaharaja Kennadyrajan 		.min_len = sizeof(struct wmi_ready_event_min) },
126d5c65159SKalle Valo 	[WMI_TAG_SERVICE_AVAILABLE_EVENT]
127d5c65159SKalle Valo 		= {.min_len = sizeof(struct wmi_service_available_event) },
128d5c65159SKalle Valo 	[WMI_TAG_PEER_ASSOC_CONF_EVENT]
129d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_assoc_conf_event) },
130d5c65159SKalle Valo 	[WMI_TAG_STATS_EVENT]
131d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_stats_event) },
132d5c65159SKalle Valo 	[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]
133d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) },
134047679e3SAloka Dixit 	[WMI_TAG_HOST_SWFDA_EVENT] = {
135047679e3SAloka Dixit 		.min_len = sizeof(struct wmi_fils_discovery_event) },
136047679e3SAloka Dixit 	[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT] = {
137047679e3SAloka Dixit 		.min_len = sizeof(struct wmi_probe_resp_tx_status_event) },
1383cbbdfbeSRitesh Singh 	[WMI_TAG_VDEV_DELETE_RESP_EVENT] = {
1393cbbdfbeSRitesh Singh 		.min_len = sizeof(struct wmi_vdev_delete_resp_event) },
140886433a9SJohn Crispin 	[WMI_TAG_OBSS_COLOR_COLLISION_EVT] = {
141886433a9SJohn Crispin 		.min_len = sizeof(struct wmi_obss_color_collision_event) },
1429dcf6808SWen Gong 	[WMI_TAG_11D_NEW_COUNTRY_EVENT] = {
1439dcf6808SWen Gong 		.min_len = sizeof(struct wmi_11d_new_cc_ev) },
144b488c766SWen Gong 	[WMI_TAG_PER_CHAIN_RSSI_STATS] = {
145b488c766SWen Gong 		.min_len = sizeof(struct wmi_per_chain_rssi_stats) },
1463d00e8b5SJohn Crispin 	[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT] = {
1473d00e8b5SJohn Crispin 		.min_len = sizeof(struct wmi_twt_add_dialog_event) },
148d5c65159SKalle Valo };
149d5c65159SKalle Valo 
150d5c65159SKalle Valo #define PRIMAP(_hw_mode_) \
151d5c65159SKalle Valo 	[_hw_mode_] = _hw_mode_##_PRI
152d5c65159SKalle Valo 
153d5c65159SKalle Valo static const int ath11k_hw_mode_pri_map[] = {
154d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SINGLE),
155d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS),
156d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE),
157d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SBS),
158d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS_SBS),
159d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS),
160d5c65159SKalle Valo 	/* keep last */
161d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_MAX),
162d5c65159SKalle Valo };
163d5c65159SKalle Valo 
164d5c65159SKalle Valo static int
165d5c65159SKalle Valo ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
166d5c65159SKalle Valo 		    int (*iter)(struct ath11k_base *ab, u16 tag, u16 len,
167d5c65159SKalle Valo 				const void *ptr, void *data),
168d5c65159SKalle Valo 		    void *data)
169d5c65159SKalle Valo {
170d5c65159SKalle Valo 	const void *begin = ptr;
171d5c65159SKalle Valo 	const struct wmi_tlv *tlv;
172d5c65159SKalle Valo 	u16 tlv_tag, tlv_len;
173d5c65159SKalle Valo 	int ret;
174d5c65159SKalle Valo 
175d5c65159SKalle Valo 	while (len > 0) {
176d5c65159SKalle Valo 		if (len < sizeof(*tlv)) {
177d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
178d5c65159SKalle Valo 				   ptr - begin, len, sizeof(*tlv));
179d5c65159SKalle Valo 			return -EINVAL;
180d5c65159SKalle Valo 		}
181d5c65159SKalle Valo 
182d5c65159SKalle Valo 		tlv = ptr;
183d5c65159SKalle Valo 		tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header);
184d5c65159SKalle Valo 		tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header);
185d5c65159SKalle Valo 		ptr += sizeof(*tlv);
186d5c65159SKalle Valo 		len -= sizeof(*tlv);
187d5c65159SKalle Valo 
188d5c65159SKalle Valo 		if (tlv_len > len) {
189bb2d2dfdSTom Rix 			ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n",
190d5c65159SKalle Valo 				   tlv_tag, ptr - begin, len, tlv_len);
191d5c65159SKalle Valo 			return -EINVAL;
192d5c65159SKalle Valo 		}
193d5c65159SKalle Valo 
194d5c65159SKalle Valo 		if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
195d5c65159SKalle Valo 		    wmi_tlv_policies[tlv_tag].min_len &&
196d5c65159SKalle Valo 		    wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
197bb2d2dfdSTom Rix 			ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%u bytes is less than min length %zu)\n",
198d5c65159SKalle Valo 				   tlv_tag, ptr - begin, tlv_len,
199d5c65159SKalle Valo 				   wmi_tlv_policies[tlv_tag].min_len);
200d5c65159SKalle Valo 			return -EINVAL;
201d5c65159SKalle Valo 		}
202d5c65159SKalle Valo 
203d5c65159SKalle Valo 		ret = iter(ab, tlv_tag, tlv_len, ptr, data);
204d5c65159SKalle Valo 		if (ret)
205d5c65159SKalle Valo 			return ret;
206d5c65159SKalle Valo 
207d5c65159SKalle Valo 		ptr += tlv_len;
208d5c65159SKalle Valo 		len -= tlv_len;
209d5c65159SKalle Valo 	}
210d5c65159SKalle Valo 
211d5c65159SKalle Valo 	return 0;
212d5c65159SKalle Valo }
213d5c65159SKalle Valo 
214d5c65159SKalle Valo static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len,
215d5c65159SKalle Valo 				     const void *ptr, void *data)
216d5c65159SKalle Valo {
217d5c65159SKalle Valo 	const void **tb = data;
218d5c65159SKalle Valo 
219d5c65159SKalle Valo 	if (tag < WMI_TAG_MAX)
220d5c65159SKalle Valo 		tb[tag] = ptr;
221d5c65159SKalle Valo 
222d5c65159SKalle Valo 	return 0;
223d5c65159SKalle Valo }
224d5c65159SKalle Valo 
225d5c65159SKalle Valo static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb,
226d5c65159SKalle Valo 				const void *ptr, size_t len)
227d5c65159SKalle Valo {
228d5c65159SKalle Valo 	return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse,
229d5c65159SKalle Valo 				   (void *)tb);
230d5c65159SKalle Valo }
231d5c65159SKalle Valo 
232d5c65159SKalle Valo static const void **
233d5c65159SKalle Valo ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr,
234d5c65159SKalle Valo 			   size_t len, gfp_t gfp)
235d5c65159SKalle Valo {
236d5c65159SKalle Valo 	const void **tb;
237d5c65159SKalle Valo 	int ret;
238d5c65159SKalle Valo 
239d5c65159SKalle Valo 	tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp);
240d5c65159SKalle Valo 	if (!tb)
241d5c65159SKalle Valo 		return ERR_PTR(-ENOMEM);
242d5c65159SKalle Valo 
243d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len);
244d5c65159SKalle Valo 	if (ret) {
245d5c65159SKalle Valo 		kfree(tb);
246d5c65159SKalle Valo 		return ERR_PTR(ret);
247d5c65159SKalle Valo 	}
248d5c65159SKalle Valo 
249d5c65159SKalle Valo 	return tb;
250d5c65159SKalle Valo }
251d5c65159SKalle Valo 
252d5c65159SKalle Valo static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
253d5c65159SKalle Valo 				      u32 cmd_id)
254d5c65159SKalle Valo {
255d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
2566bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
257d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
258d5c65159SKalle Valo 	int ret;
259d5c65159SKalle Valo 	u32 cmd = 0;
260d5c65159SKalle Valo 
261d5c65159SKalle Valo 	if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
262d5c65159SKalle Valo 		return -ENOMEM;
263d5c65159SKalle Valo 
264d5c65159SKalle Valo 	cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id);
265d5c65159SKalle Valo 
266d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
267d5c65159SKalle Valo 	cmd_hdr->cmd_id = cmd;
268d5c65159SKalle Valo 
269fb12305aSVenkateswara Naralasetty 	trace_ath11k_wmi_cmd(ab, cmd_id, skb->data, skb->len);
270fb12305aSVenkateswara Naralasetty 
271d5c65159SKalle Valo 	memset(skb_cb, 0, sizeof(*skb_cb));
272d5c65159SKalle Valo 	ret = ath11k_htc_send(&ab->htc, wmi->eid, skb);
273d5c65159SKalle Valo 
274d5c65159SKalle Valo 	if (ret)
275d5c65159SKalle Valo 		goto err_pull;
276d5c65159SKalle Valo 
277d5c65159SKalle Valo 	return 0;
278d5c65159SKalle Valo 
279d5c65159SKalle Valo err_pull:
280d5c65159SKalle Valo 	skb_pull(skb, sizeof(struct wmi_cmd_hdr));
281d5c65159SKalle Valo 	return ret;
282d5c65159SKalle Valo }
283d5c65159SKalle Valo 
284d5c65159SKalle Valo int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
285d5c65159SKalle Valo 			u32 cmd_id)
286d5c65159SKalle Valo {
2876bc9d6f7SJohn Crispin 	struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab;
288d5c65159SKalle Valo 	int ret = -EOPNOTSUPP;
289f951380aSP Praneesh 	struct ath11k_base *ab = wmi_sc->ab;
290d5c65159SKalle Valo 
291d5c65159SKalle Valo 	might_sleep();
292d5c65159SKalle Valo 
293f951380aSP Praneesh 	if (ab->hw_params.credit_flow) {
294d5c65159SKalle Valo 		wait_event_timeout(wmi_sc->tx_credits_wq, ({
295d5c65159SKalle Valo 			ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
296d5c65159SKalle Valo 
297f951380aSP Praneesh 			if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
298f951380aSP Praneesh 					    &wmi_sc->ab->dev_flags))
299d5c65159SKalle Valo 				ret = -ESHUTDOWN;
300d5c65159SKalle Valo 
301d5c65159SKalle Valo 			(ret != -EAGAIN);
302d5c65159SKalle Valo 			}), WMI_SEND_TIMEOUT_HZ);
303f951380aSP Praneesh 	} else {
304f951380aSP Praneesh 		wait_event_timeout(wmi->tx_ce_desc_wq, ({
305f951380aSP Praneesh 			ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
306f951380aSP Praneesh 
307f951380aSP Praneesh 			if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
308f951380aSP Praneesh 					    &wmi_sc->ab->dev_flags))
309f951380aSP Praneesh 				ret = -ESHUTDOWN;
310f951380aSP Praneesh 
311f951380aSP Praneesh 			(ret != -ENOBUFS);
312f951380aSP Praneesh 			}), WMI_SEND_TIMEOUT_HZ);
313f951380aSP Praneesh 	}
314d5c65159SKalle Valo 
315d5c65159SKalle Valo 	if (ret == -EAGAIN)
316d5c65159SKalle Valo 		ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id);
317d5c65159SKalle Valo 
318f951380aSP Praneesh 	if (ret == -ENOBUFS)
319f951380aSP Praneesh 		ath11k_warn(wmi_sc->ab, "ce desc not available for wmi command %d\n",
320f951380aSP Praneesh 			    cmd_id);
321f951380aSP Praneesh 
322d5c65159SKalle Valo 	return ret;
323d5c65159SKalle Valo }
324d5c65159SKalle Valo 
325d5c65159SKalle Valo static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
326d5c65159SKalle Valo 				     const void *ptr,
327d5c65159SKalle Valo 				     struct ath11k_service_ext_param *param)
328d5c65159SKalle Valo {
329d5c65159SKalle Valo 	const struct wmi_service_ready_ext_event *ev = ptr;
330d5c65159SKalle Valo 
331d5c65159SKalle Valo 	if (!ev)
332d5c65159SKalle Valo 		return -EINVAL;
333d5c65159SKalle Valo 
334d5c65159SKalle Valo 	/* Move this to host based bitmap */
335d5c65159SKalle Valo 	param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits;
336d5c65159SKalle Valo 	param->default_fw_config_bits =	ev->default_fw_config_bits;
337d5c65159SKalle Valo 	param->he_cap_info = ev->he_cap_info;
338d5c65159SKalle Valo 	param->mpdu_density = ev->mpdu_density;
339d5c65159SKalle Valo 	param->max_bssid_rx_filters = ev->max_bssid_rx_filters;
340d5c65159SKalle Valo 	memcpy(&param->ppet, &ev->ppet, sizeof(param->ppet));
341d5c65159SKalle Valo 
342d5c65159SKalle Valo 	return 0;
343d5c65159SKalle Valo }
344d5c65159SKalle Valo 
345d5c65159SKalle Valo static int
346d5c65159SKalle Valo ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
347d5c65159SKalle Valo 				      struct wmi_soc_mac_phy_hw_mode_caps *hw_caps,
348d5c65159SKalle Valo 				      struct wmi_hw_mode_capabilities *wmi_hw_mode_caps,
349d5c65159SKalle Valo 				      struct wmi_soc_hal_reg_capabilities *hal_reg_caps,
350d5c65159SKalle Valo 				      struct wmi_mac_phy_capabilities *wmi_mac_phy_caps,
351d5c65159SKalle Valo 				      u8 hw_mode_id, u8 phy_id,
352d5c65159SKalle Valo 				      struct ath11k_pdev *pdev)
353d5c65159SKalle Valo {
354d5c65159SKalle Valo 	struct wmi_mac_phy_capabilities *mac_phy_caps;
35513706340SWen Gong 	struct ath11k_base *ab = wmi_handle->wmi_ab->ab;
356d5c65159SKalle Valo 	struct ath11k_band_cap *cap_band;
357d5c65159SKalle Valo 	struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
358d5c65159SKalle Valo 	u32 phy_map;
359d5c65159SKalle Valo 	u32 hw_idx, phy_idx = 0;
360d5c65159SKalle Valo 
361d5c65159SKalle Valo 	if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps)
362d5c65159SKalle Valo 		return -EINVAL;
363d5c65159SKalle Valo 
364d5c65159SKalle Valo 	for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) {
365d5c65159SKalle Valo 		if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id)
366d5c65159SKalle Valo 			break;
367d5c65159SKalle Valo 
368d5c65159SKalle Valo 		phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map;
369d5c65159SKalle Valo 		while (phy_map) {
370d5c65159SKalle Valo 			phy_map >>= 1;
371d5c65159SKalle Valo 			phy_idx++;
372d5c65159SKalle Valo 		}
373d5c65159SKalle Valo 	}
374d5c65159SKalle Valo 
375d5c65159SKalle Valo 	if (hw_idx == hw_caps->num_hw_modes)
376d5c65159SKalle Valo 		return -EINVAL;
377d5c65159SKalle Valo 
378d5c65159SKalle Valo 	phy_idx += phy_id;
379d5c65159SKalle Valo 	if (phy_id >= hal_reg_caps->num_phy)
380d5c65159SKalle Valo 		return -EINVAL;
381d5c65159SKalle Valo 
3825b90fc76SAnilkumar Kolli 	mac_phy_caps = wmi_mac_phy_caps + phy_idx;
383d5c65159SKalle Valo 
384d5c65159SKalle Valo 	pdev->pdev_id = mac_phy_caps->pdev_id;
3855f859bc0SCarl Huang 	pdev_cap->supported_bands |= mac_phy_caps->supported_bands;
386d5c65159SKalle Valo 	pdev_cap->ampdu_density = mac_phy_caps->ampdu_density;
38713706340SWen Gong 	ab->target_pdev_ids[ab->target_pdev_count].supported_bands =
38813706340SWen Gong 		mac_phy_caps->supported_bands;
38913706340SWen Gong 	ab->target_pdev_ids[ab->target_pdev_count].pdev_id = mac_phy_caps->pdev_id;
39013706340SWen Gong 	ab->target_pdev_count++;
391d5c65159SKalle Valo 
39295959d70SManikanta Pubbisetty 	if (!(mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) &&
39395959d70SManikanta Pubbisetty 	    !(mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP))
39495959d70SManikanta Pubbisetty 		return -EINVAL;
39595959d70SManikanta Pubbisetty 
396d5c65159SKalle Valo 	/* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from
397d5c65159SKalle Valo 	 * band to band for a single radio, need to see how this should be
398d5c65159SKalle Valo 	 * handled.
399d5c65159SKalle Valo 	 */
400d5c65159SKalle Valo 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
401d5c65159SKalle Valo 		pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g;
402d5c65159SKalle Valo 		pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g;
40395959d70SManikanta Pubbisetty 	}
40495959d70SManikanta Pubbisetty 
40595959d70SManikanta Pubbisetty 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
406d5c65159SKalle Valo 		pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g;
407d5c65159SKalle Valo 		pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g;
408d5c65159SKalle Valo 		pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g;
409d5c65159SKalle Valo 		pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g;
410d5c65159SKalle Valo 		pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g;
411f552d6fdSP Praneesh 		pdev_cap->nss_ratio_enabled =
412f552d6fdSP Praneesh 			WMI_NSS_RATIO_ENABLE_DISABLE_GET(mac_phy_caps->nss_ratio);
413f552d6fdSP Praneesh 		pdev_cap->nss_ratio_info =
414f552d6fdSP Praneesh 			WMI_NSS_RATIO_INFO_GET(mac_phy_caps->nss_ratio);
415d5c65159SKalle Valo 	}
416d5c65159SKalle Valo 
417d5c65159SKalle Valo 	/* tx/rx chainmask reported from fw depends on the actual hw chains used,
418d5c65159SKalle Valo 	 * For example, for 4x4 capable macphys, first 4 chains can be used for first
4193fecca0eSJeff Johnson 	 * mac and the remaining 4 chains can be used for the second mac or vice-versa.
420d5c65159SKalle Valo 	 * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0
42116f283f0SKalle Valo 	 * will be advertised for second mac or vice-versa. Compute the shift value
422d5c65159SKalle Valo 	 * for tx/rx chainmask which will be used to advertise supported ht/vht rates to
423d5c65159SKalle Valo 	 * mac80211.
424d5c65159SKalle Valo 	 */
425d5c65159SKalle Valo 	pdev_cap->tx_chain_mask_shift =
426d5c65159SKalle Valo 			find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32);
427d5c65159SKalle Valo 	pdev_cap->rx_chain_mask_shift =
428d5c65159SKalle Valo 			find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32);
429d5c65159SKalle Valo 
4305f859bc0SCarl Huang 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
431d5c65159SKalle Valo 		cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
4325f859bc0SCarl Huang 		cap_band->phy_id = mac_phy_caps->phy_id;
433d5c65159SKalle Valo 		cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g;
434d5c65159SKalle Valo 		cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g;
435d5c65159SKalle Valo 		cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g;
436d5c65159SKalle Valo 		cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext;
437d5c65159SKalle Valo 		cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g;
438d5c65159SKalle Valo 		memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g,
439d5c65159SKalle Valo 		       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
440d5c65159SKalle Valo 		memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g,
441d5c65159SKalle Valo 		       sizeof(struct ath11k_ppe_threshold));
4425f859bc0SCarl Huang 	}
443d5c65159SKalle Valo 
4445f859bc0SCarl Huang 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
445d5c65159SKalle Valo 		cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
4465f859bc0SCarl Huang 		cap_band->phy_id = mac_phy_caps->phy_id;
447d5c65159SKalle Valo 		cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
448d5c65159SKalle Valo 		cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
449d5c65159SKalle Valo 		cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
450d5c65159SKalle Valo 		cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
451d5c65159SKalle Valo 		cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
452d5c65159SKalle Valo 		memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
453d5c65159SKalle Valo 		       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
454d5c65159SKalle Valo 		memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
455d5c65159SKalle Valo 		       sizeof(struct ath11k_ppe_threshold));
456d5c65159SKalle Valo 
45722eeadcdSPradeep Kumar Chitrapu 		cap_band = &pdev_cap->band[NL80211_BAND_6GHZ];
45822eeadcdSPradeep Kumar Chitrapu 		cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
45922eeadcdSPradeep Kumar Chitrapu 		cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
46022eeadcdSPradeep Kumar Chitrapu 		cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
46122eeadcdSPradeep Kumar Chitrapu 		cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
46222eeadcdSPradeep Kumar Chitrapu 		cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
46322eeadcdSPradeep Kumar Chitrapu 		memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
46422eeadcdSPradeep Kumar Chitrapu 		       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
46522eeadcdSPradeep Kumar Chitrapu 		memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
46622eeadcdSPradeep Kumar Chitrapu 		       sizeof(struct ath11k_ppe_threshold));
4670f17ae43SWen Gong 	}
46822eeadcdSPradeep Kumar Chitrapu 
469d5c65159SKalle Valo 	return 0;
470d5c65159SKalle Valo }
471d5c65159SKalle Valo 
472d5c65159SKalle Valo static int
473d5c65159SKalle Valo ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle,
474d5c65159SKalle Valo 				struct wmi_soc_hal_reg_capabilities *reg_caps,
475d5c65159SKalle Valo 				struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap,
476d5c65159SKalle Valo 				u8 phy_idx,
477d5c65159SKalle Valo 				struct ath11k_hal_reg_capabilities_ext *param)
478d5c65159SKalle Valo {
479d5c65159SKalle Valo 	struct wmi_hal_reg_capabilities_ext *ext_reg_cap;
480d5c65159SKalle Valo 
481d5c65159SKalle Valo 	if (!reg_caps || !wmi_ext_reg_cap)
482d5c65159SKalle Valo 		return -EINVAL;
483d5c65159SKalle Valo 
484d5c65159SKalle Valo 	if (phy_idx >= reg_caps->num_phy)
485d5c65159SKalle Valo 		return -EINVAL;
486d5c65159SKalle Valo 
487d5c65159SKalle Valo 	ext_reg_cap = &wmi_ext_reg_cap[phy_idx];
488d5c65159SKalle Valo 
489d5c65159SKalle Valo 	param->phy_id = ext_reg_cap->phy_id;
490d5c65159SKalle Valo 	param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain;
491d5c65159SKalle Valo 	param->eeprom_reg_domain_ext =
492d5c65159SKalle Valo 			      ext_reg_cap->eeprom_reg_domain_ext;
493d5c65159SKalle Valo 	param->regcap1 = ext_reg_cap->regcap1;
494d5c65159SKalle Valo 	param->regcap2 = ext_reg_cap->regcap2;
495d5c65159SKalle Valo 	/* check if param->wireless_mode is needed */
496d5c65159SKalle Valo 	param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan;
497d5c65159SKalle Valo 	param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan;
498d5c65159SKalle Valo 	param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan;
499d5c65159SKalle Valo 	param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan;
500d5c65159SKalle Valo 
501d5c65159SKalle Valo 	return 0;
502d5c65159SKalle Valo }
503d5c65159SKalle Valo 
504d5c65159SKalle Valo static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab,
505d5c65159SKalle Valo 					 const void *evt_buf,
506d5c65159SKalle Valo 					 struct ath11k_targ_cap *cap)
507d5c65159SKalle Valo {
508d5c65159SKalle Valo 	const struct wmi_service_ready_event *ev = evt_buf;
509d5c65159SKalle Valo 
510d5c65159SKalle Valo 	if (!ev) {
511d5c65159SKalle Valo 		ath11k_err(ab, "%s: failed by NULL param\n",
512d5c65159SKalle Valo 			   __func__);
513d5c65159SKalle Valo 		return -EINVAL;
514d5c65159SKalle Valo 	}
515d5c65159SKalle Valo 
516d5c65159SKalle Valo 	cap->phy_capability = ev->phy_capability;
517d5c65159SKalle Valo 	cap->max_frag_entry = ev->max_frag_entry;
518d5c65159SKalle Valo 	cap->num_rf_chains = ev->num_rf_chains;
519d5c65159SKalle Valo 	cap->ht_cap_info = ev->ht_cap_info;
520d5c65159SKalle Valo 	cap->vht_cap_info = ev->vht_cap_info;
521d5c65159SKalle Valo 	cap->vht_supp_mcs = ev->vht_supp_mcs;
522d5c65159SKalle Valo 	cap->hw_min_tx_power = ev->hw_min_tx_power;
523d5c65159SKalle Valo 	cap->hw_max_tx_power = ev->hw_max_tx_power;
524d5c65159SKalle Valo 	cap->sys_cap_info = ev->sys_cap_info;
525d5c65159SKalle Valo 	cap->min_pkt_size_enable = ev->min_pkt_size_enable;
526d5c65159SKalle Valo 	cap->max_bcn_ie_size = ev->max_bcn_ie_size;
527d5c65159SKalle Valo 	cap->max_num_scan_channels = ev->max_num_scan_channels;
528d5c65159SKalle Valo 	cap->max_supported_macs = ev->max_supported_macs;
529d5c65159SKalle Valo 	cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps;
530d5c65159SKalle Valo 	cap->txrx_chainmask = ev->txrx_chainmask;
531d5c65159SKalle Valo 	cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index;
532d5c65159SKalle Valo 	cap->num_msdu_desc = ev->num_msdu_desc;
533d5c65159SKalle Valo 
534d5c65159SKalle Valo 	return 0;
535d5c65159SKalle Valo }
536d5c65159SKalle Valo 
537d5c65159SKalle Valo /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in
538d5c65159SKalle Valo  * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each
539d5c65159SKalle Valo  * 4-byte word.
540d5c65159SKalle Valo  */
541d5c65159SKalle Valo static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi,
542d5c65159SKalle Valo 					   const u32 *wmi_svc_bm)
543d5c65159SKalle Valo {
544d5c65159SKalle Valo 	int i, j;
545d5c65159SKalle Valo 
546d5c65159SKalle Valo 	for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) {
547d5c65159SKalle Valo 		do {
548d5c65159SKalle Valo 			if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32))
5496bc9d6f7SJohn Crispin 				set_bit(j, wmi->wmi_ab->svc_map);
550d5c65159SKalle Valo 		} while (++j % WMI_SERVICE_BITS_IN_SIZE32);
551d5c65159SKalle Valo 	}
552d5c65159SKalle Valo }
553d5c65159SKalle Valo 
554d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
555d5c65159SKalle Valo 					const void *ptr, void *data)
556d5c65159SKalle Valo {
557d5c65159SKalle Valo 	struct wmi_tlv_svc_ready_parse *svc_ready = data;
5586bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
559d5c65159SKalle Valo 	u16 expect_len;
560d5c65159SKalle Valo 
561d5c65159SKalle Valo 	switch (tag) {
562d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EVENT:
563d5c65159SKalle Valo 		if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps))
564d5c65159SKalle Valo 			return -EINVAL;
565d5c65159SKalle Valo 		break;
566d5c65159SKalle Valo 
567d5c65159SKalle Valo 	case WMI_TAG_ARRAY_UINT32:
568d5c65159SKalle Valo 		if (!svc_ready->wmi_svc_bitmap_done) {
569d5c65159SKalle Valo 			expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32);
570d5c65159SKalle Valo 			if (len < expect_len) {
571d5c65159SKalle Valo 				ath11k_warn(ab, "invalid len %d for the tag 0x%x\n",
572d5c65159SKalle Valo 					    len, tag);
573d5c65159SKalle Valo 				return -EINVAL;
574d5c65159SKalle Valo 			}
575d5c65159SKalle Valo 
576d5c65159SKalle Valo 			ath11k_wmi_service_bitmap_copy(wmi_handle, ptr);
577d5c65159SKalle Valo 
578d5c65159SKalle Valo 			svc_ready->wmi_svc_bitmap_done = true;
579d5c65159SKalle Valo 		}
580d5c65159SKalle Valo 		break;
581d5c65159SKalle Valo 	default:
582d5c65159SKalle Valo 		break;
583d5c65159SKalle Valo 	}
584d5c65159SKalle Valo 
585d5c65159SKalle Valo 	return 0;
586d5c65159SKalle Valo }
587d5c65159SKalle Valo 
588d5c65159SKalle Valo static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
589d5c65159SKalle Valo {
590d5c65159SKalle Valo 	struct wmi_tlv_svc_ready_parse svc_ready = { };
591d5c65159SKalle Valo 	int ret;
592d5c65159SKalle Valo 
593d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
594d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_parse,
595d5c65159SKalle Valo 				  &svc_ready);
596d5c65159SKalle Valo 	if (ret) {
597d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
598d5c65159SKalle Valo 		return ret;
599d5c65159SKalle Valo 	}
600d5c65159SKalle Valo 
601d5c65159SKalle Valo 	return 0;
602d5c65159SKalle Valo }
603d5c65159SKalle Valo 
604d5c65159SKalle Valo struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len)
605d5c65159SKalle Valo {
606d5c65159SKalle Valo 	struct sk_buff *skb;
607d5c65159SKalle Valo 	struct ath11k_base *ab = wmi_sc->ab;
608d5c65159SKalle Valo 	u32 round_len = roundup(len, 4);
609d5c65159SKalle Valo 
610d5c65159SKalle Valo 	skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len);
611d5c65159SKalle Valo 	if (!skb)
612d5c65159SKalle Valo 		return NULL;
613d5c65159SKalle Valo 
614d5c65159SKalle Valo 	skb_reserve(skb, WMI_SKB_HEADROOM);
615d5c65159SKalle Valo 	if (!IS_ALIGNED((unsigned long)skb->data, 4))
616d5c65159SKalle Valo 		ath11k_warn(ab, "unaligned WMI skb data\n");
617d5c65159SKalle Valo 
618d5c65159SKalle Valo 	skb_put(skb, round_len);
619d5c65159SKalle Valo 	memset(skb->data, 0, round_len);
620d5c65159SKalle Valo 
621d5c65159SKalle Valo 	return skb;
622d5c65159SKalle Valo }
623d5c65159SKalle Valo 
6241d7f5145SBaochen Qiang static u32 ath11k_wmi_mgmt_get_freq(struct ath11k *ar,
6251d7f5145SBaochen Qiang 				    struct ieee80211_tx_info *info)
6261d7f5145SBaochen Qiang {
6271d7f5145SBaochen Qiang 	struct ath11k_base *ab = ar->ab;
6281d7f5145SBaochen Qiang 	u32 freq = 0;
6291d7f5145SBaochen Qiang 
6301d7f5145SBaochen Qiang 	if (ab->hw_params.support_off_channel_tx &&
6311d7f5145SBaochen Qiang 	    ar->scan.is_roc &&
6321d7f5145SBaochen Qiang 	    (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
6331d7f5145SBaochen Qiang 		freq = ar->scan.roc_freq;
6341d7f5145SBaochen Qiang 
6351d7f5145SBaochen Qiang 	return freq;
6361d7f5145SBaochen Qiang }
6371d7f5145SBaochen Qiang 
638d5c65159SKalle Valo int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id,
639d5c65159SKalle Valo 			 struct sk_buff *frame)
640d5c65159SKalle Valo {
641d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
6421d7f5145SBaochen Qiang 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(frame);
643d5c65159SKalle Valo 	struct wmi_mgmt_send_cmd *cmd;
644d5c65159SKalle Valo 	struct wmi_tlv *frame_tlv;
645d5c65159SKalle Valo 	struct sk_buff *skb;
646d5c65159SKalle Valo 	u32 buf_len;
647d5c65159SKalle Valo 	int ret, len;
648d5c65159SKalle Valo 
649d5c65159SKalle Valo 	buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ?
650d5c65159SKalle Valo 		  frame->len : WMI_MGMT_SEND_DOWNLD_LEN;
651d5c65159SKalle Valo 
652d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4);
653d5c65159SKalle Valo 
6546bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
655d5c65159SKalle Valo 	if (!skb)
656d5c65159SKalle Valo 		return -ENOMEM;
657d5c65159SKalle Valo 
658d5c65159SKalle Valo 	cmd = (struct wmi_mgmt_send_cmd *)skb->data;
659d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) |
660d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
661d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
662d5c65159SKalle Valo 	cmd->desc_id = buf_id;
6631d7f5145SBaochen Qiang 	cmd->chanfreq = ath11k_wmi_mgmt_get_freq(ar, info);
664d5c65159SKalle Valo 	cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr);
665d5c65159SKalle Valo 	cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr);
666d5c65159SKalle Valo 	cmd->frame_len = frame->len;
667d5c65159SKalle Valo 	cmd->buf_len = buf_len;
668d5c65159SKalle Valo 	cmd->tx_params_valid = 0;
669d5c65159SKalle Valo 
670d5c65159SKalle Valo 	frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
671d5c65159SKalle Valo 	frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
672d5c65159SKalle Valo 			    FIELD_PREP(WMI_TLV_LEN, buf_len);
673d5c65159SKalle Valo 
674d5c65159SKalle Valo 	memcpy(frame_tlv->value, frame->data, buf_len);
675d5c65159SKalle Valo 
676d5c65159SKalle Valo 	ath11k_ce_byte_swap(frame_tlv->value, buf_len);
677d5c65159SKalle Valo 
678d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID);
679d5c65159SKalle Valo 	if (ret) {
680d5c65159SKalle Valo 		ath11k_warn(ar->ab,
681d5c65159SKalle Valo 			    "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n");
682d5c65159SKalle Valo 		dev_kfree_skb(skb);
683d5c65159SKalle Valo 	}
684d5c65159SKalle Valo 
685d5c65159SKalle Valo 	return ret;
686d5c65159SKalle Valo }
687d5c65159SKalle Valo 
688d5c65159SKalle Valo int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr,
689d5c65159SKalle Valo 			   struct vdev_create_params *param)
690d5c65159SKalle Valo {
691d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
692d5c65159SKalle Valo 	struct wmi_vdev_create_cmd *cmd;
693d5c65159SKalle Valo 	struct sk_buff *skb;
694d5c65159SKalle Valo 	struct wmi_vdev_txrx_streams *txrx_streams;
695d5c65159SKalle Valo 	struct wmi_tlv *tlv;
696d5c65159SKalle Valo 	int ret, len;
697d5c65159SKalle Valo 	void *ptr;
698d5c65159SKalle Valo 
699d5c65159SKalle Valo 	/* It can be optimized my sending tx/rx chain configuration
700d5c65159SKalle Valo 	 * only for supported bands instead of always sending it for
701d5c65159SKalle Valo 	 * both the bands.
702d5c65159SKalle Valo 	 */
703d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE +
704d5c65159SKalle Valo 		(WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams));
705d5c65159SKalle Valo 
7066bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
707d5c65159SKalle Valo 	if (!skb)
708d5c65159SKalle Valo 		return -ENOMEM;
709d5c65159SKalle Valo 
710d5c65159SKalle Valo 	cmd = (struct wmi_vdev_create_cmd *)skb->data;
711d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) |
712d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
713d5c65159SKalle Valo 
714d5c65159SKalle Valo 	cmd->vdev_id = param->if_id;
715d5c65159SKalle Valo 	cmd->vdev_type = param->type;
716d5c65159SKalle Valo 	cmd->vdev_subtype = param->subtype;
717d5c65159SKalle Valo 	cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX;
718d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
719d5c65159SKalle Valo 	ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
720d5c65159SKalle Valo 
721d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
722d5c65159SKalle Valo 	len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams);
723d5c65159SKalle Valo 
724d5c65159SKalle Valo 	tlv = ptr;
725d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
726d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
727d5c65159SKalle Valo 
728d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
729d5c65159SKalle Valo 	txrx_streams = ptr;
730d5c65159SKalle Valo 	len = sizeof(*txrx_streams);
731d5c65159SKalle Valo 	txrx_streams->tlv_header =
732d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
733d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
734d5c65159SKalle Valo 	txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G;
735d5c65159SKalle Valo 	txrx_streams->supported_tx_streams =
736d5c65159SKalle Valo 				 param->chains[NL80211_BAND_2GHZ].tx;
737d5c65159SKalle Valo 	txrx_streams->supported_rx_streams =
738d5c65159SKalle Valo 				 param->chains[NL80211_BAND_2GHZ].rx;
739d5c65159SKalle Valo 
740d5c65159SKalle Valo 	txrx_streams++;
741d5c65159SKalle Valo 	txrx_streams->tlv_header =
742d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
743d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
744d5c65159SKalle Valo 	txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G;
745d5c65159SKalle Valo 	txrx_streams->supported_tx_streams =
746d5c65159SKalle Valo 				 param->chains[NL80211_BAND_5GHZ].tx;
747d5c65159SKalle Valo 	txrx_streams->supported_rx_streams =
748d5c65159SKalle Valo 				 param->chains[NL80211_BAND_5GHZ].rx;
749d5c65159SKalle Valo 
750d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID);
751d5c65159SKalle Valo 	if (ret) {
752d5c65159SKalle Valo 		ath11k_warn(ar->ab,
753d5c65159SKalle Valo 			    "failed to submit WMI_VDEV_CREATE_CMDID\n");
754d5c65159SKalle Valo 		dev_kfree_skb(skb);
755d5c65159SKalle Valo 	}
756d5c65159SKalle Valo 
757d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
758d5c65159SKalle Valo 		   "WMI vdev create: id %d type %d subtype %d macaddr %pM pdevid %d\n",
759d5c65159SKalle Valo 		   param->if_id, param->type, param->subtype,
760d5c65159SKalle Valo 		   macaddr, param->pdev_id);
761d5c65159SKalle Valo 
762d5c65159SKalle Valo 	return ret;
763d5c65159SKalle Valo }
764d5c65159SKalle Valo 
765d5c65159SKalle Valo int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id)
766d5c65159SKalle Valo {
767d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
768d5c65159SKalle Valo 	struct wmi_vdev_delete_cmd *cmd;
769d5c65159SKalle Valo 	struct sk_buff *skb;
770d5c65159SKalle Valo 	int ret;
771d5c65159SKalle Valo 
7726bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
773d5c65159SKalle Valo 	if (!skb)
774d5c65159SKalle Valo 		return -ENOMEM;
775d5c65159SKalle Valo 
776d5c65159SKalle Valo 	cmd = (struct wmi_vdev_delete_cmd *)skb->data;
777d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) |
778d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
779d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
780d5c65159SKalle Valo 
781d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID);
782d5c65159SKalle Valo 	if (ret) {
783d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n");
784d5c65159SKalle Valo 		dev_kfree_skb(skb);
785d5c65159SKalle Valo 	}
786d5c65159SKalle Valo 
787d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev delete id %d\n", vdev_id);
788d5c65159SKalle Valo 
789d5c65159SKalle Valo 	return ret;
790d5c65159SKalle Valo }
791d5c65159SKalle Valo 
792d5c65159SKalle Valo int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id)
793d5c65159SKalle Valo {
794d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
795d5c65159SKalle Valo 	struct wmi_vdev_stop_cmd *cmd;
796d5c65159SKalle Valo 	struct sk_buff *skb;
797d5c65159SKalle Valo 	int ret;
798d5c65159SKalle Valo 
7996bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
800d5c65159SKalle Valo 	if (!skb)
801d5c65159SKalle Valo 		return -ENOMEM;
802d5c65159SKalle Valo 
803d5c65159SKalle Valo 	cmd = (struct wmi_vdev_stop_cmd *)skb->data;
804d5c65159SKalle Valo 
805d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) |
806d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
807d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
808d5c65159SKalle Valo 
809d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID);
810d5c65159SKalle Valo 	if (ret) {
811d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n");
812d5c65159SKalle Valo 		dev_kfree_skb(skb);
813d5c65159SKalle Valo 	}
814d5c65159SKalle Valo 
815d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev stop id 0x%x\n", vdev_id);
816d5c65159SKalle Valo 
817d5c65159SKalle Valo 	return ret;
818d5c65159SKalle Valo }
819d5c65159SKalle Valo 
820d5c65159SKalle Valo int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id)
821d5c65159SKalle Valo {
822d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
823d5c65159SKalle Valo 	struct wmi_vdev_down_cmd *cmd;
824d5c65159SKalle Valo 	struct sk_buff *skb;
825d5c65159SKalle Valo 	int ret;
826d5c65159SKalle Valo 
8276bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
828d5c65159SKalle Valo 	if (!skb)
829d5c65159SKalle Valo 		return -ENOMEM;
830d5c65159SKalle Valo 
831d5c65159SKalle Valo 	cmd = (struct wmi_vdev_down_cmd *)skb->data;
832d5c65159SKalle Valo 
833d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) |
834d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
835d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
836d5c65159SKalle Valo 
837d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID);
838d5c65159SKalle Valo 	if (ret) {
839d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n");
840d5c65159SKalle Valo 		dev_kfree_skb(skb);
841d5c65159SKalle Valo 	}
842d5c65159SKalle Valo 
843d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev down id 0x%x\n", vdev_id);
844d5c65159SKalle Valo 
845d5c65159SKalle Valo 	return ret;
846d5c65159SKalle Valo }
847d5c65159SKalle Valo 
848d5c65159SKalle Valo static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan,
849d5c65159SKalle Valo 				       struct wmi_vdev_start_req_arg *arg)
850d5c65159SKalle Valo {
851f552d6fdSP Praneesh 	u32 center_freq1 = arg->channel.band_center_freq1;
852f552d6fdSP Praneesh 
853d5c65159SKalle Valo 	memset(chan, 0, sizeof(*chan));
854d5c65159SKalle Valo 
855d5c65159SKalle Valo 	chan->mhz = arg->channel.freq;
856d5c65159SKalle Valo 	chan->band_center_freq1 = arg->channel.band_center_freq1;
857f552d6fdSP Praneesh 
858f552d6fdSP Praneesh 	if (arg->channel.mode == MODE_11AX_HE160) {
859f552d6fdSP Praneesh 		if (arg->channel.freq > arg->channel.band_center_freq1)
860f552d6fdSP Praneesh 			chan->band_center_freq1 = center_freq1 + 40;
861d5c65159SKalle Valo 		else
862f552d6fdSP Praneesh 			chan->band_center_freq1 = center_freq1 - 40;
863f552d6fdSP Praneesh 
864f552d6fdSP Praneesh 		chan->band_center_freq2 = arg->channel.band_center_freq1;
865f552d6fdSP Praneesh 
866f552d6fdSP Praneesh 	} else if (arg->channel.mode == MODE_11AC_VHT80_80) {
867f552d6fdSP Praneesh 		chan->band_center_freq2 = arg->channel.band_center_freq2;
868f552d6fdSP Praneesh 	} else {
869d5c65159SKalle Valo 		chan->band_center_freq2 = 0;
870f552d6fdSP Praneesh 	}
871d5c65159SKalle Valo 
872d5c65159SKalle Valo 	chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode);
873d5c65159SKalle Valo 	if (arg->channel.passive)
874d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_PASSIVE;
875d5c65159SKalle Valo 	if (arg->channel.allow_ibss)
876d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED;
877d5c65159SKalle Valo 	if (arg->channel.allow_ht)
878d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ALLOW_HT;
879d5c65159SKalle Valo 	if (arg->channel.allow_vht)
880d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ALLOW_VHT;
8819f056ed8SJohn Crispin 	if (arg->channel.allow_he)
8829f056ed8SJohn Crispin 		chan->info |= WMI_CHAN_INFO_ALLOW_HE;
883d5c65159SKalle Valo 	if (arg->channel.ht40plus)
884d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_HT40_PLUS;
885d5c65159SKalle Valo 	if (arg->channel.chan_radar)
886d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_DFS;
887d5c65159SKalle Valo 	if (arg->channel.freq2_radar)
888d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_DFS_FREQ2;
889d5c65159SKalle Valo 
890d5c65159SKalle Valo 	chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
891d5c65159SKalle Valo 				      arg->channel.max_power) |
892d5c65159SKalle Valo 		FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
893d5c65159SKalle Valo 			   arg->channel.max_reg_power);
894d5c65159SKalle Valo 
895d5c65159SKalle Valo 	chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
896d5c65159SKalle Valo 				      arg->channel.max_antenna_gain) |
897d5c65159SKalle Valo 		FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
898d5c65159SKalle Valo 			   arg->channel.max_power);
899d5c65159SKalle Valo }
900d5c65159SKalle Valo 
901d5c65159SKalle Valo int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg,
902d5c65159SKalle Valo 			  bool restart)
903d5c65159SKalle Valo {
904d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
905d5c65159SKalle Valo 	struct wmi_vdev_start_request_cmd *cmd;
906d5c65159SKalle Valo 	struct sk_buff *skb;
907d5c65159SKalle Valo 	struct wmi_channel *chan;
908d5c65159SKalle Valo 	struct wmi_tlv *tlv;
909d5c65159SKalle Valo 	void *ptr;
910d5c65159SKalle Valo 	int ret, len;
911d5c65159SKalle Valo 
912d5c65159SKalle Valo 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
913d5c65159SKalle Valo 		return -EINVAL;
914d5c65159SKalle Valo 
915d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE;
916d5c65159SKalle Valo 
9176bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
918d5c65159SKalle Valo 	if (!skb)
919d5c65159SKalle Valo 		return -ENOMEM;
920d5c65159SKalle Valo 
921d5c65159SKalle Valo 	cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
922d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
923d5c65159SKalle Valo 				     WMI_TAG_VDEV_START_REQUEST_CMD) |
924d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
925d5c65159SKalle Valo 	cmd->vdev_id = arg->vdev_id;
926d5c65159SKalle Valo 	cmd->beacon_interval = arg->bcn_intval;
927d5c65159SKalle Valo 	cmd->bcn_tx_rate = arg->bcn_tx_rate;
928d5c65159SKalle Valo 	cmd->dtim_period = arg->dtim_period;
929d5c65159SKalle Valo 	cmd->num_noa_descriptors = arg->num_noa_descriptors;
930d5c65159SKalle Valo 	cmd->preferred_rx_streams = arg->pref_rx_streams;
931d5c65159SKalle Valo 	cmd->preferred_tx_streams = arg->pref_tx_streams;
932d5c65159SKalle Valo 	cmd->cac_duration_ms = arg->cac_duration_ms;
933d5c65159SKalle Valo 	cmd->regdomain = arg->regdomain;
934d5c65159SKalle Valo 	cmd->he_ops = arg->he_ops;
935d5c65159SKalle Valo 
936d5c65159SKalle Valo 	if (!restart) {
937d5c65159SKalle Valo 		if (arg->ssid) {
938d5c65159SKalle Valo 			cmd->ssid.ssid_len = arg->ssid_len;
939d5c65159SKalle Valo 			memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
940d5c65159SKalle Valo 		}
941d5c65159SKalle Valo 		if (arg->hidden_ssid)
942d5c65159SKalle Valo 			cmd->flags |= WMI_VDEV_START_HIDDEN_SSID;
943d5c65159SKalle Valo 		if (arg->pmf_enabled)
944d5c65159SKalle Valo 			cmd->flags |= WMI_VDEV_START_PMF_ENABLED;
945d5c65159SKalle Valo 	}
946d5c65159SKalle Valo 
947d5c65159SKalle Valo 	cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED;
9488717db7eSSeevalamuthu Mariappan 	if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
9498717db7eSSeevalamuthu Mariappan 		cmd->flags |= WMI_VDEV_START_HW_ENCRYPTION_DISABLED;
950d5c65159SKalle Valo 
951d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
952d5c65159SKalle Valo 	chan = ptr;
953d5c65159SKalle Valo 
954d5c65159SKalle Valo 	ath11k_wmi_put_wmi_channel(chan, arg);
955d5c65159SKalle Valo 
956d5c65159SKalle Valo 	chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) |
957d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
958d5c65159SKalle Valo 				      sizeof(*chan) - TLV_HDR_SIZE);
959d5c65159SKalle Valo 	ptr += sizeof(*chan);
960d5c65159SKalle Valo 
961d5c65159SKalle Valo 	tlv = ptr;
962d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
963d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, 0);
964d5c65159SKalle Valo 
965d5c65159SKalle Valo 	/* Note: This is a nested TLV containing:
966d5c65159SKalle Valo 	 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
967d5c65159SKalle Valo 	 */
968d5c65159SKalle Valo 
969d5c65159SKalle Valo 	ptr += sizeof(*tlv);
970d5c65159SKalle Valo 
971d5c65159SKalle Valo 	if (restart)
972d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb,
973d5c65159SKalle Valo 					  WMI_VDEV_RESTART_REQUEST_CMDID);
974d5c65159SKalle Valo 	else
975d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb,
976d5c65159SKalle Valo 					  WMI_VDEV_START_REQUEST_CMDID);
977d5c65159SKalle Valo 	if (ret) {
978d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n",
979d5c65159SKalle Valo 			    restart ? "restart" : "start");
980d5c65159SKalle Valo 		dev_kfree_skb(skb);
981d5c65159SKalle Valo 	}
982d5c65159SKalle Valo 
983d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "vdev %s id 0x%x freq 0x%x mode 0x%x\n",
984d5c65159SKalle Valo 		   restart ? "restart" : "start", arg->vdev_id,
985d5c65159SKalle Valo 		   arg->channel.freq, arg->channel.mode);
986d5c65159SKalle Valo 
987d5c65159SKalle Valo 	return ret;
988d5c65159SKalle Valo }
989d5c65159SKalle Valo 
990d5c65159SKalle Valo int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
991d5c65159SKalle Valo {
992d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
993d5c65159SKalle Valo 	struct wmi_vdev_up_cmd *cmd;
9947d992bd4SManikanta Pubbisetty 	struct ieee80211_bss_conf *bss_conf;
9957d992bd4SManikanta Pubbisetty 	struct ath11k_vif *arvif;
996d5c65159SKalle Valo 	struct sk_buff *skb;
997d5c65159SKalle Valo 	int ret;
998d5c65159SKalle Valo 
9997d992bd4SManikanta Pubbisetty 	arvif = ath11k_mac_get_arvif(ar, vdev_id);
10007d992bd4SManikanta Pubbisetty 
10016bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1002d5c65159SKalle Valo 	if (!skb)
1003d5c65159SKalle Valo 		return -ENOMEM;
1004d5c65159SKalle Valo 
1005d5c65159SKalle Valo 	cmd = (struct wmi_vdev_up_cmd *)skb->data;
1006d5c65159SKalle Valo 
1007d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) |
1008d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1009d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1010d5c65159SKalle Valo 	cmd->vdev_assoc_id = aid;
1011d5c65159SKalle Valo 
1012d5c65159SKalle Valo 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
1013d5c65159SKalle Valo 
10147d992bd4SManikanta Pubbisetty 	if (arvif && arvif->vif->type == NL80211_IFTYPE_STATION) {
10157d992bd4SManikanta Pubbisetty 		bss_conf = &arvif->vif->bss_conf;
10167d992bd4SManikanta Pubbisetty 
10177d992bd4SManikanta Pubbisetty 		if (bss_conf->nontransmitted) {
10187d992bd4SManikanta Pubbisetty 			ether_addr_copy(cmd->trans_bssid.addr,
10197d992bd4SManikanta Pubbisetty 					bss_conf->transmitter_bssid);
10207d992bd4SManikanta Pubbisetty 			cmd->profile_idx = bss_conf->bssid_index;
10217d992bd4SManikanta Pubbisetty 			cmd->profile_num = bss_conf->bssid_indicator;
10227d992bd4SManikanta Pubbisetty 		}
10237d992bd4SManikanta Pubbisetty 	}
10247d992bd4SManikanta Pubbisetty 
1025d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID);
1026d5c65159SKalle Valo 	if (ret) {
1027d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n");
1028d5c65159SKalle Valo 		dev_kfree_skb(skb);
1029d5c65159SKalle Valo 	}
1030d5c65159SKalle Valo 
1031d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1032d5c65159SKalle Valo 		   "WMI mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
1033d5c65159SKalle Valo 		   vdev_id, aid, bssid);
1034d5c65159SKalle Valo 
1035d5c65159SKalle Valo 	return ret;
1036d5c65159SKalle Valo }
1037d5c65159SKalle Valo 
1038d5c65159SKalle Valo int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar,
1039d5c65159SKalle Valo 				    struct peer_create_params *param)
1040d5c65159SKalle Valo {
1041d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1042d5c65159SKalle Valo 	struct wmi_peer_create_cmd *cmd;
1043d5c65159SKalle Valo 	struct sk_buff *skb;
1044d5c65159SKalle Valo 	int ret;
1045d5c65159SKalle Valo 
10466bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1047d5c65159SKalle Valo 	if (!skb)
1048d5c65159SKalle Valo 		return -ENOMEM;
1049d5c65159SKalle Valo 
1050d5c65159SKalle Valo 	cmd = (struct wmi_peer_create_cmd *)skb->data;
1051d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) |
1052d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1053d5c65159SKalle Valo 
1054d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr);
1055d5c65159SKalle Valo 	cmd->peer_type = param->peer_type;
1056d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1057d5c65159SKalle Valo 
1058d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID);
1059d5c65159SKalle Valo 	if (ret) {
1060d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n");
1061d5c65159SKalle Valo 		dev_kfree_skb(skb);
1062d5c65159SKalle Valo 	}
1063d5c65159SKalle Valo 
1064d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1065d5c65159SKalle Valo 		   "WMI peer create vdev_id %d peer_addr %pM\n",
1066d5c65159SKalle Valo 		   param->vdev_id, param->peer_addr);
1067d5c65159SKalle Valo 
1068d5c65159SKalle Valo 	return ret;
1069d5c65159SKalle Valo }
1070d5c65159SKalle Valo 
1071d5c65159SKalle Valo int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar,
1072d5c65159SKalle Valo 				    const u8 *peer_addr, u8 vdev_id)
1073d5c65159SKalle Valo {
1074d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1075d5c65159SKalle Valo 	struct wmi_peer_delete_cmd *cmd;
1076d5c65159SKalle Valo 	struct sk_buff *skb;
1077d5c65159SKalle Valo 	int ret;
1078d5c65159SKalle Valo 
10796bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1080d5c65159SKalle Valo 	if (!skb)
1081d5c65159SKalle Valo 		return -ENOMEM;
1082d5c65159SKalle Valo 
1083d5c65159SKalle Valo 	cmd = (struct wmi_peer_delete_cmd *)skb->data;
1084d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) |
1085d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1086d5c65159SKalle Valo 
1087d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1088d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1089d5c65159SKalle Valo 
1090d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1091d5c65159SKalle Valo 		   "WMI peer delete vdev_id %d peer_addr %pM\n",
1092d5c65159SKalle Valo 		   vdev_id,  peer_addr);
1093d5c65159SKalle Valo 
1094d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID);
1095d5c65159SKalle Valo 	if (ret) {
1096d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n");
1097d5c65159SKalle Valo 		dev_kfree_skb(skb);
1098d5c65159SKalle Valo 	}
1099d5c65159SKalle Valo 
1100d5c65159SKalle Valo 	return ret;
1101d5c65159SKalle Valo }
1102d5c65159SKalle Valo 
1103d5c65159SKalle Valo int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar,
1104d5c65159SKalle Valo 				       struct pdev_set_regdomain_params *param)
1105d5c65159SKalle Valo {
1106d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1107d5c65159SKalle Valo 	struct wmi_pdev_set_regdomain_cmd *cmd;
1108d5c65159SKalle Valo 	struct sk_buff *skb;
1109d5c65159SKalle Valo 	int ret;
1110d5c65159SKalle Valo 
11116bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1112d5c65159SKalle Valo 	if (!skb)
1113d5c65159SKalle Valo 		return -ENOMEM;
1114d5c65159SKalle Valo 
1115d5c65159SKalle Valo 	cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1116d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1117d5c65159SKalle Valo 				     WMI_TAG_PDEV_SET_REGDOMAIN_CMD) |
1118d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1119d5c65159SKalle Valo 
1120d5c65159SKalle Valo 	cmd->reg_domain = param->current_rd_in_use;
1121d5c65159SKalle Valo 	cmd->reg_domain_2g = param->current_rd_2g;
1122d5c65159SKalle Valo 	cmd->reg_domain_5g = param->current_rd_5g;
1123d5c65159SKalle Valo 	cmd->conformance_test_limit_2g = param->ctl_2g;
1124d5c65159SKalle Valo 	cmd->conformance_test_limit_5g = param->ctl_5g;
1125d5c65159SKalle Valo 	cmd->dfs_domain = param->dfs_domain;
1126d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
1127d5c65159SKalle Valo 
1128d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1129d5c65159SKalle Valo 		   "WMI pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n",
1130d5c65159SKalle Valo 		   param->current_rd_in_use, param->current_rd_2g,
1131d5c65159SKalle Valo 		   param->current_rd_5g, param->dfs_domain, param->pdev_id);
1132d5c65159SKalle Valo 
1133d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1134d5c65159SKalle Valo 	if (ret) {
1135d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1136d5c65159SKalle Valo 			    "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n");
1137d5c65159SKalle Valo 		dev_kfree_skb(skb);
1138d5c65159SKalle Valo 	}
1139d5c65159SKalle Valo 
1140d5c65159SKalle Valo 	return ret;
1141d5c65159SKalle Valo }
1142d5c65159SKalle Valo 
1143d5c65159SKalle Valo int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr,
1144d5c65159SKalle Valo 			      u32 vdev_id, u32 param_id, u32 param_val)
1145d5c65159SKalle Valo {
1146d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1147d5c65159SKalle Valo 	struct wmi_peer_set_param_cmd *cmd;
1148d5c65159SKalle Valo 	struct sk_buff *skb;
1149d5c65159SKalle Valo 	int ret;
1150d5c65159SKalle Valo 
11516bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1152d5c65159SKalle Valo 	if (!skb)
1153d5c65159SKalle Valo 		return -ENOMEM;
1154d5c65159SKalle Valo 
1155d5c65159SKalle Valo 	cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1156d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) |
1157d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1158d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1159d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1160d5c65159SKalle Valo 	cmd->param_id = param_id;
1161d5c65159SKalle Valo 	cmd->param_value = param_val;
1162d5c65159SKalle Valo 
1163d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID);
1164d5c65159SKalle Valo 	if (ret) {
1165d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n");
1166d5c65159SKalle Valo 		dev_kfree_skb(skb);
1167d5c65159SKalle Valo 	}
1168d5c65159SKalle Valo 
1169d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1170d5c65159SKalle Valo 		   "WMI vdev %d peer 0x%pM set param %d value %d\n",
1171d5c65159SKalle Valo 		   vdev_id, peer_addr, param_id, param_val);
1172d5c65159SKalle Valo 
1173d5c65159SKalle Valo 	return ret;
1174d5c65159SKalle Valo }
1175d5c65159SKalle Valo 
1176d5c65159SKalle Valo int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar,
1177d5c65159SKalle Valo 					u8 peer_addr[ETH_ALEN],
1178d5c65159SKalle Valo 					struct peer_flush_params *param)
1179d5c65159SKalle Valo {
1180d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1181d5c65159SKalle Valo 	struct wmi_peer_flush_tids_cmd *cmd;
1182d5c65159SKalle Valo 	struct sk_buff *skb;
1183d5c65159SKalle Valo 	int ret;
1184d5c65159SKalle Valo 
11856bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1186d5c65159SKalle Valo 	if (!skb)
1187d5c65159SKalle Valo 		return -ENOMEM;
1188d5c65159SKalle Valo 
1189d5c65159SKalle Valo 	cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1190d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) |
1191d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1192d5c65159SKalle Valo 
1193d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1194d5c65159SKalle Valo 	cmd->peer_tid_bitmap = param->peer_tid_bitmap;
1195d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1196d5c65159SKalle Valo 
1197d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1198d5c65159SKalle Valo 	if (ret) {
1199d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1200d5c65159SKalle Valo 			    "failed to send WMI_PEER_FLUSH_TIDS cmd\n");
1201d5c65159SKalle Valo 		dev_kfree_skb(skb);
1202d5c65159SKalle Valo 	}
1203d5c65159SKalle Valo 
1204d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1205d5c65159SKalle Valo 		   "WMI peer flush vdev_id %d peer_addr %pM tids %08x\n",
1206d5c65159SKalle Valo 		   param->vdev_id, peer_addr, param->peer_tid_bitmap);
1207d5c65159SKalle Valo 
1208d5c65159SKalle Valo 	return ret;
1209d5c65159SKalle Valo }
1210d5c65159SKalle Valo 
1211d5c65159SKalle Valo int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar,
1212d5c65159SKalle Valo 					   int vdev_id, const u8 *addr,
1213d5c65159SKalle Valo 					   dma_addr_t paddr, u8 tid,
1214d5c65159SKalle Valo 					   u8 ba_window_size_valid,
1215d5c65159SKalle Valo 					   u32 ba_window_size)
1216d5c65159SKalle Valo {
1217d5c65159SKalle Valo 	struct wmi_peer_reorder_queue_setup_cmd *cmd;
1218d5c65159SKalle Valo 	struct sk_buff *skb;
1219d5c65159SKalle Valo 	int ret;
1220d5c65159SKalle Valo 
12216bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
1222d5c65159SKalle Valo 	if (!skb)
1223d5c65159SKalle Valo 		return -ENOMEM;
1224d5c65159SKalle Valo 
1225d5c65159SKalle Valo 	cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data;
1226d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1227d5c65159SKalle Valo 				     WMI_TAG_REORDER_QUEUE_SETUP_CMD) |
1228d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1229d5c65159SKalle Valo 
1230d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, addr);
1231d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1232d5c65159SKalle Valo 	cmd->tid = tid;
1233d5c65159SKalle Valo 	cmd->queue_ptr_lo = lower_32_bits(paddr);
1234d5c65159SKalle Valo 	cmd->queue_ptr_hi = upper_32_bits(paddr);
1235d5c65159SKalle Valo 	cmd->queue_no = tid;
1236d5c65159SKalle Valo 	cmd->ba_window_size_valid = ba_window_size_valid;
1237d5c65159SKalle Valo 	cmd->ba_window_size = ba_window_size;
1238d5c65159SKalle Valo 
1239d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
1240d5c65159SKalle Valo 				  WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1241d5c65159SKalle Valo 	if (ret) {
1242d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1243d5c65159SKalle Valo 			    "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n");
1244d5c65159SKalle Valo 		dev_kfree_skb(skb);
1245d5c65159SKalle Valo 	}
1246d5c65159SKalle Valo 
1247d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1248d5c65159SKalle Valo 		   "wmi rx reorder queue setup addr %pM vdev_id %d tid %d\n",
1249d5c65159SKalle Valo 		   addr, vdev_id, tid);
1250d5c65159SKalle Valo 
1251d5c65159SKalle Valo 	return ret;
1252d5c65159SKalle Valo }
1253d5c65159SKalle Valo 
1254d5c65159SKalle Valo int
1255d5c65159SKalle Valo ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar,
1256d5c65159SKalle Valo 				 struct rx_reorder_queue_remove_params *param)
1257d5c65159SKalle Valo {
1258d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1259d5c65159SKalle Valo 	struct wmi_peer_reorder_queue_remove_cmd *cmd;
1260d5c65159SKalle Valo 	struct sk_buff *skb;
1261d5c65159SKalle Valo 	int ret;
1262d5c65159SKalle Valo 
12636bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1264d5c65159SKalle Valo 	if (!skb)
1265d5c65159SKalle Valo 		return -ENOMEM;
1266d5c65159SKalle Valo 
1267d5c65159SKalle Valo 	cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data;
1268d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1269d5c65159SKalle Valo 				     WMI_TAG_REORDER_QUEUE_REMOVE_CMD) |
1270d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1271d5c65159SKalle Valo 
1272d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr);
1273d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1274d5c65159SKalle Valo 	cmd->tid_mask = param->peer_tid_bitmap;
1275d5c65159SKalle Valo 
1276d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1277d5c65159SKalle Valo 		   "%s: peer_macaddr %pM vdev_id %d, tid_map %d", __func__,
1278d5c65159SKalle Valo 		   param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap);
1279d5c65159SKalle Valo 
1280d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
1281d5c65159SKalle Valo 				  WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
1282d5c65159SKalle Valo 	if (ret) {
1283d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1284d5c65159SKalle Valo 			    "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID");
1285d5c65159SKalle Valo 		dev_kfree_skb(skb);
1286d5c65159SKalle Valo 	}
1287d5c65159SKalle Valo 
1288d5c65159SKalle Valo 	return ret;
1289d5c65159SKalle Valo }
1290d5c65159SKalle Valo 
1291d5c65159SKalle Valo int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id,
1292d5c65159SKalle Valo 			      u32 param_value, u8 pdev_id)
1293d5c65159SKalle Valo {
1294d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1295d5c65159SKalle Valo 	struct wmi_pdev_set_param_cmd *cmd;
1296d5c65159SKalle Valo 	struct sk_buff *skb;
1297d5c65159SKalle Valo 	int ret;
1298d5c65159SKalle Valo 
12996bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1300d5c65159SKalle Valo 	if (!skb)
1301d5c65159SKalle Valo 		return -ENOMEM;
1302d5c65159SKalle Valo 
1303d5c65159SKalle Valo 	cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1304d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) |
1305d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1306d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1307d5c65159SKalle Valo 	cmd->param_id = param_id;
1308d5c65159SKalle Valo 	cmd->param_value = param_value;
1309d5c65159SKalle Valo 
1310d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID);
1311d5c65159SKalle Valo 	if (ret) {
1312d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1313d5c65159SKalle Valo 		dev_kfree_skb(skb);
1314d5c65159SKalle Valo 	}
1315d5c65159SKalle Valo 
1316d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1317d5c65159SKalle Valo 		   "WMI pdev set param %d pdev id %d value %d\n",
1318d5c65159SKalle Valo 		   param_id, pdev_id, param_value);
1319d5c65159SKalle Valo 
1320d5c65159SKalle Valo 	return ret;
1321d5c65159SKalle Valo }
1322d5c65159SKalle Valo 
1323af3d8964SKalle Valo int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id,
1324af3d8964SKalle Valo 				enum wmi_sta_ps_mode psmode)
132597c63746SJohn Crispin {
132697c63746SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
132797c63746SJohn Crispin 	struct wmi_pdev_set_ps_mode_cmd *cmd;
132897c63746SJohn Crispin 	struct sk_buff *skb;
132997c63746SJohn Crispin 	int ret;
133097c63746SJohn Crispin 
13316bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
133297c63746SJohn Crispin 	if (!skb)
133397c63746SJohn Crispin 		return -ENOMEM;
133497c63746SJohn Crispin 
133597c63746SJohn Crispin 	cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data;
133697c63746SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) |
133797c63746SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
133897c63746SJohn Crispin 	cmd->vdev_id = vdev_id;
1339af3d8964SKalle Valo 	cmd->sta_ps_mode = psmode;
134097c63746SJohn Crispin 
134197c63746SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID);
134297c63746SJohn Crispin 	if (ret) {
134397c63746SJohn Crispin 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
134497c63746SJohn Crispin 		dev_kfree_skb(skb);
134597c63746SJohn Crispin 	}
134697c63746SJohn Crispin 
134797c63746SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
134897c63746SJohn Crispin 		   "WMI vdev set psmode %d vdev id %d\n",
1349af3d8964SKalle Valo 		   psmode, vdev_id);
135097c63746SJohn Crispin 
135197c63746SJohn Crispin 	return ret;
135297c63746SJohn Crispin }
135397c63746SJohn Crispin 
1354d5c65159SKalle Valo int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt,
1355d5c65159SKalle Valo 			    u32 pdev_id)
1356d5c65159SKalle Valo {
1357d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1358d5c65159SKalle Valo 	struct wmi_pdev_suspend_cmd *cmd;
1359d5c65159SKalle Valo 	struct sk_buff *skb;
1360d5c65159SKalle Valo 	int ret;
1361d5c65159SKalle Valo 
13626bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1363d5c65159SKalle Valo 	if (!skb)
1364d5c65159SKalle Valo 		return -ENOMEM;
1365d5c65159SKalle Valo 
1366d5c65159SKalle Valo 	cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1367d5c65159SKalle Valo 
1368d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) |
1369d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1370d5c65159SKalle Valo 
1371d5c65159SKalle Valo 	cmd->suspend_opt = suspend_opt;
1372d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1373d5c65159SKalle Valo 
1374d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID);
1375d5c65159SKalle Valo 	if (ret) {
1376d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n");
1377d5c65159SKalle Valo 		dev_kfree_skb(skb);
1378d5c65159SKalle Valo 	}
1379d5c65159SKalle Valo 
1380d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1381d5c65159SKalle Valo 		   "WMI pdev suspend pdev_id %d\n", pdev_id);
1382d5c65159SKalle Valo 
1383d5c65159SKalle Valo 	return ret;
1384d5c65159SKalle Valo }
1385d5c65159SKalle Valo 
1386d5c65159SKalle Valo int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id)
1387d5c65159SKalle Valo {
1388d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1389d5c65159SKalle Valo 	struct wmi_pdev_resume_cmd *cmd;
1390d5c65159SKalle Valo 	struct sk_buff *skb;
1391d5c65159SKalle Valo 	int ret;
1392d5c65159SKalle Valo 
13936bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1394d5c65159SKalle Valo 	if (!skb)
1395d5c65159SKalle Valo 		return -ENOMEM;
1396d5c65159SKalle Valo 
1397d5c65159SKalle Valo 	cmd = (struct wmi_pdev_resume_cmd *)skb->data;
1398d5c65159SKalle Valo 
1399d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) |
1400d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1401d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1402d5c65159SKalle Valo 
1403d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1404d5c65159SKalle Valo 		   "WMI pdev resume pdev id %d\n", pdev_id);
1405d5c65159SKalle Valo 
1406d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID);
1407d5c65159SKalle Valo 	if (ret) {
1408d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n");
1409d5c65159SKalle Valo 		dev_kfree_skb(skb);
1410d5c65159SKalle Valo 	}
1411d5c65159SKalle Valo 
1412d5c65159SKalle Valo 	return ret;
1413d5c65159SKalle Valo }
1414d5c65159SKalle Valo 
1415d5c65159SKalle Valo /* TODO FW Support for the cmd is not available yet.
1416d5c65159SKalle Valo  * Can be tested once the command and corresponding
1417d5c65159SKalle Valo  * event is implemented in FW
1418d5c65159SKalle Valo  */
1419d5c65159SKalle Valo int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar,
1420d5c65159SKalle Valo 					  enum wmi_bss_chan_info_req_type type)
1421d5c65159SKalle Valo {
1422d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1423d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_req_cmd *cmd;
1424d5c65159SKalle Valo 	struct sk_buff *skb;
1425d5c65159SKalle Valo 	int ret;
1426d5c65159SKalle Valo 
14276bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1428d5c65159SKalle Valo 	if (!skb)
1429d5c65159SKalle Valo 		return -ENOMEM;
1430d5c65159SKalle Valo 
1431d5c65159SKalle Valo 	cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data;
1432d5c65159SKalle Valo 
1433d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1434d5c65159SKalle Valo 				     WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) |
1435d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1436d5c65159SKalle Valo 	cmd->req_type = type;
1437feab5bb8SSeevalamuthu Mariappan 	cmd->pdev_id = ar->pdev->pdev_id;
1438d5c65159SKalle Valo 
1439d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1440d5c65159SKalle Valo 		   "WMI bss chan info req type %d\n", type);
1441d5c65159SKalle Valo 
1442d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
1443d5c65159SKalle Valo 				  WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID);
1444d5c65159SKalle Valo 	if (ret) {
1445d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1446d5c65159SKalle Valo 			    "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n");
1447d5c65159SKalle Valo 		dev_kfree_skb(skb);
1448d5c65159SKalle Valo 	}
1449d5c65159SKalle Valo 
1450d5c65159SKalle Valo 	return ret;
1451d5c65159SKalle Valo }
1452d5c65159SKalle Valo 
1453d5c65159SKalle Valo int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr,
1454d5c65159SKalle Valo 					struct ap_ps_params *param)
1455d5c65159SKalle Valo {
1456d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1457d5c65159SKalle Valo 	struct wmi_ap_ps_peer_cmd *cmd;
1458d5c65159SKalle Valo 	struct sk_buff *skb;
1459d5c65159SKalle Valo 	int ret;
1460d5c65159SKalle Valo 
14616bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1462d5c65159SKalle Valo 	if (!skb)
1463d5c65159SKalle Valo 		return -ENOMEM;
1464d5c65159SKalle Valo 
1465d5c65159SKalle Valo 	cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1466d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) |
1467d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1468d5c65159SKalle Valo 
1469d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1470d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1471d5c65159SKalle Valo 	cmd->param = param->param;
1472d5c65159SKalle Valo 	cmd->value = param->value;
1473d5c65159SKalle Valo 
1474d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1475d5c65159SKalle Valo 	if (ret) {
1476d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1477d5c65159SKalle Valo 			    "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n");
1478d5c65159SKalle Valo 		dev_kfree_skb(skb);
1479d5c65159SKalle Valo 	}
1480d5c65159SKalle Valo 
1481d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1482d5c65159SKalle Valo 		   "WMI set ap ps vdev id %d peer %pM param %d value %d\n",
1483d5c65159SKalle Valo 		   param->vdev_id, peer_addr, param->param, param->value);
1484d5c65159SKalle Valo 
1485d5c65159SKalle Valo 	return ret;
1486d5c65159SKalle Valo }
1487d5c65159SKalle Valo 
1488d5c65159SKalle Valo int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id,
1489d5c65159SKalle Valo 				u32 param, u32 param_value)
1490d5c65159SKalle Valo {
1491d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1492d5c65159SKalle Valo 	struct wmi_sta_powersave_param_cmd *cmd;
1493d5c65159SKalle Valo 	struct sk_buff *skb;
1494d5c65159SKalle Valo 	int ret;
1495d5c65159SKalle Valo 
14966bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1497d5c65159SKalle Valo 	if (!skb)
1498d5c65159SKalle Valo 		return -ENOMEM;
1499d5c65159SKalle Valo 
1500d5c65159SKalle Valo 	cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1501d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1502d5c65159SKalle Valo 				     WMI_TAG_STA_POWERSAVE_PARAM_CMD) |
1503d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1504d5c65159SKalle Valo 
1505d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1506d5c65159SKalle Valo 	cmd->param = param;
1507d5c65159SKalle Valo 	cmd->value = param_value;
1508d5c65159SKalle Valo 
1509d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1510d5c65159SKalle Valo 		   "WMI set sta ps vdev_id %d param %d value %d\n",
1511d5c65159SKalle Valo 		   vdev_id, param, param_value);
1512d5c65159SKalle Valo 
1513d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1514d5c65159SKalle Valo 	if (ret) {
1515d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID");
1516d5c65159SKalle Valo 		dev_kfree_skb(skb);
1517d5c65159SKalle Valo 	}
1518d5c65159SKalle Valo 
1519d5c65159SKalle Valo 	return ret;
1520d5c65159SKalle Valo }
1521d5c65159SKalle Valo 
1522d5c65159SKalle Valo int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms)
1523d5c65159SKalle Valo {
1524d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1525d5c65159SKalle Valo 	struct wmi_force_fw_hang_cmd *cmd;
1526d5c65159SKalle Valo 	struct sk_buff *skb;
1527d5c65159SKalle Valo 	int ret, len;
1528d5c65159SKalle Valo 
1529d5c65159SKalle Valo 	len = sizeof(*cmd);
1530d5c65159SKalle Valo 
15316bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1532d5c65159SKalle Valo 	if (!skb)
1533d5c65159SKalle Valo 		return -ENOMEM;
1534d5c65159SKalle Valo 
1535d5c65159SKalle Valo 	cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
1536d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) |
1537d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1538d5c65159SKalle Valo 
1539d5c65159SKalle Valo 	cmd->type = type;
1540d5c65159SKalle Valo 	cmd->delay_time_ms = delay_time_ms;
1541d5c65159SKalle Valo 
1542d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID);
1543d5c65159SKalle Valo 
1544d5c65159SKalle Valo 	if (ret) {
1545d5c65159SKalle Valo 		ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID");
1546d5c65159SKalle Valo 		dev_kfree_skb(skb);
1547d5c65159SKalle Valo 	}
1548d5c65159SKalle Valo 	return ret;
1549d5c65159SKalle Valo }
1550d5c65159SKalle Valo 
1551d5c65159SKalle Valo int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id,
1552d5c65159SKalle Valo 				  u32 param_id, u32 param_value)
1553d5c65159SKalle Valo {
1554d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1555d5c65159SKalle Valo 	struct wmi_vdev_set_param_cmd *cmd;
1556d5c65159SKalle Valo 	struct sk_buff *skb;
1557d5c65159SKalle Valo 	int ret;
1558d5c65159SKalle Valo 
15596bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1560d5c65159SKalle Valo 	if (!skb)
1561d5c65159SKalle Valo 		return -ENOMEM;
1562d5c65159SKalle Valo 
1563d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1564d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) |
1565d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1566d5c65159SKalle Valo 
1567d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1568d5c65159SKalle Valo 	cmd->param_id = param_id;
1569d5c65159SKalle Valo 	cmd->param_value = param_value;
1570d5c65159SKalle Valo 
1571d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID);
1572d5c65159SKalle Valo 	if (ret) {
1573d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1574d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_PARAM_CMDID\n");
1575d5c65159SKalle Valo 		dev_kfree_skb(skb);
1576d5c65159SKalle Valo 	}
1577d5c65159SKalle Valo 
1578d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1579d5c65159SKalle Valo 		   "WMI vdev id 0x%x set param %d value %d\n",
1580d5c65159SKalle Valo 		   vdev_id, param_id, param_value);
1581d5c65159SKalle Valo 
1582d5c65159SKalle Valo 	return ret;
1583d5c65159SKalle Valo }
1584d5c65159SKalle Valo 
1585d5c65159SKalle Valo int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar,
1586d5c65159SKalle Valo 				      struct stats_request_params *param)
1587d5c65159SKalle Valo {
1588d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1589d5c65159SKalle Valo 	struct wmi_request_stats_cmd *cmd;
1590d5c65159SKalle Valo 	struct sk_buff *skb;
1591d5c65159SKalle Valo 	int ret;
1592d5c65159SKalle Valo 
15936bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1594d5c65159SKalle Valo 	if (!skb)
1595d5c65159SKalle Valo 		return -ENOMEM;
1596d5c65159SKalle Valo 
1597d5c65159SKalle Valo 	cmd = (struct wmi_request_stats_cmd *)skb->data;
1598d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) |
1599d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1600d5c65159SKalle Valo 
1601d5c65159SKalle Valo 	cmd->stats_id = param->stats_id;
1602d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1603d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
1604d5c65159SKalle Valo 
1605d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID);
1606d5c65159SKalle Valo 	if (ret) {
1607d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n");
1608d5c65159SKalle Valo 		dev_kfree_skb(skb);
1609d5c65159SKalle Valo 	}
1610d5c65159SKalle Valo 
1611d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1612d5c65159SKalle Valo 		   "WMI request stats 0x%x vdev id %d pdev id %d\n",
1613d5c65159SKalle Valo 		   param->stats_id, param->vdev_id, param->pdev_id);
1614d5c65159SKalle Valo 
1615d5c65159SKalle Valo 	return ret;
1616d5c65159SKalle Valo }
1617d5c65159SKalle Valo 
1618a41d1034SPradeep Kumar Chitrapu int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar)
1619a41d1034SPradeep Kumar Chitrapu {
1620a41d1034SPradeep Kumar Chitrapu 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1621a41d1034SPradeep Kumar Chitrapu 	struct wmi_get_pdev_temperature_cmd *cmd;
1622a41d1034SPradeep Kumar Chitrapu 	struct sk_buff *skb;
1623a41d1034SPradeep Kumar Chitrapu 	int ret;
1624a41d1034SPradeep Kumar Chitrapu 
1625a41d1034SPradeep Kumar Chitrapu 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1626a41d1034SPradeep Kumar Chitrapu 	if (!skb)
1627a41d1034SPradeep Kumar Chitrapu 		return -ENOMEM;
1628a41d1034SPradeep Kumar Chitrapu 
1629a41d1034SPradeep Kumar Chitrapu 	cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data;
1630a41d1034SPradeep Kumar Chitrapu 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) |
1631a41d1034SPradeep Kumar Chitrapu 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1632a41d1034SPradeep Kumar Chitrapu 	cmd->pdev_id = ar->pdev->pdev_id;
1633a41d1034SPradeep Kumar Chitrapu 
1634a41d1034SPradeep Kumar Chitrapu 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID);
1635a41d1034SPradeep Kumar Chitrapu 	if (ret) {
1636a41d1034SPradeep Kumar Chitrapu 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n");
1637a41d1034SPradeep Kumar Chitrapu 		dev_kfree_skb(skb);
1638a41d1034SPradeep Kumar Chitrapu 	}
1639a41d1034SPradeep Kumar Chitrapu 
1640a41d1034SPradeep Kumar Chitrapu 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1641a41d1034SPradeep Kumar Chitrapu 		   "WMI pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id);
1642a41d1034SPradeep Kumar Chitrapu 
1643a41d1034SPradeep Kumar Chitrapu 	return ret;
1644a41d1034SPradeep Kumar Chitrapu }
1645a41d1034SPradeep Kumar Chitrapu 
1646d5c65159SKalle Valo int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar,
1647d5c65159SKalle Valo 					    u32 vdev_id, u32 bcn_ctrl_op)
1648d5c65159SKalle Valo {
1649d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1650d5c65159SKalle Valo 	struct wmi_bcn_offload_ctrl_cmd *cmd;
1651d5c65159SKalle Valo 	struct sk_buff *skb;
1652d5c65159SKalle Valo 	int ret;
1653d5c65159SKalle Valo 
16546bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1655d5c65159SKalle Valo 	if (!skb)
1656d5c65159SKalle Valo 		return -ENOMEM;
1657d5c65159SKalle Valo 
1658d5c65159SKalle Valo 	cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data;
1659d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1660d5c65159SKalle Valo 				     WMI_TAG_BCN_OFFLOAD_CTRL_CMD) |
1661d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1662d5c65159SKalle Valo 
1663d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1664d5c65159SKalle Valo 	cmd->bcn_ctrl_op = bcn_ctrl_op;
1665d5c65159SKalle Valo 
1666d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1667d5c65159SKalle Valo 		   "WMI bcn ctrl offload vdev id %d ctrl_op %d\n",
1668d5c65159SKalle Valo 		   vdev_id, bcn_ctrl_op);
1669d5c65159SKalle Valo 
1670d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID);
1671d5c65159SKalle Valo 	if (ret) {
1672d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1673d5c65159SKalle Valo 			    "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n");
1674d5c65159SKalle Valo 		dev_kfree_skb(skb);
1675d5c65159SKalle Valo 	}
1676d5c65159SKalle Valo 
1677d5c65159SKalle Valo 	return ret;
1678d5c65159SKalle Valo }
1679d5c65159SKalle Valo 
1680d5c65159SKalle Valo int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id,
1681d5c65159SKalle Valo 			struct ieee80211_mutable_offsets *offs,
1682d5c65159SKalle Valo 			struct sk_buff *bcn)
1683d5c65159SKalle Valo {
1684d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1685d5c65159SKalle Valo 	struct wmi_bcn_tmpl_cmd *cmd;
1686d5c65159SKalle Valo 	struct wmi_bcn_prb_info *bcn_prb_info;
1687d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1688d5c65159SKalle Valo 	struct sk_buff *skb;
1689d5c65159SKalle Valo 	void *ptr;
1690d5c65159SKalle Valo 	int ret, len;
1691d5c65159SKalle Valo 	size_t aligned_len = roundup(bcn->len, 4);
1692886433a9SJohn Crispin 	struct ieee80211_vif *vif;
1693886433a9SJohn Crispin 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev_id);
1694886433a9SJohn Crispin 
1695886433a9SJohn Crispin 	if (!arvif) {
1696886433a9SJohn Crispin 		ath11k_warn(ar->ab, "failed to find arvif with vdev id %d\n", vdev_id);
1697886433a9SJohn Crispin 		return -EINVAL;
1698886433a9SJohn Crispin 	}
1699886433a9SJohn Crispin 
1700886433a9SJohn Crispin 	vif = arvif->vif;
1701d5c65159SKalle Valo 
1702d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len;
1703d5c65159SKalle Valo 
17046bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1705d5c65159SKalle Valo 	if (!skb)
1706d5c65159SKalle Valo 		return -ENOMEM;
1707d5c65159SKalle Valo 
1708d5c65159SKalle Valo 	cmd = (struct wmi_bcn_tmpl_cmd *)skb->data;
1709d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) |
1710d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1711d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1712d5c65159SKalle Valo 	cmd->tim_ie_offset = offs->tim_offset;
1713886433a9SJohn Crispin 
1714d0a9123eSJohannes Berg 	if (vif->bss_conf.csa_active) {
17158552a434SJohn Crispin 		cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0];
17168552a434SJohn Crispin 		cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1];
1717886433a9SJohn Crispin 	}
1718886433a9SJohn Crispin 
1719d5c65159SKalle Valo 	cmd->buf_len = bcn->len;
1720d5c65159SKalle Valo 
1721d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
1722d5c65159SKalle Valo 
1723d5c65159SKalle Valo 	bcn_prb_info = ptr;
1724d5c65159SKalle Valo 	len = sizeof(*bcn_prb_info);
1725d5c65159SKalle Valo 	bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1726d5c65159SKalle Valo 					      WMI_TAG_BCN_PRB_INFO) |
1727d5c65159SKalle Valo 				   FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1728d5c65159SKalle Valo 	bcn_prb_info->caps = 0;
1729d5c65159SKalle Valo 	bcn_prb_info->erp = 0;
1730d5c65159SKalle Valo 
1731d5c65159SKalle Valo 	ptr += sizeof(*bcn_prb_info);
1732d5c65159SKalle Valo 
1733d5c65159SKalle Valo 	tlv = ptr;
1734d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1735d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
1736d5c65159SKalle Valo 	memcpy(tlv->value, bcn->data, bcn->len);
1737d5c65159SKalle Valo 
1738d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID);
1739d5c65159SKalle Valo 	if (ret) {
1740d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n");
1741d5c65159SKalle Valo 		dev_kfree_skb(skb);
1742d5c65159SKalle Valo 	}
1743d5c65159SKalle Valo 
1744d5c65159SKalle Valo 	return ret;
1745d5c65159SKalle Valo }
1746d5c65159SKalle Valo 
1747d5c65159SKalle Valo int ath11k_wmi_vdev_install_key(struct ath11k *ar,
1748d5c65159SKalle Valo 				struct wmi_vdev_install_key_arg *arg)
1749d5c65159SKalle Valo {
1750d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1751d5c65159SKalle Valo 	struct wmi_vdev_install_key_cmd *cmd;
1752d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1753d5c65159SKalle Valo 	struct sk_buff *skb;
1754d5c65159SKalle Valo 	int ret, len;
1755d5c65159SKalle Valo 	int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t));
1756d5c65159SKalle Valo 
1757d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned;
1758d5c65159SKalle Valo 
17596bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1760d5c65159SKalle Valo 	if (!skb)
1761d5c65159SKalle Valo 		return -ENOMEM;
1762d5c65159SKalle Valo 
1763d5c65159SKalle Valo 	cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1764d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) |
1765d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1766d5c65159SKalle Valo 	cmd->vdev_id = arg->vdev_id;
1767d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1768d5c65159SKalle Valo 	cmd->key_idx = arg->key_idx;
1769d5c65159SKalle Valo 	cmd->key_flags = arg->key_flags;
1770d5c65159SKalle Valo 	cmd->key_cipher = arg->key_cipher;
1771d5c65159SKalle Valo 	cmd->key_len = arg->key_len;
1772d5c65159SKalle Valo 	cmd->key_txmic_len = arg->key_txmic_len;
1773d5c65159SKalle Valo 	cmd->key_rxmic_len = arg->key_rxmic_len;
1774d5c65159SKalle Valo 
1775d5c65159SKalle Valo 	if (arg->key_rsc_counter)
1776d5c65159SKalle Valo 		memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter,
1777d5c65159SKalle Valo 		       sizeof(struct wmi_key_seq_counter));
1778d5c65159SKalle Valo 
1779d5c65159SKalle Valo 	tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
1780d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1781d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, key_len_aligned);
1782436a4e88SKarthikeyan Kathirvel 	if (arg->key_data)
1783d5c65159SKalle Valo 		memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned);
1784d5c65159SKalle Valo 
1785d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1786d5c65159SKalle Valo 	if (ret) {
1787d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1788d5c65159SKalle Valo 			    "failed to send WMI_VDEV_INSTALL_KEY cmd\n");
1789d5c65159SKalle Valo 		dev_kfree_skb(skb);
1790d5c65159SKalle Valo 	}
1791d5c65159SKalle Valo 
1792d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1793d5c65159SKalle Valo 		   "WMI vdev install key idx %d cipher %d len %d\n",
1794d5c65159SKalle Valo 		   arg->key_idx, arg->key_cipher, arg->key_len);
1795d5c65159SKalle Valo 
1796d5c65159SKalle Valo 	return ret;
1797d5c65159SKalle Valo }
1798d5c65159SKalle Valo 
1799d5c65159SKalle Valo static inline void
1800d5c65159SKalle Valo ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd,
18011daf58b2SSeevalamuthu Mariappan 			   struct peer_assoc_params *param,
18021daf58b2SSeevalamuthu Mariappan 			   bool hw_crypto_disabled)
1803d5c65159SKalle Valo {
1804d5c65159SKalle Valo 	cmd->peer_flags = 0;
1805d5c65159SKalle Valo 
1806d5c65159SKalle Valo 	if (param->is_wme_set) {
1807d5c65159SKalle Valo 		if (param->qos_flag)
1808d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_QOS;
1809d5c65159SKalle Valo 		if (param->apsd_flag)
1810d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_APSD;
1811d5c65159SKalle Valo 		if (param->ht_flag)
1812d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_HT;
1813d5c65159SKalle Valo 		if (param->bw_40)
1814d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_40MHZ;
1815d5c65159SKalle Valo 		if (param->bw_80)
1816d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_80MHZ;
1817d5c65159SKalle Valo 		if (param->bw_160)
1818d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_160MHZ;
1819d5c65159SKalle Valo 
1820d5c65159SKalle Valo 		/* Typically if STBC is enabled for VHT it should be enabled
1821d5c65159SKalle Valo 		 * for HT as well
1822d5c65159SKalle Valo 		 **/
1823d5c65159SKalle Valo 		if (param->stbc_flag)
1824d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_STBC;
1825d5c65159SKalle Valo 
1826d5c65159SKalle Valo 		/* Typically if LDPC is enabled for VHT it should be enabled
1827d5c65159SKalle Valo 		 * for HT as well
1828d5c65159SKalle Valo 		 **/
1829d5c65159SKalle Valo 		if (param->ldpc_flag)
1830d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_LDPC;
1831d5c65159SKalle Valo 
1832d5c65159SKalle Valo 		if (param->static_mimops_flag)
1833d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1834d5c65159SKalle Valo 		if (param->dynamic_mimops_flag)
1835d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_DYN_MIMOPS;
1836d5c65159SKalle Valo 		if (param->spatial_mux_flag)
1837d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_SPATIAL_MUX;
1838d5c65159SKalle Valo 		if (param->vht_flag)
1839d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_VHT;
1840d5c65159SKalle Valo 		if (param->he_flag)
1841d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_HE;
18426d293d44SJohn Crispin 		if (param->twt_requester)
18436d293d44SJohn Crispin 			cmd->peer_flags |= WMI_PEER_TWT_REQ;
18446d293d44SJohn Crispin 		if (param->twt_responder)
18456d293d44SJohn Crispin 			cmd->peer_flags |= WMI_PEER_TWT_RESP;
1846d5c65159SKalle Valo 	}
1847d5c65159SKalle Valo 
1848d5c65159SKalle Valo 	/* Suppress authorization for all AUTH modes that need 4-way handshake
1849d5c65159SKalle Valo 	 * (during re-association).
1850d5c65159SKalle Valo 	 * Authorization will be done for these modes on key installation.
1851d5c65159SKalle Valo 	 */
1852d5c65159SKalle Valo 	if (param->auth_flag)
1853d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_AUTH;
185401e34233SVenkateswara Naralasetty 	if (param->need_ptk_4_way) {
1855d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1856c802b6d7SRameshkumar Sundaram 		if (!hw_crypto_disabled && param->is_assoc)
185701e34233SVenkateswara Naralasetty 			cmd->peer_flags &= ~WMI_PEER_AUTH;
185801e34233SVenkateswara Naralasetty 	}
1859d5c65159SKalle Valo 	if (param->need_gtk_2_way)
1860d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1861d5c65159SKalle Valo 	/* safe mode bypass the 4-way handshake */
1862d5c65159SKalle Valo 	if (param->safe_mode_enabled)
1863d5c65159SKalle Valo 		cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY |
1864d5c65159SKalle Valo 				     WMI_PEER_NEED_GTK_2_WAY);
1865d5c65159SKalle Valo 
1866d5c65159SKalle Valo 	if (param->is_pmf_enabled)
1867d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_PMF;
1868d5c65159SKalle Valo 
1869d5c65159SKalle Valo 	/* Disable AMSDU for station transmit, if user configures it */
1870d5c65159SKalle Valo 	/* Disable AMSDU for AP transmit to 11n Stations, if user configures
1871d5c65159SKalle Valo 	 * it
1872d5c65159SKalle Valo 	 * if (param->amsdu_disable) Add after FW support
1873d5c65159SKalle Valo 	 **/
1874d5c65159SKalle Valo 
1875d5c65159SKalle Valo 	/* Target asserts if node is marked HT and all MCS is set to 0.
1876d5c65159SKalle Valo 	 * Mark the node as non-HT if all the mcs rates are disabled through
1877d5c65159SKalle Valo 	 * iwpriv
1878d5c65159SKalle Valo 	 **/
1879d5c65159SKalle Valo 	if (param->peer_ht_rates.num_rates == 0)
1880d5c65159SKalle Valo 		cmd->peer_flags &= ~WMI_PEER_HT;
1881d5c65159SKalle Valo }
1882d5c65159SKalle Valo 
1883d5c65159SKalle Valo int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar,
1884d5c65159SKalle Valo 				   struct peer_assoc_params *param)
1885d5c65159SKalle Valo {
1886d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1887d5c65159SKalle Valo 	struct wmi_peer_assoc_complete_cmd *cmd;
1888d5c65159SKalle Valo 	struct wmi_vht_rate_set *mcs;
1889d5c65159SKalle Valo 	struct wmi_he_rate_set *he_mcs;
1890d5c65159SKalle Valo 	struct sk_buff *skb;
1891d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1892d5c65159SKalle Valo 	void *ptr;
1893d5c65159SKalle Valo 	u32 peer_legacy_rates_align;
1894d5c65159SKalle Valo 	u32 peer_ht_rates_align;
1895d5c65159SKalle Valo 	int i, ret, len;
1896d5c65159SKalle Valo 
1897d5c65159SKalle Valo 	peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates,
1898d5c65159SKalle Valo 					  sizeof(u32));
1899d5c65159SKalle Valo 	peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates,
1900d5c65159SKalle Valo 				      sizeof(u32));
1901d5c65159SKalle Valo 
1902d5c65159SKalle Valo 	len = sizeof(*cmd) +
1903d5c65159SKalle Valo 	      TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) +
1904d5c65159SKalle Valo 	      TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) +
1905d5c65159SKalle Valo 	      sizeof(*mcs) + TLV_HDR_SIZE +
1906d5c65159SKalle Valo 	      (sizeof(*he_mcs) * param->peer_he_mcs_count);
1907d5c65159SKalle Valo 
19086bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1909d5c65159SKalle Valo 	if (!skb)
1910d5c65159SKalle Valo 		return -ENOMEM;
1911d5c65159SKalle Valo 
1912d5c65159SKalle Valo 	ptr = skb->data;
1913d5c65159SKalle Valo 
1914d5c65159SKalle Valo 	cmd = ptr;
1915d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1916d5c65159SKalle Valo 				     WMI_TAG_PEER_ASSOC_COMPLETE_CMD) |
1917d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1918d5c65159SKalle Valo 
1919d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1920d5c65159SKalle Valo 
1921d5c65159SKalle Valo 	cmd->peer_new_assoc = param->peer_new_assoc;
1922d5c65159SKalle Valo 	cmd->peer_associd = param->peer_associd;
1923d5c65159SKalle Valo 
19241daf58b2SSeevalamuthu Mariappan 	ath11k_wmi_copy_peer_flags(cmd, param,
19251daf58b2SSeevalamuthu Mariappan 				   test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED,
19261daf58b2SSeevalamuthu Mariappan 					    &ar->ab->dev_flags));
1927d5c65159SKalle Valo 
1928d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac);
1929d5c65159SKalle Valo 
1930d5c65159SKalle Valo 	cmd->peer_rate_caps = param->peer_rate_caps;
1931d5c65159SKalle Valo 	cmd->peer_caps = param->peer_caps;
1932d5c65159SKalle Valo 	cmd->peer_listen_intval = param->peer_listen_intval;
1933d5c65159SKalle Valo 	cmd->peer_ht_caps = param->peer_ht_caps;
1934d5c65159SKalle Valo 	cmd->peer_max_mpdu = param->peer_max_mpdu;
1935d5c65159SKalle Valo 	cmd->peer_mpdu_density = param->peer_mpdu_density;
1936d5c65159SKalle Valo 	cmd->peer_vht_caps = param->peer_vht_caps;
1937d5c65159SKalle Valo 	cmd->peer_phymode = param->peer_phymode;
1938d5c65159SKalle Valo 
1939d5c65159SKalle Valo 	/* Update 11ax capabilities */
1940d5c65159SKalle Valo 	cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0];
1941d5c65159SKalle Valo 	cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1];
1942d5c65159SKalle Valo 	cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal;
194391270d70SPradeep Kumar Chitrapu 	cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz;
1944d5c65159SKalle Valo 	cmd->peer_he_ops = param->peer_he_ops;
1945d5c65159SKalle Valo 	memcpy(&cmd->peer_he_cap_phy, &param->peer_he_cap_phyinfo,
1946d5c65159SKalle Valo 	       sizeof(param->peer_he_cap_phyinfo));
1947d5c65159SKalle Valo 	memcpy(&cmd->peer_ppet, &param->peer_ppet,
1948d5c65159SKalle Valo 	       sizeof(param->peer_ppet));
1949d5c65159SKalle Valo 
1950d5c65159SKalle Valo 	/* Update peer legacy rate information */
1951d5c65159SKalle Valo 	ptr += sizeof(*cmd);
1952d5c65159SKalle Valo 
1953d5c65159SKalle Valo 	tlv = ptr;
1954d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1955d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align);
1956d5c65159SKalle Valo 
1957d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1958d5c65159SKalle Valo 
1959d5c65159SKalle Valo 	cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates;
1960d5c65159SKalle Valo 	memcpy(ptr, param->peer_legacy_rates.rates,
1961d5c65159SKalle Valo 	       param->peer_legacy_rates.num_rates);
1962d5c65159SKalle Valo 
1963d5c65159SKalle Valo 	/* Update peer HT rate information */
1964d5c65159SKalle Valo 	ptr += peer_legacy_rates_align;
1965d5c65159SKalle Valo 
1966d5c65159SKalle Valo 	tlv = ptr;
1967d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1968d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align);
1969d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1970d5c65159SKalle Valo 	cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates;
1971d5c65159SKalle Valo 	memcpy(ptr, param->peer_ht_rates.rates,
1972d5c65159SKalle Valo 	       param->peer_ht_rates.num_rates);
1973d5c65159SKalle Valo 
1974d5c65159SKalle Valo 	/* VHT Rates */
1975d5c65159SKalle Valo 	ptr += peer_ht_rates_align;
1976d5c65159SKalle Valo 
1977d5c65159SKalle Valo 	mcs = ptr;
1978d5c65159SKalle Valo 
1979d5c65159SKalle Valo 	mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) |
1980d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE);
1981d5c65159SKalle Valo 
1982d5c65159SKalle Valo 	cmd->peer_nss = param->peer_nss;
1983d5c65159SKalle Valo 
1984d5c65159SKalle Valo 	/* Update bandwidth-NSS mapping */
1985d5c65159SKalle Valo 	cmd->peer_bw_rxnss_override = 0;
1986d5c65159SKalle Valo 	cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override;
1987d5c65159SKalle Valo 
1988d5c65159SKalle Valo 	if (param->vht_capable) {
1989d5c65159SKalle Valo 		mcs->rx_max_rate = param->rx_max_rate;
1990d5c65159SKalle Valo 		mcs->rx_mcs_set = param->rx_mcs_set;
1991d5c65159SKalle Valo 		mcs->tx_max_rate = param->tx_max_rate;
1992d5c65159SKalle Valo 		mcs->tx_mcs_set = param->tx_mcs_set;
1993d5c65159SKalle Valo 	}
1994d5c65159SKalle Valo 
1995d5c65159SKalle Valo 	/* HE Rates */
1996d5c65159SKalle Valo 	cmd->peer_he_mcs = param->peer_he_mcs_count;
199791270d70SPradeep Kumar Chitrapu 	cmd->min_data_rate = param->min_data_rate;
1998d5c65159SKalle Valo 
1999d5c65159SKalle Valo 	ptr += sizeof(*mcs);
2000d5c65159SKalle Valo 
2001d5c65159SKalle Valo 	len = param->peer_he_mcs_count * sizeof(*he_mcs);
2002d5c65159SKalle Valo 
2003d5c65159SKalle Valo 	tlv = ptr;
2004d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2005d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2006d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2007d5c65159SKalle Valo 
2008d5c65159SKalle Valo 	/* Loop through the HE rate set */
2009d5c65159SKalle Valo 	for (i = 0; i < param->peer_he_mcs_count; i++) {
2010d5c65159SKalle Valo 		he_mcs = ptr;
2011d5c65159SKalle Valo 		he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2012d5c65159SKalle Valo 						WMI_TAG_HE_RATE_SET) |
2013d5c65159SKalle Valo 				     FIELD_PREP(WMI_TLV_LEN,
2014d5c65159SKalle Valo 						sizeof(*he_mcs) - TLV_HDR_SIZE);
2015d5c65159SKalle Valo 
201661fe43e7SMiles Hu 		he_mcs->rx_mcs_set = param->peer_he_tx_mcs_set[i];
201761fe43e7SMiles Hu 		he_mcs->tx_mcs_set = param->peer_he_rx_mcs_set[i];
2018d5c65159SKalle Valo 		ptr += sizeof(*he_mcs);
2019d5c65159SKalle Valo 	}
2020d5c65159SKalle Valo 
2021d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID);
2022d5c65159SKalle Valo 	if (ret) {
2023d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2024d5c65159SKalle Valo 			    "failed to send WMI_PEER_ASSOC_CMDID\n");
2025d5c65159SKalle Valo 		dev_kfree_skb(skb);
2026d5c65159SKalle Valo 	}
2027d5c65159SKalle Valo 
2028d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
20291cb616a3SSriram R 		   "wmi 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",
20301cb616a3SSriram R 		   cmd->vdev_id, cmd->peer_associd, param->peer_mac,
20311cb616a3SSriram R 		   cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps,
20321cb616a3SSriram R 		   cmd->peer_listen_intval, cmd->peer_ht_caps,
20331cb616a3SSriram R 		   cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode,
20341cb616a3SSriram R 		   cmd->peer_mpdu_density,
20351cb616a3SSriram R 		   cmd->peer_vht_caps, cmd->peer_he_cap_info,
20361cb616a3SSriram R 		   cmd->peer_he_ops, cmd->peer_he_cap_info_ext,
20371cb616a3SSriram R 		   cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1],
20381cb616a3SSriram R 		   cmd->peer_he_cap_phy[2],
20391cb616a3SSriram R 		   cmd->peer_bw_rxnss_override);
2040d5c65159SKalle Valo 
2041d5c65159SKalle Valo 	return ret;
2042d5c65159SKalle Valo }
2043d5c65159SKalle Valo 
2044d5c65159SKalle Valo void ath11k_wmi_start_scan_init(struct ath11k *ar,
2045d5c65159SKalle Valo 				struct scan_req_params *arg)
2046d5c65159SKalle Valo {
2047d5c65159SKalle Valo 	/* setup commonly used values */
2048d5c65159SKalle Valo 	arg->scan_req_id = 1;
20491f682dc9SWen Gong 	if (ar->state_11d == ATH11K_11D_PREPARING)
20501f682dc9SWen Gong 		arg->scan_priority = WMI_SCAN_PRIORITY_MEDIUM;
20511f682dc9SWen Gong 	else
2052d5c65159SKalle Valo 		arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
2053d5c65159SKalle Valo 	arg->dwell_time_active = 50;
2054d5c65159SKalle Valo 	arg->dwell_time_active_2g = 0;
2055d5c65159SKalle Valo 	arg->dwell_time_passive = 150;
2056194b8ea1SPradeep Kumar Chitrapu 	arg->dwell_time_active_6g = 40;
2057194b8ea1SPradeep Kumar Chitrapu 	arg->dwell_time_passive_6g = 30;
2058d5c65159SKalle Valo 	arg->min_rest_time = 50;
2059d5c65159SKalle Valo 	arg->max_rest_time = 500;
2060d5c65159SKalle Valo 	arg->repeat_probe_time = 0;
2061d5c65159SKalle Valo 	arg->probe_spacing_time = 0;
2062d5c65159SKalle Valo 	arg->idle_time = 0;
2063d5c65159SKalle Valo 	arg->max_scan_time = 20000;
2064d5c65159SKalle Valo 	arg->probe_delay = 5;
2065d5c65159SKalle Valo 	arg->notify_scan_events = WMI_SCAN_EVENT_STARTED |
2066d5c65159SKalle Valo 				  WMI_SCAN_EVENT_COMPLETED |
2067d5c65159SKalle Valo 				  WMI_SCAN_EVENT_BSS_CHANNEL |
2068d5c65159SKalle Valo 				  WMI_SCAN_EVENT_FOREIGN_CHAN |
2069d5c65159SKalle Valo 				  WMI_SCAN_EVENT_DEQUEUED;
2070d5c65159SKalle Valo 	arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2071d5c65159SKalle Valo 	arg->num_bssid = 1;
2072fa7572c2SCarl Huang 
2073fa7572c2SCarl Huang 	/* fill bssid_list[0] with 0xff, otherwise bssid and RA will be
2074fa7572c2SCarl Huang 	 * ZEROs in probe request
2075fa7572c2SCarl Huang 	 */
2076fa7572c2SCarl Huang 	eth_broadcast_addr(arg->bssid_list[0].addr);
2077d5c65159SKalle Valo }
2078d5c65159SKalle Valo 
2079d5c65159SKalle Valo static inline void
2080d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
2081d5c65159SKalle Valo 				       struct scan_req_params *param)
2082d5c65159SKalle Valo {
2083d5c65159SKalle Valo 	/* Scan events subscription */
2084d5c65159SKalle Valo 	if (param->scan_ev_started)
2085d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_STARTED;
2086d5c65159SKalle Valo 	if (param->scan_ev_completed)
2087d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_COMPLETED;
2088d5c65159SKalle Valo 	if (param->scan_ev_bss_chan)
2089d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_BSS_CHANNEL;
2090d5c65159SKalle Valo 	if (param->scan_ev_foreign_chan)
2091d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN;
2092d5c65159SKalle Valo 	if (param->scan_ev_dequeued)
2093d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_DEQUEUED;
2094d5c65159SKalle Valo 	if (param->scan_ev_preempted)
2095d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_PREEMPTED;
2096d5c65159SKalle Valo 	if (param->scan_ev_start_failed)
2097d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_START_FAILED;
2098d5c65159SKalle Valo 	if (param->scan_ev_restarted)
2099d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESTARTED;
2100d5c65159SKalle Valo 	if (param->scan_ev_foreign_chn_exit)
2101d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
2102d5c65159SKalle Valo 	if (param->scan_ev_suspended)
2103d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_SUSPENDED;
2104d5c65159SKalle Valo 	if (param->scan_ev_resumed)
2105d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESUMED;
2106d5c65159SKalle Valo 
2107d5c65159SKalle Valo 	/** Set scan control flags */
2108d5c65159SKalle Valo 	cmd->scan_ctrl_flags = 0;
2109d5c65159SKalle Valo 	if (param->scan_f_passive)
2110d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_PASSIVE;
2111d5c65159SKalle Valo 	if (param->scan_f_strict_passive_pch)
2112d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
2113d5c65159SKalle Valo 	if (param->scan_f_promisc_mode)
2114d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROMISCUOS;
2115d5c65159SKalle Valo 	if (param->scan_f_capture_phy_err)
2116d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CAPTURE_PHY_ERROR;
2117d5c65159SKalle Valo 	if (param->scan_f_half_rate)
2118d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
2119d5c65159SKalle Valo 	if (param->scan_f_quarter_rate)
2120d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
2121d5c65159SKalle Valo 	if (param->scan_f_cck_rates)
2122d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_CCK_RATES;
2123d5c65159SKalle Valo 	if (param->scan_f_ofdm_rates)
2124d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_OFDM_RATES;
2125d5c65159SKalle Valo 	if (param->scan_f_chan_stat_evnt)
2126d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CHAN_STAT_EVENT;
2127d5c65159SKalle Valo 	if (param->scan_f_filter_prb_req)
2128d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROBE_REQ;
2129d5c65159SKalle Valo 	if (param->scan_f_bcast_probe)
2130d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_BCAST_PROBE_REQ;
2131d5c65159SKalle Valo 	if (param->scan_f_offchan_mgmt_tx)
2132d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_MGMT_TX;
2133d5c65159SKalle Valo 	if (param->scan_f_offchan_data_tx)
2134d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_DATA_TX;
2135d5c65159SKalle Valo 	if (param->scan_f_force_active_dfs_chn)
2136d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
2137d5c65159SKalle Valo 	if (param->scan_f_add_tpc_ie_in_probe)
2138d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
2139d5c65159SKalle Valo 	if (param->scan_f_add_ds_ie_in_probe)
2140d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
2141d5c65159SKalle Valo 	if (param->scan_f_add_spoofed_mac_in_probe)
2142d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
2143d5c65159SKalle Valo 	if (param->scan_f_add_rand_seq_in_probe)
2144d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
2145d5c65159SKalle Valo 	if (param->scan_f_en_ie_whitelist_in_probe)
2146d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=
2147d5c65159SKalle Valo 			 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
2148d5c65159SKalle Valo 
2149d5c65159SKalle Valo 	/* for adaptive scan mode using 3 bits (21 - 23 bits) */
2150d5c65159SKalle Valo 	WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
2151d5c65159SKalle Valo 				param->adaptive_dwell_time_mode);
2152d5c65159SKalle Valo }
2153d5c65159SKalle Valo 
2154d5c65159SKalle Valo int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
2155d5c65159SKalle Valo 				   struct scan_req_params *params)
2156d5c65159SKalle Valo {
2157d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2158d5c65159SKalle Valo 	struct wmi_start_scan_cmd *cmd;
2159d5c65159SKalle Valo 	struct wmi_ssid *ssid = NULL;
2160d5c65159SKalle Valo 	struct wmi_mac_addr *bssid;
2161d5c65159SKalle Valo 	struct sk_buff *skb;
2162d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2163d5c65159SKalle Valo 	void *ptr;
2164d5c65159SKalle Valo 	int i, ret, len;
2165d5c65159SKalle Valo 	u32 *tmp_ptr;
2166a658c929SSven Eckelmann 	u16 extraie_len_with_pad = 0;
216774601ecfSPradeep Kumar Chitrapu 	struct hint_short_ssid *s_ssid = NULL;
216874601ecfSPradeep Kumar Chitrapu 	struct hint_bssid *hint_bssid = NULL;
2169d5c65159SKalle Valo 
2170d5c65159SKalle Valo 	len = sizeof(*cmd);
2171d5c65159SKalle Valo 
2172d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2173d5c65159SKalle Valo 	if (params->num_chan)
2174d5c65159SKalle Valo 		len += params->num_chan * sizeof(u32);
2175d5c65159SKalle Valo 
2176d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2177d5c65159SKalle Valo 	if (params->num_ssids)
2178d5c65159SKalle Valo 		len += params->num_ssids * sizeof(*ssid);
2179d5c65159SKalle Valo 
2180d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2181d5c65159SKalle Valo 	if (params->num_bssid)
2182d5c65159SKalle Valo 		len += sizeof(*bssid) * params->num_bssid;
2183d5c65159SKalle Valo 
2184d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2185a658c929SSven Eckelmann 	if (params->extraie.len && params->extraie.len <= 0xFFFF)
2186d5c65159SKalle Valo 		extraie_len_with_pad =
2187d5c65159SKalle Valo 			roundup(params->extraie.len, sizeof(u32));
2188d5c65159SKalle Valo 	len += extraie_len_with_pad;
2189d5c65159SKalle Valo 
219074601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid)
219174601ecfSPradeep Kumar Chitrapu 		len += TLV_HDR_SIZE +
219274601ecfSPradeep Kumar Chitrapu 		       params->num_hint_bssid * sizeof(struct hint_bssid);
219374601ecfSPradeep Kumar Chitrapu 
219474601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid)
219574601ecfSPradeep Kumar Chitrapu 		len += TLV_HDR_SIZE +
219674601ecfSPradeep Kumar Chitrapu 		       params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
219774601ecfSPradeep Kumar Chitrapu 
21986bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2199d5c65159SKalle Valo 	if (!skb)
2200d5c65159SKalle Valo 		return -ENOMEM;
2201d5c65159SKalle Valo 
2202d5c65159SKalle Valo 	ptr = skb->data;
2203d5c65159SKalle Valo 
2204d5c65159SKalle Valo 	cmd = ptr;
2205d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
2206d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2207d5c65159SKalle Valo 
2208d5c65159SKalle Valo 	cmd->scan_id = params->scan_id;
2209d5c65159SKalle Valo 	cmd->scan_req_id = params->scan_req_id;
2210d5c65159SKalle Valo 	cmd->vdev_id = params->vdev_id;
2211d5c65159SKalle Valo 	cmd->scan_priority = params->scan_priority;
2212d5c65159SKalle Valo 	cmd->notify_scan_events = params->notify_scan_events;
2213d5c65159SKalle Valo 
2214d5c65159SKalle Valo 	ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
2215d5c65159SKalle Valo 
2216d5c65159SKalle Valo 	cmd->dwell_time_active = params->dwell_time_active;
2217d5c65159SKalle Valo 	cmd->dwell_time_active_2g = params->dwell_time_active_2g;
2218d5c65159SKalle Valo 	cmd->dwell_time_passive = params->dwell_time_passive;
2219194b8ea1SPradeep Kumar Chitrapu 	cmd->dwell_time_active_6g = params->dwell_time_active_6g;
2220194b8ea1SPradeep Kumar Chitrapu 	cmd->dwell_time_passive_6g = params->dwell_time_passive_6g;
2221d5c65159SKalle Valo 	cmd->min_rest_time = params->min_rest_time;
2222d5c65159SKalle Valo 	cmd->max_rest_time = params->max_rest_time;
2223d5c65159SKalle Valo 	cmd->repeat_probe_time = params->repeat_probe_time;
2224d5c65159SKalle Valo 	cmd->probe_spacing_time = params->probe_spacing_time;
2225d5c65159SKalle Valo 	cmd->idle_time = params->idle_time;
2226d5c65159SKalle Valo 	cmd->max_scan_time = params->max_scan_time;
2227d5c65159SKalle Valo 	cmd->probe_delay = params->probe_delay;
2228d5c65159SKalle Valo 	cmd->burst_duration = params->burst_duration;
2229d5c65159SKalle Valo 	cmd->num_chan = params->num_chan;
2230d5c65159SKalle Valo 	cmd->num_bssid = params->num_bssid;
2231d5c65159SKalle Valo 	cmd->num_ssids = params->num_ssids;
2232d5c65159SKalle Valo 	cmd->ie_len = params->extraie.len;
2233d5c65159SKalle Valo 	cmd->n_probes = params->n_probes;
22349cbd7fc9SCarl Huang 	ether_addr_copy(cmd->mac_addr.addr, params->mac_addr.addr);
22359cbd7fc9SCarl Huang 	ether_addr_copy(cmd->mac_mask.addr, params->mac_mask.addr);
2236d5c65159SKalle Valo 
2237d5c65159SKalle Valo 	ptr += sizeof(*cmd);
2238d5c65159SKalle Valo 
2239d5c65159SKalle Valo 	len = params->num_chan * sizeof(u32);
2240d5c65159SKalle Valo 
2241d5c65159SKalle Valo 	tlv = ptr;
2242d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
2243d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2244d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2245d5c65159SKalle Valo 	tmp_ptr = (u32 *)ptr;
2246d5c65159SKalle Valo 
2247d5c65159SKalle Valo 	for (i = 0; i < params->num_chan; ++i)
2248d5c65159SKalle Valo 		tmp_ptr[i] = params->chan_list[i];
2249d5c65159SKalle Valo 
2250d5c65159SKalle Valo 	ptr += len;
2251d5c65159SKalle Valo 
2252d5c65159SKalle Valo 	len = params->num_ssids * sizeof(*ssid);
2253d5c65159SKalle Valo 	tlv = ptr;
2254d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2255d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2256d5c65159SKalle Valo 
2257d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2258d5c65159SKalle Valo 
2259d5c65159SKalle Valo 	if (params->num_ssids) {
2260d5c65159SKalle Valo 		ssid = ptr;
2261d5c65159SKalle Valo 		for (i = 0; i < params->num_ssids; ++i) {
2262d5c65159SKalle Valo 			ssid->ssid_len = params->ssid[i].length;
2263d5c65159SKalle Valo 			memcpy(ssid->ssid, params->ssid[i].ssid,
2264d5c65159SKalle Valo 			       params->ssid[i].length);
2265d5c65159SKalle Valo 			ssid++;
2266d5c65159SKalle Valo 		}
2267d5c65159SKalle Valo 	}
2268d5c65159SKalle Valo 
2269d5c65159SKalle Valo 	ptr += (params->num_ssids * sizeof(*ssid));
2270d5c65159SKalle Valo 	len = params->num_bssid * sizeof(*bssid);
2271d5c65159SKalle Valo 	tlv = ptr;
2272d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2273d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2274d5c65159SKalle Valo 
2275d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2276d5c65159SKalle Valo 	bssid = ptr;
2277d5c65159SKalle Valo 
2278d5c65159SKalle Valo 	if (params->num_bssid) {
2279d5c65159SKalle Valo 		for (i = 0; i < params->num_bssid; ++i) {
2280d5c65159SKalle Valo 			ether_addr_copy(bssid->addr,
2281d5c65159SKalle Valo 					params->bssid_list[i].addr);
2282d5c65159SKalle Valo 			bssid++;
2283d5c65159SKalle Valo 		}
2284d5c65159SKalle Valo 	}
2285d5c65159SKalle Valo 
2286d5c65159SKalle Valo 	ptr += params->num_bssid * sizeof(*bssid);
2287d5c65159SKalle Valo 
2288d5c65159SKalle Valo 	len = extraie_len_with_pad;
2289d5c65159SKalle Valo 	tlv = ptr;
2290d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2291d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2292d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2293d5c65159SKalle Valo 
2294a658c929SSven Eckelmann 	if (extraie_len_with_pad)
2295d5c65159SKalle Valo 		memcpy(ptr, params->extraie.ptr,
2296d5c65159SKalle Valo 		       params->extraie.len);
2297d5c65159SKalle Valo 
2298d5c65159SKalle Valo 	ptr += extraie_len_with_pad;
2299d5c65159SKalle Valo 
230074601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid) {
230174601ecfSPradeep Kumar Chitrapu 		len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
230274601ecfSPradeep Kumar Chitrapu 		tlv = ptr;
230374601ecfSPradeep Kumar Chitrapu 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
230474601ecfSPradeep Kumar Chitrapu 			      FIELD_PREP(WMI_TLV_LEN, len);
230574601ecfSPradeep Kumar Chitrapu 		ptr += TLV_HDR_SIZE;
230674601ecfSPradeep Kumar Chitrapu 		s_ssid = ptr;
230774601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_s_ssid; ++i) {
230874601ecfSPradeep Kumar Chitrapu 			s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
230974601ecfSPradeep Kumar Chitrapu 			s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
231074601ecfSPradeep Kumar Chitrapu 			s_ssid++;
231174601ecfSPradeep Kumar Chitrapu 		}
231274601ecfSPradeep Kumar Chitrapu 		ptr += len;
231374601ecfSPradeep Kumar Chitrapu 	}
231474601ecfSPradeep Kumar Chitrapu 
231574601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid) {
231674601ecfSPradeep Kumar Chitrapu 		len = params->num_hint_bssid * sizeof(struct hint_bssid);
231774601ecfSPradeep Kumar Chitrapu 		tlv = ptr;
231874601ecfSPradeep Kumar Chitrapu 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
231974601ecfSPradeep Kumar Chitrapu 			      FIELD_PREP(WMI_TLV_LEN, len);
232074601ecfSPradeep Kumar Chitrapu 		ptr += TLV_HDR_SIZE;
232174601ecfSPradeep Kumar Chitrapu 		hint_bssid = ptr;
232274601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_bssid; ++i) {
232374601ecfSPradeep Kumar Chitrapu 			hint_bssid->freq_flags =
232474601ecfSPradeep Kumar Chitrapu 				params->hint_bssid[i].freq_flags;
232574601ecfSPradeep Kumar Chitrapu 			ether_addr_copy(&params->hint_bssid[i].bssid.addr[0],
232674601ecfSPradeep Kumar Chitrapu 					&hint_bssid->bssid.addr[0]);
232774601ecfSPradeep Kumar Chitrapu 			hint_bssid++;
232874601ecfSPradeep Kumar Chitrapu 		}
232974601ecfSPradeep Kumar Chitrapu 	}
233074601ecfSPradeep Kumar Chitrapu 
2331d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2332d5c65159SKalle Valo 				  WMI_START_SCAN_CMDID);
2333d5c65159SKalle Valo 	if (ret) {
2334d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2335d5c65159SKalle Valo 		dev_kfree_skb(skb);
2336d5c65159SKalle Valo 	}
2337d5c65159SKalle Valo 
2338d5c65159SKalle Valo 	return ret;
2339d5c65159SKalle Valo }
2340d5c65159SKalle Valo 
2341d5c65159SKalle Valo int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2342d5c65159SKalle Valo 				  struct scan_cancel_param *param)
2343d5c65159SKalle Valo {
2344d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2345d5c65159SKalle Valo 	struct wmi_stop_scan_cmd *cmd;
2346d5c65159SKalle Valo 	struct sk_buff *skb;
2347d5c65159SKalle Valo 	int ret;
2348d5c65159SKalle Valo 
23496bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2350d5c65159SKalle Valo 	if (!skb)
2351d5c65159SKalle Valo 		return -ENOMEM;
2352d5c65159SKalle Valo 
2353d5c65159SKalle Valo 	cmd = (struct wmi_stop_scan_cmd *)skb->data;
2354d5c65159SKalle Valo 
2355d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2356d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2357d5c65159SKalle Valo 
2358d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
2359d5c65159SKalle Valo 	cmd->requestor = param->requester;
2360d5c65159SKalle Valo 	cmd->scan_id = param->scan_id;
2361d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
2362d5c65159SKalle Valo 	/* stop the scan with the corresponding scan_id */
2363d5c65159SKalle Valo 	if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2364d5c65159SKalle Valo 		/* Cancelling all scans */
2365d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ALL;
2366d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2367d5c65159SKalle Valo 		/* Cancelling VAP scans */
2368d5c65159SKalle Valo 		cmd->req_type =  WMI_SCN_STOP_VAP_ALL;
2369d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2370d5c65159SKalle Valo 		/* Cancelling specific scan */
2371d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ONE;
2372d5c65159SKalle Valo 	} else {
2373d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid scan cancel param %d",
2374d5c65159SKalle Valo 			    param->req_type);
2375d5c65159SKalle Valo 		dev_kfree_skb(skb);
2376d5c65159SKalle Valo 		return -EINVAL;
2377d5c65159SKalle Valo 	}
2378d5c65159SKalle Valo 
2379d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2380d5c65159SKalle Valo 				  WMI_STOP_SCAN_CMDID);
2381d5c65159SKalle Valo 	if (ret) {
2382d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2383d5c65159SKalle Valo 		dev_kfree_skb(skb);
2384d5c65159SKalle Valo 	}
2385d5c65159SKalle Valo 
2386d5c65159SKalle Valo 	return ret;
2387d5c65159SKalle Valo }
2388d5c65159SKalle Valo 
2389d5c65159SKalle Valo int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2390d5c65159SKalle Valo 				       struct scan_chan_list_params *chan_list)
2391d5c65159SKalle Valo {
2392d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2393d5c65159SKalle Valo 	struct wmi_scan_chan_list_cmd *cmd;
2394d5c65159SKalle Valo 	struct sk_buff *skb;
2395d5c65159SKalle Valo 	struct wmi_channel *chan_info;
2396d5c65159SKalle Valo 	struct channel_param *tchan_info;
2397d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2398d5c65159SKalle Valo 	void *ptr;
2399d5c65159SKalle Valo 	int i, ret, len;
2400bff621fdSPradeep Kumar Chitrapu 	u16 num_send_chans, num_sends = 0, max_chan_limit = 0;
2401d5c65159SKalle Valo 	u32 *reg1, *reg2;
2402d5c65159SKalle Valo 
2403b2549465SGustavo A. R. Silva 	tchan_info = chan_list->ch_param;
2404bff621fdSPradeep Kumar Chitrapu 	while (chan_list->nallchans) {
2405bff621fdSPradeep Kumar Chitrapu 		len = sizeof(*cmd) + TLV_HDR_SIZE;
2406bff621fdSPradeep Kumar Chitrapu 		max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) /
2407bff621fdSPradeep Kumar Chitrapu 			sizeof(*chan_info);
2408bff621fdSPradeep Kumar Chitrapu 
2409bff621fdSPradeep Kumar Chitrapu 		if (chan_list->nallchans > max_chan_limit)
2410bff621fdSPradeep Kumar Chitrapu 			num_send_chans = max_chan_limit;
2411bff621fdSPradeep Kumar Chitrapu 		else
2412bff621fdSPradeep Kumar Chitrapu 			num_send_chans = chan_list->nallchans;
2413bff621fdSPradeep Kumar Chitrapu 
2414bff621fdSPradeep Kumar Chitrapu 		chan_list->nallchans -= num_send_chans;
2415bff621fdSPradeep Kumar Chitrapu 		len += sizeof(*chan_info) * num_send_chans;
2416d5c65159SKalle Valo 
24176bc9d6f7SJohn Crispin 		skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2418d5c65159SKalle Valo 		if (!skb)
2419d5c65159SKalle Valo 			return -ENOMEM;
2420d5c65159SKalle Valo 
2421d5c65159SKalle Valo 		cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2422d5c65159SKalle Valo 		cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2423d5c65159SKalle Valo 			FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2424bff621fdSPradeep Kumar Chitrapu 		cmd->pdev_id = chan_list->pdev_id;
2425bff621fdSPradeep Kumar Chitrapu 		cmd->num_scan_chans = num_send_chans;
2426bff621fdSPradeep Kumar Chitrapu 		if (num_sends)
2427bff621fdSPradeep Kumar Chitrapu 			cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG;
2428d5c65159SKalle Valo 
2429d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2430bff621fdSPradeep Kumar Chitrapu 			   "WMI no.of chan = %d len = %d pdev_id = %d num_sends = %d\n",
2431bff621fdSPradeep Kumar Chitrapu 			   num_send_chans, len, cmd->pdev_id, num_sends);
2432d5c65159SKalle Valo 
2433d5c65159SKalle Valo 		ptr = skb->data + sizeof(*cmd);
2434d5c65159SKalle Valo 
2435bff621fdSPradeep Kumar Chitrapu 		len = sizeof(*chan_info) * num_send_chans;
2436d5c65159SKalle Valo 		tlv = ptr;
2437d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2438d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2439d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
2440d5c65159SKalle Valo 
2441bff621fdSPradeep Kumar Chitrapu 		for (i = 0; i < num_send_chans; ++i) {
2442d5c65159SKalle Valo 			chan_info = ptr;
2443d5c65159SKalle Valo 			memset(chan_info, 0, sizeof(*chan_info));
2444d5c65159SKalle Valo 			len = sizeof(*chan_info);
2445d5c65159SKalle Valo 			chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2446d5c65159SKalle Valo 							   WMI_TAG_CHANNEL) |
2447d5c65159SKalle Valo 						FIELD_PREP(WMI_TLV_LEN,
2448d5c65159SKalle Valo 							   len - TLV_HDR_SIZE);
2449d5c65159SKalle Valo 
2450d5c65159SKalle Valo 			reg1 = &chan_info->reg_info_1;
2451d5c65159SKalle Valo 			reg2 = &chan_info->reg_info_2;
2452d5c65159SKalle Valo 			chan_info->mhz = tchan_info->mhz;
2453d5c65159SKalle Valo 			chan_info->band_center_freq1 = tchan_info->cfreq1;
2454d5c65159SKalle Valo 			chan_info->band_center_freq2 = tchan_info->cfreq2;
2455d5c65159SKalle Valo 
2456d5c65159SKalle Valo 			if (tchan_info->is_chan_passive)
2457d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_PASSIVE;
24589f056ed8SJohn Crispin 			if (tchan_info->allow_he)
24599f056ed8SJohn Crispin 				chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
24609f056ed8SJohn Crispin 			else if (tchan_info->allow_vht)
2461d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2462d5c65159SKalle Valo 			else if (tchan_info->allow_ht)
2463d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2464d5c65159SKalle Valo 			if (tchan_info->half_rate)
2465d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2466d5c65159SKalle Valo 			if (tchan_info->quarter_rate)
2467d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2468bff621fdSPradeep Kumar Chitrapu 			if (tchan_info->psc_channel)
2469bff621fdSPradeep Kumar Chitrapu 				chan_info->info |= WMI_CHAN_INFO_PSC;
24708cd5c084SBaochen Qiang 			if (tchan_info->dfs_set)
24718cd5c084SBaochen Qiang 				chan_info->info |= WMI_CHAN_INFO_DFS;
2472d5c65159SKalle Valo 
2473d5c65159SKalle Valo 			chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2474d5c65159SKalle Valo 						      tchan_info->phy_mode);
2475d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2476d5c65159SKalle Valo 					    tchan_info->minpower);
2477d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2478d5c65159SKalle Valo 					    tchan_info->maxpower);
2479d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2480d5c65159SKalle Valo 					    tchan_info->maxregpower);
2481d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2482d5c65159SKalle Valo 					    tchan_info->reg_class_id);
2483d5c65159SKalle Valo 			*reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2484d5c65159SKalle Valo 					    tchan_info->antennamax);
24859212c1b9SP Praneesh 			*reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
24869212c1b9SP Praneesh 					    tchan_info->maxregpower);
2487d5c65159SKalle Valo 
2488d5c65159SKalle Valo 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2489bff621fdSPradeep Kumar Chitrapu 				   "WMI chan scan list chan[%d] = %u, chan_info->info %8x\n",
2490bff621fdSPradeep Kumar Chitrapu 				   i, chan_info->mhz, chan_info->info);
2491d5c65159SKalle Valo 
2492d5c65159SKalle Valo 			ptr += sizeof(*chan_info);
2493d5c65159SKalle Valo 
2494d5c65159SKalle Valo 			tchan_info++;
2495d5c65159SKalle Valo 		}
2496d5c65159SKalle Valo 
2497d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2498d5c65159SKalle Valo 		if (ret) {
2499d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2500d5c65159SKalle Valo 			dev_kfree_skb(skb);
2501bff621fdSPradeep Kumar Chitrapu 			return ret;
2502d5c65159SKalle Valo 		}
2503d5c65159SKalle Valo 
2504bff621fdSPradeep Kumar Chitrapu 		num_sends++;
2505bff621fdSPradeep Kumar Chitrapu 	}
2506bff621fdSPradeep Kumar Chitrapu 
2507bff621fdSPradeep Kumar Chitrapu 	return 0;
2508d5c65159SKalle Valo }
2509d5c65159SKalle Valo 
2510d5c65159SKalle Valo int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2511d5c65159SKalle Valo 				       struct wmi_wmm_params_all_arg *param)
2512d5c65159SKalle Valo {
2513d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2514d5c65159SKalle Valo 	struct wmi_vdev_set_wmm_params_cmd *cmd;
2515d5c65159SKalle Valo 	struct wmi_wmm_params *wmm_param;
2516d5c65159SKalle Valo 	struct wmi_wmm_params_arg *wmi_wmm_arg;
2517d5c65159SKalle Valo 	struct sk_buff *skb;
2518d5c65159SKalle Valo 	int ret, ac;
2519d5c65159SKalle Valo 
25206bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2521d5c65159SKalle Valo 	if (!skb)
2522d5c65159SKalle Valo 		return -ENOMEM;
2523d5c65159SKalle Valo 
2524d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2525d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2526d5c65159SKalle Valo 				     WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2527d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2528d5c65159SKalle Valo 
2529d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
2530d5c65159SKalle Valo 	cmd->wmm_param_type = 0;
2531d5c65159SKalle Valo 
2532d5c65159SKalle Valo 	for (ac = 0; ac < WME_NUM_AC; ac++) {
2533d5c65159SKalle Valo 		switch (ac) {
2534d5c65159SKalle Valo 		case WME_AC_BE:
2535d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_be;
2536d5c65159SKalle Valo 			break;
2537d5c65159SKalle Valo 		case WME_AC_BK:
2538d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_bk;
2539d5c65159SKalle Valo 			break;
2540d5c65159SKalle Valo 		case WME_AC_VI:
2541d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vi;
2542d5c65159SKalle Valo 			break;
2543d5c65159SKalle Valo 		case WME_AC_VO:
2544d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vo;
2545d5c65159SKalle Valo 			break;
2546d5c65159SKalle Valo 		}
2547d5c65159SKalle Valo 
2548d5c65159SKalle Valo 		wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2549d5c65159SKalle Valo 		wmm_param->tlv_header =
2550d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
2551d5c65159SKalle Valo 					   WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2552d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN,
2553d5c65159SKalle Valo 					   sizeof(*wmm_param) - TLV_HDR_SIZE);
2554d5c65159SKalle Valo 
2555d5c65159SKalle Valo 		wmm_param->aifs = wmi_wmm_arg->aifs;
2556d5c65159SKalle Valo 		wmm_param->cwmin = wmi_wmm_arg->cwmin;
2557d5c65159SKalle Valo 		wmm_param->cwmax = wmi_wmm_arg->cwmax;
2558d5c65159SKalle Valo 		wmm_param->txoplimit = wmi_wmm_arg->txop;
2559d5c65159SKalle Valo 		wmm_param->acm = wmi_wmm_arg->acm;
2560d5c65159SKalle Valo 		wmm_param->no_ack = wmi_wmm_arg->no_ack;
2561d5c65159SKalle Valo 
2562d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2563d5c65159SKalle Valo 			   "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2564d5c65159SKalle Valo 			   ac, wmm_param->aifs, wmm_param->cwmin,
2565d5c65159SKalle Valo 			   wmm_param->cwmax, wmm_param->txoplimit,
2566d5c65159SKalle Valo 			   wmm_param->acm, wmm_param->no_ack);
2567d5c65159SKalle Valo 	}
2568d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2569d5c65159SKalle Valo 				  WMI_VDEV_SET_WMM_PARAMS_CMDID);
2570d5c65159SKalle Valo 	if (ret) {
2571d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2572d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2573d5c65159SKalle Valo 		dev_kfree_skb(skb);
2574d5c65159SKalle Valo 	}
2575d5c65159SKalle Valo 
2576d5c65159SKalle Valo 	return ret;
2577d5c65159SKalle Valo }
2578d5c65159SKalle Valo 
2579d5c65159SKalle Valo int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2580d5c65159SKalle Valo 						  u32 pdev_id)
2581d5c65159SKalle Valo {
2582d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2583d5c65159SKalle Valo 	struct wmi_dfs_phyerr_offload_cmd *cmd;
2584d5c65159SKalle Valo 	struct sk_buff *skb;
2585d5c65159SKalle Valo 	int ret;
2586d5c65159SKalle Valo 
25876bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2588d5c65159SKalle Valo 	if (!skb)
2589d5c65159SKalle Valo 		return -ENOMEM;
2590d5c65159SKalle Valo 
2591d5c65159SKalle Valo 	cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2592d5c65159SKalle Valo 	cmd->tlv_header =
2593d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2594d5c65159SKalle Valo 			   WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2595d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2596d5c65159SKalle Valo 
2597d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
2598d5c65159SKalle Valo 
2599d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2600d5c65159SKalle Valo 		   "WMI dfs phy err offload enable pdev id %d\n", pdev_id);
2601d5c65159SKalle Valo 
2602d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2603d5c65159SKalle Valo 				  WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2604d5c65159SKalle Valo 	if (ret) {
2605d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2606d5c65159SKalle Valo 			    "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2607d5c65159SKalle Valo 		dev_kfree_skb(skb);
2608d5c65159SKalle Valo 	}
2609d5c65159SKalle Valo 
2610d5c65159SKalle Valo 	return ret;
2611d5c65159SKalle Valo }
2612d5c65159SKalle Valo 
26139556dfa2SMaharaja Kennadyrajan int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26149556dfa2SMaharaja Kennadyrajan 			  u32 tid, u32 initiator, u32 reason)
26159556dfa2SMaharaja Kennadyrajan {
26169556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26179556dfa2SMaharaja Kennadyrajan 	struct wmi_delba_send_cmd *cmd;
26189556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26199556dfa2SMaharaja Kennadyrajan 	int ret;
26209556dfa2SMaharaja Kennadyrajan 
26219556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26229556dfa2SMaharaja Kennadyrajan 	if (!skb)
26239556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
26249556dfa2SMaharaja Kennadyrajan 
26259556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_delba_send_cmd *)skb->data;
26269556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) |
26279556dfa2SMaharaja Kennadyrajan 			FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
26289556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
26299556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
26309556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
26319556dfa2SMaharaja Kennadyrajan 	cmd->initiator = initiator;
26329556dfa2SMaharaja Kennadyrajan 	cmd->reasoncode = reason;
26339556dfa2SMaharaja Kennadyrajan 
26349556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
26359556dfa2SMaharaja Kennadyrajan 		   "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
26369556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, initiator, reason);
26379556dfa2SMaharaja Kennadyrajan 
26389556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID);
26399556dfa2SMaharaja Kennadyrajan 
26409556dfa2SMaharaja Kennadyrajan 	if (ret) {
26419556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
26429556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_DELBA_SEND_CMDID cmd\n");
26439556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
26449556dfa2SMaharaja Kennadyrajan 	}
26459556dfa2SMaharaja Kennadyrajan 
26469556dfa2SMaharaja Kennadyrajan 	return ret;
26479556dfa2SMaharaja Kennadyrajan }
26489556dfa2SMaharaja Kennadyrajan 
26499556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26509556dfa2SMaharaja Kennadyrajan 			      u32 tid, u32 status)
26519556dfa2SMaharaja Kennadyrajan {
26529556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26539556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_setresponse_cmd *cmd;
26549556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26559556dfa2SMaharaja Kennadyrajan 	int ret;
26569556dfa2SMaharaja Kennadyrajan 
26579556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26589556dfa2SMaharaja Kennadyrajan 	if (!skb)
26599556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
26609556dfa2SMaharaja Kennadyrajan 
26619556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
26629556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header =
26639556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) |
26649556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
26659556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
26669556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
26679556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
26689556dfa2SMaharaja Kennadyrajan 	cmd->statuscode = status;
26699556dfa2SMaharaja Kennadyrajan 
26709556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
26719556dfa2SMaharaja Kennadyrajan 		   "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
26729556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, status);
26739556dfa2SMaharaja Kennadyrajan 
26749556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID);
26759556dfa2SMaharaja Kennadyrajan 
26769556dfa2SMaharaja Kennadyrajan 	if (ret) {
26779556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
26789556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n");
26799556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
26809556dfa2SMaharaja Kennadyrajan 	}
26819556dfa2SMaharaja Kennadyrajan 
26829556dfa2SMaharaja Kennadyrajan 	return ret;
26839556dfa2SMaharaja Kennadyrajan }
26849556dfa2SMaharaja Kennadyrajan 
26859556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26869556dfa2SMaharaja Kennadyrajan 			  u32 tid, u32 buf_size)
26879556dfa2SMaharaja Kennadyrajan {
26889556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26899556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_send_cmd *cmd;
26909556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26919556dfa2SMaharaja Kennadyrajan 	int ret;
26929556dfa2SMaharaja Kennadyrajan 
26939556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26949556dfa2SMaharaja Kennadyrajan 	if (!skb)
26959556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
26969556dfa2SMaharaja Kennadyrajan 
26979556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_send_cmd *)skb->data;
26989556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) |
26999556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27009556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
27019556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
27029556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
27039556dfa2SMaharaja Kennadyrajan 	cmd->buffersize = buf_size;
27049556dfa2SMaharaja Kennadyrajan 
27059556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
27069556dfa2SMaharaja Kennadyrajan 		   "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
27079556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, buf_size);
27089556dfa2SMaharaja Kennadyrajan 
27099556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID);
27109556dfa2SMaharaja Kennadyrajan 
27119556dfa2SMaharaja Kennadyrajan 	if (ret) {
27129556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
27139556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_SEND_CMDID cmd\n");
27149556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
27159556dfa2SMaharaja Kennadyrajan 	}
27169556dfa2SMaharaja Kennadyrajan 
27179556dfa2SMaharaja Kennadyrajan 	return ret;
27189556dfa2SMaharaja Kennadyrajan }
27199556dfa2SMaharaja Kennadyrajan 
27209556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac)
27219556dfa2SMaharaja Kennadyrajan {
27229556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
27239556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_clear_resp_cmd *cmd;
27249556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
27259556dfa2SMaharaja Kennadyrajan 	int ret;
27269556dfa2SMaharaja Kennadyrajan 
27279556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
27289556dfa2SMaharaja Kennadyrajan 	if (!skb)
27299556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
27309556dfa2SMaharaja Kennadyrajan 
27319556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
27329556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header =
27339556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) |
27349556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27359556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
27369556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
27379556dfa2SMaharaja Kennadyrajan 
27389556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
27399556dfa2SMaharaja Kennadyrajan 		   "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
27409556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac);
27419556dfa2SMaharaja Kennadyrajan 
27429556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID);
27439556dfa2SMaharaja Kennadyrajan 
27449556dfa2SMaharaja Kennadyrajan 	if (ret) {
27459556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
27469556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n");
27479556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
27489556dfa2SMaharaja Kennadyrajan 	}
27499556dfa2SMaharaja Kennadyrajan 
27509556dfa2SMaharaja Kennadyrajan 	return ret;
27519556dfa2SMaharaja Kennadyrajan }
27529556dfa2SMaharaja Kennadyrajan 
2753d5c65159SKalle Valo int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2754d5c65159SKalle Valo {
2755d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2756d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_cmd *cmd;
2757d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_info *info;
2758d5c65159SKalle Valo 	struct sk_buff *skb;
2759d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2760d5c65159SKalle Valo 	void *ptr;
2761d5c65159SKalle Valo 	int ret, len;
2762d5c65159SKalle Valo 
2763d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
27646bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2765d5c65159SKalle Valo 	if (!skb)
2766d5c65159SKalle Valo 		return -ENOMEM;
2767d5c65159SKalle Valo 
2768d5c65159SKalle Valo 	cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2769d5c65159SKalle Valo 
2770d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2771d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2772d5c65159SKalle Valo 
2773d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2774d5c65159SKalle Valo 	cmd->num_mac = 1;
2775d5c65159SKalle Valo 	cmd->enable = enable;
2776d5c65159SKalle Valo 
2777d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
2778d5c65159SKalle Valo 
2779d5c65159SKalle Valo 	tlv = ptr;
2780d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
278179c647a3SVikas Patel 		      FIELD_PREP(WMI_TLV_LEN, sizeof(*info));
2782d5c65159SKalle Valo 
2783d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2784d5c65159SKalle Valo 	info = ptr;
2785d5c65159SKalle Valo 
2786d5c65159SKalle Valo 	ether_addr_copy(info->peer_macaddr.addr, addr);
2787d5c65159SKalle Valo 	info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2788d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
2789d5c65159SKalle Valo 				      sizeof(*info) - TLV_HDR_SIZE);
2790d5c65159SKalle Valo 
2791d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2792d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_FILTER_CMDID);
2793d5c65159SKalle Valo 	if (ret) {
2794d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2795d5c65159SKalle Valo 		dev_kfree_skb(skb);
2796d5c65159SKalle Valo 	}
2797d5c65159SKalle Valo 
2798d5c65159SKalle Valo 	return ret;
2799d5c65159SKalle Valo }
2800d5c65159SKalle Valo 
2801d5c65159SKalle Valo int
2802d5c65159SKalle Valo ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2803d5c65159SKalle Valo 				 struct wmi_init_country_params init_cc_params)
2804d5c65159SKalle Valo {
2805d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2806d5c65159SKalle Valo 	struct wmi_init_country_cmd *cmd;
2807d5c65159SKalle Valo 	struct sk_buff *skb;
2808d5c65159SKalle Valo 	int ret;
2809d5c65159SKalle Valo 
28106bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2811d5c65159SKalle Valo 	if (!skb)
2812d5c65159SKalle Valo 		return -ENOMEM;
2813d5c65159SKalle Valo 
2814d5c65159SKalle Valo 	cmd = (struct wmi_init_country_cmd *)skb->data;
2815d5c65159SKalle Valo 	cmd->tlv_header =
2816d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2817d5c65159SKalle Valo 			   WMI_TAG_SET_INIT_COUNTRY_CMD) |
2818d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2819d5c65159SKalle Valo 
2820d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2821d5c65159SKalle Valo 
2822d5c65159SKalle Valo 	switch (init_cc_params.flags) {
2823d5c65159SKalle Valo 	case ALPHA_IS_SET:
2824d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2825d5c65159SKalle Valo 		memcpy((u8 *)&cmd->cc_info.alpha2,
2826d5c65159SKalle Valo 		       init_cc_params.cc_info.alpha2, 3);
2827d5c65159SKalle Valo 		break;
2828d5c65159SKalle Valo 	case CC_IS_SET:
2829d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2830d5c65159SKalle Valo 		cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2831d5c65159SKalle Valo 		break;
2832d5c65159SKalle Valo 	case REGDMN_IS_SET:
2833d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2834d5c65159SKalle Valo 		cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2835d5c65159SKalle Valo 		break;
2836d5c65159SKalle Valo 	default:
2837d5c65159SKalle Valo 		ret = -EINVAL;
2838d5c65159SKalle Valo 		goto out;
2839d5c65159SKalle Valo 	}
2840d5c65159SKalle Valo 
2841d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2842d5c65159SKalle Valo 				  WMI_SET_INIT_COUNTRY_CMDID);
2843d5c65159SKalle Valo 
2844d5c65159SKalle Valo out:
2845d5c65159SKalle Valo 	if (ret) {
2846d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2847d5c65159SKalle Valo 			    "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2848d5c65159SKalle Valo 			    ret);
2849d5c65159SKalle Valo 		dev_kfree_skb(skb);
2850d5c65159SKalle Valo 	}
2851d5c65159SKalle Valo 
2852d5c65159SKalle Valo 	return ret;
2853d5c65159SKalle Valo }
2854d5c65159SKalle Valo 
28550b05ddadSWen Gong int ath11k_wmi_send_set_current_country_cmd(struct ath11k *ar,
28560b05ddadSWen Gong 					    struct wmi_set_current_country_params *param)
28570b05ddadSWen Gong {
28580b05ddadSWen Gong 	struct ath11k_pdev_wmi *wmi = ar->wmi;
28590b05ddadSWen Gong 	struct wmi_set_current_country_cmd *cmd;
28600b05ddadSWen Gong 	struct sk_buff *skb;
28610b05ddadSWen Gong 	int ret;
28620b05ddadSWen Gong 
28630b05ddadSWen Gong 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
28640b05ddadSWen Gong 	if (!skb)
28650b05ddadSWen Gong 		return -ENOMEM;
28660b05ddadSWen Gong 
28670b05ddadSWen Gong 	cmd = (struct wmi_set_current_country_cmd *)skb->data;
28680b05ddadSWen Gong 	cmd->tlv_header =
28690b05ddadSWen Gong 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SET_CURRENT_COUNTRY_CMD) |
28700b05ddadSWen Gong 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
28710b05ddadSWen Gong 
28720b05ddadSWen Gong 	cmd->pdev_id = ar->pdev->pdev_id;
28730b05ddadSWen Gong 	memcpy(&cmd->new_alpha2, &param->alpha2, 3);
28740b05ddadSWen Gong 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SET_CURRENT_COUNTRY_CMDID);
28750b05ddadSWen Gong 
28760b05ddadSWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
28770b05ddadSWen Gong 		   "set current country pdev id %d alpha2 %c%c\n",
28780b05ddadSWen Gong 		   ar->pdev->pdev_id,
28790b05ddadSWen Gong 		   param->alpha2[0],
28800b05ddadSWen Gong 		   param->alpha2[1]);
28810b05ddadSWen Gong 
28820b05ddadSWen Gong 	if (ret) {
28830b05ddadSWen Gong 		ath11k_warn(ar->ab,
28840b05ddadSWen Gong 			    "failed to send WMI_SET_CURRENT_COUNTRY_CMDID: %d\n", ret);
28850b05ddadSWen Gong 		dev_kfree_skb(skb);
28860b05ddadSWen Gong 	}
28870b05ddadSWen Gong 
28880b05ddadSWen Gong 	return ret;
28890b05ddadSWen Gong }
28900b05ddadSWen Gong 
28912a63bbcaSPradeep Kumar Chitrapu int
28922a63bbcaSPradeep Kumar Chitrapu ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar,
28932a63bbcaSPradeep Kumar Chitrapu 					     struct thermal_mitigation_params *param)
28942a63bbcaSPradeep Kumar Chitrapu {
28952a63bbcaSPradeep Kumar Chitrapu 	struct ath11k_pdev_wmi *wmi = ar->wmi;
28962a63bbcaSPradeep Kumar Chitrapu 	struct wmi_therm_throt_config_request_cmd *cmd;
28972a63bbcaSPradeep Kumar Chitrapu 	struct wmi_therm_throt_level_config_info *lvl_conf;
28982a63bbcaSPradeep Kumar Chitrapu 	struct wmi_tlv *tlv;
28992a63bbcaSPradeep Kumar Chitrapu 	struct sk_buff *skb;
29002a63bbcaSPradeep Kumar Chitrapu 	int i, ret, len;
29012a63bbcaSPradeep Kumar Chitrapu 
29022a63bbcaSPradeep Kumar Chitrapu 	len = sizeof(*cmd) + TLV_HDR_SIZE +
29032a63bbcaSPradeep Kumar Chitrapu 	      THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info);
29042a63bbcaSPradeep Kumar Chitrapu 
29052a63bbcaSPradeep Kumar Chitrapu 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
29062a63bbcaSPradeep Kumar Chitrapu 	if (!skb)
29072a63bbcaSPradeep Kumar Chitrapu 		return -ENOMEM;
29082a63bbcaSPradeep Kumar Chitrapu 
29092a63bbcaSPradeep Kumar Chitrapu 	cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data;
29102a63bbcaSPradeep Kumar Chitrapu 
29112a63bbcaSPradeep Kumar Chitrapu 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) |
29122a63bbcaSPradeep Kumar Chitrapu 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
29132a63bbcaSPradeep Kumar Chitrapu 
29142a63bbcaSPradeep Kumar Chitrapu 	cmd->pdev_id = ar->pdev->pdev_id;
29152a63bbcaSPradeep Kumar Chitrapu 	cmd->enable = param->enable;
29162a63bbcaSPradeep Kumar Chitrapu 	cmd->dc = param->dc;
29172a63bbcaSPradeep Kumar Chitrapu 	cmd->dc_per_event = param->dc_per_event;
29182a63bbcaSPradeep Kumar Chitrapu 	cmd->therm_throt_levels = THERMAL_LEVELS;
29192a63bbcaSPradeep Kumar Chitrapu 
29202a63bbcaSPradeep Kumar Chitrapu 	tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
29212a63bbcaSPradeep Kumar Chitrapu 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
29222a63bbcaSPradeep Kumar Chitrapu 		      FIELD_PREP(WMI_TLV_LEN,
29232a63bbcaSPradeep Kumar Chitrapu 				 (THERMAL_LEVELS *
29242a63bbcaSPradeep Kumar Chitrapu 				  sizeof(struct wmi_therm_throt_level_config_info)));
29252a63bbcaSPradeep Kumar Chitrapu 
29262a63bbcaSPradeep Kumar Chitrapu 	lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data +
29272a63bbcaSPradeep Kumar Chitrapu 								sizeof(*cmd) +
29282a63bbcaSPradeep Kumar Chitrapu 								TLV_HDR_SIZE);
29292a63bbcaSPradeep Kumar Chitrapu 	for (i = 0; i < THERMAL_LEVELS; i++) {
29302a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->tlv_header =
29312a63bbcaSPradeep Kumar Chitrapu 			FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) |
29322a63bbcaSPradeep Kumar Chitrapu 			FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE);
29332a63bbcaSPradeep Kumar Chitrapu 
29342a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->temp_lwm = param->levelconf[i].tmplwm;
29352a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->temp_hwm = param->levelconf[i].tmphwm;
29362a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent;
29372a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->prio = param->levelconf[i].priority;
29382a63bbcaSPradeep Kumar Chitrapu 		lvl_conf++;
29392a63bbcaSPradeep Kumar Chitrapu 	}
29402a63bbcaSPradeep Kumar Chitrapu 
29412a63bbcaSPradeep Kumar Chitrapu 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID);
29422a63bbcaSPradeep Kumar Chitrapu 	if (ret) {
29432a63bbcaSPradeep Kumar Chitrapu 		ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n");
29442a63bbcaSPradeep Kumar Chitrapu 		dev_kfree_skb(skb);
29452a63bbcaSPradeep Kumar Chitrapu 	}
29462a63bbcaSPradeep Kumar Chitrapu 
29472a63bbcaSPradeep Kumar Chitrapu 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
29482a63bbcaSPradeep Kumar Chitrapu 		   "WMI vdev set thermal throt pdev_id %d enable %d dc %d dc_per_event %x levels %d\n",
29492a63bbcaSPradeep Kumar Chitrapu 		   ar->pdev->pdev_id, param->enable, param->dc,
29502a63bbcaSPradeep Kumar Chitrapu 		   param->dc_per_event, THERMAL_LEVELS);
29512a63bbcaSPradeep Kumar Chitrapu 
29522a63bbcaSPradeep Kumar Chitrapu 	return ret;
29532a63bbcaSPradeep Kumar Chitrapu }
29542a63bbcaSPradeep Kumar Chitrapu 
29559dcf6808SWen Gong int ath11k_wmi_send_11d_scan_start_cmd(struct ath11k *ar,
29569dcf6808SWen Gong 				       struct wmi_11d_scan_start_params *param)
29579dcf6808SWen Gong {
29589dcf6808SWen Gong 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29599dcf6808SWen Gong 	struct wmi_11d_scan_start_cmd *cmd;
29609dcf6808SWen Gong 	struct sk_buff *skb;
29619dcf6808SWen Gong 	int ret;
29629dcf6808SWen Gong 
29639dcf6808SWen Gong 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
29649dcf6808SWen Gong 	if (!skb)
29659dcf6808SWen Gong 		return -ENOMEM;
29669dcf6808SWen Gong 
29679dcf6808SWen Gong 	cmd = (struct wmi_11d_scan_start_cmd *)skb->data;
29689dcf6808SWen Gong 	cmd->tlv_header =
29699dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_START_CMD) |
29709dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
29719dcf6808SWen Gong 
29729dcf6808SWen Gong 	cmd->vdev_id = param->vdev_id;
29739dcf6808SWen Gong 	cmd->scan_period_msec = param->scan_period_msec;
29749dcf6808SWen Gong 	cmd->start_interval_msec = param->start_interval_msec;
29759dcf6808SWen Gong 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_START_CMDID);
29769dcf6808SWen Gong 
29779dcf6808SWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
29789dcf6808SWen Gong 		   "send 11d scan start vdev id %d period %d ms internal %d ms\n",
29799dcf6808SWen Gong 		   cmd->vdev_id,
29809dcf6808SWen Gong 		   cmd->scan_period_msec,
29819dcf6808SWen Gong 		   cmd->start_interval_msec);
29829dcf6808SWen Gong 
29839dcf6808SWen Gong 	if (ret) {
29849dcf6808SWen Gong 		ath11k_warn(ar->ab,
29859dcf6808SWen Gong 			    "failed to send WMI_11D_SCAN_START_CMDID: %d\n", ret);
29869dcf6808SWen Gong 		dev_kfree_skb(skb);
29879dcf6808SWen Gong 	}
29889dcf6808SWen Gong 
29899dcf6808SWen Gong 	return ret;
29909dcf6808SWen Gong }
29919dcf6808SWen Gong 
29929dcf6808SWen Gong int ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k *ar, u32 vdev_id)
29939dcf6808SWen Gong {
29949dcf6808SWen Gong 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29959dcf6808SWen Gong 	struct wmi_11d_scan_stop_cmd *cmd;
29969dcf6808SWen Gong 	struct sk_buff *skb;
29979dcf6808SWen Gong 	int ret;
29989dcf6808SWen Gong 
29999dcf6808SWen Gong 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
30009dcf6808SWen Gong 	if (!skb)
30019dcf6808SWen Gong 		return -ENOMEM;
30029dcf6808SWen Gong 
30039dcf6808SWen Gong 	cmd = (struct wmi_11d_scan_stop_cmd *)skb->data;
30049dcf6808SWen Gong 	cmd->tlv_header =
30059dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_STOP_CMD) |
30069dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
30079dcf6808SWen Gong 
30089dcf6808SWen Gong 	cmd->vdev_id = vdev_id;
30099dcf6808SWen Gong 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_STOP_CMDID);
30109dcf6808SWen Gong 
30119dcf6808SWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
30129dcf6808SWen Gong 		   "send 11d scan stop vdev id %d\n",
30139dcf6808SWen Gong 		   cmd->vdev_id);
30149dcf6808SWen Gong 
30159dcf6808SWen Gong 	if (ret) {
30169dcf6808SWen Gong 		ath11k_warn(ar->ab,
30179dcf6808SWen Gong 			    "failed to send WMI_11D_SCAN_STOP_CMDID: %d\n", ret);
30189dcf6808SWen Gong 		dev_kfree_skb(skb);
30199dcf6808SWen Gong 	}
30209dcf6808SWen Gong 
30219dcf6808SWen Gong 	return ret;
30229dcf6808SWen Gong }
30239dcf6808SWen Gong 
3024d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
3025d5c65159SKalle Valo {
3026d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3027d5c65159SKalle Valo 	struct wmi_pktlog_enable_cmd *cmd;
3028d5c65159SKalle Valo 	struct sk_buff *skb;
3029d5c65159SKalle Valo 	int ret;
3030d5c65159SKalle Valo 
30316bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3032d5c65159SKalle Valo 	if (!skb)
3033d5c65159SKalle Valo 		return -ENOMEM;
3034d5c65159SKalle Valo 
3035d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
3036d5c65159SKalle Valo 
3037d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
3038d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3039d5c65159SKalle Valo 
3040d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3041d5c65159SKalle Valo 	cmd->evlist = pktlog_filter;
3042d5c65159SKalle Valo 	cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
3043d5c65159SKalle Valo 
3044d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
3045d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_ENABLE_CMDID);
3046d5c65159SKalle Valo 	if (ret) {
3047d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3048d5c65159SKalle Valo 		dev_kfree_skb(skb);
3049d5c65159SKalle Valo 	}
3050d5c65159SKalle Valo 
3051d5c65159SKalle Valo 	return ret;
3052d5c65159SKalle Valo }
3053d5c65159SKalle Valo 
3054d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
3055d5c65159SKalle Valo {
3056d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3057d5c65159SKalle Valo 	struct wmi_pktlog_disable_cmd *cmd;
3058d5c65159SKalle Valo 	struct sk_buff *skb;
3059d5c65159SKalle Valo 	int ret;
3060d5c65159SKalle Valo 
30616bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3062d5c65159SKalle Valo 	if (!skb)
3063d5c65159SKalle Valo 		return -ENOMEM;
3064d5c65159SKalle Valo 
3065d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
3066d5c65159SKalle Valo 
3067d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
3068d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3069d5c65159SKalle Valo 
3070d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3071d5c65159SKalle Valo 
3072d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
3073d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_DISABLE_CMDID);
3074d5c65159SKalle Valo 	if (ret) {
3075d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3076d5c65159SKalle Valo 		dev_kfree_skb(skb);
3077d5c65159SKalle Valo 	}
3078d5c65159SKalle Valo 
3079d5c65159SKalle Valo 	return ret;
3080d5c65159SKalle Valo }
3081d5c65159SKalle Valo 
30829e2747c3SManikanta Pubbisetty void ath11k_wmi_fill_default_twt_params(struct wmi_twt_enable_params *twt_params)
30839e2747c3SManikanta Pubbisetty {
30849e2747c3SManikanta Pubbisetty 	twt_params->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
30859e2747c3SManikanta Pubbisetty 	twt_params->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
30869e2747c3SManikanta Pubbisetty 	twt_params->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
30879e2747c3SManikanta Pubbisetty 	twt_params->congestion_thresh_teardown =
30889e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
30899e2747c3SManikanta Pubbisetty 	twt_params->congestion_thresh_critical =
30909e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
30919e2747c3SManikanta Pubbisetty 	twt_params->interference_thresh_teardown =
30929e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
30939e2747c3SManikanta Pubbisetty 	twt_params->interference_thresh_setup =
30949e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
30959e2747c3SManikanta Pubbisetty 	twt_params->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
30969e2747c3SManikanta Pubbisetty 	twt_params->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
30979e2747c3SManikanta Pubbisetty 	twt_params->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
30989e2747c3SManikanta Pubbisetty 	twt_params->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
30999e2747c3SManikanta Pubbisetty 	twt_params->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
31009e2747c3SManikanta Pubbisetty 	twt_params->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
31019e2747c3SManikanta Pubbisetty 	twt_params->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
31029e2747c3SManikanta Pubbisetty 	twt_params->remove_sta_slot_interval =
31039e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
31049e2747c3SManikanta Pubbisetty 	/* TODO add MBSSID support */
31059e2747c3SManikanta Pubbisetty 	twt_params->mbss_support = 0;
31069e2747c3SManikanta Pubbisetty }
31079e2747c3SManikanta Pubbisetty 
31089e2747c3SManikanta Pubbisetty int ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id,
31099e2747c3SManikanta Pubbisetty 				   struct wmi_twt_enable_params *params)
31106d293d44SJohn Crispin {
31116d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
31126bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
31136d293d44SJohn Crispin 	struct wmi_twt_enable_params_cmd *cmd;
31146d293d44SJohn Crispin 	struct sk_buff *skb;
31156d293d44SJohn Crispin 	int ret, len;
31166d293d44SJohn Crispin 
31176d293d44SJohn Crispin 	len = sizeof(*cmd);
31186d293d44SJohn Crispin 
31196bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
31206d293d44SJohn Crispin 	if (!skb)
31216d293d44SJohn Crispin 		return -ENOMEM;
31226d293d44SJohn Crispin 
312377ea8b45SJohn Crispin 	cmd = (struct wmi_twt_enable_params_cmd *)skb->data;
31246d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
31256d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
31266d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
31279e2747c3SManikanta Pubbisetty 	cmd->sta_cong_timer_ms = params->sta_cong_timer_ms;
31289e2747c3SManikanta Pubbisetty 	cmd->default_slot_size = params->default_slot_size;
31299e2747c3SManikanta Pubbisetty 	cmd->congestion_thresh_setup = params->congestion_thresh_setup;
31309e2747c3SManikanta Pubbisetty 	cmd->congestion_thresh_teardown = params->congestion_thresh_teardown;
31319e2747c3SManikanta Pubbisetty 	cmd->congestion_thresh_critical = params->congestion_thresh_critical;
31329e2747c3SManikanta Pubbisetty 	cmd->interference_thresh_teardown = params->interference_thresh_teardown;
31339e2747c3SManikanta Pubbisetty 	cmd->interference_thresh_setup = params->interference_thresh_setup;
31349e2747c3SManikanta Pubbisetty 	cmd->min_no_sta_setup = params->min_no_sta_setup;
31359e2747c3SManikanta Pubbisetty 	cmd->min_no_sta_teardown = params->min_no_sta_teardown;
31369e2747c3SManikanta Pubbisetty 	cmd->no_of_bcast_mcast_slots = params->no_of_bcast_mcast_slots;
31379e2747c3SManikanta Pubbisetty 	cmd->min_no_twt_slots = params->min_no_twt_slots;
31389e2747c3SManikanta Pubbisetty 	cmd->max_no_sta_twt = params->max_no_sta_twt;
31399e2747c3SManikanta Pubbisetty 	cmd->mode_check_interval = params->mode_check_interval;
31409e2747c3SManikanta Pubbisetty 	cmd->add_sta_slot_interval = params->add_sta_slot_interval;
31419e2747c3SManikanta Pubbisetty 	cmd->remove_sta_slot_interval = params->remove_sta_slot_interval;
31429e2747c3SManikanta Pubbisetty 	cmd->mbss_support = params->mbss_support;
31436d293d44SJohn Crispin 
31443d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ENABLE_CMDID);
31456d293d44SJohn Crispin 	if (ret) {
31466d293d44SJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
31476d293d44SJohn Crispin 		dev_kfree_skb(skb);
31483d00e8b5SJohn Crispin 	} else {
31493d00e8b5SJohn Crispin 		ar->twt_enabled = 1;
31506d293d44SJohn Crispin 	}
31516d293d44SJohn Crispin 	return ret;
31526d293d44SJohn Crispin }
31536d293d44SJohn Crispin 
31546d293d44SJohn Crispin int
31556d293d44SJohn Crispin ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
31566d293d44SJohn Crispin {
31576d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
31586bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
31596d293d44SJohn Crispin 	struct wmi_twt_disable_params_cmd *cmd;
31606d293d44SJohn Crispin 	struct sk_buff *skb;
31616d293d44SJohn Crispin 	int ret, len;
31626d293d44SJohn Crispin 
31636d293d44SJohn Crispin 	len = sizeof(*cmd);
31646d293d44SJohn Crispin 
31656bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
31666d293d44SJohn Crispin 	if (!skb)
31676d293d44SJohn Crispin 		return -ENOMEM;
31686d293d44SJohn Crispin 
316977ea8b45SJohn Crispin 	cmd = (struct wmi_twt_disable_params_cmd *)skb->data;
31706d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
31716d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
31726d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
31736d293d44SJohn Crispin 
31743d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DISABLE_CMDID);
31756d293d44SJohn Crispin 	if (ret) {
3176345a4f22SColin Ian King 		ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID");
31776d293d44SJohn Crispin 		dev_kfree_skb(skb);
31783d00e8b5SJohn Crispin 	} else {
31793d00e8b5SJohn Crispin 		ar->twt_enabled = 0;
31803d00e8b5SJohn Crispin 	}
31813d00e8b5SJohn Crispin 	return ret;
31823d00e8b5SJohn Crispin }
31833d00e8b5SJohn Crispin 
31843d00e8b5SJohn Crispin int ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k *ar,
31853d00e8b5SJohn Crispin 				       struct wmi_twt_add_dialog_params *params)
31863d00e8b5SJohn Crispin {
31873d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
31883d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
31893d00e8b5SJohn Crispin 	struct wmi_twt_add_dialog_params_cmd *cmd;
31903d00e8b5SJohn Crispin 	struct sk_buff *skb;
31913d00e8b5SJohn Crispin 	int ret, len;
31923d00e8b5SJohn Crispin 
31933d00e8b5SJohn Crispin 	len = sizeof(*cmd);
31943d00e8b5SJohn Crispin 
31953d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
31963d00e8b5SJohn Crispin 	if (!skb)
31973d00e8b5SJohn Crispin 		return -ENOMEM;
31983d00e8b5SJohn Crispin 
31993d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_add_dialog_params_cmd *)skb->data;
32003d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ADD_DIALOG_CMD) |
32013d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32023d00e8b5SJohn Crispin 
32033d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
32043d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
32053d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
32063d00e8b5SJohn Crispin 	cmd->wake_intvl_us = params->wake_intvl_us;
32073d00e8b5SJohn Crispin 	cmd->wake_intvl_mantis = params->wake_intvl_mantis;
32083d00e8b5SJohn Crispin 	cmd->wake_dura_us = params->wake_dura_us;
32093d00e8b5SJohn Crispin 	cmd->sp_offset_us = params->sp_offset_us;
32103d00e8b5SJohn Crispin 	cmd->flags = params->twt_cmd;
32113d00e8b5SJohn Crispin 	if (params->flag_bcast)
32123d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_BCAST;
32133d00e8b5SJohn Crispin 	if (params->flag_trigger)
32143d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_TRIGGER;
32153d00e8b5SJohn Crispin 	if (params->flag_flow_type)
32163d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_FLOW_TYPE;
32173d00e8b5SJohn Crispin 	if (params->flag_protection)
32183d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_PROTECTION;
32193d00e8b5SJohn Crispin 
32203d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
32213d00e8b5SJohn Crispin 		   "wmi add twt dialog vdev %u dialog id %u wake interval %u mantissa %u wake duration %u service period offset %u flags 0x%x\n",
32223d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id, cmd->wake_intvl_us,
32233d00e8b5SJohn Crispin 		   cmd->wake_intvl_mantis, cmd->wake_dura_us, cmd->sp_offset_us,
32243d00e8b5SJohn Crispin 		   cmd->flags);
32253d00e8b5SJohn Crispin 
32263d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ADD_DIALOG_CMDID);
32273d00e8b5SJohn Crispin 
32283d00e8b5SJohn Crispin 	if (ret) {
32293d00e8b5SJohn Crispin 		ath11k_warn(ab,
32303d00e8b5SJohn Crispin 			    "failed to send wmi command to add twt dialog: %d",
32313d00e8b5SJohn Crispin 			    ret);
32323d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
32333d00e8b5SJohn Crispin 	}
32343d00e8b5SJohn Crispin 	return ret;
32353d00e8b5SJohn Crispin }
32363d00e8b5SJohn Crispin 
32373d00e8b5SJohn Crispin int ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k *ar,
32383d00e8b5SJohn Crispin 				       struct wmi_twt_del_dialog_params *params)
32393d00e8b5SJohn Crispin {
32403d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
32413d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
32423d00e8b5SJohn Crispin 	struct wmi_twt_del_dialog_params_cmd *cmd;
32433d00e8b5SJohn Crispin 	struct sk_buff *skb;
32443d00e8b5SJohn Crispin 	int ret, len;
32453d00e8b5SJohn Crispin 
32463d00e8b5SJohn Crispin 	len = sizeof(*cmd);
32473d00e8b5SJohn Crispin 
32483d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32493d00e8b5SJohn Crispin 	if (!skb)
32503d00e8b5SJohn Crispin 		return -ENOMEM;
32513d00e8b5SJohn Crispin 
32523d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_del_dialog_params_cmd *)skb->data;
32533d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DEL_DIALOG_CMD) |
32543d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32553d00e8b5SJohn Crispin 
32563d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
32573d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
32583d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
32593d00e8b5SJohn Crispin 
32603d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
32613d00e8b5SJohn Crispin 		   "wmi delete twt dialog vdev %u dialog id %u\n",
32623d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id);
32633d00e8b5SJohn Crispin 
32643d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DEL_DIALOG_CMDID);
32653d00e8b5SJohn Crispin 	if (ret) {
32663d00e8b5SJohn Crispin 		ath11k_warn(ab,
32673d00e8b5SJohn Crispin 			    "failed to send wmi command to delete twt dialog: %d",
32683d00e8b5SJohn Crispin 			    ret);
32693d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
32703d00e8b5SJohn Crispin 	}
32713d00e8b5SJohn Crispin 	return ret;
32723d00e8b5SJohn Crispin }
32733d00e8b5SJohn Crispin 
32743d00e8b5SJohn Crispin int ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k *ar,
32753d00e8b5SJohn Crispin 					 struct wmi_twt_pause_dialog_params *params)
32763d00e8b5SJohn Crispin {
32773d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
32783d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
32793d00e8b5SJohn Crispin 	struct wmi_twt_pause_dialog_params_cmd *cmd;
32803d00e8b5SJohn Crispin 	struct sk_buff *skb;
32813d00e8b5SJohn Crispin 	int ret, len;
32823d00e8b5SJohn Crispin 
32833d00e8b5SJohn Crispin 	len = sizeof(*cmd);
32843d00e8b5SJohn Crispin 
32853d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32863d00e8b5SJohn Crispin 	if (!skb)
32873d00e8b5SJohn Crispin 		return -ENOMEM;
32883d00e8b5SJohn Crispin 
32893d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_pause_dialog_params_cmd *)skb->data;
32903d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
32913d00e8b5SJohn Crispin 				     WMI_TAG_TWT_PAUSE_DIALOG_CMD) |
32923d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32933d00e8b5SJohn Crispin 
32943d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
32953d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
32963d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
32973d00e8b5SJohn Crispin 
32983d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
32993d00e8b5SJohn Crispin 		   "wmi pause twt dialog vdev %u dialog id %u\n",
33003d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id);
33013d00e8b5SJohn Crispin 
33023d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_PAUSE_DIALOG_CMDID);
33033d00e8b5SJohn Crispin 	if (ret) {
33043d00e8b5SJohn Crispin 		ath11k_warn(ab,
33053d00e8b5SJohn Crispin 			    "failed to send wmi command to pause twt dialog: %d",
33063d00e8b5SJohn Crispin 			    ret);
33073d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
33083d00e8b5SJohn Crispin 	}
33093d00e8b5SJohn Crispin 	return ret;
33103d00e8b5SJohn Crispin }
33113d00e8b5SJohn Crispin 
33123d00e8b5SJohn Crispin int ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k *ar,
33133d00e8b5SJohn Crispin 					  struct wmi_twt_resume_dialog_params *params)
33143d00e8b5SJohn Crispin {
33153d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
33163d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
33173d00e8b5SJohn Crispin 	struct wmi_twt_resume_dialog_params_cmd *cmd;
33183d00e8b5SJohn Crispin 	struct sk_buff *skb;
33193d00e8b5SJohn Crispin 	int ret, len;
33203d00e8b5SJohn Crispin 
33213d00e8b5SJohn Crispin 	len = sizeof(*cmd);
33223d00e8b5SJohn Crispin 
33233d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33243d00e8b5SJohn Crispin 	if (!skb)
33253d00e8b5SJohn Crispin 		return -ENOMEM;
33263d00e8b5SJohn Crispin 
33273d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_resume_dialog_params_cmd *)skb->data;
33283d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
33293d00e8b5SJohn Crispin 				     WMI_TAG_TWT_RESUME_DIALOG_CMD) |
33303d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33313d00e8b5SJohn Crispin 
33323d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
33333d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
33343d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
33353d00e8b5SJohn Crispin 	cmd->sp_offset_us = params->sp_offset_us;
33363d00e8b5SJohn Crispin 	cmd->next_twt_size = params->next_twt_size;
33373d00e8b5SJohn Crispin 
33383d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
33393d00e8b5SJohn Crispin 		   "wmi resume twt dialog vdev %u dialog id %u service period offset %u next twt subfield size %u\n",
33403d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id, cmd->sp_offset_us,
33413d00e8b5SJohn Crispin 		   cmd->next_twt_size);
33423d00e8b5SJohn Crispin 
33433d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_RESUME_DIALOG_CMDID);
33443d00e8b5SJohn Crispin 	if (ret) {
33453d00e8b5SJohn Crispin 		ath11k_warn(ab,
33463d00e8b5SJohn Crispin 			    "failed to send wmi command to resume twt dialog: %d",
33473d00e8b5SJohn Crispin 			    ret);
33483d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
33496d293d44SJohn Crispin 	}
33506d293d44SJohn Crispin 	return ret;
33516d293d44SJohn Crispin }
33526d293d44SJohn Crispin 
33533f8be640SJohn Crispin int
33543f8be640SJohn Crispin ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
33553f8be640SJohn Crispin 			     struct ieee80211_he_obss_pd *he_obss_pd)
33563f8be640SJohn Crispin {
33573f8be640SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
33586bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
33593f8be640SJohn Crispin 	struct wmi_obss_spatial_reuse_params_cmd *cmd;
33603f8be640SJohn Crispin 	struct sk_buff *skb;
33613f8be640SJohn Crispin 	int ret, len;
33623f8be640SJohn Crispin 
33633f8be640SJohn Crispin 	len = sizeof(*cmd);
33643f8be640SJohn Crispin 
33656bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33663f8be640SJohn Crispin 	if (!skb)
33673f8be640SJohn Crispin 		return -ENOMEM;
33683f8be640SJohn Crispin 
336977ea8b45SJohn Crispin 	cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data;
33703f8be640SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
33713f8be640SJohn Crispin 				     WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
33723f8be640SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33733f8be640SJohn Crispin 	cmd->vdev_id = vdev_id;
33743f8be640SJohn Crispin 	cmd->enable = he_obss_pd->enable;
33753f8be640SJohn Crispin 	cmd->obss_min = he_obss_pd->min_offset;
33763f8be640SJohn Crispin 	cmd->obss_max = he_obss_pd->max_offset;
33773f8be640SJohn Crispin 
33783f8be640SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
33793f8be640SJohn Crispin 				  WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
33803f8be640SJohn Crispin 	if (ret) {
33813f8be640SJohn Crispin 		ath11k_warn(ab,
33823f8be640SJohn Crispin 			    "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
33833f8be640SJohn Crispin 		dev_kfree_skb(skb);
33843f8be640SJohn Crispin 	}
33853f8be640SJohn Crispin 	return ret;
33863f8be640SJohn Crispin }
33873f8be640SJohn Crispin 
33885a032c8dSJohn Crispin int
3389b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k *ar, u32 *bitmap)
3390b56b08aeSRajkumar Manoharan {
3391b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3392b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3393b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3394b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3395b56b08aeSRajkumar Manoharan 	int ret, len;
3396b56b08aeSRajkumar Manoharan 
3397b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3398b56b08aeSRajkumar Manoharan 
3399b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3400b56b08aeSRajkumar Manoharan 	if (!skb)
3401b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3402b56b08aeSRajkumar Manoharan 
3403b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3404b56b08aeSRajkumar Manoharan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3405b56b08aeSRajkumar Manoharan 				     WMI_TAG_PDEV_SRG_BSS_COLOR_BITMAP_CMD) |
3406b56b08aeSRajkumar Manoharan 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3407b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3408b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3409b56b08aeSRajkumar Manoharan 
3410b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3411b56b08aeSRajkumar Manoharan 		   "obss pd pdev_id %d bss color bitmap %08x %08x\n",
3412b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3413b56b08aeSRajkumar Manoharan 
3414b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3415b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID);
3416b56b08aeSRajkumar Manoharan 	if (ret) {
3417b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3418b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID");
3419b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3420b56b08aeSRajkumar Manoharan 	}
3421b56b08aeSRajkumar Manoharan 
3422b56b08aeSRajkumar Manoharan 	return ret;
3423b56b08aeSRajkumar Manoharan }
3424b56b08aeSRajkumar Manoharan 
3425b56b08aeSRajkumar Manoharan int
3426b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k *ar, u32 *bitmap)
3427b56b08aeSRajkumar Manoharan {
3428b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3429b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3430b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3431b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3432b56b08aeSRajkumar Manoharan 	int ret, len;
3433b56b08aeSRajkumar Manoharan 
3434b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3435b56b08aeSRajkumar Manoharan 
3436b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3437b56b08aeSRajkumar Manoharan 	if (!skb)
3438b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3439b56b08aeSRajkumar Manoharan 
3440b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3441b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3442b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3443b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_SRG_PARTIAL_BSSID_BITMAP_CMD) |
3444b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3445b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3446b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3447b56b08aeSRajkumar Manoharan 
3448b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3449b56b08aeSRajkumar Manoharan 		   "obss pd pdev_id %d partial bssid bitmap %08x %08x\n",
3450b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3451b56b08aeSRajkumar Manoharan 
3452b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3453b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID);
3454b56b08aeSRajkumar Manoharan 	if (ret) {
3455b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3456b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID");
3457b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3458b56b08aeSRajkumar Manoharan 	}
3459b56b08aeSRajkumar Manoharan 
3460b56b08aeSRajkumar Manoharan 	return ret;
3461b56b08aeSRajkumar Manoharan }
3462b56b08aeSRajkumar Manoharan 
3463b56b08aeSRajkumar Manoharan int
3464b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3465b56b08aeSRajkumar Manoharan {
3466b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3467b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3468b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3469b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3470b56b08aeSRajkumar Manoharan 	int ret, len;
3471b56b08aeSRajkumar Manoharan 
3472b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3473b56b08aeSRajkumar Manoharan 
3474b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3475b56b08aeSRajkumar Manoharan 	if (!skb)
3476b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3477b56b08aeSRajkumar Manoharan 
3478b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3479b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3480b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3481b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3482b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3483b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3484b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3485b56b08aeSRajkumar Manoharan 
3486b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3487b56b08aeSRajkumar Manoharan 		   "obss pd srg pdev_id %d bss color enable bitmap %08x %08x\n",
3488b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3489b56b08aeSRajkumar Manoharan 
3490b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3491b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3492b56b08aeSRajkumar Manoharan 	if (ret) {
3493b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3494b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3495b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3496b56b08aeSRajkumar Manoharan 	}
3497b56b08aeSRajkumar Manoharan 
3498b56b08aeSRajkumar Manoharan 	return ret;
3499b56b08aeSRajkumar Manoharan }
3500b56b08aeSRajkumar Manoharan 
3501b56b08aeSRajkumar Manoharan int
3502b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3503b56b08aeSRajkumar Manoharan {
3504b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3505b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3506b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3507b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3508b56b08aeSRajkumar Manoharan 	int ret, len;
3509b56b08aeSRajkumar Manoharan 
3510b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3511b56b08aeSRajkumar Manoharan 
3512b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3513b56b08aeSRajkumar Manoharan 	if (!skb)
3514b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3515b56b08aeSRajkumar Manoharan 
3516b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3517b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3518b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3519b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3520b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3521b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3522b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3523b56b08aeSRajkumar Manoharan 
3524b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3525b56b08aeSRajkumar Manoharan 		   "obss pd srg pdev_id %d bssid enable bitmap %08x %08x\n",
3526b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3527b56b08aeSRajkumar Manoharan 
3528b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3529b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3530b56b08aeSRajkumar Manoharan 	if (ret) {
3531b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3532b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3533b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3534b56b08aeSRajkumar Manoharan 	}
3535b56b08aeSRajkumar Manoharan 
3536b56b08aeSRajkumar Manoharan 	return ret;
3537b56b08aeSRajkumar Manoharan }
3538b56b08aeSRajkumar Manoharan 
3539b56b08aeSRajkumar Manoharan int
3540b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3541b56b08aeSRajkumar Manoharan {
3542b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3543b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3544b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3545b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3546b56b08aeSRajkumar Manoharan 	int ret, len;
3547b56b08aeSRajkumar Manoharan 
3548b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3549b56b08aeSRajkumar Manoharan 
3550b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3551b56b08aeSRajkumar Manoharan 	if (!skb)
3552b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3553b56b08aeSRajkumar Manoharan 
3554b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3555b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3556b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3557b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3558b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3559b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3560b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3561b56b08aeSRajkumar Manoharan 
3562b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3563b56b08aeSRajkumar Manoharan 		   "obss pd non_srg pdev_id %d bss color enable bitmap %08x %08x\n",
3564b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3565b56b08aeSRajkumar Manoharan 
3566b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3567b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3568b56b08aeSRajkumar Manoharan 	if (ret) {
3569b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3570b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3571b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3572b56b08aeSRajkumar Manoharan 	}
3573b56b08aeSRajkumar Manoharan 
3574b56b08aeSRajkumar Manoharan 	return ret;
3575b56b08aeSRajkumar Manoharan }
3576b56b08aeSRajkumar Manoharan 
3577b56b08aeSRajkumar Manoharan int
3578b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3579b56b08aeSRajkumar Manoharan {
3580b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3581b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3582b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3583b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3584b56b08aeSRajkumar Manoharan 	int ret, len;
3585b56b08aeSRajkumar Manoharan 
3586b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3587b56b08aeSRajkumar Manoharan 
3588b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3589b56b08aeSRajkumar Manoharan 	if (!skb)
3590b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3591b56b08aeSRajkumar Manoharan 
3592b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3593b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3594b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3595b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3596b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3597b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3598b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3599b56b08aeSRajkumar Manoharan 
3600b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3601b56b08aeSRajkumar Manoharan 		   "obss pd non_srg pdev_id %d bssid enable bitmap %08x %08x\n",
3602b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3603b56b08aeSRajkumar Manoharan 
3604b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3605b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3606b56b08aeSRajkumar Manoharan 	if (ret) {
3607b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3608b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3609b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3610b56b08aeSRajkumar Manoharan 	}
3611b56b08aeSRajkumar Manoharan 
3612b56b08aeSRajkumar Manoharan 	return ret;
3613b56b08aeSRajkumar Manoharan }
3614b56b08aeSRajkumar Manoharan 
3615b56b08aeSRajkumar Manoharan int
36165a032c8dSJohn Crispin ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id,
36175a032c8dSJohn Crispin 					     u8 bss_color, u32 period,
36185a032c8dSJohn Crispin 					     bool enable)
36195a032c8dSJohn Crispin {
36205a032c8dSJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
36215a032c8dSJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
36225a032c8dSJohn Crispin 	struct wmi_obss_color_collision_cfg_params_cmd *cmd;
36235a032c8dSJohn Crispin 	struct sk_buff *skb;
36245a032c8dSJohn Crispin 	int ret, len;
36255a032c8dSJohn Crispin 
36265a032c8dSJohn Crispin 	len = sizeof(*cmd);
36275a032c8dSJohn Crispin 
36285a032c8dSJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
36295a032c8dSJohn Crispin 	if (!skb)
36305a032c8dSJohn Crispin 		return -ENOMEM;
36315a032c8dSJohn Crispin 
36325a032c8dSJohn Crispin 	cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data;
36335a032c8dSJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
36345a032c8dSJohn Crispin 				     WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) |
36355a032c8dSJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
36365a032c8dSJohn Crispin 	cmd->vdev_id = vdev_id;
36375a032c8dSJohn Crispin 	cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION :
36385a032c8dSJohn Crispin 				 ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE;
36395a032c8dSJohn Crispin 	cmd->current_bss_color = bss_color;
36405a032c8dSJohn Crispin 	cmd->detection_period_ms = period;
36415a032c8dSJohn Crispin 	cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS;
36425a032c8dSJohn Crispin 	cmd->free_slot_expiry_time_ms = 0;
36435a032c8dSJohn Crispin 	cmd->flags = 0;
36445a032c8dSJohn Crispin 
36455a032c8dSJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
36465a032c8dSJohn Crispin 		   "wmi_send_obss_color_collision_cfg id %d type %d bss_color %d detect_period %d scan_period %d\n",
36475a032c8dSJohn Crispin 		   cmd->vdev_id, cmd->evt_type, cmd->current_bss_color,
36485a032c8dSJohn Crispin 		   cmd->detection_period_ms, cmd->scan_period_ms);
36495a032c8dSJohn Crispin 
36505a032c8dSJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
36515a032c8dSJohn Crispin 				  WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID);
36525a032c8dSJohn Crispin 	if (ret) {
36535a032c8dSJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID");
36545a032c8dSJohn Crispin 		dev_kfree_skb(skb);
36555a032c8dSJohn Crispin 	}
36565a032c8dSJohn Crispin 	return ret;
36575a032c8dSJohn Crispin }
36585a032c8dSJohn Crispin 
36595a032c8dSJohn Crispin int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id,
36605a032c8dSJohn Crispin 						bool enable)
36615a032c8dSJohn Crispin {
36625a032c8dSJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
36635a032c8dSJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
36645a032c8dSJohn Crispin 	struct wmi_bss_color_change_enable_params_cmd *cmd;
36655a032c8dSJohn Crispin 	struct sk_buff *skb;
36665a032c8dSJohn Crispin 	int ret, len;
36675a032c8dSJohn Crispin 
36685a032c8dSJohn Crispin 	len = sizeof(*cmd);
36695a032c8dSJohn Crispin 
36705a032c8dSJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
36715a032c8dSJohn Crispin 	if (!skb)
36725a032c8dSJohn Crispin 		return -ENOMEM;
36735a032c8dSJohn Crispin 
36745a032c8dSJohn Crispin 	cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data;
36755a032c8dSJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) |
36765a032c8dSJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
36775a032c8dSJohn Crispin 	cmd->vdev_id = vdev_id;
36785a032c8dSJohn Crispin 	cmd->enable = enable ? 1 : 0;
36795a032c8dSJohn Crispin 
36805a032c8dSJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
36815a032c8dSJohn Crispin 		   "wmi_send_bss_color_change_enable id %d enable %d\n",
36825a032c8dSJohn Crispin 		   cmd->vdev_id, cmd->enable);
36835a032c8dSJohn Crispin 
36845a032c8dSJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
36855a032c8dSJohn Crispin 				  WMI_BSS_COLOR_CHANGE_ENABLE_CMDID);
36865a032c8dSJohn Crispin 	if (ret) {
36879a8074e3SColin Ian King 		ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID");
36885a032c8dSJohn Crispin 		dev_kfree_skb(skb);
36895a032c8dSJohn Crispin 	}
36905a032c8dSJohn Crispin 	return ret;
36915a032c8dSJohn Crispin }
36925a032c8dSJohn Crispin 
3693047679e3SAloka Dixit int ath11k_wmi_fils_discovery_tmpl(struct ath11k *ar, u32 vdev_id,
3694047679e3SAloka Dixit 				   struct sk_buff *tmpl)
3695047679e3SAloka Dixit {
3696047679e3SAloka Dixit 	struct wmi_tlv *tlv;
3697047679e3SAloka Dixit 	struct sk_buff *skb;
3698047679e3SAloka Dixit 	void *ptr;
3699047679e3SAloka Dixit 	int ret, len;
3700047679e3SAloka Dixit 	size_t aligned_len;
3701047679e3SAloka Dixit 	struct wmi_fils_discovery_tmpl_cmd *cmd;
3702047679e3SAloka Dixit 
3703047679e3SAloka Dixit 	aligned_len = roundup(tmpl->len, 4);
3704047679e3SAloka Dixit 	len = sizeof(*cmd) + TLV_HDR_SIZE + aligned_len;
3705047679e3SAloka Dixit 
3706047679e3SAloka Dixit 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3707047679e3SAloka Dixit 		   "WMI vdev %i set FILS discovery template\n", vdev_id);
3708047679e3SAloka Dixit 
3709047679e3SAloka Dixit 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3710047679e3SAloka Dixit 	if (!skb)
3711047679e3SAloka Dixit 		return -ENOMEM;
3712047679e3SAloka Dixit 
3713047679e3SAloka Dixit 	cmd = (struct wmi_fils_discovery_tmpl_cmd *)skb->data;
3714047679e3SAloka Dixit 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3715047679e3SAloka Dixit 				     WMI_TAG_FILS_DISCOVERY_TMPL_CMD) |
3716047679e3SAloka Dixit 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3717047679e3SAloka Dixit 	cmd->vdev_id = vdev_id;
3718047679e3SAloka Dixit 	cmd->buf_len = tmpl->len;
3719047679e3SAloka Dixit 	ptr = skb->data + sizeof(*cmd);
3720047679e3SAloka Dixit 
3721047679e3SAloka Dixit 	tlv = ptr;
3722047679e3SAloka Dixit 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3723047679e3SAloka Dixit 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
3724047679e3SAloka Dixit 	memcpy(tlv->value, tmpl->data, tmpl->len);
3725047679e3SAloka Dixit 
3726047679e3SAloka Dixit 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_FILS_DISCOVERY_TMPL_CMDID);
3727047679e3SAloka Dixit 	if (ret) {
3728047679e3SAloka Dixit 		ath11k_warn(ar->ab,
3729047679e3SAloka Dixit 			    "WMI vdev %i failed to send FILS discovery template command\n",
3730047679e3SAloka Dixit 			    vdev_id);
3731047679e3SAloka Dixit 		dev_kfree_skb(skb);
3732047679e3SAloka Dixit 	}
3733047679e3SAloka Dixit 	return ret;
3734047679e3SAloka Dixit }
3735047679e3SAloka Dixit 
3736047679e3SAloka Dixit int ath11k_wmi_probe_resp_tmpl(struct ath11k *ar, u32 vdev_id,
3737047679e3SAloka Dixit 			       struct sk_buff *tmpl)
3738047679e3SAloka Dixit {
3739047679e3SAloka Dixit 	struct wmi_probe_tmpl_cmd *cmd;
3740047679e3SAloka Dixit 	struct wmi_bcn_prb_info *probe_info;
3741047679e3SAloka Dixit 	struct wmi_tlv *tlv;
3742047679e3SAloka Dixit 	struct sk_buff *skb;
3743047679e3SAloka Dixit 	void *ptr;
3744047679e3SAloka Dixit 	int ret, len;
3745047679e3SAloka Dixit 	size_t aligned_len = roundup(tmpl->len, 4);
3746047679e3SAloka Dixit 
3747047679e3SAloka Dixit 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3748047679e3SAloka Dixit 		   "WMI vdev %i set probe response template\n", vdev_id);
3749047679e3SAloka Dixit 
3750047679e3SAloka Dixit 	len = sizeof(*cmd) + sizeof(*probe_info) + TLV_HDR_SIZE + aligned_len;
3751047679e3SAloka Dixit 
3752047679e3SAloka Dixit 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3753047679e3SAloka Dixit 	if (!skb)
3754047679e3SAloka Dixit 		return -ENOMEM;
3755047679e3SAloka Dixit 
3756047679e3SAloka Dixit 	cmd = (struct wmi_probe_tmpl_cmd *)skb->data;
3757047679e3SAloka Dixit 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PRB_TMPL_CMD) |
3758047679e3SAloka Dixit 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3759047679e3SAloka Dixit 	cmd->vdev_id = vdev_id;
3760047679e3SAloka Dixit 	cmd->buf_len = tmpl->len;
3761047679e3SAloka Dixit 
3762047679e3SAloka Dixit 	ptr = skb->data + sizeof(*cmd);
3763047679e3SAloka Dixit 
3764047679e3SAloka Dixit 	probe_info = ptr;
3765047679e3SAloka Dixit 	len = sizeof(*probe_info);
3766047679e3SAloka Dixit 	probe_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3767047679e3SAloka Dixit 					    WMI_TAG_BCN_PRB_INFO) |
3768047679e3SAloka Dixit 				 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3769047679e3SAloka Dixit 	probe_info->caps = 0;
3770047679e3SAloka Dixit 	probe_info->erp = 0;
3771047679e3SAloka Dixit 
3772047679e3SAloka Dixit 	ptr += sizeof(*probe_info);
3773047679e3SAloka Dixit 
3774047679e3SAloka Dixit 	tlv = ptr;
3775047679e3SAloka Dixit 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3776047679e3SAloka Dixit 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
3777047679e3SAloka Dixit 	memcpy(tlv->value, tmpl->data, tmpl->len);
3778047679e3SAloka Dixit 
3779047679e3SAloka Dixit 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_PRB_TMPL_CMDID);
3780047679e3SAloka Dixit 	if (ret) {
3781047679e3SAloka Dixit 		ath11k_warn(ar->ab,
3782047679e3SAloka Dixit 			    "WMI vdev %i failed to send probe response template command\n",
3783047679e3SAloka Dixit 			    vdev_id);
3784047679e3SAloka Dixit 		dev_kfree_skb(skb);
3785047679e3SAloka Dixit 	}
3786047679e3SAloka Dixit 	return ret;
3787047679e3SAloka Dixit }
3788047679e3SAloka Dixit 
3789047679e3SAloka Dixit int ath11k_wmi_fils_discovery(struct ath11k *ar, u32 vdev_id, u32 interval,
3790047679e3SAloka Dixit 			      bool unsol_bcast_probe_resp_enabled)
3791047679e3SAloka Dixit {
3792047679e3SAloka Dixit 	struct sk_buff *skb;
3793047679e3SAloka Dixit 	int ret, len;
3794047679e3SAloka Dixit 	struct wmi_fils_discovery_cmd *cmd;
3795047679e3SAloka Dixit 
3796047679e3SAloka Dixit 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3797047679e3SAloka Dixit 		   "WMI vdev %i set %s interval to %u TU\n",
3798047679e3SAloka Dixit 		   vdev_id, unsol_bcast_probe_resp_enabled ?
3799047679e3SAloka Dixit 		   "unsolicited broadcast probe response" : "FILS discovery",
3800047679e3SAloka Dixit 		   interval);
3801047679e3SAloka Dixit 
3802047679e3SAloka Dixit 	len = sizeof(*cmd);
3803047679e3SAloka Dixit 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3804047679e3SAloka Dixit 	if (!skb)
3805047679e3SAloka Dixit 		return -ENOMEM;
3806047679e3SAloka Dixit 
3807047679e3SAloka Dixit 	cmd = (struct wmi_fils_discovery_cmd *)skb->data;
3808047679e3SAloka Dixit 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ENABLE_FILS_CMD) |
3809047679e3SAloka Dixit 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3810047679e3SAloka Dixit 	cmd->vdev_id = vdev_id;
3811047679e3SAloka Dixit 	cmd->interval = interval;
3812047679e3SAloka Dixit 	cmd->config = unsol_bcast_probe_resp_enabled;
3813047679e3SAloka Dixit 
3814047679e3SAloka Dixit 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_ENABLE_FILS_CMDID);
3815047679e3SAloka Dixit 	if (ret) {
3816047679e3SAloka Dixit 		ath11k_warn(ar->ab,
3817047679e3SAloka Dixit 			    "WMI vdev %i failed to send FILS discovery enable/disable command\n",
3818047679e3SAloka Dixit 			    vdev_id);
3819047679e3SAloka Dixit 		dev_kfree_skb(skb);
3820047679e3SAloka Dixit 	}
3821047679e3SAloka Dixit 	return ret;
3822047679e3SAloka Dixit }
3823047679e3SAloka Dixit 
3824d5c65159SKalle Valo static void
3825886433a9SJohn Crispin ath11k_wmi_obss_color_collision_event(struct ath11k_base *ab, struct sk_buff *skb)
3826886433a9SJohn Crispin {
3827886433a9SJohn Crispin 	const void **tb;
3828886433a9SJohn Crispin 	const struct wmi_obss_color_collision_event *ev;
3829886433a9SJohn Crispin 	struct ath11k_vif *arvif;
3830886433a9SJohn Crispin 	int ret;
3831886433a9SJohn Crispin 
3832886433a9SJohn Crispin 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3833886433a9SJohn Crispin 	if (IS_ERR(tb)) {
3834886433a9SJohn Crispin 		ret = PTR_ERR(tb);
3835886433a9SJohn Crispin 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3836886433a9SJohn Crispin 		return;
3837886433a9SJohn Crispin 	}
3838886433a9SJohn Crispin 
383901e782c8SWen Gong 	rcu_read_lock();
384001e782c8SWen Gong 
3841886433a9SJohn Crispin 	ev = tb[WMI_TAG_OBSS_COLOR_COLLISION_EVT];
3842886433a9SJohn Crispin 	if (!ev) {
3843886433a9SJohn Crispin 		ath11k_warn(ab, "failed to fetch obss color collision ev");
3844886433a9SJohn Crispin 		goto exit;
3845886433a9SJohn Crispin 	}
3846886433a9SJohn Crispin 
3847886433a9SJohn Crispin 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
3848886433a9SJohn Crispin 	if (!arvif) {
3849886433a9SJohn Crispin 		ath11k_warn(ab, "failed to find arvif with vedv id %d in obss_color_collision_event\n",
3850886433a9SJohn Crispin 			    ev->vdev_id);
3851886433a9SJohn Crispin 		goto exit;
3852886433a9SJohn Crispin 	}
3853886433a9SJohn Crispin 
3854886433a9SJohn Crispin 	switch (ev->evt_type) {
3855886433a9SJohn Crispin 	case WMI_BSS_COLOR_COLLISION_DETECTION:
385603895c84SLorenzo Bianconi 		ieeee80211_obss_color_collision_notify(arvif->vif, ev->obss_color_bitmap,
385703895c84SLorenzo Bianconi 						       GFP_KERNEL);
3858886433a9SJohn Crispin 		ath11k_dbg(ab, ATH11K_DBG_WMI,
3859886433a9SJohn Crispin 			   "OBSS color collision detected vdev:%d, event:%d, bitmap:%08llx\n",
3860886433a9SJohn Crispin 			   ev->vdev_id, ev->evt_type, ev->obss_color_bitmap);
3861886433a9SJohn Crispin 		break;
3862886433a9SJohn Crispin 	case WMI_BSS_COLOR_COLLISION_DISABLE:
3863886433a9SJohn Crispin 	case WMI_BSS_COLOR_FREE_SLOT_TIMER_EXPIRY:
3864886433a9SJohn Crispin 	case WMI_BSS_COLOR_FREE_SLOT_AVAILABLE:
3865886433a9SJohn Crispin 		break;
3866886433a9SJohn Crispin 	default:
3867c27506ccSColin Ian King 		ath11k_warn(ab, "received unknown obss color collision detection event\n");
3868886433a9SJohn Crispin 	}
3869886433a9SJohn Crispin 
3870886433a9SJohn Crispin exit:
3871886433a9SJohn Crispin 	kfree(tb);
387201e782c8SWen Gong 	rcu_read_unlock();
3873886433a9SJohn Crispin }
3874886433a9SJohn Crispin 
3875886433a9SJohn Crispin static void
3876d5c65159SKalle Valo ath11k_fill_band_to_mac_param(struct ath11k_base  *soc,
3877d5c65159SKalle Valo 			      struct wmi_host_pdev_band_to_mac *band_to_mac)
3878d5c65159SKalle Valo {
3879d5c65159SKalle Valo 	u8 i;
3880d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
3881d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
3882d5c65159SKalle Valo 
3883d5c65159SKalle Valo 	for (i = 0; i < soc->num_radios; i++) {
3884d5c65159SKalle Valo 		pdev = &soc->pdevs[i];
3885d5c65159SKalle Valo 		hal_reg_cap = &soc->hal_reg_cap[i];
3886d5c65159SKalle Valo 		band_to_mac[i].pdev_id = pdev->pdev_id;
3887d5c65159SKalle Valo 
3888d5c65159SKalle Valo 		switch (pdev->cap.supported_bands) {
3889d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_5G_CAP:
3890d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3891d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3892d5c65159SKalle Valo 			break;
3893d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_CAP:
3894d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3895d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
3896d5c65159SKalle Valo 			break;
3897d5c65159SKalle Valo 		case WMI_HOST_WLAN_5G_CAP:
3898d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
3899d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3900d5c65159SKalle Valo 			break;
3901d5c65159SKalle Valo 		default:
3902d5c65159SKalle Valo 			break;
3903d5c65159SKalle Valo 		}
3904d5c65159SKalle Valo 	}
3905d5c65159SKalle Valo }
3906d5c65159SKalle Valo 
3907d5c65159SKalle Valo static void
3908d5c65159SKalle Valo ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
3909d5c65159SKalle Valo 				struct target_resource_config *tg_cfg)
3910d5c65159SKalle Valo {
3911d5c65159SKalle Valo 	wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
3912d5c65159SKalle Valo 	wmi_cfg->num_peers = tg_cfg->num_peers;
3913d5c65159SKalle Valo 	wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
3914d5c65159SKalle Valo 	wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
3915d5c65159SKalle Valo 	wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
3916d5c65159SKalle Valo 	wmi_cfg->num_tids = tg_cfg->num_tids;
3917d5c65159SKalle Valo 	wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
3918d5c65159SKalle Valo 	wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
3919d5c65159SKalle Valo 	wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
3920d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
3921d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
3922d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
3923d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
3924d5c65159SKalle Valo 	wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
3925d5c65159SKalle Valo 	wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
3926d5c65159SKalle Valo 	wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
3927d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
3928d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_ap_profiles =
3929d5c65159SKalle Valo 		tg_cfg->roam_offload_max_ap_profiles;
3930d5c65159SKalle Valo 	wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
3931d5c65159SKalle Valo 	wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
3932d5c65159SKalle Valo 	wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
3933d5c65159SKalle Valo 	wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
3934d5c65159SKalle Valo 	wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
3935d5c65159SKalle Valo 	wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
3936d5c65159SKalle Valo 	wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
3937d5c65159SKalle Valo 	wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
3938d5c65159SKalle Valo 		tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
3939d5c65159SKalle Valo 	wmi_cfg->vow_config = tg_cfg->vow_config;
3940d5c65159SKalle Valo 	wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
3941d5c65159SKalle Valo 	wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
3942d5c65159SKalle Valo 	wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
3943d5c65159SKalle Valo 	wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
3944d5c65159SKalle Valo 	wmi_cfg->num_tdls_conn_table_entries =
3945d5c65159SKalle Valo 		tg_cfg->num_tdls_conn_table_entries;
3946d5c65159SKalle Valo 	wmi_cfg->beacon_tx_offload_max_vdev =
3947d5c65159SKalle Valo 		tg_cfg->beacon_tx_offload_max_vdev;
3948d5c65159SKalle Valo 	wmi_cfg->num_multicast_filter_entries =
3949d5c65159SKalle Valo 		tg_cfg->num_multicast_filter_entries;
3950d5c65159SKalle Valo 	wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
3951d5c65159SKalle Valo 	wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
3952d5c65159SKalle Valo 	wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
3953d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_sleep_sta =
3954d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_sleep_sta;
3955d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_buffer_sta =
3956d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_buffer_sta;
3957d5c65159SKalle Valo 	wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
3958d5c65159SKalle Valo 	wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
3959d5c65159SKalle Valo 	wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
3960d5c65159SKalle Valo 	wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
3961d5c65159SKalle Valo 	wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
3962d5c65159SKalle Valo 	wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
3963d5c65159SKalle Valo 	wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
39647e9fb241SSeevalamuthu Mariappan 	wmi_cfg->flag1 = tg_cfg->flag1;
3965d5c65159SKalle Valo 	wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
39666d293d44SJohn Crispin 	wmi_cfg->sched_params = tg_cfg->sched_params;
39676d293d44SJohn Crispin 	wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
39686d293d44SJohn Crispin 	wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
3969d5c65159SKalle Valo }
3970d5c65159SKalle Valo 
3971d5c65159SKalle Valo static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
3972d5c65159SKalle Valo 				struct wmi_init_cmd_param *param)
3973d5c65159SKalle Valo {
39746bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3975d5c65159SKalle Valo 	struct sk_buff *skb;
3976d5c65159SKalle Valo 	struct wmi_init_cmd *cmd;
3977d5c65159SKalle Valo 	struct wmi_resource_config *cfg;
3978d5c65159SKalle Valo 	struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
3979d5c65159SKalle Valo 	struct wmi_pdev_band_to_mac *band_to_mac;
3980d5c65159SKalle Valo 	struct wlan_host_mem_chunk *host_mem_chunks;
3981d5c65159SKalle Valo 	struct wmi_tlv *tlv;
3982d5c65159SKalle Valo 	size_t ret, len;
3983d5c65159SKalle Valo 	void *ptr;
3984d5c65159SKalle Valo 	u32 hw_mode_len = 0;
3985d5c65159SKalle Valo 	u16 idx;
3986d5c65159SKalle Valo 
3987d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
3988d5c65159SKalle Valo 		hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
3989d5c65159SKalle Valo 			      (param->num_band_to_mac * sizeof(*band_to_mac));
3990d5c65159SKalle Valo 
3991d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
39922d4bcbedSCarl Huang 	      (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0);
3993d5c65159SKalle Valo 
39946bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3995d5c65159SKalle Valo 	if (!skb)
3996d5c65159SKalle Valo 		return -ENOMEM;
3997d5c65159SKalle Valo 
3998d5c65159SKalle Valo 	cmd = (struct wmi_init_cmd *)skb->data;
3999d5c65159SKalle Valo 
4000d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
4001d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4002d5c65159SKalle Valo 
4003d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
4004d5c65159SKalle Valo 	cfg = ptr;
4005d5c65159SKalle Valo 
4006d5c65159SKalle Valo 	ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
4007d5c65159SKalle Valo 
4008d5c65159SKalle Valo 	cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
4009d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
4010d5c65159SKalle Valo 
4011d5c65159SKalle Valo 	ptr += sizeof(*cfg);
4012d5c65159SKalle Valo 	host_mem_chunks = ptr + TLV_HDR_SIZE;
4013d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk);
4014d5c65159SKalle Valo 
4015d5c65159SKalle Valo 	for (idx = 0; idx < param->num_mem_chunks; ++idx) {
4016d5c65159SKalle Valo 		host_mem_chunks[idx].tlv_header =
4017d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
4018d5c65159SKalle Valo 					   WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
4019d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN, len);
4020d5c65159SKalle Valo 
4021d5c65159SKalle Valo 		host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
4022d5c65159SKalle Valo 		host_mem_chunks[idx].size = param->mem_chunks[idx].len;
4023d5c65159SKalle Valo 		host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
4024d5c65159SKalle Valo 
4025d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
4026d5c65159SKalle Valo 			   "WMI host mem chunk req_id %d paddr 0x%llx len %d\n",
4027d5c65159SKalle Valo 			   param->mem_chunks[idx].req_id,
4028d5c65159SKalle Valo 			   (u64)param->mem_chunks[idx].paddr,
4029d5c65159SKalle Valo 			   param->mem_chunks[idx].len);
4030d5c65159SKalle Valo 	}
4031d5c65159SKalle Valo 	cmd->num_host_mem_chunks = param->num_mem_chunks;
4032d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
4033d5c65159SKalle Valo 
4034d5c65159SKalle Valo 	/* num_mem_chunks is zero */
4035d5c65159SKalle Valo 	tlv = ptr;
4036d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4037d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
4038d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE + len;
4039d5c65159SKalle Valo 
4040d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
4041d5c65159SKalle Valo 		hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr;
4042d5c65159SKalle Valo 		hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4043d5c65159SKalle Valo 						 WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4044d5c65159SKalle Valo 				      FIELD_PREP(WMI_TLV_LEN,
4045d5c65159SKalle Valo 						 sizeof(*hw_mode) - TLV_HDR_SIZE);
4046d5c65159SKalle Valo 
4047d5c65159SKalle Valo 		hw_mode->hw_mode_index = param->hw_mode_id;
4048d5c65159SKalle Valo 		hw_mode->num_band_to_mac = param->num_band_to_mac;
4049d5c65159SKalle Valo 
4050d5c65159SKalle Valo 		ptr += sizeof(*hw_mode);
4051d5c65159SKalle Valo 
4052d5c65159SKalle Valo 		len = param->num_band_to_mac * sizeof(*band_to_mac);
4053d5c65159SKalle Valo 		tlv = ptr;
4054d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4055d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len);
4056d5c65159SKalle Valo 
4057d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
4058d5c65159SKalle Valo 		len = sizeof(*band_to_mac);
4059d5c65159SKalle Valo 
4060d5c65159SKalle Valo 		for (idx = 0; idx < param->num_band_to_mac; idx++) {
4061d5c65159SKalle Valo 			band_to_mac = (void *)ptr;
4062d5c65159SKalle Valo 
4063d5c65159SKalle Valo 			band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4064d5c65159SKalle Valo 							     WMI_TAG_PDEV_BAND_TO_MAC) |
4065d5c65159SKalle Valo 						  FIELD_PREP(WMI_TLV_LEN,
4066d5c65159SKalle Valo 							     len - TLV_HDR_SIZE);
4067d5c65159SKalle Valo 			band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
4068d5c65159SKalle Valo 			band_to_mac->start_freq =
4069d5c65159SKalle Valo 				param->band_to_mac[idx].start_freq;
4070d5c65159SKalle Valo 			band_to_mac->end_freq =
4071d5c65159SKalle Valo 				param->band_to_mac[idx].end_freq;
4072d5c65159SKalle Valo 			ptr += sizeof(*band_to_mac);
4073d5c65159SKalle Valo 		}
4074d5c65159SKalle Valo 	}
4075d5c65159SKalle Valo 
4076d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
4077d5c65159SKalle Valo 	if (ret) {
4078d5c65159SKalle Valo 		ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
4079d5c65159SKalle Valo 		dev_kfree_skb(skb);
4080d5c65159SKalle Valo 	}
4081d5c65159SKalle Valo 
4082d5c65159SKalle Valo 	return ret;
4083d5c65159SKalle Valo }
4084d5c65159SKalle Valo 
408526c79927SSriram R int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar,
408626c79927SSriram R 			    int pdev_id)
408726c79927SSriram R {
408826c79927SSriram R 	struct ath11k_wmi_pdev_lro_config_cmd *cmd;
408926c79927SSriram R 	struct sk_buff *skb;
409026c79927SSriram R 	int ret;
409126c79927SSriram R 
409226c79927SSriram R 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
409326c79927SSriram R 	if (!skb)
409426c79927SSriram R 		return -ENOMEM;
409526c79927SSriram R 
409626c79927SSriram R 	cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data;
409726c79927SSriram R 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) |
409826c79927SSriram R 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
409926c79927SSriram R 
410026c79927SSriram R 	get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE);
410126c79927SSriram R 	get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE);
410226c79927SSriram R 
410326c79927SSriram R 	cmd->pdev_id = pdev_id;
410426c79927SSriram R 
410526c79927SSriram R 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID);
410626c79927SSriram R 	if (ret) {
410726c79927SSriram R 		ath11k_warn(ar->ab,
410826c79927SSriram R 			    "failed to send lro cfg req wmi cmd\n");
410926c79927SSriram R 		goto err;
411026c79927SSriram R 	}
411126c79927SSriram R 
411226c79927SSriram R 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
411326c79927SSriram R 		   "WMI lro cfg cmd pdev_id 0x%x\n", pdev_id);
411426c79927SSriram R 	return 0;
411526c79927SSriram R err:
411626c79927SSriram R 	dev_kfree_skb(skb);
411726c79927SSriram R 	return ret;
411826c79927SSriram R }
411926c79927SSriram R 
4120d5c65159SKalle Valo int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
4121d5c65159SKalle Valo {
4122d5c65159SKalle Valo 	unsigned long time_left;
4123d5c65159SKalle Valo 
41246bc9d6f7SJohn Crispin 	time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready,
4125d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
4126d5c65159SKalle Valo 	if (!time_left)
4127d5c65159SKalle Valo 		return -ETIMEDOUT;
4128d5c65159SKalle Valo 
4129d5c65159SKalle Valo 	return 0;
4130d5c65159SKalle Valo }
4131d5c65159SKalle Valo 
4132d5c65159SKalle Valo int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
4133d5c65159SKalle Valo {
4134d5c65159SKalle Valo 	unsigned long time_left;
4135d5c65159SKalle Valo 
41366bc9d6f7SJohn Crispin 	time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready,
4137d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
4138d5c65159SKalle Valo 	if (!time_left)
4139d5c65159SKalle Valo 		return -ETIMEDOUT;
4140d5c65159SKalle Valo 
4141d5c65159SKalle Valo 	return 0;
4142d5c65159SKalle Valo }
4143d5c65159SKalle Valo 
414443ed15e1SCarl Huang int ath11k_wmi_set_hw_mode(struct ath11k_base *ab,
414543ed15e1SCarl Huang 			   enum wmi_host_hw_mode_config_type mode)
414643ed15e1SCarl Huang {
414743ed15e1SCarl Huang 	struct wmi_pdev_set_hw_mode_cmd_param *cmd;
414843ed15e1SCarl Huang 	struct sk_buff *skb;
414943ed15e1SCarl Huang 	struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab;
415043ed15e1SCarl Huang 	int len;
415143ed15e1SCarl Huang 	int ret;
415243ed15e1SCarl Huang 
415343ed15e1SCarl Huang 	len = sizeof(*cmd);
415443ed15e1SCarl Huang 
415543ed15e1SCarl Huang 	skb = ath11k_wmi_alloc_skb(wmi_ab, len);
4156292bff94SColin Ian King 	if (!skb)
4157292bff94SColin Ian King 		return -ENOMEM;
4158292bff94SColin Ian King 
415943ed15e1SCarl Huang 	cmd = (struct wmi_pdev_set_hw_mode_cmd_param *)skb->data;
416043ed15e1SCarl Huang 
416143ed15e1SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_HW_MODE_CMD) |
416243ed15e1SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
416343ed15e1SCarl Huang 
416443ed15e1SCarl Huang 	cmd->pdev_id = WMI_PDEV_ID_SOC;
416543ed15e1SCarl Huang 	cmd->hw_mode_index = mode;
416643ed15e1SCarl Huang 
416743ed15e1SCarl Huang 	ret = ath11k_wmi_cmd_send(&wmi_ab->wmi[0], skb, WMI_PDEV_SET_HW_MODE_CMDID);
416843ed15e1SCarl Huang 	if (ret) {
416943ed15e1SCarl Huang 		ath11k_warn(ab, "failed to send WMI_PDEV_SET_HW_MODE_CMDID\n");
417043ed15e1SCarl Huang 		dev_kfree_skb(skb);
417143ed15e1SCarl Huang 	}
417243ed15e1SCarl Huang 
417343ed15e1SCarl Huang 	return ret;
417443ed15e1SCarl Huang }
417543ed15e1SCarl Huang 
4176d5c65159SKalle Valo int ath11k_wmi_cmd_init(struct ath11k_base *ab)
4177d5c65159SKalle Valo {
41786bc9d6f7SJohn Crispin 	struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab;
4179d5c65159SKalle Valo 	struct wmi_init_cmd_param init_param;
4180d5c65159SKalle Valo 	struct target_resource_config  config;
4181d5c65159SKalle Valo 
4182d5c65159SKalle Valo 	memset(&init_param, 0, sizeof(init_param));
4183d5c65159SKalle Valo 	memset(&config, 0, sizeof(config));
4184d5c65159SKalle Valo 
41852d4bcbedSCarl Huang 	ab->hw_params.hw_ops->wmi_init_config(ab, &config);
41862d4bcbedSCarl Huang 
4187d5c65159SKalle Valo 	memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config));
4188d5c65159SKalle Valo 
4189d5c65159SKalle Valo 	init_param.res_cfg = &wmi_sc->wlan_resource_config;
4190d5c65159SKalle Valo 	init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
4191d5c65159SKalle Valo 	init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
4192d5c65159SKalle Valo 	init_param.mem_chunks = wmi_sc->mem_chunks;
4193d5c65159SKalle Valo 
419443ed15e1SCarl Huang 	if (ab->hw_params.single_pdev_only)
419543ed15e1SCarl Huang 		init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
419643ed15e1SCarl Huang 
4197d5c65159SKalle Valo 	init_param.num_band_to_mac = ab->num_radios;
4198d5c65159SKalle Valo 	ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
4199d5c65159SKalle Valo 
4200d5c65159SKalle Valo 	return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param);
4201d5c65159SKalle Valo }
4202d5c65159SKalle Valo 
42039d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar,
42049d11b7bfSKarthikeyan Periyasamy 				  struct ath11k_wmi_vdev_spectral_conf_param *param)
42059d11b7bfSKarthikeyan Periyasamy {
42069d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_vdev_spectral_conf_cmd *cmd;
42079d11b7bfSKarthikeyan Periyasamy 	struct sk_buff *skb;
42089d11b7bfSKarthikeyan Periyasamy 	int ret;
42099d11b7bfSKarthikeyan Periyasamy 
42109d11b7bfSKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
42119d11b7bfSKarthikeyan Periyasamy 	if (!skb)
42129d11b7bfSKarthikeyan Periyasamy 		return -ENOMEM;
42139d11b7bfSKarthikeyan Periyasamy 
42149d11b7bfSKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data;
42159d11b7bfSKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
42169d11b7bfSKarthikeyan Periyasamy 				     WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) |
42179d11b7bfSKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
42189d11b7bfSKarthikeyan Periyasamy 
42199d11b7bfSKarthikeyan Periyasamy 	memcpy(&cmd->param, param, sizeof(*param));
42209d11b7bfSKarthikeyan Periyasamy 
42219d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
42229d11b7bfSKarthikeyan Periyasamy 				  WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
42239d11b7bfSKarthikeyan Periyasamy 	if (ret) {
42249d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
42259d11b7bfSKarthikeyan Periyasamy 			    "failed to send spectral scan config wmi cmd\n");
42269d11b7bfSKarthikeyan Periyasamy 		goto err;
42279d11b7bfSKarthikeyan Periyasamy 	}
42289d11b7bfSKarthikeyan Periyasamy 
42299d11b7bfSKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
42309d11b7bfSKarthikeyan Periyasamy 		   "WMI spectral scan config cmd vdev_id 0x%x\n",
42319d11b7bfSKarthikeyan Periyasamy 		   param->vdev_id);
42329d11b7bfSKarthikeyan Periyasamy 
42339d11b7bfSKarthikeyan Periyasamy 	return 0;
42349d11b7bfSKarthikeyan Periyasamy err:
42359d11b7bfSKarthikeyan Periyasamy 	dev_kfree_skb(skb);
42369d11b7bfSKarthikeyan Periyasamy 	return ret;
42379d11b7bfSKarthikeyan Periyasamy }
42389d11b7bfSKarthikeyan Periyasamy 
42399d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id,
42409d11b7bfSKarthikeyan Periyasamy 				    u32 trigger, u32 enable)
42419d11b7bfSKarthikeyan Periyasamy {
42429d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_vdev_spectral_enable_cmd *cmd;
42439d11b7bfSKarthikeyan Periyasamy 	struct sk_buff *skb;
42449d11b7bfSKarthikeyan Periyasamy 	int ret;
42459d11b7bfSKarthikeyan Periyasamy 
42469d11b7bfSKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
42479d11b7bfSKarthikeyan Periyasamy 	if (!skb)
42489d11b7bfSKarthikeyan Periyasamy 		return -ENOMEM;
42499d11b7bfSKarthikeyan Periyasamy 
42509d11b7bfSKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data;
42519d11b7bfSKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
42529d11b7bfSKarthikeyan Periyasamy 				     WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) |
42539d11b7bfSKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
42549d11b7bfSKarthikeyan Periyasamy 
42559d11b7bfSKarthikeyan Periyasamy 	cmd->vdev_id = vdev_id;
42569d11b7bfSKarthikeyan Periyasamy 	cmd->trigger_cmd = trigger;
42579d11b7bfSKarthikeyan Periyasamy 	cmd->enable_cmd = enable;
42589d11b7bfSKarthikeyan Periyasamy 
42599d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
42609d11b7bfSKarthikeyan Periyasamy 				  WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
42619d11b7bfSKarthikeyan Periyasamy 	if (ret) {
42629d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
42639d11b7bfSKarthikeyan Periyasamy 			    "failed to send spectral enable wmi cmd\n");
42649d11b7bfSKarthikeyan Periyasamy 		goto err;
42659d11b7bfSKarthikeyan Periyasamy 	}
42669d11b7bfSKarthikeyan Periyasamy 
42679d11b7bfSKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
42689d11b7bfSKarthikeyan Periyasamy 		   "WMI spectral enable cmd vdev id 0x%x\n",
42699d11b7bfSKarthikeyan Periyasamy 		   vdev_id);
42709d11b7bfSKarthikeyan Periyasamy 
42719d11b7bfSKarthikeyan Periyasamy 	return 0;
42729d11b7bfSKarthikeyan Periyasamy err:
42739d11b7bfSKarthikeyan Periyasamy 	dev_kfree_skb(skb);
42749d11b7bfSKarthikeyan Periyasamy 	return ret;
42759d11b7bfSKarthikeyan Periyasamy }
42769d11b7bfSKarthikeyan Periyasamy 
4277bd647855SKarthikeyan Periyasamy int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar,
4278bd647855SKarthikeyan Periyasamy 				 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param)
4279bd647855SKarthikeyan Periyasamy {
4280bd647855SKarthikeyan Periyasamy 	struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd;
4281bd647855SKarthikeyan Periyasamy 	struct sk_buff *skb;
4282bd647855SKarthikeyan Periyasamy 	int ret;
4283bd647855SKarthikeyan Periyasamy 
4284bd647855SKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4285bd647855SKarthikeyan Periyasamy 	if (!skb)
4286bd647855SKarthikeyan Periyasamy 		return -ENOMEM;
4287bd647855SKarthikeyan Periyasamy 
4288bd647855SKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data;
4289bd647855SKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) |
4290bd647855SKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4291bd647855SKarthikeyan Periyasamy 
4292bd647855SKarthikeyan Periyasamy 	cmd->pdev_id		= param->pdev_id;
4293bd647855SKarthikeyan Periyasamy 	cmd->module_id		= param->module_id;
4294bd647855SKarthikeyan Periyasamy 	cmd->base_paddr_lo	= param->base_paddr_lo;
4295bd647855SKarthikeyan Periyasamy 	cmd->base_paddr_hi	= param->base_paddr_hi;
4296bd647855SKarthikeyan Periyasamy 	cmd->head_idx_paddr_lo	= param->head_idx_paddr_lo;
4297bd647855SKarthikeyan Periyasamy 	cmd->head_idx_paddr_hi	= param->head_idx_paddr_hi;
4298bd647855SKarthikeyan Periyasamy 	cmd->tail_idx_paddr_lo	= param->tail_idx_paddr_lo;
4299bd647855SKarthikeyan Periyasamy 	cmd->tail_idx_paddr_hi	= param->tail_idx_paddr_hi;
4300bd647855SKarthikeyan Periyasamy 	cmd->num_elems		= param->num_elems;
4301bd647855SKarthikeyan Periyasamy 	cmd->buf_size		= param->buf_size;
4302bd647855SKarthikeyan Periyasamy 	cmd->num_resp_per_event	= param->num_resp_per_event;
4303bd647855SKarthikeyan Periyasamy 	cmd->event_timeout_ms	= param->event_timeout_ms;
4304bd647855SKarthikeyan Periyasamy 
4305bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4306bd647855SKarthikeyan Periyasamy 				  WMI_PDEV_DMA_RING_CFG_REQ_CMDID);
4307bd647855SKarthikeyan Periyasamy 	if (ret) {
4308bd647855SKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
4309bd647855SKarthikeyan Periyasamy 			    "failed to send dma ring cfg req wmi cmd\n");
4310bd647855SKarthikeyan Periyasamy 		goto err;
4311bd647855SKarthikeyan Periyasamy 	}
4312bd647855SKarthikeyan Periyasamy 
4313bd647855SKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4314bd647855SKarthikeyan Periyasamy 		   "WMI DMA ring cfg req cmd pdev_id 0x%x\n",
4315bd647855SKarthikeyan Periyasamy 		   param->pdev_id);
4316bd647855SKarthikeyan Periyasamy 
4317bd647855SKarthikeyan Periyasamy 	return 0;
4318bd647855SKarthikeyan Periyasamy err:
4319bd647855SKarthikeyan Periyasamy 	dev_kfree_skb(skb);
4320bd647855SKarthikeyan Periyasamy 	return ret;
4321bd647855SKarthikeyan Periyasamy }
4322bd647855SKarthikeyan Periyasamy 
43239d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc,
43249d11b7bfSKarthikeyan Periyasamy 					      u16 tag, u16 len,
43259d11b7bfSKarthikeyan Periyasamy 					      const void *ptr, void *data)
43269d11b7bfSKarthikeyan Periyasamy {
43279d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
43289d11b7bfSKarthikeyan Periyasamy 
43299d11b7bfSKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY)
43309d11b7bfSKarthikeyan Periyasamy 		return -EPROTO;
43319d11b7bfSKarthikeyan Periyasamy 
43329d11b7bfSKarthikeyan Periyasamy 	if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry)
43339d11b7bfSKarthikeyan Periyasamy 		return -ENOBUFS;
43349d11b7bfSKarthikeyan Periyasamy 
43359d11b7bfSKarthikeyan Periyasamy 	parse->num_buf_entry++;
43369d11b7bfSKarthikeyan Periyasamy 	return 0;
43379d11b7bfSKarthikeyan Periyasamy }
43389d11b7bfSKarthikeyan Periyasamy 
43399d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc,
43409d11b7bfSKarthikeyan Periyasamy 					     u16 tag, u16 len,
43419d11b7bfSKarthikeyan Periyasamy 					     const void *ptr, void *data)
43429d11b7bfSKarthikeyan Periyasamy {
43439d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
43449d11b7bfSKarthikeyan Periyasamy 
43459d11b7bfSKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA)
43469d11b7bfSKarthikeyan Periyasamy 		return -EPROTO;
43479d11b7bfSKarthikeyan Periyasamy 
43489d11b7bfSKarthikeyan Periyasamy 	if (parse->num_meta >= parse->fixed.num_meta_data_entry)
43499d11b7bfSKarthikeyan Periyasamy 		return -ENOBUFS;
43509d11b7bfSKarthikeyan Periyasamy 
43519d11b7bfSKarthikeyan Periyasamy 	parse->num_meta++;
43529d11b7bfSKarthikeyan Periyasamy 	return 0;
43539d11b7bfSKarthikeyan Periyasamy }
43549d11b7bfSKarthikeyan Periyasamy 
43559d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab,
43569d11b7bfSKarthikeyan Periyasamy 					u16 tag, u16 len,
43579d11b7bfSKarthikeyan Periyasamy 					const void *ptr, void *data)
43589d11b7bfSKarthikeyan Periyasamy {
43599d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
43609d11b7bfSKarthikeyan Periyasamy 	int ret;
43619d11b7bfSKarthikeyan Periyasamy 
43629d11b7bfSKarthikeyan Periyasamy 	switch (tag) {
43639d11b7bfSKarthikeyan Periyasamy 	case WMI_TAG_DMA_BUF_RELEASE:
43649d11b7bfSKarthikeyan Periyasamy 		memcpy(&parse->fixed, ptr,
43659d11b7bfSKarthikeyan Periyasamy 		       sizeof(struct ath11k_wmi_dma_buf_release_fixed_param));
43669d11b7bfSKarthikeyan Periyasamy 		parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id);
43679d11b7bfSKarthikeyan Periyasamy 		break;
43689d11b7bfSKarthikeyan Periyasamy 	case WMI_TAG_ARRAY_STRUCT:
43699d11b7bfSKarthikeyan Periyasamy 		if (!parse->buf_entry_done) {
43709d11b7bfSKarthikeyan Periyasamy 			parse->num_buf_entry = 0;
43719d11b7bfSKarthikeyan Periyasamy 			parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr;
43729d11b7bfSKarthikeyan Periyasamy 
43739d11b7bfSKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
43749d11b7bfSKarthikeyan Periyasamy 						  ath11k_wmi_tlv_dma_buf_entry_parse,
43759d11b7bfSKarthikeyan Periyasamy 						  parse);
43769d11b7bfSKarthikeyan Periyasamy 			if (ret) {
43779d11b7bfSKarthikeyan Periyasamy 				ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n",
43789d11b7bfSKarthikeyan Periyasamy 					    ret);
43799d11b7bfSKarthikeyan Periyasamy 				return ret;
43809d11b7bfSKarthikeyan Periyasamy 			}
43819d11b7bfSKarthikeyan Periyasamy 
43829d11b7bfSKarthikeyan Periyasamy 			parse->buf_entry_done = true;
43839d11b7bfSKarthikeyan Periyasamy 		} else if (!parse->meta_data_done) {
43849d11b7bfSKarthikeyan Periyasamy 			parse->num_meta = 0;
43859d11b7bfSKarthikeyan Periyasamy 			parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr;
43869d11b7bfSKarthikeyan Periyasamy 
43879d11b7bfSKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
43889d11b7bfSKarthikeyan Periyasamy 						  ath11k_wmi_tlv_dma_buf_meta_parse,
43899d11b7bfSKarthikeyan Periyasamy 						  parse);
43909d11b7bfSKarthikeyan Periyasamy 			if (ret) {
43919d11b7bfSKarthikeyan Periyasamy 				ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n",
43929d11b7bfSKarthikeyan Periyasamy 					    ret);
43939d11b7bfSKarthikeyan Periyasamy 				return ret;
43949d11b7bfSKarthikeyan Periyasamy 			}
43959d11b7bfSKarthikeyan Periyasamy 
43969d11b7bfSKarthikeyan Periyasamy 			parse->meta_data_done = true;
43979d11b7bfSKarthikeyan Periyasamy 		}
43989d11b7bfSKarthikeyan Periyasamy 		break;
43999d11b7bfSKarthikeyan Periyasamy 	default:
44009d11b7bfSKarthikeyan Periyasamy 		break;
44019d11b7bfSKarthikeyan Periyasamy 	}
44029d11b7bfSKarthikeyan Periyasamy 	return 0;
44039d11b7bfSKarthikeyan Periyasamy }
44049d11b7bfSKarthikeyan Periyasamy 
44059d11b7bfSKarthikeyan Periyasamy static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab,
44069d11b7bfSKarthikeyan Periyasamy 						       struct sk_buff *skb)
44079d11b7bfSKarthikeyan Periyasamy {
44089d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse parse = { };
44099d11b7bfSKarthikeyan Periyasamy 	struct ath11k_dbring_buf_release_event param;
44109d11b7bfSKarthikeyan Periyasamy 	int ret;
44119d11b7bfSKarthikeyan Periyasamy 
44129d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
44139d11b7bfSKarthikeyan Periyasamy 				  ath11k_wmi_tlv_dma_buf_parse,
44149d11b7bfSKarthikeyan Periyasamy 				  &parse);
44159d11b7bfSKarthikeyan Periyasamy 	if (ret) {
44169d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret);
44179d11b7bfSKarthikeyan Periyasamy 		return;
44189d11b7bfSKarthikeyan Periyasamy 	}
44199d11b7bfSKarthikeyan Periyasamy 
44209d11b7bfSKarthikeyan Periyasamy 	param.fixed		= parse.fixed;
44219d11b7bfSKarthikeyan Periyasamy 	param.buf_entry		= parse.buf_entry;
44229d11b7bfSKarthikeyan Periyasamy 	param.num_buf_entry	= parse.num_buf_entry;
44239d11b7bfSKarthikeyan Periyasamy 	param.meta_data		= parse.meta_data;
44249d11b7bfSKarthikeyan Periyasamy 	param.num_meta		= parse.num_meta;
44259d11b7bfSKarthikeyan Periyasamy 
44269d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_dbring_buffer_release_event(ab, &param);
44279d11b7bfSKarthikeyan Periyasamy 	if (ret) {
44289d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
44299d11b7bfSKarthikeyan Periyasamy 		return;
44309d11b7bfSKarthikeyan Periyasamy 	}
44319d11b7bfSKarthikeyan Periyasamy }
44329d11b7bfSKarthikeyan Periyasamy 
4433d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
4434d5c65159SKalle Valo 					     u16 tag, u16 len,
4435d5c65159SKalle Valo 					     const void *ptr, void *data)
4436d5c65159SKalle Valo {
4437d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4438d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_cap;
4439d5c65159SKalle Valo 	u32 phy_map = 0;
4440d5c65159SKalle Valo 
4441d5c65159SKalle Valo 	if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
4442d5c65159SKalle Valo 		return -EPROTO;
4443d5c65159SKalle Valo 
4444d5c65159SKalle Valo 	if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
4445d5c65159SKalle Valo 		return -ENOBUFS;
4446d5c65159SKalle Valo 
4447d5c65159SKalle Valo 	hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
4448d5c65159SKalle Valo 				   hw_mode_id);
4449d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps++;
4450d5c65159SKalle Valo 
4451d5c65159SKalle Valo 	phy_map = hw_mode_cap->phy_id_map;
4452d5c65159SKalle Valo 	while (phy_map) {
4453d5c65159SKalle Valo 		svc_rdy_ext->tot_phy_id++;
4454d5c65159SKalle Valo 		phy_map = phy_map >> 1;
4455d5c65159SKalle Valo 	}
4456d5c65159SKalle Valo 
4457d5c65159SKalle Valo 	return 0;
4458d5c65159SKalle Valo }
4459d5c65159SKalle Valo 
4460d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
4461d5c65159SKalle Valo 				       u16 len, const void *ptr, void *data)
4462d5c65159SKalle Valo {
4463d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4464d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
4465d5c65159SKalle Valo 	enum wmi_host_hw_mode_config_type mode, pref;
4466d5c65159SKalle Valo 	u32 i;
4467d5c65159SKalle Valo 	int ret;
4468d5c65159SKalle Valo 
4469d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps = 0;
4470d5c65159SKalle Valo 	svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
4471d5c65159SKalle Valo 
4472d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4473d5c65159SKalle Valo 				  ath11k_wmi_tlv_hw_mode_caps_parse,
4474d5c65159SKalle Valo 				  svc_rdy_ext);
4475d5c65159SKalle Valo 	if (ret) {
4476d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4477d5c65159SKalle Valo 		return ret;
4478d5c65159SKalle Valo 	}
4479d5c65159SKalle Valo 
4480d5c65159SKalle Valo 	i = 0;
4481d5c65159SKalle Valo 	while (i < svc_rdy_ext->n_hw_mode_caps) {
4482d5c65159SKalle Valo 		hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
4483d5c65159SKalle Valo 		mode = hw_mode_caps->hw_mode_id;
44846bc9d6f7SJohn Crispin 		pref = soc->wmi_ab.preferred_hw_mode;
4485d5c65159SKalle Valo 
4486d5c65159SKalle Valo 		if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
4487d5c65159SKalle Valo 			svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
44886bc9d6f7SJohn Crispin 			soc->wmi_ab.preferred_hw_mode = mode;
4489d5c65159SKalle Valo 		}
4490d5c65159SKalle Valo 		i++;
4491d5c65159SKalle Valo 	}
4492d5c65159SKalle Valo 
44935f859bc0SCarl Huang 	ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n",
44945f859bc0SCarl Huang 		   soc->wmi_ab.preferred_hw_mode);
44956bc9d6f7SJohn Crispin 	if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
4496d5c65159SKalle Valo 		return -EINVAL;
4497d5c65159SKalle Valo 
4498d5c65159SKalle Valo 	return 0;
4499d5c65159SKalle Valo }
4500d5c65159SKalle Valo 
4501d5c65159SKalle Valo static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
4502d5c65159SKalle Valo 					     u16 tag, u16 len,
4503d5c65159SKalle Valo 					     const void *ptr, void *data)
4504d5c65159SKalle Valo {
4505d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4506d5c65159SKalle Valo 
4507d5c65159SKalle Valo 	if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
4508d5c65159SKalle Valo 		return -EPROTO;
4509d5c65159SKalle Valo 
4510d5c65159SKalle Valo 	if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
4511d5c65159SKalle Valo 		return -ENOBUFS;
4512d5c65159SKalle Valo 
45135b90fc76SAnilkumar Kolli 	len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
45145b90fc76SAnilkumar Kolli 	if (!svc_rdy_ext->n_mac_phy_caps) {
4515ec436338SGustavo A. R. Silva 		svc_rdy_ext->mac_phy_caps = kcalloc(svc_rdy_ext->tot_phy_id,
4516ec436338SGustavo A. R. Silva 						    len, GFP_ATOMIC);
45175b90fc76SAnilkumar Kolli 		if (!svc_rdy_ext->mac_phy_caps)
45185b90fc76SAnilkumar Kolli 			return -ENOMEM;
45195b90fc76SAnilkumar Kolli 	}
45205b90fc76SAnilkumar Kolli 
45215b90fc76SAnilkumar Kolli 	memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
4522d5c65159SKalle Valo 	svc_rdy_ext->n_mac_phy_caps++;
4523d5c65159SKalle Valo 	return 0;
4524d5c65159SKalle Valo }
4525d5c65159SKalle Valo 
4526d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
4527d5c65159SKalle Valo 						 u16 tag, u16 len,
4528d5c65159SKalle Valo 						 const void *ptr, void *data)
4529d5c65159SKalle Valo {
4530d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4531d5c65159SKalle Valo 
4532d5c65159SKalle Valo 	if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
4533d5c65159SKalle Valo 		return -EPROTO;
4534d5c65159SKalle Valo 
4535d5c65159SKalle Valo 	if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
4536d5c65159SKalle Valo 		return -ENOBUFS;
4537d5c65159SKalle Valo 
4538d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps++;
4539d5c65159SKalle Valo 	return 0;
4540d5c65159SKalle Valo }
4541d5c65159SKalle Valo 
4542d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
4543d5c65159SKalle Valo 					   u16 len, const void *ptr, void *data)
4544d5c65159SKalle Valo {
45456bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4546d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4547d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext reg_cap;
4548d5c65159SKalle Valo 	int ret;
4549d5c65159SKalle Valo 	u32 i;
4550d5c65159SKalle Valo 
4551d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps = 0;
4552d5c65159SKalle Valo 	svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
4553d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4554d5c65159SKalle Valo 				  ath11k_wmi_tlv_ext_hal_reg_caps_parse,
4555d5c65159SKalle Valo 				  svc_rdy_ext);
4556d5c65159SKalle Valo 	if (ret) {
4557d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4558d5c65159SKalle Valo 		return ret;
4559d5c65159SKalle Valo 	}
4560d5c65159SKalle Valo 
4561d5c65159SKalle Valo 	for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
4562d5c65159SKalle Valo 		ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
4563d5c65159SKalle Valo 						      svc_rdy_ext->soc_hal_reg_caps,
4564d5c65159SKalle Valo 						      svc_rdy_ext->ext_hal_reg_caps, i,
4565d5c65159SKalle Valo 						      &reg_cap);
4566d5c65159SKalle Valo 		if (ret) {
4567d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract reg cap %d\n", i);
4568d5c65159SKalle Valo 			return ret;
4569d5c65159SKalle Valo 		}
4570d5c65159SKalle Valo 
4571d5c65159SKalle Valo 		memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
4572d5c65159SKalle Valo 		       &reg_cap, sizeof(reg_cap));
4573d5c65159SKalle Valo 	}
4574d5c65159SKalle Valo 	return 0;
4575d5c65159SKalle Valo }
4576d5c65159SKalle Valo 
4577d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
4578d5c65159SKalle Valo 						     u16 len, const void *ptr,
4579d5c65159SKalle Valo 						     void *data)
4580d5c65159SKalle Valo {
45816bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4582d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4583d5c65159SKalle Valo 	u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
4584d5c65159SKalle Valo 	u32 phy_id_map;
45855f859bc0SCarl Huang 	int pdev_index = 0;
4586d5c65159SKalle Valo 	int ret;
4587d5c65159SKalle Valo 
4588d5c65159SKalle Valo 	svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
4589d5c65159SKalle Valo 	svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
4590d5c65159SKalle Valo 
4591d5c65159SKalle Valo 	soc->num_radios = 0;
459213706340SWen Gong 	soc->target_pdev_count = 0;
4593d5c65159SKalle Valo 	phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
4594d5c65159SKalle Valo 
4595d5c65159SKalle Valo 	while (phy_id_map && soc->num_radios < MAX_RADIOS) {
4596d5c65159SKalle Valo 		ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
4597d5c65159SKalle Valo 							    svc_rdy_ext->hw_caps,
4598d5c65159SKalle Valo 							    svc_rdy_ext->hw_mode_caps,
4599d5c65159SKalle Valo 							    svc_rdy_ext->soc_hal_reg_caps,
4600d5c65159SKalle Valo 							    svc_rdy_ext->mac_phy_caps,
4601d5c65159SKalle Valo 							    hw_mode_id, soc->num_radios,
46025f859bc0SCarl Huang 							    &soc->pdevs[pdev_index]);
4603d5c65159SKalle Valo 		if (ret) {
4604d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
4605d5c65159SKalle Valo 				    soc->num_radios);
4606d5c65159SKalle Valo 			return ret;
4607d5c65159SKalle Valo 		}
4608d5c65159SKalle Valo 
4609d5c65159SKalle Valo 		soc->num_radios++;
4610d5c65159SKalle Valo 
46115f859bc0SCarl Huang 		/* For QCA6390, save mac_phy capability in the same pdev */
46125f859bc0SCarl Huang 		if (soc->hw_params.single_pdev_only)
46135f859bc0SCarl Huang 			pdev_index = 0;
46145f859bc0SCarl Huang 		else
46155f859bc0SCarl Huang 			pdev_index = soc->num_radios;
46165f859bc0SCarl Huang 
4617d5c65159SKalle Valo 		/* TODO: mac_phy_cap prints */
4618d5c65159SKalle Valo 		phy_id_map >>= 1;
4619d5c65159SKalle Valo 	}
46205f859bc0SCarl Huang 
46215f859bc0SCarl Huang 	/* For QCA6390, set num_radios to 1 because host manages
46225f859bc0SCarl Huang 	 * both 2G and 5G radio in one pdev.
46235f859bc0SCarl Huang 	 * Set pdev_id = 0 and 0 means soc level.
46245f859bc0SCarl Huang 	 */
46255f859bc0SCarl Huang 	if (soc->hw_params.single_pdev_only) {
46265f859bc0SCarl Huang 		soc->num_radios = 1;
46275f859bc0SCarl Huang 		soc->pdevs[0].pdev_id = 0;
46285f859bc0SCarl Huang 	}
46295f859bc0SCarl Huang 
4630d5c65159SKalle Valo 	return 0;
4631d5c65159SKalle Valo }
4632d5c65159SKalle Valo 
4633bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc,
4634bd647855SKarthikeyan Periyasamy 					      u16 tag, u16 len,
4635bd647855SKarthikeyan Periyasamy 					      const void *ptr, void *data)
4636bd647855SKarthikeyan Periyasamy {
4637bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse *parse = data;
4638bd647855SKarthikeyan Periyasamy 
4639bd647855SKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_RING_CAPABILITIES)
4640bd647855SKarthikeyan Periyasamy 		return -EPROTO;
4641bd647855SKarthikeyan Periyasamy 
4642bd647855SKarthikeyan Periyasamy 	parse->n_dma_ring_caps++;
4643bd647855SKarthikeyan Periyasamy 	return 0;
4644bd647855SKarthikeyan Periyasamy }
4645bd647855SKarthikeyan Periyasamy 
4646bd647855SKarthikeyan Periyasamy static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab,
4647bd647855SKarthikeyan Periyasamy 					u32 num_cap)
4648bd647855SKarthikeyan Periyasamy {
4649bd647855SKarthikeyan Periyasamy 	size_t sz;
4650bd647855SKarthikeyan Periyasamy 	void *ptr;
4651bd647855SKarthikeyan Periyasamy 
4652bd647855SKarthikeyan Periyasamy 	sz = num_cap * sizeof(struct ath11k_dbring_cap);
4653bd647855SKarthikeyan Periyasamy 	ptr = kzalloc(sz, GFP_ATOMIC);
4654bd647855SKarthikeyan Periyasamy 	if (!ptr)
4655bd647855SKarthikeyan Periyasamy 		return -ENOMEM;
4656bd647855SKarthikeyan Periyasamy 
4657bd647855SKarthikeyan Periyasamy 	ab->db_caps = ptr;
4658bd647855SKarthikeyan Periyasamy 	ab->num_db_cap = num_cap;
4659bd647855SKarthikeyan Periyasamy 
4660bd647855SKarthikeyan Periyasamy 	return 0;
4661bd647855SKarthikeyan Periyasamy }
4662bd647855SKarthikeyan Periyasamy 
4663bd647855SKarthikeyan Periyasamy static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
4664bd647855SKarthikeyan Periyasamy {
4665bd647855SKarthikeyan Periyasamy 	kfree(ab->db_caps);
4666bd647855SKarthikeyan Periyasamy 	ab->db_caps = NULL;
4667bd647855SKarthikeyan Periyasamy }
4668bd647855SKarthikeyan Periyasamy 
4669bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab,
4670bd647855SKarthikeyan Periyasamy 					u16 len, const void *ptr, void *data)
4671bd647855SKarthikeyan Periyasamy {
4672bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data;
4673bd647855SKarthikeyan Periyasamy 	struct wmi_dma_ring_capabilities *dma_caps;
4674bd647855SKarthikeyan Periyasamy 	struct ath11k_dbring_cap *dir_buff_caps;
4675bd647855SKarthikeyan Periyasamy 	int ret;
4676bd647855SKarthikeyan Periyasamy 	u32 i;
4677bd647855SKarthikeyan Periyasamy 
4678bd647855SKarthikeyan Periyasamy 	dma_caps_parse->n_dma_ring_caps = 0;
4679bd647855SKarthikeyan Periyasamy 	dma_caps = (struct wmi_dma_ring_capabilities *)ptr;
4680bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4681bd647855SKarthikeyan Periyasamy 				  ath11k_wmi_tlv_dma_ring_caps_parse,
4682bd647855SKarthikeyan Periyasamy 				  dma_caps_parse);
4683bd647855SKarthikeyan Periyasamy 	if (ret) {
4684bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret);
4685bd647855SKarthikeyan Periyasamy 		return ret;
4686bd647855SKarthikeyan Periyasamy 	}
4687bd647855SKarthikeyan Periyasamy 
4688bd647855SKarthikeyan Periyasamy 	if (!dma_caps_parse->n_dma_ring_caps)
4689bd647855SKarthikeyan Periyasamy 		return 0;
4690bd647855SKarthikeyan Periyasamy 
4691bd647855SKarthikeyan Periyasamy 	if (ab->num_db_cap) {
4692bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n");
4693bd647855SKarthikeyan Periyasamy 		return 0;
4694bd647855SKarthikeyan Periyasamy 	}
4695bd647855SKarthikeyan Periyasamy 
4696bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps);
4697bd647855SKarthikeyan Periyasamy 	if (ret)
4698bd647855SKarthikeyan Periyasamy 		return ret;
4699bd647855SKarthikeyan Periyasamy 
4700bd647855SKarthikeyan Periyasamy 	dir_buff_caps = ab->db_caps;
4701bd647855SKarthikeyan Periyasamy 	for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) {
4702bd647855SKarthikeyan Periyasamy 		if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) {
4703bd647855SKarthikeyan Periyasamy 			ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id);
4704bd647855SKarthikeyan Periyasamy 			ret = -EINVAL;
4705bd647855SKarthikeyan Periyasamy 			goto free_dir_buff;
4706bd647855SKarthikeyan Periyasamy 		}
4707bd647855SKarthikeyan Periyasamy 
4708bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].id = dma_caps[i].module_id;
4709bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id);
4710bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_elem = dma_caps[i].min_elem;
4711bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz;
4712bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align;
4713bd647855SKarthikeyan Periyasamy 	}
4714bd647855SKarthikeyan Periyasamy 
4715bd647855SKarthikeyan Periyasamy 	return 0;
4716bd647855SKarthikeyan Periyasamy 
4717bd647855SKarthikeyan Periyasamy free_dir_buff:
4718bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4719bd647855SKarthikeyan Periyasamy 	return ret;
4720bd647855SKarthikeyan Periyasamy }
4721bd647855SKarthikeyan Periyasamy 
4722d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
4723d5c65159SKalle Valo 					    u16 tag, u16 len,
4724d5c65159SKalle Valo 					    const void *ptr, void *data)
4725d5c65159SKalle Valo {
47266bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
4727d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4728d5c65159SKalle Valo 	int ret;
4729d5c65159SKalle Valo 
4730d5c65159SKalle Valo 	switch (tag) {
4731d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EXT_EVENT:
4732d5c65159SKalle Valo 		ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
4733d5c65159SKalle Valo 						&svc_rdy_ext->param);
4734d5c65159SKalle Valo 		if (ret) {
4735d5c65159SKalle Valo 			ath11k_warn(ab, "unable to extract ext params\n");
4736d5c65159SKalle Valo 			return ret;
4737d5c65159SKalle Valo 		}
4738d5c65159SKalle Valo 		break;
4739d5c65159SKalle Valo 
4740d5c65159SKalle Valo 	case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
4741d5c65159SKalle Valo 		svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
4742d5c65159SKalle Valo 		svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
4743d5c65159SKalle Valo 		break;
4744d5c65159SKalle Valo 
4745d5c65159SKalle Valo 	case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
4746d5c65159SKalle Valo 		ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
4747d5c65159SKalle Valo 								svc_rdy_ext);
4748d5c65159SKalle Valo 		if (ret)
4749d5c65159SKalle Valo 			return ret;
4750d5c65159SKalle Valo 		break;
4751d5c65159SKalle Valo 
4752d5c65159SKalle Valo 	case WMI_TAG_ARRAY_STRUCT:
4753d5c65159SKalle Valo 		if (!svc_rdy_ext->hw_mode_done) {
4754d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
4755d5c65159SKalle Valo 							  svc_rdy_ext);
4756d5c65159SKalle Valo 			if (ret)
4757d5c65159SKalle Valo 				return ret;
4758d5c65159SKalle Valo 
4759d5c65159SKalle Valo 			svc_rdy_ext->hw_mode_done = true;
4760d5c65159SKalle Valo 		} else if (!svc_rdy_ext->mac_phy_done) {
4761d5c65159SKalle Valo 			svc_rdy_ext->n_mac_phy_caps = 0;
4762d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4763d5c65159SKalle Valo 						  ath11k_wmi_tlv_mac_phy_caps_parse,
4764d5c65159SKalle Valo 						  svc_rdy_ext);
4765d5c65159SKalle Valo 			if (ret) {
4766d5c65159SKalle Valo 				ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4767d5c65159SKalle Valo 				return ret;
4768d5c65159SKalle Valo 			}
4769d5c65159SKalle Valo 
4770d5c65159SKalle Valo 			svc_rdy_ext->mac_phy_done = true;
4771d5c65159SKalle Valo 		} else if (!svc_rdy_ext->ext_hal_reg_done) {
4772d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
4773d5c65159SKalle Valo 							      svc_rdy_ext);
4774d5c65159SKalle Valo 			if (ret)
4775d5c65159SKalle Valo 				return ret;
4776d5c65159SKalle Valo 
4777d5c65159SKalle Valo 			svc_rdy_ext->ext_hal_reg_done = true;
4778bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) {
4779bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->mac_phy_chainmask_combo_done = true;
4780bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) {
4781bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->mac_phy_chainmask_cap_done = true;
4782bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->oem_dma_ring_cap_done) {
4783bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->oem_dma_ring_cap_done = true;
4784bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->dma_ring_cap_done) {
4785bd647855SKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4786bd647855SKarthikeyan Periyasamy 							   &svc_rdy_ext->dma_caps_parse);
4787bd647855SKarthikeyan Periyasamy 			if (ret)
4788bd647855SKarthikeyan Periyasamy 				return ret;
4789bd647855SKarthikeyan Periyasamy 
4790bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->dma_ring_cap_done = true;
4791d5c65159SKalle Valo 		}
4792d5c65159SKalle Valo 		break;
4793d5c65159SKalle Valo 
4794d5c65159SKalle Valo 	default:
4795d5c65159SKalle Valo 		break;
4796d5c65159SKalle Valo 	}
4797d5c65159SKalle Valo 	return 0;
4798d5c65159SKalle Valo }
4799d5c65159SKalle Valo 
4800d5c65159SKalle Valo static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
4801d5c65159SKalle Valo 					  struct sk_buff *skb)
4802d5c65159SKalle Valo {
4803d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
4804d5c65159SKalle Valo 	int ret;
4805d5c65159SKalle Valo 
4806d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4807d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_ext_parse,
4808d5c65159SKalle Valo 				  &svc_rdy_ext);
4809d5c65159SKalle Valo 	if (ret) {
4810d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4811bd647855SKarthikeyan Periyasamy 		goto err;
4812d5c65159SKalle Valo 	}
4813d5c65159SKalle Valo 
4814bd647855SKarthikeyan Periyasamy 	if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map))
4815bd647855SKarthikeyan Periyasamy 		complete(&ab->wmi_ab.service_ready);
4816bd647855SKarthikeyan Periyasamy 
48175b90fc76SAnilkumar Kolli 	kfree(svc_rdy_ext.mac_phy_caps);
4818d5c65159SKalle Valo 	return 0;
4819bd647855SKarthikeyan Periyasamy 
4820bd647855SKarthikeyan Periyasamy err:
4821bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4822bd647855SKarthikeyan Periyasamy 	return ret;
4823bd647855SKarthikeyan Periyasamy }
4824bd647855SKarthikeyan Periyasamy 
4825bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab,
4826bd647855SKarthikeyan Periyasamy 					     u16 tag, u16 len,
4827bd647855SKarthikeyan Periyasamy 					     const void *ptr, void *data)
4828bd647855SKarthikeyan Periyasamy {
4829bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_svc_rdy_ext2_parse *parse = data;
4830bd647855SKarthikeyan Periyasamy 	int ret;
4831bd647855SKarthikeyan Periyasamy 
4832bd647855SKarthikeyan Periyasamy 	switch (tag) {
4833bd647855SKarthikeyan Periyasamy 	case WMI_TAG_ARRAY_STRUCT:
4834bd647855SKarthikeyan Periyasamy 		if (!parse->dma_ring_cap_done) {
4835bd647855SKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4836bd647855SKarthikeyan Periyasamy 							   &parse->dma_caps_parse);
4837bd647855SKarthikeyan Periyasamy 			if (ret)
4838bd647855SKarthikeyan Periyasamy 				return ret;
4839bd647855SKarthikeyan Periyasamy 
4840bd647855SKarthikeyan Periyasamy 			parse->dma_ring_cap_done = true;
4841bd647855SKarthikeyan Periyasamy 		}
4842bd647855SKarthikeyan Periyasamy 		break;
4843bd647855SKarthikeyan Periyasamy 	default:
4844bd647855SKarthikeyan Periyasamy 		break;
4845bd647855SKarthikeyan Periyasamy 	}
4846bd647855SKarthikeyan Periyasamy 
4847bd647855SKarthikeyan Periyasamy 	return 0;
4848bd647855SKarthikeyan Periyasamy }
4849bd647855SKarthikeyan Periyasamy 
4850bd647855SKarthikeyan Periyasamy static int ath11k_service_ready_ext2_event(struct ath11k_base *ab,
4851bd647855SKarthikeyan Periyasamy 					   struct sk_buff *skb)
4852bd647855SKarthikeyan Periyasamy {
4853bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { };
4854bd647855SKarthikeyan Periyasamy 	int ret;
4855bd647855SKarthikeyan Periyasamy 
4856bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4857bd647855SKarthikeyan Periyasamy 				  ath11k_wmi_tlv_svc_rdy_ext2_parse,
4858bd647855SKarthikeyan Periyasamy 				  &svc_rdy_ext2);
4859bd647855SKarthikeyan Periyasamy 	if (ret) {
4860bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret);
4861bd647855SKarthikeyan Periyasamy 		goto err;
4862bd647855SKarthikeyan Periyasamy 	}
4863bd647855SKarthikeyan Periyasamy 
4864bd647855SKarthikeyan Periyasamy 	complete(&ab->wmi_ab.service_ready);
4865bd647855SKarthikeyan Periyasamy 
4866bd647855SKarthikeyan Periyasamy 	return 0;
4867bd647855SKarthikeyan Periyasamy 
4868bd647855SKarthikeyan Periyasamy err:
4869bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4870bd647855SKarthikeyan Periyasamy 	return ret;
4871d5c65159SKalle Valo }
4872d5c65159SKalle Valo 
4873d5c65159SKalle Valo static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
4874d5c65159SKalle Valo 					   struct wmi_vdev_start_resp_event *vdev_rsp)
4875d5c65159SKalle Valo {
4876d5c65159SKalle Valo 	const void **tb;
4877d5c65159SKalle Valo 	const struct wmi_vdev_start_resp_event *ev;
4878d5c65159SKalle Valo 	int ret;
4879d5c65159SKalle Valo 
4880d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4881d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4882d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4883d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4884d5c65159SKalle Valo 		return ret;
4885d5c65159SKalle Valo 	}
4886d5c65159SKalle Valo 
4887d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
4888d5c65159SKalle Valo 	if (!ev) {
4889d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev start resp ev");
4890d5c65159SKalle Valo 		kfree(tb);
4891d5c65159SKalle Valo 		return -EPROTO;
4892d5c65159SKalle Valo 	}
4893d5c65159SKalle Valo 
4894d5c65159SKalle Valo 	memset(vdev_rsp, 0, sizeof(*vdev_rsp));
4895d5c65159SKalle Valo 
4896d5c65159SKalle Valo 	vdev_rsp->vdev_id = ev->vdev_id;
4897d5c65159SKalle Valo 	vdev_rsp->requestor_id = ev->requestor_id;
4898d5c65159SKalle Valo 	vdev_rsp->resp_type = ev->resp_type;
4899d5c65159SKalle Valo 	vdev_rsp->status = ev->status;
4900d5c65159SKalle Valo 	vdev_rsp->chain_mask = ev->chain_mask;
4901d5c65159SKalle Valo 	vdev_rsp->smps_mode = ev->smps_mode;
4902d5c65159SKalle Valo 	vdev_rsp->mac_id = ev->mac_id;
4903d5c65159SKalle Valo 	vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
4904d5c65159SKalle Valo 	vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
4905d5c65159SKalle Valo 
4906d5c65159SKalle Valo 	kfree(tb);
4907d5c65159SKalle Valo 	return 0;
4908d5c65159SKalle Valo }
4909d5c65159SKalle Valo 
4910d5c65159SKalle Valo static struct cur_reg_rule
4911d5c65159SKalle Valo *create_reg_rules_from_wmi(u32 num_reg_rules,
4912d5c65159SKalle Valo 			   struct wmi_regulatory_rule_struct *wmi_reg_rule)
4913d5c65159SKalle Valo {
4914d5c65159SKalle Valo 	struct cur_reg_rule *reg_rule_ptr;
4915d5c65159SKalle Valo 	u32 count;
4916d5c65159SKalle Valo 
4917ec436338SGustavo A. R. Silva 	reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr),
4918d5c65159SKalle Valo 			       GFP_ATOMIC);
4919d5c65159SKalle Valo 
4920d5c65159SKalle Valo 	if (!reg_rule_ptr)
4921d5c65159SKalle Valo 		return NULL;
4922d5c65159SKalle Valo 
4923d5c65159SKalle Valo 	for (count = 0; count < num_reg_rules; count++) {
4924d5c65159SKalle Valo 		reg_rule_ptr[count].start_freq =
4925d5c65159SKalle Valo 			FIELD_GET(REG_RULE_START_FREQ,
4926d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
4927d5c65159SKalle Valo 		reg_rule_ptr[count].end_freq =
4928d5c65159SKalle Valo 			FIELD_GET(REG_RULE_END_FREQ,
4929d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
4930d5c65159SKalle Valo 		reg_rule_ptr[count].max_bw =
4931d5c65159SKalle Valo 			FIELD_GET(REG_RULE_MAX_BW,
4932d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4933d5c65159SKalle Valo 		reg_rule_ptr[count].reg_power =
4934d5c65159SKalle Valo 			FIELD_GET(REG_RULE_REG_PWR,
4935d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4936d5c65159SKalle Valo 		reg_rule_ptr[count].ant_gain =
4937d5c65159SKalle Valo 			FIELD_GET(REG_RULE_ANT_GAIN,
4938d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4939d5c65159SKalle Valo 		reg_rule_ptr[count].flags =
4940d5c65159SKalle Valo 			FIELD_GET(REG_RULE_FLAGS,
4941d5c65159SKalle Valo 				  wmi_reg_rule[count].flag_info);
4942d5c65159SKalle Valo 	}
4943d5c65159SKalle Valo 
4944d5c65159SKalle Valo 	return reg_rule_ptr;
4945d5c65159SKalle Valo }
4946d5c65159SKalle Valo 
4947d5c65159SKalle Valo static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
4948d5c65159SKalle Valo 					       struct sk_buff *skb,
4949d5c65159SKalle Valo 					       struct cur_regulatory_info *reg_info)
4950d5c65159SKalle Valo {
4951d5c65159SKalle Valo 	const void **tb;
4952d5c65159SKalle Valo 	const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
4953d5c65159SKalle Valo 	struct wmi_regulatory_rule_struct *wmi_reg_rule;
4954d5c65159SKalle Valo 	u32 num_2g_reg_rules, num_5g_reg_rules;
4955d5c65159SKalle Valo 	int ret;
4956d5c65159SKalle Valo 
4957d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
4958d5c65159SKalle Valo 
4959d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4960d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4961d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4962d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4963d5c65159SKalle Valo 		return ret;
4964d5c65159SKalle Valo 	}
4965d5c65159SKalle Valo 
4966d5c65159SKalle Valo 	chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
4967d5c65159SKalle Valo 	if (!chan_list_event_hdr) {
4968d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
4969d5c65159SKalle Valo 		kfree(tb);
4970d5c65159SKalle Valo 		return -EPROTO;
4971d5c65159SKalle Valo 	}
4972d5c65159SKalle Valo 
4973d5c65159SKalle Valo 	reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules;
4974d5c65159SKalle Valo 	reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules;
4975d5c65159SKalle Valo 
4976d5c65159SKalle Valo 	if (!(reg_info->num_2g_reg_rules + reg_info->num_5g_reg_rules)) {
4977d5c65159SKalle Valo 		ath11k_warn(ab, "No regulatory rules available in the event info\n");
4978d5c65159SKalle Valo 		kfree(tb);
4979d5c65159SKalle Valo 		return -EINVAL;
4980d5c65159SKalle Valo 	}
4981d5c65159SKalle Valo 
4982d5c65159SKalle Valo 	memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
4983d5c65159SKalle Valo 	       REG_ALPHA2_LEN);
4984d5c65159SKalle Valo 	reg_info->dfs_region = chan_list_event_hdr->dfs_region;
4985d5c65159SKalle Valo 	reg_info->phybitmap = chan_list_event_hdr->phybitmap;
4986d5c65159SKalle Valo 	reg_info->num_phy = chan_list_event_hdr->num_phy;
4987d5c65159SKalle Valo 	reg_info->phy_id = chan_list_event_hdr->phy_id;
4988d5c65159SKalle Valo 	reg_info->ctry_code = chan_list_event_hdr->country_id;
4989d5c65159SKalle Valo 	reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
4990d5c65159SKalle Valo 	if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS)
4991d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_PASS;
4992d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND)
4993d5c65159SKalle Valo 		reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND;
4994d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND)
4995d5c65159SKalle Valo 		reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND;
4996d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED)
4997d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED;
4998d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY)
4999d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY;
5000d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL)
5001d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_FAIL;
5002d5c65159SKalle Valo 
5003d5c65159SKalle Valo 	reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g;
5004d5c65159SKalle Valo 	reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g;
5005d5c65159SKalle Valo 	reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g;
5006d5c65159SKalle Valo 	reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g;
5007d5c65159SKalle Valo 
5008d5c65159SKalle Valo 	num_2g_reg_rules = reg_info->num_2g_reg_rules;
5009d5c65159SKalle Valo 	num_5g_reg_rules = reg_info->num_5g_reg_rules;
5010d5c65159SKalle Valo 
5011d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5012d5c65159SKalle Valo 		   "%s:cc %s dsf %d BW: min_2g %d max_2g %d min_5g %d max_5g %d",
5013d5c65159SKalle Valo 		   __func__, reg_info->alpha2, reg_info->dfs_region,
5014d5c65159SKalle Valo 		   reg_info->min_bw_2g, reg_info->max_bw_2g,
5015d5c65159SKalle Valo 		   reg_info->min_bw_5g, reg_info->max_bw_5g);
5016d5c65159SKalle Valo 
5017d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5018d5c65159SKalle Valo 		   "%s: num_2g_reg_rules %d num_5g_reg_rules %d", __func__,
5019d5c65159SKalle Valo 		   num_2g_reg_rules, num_5g_reg_rules);
5020d5c65159SKalle Valo 
5021d5c65159SKalle Valo 	wmi_reg_rule =
5022d5c65159SKalle Valo 		(struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
5023d5c65159SKalle Valo 						+ sizeof(*chan_list_event_hdr)
5024d5c65159SKalle Valo 						+ sizeof(struct wmi_tlv));
5025d5c65159SKalle Valo 
5026d5c65159SKalle Valo 	if (num_2g_reg_rules) {
5027d5c65159SKalle Valo 		reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules,
5028d5c65159SKalle Valo 								       wmi_reg_rule);
5029d5c65159SKalle Valo 		if (!reg_info->reg_rules_2g_ptr) {
5030d5c65159SKalle Valo 			kfree(tb);
5031d5c65159SKalle Valo 			ath11k_warn(ab, "Unable to Allocate memory for 2g rules\n");
5032d5c65159SKalle Valo 			return -ENOMEM;
5033d5c65159SKalle Valo 		}
5034d5c65159SKalle Valo 	}
5035d5c65159SKalle Valo 
5036d5c65159SKalle Valo 	if (num_5g_reg_rules) {
5037d5c65159SKalle Valo 		wmi_reg_rule += num_2g_reg_rules;
5038d5c65159SKalle Valo 		reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules,
5039d5c65159SKalle Valo 								       wmi_reg_rule);
5040d5c65159SKalle Valo 		if (!reg_info->reg_rules_5g_ptr) {
5041d5c65159SKalle Valo 			kfree(tb);
5042d5c65159SKalle Valo 			ath11k_warn(ab, "Unable to Allocate memory for 5g rules\n");
5043d5c65159SKalle Valo 			return -ENOMEM;
5044d5c65159SKalle Valo 		}
5045d5c65159SKalle Valo 	}
5046d5c65159SKalle Valo 
5047d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
5048d5c65159SKalle Valo 
5049d5c65159SKalle Valo 	kfree(tb);
5050d5c65159SKalle Valo 	return 0;
5051d5c65159SKalle Valo }
5052d5c65159SKalle Valo 
5053d5c65159SKalle Valo static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
5054d5c65159SKalle Valo 					struct wmi_peer_delete_resp_event *peer_del_resp)
5055d5c65159SKalle Valo {
5056d5c65159SKalle Valo 	const void **tb;
5057d5c65159SKalle Valo 	const struct wmi_peer_delete_resp_event *ev;
5058d5c65159SKalle Valo 	int ret;
5059d5c65159SKalle Valo 
5060d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5061d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5062d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5063d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5064d5c65159SKalle Valo 		return ret;
5065d5c65159SKalle Valo 	}
5066d5c65159SKalle Valo 
5067d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
5068d5c65159SKalle Valo 	if (!ev) {
5069d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer delete resp ev");
5070d5c65159SKalle Valo 		kfree(tb);
5071d5c65159SKalle Valo 		return -EPROTO;
5072d5c65159SKalle Valo 	}
5073d5c65159SKalle Valo 
5074d5c65159SKalle Valo 	memset(peer_del_resp, 0, sizeof(*peer_del_resp));
5075d5c65159SKalle Valo 
5076d5c65159SKalle Valo 	peer_del_resp->vdev_id = ev->vdev_id;
5077d5c65159SKalle Valo 	ether_addr_copy(peer_del_resp->peer_macaddr.addr,
5078d5c65159SKalle Valo 			ev->peer_macaddr.addr);
5079d5c65159SKalle Valo 
5080d5c65159SKalle Valo 	kfree(tb);
5081d5c65159SKalle Valo 	return 0;
5082d5c65159SKalle Valo }
5083d5c65159SKalle Valo 
50843cbbdfbeSRitesh Singh static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab,
50853cbbdfbeSRitesh Singh 					struct sk_buff *skb,
50863cbbdfbeSRitesh Singh 					u32 *vdev_id)
50873cbbdfbeSRitesh Singh {
50883cbbdfbeSRitesh Singh 	const void **tb;
50893cbbdfbeSRitesh Singh 	const struct wmi_vdev_delete_resp_event *ev;
50903cbbdfbeSRitesh Singh 	int ret;
50913cbbdfbeSRitesh Singh 
50923cbbdfbeSRitesh Singh 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
50933cbbdfbeSRitesh Singh 	if (IS_ERR(tb)) {
50943cbbdfbeSRitesh Singh 		ret = PTR_ERR(tb);
50953cbbdfbeSRitesh Singh 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
50963cbbdfbeSRitesh Singh 		return ret;
50973cbbdfbeSRitesh Singh 	}
50983cbbdfbeSRitesh Singh 
50993cbbdfbeSRitesh Singh 	ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT];
51003cbbdfbeSRitesh Singh 	if (!ev) {
51013cbbdfbeSRitesh Singh 		ath11k_warn(ab, "failed to fetch vdev delete resp ev");
51023cbbdfbeSRitesh Singh 		kfree(tb);
51033cbbdfbeSRitesh Singh 		return -EPROTO;
51043cbbdfbeSRitesh Singh 	}
51053cbbdfbeSRitesh Singh 
51063cbbdfbeSRitesh Singh 	*vdev_id = ev->vdev_id;
51073cbbdfbeSRitesh Singh 
51083cbbdfbeSRitesh Singh 	kfree(tb);
51093cbbdfbeSRitesh Singh 	return 0;
51103cbbdfbeSRitesh Singh }
51113cbbdfbeSRitesh Singh 
5112d5c65159SKalle Valo static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
5113d5c65159SKalle Valo 					u32 len, u32 *vdev_id,
5114d5c65159SKalle Valo 					u32 *tx_status)
5115d5c65159SKalle Valo {
5116d5c65159SKalle Valo 	const void **tb;
5117d5c65159SKalle Valo 	const struct wmi_bcn_tx_status_event *ev;
5118d5c65159SKalle Valo 	int ret;
5119d5c65159SKalle Valo 
5120d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5121d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5122d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5123d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5124d5c65159SKalle Valo 		return ret;
5125d5c65159SKalle Valo 	}
5126d5c65159SKalle Valo 
5127d5c65159SKalle Valo 	ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
5128d5c65159SKalle Valo 	if (!ev) {
5129d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch bcn tx status ev");
5130d5c65159SKalle Valo 		kfree(tb);
5131d5c65159SKalle Valo 		return -EPROTO;
5132d5c65159SKalle Valo 	}
5133d5c65159SKalle Valo 
5134d5c65159SKalle Valo 	*vdev_id   = ev->vdev_id;
5135d5c65159SKalle Valo 	*tx_status = ev->tx_status;
5136d5c65159SKalle Valo 
5137d5c65159SKalle Valo 	kfree(tb);
5138d5c65159SKalle Valo 	return 0;
5139d5c65159SKalle Valo }
5140d5c65159SKalle Valo 
5141d5c65159SKalle Valo static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5142d5c65159SKalle Valo 					      u32 *vdev_id)
5143d5c65159SKalle Valo {
5144d5c65159SKalle Valo 	const void **tb;
5145d5c65159SKalle Valo 	const struct wmi_vdev_stopped_event *ev;
5146d5c65159SKalle Valo 	int ret;
5147d5c65159SKalle Valo 
5148d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5149d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5150d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5151d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5152d5c65159SKalle Valo 		return ret;
5153d5c65159SKalle Valo 	}
5154d5c65159SKalle Valo 
5155d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
5156d5c65159SKalle Valo 	if (!ev) {
5157d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev stop ev");
5158d5c65159SKalle Valo 		kfree(tb);
5159d5c65159SKalle Valo 		return -EPROTO;
5160d5c65159SKalle Valo 	}
5161d5c65159SKalle Valo 
5162d5c65159SKalle Valo 	*vdev_id =  ev->vdev_id;
5163d5c65159SKalle Valo 
5164d5c65159SKalle Valo 	kfree(tb);
5165d5c65159SKalle Valo 	return 0;
5166d5c65159SKalle Valo }
5167d5c65159SKalle Valo 
5168d5c65159SKalle Valo static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
5169d5c65159SKalle Valo 					  struct sk_buff *skb,
5170d5c65159SKalle Valo 					  struct mgmt_rx_event_params *hdr)
5171d5c65159SKalle Valo {
5172d5c65159SKalle Valo 	const void **tb;
5173d5c65159SKalle Valo 	const struct wmi_mgmt_rx_hdr *ev;
5174d5c65159SKalle Valo 	const u8 *frame;
5175d5c65159SKalle Valo 	int ret;
5176d5c65159SKalle Valo 
5177d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5178d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5179d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5180d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5181d5c65159SKalle Valo 		return ret;
5182d5c65159SKalle Valo 	}
5183d5c65159SKalle Valo 
5184d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_RX_HDR];
5185d5c65159SKalle Valo 	frame = tb[WMI_TAG_ARRAY_BYTE];
5186d5c65159SKalle Valo 
5187d5c65159SKalle Valo 	if (!ev || !frame) {
5188d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt rx hdr");
5189d5c65159SKalle Valo 		kfree(tb);
5190d5c65159SKalle Valo 		return -EPROTO;
5191d5c65159SKalle Valo 	}
5192d5c65159SKalle Valo 
5193d5c65159SKalle Valo 	hdr->pdev_id =  ev->pdev_id;
51945dcf42f8SPradeep Kumar Chitrapu 	hdr->chan_freq = ev->chan_freq;
5195d5c65159SKalle Valo 	hdr->channel =  ev->channel;
5196d5c65159SKalle Valo 	hdr->snr =  ev->snr;
5197d5c65159SKalle Valo 	hdr->rate =  ev->rate;
5198d5c65159SKalle Valo 	hdr->phy_mode =  ev->phy_mode;
5199d5c65159SKalle Valo 	hdr->buf_len =  ev->buf_len;
5200d5c65159SKalle Valo 	hdr->status =  ev->status;
5201d5c65159SKalle Valo 	hdr->flags =  ev->flags;
5202d5c65159SKalle Valo 	hdr->rssi =  ev->rssi;
5203d5c65159SKalle Valo 	hdr->tsf_delta =  ev->tsf_delta;
5204d5c65159SKalle Valo 	memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
5205d5c65159SKalle Valo 
5206d5c65159SKalle Valo 	if (skb->len < (frame - skb->data) + hdr->buf_len) {
5207d5c65159SKalle Valo 		ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
5208d5c65159SKalle Valo 		kfree(tb);
5209d5c65159SKalle Valo 		return -EPROTO;
5210d5c65159SKalle Valo 	}
5211d5c65159SKalle Valo 
5212d5c65159SKalle Valo 	/* shift the sk_buff to point to `frame` */
5213d5c65159SKalle Valo 	skb_trim(skb, 0);
5214d5c65159SKalle Valo 	skb_put(skb, frame - skb->data);
5215d5c65159SKalle Valo 	skb_pull(skb, frame - skb->data);
5216d5c65159SKalle Valo 	skb_put(skb, hdr->buf_len);
5217d5c65159SKalle Valo 
5218d5c65159SKalle Valo 	ath11k_ce_byte_swap(skb->data, hdr->buf_len);
5219d5c65159SKalle Valo 
5220d5c65159SKalle Valo 	kfree(tb);
5221d5c65159SKalle Valo 	return 0;
5222d5c65159SKalle Valo }
5223d5c65159SKalle Valo 
5224d5c65159SKalle Valo static int wmi_process_mgmt_tx_comp(struct ath11k *ar, u32 desc_id,
5225d5c65159SKalle Valo 				    u32 status)
5226d5c65159SKalle Valo {
5227d5c65159SKalle Valo 	struct sk_buff *msdu;
5228d5c65159SKalle Valo 	struct ieee80211_tx_info *info;
5229d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb;
5230dddaa64dSWen Gong 	int num_mgmt;
5231d5c65159SKalle Valo 
5232d5c65159SKalle Valo 	spin_lock_bh(&ar->txmgmt_idr_lock);
5233d5c65159SKalle Valo 	msdu = idr_find(&ar->txmgmt_idr, desc_id);
5234d5c65159SKalle Valo 
5235d5c65159SKalle Valo 	if (!msdu) {
5236d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
5237d5c65159SKalle Valo 			    desc_id);
5238d5c65159SKalle Valo 		spin_unlock_bh(&ar->txmgmt_idr_lock);
5239d5c65159SKalle Valo 		return -ENOENT;
5240d5c65159SKalle Valo 	}
5241d5c65159SKalle Valo 
5242d5c65159SKalle Valo 	idr_remove(&ar->txmgmt_idr, desc_id);
5243d5c65159SKalle Valo 	spin_unlock_bh(&ar->txmgmt_idr_lock);
5244d5c65159SKalle Valo 
5245d5c65159SKalle Valo 	skb_cb = ATH11K_SKB_CB(msdu);
5246d5c65159SKalle Valo 	dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
5247d5c65159SKalle Valo 
5248d5c65159SKalle Valo 	info = IEEE80211_SKB_CB(msdu);
5249d5c65159SKalle Valo 	if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) && !status)
5250d5c65159SKalle Valo 		info->flags |= IEEE80211_TX_STAT_ACK;
5251d5c65159SKalle Valo 
5252d5c65159SKalle Valo 	ieee80211_tx_status_irqsafe(ar->hw, msdu);
5253d5c65159SKalle Valo 
5254dddaa64dSWen Gong 	num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5255dddaa64dSWen Gong 
5256800113ffSSriram R 	/* WARN when we received this event without doing any mgmt tx */
5257dddaa64dSWen Gong 	if (num_mgmt < 0)
5258800113ffSSriram R 		WARN_ON_ONCE(1);
5259d5c65159SKalle Valo 
5260dddaa64dSWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5261dddaa64dSWen Gong 		   "wmi mgmt tx comp pending %d desc id %d\n",
5262dddaa64dSWen Gong 		   num_mgmt, desc_id);
5263dddaa64dSWen Gong 
5264dddaa64dSWen Gong 	if (!num_mgmt)
5265dddaa64dSWen Gong 		wake_up(&ar->txmgmt_empty_waitq);
5266dddaa64dSWen Gong 
5267d5c65159SKalle Valo 	return 0;
5268d5c65159SKalle Valo }
5269d5c65159SKalle Valo 
5270d5c65159SKalle Valo static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
5271d5c65159SKalle Valo 					       struct sk_buff *skb,
5272d5c65159SKalle Valo 					       struct wmi_mgmt_tx_compl_event *param)
5273d5c65159SKalle Valo {
5274d5c65159SKalle Valo 	const void **tb;
5275d5c65159SKalle Valo 	const struct wmi_mgmt_tx_compl_event *ev;
5276d5c65159SKalle Valo 	int ret;
5277d5c65159SKalle Valo 
5278d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5279d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5280d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5281d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5282d5c65159SKalle Valo 		return ret;
5283d5c65159SKalle Valo 	}
5284d5c65159SKalle Valo 
5285d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
5286d5c65159SKalle Valo 	if (!ev) {
5287d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
5288d5c65159SKalle Valo 		kfree(tb);
5289d5c65159SKalle Valo 		return -EPROTO;
5290d5c65159SKalle Valo 	}
5291d5c65159SKalle Valo 
5292d5c65159SKalle Valo 	param->pdev_id = ev->pdev_id;
5293d5c65159SKalle Valo 	param->desc_id = ev->desc_id;
5294d5c65159SKalle Valo 	param->status = ev->status;
5295d5c65159SKalle Valo 
5296d5c65159SKalle Valo 	kfree(tb);
5297d5c65159SKalle Valo 	return 0;
5298d5c65159SKalle Valo }
5299d5c65159SKalle Valo 
5300d5c65159SKalle Valo static void ath11k_wmi_event_scan_started(struct ath11k *ar)
5301d5c65159SKalle Valo {
5302d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5303d5c65159SKalle Valo 
5304d5c65159SKalle Valo 	switch (ar->scan.state) {
5305d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5306d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5307d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5308d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
5309d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5310d5c65159SKalle Valo 			    ar->scan.state);
5311d5c65159SKalle Valo 		break;
5312d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5313d5c65159SKalle Valo 		ar->scan.state = ATH11K_SCAN_RUNNING;
53143a5627b9SBaochen Qiang 		if (ar->scan.is_roc)
53153a5627b9SBaochen Qiang 			ieee80211_ready_on_channel(ar->hw);
5316d5c65159SKalle Valo 		complete(&ar->scan.started);
5317d5c65159SKalle Valo 		break;
5318d5c65159SKalle Valo 	}
5319d5c65159SKalle Valo }
5320d5c65159SKalle Valo 
5321d5c65159SKalle Valo static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
5322d5c65159SKalle Valo {
5323d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5324d5c65159SKalle Valo 
5325d5c65159SKalle Valo 	switch (ar->scan.state) {
5326d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5327d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5328d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5329d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
5330d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5331d5c65159SKalle Valo 			    ar->scan.state);
5332d5c65159SKalle Valo 		break;
5333d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5334d5c65159SKalle Valo 		complete(&ar->scan.started);
5335d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
5336d5c65159SKalle Valo 		break;
5337d5c65159SKalle Valo 	}
5338d5c65159SKalle Valo }
5339d5c65159SKalle Valo 
5340d5c65159SKalle Valo static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
5341d5c65159SKalle Valo {
5342d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5343d5c65159SKalle Valo 
5344d5c65159SKalle Valo 	switch (ar->scan.state) {
5345d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5346d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5347d5c65159SKalle Valo 		/* One suspected reason scan can be completed while starting is
5348d5c65159SKalle Valo 		 * if firmware fails to deliver all scan events to the host,
5349d5c65159SKalle Valo 		 * e.g. when transport pipe is full. This has been observed
5350d5c65159SKalle Valo 		 * with spectral scan phyerr events starving wmi transport
5351d5c65159SKalle Valo 		 * pipe. In such case the "scan completed" event should be (and
5352d5c65159SKalle Valo 		 * is) ignored by the host as it may be just firmware's scan
5353d5c65159SKalle Valo 		 * state machine recovering.
5354d5c65159SKalle Valo 		 */
5355d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
5356d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5357d5c65159SKalle Valo 			    ar->scan.state);
5358d5c65159SKalle Valo 		break;
5359d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5360d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5361d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
5362d5c65159SKalle Valo 		break;
5363d5c65159SKalle Valo 	}
5364d5c65159SKalle Valo }
5365d5c65159SKalle Valo 
5366d5c65159SKalle Valo static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
5367d5c65159SKalle Valo {
5368d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5369d5c65159SKalle Valo 
5370d5c65159SKalle Valo 	switch (ar->scan.state) {
5371d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5372d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5373d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
5374d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5375d5c65159SKalle Valo 			    ar->scan.state);
5376d5c65159SKalle Valo 		break;
5377d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5378d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5379d5c65159SKalle Valo 		ar->scan_channel = NULL;
5380d5c65159SKalle Valo 		break;
5381d5c65159SKalle Valo 	}
5382d5c65159SKalle Valo }
5383d5c65159SKalle Valo 
5384d5c65159SKalle Valo static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
5385d5c65159SKalle Valo {
5386d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5387d5c65159SKalle Valo 
5388d5c65159SKalle Valo 	switch (ar->scan.state) {
5389d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5390d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5391d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
5392d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5393d5c65159SKalle Valo 			    ar->scan.state);
5394d5c65159SKalle Valo 		break;
5395d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5396d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5397d5c65159SKalle Valo 		ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
53983a5627b9SBaochen Qiang 		if (ar->scan.is_roc && ar->scan.roc_freq == freq)
53993a5627b9SBaochen Qiang 			complete(&ar->scan.on_channel);
5400d5c65159SKalle Valo 		break;
5401d5c65159SKalle Valo 	}
5402d5c65159SKalle Valo }
5403d5c65159SKalle Valo 
5404d5c65159SKalle Valo static const char *
5405d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
5406d5c65159SKalle Valo 			       enum wmi_scan_completion_reason reason)
5407d5c65159SKalle Valo {
5408d5c65159SKalle Valo 	switch (type) {
5409d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
5410d5c65159SKalle Valo 		return "started";
5411d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
5412d5c65159SKalle Valo 		switch (reason) {
5413d5c65159SKalle Valo 		case WMI_SCAN_REASON_COMPLETED:
5414d5c65159SKalle Valo 			return "completed";
5415d5c65159SKalle Valo 		case WMI_SCAN_REASON_CANCELLED:
5416d5c65159SKalle Valo 			return "completed [cancelled]";
5417d5c65159SKalle Valo 		case WMI_SCAN_REASON_PREEMPTED:
5418d5c65159SKalle Valo 			return "completed [preempted]";
5419d5c65159SKalle Valo 		case WMI_SCAN_REASON_TIMEDOUT:
5420d5c65159SKalle Valo 			return "completed [timedout]";
5421d5c65159SKalle Valo 		case WMI_SCAN_REASON_INTERNAL_FAILURE:
5422d5c65159SKalle Valo 			return "completed [internal err]";
5423d5c65159SKalle Valo 		case WMI_SCAN_REASON_MAX:
5424d5c65159SKalle Valo 			break;
5425d5c65159SKalle Valo 		}
5426d5c65159SKalle Valo 		return "completed [unknown]";
5427d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
5428d5c65159SKalle Valo 		return "bss channel";
5429d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
5430d5c65159SKalle Valo 		return "foreign channel";
5431d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
5432d5c65159SKalle Valo 		return "dequeued";
5433d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
5434d5c65159SKalle Valo 		return "preempted";
5435d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
5436d5c65159SKalle Valo 		return "start failed";
5437d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
5438d5c65159SKalle Valo 		return "restarted";
5439d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
5440d5c65159SKalle Valo 		return "foreign channel exit";
5441d5c65159SKalle Valo 	default:
5442d5c65159SKalle Valo 		return "unknown";
5443d5c65159SKalle Valo 	}
5444d5c65159SKalle Valo }
5445d5c65159SKalle Valo 
5446d5c65159SKalle Valo static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
5447d5c65159SKalle Valo 			       struct wmi_scan_event *scan_evt_param)
5448d5c65159SKalle Valo {
5449d5c65159SKalle Valo 	const void **tb;
5450d5c65159SKalle Valo 	const struct wmi_scan_event *ev;
5451d5c65159SKalle Valo 	int ret;
5452d5c65159SKalle Valo 
5453d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5454d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5455d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5456d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5457d5c65159SKalle Valo 		return ret;
5458d5c65159SKalle Valo 	}
5459d5c65159SKalle Valo 
5460d5c65159SKalle Valo 	ev = tb[WMI_TAG_SCAN_EVENT];
5461d5c65159SKalle Valo 	if (!ev) {
5462d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch scan ev");
5463d5c65159SKalle Valo 		kfree(tb);
5464d5c65159SKalle Valo 		return -EPROTO;
5465d5c65159SKalle Valo 	}
5466d5c65159SKalle Valo 
5467d5c65159SKalle Valo 	scan_evt_param->event_type = ev->event_type;
5468d5c65159SKalle Valo 	scan_evt_param->reason = ev->reason;
5469d5c65159SKalle Valo 	scan_evt_param->channel_freq = ev->channel_freq;
5470d5c65159SKalle Valo 	scan_evt_param->scan_req_id = ev->scan_req_id;
5471d5c65159SKalle Valo 	scan_evt_param->scan_id = ev->scan_id;
5472d5c65159SKalle Valo 	scan_evt_param->vdev_id = ev->vdev_id;
5473d5c65159SKalle Valo 	scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
5474d5c65159SKalle Valo 
5475d5c65159SKalle Valo 	kfree(tb);
5476d5c65159SKalle Valo 	return 0;
5477d5c65159SKalle Valo }
5478d5c65159SKalle Valo 
5479d5c65159SKalle Valo static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
5480d5c65159SKalle Valo 					   struct wmi_peer_sta_kickout_arg *arg)
5481d5c65159SKalle Valo {
5482d5c65159SKalle Valo 	const void **tb;
5483d5c65159SKalle Valo 	const struct wmi_peer_sta_kickout_event *ev;
5484d5c65159SKalle Valo 	int ret;
5485d5c65159SKalle Valo 
5486d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5487d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5488d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5489d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5490d5c65159SKalle Valo 		return ret;
5491d5c65159SKalle Valo 	}
5492d5c65159SKalle Valo 
5493d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
5494d5c65159SKalle Valo 	if (!ev) {
5495d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer sta kickout ev");
5496d5c65159SKalle Valo 		kfree(tb);
5497d5c65159SKalle Valo 		return -EPROTO;
5498d5c65159SKalle Valo 	}
5499d5c65159SKalle Valo 
5500d5c65159SKalle Valo 	arg->mac_addr = ev->peer_macaddr.addr;
5501d5c65159SKalle Valo 
5502d5c65159SKalle Valo 	kfree(tb);
5503d5c65159SKalle Valo 	return 0;
5504d5c65159SKalle Valo }
5505d5c65159SKalle Valo 
5506d5c65159SKalle Valo static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
5507d5c65159SKalle Valo 			       struct wmi_roam_event *roam_ev)
5508d5c65159SKalle Valo {
5509d5c65159SKalle Valo 	const void **tb;
5510d5c65159SKalle Valo 	const struct wmi_roam_event *ev;
5511d5c65159SKalle Valo 	int ret;
5512d5c65159SKalle Valo 
5513d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5514d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5515d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5516d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5517d5c65159SKalle Valo 		return ret;
5518d5c65159SKalle Valo 	}
5519d5c65159SKalle Valo 
5520d5c65159SKalle Valo 	ev = tb[WMI_TAG_ROAM_EVENT];
5521d5c65159SKalle Valo 	if (!ev) {
5522d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch roam ev");
5523d5c65159SKalle Valo 		kfree(tb);
5524d5c65159SKalle Valo 		return -EPROTO;
5525d5c65159SKalle Valo 	}
5526d5c65159SKalle Valo 
5527d5c65159SKalle Valo 	roam_ev->vdev_id = ev->vdev_id;
5528d5c65159SKalle Valo 	roam_ev->reason = ev->reason;
5529d5c65159SKalle Valo 	roam_ev->rssi = ev->rssi;
5530d5c65159SKalle Valo 
5531d5c65159SKalle Valo 	kfree(tb);
5532d5c65159SKalle Valo 	return 0;
5533d5c65159SKalle Valo }
5534d5c65159SKalle Valo 
5535d5c65159SKalle Valo static int freq_to_idx(struct ath11k *ar, int freq)
5536d5c65159SKalle Valo {
5537d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
5538d5c65159SKalle Valo 	int band, ch, idx = 0;
5539d5c65159SKalle Valo 
5540d5c65159SKalle Valo 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
5541d5c65159SKalle Valo 		sband = ar->hw->wiphy->bands[band];
5542d5c65159SKalle Valo 		if (!sband)
5543d5c65159SKalle Valo 			continue;
5544d5c65159SKalle Valo 
5545d5c65159SKalle Valo 		for (ch = 0; ch < sband->n_channels; ch++, idx++)
5546d5c65159SKalle Valo 			if (sband->channels[ch].center_freq == freq)
5547d5c65159SKalle Valo 				goto exit;
5548d5c65159SKalle Valo 	}
5549d5c65159SKalle Valo 
5550d5c65159SKalle Valo exit:
5551d5c65159SKalle Valo 	return idx;
5552d5c65159SKalle Valo }
5553d5c65159SKalle Valo 
5554d5c65159SKalle Valo static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
5555d5c65159SKalle Valo 				    u32 len, struct wmi_chan_info_event *ch_info_ev)
5556d5c65159SKalle Valo {
5557d5c65159SKalle Valo 	const void **tb;
5558d5c65159SKalle Valo 	const struct wmi_chan_info_event *ev;
5559d5c65159SKalle Valo 	int ret;
5560d5c65159SKalle Valo 
5561d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5562d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5563d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5564d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5565d5c65159SKalle Valo 		return ret;
5566d5c65159SKalle Valo 	}
5567d5c65159SKalle Valo 
5568d5c65159SKalle Valo 	ev = tb[WMI_TAG_CHAN_INFO_EVENT];
5569d5c65159SKalle Valo 	if (!ev) {
5570d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch chan info ev");
5571d5c65159SKalle Valo 		kfree(tb);
5572d5c65159SKalle Valo 		return -EPROTO;
5573d5c65159SKalle Valo 	}
5574d5c65159SKalle Valo 
5575d5c65159SKalle Valo 	ch_info_ev->err_code = ev->err_code;
5576d5c65159SKalle Valo 	ch_info_ev->freq = ev->freq;
5577d5c65159SKalle Valo 	ch_info_ev->cmd_flags = ev->cmd_flags;
5578d5c65159SKalle Valo 	ch_info_ev->noise_floor = ev->noise_floor;
5579d5c65159SKalle Valo 	ch_info_ev->rx_clear_count = ev->rx_clear_count;
5580d5c65159SKalle Valo 	ch_info_ev->cycle_count = ev->cycle_count;
5581d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
5582d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
5583d5c65159SKalle Valo 	ch_info_ev->rx_frame_count = ev->rx_frame_count;
5584d5c65159SKalle Valo 	ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
5585d5c65159SKalle Valo 	ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
5586d5c65159SKalle Valo 	ch_info_ev->vdev_id = ev->vdev_id;
5587d5c65159SKalle Valo 
5588d5c65159SKalle Valo 	kfree(tb);
5589d5c65159SKalle Valo 	return 0;
5590d5c65159SKalle Valo }
5591d5c65159SKalle Valo 
5592d5c65159SKalle Valo static int
5593d5c65159SKalle Valo ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
5594d5c65159SKalle Valo 				  struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
5595d5c65159SKalle Valo {
5596d5c65159SKalle Valo 	const void **tb;
5597d5c65159SKalle Valo 	const struct wmi_pdev_bss_chan_info_event *ev;
5598d5c65159SKalle Valo 	int ret;
5599d5c65159SKalle Valo 
5600d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5601d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5602d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5603d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5604d5c65159SKalle Valo 		return ret;
5605d5c65159SKalle Valo 	}
5606d5c65159SKalle Valo 
5607d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
5608d5c65159SKalle Valo 	if (!ev) {
5609d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
5610d5c65159SKalle Valo 		kfree(tb);
5611d5c65159SKalle Valo 		return -EPROTO;
5612d5c65159SKalle Valo 	}
5613d5c65159SKalle Valo 
5614d5c65159SKalle Valo 	bss_ch_info_ev->pdev_id = ev->pdev_id;
5615d5c65159SKalle Valo 	bss_ch_info_ev->freq = ev->freq;
5616d5c65159SKalle Valo 	bss_ch_info_ev->noise_floor = ev->noise_floor;
5617d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
5618d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
5619d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
5620d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
5621d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
5622d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
5623d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
5624d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
5625d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
5626d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
5627d5c65159SKalle Valo 
5628d5c65159SKalle Valo 	kfree(tb);
5629d5c65159SKalle Valo 	return 0;
5630d5c65159SKalle Valo }
5631d5c65159SKalle Valo 
5632d5c65159SKalle Valo static int
5633d5c65159SKalle Valo ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
5634d5c65159SKalle Valo 				      struct wmi_vdev_install_key_complete_arg *arg)
5635d5c65159SKalle Valo {
5636d5c65159SKalle Valo 	const void **tb;
5637d5c65159SKalle Valo 	const struct wmi_vdev_install_key_compl_event *ev;
5638d5c65159SKalle Valo 	int ret;
5639d5c65159SKalle Valo 
5640d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5641d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5642d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5643d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5644d5c65159SKalle Valo 		return ret;
5645d5c65159SKalle Valo 	}
5646d5c65159SKalle Valo 
5647d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
5648d5c65159SKalle Valo 	if (!ev) {
5649d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev install key compl ev");
5650d5c65159SKalle Valo 		kfree(tb);
5651d5c65159SKalle Valo 		return -EPROTO;
5652d5c65159SKalle Valo 	}
5653d5c65159SKalle Valo 
5654d5c65159SKalle Valo 	arg->vdev_id = ev->vdev_id;
5655d5c65159SKalle Valo 	arg->macaddr = ev->peer_macaddr.addr;
5656d5c65159SKalle Valo 	arg->key_idx = ev->key_idx;
5657d5c65159SKalle Valo 	arg->key_flags = ev->key_flags;
5658d5c65159SKalle Valo 	arg->status = ev->status;
5659d5c65159SKalle Valo 
5660d5c65159SKalle Valo 	kfree(tb);
5661d5c65159SKalle Valo 	return 0;
5662d5c65159SKalle Valo }
5663d5c65159SKalle Valo 
5664d5c65159SKalle Valo static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
5665d5c65159SKalle Valo 					  struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
5666d5c65159SKalle Valo {
5667d5c65159SKalle Valo 	const void **tb;
5668d5c65159SKalle Valo 	const struct wmi_peer_assoc_conf_event *ev;
5669d5c65159SKalle Valo 	int ret;
5670d5c65159SKalle Valo 
5671d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5672d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5673d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5674d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5675d5c65159SKalle Valo 		return ret;
5676d5c65159SKalle Valo 	}
5677d5c65159SKalle Valo 
5678d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
5679d5c65159SKalle Valo 	if (!ev) {
5680d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer assoc conf ev");
5681d5c65159SKalle Valo 		kfree(tb);
5682d5c65159SKalle Valo 		return -EPROTO;
5683d5c65159SKalle Valo 	}
5684d5c65159SKalle Valo 
5685d5c65159SKalle Valo 	peer_assoc_conf->vdev_id = ev->vdev_id;
5686d5c65159SKalle Valo 	peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
5687d5c65159SKalle Valo 
5688d5c65159SKalle Valo 	kfree(tb);
5689d5c65159SKalle Valo 	return 0;
5690d5c65159SKalle Valo }
5691d5c65159SKalle Valo 
5692d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
5693d5c65159SKalle Valo 					    struct ath11k_fw_stats_pdev *dst)
5694d5c65159SKalle Valo {
5695d5c65159SKalle Valo 	dst->ch_noise_floor = src->chan_nf;
5696d5c65159SKalle Valo 	dst->tx_frame_count = src->tx_frame_count;
5697d5c65159SKalle Valo 	dst->rx_frame_count = src->rx_frame_count;
5698d5c65159SKalle Valo 	dst->rx_clear_count = src->rx_clear_count;
5699d5c65159SKalle Valo 	dst->cycle_count = src->cycle_count;
5700d5c65159SKalle Valo 	dst->phy_err_count = src->phy_err_count;
5701d5c65159SKalle Valo 	dst->chan_tx_power = src->chan_tx_pwr;
5702d5c65159SKalle Valo }
5703d5c65159SKalle Valo 
5704d5c65159SKalle Valo static void
5705d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
5706d5c65159SKalle Valo 			      struct ath11k_fw_stats_pdev *dst)
5707d5c65159SKalle Valo {
5708d5c65159SKalle Valo 	dst->comp_queued = src->comp_queued;
5709d5c65159SKalle Valo 	dst->comp_delivered = src->comp_delivered;
5710d5c65159SKalle Valo 	dst->msdu_enqued = src->msdu_enqued;
5711d5c65159SKalle Valo 	dst->mpdu_enqued = src->mpdu_enqued;
5712d5c65159SKalle Valo 	dst->wmm_drop = src->wmm_drop;
5713d5c65159SKalle Valo 	dst->local_enqued = src->local_enqued;
5714d5c65159SKalle Valo 	dst->local_freed = src->local_freed;
5715d5c65159SKalle Valo 	dst->hw_queued = src->hw_queued;
5716d5c65159SKalle Valo 	dst->hw_reaped = src->hw_reaped;
5717d5c65159SKalle Valo 	dst->underrun = src->underrun;
5718f394e4eaSSriram R 	dst->hw_paused = src->hw_paused;
5719d5c65159SKalle Valo 	dst->tx_abort = src->tx_abort;
572017818dfaSColin Ian King 	dst->mpdus_requeued = src->mpdus_requeued;
5721d5c65159SKalle Valo 	dst->tx_ko = src->tx_ko;
5722f394e4eaSSriram R 	dst->tx_xretry = src->tx_xretry;
5723d5c65159SKalle Valo 	dst->data_rc = src->data_rc;
5724d5c65159SKalle Valo 	dst->self_triggers = src->self_triggers;
5725d5c65159SKalle Valo 	dst->sw_retry_failure = src->sw_retry_failure;
5726d5c65159SKalle Valo 	dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
5727d5c65159SKalle Valo 	dst->pdev_cont_xretry = src->pdev_cont_xretry;
5728d5c65159SKalle Valo 	dst->pdev_tx_timeout = src->pdev_tx_timeout;
5729d5c65159SKalle Valo 	dst->pdev_resets = src->pdev_resets;
5730d5c65159SKalle Valo 	dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
5731d5c65159SKalle Valo 	dst->phy_underrun = src->phy_underrun;
5732d5c65159SKalle Valo 	dst->txop_ovf = src->txop_ovf;
5733f394e4eaSSriram R 	dst->seq_posted = src->seq_posted;
5734f394e4eaSSriram R 	dst->seq_failed_queueing = src->seq_failed_queueing;
5735f394e4eaSSriram R 	dst->seq_completed = src->seq_completed;
5736f394e4eaSSriram R 	dst->seq_restarted = src->seq_restarted;
5737f394e4eaSSriram R 	dst->mu_seq_posted = src->mu_seq_posted;
5738f394e4eaSSriram R 	dst->mpdus_sw_flush = src->mpdus_sw_flush;
5739f394e4eaSSriram R 	dst->mpdus_hw_filter = src->mpdus_hw_filter;
5740f394e4eaSSriram R 	dst->mpdus_truncated = src->mpdus_truncated;
5741f394e4eaSSriram R 	dst->mpdus_ack_failed = src->mpdus_ack_failed;
5742f394e4eaSSriram R 	dst->mpdus_expired = src->mpdus_expired;
5743d5c65159SKalle Valo }
5744d5c65159SKalle Valo 
5745d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
5746d5c65159SKalle Valo 					  struct ath11k_fw_stats_pdev *dst)
5747d5c65159SKalle Valo {
5748d5c65159SKalle Valo 	dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
5749d5c65159SKalle Valo 	dst->status_rcvd = src->status_rcvd;
5750d5c65159SKalle Valo 	dst->r0_frags = src->r0_frags;
5751d5c65159SKalle Valo 	dst->r1_frags = src->r1_frags;
5752d5c65159SKalle Valo 	dst->r2_frags = src->r2_frags;
5753d5c65159SKalle Valo 	dst->r3_frags = src->r3_frags;
5754d5c65159SKalle Valo 	dst->htt_msdus = src->htt_msdus;
5755d5c65159SKalle Valo 	dst->htt_mpdus = src->htt_mpdus;
5756d5c65159SKalle Valo 	dst->loc_msdus = src->loc_msdus;
5757d5c65159SKalle Valo 	dst->loc_mpdus = src->loc_mpdus;
5758d5c65159SKalle Valo 	dst->oversize_amsdu = src->oversize_amsdu;
5759d5c65159SKalle Valo 	dst->phy_errs = src->phy_errs;
5760d5c65159SKalle Valo 	dst->phy_err_drop = src->phy_err_drop;
5761d5c65159SKalle Valo 	dst->mpdu_errs = src->mpdu_errs;
5762f394e4eaSSriram R 	dst->rx_ovfl_errs = src->rx_ovfl_errs;
5763d5c65159SKalle Valo }
5764d5c65159SKalle Valo 
5765d5c65159SKalle Valo static void
5766d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
5767d5c65159SKalle Valo 			   struct ath11k_fw_stats_vdev *dst)
5768d5c65159SKalle Valo {
5769d5c65159SKalle Valo 	int i;
5770d5c65159SKalle Valo 
5771d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
5772d5c65159SKalle Valo 	dst->beacon_snr = src->beacon_snr;
5773d5c65159SKalle Valo 	dst->data_snr = src->data_snr;
5774d5c65159SKalle Valo 	dst->num_rx_frames = src->num_rx_frames;
5775d5c65159SKalle Valo 	dst->num_rts_fail = src->num_rts_fail;
5776d5c65159SKalle Valo 	dst->num_rts_success = src->num_rts_success;
5777d5c65159SKalle Valo 	dst->num_rx_err = src->num_rx_err;
5778d5c65159SKalle Valo 	dst->num_rx_discard = src->num_rx_discard;
5779d5c65159SKalle Valo 	dst->num_tx_not_acked = src->num_tx_not_acked;
5780d5c65159SKalle Valo 
5781d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
5782d5c65159SKalle Valo 		dst->num_tx_frames[i] = src->num_tx_frames[i];
5783d5c65159SKalle Valo 
5784d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
5785d5c65159SKalle Valo 		dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
5786d5c65159SKalle Valo 
5787d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
5788d5c65159SKalle Valo 		dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
5789d5c65159SKalle Valo 
5790d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
5791d5c65159SKalle Valo 		dst->tx_rate_history[i] = src->tx_rate_history[i];
5792d5c65159SKalle Valo 
5793d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
5794d5c65159SKalle Valo 		dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
5795d5c65159SKalle Valo }
5796d5c65159SKalle Valo 
5797d5c65159SKalle Valo static void
5798d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
5799d5c65159SKalle Valo 			  struct ath11k_fw_stats_bcn *dst)
5800d5c65159SKalle Valo {
5801d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
5802d5c65159SKalle Valo 	dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
5803d5c65159SKalle Valo 	dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
5804d5c65159SKalle Valo }
5805d5c65159SKalle Valo 
5806b488c766SWen Gong static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
5807b488c766SWen Gong 					   u16 tag, u16 len,
5808b488c766SWen Gong 					   const void *ptr, void *data)
5809d5c65159SKalle Valo {
5810b488c766SWen Gong 	struct wmi_tlv_fw_stats_parse *parse = data;
5811b488c766SWen Gong 	const struct wmi_stats_event *ev = parse->ev;
5812b488c766SWen Gong 	struct ath11k_fw_stats *stats = parse->stats;
5813b488c766SWen Gong 	struct ath11k *ar;
5814b488c766SWen Gong 	struct ath11k_vif *arvif;
5815b488c766SWen Gong 	struct ieee80211_sta *sta;
5816b488c766SWen Gong 	struct ath11k_sta *arsta;
5817b488c766SWen Gong 	const struct wmi_rssi_stats *stats_rssi = (const struct wmi_rssi_stats *)ptr;
5818b488c766SWen Gong 	int j, ret = 0;
5819d5c65159SKalle Valo 
5820b488c766SWen Gong 	if (tag != WMI_TAG_RSSI_STATS)
5821d5c65159SKalle Valo 		return -EPROTO;
5822b488c766SWen Gong 
5823b488c766SWen Gong 	rcu_read_lock();
5824b488c766SWen Gong 
5825b488c766SWen Gong 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5826b488c766SWen Gong 	stats->stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
5827b488c766SWen Gong 
5828b488c766SWen Gong 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5829b488c766SWen Gong 		   "wmi stats vdev id %d mac %pM\n",
5830b488c766SWen Gong 		   stats_rssi->vdev_id, stats_rssi->peer_macaddr.addr);
5831b488c766SWen Gong 
5832b488c766SWen Gong 	arvif = ath11k_mac_get_arvif(ar, stats_rssi->vdev_id);
5833b488c766SWen Gong 	if (!arvif) {
5834b488c766SWen Gong 		ath11k_warn(ab, "not found vif for vdev id %d\n",
5835b488c766SWen Gong 			    stats_rssi->vdev_id);
5836b488c766SWen Gong 		ret = -EPROTO;
5837b488c766SWen Gong 		goto exit;
5838d5c65159SKalle Valo 	}
5839d5c65159SKalle Valo 
5840d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5841b488c766SWen Gong 		   "wmi stats bssid %pM vif %pK\n",
5842b488c766SWen Gong 		   arvif->bssid, arvif->vif);
5843d5c65159SKalle Valo 
5844b488c766SWen Gong 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5845b488c766SWen Gong 					   arvif->bssid,
5846b488c766SWen Gong 					   NULL);
5847b488c766SWen Gong 	if (!sta) {
58487330e1ecSWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
58497330e1ecSWen Gong 			   "not found station of bssid %pM for rssi chain\n",
5850b488c766SWen Gong 			   arvif->bssid);
5851b488c766SWen Gong 		goto exit;
5852b488c766SWen Gong 	}
5853b488c766SWen Gong 
5854b488c766SWen Gong 	arsta = (struct ath11k_sta *)sta->drv_priv;
5855b488c766SWen Gong 
5856b488c766SWen Gong 	BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
5857b488c766SWen Gong 		     ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
5858b488c766SWen Gong 
5859b488c766SWen Gong 	for (j = 0; j < ARRAY_SIZE(arsta->chain_signal); j++) {
5860b488c766SWen Gong 		arsta->chain_signal[j] = stats_rssi->rssi_avg_beacon[j];
5861b488c766SWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
5862b488c766SWen Gong 			   "wmi stats beacon rssi[%d] %d data rssi[%d] %d\n",
5863b488c766SWen Gong 			   j,
5864b488c766SWen Gong 			   stats_rssi->rssi_avg_beacon[j],
5865b488c766SWen Gong 			   j,
5866b488c766SWen Gong 			   stats_rssi->rssi_avg_data[j]);
5867b488c766SWen Gong 	}
5868b488c766SWen Gong 
5869b488c766SWen Gong exit:
5870b488c766SWen Gong 	rcu_read_unlock();
5871b488c766SWen Gong 	return ret;
5872b488c766SWen Gong }
5873b488c766SWen Gong 
5874b488c766SWen Gong static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
5875b488c766SWen Gong 					      struct wmi_tlv_fw_stats_parse *parse,
5876b488c766SWen Gong 					      const void *ptr,
5877b488c766SWen Gong 					      u16 len)
5878b488c766SWen Gong {
5879b488c766SWen Gong 	struct ath11k_fw_stats *stats = parse->stats;
5880b488c766SWen Gong 	const struct wmi_stats_event *ev = parse->ev;
5881c3b39553SWen Gong 	struct ath11k *ar;
5882c3b39553SWen Gong 	struct ath11k_vif *arvif;
5883c3b39553SWen Gong 	struct ieee80211_sta *sta;
5884c3b39553SWen Gong 	struct ath11k_sta *arsta;
5885c3b39553SWen Gong 	int i, ret = 0;
5886b488c766SWen Gong 	const void *data = ptr;
5887b488c766SWen Gong 
5888b488c766SWen Gong 	if (!ev) {
5889b488c766SWen Gong 		ath11k_warn(ab, "failed to fetch update stats ev");
5890b488c766SWen Gong 		return -EPROTO;
5891b488c766SWen Gong 	}
5892b488c766SWen Gong 
5893d5c65159SKalle Valo 	stats->stats_id = 0;
5894d5c65159SKalle Valo 
5895c3b39553SWen Gong 	rcu_read_lock();
5896c3b39553SWen Gong 
5897c3b39553SWen Gong 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5898c3b39553SWen Gong 
5899d5c65159SKalle Valo 	for (i = 0; i < ev->num_pdev_stats; i++) {
5900d5c65159SKalle Valo 		const struct wmi_pdev_stats *src;
5901d5c65159SKalle Valo 		struct ath11k_fw_stats_pdev *dst;
5902d5c65159SKalle Valo 
5903d5c65159SKalle Valo 		src = data;
5904c3b39553SWen Gong 		if (len < sizeof(*src)) {
5905c3b39553SWen Gong 			ret = -EPROTO;
5906c3b39553SWen Gong 			goto exit;
5907c3b39553SWen Gong 		}
5908d5c65159SKalle Valo 
5909d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_PDEV_STAT;
5910d5c65159SKalle Valo 
5911d5c65159SKalle Valo 		data += sizeof(*src);
5912d5c65159SKalle Valo 		len -= sizeof(*src);
5913d5c65159SKalle Valo 
5914d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5915d5c65159SKalle Valo 		if (!dst)
5916d5c65159SKalle Valo 			continue;
5917d5c65159SKalle Valo 
5918d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
5919d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
5920d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
5921d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->pdevs);
5922d5c65159SKalle Valo 	}
5923d5c65159SKalle Valo 
5924d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdev_stats; i++) {
5925d5c65159SKalle Valo 		const struct wmi_vdev_stats *src;
5926d5c65159SKalle Valo 		struct ath11k_fw_stats_vdev *dst;
5927d5c65159SKalle Valo 
5928d5c65159SKalle Valo 		src = data;
5929c3b39553SWen Gong 		if (len < sizeof(*src)) {
5930c3b39553SWen Gong 			ret = -EPROTO;
5931c3b39553SWen Gong 			goto exit;
5932c3b39553SWen Gong 		}
5933d5c65159SKalle Valo 
5934d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_VDEV_STAT;
5935d5c65159SKalle Valo 
5936c3b39553SWen Gong 		arvif = ath11k_mac_get_arvif(ar, src->vdev_id);
5937c3b39553SWen Gong 		if (arvif) {
5938c3b39553SWen Gong 			sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5939c3b39553SWen Gong 							   arvif->bssid,
5940c3b39553SWen Gong 							   NULL);
5941c3b39553SWen Gong 			if (sta) {
5942c3b39553SWen Gong 				arsta = (struct ath11k_sta *)sta->drv_priv;
5943c3b39553SWen Gong 				arsta->rssi_beacon = src->beacon_snr;
5944c3b39553SWen Gong 				ath11k_dbg(ab, ATH11K_DBG_WMI,
5945c3b39553SWen Gong 					   "wmi stats vdev id %d snr %d\n",
5946c3b39553SWen Gong 					   src->vdev_id, src->beacon_snr);
5947c3b39553SWen Gong 			} else {
59487330e1ecSWen Gong 				ath11k_dbg(ab, ATH11K_DBG_WMI,
59497330e1ecSWen Gong 					   "not found station of bssid %pM for vdev stat\n",
5950c3b39553SWen Gong 					   arvif->bssid);
5951c3b39553SWen Gong 			}
5952c3b39553SWen Gong 		}
5953c3b39553SWen Gong 
5954d5c65159SKalle Valo 		data += sizeof(*src);
5955d5c65159SKalle Valo 		len -= sizeof(*src);
5956d5c65159SKalle Valo 
5957d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5958d5c65159SKalle Valo 		if (!dst)
5959d5c65159SKalle Valo 			continue;
5960d5c65159SKalle Valo 
5961d5c65159SKalle Valo 		ath11k_wmi_pull_vdev_stats(src, dst);
5962d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->vdevs);
5963d5c65159SKalle Valo 	}
5964d5c65159SKalle Valo 
5965d5c65159SKalle Valo 	for (i = 0; i < ev->num_bcn_stats; i++) {
5966d5c65159SKalle Valo 		const struct wmi_bcn_stats *src;
5967d5c65159SKalle Valo 		struct ath11k_fw_stats_bcn *dst;
5968d5c65159SKalle Valo 
5969d5c65159SKalle Valo 		src = data;
5970c3b39553SWen Gong 		if (len < sizeof(*src)) {
5971c3b39553SWen Gong 			ret = -EPROTO;
5972c3b39553SWen Gong 			goto exit;
5973c3b39553SWen Gong 		}
5974d5c65159SKalle Valo 
5975d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_BCN_STAT;
5976d5c65159SKalle Valo 
5977d5c65159SKalle Valo 		data += sizeof(*src);
5978d5c65159SKalle Valo 		len -= sizeof(*src);
5979d5c65159SKalle Valo 
5980d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5981d5c65159SKalle Valo 		if (!dst)
5982d5c65159SKalle Valo 			continue;
5983d5c65159SKalle Valo 
5984d5c65159SKalle Valo 		ath11k_wmi_pull_bcn_stats(src, dst);
5985d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->bcn);
5986d5c65159SKalle Valo 	}
5987d5c65159SKalle Valo 
5988c3b39553SWen Gong exit:
5989c3b39553SWen Gong 	rcu_read_unlock();
5990c3b39553SWen Gong 	return ret;
5991d5c65159SKalle Valo }
5992d5c65159SKalle Valo 
5993b488c766SWen Gong static int ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base *ab,
5994b488c766SWen Gong 					 u16 tag, u16 len,
5995b488c766SWen Gong 					 const void *ptr, void *data)
5996b488c766SWen Gong {
5997b488c766SWen Gong 	struct wmi_tlv_fw_stats_parse *parse = data;
5998b488c766SWen Gong 	int ret = 0;
5999b488c766SWen Gong 
6000b488c766SWen Gong 	switch (tag) {
6001b488c766SWen Gong 	case WMI_TAG_STATS_EVENT:
6002b488c766SWen Gong 		parse->ev = (struct wmi_stats_event *)ptr;
6003b488c766SWen Gong 		parse->stats->pdev_id = parse->ev->pdev_id;
6004b488c766SWen Gong 		break;
6005b488c766SWen Gong 	case WMI_TAG_ARRAY_BYTE:
6006b488c766SWen Gong 		ret = ath11k_wmi_tlv_fw_stats_data_parse(ab, parse, ptr, len);
6007b488c766SWen Gong 		break;
6008b488c766SWen Gong 	case WMI_TAG_PER_CHAIN_RSSI_STATS:
6009b488c766SWen Gong 		parse->rssi = (struct wmi_per_chain_rssi_stats *)ptr;
6010b488c766SWen Gong 
6011b488c766SWen Gong 		if (parse->ev->stats_id & WMI_REQUEST_RSSI_PER_CHAIN_STAT)
6012b488c766SWen Gong 			parse->rssi_num = parse->rssi->num_per_chain_rssi_stats;
6013b488c766SWen Gong 
6014b488c766SWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
6015b488c766SWen Gong 			   "wmi stats id 0x%x num chain %d\n",
6016b488c766SWen Gong 			   parse->ev->stats_id,
6017b488c766SWen Gong 			   parse->rssi_num);
6018b488c766SWen Gong 		break;
6019b488c766SWen Gong 	case WMI_TAG_ARRAY_STRUCT:
6020b488c766SWen Gong 		if (parse->rssi_num && !parse->chain_rssi_done) {
6021b488c766SWen Gong 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
6022b488c766SWen Gong 						  ath11k_wmi_tlv_rssi_chain_parse,
6023b488c766SWen Gong 						  parse);
6024b488c766SWen Gong 			if (ret) {
6025b488c766SWen Gong 				ath11k_warn(ab, "failed to parse rssi chain %d\n",
6026b488c766SWen Gong 					    ret);
6027b488c766SWen Gong 				return ret;
6028b488c766SWen Gong 			}
6029b488c766SWen Gong 			parse->chain_rssi_done = true;
6030b488c766SWen Gong 		}
6031b488c766SWen Gong 		break;
6032b488c766SWen Gong 	default:
6033b488c766SWen Gong 		break;
6034b488c766SWen Gong 	}
6035b488c766SWen Gong 	return ret;
6036b488c766SWen Gong }
6037b488c766SWen Gong 
6038b488c766SWen Gong int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
6039b488c766SWen Gong 			     struct ath11k_fw_stats *stats)
6040b488c766SWen Gong {
6041b488c766SWen Gong 	struct wmi_tlv_fw_stats_parse parse = { };
6042b488c766SWen Gong 
6043b488c766SWen Gong 	stats->stats_id = 0;
6044b488c766SWen Gong 	parse.stats = stats;
6045b488c766SWen Gong 
6046b488c766SWen Gong 	return ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6047b488c766SWen Gong 				   ath11k_wmi_tlv_fw_stats_parse,
6048b488c766SWen Gong 				   &parse);
6049b488c766SWen Gong }
6050b488c766SWen Gong 
6051d5c65159SKalle Valo size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head)
6052d5c65159SKalle Valo {
6053d5c65159SKalle Valo 	struct ath11k_fw_stats_vdev *i;
6054d5c65159SKalle Valo 	size_t num = 0;
6055d5c65159SKalle Valo 
6056d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
6057d5c65159SKalle Valo 		++num;
6058d5c65159SKalle Valo 
6059d5c65159SKalle Valo 	return num;
6060d5c65159SKalle Valo }
6061d5c65159SKalle Valo 
6062d5c65159SKalle Valo static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head)
6063d5c65159SKalle Valo {
6064d5c65159SKalle Valo 	struct ath11k_fw_stats_bcn *i;
6065d5c65159SKalle Valo 	size_t num = 0;
6066d5c65159SKalle Valo 
6067d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
6068d5c65159SKalle Valo 		++num;
6069d5c65159SKalle Valo 
6070d5c65159SKalle Valo 	return num;
6071d5c65159SKalle Valo }
6072d5c65159SKalle Valo 
6073d5c65159SKalle Valo static void
6074d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6075d5c65159SKalle Valo 				   char *buf, u32 *length)
6076d5c65159SKalle Valo {
6077d5c65159SKalle Valo 	u32 len = *length;
6078d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6079d5c65159SKalle Valo 
6080d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
6081d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
6082d5c65159SKalle Valo 			"ath11k PDEV stats");
6083d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6084d5c65159SKalle Valo 			"=================");
6085d5c65159SKalle Valo 
6086d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6087d5c65159SKalle Valo 			"Channel noise floor", pdev->ch_noise_floor);
6088d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6089d5c65159SKalle Valo 			"Channel TX power", pdev->chan_tx_power);
6090d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6091d5c65159SKalle Valo 			"TX frame count", pdev->tx_frame_count);
6092d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6093d5c65159SKalle Valo 			"RX frame count", pdev->rx_frame_count);
6094d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6095d5c65159SKalle Valo 			"RX clear count", pdev->rx_clear_count);
6096d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6097d5c65159SKalle Valo 			"Cycle count", pdev->cycle_count);
6098d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6099d5c65159SKalle Valo 			"PHY error count", pdev->phy_err_count);
6100d5c65159SKalle Valo 
6101d5c65159SKalle Valo 	*length = len;
6102d5c65159SKalle Valo }
6103d5c65159SKalle Valo 
6104d5c65159SKalle Valo static void
6105d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6106d5c65159SKalle Valo 				 char *buf, u32 *length)
6107d5c65159SKalle Valo {
6108d5c65159SKalle Valo 	u32 len = *length;
6109d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6110d5c65159SKalle Valo 
6111d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6112d5c65159SKalle Valo 			 "ath11k PDEV TX stats");
6113d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6114d5c65159SKalle Valo 			 "====================");
6115d5c65159SKalle Valo 
6116d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6117d5c65159SKalle Valo 			 "HTT cookies queued", pdev->comp_queued);
6118d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6119d5c65159SKalle Valo 			 "HTT cookies disp.", pdev->comp_delivered);
6120d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6121d5c65159SKalle Valo 			 "MSDU queued", pdev->msdu_enqued);
6122d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6123d5c65159SKalle Valo 			 "MPDU queued", pdev->mpdu_enqued);
6124d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6125d5c65159SKalle Valo 			 "MSDUs dropped", pdev->wmm_drop);
6126d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6127d5c65159SKalle Valo 			 "Local enqued", pdev->local_enqued);
6128d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6129d5c65159SKalle Valo 			 "Local freed", pdev->local_freed);
6130d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6131d5c65159SKalle Valo 			 "HW queued", pdev->hw_queued);
6132d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6133d5c65159SKalle Valo 			 "PPDUs reaped", pdev->hw_reaped);
6134d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6135d5c65159SKalle Valo 			 "Num underruns", pdev->underrun);
6136d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6137f394e4eaSSriram R 			 "Num HW Paused", pdev->hw_paused);
6138f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6139d5c65159SKalle Valo 			 "PPDUs cleaned", pdev->tx_abort);
6140d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
614117818dfaSColin Ian King 			 "MPDUs requeued", pdev->mpdus_requeued);
6142d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6143f394e4eaSSriram R 			 "PPDU OK", pdev->tx_ko);
6144f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6145f394e4eaSSriram R 			 "Excessive retries", pdev->tx_xretry);
6146d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6147d5c65159SKalle Valo 			 "HW rate", pdev->data_rc);
6148d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6149d5c65159SKalle Valo 			 "Sched self triggers", pdev->self_triggers);
6150d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6151d5c65159SKalle Valo 			 "Dropped due to SW retries",
6152d5c65159SKalle Valo 			 pdev->sw_retry_failure);
6153d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6154d5c65159SKalle Valo 			 "Illegal rate phy errors",
6155d5c65159SKalle Valo 			 pdev->illgl_rate_phy_err);
6156d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6157d5c65159SKalle Valo 			 "PDEV continuous xretry", pdev->pdev_cont_xretry);
6158d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6159d5c65159SKalle Valo 			 "TX timeout", pdev->pdev_tx_timeout);
6160d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6161d5c65159SKalle Valo 			 "PDEV resets", pdev->pdev_resets);
6162d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6163d5c65159SKalle Valo 			 "Stateless TIDs alloc failures",
6164d5c65159SKalle Valo 			 pdev->stateless_tid_alloc_failure);
6165d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6166d5c65159SKalle Valo 			 "PHY underrun", pdev->phy_underrun);
6167d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6168d5c65159SKalle Valo 			 "MPDU is more than txop limit", pdev->txop_ovf);
6169f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6170f394e4eaSSriram R 			 "Num sequences posted", pdev->seq_posted);
6171f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6172f394e4eaSSriram R 			 "Num seq failed queueing ", pdev->seq_failed_queueing);
6173f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6174f394e4eaSSriram R 			 "Num sequences completed ", pdev->seq_completed);
6175f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6176f394e4eaSSriram R 			 "Num sequences restarted ", pdev->seq_restarted);
6177f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6178f394e4eaSSriram R 			 "Num of MU sequences posted ", pdev->mu_seq_posted);
6179f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6180f394e4eaSSriram R 			 "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush);
6181f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6182f394e4eaSSriram R 			 "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter);
6183f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6184f394e4eaSSriram R 			 "Num of MPDUS truncated ", pdev->mpdus_truncated);
6185f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6186f394e4eaSSriram R 			 "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed);
6187f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6188f394e4eaSSriram R 			 "Num of MPDUS expired ", pdev->mpdus_expired);
6189d5c65159SKalle Valo 	*length = len;
6190d5c65159SKalle Valo }
6191d5c65159SKalle Valo 
6192d5c65159SKalle Valo static void
6193d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6194d5c65159SKalle Valo 				 char *buf, u32 *length)
6195d5c65159SKalle Valo {
6196d5c65159SKalle Valo 	u32 len = *length;
6197d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6198d5c65159SKalle Valo 
6199d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6200d5c65159SKalle Valo 			 "ath11k PDEV RX stats");
6201d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6202d5c65159SKalle Valo 			 "====================");
6203d5c65159SKalle Valo 
6204d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6205d5c65159SKalle Valo 			 "Mid PPDU route change",
6206d5c65159SKalle Valo 			 pdev->mid_ppdu_route_change);
6207d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6208d5c65159SKalle Valo 			 "Tot. number of statuses", pdev->status_rcvd);
6209d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6210d5c65159SKalle Valo 			 "Extra frags on rings 0", pdev->r0_frags);
6211d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6212d5c65159SKalle Valo 			 "Extra frags on rings 1", pdev->r1_frags);
6213d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6214d5c65159SKalle Valo 			 "Extra frags on rings 2", pdev->r2_frags);
6215d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6216d5c65159SKalle Valo 			 "Extra frags on rings 3", pdev->r3_frags);
6217d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6218d5c65159SKalle Valo 			 "MSDUs delivered to HTT", pdev->htt_msdus);
6219d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6220d5c65159SKalle Valo 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
6221d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6222d5c65159SKalle Valo 			 "MSDUs delivered to stack", pdev->loc_msdus);
6223d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6224d5c65159SKalle Valo 			 "MPDUs delivered to stack", pdev->loc_mpdus);
6225d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6226d5c65159SKalle Valo 			 "Oversized AMSUs", pdev->oversize_amsdu);
6227d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6228d5c65159SKalle Valo 			 "PHY errors", pdev->phy_errs);
6229d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6230d5c65159SKalle Valo 			 "PHY errors drops", pdev->phy_err_drop);
6231d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6232d5c65159SKalle Valo 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
6233f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6234f394e4eaSSriram R 			 "Overflow errors", pdev->rx_ovfl_errs);
6235d5c65159SKalle Valo 	*length = len;
6236d5c65159SKalle Valo }
6237d5c65159SKalle Valo 
6238d5c65159SKalle Valo static void
6239d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
6240d5c65159SKalle Valo 			      const struct ath11k_fw_stats_vdev *vdev,
6241d5c65159SKalle Valo 			      char *buf, u32 *length)
6242d5c65159SKalle Valo {
6243d5c65159SKalle Valo 	u32 len = *length;
6244d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6245d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
6246d5c65159SKalle Valo 	u8 *vif_macaddr;
6247d5c65159SKalle Valo 	int i;
6248d5c65159SKalle Valo 
6249d5c65159SKalle Valo 	/* VDEV stats has all the active VDEVs of other PDEVs as well,
6250d5c65159SKalle Valo 	 * ignoring those not part of requested PDEV
6251d5c65159SKalle Valo 	 */
6252d5c65159SKalle Valo 	if (!arvif)
6253d5c65159SKalle Valo 		return;
6254d5c65159SKalle Valo 
6255d5c65159SKalle Valo 	vif_macaddr = arvif->vif->addr;
6256d5c65159SKalle Valo 
6257d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6258d5c65159SKalle Valo 			 "VDEV ID", vdev->vdev_id);
6259d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6260d5c65159SKalle Valo 			 "VDEV MAC address", vif_macaddr);
6261d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6262d5c65159SKalle Valo 			 "beacon snr", vdev->beacon_snr);
6263d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6264d5c65159SKalle Valo 			 "data snr", vdev->data_snr);
6265d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6266d5c65159SKalle Valo 			 "num rx frames", vdev->num_rx_frames);
6267d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6268d5c65159SKalle Valo 			 "num rts fail", vdev->num_rts_fail);
6269d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6270d5c65159SKalle Valo 			 "num rts success", vdev->num_rts_success);
6271d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6272d5c65159SKalle Valo 			 "num rx err", vdev->num_rx_err);
6273d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6274d5c65159SKalle Valo 			 "num rx discard", vdev->num_rx_discard);
6275d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6276d5c65159SKalle Valo 			 "num tx not acked", vdev->num_tx_not_acked);
6277d5c65159SKalle Valo 
6278d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
6279d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6280d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6281d5c65159SKalle Valo 				"num tx frames", i,
6282d5c65159SKalle Valo 				vdev->num_tx_frames[i]);
6283d5c65159SKalle Valo 
6284d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
6285d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6286d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6287d5c65159SKalle Valo 				"num tx frames retries", i,
6288d5c65159SKalle Valo 				vdev->num_tx_frames_retries[i]);
6289d5c65159SKalle Valo 
6290d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
6291d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6292d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6293d5c65159SKalle Valo 				"num tx frames failures", i,
6294d5c65159SKalle Valo 				vdev->num_tx_frames_failures[i]);
6295d5c65159SKalle Valo 
6296d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
6297d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6298d5c65159SKalle Valo 				"%25s [%02d] 0x%08x\n",
6299d5c65159SKalle Valo 				"tx rate history", i,
6300d5c65159SKalle Valo 				vdev->tx_rate_history[i]);
6301d5c65159SKalle Valo 
6302d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
6303d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6304d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6305d5c65159SKalle Valo 				"beacon rssi history", i,
6306d5c65159SKalle Valo 				vdev->beacon_rssi_history[i]);
6307d5c65159SKalle Valo 
6308d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
6309d5c65159SKalle Valo 	*length = len;
6310d5c65159SKalle Valo }
6311d5c65159SKalle Valo 
6312d5c65159SKalle Valo static void
6313d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
6314d5c65159SKalle Valo 			     const struct ath11k_fw_stats_bcn *bcn,
6315d5c65159SKalle Valo 			     char *buf, u32 *length)
6316d5c65159SKalle Valo {
6317d5c65159SKalle Valo 	u32 len = *length;
6318d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6319d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
6320d5c65159SKalle Valo 	u8 *vdev_macaddr;
6321d5c65159SKalle Valo 
6322d5c65159SKalle Valo 	if (!arvif) {
6323d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
6324d5c65159SKalle Valo 			    bcn->vdev_id);
6325d5c65159SKalle Valo 		return;
6326d5c65159SKalle Valo 	}
6327d5c65159SKalle Valo 
6328d5c65159SKalle Valo 	vdev_macaddr = arvif->vif->addr;
6329d5c65159SKalle Valo 
6330d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6331d5c65159SKalle Valo 			 "VDEV ID", bcn->vdev_id);
6332d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6333d5c65159SKalle Valo 			 "VDEV MAC address", vdev_macaddr);
6334d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6335d5c65159SKalle Valo 			 "================");
6336d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6337d5c65159SKalle Valo 			 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
6338d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6339d5c65159SKalle Valo 			 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
6340d5c65159SKalle Valo 
6341d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
6342d5c65159SKalle Valo 	*length = len;
6343d5c65159SKalle Valo }
6344d5c65159SKalle Valo 
6345d5c65159SKalle Valo void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
6346d5c65159SKalle Valo 			      struct ath11k_fw_stats *fw_stats,
6347d5c65159SKalle Valo 			      u32 stats_id, char *buf)
6348d5c65159SKalle Valo {
6349d5c65159SKalle Valo 	u32 len = 0;
6350d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6351d5c65159SKalle Valo 	const struct ath11k_fw_stats_pdev *pdev;
6352d5c65159SKalle Valo 	const struct ath11k_fw_stats_vdev *vdev;
6353d5c65159SKalle Valo 	const struct ath11k_fw_stats_bcn *bcn;
6354d5c65159SKalle Valo 	size_t num_bcn;
6355d5c65159SKalle Valo 
6356d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
6357d5c65159SKalle Valo 
6358d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_PDEV_STAT) {
6359d5c65159SKalle Valo 		pdev = list_first_entry_or_null(&fw_stats->pdevs,
6360d5c65159SKalle Valo 						struct ath11k_fw_stats_pdev, list);
6361d5c65159SKalle Valo 		if (!pdev) {
6362d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to get pdev stats\n");
6363d5c65159SKalle Valo 			goto unlock;
6364d5c65159SKalle Valo 		}
6365d5c65159SKalle Valo 
6366d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
6367d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
6368d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
6369d5c65159SKalle Valo 	}
6370d5c65159SKalle Valo 
6371d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_VDEV_STAT) {
6372d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
6373d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n",
6374d5c65159SKalle Valo 				 "ath11k VDEV stats");
6375d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6376d5c65159SKalle Valo 				 "=================");
6377d5c65159SKalle Valo 
6378d5c65159SKalle Valo 		list_for_each_entry(vdev, &fw_stats->vdevs, list)
6379d5c65159SKalle Valo 			ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
6380d5c65159SKalle Valo 	}
6381d5c65159SKalle Valo 
6382d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_BCN_STAT) {
6383d5c65159SKalle Valo 		num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn);
6384d5c65159SKalle Valo 
6385d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
6386d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
6387d5c65159SKalle Valo 				 "ath11k Beacon stats", num_bcn);
6388d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6389d5c65159SKalle Valo 				 "===================");
6390d5c65159SKalle Valo 
6391d5c65159SKalle Valo 		list_for_each_entry(bcn, &fw_stats->bcn, list)
6392d5c65159SKalle Valo 			ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
6393d5c65159SKalle Valo 	}
6394d5c65159SKalle Valo 
6395d5c65159SKalle Valo unlock:
6396d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
6397d5c65159SKalle Valo 
6398d5c65159SKalle Valo 	if (len >= buf_len)
6399d5c65159SKalle Valo 		buf[len - 1] = 0;
6400d5c65159SKalle Valo 	else
6401d5c65159SKalle Valo 		buf[len] = 0;
6402d5c65159SKalle Valo }
6403d5c65159SKalle Valo 
6404d5c65159SKalle Valo static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
6405d5c65159SKalle Valo {
6406d5c65159SKalle Valo 	/* try to send pending beacons first. they take priority */
64076bc9d6f7SJohn Crispin 	wake_up(&ab->wmi_ab.tx_credits_wq);
6408d5c65159SKalle Valo }
6409d5c65159SKalle Valo 
64109dcf6808SWen Gong static int ath11k_reg_11d_new_cc_event(struct ath11k_base *ab, struct sk_buff *skb)
64119dcf6808SWen Gong {
64129dcf6808SWen Gong 	const struct wmi_11d_new_cc_ev *ev;
64131f682dc9SWen Gong 	struct ath11k *ar;
64141f682dc9SWen Gong 	struct ath11k_pdev *pdev;
64159dcf6808SWen Gong 	const void **tb;
64161f682dc9SWen Gong 	int ret, i;
64179dcf6808SWen Gong 
64189dcf6808SWen Gong 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
64199dcf6808SWen Gong 	if (IS_ERR(tb)) {
64209dcf6808SWen Gong 		ret = PTR_ERR(tb);
64219dcf6808SWen Gong 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
64229dcf6808SWen Gong 		return ret;
64239dcf6808SWen Gong 	}
64249dcf6808SWen Gong 
64259dcf6808SWen Gong 	ev = tb[WMI_TAG_11D_NEW_COUNTRY_EVENT];
64269dcf6808SWen Gong 	if (!ev) {
64279dcf6808SWen Gong 		kfree(tb);
64289dcf6808SWen Gong 		ath11k_warn(ab, "failed to fetch 11d new cc ev");
64299dcf6808SWen Gong 		return -EPROTO;
64309dcf6808SWen Gong 	}
64319dcf6808SWen Gong 
64329dcf6808SWen Gong 	spin_lock_bh(&ab->base_lock);
64339dcf6808SWen Gong 	memcpy(&ab->new_alpha2, &ev->new_alpha2, 2);
64349dcf6808SWen Gong 	spin_unlock_bh(&ab->base_lock);
64359dcf6808SWen Gong 
64369dcf6808SWen Gong 	ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi 11d new cc %c%c\n",
64379dcf6808SWen Gong 		   ab->new_alpha2[0],
64389dcf6808SWen Gong 		   ab->new_alpha2[1]);
64399dcf6808SWen Gong 
64409dcf6808SWen Gong 	kfree(tb);
64419dcf6808SWen Gong 
64421f682dc9SWen Gong 	for (i = 0; i < ab->num_radios; i++) {
64431f682dc9SWen Gong 		pdev = &ab->pdevs[i];
64441f682dc9SWen Gong 		ar = pdev->ar;
64451f682dc9SWen Gong 		ar->state_11d = ATH11K_11D_IDLE;
64461f682dc9SWen Gong 		complete(&ar->completed_11d_scan);
64471f682dc9SWen Gong 	}
64481f682dc9SWen Gong 
64499dcf6808SWen Gong 	queue_work(ab->workqueue, &ab->update_11d_work);
64509dcf6808SWen Gong 
64519dcf6808SWen Gong 	return 0;
64529dcf6808SWen Gong }
64539dcf6808SWen Gong 
6454d5c65159SKalle Valo static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
6455d5c65159SKalle Valo 				       struct sk_buff *skb)
6456d5c65159SKalle Valo {
6457f951380aSP Praneesh 	struct ath11k_pdev_wmi *wmi = NULL;
6458f951380aSP Praneesh 	u32 i;
6459f951380aSP Praneesh 	u8 wmi_ep_count;
6460f951380aSP Praneesh 	u8 eid;
6461f951380aSP Praneesh 
6462f951380aSP Praneesh 	eid = ATH11K_SKB_CB(skb)->eid;
6463d5c65159SKalle Valo 	dev_kfree_skb(skb);
6464f951380aSP Praneesh 
6465f951380aSP Praneesh 	if (eid >= ATH11K_HTC_EP_COUNT)
6466f951380aSP Praneesh 		return;
6467f951380aSP Praneesh 
6468f951380aSP Praneesh 	wmi_ep_count = ab->htc.wmi_ep_count;
6469f951380aSP Praneesh 	if (wmi_ep_count > ab->hw_params.max_radios)
6470f951380aSP Praneesh 		return;
6471f951380aSP Praneesh 
6472f951380aSP Praneesh 	for (i = 0; i < ab->htc.wmi_ep_count; i++) {
6473f951380aSP Praneesh 		if (ab->wmi_ab.wmi[i].eid == eid) {
6474f951380aSP Praneesh 			wmi = &ab->wmi_ab.wmi[i];
6475f951380aSP Praneesh 			break;
6476f951380aSP Praneesh 		}
6477f951380aSP Praneesh 	}
6478f951380aSP Praneesh 
6479f951380aSP Praneesh 	if (wmi)
6480f951380aSP Praneesh 		wake_up(&wmi->tx_ce_desc_wq);
6481d5c65159SKalle Valo }
6482d5c65159SKalle Valo 
6483d5c65159SKalle Valo static bool ath11k_reg_is_world_alpha(char *alpha)
6484d5c65159SKalle Valo {
6485f8108250SWen Gong 	if (alpha[0] == '0' && alpha[1] == '0')
6486f8108250SWen Gong 		return true;
6487f8108250SWen Gong 
6488f8108250SWen Gong 	if (alpha[0] == 'n' && alpha[1] == 'a')
6489f8108250SWen Gong 		return true;
6490f8108250SWen Gong 
6491f8108250SWen Gong 	return false;
6492d5c65159SKalle Valo }
6493d5c65159SKalle Valo 
6494d5c65159SKalle Valo static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb)
6495d5c65159SKalle Valo {
6496d5c65159SKalle Valo 	struct cur_regulatory_info *reg_info = NULL;
6497d5c65159SKalle Valo 	struct ieee80211_regdomain *regd = NULL;
6498d5c65159SKalle Valo 	bool intersect = false;
6499d5c65159SKalle Valo 	int ret = 0, pdev_idx;
6500d5c65159SKalle Valo 	struct ath11k *ar;
6501d5c65159SKalle Valo 
6502d5c65159SKalle Valo 	reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
6503d5c65159SKalle Valo 	if (!reg_info) {
6504d5c65159SKalle Valo 		ret = -ENOMEM;
6505d5c65159SKalle Valo 		goto fallback;
6506d5c65159SKalle Valo 	}
6507d5c65159SKalle Valo 
6508d5c65159SKalle Valo 	ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
6509d5c65159SKalle Valo 	if (ret) {
6510d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract regulatory info from received event\n");
6511d5c65159SKalle Valo 		goto fallback;
6512d5c65159SKalle Valo 	}
6513d5c65159SKalle Valo 
6514d5c65159SKalle Valo 	if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
6515d5c65159SKalle Valo 		/* In case of failure to set the requested ctry,
6516d5c65159SKalle Valo 		 * fw retains the current regd. We print a failure info
6517d5c65159SKalle Valo 		 * and return from here.
6518d5c65159SKalle Valo 		 */
6519d5c65159SKalle Valo 		ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
6520d5c65159SKalle Valo 		goto mem_free;
6521d5c65159SKalle Valo 	}
6522d5c65159SKalle Valo 
6523d5c65159SKalle Valo 	pdev_idx = reg_info->phy_id;
6524d5c65159SKalle Valo 
652569a0fcf8SSriram R 	/* Avoid default reg rule updates sent during FW recovery if
652669a0fcf8SSriram R 	 * it is already available
652769a0fcf8SSriram R 	 */
652869a0fcf8SSriram R 	spin_lock(&ab->base_lock);
652969a0fcf8SSriram R 	if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) &&
653069a0fcf8SSriram R 	    ab->default_regd[pdev_idx]) {
653169a0fcf8SSriram R 		spin_unlock(&ab->base_lock);
653269a0fcf8SSriram R 		goto mem_free;
653369a0fcf8SSriram R 	}
653469a0fcf8SSriram R 	spin_unlock(&ab->base_lock);
653569a0fcf8SSriram R 
65365f859bc0SCarl Huang 	if (pdev_idx >= ab->num_radios) {
653784eee3c8SCarl Huang 		/* Process the event for phy0 only if single_pdev_only
653884eee3c8SCarl Huang 		 * is true. If pdev_idx is valid but not 0, discard the
653984eee3c8SCarl Huang 		 * event. Otherwise, it goes to fallback.
654084eee3c8SCarl Huang 		 */
654184eee3c8SCarl Huang 		if (ab->hw_params.single_pdev_only &&
654284eee3c8SCarl Huang 		    pdev_idx < ab->hw_params.num_rxmda_per_pdev)
65435f859bc0SCarl Huang 			goto mem_free;
65445f859bc0SCarl Huang 		else
6545d5c65159SKalle Valo 			goto fallback;
65465f859bc0SCarl Huang 	}
6547d5c65159SKalle Valo 
6548d5c65159SKalle Valo 	/* Avoid multiple overwrites to default regd, during core
6549d5c65159SKalle Valo 	 * stop-start after mac registration.
6550d5c65159SKalle Valo 	 */
6551d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
6552d5c65159SKalle Valo 	    !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
6553d5c65159SKalle Valo 		    (char *)reg_info->alpha2, 2))
6554b5316db2SColin Ian King 		goto mem_free;
6555d5c65159SKalle Valo 
6556d5c65159SKalle Valo 	/* Intersect new rules with default regd if a new country setting was
6557d5c65159SKalle Valo 	 * requested, i.e a default regd was already set during initialization
6558d5c65159SKalle Valo 	 * and the regd coming from this event has a valid country info.
6559d5c65159SKalle Valo 	 */
6560d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] &&
6561d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)
6562d5c65159SKalle Valo 		ab->default_regd[pdev_idx]->alpha2) &&
6563d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
6564d5c65159SKalle Valo 		intersect = true;
6565d5c65159SKalle Valo 
6566d5c65159SKalle Valo 	regd = ath11k_reg_build_regd(ab, reg_info, intersect);
6567d5c65159SKalle Valo 	if (!regd) {
6568d5c65159SKalle Valo 		ath11k_warn(ab, "failed to build regd from reg_info\n");
6569d5c65159SKalle Valo 		goto fallback;
6570d5c65159SKalle Valo 	}
6571d5c65159SKalle Valo 
6572d5c65159SKalle Valo 	spin_lock(&ab->base_lock);
65731db2b0d0SSriram R 	if (ab->default_regd[pdev_idx]) {
65741db2b0d0SSriram R 		/* The initial rules from FW after WMI Init is to build
65751db2b0d0SSriram R 		 * the default regd. From then on, any rules updated for
65761db2b0d0SSriram R 		 * the pdev could be due to user reg changes.
6577d5c65159SKalle Valo 		 * Free previously built regd before assigning the newly
6578d5c65159SKalle Valo 		 * generated regd to ar. NULL pointer handling will be
6579d5c65159SKalle Valo 		 * taken care by kfree itself.
6580d5c65159SKalle Valo 		 */
6581d5c65159SKalle Valo 		ar = ab->pdevs[pdev_idx].ar;
6582d5c65159SKalle Valo 		kfree(ab->new_regd[pdev_idx]);
6583d5c65159SKalle Valo 		ab->new_regd[pdev_idx] = regd;
6584ed05c7cfSWen Gong 		queue_work(ab->workqueue, &ar->regd_update_work);
6585d5c65159SKalle Valo 	} else {
65861db2b0d0SSriram R 		/* This regd would be applied during mac registration and is
65871db2b0d0SSriram R 		 * held constant throughout for regd intersection purpose
6588d5c65159SKalle Valo 		 */
6589d5c65159SKalle Valo 		ab->default_regd[pdev_idx] = regd;
6590d5c65159SKalle Valo 	}
6591d5c65159SKalle Valo 	ab->dfs_region = reg_info->dfs_region;
6592d5c65159SKalle Valo 	spin_unlock(&ab->base_lock);
6593d5c65159SKalle Valo 
6594d5c65159SKalle Valo 	goto mem_free;
6595d5c65159SKalle Valo 
6596d5c65159SKalle Valo fallback:
6597d5c65159SKalle Valo 	/* Fallback to older reg (by sending previous country setting
65983926e0c1SManikanta Pubbisetty 	 * again if fw has succeeded and we failed to process here.
6599d5c65159SKalle Valo 	 * The Regdomain should be uniform across driver and fw. Since the
6600d5c65159SKalle Valo 	 * FW has processed the command and sent a success status, we expect
6601d5c65159SKalle Valo 	 * this function to succeed as well. If it doesn't, CTRY needs to be
6602d5c65159SKalle Valo 	 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
6603d5c65159SKalle Valo 	 */
6604d5c65159SKalle Valo 	/* TODO: This is rare, but still should also be handled */
6605d5c65159SKalle Valo 	WARN_ON(1);
6606d5c65159SKalle Valo mem_free:
6607d5c65159SKalle Valo 	if (reg_info) {
6608d5c65159SKalle Valo 		kfree(reg_info->reg_rules_2g_ptr);
6609d5c65159SKalle Valo 		kfree(reg_info->reg_rules_5g_ptr);
6610d5c65159SKalle Valo 		kfree(reg_info);
6611d5c65159SKalle Valo 	}
6612d5c65159SKalle Valo 	return ret;
6613d5c65159SKalle Valo }
6614d5c65159SKalle Valo 
6615d5c65159SKalle Valo static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
6616d5c65159SKalle Valo 				    const void *ptr, void *data)
6617d5c65159SKalle Valo {
6618d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse *rdy_parse = data;
661921c1b063SMaharaja Kennadyrajan 	struct wmi_ready_event fixed_param;
6620d5c65159SKalle Valo 	struct wmi_mac_addr *addr_list;
6621d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
6622d5c65159SKalle Valo 	u32 num_mac_addr;
6623d5c65159SKalle Valo 	int i;
6624d5c65159SKalle Valo 
6625d5c65159SKalle Valo 	switch (tag) {
6626d5c65159SKalle Valo 	case WMI_TAG_READY_EVENT:
662721c1b063SMaharaja Kennadyrajan 		memset(&fixed_param, 0, sizeof(fixed_param));
662821c1b063SMaharaja Kennadyrajan 		memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
662921c1b063SMaharaja Kennadyrajan 		       min_t(u16, sizeof(fixed_param), len));
663021c1b063SMaharaja Kennadyrajan 		ab->wlan_init_status = fixed_param.ready_event_min.status;
663121c1b063SMaharaja Kennadyrajan 		rdy_parse->num_extra_mac_addr =
663221c1b063SMaharaja Kennadyrajan 			fixed_param.ready_event_min.num_extra_mac_addr;
6633d5c65159SKalle Valo 
663421c1b063SMaharaja Kennadyrajan 		ether_addr_copy(ab->mac_addr,
663521c1b063SMaharaja Kennadyrajan 				fixed_param.ready_event_min.mac_addr.addr);
663621c1b063SMaharaja Kennadyrajan 		ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum;
6637d5c65159SKalle Valo 		ab->wmi_ready = true;
6638d5c65159SKalle Valo 		break;
6639d5c65159SKalle Valo 	case WMI_TAG_ARRAY_FIXED_STRUCT:
6640d5c65159SKalle Valo 		addr_list = (struct wmi_mac_addr *)ptr;
6641d5c65159SKalle Valo 		num_mac_addr = rdy_parse->num_extra_mac_addr;
6642d5c65159SKalle Valo 
6643d5c65159SKalle Valo 		if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
6644d5c65159SKalle Valo 			break;
6645d5c65159SKalle Valo 
6646d5c65159SKalle Valo 		for (i = 0; i < ab->num_radios; i++) {
6647d5c65159SKalle Valo 			pdev = &ab->pdevs[i];
6648d5c65159SKalle Valo 			ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
6649d5c65159SKalle Valo 		}
6650d5c65159SKalle Valo 		ab->pdevs_macaddr_valid = true;
6651d5c65159SKalle Valo 		break;
6652d5c65159SKalle Valo 	default:
6653d5c65159SKalle Valo 		break;
6654d5c65159SKalle Valo 	}
6655d5c65159SKalle Valo 
6656d5c65159SKalle Valo 	return 0;
6657d5c65159SKalle Valo }
6658d5c65159SKalle Valo 
6659d5c65159SKalle Valo static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
6660d5c65159SKalle Valo {
6661d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse rdy_parse = { };
6662d5c65159SKalle Valo 	int ret;
6663d5c65159SKalle Valo 
6664d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6665d5c65159SKalle Valo 				  ath11k_wmi_tlv_rdy_parse, &rdy_parse);
6666d5c65159SKalle Valo 	if (ret) {
6667d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
6668d5c65159SKalle Valo 		return ret;
6669d5c65159SKalle Valo 	}
6670d5c65159SKalle Valo 
66716bc9d6f7SJohn Crispin 	complete(&ab->wmi_ab.unified_ready);
6672d5c65159SKalle Valo 	return 0;
6673d5c65159SKalle Valo }
6674d5c65159SKalle Valo 
6675d5c65159SKalle Valo static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
6676d5c65159SKalle Valo {
6677d5c65159SKalle Valo 	struct wmi_peer_delete_resp_event peer_del_resp;
6678690ace20SRitesh Singh 	struct ath11k *ar;
6679d5c65159SKalle Valo 
6680d5c65159SKalle Valo 	if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
6681d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer delete resp");
6682d5c65159SKalle Valo 		return;
6683d5c65159SKalle Valo 	}
6684d5c65159SKalle Valo 
6685690ace20SRitesh Singh 	rcu_read_lock();
6686690ace20SRitesh Singh 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id);
6687690ace20SRitesh Singh 	if (!ar) {
6688690ace20SRitesh Singh 		ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d",
6689690ace20SRitesh Singh 			    peer_del_resp.vdev_id);
6690690ace20SRitesh Singh 		rcu_read_unlock();
6691690ace20SRitesh Singh 		return;
6692690ace20SRitesh Singh 	}
6693690ace20SRitesh Singh 
6694690ace20SRitesh Singh 	complete(&ar->peer_delete_done);
6695690ace20SRitesh Singh 	rcu_read_unlock();
6696690ace20SRitesh Singh 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n",
6697690ace20SRitesh Singh 		   peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr);
6698d5c65159SKalle Valo }
6699d5c65159SKalle Valo 
67003cbbdfbeSRitesh Singh static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab,
67013cbbdfbeSRitesh Singh 					  struct sk_buff *skb)
67023cbbdfbeSRitesh Singh {
67033cbbdfbeSRitesh Singh 	struct ath11k *ar;
67043cbbdfbeSRitesh Singh 	u32 vdev_id = 0;
67053cbbdfbeSRitesh Singh 
67063cbbdfbeSRitesh Singh 	if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) {
67073cbbdfbeSRitesh Singh 		ath11k_warn(ab, "failed to extract vdev delete resp");
67083cbbdfbeSRitesh Singh 		return;
67093cbbdfbeSRitesh Singh 	}
67103cbbdfbeSRitesh Singh 
67113cbbdfbeSRitesh Singh 	rcu_read_lock();
67123cbbdfbeSRitesh Singh 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
67133cbbdfbeSRitesh Singh 	if (!ar) {
67143cbbdfbeSRitesh Singh 		ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d",
67153cbbdfbeSRitesh Singh 			    vdev_id);
67163cbbdfbeSRitesh Singh 		rcu_read_unlock();
67173cbbdfbeSRitesh Singh 		return;
67183cbbdfbeSRitesh Singh 	}
67193cbbdfbeSRitesh Singh 
67203cbbdfbeSRitesh Singh 	complete(&ar->vdev_delete_done);
67213cbbdfbeSRitesh Singh 
67223cbbdfbeSRitesh Singh 	rcu_read_unlock();
67233cbbdfbeSRitesh Singh 
67243cbbdfbeSRitesh Singh 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev delete resp for vdev id %d\n",
67253cbbdfbeSRitesh Singh 		   vdev_id);
67263cbbdfbeSRitesh Singh }
67273cbbdfbeSRitesh Singh 
6728d5c65159SKalle Valo static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
6729d5c65159SKalle Valo {
6730d5c65159SKalle Valo 	switch (vdev_resp_status) {
6731d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
6732d5c65159SKalle Valo 		return "invalid vdev id";
6733d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
6734d5c65159SKalle Valo 		return "not supported";
6735d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
6736d5c65159SKalle Valo 		return "dfs violation";
6737d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
6738d5c65159SKalle Valo 		return "invalid regdomain";
6739d5c65159SKalle Valo 	default:
6740d5c65159SKalle Valo 		return "unknown";
6741d5c65159SKalle Valo 	}
6742d5c65159SKalle Valo }
6743d5c65159SKalle Valo 
6744d5c65159SKalle Valo static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
6745d5c65159SKalle Valo {
6746d5c65159SKalle Valo 	struct wmi_vdev_start_resp_event vdev_start_resp;
6747d5c65159SKalle Valo 	struct ath11k *ar;
6748d5c65159SKalle Valo 	u32 status;
6749d5c65159SKalle Valo 
6750d5c65159SKalle Valo 	if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
6751d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev start resp");
6752d5c65159SKalle Valo 		return;
6753d5c65159SKalle Valo 	}
6754d5c65159SKalle Valo 
6755d5c65159SKalle Valo 	rcu_read_lock();
6756d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
6757d5c65159SKalle Valo 	if (!ar) {
6758d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
6759d5c65159SKalle Valo 			    vdev_start_resp.vdev_id);
6760d5c65159SKalle Valo 		rcu_read_unlock();
6761d5c65159SKalle Valo 		return;
6762d5c65159SKalle Valo 	}
6763d5c65159SKalle Valo 
6764d5c65159SKalle Valo 	ar->last_wmi_vdev_start_status = 0;
6765d5c65159SKalle Valo 
6766d5c65159SKalle Valo 	status = vdev_start_resp.status;
6767d5c65159SKalle Valo 
6768d5c65159SKalle Valo 	if (WARN_ON_ONCE(status)) {
6769d5c65159SKalle Valo 		ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
6770d5c65159SKalle Valo 			    status, ath11k_wmi_vdev_resp_print(status));
6771d5c65159SKalle Valo 		ar->last_wmi_vdev_start_status = status;
6772d5c65159SKalle Valo 	}
6773d5c65159SKalle Valo 
6774d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
6775d5c65159SKalle Valo 
6776d5c65159SKalle Valo 	rcu_read_unlock();
6777d5c65159SKalle Valo 
6778d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
6779d5c65159SKalle Valo 		   vdev_start_resp.vdev_id);
6780d5c65159SKalle Valo }
6781d5c65159SKalle Valo 
6782d5c65159SKalle Valo static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
6783d5c65159SKalle Valo {
6784886433a9SJohn Crispin 	struct ath11k_vif *arvif;
6785d5c65159SKalle Valo 	u32 vdev_id, tx_status;
6786d5c65159SKalle Valo 
6787d5c65159SKalle Valo 	if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
6788d5c65159SKalle Valo 					 &vdev_id, &tx_status) != 0) {
6789d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract bcn tx status");
6790d5c65159SKalle Valo 		return;
6791d5c65159SKalle Valo 	}
6792886433a9SJohn Crispin 
679301e782c8SWen Gong 	rcu_read_lock();
6794886433a9SJohn Crispin 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_id);
6795886433a9SJohn Crispin 	if (!arvif) {
6796886433a9SJohn Crispin 		ath11k_warn(ab, "invalid vdev id %d in bcn_tx_status",
6797886433a9SJohn Crispin 			    vdev_id);
679801e782c8SWen Gong 		rcu_read_unlock();
6799886433a9SJohn Crispin 		return;
6800886433a9SJohn Crispin 	}
6801886433a9SJohn Crispin 	ath11k_mac_bcn_tx_event(arvif);
680201e782c8SWen Gong 	rcu_read_unlock();
6803d5c65159SKalle Valo }
6804d5c65159SKalle Valo 
6805d5c65159SKalle Valo static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
6806d5c65159SKalle Valo {
6807d5c65159SKalle Valo 	struct ath11k *ar;
6808d5c65159SKalle Valo 	u32 vdev_id = 0;
6809d5c65159SKalle Valo 
6810d5c65159SKalle Valo 	if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
6811d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev stopped event");
6812d5c65159SKalle Valo 		return;
6813d5c65159SKalle Valo 	}
6814d5c65159SKalle Valo 
6815d5c65159SKalle Valo 	rcu_read_lock();
6816fae0385bSRitesh Singh 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
6817d5c65159SKalle Valo 	if (!ar) {
6818d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
6819d5c65159SKalle Valo 			    vdev_id);
6820d5c65159SKalle Valo 		rcu_read_unlock();
6821d5c65159SKalle Valo 		return;
6822d5c65159SKalle Valo 	}
6823d5c65159SKalle Valo 
6824d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
6825d5c65159SKalle Valo 
6826d5c65159SKalle Valo 	rcu_read_unlock();
6827d5c65159SKalle Valo 
6828d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
6829d5c65159SKalle Valo }
6830d5c65159SKalle Valo 
6831d5c65159SKalle Valo static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
6832d5c65159SKalle Valo {
6833d5c65159SKalle Valo 	struct mgmt_rx_event_params rx_ev = {0};
6834d5c65159SKalle Valo 	struct ath11k *ar;
6835d5c65159SKalle Valo 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
6836d5c65159SKalle Valo 	struct ieee80211_hdr *hdr;
6837d5c65159SKalle Valo 	u16 fc;
6838d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
6839d5c65159SKalle Valo 
6840d5c65159SKalle Valo 	if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
6841d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt rx event");
6842d5c65159SKalle Valo 		dev_kfree_skb(skb);
6843d5c65159SKalle Valo 		return;
6844d5c65159SKalle Valo 	}
6845d5c65159SKalle Valo 
6846d5c65159SKalle Valo 	memset(status, 0, sizeof(*status));
6847d5c65159SKalle Valo 
6848d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n",
6849d5c65159SKalle Valo 		   rx_ev.status);
6850d5c65159SKalle Valo 
6851d5c65159SKalle Valo 	rcu_read_lock();
6852d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
6853d5c65159SKalle Valo 
6854d5c65159SKalle Valo 	if (!ar) {
6855d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
6856d5c65159SKalle Valo 			    rx_ev.pdev_id);
6857d5c65159SKalle Valo 		dev_kfree_skb(skb);
6858d5c65159SKalle Valo 		goto exit;
6859d5c65159SKalle Valo 	}
6860d5c65159SKalle Valo 
6861d5c65159SKalle Valo 	if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
6862d5c65159SKalle Valo 	    (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
6863d5c65159SKalle Valo 	    WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
6864d5c65159SKalle Valo 		dev_kfree_skb(skb);
6865d5c65159SKalle Valo 		goto exit;
6866d5c65159SKalle Valo 	}
6867d5c65159SKalle Valo 
6868d5c65159SKalle Valo 	if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
6869d5c65159SKalle Valo 		status->flag |= RX_FLAG_MMIC_ERROR;
6870d5c65159SKalle Valo 
68719d6ae1f5SPradeep Kumar Chitrapu 	if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ &&
68729d6ae1f5SPradeep Kumar Chitrapu 	    rx_ev.chan_freq <= ATH11K_MAX_6G_FREQ) {
68735dcf42f8SPradeep Kumar Chitrapu 		status->band = NL80211_BAND_6GHZ;
68749d6ae1f5SPradeep Kumar Chitrapu 		status->freq = rx_ev.chan_freq;
68755dcf42f8SPradeep Kumar Chitrapu 	} else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
6876d5c65159SKalle Valo 		status->band = NL80211_BAND_2GHZ;
6877d5c65159SKalle Valo 	} else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
6878d5c65159SKalle Valo 		status->band = NL80211_BAND_5GHZ;
6879d5c65159SKalle Valo 	} else {
6880d5c65159SKalle Valo 		/* Shouldn't happen unless list of advertised channels to
6881d5c65159SKalle Valo 		 * mac80211 has been changed.
6882d5c65159SKalle Valo 		 */
6883d5c65159SKalle Valo 		WARN_ON_ONCE(1);
6884d5c65159SKalle Valo 		dev_kfree_skb(skb);
6885d5c65159SKalle Valo 		goto exit;
6886d5c65159SKalle Valo 	}
6887d5c65159SKalle Valo 
688822eeadcdSPradeep Kumar Chitrapu 	if (rx_ev.phy_mode == MODE_11B &&
688922eeadcdSPradeep Kumar Chitrapu 	    (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
6890d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
689122eeadcdSPradeep Kumar Chitrapu 			   "wmi mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
6892d5c65159SKalle Valo 
6893d5c65159SKalle Valo 	sband = &ar->mac.sbands[status->band];
6894d5c65159SKalle Valo 
68959d6ae1f5SPradeep Kumar Chitrapu 	if (status->band != NL80211_BAND_6GHZ)
6896d5c65159SKalle Valo 		status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
6897d5c65159SKalle Valo 							      status->band);
68989d6ae1f5SPradeep Kumar Chitrapu 
6899d5c65159SKalle Valo 	status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
6900d5c65159SKalle Valo 	status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
6901d5c65159SKalle Valo 
6902d5c65159SKalle Valo 	hdr = (struct ieee80211_hdr *)skb->data;
6903d5c65159SKalle Valo 	fc = le16_to_cpu(hdr->frame_control);
6904d5c65159SKalle Valo 
6905d5c65159SKalle Valo 	/* Firmware is guaranteed to report all essential management frames via
6906d5c65159SKalle Valo 	 * WMI while it can deliver some extra via HTT. Since there can be
6907d5c65159SKalle Valo 	 * duplicates split the reporting wrt monitor/sniffing.
6908d5c65159SKalle Valo 	 */
6909d5c65159SKalle Valo 	status->flag |= RX_FLAG_SKIP_MONITOR;
6910d5c65159SKalle Valo 
6911d5c65159SKalle Valo 	/* In case of PMF, FW delivers decrypted frames with Protected Bit set.
6912d5c65159SKalle Valo 	 * Don't clear that. Also, FW delivers broadcast management frames
6913d5c65159SKalle Valo 	 * (ex: group privacy action frames in mesh) as encrypted payload.
6914d5c65159SKalle Valo 	 */
6915d5c65159SKalle Valo 	if (ieee80211_has_protected(hdr->frame_control) &&
6916d5c65159SKalle Valo 	    !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
6917d5c65159SKalle Valo 		status->flag |= RX_FLAG_DECRYPTED;
6918d5c65159SKalle Valo 
6919d5c65159SKalle Valo 		if (!ieee80211_is_robust_mgmt_frame(skb)) {
6920d5c65159SKalle Valo 			status->flag |= RX_FLAG_IV_STRIPPED |
6921d5c65159SKalle Valo 					RX_FLAG_MMIC_STRIPPED;
6922d5c65159SKalle Valo 			hdr->frame_control = __cpu_to_le16(fc &
6923d5c65159SKalle Valo 					     ~IEEE80211_FCTL_PROTECTED);
6924d5c65159SKalle Valo 		}
6925d5c65159SKalle Valo 	}
6926d5c65159SKalle Valo 
692726f69792SLavanya Suresh 	if (ieee80211_is_beacon(hdr->frame_control))
692826f69792SLavanya Suresh 		ath11k_mac_handle_beacon(ar, skb);
6929d5c65159SKalle Valo 
6930d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
6931d5c65159SKalle Valo 		   "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
6932d5c65159SKalle Valo 		   skb, skb->len,
6933d5c65159SKalle Valo 		   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
6934d5c65159SKalle Valo 
6935d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
6936d5c65159SKalle Valo 		   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
6937d5c65159SKalle Valo 		   status->freq, status->band, status->signal,
6938d5c65159SKalle Valo 		   status->rate_idx);
6939d5c65159SKalle Valo 
6940d5c65159SKalle Valo 	ieee80211_rx_ni(ar->hw, skb);
6941d5c65159SKalle Valo 
6942d5c65159SKalle Valo exit:
6943d5c65159SKalle Valo 	rcu_read_unlock();
6944d5c65159SKalle Valo }
6945d5c65159SKalle Valo 
6946d5c65159SKalle Valo static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
6947d5c65159SKalle Valo {
6948d5c65159SKalle Valo 	struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
6949d5c65159SKalle Valo 	struct ath11k *ar;
6950d5c65159SKalle Valo 
6951d5c65159SKalle Valo 	if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
6952d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt tx compl event");
6953d5c65159SKalle Valo 		return;
6954d5c65159SKalle Valo 	}
6955d5c65159SKalle Valo 
6956d5c65159SKalle Valo 	rcu_read_lock();
6957d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
6958d5c65159SKalle Valo 	if (!ar) {
6959d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
6960d5c65159SKalle Valo 			    tx_compl_param.pdev_id);
6961d5c65159SKalle Valo 		goto exit;
6962d5c65159SKalle Valo 	}
6963d5c65159SKalle Valo 
6964d5c65159SKalle Valo 	wmi_process_mgmt_tx_comp(ar, tx_compl_param.desc_id,
6965d5c65159SKalle Valo 				 tx_compl_param.status);
6966d5c65159SKalle Valo 
6967d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
6968d5c65159SKalle Valo 		   "mgmt tx compl ev pdev_id %d, desc_id %d, status %d",
6969d5c65159SKalle Valo 		   tx_compl_param.pdev_id, tx_compl_param.desc_id,
6970d5c65159SKalle Valo 		   tx_compl_param.status);
6971d5c65159SKalle Valo 
6972d5c65159SKalle Valo exit:
6973d5c65159SKalle Valo 	rcu_read_unlock();
6974d5c65159SKalle Valo }
6975d5c65159SKalle Valo 
6976c677d4b1SWen Gong static struct ath11k *ath11k_get_ar_on_scan_state(struct ath11k_base *ab,
6977c677d4b1SWen Gong 						  u32 vdev_id,
6978c677d4b1SWen Gong 						  enum ath11k_scan_state state)
6979d5c65159SKalle Valo {
6980d5c65159SKalle Valo 	int i;
6981d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
6982d5c65159SKalle Valo 	struct ath11k *ar;
6983d5c65159SKalle Valo 
6984d5c65159SKalle Valo 	for (i = 0; i < ab->num_radios; i++) {
6985d5c65159SKalle Valo 		pdev = rcu_dereference(ab->pdevs_active[i]);
6986d5c65159SKalle Valo 		if (pdev && pdev->ar) {
6987d5c65159SKalle Valo 			ar = pdev->ar;
6988d5c65159SKalle Valo 
6989d5c65159SKalle Valo 			spin_lock_bh(&ar->data_lock);
6990c677d4b1SWen Gong 			if (ar->scan.state == state &&
6991d5c65159SKalle Valo 			    ar->scan.vdev_id == vdev_id) {
6992d5c65159SKalle Valo 				spin_unlock_bh(&ar->data_lock);
6993d5c65159SKalle Valo 				return ar;
6994d5c65159SKalle Valo 			}
6995d5c65159SKalle Valo 			spin_unlock_bh(&ar->data_lock);
6996d5c65159SKalle Valo 		}
6997d5c65159SKalle Valo 	}
6998d5c65159SKalle Valo 	return NULL;
6999d5c65159SKalle Valo }
7000d5c65159SKalle Valo 
7001d5c65159SKalle Valo static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
7002d5c65159SKalle Valo {
7003d5c65159SKalle Valo 	struct ath11k *ar;
7004d5c65159SKalle Valo 	struct wmi_scan_event scan_ev = {0};
7005d5c65159SKalle Valo 
7006d5c65159SKalle Valo 	if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
7007d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract scan event");
7008d5c65159SKalle Valo 		return;
7009d5c65159SKalle Valo 	}
7010d5c65159SKalle Valo 
7011d5c65159SKalle Valo 	rcu_read_lock();
7012d5c65159SKalle Valo 
7013d5c65159SKalle Valo 	/* In case the scan was cancelled, ex. during interface teardown,
7014d5c65159SKalle Valo 	 * the interface will not be found in active interfaces.
7015d5c65159SKalle Valo 	 * Rather, in such scenarios, iterate over the active pdev's to
7016d5c65159SKalle Valo 	 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
7017d5c65159SKalle Valo 	 * aborting scan's vdev id matches this event info.
7018d5c65159SKalle Valo 	 */
7019d5c65159SKalle Valo 	if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
7020c677d4b1SWen Gong 	    scan_ev.reason == WMI_SCAN_REASON_CANCELLED) {
7021c677d4b1SWen Gong 		ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7022c677d4b1SWen Gong 						 ATH11K_SCAN_ABORTING);
7023c677d4b1SWen Gong 		if (!ar)
7024c677d4b1SWen Gong 			ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7025c677d4b1SWen Gong 							 ATH11K_SCAN_RUNNING);
7026c677d4b1SWen Gong 	} else {
7027d5c65159SKalle Valo 		ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
7028c677d4b1SWen Gong 	}
7029d5c65159SKalle Valo 
7030d5c65159SKalle Valo 	if (!ar) {
7031d5c65159SKalle Valo 		ath11k_warn(ab, "Received scan event for unknown vdev");
7032d5c65159SKalle Valo 		rcu_read_unlock();
7033d5c65159SKalle Valo 		return;
7034d5c65159SKalle Valo 	}
7035d5c65159SKalle Valo 
7036d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
7037d5c65159SKalle Valo 
7038d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7039d5c65159SKalle Valo 		   "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
7040d5c65159SKalle Valo 		   ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
7041d5c65159SKalle Valo 		   scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
7042d5c65159SKalle Valo 		   scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
7043d5c65159SKalle Valo 		   ath11k_scan_state_str(ar->scan.state), ar->scan.state);
7044d5c65159SKalle Valo 
7045d5c65159SKalle Valo 	switch (scan_ev.event_type) {
7046d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
7047d5c65159SKalle Valo 		ath11k_wmi_event_scan_started(ar);
7048d5c65159SKalle Valo 		break;
7049d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
7050d5c65159SKalle Valo 		ath11k_wmi_event_scan_completed(ar);
7051d5c65159SKalle Valo 		break;
7052d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
7053d5c65159SKalle Valo 		ath11k_wmi_event_scan_bss_chan(ar);
7054d5c65159SKalle Valo 		break;
7055d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
7056d5c65159SKalle Valo 		ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
7057d5c65159SKalle Valo 		break;
7058d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
7059d5c65159SKalle Valo 		ath11k_warn(ab, "received scan start failure event\n");
7060d5c65159SKalle Valo 		ath11k_wmi_event_scan_start_failed(ar);
7061d5c65159SKalle Valo 		break;
7062d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
7063441b3b59SWen Gong 		__ath11k_mac_scan_finish(ar);
7064441b3b59SWen Gong 		break;
7065d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
7066d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
7067d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
7068d5c65159SKalle Valo 	default:
7069d5c65159SKalle Valo 		break;
7070d5c65159SKalle Valo 	}
7071d5c65159SKalle Valo 
7072d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
7073d5c65159SKalle Valo 
7074d5c65159SKalle Valo 	rcu_read_unlock();
7075d5c65159SKalle Valo }
7076d5c65159SKalle Valo 
7077d5c65159SKalle Valo static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
7078d5c65159SKalle Valo {
7079d5c65159SKalle Valo 	struct wmi_peer_sta_kickout_arg arg = {};
7080d5c65159SKalle Valo 	struct ieee80211_sta *sta;
7081d5c65159SKalle Valo 	struct ath11k_peer *peer;
7082d5c65159SKalle Valo 	struct ath11k *ar;
70834c375743SKarthikeyan Periyasamy 	u32 vdev_id;
7084d5c65159SKalle Valo 
7085d5c65159SKalle Valo 	if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
7086d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer sta kickout event");
7087d5c65159SKalle Valo 		return;
7088d5c65159SKalle Valo 	}
7089d5c65159SKalle Valo 
7090d5c65159SKalle Valo 	rcu_read_lock();
7091d5c65159SKalle Valo 
7092d5c65159SKalle Valo 	spin_lock_bh(&ab->base_lock);
7093d5c65159SKalle Valo 
7094d5c65159SKalle Valo 	peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
7095d5c65159SKalle Valo 
7096d5c65159SKalle Valo 	if (!peer) {
7097d5c65159SKalle Valo 		ath11k_warn(ab, "peer not found %pM\n",
7098d5c65159SKalle Valo 			    arg.mac_addr);
70994c375743SKarthikeyan Periyasamy 		spin_unlock_bh(&ab->base_lock);
7100d5c65159SKalle Valo 		goto exit;
7101d5c65159SKalle Valo 	}
7102d5c65159SKalle Valo 
71034c375743SKarthikeyan Periyasamy 	vdev_id = peer->vdev_id;
71044c375743SKarthikeyan Periyasamy 
71054c375743SKarthikeyan Periyasamy 	spin_unlock_bh(&ab->base_lock);
71064c375743SKarthikeyan Periyasamy 
71074c375743SKarthikeyan Periyasamy 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7108d5c65159SKalle Valo 	if (!ar) {
7109d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
7110d5c65159SKalle Valo 			    peer->vdev_id);
7111d5c65159SKalle Valo 		goto exit;
7112d5c65159SKalle Valo 	}
7113d5c65159SKalle Valo 
7114d5c65159SKalle Valo 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
7115d5c65159SKalle Valo 					   arg.mac_addr, NULL);
7116d5c65159SKalle Valo 	if (!sta) {
7117d5c65159SKalle Valo 		ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
7118d5c65159SKalle Valo 			    arg.mac_addr);
7119d5c65159SKalle Valo 		goto exit;
7120d5c65159SKalle Valo 	}
7121d5c65159SKalle Valo 
7122d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM",
7123d5c65159SKalle Valo 		   arg.mac_addr);
7124d5c65159SKalle Valo 
7125d5c65159SKalle Valo 	ieee80211_report_low_ack(sta, 10);
7126d5c65159SKalle Valo 
7127d5c65159SKalle Valo exit:
7128d5c65159SKalle Valo 	rcu_read_unlock();
7129d5c65159SKalle Valo }
7130d5c65159SKalle Valo 
7131d5c65159SKalle Valo static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
7132d5c65159SKalle Valo {
7133d5c65159SKalle Valo 	struct wmi_roam_event roam_ev = {};
7134d5c65159SKalle Valo 	struct ath11k *ar;
7135d5c65159SKalle Valo 
7136d5c65159SKalle Valo 	if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
7137d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract roam event");
7138d5c65159SKalle Valo 		return;
7139d5c65159SKalle Valo 	}
7140d5c65159SKalle Valo 
7141d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7142d5c65159SKalle Valo 		   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
7143d5c65159SKalle Valo 		   roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
7144d5c65159SKalle Valo 
7145d5c65159SKalle Valo 	rcu_read_lock();
7146d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
7147d5c65159SKalle Valo 	if (!ar) {
7148d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in roam ev %d",
7149d5c65159SKalle Valo 			    roam_ev.vdev_id);
7150d5c65159SKalle Valo 		rcu_read_unlock();
7151d5c65159SKalle Valo 		return;
7152d5c65159SKalle Valo 	}
7153d5c65159SKalle Valo 
7154d5c65159SKalle Valo 	if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
7155d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
7156d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
7157d5c65159SKalle Valo 
7158d5c65159SKalle Valo 	switch (roam_ev.reason) {
7159d5c65159SKalle Valo 	case WMI_ROAM_REASON_BEACON_MISS:
716026f69792SLavanya Suresh 		ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id);
7161d5c65159SKalle Valo 		break;
7162d5c65159SKalle Valo 	case WMI_ROAM_REASON_BETTER_AP:
7163d5c65159SKalle Valo 	case WMI_ROAM_REASON_LOW_RSSI:
7164d5c65159SKalle Valo 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
7165d5c65159SKalle Valo 	case WMI_ROAM_REASON_HO_FAILED:
7166d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
7167d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
7168d5c65159SKalle Valo 		break;
7169d5c65159SKalle Valo 	}
7170d5c65159SKalle Valo 
7171d5c65159SKalle Valo 	rcu_read_unlock();
7172d5c65159SKalle Valo }
7173d5c65159SKalle Valo 
7174d5c65159SKalle Valo static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7175d5c65159SKalle Valo {
7176d5c65159SKalle Valo 	struct wmi_chan_info_event ch_info_ev = {0};
7177d5c65159SKalle Valo 	struct ath11k *ar;
7178d5c65159SKalle Valo 	struct survey_info *survey;
7179d5c65159SKalle Valo 	int idx;
7180d5c65159SKalle Valo 	/* HW channel counters frequency value in hertz */
7181d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
7182d5c65159SKalle Valo 
7183d5c65159SKalle Valo 	if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
7184d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract chan info event");
7185d5c65159SKalle Valo 		return;
7186d5c65159SKalle Valo 	}
7187d5c65159SKalle Valo 
7188d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7189d5c65159SKalle Valo 		   "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",
7190d5c65159SKalle Valo 		   ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
7191d5c65159SKalle Valo 		   ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
7192d5c65159SKalle Valo 		   ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
7193d5c65159SKalle Valo 		   ch_info_ev.mac_clk_mhz);
7194d5c65159SKalle Valo 
7195d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
7196d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
7197d5c65159SKalle Valo 		return;
7198d5c65159SKalle Valo 	}
7199d5c65159SKalle Valo 
7200d5c65159SKalle Valo 	rcu_read_lock();
7201d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
7202d5c65159SKalle Valo 	if (!ar) {
7203d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in chan info ev %d",
7204d5c65159SKalle Valo 			    ch_info_ev.vdev_id);
7205d5c65159SKalle Valo 		rcu_read_unlock();
7206d5c65159SKalle Valo 		return;
7207d5c65159SKalle Valo 	}
7208d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
7209d5c65159SKalle Valo 
7210d5c65159SKalle Valo 	switch (ar->scan.state) {
7211d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
7212d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
7213d5c65159SKalle Valo 		ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
7214d5c65159SKalle Valo 		goto exit;
7215d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
7216d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
7217d5c65159SKalle Valo 		break;
7218d5c65159SKalle Valo 	}
7219d5c65159SKalle Valo 
7220d5c65159SKalle Valo 	idx = freq_to_idx(ar, ch_info_ev.freq);
7221d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
7222d5c65159SKalle Valo 		ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
7223d5c65159SKalle Valo 			    ch_info_ev.freq, idx);
7224d5c65159SKalle Valo 		goto exit;
7225d5c65159SKalle Valo 	}
7226d5c65159SKalle Valo 
7227d5c65159SKalle Valo 	/* If FW provides MAC clock frequency in Mhz, overriding the initialized
7228d5c65159SKalle Valo 	 * HW channel counters frequency value
7229d5c65159SKalle Valo 	 */
7230d5c65159SKalle Valo 	if (ch_info_ev.mac_clk_mhz)
7231d5c65159SKalle Valo 		cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
7232d5c65159SKalle Valo 
7233d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
7234d5c65159SKalle Valo 		survey = &ar->survey[idx];
7235d5c65159SKalle Valo 		memset(survey, 0, sizeof(*survey));
7236d5c65159SKalle Valo 		survey->noise = ch_info_ev.noise_floor;
7237d5c65159SKalle Valo 		survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
7238d5c65159SKalle Valo 				 SURVEY_INFO_TIME_BUSY;
7239d5c65159SKalle Valo 		survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
7240d5c65159SKalle Valo 		survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
7241d5c65159SKalle Valo 	}
7242d5c65159SKalle Valo exit:
7243d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
7244d5c65159SKalle Valo 	rcu_read_unlock();
7245d5c65159SKalle Valo }
7246d5c65159SKalle Valo 
7247d5c65159SKalle Valo static void
7248d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7249d5c65159SKalle Valo {
7250d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
7251d5c65159SKalle Valo 	struct survey_info *survey;
7252d5c65159SKalle Valo 	struct ath11k *ar;
7253d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
7254d5c65159SKalle Valo 	u64 busy, total, tx, rx, rx_bss;
7255d5c65159SKalle Valo 	int idx;
7256d5c65159SKalle Valo 
7257d5c65159SKalle Valo 	if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
7258d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract pdev bss chan info event");
7259d5c65159SKalle Valo 		return;
7260d5c65159SKalle Valo 	}
7261d5c65159SKalle Valo 
7262d5c65159SKalle Valo 	busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
7263d5c65159SKalle Valo 			bss_ch_info_ev.rx_clear_count_low;
7264d5c65159SKalle Valo 
7265d5c65159SKalle Valo 	total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
7266d5c65159SKalle Valo 			bss_ch_info_ev.cycle_count_low;
7267d5c65159SKalle Valo 
7268d5c65159SKalle Valo 	tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
7269d5c65159SKalle Valo 			bss_ch_info_ev.tx_cycle_count_low;
7270d5c65159SKalle Valo 
7271d5c65159SKalle Valo 	rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
7272d5c65159SKalle Valo 			bss_ch_info_ev.rx_cycle_count_low;
7273d5c65159SKalle Valo 
7274d5c65159SKalle Valo 	rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
7275d5c65159SKalle Valo 			bss_ch_info_ev.rx_bss_cycle_count_low;
7276d5c65159SKalle Valo 
7277d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7278d5c65159SKalle Valo 		   "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",
7279d5c65159SKalle Valo 		   bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
7280d5c65159SKalle Valo 		   bss_ch_info_ev.noise_floor, busy, total,
7281d5c65159SKalle Valo 		   tx, rx, rx_bss);
7282d5c65159SKalle Valo 
7283d5c65159SKalle Valo 	rcu_read_lock();
7284d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
7285d5c65159SKalle Valo 
7286d5c65159SKalle Valo 	if (!ar) {
7287d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
7288d5c65159SKalle Valo 			    bss_ch_info_ev.pdev_id);
7289d5c65159SKalle Valo 		rcu_read_unlock();
7290d5c65159SKalle Valo 		return;
7291d5c65159SKalle Valo 	}
7292d5c65159SKalle Valo 
7293d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
7294d5c65159SKalle Valo 	idx = freq_to_idx(ar, bss_ch_info_ev.freq);
7295d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
7296d5c65159SKalle Valo 		ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
7297d5c65159SKalle Valo 			    bss_ch_info_ev.freq, idx);
7298d5c65159SKalle Valo 		goto exit;
7299d5c65159SKalle Valo 	}
7300d5c65159SKalle Valo 
7301d5c65159SKalle Valo 	survey = &ar->survey[idx];
7302d5c65159SKalle Valo 
7303d5c65159SKalle Valo 	survey->noise     = bss_ch_info_ev.noise_floor;
7304d5c65159SKalle Valo 	survey->time      = div_u64(total, cc_freq_hz);
7305d5c65159SKalle Valo 	survey->time_busy = div_u64(busy, cc_freq_hz);
7306d5c65159SKalle Valo 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
7307d5c65159SKalle Valo 	survey->time_tx   = div_u64(tx, cc_freq_hz);
7308d5c65159SKalle Valo 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
7309d5c65159SKalle Valo 			     SURVEY_INFO_TIME |
7310d5c65159SKalle Valo 			     SURVEY_INFO_TIME_BUSY |
7311d5c65159SKalle Valo 			     SURVEY_INFO_TIME_RX |
7312d5c65159SKalle Valo 			     SURVEY_INFO_TIME_TX);
7313d5c65159SKalle Valo exit:
7314d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
7315d5c65159SKalle Valo 	complete(&ar->bss_survey_done);
7316d5c65159SKalle Valo 
7317d5c65159SKalle Valo 	rcu_read_unlock();
7318d5c65159SKalle Valo }
7319d5c65159SKalle Valo 
7320d5c65159SKalle Valo static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
7321d5c65159SKalle Valo 						struct sk_buff *skb)
7322d5c65159SKalle Valo {
7323d5c65159SKalle Valo 	struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
7324d5c65159SKalle Valo 	struct ath11k *ar;
7325d5c65159SKalle Valo 
7326d5c65159SKalle Valo 	if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
7327d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract install key compl event");
7328d5c65159SKalle Valo 		return;
7329d5c65159SKalle Valo 	}
7330d5c65159SKalle Valo 
7331d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7332d5c65159SKalle Valo 		   "vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
7333d5c65159SKalle Valo 		   install_key_compl.key_idx, install_key_compl.key_flags,
7334d5c65159SKalle Valo 		   install_key_compl.macaddr, install_key_compl.status);
7335d5c65159SKalle Valo 
7336d5c65159SKalle Valo 	rcu_read_lock();
7337d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
7338d5c65159SKalle Valo 	if (!ar) {
7339d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
7340d5c65159SKalle Valo 			    install_key_compl.vdev_id);
7341d5c65159SKalle Valo 		rcu_read_unlock();
7342d5c65159SKalle Valo 		return;
7343d5c65159SKalle Valo 	}
7344d5c65159SKalle Valo 
7345d5c65159SKalle Valo 	ar->install_key_status = 0;
7346d5c65159SKalle Valo 
7347d5c65159SKalle Valo 	if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
7348d5c65159SKalle Valo 		ath11k_warn(ab, "install key failed for %pM status %d\n",
7349d5c65159SKalle Valo 			    install_key_compl.macaddr, install_key_compl.status);
7350d5c65159SKalle Valo 		ar->install_key_status = install_key_compl.status;
7351d5c65159SKalle Valo 	}
7352d5c65159SKalle Valo 
7353d5c65159SKalle Valo 	complete(&ar->install_key_done);
7354d5c65159SKalle Valo 	rcu_read_unlock();
7355d5c65159SKalle Valo }
7356d5c65159SKalle Valo 
7357e2e23a79SWen Gong static int  ath11k_wmi_tlv_services_parser(struct ath11k_base *ab,
7358e2e23a79SWen Gong 					   u16 tag, u16 len,
7359e2e23a79SWen Gong 					   const void *ptr, void *data)
7360d5c65159SKalle Valo {
7361d5c65159SKalle Valo 	const struct wmi_service_available_event *ev;
7362e2e23a79SWen Gong 	u32 *wmi_ext2_service_bitmap;
7363d5c65159SKalle Valo 	int i, j;
7364d5c65159SKalle Valo 
7365e2e23a79SWen Gong 	switch (tag) {
7366e2e23a79SWen Gong 	case WMI_TAG_SERVICE_AVAILABLE_EVENT:
7367e2e23a79SWen Gong 		ev = (struct wmi_service_available_event *)ptr;
7368d5c65159SKalle Valo 		for (i = 0, j = WMI_MAX_SERVICE;
7369d5c65159SKalle Valo 			i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
7370d5c65159SKalle Valo 			i++) {
7371d5c65159SKalle Valo 			do {
7372d5c65159SKalle Valo 				if (ev->wmi_service_segment_bitmap[i] &
7373d5c65159SKalle Valo 				    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
73746bc9d6f7SJohn Crispin 					set_bit(j, ab->wmi_ab.svc_map);
7375d5c65159SKalle Valo 			} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
7376d5c65159SKalle Valo 		}
7377d5c65159SKalle Valo 
7378d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
7379e2e23a79SWen Gong 			   "wmi_ext_service_bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
7380e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[0],
7381e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[1],
7382e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[2],
7383e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[3]);
7384e2e23a79SWen Gong 		break;
7385e2e23a79SWen Gong 	case WMI_TAG_ARRAY_UINT32:
7386e2e23a79SWen Gong 		wmi_ext2_service_bitmap = (u32 *)ptr;
7387e2e23a79SWen Gong 		for (i = 0, j = WMI_MAX_EXT_SERVICE;
7388e2e23a79SWen Gong 			i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT2_SERVICE;
7389e2e23a79SWen Gong 			i++) {
7390e2e23a79SWen Gong 			do {
7391e2e23a79SWen Gong 				if (wmi_ext2_service_bitmap[i] &
7392e2e23a79SWen Gong 				    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
7393e2e23a79SWen Gong 					set_bit(j, ab->wmi_ab.svc_map);
7394e2e23a79SWen Gong 			} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
7395e2e23a79SWen Gong 		}
7396d5c65159SKalle Valo 
7397e2e23a79SWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
7398e2e23a79SWen Gong 			   "wmi_ext2_service__bitmap  0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
7399e2e23a79SWen Gong 			   wmi_ext2_service_bitmap[0], wmi_ext2_service_bitmap[1],
7400e2e23a79SWen Gong 			   wmi_ext2_service_bitmap[2], wmi_ext2_service_bitmap[3]);
7401e2e23a79SWen Gong 		break;
7402e2e23a79SWen Gong 	}
7403e2e23a79SWen Gong 	return 0;
7404e2e23a79SWen Gong }
7405e2e23a79SWen Gong 
7406e2e23a79SWen Gong static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
7407e2e23a79SWen Gong {
7408e2e23a79SWen Gong 	int ret;
7409e2e23a79SWen Gong 
7410e2e23a79SWen Gong 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7411e2e23a79SWen Gong 				  ath11k_wmi_tlv_services_parser,
7412e2e23a79SWen Gong 				  NULL);
7413e2e23a79SWen Gong 	if (ret)
7414e2e23a79SWen Gong 		ath11k_warn(ab, "failed to parse services available tlv %d\n", ret);
7415d5c65159SKalle Valo }
7416d5c65159SKalle Valo 
7417d5c65159SKalle Valo static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
7418d5c65159SKalle Valo {
7419d5c65159SKalle Valo 	struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
7420d5c65159SKalle Valo 	struct ath11k *ar;
7421d5c65159SKalle Valo 
7422d5c65159SKalle Valo 	if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
7423d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer assoc conf event");
7424d5c65159SKalle Valo 		return;
7425d5c65159SKalle Valo 	}
7426d5c65159SKalle Valo 
7427d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7428d5c65159SKalle Valo 		   "peer assoc conf ev vdev id %d macaddr %pM\n",
7429d5c65159SKalle Valo 		   peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
7430d5c65159SKalle Valo 
7431db0889abSKarthikeyan Periyasamy 	rcu_read_lock();
7432d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
7433d5c65159SKalle Valo 
7434d5c65159SKalle Valo 	if (!ar) {
7435d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
7436d5c65159SKalle Valo 			    peer_assoc_conf.vdev_id);
7437db0889abSKarthikeyan Periyasamy 		rcu_read_unlock();
7438d5c65159SKalle Valo 		return;
7439d5c65159SKalle Valo 	}
7440d5c65159SKalle Valo 
7441d5c65159SKalle Valo 	complete(&ar->peer_assoc_done);
7442db0889abSKarthikeyan Periyasamy 	rcu_read_unlock();
7443d5c65159SKalle Valo }
7444d5c65159SKalle Valo 
7445d5c65159SKalle Valo static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
7446d5c65159SKalle Valo {
7447cb4e57dbSKalle Valo 	ath11k_debugfs_fw_stats_process(ab, skb);
7448d5c65159SKalle Valo }
7449d5c65159SKalle Valo 
7450d5c65159SKalle Valo /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
7451d5c65159SKalle Valo  * is not part of BDF CTL(Conformance test limits) table entries.
7452d5c65159SKalle Valo  */
7453d5c65159SKalle Valo static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
7454d5c65159SKalle Valo 						 struct sk_buff *skb)
7455d5c65159SKalle Valo {
7456d5c65159SKalle Valo 	const void **tb;
7457d5c65159SKalle Valo 	const struct wmi_pdev_ctl_failsafe_chk_event *ev;
7458d5c65159SKalle Valo 	int ret;
7459d5c65159SKalle Valo 
7460d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7461d5c65159SKalle Valo 	if (IS_ERR(tb)) {
7462d5c65159SKalle Valo 		ret = PTR_ERR(tb);
7463d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7464d5c65159SKalle Valo 		return;
7465d5c65159SKalle Valo 	}
7466d5c65159SKalle Valo 
7467d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
7468d5c65159SKalle Valo 	if (!ev) {
7469d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
7470d5c65159SKalle Valo 		kfree(tb);
7471d5c65159SKalle Valo 		return;
7472d5c65159SKalle Valo 	}
7473d5c65159SKalle Valo 
7474d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7475d5c65159SKalle Valo 		   "pdev ctl failsafe check ev status %d\n",
7476d5c65159SKalle Valo 		   ev->ctl_failsafe_status);
7477d5c65159SKalle Valo 
7478d5c65159SKalle Valo 	/* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
7479d5c65159SKalle Valo 	 * to 10 dBm else the CTL power entry in the BDF would be picked up.
7480d5c65159SKalle Valo 	 */
7481d5c65159SKalle Valo 	if (ev->ctl_failsafe_status != 0)
7482d5c65159SKalle Valo 		ath11k_warn(ab, "pdev ctl failsafe failure status %d",
7483d5c65159SKalle Valo 			    ev->ctl_failsafe_status);
7484d5c65159SKalle Valo 
7485d5c65159SKalle Valo 	kfree(tb);
7486d5c65159SKalle Valo }
7487d5c65159SKalle Valo 
7488d5c65159SKalle Valo static void
7489d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
7490d5c65159SKalle Valo 					  const struct wmi_pdev_csa_switch_ev *ev,
7491d5c65159SKalle Valo 					  const u32 *vdev_ids)
7492d5c65159SKalle Valo {
7493d5c65159SKalle Valo 	int i;
7494d5c65159SKalle Valo 	struct ath11k_vif *arvif;
7495d5c65159SKalle Valo 
7496d5c65159SKalle Valo 	/* Finish CSA once the switch count becomes NULL */
7497d5c65159SKalle Valo 	if (ev->current_switch_count)
7498d5c65159SKalle Valo 		return;
7499d5c65159SKalle Valo 
7500d5c65159SKalle Valo 	rcu_read_lock();
7501d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdevs; i++) {
7502d5c65159SKalle Valo 		arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
7503d5c65159SKalle Valo 
7504d5c65159SKalle Valo 		if (!arvif) {
7505d5c65159SKalle Valo 			ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
7506d5c65159SKalle Valo 				    vdev_ids[i]);
7507d5c65159SKalle Valo 			continue;
7508d5c65159SKalle Valo 		}
7509d5c65159SKalle Valo 
7510d0a9123eSJohannes Berg 		if (arvif->is_up && arvif->vif->bss_conf.csa_active)
7511d5c65159SKalle Valo 			ieee80211_csa_finish(arvif->vif);
7512d5c65159SKalle Valo 	}
7513d5c65159SKalle Valo 	rcu_read_unlock();
7514d5c65159SKalle Valo }
7515d5c65159SKalle Valo 
7516d5c65159SKalle Valo static void
7517d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
7518d5c65159SKalle Valo 					      struct sk_buff *skb)
7519d5c65159SKalle Valo {
7520d5c65159SKalle Valo 	const void **tb;
7521d5c65159SKalle Valo 	const struct wmi_pdev_csa_switch_ev *ev;
7522d5c65159SKalle Valo 	const u32 *vdev_ids;
7523d5c65159SKalle Valo 	int ret;
7524d5c65159SKalle Valo 
7525d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7526d5c65159SKalle Valo 	if (IS_ERR(tb)) {
7527d5c65159SKalle Valo 		ret = PTR_ERR(tb);
7528d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7529d5c65159SKalle Valo 		return;
7530d5c65159SKalle Valo 	}
7531d5c65159SKalle Valo 
7532d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
7533d5c65159SKalle Valo 	vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
7534d5c65159SKalle Valo 
7535d5c65159SKalle Valo 	if (!ev || !vdev_ids) {
7536d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
7537d5c65159SKalle Valo 		kfree(tb);
7538d5c65159SKalle Valo 		return;
7539d5c65159SKalle Valo 	}
7540d5c65159SKalle Valo 
7541d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7542d5c65159SKalle Valo 		   "pdev csa switch count %d for pdev %d, num_vdevs %d",
7543d5c65159SKalle Valo 		   ev->current_switch_count, ev->pdev_id,
7544d5c65159SKalle Valo 		   ev->num_vdevs);
7545d5c65159SKalle Valo 
7546d5c65159SKalle Valo 	ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
7547d5c65159SKalle Valo 
7548d5c65159SKalle Valo 	kfree(tb);
7549d5c65159SKalle Valo }
7550d5c65159SKalle Valo 
7551d5c65159SKalle Valo static void
7552d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
7553d5c65159SKalle Valo {
7554d5c65159SKalle Valo 	const void **tb;
7555d5c65159SKalle Valo 	const struct wmi_pdev_radar_ev *ev;
7556d5c65159SKalle Valo 	struct ath11k *ar;
7557d5c65159SKalle Valo 	int ret;
7558d5c65159SKalle Valo 
7559d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7560d5c65159SKalle Valo 	if (IS_ERR(tb)) {
7561d5c65159SKalle Valo 		ret = PTR_ERR(tb);
7562d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7563d5c65159SKalle Valo 		return;
7564d5c65159SKalle Valo 	}
7565d5c65159SKalle Valo 
7566d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
7567d5c65159SKalle Valo 
7568d5c65159SKalle Valo 	if (!ev) {
7569d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
7570d5c65159SKalle Valo 		kfree(tb);
7571d5c65159SKalle Valo 		return;
7572d5c65159SKalle Valo 	}
7573d5c65159SKalle Valo 
7574d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7575d5c65159SKalle Valo 		   "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",
7576d5c65159SKalle Valo 		   ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
7577d5c65159SKalle Valo 		   ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
7578d5c65159SKalle Valo 		   ev->freq_offset, ev->sidx);
7579d5c65159SKalle Valo 
7580d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
7581d5c65159SKalle Valo 
7582d5c65159SKalle Valo 	if (!ar) {
7583d5c65159SKalle Valo 		ath11k_warn(ab, "radar detected in invalid pdev %d\n",
7584d5c65159SKalle Valo 			    ev->pdev_id);
7585d5c65159SKalle Valo 		goto exit;
7586d5c65159SKalle Valo 	}
7587d5c65159SKalle Valo 
7588d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
7589d5c65159SKalle Valo 		   ev->pdev_id);
7590d5c65159SKalle Valo 
7591d5c65159SKalle Valo 	if (ar->dfs_block_radar_events)
7592d5c65159SKalle Valo 		ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
7593d5c65159SKalle Valo 	else
7594d5c65159SKalle Valo 		ieee80211_radar_detected(ar->hw);
7595d5c65159SKalle Valo 
7596d5c65159SKalle Valo exit:
7597d5c65159SKalle Valo 	kfree(tb);
7598d5c65159SKalle Valo }
7599d5c65159SKalle Valo 
7600a41d1034SPradeep Kumar Chitrapu static void
7601a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
7602a41d1034SPradeep Kumar Chitrapu 				  struct sk_buff *skb)
7603a41d1034SPradeep Kumar Chitrapu {
7604a41d1034SPradeep Kumar Chitrapu 	struct ath11k *ar;
7605e3de5bb7SPradeep Kumar Chitrapu 	const void **tb;
7606e3de5bb7SPradeep Kumar Chitrapu 	const struct wmi_pdev_temperature_event *ev;
7607e3de5bb7SPradeep Kumar Chitrapu 	int ret;
7608a41d1034SPradeep Kumar Chitrapu 
7609e3de5bb7SPradeep Kumar Chitrapu 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7610e3de5bb7SPradeep Kumar Chitrapu 	if (IS_ERR(tb)) {
7611e3de5bb7SPradeep Kumar Chitrapu 		ret = PTR_ERR(tb);
7612e3de5bb7SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7613e3de5bb7SPradeep Kumar Chitrapu 		return;
7614e3de5bb7SPradeep Kumar Chitrapu 	}
7615e3de5bb7SPradeep Kumar Chitrapu 
7616e3de5bb7SPradeep Kumar Chitrapu 	ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
7617e3de5bb7SPradeep Kumar Chitrapu 	if (!ev) {
7618e3de5bb7SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to fetch pdev temp ev");
7619e3de5bb7SPradeep Kumar Chitrapu 		kfree(tb);
7620a41d1034SPradeep Kumar Chitrapu 		return;
7621a41d1034SPradeep Kumar Chitrapu 	}
7622a41d1034SPradeep Kumar Chitrapu 
7623a41d1034SPradeep Kumar Chitrapu 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7624e3de5bb7SPradeep Kumar Chitrapu 		   "pdev temperature ev temp %d pdev_id %d\n", ev->temp, ev->pdev_id);
7625a41d1034SPradeep Kumar Chitrapu 
7626e3de5bb7SPradeep Kumar Chitrapu 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
7627a41d1034SPradeep Kumar Chitrapu 	if (!ar) {
7628e3de5bb7SPradeep Kumar Chitrapu 		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
7629e3de5bb7SPradeep Kumar Chitrapu 		kfree(tb);
7630a41d1034SPradeep Kumar Chitrapu 		return;
7631a41d1034SPradeep Kumar Chitrapu 	}
7632a41d1034SPradeep Kumar Chitrapu 
7633e3de5bb7SPradeep Kumar Chitrapu 	ath11k_thermal_event_temperature(ar, ev->temp);
7634e3de5bb7SPradeep Kumar Chitrapu 
7635e3de5bb7SPradeep Kumar Chitrapu 	kfree(tb);
7636a41d1034SPradeep Kumar Chitrapu }
7637a41d1034SPradeep Kumar Chitrapu 
7638047679e3SAloka Dixit static void ath11k_fils_discovery_event(struct ath11k_base *ab,
7639047679e3SAloka Dixit 					struct sk_buff *skb)
7640047679e3SAloka Dixit {
7641047679e3SAloka Dixit 	const void **tb;
7642047679e3SAloka Dixit 	const struct wmi_fils_discovery_event *ev;
7643047679e3SAloka Dixit 	int ret;
7644047679e3SAloka Dixit 
7645047679e3SAloka Dixit 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7646047679e3SAloka Dixit 	if (IS_ERR(tb)) {
7647047679e3SAloka Dixit 		ret = PTR_ERR(tb);
7648047679e3SAloka Dixit 		ath11k_warn(ab,
7649047679e3SAloka Dixit 			    "failed to parse FILS discovery event tlv %d\n",
7650047679e3SAloka Dixit 			    ret);
7651047679e3SAloka Dixit 		return;
7652047679e3SAloka Dixit 	}
7653047679e3SAloka Dixit 
7654047679e3SAloka Dixit 	ev = tb[WMI_TAG_HOST_SWFDA_EVENT];
7655047679e3SAloka Dixit 	if (!ev) {
7656047679e3SAloka Dixit 		ath11k_warn(ab, "failed to fetch FILS discovery event\n");
7657047679e3SAloka Dixit 		kfree(tb);
7658047679e3SAloka Dixit 		return;
7659047679e3SAloka Dixit 	}
7660047679e3SAloka Dixit 
7661047679e3SAloka Dixit 	ath11k_warn(ab,
7662047679e3SAloka Dixit 		    "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n",
7663047679e3SAloka Dixit 		    ev->vdev_id, ev->fils_tt, ev->tbtt);
7664047679e3SAloka Dixit 
7665047679e3SAloka Dixit 	kfree(tb);
7666047679e3SAloka Dixit }
7667047679e3SAloka Dixit 
7668047679e3SAloka Dixit static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab,
7669047679e3SAloka Dixit 					      struct sk_buff *skb)
7670047679e3SAloka Dixit {
7671047679e3SAloka Dixit 	const void **tb;
7672047679e3SAloka Dixit 	const struct wmi_probe_resp_tx_status_event *ev;
7673047679e3SAloka Dixit 	int ret;
7674047679e3SAloka Dixit 
7675047679e3SAloka Dixit 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7676047679e3SAloka Dixit 	if (IS_ERR(tb)) {
7677047679e3SAloka Dixit 		ret = PTR_ERR(tb);
7678047679e3SAloka Dixit 		ath11k_warn(ab,
7679047679e3SAloka Dixit 			    "failed to parse probe response transmission status event tlv: %d\n",
7680047679e3SAloka Dixit 			    ret);
7681047679e3SAloka Dixit 		return;
7682047679e3SAloka Dixit 	}
7683047679e3SAloka Dixit 
7684047679e3SAloka Dixit 	ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT];
7685047679e3SAloka Dixit 	if (!ev) {
7686047679e3SAloka Dixit 		ath11k_warn(ab,
7687047679e3SAloka Dixit 			    "failed to fetch probe response transmission status event");
7688047679e3SAloka Dixit 		kfree(tb);
7689047679e3SAloka Dixit 		return;
7690047679e3SAloka Dixit 	}
7691047679e3SAloka Dixit 
7692047679e3SAloka Dixit 	if (ev->tx_status)
7693047679e3SAloka Dixit 		ath11k_warn(ab,
7694047679e3SAloka Dixit 			    "Probe response transmission failed for vdev_id %u, status %u\n",
7695047679e3SAloka Dixit 			    ev->vdev_id, ev->tx_status);
7696047679e3SAloka Dixit 
7697047679e3SAloka Dixit 	kfree(tb);
7698047679e3SAloka Dixit }
7699047679e3SAloka Dixit 
770079802b13SCarl Huang static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab,
770179802b13SCarl Huang 						u16 tag, u16 len,
770279802b13SCarl Huang 						const void *ptr, void *data)
770379802b13SCarl Huang {
770479802b13SCarl Huang 	struct wmi_wow_ev_arg *ev = data;
770579802b13SCarl Huang 	const char *wow_pg_fault;
770679802b13SCarl Huang 	int wow_pg_len;
770779802b13SCarl Huang 
770879802b13SCarl Huang 	switch (tag) {
770979802b13SCarl Huang 	case WMI_TAG_WOW_EVENT_INFO:
771079802b13SCarl Huang 		memcpy(ev, ptr, sizeof(*ev));
771179802b13SCarl Huang 		ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n",
771279802b13SCarl Huang 			   ev->wake_reason, wow_reason(ev->wake_reason));
771379802b13SCarl Huang 		break;
771479802b13SCarl Huang 
771579802b13SCarl Huang 	case WMI_TAG_ARRAY_BYTE:
771679802b13SCarl Huang 		if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) {
771779802b13SCarl Huang 			wow_pg_fault = ptr;
771879802b13SCarl Huang 			/* the first 4 bytes are length */
771979802b13SCarl Huang 			wow_pg_len = *(int *)wow_pg_fault;
772079802b13SCarl Huang 			wow_pg_fault += sizeof(int);
772179802b13SCarl Huang 			ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n",
772279802b13SCarl Huang 				   wow_pg_len);
772379802b13SCarl Huang 			ath11k_dbg_dump(ab, ATH11K_DBG_WMI,
772479802b13SCarl Huang 					"wow_event_info_type packet present",
772579802b13SCarl Huang 					"wow_pg_fault ",
772679802b13SCarl Huang 					wow_pg_fault,
772779802b13SCarl Huang 					wow_pg_len);
772879802b13SCarl Huang 		}
772979802b13SCarl Huang 		break;
773079802b13SCarl Huang 	default:
773179802b13SCarl Huang 		break;
773279802b13SCarl Huang 	}
773379802b13SCarl Huang 
773479802b13SCarl Huang 	return 0;
773579802b13SCarl Huang }
773679802b13SCarl Huang 
773779802b13SCarl Huang static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb)
773879802b13SCarl Huang {
773979802b13SCarl Huang 	struct wmi_wow_ev_arg ev = { };
774079802b13SCarl Huang 	int ret;
774179802b13SCarl Huang 
774279802b13SCarl Huang 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
774379802b13SCarl Huang 				  ath11k_wmi_tlv_wow_wakeup_host_parse,
774479802b13SCarl Huang 				  &ev);
774579802b13SCarl Huang 	if (ret) {
774679802b13SCarl Huang 		ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret);
774779802b13SCarl Huang 		return;
774879802b13SCarl Huang 	}
774979802b13SCarl Huang 
775079802b13SCarl Huang 	complete(&ab->wow.wakeup_completed);
775179802b13SCarl Huang }
775279802b13SCarl Huang 
775342da1cc7SCheng Wang static void
775442da1cc7SCheng Wang ath11k_wmi_diag_event(struct ath11k_base *ab,
775542da1cc7SCheng Wang 		      struct sk_buff *skb)
775642da1cc7SCheng Wang {
775742da1cc7SCheng Wang 	trace_ath11k_wmi_diag(ab, skb->data, skb->len);
775842da1cc7SCheng Wang }
775942da1cc7SCheng Wang 
77603d00e8b5SJohn Crispin static const char *ath11k_wmi_twt_add_dialog_event_status(u32 status)
77613d00e8b5SJohn Crispin {
77623d00e8b5SJohn Crispin 	switch (status) {
77633d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_OK:
77643d00e8b5SJohn Crispin 		return "ok";
77653d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
77663d00e8b5SJohn Crispin 		return "twt disabled";
77673d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
77683d00e8b5SJohn Crispin 		return "dialog id in use";
77693d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_INVALID_PARAM:
77703d00e8b5SJohn Crispin 		return "invalid parameters";
77713d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NOT_READY:
77723d00e8b5SJohn Crispin 		return "not ready";
77733d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NO_RESOURCE:
77743d00e8b5SJohn Crispin 		return "resource unavailable";
77753d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NO_ACK:
77763d00e8b5SJohn Crispin 		return "no ack";
77773d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NO_RESPONSE:
77783d00e8b5SJohn Crispin 		return "no response";
77793d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_DENIED:
77803d00e8b5SJohn Crispin 		return "denied";
77813d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_UNKNOWN_ERROR:
77823d00e8b5SJohn Crispin 		fallthrough;
77833d00e8b5SJohn Crispin 	default:
77843d00e8b5SJohn Crispin 		return "unknown error";
77853d00e8b5SJohn Crispin 	}
77863d00e8b5SJohn Crispin }
77873d00e8b5SJohn Crispin 
77883d00e8b5SJohn Crispin static void ath11k_wmi_twt_add_dialog_event(struct ath11k_base *ab,
77893d00e8b5SJohn Crispin 					    struct sk_buff *skb)
77903d00e8b5SJohn Crispin {
77913d00e8b5SJohn Crispin 	const void **tb;
77923d00e8b5SJohn Crispin 	const struct wmi_twt_add_dialog_event *ev;
77933d00e8b5SJohn Crispin 	int ret;
77943d00e8b5SJohn Crispin 
77953d00e8b5SJohn Crispin 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
77963d00e8b5SJohn Crispin 	if (IS_ERR(tb)) {
77973d00e8b5SJohn Crispin 		ret = PTR_ERR(tb);
77983d00e8b5SJohn Crispin 		ath11k_warn(ab,
77993d00e8b5SJohn Crispin 			    "failed to parse wmi twt add dialog status event tlv: %d\n",
78003d00e8b5SJohn Crispin 			    ret);
78013d00e8b5SJohn Crispin 		return;
78023d00e8b5SJohn Crispin 	}
78033d00e8b5SJohn Crispin 
78043d00e8b5SJohn Crispin 	ev = tb[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT];
78053d00e8b5SJohn Crispin 	if (!ev) {
78063d00e8b5SJohn Crispin 		ath11k_warn(ab, "failed to fetch twt add dialog wmi event\n");
78073d00e8b5SJohn Crispin 		goto exit;
78083d00e8b5SJohn Crispin 	}
78093d00e8b5SJohn Crispin 
78103d00e8b5SJohn Crispin 	if (ev->status)
78113d00e8b5SJohn Crispin 		ath11k_warn(ab,
78123d00e8b5SJohn Crispin 			    "wmi add twt dialog event vdev %d dialog id %d status %s\n",
78133d00e8b5SJohn Crispin 			    ev->vdev_id, ev->dialog_id,
78143d00e8b5SJohn Crispin 			    ath11k_wmi_twt_add_dialog_event_status(ev->status));
78153d00e8b5SJohn Crispin 
78163d00e8b5SJohn Crispin exit:
78173d00e8b5SJohn Crispin 	kfree(tb);
78183d00e8b5SJohn Crispin }
78193d00e8b5SJohn Crispin 
7820a16d9b50SCarl Huang static void ath11k_wmi_gtk_offload_status_event(struct ath11k_base *ab,
7821a16d9b50SCarl Huang 						struct sk_buff *skb)
7822a16d9b50SCarl Huang {
7823a16d9b50SCarl Huang 	const void **tb;
7824a16d9b50SCarl Huang 	const struct wmi_gtk_offload_status_event *ev;
7825a16d9b50SCarl Huang 	struct ath11k_vif *arvif;
7826a16d9b50SCarl Huang 	__be64 replay_ctr_be;
7827a16d9b50SCarl Huang 	u64    replay_ctr;
7828a16d9b50SCarl Huang 	int ret;
7829a16d9b50SCarl Huang 
7830a16d9b50SCarl Huang 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7831a16d9b50SCarl Huang 	if (IS_ERR(tb)) {
7832a16d9b50SCarl Huang 		ret = PTR_ERR(tb);
7833a16d9b50SCarl Huang 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7834a16d9b50SCarl Huang 		return;
7835a16d9b50SCarl Huang 	}
7836a16d9b50SCarl Huang 
7837a16d9b50SCarl Huang 	ev = tb[WMI_TAG_GTK_OFFLOAD_STATUS_EVENT];
7838a16d9b50SCarl Huang 	if (!ev) {
7839a16d9b50SCarl Huang 		ath11k_warn(ab, "failed to fetch gtk offload status ev");
7840a16d9b50SCarl Huang 		kfree(tb);
7841a16d9b50SCarl Huang 		return;
7842a16d9b50SCarl Huang 	}
7843a16d9b50SCarl Huang 
7844a16d9b50SCarl Huang 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
7845a16d9b50SCarl Huang 	if (!arvif) {
7846a16d9b50SCarl Huang 		ath11k_warn(ab, "failed to get arvif for vdev_id:%d\n",
7847a16d9b50SCarl Huang 			    ev->vdev_id);
7848a16d9b50SCarl Huang 		kfree(tb);
7849a16d9b50SCarl Huang 		return;
7850a16d9b50SCarl Huang 	}
7851a16d9b50SCarl Huang 
7852a16d9b50SCarl Huang 	ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi gtk offload event refresh_cnt %d\n",
7853a16d9b50SCarl Huang 		   ev->refresh_cnt);
7854a16d9b50SCarl Huang 	ath11k_dbg_dump(ab, ATH11K_DBG_WMI, "replay_cnt",
7855a16d9b50SCarl Huang 			NULL, ev->replay_ctr.counter, GTK_REPLAY_COUNTER_BYTES);
7856a16d9b50SCarl Huang 
7857a16d9b50SCarl Huang 	replay_ctr =  ev->replay_ctr.word1;
7858a16d9b50SCarl Huang 	replay_ctr = (replay_ctr << 32) | ev->replay_ctr.word0;
7859a16d9b50SCarl Huang 	arvif->rekey_data.replay_ctr = replay_ctr;
7860a16d9b50SCarl Huang 
7861a16d9b50SCarl Huang 	/* supplicant expects big-endian replay counter */
7862a16d9b50SCarl Huang 	replay_ctr_be = cpu_to_be64(replay_ctr);
7863a16d9b50SCarl Huang 
7864a16d9b50SCarl Huang 	ieee80211_gtk_rekey_notify(arvif->vif, arvif->bssid,
7865eee645ecSBaochen Qiang 				   (void *)&replay_ctr_be, GFP_ATOMIC);
7866a16d9b50SCarl Huang 
7867a16d9b50SCarl Huang 	kfree(tb);
7868a16d9b50SCarl Huang }
7869a16d9b50SCarl Huang 
7870d5c65159SKalle Valo static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
7871d5c65159SKalle Valo {
7872d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
7873d5c65159SKalle Valo 	enum wmi_tlv_event_id id;
7874d5c65159SKalle Valo 
7875d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
7876d5c65159SKalle Valo 	id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
7877d5c65159SKalle Valo 
7878fb12305aSVenkateswara Naralasetty 	trace_ath11k_wmi_event(ab, id, skb->data, skb->len);
7879fb12305aSVenkateswara Naralasetty 
7880d5c65159SKalle Valo 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
7881d5c65159SKalle Valo 		goto out;
7882d5c65159SKalle Valo 
7883d5c65159SKalle Valo 	switch (id) {
7884d5c65159SKalle Valo 		/* Process all the WMI events here */
7885d5c65159SKalle Valo 	case WMI_SERVICE_READY_EVENTID:
7886d5c65159SKalle Valo 		ath11k_service_ready_event(ab, skb);
7887d5c65159SKalle Valo 		break;
7888d5c65159SKalle Valo 	case WMI_SERVICE_READY_EXT_EVENTID:
7889d5c65159SKalle Valo 		ath11k_service_ready_ext_event(ab, skb);
7890d5c65159SKalle Valo 		break;
7891bd647855SKarthikeyan Periyasamy 	case WMI_SERVICE_READY_EXT2_EVENTID:
7892bd647855SKarthikeyan Periyasamy 		ath11k_service_ready_ext2_event(ab, skb);
7893bd647855SKarthikeyan Periyasamy 		break;
7894d5c65159SKalle Valo 	case WMI_REG_CHAN_LIST_CC_EVENTID:
7895d5c65159SKalle Valo 		ath11k_reg_chan_list_event(ab, skb);
7896d5c65159SKalle Valo 		break;
7897d5c65159SKalle Valo 	case WMI_READY_EVENTID:
7898d5c65159SKalle Valo 		ath11k_ready_event(ab, skb);
7899d5c65159SKalle Valo 		break;
7900d5c65159SKalle Valo 	case WMI_PEER_DELETE_RESP_EVENTID:
7901d5c65159SKalle Valo 		ath11k_peer_delete_resp_event(ab, skb);
7902d5c65159SKalle Valo 		break;
7903d5c65159SKalle Valo 	case WMI_VDEV_START_RESP_EVENTID:
7904d5c65159SKalle Valo 		ath11k_vdev_start_resp_event(ab, skb);
7905d5c65159SKalle Valo 		break;
7906d5c65159SKalle Valo 	case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
7907d5c65159SKalle Valo 		ath11k_bcn_tx_status_event(ab, skb);
7908d5c65159SKalle Valo 		break;
7909d5c65159SKalle Valo 	case WMI_VDEV_STOPPED_EVENTID:
7910d5c65159SKalle Valo 		ath11k_vdev_stopped_event(ab, skb);
7911d5c65159SKalle Valo 		break;
7912d5c65159SKalle Valo 	case WMI_MGMT_RX_EVENTID:
7913d5c65159SKalle Valo 		ath11k_mgmt_rx_event(ab, skb);
7914d5c65159SKalle Valo 		/* mgmt_rx_event() owns the skb now! */
7915d5c65159SKalle Valo 		return;
7916d5c65159SKalle Valo 	case WMI_MGMT_TX_COMPLETION_EVENTID:
7917d5c65159SKalle Valo 		ath11k_mgmt_tx_compl_event(ab, skb);
7918d5c65159SKalle Valo 		break;
7919d5c65159SKalle Valo 	case WMI_SCAN_EVENTID:
7920d5c65159SKalle Valo 		ath11k_scan_event(ab, skb);
7921d5c65159SKalle Valo 		break;
7922d5c65159SKalle Valo 	case WMI_PEER_STA_KICKOUT_EVENTID:
7923d5c65159SKalle Valo 		ath11k_peer_sta_kickout_event(ab, skb);
7924d5c65159SKalle Valo 		break;
7925d5c65159SKalle Valo 	case WMI_ROAM_EVENTID:
7926d5c65159SKalle Valo 		ath11k_roam_event(ab, skb);
7927d5c65159SKalle Valo 		break;
7928d5c65159SKalle Valo 	case WMI_CHAN_INFO_EVENTID:
7929d5c65159SKalle Valo 		ath11k_chan_info_event(ab, skb);
7930d5c65159SKalle Valo 		break;
7931d5c65159SKalle Valo 	case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
7932d5c65159SKalle Valo 		ath11k_pdev_bss_chan_info_event(ab, skb);
7933d5c65159SKalle Valo 		break;
7934d5c65159SKalle Valo 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
7935d5c65159SKalle Valo 		ath11k_vdev_install_key_compl_event(ab, skb);
7936d5c65159SKalle Valo 		break;
7937d5c65159SKalle Valo 	case WMI_SERVICE_AVAILABLE_EVENTID:
7938d5c65159SKalle Valo 		ath11k_service_available_event(ab, skb);
7939d5c65159SKalle Valo 		break;
7940d5c65159SKalle Valo 	case WMI_PEER_ASSOC_CONF_EVENTID:
7941d5c65159SKalle Valo 		ath11k_peer_assoc_conf_event(ab, skb);
7942d5c65159SKalle Valo 		break;
7943d5c65159SKalle Valo 	case WMI_UPDATE_STATS_EVENTID:
7944d5c65159SKalle Valo 		ath11k_update_stats_event(ab, skb);
7945d5c65159SKalle Valo 		break;
7946d5c65159SKalle Valo 	case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
7947d5c65159SKalle Valo 		ath11k_pdev_ctl_failsafe_check_event(ab, skb);
7948d5c65159SKalle Valo 		break;
7949d5c65159SKalle Valo 	case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
7950d5c65159SKalle Valo 		ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
7951d5c65159SKalle Valo 		break;
7952a41d1034SPradeep Kumar Chitrapu 	case WMI_PDEV_TEMPERATURE_EVENTID:
7953a41d1034SPradeep Kumar Chitrapu 		ath11k_wmi_pdev_temperature_event(ab, skb);
7954a41d1034SPradeep Kumar Chitrapu 		break;
79559d11b7bfSKarthikeyan Periyasamy 	case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
79569d11b7bfSKarthikeyan Periyasamy 		ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
79579d11b7bfSKarthikeyan Periyasamy 		break;
7958047679e3SAloka Dixit 	case WMI_HOST_FILS_DISCOVERY_EVENTID:
7959047679e3SAloka Dixit 		ath11k_fils_discovery_event(ab, skb);
7960047679e3SAloka Dixit 		break;
7961047679e3SAloka Dixit 	case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID:
7962047679e3SAloka Dixit 		ath11k_probe_resp_tx_status_event(ab, skb);
7963047679e3SAloka Dixit 		break;
7964886433a9SJohn Crispin 	case WMI_OBSS_COLOR_COLLISION_DETECTION_EVENTID:
7965886433a9SJohn Crispin 		ath11k_wmi_obss_color_collision_event(ab, skb);
7966886433a9SJohn Crispin 		break;
79673d00e8b5SJohn Crispin 	case WMI_TWT_ADD_DIALOG_EVENTID:
79683d00e8b5SJohn Crispin 		ath11k_wmi_twt_add_dialog_event(ab, skb);
79693d00e8b5SJohn Crispin 		break;
7970d5c65159SKalle Valo 	/* add Unsupported events here */
7971d5c65159SKalle Valo 	case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID:
79729cfbae46SJohn Crispin 	case WMI_PEER_OPER_MODE_CHANGE_EVENTID:
79736d293d44SJohn Crispin 	case WMI_TWT_ENABLE_EVENTID:
79746d293d44SJohn Crispin 	case WMI_TWT_DISABLE_EVENTID:
79753d00e8b5SJohn Crispin 	case WMI_TWT_DEL_DIALOG_EVENTID:
79763d00e8b5SJohn Crispin 	case WMI_TWT_PAUSE_DIALOG_EVENTID:
79773d00e8b5SJohn Crispin 	case WMI_TWT_RESUME_DIALOG_EVENTID:
79789d11b7bfSKarthikeyan Periyasamy 	case WMI_PDEV_DMA_RING_CFG_RSP_EVENTID:
797994a6df31SP Praneesh 	case WMI_PEER_CREATE_CONF_EVENTID:
7980d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
7981d5c65159SKalle Valo 			   "ignoring unsupported event 0x%x\n", id);
7982d5c65159SKalle Valo 		break;
7983d5c65159SKalle Valo 	case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
7984d5c65159SKalle Valo 		ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
7985d5c65159SKalle Valo 		break;
79863cbbdfbeSRitesh Singh 	case WMI_VDEV_DELETE_RESP_EVENTID:
79873cbbdfbeSRitesh Singh 		ath11k_vdev_delete_resp_event(ab, skb);
79883cbbdfbeSRitesh Singh 		break;
798979802b13SCarl Huang 	case WMI_WOW_WAKEUP_HOST_EVENTID:
799079802b13SCarl Huang 		ath11k_wmi_event_wow_wakeup_host(ab, skb);
799179802b13SCarl Huang 		break;
79929dcf6808SWen Gong 	case WMI_11D_NEW_COUNTRY_EVENTID:
79939dcf6808SWen Gong 		ath11k_reg_11d_new_cc_event(ab, skb);
79949dcf6808SWen Gong 		break;
799542da1cc7SCheng Wang 	case WMI_DIAG_EVENTID:
799642da1cc7SCheng Wang 		ath11k_wmi_diag_event(ab, skb);
799742da1cc7SCheng Wang 		break;
7998a16d9b50SCarl Huang 	case WMI_GTK_OFFLOAD_STATUS_EVENTID:
7999a16d9b50SCarl Huang 		ath11k_wmi_gtk_offload_status_event(ab, skb);
8000a16d9b50SCarl Huang 		break;
8001d5c65159SKalle Valo 	/* TODO: Add remaining events */
8002d5c65159SKalle Valo 	default:
800382b4f9b8SGovind Singh 		ath11k_dbg(ab, ATH11K_DBG_WMI, "Unknown eventid: 0x%x\n", id);
8004d5c65159SKalle Valo 		break;
8005d5c65159SKalle Valo 	}
8006d5c65159SKalle Valo 
8007d5c65159SKalle Valo out:
8008d5c65159SKalle Valo 	dev_kfree_skb(skb);
8009d5c65159SKalle Valo }
8010d5c65159SKalle Valo 
8011d5c65159SKalle Valo static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
8012d5c65159SKalle Valo 					   u32 pdev_idx)
8013d5c65159SKalle Valo {
8014d5c65159SKalle Valo 	int status;
8015d5c65159SKalle Valo 	u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
8016d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
8017d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
8018d5c65159SKalle Valo 
8019d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_req conn_req;
8020d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_resp conn_resp;
8021d5c65159SKalle Valo 
8022d5c65159SKalle Valo 	memset(&conn_req, 0, sizeof(conn_req));
8023d5c65159SKalle Valo 	memset(&conn_resp, 0, sizeof(conn_resp));
8024d5c65159SKalle Valo 
8025d5c65159SKalle Valo 	/* these fields are the same for all service endpoints */
8026d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
8027d5c65159SKalle Valo 	conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
8028d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
8029d5c65159SKalle Valo 
8030d5c65159SKalle Valo 	/* connect to control service */
8031d5c65159SKalle Valo 	conn_req.service_id = svc_id[pdev_idx];
8032d5c65159SKalle Valo 
8033d5c65159SKalle Valo 	status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
8034d5c65159SKalle Valo 	if (status) {
8035d5c65159SKalle Valo 		ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
8036d5c65159SKalle Valo 			    status);
8037d5c65159SKalle Valo 		return status;
8038d5c65159SKalle Valo 	}
8039d5c65159SKalle Valo 
80406bc9d6f7SJohn Crispin 	ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
80416bc9d6f7SJohn Crispin 	ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
80426bc9d6f7SJohn Crispin 	ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
8043f951380aSP Praneesh 	init_waitqueue_head(&ab->wmi_ab.wmi[pdev_idx].tx_ce_desc_wq);
8044d5c65159SKalle Valo 
8045d5c65159SKalle Valo 	return 0;
8046d5c65159SKalle Valo }
8047d5c65159SKalle Valo 
8048d5c65159SKalle Valo static int
8049d5c65159SKalle Valo ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
8050d5c65159SKalle Valo 			      struct wmi_unit_test_cmd ut_cmd,
8051d5c65159SKalle Valo 			      u32 *test_args)
8052d5c65159SKalle Valo {
8053d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8054d5c65159SKalle Valo 	struct wmi_unit_test_cmd *cmd;
8055d5c65159SKalle Valo 	struct sk_buff *skb;
8056d5c65159SKalle Valo 	struct wmi_tlv *tlv;
8057d5c65159SKalle Valo 	void *ptr;
8058d5c65159SKalle Valo 	u32 *ut_cmd_args;
8059d5c65159SKalle Valo 	int buf_len, arg_len;
8060d5c65159SKalle Valo 	int ret;
8061d5c65159SKalle Valo 	int i;
8062d5c65159SKalle Valo 
8063d5c65159SKalle Valo 	arg_len = sizeof(u32) * ut_cmd.num_args;
8064d5c65159SKalle Valo 	buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
8065d5c65159SKalle Valo 
80666bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
8067d5c65159SKalle Valo 	if (!skb)
8068d5c65159SKalle Valo 		return -ENOMEM;
8069d5c65159SKalle Valo 
8070d5c65159SKalle Valo 	cmd = (struct wmi_unit_test_cmd *)skb->data;
8071d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
8072d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
8073d5c65159SKalle Valo 
8074d5c65159SKalle Valo 	cmd->vdev_id = ut_cmd.vdev_id;
8075d5c65159SKalle Valo 	cmd->module_id = ut_cmd.module_id;
8076d5c65159SKalle Valo 	cmd->num_args = ut_cmd.num_args;
8077d5c65159SKalle Valo 	cmd->diag_token = ut_cmd.diag_token;
8078d5c65159SKalle Valo 
8079d5c65159SKalle Valo 	ptr = skb->data + sizeof(ut_cmd);
8080d5c65159SKalle Valo 
8081d5c65159SKalle Valo 	tlv = ptr;
8082d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8083d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, arg_len);
8084d5c65159SKalle Valo 
8085d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
8086d5c65159SKalle Valo 
8087d5c65159SKalle Valo 	ut_cmd_args = ptr;
8088d5c65159SKalle Valo 	for (i = 0; i < ut_cmd.num_args; i++)
8089d5c65159SKalle Valo 		ut_cmd_args[i] = test_args[i];
8090d5c65159SKalle Valo 
8091d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
8092d5c65159SKalle Valo 
8093d5c65159SKalle Valo 	if (ret) {
8094d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
8095d5c65159SKalle Valo 			    ret);
8096d5c65159SKalle Valo 		dev_kfree_skb(skb);
8097d5c65159SKalle Valo 	}
8098d5c65159SKalle Valo 
8099d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8100d5c65159SKalle Valo 		   "WMI unit test : module %d vdev %d n_args %d token %d\n",
8101d5c65159SKalle Valo 		   cmd->module_id, cmd->vdev_id, cmd->num_args,
8102d5c65159SKalle Valo 		   cmd->diag_token);
8103d5c65159SKalle Valo 
8104d5c65159SKalle Valo 	return ret;
8105d5c65159SKalle Valo }
8106d5c65159SKalle Valo 
8107d5c65159SKalle Valo int ath11k_wmi_simulate_radar(struct ath11k *ar)
8108d5c65159SKalle Valo {
8109d5c65159SKalle Valo 	struct ath11k_vif *arvif;
8110d5c65159SKalle Valo 	u32 dfs_args[DFS_MAX_TEST_ARGS];
8111d5c65159SKalle Valo 	struct wmi_unit_test_cmd wmi_ut;
8112d5c65159SKalle Valo 	bool arvif_found = false;
8113d5c65159SKalle Valo 
8114d5c65159SKalle Valo 	list_for_each_entry(arvif, &ar->arvifs, list) {
8115d5c65159SKalle Valo 		if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
8116d5c65159SKalle Valo 			arvif_found = true;
8117d5c65159SKalle Valo 			break;
8118d5c65159SKalle Valo 		}
8119d5c65159SKalle Valo 	}
8120d5c65159SKalle Valo 
8121d5c65159SKalle Valo 	if (!arvif_found)
8122d5c65159SKalle Valo 		return -EINVAL;
8123d5c65159SKalle Valo 
8124d5c65159SKalle Valo 	dfs_args[DFS_TEST_CMDID] = 0;
8125d5c65159SKalle Valo 	dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
8126d5c65159SKalle Valo 	/* Currently we could pass segment_id(b0 - b1), chirp(b2)
8127d5c65159SKalle Valo 	 * freq offset (b3 - b10) to unit test. For simulation
8128d5c65159SKalle Valo 	 * purpose this can be set to 0 which is valid.
8129d5c65159SKalle Valo 	 */
8130d5c65159SKalle Valo 	dfs_args[DFS_TEST_RADAR_PARAM] = 0;
8131d5c65159SKalle Valo 
8132d5c65159SKalle Valo 	wmi_ut.vdev_id = arvif->vdev_id;
8133d5c65159SKalle Valo 	wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
8134d5c65159SKalle Valo 	wmi_ut.num_args = DFS_MAX_TEST_ARGS;
8135d5c65159SKalle Valo 	wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
8136d5c65159SKalle Valo 
8137d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
8138d5c65159SKalle Valo 
8139d5c65159SKalle Valo 	return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
8140d5c65159SKalle Valo }
8141d5c65159SKalle Valo 
8142f295ad91SSeevalamuthu Mariappan int ath11k_wmi_fw_dbglog_cfg(struct ath11k *ar, u32 *module_id_bitmap,
8143f295ad91SSeevalamuthu Mariappan 			     struct ath11k_fw_dbglog *dbglog)
8144f295ad91SSeevalamuthu Mariappan {
8145f295ad91SSeevalamuthu Mariappan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8146f295ad91SSeevalamuthu Mariappan 	struct wmi_debug_log_config_cmd_fixed_param *cmd;
8147f295ad91SSeevalamuthu Mariappan 	struct sk_buff *skb;
8148f295ad91SSeevalamuthu Mariappan 	struct wmi_tlv *tlv;
8149f295ad91SSeevalamuthu Mariappan 	int ret, len;
8150f295ad91SSeevalamuthu Mariappan 
8151f295ad91SSeevalamuthu Mariappan 	len = sizeof(*cmd) + TLV_HDR_SIZE + (MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8152f295ad91SSeevalamuthu Mariappan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8153f295ad91SSeevalamuthu Mariappan 	if (!skb)
8154f295ad91SSeevalamuthu Mariappan 		return -ENOMEM;
8155f295ad91SSeevalamuthu Mariappan 
8156f295ad91SSeevalamuthu Mariappan 	cmd = (struct wmi_debug_log_config_cmd_fixed_param *)skb->data;
8157f295ad91SSeevalamuthu Mariappan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DEBUG_LOG_CONFIG_CMD) |
8158f295ad91SSeevalamuthu Mariappan 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8159f295ad91SSeevalamuthu Mariappan 	cmd->dbg_log_param = dbglog->param;
8160f295ad91SSeevalamuthu Mariappan 
8161f295ad91SSeevalamuthu Mariappan 	tlv = (struct wmi_tlv *)((u8 *)cmd + sizeof(*cmd));
8162f295ad91SSeevalamuthu Mariappan 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8163f295ad91SSeevalamuthu Mariappan 		      FIELD_PREP(WMI_TLV_LEN, MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8164f295ad91SSeevalamuthu Mariappan 
8165f295ad91SSeevalamuthu Mariappan 	switch (dbglog->param) {
8166f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_LOG_LEVEL:
8167f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE:
8168f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_VDEV_DISABLE:
8169f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE_BITMAP:
8170f295ad91SSeevalamuthu Mariappan 		cmd->value = dbglog->value;
8171f295ad91SSeevalamuthu Mariappan 		break;
8172f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_MOD_ENABLE_BITMAP:
8173f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_WOW_MOD_ENABLE_BITMAP:
8174f295ad91SSeevalamuthu Mariappan 		cmd->value = dbglog->value;
8175f295ad91SSeevalamuthu Mariappan 		memcpy(tlv->value, module_id_bitmap,
8176f295ad91SSeevalamuthu Mariappan 		       MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8177f295ad91SSeevalamuthu Mariappan 		/* clear current config to be used for next user config */
8178f295ad91SSeevalamuthu Mariappan 		memset(module_id_bitmap, 0,
8179f295ad91SSeevalamuthu Mariappan 		       MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8180f295ad91SSeevalamuthu Mariappan 		break;
8181f295ad91SSeevalamuthu Mariappan 	default:
8182f295ad91SSeevalamuthu Mariappan 		dev_kfree_skb(skb);
8183f295ad91SSeevalamuthu Mariappan 		return -EINVAL;
8184f295ad91SSeevalamuthu Mariappan 	}
8185f295ad91SSeevalamuthu Mariappan 
8186f295ad91SSeevalamuthu Mariappan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DBGLOG_CFG_CMDID);
8187f295ad91SSeevalamuthu Mariappan 	if (ret) {
8188f295ad91SSeevalamuthu Mariappan 		ath11k_warn(ar->ab,
8189f295ad91SSeevalamuthu Mariappan 			    "failed to send WMI_DBGLOG_CFG_CMDID\n");
8190f295ad91SSeevalamuthu Mariappan 		dev_kfree_skb(skb);
8191f295ad91SSeevalamuthu Mariappan 	}
8192f295ad91SSeevalamuthu Mariappan 	return ret;
8193f295ad91SSeevalamuthu Mariappan }
8194f295ad91SSeevalamuthu Mariappan 
8195d5c65159SKalle Valo int ath11k_wmi_connect(struct ath11k_base *ab)
8196d5c65159SKalle Valo {
8197d5c65159SKalle Valo 	u32 i;
8198d5c65159SKalle Valo 	u8 wmi_ep_count;
8199d5c65159SKalle Valo 
8200d5c65159SKalle Valo 	wmi_ep_count = ab->htc.wmi_ep_count;
8201b1cc29e9SAnilkumar Kolli 	if (wmi_ep_count > ab->hw_params.max_radios)
8202d5c65159SKalle Valo 		return -1;
8203d5c65159SKalle Valo 
8204d5c65159SKalle Valo 	for (i = 0; i < wmi_ep_count; i++)
8205d5c65159SKalle Valo 		ath11k_connect_pdev_htc_service(ab, i);
8206d5c65159SKalle Valo 
8207d5c65159SKalle Valo 	return 0;
8208d5c65159SKalle Valo }
8209d5c65159SKalle Valo 
8210d5c65159SKalle Valo static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
8211d5c65159SKalle Valo {
8212d5c65159SKalle Valo 	if (WARN_ON(pdev_id >= MAX_RADIOS))
8213d5c65159SKalle Valo 		return;
8214d5c65159SKalle Valo 
8215d5c65159SKalle Valo 	/* TODO: Deinit any pdev specific wmi resource */
8216d5c65159SKalle Valo }
8217d5c65159SKalle Valo 
8218d5c65159SKalle Valo int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
8219d5c65159SKalle Valo 			   u8 pdev_id)
8220d5c65159SKalle Valo {
8221d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle;
8222d5c65159SKalle Valo 
8223b1cc29e9SAnilkumar Kolli 	if (pdev_id >= ab->hw_params.max_radios)
8224d5c65159SKalle Valo 		return -EINVAL;
8225d5c65159SKalle Valo 
82266bc9d6f7SJohn Crispin 	wmi_handle = &ab->wmi_ab.wmi[pdev_id];
8227d5c65159SKalle Valo 
82286bc9d6f7SJohn Crispin 	wmi_handle->wmi_ab = &ab->wmi_ab;
8229d5c65159SKalle Valo 
82306bc9d6f7SJohn Crispin 	ab->wmi_ab.ab = ab;
8231d5c65159SKalle Valo 	/* TODO: Init remaining resource specific to pdev */
8232d5c65159SKalle Valo 
8233d5c65159SKalle Valo 	return 0;
8234d5c65159SKalle Valo }
8235d5c65159SKalle Valo 
8236d5c65159SKalle Valo int ath11k_wmi_attach(struct ath11k_base *ab)
8237d5c65159SKalle Valo {
8238d5c65159SKalle Valo 	int ret;
8239d5c65159SKalle Valo 
8240d5c65159SKalle Valo 	ret = ath11k_wmi_pdev_attach(ab, 0);
8241d5c65159SKalle Valo 	if (ret)
8242d5c65159SKalle Valo 		return ret;
8243d5c65159SKalle Valo 
82446bc9d6f7SJohn Crispin 	ab->wmi_ab.ab = ab;
82456bc9d6f7SJohn Crispin 	ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
8246d5c65159SKalle Valo 
82475f859bc0SCarl Huang 	/* It's overwritten when service_ext_ready is handled */
8248b6f63010SManikanta Pubbisetty 	if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1)
82495f859bc0SCarl Huang 		ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
82505f859bc0SCarl Huang 
8251d5c65159SKalle Valo 	/* TODO: Init remaining wmi soc resources required */
82526bc9d6f7SJohn Crispin 	init_completion(&ab->wmi_ab.service_ready);
82536bc9d6f7SJohn Crispin 	init_completion(&ab->wmi_ab.unified_ready);
8254d5c65159SKalle Valo 
8255d5c65159SKalle Valo 	return 0;
8256d5c65159SKalle Valo }
8257d5c65159SKalle Valo 
8258d5c65159SKalle Valo void ath11k_wmi_detach(struct ath11k_base *ab)
8259d5c65159SKalle Valo {
8260d5c65159SKalle Valo 	int i;
8261d5c65159SKalle Valo 
8262d5c65159SKalle Valo 	/* TODO: Deinit wmi resource specific to SOC as required */
8263d5c65159SKalle Valo 
8264d5c65159SKalle Valo 	for (i = 0; i < ab->htc.wmi_ep_count; i++)
8265d5c65159SKalle Valo 		ath11k_wmi_pdev_detach(ab, i);
8266bd647855SKarthikeyan Periyasamy 
8267bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
8268d5c65159SKalle Valo }
826979802b13SCarl Huang 
8270c417b247SCarl Huang int ath11k_wmi_hw_data_filter_cmd(struct ath11k *ar, u32 vdev_id,
8271c417b247SCarl Huang 				  u32 filter_bitmap, bool enable)
8272c417b247SCarl Huang {
8273c417b247SCarl Huang 	struct wmi_hw_data_filter_cmd *cmd;
8274c417b247SCarl Huang 	struct sk_buff *skb;
8275c417b247SCarl Huang 	int len;
8276c417b247SCarl Huang 
8277c417b247SCarl Huang 	len = sizeof(*cmd);
8278c417b247SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8279c417b247SCarl Huang 
8280c417b247SCarl Huang 	if (!skb)
8281c417b247SCarl Huang 		return -ENOMEM;
8282c417b247SCarl Huang 
8283c417b247SCarl Huang 	cmd = (struct wmi_hw_data_filter_cmd *)skb->data;
8284c417b247SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_HW_DATA_FILTER_CMD) |
8285c417b247SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8286c417b247SCarl Huang 
8287c417b247SCarl Huang 	cmd->vdev_id = vdev_id;
8288c417b247SCarl Huang 	cmd->enable = enable;
8289c417b247SCarl Huang 
8290c417b247SCarl Huang 	/* Set all modes in case of disable */
8291c417b247SCarl Huang 	if (cmd->enable)
8292c417b247SCarl Huang 		cmd->hw_filter_bitmap = filter_bitmap;
8293c417b247SCarl Huang 	else
8294c417b247SCarl Huang 		cmd->hw_filter_bitmap = ((u32)~0U);
8295c417b247SCarl Huang 
8296c417b247SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8297c417b247SCarl Huang 		   "wmi hw data filter enable %d filter_bitmap 0x%x\n",
8298c417b247SCarl Huang 		   enable, filter_bitmap);
8299c417b247SCarl Huang 
8300c417b247SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_HW_DATA_FILTER_CMDID);
8301c417b247SCarl Huang }
8302c417b247SCarl Huang 
830379802b13SCarl Huang int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar)
830479802b13SCarl Huang {
830579802b13SCarl Huang 	struct wmi_wow_host_wakeup_ind *cmd;
830679802b13SCarl Huang 	struct sk_buff *skb;
830779802b13SCarl Huang 	size_t len;
830879802b13SCarl Huang 
830979802b13SCarl Huang 	len = sizeof(*cmd);
831079802b13SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
831179802b13SCarl Huang 	if (!skb)
831279802b13SCarl Huang 		return -ENOMEM;
831379802b13SCarl Huang 
831479802b13SCarl Huang 	cmd = (struct wmi_wow_host_wakeup_ind *)skb->data;
831579802b13SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
831679802b13SCarl Huang 				     WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) |
831779802b13SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
831879802b13SCarl Huang 
831979802b13SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow host wakeup ind\n");
832079802b13SCarl Huang 
832179802b13SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
832279802b13SCarl Huang }
832379802b13SCarl Huang 
832479802b13SCarl Huang int ath11k_wmi_wow_enable(struct ath11k *ar)
832579802b13SCarl Huang {
832679802b13SCarl Huang 	struct wmi_wow_enable_cmd *cmd;
832779802b13SCarl Huang 	struct sk_buff *skb;
832879802b13SCarl Huang 	int len;
832979802b13SCarl Huang 
833079802b13SCarl Huang 	len = sizeof(*cmd);
833179802b13SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
833279802b13SCarl Huang 	if (!skb)
833379802b13SCarl Huang 		return -ENOMEM;
833479802b13SCarl Huang 
833579802b13SCarl Huang 	cmd = (struct wmi_wow_enable_cmd *)skb->data;
833679802b13SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) |
833779802b13SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
833879802b13SCarl Huang 
833979802b13SCarl Huang 	cmd->enable = 1;
834079802b13SCarl Huang 	cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
834179802b13SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow enable\n");
834279802b13SCarl Huang 
834379802b13SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID);
834479802b13SCarl Huang }
83459cbd7fc9SCarl Huang 
83469cbd7fc9SCarl Huang int ath11k_wmi_scan_prob_req_oui(struct ath11k *ar,
83479cbd7fc9SCarl Huang 				 const u8 mac_addr[ETH_ALEN])
83489cbd7fc9SCarl Huang {
83499cbd7fc9SCarl Huang 	struct sk_buff *skb;
83509cbd7fc9SCarl Huang 	struct wmi_scan_prob_req_oui_cmd *cmd;
83519cbd7fc9SCarl Huang 	u32 prob_req_oui;
83529cbd7fc9SCarl Huang 	int len;
83539cbd7fc9SCarl Huang 
83549cbd7fc9SCarl Huang 	prob_req_oui = (((u32)mac_addr[0]) << 16) |
83559cbd7fc9SCarl Huang 		       (((u32)mac_addr[1]) << 8) | mac_addr[2];
83569cbd7fc9SCarl Huang 
83579cbd7fc9SCarl Huang 	len = sizeof(*cmd);
83589cbd7fc9SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
83599cbd7fc9SCarl Huang 	if (!skb)
83609cbd7fc9SCarl Huang 		return -ENOMEM;
83619cbd7fc9SCarl Huang 
83629cbd7fc9SCarl Huang 	cmd = (struct wmi_scan_prob_req_oui_cmd *)skb->data;
83639cbd7fc9SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
83649cbd7fc9SCarl Huang 				     WMI_TAG_SCAN_PROB_REQ_OUI_CMD) |
83659cbd7fc9SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
83669cbd7fc9SCarl Huang 	cmd->prob_req_oui = prob_req_oui;
83679cbd7fc9SCarl Huang 
83689cbd7fc9SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi scan prob req oui %d\n",
83699cbd7fc9SCarl Huang 		   prob_req_oui);
83709cbd7fc9SCarl Huang 
83719cbd7fc9SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SCAN_PROB_REQ_OUI_CMDID);
83729cbd7fc9SCarl Huang }
8373ba9177fcSCarl Huang 
8374ba9177fcSCarl Huang int ath11k_wmi_wow_add_wakeup_event(struct ath11k *ar, u32 vdev_id,
8375ba9177fcSCarl Huang 				    enum wmi_wow_wakeup_event event,
8376ba9177fcSCarl Huang 				u32 enable)
8377ba9177fcSCarl Huang {
8378ba9177fcSCarl Huang 	struct wmi_wow_add_del_event_cmd *cmd;
8379ba9177fcSCarl Huang 	struct sk_buff *skb;
8380ba9177fcSCarl Huang 	size_t len;
8381ba9177fcSCarl Huang 
8382ba9177fcSCarl Huang 	len = sizeof(*cmd);
8383ba9177fcSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8384ba9177fcSCarl Huang 	if (!skb)
8385ba9177fcSCarl Huang 		return -ENOMEM;
8386ba9177fcSCarl Huang 
8387ba9177fcSCarl Huang 	cmd = (struct wmi_wow_add_del_event_cmd *)skb->data;
8388ba9177fcSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ADD_DEL_EVT_CMD) |
8389ba9177fcSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8390ba9177fcSCarl Huang 
8391ba9177fcSCarl Huang 	cmd->vdev_id = vdev_id;
8392ba9177fcSCarl Huang 	cmd->is_add = enable;
8393ba9177fcSCarl Huang 	cmd->event_bitmap = (1 << event);
8394ba9177fcSCarl Huang 
8395ba9177fcSCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow add wakeup event %s enable %d vdev_id %d\n",
8396ba9177fcSCarl Huang 		   wow_wakeup_event(event), enable, vdev_id);
8397ba9177fcSCarl Huang 
8398ba9177fcSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
8399ba9177fcSCarl Huang }
8400ba9177fcSCarl Huang 
8401ba9177fcSCarl Huang int ath11k_wmi_wow_add_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id,
8402ba9177fcSCarl Huang 			       const u8 *pattern, const u8 *mask,
8403ba9177fcSCarl Huang 			   int pattern_len, int pattern_offset)
8404ba9177fcSCarl Huang {
8405ba9177fcSCarl Huang 	struct wmi_wow_add_pattern_cmd *cmd;
8406ba9177fcSCarl Huang 	struct wmi_wow_bitmap_pattern *bitmap;
8407ba9177fcSCarl Huang 	struct wmi_tlv *tlv;
8408ba9177fcSCarl Huang 	struct sk_buff *skb;
8409ba9177fcSCarl Huang 	u8 *ptr;
8410ba9177fcSCarl Huang 	size_t len;
8411ba9177fcSCarl Huang 
8412ba9177fcSCarl Huang 	len = sizeof(*cmd) +
8413ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* array struct */
8414ba9177fcSCarl Huang 	      sizeof(*bitmap) +			/* bitmap */
8415ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty ipv4 sync */
8416ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty ipv6 sync */
8417ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty magic */
8418ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty info timeout */
8419ba9177fcSCarl Huang 	      sizeof(*tlv) + sizeof(u32);	/* ratelimit interval */
8420ba9177fcSCarl Huang 
8421ba9177fcSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8422ba9177fcSCarl Huang 	if (!skb)
8423ba9177fcSCarl Huang 		return -ENOMEM;
8424ba9177fcSCarl Huang 
8425ba9177fcSCarl Huang 	/* cmd */
8426ba9177fcSCarl Huang 	ptr = (u8 *)skb->data;
8427ba9177fcSCarl Huang 	cmd = (struct wmi_wow_add_pattern_cmd *)ptr;
8428ba9177fcSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8429ba9177fcSCarl Huang 				     WMI_TAG_WOW_ADD_PATTERN_CMD) |
8430ba9177fcSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8431ba9177fcSCarl Huang 
8432ba9177fcSCarl Huang 	cmd->vdev_id = vdev_id;
8433ba9177fcSCarl Huang 	cmd->pattern_id = pattern_id;
8434ba9177fcSCarl Huang 	cmd->pattern_type = WOW_BITMAP_PATTERN;
8435ba9177fcSCarl Huang 
8436ba9177fcSCarl Huang 	ptr += sizeof(*cmd);
8437ba9177fcSCarl Huang 
8438ba9177fcSCarl Huang 	/* bitmap */
8439ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8440ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8441ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8442ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap));
8443ba9177fcSCarl Huang 
8444ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8445ba9177fcSCarl Huang 
8446ba9177fcSCarl Huang 	bitmap = (struct wmi_wow_bitmap_pattern *)ptr;
8447ba9177fcSCarl Huang 	bitmap->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8448ba9177fcSCarl Huang 					WMI_TAG_WOW_BITMAP_PATTERN_T) |
8449ba9177fcSCarl Huang 			     FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap) - TLV_HDR_SIZE);
8450ba9177fcSCarl Huang 
8451ba9177fcSCarl Huang 	memcpy(bitmap->patternbuf, pattern, pattern_len);
8452ba9177fcSCarl Huang 	ath11k_ce_byte_swap(bitmap->patternbuf, roundup(pattern_len, 4));
8453ba9177fcSCarl Huang 	memcpy(bitmap->bitmaskbuf, mask, pattern_len);
8454ba9177fcSCarl Huang 	ath11k_ce_byte_swap(bitmap->bitmaskbuf, roundup(pattern_len, 4));
8455ba9177fcSCarl Huang 	bitmap->pattern_offset = pattern_offset;
8456ba9177fcSCarl Huang 	bitmap->pattern_len = pattern_len;
8457ba9177fcSCarl Huang 	bitmap->bitmask_len = pattern_len;
8458ba9177fcSCarl Huang 	bitmap->pattern_id = pattern_id;
8459ba9177fcSCarl Huang 
8460ba9177fcSCarl Huang 	ptr += sizeof(*bitmap);
8461ba9177fcSCarl Huang 
8462ba9177fcSCarl Huang 	/* ipv4 sync */
8463ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8464ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8465ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8466ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8467ba9177fcSCarl Huang 
8468ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8469ba9177fcSCarl Huang 
8470ba9177fcSCarl Huang 	/* ipv6 sync */
8471ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8472ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8473ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8474ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8475ba9177fcSCarl Huang 
8476ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8477ba9177fcSCarl Huang 
8478ba9177fcSCarl Huang 	/* magic */
8479ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8480ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8481ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8482ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8483ba9177fcSCarl Huang 
8484ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8485ba9177fcSCarl Huang 
8486ba9177fcSCarl Huang 	/* pattern info timeout */
8487ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8488ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8489ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_UINT32) |
8490ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8491ba9177fcSCarl Huang 
8492ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8493ba9177fcSCarl Huang 
8494ba9177fcSCarl Huang 	/* ratelimit interval */
8495ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8496ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8497ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_UINT32) |
8498ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, sizeof(u32));
8499ba9177fcSCarl Huang 
8500ba9177fcSCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow add pattern vdev_id %d pattern_id %d pattern_offset %d\n",
8501ba9177fcSCarl Huang 		   vdev_id, pattern_id, pattern_offset);
8502ba9177fcSCarl Huang 
8503ba9177fcSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ADD_WAKE_PATTERN_CMDID);
8504ba9177fcSCarl Huang }
8505ba9177fcSCarl Huang 
8506ba9177fcSCarl Huang int ath11k_wmi_wow_del_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id)
8507ba9177fcSCarl Huang {
8508ba9177fcSCarl Huang 	struct wmi_wow_del_pattern_cmd *cmd;
8509ba9177fcSCarl Huang 	struct sk_buff *skb;
8510ba9177fcSCarl Huang 	size_t len;
8511ba9177fcSCarl Huang 
8512ba9177fcSCarl Huang 	len = sizeof(*cmd);
8513ba9177fcSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8514ba9177fcSCarl Huang 	if (!skb)
8515ba9177fcSCarl Huang 		return -ENOMEM;
8516ba9177fcSCarl Huang 
8517ba9177fcSCarl Huang 	cmd = (struct wmi_wow_del_pattern_cmd *)skb->data;
8518ba9177fcSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8519ba9177fcSCarl Huang 				     WMI_TAG_WOW_DEL_PATTERN_CMD) |
8520ba9177fcSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8521ba9177fcSCarl Huang 
8522ba9177fcSCarl Huang 	cmd->vdev_id = vdev_id;
8523ba9177fcSCarl Huang 	cmd->pattern_id = pattern_id;
8524ba9177fcSCarl Huang 	cmd->pattern_type = WOW_BITMAP_PATTERN;
8525ba9177fcSCarl Huang 
8526ba9177fcSCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow del pattern vdev_id %d pattern_id %d\n",
8527ba9177fcSCarl Huang 		   vdev_id, pattern_id);
8528ba9177fcSCarl Huang 
8529ba9177fcSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_DEL_WAKE_PATTERN_CMDID);
8530ba9177fcSCarl Huang }
8531fec4b898SCarl Huang 
8532fec4b898SCarl Huang static struct sk_buff *
8533fec4b898SCarl Huang ath11k_wmi_op_gen_config_pno_start(struct ath11k *ar,
8534fec4b898SCarl Huang 				   u32 vdev_id,
8535fec4b898SCarl Huang 				       struct wmi_pno_scan_req *pno)
8536fec4b898SCarl Huang {
8537fec4b898SCarl Huang 	struct nlo_configured_parameters *nlo_list;
8538fec4b898SCarl Huang 	struct wmi_wow_nlo_config_cmd *cmd;
8539fec4b898SCarl Huang 	struct wmi_tlv *tlv;
8540fec4b898SCarl Huang 	struct sk_buff *skb;
8541fec4b898SCarl Huang 	u32 *channel_list;
8542fec4b898SCarl Huang 	size_t len, nlo_list_len, channel_list_len;
8543fec4b898SCarl Huang 	u8 *ptr;
8544fec4b898SCarl Huang 	u32 i;
8545fec4b898SCarl Huang 
8546fec4b898SCarl Huang 	len = sizeof(*cmd) +
8547fec4b898SCarl Huang 	      sizeof(*tlv) +
8548fec4b898SCarl Huang 	      /* TLV place holder for array of structures
8549fec4b898SCarl Huang 	       * nlo_configured_parameters(nlo_list)
8550fec4b898SCarl Huang 	       */
8551fec4b898SCarl Huang 	      sizeof(*tlv);
8552fec4b898SCarl Huang 	      /* TLV place holder for array of uint32 channel_list */
8553fec4b898SCarl Huang 
8554fec4b898SCarl Huang 	channel_list_len = sizeof(u32) * pno->a_networks[0].channel_count;
8555fec4b898SCarl Huang 	len += channel_list_len;
8556fec4b898SCarl Huang 
8557fec4b898SCarl Huang 	nlo_list_len = sizeof(*nlo_list) * pno->uc_networks_count;
8558fec4b898SCarl Huang 	len += nlo_list_len;
8559fec4b898SCarl Huang 
8560fec4b898SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8561fec4b898SCarl Huang 	if (!skb)
8562fec4b898SCarl Huang 		return ERR_PTR(-ENOMEM);
8563fec4b898SCarl Huang 
8564fec4b898SCarl Huang 	ptr = (u8 *)skb->data;
8565fec4b898SCarl Huang 	cmd = (struct wmi_wow_nlo_config_cmd *)ptr;
8566fec4b898SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
8567fec4b898SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8568fec4b898SCarl Huang 
8569fec4b898SCarl Huang 	cmd->vdev_id = pno->vdev_id;
8570fec4b898SCarl Huang 	cmd->flags = WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN;
8571fec4b898SCarl Huang 
8572fec4b898SCarl Huang 	/* current FW does not support min-max range for dwell time */
8573fec4b898SCarl Huang 	cmd->active_dwell_time = pno->active_max_time;
8574fec4b898SCarl Huang 	cmd->passive_dwell_time = pno->passive_max_time;
8575fec4b898SCarl Huang 
8576fec4b898SCarl Huang 	if (pno->do_passive_scan)
8577fec4b898SCarl Huang 		cmd->flags |= WMI_NLO_CONFIG_SCAN_PASSIVE;
8578fec4b898SCarl Huang 
8579fec4b898SCarl Huang 	cmd->fast_scan_period = pno->fast_scan_period;
8580fec4b898SCarl Huang 	cmd->slow_scan_period = pno->slow_scan_period;
8581fec4b898SCarl Huang 	cmd->fast_scan_max_cycles = pno->fast_scan_max_cycles;
8582fec4b898SCarl Huang 	cmd->delay_start_time = pno->delay_start_time;
8583fec4b898SCarl Huang 
8584fec4b898SCarl Huang 	if (pno->enable_pno_scan_randomization) {
8585fec4b898SCarl Huang 		cmd->flags |= WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
8586fec4b898SCarl Huang 				WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ;
8587fec4b898SCarl Huang 		ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
8588fec4b898SCarl Huang 		ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
8589fec4b898SCarl Huang 		ath11k_ce_byte_swap(cmd->mac_addr.addr, 8);
8590fec4b898SCarl Huang 		ath11k_ce_byte_swap(cmd->mac_mask.addr, 8);
8591fec4b898SCarl Huang 	}
8592fec4b898SCarl Huang 
8593fec4b898SCarl Huang 	ptr += sizeof(*cmd);
8594fec4b898SCarl Huang 
8595fec4b898SCarl Huang 	/* nlo_configured_parameters(nlo_list) */
8596fec4b898SCarl Huang 	cmd->no_of_ssids = pno->uc_networks_count;
8597fec4b898SCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8598fec4b898SCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8599fec4b898SCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8600fec4b898SCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, nlo_list_len);
8601fec4b898SCarl Huang 
8602fec4b898SCarl Huang 	ptr += sizeof(*tlv);
8603fec4b898SCarl Huang 	nlo_list = (struct nlo_configured_parameters *)ptr;
8604fec4b898SCarl Huang 	for (i = 0; i < cmd->no_of_ssids; i++) {
8605fec4b898SCarl Huang 		tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
8606fec4b898SCarl Huang 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8607fec4b898SCarl Huang 			      FIELD_PREP(WMI_TLV_LEN, sizeof(*nlo_list) - sizeof(*tlv));
8608fec4b898SCarl Huang 
8609fec4b898SCarl Huang 		nlo_list[i].ssid.valid = true;
8610fec4b898SCarl Huang 		nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
8611fec4b898SCarl Huang 		memcpy(nlo_list[i].ssid.ssid.ssid,
8612fec4b898SCarl Huang 		       pno->a_networks[i].ssid.ssid,
8613fec4b898SCarl Huang 		       nlo_list[i].ssid.ssid.ssid_len);
8614fec4b898SCarl Huang 		ath11k_ce_byte_swap(nlo_list[i].ssid.ssid.ssid,
8615fec4b898SCarl Huang 				    roundup(nlo_list[i].ssid.ssid.ssid_len, 4));
8616fec4b898SCarl Huang 
8617fec4b898SCarl Huang 		if (pno->a_networks[i].rssi_threshold &&
8618fec4b898SCarl Huang 		    pno->a_networks[i].rssi_threshold > -300) {
8619fec4b898SCarl Huang 			nlo_list[i].rssi_cond.valid = true;
8620fec4b898SCarl Huang 			nlo_list[i].rssi_cond.rssi =
8621fec4b898SCarl Huang 				pno->a_networks[i].rssi_threshold;
8622fec4b898SCarl Huang 		}
8623fec4b898SCarl Huang 
8624fec4b898SCarl Huang 		nlo_list[i].bcast_nw_type.valid = true;
8625fec4b898SCarl Huang 		nlo_list[i].bcast_nw_type.bcast_nw_type =
8626fec4b898SCarl Huang 			pno->a_networks[i].bcast_nw_type;
8627fec4b898SCarl Huang 	}
8628fec4b898SCarl Huang 
8629fec4b898SCarl Huang 	ptr += nlo_list_len;
8630fec4b898SCarl Huang 	cmd->num_of_channels = pno->a_networks[0].channel_count;
8631fec4b898SCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8632fec4b898SCarl Huang 	tlv->header =  FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8633fec4b898SCarl Huang 		       FIELD_PREP(WMI_TLV_LEN, channel_list_len);
8634fec4b898SCarl Huang 	ptr += sizeof(*tlv);
8635fec4b898SCarl Huang 	channel_list = (u32 *)ptr;
8636fec4b898SCarl Huang 	for (i = 0; i < cmd->num_of_channels; i++)
8637fec4b898SCarl Huang 		channel_list[i] = pno->a_networks[0].channels[i];
8638fec4b898SCarl Huang 
8639fec4b898SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv start pno config vdev_id %d\n",
8640fec4b898SCarl Huang 		   vdev_id);
8641fec4b898SCarl Huang 
8642fec4b898SCarl Huang 	return skb;
8643fec4b898SCarl Huang }
8644fec4b898SCarl Huang 
8645fec4b898SCarl Huang static struct sk_buff *ath11k_wmi_op_gen_config_pno_stop(struct ath11k *ar,
8646fec4b898SCarl Huang 							 u32 vdev_id)
8647fec4b898SCarl Huang {
8648fec4b898SCarl Huang 	struct wmi_wow_nlo_config_cmd *cmd;
8649fec4b898SCarl Huang 	struct sk_buff *skb;
8650fec4b898SCarl Huang 	size_t len;
8651fec4b898SCarl Huang 
8652fec4b898SCarl Huang 	len = sizeof(*cmd);
8653fec4b898SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8654fec4b898SCarl Huang 	if (!skb)
8655fec4b898SCarl Huang 		return ERR_PTR(-ENOMEM);
8656fec4b898SCarl Huang 
8657fec4b898SCarl Huang 	cmd = (struct wmi_wow_nlo_config_cmd *)skb->data;
8658fec4b898SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
8659fec4b898SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
8660fec4b898SCarl Huang 
8661fec4b898SCarl Huang 	cmd->vdev_id = vdev_id;
8662fec4b898SCarl Huang 	cmd->flags = WMI_NLO_CONFIG_STOP;
8663fec4b898SCarl Huang 
8664fec4b898SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8665fec4b898SCarl Huang 		   "wmi tlv stop pno config vdev_id %d\n", vdev_id);
8666fec4b898SCarl Huang 	return skb;
8667fec4b898SCarl Huang }
8668fec4b898SCarl Huang 
8669fec4b898SCarl Huang int ath11k_wmi_wow_config_pno(struct ath11k *ar, u32 vdev_id,
8670fec4b898SCarl Huang 			      struct wmi_pno_scan_req  *pno_scan)
8671fec4b898SCarl Huang {
8672fec4b898SCarl Huang 	struct sk_buff *skb;
8673fec4b898SCarl Huang 
8674fec4b898SCarl Huang 	if (pno_scan->enable)
8675fec4b898SCarl Huang 		skb = ath11k_wmi_op_gen_config_pno_start(ar, vdev_id, pno_scan);
8676fec4b898SCarl Huang 	else
8677fec4b898SCarl Huang 		skb = ath11k_wmi_op_gen_config_pno_stop(ar, vdev_id);
8678fec4b898SCarl Huang 
8679fec4b898SCarl Huang 	if (IS_ERR_OR_NULL(skb))
8680fec4b898SCarl Huang 		return -ENOMEM;
8681fec4b898SCarl Huang 
8682fec4b898SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
8683fec4b898SCarl Huang }
8684fec4b898SCarl Huang 
8685c3c36bfeSCarl Huang static void ath11k_wmi_fill_ns_offload(struct ath11k *ar,
8686c3c36bfeSCarl Huang 				       struct ath11k_arp_ns_offload *offload,
8687c3c36bfeSCarl Huang 				       u8 **ptr,
8688c3c36bfeSCarl Huang 				       bool enable,
8689c3c36bfeSCarl Huang 				       bool ext)
8690c3c36bfeSCarl Huang {
8691c3c36bfeSCarl Huang 	struct wmi_ns_offload_tuple *ns;
8692c3c36bfeSCarl Huang 	struct wmi_tlv *tlv;
8693c3c36bfeSCarl Huang 	u8 *buf_ptr = *ptr;
8694c3c36bfeSCarl Huang 	u32 ns_cnt, ns_ext_tuples;
8695c3c36bfeSCarl Huang 	int i, max_offloads;
8696c3c36bfeSCarl Huang 
8697c3c36bfeSCarl Huang 	ns_cnt = offload->ipv6_count;
8698c3c36bfeSCarl Huang 
8699c3c36bfeSCarl Huang 	tlv  = (struct wmi_tlv *)buf_ptr;
8700c3c36bfeSCarl Huang 
8701c3c36bfeSCarl Huang 	if (ext) {
8702c3c36bfeSCarl Huang 		ns_ext_tuples = offload->ipv6_count - WMI_MAX_NS_OFFLOADS;
8703c3c36bfeSCarl Huang 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8704c3c36bfeSCarl Huang 			      FIELD_PREP(WMI_TLV_LEN, ns_ext_tuples * sizeof(*ns));
8705c3c36bfeSCarl Huang 		i = WMI_MAX_NS_OFFLOADS;
8706c3c36bfeSCarl Huang 		max_offloads = offload->ipv6_count;
8707c3c36bfeSCarl Huang 	} else {
8708c3c36bfeSCarl Huang 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8709c3c36bfeSCarl Huang 			      FIELD_PREP(WMI_TLV_LEN, WMI_MAX_NS_OFFLOADS * sizeof(*ns));
8710c3c36bfeSCarl Huang 		i = 0;
8711c3c36bfeSCarl Huang 		max_offloads = WMI_MAX_NS_OFFLOADS;
8712c3c36bfeSCarl Huang 	}
8713c3c36bfeSCarl Huang 
8714c3c36bfeSCarl Huang 	buf_ptr += sizeof(*tlv);
8715c3c36bfeSCarl Huang 
8716c3c36bfeSCarl Huang 	for (; i < max_offloads; i++) {
8717c3c36bfeSCarl Huang 		ns = (struct wmi_ns_offload_tuple *)buf_ptr;
8718c3c36bfeSCarl Huang 		ns->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NS_OFFLOAD_TUPLE) |
8719c3c36bfeSCarl Huang 				 FIELD_PREP(WMI_TLV_LEN, sizeof(*ns) - TLV_HDR_SIZE);
8720c3c36bfeSCarl Huang 
8721c3c36bfeSCarl Huang 		if (enable) {
8722c3c36bfeSCarl Huang 			if (i < ns_cnt)
8723c3c36bfeSCarl Huang 				ns->flags |= WMI_NSOL_FLAGS_VALID;
8724c3c36bfeSCarl Huang 
8725c3c36bfeSCarl Huang 			memcpy(ns->target_ipaddr[0], offload->ipv6_addr[i], 16);
8726c3c36bfeSCarl Huang 			memcpy(ns->solicitation_ipaddr, offload->self_ipv6_addr[i], 16);
8727c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(ns->target_ipaddr[0], 16);
8728c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(ns->solicitation_ipaddr, 16);
8729c3c36bfeSCarl Huang 
8730c3c36bfeSCarl Huang 			if (offload->ipv6_type[i])
8731c3c36bfeSCarl Huang 				ns->flags |= WMI_NSOL_FLAGS_IS_IPV6_ANYCAST;
8732c3c36bfeSCarl Huang 
8733c3c36bfeSCarl Huang 			memcpy(ns->target_mac.addr, offload->mac_addr, ETH_ALEN);
8734c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(ns->target_mac.addr, 8);
8735c3c36bfeSCarl Huang 
8736c3c36bfeSCarl Huang 			if (ns->target_mac.word0 != 0 ||
8737c3c36bfeSCarl Huang 			    ns->target_mac.word1 != 0) {
8738c3c36bfeSCarl Huang 				ns->flags |= WMI_NSOL_FLAGS_MAC_VALID;
8739c3c36bfeSCarl Huang 			}
8740c3c36bfeSCarl Huang 
8741c3c36bfeSCarl Huang 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8742c3c36bfeSCarl Huang 				   "wmi index %d ns_solicited %pI6 target %pI6",
8743c3c36bfeSCarl Huang 				   i, ns->solicitation_ipaddr,
8744c3c36bfeSCarl Huang 				   ns->target_ipaddr[0]);
8745c3c36bfeSCarl Huang 		}
8746c3c36bfeSCarl Huang 
8747c3c36bfeSCarl Huang 		buf_ptr += sizeof(*ns);
8748c3c36bfeSCarl Huang 	}
8749c3c36bfeSCarl Huang 
8750c3c36bfeSCarl Huang 	*ptr = buf_ptr;
8751c3c36bfeSCarl Huang }
8752c3c36bfeSCarl Huang 
8753c3c36bfeSCarl Huang static void ath11k_wmi_fill_arp_offload(struct ath11k *ar,
8754c3c36bfeSCarl Huang 					struct ath11k_arp_ns_offload *offload,
8755c3c36bfeSCarl Huang 					u8 **ptr,
8756c3c36bfeSCarl Huang 					bool enable)
8757c3c36bfeSCarl Huang {
8758c3c36bfeSCarl Huang 	struct wmi_arp_offload_tuple *arp;
8759c3c36bfeSCarl Huang 	struct wmi_tlv *tlv;
8760c3c36bfeSCarl Huang 	u8 *buf_ptr = *ptr;
8761c3c36bfeSCarl Huang 	int i;
8762c3c36bfeSCarl Huang 
8763c3c36bfeSCarl Huang 	/* fill arp tuple */
8764c3c36bfeSCarl Huang 	tlv = (struct wmi_tlv *)buf_ptr;
8765c3c36bfeSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8766c3c36bfeSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, WMI_MAX_ARP_OFFLOADS * sizeof(*arp));
8767c3c36bfeSCarl Huang 	buf_ptr += sizeof(*tlv);
8768c3c36bfeSCarl Huang 
8769c3c36bfeSCarl Huang 	for (i = 0; i < WMI_MAX_ARP_OFFLOADS; i++) {
8770c3c36bfeSCarl Huang 		arp = (struct wmi_arp_offload_tuple *)buf_ptr;
8771c3c36bfeSCarl Huang 		arp->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARP_OFFLOAD_TUPLE) |
8772c3c36bfeSCarl Huang 				  FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
8773c3c36bfeSCarl Huang 
8774c3c36bfeSCarl Huang 		if (enable && i < offload->ipv4_count) {
8775c3c36bfeSCarl Huang 			/* Copy the target ip addr and flags */
8776c3c36bfeSCarl Huang 			arp->flags = WMI_ARPOL_FLAGS_VALID;
8777c3c36bfeSCarl Huang 			memcpy(arp->target_ipaddr, offload->ipv4_addr[i], 4);
8778c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(arp->target_ipaddr, 4);
8779c3c36bfeSCarl Huang 
8780c3c36bfeSCarl Huang 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi arp offload address %pI4",
8781c3c36bfeSCarl Huang 				   arp->target_ipaddr);
8782c3c36bfeSCarl Huang 		}
8783c3c36bfeSCarl Huang 
8784c3c36bfeSCarl Huang 		buf_ptr += sizeof(*arp);
8785c3c36bfeSCarl Huang 	}
8786c3c36bfeSCarl Huang 
8787c3c36bfeSCarl Huang 	*ptr = buf_ptr;
8788c3c36bfeSCarl Huang }
8789c3c36bfeSCarl Huang 
8790c3c36bfeSCarl Huang int ath11k_wmi_arp_ns_offload(struct ath11k *ar,
8791c3c36bfeSCarl Huang 			      struct ath11k_vif *arvif, bool enable)
8792c3c36bfeSCarl Huang {
8793c3c36bfeSCarl Huang 	struct ath11k_arp_ns_offload *offload;
8794c3c36bfeSCarl Huang 	struct wmi_set_arp_ns_offload_cmd *cmd;
8795c3c36bfeSCarl Huang 	struct wmi_tlv *tlv;
8796c3c36bfeSCarl Huang 	struct sk_buff *skb;
8797c3c36bfeSCarl Huang 	u8 *buf_ptr;
8798c3c36bfeSCarl Huang 	size_t len;
8799c3c36bfeSCarl Huang 	u8 ns_cnt, ns_ext_tuples = 0;
8800c3c36bfeSCarl Huang 
8801c3c36bfeSCarl Huang 	offload = &arvif->arp_ns_offload;
8802c3c36bfeSCarl Huang 	ns_cnt = offload->ipv6_count;
8803c3c36bfeSCarl Huang 
8804c3c36bfeSCarl Huang 	len = sizeof(*cmd) +
8805c3c36bfeSCarl Huang 	      sizeof(*tlv) +
8806c3c36bfeSCarl Huang 	      WMI_MAX_NS_OFFLOADS * sizeof(struct wmi_ns_offload_tuple) +
8807c3c36bfeSCarl Huang 	      sizeof(*tlv) +
8808c3c36bfeSCarl Huang 	      WMI_MAX_ARP_OFFLOADS * sizeof(struct wmi_arp_offload_tuple);
8809c3c36bfeSCarl Huang 
8810c3c36bfeSCarl Huang 	if (ns_cnt > WMI_MAX_NS_OFFLOADS) {
8811c3c36bfeSCarl Huang 		ns_ext_tuples = ns_cnt - WMI_MAX_NS_OFFLOADS;
8812c3c36bfeSCarl Huang 		len += sizeof(*tlv) +
8813c3c36bfeSCarl Huang 		       ns_ext_tuples * sizeof(struct wmi_ns_offload_tuple);
8814c3c36bfeSCarl Huang 	}
8815c3c36bfeSCarl Huang 
8816c3c36bfeSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8817c3c36bfeSCarl Huang 	if (!skb)
8818c3c36bfeSCarl Huang 		return -ENOMEM;
8819c3c36bfeSCarl Huang 
8820c3c36bfeSCarl Huang 	buf_ptr = skb->data;
8821c3c36bfeSCarl Huang 	cmd = (struct wmi_set_arp_ns_offload_cmd *)buf_ptr;
8822c3c36bfeSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8823c3c36bfeSCarl Huang 				     WMI_TAG_SET_ARP_NS_OFFLOAD_CMD) |
8824c3c36bfeSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8825c3c36bfeSCarl Huang 
8826c3c36bfeSCarl Huang 	cmd->flags = 0;
8827c3c36bfeSCarl Huang 	cmd->vdev_id = arvif->vdev_id;
8828c3c36bfeSCarl Huang 	cmd->num_ns_ext_tuples = ns_ext_tuples;
8829c3c36bfeSCarl Huang 
8830c3c36bfeSCarl Huang 	buf_ptr += sizeof(*cmd);
8831c3c36bfeSCarl Huang 
8832c3c36bfeSCarl Huang 	ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 0);
8833c3c36bfeSCarl Huang 	ath11k_wmi_fill_arp_offload(ar, offload, &buf_ptr, enable);
8834c3c36bfeSCarl Huang 
8835c3c36bfeSCarl Huang 	if (ns_ext_tuples)
8836c3c36bfeSCarl Huang 		ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 1);
8837c3c36bfeSCarl Huang 
8838c3c36bfeSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SET_ARP_NS_OFFLOAD_CMDID);
8839c3c36bfeSCarl Huang }
8840a16d9b50SCarl Huang 
8841a16d9b50SCarl Huang int ath11k_wmi_gtk_rekey_offload(struct ath11k *ar,
8842a16d9b50SCarl Huang 				 struct ath11k_vif *arvif, bool enable)
8843a16d9b50SCarl Huang {
8844a16d9b50SCarl Huang 	struct wmi_gtk_rekey_offload_cmd *cmd;
8845a16d9b50SCarl Huang 	struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
8846a16d9b50SCarl Huang 	int len;
8847a16d9b50SCarl Huang 	struct sk_buff *skb;
8848a16d9b50SCarl Huang 	__le64 replay_ctr;
8849a16d9b50SCarl Huang 
8850a16d9b50SCarl Huang 	len = sizeof(*cmd);
8851a16d9b50SCarl Huang 	skb =  ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8852a16d9b50SCarl Huang 	if (!skb)
8853a16d9b50SCarl Huang 		return -ENOMEM;
8854a16d9b50SCarl Huang 
8855a16d9b50SCarl Huang 	cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
8856a16d9b50SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
8857a16d9b50SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8858a16d9b50SCarl Huang 
8859a16d9b50SCarl Huang 	cmd->vdev_id = arvif->vdev_id;
8860a16d9b50SCarl Huang 
8861a16d9b50SCarl Huang 	if (enable) {
8862a16d9b50SCarl Huang 		cmd->flags = GTK_OFFLOAD_ENABLE_OPCODE;
8863a16d9b50SCarl Huang 
8864a16d9b50SCarl Huang 		/* the length in rekey_data and cmd is equal */
8865a16d9b50SCarl Huang 		memcpy(cmd->kck, rekey_data->kck, sizeof(cmd->kck));
8866a16d9b50SCarl Huang 		ath11k_ce_byte_swap(cmd->kck, GTK_OFFLOAD_KEK_BYTES);
8867a16d9b50SCarl Huang 		memcpy(cmd->kek, rekey_data->kek, sizeof(cmd->kek));
8868a16d9b50SCarl Huang 		ath11k_ce_byte_swap(cmd->kek, GTK_OFFLOAD_KEK_BYTES);
8869a16d9b50SCarl Huang 
8870a16d9b50SCarl Huang 		replay_ctr = cpu_to_le64(rekey_data->replay_ctr);
8871a16d9b50SCarl Huang 		memcpy(cmd->replay_ctr, &replay_ctr,
8872a16d9b50SCarl Huang 		       sizeof(replay_ctr));
8873a16d9b50SCarl Huang 		ath11k_ce_byte_swap(cmd->replay_ctr, GTK_REPLAY_COUNTER_BYTES);
8874a16d9b50SCarl Huang 	} else {
8875a16d9b50SCarl Huang 		cmd->flags = GTK_OFFLOAD_DISABLE_OPCODE;
8876a16d9b50SCarl Huang 	}
8877a16d9b50SCarl Huang 
8878a16d9b50SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "offload gtk rekey vdev: %d %d\n",
8879a16d9b50SCarl Huang 		   arvif->vdev_id, enable);
8880a16d9b50SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
8881a16d9b50SCarl Huang }
8882a16d9b50SCarl Huang 
8883a16d9b50SCarl Huang int ath11k_wmi_gtk_rekey_getinfo(struct ath11k *ar,
8884a16d9b50SCarl Huang 				 struct ath11k_vif *arvif)
8885a16d9b50SCarl Huang {
8886a16d9b50SCarl Huang 	struct wmi_gtk_rekey_offload_cmd *cmd;
8887a16d9b50SCarl Huang 	int len;
8888a16d9b50SCarl Huang 	struct sk_buff *skb;
8889a16d9b50SCarl Huang 
8890a16d9b50SCarl Huang 	len = sizeof(*cmd);
8891a16d9b50SCarl Huang 	skb =  ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8892a16d9b50SCarl Huang 	if (!skb)
8893a16d9b50SCarl Huang 		return -ENOMEM;
8894a16d9b50SCarl Huang 
8895a16d9b50SCarl Huang 	cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
8896a16d9b50SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
8897a16d9b50SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8898a16d9b50SCarl Huang 
8899a16d9b50SCarl Huang 	cmd->vdev_id = arvif->vdev_id;
8900a16d9b50SCarl Huang 	cmd->flags = GTK_OFFLOAD_REQUEST_STATUS_OPCODE;
8901a16d9b50SCarl Huang 
8902a16d9b50SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "get gtk rekey vdev_id: %d\n",
8903a16d9b50SCarl Huang 		   arvif->vdev_id);
8904a16d9b50SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
8905a16d9b50SCarl Huang }
8906652f69edSBaochen Qiang 
8907652f69edSBaochen Qiang int ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k *ar, const u8 *sar_val)
8908652f69edSBaochen Qiang {	struct ath11k_pdev_wmi *wmi = ar->wmi;
8909652f69edSBaochen Qiang 	struct wmi_pdev_set_sar_table_cmd *cmd;
8910652f69edSBaochen Qiang 	struct wmi_tlv *tlv;
8911652f69edSBaochen Qiang 	struct sk_buff *skb;
8912652f69edSBaochen Qiang 	u8 *buf_ptr;
8913652f69edSBaochen Qiang 	u32 len, sar_len_aligned, rsvd_len_aligned;
8914652f69edSBaochen Qiang 
8915652f69edSBaochen Qiang 	sar_len_aligned = roundup(BIOS_SAR_TABLE_LEN, sizeof(u32));
8916652f69edSBaochen Qiang 	rsvd_len_aligned = roundup(BIOS_SAR_RSVD1_LEN, sizeof(u32));
8917652f69edSBaochen Qiang 	len = sizeof(*cmd) +
8918652f69edSBaochen Qiang 	      TLV_HDR_SIZE + sar_len_aligned +
8919652f69edSBaochen Qiang 	      TLV_HDR_SIZE + rsvd_len_aligned;
8920652f69edSBaochen Qiang 
8921652f69edSBaochen Qiang 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8922652f69edSBaochen Qiang 	if (!skb)
8923652f69edSBaochen Qiang 		return -ENOMEM;
8924652f69edSBaochen Qiang 
8925652f69edSBaochen Qiang 	cmd = (struct wmi_pdev_set_sar_table_cmd *)skb->data;
8926652f69edSBaochen Qiang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_SAR_TABLE_CMD) |
8927652f69edSBaochen Qiang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8928652f69edSBaochen Qiang 	cmd->pdev_id = ar->pdev->pdev_id;
8929652f69edSBaochen Qiang 	cmd->sar_len = BIOS_SAR_TABLE_LEN;
8930652f69edSBaochen Qiang 	cmd->rsvd_len = BIOS_SAR_RSVD1_LEN;
8931652f69edSBaochen Qiang 
8932652f69edSBaochen Qiang 	buf_ptr = skb->data + sizeof(*cmd);
8933652f69edSBaochen Qiang 	tlv = (struct wmi_tlv *)buf_ptr;
8934652f69edSBaochen Qiang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8935652f69edSBaochen Qiang 		      FIELD_PREP(WMI_TLV_LEN, sar_len_aligned);
8936652f69edSBaochen Qiang 	buf_ptr += TLV_HDR_SIZE;
8937652f69edSBaochen Qiang 	memcpy(buf_ptr, sar_val, BIOS_SAR_TABLE_LEN);
8938652f69edSBaochen Qiang 
8939652f69edSBaochen Qiang 	buf_ptr += sar_len_aligned;
8940652f69edSBaochen Qiang 	tlv = (struct wmi_tlv *)buf_ptr;
8941652f69edSBaochen Qiang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8942652f69edSBaochen Qiang 		      FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
8943652f69edSBaochen Qiang 
8944652f69edSBaochen Qiang 	return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_SAR_TABLE_CMDID);
8945652f69edSBaochen Qiang }
8946652f69edSBaochen Qiang 
8947652f69edSBaochen Qiang int ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k *ar)
8948652f69edSBaochen Qiang {
8949652f69edSBaochen Qiang 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8950652f69edSBaochen Qiang 	struct wmi_pdev_set_geo_table_cmd *cmd;
8951652f69edSBaochen Qiang 	struct wmi_tlv *tlv;
8952652f69edSBaochen Qiang 	struct sk_buff *skb;
8953652f69edSBaochen Qiang 	u8 *buf_ptr;
8954652f69edSBaochen Qiang 	u32 len, rsvd_len_aligned;
8955652f69edSBaochen Qiang 
8956652f69edSBaochen Qiang 	rsvd_len_aligned = roundup(BIOS_SAR_RSVD2_LEN, sizeof(u32));
8957652f69edSBaochen Qiang 	len = sizeof(*cmd) + TLV_HDR_SIZE + rsvd_len_aligned;
8958652f69edSBaochen Qiang 
8959652f69edSBaochen Qiang 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8960652f69edSBaochen Qiang 	if (!skb)
8961652f69edSBaochen Qiang 		return -ENOMEM;
8962652f69edSBaochen Qiang 
8963652f69edSBaochen Qiang 	cmd = (struct wmi_pdev_set_geo_table_cmd *)skb->data;
8964652f69edSBaochen Qiang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_GEO_TABLE_CMD) |
8965652f69edSBaochen Qiang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8966652f69edSBaochen Qiang 	cmd->pdev_id = ar->pdev->pdev_id;
8967652f69edSBaochen Qiang 	cmd->rsvd_len = BIOS_SAR_RSVD2_LEN;
8968652f69edSBaochen Qiang 
8969652f69edSBaochen Qiang 	buf_ptr = skb->data + sizeof(*cmd);
8970652f69edSBaochen Qiang 	tlv = (struct wmi_tlv *)buf_ptr;
8971652f69edSBaochen Qiang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8972652f69edSBaochen Qiang 		      FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
8973652f69edSBaochen Qiang 
8974652f69edSBaochen Qiang 	return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_GEO_TABLE_CMDID);
8975652f69edSBaochen Qiang }
89760f84a156SBaochen Qiang 
89770f84a156SBaochen Qiang int ath11k_wmi_sta_keepalive(struct ath11k *ar,
89780f84a156SBaochen Qiang 			     const struct wmi_sta_keepalive_arg *arg)
89790f84a156SBaochen Qiang {
89800f84a156SBaochen Qiang 	struct ath11k_pdev_wmi *wmi = ar->wmi;
89810f84a156SBaochen Qiang 	struct wmi_sta_keepalive_cmd *cmd;
89820f84a156SBaochen Qiang 	struct wmi_sta_keepalive_arp_resp *arp;
89830f84a156SBaochen Qiang 	struct sk_buff *skb;
89840f84a156SBaochen Qiang 	size_t len;
89850f84a156SBaochen Qiang 
89860f84a156SBaochen Qiang 	len = sizeof(*cmd) + sizeof(*arp);
89870f84a156SBaochen Qiang 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
89880f84a156SBaochen Qiang 	if (!skb)
89890f84a156SBaochen Qiang 		return -ENOMEM;
89900f84a156SBaochen Qiang 
89910f84a156SBaochen Qiang 	cmd = (struct wmi_sta_keepalive_cmd *)skb->data;
89920f84a156SBaochen Qiang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
89930f84a156SBaochen Qiang 				     WMI_TAG_STA_KEEPALIVE_CMD) |
89940f84a156SBaochen Qiang 				     FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
89950f84a156SBaochen Qiang 	cmd->vdev_id = arg->vdev_id;
89960f84a156SBaochen Qiang 	cmd->enabled = arg->enabled;
89970f84a156SBaochen Qiang 	cmd->interval = arg->interval;
89980f84a156SBaochen Qiang 	cmd->method = arg->method;
89990f84a156SBaochen Qiang 
90000f84a156SBaochen Qiang 	arp = (struct wmi_sta_keepalive_arp_resp *)(cmd + 1);
90010f84a156SBaochen Qiang 	arp->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9002*b7b6f861SBaochen Qiang 				     WMI_TAG_STA_KEEPALIVE_ARP_RESPONSE) |
90030f84a156SBaochen Qiang 			 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9004*b7b6f861SBaochen Qiang 
9005*b7b6f861SBaochen Qiang 	if (arg->method == WMI_STA_KEEPALIVE_METHOD_UNSOLICITED_ARP_RESPONSE ||
9006*b7b6f861SBaochen Qiang 	    arg->method == WMI_STA_KEEPALIVE_METHOD_GRATUITOUS_ARP_REQUEST) {
90070f84a156SBaochen Qiang 		arp->src_ip4_addr = arg->src_ip4_addr;
90080f84a156SBaochen Qiang 		arp->dest_ip4_addr = arg->dest_ip4_addr;
90090f84a156SBaochen Qiang 		ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
90100f84a156SBaochen Qiang 	}
90110f84a156SBaochen Qiang 
90120f84a156SBaochen Qiang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
90130f84a156SBaochen Qiang 		   "wmi sta keepalive vdev %d enabled %d method %d interval %d\n",
90140f84a156SBaochen Qiang 		   arg->vdev_id, arg->enabled, arg->method, arg->interval);
90150f84a156SBaochen Qiang 
90160f84a156SBaochen Qiang 	return ath11k_wmi_cmd_send(wmi, skb, WMI_STA_KEEPALIVE_CMDID);
90170f84a156SBaochen Qiang }
9018