xref: /openbmc/linux/drivers/net/wireless/ath/ath11k/wmi.c (revision 82b4f9b857e7ac38d26f853a28ca719fdc415cbe)
1d5c65159SKalle Valo // SPDX-License-Identifier: BSD-3-Clause-Clear
2d5c65159SKalle Valo /*
3d5c65159SKalle Valo  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4d5c65159SKalle Valo  */
5d5c65159SKalle Valo #include <linux/skbuff.h>
6d5c65159SKalle Valo #include <linux/ctype.h>
7d5c65159SKalle Valo #include <net/mac80211.h>
8d5c65159SKalle Valo #include <net/cfg80211.h>
9d5c65159SKalle Valo #include <linux/completion.h>
10d5c65159SKalle Valo #include <linux/if_ether.h>
11d5c65159SKalle Valo #include <linux/types.h>
12d5c65159SKalle Valo #include <linux/pci.h>
13d5c65159SKalle Valo #include <linux/uuid.h>
14d5c65159SKalle Valo #include <linux/time.h>
15d5c65159SKalle Valo #include <linux/of.h>
16d5c65159SKalle Valo #include "core.h"
17d5c65159SKalle Valo #include "debug.h"
18d5c65159SKalle Valo #include "mac.h"
19d5c65159SKalle Valo #include "hw.h"
20d5c65159SKalle Valo #include "peer.h"
21d5c65159SKalle Valo 
22d5c65159SKalle Valo struct wmi_tlv_policy {
23d5c65159SKalle Valo 	size_t min_len;
24d5c65159SKalle Valo };
25d5c65159SKalle Valo 
26d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse {
27d5c65159SKalle Valo 	bool wmi_svc_bitmap_done;
28d5c65159SKalle Valo };
29d5c65159SKalle Valo 
30bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse {
31bd647855SKarthikeyan Periyasamy 	struct wmi_dma_ring_capabilities *dma_ring_caps;
32bd647855SKarthikeyan Periyasamy 	u32 n_dma_ring_caps;
33bd647855SKarthikeyan Periyasamy };
34bd647855SKarthikeyan Periyasamy 
35d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse {
36d5c65159SKalle Valo 	struct ath11k_service_ext_param param;
37d5c65159SKalle Valo 	struct wmi_soc_mac_phy_hw_mode_caps *hw_caps;
38d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
39d5c65159SKalle Valo 	u32 n_hw_mode_caps;
40d5c65159SKalle Valo 	u32 tot_phy_id;
41d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities pref_hw_mode_caps;
42d5c65159SKalle Valo 	struct wmi_mac_phy_capabilities *mac_phy_caps;
43d5c65159SKalle Valo 	u32 n_mac_phy_caps;
44d5c65159SKalle Valo 	struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps;
45d5c65159SKalle Valo 	struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps;
46d5c65159SKalle Valo 	u32 n_ext_hal_reg_caps;
47bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
48d5c65159SKalle Valo 	bool hw_mode_done;
49d5c65159SKalle Valo 	bool mac_phy_done;
50d5c65159SKalle Valo 	bool ext_hal_reg_done;
51bd647855SKarthikeyan Periyasamy 	bool mac_phy_chainmask_combo_done;
52bd647855SKarthikeyan Periyasamy 	bool mac_phy_chainmask_cap_done;
53bd647855SKarthikeyan Periyasamy 	bool oem_dma_ring_cap_done;
54bd647855SKarthikeyan Periyasamy 	bool dma_ring_cap_done;
55bd647855SKarthikeyan Periyasamy };
56bd647855SKarthikeyan Periyasamy 
57bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse {
58bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
59bd647855SKarthikeyan Periyasamy 	bool dma_ring_cap_done;
60d5c65159SKalle Valo };
61d5c65159SKalle Valo 
62d5c65159SKalle Valo struct wmi_tlv_rdy_parse {
63d5c65159SKalle Valo 	u32 num_extra_mac_addr;
64d5c65159SKalle Valo };
65d5c65159SKalle Valo 
669d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse {
679d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_dma_buf_release_fixed_param fixed;
689d11b7bfSKarthikeyan Periyasamy 	struct wmi_dma_buf_release_entry *buf_entry;
699d11b7bfSKarthikeyan Periyasamy 	struct wmi_dma_buf_release_meta_data *meta_data;
709d11b7bfSKarthikeyan Periyasamy 	u32 num_buf_entry;
719d11b7bfSKarthikeyan Periyasamy 	u32 num_meta;
729d11b7bfSKarthikeyan Periyasamy 	bool buf_entry_done;
739d11b7bfSKarthikeyan Periyasamy 	bool meta_data_done;
749d11b7bfSKarthikeyan Periyasamy };
759d11b7bfSKarthikeyan Periyasamy 
76d5c65159SKalle Valo static const struct wmi_tlv_policy wmi_tlv_policies[] = {
77d5c65159SKalle Valo 	[WMI_TAG_ARRAY_BYTE]
78d5c65159SKalle Valo 		= { .min_len = 0 },
79d5c65159SKalle Valo 	[WMI_TAG_ARRAY_UINT32]
80d5c65159SKalle Valo 		= { .min_len = 0 },
81d5c65159SKalle Valo 	[WMI_TAG_SERVICE_READY_EVENT]
82d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_service_ready_event) },
83d5c65159SKalle Valo 	[WMI_TAG_SERVICE_READY_EXT_EVENT]
84d5c65159SKalle Valo 		= { .min_len =  sizeof(struct wmi_service_ready_ext_event) },
85d5c65159SKalle Valo 	[WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS]
86d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) },
87d5c65159SKalle Valo 	[WMI_TAG_SOC_HAL_REG_CAPABILITIES]
88d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) },
89d5c65159SKalle Valo 	[WMI_TAG_VDEV_START_RESPONSE_EVENT]
90d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_start_resp_event) },
91d5c65159SKalle Valo 	[WMI_TAG_PEER_DELETE_RESP_EVENT]
92d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_delete_resp_event) },
93d5c65159SKalle Valo 	[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]
94d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_bcn_tx_status_event) },
95d5c65159SKalle Valo 	[WMI_TAG_VDEV_STOPPED_EVENT]
96d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_stopped_event) },
97d5c65159SKalle Valo 	[WMI_TAG_REG_CHAN_LIST_CC_EVENT]
98d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) },
99d5c65159SKalle Valo 	[WMI_TAG_MGMT_RX_HDR]
100d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_mgmt_rx_hdr) },
101d5c65159SKalle Valo 	[WMI_TAG_MGMT_TX_COMPL_EVENT]
102d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) },
103d5c65159SKalle Valo 	[WMI_TAG_SCAN_EVENT]
104d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_scan_event) },
105d5c65159SKalle Valo 	[WMI_TAG_PEER_STA_KICKOUT_EVENT]
106d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
107d5c65159SKalle Valo 	[WMI_TAG_ROAM_EVENT]
108d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_roam_event) },
109d5c65159SKalle Valo 	[WMI_TAG_CHAN_INFO_EVENT]
110d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_chan_info_event) },
111d5c65159SKalle Valo 	[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]
112d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) },
113d5c65159SKalle Valo 	[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]
114d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) },
11521c1b063SMaharaja Kennadyrajan 	[WMI_TAG_READY_EVENT] = {
11621c1b063SMaharaja Kennadyrajan 		.min_len = sizeof(struct wmi_ready_event_min) },
117d5c65159SKalle Valo 	[WMI_TAG_SERVICE_AVAILABLE_EVENT]
118d5c65159SKalle Valo 		= {.min_len = sizeof(struct wmi_service_available_event) },
119d5c65159SKalle Valo 	[WMI_TAG_PEER_ASSOC_CONF_EVENT]
120d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_assoc_conf_event) },
121d5c65159SKalle Valo 	[WMI_TAG_STATS_EVENT]
122d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_stats_event) },
123d5c65159SKalle Valo 	[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]
124d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) },
125d5c65159SKalle Valo };
126d5c65159SKalle Valo 
127d5c65159SKalle Valo #define PRIMAP(_hw_mode_) \
128d5c65159SKalle Valo 	[_hw_mode_] = _hw_mode_##_PRI
129d5c65159SKalle Valo 
130d5c65159SKalle Valo static const int ath11k_hw_mode_pri_map[] = {
131d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SINGLE),
132d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS),
133d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE),
134d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SBS),
135d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS_SBS),
136d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS),
137d5c65159SKalle Valo 	/* keep last */
138d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_MAX),
139d5c65159SKalle Valo };
140d5c65159SKalle Valo 
141d5c65159SKalle Valo static int
142d5c65159SKalle Valo ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
143d5c65159SKalle Valo 		    int (*iter)(struct ath11k_base *ab, u16 tag, u16 len,
144d5c65159SKalle Valo 				const void *ptr, void *data),
145d5c65159SKalle Valo 		    void *data)
146d5c65159SKalle Valo {
147d5c65159SKalle Valo 	const void *begin = ptr;
148d5c65159SKalle Valo 	const struct wmi_tlv *tlv;
149d5c65159SKalle Valo 	u16 tlv_tag, tlv_len;
150d5c65159SKalle Valo 	int ret;
151d5c65159SKalle Valo 
152d5c65159SKalle Valo 	while (len > 0) {
153d5c65159SKalle Valo 		if (len < sizeof(*tlv)) {
154d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
155d5c65159SKalle Valo 				   ptr - begin, len, sizeof(*tlv));
156d5c65159SKalle Valo 			return -EINVAL;
157d5c65159SKalle Valo 		}
158d5c65159SKalle Valo 
159d5c65159SKalle Valo 		tlv = ptr;
160d5c65159SKalle Valo 		tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header);
161d5c65159SKalle Valo 		tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header);
162d5c65159SKalle Valo 		ptr += sizeof(*tlv);
163d5c65159SKalle Valo 		len -= sizeof(*tlv);
164d5c65159SKalle Valo 
165d5c65159SKalle Valo 		if (tlv_len > len) {
166d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure of tag %hhu at byte %zd (%zu bytes left, %hhu expected)\n",
167d5c65159SKalle Valo 				   tlv_tag, ptr - begin, len, tlv_len);
168d5c65159SKalle Valo 			return -EINVAL;
169d5c65159SKalle Valo 		}
170d5c65159SKalle Valo 
171d5c65159SKalle Valo 		if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
172d5c65159SKalle Valo 		    wmi_tlv_policies[tlv_tag].min_len &&
173d5c65159SKalle Valo 		    wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
174d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure of tag %hhu at byte %zd (%hhu bytes is less than min length %zu)\n",
175d5c65159SKalle Valo 				   tlv_tag, ptr - begin, tlv_len,
176d5c65159SKalle Valo 				   wmi_tlv_policies[tlv_tag].min_len);
177d5c65159SKalle Valo 			return -EINVAL;
178d5c65159SKalle Valo 		}
179d5c65159SKalle Valo 
180d5c65159SKalle Valo 		ret = iter(ab, tlv_tag, tlv_len, ptr, data);
181d5c65159SKalle Valo 		if (ret)
182d5c65159SKalle Valo 			return ret;
183d5c65159SKalle Valo 
184d5c65159SKalle Valo 		ptr += tlv_len;
185d5c65159SKalle Valo 		len -= tlv_len;
186d5c65159SKalle Valo 	}
187d5c65159SKalle Valo 
188d5c65159SKalle Valo 	return 0;
189d5c65159SKalle Valo }
190d5c65159SKalle Valo 
191d5c65159SKalle Valo static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len,
192d5c65159SKalle Valo 				     const void *ptr, void *data)
193d5c65159SKalle Valo {
194d5c65159SKalle Valo 	const void **tb = data;
195d5c65159SKalle Valo 
196d5c65159SKalle Valo 	if (tag < WMI_TAG_MAX)
197d5c65159SKalle Valo 		tb[tag] = ptr;
198d5c65159SKalle Valo 
199d5c65159SKalle Valo 	return 0;
200d5c65159SKalle Valo }
201d5c65159SKalle Valo 
202d5c65159SKalle Valo static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb,
203d5c65159SKalle Valo 				const void *ptr, size_t len)
204d5c65159SKalle Valo {
205d5c65159SKalle Valo 	return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse,
206d5c65159SKalle Valo 				   (void *)tb);
207d5c65159SKalle Valo }
208d5c65159SKalle Valo 
209d5c65159SKalle Valo static const void **
210d5c65159SKalle Valo ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr,
211d5c65159SKalle Valo 			   size_t len, gfp_t gfp)
212d5c65159SKalle Valo {
213d5c65159SKalle Valo 	const void **tb;
214d5c65159SKalle Valo 	int ret;
215d5c65159SKalle Valo 
216d5c65159SKalle Valo 	tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp);
217d5c65159SKalle Valo 	if (!tb)
218d5c65159SKalle Valo 		return ERR_PTR(-ENOMEM);
219d5c65159SKalle Valo 
220d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len);
221d5c65159SKalle Valo 	if (ret) {
222d5c65159SKalle Valo 		kfree(tb);
223d5c65159SKalle Valo 		return ERR_PTR(ret);
224d5c65159SKalle Valo 	}
225d5c65159SKalle Valo 
226d5c65159SKalle Valo 	return tb;
227d5c65159SKalle Valo }
228d5c65159SKalle Valo 
229d5c65159SKalle Valo static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
230d5c65159SKalle Valo 				      u32 cmd_id)
231d5c65159SKalle Valo {
232d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
2336bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
234d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
235d5c65159SKalle Valo 	int ret;
236d5c65159SKalle Valo 	u32 cmd = 0;
237d5c65159SKalle Valo 
238d5c65159SKalle Valo 	if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
239d5c65159SKalle Valo 		return -ENOMEM;
240d5c65159SKalle Valo 
241d5c65159SKalle Valo 	cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id);
242d5c65159SKalle Valo 
243d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
244d5c65159SKalle Valo 	cmd_hdr->cmd_id = cmd;
245d5c65159SKalle Valo 
246d5c65159SKalle Valo 	memset(skb_cb, 0, sizeof(*skb_cb));
247d5c65159SKalle Valo 	ret = ath11k_htc_send(&ab->htc, wmi->eid, skb);
248d5c65159SKalle Valo 
249d5c65159SKalle Valo 	if (ret)
250d5c65159SKalle Valo 		goto err_pull;
251d5c65159SKalle Valo 
252d5c65159SKalle Valo 	return 0;
253d5c65159SKalle Valo 
254d5c65159SKalle Valo err_pull:
255d5c65159SKalle Valo 	skb_pull(skb, sizeof(struct wmi_cmd_hdr));
256d5c65159SKalle Valo 	return ret;
257d5c65159SKalle Valo }
258d5c65159SKalle Valo 
259d5c65159SKalle Valo int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
260d5c65159SKalle Valo 			u32 cmd_id)
261d5c65159SKalle Valo {
2626bc9d6f7SJohn Crispin 	struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab;
263d5c65159SKalle Valo 	int ret = -EOPNOTSUPP;
264d5c65159SKalle Valo 
265d5c65159SKalle Valo 	might_sleep();
266d5c65159SKalle Valo 
267d5c65159SKalle Valo 	wait_event_timeout(wmi_sc->tx_credits_wq, ({
268d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
269d5c65159SKalle Valo 
270d5c65159SKalle Valo 		if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH, &wmi_sc->ab->dev_flags))
271d5c65159SKalle Valo 			ret = -ESHUTDOWN;
272d5c65159SKalle Valo 
273d5c65159SKalle Valo 		(ret != -EAGAIN);
274d5c65159SKalle Valo 	}), WMI_SEND_TIMEOUT_HZ);
275d5c65159SKalle Valo 
276d5c65159SKalle Valo 	if (ret == -EAGAIN)
277d5c65159SKalle Valo 		ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id);
278d5c65159SKalle Valo 
279d5c65159SKalle Valo 	return ret;
280d5c65159SKalle Valo }
281d5c65159SKalle Valo 
282d5c65159SKalle Valo static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
283d5c65159SKalle Valo 				     const void *ptr,
284d5c65159SKalle Valo 				     struct ath11k_service_ext_param *param)
285d5c65159SKalle Valo {
286d5c65159SKalle Valo 	const struct wmi_service_ready_ext_event *ev = ptr;
287d5c65159SKalle Valo 
288d5c65159SKalle Valo 	if (!ev)
289d5c65159SKalle Valo 		return -EINVAL;
290d5c65159SKalle Valo 
291d5c65159SKalle Valo 	/* Move this to host based bitmap */
292d5c65159SKalle Valo 	param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits;
293d5c65159SKalle Valo 	param->default_fw_config_bits =	ev->default_fw_config_bits;
294d5c65159SKalle Valo 	param->he_cap_info = ev->he_cap_info;
295d5c65159SKalle Valo 	param->mpdu_density = ev->mpdu_density;
296d5c65159SKalle Valo 	param->max_bssid_rx_filters = ev->max_bssid_rx_filters;
297d5c65159SKalle Valo 	memcpy(&param->ppet, &ev->ppet, sizeof(param->ppet));
298d5c65159SKalle Valo 
299d5c65159SKalle Valo 	return 0;
300d5c65159SKalle Valo }
301d5c65159SKalle Valo 
302d5c65159SKalle Valo static int
303d5c65159SKalle Valo ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
304d5c65159SKalle Valo 				      struct wmi_soc_mac_phy_hw_mode_caps *hw_caps,
305d5c65159SKalle Valo 				      struct wmi_hw_mode_capabilities *wmi_hw_mode_caps,
306d5c65159SKalle Valo 				      struct wmi_soc_hal_reg_capabilities *hal_reg_caps,
307d5c65159SKalle Valo 				      struct wmi_mac_phy_capabilities *wmi_mac_phy_caps,
308d5c65159SKalle Valo 				      u8 hw_mode_id, u8 phy_id,
309d5c65159SKalle Valo 				      struct ath11k_pdev *pdev)
310d5c65159SKalle Valo {
311d5c65159SKalle Valo 	struct wmi_mac_phy_capabilities *mac_phy_caps;
312d5c65159SKalle Valo 	struct ath11k_band_cap *cap_band;
313d5c65159SKalle Valo 	struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
314d5c65159SKalle Valo 	u32 phy_map;
315d5c65159SKalle Valo 	u32 hw_idx, phy_idx = 0;
316d5c65159SKalle Valo 
317d5c65159SKalle Valo 	if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps)
318d5c65159SKalle Valo 		return -EINVAL;
319d5c65159SKalle Valo 
320d5c65159SKalle Valo 	for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) {
321d5c65159SKalle Valo 		if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id)
322d5c65159SKalle Valo 			break;
323d5c65159SKalle Valo 
324d5c65159SKalle Valo 		phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map;
325d5c65159SKalle Valo 		while (phy_map) {
326d5c65159SKalle Valo 			phy_map >>= 1;
327d5c65159SKalle Valo 			phy_idx++;
328d5c65159SKalle Valo 		}
329d5c65159SKalle Valo 	}
330d5c65159SKalle Valo 
331d5c65159SKalle Valo 	if (hw_idx == hw_caps->num_hw_modes)
332d5c65159SKalle Valo 		return -EINVAL;
333d5c65159SKalle Valo 
334d5c65159SKalle Valo 	phy_idx += phy_id;
335d5c65159SKalle Valo 	if (phy_id >= hal_reg_caps->num_phy)
336d5c65159SKalle Valo 		return -EINVAL;
337d5c65159SKalle Valo 
3385b90fc76SAnilkumar Kolli 	mac_phy_caps = wmi_mac_phy_caps + phy_idx;
339d5c65159SKalle Valo 
340d5c65159SKalle Valo 	pdev->pdev_id = mac_phy_caps->pdev_id;
3415f859bc0SCarl Huang 	pdev_cap->supported_bands |= mac_phy_caps->supported_bands;
342d5c65159SKalle Valo 	pdev_cap->ampdu_density = mac_phy_caps->ampdu_density;
343d5c65159SKalle Valo 
344d5c65159SKalle Valo 	/* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from
345d5c65159SKalle Valo 	 * band to band for a single radio, need to see how this should be
346d5c65159SKalle Valo 	 * handled.
347d5c65159SKalle Valo 	 */
348d5c65159SKalle Valo 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
349d5c65159SKalle Valo 		pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g;
350d5c65159SKalle Valo 		pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g;
351d5c65159SKalle Valo 	} else if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
352d5c65159SKalle Valo 		pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g;
353d5c65159SKalle Valo 		pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g;
354d5c65159SKalle Valo 		pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g;
355d5c65159SKalle Valo 		pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g;
356d5c65159SKalle Valo 		pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g;
357d5c65159SKalle Valo 	} else {
358d5c65159SKalle Valo 		return -EINVAL;
359d5c65159SKalle Valo 	}
360d5c65159SKalle Valo 
361d5c65159SKalle Valo 	/* tx/rx chainmask reported from fw depends on the actual hw chains used,
362d5c65159SKalle Valo 	 * For example, for 4x4 capable macphys, first 4 chains can be used for first
363d5c65159SKalle Valo 	 * mac and the remaing 4 chains can be used for the second mac or vice-versa.
364d5c65159SKalle Valo 	 * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0
365d5c65159SKalle Valo 	 * will be advertised for second mac or vice-versa. Compute the shift value for
366d5c65159SKalle Valo 	 * for tx/rx chainmask which will be used to advertise supported ht/vht rates to
367d5c65159SKalle Valo 	 * mac80211.
368d5c65159SKalle Valo 	 */
369d5c65159SKalle Valo 	pdev_cap->tx_chain_mask_shift =
370d5c65159SKalle Valo 			find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32);
371d5c65159SKalle Valo 	pdev_cap->rx_chain_mask_shift =
372d5c65159SKalle Valo 			find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32);
373d5c65159SKalle Valo 
3745f859bc0SCarl Huang 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
375d5c65159SKalle Valo 		cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
3765f859bc0SCarl Huang 		cap_band->phy_id = mac_phy_caps->phy_id;
377d5c65159SKalle Valo 		cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g;
378d5c65159SKalle Valo 		cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g;
379d5c65159SKalle Valo 		cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g;
380d5c65159SKalle Valo 		cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext;
381d5c65159SKalle Valo 		cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g;
382d5c65159SKalle Valo 		memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g,
383d5c65159SKalle Valo 		       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
384d5c65159SKalle Valo 		memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g,
385d5c65159SKalle Valo 		       sizeof(struct ath11k_ppe_threshold));
3865f859bc0SCarl Huang 	}
387d5c65159SKalle Valo 
3885f859bc0SCarl Huang 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
389d5c65159SKalle Valo 		cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
3905f859bc0SCarl Huang 		cap_band->phy_id = mac_phy_caps->phy_id;
391d5c65159SKalle Valo 		cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
392d5c65159SKalle Valo 		cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
393d5c65159SKalle Valo 		cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
394d5c65159SKalle Valo 		cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
395d5c65159SKalle Valo 		cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
396d5c65159SKalle Valo 		memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
397d5c65159SKalle Valo 		       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
398d5c65159SKalle Valo 		memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
399d5c65159SKalle Valo 		       sizeof(struct ath11k_ppe_threshold));
4005f859bc0SCarl Huang 	}
401d5c65159SKalle Valo 
40222eeadcdSPradeep Kumar Chitrapu 	cap_band = &pdev_cap->band[NL80211_BAND_6GHZ];
40322eeadcdSPradeep Kumar Chitrapu 	cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
40422eeadcdSPradeep Kumar Chitrapu 	cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
40522eeadcdSPradeep Kumar Chitrapu 	cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
40622eeadcdSPradeep Kumar Chitrapu 	cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
40722eeadcdSPradeep Kumar Chitrapu 	cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
40822eeadcdSPradeep Kumar Chitrapu 	memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
40922eeadcdSPradeep Kumar Chitrapu 	       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
41022eeadcdSPradeep Kumar Chitrapu 	memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
41122eeadcdSPradeep Kumar Chitrapu 	       sizeof(struct ath11k_ppe_threshold));
41222eeadcdSPradeep Kumar Chitrapu 
413d5c65159SKalle Valo 	return 0;
414d5c65159SKalle Valo }
415d5c65159SKalle Valo 
416d5c65159SKalle Valo static int
417d5c65159SKalle Valo ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle,
418d5c65159SKalle Valo 				struct wmi_soc_hal_reg_capabilities *reg_caps,
419d5c65159SKalle Valo 				struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap,
420d5c65159SKalle Valo 				u8 phy_idx,
421d5c65159SKalle Valo 				struct ath11k_hal_reg_capabilities_ext *param)
422d5c65159SKalle Valo {
423d5c65159SKalle Valo 	struct wmi_hal_reg_capabilities_ext *ext_reg_cap;
424d5c65159SKalle Valo 
425d5c65159SKalle Valo 	if (!reg_caps || !wmi_ext_reg_cap)
426d5c65159SKalle Valo 		return -EINVAL;
427d5c65159SKalle Valo 
428d5c65159SKalle Valo 	if (phy_idx >= reg_caps->num_phy)
429d5c65159SKalle Valo 		return -EINVAL;
430d5c65159SKalle Valo 
431d5c65159SKalle Valo 	ext_reg_cap = &wmi_ext_reg_cap[phy_idx];
432d5c65159SKalle Valo 
433d5c65159SKalle Valo 	param->phy_id = ext_reg_cap->phy_id;
434d5c65159SKalle Valo 	param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain;
435d5c65159SKalle Valo 	param->eeprom_reg_domain_ext =
436d5c65159SKalle Valo 			      ext_reg_cap->eeprom_reg_domain_ext;
437d5c65159SKalle Valo 	param->regcap1 = ext_reg_cap->regcap1;
438d5c65159SKalle Valo 	param->regcap2 = ext_reg_cap->regcap2;
439d5c65159SKalle Valo 	/* check if param->wireless_mode is needed */
440d5c65159SKalle Valo 	param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan;
441d5c65159SKalle Valo 	param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan;
442d5c65159SKalle Valo 	param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan;
443d5c65159SKalle Valo 	param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan;
444d5c65159SKalle Valo 
445d5c65159SKalle Valo 	return 0;
446d5c65159SKalle Valo }
447d5c65159SKalle Valo 
448d5c65159SKalle Valo static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab,
449d5c65159SKalle Valo 					 const void *evt_buf,
450d5c65159SKalle Valo 					 struct ath11k_targ_cap *cap)
451d5c65159SKalle Valo {
452d5c65159SKalle Valo 	const struct wmi_service_ready_event *ev = evt_buf;
453d5c65159SKalle Valo 
454d5c65159SKalle Valo 	if (!ev) {
455d5c65159SKalle Valo 		ath11k_err(ab, "%s: failed by NULL param\n",
456d5c65159SKalle Valo 			   __func__);
457d5c65159SKalle Valo 		return -EINVAL;
458d5c65159SKalle Valo 	}
459d5c65159SKalle Valo 
460d5c65159SKalle Valo 	cap->phy_capability = ev->phy_capability;
461d5c65159SKalle Valo 	cap->max_frag_entry = ev->max_frag_entry;
462d5c65159SKalle Valo 	cap->num_rf_chains = ev->num_rf_chains;
463d5c65159SKalle Valo 	cap->ht_cap_info = ev->ht_cap_info;
464d5c65159SKalle Valo 	cap->vht_cap_info = ev->vht_cap_info;
465d5c65159SKalle Valo 	cap->vht_supp_mcs = ev->vht_supp_mcs;
466d5c65159SKalle Valo 	cap->hw_min_tx_power = ev->hw_min_tx_power;
467d5c65159SKalle Valo 	cap->hw_max_tx_power = ev->hw_max_tx_power;
468d5c65159SKalle Valo 	cap->sys_cap_info = ev->sys_cap_info;
469d5c65159SKalle Valo 	cap->min_pkt_size_enable = ev->min_pkt_size_enable;
470d5c65159SKalle Valo 	cap->max_bcn_ie_size = ev->max_bcn_ie_size;
471d5c65159SKalle Valo 	cap->max_num_scan_channels = ev->max_num_scan_channels;
472d5c65159SKalle Valo 	cap->max_supported_macs = ev->max_supported_macs;
473d5c65159SKalle Valo 	cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps;
474d5c65159SKalle Valo 	cap->txrx_chainmask = ev->txrx_chainmask;
475d5c65159SKalle Valo 	cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index;
476d5c65159SKalle Valo 	cap->num_msdu_desc = ev->num_msdu_desc;
477d5c65159SKalle Valo 
478d5c65159SKalle Valo 	return 0;
479d5c65159SKalle Valo }
480d5c65159SKalle Valo 
481d5c65159SKalle Valo /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in
482d5c65159SKalle Valo  * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each
483d5c65159SKalle Valo  * 4-byte word.
484d5c65159SKalle Valo  */
485d5c65159SKalle Valo static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi,
486d5c65159SKalle Valo 					   const u32 *wmi_svc_bm)
487d5c65159SKalle Valo {
488d5c65159SKalle Valo 	int i, j;
489d5c65159SKalle Valo 
490d5c65159SKalle Valo 	for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) {
491d5c65159SKalle Valo 		do {
492d5c65159SKalle Valo 			if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32))
4936bc9d6f7SJohn Crispin 				set_bit(j, wmi->wmi_ab->svc_map);
494d5c65159SKalle Valo 		} while (++j % WMI_SERVICE_BITS_IN_SIZE32);
495d5c65159SKalle Valo 	}
496d5c65159SKalle Valo }
497d5c65159SKalle Valo 
498d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
499d5c65159SKalle Valo 					const void *ptr, void *data)
500d5c65159SKalle Valo {
501d5c65159SKalle Valo 	struct wmi_tlv_svc_ready_parse *svc_ready = data;
5026bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
503d5c65159SKalle Valo 	u16 expect_len;
504d5c65159SKalle Valo 
505d5c65159SKalle Valo 	switch (tag) {
506d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EVENT:
507d5c65159SKalle Valo 		if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps))
508d5c65159SKalle Valo 			return -EINVAL;
509d5c65159SKalle Valo 		break;
510d5c65159SKalle Valo 
511d5c65159SKalle Valo 	case WMI_TAG_ARRAY_UINT32:
512d5c65159SKalle Valo 		if (!svc_ready->wmi_svc_bitmap_done) {
513d5c65159SKalle Valo 			expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32);
514d5c65159SKalle Valo 			if (len < expect_len) {
515d5c65159SKalle Valo 				ath11k_warn(ab, "invalid len %d for the tag 0x%x\n",
516d5c65159SKalle Valo 					    len, tag);
517d5c65159SKalle Valo 				return -EINVAL;
518d5c65159SKalle Valo 			}
519d5c65159SKalle Valo 
520d5c65159SKalle Valo 			ath11k_wmi_service_bitmap_copy(wmi_handle, ptr);
521d5c65159SKalle Valo 
522d5c65159SKalle Valo 			svc_ready->wmi_svc_bitmap_done = true;
523d5c65159SKalle Valo 		}
524d5c65159SKalle Valo 		break;
525d5c65159SKalle Valo 	default:
526d5c65159SKalle Valo 		break;
527d5c65159SKalle Valo 	}
528d5c65159SKalle Valo 
529d5c65159SKalle Valo 	return 0;
530d5c65159SKalle Valo }
531d5c65159SKalle Valo 
532d5c65159SKalle Valo static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
533d5c65159SKalle Valo {
534d5c65159SKalle Valo 	struct wmi_tlv_svc_ready_parse svc_ready = { };
535d5c65159SKalle Valo 	int ret;
536d5c65159SKalle Valo 
537d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
538d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_parse,
539d5c65159SKalle Valo 				  &svc_ready);
540d5c65159SKalle Valo 	if (ret) {
541d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
542d5c65159SKalle Valo 		return ret;
543d5c65159SKalle Valo 	}
544d5c65159SKalle Valo 
545d5c65159SKalle Valo 	return 0;
546d5c65159SKalle Valo }
547d5c65159SKalle Valo 
548d5c65159SKalle Valo struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len)
549d5c65159SKalle Valo {
550d5c65159SKalle Valo 	struct sk_buff *skb;
551d5c65159SKalle Valo 	struct ath11k_base *ab = wmi_sc->ab;
552d5c65159SKalle Valo 	u32 round_len = roundup(len, 4);
553d5c65159SKalle Valo 
554d5c65159SKalle Valo 	skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len);
555d5c65159SKalle Valo 	if (!skb)
556d5c65159SKalle Valo 		return NULL;
557d5c65159SKalle Valo 
558d5c65159SKalle Valo 	skb_reserve(skb, WMI_SKB_HEADROOM);
559d5c65159SKalle Valo 	if (!IS_ALIGNED((unsigned long)skb->data, 4))
560d5c65159SKalle Valo 		ath11k_warn(ab, "unaligned WMI skb data\n");
561d5c65159SKalle Valo 
562d5c65159SKalle Valo 	skb_put(skb, round_len);
563d5c65159SKalle Valo 	memset(skb->data, 0, round_len);
564d5c65159SKalle Valo 
565d5c65159SKalle Valo 	return skb;
566d5c65159SKalle Valo }
567d5c65159SKalle Valo 
568d5c65159SKalle Valo int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id,
569d5c65159SKalle Valo 			 struct sk_buff *frame)
570d5c65159SKalle Valo {
571d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
572d5c65159SKalle Valo 	struct wmi_mgmt_send_cmd *cmd;
573d5c65159SKalle Valo 	struct wmi_tlv *frame_tlv;
574d5c65159SKalle Valo 	struct sk_buff *skb;
575d5c65159SKalle Valo 	u32 buf_len;
576d5c65159SKalle Valo 	int ret, len;
577d5c65159SKalle Valo 
578d5c65159SKalle Valo 	buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ?
579d5c65159SKalle Valo 		  frame->len : WMI_MGMT_SEND_DOWNLD_LEN;
580d5c65159SKalle Valo 
581d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4);
582d5c65159SKalle Valo 
5836bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
584d5c65159SKalle Valo 	if (!skb)
585d5c65159SKalle Valo 		return -ENOMEM;
586d5c65159SKalle Valo 
587d5c65159SKalle Valo 	cmd = (struct wmi_mgmt_send_cmd *)skb->data;
588d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) |
589d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
590d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
591d5c65159SKalle Valo 	cmd->desc_id = buf_id;
592d5c65159SKalle Valo 	cmd->chanfreq = 0;
593d5c65159SKalle Valo 	cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr);
594d5c65159SKalle Valo 	cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr);
595d5c65159SKalle Valo 	cmd->frame_len = frame->len;
596d5c65159SKalle Valo 	cmd->buf_len = buf_len;
597d5c65159SKalle Valo 	cmd->tx_params_valid = 0;
598d5c65159SKalle Valo 
599d5c65159SKalle Valo 	frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
600d5c65159SKalle Valo 	frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
601d5c65159SKalle Valo 			    FIELD_PREP(WMI_TLV_LEN, buf_len);
602d5c65159SKalle Valo 
603d5c65159SKalle Valo 	memcpy(frame_tlv->value, frame->data, buf_len);
604d5c65159SKalle Valo 
605d5c65159SKalle Valo 	ath11k_ce_byte_swap(frame_tlv->value, buf_len);
606d5c65159SKalle Valo 
607d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID);
608d5c65159SKalle Valo 	if (ret) {
609d5c65159SKalle Valo 		ath11k_warn(ar->ab,
610d5c65159SKalle Valo 			    "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n");
611d5c65159SKalle Valo 		dev_kfree_skb(skb);
612d5c65159SKalle Valo 	}
613d5c65159SKalle Valo 
614d5c65159SKalle Valo 	return ret;
615d5c65159SKalle Valo }
616d5c65159SKalle Valo 
617d5c65159SKalle Valo int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr,
618d5c65159SKalle Valo 			   struct vdev_create_params *param)
619d5c65159SKalle Valo {
620d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
621d5c65159SKalle Valo 	struct wmi_vdev_create_cmd *cmd;
622d5c65159SKalle Valo 	struct sk_buff *skb;
623d5c65159SKalle Valo 	struct wmi_vdev_txrx_streams *txrx_streams;
624d5c65159SKalle Valo 	struct wmi_tlv *tlv;
625d5c65159SKalle Valo 	int ret, len;
626d5c65159SKalle Valo 	void *ptr;
627d5c65159SKalle Valo 
628d5c65159SKalle Valo 	/* It can be optimized my sending tx/rx chain configuration
629d5c65159SKalle Valo 	 * only for supported bands instead of always sending it for
630d5c65159SKalle Valo 	 * both the bands.
631d5c65159SKalle Valo 	 */
632d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE +
633d5c65159SKalle Valo 		(WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams));
634d5c65159SKalle Valo 
6356bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
636d5c65159SKalle Valo 	if (!skb)
637d5c65159SKalle Valo 		return -ENOMEM;
638d5c65159SKalle Valo 
639d5c65159SKalle Valo 	cmd = (struct wmi_vdev_create_cmd *)skb->data;
640d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) |
641d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
642d5c65159SKalle Valo 
643d5c65159SKalle Valo 	cmd->vdev_id = param->if_id;
644d5c65159SKalle Valo 	cmd->vdev_type = param->type;
645d5c65159SKalle Valo 	cmd->vdev_subtype = param->subtype;
646d5c65159SKalle Valo 	cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX;
647d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
648d5c65159SKalle Valo 	ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
649d5c65159SKalle Valo 
650d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
651d5c65159SKalle Valo 	len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams);
652d5c65159SKalle Valo 
653d5c65159SKalle Valo 	tlv = ptr;
654d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
655d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
656d5c65159SKalle Valo 
657d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
658d5c65159SKalle Valo 	txrx_streams = ptr;
659d5c65159SKalle Valo 	len = sizeof(*txrx_streams);
660d5c65159SKalle Valo 	txrx_streams->tlv_header =
661d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
662d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
663d5c65159SKalle Valo 	txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G;
664d5c65159SKalle Valo 	txrx_streams->supported_tx_streams =
665d5c65159SKalle Valo 				 param->chains[NL80211_BAND_2GHZ].tx;
666d5c65159SKalle Valo 	txrx_streams->supported_rx_streams =
667d5c65159SKalle Valo 				 param->chains[NL80211_BAND_2GHZ].rx;
668d5c65159SKalle Valo 
669d5c65159SKalle Valo 	txrx_streams++;
670d5c65159SKalle Valo 	txrx_streams->tlv_header =
671d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
672d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
673d5c65159SKalle Valo 	txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G;
674d5c65159SKalle Valo 	txrx_streams->supported_tx_streams =
675d5c65159SKalle Valo 				 param->chains[NL80211_BAND_5GHZ].tx;
676d5c65159SKalle Valo 	txrx_streams->supported_rx_streams =
677d5c65159SKalle Valo 				 param->chains[NL80211_BAND_5GHZ].rx;
678d5c65159SKalle Valo 
679d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID);
680d5c65159SKalle Valo 	if (ret) {
681d5c65159SKalle Valo 		ath11k_warn(ar->ab,
682d5c65159SKalle Valo 			    "failed to submit WMI_VDEV_CREATE_CMDID\n");
683d5c65159SKalle Valo 		dev_kfree_skb(skb);
684d5c65159SKalle Valo 	}
685d5c65159SKalle Valo 
686d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
687d5c65159SKalle Valo 		   "WMI vdev create: id %d type %d subtype %d macaddr %pM pdevid %d\n",
688d5c65159SKalle Valo 		   param->if_id, param->type, param->subtype,
689d5c65159SKalle Valo 		   macaddr, param->pdev_id);
690d5c65159SKalle Valo 
691d5c65159SKalle Valo 	return ret;
692d5c65159SKalle Valo }
693d5c65159SKalle Valo 
694d5c65159SKalle Valo int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id)
695d5c65159SKalle Valo {
696d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
697d5c65159SKalle Valo 	struct wmi_vdev_delete_cmd *cmd;
698d5c65159SKalle Valo 	struct sk_buff *skb;
699d5c65159SKalle Valo 	int ret;
700d5c65159SKalle Valo 
7016bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
702d5c65159SKalle Valo 	if (!skb)
703d5c65159SKalle Valo 		return -ENOMEM;
704d5c65159SKalle Valo 
705d5c65159SKalle Valo 	cmd = (struct wmi_vdev_delete_cmd *)skb->data;
706d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) |
707d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
708d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
709d5c65159SKalle Valo 
710d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID);
711d5c65159SKalle Valo 	if (ret) {
712d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n");
713d5c65159SKalle Valo 		dev_kfree_skb(skb);
714d5c65159SKalle Valo 	}
715d5c65159SKalle Valo 
716d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev delete id %d\n", vdev_id);
717d5c65159SKalle Valo 
718d5c65159SKalle Valo 	return ret;
719d5c65159SKalle Valo }
720d5c65159SKalle Valo 
721d5c65159SKalle Valo int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id)
722d5c65159SKalle Valo {
723d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
724d5c65159SKalle Valo 	struct wmi_vdev_stop_cmd *cmd;
725d5c65159SKalle Valo 	struct sk_buff *skb;
726d5c65159SKalle Valo 	int ret;
727d5c65159SKalle Valo 
7286bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
729d5c65159SKalle Valo 	if (!skb)
730d5c65159SKalle Valo 		return -ENOMEM;
731d5c65159SKalle Valo 
732d5c65159SKalle Valo 	cmd = (struct wmi_vdev_stop_cmd *)skb->data;
733d5c65159SKalle Valo 
734d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) |
735d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
736d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
737d5c65159SKalle Valo 
738d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID);
739d5c65159SKalle Valo 	if (ret) {
740d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n");
741d5c65159SKalle Valo 		dev_kfree_skb(skb);
742d5c65159SKalle Valo 	}
743d5c65159SKalle Valo 
744d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev stop id 0x%x\n", vdev_id);
745d5c65159SKalle Valo 
746d5c65159SKalle Valo 	return ret;
747d5c65159SKalle Valo }
748d5c65159SKalle Valo 
749d5c65159SKalle Valo int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id)
750d5c65159SKalle Valo {
751d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
752d5c65159SKalle Valo 	struct wmi_vdev_down_cmd *cmd;
753d5c65159SKalle Valo 	struct sk_buff *skb;
754d5c65159SKalle Valo 	int ret;
755d5c65159SKalle Valo 
7566bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
757d5c65159SKalle Valo 	if (!skb)
758d5c65159SKalle Valo 		return -ENOMEM;
759d5c65159SKalle Valo 
760d5c65159SKalle Valo 	cmd = (struct wmi_vdev_down_cmd *)skb->data;
761d5c65159SKalle Valo 
762d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) |
763d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
764d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
765d5c65159SKalle Valo 
766d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID);
767d5c65159SKalle Valo 	if (ret) {
768d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n");
769d5c65159SKalle Valo 		dev_kfree_skb(skb);
770d5c65159SKalle Valo 	}
771d5c65159SKalle Valo 
772d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev down id 0x%x\n", vdev_id);
773d5c65159SKalle Valo 
774d5c65159SKalle Valo 	return ret;
775d5c65159SKalle Valo }
776d5c65159SKalle Valo 
777d5c65159SKalle Valo static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan,
778d5c65159SKalle Valo 				       struct wmi_vdev_start_req_arg *arg)
779d5c65159SKalle Valo {
780d5c65159SKalle Valo 	memset(chan, 0, sizeof(*chan));
781d5c65159SKalle Valo 
782d5c65159SKalle Valo 	chan->mhz = arg->channel.freq;
783d5c65159SKalle Valo 	chan->band_center_freq1 = arg->channel.band_center_freq1;
784d5c65159SKalle Valo 	if (arg->channel.mode == MODE_11AC_VHT80_80)
785d5c65159SKalle Valo 		chan->band_center_freq2 = arg->channel.band_center_freq2;
786d5c65159SKalle Valo 	else
787d5c65159SKalle Valo 		chan->band_center_freq2 = 0;
788d5c65159SKalle Valo 
789d5c65159SKalle Valo 	chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode);
790d5c65159SKalle Valo 	if (arg->channel.passive)
791d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_PASSIVE;
792d5c65159SKalle Valo 	if (arg->channel.allow_ibss)
793d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED;
794d5c65159SKalle Valo 	if (arg->channel.allow_ht)
795d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ALLOW_HT;
796d5c65159SKalle Valo 	if (arg->channel.allow_vht)
797d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ALLOW_VHT;
7989f056ed8SJohn Crispin 	if (arg->channel.allow_he)
7999f056ed8SJohn Crispin 		chan->info |= WMI_CHAN_INFO_ALLOW_HE;
800d5c65159SKalle Valo 	if (arg->channel.ht40plus)
801d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_HT40_PLUS;
802d5c65159SKalle Valo 	if (arg->channel.chan_radar)
803d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_DFS;
804d5c65159SKalle Valo 	if (arg->channel.freq2_radar)
805d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_DFS_FREQ2;
806d5c65159SKalle Valo 
807d5c65159SKalle Valo 	chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
808d5c65159SKalle Valo 				      arg->channel.max_power) |
809d5c65159SKalle Valo 		FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
810d5c65159SKalle Valo 			   arg->channel.max_reg_power);
811d5c65159SKalle Valo 
812d5c65159SKalle Valo 	chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
813d5c65159SKalle Valo 				      arg->channel.max_antenna_gain) |
814d5c65159SKalle Valo 		FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
815d5c65159SKalle Valo 			   arg->channel.max_power);
816d5c65159SKalle Valo }
817d5c65159SKalle Valo 
818d5c65159SKalle Valo int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg,
819d5c65159SKalle Valo 			  bool restart)
820d5c65159SKalle Valo {
821d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
822d5c65159SKalle Valo 	struct wmi_vdev_start_request_cmd *cmd;
823d5c65159SKalle Valo 	struct sk_buff *skb;
824d5c65159SKalle Valo 	struct wmi_channel *chan;
825d5c65159SKalle Valo 	struct wmi_tlv *tlv;
826d5c65159SKalle Valo 	void *ptr;
827d5c65159SKalle Valo 	int ret, len;
828d5c65159SKalle Valo 
829d5c65159SKalle Valo 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
830d5c65159SKalle Valo 		return -EINVAL;
831d5c65159SKalle Valo 
832d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE;
833d5c65159SKalle Valo 
8346bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
835d5c65159SKalle Valo 	if (!skb)
836d5c65159SKalle Valo 		return -ENOMEM;
837d5c65159SKalle Valo 
838d5c65159SKalle Valo 	cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
839d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
840d5c65159SKalle Valo 				     WMI_TAG_VDEV_START_REQUEST_CMD) |
841d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
842d5c65159SKalle Valo 	cmd->vdev_id = arg->vdev_id;
843d5c65159SKalle Valo 	cmd->beacon_interval = arg->bcn_intval;
844d5c65159SKalle Valo 	cmd->bcn_tx_rate = arg->bcn_tx_rate;
845d5c65159SKalle Valo 	cmd->dtim_period = arg->dtim_period;
846d5c65159SKalle Valo 	cmd->num_noa_descriptors = arg->num_noa_descriptors;
847d5c65159SKalle Valo 	cmd->preferred_rx_streams = arg->pref_rx_streams;
848d5c65159SKalle Valo 	cmd->preferred_tx_streams = arg->pref_tx_streams;
849d5c65159SKalle Valo 	cmd->cac_duration_ms = arg->cac_duration_ms;
850d5c65159SKalle Valo 	cmd->regdomain = arg->regdomain;
851d5c65159SKalle Valo 	cmd->he_ops = arg->he_ops;
852d5c65159SKalle Valo 
853d5c65159SKalle Valo 	if (!restart) {
854d5c65159SKalle Valo 		if (arg->ssid) {
855d5c65159SKalle Valo 			cmd->ssid.ssid_len = arg->ssid_len;
856d5c65159SKalle Valo 			memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
857d5c65159SKalle Valo 		}
858d5c65159SKalle Valo 		if (arg->hidden_ssid)
859d5c65159SKalle Valo 			cmd->flags |= WMI_VDEV_START_HIDDEN_SSID;
860d5c65159SKalle Valo 		if (arg->pmf_enabled)
861d5c65159SKalle Valo 			cmd->flags |= WMI_VDEV_START_PMF_ENABLED;
862d5c65159SKalle Valo 	}
863d5c65159SKalle Valo 
864d5c65159SKalle Valo 	cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED;
865d5c65159SKalle Valo 
866d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
867d5c65159SKalle Valo 	chan = ptr;
868d5c65159SKalle Valo 
869d5c65159SKalle Valo 	ath11k_wmi_put_wmi_channel(chan, arg);
870d5c65159SKalle Valo 
871d5c65159SKalle Valo 	chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) |
872d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
873d5c65159SKalle Valo 				      sizeof(*chan) - TLV_HDR_SIZE);
874d5c65159SKalle Valo 	ptr += sizeof(*chan);
875d5c65159SKalle Valo 
876d5c65159SKalle Valo 	tlv = ptr;
877d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
878d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, 0);
879d5c65159SKalle Valo 
880d5c65159SKalle Valo 	/* Note: This is a nested TLV containing:
881d5c65159SKalle Valo 	 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
882d5c65159SKalle Valo 	 */
883d5c65159SKalle Valo 
884d5c65159SKalle Valo 	ptr += sizeof(*tlv);
885d5c65159SKalle Valo 
886d5c65159SKalle Valo 	if (restart)
887d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb,
888d5c65159SKalle Valo 					  WMI_VDEV_RESTART_REQUEST_CMDID);
889d5c65159SKalle Valo 	else
890d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb,
891d5c65159SKalle Valo 					  WMI_VDEV_START_REQUEST_CMDID);
892d5c65159SKalle Valo 	if (ret) {
893d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n",
894d5c65159SKalle Valo 			    restart ? "restart" : "start");
895d5c65159SKalle Valo 		dev_kfree_skb(skb);
896d5c65159SKalle Valo 	}
897d5c65159SKalle Valo 
898d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "vdev %s id 0x%x freq 0x%x mode 0x%x\n",
899d5c65159SKalle Valo 		   restart ? "restart" : "start", arg->vdev_id,
900d5c65159SKalle Valo 		   arg->channel.freq, arg->channel.mode);
901d5c65159SKalle Valo 
902d5c65159SKalle Valo 	return ret;
903d5c65159SKalle Valo }
904d5c65159SKalle Valo 
905d5c65159SKalle Valo int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
906d5c65159SKalle Valo {
907d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
908d5c65159SKalle Valo 	struct wmi_vdev_up_cmd *cmd;
909d5c65159SKalle Valo 	struct sk_buff *skb;
910d5c65159SKalle Valo 	int ret;
911d5c65159SKalle Valo 
9126bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
913d5c65159SKalle Valo 	if (!skb)
914d5c65159SKalle Valo 		return -ENOMEM;
915d5c65159SKalle Valo 
916d5c65159SKalle Valo 	cmd = (struct wmi_vdev_up_cmd *)skb->data;
917d5c65159SKalle Valo 
918d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) |
919d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
920d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
921d5c65159SKalle Valo 	cmd->vdev_assoc_id = aid;
922d5c65159SKalle Valo 
923d5c65159SKalle Valo 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
924d5c65159SKalle Valo 
925d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID);
926d5c65159SKalle Valo 	if (ret) {
927d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n");
928d5c65159SKalle Valo 		dev_kfree_skb(skb);
929d5c65159SKalle Valo 	}
930d5c65159SKalle Valo 
931d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
932d5c65159SKalle Valo 		   "WMI mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
933d5c65159SKalle Valo 		   vdev_id, aid, bssid);
934d5c65159SKalle Valo 
935d5c65159SKalle Valo 	return ret;
936d5c65159SKalle Valo }
937d5c65159SKalle Valo 
938d5c65159SKalle Valo int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar,
939d5c65159SKalle Valo 				    struct peer_create_params *param)
940d5c65159SKalle Valo {
941d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
942d5c65159SKalle Valo 	struct wmi_peer_create_cmd *cmd;
943d5c65159SKalle Valo 	struct sk_buff *skb;
944d5c65159SKalle Valo 	int ret;
945d5c65159SKalle Valo 
9466bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
947d5c65159SKalle Valo 	if (!skb)
948d5c65159SKalle Valo 		return -ENOMEM;
949d5c65159SKalle Valo 
950d5c65159SKalle Valo 	cmd = (struct wmi_peer_create_cmd *)skb->data;
951d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) |
952d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
953d5c65159SKalle Valo 
954d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr);
955d5c65159SKalle Valo 	cmd->peer_type = param->peer_type;
956d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
957d5c65159SKalle Valo 
958d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID);
959d5c65159SKalle Valo 	if (ret) {
960d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n");
961d5c65159SKalle Valo 		dev_kfree_skb(skb);
962d5c65159SKalle Valo 	}
963d5c65159SKalle Valo 
964d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
965d5c65159SKalle Valo 		   "WMI peer create vdev_id %d peer_addr %pM\n",
966d5c65159SKalle Valo 		   param->vdev_id, param->peer_addr);
967d5c65159SKalle Valo 
968d5c65159SKalle Valo 	return ret;
969d5c65159SKalle Valo }
970d5c65159SKalle Valo 
971d5c65159SKalle Valo int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar,
972d5c65159SKalle Valo 				    const u8 *peer_addr, u8 vdev_id)
973d5c65159SKalle Valo {
974d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
975d5c65159SKalle Valo 	struct wmi_peer_delete_cmd *cmd;
976d5c65159SKalle Valo 	struct sk_buff *skb;
977d5c65159SKalle Valo 	int ret;
978d5c65159SKalle Valo 
9796bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
980d5c65159SKalle Valo 	if (!skb)
981d5c65159SKalle Valo 		return -ENOMEM;
982d5c65159SKalle Valo 
983d5c65159SKalle Valo 	cmd = (struct wmi_peer_delete_cmd *)skb->data;
984d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) |
985d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
986d5c65159SKalle Valo 
987d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
988d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
989d5c65159SKalle Valo 
990d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
991d5c65159SKalle Valo 		   "WMI peer delete vdev_id %d peer_addr %pM\n",
992d5c65159SKalle Valo 		   vdev_id,  peer_addr);
993d5c65159SKalle Valo 
994d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID);
995d5c65159SKalle Valo 	if (ret) {
996d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n");
997d5c65159SKalle Valo 		dev_kfree_skb(skb);
998d5c65159SKalle Valo 	}
999d5c65159SKalle Valo 
1000d5c65159SKalle Valo 	return ret;
1001d5c65159SKalle Valo }
1002d5c65159SKalle Valo 
1003d5c65159SKalle Valo int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar,
1004d5c65159SKalle Valo 				       struct pdev_set_regdomain_params *param)
1005d5c65159SKalle Valo {
1006d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1007d5c65159SKalle Valo 	struct wmi_pdev_set_regdomain_cmd *cmd;
1008d5c65159SKalle Valo 	struct sk_buff *skb;
1009d5c65159SKalle Valo 	int ret;
1010d5c65159SKalle Valo 
10116bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1012d5c65159SKalle Valo 	if (!skb)
1013d5c65159SKalle Valo 		return -ENOMEM;
1014d5c65159SKalle Valo 
1015d5c65159SKalle Valo 	cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1016d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1017d5c65159SKalle Valo 				     WMI_TAG_PDEV_SET_REGDOMAIN_CMD) |
1018d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1019d5c65159SKalle Valo 
1020d5c65159SKalle Valo 	cmd->reg_domain = param->current_rd_in_use;
1021d5c65159SKalle Valo 	cmd->reg_domain_2g = param->current_rd_2g;
1022d5c65159SKalle Valo 	cmd->reg_domain_5g = param->current_rd_5g;
1023d5c65159SKalle Valo 	cmd->conformance_test_limit_2g = param->ctl_2g;
1024d5c65159SKalle Valo 	cmd->conformance_test_limit_5g = param->ctl_5g;
1025d5c65159SKalle Valo 	cmd->dfs_domain = param->dfs_domain;
1026d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
1027d5c65159SKalle Valo 
1028d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1029d5c65159SKalle Valo 		   "WMI pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n",
1030d5c65159SKalle Valo 		   param->current_rd_in_use, param->current_rd_2g,
1031d5c65159SKalle Valo 		   param->current_rd_5g, param->dfs_domain, param->pdev_id);
1032d5c65159SKalle Valo 
1033d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1034d5c65159SKalle Valo 	if (ret) {
1035d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1036d5c65159SKalle Valo 			    "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n");
1037d5c65159SKalle Valo 		dev_kfree_skb(skb);
1038d5c65159SKalle Valo 	}
1039d5c65159SKalle Valo 
1040d5c65159SKalle Valo 	return ret;
1041d5c65159SKalle Valo }
1042d5c65159SKalle Valo 
1043d5c65159SKalle Valo int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr,
1044d5c65159SKalle Valo 			      u32 vdev_id, u32 param_id, u32 param_val)
1045d5c65159SKalle Valo {
1046d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1047d5c65159SKalle Valo 	struct wmi_peer_set_param_cmd *cmd;
1048d5c65159SKalle Valo 	struct sk_buff *skb;
1049d5c65159SKalle Valo 	int ret;
1050d5c65159SKalle Valo 
10516bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1052d5c65159SKalle Valo 	if (!skb)
1053d5c65159SKalle Valo 		return -ENOMEM;
1054d5c65159SKalle Valo 
1055d5c65159SKalle Valo 	cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1056d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) |
1057d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1058d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1059d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1060d5c65159SKalle Valo 	cmd->param_id = param_id;
1061d5c65159SKalle Valo 	cmd->param_value = param_val;
1062d5c65159SKalle Valo 
1063d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID);
1064d5c65159SKalle Valo 	if (ret) {
1065d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n");
1066d5c65159SKalle Valo 		dev_kfree_skb(skb);
1067d5c65159SKalle Valo 	}
1068d5c65159SKalle Valo 
1069d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1070d5c65159SKalle Valo 		   "WMI vdev %d peer 0x%pM set param %d value %d\n",
1071d5c65159SKalle Valo 		   vdev_id, peer_addr, param_id, param_val);
1072d5c65159SKalle Valo 
1073d5c65159SKalle Valo 	return ret;
1074d5c65159SKalle Valo }
1075d5c65159SKalle Valo 
1076d5c65159SKalle Valo int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar,
1077d5c65159SKalle Valo 					u8 peer_addr[ETH_ALEN],
1078d5c65159SKalle Valo 					struct peer_flush_params *param)
1079d5c65159SKalle Valo {
1080d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1081d5c65159SKalle Valo 	struct wmi_peer_flush_tids_cmd *cmd;
1082d5c65159SKalle Valo 	struct sk_buff *skb;
1083d5c65159SKalle Valo 	int ret;
1084d5c65159SKalle Valo 
10856bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1086d5c65159SKalle Valo 	if (!skb)
1087d5c65159SKalle Valo 		return -ENOMEM;
1088d5c65159SKalle Valo 
1089d5c65159SKalle Valo 	cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1090d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) |
1091d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1092d5c65159SKalle Valo 
1093d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1094d5c65159SKalle Valo 	cmd->peer_tid_bitmap = param->peer_tid_bitmap;
1095d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1096d5c65159SKalle Valo 
1097d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1098d5c65159SKalle Valo 	if (ret) {
1099d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1100d5c65159SKalle Valo 			    "failed to send WMI_PEER_FLUSH_TIDS cmd\n");
1101d5c65159SKalle Valo 		dev_kfree_skb(skb);
1102d5c65159SKalle Valo 	}
1103d5c65159SKalle Valo 
1104d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1105d5c65159SKalle Valo 		   "WMI peer flush vdev_id %d peer_addr %pM tids %08x\n",
1106d5c65159SKalle Valo 		   param->vdev_id, peer_addr, param->peer_tid_bitmap);
1107d5c65159SKalle Valo 
1108d5c65159SKalle Valo 	return ret;
1109d5c65159SKalle Valo }
1110d5c65159SKalle Valo 
1111d5c65159SKalle Valo int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar,
1112d5c65159SKalle Valo 					   int vdev_id, const u8 *addr,
1113d5c65159SKalle Valo 					   dma_addr_t paddr, u8 tid,
1114d5c65159SKalle Valo 					   u8 ba_window_size_valid,
1115d5c65159SKalle Valo 					   u32 ba_window_size)
1116d5c65159SKalle Valo {
1117d5c65159SKalle Valo 	struct wmi_peer_reorder_queue_setup_cmd *cmd;
1118d5c65159SKalle Valo 	struct sk_buff *skb;
1119d5c65159SKalle Valo 	int ret;
1120d5c65159SKalle Valo 
11216bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
1122d5c65159SKalle Valo 	if (!skb)
1123d5c65159SKalle Valo 		return -ENOMEM;
1124d5c65159SKalle Valo 
1125d5c65159SKalle Valo 	cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data;
1126d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1127d5c65159SKalle Valo 				     WMI_TAG_REORDER_QUEUE_SETUP_CMD) |
1128d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1129d5c65159SKalle Valo 
1130d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, addr);
1131d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1132d5c65159SKalle Valo 	cmd->tid = tid;
1133d5c65159SKalle Valo 	cmd->queue_ptr_lo = lower_32_bits(paddr);
1134d5c65159SKalle Valo 	cmd->queue_ptr_hi = upper_32_bits(paddr);
1135d5c65159SKalle Valo 	cmd->queue_no = tid;
1136d5c65159SKalle Valo 	cmd->ba_window_size_valid = ba_window_size_valid;
1137d5c65159SKalle Valo 	cmd->ba_window_size = ba_window_size;
1138d5c65159SKalle Valo 
1139d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
1140d5c65159SKalle Valo 				  WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1141d5c65159SKalle Valo 	if (ret) {
1142d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1143d5c65159SKalle Valo 			    "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n");
1144d5c65159SKalle Valo 		dev_kfree_skb(skb);
1145d5c65159SKalle Valo 	}
1146d5c65159SKalle Valo 
1147d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1148d5c65159SKalle Valo 		   "wmi rx reorder queue setup addr %pM vdev_id %d tid %d\n",
1149d5c65159SKalle Valo 		   addr, vdev_id, tid);
1150d5c65159SKalle Valo 
1151d5c65159SKalle Valo 	return ret;
1152d5c65159SKalle Valo }
1153d5c65159SKalle Valo 
1154d5c65159SKalle Valo int
1155d5c65159SKalle Valo ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar,
1156d5c65159SKalle Valo 				 struct rx_reorder_queue_remove_params *param)
1157d5c65159SKalle Valo {
1158d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1159d5c65159SKalle Valo 	struct wmi_peer_reorder_queue_remove_cmd *cmd;
1160d5c65159SKalle Valo 	struct sk_buff *skb;
1161d5c65159SKalle Valo 	int ret;
1162d5c65159SKalle Valo 
11636bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1164d5c65159SKalle Valo 	if (!skb)
1165d5c65159SKalle Valo 		return -ENOMEM;
1166d5c65159SKalle Valo 
1167d5c65159SKalle Valo 	cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data;
1168d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1169d5c65159SKalle Valo 				     WMI_TAG_REORDER_QUEUE_REMOVE_CMD) |
1170d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1171d5c65159SKalle Valo 
1172d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr);
1173d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1174d5c65159SKalle Valo 	cmd->tid_mask = param->peer_tid_bitmap;
1175d5c65159SKalle Valo 
1176d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1177d5c65159SKalle Valo 		   "%s: peer_macaddr %pM vdev_id %d, tid_map %d", __func__,
1178d5c65159SKalle Valo 		   param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap);
1179d5c65159SKalle Valo 
1180d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
1181d5c65159SKalle Valo 				  WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
1182d5c65159SKalle Valo 	if (ret) {
1183d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1184d5c65159SKalle Valo 			    "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID");
1185d5c65159SKalle Valo 		dev_kfree_skb(skb);
1186d5c65159SKalle Valo 	}
1187d5c65159SKalle Valo 
1188d5c65159SKalle Valo 	return ret;
1189d5c65159SKalle Valo }
1190d5c65159SKalle Valo 
1191d5c65159SKalle Valo int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id,
1192d5c65159SKalle Valo 			      u32 param_value, u8 pdev_id)
1193d5c65159SKalle Valo {
1194d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1195d5c65159SKalle Valo 	struct wmi_pdev_set_param_cmd *cmd;
1196d5c65159SKalle Valo 	struct sk_buff *skb;
1197d5c65159SKalle Valo 	int ret;
1198d5c65159SKalle Valo 
11996bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1200d5c65159SKalle Valo 	if (!skb)
1201d5c65159SKalle Valo 		return -ENOMEM;
1202d5c65159SKalle Valo 
1203d5c65159SKalle Valo 	cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1204d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) |
1205d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1206d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1207d5c65159SKalle Valo 	cmd->param_id = param_id;
1208d5c65159SKalle Valo 	cmd->param_value = param_value;
1209d5c65159SKalle Valo 
1210d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID);
1211d5c65159SKalle Valo 	if (ret) {
1212d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1213d5c65159SKalle Valo 		dev_kfree_skb(skb);
1214d5c65159SKalle Valo 	}
1215d5c65159SKalle Valo 
1216d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1217d5c65159SKalle Valo 		   "WMI pdev set param %d pdev id %d value %d\n",
1218d5c65159SKalle Valo 		   param_id, pdev_id, param_value);
1219d5c65159SKalle Valo 
1220d5c65159SKalle Valo 	return ret;
1221d5c65159SKalle Valo }
1222d5c65159SKalle Valo 
122397c63746SJohn Crispin int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id, u32 enable)
122497c63746SJohn Crispin {
122597c63746SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
122697c63746SJohn Crispin 	struct wmi_pdev_set_ps_mode_cmd *cmd;
122797c63746SJohn Crispin 	struct sk_buff *skb;
122897c63746SJohn Crispin 	int ret;
122997c63746SJohn Crispin 
12306bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
123197c63746SJohn Crispin 	if (!skb)
123297c63746SJohn Crispin 		return -ENOMEM;
123397c63746SJohn Crispin 
123497c63746SJohn Crispin 	cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data;
123597c63746SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) |
123697c63746SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
123797c63746SJohn Crispin 	cmd->vdev_id = vdev_id;
123897c63746SJohn Crispin 	cmd->sta_ps_mode = enable;
123997c63746SJohn Crispin 
124097c63746SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID);
124197c63746SJohn Crispin 	if (ret) {
124297c63746SJohn Crispin 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
124397c63746SJohn Crispin 		dev_kfree_skb(skb);
124497c63746SJohn Crispin 	}
124597c63746SJohn Crispin 
124697c63746SJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
124797c63746SJohn Crispin 		   "WMI vdev set psmode %d vdev id %d\n",
124897c63746SJohn Crispin 		   enable, vdev_id);
124997c63746SJohn Crispin 
125097c63746SJohn Crispin 	return ret;
125197c63746SJohn Crispin }
125297c63746SJohn Crispin 
1253d5c65159SKalle Valo int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt,
1254d5c65159SKalle Valo 			    u32 pdev_id)
1255d5c65159SKalle Valo {
1256d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1257d5c65159SKalle Valo 	struct wmi_pdev_suspend_cmd *cmd;
1258d5c65159SKalle Valo 	struct sk_buff *skb;
1259d5c65159SKalle Valo 	int ret;
1260d5c65159SKalle Valo 
12616bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1262d5c65159SKalle Valo 	if (!skb)
1263d5c65159SKalle Valo 		return -ENOMEM;
1264d5c65159SKalle Valo 
1265d5c65159SKalle Valo 	cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1266d5c65159SKalle Valo 
1267d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) |
1268d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1269d5c65159SKalle Valo 
1270d5c65159SKalle Valo 	cmd->suspend_opt = suspend_opt;
1271d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1272d5c65159SKalle Valo 
1273d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID);
1274d5c65159SKalle Valo 	if (ret) {
1275d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n");
1276d5c65159SKalle Valo 		dev_kfree_skb(skb);
1277d5c65159SKalle Valo 	}
1278d5c65159SKalle Valo 
1279d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1280d5c65159SKalle Valo 		   "WMI pdev suspend pdev_id %d\n", pdev_id);
1281d5c65159SKalle Valo 
1282d5c65159SKalle Valo 	return ret;
1283d5c65159SKalle Valo }
1284d5c65159SKalle Valo 
1285d5c65159SKalle Valo int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id)
1286d5c65159SKalle Valo {
1287d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1288d5c65159SKalle Valo 	struct wmi_pdev_resume_cmd *cmd;
1289d5c65159SKalle Valo 	struct sk_buff *skb;
1290d5c65159SKalle Valo 	int ret;
1291d5c65159SKalle Valo 
12926bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1293d5c65159SKalle Valo 	if (!skb)
1294d5c65159SKalle Valo 		return -ENOMEM;
1295d5c65159SKalle Valo 
1296d5c65159SKalle Valo 	cmd = (struct wmi_pdev_resume_cmd *)skb->data;
1297d5c65159SKalle Valo 
1298d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) |
1299d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1300d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1301d5c65159SKalle Valo 
1302d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1303d5c65159SKalle Valo 		   "WMI pdev resume pdev id %d\n", pdev_id);
1304d5c65159SKalle Valo 
1305d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID);
1306d5c65159SKalle Valo 	if (ret) {
1307d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n");
1308d5c65159SKalle Valo 		dev_kfree_skb(skb);
1309d5c65159SKalle Valo 	}
1310d5c65159SKalle Valo 
1311d5c65159SKalle Valo 	return ret;
1312d5c65159SKalle Valo }
1313d5c65159SKalle Valo 
1314d5c65159SKalle Valo /* TODO FW Support for the cmd is not available yet.
1315d5c65159SKalle Valo  * Can be tested once the command and corresponding
1316d5c65159SKalle Valo  * event is implemented in FW
1317d5c65159SKalle Valo  */
1318d5c65159SKalle Valo int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar,
1319d5c65159SKalle Valo 					  enum wmi_bss_chan_info_req_type type)
1320d5c65159SKalle Valo {
1321d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1322d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_req_cmd *cmd;
1323d5c65159SKalle Valo 	struct sk_buff *skb;
1324d5c65159SKalle Valo 	int ret;
1325d5c65159SKalle Valo 
13266bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1327d5c65159SKalle Valo 	if (!skb)
1328d5c65159SKalle Valo 		return -ENOMEM;
1329d5c65159SKalle Valo 
1330d5c65159SKalle Valo 	cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data;
1331d5c65159SKalle Valo 
1332d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1333d5c65159SKalle Valo 				     WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) |
1334d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1335d5c65159SKalle Valo 	cmd->req_type = type;
1336d5c65159SKalle Valo 
1337d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1338d5c65159SKalle Valo 		   "WMI bss chan info req type %d\n", type);
1339d5c65159SKalle Valo 
1340d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
1341d5c65159SKalle Valo 				  WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID);
1342d5c65159SKalle Valo 	if (ret) {
1343d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1344d5c65159SKalle Valo 			    "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n");
1345d5c65159SKalle Valo 		dev_kfree_skb(skb);
1346d5c65159SKalle Valo 	}
1347d5c65159SKalle Valo 
1348d5c65159SKalle Valo 	return ret;
1349d5c65159SKalle Valo }
1350d5c65159SKalle Valo 
1351d5c65159SKalle Valo int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr,
1352d5c65159SKalle Valo 					struct ap_ps_params *param)
1353d5c65159SKalle Valo {
1354d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1355d5c65159SKalle Valo 	struct wmi_ap_ps_peer_cmd *cmd;
1356d5c65159SKalle Valo 	struct sk_buff *skb;
1357d5c65159SKalle Valo 	int ret;
1358d5c65159SKalle Valo 
13596bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1360d5c65159SKalle Valo 	if (!skb)
1361d5c65159SKalle Valo 		return -ENOMEM;
1362d5c65159SKalle Valo 
1363d5c65159SKalle Valo 	cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1364d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) |
1365d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1366d5c65159SKalle Valo 
1367d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1368d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1369d5c65159SKalle Valo 	cmd->param = param->param;
1370d5c65159SKalle Valo 	cmd->value = param->value;
1371d5c65159SKalle Valo 
1372d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1373d5c65159SKalle Valo 	if (ret) {
1374d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1375d5c65159SKalle Valo 			    "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n");
1376d5c65159SKalle Valo 		dev_kfree_skb(skb);
1377d5c65159SKalle Valo 	}
1378d5c65159SKalle Valo 
1379d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1380d5c65159SKalle Valo 		   "WMI set ap ps vdev id %d peer %pM param %d value %d\n",
1381d5c65159SKalle Valo 		   param->vdev_id, peer_addr, param->param, param->value);
1382d5c65159SKalle Valo 
1383d5c65159SKalle Valo 	return ret;
1384d5c65159SKalle Valo }
1385d5c65159SKalle Valo 
1386d5c65159SKalle Valo int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id,
1387d5c65159SKalle Valo 				u32 param, u32 param_value)
1388d5c65159SKalle Valo {
1389d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1390d5c65159SKalle Valo 	struct wmi_sta_powersave_param_cmd *cmd;
1391d5c65159SKalle Valo 	struct sk_buff *skb;
1392d5c65159SKalle Valo 	int ret;
1393d5c65159SKalle Valo 
13946bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1395d5c65159SKalle Valo 	if (!skb)
1396d5c65159SKalle Valo 		return -ENOMEM;
1397d5c65159SKalle Valo 
1398d5c65159SKalle Valo 	cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1399d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1400d5c65159SKalle Valo 				     WMI_TAG_STA_POWERSAVE_PARAM_CMD) |
1401d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1402d5c65159SKalle Valo 
1403d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1404d5c65159SKalle Valo 	cmd->param = param;
1405d5c65159SKalle Valo 	cmd->value = param_value;
1406d5c65159SKalle Valo 
1407d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1408d5c65159SKalle Valo 		   "WMI set sta ps vdev_id %d param %d value %d\n",
1409d5c65159SKalle Valo 		   vdev_id, param, param_value);
1410d5c65159SKalle Valo 
1411d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1412d5c65159SKalle Valo 	if (ret) {
1413d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID");
1414d5c65159SKalle Valo 		dev_kfree_skb(skb);
1415d5c65159SKalle Valo 	}
1416d5c65159SKalle Valo 
1417d5c65159SKalle Valo 	return ret;
1418d5c65159SKalle Valo }
1419d5c65159SKalle Valo 
1420d5c65159SKalle Valo int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms)
1421d5c65159SKalle Valo {
1422d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1423d5c65159SKalle Valo 	struct wmi_force_fw_hang_cmd *cmd;
1424d5c65159SKalle Valo 	struct sk_buff *skb;
1425d5c65159SKalle Valo 	int ret, len;
1426d5c65159SKalle Valo 
1427d5c65159SKalle Valo 	len = sizeof(*cmd);
1428d5c65159SKalle Valo 
14296bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1430d5c65159SKalle Valo 	if (!skb)
1431d5c65159SKalle Valo 		return -ENOMEM;
1432d5c65159SKalle Valo 
1433d5c65159SKalle Valo 	cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
1434d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) |
1435d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1436d5c65159SKalle Valo 
1437d5c65159SKalle Valo 	cmd->type = type;
1438d5c65159SKalle Valo 	cmd->delay_time_ms = delay_time_ms;
1439d5c65159SKalle Valo 
1440d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID);
1441d5c65159SKalle Valo 
1442d5c65159SKalle Valo 	if (ret) {
1443d5c65159SKalle Valo 		ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID");
1444d5c65159SKalle Valo 		dev_kfree_skb(skb);
1445d5c65159SKalle Valo 	}
1446d5c65159SKalle Valo 	return ret;
1447d5c65159SKalle Valo }
1448d5c65159SKalle Valo 
1449d5c65159SKalle Valo int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id,
1450d5c65159SKalle Valo 				  u32 param_id, u32 param_value)
1451d5c65159SKalle Valo {
1452d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1453d5c65159SKalle Valo 	struct wmi_vdev_set_param_cmd *cmd;
1454d5c65159SKalle Valo 	struct sk_buff *skb;
1455d5c65159SKalle Valo 	int ret;
1456d5c65159SKalle Valo 
14576bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1458d5c65159SKalle Valo 	if (!skb)
1459d5c65159SKalle Valo 		return -ENOMEM;
1460d5c65159SKalle Valo 
1461d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1462d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) |
1463d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1464d5c65159SKalle Valo 
1465d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1466d5c65159SKalle Valo 	cmd->param_id = param_id;
1467d5c65159SKalle Valo 	cmd->param_value = param_value;
1468d5c65159SKalle Valo 
1469d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID);
1470d5c65159SKalle Valo 	if (ret) {
1471d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1472d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_PARAM_CMDID\n");
1473d5c65159SKalle Valo 		dev_kfree_skb(skb);
1474d5c65159SKalle Valo 	}
1475d5c65159SKalle Valo 
1476d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1477d5c65159SKalle Valo 		   "WMI vdev id 0x%x set param %d value %d\n",
1478d5c65159SKalle Valo 		   vdev_id, param_id, param_value);
1479d5c65159SKalle Valo 
1480d5c65159SKalle Valo 	return ret;
1481d5c65159SKalle Valo }
1482d5c65159SKalle Valo 
1483d5c65159SKalle Valo int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar,
1484d5c65159SKalle Valo 				      struct stats_request_params *param)
1485d5c65159SKalle Valo {
1486d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1487d5c65159SKalle Valo 	struct wmi_request_stats_cmd *cmd;
1488d5c65159SKalle Valo 	struct sk_buff *skb;
1489d5c65159SKalle Valo 	int ret;
1490d5c65159SKalle Valo 
14916bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1492d5c65159SKalle Valo 	if (!skb)
1493d5c65159SKalle Valo 		return -ENOMEM;
1494d5c65159SKalle Valo 
1495d5c65159SKalle Valo 	cmd = (struct wmi_request_stats_cmd *)skb->data;
1496d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) |
1497d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1498d5c65159SKalle Valo 
1499d5c65159SKalle Valo 	cmd->stats_id = param->stats_id;
1500d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1501d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
1502d5c65159SKalle Valo 
1503d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID);
1504d5c65159SKalle Valo 	if (ret) {
1505d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n");
1506d5c65159SKalle Valo 		dev_kfree_skb(skb);
1507d5c65159SKalle Valo 	}
1508d5c65159SKalle Valo 
1509d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1510d5c65159SKalle Valo 		   "WMI request stats 0x%x vdev id %d pdev id %d\n",
1511d5c65159SKalle Valo 		   param->stats_id, param->vdev_id, param->pdev_id);
1512d5c65159SKalle Valo 
1513d5c65159SKalle Valo 	return ret;
1514d5c65159SKalle Valo }
1515d5c65159SKalle Valo 
1516a41d1034SPradeep Kumar Chitrapu int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar)
1517a41d1034SPradeep Kumar Chitrapu {
1518a41d1034SPradeep Kumar Chitrapu 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1519a41d1034SPradeep Kumar Chitrapu 	struct wmi_get_pdev_temperature_cmd *cmd;
1520a41d1034SPradeep Kumar Chitrapu 	struct sk_buff *skb;
1521a41d1034SPradeep Kumar Chitrapu 	int ret;
1522a41d1034SPradeep Kumar Chitrapu 
1523a41d1034SPradeep Kumar Chitrapu 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1524a41d1034SPradeep Kumar Chitrapu 	if (!skb)
1525a41d1034SPradeep Kumar Chitrapu 		return -ENOMEM;
1526a41d1034SPradeep Kumar Chitrapu 
1527a41d1034SPradeep Kumar Chitrapu 	cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data;
1528a41d1034SPradeep Kumar Chitrapu 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) |
1529a41d1034SPradeep Kumar Chitrapu 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1530a41d1034SPradeep Kumar Chitrapu 	cmd->pdev_id = ar->pdev->pdev_id;
1531a41d1034SPradeep Kumar Chitrapu 
1532a41d1034SPradeep Kumar Chitrapu 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID);
1533a41d1034SPradeep Kumar Chitrapu 	if (ret) {
1534a41d1034SPradeep Kumar Chitrapu 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n");
1535a41d1034SPradeep Kumar Chitrapu 		dev_kfree_skb(skb);
1536a41d1034SPradeep Kumar Chitrapu 	}
1537a41d1034SPradeep Kumar Chitrapu 
1538a41d1034SPradeep Kumar Chitrapu 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1539a41d1034SPradeep Kumar Chitrapu 		   "WMI pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id);
1540a41d1034SPradeep Kumar Chitrapu 
1541a41d1034SPradeep Kumar Chitrapu 	return ret;
1542a41d1034SPradeep Kumar Chitrapu }
1543a41d1034SPradeep Kumar Chitrapu 
1544d5c65159SKalle Valo int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar,
1545d5c65159SKalle Valo 					    u32 vdev_id, u32 bcn_ctrl_op)
1546d5c65159SKalle Valo {
1547d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1548d5c65159SKalle Valo 	struct wmi_bcn_offload_ctrl_cmd *cmd;
1549d5c65159SKalle Valo 	struct sk_buff *skb;
1550d5c65159SKalle Valo 	int ret;
1551d5c65159SKalle Valo 
15526bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1553d5c65159SKalle Valo 	if (!skb)
1554d5c65159SKalle Valo 		return -ENOMEM;
1555d5c65159SKalle Valo 
1556d5c65159SKalle Valo 	cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data;
1557d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1558d5c65159SKalle Valo 				     WMI_TAG_BCN_OFFLOAD_CTRL_CMD) |
1559d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1560d5c65159SKalle Valo 
1561d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1562d5c65159SKalle Valo 	cmd->bcn_ctrl_op = bcn_ctrl_op;
1563d5c65159SKalle Valo 
1564d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1565d5c65159SKalle Valo 		   "WMI bcn ctrl offload vdev id %d ctrl_op %d\n",
1566d5c65159SKalle Valo 		   vdev_id, bcn_ctrl_op);
1567d5c65159SKalle Valo 
1568d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID);
1569d5c65159SKalle Valo 	if (ret) {
1570d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1571d5c65159SKalle Valo 			    "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n");
1572d5c65159SKalle Valo 		dev_kfree_skb(skb);
1573d5c65159SKalle Valo 	}
1574d5c65159SKalle Valo 
1575d5c65159SKalle Valo 	return ret;
1576d5c65159SKalle Valo }
1577d5c65159SKalle Valo 
1578d5c65159SKalle Valo int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id,
1579d5c65159SKalle Valo 			struct ieee80211_mutable_offsets *offs,
1580d5c65159SKalle Valo 			struct sk_buff *bcn)
1581d5c65159SKalle Valo {
1582d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1583d5c65159SKalle Valo 	struct wmi_bcn_tmpl_cmd *cmd;
1584d5c65159SKalle Valo 	struct wmi_bcn_prb_info *bcn_prb_info;
1585d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1586d5c65159SKalle Valo 	struct sk_buff *skb;
1587d5c65159SKalle Valo 	void *ptr;
1588d5c65159SKalle Valo 	int ret, len;
1589d5c65159SKalle Valo 	size_t aligned_len = roundup(bcn->len, 4);
1590d5c65159SKalle Valo 
1591d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len;
1592d5c65159SKalle Valo 
15936bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1594d5c65159SKalle Valo 	if (!skb)
1595d5c65159SKalle Valo 		return -ENOMEM;
1596d5c65159SKalle Valo 
1597d5c65159SKalle Valo 	cmd = (struct wmi_bcn_tmpl_cmd *)skb->data;
1598d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) |
1599d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1600d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1601d5c65159SKalle Valo 	cmd->tim_ie_offset = offs->tim_offset;
16028552a434SJohn Crispin 	cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0];
16038552a434SJohn Crispin 	cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1];
1604d5c65159SKalle Valo 	cmd->buf_len = bcn->len;
1605d5c65159SKalle Valo 
1606d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
1607d5c65159SKalle Valo 
1608d5c65159SKalle Valo 	bcn_prb_info = ptr;
1609d5c65159SKalle Valo 	len = sizeof(*bcn_prb_info);
1610d5c65159SKalle Valo 	bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1611d5c65159SKalle Valo 					      WMI_TAG_BCN_PRB_INFO) |
1612d5c65159SKalle Valo 				   FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1613d5c65159SKalle Valo 	bcn_prb_info->caps = 0;
1614d5c65159SKalle Valo 	bcn_prb_info->erp = 0;
1615d5c65159SKalle Valo 
1616d5c65159SKalle Valo 	ptr += sizeof(*bcn_prb_info);
1617d5c65159SKalle Valo 
1618d5c65159SKalle Valo 	tlv = ptr;
1619d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1620d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
1621d5c65159SKalle Valo 	memcpy(tlv->value, bcn->data, bcn->len);
1622d5c65159SKalle Valo 
1623d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID);
1624d5c65159SKalle Valo 	if (ret) {
1625d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n");
1626d5c65159SKalle Valo 		dev_kfree_skb(skb);
1627d5c65159SKalle Valo 	}
1628d5c65159SKalle Valo 
1629d5c65159SKalle Valo 	return ret;
1630d5c65159SKalle Valo }
1631d5c65159SKalle Valo 
1632d5c65159SKalle Valo int ath11k_wmi_vdev_install_key(struct ath11k *ar,
1633d5c65159SKalle Valo 				struct wmi_vdev_install_key_arg *arg)
1634d5c65159SKalle Valo {
1635d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1636d5c65159SKalle Valo 	struct wmi_vdev_install_key_cmd *cmd;
1637d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1638d5c65159SKalle Valo 	struct sk_buff *skb;
1639d5c65159SKalle Valo 	int ret, len;
1640d5c65159SKalle Valo 	int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t));
1641d5c65159SKalle Valo 
1642d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned;
1643d5c65159SKalle Valo 
16446bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1645d5c65159SKalle Valo 	if (!skb)
1646d5c65159SKalle Valo 		return -ENOMEM;
1647d5c65159SKalle Valo 
1648d5c65159SKalle Valo 	cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1649d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) |
1650d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1651d5c65159SKalle Valo 	cmd->vdev_id = arg->vdev_id;
1652d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1653d5c65159SKalle Valo 	cmd->key_idx = arg->key_idx;
1654d5c65159SKalle Valo 	cmd->key_flags = arg->key_flags;
1655d5c65159SKalle Valo 	cmd->key_cipher = arg->key_cipher;
1656d5c65159SKalle Valo 	cmd->key_len = arg->key_len;
1657d5c65159SKalle Valo 	cmd->key_txmic_len = arg->key_txmic_len;
1658d5c65159SKalle Valo 	cmd->key_rxmic_len = arg->key_rxmic_len;
1659d5c65159SKalle Valo 
1660d5c65159SKalle Valo 	if (arg->key_rsc_counter)
1661d5c65159SKalle Valo 		memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter,
1662d5c65159SKalle Valo 		       sizeof(struct wmi_key_seq_counter));
1663d5c65159SKalle Valo 
1664d5c65159SKalle Valo 	tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
1665d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1666d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, key_len_aligned);
1667d5c65159SKalle Valo 	memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned);
1668d5c65159SKalle Valo 
1669d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1670d5c65159SKalle Valo 	if (ret) {
1671d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1672d5c65159SKalle Valo 			    "failed to send WMI_VDEV_INSTALL_KEY cmd\n");
1673d5c65159SKalle Valo 		dev_kfree_skb(skb);
1674d5c65159SKalle Valo 	}
1675d5c65159SKalle Valo 
1676d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1677d5c65159SKalle Valo 		   "WMI vdev install key idx %d cipher %d len %d\n",
1678d5c65159SKalle Valo 		   arg->key_idx, arg->key_cipher, arg->key_len);
1679d5c65159SKalle Valo 
1680d5c65159SKalle Valo 	return ret;
1681d5c65159SKalle Valo }
1682d5c65159SKalle Valo 
1683d5c65159SKalle Valo static inline void
1684d5c65159SKalle Valo ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd,
1685d5c65159SKalle Valo 			   struct peer_assoc_params *param)
1686d5c65159SKalle Valo {
1687d5c65159SKalle Valo 	cmd->peer_flags = 0;
1688d5c65159SKalle Valo 
1689d5c65159SKalle Valo 	if (param->is_wme_set) {
1690d5c65159SKalle Valo 		if (param->qos_flag)
1691d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_QOS;
1692d5c65159SKalle Valo 		if (param->apsd_flag)
1693d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_APSD;
1694d5c65159SKalle Valo 		if (param->ht_flag)
1695d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_HT;
1696d5c65159SKalle Valo 		if (param->bw_40)
1697d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_40MHZ;
1698d5c65159SKalle Valo 		if (param->bw_80)
1699d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_80MHZ;
1700d5c65159SKalle Valo 		if (param->bw_160)
1701d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_160MHZ;
1702d5c65159SKalle Valo 
1703d5c65159SKalle Valo 		/* Typically if STBC is enabled for VHT it should be enabled
1704d5c65159SKalle Valo 		 * for HT as well
1705d5c65159SKalle Valo 		 **/
1706d5c65159SKalle Valo 		if (param->stbc_flag)
1707d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_STBC;
1708d5c65159SKalle Valo 
1709d5c65159SKalle Valo 		/* Typically if LDPC is enabled for VHT it should be enabled
1710d5c65159SKalle Valo 		 * for HT as well
1711d5c65159SKalle Valo 		 **/
1712d5c65159SKalle Valo 		if (param->ldpc_flag)
1713d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_LDPC;
1714d5c65159SKalle Valo 
1715d5c65159SKalle Valo 		if (param->static_mimops_flag)
1716d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1717d5c65159SKalle Valo 		if (param->dynamic_mimops_flag)
1718d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_DYN_MIMOPS;
1719d5c65159SKalle Valo 		if (param->spatial_mux_flag)
1720d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_SPATIAL_MUX;
1721d5c65159SKalle Valo 		if (param->vht_flag)
1722d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_VHT;
1723d5c65159SKalle Valo 		if (param->he_flag)
1724d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_HE;
17256d293d44SJohn Crispin 		if (param->twt_requester)
17266d293d44SJohn Crispin 			cmd->peer_flags |= WMI_PEER_TWT_REQ;
17276d293d44SJohn Crispin 		if (param->twt_responder)
17286d293d44SJohn Crispin 			cmd->peer_flags |= WMI_PEER_TWT_RESP;
1729d5c65159SKalle Valo 	}
1730d5c65159SKalle Valo 
1731d5c65159SKalle Valo 	/* Suppress authorization for all AUTH modes that need 4-way handshake
1732d5c65159SKalle Valo 	 * (during re-association).
1733d5c65159SKalle Valo 	 * Authorization will be done for these modes on key installation.
1734d5c65159SKalle Valo 	 */
1735d5c65159SKalle Valo 	if (param->auth_flag)
1736d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_AUTH;
173701e34233SVenkateswara Naralasetty 	if (param->need_ptk_4_way) {
1738d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
173901e34233SVenkateswara Naralasetty 		cmd->peer_flags &= ~WMI_PEER_AUTH;
174001e34233SVenkateswara Naralasetty 	}
1741d5c65159SKalle Valo 	if (param->need_gtk_2_way)
1742d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1743d5c65159SKalle Valo 	/* safe mode bypass the 4-way handshake */
1744d5c65159SKalle Valo 	if (param->safe_mode_enabled)
1745d5c65159SKalle Valo 		cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY |
1746d5c65159SKalle Valo 				     WMI_PEER_NEED_GTK_2_WAY);
1747d5c65159SKalle Valo 
1748d5c65159SKalle Valo 	if (param->is_pmf_enabled)
1749d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_PMF;
1750d5c65159SKalle Valo 
1751d5c65159SKalle Valo 	/* Disable AMSDU for station transmit, if user configures it */
1752d5c65159SKalle Valo 	/* Disable AMSDU for AP transmit to 11n Stations, if user configures
1753d5c65159SKalle Valo 	 * it
1754d5c65159SKalle Valo 	 * if (param->amsdu_disable) Add after FW support
1755d5c65159SKalle Valo 	 **/
1756d5c65159SKalle Valo 
1757d5c65159SKalle Valo 	/* Target asserts if node is marked HT and all MCS is set to 0.
1758d5c65159SKalle Valo 	 * Mark the node as non-HT if all the mcs rates are disabled through
1759d5c65159SKalle Valo 	 * iwpriv
1760d5c65159SKalle Valo 	 **/
1761d5c65159SKalle Valo 	if (param->peer_ht_rates.num_rates == 0)
1762d5c65159SKalle Valo 		cmd->peer_flags &= ~WMI_PEER_HT;
1763d5c65159SKalle Valo }
1764d5c65159SKalle Valo 
1765d5c65159SKalle Valo int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar,
1766d5c65159SKalle Valo 				   struct peer_assoc_params *param)
1767d5c65159SKalle Valo {
1768d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1769d5c65159SKalle Valo 	struct wmi_peer_assoc_complete_cmd *cmd;
1770d5c65159SKalle Valo 	struct wmi_vht_rate_set *mcs;
1771d5c65159SKalle Valo 	struct wmi_he_rate_set *he_mcs;
1772d5c65159SKalle Valo 	struct sk_buff *skb;
1773d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1774d5c65159SKalle Valo 	void *ptr;
1775d5c65159SKalle Valo 	u32 peer_legacy_rates_align;
1776d5c65159SKalle Valo 	u32 peer_ht_rates_align;
1777d5c65159SKalle Valo 	int i, ret, len;
1778d5c65159SKalle Valo 
1779d5c65159SKalle Valo 	peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates,
1780d5c65159SKalle Valo 					  sizeof(u32));
1781d5c65159SKalle Valo 	peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates,
1782d5c65159SKalle Valo 				      sizeof(u32));
1783d5c65159SKalle Valo 
1784d5c65159SKalle Valo 	len = sizeof(*cmd) +
1785d5c65159SKalle Valo 	      TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) +
1786d5c65159SKalle Valo 	      TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) +
1787d5c65159SKalle Valo 	      sizeof(*mcs) + TLV_HDR_SIZE +
1788d5c65159SKalle Valo 	      (sizeof(*he_mcs) * param->peer_he_mcs_count);
1789d5c65159SKalle Valo 
17906bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1791d5c65159SKalle Valo 	if (!skb)
1792d5c65159SKalle Valo 		return -ENOMEM;
1793d5c65159SKalle Valo 
1794d5c65159SKalle Valo 	ptr = skb->data;
1795d5c65159SKalle Valo 
1796d5c65159SKalle Valo 	cmd = ptr;
1797d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1798d5c65159SKalle Valo 				     WMI_TAG_PEER_ASSOC_COMPLETE_CMD) |
1799d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1800d5c65159SKalle Valo 
1801d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1802d5c65159SKalle Valo 
1803d5c65159SKalle Valo 	cmd->peer_new_assoc = param->peer_new_assoc;
1804d5c65159SKalle Valo 	cmd->peer_associd = param->peer_associd;
1805d5c65159SKalle Valo 
1806d5c65159SKalle Valo 	ath11k_wmi_copy_peer_flags(cmd, param);
1807d5c65159SKalle Valo 
1808d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac);
1809d5c65159SKalle Valo 
1810d5c65159SKalle Valo 	cmd->peer_rate_caps = param->peer_rate_caps;
1811d5c65159SKalle Valo 	cmd->peer_caps = param->peer_caps;
1812d5c65159SKalle Valo 	cmd->peer_listen_intval = param->peer_listen_intval;
1813d5c65159SKalle Valo 	cmd->peer_ht_caps = param->peer_ht_caps;
1814d5c65159SKalle Valo 	cmd->peer_max_mpdu = param->peer_max_mpdu;
1815d5c65159SKalle Valo 	cmd->peer_mpdu_density = param->peer_mpdu_density;
1816d5c65159SKalle Valo 	cmd->peer_vht_caps = param->peer_vht_caps;
1817d5c65159SKalle Valo 	cmd->peer_phymode = param->peer_phymode;
1818d5c65159SKalle Valo 
1819d5c65159SKalle Valo 	/* Update 11ax capabilities */
1820d5c65159SKalle Valo 	cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0];
1821d5c65159SKalle Valo 	cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1];
1822d5c65159SKalle Valo 	cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal;
182391270d70SPradeep Kumar Chitrapu 	cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz;
1824d5c65159SKalle Valo 	cmd->peer_he_ops = param->peer_he_ops;
1825d5c65159SKalle Valo 	memcpy(&cmd->peer_he_cap_phy, &param->peer_he_cap_phyinfo,
1826d5c65159SKalle Valo 	       sizeof(param->peer_he_cap_phyinfo));
1827d5c65159SKalle Valo 	memcpy(&cmd->peer_ppet, &param->peer_ppet,
1828d5c65159SKalle Valo 	       sizeof(param->peer_ppet));
1829d5c65159SKalle Valo 
1830d5c65159SKalle Valo 	/* Update peer legacy rate information */
1831d5c65159SKalle Valo 	ptr += sizeof(*cmd);
1832d5c65159SKalle Valo 
1833d5c65159SKalle Valo 	tlv = ptr;
1834d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1835d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align);
1836d5c65159SKalle Valo 
1837d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1838d5c65159SKalle Valo 
1839d5c65159SKalle Valo 	cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates;
1840d5c65159SKalle Valo 	memcpy(ptr, param->peer_legacy_rates.rates,
1841d5c65159SKalle Valo 	       param->peer_legacy_rates.num_rates);
1842d5c65159SKalle Valo 
1843d5c65159SKalle Valo 	/* Update peer HT rate information */
1844d5c65159SKalle Valo 	ptr += peer_legacy_rates_align;
1845d5c65159SKalle Valo 
1846d5c65159SKalle Valo 	tlv = ptr;
1847d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1848d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align);
1849d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1850d5c65159SKalle Valo 	cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates;
1851d5c65159SKalle Valo 	memcpy(ptr, param->peer_ht_rates.rates,
1852d5c65159SKalle Valo 	       param->peer_ht_rates.num_rates);
1853d5c65159SKalle Valo 
1854d5c65159SKalle Valo 	/* VHT Rates */
1855d5c65159SKalle Valo 	ptr += peer_ht_rates_align;
1856d5c65159SKalle Valo 
1857d5c65159SKalle Valo 	mcs = ptr;
1858d5c65159SKalle Valo 
1859d5c65159SKalle Valo 	mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) |
1860d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE);
1861d5c65159SKalle Valo 
1862d5c65159SKalle Valo 	cmd->peer_nss = param->peer_nss;
1863d5c65159SKalle Valo 
1864d5c65159SKalle Valo 	/* Update bandwidth-NSS mapping */
1865d5c65159SKalle Valo 	cmd->peer_bw_rxnss_override = 0;
1866d5c65159SKalle Valo 	cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override;
1867d5c65159SKalle Valo 
1868d5c65159SKalle Valo 	if (param->vht_capable) {
1869d5c65159SKalle Valo 		mcs->rx_max_rate = param->rx_max_rate;
1870d5c65159SKalle Valo 		mcs->rx_mcs_set = param->rx_mcs_set;
1871d5c65159SKalle Valo 		mcs->tx_max_rate = param->tx_max_rate;
1872d5c65159SKalle Valo 		mcs->tx_mcs_set = param->tx_mcs_set;
1873d5c65159SKalle Valo 	}
1874d5c65159SKalle Valo 
1875d5c65159SKalle Valo 	/* HE Rates */
1876d5c65159SKalle Valo 	cmd->peer_he_mcs = param->peer_he_mcs_count;
187791270d70SPradeep Kumar Chitrapu 	cmd->min_data_rate = param->min_data_rate;
1878d5c65159SKalle Valo 
1879d5c65159SKalle Valo 	ptr += sizeof(*mcs);
1880d5c65159SKalle Valo 
1881d5c65159SKalle Valo 	len = param->peer_he_mcs_count * sizeof(*he_mcs);
1882d5c65159SKalle Valo 
1883d5c65159SKalle Valo 	tlv = ptr;
1884d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
1885d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
1886d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1887d5c65159SKalle Valo 
1888d5c65159SKalle Valo 	/* Loop through the HE rate set */
1889d5c65159SKalle Valo 	for (i = 0; i < param->peer_he_mcs_count; i++) {
1890d5c65159SKalle Valo 		he_mcs = ptr;
1891d5c65159SKalle Valo 		he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1892d5c65159SKalle Valo 						WMI_TAG_HE_RATE_SET) |
1893d5c65159SKalle Valo 				     FIELD_PREP(WMI_TLV_LEN,
1894d5c65159SKalle Valo 						sizeof(*he_mcs) - TLV_HDR_SIZE);
1895d5c65159SKalle Valo 
1896d5c65159SKalle Valo 		he_mcs->rx_mcs_set = param->peer_he_rx_mcs_set[i];
1897d5c65159SKalle Valo 		he_mcs->tx_mcs_set = param->peer_he_tx_mcs_set[i];
1898d5c65159SKalle Valo 		ptr += sizeof(*he_mcs);
1899d5c65159SKalle Valo 	}
1900d5c65159SKalle Valo 
1901d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID);
1902d5c65159SKalle Valo 	if (ret) {
1903d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1904d5c65159SKalle Valo 			    "failed to send WMI_PEER_ASSOC_CMDID\n");
1905d5c65159SKalle Valo 		dev_kfree_skb(skb);
1906d5c65159SKalle Valo 	}
1907d5c65159SKalle Valo 
1908d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
19091cb616a3SSriram 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",
19101cb616a3SSriram R 		   cmd->vdev_id, cmd->peer_associd, param->peer_mac,
19111cb616a3SSriram R 		   cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps,
19121cb616a3SSriram R 		   cmd->peer_listen_intval, cmd->peer_ht_caps,
19131cb616a3SSriram R 		   cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode,
19141cb616a3SSriram R 		   cmd->peer_mpdu_density,
19151cb616a3SSriram R 		   cmd->peer_vht_caps, cmd->peer_he_cap_info,
19161cb616a3SSriram R 		   cmd->peer_he_ops, cmd->peer_he_cap_info_ext,
19171cb616a3SSriram R 		   cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1],
19181cb616a3SSriram R 		   cmd->peer_he_cap_phy[2],
19191cb616a3SSriram R 		   cmd->peer_bw_rxnss_override);
1920d5c65159SKalle Valo 
1921d5c65159SKalle Valo 	return ret;
1922d5c65159SKalle Valo }
1923d5c65159SKalle Valo 
1924d5c65159SKalle Valo void ath11k_wmi_start_scan_init(struct ath11k *ar,
1925d5c65159SKalle Valo 				struct scan_req_params *arg)
1926d5c65159SKalle Valo {
1927d5c65159SKalle Valo 	/* setup commonly used values */
1928d5c65159SKalle Valo 	arg->scan_req_id = 1;
1929d5c65159SKalle Valo 	arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
1930d5c65159SKalle Valo 	arg->dwell_time_active = 50;
1931d5c65159SKalle Valo 	arg->dwell_time_active_2g = 0;
1932d5c65159SKalle Valo 	arg->dwell_time_passive = 150;
1933194b8ea1SPradeep Kumar Chitrapu 	arg->dwell_time_active_6g = 40;
1934194b8ea1SPradeep Kumar Chitrapu 	arg->dwell_time_passive_6g = 30;
1935d5c65159SKalle Valo 	arg->min_rest_time = 50;
1936d5c65159SKalle Valo 	arg->max_rest_time = 500;
1937d5c65159SKalle Valo 	arg->repeat_probe_time = 0;
1938d5c65159SKalle Valo 	arg->probe_spacing_time = 0;
1939d5c65159SKalle Valo 	arg->idle_time = 0;
1940d5c65159SKalle Valo 	arg->max_scan_time = 20000;
1941d5c65159SKalle Valo 	arg->probe_delay = 5;
1942d5c65159SKalle Valo 	arg->notify_scan_events = WMI_SCAN_EVENT_STARTED |
1943d5c65159SKalle Valo 				  WMI_SCAN_EVENT_COMPLETED |
1944d5c65159SKalle Valo 				  WMI_SCAN_EVENT_BSS_CHANNEL |
1945d5c65159SKalle Valo 				  WMI_SCAN_EVENT_FOREIGN_CHAN |
1946d5c65159SKalle Valo 				  WMI_SCAN_EVENT_DEQUEUED;
1947d5c65159SKalle Valo 	arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT;
1948d5c65159SKalle Valo 	arg->num_bssid = 1;
1949d5c65159SKalle Valo }
1950d5c65159SKalle Valo 
1951d5c65159SKalle Valo static inline void
1952d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
1953d5c65159SKalle Valo 				       struct scan_req_params *param)
1954d5c65159SKalle Valo {
1955d5c65159SKalle Valo 	/* Scan events subscription */
1956d5c65159SKalle Valo 	if (param->scan_ev_started)
1957d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_STARTED;
1958d5c65159SKalle Valo 	if (param->scan_ev_completed)
1959d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_COMPLETED;
1960d5c65159SKalle Valo 	if (param->scan_ev_bss_chan)
1961d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_BSS_CHANNEL;
1962d5c65159SKalle Valo 	if (param->scan_ev_foreign_chan)
1963d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN;
1964d5c65159SKalle Valo 	if (param->scan_ev_dequeued)
1965d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_DEQUEUED;
1966d5c65159SKalle Valo 	if (param->scan_ev_preempted)
1967d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_PREEMPTED;
1968d5c65159SKalle Valo 	if (param->scan_ev_start_failed)
1969d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_START_FAILED;
1970d5c65159SKalle Valo 	if (param->scan_ev_restarted)
1971d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESTARTED;
1972d5c65159SKalle Valo 	if (param->scan_ev_foreign_chn_exit)
1973d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
1974d5c65159SKalle Valo 	if (param->scan_ev_suspended)
1975d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_SUSPENDED;
1976d5c65159SKalle Valo 	if (param->scan_ev_resumed)
1977d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESUMED;
1978d5c65159SKalle Valo 
1979d5c65159SKalle Valo 	/** Set scan control flags */
1980d5c65159SKalle Valo 	cmd->scan_ctrl_flags = 0;
1981d5c65159SKalle Valo 	if (param->scan_f_passive)
1982d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_PASSIVE;
1983d5c65159SKalle Valo 	if (param->scan_f_strict_passive_pch)
1984d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
1985d5c65159SKalle Valo 	if (param->scan_f_promisc_mode)
1986d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROMISCUOS;
1987d5c65159SKalle Valo 	if (param->scan_f_capture_phy_err)
1988d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CAPTURE_PHY_ERROR;
1989d5c65159SKalle Valo 	if (param->scan_f_half_rate)
1990d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
1991d5c65159SKalle Valo 	if (param->scan_f_quarter_rate)
1992d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
1993d5c65159SKalle Valo 	if (param->scan_f_cck_rates)
1994d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_CCK_RATES;
1995d5c65159SKalle Valo 	if (param->scan_f_ofdm_rates)
1996d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_OFDM_RATES;
1997d5c65159SKalle Valo 	if (param->scan_f_chan_stat_evnt)
1998d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CHAN_STAT_EVENT;
1999d5c65159SKalle Valo 	if (param->scan_f_filter_prb_req)
2000d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROBE_REQ;
2001d5c65159SKalle Valo 	if (param->scan_f_bcast_probe)
2002d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_BCAST_PROBE_REQ;
2003d5c65159SKalle Valo 	if (param->scan_f_offchan_mgmt_tx)
2004d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_MGMT_TX;
2005d5c65159SKalle Valo 	if (param->scan_f_offchan_data_tx)
2006d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_DATA_TX;
2007d5c65159SKalle Valo 	if (param->scan_f_force_active_dfs_chn)
2008d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
2009d5c65159SKalle Valo 	if (param->scan_f_add_tpc_ie_in_probe)
2010d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
2011d5c65159SKalle Valo 	if (param->scan_f_add_ds_ie_in_probe)
2012d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
2013d5c65159SKalle Valo 	if (param->scan_f_add_spoofed_mac_in_probe)
2014d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
2015d5c65159SKalle Valo 	if (param->scan_f_add_rand_seq_in_probe)
2016d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
2017d5c65159SKalle Valo 	if (param->scan_f_en_ie_whitelist_in_probe)
2018d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=
2019d5c65159SKalle Valo 			 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
2020d5c65159SKalle Valo 
2021d5c65159SKalle Valo 	/* for adaptive scan mode using 3 bits (21 - 23 bits) */
2022d5c65159SKalle Valo 	WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
2023d5c65159SKalle Valo 				param->adaptive_dwell_time_mode);
2024d5c65159SKalle Valo }
2025d5c65159SKalle Valo 
2026d5c65159SKalle Valo int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
2027d5c65159SKalle Valo 				   struct scan_req_params *params)
2028d5c65159SKalle Valo {
2029d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2030d5c65159SKalle Valo 	struct wmi_start_scan_cmd *cmd;
2031d5c65159SKalle Valo 	struct wmi_ssid *ssid = NULL;
2032d5c65159SKalle Valo 	struct wmi_mac_addr *bssid;
2033d5c65159SKalle Valo 	struct sk_buff *skb;
2034d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2035d5c65159SKalle Valo 	void *ptr;
2036d5c65159SKalle Valo 	int i, ret, len;
2037d5c65159SKalle Valo 	u32 *tmp_ptr;
2038d5c65159SKalle Valo 	u8 extraie_len_with_pad = 0;
203974601ecfSPradeep Kumar Chitrapu 	struct hint_short_ssid *s_ssid = NULL;
204074601ecfSPradeep Kumar Chitrapu 	struct hint_bssid *hint_bssid = NULL;
2041d5c65159SKalle Valo 
2042d5c65159SKalle Valo 	len = sizeof(*cmd);
2043d5c65159SKalle Valo 
2044d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2045d5c65159SKalle Valo 	if (params->num_chan)
2046d5c65159SKalle Valo 		len += params->num_chan * sizeof(u32);
2047d5c65159SKalle Valo 
2048d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2049d5c65159SKalle Valo 	if (params->num_ssids)
2050d5c65159SKalle Valo 		len += params->num_ssids * sizeof(*ssid);
2051d5c65159SKalle Valo 
2052d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2053d5c65159SKalle Valo 	if (params->num_bssid)
2054d5c65159SKalle Valo 		len += sizeof(*bssid) * params->num_bssid;
2055d5c65159SKalle Valo 
2056d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
2057d5c65159SKalle Valo 	if (params->extraie.len)
2058d5c65159SKalle Valo 		extraie_len_with_pad =
2059d5c65159SKalle Valo 			roundup(params->extraie.len, sizeof(u32));
2060d5c65159SKalle Valo 	len += extraie_len_with_pad;
2061d5c65159SKalle Valo 
206274601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid)
206374601ecfSPradeep Kumar Chitrapu 		len += TLV_HDR_SIZE +
206474601ecfSPradeep Kumar Chitrapu 		       params->num_hint_bssid * sizeof(struct hint_bssid);
206574601ecfSPradeep Kumar Chitrapu 
206674601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid)
206774601ecfSPradeep Kumar Chitrapu 		len += TLV_HDR_SIZE +
206874601ecfSPradeep Kumar Chitrapu 		       params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
206974601ecfSPradeep Kumar Chitrapu 
20706bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2071d5c65159SKalle Valo 	if (!skb)
2072d5c65159SKalle Valo 		return -ENOMEM;
2073d5c65159SKalle Valo 
2074d5c65159SKalle Valo 	ptr = skb->data;
2075d5c65159SKalle Valo 
2076d5c65159SKalle Valo 	cmd = ptr;
2077d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
2078d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2079d5c65159SKalle Valo 
2080d5c65159SKalle Valo 	cmd->scan_id = params->scan_id;
2081d5c65159SKalle Valo 	cmd->scan_req_id = params->scan_req_id;
2082d5c65159SKalle Valo 	cmd->vdev_id = params->vdev_id;
2083d5c65159SKalle Valo 	cmd->scan_priority = params->scan_priority;
2084d5c65159SKalle Valo 	cmd->notify_scan_events = params->notify_scan_events;
2085d5c65159SKalle Valo 
2086d5c65159SKalle Valo 	ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
2087d5c65159SKalle Valo 
2088d5c65159SKalle Valo 	cmd->dwell_time_active = params->dwell_time_active;
2089d5c65159SKalle Valo 	cmd->dwell_time_active_2g = params->dwell_time_active_2g;
2090d5c65159SKalle Valo 	cmd->dwell_time_passive = params->dwell_time_passive;
2091194b8ea1SPradeep Kumar Chitrapu 	cmd->dwell_time_active_6g = params->dwell_time_active_6g;
2092194b8ea1SPradeep Kumar Chitrapu 	cmd->dwell_time_passive_6g = params->dwell_time_passive_6g;
2093d5c65159SKalle Valo 	cmd->min_rest_time = params->min_rest_time;
2094d5c65159SKalle Valo 	cmd->max_rest_time = params->max_rest_time;
2095d5c65159SKalle Valo 	cmd->repeat_probe_time = params->repeat_probe_time;
2096d5c65159SKalle Valo 	cmd->probe_spacing_time = params->probe_spacing_time;
2097d5c65159SKalle Valo 	cmd->idle_time = params->idle_time;
2098d5c65159SKalle Valo 	cmd->max_scan_time = params->max_scan_time;
2099d5c65159SKalle Valo 	cmd->probe_delay = params->probe_delay;
2100d5c65159SKalle Valo 	cmd->burst_duration = params->burst_duration;
2101d5c65159SKalle Valo 	cmd->num_chan = params->num_chan;
2102d5c65159SKalle Valo 	cmd->num_bssid = params->num_bssid;
2103d5c65159SKalle Valo 	cmd->num_ssids = params->num_ssids;
2104d5c65159SKalle Valo 	cmd->ie_len = params->extraie.len;
2105d5c65159SKalle Valo 	cmd->n_probes = params->n_probes;
2106d5c65159SKalle Valo 
2107d5c65159SKalle Valo 	ptr += sizeof(*cmd);
2108d5c65159SKalle Valo 
2109d5c65159SKalle Valo 	len = params->num_chan * sizeof(u32);
2110d5c65159SKalle Valo 
2111d5c65159SKalle Valo 	tlv = ptr;
2112d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
2113d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2114d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2115d5c65159SKalle Valo 	tmp_ptr = (u32 *)ptr;
2116d5c65159SKalle Valo 
2117d5c65159SKalle Valo 	for (i = 0; i < params->num_chan; ++i)
2118d5c65159SKalle Valo 		tmp_ptr[i] = params->chan_list[i];
2119d5c65159SKalle Valo 
2120d5c65159SKalle Valo 	ptr += len;
2121d5c65159SKalle Valo 
2122d5c65159SKalle Valo 	len = params->num_ssids * sizeof(*ssid);
2123d5c65159SKalle Valo 	tlv = ptr;
2124d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2125d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2126d5c65159SKalle Valo 
2127d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2128d5c65159SKalle Valo 
2129d5c65159SKalle Valo 	if (params->num_ssids) {
2130d5c65159SKalle Valo 		ssid = ptr;
2131d5c65159SKalle Valo 		for (i = 0; i < params->num_ssids; ++i) {
2132d5c65159SKalle Valo 			ssid->ssid_len = params->ssid[i].length;
2133d5c65159SKalle Valo 			memcpy(ssid->ssid, params->ssid[i].ssid,
2134d5c65159SKalle Valo 			       params->ssid[i].length);
2135d5c65159SKalle Valo 			ssid++;
2136d5c65159SKalle Valo 		}
2137d5c65159SKalle Valo 	}
2138d5c65159SKalle Valo 
2139d5c65159SKalle Valo 	ptr += (params->num_ssids * sizeof(*ssid));
2140d5c65159SKalle Valo 	len = params->num_bssid * sizeof(*bssid);
2141d5c65159SKalle Valo 	tlv = ptr;
2142d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2143d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2144d5c65159SKalle Valo 
2145d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2146d5c65159SKalle Valo 	bssid = ptr;
2147d5c65159SKalle Valo 
2148d5c65159SKalle Valo 	if (params->num_bssid) {
2149d5c65159SKalle Valo 		for (i = 0; i < params->num_bssid; ++i) {
2150d5c65159SKalle Valo 			ether_addr_copy(bssid->addr,
2151d5c65159SKalle Valo 					params->bssid_list[i].addr);
2152d5c65159SKalle Valo 			bssid++;
2153d5c65159SKalle Valo 		}
2154d5c65159SKalle Valo 	}
2155d5c65159SKalle Valo 
2156d5c65159SKalle Valo 	ptr += params->num_bssid * sizeof(*bssid);
2157d5c65159SKalle Valo 
2158d5c65159SKalle Valo 	len = extraie_len_with_pad;
2159d5c65159SKalle Valo 	tlv = ptr;
2160d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2161d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2162d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2163d5c65159SKalle Valo 
2164d5c65159SKalle Valo 	if (params->extraie.len)
2165d5c65159SKalle Valo 		memcpy(ptr, params->extraie.ptr,
2166d5c65159SKalle Valo 		       params->extraie.len);
2167d5c65159SKalle Valo 
2168d5c65159SKalle Valo 	ptr += extraie_len_with_pad;
2169d5c65159SKalle Valo 
217074601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid) {
217174601ecfSPradeep Kumar Chitrapu 		len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
217274601ecfSPradeep Kumar Chitrapu 		tlv = ptr;
217374601ecfSPradeep Kumar Chitrapu 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
217474601ecfSPradeep Kumar Chitrapu 			      FIELD_PREP(WMI_TLV_LEN, len);
217574601ecfSPradeep Kumar Chitrapu 		ptr += TLV_HDR_SIZE;
217674601ecfSPradeep Kumar Chitrapu 		s_ssid = ptr;
217774601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_s_ssid; ++i) {
217874601ecfSPradeep Kumar Chitrapu 			s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
217974601ecfSPradeep Kumar Chitrapu 			s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
218074601ecfSPradeep Kumar Chitrapu 			s_ssid++;
218174601ecfSPradeep Kumar Chitrapu 		}
218274601ecfSPradeep Kumar Chitrapu 		ptr += len;
218374601ecfSPradeep Kumar Chitrapu 	}
218474601ecfSPradeep Kumar Chitrapu 
218574601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid) {
218674601ecfSPradeep Kumar Chitrapu 		len = params->num_hint_bssid * sizeof(struct hint_bssid);
218774601ecfSPradeep Kumar Chitrapu 		tlv = ptr;
218874601ecfSPradeep Kumar Chitrapu 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
218974601ecfSPradeep Kumar Chitrapu 			      FIELD_PREP(WMI_TLV_LEN, len);
219074601ecfSPradeep Kumar Chitrapu 		ptr += TLV_HDR_SIZE;
219174601ecfSPradeep Kumar Chitrapu 		hint_bssid = ptr;
219274601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_bssid; ++i) {
219374601ecfSPradeep Kumar Chitrapu 			hint_bssid->freq_flags =
219474601ecfSPradeep Kumar Chitrapu 				params->hint_bssid[i].freq_flags;
219574601ecfSPradeep Kumar Chitrapu 			ether_addr_copy(&params->hint_bssid[i].bssid.addr[0],
219674601ecfSPradeep Kumar Chitrapu 					&hint_bssid->bssid.addr[0]);
219774601ecfSPradeep Kumar Chitrapu 			hint_bssid++;
219874601ecfSPradeep Kumar Chitrapu 		}
219974601ecfSPradeep Kumar Chitrapu 	}
220074601ecfSPradeep Kumar Chitrapu 
220174601ecfSPradeep Kumar Chitrapu 	len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
220274601ecfSPradeep Kumar Chitrapu 	tlv = ptr;
220374601ecfSPradeep Kumar Chitrapu 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
220474601ecfSPradeep Kumar Chitrapu 		      FIELD_PREP(WMI_TLV_LEN, len);
220574601ecfSPradeep Kumar Chitrapu 	ptr += TLV_HDR_SIZE;
220674601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_s_ssid) {
220774601ecfSPradeep Kumar Chitrapu 		s_ssid = ptr;
220874601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_s_ssid; ++i) {
220974601ecfSPradeep Kumar Chitrapu 			s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
221074601ecfSPradeep Kumar Chitrapu 			s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
221174601ecfSPradeep Kumar Chitrapu 			s_ssid++;
221274601ecfSPradeep Kumar Chitrapu 		}
221374601ecfSPradeep Kumar Chitrapu 	}
221474601ecfSPradeep Kumar Chitrapu 	ptr += len;
221574601ecfSPradeep Kumar Chitrapu 
221674601ecfSPradeep Kumar Chitrapu 	len = params->num_hint_bssid * sizeof(struct hint_bssid);
221774601ecfSPradeep Kumar Chitrapu 	tlv = ptr;
221874601ecfSPradeep Kumar Chitrapu 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
221974601ecfSPradeep Kumar Chitrapu 		      FIELD_PREP(WMI_TLV_LEN, len);
222074601ecfSPradeep Kumar Chitrapu 	ptr += TLV_HDR_SIZE;
222174601ecfSPradeep Kumar Chitrapu 	if (params->num_hint_bssid) {
222274601ecfSPradeep Kumar Chitrapu 		hint_bssid = ptr;
222374601ecfSPradeep Kumar Chitrapu 		for (i = 0; i < params->num_hint_bssid; ++i) {
222474601ecfSPradeep Kumar Chitrapu 			hint_bssid->freq_flags =
222574601ecfSPradeep Kumar Chitrapu 				params->hint_bssid[i].freq_flags;
222674601ecfSPradeep Kumar Chitrapu 			ether_addr_copy(&params->hint_bssid[i].bssid.addr[0],
222774601ecfSPradeep Kumar Chitrapu 					&hint_bssid->bssid.addr[0]);
222874601ecfSPradeep Kumar Chitrapu 			hint_bssid++;
222974601ecfSPradeep Kumar Chitrapu 		}
223074601ecfSPradeep Kumar Chitrapu 	}
223174601ecfSPradeep Kumar Chitrapu 
2232d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2233d5c65159SKalle Valo 				  WMI_START_SCAN_CMDID);
2234d5c65159SKalle Valo 	if (ret) {
2235d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2236d5c65159SKalle Valo 		dev_kfree_skb(skb);
2237d5c65159SKalle Valo 	}
2238d5c65159SKalle Valo 
2239d5c65159SKalle Valo 	return ret;
2240d5c65159SKalle Valo }
2241d5c65159SKalle Valo 
2242d5c65159SKalle Valo int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2243d5c65159SKalle Valo 				  struct scan_cancel_param *param)
2244d5c65159SKalle Valo {
2245d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2246d5c65159SKalle Valo 	struct wmi_stop_scan_cmd *cmd;
2247d5c65159SKalle Valo 	struct sk_buff *skb;
2248d5c65159SKalle Valo 	int ret;
2249d5c65159SKalle Valo 
22506bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2251d5c65159SKalle Valo 	if (!skb)
2252d5c65159SKalle Valo 		return -ENOMEM;
2253d5c65159SKalle Valo 
2254d5c65159SKalle Valo 	cmd = (struct wmi_stop_scan_cmd *)skb->data;
2255d5c65159SKalle Valo 
2256d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2257d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2258d5c65159SKalle Valo 
2259d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
2260d5c65159SKalle Valo 	cmd->requestor = param->requester;
2261d5c65159SKalle Valo 	cmd->scan_id = param->scan_id;
2262d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
2263d5c65159SKalle Valo 	/* stop the scan with the corresponding scan_id */
2264d5c65159SKalle Valo 	if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2265d5c65159SKalle Valo 		/* Cancelling all scans */
2266d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ALL;
2267d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2268d5c65159SKalle Valo 		/* Cancelling VAP scans */
2269d5c65159SKalle Valo 		cmd->req_type =  WMI_SCN_STOP_VAP_ALL;
2270d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2271d5c65159SKalle Valo 		/* Cancelling specific scan */
2272d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ONE;
2273d5c65159SKalle Valo 	} else {
2274d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid scan cancel param %d",
2275d5c65159SKalle Valo 			    param->req_type);
2276d5c65159SKalle Valo 		dev_kfree_skb(skb);
2277d5c65159SKalle Valo 		return -EINVAL;
2278d5c65159SKalle Valo 	}
2279d5c65159SKalle Valo 
2280d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2281d5c65159SKalle Valo 				  WMI_STOP_SCAN_CMDID);
2282d5c65159SKalle Valo 	if (ret) {
2283d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2284d5c65159SKalle Valo 		dev_kfree_skb(skb);
2285d5c65159SKalle Valo 	}
2286d5c65159SKalle Valo 
2287d5c65159SKalle Valo 	return ret;
2288d5c65159SKalle Valo }
2289d5c65159SKalle Valo 
2290d5c65159SKalle Valo int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2291d5c65159SKalle Valo 				       struct scan_chan_list_params *chan_list)
2292d5c65159SKalle Valo {
2293d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2294d5c65159SKalle Valo 	struct wmi_scan_chan_list_cmd *cmd;
2295d5c65159SKalle Valo 	struct sk_buff *skb;
2296d5c65159SKalle Valo 	struct wmi_channel *chan_info;
2297d5c65159SKalle Valo 	struct channel_param *tchan_info;
2298d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2299d5c65159SKalle Valo 	void *ptr;
2300d5c65159SKalle Valo 	int i, ret, len;
2301bff621fdSPradeep Kumar Chitrapu 	u16 num_send_chans, num_sends = 0, max_chan_limit = 0;
2302d5c65159SKalle Valo 	u32 *reg1, *reg2;
2303d5c65159SKalle Valo 
2304bff621fdSPradeep Kumar Chitrapu 	tchan_info = &chan_list->ch_param[0];
2305bff621fdSPradeep Kumar Chitrapu 	while (chan_list->nallchans) {
2306bff621fdSPradeep Kumar Chitrapu 		len = sizeof(*cmd) + TLV_HDR_SIZE;
2307bff621fdSPradeep Kumar Chitrapu 		max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) /
2308bff621fdSPradeep Kumar Chitrapu 			sizeof(*chan_info);
2309bff621fdSPradeep Kumar Chitrapu 
2310bff621fdSPradeep Kumar Chitrapu 		if (chan_list->nallchans > max_chan_limit)
2311bff621fdSPradeep Kumar Chitrapu 			num_send_chans = max_chan_limit;
2312bff621fdSPradeep Kumar Chitrapu 		else
2313bff621fdSPradeep Kumar Chitrapu 			num_send_chans = chan_list->nallchans;
2314bff621fdSPradeep Kumar Chitrapu 
2315bff621fdSPradeep Kumar Chitrapu 		chan_list->nallchans -= num_send_chans;
2316bff621fdSPradeep Kumar Chitrapu 		len += sizeof(*chan_info) * num_send_chans;
2317d5c65159SKalle Valo 
23186bc9d6f7SJohn Crispin 		skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2319d5c65159SKalle Valo 		if (!skb)
2320d5c65159SKalle Valo 			return -ENOMEM;
2321d5c65159SKalle Valo 
2322d5c65159SKalle Valo 		cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2323d5c65159SKalle Valo 		cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2324d5c65159SKalle Valo 			FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2325bff621fdSPradeep Kumar Chitrapu 		cmd->pdev_id = chan_list->pdev_id;
2326bff621fdSPradeep Kumar Chitrapu 		cmd->num_scan_chans = num_send_chans;
2327bff621fdSPradeep Kumar Chitrapu 		if (num_sends)
2328bff621fdSPradeep Kumar Chitrapu 			cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG;
2329d5c65159SKalle Valo 
2330d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2331bff621fdSPradeep Kumar Chitrapu 			   "WMI no.of chan = %d len = %d pdev_id = %d num_sends = %d\n",
2332bff621fdSPradeep Kumar Chitrapu 			   num_send_chans, len, cmd->pdev_id, num_sends);
2333d5c65159SKalle Valo 
2334d5c65159SKalle Valo 		ptr = skb->data + sizeof(*cmd);
2335d5c65159SKalle Valo 
2336bff621fdSPradeep Kumar Chitrapu 		len = sizeof(*chan_info) * num_send_chans;
2337d5c65159SKalle Valo 		tlv = ptr;
2338d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2339d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2340d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
2341d5c65159SKalle Valo 
2342bff621fdSPradeep Kumar Chitrapu 		for (i = 0; i < num_send_chans; ++i) {
2343d5c65159SKalle Valo 			chan_info = ptr;
2344d5c65159SKalle Valo 			memset(chan_info, 0, sizeof(*chan_info));
2345d5c65159SKalle Valo 			len = sizeof(*chan_info);
2346d5c65159SKalle Valo 			chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2347d5c65159SKalle Valo 							   WMI_TAG_CHANNEL) |
2348d5c65159SKalle Valo 						FIELD_PREP(WMI_TLV_LEN,
2349d5c65159SKalle Valo 							   len - TLV_HDR_SIZE);
2350d5c65159SKalle Valo 
2351d5c65159SKalle Valo 			reg1 = &chan_info->reg_info_1;
2352d5c65159SKalle Valo 			reg2 = &chan_info->reg_info_2;
2353d5c65159SKalle Valo 			chan_info->mhz = tchan_info->mhz;
2354d5c65159SKalle Valo 			chan_info->band_center_freq1 = tchan_info->cfreq1;
2355d5c65159SKalle Valo 			chan_info->band_center_freq2 = tchan_info->cfreq2;
2356d5c65159SKalle Valo 
2357d5c65159SKalle Valo 			if (tchan_info->is_chan_passive)
2358d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_PASSIVE;
23599f056ed8SJohn Crispin 			if (tchan_info->allow_he)
23609f056ed8SJohn Crispin 				chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
23619f056ed8SJohn Crispin 			else if (tchan_info->allow_vht)
2362d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2363d5c65159SKalle Valo 			else if (tchan_info->allow_ht)
2364d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2365d5c65159SKalle Valo 			if (tchan_info->half_rate)
2366d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2367d5c65159SKalle Valo 			if (tchan_info->quarter_rate)
2368d5c65159SKalle Valo 				chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2369bff621fdSPradeep Kumar Chitrapu 			if (tchan_info->psc_channel)
2370bff621fdSPradeep Kumar Chitrapu 				chan_info->info |= WMI_CHAN_INFO_PSC;
2371d5c65159SKalle Valo 
2372d5c65159SKalle Valo 			chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2373d5c65159SKalle Valo 						      tchan_info->phy_mode);
2374d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2375d5c65159SKalle Valo 					    tchan_info->minpower);
2376d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2377d5c65159SKalle Valo 					    tchan_info->maxpower);
2378d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2379d5c65159SKalle Valo 					    tchan_info->maxregpower);
2380d5c65159SKalle Valo 			*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2381d5c65159SKalle Valo 					    tchan_info->reg_class_id);
2382d5c65159SKalle Valo 			*reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2383d5c65159SKalle Valo 					    tchan_info->antennamax);
2384d5c65159SKalle Valo 
2385d5c65159SKalle Valo 			ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2386bff621fdSPradeep Kumar Chitrapu 				   "WMI chan scan list chan[%d] = %u, chan_info->info %8x\n",
2387bff621fdSPradeep Kumar Chitrapu 				   i, chan_info->mhz, chan_info->info);
2388d5c65159SKalle Valo 
2389d5c65159SKalle Valo 			ptr += sizeof(*chan_info);
2390d5c65159SKalle Valo 
2391d5c65159SKalle Valo 			tchan_info++;
2392d5c65159SKalle Valo 		}
2393d5c65159SKalle Valo 
2394d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2395d5c65159SKalle Valo 		if (ret) {
2396d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2397d5c65159SKalle Valo 			dev_kfree_skb(skb);
2398bff621fdSPradeep Kumar Chitrapu 			return ret;
2399d5c65159SKalle Valo 		}
2400d5c65159SKalle Valo 
2401bff621fdSPradeep Kumar Chitrapu 		num_sends++;
2402bff621fdSPradeep Kumar Chitrapu 	}
2403bff621fdSPradeep Kumar Chitrapu 
2404bff621fdSPradeep Kumar Chitrapu 	return 0;
2405d5c65159SKalle Valo }
2406d5c65159SKalle Valo 
2407d5c65159SKalle Valo int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2408d5c65159SKalle Valo 				       struct wmi_wmm_params_all_arg *param)
2409d5c65159SKalle Valo {
2410d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2411d5c65159SKalle Valo 	struct wmi_vdev_set_wmm_params_cmd *cmd;
2412d5c65159SKalle Valo 	struct wmi_wmm_params *wmm_param;
2413d5c65159SKalle Valo 	struct wmi_wmm_params_arg *wmi_wmm_arg;
2414d5c65159SKalle Valo 	struct sk_buff *skb;
2415d5c65159SKalle Valo 	int ret, ac;
2416d5c65159SKalle Valo 
24176bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2418d5c65159SKalle Valo 	if (!skb)
2419d5c65159SKalle Valo 		return -ENOMEM;
2420d5c65159SKalle Valo 
2421d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2422d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2423d5c65159SKalle Valo 				     WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2424d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2425d5c65159SKalle Valo 
2426d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
2427d5c65159SKalle Valo 	cmd->wmm_param_type = 0;
2428d5c65159SKalle Valo 
2429d5c65159SKalle Valo 	for (ac = 0; ac < WME_NUM_AC; ac++) {
2430d5c65159SKalle Valo 		switch (ac) {
2431d5c65159SKalle Valo 		case WME_AC_BE:
2432d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_be;
2433d5c65159SKalle Valo 			break;
2434d5c65159SKalle Valo 		case WME_AC_BK:
2435d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_bk;
2436d5c65159SKalle Valo 			break;
2437d5c65159SKalle Valo 		case WME_AC_VI:
2438d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vi;
2439d5c65159SKalle Valo 			break;
2440d5c65159SKalle Valo 		case WME_AC_VO:
2441d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vo;
2442d5c65159SKalle Valo 			break;
2443d5c65159SKalle Valo 		}
2444d5c65159SKalle Valo 
2445d5c65159SKalle Valo 		wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2446d5c65159SKalle Valo 		wmm_param->tlv_header =
2447d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
2448d5c65159SKalle Valo 					   WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2449d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN,
2450d5c65159SKalle Valo 					   sizeof(*wmm_param) - TLV_HDR_SIZE);
2451d5c65159SKalle Valo 
2452d5c65159SKalle Valo 		wmm_param->aifs = wmi_wmm_arg->aifs;
2453d5c65159SKalle Valo 		wmm_param->cwmin = wmi_wmm_arg->cwmin;
2454d5c65159SKalle Valo 		wmm_param->cwmax = wmi_wmm_arg->cwmax;
2455d5c65159SKalle Valo 		wmm_param->txoplimit = wmi_wmm_arg->txop;
2456d5c65159SKalle Valo 		wmm_param->acm = wmi_wmm_arg->acm;
2457d5c65159SKalle Valo 		wmm_param->no_ack = wmi_wmm_arg->no_ack;
2458d5c65159SKalle Valo 
2459d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2460d5c65159SKalle Valo 			   "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2461d5c65159SKalle Valo 			   ac, wmm_param->aifs, wmm_param->cwmin,
2462d5c65159SKalle Valo 			   wmm_param->cwmax, wmm_param->txoplimit,
2463d5c65159SKalle Valo 			   wmm_param->acm, wmm_param->no_ack);
2464d5c65159SKalle Valo 	}
2465d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2466d5c65159SKalle Valo 				  WMI_VDEV_SET_WMM_PARAMS_CMDID);
2467d5c65159SKalle Valo 	if (ret) {
2468d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2469d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2470d5c65159SKalle Valo 		dev_kfree_skb(skb);
2471d5c65159SKalle Valo 	}
2472d5c65159SKalle Valo 
2473d5c65159SKalle Valo 	return ret;
2474d5c65159SKalle Valo }
2475d5c65159SKalle Valo 
2476d5c65159SKalle Valo int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2477d5c65159SKalle Valo 						  u32 pdev_id)
2478d5c65159SKalle Valo {
2479d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2480d5c65159SKalle Valo 	struct wmi_dfs_phyerr_offload_cmd *cmd;
2481d5c65159SKalle Valo 	struct sk_buff *skb;
2482d5c65159SKalle Valo 	int ret;
2483d5c65159SKalle Valo 
24846bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2485d5c65159SKalle Valo 	if (!skb)
2486d5c65159SKalle Valo 		return -ENOMEM;
2487d5c65159SKalle Valo 
2488d5c65159SKalle Valo 	cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2489d5c65159SKalle Valo 	cmd->tlv_header =
2490d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2491d5c65159SKalle Valo 			   WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2492d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2493d5c65159SKalle Valo 
2494d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
2495d5c65159SKalle Valo 
2496d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2497d5c65159SKalle Valo 		   "WMI dfs phy err offload enable pdev id %d\n", pdev_id);
2498d5c65159SKalle Valo 
2499d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2500d5c65159SKalle Valo 				  WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2501d5c65159SKalle Valo 	if (ret) {
2502d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2503d5c65159SKalle Valo 			    "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2504d5c65159SKalle Valo 		dev_kfree_skb(skb);
2505d5c65159SKalle Valo 	}
2506d5c65159SKalle Valo 
2507d5c65159SKalle Valo 	return ret;
2508d5c65159SKalle Valo }
2509d5c65159SKalle Valo 
25109556dfa2SMaharaja Kennadyrajan int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
25119556dfa2SMaharaja Kennadyrajan 			  u32 tid, u32 initiator, u32 reason)
25129556dfa2SMaharaja Kennadyrajan {
25139556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
25149556dfa2SMaharaja Kennadyrajan 	struct wmi_delba_send_cmd *cmd;
25159556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
25169556dfa2SMaharaja Kennadyrajan 	int ret;
25179556dfa2SMaharaja Kennadyrajan 
25189556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
25199556dfa2SMaharaja Kennadyrajan 	if (!skb)
25209556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
25219556dfa2SMaharaja Kennadyrajan 
25229556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_delba_send_cmd *)skb->data;
25239556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) |
25249556dfa2SMaharaja Kennadyrajan 			FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
25259556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
25269556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
25279556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
25289556dfa2SMaharaja Kennadyrajan 	cmd->initiator = initiator;
25299556dfa2SMaharaja Kennadyrajan 	cmd->reasoncode = reason;
25309556dfa2SMaharaja Kennadyrajan 
25319556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
25329556dfa2SMaharaja Kennadyrajan 		   "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
25339556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, initiator, reason);
25349556dfa2SMaharaja Kennadyrajan 
25359556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID);
25369556dfa2SMaharaja Kennadyrajan 
25379556dfa2SMaharaja Kennadyrajan 	if (ret) {
25389556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
25399556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_DELBA_SEND_CMDID cmd\n");
25409556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
25419556dfa2SMaharaja Kennadyrajan 	}
25429556dfa2SMaharaja Kennadyrajan 
25439556dfa2SMaharaja Kennadyrajan 	return ret;
25449556dfa2SMaharaja Kennadyrajan }
25459556dfa2SMaharaja Kennadyrajan 
25469556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac,
25479556dfa2SMaharaja Kennadyrajan 			      u32 tid, u32 status)
25489556dfa2SMaharaja Kennadyrajan {
25499556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
25509556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_setresponse_cmd *cmd;
25519556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
25529556dfa2SMaharaja Kennadyrajan 	int ret;
25539556dfa2SMaharaja Kennadyrajan 
25549556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
25559556dfa2SMaharaja Kennadyrajan 	if (!skb)
25569556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
25579556dfa2SMaharaja Kennadyrajan 
25589556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
25599556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header =
25609556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) |
25619556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
25629556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
25639556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
25649556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
25659556dfa2SMaharaja Kennadyrajan 	cmd->statuscode = status;
25669556dfa2SMaharaja Kennadyrajan 
25679556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
25689556dfa2SMaharaja Kennadyrajan 		   "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
25699556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, status);
25709556dfa2SMaharaja Kennadyrajan 
25719556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID);
25729556dfa2SMaharaja Kennadyrajan 
25739556dfa2SMaharaja Kennadyrajan 	if (ret) {
25749556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
25759556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n");
25769556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
25779556dfa2SMaharaja Kennadyrajan 	}
25789556dfa2SMaharaja Kennadyrajan 
25799556dfa2SMaharaja Kennadyrajan 	return ret;
25809556dfa2SMaharaja Kennadyrajan }
25819556dfa2SMaharaja Kennadyrajan 
25829556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
25839556dfa2SMaharaja Kennadyrajan 			  u32 tid, u32 buf_size)
25849556dfa2SMaharaja Kennadyrajan {
25859556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
25869556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_send_cmd *cmd;
25879556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
25889556dfa2SMaharaja Kennadyrajan 	int ret;
25899556dfa2SMaharaja Kennadyrajan 
25909556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
25919556dfa2SMaharaja Kennadyrajan 	if (!skb)
25929556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
25939556dfa2SMaharaja Kennadyrajan 
25949556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_send_cmd *)skb->data;
25959556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) |
25969556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
25979556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
25989556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
25999556dfa2SMaharaja Kennadyrajan 	cmd->tid = tid;
26009556dfa2SMaharaja Kennadyrajan 	cmd->buffersize = buf_size;
26019556dfa2SMaharaja Kennadyrajan 
26029556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
26039556dfa2SMaharaja Kennadyrajan 		   "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
26049556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac, tid, buf_size);
26059556dfa2SMaharaja Kennadyrajan 
26069556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID);
26079556dfa2SMaharaja Kennadyrajan 
26089556dfa2SMaharaja Kennadyrajan 	if (ret) {
26099556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
26109556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_SEND_CMDID cmd\n");
26119556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
26129556dfa2SMaharaja Kennadyrajan 	}
26139556dfa2SMaharaja Kennadyrajan 
26149556dfa2SMaharaja Kennadyrajan 	return ret;
26159556dfa2SMaharaja Kennadyrajan }
26169556dfa2SMaharaja Kennadyrajan 
26179556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac)
26189556dfa2SMaharaja Kennadyrajan {
26199556dfa2SMaharaja Kennadyrajan 	struct ath11k_pdev_wmi *wmi = ar->wmi;
26209556dfa2SMaharaja Kennadyrajan 	struct wmi_addba_clear_resp_cmd *cmd;
26219556dfa2SMaharaja Kennadyrajan 	struct sk_buff *skb;
26229556dfa2SMaharaja Kennadyrajan 	int ret;
26239556dfa2SMaharaja Kennadyrajan 
26249556dfa2SMaharaja Kennadyrajan 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26259556dfa2SMaharaja Kennadyrajan 	if (!skb)
26269556dfa2SMaharaja Kennadyrajan 		return -ENOMEM;
26279556dfa2SMaharaja Kennadyrajan 
26289556dfa2SMaharaja Kennadyrajan 	cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
26299556dfa2SMaharaja Kennadyrajan 	cmd->tlv_header =
26309556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) |
26319556dfa2SMaharaja Kennadyrajan 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
26329556dfa2SMaharaja Kennadyrajan 	cmd->vdev_id = vdev_id;
26339556dfa2SMaharaja Kennadyrajan 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
26349556dfa2SMaharaja Kennadyrajan 
26359556dfa2SMaharaja Kennadyrajan 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
26369556dfa2SMaharaja Kennadyrajan 		   "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
26379556dfa2SMaharaja Kennadyrajan 		   vdev_id, mac);
26389556dfa2SMaharaja Kennadyrajan 
26399556dfa2SMaharaja Kennadyrajan 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID);
26409556dfa2SMaharaja Kennadyrajan 
26419556dfa2SMaharaja Kennadyrajan 	if (ret) {
26429556dfa2SMaharaja Kennadyrajan 		ath11k_warn(ar->ab,
26439556dfa2SMaharaja Kennadyrajan 			    "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n");
26449556dfa2SMaharaja Kennadyrajan 		dev_kfree_skb(skb);
26459556dfa2SMaharaja Kennadyrajan 	}
26469556dfa2SMaharaja Kennadyrajan 
26479556dfa2SMaharaja Kennadyrajan 	return ret;
26489556dfa2SMaharaja Kennadyrajan }
26499556dfa2SMaharaja Kennadyrajan 
2650d5c65159SKalle Valo int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2651d5c65159SKalle Valo {
2652d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2653d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_cmd *cmd;
2654d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_info *info;
2655d5c65159SKalle Valo 	struct sk_buff *skb;
2656d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2657d5c65159SKalle Valo 	void *ptr;
2658d5c65159SKalle Valo 	int ret, len;
2659d5c65159SKalle Valo 
2660d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
26616bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2662d5c65159SKalle Valo 	if (!skb)
2663d5c65159SKalle Valo 		return -ENOMEM;
2664d5c65159SKalle Valo 
2665d5c65159SKalle Valo 	cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2666d5c65159SKalle Valo 
2667d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2668d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2669d5c65159SKalle Valo 
2670d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2671d5c65159SKalle Valo 	cmd->num_mac = 1;
2672d5c65159SKalle Valo 	cmd->enable = enable;
2673d5c65159SKalle Valo 
2674d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
2675d5c65159SKalle Valo 
2676d5c65159SKalle Valo 	tlv = ptr;
2677d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
267879c647a3SVikas Patel 		      FIELD_PREP(WMI_TLV_LEN, sizeof(*info));
2679d5c65159SKalle Valo 
2680d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2681d5c65159SKalle Valo 	info = ptr;
2682d5c65159SKalle Valo 
2683d5c65159SKalle Valo 	ether_addr_copy(info->peer_macaddr.addr, addr);
2684d5c65159SKalle Valo 	info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2685d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
2686d5c65159SKalle Valo 				      sizeof(*info) - TLV_HDR_SIZE);
2687d5c65159SKalle Valo 
2688d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2689d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_FILTER_CMDID);
2690d5c65159SKalle Valo 	if (ret) {
2691d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2692d5c65159SKalle Valo 		dev_kfree_skb(skb);
2693d5c65159SKalle Valo 	}
2694d5c65159SKalle Valo 
2695d5c65159SKalle Valo 	return ret;
2696d5c65159SKalle Valo }
2697d5c65159SKalle Valo 
2698d5c65159SKalle Valo int
2699d5c65159SKalle Valo ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2700d5c65159SKalle Valo 				 struct wmi_init_country_params init_cc_params)
2701d5c65159SKalle Valo {
2702d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2703d5c65159SKalle Valo 	struct wmi_init_country_cmd *cmd;
2704d5c65159SKalle Valo 	struct sk_buff *skb;
2705d5c65159SKalle Valo 	int ret;
2706d5c65159SKalle Valo 
27076bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2708d5c65159SKalle Valo 	if (!skb)
2709d5c65159SKalle Valo 		return -ENOMEM;
2710d5c65159SKalle Valo 
2711d5c65159SKalle Valo 	cmd = (struct wmi_init_country_cmd *)skb->data;
2712d5c65159SKalle Valo 	cmd->tlv_header =
2713d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2714d5c65159SKalle Valo 			   WMI_TAG_SET_INIT_COUNTRY_CMD) |
2715d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2716d5c65159SKalle Valo 
2717d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2718d5c65159SKalle Valo 
2719d5c65159SKalle Valo 	switch (init_cc_params.flags) {
2720d5c65159SKalle Valo 	case ALPHA_IS_SET:
2721d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2722d5c65159SKalle Valo 		memcpy((u8 *)&cmd->cc_info.alpha2,
2723d5c65159SKalle Valo 		       init_cc_params.cc_info.alpha2, 3);
2724d5c65159SKalle Valo 		break;
2725d5c65159SKalle Valo 	case CC_IS_SET:
2726d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2727d5c65159SKalle Valo 		cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2728d5c65159SKalle Valo 		break;
2729d5c65159SKalle Valo 	case REGDMN_IS_SET:
2730d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2731d5c65159SKalle Valo 		cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2732d5c65159SKalle Valo 		break;
2733d5c65159SKalle Valo 	default:
2734d5c65159SKalle Valo 		ret = -EINVAL;
2735d5c65159SKalle Valo 		goto out;
2736d5c65159SKalle Valo 	}
2737d5c65159SKalle Valo 
2738d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2739d5c65159SKalle Valo 				  WMI_SET_INIT_COUNTRY_CMDID);
2740d5c65159SKalle Valo 
2741d5c65159SKalle Valo out:
2742d5c65159SKalle Valo 	if (ret) {
2743d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2744d5c65159SKalle Valo 			    "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2745d5c65159SKalle Valo 			    ret);
2746d5c65159SKalle Valo 		dev_kfree_skb(skb);
2747d5c65159SKalle Valo 	}
2748d5c65159SKalle Valo 
2749d5c65159SKalle Valo 	return ret;
2750d5c65159SKalle Valo }
2751d5c65159SKalle Valo 
27522a63bbcaSPradeep Kumar Chitrapu int
27532a63bbcaSPradeep Kumar Chitrapu ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar,
27542a63bbcaSPradeep Kumar Chitrapu 					     struct thermal_mitigation_params *param)
27552a63bbcaSPradeep Kumar Chitrapu {
27562a63bbcaSPradeep Kumar Chitrapu 	struct ath11k_pdev_wmi *wmi = ar->wmi;
27572a63bbcaSPradeep Kumar Chitrapu 	struct wmi_therm_throt_config_request_cmd *cmd;
27582a63bbcaSPradeep Kumar Chitrapu 	struct wmi_therm_throt_level_config_info *lvl_conf;
27592a63bbcaSPradeep Kumar Chitrapu 	struct wmi_tlv *tlv;
27602a63bbcaSPradeep Kumar Chitrapu 	struct sk_buff *skb;
27612a63bbcaSPradeep Kumar Chitrapu 	int i, ret, len;
27622a63bbcaSPradeep Kumar Chitrapu 
27632a63bbcaSPradeep Kumar Chitrapu 	len = sizeof(*cmd) + TLV_HDR_SIZE +
27642a63bbcaSPradeep Kumar Chitrapu 	      THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info);
27652a63bbcaSPradeep Kumar Chitrapu 
27662a63bbcaSPradeep Kumar Chitrapu 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
27672a63bbcaSPradeep Kumar Chitrapu 	if (!skb)
27682a63bbcaSPradeep Kumar Chitrapu 		return -ENOMEM;
27692a63bbcaSPradeep Kumar Chitrapu 
27702a63bbcaSPradeep Kumar Chitrapu 	cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data;
27712a63bbcaSPradeep Kumar Chitrapu 
27722a63bbcaSPradeep Kumar Chitrapu 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) |
27732a63bbcaSPradeep Kumar Chitrapu 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27742a63bbcaSPradeep Kumar Chitrapu 
27752a63bbcaSPradeep Kumar Chitrapu 	cmd->pdev_id = ar->pdev->pdev_id;
27762a63bbcaSPradeep Kumar Chitrapu 	cmd->enable = param->enable;
27772a63bbcaSPradeep Kumar Chitrapu 	cmd->dc = param->dc;
27782a63bbcaSPradeep Kumar Chitrapu 	cmd->dc_per_event = param->dc_per_event;
27792a63bbcaSPradeep Kumar Chitrapu 	cmd->therm_throt_levels = THERMAL_LEVELS;
27802a63bbcaSPradeep Kumar Chitrapu 
27812a63bbcaSPradeep Kumar Chitrapu 	tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
27822a63bbcaSPradeep Kumar Chitrapu 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
27832a63bbcaSPradeep Kumar Chitrapu 		      FIELD_PREP(WMI_TLV_LEN,
27842a63bbcaSPradeep Kumar Chitrapu 				 (THERMAL_LEVELS *
27852a63bbcaSPradeep Kumar Chitrapu 				  sizeof(struct wmi_therm_throt_level_config_info)));
27862a63bbcaSPradeep Kumar Chitrapu 
27872a63bbcaSPradeep Kumar Chitrapu 	lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data +
27882a63bbcaSPradeep Kumar Chitrapu 								sizeof(*cmd) +
27892a63bbcaSPradeep Kumar Chitrapu 								TLV_HDR_SIZE);
27902a63bbcaSPradeep Kumar Chitrapu 	for (i = 0; i < THERMAL_LEVELS; i++) {
27912a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->tlv_header =
27922a63bbcaSPradeep Kumar Chitrapu 			FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) |
27932a63bbcaSPradeep Kumar Chitrapu 			FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE);
27942a63bbcaSPradeep Kumar Chitrapu 
27952a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->temp_lwm = param->levelconf[i].tmplwm;
27962a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->temp_hwm = param->levelconf[i].tmphwm;
27972a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent;
27982a63bbcaSPradeep Kumar Chitrapu 		lvl_conf->prio = param->levelconf[i].priority;
27992a63bbcaSPradeep Kumar Chitrapu 		lvl_conf++;
28002a63bbcaSPradeep Kumar Chitrapu 	}
28012a63bbcaSPradeep Kumar Chitrapu 
28022a63bbcaSPradeep Kumar Chitrapu 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID);
28032a63bbcaSPradeep Kumar Chitrapu 	if (ret) {
28042a63bbcaSPradeep Kumar Chitrapu 		ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n");
28052a63bbcaSPradeep Kumar Chitrapu 		dev_kfree_skb(skb);
28062a63bbcaSPradeep Kumar Chitrapu 	}
28072a63bbcaSPradeep Kumar Chitrapu 
28082a63bbcaSPradeep Kumar Chitrapu 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
28092a63bbcaSPradeep Kumar Chitrapu 		   "WMI vdev set thermal throt pdev_id %d enable %d dc %d dc_per_event %x levels %d\n",
28102a63bbcaSPradeep Kumar Chitrapu 		   ar->pdev->pdev_id, param->enable, param->dc,
28112a63bbcaSPradeep Kumar Chitrapu 		   param->dc_per_event, THERMAL_LEVELS);
28122a63bbcaSPradeep Kumar Chitrapu 
28132a63bbcaSPradeep Kumar Chitrapu 	return ret;
28142a63bbcaSPradeep Kumar Chitrapu }
28152a63bbcaSPradeep Kumar Chitrapu 
2816d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
2817d5c65159SKalle Valo {
2818d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2819d5c65159SKalle Valo 	struct wmi_pktlog_enable_cmd *cmd;
2820d5c65159SKalle Valo 	struct sk_buff *skb;
2821d5c65159SKalle Valo 	int ret;
2822d5c65159SKalle Valo 
28236bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2824d5c65159SKalle Valo 	if (!skb)
2825d5c65159SKalle Valo 		return -ENOMEM;
2826d5c65159SKalle Valo 
2827d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
2828d5c65159SKalle Valo 
2829d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
2830d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2831d5c65159SKalle Valo 
2832d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2833d5c65159SKalle Valo 	cmd->evlist = pktlog_filter;
2834d5c65159SKalle Valo 	cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
2835d5c65159SKalle Valo 
2836d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2837d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_ENABLE_CMDID);
2838d5c65159SKalle Valo 	if (ret) {
2839d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2840d5c65159SKalle Valo 		dev_kfree_skb(skb);
2841d5c65159SKalle Valo 	}
2842d5c65159SKalle Valo 
2843d5c65159SKalle Valo 	return ret;
2844d5c65159SKalle Valo }
2845d5c65159SKalle Valo 
2846d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
2847d5c65159SKalle Valo {
2848d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2849d5c65159SKalle Valo 	struct wmi_pktlog_disable_cmd *cmd;
2850d5c65159SKalle Valo 	struct sk_buff *skb;
2851d5c65159SKalle Valo 	int ret;
2852d5c65159SKalle Valo 
28536bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2854d5c65159SKalle Valo 	if (!skb)
2855d5c65159SKalle Valo 		return -ENOMEM;
2856d5c65159SKalle Valo 
2857d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
2858d5c65159SKalle Valo 
2859d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
2860d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2861d5c65159SKalle Valo 
2862d0f390eaSAnilkumar Kolli 	cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2863d5c65159SKalle Valo 
2864d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2865d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_DISABLE_CMDID);
2866d5c65159SKalle Valo 	if (ret) {
2867d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2868d5c65159SKalle Valo 		dev_kfree_skb(skb);
2869d5c65159SKalle Valo 	}
2870d5c65159SKalle Valo 
2871d5c65159SKalle Valo 	return ret;
2872d5c65159SKalle Valo }
2873d5c65159SKalle Valo 
28746d293d44SJohn Crispin int
28756d293d44SJohn Crispin ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id)
28766d293d44SJohn Crispin {
28776d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
28786bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
28796d293d44SJohn Crispin 	struct wmi_twt_enable_params_cmd *cmd;
28806d293d44SJohn Crispin 	struct sk_buff *skb;
28816d293d44SJohn Crispin 	int ret, len;
28826d293d44SJohn Crispin 
28836d293d44SJohn Crispin 	len = sizeof(*cmd);
28846d293d44SJohn Crispin 
28856bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
28866d293d44SJohn Crispin 	if (!skb)
28876d293d44SJohn Crispin 		return -ENOMEM;
28886d293d44SJohn Crispin 
288977ea8b45SJohn Crispin 	cmd = (struct wmi_twt_enable_params_cmd *)skb->data;
28906d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
28916d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
28926d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
28936d293d44SJohn Crispin 	cmd->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
28946d293d44SJohn Crispin 	cmd->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
28956d293d44SJohn Crispin 	cmd->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
28966d293d44SJohn Crispin 	cmd->congestion_thresh_teardown =
28976d293d44SJohn Crispin 		ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
28986d293d44SJohn Crispin 	cmd->congestion_thresh_critical =
28996d293d44SJohn Crispin 		ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
29006d293d44SJohn Crispin 	cmd->interference_thresh_teardown =
29016d293d44SJohn Crispin 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
29026d293d44SJohn Crispin 	cmd->interference_thresh_setup =
29036d293d44SJohn Crispin 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
29046d293d44SJohn Crispin 	cmd->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
29056d293d44SJohn Crispin 	cmd->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
29066d293d44SJohn Crispin 	cmd->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
29076d293d44SJohn Crispin 	cmd->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
29086d293d44SJohn Crispin 	cmd->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
29096d293d44SJohn Crispin 	cmd->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
29106d293d44SJohn Crispin 	cmd->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
29116d293d44SJohn Crispin 	cmd->remove_sta_slot_interval =
29126d293d44SJohn Crispin 		ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
29136d293d44SJohn Crispin 	/* TODO add MBSSID support */
29146d293d44SJohn Crispin 	cmd->mbss_support = 0;
29156d293d44SJohn Crispin 
29166d293d44SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
29176d293d44SJohn Crispin 				  WMI_TWT_ENABLE_CMDID);
29186d293d44SJohn Crispin 	if (ret) {
29196d293d44SJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
29206d293d44SJohn Crispin 		dev_kfree_skb(skb);
29216d293d44SJohn Crispin 	}
29226d293d44SJohn Crispin 	return ret;
29236d293d44SJohn Crispin }
29246d293d44SJohn Crispin 
29256d293d44SJohn Crispin int
29266d293d44SJohn Crispin ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
29276d293d44SJohn Crispin {
29286d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29296bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
29306d293d44SJohn Crispin 	struct wmi_twt_disable_params_cmd *cmd;
29316d293d44SJohn Crispin 	struct sk_buff *skb;
29326d293d44SJohn Crispin 	int ret, len;
29336d293d44SJohn Crispin 
29346d293d44SJohn Crispin 	len = sizeof(*cmd);
29356d293d44SJohn Crispin 
29366bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
29376d293d44SJohn Crispin 	if (!skb)
29386d293d44SJohn Crispin 		return -ENOMEM;
29396d293d44SJohn Crispin 
294077ea8b45SJohn Crispin 	cmd = (struct wmi_twt_disable_params_cmd *)skb->data;
29416d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
29426d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
29436d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
29446d293d44SJohn Crispin 
29456d293d44SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
29466d293d44SJohn Crispin 				  WMI_TWT_DISABLE_CMDID);
29476d293d44SJohn Crispin 	if (ret) {
2948345a4f22SColin Ian King 		ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID");
29496d293d44SJohn Crispin 		dev_kfree_skb(skb);
29506d293d44SJohn Crispin 	}
29516d293d44SJohn Crispin 	return ret;
29526d293d44SJohn Crispin }
29536d293d44SJohn Crispin 
29543f8be640SJohn Crispin int
29553f8be640SJohn Crispin ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
29563f8be640SJohn Crispin 			     struct ieee80211_he_obss_pd *he_obss_pd)
29573f8be640SJohn Crispin {
29583f8be640SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29596bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
29603f8be640SJohn Crispin 	struct wmi_obss_spatial_reuse_params_cmd *cmd;
29613f8be640SJohn Crispin 	struct sk_buff *skb;
29623f8be640SJohn Crispin 	int ret, len;
29633f8be640SJohn Crispin 
29643f8be640SJohn Crispin 	len = sizeof(*cmd);
29653f8be640SJohn Crispin 
29666bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
29673f8be640SJohn Crispin 	if (!skb)
29683f8be640SJohn Crispin 		return -ENOMEM;
29693f8be640SJohn Crispin 
297077ea8b45SJohn Crispin 	cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data;
29713f8be640SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
29723f8be640SJohn Crispin 				     WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
29733f8be640SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
29743f8be640SJohn Crispin 	cmd->vdev_id = vdev_id;
29753f8be640SJohn Crispin 	cmd->enable = he_obss_pd->enable;
29763f8be640SJohn Crispin 	cmd->obss_min = he_obss_pd->min_offset;
29773f8be640SJohn Crispin 	cmd->obss_max = he_obss_pd->max_offset;
29783f8be640SJohn Crispin 
29793f8be640SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
29803f8be640SJohn Crispin 				  WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
29813f8be640SJohn Crispin 	if (ret) {
29823f8be640SJohn Crispin 		ath11k_warn(ab,
29833f8be640SJohn Crispin 			    "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
29843f8be640SJohn Crispin 		dev_kfree_skb(skb);
29853f8be640SJohn Crispin 	}
29863f8be640SJohn Crispin 	return ret;
29873f8be640SJohn Crispin }
29883f8be640SJohn Crispin 
29895a032c8dSJohn Crispin int
29905a032c8dSJohn Crispin ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id,
29915a032c8dSJohn Crispin 					     u8 bss_color, u32 period,
29925a032c8dSJohn Crispin 					     bool enable)
29935a032c8dSJohn Crispin {
29945a032c8dSJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
29955a032c8dSJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
29965a032c8dSJohn Crispin 	struct wmi_obss_color_collision_cfg_params_cmd *cmd;
29975a032c8dSJohn Crispin 	struct sk_buff *skb;
29985a032c8dSJohn Crispin 	int ret, len;
29995a032c8dSJohn Crispin 
30005a032c8dSJohn Crispin 	len = sizeof(*cmd);
30015a032c8dSJohn Crispin 
30025a032c8dSJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
30035a032c8dSJohn Crispin 	if (!skb)
30045a032c8dSJohn Crispin 		return -ENOMEM;
30055a032c8dSJohn Crispin 
30065a032c8dSJohn Crispin 	cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data;
30075a032c8dSJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
30085a032c8dSJohn Crispin 				     WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) |
30095a032c8dSJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
30105a032c8dSJohn Crispin 	cmd->vdev_id = vdev_id;
30115a032c8dSJohn Crispin 	cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION :
30125a032c8dSJohn Crispin 				 ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE;
30135a032c8dSJohn Crispin 	cmd->current_bss_color = bss_color;
30145a032c8dSJohn Crispin 	cmd->detection_period_ms = period;
30155a032c8dSJohn Crispin 	cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS;
30165a032c8dSJohn Crispin 	cmd->free_slot_expiry_time_ms = 0;
30175a032c8dSJohn Crispin 	cmd->flags = 0;
30185a032c8dSJohn Crispin 
30195a032c8dSJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
30205a032c8dSJohn Crispin 		   "wmi_send_obss_color_collision_cfg id %d type %d bss_color %d detect_period %d scan_period %d\n",
30215a032c8dSJohn Crispin 		   cmd->vdev_id, cmd->evt_type, cmd->current_bss_color,
30225a032c8dSJohn Crispin 		   cmd->detection_period_ms, cmd->scan_period_ms);
30235a032c8dSJohn Crispin 
30245a032c8dSJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
30255a032c8dSJohn Crispin 				  WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID);
30265a032c8dSJohn Crispin 	if (ret) {
30275a032c8dSJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID");
30285a032c8dSJohn Crispin 		dev_kfree_skb(skb);
30295a032c8dSJohn Crispin 	}
30305a032c8dSJohn Crispin 	return ret;
30315a032c8dSJohn Crispin }
30325a032c8dSJohn Crispin 
30335a032c8dSJohn Crispin int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id,
30345a032c8dSJohn Crispin 						bool enable)
30355a032c8dSJohn Crispin {
30365a032c8dSJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
30375a032c8dSJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
30385a032c8dSJohn Crispin 	struct wmi_bss_color_change_enable_params_cmd *cmd;
30395a032c8dSJohn Crispin 	struct sk_buff *skb;
30405a032c8dSJohn Crispin 	int ret, len;
30415a032c8dSJohn Crispin 
30425a032c8dSJohn Crispin 	len = sizeof(*cmd);
30435a032c8dSJohn Crispin 
30445a032c8dSJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
30455a032c8dSJohn Crispin 	if (!skb)
30465a032c8dSJohn Crispin 		return -ENOMEM;
30475a032c8dSJohn Crispin 
30485a032c8dSJohn Crispin 	cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data;
30495a032c8dSJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) |
30505a032c8dSJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
30515a032c8dSJohn Crispin 	cmd->vdev_id = vdev_id;
30525a032c8dSJohn Crispin 	cmd->enable = enable ? 1 : 0;
30535a032c8dSJohn Crispin 
30545a032c8dSJohn Crispin 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
30555a032c8dSJohn Crispin 		   "wmi_send_bss_color_change_enable id %d enable %d\n",
30565a032c8dSJohn Crispin 		   cmd->vdev_id, cmd->enable);
30575a032c8dSJohn Crispin 
30585a032c8dSJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
30595a032c8dSJohn Crispin 				  WMI_BSS_COLOR_CHANGE_ENABLE_CMDID);
30605a032c8dSJohn Crispin 	if (ret) {
30619a8074e3SColin Ian King 		ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID");
30625a032c8dSJohn Crispin 		dev_kfree_skb(skb);
30635a032c8dSJohn Crispin 	}
30645a032c8dSJohn Crispin 	return ret;
30655a032c8dSJohn Crispin }
30665a032c8dSJohn Crispin 
3067d5c65159SKalle Valo static void
3068d5c65159SKalle Valo ath11k_fill_band_to_mac_param(struct ath11k_base  *soc,
3069d5c65159SKalle Valo 			      struct wmi_host_pdev_band_to_mac *band_to_mac)
3070d5c65159SKalle Valo {
3071d5c65159SKalle Valo 	u8 i;
3072d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
3073d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
3074d5c65159SKalle Valo 
3075d5c65159SKalle Valo 	for (i = 0; i < soc->num_radios; i++) {
3076d5c65159SKalle Valo 		pdev = &soc->pdevs[i];
3077d5c65159SKalle Valo 		hal_reg_cap = &soc->hal_reg_cap[i];
3078d5c65159SKalle Valo 		band_to_mac[i].pdev_id = pdev->pdev_id;
3079d5c65159SKalle Valo 
3080d5c65159SKalle Valo 		switch (pdev->cap.supported_bands) {
3081d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_5G_CAP:
3082d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3083d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3084d5c65159SKalle Valo 			break;
3085d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_CAP:
3086d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3087d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
3088d5c65159SKalle Valo 			break;
3089d5c65159SKalle Valo 		case WMI_HOST_WLAN_5G_CAP:
3090d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
3091d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3092d5c65159SKalle Valo 			break;
3093d5c65159SKalle Valo 		default:
3094d5c65159SKalle Valo 			break;
3095d5c65159SKalle Valo 		}
3096d5c65159SKalle Valo 	}
3097d5c65159SKalle Valo }
3098d5c65159SKalle Valo 
3099d5c65159SKalle Valo static void
3100d5c65159SKalle Valo ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
3101d5c65159SKalle Valo 				struct target_resource_config *tg_cfg)
3102d5c65159SKalle Valo {
3103d5c65159SKalle Valo 	wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
3104d5c65159SKalle Valo 	wmi_cfg->num_peers = tg_cfg->num_peers;
3105d5c65159SKalle Valo 	wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
3106d5c65159SKalle Valo 	wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
3107d5c65159SKalle Valo 	wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
3108d5c65159SKalle Valo 	wmi_cfg->num_tids = tg_cfg->num_tids;
3109d5c65159SKalle Valo 	wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
3110d5c65159SKalle Valo 	wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
3111d5c65159SKalle Valo 	wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
3112d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
3113d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
3114d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
3115d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
3116d5c65159SKalle Valo 	wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
3117d5c65159SKalle Valo 	wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
3118d5c65159SKalle Valo 	wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
3119d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
3120d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_ap_profiles =
3121d5c65159SKalle Valo 		tg_cfg->roam_offload_max_ap_profiles;
3122d5c65159SKalle Valo 	wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
3123d5c65159SKalle Valo 	wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
3124d5c65159SKalle Valo 	wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
3125d5c65159SKalle Valo 	wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
3126d5c65159SKalle Valo 	wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
3127d5c65159SKalle Valo 	wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
3128d5c65159SKalle Valo 	wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
3129d5c65159SKalle Valo 	wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
3130d5c65159SKalle Valo 		tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
3131d5c65159SKalle Valo 	wmi_cfg->vow_config = tg_cfg->vow_config;
3132d5c65159SKalle Valo 	wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
3133d5c65159SKalle Valo 	wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
3134d5c65159SKalle Valo 	wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
3135d5c65159SKalle Valo 	wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
3136d5c65159SKalle Valo 	wmi_cfg->num_tdls_conn_table_entries =
3137d5c65159SKalle Valo 		tg_cfg->num_tdls_conn_table_entries;
3138d5c65159SKalle Valo 	wmi_cfg->beacon_tx_offload_max_vdev =
3139d5c65159SKalle Valo 		tg_cfg->beacon_tx_offload_max_vdev;
3140d5c65159SKalle Valo 	wmi_cfg->num_multicast_filter_entries =
3141d5c65159SKalle Valo 		tg_cfg->num_multicast_filter_entries;
3142d5c65159SKalle Valo 	wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
3143d5c65159SKalle Valo 	wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
3144d5c65159SKalle Valo 	wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
3145d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_sleep_sta =
3146d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_sleep_sta;
3147d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_buffer_sta =
3148d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_buffer_sta;
3149d5c65159SKalle Valo 	wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
3150d5c65159SKalle Valo 	wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
3151d5c65159SKalle Valo 	wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
3152d5c65159SKalle Valo 	wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
3153d5c65159SKalle Valo 	wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
3154d5c65159SKalle Valo 	wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
3155d5c65159SKalle Valo 	wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
3156d5c65159SKalle Valo 	wmi_cfg->flag1 = tg_cfg->atf_config;
3157d5c65159SKalle Valo 	wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
31586d293d44SJohn Crispin 	wmi_cfg->sched_params = tg_cfg->sched_params;
31596d293d44SJohn Crispin 	wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
31606d293d44SJohn Crispin 	wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
3161d5c65159SKalle Valo }
3162d5c65159SKalle Valo 
3163d5c65159SKalle Valo static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
3164d5c65159SKalle Valo 				struct wmi_init_cmd_param *param)
3165d5c65159SKalle Valo {
31666bc9d6f7SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_ab->ab;
3167d5c65159SKalle Valo 	struct sk_buff *skb;
3168d5c65159SKalle Valo 	struct wmi_init_cmd *cmd;
3169d5c65159SKalle Valo 	struct wmi_resource_config *cfg;
3170d5c65159SKalle Valo 	struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
3171d5c65159SKalle Valo 	struct wmi_pdev_band_to_mac *band_to_mac;
3172d5c65159SKalle Valo 	struct wlan_host_mem_chunk *host_mem_chunks;
3173d5c65159SKalle Valo 	struct wmi_tlv *tlv;
3174d5c65159SKalle Valo 	size_t ret, len;
3175d5c65159SKalle Valo 	void *ptr;
3176d5c65159SKalle Valo 	u32 hw_mode_len = 0;
3177d5c65159SKalle Valo 	u16 idx;
3178d5c65159SKalle Valo 
3179d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
3180d5c65159SKalle Valo 		hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
3181d5c65159SKalle Valo 			      (param->num_band_to_mac * sizeof(*band_to_mac));
3182d5c65159SKalle Valo 
3183d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
31842d4bcbedSCarl Huang 	      (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0);
3185d5c65159SKalle Valo 
31866bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3187d5c65159SKalle Valo 	if (!skb)
3188d5c65159SKalle Valo 		return -ENOMEM;
3189d5c65159SKalle Valo 
3190d5c65159SKalle Valo 	cmd = (struct wmi_init_cmd *)skb->data;
3191d5c65159SKalle Valo 
3192d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
3193d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3194d5c65159SKalle Valo 
3195d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
3196d5c65159SKalle Valo 	cfg = ptr;
3197d5c65159SKalle Valo 
3198d5c65159SKalle Valo 	ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
3199d5c65159SKalle Valo 
3200d5c65159SKalle Valo 	cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
3201d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
3202d5c65159SKalle Valo 
3203d5c65159SKalle Valo 	ptr += sizeof(*cfg);
3204d5c65159SKalle Valo 	host_mem_chunks = ptr + TLV_HDR_SIZE;
3205d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk);
3206d5c65159SKalle Valo 
3207d5c65159SKalle Valo 	for (idx = 0; idx < param->num_mem_chunks; ++idx) {
3208d5c65159SKalle Valo 		host_mem_chunks[idx].tlv_header =
3209d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
3210d5c65159SKalle Valo 					   WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
3211d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN, len);
3212d5c65159SKalle Valo 
3213d5c65159SKalle Valo 		host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
3214d5c65159SKalle Valo 		host_mem_chunks[idx].size = param->mem_chunks[idx].len;
3215d5c65159SKalle Valo 		host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
3216d5c65159SKalle Valo 
3217d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
3218d5c65159SKalle Valo 			   "WMI host mem chunk req_id %d paddr 0x%llx len %d\n",
3219d5c65159SKalle Valo 			   param->mem_chunks[idx].req_id,
3220d5c65159SKalle Valo 			   (u64)param->mem_chunks[idx].paddr,
3221d5c65159SKalle Valo 			   param->mem_chunks[idx].len);
3222d5c65159SKalle Valo 	}
3223d5c65159SKalle Valo 	cmd->num_host_mem_chunks = param->num_mem_chunks;
3224d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
3225d5c65159SKalle Valo 
3226d5c65159SKalle Valo 	/* num_mem_chunks is zero */
3227d5c65159SKalle Valo 	tlv = ptr;
3228d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
3229d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
3230d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE + len;
3231d5c65159SKalle Valo 
3232d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
3233d5c65159SKalle Valo 		hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr;
3234d5c65159SKalle Valo 		hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3235d5c65159SKalle Valo 						 WMI_TAG_PDEV_SET_HW_MODE_CMD) |
3236d5c65159SKalle Valo 				      FIELD_PREP(WMI_TLV_LEN,
3237d5c65159SKalle Valo 						 sizeof(*hw_mode) - TLV_HDR_SIZE);
3238d5c65159SKalle Valo 
3239d5c65159SKalle Valo 		hw_mode->hw_mode_index = param->hw_mode_id;
3240d5c65159SKalle Valo 		hw_mode->num_band_to_mac = param->num_band_to_mac;
3241d5c65159SKalle Valo 
3242d5c65159SKalle Valo 		ptr += sizeof(*hw_mode);
3243d5c65159SKalle Valo 
3244d5c65159SKalle Valo 		len = param->num_band_to_mac * sizeof(*band_to_mac);
3245d5c65159SKalle Valo 		tlv = ptr;
3246d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
3247d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len);
3248d5c65159SKalle Valo 
3249d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
3250d5c65159SKalle Valo 		len = sizeof(*band_to_mac);
3251d5c65159SKalle Valo 
3252d5c65159SKalle Valo 		for (idx = 0; idx < param->num_band_to_mac; idx++) {
3253d5c65159SKalle Valo 			band_to_mac = (void *)ptr;
3254d5c65159SKalle Valo 
3255d5c65159SKalle Valo 			band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3256d5c65159SKalle Valo 							     WMI_TAG_PDEV_BAND_TO_MAC) |
3257d5c65159SKalle Valo 						  FIELD_PREP(WMI_TLV_LEN,
3258d5c65159SKalle Valo 							     len - TLV_HDR_SIZE);
3259d5c65159SKalle Valo 			band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
3260d5c65159SKalle Valo 			band_to_mac->start_freq =
3261d5c65159SKalle Valo 				param->band_to_mac[idx].start_freq;
3262d5c65159SKalle Valo 			band_to_mac->end_freq =
3263d5c65159SKalle Valo 				param->band_to_mac[idx].end_freq;
3264d5c65159SKalle Valo 			ptr += sizeof(*band_to_mac);
3265d5c65159SKalle Valo 		}
3266d5c65159SKalle Valo 	}
3267d5c65159SKalle Valo 
3268d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
3269d5c65159SKalle Valo 	if (ret) {
3270d5c65159SKalle Valo 		ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
3271d5c65159SKalle Valo 		dev_kfree_skb(skb);
3272d5c65159SKalle Valo 	}
3273d5c65159SKalle Valo 
3274d5c65159SKalle Valo 	return ret;
3275d5c65159SKalle Valo }
3276d5c65159SKalle Valo 
327726c79927SSriram R int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar,
327826c79927SSriram R 			    int pdev_id)
327926c79927SSriram R {
328026c79927SSriram R 	struct ath11k_wmi_pdev_lro_config_cmd *cmd;
328126c79927SSriram R 	struct sk_buff *skb;
328226c79927SSriram R 	int ret;
328326c79927SSriram R 
328426c79927SSriram R 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
328526c79927SSriram R 	if (!skb)
328626c79927SSriram R 		return -ENOMEM;
328726c79927SSriram R 
328826c79927SSriram R 	cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data;
328926c79927SSriram R 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) |
329026c79927SSriram R 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
329126c79927SSriram R 
329226c79927SSriram R 	get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE);
329326c79927SSriram R 	get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE);
329426c79927SSriram R 
329526c79927SSriram R 	cmd->pdev_id = pdev_id;
329626c79927SSriram R 
329726c79927SSriram R 	ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID);
329826c79927SSriram R 	if (ret) {
329926c79927SSriram R 		ath11k_warn(ar->ab,
330026c79927SSriram R 			    "failed to send lro cfg req wmi cmd\n");
330126c79927SSriram R 		goto err;
330226c79927SSriram R 	}
330326c79927SSriram R 
330426c79927SSriram R 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
330526c79927SSriram R 		   "WMI lro cfg cmd pdev_id 0x%x\n", pdev_id);
330626c79927SSriram R 	return 0;
330726c79927SSriram R err:
330826c79927SSriram R 	dev_kfree_skb(skb);
330926c79927SSriram R 	return ret;
331026c79927SSriram R }
331126c79927SSriram R 
3312d5c65159SKalle Valo int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
3313d5c65159SKalle Valo {
3314d5c65159SKalle Valo 	unsigned long time_left;
3315d5c65159SKalle Valo 
33166bc9d6f7SJohn Crispin 	time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready,
3317d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
3318d5c65159SKalle Valo 	if (!time_left)
3319d5c65159SKalle Valo 		return -ETIMEDOUT;
3320d5c65159SKalle Valo 
3321d5c65159SKalle Valo 	return 0;
3322d5c65159SKalle Valo }
3323d5c65159SKalle Valo 
3324d5c65159SKalle Valo int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
3325d5c65159SKalle Valo {
3326d5c65159SKalle Valo 	unsigned long time_left;
3327d5c65159SKalle Valo 
33286bc9d6f7SJohn Crispin 	time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready,
3329d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
3330d5c65159SKalle Valo 	if (!time_left)
3331d5c65159SKalle Valo 		return -ETIMEDOUT;
3332d5c65159SKalle Valo 
3333d5c65159SKalle Valo 	return 0;
3334d5c65159SKalle Valo }
3335d5c65159SKalle Valo 
3336d5c65159SKalle Valo int ath11k_wmi_cmd_init(struct ath11k_base *ab)
3337d5c65159SKalle Valo {
33386bc9d6f7SJohn Crispin 	struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab;
3339d5c65159SKalle Valo 	struct wmi_init_cmd_param init_param;
3340d5c65159SKalle Valo 	struct target_resource_config  config;
3341d5c65159SKalle Valo 
3342d5c65159SKalle Valo 	memset(&init_param, 0, sizeof(init_param));
3343d5c65159SKalle Valo 	memset(&config, 0, sizeof(config));
3344d5c65159SKalle Valo 
33452d4bcbedSCarl Huang 	ab->hw_params.hw_ops->wmi_init_config(ab, &config);
33462d4bcbedSCarl Huang 
3347d5c65159SKalle Valo 	memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config));
3348d5c65159SKalle Valo 
3349d5c65159SKalle Valo 	init_param.res_cfg = &wmi_sc->wlan_resource_config;
3350d5c65159SKalle Valo 	init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
3351d5c65159SKalle Valo 	init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
3352d5c65159SKalle Valo 	init_param.mem_chunks = wmi_sc->mem_chunks;
3353d5c65159SKalle Valo 
3354d5c65159SKalle Valo 	if (wmi_sc->preferred_hw_mode == WMI_HOST_HW_MODE_SINGLE)
3355d5c65159SKalle Valo 		init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
3356d5c65159SKalle Valo 
3357ed0192f7SCarl Huang 	if (ab->hw_params.needs_band_to_mac) {
3358d5c65159SKalle Valo 		init_param.num_band_to_mac = ab->num_radios;
3359d5c65159SKalle Valo 		ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
3360ed0192f7SCarl Huang 	}
3361d5c65159SKalle Valo 
3362d5c65159SKalle Valo 	return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param);
3363d5c65159SKalle Valo }
3364d5c65159SKalle Valo 
33659d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar,
33669d11b7bfSKarthikeyan Periyasamy 				  struct ath11k_wmi_vdev_spectral_conf_param *param)
33679d11b7bfSKarthikeyan Periyasamy {
33689d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_vdev_spectral_conf_cmd *cmd;
33699d11b7bfSKarthikeyan Periyasamy 	struct sk_buff *skb;
33709d11b7bfSKarthikeyan Periyasamy 	int ret;
33719d11b7bfSKarthikeyan Periyasamy 
33729d11b7bfSKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
33739d11b7bfSKarthikeyan Periyasamy 	if (!skb)
33749d11b7bfSKarthikeyan Periyasamy 		return -ENOMEM;
33759d11b7bfSKarthikeyan Periyasamy 
33769d11b7bfSKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data;
33779d11b7bfSKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
33789d11b7bfSKarthikeyan Periyasamy 				     WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) |
33799d11b7bfSKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
33809d11b7bfSKarthikeyan Periyasamy 
33819d11b7bfSKarthikeyan Periyasamy 	memcpy(&cmd->param, param, sizeof(*param));
33829d11b7bfSKarthikeyan Periyasamy 
33839d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
33849d11b7bfSKarthikeyan Periyasamy 				  WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
33859d11b7bfSKarthikeyan Periyasamy 	if (ret) {
33869d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
33879d11b7bfSKarthikeyan Periyasamy 			    "failed to send spectral scan config wmi cmd\n");
33889d11b7bfSKarthikeyan Periyasamy 		goto err;
33899d11b7bfSKarthikeyan Periyasamy 	}
33909d11b7bfSKarthikeyan Periyasamy 
33919d11b7bfSKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
33929d11b7bfSKarthikeyan Periyasamy 		   "WMI spectral scan config cmd vdev_id 0x%x\n",
33939d11b7bfSKarthikeyan Periyasamy 		   param->vdev_id);
33949d11b7bfSKarthikeyan Periyasamy 
33959d11b7bfSKarthikeyan Periyasamy 	return 0;
33969d11b7bfSKarthikeyan Periyasamy err:
33979d11b7bfSKarthikeyan Periyasamy 	dev_kfree_skb(skb);
33989d11b7bfSKarthikeyan Periyasamy 	return ret;
33999d11b7bfSKarthikeyan Periyasamy }
34009d11b7bfSKarthikeyan Periyasamy 
34019d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id,
34029d11b7bfSKarthikeyan Periyasamy 				    u32 trigger, u32 enable)
34039d11b7bfSKarthikeyan Periyasamy {
34049d11b7bfSKarthikeyan Periyasamy 	struct ath11k_wmi_vdev_spectral_enable_cmd *cmd;
34059d11b7bfSKarthikeyan Periyasamy 	struct sk_buff *skb;
34069d11b7bfSKarthikeyan Periyasamy 	int ret;
34079d11b7bfSKarthikeyan Periyasamy 
34089d11b7bfSKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
34099d11b7bfSKarthikeyan Periyasamy 	if (!skb)
34109d11b7bfSKarthikeyan Periyasamy 		return -ENOMEM;
34119d11b7bfSKarthikeyan Periyasamy 
34129d11b7bfSKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data;
34139d11b7bfSKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
34149d11b7bfSKarthikeyan Periyasamy 				     WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) |
34159d11b7bfSKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
34169d11b7bfSKarthikeyan Periyasamy 
34179d11b7bfSKarthikeyan Periyasamy 	cmd->vdev_id = vdev_id;
34189d11b7bfSKarthikeyan Periyasamy 	cmd->trigger_cmd = trigger;
34199d11b7bfSKarthikeyan Periyasamy 	cmd->enable_cmd = enable;
34209d11b7bfSKarthikeyan Periyasamy 
34219d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
34229d11b7bfSKarthikeyan Periyasamy 				  WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
34239d11b7bfSKarthikeyan Periyasamy 	if (ret) {
34249d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
34259d11b7bfSKarthikeyan Periyasamy 			    "failed to send spectral enable wmi cmd\n");
34269d11b7bfSKarthikeyan Periyasamy 		goto err;
34279d11b7bfSKarthikeyan Periyasamy 	}
34289d11b7bfSKarthikeyan Periyasamy 
34299d11b7bfSKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
34309d11b7bfSKarthikeyan Periyasamy 		   "WMI spectral enable cmd vdev id 0x%x\n",
34319d11b7bfSKarthikeyan Periyasamy 		   vdev_id);
34329d11b7bfSKarthikeyan Periyasamy 
34339d11b7bfSKarthikeyan Periyasamy 	return 0;
34349d11b7bfSKarthikeyan Periyasamy err:
34359d11b7bfSKarthikeyan Periyasamy 	dev_kfree_skb(skb);
34369d11b7bfSKarthikeyan Periyasamy 	return ret;
34379d11b7bfSKarthikeyan Periyasamy }
34389d11b7bfSKarthikeyan Periyasamy 
3439bd647855SKarthikeyan Periyasamy int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar,
3440bd647855SKarthikeyan Periyasamy 				 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param)
3441bd647855SKarthikeyan Periyasamy {
3442bd647855SKarthikeyan Periyasamy 	struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd;
3443bd647855SKarthikeyan Periyasamy 	struct sk_buff *skb;
3444bd647855SKarthikeyan Periyasamy 	int ret;
3445bd647855SKarthikeyan Periyasamy 
3446bd647855SKarthikeyan Periyasamy 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
3447bd647855SKarthikeyan Periyasamy 	if (!skb)
3448bd647855SKarthikeyan Periyasamy 		return -ENOMEM;
3449bd647855SKarthikeyan Periyasamy 
3450bd647855SKarthikeyan Periyasamy 	cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data;
3451bd647855SKarthikeyan Periyasamy 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) |
3452bd647855SKarthikeyan Periyasamy 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3453bd647855SKarthikeyan Periyasamy 
3454bd647855SKarthikeyan Periyasamy 	cmd->pdev_id		= param->pdev_id;
3455bd647855SKarthikeyan Periyasamy 	cmd->module_id		= param->module_id;
3456bd647855SKarthikeyan Periyasamy 	cmd->base_paddr_lo	= param->base_paddr_lo;
3457bd647855SKarthikeyan Periyasamy 	cmd->base_paddr_hi	= param->base_paddr_hi;
3458bd647855SKarthikeyan Periyasamy 	cmd->head_idx_paddr_lo	= param->head_idx_paddr_lo;
3459bd647855SKarthikeyan Periyasamy 	cmd->head_idx_paddr_hi	= param->head_idx_paddr_hi;
3460bd647855SKarthikeyan Periyasamy 	cmd->tail_idx_paddr_lo	= param->tail_idx_paddr_lo;
3461bd647855SKarthikeyan Periyasamy 	cmd->tail_idx_paddr_hi	= param->tail_idx_paddr_hi;
3462bd647855SKarthikeyan Periyasamy 	cmd->num_elems		= param->num_elems;
3463bd647855SKarthikeyan Periyasamy 	cmd->buf_size		= param->buf_size;
3464bd647855SKarthikeyan Periyasamy 	cmd->num_resp_per_event	= param->num_resp_per_event;
3465bd647855SKarthikeyan Periyasamy 	cmd->event_timeout_ms	= param->event_timeout_ms;
3466bd647855SKarthikeyan Periyasamy 
3467bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
3468bd647855SKarthikeyan Periyasamy 				  WMI_PDEV_DMA_RING_CFG_REQ_CMDID);
3469bd647855SKarthikeyan Periyasamy 	if (ret) {
3470bd647855SKarthikeyan Periyasamy 		ath11k_warn(ar->ab,
3471bd647855SKarthikeyan Periyasamy 			    "failed to send dma ring cfg req wmi cmd\n");
3472bd647855SKarthikeyan Periyasamy 		goto err;
3473bd647855SKarthikeyan Periyasamy 	}
3474bd647855SKarthikeyan Periyasamy 
3475bd647855SKarthikeyan Periyasamy 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3476bd647855SKarthikeyan Periyasamy 		   "WMI DMA ring cfg req cmd pdev_id 0x%x\n",
3477bd647855SKarthikeyan Periyasamy 		   param->pdev_id);
3478bd647855SKarthikeyan Periyasamy 
3479bd647855SKarthikeyan Periyasamy 	return 0;
3480bd647855SKarthikeyan Periyasamy err:
3481bd647855SKarthikeyan Periyasamy 	dev_kfree_skb(skb);
3482bd647855SKarthikeyan Periyasamy 	return ret;
3483bd647855SKarthikeyan Periyasamy }
3484bd647855SKarthikeyan Periyasamy 
34859d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc,
34869d11b7bfSKarthikeyan Periyasamy 					      u16 tag, u16 len,
34879d11b7bfSKarthikeyan Periyasamy 					      const void *ptr, void *data)
34889d11b7bfSKarthikeyan Periyasamy {
34899d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
34909d11b7bfSKarthikeyan Periyasamy 
34919d11b7bfSKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY)
34929d11b7bfSKarthikeyan Periyasamy 		return -EPROTO;
34939d11b7bfSKarthikeyan Periyasamy 
34949d11b7bfSKarthikeyan Periyasamy 	if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry)
34959d11b7bfSKarthikeyan Periyasamy 		return -ENOBUFS;
34969d11b7bfSKarthikeyan Periyasamy 
34979d11b7bfSKarthikeyan Periyasamy 	parse->num_buf_entry++;
34989d11b7bfSKarthikeyan Periyasamy 	return 0;
34999d11b7bfSKarthikeyan Periyasamy }
35009d11b7bfSKarthikeyan Periyasamy 
35019d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc,
35029d11b7bfSKarthikeyan Periyasamy 					     u16 tag, u16 len,
35039d11b7bfSKarthikeyan Periyasamy 					     const void *ptr, void *data)
35049d11b7bfSKarthikeyan Periyasamy {
35059d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
35069d11b7bfSKarthikeyan Periyasamy 
35079d11b7bfSKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA)
35089d11b7bfSKarthikeyan Periyasamy 		return -EPROTO;
35099d11b7bfSKarthikeyan Periyasamy 
35109d11b7bfSKarthikeyan Periyasamy 	if (parse->num_meta >= parse->fixed.num_meta_data_entry)
35119d11b7bfSKarthikeyan Periyasamy 		return -ENOBUFS;
35129d11b7bfSKarthikeyan Periyasamy 
35139d11b7bfSKarthikeyan Periyasamy 	parse->num_meta++;
35149d11b7bfSKarthikeyan Periyasamy 	return 0;
35159d11b7bfSKarthikeyan Periyasamy }
35169d11b7bfSKarthikeyan Periyasamy 
35179d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab,
35189d11b7bfSKarthikeyan Periyasamy 					u16 tag, u16 len,
35199d11b7bfSKarthikeyan Periyasamy 					const void *ptr, void *data)
35209d11b7bfSKarthikeyan Periyasamy {
35219d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse *parse = data;
35229d11b7bfSKarthikeyan Periyasamy 	int ret;
35239d11b7bfSKarthikeyan Periyasamy 
35249d11b7bfSKarthikeyan Periyasamy 	switch (tag) {
35259d11b7bfSKarthikeyan Periyasamy 	case WMI_TAG_DMA_BUF_RELEASE:
35269d11b7bfSKarthikeyan Periyasamy 		memcpy(&parse->fixed, ptr,
35279d11b7bfSKarthikeyan Periyasamy 		       sizeof(struct ath11k_wmi_dma_buf_release_fixed_param));
35289d11b7bfSKarthikeyan Periyasamy 		parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id);
35299d11b7bfSKarthikeyan Periyasamy 		break;
35309d11b7bfSKarthikeyan Periyasamy 	case WMI_TAG_ARRAY_STRUCT:
35319d11b7bfSKarthikeyan Periyasamy 		if (!parse->buf_entry_done) {
35329d11b7bfSKarthikeyan Periyasamy 			parse->num_buf_entry = 0;
35339d11b7bfSKarthikeyan Periyasamy 			parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr;
35349d11b7bfSKarthikeyan Periyasamy 
35359d11b7bfSKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
35369d11b7bfSKarthikeyan Periyasamy 						  ath11k_wmi_tlv_dma_buf_entry_parse,
35379d11b7bfSKarthikeyan Periyasamy 						  parse);
35389d11b7bfSKarthikeyan Periyasamy 			if (ret) {
35399d11b7bfSKarthikeyan Periyasamy 				ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n",
35409d11b7bfSKarthikeyan Periyasamy 					    ret);
35419d11b7bfSKarthikeyan Periyasamy 				return ret;
35429d11b7bfSKarthikeyan Periyasamy 			}
35439d11b7bfSKarthikeyan Periyasamy 
35449d11b7bfSKarthikeyan Periyasamy 			parse->buf_entry_done = true;
35459d11b7bfSKarthikeyan Periyasamy 		} else if (!parse->meta_data_done) {
35469d11b7bfSKarthikeyan Periyasamy 			parse->num_meta = 0;
35479d11b7bfSKarthikeyan Periyasamy 			parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr;
35489d11b7bfSKarthikeyan Periyasamy 
35499d11b7bfSKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
35509d11b7bfSKarthikeyan Periyasamy 						  ath11k_wmi_tlv_dma_buf_meta_parse,
35519d11b7bfSKarthikeyan Periyasamy 						  parse);
35529d11b7bfSKarthikeyan Periyasamy 			if (ret) {
35539d11b7bfSKarthikeyan Periyasamy 				ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n",
35549d11b7bfSKarthikeyan Periyasamy 					    ret);
35559d11b7bfSKarthikeyan Periyasamy 				return ret;
35569d11b7bfSKarthikeyan Periyasamy 			}
35579d11b7bfSKarthikeyan Periyasamy 
35589d11b7bfSKarthikeyan Periyasamy 			parse->meta_data_done = true;
35599d11b7bfSKarthikeyan Periyasamy 		}
35609d11b7bfSKarthikeyan Periyasamy 		break;
35619d11b7bfSKarthikeyan Periyasamy 	default:
35629d11b7bfSKarthikeyan Periyasamy 		break;
35639d11b7bfSKarthikeyan Periyasamy 	}
35649d11b7bfSKarthikeyan Periyasamy 	return 0;
35659d11b7bfSKarthikeyan Periyasamy }
35669d11b7bfSKarthikeyan Periyasamy 
35679d11b7bfSKarthikeyan Periyasamy static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab,
35689d11b7bfSKarthikeyan Periyasamy 						       struct sk_buff *skb)
35699d11b7bfSKarthikeyan Periyasamy {
35709d11b7bfSKarthikeyan Periyasamy 	struct wmi_tlv_dma_buf_release_parse parse = { };
35719d11b7bfSKarthikeyan Periyasamy 	struct ath11k_dbring_buf_release_event param;
35729d11b7bfSKarthikeyan Periyasamy 	int ret;
35739d11b7bfSKarthikeyan Periyasamy 
35749d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
35759d11b7bfSKarthikeyan Periyasamy 				  ath11k_wmi_tlv_dma_buf_parse,
35769d11b7bfSKarthikeyan Periyasamy 				  &parse);
35779d11b7bfSKarthikeyan Periyasamy 	if (ret) {
35789d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret);
35799d11b7bfSKarthikeyan Periyasamy 		return;
35809d11b7bfSKarthikeyan Periyasamy 	}
35819d11b7bfSKarthikeyan Periyasamy 
35829d11b7bfSKarthikeyan Periyasamy 	param.fixed		= parse.fixed;
35839d11b7bfSKarthikeyan Periyasamy 	param.buf_entry		= parse.buf_entry;
35849d11b7bfSKarthikeyan Periyasamy 	param.num_buf_entry	= parse.num_buf_entry;
35859d11b7bfSKarthikeyan Periyasamy 	param.meta_data		= parse.meta_data;
35869d11b7bfSKarthikeyan Periyasamy 	param.num_meta		= parse.num_meta;
35879d11b7bfSKarthikeyan Periyasamy 
35889d11b7bfSKarthikeyan Periyasamy 	ret = ath11k_dbring_buffer_release_event(ab, &param);
35899d11b7bfSKarthikeyan Periyasamy 	if (ret) {
35909d11b7bfSKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
35919d11b7bfSKarthikeyan Periyasamy 		return;
35929d11b7bfSKarthikeyan Periyasamy 	}
35939d11b7bfSKarthikeyan Periyasamy }
35949d11b7bfSKarthikeyan Periyasamy 
3595d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
3596d5c65159SKalle Valo 					     u16 tag, u16 len,
3597d5c65159SKalle Valo 					     const void *ptr, void *data)
3598d5c65159SKalle Valo {
3599d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3600d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_cap;
3601d5c65159SKalle Valo 	u32 phy_map = 0;
3602d5c65159SKalle Valo 
3603d5c65159SKalle Valo 	if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
3604d5c65159SKalle Valo 		return -EPROTO;
3605d5c65159SKalle Valo 
3606d5c65159SKalle Valo 	if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
3607d5c65159SKalle Valo 		return -ENOBUFS;
3608d5c65159SKalle Valo 
3609d5c65159SKalle Valo 	hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
3610d5c65159SKalle Valo 				   hw_mode_id);
3611d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps++;
3612d5c65159SKalle Valo 
3613d5c65159SKalle Valo 	phy_map = hw_mode_cap->phy_id_map;
3614d5c65159SKalle Valo 	while (phy_map) {
3615d5c65159SKalle Valo 		svc_rdy_ext->tot_phy_id++;
3616d5c65159SKalle Valo 		phy_map = phy_map >> 1;
3617d5c65159SKalle Valo 	}
3618d5c65159SKalle Valo 
3619d5c65159SKalle Valo 	return 0;
3620d5c65159SKalle Valo }
3621d5c65159SKalle Valo 
3622d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
3623d5c65159SKalle Valo 				       u16 len, const void *ptr, void *data)
3624d5c65159SKalle Valo {
3625d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3626d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
3627d5c65159SKalle Valo 	enum wmi_host_hw_mode_config_type mode, pref;
3628d5c65159SKalle Valo 	u32 i;
3629d5c65159SKalle Valo 	int ret;
3630d5c65159SKalle Valo 
3631d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps = 0;
3632d5c65159SKalle Valo 	svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
3633d5c65159SKalle Valo 
3634d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
3635d5c65159SKalle Valo 				  ath11k_wmi_tlv_hw_mode_caps_parse,
3636d5c65159SKalle Valo 				  svc_rdy_ext);
3637d5c65159SKalle Valo 	if (ret) {
3638d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
3639d5c65159SKalle Valo 		return ret;
3640d5c65159SKalle Valo 	}
3641d5c65159SKalle Valo 
3642d5c65159SKalle Valo 	i = 0;
3643d5c65159SKalle Valo 	while (i < svc_rdy_ext->n_hw_mode_caps) {
3644d5c65159SKalle Valo 		hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
3645d5c65159SKalle Valo 		mode = hw_mode_caps->hw_mode_id;
36466bc9d6f7SJohn Crispin 		pref = soc->wmi_ab.preferred_hw_mode;
3647d5c65159SKalle Valo 
3648d5c65159SKalle Valo 		if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
3649d5c65159SKalle Valo 			svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
36506bc9d6f7SJohn Crispin 			soc->wmi_ab.preferred_hw_mode = mode;
3651d5c65159SKalle Valo 		}
3652d5c65159SKalle Valo 		i++;
3653d5c65159SKalle Valo 	}
3654d5c65159SKalle Valo 
36555f859bc0SCarl Huang 	ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n",
36565f859bc0SCarl Huang 		   soc->wmi_ab.preferred_hw_mode);
36576bc9d6f7SJohn Crispin 	if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
3658d5c65159SKalle Valo 		return -EINVAL;
3659d5c65159SKalle Valo 
3660d5c65159SKalle Valo 	return 0;
3661d5c65159SKalle Valo }
3662d5c65159SKalle Valo 
3663d5c65159SKalle Valo static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
3664d5c65159SKalle Valo 					     u16 tag, u16 len,
3665d5c65159SKalle Valo 					     const void *ptr, void *data)
3666d5c65159SKalle Valo {
3667d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3668d5c65159SKalle Valo 
3669d5c65159SKalle Valo 	if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
3670d5c65159SKalle Valo 		return -EPROTO;
3671d5c65159SKalle Valo 
3672d5c65159SKalle Valo 	if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
3673d5c65159SKalle Valo 		return -ENOBUFS;
3674d5c65159SKalle Valo 
36755b90fc76SAnilkumar Kolli 	len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
36765b90fc76SAnilkumar Kolli 	if (!svc_rdy_ext->n_mac_phy_caps) {
36775b90fc76SAnilkumar Kolli 		svc_rdy_ext->mac_phy_caps = kzalloc((svc_rdy_ext->tot_phy_id) * len,
36785b90fc76SAnilkumar Kolli 						    GFP_ATOMIC);
36795b90fc76SAnilkumar Kolli 		if (!svc_rdy_ext->mac_phy_caps)
36805b90fc76SAnilkumar Kolli 			return -ENOMEM;
36815b90fc76SAnilkumar Kolli 	}
36825b90fc76SAnilkumar Kolli 
36835b90fc76SAnilkumar Kolli 	memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
3684d5c65159SKalle Valo 	svc_rdy_ext->n_mac_phy_caps++;
3685d5c65159SKalle Valo 	return 0;
3686d5c65159SKalle Valo }
3687d5c65159SKalle Valo 
3688d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
3689d5c65159SKalle Valo 						 u16 tag, u16 len,
3690d5c65159SKalle Valo 						 const void *ptr, void *data)
3691d5c65159SKalle Valo {
3692d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3693d5c65159SKalle Valo 
3694d5c65159SKalle Valo 	if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
3695d5c65159SKalle Valo 		return -EPROTO;
3696d5c65159SKalle Valo 
3697d5c65159SKalle Valo 	if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
3698d5c65159SKalle Valo 		return -ENOBUFS;
3699d5c65159SKalle Valo 
3700d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps++;
3701d5c65159SKalle Valo 	return 0;
3702d5c65159SKalle Valo }
3703d5c65159SKalle Valo 
3704d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
3705d5c65159SKalle Valo 					   u16 len, const void *ptr, void *data)
3706d5c65159SKalle Valo {
37076bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
3708d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3709d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext reg_cap;
3710d5c65159SKalle Valo 	int ret;
3711d5c65159SKalle Valo 	u32 i;
3712d5c65159SKalle Valo 
3713d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps = 0;
3714d5c65159SKalle Valo 	svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
3715d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
3716d5c65159SKalle Valo 				  ath11k_wmi_tlv_ext_hal_reg_caps_parse,
3717d5c65159SKalle Valo 				  svc_rdy_ext);
3718d5c65159SKalle Valo 	if (ret) {
3719d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
3720d5c65159SKalle Valo 		return ret;
3721d5c65159SKalle Valo 	}
3722d5c65159SKalle Valo 
3723d5c65159SKalle Valo 	for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
3724d5c65159SKalle Valo 		ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
3725d5c65159SKalle Valo 						      svc_rdy_ext->soc_hal_reg_caps,
3726d5c65159SKalle Valo 						      svc_rdy_ext->ext_hal_reg_caps, i,
3727d5c65159SKalle Valo 						      &reg_cap);
3728d5c65159SKalle Valo 		if (ret) {
3729d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract reg cap %d\n", i);
3730d5c65159SKalle Valo 			return ret;
3731d5c65159SKalle Valo 		}
3732d5c65159SKalle Valo 
3733d5c65159SKalle Valo 		memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
3734d5c65159SKalle Valo 		       &reg_cap, sizeof(reg_cap));
3735d5c65159SKalle Valo 	}
3736d5c65159SKalle Valo 	return 0;
3737d5c65159SKalle Valo }
3738d5c65159SKalle Valo 
3739d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
3740d5c65159SKalle Valo 						     u16 len, const void *ptr,
3741d5c65159SKalle Valo 						     void *data)
3742d5c65159SKalle Valo {
37436bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
3744d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3745d5c65159SKalle Valo 	u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
3746d5c65159SKalle Valo 	u32 phy_id_map;
37475f859bc0SCarl Huang 	int pdev_index = 0;
3748d5c65159SKalle Valo 	int ret;
3749d5c65159SKalle Valo 
3750d5c65159SKalle Valo 	svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
3751d5c65159SKalle Valo 	svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
3752d5c65159SKalle Valo 
3753d5c65159SKalle Valo 	soc->num_radios = 0;
3754d5c65159SKalle Valo 	phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
3755d5c65159SKalle Valo 
3756d5c65159SKalle Valo 	while (phy_id_map && soc->num_radios < MAX_RADIOS) {
3757d5c65159SKalle Valo 		ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
3758d5c65159SKalle Valo 							    svc_rdy_ext->hw_caps,
3759d5c65159SKalle Valo 							    svc_rdy_ext->hw_mode_caps,
3760d5c65159SKalle Valo 							    svc_rdy_ext->soc_hal_reg_caps,
3761d5c65159SKalle Valo 							    svc_rdy_ext->mac_phy_caps,
3762d5c65159SKalle Valo 							    hw_mode_id, soc->num_radios,
37635f859bc0SCarl Huang 							    &soc->pdevs[pdev_index]);
3764d5c65159SKalle Valo 		if (ret) {
3765d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
3766d5c65159SKalle Valo 				    soc->num_radios);
3767d5c65159SKalle Valo 			return ret;
3768d5c65159SKalle Valo 		}
3769d5c65159SKalle Valo 
3770d5c65159SKalle Valo 		soc->num_radios++;
3771d5c65159SKalle Valo 
37725f859bc0SCarl Huang 		/* For QCA6390, save mac_phy capability in the same pdev */
37735f859bc0SCarl Huang 		if (soc->hw_params.single_pdev_only)
37745f859bc0SCarl Huang 			pdev_index = 0;
37755f859bc0SCarl Huang 		else
37765f859bc0SCarl Huang 			pdev_index = soc->num_radios;
37775f859bc0SCarl Huang 
3778d5c65159SKalle Valo 		/* TODO: mac_phy_cap prints */
3779d5c65159SKalle Valo 		phy_id_map >>= 1;
3780d5c65159SKalle Valo 	}
37815f859bc0SCarl Huang 
37825f859bc0SCarl Huang 	/* For QCA6390, set num_radios to 1 because host manages
37835f859bc0SCarl Huang 	 * both 2G and 5G radio in one pdev.
37845f859bc0SCarl Huang 	 * Set pdev_id = 0 and 0 means soc level.
37855f859bc0SCarl Huang 	 */
37865f859bc0SCarl Huang 	if (soc->hw_params.single_pdev_only) {
37875f859bc0SCarl Huang 		soc->num_radios = 1;
37885f859bc0SCarl Huang 		soc->pdevs[0].pdev_id = 0;
37895f859bc0SCarl Huang 	}
37905f859bc0SCarl Huang 
3791d5c65159SKalle Valo 	return 0;
3792d5c65159SKalle Valo }
3793d5c65159SKalle Valo 
3794bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc,
3795bd647855SKarthikeyan Periyasamy 					      u16 tag, u16 len,
3796bd647855SKarthikeyan Periyasamy 					      const void *ptr, void *data)
3797bd647855SKarthikeyan Periyasamy {
3798bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse *parse = data;
3799bd647855SKarthikeyan Periyasamy 
3800bd647855SKarthikeyan Periyasamy 	if (tag != WMI_TAG_DMA_RING_CAPABILITIES)
3801bd647855SKarthikeyan Periyasamy 		return -EPROTO;
3802bd647855SKarthikeyan Periyasamy 
3803bd647855SKarthikeyan Periyasamy 	parse->n_dma_ring_caps++;
3804bd647855SKarthikeyan Periyasamy 	return 0;
3805bd647855SKarthikeyan Periyasamy }
3806bd647855SKarthikeyan Periyasamy 
3807bd647855SKarthikeyan Periyasamy static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab,
3808bd647855SKarthikeyan Periyasamy 					u32 num_cap)
3809bd647855SKarthikeyan Periyasamy {
3810bd647855SKarthikeyan Periyasamy 	size_t sz;
3811bd647855SKarthikeyan Periyasamy 	void *ptr;
3812bd647855SKarthikeyan Periyasamy 
3813bd647855SKarthikeyan Periyasamy 	sz = num_cap * sizeof(struct ath11k_dbring_cap);
3814bd647855SKarthikeyan Periyasamy 	ptr = kzalloc(sz, GFP_ATOMIC);
3815bd647855SKarthikeyan Periyasamy 	if (!ptr)
3816bd647855SKarthikeyan Periyasamy 		return -ENOMEM;
3817bd647855SKarthikeyan Periyasamy 
3818bd647855SKarthikeyan Periyasamy 	ab->db_caps = ptr;
3819bd647855SKarthikeyan Periyasamy 	ab->num_db_cap = num_cap;
3820bd647855SKarthikeyan Periyasamy 
3821bd647855SKarthikeyan Periyasamy 	return 0;
3822bd647855SKarthikeyan Periyasamy }
3823bd647855SKarthikeyan Periyasamy 
3824bd647855SKarthikeyan Periyasamy static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
3825bd647855SKarthikeyan Periyasamy {
3826bd647855SKarthikeyan Periyasamy 	kfree(ab->db_caps);
3827bd647855SKarthikeyan Periyasamy 	ab->db_caps = NULL;
3828bd647855SKarthikeyan Periyasamy }
3829bd647855SKarthikeyan Periyasamy 
3830bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab,
3831bd647855SKarthikeyan Periyasamy 					u16 len, const void *ptr, void *data)
3832bd647855SKarthikeyan Periyasamy {
3833bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data;
3834bd647855SKarthikeyan Periyasamy 	struct wmi_dma_ring_capabilities *dma_caps;
3835bd647855SKarthikeyan Periyasamy 	struct ath11k_dbring_cap *dir_buff_caps;
3836bd647855SKarthikeyan Periyasamy 	int ret;
3837bd647855SKarthikeyan Periyasamy 	u32 i;
3838bd647855SKarthikeyan Periyasamy 
3839bd647855SKarthikeyan Periyasamy 	dma_caps_parse->n_dma_ring_caps = 0;
3840bd647855SKarthikeyan Periyasamy 	dma_caps = (struct wmi_dma_ring_capabilities *)ptr;
3841bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, ptr, len,
3842bd647855SKarthikeyan Periyasamy 				  ath11k_wmi_tlv_dma_ring_caps_parse,
3843bd647855SKarthikeyan Periyasamy 				  dma_caps_parse);
3844bd647855SKarthikeyan Periyasamy 	if (ret) {
3845bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret);
3846bd647855SKarthikeyan Periyasamy 		return ret;
3847bd647855SKarthikeyan Periyasamy 	}
3848bd647855SKarthikeyan Periyasamy 
3849bd647855SKarthikeyan Periyasamy 	if (!dma_caps_parse->n_dma_ring_caps)
3850bd647855SKarthikeyan Periyasamy 		return 0;
3851bd647855SKarthikeyan Periyasamy 
3852bd647855SKarthikeyan Periyasamy 	if (ab->num_db_cap) {
3853bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n");
3854bd647855SKarthikeyan Periyasamy 		return 0;
3855bd647855SKarthikeyan Periyasamy 	}
3856bd647855SKarthikeyan Periyasamy 
3857bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps);
3858bd647855SKarthikeyan Periyasamy 	if (ret)
3859bd647855SKarthikeyan Periyasamy 		return ret;
3860bd647855SKarthikeyan Periyasamy 
3861bd647855SKarthikeyan Periyasamy 	dir_buff_caps = ab->db_caps;
3862bd647855SKarthikeyan Periyasamy 	for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) {
3863bd647855SKarthikeyan Periyasamy 		if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) {
3864bd647855SKarthikeyan Periyasamy 			ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id);
3865bd647855SKarthikeyan Periyasamy 			ret = -EINVAL;
3866bd647855SKarthikeyan Periyasamy 			goto free_dir_buff;
3867bd647855SKarthikeyan Periyasamy 		}
3868bd647855SKarthikeyan Periyasamy 
3869bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].id = dma_caps[i].module_id;
3870bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id);
3871bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_elem = dma_caps[i].min_elem;
3872bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz;
3873bd647855SKarthikeyan Periyasamy 		dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align;
3874bd647855SKarthikeyan Periyasamy 	}
3875bd647855SKarthikeyan Periyasamy 
3876bd647855SKarthikeyan Periyasamy 	return 0;
3877bd647855SKarthikeyan Periyasamy 
3878bd647855SKarthikeyan Periyasamy free_dir_buff:
3879bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
3880bd647855SKarthikeyan Periyasamy 	return ret;
3881bd647855SKarthikeyan Periyasamy }
3882bd647855SKarthikeyan Periyasamy 
3883d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
3884d5c65159SKalle Valo 					    u16 tag, u16 len,
3885d5c65159SKalle Valo 					    const void *ptr, void *data)
3886d5c65159SKalle Valo {
38876bc9d6f7SJohn Crispin 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
3888d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3889d5c65159SKalle Valo 	int ret;
3890d5c65159SKalle Valo 
3891d5c65159SKalle Valo 	switch (tag) {
3892d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EXT_EVENT:
3893d5c65159SKalle Valo 		ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
3894d5c65159SKalle Valo 						&svc_rdy_ext->param);
3895d5c65159SKalle Valo 		if (ret) {
3896d5c65159SKalle Valo 			ath11k_warn(ab, "unable to extract ext params\n");
3897d5c65159SKalle Valo 			return ret;
3898d5c65159SKalle Valo 		}
3899d5c65159SKalle Valo 		break;
3900d5c65159SKalle Valo 
3901d5c65159SKalle Valo 	case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
3902d5c65159SKalle Valo 		svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
3903d5c65159SKalle Valo 		svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
3904d5c65159SKalle Valo 		break;
3905d5c65159SKalle Valo 
3906d5c65159SKalle Valo 	case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
3907d5c65159SKalle Valo 		ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
3908d5c65159SKalle Valo 								svc_rdy_ext);
3909d5c65159SKalle Valo 		if (ret)
3910d5c65159SKalle Valo 			return ret;
3911d5c65159SKalle Valo 		break;
3912d5c65159SKalle Valo 
3913d5c65159SKalle Valo 	case WMI_TAG_ARRAY_STRUCT:
3914d5c65159SKalle Valo 		if (!svc_rdy_ext->hw_mode_done) {
3915d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
3916d5c65159SKalle Valo 							  svc_rdy_ext);
3917d5c65159SKalle Valo 			if (ret)
3918d5c65159SKalle Valo 				return ret;
3919d5c65159SKalle Valo 
3920d5c65159SKalle Valo 			svc_rdy_ext->hw_mode_done = true;
3921d5c65159SKalle Valo 		} else if (!svc_rdy_ext->mac_phy_done) {
3922d5c65159SKalle Valo 			svc_rdy_ext->n_mac_phy_caps = 0;
3923d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
3924d5c65159SKalle Valo 						  ath11k_wmi_tlv_mac_phy_caps_parse,
3925d5c65159SKalle Valo 						  svc_rdy_ext);
3926d5c65159SKalle Valo 			if (ret) {
3927d5c65159SKalle Valo 				ath11k_warn(ab, "failed to parse tlv %d\n", ret);
3928d5c65159SKalle Valo 				return ret;
3929d5c65159SKalle Valo 			}
3930d5c65159SKalle Valo 
3931d5c65159SKalle Valo 			svc_rdy_ext->mac_phy_done = true;
3932d5c65159SKalle Valo 		} else if (!svc_rdy_ext->ext_hal_reg_done) {
3933d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
3934d5c65159SKalle Valo 							      svc_rdy_ext);
3935d5c65159SKalle Valo 			if (ret)
3936d5c65159SKalle Valo 				return ret;
3937d5c65159SKalle Valo 
3938d5c65159SKalle Valo 			svc_rdy_ext->ext_hal_reg_done = true;
3939bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) {
3940bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->mac_phy_chainmask_combo_done = true;
3941bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) {
3942bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->mac_phy_chainmask_cap_done = true;
3943bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->oem_dma_ring_cap_done) {
3944bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->oem_dma_ring_cap_done = true;
3945bd647855SKarthikeyan Periyasamy 		} else if (!svc_rdy_ext->dma_ring_cap_done) {
3946bd647855SKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
3947bd647855SKarthikeyan Periyasamy 							   &svc_rdy_ext->dma_caps_parse);
3948bd647855SKarthikeyan Periyasamy 			if (ret)
3949bd647855SKarthikeyan Periyasamy 				return ret;
3950bd647855SKarthikeyan Periyasamy 
3951bd647855SKarthikeyan Periyasamy 			svc_rdy_ext->dma_ring_cap_done = true;
3952d5c65159SKalle Valo 		}
3953d5c65159SKalle Valo 		break;
3954d5c65159SKalle Valo 
3955d5c65159SKalle Valo 	default:
3956d5c65159SKalle Valo 		break;
3957d5c65159SKalle Valo 	}
3958d5c65159SKalle Valo 	return 0;
3959d5c65159SKalle Valo }
3960d5c65159SKalle Valo 
3961d5c65159SKalle Valo static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
3962d5c65159SKalle Valo 					  struct sk_buff *skb)
3963d5c65159SKalle Valo {
3964d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
3965d5c65159SKalle Valo 	int ret;
3966d5c65159SKalle Valo 
3967d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
3968d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_ext_parse,
3969d5c65159SKalle Valo 				  &svc_rdy_ext);
3970d5c65159SKalle Valo 	if (ret) {
3971d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
3972bd647855SKarthikeyan Periyasamy 		goto err;
3973d5c65159SKalle Valo 	}
3974d5c65159SKalle Valo 
3975bd647855SKarthikeyan Periyasamy 	if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map))
3976bd647855SKarthikeyan Periyasamy 		complete(&ab->wmi_ab.service_ready);
3977bd647855SKarthikeyan Periyasamy 
39785b90fc76SAnilkumar Kolli 	kfree(svc_rdy_ext.mac_phy_caps);
3979d5c65159SKalle Valo 	return 0;
3980bd647855SKarthikeyan Periyasamy 
3981bd647855SKarthikeyan Periyasamy err:
3982bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
3983bd647855SKarthikeyan Periyasamy 	return ret;
3984bd647855SKarthikeyan Periyasamy }
3985bd647855SKarthikeyan Periyasamy 
3986bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab,
3987bd647855SKarthikeyan Periyasamy 					     u16 tag, u16 len,
3988bd647855SKarthikeyan Periyasamy 					     const void *ptr, void *data)
3989bd647855SKarthikeyan Periyasamy {
3990bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_svc_rdy_ext2_parse *parse = data;
3991bd647855SKarthikeyan Periyasamy 	int ret;
3992bd647855SKarthikeyan Periyasamy 
3993bd647855SKarthikeyan Periyasamy 	switch (tag) {
3994bd647855SKarthikeyan Periyasamy 	case WMI_TAG_ARRAY_STRUCT:
3995bd647855SKarthikeyan Periyasamy 		if (!parse->dma_ring_cap_done) {
3996bd647855SKarthikeyan Periyasamy 			ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
3997bd647855SKarthikeyan Periyasamy 							   &parse->dma_caps_parse);
3998bd647855SKarthikeyan Periyasamy 			if (ret)
3999bd647855SKarthikeyan Periyasamy 				return ret;
4000bd647855SKarthikeyan Periyasamy 
4001bd647855SKarthikeyan Periyasamy 			parse->dma_ring_cap_done = true;
4002bd647855SKarthikeyan Periyasamy 		}
4003bd647855SKarthikeyan Periyasamy 		break;
4004bd647855SKarthikeyan Periyasamy 	default:
4005bd647855SKarthikeyan Periyasamy 		break;
4006bd647855SKarthikeyan Periyasamy 	}
4007bd647855SKarthikeyan Periyasamy 
4008bd647855SKarthikeyan Periyasamy 	return 0;
4009bd647855SKarthikeyan Periyasamy }
4010bd647855SKarthikeyan Periyasamy 
4011bd647855SKarthikeyan Periyasamy static int ath11k_service_ready_ext2_event(struct ath11k_base *ab,
4012bd647855SKarthikeyan Periyasamy 					   struct sk_buff *skb)
4013bd647855SKarthikeyan Periyasamy {
4014bd647855SKarthikeyan Periyasamy 	struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { };
4015bd647855SKarthikeyan Periyasamy 	int ret;
4016bd647855SKarthikeyan Periyasamy 
4017bd647855SKarthikeyan Periyasamy 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4018bd647855SKarthikeyan Periyasamy 				  ath11k_wmi_tlv_svc_rdy_ext2_parse,
4019bd647855SKarthikeyan Periyasamy 				  &svc_rdy_ext2);
4020bd647855SKarthikeyan Periyasamy 	if (ret) {
4021bd647855SKarthikeyan Periyasamy 		ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret);
4022bd647855SKarthikeyan Periyasamy 		goto err;
4023bd647855SKarthikeyan Periyasamy 	}
4024bd647855SKarthikeyan Periyasamy 
4025bd647855SKarthikeyan Periyasamy 	complete(&ab->wmi_ab.service_ready);
4026bd647855SKarthikeyan Periyasamy 
4027bd647855SKarthikeyan Periyasamy 	return 0;
4028bd647855SKarthikeyan Periyasamy 
4029bd647855SKarthikeyan Periyasamy err:
4030bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
4031bd647855SKarthikeyan Periyasamy 	return ret;
4032d5c65159SKalle Valo }
4033d5c65159SKalle Valo 
4034d5c65159SKalle Valo static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
4035d5c65159SKalle Valo 					   struct wmi_vdev_start_resp_event *vdev_rsp)
4036d5c65159SKalle Valo {
4037d5c65159SKalle Valo 	const void **tb;
4038d5c65159SKalle Valo 	const struct wmi_vdev_start_resp_event *ev;
4039d5c65159SKalle Valo 	int ret;
4040d5c65159SKalle Valo 
4041d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4042d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4043d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4044d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4045d5c65159SKalle Valo 		return ret;
4046d5c65159SKalle Valo 	}
4047d5c65159SKalle Valo 
4048d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
4049d5c65159SKalle Valo 	if (!ev) {
4050d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev start resp ev");
4051d5c65159SKalle Valo 		kfree(tb);
4052d5c65159SKalle Valo 		return -EPROTO;
4053d5c65159SKalle Valo 	}
4054d5c65159SKalle Valo 
4055d5c65159SKalle Valo 	memset(vdev_rsp, 0, sizeof(*vdev_rsp));
4056d5c65159SKalle Valo 
4057d5c65159SKalle Valo 	vdev_rsp->vdev_id = ev->vdev_id;
4058d5c65159SKalle Valo 	vdev_rsp->requestor_id = ev->requestor_id;
4059d5c65159SKalle Valo 	vdev_rsp->resp_type = ev->resp_type;
4060d5c65159SKalle Valo 	vdev_rsp->status = ev->status;
4061d5c65159SKalle Valo 	vdev_rsp->chain_mask = ev->chain_mask;
4062d5c65159SKalle Valo 	vdev_rsp->smps_mode = ev->smps_mode;
4063d5c65159SKalle Valo 	vdev_rsp->mac_id = ev->mac_id;
4064d5c65159SKalle Valo 	vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
4065d5c65159SKalle Valo 	vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
4066d5c65159SKalle Valo 
4067d5c65159SKalle Valo 	kfree(tb);
4068d5c65159SKalle Valo 	return 0;
4069d5c65159SKalle Valo }
4070d5c65159SKalle Valo 
4071d5c65159SKalle Valo static struct cur_reg_rule
4072d5c65159SKalle Valo *create_reg_rules_from_wmi(u32 num_reg_rules,
4073d5c65159SKalle Valo 			   struct wmi_regulatory_rule_struct *wmi_reg_rule)
4074d5c65159SKalle Valo {
4075d5c65159SKalle Valo 	struct cur_reg_rule *reg_rule_ptr;
4076d5c65159SKalle Valo 	u32 count;
4077d5c65159SKalle Valo 
4078d5c65159SKalle Valo 	reg_rule_ptr =  kzalloc((num_reg_rules * sizeof(*reg_rule_ptr)),
4079d5c65159SKalle Valo 				GFP_ATOMIC);
4080d5c65159SKalle Valo 
4081d5c65159SKalle Valo 	if (!reg_rule_ptr)
4082d5c65159SKalle Valo 		return NULL;
4083d5c65159SKalle Valo 
4084d5c65159SKalle Valo 	for (count = 0; count < num_reg_rules; count++) {
4085d5c65159SKalle Valo 		reg_rule_ptr[count].start_freq =
4086d5c65159SKalle Valo 			FIELD_GET(REG_RULE_START_FREQ,
4087d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
4088d5c65159SKalle Valo 		reg_rule_ptr[count].end_freq =
4089d5c65159SKalle Valo 			FIELD_GET(REG_RULE_END_FREQ,
4090d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
4091d5c65159SKalle Valo 		reg_rule_ptr[count].max_bw =
4092d5c65159SKalle Valo 			FIELD_GET(REG_RULE_MAX_BW,
4093d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4094d5c65159SKalle Valo 		reg_rule_ptr[count].reg_power =
4095d5c65159SKalle Valo 			FIELD_GET(REG_RULE_REG_PWR,
4096d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4097d5c65159SKalle Valo 		reg_rule_ptr[count].ant_gain =
4098d5c65159SKalle Valo 			FIELD_GET(REG_RULE_ANT_GAIN,
4099d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
4100d5c65159SKalle Valo 		reg_rule_ptr[count].flags =
4101d5c65159SKalle Valo 			FIELD_GET(REG_RULE_FLAGS,
4102d5c65159SKalle Valo 				  wmi_reg_rule[count].flag_info);
4103d5c65159SKalle Valo 	}
4104d5c65159SKalle Valo 
4105d5c65159SKalle Valo 	return reg_rule_ptr;
4106d5c65159SKalle Valo }
4107d5c65159SKalle Valo 
4108d5c65159SKalle Valo static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
4109d5c65159SKalle Valo 					       struct sk_buff *skb,
4110d5c65159SKalle Valo 					       struct cur_regulatory_info *reg_info)
4111d5c65159SKalle Valo {
4112d5c65159SKalle Valo 	const void **tb;
4113d5c65159SKalle Valo 	const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
4114d5c65159SKalle Valo 	struct wmi_regulatory_rule_struct *wmi_reg_rule;
4115d5c65159SKalle Valo 	u32 num_2g_reg_rules, num_5g_reg_rules;
4116d5c65159SKalle Valo 	int ret;
4117d5c65159SKalle Valo 
4118d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
4119d5c65159SKalle Valo 
4120d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4121d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4122d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4123d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4124d5c65159SKalle Valo 		return ret;
4125d5c65159SKalle Valo 	}
4126d5c65159SKalle Valo 
4127d5c65159SKalle Valo 	chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
4128d5c65159SKalle Valo 	if (!chan_list_event_hdr) {
4129d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
4130d5c65159SKalle Valo 		kfree(tb);
4131d5c65159SKalle Valo 		return -EPROTO;
4132d5c65159SKalle Valo 	}
4133d5c65159SKalle Valo 
4134d5c65159SKalle Valo 	reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules;
4135d5c65159SKalle Valo 	reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules;
4136d5c65159SKalle Valo 
4137d5c65159SKalle Valo 	if (!(reg_info->num_2g_reg_rules + reg_info->num_5g_reg_rules)) {
4138d5c65159SKalle Valo 		ath11k_warn(ab, "No regulatory rules available in the event info\n");
4139d5c65159SKalle Valo 		kfree(tb);
4140d5c65159SKalle Valo 		return -EINVAL;
4141d5c65159SKalle Valo 	}
4142d5c65159SKalle Valo 
4143d5c65159SKalle Valo 	memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
4144d5c65159SKalle Valo 	       REG_ALPHA2_LEN);
4145d5c65159SKalle Valo 	reg_info->dfs_region = chan_list_event_hdr->dfs_region;
4146d5c65159SKalle Valo 	reg_info->phybitmap = chan_list_event_hdr->phybitmap;
4147d5c65159SKalle Valo 	reg_info->num_phy = chan_list_event_hdr->num_phy;
4148d5c65159SKalle Valo 	reg_info->phy_id = chan_list_event_hdr->phy_id;
4149d5c65159SKalle Valo 	reg_info->ctry_code = chan_list_event_hdr->country_id;
4150d5c65159SKalle Valo 	reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
4151d5c65159SKalle Valo 	if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS)
4152d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_PASS;
4153d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND)
4154d5c65159SKalle Valo 		reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND;
4155d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND)
4156d5c65159SKalle Valo 		reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND;
4157d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED)
4158d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED;
4159d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY)
4160d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY;
4161d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL)
4162d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_FAIL;
4163d5c65159SKalle Valo 
4164d5c65159SKalle Valo 	reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g;
4165d5c65159SKalle Valo 	reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g;
4166d5c65159SKalle Valo 	reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g;
4167d5c65159SKalle Valo 	reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g;
4168d5c65159SKalle Valo 
4169d5c65159SKalle Valo 	num_2g_reg_rules = reg_info->num_2g_reg_rules;
4170d5c65159SKalle Valo 	num_5g_reg_rules = reg_info->num_5g_reg_rules;
4171d5c65159SKalle Valo 
4172d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
4173d5c65159SKalle Valo 		   "%s:cc %s dsf %d BW: min_2g %d max_2g %d min_5g %d max_5g %d",
4174d5c65159SKalle Valo 		   __func__, reg_info->alpha2, reg_info->dfs_region,
4175d5c65159SKalle Valo 		   reg_info->min_bw_2g, reg_info->max_bw_2g,
4176d5c65159SKalle Valo 		   reg_info->min_bw_5g, reg_info->max_bw_5g);
4177d5c65159SKalle Valo 
4178d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
4179d5c65159SKalle Valo 		   "%s: num_2g_reg_rules %d num_5g_reg_rules %d", __func__,
4180d5c65159SKalle Valo 		   num_2g_reg_rules, num_5g_reg_rules);
4181d5c65159SKalle Valo 
4182d5c65159SKalle Valo 	wmi_reg_rule =
4183d5c65159SKalle Valo 		(struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
4184d5c65159SKalle Valo 						+ sizeof(*chan_list_event_hdr)
4185d5c65159SKalle Valo 						+ sizeof(struct wmi_tlv));
4186d5c65159SKalle Valo 
4187d5c65159SKalle Valo 	if (num_2g_reg_rules) {
4188d5c65159SKalle Valo 		reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules,
4189d5c65159SKalle Valo 								       wmi_reg_rule);
4190d5c65159SKalle Valo 		if (!reg_info->reg_rules_2g_ptr) {
4191d5c65159SKalle Valo 			kfree(tb);
4192d5c65159SKalle Valo 			ath11k_warn(ab, "Unable to Allocate memory for 2g rules\n");
4193d5c65159SKalle Valo 			return -ENOMEM;
4194d5c65159SKalle Valo 		}
4195d5c65159SKalle Valo 	}
4196d5c65159SKalle Valo 
4197d5c65159SKalle Valo 	if (num_5g_reg_rules) {
4198d5c65159SKalle Valo 		wmi_reg_rule += num_2g_reg_rules;
4199d5c65159SKalle Valo 		reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules,
4200d5c65159SKalle Valo 								       wmi_reg_rule);
4201d5c65159SKalle Valo 		if (!reg_info->reg_rules_5g_ptr) {
4202d5c65159SKalle Valo 			kfree(tb);
4203d5c65159SKalle Valo 			ath11k_warn(ab, "Unable to Allocate memory for 5g rules\n");
4204d5c65159SKalle Valo 			return -ENOMEM;
4205d5c65159SKalle Valo 		}
4206d5c65159SKalle Valo 	}
4207d5c65159SKalle Valo 
4208d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
4209d5c65159SKalle Valo 
4210d5c65159SKalle Valo 	kfree(tb);
4211d5c65159SKalle Valo 	return 0;
4212d5c65159SKalle Valo }
4213d5c65159SKalle Valo 
4214d5c65159SKalle Valo static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
4215d5c65159SKalle Valo 					struct wmi_peer_delete_resp_event *peer_del_resp)
4216d5c65159SKalle Valo {
4217d5c65159SKalle Valo 	const void **tb;
4218d5c65159SKalle Valo 	const struct wmi_peer_delete_resp_event *ev;
4219d5c65159SKalle Valo 	int ret;
4220d5c65159SKalle Valo 
4221d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4222d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4223d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4224d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4225d5c65159SKalle Valo 		return ret;
4226d5c65159SKalle Valo 	}
4227d5c65159SKalle Valo 
4228d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
4229d5c65159SKalle Valo 	if (!ev) {
4230d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer delete resp ev");
4231d5c65159SKalle Valo 		kfree(tb);
4232d5c65159SKalle Valo 		return -EPROTO;
4233d5c65159SKalle Valo 	}
4234d5c65159SKalle Valo 
4235d5c65159SKalle Valo 	memset(peer_del_resp, 0, sizeof(*peer_del_resp));
4236d5c65159SKalle Valo 
4237d5c65159SKalle Valo 	peer_del_resp->vdev_id = ev->vdev_id;
4238d5c65159SKalle Valo 	ether_addr_copy(peer_del_resp->peer_macaddr.addr,
4239d5c65159SKalle Valo 			ev->peer_macaddr.addr);
4240d5c65159SKalle Valo 
4241d5c65159SKalle Valo 	kfree(tb);
4242d5c65159SKalle Valo 	return 0;
4243d5c65159SKalle Valo }
4244d5c65159SKalle Valo 
4245d5c65159SKalle Valo static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
4246d5c65159SKalle Valo 					u32 len, u32 *vdev_id,
4247d5c65159SKalle Valo 					u32 *tx_status)
4248d5c65159SKalle Valo {
4249d5c65159SKalle Valo 	const void **tb;
4250d5c65159SKalle Valo 	const struct wmi_bcn_tx_status_event *ev;
4251d5c65159SKalle Valo 	int ret;
4252d5c65159SKalle Valo 
4253d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
4254d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4255d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4256d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4257d5c65159SKalle Valo 		return ret;
4258d5c65159SKalle Valo 	}
4259d5c65159SKalle Valo 
4260d5c65159SKalle Valo 	ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
4261d5c65159SKalle Valo 	if (!ev) {
4262d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch bcn tx status ev");
4263d5c65159SKalle Valo 		kfree(tb);
4264d5c65159SKalle Valo 		return -EPROTO;
4265d5c65159SKalle Valo 	}
4266d5c65159SKalle Valo 
4267d5c65159SKalle Valo 	*vdev_id   = ev->vdev_id;
4268d5c65159SKalle Valo 	*tx_status = ev->tx_status;
4269d5c65159SKalle Valo 
4270d5c65159SKalle Valo 	kfree(tb);
4271d5c65159SKalle Valo 	return 0;
4272d5c65159SKalle Valo }
4273d5c65159SKalle Valo 
4274d5c65159SKalle Valo static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
4275d5c65159SKalle Valo 					      u32 *vdev_id)
4276d5c65159SKalle Valo {
4277d5c65159SKalle Valo 	const void **tb;
4278d5c65159SKalle Valo 	const struct wmi_vdev_stopped_event *ev;
4279d5c65159SKalle Valo 	int ret;
4280d5c65159SKalle Valo 
4281d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4282d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4283d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4284d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4285d5c65159SKalle Valo 		return ret;
4286d5c65159SKalle Valo 	}
4287d5c65159SKalle Valo 
4288d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
4289d5c65159SKalle Valo 	if (!ev) {
4290d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev stop ev");
4291d5c65159SKalle Valo 		kfree(tb);
4292d5c65159SKalle Valo 		return -EPROTO;
4293d5c65159SKalle Valo 	}
4294d5c65159SKalle Valo 
4295d5c65159SKalle Valo 	*vdev_id =  ev->vdev_id;
4296d5c65159SKalle Valo 
4297d5c65159SKalle Valo 	kfree(tb);
4298d5c65159SKalle Valo 	return 0;
4299d5c65159SKalle Valo }
4300d5c65159SKalle Valo 
4301d5c65159SKalle Valo static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
4302d5c65159SKalle Valo 					  struct sk_buff *skb,
4303d5c65159SKalle Valo 					  struct mgmt_rx_event_params *hdr)
4304d5c65159SKalle Valo {
4305d5c65159SKalle Valo 	const void **tb;
4306d5c65159SKalle Valo 	const struct wmi_mgmt_rx_hdr *ev;
4307d5c65159SKalle Valo 	const u8 *frame;
4308d5c65159SKalle Valo 	int ret;
4309d5c65159SKalle Valo 
4310d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4311d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4312d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4313d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4314d5c65159SKalle Valo 		return ret;
4315d5c65159SKalle Valo 	}
4316d5c65159SKalle Valo 
4317d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_RX_HDR];
4318d5c65159SKalle Valo 	frame = tb[WMI_TAG_ARRAY_BYTE];
4319d5c65159SKalle Valo 
4320d5c65159SKalle Valo 	if (!ev || !frame) {
4321d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt rx hdr");
4322d5c65159SKalle Valo 		kfree(tb);
4323d5c65159SKalle Valo 		return -EPROTO;
4324d5c65159SKalle Valo 	}
4325d5c65159SKalle Valo 
4326d5c65159SKalle Valo 	hdr->pdev_id =  ev->pdev_id;
43275dcf42f8SPradeep Kumar Chitrapu 	hdr->chan_freq = ev->chan_freq;
4328d5c65159SKalle Valo 	hdr->channel =  ev->channel;
4329d5c65159SKalle Valo 	hdr->snr =  ev->snr;
4330d5c65159SKalle Valo 	hdr->rate =  ev->rate;
4331d5c65159SKalle Valo 	hdr->phy_mode =  ev->phy_mode;
4332d5c65159SKalle Valo 	hdr->buf_len =  ev->buf_len;
4333d5c65159SKalle Valo 	hdr->status =  ev->status;
4334d5c65159SKalle Valo 	hdr->flags =  ev->flags;
4335d5c65159SKalle Valo 	hdr->rssi =  ev->rssi;
4336d5c65159SKalle Valo 	hdr->tsf_delta =  ev->tsf_delta;
4337d5c65159SKalle Valo 	memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
4338d5c65159SKalle Valo 
4339d5c65159SKalle Valo 	if (skb->len < (frame - skb->data) + hdr->buf_len) {
4340d5c65159SKalle Valo 		ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
4341d5c65159SKalle Valo 		kfree(tb);
4342d5c65159SKalle Valo 		return -EPROTO;
4343d5c65159SKalle Valo 	}
4344d5c65159SKalle Valo 
4345d5c65159SKalle Valo 	/* shift the sk_buff to point to `frame` */
4346d5c65159SKalle Valo 	skb_trim(skb, 0);
4347d5c65159SKalle Valo 	skb_put(skb, frame - skb->data);
4348d5c65159SKalle Valo 	skb_pull(skb, frame - skb->data);
4349d5c65159SKalle Valo 	skb_put(skb, hdr->buf_len);
4350d5c65159SKalle Valo 
4351d5c65159SKalle Valo 	ath11k_ce_byte_swap(skb->data, hdr->buf_len);
4352d5c65159SKalle Valo 
4353d5c65159SKalle Valo 	kfree(tb);
4354d5c65159SKalle Valo 	return 0;
4355d5c65159SKalle Valo }
4356d5c65159SKalle Valo 
4357d5c65159SKalle Valo static int wmi_process_mgmt_tx_comp(struct ath11k *ar, u32 desc_id,
4358d5c65159SKalle Valo 				    u32 status)
4359d5c65159SKalle Valo {
4360d5c65159SKalle Valo 	struct sk_buff *msdu;
4361d5c65159SKalle Valo 	struct ieee80211_tx_info *info;
4362d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb;
4363d5c65159SKalle Valo 
4364d5c65159SKalle Valo 	spin_lock_bh(&ar->txmgmt_idr_lock);
4365d5c65159SKalle Valo 	msdu = idr_find(&ar->txmgmt_idr, desc_id);
4366d5c65159SKalle Valo 
4367d5c65159SKalle Valo 	if (!msdu) {
4368d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
4369d5c65159SKalle Valo 			    desc_id);
4370d5c65159SKalle Valo 		spin_unlock_bh(&ar->txmgmt_idr_lock);
4371d5c65159SKalle Valo 		return -ENOENT;
4372d5c65159SKalle Valo 	}
4373d5c65159SKalle Valo 
4374d5c65159SKalle Valo 	idr_remove(&ar->txmgmt_idr, desc_id);
4375d5c65159SKalle Valo 	spin_unlock_bh(&ar->txmgmt_idr_lock);
4376d5c65159SKalle Valo 
4377d5c65159SKalle Valo 	skb_cb = ATH11K_SKB_CB(msdu);
4378d5c65159SKalle Valo 	dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
4379d5c65159SKalle Valo 
4380d5c65159SKalle Valo 	info = IEEE80211_SKB_CB(msdu);
4381d5c65159SKalle Valo 	if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) && !status)
4382d5c65159SKalle Valo 		info->flags |= IEEE80211_TX_STAT_ACK;
4383d5c65159SKalle Valo 
4384d5c65159SKalle Valo 	ieee80211_tx_status_irqsafe(ar->hw, msdu);
4385d5c65159SKalle Valo 
4386800113ffSSriram R 	/* WARN when we received this event without doing any mgmt tx */
4387800113ffSSriram R 	if (atomic_dec_if_positive(&ar->num_pending_mgmt_tx) < 0)
4388800113ffSSriram R 		WARN_ON_ONCE(1);
4389d5c65159SKalle Valo 
4390d5c65159SKalle Valo 	return 0;
4391d5c65159SKalle Valo }
4392d5c65159SKalle Valo 
4393d5c65159SKalle Valo static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
4394d5c65159SKalle Valo 					       struct sk_buff *skb,
4395d5c65159SKalle Valo 					       struct wmi_mgmt_tx_compl_event *param)
4396d5c65159SKalle Valo {
4397d5c65159SKalle Valo 	const void **tb;
4398d5c65159SKalle Valo 	const struct wmi_mgmt_tx_compl_event *ev;
4399d5c65159SKalle Valo 	int ret;
4400d5c65159SKalle Valo 
4401d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4402d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4403d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4404d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4405d5c65159SKalle Valo 		return ret;
4406d5c65159SKalle Valo 	}
4407d5c65159SKalle Valo 
4408d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
4409d5c65159SKalle Valo 	if (!ev) {
4410d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
4411d5c65159SKalle Valo 		kfree(tb);
4412d5c65159SKalle Valo 		return -EPROTO;
4413d5c65159SKalle Valo 	}
4414d5c65159SKalle Valo 
4415d5c65159SKalle Valo 	param->pdev_id = ev->pdev_id;
4416d5c65159SKalle Valo 	param->desc_id = ev->desc_id;
4417d5c65159SKalle Valo 	param->status = ev->status;
4418d5c65159SKalle Valo 
4419d5c65159SKalle Valo 	kfree(tb);
4420d5c65159SKalle Valo 	return 0;
4421d5c65159SKalle Valo }
4422d5c65159SKalle Valo 
4423d5c65159SKalle Valo static void ath11k_wmi_event_scan_started(struct ath11k *ar)
4424d5c65159SKalle Valo {
4425d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
4426d5c65159SKalle Valo 
4427d5c65159SKalle Valo 	switch (ar->scan.state) {
4428d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
4429d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
4430d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
4431d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
4432d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
4433d5c65159SKalle Valo 			    ar->scan.state);
4434d5c65159SKalle Valo 		break;
4435d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
4436d5c65159SKalle Valo 		ar->scan.state = ATH11K_SCAN_RUNNING;
4437d5c65159SKalle Valo 		complete(&ar->scan.started);
4438d5c65159SKalle Valo 		break;
4439d5c65159SKalle Valo 	}
4440d5c65159SKalle Valo }
4441d5c65159SKalle Valo 
4442d5c65159SKalle Valo static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
4443d5c65159SKalle Valo {
4444d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
4445d5c65159SKalle Valo 
4446d5c65159SKalle Valo 	switch (ar->scan.state) {
4447d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
4448d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
4449d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
4450d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
4451d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
4452d5c65159SKalle Valo 			    ar->scan.state);
4453d5c65159SKalle Valo 		break;
4454d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
4455d5c65159SKalle Valo 		complete(&ar->scan.started);
4456d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
4457d5c65159SKalle Valo 		break;
4458d5c65159SKalle Valo 	}
4459d5c65159SKalle Valo }
4460d5c65159SKalle Valo 
4461d5c65159SKalle Valo static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
4462d5c65159SKalle Valo {
4463d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
4464d5c65159SKalle Valo 
4465d5c65159SKalle Valo 	switch (ar->scan.state) {
4466d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
4467d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
4468d5c65159SKalle Valo 		/* One suspected reason scan can be completed while starting is
4469d5c65159SKalle Valo 		 * if firmware fails to deliver all scan events to the host,
4470d5c65159SKalle Valo 		 * e.g. when transport pipe is full. This has been observed
4471d5c65159SKalle Valo 		 * with spectral scan phyerr events starving wmi transport
4472d5c65159SKalle Valo 		 * pipe. In such case the "scan completed" event should be (and
4473d5c65159SKalle Valo 		 * is) ignored by the host as it may be just firmware's scan
4474d5c65159SKalle Valo 		 * state machine recovering.
4475d5c65159SKalle Valo 		 */
4476d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
4477d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
4478d5c65159SKalle Valo 			    ar->scan.state);
4479d5c65159SKalle Valo 		break;
4480d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
4481d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
4482d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
4483d5c65159SKalle Valo 		break;
4484d5c65159SKalle Valo 	}
4485d5c65159SKalle Valo }
4486d5c65159SKalle Valo 
4487d5c65159SKalle Valo static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
4488d5c65159SKalle Valo {
4489d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
4490d5c65159SKalle Valo 
4491d5c65159SKalle Valo 	switch (ar->scan.state) {
4492d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
4493d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
4494d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
4495d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
4496d5c65159SKalle Valo 			    ar->scan.state);
4497d5c65159SKalle Valo 		break;
4498d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
4499d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
4500d5c65159SKalle Valo 		ar->scan_channel = NULL;
4501d5c65159SKalle Valo 		break;
4502d5c65159SKalle Valo 	}
4503d5c65159SKalle Valo }
4504d5c65159SKalle Valo 
4505d5c65159SKalle Valo static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
4506d5c65159SKalle Valo {
4507d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
4508d5c65159SKalle Valo 
4509d5c65159SKalle Valo 	switch (ar->scan.state) {
4510d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
4511d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
4512d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
4513d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
4514d5c65159SKalle Valo 			    ar->scan.state);
4515d5c65159SKalle Valo 		break;
4516d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
4517d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
4518d5c65159SKalle Valo 		ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
4519d5c65159SKalle Valo 		break;
4520d5c65159SKalle Valo 	}
4521d5c65159SKalle Valo }
4522d5c65159SKalle Valo 
4523d5c65159SKalle Valo static const char *
4524d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
4525d5c65159SKalle Valo 			       enum wmi_scan_completion_reason reason)
4526d5c65159SKalle Valo {
4527d5c65159SKalle Valo 	switch (type) {
4528d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
4529d5c65159SKalle Valo 		return "started";
4530d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
4531d5c65159SKalle Valo 		switch (reason) {
4532d5c65159SKalle Valo 		case WMI_SCAN_REASON_COMPLETED:
4533d5c65159SKalle Valo 			return "completed";
4534d5c65159SKalle Valo 		case WMI_SCAN_REASON_CANCELLED:
4535d5c65159SKalle Valo 			return "completed [cancelled]";
4536d5c65159SKalle Valo 		case WMI_SCAN_REASON_PREEMPTED:
4537d5c65159SKalle Valo 			return "completed [preempted]";
4538d5c65159SKalle Valo 		case WMI_SCAN_REASON_TIMEDOUT:
4539d5c65159SKalle Valo 			return "completed [timedout]";
4540d5c65159SKalle Valo 		case WMI_SCAN_REASON_INTERNAL_FAILURE:
4541d5c65159SKalle Valo 			return "completed [internal err]";
4542d5c65159SKalle Valo 		case WMI_SCAN_REASON_MAX:
4543d5c65159SKalle Valo 			break;
4544d5c65159SKalle Valo 		}
4545d5c65159SKalle Valo 		return "completed [unknown]";
4546d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
4547d5c65159SKalle Valo 		return "bss channel";
4548d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
4549d5c65159SKalle Valo 		return "foreign channel";
4550d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
4551d5c65159SKalle Valo 		return "dequeued";
4552d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
4553d5c65159SKalle Valo 		return "preempted";
4554d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
4555d5c65159SKalle Valo 		return "start failed";
4556d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
4557d5c65159SKalle Valo 		return "restarted";
4558d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
4559d5c65159SKalle Valo 		return "foreign channel exit";
4560d5c65159SKalle Valo 	default:
4561d5c65159SKalle Valo 		return "unknown";
4562d5c65159SKalle Valo 	}
4563d5c65159SKalle Valo }
4564d5c65159SKalle Valo 
4565d5c65159SKalle Valo static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
4566d5c65159SKalle Valo 			       struct wmi_scan_event *scan_evt_param)
4567d5c65159SKalle Valo {
4568d5c65159SKalle Valo 	const void **tb;
4569d5c65159SKalle Valo 	const struct wmi_scan_event *ev;
4570d5c65159SKalle Valo 	int ret;
4571d5c65159SKalle Valo 
4572d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4573d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4574d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4575d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4576d5c65159SKalle Valo 		return ret;
4577d5c65159SKalle Valo 	}
4578d5c65159SKalle Valo 
4579d5c65159SKalle Valo 	ev = tb[WMI_TAG_SCAN_EVENT];
4580d5c65159SKalle Valo 	if (!ev) {
4581d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch scan ev");
4582d5c65159SKalle Valo 		kfree(tb);
4583d5c65159SKalle Valo 		return -EPROTO;
4584d5c65159SKalle Valo 	}
4585d5c65159SKalle Valo 
4586d5c65159SKalle Valo 	scan_evt_param->event_type = ev->event_type;
4587d5c65159SKalle Valo 	scan_evt_param->reason = ev->reason;
4588d5c65159SKalle Valo 	scan_evt_param->channel_freq = ev->channel_freq;
4589d5c65159SKalle Valo 	scan_evt_param->scan_req_id = ev->scan_req_id;
4590d5c65159SKalle Valo 	scan_evt_param->scan_id = ev->scan_id;
4591d5c65159SKalle Valo 	scan_evt_param->vdev_id = ev->vdev_id;
4592d5c65159SKalle Valo 	scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
4593d5c65159SKalle Valo 
4594d5c65159SKalle Valo 	kfree(tb);
4595d5c65159SKalle Valo 	return 0;
4596d5c65159SKalle Valo }
4597d5c65159SKalle Valo 
4598d5c65159SKalle Valo static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
4599d5c65159SKalle Valo 					   struct wmi_peer_sta_kickout_arg *arg)
4600d5c65159SKalle Valo {
4601d5c65159SKalle Valo 	const void **tb;
4602d5c65159SKalle Valo 	const struct wmi_peer_sta_kickout_event *ev;
4603d5c65159SKalle Valo 	int ret;
4604d5c65159SKalle Valo 
4605d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4606d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4607d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4608d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4609d5c65159SKalle Valo 		return ret;
4610d5c65159SKalle Valo 	}
4611d5c65159SKalle Valo 
4612d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
4613d5c65159SKalle Valo 	if (!ev) {
4614d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer sta kickout ev");
4615d5c65159SKalle Valo 		kfree(tb);
4616d5c65159SKalle Valo 		return -EPROTO;
4617d5c65159SKalle Valo 	}
4618d5c65159SKalle Valo 
4619d5c65159SKalle Valo 	arg->mac_addr = ev->peer_macaddr.addr;
4620d5c65159SKalle Valo 
4621d5c65159SKalle Valo 	kfree(tb);
4622d5c65159SKalle Valo 	return 0;
4623d5c65159SKalle Valo }
4624d5c65159SKalle Valo 
4625d5c65159SKalle Valo static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
4626d5c65159SKalle Valo 			       struct wmi_roam_event *roam_ev)
4627d5c65159SKalle Valo {
4628d5c65159SKalle Valo 	const void **tb;
4629d5c65159SKalle Valo 	const struct wmi_roam_event *ev;
4630d5c65159SKalle Valo 	int ret;
4631d5c65159SKalle Valo 
4632d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4633d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4634d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4635d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4636d5c65159SKalle Valo 		return ret;
4637d5c65159SKalle Valo 	}
4638d5c65159SKalle Valo 
4639d5c65159SKalle Valo 	ev = tb[WMI_TAG_ROAM_EVENT];
4640d5c65159SKalle Valo 	if (!ev) {
4641d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch roam ev");
4642d5c65159SKalle Valo 		kfree(tb);
4643d5c65159SKalle Valo 		return -EPROTO;
4644d5c65159SKalle Valo 	}
4645d5c65159SKalle Valo 
4646d5c65159SKalle Valo 	roam_ev->vdev_id = ev->vdev_id;
4647d5c65159SKalle Valo 	roam_ev->reason = ev->reason;
4648d5c65159SKalle Valo 	roam_ev->rssi = ev->rssi;
4649d5c65159SKalle Valo 
4650d5c65159SKalle Valo 	kfree(tb);
4651d5c65159SKalle Valo 	return 0;
4652d5c65159SKalle Valo }
4653d5c65159SKalle Valo 
4654d5c65159SKalle Valo static int freq_to_idx(struct ath11k *ar, int freq)
4655d5c65159SKalle Valo {
4656d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
4657d5c65159SKalle Valo 	int band, ch, idx = 0;
4658d5c65159SKalle Valo 
4659d5c65159SKalle Valo 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
4660d5c65159SKalle Valo 		sband = ar->hw->wiphy->bands[band];
4661d5c65159SKalle Valo 		if (!sband)
4662d5c65159SKalle Valo 			continue;
4663d5c65159SKalle Valo 
4664d5c65159SKalle Valo 		for (ch = 0; ch < sband->n_channels; ch++, idx++)
4665d5c65159SKalle Valo 			if (sband->channels[ch].center_freq == freq)
4666d5c65159SKalle Valo 				goto exit;
4667d5c65159SKalle Valo 	}
4668d5c65159SKalle Valo 
4669d5c65159SKalle Valo exit:
4670d5c65159SKalle Valo 	return idx;
4671d5c65159SKalle Valo }
4672d5c65159SKalle Valo 
4673d5c65159SKalle Valo static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
4674d5c65159SKalle Valo 				    u32 len, struct wmi_chan_info_event *ch_info_ev)
4675d5c65159SKalle Valo {
4676d5c65159SKalle Valo 	const void **tb;
4677d5c65159SKalle Valo 	const struct wmi_chan_info_event *ev;
4678d5c65159SKalle Valo 	int ret;
4679d5c65159SKalle Valo 
4680d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
4681d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4682d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4683d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4684d5c65159SKalle Valo 		return ret;
4685d5c65159SKalle Valo 	}
4686d5c65159SKalle Valo 
4687d5c65159SKalle Valo 	ev = tb[WMI_TAG_CHAN_INFO_EVENT];
4688d5c65159SKalle Valo 	if (!ev) {
4689d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch chan info ev");
4690d5c65159SKalle Valo 		kfree(tb);
4691d5c65159SKalle Valo 		return -EPROTO;
4692d5c65159SKalle Valo 	}
4693d5c65159SKalle Valo 
4694d5c65159SKalle Valo 	ch_info_ev->err_code = ev->err_code;
4695d5c65159SKalle Valo 	ch_info_ev->freq = ev->freq;
4696d5c65159SKalle Valo 	ch_info_ev->cmd_flags = ev->cmd_flags;
4697d5c65159SKalle Valo 	ch_info_ev->noise_floor = ev->noise_floor;
4698d5c65159SKalle Valo 	ch_info_ev->rx_clear_count = ev->rx_clear_count;
4699d5c65159SKalle Valo 	ch_info_ev->cycle_count = ev->cycle_count;
4700d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
4701d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
4702d5c65159SKalle Valo 	ch_info_ev->rx_frame_count = ev->rx_frame_count;
4703d5c65159SKalle Valo 	ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
4704d5c65159SKalle Valo 	ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
4705d5c65159SKalle Valo 	ch_info_ev->vdev_id = ev->vdev_id;
4706d5c65159SKalle Valo 
4707d5c65159SKalle Valo 	kfree(tb);
4708d5c65159SKalle Valo 	return 0;
4709d5c65159SKalle Valo }
4710d5c65159SKalle Valo 
4711d5c65159SKalle Valo static int
4712d5c65159SKalle Valo ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
4713d5c65159SKalle Valo 				  struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
4714d5c65159SKalle Valo {
4715d5c65159SKalle Valo 	const void **tb;
4716d5c65159SKalle Valo 	const struct wmi_pdev_bss_chan_info_event *ev;
4717d5c65159SKalle Valo 	int ret;
4718d5c65159SKalle Valo 
4719d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4720d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4721d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4722d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4723d5c65159SKalle Valo 		return ret;
4724d5c65159SKalle Valo 	}
4725d5c65159SKalle Valo 
4726d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
4727d5c65159SKalle Valo 	if (!ev) {
4728d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
4729d5c65159SKalle Valo 		kfree(tb);
4730d5c65159SKalle Valo 		return -EPROTO;
4731d5c65159SKalle Valo 	}
4732d5c65159SKalle Valo 
4733d5c65159SKalle Valo 	bss_ch_info_ev->pdev_id = ev->pdev_id;
4734d5c65159SKalle Valo 	bss_ch_info_ev->freq = ev->freq;
4735d5c65159SKalle Valo 	bss_ch_info_ev->noise_floor = ev->noise_floor;
4736d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
4737d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
4738d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
4739d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
4740d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
4741d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
4742d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
4743d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
4744d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
4745d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
4746d5c65159SKalle Valo 
4747d5c65159SKalle Valo 	kfree(tb);
4748d5c65159SKalle Valo 	return 0;
4749d5c65159SKalle Valo }
4750d5c65159SKalle Valo 
4751d5c65159SKalle Valo static int
4752d5c65159SKalle Valo ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
4753d5c65159SKalle Valo 				      struct wmi_vdev_install_key_complete_arg *arg)
4754d5c65159SKalle Valo {
4755d5c65159SKalle Valo 	const void **tb;
4756d5c65159SKalle Valo 	const struct wmi_vdev_install_key_compl_event *ev;
4757d5c65159SKalle Valo 	int ret;
4758d5c65159SKalle Valo 
4759d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4760d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4761d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4762d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4763d5c65159SKalle Valo 		return ret;
4764d5c65159SKalle Valo 	}
4765d5c65159SKalle Valo 
4766d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
4767d5c65159SKalle Valo 	if (!ev) {
4768d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev install key compl ev");
4769d5c65159SKalle Valo 		kfree(tb);
4770d5c65159SKalle Valo 		return -EPROTO;
4771d5c65159SKalle Valo 	}
4772d5c65159SKalle Valo 
4773d5c65159SKalle Valo 	arg->vdev_id = ev->vdev_id;
4774d5c65159SKalle Valo 	arg->macaddr = ev->peer_macaddr.addr;
4775d5c65159SKalle Valo 	arg->key_idx = ev->key_idx;
4776d5c65159SKalle Valo 	arg->key_flags = ev->key_flags;
4777d5c65159SKalle Valo 	arg->status = ev->status;
4778d5c65159SKalle Valo 
4779d5c65159SKalle Valo 	kfree(tb);
4780d5c65159SKalle Valo 	return 0;
4781d5c65159SKalle Valo }
4782d5c65159SKalle Valo 
4783d5c65159SKalle Valo static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
4784d5c65159SKalle Valo 					  struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
4785d5c65159SKalle Valo {
4786d5c65159SKalle Valo 	const void **tb;
4787d5c65159SKalle Valo 	const struct wmi_peer_assoc_conf_event *ev;
4788d5c65159SKalle Valo 	int ret;
4789d5c65159SKalle Valo 
4790d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4791d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4792d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4793d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4794d5c65159SKalle Valo 		return ret;
4795d5c65159SKalle Valo 	}
4796d5c65159SKalle Valo 
4797d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
4798d5c65159SKalle Valo 	if (!ev) {
4799d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer assoc conf ev");
4800d5c65159SKalle Valo 		kfree(tb);
4801d5c65159SKalle Valo 		return -EPROTO;
4802d5c65159SKalle Valo 	}
4803d5c65159SKalle Valo 
4804d5c65159SKalle Valo 	peer_assoc_conf->vdev_id = ev->vdev_id;
4805d5c65159SKalle Valo 	peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
4806d5c65159SKalle Valo 
4807d5c65159SKalle Valo 	kfree(tb);
4808d5c65159SKalle Valo 	return 0;
4809d5c65159SKalle Valo }
4810d5c65159SKalle Valo 
4811d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
4812d5c65159SKalle Valo 					    struct ath11k_fw_stats_pdev *dst)
4813d5c65159SKalle Valo {
4814d5c65159SKalle Valo 	dst->ch_noise_floor = src->chan_nf;
4815d5c65159SKalle Valo 	dst->tx_frame_count = src->tx_frame_count;
4816d5c65159SKalle Valo 	dst->rx_frame_count = src->rx_frame_count;
4817d5c65159SKalle Valo 	dst->rx_clear_count = src->rx_clear_count;
4818d5c65159SKalle Valo 	dst->cycle_count = src->cycle_count;
4819d5c65159SKalle Valo 	dst->phy_err_count = src->phy_err_count;
4820d5c65159SKalle Valo 	dst->chan_tx_power = src->chan_tx_pwr;
4821d5c65159SKalle Valo }
4822d5c65159SKalle Valo 
4823d5c65159SKalle Valo static void
4824d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
4825d5c65159SKalle Valo 			      struct ath11k_fw_stats_pdev *dst)
4826d5c65159SKalle Valo {
4827d5c65159SKalle Valo 	dst->comp_queued = src->comp_queued;
4828d5c65159SKalle Valo 	dst->comp_delivered = src->comp_delivered;
4829d5c65159SKalle Valo 	dst->msdu_enqued = src->msdu_enqued;
4830d5c65159SKalle Valo 	dst->mpdu_enqued = src->mpdu_enqued;
4831d5c65159SKalle Valo 	dst->wmm_drop = src->wmm_drop;
4832d5c65159SKalle Valo 	dst->local_enqued = src->local_enqued;
4833d5c65159SKalle Valo 	dst->local_freed = src->local_freed;
4834d5c65159SKalle Valo 	dst->hw_queued = src->hw_queued;
4835d5c65159SKalle Valo 	dst->hw_reaped = src->hw_reaped;
4836d5c65159SKalle Valo 	dst->underrun = src->underrun;
4837d5c65159SKalle Valo 	dst->tx_abort = src->tx_abort;
4838d5c65159SKalle Valo 	dst->mpdus_requed = src->mpdus_requed;
4839d5c65159SKalle Valo 	dst->tx_ko = src->tx_ko;
4840d5c65159SKalle Valo 	dst->data_rc = src->data_rc;
4841d5c65159SKalle Valo 	dst->self_triggers = src->self_triggers;
4842d5c65159SKalle Valo 	dst->sw_retry_failure = src->sw_retry_failure;
4843d5c65159SKalle Valo 	dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
4844d5c65159SKalle Valo 	dst->pdev_cont_xretry = src->pdev_cont_xretry;
4845d5c65159SKalle Valo 	dst->pdev_tx_timeout = src->pdev_tx_timeout;
4846d5c65159SKalle Valo 	dst->pdev_resets = src->pdev_resets;
4847d5c65159SKalle Valo 	dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
4848d5c65159SKalle Valo 	dst->phy_underrun = src->phy_underrun;
4849d5c65159SKalle Valo 	dst->txop_ovf = src->txop_ovf;
4850d5c65159SKalle Valo }
4851d5c65159SKalle Valo 
4852d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
4853d5c65159SKalle Valo 					  struct ath11k_fw_stats_pdev *dst)
4854d5c65159SKalle Valo {
4855d5c65159SKalle Valo 	dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
4856d5c65159SKalle Valo 	dst->status_rcvd = src->status_rcvd;
4857d5c65159SKalle Valo 	dst->r0_frags = src->r0_frags;
4858d5c65159SKalle Valo 	dst->r1_frags = src->r1_frags;
4859d5c65159SKalle Valo 	dst->r2_frags = src->r2_frags;
4860d5c65159SKalle Valo 	dst->r3_frags = src->r3_frags;
4861d5c65159SKalle Valo 	dst->htt_msdus = src->htt_msdus;
4862d5c65159SKalle Valo 	dst->htt_mpdus = src->htt_mpdus;
4863d5c65159SKalle Valo 	dst->loc_msdus = src->loc_msdus;
4864d5c65159SKalle Valo 	dst->loc_mpdus = src->loc_mpdus;
4865d5c65159SKalle Valo 	dst->oversize_amsdu = src->oversize_amsdu;
4866d5c65159SKalle Valo 	dst->phy_errs = src->phy_errs;
4867d5c65159SKalle Valo 	dst->phy_err_drop = src->phy_err_drop;
4868d5c65159SKalle Valo 	dst->mpdu_errs = src->mpdu_errs;
4869d5c65159SKalle Valo }
4870d5c65159SKalle Valo 
4871d5c65159SKalle Valo static void
4872d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
4873d5c65159SKalle Valo 			   struct ath11k_fw_stats_vdev *dst)
4874d5c65159SKalle Valo {
4875d5c65159SKalle Valo 	int i;
4876d5c65159SKalle Valo 
4877d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
4878d5c65159SKalle Valo 	dst->beacon_snr = src->beacon_snr;
4879d5c65159SKalle Valo 	dst->data_snr = src->data_snr;
4880d5c65159SKalle Valo 	dst->num_rx_frames = src->num_rx_frames;
4881d5c65159SKalle Valo 	dst->num_rts_fail = src->num_rts_fail;
4882d5c65159SKalle Valo 	dst->num_rts_success = src->num_rts_success;
4883d5c65159SKalle Valo 	dst->num_rx_err = src->num_rx_err;
4884d5c65159SKalle Valo 	dst->num_rx_discard = src->num_rx_discard;
4885d5c65159SKalle Valo 	dst->num_tx_not_acked = src->num_tx_not_acked;
4886d5c65159SKalle Valo 
4887d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
4888d5c65159SKalle Valo 		dst->num_tx_frames[i] = src->num_tx_frames[i];
4889d5c65159SKalle Valo 
4890d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
4891d5c65159SKalle Valo 		dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
4892d5c65159SKalle Valo 
4893d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
4894d5c65159SKalle Valo 		dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
4895d5c65159SKalle Valo 
4896d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
4897d5c65159SKalle Valo 		dst->tx_rate_history[i] = src->tx_rate_history[i];
4898d5c65159SKalle Valo 
4899d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
4900d5c65159SKalle Valo 		dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
4901d5c65159SKalle Valo }
4902d5c65159SKalle Valo 
4903d5c65159SKalle Valo static void
4904d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
4905d5c65159SKalle Valo 			  struct ath11k_fw_stats_bcn *dst)
4906d5c65159SKalle Valo {
4907d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
4908d5c65159SKalle Valo 	dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
4909d5c65159SKalle Valo 	dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
4910d5c65159SKalle Valo }
4911d5c65159SKalle Valo 
4912d5c65159SKalle Valo int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
4913d5c65159SKalle Valo 			     struct ath11k_fw_stats *stats)
4914d5c65159SKalle Valo {
4915d5c65159SKalle Valo 	const void **tb;
4916d5c65159SKalle Valo 	const struct wmi_stats_event *ev;
4917d5c65159SKalle Valo 	const void *data;
4918d5c65159SKalle Valo 	int i, ret;
4919d5c65159SKalle Valo 	u32 len = skb->len;
4920d5c65159SKalle Valo 
4921d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, len, GFP_ATOMIC);
4922d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4923d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4924d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4925d5c65159SKalle Valo 		return ret;
4926d5c65159SKalle Valo 	}
4927d5c65159SKalle Valo 
4928d5c65159SKalle Valo 	ev = tb[WMI_TAG_STATS_EVENT];
4929d5c65159SKalle Valo 	data = tb[WMI_TAG_ARRAY_BYTE];
4930d5c65159SKalle Valo 	if (!ev || !data) {
4931d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch update stats ev");
4932d5c65159SKalle Valo 		kfree(tb);
4933d5c65159SKalle Valo 		return -EPROTO;
4934d5c65159SKalle Valo 	}
4935d5c65159SKalle Valo 
4936d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
4937d5c65159SKalle Valo 		   "wmi stats update ev pdev_id %d pdev %i vdev %i bcn %i\n",
4938d5c65159SKalle Valo 		   ev->pdev_id,
4939d5c65159SKalle Valo 		   ev->num_pdev_stats, ev->num_vdev_stats,
4940d5c65159SKalle Valo 		   ev->num_bcn_stats);
4941d5c65159SKalle Valo 
4942d5c65159SKalle Valo 	stats->pdev_id = ev->pdev_id;
4943d5c65159SKalle Valo 	stats->stats_id = 0;
4944d5c65159SKalle Valo 
4945d5c65159SKalle Valo 	for (i = 0; i < ev->num_pdev_stats; i++) {
4946d5c65159SKalle Valo 		const struct wmi_pdev_stats *src;
4947d5c65159SKalle Valo 		struct ath11k_fw_stats_pdev *dst;
4948d5c65159SKalle Valo 
4949d5c65159SKalle Valo 		src = data;
4950d5c65159SKalle Valo 		if (len < sizeof(*src)) {
4951d5c65159SKalle Valo 			kfree(tb);
4952d5c65159SKalle Valo 			return -EPROTO;
4953d5c65159SKalle Valo 		}
4954d5c65159SKalle Valo 
4955d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_PDEV_STAT;
4956d5c65159SKalle Valo 
4957d5c65159SKalle Valo 		data += sizeof(*src);
4958d5c65159SKalle Valo 		len -= sizeof(*src);
4959d5c65159SKalle Valo 
4960d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
4961d5c65159SKalle Valo 		if (!dst)
4962d5c65159SKalle Valo 			continue;
4963d5c65159SKalle Valo 
4964d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
4965d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
4966d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
4967d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->pdevs);
4968d5c65159SKalle Valo 	}
4969d5c65159SKalle Valo 
4970d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdev_stats; i++) {
4971d5c65159SKalle Valo 		const struct wmi_vdev_stats *src;
4972d5c65159SKalle Valo 		struct ath11k_fw_stats_vdev *dst;
4973d5c65159SKalle Valo 
4974d5c65159SKalle Valo 		src = data;
4975d5c65159SKalle Valo 		if (len < sizeof(*src)) {
4976d5c65159SKalle Valo 			kfree(tb);
4977d5c65159SKalle Valo 			return -EPROTO;
4978d5c65159SKalle Valo 		}
4979d5c65159SKalle Valo 
4980d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_VDEV_STAT;
4981d5c65159SKalle Valo 
4982d5c65159SKalle Valo 		data += sizeof(*src);
4983d5c65159SKalle Valo 		len -= sizeof(*src);
4984d5c65159SKalle Valo 
4985d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
4986d5c65159SKalle Valo 		if (!dst)
4987d5c65159SKalle Valo 			continue;
4988d5c65159SKalle Valo 
4989d5c65159SKalle Valo 		ath11k_wmi_pull_vdev_stats(src, dst);
4990d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->vdevs);
4991d5c65159SKalle Valo 	}
4992d5c65159SKalle Valo 
4993d5c65159SKalle Valo 	for (i = 0; i < ev->num_bcn_stats; i++) {
4994d5c65159SKalle Valo 		const struct wmi_bcn_stats *src;
4995d5c65159SKalle Valo 		struct ath11k_fw_stats_bcn *dst;
4996d5c65159SKalle Valo 
4997d5c65159SKalle Valo 		src = data;
4998d5c65159SKalle Valo 		if (len < sizeof(*src)) {
4999d5c65159SKalle Valo 			kfree(tb);
5000d5c65159SKalle Valo 			return -EPROTO;
5001d5c65159SKalle Valo 		}
5002d5c65159SKalle Valo 
5003d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_BCN_STAT;
5004d5c65159SKalle Valo 
5005d5c65159SKalle Valo 		data += sizeof(*src);
5006d5c65159SKalle Valo 		len -= sizeof(*src);
5007d5c65159SKalle Valo 
5008d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5009d5c65159SKalle Valo 		if (!dst)
5010d5c65159SKalle Valo 			continue;
5011d5c65159SKalle Valo 
5012d5c65159SKalle Valo 		ath11k_wmi_pull_bcn_stats(src, dst);
5013d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->bcn);
5014d5c65159SKalle Valo 	}
5015d5c65159SKalle Valo 
5016d5c65159SKalle Valo 	kfree(tb);
5017d5c65159SKalle Valo 	return 0;
5018d5c65159SKalle Valo }
5019d5c65159SKalle Valo 
5020a41d1034SPradeep Kumar Chitrapu static int
5021a41d1034SPradeep Kumar Chitrapu ath11k_pull_pdev_temp_ev(struct ath11k_base *ab, u8 *evt_buf,
5022a41d1034SPradeep Kumar Chitrapu 			 u32 len, const struct wmi_pdev_temperature_event *ev)
5023a41d1034SPradeep Kumar Chitrapu {
5024a41d1034SPradeep Kumar Chitrapu 	const void **tb;
5025a41d1034SPradeep Kumar Chitrapu 	int ret;
5026a41d1034SPradeep Kumar Chitrapu 
5027a41d1034SPradeep Kumar Chitrapu 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5028a41d1034SPradeep Kumar Chitrapu 	if (IS_ERR(tb)) {
5029a41d1034SPradeep Kumar Chitrapu 		ret = PTR_ERR(tb);
5030a41d1034SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5031a41d1034SPradeep Kumar Chitrapu 		return ret;
5032a41d1034SPradeep Kumar Chitrapu 	}
5033a41d1034SPradeep Kumar Chitrapu 
5034a41d1034SPradeep Kumar Chitrapu 	ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
5035a41d1034SPradeep Kumar Chitrapu 	if (!ev) {
5036a41d1034SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to fetch pdev temp ev");
5037a41d1034SPradeep Kumar Chitrapu 		kfree(tb);
5038a41d1034SPradeep Kumar Chitrapu 		return -EPROTO;
5039a41d1034SPradeep Kumar Chitrapu 	}
5040a41d1034SPradeep Kumar Chitrapu 
5041a41d1034SPradeep Kumar Chitrapu 	kfree(tb);
5042a41d1034SPradeep Kumar Chitrapu 	return 0;
5043a41d1034SPradeep Kumar Chitrapu }
5044a41d1034SPradeep Kumar Chitrapu 
5045d5c65159SKalle Valo size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head)
5046d5c65159SKalle Valo {
5047d5c65159SKalle Valo 	struct ath11k_fw_stats_vdev *i;
5048d5c65159SKalle Valo 	size_t num = 0;
5049d5c65159SKalle Valo 
5050d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
5051d5c65159SKalle Valo 		++num;
5052d5c65159SKalle Valo 
5053d5c65159SKalle Valo 	return num;
5054d5c65159SKalle Valo }
5055d5c65159SKalle Valo 
5056d5c65159SKalle Valo static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head)
5057d5c65159SKalle Valo {
5058d5c65159SKalle Valo 	struct ath11k_fw_stats_bcn *i;
5059d5c65159SKalle Valo 	size_t num = 0;
5060d5c65159SKalle Valo 
5061d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
5062d5c65159SKalle Valo 		++num;
5063d5c65159SKalle Valo 
5064d5c65159SKalle Valo 	return num;
5065d5c65159SKalle Valo }
5066d5c65159SKalle Valo 
5067d5c65159SKalle Valo static void
5068d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
5069d5c65159SKalle Valo 				   char *buf, u32 *length)
5070d5c65159SKalle Valo {
5071d5c65159SKalle Valo 	u32 len = *length;
5072d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
5073d5c65159SKalle Valo 
5074d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
5075d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
5076d5c65159SKalle Valo 			"ath11k PDEV stats");
5077d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
5078d5c65159SKalle Valo 			"=================");
5079d5c65159SKalle Valo 
5080d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5081d5c65159SKalle Valo 			"Channel noise floor", pdev->ch_noise_floor);
5082d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5083d5c65159SKalle Valo 			"Channel TX power", pdev->chan_tx_power);
5084d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5085d5c65159SKalle Valo 			"TX frame count", pdev->tx_frame_count);
5086d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5087d5c65159SKalle Valo 			"RX frame count", pdev->rx_frame_count);
5088d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5089d5c65159SKalle Valo 			"RX clear count", pdev->rx_clear_count);
5090d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5091d5c65159SKalle Valo 			"Cycle count", pdev->cycle_count);
5092d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5093d5c65159SKalle Valo 			"PHY error count", pdev->phy_err_count);
5094d5c65159SKalle Valo 
5095d5c65159SKalle Valo 	*length = len;
5096d5c65159SKalle Valo }
5097d5c65159SKalle Valo 
5098d5c65159SKalle Valo static void
5099d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
5100d5c65159SKalle Valo 				 char *buf, u32 *length)
5101d5c65159SKalle Valo {
5102d5c65159SKalle Valo 	u32 len = *length;
5103d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
5104d5c65159SKalle Valo 
5105d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
5106d5c65159SKalle Valo 			 "ath11k PDEV TX stats");
5107d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
5108d5c65159SKalle Valo 			 "====================");
5109d5c65159SKalle Valo 
5110d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5111d5c65159SKalle Valo 			 "HTT cookies queued", pdev->comp_queued);
5112d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5113d5c65159SKalle Valo 			 "HTT cookies disp.", pdev->comp_delivered);
5114d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5115d5c65159SKalle Valo 			 "MSDU queued", pdev->msdu_enqued);
5116d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5117d5c65159SKalle Valo 			 "MPDU queued", pdev->mpdu_enqued);
5118d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5119d5c65159SKalle Valo 			 "MSDUs dropped", pdev->wmm_drop);
5120d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5121d5c65159SKalle Valo 			 "Local enqued", pdev->local_enqued);
5122d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5123d5c65159SKalle Valo 			 "Local freed", pdev->local_freed);
5124d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5125d5c65159SKalle Valo 			 "HW queued", pdev->hw_queued);
5126d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5127d5c65159SKalle Valo 			 "PPDUs reaped", pdev->hw_reaped);
5128d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5129d5c65159SKalle Valo 			 "Num underruns", pdev->underrun);
5130d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5131d5c65159SKalle Valo 			 "PPDUs cleaned", pdev->tx_abort);
5132d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5133d5c65159SKalle Valo 			 "MPDUs requed", pdev->mpdus_requed);
5134d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5135d5c65159SKalle Valo 			 "Excessive retries", pdev->tx_ko);
5136d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5137d5c65159SKalle Valo 			 "HW rate", pdev->data_rc);
5138d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5139d5c65159SKalle Valo 			 "Sched self triggers", pdev->self_triggers);
5140d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5141d5c65159SKalle Valo 			 "Dropped due to SW retries",
5142d5c65159SKalle Valo 			 pdev->sw_retry_failure);
5143d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5144d5c65159SKalle Valo 			 "Illegal rate phy errors",
5145d5c65159SKalle Valo 			 pdev->illgl_rate_phy_err);
5146d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5147d5c65159SKalle Valo 			 "PDEV continuous xretry", pdev->pdev_cont_xretry);
5148d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5149d5c65159SKalle Valo 			 "TX timeout", pdev->pdev_tx_timeout);
5150d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5151d5c65159SKalle Valo 			 "PDEV resets", pdev->pdev_resets);
5152d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5153d5c65159SKalle Valo 			 "Stateless TIDs alloc failures",
5154d5c65159SKalle Valo 			 pdev->stateless_tid_alloc_failure);
5155d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5156d5c65159SKalle Valo 			 "PHY underrun", pdev->phy_underrun);
5157d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
5158d5c65159SKalle Valo 			 "MPDU is more than txop limit", pdev->txop_ovf);
5159d5c65159SKalle Valo 	*length = len;
5160d5c65159SKalle Valo }
5161d5c65159SKalle Valo 
5162d5c65159SKalle Valo static void
5163d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
5164d5c65159SKalle Valo 				 char *buf, u32 *length)
5165d5c65159SKalle Valo {
5166d5c65159SKalle Valo 	u32 len = *length;
5167d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
5168d5c65159SKalle Valo 
5169d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
5170d5c65159SKalle Valo 			 "ath11k PDEV RX stats");
5171d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
5172d5c65159SKalle Valo 			 "====================");
5173d5c65159SKalle Valo 
5174d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5175d5c65159SKalle Valo 			 "Mid PPDU route change",
5176d5c65159SKalle Valo 			 pdev->mid_ppdu_route_change);
5177d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5178d5c65159SKalle Valo 			 "Tot. number of statuses", pdev->status_rcvd);
5179d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5180d5c65159SKalle Valo 			 "Extra frags on rings 0", pdev->r0_frags);
5181d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5182d5c65159SKalle Valo 			 "Extra frags on rings 1", pdev->r1_frags);
5183d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5184d5c65159SKalle Valo 			 "Extra frags on rings 2", pdev->r2_frags);
5185d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5186d5c65159SKalle Valo 			 "Extra frags on rings 3", pdev->r3_frags);
5187d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5188d5c65159SKalle Valo 			 "MSDUs delivered to HTT", pdev->htt_msdus);
5189d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5190d5c65159SKalle Valo 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
5191d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5192d5c65159SKalle Valo 			 "MSDUs delivered to stack", pdev->loc_msdus);
5193d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5194d5c65159SKalle Valo 			 "MPDUs delivered to stack", pdev->loc_mpdus);
5195d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5196d5c65159SKalle Valo 			 "Oversized AMSUs", pdev->oversize_amsdu);
5197d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5198d5c65159SKalle Valo 			 "PHY errors", pdev->phy_errs);
5199d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5200d5c65159SKalle Valo 			 "PHY errors drops", pdev->phy_err_drop);
5201d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
5202d5c65159SKalle Valo 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
5203d5c65159SKalle Valo 	*length = len;
5204d5c65159SKalle Valo }
5205d5c65159SKalle Valo 
5206d5c65159SKalle Valo static void
5207d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
5208d5c65159SKalle Valo 			      const struct ath11k_fw_stats_vdev *vdev,
5209d5c65159SKalle Valo 			      char *buf, u32 *length)
5210d5c65159SKalle Valo {
5211d5c65159SKalle Valo 	u32 len = *length;
5212d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
5213d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
5214d5c65159SKalle Valo 	u8 *vif_macaddr;
5215d5c65159SKalle Valo 	int i;
5216d5c65159SKalle Valo 
5217d5c65159SKalle Valo 	/* VDEV stats has all the active VDEVs of other PDEVs as well,
5218d5c65159SKalle Valo 	 * ignoring those not part of requested PDEV
5219d5c65159SKalle Valo 	 */
5220d5c65159SKalle Valo 	if (!arvif)
5221d5c65159SKalle Valo 		return;
5222d5c65159SKalle Valo 
5223d5c65159SKalle Valo 	vif_macaddr = arvif->vif->addr;
5224d5c65159SKalle Valo 
5225d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5226d5c65159SKalle Valo 			 "VDEV ID", vdev->vdev_id);
5227d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
5228d5c65159SKalle Valo 			 "VDEV MAC address", vif_macaddr);
5229d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5230d5c65159SKalle Valo 			 "beacon snr", vdev->beacon_snr);
5231d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5232d5c65159SKalle Valo 			 "data snr", vdev->data_snr);
5233d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5234d5c65159SKalle Valo 			 "num rx frames", vdev->num_rx_frames);
5235d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5236d5c65159SKalle Valo 			 "num rts fail", vdev->num_rts_fail);
5237d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5238d5c65159SKalle Valo 			 "num rts success", vdev->num_rts_success);
5239d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5240d5c65159SKalle Valo 			 "num rx err", vdev->num_rx_err);
5241d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5242d5c65159SKalle Valo 			 "num rx discard", vdev->num_rx_discard);
5243d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5244d5c65159SKalle Valo 			 "num tx not acked", vdev->num_tx_not_acked);
5245d5c65159SKalle Valo 
5246d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
5247d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
5248d5c65159SKalle Valo 				"%25s [%02d] %u\n",
5249d5c65159SKalle Valo 				"num tx frames", i,
5250d5c65159SKalle Valo 				vdev->num_tx_frames[i]);
5251d5c65159SKalle Valo 
5252d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
5253d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
5254d5c65159SKalle Valo 				"%25s [%02d] %u\n",
5255d5c65159SKalle Valo 				"num tx frames retries", i,
5256d5c65159SKalle Valo 				vdev->num_tx_frames_retries[i]);
5257d5c65159SKalle Valo 
5258d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
5259d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
5260d5c65159SKalle Valo 				"%25s [%02d] %u\n",
5261d5c65159SKalle Valo 				"num tx frames failures", i,
5262d5c65159SKalle Valo 				vdev->num_tx_frames_failures[i]);
5263d5c65159SKalle Valo 
5264d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
5265d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
5266d5c65159SKalle Valo 				"%25s [%02d] 0x%08x\n",
5267d5c65159SKalle Valo 				"tx rate history", i,
5268d5c65159SKalle Valo 				vdev->tx_rate_history[i]);
5269d5c65159SKalle Valo 
5270d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
5271d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
5272d5c65159SKalle Valo 				"%25s [%02d] %u\n",
5273d5c65159SKalle Valo 				"beacon rssi history", i,
5274d5c65159SKalle Valo 				vdev->beacon_rssi_history[i]);
5275d5c65159SKalle Valo 
5276d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
5277d5c65159SKalle Valo 	*length = len;
5278d5c65159SKalle Valo }
5279d5c65159SKalle Valo 
5280d5c65159SKalle Valo static void
5281d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
5282d5c65159SKalle Valo 			     const struct ath11k_fw_stats_bcn *bcn,
5283d5c65159SKalle Valo 			     char *buf, u32 *length)
5284d5c65159SKalle Valo {
5285d5c65159SKalle Valo 	u32 len = *length;
5286d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
5287d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
5288d5c65159SKalle Valo 	u8 *vdev_macaddr;
5289d5c65159SKalle Valo 
5290d5c65159SKalle Valo 	if (!arvif) {
5291d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
5292d5c65159SKalle Valo 			    bcn->vdev_id);
5293d5c65159SKalle Valo 		return;
5294d5c65159SKalle Valo 	}
5295d5c65159SKalle Valo 
5296d5c65159SKalle Valo 	vdev_macaddr = arvif->vif->addr;
5297d5c65159SKalle Valo 
5298d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5299d5c65159SKalle Valo 			 "VDEV ID", bcn->vdev_id);
5300d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
5301d5c65159SKalle Valo 			 "VDEV MAC address", vdev_macaddr);
5302d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
5303d5c65159SKalle Valo 			 "================");
5304d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5305d5c65159SKalle Valo 			 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
5306d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
5307d5c65159SKalle Valo 			 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
5308d5c65159SKalle Valo 
5309d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
5310d5c65159SKalle Valo 	*length = len;
5311d5c65159SKalle Valo }
5312d5c65159SKalle Valo 
5313d5c65159SKalle Valo void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
5314d5c65159SKalle Valo 			      struct ath11k_fw_stats *fw_stats,
5315d5c65159SKalle Valo 			      u32 stats_id, char *buf)
5316d5c65159SKalle Valo {
5317d5c65159SKalle Valo 	u32 len = 0;
5318d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
5319d5c65159SKalle Valo 	const struct ath11k_fw_stats_pdev *pdev;
5320d5c65159SKalle Valo 	const struct ath11k_fw_stats_vdev *vdev;
5321d5c65159SKalle Valo 	const struct ath11k_fw_stats_bcn *bcn;
5322d5c65159SKalle Valo 	size_t num_bcn;
5323d5c65159SKalle Valo 
5324d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
5325d5c65159SKalle Valo 
5326d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_PDEV_STAT) {
5327d5c65159SKalle Valo 		pdev = list_first_entry_or_null(&fw_stats->pdevs,
5328d5c65159SKalle Valo 						struct ath11k_fw_stats_pdev, list);
5329d5c65159SKalle Valo 		if (!pdev) {
5330d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to get pdev stats\n");
5331d5c65159SKalle Valo 			goto unlock;
5332d5c65159SKalle Valo 		}
5333d5c65159SKalle Valo 
5334d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
5335d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
5336d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
5337d5c65159SKalle Valo 	}
5338d5c65159SKalle Valo 
5339d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_VDEV_STAT) {
5340d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
5341d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n",
5342d5c65159SKalle Valo 				 "ath11k VDEV stats");
5343d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
5344d5c65159SKalle Valo 				 "=================");
5345d5c65159SKalle Valo 
5346d5c65159SKalle Valo 		list_for_each_entry(vdev, &fw_stats->vdevs, list)
5347d5c65159SKalle Valo 			ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
5348d5c65159SKalle Valo 	}
5349d5c65159SKalle Valo 
5350d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_BCN_STAT) {
5351d5c65159SKalle Valo 		num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn);
5352d5c65159SKalle Valo 
5353d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
5354d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
5355d5c65159SKalle Valo 				 "ath11k Beacon stats", num_bcn);
5356d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
5357d5c65159SKalle Valo 				 "===================");
5358d5c65159SKalle Valo 
5359d5c65159SKalle Valo 		list_for_each_entry(bcn, &fw_stats->bcn, list)
5360d5c65159SKalle Valo 			ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
5361d5c65159SKalle Valo 	}
5362d5c65159SKalle Valo 
5363d5c65159SKalle Valo unlock:
5364d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
5365d5c65159SKalle Valo 
5366d5c65159SKalle Valo 	if (len >= buf_len)
5367d5c65159SKalle Valo 		buf[len - 1] = 0;
5368d5c65159SKalle Valo 	else
5369d5c65159SKalle Valo 		buf[len] = 0;
5370d5c65159SKalle Valo }
5371d5c65159SKalle Valo 
5372d5c65159SKalle Valo static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
5373d5c65159SKalle Valo {
5374d5c65159SKalle Valo 	/* try to send pending beacons first. they take priority */
53756bc9d6f7SJohn Crispin 	wake_up(&ab->wmi_ab.tx_credits_wq);
5376d5c65159SKalle Valo }
5377d5c65159SKalle Valo 
5378d5c65159SKalle Valo static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
5379d5c65159SKalle Valo 				       struct sk_buff *skb)
5380d5c65159SKalle Valo {
5381d5c65159SKalle Valo 	dev_kfree_skb(skb);
5382d5c65159SKalle Valo }
5383d5c65159SKalle Valo 
5384d5c65159SKalle Valo static bool ath11k_reg_is_world_alpha(char *alpha)
5385d5c65159SKalle Valo {
5386d5c65159SKalle Valo 	return alpha[0] == '0' && alpha[1] == '0';
5387d5c65159SKalle Valo }
5388d5c65159SKalle Valo 
5389d5c65159SKalle Valo static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb)
5390d5c65159SKalle Valo {
5391d5c65159SKalle Valo 	struct cur_regulatory_info *reg_info = NULL;
5392d5c65159SKalle Valo 	struct ieee80211_regdomain *regd = NULL;
5393d5c65159SKalle Valo 	bool intersect = false;
5394d5c65159SKalle Valo 	int ret = 0, pdev_idx;
5395d5c65159SKalle Valo 	struct ath11k *ar;
5396d5c65159SKalle Valo 
5397d5c65159SKalle Valo 	reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
5398d5c65159SKalle Valo 	if (!reg_info) {
5399d5c65159SKalle Valo 		ret = -ENOMEM;
5400d5c65159SKalle Valo 		goto fallback;
5401d5c65159SKalle Valo 	}
5402d5c65159SKalle Valo 
5403d5c65159SKalle Valo 	ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
5404d5c65159SKalle Valo 	if (ret) {
5405d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract regulatory info from received event\n");
5406d5c65159SKalle Valo 		goto fallback;
5407d5c65159SKalle Valo 	}
5408d5c65159SKalle Valo 
5409d5c65159SKalle Valo 	if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
5410d5c65159SKalle Valo 		/* In case of failure to set the requested ctry,
5411d5c65159SKalle Valo 		 * fw retains the current regd. We print a failure info
5412d5c65159SKalle Valo 		 * and return from here.
5413d5c65159SKalle Valo 		 */
5414d5c65159SKalle Valo 		ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
5415d5c65159SKalle Valo 		goto mem_free;
5416d5c65159SKalle Valo 	}
5417d5c65159SKalle Valo 
5418d5c65159SKalle Valo 	pdev_idx = reg_info->phy_id;
5419d5c65159SKalle Valo 
54205f859bc0SCarl Huang 	if (pdev_idx >= ab->num_radios) {
542184eee3c8SCarl Huang 		/* Process the event for phy0 only if single_pdev_only
542284eee3c8SCarl Huang 		 * is true. If pdev_idx is valid but not 0, discard the
542384eee3c8SCarl Huang 		 * event. Otherwise, it goes to fallback.
542484eee3c8SCarl Huang 		 */
542584eee3c8SCarl Huang 		if (ab->hw_params.single_pdev_only &&
542684eee3c8SCarl Huang 		    pdev_idx < ab->hw_params.num_rxmda_per_pdev)
54275f859bc0SCarl Huang 			goto mem_free;
54285f859bc0SCarl Huang 		else
5429d5c65159SKalle Valo 			goto fallback;
54305f859bc0SCarl Huang 	}
5431d5c65159SKalle Valo 
5432d5c65159SKalle Valo 	/* Avoid multiple overwrites to default regd, during core
5433d5c65159SKalle Valo 	 * stop-start after mac registration.
5434d5c65159SKalle Valo 	 */
5435d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
5436d5c65159SKalle Valo 	    !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
5437d5c65159SKalle Valo 		    (char *)reg_info->alpha2, 2))
5438b5316db2SColin Ian King 		goto mem_free;
5439d5c65159SKalle Valo 
5440d5c65159SKalle Valo 	/* Intersect new rules with default regd if a new country setting was
5441d5c65159SKalle Valo 	 * requested, i.e a default regd was already set during initialization
5442d5c65159SKalle Valo 	 * and the regd coming from this event has a valid country info.
5443d5c65159SKalle Valo 	 */
5444d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] &&
5445d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)
5446d5c65159SKalle Valo 		ab->default_regd[pdev_idx]->alpha2) &&
5447d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
5448d5c65159SKalle Valo 		intersect = true;
5449d5c65159SKalle Valo 
5450d5c65159SKalle Valo 	regd = ath11k_reg_build_regd(ab, reg_info, intersect);
5451d5c65159SKalle Valo 	if (!regd) {
5452d5c65159SKalle Valo 		ath11k_warn(ab, "failed to build regd from reg_info\n");
5453d5c65159SKalle Valo 		goto fallback;
5454d5c65159SKalle Valo 	}
5455d5c65159SKalle Valo 
5456d5c65159SKalle Valo 	spin_lock(&ab->base_lock);
5457d5c65159SKalle Valo 	if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) {
5458d5c65159SKalle Valo 		/* Once mac is registered, ar is valid and all CC events from
5459d5c65159SKalle Valo 		 * fw is considered to be received due to user requests
5460d5c65159SKalle Valo 		 * currently.
5461d5c65159SKalle Valo 		 * Free previously built regd before assigning the newly
5462d5c65159SKalle Valo 		 * generated regd to ar. NULL pointer handling will be
5463d5c65159SKalle Valo 		 * taken care by kfree itself.
5464d5c65159SKalle Valo 		 */
5465d5c65159SKalle Valo 		ar = ab->pdevs[pdev_idx].ar;
5466d5c65159SKalle Valo 		kfree(ab->new_regd[pdev_idx]);
5467d5c65159SKalle Valo 		ab->new_regd[pdev_idx] = regd;
5468d5c65159SKalle Valo 		ieee80211_queue_work(ar->hw, &ar->regd_update_work);
5469d5c65159SKalle Valo 	} else {
5470d5c65159SKalle Valo 		/* Multiple events for the same *ar is not expected. But we
5471d5c65159SKalle Valo 		 * can still clear any previously stored default_regd if we
5472d5c65159SKalle Valo 		 * are receiving this event for the same radio by mistake.
5473d5c65159SKalle Valo 		 * NULL pointer handling will be taken care by kfree itself.
5474d5c65159SKalle Valo 		 */
5475d5c65159SKalle Valo 		kfree(ab->default_regd[pdev_idx]);
5476d5c65159SKalle Valo 		/* This regd would be applied during mac registration */
5477d5c65159SKalle Valo 		ab->default_regd[pdev_idx] = regd;
5478d5c65159SKalle Valo 	}
5479d5c65159SKalle Valo 	ab->dfs_region = reg_info->dfs_region;
5480d5c65159SKalle Valo 	spin_unlock(&ab->base_lock);
5481d5c65159SKalle Valo 
5482d5c65159SKalle Valo 	goto mem_free;
5483d5c65159SKalle Valo 
5484d5c65159SKalle Valo fallback:
5485d5c65159SKalle Valo 	/* Fallback to older reg (by sending previous country setting
5486d5c65159SKalle Valo 	 * again if fw has succeded and we failed to process here.
5487d5c65159SKalle Valo 	 * The Regdomain should be uniform across driver and fw. Since the
5488d5c65159SKalle Valo 	 * FW has processed the command and sent a success status, we expect
5489d5c65159SKalle Valo 	 * this function to succeed as well. If it doesn't, CTRY needs to be
5490d5c65159SKalle Valo 	 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
5491d5c65159SKalle Valo 	 */
5492d5c65159SKalle Valo 	/* TODO: This is rare, but still should also be handled */
5493d5c65159SKalle Valo 	WARN_ON(1);
5494d5c65159SKalle Valo mem_free:
5495d5c65159SKalle Valo 	if (reg_info) {
5496d5c65159SKalle Valo 		kfree(reg_info->reg_rules_2g_ptr);
5497d5c65159SKalle Valo 		kfree(reg_info->reg_rules_5g_ptr);
5498d5c65159SKalle Valo 		kfree(reg_info);
5499d5c65159SKalle Valo 	}
5500d5c65159SKalle Valo 	return ret;
5501d5c65159SKalle Valo }
5502d5c65159SKalle Valo 
5503d5c65159SKalle Valo static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
5504d5c65159SKalle Valo 				    const void *ptr, void *data)
5505d5c65159SKalle Valo {
5506d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse *rdy_parse = data;
550721c1b063SMaharaja Kennadyrajan 	struct wmi_ready_event fixed_param;
5508d5c65159SKalle Valo 	struct wmi_mac_addr *addr_list;
5509d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
5510d5c65159SKalle Valo 	u32 num_mac_addr;
5511d5c65159SKalle Valo 	int i;
5512d5c65159SKalle Valo 
5513d5c65159SKalle Valo 	switch (tag) {
5514d5c65159SKalle Valo 	case WMI_TAG_READY_EVENT:
551521c1b063SMaharaja Kennadyrajan 		memset(&fixed_param, 0, sizeof(fixed_param));
551621c1b063SMaharaja Kennadyrajan 		memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
551721c1b063SMaharaja Kennadyrajan 		       min_t(u16, sizeof(fixed_param), len));
551821c1b063SMaharaja Kennadyrajan 		ab->wlan_init_status = fixed_param.ready_event_min.status;
551921c1b063SMaharaja Kennadyrajan 		rdy_parse->num_extra_mac_addr =
552021c1b063SMaharaja Kennadyrajan 			fixed_param.ready_event_min.num_extra_mac_addr;
5521d5c65159SKalle Valo 
552221c1b063SMaharaja Kennadyrajan 		ether_addr_copy(ab->mac_addr,
552321c1b063SMaharaja Kennadyrajan 				fixed_param.ready_event_min.mac_addr.addr);
552421c1b063SMaharaja Kennadyrajan 		ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum;
5525d5c65159SKalle Valo 		ab->wmi_ready = true;
5526d5c65159SKalle Valo 		break;
5527d5c65159SKalle Valo 	case WMI_TAG_ARRAY_FIXED_STRUCT:
5528d5c65159SKalle Valo 		addr_list = (struct wmi_mac_addr *)ptr;
5529d5c65159SKalle Valo 		num_mac_addr = rdy_parse->num_extra_mac_addr;
5530d5c65159SKalle Valo 
5531d5c65159SKalle Valo 		if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
5532d5c65159SKalle Valo 			break;
5533d5c65159SKalle Valo 
5534d5c65159SKalle Valo 		for (i = 0; i < ab->num_radios; i++) {
5535d5c65159SKalle Valo 			pdev = &ab->pdevs[i];
5536d5c65159SKalle Valo 			ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
5537d5c65159SKalle Valo 		}
5538d5c65159SKalle Valo 		ab->pdevs_macaddr_valid = true;
5539d5c65159SKalle Valo 		break;
5540d5c65159SKalle Valo 	default:
5541d5c65159SKalle Valo 		break;
5542d5c65159SKalle Valo 	}
5543d5c65159SKalle Valo 
5544d5c65159SKalle Valo 	return 0;
5545d5c65159SKalle Valo }
5546d5c65159SKalle Valo 
5547d5c65159SKalle Valo static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
5548d5c65159SKalle Valo {
5549d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse rdy_parse = { };
5550d5c65159SKalle Valo 	int ret;
5551d5c65159SKalle Valo 
5552d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
5553d5c65159SKalle Valo 				  ath11k_wmi_tlv_rdy_parse, &rdy_parse);
5554d5c65159SKalle Valo 	if (ret) {
5555d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
5556d5c65159SKalle Valo 		return ret;
5557d5c65159SKalle Valo 	}
5558d5c65159SKalle Valo 
55596bc9d6f7SJohn Crispin 	complete(&ab->wmi_ab.unified_ready);
5560d5c65159SKalle Valo 	return 0;
5561d5c65159SKalle Valo }
5562d5c65159SKalle Valo 
5563d5c65159SKalle Valo static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
5564d5c65159SKalle Valo {
5565d5c65159SKalle Valo 	struct wmi_peer_delete_resp_event peer_del_resp;
5566d5c65159SKalle Valo 
5567d5c65159SKalle Valo 	if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
5568d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer delete resp");
5569d5c65159SKalle Valo 		return;
5570d5c65159SKalle Valo 	}
5571d5c65159SKalle Valo 
5572d5c65159SKalle Valo 	/* TODO: Do we need to validate whether ath11k_peer_find() return NULL
5573d5c65159SKalle Valo 	 *	 Why this is needed when there is HTT event for peer delete
5574d5c65159SKalle Valo 	 */
5575d5c65159SKalle Valo }
5576d5c65159SKalle Valo 
5577d5c65159SKalle Valo static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
5578d5c65159SKalle Valo {
5579d5c65159SKalle Valo 	switch (vdev_resp_status) {
5580d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
5581d5c65159SKalle Valo 		return "invalid vdev id";
5582d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
5583d5c65159SKalle Valo 		return "not supported";
5584d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
5585d5c65159SKalle Valo 		return "dfs violation";
5586d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
5587d5c65159SKalle Valo 		return "invalid regdomain";
5588d5c65159SKalle Valo 	default:
5589d5c65159SKalle Valo 		return "unknown";
5590d5c65159SKalle Valo 	}
5591d5c65159SKalle Valo }
5592d5c65159SKalle Valo 
5593d5c65159SKalle Valo static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
5594d5c65159SKalle Valo {
5595d5c65159SKalle Valo 	struct wmi_vdev_start_resp_event vdev_start_resp;
5596d5c65159SKalle Valo 	struct ath11k *ar;
5597d5c65159SKalle Valo 	u32 status;
5598d5c65159SKalle Valo 
5599d5c65159SKalle Valo 	if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
5600d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev start resp");
5601d5c65159SKalle Valo 		return;
5602d5c65159SKalle Valo 	}
5603d5c65159SKalle Valo 
5604d5c65159SKalle Valo 	rcu_read_lock();
5605d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
5606d5c65159SKalle Valo 	if (!ar) {
5607d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
5608d5c65159SKalle Valo 			    vdev_start_resp.vdev_id);
5609d5c65159SKalle Valo 		rcu_read_unlock();
5610d5c65159SKalle Valo 		return;
5611d5c65159SKalle Valo 	}
5612d5c65159SKalle Valo 
5613d5c65159SKalle Valo 	ar->last_wmi_vdev_start_status = 0;
5614d5c65159SKalle Valo 
5615d5c65159SKalle Valo 	status = vdev_start_resp.status;
5616d5c65159SKalle Valo 
5617d5c65159SKalle Valo 	if (WARN_ON_ONCE(status)) {
5618d5c65159SKalle Valo 		ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
5619d5c65159SKalle Valo 			    status, ath11k_wmi_vdev_resp_print(status));
5620d5c65159SKalle Valo 		ar->last_wmi_vdev_start_status = status;
5621d5c65159SKalle Valo 	}
5622d5c65159SKalle Valo 
5623d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
5624d5c65159SKalle Valo 
5625d5c65159SKalle Valo 	rcu_read_unlock();
5626d5c65159SKalle Valo 
5627d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
5628d5c65159SKalle Valo 		   vdev_start_resp.vdev_id);
5629d5c65159SKalle Valo }
5630d5c65159SKalle Valo 
5631d5c65159SKalle Valo static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
5632d5c65159SKalle Valo {
5633d5c65159SKalle Valo 	u32 vdev_id, tx_status;
5634d5c65159SKalle Valo 
5635d5c65159SKalle Valo 	if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
5636d5c65159SKalle Valo 					 &vdev_id, &tx_status) != 0) {
5637d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract bcn tx status");
5638d5c65159SKalle Valo 		return;
5639d5c65159SKalle Valo 	}
5640d5c65159SKalle Valo }
5641d5c65159SKalle Valo 
5642d5c65159SKalle Valo static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
5643d5c65159SKalle Valo {
5644d5c65159SKalle Valo 	struct ath11k *ar;
5645d5c65159SKalle Valo 	u32 vdev_id = 0;
5646d5c65159SKalle Valo 
5647d5c65159SKalle Valo 	if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
5648d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev stopped event");
5649d5c65159SKalle Valo 		return;
5650d5c65159SKalle Valo 	}
5651d5c65159SKalle Valo 
5652d5c65159SKalle Valo 	rcu_read_lock();
5653d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_vdev_stop_status(ab, vdev_id);
5654d5c65159SKalle Valo 	if (!ar) {
5655d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
5656d5c65159SKalle Valo 			    vdev_id);
5657d5c65159SKalle Valo 		rcu_read_unlock();
5658d5c65159SKalle Valo 		return;
5659d5c65159SKalle Valo 	}
5660d5c65159SKalle Valo 
5661d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
5662d5c65159SKalle Valo 
5663d5c65159SKalle Valo 	rcu_read_unlock();
5664d5c65159SKalle Valo 
5665d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
5666d5c65159SKalle Valo }
5667d5c65159SKalle Valo 
5668d5c65159SKalle Valo static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
5669d5c65159SKalle Valo {
5670d5c65159SKalle Valo 	struct mgmt_rx_event_params rx_ev = {0};
5671d5c65159SKalle Valo 	struct ath11k *ar;
5672d5c65159SKalle Valo 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
5673d5c65159SKalle Valo 	struct ieee80211_hdr *hdr;
5674d5c65159SKalle Valo 	u16 fc;
5675d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
5676d5c65159SKalle Valo 
5677d5c65159SKalle Valo 	if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
5678d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt rx event");
5679d5c65159SKalle Valo 		dev_kfree_skb(skb);
5680d5c65159SKalle Valo 		return;
5681d5c65159SKalle Valo 	}
5682d5c65159SKalle Valo 
5683d5c65159SKalle Valo 	memset(status, 0, sizeof(*status));
5684d5c65159SKalle Valo 
5685d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n",
5686d5c65159SKalle Valo 		   rx_ev.status);
5687d5c65159SKalle Valo 
5688d5c65159SKalle Valo 	rcu_read_lock();
5689d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
5690d5c65159SKalle Valo 
5691d5c65159SKalle Valo 	if (!ar) {
5692d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
5693d5c65159SKalle Valo 			    rx_ev.pdev_id);
5694d5c65159SKalle Valo 		dev_kfree_skb(skb);
5695d5c65159SKalle Valo 		goto exit;
5696d5c65159SKalle Valo 	}
5697d5c65159SKalle Valo 
5698d5c65159SKalle Valo 	if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
5699d5c65159SKalle Valo 	    (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
5700d5c65159SKalle Valo 	    WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
5701d5c65159SKalle Valo 		dev_kfree_skb(skb);
5702d5c65159SKalle Valo 		goto exit;
5703d5c65159SKalle Valo 	}
5704d5c65159SKalle Valo 
5705d5c65159SKalle Valo 	if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
5706d5c65159SKalle Valo 		status->flag |= RX_FLAG_MMIC_ERROR;
5707d5c65159SKalle Valo 
57085dcf42f8SPradeep Kumar Chitrapu 	if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ) {
57095dcf42f8SPradeep Kumar Chitrapu 		status->band = NL80211_BAND_6GHZ;
57105dcf42f8SPradeep Kumar Chitrapu 	} else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
5711d5c65159SKalle Valo 		status->band = NL80211_BAND_2GHZ;
5712d5c65159SKalle Valo 	} else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
5713d5c65159SKalle Valo 		status->band = NL80211_BAND_5GHZ;
5714d5c65159SKalle Valo 	} else {
5715d5c65159SKalle Valo 		/* Shouldn't happen unless list of advertised channels to
5716d5c65159SKalle Valo 		 * mac80211 has been changed.
5717d5c65159SKalle Valo 		 */
5718d5c65159SKalle Valo 		WARN_ON_ONCE(1);
5719d5c65159SKalle Valo 		dev_kfree_skb(skb);
5720d5c65159SKalle Valo 		goto exit;
5721d5c65159SKalle Valo 	}
5722d5c65159SKalle Valo 
572322eeadcdSPradeep Kumar Chitrapu 	if (rx_ev.phy_mode == MODE_11B &&
572422eeadcdSPradeep Kumar Chitrapu 	    (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
5725d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
572622eeadcdSPradeep Kumar Chitrapu 			   "wmi mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
5727d5c65159SKalle Valo 
5728d5c65159SKalle Valo 	sband = &ar->mac.sbands[status->band];
5729d5c65159SKalle Valo 
5730d5c65159SKalle Valo 	status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
5731d5c65159SKalle Valo 						      status->band);
5732d5c65159SKalle Valo 	status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
5733d5c65159SKalle Valo 	status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
5734d5c65159SKalle Valo 
5735d5c65159SKalle Valo 	hdr = (struct ieee80211_hdr *)skb->data;
5736d5c65159SKalle Valo 	fc = le16_to_cpu(hdr->frame_control);
5737d5c65159SKalle Valo 
5738d5c65159SKalle Valo 	/* Firmware is guaranteed to report all essential management frames via
5739d5c65159SKalle Valo 	 * WMI while it can deliver some extra via HTT. Since there can be
5740d5c65159SKalle Valo 	 * duplicates split the reporting wrt monitor/sniffing.
5741d5c65159SKalle Valo 	 */
5742d5c65159SKalle Valo 	status->flag |= RX_FLAG_SKIP_MONITOR;
5743d5c65159SKalle Valo 
5744d5c65159SKalle Valo 	/* In case of PMF, FW delivers decrypted frames with Protected Bit set.
5745d5c65159SKalle Valo 	 * Don't clear that. Also, FW delivers broadcast management frames
5746d5c65159SKalle Valo 	 * (ex: group privacy action frames in mesh) as encrypted payload.
5747d5c65159SKalle Valo 	 */
5748d5c65159SKalle Valo 	if (ieee80211_has_protected(hdr->frame_control) &&
5749d5c65159SKalle Valo 	    !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
5750d5c65159SKalle Valo 		status->flag |= RX_FLAG_DECRYPTED;
5751d5c65159SKalle Valo 
5752d5c65159SKalle Valo 		if (!ieee80211_is_robust_mgmt_frame(skb)) {
5753d5c65159SKalle Valo 			status->flag |= RX_FLAG_IV_STRIPPED |
5754d5c65159SKalle Valo 					RX_FLAG_MMIC_STRIPPED;
5755d5c65159SKalle Valo 			hdr->frame_control = __cpu_to_le16(fc &
5756d5c65159SKalle Valo 					     ~IEEE80211_FCTL_PROTECTED);
5757d5c65159SKalle Valo 		}
5758d5c65159SKalle Valo 	}
5759d5c65159SKalle Valo 
5760d5c65159SKalle Valo 	/* TODO: Pending handle beacon implementation
5761d5c65159SKalle Valo 	 *if (ieee80211_is_beacon(hdr->frame_control))
5762d5c65159SKalle Valo 	 *	ath11k_mac_handle_beacon(ar, skb);
5763d5c65159SKalle Valo 	 */
5764d5c65159SKalle Valo 
5765d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
5766d5c65159SKalle Valo 		   "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
5767d5c65159SKalle Valo 		   skb, skb->len,
5768d5c65159SKalle Valo 		   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
5769d5c65159SKalle Valo 
5770d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
5771d5c65159SKalle Valo 		   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
5772d5c65159SKalle Valo 		   status->freq, status->band, status->signal,
5773d5c65159SKalle Valo 		   status->rate_idx);
5774d5c65159SKalle Valo 
5775d5c65159SKalle Valo 	ieee80211_rx_ni(ar->hw, skb);
5776d5c65159SKalle Valo 
5777d5c65159SKalle Valo exit:
5778d5c65159SKalle Valo 	rcu_read_unlock();
5779d5c65159SKalle Valo }
5780d5c65159SKalle Valo 
5781d5c65159SKalle Valo static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
5782d5c65159SKalle Valo {
5783d5c65159SKalle Valo 	struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
5784d5c65159SKalle Valo 	struct ath11k *ar;
5785d5c65159SKalle Valo 
5786d5c65159SKalle Valo 	if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
5787d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt tx compl event");
5788d5c65159SKalle Valo 		return;
5789d5c65159SKalle Valo 	}
5790d5c65159SKalle Valo 
5791d5c65159SKalle Valo 	rcu_read_lock();
5792d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
5793d5c65159SKalle Valo 	if (!ar) {
5794d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
5795d5c65159SKalle Valo 			    tx_compl_param.pdev_id);
5796d5c65159SKalle Valo 		goto exit;
5797d5c65159SKalle Valo 	}
5798d5c65159SKalle Valo 
5799d5c65159SKalle Valo 	wmi_process_mgmt_tx_comp(ar, tx_compl_param.desc_id,
5800d5c65159SKalle Valo 				 tx_compl_param.status);
5801d5c65159SKalle Valo 
5802d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
5803d5c65159SKalle Valo 		   "mgmt tx compl ev pdev_id %d, desc_id %d, status %d",
5804d5c65159SKalle Valo 		   tx_compl_param.pdev_id, tx_compl_param.desc_id,
5805d5c65159SKalle Valo 		   tx_compl_param.status);
5806d5c65159SKalle Valo 
5807d5c65159SKalle Valo exit:
5808d5c65159SKalle Valo 	rcu_read_unlock();
5809d5c65159SKalle Valo }
5810d5c65159SKalle Valo 
5811d5c65159SKalle Valo static struct ath11k *ath11k_get_ar_on_scan_abort(struct ath11k_base *ab,
5812d5c65159SKalle Valo 						  u32 vdev_id)
5813d5c65159SKalle Valo {
5814d5c65159SKalle Valo 	int i;
5815d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
5816d5c65159SKalle Valo 	struct ath11k *ar;
5817d5c65159SKalle Valo 
5818d5c65159SKalle Valo 	for (i = 0; i < ab->num_radios; i++) {
5819d5c65159SKalle Valo 		pdev = rcu_dereference(ab->pdevs_active[i]);
5820d5c65159SKalle Valo 		if (pdev && pdev->ar) {
5821d5c65159SKalle Valo 			ar = pdev->ar;
5822d5c65159SKalle Valo 
5823d5c65159SKalle Valo 			spin_lock_bh(&ar->data_lock);
5824d5c65159SKalle Valo 			if (ar->scan.state == ATH11K_SCAN_ABORTING &&
5825d5c65159SKalle Valo 			    ar->scan.vdev_id == vdev_id) {
5826d5c65159SKalle Valo 				spin_unlock_bh(&ar->data_lock);
5827d5c65159SKalle Valo 				return ar;
5828d5c65159SKalle Valo 			}
5829d5c65159SKalle Valo 			spin_unlock_bh(&ar->data_lock);
5830d5c65159SKalle Valo 		}
5831d5c65159SKalle Valo 	}
5832d5c65159SKalle Valo 	return NULL;
5833d5c65159SKalle Valo }
5834d5c65159SKalle Valo 
5835d5c65159SKalle Valo static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
5836d5c65159SKalle Valo {
5837d5c65159SKalle Valo 	struct ath11k *ar;
5838d5c65159SKalle Valo 	struct wmi_scan_event scan_ev = {0};
5839d5c65159SKalle Valo 
5840d5c65159SKalle Valo 	if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
5841d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract scan event");
5842d5c65159SKalle Valo 		return;
5843d5c65159SKalle Valo 	}
5844d5c65159SKalle Valo 
5845d5c65159SKalle Valo 	rcu_read_lock();
5846d5c65159SKalle Valo 
5847d5c65159SKalle Valo 	/* In case the scan was cancelled, ex. during interface teardown,
5848d5c65159SKalle Valo 	 * the interface will not be found in active interfaces.
5849d5c65159SKalle Valo 	 * Rather, in such scenarios, iterate over the active pdev's to
5850d5c65159SKalle Valo 	 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
5851d5c65159SKalle Valo 	 * aborting scan's vdev id matches this event info.
5852d5c65159SKalle Valo 	 */
5853d5c65159SKalle Valo 	if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
5854d5c65159SKalle Valo 	    scan_ev.reason == WMI_SCAN_REASON_CANCELLED)
5855d5c65159SKalle Valo 		ar = ath11k_get_ar_on_scan_abort(ab, scan_ev.vdev_id);
5856d5c65159SKalle Valo 	else
5857d5c65159SKalle Valo 		ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
5858d5c65159SKalle Valo 
5859d5c65159SKalle Valo 	if (!ar) {
5860d5c65159SKalle Valo 		ath11k_warn(ab, "Received scan event for unknown vdev");
5861d5c65159SKalle Valo 		rcu_read_unlock();
5862d5c65159SKalle Valo 		return;
5863d5c65159SKalle Valo 	}
5864d5c65159SKalle Valo 
5865d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
5866d5c65159SKalle Valo 
5867d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5868d5c65159SKalle Valo 		   "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
5869d5c65159SKalle Valo 		   ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
5870d5c65159SKalle Valo 		   scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
5871d5c65159SKalle Valo 		   scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
5872d5c65159SKalle Valo 		   ath11k_scan_state_str(ar->scan.state), ar->scan.state);
5873d5c65159SKalle Valo 
5874d5c65159SKalle Valo 	switch (scan_ev.event_type) {
5875d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
5876d5c65159SKalle Valo 		ath11k_wmi_event_scan_started(ar);
5877d5c65159SKalle Valo 		break;
5878d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
5879d5c65159SKalle Valo 		ath11k_wmi_event_scan_completed(ar);
5880d5c65159SKalle Valo 		break;
5881d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
5882d5c65159SKalle Valo 		ath11k_wmi_event_scan_bss_chan(ar);
5883d5c65159SKalle Valo 		break;
5884d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
5885d5c65159SKalle Valo 		ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
5886d5c65159SKalle Valo 		break;
5887d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
5888d5c65159SKalle Valo 		ath11k_warn(ab, "received scan start failure event\n");
5889d5c65159SKalle Valo 		ath11k_wmi_event_scan_start_failed(ar);
5890d5c65159SKalle Valo 		break;
5891d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
5892d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
5893d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
5894d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
5895d5c65159SKalle Valo 	default:
5896d5c65159SKalle Valo 		break;
5897d5c65159SKalle Valo 	}
5898d5c65159SKalle Valo 
5899d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
5900d5c65159SKalle Valo 
5901d5c65159SKalle Valo 	rcu_read_unlock();
5902d5c65159SKalle Valo }
5903d5c65159SKalle Valo 
5904d5c65159SKalle Valo static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
5905d5c65159SKalle Valo {
5906d5c65159SKalle Valo 	struct wmi_peer_sta_kickout_arg arg = {};
5907d5c65159SKalle Valo 	struct ieee80211_sta *sta;
5908d5c65159SKalle Valo 	struct ath11k_peer *peer;
5909d5c65159SKalle Valo 	struct ath11k *ar;
5910d5c65159SKalle Valo 
5911d5c65159SKalle Valo 	if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
5912d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer sta kickout event");
5913d5c65159SKalle Valo 		return;
5914d5c65159SKalle Valo 	}
5915d5c65159SKalle Valo 
5916d5c65159SKalle Valo 	rcu_read_lock();
5917d5c65159SKalle Valo 
5918d5c65159SKalle Valo 	spin_lock_bh(&ab->base_lock);
5919d5c65159SKalle Valo 
5920d5c65159SKalle Valo 	peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
5921d5c65159SKalle Valo 
5922d5c65159SKalle Valo 	if (!peer) {
5923d5c65159SKalle Valo 		ath11k_warn(ab, "peer not found %pM\n",
5924d5c65159SKalle Valo 			    arg.mac_addr);
5925d5c65159SKalle Valo 		goto exit;
5926d5c65159SKalle Valo 	}
5927d5c65159SKalle Valo 
5928d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id);
5929d5c65159SKalle Valo 	if (!ar) {
5930d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
5931d5c65159SKalle Valo 			    peer->vdev_id);
5932d5c65159SKalle Valo 		goto exit;
5933d5c65159SKalle Valo 	}
5934d5c65159SKalle Valo 
5935d5c65159SKalle Valo 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5936d5c65159SKalle Valo 					   arg.mac_addr, NULL);
5937d5c65159SKalle Valo 	if (!sta) {
5938d5c65159SKalle Valo 		ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
5939d5c65159SKalle Valo 			    arg.mac_addr);
5940d5c65159SKalle Valo 		goto exit;
5941d5c65159SKalle Valo 	}
5942d5c65159SKalle Valo 
5943d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM",
5944d5c65159SKalle Valo 		   arg.mac_addr);
5945d5c65159SKalle Valo 
5946d5c65159SKalle Valo 	ieee80211_report_low_ack(sta, 10);
5947d5c65159SKalle Valo 
5948d5c65159SKalle Valo exit:
5949d5c65159SKalle Valo 	spin_unlock_bh(&ab->base_lock);
5950d5c65159SKalle Valo 	rcu_read_unlock();
5951d5c65159SKalle Valo }
5952d5c65159SKalle Valo 
5953d5c65159SKalle Valo static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
5954d5c65159SKalle Valo {
5955d5c65159SKalle Valo 	struct wmi_roam_event roam_ev = {};
5956d5c65159SKalle Valo 	struct ath11k *ar;
5957d5c65159SKalle Valo 
5958d5c65159SKalle Valo 	if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
5959d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract roam event");
5960d5c65159SKalle Valo 		return;
5961d5c65159SKalle Valo 	}
5962d5c65159SKalle Valo 
5963d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5964d5c65159SKalle Valo 		   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
5965d5c65159SKalle Valo 		   roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
5966d5c65159SKalle Valo 
5967d5c65159SKalle Valo 	rcu_read_lock();
5968d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
5969d5c65159SKalle Valo 	if (!ar) {
5970d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in roam ev %d",
5971d5c65159SKalle Valo 			    roam_ev.vdev_id);
5972d5c65159SKalle Valo 		rcu_read_unlock();
5973d5c65159SKalle Valo 		return;
5974d5c65159SKalle Valo 	}
5975d5c65159SKalle Valo 
5976d5c65159SKalle Valo 	if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
5977d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
5978d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
5979d5c65159SKalle Valo 
5980d5c65159SKalle Valo 	switch (roam_ev.reason) {
5981d5c65159SKalle Valo 	case WMI_ROAM_REASON_BEACON_MISS:
5982d5c65159SKalle Valo 		/* TODO: Pending beacon miss and connection_loss_work
5983d5c65159SKalle Valo 		 * implementation
5984d5c65159SKalle Valo 		 * ath11k_mac_handle_beacon_miss(ar, vdev_id);
5985d5c65159SKalle Valo 		 */
5986d5c65159SKalle Valo 		break;
5987d5c65159SKalle Valo 	case WMI_ROAM_REASON_BETTER_AP:
5988d5c65159SKalle Valo 	case WMI_ROAM_REASON_LOW_RSSI:
5989d5c65159SKalle Valo 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
5990d5c65159SKalle Valo 	case WMI_ROAM_REASON_HO_FAILED:
5991d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
5992d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
5993d5c65159SKalle Valo 		break;
5994d5c65159SKalle Valo 	}
5995d5c65159SKalle Valo 
5996d5c65159SKalle Valo 	rcu_read_unlock();
5997d5c65159SKalle Valo }
5998d5c65159SKalle Valo 
5999d5c65159SKalle Valo static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
6000d5c65159SKalle Valo {
6001d5c65159SKalle Valo 	struct wmi_chan_info_event ch_info_ev = {0};
6002d5c65159SKalle Valo 	struct ath11k *ar;
6003d5c65159SKalle Valo 	struct survey_info *survey;
6004d5c65159SKalle Valo 	int idx;
6005d5c65159SKalle Valo 	/* HW channel counters frequency value in hertz */
6006d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
6007d5c65159SKalle Valo 
6008d5c65159SKalle Valo 	if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
6009d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract chan info event");
6010d5c65159SKalle Valo 		return;
6011d5c65159SKalle Valo 	}
6012d5c65159SKalle Valo 
6013d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6014d5c65159SKalle 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",
6015d5c65159SKalle Valo 		   ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
6016d5c65159SKalle Valo 		   ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
6017d5c65159SKalle Valo 		   ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
6018d5c65159SKalle Valo 		   ch_info_ev.mac_clk_mhz);
6019d5c65159SKalle Valo 
6020d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
6021d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
6022d5c65159SKalle Valo 		return;
6023d5c65159SKalle Valo 	}
6024d5c65159SKalle Valo 
6025d5c65159SKalle Valo 	rcu_read_lock();
6026d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
6027d5c65159SKalle Valo 	if (!ar) {
6028d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in chan info ev %d",
6029d5c65159SKalle Valo 			    ch_info_ev.vdev_id);
6030d5c65159SKalle Valo 		rcu_read_unlock();
6031d5c65159SKalle Valo 		return;
6032d5c65159SKalle Valo 	}
6033d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
6034d5c65159SKalle Valo 
6035d5c65159SKalle Valo 	switch (ar->scan.state) {
6036d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
6037d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
6038d5c65159SKalle Valo 		ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
6039d5c65159SKalle Valo 		goto exit;
6040d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
6041d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
6042d5c65159SKalle Valo 		break;
6043d5c65159SKalle Valo 	}
6044d5c65159SKalle Valo 
6045d5c65159SKalle Valo 	idx = freq_to_idx(ar, ch_info_ev.freq);
6046d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
6047d5c65159SKalle Valo 		ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
6048d5c65159SKalle Valo 			    ch_info_ev.freq, idx);
6049d5c65159SKalle Valo 		goto exit;
6050d5c65159SKalle Valo 	}
6051d5c65159SKalle Valo 
6052d5c65159SKalle Valo 	/* If FW provides MAC clock frequency in Mhz, overriding the initialized
6053d5c65159SKalle Valo 	 * HW channel counters frequency value
6054d5c65159SKalle Valo 	 */
6055d5c65159SKalle Valo 	if (ch_info_ev.mac_clk_mhz)
6056d5c65159SKalle Valo 		cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
6057d5c65159SKalle Valo 
6058d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
6059d5c65159SKalle Valo 		survey = &ar->survey[idx];
6060d5c65159SKalle Valo 		memset(survey, 0, sizeof(*survey));
6061d5c65159SKalle Valo 		survey->noise = ch_info_ev.noise_floor;
6062d5c65159SKalle Valo 		survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
6063d5c65159SKalle Valo 				 SURVEY_INFO_TIME_BUSY;
6064d5c65159SKalle Valo 		survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
6065d5c65159SKalle Valo 		survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
6066d5c65159SKalle Valo 	}
6067d5c65159SKalle Valo exit:
6068d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
6069d5c65159SKalle Valo 	rcu_read_unlock();
6070d5c65159SKalle Valo }
6071d5c65159SKalle Valo 
6072d5c65159SKalle Valo static void
6073d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
6074d5c65159SKalle Valo {
6075d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
6076d5c65159SKalle Valo 	struct survey_info *survey;
6077d5c65159SKalle Valo 	struct ath11k *ar;
6078d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
6079d5c65159SKalle Valo 	u64 busy, total, tx, rx, rx_bss;
6080d5c65159SKalle Valo 	int idx;
6081d5c65159SKalle Valo 
6082d5c65159SKalle Valo 	if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
6083d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract pdev bss chan info event");
6084d5c65159SKalle Valo 		return;
6085d5c65159SKalle Valo 	}
6086d5c65159SKalle Valo 
6087d5c65159SKalle Valo 	busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
6088d5c65159SKalle Valo 			bss_ch_info_ev.rx_clear_count_low;
6089d5c65159SKalle Valo 
6090d5c65159SKalle Valo 	total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
6091d5c65159SKalle Valo 			bss_ch_info_ev.cycle_count_low;
6092d5c65159SKalle Valo 
6093d5c65159SKalle Valo 	tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
6094d5c65159SKalle Valo 			bss_ch_info_ev.tx_cycle_count_low;
6095d5c65159SKalle Valo 
6096d5c65159SKalle Valo 	rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
6097d5c65159SKalle Valo 			bss_ch_info_ev.rx_cycle_count_low;
6098d5c65159SKalle Valo 
6099d5c65159SKalle Valo 	rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
6100d5c65159SKalle Valo 			bss_ch_info_ev.rx_bss_cycle_count_low;
6101d5c65159SKalle Valo 
6102d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6103d5c65159SKalle 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",
6104d5c65159SKalle Valo 		   bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
6105d5c65159SKalle Valo 		   bss_ch_info_ev.noise_floor, busy, total,
6106d5c65159SKalle Valo 		   tx, rx, rx_bss);
6107d5c65159SKalle Valo 
6108d5c65159SKalle Valo 	rcu_read_lock();
6109d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
6110d5c65159SKalle Valo 
6111d5c65159SKalle Valo 	if (!ar) {
6112d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
6113d5c65159SKalle Valo 			    bss_ch_info_ev.pdev_id);
6114d5c65159SKalle Valo 		rcu_read_unlock();
6115d5c65159SKalle Valo 		return;
6116d5c65159SKalle Valo 	}
6117d5c65159SKalle Valo 
6118d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
6119d5c65159SKalle Valo 	idx = freq_to_idx(ar, bss_ch_info_ev.freq);
6120d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
6121d5c65159SKalle Valo 		ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
6122d5c65159SKalle Valo 			    bss_ch_info_ev.freq, idx);
6123d5c65159SKalle Valo 		goto exit;
6124d5c65159SKalle Valo 	}
6125d5c65159SKalle Valo 
6126d5c65159SKalle Valo 	survey = &ar->survey[idx];
6127d5c65159SKalle Valo 
6128d5c65159SKalle Valo 	survey->noise     = bss_ch_info_ev.noise_floor;
6129d5c65159SKalle Valo 	survey->time      = div_u64(total, cc_freq_hz);
6130d5c65159SKalle Valo 	survey->time_busy = div_u64(busy, cc_freq_hz);
6131d5c65159SKalle Valo 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
6132d5c65159SKalle Valo 	survey->time_tx   = div_u64(tx, cc_freq_hz);
6133d5c65159SKalle Valo 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
6134d5c65159SKalle Valo 			     SURVEY_INFO_TIME |
6135d5c65159SKalle Valo 			     SURVEY_INFO_TIME_BUSY |
6136d5c65159SKalle Valo 			     SURVEY_INFO_TIME_RX |
6137d5c65159SKalle Valo 			     SURVEY_INFO_TIME_TX);
6138d5c65159SKalle Valo exit:
6139d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
6140d5c65159SKalle Valo 	complete(&ar->bss_survey_done);
6141d5c65159SKalle Valo 
6142d5c65159SKalle Valo 	rcu_read_unlock();
6143d5c65159SKalle Valo }
6144d5c65159SKalle Valo 
6145d5c65159SKalle Valo static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
6146d5c65159SKalle Valo 						struct sk_buff *skb)
6147d5c65159SKalle Valo {
6148d5c65159SKalle Valo 	struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
6149d5c65159SKalle Valo 	struct ath11k *ar;
6150d5c65159SKalle Valo 
6151d5c65159SKalle Valo 	if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
6152d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract install key compl event");
6153d5c65159SKalle Valo 		return;
6154d5c65159SKalle Valo 	}
6155d5c65159SKalle Valo 
6156d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6157d5c65159SKalle Valo 		   "vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
6158d5c65159SKalle Valo 		   install_key_compl.key_idx, install_key_compl.key_flags,
6159d5c65159SKalle Valo 		   install_key_compl.macaddr, install_key_compl.status);
6160d5c65159SKalle Valo 
6161d5c65159SKalle Valo 	rcu_read_lock();
6162d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
6163d5c65159SKalle Valo 	if (!ar) {
6164d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
6165d5c65159SKalle Valo 			    install_key_compl.vdev_id);
6166d5c65159SKalle Valo 		rcu_read_unlock();
6167d5c65159SKalle Valo 		return;
6168d5c65159SKalle Valo 	}
6169d5c65159SKalle Valo 
6170d5c65159SKalle Valo 	ar->install_key_status = 0;
6171d5c65159SKalle Valo 
6172d5c65159SKalle Valo 	if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
6173d5c65159SKalle Valo 		ath11k_warn(ab, "install key failed for %pM status %d\n",
6174d5c65159SKalle Valo 			    install_key_compl.macaddr, install_key_compl.status);
6175d5c65159SKalle Valo 		ar->install_key_status = install_key_compl.status;
6176d5c65159SKalle Valo 	}
6177d5c65159SKalle Valo 
6178d5c65159SKalle Valo 	complete(&ar->install_key_done);
6179d5c65159SKalle Valo 	rcu_read_unlock();
6180d5c65159SKalle Valo }
6181d5c65159SKalle Valo 
6182d5c65159SKalle Valo static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
6183d5c65159SKalle Valo {
6184d5c65159SKalle Valo 	const void **tb;
6185d5c65159SKalle Valo 	const struct wmi_service_available_event *ev;
6186d5c65159SKalle Valo 	int ret;
6187d5c65159SKalle Valo 	int i, j;
6188d5c65159SKalle Valo 
6189d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6190d5c65159SKalle Valo 	if (IS_ERR(tb)) {
6191d5c65159SKalle Valo 		ret = PTR_ERR(tb);
6192d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6193d5c65159SKalle Valo 		return;
6194d5c65159SKalle Valo 	}
6195d5c65159SKalle Valo 
6196d5c65159SKalle Valo 	ev = tb[WMI_TAG_SERVICE_AVAILABLE_EVENT];
6197d5c65159SKalle Valo 	if (!ev) {
6198d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch svc available ev");
6199d5c65159SKalle Valo 		kfree(tb);
6200d5c65159SKalle Valo 		return;
6201d5c65159SKalle Valo 	}
6202d5c65159SKalle Valo 
6203d5c65159SKalle Valo 	/* TODO: Use wmi_service_segment_offset information to get the service
6204d5c65159SKalle Valo 	 * especially when more services are advertised in multiple sevice
6205d5c65159SKalle Valo 	 * available events.
6206d5c65159SKalle Valo 	 */
6207d5c65159SKalle Valo 	for (i = 0, j = WMI_MAX_SERVICE;
6208d5c65159SKalle Valo 	     i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
6209d5c65159SKalle Valo 	     i++) {
6210d5c65159SKalle Valo 		do {
6211d5c65159SKalle Valo 			if (ev->wmi_service_segment_bitmap[i] &
6212d5c65159SKalle Valo 			    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
62136bc9d6f7SJohn Crispin 				set_bit(j, ab->wmi_ab.svc_map);
6214d5c65159SKalle Valo 		} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
6215d5c65159SKalle Valo 	}
6216d5c65159SKalle Valo 
6217d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6218d5c65159SKalle Valo 		   "wmi_ext_service_bitmap 0:0x%x, 1:0x%x, 2:0x%x, 3:0x%x",
6219d5c65159SKalle Valo 		   ev->wmi_service_segment_bitmap[0], ev->wmi_service_segment_bitmap[1],
6220d5c65159SKalle Valo 		   ev->wmi_service_segment_bitmap[2], ev->wmi_service_segment_bitmap[3]);
6221d5c65159SKalle Valo 
6222d5c65159SKalle Valo 	kfree(tb);
6223d5c65159SKalle Valo }
6224d5c65159SKalle Valo 
6225d5c65159SKalle Valo static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
6226d5c65159SKalle Valo {
6227d5c65159SKalle Valo 	struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
6228d5c65159SKalle Valo 	struct ath11k *ar;
6229d5c65159SKalle Valo 
6230d5c65159SKalle Valo 	if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
6231d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer assoc conf event");
6232d5c65159SKalle Valo 		return;
6233d5c65159SKalle Valo 	}
6234d5c65159SKalle Valo 
6235d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6236d5c65159SKalle Valo 		   "peer assoc conf ev vdev id %d macaddr %pM\n",
6237d5c65159SKalle Valo 		   peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
6238d5c65159SKalle Valo 
6239db0889abSKarthikeyan Periyasamy 	rcu_read_lock();
6240d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
6241d5c65159SKalle Valo 
6242d5c65159SKalle Valo 	if (!ar) {
6243d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
6244d5c65159SKalle Valo 			    peer_assoc_conf.vdev_id);
6245db0889abSKarthikeyan Periyasamy 		rcu_read_unlock();
6246d5c65159SKalle Valo 		return;
6247d5c65159SKalle Valo 	}
6248d5c65159SKalle Valo 
6249d5c65159SKalle Valo 	complete(&ar->peer_assoc_done);
6250db0889abSKarthikeyan Periyasamy 	rcu_read_unlock();
6251d5c65159SKalle Valo }
6252d5c65159SKalle Valo 
6253d5c65159SKalle Valo static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
6254d5c65159SKalle Valo {
6255cb4e57dbSKalle Valo 	ath11k_debugfs_fw_stats_process(ab, skb);
6256d5c65159SKalle Valo }
6257d5c65159SKalle Valo 
6258d5c65159SKalle Valo /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
6259d5c65159SKalle Valo  * is not part of BDF CTL(Conformance test limits) table entries.
6260d5c65159SKalle Valo  */
6261d5c65159SKalle Valo static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
6262d5c65159SKalle Valo 						 struct sk_buff *skb)
6263d5c65159SKalle Valo {
6264d5c65159SKalle Valo 	const void **tb;
6265d5c65159SKalle Valo 	const struct wmi_pdev_ctl_failsafe_chk_event *ev;
6266d5c65159SKalle Valo 	int ret;
6267d5c65159SKalle Valo 
6268d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6269d5c65159SKalle Valo 	if (IS_ERR(tb)) {
6270d5c65159SKalle Valo 		ret = PTR_ERR(tb);
6271d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6272d5c65159SKalle Valo 		return;
6273d5c65159SKalle Valo 	}
6274d5c65159SKalle Valo 
6275d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
6276d5c65159SKalle Valo 	if (!ev) {
6277d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
6278d5c65159SKalle Valo 		kfree(tb);
6279d5c65159SKalle Valo 		return;
6280d5c65159SKalle Valo 	}
6281d5c65159SKalle Valo 
6282d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6283d5c65159SKalle Valo 		   "pdev ctl failsafe check ev status %d\n",
6284d5c65159SKalle Valo 		   ev->ctl_failsafe_status);
6285d5c65159SKalle Valo 
6286d5c65159SKalle Valo 	/* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
6287d5c65159SKalle Valo 	 * to 10 dBm else the CTL power entry in the BDF would be picked up.
6288d5c65159SKalle Valo 	 */
6289d5c65159SKalle Valo 	if (ev->ctl_failsafe_status != 0)
6290d5c65159SKalle Valo 		ath11k_warn(ab, "pdev ctl failsafe failure status %d",
6291d5c65159SKalle Valo 			    ev->ctl_failsafe_status);
6292d5c65159SKalle Valo 
6293d5c65159SKalle Valo 	kfree(tb);
6294d5c65159SKalle Valo }
6295d5c65159SKalle Valo 
6296d5c65159SKalle Valo static void
6297d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
6298d5c65159SKalle Valo 					  const struct wmi_pdev_csa_switch_ev *ev,
6299d5c65159SKalle Valo 					  const u32 *vdev_ids)
6300d5c65159SKalle Valo {
6301d5c65159SKalle Valo 	int i;
6302d5c65159SKalle Valo 	struct ath11k_vif *arvif;
6303d5c65159SKalle Valo 
6304d5c65159SKalle Valo 	/* Finish CSA once the switch count becomes NULL */
6305d5c65159SKalle Valo 	if (ev->current_switch_count)
6306d5c65159SKalle Valo 		return;
6307d5c65159SKalle Valo 
6308d5c65159SKalle Valo 	rcu_read_lock();
6309d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdevs; i++) {
6310d5c65159SKalle Valo 		arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
6311d5c65159SKalle Valo 
6312d5c65159SKalle Valo 		if (!arvif) {
6313d5c65159SKalle Valo 			ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
6314d5c65159SKalle Valo 				    vdev_ids[i]);
6315d5c65159SKalle Valo 			continue;
6316d5c65159SKalle Valo 		}
6317d5c65159SKalle Valo 
6318d5c65159SKalle Valo 		if (arvif->is_up && arvif->vif->csa_active)
6319d5c65159SKalle Valo 			ieee80211_csa_finish(arvif->vif);
6320d5c65159SKalle Valo 	}
6321d5c65159SKalle Valo 	rcu_read_unlock();
6322d5c65159SKalle Valo }
6323d5c65159SKalle Valo 
6324d5c65159SKalle Valo static void
6325d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
6326d5c65159SKalle Valo 					      struct sk_buff *skb)
6327d5c65159SKalle Valo {
6328d5c65159SKalle Valo 	const void **tb;
6329d5c65159SKalle Valo 	const struct wmi_pdev_csa_switch_ev *ev;
6330d5c65159SKalle Valo 	const u32 *vdev_ids;
6331d5c65159SKalle Valo 	int ret;
6332d5c65159SKalle Valo 
6333d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6334d5c65159SKalle Valo 	if (IS_ERR(tb)) {
6335d5c65159SKalle Valo 		ret = PTR_ERR(tb);
6336d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6337d5c65159SKalle Valo 		return;
6338d5c65159SKalle Valo 	}
6339d5c65159SKalle Valo 
6340d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
6341d5c65159SKalle Valo 	vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
6342d5c65159SKalle Valo 
6343d5c65159SKalle Valo 	if (!ev || !vdev_ids) {
6344d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
6345d5c65159SKalle Valo 		kfree(tb);
6346d5c65159SKalle Valo 		return;
6347d5c65159SKalle Valo 	}
6348d5c65159SKalle Valo 
6349d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6350d5c65159SKalle Valo 		   "pdev csa switch count %d for pdev %d, num_vdevs %d",
6351d5c65159SKalle Valo 		   ev->current_switch_count, ev->pdev_id,
6352d5c65159SKalle Valo 		   ev->num_vdevs);
6353d5c65159SKalle Valo 
6354d5c65159SKalle Valo 	ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
6355d5c65159SKalle Valo 
6356d5c65159SKalle Valo 	kfree(tb);
6357d5c65159SKalle Valo }
6358d5c65159SKalle Valo 
6359d5c65159SKalle Valo static void
6360d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
6361d5c65159SKalle Valo {
6362d5c65159SKalle Valo 	const void **tb;
6363d5c65159SKalle Valo 	const struct wmi_pdev_radar_ev *ev;
6364d5c65159SKalle Valo 	struct ath11k *ar;
6365d5c65159SKalle Valo 	int ret;
6366d5c65159SKalle Valo 
6367d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6368d5c65159SKalle Valo 	if (IS_ERR(tb)) {
6369d5c65159SKalle Valo 		ret = PTR_ERR(tb);
6370d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6371d5c65159SKalle Valo 		return;
6372d5c65159SKalle Valo 	}
6373d5c65159SKalle Valo 
6374d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
6375d5c65159SKalle Valo 
6376d5c65159SKalle Valo 	if (!ev) {
6377d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
6378d5c65159SKalle Valo 		kfree(tb);
6379d5c65159SKalle Valo 		return;
6380d5c65159SKalle Valo 	}
6381d5c65159SKalle Valo 
6382d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6383d5c65159SKalle 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",
6384d5c65159SKalle Valo 		   ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
6385d5c65159SKalle Valo 		   ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
6386d5c65159SKalle Valo 		   ev->freq_offset, ev->sidx);
6387d5c65159SKalle Valo 
6388d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6389d5c65159SKalle Valo 
6390d5c65159SKalle Valo 	if (!ar) {
6391d5c65159SKalle Valo 		ath11k_warn(ab, "radar detected in invalid pdev %d\n",
6392d5c65159SKalle Valo 			    ev->pdev_id);
6393d5c65159SKalle Valo 		goto exit;
6394d5c65159SKalle Valo 	}
6395d5c65159SKalle Valo 
6396d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
6397d5c65159SKalle Valo 		   ev->pdev_id);
6398d5c65159SKalle Valo 
6399d5c65159SKalle Valo 	if (ar->dfs_block_radar_events)
6400d5c65159SKalle Valo 		ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
6401d5c65159SKalle Valo 	else
6402d5c65159SKalle Valo 		ieee80211_radar_detected(ar->hw);
6403d5c65159SKalle Valo 
6404d5c65159SKalle Valo exit:
6405d5c65159SKalle Valo 	kfree(tb);
6406d5c65159SKalle Valo }
6407d5c65159SKalle Valo 
6408a41d1034SPradeep Kumar Chitrapu static void
6409a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
6410a41d1034SPradeep Kumar Chitrapu 				  struct sk_buff *skb)
6411a41d1034SPradeep Kumar Chitrapu {
6412a41d1034SPradeep Kumar Chitrapu 	struct ath11k *ar;
6413a41d1034SPradeep Kumar Chitrapu 	struct wmi_pdev_temperature_event ev = {0};
6414a41d1034SPradeep Kumar Chitrapu 
6415a41d1034SPradeep Kumar Chitrapu 	if (ath11k_pull_pdev_temp_ev(ab, skb->data, skb->len, &ev) != 0) {
6416a41d1034SPradeep Kumar Chitrapu 		ath11k_warn(ab, "failed to extract pdev temperature event");
6417a41d1034SPradeep Kumar Chitrapu 		return;
6418a41d1034SPradeep Kumar Chitrapu 	}
6419a41d1034SPradeep Kumar Chitrapu 
6420a41d1034SPradeep Kumar Chitrapu 	ath11k_dbg(ab, ATH11K_DBG_WMI,
6421a41d1034SPradeep Kumar Chitrapu 		   "pdev temperature ev temp %d pdev_id %d\n", ev.temp, ev.pdev_id);
6422a41d1034SPradeep Kumar Chitrapu 
6423a41d1034SPradeep Kumar Chitrapu 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev.pdev_id);
6424a41d1034SPradeep Kumar Chitrapu 	if (!ar) {
6425a41d1034SPradeep Kumar Chitrapu 		ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev.pdev_id);
6426a41d1034SPradeep Kumar Chitrapu 		return;
6427a41d1034SPradeep Kumar Chitrapu 	}
6428a41d1034SPradeep Kumar Chitrapu 
6429a41d1034SPradeep Kumar Chitrapu 	ath11k_thermal_event_temperature(ar, ev.temp);
6430a41d1034SPradeep Kumar Chitrapu }
6431a41d1034SPradeep Kumar Chitrapu 
6432d5c65159SKalle Valo static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
6433d5c65159SKalle Valo {
6434d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
6435d5c65159SKalle Valo 	enum wmi_tlv_event_id id;
6436d5c65159SKalle Valo 
6437d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
6438d5c65159SKalle Valo 	id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
6439d5c65159SKalle Valo 
6440d5c65159SKalle Valo 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
6441d5c65159SKalle Valo 		goto out;
6442d5c65159SKalle Valo 
6443d5c65159SKalle Valo 	switch (id) {
6444d5c65159SKalle Valo 		/* Process all the WMI events here */
6445d5c65159SKalle Valo 	case WMI_SERVICE_READY_EVENTID:
6446d5c65159SKalle Valo 		ath11k_service_ready_event(ab, skb);
6447d5c65159SKalle Valo 		break;
6448d5c65159SKalle Valo 	case WMI_SERVICE_READY_EXT_EVENTID:
6449d5c65159SKalle Valo 		ath11k_service_ready_ext_event(ab, skb);
6450d5c65159SKalle Valo 		break;
6451bd647855SKarthikeyan Periyasamy 	case WMI_SERVICE_READY_EXT2_EVENTID:
6452bd647855SKarthikeyan Periyasamy 		ath11k_service_ready_ext2_event(ab, skb);
6453bd647855SKarthikeyan Periyasamy 		break;
6454d5c65159SKalle Valo 	case WMI_REG_CHAN_LIST_CC_EVENTID:
6455d5c65159SKalle Valo 		ath11k_reg_chan_list_event(ab, skb);
6456d5c65159SKalle Valo 		break;
6457d5c65159SKalle Valo 	case WMI_READY_EVENTID:
6458d5c65159SKalle Valo 		ath11k_ready_event(ab, skb);
6459d5c65159SKalle Valo 		break;
6460d5c65159SKalle Valo 	case WMI_PEER_DELETE_RESP_EVENTID:
6461d5c65159SKalle Valo 		ath11k_peer_delete_resp_event(ab, skb);
6462d5c65159SKalle Valo 		break;
6463d5c65159SKalle Valo 	case WMI_VDEV_START_RESP_EVENTID:
6464d5c65159SKalle Valo 		ath11k_vdev_start_resp_event(ab, skb);
6465d5c65159SKalle Valo 		break;
6466d5c65159SKalle Valo 	case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
6467d5c65159SKalle Valo 		ath11k_bcn_tx_status_event(ab, skb);
6468d5c65159SKalle Valo 		break;
6469d5c65159SKalle Valo 	case WMI_VDEV_STOPPED_EVENTID:
6470d5c65159SKalle Valo 		ath11k_vdev_stopped_event(ab, skb);
6471d5c65159SKalle Valo 		break;
6472d5c65159SKalle Valo 	case WMI_MGMT_RX_EVENTID:
6473d5c65159SKalle Valo 		ath11k_mgmt_rx_event(ab, skb);
6474d5c65159SKalle Valo 		/* mgmt_rx_event() owns the skb now! */
6475d5c65159SKalle Valo 		return;
6476d5c65159SKalle Valo 	case WMI_MGMT_TX_COMPLETION_EVENTID:
6477d5c65159SKalle Valo 		ath11k_mgmt_tx_compl_event(ab, skb);
6478d5c65159SKalle Valo 		break;
6479d5c65159SKalle Valo 	case WMI_SCAN_EVENTID:
6480d5c65159SKalle Valo 		ath11k_scan_event(ab, skb);
6481d5c65159SKalle Valo 		break;
6482d5c65159SKalle Valo 	case WMI_PEER_STA_KICKOUT_EVENTID:
6483d5c65159SKalle Valo 		ath11k_peer_sta_kickout_event(ab, skb);
6484d5c65159SKalle Valo 		break;
6485d5c65159SKalle Valo 	case WMI_ROAM_EVENTID:
6486d5c65159SKalle Valo 		ath11k_roam_event(ab, skb);
6487d5c65159SKalle Valo 		break;
6488d5c65159SKalle Valo 	case WMI_CHAN_INFO_EVENTID:
6489d5c65159SKalle Valo 		ath11k_chan_info_event(ab, skb);
6490d5c65159SKalle Valo 		break;
6491d5c65159SKalle Valo 	case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
6492d5c65159SKalle Valo 		ath11k_pdev_bss_chan_info_event(ab, skb);
6493d5c65159SKalle Valo 		break;
6494d5c65159SKalle Valo 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
6495d5c65159SKalle Valo 		ath11k_vdev_install_key_compl_event(ab, skb);
6496d5c65159SKalle Valo 		break;
6497d5c65159SKalle Valo 	case WMI_SERVICE_AVAILABLE_EVENTID:
6498d5c65159SKalle Valo 		ath11k_service_available_event(ab, skb);
6499d5c65159SKalle Valo 		break;
6500d5c65159SKalle Valo 	case WMI_PEER_ASSOC_CONF_EVENTID:
6501d5c65159SKalle Valo 		ath11k_peer_assoc_conf_event(ab, skb);
6502d5c65159SKalle Valo 		break;
6503d5c65159SKalle Valo 	case WMI_UPDATE_STATS_EVENTID:
6504d5c65159SKalle Valo 		ath11k_update_stats_event(ab, skb);
6505d5c65159SKalle Valo 		break;
6506d5c65159SKalle Valo 	case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
6507d5c65159SKalle Valo 		ath11k_pdev_ctl_failsafe_check_event(ab, skb);
6508d5c65159SKalle Valo 		break;
6509d5c65159SKalle Valo 	case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
6510d5c65159SKalle Valo 		ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
6511d5c65159SKalle Valo 		break;
6512a41d1034SPradeep Kumar Chitrapu 	case WMI_PDEV_TEMPERATURE_EVENTID:
6513a41d1034SPradeep Kumar Chitrapu 		ath11k_wmi_pdev_temperature_event(ab, skb);
6514a41d1034SPradeep Kumar Chitrapu 		break;
65159d11b7bfSKarthikeyan Periyasamy 	case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
65169d11b7bfSKarthikeyan Periyasamy 		ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
65179d11b7bfSKarthikeyan Periyasamy 		break;
6518d5c65159SKalle Valo 	/* add Unsupported events here */
6519d5c65159SKalle Valo 	case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID:
6520d5c65159SKalle Valo 	case WMI_VDEV_DELETE_RESP_EVENTID:
65219cfbae46SJohn Crispin 	case WMI_PEER_OPER_MODE_CHANGE_EVENTID:
65226d293d44SJohn Crispin 	case WMI_TWT_ENABLE_EVENTID:
65236d293d44SJohn Crispin 	case WMI_TWT_DISABLE_EVENTID:
65249d11b7bfSKarthikeyan Periyasamy 	case WMI_PDEV_DMA_RING_CFG_RSP_EVENTID:
6525d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
6526d5c65159SKalle Valo 			   "ignoring unsupported event 0x%x\n", id);
6527d5c65159SKalle Valo 		break;
6528d5c65159SKalle Valo 	case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
6529d5c65159SKalle Valo 		ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
6530d5c65159SKalle Valo 		break;
6531d5c65159SKalle Valo 	/* TODO: Add remaining events */
6532d5c65159SKalle Valo 	default:
6533*82b4f9b8SGovind Singh 		ath11k_dbg(ab, ATH11K_DBG_WMI, "Unknown eventid: 0x%x\n", id);
6534d5c65159SKalle Valo 		break;
6535d5c65159SKalle Valo 	}
6536d5c65159SKalle Valo 
6537d5c65159SKalle Valo out:
6538d5c65159SKalle Valo 	dev_kfree_skb(skb);
6539d5c65159SKalle Valo }
6540d5c65159SKalle Valo 
6541d5c65159SKalle Valo static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
6542d5c65159SKalle Valo 					   u32 pdev_idx)
6543d5c65159SKalle Valo {
6544d5c65159SKalle Valo 	int status;
6545d5c65159SKalle Valo 	u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
6546d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
6547d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
6548d5c65159SKalle Valo 
6549d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_req conn_req;
6550d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_resp conn_resp;
6551d5c65159SKalle Valo 
6552d5c65159SKalle Valo 	memset(&conn_req, 0, sizeof(conn_req));
6553d5c65159SKalle Valo 	memset(&conn_resp, 0, sizeof(conn_resp));
6554d5c65159SKalle Valo 
6555d5c65159SKalle Valo 	/* these fields are the same for all service endpoints */
6556d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
6557d5c65159SKalle Valo 	conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
6558d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
6559d5c65159SKalle Valo 
6560d5c65159SKalle Valo 	/* connect to control service */
6561d5c65159SKalle Valo 	conn_req.service_id = svc_id[pdev_idx];
6562d5c65159SKalle Valo 
6563d5c65159SKalle Valo 	status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
6564d5c65159SKalle Valo 	if (status) {
6565d5c65159SKalle Valo 		ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
6566d5c65159SKalle Valo 			    status);
6567d5c65159SKalle Valo 		return status;
6568d5c65159SKalle Valo 	}
6569d5c65159SKalle Valo 
65706bc9d6f7SJohn Crispin 	ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
65716bc9d6f7SJohn Crispin 	ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
65726bc9d6f7SJohn Crispin 	ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
6573d5c65159SKalle Valo 
6574d5c65159SKalle Valo 	return 0;
6575d5c65159SKalle Valo }
6576d5c65159SKalle Valo 
6577d5c65159SKalle Valo static int
6578d5c65159SKalle Valo ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
6579d5c65159SKalle Valo 			      struct wmi_unit_test_cmd ut_cmd,
6580d5c65159SKalle Valo 			      u32 *test_args)
6581d5c65159SKalle Valo {
6582d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
6583d5c65159SKalle Valo 	struct wmi_unit_test_cmd *cmd;
6584d5c65159SKalle Valo 	struct sk_buff *skb;
6585d5c65159SKalle Valo 	struct wmi_tlv *tlv;
6586d5c65159SKalle Valo 	void *ptr;
6587d5c65159SKalle Valo 	u32 *ut_cmd_args;
6588d5c65159SKalle Valo 	int buf_len, arg_len;
6589d5c65159SKalle Valo 	int ret;
6590d5c65159SKalle Valo 	int i;
6591d5c65159SKalle Valo 
6592d5c65159SKalle Valo 	arg_len = sizeof(u32) * ut_cmd.num_args;
6593d5c65159SKalle Valo 	buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
6594d5c65159SKalle Valo 
65956bc9d6f7SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
6596d5c65159SKalle Valo 	if (!skb)
6597d5c65159SKalle Valo 		return -ENOMEM;
6598d5c65159SKalle Valo 
6599d5c65159SKalle Valo 	cmd = (struct wmi_unit_test_cmd *)skb->data;
6600d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
6601d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
6602d5c65159SKalle Valo 
6603d5c65159SKalle Valo 	cmd->vdev_id = ut_cmd.vdev_id;
6604d5c65159SKalle Valo 	cmd->module_id = ut_cmd.module_id;
6605d5c65159SKalle Valo 	cmd->num_args = ut_cmd.num_args;
6606d5c65159SKalle Valo 	cmd->diag_token = ut_cmd.diag_token;
6607d5c65159SKalle Valo 
6608d5c65159SKalle Valo 	ptr = skb->data + sizeof(ut_cmd);
6609d5c65159SKalle Valo 
6610d5c65159SKalle Valo 	tlv = ptr;
6611d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
6612d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, arg_len);
6613d5c65159SKalle Valo 
6614d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
6615d5c65159SKalle Valo 
6616d5c65159SKalle Valo 	ut_cmd_args = ptr;
6617d5c65159SKalle Valo 	for (i = 0; i < ut_cmd.num_args; i++)
6618d5c65159SKalle Valo 		ut_cmd_args[i] = test_args[i];
6619d5c65159SKalle Valo 
6620d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
6621d5c65159SKalle Valo 
6622d5c65159SKalle Valo 	if (ret) {
6623d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
6624d5c65159SKalle Valo 			    ret);
6625d5c65159SKalle Valo 		dev_kfree_skb(skb);
6626d5c65159SKalle Valo 	}
6627d5c65159SKalle Valo 
6628d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
6629d5c65159SKalle Valo 		   "WMI unit test : module %d vdev %d n_args %d token %d\n",
6630d5c65159SKalle Valo 		   cmd->module_id, cmd->vdev_id, cmd->num_args,
6631d5c65159SKalle Valo 		   cmd->diag_token);
6632d5c65159SKalle Valo 
6633d5c65159SKalle Valo 	return ret;
6634d5c65159SKalle Valo }
6635d5c65159SKalle Valo 
6636d5c65159SKalle Valo int ath11k_wmi_simulate_radar(struct ath11k *ar)
6637d5c65159SKalle Valo {
6638d5c65159SKalle Valo 	struct ath11k_vif *arvif;
6639d5c65159SKalle Valo 	u32 dfs_args[DFS_MAX_TEST_ARGS];
6640d5c65159SKalle Valo 	struct wmi_unit_test_cmd wmi_ut;
6641d5c65159SKalle Valo 	bool arvif_found = false;
6642d5c65159SKalle Valo 
6643d5c65159SKalle Valo 	list_for_each_entry(arvif, &ar->arvifs, list) {
6644d5c65159SKalle Valo 		if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6645d5c65159SKalle Valo 			arvif_found = true;
6646d5c65159SKalle Valo 			break;
6647d5c65159SKalle Valo 		}
6648d5c65159SKalle Valo 	}
6649d5c65159SKalle Valo 
6650d5c65159SKalle Valo 	if (!arvif_found)
6651d5c65159SKalle Valo 		return -EINVAL;
6652d5c65159SKalle Valo 
6653d5c65159SKalle Valo 	dfs_args[DFS_TEST_CMDID] = 0;
6654d5c65159SKalle Valo 	dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
6655d5c65159SKalle Valo 	/* Currently we could pass segment_id(b0 - b1), chirp(b2)
6656d5c65159SKalle Valo 	 * freq offset (b3 - b10) to unit test. For simulation
6657d5c65159SKalle Valo 	 * purpose this can be set to 0 which is valid.
6658d5c65159SKalle Valo 	 */
6659d5c65159SKalle Valo 	dfs_args[DFS_TEST_RADAR_PARAM] = 0;
6660d5c65159SKalle Valo 
6661d5c65159SKalle Valo 	wmi_ut.vdev_id = arvif->vdev_id;
6662d5c65159SKalle Valo 	wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
6663d5c65159SKalle Valo 	wmi_ut.num_args = DFS_MAX_TEST_ARGS;
6664d5c65159SKalle Valo 	wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
6665d5c65159SKalle Valo 
6666d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
6667d5c65159SKalle Valo 
6668d5c65159SKalle Valo 	return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
6669d5c65159SKalle Valo }
6670d5c65159SKalle Valo 
6671d5c65159SKalle Valo int ath11k_wmi_connect(struct ath11k_base *ab)
6672d5c65159SKalle Valo {
6673d5c65159SKalle Valo 	u32 i;
6674d5c65159SKalle Valo 	u8 wmi_ep_count;
6675d5c65159SKalle Valo 
6676d5c65159SKalle Valo 	wmi_ep_count = ab->htc.wmi_ep_count;
6677b1cc29e9SAnilkumar Kolli 	if (wmi_ep_count > ab->hw_params.max_radios)
6678d5c65159SKalle Valo 		return -1;
6679d5c65159SKalle Valo 
6680d5c65159SKalle Valo 	for (i = 0; i < wmi_ep_count; i++)
6681d5c65159SKalle Valo 		ath11k_connect_pdev_htc_service(ab, i);
6682d5c65159SKalle Valo 
6683d5c65159SKalle Valo 	return 0;
6684d5c65159SKalle Valo }
6685d5c65159SKalle Valo 
6686d5c65159SKalle Valo static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
6687d5c65159SKalle Valo {
6688d5c65159SKalle Valo 	if (WARN_ON(pdev_id >= MAX_RADIOS))
6689d5c65159SKalle Valo 		return;
6690d5c65159SKalle Valo 
6691d5c65159SKalle Valo 	/* TODO: Deinit any pdev specific wmi resource */
6692d5c65159SKalle Valo }
6693d5c65159SKalle Valo 
6694d5c65159SKalle Valo int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
6695d5c65159SKalle Valo 			   u8 pdev_id)
6696d5c65159SKalle Valo {
6697d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle;
6698d5c65159SKalle Valo 
6699b1cc29e9SAnilkumar Kolli 	if (pdev_id >= ab->hw_params.max_radios)
6700d5c65159SKalle Valo 		return -EINVAL;
6701d5c65159SKalle Valo 
67026bc9d6f7SJohn Crispin 	wmi_handle = &ab->wmi_ab.wmi[pdev_id];
6703d5c65159SKalle Valo 
67046bc9d6f7SJohn Crispin 	wmi_handle->wmi_ab = &ab->wmi_ab;
6705d5c65159SKalle Valo 
67066bc9d6f7SJohn Crispin 	ab->wmi_ab.ab = ab;
6707d5c65159SKalle Valo 	/* TODO: Init remaining resource specific to pdev */
6708d5c65159SKalle Valo 
6709d5c65159SKalle Valo 	return 0;
6710d5c65159SKalle Valo }
6711d5c65159SKalle Valo 
6712d5c65159SKalle Valo int ath11k_wmi_attach(struct ath11k_base *ab)
6713d5c65159SKalle Valo {
6714d5c65159SKalle Valo 	int ret;
6715d5c65159SKalle Valo 
6716d5c65159SKalle Valo 	ret = ath11k_wmi_pdev_attach(ab, 0);
6717d5c65159SKalle Valo 	if (ret)
6718d5c65159SKalle Valo 		return ret;
6719d5c65159SKalle Valo 
67206bc9d6f7SJohn Crispin 	ab->wmi_ab.ab = ab;
67216bc9d6f7SJohn Crispin 	ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
6722d5c65159SKalle Valo 
67235f859bc0SCarl Huang 	/* It's overwritten when service_ext_ready is handled */
67245f859bc0SCarl Huang 	if (ab->hw_params.single_pdev_only)
67255f859bc0SCarl Huang 		ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
67265f859bc0SCarl Huang 
6727d5c65159SKalle Valo 	/* TODO: Init remaining wmi soc resources required */
67286bc9d6f7SJohn Crispin 	init_completion(&ab->wmi_ab.service_ready);
67296bc9d6f7SJohn Crispin 	init_completion(&ab->wmi_ab.unified_ready);
6730d5c65159SKalle Valo 
6731d5c65159SKalle Valo 	return 0;
6732d5c65159SKalle Valo }
6733d5c65159SKalle Valo 
6734d5c65159SKalle Valo void ath11k_wmi_detach(struct ath11k_base *ab)
6735d5c65159SKalle Valo {
6736d5c65159SKalle Valo 	int i;
6737d5c65159SKalle Valo 
6738d5c65159SKalle Valo 	/* TODO: Deinit wmi resource specific to SOC as required */
6739d5c65159SKalle Valo 
6740d5c65159SKalle Valo 	for (i = 0; i < ab->htc.wmi_ep_count; i++)
6741d5c65159SKalle Valo 		ath11k_wmi_pdev_detach(ab, i);
6742bd647855SKarthikeyan Periyasamy 
6743bd647855SKarthikeyan Periyasamy 	ath11k_wmi_free_dbring_caps(ab);
6744d5c65159SKalle Valo }
6745