xref: /openbmc/linux/drivers/net/wireless/ath/ath11k/wmi.c (revision 25e289e1f52e1f4fb1d07622c6a24f8d8a8e420d)
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;
2071cf8f3d4dSTamizh Chelvam Raja 
2072cf8f3d4dSTamizh Chelvam Raja 	if (test_bit(WMI_TLV_SERVICE_PASSIVE_SCAN_START_TIME_ENHANCE,
2073cf8f3d4dSTamizh Chelvam Raja 		     ar->ab->wmi_ab.svc_map))
2074cf8f3d4dSTamizh Chelvam Raja 		arg->scan_ctrl_flags_ext |=
2075cf8f3d4dSTamizh Chelvam Raja 			WMI_SCAN_FLAG_EXT_PASSIVE_SCAN_START_TIME_ENHANCE;
2076cf8f3d4dSTamizh Chelvam Raja 
2077d5c65159SKalle Valo 	arg->num_bssid = 1;
2078fa7572c2SCarl Huang 
2079fa7572c2SCarl Huang 	/* fill bssid_list[0] with 0xff, otherwise bssid and RA will be
2080fa7572c2SCarl Huang 	 * ZEROs in probe request
2081fa7572c2SCarl Huang 	 */
2082fa7572c2SCarl Huang 	eth_broadcast_addr(arg->bssid_list[0].addr);
2083d5c65159SKalle Valo }
2084d5c65159SKalle Valo 
2085d5c65159SKalle Valo static inline void
2086d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
2087d5c65159SKalle Valo 				       struct scan_req_params *param)
2088d5c65159SKalle Valo {
2089d5c65159SKalle Valo 	/* Scan events subscription */
2090d5c65159SKalle Valo 	if (param->scan_ev_started)
2091d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_STARTED;
2092d5c65159SKalle Valo 	if (param->scan_ev_completed)
2093d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_COMPLETED;
2094d5c65159SKalle Valo 	if (param->scan_ev_bss_chan)
2095d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_BSS_CHANNEL;
2096d5c65159SKalle Valo 	if (param->scan_ev_foreign_chan)
2097d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN;
2098d5c65159SKalle Valo 	if (param->scan_ev_dequeued)
2099d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_DEQUEUED;
2100d5c65159SKalle Valo 	if (param->scan_ev_preempted)
2101d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_PREEMPTED;
2102d5c65159SKalle Valo 	if (param->scan_ev_start_failed)
2103d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_START_FAILED;
2104d5c65159SKalle Valo 	if (param->scan_ev_restarted)
2105d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESTARTED;
2106d5c65159SKalle Valo 	if (param->scan_ev_foreign_chn_exit)
2107d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
2108d5c65159SKalle Valo 	if (param->scan_ev_suspended)
2109d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_SUSPENDED;
2110d5c65159SKalle Valo 	if (param->scan_ev_resumed)
2111d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESUMED;
2112d5c65159SKalle Valo 
2113d5c65159SKalle Valo 	/** Set scan control flags */
2114d5c65159SKalle Valo 	cmd->scan_ctrl_flags = 0;
2115d5c65159SKalle Valo 	if (param->scan_f_passive)
2116d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_PASSIVE;
2117d5c65159SKalle Valo 	if (param->scan_f_strict_passive_pch)
2118d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
2119d5c65159SKalle Valo 	if (param->scan_f_promisc_mode)
2120d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROMISCUOS;
2121d5c65159SKalle Valo 	if (param->scan_f_capture_phy_err)
2122d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CAPTURE_PHY_ERROR;
2123d5c65159SKalle Valo 	if (param->scan_f_half_rate)
2124d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
2125d5c65159SKalle Valo 	if (param->scan_f_quarter_rate)
2126d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
2127d5c65159SKalle Valo 	if (param->scan_f_cck_rates)
2128d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_CCK_RATES;
2129d5c65159SKalle Valo 	if (param->scan_f_ofdm_rates)
2130d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_OFDM_RATES;
2131d5c65159SKalle Valo 	if (param->scan_f_chan_stat_evnt)
2132d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CHAN_STAT_EVENT;
2133d5c65159SKalle Valo 	if (param->scan_f_filter_prb_req)
2134d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROBE_REQ;
2135d5c65159SKalle Valo 	if (param->scan_f_bcast_probe)
2136d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_BCAST_PROBE_REQ;
2137d5c65159SKalle Valo 	if (param->scan_f_offchan_mgmt_tx)
2138d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_MGMT_TX;
2139d5c65159SKalle Valo 	if (param->scan_f_offchan_data_tx)
2140d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_DATA_TX;
2141d5c65159SKalle Valo 	if (param->scan_f_force_active_dfs_chn)
2142d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
2143d5c65159SKalle Valo 	if (param->scan_f_add_tpc_ie_in_probe)
2144d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
2145d5c65159SKalle Valo 	if (param->scan_f_add_ds_ie_in_probe)
2146d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
2147d5c65159SKalle Valo 	if (param->scan_f_add_spoofed_mac_in_probe)
2148d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
2149d5c65159SKalle Valo 	if (param->scan_f_add_rand_seq_in_probe)
2150d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
2151d5c65159SKalle Valo 	if (param->scan_f_en_ie_whitelist_in_probe)
2152d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=
2153d5c65159SKalle Valo 			 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
2154d5c65159SKalle Valo 
2155d5c65159SKalle Valo 	/* for adaptive scan mode using 3 bits (21 - 23 bits) */
2156d5c65159SKalle Valo 	WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
2157d5c65159SKalle Valo 				param->adaptive_dwell_time_mode);
2158cf8f3d4dSTamizh Chelvam Raja 
2159cf8f3d4dSTamizh Chelvam Raja 	cmd->scan_ctrl_flags_ext = param->scan_ctrl_flags_ext;
2160d5c65159SKalle Valo }
2161d5c65159SKalle Valo 
2162d5c65159SKalle Valo int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
2163d5c65159SKalle Valo 				   struct scan_req_params *params)
2164d5c65159SKalle Valo {
2165d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2166d5c65159SKalle Valo 	struct wmi_start_scan_cmd *cmd;
2167d5c65159SKalle Valo 	struct wmi_ssid *ssid = NULL;
2168d5c65159SKalle Valo 	struct wmi_mac_addr *bssid;
2169d5c65159SKalle Valo 	struct sk_buff *skb;
2170d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2171d5c65159SKalle Valo 	void *ptr;
2172d5c65159SKalle Valo 	int i, ret, len;
2173d5c65159SKalle Valo 	u32 *tmp_ptr;
2174a658c929SSven Eckelmann 	u16 extraie_len_with_pad = 0;
217574601ecfSPradeep Kumar Chitrapu 	struct hint_short_ssid *s_ssid = NULL;
217674601ecfSPradeep Kumar Chitrapu 	struct hint_bssid *hint_bssid = NULL;
2177d5c65159SKalle Valo 
2178d5c65159SKalle Valo 	len = sizeof(*cmd);
2179d5c65159SKalle Valo 
2180d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2181d5c65159SKalle Valo 	if (params->num_chan)
2182d5c65159SKalle Valo 		len += params->num_chan * sizeof(u32);
2183d5c65159SKalle Valo 
2184d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2185d5c65159SKalle Valo 	if (params->num_ssids)
2186d5c65159SKalle Valo 		len += params->num_ssids * sizeof(*ssid);
2187d5c65159SKalle Valo 
2188d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2189d5c65159SKalle Valo 	if (params->num_bssid)
2190d5c65159SKalle Valo 		len += sizeof(*bssid) * params->num_bssid;
2191d5c65159SKalle Valo 
2192d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2193a658c929SSven Eckelmann 	if (params->extraie.len && params->extraie.len <= 0xFFFF)
2194d5c65159SKalle Valo 		extraie_len_with_pad =
2195d5c65159SKalle Valo 			roundup(params->extraie.len, sizeof(u32));
2196d5c65159SKalle Valo 	len += extraie_len_with_pad;
2197d5c65159SKalle Valo 
219874601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid)
219974601ecfSPradeep Kumar Chitrapu 		len += TLV_HDR_SIZE +
220074601ecfSPradeep Kumar Chitrapu 		       params->num_hint_bssid * sizeof(struct hint_bssid);
220174601ecfSPradeep Kumar Chitrapu 
220274601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid)
220374601ecfSPradeep Kumar Chitrapu 		len += TLV_HDR_SIZE +
220474601ecfSPradeep Kumar Chitrapu 		       params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
220574601ecfSPradeep Kumar Chitrapu 
22066bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2207d5c65159SKalle Valo 	if (!skb)
2208d5c65159SKalle Valo 		return -ENOMEM;
2209d5c65159SKalle Valo 
2210d5c65159SKalle Valo 	ptr = skb->data;
2211d5c65159SKalle Valo 
2212d5c65159SKalle Valo 	cmd = ptr;
2213d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
2214d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2215d5c65159SKalle Valo 
2216d5c65159SKalle Valo 	cmd->scan_id = params->scan_id;
2217d5c65159SKalle Valo 	cmd->scan_req_id = params->scan_req_id;
2218d5c65159SKalle Valo 	cmd->vdev_id = params->vdev_id;
2219d5c65159SKalle Valo 	cmd->scan_priority = params->scan_priority;
2220d5c65159SKalle Valo 	cmd->notify_scan_events = params->notify_scan_events;
2221d5c65159SKalle Valo 
2222d5c65159SKalle Valo 	ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
2223d5c65159SKalle Valo 
2224d5c65159SKalle Valo 	cmd->dwell_time_active = params->dwell_time_active;
2225d5c65159SKalle Valo 	cmd->dwell_time_active_2g = params->dwell_time_active_2g;
2226d5c65159SKalle Valo 	cmd->dwell_time_passive = params->dwell_time_passive;
2227194b8ea1SPradeep Kumar Chitrapu 	cmd->dwell_time_active_6g = params->dwell_time_active_6g;
2228194b8ea1SPradeep Kumar Chitrapu 	cmd->dwell_time_passive_6g = params->dwell_time_passive_6g;
2229d5c65159SKalle Valo 	cmd->min_rest_time = params->min_rest_time;
2230d5c65159SKalle Valo 	cmd->max_rest_time = params->max_rest_time;
2231d5c65159SKalle Valo 	cmd->repeat_probe_time = params->repeat_probe_time;
2232d5c65159SKalle Valo 	cmd->probe_spacing_time = params->probe_spacing_time;
2233d5c65159SKalle Valo 	cmd->idle_time = params->idle_time;
2234d5c65159SKalle Valo 	cmd->max_scan_time = params->max_scan_time;
2235d5c65159SKalle Valo 	cmd->probe_delay = params->probe_delay;
2236d5c65159SKalle Valo 	cmd->burst_duration = params->burst_duration;
2237d5c65159SKalle Valo 	cmd->num_chan = params->num_chan;
2238d5c65159SKalle Valo 	cmd->num_bssid = params->num_bssid;
2239d5c65159SKalle Valo 	cmd->num_ssids = params->num_ssids;
2240d5c65159SKalle Valo 	cmd->ie_len = params->extraie.len;
2241d5c65159SKalle Valo 	cmd->n_probes = params->n_probes;
22429cbd7fc9SCarl Huang 	ether_addr_copy(cmd->mac_addr.addr, params->mac_addr.addr);
22439cbd7fc9SCarl Huang 	ether_addr_copy(cmd->mac_mask.addr, params->mac_mask.addr);
2244d5c65159SKalle Valo 
2245d5c65159SKalle Valo 	ptr += sizeof(*cmd);
2246d5c65159SKalle Valo 
2247d5c65159SKalle Valo 	len = params->num_chan * sizeof(u32);
2248d5c65159SKalle Valo 
2249d5c65159SKalle Valo 	tlv = ptr;
2250d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
2251d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2252d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2253d5c65159SKalle Valo 	tmp_ptr = (u32 *)ptr;
2254d5c65159SKalle Valo 
2255d5c65159SKalle Valo 	for (i = 0; i < params->num_chan; ++i)
2256d5c65159SKalle Valo 		tmp_ptr[i] = params->chan_list[i];
2257d5c65159SKalle Valo 
2258d5c65159SKalle Valo 	ptr += len;
2259d5c65159SKalle Valo 
2260d5c65159SKalle Valo 	len = params->num_ssids * sizeof(*ssid);
2261d5c65159SKalle Valo 	tlv = ptr;
2262d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2263d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2264d5c65159SKalle Valo 
2265d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2266d5c65159SKalle Valo 
2267d5c65159SKalle Valo 	if (params->num_ssids) {
2268d5c65159SKalle Valo 		ssid = ptr;
2269d5c65159SKalle Valo 		for (i = 0; i < params->num_ssids; ++i) {
2270d5c65159SKalle Valo 			ssid->ssid_len = params->ssid[i].length;
2271d5c65159SKalle Valo 			memcpy(ssid->ssid, params->ssid[i].ssid,
2272d5c65159SKalle Valo 			       params->ssid[i].length);
2273d5c65159SKalle Valo 			ssid++;
2274d5c65159SKalle Valo 		}
2275d5c65159SKalle Valo 	}
2276d5c65159SKalle Valo 
2277d5c65159SKalle Valo 	ptr += (params->num_ssids * sizeof(*ssid));
2278d5c65159SKalle Valo 	len = params->num_bssid * sizeof(*bssid);
2279d5c65159SKalle Valo 	tlv = ptr;
2280d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2281d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2282d5c65159SKalle Valo 
2283d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2284d5c65159SKalle Valo 	bssid = ptr;
2285d5c65159SKalle Valo 
2286d5c65159SKalle Valo 	if (params->num_bssid) {
2287d5c65159SKalle Valo 		for (i = 0; i < params->num_bssid; ++i) {
2288d5c65159SKalle Valo 			ether_addr_copy(bssid->addr,
2289d5c65159SKalle Valo 					params->bssid_list[i].addr);
2290d5c65159SKalle Valo 			bssid++;
2291d5c65159SKalle Valo 		}
2292d5c65159SKalle Valo 	}
2293d5c65159SKalle Valo 
2294d5c65159SKalle Valo 	ptr += params->num_bssid * sizeof(*bssid);
2295d5c65159SKalle Valo 
2296d5c65159SKalle Valo 	len = extraie_len_with_pad;
2297d5c65159SKalle Valo 	tlv = ptr;
2298d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2299d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2300d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2301d5c65159SKalle Valo 
2302a658c929SSven Eckelmann 	if (extraie_len_with_pad)
2303d5c65159SKalle Valo 		memcpy(ptr, params->extraie.ptr,
2304d5c65159SKalle Valo 		       params->extraie.len);
2305d5c65159SKalle Valo 
2306d5c65159SKalle Valo 	ptr += extraie_len_with_pad;
2307d5c65159SKalle Valo 
230874601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid) {
230974601ecfSPradeep Kumar Chitrapu 		len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
231074601ecfSPradeep Kumar Chitrapu 		tlv = ptr;
231174601ecfSPradeep Kumar Chitrapu 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
231274601ecfSPradeep Kumar Chitrapu 			      FIELD_PREP(WMI_TLV_LEN, len);
231374601ecfSPradeep Kumar Chitrapu 		ptr += TLV_HDR_SIZE;
231474601ecfSPradeep Kumar Chitrapu 		s_ssid = ptr;
231574601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_s_ssid; ++i) {
231674601ecfSPradeep Kumar Chitrapu 			s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
231774601ecfSPradeep Kumar Chitrapu 			s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
231874601ecfSPradeep Kumar Chitrapu 			s_ssid++;
231974601ecfSPradeep Kumar Chitrapu 		}
232074601ecfSPradeep Kumar Chitrapu 		ptr += len;
232174601ecfSPradeep Kumar Chitrapu 	}
232274601ecfSPradeep Kumar Chitrapu 
232374601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid) {
232474601ecfSPradeep Kumar Chitrapu 		len = params->num_hint_bssid * sizeof(struct hint_bssid);
232574601ecfSPradeep Kumar Chitrapu 		tlv = ptr;
232674601ecfSPradeep Kumar Chitrapu 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
232774601ecfSPradeep Kumar Chitrapu 			      FIELD_PREP(WMI_TLV_LEN, len);
232874601ecfSPradeep Kumar Chitrapu 		ptr += TLV_HDR_SIZE;
232974601ecfSPradeep Kumar Chitrapu 		hint_bssid = ptr;
233074601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_bssid; ++i) {
233174601ecfSPradeep Kumar Chitrapu 			hint_bssid->freq_flags =
233274601ecfSPradeep Kumar Chitrapu 				params->hint_bssid[i].freq_flags;
233374601ecfSPradeep Kumar Chitrapu 			ether_addr_copy(&params->hint_bssid[i].bssid.addr[0],
233474601ecfSPradeep Kumar Chitrapu 					&hint_bssid->bssid.addr[0]);
233574601ecfSPradeep Kumar Chitrapu 			hint_bssid++;
233674601ecfSPradeep Kumar Chitrapu 		}
233774601ecfSPradeep Kumar Chitrapu 	}
233874601ecfSPradeep Kumar Chitrapu 
2339d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2340d5c65159SKalle Valo 				  WMI_START_SCAN_CMDID);
2341d5c65159SKalle Valo 	if (ret) {
2342d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2343d5c65159SKalle Valo 		dev_kfree_skb(skb);
2344d5c65159SKalle Valo 	}
2345d5c65159SKalle Valo 
2346d5c65159SKalle Valo 	return ret;
2347d5c65159SKalle Valo }
2348d5c65159SKalle Valo 
2349d5c65159SKalle Valo int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2350d5c65159SKalle Valo 				  struct scan_cancel_param *param)
2351d5c65159SKalle Valo {
2352d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2353d5c65159SKalle Valo 	struct wmi_stop_scan_cmd *cmd;
2354d5c65159SKalle Valo 	struct sk_buff *skb;
2355d5c65159SKalle Valo 	int ret;
2356d5c65159SKalle Valo 
23576bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2358d5c65159SKalle Valo 	if (!skb)
2359d5c65159SKalle Valo 		return -ENOMEM;
2360d5c65159SKalle Valo 
2361d5c65159SKalle Valo 	cmd = (struct wmi_stop_scan_cmd *)skb->data;
2362d5c65159SKalle Valo 
2363d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2364d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2365d5c65159SKalle Valo 
2366d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
2367d5c65159SKalle Valo 	cmd->requestor = param->requester;
2368d5c65159SKalle Valo 	cmd->scan_id = param->scan_id;
2369d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
2370d5c65159SKalle Valo 	/* stop the scan with the corresponding scan_id */
2371d5c65159SKalle Valo 	if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2372d5c65159SKalle Valo 		/* Cancelling all scans */
2373d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ALL;
2374d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2375d5c65159SKalle Valo 		/* Cancelling VAP scans */
2376d5c65159SKalle Valo 		cmd->req_type =  WMI_SCN_STOP_VAP_ALL;
2377d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2378d5c65159SKalle Valo 		/* Cancelling specific scan */
2379d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ONE;
2380d5c65159SKalle Valo 	} else {
2381d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid scan cancel param %d",
2382d5c65159SKalle Valo 			    param->req_type);
2383d5c65159SKalle Valo 		dev_kfree_skb(skb);
2384d5c65159SKalle Valo 		return -EINVAL;
2385d5c65159SKalle Valo 	}
2386d5c65159SKalle Valo 
2387d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2388d5c65159SKalle Valo 				  WMI_STOP_SCAN_CMDID);
2389d5c65159SKalle Valo 	if (ret) {
2390d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2391d5c65159SKalle Valo 		dev_kfree_skb(skb);
2392d5c65159SKalle Valo 	}
2393d5c65159SKalle Valo 
2394d5c65159SKalle Valo 	return ret;
2395d5c65159SKalle Valo }
2396d5c65159SKalle Valo 
2397d5c65159SKalle Valo int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2398d5c65159SKalle Valo 				       struct scan_chan_list_params *chan_list)
2399d5c65159SKalle Valo {
2400d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2401d5c65159SKalle Valo 	struct wmi_scan_chan_list_cmd *cmd;
2402d5c65159SKalle Valo 	struct sk_buff *skb;
2403d5c65159SKalle Valo 	struct wmi_channel *chan_info;
2404d5c65159SKalle Valo 	struct channel_param *tchan_info;
2405d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2406d5c65159SKalle Valo 	void *ptr;
2407d5c65159SKalle Valo 	int i, ret, len;
2408bff621fdSPradeep Kumar Chitrapu 	u16 num_send_chans, num_sends = 0, max_chan_limit = 0;
2409d5c65159SKalle Valo 	u32 *reg1, *reg2;
2410d5c65159SKalle Valo 
2411b2549465SGustavo A. R. Silva 	tchan_info = chan_list->ch_param;
2412bff621fdSPradeep Kumar Chitrapu 	while (chan_list->nallchans) {
2413bff621fdSPradeep Kumar Chitrapu 		len = sizeof(*cmd) + TLV_HDR_SIZE;
2414bff621fdSPradeep Kumar Chitrapu 		max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) /
2415bff621fdSPradeep Kumar Chitrapu 			sizeof(*chan_info);
2416bff621fdSPradeep Kumar Chitrapu 
2417bff621fdSPradeep Kumar Chitrapu 		if (chan_list->nallchans > max_chan_limit)
2418bff621fdSPradeep Kumar Chitrapu 			num_send_chans = max_chan_limit;
2419bff621fdSPradeep Kumar Chitrapu 		else
2420bff621fdSPradeep Kumar Chitrapu 			num_send_chans = chan_list->nallchans;
2421bff621fdSPradeep Kumar Chitrapu 
2422bff621fdSPradeep Kumar Chitrapu 		chan_list->nallchans -= num_send_chans;
2423bff621fdSPradeep Kumar Chitrapu 		len += sizeof(*chan_info) * num_send_chans;
2424d5c65159SKalle Valo 
24256bc9d6f7SJohn Crispin 		skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2426d5c65159SKalle Valo 		if (!skb)
2427d5c65159SKalle Valo 			return -ENOMEM;
2428d5c65159SKalle Valo 
2429d5c65159SKalle Valo 		cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2430d5c65159SKalle Valo 		cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2431d5c65159SKalle Valo 			FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2432bff621fdSPradeep Kumar Chitrapu 		cmd->pdev_id = chan_list->pdev_id;
2433bff621fdSPradeep Kumar Chitrapu 		cmd->num_scan_chans = num_send_chans;
2434bff621fdSPradeep Kumar Chitrapu 		if (num_sends)
2435bff621fdSPradeep Kumar Chitrapu 			cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG;
2436d5c65159SKalle Valo 
2437d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2438bff621fdSPradeep Kumar Chitrapu 			   "WMI no.of chan = %d len = %d pdev_id = %d num_sends = %d\n",
2439bff621fdSPradeep Kumar Chitrapu 			   num_send_chans, len, cmd->pdev_id, num_sends);
2440d5c65159SKalle Valo 
2441d5c65159SKalle Valo 		ptr = skb->data + sizeof(*cmd);
2442d5c65159SKalle Valo 
2443bff621fdSPradeep Kumar Chitrapu 		len = sizeof(*chan_info) * num_send_chans;
2444d5c65159SKalle Valo 		tlv = ptr;
2445d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2446d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2447d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
2448d5c65159SKalle Valo 
2449bff621fdSPradeep Kumar Chitrapu 		for (i = 0; i < num_send_chans; ++i) {
2450d5c65159SKalle Valo 			chan_info = ptr;
2451d5c65159SKalle Valo 			memset(chan_info, 0, sizeof(*chan_info));
2452d5c65159SKalle Valo 			len = sizeof(*chan_info);
2453d5c65159SKalle Valo 			chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2454d5c65159SKalle Valo 							   WMI_TAG_CHANNEL) |
2455d5c65159SKalle Valo 						FIELD_PREP(WMI_TLV_LEN,
2456d5c65159SKalle Valo 							   len - TLV_HDR_SIZE);
2457d5c65159SKalle Valo 
2458d5c65159SKalle Valo 			reg1 = &chan_info->reg_info_1;
2459d5c65159SKalle Valo 			reg2 = &chan_info->reg_info_2;
2460d5c65159SKalle Valo 			chan_info->mhz = tchan_info->mhz;
2461d5c65159SKalle Valo 			chan_info->band_center_freq1 = tchan_info->cfreq1;
2462d5c65159SKalle Valo 			chan_info->band_center_freq2 = tchan_info->cfreq2;
2463d5c65159SKalle Valo 
2464d5c65159SKalle Valo 			if (tchan_info->is_chan_passive)
2465d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_PASSIVE;
24669f056ed8SJohn Crispin 			if (tchan_info->allow_he)
24679f056ed8SJohn Crispin 				chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
24689f056ed8SJohn Crispin 			else if (tchan_info->allow_vht)
2469d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2470d5c65159SKalle Valo 			else if (tchan_info->allow_ht)
2471d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2472d5c65159SKalle Valo 			if (tchan_info->half_rate)
2473d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2474d5c65159SKalle Valo 			if (tchan_info->quarter_rate)
2475d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2476bff621fdSPradeep Kumar Chitrapu 			if (tchan_info->psc_channel)
2477bff621fdSPradeep Kumar Chitrapu 				chan_info->info |= WMI_CHAN_INFO_PSC;
24788cd5c084SBaochen Qiang 			if (tchan_info->dfs_set)
24798cd5c084SBaochen Qiang 				chan_info->info |= WMI_CHAN_INFO_DFS;
2480d5c65159SKalle Valo 
2481d5c65159SKalle Valo 			chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2482d5c65159SKalle Valo 						      tchan_info->phy_mode);
2483d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2484d5c65159SKalle Valo 					    tchan_info->minpower);
2485d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2486d5c65159SKalle Valo 					    tchan_info->maxpower);
2487d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2488d5c65159SKalle Valo 					    tchan_info->maxregpower);
2489d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2490d5c65159SKalle Valo 					    tchan_info->reg_class_id);
2491d5c65159SKalle Valo 			*reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2492d5c65159SKalle Valo 					    tchan_info->antennamax);
24939212c1b9SP Praneesh 			*reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
24949212c1b9SP Praneesh 					    tchan_info->maxregpower);
2495d5c65159SKalle Valo 
2496d5c65159SKalle Valo 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2497bff621fdSPradeep Kumar Chitrapu 				   "WMI chan scan list chan[%d] = %u, chan_info->info %8x\n",
2498bff621fdSPradeep Kumar Chitrapu 				   i, chan_info->mhz, chan_info->info);
2499d5c65159SKalle Valo 
2500d5c65159SKalle Valo 			ptr += sizeof(*chan_info);
2501d5c65159SKalle Valo 
2502d5c65159SKalle Valo 			tchan_info++;
2503d5c65159SKalle Valo 		}
2504d5c65159SKalle Valo 
2505d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2506d5c65159SKalle Valo 		if (ret) {
2507d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2508d5c65159SKalle Valo 			dev_kfree_skb(skb);
2509bff621fdSPradeep Kumar Chitrapu 			return ret;
2510d5c65159SKalle Valo 		}
2511d5c65159SKalle Valo 
2512bff621fdSPradeep Kumar Chitrapu 		num_sends++;
2513bff621fdSPradeep Kumar Chitrapu 	}
2514bff621fdSPradeep Kumar Chitrapu 
2515bff621fdSPradeep Kumar Chitrapu 	return 0;
2516d5c65159SKalle Valo }
2517d5c65159SKalle Valo 
2518d5c65159SKalle Valo int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2519d5c65159SKalle Valo 				       struct wmi_wmm_params_all_arg *param)
2520d5c65159SKalle Valo {
2521d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2522d5c65159SKalle Valo 	struct wmi_vdev_set_wmm_params_cmd *cmd;
2523d5c65159SKalle Valo 	struct wmi_wmm_params *wmm_param;
2524d5c65159SKalle Valo 	struct wmi_wmm_params_arg *wmi_wmm_arg;
2525d5c65159SKalle Valo 	struct sk_buff *skb;
2526d5c65159SKalle Valo 	int ret, ac;
2527d5c65159SKalle Valo 
25286bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2529d5c65159SKalle Valo 	if (!skb)
2530d5c65159SKalle Valo 		return -ENOMEM;
2531d5c65159SKalle Valo 
2532d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2533d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2534d5c65159SKalle Valo 				     WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2535d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2536d5c65159SKalle Valo 
2537d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
2538d5c65159SKalle Valo 	cmd->wmm_param_type = 0;
2539d5c65159SKalle Valo 
2540d5c65159SKalle Valo 	for (ac = 0; ac < WME_NUM_AC; ac++) {
2541d5c65159SKalle Valo 		switch (ac) {
2542d5c65159SKalle Valo 		case WME_AC_BE:
2543d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_be;
2544d5c65159SKalle Valo 			break;
2545d5c65159SKalle Valo 		case WME_AC_BK:
2546d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_bk;
2547d5c65159SKalle Valo 			break;
2548d5c65159SKalle Valo 		case WME_AC_VI:
2549d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vi;
2550d5c65159SKalle Valo 			break;
2551d5c65159SKalle Valo 		case WME_AC_VO:
2552d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vo;
2553d5c65159SKalle Valo 			break;
2554d5c65159SKalle Valo 		}
2555d5c65159SKalle Valo 
2556d5c65159SKalle Valo 		wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2557d5c65159SKalle Valo 		wmm_param->tlv_header =
2558d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
2559d5c65159SKalle Valo 					   WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2560d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN,
2561d5c65159SKalle Valo 					   sizeof(*wmm_param) - TLV_HDR_SIZE);
2562d5c65159SKalle Valo 
2563d5c65159SKalle Valo 		wmm_param->aifs = wmi_wmm_arg->aifs;
2564d5c65159SKalle Valo 		wmm_param->cwmin = wmi_wmm_arg->cwmin;
2565d5c65159SKalle Valo 		wmm_param->cwmax = wmi_wmm_arg->cwmax;
2566d5c65159SKalle Valo 		wmm_param->txoplimit = wmi_wmm_arg->txop;
2567d5c65159SKalle Valo 		wmm_param->acm = wmi_wmm_arg->acm;
2568d5c65159SKalle Valo 		wmm_param->no_ack = wmi_wmm_arg->no_ack;
2569d5c65159SKalle Valo 
2570d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2571d5c65159SKalle Valo 			   "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2572d5c65159SKalle Valo 			   ac, wmm_param->aifs, wmm_param->cwmin,
2573d5c65159SKalle Valo 			   wmm_param->cwmax, wmm_param->txoplimit,
2574d5c65159SKalle Valo 			   wmm_param->acm, wmm_param->no_ack);
2575d5c65159SKalle Valo 	}
2576d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2577d5c65159SKalle Valo 				  WMI_VDEV_SET_WMM_PARAMS_CMDID);
2578d5c65159SKalle Valo 	if (ret) {
2579d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2580d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2581d5c65159SKalle Valo 		dev_kfree_skb(skb);
2582d5c65159SKalle Valo 	}
2583d5c65159SKalle Valo 
2584d5c65159SKalle Valo 	return ret;
2585d5c65159SKalle Valo }
2586d5c65159SKalle Valo 
2587d5c65159SKalle Valo int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2588d5c65159SKalle Valo 						  u32 pdev_id)
2589d5c65159SKalle Valo {
2590d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2591d5c65159SKalle Valo 	struct wmi_dfs_phyerr_offload_cmd *cmd;
2592d5c65159SKalle Valo 	struct sk_buff *skb;
2593d5c65159SKalle Valo 	int ret;
2594d5c65159SKalle Valo 
25956bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2596d5c65159SKalle Valo 	if (!skb)
2597d5c65159SKalle Valo 		return -ENOMEM;
2598d5c65159SKalle Valo 
2599d5c65159SKalle Valo 	cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2600d5c65159SKalle Valo 	cmd->tlv_header =
2601d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2602d5c65159SKalle Valo 			   WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2603d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2604d5c65159SKalle Valo 
2605d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
2606d5c65159SKalle Valo 
2607d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2608d5c65159SKalle Valo 		   "WMI dfs phy err offload enable pdev id %d\n", pdev_id);
2609d5c65159SKalle Valo 
2610d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2611d5c65159SKalle Valo 				  WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2612d5c65159SKalle Valo 	if (ret) {
2613d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2614d5c65159SKalle Valo 			    "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2615d5c65159SKalle Valo 		dev_kfree_skb(skb);
2616d5c65159SKalle Valo 	}
2617d5c65159SKalle Valo 
2618d5c65159SKalle Valo 	return ret;
2619d5c65159SKalle Valo }
2620d5c65159SKalle Valo 
26219556dfa2SMaharaja Kennadyrajan int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26229556dfa2SMaharaja Kennadyrajan 			  u32 tid, u32 initiator, u32 reason)
26239556dfa2SMaharaja Kennadyrajan {
26249556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26259556dfa2SMaharaja Kennadyrajan 	struct wmi_delba_send_cmd *cmd;
26269556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26279556dfa2SMaharaja Kennadyrajan 	int ret;
26289556dfa2SMaharaja Kennadyrajan 
26299556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26309556dfa2SMaharaja Kennadyrajan 	if (!skb)
26319556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
26329556dfa2SMaharaja Kennadyrajan 
26339556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_delba_send_cmd *)skb->data;
26349556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) |
26359556dfa2SMaharaja Kennadyrajan 			FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
26369556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
26379556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
26389556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
26399556dfa2SMaharaja Kennadyrajan 	cmd->initiator = initiator;
26409556dfa2SMaharaja Kennadyrajan 	cmd->reasoncode = reason;
26419556dfa2SMaharaja Kennadyrajan 
26429556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
26439556dfa2SMaharaja Kennadyrajan 		   "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
26449556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, initiator, reason);
26459556dfa2SMaharaja Kennadyrajan 
26469556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID);
26479556dfa2SMaharaja Kennadyrajan 
26489556dfa2SMaharaja Kennadyrajan 	if (ret) {
26499556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
26509556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_DELBA_SEND_CMDID cmd\n");
26519556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
26529556dfa2SMaharaja Kennadyrajan 	}
26539556dfa2SMaharaja Kennadyrajan 
26549556dfa2SMaharaja Kennadyrajan 	return ret;
26559556dfa2SMaharaja Kennadyrajan }
26569556dfa2SMaharaja Kennadyrajan 
26579556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26589556dfa2SMaharaja Kennadyrajan 			      u32 tid, u32 status)
26599556dfa2SMaharaja Kennadyrajan {
26609556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26619556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_setresponse_cmd *cmd;
26629556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26639556dfa2SMaharaja Kennadyrajan 	int ret;
26649556dfa2SMaharaja Kennadyrajan 
26659556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26669556dfa2SMaharaja Kennadyrajan 	if (!skb)
26679556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
26689556dfa2SMaharaja Kennadyrajan 
26699556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
26709556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header =
26719556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) |
26729556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
26739556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
26749556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
26759556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
26769556dfa2SMaharaja Kennadyrajan 	cmd->statuscode = status;
26779556dfa2SMaharaja Kennadyrajan 
26789556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
26799556dfa2SMaharaja Kennadyrajan 		   "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
26809556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, status);
26819556dfa2SMaharaja Kennadyrajan 
26829556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID);
26839556dfa2SMaharaja Kennadyrajan 
26849556dfa2SMaharaja Kennadyrajan 	if (ret) {
26859556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
26869556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n");
26879556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
26889556dfa2SMaharaja Kennadyrajan 	}
26899556dfa2SMaharaja Kennadyrajan 
26909556dfa2SMaharaja Kennadyrajan 	return ret;
26919556dfa2SMaharaja Kennadyrajan }
26929556dfa2SMaharaja Kennadyrajan 
26939556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26949556dfa2SMaharaja Kennadyrajan 			  u32 tid, u32 buf_size)
26959556dfa2SMaharaja Kennadyrajan {
26969556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26979556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_send_cmd *cmd;
26989556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26999556dfa2SMaharaja Kennadyrajan 	int ret;
27009556dfa2SMaharaja Kennadyrajan 
27019556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
27029556dfa2SMaharaja Kennadyrajan 	if (!skb)
27039556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
27049556dfa2SMaharaja Kennadyrajan 
27059556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_send_cmd *)skb->data;
27069556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) |
27079556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27089556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
27099556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
27109556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
27119556dfa2SMaharaja Kennadyrajan 	cmd->buffersize = buf_size;
27129556dfa2SMaharaja Kennadyrajan 
27139556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
27149556dfa2SMaharaja Kennadyrajan 		   "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
27159556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, buf_size);
27169556dfa2SMaharaja Kennadyrajan 
27179556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID);
27189556dfa2SMaharaja Kennadyrajan 
27199556dfa2SMaharaja Kennadyrajan 	if (ret) {
27209556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
27219556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_SEND_CMDID cmd\n");
27229556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
27239556dfa2SMaharaja Kennadyrajan 	}
27249556dfa2SMaharaja Kennadyrajan 
27259556dfa2SMaharaja Kennadyrajan 	return ret;
27269556dfa2SMaharaja Kennadyrajan }
27279556dfa2SMaharaja Kennadyrajan 
27289556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac)
27299556dfa2SMaharaja Kennadyrajan {
27309556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
27319556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_clear_resp_cmd *cmd;
27329556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
27339556dfa2SMaharaja Kennadyrajan 	int ret;
27349556dfa2SMaharaja Kennadyrajan 
27359556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
27369556dfa2SMaharaja Kennadyrajan 	if (!skb)
27379556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
27389556dfa2SMaharaja Kennadyrajan 
27399556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
27409556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header =
27419556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) |
27429556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27439556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
27449556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
27459556dfa2SMaharaja Kennadyrajan 
27469556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
27479556dfa2SMaharaja Kennadyrajan 		   "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
27489556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac);
27499556dfa2SMaharaja Kennadyrajan 
27509556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID);
27519556dfa2SMaharaja Kennadyrajan 
27529556dfa2SMaharaja Kennadyrajan 	if (ret) {
27539556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
27549556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n");
27559556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
27569556dfa2SMaharaja Kennadyrajan 	}
27579556dfa2SMaharaja Kennadyrajan 
27589556dfa2SMaharaja Kennadyrajan 	return ret;
27599556dfa2SMaharaja Kennadyrajan }
27609556dfa2SMaharaja Kennadyrajan 
2761d5c65159SKalle Valo int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2762d5c65159SKalle Valo {
2763d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2764d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_cmd *cmd;
2765d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_info *info;
2766d5c65159SKalle Valo 	struct sk_buff *skb;
2767d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2768d5c65159SKalle Valo 	void *ptr;
2769d5c65159SKalle Valo 	int ret, len;
2770d5c65159SKalle Valo 
2771d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
27726bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2773d5c65159SKalle Valo 	if (!skb)
2774d5c65159SKalle Valo 		return -ENOMEM;
2775d5c65159SKalle Valo 
2776d5c65159SKalle Valo 	cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2777d5c65159SKalle Valo 
2778d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2779d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2780d5c65159SKalle Valo 
2781d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2782d5c65159SKalle Valo 	cmd->num_mac = 1;
2783d5c65159SKalle Valo 	cmd->enable = enable;
2784d5c65159SKalle Valo 
2785d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
2786d5c65159SKalle Valo 
2787d5c65159SKalle Valo 	tlv = ptr;
2788d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
278979c647a3SVikas Patel 		      FIELD_PREP(WMI_TLV_LEN, sizeof(*info));
2790d5c65159SKalle Valo 
2791d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2792d5c65159SKalle Valo 	info = ptr;
2793d5c65159SKalle Valo 
2794d5c65159SKalle Valo 	ether_addr_copy(info->peer_macaddr.addr, addr);
2795d5c65159SKalle Valo 	info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2796d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
2797d5c65159SKalle Valo 				      sizeof(*info) - TLV_HDR_SIZE);
2798d5c65159SKalle Valo 
2799d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2800d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_FILTER_CMDID);
2801d5c65159SKalle Valo 	if (ret) {
2802d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2803d5c65159SKalle Valo 		dev_kfree_skb(skb);
2804d5c65159SKalle Valo 	}
2805d5c65159SKalle Valo 
2806d5c65159SKalle Valo 	return ret;
2807d5c65159SKalle Valo }
2808d5c65159SKalle Valo 
2809d5c65159SKalle Valo int
2810d5c65159SKalle Valo ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2811d5c65159SKalle Valo 				 struct wmi_init_country_params init_cc_params)
2812d5c65159SKalle Valo {
2813d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2814d5c65159SKalle Valo 	struct wmi_init_country_cmd *cmd;
2815d5c65159SKalle Valo 	struct sk_buff *skb;
2816d5c65159SKalle Valo 	int ret;
2817d5c65159SKalle Valo 
28186bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2819d5c65159SKalle Valo 	if (!skb)
2820d5c65159SKalle Valo 		return -ENOMEM;
2821d5c65159SKalle Valo 
2822d5c65159SKalle Valo 	cmd = (struct wmi_init_country_cmd *)skb->data;
2823d5c65159SKalle Valo 	cmd->tlv_header =
2824d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2825d5c65159SKalle Valo 			   WMI_TAG_SET_INIT_COUNTRY_CMD) |
2826d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2827d5c65159SKalle Valo 
2828d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2829d5c65159SKalle Valo 
2830d5c65159SKalle Valo 	switch (init_cc_params.flags) {
2831d5c65159SKalle Valo 	case ALPHA_IS_SET:
2832d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2833d5c65159SKalle Valo 		memcpy((u8 *)&cmd->cc_info.alpha2,
2834d5c65159SKalle Valo 		       init_cc_params.cc_info.alpha2, 3);
2835d5c65159SKalle Valo 		break;
2836d5c65159SKalle Valo 	case CC_IS_SET:
2837d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2838d5c65159SKalle Valo 		cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2839d5c65159SKalle Valo 		break;
2840d5c65159SKalle Valo 	case REGDMN_IS_SET:
2841d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2842d5c65159SKalle Valo 		cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2843d5c65159SKalle Valo 		break;
2844d5c65159SKalle Valo 	default:
2845d5c65159SKalle Valo 		ret = -EINVAL;
2846d5c65159SKalle Valo 		goto out;
2847d5c65159SKalle Valo 	}
2848d5c65159SKalle Valo 
2849d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2850d5c65159SKalle Valo 				  WMI_SET_INIT_COUNTRY_CMDID);
2851d5c65159SKalle Valo 
2852d5c65159SKalle Valo out:
2853d5c65159SKalle Valo 	if (ret) {
2854d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2855d5c65159SKalle Valo 			    "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2856d5c65159SKalle Valo 			    ret);
2857d5c65159SKalle Valo 		dev_kfree_skb(skb);
2858d5c65159SKalle Valo 	}
2859d5c65159SKalle Valo 
2860d5c65159SKalle Valo 	return ret;
2861d5c65159SKalle Valo }
2862d5c65159SKalle Valo 
28630b05ddadSWen Gong int ath11k_wmi_send_set_current_country_cmd(struct ath11k *ar,
28640b05ddadSWen Gong 					    struct wmi_set_current_country_params *param)
28650b05ddadSWen Gong {
28660b05ddadSWen Gong 	struct ath11k_pdev_wmi *wmi = ar->wmi;
28670b05ddadSWen Gong 	struct wmi_set_current_country_cmd *cmd;
28680b05ddadSWen Gong 	struct sk_buff *skb;
28690b05ddadSWen Gong 	int ret;
28700b05ddadSWen Gong 
28710b05ddadSWen Gong 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
28720b05ddadSWen Gong 	if (!skb)
28730b05ddadSWen Gong 		return -ENOMEM;
28740b05ddadSWen Gong 
28750b05ddadSWen Gong 	cmd = (struct wmi_set_current_country_cmd *)skb->data;
28760b05ddadSWen Gong 	cmd->tlv_header =
28770b05ddadSWen Gong 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SET_CURRENT_COUNTRY_CMD) |
28780b05ddadSWen Gong 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
28790b05ddadSWen Gong 
28800b05ddadSWen Gong 	cmd->pdev_id = ar->pdev->pdev_id;
28810b05ddadSWen Gong 	memcpy(&cmd->new_alpha2, &param->alpha2, 3);
28820b05ddadSWen Gong 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SET_CURRENT_COUNTRY_CMDID);
28830b05ddadSWen Gong 
28840b05ddadSWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
28850b05ddadSWen Gong 		   "set current country pdev id %d alpha2 %c%c\n",
28860b05ddadSWen Gong 		   ar->pdev->pdev_id,
28870b05ddadSWen Gong 		   param->alpha2[0],
28880b05ddadSWen Gong 		   param->alpha2[1]);
28890b05ddadSWen Gong 
28900b05ddadSWen Gong 	if (ret) {
28910b05ddadSWen Gong 		ath11k_warn(ar->ab,
28920b05ddadSWen Gong 			    "failed to send WMI_SET_CURRENT_COUNTRY_CMDID: %d\n", ret);
28930b05ddadSWen Gong 		dev_kfree_skb(skb);
28940b05ddadSWen Gong 	}
28950b05ddadSWen Gong 
28960b05ddadSWen Gong 	return ret;
28970b05ddadSWen Gong }
28980b05ddadSWen Gong 
28992a63bbcaSPradeep Kumar Chitrapu int
29002a63bbcaSPradeep Kumar Chitrapu ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar,
29012a63bbcaSPradeep Kumar Chitrapu 					     struct thermal_mitigation_params *param)
29022a63bbcaSPradeep Kumar Chitrapu {
29032a63bbcaSPradeep Kumar Chitrapu 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29042a63bbcaSPradeep Kumar Chitrapu 	struct wmi_therm_throt_config_request_cmd *cmd;
29052a63bbcaSPradeep Kumar Chitrapu 	struct wmi_therm_throt_level_config_info *lvl_conf;
29062a63bbcaSPradeep Kumar Chitrapu 	struct wmi_tlv *tlv;
29072a63bbcaSPradeep Kumar Chitrapu 	struct sk_buff *skb;
29082a63bbcaSPradeep Kumar Chitrapu 	int i, ret, len;
29092a63bbcaSPradeep Kumar Chitrapu 
29102a63bbcaSPradeep Kumar Chitrapu 	len = sizeof(*cmd) + TLV_HDR_SIZE +
29112a63bbcaSPradeep Kumar Chitrapu 	      THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info);
29122a63bbcaSPradeep Kumar Chitrapu 
29132a63bbcaSPradeep Kumar Chitrapu 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
29142a63bbcaSPradeep Kumar Chitrapu 	if (!skb)
29152a63bbcaSPradeep Kumar Chitrapu 		return -ENOMEM;
29162a63bbcaSPradeep Kumar Chitrapu 
29172a63bbcaSPradeep Kumar Chitrapu 	cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data;
29182a63bbcaSPradeep Kumar Chitrapu 
29192a63bbcaSPradeep Kumar Chitrapu 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) |
29202a63bbcaSPradeep Kumar Chitrapu 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
29212a63bbcaSPradeep Kumar Chitrapu 
29222a63bbcaSPradeep Kumar Chitrapu 	cmd->pdev_id = ar->pdev->pdev_id;
29232a63bbcaSPradeep Kumar Chitrapu 	cmd->enable = param->enable;
29242a63bbcaSPradeep Kumar Chitrapu 	cmd->dc = param->dc;
29252a63bbcaSPradeep Kumar Chitrapu 	cmd->dc_per_event = param->dc_per_event;
29262a63bbcaSPradeep Kumar Chitrapu 	cmd->therm_throt_levels = THERMAL_LEVELS;
29272a63bbcaSPradeep Kumar Chitrapu 
29282a63bbcaSPradeep Kumar Chitrapu 	tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
29292a63bbcaSPradeep Kumar Chitrapu 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
29302a63bbcaSPradeep Kumar Chitrapu 		      FIELD_PREP(WMI_TLV_LEN,
29312a63bbcaSPradeep Kumar Chitrapu 				 (THERMAL_LEVELS *
29322a63bbcaSPradeep Kumar Chitrapu 				  sizeof(struct wmi_therm_throt_level_config_info)));
29332a63bbcaSPradeep Kumar Chitrapu 
29342a63bbcaSPradeep Kumar Chitrapu 	lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data +
29352a63bbcaSPradeep Kumar Chitrapu 								sizeof(*cmd) +
29362a63bbcaSPradeep Kumar Chitrapu 								TLV_HDR_SIZE);
29372a63bbcaSPradeep Kumar Chitrapu 	for (i = 0; i < THERMAL_LEVELS; i++) {
29382a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->tlv_header =
29392a63bbcaSPradeep Kumar Chitrapu 			FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) |
29402a63bbcaSPradeep Kumar Chitrapu 			FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE);
29412a63bbcaSPradeep Kumar Chitrapu 
29422a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->temp_lwm = param->levelconf[i].tmplwm;
29432a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->temp_hwm = param->levelconf[i].tmphwm;
29442a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent;
29452a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->prio = param->levelconf[i].priority;
29462a63bbcaSPradeep Kumar Chitrapu 		lvl_conf++;
29472a63bbcaSPradeep Kumar Chitrapu 	}
29482a63bbcaSPradeep Kumar Chitrapu 
29492a63bbcaSPradeep Kumar Chitrapu 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID);
29502a63bbcaSPradeep Kumar Chitrapu 	if (ret) {
29512a63bbcaSPradeep Kumar Chitrapu 		ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n");
29522a63bbcaSPradeep Kumar Chitrapu 		dev_kfree_skb(skb);
29532a63bbcaSPradeep Kumar Chitrapu 	}
29542a63bbcaSPradeep Kumar Chitrapu 
29552a63bbcaSPradeep Kumar Chitrapu 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
29562a63bbcaSPradeep Kumar Chitrapu 		   "WMI vdev set thermal throt pdev_id %d enable %d dc %d dc_per_event %x levels %d\n",
29572a63bbcaSPradeep Kumar Chitrapu 		   ar->pdev->pdev_id, param->enable, param->dc,
29582a63bbcaSPradeep Kumar Chitrapu 		   param->dc_per_event, THERMAL_LEVELS);
29592a63bbcaSPradeep Kumar Chitrapu 
29602a63bbcaSPradeep Kumar Chitrapu 	return ret;
29612a63bbcaSPradeep Kumar Chitrapu }
29622a63bbcaSPradeep Kumar Chitrapu 
29639dcf6808SWen Gong int ath11k_wmi_send_11d_scan_start_cmd(struct ath11k *ar,
29649dcf6808SWen Gong 				       struct wmi_11d_scan_start_params *param)
29659dcf6808SWen Gong {
29669dcf6808SWen Gong 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29679dcf6808SWen Gong 	struct wmi_11d_scan_start_cmd *cmd;
29689dcf6808SWen Gong 	struct sk_buff *skb;
29699dcf6808SWen Gong 	int ret;
29709dcf6808SWen Gong 
29719dcf6808SWen Gong 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
29729dcf6808SWen Gong 	if (!skb)
29739dcf6808SWen Gong 		return -ENOMEM;
29749dcf6808SWen Gong 
29759dcf6808SWen Gong 	cmd = (struct wmi_11d_scan_start_cmd *)skb->data;
29769dcf6808SWen Gong 	cmd->tlv_header =
29779dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_START_CMD) |
29789dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
29799dcf6808SWen Gong 
29809dcf6808SWen Gong 	cmd->vdev_id = param->vdev_id;
29819dcf6808SWen Gong 	cmd->scan_period_msec = param->scan_period_msec;
29829dcf6808SWen Gong 	cmd->start_interval_msec = param->start_interval_msec;
29839dcf6808SWen Gong 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_START_CMDID);
29849dcf6808SWen Gong 
29859dcf6808SWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
29869dcf6808SWen Gong 		   "send 11d scan start vdev id %d period %d ms internal %d ms\n",
29879dcf6808SWen Gong 		   cmd->vdev_id,
29889dcf6808SWen Gong 		   cmd->scan_period_msec,
29899dcf6808SWen Gong 		   cmd->start_interval_msec);
29909dcf6808SWen Gong 
29919dcf6808SWen Gong 	if (ret) {
29929dcf6808SWen Gong 		ath11k_warn(ar->ab,
29939dcf6808SWen Gong 			    "failed to send WMI_11D_SCAN_START_CMDID: %d\n", ret);
29949dcf6808SWen Gong 		dev_kfree_skb(skb);
29959dcf6808SWen Gong 	}
29969dcf6808SWen Gong 
29979dcf6808SWen Gong 	return ret;
29989dcf6808SWen Gong }
29999dcf6808SWen Gong 
30009dcf6808SWen Gong int ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k *ar, u32 vdev_id)
30019dcf6808SWen Gong {
30029dcf6808SWen Gong 	struct ath11k_pdev_wmi *wmi = ar->wmi;
30039dcf6808SWen Gong 	struct wmi_11d_scan_stop_cmd *cmd;
30049dcf6808SWen Gong 	struct sk_buff *skb;
30059dcf6808SWen Gong 	int ret;
30069dcf6808SWen Gong 
30079dcf6808SWen Gong 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
30089dcf6808SWen Gong 	if (!skb)
30099dcf6808SWen Gong 		return -ENOMEM;
30109dcf6808SWen Gong 
30119dcf6808SWen Gong 	cmd = (struct wmi_11d_scan_stop_cmd *)skb->data;
30129dcf6808SWen Gong 	cmd->tlv_header =
30139dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_STOP_CMD) |
30149dcf6808SWen Gong 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
30159dcf6808SWen Gong 
30169dcf6808SWen Gong 	cmd->vdev_id = vdev_id;
30179dcf6808SWen Gong 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_STOP_CMDID);
30189dcf6808SWen Gong 
30199dcf6808SWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
30209dcf6808SWen Gong 		   "send 11d scan stop vdev id %d\n",
30219dcf6808SWen Gong 		   cmd->vdev_id);
30229dcf6808SWen Gong 
30239dcf6808SWen Gong 	if (ret) {
30249dcf6808SWen Gong 		ath11k_warn(ar->ab,
30259dcf6808SWen Gong 			    "failed to send WMI_11D_SCAN_STOP_CMDID: %d\n", ret);
30269dcf6808SWen Gong 		dev_kfree_skb(skb);
30279dcf6808SWen Gong 	}
30289dcf6808SWen Gong 
30299dcf6808SWen Gong 	return ret;
30309dcf6808SWen Gong }
30319dcf6808SWen Gong 
3032d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
3033d5c65159SKalle Valo {
3034d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3035d5c65159SKalle Valo 	struct wmi_pktlog_enable_cmd *cmd;
3036d5c65159SKalle Valo 	struct sk_buff *skb;
3037d5c65159SKalle Valo 	int ret;
3038d5c65159SKalle Valo 
30396bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3040d5c65159SKalle Valo 	if (!skb)
3041d5c65159SKalle Valo 		return -ENOMEM;
3042d5c65159SKalle Valo 
3043d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
3044d5c65159SKalle Valo 
3045d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
3046d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3047d5c65159SKalle Valo 
3048d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3049d5c65159SKalle Valo 	cmd->evlist = pktlog_filter;
3050d5c65159SKalle Valo 	cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
3051d5c65159SKalle Valo 
3052d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
3053d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_ENABLE_CMDID);
3054d5c65159SKalle Valo 	if (ret) {
3055d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3056d5c65159SKalle Valo 		dev_kfree_skb(skb);
3057d5c65159SKalle Valo 	}
3058d5c65159SKalle Valo 
3059d5c65159SKalle Valo 	return ret;
3060d5c65159SKalle Valo }
3061d5c65159SKalle Valo 
3062d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
3063d5c65159SKalle Valo {
3064d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3065d5c65159SKalle Valo 	struct wmi_pktlog_disable_cmd *cmd;
3066d5c65159SKalle Valo 	struct sk_buff *skb;
3067d5c65159SKalle Valo 	int ret;
3068d5c65159SKalle Valo 
30696bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3070d5c65159SKalle Valo 	if (!skb)
3071d5c65159SKalle Valo 		return -ENOMEM;
3072d5c65159SKalle Valo 
3073d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
3074d5c65159SKalle Valo 
3075d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
3076d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3077d5c65159SKalle Valo 
3078d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3079d5c65159SKalle Valo 
3080d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
3081d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_DISABLE_CMDID);
3082d5c65159SKalle Valo 	if (ret) {
3083d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3084d5c65159SKalle Valo 		dev_kfree_skb(skb);
3085d5c65159SKalle Valo 	}
3086d5c65159SKalle Valo 
3087d5c65159SKalle Valo 	return ret;
3088d5c65159SKalle Valo }
3089d5c65159SKalle Valo 
30909e2747c3SManikanta Pubbisetty void ath11k_wmi_fill_default_twt_params(struct wmi_twt_enable_params *twt_params)
30919e2747c3SManikanta Pubbisetty {
30929e2747c3SManikanta Pubbisetty 	twt_params->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
30939e2747c3SManikanta Pubbisetty 	twt_params->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
30949e2747c3SManikanta Pubbisetty 	twt_params->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
30959e2747c3SManikanta Pubbisetty 	twt_params->congestion_thresh_teardown =
30969e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
30979e2747c3SManikanta Pubbisetty 	twt_params->congestion_thresh_critical =
30989e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
30999e2747c3SManikanta Pubbisetty 	twt_params->interference_thresh_teardown =
31009e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
31019e2747c3SManikanta Pubbisetty 	twt_params->interference_thresh_setup =
31029e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
31039e2747c3SManikanta Pubbisetty 	twt_params->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
31049e2747c3SManikanta Pubbisetty 	twt_params->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
31059e2747c3SManikanta Pubbisetty 	twt_params->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
31069e2747c3SManikanta Pubbisetty 	twt_params->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
31079e2747c3SManikanta Pubbisetty 	twt_params->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
31089e2747c3SManikanta Pubbisetty 	twt_params->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
31099e2747c3SManikanta Pubbisetty 	twt_params->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
31109e2747c3SManikanta Pubbisetty 	twt_params->remove_sta_slot_interval =
31119e2747c3SManikanta Pubbisetty 		ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
31129e2747c3SManikanta Pubbisetty 	/* TODO add MBSSID support */
31139e2747c3SManikanta Pubbisetty 	twt_params->mbss_support = 0;
31149e2747c3SManikanta Pubbisetty }
31159e2747c3SManikanta Pubbisetty 
31169e2747c3SManikanta Pubbisetty int ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id,
31179e2747c3SManikanta Pubbisetty 				   struct wmi_twt_enable_params *params)
31186d293d44SJohn Crispin {
31196d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
31206bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
31216d293d44SJohn Crispin 	struct wmi_twt_enable_params_cmd *cmd;
31226d293d44SJohn Crispin 	struct sk_buff *skb;
31236d293d44SJohn Crispin 	int ret, len;
31246d293d44SJohn Crispin 
31256d293d44SJohn Crispin 	len = sizeof(*cmd);
31266d293d44SJohn Crispin 
31276bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
31286d293d44SJohn Crispin 	if (!skb)
31296d293d44SJohn Crispin 		return -ENOMEM;
31306d293d44SJohn Crispin 
313177ea8b45SJohn Crispin 	cmd = (struct wmi_twt_enable_params_cmd *)skb->data;
31326d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
31336d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
31346d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
31359e2747c3SManikanta Pubbisetty 	cmd->sta_cong_timer_ms = params->sta_cong_timer_ms;
31369e2747c3SManikanta Pubbisetty 	cmd->default_slot_size = params->default_slot_size;
31379e2747c3SManikanta Pubbisetty 	cmd->congestion_thresh_setup = params->congestion_thresh_setup;
31389e2747c3SManikanta Pubbisetty 	cmd->congestion_thresh_teardown = params->congestion_thresh_teardown;
31399e2747c3SManikanta Pubbisetty 	cmd->congestion_thresh_critical = params->congestion_thresh_critical;
31409e2747c3SManikanta Pubbisetty 	cmd->interference_thresh_teardown = params->interference_thresh_teardown;
31419e2747c3SManikanta Pubbisetty 	cmd->interference_thresh_setup = params->interference_thresh_setup;
31429e2747c3SManikanta Pubbisetty 	cmd->min_no_sta_setup = params->min_no_sta_setup;
31439e2747c3SManikanta Pubbisetty 	cmd->min_no_sta_teardown = params->min_no_sta_teardown;
31449e2747c3SManikanta Pubbisetty 	cmd->no_of_bcast_mcast_slots = params->no_of_bcast_mcast_slots;
31459e2747c3SManikanta Pubbisetty 	cmd->min_no_twt_slots = params->min_no_twt_slots;
31469e2747c3SManikanta Pubbisetty 	cmd->max_no_sta_twt = params->max_no_sta_twt;
31479e2747c3SManikanta Pubbisetty 	cmd->mode_check_interval = params->mode_check_interval;
31489e2747c3SManikanta Pubbisetty 	cmd->add_sta_slot_interval = params->add_sta_slot_interval;
31499e2747c3SManikanta Pubbisetty 	cmd->remove_sta_slot_interval = params->remove_sta_slot_interval;
31509e2747c3SManikanta Pubbisetty 	cmd->mbss_support = params->mbss_support;
31516d293d44SJohn Crispin 
31523d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ENABLE_CMDID);
31536d293d44SJohn Crispin 	if (ret) {
31546d293d44SJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
31556d293d44SJohn Crispin 		dev_kfree_skb(skb);
31563d00e8b5SJohn Crispin 	} else {
31573d00e8b5SJohn Crispin 		ar->twt_enabled = 1;
31586d293d44SJohn Crispin 	}
31596d293d44SJohn Crispin 	return ret;
31606d293d44SJohn Crispin }
31616d293d44SJohn Crispin 
31626d293d44SJohn Crispin int
31636d293d44SJohn Crispin ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
31646d293d44SJohn Crispin {
31656d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
31666bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
31676d293d44SJohn Crispin 	struct wmi_twt_disable_params_cmd *cmd;
31686d293d44SJohn Crispin 	struct sk_buff *skb;
31696d293d44SJohn Crispin 	int ret, len;
31706d293d44SJohn Crispin 
31716d293d44SJohn Crispin 	len = sizeof(*cmd);
31726d293d44SJohn Crispin 
31736bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
31746d293d44SJohn Crispin 	if (!skb)
31756d293d44SJohn Crispin 		return -ENOMEM;
31766d293d44SJohn Crispin 
317777ea8b45SJohn Crispin 	cmd = (struct wmi_twt_disable_params_cmd *)skb->data;
31786d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
31796d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
31806d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
31816d293d44SJohn Crispin 
31823d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DISABLE_CMDID);
31836d293d44SJohn Crispin 	if (ret) {
3184345a4f22SColin Ian King 		ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID");
31856d293d44SJohn Crispin 		dev_kfree_skb(skb);
31863d00e8b5SJohn Crispin 	} else {
31873d00e8b5SJohn Crispin 		ar->twt_enabled = 0;
31883d00e8b5SJohn Crispin 	}
31893d00e8b5SJohn Crispin 	return ret;
31903d00e8b5SJohn Crispin }
31913d00e8b5SJohn Crispin 
31923d00e8b5SJohn Crispin int ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k *ar,
31933d00e8b5SJohn Crispin 				       struct wmi_twt_add_dialog_params *params)
31943d00e8b5SJohn Crispin {
31953d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
31963d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
31973d00e8b5SJohn Crispin 	struct wmi_twt_add_dialog_params_cmd *cmd;
31983d00e8b5SJohn Crispin 	struct sk_buff *skb;
31993d00e8b5SJohn Crispin 	int ret, len;
32003d00e8b5SJohn Crispin 
32013d00e8b5SJohn Crispin 	len = sizeof(*cmd);
32023d00e8b5SJohn Crispin 
32033d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32043d00e8b5SJohn Crispin 	if (!skb)
32053d00e8b5SJohn Crispin 		return -ENOMEM;
32063d00e8b5SJohn Crispin 
32073d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_add_dialog_params_cmd *)skb->data;
32083d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ADD_DIALOG_CMD) |
32093d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32103d00e8b5SJohn Crispin 
32113d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
32123d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
32133d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
32143d00e8b5SJohn Crispin 	cmd->wake_intvl_us = params->wake_intvl_us;
32153d00e8b5SJohn Crispin 	cmd->wake_intvl_mantis = params->wake_intvl_mantis;
32163d00e8b5SJohn Crispin 	cmd->wake_dura_us = params->wake_dura_us;
32173d00e8b5SJohn Crispin 	cmd->sp_offset_us = params->sp_offset_us;
32183d00e8b5SJohn Crispin 	cmd->flags = params->twt_cmd;
32193d00e8b5SJohn Crispin 	if (params->flag_bcast)
32203d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_BCAST;
32213d00e8b5SJohn Crispin 	if (params->flag_trigger)
32223d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_TRIGGER;
32233d00e8b5SJohn Crispin 	if (params->flag_flow_type)
32243d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_FLOW_TYPE;
32253d00e8b5SJohn Crispin 	if (params->flag_protection)
32263d00e8b5SJohn Crispin 		cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_PROTECTION;
32273d00e8b5SJohn Crispin 
32283d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
32293d00e8b5SJohn 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",
32303d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id, cmd->wake_intvl_us,
32313d00e8b5SJohn Crispin 		   cmd->wake_intvl_mantis, cmd->wake_dura_us, cmd->sp_offset_us,
32323d00e8b5SJohn Crispin 		   cmd->flags);
32333d00e8b5SJohn Crispin 
32343d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ADD_DIALOG_CMDID);
32353d00e8b5SJohn Crispin 
32363d00e8b5SJohn Crispin 	if (ret) {
32373d00e8b5SJohn Crispin 		ath11k_warn(ab,
32383d00e8b5SJohn Crispin 			    "failed to send wmi command to add twt dialog: %d",
32393d00e8b5SJohn Crispin 			    ret);
32403d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
32413d00e8b5SJohn Crispin 	}
32423d00e8b5SJohn Crispin 	return ret;
32433d00e8b5SJohn Crispin }
32443d00e8b5SJohn Crispin 
32453d00e8b5SJohn Crispin int ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k *ar,
32463d00e8b5SJohn Crispin 				       struct wmi_twt_del_dialog_params *params)
32473d00e8b5SJohn Crispin {
32483d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
32493d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
32503d00e8b5SJohn Crispin 	struct wmi_twt_del_dialog_params_cmd *cmd;
32513d00e8b5SJohn Crispin 	struct sk_buff *skb;
32523d00e8b5SJohn Crispin 	int ret, len;
32533d00e8b5SJohn Crispin 
32543d00e8b5SJohn Crispin 	len = sizeof(*cmd);
32553d00e8b5SJohn Crispin 
32563d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32573d00e8b5SJohn Crispin 	if (!skb)
32583d00e8b5SJohn Crispin 		return -ENOMEM;
32593d00e8b5SJohn Crispin 
32603d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_del_dialog_params_cmd *)skb->data;
32613d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DEL_DIALOG_CMD) |
32623d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32633d00e8b5SJohn Crispin 
32643d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
32653d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
32663d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
32673d00e8b5SJohn Crispin 
32683d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
32693d00e8b5SJohn Crispin 		   "wmi delete twt dialog vdev %u dialog id %u\n",
32703d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id);
32713d00e8b5SJohn Crispin 
32723d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DEL_DIALOG_CMDID);
32733d00e8b5SJohn Crispin 	if (ret) {
32743d00e8b5SJohn Crispin 		ath11k_warn(ab,
32753d00e8b5SJohn Crispin 			    "failed to send wmi command to delete twt dialog: %d",
32763d00e8b5SJohn Crispin 			    ret);
32773d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
32783d00e8b5SJohn Crispin 	}
32793d00e8b5SJohn Crispin 	return ret;
32803d00e8b5SJohn Crispin }
32813d00e8b5SJohn Crispin 
32823d00e8b5SJohn Crispin int ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k *ar,
32833d00e8b5SJohn Crispin 					 struct wmi_twt_pause_dialog_params *params)
32843d00e8b5SJohn Crispin {
32853d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
32863d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
32873d00e8b5SJohn Crispin 	struct wmi_twt_pause_dialog_params_cmd *cmd;
32883d00e8b5SJohn Crispin 	struct sk_buff *skb;
32893d00e8b5SJohn Crispin 	int ret, len;
32903d00e8b5SJohn Crispin 
32913d00e8b5SJohn Crispin 	len = sizeof(*cmd);
32923d00e8b5SJohn Crispin 
32933d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32943d00e8b5SJohn Crispin 	if (!skb)
32953d00e8b5SJohn Crispin 		return -ENOMEM;
32963d00e8b5SJohn Crispin 
32973d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_pause_dialog_params_cmd *)skb->data;
32983d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
32993d00e8b5SJohn Crispin 				     WMI_TAG_TWT_PAUSE_DIALOG_CMD) |
33003d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33013d00e8b5SJohn Crispin 
33023d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
33033d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
33043d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
33053d00e8b5SJohn Crispin 
33063d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
33073d00e8b5SJohn Crispin 		   "wmi pause twt dialog vdev %u dialog id %u\n",
33083d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id);
33093d00e8b5SJohn Crispin 
33103d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_PAUSE_DIALOG_CMDID);
33113d00e8b5SJohn Crispin 	if (ret) {
33123d00e8b5SJohn Crispin 		ath11k_warn(ab,
33133d00e8b5SJohn Crispin 			    "failed to send wmi command to pause twt dialog: %d",
33143d00e8b5SJohn Crispin 			    ret);
33153d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
33163d00e8b5SJohn Crispin 	}
33173d00e8b5SJohn Crispin 	return ret;
33183d00e8b5SJohn Crispin }
33193d00e8b5SJohn Crispin 
33203d00e8b5SJohn Crispin int ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k *ar,
33213d00e8b5SJohn Crispin 					  struct wmi_twt_resume_dialog_params *params)
33223d00e8b5SJohn Crispin {
33233d00e8b5SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
33243d00e8b5SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
33253d00e8b5SJohn Crispin 	struct wmi_twt_resume_dialog_params_cmd *cmd;
33263d00e8b5SJohn Crispin 	struct sk_buff *skb;
33273d00e8b5SJohn Crispin 	int ret, len;
33283d00e8b5SJohn Crispin 
33293d00e8b5SJohn Crispin 	len = sizeof(*cmd);
33303d00e8b5SJohn Crispin 
33313d00e8b5SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33323d00e8b5SJohn Crispin 	if (!skb)
33333d00e8b5SJohn Crispin 		return -ENOMEM;
33343d00e8b5SJohn Crispin 
33353d00e8b5SJohn Crispin 	cmd = (struct wmi_twt_resume_dialog_params_cmd *)skb->data;
33363d00e8b5SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
33373d00e8b5SJohn Crispin 				     WMI_TAG_TWT_RESUME_DIALOG_CMD) |
33383d00e8b5SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33393d00e8b5SJohn Crispin 
33403d00e8b5SJohn Crispin 	cmd->vdev_id = params->vdev_id;
33413d00e8b5SJohn Crispin 	ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
33423d00e8b5SJohn Crispin 	cmd->dialog_id = params->dialog_id;
33433d00e8b5SJohn Crispin 	cmd->sp_offset_us = params->sp_offset_us;
33443d00e8b5SJohn Crispin 	cmd->next_twt_size = params->next_twt_size;
33453d00e8b5SJohn Crispin 
33463d00e8b5SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
33473d00e8b5SJohn Crispin 		   "wmi resume twt dialog vdev %u dialog id %u service period offset %u next twt subfield size %u\n",
33483d00e8b5SJohn Crispin 		   cmd->vdev_id, cmd->dialog_id, cmd->sp_offset_us,
33493d00e8b5SJohn Crispin 		   cmd->next_twt_size);
33503d00e8b5SJohn Crispin 
33513d00e8b5SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_RESUME_DIALOG_CMDID);
33523d00e8b5SJohn Crispin 	if (ret) {
33533d00e8b5SJohn Crispin 		ath11k_warn(ab,
33543d00e8b5SJohn Crispin 			    "failed to send wmi command to resume twt dialog: %d",
33553d00e8b5SJohn Crispin 			    ret);
33563d00e8b5SJohn Crispin 		dev_kfree_skb(skb);
33576d293d44SJohn Crispin 	}
33586d293d44SJohn Crispin 	return ret;
33596d293d44SJohn Crispin }
33606d293d44SJohn Crispin 
33613f8be640SJohn Crispin int
33623f8be640SJohn Crispin ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
33633f8be640SJohn Crispin 			     struct ieee80211_he_obss_pd *he_obss_pd)
33643f8be640SJohn Crispin {
33653f8be640SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
33666bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
33673f8be640SJohn Crispin 	struct wmi_obss_spatial_reuse_params_cmd *cmd;
33683f8be640SJohn Crispin 	struct sk_buff *skb;
33693f8be640SJohn Crispin 	int ret, len;
33703f8be640SJohn Crispin 
33713f8be640SJohn Crispin 	len = sizeof(*cmd);
33723f8be640SJohn Crispin 
33736bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33743f8be640SJohn Crispin 	if (!skb)
33753f8be640SJohn Crispin 		return -ENOMEM;
33763f8be640SJohn Crispin 
337777ea8b45SJohn Crispin 	cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data;
33783f8be640SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
33793f8be640SJohn Crispin 				     WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
33803f8be640SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33813f8be640SJohn Crispin 	cmd->vdev_id = vdev_id;
33823f8be640SJohn Crispin 	cmd->enable = he_obss_pd->enable;
33833f8be640SJohn Crispin 	cmd->obss_min = he_obss_pd->min_offset;
33843f8be640SJohn Crispin 	cmd->obss_max = he_obss_pd->max_offset;
33853f8be640SJohn Crispin 
33863f8be640SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
33873f8be640SJohn Crispin 				  WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
33883f8be640SJohn Crispin 	if (ret) {
33893f8be640SJohn Crispin 		ath11k_warn(ab,
33903f8be640SJohn Crispin 			    "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
33913f8be640SJohn Crispin 		dev_kfree_skb(skb);
33923f8be640SJohn Crispin 	}
33933f8be640SJohn Crispin 	return ret;
33943f8be640SJohn Crispin }
33953f8be640SJohn Crispin 
33965a032c8dSJohn Crispin int
3397b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k *ar, u32 *bitmap)
3398b56b08aeSRajkumar Manoharan {
3399b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3400b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3401b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3402b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3403b56b08aeSRajkumar Manoharan 	int ret, len;
3404b56b08aeSRajkumar Manoharan 
3405b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3406b56b08aeSRajkumar Manoharan 
3407b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3408b56b08aeSRajkumar Manoharan 	if (!skb)
3409b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3410b56b08aeSRajkumar Manoharan 
3411b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3412b56b08aeSRajkumar Manoharan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3413b56b08aeSRajkumar Manoharan 				     WMI_TAG_PDEV_SRG_BSS_COLOR_BITMAP_CMD) |
3414b56b08aeSRajkumar Manoharan 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3415b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3416b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3417b56b08aeSRajkumar Manoharan 
3418b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3419b56b08aeSRajkumar Manoharan 		   "obss pd pdev_id %d bss color bitmap %08x %08x\n",
3420b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3421b56b08aeSRajkumar Manoharan 
3422b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3423b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID);
3424b56b08aeSRajkumar Manoharan 	if (ret) {
3425b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3426b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID");
3427b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3428b56b08aeSRajkumar Manoharan 	}
3429b56b08aeSRajkumar Manoharan 
3430b56b08aeSRajkumar Manoharan 	return ret;
3431b56b08aeSRajkumar Manoharan }
3432b56b08aeSRajkumar Manoharan 
3433b56b08aeSRajkumar Manoharan int
3434b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k *ar, u32 *bitmap)
3435b56b08aeSRajkumar Manoharan {
3436b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3437b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3438b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3439b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3440b56b08aeSRajkumar Manoharan 	int ret, len;
3441b56b08aeSRajkumar Manoharan 
3442b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3443b56b08aeSRajkumar Manoharan 
3444b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3445b56b08aeSRajkumar Manoharan 	if (!skb)
3446b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3447b56b08aeSRajkumar Manoharan 
3448b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3449b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3450b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3451b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_SRG_PARTIAL_BSSID_BITMAP_CMD) |
3452b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3453b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3454b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3455b56b08aeSRajkumar Manoharan 
3456b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3457b56b08aeSRajkumar Manoharan 		   "obss pd pdev_id %d partial bssid bitmap %08x %08x\n",
3458b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3459b56b08aeSRajkumar Manoharan 
3460b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3461b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID);
3462b56b08aeSRajkumar Manoharan 	if (ret) {
3463b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3464b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID");
3465b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3466b56b08aeSRajkumar Manoharan 	}
3467b56b08aeSRajkumar Manoharan 
3468b56b08aeSRajkumar Manoharan 	return ret;
3469b56b08aeSRajkumar Manoharan }
3470b56b08aeSRajkumar Manoharan 
3471b56b08aeSRajkumar Manoharan int
3472b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3473b56b08aeSRajkumar Manoharan {
3474b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3475b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3476b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3477b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3478b56b08aeSRajkumar Manoharan 	int ret, len;
3479b56b08aeSRajkumar Manoharan 
3480b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3481b56b08aeSRajkumar Manoharan 
3482b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3483b56b08aeSRajkumar Manoharan 	if (!skb)
3484b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3485b56b08aeSRajkumar Manoharan 
3486b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3487b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3488b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3489b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3490b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3491b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3492b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3493b56b08aeSRajkumar Manoharan 
3494b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3495b56b08aeSRajkumar Manoharan 		   "obss pd srg pdev_id %d bss color enable bitmap %08x %08x\n",
3496b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3497b56b08aeSRajkumar Manoharan 
3498b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3499b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3500b56b08aeSRajkumar Manoharan 	if (ret) {
3501b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3502b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3503b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3504b56b08aeSRajkumar Manoharan 	}
3505b56b08aeSRajkumar Manoharan 
3506b56b08aeSRajkumar Manoharan 	return ret;
3507b56b08aeSRajkumar Manoharan }
3508b56b08aeSRajkumar Manoharan 
3509b56b08aeSRajkumar Manoharan int
3510b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3511b56b08aeSRajkumar Manoharan {
3512b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3513b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3514b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3515b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3516b56b08aeSRajkumar Manoharan 	int ret, len;
3517b56b08aeSRajkumar Manoharan 
3518b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3519b56b08aeSRajkumar Manoharan 
3520b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3521b56b08aeSRajkumar Manoharan 	if (!skb)
3522b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3523b56b08aeSRajkumar Manoharan 
3524b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3525b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3526b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3527b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3528b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3529b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3530b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3531b56b08aeSRajkumar Manoharan 
3532b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3533b56b08aeSRajkumar Manoharan 		   "obss pd srg pdev_id %d bssid enable bitmap %08x %08x\n",
3534b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3535b56b08aeSRajkumar Manoharan 
3536b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3537b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3538b56b08aeSRajkumar Manoharan 	if (ret) {
3539b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3540b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3541b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3542b56b08aeSRajkumar Manoharan 	}
3543b56b08aeSRajkumar Manoharan 
3544b56b08aeSRajkumar Manoharan 	return ret;
3545b56b08aeSRajkumar Manoharan }
3546b56b08aeSRajkumar Manoharan 
3547b56b08aeSRajkumar Manoharan int
3548b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3549b56b08aeSRajkumar Manoharan {
3550b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3551b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3552b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3553b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3554b56b08aeSRajkumar Manoharan 	int ret, len;
3555b56b08aeSRajkumar Manoharan 
3556b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3557b56b08aeSRajkumar Manoharan 
3558b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3559b56b08aeSRajkumar Manoharan 	if (!skb)
3560b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3561b56b08aeSRajkumar Manoharan 
3562b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3563b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3564b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3565b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3566b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3567b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3568b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3569b56b08aeSRajkumar Manoharan 
3570b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3571b56b08aeSRajkumar Manoharan 		   "obss pd non_srg pdev_id %d bss color enable bitmap %08x %08x\n",
3572b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3573b56b08aeSRajkumar Manoharan 
3574b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3575b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3576b56b08aeSRajkumar Manoharan 	if (ret) {
3577b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3578b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3579b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3580b56b08aeSRajkumar Manoharan 	}
3581b56b08aeSRajkumar Manoharan 
3582b56b08aeSRajkumar Manoharan 	return ret;
3583b56b08aeSRajkumar Manoharan }
3584b56b08aeSRajkumar Manoharan 
3585b56b08aeSRajkumar Manoharan int
3586b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3587b56b08aeSRajkumar Manoharan {
3588b56b08aeSRajkumar Manoharan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
3589b56b08aeSRajkumar Manoharan 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3590b56b08aeSRajkumar Manoharan 	struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3591b56b08aeSRajkumar Manoharan 	struct sk_buff *skb;
3592b56b08aeSRajkumar Manoharan 	int ret, len;
3593b56b08aeSRajkumar Manoharan 
3594b56b08aeSRajkumar Manoharan 	len = sizeof(*cmd);
3595b56b08aeSRajkumar Manoharan 
3596b56b08aeSRajkumar Manoharan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3597b56b08aeSRajkumar Manoharan 	if (!skb)
3598b56b08aeSRajkumar Manoharan 		return -ENOMEM;
3599b56b08aeSRajkumar Manoharan 
3600b56b08aeSRajkumar Manoharan 	cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3601b56b08aeSRajkumar Manoharan 	cmd->tlv_header =
3602b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_TAG,
3603b56b08aeSRajkumar Manoharan 			   WMI_TAG_PDEV_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3604b56b08aeSRajkumar Manoharan 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3605b56b08aeSRajkumar Manoharan 	cmd->pdev_id = ar->pdev->pdev_id;
3606b56b08aeSRajkumar Manoharan 	memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3607b56b08aeSRajkumar Manoharan 
3608b56b08aeSRajkumar Manoharan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3609b56b08aeSRajkumar Manoharan 		   "obss pd non_srg pdev_id %d bssid enable bitmap %08x %08x\n",
3610b56b08aeSRajkumar Manoharan 		   cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3611b56b08aeSRajkumar Manoharan 
3612b56b08aeSRajkumar Manoharan 	ret = ath11k_wmi_cmd_send(wmi, skb,
3613b56b08aeSRajkumar Manoharan 				  WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3614b56b08aeSRajkumar Manoharan 	if (ret) {
3615b56b08aeSRajkumar Manoharan 		ath11k_warn(ab,
3616b56b08aeSRajkumar Manoharan 			    "failed to send WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3617b56b08aeSRajkumar Manoharan 		dev_kfree_skb(skb);
3618b56b08aeSRajkumar Manoharan 	}
3619b56b08aeSRajkumar Manoharan 
3620b56b08aeSRajkumar Manoharan 	return ret;
3621b56b08aeSRajkumar Manoharan }
3622b56b08aeSRajkumar Manoharan 
3623b56b08aeSRajkumar Manoharan int
36245a032c8dSJohn Crispin ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id,
36255a032c8dSJohn Crispin 					     u8 bss_color, u32 period,
36265a032c8dSJohn Crispin 					     bool enable)
36275a032c8dSJohn Crispin {
36285a032c8dSJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
36295a032c8dSJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
36305a032c8dSJohn Crispin 	struct wmi_obss_color_collision_cfg_params_cmd *cmd;
36315a032c8dSJohn Crispin 	struct sk_buff *skb;
36325a032c8dSJohn Crispin 	int ret, len;
36335a032c8dSJohn Crispin 
36345a032c8dSJohn Crispin 	len = sizeof(*cmd);
36355a032c8dSJohn Crispin 
36365a032c8dSJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
36375a032c8dSJohn Crispin 	if (!skb)
36385a032c8dSJohn Crispin 		return -ENOMEM;
36395a032c8dSJohn Crispin 
36405a032c8dSJohn Crispin 	cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data;
36415a032c8dSJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
36425a032c8dSJohn Crispin 				     WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) |
36435a032c8dSJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
36445a032c8dSJohn Crispin 	cmd->vdev_id = vdev_id;
36455a032c8dSJohn Crispin 	cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION :
36465a032c8dSJohn Crispin 				 ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE;
36475a032c8dSJohn Crispin 	cmd->current_bss_color = bss_color;
36485a032c8dSJohn Crispin 	cmd->detection_period_ms = period;
36495a032c8dSJohn Crispin 	cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS;
36505a032c8dSJohn Crispin 	cmd->free_slot_expiry_time_ms = 0;
36515a032c8dSJohn Crispin 	cmd->flags = 0;
36525a032c8dSJohn Crispin 
36535a032c8dSJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
36545a032c8dSJohn Crispin 		   "wmi_send_obss_color_collision_cfg id %d type %d bss_color %d detect_period %d scan_period %d\n",
36555a032c8dSJohn Crispin 		   cmd->vdev_id, cmd->evt_type, cmd->current_bss_color,
36565a032c8dSJohn Crispin 		   cmd->detection_period_ms, cmd->scan_period_ms);
36575a032c8dSJohn Crispin 
36585a032c8dSJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
36595a032c8dSJohn Crispin 				  WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID);
36605a032c8dSJohn Crispin 	if (ret) {
36615a032c8dSJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID");
36625a032c8dSJohn Crispin 		dev_kfree_skb(skb);
36635a032c8dSJohn Crispin 	}
36645a032c8dSJohn Crispin 	return ret;
36655a032c8dSJohn Crispin }
36665a032c8dSJohn Crispin 
36675a032c8dSJohn Crispin int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id,
36685a032c8dSJohn Crispin 						bool enable)
36695a032c8dSJohn Crispin {
36705a032c8dSJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
36715a032c8dSJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
36725a032c8dSJohn Crispin 	struct wmi_bss_color_change_enable_params_cmd *cmd;
36735a032c8dSJohn Crispin 	struct sk_buff *skb;
36745a032c8dSJohn Crispin 	int ret, len;
36755a032c8dSJohn Crispin 
36765a032c8dSJohn Crispin 	len = sizeof(*cmd);
36775a032c8dSJohn Crispin 
36785a032c8dSJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
36795a032c8dSJohn Crispin 	if (!skb)
36805a032c8dSJohn Crispin 		return -ENOMEM;
36815a032c8dSJohn Crispin 
36825a032c8dSJohn Crispin 	cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data;
36835a032c8dSJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) |
36845a032c8dSJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
36855a032c8dSJohn Crispin 	cmd->vdev_id = vdev_id;
36865a032c8dSJohn Crispin 	cmd->enable = enable ? 1 : 0;
36875a032c8dSJohn Crispin 
36885a032c8dSJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
36895a032c8dSJohn Crispin 		   "wmi_send_bss_color_change_enable id %d enable %d\n",
36905a032c8dSJohn Crispin 		   cmd->vdev_id, cmd->enable);
36915a032c8dSJohn Crispin 
36925a032c8dSJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
36935a032c8dSJohn Crispin 				  WMI_BSS_COLOR_CHANGE_ENABLE_CMDID);
36945a032c8dSJohn Crispin 	if (ret) {
36959a8074e3SColin Ian King 		ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID");
36965a032c8dSJohn Crispin 		dev_kfree_skb(skb);
36975a032c8dSJohn Crispin 	}
36985a032c8dSJohn Crispin 	return ret;
36995a032c8dSJohn Crispin }
37005a032c8dSJohn Crispin 
3701047679e3SAloka Dixit int ath11k_wmi_fils_discovery_tmpl(struct ath11k *ar, u32 vdev_id,
3702047679e3SAloka Dixit 				   struct sk_buff *tmpl)
3703047679e3SAloka Dixit {
3704047679e3SAloka Dixit 	struct wmi_tlv *tlv;
3705047679e3SAloka Dixit 	struct sk_buff *skb;
3706047679e3SAloka Dixit 	void *ptr;
3707047679e3SAloka Dixit 	int ret, len;
3708047679e3SAloka Dixit 	size_t aligned_len;
3709047679e3SAloka Dixit 	struct wmi_fils_discovery_tmpl_cmd *cmd;
3710047679e3SAloka Dixit 
3711047679e3SAloka Dixit 	aligned_len = roundup(tmpl->len, 4);
3712047679e3SAloka Dixit 	len = sizeof(*cmd) + TLV_HDR_SIZE + aligned_len;
3713047679e3SAloka Dixit 
3714047679e3SAloka Dixit 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3715047679e3SAloka Dixit 		   "WMI vdev %i set FILS discovery template\n", vdev_id);
3716047679e3SAloka Dixit 
3717047679e3SAloka Dixit 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3718047679e3SAloka Dixit 	if (!skb)
3719047679e3SAloka Dixit 		return -ENOMEM;
3720047679e3SAloka Dixit 
3721047679e3SAloka Dixit 	cmd = (struct wmi_fils_discovery_tmpl_cmd *)skb->data;
3722047679e3SAloka Dixit 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3723047679e3SAloka Dixit 				     WMI_TAG_FILS_DISCOVERY_TMPL_CMD) |
3724047679e3SAloka Dixit 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3725047679e3SAloka Dixit 	cmd->vdev_id = vdev_id;
3726047679e3SAloka Dixit 	cmd->buf_len = tmpl->len;
3727047679e3SAloka Dixit 	ptr = skb->data + sizeof(*cmd);
3728047679e3SAloka Dixit 
3729047679e3SAloka Dixit 	tlv = ptr;
3730047679e3SAloka Dixit 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3731047679e3SAloka Dixit 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
3732047679e3SAloka Dixit 	memcpy(tlv->value, tmpl->data, tmpl->len);
3733047679e3SAloka Dixit 
3734047679e3SAloka Dixit 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_FILS_DISCOVERY_TMPL_CMDID);
3735047679e3SAloka Dixit 	if (ret) {
3736047679e3SAloka Dixit 		ath11k_warn(ar->ab,
3737047679e3SAloka Dixit 			    "WMI vdev %i failed to send FILS discovery template command\n",
3738047679e3SAloka Dixit 			    vdev_id);
3739047679e3SAloka Dixit 		dev_kfree_skb(skb);
3740047679e3SAloka Dixit 	}
3741047679e3SAloka Dixit 	return ret;
3742047679e3SAloka Dixit }
3743047679e3SAloka Dixit 
3744047679e3SAloka Dixit int ath11k_wmi_probe_resp_tmpl(struct ath11k *ar, u32 vdev_id,
3745047679e3SAloka Dixit 			       struct sk_buff *tmpl)
3746047679e3SAloka Dixit {
3747047679e3SAloka Dixit 	struct wmi_probe_tmpl_cmd *cmd;
3748047679e3SAloka Dixit 	struct wmi_bcn_prb_info *probe_info;
3749047679e3SAloka Dixit 	struct wmi_tlv *tlv;
3750047679e3SAloka Dixit 	struct sk_buff *skb;
3751047679e3SAloka Dixit 	void *ptr;
3752047679e3SAloka Dixit 	int ret, len;
3753047679e3SAloka Dixit 	size_t aligned_len = roundup(tmpl->len, 4);
3754047679e3SAloka Dixit 
3755047679e3SAloka Dixit 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3756047679e3SAloka Dixit 		   "WMI vdev %i set probe response template\n", vdev_id);
3757047679e3SAloka Dixit 
3758047679e3SAloka Dixit 	len = sizeof(*cmd) + sizeof(*probe_info) + TLV_HDR_SIZE + aligned_len;
3759047679e3SAloka Dixit 
3760047679e3SAloka Dixit 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3761047679e3SAloka Dixit 	if (!skb)
3762047679e3SAloka Dixit 		return -ENOMEM;
3763047679e3SAloka Dixit 
3764047679e3SAloka Dixit 	cmd = (struct wmi_probe_tmpl_cmd *)skb->data;
3765047679e3SAloka Dixit 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PRB_TMPL_CMD) |
3766047679e3SAloka Dixit 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3767047679e3SAloka Dixit 	cmd->vdev_id = vdev_id;
3768047679e3SAloka Dixit 	cmd->buf_len = tmpl->len;
3769047679e3SAloka Dixit 
3770047679e3SAloka Dixit 	ptr = skb->data + sizeof(*cmd);
3771047679e3SAloka Dixit 
3772047679e3SAloka Dixit 	probe_info = ptr;
3773047679e3SAloka Dixit 	len = sizeof(*probe_info);
3774047679e3SAloka Dixit 	probe_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3775047679e3SAloka Dixit 					    WMI_TAG_BCN_PRB_INFO) |
3776047679e3SAloka Dixit 				 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3777047679e3SAloka Dixit 	probe_info->caps = 0;
3778047679e3SAloka Dixit 	probe_info->erp = 0;
3779047679e3SAloka Dixit 
3780047679e3SAloka Dixit 	ptr += sizeof(*probe_info);
3781047679e3SAloka Dixit 
3782047679e3SAloka Dixit 	tlv = ptr;
3783047679e3SAloka Dixit 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3784047679e3SAloka Dixit 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
3785047679e3SAloka Dixit 	memcpy(tlv->value, tmpl->data, tmpl->len);
3786047679e3SAloka Dixit 
3787047679e3SAloka Dixit 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_PRB_TMPL_CMDID);
3788047679e3SAloka Dixit 	if (ret) {
3789047679e3SAloka Dixit 		ath11k_warn(ar->ab,
3790047679e3SAloka Dixit 			    "WMI vdev %i failed to send probe response template command\n",
3791047679e3SAloka Dixit 			    vdev_id);
3792047679e3SAloka Dixit 		dev_kfree_skb(skb);
3793047679e3SAloka Dixit 	}
3794047679e3SAloka Dixit 	return ret;
3795047679e3SAloka Dixit }
3796047679e3SAloka Dixit 
3797047679e3SAloka Dixit int ath11k_wmi_fils_discovery(struct ath11k *ar, u32 vdev_id, u32 interval,
3798047679e3SAloka Dixit 			      bool unsol_bcast_probe_resp_enabled)
3799047679e3SAloka Dixit {
3800047679e3SAloka Dixit 	struct sk_buff *skb;
3801047679e3SAloka Dixit 	int ret, len;
3802047679e3SAloka Dixit 	struct wmi_fils_discovery_cmd *cmd;
3803047679e3SAloka Dixit 
3804047679e3SAloka Dixit 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3805047679e3SAloka Dixit 		   "WMI vdev %i set %s interval to %u TU\n",
3806047679e3SAloka Dixit 		   vdev_id, unsol_bcast_probe_resp_enabled ?
3807047679e3SAloka Dixit 		   "unsolicited broadcast probe response" : "FILS discovery",
3808047679e3SAloka Dixit 		   interval);
3809047679e3SAloka Dixit 
3810047679e3SAloka Dixit 	len = sizeof(*cmd);
3811047679e3SAloka Dixit 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3812047679e3SAloka Dixit 	if (!skb)
3813047679e3SAloka Dixit 		return -ENOMEM;
3814047679e3SAloka Dixit 
3815047679e3SAloka Dixit 	cmd = (struct wmi_fils_discovery_cmd *)skb->data;
3816047679e3SAloka Dixit 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ENABLE_FILS_CMD) |
3817047679e3SAloka Dixit 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3818047679e3SAloka Dixit 	cmd->vdev_id = vdev_id;
3819047679e3SAloka Dixit 	cmd->interval = interval;
3820047679e3SAloka Dixit 	cmd->config = unsol_bcast_probe_resp_enabled;
3821047679e3SAloka Dixit 
3822047679e3SAloka Dixit 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_ENABLE_FILS_CMDID);
3823047679e3SAloka Dixit 	if (ret) {
3824047679e3SAloka Dixit 		ath11k_warn(ar->ab,
3825047679e3SAloka Dixit 			    "WMI vdev %i failed to send FILS discovery enable/disable command\n",
3826047679e3SAloka Dixit 			    vdev_id);
3827047679e3SAloka Dixit 		dev_kfree_skb(skb);
3828047679e3SAloka Dixit 	}
3829047679e3SAloka Dixit 	return ret;
3830047679e3SAloka Dixit }
3831047679e3SAloka Dixit 
3832d5c65159SKalle Valo static void
3833886433a9SJohn Crispin ath11k_wmi_obss_color_collision_event(struct ath11k_base *ab, struct sk_buff *skb)
3834886433a9SJohn Crispin {
3835886433a9SJohn Crispin 	const void **tb;
3836886433a9SJohn Crispin 	const struct wmi_obss_color_collision_event *ev;
3837886433a9SJohn Crispin 	struct ath11k_vif *arvif;
3838886433a9SJohn Crispin 	int ret;
3839886433a9SJohn Crispin 
3840886433a9SJohn Crispin 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3841886433a9SJohn Crispin 	if (IS_ERR(tb)) {
3842886433a9SJohn Crispin 		ret = PTR_ERR(tb);
3843886433a9SJohn Crispin 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3844886433a9SJohn Crispin 		return;
3845886433a9SJohn Crispin 	}
3846886433a9SJohn Crispin 
384701e782c8SWen Gong 	rcu_read_lock();
384801e782c8SWen Gong 
3849886433a9SJohn Crispin 	ev = tb[WMI_TAG_OBSS_COLOR_COLLISION_EVT];
3850886433a9SJohn Crispin 	if (!ev) {
3851886433a9SJohn Crispin 		ath11k_warn(ab, "failed to fetch obss color collision ev");
3852886433a9SJohn Crispin 		goto exit;
3853886433a9SJohn Crispin 	}
3854886433a9SJohn Crispin 
3855886433a9SJohn Crispin 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
3856886433a9SJohn Crispin 	if (!arvif) {
3857886433a9SJohn Crispin 		ath11k_warn(ab, "failed to find arvif with vedv id %d in obss_color_collision_event\n",
3858886433a9SJohn Crispin 			    ev->vdev_id);
3859886433a9SJohn Crispin 		goto exit;
3860886433a9SJohn Crispin 	}
3861886433a9SJohn Crispin 
3862886433a9SJohn Crispin 	switch (ev->evt_type) {
3863886433a9SJohn Crispin 	case WMI_BSS_COLOR_COLLISION_DETECTION:
386482253ddaSJohannes Berg 		ieee80211_obss_color_collision_notify(arvif->vif, ev->obss_color_bitmap,
386503895c84SLorenzo Bianconi 						      GFP_KERNEL);
3866886433a9SJohn Crispin 		ath11k_dbg(ab, ATH11K_DBG_WMI,
3867886433a9SJohn Crispin 			   "OBSS color collision detected vdev:%d, event:%d, bitmap:%08llx\n",
3868886433a9SJohn Crispin 			   ev->vdev_id, ev->evt_type, ev->obss_color_bitmap);
3869886433a9SJohn Crispin 		break;
3870886433a9SJohn Crispin 	case WMI_BSS_COLOR_COLLISION_DISABLE:
3871886433a9SJohn Crispin 	case WMI_BSS_COLOR_FREE_SLOT_TIMER_EXPIRY:
3872886433a9SJohn Crispin 	case WMI_BSS_COLOR_FREE_SLOT_AVAILABLE:
3873886433a9SJohn Crispin 		break;
3874886433a9SJohn Crispin 	default:
3875c27506ccSColin Ian King 		ath11k_warn(ab, "received unknown obss color collision detection event\n");
3876886433a9SJohn Crispin 	}
3877886433a9SJohn Crispin 
3878886433a9SJohn Crispin exit:
3879886433a9SJohn Crispin 	kfree(tb);
388001e782c8SWen Gong 	rcu_read_unlock();
3881886433a9SJohn Crispin }
3882886433a9SJohn Crispin 
3883886433a9SJohn Crispin static void
3884d5c65159SKalle Valo ath11k_fill_band_to_mac_param(struct ath11k_base  *soc,
3885d5c65159SKalle Valo 			      struct wmi_host_pdev_band_to_mac *band_to_mac)
3886d5c65159SKalle Valo {
3887d5c65159SKalle Valo 	u8 i;
3888d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
3889d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
3890d5c65159SKalle Valo 
3891d5c65159SKalle Valo 	for (i = 0; i < soc->num_radios; i++) {
3892d5c65159SKalle Valo 		pdev = &soc->pdevs[i];
3893d5c65159SKalle Valo 		hal_reg_cap = &soc->hal_reg_cap[i];
3894d5c65159SKalle Valo 		band_to_mac[i].pdev_id = pdev->pdev_id;
3895d5c65159SKalle Valo 
3896d5c65159SKalle Valo 		switch (pdev->cap.supported_bands) {
3897d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_5G_CAP:
3898d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3899d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3900d5c65159SKalle Valo 			break;
3901d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_CAP:
3902d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3903d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
3904d5c65159SKalle Valo 			break;
3905d5c65159SKalle Valo 		case WMI_HOST_WLAN_5G_CAP:
3906d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
3907d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3908d5c65159SKalle Valo 			break;
3909d5c65159SKalle Valo 		default:
3910d5c65159SKalle Valo 			break;
3911d5c65159SKalle Valo 		}
3912d5c65159SKalle Valo 	}
3913d5c65159SKalle Valo }
3914d5c65159SKalle Valo 
3915d5c65159SKalle Valo static void
3916d5c65159SKalle Valo ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
3917d5c65159SKalle Valo 				struct target_resource_config *tg_cfg)
3918d5c65159SKalle Valo {
3919d5c65159SKalle Valo 	wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
3920d5c65159SKalle Valo 	wmi_cfg->num_peers = tg_cfg->num_peers;
3921d5c65159SKalle Valo 	wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
3922d5c65159SKalle Valo 	wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
3923d5c65159SKalle Valo 	wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
3924d5c65159SKalle Valo 	wmi_cfg->num_tids = tg_cfg->num_tids;
3925d5c65159SKalle Valo 	wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
3926d5c65159SKalle Valo 	wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
3927d5c65159SKalle Valo 	wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
3928d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
3929d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
3930d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
3931d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
3932d5c65159SKalle Valo 	wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
3933d5c65159SKalle Valo 	wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
3934d5c65159SKalle Valo 	wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
3935d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
3936d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_ap_profiles =
3937d5c65159SKalle Valo 		tg_cfg->roam_offload_max_ap_profiles;
3938d5c65159SKalle Valo 	wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
3939d5c65159SKalle Valo 	wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
3940d5c65159SKalle Valo 	wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
3941d5c65159SKalle Valo 	wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
3942d5c65159SKalle Valo 	wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
3943d5c65159SKalle Valo 	wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
3944d5c65159SKalle Valo 	wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
3945d5c65159SKalle Valo 	wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
3946d5c65159SKalle Valo 		tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
3947d5c65159SKalle Valo 	wmi_cfg->vow_config = tg_cfg->vow_config;
3948d5c65159SKalle Valo 	wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
3949d5c65159SKalle Valo 	wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
3950d5c65159SKalle Valo 	wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
3951d5c65159SKalle Valo 	wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
3952d5c65159SKalle Valo 	wmi_cfg->num_tdls_conn_table_entries =
3953d5c65159SKalle Valo 		tg_cfg->num_tdls_conn_table_entries;
3954d5c65159SKalle Valo 	wmi_cfg->beacon_tx_offload_max_vdev =
3955d5c65159SKalle Valo 		tg_cfg->beacon_tx_offload_max_vdev;
3956d5c65159SKalle Valo 	wmi_cfg->num_multicast_filter_entries =
3957d5c65159SKalle Valo 		tg_cfg->num_multicast_filter_entries;
3958d5c65159SKalle Valo 	wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
3959d5c65159SKalle Valo 	wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
3960d5c65159SKalle Valo 	wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
3961d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_sleep_sta =
3962d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_sleep_sta;
3963d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_buffer_sta =
3964d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_buffer_sta;
3965d5c65159SKalle Valo 	wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
3966d5c65159SKalle Valo 	wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
3967d5c65159SKalle Valo 	wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
3968d5c65159SKalle Valo 	wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
3969d5c65159SKalle Valo 	wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
3970d5c65159SKalle Valo 	wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
3971d5c65159SKalle Valo 	wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
39727e9fb241SSeevalamuthu Mariappan 	wmi_cfg->flag1 = tg_cfg->flag1;
3973d5c65159SKalle Valo 	wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
39746d293d44SJohn Crispin 	wmi_cfg->sched_params = tg_cfg->sched_params;
39756d293d44SJohn Crispin 	wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
39766d293d44SJohn Crispin 	wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
3977d5c65159SKalle Valo }
3978d5c65159SKalle Valo 
3979d5c65159SKalle Valo static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
3980d5c65159SKalle Valo 				struct wmi_init_cmd_param *param)
3981d5c65159SKalle Valo {
39826bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3983d5c65159SKalle Valo 	struct sk_buff *skb;
3984d5c65159SKalle Valo 	struct wmi_init_cmd *cmd;
3985d5c65159SKalle Valo 	struct wmi_resource_config *cfg;
3986d5c65159SKalle Valo 	struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
3987d5c65159SKalle Valo 	struct wmi_pdev_band_to_mac *band_to_mac;
3988d5c65159SKalle Valo 	struct wlan_host_mem_chunk *host_mem_chunks;
3989d5c65159SKalle Valo 	struct wmi_tlv *tlv;
3990d5c65159SKalle Valo 	size_t ret, len;
3991d5c65159SKalle Valo 	void *ptr;
3992d5c65159SKalle Valo 	u32 hw_mode_len = 0;
3993d5c65159SKalle Valo 	u16 idx;
3994d5c65159SKalle Valo 
3995d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
3996d5c65159SKalle Valo 		hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
3997d5c65159SKalle Valo 			      (param->num_band_to_mac * sizeof(*band_to_mac));
3998d5c65159SKalle Valo 
3999d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
40002d4bcbedSCarl Huang 	      (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0);
4001d5c65159SKalle Valo 
40026bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
4003d5c65159SKalle Valo 	if (!skb)
4004d5c65159SKalle Valo 		return -ENOMEM;
4005d5c65159SKalle Valo 
4006d5c65159SKalle Valo 	cmd = (struct wmi_init_cmd *)skb->data;
4007d5c65159SKalle Valo 
4008d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
4009d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4010d5c65159SKalle Valo 
4011d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
4012d5c65159SKalle Valo 	cfg = ptr;
4013d5c65159SKalle Valo 
4014d5c65159SKalle Valo 	ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
4015d5c65159SKalle Valo 
4016d5c65159SKalle Valo 	cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
4017d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
4018d5c65159SKalle Valo 
4019d5c65159SKalle Valo 	ptr += sizeof(*cfg);
4020d5c65159SKalle Valo 	host_mem_chunks = ptr + TLV_HDR_SIZE;
4021d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk);
4022d5c65159SKalle Valo 
4023d5c65159SKalle Valo 	for (idx = 0; idx < param->num_mem_chunks; ++idx) {
4024d5c65159SKalle Valo 		host_mem_chunks[idx].tlv_header =
4025d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
4026d5c65159SKalle Valo 					   WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
4027d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN, len);
4028d5c65159SKalle Valo 
4029d5c65159SKalle Valo 		host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
4030d5c65159SKalle Valo 		host_mem_chunks[idx].size = param->mem_chunks[idx].len;
4031d5c65159SKalle Valo 		host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
4032d5c65159SKalle Valo 
4033d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
4034d5c65159SKalle Valo 			   "WMI host mem chunk req_id %d paddr 0x%llx len %d\n",
4035d5c65159SKalle Valo 			   param->mem_chunks[idx].req_id,
4036d5c65159SKalle Valo 			   (u64)param->mem_chunks[idx].paddr,
4037d5c65159SKalle Valo 			   param->mem_chunks[idx].len);
4038d5c65159SKalle Valo 	}
4039d5c65159SKalle Valo 	cmd->num_host_mem_chunks = param->num_mem_chunks;
4040d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
4041d5c65159SKalle Valo 
4042d5c65159SKalle Valo 	/* num_mem_chunks is zero */
4043d5c65159SKalle Valo 	tlv = ptr;
4044d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4045d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
4046d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE + len;
4047d5c65159SKalle Valo 
4048d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
4049d5c65159SKalle Valo 		hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr;
4050d5c65159SKalle Valo 		hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4051d5c65159SKalle Valo 						 WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4052d5c65159SKalle Valo 				      FIELD_PREP(WMI_TLV_LEN,
4053d5c65159SKalle Valo 						 sizeof(*hw_mode) - TLV_HDR_SIZE);
4054d5c65159SKalle Valo 
4055d5c65159SKalle Valo 		hw_mode->hw_mode_index = param->hw_mode_id;
4056d5c65159SKalle Valo 		hw_mode->num_band_to_mac = param->num_band_to_mac;
4057d5c65159SKalle Valo 
4058d5c65159SKalle Valo 		ptr += sizeof(*hw_mode);
4059d5c65159SKalle Valo 
4060d5c65159SKalle Valo 		len = param->num_band_to_mac * sizeof(*band_to_mac);
4061d5c65159SKalle Valo 		tlv = ptr;
4062d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4063d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len);
4064d5c65159SKalle Valo 
4065d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
4066d5c65159SKalle Valo 		len = sizeof(*band_to_mac);
4067d5c65159SKalle Valo 
4068d5c65159SKalle Valo 		for (idx = 0; idx < param->num_band_to_mac; idx++) {
4069d5c65159SKalle Valo 			band_to_mac = (void *)ptr;
4070d5c65159SKalle Valo 
4071d5c65159SKalle Valo 			band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4072d5c65159SKalle Valo 							     WMI_TAG_PDEV_BAND_TO_MAC) |
4073d5c65159SKalle Valo 						  FIELD_PREP(WMI_TLV_LEN,
4074d5c65159SKalle Valo 							     len - TLV_HDR_SIZE);
4075d5c65159SKalle Valo 			band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
4076d5c65159SKalle Valo 			band_to_mac->start_freq =
4077d5c65159SKalle Valo 				param->band_to_mac[idx].start_freq;
4078d5c65159SKalle Valo 			band_to_mac->end_freq =
4079d5c65159SKalle Valo 				param->band_to_mac[idx].end_freq;
4080d5c65159SKalle Valo 			ptr += sizeof(*band_to_mac);
4081d5c65159SKalle Valo 		}
4082d5c65159SKalle Valo 	}
4083d5c65159SKalle Valo 
4084d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
4085d5c65159SKalle Valo 	if (ret) {
4086d5c65159SKalle Valo 		ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
4087d5c65159SKalle Valo 		dev_kfree_skb(skb);
4088d5c65159SKalle Valo 	}
4089d5c65159SKalle Valo 
4090d5c65159SKalle Valo 	return ret;
4091d5c65159SKalle Valo }
4092d5c65159SKalle Valo 
409326c79927SSriram R int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar,
409426c79927SSriram R 			    int pdev_id)
409526c79927SSriram R {
409626c79927SSriram R 	struct ath11k_wmi_pdev_lro_config_cmd *cmd;
409726c79927SSriram R 	struct sk_buff *skb;
409826c79927SSriram R 	int ret;
409926c79927SSriram R 
410026c79927SSriram R 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
410126c79927SSriram R 	if (!skb)
410226c79927SSriram R 		return -ENOMEM;
410326c79927SSriram R 
410426c79927SSriram R 	cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data;
410526c79927SSriram R 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) |
410626c79927SSriram R 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
410726c79927SSriram R 
410826c79927SSriram R 	get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE);
410926c79927SSriram R 	get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE);
411026c79927SSriram R 
411126c79927SSriram R 	cmd->pdev_id = pdev_id;
411226c79927SSriram R 
411326c79927SSriram R 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID);
411426c79927SSriram R 	if (ret) {
411526c79927SSriram R 		ath11k_warn(ar->ab,
411626c79927SSriram R 			    "failed to send lro cfg req wmi cmd\n");
411726c79927SSriram R 		goto err;
411826c79927SSriram R 	}
411926c79927SSriram R 
412026c79927SSriram R 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
412126c79927SSriram R 		   "WMI lro cfg cmd pdev_id 0x%x\n", pdev_id);
412226c79927SSriram R 	return 0;
412326c79927SSriram R err:
412426c79927SSriram R 	dev_kfree_skb(skb);
412526c79927SSriram R 	return ret;
412626c79927SSriram R }
412726c79927SSriram R 
4128d5c65159SKalle Valo int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
4129d5c65159SKalle Valo {
4130d5c65159SKalle Valo 	unsigned long time_left;
4131d5c65159SKalle Valo 
41326bc9d6f7SJohn Crispin 	time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready,
4133d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
4134d5c65159SKalle Valo 	if (!time_left)
4135d5c65159SKalle Valo 		return -ETIMEDOUT;
4136d5c65159SKalle Valo 
4137d5c65159SKalle Valo 	return 0;
4138d5c65159SKalle Valo }
4139d5c65159SKalle Valo 
4140d5c65159SKalle Valo int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
4141d5c65159SKalle Valo {
4142d5c65159SKalle Valo 	unsigned long time_left;
4143d5c65159SKalle Valo 
41446bc9d6f7SJohn Crispin 	time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready,
4145d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
4146d5c65159SKalle Valo 	if (!time_left)
4147d5c65159SKalle Valo 		return -ETIMEDOUT;
4148d5c65159SKalle Valo 
4149d5c65159SKalle Valo 	return 0;
4150d5c65159SKalle Valo }
4151d5c65159SKalle Valo 
415243ed15e1SCarl Huang int ath11k_wmi_set_hw_mode(struct ath11k_base *ab,
415343ed15e1SCarl Huang 			   enum wmi_host_hw_mode_config_type mode)
415443ed15e1SCarl Huang {
415543ed15e1SCarl Huang 	struct wmi_pdev_set_hw_mode_cmd_param *cmd;
415643ed15e1SCarl Huang 	struct sk_buff *skb;
415743ed15e1SCarl Huang 	struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab;
415843ed15e1SCarl Huang 	int len;
415943ed15e1SCarl Huang 	int ret;
416043ed15e1SCarl Huang 
416143ed15e1SCarl Huang 	len = sizeof(*cmd);
416243ed15e1SCarl Huang 
416343ed15e1SCarl Huang 	skb = ath11k_wmi_alloc_skb(wmi_ab, len);
4164292bff94SColin Ian King 	if (!skb)
4165292bff94SColin Ian King 		return -ENOMEM;
4166292bff94SColin Ian King 
416743ed15e1SCarl Huang 	cmd = (struct wmi_pdev_set_hw_mode_cmd_param *)skb->data;
416843ed15e1SCarl Huang 
416943ed15e1SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_HW_MODE_CMD) |
417043ed15e1SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
417143ed15e1SCarl Huang 
417243ed15e1SCarl Huang 	cmd->pdev_id = WMI_PDEV_ID_SOC;
417343ed15e1SCarl Huang 	cmd->hw_mode_index = mode;
417443ed15e1SCarl Huang 
417543ed15e1SCarl Huang 	ret = ath11k_wmi_cmd_send(&wmi_ab->wmi[0], skb, WMI_PDEV_SET_HW_MODE_CMDID);
417643ed15e1SCarl Huang 	if (ret) {
417743ed15e1SCarl Huang 		ath11k_warn(ab, "failed to send WMI_PDEV_SET_HW_MODE_CMDID\n");
417843ed15e1SCarl Huang 		dev_kfree_skb(skb);
417943ed15e1SCarl Huang 	}
418043ed15e1SCarl Huang 
418143ed15e1SCarl Huang 	return ret;
418243ed15e1SCarl Huang }
418343ed15e1SCarl Huang 
4184d5c65159SKalle Valo int ath11k_wmi_cmd_init(struct ath11k_base *ab)
4185d5c65159SKalle Valo {
41866bc9d6f7SJohn Crispin 	struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab;
4187d5c65159SKalle Valo 	struct wmi_init_cmd_param init_param;
4188d5c65159SKalle Valo 	struct target_resource_config  config;
4189d5c65159SKalle Valo 
4190d5c65159SKalle Valo 	memset(&init_param, 0, sizeof(init_param));
4191d5c65159SKalle Valo 	memset(&config, 0, sizeof(config));
4192d5c65159SKalle Valo 
41932d4bcbedSCarl Huang 	ab->hw_params.hw_ops->wmi_init_config(ab, &config);
41942d4bcbedSCarl Huang 
4195d5c65159SKalle Valo 	memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config));
4196d5c65159SKalle Valo 
4197d5c65159SKalle Valo 	init_param.res_cfg = &wmi_sc->wlan_resource_config;
4198d5c65159SKalle Valo 	init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
4199d5c65159SKalle Valo 	init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
4200d5c65159SKalle Valo 	init_param.mem_chunks = wmi_sc->mem_chunks;
4201d5c65159SKalle Valo 
420243ed15e1SCarl Huang 	if (ab->hw_params.single_pdev_only)
420343ed15e1SCarl Huang 		init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
420443ed15e1SCarl Huang 
4205d5c65159SKalle Valo 	init_param.num_band_to_mac = ab->num_radios;
4206d5c65159SKalle Valo 	ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
4207d5c65159SKalle Valo 
4208d5c65159SKalle Valo 	return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param);
4209d5c65159SKalle Valo }
4210d5c65159SKalle Valo 
42119d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar,
42129d11b7bfSKarthikeyan Periyasamy 				  struct ath11k_wmi_vdev_spectral_conf_param *param)
42139d11b7bfSKarthikeyan Periyasamy {
42149d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_vdev_spectral_conf_cmd *cmd;
42159d11b7bfSKarthikeyan Periyasamy 	struct sk_buff *skb;
42169d11b7bfSKarthikeyan Periyasamy 	int ret;
42179d11b7bfSKarthikeyan Periyasamy 
42189d11b7bfSKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
42199d11b7bfSKarthikeyan Periyasamy 	if (!skb)
42209d11b7bfSKarthikeyan Periyasamy 		return -ENOMEM;
42219d11b7bfSKarthikeyan Periyasamy 
42229d11b7bfSKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data;
42239d11b7bfSKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
42249d11b7bfSKarthikeyan Periyasamy 				     WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) |
42259d11b7bfSKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
42269d11b7bfSKarthikeyan Periyasamy 
42279d11b7bfSKarthikeyan Periyasamy 	memcpy(&cmd->param, param, sizeof(*param));
42289d11b7bfSKarthikeyan Periyasamy 
42299d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
42309d11b7bfSKarthikeyan Periyasamy 				  WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
42319d11b7bfSKarthikeyan Periyasamy 	if (ret) {
42329d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
42339d11b7bfSKarthikeyan Periyasamy 			    "failed to send spectral scan config wmi cmd\n");
42349d11b7bfSKarthikeyan Periyasamy 		goto err;
42359d11b7bfSKarthikeyan Periyasamy 	}
42369d11b7bfSKarthikeyan Periyasamy 
42379d11b7bfSKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
42389d11b7bfSKarthikeyan Periyasamy 		   "WMI spectral scan config cmd vdev_id 0x%x\n",
42399d11b7bfSKarthikeyan Periyasamy 		   param->vdev_id);
42409d11b7bfSKarthikeyan Periyasamy 
42419d11b7bfSKarthikeyan Periyasamy 	return 0;
42429d11b7bfSKarthikeyan Periyasamy err:
42439d11b7bfSKarthikeyan Periyasamy 	dev_kfree_skb(skb);
42449d11b7bfSKarthikeyan Periyasamy 	return ret;
42459d11b7bfSKarthikeyan Periyasamy }
42469d11b7bfSKarthikeyan Periyasamy 
42479d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id,
42489d11b7bfSKarthikeyan Periyasamy 				    u32 trigger, u32 enable)
42499d11b7bfSKarthikeyan Periyasamy {
42509d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_vdev_spectral_enable_cmd *cmd;
42519d11b7bfSKarthikeyan Periyasamy 	struct sk_buff *skb;
42529d11b7bfSKarthikeyan Periyasamy 	int ret;
42539d11b7bfSKarthikeyan Periyasamy 
42549d11b7bfSKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
42559d11b7bfSKarthikeyan Periyasamy 	if (!skb)
42569d11b7bfSKarthikeyan Periyasamy 		return -ENOMEM;
42579d11b7bfSKarthikeyan Periyasamy 
42589d11b7bfSKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data;
42599d11b7bfSKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
42609d11b7bfSKarthikeyan Periyasamy 				     WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) |
42619d11b7bfSKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
42629d11b7bfSKarthikeyan Periyasamy 
42639d11b7bfSKarthikeyan Periyasamy 	cmd->vdev_id = vdev_id;
42649d11b7bfSKarthikeyan Periyasamy 	cmd->trigger_cmd = trigger;
42659d11b7bfSKarthikeyan Periyasamy 	cmd->enable_cmd = enable;
42669d11b7bfSKarthikeyan Periyasamy 
42679d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
42689d11b7bfSKarthikeyan Periyasamy 				  WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
42699d11b7bfSKarthikeyan Periyasamy 	if (ret) {
42709d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
42719d11b7bfSKarthikeyan Periyasamy 			    "failed to send spectral enable wmi cmd\n");
42729d11b7bfSKarthikeyan Periyasamy 		goto err;
42739d11b7bfSKarthikeyan Periyasamy 	}
42749d11b7bfSKarthikeyan Periyasamy 
42759d11b7bfSKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
42769d11b7bfSKarthikeyan Periyasamy 		   "WMI spectral enable cmd vdev id 0x%x\n",
42779d11b7bfSKarthikeyan Periyasamy 		   vdev_id);
42789d11b7bfSKarthikeyan Periyasamy 
42799d11b7bfSKarthikeyan Periyasamy 	return 0;
42809d11b7bfSKarthikeyan Periyasamy err:
42819d11b7bfSKarthikeyan Periyasamy 	dev_kfree_skb(skb);
42829d11b7bfSKarthikeyan Periyasamy 	return ret;
42839d11b7bfSKarthikeyan Periyasamy }
42849d11b7bfSKarthikeyan Periyasamy 
4285bd647855SKarthikeyan Periyasamy int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar,
4286bd647855SKarthikeyan Periyasamy 				 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param)
4287bd647855SKarthikeyan Periyasamy {
4288bd647855SKarthikeyan Periyasamy 	struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd;
4289bd647855SKarthikeyan Periyasamy 	struct sk_buff *skb;
4290bd647855SKarthikeyan Periyasamy 	int ret;
4291bd647855SKarthikeyan Periyasamy 
4292bd647855SKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4293bd647855SKarthikeyan Periyasamy 	if (!skb)
4294bd647855SKarthikeyan Periyasamy 		return -ENOMEM;
4295bd647855SKarthikeyan Periyasamy 
4296bd647855SKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data;
4297bd647855SKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) |
4298bd647855SKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4299bd647855SKarthikeyan Periyasamy 
4300bd647855SKarthikeyan Periyasamy 	cmd->pdev_id		= param->pdev_id;
4301bd647855SKarthikeyan Periyasamy 	cmd->module_id		= param->module_id;
4302bd647855SKarthikeyan Periyasamy 	cmd->base_paddr_lo	= param->base_paddr_lo;
4303bd647855SKarthikeyan Periyasamy 	cmd->base_paddr_hi	= param->base_paddr_hi;
4304bd647855SKarthikeyan Periyasamy 	cmd->head_idx_paddr_lo	= param->head_idx_paddr_lo;
4305bd647855SKarthikeyan Periyasamy 	cmd->head_idx_paddr_hi	= param->head_idx_paddr_hi;
4306bd647855SKarthikeyan Periyasamy 	cmd->tail_idx_paddr_lo	= param->tail_idx_paddr_lo;
4307bd647855SKarthikeyan Periyasamy 	cmd->tail_idx_paddr_hi	= param->tail_idx_paddr_hi;
4308bd647855SKarthikeyan Periyasamy 	cmd->num_elems		= param->num_elems;
4309bd647855SKarthikeyan Periyasamy 	cmd->buf_size		= param->buf_size;
4310bd647855SKarthikeyan Periyasamy 	cmd->num_resp_per_event	= param->num_resp_per_event;
4311bd647855SKarthikeyan Periyasamy 	cmd->event_timeout_ms	= param->event_timeout_ms;
4312bd647855SKarthikeyan Periyasamy 
4313bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4314bd647855SKarthikeyan Periyasamy 				  WMI_PDEV_DMA_RING_CFG_REQ_CMDID);
4315bd647855SKarthikeyan Periyasamy 	if (ret) {
4316bd647855SKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
4317bd647855SKarthikeyan Periyasamy 			    "failed to send dma ring cfg req wmi cmd\n");
4318bd647855SKarthikeyan Periyasamy 		goto err;
4319bd647855SKarthikeyan Periyasamy 	}
4320bd647855SKarthikeyan Periyasamy 
4321bd647855SKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4322bd647855SKarthikeyan Periyasamy 		   "WMI DMA ring cfg req cmd pdev_id 0x%x\n",
4323bd647855SKarthikeyan Periyasamy 		   param->pdev_id);
4324bd647855SKarthikeyan Periyasamy 
4325bd647855SKarthikeyan Periyasamy 	return 0;
4326bd647855SKarthikeyan Periyasamy err:
4327bd647855SKarthikeyan Periyasamy 	dev_kfree_skb(skb);
4328bd647855SKarthikeyan Periyasamy 	return ret;
4329bd647855SKarthikeyan Periyasamy }
4330bd647855SKarthikeyan Periyasamy 
43319d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc,
43329d11b7bfSKarthikeyan Periyasamy 					      u16 tag, u16 len,
43339d11b7bfSKarthikeyan Periyasamy 					      const void *ptr, void *data)
43349d11b7bfSKarthikeyan Periyasamy {
43359d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
43369d11b7bfSKarthikeyan Periyasamy 
43379d11b7bfSKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY)
43389d11b7bfSKarthikeyan Periyasamy 		return -EPROTO;
43399d11b7bfSKarthikeyan Periyasamy 
43409d11b7bfSKarthikeyan Periyasamy 	if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry)
43419d11b7bfSKarthikeyan Periyasamy 		return -ENOBUFS;
43429d11b7bfSKarthikeyan Periyasamy 
43439d11b7bfSKarthikeyan Periyasamy 	parse->num_buf_entry++;
43449d11b7bfSKarthikeyan Periyasamy 	return 0;
43459d11b7bfSKarthikeyan Periyasamy }
43469d11b7bfSKarthikeyan Periyasamy 
43479d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc,
43489d11b7bfSKarthikeyan Periyasamy 					     u16 tag, u16 len,
43499d11b7bfSKarthikeyan Periyasamy 					     const void *ptr, void *data)
43509d11b7bfSKarthikeyan Periyasamy {
43519d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
43529d11b7bfSKarthikeyan Periyasamy 
43539d11b7bfSKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA)
43549d11b7bfSKarthikeyan Periyasamy 		return -EPROTO;
43559d11b7bfSKarthikeyan Periyasamy 
43569d11b7bfSKarthikeyan Periyasamy 	if (parse->num_meta >= parse->fixed.num_meta_data_entry)
43579d11b7bfSKarthikeyan Periyasamy 		return -ENOBUFS;
43589d11b7bfSKarthikeyan Periyasamy 
43599d11b7bfSKarthikeyan Periyasamy 	parse->num_meta++;
43609d11b7bfSKarthikeyan Periyasamy 	return 0;
43619d11b7bfSKarthikeyan Periyasamy }
43629d11b7bfSKarthikeyan Periyasamy 
43639d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab,
43649d11b7bfSKarthikeyan Periyasamy 					u16 tag, u16 len,
43659d11b7bfSKarthikeyan Periyasamy 					const void *ptr, void *data)
43669d11b7bfSKarthikeyan Periyasamy {
43679d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
43689d11b7bfSKarthikeyan Periyasamy 	int ret;
43699d11b7bfSKarthikeyan Periyasamy 
43709d11b7bfSKarthikeyan Periyasamy 	switch (tag) {
43719d11b7bfSKarthikeyan Periyasamy 	case WMI_TAG_DMA_BUF_RELEASE:
43729d11b7bfSKarthikeyan Periyasamy 		memcpy(&parse->fixed, ptr,
43739d11b7bfSKarthikeyan Periyasamy 		       sizeof(struct ath11k_wmi_dma_buf_release_fixed_param));
43749d11b7bfSKarthikeyan Periyasamy 		parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id);
43759d11b7bfSKarthikeyan Periyasamy 		break;
43769d11b7bfSKarthikeyan Periyasamy 	case WMI_TAG_ARRAY_STRUCT:
43779d11b7bfSKarthikeyan Periyasamy 		if (!parse->buf_entry_done) {
43789d11b7bfSKarthikeyan Periyasamy 			parse->num_buf_entry = 0;
43799d11b7bfSKarthikeyan Periyasamy 			parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr;
43809d11b7bfSKarthikeyan Periyasamy 
43819d11b7bfSKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
43829d11b7bfSKarthikeyan Periyasamy 						  ath11k_wmi_tlv_dma_buf_entry_parse,
43839d11b7bfSKarthikeyan Periyasamy 						  parse);
43849d11b7bfSKarthikeyan Periyasamy 			if (ret) {
43859d11b7bfSKarthikeyan Periyasamy 				ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n",
43869d11b7bfSKarthikeyan Periyasamy 					    ret);
43879d11b7bfSKarthikeyan Periyasamy 				return ret;
43889d11b7bfSKarthikeyan Periyasamy 			}
43899d11b7bfSKarthikeyan Periyasamy 
43909d11b7bfSKarthikeyan Periyasamy 			parse->buf_entry_done = true;
43919d11b7bfSKarthikeyan Periyasamy 		} else if (!parse->meta_data_done) {
43929d11b7bfSKarthikeyan Periyasamy 			parse->num_meta = 0;
43939d11b7bfSKarthikeyan Periyasamy 			parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr;
43949d11b7bfSKarthikeyan Periyasamy 
43959d11b7bfSKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
43969d11b7bfSKarthikeyan Periyasamy 						  ath11k_wmi_tlv_dma_buf_meta_parse,
43979d11b7bfSKarthikeyan Periyasamy 						  parse);
43989d11b7bfSKarthikeyan Periyasamy 			if (ret) {
43999d11b7bfSKarthikeyan Periyasamy 				ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n",
44009d11b7bfSKarthikeyan Periyasamy 					    ret);
44019d11b7bfSKarthikeyan Periyasamy 				return ret;
44029d11b7bfSKarthikeyan Periyasamy 			}
44039d11b7bfSKarthikeyan Periyasamy 
44049d11b7bfSKarthikeyan Periyasamy 			parse->meta_data_done = true;
44059d11b7bfSKarthikeyan Periyasamy 		}
44069d11b7bfSKarthikeyan Periyasamy 		break;
44079d11b7bfSKarthikeyan Periyasamy 	default:
44089d11b7bfSKarthikeyan Periyasamy 		break;
44099d11b7bfSKarthikeyan Periyasamy 	}
44109d11b7bfSKarthikeyan Periyasamy 	return 0;
44119d11b7bfSKarthikeyan Periyasamy }
44129d11b7bfSKarthikeyan Periyasamy 
44139d11b7bfSKarthikeyan Periyasamy static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab,
44149d11b7bfSKarthikeyan Periyasamy 						       struct sk_buff *skb)
44159d11b7bfSKarthikeyan Periyasamy {
44169d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse parse = { };
44179d11b7bfSKarthikeyan Periyasamy 	struct ath11k_dbring_buf_release_event param;
44189d11b7bfSKarthikeyan Periyasamy 	int ret;
44199d11b7bfSKarthikeyan Periyasamy 
44209d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
44219d11b7bfSKarthikeyan Periyasamy 				  ath11k_wmi_tlv_dma_buf_parse,
44229d11b7bfSKarthikeyan Periyasamy 				  &parse);
44239d11b7bfSKarthikeyan Periyasamy 	if (ret) {
44249d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret);
44259d11b7bfSKarthikeyan Periyasamy 		return;
44269d11b7bfSKarthikeyan Periyasamy 	}
44279d11b7bfSKarthikeyan Periyasamy 
44289d11b7bfSKarthikeyan Periyasamy 	param.fixed		= parse.fixed;
44299d11b7bfSKarthikeyan Periyasamy 	param.buf_entry		= parse.buf_entry;
44309d11b7bfSKarthikeyan Periyasamy 	param.num_buf_entry	= parse.num_buf_entry;
44319d11b7bfSKarthikeyan Periyasamy 	param.meta_data		= parse.meta_data;
44329d11b7bfSKarthikeyan Periyasamy 	param.num_meta		= parse.num_meta;
44339d11b7bfSKarthikeyan Periyasamy 
44349d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_dbring_buffer_release_event(ab, &param);
44359d11b7bfSKarthikeyan Periyasamy 	if (ret) {
44369d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
44379d11b7bfSKarthikeyan Periyasamy 		return;
44389d11b7bfSKarthikeyan Periyasamy 	}
44399d11b7bfSKarthikeyan Periyasamy }
44409d11b7bfSKarthikeyan Periyasamy 
4441d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
4442d5c65159SKalle Valo 					     u16 tag, u16 len,
4443d5c65159SKalle Valo 					     const void *ptr, void *data)
4444d5c65159SKalle Valo {
4445d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4446d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_cap;
4447d5c65159SKalle Valo 	u32 phy_map = 0;
4448d5c65159SKalle Valo 
4449d5c65159SKalle Valo 	if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
4450d5c65159SKalle Valo 		return -EPROTO;
4451d5c65159SKalle Valo 
4452d5c65159SKalle Valo 	if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
4453d5c65159SKalle Valo 		return -ENOBUFS;
4454d5c65159SKalle Valo 
4455d5c65159SKalle Valo 	hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
4456d5c65159SKalle Valo 				   hw_mode_id);
4457d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps++;
4458d5c65159SKalle Valo 
4459d5c65159SKalle Valo 	phy_map = hw_mode_cap->phy_id_map;
4460d5c65159SKalle Valo 	while (phy_map) {
4461d5c65159SKalle Valo 		svc_rdy_ext->tot_phy_id++;
4462d5c65159SKalle Valo 		phy_map = phy_map >> 1;
4463d5c65159SKalle Valo 	}
4464d5c65159SKalle Valo 
4465d5c65159SKalle Valo 	return 0;
4466d5c65159SKalle Valo }
4467d5c65159SKalle Valo 
4468d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
4469d5c65159SKalle Valo 				       u16 len, const void *ptr, void *data)
4470d5c65159SKalle Valo {
4471d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4472d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
4473d5c65159SKalle Valo 	enum wmi_host_hw_mode_config_type mode, pref;
4474d5c65159SKalle Valo 	u32 i;
4475d5c65159SKalle Valo 	int ret;
4476d5c65159SKalle Valo 
4477d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps = 0;
4478d5c65159SKalle Valo 	svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
4479d5c65159SKalle Valo 
4480d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4481d5c65159SKalle Valo 				  ath11k_wmi_tlv_hw_mode_caps_parse,
4482d5c65159SKalle Valo 				  svc_rdy_ext);
4483d5c65159SKalle Valo 	if (ret) {
4484d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4485d5c65159SKalle Valo 		return ret;
4486d5c65159SKalle Valo 	}
4487d5c65159SKalle Valo 
4488d5c65159SKalle Valo 	i = 0;
4489d5c65159SKalle Valo 	while (i < svc_rdy_ext->n_hw_mode_caps) {
4490d5c65159SKalle Valo 		hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
4491d5c65159SKalle Valo 		mode = hw_mode_caps->hw_mode_id;
44926bc9d6f7SJohn Crispin 		pref = soc->wmi_ab.preferred_hw_mode;
4493d5c65159SKalle Valo 
4494d5c65159SKalle Valo 		if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
4495d5c65159SKalle Valo 			svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
44966bc9d6f7SJohn Crispin 			soc->wmi_ab.preferred_hw_mode = mode;
4497d5c65159SKalle Valo 		}
4498d5c65159SKalle Valo 		i++;
4499d5c65159SKalle Valo 	}
4500d5c65159SKalle Valo 
45015f859bc0SCarl Huang 	ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n",
45025f859bc0SCarl Huang 		   soc->wmi_ab.preferred_hw_mode);
45036bc9d6f7SJohn Crispin 	if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
4504d5c65159SKalle Valo 		return -EINVAL;
4505d5c65159SKalle Valo 
4506d5c65159SKalle Valo 	return 0;
4507d5c65159SKalle Valo }
4508d5c65159SKalle Valo 
4509d5c65159SKalle Valo static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
4510d5c65159SKalle Valo 					     u16 tag, u16 len,
4511d5c65159SKalle Valo 					     const void *ptr, void *data)
4512d5c65159SKalle Valo {
4513d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4514d5c65159SKalle Valo 
4515d5c65159SKalle Valo 	if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
4516d5c65159SKalle Valo 		return -EPROTO;
4517d5c65159SKalle Valo 
4518d5c65159SKalle Valo 	if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
4519d5c65159SKalle Valo 		return -ENOBUFS;
4520d5c65159SKalle Valo 
45215b90fc76SAnilkumar Kolli 	len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
45225b90fc76SAnilkumar Kolli 	if (!svc_rdy_ext->n_mac_phy_caps) {
4523ec436338SGustavo A. R. Silva 		svc_rdy_ext->mac_phy_caps = kcalloc(svc_rdy_ext->tot_phy_id,
4524ec436338SGustavo A. R. Silva 						    len, GFP_ATOMIC);
45255b90fc76SAnilkumar Kolli 		if (!svc_rdy_ext->mac_phy_caps)
45265b90fc76SAnilkumar Kolli 			return -ENOMEM;
45275b90fc76SAnilkumar Kolli 	}
45285b90fc76SAnilkumar Kolli 
45295b90fc76SAnilkumar Kolli 	memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
4530d5c65159SKalle Valo 	svc_rdy_ext->n_mac_phy_caps++;
4531d5c65159SKalle Valo 	return 0;
4532d5c65159SKalle Valo }
4533d5c65159SKalle Valo 
4534d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
4535d5c65159SKalle Valo 						 u16 tag, u16 len,
4536d5c65159SKalle Valo 						 const void *ptr, void *data)
4537d5c65159SKalle Valo {
4538d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4539d5c65159SKalle Valo 
4540d5c65159SKalle Valo 	if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
4541d5c65159SKalle Valo 		return -EPROTO;
4542d5c65159SKalle Valo 
4543d5c65159SKalle Valo 	if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
4544d5c65159SKalle Valo 		return -ENOBUFS;
4545d5c65159SKalle Valo 
4546d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps++;
4547d5c65159SKalle Valo 	return 0;
4548d5c65159SKalle Valo }
4549d5c65159SKalle Valo 
4550d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
4551d5c65159SKalle Valo 					   u16 len, const void *ptr, void *data)
4552d5c65159SKalle Valo {
45536bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4554d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4555d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext reg_cap;
4556d5c65159SKalle Valo 	int ret;
4557d5c65159SKalle Valo 	u32 i;
4558d5c65159SKalle Valo 
4559d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps = 0;
4560d5c65159SKalle Valo 	svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
4561d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4562d5c65159SKalle Valo 				  ath11k_wmi_tlv_ext_hal_reg_caps_parse,
4563d5c65159SKalle Valo 				  svc_rdy_ext);
4564d5c65159SKalle Valo 	if (ret) {
4565d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4566d5c65159SKalle Valo 		return ret;
4567d5c65159SKalle Valo 	}
4568d5c65159SKalle Valo 
4569d5c65159SKalle Valo 	for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
4570d5c65159SKalle Valo 		ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
4571d5c65159SKalle Valo 						      svc_rdy_ext->soc_hal_reg_caps,
4572d5c65159SKalle Valo 						      svc_rdy_ext->ext_hal_reg_caps, i,
4573d5c65159SKalle Valo 						      &reg_cap);
4574d5c65159SKalle Valo 		if (ret) {
4575d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract reg cap %d\n", i);
4576d5c65159SKalle Valo 			return ret;
4577d5c65159SKalle Valo 		}
4578d5c65159SKalle Valo 
4579d5c65159SKalle Valo 		memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
4580d5c65159SKalle Valo 		       &reg_cap, sizeof(reg_cap));
4581d5c65159SKalle Valo 	}
4582d5c65159SKalle Valo 	return 0;
4583d5c65159SKalle Valo }
4584d5c65159SKalle Valo 
4585d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
4586d5c65159SKalle Valo 						     u16 len, const void *ptr,
4587d5c65159SKalle Valo 						     void *data)
4588d5c65159SKalle Valo {
45896bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4590d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4591d5c65159SKalle Valo 	u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
4592d5c65159SKalle Valo 	u32 phy_id_map;
45935f859bc0SCarl Huang 	int pdev_index = 0;
4594d5c65159SKalle Valo 	int ret;
4595d5c65159SKalle Valo 
4596d5c65159SKalle Valo 	svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
4597d5c65159SKalle Valo 	svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
4598d5c65159SKalle Valo 
4599d5c65159SKalle Valo 	soc->num_radios = 0;
460013706340SWen Gong 	soc->target_pdev_count = 0;
4601d5c65159SKalle Valo 	phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
4602d5c65159SKalle Valo 
4603d5c65159SKalle Valo 	while (phy_id_map && soc->num_radios < MAX_RADIOS) {
4604d5c65159SKalle Valo 		ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
4605d5c65159SKalle Valo 							    svc_rdy_ext->hw_caps,
4606d5c65159SKalle Valo 							    svc_rdy_ext->hw_mode_caps,
4607d5c65159SKalle Valo 							    svc_rdy_ext->soc_hal_reg_caps,
4608d5c65159SKalle Valo 							    svc_rdy_ext->mac_phy_caps,
4609d5c65159SKalle Valo 							    hw_mode_id, soc->num_radios,
46105f859bc0SCarl Huang 							    &soc->pdevs[pdev_index]);
4611d5c65159SKalle Valo 		if (ret) {
4612d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
4613d5c65159SKalle Valo 				    soc->num_radios);
4614d5c65159SKalle Valo 			return ret;
4615d5c65159SKalle Valo 		}
4616d5c65159SKalle Valo 
4617d5c65159SKalle Valo 		soc->num_radios++;
4618d5c65159SKalle Valo 
46195f859bc0SCarl Huang 		/* For QCA6390, save mac_phy capability in the same pdev */
46205f859bc0SCarl Huang 		if (soc->hw_params.single_pdev_only)
46215f859bc0SCarl Huang 			pdev_index = 0;
46225f859bc0SCarl Huang 		else
46235f859bc0SCarl Huang 			pdev_index = soc->num_radios;
46245f859bc0SCarl Huang 
4625d5c65159SKalle Valo 		/* TODO: mac_phy_cap prints */
4626d5c65159SKalle Valo 		phy_id_map >>= 1;
4627d5c65159SKalle Valo 	}
46285f859bc0SCarl Huang 
46295f859bc0SCarl Huang 	/* For QCA6390, set num_radios to 1 because host manages
46305f859bc0SCarl Huang 	 * both 2G and 5G radio in one pdev.
46315f859bc0SCarl Huang 	 * Set pdev_id = 0 and 0 means soc level.
46325f859bc0SCarl Huang 	 */
46335f859bc0SCarl Huang 	if (soc->hw_params.single_pdev_only) {
46345f859bc0SCarl Huang 		soc->num_radios = 1;
46355f859bc0SCarl Huang 		soc->pdevs[0].pdev_id = 0;
46365f859bc0SCarl Huang 	}
46375f859bc0SCarl Huang 
4638d5c65159SKalle Valo 	return 0;
4639d5c65159SKalle Valo }
4640d5c65159SKalle Valo 
4641bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc,
4642bd647855SKarthikeyan Periyasamy 					      u16 tag, u16 len,
4643bd647855SKarthikeyan Periyasamy 					      const void *ptr, void *data)
4644bd647855SKarthikeyan Periyasamy {
4645bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse *parse = data;
4646bd647855SKarthikeyan Periyasamy 
4647bd647855SKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_RING_CAPABILITIES)
4648bd647855SKarthikeyan Periyasamy 		return -EPROTO;
4649bd647855SKarthikeyan Periyasamy 
4650bd647855SKarthikeyan Periyasamy 	parse->n_dma_ring_caps++;
4651bd647855SKarthikeyan Periyasamy 	return 0;
4652bd647855SKarthikeyan Periyasamy }
4653bd647855SKarthikeyan Periyasamy 
4654bd647855SKarthikeyan Periyasamy static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab,
4655bd647855SKarthikeyan Periyasamy 					u32 num_cap)
4656bd647855SKarthikeyan Periyasamy {
4657bd647855SKarthikeyan Periyasamy 	size_t sz;
4658bd647855SKarthikeyan Periyasamy 	void *ptr;
4659bd647855SKarthikeyan Periyasamy 
4660bd647855SKarthikeyan Periyasamy 	sz = num_cap * sizeof(struct ath11k_dbring_cap);
4661bd647855SKarthikeyan Periyasamy 	ptr = kzalloc(sz, GFP_ATOMIC);
4662bd647855SKarthikeyan Periyasamy 	if (!ptr)
4663bd647855SKarthikeyan Periyasamy 		return -ENOMEM;
4664bd647855SKarthikeyan Periyasamy 
4665bd647855SKarthikeyan Periyasamy 	ab->db_caps = ptr;
4666bd647855SKarthikeyan Periyasamy 	ab->num_db_cap = num_cap;
4667bd647855SKarthikeyan Periyasamy 
4668bd647855SKarthikeyan Periyasamy 	return 0;
4669bd647855SKarthikeyan Periyasamy }
4670bd647855SKarthikeyan Periyasamy 
4671bd647855SKarthikeyan Periyasamy static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
4672bd647855SKarthikeyan Periyasamy {
4673bd647855SKarthikeyan Periyasamy 	kfree(ab->db_caps);
4674bd647855SKarthikeyan Periyasamy 	ab->db_caps = NULL;
4675bd647855SKarthikeyan Periyasamy }
4676bd647855SKarthikeyan Periyasamy 
4677bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab,
4678bd647855SKarthikeyan Periyasamy 					u16 len, const void *ptr, void *data)
4679bd647855SKarthikeyan Periyasamy {
4680bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data;
4681bd647855SKarthikeyan Periyasamy 	struct wmi_dma_ring_capabilities *dma_caps;
4682bd647855SKarthikeyan Periyasamy 	struct ath11k_dbring_cap *dir_buff_caps;
4683bd647855SKarthikeyan Periyasamy 	int ret;
4684bd647855SKarthikeyan Periyasamy 	u32 i;
4685bd647855SKarthikeyan Periyasamy 
4686bd647855SKarthikeyan Periyasamy 	dma_caps_parse->n_dma_ring_caps = 0;
4687bd647855SKarthikeyan Periyasamy 	dma_caps = (struct wmi_dma_ring_capabilities *)ptr;
4688bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4689bd647855SKarthikeyan Periyasamy 				  ath11k_wmi_tlv_dma_ring_caps_parse,
4690bd647855SKarthikeyan Periyasamy 				  dma_caps_parse);
4691bd647855SKarthikeyan Periyasamy 	if (ret) {
4692bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret);
4693bd647855SKarthikeyan Periyasamy 		return ret;
4694bd647855SKarthikeyan Periyasamy 	}
4695bd647855SKarthikeyan Periyasamy 
4696bd647855SKarthikeyan Periyasamy 	if (!dma_caps_parse->n_dma_ring_caps)
4697bd647855SKarthikeyan Periyasamy 		return 0;
4698bd647855SKarthikeyan Periyasamy 
4699bd647855SKarthikeyan Periyasamy 	if (ab->num_db_cap) {
4700bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n");
4701bd647855SKarthikeyan Periyasamy 		return 0;
4702bd647855SKarthikeyan Periyasamy 	}
4703bd647855SKarthikeyan Periyasamy 
4704bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps);
4705bd647855SKarthikeyan Periyasamy 	if (ret)
4706bd647855SKarthikeyan Periyasamy 		return ret;
4707bd647855SKarthikeyan Periyasamy 
4708bd647855SKarthikeyan Periyasamy 	dir_buff_caps = ab->db_caps;
4709bd647855SKarthikeyan Periyasamy 	for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) {
4710bd647855SKarthikeyan Periyasamy 		if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) {
4711bd647855SKarthikeyan Periyasamy 			ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id);
4712bd647855SKarthikeyan Periyasamy 			ret = -EINVAL;
4713bd647855SKarthikeyan Periyasamy 			goto free_dir_buff;
4714bd647855SKarthikeyan Periyasamy 		}
4715bd647855SKarthikeyan Periyasamy 
4716bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].id = dma_caps[i].module_id;
4717bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id);
4718bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_elem = dma_caps[i].min_elem;
4719bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz;
4720bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align;
4721bd647855SKarthikeyan Periyasamy 	}
4722bd647855SKarthikeyan Periyasamy 
4723bd647855SKarthikeyan Periyasamy 	return 0;
4724bd647855SKarthikeyan Periyasamy 
4725bd647855SKarthikeyan Periyasamy free_dir_buff:
4726bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4727bd647855SKarthikeyan Periyasamy 	return ret;
4728bd647855SKarthikeyan Periyasamy }
4729bd647855SKarthikeyan Periyasamy 
4730d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
4731d5c65159SKalle Valo 					    u16 tag, u16 len,
4732d5c65159SKalle Valo 					    const void *ptr, void *data)
4733d5c65159SKalle Valo {
47346bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
4735d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4736d5c65159SKalle Valo 	int ret;
4737d5c65159SKalle Valo 
4738d5c65159SKalle Valo 	switch (tag) {
4739d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EXT_EVENT:
4740d5c65159SKalle Valo 		ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
4741d5c65159SKalle Valo 						&svc_rdy_ext->param);
4742d5c65159SKalle Valo 		if (ret) {
4743d5c65159SKalle Valo 			ath11k_warn(ab, "unable to extract ext params\n");
4744d5c65159SKalle Valo 			return ret;
4745d5c65159SKalle Valo 		}
4746d5c65159SKalle Valo 		break;
4747d5c65159SKalle Valo 
4748d5c65159SKalle Valo 	case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
4749d5c65159SKalle Valo 		svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
4750d5c65159SKalle Valo 		svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
4751d5c65159SKalle Valo 		break;
4752d5c65159SKalle Valo 
4753d5c65159SKalle Valo 	case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
4754d5c65159SKalle Valo 		ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
4755d5c65159SKalle Valo 								svc_rdy_ext);
4756d5c65159SKalle Valo 		if (ret)
4757d5c65159SKalle Valo 			return ret;
4758d5c65159SKalle Valo 		break;
4759d5c65159SKalle Valo 
4760d5c65159SKalle Valo 	case WMI_TAG_ARRAY_STRUCT:
4761d5c65159SKalle Valo 		if (!svc_rdy_ext->hw_mode_done) {
4762d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
4763d5c65159SKalle Valo 							  svc_rdy_ext);
4764d5c65159SKalle Valo 			if (ret)
4765d5c65159SKalle Valo 				return ret;
4766d5c65159SKalle Valo 
4767d5c65159SKalle Valo 			svc_rdy_ext->hw_mode_done = true;
4768d5c65159SKalle Valo 		} else if (!svc_rdy_ext->mac_phy_done) {
4769d5c65159SKalle Valo 			svc_rdy_ext->n_mac_phy_caps = 0;
4770d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4771d5c65159SKalle Valo 						  ath11k_wmi_tlv_mac_phy_caps_parse,
4772d5c65159SKalle Valo 						  svc_rdy_ext);
4773d5c65159SKalle Valo 			if (ret) {
4774d5c65159SKalle Valo 				ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4775d5c65159SKalle Valo 				return ret;
4776d5c65159SKalle Valo 			}
4777d5c65159SKalle Valo 
4778d5c65159SKalle Valo 			svc_rdy_ext->mac_phy_done = true;
4779d5c65159SKalle Valo 		} else if (!svc_rdy_ext->ext_hal_reg_done) {
4780d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
4781d5c65159SKalle Valo 							      svc_rdy_ext);
4782d5c65159SKalle Valo 			if (ret)
4783d5c65159SKalle Valo 				return ret;
4784d5c65159SKalle Valo 
4785d5c65159SKalle Valo 			svc_rdy_ext->ext_hal_reg_done = true;
4786bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) {
4787bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->mac_phy_chainmask_combo_done = true;
4788bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) {
4789bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->mac_phy_chainmask_cap_done = true;
4790bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->oem_dma_ring_cap_done) {
4791bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->oem_dma_ring_cap_done = true;
4792bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->dma_ring_cap_done) {
4793bd647855SKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4794bd647855SKarthikeyan Periyasamy 							   &svc_rdy_ext->dma_caps_parse);
4795bd647855SKarthikeyan Periyasamy 			if (ret)
4796bd647855SKarthikeyan Periyasamy 				return ret;
4797bd647855SKarthikeyan Periyasamy 
4798bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->dma_ring_cap_done = true;
4799d5c65159SKalle Valo 		}
4800d5c65159SKalle Valo 		break;
4801d5c65159SKalle Valo 
4802d5c65159SKalle Valo 	default:
4803d5c65159SKalle Valo 		break;
4804d5c65159SKalle Valo 	}
4805d5c65159SKalle Valo 	return 0;
4806d5c65159SKalle Valo }
4807d5c65159SKalle Valo 
4808d5c65159SKalle Valo static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
4809d5c65159SKalle Valo 					  struct sk_buff *skb)
4810d5c65159SKalle Valo {
4811d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
4812d5c65159SKalle Valo 	int ret;
4813d5c65159SKalle Valo 
4814d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4815d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_ext_parse,
4816d5c65159SKalle Valo 				  &svc_rdy_ext);
4817d5c65159SKalle Valo 	if (ret) {
4818d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4819bd647855SKarthikeyan Periyasamy 		goto err;
4820d5c65159SKalle Valo 	}
4821d5c65159SKalle Valo 
4822bd647855SKarthikeyan Periyasamy 	if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map))
4823bd647855SKarthikeyan Periyasamy 		complete(&ab->wmi_ab.service_ready);
4824bd647855SKarthikeyan Periyasamy 
48255b90fc76SAnilkumar Kolli 	kfree(svc_rdy_ext.mac_phy_caps);
4826d5c65159SKalle Valo 	return 0;
4827bd647855SKarthikeyan Periyasamy 
4828bd647855SKarthikeyan Periyasamy err:
4829bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4830bd647855SKarthikeyan Periyasamy 	return ret;
4831bd647855SKarthikeyan Periyasamy }
4832bd647855SKarthikeyan Periyasamy 
4833bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab,
4834bd647855SKarthikeyan Periyasamy 					     u16 tag, u16 len,
4835bd647855SKarthikeyan Periyasamy 					     const void *ptr, void *data)
4836bd647855SKarthikeyan Periyasamy {
4837bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_svc_rdy_ext2_parse *parse = data;
4838bd647855SKarthikeyan Periyasamy 	int ret;
4839bd647855SKarthikeyan Periyasamy 
4840bd647855SKarthikeyan Periyasamy 	switch (tag) {
4841bd647855SKarthikeyan Periyasamy 	case WMI_TAG_ARRAY_STRUCT:
4842bd647855SKarthikeyan Periyasamy 		if (!parse->dma_ring_cap_done) {
4843bd647855SKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4844bd647855SKarthikeyan Periyasamy 							   &parse->dma_caps_parse);
4845bd647855SKarthikeyan Periyasamy 			if (ret)
4846bd647855SKarthikeyan Periyasamy 				return ret;
4847bd647855SKarthikeyan Periyasamy 
4848bd647855SKarthikeyan Periyasamy 			parse->dma_ring_cap_done = true;
4849bd647855SKarthikeyan Periyasamy 		}
4850bd647855SKarthikeyan Periyasamy 		break;
4851bd647855SKarthikeyan Periyasamy 	default:
4852bd647855SKarthikeyan Periyasamy 		break;
4853bd647855SKarthikeyan Periyasamy 	}
4854bd647855SKarthikeyan Periyasamy 
4855bd647855SKarthikeyan Periyasamy 	return 0;
4856bd647855SKarthikeyan Periyasamy }
4857bd647855SKarthikeyan Periyasamy 
4858bd647855SKarthikeyan Periyasamy static int ath11k_service_ready_ext2_event(struct ath11k_base *ab,
4859bd647855SKarthikeyan Periyasamy 					   struct sk_buff *skb)
4860bd647855SKarthikeyan Periyasamy {
4861bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { };
4862bd647855SKarthikeyan Periyasamy 	int ret;
4863bd647855SKarthikeyan Periyasamy 
4864bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4865bd647855SKarthikeyan Periyasamy 				  ath11k_wmi_tlv_svc_rdy_ext2_parse,
4866bd647855SKarthikeyan Periyasamy 				  &svc_rdy_ext2);
4867bd647855SKarthikeyan Periyasamy 	if (ret) {
4868bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret);
4869bd647855SKarthikeyan Periyasamy 		goto err;
4870bd647855SKarthikeyan Periyasamy 	}
4871bd647855SKarthikeyan Periyasamy 
4872bd647855SKarthikeyan Periyasamy 	complete(&ab->wmi_ab.service_ready);
4873bd647855SKarthikeyan Periyasamy 
4874bd647855SKarthikeyan Periyasamy 	return 0;
4875bd647855SKarthikeyan Periyasamy 
4876bd647855SKarthikeyan Periyasamy err:
4877bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4878bd647855SKarthikeyan Periyasamy 	return ret;
4879d5c65159SKalle Valo }
4880d5c65159SKalle Valo 
4881d5c65159SKalle Valo static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
4882d5c65159SKalle Valo 					   struct wmi_vdev_start_resp_event *vdev_rsp)
4883d5c65159SKalle Valo {
4884d5c65159SKalle Valo 	const void **tb;
4885d5c65159SKalle Valo 	const struct wmi_vdev_start_resp_event *ev;
4886d5c65159SKalle Valo 	int ret;
4887d5c65159SKalle Valo 
4888d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4889d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4890d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4891d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4892d5c65159SKalle Valo 		return ret;
4893d5c65159SKalle Valo 	}
4894d5c65159SKalle Valo 
4895d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
4896d5c65159SKalle Valo 	if (!ev) {
4897d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev start resp ev");
4898d5c65159SKalle Valo 		kfree(tb);
4899d5c65159SKalle Valo 		return -EPROTO;
4900d5c65159SKalle Valo 	}
4901d5c65159SKalle Valo 
4902d5c65159SKalle Valo 	memset(vdev_rsp, 0, sizeof(*vdev_rsp));
4903d5c65159SKalle Valo 
4904d5c65159SKalle Valo 	vdev_rsp->vdev_id = ev->vdev_id;
4905d5c65159SKalle Valo 	vdev_rsp->requestor_id = ev->requestor_id;
4906d5c65159SKalle Valo 	vdev_rsp->resp_type = ev->resp_type;
4907d5c65159SKalle Valo 	vdev_rsp->status = ev->status;
4908d5c65159SKalle Valo 	vdev_rsp->chain_mask = ev->chain_mask;
4909d5c65159SKalle Valo 	vdev_rsp->smps_mode = ev->smps_mode;
4910d5c65159SKalle Valo 	vdev_rsp->mac_id = ev->mac_id;
4911d5c65159SKalle Valo 	vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
4912d5c65159SKalle Valo 	vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
4913d5c65159SKalle Valo 
4914d5c65159SKalle Valo 	kfree(tb);
4915d5c65159SKalle Valo 	return 0;
4916d5c65159SKalle Valo }
4917d5c65159SKalle Valo 
4918d5c65159SKalle Valo static struct cur_reg_rule
4919d5c65159SKalle Valo *create_reg_rules_from_wmi(u32 num_reg_rules,
4920d5c65159SKalle Valo 			   struct wmi_regulatory_rule_struct *wmi_reg_rule)
4921d5c65159SKalle Valo {
4922d5c65159SKalle Valo 	struct cur_reg_rule *reg_rule_ptr;
4923d5c65159SKalle Valo 	u32 count;
4924d5c65159SKalle Valo 
4925ec436338SGustavo A. R. Silva 	reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr),
4926d5c65159SKalle Valo 			       GFP_ATOMIC);
4927d5c65159SKalle Valo 
4928d5c65159SKalle Valo 	if (!reg_rule_ptr)
4929d5c65159SKalle Valo 		return NULL;
4930d5c65159SKalle Valo 
4931d5c65159SKalle Valo 	for (count = 0; count < num_reg_rules; count++) {
4932d5c65159SKalle Valo 		reg_rule_ptr[count].start_freq =
4933d5c65159SKalle Valo 			FIELD_GET(REG_RULE_START_FREQ,
4934d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
4935d5c65159SKalle Valo 		reg_rule_ptr[count].end_freq =
4936d5c65159SKalle Valo 			FIELD_GET(REG_RULE_END_FREQ,
4937d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
4938d5c65159SKalle Valo 		reg_rule_ptr[count].max_bw =
4939d5c65159SKalle Valo 			FIELD_GET(REG_RULE_MAX_BW,
4940d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4941d5c65159SKalle Valo 		reg_rule_ptr[count].reg_power =
4942d5c65159SKalle Valo 			FIELD_GET(REG_RULE_REG_PWR,
4943d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4944d5c65159SKalle Valo 		reg_rule_ptr[count].ant_gain =
4945d5c65159SKalle Valo 			FIELD_GET(REG_RULE_ANT_GAIN,
4946d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4947d5c65159SKalle Valo 		reg_rule_ptr[count].flags =
4948d5c65159SKalle Valo 			FIELD_GET(REG_RULE_FLAGS,
4949d5c65159SKalle Valo 				  wmi_reg_rule[count].flag_info);
4950d5c65159SKalle Valo 	}
4951d5c65159SKalle Valo 
4952d5c65159SKalle Valo 	return reg_rule_ptr;
4953d5c65159SKalle Valo }
4954d5c65159SKalle Valo 
4955d5c65159SKalle Valo static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
4956d5c65159SKalle Valo 					       struct sk_buff *skb,
4957d5c65159SKalle Valo 					       struct cur_regulatory_info *reg_info)
4958d5c65159SKalle Valo {
4959d5c65159SKalle Valo 	const void **tb;
4960d5c65159SKalle Valo 	const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
4961d5c65159SKalle Valo 	struct wmi_regulatory_rule_struct *wmi_reg_rule;
4962*25e289e1SAditya Kumar Singh 	u32 num_2ghz_reg_rules, num_5ghz_reg_rules;
4963d5c65159SKalle Valo 	int ret;
4964d5c65159SKalle Valo 
4965d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
4966d5c65159SKalle Valo 
4967d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4968d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4969d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4970d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4971d5c65159SKalle Valo 		return ret;
4972d5c65159SKalle Valo 	}
4973d5c65159SKalle Valo 
4974d5c65159SKalle Valo 	chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
4975d5c65159SKalle Valo 	if (!chan_list_event_hdr) {
4976d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
4977d5c65159SKalle Valo 		kfree(tb);
4978d5c65159SKalle Valo 		return -EPROTO;
4979d5c65159SKalle Valo 	}
4980d5c65159SKalle Valo 
4981*25e289e1SAditya Kumar Singh 	reg_info->num_2ghz_reg_rules = chan_list_event_hdr->num_2ghz_reg_rules;
4982*25e289e1SAditya Kumar Singh 	reg_info->num_5ghz_reg_rules = chan_list_event_hdr->num_5ghz_reg_rules;
4983d5c65159SKalle Valo 
4984*25e289e1SAditya Kumar Singh 	if (!(reg_info->num_2ghz_reg_rules + reg_info->num_5ghz_reg_rules)) {
4985d5c65159SKalle Valo 		ath11k_warn(ab, "No regulatory rules available in the event info\n");
4986d5c65159SKalle Valo 		kfree(tb);
4987d5c65159SKalle Valo 		return -EINVAL;
4988d5c65159SKalle Valo 	}
4989d5c65159SKalle Valo 
4990d5c65159SKalle Valo 	memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
4991d5c65159SKalle Valo 	       REG_ALPHA2_LEN);
4992d5c65159SKalle Valo 	reg_info->dfs_region = chan_list_event_hdr->dfs_region;
4993d5c65159SKalle Valo 	reg_info->phybitmap = chan_list_event_hdr->phybitmap;
4994d5c65159SKalle Valo 	reg_info->num_phy = chan_list_event_hdr->num_phy;
4995d5c65159SKalle Valo 	reg_info->phy_id = chan_list_event_hdr->phy_id;
4996d5c65159SKalle Valo 	reg_info->ctry_code = chan_list_event_hdr->country_id;
4997d5c65159SKalle Valo 	reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
4998d5c65159SKalle Valo 	if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS)
4999d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_PASS;
5000d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND)
5001d5c65159SKalle Valo 		reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND;
5002d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND)
5003d5c65159SKalle Valo 		reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND;
5004d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED)
5005d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED;
5006d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY)
5007d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY;
5008d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL)
5009d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_FAIL;
5010d5c65159SKalle Valo 
5011*25e289e1SAditya Kumar Singh 	reg_info->min_bw_2ghz = chan_list_event_hdr->min_bw_2ghz;
5012*25e289e1SAditya Kumar Singh 	reg_info->max_bw_2ghz = chan_list_event_hdr->max_bw_2ghz;
5013*25e289e1SAditya Kumar Singh 	reg_info->min_bw_5ghz = chan_list_event_hdr->min_bw_5ghz;
5014*25e289e1SAditya Kumar Singh 	reg_info->max_bw_5ghz = chan_list_event_hdr->max_bw_5ghz;
5015d5c65159SKalle Valo 
5016*25e289e1SAditya Kumar Singh 	num_2ghz_reg_rules = reg_info->num_2ghz_reg_rules;
5017*25e289e1SAditya Kumar Singh 	num_5ghz_reg_rules = reg_info->num_5ghz_reg_rules;
5018d5c65159SKalle Valo 
5019d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5020*25e289e1SAditya Kumar Singh 		   "%s:cc %s dsf %d BW: min_2ghz %d max_2ghz %d min_5ghz %d max_5ghz %d",
5021d5c65159SKalle Valo 		   __func__, reg_info->alpha2, reg_info->dfs_region,
5022*25e289e1SAditya Kumar Singh 		   reg_info->min_bw_2ghz, reg_info->max_bw_2ghz,
5023*25e289e1SAditya Kumar Singh 		   reg_info->min_bw_5ghz, reg_info->max_bw_5ghz);
5024d5c65159SKalle Valo 
5025d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5026*25e289e1SAditya Kumar Singh 		   "%s: num_2ghz_reg_rules %d num_5ghz_reg_rules %d", __func__,
5027*25e289e1SAditya Kumar Singh 		   num_2ghz_reg_rules, num_5ghz_reg_rules);
5028d5c65159SKalle Valo 
5029d5c65159SKalle Valo 	wmi_reg_rule =
5030d5c65159SKalle Valo 		(struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
5031d5c65159SKalle Valo 						+ sizeof(*chan_list_event_hdr)
5032d5c65159SKalle Valo 						+ sizeof(struct wmi_tlv));
5033d5c65159SKalle Valo 
5034*25e289e1SAditya Kumar Singh 	if (num_2ghz_reg_rules) {
5035*25e289e1SAditya Kumar Singh 		reg_info->reg_rules_2ghz_ptr =
5036*25e289e1SAditya Kumar Singh 				create_reg_rules_from_wmi(num_2ghz_reg_rules,
5037d5c65159SKalle Valo 							  wmi_reg_rule);
5038*25e289e1SAditya Kumar Singh 		if (!reg_info->reg_rules_2ghz_ptr) {
5039d5c65159SKalle Valo 			kfree(tb);
5040*25e289e1SAditya Kumar Singh 			ath11k_warn(ab, "Unable to Allocate memory for 2 GHz rules\n");
5041d5c65159SKalle Valo 			return -ENOMEM;
5042d5c65159SKalle Valo 		}
5043d5c65159SKalle Valo 	}
5044d5c65159SKalle Valo 
5045*25e289e1SAditya Kumar Singh 	if (num_5ghz_reg_rules) {
5046*25e289e1SAditya Kumar Singh 		wmi_reg_rule += num_2ghz_reg_rules;
5047*25e289e1SAditya Kumar Singh 		reg_info->reg_rules_5ghz_ptr =
5048*25e289e1SAditya Kumar Singh 				create_reg_rules_from_wmi(num_5ghz_reg_rules,
5049d5c65159SKalle Valo 							  wmi_reg_rule);
5050*25e289e1SAditya Kumar Singh 		if (!reg_info->reg_rules_5ghz_ptr) {
5051d5c65159SKalle Valo 			kfree(tb);
5052*25e289e1SAditya Kumar Singh 			ath11k_warn(ab, "Unable to Allocate memory for 5 GHz rules\n");
5053d5c65159SKalle Valo 			return -ENOMEM;
5054d5c65159SKalle Valo 		}
5055d5c65159SKalle Valo 	}
5056d5c65159SKalle Valo 
5057d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
5058d5c65159SKalle Valo 
5059d5c65159SKalle Valo 	kfree(tb);
5060d5c65159SKalle Valo 	return 0;
5061d5c65159SKalle Valo }
5062d5c65159SKalle Valo 
5063d5c65159SKalle Valo static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
5064d5c65159SKalle Valo 					struct wmi_peer_delete_resp_event *peer_del_resp)
5065d5c65159SKalle Valo {
5066d5c65159SKalle Valo 	const void **tb;
5067d5c65159SKalle Valo 	const struct wmi_peer_delete_resp_event *ev;
5068d5c65159SKalle Valo 	int ret;
5069d5c65159SKalle Valo 
5070d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5071d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5072d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5073d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5074d5c65159SKalle Valo 		return ret;
5075d5c65159SKalle Valo 	}
5076d5c65159SKalle Valo 
5077d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
5078d5c65159SKalle Valo 	if (!ev) {
5079d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer delete resp ev");
5080d5c65159SKalle Valo 		kfree(tb);
5081d5c65159SKalle Valo 		return -EPROTO;
5082d5c65159SKalle Valo 	}
5083d5c65159SKalle Valo 
5084d5c65159SKalle Valo 	memset(peer_del_resp, 0, sizeof(*peer_del_resp));
5085d5c65159SKalle Valo 
5086d5c65159SKalle Valo 	peer_del_resp->vdev_id = ev->vdev_id;
5087d5c65159SKalle Valo 	ether_addr_copy(peer_del_resp->peer_macaddr.addr,
5088d5c65159SKalle Valo 			ev->peer_macaddr.addr);
5089d5c65159SKalle Valo 
5090d5c65159SKalle Valo 	kfree(tb);
5091d5c65159SKalle Valo 	return 0;
5092d5c65159SKalle Valo }
5093d5c65159SKalle Valo 
50943cbbdfbeSRitesh Singh static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab,
50953cbbdfbeSRitesh Singh 					struct sk_buff *skb,
50963cbbdfbeSRitesh Singh 					u32 *vdev_id)
50973cbbdfbeSRitesh Singh {
50983cbbdfbeSRitesh Singh 	const void **tb;
50993cbbdfbeSRitesh Singh 	const struct wmi_vdev_delete_resp_event *ev;
51003cbbdfbeSRitesh Singh 	int ret;
51013cbbdfbeSRitesh Singh 
51023cbbdfbeSRitesh Singh 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
51033cbbdfbeSRitesh Singh 	if (IS_ERR(tb)) {
51043cbbdfbeSRitesh Singh 		ret = PTR_ERR(tb);
51053cbbdfbeSRitesh Singh 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
51063cbbdfbeSRitesh Singh 		return ret;
51073cbbdfbeSRitesh Singh 	}
51083cbbdfbeSRitesh Singh 
51093cbbdfbeSRitesh Singh 	ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT];
51103cbbdfbeSRitesh Singh 	if (!ev) {
51113cbbdfbeSRitesh Singh 		ath11k_warn(ab, "failed to fetch vdev delete resp ev");
51123cbbdfbeSRitesh Singh 		kfree(tb);
51133cbbdfbeSRitesh Singh 		return -EPROTO;
51143cbbdfbeSRitesh Singh 	}
51153cbbdfbeSRitesh Singh 
51163cbbdfbeSRitesh Singh 	*vdev_id = ev->vdev_id;
51173cbbdfbeSRitesh Singh 
51183cbbdfbeSRitesh Singh 	kfree(tb);
51193cbbdfbeSRitesh Singh 	return 0;
51203cbbdfbeSRitesh Singh }
51213cbbdfbeSRitesh Singh 
5122d5c65159SKalle Valo static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
5123d5c65159SKalle Valo 					u32 len, u32 *vdev_id,
5124d5c65159SKalle Valo 					u32 *tx_status)
5125d5c65159SKalle Valo {
5126d5c65159SKalle Valo 	const void **tb;
5127d5c65159SKalle Valo 	const struct wmi_bcn_tx_status_event *ev;
5128d5c65159SKalle Valo 	int ret;
5129d5c65159SKalle Valo 
5130d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5131d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5132d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5133d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5134d5c65159SKalle Valo 		return ret;
5135d5c65159SKalle Valo 	}
5136d5c65159SKalle Valo 
5137d5c65159SKalle Valo 	ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
5138d5c65159SKalle Valo 	if (!ev) {
5139d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch bcn tx status ev");
5140d5c65159SKalle Valo 		kfree(tb);
5141d5c65159SKalle Valo 		return -EPROTO;
5142d5c65159SKalle Valo 	}
5143d5c65159SKalle Valo 
5144d5c65159SKalle Valo 	*vdev_id   = ev->vdev_id;
5145d5c65159SKalle Valo 	*tx_status = ev->tx_status;
5146d5c65159SKalle Valo 
5147d5c65159SKalle Valo 	kfree(tb);
5148d5c65159SKalle Valo 	return 0;
5149d5c65159SKalle Valo }
5150d5c65159SKalle Valo 
5151d5c65159SKalle Valo static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5152d5c65159SKalle Valo 					      u32 *vdev_id)
5153d5c65159SKalle Valo {
5154d5c65159SKalle Valo 	const void **tb;
5155d5c65159SKalle Valo 	const struct wmi_vdev_stopped_event *ev;
5156d5c65159SKalle Valo 	int ret;
5157d5c65159SKalle Valo 
5158d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5159d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5160d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5161d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5162d5c65159SKalle Valo 		return ret;
5163d5c65159SKalle Valo 	}
5164d5c65159SKalle Valo 
5165d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
5166d5c65159SKalle Valo 	if (!ev) {
5167d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev stop ev");
5168d5c65159SKalle Valo 		kfree(tb);
5169d5c65159SKalle Valo 		return -EPROTO;
5170d5c65159SKalle Valo 	}
5171d5c65159SKalle Valo 
5172d5c65159SKalle Valo 	*vdev_id =  ev->vdev_id;
5173d5c65159SKalle Valo 
5174d5c65159SKalle Valo 	kfree(tb);
5175d5c65159SKalle Valo 	return 0;
5176d5c65159SKalle Valo }
5177d5c65159SKalle Valo 
5178d5c65159SKalle Valo static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
5179d5c65159SKalle Valo 					  struct sk_buff *skb,
5180d5c65159SKalle Valo 					  struct mgmt_rx_event_params *hdr)
5181d5c65159SKalle Valo {
5182d5c65159SKalle Valo 	const void **tb;
5183d5c65159SKalle Valo 	const struct wmi_mgmt_rx_hdr *ev;
5184d5c65159SKalle Valo 	const u8 *frame;
5185d5c65159SKalle Valo 	int ret;
5186d5c65159SKalle Valo 
5187d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5188d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5189d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5190d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5191d5c65159SKalle Valo 		return ret;
5192d5c65159SKalle Valo 	}
5193d5c65159SKalle Valo 
5194d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_RX_HDR];
5195d5c65159SKalle Valo 	frame = tb[WMI_TAG_ARRAY_BYTE];
5196d5c65159SKalle Valo 
5197d5c65159SKalle Valo 	if (!ev || !frame) {
5198d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt rx hdr");
5199d5c65159SKalle Valo 		kfree(tb);
5200d5c65159SKalle Valo 		return -EPROTO;
5201d5c65159SKalle Valo 	}
5202d5c65159SKalle Valo 
5203d5c65159SKalle Valo 	hdr->pdev_id =  ev->pdev_id;
52045dcf42f8SPradeep Kumar Chitrapu 	hdr->chan_freq = ev->chan_freq;
5205d5c65159SKalle Valo 	hdr->channel =  ev->channel;
5206d5c65159SKalle Valo 	hdr->snr =  ev->snr;
5207d5c65159SKalle Valo 	hdr->rate =  ev->rate;
5208d5c65159SKalle Valo 	hdr->phy_mode =  ev->phy_mode;
5209d5c65159SKalle Valo 	hdr->buf_len =  ev->buf_len;
5210d5c65159SKalle Valo 	hdr->status =  ev->status;
5211d5c65159SKalle Valo 	hdr->flags =  ev->flags;
5212d5c65159SKalle Valo 	hdr->rssi =  ev->rssi;
5213d5c65159SKalle Valo 	hdr->tsf_delta =  ev->tsf_delta;
5214d5c65159SKalle Valo 	memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
5215d5c65159SKalle Valo 
5216d5c65159SKalle Valo 	if (skb->len < (frame - skb->data) + hdr->buf_len) {
5217d5c65159SKalle Valo 		ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
5218d5c65159SKalle Valo 		kfree(tb);
5219d5c65159SKalle Valo 		return -EPROTO;
5220d5c65159SKalle Valo 	}
5221d5c65159SKalle Valo 
5222d5c65159SKalle Valo 	/* shift the sk_buff to point to `frame` */
5223d5c65159SKalle Valo 	skb_trim(skb, 0);
5224d5c65159SKalle Valo 	skb_put(skb, frame - skb->data);
5225d5c65159SKalle Valo 	skb_pull(skb, frame - skb->data);
5226d5c65159SKalle Valo 	skb_put(skb, hdr->buf_len);
5227d5c65159SKalle Valo 
5228d5c65159SKalle Valo 	ath11k_ce_byte_swap(skb->data, hdr->buf_len);
5229d5c65159SKalle Valo 
5230d5c65159SKalle Valo 	kfree(tb);
5231d5c65159SKalle Valo 	return 0;
5232d5c65159SKalle Valo }
5233d5c65159SKalle Valo 
523401c6c9fcSAbinaya Kalaiselvan static int wmi_process_mgmt_tx_comp(struct ath11k *ar,
523501c6c9fcSAbinaya Kalaiselvan 				    struct wmi_mgmt_tx_compl_event *tx_compl_param)
5236d5c65159SKalle Valo {
5237d5c65159SKalle Valo 	struct sk_buff *msdu;
5238d5c65159SKalle Valo 	struct ieee80211_tx_info *info;
5239d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb;
5240dddaa64dSWen Gong 	int num_mgmt;
5241d5c65159SKalle Valo 
5242d5c65159SKalle Valo 	spin_lock_bh(&ar->txmgmt_idr_lock);
524301c6c9fcSAbinaya Kalaiselvan 	msdu = idr_find(&ar->txmgmt_idr, tx_compl_param->desc_id);
5244d5c65159SKalle Valo 
5245d5c65159SKalle Valo 	if (!msdu) {
5246d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
524701c6c9fcSAbinaya Kalaiselvan 			    tx_compl_param->desc_id);
5248d5c65159SKalle Valo 		spin_unlock_bh(&ar->txmgmt_idr_lock);
5249d5c65159SKalle Valo 		return -ENOENT;
5250d5c65159SKalle Valo 	}
5251d5c65159SKalle Valo 
525201c6c9fcSAbinaya Kalaiselvan 	idr_remove(&ar->txmgmt_idr, tx_compl_param->desc_id);
5253d5c65159SKalle Valo 	spin_unlock_bh(&ar->txmgmt_idr_lock);
5254d5c65159SKalle Valo 
5255d5c65159SKalle Valo 	skb_cb = ATH11K_SKB_CB(msdu);
5256d5c65159SKalle Valo 	dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
5257d5c65159SKalle Valo 
5258d5c65159SKalle Valo 	info = IEEE80211_SKB_CB(msdu);
525901c6c9fcSAbinaya Kalaiselvan 	if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) &&
526001c6c9fcSAbinaya Kalaiselvan 	    !tx_compl_param->status) {
5261d5c65159SKalle Valo 		info->flags |= IEEE80211_TX_STAT_ACK;
526201c6c9fcSAbinaya Kalaiselvan 		if (test_bit(WMI_TLV_SERVICE_TX_DATA_MGMT_ACK_RSSI,
526301c6c9fcSAbinaya Kalaiselvan 			     ar->ab->wmi_ab.svc_map))
526401c6c9fcSAbinaya Kalaiselvan 			info->status.ack_signal = tx_compl_param->ack_rssi;
526501c6c9fcSAbinaya Kalaiselvan 	}
5266d5c65159SKalle Valo 
5267d5c65159SKalle Valo 	ieee80211_tx_status_irqsafe(ar->hw, msdu);
5268d5c65159SKalle Valo 
5269dddaa64dSWen Gong 	num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5270dddaa64dSWen Gong 
5271800113ffSSriram R 	/* WARN when we received this event without doing any mgmt tx */
5272dddaa64dSWen Gong 	if (num_mgmt < 0)
5273800113ffSSriram R 		WARN_ON_ONCE(1);
5274d5c65159SKalle Valo 
5275dddaa64dSWen Gong 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5276dddaa64dSWen Gong 		   "wmi mgmt tx comp pending %d desc id %d\n",
527701c6c9fcSAbinaya Kalaiselvan 		   num_mgmt, tx_compl_param->desc_id);
5278dddaa64dSWen Gong 
5279dddaa64dSWen Gong 	if (!num_mgmt)
5280dddaa64dSWen Gong 		wake_up(&ar->txmgmt_empty_waitq);
5281dddaa64dSWen Gong 
5282d5c65159SKalle Valo 	return 0;
5283d5c65159SKalle Valo }
5284d5c65159SKalle Valo 
5285d5c65159SKalle Valo static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
5286d5c65159SKalle Valo 					       struct sk_buff *skb,
5287d5c65159SKalle Valo 					       struct wmi_mgmt_tx_compl_event *param)
5288d5c65159SKalle Valo {
5289d5c65159SKalle Valo 	const void **tb;
5290d5c65159SKalle Valo 	const struct wmi_mgmt_tx_compl_event *ev;
5291d5c65159SKalle Valo 	int ret;
5292d5c65159SKalle Valo 
5293d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5294d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5295d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5296d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5297d5c65159SKalle Valo 		return ret;
5298d5c65159SKalle Valo 	}
5299d5c65159SKalle Valo 
5300d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
5301d5c65159SKalle Valo 	if (!ev) {
5302d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
5303d5c65159SKalle Valo 		kfree(tb);
5304d5c65159SKalle Valo 		return -EPROTO;
5305d5c65159SKalle Valo 	}
5306d5c65159SKalle Valo 
5307d5c65159SKalle Valo 	param->pdev_id = ev->pdev_id;
5308d5c65159SKalle Valo 	param->desc_id = ev->desc_id;
5309d5c65159SKalle Valo 	param->status = ev->status;
531001c6c9fcSAbinaya Kalaiselvan 	param->ack_rssi = ev->ack_rssi;
5311d5c65159SKalle Valo 
5312d5c65159SKalle Valo 	kfree(tb);
5313d5c65159SKalle Valo 	return 0;
5314d5c65159SKalle Valo }
5315d5c65159SKalle Valo 
5316d5c65159SKalle Valo static void ath11k_wmi_event_scan_started(struct ath11k *ar)
5317d5c65159SKalle Valo {
5318d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5319d5c65159SKalle Valo 
5320d5c65159SKalle Valo 	switch (ar->scan.state) {
5321d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5322d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5323d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5324d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
5325d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5326d5c65159SKalle Valo 			    ar->scan.state);
5327d5c65159SKalle Valo 		break;
5328d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5329d5c65159SKalle Valo 		ar->scan.state = ATH11K_SCAN_RUNNING;
53303a5627b9SBaochen Qiang 		if (ar->scan.is_roc)
53313a5627b9SBaochen Qiang 			ieee80211_ready_on_channel(ar->hw);
5332d5c65159SKalle Valo 		complete(&ar->scan.started);
5333d5c65159SKalle Valo 		break;
5334d5c65159SKalle Valo 	}
5335d5c65159SKalle Valo }
5336d5c65159SKalle Valo 
5337d5c65159SKalle Valo static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
5338d5c65159SKalle Valo {
5339d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5340d5c65159SKalle Valo 
5341d5c65159SKalle Valo 	switch (ar->scan.state) {
5342d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5343d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5344d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5345d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
5346d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5347d5c65159SKalle Valo 			    ar->scan.state);
5348d5c65159SKalle Valo 		break;
5349d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5350d5c65159SKalle Valo 		complete(&ar->scan.started);
5351d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
5352d5c65159SKalle Valo 		break;
5353d5c65159SKalle Valo 	}
5354d5c65159SKalle Valo }
5355d5c65159SKalle Valo 
5356d5c65159SKalle Valo static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
5357d5c65159SKalle Valo {
5358d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5359d5c65159SKalle Valo 
5360d5c65159SKalle Valo 	switch (ar->scan.state) {
5361d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5362d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5363d5c65159SKalle Valo 		/* One suspected reason scan can be completed while starting is
5364d5c65159SKalle Valo 		 * if firmware fails to deliver all scan events to the host,
5365d5c65159SKalle Valo 		 * e.g. when transport pipe is full. This has been observed
5366d5c65159SKalle Valo 		 * with spectral scan phyerr events starving wmi transport
5367d5c65159SKalle Valo 		 * pipe. In such case the "scan completed" event should be (and
5368d5c65159SKalle Valo 		 * is) ignored by the host as it may be just firmware's scan
5369d5c65159SKalle Valo 		 * state machine recovering.
5370d5c65159SKalle Valo 		 */
5371d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
5372d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5373d5c65159SKalle Valo 			    ar->scan.state);
5374d5c65159SKalle Valo 		break;
5375d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5376d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5377d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
5378d5c65159SKalle Valo 		break;
5379d5c65159SKalle Valo 	}
5380d5c65159SKalle Valo }
5381d5c65159SKalle Valo 
5382d5c65159SKalle Valo static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
5383d5c65159SKalle Valo {
5384d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5385d5c65159SKalle Valo 
5386d5c65159SKalle Valo 	switch (ar->scan.state) {
5387d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5388d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5389d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
5390d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5391d5c65159SKalle Valo 			    ar->scan.state);
5392d5c65159SKalle Valo 		break;
5393d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5394d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5395d5c65159SKalle Valo 		ar->scan_channel = NULL;
5396d5c65159SKalle Valo 		break;
5397d5c65159SKalle Valo 	}
5398d5c65159SKalle Valo }
5399d5c65159SKalle Valo 
5400d5c65159SKalle Valo static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
5401d5c65159SKalle Valo {
5402d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
5403d5c65159SKalle Valo 
5404d5c65159SKalle Valo 	switch (ar->scan.state) {
5405d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5406d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5407d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
5408d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
5409d5c65159SKalle Valo 			    ar->scan.state);
5410d5c65159SKalle Valo 		break;
5411d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5412d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5413d5c65159SKalle Valo 		ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
54143a5627b9SBaochen Qiang 		if (ar->scan.is_roc && ar->scan.roc_freq == freq)
54153a5627b9SBaochen Qiang 			complete(&ar->scan.on_channel);
5416d5c65159SKalle Valo 		break;
5417d5c65159SKalle Valo 	}
5418d5c65159SKalle Valo }
5419d5c65159SKalle Valo 
5420d5c65159SKalle Valo static const char *
5421d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
5422d5c65159SKalle Valo 			       enum wmi_scan_completion_reason reason)
5423d5c65159SKalle Valo {
5424d5c65159SKalle Valo 	switch (type) {
5425d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
5426d5c65159SKalle Valo 		return "started";
5427d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
5428d5c65159SKalle Valo 		switch (reason) {
5429d5c65159SKalle Valo 		case WMI_SCAN_REASON_COMPLETED:
5430d5c65159SKalle Valo 			return "completed";
5431d5c65159SKalle Valo 		case WMI_SCAN_REASON_CANCELLED:
5432d5c65159SKalle Valo 			return "completed [cancelled]";
5433d5c65159SKalle Valo 		case WMI_SCAN_REASON_PREEMPTED:
5434d5c65159SKalle Valo 			return "completed [preempted]";
5435d5c65159SKalle Valo 		case WMI_SCAN_REASON_TIMEDOUT:
5436d5c65159SKalle Valo 			return "completed [timedout]";
5437d5c65159SKalle Valo 		case WMI_SCAN_REASON_INTERNAL_FAILURE:
5438d5c65159SKalle Valo 			return "completed [internal err]";
5439d5c65159SKalle Valo 		case WMI_SCAN_REASON_MAX:
5440d5c65159SKalle Valo 			break;
5441d5c65159SKalle Valo 		}
5442d5c65159SKalle Valo 		return "completed [unknown]";
5443d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
5444d5c65159SKalle Valo 		return "bss channel";
5445d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
5446d5c65159SKalle Valo 		return "foreign channel";
5447d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
5448d5c65159SKalle Valo 		return "dequeued";
5449d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
5450d5c65159SKalle Valo 		return "preempted";
5451d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
5452d5c65159SKalle Valo 		return "start failed";
5453d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
5454d5c65159SKalle Valo 		return "restarted";
5455d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
5456d5c65159SKalle Valo 		return "foreign channel exit";
5457d5c65159SKalle Valo 	default:
5458d5c65159SKalle Valo 		return "unknown";
5459d5c65159SKalle Valo 	}
5460d5c65159SKalle Valo }
5461d5c65159SKalle Valo 
5462d5c65159SKalle Valo static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
5463d5c65159SKalle Valo 			       struct wmi_scan_event *scan_evt_param)
5464d5c65159SKalle Valo {
5465d5c65159SKalle Valo 	const void **tb;
5466d5c65159SKalle Valo 	const struct wmi_scan_event *ev;
5467d5c65159SKalle Valo 	int ret;
5468d5c65159SKalle Valo 
5469d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5470d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5471d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5472d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5473d5c65159SKalle Valo 		return ret;
5474d5c65159SKalle Valo 	}
5475d5c65159SKalle Valo 
5476d5c65159SKalle Valo 	ev = tb[WMI_TAG_SCAN_EVENT];
5477d5c65159SKalle Valo 	if (!ev) {
5478d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch scan ev");
5479d5c65159SKalle Valo 		kfree(tb);
5480d5c65159SKalle Valo 		return -EPROTO;
5481d5c65159SKalle Valo 	}
5482d5c65159SKalle Valo 
5483d5c65159SKalle Valo 	scan_evt_param->event_type = ev->event_type;
5484d5c65159SKalle Valo 	scan_evt_param->reason = ev->reason;
5485d5c65159SKalle Valo 	scan_evt_param->channel_freq = ev->channel_freq;
5486d5c65159SKalle Valo 	scan_evt_param->scan_req_id = ev->scan_req_id;
5487d5c65159SKalle Valo 	scan_evt_param->scan_id = ev->scan_id;
5488d5c65159SKalle Valo 	scan_evt_param->vdev_id = ev->vdev_id;
5489d5c65159SKalle Valo 	scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
5490d5c65159SKalle Valo 
5491d5c65159SKalle Valo 	kfree(tb);
5492d5c65159SKalle Valo 	return 0;
5493d5c65159SKalle Valo }
5494d5c65159SKalle Valo 
5495d5c65159SKalle Valo static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
5496d5c65159SKalle Valo 					   struct wmi_peer_sta_kickout_arg *arg)
5497d5c65159SKalle Valo {
5498d5c65159SKalle Valo 	const void **tb;
5499d5c65159SKalle Valo 	const struct wmi_peer_sta_kickout_event *ev;
5500d5c65159SKalle Valo 	int ret;
5501d5c65159SKalle Valo 
5502d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5503d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5504d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5505d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5506d5c65159SKalle Valo 		return ret;
5507d5c65159SKalle Valo 	}
5508d5c65159SKalle Valo 
5509d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
5510d5c65159SKalle Valo 	if (!ev) {
5511d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer sta kickout ev");
5512d5c65159SKalle Valo 		kfree(tb);
5513d5c65159SKalle Valo 		return -EPROTO;
5514d5c65159SKalle Valo 	}
5515d5c65159SKalle Valo 
5516d5c65159SKalle Valo 	arg->mac_addr = ev->peer_macaddr.addr;
5517d5c65159SKalle Valo 
5518d5c65159SKalle Valo 	kfree(tb);
5519d5c65159SKalle Valo 	return 0;
5520d5c65159SKalle Valo }
5521d5c65159SKalle Valo 
5522d5c65159SKalle Valo static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
5523d5c65159SKalle Valo 			       struct wmi_roam_event *roam_ev)
5524d5c65159SKalle Valo {
5525d5c65159SKalle Valo 	const void **tb;
5526d5c65159SKalle Valo 	const struct wmi_roam_event *ev;
5527d5c65159SKalle Valo 	int ret;
5528d5c65159SKalle Valo 
5529d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5530d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5531d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5532d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5533d5c65159SKalle Valo 		return ret;
5534d5c65159SKalle Valo 	}
5535d5c65159SKalle Valo 
5536d5c65159SKalle Valo 	ev = tb[WMI_TAG_ROAM_EVENT];
5537d5c65159SKalle Valo 	if (!ev) {
5538d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch roam ev");
5539d5c65159SKalle Valo 		kfree(tb);
5540d5c65159SKalle Valo 		return -EPROTO;
5541d5c65159SKalle Valo 	}
5542d5c65159SKalle Valo 
5543d5c65159SKalle Valo 	roam_ev->vdev_id = ev->vdev_id;
5544d5c65159SKalle Valo 	roam_ev->reason = ev->reason;
5545d5c65159SKalle Valo 	roam_ev->rssi = ev->rssi;
5546d5c65159SKalle Valo 
5547d5c65159SKalle Valo 	kfree(tb);
5548d5c65159SKalle Valo 	return 0;
5549d5c65159SKalle Valo }
5550d5c65159SKalle Valo 
5551d5c65159SKalle Valo static int freq_to_idx(struct ath11k *ar, int freq)
5552d5c65159SKalle Valo {
5553d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
5554d5c65159SKalle Valo 	int band, ch, idx = 0;
5555d5c65159SKalle Valo 
5556d5c65159SKalle Valo 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
5557d5c65159SKalle Valo 		sband = ar->hw->wiphy->bands[band];
5558d5c65159SKalle Valo 		if (!sband)
5559d5c65159SKalle Valo 			continue;
5560d5c65159SKalle Valo 
5561d5c65159SKalle Valo 		for (ch = 0; ch < sband->n_channels; ch++, idx++)
5562d5c65159SKalle Valo 			if (sband->channels[ch].center_freq == freq)
5563d5c65159SKalle Valo 				goto exit;
5564d5c65159SKalle Valo 	}
5565d5c65159SKalle Valo 
5566d5c65159SKalle Valo exit:
5567d5c65159SKalle Valo 	return idx;
5568d5c65159SKalle Valo }
5569d5c65159SKalle Valo 
5570d5c65159SKalle Valo static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
5571d5c65159SKalle Valo 				    u32 len, struct wmi_chan_info_event *ch_info_ev)
5572d5c65159SKalle Valo {
5573d5c65159SKalle Valo 	const void **tb;
5574d5c65159SKalle Valo 	const struct wmi_chan_info_event *ev;
5575d5c65159SKalle Valo 	int ret;
5576d5c65159SKalle Valo 
5577d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5578d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5579d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5580d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5581d5c65159SKalle Valo 		return ret;
5582d5c65159SKalle Valo 	}
5583d5c65159SKalle Valo 
5584d5c65159SKalle Valo 	ev = tb[WMI_TAG_CHAN_INFO_EVENT];
5585d5c65159SKalle Valo 	if (!ev) {
5586d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch chan info ev");
5587d5c65159SKalle Valo 		kfree(tb);
5588d5c65159SKalle Valo 		return -EPROTO;
5589d5c65159SKalle Valo 	}
5590d5c65159SKalle Valo 
5591d5c65159SKalle Valo 	ch_info_ev->err_code = ev->err_code;
5592d5c65159SKalle Valo 	ch_info_ev->freq = ev->freq;
5593d5c65159SKalle Valo 	ch_info_ev->cmd_flags = ev->cmd_flags;
5594d5c65159SKalle Valo 	ch_info_ev->noise_floor = ev->noise_floor;
5595d5c65159SKalle Valo 	ch_info_ev->rx_clear_count = ev->rx_clear_count;
5596d5c65159SKalle Valo 	ch_info_ev->cycle_count = ev->cycle_count;
5597d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
5598d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
5599d5c65159SKalle Valo 	ch_info_ev->rx_frame_count = ev->rx_frame_count;
5600d5c65159SKalle Valo 	ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
5601d5c65159SKalle Valo 	ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
5602d5c65159SKalle Valo 	ch_info_ev->vdev_id = ev->vdev_id;
5603d5c65159SKalle Valo 
5604d5c65159SKalle Valo 	kfree(tb);
5605d5c65159SKalle Valo 	return 0;
5606d5c65159SKalle Valo }
5607d5c65159SKalle Valo 
5608d5c65159SKalle Valo static int
5609d5c65159SKalle Valo ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
5610d5c65159SKalle Valo 				  struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
5611d5c65159SKalle Valo {
5612d5c65159SKalle Valo 	const void **tb;
5613d5c65159SKalle Valo 	const struct wmi_pdev_bss_chan_info_event *ev;
5614d5c65159SKalle Valo 	int ret;
5615d5c65159SKalle Valo 
5616d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5617d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5618d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5619d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5620d5c65159SKalle Valo 		return ret;
5621d5c65159SKalle Valo 	}
5622d5c65159SKalle Valo 
5623d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
5624d5c65159SKalle Valo 	if (!ev) {
5625d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
5626d5c65159SKalle Valo 		kfree(tb);
5627d5c65159SKalle Valo 		return -EPROTO;
5628d5c65159SKalle Valo 	}
5629d5c65159SKalle Valo 
5630d5c65159SKalle Valo 	bss_ch_info_ev->pdev_id = ev->pdev_id;
5631d5c65159SKalle Valo 	bss_ch_info_ev->freq = ev->freq;
5632d5c65159SKalle Valo 	bss_ch_info_ev->noise_floor = ev->noise_floor;
5633d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
5634d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
5635d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
5636d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
5637d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
5638d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
5639d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
5640d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
5641d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
5642d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
5643d5c65159SKalle Valo 
5644d5c65159SKalle Valo 	kfree(tb);
5645d5c65159SKalle Valo 	return 0;
5646d5c65159SKalle Valo }
5647d5c65159SKalle Valo 
5648d5c65159SKalle Valo static int
5649d5c65159SKalle Valo ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
5650d5c65159SKalle Valo 				      struct wmi_vdev_install_key_complete_arg *arg)
5651d5c65159SKalle Valo {
5652d5c65159SKalle Valo 	const void **tb;
5653d5c65159SKalle Valo 	const struct wmi_vdev_install_key_compl_event *ev;
5654d5c65159SKalle Valo 	int ret;
5655d5c65159SKalle Valo 
5656d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5657d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5658d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5659d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5660d5c65159SKalle Valo 		return ret;
5661d5c65159SKalle Valo 	}
5662d5c65159SKalle Valo 
5663d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
5664d5c65159SKalle Valo 	if (!ev) {
5665d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev install key compl ev");
5666d5c65159SKalle Valo 		kfree(tb);
5667d5c65159SKalle Valo 		return -EPROTO;
5668d5c65159SKalle Valo 	}
5669d5c65159SKalle Valo 
5670d5c65159SKalle Valo 	arg->vdev_id = ev->vdev_id;
5671d5c65159SKalle Valo 	arg->macaddr = ev->peer_macaddr.addr;
5672d5c65159SKalle Valo 	arg->key_idx = ev->key_idx;
5673d5c65159SKalle Valo 	arg->key_flags = ev->key_flags;
5674d5c65159SKalle Valo 	arg->status = ev->status;
5675d5c65159SKalle Valo 
5676d5c65159SKalle Valo 	kfree(tb);
5677d5c65159SKalle Valo 	return 0;
5678d5c65159SKalle Valo }
5679d5c65159SKalle Valo 
5680d5c65159SKalle Valo static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
5681d5c65159SKalle Valo 					  struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
5682d5c65159SKalle Valo {
5683d5c65159SKalle Valo 	const void **tb;
5684d5c65159SKalle Valo 	const struct wmi_peer_assoc_conf_event *ev;
5685d5c65159SKalle Valo 	int ret;
5686d5c65159SKalle Valo 
5687d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5688d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5689d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5690d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5691d5c65159SKalle Valo 		return ret;
5692d5c65159SKalle Valo 	}
5693d5c65159SKalle Valo 
5694d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
5695d5c65159SKalle Valo 	if (!ev) {
5696d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer assoc conf ev");
5697d5c65159SKalle Valo 		kfree(tb);
5698d5c65159SKalle Valo 		return -EPROTO;
5699d5c65159SKalle Valo 	}
5700d5c65159SKalle Valo 
5701d5c65159SKalle Valo 	peer_assoc_conf->vdev_id = ev->vdev_id;
5702d5c65159SKalle Valo 	peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
5703d5c65159SKalle Valo 
5704d5c65159SKalle Valo 	kfree(tb);
5705d5c65159SKalle Valo 	return 0;
5706d5c65159SKalle Valo }
5707d5c65159SKalle Valo 
5708d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
5709d5c65159SKalle Valo 					    struct ath11k_fw_stats_pdev *dst)
5710d5c65159SKalle Valo {
5711d5c65159SKalle Valo 	dst->ch_noise_floor = src->chan_nf;
5712d5c65159SKalle Valo 	dst->tx_frame_count = src->tx_frame_count;
5713d5c65159SKalle Valo 	dst->rx_frame_count = src->rx_frame_count;
5714d5c65159SKalle Valo 	dst->rx_clear_count = src->rx_clear_count;
5715d5c65159SKalle Valo 	dst->cycle_count = src->cycle_count;
5716d5c65159SKalle Valo 	dst->phy_err_count = src->phy_err_count;
5717d5c65159SKalle Valo 	dst->chan_tx_power = src->chan_tx_pwr;
5718d5c65159SKalle Valo }
5719d5c65159SKalle Valo 
5720d5c65159SKalle Valo static void
5721d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
5722d5c65159SKalle Valo 			      struct ath11k_fw_stats_pdev *dst)
5723d5c65159SKalle Valo {
5724d5c65159SKalle Valo 	dst->comp_queued = src->comp_queued;
5725d5c65159SKalle Valo 	dst->comp_delivered = src->comp_delivered;
5726d5c65159SKalle Valo 	dst->msdu_enqued = src->msdu_enqued;
5727d5c65159SKalle Valo 	dst->mpdu_enqued = src->mpdu_enqued;
5728d5c65159SKalle Valo 	dst->wmm_drop = src->wmm_drop;
5729d5c65159SKalle Valo 	dst->local_enqued = src->local_enqued;
5730d5c65159SKalle Valo 	dst->local_freed = src->local_freed;
5731d5c65159SKalle Valo 	dst->hw_queued = src->hw_queued;
5732d5c65159SKalle Valo 	dst->hw_reaped = src->hw_reaped;
5733d5c65159SKalle Valo 	dst->underrun = src->underrun;
5734f394e4eaSSriram R 	dst->hw_paused = src->hw_paused;
5735d5c65159SKalle Valo 	dst->tx_abort = src->tx_abort;
573617818dfaSColin Ian King 	dst->mpdus_requeued = src->mpdus_requeued;
5737d5c65159SKalle Valo 	dst->tx_ko = src->tx_ko;
5738f394e4eaSSriram R 	dst->tx_xretry = src->tx_xretry;
5739d5c65159SKalle Valo 	dst->data_rc = src->data_rc;
5740d5c65159SKalle Valo 	dst->self_triggers = src->self_triggers;
5741d5c65159SKalle Valo 	dst->sw_retry_failure = src->sw_retry_failure;
5742d5c65159SKalle Valo 	dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
5743d5c65159SKalle Valo 	dst->pdev_cont_xretry = src->pdev_cont_xretry;
5744d5c65159SKalle Valo 	dst->pdev_tx_timeout = src->pdev_tx_timeout;
5745d5c65159SKalle Valo 	dst->pdev_resets = src->pdev_resets;
5746d5c65159SKalle Valo 	dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
5747d5c65159SKalle Valo 	dst->phy_underrun = src->phy_underrun;
5748d5c65159SKalle Valo 	dst->txop_ovf = src->txop_ovf;
5749f394e4eaSSriram R 	dst->seq_posted = src->seq_posted;
5750f394e4eaSSriram R 	dst->seq_failed_queueing = src->seq_failed_queueing;
5751f394e4eaSSriram R 	dst->seq_completed = src->seq_completed;
5752f394e4eaSSriram R 	dst->seq_restarted = src->seq_restarted;
5753f394e4eaSSriram R 	dst->mu_seq_posted = src->mu_seq_posted;
5754f394e4eaSSriram R 	dst->mpdus_sw_flush = src->mpdus_sw_flush;
5755f394e4eaSSriram R 	dst->mpdus_hw_filter = src->mpdus_hw_filter;
5756f394e4eaSSriram R 	dst->mpdus_truncated = src->mpdus_truncated;
5757f394e4eaSSriram R 	dst->mpdus_ack_failed = src->mpdus_ack_failed;
5758f394e4eaSSriram R 	dst->mpdus_expired = src->mpdus_expired;
5759d5c65159SKalle Valo }
5760d5c65159SKalle Valo 
5761d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
5762d5c65159SKalle Valo 					  struct ath11k_fw_stats_pdev *dst)
5763d5c65159SKalle Valo {
5764d5c65159SKalle Valo 	dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
5765d5c65159SKalle Valo 	dst->status_rcvd = src->status_rcvd;
5766d5c65159SKalle Valo 	dst->r0_frags = src->r0_frags;
5767d5c65159SKalle Valo 	dst->r1_frags = src->r1_frags;
5768d5c65159SKalle Valo 	dst->r2_frags = src->r2_frags;
5769d5c65159SKalle Valo 	dst->r3_frags = src->r3_frags;
5770d5c65159SKalle Valo 	dst->htt_msdus = src->htt_msdus;
5771d5c65159SKalle Valo 	dst->htt_mpdus = src->htt_mpdus;
5772d5c65159SKalle Valo 	dst->loc_msdus = src->loc_msdus;
5773d5c65159SKalle Valo 	dst->loc_mpdus = src->loc_mpdus;
5774d5c65159SKalle Valo 	dst->oversize_amsdu = src->oversize_amsdu;
5775d5c65159SKalle Valo 	dst->phy_errs = src->phy_errs;
5776d5c65159SKalle Valo 	dst->phy_err_drop = src->phy_err_drop;
5777d5c65159SKalle Valo 	dst->mpdu_errs = src->mpdu_errs;
5778f394e4eaSSriram R 	dst->rx_ovfl_errs = src->rx_ovfl_errs;
5779d5c65159SKalle Valo }
5780d5c65159SKalle Valo 
5781d5c65159SKalle Valo static void
5782d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
5783d5c65159SKalle Valo 			   struct ath11k_fw_stats_vdev *dst)
5784d5c65159SKalle Valo {
5785d5c65159SKalle Valo 	int i;
5786d5c65159SKalle Valo 
5787d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
5788d5c65159SKalle Valo 	dst->beacon_snr = src->beacon_snr;
5789d5c65159SKalle Valo 	dst->data_snr = src->data_snr;
5790d5c65159SKalle Valo 	dst->num_rx_frames = src->num_rx_frames;
5791d5c65159SKalle Valo 	dst->num_rts_fail = src->num_rts_fail;
5792d5c65159SKalle Valo 	dst->num_rts_success = src->num_rts_success;
5793d5c65159SKalle Valo 	dst->num_rx_err = src->num_rx_err;
5794d5c65159SKalle Valo 	dst->num_rx_discard = src->num_rx_discard;
5795d5c65159SKalle Valo 	dst->num_tx_not_acked = src->num_tx_not_acked;
5796d5c65159SKalle Valo 
5797d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
5798d5c65159SKalle Valo 		dst->num_tx_frames[i] = src->num_tx_frames[i];
5799d5c65159SKalle Valo 
5800d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
5801d5c65159SKalle Valo 		dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
5802d5c65159SKalle Valo 
5803d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
5804d5c65159SKalle Valo 		dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
5805d5c65159SKalle Valo 
5806d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
5807d5c65159SKalle Valo 		dst->tx_rate_history[i] = src->tx_rate_history[i];
5808d5c65159SKalle Valo 
5809d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
5810d5c65159SKalle Valo 		dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
5811d5c65159SKalle Valo }
5812d5c65159SKalle Valo 
5813d5c65159SKalle Valo static void
5814d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
5815d5c65159SKalle Valo 			  struct ath11k_fw_stats_bcn *dst)
5816d5c65159SKalle Valo {
5817d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
5818d5c65159SKalle Valo 	dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
5819d5c65159SKalle Valo 	dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
5820d5c65159SKalle Valo }
5821d5c65159SKalle Valo 
5822b488c766SWen Gong static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
5823b488c766SWen Gong 					   u16 tag, u16 len,
5824b488c766SWen Gong 					   const void *ptr, void *data)
5825d5c65159SKalle Valo {
5826b488c766SWen Gong 	struct wmi_tlv_fw_stats_parse *parse = data;
5827b488c766SWen Gong 	const struct wmi_stats_event *ev = parse->ev;
5828b488c766SWen Gong 	struct ath11k_fw_stats *stats = parse->stats;
5829b488c766SWen Gong 	struct ath11k *ar;
5830b488c766SWen Gong 	struct ath11k_vif *arvif;
5831b488c766SWen Gong 	struct ieee80211_sta *sta;
5832b488c766SWen Gong 	struct ath11k_sta *arsta;
5833b488c766SWen Gong 	const struct wmi_rssi_stats *stats_rssi = (const struct wmi_rssi_stats *)ptr;
5834b488c766SWen Gong 	int j, ret = 0;
5835d5c65159SKalle Valo 
5836b488c766SWen Gong 	if (tag != WMI_TAG_RSSI_STATS)
5837d5c65159SKalle Valo 		return -EPROTO;
5838b488c766SWen Gong 
5839b488c766SWen Gong 	rcu_read_lock();
5840b488c766SWen Gong 
5841b488c766SWen Gong 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5842b488c766SWen Gong 	stats->stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
5843b488c766SWen Gong 
5844b488c766SWen Gong 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5845b488c766SWen Gong 		   "wmi stats vdev id %d mac %pM\n",
5846b488c766SWen Gong 		   stats_rssi->vdev_id, stats_rssi->peer_macaddr.addr);
5847b488c766SWen Gong 
5848b488c766SWen Gong 	arvif = ath11k_mac_get_arvif(ar, stats_rssi->vdev_id);
5849b488c766SWen Gong 	if (!arvif) {
5850b488c766SWen Gong 		ath11k_warn(ab, "not found vif for vdev id %d\n",
5851b488c766SWen Gong 			    stats_rssi->vdev_id);
5852b488c766SWen Gong 		ret = -EPROTO;
5853b488c766SWen Gong 		goto exit;
5854d5c65159SKalle Valo 	}
5855d5c65159SKalle Valo 
5856d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5857b488c766SWen Gong 		   "wmi stats bssid %pM vif %pK\n",
5858b488c766SWen Gong 		   arvif->bssid, arvif->vif);
5859d5c65159SKalle Valo 
5860b488c766SWen Gong 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5861b488c766SWen Gong 					   arvif->bssid,
5862b488c766SWen Gong 					   NULL);
5863b488c766SWen Gong 	if (!sta) {
58647330e1ecSWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
58657330e1ecSWen Gong 			   "not found station of bssid %pM for rssi chain\n",
5866b488c766SWen Gong 			   arvif->bssid);
5867b488c766SWen Gong 		goto exit;
5868b488c766SWen Gong 	}
5869b488c766SWen Gong 
5870b488c766SWen Gong 	arsta = (struct ath11k_sta *)sta->drv_priv;
5871b488c766SWen Gong 
5872b488c766SWen Gong 	BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
5873b488c766SWen Gong 		     ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
5874b488c766SWen Gong 
5875b488c766SWen Gong 	for (j = 0; j < ARRAY_SIZE(arsta->chain_signal); j++) {
5876b488c766SWen Gong 		arsta->chain_signal[j] = stats_rssi->rssi_avg_beacon[j];
5877b488c766SWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
5878b488c766SWen Gong 			   "wmi stats beacon rssi[%d] %d data rssi[%d] %d\n",
5879b488c766SWen Gong 			   j,
5880b488c766SWen Gong 			   stats_rssi->rssi_avg_beacon[j],
5881b488c766SWen Gong 			   j,
5882b488c766SWen Gong 			   stats_rssi->rssi_avg_data[j]);
5883b488c766SWen Gong 	}
5884b488c766SWen Gong 
5885b488c766SWen Gong exit:
5886b488c766SWen Gong 	rcu_read_unlock();
5887b488c766SWen Gong 	return ret;
5888b488c766SWen Gong }
5889b488c766SWen Gong 
5890b488c766SWen Gong static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
5891b488c766SWen Gong 					      struct wmi_tlv_fw_stats_parse *parse,
5892b488c766SWen Gong 					      const void *ptr,
5893b488c766SWen Gong 					      u16 len)
5894b488c766SWen Gong {
5895b488c766SWen Gong 	struct ath11k_fw_stats *stats = parse->stats;
5896b488c766SWen Gong 	const struct wmi_stats_event *ev = parse->ev;
5897c3b39553SWen Gong 	struct ath11k *ar;
5898c3b39553SWen Gong 	struct ath11k_vif *arvif;
5899c3b39553SWen Gong 	struct ieee80211_sta *sta;
5900c3b39553SWen Gong 	struct ath11k_sta *arsta;
5901c3b39553SWen Gong 	int i, ret = 0;
5902b488c766SWen Gong 	const void *data = ptr;
5903b488c766SWen Gong 
5904b488c766SWen Gong 	if (!ev) {
5905b488c766SWen Gong 		ath11k_warn(ab, "failed to fetch update stats ev");
5906b488c766SWen Gong 		return -EPROTO;
5907b488c766SWen Gong 	}
5908b488c766SWen Gong 
5909d5c65159SKalle Valo 	stats->stats_id = 0;
5910d5c65159SKalle Valo 
5911c3b39553SWen Gong 	rcu_read_lock();
5912c3b39553SWen Gong 
5913c3b39553SWen Gong 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5914c3b39553SWen Gong 
5915d5c65159SKalle Valo 	for (i = 0; i < ev->num_pdev_stats; i++) {
5916d5c65159SKalle Valo 		const struct wmi_pdev_stats *src;
5917d5c65159SKalle Valo 		struct ath11k_fw_stats_pdev *dst;
5918d5c65159SKalle Valo 
5919d5c65159SKalle Valo 		src = data;
5920c3b39553SWen Gong 		if (len < sizeof(*src)) {
5921c3b39553SWen Gong 			ret = -EPROTO;
5922c3b39553SWen Gong 			goto exit;
5923c3b39553SWen Gong 		}
5924d5c65159SKalle Valo 
5925d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_PDEV_STAT;
5926d5c65159SKalle Valo 
5927d5c65159SKalle Valo 		data += sizeof(*src);
5928d5c65159SKalle Valo 		len -= sizeof(*src);
5929d5c65159SKalle Valo 
5930d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5931d5c65159SKalle Valo 		if (!dst)
5932d5c65159SKalle Valo 			continue;
5933d5c65159SKalle Valo 
5934d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
5935d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
5936d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
5937d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->pdevs);
5938d5c65159SKalle Valo 	}
5939d5c65159SKalle Valo 
5940d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdev_stats; i++) {
5941d5c65159SKalle Valo 		const struct wmi_vdev_stats *src;
5942d5c65159SKalle Valo 		struct ath11k_fw_stats_vdev *dst;
5943d5c65159SKalle Valo 
5944d5c65159SKalle Valo 		src = data;
5945c3b39553SWen Gong 		if (len < sizeof(*src)) {
5946c3b39553SWen Gong 			ret = -EPROTO;
5947c3b39553SWen Gong 			goto exit;
5948c3b39553SWen Gong 		}
5949d5c65159SKalle Valo 
5950d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_VDEV_STAT;
5951d5c65159SKalle Valo 
5952c3b39553SWen Gong 		arvif = ath11k_mac_get_arvif(ar, src->vdev_id);
5953c3b39553SWen Gong 		if (arvif) {
5954c3b39553SWen Gong 			sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5955c3b39553SWen Gong 							   arvif->bssid,
5956c3b39553SWen Gong 							   NULL);
5957c3b39553SWen Gong 			if (sta) {
5958c3b39553SWen Gong 				arsta = (struct ath11k_sta *)sta->drv_priv;
5959c3b39553SWen Gong 				arsta->rssi_beacon = src->beacon_snr;
5960c3b39553SWen Gong 				ath11k_dbg(ab, ATH11K_DBG_WMI,
5961c3b39553SWen Gong 					   "wmi stats vdev id %d snr %d\n",
5962c3b39553SWen Gong 					   src->vdev_id, src->beacon_snr);
5963c3b39553SWen Gong 			} else {
59647330e1ecSWen Gong 				ath11k_dbg(ab, ATH11K_DBG_WMI,
59657330e1ecSWen Gong 					   "not found station of bssid %pM for vdev stat\n",
5966c3b39553SWen Gong 					   arvif->bssid);
5967c3b39553SWen Gong 			}
5968c3b39553SWen Gong 		}
5969c3b39553SWen Gong 
5970d5c65159SKalle Valo 		data += sizeof(*src);
5971d5c65159SKalle Valo 		len -= sizeof(*src);
5972d5c65159SKalle Valo 
5973d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5974d5c65159SKalle Valo 		if (!dst)
5975d5c65159SKalle Valo 			continue;
5976d5c65159SKalle Valo 
5977d5c65159SKalle Valo 		ath11k_wmi_pull_vdev_stats(src, dst);
5978d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->vdevs);
5979d5c65159SKalle Valo 	}
5980d5c65159SKalle Valo 
5981d5c65159SKalle Valo 	for (i = 0; i < ev->num_bcn_stats; i++) {
5982d5c65159SKalle Valo 		const struct wmi_bcn_stats *src;
5983d5c65159SKalle Valo 		struct ath11k_fw_stats_bcn *dst;
5984d5c65159SKalle Valo 
5985d5c65159SKalle Valo 		src = data;
5986c3b39553SWen Gong 		if (len < sizeof(*src)) {
5987c3b39553SWen Gong 			ret = -EPROTO;
5988c3b39553SWen Gong 			goto exit;
5989c3b39553SWen Gong 		}
5990d5c65159SKalle Valo 
5991d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_BCN_STAT;
5992d5c65159SKalle Valo 
5993d5c65159SKalle Valo 		data += sizeof(*src);
5994d5c65159SKalle Valo 		len -= sizeof(*src);
5995d5c65159SKalle Valo 
5996d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5997d5c65159SKalle Valo 		if (!dst)
5998d5c65159SKalle Valo 			continue;
5999d5c65159SKalle Valo 
6000d5c65159SKalle Valo 		ath11k_wmi_pull_bcn_stats(src, dst);
6001d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->bcn);
6002d5c65159SKalle Valo 	}
6003d5c65159SKalle Valo 
6004c3b39553SWen Gong exit:
6005c3b39553SWen Gong 	rcu_read_unlock();
6006c3b39553SWen Gong 	return ret;
6007d5c65159SKalle Valo }
6008d5c65159SKalle Valo 
6009b488c766SWen Gong static int ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base *ab,
6010b488c766SWen Gong 					 u16 tag, u16 len,
6011b488c766SWen Gong 					 const void *ptr, void *data)
6012b488c766SWen Gong {
6013b488c766SWen Gong 	struct wmi_tlv_fw_stats_parse *parse = data;
6014b488c766SWen Gong 	int ret = 0;
6015b488c766SWen Gong 
6016b488c766SWen Gong 	switch (tag) {
6017b488c766SWen Gong 	case WMI_TAG_STATS_EVENT:
6018b488c766SWen Gong 		parse->ev = (struct wmi_stats_event *)ptr;
6019b488c766SWen Gong 		parse->stats->pdev_id = parse->ev->pdev_id;
6020b488c766SWen Gong 		break;
6021b488c766SWen Gong 	case WMI_TAG_ARRAY_BYTE:
6022b488c766SWen Gong 		ret = ath11k_wmi_tlv_fw_stats_data_parse(ab, parse, ptr, len);
6023b488c766SWen Gong 		break;
6024b488c766SWen Gong 	case WMI_TAG_PER_CHAIN_RSSI_STATS:
6025b488c766SWen Gong 		parse->rssi = (struct wmi_per_chain_rssi_stats *)ptr;
6026b488c766SWen Gong 
6027b488c766SWen Gong 		if (parse->ev->stats_id & WMI_REQUEST_RSSI_PER_CHAIN_STAT)
6028b488c766SWen Gong 			parse->rssi_num = parse->rssi->num_per_chain_rssi_stats;
6029b488c766SWen Gong 
6030b488c766SWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
6031b488c766SWen Gong 			   "wmi stats id 0x%x num chain %d\n",
6032b488c766SWen Gong 			   parse->ev->stats_id,
6033b488c766SWen Gong 			   parse->rssi_num);
6034b488c766SWen Gong 		break;
6035b488c766SWen Gong 	case WMI_TAG_ARRAY_STRUCT:
6036b488c766SWen Gong 		if (parse->rssi_num && !parse->chain_rssi_done) {
6037b488c766SWen Gong 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
6038b488c766SWen Gong 						  ath11k_wmi_tlv_rssi_chain_parse,
6039b488c766SWen Gong 						  parse);
6040b488c766SWen Gong 			if (ret) {
6041b488c766SWen Gong 				ath11k_warn(ab, "failed to parse rssi chain %d\n",
6042b488c766SWen Gong 					    ret);
6043b488c766SWen Gong 				return ret;
6044b488c766SWen Gong 			}
6045b488c766SWen Gong 			parse->chain_rssi_done = true;
6046b488c766SWen Gong 		}
6047b488c766SWen Gong 		break;
6048b488c766SWen Gong 	default:
6049b488c766SWen Gong 		break;
6050b488c766SWen Gong 	}
6051b488c766SWen Gong 	return ret;
6052b488c766SWen Gong }
6053b488c766SWen Gong 
6054b488c766SWen Gong int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
6055b488c766SWen Gong 			     struct ath11k_fw_stats *stats)
6056b488c766SWen Gong {
6057b488c766SWen Gong 	struct wmi_tlv_fw_stats_parse parse = { };
6058b488c766SWen Gong 
6059b488c766SWen Gong 	stats->stats_id = 0;
6060b488c766SWen Gong 	parse.stats = stats;
6061b488c766SWen Gong 
6062b488c766SWen Gong 	return ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6063b488c766SWen Gong 				   ath11k_wmi_tlv_fw_stats_parse,
6064b488c766SWen Gong 				   &parse);
6065b488c766SWen Gong }
6066b488c766SWen Gong 
6067d5c65159SKalle Valo size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head)
6068d5c65159SKalle Valo {
6069d5c65159SKalle Valo 	struct ath11k_fw_stats_vdev *i;
6070d5c65159SKalle Valo 	size_t num = 0;
6071d5c65159SKalle Valo 
6072d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
6073d5c65159SKalle Valo 		++num;
6074d5c65159SKalle Valo 
6075d5c65159SKalle Valo 	return num;
6076d5c65159SKalle Valo }
6077d5c65159SKalle Valo 
6078d5c65159SKalle Valo static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head)
6079d5c65159SKalle Valo {
6080d5c65159SKalle Valo 	struct ath11k_fw_stats_bcn *i;
6081d5c65159SKalle Valo 	size_t num = 0;
6082d5c65159SKalle Valo 
6083d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
6084d5c65159SKalle Valo 		++num;
6085d5c65159SKalle Valo 
6086d5c65159SKalle Valo 	return num;
6087d5c65159SKalle Valo }
6088d5c65159SKalle Valo 
6089d5c65159SKalle Valo static void
6090d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6091d5c65159SKalle Valo 				   char *buf, u32 *length)
6092d5c65159SKalle Valo {
6093d5c65159SKalle Valo 	u32 len = *length;
6094d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6095d5c65159SKalle Valo 
6096d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
6097d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
6098d5c65159SKalle Valo 			"ath11k PDEV stats");
6099d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6100d5c65159SKalle Valo 			"=================");
6101d5c65159SKalle Valo 
6102d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6103d5c65159SKalle Valo 			"Channel noise floor", pdev->ch_noise_floor);
6104d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6105d5c65159SKalle Valo 			"Channel TX power", pdev->chan_tx_power);
6106d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6107d5c65159SKalle Valo 			"TX frame count", pdev->tx_frame_count);
6108d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6109d5c65159SKalle Valo 			"RX frame count", pdev->rx_frame_count);
6110d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6111d5c65159SKalle Valo 			"RX clear count", pdev->rx_clear_count);
6112d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6113d5c65159SKalle Valo 			"Cycle count", pdev->cycle_count);
6114d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6115d5c65159SKalle Valo 			"PHY error count", pdev->phy_err_count);
6116d5c65159SKalle Valo 
6117d5c65159SKalle Valo 	*length = len;
6118d5c65159SKalle Valo }
6119d5c65159SKalle Valo 
6120d5c65159SKalle Valo static void
6121d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6122d5c65159SKalle Valo 				 char *buf, u32 *length)
6123d5c65159SKalle Valo {
6124d5c65159SKalle Valo 	u32 len = *length;
6125d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6126d5c65159SKalle Valo 
6127d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6128d5c65159SKalle Valo 			 "ath11k PDEV TX stats");
6129d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6130d5c65159SKalle Valo 			 "====================");
6131d5c65159SKalle Valo 
6132d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6133d5c65159SKalle Valo 			 "HTT cookies queued", pdev->comp_queued);
6134d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6135d5c65159SKalle Valo 			 "HTT cookies disp.", pdev->comp_delivered);
6136d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6137d5c65159SKalle Valo 			 "MSDU queued", pdev->msdu_enqued);
6138d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6139d5c65159SKalle Valo 			 "MPDU queued", pdev->mpdu_enqued);
6140d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6141d5c65159SKalle Valo 			 "MSDUs dropped", pdev->wmm_drop);
6142d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6143d5c65159SKalle Valo 			 "Local enqued", pdev->local_enqued);
6144d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6145d5c65159SKalle Valo 			 "Local freed", pdev->local_freed);
6146d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6147d5c65159SKalle Valo 			 "HW queued", pdev->hw_queued);
6148d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6149d5c65159SKalle Valo 			 "PPDUs reaped", pdev->hw_reaped);
6150d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6151d5c65159SKalle Valo 			 "Num underruns", pdev->underrun);
6152d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6153f394e4eaSSriram R 			 "Num HW Paused", pdev->hw_paused);
6154f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6155d5c65159SKalle Valo 			 "PPDUs cleaned", pdev->tx_abort);
6156d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
615717818dfaSColin Ian King 			 "MPDUs requeued", pdev->mpdus_requeued);
6158d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6159f394e4eaSSriram R 			 "PPDU OK", pdev->tx_ko);
6160f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6161f394e4eaSSriram R 			 "Excessive retries", pdev->tx_xretry);
6162d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6163d5c65159SKalle Valo 			 "HW rate", pdev->data_rc);
6164d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6165d5c65159SKalle Valo 			 "Sched self triggers", pdev->self_triggers);
6166d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6167d5c65159SKalle Valo 			 "Dropped due to SW retries",
6168d5c65159SKalle Valo 			 pdev->sw_retry_failure);
6169d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6170d5c65159SKalle Valo 			 "Illegal rate phy errors",
6171d5c65159SKalle Valo 			 pdev->illgl_rate_phy_err);
6172d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6173d5c65159SKalle Valo 			 "PDEV continuous xretry", pdev->pdev_cont_xretry);
6174d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6175d5c65159SKalle Valo 			 "TX timeout", pdev->pdev_tx_timeout);
6176d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6177d5c65159SKalle Valo 			 "PDEV resets", pdev->pdev_resets);
6178d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6179d5c65159SKalle Valo 			 "Stateless TIDs alloc failures",
6180d5c65159SKalle Valo 			 pdev->stateless_tid_alloc_failure);
6181d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6182d5c65159SKalle Valo 			 "PHY underrun", pdev->phy_underrun);
6183d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6184d5c65159SKalle Valo 			 "MPDU is more than txop limit", pdev->txop_ovf);
6185f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6186f394e4eaSSriram R 			 "Num sequences posted", pdev->seq_posted);
6187f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6188f394e4eaSSriram R 			 "Num seq failed queueing ", pdev->seq_failed_queueing);
6189f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6190f394e4eaSSriram R 			 "Num sequences completed ", pdev->seq_completed);
6191f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6192f394e4eaSSriram R 			 "Num sequences restarted ", pdev->seq_restarted);
6193f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6194f394e4eaSSriram R 			 "Num of MU sequences posted ", pdev->mu_seq_posted);
6195f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6196f394e4eaSSriram R 			 "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush);
6197f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6198f394e4eaSSriram R 			 "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter);
6199f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6200f394e4eaSSriram R 			 "Num of MPDUS truncated ", pdev->mpdus_truncated);
6201f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6202f394e4eaSSriram R 			 "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed);
6203f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6204f394e4eaSSriram R 			 "Num of MPDUS expired ", pdev->mpdus_expired);
6205d5c65159SKalle Valo 	*length = len;
6206d5c65159SKalle Valo }
6207d5c65159SKalle Valo 
6208d5c65159SKalle Valo static void
6209d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6210d5c65159SKalle Valo 				 char *buf, u32 *length)
6211d5c65159SKalle Valo {
6212d5c65159SKalle Valo 	u32 len = *length;
6213d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6214d5c65159SKalle Valo 
6215d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6216d5c65159SKalle Valo 			 "ath11k PDEV RX stats");
6217d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6218d5c65159SKalle Valo 			 "====================");
6219d5c65159SKalle Valo 
6220d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6221d5c65159SKalle Valo 			 "Mid PPDU route change",
6222d5c65159SKalle Valo 			 pdev->mid_ppdu_route_change);
6223d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6224d5c65159SKalle Valo 			 "Tot. number of statuses", pdev->status_rcvd);
6225d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6226d5c65159SKalle Valo 			 "Extra frags on rings 0", pdev->r0_frags);
6227d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6228d5c65159SKalle Valo 			 "Extra frags on rings 1", pdev->r1_frags);
6229d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6230d5c65159SKalle Valo 			 "Extra frags on rings 2", pdev->r2_frags);
6231d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6232d5c65159SKalle Valo 			 "Extra frags on rings 3", pdev->r3_frags);
6233d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6234d5c65159SKalle Valo 			 "MSDUs delivered to HTT", pdev->htt_msdus);
6235d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6236d5c65159SKalle Valo 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
6237d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6238d5c65159SKalle Valo 			 "MSDUs delivered to stack", pdev->loc_msdus);
6239d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6240d5c65159SKalle Valo 			 "MPDUs delivered to stack", pdev->loc_mpdus);
6241d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6242d5c65159SKalle Valo 			 "Oversized AMSUs", pdev->oversize_amsdu);
6243d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6244d5c65159SKalle Valo 			 "PHY errors", pdev->phy_errs);
6245d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6246d5c65159SKalle Valo 			 "PHY errors drops", pdev->phy_err_drop);
6247d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6248d5c65159SKalle Valo 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
6249f394e4eaSSriram R 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6250f394e4eaSSriram R 			 "Overflow errors", pdev->rx_ovfl_errs);
6251d5c65159SKalle Valo 	*length = len;
6252d5c65159SKalle Valo }
6253d5c65159SKalle Valo 
6254d5c65159SKalle Valo static void
6255d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
6256d5c65159SKalle Valo 			      const struct ath11k_fw_stats_vdev *vdev,
6257d5c65159SKalle Valo 			      char *buf, u32 *length)
6258d5c65159SKalle Valo {
6259d5c65159SKalle Valo 	u32 len = *length;
6260d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6261d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
6262d5c65159SKalle Valo 	u8 *vif_macaddr;
6263d5c65159SKalle Valo 	int i;
6264d5c65159SKalle Valo 
6265d5c65159SKalle Valo 	/* VDEV stats has all the active VDEVs of other PDEVs as well,
6266d5c65159SKalle Valo 	 * ignoring those not part of requested PDEV
6267d5c65159SKalle Valo 	 */
6268d5c65159SKalle Valo 	if (!arvif)
6269d5c65159SKalle Valo 		return;
6270d5c65159SKalle Valo 
6271d5c65159SKalle Valo 	vif_macaddr = arvif->vif->addr;
6272d5c65159SKalle Valo 
6273d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6274d5c65159SKalle Valo 			 "VDEV ID", vdev->vdev_id);
6275d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6276d5c65159SKalle Valo 			 "VDEV MAC address", vif_macaddr);
6277d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6278d5c65159SKalle Valo 			 "beacon snr", vdev->beacon_snr);
6279d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6280d5c65159SKalle Valo 			 "data snr", vdev->data_snr);
6281d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6282d5c65159SKalle Valo 			 "num rx frames", vdev->num_rx_frames);
6283d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6284d5c65159SKalle Valo 			 "num rts fail", vdev->num_rts_fail);
6285d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6286d5c65159SKalle Valo 			 "num rts success", vdev->num_rts_success);
6287d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6288d5c65159SKalle Valo 			 "num rx err", vdev->num_rx_err);
6289d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6290d5c65159SKalle Valo 			 "num rx discard", vdev->num_rx_discard);
6291d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6292d5c65159SKalle Valo 			 "num tx not acked", vdev->num_tx_not_acked);
6293d5c65159SKalle Valo 
6294d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
6295d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6296d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6297d5c65159SKalle Valo 				"num tx frames", i,
6298d5c65159SKalle Valo 				vdev->num_tx_frames[i]);
6299d5c65159SKalle Valo 
6300d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
6301d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6302d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6303d5c65159SKalle Valo 				"num tx frames retries", i,
6304d5c65159SKalle Valo 				vdev->num_tx_frames_retries[i]);
6305d5c65159SKalle Valo 
6306d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
6307d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6308d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6309d5c65159SKalle Valo 				"num tx frames failures", i,
6310d5c65159SKalle Valo 				vdev->num_tx_frames_failures[i]);
6311d5c65159SKalle Valo 
6312d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
6313d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6314d5c65159SKalle Valo 				"%25s [%02d] 0x%08x\n",
6315d5c65159SKalle Valo 				"tx rate history", i,
6316d5c65159SKalle Valo 				vdev->tx_rate_history[i]);
6317d5c65159SKalle Valo 
6318d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
6319d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
6320d5c65159SKalle Valo 				"%25s [%02d] %u\n",
6321d5c65159SKalle Valo 				"beacon rssi history", i,
6322d5c65159SKalle Valo 				vdev->beacon_rssi_history[i]);
6323d5c65159SKalle Valo 
6324d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
6325d5c65159SKalle Valo 	*length = len;
6326d5c65159SKalle Valo }
6327d5c65159SKalle Valo 
6328d5c65159SKalle Valo static void
6329d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
6330d5c65159SKalle Valo 			     const struct ath11k_fw_stats_bcn *bcn,
6331d5c65159SKalle Valo 			     char *buf, u32 *length)
6332d5c65159SKalle Valo {
6333d5c65159SKalle Valo 	u32 len = *length;
6334d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6335d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
6336d5c65159SKalle Valo 	u8 *vdev_macaddr;
6337d5c65159SKalle Valo 
6338d5c65159SKalle Valo 	if (!arvif) {
6339d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
6340d5c65159SKalle Valo 			    bcn->vdev_id);
6341d5c65159SKalle Valo 		return;
6342d5c65159SKalle Valo 	}
6343d5c65159SKalle Valo 
6344d5c65159SKalle Valo 	vdev_macaddr = arvif->vif->addr;
6345d5c65159SKalle Valo 
6346d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6347d5c65159SKalle Valo 			 "VDEV ID", bcn->vdev_id);
6348d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6349d5c65159SKalle Valo 			 "VDEV MAC address", vdev_macaddr);
6350d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6351d5c65159SKalle Valo 			 "================");
6352d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6353d5c65159SKalle Valo 			 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
6354d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6355d5c65159SKalle Valo 			 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
6356d5c65159SKalle Valo 
6357d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
6358d5c65159SKalle Valo 	*length = len;
6359d5c65159SKalle Valo }
6360d5c65159SKalle Valo 
6361d5c65159SKalle Valo void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
6362d5c65159SKalle Valo 			      struct ath11k_fw_stats *fw_stats,
6363d5c65159SKalle Valo 			      u32 stats_id, char *buf)
6364d5c65159SKalle Valo {
6365d5c65159SKalle Valo 	u32 len = 0;
6366d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6367d5c65159SKalle Valo 	const struct ath11k_fw_stats_pdev *pdev;
6368d5c65159SKalle Valo 	const struct ath11k_fw_stats_vdev *vdev;
6369d5c65159SKalle Valo 	const struct ath11k_fw_stats_bcn *bcn;
6370d5c65159SKalle Valo 	size_t num_bcn;
6371d5c65159SKalle Valo 
6372d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
6373d5c65159SKalle Valo 
6374d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_PDEV_STAT) {
6375d5c65159SKalle Valo 		pdev = list_first_entry_or_null(&fw_stats->pdevs,
6376d5c65159SKalle Valo 						struct ath11k_fw_stats_pdev, list);
6377d5c65159SKalle Valo 		if (!pdev) {
6378d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to get pdev stats\n");
6379d5c65159SKalle Valo 			goto unlock;
6380d5c65159SKalle Valo 		}
6381d5c65159SKalle Valo 
6382d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
6383d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
6384d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
6385d5c65159SKalle Valo 	}
6386d5c65159SKalle Valo 
6387d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_VDEV_STAT) {
6388d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
6389d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n",
6390d5c65159SKalle Valo 				 "ath11k VDEV stats");
6391d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6392d5c65159SKalle Valo 				 "=================");
6393d5c65159SKalle Valo 
6394d5c65159SKalle Valo 		list_for_each_entry(vdev, &fw_stats->vdevs, list)
6395d5c65159SKalle Valo 			ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
6396d5c65159SKalle Valo 	}
6397d5c65159SKalle Valo 
6398d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_BCN_STAT) {
6399d5c65159SKalle Valo 		num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn);
6400d5c65159SKalle Valo 
6401d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
6402d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
6403d5c65159SKalle Valo 				 "ath11k Beacon stats", num_bcn);
6404d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6405d5c65159SKalle Valo 				 "===================");
6406d5c65159SKalle Valo 
6407d5c65159SKalle Valo 		list_for_each_entry(bcn, &fw_stats->bcn, list)
6408d5c65159SKalle Valo 			ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
6409d5c65159SKalle Valo 	}
6410d5c65159SKalle Valo 
6411d5c65159SKalle Valo unlock:
6412d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
6413d5c65159SKalle Valo 
6414d5c65159SKalle Valo 	if (len >= buf_len)
6415d5c65159SKalle Valo 		buf[len - 1] = 0;
6416d5c65159SKalle Valo 	else
6417d5c65159SKalle Valo 		buf[len] = 0;
6418d5c65159SKalle Valo }
6419d5c65159SKalle Valo 
6420d5c65159SKalle Valo static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
6421d5c65159SKalle Valo {
6422d5c65159SKalle Valo 	/* try to send pending beacons first. they take priority */
64236bc9d6f7SJohn Crispin 	wake_up(&ab->wmi_ab.tx_credits_wq);
6424d5c65159SKalle Valo }
6425d5c65159SKalle Valo 
64269dcf6808SWen Gong static int ath11k_reg_11d_new_cc_event(struct ath11k_base *ab, struct sk_buff *skb)
64279dcf6808SWen Gong {
64289dcf6808SWen Gong 	const struct wmi_11d_new_cc_ev *ev;
64291f682dc9SWen Gong 	struct ath11k *ar;
64301f682dc9SWen Gong 	struct ath11k_pdev *pdev;
64319dcf6808SWen Gong 	const void **tb;
64321f682dc9SWen Gong 	int ret, i;
64339dcf6808SWen Gong 
64349dcf6808SWen Gong 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
64359dcf6808SWen Gong 	if (IS_ERR(tb)) {
64369dcf6808SWen Gong 		ret = PTR_ERR(tb);
64379dcf6808SWen Gong 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
64389dcf6808SWen Gong 		return ret;
64399dcf6808SWen Gong 	}
64409dcf6808SWen Gong 
64419dcf6808SWen Gong 	ev = tb[WMI_TAG_11D_NEW_COUNTRY_EVENT];
64429dcf6808SWen Gong 	if (!ev) {
64439dcf6808SWen Gong 		kfree(tb);
64449dcf6808SWen Gong 		ath11k_warn(ab, "failed to fetch 11d new cc ev");
64459dcf6808SWen Gong 		return -EPROTO;
64469dcf6808SWen Gong 	}
64479dcf6808SWen Gong 
64489dcf6808SWen Gong 	spin_lock_bh(&ab->base_lock);
64499dcf6808SWen Gong 	memcpy(&ab->new_alpha2, &ev->new_alpha2, 2);
64509dcf6808SWen Gong 	spin_unlock_bh(&ab->base_lock);
64519dcf6808SWen Gong 
64529dcf6808SWen Gong 	ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi 11d new cc %c%c\n",
64539dcf6808SWen Gong 		   ab->new_alpha2[0],
64549dcf6808SWen Gong 		   ab->new_alpha2[1]);
64559dcf6808SWen Gong 
64569dcf6808SWen Gong 	kfree(tb);
64579dcf6808SWen Gong 
64581f682dc9SWen Gong 	for (i = 0; i < ab->num_radios; i++) {
64591f682dc9SWen Gong 		pdev = &ab->pdevs[i];
64601f682dc9SWen Gong 		ar = pdev->ar;
64611f682dc9SWen Gong 		ar->state_11d = ATH11K_11D_IDLE;
64621f682dc9SWen Gong 		complete(&ar->completed_11d_scan);
64631f682dc9SWen Gong 	}
64641f682dc9SWen Gong 
64659dcf6808SWen Gong 	queue_work(ab->workqueue, &ab->update_11d_work);
64669dcf6808SWen Gong 
64679dcf6808SWen Gong 	return 0;
64689dcf6808SWen Gong }
64699dcf6808SWen Gong 
6470d5c65159SKalle Valo static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
6471d5c65159SKalle Valo 				       struct sk_buff *skb)
6472d5c65159SKalle Valo {
6473f951380aSP Praneesh 	struct ath11k_pdev_wmi *wmi = NULL;
6474f951380aSP Praneesh 	u32 i;
6475f951380aSP Praneesh 	u8 wmi_ep_count;
6476f951380aSP Praneesh 	u8 eid;
6477f951380aSP Praneesh 
6478f951380aSP Praneesh 	eid = ATH11K_SKB_CB(skb)->eid;
6479d5c65159SKalle Valo 	dev_kfree_skb(skb);
6480f951380aSP Praneesh 
6481f951380aSP Praneesh 	if (eid >= ATH11K_HTC_EP_COUNT)
6482f951380aSP Praneesh 		return;
6483f951380aSP Praneesh 
6484f951380aSP Praneesh 	wmi_ep_count = ab->htc.wmi_ep_count;
6485f951380aSP Praneesh 	if (wmi_ep_count > ab->hw_params.max_radios)
6486f951380aSP Praneesh 		return;
6487f951380aSP Praneesh 
6488f951380aSP Praneesh 	for (i = 0; i < ab->htc.wmi_ep_count; i++) {
6489f951380aSP Praneesh 		if (ab->wmi_ab.wmi[i].eid == eid) {
6490f951380aSP Praneesh 			wmi = &ab->wmi_ab.wmi[i];
6491f951380aSP Praneesh 			break;
6492f951380aSP Praneesh 		}
6493f951380aSP Praneesh 	}
6494f951380aSP Praneesh 
6495f951380aSP Praneesh 	if (wmi)
6496f951380aSP Praneesh 		wake_up(&wmi->tx_ce_desc_wq);
6497d5c65159SKalle Valo }
6498d5c65159SKalle Valo 
6499d5c65159SKalle Valo static bool ath11k_reg_is_world_alpha(char *alpha)
6500d5c65159SKalle Valo {
6501f8108250SWen Gong 	if (alpha[0] == '0' && alpha[1] == '0')
6502f8108250SWen Gong 		return true;
6503f8108250SWen Gong 
6504f8108250SWen Gong 	if (alpha[0] == 'n' && alpha[1] == 'a')
6505f8108250SWen Gong 		return true;
6506f8108250SWen Gong 
6507f8108250SWen Gong 	return false;
6508d5c65159SKalle Valo }
6509d5c65159SKalle Valo 
6510d5c65159SKalle Valo static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb)
6511d5c65159SKalle Valo {
6512d5c65159SKalle Valo 	struct cur_regulatory_info *reg_info = NULL;
6513d5c65159SKalle Valo 	struct ieee80211_regdomain *regd = NULL;
6514d5c65159SKalle Valo 	bool intersect = false;
6515d5c65159SKalle Valo 	int ret = 0, pdev_idx;
6516d5c65159SKalle Valo 	struct ath11k *ar;
6517d5c65159SKalle Valo 
6518d5c65159SKalle Valo 	reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
6519d5c65159SKalle Valo 	if (!reg_info) {
6520d5c65159SKalle Valo 		ret = -ENOMEM;
6521d5c65159SKalle Valo 		goto fallback;
6522d5c65159SKalle Valo 	}
6523d5c65159SKalle Valo 
6524d5c65159SKalle Valo 	ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
6525d5c65159SKalle Valo 	if (ret) {
6526d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract regulatory info from received event\n");
6527d5c65159SKalle Valo 		goto fallback;
6528d5c65159SKalle Valo 	}
6529d5c65159SKalle Valo 
6530d5c65159SKalle Valo 	if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
6531d5c65159SKalle Valo 		/* In case of failure to set the requested ctry,
6532d5c65159SKalle Valo 		 * fw retains the current regd. We print a failure info
6533d5c65159SKalle Valo 		 * and return from here.
6534d5c65159SKalle Valo 		 */
6535d5c65159SKalle Valo 		ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
6536d5c65159SKalle Valo 		goto mem_free;
6537d5c65159SKalle Valo 	}
6538d5c65159SKalle Valo 
6539d5c65159SKalle Valo 	pdev_idx = reg_info->phy_id;
6540d5c65159SKalle Valo 
654169a0fcf8SSriram R 	/* Avoid default reg rule updates sent during FW recovery if
654269a0fcf8SSriram R 	 * it is already available
654369a0fcf8SSriram R 	 */
654469a0fcf8SSriram R 	spin_lock(&ab->base_lock);
654569a0fcf8SSriram R 	if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) &&
654669a0fcf8SSriram R 	    ab->default_regd[pdev_idx]) {
654769a0fcf8SSriram R 		spin_unlock(&ab->base_lock);
654869a0fcf8SSriram R 		goto mem_free;
654969a0fcf8SSriram R 	}
655069a0fcf8SSriram R 	spin_unlock(&ab->base_lock);
655169a0fcf8SSriram R 
65525f859bc0SCarl Huang 	if (pdev_idx >= ab->num_radios) {
655384eee3c8SCarl Huang 		/* Process the event for phy0 only if single_pdev_only
655484eee3c8SCarl Huang 		 * is true. If pdev_idx is valid but not 0, discard the
655584eee3c8SCarl Huang 		 * event. Otherwise, it goes to fallback.
655684eee3c8SCarl Huang 		 */
655784eee3c8SCarl Huang 		if (ab->hw_params.single_pdev_only &&
655884eee3c8SCarl Huang 		    pdev_idx < ab->hw_params.num_rxmda_per_pdev)
65595f859bc0SCarl Huang 			goto mem_free;
65605f859bc0SCarl Huang 		else
6561d5c65159SKalle Valo 			goto fallback;
65625f859bc0SCarl Huang 	}
6563d5c65159SKalle Valo 
6564d5c65159SKalle Valo 	/* Avoid multiple overwrites to default regd, during core
6565d5c65159SKalle Valo 	 * stop-start after mac registration.
6566d5c65159SKalle Valo 	 */
6567d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
6568d5c65159SKalle Valo 	    !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
6569d5c65159SKalle Valo 		    (char *)reg_info->alpha2, 2))
6570b5316db2SColin Ian King 		goto mem_free;
6571d5c65159SKalle Valo 
6572d5c65159SKalle Valo 	/* Intersect new rules with default regd if a new country setting was
6573d5c65159SKalle Valo 	 * requested, i.e a default regd was already set during initialization
6574d5c65159SKalle Valo 	 * and the regd coming from this event has a valid country info.
6575d5c65159SKalle Valo 	 */
6576d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] &&
6577d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)
6578d5c65159SKalle Valo 		ab->default_regd[pdev_idx]->alpha2) &&
6579d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
6580d5c65159SKalle Valo 		intersect = true;
6581d5c65159SKalle Valo 
6582d5c65159SKalle Valo 	regd = ath11k_reg_build_regd(ab, reg_info, intersect);
6583d5c65159SKalle Valo 	if (!regd) {
6584d5c65159SKalle Valo 		ath11k_warn(ab, "failed to build regd from reg_info\n");
6585d5c65159SKalle Valo 		goto fallback;
6586d5c65159SKalle Valo 	}
6587d5c65159SKalle Valo 
6588d5c65159SKalle Valo 	spin_lock(&ab->base_lock);
65891db2b0d0SSriram R 	if (ab->default_regd[pdev_idx]) {
65901db2b0d0SSriram R 		/* The initial rules from FW after WMI Init is to build
65911db2b0d0SSriram R 		 * the default regd. From then on, any rules updated for
65921db2b0d0SSriram R 		 * the pdev could be due to user reg changes.
6593d5c65159SKalle Valo 		 * Free previously built regd before assigning the newly
6594d5c65159SKalle Valo 		 * generated regd to ar. NULL pointer handling will be
6595d5c65159SKalle Valo 		 * taken care by kfree itself.
6596d5c65159SKalle Valo 		 */
6597d5c65159SKalle Valo 		ar = ab->pdevs[pdev_idx].ar;
6598d5c65159SKalle Valo 		kfree(ab->new_regd[pdev_idx]);
6599d5c65159SKalle Valo 		ab->new_regd[pdev_idx] = regd;
6600ed05c7cfSWen Gong 		queue_work(ab->workqueue, &ar->regd_update_work);
6601d5c65159SKalle Valo 	} else {
66021db2b0d0SSriram R 		/* This regd would be applied during mac registration and is
66031db2b0d0SSriram R 		 * held constant throughout for regd intersection purpose
6604d5c65159SKalle Valo 		 */
6605d5c65159SKalle Valo 		ab->default_regd[pdev_idx] = regd;
6606d5c65159SKalle Valo 	}
6607d5c65159SKalle Valo 	ab->dfs_region = reg_info->dfs_region;
6608d5c65159SKalle Valo 	spin_unlock(&ab->base_lock);
6609d5c65159SKalle Valo 
6610d5c65159SKalle Valo 	goto mem_free;
6611d5c65159SKalle Valo 
6612d5c65159SKalle Valo fallback:
6613d5c65159SKalle Valo 	/* Fallback to older reg (by sending previous country setting
66143926e0c1SManikanta Pubbisetty 	 * again if fw has succeeded and we failed to process here.
6615d5c65159SKalle Valo 	 * The Regdomain should be uniform across driver and fw. Since the
6616d5c65159SKalle Valo 	 * FW has processed the command and sent a success status, we expect
6617d5c65159SKalle Valo 	 * this function to succeed as well. If it doesn't, CTRY needs to be
6618d5c65159SKalle Valo 	 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
6619d5c65159SKalle Valo 	 */
6620d5c65159SKalle Valo 	/* TODO: This is rare, but still should also be handled */
6621d5c65159SKalle Valo 	WARN_ON(1);
6622d5c65159SKalle Valo mem_free:
6623d5c65159SKalle Valo 	if (reg_info) {
6624*25e289e1SAditya Kumar Singh 		kfree(reg_info->reg_rules_2ghz_ptr);
6625*25e289e1SAditya Kumar Singh 		kfree(reg_info->reg_rules_5ghz_ptr);
6626d5c65159SKalle Valo 		kfree(reg_info);
6627d5c65159SKalle Valo 	}
6628d5c65159SKalle Valo 	return ret;
6629d5c65159SKalle Valo }
6630d5c65159SKalle Valo 
6631d5c65159SKalle Valo static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
6632d5c65159SKalle Valo 				    const void *ptr, void *data)
6633d5c65159SKalle Valo {
6634d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse *rdy_parse = data;
663521c1b063SMaharaja Kennadyrajan 	struct wmi_ready_event fixed_param;
6636d5c65159SKalle Valo 	struct wmi_mac_addr *addr_list;
6637d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
6638d5c65159SKalle Valo 	u32 num_mac_addr;
6639d5c65159SKalle Valo 	int i;
6640d5c65159SKalle Valo 
6641d5c65159SKalle Valo 	switch (tag) {
6642d5c65159SKalle Valo 	case WMI_TAG_READY_EVENT:
664321c1b063SMaharaja Kennadyrajan 		memset(&fixed_param, 0, sizeof(fixed_param));
664421c1b063SMaharaja Kennadyrajan 		memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
664521c1b063SMaharaja Kennadyrajan 		       min_t(u16, sizeof(fixed_param), len));
664621c1b063SMaharaja Kennadyrajan 		ab->wlan_init_status = fixed_param.ready_event_min.status;
664721c1b063SMaharaja Kennadyrajan 		rdy_parse->num_extra_mac_addr =
664821c1b063SMaharaja Kennadyrajan 			fixed_param.ready_event_min.num_extra_mac_addr;
6649d5c65159SKalle Valo 
665021c1b063SMaharaja Kennadyrajan 		ether_addr_copy(ab->mac_addr,
665121c1b063SMaharaja Kennadyrajan 				fixed_param.ready_event_min.mac_addr.addr);
665221c1b063SMaharaja Kennadyrajan 		ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum;
6653d5c65159SKalle Valo 		ab->wmi_ready = true;
6654d5c65159SKalle Valo 		break;
6655d5c65159SKalle Valo 	case WMI_TAG_ARRAY_FIXED_STRUCT:
6656d5c65159SKalle Valo 		addr_list = (struct wmi_mac_addr *)ptr;
6657d5c65159SKalle Valo 		num_mac_addr = rdy_parse->num_extra_mac_addr;
6658d5c65159SKalle Valo 
6659d5c65159SKalle Valo 		if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
6660d5c65159SKalle Valo 			break;
6661d5c65159SKalle Valo 
6662d5c65159SKalle Valo 		for (i = 0; i < ab->num_radios; i++) {
6663d5c65159SKalle Valo 			pdev = &ab->pdevs[i];
6664d5c65159SKalle Valo 			ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
6665d5c65159SKalle Valo 		}
6666d5c65159SKalle Valo 		ab->pdevs_macaddr_valid = true;
6667d5c65159SKalle Valo 		break;
6668d5c65159SKalle Valo 	default:
6669d5c65159SKalle Valo 		break;
6670d5c65159SKalle Valo 	}
6671d5c65159SKalle Valo 
6672d5c65159SKalle Valo 	return 0;
6673d5c65159SKalle Valo }
6674d5c65159SKalle Valo 
6675d5c65159SKalle Valo static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
6676d5c65159SKalle Valo {
6677d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse rdy_parse = { };
6678d5c65159SKalle Valo 	int ret;
6679d5c65159SKalle Valo 
6680d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6681d5c65159SKalle Valo 				  ath11k_wmi_tlv_rdy_parse, &rdy_parse);
6682d5c65159SKalle Valo 	if (ret) {
6683d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
6684d5c65159SKalle Valo 		return ret;
6685d5c65159SKalle Valo 	}
6686d5c65159SKalle Valo 
66876bc9d6f7SJohn Crispin 	complete(&ab->wmi_ab.unified_ready);
6688d5c65159SKalle Valo 	return 0;
6689d5c65159SKalle Valo }
6690d5c65159SKalle Valo 
6691d5c65159SKalle Valo static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
6692d5c65159SKalle Valo {
6693d5c65159SKalle Valo 	struct wmi_peer_delete_resp_event peer_del_resp;
6694690ace20SRitesh Singh 	struct ath11k *ar;
6695d5c65159SKalle Valo 
6696d5c65159SKalle Valo 	if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
6697d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer delete resp");
6698d5c65159SKalle Valo 		return;
6699d5c65159SKalle Valo 	}
6700d5c65159SKalle Valo 
6701690ace20SRitesh Singh 	rcu_read_lock();
6702690ace20SRitesh Singh 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id);
6703690ace20SRitesh Singh 	if (!ar) {
6704690ace20SRitesh Singh 		ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d",
6705690ace20SRitesh Singh 			    peer_del_resp.vdev_id);
6706690ace20SRitesh Singh 		rcu_read_unlock();
6707690ace20SRitesh Singh 		return;
6708690ace20SRitesh Singh 	}
6709690ace20SRitesh Singh 
6710690ace20SRitesh Singh 	complete(&ar->peer_delete_done);
6711690ace20SRitesh Singh 	rcu_read_unlock();
6712690ace20SRitesh Singh 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n",
6713690ace20SRitesh Singh 		   peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr);
6714d5c65159SKalle Valo }
6715d5c65159SKalle Valo 
67163cbbdfbeSRitesh Singh static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab,
67173cbbdfbeSRitesh Singh 					  struct sk_buff *skb)
67183cbbdfbeSRitesh Singh {
67193cbbdfbeSRitesh Singh 	struct ath11k *ar;
67203cbbdfbeSRitesh Singh 	u32 vdev_id = 0;
67213cbbdfbeSRitesh Singh 
67223cbbdfbeSRitesh Singh 	if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) {
67233cbbdfbeSRitesh Singh 		ath11k_warn(ab, "failed to extract vdev delete resp");
67243cbbdfbeSRitesh Singh 		return;
67253cbbdfbeSRitesh Singh 	}
67263cbbdfbeSRitesh Singh 
67273cbbdfbeSRitesh Singh 	rcu_read_lock();
67283cbbdfbeSRitesh Singh 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
67293cbbdfbeSRitesh Singh 	if (!ar) {
67303cbbdfbeSRitesh Singh 		ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d",
67313cbbdfbeSRitesh Singh 			    vdev_id);
67323cbbdfbeSRitesh Singh 		rcu_read_unlock();
67333cbbdfbeSRitesh Singh 		return;
67343cbbdfbeSRitesh Singh 	}
67353cbbdfbeSRitesh Singh 
67363cbbdfbeSRitesh Singh 	complete(&ar->vdev_delete_done);
67373cbbdfbeSRitesh Singh 
67383cbbdfbeSRitesh Singh 	rcu_read_unlock();
67393cbbdfbeSRitesh Singh 
67403cbbdfbeSRitesh Singh 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev delete resp for vdev id %d\n",
67413cbbdfbeSRitesh Singh 		   vdev_id);
67423cbbdfbeSRitesh Singh }
67433cbbdfbeSRitesh Singh 
6744d5c65159SKalle Valo static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
6745d5c65159SKalle Valo {
6746d5c65159SKalle Valo 	switch (vdev_resp_status) {
6747d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
6748d5c65159SKalle Valo 		return "invalid vdev id";
6749d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
6750d5c65159SKalle Valo 		return "not supported";
6751d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
6752d5c65159SKalle Valo 		return "dfs violation";
6753d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
6754d5c65159SKalle Valo 		return "invalid regdomain";
6755d5c65159SKalle Valo 	default:
6756d5c65159SKalle Valo 		return "unknown";
6757d5c65159SKalle Valo 	}
6758d5c65159SKalle Valo }
6759d5c65159SKalle Valo 
6760d5c65159SKalle Valo static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
6761d5c65159SKalle Valo {
6762d5c65159SKalle Valo 	struct wmi_vdev_start_resp_event vdev_start_resp;
6763d5c65159SKalle Valo 	struct ath11k *ar;
6764d5c65159SKalle Valo 	u32 status;
6765d5c65159SKalle Valo 
6766d5c65159SKalle Valo 	if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
6767d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev start resp");
6768d5c65159SKalle Valo 		return;
6769d5c65159SKalle Valo 	}
6770d5c65159SKalle Valo 
6771d5c65159SKalle Valo 	rcu_read_lock();
6772d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
6773d5c65159SKalle Valo 	if (!ar) {
6774d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
6775d5c65159SKalle Valo 			    vdev_start_resp.vdev_id);
6776d5c65159SKalle Valo 		rcu_read_unlock();
6777d5c65159SKalle Valo 		return;
6778d5c65159SKalle Valo 	}
6779d5c65159SKalle Valo 
6780d5c65159SKalle Valo 	ar->last_wmi_vdev_start_status = 0;
6781d5c65159SKalle Valo 
6782d5c65159SKalle Valo 	status = vdev_start_resp.status;
6783d5c65159SKalle Valo 
6784d5c65159SKalle Valo 	if (WARN_ON_ONCE(status)) {
6785d5c65159SKalle Valo 		ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
6786d5c65159SKalle Valo 			    status, ath11k_wmi_vdev_resp_print(status));
6787d5c65159SKalle Valo 		ar->last_wmi_vdev_start_status = status;
6788d5c65159SKalle Valo 	}
6789d5c65159SKalle Valo 
6790d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
6791d5c65159SKalle Valo 
6792d5c65159SKalle Valo 	rcu_read_unlock();
6793d5c65159SKalle Valo 
6794d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
6795d5c65159SKalle Valo 		   vdev_start_resp.vdev_id);
6796d5c65159SKalle Valo }
6797d5c65159SKalle Valo 
6798d5c65159SKalle Valo static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
6799d5c65159SKalle Valo {
6800886433a9SJohn Crispin 	struct ath11k_vif *arvif;
6801d5c65159SKalle Valo 	u32 vdev_id, tx_status;
6802d5c65159SKalle Valo 
6803d5c65159SKalle Valo 	if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
6804d5c65159SKalle Valo 					 &vdev_id, &tx_status) != 0) {
6805d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract bcn tx status");
6806d5c65159SKalle Valo 		return;
6807d5c65159SKalle Valo 	}
6808886433a9SJohn Crispin 
680901e782c8SWen Gong 	rcu_read_lock();
6810886433a9SJohn Crispin 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_id);
6811886433a9SJohn Crispin 	if (!arvif) {
6812886433a9SJohn Crispin 		ath11k_warn(ab, "invalid vdev id %d in bcn_tx_status",
6813886433a9SJohn Crispin 			    vdev_id);
681401e782c8SWen Gong 		rcu_read_unlock();
6815886433a9SJohn Crispin 		return;
6816886433a9SJohn Crispin 	}
6817886433a9SJohn Crispin 	ath11k_mac_bcn_tx_event(arvif);
681801e782c8SWen Gong 	rcu_read_unlock();
6819d5c65159SKalle Valo }
6820d5c65159SKalle Valo 
6821710a95f9SVenkateswara Naralasetty static void ath11k_wmi_event_peer_sta_ps_state_chg(struct ath11k_base *ab,
6822710a95f9SVenkateswara Naralasetty 						   struct sk_buff *skb)
6823710a95f9SVenkateswara Naralasetty {
6824710a95f9SVenkateswara Naralasetty 	const struct wmi_peer_sta_ps_state_chg_event *ev;
6825710a95f9SVenkateswara Naralasetty 	struct ieee80211_sta *sta;
6826710a95f9SVenkateswara Naralasetty 	struct ath11k_peer *peer;
6827710a95f9SVenkateswara Naralasetty 	struct ath11k *ar;
6828710a95f9SVenkateswara Naralasetty 	struct ath11k_sta *arsta;
6829710a95f9SVenkateswara Naralasetty 	const void **tb;
6830710a95f9SVenkateswara Naralasetty 	enum ath11k_wmi_peer_ps_state peer_previous_ps_state;
6831710a95f9SVenkateswara Naralasetty 	int ret;
6832710a95f9SVenkateswara Naralasetty 
6833710a95f9SVenkateswara Naralasetty 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6834710a95f9SVenkateswara Naralasetty 	if (IS_ERR(tb)) {
6835710a95f9SVenkateswara Naralasetty 		ret = PTR_ERR(tb);
6836710a95f9SVenkateswara Naralasetty 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6837710a95f9SVenkateswara Naralasetty 		return;
6838710a95f9SVenkateswara Naralasetty 	}
6839710a95f9SVenkateswara Naralasetty 
6840710a95f9SVenkateswara Naralasetty 	ev = tb[WMI_TAG_PEER_STA_PS_STATECHANGE_EVENT];
6841710a95f9SVenkateswara Naralasetty 	if (!ev) {
6842710a95f9SVenkateswara Naralasetty 		ath11k_warn(ab, "failed to fetch sta ps change ev");
6843710a95f9SVenkateswara Naralasetty 		kfree(tb);
6844710a95f9SVenkateswara Naralasetty 		return;
6845710a95f9SVenkateswara Naralasetty 	}
6846710a95f9SVenkateswara Naralasetty 
6847710a95f9SVenkateswara Naralasetty 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6848a797f479SColin Ian King 		   "peer sta ps change ev addr %pM state %u sup_bitmap %x ps_valid %u ts %u\n",
6849710a95f9SVenkateswara Naralasetty 		   ev->peer_macaddr.addr, ev->peer_ps_state,
6850710a95f9SVenkateswara Naralasetty 		   ev->ps_supported_bitmap, ev->peer_ps_valid,
6851710a95f9SVenkateswara Naralasetty 		   ev->peer_ps_timestamp);
6852710a95f9SVenkateswara Naralasetty 
6853710a95f9SVenkateswara Naralasetty 	rcu_read_lock();
6854710a95f9SVenkateswara Naralasetty 
6855710a95f9SVenkateswara Naralasetty 	spin_lock_bh(&ab->base_lock);
6856710a95f9SVenkateswara Naralasetty 
6857710a95f9SVenkateswara Naralasetty 	peer = ath11k_peer_find_by_addr(ab, ev->peer_macaddr.addr);
6858710a95f9SVenkateswara Naralasetty 
6859710a95f9SVenkateswara Naralasetty 	if (!peer) {
6860710a95f9SVenkateswara Naralasetty 		spin_unlock_bh(&ab->base_lock);
6861710a95f9SVenkateswara Naralasetty 		ath11k_warn(ab, "peer not found %pM\n", ev->peer_macaddr.addr);
6862710a95f9SVenkateswara Naralasetty 		goto exit;
6863710a95f9SVenkateswara Naralasetty 	}
6864710a95f9SVenkateswara Naralasetty 
6865710a95f9SVenkateswara Naralasetty 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id);
6866710a95f9SVenkateswara Naralasetty 
6867710a95f9SVenkateswara Naralasetty 	if (!ar) {
6868710a95f9SVenkateswara Naralasetty 		spin_unlock_bh(&ab->base_lock);
6869710a95f9SVenkateswara Naralasetty 		ath11k_warn(ab, "invalid vdev id in peer sta ps state change ev %d",
6870710a95f9SVenkateswara Naralasetty 			    peer->vdev_id);
6871710a95f9SVenkateswara Naralasetty 
6872710a95f9SVenkateswara Naralasetty 		goto exit;
6873710a95f9SVenkateswara Naralasetty 	}
6874710a95f9SVenkateswara Naralasetty 
6875710a95f9SVenkateswara Naralasetty 	sta = peer->sta;
6876710a95f9SVenkateswara Naralasetty 
6877710a95f9SVenkateswara Naralasetty 	spin_unlock_bh(&ab->base_lock);
6878710a95f9SVenkateswara Naralasetty 
6879710a95f9SVenkateswara Naralasetty 	if (!sta) {
6880710a95f9SVenkateswara Naralasetty 		ath11k_warn(ab, "failed to find station entry %pM\n",
6881710a95f9SVenkateswara Naralasetty 			    ev->peer_macaddr.addr);
6882710a95f9SVenkateswara Naralasetty 		goto exit;
6883710a95f9SVenkateswara Naralasetty 	}
6884710a95f9SVenkateswara Naralasetty 
6885710a95f9SVenkateswara Naralasetty 	arsta = (struct ath11k_sta *)sta->drv_priv;
6886710a95f9SVenkateswara Naralasetty 
6887710a95f9SVenkateswara Naralasetty 	spin_lock_bh(&ar->data_lock);
6888710a95f9SVenkateswara Naralasetty 
6889710a95f9SVenkateswara Naralasetty 	peer_previous_ps_state = arsta->peer_ps_state;
6890710a95f9SVenkateswara Naralasetty 	arsta->peer_ps_state = ev->peer_ps_state;
6891710a95f9SVenkateswara Naralasetty 	arsta->peer_current_ps_valid = !!ev->peer_ps_valid;
6892710a95f9SVenkateswara Naralasetty 
6893710a95f9SVenkateswara Naralasetty 	if (test_bit(WMI_TLV_SERVICE_PEER_POWER_SAVE_DURATION_SUPPORT,
6894710a95f9SVenkateswara Naralasetty 		     ar->ab->wmi_ab.svc_map)) {
6895710a95f9SVenkateswara Naralasetty 		if (!(ev->ps_supported_bitmap & WMI_PEER_PS_VALID) ||
6896710a95f9SVenkateswara Naralasetty 		    !(ev->ps_supported_bitmap & WMI_PEER_PS_STATE_TIMESTAMP) ||
6897710a95f9SVenkateswara Naralasetty 		    !ev->peer_ps_valid)
6898710a95f9SVenkateswara Naralasetty 			goto out;
6899710a95f9SVenkateswara Naralasetty 
6900710a95f9SVenkateswara Naralasetty 		if (arsta->peer_ps_state == WMI_PEER_PS_STATE_ON) {
6901710a95f9SVenkateswara Naralasetty 			arsta->ps_start_time = ev->peer_ps_timestamp;
6902710a95f9SVenkateswara Naralasetty 			arsta->ps_start_jiffies = jiffies;
6903710a95f9SVenkateswara Naralasetty 		} else if (arsta->peer_ps_state == WMI_PEER_PS_STATE_OFF &&
6904710a95f9SVenkateswara Naralasetty 			   peer_previous_ps_state == WMI_PEER_PS_STATE_ON) {
6905710a95f9SVenkateswara Naralasetty 			arsta->ps_total_duration = arsta->ps_total_duration +
6906710a95f9SVenkateswara Naralasetty 					(ev->peer_ps_timestamp - arsta->ps_start_time);
6907710a95f9SVenkateswara Naralasetty 		}
6908710a95f9SVenkateswara Naralasetty 
6909710a95f9SVenkateswara Naralasetty 		if (ar->ps_timekeeper_enable)
6910710a95f9SVenkateswara Naralasetty 			trace_ath11k_ps_timekeeper(ar, ev->peer_macaddr.addr,
6911710a95f9SVenkateswara Naralasetty 						   ev->peer_ps_timestamp,
6912710a95f9SVenkateswara Naralasetty 						   arsta->peer_ps_state);
6913710a95f9SVenkateswara Naralasetty 	}
6914710a95f9SVenkateswara Naralasetty 
6915710a95f9SVenkateswara Naralasetty out:
6916710a95f9SVenkateswara Naralasetty 	spin_unlock_bh(&ar->data_lock);
6917710a95f9SVenkateswara Naralasetty exit:
6918710a95f9SVenkateswara Naralasetty 	rcu_read_unlock();
6919710a95f9SVenkateswara Naralasetty 	kfree(tb);
6920710a95f9SVenkateswara Naralasetty }
6921710a95f9SVenkateswara Naralasetty 
6922d5c65159SKalle Valo static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
6923d5c65159SKalle Valo {
6924d5c65159SKalle Valo 	struct ath11k *ar;
6925d5c65159SKalle Valo 	u32 vdev_id = 0;
6926d5c65159SKalle Valo 
6927d5c65159SKalle Valo 	if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
6928d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev stopped event");
6929d5c65159SKalle Valo 		return;
6930d5c65159SKalle Valo 	}
6931d5c65159SKalle Valo 
6932d5c65159SKalle Valo 	rcu_read_lock();
6933fae0385bSRitesh Singh 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
6934d5c65159SKalle Valo 	if (!ar) {
6935d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
6936d5c65159SKalle Valo 			    vdev_id);
6937d5c65159SKalle Valo 		rcu_read_unlock();
6938d5c65159SKalle Valo 		return;
6939d5c65159SKalle Valo 	}
6940d5c65159SKalle Valo 
6941d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
6942d5c65159SKalle Valo 
6943d5c65159SKalle Valo 	rcu_read_unlock();
6944d5c65159SKalle Valo 
6945d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
6946d5c65159SKalle Valo }
6947d5c65159SKalle Valo 
6948d5c65159SKalle Valo static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
6949d5c65159SKalle Valo {
6950d5c65159SKalle Valo 	struct mgmt_rx_event_params rx_ev = {0};
6951d5c65159SKalle Valo 	struct ath11k *ar;
6952d5c65159SKalle Valo 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
6953d5c65159SKalle Valo 	struct ieee80211_hdr *hdr;
6954d5c65159SKalle Valo 	u16 fc;
6955d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
6956d5c65159SKalle Valo 
6957d5c65159SKalle Valo 	if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
6958d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt rx event");
6959d5c65159SKalle Valo 		dev_kfree_skb(skb);
6960d5c65159SKalle Valo 		return;
6961d5c65159SKalle Valo 	}
6962d5c65159SKalle Valo 
6963d5c65159SKalle Valo 	memset(status, 0, sizeof(*status));
6964d5c65159SKalle Valo 
6965d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n",
6966d5c65159SKalle Valo 		   rx_ev.status);
6967d5c65159SKalle Valo 
6968d5c65159SKalle Valo 	rcu_read_lock();
6969d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
6970d5c65159SKalle Valo 
6971d5c65159SKalle Valo 	if (!ar) {
6972d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
6973d5c65159SKalle Valo 			    rx_ev.pdev_id);
6974d5c65159SKalle Valo 		dev_kfree_skb(skb);
6975d5c65159SKalle Valo 		goto exit;
6976d5c65159SKalle Valo 	}
6977d5c65159SKalle Valo 
6978d5c65159SKalle Valo 	if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
6979d5c65159SKalle Valo 	    (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
6980d5c65159SKalle Valo 	    WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
6981d5c65159SKalle Valo 		dev_kfree_skb(skb);
6982d5c65159SKalle Valo 		goto exit;
6983d5c65159SKalle Valo 	}
6984d5c65159SKalle Valo 
6985d5c65159SKalle Valo 	if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
6986d5c65159SKalle Valo 		status->flag |= RX_FLAG_MMIC_ERROR;
6987d5c65159SKalle Valo 
69889d6ae1f5SPradeep Kumar Chitrapu 	if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ &&
69899d6ae1f5SPradeep Kumar Chitrapu 	    rx_ev.chan_freq <= ATH11K_MAX_6G_FREQ) {
69905dcf42f8SPradeep Kumar Chitrapu 		status->band = NL80211_BAND_6GHZ;
69919d6ae1f5SPradeep Kumar Chitrapu 		status->freq = rx_ev.chan_freq;
69925dcf42f8SPradeep Kumar Chitrapu 	} else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
6993d5c65159SKalle Valo 		status->band = NL80211_BAND_2GHZ;
6994d5c65159SKalle Valo 	} else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
6995d5c65159SKalle Valo 		status->band = NL80211_BAND_5GHZ;
6996d5c65159SKalle Valo 	} else {
6997d5c65159SKalle Valo 		/* Shouldn't happen unless list of advertised channels to
6998d5c65159SKalle Valo 		 * mac80211 has been changed.
6999d5c65159SKalle Valo 		 */
7000d5c65159SKalle Valo 		WARN_ON_ONCE(1);
7001d5c65159SKalle Valo 		dev_kfree_skb(skb);
7002d5c65159SKalle Valo 		goto exit;
7003d5c65159SKalle Valo 	}
7004d5c65159SKalle Valo 
700522eeadcdSPradeep Kumar Chitrapu 	if (rx_ev.phy_mode == MODE_11B &&
700622eeadcdSPradeep Kumar Chitrapu 	    (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
7007d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
700822eeadcdSPradeep Kumar Chitrapu 			   "wmi mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
7009d5c65159SKalle Valo 
7010d5c65159SKalle Valo 	sband = &ar->mac.sbands[status->band];
7011d5c65159SKalle Valo 
70129d6ae1f5SPradeep Kumar Chitrapu 	if (status->band != NL80211_BAND_6GHZ)
7013d5c65159SKalle Valo 		status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
7014d5c65159SKalle Valo 							      status->band);
70159d6ae1f5SPradeep Kumar Chitrapu 
7016d5c65159SKalle Valo 	status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
7017d5c65159SKalle Valo 	status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
7018d5c65159SKalle Valo 
7019d5c65159SKalle Valo 	hdr = (struct ieee80211_hdr *)skb->data;
7020d5c65159SKalle Valo 	fc = le16_to_cpu(hdr->frame_control);
7021d5c65159SKalle Valo 
7022d5c65159SKalle Valo 	/* Firmware is guaranteed to report all essential management frames via
7023d5c65159SKalle Valo 	 * WMI while it can deliver some extra via HTT. Since there can be
7024d5c65159SKalle Valo 	 * duplicates split the reporting wrt monitor/sniffing.
7025d5c65159SKalle Valo 	 */
7026d5c65159SKalle Valo 	status->flag |= RX_FLAG_SKIP_MONITOR;
7027d5c65159SKalle Valo 
7028d5c65159SKalle Valo 	/* In case of PMF, FW delivers decrypted frames with Protected Bit set.
7029d5c65159SKalle Valo 	 * Don't clear that. Also, FW delivers broadcast management frames
7030d5c65159SKalle Valo 	 * (ex: group privacy action frames in mesh) as encrypted payload.
7031d5c65159SKalle Valo 	 */
7032d5c65159SKalle Valo 	if (ieee80211_has_protected(hdr->frame_control) &&
7033d5c65159SKalle Valo 	    !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
7034d5c65159SKalle Valo 		status->flag |= RX_FLAG_DECRYPTED;
7035d5c65159SKalle Valo 
7036d5c65159SKalle Valo 		if (!ieee80211_is_robust_mgmt_frame(skb)) {
7037d5c65159SKalle Valo 			status->flag |= RX_FLAG_IV_STRIPPED |
7038d5c65159SKalle Valo 					RX_FLAG_MMIC_STRIPPED;
7039d5c65159SKalle Valo 			hdr->frame_control = __cpu_to_le16(fc &
7040d5c65159SKalle Valo 					     ~IEEE80211_FCTL_PROTECTED);
7041d5c65159SKalle Valo 		}
7042d5c65159SKalle Valo 	}
7043d5c65159SKalle Valo 
704426f69792SLavanya Suresh 	if (ieee80211_is_beacon(hdr->frame_control))
704526f69792SLavanya Suresh 		ath11k_mac_handle_beacon(ar, skb);
7046d5c65159SKalle Valo 
7047d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
7048d5c65159SKalle Valo 		   "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
7049d5c65159SKalle Valo 		   skb, skb->len,
7050d5c65159SKalle Valo 		   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
7051d5c65159SKalle Valo 
7052d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
7053d5c65159SKalle Valo 		   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
7054d5c65159SKalle Valo 		   status->freq, status->band, status->signal,
7055d5c65159SKalle Valo 		   status->rate_idx);
7056d5c65159SKalle Valo 
7057d5c65159SKalle Valo 	ieee80211_rx_ni(ar->hw, skb);
7058d5c65159SKalle Valo 
7059d5c65159SKalle Valo exit:
7060d5c65159SKalle Valo 	rcu_read_unlock();
7061d5c65159SKalle Valo }
7062d5c65159SKalle Valo 
7063d5c65159SKalle Valo static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
7064d5c65159SKalle Valo {
7065d5c65159SKalle Valo 	struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
7066d5c65159SKalle Valo 	struct ath11k *ar;
7067d5c65159SKalle Valo 
7068d5c65159SKalle Valo 	if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
7069d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt tx compl event");
7070d5c65159SKalle Valo 		return;
7071d5c65159SKalle Valo 	}
7072d5c65159SKalle Valo 
7073d5c65159SKalle Valo 	rcu_read_lock();
7074d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
7075d5c65159SKalle Valo 	if (!ar) {
7076d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
7077d5c65159SKalle Valo 			    tx_compl_param.pdev_id);
7078d5c65159SKalle Valo 		goto exit;
7079d5c65159SKalle Valo 	}
7080d5c65159SKalle Valo 
708101c6c9fcSAbinaya Kalaiselvan 	wmi_process_mgmt_tx_comp(ar, &tx_compl_param);
7082d5c65159SKalle Valo 
7083d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
708401c6c9fcSAbinaya Kalaiselvan 		   "mgmt tx compl ev pdev_id %d, desc_id %d, status %d ack_rssi %d",
7085d5c65159SKalle Valo 		   tx_compl_param.pdev_id, tx_compl_param.desc_id,
708601c6c9fcSAbinaya Kalaiselvan 		   tx_compl_param.status, tx_compl_param.ack_rssi);
7087d5c65159SKalle Valo 
7088d5c65159SKalle Valo exit:
7089d5c65159SKalle Valo 	rcu_read_unlock();
7090d5c65159SKalle Valo }
7091d5c65159SKalle Valo 
7092c677d4b1SWen Gong static struct ath11k *ath11k_get_ar_on_scan_state(struct ath11k_base *ab,
7093c677d4b1SWen Gong 						  u32 vdev_id,
7094c677d4b1SWen Gong 						  enum ath11k_scan_state state)
7095d5c65159SKalle Valo {
7096d5c65159SKalle Valo 	int i;
7097d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
7098d5c65159SKalle Valo 	struct ath11k *ar;
7099d5c65159SKalle Valo 
7100d5c65159SKalle Valo 	for (i = 0; i < ab->num_radios; i++) {
7101d5c65159SKalle Valo 		pdev = rcu_dereference(ab->pdevs_active[i]);
7102d5c65159SKalle Valo 		if (pdev && pdev->ar) {
7103d5c65159SKalle Valo 			ar = pdev->ar;
7104d5c65159SKalle Valo 
7105d5c65159SKalle Valo 			spin_lock_bh(&ar->data_lock);
7106c677d4b1SWen Gong 			if (ar->scan.state == state &&
7107d5c65159SKalle Valo 			    ar->scan.vdev_id == vdev_id) {
7108d5c65159SKalle Valo 				spin_unlock_bh(&ar->data_lock);
7109d5c65159SKalle Valo 				return ar;
7110d5c65159SKalle Valo 			}
7111d5c65159SKalle Valo 			spin_unlock_bh(&ar->data_lock);
7112d5c65159SKalle Valo 		}
7113d5c65159SKalle Valo 	}
7114d5c65159SKalle Valo 	return NULL;
7115d5c65159SKalle Valo }
7116d5c65159SKalle Valo 
7117d5c65159SKalle Valo static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
7118d5c65159SKalle Valo {
7119d5c65159SKalle Valo 	struct ath11k *ar;
7120d5c65159SKalle Valo 	struct wmi_scan_event scan_ev = {0};
7121d5c65159SKalle Valo 
7122d5c65159SKalle Valo 	if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
7123d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract scan event");
7124d5c65159SKalle Valo 		return;
7125d5c65159SKalle Valo 	}
7126d5c65159SKalle Valo 
7127d5c65159SKalle Valo 	rcu_read_lock();
7128d5c65159SKalle Valo 
7129d5c65159SKalle Valo 	/* In case the scan was cancelled, ex. during interface teardown,
7130d5c65159SKalle Valo 	 * the interface will not be found in active interfaces.
7131d5c65159SKalle Valo 	 * Rather, in such scenarios, iterate over the active pdev's to
7132d5c65159SKalle Valo 	 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
7133d5c65159SKalle Valo 	 * aborting scan's vdev id matches this event info.
7134d5c65159SKalle Valo 	 */
7135d5c65159SKalle Valo 	if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
7136c677d4b1SWen Gong 	    scan_ev.reason == WMI_SCAN_REASON_CANCELLED) {
7137c677d4b1SWen Gong 		ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7138c677d4b1SWen Gong 						 ATH11K_SCAN_ABORTING);
7139c677d4b1SWen Gong 		if (!ar)
7140c677d4b1SWen Gong 			ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7141c677d4b1SWen Gong 							 ATH11K_SCAN_RUNNING);
7142c677d4b1SWen Gong 	} else {
7143d5c65159SKalle Valo 		ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
7144c677d4b1SWen Gong 	}
7145d5c65159SKalle Valo 
7146d5c65159SKalle Valo 	if (!ar) {
7147d5c65159SKalle Valo 		ath11k_warn(ab, "Received scan event for unknown vdev");
7148d5c65159SKalle Valo 		rcu_read_unlock();
7149d5c65159SKalle Valo 		return;
7150d5c65159SKalle Valo 	}
7151d5c65159SKalle Valo 
7152d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
7153d5c65159SKalle Valo 
7154d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7155d5c65159SKalle Valo 		   "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
7156d5c65159SKalle Valo 		   ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
7157d5c65159SKalle Valo 		   scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
7158d5c65159SKalle Valo 		   scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
7159d5c65159SKalle Valo 		   ath11k_scan_state_str(ar->scan.state), ar->scan.state);
7160d5c65159SKalle Valo 
7161d5c65159SKalle Valo 	switch (scan_ev.event_type) {
7162d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
7163d5c65159SKalle Valo 		ath11k_wmi_event_scan_started(ar);
7164d5c65159SKalle Valo 		break;
7165d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
7166d5c65159SKalle Valo 		ath11k_wmi_event_scan_completed(ar);
7167d5c65159SKalle Valo 		break;
7168d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
7169d5c65159SKalle Valo 		ath11k_wmi_event_scan_bss_chan(ar);
7170d5c65159SKalle Valo 		break;
7171d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
7172d5c65159SKalle Valo 		ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
7173d5c65159SKalle Valo 		break;
7174d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
7175d5c65159SKalle Valo 		ath11k_warn(ab, "received scan start failure event\n");
7176d5c65159SKalle Valo 		ath11k_wmi_event_scan_start_failed(ar);
7177d5c65159SKalle Valo 		break;
7178d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
7179441b3b59SWen Gong 		__ath11k_mac_scan_finish(ar);
7180441b3b59SWen Gong 		break;
7181d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
7182d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
7183d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
7184d5c65159SKalle Valo 	default:
7185d5c65159SKalle Valo 		break;
7186d5c65159SKalle Valo 	}
7187d5c65159SKalle Valo 
7188d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
7189d5c65159SKalle Valo 
7190d5c65159SKalle Valo 	rcu_read_unlock();
7191d5c65159SKalle Valo }
7192d5c65159SKalle Valo 
7193d5c65159SKalle Valo static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
7194d5c65159SKalle Valo {
7195d5c65159SKalle Valo 	struct wmi_peer_sta_kickout_arg arg = {};
7196d5c65159SKalle Valo 	struct ieee80211_sta *sta;
7197d5c65159SKalle Valo 	struct ath11k_peer *peer;
7198d5c65159SKalle Valo 	struct ath11k *ar;
71994c375743SKarthikeyan Periyasamy 	u32 vdev_id;
7200d5c65159SKalle Valo 
7201d5c65159SKalle Valo 	if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
7202d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer sta kickout event");
7203d5c65159SKalle Valo 		return;
7204d5c65159SKalle Valo 	}
7205d5c65159SKalle Valo 
7206d5c65159SKalle Valo 	rcu_read_lock();
7207d5c65159SKalle Valo 
7208d5c65159SKalle Valo 	spin_lock_bh(&ab->base_lock);
7209d5c65159SKalle Valo 
7210d5c65159SKalle Valo 	peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
7211d5c65159SKalle Valo 
7212d5c65159SKalle Valo 	if (!peer) {
7213d5c65159SKalle Valo 		ath11k_warn(ab, "peer not found %pM\n",
7214d5c65159SKalle Valo 			    arg.mac_addr);
72154c375743SKarthikeyan Periyasamy 		spin_unlock_bh(&ab->base_lock);
7216d5c65159SKalle Valo 		goto exit;
7217d5c65159SKalle Valo 	}
7218d5c65159SKalle Valo 
72194c375743SKarthikeyan Periyasamy 	vdev_id = peer->vdev_id;
72204c375743SKarthikeyan Periyasamy 
72214c375743SKarthikeyan Periyasamy 	spin_unlock_bh(&ab->base_lock);
72224c375743SKarthikeyan Periyasamy 
72234c375743SKarthikeyan Periyasamy 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7224d5c65159SKalle Valo 	if (!ar) {
7225d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
7226d5c65159SKalle Valo 			    peer->vdev_id);
7227d5c65159SKalle Valo 		goto exit;
7228d5c65159SKalle Valo 	}
7229d5c65159SKalle Valo 
7230d5c65159SKalle Valo 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
7231d5c65159SKalle Valo 					   arg.mac_addr, NULL);
7232d5c65159SKalle Valo 	if (!sta) {
7233d5c65159SKalle Valo 		ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
7234d5c65159SKalle Valo 			    arg.mac_addr);
7235d5c65159SKalle Valo 		goto exit;
7236d5c65159SKalle Valo 	}
7237d5c65159SKalle Valo 
7238d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM",
7239d5c65159SKalle Valo 		   arg.mac_addr);
7240d5c65159SKalle Valo 
7241d5c65159SKalle Valo 	ieee80211_report_low_ack(sta, 10);
7242d5c65159SKalle Valo 
7243d5c65159SKalle Valo exit:
7244d5c65159SKalle Valo 	rcu_read_unlock();
7245d5c65159SKalle Valo }
7246d5c65159SKalle Valo 
7247d5c65159SKalle Valo static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
7248d5c65159SKalle Valo {
7249d5c65159SKalle Valo 	struct wmi_roam_event roam_ev = {};
7250d5c65159SKalle Valo 	struct ath11k *ar;
7251d5c65159SKalle Valo 
7252d5c65159SKalle Valo 	if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
7253d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract roam event");
7254d5c65159SKalle Valo 		return;
7255d5c65159SKalle Valo 	}
7256d5c65159SKalle Valo 
7257d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7258d5c65159SKalle Valo 		   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
7259d5c65159SKalle Valo 		   roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
7260d5c65159SKalle Valo 
7261d5c65159SKalle Valo 	rcu_read_lock();
7262d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
7263d5c65159SKalle Valo 	if (!ar) {
7264d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in roam ev %d",
7265d5c65159SKalle Valo 			    roam_ev.vdev_id);
7266d5c65159SKalle Valo 		rcu_read_unlock();
7267d5c65159SKalle Valo 		return;
7268d5c65159SKalle Valo 	}
7269d5c65159SKalle Valo 
7270d5c65159SKalle Valo 	if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
7271d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
7272d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
7273d5c65159SKalle Valo 
7274d5c65159SKalle Valo 	switch (roam_ev.reason) {
7275d5c65159SKalle Valo 	case WMI_ROAM_REASON_BEACON_MISS:
727626f69792SLavanya Suresh 		ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id);
7277d5c65159SKalle Valo 		break;
7278d5c65159SKalle Valo 	case WMI_ROAM_REASON_BETTER_AP:
7279d5c65159SKalle Valo 	case WMI_ROAM_REASON_LOW_RSSI:
7280d5c65159SKalle Valo 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
7281d5c65159SKalle Valo 	case WMI_ROAM_REASON_HO_FAILED:
7282d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
7283d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
7284d5c65159SKalle Valo 		break;
7285d5c65159SKalle Valo 	}
7286d5c65159SKalle Valo 
7287d5c65159SKalle Valo 	rcu_read_unlock();
7288d5c65159SKalle Valo }
7289d5c65159SKalle Valo 
7290d5c65159SKalle Valo static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7291d5c65159SKalle Valo {
7292d5c65159SKalle Valo 	struct wmi_chan_info_event ch_info_ev = {0};
7293d5c65159SKalle Valo 	struct ath11k *ar;
7294d5c65159SKalle Valo 	struct survey_info *survey;
7295d5c65159SKalle Valo 	int idx;
7296d5c65159SKalle Valo 	/* HW channel counters frequency value in hertz */
7297d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
7298d5c65159SKalle Valo 
7299d5c65159SKalle Valo 	if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
7300d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract chan info event");
7301d5c65159SKalle Valo 		return;
7302d5c65159SKalle Valo 	}
7303d5c65159SKalle Valo 
7304d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7305d5c65159SKalle 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",
7306d5c65159SKalle Valo 		   ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
7307d5c65159SKalle Valo 		   ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
7308d5c65159SKalle Valo 		   ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
7309d5c65159SKalle Valo 		   ch_info_ev.mac_clk_mhz);
7310d5c65159SKalle Valo 
7311d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
7312d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
7313d5c65159SKalle Valo 		return;
7314d5c65159SKalle Valo 	}
7315d5c65159SKalle Valo 
7316d5c65159SKalle Valo 	rcu_read_lock();
7317d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
7318d5c65159SKalle Valo 	if (!ar) {
7319d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in chan info ev %d",
7320d5c65159SKalle Valo 			    ch_info_ev.vdev_id);
7321d5c65159SKalle Valo 		rcu_read_unlock();
7322d5c65159SKalle Valo 		return;
7323d5c65159SKalle Valo 	}
7324d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
7325d5c65159SKalle Valo 
7326d5c65159SKalle Valo 	switch (ar->scan.state) {
7327d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
7328d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
7329d5c65159SKalle Valo 		ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
7330d5c65159SKalle Valo 		goto exit;
7331d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
7332d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
7333d5c65159SKalle Valo 		break;
7334d5c65159SKalle Valo 	}
7335d5c65159SKalle Valo 
7336d5c65159SKalle Valo 	idx = freq_to_idx(ar, ch_info_ev.freq);
7337d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
7338d5c65159SKalle Valo 		ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
7339d5c65159SKalle Valo 			    ch_info_ev.freq, idx);
7340d5c65159SKalle Valo 		goto exit;
7341d5c65159SKalle Valo 	}
7342d5c65159SKalle Valo 
7343d5c65159SKalle Valo 	/* If FW provides MAC clock frequency in Mhz, overriding the initialized
7344d5c65159SKalle Valo 	 * HW channel counters frequency value
7345d5c65159SKalle Valo 	 */
7346d5c65159SKalle Valo 	if (ch_info_ev.mac_clk_mhz)
7347d5c65159SKalle Valo 		cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
7348d5c65159SKalle Valo 
7349d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
7350d5c65159SKalle Valo 		survey = &ar->survey[idx];
7351d5c65159SKalle Valo 		memset(survey, 0, sizeof(*survey));
7352d5c65159SKalle Valo 		survey->noise = ch_info_ev.noise_floor;
7353d5c65159SKalle Valo 		survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
7354d5c65159SKalle Valo 				 SURVEY_INFO_TIME_BUSY;
7355d5c65159SKalle Valo 		survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
7356d5c65159SKalle Valo 		survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
7357d5c65159SKalle Valo 	}
7358d5c65159SKalle Valo exit:
7359d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
7360d5c65159SKalle Valo 	rcu_read_unlock();
7361d5c65159SKalle Valo }
7362d5c65159SKalle Valo 
7363d5c65159SKalle Valo static void
7364d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7365d5c65159SKalle Valo {
7366d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
7367d5c65159SKalle Valo 	struct survey_info *survey;
7368d5c65159SKalle Valo 	struct ath11k *ar;
7369d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
7370d5c65159SKalle Valo 	u64 busy, total, tx, rx, rx_bss;
7371d5c65159SKalle Valo 	int idx;
7372d5c65159SKalle Valo 
7373d5c65159SKalle Valo 	if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
7374d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract pdev bss chan info event");
7375d5c65159SKalle Valo 		return;
7376d5c65159SKalle Valo 	}
7377d5c65159SKalle Valo 
7378d5c65159SKalle Valo 	busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
7379d5c65159SKalle Valo 			bss_ch_info_ev.rx_clear_count_low;
7380d5c65159SKalle Valo 
7381d5c65159SKalle Valo 	total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
7382d5c65159SKalle Valo 			bss_ch_info_ev.cycle_count_low;
7383d5c65159SKalle Valo 
7384d5c65159SKalle Valo 	tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
7385d5c65159SKalle Valo 			bss_ch_info_ev.tx_cycle_count_low;
7386d5c65159SKalle Valo 
7387d5c65159SKalle Valo 	rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
7388d5c65159SKalle Valo 			bss_ch_info_ev.rx_cycle_count_low;
7389d5c65159SKalle Valo 
7390d5c65159SKalle Valo 	rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
7391d5c65159SKalle Valo 			bss_ch_info_ev.rx_bss_cycle_count_low;
7392d5c65159SKalle Valo 
7393d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7394d5c65159SKalle 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",
7395d5c65159SKalle Valo 		   bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
7396d5c65159SKalle Valo 		   bss_ch_info_ev.noise_floor, busy, total,
7397d5c65159SKalle Valo 		   tx, rx, rx_bss);
7398d5c65159SKalle Valo 
7399d5c65159SKalle Valo 	rcu_read_lock();
7400d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
7401d5c65159SKalle Valo 
7402d5c65159SKalle Valo 	if (!ar) {
7403d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
7404d5c65159SKalle Valo 			    bss_ch_info_ev.pdev_id);
7405d5c65159SKalle Valo 		rcu_read_unlock();
7406d5c65159SKalle Valo 		return;
7407d5c65159SKalle Valo 	}
7408d5c65159SKalle Valo 
7409d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
7410d5c65159SKalle Valo 	idx = freq_to_idx(ar, bss_ch_info_ev.freq);
7411d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
7412d5c65159SKalle Valo 		ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
7413d5c65159SKalle Valo 			    bss_ch_info_ev.freq, idx);
7414d5c65159SKalle Valo 		goto exit;
7415d5c65159SKalle Valo 	}
7416d5c65159SKalle Valo 
7417d5c65159SKalle Valo 	survey = &ar->survey[idx];
7418d5c65159SKalle Valo 
7419d5c65159SKalle Valo 	survey->noise     = bss_ch_info_ev.noise_floor;
7420d5c65159SKalle Valo 	survey->time      = div_u64(total, cc_freq_hz);
7421d5c65159SKalle Valo 	survey->time_busy = div_u64(busy, cc_freq_hz);
7422d5c65159SKalle Valo 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
7423d5c65159SKalle Valo 	survey->time_tx   = div_u64(tx, cc_freq_hz);
7424d5c65159SKalle Valo 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
7425d5c65159SKalle Valo 			     SURVEY_INFO_TIME |
7426d5c65159SKalle Valo 			     SURVEY_INFO_TIME_BUSY |
7427d5c65159SKalle Valo 			     SURVEY_INFO_TIME_RX |
7428d5c65159SKalle Valo 			     SURVEY_INFO_TIME_TX);
7429d5c65159SKalle Valo exit:
7430d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
7431d5c65159SKalle Valo 	complete(&ar->bss_survey_done);
7432d5c65159SKalle Valo 
7433d5c65159SKalle Valo 	rcu_read_unlock();
7434d5c65159SKalle Valo }
7435d5c65159SKalle Valo 
7436d5c65159SKalle Valo static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
7437d5c65159SKalle Valo 						struct sk_buff *skb)
7438d5c65159SKalle Valo {
7439d5c65159SKalle Valo 	struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
7440d5c65159SKalle Valo 	struct ath11k *ar;
7441d5c65159SKalle Valo 
7442d5c65159SKalle Valo 	if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
7443d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract install key compl event");
7444d5c65159SKalle Valo 		return;
7445d5c65159SKalle Valo 	}
7446d5c65159SKalle Valo 
7447d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7448d5c65159SKalle Valo 		   "vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
7449d5c65159SKalle Valo 		   install_key_compl.key_idx, install_key_compl.key_flags,
7450d5c65159SKalle Valo 		   install_key_compl.macaddr, install_key_compl.status);
7451d5c65159SKalle Valo 
7452d5c65159SKalle Valo 	rcu_read_lock();
7453d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
7454d5c65159SKalle Valo 	if (!ar) {
7455d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
7456d5c65159SKalle Valo 			    install_key_compl.vdev_id);
7457d5c65159SKalle Valo 		rcu_read_unlock();
7458d5c65159SKalle Valo 		return;
7459d5c65159SKalle Valo 	}
7460d5c65159SKalle Valo 
7461d5c65159SKalle Valo 	ar->install_key_status = 0;
7462d5c65159SKalle Valo 
7463d5c65159SKalle Valo 	if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
7464d5c65159SKalle Valo 		ath11k_warn(ab, "install key failed for %pM status %d\n",
7465d5c65159SKalle Valo 			    install_key_compl.macaddr, install_key_compl.status);
7466d5c65159SKalle Valo 		ar->install_key_status = install_key_compl.status;
7467d5c65159SKalle Valo 	}
7468d5c65159SKalle Valo 
7469d5c65159SKalle Valo 	complete(&ar->install_key_done);
7470d5c65159SKalle Valo 	rcu_read_unlock();
7471d5c65159SKalle Valo }
7472d5c65159SKalle Valo 
7473e2e23a79SWen Gong static int  ath11k_wmi_tlv_services_parser(struct ath11k_base *ab,
7474e2e23a79SWen Gong 					   u16 tag, u16 len,
7475e2e23a79SWen Gong 					   const void *ptr, void *data)
7476d5c65159SKalle Valo {
7477d5c65159SKalle Valo 	const struct wmi_service_available_event *ev;
7478e2e23a79SWen Gong 	u32 *wmi_ext2_service_bitmap;
7479d5c65159SKalle Valo 	int i, j;
7480d5c65159SKalle Valo 
7481e2e23a79SWen Gong 	switch (tag) {
7482e2e23a79SWen Gong 	case WMI_TAG_SERVICE_AVAILABLE_EVENT:
7483e2e23a79SWen Gong 		ev = (struct wmi_service_available_event *)ptr;
7484d5c65159SKalle Valo 		for (i = 0, j = WMI_MAX_SERVICE;
7485d5c65159SKalle Valo 			i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
7486d5c65159SKalle Valo 			i++) {
7487d5c65159SKalle Valo 			do {
7488d5c65159SKalle Valo 				if (ev->wmi_service_segment_bitmap[i] &
7489d5c65159SKalle Valo 				    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
74906bc9d6f7SJohn Crispin 					set_bit(j, ab->wmi_ab.svc_map);
7491d5c65159SKalle Valo 			} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
7492d5c65159SKalle Valo 		}
7493d5c65159SKalle Valo 
7494d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
7495e2e23a79SWen Gong 			   "wmi_ext_service_bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
7496e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[0],
7497e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[1],
7498e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[2],
7499e2e23a79SWen Gong 			   ev->wmi_service_segment_bitmap[3]);
7500e2e23a79SWen Gong 		break;
7501e2e23a79SWen Gong 	case WMI_TAG_ARRAY_UINT32:
7502e2e23a79SWen Gong 		wmi_ext2_service_bitmap = (u32 *)ptr;
7503e2e23a79SWen Gong 		for (i = 0, j = WMI_MAX_EXT_SERVICE;
7504e2e23a79SWen Gong 			i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT2_SERVICE;
7505e2e23a79SWen Gong 			i++) {
7506e2e23a79SWen Gong 			do {
7507e2e23a79SWen Gong 				if (wmi_ext2_service_bitmap[i] &
7508e2e23a79SWen Gong 				    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
7509e2e23a79SWen Gong 					set_bit(j, ab->wmi_ab.svc_map);
7510e2e23a79SWen Gong 			} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
7511e2e23a79SWen Gong 		}
7512d5c65159SKalle Valo 
7513e2e23a79SWen Gong 		ath11k_dbg(ab, ATH11K_DBG_WMI,
7514e2e23a79SWen Gong 			   "wmi_ext2_service__bitmap  0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
7515e2e23a79SWen Gong 			   wmi_ext2_service_bitmap[0], wmi_ext2_service_bitmap[1],
7516e2e23a79SWen Gong 			   wmi_ext2_service_bitmap[2], wmi_ext2_service_bitmap[3]);
7517e2e23a79SWen Gong 		break;
7518e2e23a79SWen Gong 	}
7519e2e23a79SWen Gong 	return 0;
7520e2e23a79SWen Gong }
7521e2e23a79SWen Gong 
7522e2e23a79SWen Gong static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
7523e2e23a79SWen Gong {
7524e2e23a79SWen Gong 	int ret;
7525e2e23a79SWen Gong 
7526e2e23a79SWen Gong 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7527e2e23a79SWen Gong 				  ath11k_wmi_tlv_services_parser,
7528e2e23a79SWen Gong 				  NULL);
7529e2e23a79SWen Gong 	if (ret)
7530e2e23a79SWen Gong 		ath11k_warn(ab, "failed to parse services available tlv %d\n", ret);
7531d5c65159SKalle Valo }
7532d5c65159SKalle Valo 
7533d5c65159SKalle Valo static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
7534d5c65159SKalle Valo {
7535d5c65159SKalle Valo 	struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
7536d5c65159SKalle Valo 	struct ath11k *ar;
7537d5c65159SKalle Valo 
7538d5c65159SKalle Valo 	if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
7539d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer assoc conf event");
7540d5c65159SKalle Valo 		return;
7541d5c65159SKalle Valo 	}
7542d5c65159SKalle Valo 
7543d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7544d5c65159SKalle Valo 		   "peer assoc conf ev vdev id %d macaddr %pM\n",
7545d5c65159SKalle Valo 		   peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
7546d5c65159SKalle Valo 
7547db0889abSKarthikeyan Periyasamy 	rcu_read_lock();
7548d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
7549d5c65159SKalle Valo 
7550d5c65159SKalle Valo 	if (!ar) {
7551d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
7552d5c65159SKalle Valo 			    peer_assoc_conf.vdev_id);
7553db0889abSKarthikeyan Periyasamy 		rcu_read_unlock();
7554d5c65159SKalle Valo 		return;
7555d5c65159SKalle Valo 	}
7556d5c65159SKalle Valo 
7557d5c65159SKalle Valo 	complete(&ar->peer_assoc_done);
7558db0889abSKarthikeyan Periyasamy 	rcu_read_unlock();
7559d5c65159SKalle Valo }
7560d5c65159SKalle Valo 
7561d5c65159SKalle Valo static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
7562d5c65159SKalle Valo {
7563ec8918f9SAditya Kumar Singh 	struct ath11k_fw_stats stats = {};
7564ec8918f9SAditya Kumar Singh 	struct ath11k *ar;
7565ec8918f9SAditya Kumar Singh 	int ret;
7566ec8918f9SAditya Kumar Singh 
7567ec8918f9SAditya Kumar Singh 	INIT_LIST_HEAD(&stats.pdevs);
7568ec8918f9SAditya Kumar Singh 	INIT_LIST_HEAD(&stats.vdevs);
7569ec8918f9SAditya Kumar Singh 	INIT_LIST_HEAD(&stats.bcn);
7570ec8918f9SAditya Kumar Singh 
7571ec8918f9SAditya Kumar Singh 	ret = ath11k_wmi_pull_fw_stats(ab, skb, &stats);
7572ec8918f9SAditya Kumar Singh 	if (ret) {
7573ec8918f9SAditya Kumar Singh 		ath11k_warn(ab, "failed to pull fw stats: %d\n", ret);
7574ec8918f9SAditya Kumar Singh 		goto free;
7575ec8918f9SAditya Kumar Singh 	}
7576ec8918f9SAditya Kumar Singh 
7577ec8918f9SAditya Kumar Singh 	rcu_read_lock();
7578ec8918f9SAditya Kumar Singh 	ar = ath11k_mac_get_ar_by_pdev_id(ab, stats.pdev_id);
7579ec8918f9SAditya Kumar Singh 	if (!ar) {
7580ec8918f9SAditya Kumar Singh 		rcu_read_unlock();
7581ec8918f9SAditya Kumar Singh 		ath11k_warn(ab, "failed to get ar for pdev_id %d: %d\n",
7582ec8918f9SAditya Kumar Singh 			    stats.pdev_id, ret);
7583ec8918f9SAditya Kumar Singh 		goto free;
7584ec8918f9SAditya Kumar Singh 	}
7585ec8918f9SAditya Kumar Singh 
7586ec8918f9SAditya Kumar Singh 	spin_lock_bh(&ar->data_lock);
7587ec8918f9SAditya Kumar Singh 
7588ec8918f9SAditya Kumar Singh 	/* WMI_REQUEST_PDEV_STAT can be requested via .get_txpower mac ops or via
7589ec8918f9SAditya Kumar Singh 	 * debugfs fw stats. Therefore, processing it separately.
7590ec8918f9SAditya Kumar Singh 	 */
7591ec8918f9SAditya Kumar Singh 	if (stats.stats_id == WMI_REQUEST_PDEV_STAT) {
7592ec8918f9SAditya Kumar Singh 		list_splice_tail_init(&stats.pdevs, &ar->fw_stats.pdevs);
7593ec8918f9SAditya Kumar Singh 		ar->fw_stats_done = true;
7594ec8918f9SAditya Kumar Singh 		goto complete;
7595ec8918f9SAditya Kumar Singh 	}
7596ec8918f9SAditya Kumar Singh 
7597ec8918f9SAditya Kumar Singh 	/* WMI_REQUEST_VDEV_STAT, WMI_REQUEST_BCN_STAT and WMI_REQUEST_RSSI_PER_CHAIN_STAT
7598ec8918f9SAditya Kumar Singh 	 * are currently requested only via debugfs fw stats. Hence, processing these
7599ec8918f9SAditya Kumar Singh 	 * in debugfs context
7600ec8918f9SAditya Kumar Singh 	 */
7601ec8918f9SAditya Kumar Singh 	ath11k_debugfs_fw_stats_process(ar, &stats);
7602ec8918f9SAditya Kumar Singh 
7603ec8918f9SAditya Kumar Singh complete:
7604ec8918f9SAditya Kumar Singh 	complete(&ar->fw_stats_complete);
7605ec8918f9SAditya Kumar Singh 	rcu_read_unlock();
7606ec8918f9SAditya Kumar Singh 	spin_unlock_bh(&ar->data_lock);
7607ec8918f9SAditya Kumar Singh 
7608ec8918f9SAditya Kumar Singh free:
7609ec8918f9SAditya Kumar Singh 	ath11k_fw_stats_free(&stats);
7610d5c65159SKalle Valo }
7611d5c65159SKalle Valo 
7612d5c65159SKalle Valo /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
7613d5c65159SKalle Valo  * is not part of BDF CTL(Conformance test limits) table entries.
7614d5c65159SKalle Valo  */
7615d5c65159SKalle Valo static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
7616d5c65159SKalle Valo 						 struct sk_buff *skb)
7617d5c65159SKalle Valo {
7618d5c65159SKalle Valo 	const void **tb;
7619d5c65159SKalle Valo 	const struct wmi_pdev_ctl_failsafe_chk_event *ev;
7620d5c65159SKalle Valo 	int ret;
7621d5c65159SKalle Valo 
7622d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7623d5c65159SKalle Valo 	if (IS_ERR(tb)) {
7624d5c65159SKalle Valo 		ret = PTR_ERR(tb);
7625d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7626d5c65159SKalle Valo 		return;
7627d5c65159SKalle Valo 	}
7628d5c65159SKalle Valo 
7629d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
7630d5c65159SKalle Valo 	if (!ev) {
7631d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
7632d5c65159SKalle Valo 		kfree(tb);
7633d5c65159SKalle Valo 		return;
7634d5c65159SKalle Valo 	}
7635d5c65159SKalle Valo 
7636d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7637d5c65159SKalle Valo 		   "pdev ctl failsafe check ev status %d\n",
7638d5c65159SKalle Valo 		   ev->ctl_failsafe_status);
7639d5c65159SKalle Valo 
7640d5c65159SKalle Valo 	/* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
7641d5c65159SKalle Valo 	 * to 10 dBm else the CTL power entry in the BDF would be picked up.
7642d5c65159SKalle Valo 	 */
7643d5c65159SKalle Valo 	if (ev->ctl_failsafe_status != 0)
7644d5c65159SKalle Valo 		ath11k_warn(ab, "pdev ctl failsafe failure status %d",
7645d5c65159SKalle Valo 			    ev->ctl_failsafe_status);
7646d5c65159SKalle Valo 
7647d5c65159SKalle Valo 	kfree(tb);
7648d5c65159SKalle Valo }
7649d5c65159SKalle Valo 
7650d5c65159SKalle Valo static void
7651d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
7652d5c65159SKalle Valo 					  const struct wmi_pdev_csa_switch_ev *ev,
7653d5c65159SKalle Valo 					  const u32 *vdev_ids)
7654d5c65159SKalle Valo {
7655d5c65159SKalle Valo 	int i;
7656d5c65159SKalle Valo 	struct ath11k_vif *arvif;
7657d5c65159SKalle Valo 
7658d5c65159SKalle Valo 	/* Finish CSA once the switch count becomes NULL */
7659d5c65159SKalle Valo 	if (ev->current_switch_count)
7660d5c65159SKalle Valo 		return;
7661d5c65159SKalle Valo 
7662d5c65159SKalle Valo 	rcu_read_lock();
7663d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdevs; i++) {
7664d5c65159SKalle Valo 		arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
7665d5c65159SKalle Valo 
7666d5c65159SKalle Valo 		if (!arvif) {
7667d5c65159SKalle Valo 			ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
7668d5c65159SKalle Valo 				    vdev_ids[i]);
7669d5c65159SKalle Valo 			continue;
7670d5c65159SKalle Valo 		}
7671d5c65159SKalle Valo 
7672d0a9123eSJohannes Berg 		if (arvif->is_up && arvif->vif->bss_conf.csa_active)
7673d5c65159SKalle Valo 			ieee80211_csa_finish(arvif->vif);
7674d5c65159SKalle Valo 	}
7675d5c65159SKalle Valo 	rcu_read_unlock();
7676d5c65159SKalle Valo }
7677d5c65159SKalle Valo 
7678d5c65159SKalle Valo static void
7679d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
7680d5c65159SKalle Valo 					      struct sk_buff *skb)
7681d5c65159SKalle Valo {
7682d5c65159SKalle Valo 	const void **tb;
7683d5c65159SKalle Valo 	const struct wmi_pdev_csa_switch_ev *ev;
7684d5c65159SKalle Valo 	const u32 *vdev_ids;
7685d5c65159SKalle Valo 	int ret;
7686d5c65159SKalle Valo 
7687d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7688d5c65159SKalle Valo 	if (IS_ERR(tb)) {
7689d5c65159SKalle Valo 		ret = PTR_ERR(tb);
7690d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7691d5c65159SKalle Valo 		return;
7692d5c65159SKalle Valo 	}
7693d5c65159SKalle Valo 
7694d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
7695d5c65159SKalle Valo 	vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
7696d5c65159SKalle Valo 
7697d5c65159SKalle Valo 	if (!ev || !vdev_ids) {
7698d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
7699d5c65159SKalle Valo 		kfree(tb);
7700d5c65159SKalle Valo 		return;
7701d5c65159SKalle Valo 	}
7702d5c65159SKalle Valo 
7703d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7704d5c65159SKalle Valo 		   "pdev csa switch count %d for pdev %d, num_vdevs %d",
7705d5c65159SKalle Valo 		   ev->current_switch_count, ev->pdev_id,
7706d5c65159SKalle Valo 		   ev->num_vdevs);
7707d5c65159SKalle Valo 
7708d5c65159SKalle Valo 	ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
7709d5c65159SKalle Valo 
7710d5c65159SKalle Valo 	kfree(tb);
7711d5c65159SKalle Valo }
7712d5c65159SKalle Valo 
7713d5c65159SKalle Valo static void
7714d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
7715d5c65159SKalle Valo {
7716d5c65159SKalle Valo 	const void **tb;
7717d5c65159SKalle Valo 	const struct wmi_pdev_radar_ev *ev;
7718d5c65159SKalle Valo 	struct ath11k *ar;
7719d5c65159SKalle Valo 	int ret;
7720d5c65159SKalle Valo 
7721d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7722d5c65159SKalle Valo 	if (IS_ERR(tb)) {
7723d5c65159SKalle Valo 		ret = PTR_ERR(tb);
7724d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7725d5c65159SKalle Valo 		return;
7726d5c65159SKalle Valo 	}
7727d5c65159SKalle Valo 
7728d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
7729d5c65159SKalle Valo 
7730d5c65159SKalle Valo 	if (!ev) {
7731d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
7732d5c65159SKalle Valo 		kfree(tb);
7733d5c65159SKalle Valo 		return;
7734d5c65159SKalle Valo 	}
7735d5c65159SKalle Valo 
7736d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7737d5c65159SKalle 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",
7738d5c65159SKalle Valo 		   ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
7739d5c65159SKalle Valo 		   ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
7740d5c65159SKalle Valo 		   ev->freq_offset, ev->sidx);
7741d5c65159SKalle Valo 
7742d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
7743d5c65159SKalle Valo 
7744d5c65159SKalle Valo 	if (!ar) {
7745d5c65159SKalle Valo 		ath11k_warn(ab, "radar detected in invalid pdev %d\n",
7746d5c65159SKalle Valo 			    ev->pdev_id);
7747d5c65159SKalle Valo 		goto exit;
7748d5c65159SKalle Valo 	}
7749d5c65159SKalle Valo 
7750d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
7751d5c65159SKalle Valo 		   ev->pdev_id);
7752d5c65159SKalle Valo 
7753d5c65159SKalle Valo 	if (ar->dfs_block_radar_events)
7754d5c65159SKalle Valo 		ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
7755d5c65159SKalle Valo 	else
7756d5c65159SKalle Valo 		ieee80211_radar_detected(ar->hw);
7757d5c65159SKalle Valo 
7758d5c65159SKalle Valo exit:
7759d5c65159SKalle Valo 	kfree(tb);
7760d5c65159SKalle Valo }
7761d5c65159SKalle Valo 
7762a41d1034SPradeep Kumar Chitrapu static void
7763a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
7764a41d1034SPradeep Kumar Chitrapu 				  struct sk_buff *skb)
7765a41d1034SPradeep Kumar Chitrapu {
7766a41d1034SPradeep Kumar Chitrapu 	struct ath11k *ar;
7767e3de5bb7SPradeep Kumar Chitrapu 	const void **tb;
7768e3de5bb7SPradeep Kumar Chitrapu 	const struct wmi_pdev_temperature_event *ev;
7769e3de5bb7SPradeep Kumar Chitrapu 	int ret;
7770a41d1034SPradeep Kumar Chitrapu 
7771e3de5bb7SPradeep Kumar Chitrapu 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7772e3de5bb7SPradeep Kumar Chitrapu 	if (IS_ERR(tb)) {
7773e3de5bb7SPradeep Kumar Chitrapu 		ret = PTR_ERR(tb);
7774e3de5bb7SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7775e3de5bb7SPradeep Kumar Chitrapu 		return;
7776e3de5bb7SPradeep Kumar Chitrapu 	}
7777e3de5bb7SPradeep Kumar Chitrapu 
7778e3de5bb7SPradeep Kumar Chitrapu 	ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
7779e3de5bb7SPradeep Kumar Chitrapu 	if (!ev) {
7780e3de5bb7SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to fetch pdev temp ev");
7781e3de5bb7SPradeep Kumar Chitrapu 		kfree(tb);
7782a41d1034SPradeep Kumar Chitrapu 		return;
7783a41d1034SPradeep Kumar Chitrapu 	}
7784a41d1034SPradeep Kumar Chitrapu 
7785a41d1034SPradeep Kumar Chitrapu 	ath11k_dbg(ab, ATH11K_DBG_WMI,
7786e3de5bb7SPradeep Kumar Chitrapu 		   "pdev temperature ev temp %d pdev_id %d\n", ev->temp, ev->pdev_id);
7787a41d1034SPradeep Kumar Chitrapu 
7788e3de5bb7SPradeep Kumar Chitrapu 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
7789a41d1034SPradeep Kumar Chitrapu 	if (!ar) {
7790e3de5bb7SPradeep Kumar Chitrapu 		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
7791e3de5bb7SPradeep Kumar Chitrapu 		kfree(tb);
7792a41d1034SPradeep Kumar Chitrapu 		return;
7793a41d1034SPradeep Kumar Chitrapu 	}
7794a41d1034SPradeep Kumar Chitrapu 
7795e3de5bb7SPradeep Kumar Chitrapu 	ath11k_thermal_event_temperature(ar, ev->temp);
7796e3de5bb7SPradeep Kumar Chitrapu 
7797e3de5bb7SPradeep Kumar Chitrapu 	kfree(tb);
7798a41d1034SPradeep Kumar Chitrapu }
7799a41d1034SPradeep Kumar Chitrapu 
7800047679e3SAloka Dixit static void ath11k_fils_discovery_event(struct ath11k_base *ab,
7801047679e3SAloka Dixit 					struct sk_buff *skb)
7802047679e3SAloka Dixit {
7803047679e3SAloka Dixit 	const void **tb;
7804047679e3SAloka Dixit 	const struct wmi_fils_discovery_event *ev;
7805047679e3SAloka Dixit 	int ret;
7806047679e3SAloka Dixit 
7807047679e3SAloka Dixit 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7808047679e3SAloka Dixit 	if (IS_ERR(tb)) {
7809047679e3SAloka Dixit 		ret = PTR_ERR(tb);
7810047679e3SAloka Dixit 		ath11k_warn(ab,
7811047679e3SAloka Dixit 			    "failed to parse FILS discovery event tlv %d\n",
7812047679e3SAloka Dixit 			    ret);
7813047679e3SAloka Dixit 		return;
7814047679e3SAloka Dixit 	}
7815047679e3SAloka Dixit 
7816047679e3SAloka Dixit 	ev = tb[WMI_TAG_HOST_SWFDA_EVENT];
7817047679e3SAloka Dixit 	if (!ev) {
7818047679e3SAloka Dixit 		ath11k_warn(ab, "failed to fetch FILS discovery event\n");
7819047679e3SAloka Dixit 		kfree(tb);
7820047679e3SAloka Dixit 		return;
7821047679e3SAloka Dixit 	}
7822047679e3SAloka Dixit 
7823047679e3SAloka Dixit 	ath11k_warn(ab,
7824047679e3SAloka Dixit 		    "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n",
7825047679e3SAloka Dixit 		    ev->vdev_id, ev->fils_tt, ev->tbtt);
7826047679e3SAloka Dixit 
7827047679e3SAloka Dixit 	kfree(tb);
7828047679e3SAloka Dixit }
7829047679e3SAloka Dixit 
7830047679e3SAloka Dixit static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab,
7831047679e3SAloka Dixit 					      struct sk_buff *skb)
7832047679e3SAloka Dixit {
7833047679e3SAloka Dixit 	const void **tb;
7834047679e3SAloka Dixit 	const struct wmi_probe_resp_tx_status_event *ev;
7835047679e3SAloka Dixit 	int ret;
7836047679e3SAloka Dixit 
7837047679e3SAloka Dixit 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7838047679e3SAloka Dixit 	if (IS_ERR(tb)) {
7839047679e3SAloka Dixit 		ret = PTR_ERR(tb);
7840047679e3SAloka Dixit 		ath11k_warn(ab,
7841047679e3SAloka Dixit 			    "failed to parse probe response transmission status event tlv: %d\n",
7842047679e3SAloka Dixit 			    ret);
7843047679e3SAloka Dixit 		return;
7844047679e3SAloka Dixit 	}
7845047679e3SAloka Dixit 
7846047679e3SAloka Dixit 	ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT];
7847047679e3SAloka Dixit 	if (!ev) {
7848047679e3SAloka Dixit 		ath11k_warn(ab,
7849047679e3SAloka Dixit 			    "failed to fetch probe response transmission status event");
7850047679e3SAloka Dixit 		kfree(tb);
7851047679e3SAloka Dixit 		return;
7852047679e3SAloka Dixit 	}
7853047679e3SAloka Dixit 
7854047679e3SAloka Dixit 	if (ev->tx_status)
7855047679e3SAloka Dixit 		ath11k_warn(ab,
7856047679e3SAloka Dixit 			    "Probe response transmission failed for vdev_id %u, status %u\n",
7857047679e3SAloka Dixit 			    ev->vdev_id, ev->tx_status);
7858047679e3SAloka Dixit 
7859047679e3SAloka Dixit 	kfree(tb);
7860047679e3SAloka Dixit }
7861047679e3SAloka Dixit 
786279802b13SCarl Huang static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab,
786379802b13SCarl Huang 						u16 tag, u16 len,
786479802b13SCarl Huang 						const void *ptr, void *data)
786579802b13SCarl Huang {
786679802b13SCarl Huang 	struct wmi_wow_ev_arg *ev = data;
786779802b13SCarl Huang 	const char *wow_pg_fault;
786879802b13SCarl Huang 	int wow_pg_len;
786979802b13SCarl Huang 
787079802b13SCarl Huang 	switch (tag) {
787179802b13SCarl Huang 	case WMI_TAG_WOW_EVENT_INFO:
787279802b13SCarl Huang 		memcpy(ev, ptr, sizeof(*ev));
787379802b13SCarl Huang 		ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n",
787479802b13SCarl Huang 			   ev->wake_reason, wow_reason(ev->wake_reason));
787579802b13SCarl Huang 		break;
787679802b13SCarl Huang 
787779802b13SCarl Huang 	case WMI_TAG_ARRAY_BYTE:
787879802b13SCarl Huang 		if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) {
787979802b13SCarl Huang 			wow_pg_fault = ptr;
788079802b13SCarl Huang 			/* the first 4 bytes are length */
788179802b13SCarl Huang 			wow_pg_len = *(int *)wow_pg_fault;
788279802b13SCarl Huang 			wow_pg_fault += sizeof(int);
788379802b13SCarl Huang 			ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n",
788479802b13SCarl Huang 				   wow_pg_len);
788579802b13SCarl Huang 			ath11k_dbg_dump(ab, ATH11K_DBG_WMI,
788679802b13SCarl Huang 					"wow_event_info_type packet present",
788779802b13SCarl Huang 					"wow_pg_fault ",
788879802b13SCarl Huang 					wow_pg_fault,
788979802b13SCarl Huang 					wow_pg_len);
789079802b13SCarl Huang 		}
789179802b13SCarl Huang 		break;
789279802b13SCarl Huang 	default:
789379802b13SCarl Huang 		break;
789479802b13SCarl Huang 	}
789579802b13SCarl Huang 
789679802b13SCarl Huang 	return 0;
789779802b13SCarl Huang }
789879802b13SCarl Huang 
789979802b13SCarl Huang static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb)
790079802b13SCarl Huang {
790179802b13SCarl Huang 	struct wmi_wow_ev_arg ev = { };
790279802b13SCarl Huang 	int ret;
790379802b13SCarl Huang 
790479802b13SCarl Huang 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
790579802b13SCarl Huang 				  ath11k_wmi_tlv_wow_wakeup_host_parse,
790679802b13SCarl Huang 				  &ev);
790779802b13SCarl Huang 	if (ret) {
790879802b13SCarl Huang 		ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret);
790979802b13SCarl Huang 		return;
791079802b13SCarl Huang 	}
791179802b13SCarl Huang 
791279802b13SCarl Huang 	complete(&ab->wow.wakeup_completed);
791379802b13SCarl Huang }
791479802b13SCarl Huang 
791542da1cc7SCheng Wang static void
791642da1cc7SCheng Wang ath11k_wmi_diag_event(struct ath11k_base *ab,
791742da1cc7SCheng Wang 		      struct sk_buff *skb)
791842da1cc7SCheng Wang {
791942da1cc7SCheng Wang 	trace_ath11k_wmi_diag(ab, skb->data, skb->len);
792042da1cc7SCheng Wang }
792142da1cc7SCheng Wang 
79223d00e8b5SJohn Crispin static const char *ath11k_wmi_twt_add_dialog_event_status(u32 status)
79233d00e8b5SJohn Crispin {
79243d00e8b5SJohn Crispin 	switch (status) {
79253d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_OK:
79263d00e8b5SJohn Crispin 		return "ok";
79273d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
79283d00e8b5SJohn Crispin 		return "twt disabled";
79293d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
79303d00e8b5SJohn Crispin 		return "dialog id in use";
79313d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_INVALID_PARAM:
79323d00e8b5SJohn Crispin 		return "invalid parameters";
79333d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NOT_READY:
79343d00e8b5SJohn Crispin 		return "not ready";
79353d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NO_RESOURCE:
79363d00e8b5SJohn Crispin 		return "resource unavailable";
79373d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NO_ACK:
79383d00e8b5SJohn Crispin 		return "no ack";
79393d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_NO_RESPONSE:
79403d00e8b5SJohn Crispin 		return "no response";
79413d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_DENIED:
79423d00e8b5SJohn Crispin 		return "denied";
79433d00e8b5SJohn Crispin 	case WMI_ADD_TWT_STATUS_UNKNOWN_ERROR:
79443d00e8b5SJohn Crispin 		fallthrough;
79453d00e8b5SJohn Crispin 	default:
79463d00e8b5SJohn Crispin 		return "unknown error";
79473d00e8b5SJohn Crispin 	}
79483d00e8b5SJohn Crispin }
79493d00e8b5SJohn Crispin 
79503d00e8b5SJohn Crispin static void ath11k_wmi_twt_add_dialog_event(struct ath11k_base *ab,
79513d00e8b5SJohn Crispin 					    struct sk_buff *skb)
79523d00e8b5SJohn Crispin {
79533d00e8b5SJohn Crispin 	const void **tb;
79543d00e8b5SJohn Crispin 	const struct wmi_twt_add_dialog_event *ev;
79553d00e8b5SJohn Crispin 	int ret;
79563d00e8b5SJohn Crispin 
79573d00e8b5SJohn Crispin 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
79583d00e8b5SJohn Crispin 	if (IS_ERR(tb)) {
79593d00e8b5SJohn Crispin 		ret = PTR_ERR(tb);
79603d00e8b5SJohn Crispin 		ath11k_warn(ab,
79613d00e8b5SJohn Crispin 			    "failed to parse wmi twt add dialog status event tlv: %d\n",
79623d00e8b5SJohn Crispin 			    ret);
79633d00e8b5SJohn Crispin 		return;
79643d00e8b5SJohn Crispin 	}
79653d00e8b5SJohn Crispin 
79663d00e8b5SJohn Crispin 	ev = tb[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT];
79673d00e8b5SJohn Crispin 	if (!ev) {
79683d00e8b5SJohn Crispin 		ath11k_warn(ab, "failed to fetch twt add dialog wmi event\n");
79693d00e8b5SJohn Crispin 		goto exit;
79703d00e8b5SJohn Crispin 	}
79713d00e8b5SJohn Crispin 
79723d00e8b5SJohn Crispin 	if (ev->status)
79733d00e8b5SJohn Crispin 		ath11k_warn(ab,
79743d00e8b5SJohn Crispin 			    "wmi add twt dialog event vdev %d dialog id %d status %s\n",
79753d00e8b5SJohn Crispin 			    ev->vdev_id, ev->dialog_id,
79763d00e8b5SJohn Crispin 			    ath11k_wmi_twt_add_dialog_event_status(ev->status));
79773d00e8b5SJohn Crispin 
79783d00e8b5SJohn Crispin exit:
79793d00e8b5SJohn Crispin 	kfree(tb);
79803d00e8b5SJohn Crispin }
79813d00e8b5SJohn Crispin 
7982a16d9b50SCarl Huang static void ath11k_wmi_gtk_offload_status_event(struct ath11k_base *ab,
7983a16d9b50SCarl Huang 						struct sk_buff *skb)
7984a16d9b50SCarl Huang {
7985a16d9b50SCarl Huang 	const void **tb;
7986a16d9b50SCarl Huang 	const struct wmi_gtk_offload_status_event *ev;
7987a16d9b50SCarl Huang 	struct ath11k_vif *arvif;
7988a16d9b50SCarl Huang 	__be64 replay_ctr_be;
7989a16d9b50SCarl Huang 	u64    replay_ctr;
7990a16d9b50SCarl Huang 	int ret;
7991a16d9b50SCarl Huang 
7992a16d9b50SCarl Huang 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7993a16d9b50SCarl Huang 	if (IS_ERR(tb)) {
7994a16d9b50SCarl Huang 		ret = PTR_ERR(tb);
7995a16d9b50SCarl Huang 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7996a16d9b50SCarl Huang 		return;
7997a16d9b50SCarl Huang 	}
7998a16d9b50SCarl Huang 
7999a16d9b50SCarl Huang 	ev = tb[WMI_TAG_GTK_OFFLOAD_STATUS_EVENT];
8000a16d9b50SCarl Huang 	if (!ev) {
8001a16d9b50SCarl Huang 		ath11k_warn(ab, "failed to fetch gtk offload status ev");
8002a16d9b50SCarl Huang 		kfree(tb);
8003a16d9b50SCarl Huang 		return;
8004a16d9b50SCarl Huang 	}
8005a16d9b50SCarl Huang 
8006a16d9b50SCarl Huang 	arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
8007a16d9b50SCarl Huang 	if (!arvif) {
8008a16d9b50SCarl Huang 		ath11k_warn(ab, "failed to get arvif for vdev_id:%d\n",
8009a16d9b50SCarl Huang 			    ev->vdev_id);
8010a16d9b50SCarl Huang 		kfree(tb);
8011a16d9b50SCarl Huang 		return;
8012a16d9b50SCarl Huang 	}
8013a16d9b50SCarl Huang 
8014a16d9b50SCarl Huang 	ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi gtk offload event refresh_cnt %d\n",
8015a16d9b50SCarl Huang 		   ev->refresh_cnt);
8016a16d9b50SCarl Huang 	ath11k_dbg_dump(ab, ATH11K_DBG_WMI, "replay_cnt",
8017a16d9b50SCarl Huang 			NULL, ev->replay_ctr.counter, GTK_REPLAY_COUNTER_BYTES);
8018a16d9b50SCarl Huang 
8019a16d9b50SCarl Huang 	replay_ctr =  ev->replay_ctr.word1;
8020a16d9b50SCarl Huang 	replay_ctr = (replay_ctr << 32) | ev->replay_ctr.word0;
8021a16d9b50SCarl Huang 	arvif->rekey_data.replay_ctr = replay_ctr;
8022a16d9b50SCarl Huang 
8023a16d9b50SCarl Huang 	/* supplicant expects big-endian replay counter */
8024a16d9b50SCarl Huang 	replay_ctr_be = cpu_to_be64(replay_ctr);
8025a16d9b50SCarl Huang 
8026a16d9b50SCarl Huang 	ieee80211_gtk_rekey_notify(arvif->vif, arvif->bssid,
8027eee645ecSBaochen Qiang 				   (void *)&replay_ctr_be, GFP_ATOMIC);
8028a16d9b50SCarl Huang 
8029a16d9b50SCarl Huang 	kfree(tb);
8030a16d9b50SCarl Huang }
8031a16d9b50SCarl Huang 
8032d5c65159SKalle Valo static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
8033d5c65159SKalle Valo {
8034d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
8035d5c65159SKalle Valo 	enum wmi_tlv_event_id id;
8036d5c65159SKalle Valo 
8037d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
8038d5c65159SKalle Valo 	id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
8039d5c65159SKalle Valo 
8040fb12305aSVenkateswara Naralasetty 	trace_ath11k_wmi_event(ab, id, skb->data, skb->len);
8041fb12305aSVenkateswara Naralasetty 
8042d5c65159SKalle Valo 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
8043d5c65159SKalle Valo 		goto out;
8044d5c65159SKalle Valo 
8045d5c65159SKalle Valo 	switch (id) {
8046d5c65159SKalle Valo 		/* Process all the WMI events here */
8047d5c65159SKalle Valo 	case WMI_SERVICE_READY_EVENTID:
8048d5c65159SKalle Valo 		ath11k_service_ready_event(ab, skb);
8049d5c65159SKalle Valo 		break;
8050d5c65159SKalle Valo 	case WMI_SERVICE_READY_EXT_EVENTID:
8051d5c65159SKalle Valo 		ath11k_service_ready_ext_event(ab, skb);
8052d5c65159SKalle Valo 		break;
8053bd647855SKarthikeyan Periyasamy 	case WMI_SERVICE_READY_EXT2_EVENTID:
8054bd647855SKarthikeyan Periyasamy 		ath11k_service_ready_ext2_event(ab, skb);
8055bd647855SKarthikeyan Periyasamy 		break;
8056d5c65159SKalle Valo 	case WMI_REG_CHAN_LIST_CC_EVENTID:
8057d5c65159SKalle Valo 		ath11k_reg_chan_list_event(ab, skb);
8058d5c65159SKalle Valo 		break;
8059d5c65159SKalle Valo 	case WMI_READY_EVENTID:
8060d5c65159SKalle Valo 		ath11k_ready_event(ab, skb);
8061d5c65159SKalle Valo 		break;
8062d5c65159SKalle Valo 	case WMI_PEER_DELETE_RESP_EVENTID:
8063d5c65159SKalle Valo 		ath11k_peer_delete_resp_event(ab, skb);
8064d5c65159SKalle Valo 		break;
8065d5c65159SKalle Valo 	case WMI_VDEV_START_RESP_EVENTID:
8066d5c65159SKalle Valo 		ath11k_vdev_start_resp_event(ab, skb);
8067d5c65159SKalle Valo 		break;
8068d5c65159SKalle Valo 	case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
8069d5c65159SKalle Valo 		ath11k_bcn_tx_status_event(ab, skb);
8070d5c65159SKalle Valo 		break;
8071d5c65159SKalle Valo 	case WMI_VDEV_STOPPED_EVENTID:
8072d5c65159SKalle Valo 		ath11k_vdev_stopped_event(ab, skb);
8073d5c65159SKalle Valo 		break;
8074d5c65159SKalle Valo 	case WMI_MGMT_RX_EVENTID:
8075d5c65159SKalle Valo 		ath11k_mgmt_rx_event(ab, skb);
8076d5c65159SKalle Valo 		/* mgmt_rx_event() owns the skb now! */
8077d5c65159SKalle Valo 		return;
8078d5c65159SKalle Valo 	case WMI_MGMT_TX_COMPLETION_EVENTID:
8079d5c65159SKalle Valo 		ath11k_mgmt_tx_compl_event(ab, skb);
8080d5c65159SKalle Valo 		break;
8081d5c65159SKalle Valo 	case WMI_SCAN_EVENTID:
8082d5c65159SKalle Valo 		ath11k_scan_event(ab, skb);
8083d5c65159SKalle Valo 		break;
8084d5c65159SKalle Valo 	case WMI_PEER_STA_KICKOUT_EVENTID:
8085d5c65159SKalle Valo 		ath11k_peer_sta_kickout_event(ab, skb);
8086d5c65159SKalle Valo 		break;
8087d5c65159SKalle Valo 	case WMI_ROAM_EVENTID:
8088d5c65159SKalle Valo 		ath11k_roam_event(ab, skb);
8089d5c65159SKalle Valo 		break;
8090d5c65159SKalle Valo 	case WMI_CHAN_INFO_EVENTID:
8091d5c65159SKalle Valo 		ath11k_chan_info_event(ab, skb);
8092d5c65159SKalle Valo 		break;
8093d5c65159SKalle Valo 	case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
8094d5c65159SKalle Valo 		ath11k_pdev_bss_chan_info_event(ab, skb);
8095d5c65159SKalle Valo 		break;
8096d5c65159SKalle Valo 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
8097d5c65159SKalle Valo 		ath11k_vdev_install_key_compl_event(ab, skb);
8098d5c65159SKalle Valo 		break;
8099d5c65159SKalle Valo 	case WMI_SERVICE_AVAILABLE_EVENTID:
8100d5c65159SKalle Valo 		ath11k_service_available_event(ab, skb);
8101d5c65159SKalle Valo 		break;
8102d5c65159SKalle Valo 	case WMI_PEER_ASSOC_CONF_EVENTID:
8103d5c65159SKalle Valo 		ath11k_peer_assoc_conf_event(ab, skb);
8104d5c65159SKalle Valo 		break;
8105d5c65159SKalle Valo 	case WMI_UPDATE_STATS_EVENTID:
8106d5c65159SKalle Valo 		ath11k_update_stats_event(ab, skb);
8107d5c65159SKalle Valo 		break;
8108d5c65159SKalle Valo 	case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
8109d5c65159SKalle Valo 		ath11k_pdev_ctl_failsafe_check_event(ab, skb);
8110d5c65159SKalle Valo 		break;
8111d5c65159SKalle Valo 	case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
8112d5c65159SKalle Valo 		ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
8113d5c65159SKalle Valo 		break;
8114a41d1034SPradeep Kumar Chitrapu 	case WMI_PDEV_TEMPERATURE_EVENTID:
8115a41d1034SPradeep Kumar Chitrapu 		ath11k_wmi_pdev_temperature_event(ab, skb);
8116a41d1034SPradeep Kumar Chitrapu 		break;
81179d11b7bfSKarthikeyan Periyasamy 	case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
81189d11b7bfSKarthikeyan Periyasamy 		ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
81199d11b7bfSKarthikeyan Periyasamy 		break;
8120047679e3SAloka Dixit 	case WMI_HOST_FILS_DISCOVERY_EVENTID:
8121047679e3SAloka Dixit 		ath11k_fils_discovery_event(ab, skb);
8122047679e3SAloka Dixit 		break;
8123047679e3SAloka Dixit 	case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID:
8124047679e3SAloka Dixit 		ath11k_probe_resp_tx_status_event(ab, skb);
8125047679e3SAloka Dixit 		break;
8126886433a9SJohn Crispin 	case WMI_OBSS_COLOR_COLLISION_DETECTION_EVENTID:
8127886433a9SJohn Crispin 		ath11k_wmi_obss_color_collision_event(ab, skb);
8128886433a9SJohn Crispin 		break;
81293d00e8b5SJohn Crispin 	case WMI_TWT_ADD_DIALOG_EVENTID:
81303d00e8b5SJohn Crispin 		ath11k_wmi_twt_add_dialog_event(ab, skb);
81313d00e8b5SJohn Crispin 		break;
8132d5c65159SKalle Valo 	/* add Unsupported events here */
8133d5c65159SKalle Valo 	case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID:
81349cfbae46SJohn Crispin 	case WMI_PEER_OPER_MODE_CHANGE_EVENTID:
81356d293d44SJohn Crispin 	case WMI_TWT_ENABLE_EVENTID:
81366d293d44SJohn Crispin 	case WMI_TWT_DISABLE_EVENTID:
81373d00e8b5SJohn Crispin 	case WMI_TWT_DEL_DIALOG_EVENTID:
81383d00e8b5SJohn Crispin 	case WMI_TWT_PAUSE_DIALOG_EVENTID:
81393d00e8b5SJohn Crispin 	case WMI_TWT_RESUME_DIALOG_EVENTID:
81409d11b7bfSKarthikeyan Periyasamy 	case WMI_PDEV_DMA_RING_CFG_RSP_EVENTID:
814194a6df31SP Praneesh 	case WMI_PEER_CREATE_CONF_EVENTID:
8142d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
8143d5c65159SKalle Valo 			   "ignoring unsupported event 0x%x\n", id);
8144d5c65159SKalle Valo 		break;
8145d5c65159SKalle Valo 	case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
8146d5c65159SKalle Valo 		ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
8147d5c65159SKalle Valo 		break;
81483cbbdfbeSRitesh Singh 	case WMI_VDEV_DELETE_RESP_EVENTID:
81493cbbdfbeSRitesh Singh 		ath11k_vdev_delete_resp_event(ab, skb);
81503cbbdfbeSRitesh Singh 		break;
815179802b13SCarl Huang 	case WMI_WOW_WAKEUP_HOST_EVENTID:
815279802b13SCarl Huang 		ath11k_wmi_event_wow_wakeup_host(ab, skb);
815379802b13SCarl Huang 		break;
81549dcf6808SWen Gong 	case WMI_11D_NEW_COUNTRY_EVENTID:
81559dcf6808SWen Gong 		ath11k_reg_11d_new_cc_event(ab, skb);
81569dcf6808SWen Gong 		break;
815742da1cc7SCheng Wang 	case WMI_DIAG_EVENTID:
815842da1cc7SCheng Wang 		ath11k_wmi_diag_event(ab, skb);
815942da1cc7SCheng Wang 		break;
8160710a95f9SVenkateswara Naralasetty 	case WMI_PEER_STA_PS_STATECHG_EVENTID:
8161710a95f9SVenkateswara Naralasetty 		ath11k_wmi_event_peer_sta_ps_state_chg(ab, skb);
8162710a95f9SVenkateswara Naralasetty 		break;
8163a16d9b50SCarl Huang 	case WMI_GTK_OFFLOAD_STATUS_EVENTID:
8164a16d9b50SCarl Huang 		ath11k_wmi_gtk_offload_status_event(ab, skb);
8165a16d9b50SCarl Huang 		break;
8166d5c65159SKalle Valo 	/* TODO: Add remaining events */
8167d5c65159SKalle Valo 	default:
816882b4f9b8SGovind Singh 		ath11k_dbg(ab, ATH11K_DBG_WMI, "Unknown eventid: 0x%x\n", id);
8169d5c65159SKalle Valo 		break;
8170d5c65159SKalle Valo 	}
8171d5c65159SKalle Valo 
8172d5c65159SKalle Valo out:
8173d5c65159SKalle Valo 	dev_kfree_skb(skb);
8174d5c65159SKalle Valo }
8175d5c65159SKalle Valo 
8176d5c65159SKalle Valo static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
8177d5c65159SKalle Valo 					   u32 pdev_idx)
8178d5c65159SKalle Valo {
8179d5c65159SKalle Valo 	int status;
8180d5c65159SKalle Valo 	u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
8181d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
8182d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
8183d5c65159SKalle Valo 
8184d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_req conn_req;
8185d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_resp conn_resp;
8186d5c65159SKalle Valo 
8187d5c65159SKalle Valo 	memset(&conn_req, 0, sizeof(conn_req));
8188d5c65159SKalle Valo 	memset(&conn_resp, 0, sizeof(conn_resp));
8189d5c65159SKalle Valo 
8190d5c65159SKalle Valo 	/* these fields are the same for all service endpoints */
8191d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
8192d5c65159SKalle Valo 	conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
8193d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
8194d5c65159SKalle Valo 
8195d5c65159SKalle Valo 	/* connect to control service */
8196d5c65159SKalle Valo 	conn_req.service_id = svc_id[pdev_idx];
8197d5c65159SKalle Valo 
8198d5c65159SKalle Valo 	status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
8199d5c65159SKalle Valo 	if (status) {
8200d5c65159SKalle Valo 		ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
8201d5c65159SKalle Valo 			    status);
8202d5c65159SKalle Valo 		return status;
8203d5c65159SKalle Valo 	}
8204d5c65159SKalle Valo 
82056bc9d6f7SJohn Crispin 	ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
82066bc9d6f7SJohn Crispin 	ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
82076bc9d6f7SJohn Crispin 	ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
8208f951380aSP Praneesh 	init_waitqueue_head(&ab->wmi_ab.wmi[pdev_idx].tx_ce_desc_wq);
8209d5c65159SKalle Valo 
8210d5c65159SKalle Valo 	return 0;
8211d5c65159SKalle Valo }
8212d5c65159SKalle Valo 
8213d5c65159SKalle Valo static int
8214d5c65159SKalle Valo ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
8215d5c65159SKalle Valo 			      struct wmi_unit_test_cmd ut_cmd,
8216d5c65159SKalle Valo 			      u32 *test_args)
8217d5c65159SKalle Valo {
8218d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8219d5c65159SKalle Valo 	struct wmi_unit_test_cmd *cmd;
8220d5c65159SKalle Valo 	struct sk_buff *skb;
8221d5c65159SKalle Valo 	struct wmi_tlv *tlv;
8222d5c65159SKalle Valo 	void *ptr;
8223d5c65159SKalle Valo 	u32 *ut_cmd_args;
8224d5c65159SKalle Valo 	int buf_len, arg_len;
8225d5c65159SKalle Valo 	int ret;
8226d5c65159SKalle Valo 	int i;
8227d5c65159SKalle Valo 
8228d5c65159SKalle Valo 	arg_len = sizeof(u32) * ut_cmd.num_args;
8229d5c65159SKalle Valo 	buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
8230d5c65159SKalle Valo 
82316bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
8232d5c65159SKalle Valo 	if (!skb)
8233d5c65159SKalle Valo 		return -ENOMEM;
8234d5c65159SKalle Valo 
8235d5c65159SKalle Valo 	cmd = (struct wmi_unit_test_cmd *)skb->data;
8236d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
8237d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
8238d5c65159SKalle Valo 
8239d5c65159SKalle Valo 	cmd->vdev_id = ut_cmd.vdev_id;
8240d5c65159SKalle Valo 	cmd->module_id = ut_cmd.module_id;
8241d5c65159SKalle Valo 	cmd->num_args = ut_cmd.num_args;
8242d5c65159SKalle Valo 	cmd->diag_token = ut_cmd.diag_token;
8243d5c65159SKalle Valo 
8244d5c65159SKalle Valo 	ptr = skb->data + sizeof(ut_cmd);
8245d5c65159SKalle Valo 
8246d5c65159SKalle Valo 	tlv = ptr;
8247d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8248d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, arg_len);
8249d5c65159SKalle Valo 
8250d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
8251d5c65159SKalle Valo 
8252d5c65159SKalle Valo 	ut_cmd_args = ptr;
8253d5c65159SKalle Valo 	for (i = 0; i < ut_cmd.num_args; i++)
8254d5c65159SKalle Valo 		ut_cmd_args[i] = test_args[i];
8255d5c65159SKalle Valo 
8256d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
8257d5c65159SKalle Valo 
8258d5c65159SKalle Valo 	if (ret) {
8259d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
8260d5c65159SKalle Valo 			    ret);
8261d5c65159SKalle Valo 		dev_kfree_skb(skb);
8262d5c65159SKalle Valo 	}
8263d5c65159SKalle Valo 
8264d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8265d5c65159SKalle Valo 		   "WMI unit test : module %d vdev %d n_args %d token %d\n",
8266d5c65159SKalle Valo 		   cmd->module_id, cmd->vdev_id, cmd->num_args,
8267d5c65159SKalle Valo 		   cmd->diag_token);
8268d5c65159SKalle Valo 
8269d5c65159SKalle Valo 	return ret;
8270d5c65159SKalle Valo }
8271d5c65159SKalle Valo 
8272d5c65159SKalle Valo int ath11k_wmi_simulate_radar(struct ath11k *ar)
8273d5c65159SKalle Valo {
8274d5c65159SKalle Valo 	struct ath11k_vif *arvif;
8275d5c65159SKalle Valo 	u32 dfs_args[DFS_MAX_TEST_ARGS];
8276d5c65159SKalle Valo 	struct wmi_unit_test_cmd wmi_ut;
8277d5c65159SKalle Valo 	bool arvif_found = false;
8278d5c65159SKalle Valo 
8279d5c65159SKalle Valo 	list_for_each_entry(arvif, &ar->arvifs, list) {
8280d5c65159SKalle Valo 		if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
8281d5c65159SKalle Valo 			arvif_found = true;
8282d5c65159SKalle Valo 			break;
8283d5c65159SKalle Valo 		}
8284d5c65159SKalle Valo 	}
8285d5c65159SKalle Valo 
8286d5c65159SKalle Valo 	if (!arvif_found)
8287d5c65159SKalle Valo 		return -EINVAL;
8288d5c65159SKalle Valo 
8289d5c65159SKalle Valo 	dfs_args[DFS_TEST_CMDID] = 0;
8290d5c65159SKalle Valo 	dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
8291d5c65159SKalle Valo 	/* Currently we could pass segment_id(b0 - b1), chirp(b2)
8292d5c65159SKalle Valo 	 * freq offset (b3 - b10) to unit test. For simulation
8293d5c65159SKalle Valo 	 * purpose this can be set to 0 which is valid.
8294d5c65159SKalle Valo 	 */
8295d5c65159SKalle Valo 	dfs_args[DFS_TEST_RADAR_PARAM] = 0;
8296d5c65159SKalle Valo 
8297d5c65159SKalle Valo 	wmi_ut.vdev_id = arvif->vdev_id;
8298d5c65159SKalle Valo 	wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
8299d5c65159SKalle Valo 	wmi_ut.num_args = DFS_MAX_TEST_ARGS;
8300d5c65159SKalle Valo 	wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
8301d5c65159SKalle Valo 
8302d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
8303d5c65159SKalle Valo 
8304d5c65159SKalle Valo 	return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
8305d5c65159SKalle Valo }
8306d5c65159SKalle Valo 
8307f295ad91SSeevalamuthu Mariappan int ath11k_wmi_fw_dbglog_cfg(struct ath11k *ar, u32 *module_id_bitmap,
8308f295ad91SSeevalamuthu Mariappan 			     struct ath11k_fw_dbglog *dbglog)
8309f295ad91SSeevalamuthu Mariappan {
8310f295ad91SSeevalamuthu Mariappan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
8311f295ad91SSeevalamuthu Mariappan 	struct wmi_debug_log_config_cmd_fixed_param *cmd;
8312f295ad91SSeevalamuthu Mariappan 	struct sk_buff *skb;
8313f295ad91SSeevalamuthu Mariappan 	struct wmi_tlv *tlv;
8314f295ad91SSeevalamuthu Mariappan 	int ret, len;
8315f295ad91SSeevalamuthu Mariappan 
8316f295ad91SSeevalamuthu Mariappan 	len = sizeof(*cmd) + TLV_HDR_SIZE + (MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8317f295ad91SSeevalamuthu Mariappan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8318f295ad91SSeevalamuthu Mariappan 	if (!skb)
8319f295ad91SSeevalamuthu Mariappan 		return -ENOMEM;
8320f295ad91SSeevalamuthu Mariappan 
8321f295ad91SSeevalamuthu Mariappan 	cmd = (struct wmi_debug_log_config_cmd_fixed_param *)skb->data;
8322f295ad91SSeevalamuthu Mariappan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DEBUG_LOG_CONFIG_CMD) |
8323f295ad91SSeevalamuthu Mariappan 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8324f295ad91SSeevalamuthu Mariappan 	cmd->dbg_log_param = dbglog->param;
8325f295ad91SSeevalamuthu Mariappan 
8326f295ad91SSeevalamuthu Mariappan 	tlv = (struct wmi_tlv *)((u8 *)cmd + sizeof(*cmd));
8327f295ad91SSeevalamuthu Mariappan 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8328f295ad91SSeevalamuthu Mariappan 		      FIELD_PREP(WMI_TLV_LEN, MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8329f295ad91SSeevalamuthu Mariappan 
8330f295ad91SSeevalamuthu Mariappan 	switch (dbglog->param) {
8331f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_LOG_LEVEL:
8332f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE:
8333f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_VDEV_DISABLE:
8334f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE_BITMAP:
8335f295ad91SSeevalamuthu Mariappan 		cmd->value = dbglog->value;
8336f295ad91SSeevalamuthu Mariappan 		break;
8337f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_MOD_ENABLE_BITMAP:
8338f295ad91SSeevalamuthu Mariappan 	case WMI_DEBUG_LOG_PARAM_WOW_MOD_ENABLE_BITMAP:
8339f295ad91SSeevalamuthu Mariappan 		cmd->value = dbglog->value;
8340f295ad91SSeevalamuthu Mariappan 		memcpy(tlv->value, module_id_bitmap,
8341f295ad91SSeevalamuthu Mariappan 		       MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8342f295ad91SSeevalamuthu Mariappan 		/* clear current config to be used for next user config */
8343f295ad91SSeevalamuthu Mariappan 		memset(module_id_bitmap, 0,
8344f295ad91SSeevalamuthu Mariappan 		       MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8345f295ad91SSeevalamuthu Mariappan 		break;
8346f295ad91SSeevalamuthu Mariappan 	default:
8347f295ad91SSeevalamuthu Mariappan 		dev_kfree_skb(skb);
8348f295ad91SSeevalamuthu Mariappan 		return -EINVAL;
8349f295ad91SSeevalamuthu Mariappan 	}
8350f295ad91SSeevalamuthu Mariappan 
8351f295ad91SSeevalamuthu Mariappan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DBGLOG_CFG_CMDID);
8352f295ad91SSeevalamuthu Mariappan 	if (ret) {
8353f295ad91SSeevalamuthu Mariappan 		ath11k_warn(ar->ab,
8354f295ad91SSeevalamuthu Mariappan 			    "failed to send WMI_DBGLOG_CFG_CMDID\n");
8355f295ad91SSeevalamuthu Mariappan 		dev_kfree_skb(skb);
8356f295ad91SSeevalamuthu Mariappan 	}
8357f295ad91SSeevalamuthu Mariappan 	return ret;
8358f295ad91SSeevalamuthu Mariappan }
8359f295ad91SSeevalamuthu Mariappan 
8360d5c65159SKalle Valo int ath11k_wmi_connect(struct ath11k_base *ab)
8361d5c65159SKalle Valo {
8362d5c65159SKalle Valo 	u32 i;
8363d5c65159SKalle Valo 	u8 wmi_ep_count;
8364d5c65159SKalle Valo 
8365d5c65159SKalle Valo 	wmi_ep_count = ab->htc.wmi_ep_count;
8366b1cc29e9SAnilkumar Kolli 	if (wmi_ep_count > ab->hw_params.max_radios)
8367d5c65159SKalle Valo 		return -1;
8368d5c65159SKalle Valo 
8369d5c65159SKalle Valo 	for (i = 0; i < wmi_ep_count; i++)
8370d5c65159SKalle Valo 		ath11k_connect_pdev_htc_service(ab, i);
8371d5c65159SKalle Valo 
8372d5c65159SKalle Valo 	return 0;
8373d5c65159SKalle Valo }
8374d5c65159SKalle Valo 
8375d5c65159SKalle Valo static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
8376d5c65159SKalle Valo {
8377d5c65159SKalle Valo 	if (WARN_ON(pdev_id >= MAX_RADIOS))
8378d5c65159SKalle Valo 		return;
8379d5c65159SKalle Valo 
8380d5c65159SKalle Valo 	/* TODO: Deinit any pdev specific wmi resource */
8381d5c65159SKalle Valo }
8382d5c65159SKalle Valo 
8383d5c65159SKalle Valo int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
8384d5c65159SKalle Valo 			   u8 pdev_id)
8385d5c65159SKalle Valo {
8386d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle;
8387d5c65159SKalle Valo 
8388b1cc29e9SAnilkumar Kolli 	if (pdev_id >= ab->hw_params.max_radios)
8389d5c65159SKalle Valo 		return -EINVAL;
8390d5c65159SKalle Valo 
83916bc9d6f7SJohn Crispin 	wmi_handle = &ab->wmi_ab.wmi[pdev_id];
8392d5c65159SKalle Valo 
83936bc9d6f7SJohn Crispin 	wmi_handle->wmi_ab = &ab->wmi_ab;
8394d5c65159SKalle Valo 
83956bc9d6f7SJohn Crispin 	ab->wmi_ab.ab = ab;
8396d5c65159SKalle Valo 	/* TODO: Init remaining resource specific to pdev */
8397d5c65159SKalle Valo 
8398d5c65159SKalle Valo 	return 0;
8399d5c65159SKalle Valo }
8400d5c65159SKalle Valo 
8401d5c65159SKalle Valo int ath11k_wmi_attach(struct ath11k_base *ab)
8402d5c65159SKalle Valo {
8403d5c65159SKalle Valo 	int ret;
8404d5c65159SKalle Valo 
8405d5c65159SKalle Valo 	ret = ath11k_wmi_pdev_attach(ab, 0);
8406d5c65159SKalle Valo 	if (ret)
8407d5c65159SKalle Valo 		return ret;
8408d5c65159SKalle Valo 
84096bc9d6f7SJohn Crispin 	ab->wmi_ab.ab = ab;
84106bc9d6f7SJohn Crispin 	ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
8411d5c65159SKalle Valo 
84125f859bc0SCarl Huang 	/* It's overwritten when service_ext_ready is handled */
8413b6f63010SManikanta Pubbisetty 	if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1)
84145f859bc0SCarl Huang 		ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
84155f859bc0SCarl Huang 
8416d5c65159SKalle Valo 	/* TODO: Init remaining wmi soc resources required */
84176bc9d6f7SJohn Crispin 	init_completion(&ab->wmi_ab.service_ready);
84186bc9d6f7SJohn Crispin 	init_completion(&ab->wmi_ab.unified_ready);
8419d5c65159SKalle Valo 
8420d5c65159SKalle Valo 	return 0;
8421d5c65159SKalle Valo }
8422d5c65159SKalle Valo 
8423d5c65159SKalle Valo void ath11k_wmi_detach(struct ath11k_base *ab)
8424d5c65159SKalle Valo {
8425d5c65159SKalle Valo 	int i;
8426d5c65159SKalle Valo 
8427d5c65159SKalle Valo 	/* TODO: Deinit wmi resource specific to SOC as required */
8428d5c65159SKalle Valo 
8429d5c65159SKalle Valo 	for (i = 0; i < ab->htc.wmi_ep_count; i++)
8430d5c65159SKalle Valo 		ath11k_wmi_pdev_detach(ab, i);
8431bd647855SKarthikeyan Periyasamy 
8432bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
8433d5c65159SKalle Valo }
843479802b13SCarl Huang 
8435c417b247SCarl Huang int ath11k_wmi_hw_data_filter_cmd(struct ath11k *ar, u32 vdev_id,
8436c417b247SCarl Huang 				  u32 filter_bitmap, bool enable)
8437c417b247SCarl Huang {
8438c417b247SCarl Huang 	struct wmi_hw_data_filter_cmd *cmd;
8439c417b247SCarl Huang 	struct sk_buff *skb;
8440c417b247SCarl Huang 	int len;
8441c417b247SCarl Huang 
8442c417b247SCarl Huang 	len = sizeof(*cmd);
8443c417b247SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8444c417b247SCarl Huang 
8445c417b247SCarl Huang 	if (!skb)
8446c417b247SCarl Huang 		return -ENOMEM;
8447c417b247SCarl Huang 
8448c417b247SCarl Huang 	cmd = (struct wmi_hw_data_filter_cmd *)skb->data;
8449c417b247SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_HW_DATA_FILTER_CMD) |
8450c417b247SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8451c417b247SCarl Huang 
8452c417b247SCarl Huang 	cmd->vdev_id = vdev_id;
8453c417b247SCarl Huang 	cmd->enable = enable;
8454c417b247SCarl Huang 
8455c417b247SCarl Huang 	/* Set all modes in case of disable */
8456c417b247SCarl Huang 	if (cmd->enable)
8457c417b247SCarl Huang 		cmd->hw_filter_bitmap = filter_bitmap;
8458c417b247SCarl Huang 	else
8459c417b247SCarl Huang 		cmd->hw_filter_bitmap = ((u32)~0U);
8460c417b247SCarl Huang 
8461c417b247SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8462c417b247SCarl Huang 		   "wmi hw data filter enable %d filter_bitmap 0x%x\n",
8463c417b247SCarl Huang 		   enable, filter_bitmap);
8464c417b247SCarl Huang 
8465c417b247SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_HW_DATA_FILTER_CMDID);
8466c417b247SCarl Huang }
8467c417b247SCarl Huang 
846879802b13SCarl Huang int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar)
846979802b13SCarl Huang {
847079802b13SCarl Huang 	struct wmi_wow_host_wakeup_ind *cmd;
847179802b13SCarl Huang 	struct sk_buff *skb;
847279802b13SCarl Huang 	size_t len;
847379802b13SCarl Huang 
847479802b13SCarl Huang 	len = sizeof(*cmd);
847579802b13SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
847679802b13SCarl Huang 	if (!skb)
847779802b13SCarl Huang 		return -ENOMEM;
847879802b13SCarl Huang 
847979802b13SCarl Huang 	cmd = (struct wmi_wow_host_wakeup_ind *)skb->data;
848079802b13SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
848179802b13SCarl Huang 				     WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) |
848279802b13SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
848379802b13SCarl Huang 
848479802b13SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow host wakeup ind\n");
848579802b13SCarl Huang 
848679802b13SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
848779802b13SCarl Huang }
848879802b13SCarl Huang 
848979802b13SCarl Huang int ath11k_wmi_wow_enable(struct ath11k *ar)
849079802b13SCarl Huang {
849179802b13SCarl Huang 	struct wmi_wow_enable_cmd *cmd;
849279802b13SCarl Huang 	struct sk_buff *skb;
849379802b13SCarl Huang 	int len;
849479802b13SCarl Huang 
849579802b13SCarl Huang 	len = sizeof(*cmd);
849679802b13SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
849779802b13SCarl Huang 	if (!skb)
849879802b13SCarl Huang 		return -ENOMEM;
849979802b13SCarl Huang 
850079802b13SCarl Huang 	cmd = (struct wmi_wow_enable_cmd *)skb->data;
850179802b13SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) |
850279802b13SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
850379802b13SCarl Huang 
850479802b13SCarl Huang 	cmd->enable = 1;
850579802b13SCarl Huang 	cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
850679802b13SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow enable\n");
850779802b13SCarl Huang 
850879802b13SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID);
850979802b13SCarl Huang }
85109cbd7fc9SCarl Huang 
85119cbd7fc9SCarl Huang int ath11k_wmi_scan_prob_req_oui(struct ath11k *ar,
85129cbd7fc9SCarl Huang 				 const u8 mac_addr[ETH_ALEN])
85139cbd7fc9SCarl Huang {
85149cbd7fc9SCarl Huang 	struct sk_buff *skb;
85159cbd7fc9SCarl Huang 	struct wmi_scan_prob_req_oui_cmd *cmd;
85169cbd7fc9SCarl Huang 	u32 prob_req_oui;
85179cbd7fc9SCarl Huang 	int len;
85189cbd7fc9SCarl Huang 
85199cbd7fc9SCarl Huang 	prob_req_oui = (((u32)mac_addr[0]) << 16) |
85209cbd7fc9SCarl Huang 		       (((u32)mac_addr[1]) << 8) | mac_addr[2];
85219cbd7fc9SCarl Huang 
85229cbd7fc9SCarl Huang 	len = sizeof(*cmd);
85239cbd7fc9SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
85249cbd7fc9SCarl Huang 	if (!skb)
85259cbd7fc9SCarl Huang 		return -ENOMEM;
85269cbd7fc9SCarl Huang 
85279cbd7fc9SCarl Huang 	cmd = (struct wmi_scan_prob_req_oui_cmd *)skb->data;
85289cbd7fc9SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
85299cbd7fc9SCarl Huang 				     WMI_TAG_SCAN_PROB_REQ_OUI_CMD) |
85309cbd7fc9SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
85319cbd7fc9SCarl Huang 	cmd->prob_req_oui = prob_req_oui;
85329cbd7fc9SCarl Huang 
85339cbd7fc9SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi scan prob req oui %d\n",
85349cbd7fc9SCarl Huang 		   prob_req_oui);
85359cbd7fc9SCarl Huang 
85369cbd7fc9SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SCAN_PROB_REQ_OUI_CMDID);
85379cbd7fc9SCarl Huang }
8538ba9177fcSCarl Huang 
8539ba9177fcSCarl Huang int ath11k_wmi_wow_add_wakeup_event(struct ath11k *ar, u32 vdev_id,
8540ba9177fcSCarl Huang 				    enum wmi_wow_wakeup_event event,
8541ba9177fcSCarl Huang 				u32 enable)
8542ba9177fcSCarl Huang {
8543ba9177fcSCarl Huang 	struct wmi_wow_add_del_event_cmd *cmd;
8544ba9177fcSCarl Huang 	struct sk_buff *skb;
8545ba9177fcSCarl Huang 	size_t len;
8546ba9177fcSCarl Huang 
8547ba9177fcSCarl Huang 	len = sizeof(*cmd);
8548ba9177fcSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8549ba9177fcSCarl Huang 	if (!skb)
8550ba9177fcSCarl Huang 		return -ENOMEM;
8551ba9177fcSCarl Huang 
8552ba9177fcSCarl Huang 	cmd = (struct wmi_wow_add_del_event_cmd *)skb->data;
8553ba9177fcSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ADD_DEL_EVT_CMD) |
8554ba9177fcSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8555ba9177fcSCarl Huang 
8556ba9177fcSCarl Huang 	cmd->vdev_id = vdev_id;
8557ba9177fcSCarl Huang 	cmd->is_add = enable;
8558ba9177fcSCarl Huang 	cmd->event_bitmap = (1 << event);
8559ba9177fcSCarl Huang 
8560ba9177fcSCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow add wakeup event %s enable %d vdev_id %d\n",
8561ba9177fcSCarl Huang 		   wow_wakeup_event(event), enable, vdev_id);
8562ba9177fcSCarl Huang 
8563ba9177fcSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
8564ba9177fcSCarl Huang }
8565ba9177fcSCarl Huang 
8566ba9177fcSCarl Huang int ath11k_wmi_wow_add_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id,
8567ba9177fcSCarl Huang 			       const u8 *pattern, const u8 *mask,
8568ba9177fcSCarl Huang 			   int pattern_len, int pattern_offset)
8569ba9177fcSCarl Huang {
8570ba9177fcSCarl Huang 	struct wmi_wow_add_pattern_cmd *cmd;
8571ba9177fcSCarl Huang 	struct wmi_wow_bitmap_pattern *bitmap;
8572ba9177fcSCarl Huang 	struct wmi_tlv *tlv;
8573ba9177fcSCarl Huang 	struct sk_buff *skb;
8574ba9177fcSCarl Huang 	u8 *ptr;
8575ba9177fcSCarl Huang 	size_t len;
8576ba9177fcSCarl Huang 
8577ba9177fcSCarl Huang 	len = sizeof(*cmd) +
8578ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* array struct */
8579ba9177fcSCarl Huang 	      sizeof(*bitmap) +			/* bitmap */
8580ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty ipv4 sync */
8581ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty ipv6 sync */
8582ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty magic */
8583ba9177fcSCarl Huang 	      sizeof(*tlv) +			/* empty info timeout */
8584ba9177fcSCarl Huang 	      sizeof(*tlv) + sizeof(u32);	/* ratelimit interval */
8585ba9177fcSCarl Huang 
8586ba9177fcSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8587ba9177fcSCarl Huang 	if (!skb)
8588ba9177fcSCarl Huang 		return -ENOMEM;
8589ba9177fcSCarl Huang 
8590ba9177fcSCarl Huang 	/* cmd */
8591ba9177fcSCarl Huang 	ptr = (u8 *)skb->data;
8592ba9177fcSCarl Huang 	cmd = (struct wmi_wow_add_pattern_cmd *)ptr;
8593ba9177fcSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8594ba9177fcSCarl Huang 				     WMI_TAG_WOW_ADD_PATTERN_CMD) |
8595ba9177fcSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8596ba9177fcSCarl Huang 
8597ba9177fcSCarl Huang 	cmd->vdev_id = vdev_id;
8598ba9177fcSCarl Huang 	cmd->pattern_id = pattern_id;
8599ba9177fcSCarl Huang 	cmd->pattern_type = WOW_BITMAP_PATTERN;
8600ba9177fcSCarl Huang 
8601ba9177fcSCarl Huang 	ptr += sizeof(*cmd);
8602ba9177fcSCarl Huang 
8603ba9177fcSCarl Huang 	/* bitmap */
8604ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8605ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8606ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8607ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap));
8608ba9177fcSCarl Huang 
8609ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8610ba9177fcSCarl Huang 
8611ba9177fcSCarl Huang 	bitmap = (struct wmi_wow_bitmap_pattern *)ptr;
8612ba9177fcSCarl Huang 	bitmap->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8613ba9177fcSCarl Huang 					WMI_TAG_WOW_BITMAP_PATTERN_T) |
8614ba9177fcSCarl Huang 			     FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap) - TLV_HDR_SIZE);
8615ba9177fcSCarl Huang 
8616ba9177fcSCarl Huang 	memcpy(bitmap->patternbuf, pattern, pattern_len);
8617ba9177fcSCarl Huang 	ath11k_ce_byte_swap(bitmap->patternbuf, roundup(pattern_len, 4));
8618ba9177fcSCarl Huang 	memcpy(bitmap->bitmaskbuf, mask, pattern_len);
8619ba9177fcSCarl Huang 	ath11k_ce_byte_swap(bitmap->bitmaskbuf, roundup(pattern_len, 4));
8620ba9177fcSCarl Huang 	bitmap->pattern_offset = pattern_offset;
8621ba9177fcSCarl Huang 	bitmap->pattern_len = pattern_len;
8622ba9177fcSCarl Huang 	bitmap->bitmask_len = pattern_len;
8623ba9177fcSCarl Huang 	bitmap->pattern_id = pattern_id;
8624ba9177fcSCarl Huang 
8625ba9177fcSCarl Huang 	ptr += sizeof(*bitmap);
8626ba9177fcSCarl Huang 
8627ba9177fcSCarl Huang 	/* ipv4 sync */
8628ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8629ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8630ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8631ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8632ba9177fcSCarl Huang 
8633ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8634ba9177fcSCarl Huang 
8635ba9177fcSCarl Huang 	/* ipv6 sync */
8636ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8637ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8638ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8639ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8640ba9177fcSCarl Huang 
8641ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8642ba9177fcSCarl Huang 
8643ba9177fcSCarl Huang 	/* magic */
8644ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8645ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8646ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8647ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8648ba9177fcSCarl Huang 
8649ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8650ba9177fcSCarl Huang 
8651ba9177fcSCarl Huang 	/* pattern info timeout */
8652ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8653ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8654ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_UINT32) |
8655ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, 0);
8656ba9177fcSCarl Huang 
8657ba9177fcSCarl Huang 	ptr += sizeof(*tlv);
8658ba9177fcSCarl Huang 
8659ba9177fcSCarl Huang 	/* ratelimit interval */
8660ba9177fcSCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8661ba9177fcSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8662ba9177fcSCarl Huang 				 WMI_TAG_ARRAY_UINT32) |
8663ba9177fcSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, sizeof(u32));
8664ba9177fcSCarl Huang 
8665ba9177fcSCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow add pattern vdev_id %d pattern_id %d pattern_offset %d\n",
8666ba9177fcSCarl Huang 		   vdev_id, pattern_id, pattern_offset);
8667ba9177fcSCarl Huang 
8668ba9177fcSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ADD_WAKE_PATTERN_CMDID);
8669ba9177fcSCarl Huang }
8670ba9177fcSCarl Huang 
8671ba9177fcSCarl Huang int ath11k_wmi_wow_del_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id)
8672ba9177fcSCarl Huang {
8673ba9177fcSCarl Huang 	struct wmi_wow_del_pattern_cmd *cmd;
8674ba9177fcSCarl Huang 	struct sk_buff *skb;
8675ba9177fcSCarl Huang 	size_t len;
8676ba9177fcSCarl Huang 
8677ba9177fcSCarl Huang 	len = sizeof(*cmd);
8678ba9177fcSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8679ba9177fcSCarl Huang 	if (!skb)
8680ba9177fcSCarl Huang 		return -ENOMEM;
8681ba9177fcSCarl Huang 
8682ba9177fcSCarl Huang 	cmd = (struct wmi_wow_del_pattern_cmd *)skb->data;
8683ba9177fcSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8684ba9177fcSCarl Huang 				     WMI_TAG_WOW_DEL_PATTERN_CMD) |
8685ba9177fcSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8686ba9177fcSCarl Huang 
8687ba9177fcSCarl Huang 	cmd->vdev_id = vdev_id;
8688ba9177fcSCarl Huang 	cmd->pattern_id = pattern_id;
8689ba9177fcSCarl Huang 	cmd->pattern_type = WOW_BITMAP_PATTERN;
8690ba9177fcSCarl Huang 
8691ba9177fcSCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow del pattern vdev_id %d pattern_id %d\n",
8692ba9177fcSCarl Huang 		   vdev_id, pattern_id);
8693ba9177fcSCarl Huang 
8694ba9177fcSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_DEL_WAKE_PATTERN_CMDID);
8695ba9177fcSCarl Huang }
8696fec4b898SCarl Huang 
8697fec4b898SCarl Huang static struct sk_buff *
8698fec4b898SCarl Huang ath11k_wmi_op_gen_config_pno_start(struct ath11k *ar,
8699fec4b898SCarl Huang 				   u32 vdev_id,
8700fec4b898SCarl Huang 				       struct wmi_pno_scan_req *pno)
8701fec4b898SCarl Huang {
8702fec4b898SCarl Huang 	struct nlo_configured_parameters *nlo_list;
8703fec4b898SCarl Huang 	struct wmi_wow_nlo_config_cmd *cmd;
8704fec4b898SCarl Huang 	struct wmi_tlv *tlv;
8705fec4b898SCarl Huang 	struct sk_buff *skb;
8706fec4b898SCarl Huang 	u32 *channel_list;
8707fec4b898SCarl Huang 	size_t len, nlo_list_len, channel_list_len;
8708fec4b898SCarl Huang 	u8 *ptr;
8709fec4b898SCarl Huang 	u32 i;
8710fec4b898SCarl Huang 
8711fec4b898SCarl Huang 	len = sizeof(*cmd) +
8712fec4b898SCarl Huang 	      sizeof(*tlv) +
8713fec4b898SCarl Huang 	      /* TLV place holder for array of structures
8714fec4b898SCarl Huang 	       * nlo_configured_parameters(nlo_list)
8715fec4b898SCarl Huang 	       */
8716fec4b898SCarl Huang 	      sizeof(*tlv);
8717fec4b898SCarl Huang 	      /* TLV place holder for array of uint32 channel_list */
8718fec4b898SCarl Huang 
8719fec4b898SCarl Huang 	channel_list_len = sizeof(u32) * pno->a_networks[0].channel_count;
8720fec4b898SCarl Huang 	len += channel_list_len;
8721fec4b898SCarl Huang 
8722fec4b898SCarl Huang 	nlo_list_len = sizeof(*nlo_list) * pno->uc_networks_count;
8723fec4b898SCarl Huang 	len += nlo_list_len;
8724fec4b898SCarl Huang 
8725fec4b898SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8726fec4b898SCarl Huang 	if (!skb)
8727fec4b898SCarl Huang 		return ERR_PTR(-ENOMEM);
8728fec4b898SCarl Huang 
8729fec4b898SCarl Huang 	ptr = (u8 *)skb->data;
8730fec4b898SCarl Huang 	cmd = (struct wmi_wow_nlo_config_cmd *)ptr;
8731fec4b898SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
8732fec4b898SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8733fec4b898SCarl Huang 
8734fec4b898SCarl Huang 	cmd->vdev_id = pno->vdev_id;
8735fec4b898SCarl Huang 	cmd->flags = WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN;
8736fec4b898SCarl Huang 
8737fec4b898SCarl Huang 	/* current FW does not support min-max range for dwell time */
8738fec4b898SCarl Huang 	cmd->active_dwell_time = pno->active_max_time;
8739fec4b898SCarl Huang 	cmd->passive_dwell_time = pno->passive_max_time;
8740fec4b898SCarl Huang 
8741fec4b898SCarl Huang 	if (pno->do_passive_scan)
8742fec4b898SCarl Huang 		cmd->flags |= WMI_NLO_CONFIG_SCAN_PASSIVE;
8743fec4b898SCarl Huang 
8744fec4b898SCarl Huang 	cmd->fast_scan_period = pno->fast_scan_period;
8745fec4b898SCarl Huang 	cmd->slow_scan_period = pno->slow_scan_period;
8746fec4b898SCarl Huang 	cmd->fast_scan_max_cycles = pno->fast_scan_max_cycles;
8747fec4b898SCarl Huang 	cmd->delay_start_time = pno->delay_start_time;
8748fec4b898SCarl Huang 
8749fec4b898SCarl Huang 	if (pno->enable_pno_scan_randomization) {
8750fec4b898SCarl Huang 		cmd->flags |= WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
8751fec4b898SCarl Huang 				WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ;
8752fec4b898SCarl Huang 		ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
8753fec4b898SCarl Huang 		ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
8754fec4b898SCarl Huang 		ath11k_ce_byte_swap(cmd->mac_addr.addr, 8);
8755fec4b898SCarl Huang 		ath11k_ce_byte_swap(cmd->mac_mask.addr, 8);
8756fec4b898SCarl Huang 	}
8757fec4b898SCarl Huang 
8758fec4b898SCarl Huang 	ptr += sizeof(*cmd);
8759fec4b898SCarl Huang 
8760fec4b898SCarl Huang 	/* nlo_configured_parameters(nlo_list) */
8761fec4b898SCarl Huang 	cmd->no_of_ssids = pno->uc_networks_count;
8762fec4b898SCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8763fec4b898SCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG,
8764fec4b898SCarl Huang 				 WMI_TAG_ARRAY_STRUCT) |
8765fec4b898SCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, nlo_list_len);
8766fec4b898SCarl Huang 
8767fec4b898SCarl Huang 	ptr += sizeof(*tlv);
8768fec4b898SCarl Huang 	nlo_list = (struct nlo_configured_parameters *)ptr;
8769fec4b898SCarl Huang 	for (i = 0; i < cmd->no_of_ssids; i++) {
8770fec4b898SCarl Huang 		tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
8771fec4b898SCarl Huang 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8772fec4b898SCarl Huang 			      FIELD_PREP(WMI_TLV_LEN, sizeof(*nlo_list) - sizeof(*tlv));
8773fec4b898SCarl Huang 
8774fec4b898SCarl Huang 		nlo_list[i].ssid.valid = true;
8775fec4b898SCarl Huang 		nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
8776fec4b898SCarl Huang 		memcpy(nlo_list[i].ssid.ssid.ssid,
8777fec4b898SCarl Huang 		       pno->a_networks[i].ssid.ssid,
8778fec4b898SCarl Huang 		       nlo_list[i].ssid.ssid.ssid_len);
8779fec4b898SCarl Huang 		ath11k_ce_byte_swap(nlo_list[i].ssid.ssid.ssid,
8780fec4b898SCarl Huang 				    roundup(nlo_list[i].ssid.ssid.ssid_len, 4));
8781fec4b898SCarl Huang 
8782fec4b898SCarl Huang 		if (pno->a_networks[i].rssi_threshold &&
8783fec4b898SCarl Huang 		    pno->a_networks[i].rssi_threshold > -300) {
8784fec4b898SCarl Huang 			nlo_list[i].rssi_cond.valid = true;
8785fec4b898SCarl Huang 			nlo_list[i].rssi_cond.rssi =
8786fec4b898SCarl Huang 				pno->a_networks[i].rssi_threshold;
8787fec4b898SCarl Huang 		}
8788fec4b898SCarl Huang 
8789fec4b898SCarl Huang 		nlo_list[i].bcast_nw_type.valid = true;
8790fec4b898SCarl Huang 		nlo_list[i].bcast_nw_type.bcast_nw_type =
8791fec4b898SCarl Huang 			pno->a_networks[i].bcast_nw_type;
8792fec4b898SCarl Huang 	}
8793fec4b898SCarl Huang 
8794fec4b898SCarl Huang 	ptr += nlo_list_len;
8795fec4b898SCarl Huang 	cmd->num_of_channels = pno->a_networks[0].channel_count;
8796fec4b898SCarl Huang 	tlv = (struct wmi_tlv *)ptr;
8797fec4b898SCarl Huang 	tlv->header =  FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8798fec4b898SCarl Huang 		       FIELD_PREP(WMI_TLV_LEN, channel_list_len);
8799fec4b898SCarl Huang 	ptr += sizeof(*tlv);
8800fec4b898SCarl Huang 	channel_list = (u32 *)ptr;
8801fec4b898SCarl Huang 	for (i = 0; i < cmd->num_of_channels; i++)
8802fec4b898SCarl Huang 		channel_list[i] = pno->a_networks[0].channels[i];
8803fec4b898SCarl Huang 
8804fec4b898SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv start pno config vdev_id %d\n",
8805fec4b898SCarl Huang 		   vdev_id);
8806fec4b898SCarl Huang 
8807fec4b898SCarl Huang 	return skb;
8808fec4b898SCarl Huang }
8809fec4b898SCarl Huang 
8810fec4b898SCarl Huang static struct sk_buff *ath11k_wmi_op_gen_config_pno_stop(struct ath11k *ar,
8811fec4b898SCarl Huang 							 u32 vdev_id)
8812fec4b898SCarl Huang {
8813fec4b898SCarl Huang 	struct wmi_wow_nlo_config_cmd *cmd;
8814fec4b898SCarl Huang 	struct sk_buff *skb;
8815fec4b898SCarl Huang 	size_t len;
8816fec4b898SCarl Huang 
8817fec4b898SCarl Huang 	len = sizeof(*cmd);
8818fec4b898SCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8819fec4b898SCarl Huang 	if (!skb)
8820fec4b898SCarl Huang 		return ERR_PTR(-ENOMEM);
8821fec4b898SCarl Huang 
8822fec4b898SCarl Huang 	cmd = (struct wmi_wow_nlo_config_cmd *)skb->data;
8823fec4b898SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
8824fec4b898SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
8825fec4b898SCarl Huang 
8826fec4b898SCarl Huang 	cmd->vdev_id = vdev_id;
8827fec4b898SCarl Huang 	cmd->flags = WMI_NLO_CONFIG_STOP;
8828fec4b898SCarl Huang 
8829fec4b898SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8830fec4b898SCarl Huang 		   "wmi tlv stop pno config vdev_id %d\n", vdev_id);
8831fec4b898SCarl Huang 	return skb;
8832fec4b898SCarl Huang }
8833fec4b898SCarl Huang 
8834fec4b898SCarl Huang int ath11k_wmi_wow_config_pno(struct ath11k *ar, u32 vdev_id,
8835fec4b898SCarl Huang 			      struct wmi_pno_scan_req  *pno_scan)
8836fec4b898SCarl Huang {
8837fec4b898SCarl Huang 	struct sk_buff *skb;
8838fec4b898SCarl Huang 
8839fec4b898SCarl Huang 	if (pno_scan->enable)
8840fec4b898SCarl Huang 		skb = ath11k_wmi_op_gen_config_pno_start(ar, vdev_id, pno_scan);
8841fec4b898SCarl Huang 	else
8842fec4b898SCarl Huang 		skb = ath11k_wmi_op_gen_config_pno_stop(ar, vdev_id);
8843fec4b898SCarl Huang 
8844fec4b898SCarl Huang 	if (IS_ERR_OR_NULL(skb))
8845fec4b898SCarl Huang 		return -ENOMEM;
8846fec4b898SCarl Huang 
8847fec4b898SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
8848fec4b898SCarl Huang }
8849fec4b898SCarl Huang 
8850c3c36bfeSCarl Huang static void ath11k_wmi_fill_ns_offload(struct ath11k *ar,
8851c3c36bfeSCarl Huang 				       struct ath11k_arp_ns_offload *offload,
8852c3c36bfeSCarl Huang 				       u8 **ptr,
8853c3c36bfeSCarl Huang 				       bool enable,
8854c3c36bfeSCarl Huang 				       bool ext)
8855c3c36bfeSCarl Huang {
8856c3c36bfeSCarl Huang 	struct wmi_ns_offload_tuple *ns;
8857c3c36bfeSCarl Huang 	struct wmi_tlv *tlv;
8858c3c36bfeSCarl Huang 	u8 *buf_ptr = *ptr;
8859c3c36bfeSCarl Huang 	u32 ns_cnt, ns_ext_tuples;
8860c3c36bfeSCarl Huang 	int i, max_offloads;
8861c3c36bfeSCarl Huang 
8862c3c36bfeSCarl Huang 	ns_cnt = offload->ipv6_count;
8863c3c36bfeSCarl Huang 
8864c3c36bfeSCarl Huang 	tlv  = (struct wmi_tlv *)buf_ptr;
8865c3c36bfeSCarl Huang 
8866c3c36bfeSCarl Huang 	if (ext) {
8867c3c36bfeSCarl Huang 		ns_ext_tuples = offload->ipv6_count - WMI_MAX_NS_OFFLOADS;
8868c3c36bfeSCarl Huang 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8869c3c36bfeSCarl Huang 			      FIELD_PREP(WMI_TLV_LEN, ns_ext_tuples * sizeof(*ns));
8870c3c36bfeSCarl Huang 		i = WMI_MAX_NS_OFFLOADS;
8871c3c36bfeSCarl Huang 		max_offloads = offload->ipv6_count;
8872c3c36bfeSCarl Huang 	} else {
8873c3c36bfeSCarl Huang 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8874c3c36bfeSCarl Huang 			      FIELD_PREP(WMI_TLV_LEN, WMI_MAX_NS_OFFLOADS * sizeof(*ns));
8875c3c36bfeSCarl Huang 		i = 0;
8876c3c36bfeSCarl Huang 		max_offloads = WMI_MAX_NS_OFFLOADS;
8877c3c36bfeSCarl Huang 	}
8878c3c36bfeSCarl Huang 
8879c3c36bfeSCarl Huang 	buf_ptr += sizeof(*tlv);
8880c3c36bfeSCarl Huang 
8881c3c36bfeSCarl Huang 	for (; i < max_offloads; i++) {
8882c3c36bfeSCarl Huang 		ns = (struct wmi_ns_offload_tuple *)buf_ptr;
8883c3c36bfeSCarl Huang 		ns->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NS_OFFLOAD_TUPLE) |
8884c3c36bfeSCarl Huang 				 FIELD_PREP(WMI_TLV_LEN, sizeof(*ns) - TLV_HDR_SIZE);
8885c3c36bfeSCarl Huang 
8886c3c36bfeSCarl Huang 		if (enable) {
8887c3c36bfeSCarl Huang 			if (i < ns_cnt)
8888c3c36bfeSCarl Huang 				ns->flags |= WMI_NSOL_FLAGS_VALID;
8889c3c36bfeSCarl Huang 
8890c3c36bfeSCarl Huang 			memcpy(ns->target_ipaddr[0], offload->ipv6_addr[i], 16);
8891c3c36bfeSCarl Huang 			memcpy(ns->solicitation_ipaddr, offload->self_ipv6_addr[i], 16);
8892c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(ns->target_ipaddr[0], 16);
8893c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(ns->solicitation_ipaddr, 16);
8894c3c36bfeSCarl Huang 
8895c3c36bfeSCarl Huang 			if (offload->ipv6_type[i])
8896c3c36bfeSCarl Huang 				ns->flags |= WMI_NSOL_FLAGS_IS_IPV6_ANYCAST;
8897c3c36bfeSCarl Huang 
8898c3c36bfeSCarl Huang 			memcpy(ns->target_mac.addr, offload->mac_addr, ETH_ALEN);
8899c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(ns->target_mac.addr, 8);
8900c3c36bfeSCarl Huang 
8901c3c36bfeSCarl Huang 			if (ns->target_mac.word0 != 0 ||
8902c3c36bfeSCarl Huang 			    ns->target_mac.word1 != 0) {
8903c3c36bfeSCarl Huang 				ns->flags |= WMI_NSOL_FLAGS_MAC_VALID;
8904c3c36bfeSCarl Huang 			}
8905c3c36bfeSCarl Huang 
8906c3c36bfeSCarl Huang 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8907c3c36bfeSCarl Huang 				   "wmi index %d ns_solicited %pI6 target %pI6",
8908c3c36bfeSCarl Huang 				   i, ns->solicitation_ipaddr,
8909c3c36bfeSCarl Huang 				   ns->target_ipaddr[0]);
8910c3c36bfeSCarl Huang 		}
8911c3c36bfeSCarl Huang 
8912c3c36bfeSCarl Huang 		buf_ptr += sizeof(*ns);
8913c3c36bfeSCarl Huang 	}
8914c3c36bfeSCarl Huang 
8915c3c36bfeSCarl Huang 	*ptr = buf_ptr;
8916c3c36bfeSCarl Huang }
8917c3c36bfeSCarl Huang 
8918c3c36bfeSCarl Huang static void ath11k_wmi_fill_arp_offload(struct ath11k *ar,
8919c3c36bfeSCarl Huang 					struct ath11k_arp_ns_offload *offload,
8920c3c36bfeSCarl Huang 					u8 **ptr,
8921c3c36bfeSCarl Huang 					bool enable)
8922c3c36bfeSCarl Huang {
8923c3c36bfeSCarl Huang 	struct wmi_arp_offload_tuple *arp;
8924c3c36bfeSCarl Huang 	struct wmi_tlv *tlv;
8925c3c36bfeSCarl Huang 	u8 *buf_ptr = *ptr;
8926c3c36bfeSCarl Huang 	int i;
8927c3c36bfeSCarl Huang 
8928c3c36bfeSCarl Huang 	/* fill arp tuple */
8929c3c36bfeSCarl Huang 	tlv = (struct wmi_tlv *)buf_ptr;
8930c3c36bfeSCarl Huang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8931c3c36bfeSCarl Huang 		      FIELD_PREP(WMI_TLV_LEN, WMI_MAX_ARP_OFFLOADS * sizeof(*arp));
8932c3c36bfeSCarl Huang 	buf_ptr += sizeof(*tlv);
8933c3c36bfeSCarl Huang 
8934c3c36bfeSCarl Huang 	for (i = 0; i < WMI_MAX_ARP_OFFLOADS; i++) {
8935c3c36bfeSCarl Huang 		arp = (struct wmi_arp_offload_tuple *)buf_ptr;
8936c3c36bfeSCarl Huang 		arp->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARP_OFFLOAD_TUPLE) |
8937c3c36bfeSCarl Huang 				  FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
8938c3c36bfeSCarl Huang 
8939c3c36bfeSCarl Huang 		if (enable && i < offload->ipv4_count) {
8940c3c36bfeSCarl Huang 			/* Copy the target ip addr and flags */
8941c3c36bfeSCarl Huang 			arp->flags = WMI_ARPOL_FLAGS_VALID;
8942c3c36bfeSCarl Huang 			memcpy(arp->target_ipaddr, offload->ipv4_addr[i], 4);
8943c3c36bfeSCarl Huang 			ath11k_ce_byte_swap(arp->target_ipaddr, 4);
8944c3c36bfeSCarl Huang 
8945c3c36bfeSCarl Huang 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi arp offload address %pI4",
8946c3c36bfeSCarl Huang 				   arp->target_ipaddr);
8947c3c36bfeSCarl Huang 		}
8948c3c36bfeSCarl Huang 
8949c3c36bfeSCarl Huang 		buf_ptr += sizeof(*arp);
8950c3c36bfeSCarl Huang 	}
8951c3c36bfeSCarl Huang 
8952c3c36bfeSCarl Huang 	*ptr = buf_ptr;
8953c3c36bfeSCarl Huang }
8954c3c36bfeSCarl Huang 
8955c3c36bfeSCarl Huang int ath11k_wmi_arp_ns_offload(struct ath11k *ar,
8956c3c36bfeSCarl Huang 			      struct ath11k_vif *arvif, bool enable)
8957c3c36bfeSCarl Huang {
8958c3c36bfeSCarl Huang 	struct ath11k_arp_ns_offload *offload;
8959c3c36bfeSCarl Huang 	struct wmi_set_arp_ns_offload_cmd *cmd;
8960c3c36bfeSCarl Huang 	struct wmi_tlv *tlv;
8961c3c36bfeSCarl Huang 	struct sk_buff *skb;
8962c3c36bfeSCarl Huang 	u8 *buf_ptr;
8963c3c36bfeSCarl Huang 	size_t len;
8964c3c36bfeSCarl Huang 	u8 ns_cnt, ns_ext_tuples = 0;
8965c3c36bfeSCarl Huang 
8966c3c36bfeSCarl Huang 	offload = &arvif->arp_ns_offload;
8967c3c36bfeSCarl Huang 	ns_cnt = offload->ipv6_count;
8968c3c36bfeSCarl Huang 
8969c3c36bfeSCarl Huang 	len = sizeof(*cmd) +
8970c3c36bfeSCarl Huang 	      sizeof(*tlv) +
8971c3c36bfeSCarl Huang 	      WMI_MAX_NS_OFFLOADS * sizeof(struct wmi_ns_offload_tuple) +
8972c3c36bfeSCarl Huang 	      sizeof(*tlv) +
8973c3c36bfeSCarl Huang 	      WMI_MAX_ARP_OFFLOADS * sizeof(struct wmi_arp_offload_tuple);
8974c3c36bfeSCarl Huang 
8975c3c36bfeSCarl Huang 	if (ns_cnt > WMI_MAX_NS_OFFLOADS) {
8976c3c36bfeSCarl Huang 		ns_ext_tuples = ns_cnt - WMI_MAX_NS_OFFLOADS;
8977c3c36bfeSCarl Huang 		len += sizeof(*tlv) +
8978c3c36bfeSCarl Huang 		       ns_ext_tuples * sizeof(struct wmi_ns_offload_tuple);
8979c3c36bfeSCarl Huang 	}
8980c3c36bfeSCarl Huang 
8981c3c36bfeSCarl Huang 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8982c3c36bfeSCarl Huang 	if (!skb)
8983c3c36bfeSCarl Huang 		return -ENOMEM;
8984c3c36bfeSCarl Huang 
8985c3c36bfeSCarl Huang 	buf_ptr = skb->data;
8986c3c36bfeSCarl Huang 	cmd = (struct wmi_set_arp_ns_offload_cmd *)buf_ptr;
8987c3c36bfeSCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8988c3c36bfeSCarl Huang 				     WMI_TAG_SET_ARP_NS_OFFLOAD_CMD) |
8989c3c36bfeSCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8990c3c36bfeSCarl Huang 
8991c3c36bfeSCarl Huang 	cmd->flags = 0;
8992c3c36bfeSCarl Huang 	cmd->vdev_id = arvif->vdev_id;
8993c3c36bfeSCarl Huang 	cmd->num_ns_ext_tuples = ns_ext_tuples;
8994c3c36bfeSCarl Huang 
8995c3c36bfeSCarl Huang 	buf_ptr += sizeof(*cmd);
8996c3c36bfeSCarl Huang 
8997c3c36bfeSCarl Huang 	ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 0);
8998c3c36bfeSCarl Huang 	ath11k_wmi_fill_arp_offload(ar, offload, &buf_ptr, enable);
8999c3c36bfeSCarl Huang 
9000c3c36bfeSCarl Huang 	if (ns_ext_tuples)
9001c3c36bfeSCarl Huang 		ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 1);
9002c3c36bfeSCarl Huang 
9003c3c36bfeSCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SET_ARP_NS_OFFLOAD_CMDID);
9004c3c36bfeSCarl Huang }
9005a16d9b50SCarl Huang 
9006a16d9b50SCarl Huang int ath11k_wmi_gtk_rekey_offload(struct ath11k *ar,
9007a16d9b50SCarl Huang 				 struct ath11k_vif *arvif, bool enable)
9008a16d9b50SCarl Huang {
9009a16d9b50SCarl Huang 	struct wmi_gtk_rekey_offload_cmd *cmd;
9010a16d9b50SCarl Huang 	struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
9011a16d9b50SCarl Huang 	int len;
9012a16d9b50SCarl Huang 	struct sk_buff *skb;
9013a16d9b50SCarl Huang 	__le64 replay_ctr;
9014a16d9b50SCarl Huang 
9015a16d9b50SCarl Huang 	len = sizeof(*cmd);
9016a16d9b50SCarl Huang 	skb =  ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9017a16d9b50SCarl Huang 	if (!skb)
9018a16d9b50SCarl Huang 		return -ENOMEM;
9019a16d9b50SCarl Huang 
9020a16d9b50SCarl Huang 	cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9021a16d9b50SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9022a16d9b50SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9023a16d9b50SCarl Huang 
9024a16d9b50SCarl Huang 	cmd->vdev_id = arvif->vdev_id;
9025a16d9b50SCarl Huang 
9026a16d9b50SCarl Huang 	if (enable) {
9027a16d9b50SCarl Huang 		cmd->flags = GTK_OFFLOAD_ENABLE_OPCODE;
9028a16d9b50SCarl Huang 
9029a16d9b50SCarl Huang 		/* the length in rekey_data and cmd is equal */
9030a16d9b50SCarl Huang 		memcpy(cmd->kck, rekey_data->kck, sizeof(cmd->kck));
9031a16d9b50SCarl Huang 		ath11k_ce_byte_swap(cmd->kck, GTK_OFFLOAD_KEK_BYTES);
9032a16d9b50SCarl Huang 		memcpy(cmd->kek, rekey_data->kek, sizeof(cmd->kek));
9033a16d9b50SCarl Huang 		ath11k_ce_byte_swap(cmd->kek, GTK_OFFLOAD_KEK_BYTES);
9034a16d9b50SCarl Huang 
9035a16d9b50SCarl Huang 		replay_ctr = cpu_to_le64(rekey_data->replay_ctr);
9036a16d9b50SCarl Huang 		memcpy(cmd->replay_ctr, &replay_ctr,
9037a16d9b50SCarl Huang 		       sizeof(replay_ctr));
9038a16d9b50SCarl Huang 		ath11k_ce_byte_swap(cmd->replay_ctr, GTK_REPLAY_COUNTER_BYTES);
9039a16d9b50SCarl Huang 	} else {
9040a16d9b50SCarl Huang 		cmd->flags = GTK_OFFLOAD_DISABLE_OPCODE;
9041a16d9b50SCarl Huang 	}
9042a16d9b50SCarl Huang 
9043a16d9b50SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "offload gtk rekey vdev: %d %d\n",
9044a16d9b50SCarl Huang 		   arvif->vdev_id, enable);
9045a16d9b50SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9046a16d9b50SCarl Huang }
9047a16d9b50SCarl Huang 
9048a16d9b50SCarl Huang int ath11k_wmi_gtk_rekey_getinfo(struct ath11k *ar,
9049a16d9b50SCarl Huang 				 struct ath11k_vif *arvif)
9050a16d9b50SCarl Huang {
9051a16d9b50SCarl Huang 	struct wmi_gtk_rekey_offload_cmd *cmd;
9052a16d9b50SCarl Huang 	int len;
9053a16d9b50SCarl Huang 	struct sk_buff *skb;
9054a16d9b50SCarl Huang 
9055a16d9b50SCarl Huang 	len = sizeof(*cmd);
9056a16d9b50SCarl Huang 	skb =  ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9057a16d9b50SCarl Huang 	if (!skb)
9058a16d9b50SCarl Huang 		return -ENOMEM;
9059a16d9b50SCarl Huang 
9060a16d9b50SCarl Huang 	cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9061a16d9b50SCarl Huang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9062a16d9b50SCarl Huang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9063a16d9b50SCarl Huang 
9064a16d9b50SCarl Huang 	cmd->vdev_id = arvif->vdev_id;
9065a16d9b50SCarl Huang 	cmd->flags = GTK_OFFLOAD_REQUEST_STATUS_OPCODE;
9066a16d9b50SCarl Huang 
9067a16d9b50SCarl Huang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "get gtk rekey vdev_id: %d\n",
9068a16d9b50SCarl Huang 		   arvif->vdev_id);
9069a16d9b50SCarl Huang 	return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9070a16d9b50SCarl Huang }
9071652f69edSBaochen Qiang 
9072652f69edSBaochen Qiang int ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k *ar, const u8 *sar_val)
9073652f69edSBaochen Qiang {	struct ath11k_pdev_wmi *wmi = ar->wmi;
9074652f69edSBaochen Qiang 	struct wmi_pdev_set_sar_table_cmd *cmd;
9075652f69edSBaochen Qiang 	struct wmi_tlv *tlv;
9076652f69edSBaochen Qiang 	struct sk_buff *skb;
9077652f69edSBaochen Qiang 	u8 *buf_ptr;
9078652f69edSBaochen Qiang 	u32 len, sar_len_aligned, rsvd_len_aligned;
9079652f69edSBaochen Qiang 
9080652f69edSBaochen Qiang 	sar_len_aligned = roundup(BIOS_SAR_TABLE_LEN, sizeof(u32));
9081652f69edSBaochen Qiang 	rsvd_len_aligned = roundup(BIOS_SAR_RSVD1_LEN, sizeof(u32));
9082652f69edSBaochen Qiang 	len = sizeof(*cmd) +
9083652f69edSBaochen Qiang 	      TLV_HDR_SIZE + sar_len_aligned +
9084652f69edSBaochen Qiang 	      TLV_HDR_SIZE + rsvd_len_aligned;
9085652f69edSBaochen Qiang 
9086652f69edSBaochen Qiang 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9087652f69edSBaochen Qiang 	if (!skb)
9088652f69edSBaochen Qiang 		return -ENOMEM;
9089652f69edSBaochen Qiang 
9090652f69edSBaochen Qiang 	cmd = (struct wmi_pdev_set_sar_table_cmd *)skb->data;
9091652f69edSBaochen Qiang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_SAR_TABLE_CMD) |
9092652f69edSBaochen Qiang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9093652f69edSBaochen Qiang 	cmd->pdev_id = ar->pdev->pdev_id;
9094652f69edSBaochen Qiang 	cmd->sar_len = BIOS_SAR_TABLE_LEN;
9095652f69edSBaochen Qiang 	cmd->rsvd_len = BIOS_SAR_RSVD1_LEN;
9096652f69edSBaochen Qiang 
9097652f69edSBaochen Qiang 	buf_ptr = skb->data + sizeof(*cmd);
9098652f69edSBaochen Qiang 	tlv = (struct wmi_tlv *)buf_ptr;
9099652f69edSBaochen Qiang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9100652f69edSBaochen Qiang 		      FIELD_PREP(WMI_TLV_LEN, sar_len_aligned);
9101652f69edSBaochen Qiang 	buf_ptr += TLV_HDR_SIZE;
9102652f69edSBaochen Qiang 	memcpy(buf_ptr, sar_val, BIOS_SAR_TABLE_LEN);
9103652f69edSBaochen Qiang 
9104652f69edSBaochen Qiang 	buf_ptr += sar_len_aligned;
9105652f69edSBaochen Qiang 	tlv = (struct wmi_tlv *)buf_ptr;
9106652f69edSBaochen Qiang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9107652f69edSBaochen Qiang 		      FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9108652f69edSBaochen Qiang 
9109652f69edSBaochen Qiang 	return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_SAR_TABLE_CMDID);
9110652f69edSBaochen Qiang }
9111652f69edSBaochen Qiang 
9112652f69edSBaochen Qiang int ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k *ar)
9113652f69edSBaochen Qiang {
9114652f69edSBaochen Qiang 	struct ath11k_pdev_wmi *wmi = ar->wmi;
9115652f69edSBaochen Qiang 	struct wmi_pdev_set_geo_table_cmd *cmd;
9116652f69edSBaochen Qiang 	struct wmi_tlv *tlv;
9117652f69edSBaochen Qiang 	struct sk_buff *skb;
9118652f69edSBaochen Qiang 	u8 *buf_ptr;
9119652f69edSBaochen Qiang 	u32 len, rsvd_len_aligned;
9120652f69edSBaochen Qiang 
9121652f69edSBaochen Qiang 	rsvd_len_aligned = roundup(BIOS_SAR_RSVD2_LEN, sizeof(u32));
9122652f69edSBaochen Qiang 	len = sizeof(*cmd) + TLV_HDR_SIZE + rsvd_len_aligned;
9123652f69edSBaochen Qiang 
9124652f69edSBaochen Qiang 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9125652f69edSBaochen Qiang 	if (!skb)
9126652f69edSBaochen Qiang 		return -ENOMEM;
9127652f69edSBaochen Qiang 
9128652f69edSBaochen Qiang 	cmd = (struct wmi_pdev_set_geo_table_cmd *)skb->data;
9129652f69edSBaochen Qiang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_GEO_TABLE_CMD) |
9130652f69edSBaochen Qiang 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9131652f69edSBaochen Qiang 	cmd->pdev_id = ar->pdev->pdev_id;
9132652f69edSBaochen Qiang 	cmd->rsvd_len = BIOS_SAR_RSVD2_LEN;
9133652f69edSBaochen Qiang 
9134652f69edSBaochen Qiang 	buf_ptr = skb->data + sizeof(*cmd);
9135652f69edSBaochen Qiang 	tlv = (struct wmi_tlv *)buf_ptr;
9136652f69edSBaochen Qiang 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9137652f69edSBaochen Qiang 		      FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9138652f69edSBaochen Qiang 
9139652f69edSBaochen Qiang 	return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_GEO_TABLE_CMDID);
9140652f69edSBaochen Qiang }
91410f84a156SBaochen Qiang 
91420f84a156SBaochen Qiang int ath11k_wmi_sta_keepalive(struct ath11k *ar,
91430f84a156SBaochen Qiang 			     const struct wmi_sta_keepalive_arg *arg)
91440f84a156SBaochen Qiang {
91450f84a156SBaochen Qiang 	struct ath11k_pdev_wmi *wmi = ar->wmi;
91460f84a156SBaochen Qiang 	struct wmi_sta_keepalive_cmd *cmd;
91470f84a156SBaochen Qiang 	struct wmi_sta_keepalive_arp_resp *arp;
91480f84a156SBaochen Qiang 	struct sk_buff *skb;
91490f84a156SBaochen Qiang 	size_t len;
91500f84a156SBaochen Qiang 
91510f84a156SBaochen Qiang 	len = sizeof(*cmd) + sizeof(*arp);
91520f84a156SBaochen Qiang 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
91530f84a156SBaochen Qiang 	if (!skb)
91540f84a156SBaochen Qiang 		return -ENOMEM;
91550f84a156SBaochen Qiang 
91560f84a156SBaochen Qiang 	cmd = (struct wmi_sta_keepalive_cmd *)skb->data;
91570f84a156SBaochen Qiang 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
91580f84a156SBaochen Qiang 				     WMI_TAG_STA_KEEPALIVE_CMD) |
91590f84a156SBaochen Qiang 				     FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
91600f84a156SBaochen Qiang 	cmd->vdev_id = arg->vdev_id;
91610f84a156SBaochen Qiang 	cmd->enabled = arg->enabled;
91620f84a156SBaochen Qiang 	cmd->interval = arg->interval;
91630f84a156SBaochen Qiang 	cmd->method = arg->method;
91640f84a156SBaochen Qiang 
91650f84a156SBaochen Qiang 	arp = (struct wmi_sta_keepalive_arp_resp *)(cmd + 1);
91660f84a156SBaochen Qiang 	arp->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9167b7b6f861SBaochen Qiang 				     WMI_TAG_STA_KEEPALIVE_ARP_RESPONSE) |
91680f84a156SBaochen Qiang 			 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9169b7b6f861SBaochen Qiang 
9170b7b6f861SBaochen Qiang 	if (arg->method == WMI_STA_KEEPALIVE_METHOD_UNSOLICITED_ARP_RESPONSE ||
9171b7b6f861SBaochen Qiang 	    arg->method == WMI_STA_KEEPALIVE_METHOD_GRATUITOUS_ARP_REQUEST) {
91720f84a156SBaochen Qiang 		arp->src_ip4_addr = arg->src_ip4_addr;
91730f84a156SBaochen Qiang 		arp->dest_ip4_addr = arg->dest_ip4_addr;
91740f84a156SBaochen Qiang 		ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
91750f84a156SBaochen Qiang 	}
91760f84a156SBaochen Qiang 
91770f84a156SBaochen Qiang 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
91780f84a156SBaochen Qiang 		   "wmi sta keepalive vdev %d enabled %d method %d interval %d\n",
91790f84a156SBaochen Qiang 		   arg->vdev_id, arg->enabled, arg->method, arg->interval);
91800f84a156SBaochen Qiang 
91810f84a156SBaochen Qiang 	return ath11k_wmi_cmd_send(wmi, skb, WMI_STA_KEEPALIVE_CMDID);
91820f84a156SBaochen Qiang }
9183