xref: /openbmc/linux/drivers/net/wireless/ath/ath11k/wmi.c (revision 5b90fc760db5a969ed26d70f8e62c91915f012bd)
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 
30d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse {
31d5c65159SKalle Valo 	struct ath11k_service_ext_param param;
32d5c65159SKalle Valo 	struct wmi_soc_mac_phy_hw_mode_caps *hw_caps;
33d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
34d5c65159SKalle Valo 	u32 n_hw_mode_caps;
35d5c65159SKalle Valo 	u32 tot_phy_id;
36d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities pref_hw_mode_caps;
37d5c65159SKalle Valo 	struct wmi_mac_phy_capabilities *mac_phy_caps;
38d5c65159SKalle Valo 	u32 n_mac_phy_caps;
39d5c65159SKalle Valo 	struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps;
40d5c65159SKalle Valo 	struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps;
41d5c65159SKalle Valo 	u32 n_ext_hal_reg_caps;
42d5c65159SKalle Valo 	bool hw_mode_done;
43d5c65159SKalle Valo 	bool mac_phy_done;
44d5c65159SKalle Valo 	bool ext_hal_reg_done;
45d5c65159SKalle Valo };
46d5c65159SKalle Valo 
47d5c65159SKalle Valo struct wmi_tlv_rdy_parse {
48d5c65159SKalle Valo 	u32 num_extra_mac_addr;
49d5c65159SKalle Valo };
50d5c65159SKalle Valo 
51d5c65159SKalle Valo static const struct wmi_tlv_policy wmi_tlv_policies[] = {
52d5c65159SKalle Valo 	[WMI_TAG_ARRAY_BYTE]
53d5c65159SKalle Valo 		= { .min_len = 0 },
54d5c65159SKalle Valo 	[WMI_TAG_ARRAY_UINT32]
55d5c65159SKalle Valo 		= { .min_len = 0 },
56d5c65159SKalle Valo 	[WMI_TAG_SERVICE_READY_EVENT]
57d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_service_ready_event) },
58d5c65159SKalle Valo 	[WMI_TAG_SERVICE_READY_EXT_EVENT]
59d5c65159SKalle Valo 		= { .min_len =  sizeof(struct wmi_service_ready_ext_event) },
60d5c65159SKalle Valo 	[WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS]
61d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) },
62d5c65159SKalle Valo 	[WMI_TAG_SOC_HAL_REG_CAPABILITIES]
63d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) },
64d5c65159SKalle Valo 	[WMI_TAG_VDEV_START_RESPONSE_EVENT]
65d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_start_resp_event) },
66d5c65159SKalle Valo 	[WMI_TAG_PEER_DELETE_RESP_EVENT]
67d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_delete_resp_event) },
68d5c65159SKalle Valo 	[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]
69d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_bcn_tx_status_event) },
70d5c65159SKalle Valo 	[WMI_TAG_VDEV_STOPPED_EVENT]
71d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_stopped_event) },
72d5c65159SKalle Valo 	[WMI_TAG_REG_CHAN_LIST_CC_EVENT]
73d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) },
74d5c65159SKalle Valo 	[WMI_TAG_MGMT_RX_HDR]
75d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_mgmt_rx_hdr) },
76d5c65159SKalle Valo 	[WMI_TAG_MGMT_TX_COMPL_EVENT]
77d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) },
78d5c65159SKalle Valo 	[WMI_TAG_SCAN_EVENT]
79d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_scan_event) },
80d5c65159SKalle Valo 	[WMI_TAG_PEER_STA_KICKOUT_EVENT]
81d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
82d5c65159SKalle Valo 	[WMI_TAG_ROAM_EVENT]
83d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_roam_event) },
84d5c65159SKalle Valo 	[WMI_TAG_CHAN_INFO_EVENT]
85d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_chan_info_event) },
86d5c65159SKalle Valo 	[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]
87d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) },
88d5c65159SKalle Valo 	[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]
89d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) },
90d5c65159SKalle Valo 	[WMI_TAG_READY_EVENT]
91d5c65159SKalle Valo 		= {.min_len = sizeof(struct wmi_ready_event) },
92d5c65159SKalle Valo 	[WMI_TAG_SERVICE_AVAILABLE_EVENT]
93d5c65159SKalle Valo 		= {.min_len = sizeof(struct wmi_service_available_event) },
94d5c65159SKalle Valo 	[WMI_TAG_PEER_ASSOC_CONF_EVENT]
95d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_peer_assoc_conf_event) },
96d5c65159SKalle Valo 	[WMI_TAG_STATS_EVENT]
97d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_stats_event) },
98d5c65159SKalle Valo 	[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]
99d5c65159SKalle Valo 		= { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) },
100d5c65159SKalle Valo };
101d5c65159SKalle Valo 
102d5c65159SKalle Valo #define PRIMAP(_hw_mode_) \
103d5c65159SKalle Valo 	[_hw_mode_] = _hw_mode_##_PRI
104d5c65159SKalle Valo 
105d5c65159SKalle Valo static const int ath11k_hw_mode_pri_map[] = {
106d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SINGLE),
107d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS),
108d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE),
109d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_SBS),
110d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS_SBS),
111d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS),
112d5c65159SKalle Valo 	/* keep last */
113d5c65159SKalle Valo 	PRIMAP(WMI_HOST_HW_MODE_MAX),
114d5c65159SKalle Valo };
115d5c65159SKalle Valo 
116d5c65159SKalle Valo static int
117d5c65159SKalle Valo ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
118d5c65159SKalle Valo 		    int (*iter)(struct ath11k_base *ab, u16 tag, u16 len,
119d5c65159SKalle Valo 				const void *ptr, void *data),
120d5c65159SKalle Valo 		    void *data)
121d5c65159SKalle Valo {
122d5c65159SKalle Valo 	const void *begin = ptr;
123d5c65159SKalle Valo 	const struct wmi_tlv *tlv;
124d5c65159SKalle Valo 	u16 tlv_tag, tlv_len;
125d5c65159SKalle Valo 	int ret;
126d5c65159SKalle Valo 
127d5c65159SKalle Valo 	while (len > 0) {
128d5c65159SKalle Valo 		if (len < sizeof(*tlv)) {
129d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
130d5c65159SKalle Valo 				   ptr - begin, len, sizeof(*tlv));
131d5c65159SKalle Valo 			return -EINVAL;
132d5c65159SKalle Valo 		}
133d5c65159SKalle Valo 
134d5c65159SKalle Valo 		tlv = ptr;
135d5c65159SKalle Valo 		tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header);
136d5c65159SKalle Valo 		tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header);
137d5c65159SKalle Valo 		ptr += sizeof(*tlv);
138d5c65159SKalle Valo 		len -= sizeof(*tlv);
139d5c65159SKalle Valo 
140d5c65159SKalle Valo 		if (tlv_len > len) {
141d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure of tag %hhu at byte %zd (%zu bytes left, %hhu expected)\n",
142d5c65159SKalle Valo 				   tlv_tag, ptr - begin, len, tlv_len);
143d5c65159SKalle Valo 			return -EINVAL;
144d5c65159SKalle Valo 		}
145d5c65159SKalle Valo 
146d5c65159SKalle Valo 		if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
147d5c65159SKalle Valo 		    wmi_tlv_policies[tlv_tag].min_len &&
148d5c65159SKalle Valo 		    wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
149d5c65159SKalle Valo 			ath11k_err(ab, "wmi tlv parse failure of tag %hhu at byte %zd (%hhu bytes is less than min length %zu)\n",
150d5c65159SKalle Valo 				   tlv_tag, ptr - begin, tlv_len,
151d5c65159SKalle Valo 				   wmi_tlv_policies[tlv_tag].min_len);
152d5c65159SKalle Valo 			return -EINVAL;
153d5c65159SKalle Valo 		}
154d5c65159SKalle Valo 
155d5c65159SKalle Valo 		ret = iter(ab, tlv_tag, tlv_len, ptr, data);
156d5c65159SKalle Valo 		if (ret)
157d5c65159SKalle Valo 			return ret;
158d5c65159SKalle Valo 
159d5c65159SKalle Valo 		ptr += tlv_len;
160d5c65159SKalle Valo 		len -= tlv_len;
161d5c65159SKalle Valo 	}
162d5c65159SKalle Valo 
163d5c65159SKalle Valo 	return 0;
164d5c65159SKalle Valo }
165d5c65159SKalle Valo 
166d5c65159SKalle Valo static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len,
167d5c65159SKalle Valo 				     const void *ptr, void *data)
168d5c65159SKalle Valo {
169d5c65159SKalle Valo 	const void **tb = data;
170d5c65159SKalle Valo 
171d5c65159SKalle Valo 	if (tag < WMI_TAG_MAX)
172d5c65159SKalle Valo 		tb[tag] = ptr;
173d5c65159SKalle Valo 
174d5c65159SKalle Valo 	return 0;
175d5c65159SKalle Valo }
176d5c65159SKalle Valo 
177d5c65159SKalle Valo static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb,
178d5c65159SKalle Valo 				const void *ptr, size_t len)
179d5c65159SKalle Valo {
180d5c65159SKalle Valo 	return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse,
181d5c65159SKalle Valo 				   (void *)tb);
182d5c65159SKalle Valo }
183d5c65159SKalle Valo 
184d5c65159SKalle Valo static const void **
185d5c65159SKalle Valo ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr,
186d5c65159SKalle Valo 			   size_t len, gfp_t gfp)
187d5c65159SKalle Valo {
188d5c65159SKalle Valo 	const void **tb;
189d5c65159SKalle Valo 	int ret;
190d5c65159SKalle Valo 
191d5c65159SKalle Valo 	tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp);
192d5c65159SKalle Valo 	if (!tb)
193d5c65159SKalle Valo 		return ERR_PTR(-ENOMEM);
194d5c65159SKalle Valo 
195d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len);
196d5c65159SKalle Valo 	if (ret) {
197d5c65159SKalle Valo 		kfree(tb);
198d5c65159SKalle Valo 		return ERR_PTR(ret);
199d5c65159SKalle Valo 	}
200d5c65159SKalle Valo 
201d5c65159SKalle Valo 	return tb;
202d5c65159SKalle Valo }
203d5c65159SKalle Valo 
204d5c65159SKalle Valo static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
205d5c65159SKalle Valo 				      u32 cmd_id)
206d5c65159SKalle Valo {
207d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
208d5c65159SKalle Valo 	struct ath11k_base *ab = wmi->wmi_sc->ab;
209d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
210d5c65159SKalle Valo 	int ret;
211d5c65159SKalle Valo 	u32 cmd = 0;
212d5c65159SKalle Valo 
213d5c65159SKalle Valo 	if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
214d5c65159SKalle Valo 		return -ENOMEM;
215d5c65159SKalle Valo 
216d5c65159SKalle Valo 	cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id);
217d5c65159SKalle Valo 
218d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
219d5c65159SKalle Valo 	cmd_hdr->cmd_id = cmd;
220d5c65159SKalle Valo 
221d5c65159SKalle Valo 	memset(skb_cb, 0, sizeof(*skb_cb));
222d5c65159SKalle Valo 	ret = ath11k_htc_send(&ab->htc, wmi->eid, skb);
223d5c65159SKalle Valo 
224d5c65159SKalle Valo 	if (ret)
225d5c65159SKalle Valo 		goto err_pull;
226d5c65159SKalle Valo 
227d5c65159SKalle Valo 	return 0;
228d5c65159SKalle Valo 
229d5c65159SKalle Valo err_pull:
230d5c65159SKalle Valo 	skb_pull(skb, sizeof(struct wmi_cmd_hdr));
231d5c65159SKalle Valo 	return ret;
232d5c65159SKalle Valo }
233d5c65159SKalle Valo 
234d5c65159SKalle Valo int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
235d5c65159SKalle Valo 			u32 cmd_id)
236d5c65159SKalle Valo {
237d5c65159SKalle Valo 	struct ath11k_wmi_base *wmi_sc = wmi->wmi_sc;
238d5c65159SKalle Valo 	int ret = -EOPNOTSUPP;
239d5c65159SKalle Valo 
240d5c65159SKalle Valo 	might_sleep();
241d5c65159SKalle Valo 
242d5c65159SKalle Valo 	wait_event_timeout(wmi_sc->tx_credits_wq, ({
243d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
244d5c65159SKalle Valo 
245d5c65159SKalle Valo 		if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH, &wmi_sc->ab->dev_flags))
246d5c65159SKalle Valo 			ret = -ESHUTDOWN;
247d5c65159SKalle Valo 
248d5c65159SKalle Valo 		(ret != -EAGAIN);
249d5c65159SKalle Valo 	}), WMI_SEND_TIMEOUT_HZ);
250d5c65159SKalle Valo 
251d5c65159SKalle Valo 	if (ret == -EAGAIN)
252d5c65159SKalle Valo 		ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id);
253d5c65159SKalle Valo 
254d5c65159SKalle Valo 	return ret;
255d5c65159SKalle Valo }
256d5c65159SKalle Valo 
257d5c65159SKalle Valo static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
258d5c65159SKalle Valo 				     const void *ptr,
259d5c65159SKalle Valo 				     struct ath11k_service_ext_param *param)
260d5c65159SKalle Valo {
261d5c65159SKalle Valo 	const struct wmi_service_ready_ext_event *ev = ptr;
262d5c65159SKalle Valo 
263d5c65159SKalle Valo 	if (!ev)
264d5c65159SKalle Valo 		return -EINVAL;
265d5c65159SKalle Valo 
266d5c65159SKalle Valo 	/* Move this to host based bitmap */
267d5c65159SKalle Valo 	param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits;
268d5c65159SKalle Valo 	param->default_fw_config_bits =	ev->default_fw_config_bits;
269d5c65159SKalle Valo 	param->he_cap_info = ev->he_cap_info;
270d5c65159SKalle Valo 	param->mpdu_density = ev->mpdu_density;
271d5c65159SKalle Valo 	param->max_bssid_rx_filters = ev->max_bssid_rx_filters;
272d5c65159SKalle Valo 	memcpy(&param->ppet, &ev->ppet, sizeof(param->ppet));
273d5c65159SKalle Valo 
274d5c65159SKalle Valo 	return 0;
275d5c65159SKalle Valo }
276d5c65159SKalle Valo 
277d5c65159SKalle Valo static int
278d5c65159SKalle Valo ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
279d5c65159SKalle Valo 				      struct wmi_soc_mac_phy_hw_mode_caps *hw_caps,
280d5c65159SKalle Valo 				      struct wmi_hw_mode_capabilities *wmi_hw_mode_caps,
281d5c65159SKalle Valo 				      struct wmi_soc_hal_reg_capabilities *hal_reg_caps,
282d5c65159SKalle Valo 				      struct wmi_mac_phy_capabilities *wmi_mac_phy_caps,
283d5c65159SKalle Valo 				      u8 hw_mode_id, u8 phy_id,
284d5c65159SKalle Valo 				      struct ath11k_pdev *pdev)
285d5c65159SKalle Valo {
286d5c65159SKalle Valo 	struct wmi_mac_phy_capabilities *mac_phy_caps;
287d5c65159SKalle Valo 	struct ath11k_band_cap *cap_band;
288d5c65159SKalle Valo 	struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
289d5c65159SKalle Valo 	u32 phy_map;
290d5c65159SKalle Valo 	u32 hw_idx, phy_idx = 0;
291d5c65159SKalle Valo 
292d5c65159SKalle Valo 	if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps)
293d5c65159SKalle Valo 		return -EINVAL;
294d5c65159SKalle Valo 
295d5c65159SKalle Valo 	for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) {
296d5c65159SKalle Valo 		if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id)
297d5c65159SKalle Valo 			break;
298d5c65159SKalle Valo 
299d5c65159SKalle Valo 		phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map;
300d5c65159SKalle Valo 		while (phy_map) {
301d5c65159SKalle Valo 			phy_map >>= 1;
302d5c65159SKalle Valo 			phy_idx++;
303d5c65159SKalle Valo 		}
304d5c65159SKalle Valo 	}
305d5c65159SKalle Valo 
306d5c65159SKalle Valo 	if (hw_idx == hw_caps->num_hw_modes)
307d5c65159SKalle Valo 		return -EINVAL;
308d5c65159SKalle Valo 
309d5c65159SKalle Valo 	phy_idx += phy_id;
310d5c65159SKalle Valo 	if (phy_id >= hal_reg_caps->num_phy)
311d5c65159SKalle Valo 		return -EINVAL;
312d5c65159SKalle Valo 
313*5b90fc76SAnilkumar Kolli 	mac_phy_caps = wmi_mac_phy_caps + phy_idx;
314d5c65159SKalle Valo 
315d5c65159SKalle Valo 	pdev->pdev_id = mac_phy_caps->pdev_id;
316d5c65159SKalle Valo 	pdev_cap->supported_bands = mac_phy_caps->supported_bands;
317d5c65159SKalle Valo 	pdev_cap->ampdu_density = mac_phy_caps->ampdu_density;
318d5c65159SKalle Valo 
319d5c65159SKalle Valo 	/* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from
320d5c65159SKalle Valo 	 * band to band for a single radio, need to see how this should be
321d5c65159SKalle Valo 	 * handled.
322d5c65159SKalle Valo 	 */
323d5c65159SKalle Valo 	if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
324d5c65159SKalle Valo 		pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g;
325d5c65159SKalle Valo 		pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g;
326d5c65159SKalle Valo 	} else if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
327d5c65159SKalle Valo 		pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g;
328d5c65159SKalle Valo 		pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g;
329d5c65159SKalle Valo 		pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g;
330d5c65159SKalle Valo 		pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g;
331d5c65159SKalle Valo 		pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g;
332d5c65159SKalle Valo 	} else {
333d5c65159SKalle Valo 		return -EINVAL;
334d5c65159SKalle Valo 	}
335d5c65159SKalle Valo 
336d5c65159SKalle Valo 	/* tx/rx chainmask reported from fw depends on the actual hw chains used,
337d5c65159SKalle Valo 	 * For example, for 4x4 capable macphys, first 4 chains can be used for first
338d5c65159SKalle Valo 	 * mac and the remaing 4 chains can be used for the second mac or vice-versa.
339d5c65159SKalle Valo 	 * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0
340d5c65159SKalle Valo 	 * will be advertised for second mac or vice-versa. Compute the shift value for
341d5c65159SKalle Valo 	 * for tx/rx chainmask which will be used to advertise supported ht/vht rates to
342d5c65159SKalle Valo 	 * mac80211.
343d5c65159SKalle Valo 	 */
344d5c65159SKalle Valo 	pdev_cap->tx_chain_mask_shift =
345d5c65159SKalle Valo 			find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32);
346d5c65159SKalle Valo 	pdev_cap->rx_chain_mask_shift =
347d5c65159SKalle Valo 			find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32);
348d5c65159SKalle Valo 
349d5c65159SKalle Valo 	cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
350d5c65159SKalle Valo 	cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g;
351d5c65159SKalle Valo 	cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g;
352d5c65159SKalle Valo 	cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g;
353d5c65159SKalle Valo 	cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext;
354d5c65159SKalle Valo 	cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g;
355d5c65159SKalle Valo 	memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g,
356d5c65159SKalle Valo 	       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
357d5c65159SKalle Valo 	memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g,
358d5c65159SKalle Valo 	       sizeof(struct ath11k_ppe_threshold));
359d5c65159SKalle Valo 
360d5c65159SKalle Valo 	cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
361d5c65159SKalle Valo 	cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
362d5c65159SKalle Valo 	cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
363d5c65159SKalle Valo 	cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
364d5c65159SKalle Valo 	cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
365d5c65159SKalle Valo 	cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
366d5c65159SKalle Valo 	memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
367d5c65159SKalle Valo 	       sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
368d5c65159SKalle Valo 	memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
369d5c65159SKalle Valo 	       sizeof(struct ath11k_ppe_threshold));
370d5c65159SKalle Valo 
371d5c65159SKalle Valo 	return 0;
372d5c65159SKalle Valo }
373d5c65159SKalle Valo 
374d5c65159SKalle Valo static int
375d5c65159SKalle Valo ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle,
376d5c65159SKalle Valo 				struct wmi_soc_hal_reg_capabilities *reg_caps,
377d5c65159SKalle Valo 				struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap,
378d5c65159SKalle Valo 				u8 phy_idx,
379d5c65159SKalle Valo 				struct ath11k_hal_reg_capabilities_ext *param)
380d5c65159SKalle Valo {
381d5c65159SKalle Valo 	struct wmi_hal_reg_capabilities_ext *ext_reg_cap;
382d5c65159SKalle Valo 
383d5c65159SKalle Valo 	if (!reg_caps || !wmi_ext_reg_cap)
384d5c65159SKalle Valo 		return -EINVAL;
385d5c65159SKalle Valo 
386d5c65159SKalle Valo 	if (phy_idx >= reg_caps->num_phy)
387d5c65159SKalle Valo 		return -EINVAL;
388d5c65159SKalle Valo 
389d5c65159SKalle Valo 	ext_reg_cap = &wmi_ext_reg_cap[phy_idx];
390d5c65159SKalle Valo 
391d5c65159SKalle Valo 	param->phy_id = ext_reg_cap->phy_id;
392d5c65159SKalle Valo 	param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain;
393d5c65159SKalle Valo 	param->eeprom_reg_domain_ext =
394d5c65159SKalle Valo 			      ext_reg_cap->eeprom_reg_domain_ext;
395d5c65159SKalle Valo 	param->regcap1 = ext_reg_cap->regcap1;
396d5c65159SKalle Valo 	param->regcap2 = ext_reg_cap->regcap2;
397d5c65159SKalle Valo 	/* check if param->wireless_mode is needed */
398d5c65159SKalle Valo 	param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan;
399d5c65159SKalle Valo 	param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan;
400d5c65159SKalle Valo 	param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan;
401d5c65159SKalle Valo 	param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan;
402d5c65159SKalle Valo 
403d5c65159SKalle Valo 	return 0;
404d5c65159SKalle Valo }
405d5c65159SKalle Valo 
406d5c65159SKalle Valo static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab,
407d5c65159SKalle Valo 					 const void *evt_buf,
408d5c65159SKalle Valo 					 struct ath11k_targ_cap *cap)
409d5c65159SKalle Valo {
410d5c65159SKalle Valo 	const struct wmi_service_ready_event *ev = evt_buf;
411d5c65159SKalle Valo 
412d5c65159SKalle Valo 	if (!ev) {
413d5c65159SKalle Valo 		ath11k_err(ab, "%s: failed by NULL param\n",
414d5c65159SKalle Valo 			   __func__);
415d5c65159SKalle Valo 		return -EINVAL;
416d5c65159SKalle Valo 	}
417d5c65159SKalle Valo 
418d5c65159SKalle Valo 	cap->phy_capability = ev->phy_capability;
419d5c65159SKalle Valo 	cap->max_frag_entry = ev->max_frag_entry;
420d5c65159SKalle Valo 	cap->num_rf_chains = ev->num_rf_chains;
421d5c65159SKalle Valo 	cap->ht_cap_info = ev->ht_cap_info;
422d5c65159SKalle Valo 	cap->vht_cap_info = ev->vht_cap_info;
423d5c65159SKalle Valo 	cap->vht_supp_mcs = ev->vht_supp_mcs;
424d5c65159SKalle Valo 	cap->hw_min_tx_power = ev->hw_min_tx_power;
425d5c65159SKalle Valo 	cap->hw_max_tx_power = ev->hw_max_tx_power;
426d5c65159SKalle Valo 	cap->sys_cap_info = ev->sys_cap_info;
427d5c65159SKalle Valo 	cap->min_pkt_size_enable = ev->min_pkt_size_enable;
428d5c65159SKalle Valo 	cap->max_bcn_ie_size = ev->max_bcn_ie_size;
429d5c65159SKalle Valo 	cap->max_num_scan_channels = ev->max_num_scan_channels;
430d5c65159SKalle Valo 	cap->max_supported_macs = ev->max_supported_macs;
431d5c65159SKalle Valo 	cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps;
432d5c65159SKalle Valo 	cap->txrx_chainmask = ev->txrx_chainmask;
433d5c65159SKalle Valo 	cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index;
434d5c65159SKalle Valo 	cap->num_msdu_desc = ev->num_msdu_desc;
435d5c65159SKalle Valo 
436d5c65159SKalle Valo 	return 0;
437d5c65159SKalle Valo }
438d5c65159SKalle Valo 
439d5c65159SKalle Valo /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in
440d5c65159SKalle Valo  * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each
441d5c65159SKalle Valo  * 4-byte word.
442d5c65159SKalle Valo  */
443d5c65159SKalle Valo static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi,
444d5c65159SKalle Valo 					   const u32 *wmi_svc_bm)
445d5c65159SKalle Valo {
446d5c65159SKalle Valo 	int i, j;
447d5c65159SKalle Valo 
448d5c65159SKalle Valo 	for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) {
449d5c65159SKalle Valo 		do {
450d5c65159SKalle Valo 			if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32))
451d5c65159SKalle Valo 				set_bit(j, wmi->wmi_sc->svc_map);
452d5c65159SKalle Valo 		} while (++j % WMI_SERVICE_BITS_IN_SIZE32);
453d5c65159SKalle Valo 	}
454d5c65159SKalle Valo }
455d5c65159SKalle Valo 
456d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
457d5c65159SKalle Valo 					const void *ptr, void *data)
458d5c65159SKalle Valo {
459d5c65159SKalle Valo 	struct wmi_tlv_svc_ready_parse *svc_ready = data;
460d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_sc.wmi[0];
461d5c65159SKalle Valo 	u16 expect_len;
462d5c65159SKalle Valo 
463d5c65159SKalle Valo 	switch (tag) {
464d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EVENT:
465d5c65159SKalle Valo 		if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps))
466d5c65159SKalle Valo 			return -EINVAL;
467d5c65159SKalle Valo 		break;
468d5c65159SKalle Valo 
469d5c65159SKalle Valo 	case WMI_TAG_ARRAY_UINT32:
470d5c65159SKalle Valo 		if (!svc_ready->wmi_svc_bitmap_done) {
471d5c65159SKalle Valo 			expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32);
472d5c65159SKalle Valo 			if (len < expect_len) {
473d5c65159SKalle Valo 				ath11k_warn(ab, "invalid len %d for the tag 0x%x\n",
474d5c65159SKalle Valo 					    len, tag);
475d5c65159SKalle Valo 				return -EINVAL;
476d5c65159SKalle Valo 			}
477d5c65159SKalle Valo 
478d5c65159SKalle Valo 			ath11k_wmi_service_bitmap_copy(wmi_handle, ptr);
479d5c65159SKalle Valo 
480d5c65159SKalle Valo 			svc_ready->wmi_svc_bitmap_done = true;
481d5c65159SKalle Valo 		}
482d5c65159SKalle Valo 		break;
483d5c65159SKalle Valo 	default:
484d5c65159SKalle Valo 		break;
485d5c65159SKalle Valo 	}
486d5c65159SKalle Valo 
487d5c65159SKalle Valo 	return 0;
488d5c65159SKalle Valo }
489d5c65159SKalle Valo 
490d5c65159SKalle Valo static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
491d5c65159SKalle Valo {
492d5c65159SKalle Valo 	struct wmi_tlv_svc_ready_parse svc_ready = { };
493d5c65159SKalle Valo 	int ret;
494d5c65159SKalle Valo 
495d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
496d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_parse,
497d5c65159SKalle Valo 				  &svc_ready);
498d5c65159SKalle Valo 	if (ret) {
499d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
500d5c65159SKalle Valo 		return ret;
501d5c65159SKalle Valo 	}
502d5c65159SKalle Valo 
503d5c65159SKalle Valo 	return 0;
504d5c65159SKalle Valo }
505d5c65159SKalle Valo 
506d5c65159SKalle Valo struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len)
507d5c65159SKalle Valo {
508d5c65159SKalle Valo 	struct sk_buff *skb;
509d5c65159SKalle Valo 	struct ath11k_base *ab = wmi_sc->ab;
510d5c65159SKalle Valo 	u32 round_len = roundup(len, 4);
511d5c65159SKalle Valo 
512d5c65159SKalle Valo 	skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len);
513d5c65159SKalle Valo 	if (!skb)
514d5c65159SKalle Valo 		return NULL;
515d5c65159SKalle Valo 
516d5c65159SKalle Valo 	skb_reserve(skb, WMI_SKB_HEADROOM);
517d5c65159SKalle Valo 	if (!IS_ALIGNED((unsigned long)skb->data, 4))
518d5c65159SKalle Valo 		ath11k_warn(ab, "unaligned WMI skb data\n");
519d5c65159SKalle Valo 
520d5c65159SKalle Valo 	skb_put(skb, round_len);
521d5c65159SKalle Valo 	memset(skb->data, 0, round_len);
522d5c65159SKalle Valo 
523d5c65159SKalle Valo 	return skb;
524d5c65159SKalle Valo }
525d5c65159SKalle Valo 
526d5c65159SKalle Valo int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id,
527d5c65159SKalle Valo 			 struct sk_buff *frame)
528d5c65159SKalle Valo {
529d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
530d5c65159SKalle Valo 	struct wmi_mgmt_send_cmd *cmd;
531d5c65159SKalle Valo 	struct wmi_tlv *frame_tlv;
532d5c65159SKalle Valo 	struct sk_buff *skb;
533d5c65159SKalle Valo 	u32 buf_len;
534d5c65159SKalle Valo 	int ret, len;
535d5c65159SKalle Valo 
536d5c65159SKalle Valo 	buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ?
537d5c65159SKalle Valo 		  frame->len : WMI_MGMT_SEND_DOWNLD_LEN;
538d5c65159SKalle Valo 
539d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4);
540d5c65159SKalle Valo 
541d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
542d5c65159SKalle Valo 	if (!skb)
543d5c65159SKalle Valo 		return -ENOMEM;
544d5c65159SKalle Valo 
545d5c65159SKalle Valo 	cmd = (struct wmi_mgmt_send_cmd *)skb->data;
546d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) |
547d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
548d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
549d5c65159SKalle Valo 	cmd->desc_id = buf_id;
550d5c65159SKalle Valo 	cmd->chanfreq = 0;
551d5c65159SKalle Valo 	cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr);
552d5c65159SKalle Valo 	cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr);
553d5c65159SKalle Valo 	cmd->frame_len = frame->len;
554d5c65159SKalle Valo 	cmd->buf_len = buf_len;
555d5c65159SKalle Valo 	cmd->tx_params_valid = 0;
556d5c65159SKalle Valo 
557d5c65159SKalle Valo 	frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
558d5c65159SKalle Valo 	frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
559d5c65159SKalle Valo 			    FIELD_PREP(WMI_TLV_LEN, buf_len);
560d5c65159SKalle Valo 
561d5c65159SKalle Valo 	memcpy(frame_tlv->value, frame->data, buf_len);
562d5c65159SKalle Valo 
563d5c65159SKalle Valo 	ath11k_ce_byte_swap(frame_tlv->value, buf_len);
564d5c65159SKalle Valo 
565d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID);
566d5c65159SKalle Valo 	if (ret) {
567d5c65159SKalle Valo 		ath11k_warn(ar->ab,
568d5c65159SKalle Valo 			    "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n");
569d5c65159SKalle Valo 		dev_kfree_skb(skb);
570d5c65159SKalle Valo 	}
571d5c65159SKalle Valo 
572d5c65159SKalle Valo 	return ret;
573d5c65159SKalle Valo }
574d5c65159SKalle Valo 
575d5c65159SKalle Valo int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr,
576d5c65159SKalle Valo 			   struct vdev_create_params *param)
577d5c65159SKalle Valo {
578d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
579d5c65159SKalle Valo 	struct wmi_vdev_create_cmd *cmd;
580d5c65159SKalle Valo 	struct sk_buff *skb;
581d5c65159SKalle Valo 	struct wmi_vdev_txrx_streams *txrx_streams;
582d5c65159SKalle Valo 	struct wmi_tlv *tlv;
583d5c65159SKalle Valo 	int ret, len;
584d5c65159SKalle Valo 	void *ptr;
585d5c65159SKalle Valo 
586d5c65159SKalle Valo 	/* It can be optimized my sending tx/rx chain configuration
587d5c65159SKalle Valo 	 * only for supported bands instead of always sending it for
588d5c65159SKalle Valo 	 * both the bands.
589d5c65159SKalle Valo 	 */
590d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE +
591d5c65159SKalle Valo 		(WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams));
592d5c65159SKalle Valo 
593d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
594d5c65159SKalle Valo 	if (!skb)
595d5c65159SKalle Valo 		return -ENOMEM;
596d5c65159SKalle Valo 
597d5c65159SKalle Valo 	cmd = (struct wmi_vdev_create_cmd *)skb->data;
598d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) |
599d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
600d5c65159SKalle Valo 
601d5c65159SKalle Valo 	cmd->vdev_id = param->if_id;
602d5c65159SKalle Valo 	cmd->vdev_type = param->type;
603d5c65159SKalle Valo 	cmd->vdev_subtype = param->subtype;
604d5c65159SKalle Valo 	cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX;
605d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
606d5c65159SKalle Valo 	ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
607d5c65159SKalle Valo 
608d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
609d5c65159SKalle Valo 	len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams);
610d5c65159SKalle Valo 
611d5c65159SKalle Valo 	tlv = ptr;
612d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
613d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
614d5c65159SKalle Valo 
615d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
616d5c65159SKalle Valo 	txrx_streams = ptr;
617d5c65159SKalle Valo 	len = sizeof(*txrx_streams);
618d5c65159SKalle Valo 	txrx_streams->tlv_header =
619d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
620d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
621d5c65159SKalle Valo 	txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G;
622d5c65159SKalle Valo 	txrx_streams->supported_tx_streams =
623d5c65159SKalle Valo 				 param->chains[NL80211_BAND_2GHZ].tx;
624d5c65159SKalle Valo 	txrx_streams->supported_rx_streams =
625d5c65159SKalle Valo 				 param->chains[NL80211_BAND_2GHZ].rx;
626d5c65159SKalle Valo 
627d5c65159SKalle Valo 	txrx_streams++;
628d5c65159SKalle Valo 	txrx_streams->tlv_header =
629d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
630d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
631d5c65159SKalle Valo 	txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G;
632d5c65159SKalle Valo 	txrx_streams->supported_tx_streams =
633d5c65159SKalle Valo 				 param->chains[NL80211_BAND_5GHZ].tx;
634d5c65159SKalle Valo 	txrx_streams->supported_rx_streams =
635d5c65159SKalle Valo 				 param->chains[NL80211_BAND_5GHZ].rx;
636d5c65159SKalle Valo 
637d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID);
638d5c65159SKalle Valo 	if (ret) {
639d5c65159SKalle Valo 		ath11k_warn(ar->ab,
640d5c65159SKalle Valo 			    "failed to submit WMI_VDEV_CREATE_CMDID\n");
641d5c65159SKalle Valo 		dev_kfree_skb(skb);
642d5c65159SKalle Valo 	}
643d5c65159SKalle Valo 
644d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
645d5c65159SKalle Valo 		   "WMI vdev create: id %d type %d subtype %d macaddr %pM pdevid %d\n",
646d5c65159SKalle Valo 		   param->if_id, param->type, param->subtype,
647d5c65159SKalle Valo 		   macaddr, param->pdev_id);
648d5c65159SKalle Valo 
649d5c65159SKalle Valo 	return ret;
650d5c65159SKalle Valo }
651d5c65159SKalle Valo 
652d5c65159SKalle Valo int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id)
653d5c65159SKalle Valo {
654d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
655d5c65159SKalle Valo 	struct wmi_vdev_delete_cmd *cmd;
656d5c65159SKalle Valo 	struct sk_buff *skb;
657d5c65159SKalle Valo 	int ret;
658d5c65159SKalle Valo 
659d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
660d5c65159SKalle Valo 	if (!skb)
661d5c65159SKalle Valo 		return -ENOMEM;
662d5c65159SKalle Valo 
663d5c65159SKalle Valo 	cmd = (struct wmi_vdev_delete_cmd *)skb->data;
664d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) |
665d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
666d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
667d5c65159SKalle Valo 
668d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID);
669d5c65159SKalle Valo 	if (ret) {
670d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n");
671d5c65159SKalle Valo 		dev_kfree_skb(skb);
672d5c65159SKalle Valo 	}
673d5c65159SKalle Valo 
674d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev delete id %d\n", vdev_id);
675d5c65159SKalle Valo 
676d5c65159SKalle Valo 	return ret;
677d5c65159SKalle Valo }
678d5c65159SKalle Valo 
679d5c65159SKalle Valo int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id)
680d5c65159SKalle Valo {
681d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
682d5c65159SKalle Valo 	struct wmi_vdev_stop_cmd *cmd;
683d5c65159SKalle Valo 	struct sk_buff *skb;
684d5c65159SKalle Valo 	int ret;
685d5c65159SKalle Valo 
686d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
687d5c65159SKalle Valo 	if (!skb)
688d5c65159SKalle Valo 		return -ENOMEM;
689d5c65159SKalle Valo 
690d5c65159SKalle Valo 	cmd = (struct wmi_vdev_stop_cmd *)skb->data;
691d5c65159SKalle Valo 
692d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) |
693d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
694d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
695d5c65159SKalle Valo 
696d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID);
697d5c65159SKalle Valo 	if (ret) {
698d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n");
699d5c65159SKalle Valo 		dev_kfree_skb(skb);
700d5c65159SKalle Valo 	}
701d5c65159SKalle Valo 
702d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev stop id 0x%x\n", vdev_id);
703d5c65159SKalle Valo 
704d5c65159SKalle Valo 	return ret;
705d5c65159SKalle Valo }
706d5c65159SKalle Valo 
707d5c65159SKalle Valo int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id)
708d5c65159SKalle Valo {
709d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
710d5c65159SKalle Valo 	struct wmi_vdev_down_cmd *cmd;
711d5c65159SKalle Valo 	struct sk_buff *skb;
712d5c65159SKalle Valo 	int ret;
713d5c65159SKalle Valo 
714d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
715d5c65159SKalle Valo 	if (!skb)
716d5c65159SKalle Valo 		return -ENOMEM;
717d5c65159SKalle Valo 
718d5c65159SKalle Valo 	cmd = (struct wmi_vdev_down_cmd *)skb->data;
719d5c65159SKalle Valo 
720d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) |
721d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
722d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
723d5c65159SKalle Valo 
724d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID);
725d5c65159SKalle Valo 	if (ret) {
726d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n");
727d5c65159SKalle Valo 		dev_kfree_skb(skb);
728d5c65159SKalle Valo 	}
729d5c65159SKalle Valo 
730d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev down id 0x%x\n", vdev_id);
731d5c65159SKalle Valo 
732d5c65159SKalle Valo 	return ret;
733d5c65159SKalle Valo }
734d5c65159SKalle Valo 
735d5c65159SKalle Valo static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan,
736d5c65159SKalle Valo 				       struct wmi_vdev_start_req_arg *arg)
737d5c65159SKalle Valo {
738d5c65159SKalle Valo 	memset(chan, 0, sizeof(*chan));
739d5c65159SKalle Valo 
740d5c65159SKalle Valo 	chan->mhz = arg->channel.freq;
741d5c65159SKalle Valo 	chan->band_center_freq1 = arg->channel.band_center_freq1;
742d5c65159SKalle Valo 	if (arg->channel.mode == MODE_11AC_VHT80_80)
743d5c65159SKalle Valo 		chan->band_center_freq2 = arg->channel.band_center_freq2;
744d5c65159SKalle Valo 	else
745d5c65159SKalle Valo 		chan->band_center_freq2 = 0;
746d5c65159SKalle Valo 
747d5c65159SKalle Valo 	chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode);
748d5c65159SKalle Valo 	if (arg->channel.passive)
749d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_PASSIVE;
750d5c65159SKalle Valo 	if (arg->channel.allow_ibss)
751d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED;
752d5c65159SKalle Valo 	if (arg->channel.allow_ht)
753d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ALLOW_HT;
754d5c65159SKalle Valo 	if (arg->channel.allow_vht)
755d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_ALLOW_VHT;
7569f056ed8SJohn Crispin 	if (arg->channel.allow_he)
7579f056ed8SJohn Crispin 		chan->info |= WMI_CHAN_INFO_ALLOW_HE;
758d5c65159SKalle Valo 	if (arg->channel.ht40plus)
759d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_HT40_PLUS;
760d5c65159SKalle Valo 	if (arg->channel.chan_radar)
761d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_DFS;
762d5c65159SKalle Valo 	if (arg->channel.freq2_radar)
763d5c65159SKalle Valo 		chan->info |= WMI_CHAN_INFO_DFS_FREQ2;
764d5c65159SKalle Valo 
765d5c65159SKalle Valo 	chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
766d5c65159SKalle Valo 				      arg->channel.max_power) |
767d5c65159SKalle Valo 		FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
768d5c65159SKalle Valo 			   arg->channel.max_reg_power);
769d5c65159SKalle Valo 
770d5c65159SKalle Valo 	chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
771d5c65159SKalle Valo 				      arg->channel.max_antenna_gain) |
772d5c65159SKalle Valo 		FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
773d5c65159SKalle Valo 			   arg->channel.max_power);
774d5c65159SKalle Valo }
775d5c65159SKalle Valo 
776d5c65159SKalle Valo int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg,
777d5c65159SKalle Valo 			  bool restart)
778d5c65159SKalle Valo {
779d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
780d5c65159SKalle Valo 	struct wmi_vdev_start_request_cmd *cmd;
781d5c65159SKalle Valo 	struct sk_buff *skb;
782d5c65159SKalle Valo 	struct wmi_channel *chan;
783d5c65159SKalle Valo 	struct wmi_tlv *tlv;
784d5c65159SKalle Valo 	void *ptr;
785d5c65159SKalle Valo 	int ret, len;
786d5c65159SKalle Valo 
787d5c65159SKalle Valo 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
788d5c65159SKalle Valo 		return -EINVAL;
789d5c65159SKalle Valo 
790d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE;
791d5c65159SKalle Valo 
792d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
793d5c65159SKalle Valo 	if (!skb)
794d5c65159SKalle Valo 		return -ENOMEM;
795d5c65159SKalle Valo 
796d5c65159SKalle Valo 	cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
797d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
798d5c65159SKalle Valo 				     WMI_TAG_VDEV_START_REQUEST_CMD) |
799d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
800d5c65159SKalle Valo 	cmd->vdev_id = arg->vdev_id;
801d5c65159SKalle Valo 	cmd->beacon_interval = arg->bcn_intval;
802d5c65159SKalle Valo 	cmd->bcn_tx_rate = arg->bcn_tx_rate;
803d5c65159SKalle Valo 	cmd->dtim_period = arg->dtim_period;
804d5c65159SKalle Valo 	cmd->num_noa_descriptors = arg->num_noa_descriptors;
805d5c65159SKalle Valo 	cmd->preferred_rx_streams = arg->pref_rx_streams;
806d5c65159SKalle Valo 	cmd->preferred_tx_streams = arg->pref_tx_streams;
807d5c65159SKalle Valo 	cmd->cac_duration_ms = arg->cac_duration_ms;
808d5c65159SKalle Valo 	cmd->regdomain = arg->regdomain;
809d5c65159SKalle Valo 	cmd->he_ops = arg->he_ops;
810d5c65159SKalle Valo 
811d5c65159SKalle Valo 	if (!restart) {
812d5c65159SKalle Valo 		if (arg->ssid) {
813d5c65159SKalle Valo 			cmd->ssid.ssid_len = arg->ssid_len;
814d5c65159SKalle Valo 			memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
815d5c65159SKalle Valo 		}
816d5c65159SKalle Valo 		if (arg->hidden_ssid)
817d5c65159SKalle Valo 			cmd->flags |= WMI_VDEV_START_HIDDEN_SSID;
818d5c65159SKalle Valo 		if (arg->pmf_enabled)
819d5c65159SKalle Valo 			cmd->flags |= WMI_VDEV_START_PMF_ENABLED;
820d5c65159SKalle Valo 	}
821d5c65159SKalle Valo 
822d5c65159SKalle Valo 	cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED;
823d5c65159SKalle Valo 
824d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
825d5c65159SKalle Valo 	chan = ptr;
826d5c65159SKalle Valo 
827d5c65159SKalle Valo 	ath11k_wmi_put_wmi_channel(chan, arg);
828d5c65159SKalle Valo 
829d5c65159SKalle Valo 	chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) |
830d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
831d5c65159SKalle Valo 				      sizeof(*chan) - TLV_HDR_SIZE);
832d5c65159SKalle Valo 	ptr += sizeof(*chan);
833d5c65159SKalle Valo 
834d5c65159SKalle Valo 	tlv = ptr;
835d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
836d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, 0);
837d5c65159SKalle Valo 
838d5c65159SKalle Valo 	/* Note: This is a nested TLV containing:
839d5c65159SKalle Valo 	 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
840d5c65159SKalle Valo 	 */
841d5c65159SKalle Valo 
842d5c65159SKalle Valo 	ptr += sizeof(*tlv);
843d5c65159SKalle Valo 
844d5c65159SKalle Valo 	if (restart)
845d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb,
846d5c65159SKalle Valo 					  WMI_VDEV_RESTART_REQUEST_CMDID);
847d5c65159SKalle Valo 	else
848d5c65159SKalle Valo 		ret = ath11k_wmi_cmd_send(wmi, skb,
849d5c65159SKalle Valo 					  WMI_VDEV_START_REQUEST_CMDID);
850d5c65159SKalle Valo 	if (ret) {
851d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n",
852d5c65159SKalle Valo 			    restart ? "restart" : "start");
853d5c65159SKalle Valo 		dev_kfree_skb(skb);
854d5c65159SKalle Valo 	}
855d5c65159SKalle Valo 
856d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "vdev %s id 0x%x freq 0x%x mode 0x%x\n",
857d5c65159SKalle Valo 		   restart ? "restart" : "start", arg->vdev_id,
858d5c65159SKalle Valo 		   arg->channel.freq, arg->channel.mode);
859d5c65159SKalle Valo 
860d5c65159SKalle Valo 	return ret;
861d5c65159SKalle Valo }
862d5c65159SKalle Valo 
863d5c65159SKalle Valo int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
864d5c65159SKalle Valo {
865d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
866d5c65159SKalle Valo 	struct wmi_vdev_up_cmd *cmd;
867d5c65159SKalle Valo 	struct sk_buff *skb;
868d5c65159SKalle Valo 	int ret;
869d5c65159SKalle Valo 
870d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
871d5c65159SKalle Valo 	if (!skb)
872d5c65159SKalle Valo 		return -ENOMEM;
873d5c65159SKalle Valo 
874d5c65159SKalle Valo 	cmd = (struct wmi_vdev_up_cmd *)skb->data;
875d5c65159SKalle Valo 
876d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) |
877d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
878d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
879d5c65159SKalle Valo 	cmd->vdev_assoc_id = aid;
880d5c65159SKalle Valo 
881d5c65159SKalle Valo 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
882d5c65159SKalle Valo 
883d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID);
884d5c65159SKalle Valo 	if (ret) {
885d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n");
886d5c65159SKalle Valo 		dev_kfree_skb(skb);
887d5c65159SKalle Valo 	}
888d5c65159SKalle Valo 
889d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
890d5c65159SKalle Valo 		   "WMI mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
891d5c65159SKalle Valo 		   vdev_id, aid, bssid);
892d5c65159SKalle Valo 
893d5c65159SKalle Valo 	return ret;
894d5c65159SKalle Valo }
895d5c65159SKalle Valo 
896d5c65159SKalle Valo int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar,
897d5c65159SKalle Valo 				    struct peer_create_params *param)
898d5c65159SKalle Valo {
899d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
900d5c65159SKalle Valo 	struct wmi_peer_create_cmd *cmd;
901d5c65159SKalle Valo 	struct sk_buff *skb;
902d5c65159SKalle Valo 	int ret;
903d5c65159SKalle Valo 
904d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
905d5c65159SKalle Valo 	if (!skb)
906d5c65159SKalle Valo 		return -ENOMEM;
907d5c65159SKalle Valo 
908d5c65159SKalle Valo 	cmd = (struct wmi_peer_create_cmd *)skb->data;
909d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) |
910d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
911d5c65159SKalle Valo 
912d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr);
913d5c65159SKalle Valo 	cmd->peer_type = param->peer_type;
914d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
915d5c65159SKalle Valo 
916d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID);
917d5c65159SKalle Valo 	if (ret) {
918d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n");
919d5c65159SKalle Valo 		dev_kfree_skb(skb);
920d5c65159SKalle Valo 	}
921d5c65159SKalle Valo 
922d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
923d5c65159SKalle Valo 		   "WMI peer create vdev_id %d peer_addr %pM\n",
924d5c65159SKalle Valo 		   param->vdev_id, param->peer_addr);
925d5c65159SKalle Valo 
926d5c65159SKalle Valo 	return ret;
927d5c65159SKalle Valo }
928d5c65159SKalle Valo 
929d5c65159SKalle Valo int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar,
930d5c65159SKalle Valo 				    const u8 *peer_addr, u8 vdev_id)
931d5c65159SKalle Valo {
932d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
933d5c65159SKalle Valo 	struct wmi_peer_delete_cmd *cmd;
934d5c65159SKalle Valo 	struct sk_buff *skb;
935d5c65159SKalle Valo 	int ret;
936d5c65159SKalle Valo 
937d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
938d5c65159SKalle Valo 	if (!skb)
939d5c65159SKalle Valo 		return -ENOMEM;
940d5c65159SKalle Valo 
941d5c65159SKalle Valo 	cmd = (struct wmi_peer_delete_cmd *)skb->data;
942d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) |
943d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
944d5c65159SKalle Valo 
945d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
946d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
947d5c65159SKalle Valo 
948d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
949d5c65159SKalle Valo 		   "WMI peer delete vdev_id %d peer_addr %pM\n",
950d5c65159SKalle Valo 		   vdev_id,  peer_addr);
951d5c65159SKalle Valo 
952d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID);
953d5c65159SKalle Valo 	if (ret) {
954d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n");
955d5c65159SKalle Valo 		dev_kfree_skb(skb);
956d5c65159SKalle Valo 	}
957d5c65159SKalle Valo 
958d5c65159SKalle Valo 	return ret;
959d5c65159SKalle Valo }
960d5c65159SKalle Valo 
961d5c65159SKalle Valo int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar,
962d5c65159SKalle Valo 				       struct pdev_set_regdomain_params *param)
963d5c65159SKalle Valo {
964d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
965d5c65159SKalle Valo 	struct wmi_pdev_set_regdomain_cmd *cmd;
966d5c65159SKalle Valo 	struct sk_buff *skb;
967d5c65159SKalle Valo 	int ret;
968d5c65159SKalle Valo 
969d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
970d5c65159SKalle Valo 	if (!skb)
971d5c65159SKalle Valo 		return -ENOMEM;
972d5c65159SKalle Valo 
973d5c65159SKalle Valo 	cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
974d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
975d5c65159SKalle Valo 				     WMI_TAG_PDEV_SET_REGDOMAIN_CMD) |
976d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
977d5c65159SKalle Valo 
978d5c65159SKalle Valo 	cmd->reg_domain = param->current_rd_in_use;
979d5c65159SKalle Valo 	cmd->reg_domain_2g = param->current_rd_2g;
980d5c65159SKalle Valo 	cmd->reg_domain_5g = param->current_rd_5g;
981d5c65159SKalle Valo 	cmd->conformance_test_limit_2g = param->ctl_2g;
982d5c65159SKalle Valo 	cmd->conformance_test_limit_5g = param->ctl_5g;
983d5c65159SKalle Valo 	cmd->dfs_domain = param->dfs_domain;
984d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
985d5c65159SKalle Valo 
986d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
987d5c65159SKalle Valo 		   "WMI pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n",
988d5c65159SKalle Valo 		   param->current_rd_in_use, param->current_rd_2g,
989d5c65159SKalle Valo 		   param->current_rd_5g, param->dfs_domain, param->pdev_id);
990d5c65159SKalle Valo 
991d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
992d5c65159SKalle Valo 	if (ret) {
993d5c65159SKalle Valo 		ath11k_warn(ar->ab,
994d5c65159SKalle Valo 			    "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n");
995d5c65159SKalle Valo 		dev_kfree_skb(skb);
996d5c65159SKalle Valo 	}
997d5c65159SKalle Valo 
998d5c65159SKalle Valo 	return ret;
999d5c65159SKalle Valo }
1000d5c65159SKalle Valo 
1001d5c65159SKalle Valo int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr,
1002d5c65159SKalle Valo 			      u32 vdev_id, u32 param_id, u32 param_val)
1003d5c65159SKalle Valo {
1004d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1005d5c65159SKalle Valo 	struct wmi_peer_set_param_cmd *cmd;
1006d5c65159SKalle Valo 	struct sk_buff *skb;
1007d5c65159SKalle Valo 	int ret;
1008d5c65159SKalle Valo 
1009d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1010d5c65159SKalle Valo 	if (!skb)
1011d5c65159SKalle Valo 		return -ENOMEM;
1012d5c65159SKalle Valo 
1013d5c65159SKalle Valo 	cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1014d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) |
1015d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1016d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1017d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1018d5c65159SKalle Valo 	cmd->param_id = param_id;
1019d5c65159SKalle Valo 	cmd->param_value = param_val;
1020d5c65159SKalle Valo 
1021d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID);
1022d5c65159SKalle Valo 	if (ret) {
1023d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n");
1024d5c65159SKalle Valo 		dev_kfree_skb(skb);
1025d5c65159SKalle Valo 	}
1026d5c65159SKalle Valo 
1027d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1028d5c65159SKalle Valo 		   "WMI vdev %d peer 0x%pM set param %d value %d\n",
1029d5c65159SKalle Valo 		   vdev_id, peer_addr, param_id, param_val);
1030d5c65159SKalle Valo 
1031d5c65159SKalle Valo 	return ret;
1032d5c65159SKalle Valo }
1033d5c65159SKalle Valo 
1034d5c65159SKalle Valo int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar,
1035d5c65159SKalle Valo 					u8 peer_addr[ETH_ALEN],
1036d5c65159SKalle Valo 					struct peer_flush_params *param)
1037d5c65159SKalle Valo {
1038d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1039d5c65159SKalle Valo 	struct wmi_peer_flush_tids_cmd *cmd;
1040d5c65159SKalle Valo 	struct sk_buff *skb;
1041d5c65159SKalle Valo 	int ret;
1042d5c65159SKalle Valo 
1043d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1044d5c65159SKalle Valo 	if (!skb)
1045d5c65159SKalle Valo 		return -ENOMEM;
1046d5c65159SKalle Valo 
1047d5c65159SKalle Valo 	cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1048d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) |
1049d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1050d5c65159SKalle Valo 
1051d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1052d5c65159SKalle Valo 	cmd->peer_tid_bitmap = param->peer_tid_bitmap;
1053d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1054d5c65159SKalle Valo 
1055d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1056d5c65159SKalle Valo 	if (ret) {
1057d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1058d5c65159SKalle Valo 			    "failed to send WMI_PEER_FLUSH_TIDS cmd\n");
1059d5c65159SKalle Valo 		dev_kfree_skb(skb);
1060d5c65159SKalle Valo 	}
1061d5c65159SKalle Valo 
1062d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1063d5c65159SKalle Valo 		   "WMI peer flush vdev_id %d peer_addr %pM tids %08x\n",
1064d5c65159SKalle Valo 		   param->vdev_id, peer_addr, param->peer_tid_bitmap);
1065d5c65159SKalle Valo 
1066d5c65159SKalle Valo 	return ret;
1067d5c65159SKalle Valo }
1068d5c65159SKalle Valo 
1069d5c65159SKalle Valo int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar,
1070d5c65159SKalle Valo 					   int vdev_id, const u8 *addr,
1071d5c65159SKalle Valo 					   dma_addr_t paddr, u8 tid,
1072d5c65159SKalle Valo 					   u8 ba_window_size_valid,
1073d5c65159SKalle Valo 					   u32 ba_window_size)
1074d5c65159SKalle Valo {
1075d5c65159SKalle Valo 	struct wmi_peer_reorder_queue_setup_cmd *cmd;
1076d5c65159SKalle Valo 	struct sk_buff *skb;
1077d5c65159SKalle Valo 	int ret;
1078d5c65159SKalle Valo 
1079d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_sc, sizeof(*cmd));
1080d5c65159SKalle Valo 	if (!skb)
1081d5c65159SKalle Valo 		return -ENOMEM;
1082d5c65159SKalle Valo 
1083d5c65159SKalle Valo 	cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data;
1084d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1085d5c65159SKalle Valo 				     WMI_TAG_REORDER_QUEUE_SETUP_CMD) |
1086d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1087d5c65159SKalle Valo 
1088d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, addr);
1089d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1090d5c65159SKalle Valo 	cmd->tid = tid;
1091d5c65159SKalle Valo 	cmd->queue_ptr_lo = lower_32_bits(paddr);
1092d5c65159SKalle Valo 	cmd->queue_ptr_hi = upper_32_bits(paddr);
1093d5c65159SKalle Valo 	cmd->queue_no = tid;
1094d5c65159SKalle Valo 	cmd->ba_window_size_valid = ba_window_size_valid;
1095d5c65159SKalle Valo 	cmd->ba_window_size = ba_window_size;
1096d5c65159SKalle Valo 
1097d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(ar->wmi, skb,
1098d5c65159SKalle Valo 				  WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1099d5c65159SKalle Valo 	if (ret) {
1100d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1101d5c65159SKalle Valo 			    "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n");
1102d5c65159SKalle Valo 		dev_kfree_skb(skb);
1103d5c65159SKalle Valo 	}
1104d5c65159SKalle Valo 
1105d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1106d5c65159SKalle Valo 		   "wmi rx reorder queue setup addr %pM vdev_id %d tid %d\n",
1107d5c65159SKalle Valo 		   addr, vdev_id, tid);
1108d5c65159SKalle Valo 
1109d5c65159SKalle Valo 	return ret;
1110d5c65159SKalle Valo }
1111d5c65159SKalle Valo 
1112d5c65159SKalle Valo int
1113d5c65159SKalle Valo ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar,
1114d5c65159SKalle Valo 				 struct rx_reorder_queue_remove_params *param)
1115d5c65159SKalle Valo {
1116d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1117d5c65159SKalle Valo 	struct wmi_peer_reorder_queue_remove_cmd *cmd;
1118d5c65159SKalle Valo 	struct sk_buff *skb;
1119d5c65159SKalle Valo 	int ret;
1120d5c65159SKalle Valo 
1121d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1122d5c65159SKalle Valo 	if (!skb)
1123d5c65159SKalle Valo 		return -ENOMEM;
1124d5c65159SKalle Valo 
1125d5c65159SKalle Valo 	cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data;
1126d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1127d5c65159SKalle Valo 				     WMI_TAG_REORDER_QUEUE_REMOVE_CMD) |
1128d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1129d5c65159SKalle Valo 
1130d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr);
1131d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1132d5c65159SKalle Valo 	cmd->tid_mask = param->peer_tid_bitmap;
1133d5c65159SKalle Valo 
1134d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1135d5c65159SKalle Valo 		   "%s: peer_macaddr %pM vdev_id %d, tid_map %d", __func__,
1136d5c65159SKalle Valo 		   param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap);
1137d5c65159SKalle Valo 
1138d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
1139d5c65159SKalle Valo 				  WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
1140d5c65159SKalle Valo 	if (ret) {
1141d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1142d5c65159SKalle Valo 			    "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID");
1143d5c65159SKalle Valo 		dev_kfree_skb(skb);
1144d5c65159SKalle Valo 	}
1145d5c65159SKalle Valo 
1146d5c65159SKalle Valo 	return ret;
1147d5c65159SKalle Valo }
1148d5c65159SKalle Valo 
1149d5c65159SKalle Valo int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id,
1150d5c65159SKalle Valo 			      u32 param_value, u8 pdev_id)
1151d5c65159SKalle Valo {
1152d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1153d5c65159SKalle Valo 	struct wmi_pdev_set_param_cmd *cmd;
1154d5c65159SKalle Valo 	struct sk_buff *skb;
1155d5c65159SKalle Valo 	int ret;
1156d5c65159SKalle Valo 
1157d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1158d5c65159SKalle Valo 	if (!skb)
1159d5c65159SKalle Valo 		return -ENOMEM;
1160d5c65159SKalle Valo 
1161d5c65159SKalle Valo 	cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1162d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) |
1163d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1164d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1165d5c65159SKalle Valo 	cmd->param_id = param_id;
1166d5c65159SKalle Valo 	cmd->param_value = param_value;
1167d5c65159SKalle Valo 
1168d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID);
1169d5c65159SKalle Valo 	if (ret) {
1170d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1171d5c65159SKalle Valo 		dev_kfree_skb(skb);
1172d5c65159SKalle Valo 	}
1173d5c65159SKalle Valo 
1174d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1175d5c65159SKalle Valo 		   "WMI pdev set param %d pdev id %d value %d\n",
1176d5c65159SKalle Valo 		   param_id, pdev_id, param_value);
1177d5c65159SKalle Valo 
1178d5c65159SKalle Valo 	return ret;
1179d5c65159SKalle Valo }
1180d5c65159SKalle Valo 
1181d5c65159SKalle Valo int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt,
1182d5c65159SKalle Valo 			    u32 pdev_id)
1183d5c65159SKalle Valo {
1184d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1185d5c65159SKalle Valo 	struct wmi_pdev_suspend_cmd *cmd;
1186d5c65159SKalle Valo 	struct sk_buff *skb;
1187d5c65159SKalle Valo 	int ret;
1188d5c65159SKalle Valo 
1189d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1190d5c65159SKalle Valo 	if (!skb)
1191d5c65159SKalle Valo 		return -ENOMEM;
1192d5c65159SKalle Valo 
1193d5c65159SKalle Valo 	cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1194d5c65159SKalle Valo 
1195d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) |
1196d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1197d5c65159SKalle Valo 
1198d5c65159SKalle Valo 	cmd->suspend_opt = suspend_opt;
1199d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1200d5c65159SKalle Valo 
1201d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID);
1202d5c65159SKalle Valo 	if (ret) {
1203d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n");
1204d5c65159SKalle Valo 		dev_kfree_skb(skb);
1205d5c65159SKalle Valo 	}
1206d5c65159SKalle Valo 
1207d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1208d5c65159SKalle Valo 		   "WMI pdev suspend pdev_id %d\n", pdev_id);
1209d5c65159SKalle Valo 
1210d5c65159SKalle Valo 	return ret;
1211d5c65159SKalle Valo }
1212d5c65159SKalle Valo 
1213d5c65159SKalle Valo int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id)
1214d5c65159SKalle Valo {
1215d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1216d5c65159SKalle Valo 	struct wmi_pdev_resume_cmd *cmd;
1217d5c65159SKalle Valo 	struct sk_buff *skb;
1218d5c65159SKalle Valo 	int ret;
1219d5c65159SKalle Valo 
1220d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1221d5c65159SKalle Valo 	if (!skb)
1222d5c65159SKalle Valo 		return -ENOMEM;
1223d5c65159SKalle Valo 
1224d5c65159SKalle Valo 	cmd = (struct wmi_pdev_resume_cmd *)skb->data;
1225d5c65159SKalle Valo 
1226d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) |
1227d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1228d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
1229d5c65159SKalle Valo 
1230d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1231d5c65159SKalle Valo 		   "WMI pdev resume pdev id %d\n", pdev_id);
1232d5c65159SKalle Valo 
1233d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID);
1234d5c65159SKalle Valo 	if (ret) {
1235d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n");
1236d5c65159SKalle Valo 		dev_kfree_skb(skb);
1237d5c65159SKalle Valo 	}
1238d5c65159SKalle Valo 
1239d5c65159SKalle Valo 	return ret;
1240d5c65159SKalle Valo }
1241d5c65159SKalle Valo 
1242d5c65159SKalle Valo /* TODO FW Support for the cmd is not available yet.
1243d5c65159SKalle Valo  * Can be tested once the command and corresponding
1244d5c65159SKalle Valo  * event is implemented in FW
1245d5c65159SKalle Valo  */
1246d5c65159SKalle Valo int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar,
1247d5c65159SKalle Valo 					  enum wmi_bss_chan_info_req_type type)
1248d5c65159SKalle Valo {
1249d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1250d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_req_cmd *cmd;
1251d5c65159SKalle Valo 	struct sk_buff *skb;
1252d5c65159SKalle Valo 	int ret;
1253d5c65159SKalle Valo 
1254d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1255d5c65159SKalle Valo 	if (!skb)
1256d5c65159SKalle Valo 		return -ENOMEM;
1257d5c65159SKalle Valo 
1258d5c65159SKalle Valo 	cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data;
1259d5c65159SKalle Valo 
1260d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1261d5c65159SKalle Valo 				     WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) |
1262d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1263d5c65159SKalle Valo 	cmd->req_type = type;
1264d5c65159SKalle Valo 
1265d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1266d5c65159SKalle Valo 		   "WMI bss chan info req type %d\n", type);
1267d5c65159SKalle Valo 
1268d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
1269d5c65159SKalle Valo 				  WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID);
1270d5c65159SKalle Valo 	if (ret) {
1271d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1272d5c65159SKalle Valo 			    "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n");
1273d5c65159SKalle Valo 		dev_kfree_skb(skb);
1274d5c65159SKalle Valo 	}
1275d5c65159SKalle Valo 
1276d5c65159SKalle Valo 	return ret;
1277d5c65159SKalle Valo }
1278d5c65159SKalle Valo 
1279d5c65159SKalle Valo int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr,
1280d5c65159SKalle Valo 					struct ap_ps_params *param)
1281d5c65159SKalle Valo {
1282d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1283d5c65159SKalle Valo 	struct wmi_ap_ps_peer_cmd *cmd;
1284d5c65159SKalle Valo 	struct sk_buff *skb;
1285d5c65159SKalle Valo 	int ret;
1286d5c65159SKalle Valo 
1287d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1288d5c65159SKalle Valo 	if (!skb)
1289d5c65159SKalle Valo 		return -ENOMEM;
1290d5c65159SKalle Valo 
1291d5c65159SKalle Valo 	cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1292d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) |
1293d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1294d5c65159SKalle Valo 
1295d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1296d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1297d5c65159SKalle Valo 	cmd->param = param->param;
1298d5c65159SKalle Valo 	cmd->value = param->value;
1299d5c65159SKalle Valo 
1300d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1301d5c65159SKalle Valo 	if (ret) {
1302d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1303d5c65159SKalle Valo 			    "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n");
1304d5c65159SKalle Valo 		dev_kfree_skb(skb);
1305d5c65159SKalle Valo 	}
1306d5c65159SKalle Valo 
1307d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1308d5c65159SKalle Valo 		   "WMI set ap ps vdev id %d peer %pM param %d value %d\n",
1309d5c65159SKalle Valo 		   param->vdev_id, peer_addr, param->param, param->value);
1310d5c65159SKalle Valo 
1311d5c65159SKalle Valo 	return ret;
1312d5c65159SKalle Valo }
1313d5c65159SKalle Valo 
1314d5c65159SKalle Valo int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id,
1315d5c65159SKalle Valo 				u32 param, u32 param_value)
1316d5c65159SKalle Valo {
1317d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1318d5c65159SKalle Valo 	struct wmi_sta_powersave_param_cmd *cmd;
1319d5c65159SKalle Valo 	struct sk_buff *skb;
1320d5c65159SKalle Valo 	int ret;
1321d5c65159SKalle Valo 
1322d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1323d5c65159SKalle Valo 	if (!skb)
1324d5c65159SKalle Valo 		return -ENOMEM;
1325d5c65159SKalle Valo 
1326d5c65159SKalle Valo 	cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1327d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1328d5c65159SKalle Valo 				     WMI_TAG_STA_POWERSAVE_PARAM_CMD) |
1329d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1330d5c65159SKalle Valo 
1331d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1332d5c65159SKalle Valo 	cmd->param = param;
1333d5c65159SKalle Valo 	cmd->value = param_value;
1334d5c65159SKalle Valo 
1335d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1336d5c65159SKalle Valo 		   "WMI set sta ps vdev_id %d param %d value %d\n",
1337d5c65159SKalle Valo 		   vdev_id, param, param_value);
1338d5c65159SKalle Valo 
1339d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1340d5c65159SKalle Valo 	if (ret) {
1341d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID");
1342d5c65159SKalle Valo 		dev_kfree_skb(skb);
1343d5c65159SKalle Valo 	}
1344d5c65159SKalle Valo 
1345d5c65159SKalle Valo 	return ret;
1346d5c65159SKalle Valo }
1347d5c65159SKalle Valo 
1348d5c65159SKalle Valo int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms)
1349d5c65159SKalle Valo {
1350d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1351d5c65159SKalle Valo 	struct wmi_force_fw_hang_cmd *cmd;
1352d5c65159SKalle Valo 	struct sk_buff *skb;
1353d5c65159SKalle Valo 	int ret, len;
1354d5c65159SKalle Valo 
1355d5c65159SKalle Valo 	len = sizeof(*cmd);
1356d5c65159SKalle Valo 
1357d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
1358d5c65159SKalle Valo 	if (!skb)
1359d5c65159SKalle Valo 		return -ENOMEM;
1360d5c65159SKalle Valo 
1361d5c65159SKalle Valo 	cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
1362d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) |
1363d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1364d5c65159SKalle Valo 
1365d5c65159SKalle Valo 	cmd->type = type;
1366d5c65159SKalle Valo 	cmd->delay_time_ms = delay_time_ms;
1367d5c65159SKalle Valo 
1368d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID);
1369d5c65159SKalle Valo 
1370d5c65159SKalle Valo 	if (ret) {
1371d5c65159SKalle Valo 		ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID");
1372d5c65159SKalle Valo 		dev_kfree_skb(skb);
1373d5c65159SKalle Valo 	}
1374d5c65159SKalle Valo 	return ret;
1375d5c65159SKalle Valo }
1376d5c65159SKalle Valo 
1377d5c65159SKalle Valo int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id,
1378d5c65159SKalle Valo 				  u32 param_id, u32 param_value)
1379d5c65159SKalle Valo {
1380d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1381d5c65159SKalle Valo 	struct wmi_vdev_set_param_cmd *cmd;
1382d5c65159SKalle Valo 	struct sk_buff *skb;
1383d5c65159SKalle Valo 	int ret;
1384d5c65159SKalle Valo 
1385d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1386d5c65159SKalle Valo 	if (!skb)
1387d5c65159SKalle Valo 		return -ENOMEM;
1388d5c65159SKalle Valo 
1389d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1390d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) |
1391d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1392d5c65159SKalle Valo 
1393d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1394d5c65159SKalle Valo 	cmd->param_id = param_id;
1395d5c65159SKalle Valo 	cmd->param_value = param_value;
1396d5c65159SKalle Valo 
1397d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID);
1398d5c65159SKalle Valo 	if (ret) {
1399d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1400d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_PARAM_CMDID\n");
1401d5c65159SKalle Valo 		dev_kfree_skb(skb);
1402d5c65159SKalle Valo 	}
1403d5c65159SKalle Valo 
1404d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1405d5c65159SKalle Valo 		   "WMI vdev id 0x%x set param %d value %d\n",
1406d5c65159SKalle Valo 		   vdev_id, param_id, param_value);
1407d5c65159SKalle Valo 
1408d5c65159SKalle Valo 	return ret;
1409d5c65159SKalle Valo }
1410d5c65159SKalle Valo 
1411d5c65159SKalle Valo int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar,
1412d5c65159SKalle Valo 				      struct stats_request_params *param)
1413d5c65159SKalle Valo {
1414d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1415d5c65159SKalle Valo 	struct wmi_request_stats_cmd *cmd;
1416d5c65159SKalle Valo 	struct sk_buff *skb;
1417d5c65159SKalle Valo 	int ret;
1418d5c65159SKalle Valo 
1419d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1420d5c65159SKalle Valo 	if (!skb)
1421d5c65159SKalle Valo 		return -ENOMEM;
1422d5c65159SKalle Valo 
1423d5c65159SKalle Valo 	cmd = (struct wmi_request_stats_cmd *)skb->data;
1424d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) |
1425d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1426d5c65159SKalle Valo 
1427d5c65159SKalle Valo 	cmd->stats_id = param->stats_id;
1428d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1429d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
1430d5c65159SKalle Valo 
1431d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID);
1432d5c65159SKalle Valo 	if (ret) {
1433d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n");
1434d5c65159SKalle Valo 		dev_kfree_skb(skb);
1435d5c65159SKalle Valo 	}
1436d5c65159SKalle Valo 
1437d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1438d5c65159SKalle Valo 		   "WMI request stats 0x%x vdev id %d pdev id %d\n",
1439d5c65159SKalle Valo 		   param->stats_id, param->vdev_id, param->pdev_id);
1440d5c65159SKalle Valo 
1441d5c65159SKalle Valo 	return ret;
1442d5c65159SKalle Valo }
1443d5c65159SKalle Valo 
1444d5c65159SKalle Valo int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar,
1445d5c65159SKalle Valo 					    u32 vdev_id, u32 bcn_ctrl_op)
1446d5c65159SKalle Valo {
1447d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1448d5c65159SKalle Valo 	struct wmi_bcn_offload_ctrl_cmd *cmd;
1449d5c65159SKalle Valo 	struct sk_buff *skb;
1450d5c65159SKalle Valo 	int ret;
1451d5c65159SKalle Valo 
1452d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
1453d5c65159SKalle Valo 	if (!skb)
1454d5c65159SKalle Valo 		return -ENOMEM;
1455d5c65159SKalle Valo 
1456d5c65159SKalle Valo 	cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data;
1457d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1458d5c65159SKalle Valo 				     WMI_TAG_BCN_OFFLOAD_CTRL_CMD) |
1459d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1460d5c65159SKalle Valo 
1461d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1462d5c65159SKalle Valo 	cmd->bcn_ctrl_op = bcn_ctrl_op;
1463d5c65159SKalle Valo 
1464d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1465d5c65159SKalle Valo 		   "WMI bcn ctrl offload vdev id %d ctrl_op %d\n",
1466d5c65159SKalle Valo 		   vdev_id, bcn_ctrl_op);
1467d5c65159SKalle Valo 
1468d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID);
1469d5c65159SKalle Valo 	if (ret) {
1470d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1471d5c65159SKalle Valo 			    "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n");
1472d5c65159SKalle Valo 		dev_kfree_skb(skb);
1473d5c65159SKalle Valo 	}
1474d5c65159SKalle Valo 
1475d5c65159SKalle Valo 	return ret;
1476d5c65159SKalle Valo }
1477d5c65159SKalle Valo 
1478d5c65159SKalle Valo int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id,
1479d5c65159SKalle Valo 			struct ieee80211_mutable_offsets *offs,
1480d5c65159SKalle Valo 			struct sk_buff *bcn)
1481d5c65159SKalle Valo {
1482d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1483d5c65159SKalle Valo 	struct wmi_bcn_tmpl_cmd *cmd;
1484d5c65159SKalle Valo 	struct wmi_bcn_prb_info *bcn_prb_info;
1485d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1486d5c65159SKalle Valo 	struct sk_buff *skb;
1487d5c65159SKalle Valo 	void *ptr;
1488d5c65159SKalle Valo 	int ret, len;
1489d5c65159SKalle Valo 	size_t aligned_len = roundup(bcn->len, 4);
1490d5c65159SKalle Valo 
1491d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len;
1492d5c65159SKalle Valo 
1493d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
1494d5c65159SKalle Valo 	if (!skb)
1495d5c65159SKalle Valo 		return -ENOMEM;
1496d5c65159SKalle Valo 
1497d5c65159SKalle Valo 	cmd = (struct wmi_bcn_tmpl_cmd *)skb->data;
1498d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) |
1499d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1500d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
1501d5c65159SKalle Valo 	cmd->tim_ie_offset = offs->tim_offset;
1502d5c65159SKalle Valo 	cmd->csa_switch_count_offset = offs->csa_counter_offs[0];
1503d5c65159SKalle Valo 	cmd->ext_csa_switch_count_offset = offs->csa_counter_offs[1];
1504d5c65159SKalle Valo 	cmd->buf_len = bcn->len;
1505d5c65159SKalle Valo 
1506d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
1507d5c65159SKalle Valo 
1508d5c65159SKalle Valo 	bcn_prb_info = ptr;
1509d5c65159SKalle Valo 	len = sizeof(*bcn_prb_info);
1510d5c65159SKalle Valo 	bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1511d5c65159SKalle Valo 					      WMI_TAG_BCN_PRB_INFO) |
1512d5c65159SKalle Valo 				   FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1513d5c65159SKalle Valo 	bcn_prb_info->caps = 0;
1514d5c65159SKalle Valo 	bcn_prb_info->erp = 0;
1515d5c65159SKalle Valo 
1516d5c65159SKalle Valo 	ptr += sizeof(*bcn_prb_info);
1517d5c65159SKalle Valo 
1518d5c65159SKalle Valo 	tlv = ptr;
1519d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1520d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, aligned_len);
1521d5c65159SKalle Valo 	memcpy(tlv->value, bcn->data, bcn->len);
1522d5c65159SKalle Valo 
1523d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID);
1524d5c65159SKalle Valo 	if (ret) {
1525d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n");
1526d5c65159SKalle Valo 		dev_kfree_skb(skb);
1527d5c65159SKalle Valo 	}
1528d5c65159SKalle Valo 
1529d5c65159SKalle Valo 	return ret;
1530d5c65159SKalle Valo }
1531d5c65159SKalle Valo 
1532d5c65159SKalle Valo int ath11k_wmi_vdev_install_key(struct ath11k *ar,
1533d5c65159SKalle Valo 				struct wmi_vdev_install_key_arg *arg)
1534d5c65159SKalle Valo {
1535d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1536d5c65159SKalle Valo 	struct wmi_vdev_install_key_cmd *cmd;
1537d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1538d5c65159SKalle Valo 	struct sk_buff *skb;
1539d5c65159SKalle Valo 	int ret, len;
1540d5c65159SKalle Valo 	int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t));
1541d5c65159SKalle Valo 
1542d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned;
1543d5c65159SKalle Valo 
1544d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
1545d5c65159SKalle Valo 	if (!skb)
1546d5c65159SKalle Valo 		return -ENOMEM;
1547d5c65159SKalle Valo 
1548d5c65159SKalle Valo 	cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1549d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) |
1550d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1551d5c65159SKalle Valo 	cmd->vdev_id = arg->vdev_id;
1552d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1553d5c65159SKalle Valo 	cmd->key_idx = arg->key_idx;
1554d5c65159SKalle Valo 	cmd->key_flags = arg->key_flags;
1555d5c65159SKalle Valo 	cmd->key_cipher = arg->key_cipher;
1556d5c65159SKalle Valo 	cmd->key_len = arg->key_len;
1557d5c65159SKalle Valo 	cmd->key_txmic_len = arg->key_txmic_len;
1558d5c65159SKalle Valo 	cmd->key_rxmic_len = arg->key_rxmic_len;
1559d5c65159SKalle Valo 
1560d5c65159SKalle Valo 	if (arg->key_rsc_counter)
1561d5c65159SKalle Valo 		memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter,
1562d5c65159SKalle Valo 		       sizeof(struct wmi_key_seq_counter));
1563d5c65159SKalle Valo 
1564d5c65159SKalle Valo 	tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
1565d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1566d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, key_len_aligned);
1567d5c65159SKalle Valo 	memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned);
1568d5c65159SKalle Valo 
1569d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1570d5c65159SKalle Valo 	if (ret) {
1571d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1572d5c65159SKalle Valo 			    "failed to send WMI_VDEV_INSTALL_KEY cmd\n");
1573d5c65159SKalle Valo 		dev_kfree_skb(skb);
1574d5c65159SKalle Valo 	}
1575d5c65159SKalle Valo 
1576d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1577d5c65159SKalle Valo 		   "WMI vdev install key idx %d cipher %d len %d\n",
1578d5c65159SKalle Valo 		   arg->key_idx, arg->key_cipher, arg->key_len);
1579d5c65159SKalle Valo 
1580d5c65159SKalle Valo 	return ret;
1581d5c65159SKalle Valo }
1582d5c65159SKalle Valo 
1583d5c65159SKalle Valo static inline void
1584d5c65159SKalle Valo ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd,
1585d5c65159SKalle Valo 			   struct peer_assoc_params *param)
1586d5c65159SKalle Valo {
1587d5c65159SKalle Valo 	cmd->peer_flags = 0;
1588d5c65159SKalle Valo 
1589d5c65159SKalle Valo 	if (param->is_wme_set) {
1590d5c65159SKalle Valo 		if (param->qos_flag)
1591d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_QOS;
1592d5c65159SKalle Valo 		if (param->apsd_flag)
1593d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_APSD;
1594d5c65159SKalle Valo 		if (param->ht_flag)
1595d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_HT;
1596d5c65159SKalle Valo 		if (param->bw_40)
1597d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_40MHZ;
1598d5c65159SKalle Valo 		if (param->bw_80)
1599d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_80MHZ;
1600d5c65159SKalle Valo 		if (param->bw_160)
1601d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_160MHZ;
1602d5c65159SKalle Valo 
1603d5c65159SKalle Valo 		/* Typically if STBC is enabled for VHT it should be enabled
1604d5c65159SKalle Valo 		 * for HT as well
1605d5c65159SKalle Valo 		 **/
1606d5c65159SKalle Valo 		if (param->stbc_flag)
1607d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_STBC;
1608d5c65159SKalle Valo 
1609d5c65159SKalle Valo 		/* Typically if LDPC is enabled for VHT it should be enabled
1610d5c65159SKalle Valo 		 * for HT as well
1611d5c65159SKalle Valo 		 **/
1612d5c65159SKalle Valo 		if (param->ldpc_flag)
1613d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_LDPC;
1614d5c65159SKalle Valo 
1615d5c65159SKalle Valo 		if (param->static_mimops_flag)
1616d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1617d5c65159SKalle Valo 		if (param->dynamic_mimops_flag)
1618d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_DYN_MIMOPS;
1619d5c65159SKalle Valo 		if (param->spatial_mux_flag)
1620d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_SPATIAL_MUX;
1621d5c65159SKalle Valo 		if (param->vht_flag)
1622d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_VHT;
1623d5c65159SKalle Valo 		if (param->he_flag)
1624d5c65159SKalle Valo 			cmd->peer_flags |= WMI_PEER_HE;
16256d293d44SJohn Crispin 		if (param->twt_requester)
16266d293d44SJohn Crispin 			cmd->peer_flags |= WMI_PEER_TWT_REQ;
16276d293d44SJohn Crispin 		if (param->twt_responder)
16286d293d44SJohn Crispin 			cmd->peer_flags |= WMI_PEER_TWT_RESP;
1629d5c65159SKalle Valo 	}
1630d5c65159SKalle Valo 
1631d5c65159SKalle Valo 	/* Suppress authorization for all AUTH modes that need 4-way handshake
1632d5c65159SKalle Valo 	 * (during re-association).
1633d5c65159SKalle Valo 	 * Authorization will be done for these modes on key installation.
1634d5c65159SKalle Valo 	 */
1635d5c65159SKalle Valo 	if (param->auth_flag)
1636d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_AUTH;
1637d5c65159SKalle Valo 	if (param->need_ptk_4_way)
1638d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1639d5c65159SKalle Valo 	else
1640d5c65159SKalle Valo 		cmd->peer_flags &= ~WMI_PEER_NEED_PTK_4_WAY;
1641d5c65159SKalle Valo 	if (param->need_gtk_2_way)
1642d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1643d5c65159SKalle Valo 	/* safe mode bypass the 4-way handshake */
1644d5c65159SKalle Valo 	if (param->safe_mode_enabled)
1645d5c65159SKalle Valo 		cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY |
1646d5c65159SKalle Valo 				     WMI_PEER_NEED_GTK_2_WAY);
1647d5c65159SKalle Valo 
1648d5c65159SKalle Valo 	if (param->is_pmf_enabled)
1649d5c65159SKalle Valo 		cmd->peer_flags |= WMI_PEER_PMF;
1650d5c65159SKalle Valo 
1651d5c65159SKalle Valo 	/* Disable AMSDU for station transmit, if user configures it */
1652d5c65159SKalle Valo 	/* Disable AMSDU for AP transmit to 11n Stations, if user configures
1653d5c65159SKalle Valo 	 * it
1654d5c65159SKalle Valo 	 * if (param->amsdu_disable) Add after FW support
1655d5c65159SKalle Valo 	 **/
1656d5c65159SKalle Valo 
1657d5c65159SKalle Valo 	/* Target asserts if node is marked HT and all MCS is set to 0.
1658d5c65159SKalle Valo 	 * Mark the node as non-HT if all the mcs rates are disabled through
1659d5c65159SKalle Valo 	 * iwpriv
1660d5c65159SKalle Valo 	 **/
1661d5c65159SKalle Valo 	if (param->peer_ht_rates.num_rates == 0)
1662d5c65159SKalle Valo 		cmd->peer_flags &= ~WMI_PEER_HT;
1663d5c65159SKalle Valo }
1664d5c65159SKalle Valo 
1665d5c65159SKalle Valo int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar,
1666d5c65159SKalle Valo 				   struct peer_assoc_params *param)
1667d5c65159SKalle Valo {
1668d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1669d5c65159SKalle Valo 	struct wmi_peer_assoc_complete_cmd *cmd;
1670d5c65159SKalle Valo 	struct wmi_vht_rate_set *mcs;
1671d5c65159SKalle Valo 	struct wmi_he_rate_set *he_mcs;
1672d5c65159SKalle Valo 	struct sk_buff *skb;
1673d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1674d5c65159SKalle Valo 	void *ptr;
1675d5c65159SKalle Valo 	u32 peer_legacy_rates_align;
1676d5c65159SKalle Valo 	u32 peer_ht_rates_align;
1677d5c65159SKalle Valo 	int i, ret, len;
1678d5c65159SKalle Valo 
1679d5c65159SKalle Valo 	peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates,
1680d5c65159SKalle Valo 					  sizeof(u32));
1681d5c65159SKalle Valo 	peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates,
1682d5c65159SKalle Valo 				      sizeof(u32));
1683d5c65159SKalle Valo 
1684d5c65159SKalle Valo 	len = sizeof(*cmd) +
1685d5c65159SKalle Valo 	      TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) +
1686d5c65159SKalle Valo 	      TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) +
1687d5c65159SKalle Valo 	      sizeof(*mcs) + TLV_HDR_SIZE +
1688d5c65159SKalle Valo 	      (sizeof(*he_mcs) * param->peer_he_mcs_count);
1689d5c65159SKalle Valo 
1690d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
1691d5c65159SKalle Valo 	if (!skb)
1692d5c65159SKalle Valo 		return -ENOMEM;
1693d5c65159SKalle Valo 
1694d5c65159SKalle Valo 	ptr = skb->data;
1695d5c65159SKalle Valo 
1696d5c65159SKalle Valo 	cmd = ptr;
1697d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1698d5c65159SKalle Valo 				     WMI_TAG_PEER_ASSOC_COMPLETE_CMD) |
1699d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1700d5c65159SKalle Valo 
1701d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
1702d5c65159SKalle Valo 
1703d5c65159SKalle Valo 	cmd->peer_new_assoc = param->peer_new_assoc;
1704d5c65159SKalle Valo 	cmd->peer_associd = param->peer_associd;
1705d5c65159SKalle Valo 
1706d5c65159SKalle Valo 	ath11k_wmi_copy_peer_flags(cmd, param);
1707d5c65159SKalle Valo 
1708d5c65159SKalle Valo 	ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac);
1709d5c65159SKalle Valo 
1710d5c65159SKalle Valo 	cmd->peer_rate_caps = param->peer_rate_caps;
1711d5c65159SKalle Valo 	cmd->peer_caps = param->peer_caps;
1712d5c65159SKalle Valo 	cmd->peer_listen_intval = param->peer_listen_intval;
1713d5c65159SKalle Valo 	cmd->peer_ht_caps = param->peer_ht_caps;
1714d5c65159SKalle Valo 	cmd->peer_max_mpdu = param->peer_max_mpdu;
1715d5c65159SKalle Valo 	cmd->peer_mpdu_density = param->peer_mpdu_density;
1716d5c65159SKalle Valo 	cmd->peer_vht_caps = param->peer_vht_caps;
1717d5c65159SKalle Valo 	cmd->peer_phymode = param->peer_phymode;
1718d5c65159SKalle Valo 
1719d5c65159SKalle Valo 	/* Update 11ax capabilities */
1720d5c65159SKalle Valo 	cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0];
1721d5c65159SKalle Valo 	cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1];
1722d5c65159SKalle Valo 	cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal;
1723d5c65159SKalle Valo 	cmd->peer_he_ops = param->peer_he_ops;
1724d5c65159SKalle Valo 	memcpy(&cmd->peer_he_cap_phy, &param->peer_he_cap_phyinfo,
1725d5c65159SKalle Valo 	       sizeof(param->peer_he_cap_phyinfo));
1726d5c65159SKalle Valo 	memcpy(&cmd->peer_ppet, &param->peer_ppet,
1727d5c65159SKalle Valo 	       sizeof(param->peer_ppet));
1728d5c65159SKalle Valo 
1729d5c65159SKalle Valo 	/* Update peer legacy rate information */
1730d5c65159SKalle Valo 	ptr += sizeof(*cmd);
1731d5c65159SKalle Valo 
1732d5c65159SKalle Valo 	tlv = ptr;
1733d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1734d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align);
1735d5c65159SKalle Valo 
1736d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1737d5c65159SKalle Valo 
1738d5c65159SKalle Valo 	cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates;
1739d5c65159SKalle Valo 	memcpy(ptr, param->peer_legacy_rates.rates,
1740d5c65159SKalle Valo 	       param->peer_legacy_rates.num_rates);
1741d5c65159SKalle Valo 
1742d5c65159SKalle Valo 	/* Update peer HT rate information */
1743d5c65159SKalle Valo 	ptr += peer_legacy_rates_align;
1744d5c65159SKalle Valo 
1745d5c65159SKalle Valo 	tlv = ptr;
1746d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1747d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align);
1748d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1749d5c65159SKalle Valo 	cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates;
1750d5c65159SKalle Valo 	memcpy(ptr, param->peer_ht_rates.rates,
1751d5c65159SKalle Valo 	       param->peer_ht_rates.num_rates);
1752d5c65159SKalle Valo 
1753d5c65159SKalle Valo 	/* VHT Rates */
1754d5c65159SKalle Valo 	ptr += peer_ht_rates_align;
1755d5c65159SKalle Valo 
1756d5c65159SKalle Valo 	mcs = ptr;
1757d5c65159SKalle Valo 
1758d5c65159SKalle Valo 	mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) |
1759d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE);
1760d5c65159SKalle Valo 
1761d5c65159SKalle Valo 	cmd->peer_nss = param->peer_nss;
1762d5c65159SKalle Valo 
1763d5c65159SKalle Valo 	/* Update bandwidth-NSS mapping */
1764d5c65159SKalle Valo 	cmd->peer_bw_rxnss_override = 0;
1765d5c65159SKalle Valo 	cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override;
1766d5c65159SKalle Valo 
1767d5c65159SKalle Valo 	if (param->vht_capable) {
1768d5c65159SKalle Valo 		mcs->rx_max_rate = param->rx_max_rate;
1769d5c65159SKalle Valo 		mcs->rx_mcs_set = param->rx_mcs_set;
1770d5c65159SKalle Valo 		mcs->tx_max_rate = param->tx_max_rate;
1771d5c65159SKalle Valo 		mcs->tx_mcs_set = param->tx_mcs_set;
1772d5c65159SKalle Valo 	}
1773d5c65159SKalle Valo 
1774d5c65159SKalle Valo 	/* HE Rates */
1775d5c65159SKalle Valo 	cmd->peer_he_mcs = param->peer_he_mcs_count;
1776d5c65159SKalle Valo 
1777d5c65159SKalle Valo 	ptr += sizeof(*mcs);
1778d5c65159SKalle Valo 
1779d5c65159SKalle Valo 	len = param->peer_he_mcs_count * sizeof(*he_mcs);
1780d5c65159SKalle Valo 
1781d5c65159SKalle Valo 	tlv = ptr;
1782d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
1783d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
1784d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1785d5c65159SKalle Valo 
1786d5c65159SKalle Valo 	/* Loop through the HE rate set */
1787d5c65159SKalle Valo 	for (i = 0; i < param->peer_he_mcs_count; i++) {
1788d5c65159SKalle Valo 		he_mcs = ptr;
1789d5c65159SKalle Valo 		he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1790d5c65159SKalle Valo 						WMI_TAG_HE_RATE_SET) |
1791d5c65159SKalle Valo 				     FIELD_PREP(WMI_TLV_LEN,
1792d5c65159SKalle Valo 						sizeof(*he_mcs) - TLV_HDR_SIZE);
1793d5c65159SKalle Valo 
1794d5c65159SKalle Valo 		he_mcs->rx_mcs_set = param->peer_he_rx_mcs_set[i];
1795d5c65159SKalle Valo 		he_mcs->tx_mcs_set = param->peer_he_tx_mcs_set[i];
1796d5c65159SKalle Valo 		ptr += sizeof(*he_mcs);
1797d5c65159SKalle Valo 	}
1798d5c65159SKalle Valo 
1799d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID);
1800d5c65159SKalle Valo 	if (ret) {
1801d5c65159SKalle Valo 		ath11k_warn(ar->ab,
1802d5c65159SKalle Valo 			    "failed to send WMI_PEER_ASSOC_CMDID\n");
1803d5c65159SKalle Valo 		dev_kfree_skb(skb);
1804d5c65159SKalle Valo 	}
1805d5c65159SKalle Valo 
1806d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1807d5c65159SKalle Valo 		   "WMI peer assoc vdev id %d assoc id %d peer mac %pM\n",
1808d5c65159SKalle Valo 		   param->vdev_id, param->peer_associd, param->peer_mac);
1809d5c65159SKalle Valo 
1810d5c65159SKalle Valo 	return ret;
1811d5c65159SKalle Valo }
1812d5c65159SKalle Valo 
1813d5c65159SKalle Valo void ath11k_wmi_start_scan_init(struct ath11k *ar,
1814d5c65159SKalle Valo 				struct scan_req_params *arg)
1815d5c65159SKalle Valo {
1816d5c65159SKalle Valo 	/* setup commonly used values */
1817d5c65159SKalle Valo 	arg->scan_req_id = 1;
1818d5c65159SKalle Valo 	arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
1819d5c65159SKalle Valo 	arg->dwell_time_active = 50;
1820d5c65159SKalle Valo 	arg->dwell_time_active_2g = 0;
1821d5c65159SKalle Valo 	arg->dwell_time_passive = 150;
1822d5c65159SKalle Valo 	arg->min_rest_time = 50;
1823d5c65159SKalle Valo 	arg->max_rest_time = 500;
1824d5c65159SKalle Valo 	arg->repeat_probe_time = 0;
1825d5c65159SKalle Valo 	arg->probe_spacing_time = 0;
1826d5c65159SKalle Valo 	arg->idle_time = 0;
1827d5c65159SKalle Valo 	arg->max_scan_time = 20000;
1828d5c65159SKalle Valo 	arg->probe_delay = 5;
1829d5c65159SKalle Valo 	arg->notify_scan_events = WMI_SCAN_EVENT_STARTED |
1830d5c65159SKalle Valo 				  WMI_SCAN_EVENT_COMPLETED |
1831d5c65159SKalle Valo 				  WMI_SCAN_EVENT_BSS_CHANNEL |
1832d5c65159SKalle Valo 				  WMI_SCAN_EVENT_FOREIGN_CHAN |
1833d5c65159SKalle Valo 				  WMI_SCAN_EVENT_DEQUEUED;
1834d5c65159SKalle Valo 	arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT;
1835d5c65159SKalle Valo 	arg->num_bssid = 1;
1836d5c65159SKalle Valo }
1837d5c65159SKalle Valo 
1838d5c65159SKalle Valo static inline void
1839d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
1840d5c65159SKalle Valo 				       struct scan_req_params *param)
1841d5c65159SKalle Valo {
1842d5c65159SKalle Valo 	/* Scan events subscription */
1843d5c65159SKalle Valo 	if (param->scan_ev_started)
1844d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_STARTED;
1845d5c65159SKalle Valo 	if (param->scan_ev_completed)
1846d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_COMPLETED;
1847d5c65159SKalle Valo 	if (param->scan_ev_bss_chan)
1848d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_BSS_CHANNEL;
1849d5c65159SKalle Valo 	if (param->scan_ev_foreign_chan)
1850d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN;
1851d5c65159SKalle Valo 	if (param->scan_ev_dequeued)
1852d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_DEQUEUED;
1853d5c65159SKalle Valo 	if (param->scan_ev_preempted)
1854d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_PREEMPTED;
1855d5c65159SKalle Valo 	if (param->scan_ev_start_failed)
1856d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_START_FAILED;
1857d5c65159SKalle Valo 	if (param->scan_ev_restarted)
1858d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESTARTED;
1859d5c65159SKalle Valo 	if (param->scan_ev_foreign_chn_exit)
1860d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
1861d5c65159SKalle Valo 	if (param->scan_ev_suspended)
1862d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_SUSPENDED;
1863d5c65159SKalle Valo 	if (param->scan_ev_resumed)
1864d5c65159SKalle Valo 		cmd->notify_scan_events |=  WMI_SCAN_EVENT_RESUMED;
1865d5c65159SKalle Valo 
1866d5c65159SKalle Valo 	/** Set scan control flags */
1867d5c65159SKalle Valo 	cmd->scan_ctrl_flags = 0;
1868d5c65159SKalle Valo 	if (param->scan_f_passive)
1869d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_PASSIVE;
1870d5c65159SKalle Valo 	if (param->scan_f_strict_passive_pch)
1871d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
1872d5c65159SKalle Valo 	if (param->scan_f_promisc_mode)
1873d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROMISCUOS;
1874d5c65159SKalle Valo 	if (param->scan_f_capture_phy_err)
1875d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CAPTURE_PHY_ERROR;
1876d5c65159SKalle Valo 	if (param->scan_f_half_rate)
1877d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
1878d5c65159SKalle Valo 	if (param->scan_f_quarter_rate)
1879d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
1880d5c65159SKalle Valo 	if (param->scan_f_cck_rates)
1881d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_CCK_RATES;
1882d5c65159SKalle Valo 	if (param->scan_f_ofdm_rates)
1883d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_OFDM_RATES;
1884d5c65159SKalle Valo 	if (param->scan_f_chan_stat_evnt)
1885d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_CHAN_STAT_EVENT;
1886d5c65159SKalle Valo 	if (param->scan_f_filter_prb_req)
1887d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FILTER_PROBE_REQ;
1888d5c65159SKalle Valo 	if (param->scan_f_bcast_probe)
1889d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_BCAST_PROBE_REQ;
1890d5c65159SKalle Valo 	if (param->scan_f_offchan_mgmt_tx)
1891d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_MGMT_TX;
1892d5c65159SKalle Valo 	if (param->scan_f_offchan_data_tx)
1893d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_OFFCHAN_DATA_TX;
1894d5c65159SKalle Valo 	if (param->scan_f_force_active_dfs_chn)
1895d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
1896d5c65159SKalle Valo 	if (param->scan_f_add_tpc_ie_in_probe)
1897d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
1898d5c65159SKalle Valo 	if (param->scan_f_add_ds_ie_in_probe)
1899d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
1900d5c65159SKalle Valo 	if (param->scan_f_add_spoofed_mac_in_probe)
1901d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
1902d5c65159SKalle Valo 	if (param->scan_f_add_rand_seq_in_probe)
1903d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=  WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
1904d5c65159SKalle Valo 	if (param->scan_f_en_ie_whitelist_in_probe)
1905d5c65159SKalle Valo 		cmd->scan_ctrl_flags |=
1906d5c65159SKalle Valo 			 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
1907d5c65159SKalle Valo 
1908d5c65159SKalle Valo 	/* for adaptive scan mode using 3 bits (21 - 23 bits) */
1909d5c65159SKalle Valo 	WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
1910d5c65159SKalle Valo 				param->adaptive_dwell_time_mode);
1911d5c65159SKalle Valo }
1912d5c65159SKalle Valo 
1913d5c65159SKalle Valo int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
1914d5c65159SKalle Valo 				   struct scan_req_params *params)
1915d5c65159SKalle Valo {
1916d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
1917d5c65159SKalle Valo 	struct wmi_start_scan_cmd *cmd;
1918d5c65159SKalle Valo 	struct wmi_ssid *ssid = NULL;
1919d5c65159SKalle Valo 	struct wmi_mac_addr *bssid;
1920d5c65159SKalle Valo 	struct sk_buff *skb;
1921d5c65159SKalle Valo 	struct wmi_tlv *tlv;
1922d5c65159SKalle Valo 	void *ptr;
1923d5c65159SKalle Valo 	int i, ret, len;
1924d5c65159SKalle Valo 	u32 *tmp_ptr;
1925d5c65159SKalle Valo 	u8 extraie_len_with_pad = 0;
1926d5c65159SKalle Valo 
1927d5c65159SKalle Valo 	len = sizeof(*cmd);
1928d5c65159SKalle Valo 
1929d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
1930d5c65159SKalle Valo 	if (params->num_chan)
1931d5c65159SKalle Valo 		len += params->num_chan * sizeof(u32);
1932d5c65159SKalle Valo 
1933d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
1934d5c65159SKalle Valo 	if (params->num_ssids)
1935d5c65159SKalle Valo 		len += params->num_ssids * sizeof(*ssid);
1936d5c65159SKalle Valo 
1937d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
1938d5c65159SKalle Valo 	if (params->num_bssid)
1939d5c65159SKalle Valo 		len += sizeof(*bssid) * params->num_bssid;
1940d5c65159SKalle Valo 
1941d5c65159SKalle Valo 	len += TLV_HDR_SIZE;
1942d5c65159SKalle Valo 	if (params->extraie.len)
1943d5c65159SKalle Valo 		extraie_len_with_pad =
1944d5c65159SKalle Valo 			roundup(params->extraie.len, sizeof(u32));
1945d5c65159SKalle Valo 	len += extraie_len_with_pad;
1946d5c65159SKalle Valo 
1947d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
1948d5c65159SKalle Valo 	if (!skb)
1949d5c65159SKalle Valo 		return -ENOMEM;
1950d5c65159SKalle Valo 
1951d5c65159SKalle Valo 	ptr = skb->data;
1952d5c65159SKalle Valo 
1953d5c65159SKalle Valo 	cmd = ptr;
1954d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
1955d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1956d5c65159SKalle Valo 
1957d5c65159SKalle Valo 	cmd->scan_id = params->scan_id;
1958d5c65159SKalle Valo 	cmd->scan_req_id = params->scan_req_id;
1959d5c65159SKalle Valo 	cmd->vdev_id = params->vdev_id;
1960d5c65159SKalle Valo 	cmd->scan_priority = params->scan_priority;
1961d5c65159SKalle Valo 	cmd->notify_scan_events = params->notify_scan_events;
1962d5c65159SKalle Valo 
1963d5c65159SKalle Valo 	ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
1964d5c65159SKalle Valo 
1965d5c65159SKalle Valo 	cmd->dwell_time_active = params->dwell_time_active;
1966d5c65159SKalle Valo 	cmd->dwell_time_active_2g = params->dwell_time_active_2g;
1967d5c65159SKalle Valo 	cmd->dwell_time_passive = params->dwell_time_passive;
1968d5c65159SKalle Valo 	cmd->min_rest_time = params->min_rest_time;
1969d5c65159SKalle Valo 	cmd->max_rest_time = params->max_rest_time;
1970d5c65159SKalle Valo 	cmd->repeat_probe_time = params->repeat_probe_time;
1971d5c65159SKalle Valo 	cmd->probe_spacing_time = params->probe_spacing_time;
1972d5c65159SKalle Valo 	cmd->idle_time = params->idle_time;
1973d5c65159SKalle Valo 	cmd->max_scan_time = params->max_scan_time;
1974d5c65159SKalle Valo 	cmd->probe_delay = params->probe_delay;
1975d5c65159SKalle Valo 	cmd->burst_duration = params->burst_duration;
1976d5c65159SKalle Valo 	cmd->num_chan = params->num_chan;
1977d5c65159SKalle Valo 	cmd->num_bssid = params->num_bssid;
1978d5c65159SKalle Valo 	cmd->num_ssids = params->num_ssids;
1979d5c65159SKalle Valo 	cmd->ie_len = params->extraie.len;
1980d5c65159SKalle Valo 	cmd->n_probes = params->n_probes;
1981d5c65159SKalle Valo 
1982d5c65159SKalle Valo 	ptr += sizeof(*cmd);
1983d5c65159SKalle Valo 
1984d5c65159SKalle Valo 	len = params->num_chan * sizeof(u32);
1985d5c65159SKalle Valo 
1986d5c65159SKalle Valo 	tlv = ptr;
1987d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
1988d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
1989d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
1990d5c65159SKalle Valo 	tmp_ptr = (u32 *)ptr;
1991d5c65159SKalle Valo 
1992d5c65159SKalle Valo 	for (i = 0; i < params->num_chan; ++i)
1993d5c65159SKalle Valo 		tmp_ptr[i] = params->chan_list[i];
1994d5c65159SKalle Valo 
1995d5c65159SKalle Valo 	ptr += len;
1996d5c65159SKalle Valo 
1997d5c65159SKalle Valo 	len = params->num_ssids * sizeof(*ssid);
1998d5c65159SKalle Valo 	tlv = ptr;
1999d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2000d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2001d5c65159SKalle Valo 
2002d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2003d5c65159SKalle Valo 
2004d5c65159SKalle Valo 	if (params->num_ssids) {
2005d5c65159SKalle Valo 		ssid = ptr;
2006d5c65159SKalle Valo 		for (i = 0; i < params->num_ssids; ++i) {
2007d5c65159SKalle Valo 			ssid->ssid_len = params->ssid[i].length;
2008d5c65159SKalle Valo 			memcpy(ssid->ssid, params->ssid[i].ssid,
2009d5c65159SKalle Valo 			       params->ssid[i].length);
2010d5c65159SKalle Valo 			ssid++;
2011d5c65159SKalle Valo 		}
2012d5c65159SKalle Valo 	}
2013d5c65159SKalle Valo 
2014d5c65159SKalle Valo 	ptr += (params->num_ssids * sizeof(*ssid));
2015d5c65159SKalle Valo 	len = params->num_bssid * sizeof(*bssid);
2016d5c65159SKalle Valo 	tlv = ptr;
2017d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2018d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2019d5c65159SKalle Valo 
2020d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2021d5c65159SKalle Valo 	bssid = ptr;
2022d5c65159SKalle Valo 
2023d5c65159SKalle Valo 	if (params->num_bssid) {
2024d5c65159SKalle Valo 		for (i = 0; i < params->num_bssid; ++i) {
2025d5c65159SKalle Valo 			ether_addr_copy(bssid->addr,
2026d5c65159SKalle Valo 					params->bssid_list[i].addr);
2027d5c65159SKalle Valo 			bssid++;
2028d5c65159SKalle Valo 		}
2029d5c65159SKalle Valo 	}
2030d5c65159SKalle Valo 
2031d5c65159SKalle Valo 	ptr += params->num_bssid * sizeof(*bssid);
2032d5c65159SKalle Valo 
2033d5c65159SKalle Valo 	len = extraie_len_with_pad;
2034d5c65159SKalle Valo 	tlv = ptr;
2035d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2036d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2037d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2038d5c65159SKalle Valo 
2039d5c65159SKalle Valo 	if (params->extraie.len)
2040d5c65159SKalle Valo 		memcpy(ptr, params->extraie.ptr,
2041d5c65159SKalle Valo 		       params->extraie.len);
2042d5c65159SKalle Valo 
2043d5c65159SKalle Valo 	ptr += extraie_len_with_pad;
2044d5c65159SKalle Valo 
2045d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2046d5c65159SKalle Valo 				  WMI_START_SCAN_CMDID);
2047d5c65159SKalle Valo 	if (ret) {
2048d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2049d5c65159SKalle Valo 		dev_kfree_skb(skb);
2050d5c65159SKalle Valo 	}
2051d5c65159SKalle Valo 
2052d5c65159SKalle Valo 	return ret;
2053d5c65159SKalle Valo }
2054d5c65159SKalle Valo 
2055d5c65159SKalle Valo int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2056d5c65159SKalle Valo 				  struct scan_cancel_param *param)
2057d5c65159SKalle Valo {
2058d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2059d5c65159SKalle Valo 	struct wmi_stop_scan_cmd *cmd;
2060d5c65159SKalle Valo 	struct sk_buff *skb;
2061d5c65159SKalle Valo 	int ret;
2062d5c65159SKalle Valo 
2063d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
2064d5c65159SKalle Valo 	if (!skb)
2065d5c65159SKalle Valo 		return -ENOMEM;
2066d5c65159SKalle Valo 
2067d5c65159SKalle Valo 	cmd = (struct wmi_stop_scan_cmd *)skb->data;
2068d5c65159SKalle Valo 
2069d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2070d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2071d5c65159SKalle Valo 
2072d5c65159SKalle Valo 	cmd->vdev_id = param->vdev_id;
2073d5c65159SKalle Valo 	cmd->requestor = param->requester;
2074d5c65159SKalle Valo 	cmd->scan_id = param->scan_id;
2075d5c65159SKalle Valo 	cmd->pdev_id = param->pdev_id;
2076d5c65159SKalle Valo 	/* stop the scan with the corresponding scan_id */
2077d5c65159SKalle Valo 	if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2078d5c65159SKalle Valo 		/* Cancelling all scans */
2079d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ALL;
2080d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2081d5c65159SKalle Valo 		/* Cancelling VAP scans */
2082d5c65159SKalle Valo 		cmd->req_type =  WMI_SCN_STOP_VAP_ALL;
2083d5c65159SKalle Valo 	} else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2084d5c65159SKalle Valo 		/* Cancelling specific scan */
2085d5c65159SKalle Valo 		cmd->req_type =  WMI_SCAN_STOP_ONE;
2086d5c65159SKalle Valo 	} else {
2087d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid scan cancel param %d",
2088d5c65159SKalle Valo 			    param->req_type);
2089d5c65159SKalle Valo 		dev_kfree_skb(skb);
2090d5c65159SKalle Valo 		return -EINVAL;
2091d5c65159SKalle Valo 	}
2092d5c65159SKalle Valo 
2093d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2094d5c65159SKalle Valo 				  WMI_STOP_SCAN_CMDID);
2095d5c65159SKalle Valo 	if (ret) {
2096d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2097d5c65159SKalle Valo 		dev_kfree_skb(skb);
2098d5c65159SKalle Valo 	}
2099d5c65159SKalle Valo 
2100d5c65159SKalle Valo 	return ret;
2101d5c65159SKalle Valo }
2102d5c65159SKalle Valo 
2103d5c65159SKalle Valo int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2104d5c65159SKalle Valo 				       struct scan_chan_list_params *chan_list)
2105d5c65159SKalle Valo {
2106d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2107d5c65159SKalle Valo 	struct wmi_scan_chan_list_cmd *cmd;
2108d5c65159SKalle Valo 	struct sk_buff *skb;
2109d5c65159SKalle Valo 	struct wmi_channel *chan_info;
2110d5c65159SKalle Valo 	struct channel_param *tchan_info;
2111d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2112d5c65159SKalle Valo 	void *ptr;
2113d5c65159SKalle Valo 	int i, ret, len;
2114d5c65159SKalle Valo 	u32 *reg1, *reg2;
2115d5c65159SKalle Valo 
2116d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE +
2117d5c65159SKalle Valo 		 sizeof(*chan_info) * chan_list->nallchans;
2118d5c65159SKalle Valo 
2119d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
2120d5c65159SKalle Valo 	if (!skb)
2121d5c65159SKalle Valo 		return -ENOMEM;
2122d5c65159SKalle Valo 
2123d5c65159SKalle Valo 	cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2124d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2125d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2126d5c65159SKalle Valo 
2127d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2128d5c65159SKalle Valo 		   "WMI no.of chan = %d len = %d\n", chan_list->nallchans, len);
2129d5c65159SKalle Valo 	cmd->pdev_id = chan_list->pdev_id;
2130d5c65159SKalle Valo 	cmd->num_scan_chans = chan_list->nallchans;
2131d5c65159SKalle Valo 
2132d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
2133d5c65159SKalle Valo 
2134d5c65159SKalle Valo 	len = sizeof(*chan_info) * chan_list->nallchans;
2135d5c65159SKalle Valo 	tlv = ptr;
2136d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2137d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2138d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2139d5c65159SKalle Valo 
2140d5c65159SKalle Valo 	tchan_info = &chan_list->ch_param[0];
2141d5c65159SKalle Valo 
2142d5c65159SKalle Valo 	for (i = 0; i < chan_list->nallchans; ++i) {
2143d5c65159SKalle Valo 		chan_info = ptr;
2144d5c65159SKalle Valo 		memset(chan_info, 0, sizeof(*chan_info));
2145d5c65159SKalle Valo 		len = sizeof(*chan_info);
2146d5c65159SKalle Valo 		chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2147d5c65159SKalle Valo 						   WMI_TAG_CHANNEL) |
2148d5c65159SKalle Valo 					FIELD_PREP(WMI_TLV_LEN,
2149d5c65159SKalle Valo 						   len - TLV_HDR_SIZE);
2150d5c65159SKalle Valo 
2151d5c65159SKalle Valo 		reg1 = &chan_info->reg_info_1;
2152d5c65159SKalle Valo 		reg2 = &chan_info->reg_info_2;
2153d5c65159SKalle Valo 		chan_info->mhz = tchan_info->mhz;
2154d5c65159SKalle Valo 		chan_info->band_center_freq1 = tchan_info->cfreq1;
2155d5c65159SKalle Valo 		chan_info->band_center_freq2 = tchan_info->cfreq2;
2156d5c65159SKalle Valo 
2157d5c65159SKalle Valo 		if (tchan_info->is_chan_passive)
2158d5c65159SKalle Valo 			chan_info->info |= WMI_CHAN_INFO_PASSIVE;
21599f056ed8SJohn Crispin 		if (tchan_info->allow_he)
21609f056ed8SJohn Crispin 			chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
21619f056ed8SJohn Crispin 		else if (tchan_info->allow_vht)
2162d5c65159SKalle Valo 			chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2163d5c65159SKalle Valo 		else if (tchan_info->allow_ht)
2164d5c65159SKalle Valo 			chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2165d5c65159SKalle Valo 		if (tchan_info->half_rate)
2166d5c65159SKalle Valo 			chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2167d5c65159SKalle Valo 		if (tchan_info->quarter_rate)
2168d5c65159SKalle Valo 			chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2169d5c65159SKalle Valo 
2170d5c65159SKalle Valo 		chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2171d5c65159SKalle Valo 					      tchan_info->phy_mode);
2172d5c65159SKalle Valo 		*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2173d5c65159SKalle Valo 				    tchan_info->minpower);
2174d5c65159SKalle Valo 		*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2175d5c65159SKalle Valo 				    tchan_info->maxpower);
2176d5c65159SKalle Valo 		*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2177d5c65159SKalle Valo 				    tchan_info->maxregpower);
2178d5c65159SKalle Valo 		*reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2179d5c65159SKalle Valo 				    tchan_info->reg_class_id);
2180d5c65159SKalle Valo 		*reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2181d5c65159SKalle Valo 				    tchan_info->antennamax);
2182d5c65159SKalle Valo 
2183d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2184d5c65159SKalle Valo 			   "WMI chan scan list chan[%d] = %u\n",
2185d5c65159SKalle Valo 			   i, chan_info->mhz);
2186d5c65159SKalle Valo 
2187d5c65159SKalle Valo 		ptr += sizeof(*chan_info);
2188d5c65159SKalle Valo 
2189d5c65159SKalle Valo 		tchan_info++;
2190d5c65159SKalle Valo 	}
2191d5c65159SKalle Valo 
2192d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2193d5c65159SKalle Valo 	if (ret) {
2194d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2195d5c65159SKalle Valo 		dev_kfree_skb(skb);
2196d5c65159SKalle Valo 	}
2197d5c65159SKalle Valo 
2198d5c65159SKalle Valo 	return ret;
2199d5c65159SKalle Valo }
2200d5c65159SKalle Valo 
2201d5c65159SKalle Valo int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2202d5c65159SKalle Valo 				       struct wmi_wmm_params_all_arg *param)
2203d5c65159SKalle Valo {
2204d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2205d5c65159SKalle Valo 	struct wmi_vdev_set_wmm_params_cmd *cmd;
2206d5c65159SKalle Valo 	struct wmi_wmm_params *wmm_param;
2207d5c65159SKalle Valo 	struct wmi_wmm_params_arg *wmi_wmm_arg;
2208d5c65159SKalle Valo 	struct sk_buff *skb;
2209d5c65159SKalle Valo 	int ret, ac;
2210d5c65159SKalle Valo 
2211d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
2212d5c65159SKalle Valo 	if (!skb)
2213d5c65159SKalle Valo 		return -ENOMEM;
2214d5c65159SKalle Valo 
2215d5c65159SKalle Valo 	cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2216d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2217d5c65159SKalle Valo 				     WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2218d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2219d5c65159SKalle Valo 
2220d5c65159SKalle Valo 	cmd->vdev_id = vdev_id;
2221d5c65159SKalle Valo 	cmd->wmm_param_type = 0;
2222d5c65159SKalle Valo 
2223d5c65159SKalle Valo 	for (ac = 0; ac < WME_NUM_AC; ac++) {
2224d5c65159SKalle Valo 		switch (ac) {
2225d5c65159SKalle Valo 		case WME_AC_BE:
2226d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_be;
2227d5c65159SKalle Valo 			break;
2228d5c65159SKalle Valo 		case WME_AC_BK:
2229d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_bk;
2230d5c65159SKalle Valo 			break;
2231d5c65159SKalle Valo 		case WME_AC_VI:
2232d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vi;
2233d5c65159SKalle Valo 			break;
2234d5c65159SKalle Valo 		case WME_AC_VO:
2235d5c65159SKalle Valo 			wmi_wmm_arg = &param->ac_vo;
2236d5c65159SKalle Valo 			break;
2237d5c65159SKalle Valo 		}
2238d5c65159SKalle Valo 
2239d5c65159SKalle Valo 		wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2240d5c65159SKalle Valo 		wmm_param->tlv_header =
2241d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
2242d5c65159SKalle Valo 					   WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2243d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN,
2244d5c65159SKalle Valo 					   sizeof(*wmm_param) - TLV_HDR_SIZE);
2245d5c65159SKalle Valo 
2246d5c65159SKalle Valo 		wmm_param->aifs = wmi_wmm_arg->aifs;
2247d5c65159SKalle Valo 		wmm_param->cwmin = wmi_wmm_arg->cwmin;
2248d5c65159SKalle Valo 		wmm_param->cwmax = wmi_wmm_arg->cwmax;
2249d5c65159SKalle Valo 		wmm_param->txoplimit = wmi_wmm_arg->txop;
2250d5c65159SKalle Valo 		wmm_param->acm = wmi_wmm_arg->acm;
2251d5c65159SKalle Valo 		wmm_param->no_ack = wmi_wmm_arg->no_ack;
2252d5c65159SKalle Valo 
2253d5c65159SKalle Valo 		ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2254d5c65159SKalle Valo 			   "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2255d5c65159SKalle Valo 			   ac, wmm_param->aifs, wmm_param->cwmin,
2256d5c65159SKalle Valo 			   wmm_param->cwmax, wmm_param->txoplimit,
2257d5c65159SKalle Valo 			   wmm_param->acm, wmm_param->no_ack);
2258d5c65159SKalle Valo 	}
2259d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2260d5c65159SKalle Valo 				  WMI_VDEV_SET_WMM_PARAMS_CMDID);
2261d5c65159SKalle Valo 	if (ret) {
2262d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2263d5c65159SKalle Valo 			    "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2264d5c65159SKalle Valo 		dev_kfree_skb(skb);
2265d5c65159SKalle Valo 	}
2266d5c65159SKalle Valo 
2267d5c65159SKalle Valo 	return ret;
2268d5c65159SKalle Valo }
2269d5c65159SKalle Valo 
2270d5c65159SKalle Valo int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2271d5c65159SKalle Valo 						  u32 pdev_id)
2272d5c65159SKalle Valo {
2273d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2274d5c65159SKalle Valo 	struct wmi_dfs_phyerr_offload_cmd *cmd;
2275d5c65159SKalle Valo 	struct sk_buff *skb;
2276d5c65159SKalle Valo 	int ret;
2277d5c65159SKalle Valo 
2278d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
2279d5c65159SKalle Valo 	if (!skb)
2280d5c65159SKalle Valo 		return -ENOMEM;
2281d5c65159SKalle Valo 
2282d5c65159SKalle Valo 	cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2283d5c65159SKalle Valo 	cmd->tlv_header =
2284d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2285d5c65159SKalle Valo 			   WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2286d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2287d5c65159SKalle Valo 
2288d5c65159SKalle Valo 	cmd->pdev_id = pdev_id;
2289d5c65159SKalle Valo 
2290d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2291d5c65159SKalle Valo 		   "WMI dfs phy err offload enable pdev id %d\n", pdev_id);
2292d5c65159SKalle Valo 
2293d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2294d5c65159SKalle Valo 				  WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2295d5c65159SKalle Valo 	if (ret) {
2296d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2297d5c65159SKalle Valo 			    "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2298d5c65159SKalle Valo 		dev_kfree_skb(skb);
2299d5c65159SKalle Valo 	}
2300d5c65159SKalle Valo 
2301d5c65159SKalle Valo 	return ret;
2302d5c65159SKalle Valo }
2303d5c65159SKalle Valo 
2304d5c65159SKalle Valo int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2305d5c65159SKalle Valo {
2306d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2307d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_cmd *cmd;
2308d5c65159SKalle Valo 	struct wmi_pdev_pktlog_filter_info *info;
2309d5c65159SKalle Valo 	struct sk_buff *skb;
2310d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2311d5c65159SKalle Valo 	void *ptr;
2312d5c65159SKalle Valo 	int ret, len;
2313d5c65159SKalle Valo 
2314d5c65159SKalle Valo 	len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
2315d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
2316d5c65159SKalle Valo 	if (!skb)
2317d5c65159SKalle Valo 		return -ENOMEM;
2318d5c65159SKalle Valo 
2319d5c65159SKalle Valo 	cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2320d5c65159SKalle Valo 
2321d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2322d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2323d5c65159SKalle Valo 
2324d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2325d5c65159SKalle Valo 	cmd->num_mac = 1;
2326d5c65159SKalle Valo 	cmd->enable = enable;
2327d5c65159SKalle Valo 
2328d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
2329d5c65159SKalle Valo 
2330d5c65159SKalle Valo 	tlv = ptr;
2331d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2332d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, 0);
2333d5c65159SKalle Valo 
2334d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
2335d5c65159SKalle Valo 	info = ptr;
2336d5c65159SKalle Valo 
2337d5c65159SKalle Valo 	ether_addr_copy(info->peer_macaddr.addr, addr);
2338d5c65159SKalle Valo 	info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2339d5c65159SKalle Valo 			   FIELD_PREP(WMI_TLV_LEN,
2340d5c65159SKalle Valo 				      sizeof(*info) - TLV_HDR_SIZE);
2341d5c65159SKalle Valo 
2342d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2343d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_FILTER_CMDID);
2344d5c65159SKalle Valo 	if (ret) {
2345d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2346d5c65159SKalle Valo 		dev_kfree_skb(skb);
2347d5c65159SKalle Valo 	}
2348d5c65159SKalle Valo 
2349d5c65159SKalle Valo 	return ret;
2350d5c65159SKalle Valo }
2351d5c65159SKalle Valo 
2352d5c65159SKalle Valo int
2353d5c65159SKalle Valo ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2354d5c65159SKalle Valo 				 struct wmi_init_country_params init_cc_params)
2355d5c65159SKalle Valo {
2356d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2357d5c65159SKalle Valo 	struct wmi_init_country_cmd *cmd;
2358d5c65159SKalle Valo 	struct sk_buff *skb;
2359d5c65159SKalle Valo 	int ret;
2360d5c65159SKalle Valo 
2361d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
2362d5c65159SKalle Valo 	if (!skb)
2363d5c65159SKalle Valo 		return -ENOMEM;
2364d5c65159SKalle Valo 
2365d5c65159SKalle Valo 	cmd = (struct wmi_init_country_cmd *)skb->data;
2366d5c65159SKalle Valo 	cmd->tlv_header =
2367d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_TAG,
2368d5c65159SKalle Valo 			   WMI_TAG_SET_INIT_COUNTRY_CMD) |
2369d5c65159SKalle Valo 		FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2370d5c65159SKalle Valo 
2371d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2372d5c65159SKalle Valo 
2373d5c65159SKalle Valo 	switch (init_cc_params.flags) {
2374d5c65159SKalle Valo 	case ALPHA_IS_SET:
2375d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2376d5c65159SKalle Valo 		memcpy((u8 *)&cmd->cc_info.alpha2,
2377d5c65159SKalle Valo 		       init_cc_params.cc_info.alpha2, 3);
2378d5c65159SKalle Valo 		break;
2379d5c65159SKalle Valo 	case CC_IS_SET:
2380d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2381d5c65159SKalle Valo 		cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2382d5c65159SKalle Valo 		break;
2383d5c65159SKalle Valo 	case REGDMN_IS_SET:
2384d5c65159SKalle Valo 		cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2385d5c65159SKalle Valo 		cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2386d5c65159SKalle Valo 		break;
2387d5c65159SKalle Valo 	default:
2388d5c65159SKalle Valo 		ret = -EINVAL;
2389d5c65159SKalle Valo 		goto out;
2390d5c65159SKalle Valo 	}
2391d5c65159SKalle Valo 
2392d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2393d5c65159SKalle Valo 				  WMI_SET_INIT_COUNTRY_CMDID);
2394d5c65159SKalle Valo 
2395d5c65159SKalle Valo out:
2396d5c65159SKalle Valo 	if (ret) {
2397d5c65159SKalle Valo 		ath11k_warn(ar->ab,
2398d5c65159SKalle Valo 			    "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2399d5c65159SKalle Valo 			    ret);
2400d5c65159SKalle Valo 		dev_kfree_skb(skb);
2401d5c65159SKalle Valo 	}
2402d5c65159SKalle Valo 
2403d5c65159SKalle Valo 	return ret;
2404d5c65159SKalle Valo }
2405d5c65159SKalle Valo 
2406d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
2407d5c65159SKalle Valo {
2408d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2409d5c65159SKalle Valo 	struct wmi_pktlog_enable_cmd *cmd;
2410d5c65159SKalle Valo 	struct sk_buff *skb;
2411d5c65159SKalle Valo 	int ret;
2412d5c65159SKalle Valo 
2413d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
2414d5c65159SKalle Valo 	if (!skb)
2415d5c65159SKalle Valo 		return -ENOMEM;
2416d5c65159SKalle Valo 
2417d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
2418d5c65159SKalle Valo 
2419d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
2420d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2421d5c65159SKalle Valo 
2422d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2423d5c65159SKalle Valo 	cmd->evlist = pktlog_filter;
2424d5c65159SKalle Valo 	cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
2425d5c65159SKalle Valo 
2426d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2427d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_ENABLE_CMDID);
2428d5c65159SKalle Valo 	if (ret) {
2429d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2430d5c65159SKalle Valo 		dev_kfree_skb(skb);
2431d5c65159SKalle Valo 	}
2432d5c65159SKalle Valo 
2433d5c65159SKalle Valo 	return ret;
2434d5c65159SKalle Valo }
2435d5c65159SKalle Valo 
2436d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
2437d5c65159SKalle Valo {
2438d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
2439d5c65159SKalle Valo 	struct wmi_pktlog_disable_cmd *cmd;
2440d5c65159SKalle Valo 	struct sk_buff *skb;
2441d5c65159SKalle Valo 	int ret;
2442d5c65159SKalle Valo 
2443d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, sizeof(*cmd));
2444d5c65159SKalle Valo 	if (!skb)
2445d5c65159SKalle Valo 		return -ENOMEM;
2446d5c65159SKalle Valo 
2447d5c65159SKalle Valo 	cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
2448d5c65159SKalle Valo 
2449d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
2450d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2451d5c65159SKalle Valo 
2452d5c65159SKalle Valo 	cmd->pdev_id = ar->pdev->pdev_id;
2453d5c65159SKalle Valo 
2454d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb,
2455d5c65159SKalle Valo 				  WMI_PDEV_PKTLOG_DISABLE_CMDID);
2456d5c65159SKalle Valo 	if (ret) {
2457d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2458d5c65159SKalle Valo 		dev_kfree_skb(skb);
2459d5c65159SKalle Valo 	}
2460d5c65159SKalle Valo 
2461d5c65159SKalle Valo 	return ret;
2462d5c65159SKalle Valo }
2463d5c65159SKalle Valo 
24646d293d44SJohn Crispin int
24656d293d44SJohn Crispin ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id)
24666d293d44SJohn Crispin {
24676d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
24686d293d44SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_sc->ab;
24696d293d44SJohn Crispin 	struct wmi_twt_enable_params_cmd *cmd;
24706d293d44SJohn Crispin 	struct sk_buff *skb;
24716d293d44SJohn Crispin 	int ret, len;
24726d293d44SJohn Crispin 
24736d293d44SJohn Crispin 	len = sizeof(*cmd);
24746d293d44SJohn Crispin 
24756d293d44SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
24766d293d44SJohn Crispin 	if (!skb)
24776d293d44SJohn Crispin 		return -ENOMEM;
24786d293d44SJohn Crispin 
24796d293d44SJohn Crispin 	cmd = (void *)skb->data;
24806d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
24816d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
24826d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
24836d293d44SJohn Crispin 	cmd->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
24846d293d44SJohn Crispin 	cmd->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
24856d293d44SJohn Crispin 	cmd->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
24866d293d44SJohn Crispin 	cmd->congestion_thresh_teardown =
24876d293d44SJohn Crispin 		ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
24886d293d44SJohn Crispin 	cmd->congestion_thresh_critical =
24896d293d44SJohn Crispin 		ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
24906d293d44SJohn Crispin 	cmd->interference_thresh_teardown =
24916d293d44SJohn Crispin 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
24926d293d44SJohn Crispin 	cmd->interference_thresh_setup =
24936d293d44SJohn Crispin 		ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
24946d293d44SJohn Crispin 	cmd->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
24956d293d44SJohn Crispin 	cmd->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
24966d293d44SJohn Crispin 	cmd->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
24976d293d44SJohn Crispin 	cmd->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
24986d293d44SJohn Crispin 	cmd->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
24996d293d44SJohn Crispin 	cmd->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
25006d293d44SJohn Crispin 	cmd->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
25016d293d44SJohn Crispin 	cmd->remove_sta_slot_interval =
25026d293d44SJohn Crispin 		ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
25036d293d44SJohn Crispin 	/* TODO add MBSSID support */
25046d293d44SJohn Crispin 	cmd->mbss_support = 0;
25056d293d44SJohn Crispin 
25066d293d44SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
25076d293d44SJohn Crispin 				  WMI_TWT_ENABLE_CMDID);
25086d293d44SJohn Crispin 	if (ret) {
25096d293d44SJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
25106d293d44SJohn Crispin 		dev_kfree_skb(skb);
25116d293d44SJohn Crispin 	}
25126d293d44SJohn Crispin 	return ret;
25136d293d44SJohn Crispin }
25146d293d44SJohn Crispin 
25156d293d44SJohn Crispin int
25166d293d44SJohn Crispin ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
25176d293d44SJohn Crispin {
25186d293d44SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
25196d293d44SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_sc->ab;
25206d293d44SJohn Crispin 	struct wmi_twt_disable_params_cmd *cmd;
25216d293d44SJohn Crispin 	struct sk_buff *skb;
25226d293d44SJohn Crispin 	int ret, len;
25236d293d44SJohn Crispin 
25246d293d44SJohn Crispin 	len = sizeof(*cmd);
25256d293d44SJohn Crispin 
25266d293d44SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
25276d293d44SJohn Crispin 	if (!skb)
25286d293d44SJohn Crispin 		return -ENOMEM;
25296d293d44SJohn Crispin 
25306d293d44SJohn Crispin 	cmd = (void *)skb->data;
25316d293d44SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
25326d293d44SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
25336d293d44SJohn Crispin 	cmd->pdev_id = pdev_id;
25346d293d44SJohn Crispin 
25356d293d44SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
25366d293d44SJohn Crispin 				  WMI_TWT_DISABLE_CMDID);
25376d293d44SJohn Crispin 	if (ret) {
25386d293d44SJohn Crispin 		ath11k_warn(ab, "Failed to send WMI_TWT_DIeABLE_CMDID");
25396d293d44SJohn Crispin 		dev_kfree_skb(skb);
25406d293d44SJohn Crispin 	}
25416d293d44SJohn Crispin 	return ret;
25426d293d44SJohn Crispin }
25436d293d44SJohn Crispin 
25443f8be640SJohn Crispin int
25453f8be640SJohn Crispin ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
25463f8be640SJohn Crispin 			     struct ieee80211_he_obss_pd *he_obss_pd)
25473f8be640SJohn Crispin {
25483f8be640SJohn Crispin 	struct ath11k_pdev_wmi *wmi = ar->wmi;
25493f8be640SJohn Crispin 	struct ath11k_base *ab = wmi->wmi_sc->ab;
25503f8be640SJohn Crispin 	struct wmi_obss_spatial_reuse_params_cmd *cmd;
25513f8be640SJohn Crispin 	struct sk_buff *skb;
25523f8be640SJohn Crispin 	int ret, len;
25533f8be640SJohn Crispin 
25543f8be640SJohn Crispin 	len = sizeof(*cmd);
25553f8be640SJohn Crispin 
25563f8be640SJohn Crispin 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
25573f8be640SJohn Crispin 	if (!skb)
25583f8be640SJohn Crispin 		return -ENOMEM;
25593f8be640SJohn Crispin 
25603f8be640SJohn Crispin 	cmd = (void *)skb->data;
25613f8be640SJohn Crispin 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
25623f8be640SJohn Crispin 				     WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
25633f8be640SJohn Crispin 			  FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
25643f8be640SJohn Crispin 	cmd->vdev_id = vdev_id;
25653f8be640SJohn Crispin 	cmd->enable = he_obss_pd->enable;
25663f8be640SJohn Crispin 	cmd->obss_min = he_obss_pd->min_offset;
25673f8be640SJohn Crispin 	cmd->obss_max = he_obss_pd->max_offset;
25683f8be640SJohn Crispin 
25693f8be640SJohn Crispin 	ret = ath11k_wmi_cmd_send(wmi, skb,
25703f8be640SJohn Crispin 				  WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
25713f8be640SJohn Crispin 	if (ret) {
25723f8be640SJohn Crispin 		ath11k_warn(ab,
25733f8be640SJohn Crispin 			    "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
25743f8be640SJohn Crispin 		dev_kfree_skb(skb);
25753f8be640SJohn Crispin 	}
25763f8be640SJohn Crispin 	return ret;
25773f8be640SJohn Crispin }
25783f8be640SJohn Crispin 
2579d5c65159SKalle Valo static void
2580d5c65159SKalle Valo ath11k_fill_band_to_mac_param(struct ath11k_base  *soc,
2581d5c65159SKalle Valo 			      struct wmi_host_pdev_band_to_mac *band_to_mac)
2582d5c65159SKalle Valo {
2583d5c65159SKalle Valo 	u8 i;
2584d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
2585d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
2586d5c65159SKalle Valo 
2587d5c65159SKalle Valo 	for (i = 0; i < soc->num_radios; i++) {
2588d5c65159SKalle Valo 		pdev = &soc->pdevs[i];
2589d5c65159SKalle Valo 		hal_reg_cap = &soc->hal_reg_cap[i];
2590d5c65159SKalle Valo 		band_to_mac[i].pdev_id = pdev->pdev_id;
2591d5c65159SKalle Valo 
2592d5c65159SKalle Valo 		switch (pdev->cap.supported_bands) {
2593d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_5G_CAP:
2594d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
2595d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
2596d5c65159SKalle Valo 			break;
2597d5c65159SKalle Valo 		case WMI_HOST_WLAN_2G_CAP:
2598d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
2599d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
2600d5c65159SKalle Valo 			break;
2601d5c65159SKalle Valo 		case WMI_HOST_WLAN_5G_CAP:
2602d5c65159SKalle Valo 			band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
2603d5c65159SKalle Valo 			band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
2604d5c65159SKalle Valo 			break;
2605d5c65159SKalle Valo 		default:
2606d5c65159SKalle Valo 			break;
2607d5c65159SKalle Valo 		}
2608d5c65159SKalle Valo 	}
2609d5c65159SKalle Valo }
2610d5c65159SKalle Valo 
2611d5c65159SKalle Valo static void
2612d5c65159SKalle Valo ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
2613d5c65159SKalle Valo 				struct target_resource_config *tg_cfg)
2614d5c65159SKalle Valo {
2615d5c65159SKalle Valo 	wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
2616d5c65159SKalle Valo 	wmi_cfg->num_peers = tg_cfg->num_peers;
2617d5c65159SKalle Valo 	wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
2618d5c65159SKalle Valo 	wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
2619d5c65159SKalle Valo 	wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
2620d5c65159SKalle Valo 	wmi_cfg->num_tids = tg_cfg->num_tids;
2621d5c65159SKalle Valo 	wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
2622d5c65159SKalle Valo 	wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
2623d5c65159SKalle Valo 	wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
2624d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
2625d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
2626d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
2627d5c65159SKalle Valo 	wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
2628d5c65159SKalle Valo 	wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
2629d5c65159SKalle Valo 	wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
2630d5c65159SKalle Valo 	wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
2631d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
2632d5c65159SKalle Valo 	wmi_cfg->roam_offload_max_ap_profiles =
2633d5c65159SKalle Valo 		tg_cfg->roam_offload_max_ap_profiles;
2634d5c65159SKalle Valo 	wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
2635d5c65159SKalle Valo 	wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
2636d5c65159SKalle Valo 	wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
2637d5c65159SKalle Valo 	wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
2638d5c65159SKalle Valo 	wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
2639d5c65159SKalle Valo 	wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
2640d5c65159SKalle Valo 	wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
2641d5c65159SKalle Valo 	wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
2642d5c65159SKalle Valo 		tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
2643d5c65159SKalle Valo 	wmi_cfg->vow_config = tg_cfg->vow_config;
2644d5c65159SKalle Valo 	wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
2645d5c65159SKalle Valo 	wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
2646d5c65159SKalle Valo 	wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
2647d5c65159SKalle Valo 	wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
2648d5c65159SKalle Valo 	wmi_cfg->num_tdls_conn_table_entries =
2649d5c65159SKalle Valo 		tg_cfg->num_tdls_conn_table_entries;
2650d5c65159SKalle Valo 	wmi_cfg->beacon_tx_offload_max_vdev =
2651d5c65159SKalle Valo 		tg_cfg->beacon_tx_offload_max_vdev;
2652d5c65159SKalle Valo 	wmi_cfg->num_multicast_filter_entries =
2653d5c65159SKalle Valo 		tg_cfg->num_multicast_filter_entries;
2654d5c65159SKalle Valo 	wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
2655d5c65159SKalle Valo 	wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
2656d5c65159SKalle Valo 	wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
2657d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_sleep_sta =
2658d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_sleep_sta;
2659d5c65159SKalle Valo 	wmi_cfg->max_tdls_concurrent_buffer_sta =
2660d5c65159SKalle Valo 		tg_cfg->max_tdls_concurrent_buffer_sta;
2661d5c65159SKalle Valo 	wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
2662d5c65159SKalle Valo 	wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
2663d5c65159SKalle Valo 	wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
2664d5c65159SKalle Valo 	wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
2665d5c65159SKalle Valo 	wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
2666d5c65159SKalle Valo 	wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
2667d5c65159SKalle Valo 	wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
2668d5c65159SKalle Valo 	wmi_cfg->flag1 = tg_cfg->atf_config;
2669d5c65159SKalle Valo 	wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
26706d293d44SJohn Crispin 	wmi_cfg->sched_params = tg_cfg->sched_params;
26716d293d44SJohn Crispin 	wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
26726d293d44SJohn Crispin 	wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
2673d5c65159SKalle Valo }
2674d5c65159SKalle Valo 
2675d5c65159SKalle Valo static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
2676d5c65159SKalle Valo 				struct wmi_init_cmd_param *param)
2677d5c65159SKalle Valo {
2678d5c65159SKalle Valo 	struct ath11k_base *ab = wmi->wmi_sc->ab;
2679d5c65159SKalle Valo 	struct sk_buff *skb;
2680d5c65159SKalle Valo 	struct wmi_init_cmd *cmd;
2681d5c65159SKalle Valo 	struct wmi_resource_config *cfg;
2682d5c65159SKalle Valo 	struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
2683d5c65159SKalle Valo 	struct wmi_pdev_band_to_mac *band_to_mac;
2684d5c65159SKalle Valo 	struct wlan_host_mem_chunk *host_mem_chunks;
2685d5c65159SKalle Valo 	struct wmi_tlv *tlv;
2686d5c65159SKalle Valo 	size_t ret, len;
2687d5c65159SKalle Valo 	void *ptr;
2688d5c65159SKalle Valo 	u32 hw_mode_len = 0;
2689d5c65159SKalle Valo 	u16 idx;
2690d5c65159SKalle Valo 
2691d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
2692d5c65159SKalle Valo 		hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
2693d5c65159SKalle Valo 			      (param->num_band_to_mac * sizeof(*band_to_mac));
2694d5c65159SKalle Valo 
2695d5c65159SKalle Valo 	len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
2696d5c65159SKalle Valo 	      (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS);
2697d5c65159SKalle Valo 
2698d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, len);
2699d5c65159SKalle Valo 	if (!skb)
2700d5c65159SKalle Valo 		return -ENOMEM;
2701d5c65159SKalle Valo 
2702d5c65159SKalle Valo 	cmd = (struct wmi_init_cmd *)skb->data;
2703d5c65159SKalle Valo 
2704d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
2705d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2706d5c65159SKalle Valo 
2707d5c65159SKalle Valo 	ptr = skb->data + sizeof(*cmd);
2708d5c65159SKalle Valo 	cfg = ptr;
2709d5c65159SKalle Valo 
2710d5c65159SKalle Valo 	ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
2711d5c65159SKalle Valo 
2712d5c65159SKalle Valo 	cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
2713d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
2714d5c65159SKalle Valo 
2715d5c65159SKalle Valo 	ptr += sizeof(*cfg);
2716d5c65159SKalle Valo 	host_mem_chunks = ptr + TLV_HDR_SIZE;
2717d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk);
2718d5c65159SKalle Valo 
2719d5c65159SKalle Valo 	for (idx = 0; idx < param->num_mem_chunks; ++idx) {
2720d5c65159SKalle Valo 		host_mem_chunks[idx].tlv_header =
2721d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_TAG,
2722d5c65159SKalle Valo 					   WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
2723d5c65159SKalle Valo 				FIELD_PREP(WMI_TLV_LEN, len);
2724d5c65159SKalle Valo 
2725d5c65159SKalle Valo 		host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
2726d5c65159SKalle Valo 		host_mem_chunks[idx].size = param->mem_chunks[idx].len;
2727d5c65159SKalle Valo 		host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
2728d5c65159SKalle Valo 
2729d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
2730d5c65159SKalle Valo 			   "WMI host mem chunk req_id %d paddr 0x%llx len %d\n",
2731d5c65159SKalle Valo 			   param->mem_chunks[idx].req_id,
2732d5c65159SKalle Valo 			   (u64)param->mem_chunks[idx].paddr,
2733d5c65159SKalle Valo 			   param->mem_chunks[idx].len);
2734d5c65159SKalle Valo 	}
2735d5c65159SKalle Valo 	cmd->num_host_mem_chunks = param->num_mem_chunks;
2736d5c65159SKalle Valo 	len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
2737d5c65159SKalle Valo 
2738d5c65159SKalle Valo 	/* num_mem_chunks is zero */
2739d5c65159SKalle Valo 	tlv = ptr;
2740d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2741d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, len);
2742d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE + len;
2743d5c65159SKalle Valo 
2744d5c65159SKalle Valo 	if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
2745d5c65159SKalle Valo 		hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr;
2746d5c65159SKalle Valo 		hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2747d5c65159SKalle Valo 						 WMI_TAG_PDEV_SET_HW_MODE_CMD) |
2748d5c65159SKalle Valo 				      FIELD_PREP(WMI_TLV_LEN,
2749d5c65159SKalle Valo 						 sizeof(*hw_mode) - TLV_HDR_SIZE);
2750d5c65159SKalle Valo 
2751d5c65159SKalle Valo 		hw_mode->hw_mode_index = param->hw_mode_id;
2752d5c65159SKalle Valo 		hw_mode->num_band_to_mac = param->num_band_to_mac;
2753d5c65159SKalle Valo 
2754d5c65159SKalle Valo 		ptr += sizeof(*hw_mode);
2755d5c65159SKalle Valo 
2756d5c65159SKalle Valo 		len = param->num_band_to_mac * sizeof(*band_to_mac);
2757d5c65159SKalle Valo 		tlv = ptr;
2758d5c65159SKalle Valo 		tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2759d5c65159SKalle Valo 			      FIELD_PREP(WMI_TLV_LEN, len);
2760d5c65159SKalle Valo 
2761d5c65159SKalle Valo 		ptr += TLV_HDR_SIZE;
2762d5c65159SKalle Valo 		len = sizeof(*band_to_mac);
2763d5c65159SKalle Valo 
2764d5c65159SKalle Valo 		for (idx = 0; idx < param->num_band_to_mac; idx++) {
2765d5c65159SKalle Valo 			band_to_mac = (void *)ptr;
2766d5c65159SKalle Valo 
2767d5c65159SKalle Valo 			band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2768d5c65159SKalle Valo 							     WMI_TAG_PDEV_BAND_TO_MAC) |
2769d5c65159SKalle Valo 						  FIELD_PREP(WMI_TLV_LEN,
2770d5c65159SKalle Valo 							     len - TLV_HDR_SIZE);
2771d5c65159SKalle Valo 			band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
2772d5c65159SKalle Valo 			band_to_mac->start_freq =
2773d5c65159SKalle Valo 				param->band_to_mac[idx].start_freq;
2774d5c65159SKalle Valo 			band_to_mac->end_freq =
2775d5c65159SKalle Valo 				param->band_to_mac[idx].end_freq;
2776d5c65159SKalle Valo 			ptr += sizeof(*band_to_mac);
2777d5c65159SKalle Valo 		}
2778d5c65159SKalle Valo 	}
2779d5c65159SKalle Valo 
2780d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
2781d5c65159SKalle Valo 	if (ret) {
2782d5c65159SKalle Valo 		ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
2783d5c65159SKalle Valo 		dev_kfree_skb(skb);
2784d5c65159SKalle Valo 	}
2785d5c65159SKalle Valo 
2786d5c65159SKalle Valo 	return ret;
2787d5c65159SKalle Valo }
2788d5c65159SKalle Valo 
2789d5c65159SKalle Valo int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
2790d5c65159SKalle Valo {
2791d5c65159SKalle Valo 	unsigned long time_left;
2792d5c65159SKalle Valo 
2793d5c65159SKalle Valo 	time_left = wait_for_completion_timeout(&ab->wmi_sc.service_ready,
2794d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
2795d5c65159SKalle Valo 	if (!time_left)
2796d5c65159SKalle Valo 		return -ETIMEDOUT;
2797d5c65159SKalle Valo 
2798d5c65159SKalle Valo 	return 0;
2799d5c65159SKalle Valo }
2800d5c65159SKalle Valo 
2801d5c65159SKalle Valo int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
2802d5c65159SKalle Valo {
2803d5c65159SKalle Valo 	unsigned long time_left;
2804d5c65159SKalle Valo 
2805d5c65159SKalle Valo 	time_left = wait_for_completion_timeout(&ab->wmi_sc.unified_ready,
2806d5c65159SKalle Valo 						WMI_SERVICE_READY_TIMEOUT_HZ);
2807d5c65159SKalle Valo 	if (!time_left)
2808d5c65159SKalle Valo 		return -ETIMEDOUT;
2809d5c65159SKalle Valo 
2810d5c65159SKalle Valo 	return 0;
2811d5c65159SKalle Valo }
2812d5c65159SKalle Valo 
2813d5c65159SKalle Valo int ath11k_wmi_cmd_init(struct ath11k_base *ab)
2814d5c65159SKalle Valo {
2815d5c65159SKalle Valo 	struct ath11k_wmi_base *wmi_sc = &ab->wmi_sc;
2816d5c65159SKalle Valo 	struct wmi_init_cmd_param init_param;
2817d5c65159SKalle Valo 	struct target_resource_config  config;
2818d5c65159SKalle Valo 
2819d5c65159SKalle Valo 	memset(&init_param, 0, sizeof(init_param));
2820d5c65159SKalle Valo 	memset(&config, 0, sizeof(config));
2821d5c65159SKalle Valo 
2822d5c65159SKalle Valo 	config.num_vdevs = ab->num_radios * TARGET_NUM_VDEVS;
2823d5c65159SKalle Valo 
2824d5c65159SKalle Valo 	if (ab->num_radios == 2) {
2825d5c65159SKalle Valo 		config.num_peers = TARGET_NUM_PEERS(DBS);
2826d5c65159SKalle Valo 		config.num_tids = TARGET_NUM_TIDS(DBS);
2827d5c65159SKalle Valo 	} else if (ab->num_radios == 3) {
2828d5c65159SKalle Valo 		config.num_peers = TARGET_NUM_PEERS(DBS_SBS);
2829d5c65159SKalle Valo 		config.num_tids = TARGET_NUM_TIDS(DBS_SBS);
2830d5c65159SKalle Valo 	} else {
2831d5c65159SKalle Valo 		/* Control should not reach here */
2832d5c65159SKalle Valo 		config.num_peers = TARGET_NUM_PEERS(SINGLE);
2833d5c65159SKalle Valo 		config.num_tids = TARGET_NUM_TIDS(SINGLE);
2834d5c65159SKalle Valo 	}
2835d5c65159SKalle Valo 	config.num_offload_peers = TARGET_NUM_OFFLD_PEERS;
2836d5c65159SKalle Valo 	config.num_offload_reorder_buffs = TARGET_NUM_OFFLD_REORDER_BUFFS;
2837d5c65159SKalle Valo 	config.num_peer_keys = TARGET_NUM_PEER_KEYS;
2838d5c65159SKalle Valo 	config.ast_skid_limit = TARGET_AST_SKID_LIMIT;
2839d5c65159SKalle Valo 	config.tx_chain_mask = (1 << ab->target_caps.num_rf_chains) - 1;
2840d5c65159SKalle Valo 	config.rx_chain_mask = (1 << ab->target_caps.num_rf_chains) - 1;
2841d5c65159SKalle Valo 	config.rx_timeout_pri[0] = TARGET_RX_TIMEOUT_LO_PRI;
2842d5c65159SKalle Valo 	config.rx_timeout_pri[1] = TARGET_RX_TIMEOUT_LO_PRI;
2843d5c65159SKalle Valo 	config.rx_timeout_pri[2] = TARGET_RX_TIMEOUT_LO_PRI;
2844d5c65159SKalle Valo 	config.rx_timeout_pri[3] = TARGET_RX_TIMEOUT_HI_PRI;
2845d5c65159SKalle Valo 	config.rx_decap_mode = TARGET_DECAP_MODE_NATIVE_WIFI;
2846d5c65159SKalle Valo 	config.scan_max_pending_req = TARGET_SCAN_MAX_PENDING_REQS;
2847d5c65159SKalle Valo 	config.bmiss_offload_max_vdev = TARGET_BMISS_OFFLOAD_MAX_VDEV;
2848d5c65159SKalle Valo 	config.roam_offload_max_vdev = TARGET_ROAM_OFFLOAD_MAX_VDEV;
2849d5c65159SKalle Valo 	config.roam_offload_max_ap_profiles = TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES;
2850d5c65159SKalle Valo 	config.num_mcast_groups = TARGET_NUM_MCAST_GROUPS;
2851d5c65159SKalle Valo 	config.num_mcast_table_elems = TARGET_NUM_MCAST_TABLE_ELEMS;
2852d5c65159SKalle Valo 	config.mcast2ucast_mode = TARGET_MCAST2UCAST_MODE;
2853d5c65159SKalle Valo 	config.tx_dbg_log_size = TARGET_TX_DBG_LOG_SIZE;
2854d5c65159SKalle Valo 	config.num_wds_entries = TARGET_NUM_WDS_ENTRIES;
2855d5c65159SKalle Valo 	config.dma_burst_size = TARGET_DMA_BURST_SIZE;
2856d5c65159SKalle Valo 	config.rx_skip_defrag_timeout_dup_detection_check =
2857d5c65159SKalle Valo 		TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
2858d5c65159SKalle Valo 	config.vow_config = TARGET_VOW_CONFIG;
2859d5c65159SKalle Valo 	config.gtk_offload_max_vdev = TARGET_GTK_OFFLOAD_MAX_VDEV;
2860d5c65159SKalle Valo 	config.num_msdu_desc = TARGET_NUM_MSDU_DESC;
2861d5c65159SKalle Valo 	config.beacon_tx_offload_max_vdev = ab->num_radios * TARGET_MAX_BCN_OFFLD;
2862d5c65159SKalle Valo 	config.rx_batchmode = TARGET_RX_BATCHMODE;
2863d5c65159SKalle Valo 	config.peer_map_unmap_v2_support = 1;
28646d293d44SJohn Crispin 	config.twt_ap_pdev_count = 2;
28656d293d44SJohn Crispin 	config.twt_ap_sta_count = 1000;
2866d5c65159SKalle Valo 
2867d5c65159SKalle Valo 	memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config));
2868d5c65159SKalle Valo 
2869d5c65159SKalle Valo 	init_param.res_cfg = &wmi_sc->wlan_resource_config;
2870d5c65159SKalle Valo 	init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
2871d5c65159SKalle Valo 	init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
2872d5c65159SKalle Valo 	init_param.mem_chunks = wmi_sc->mem_chunks;
2873d5c65159SKalle Valo 
2874d5c65159SKalle Valo 	if (wmi_sc->preferred_hw_mode == WMI_HOST_HW_MODE_SINGLE)
2875d5c65159SKalle Valo 		init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
2876d5c65159SKalle Valo 
2877d5c65159SKalle Valo 	init_param.num_band_to_mac = ab->num_radios;
2878d5c65159SKalle Valo 
2879d5c65159SKalle Valo 	ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
2880d5c65159SKalle Valo 
2881d5c65159SKalle Valo 	return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param);
2882d5c65159SKalle Valo }
2883d5c65159SKalle Valo 
2884d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
2885d5c65159SKalle Valo 					     u16 tag, u16 len,
2886d5c65159SKalle Valo 					     const void *ptr, void *data)
2887d5c65159SKalle Valo {
2888d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
2889d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_cap;
2890d5c65159SKalle Valo 	u32 phy_map = 0;
2891d5c65159SKalle Valo 
2892d5c65159SKalle Valo 	if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
2893d5c65159SKalle Valo 		return -EPROTO;
2894d5c65159SKalle Valo 
2895d5c65159SKalle Valo 	if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
2896d5c65159SKalle Valo 		return -ENOBUFS;
2897d5c65159SKalle Valo 
2898d5c65159SKalle Valo 	hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
2899d5c65159SKalle Valo 				   hw_mode_id);
2900d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps++;
2901d5c65159SKalle Valo 
2902d5c65159SKalle Valo 	phy_map = hw_mode_cap->phy_id_map;
2903d5c65159SKalle Valo 	while (phy_map) {
2904d5c65159SKalle Valo 		svc_rdy_ext->tot_phy_id++;
2905d5c65159SKalle Valo 		phy_map = phy_map >> 1;
2906d5c65159SKalle Valo 	}
2907d5c65159SKalle Valo 
2908d5c65159SKalle Valo 	return 0;
2909d5c65159SKalle Valo }
2910d5c65159SKalle Valo 
2911d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
2912d5c65159SKalle Valo 				       u16 len, const void *ptr, void *data)
2913d5c65159SKalle Valo {
2914d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
2915d5c65159SKalle Valo 	struct wmi_hw_mode_capabilities *hw_mode_caps;
2916d5c65159SKalle Valo 	enum wmi_host_hw_mode_config_type mode, pref;
2917d5c65159SKalle Valo 	u32 i;
2918d5c65159SKalle Valo 	int ret;
2919d5c65159SKalle Valo 
2920d5c65159SKalle Valo 	svc_rdy_ext->n_hw_mode_caps = 0;
2921d5c65159SKalle Valo 	svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
2922d5c65159SKalle Valo 
2923d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
2924d5c65159SKalle Valo 				  ath11k_wmi_tlv_hw_mode_caps_parse,
2925d5c65159SKalle Valo 				  svc_rdy_ext);
2926d5c65159SKalle Valo 	if (ret) {
2927d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
2928d5c65159SKalle Valo 		return ret;
2929d5c65159SKalle Valo 	}
2930d5c65159SKalle Valo 
2931d5c65159SKalle Valo 	i = 0;
2932d5c65159SKalle Valo 	while (i < svc_rdy_ext->n_hw_mode_caps) {
2933d5c65159SKalle Valo 		hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
2934d5c65159SKalle Valo 		mode = hw_mode_caps->hw_mode_id;
2935d5c65159SKalle Valo 		pref = soc->wmi_sc.preferred_hw_mode;
2936d5c65159SKalle Valo 
2937d5c65159SKalle Valo 		if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
2938d5c65159SKalle Valo 			svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
2939d5c65159SKalle Valo 			soc->wmi_sc.preferred_hw_mode = mode;
2940d5c65159SKalle Valo 		}
2941d5c65159SKalle Valo 		i++;
2942d5c65159SKalle Valo 	}
2943d5c65159SKalle Valo 
2944d5c65159SKalle Valo 	if (soc->wmi_sc.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
2945d5c65159SKalle Valo 		return -EINVAL;
2946d5c65159SKalle Valo 
2947d5c65159SKalle Valo 	return 0;
2948d5c65159SKalle Valo }
2949d5c65159SKalle Valo 
2950d5c65159SKalle Valo static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
2951d5c65159SKalle Valo 					     u16 tag, u16 len,
2952d5c65159SKalle Valo 					     const void *ptr, void *data)
2953d5c65159SKalle Valo {
2954d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
2955d5c65159SKalle Valo 
2956d5c65159SKalle Valo 	if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
2957d5c65159SKalle Valo 		return -EPROTO;
2958d5c65159SKalle Valo 
2959d5c65159SKalle Valo 	if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
2960d5c65159SKalle Valo 		return -ENOBUFS;
2961d5c65159SKalle Valo 
2962*5b90fc76SAnilkumar Kolli 	len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
2963*5b90fc76SAnilkumar Kolli 	if (!svc_rdy_ext->n_mac_phy_caps) {
2964*5b90fc76SAnilkumar Kolli 		svc_rdy_ext->mac_phy_caps = kzalloc((svc_rdy_ext->tot_phy_id) * len,
2965*5b90fc76SAnilkumar Kolli 						    GFP_ATOMIC);
2966*5b90fc76SAnilkumar Kolli 		if (!svc_rdy_ext->mac_phy_caps)
2967*5b90fc76SAnilkumar Kolli 			return -ENOMEM;
2968*5b90fc76SAnilkumar Kolli 	}
2969*5b90fc76SAnilkumar Kolli 
2970*5b90fc76SAnilkumar Kolli 	memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
2971d5c65159SKalle Valo 	svc_rdy_ext->n_mac_phy_caps++;
2972d5c65159SKalle Valo 	return 0;
2973d5c65159SKalle Valo }
2974d5c65159SKalle Valo 
2975d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
2976d5c65159SKalle Valo 						 u16 tag, u16 len,
2977d5c65159SKalle Valo 						 const void *ptr, void *data)
2978d5c65159SKalle Valo {
2979d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
2980d5c65159SKalle Valo 
2981d5c65159SKalle Valo 	if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
2982d5c65159SKalle Valo 		return -EPROTO;
2983d5c65159SKalle Valo 
2984d5c65159SKalle Valo 	if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
2985d5c65159SKalle Valo 		return -ENOBUFS;
2986d5c65159SKalle Valo 
2987d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps++;
2988d5c65159SKalle Valo 	return 0;
2989d5c65159SKalle Valo }
2990d5c65159SKalle Valo 
2991d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
2992d5c65159SKalle Valo 					   u16 len, const void *ptr, void *data)
2993d5c65159SKalle Valo {
2994d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_sc.wmi[0];
2995d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
2996d5c65159SKalle Valo 	struct ath11k_hal_reg_capabilities_ext reg_cap;
2997d5c65159SKalle Valo 	int ret;
2998d5c65159SKalle Valo 	u32 i;
2999d5c65159SKalle Valo 
3000d5c65159SKalle Valo 	svc_rdy_ext->n_ext_hal_reg_caps = 0;
3001d5c65159SKalle Valo 	svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
3002d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(soc, ptr, len,
3003d5c65159SKalle Valo 				  ath11k_wmi_tlv_ext_hal_reg_caps_parse,
3004d5c65159SKalle Valo 				  svc_rdy_ext);
3005d5c65159SKalle Valo 	if (ret) {
3006d5c65159SKalle Valo 		ath11k_warn(soc, "failed to parse tlv %d\n", ret);
3007d5c65159SKalle Valo 		return ret;
3008d5c65159SKalle Valo 	}
3009d5c65159SKalle Valo 
3010d5c65159SKalle Valo 	for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
3011d5c65159SKalle Valo 		ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
3012d5c65159SKalle Valo 						      svc_rdy_ext->soc_hal_reg_caps,
3013d5c65159SKalle Valo 						      svc_rdy_ext->ext_hal_reg_caps, i,
3014d5c65159SKalle Valo 						      &reg_cap);
3015d5c65159SKalle Valo 		if (ret) {
3016d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract reg cap %d\n", i);
3017d5c65159SKalle Valo 			return ret;
3018d5c65159SKalle Valo 		}
3019d5c65159SKalle Valo 
3020d5c65159SKalle Valo 		memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
3021d5c65159SKalle Valo 		       &reg_cap, sizeof(reg_cap));
3022d5c65159SKalle Valo 	}
3023d5c65159SKalle Valo 	return 0;
3024d5c65159SKalle Valo }
3025d5c65159SKalle Valo 
3026d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
3027d5c65159SKalle Valo 						     u16 len, const void *ptr,
3028d5c65159SKalle Valo 						     void *data)
3029d5c65159SKalle Valo {
3030d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_sc.wmi[0];
3031d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3032d5c65159SKalle Valo 	u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
3033d5c65159SKalle Valo 	u32 phy_id_map;
3034d5c65159SKalle Valo 	int ret;
3035d5c65159SKalle Valo 
3036d5c65159SKalle Valo 	svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
3037d5c65159SKalle Valo 	svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
3038d5c65159SKalle Valo 
3039d5c65159SKalle Valo 	soc->num_radios = 0;
3040d5c65159SKalle Valo 	phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
3041d5c65159SKalle Valo 
3042d5c65159SKalle Valo 	while (phy_id_map && soc->num_radios < MAX_RADIOS) {
3043d5c65159SKalle Valo 		ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
3044d5c65159SKalle Valo 							    svc_rdy_ext->hw_caps,
3045d5c65159SKalle Valo 							    svc_rdy_ext->hw_mode_caps,
3046d5c65159SKalle Valo 							    svc_rdy_ext->soc_hal_reg_caps,
3047d5c65159SKalle Valo 							    svc_rdy_ext->mac_phy_caps,
3048d5c65159SKalle Valo 							    hw_mode_id, soc->num_radios,
3049d5c65159SKalle Valo 							    &soc->pdevs[soc->num_radios]);
3050d5c65159SKalle Valo 		if (ret) {
3051d5c65159SKalle Valo 			ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
3052d5c65159SKalle Valo 				    soc->num_radios);
3053d5c65159SKalle Valo 			return ret;
3054d5c65159SKalle Valo 		}
3055d5c65159SKalle Valo 
3056d5c65159SKalle Valo 		soc->num_radios++;
3057d5c65159SKalle Valo 
3058d5c65159SKalle Valo 		/* TODO: mac_phy_cap prints */
3059d5c65159SKalle Valo 		phy_id_map >>= 1;
3060d5c65159SKalle Valo 	}
3061d5c65159SKalle Valo 	return 0;
3062d5c65159SKalle Valo }
3063d5c65159SKalle Valo 
3064d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
3065d5c65159SKalle Valo 					    u16 tag, u16 len,
3066d5c65159SKalle Valo 					    const void *ptr, void *data)
3067d5c65159SKalle Valo {
3068d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_sc.wmi[0];
3069d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
3070d5c65159SKalle Valo 	int ret;
3071d5c65159SKalle Valo 
3072d5c65159SKalle Valo 	switch (tag) {
3073d5c65159SKalle Valo 	case WMI_TAG_SERVICE_READY_EXT_EVENT:
3074d5c65159SKalle Valo 		ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
3075d5c65159SKalle Valo 						&svc_rdy_ext->param);
3076d5c65159SKalle Valo 		if (ret) {
3077d5c65159SKalle Valo 			ath11k_warn(ab, "unable to extract ext params\n");
3078d5c65159SKalle Valo 			return ret;
3079d5c65159SKalle Valo 		}
3080d5c65159SKalle Valo 		break;
3081d5c65159SKalle Valo 
3082d5c65159SKalle Valo 	case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
3083d5c65159SKalle Valo 		svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
3084d5c65159SKalle Valo 		svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
3085d5c65159SKalle Valo 		break;
3086d5c65159SKalle Valo 
3087d5c65159SKalle Valo 	case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
3088d5c65159SKalle Valo 		ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
3089d5c65159SKalle Valo 								svc_rdy_ext);
3090d5c65159SKalle Valo 		if (ret)
3091d5c65159SKalle Valo 			return ret;
3092d5c65159SKalle Valo 		break;
3093d5c65159SKalle Valo 
3094d5c65159SKalle Valo 	case WMI_TAG_ARRAY_STRUCT:
3095d5c65159SKalle Valo 		if (!svc_rdy_ext->hw_mode_done) {
3096d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
3097d5c65159SKalle Valo 							  svc_rdy_ext);
3098d5c65159SKalle Valo 			if (ret)
3099d5c65159SKalle Valo 				return ret;
3100d5c65159SKalle Valo 
3101d5c65159SKalle Valo 			svc_rdy_ext->hw_mode_done = true;
3102d5c65159SKalle Valo 		} else if (!svc_rdy_ext->mac_phy_done) {
3103d5c65159SKalle Valo 			svc_rdy_ext->n_mac_phy_caps = 0;
3104d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_iter(ab, ptr, len,
3105d5c65159SKalle Valo 						  ath11k_wmi_tlv_mac_phy_caps_parse,
3106d5c65159SKalle Valo 						  svc_rdy_ext);
3107d5c65159SKalle Valo 			if (ret) {
3108d5c65159SKalle Valo 				ath11k_warn(ab, "failed to parse tlv %d\n", ret);
3109d5c65159SKalle Valo 				return ret;
3110d5c65159SKalle Valo 			}
3111d5c65159SKalle Valo 
3112d5c65159SKalle Valo 			svc_rdy_ext->mac_phy_done = true;
3113d5c65159SKalle Valo 		} else if (!svc_rdy_ext->ext_hal_reg_done) {
3114d5c65159SKalle Valo 			ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
3115d5c65159SKalle Valo 							      svc_rdy_ext);
3116d5c65159SKalle Valo 			if (ret)
3117d5c65159SKalle Valo 				return ret;
3118d5c65159SKalle Valo 
3119d5c65159SKalle Valo 			svc_rdy_ext->ext_hal_reg_done = true;
3120d5c65159SKalle Valo 			complete(&ab->wmi_sc.service_ready);
3121d5c65159SKalle Valo 		}
3122d5c65159SKalle Valo 		break;
3123d5c65159SKalle Valo 
3124d5c65159SKalle Valo 	default:
3125d5c65159SKalle Valo 		break;
3126d5c65159SKalle Valo 	}
3127d5c65159SKalle Valo 	return 0;
3128d5c65159SKalle Valo }
3129d5c65159SKalle Valo 
3130d5c65159SKalle Valo static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
3131d5c65159SKalle Valo 					  struct sk_buff *skb)
3132d5c65159SKalle Valo {
3133d5c65159SKalle Valo 	struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
3134d5c65159SKalle Valo 	int ret;
3135d5c65159SKalle Valo 
3136d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
3137d5c65159SKalle Valo 				  ath11k_wmi_tlv_svc_rdy_ext_parse,
3138d5c65159SKalle Valo 				  &svc_rdy_ext);
3139d5c65159SKalle Valo 	if (ret) {
3140d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
3141d5c65159SKalle Valo 		return ret;
3142d5c65159SKalle Valo 	}
3143d5c65159SKalle Valo 
3144*5b90fc76SAnilkumar Kolli 	kfree(svc_rdy_ext.mac_phy_caps);
3145d5c65159SKalle Valo 	return 0;
3146d5c65159SKalle Valo }
3147d5c65159SKalle Valo 
3148d5c65159SKalle Valo static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
3149d5c65159SKalle Valo 					   struct wmi_vdev_start_resp_event *vdev_rsp)
3150d5c65159SKalle Valo {
3151d5c65159SKalle Valo 	const void **tb;
3152d5c65159SKalle Valo 	const struct wmi_vdev_start_resp_event *ev;
3153d5c65159SKalle Valo 	int ret;
3154d5c65159SKalle Valo 
3155d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3156d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3157d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3158d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3159d5c65159SKalle Valo 		return ret;
3160d5c65159SKalle Valo 	}
3161d5c65159SKalle Valo 
3162d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
3163d5c65159SKalle Valo 	if (!ev) {
3164d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev start resp ev");
3165d5c65159SKalle Valo 		kfree(tb);
3166d5c65159SKalle Valo 		return -EPROTO;
3167d5c65159SKalle Valo 	}
3168d5c65159SKalle Valo 
3169d5c65159SKalle Valo 	memset(vdev_rsp, 0, sizeof(*vdev_rsp));
3170d5c65159SKalle Valo 
3171d5c65159SKalle Valo 	vdev_rsp->vdev_id = ev->vdev_id;
3172d5c65159SKalle Valo 	vdev_rsp->requestor_id = ev->requestor_id;
3173d5c65159SKalle Valo 	vdev_rsp->resp_type = ev->resp_type;
3174d5c65159SKalle Valo 	vdev_rsp->status = ev->status;
3175d5c65159SKalle Valo 	vdev_rsp->chain_mask = ev->chain_mask;
3176d5c65159SKalle Valo 	vdev_rsp->smps_mode = ev->smps_mode;
3177d5c65159SKalle Valo 	vdev_rsp->mac_id = ev->mac_id;
3178d5c65159SKalle Valo 	vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
3179d5c65159SKalle Valo 	vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
3180d5c65159SKalle Valo 
3181d5c65159SKalle Valo 	kfree(tb);
3182d5c65159SKalle Valo 	return 0;
3183d5c65159SKalle Valo }
3184d5c65159SKalle Valo 
3185d5c65159SKalle Valo static struct cur_reg_rule
3186d5c65159SKalle Valo *create_reg_rules_from_wmi(u32 num_reg_rules,
3187d5c65159SKalle Valo 			   struct wmi_regulatory_rule_struct *wmi_reg_rule)
3188d5c65159SKalle Valo {
3189d5c65159SKalle Valo 	struct cur_reg_rule *reg_rule_ptr;
3190d5c65159SKalle Valo 	u32 count;
3191d5c65159SKalle Valo 
3192d5c65159SKalle Valo 	reg_rule_ptr =  kzalloc((num_reg_rules * sizeof(*reg_rule_ptr)),
3193d5c65159SKalle Valo 				GFP_ATOMIC);
3194d5c65159SKalle Valo 
3195d5c65159SKalle Valo 	if (!reg_rule_ptr)
3196d5c65159SKalle Valo 		return NULL;
3197d5c65159SKalle Valo 
3198d5c65159SKalle Valo 	for (count = 0; count < num_reg_rules; count++) {
3199d5c65159SKalle Valo 		reg_rule_ptr[count].start_freq =
3200d5c65159SKalle Valo 			FIELD_GET(REG_RULE_START_FREQ,
3201d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
3202d5c65159SKalle Valo 		reg_rule_ptr[count].end_freq =
3203d5c65159SKalle Valo 			FIELD_GET(REG_RULE_END_FREQ,
3204d5c65159SKalle Valo 				  wmi_reg_rule[count].freq_info);
3205d5c65159SKalle Valo 		reg_rule_ptr[count].max_bw =
3206d5c65159SKalle Valo 			FIELD_GET(REG_RULE_MAX_BW,
3207d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
3208d5c65159SKalle Valo 		reg_rule_ptr[count].reg_power =
3209d5c65159SKalle Valo 			FIELD_GET(REG_RULE_REG_PWR,
3210d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
3211d5c65159SKalle Valo 		reg_rule_ptr[count].ant_gain =
3212d5c65159SKalle Valo 			FIELD_GET(REG_RULE_ANT_GAIN,
3213d5c65159SKalle Valo 				  wmi_reg_rule[count].bw_pwr_info);
3214d5c65159SKalle Valo 		reg_rule_ptr[count].flags =
3215d5c65159SKalle Valo 			FIELD_GET(REG_RULE_FLAGS,
3216d5c65159SKalle Valo 				  wmi_reg_rule[count].flag_info);
3217d5c65159SKalle Valo 	}
3218d5c65159SKalle Valo 
3219d5c65159SKalle Valo 	return reg_rule_ptr;
3220d5c65159SKalle Valo }
3221d5c65159SKalle Valo 
3222d5c65159SKalle Valo static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
3223d5c65159SKalle Valo 					       struct sk_buff *skb,
3224d5c65159SKalle Valo 					       struct cur_regulatory_info *reg_info)
3225d5c65159SKalle Valo {
3226d5c65159SKalle Valo 	const void **tb;
3227d5c65159SKalle Valo 	const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
3228d5c65159SKalle Valo 	struct wmi_regulatory_rule_struct *wmi_reg_rule;
3229d5c65159SKalle Valo 	u32 num_2g_reg_rules, num_5g_reg_rules;
3230d5c65159SKalle Valo 	int ret;
3231d5c65159SKalle Valo 
3232d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
3233d5c65159SKalle Valo 
3234d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3235d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3236d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3237d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3238d5c65159SKalle Valo 		return ret;
3239d5c65159SKalle Valo 	}
3240d5c65159SKalle Valo 
3241d5c65159SKalle Valo 	chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
3242d5c65159SKalle Valo 	if (!chan_list_event_hdr) {
3243d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
3244d5c65159SKalle Valo 		kfree(tb);
3245d5c65159SKalle Valo 		return -EPROTO;
3246d5c65159SKalle Valo 	}
3247d5c65159SKalle Valo 
3248d5c65159SKalle Valo 	reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules;
3249d5c65159SKalle Valo 	reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules;
3250d5c65159SKalle Valo 
3251d5c65159SKalle Valo 	if (!(reg_info->num_2g_reg_rules + reg_info->num_5g_reg_rules)) {
3252d5c65159SKalle Valo 		ath11k_warn(ab, "No regulatory rules available in the event info\n");
3253d5c65159SKalle Valo 		kfree(tb);
3254d5c65159SKalle Valo 		return -EINVAL;
3255d5c65159SKalle Valo 	}
3256d5c65159SKalle Valo 
3257d5c65159SKalle Valo 	memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
3258d5c65159SKalle Valo 	       REG_ALPHA2_LEN);
3259d5c65159SKalle Valo 	reg_info->dfs_region = chan_list_event_hdr->dfs_region;
3260d5c65159SKalle Valo 	reg_info->phybitmap = chan_list_event_hdr->phybitmap;
3261d5c65159SKalle Valo 	reg_info->num_phy = chan_list_event_hdr->num_phy;
3262d5c65159SKalle Valo 	reg_info->phy_id = chan_list_event_hdr->phy_id;
3263d5c65159SKalle Valo 	reg_info->ctry_code = chan_list_event_hdr->country_id;
3264d5c65159SKalle Valo 	reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
3265d5c65159SKalle Valo 	if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS)
3266d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_PASS;
3267d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND)
3268d5c65159SKalle Valo 		reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND;
3269d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND)
3270d5c65159SKalle Valo 		reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND;
3271d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED)
3272d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED;
3273d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY)
3274d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY;
3275d5c65159SKalle Valo 	else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL)
3276d5c65159SKalle Valo 		reg_info->status_code = REG_SET_CC_STATUS_FAIL;
3277d5c65159SKalle Valo 
3278d5c65159SKalle Valo 	reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g;
3279d5c65159SKalle Valo 	reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g;
3280d5c65159SKalle Valo 	reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g;
3281d5c65159SKalle Valo 	reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g;
3282d5c65159SKalle Valo 
3283d5c65159SKalle Valo 	num_2g_reg_rules = reg_info->num_2g_reg_rules;
3284d5c65159SKalle Valo 	num_5g_reg_rules = reg_info->num_5g_reg_rules;
3285d5c65159SKalle Valo 
3286d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
3287d5c65159SKalle Valo 		   "%s:cc %s dsf %d BW: min_2g %d max_2g %d min_5g %d max_5g %d",
3288d5c65159SKalle Valo 		   __func__, reg_info->alpha2, reg_info->dfs_region,
3289d5c65159SKalle Valo 		   reg_info->min_bw_2g, reg_info->max_bw_2g,
3290d5c65159SKalle Valo 		   reg_info->min_bw_5g, reg_info->max_bw_5g);
3291d5c65159SKalle Valo 
3292d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
3293d5c65159SKalle Valo 		   "%s: num_2g_reg_rules %d num_5g_reg_rules %d", __func__,
3294d5c65159SKalle Valo 		   num_2g_reg_rules, num_5g_reg_rules);
3295d5c65159SKalle Valo 
3296d5c65159SKalle Valo 	wmi_reg_rule =
3297d5c65159SKalle Valo 		(struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
3298d5c65159SKalle Valo 						+ sizeof(*chan_list_event_hdr)
3299d5c65159SKalle Valo 						+ sizeof(struct wmi_tlv));
3300d5c65159SKalle Valo 
3301d5c65159SKalle Valo 	if (num_2g_reg_rules) {
3302d5c65159SKalle Valo 		reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules,
3303d5c65159SKalle Valo 								       wmi_reg_rule);
3304d5c65159SKalle Valo 		if (!reg_info->reg_rules_2g_ptr) {
3305d5c65159SKalle Valo 			kfree(tb);
3306d5c65159SKalle Valo 			ath11k_warn(ab, "Unable to Allocate memory for 2g rules\n");
3307d5c65159SKalle Valo 			return -ENOMEM;
3308d5c65159SKalle Valo 		}
3309d5c65159SKalle Valo 	}
3310d5c65159SKalle Valo 
3311d5c65159SKalle Valo 	if (num_5g_reg_rules) {
3312d5c65159SKalle Valo 		wmi_reg_rule += num_2g_reg_rules;
3313d5c65159SKalle Valo 		reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules,
3314d5c65159SKalle Valo 								       wmi_reg_rule);
3315d5c65159SKalle Valo 		if (!reg_info->reg_rules_5g_ptr) {
3316d5c65159SKalle Valo 			kfree(tb);
3317d5c65159SKalle Valo 			ath11k_warn(ab, "Unable to Allocate memory for 5g rules\n");
3318d5c65159SKalle Valo 			return -ENOMEM;
3319d5c65159SKalle Valo 		}
3320d5c65159SKalle Valo 	}
3321d5c65159SKalle Valo 
3322d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
3323d5c65159SKalle Valo 
3324d5c65159SKalle Valo 	kfree(tb);
3325d5c65159SKalle Valo 	return 0;
3326d5c65159SKalle Valo }
3327d5c65159SKalle Valo 
3328d5c65159SKalle Valo static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
3329d5c65159SKalle Valo 					struct wmi_peer_delete_resp_event *peer_del_resp)
3330d5c65159SKalle Valo {
3331d5c65159SKalle Valo 	const void **tb;
3332d5c65159SKalle Valo 	const struct wmi_peer_delete_resp_event *ev;
3333d5c65159SKalle Valo 	int ret;
3334d5c65159SKalle Valo 
3335d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3336d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3337d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3338d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3339d5c65159SKalle Valo 		return ret;
3340d5c65159SKalle Valo 	}
3341d5c65159SKalle Valo 
3342d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
3343d5c65159SKalle Valo 	if (!ev) {
3344d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer delete resp ev");
3345d5c65159SKalle Valo 		kfree(tb);
3346d5c65159SKalle Valo 		return -EPROTO;
3347d5c65159SKalle Valo 	}
3348d5c65159SKalle Valo 
3349d5c65159SKalle Valo 	memset(peer_del_resp, 0, sizeof(*peer_del_resp));
3350d5c65159SKalle Valo 
3351d5c65159SKalle Valo 	peer_del_resp->vdev_id = ev->vdev_id;
3352d5c65159SKalle Valo 	ether_addr_copy(peer_del_resp->peer_macaddr.addr,
3353d5c65159SKalle Valo 			ev->peer_macaddr.addr);
3354d5c65159SKalle Valo 
3355d5c65159SKalle Valo 	kfree(tb);
3356d5c65159SKalle Valo 	return 0;
3357d5c65159SKalle Valo }
3358d5c65159SKalle Valo 
3359d5c65159SKalle Valo static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
3360d5c65159SKalle Valo 					u32 len, u32 *vdev_id,
3361d5c65159SKalle Valo 					u32 *tx_status)
3362d5c65159SKalle Valo {
3363d5c65159SKalle Valo 	const void **tb;
3364d5c65159SKalle Valo 	const struct wmi_bcn_tx_status_event *ev;
3365d5c65159SKalle Valo 	int ret;
3366d5c65159SKalle Valo 
3367d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
3368d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3369d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3370d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3371d5c65159SKalle Valo 		return ret;
3372d5c65159SKalle Valo 	}
3373d5c65159SKalle Valo 
3374d5c65159SKalle Valo 	ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
3375d5c65159SKalle Valo 	if (!ev) {
3376d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch bcn tx status ev");
3377d5c65159SKalle Valo 		kfree(tb);
3378d5c65159SKalle Valo 		return -EPROTO;
3379d5c65159SKalle Valo 	}
3380d5c65159SKalle Valo 
3381d5c65159SKalle Valo 	*vdev_id   = ev->vdev_id;
3382d5c65159SKalle Valo 	*tx_status = ev->tx_status;
3383d5c65159SKalle Valo 
3384d5c65159SKalle Valo 	kfree(tb);
3385d5c65159SKalle Valo 	return 0;
3386d5c65159SKalle Valo }
3387d5c65159SKalle Valo 
3388d5c65159SKalle Valo static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
3389d5c65159SKalle Valo 					      u32 *vdev_id)
3390d5c65159SKalle Valo {
3391d5c65159SKalle Valo 	const void **tb;
3392d5c65159SKalle Valo 	const struct wmi_vdev_stopped_event *ev;
3393d5c65159SKalle Valo 	int ret;
3394d5c65159SKalle Valo 
3395d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3396d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3397d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3398d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3399d5c65159SKalle Valo 		return ret;
3400d5c65159SKalle Valo 	}
3401d5c65159SKalle Valo 
3402d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
3403d5c65159SKalle Valo 	if (!ev) {
3404d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev stop ev");
3405d5c65159SKalle Valo 		kfree(tb);
3406d5c65159SKalle Valo 		return -EPROTO;
3407d5c65159SKalle Valo 	}
3408d5c65159SKalle Valo 
3409d5c65159SKalle Valo 	*vdev_id =  ev->vdev_id;
3410d5c65159SKalle Valo 
3411d5c65159SKalle Valo 	kfree(tb);
3412d5c65159SKalle Valo 	return 0;
3413d5c65159SKalle Valo }
3414d5c65159SKalle Valo 
3415d5c65159SKalle Valo static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
3416d5c65159SKalle Valo 					  struct sk_buff *skb,
3417d5c65159SKalle Valo 					  struct mgmt_rx_event_params *hdr)
3418d5c65159SKalle Valo {
3419d5c65159SKalle Valo 	const void **tb;
3420d5c65159SKalle Valo 	const struct wmi_mgmt_rx_hdr *ev;
3421d5c65159SKalle Valo 	const u8 *frame;
3422d5c65159SKalle Valo 	int ret;
3423d5c65159SKalle Valo 
3424d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3425d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3426d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3427d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3428d5c65159SKalle Valo 		return ret;
3429d5c65159SKalle Valo 	}
3430d5c65159SKalle Valo 
3431d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_RX_HDR];
3432d5c65159SKalle Valo 	frame = tb[WMI_TAG_ARRAY_BYTE];
3433d5c65159SKalle Valo 
3434d5c65159SKalle Valo 	if (!ev || !frame) {
3435d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt rx hdr");
3436d5c65159SKalle Valo 		kfree(tb);
3437d5c65159SKalle Valo 		return -EPROTO;
3438d5c65159SKalle Valo 	}
3439d5c65159SKalle Valo 
3440d5c65159SKalle Valo 	hdr->pdev_id =  ev->pdev_id;
3441d5c65159SKalle Valo 	hdr->channel =  ev->channel;
3442d5c65159SKalle Valo 	hdr->snr =  ev->snr;
3443d5c65159SKalle Valo 	hdr->rate =  ev->rate;
3444d5c65159SKalle Valo 	hdr->phy_mode =  ev->phy_mode;
3445d5c65159SKalle Valo 	hdr->buf_len =  ev->buf_len;
3446d5c65159SKalle Valo 	hdr->status =  ev->status;
3447d5c65159SKalle Valo 	hdr->flags =  ev->flags;
3448d5c65159SKalle Valo 	hdr->rssi =  ev->rssi;
3449d5c65159SKalle Valo 	hdr->tsf_delta =  ev->tsf_delta;
3450d5c65159SKalle Valo 	memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
3451d5c65159SKalle Valo 
3452d5c65159SKalle Valo 	if (skb->len < (frame - skb->data) + hdr->buf_len) {
3453d5c65159SKalle Valo 		ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
3454d5c65159SKalle Valo 		kfree(tb);
3455d5c65159SKalle Valo 		return -EPROTO;
3456d5c65159SKalle Valo 	}
3457d5c65159SKalle Valo 
3458d5c65159SKalle Valo 	/* shift the sk_buff to point to `frame` */
3459d5c65159SKalle Valo 	skb_trim(skb, 0);
3460d5c65159SKalle Valo 	skb_put(skb, frame - skb->data);
3461d5c65159SKalle Valo 	skb_pull(skb, frame - skb->data);
3462d5c65159SKalle Valo 	skb_put(skb, hdr->buf_len);
3463d5c65159SKalle Valo 
3464d5c65159SKalle Valo 	ath11k_ce_byte_swap(skb->data, hdr->buf_len);
3465d5c65159SKalle Valo 
3466d5c65159SKalle Valo 	kfree(tb);
3467d5c65159SKalle Valo 	return 0;
3468d5c65159SKalle Valo }
3469d5c65159SKalle Valo 
3470d5c65159SKalle Valo static int wmi_process_mgmt_tx_comp(struct ath11k *ar, u32 desc_id,
3471d5c65159SKalle Valo 				    u32 status)
3472d5c65159SKalle Valo {
3473d5c65159SKalle Valo 	struct sk_buff *msdu;
3474d5c65159SKalle Valo 	struct ieee80211_tx_info *info;
3475d5c65159SKalle Valo 	struct ath11k_skb_cb *skb_cb;
3476d5c65159SKalle Valo 
3477d5c65159SKalle Valo 	spin_lock_bh(&ar->txmgmt_idr_lock);
3478d5c65159SKalle Valo 	msdu = idr_find(&ar->txmgmt_idr, desc_id);
3479d5c65159SKalle Valo 
3480d5c65159SKalle Valo 	if (!msdu) {
3481d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
3482d5c65159SKalle Valo 			    desc_id);
3483d5c65159SKalle Valo 		spin_unlock_bh(&ar->txmgmt_idr_lock);
3484d5c65159SKalle Valo 		return -ENOENT;
3485d5c65159SKalle Valo 	}
3486d5c65159SKalle Valo 
3487d5c65159SKalle Valo 	idr_remove(&ar->txmgmt_idr, desc_id);
3488d5c65159SKalle Valo 	spin_unlock_bh(&ar->txmgmt_idr_lock);
3489d5c65159SKalle Valo 
3490d5c65159SKalle Valo 	skb_cb = ATH11K_SKB_CB(msdu);
3491d5c65159SKalle Valo 	dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
3492d5c65159SKalle Valo 
3493d5c65159SKalle Valo 	info = IEEE80211_SKB_CB(msdu);
3494d5c65159SKalle Valo 	if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) && !status)
3495d5c65159SKalle Valo 		info->flags |= IEEE80211_TX_STAT_ACK;
3496d5c65159SKalle Valo 
3497d5c65159SKalle Valo 	ieee80211_tx_status_irqsafe(ar->hw, msdu);
3498d5c65159SKalle Valo 
3499d5c65159SKalle Valo 	WARN_ON_ONCE(atomic_read(&ar->num_pending_mgmt_tx) == 0);
3500d5c65159SKalle Valo 	atomic_dec(&ar->num_pending_mgmt_tx);
3501d5c65159SKalle Valo 
3502d5c65159SKalle Valo 	return 0;
3503d5c65159SKalle Valo }
3504d5c65159SKalle Valo 
3505d5c65159SKalle Valo static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
3506d5c65159SKalle Valo 					       struct sk_buff *skb,
3507d5c65159SKalle Valo 					       struct wmi_mgmt_tx_compl_event *param)
3508d5c65159SKalle Valo {
3509d5c65159SKalle Valo 	const void **tb;
3510d5c65159SKalle Valo 	const struct wmi_mgmt_tx_compl_event *ev;
3511d5c65159SKalle Valo 	int ret;
3512d5c65159SKalle Valo 
3513d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3514d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3515d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3516d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3517d5c65159SKalle Valo 		return ret;
3518d5c65159SKalle Valo 	}
3519d5c65159SKalle Valo 
3520d5c65159SKalle Valo 	ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
3521d5c65159SKalle Valo 	if (!ev) {
3522d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
3523d5c65159SKalle Valo 		kfree(tb);
3524d5c65159SKalle Valo 		return -EPROTO;
3525d5c65159SKalle Valo 	}
3526d5c65159SKalle Valo 
3527d5c65159SKalle Valo 	param->pdev_id = ev->pdev_id;
3528d5c65159SKalle Valo 	param->desc_id = ev->desc_id;
3529d5c65159SKalle Valo 	param->status = ev->status;
3530d5c65159SKalle Valo 
3531d5c65159SKalle Valo 	kfree(tb);
3532d5c65159SKalle Valo 	return 0;
3533d5c65159SKalle Valo }
3534d5c65159SKalle Valo 
3535d5c65159SKalle Valo static void ath11k_wmi_event_scan_started(struct ath11k *ar)
3536d5c65159SKalle Valo {
3537d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
3538d5c65159SKalle Valo 
3539d5c65159SKalle Valo 	switch (ar->scan.state) {
3540d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
3541d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
3542d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
3543d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
3544d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
3545d5c65159SKalle Valo 			    ar->scan.state);
3546d5c65159SKalle Valo 		break;
3547d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
3548d5c65159SKalle Valo 		ar->scan.state = ATH11K_SCAN_RUNNING;
3549d5c65159SKalle Valo 		complete(&ar->scan.started);
3550d5c65159SKalle Valo 		break;
3551d5c65159SKalle Valo 	}
3552d5c65159SKalle Valo }
3553d5c65159SKalle Valo 
3554d5c65159SKalle Valo static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
3555d5c65159SKalle Valo {
3556d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
3557d5c65159SKalle Valo 
3558d5c65159SKalle Valo 	switch (ar->scan.state) {
3559d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
3560d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
3561d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
3562d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
3563d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
3564d5c65159SKalle Valo 			    ar->scan.state);
3565d5c65159SKalle Valo 		break;
3566d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
3567d5c65159SKalle Valo 		complete(&ar->scan.started);
3568d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
3569d5c65159SKalle Valo 		break;
3570d5c65159SKalle Valo 	}
3571d5c65159SKalle Valo }
3572d5c65159SKalle Valo 
3573d5c65159SKalle Valo static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
3574d5c65159SKalle Valo {
3575d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
3576d5c65159SKalle Valo 
3577d5c65159SKalle Valo 	switch (ar->scan.state) {
3578d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
3579d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
3580d5c65159SKalle Valo 		/* One suspected reason scan can be completed while starting is
3581d5c65159SKalle Valo 		 * if firmware fails to deliver all scan events to the host,
3582d5c65159SKalle Valo 		 * e.g. when transport pipe is full. This has been observed
3583d5c65159SKalle Valo 		 * with spectral scan phyerr events starving wmi transport
3584d5c65159SKalle Valo 		 * pipe. In such case the "scan completed" event should be (and
3585d5c65159SKalle Valo 		 * is) ignored by the host as it may be just firmware's scan
3586d5c65159SKalle Valo 		 * state machine recovering.
3587d5c65159SKalle Valo 		 */
3588d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
3589d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
3590d5c65159SKalle Valo 			    ar->scan.state);
3591d5c65159SKalle Valo 		break;
3592d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
3593d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
3594d5c65159SKalle Valo 		__ath11k_mac_scan_finish(ar);
3595d5c65159SKalle Valo 		break;
3596d5c65159SKalle Valo 	}
3597d5c65159SKalle Valo }
3598d5c65159SKalle Valo 
3599d5c65159SKalle Valo static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
3600d5c65159SKalle Valo {
3601d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
3602d5c65159SKalle Valo 
3603d5c65159SKalle Valo 	switch (ar->scan.state) {
3604d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
3605d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
3606d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
3607d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
3608d5c65159SKalle Valo 			    ar->scan.state);
3609d5c65159SKalle Valo 		break;
3610d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
3611d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
3612d5c65159SKalle Valo 		ar->scan_channel = NULL;
3613d5c65159SKalle Valo 		break;
3614d5c65159SKalle Valo 	}
3615d5c65159SKalle Valo }
3616d5c65159SKalle Valo 
3617d5c65159SKalle Valo static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
3618d5c65159SKalle Valo {
3619d5c65159SKalle Valo 	lockdep_assert_held(&ar->data_lock);
3620d5c65159SKalle Valo 
3621d5c65159SKalle Valo 	switch (ar->scan.state) {
3622d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
3623d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
3624d5c65159SKalle Valo 		ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
3625d5c65159SKalle Valo 			    ath11k_scan_state_str(ar->scan.state),
3626d5c65159SKalle Valo 			    ar->scan.state);
3627d5c65159SKalle Valo 		break;
3628d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
3629d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
3630d5c65159SKalle Valo 		ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
3631d5c65159SKalle Valo 		break;
3632d5c65159SKalle Valo 	}
3633d5c65159SKalle Valo }
3634d5c65159SKalle Valo 
3635d5c65159SKalle Valo static const char *
3636d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
3637d5c65159SKalle Valo 			       enum wmi_scan_completion_reason reason)
3638d5c65159SKalle Valo {
3639d5c65159SKalle Valo 	switch (type) {
3640d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
3641d5c65159SKalle Valo 		return "started";
3642d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
3643d5c65159SKalle Valo 		switch (reason) {
3644d5c65159SKalle Valo 		case WMI_SCAN_REASON_COMPLETED:
3645d5c65159SKalle Valo 			return "completed";
3646d5c65159SKalle Valo 		case WMI_SCAN_REASON_CANCELLED:
3647d5c65159SKalle Valo 			return "completed [cancelled]";
3648d5c65159SKalle Valo 		case WMI_SCAN_REASON_PREEMPTED:
3649d5c65159SKalle Valo 			return "completed [preempted]";
3650d5c65159SKalle Valo 		case WMI_SCAN_REASON_TIMEDOUT:
3651d5c65159SKalle Valo 			return "completed [timedout]";
3652d5c65159SKalle Valo 		case WMI_SCAN_REASON_INTERNAL_FAILURE:
3653d5c65159SKalle Valo 			return "completed [internal err]";
3654d5c65159SKalle Valo 		case WMI_SCAN_REASON_MAX:
3655d5c65159SKalle Valo 			break;
3656d5c65159SKalle Valo 		}
3657d5c65159SKalle Valo 		return "completed [unknown]";
3658d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
3659d5c65159SKalle Valo 		return "bss channel";
3660d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
3661d5c65159SKalle Valo 		return "foreign channel";
3662d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
3663d5c65159SKalle Valo 		return "dequeued";
3664d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
3665d5c65159SKalle Valo 		return "preempted";
3666d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
3667d5c65159SKalle Valo 		return "start failed";
3668d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
3669d5c65159SKalle Valo 		return "restarted";
3670d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
3671d5c65159SKalle Valo 		return "foreign channel exit";
3672d5c65159SKalle Valo 	default:
3673d5c65159SKalle Valo 		return "unknown";
3674d5c65159SKalle Valo 	}
3675d5c65159SKalle Valo }
3676d5c65159SKalle Valo 
3677d5c65159SKalle Valo static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
3678d5c65159SKalle Valo 			       struct wmi_scan_event *scan_evt_param)
3679d5c65159SKalle Valo {
3680d5c65159SKalle Valo 	const void **tb;
3681d5c65159SKalle Valo 	const struct wmi_scan_event *ev;
3682d5c65159SKalle Valo 	int ret;
3683d5c65159SKalle Valo 
3684d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3685d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3686d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3687d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3688d5c65159SKalle Valo 		return ret;
3689d5c65159SKalle Valo 	}
3690d5c65159SKalle Valo 
3691d5c65159SKalle Valo 	ev = tb[WMI_TAG_SCAN_EVENT];
3692d5c65159SKalle Valo 	if (!ev) {
3693d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch scan ev");
3694d5c65159SKalle Valo 		kfree(tb);
3695d5c65159SKalle Valo 		return -EPROTO;
3696d5c65159SKalle Valo 	}
3697d5c65159SKalle Valo 
3698d5c65159SKalle Valo 	scan_evt_param->event_type = ev->event_type;
3699d5c65159SKalle Valo 	scan_evt_param->reason = ev->reason;
3700d5c65159SKalle Valo 	scan_evt_param->channel_freq = ev->channel_freq;
3701d5c65159SKalle Valo 	scan_evt_param->scan_req_id = ev->scan_req_id;
3702d5c65159SKalle Valo 	scan_evt_param->scan_id = ev->scan_id;
3703d5c65159SKalle Valo 	scan_evt_param->vdev_id = ev->vdev_id;
3704d5c65159SKalle Valo 	scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
3705d5c65159SKalle Valo 
3706d5c65159SKalle Valo 	kfree(tb);
3707d5c65159SKalle Valo 	return 0;
3708d5c65159SKalle Valo }
3709d5c65159SKalle Valo 
3710d5c65159SKalle Valo static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
3711d5c65159SKalle Valo 					   struct wmi_peer_sta_kickout_arg *arg)
3712d5c65159SKalle Valo {
3713d5c65159SKalle Valo 	const void **tb;
3714d5c65159SKalle Valo 	const struct wmi_peer_sta_kickout_event *ev;
3715d5c65159SKalle Valo 	int ret;
3716d5c65159SKalle Valo 
3717d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3718d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3719d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3720d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3721d5c65159SKalle Valo 		return ret;
3722d5c65159SKalle Valo 	}
3723d5c65159SKalle Valo 
3724d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
3725d5c65159SKalle Valo 	if (!ev) {
3726d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer sta kickout ev");
3727d5c65159SKalle Valo 		kfree(tb);
3728d5c65159SKalle Valo 		return -EPROTO;
3729d5c65159SKalle Valo 	}
3730d5c65159SKalle Valo 
3731d5c65159SKalle Valo 	arg->mac_addr = ev->peer_macaddr.addr;
3732d5c65159SKalle Valo 
3733d5c65159SKalle Valo 	kfree(tb);
3734d5c65159SKalle Valo 	return 0;
3735d5c65159SKalle Valo }
3736d5c65159SKalle Valo 
3737d5c65159SKalle Valo static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
3738d5c65159SKalle Valo 			       struct wmi_roam_event *roam_ev)
3739d5c65159SKalle Valo {
3740d5c65159SKalle Valo 	const void **tb;
3741d5c65159SKalle Valo 	const struct wmi_roam_event *ev;
3742d5c65159SKalle Valo 	int ret;
3743d5c65159SKalle Valo 
3744d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3745d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3746d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3747d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3748d5c65159SKalle Valo 		return ret;
3749d5c65159SKalle Valo 	}
3750d5c65159SKalle Valo 
3751d5c65159SKalle Valo 	ev = tb[WMI_TAG_ROAM_EVENT];
3752d5c65159SKalle Valo 	if (!ev) {
3753d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch roam ev");
3754d5c65159SKalle Valo 		kfree(tb);
3755d5c65159SKalle Valo 		return -EPROTO;
3756d5c65159SKalle Valo 	}
3757d5c65159SKalle Valo 
3758d5c65159SKalle Valo 	roam_ev->vdev_id = ev->vdev_id;
3759d5c65159SKalle Valo 	roam_ev->reason = ev->reason;
3760d5c65159SKalle Valo 	roam_ev->rssi = ev->rssi;
3761d5c65159SKalle Valo 
3762d5c65159SKalle Valo 	kfree(tb);
3763d5c65159SKalle Valo 	return 0;
3764d5c65159SKalle Valo }
3765d5c65159SKalle Valo 
3766d5c65159SKalle Valo static int freq_to_idx(struct ath11k *ar, int freq)
3767d5c65159SKalle Valo {
3768d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
3769d5c65159SKalle Valo 	int band, ch, idx = 0;
3770d5c65159SKalle Valo 
3771d5c65159SKalle Valo 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
3772d5c65159SKalle Valo 		sband = ar->hw->wiphy->bands[band];
3773d5c65159SKalle Valo 		if (!sband)
3774d5c65159SKalle Valo 			continue;
3775d5c65159SKalle Valo 
3776d5c65159SKalle Valo 		for (ch = 0; ch < sband->n_channels; ch++, idx++)
3777d5c65159SKalle Valo 			if (sband->channels[ch].center_freq == freq)
3778d5c65159SKalle Valo 				goto exit;
3779d5c65159SKalle Valo 	}
3780d5c65159SKalle Valo 
3781d5c65159SKalle Valo exit:
3782d5c65159SKalle Valo 	return idx;
3783d5c65159SKalle Valo }
3784d5c65159SKalle Valo 
3785d5c65159SKalle Valo static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
3786d5c65159SKalle Valo 				    u32 len, struct wmi_chan_info_event *ch_info_ev)
3787d5c65159SKalle Valo {
3788d5c65159SKalle Valo 	const void **tb;
3789d5c65159SKalle Valo 	const struct wmi_chan_info_event *ev;
3790d5c65159SKalle Valo 	int ret;
3791d5c65159SKalle Valo 
3792d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
3793d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3794d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3795d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3796d5c65159SKalle Valo 		return ret;
3797d5c65159SKalle Valo 	}
3798d5c65159SKalle Valo 
3799d5c65159SKalle Valo 	ev = tb[WMI_TAG_CHAN_INFO_EVENT];
3800d5c65159SKalle Valo 	if (!ev) {
3801d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch chan info ev");
3802d5c65159SKalle Valo 		kfree(tb);
3803d5c65159SKalle Valo 		return -EPROTO;
3804d5c65159SKalle Valo 	}
3805d5c65159SKalle Valo 
3806d5c65159SKalle Valo 	ch_info_ev->err_code = ev->err_code;
3807d5c65159SKalle Valo 	ch_info_ev->freq = ev->freq;
3808d5c65159SKalle Valo 	ch_info_ev->cmd_flags = ev->cmd_flags;
3809d5c65159SKalle Valo 	ch_info_ev->noise_floor = ev->noise_floor;
3810d5c65159SKalle Valo 	ch_info_ev->rx_clear_count = ev->rx_clear_count;
3811d5c65159SKalle Valo 	ch_info_ev->cycle_count = ev->cycle_count;
3812d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
3813d5c65159SKalle Valo 	ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
3814d5c65159SKalle Valo 	ch_info_ev->rx_frame_count = ev->rx_frame_count;
3815d5c65159SKalle Valo 	ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
3816d5c65159SKalle Valo 	ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
3817d5c65159SKalle Valo 	ch_info_ev->vdev_id = ev->vdev_id;
3818d5c65159SKalle Valo 
3819d5c65159SKalle Valo 	kfree(tb);
3820d5c65159SKalle Valo 	return 0;
3821d5c65159SKalle Valo }
3822d5c65159SKalle Valo 
3823d5c65159SKalle Valo static int
3824d5c65159SKalle Valo ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
3825d5c65159SKalle Valo 				  struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
3826d5c65159SKalle Valo {
3827d5c65159SKalle Valo 	const void **tb;
3828d5c65159SKalle Valo 	const struct wmi_pdev_bss_chan_info_event *ev;
3829d5c65159SKalle Valo 	int ret;
3830d5c65159SKalle Valo 
3831d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3832d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3833d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3834d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3835d5c65159SKalle Valo 		return ret;
3836d5c65159SKalle Valo 	}
3837d5c65159SKalle Valo 
3838d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
3839d5c65159SKalle Valo 	if (!ev) {
3840d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
3841d5c65159SKalle Valo 		kfree(tb);
3842d5c65159SKalle Valo 		return -EPROTO;
3843d5c65159SKalle Valo 	}
3844d5c65159SKalle Valo 
3845d5c65159SKalle Valo 	bss_ch_info_ev->pdev_id = ev->pdev_id;
3846d5c65159SKalle Valo 	bss_ch_info_ev->freq = ev->freq;
3847d5c65159SKalle Valo 	bss_ch_info_ev->noise_floor = ev->noise_floor;
3848d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
3849d5c65159SKalle Valo 	bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
3850d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
3851d5c65159SKalle Valo 	bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
3852d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
3853d5c65159SKalle Valo 	bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
3854d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
3855d5c65159SKalle Valo 	bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
3856d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
3857d5c65159SKalle Valo 	bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
3858d5c65159SKalle Valo 
3859d5c65159SKalle Valo 	kfree(tb);
3860d5c65159SKalle Valo 	return 0;
3861d5c65159SKalle Valo }
3862d5c65159SKalle Valo 
3863d5c65159SKalle Valo static int
3864d5c65159SKalle Valo ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
3865d5c65159SKalle Valo 				      struct wmi_vdev_install_key_complete_arg *arg)
3866d5c65159SKalle Valo {
3867d5c65159SKalle Valo 	const void **tb;
3868d5c65159SKalle Valo 	const struct wmi_vdev_install_key_compl_event *ev;
3869d5c65159SKalle Valo 	int ret;
3870d5c65159SKalle Valo 
3871d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3872d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3873d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3874d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3875d5c65159SKalle Valo 		return ret;
3876d5c65159SKalle Valo 	}
3877d5c65159SKalle Valo 
3878d5c65159SKalle Valo 	ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
3879d5c65159SKalle Valo 	if (!ev) {
3880d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch vdev install key compl ev");
3881d5c65159SKalle Valo 		kfree(tb);
3882d5c65159SKalle Valo 		return -EPROTO;
3883d5c65159SKalle Valo 	}
3884d5c65159SKalle Valo 
3885d5c65159SKalle Valo 	arg->vdev_id = ev->vdev_id;
3886d5c65159SKalle Valo 	arg->macaddr = ev->peer_macaddr.addr;
3887d5c65159SKalle Valo 	arg->key_idx = ev->key_idx;
3888d5c65159SKalle Valo 	arg->key_flags = ev->key_flags;
3889d5c65159SKalle Valo 	arg->status = ev->status;
3890d5c65159SKalle Valo 
3891d5c65159SKalle Valo 	kfree(tb);
3892d5c65159SKalle Valo 	return 0;
3893d5c65159SKalle Valo }
3894d5c65159SKalle Valo 
3895d5c65159SKalle Valo static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
3896d5c65159SKalle Valo 					  struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
3897d5c65159SKalle Valo {
3898d5c65159SKalle Valo 	const void **tb;
3899d5c65159SKalle Valo 	const struct wmi_peer_assoc_conf_event *ev;
3900d5c65159SKalle Valo 	int ret;
3901d5c65159SKalle Valo 
3902d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3903d5c65159SKalle Valo 	if (IS_ERR(tb)) {
3904d5c65159SKalle Valo 		ret = PTR_ERR(tb);
3905d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3906d5c65159SKalle Valo 		return ret;
3907d5c65159SKalle Valo 	}
3908d5c65159SKalle Valo 
3909d5c65159SKalle Valo 	ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
3910d5c65159SKalle Valo 	if (!ev) {
3911d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch peer assoc conf ev");
3912d5c65159SKalle Valo 		kfree(tb);
3913d5c65159SKalle Valo 		return -EPROTO;
3914d5c65159SKalle Valo 	}
3915d5c65159SKalle Valo 
3916d5c65159SKalle Valo 	peer_assoc_conf->vdev_id = ev->vdev_id;
3917d5c65159SKalle Valo 	peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
3918d5c65159SKalle Valo 
3919d5c65159SKalle Valo 	kfree(tb);
3920d5c65159SKalle Valo 	return 0;
3921d5c65159SKalle Valo }
3922d5c65159SKalle Valo 
3923d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
3924d5c65159SKalle Valo 					    struct ath11k_fw_stats_pdev *dst)
3925d5c65159SKalle Valo {
3926d5c65159SKalle Valo 	dst->ch_noise_floor = src->chan_nf;
3927d5c65159SKalle Valo 	dst->tx_frame_count = src->tx_frame_count;
3928d5c65159SKalle Valo 	dst->rx_frame_count = src->rx_frame_count;
3929d5c65159SKalle Valo 	dst->rx_clear_count = src->rx_clear_count;
3930d5c65159SKalle Valo 	dst->cycle_count = src->cycle_count;
3931d5c65159SKalle Valo 	dst->phy_err_count = src->phy_err_count;
3932d5c65159SKalle Valo 	dst->chan_tx_power = src->chan_tx_pwr;
3933d5c65159SKalle Valo }
3934d5c65159SKalle Valo 
3935d5c65159SKalle Valo static void
3936d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
3937d5c65159SKalle Valo 			      struct ath11k_fw_stats_pdev *dst)
3938d5c65159SKalle Valo {
3939d5c65159SKalle Valo 	dst->comp_queued = src->comp_queued;
3940d5c65159SKalle Valo 	dst->comp_delivered = src->comp_delivered;
3941d5c65159SKalle Valo 	dst->msdu_enqued = src->msdu_enqued;
3942d5c65159SKalle Valo 	dst->mpdu_enqued = src->mpdu_enqued;
3943d5c65159SKalle Valo 	dst->wmm_drop = src->wmm_drop;
3944d5c65159SKalle Valo 	dst->local_enqued = src->local_enqued;
3945d5c65159SKalle Valo 	dst->local_freed = src->local_freed;
3946d5c65159SKalle Valo 	dst->hw_queued = src->hw_queued;
3947d5c65159SKalle Valo 	dst->hw_reaped = src->hw_reaped;
3948d5c65159SKalle Valo 	dst->underrun = src->underrun;
3949d5c65159SKalle Valo 	dst->tx_abort = src->tx_abort;
3950d5c65159SKalle Valo 	dst->mpdus_requed = src->mpdus_requed;
3951d5c65159SKalle Valo 	dst->tx_ko = src->tx_ko;
3952d5c65159SKalle Valo 	dst->data_rc = src->data_rc;
3953d5c65159SKalle Valo 	dst->self_triggers = src->self_triggers;
3954d5c65159SKalle Valo 	dst->sw_retry_failure = src->sw_retry_failure;
3955d5c65159SKalle Valo 	dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
3956d5c65159SKalle Valo 	dst->pdev_cont_xretry = src->pdev_cont_xretry;
3957d5c65159SKalle Valo 	dst->pdev_tx_timeout = src->pdev_tx_timeout;
3958d5c65159SKalle Valo 	dst->pdev_resets = src->pdev_resets;
3959d5c65159SKalle Valo 	dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
3960d5c65159SKalle Valo 	dst->phy_underrun = src->phy_underrun;
3961d5c65159SKalle Valo 	dst->txop_ovf = src->txop_ovf;
3962d5c65159SKalle Valo }
3963d5c65159SKalle Valo 
3964d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
3965d5c65159SKalle Valo 					  struct ath11k_fw_stats_pdev *dst)
3966d5c65159SKalle Valo {
3967d5c65159SKalle Valo 	dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
3968d5c65159SKalle Valo 	dst->status_rcvd = src->status_rcvd;
3969d5c65159SKalle Valo 	dst->r0_frags = src->r0_frags;
3970d5c65159SKalle Valo 	dst->r1_frags = src->r1_frags;
3971d5c65159SKalle Valo 	dst->r2_frags = src->r2_frags;
3972d5c65159SKalle Valo 	dst->r3_frags = src->r3_frags;
3973d5c65159SKalle Valo 	dst->htt_msdus = src->htt_msdus;
3974d5c65159SKalle Valo 	dst->htt_mpdus = src->htt_mpdus;
3975d5c65159SKalle Valo 	dst->loc_msdus = src->loc_msdus;
3976d5c65159SKalle Valo 	dst->loc_mpdus = src->loc_mpdus;
3977d5c65159SKalle Valo 	dst->oversize_amsdu = src->oversize_amsdu;
3978d5c65159SKalle Valo 	dst->phy_errs = src->phy_errs;
3979d5c65159SKalle Valo 	dst->phy_err_drop = src->phy_err_drop;
3980d5c65159SKalle Valo 	dst->mpdu_errs = src->mpdu_errs;
3981d5c65159SKalle Valo }
3982d5c65159SKalle Valo 
3983d5c65159SKalle Valo static void
3984d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
3985d5c65159SKalle Valo 			   struct ath11k_fw_stats_vdev *dst)
3986d5c65159SKalle Valo {
3987d5c65159SKalle Valo 	int i;
3988d5c65159SKalle Valo 
3989d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
3990d5c65159SKalle Valo 	dst->beacon_snr = src->beacon_snr;
3991d5c65159SKalle Valo 	dst->data_snr = src->data_snr;
3992d5c65159SKalle Valo 	dst->num_rx_frames = src->num_rx_frames;
3993d5c65159SKalle Valo 	dst->num_rts_fail = src->num_rts_fail;
3994d5c65159SKalle Valo 	dst->num_rts_success = src->num_rts_success;
3995d5c65159SKalle Valo 	dst->num_rx_err = src->num_rx_err;
3996d5c65159SKalle Valo 	dst->num_rx_discard = src->num_rx_discard;
3997d5c65159SKalle Valo 	dst->num_tx_not_acked = src->num_tx_not_acked;
3998d5c65159SKalle Valo 
3999d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
4000d5c65159SKalle Valo 		dst->num_tx_frames[i] = src->num_tx_frames[i];
4001d5c65159SKalle Valo 
4002d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
4003d5c65159SKalle Valo 		dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
4004d5c65159SKalle Valo 
4005d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
4006d5c65159SKalle Valo 		dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
4007d5c65159SKalle Valo 
4008d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
4009d5c65159SKalle Valo 		dst->tx_rate_history[i] = src->tx_rate_history[i];
4010d5c65159SKalle Valo 
4011d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
4012d5c65159SKalle Valo 		dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
4013d5c65159SKalle Valo }
4014d5c65159SKalle Valo 
4015d5c65159SKalle Valo static void
4016d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
4017d5c65159SKalle Valo 			  struct ath11k_fw_stats_bcn *dst)
4018d5c65159SKalle Valo {
4019d5c65159SKalle Valo 	dst->vdev_id = src->vdev_id;
4020d5c65159SKalle Valo 	dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
4021d5c65159SKalle Valo 	dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
4022d5c65159SKalle Valo }
4023d5c65159SKalle Valo 
4024d5c65159SKalle Valo int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
4025d5c65159SKalle Valo 			     struct ath11k_fw_stats *stats)
4026d5c65159SKalle Valo {
4027d5c65159SKalle Valo 	const void **tb;
4028d5c65159SKalle Valo 	const struct wmi_stats_event *ev;
4029d5c65159SKalle Valo 	const void *data;
4030d5c65159SKalle Valo 	int i, ret;
4031d5c65159SKalle Valo 	u32 len = skb->len;
4032d5c65159SKalle Valo 
4033d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, len, GFP_ATOMIC);
4034d5c65159SKalle Valo 	if (IS_ERR(tb)) {
4035d5c65159SKalle Valo 		ret = PTR_ERR(tb);
4036d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4037d5c65159SKalle Valo 		return ret;
4038d5c65159SKalle Valo 	}
4039d5c65159SKalle Valo 
4040d5c65159SKalle Valo 	ev = tb[WMI_TAG_STATS_EVENT];
4041d5c65159SKalle Valo 	data = tb[WMI_TAG_ARRAY_BYTE];
4042d5c65159SKalle Valo 	if (!ev || !data) {
4043d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch update stats ev");
4044d5c65159SKalle Valo 		kfree(tb);
4045d5c65159SKalle Valo 		return -EPROTO;
4046d5c65159SKalle Valo 	}
4047d5c65159SKalle Valo 
4048d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
4049d5c65159SKalle Valo 		   "wmi stats update ev pdev_id %d pdev %i vdev %i bcn %i\n",
4050d5c65159SKalle Valo 		   ev->pdev_id,
4051d5c65159SKalle Valo 		   ev->num_pdev_stats, ev->num_vdev_stats,
4052d5c65159SKalle Valo 		   ev->num_bcn_stats);
4053d5c65159SKalle Valo 
4054d5c65159SKalle Valo 	stats->pdev_id = ev->pdev_id;
4055d5c65159SKalle Valo 	stats->stats_id = 0;
4056d5c65159SKalle Valo 
4057d5c65159SKalle Valo 	for (i = 0; i < ev->num_pdev_stats; i++) {
4058d5c65159SKalle Valo 		const struct wmi_pdev_stats *src;
4059d5c65159SKalle Valo 		struct ath11k_fw_stats_pdev *dst;
4060d5c65159SKalle Valo 
4061d5c65159SKalle Valo 		src = data;
4062d5c65159SKalle Valo 		if (len < sizeof(*src)) {
4063d5c65159SKalle Valo 			kfree(tb);
4064d5c65159SKalle Valo 			return -EPROTO;
4065d5c65159SKalle Valo 		}
4066d5c65159SKalle Valo 
4067d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_PDEV_STAT;
4068d5c65159SKalle Valo 
4069d5c65159SKalle Valo 		data += sizeof(*src);
4070d5c65159SKalle Valo 		len -= sizeof(*src);
4071d5c65159SKalle Valo 
4072d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
4073d5c65159SKalle Valo 		if (!dst)
4074d5c65159SKalle Valo 			continue;
4075d5c65159SKalle Valo 
4076d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
4077d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
4078d5c65159SKalle Valo 		ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
4079d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->pdevs);
4080d5c65159SKalle Valo 	}
4081d5c65159SKalle Valo 
4082d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdev_stats; i++) {
4083d5c65159SKalle Valo 		const struct wmi_vdev_stats *src;
4084d5c65159SKalle Valo 		struct ath11k_fw_stats_vdev *dst;
4085d5c65159SKalle Valo 
4086d5c65159SKalle Valo 		src = data;
4087d5c65159SKalle Valo 		if (len < sizeof(*src)) {
4088d5c65159SKalle Valo 			kfree(tb);
4089d5c65159SKalle Valo 			return -EPROTO;
4090d5c65159SKalle Valo 		}
4091d5c65159SKalle Valo 
4092d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_VDEV_STAT;
4093d5c65159SKalle Valo 
4094d5c65159SKalle Valo 		data += sizeof(*src);
4095d5c65159SKalle Valo 		len -= sizeof(*src);
4096d5c65159SKalle Valo 
4097d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
4098d5c65159SKalle Valo 		if (!dst)
4099d5c65159SKalle Valo 			continue;
4100d5c65159SKalle Valo 
4101d5c65159SKalle Valo 		ath11k_wmi_pull_vdev_stats(src, dst);
4102d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->vdevs);
4103d5c65159SKalle Valo 	}
4104d5c65159SKalle Valo 
4105d5c65159SKalle Valo 	for (i = 0; i < ev->num_bcn_stats; i++) {
4106d5c65159SKalle Valo 		const struct wmi_bcn_stats *src;
4107d5c65159SKalle Valo 		struct ath11k_fw_stats_bcn *dst;
4108d5c65159SKalle Valo 
4109d5c65159SKalle Valo 		src = data;
4110d5c65159SKalle Valo 		if (len < sizeof(*src)) {
4111d5c65159SKalle Valo 			kfree(tb);
4112d5c65159SKalle Valo 			return -EPROTO;
4113d5c65159SKalle Valo 		}
4114d5c65159SKalle Valo 
4115d5c65159SKalle Valo 		stats->stats_id = WMI_REQUEST_BCN_STAT;
4116d5c65159SKalle Valo 
4117d5c65159SKalle Valo 		data += sizeof(*src);
4118d5c65159SKalle Valo 		len -= sizeof(*src);
4119d5c65159SKalle Valo 
4120d5c65159SKalle Valo 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
4121d5c65159SKalle Valo 		if (!dst)
4122d5c65159SKalle Valo 			continue;
4123d5c65159SKalle Valo 
4124d5c65159SKalle Valo 		ath11k_wmi_pull_bcn_stats(src, dst);
4125d5c65159SKalle Valo 		list_add_tail(&dst->list, &stats->bcn);
4126d5c65159SKalle Valo 	}
4127d5c65159SKalle Valo 
4128d5c65159SKalle Valo 	kfree(tb);
4129d5c65159SKalle Valo 	return 0;
4130d5c65159SKalle Valo }
4131d5c65159SKalle Valo 
4132d5c65159SKalle Valo size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head)
4133d5c65159SKalle Valo {
4134d5c65159SKalle Valo 	struct ath11k_fw_stats_vdev *i;
4135d5c65159SKalle Valo 	size_t num = 0;
4136d5c65159SKalle Valo 
4137d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
4138d5c65159SKalle Valo 		++num;
4139d5c65159SKalle Valo 
4140d5c65159SKalle Valo 	return num;
4141d5c65159SKalle Valo }
4142d5c65159SKalle Valo 
4143d5c65159SKalle Valo static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head)
4144d5c65159SKalle Valo {
4145d5c65159SKalle Valo 	struct ath11k_fw_stats_bcn *i;
4146d5c65159SKalle Valo 	size_t num = 0;
4147d5c65159SKalle Valo 
4148d5c65159SKalle Valo 	list_for_each_entry(i, head, list)
4149d5c65159SKalle Valo 		++num;
4150d5c65159SKalle Valo 
4151d5c65159SKalle Valo 	return num;
4152d5c65159SKalle Valo }
4153d5c65159SKalle Valo 
4154d5c65159SKalle Valo static void
4155d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
4156d5c65159SKalle Valo 				   char *buf, u32 *length)
4157d5c65159SKalle Valo {
4158d5c65159SKalle Valo 	u32 len = *length;
4159d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
4160d5c65159SKalle Valo 
4161d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
4162d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
4163d5c65159SKalle Valo 			"ath11k PDEV stats");
4164d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
4165d5c65159SKalle Valo 			"=================");
4166d5c65159SKalle Valo 
4167d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4168d5c65159SKalle Valo 			"Channel noise floor", pdev->ch_noise_floor);
4169d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4170d5c65159SKalle Valo 			"Channel TX power", pdev->chan_tx_power);
4171d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4172d5c65159SKalle Valo 			"TX frame count", pdev->tx_frame_count);
4173d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4174d5c65159SKalle Valo 			"RX frame count", pdev->rx_frame_count);
4175d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4176d5c65159SKalle Valo 			"RX clear count", pdev->rx_clear_count);
4177d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4178d5c65159SKalle Valo 			"Cycle count", pdev->cycle_count);
4179d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4180d5c65159SKalle Valo 			"PHY error count", pdev->phy_err_count);
4181d5c65159SKalle Valo 
4182d5c65159SKalle Valo 	*length = len;
4183d5c65159SKalle Valo }
4184d5c65159SKalle Valo 
4185d5c65159SKalle Valo static void
4186d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
4187d5c65159SKalle Valo 				 char *buf, u32 *length)
4188d5c65159SKalle Valo {
4189d5c65159SKalle Valo 	u32 len = *length;
4190d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
4191d5c65159SKalle Valo 
4192d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
4193d5c65159SKalle Valo 			 "ath11k PDEV TX stats");
4194d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
4195d5c65159SKalle Valo 			 "====================");
4196d5c65159SKalle Valo 
4197d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4198d5c65159SKalle Valo 			 "HTT cookies queued", pdev->comp_queued);
4199d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4200d5c65159SKalle Valo 			 "HTT cookies disp.", pdev->comp_delivered);
4201d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4202d5c65159SKalle Valo 			 "MSDU queued", pdev->msdu_enqued);
4203d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4204d5c65159SKalle Valo 			 "MPDU queued", pdev->mpdu_enqued);
4205d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4206d5c65159SKalle Valo 			 "MSDUs dropped", pdev->wmm_drop);
4207d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4208d5c65159SKalle Valo 			 "Local enqued", pdev->local_enqued);
4209d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4210d5c65159SKalle Valo 			 "Local freed", pdev->local_freed);
4211d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4212d5c65159SKalle Valo 			 "HW queued", pdev->hw_queued);
4213d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4214d5c65159SKalle Valo 			 "PPDUs reaped", pdev->hw_reaped);
4215d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4216d5c65159SKalle Valo 			 "Num underruns", pdev->underrun);
4217d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4218d5c65159SKalle Valo 			 "PPDUs cleaned", pdev->tx_abort);
4219d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4220d5c65159SKalle Valo 			 "MPDUs requed", pdev->mpdus_requed);
4221d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4222d5c65159SKalle Valo 			 "Excessive retries", pdev->tx_ko);
4223d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4224d5c65159SKalle Valo 			 "HW rate", pdev->data_rc);
4225d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4226d5c65159SKalle Valo 			 "Sched self triggers", pdev->self_triggers);
4227d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4228d5c65159SKalle Valo 			 "Dropped due to SW retries",
4229d5c65159SKalle Valo 			 pdev->sw_retry_failure);
4230d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4231d5c65159SKalle Valo 			 "Illegal rate phy errors",
4232d5c65159SKalle Valo 			 pdev->illgl_rate_phy_err);
4233d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4234d5c65159SKalle Valo 			 "PDEV continuous xretry", pdev->pdev_cont_xretry);
4235d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4236d5c65159SKalle Valo 			 "TX timeout", pdev->pdev_tx_timeout);
4237d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4238d5c65159SKalle Valo 			 "PDEV resets", pdev->pdev_resets);
4239d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4240d5c65159SKalle Valo 			 "Stateless TIDs alloc failures",
4241d5c65159SKalle Valo 			 pdev->stateless_tid_alloc_failure);
4242d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4243d5c65159SKalle Valo 			 "PHY underrun", pdev->phy_underrun);
4244d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
4245d5c65159SKalle Valo 			 "MPDU is more than txop limit", pdev->txop_ovf);
4246d5c65159SKalle Valo 	*length = len;
4247d5c65159SKalle Valo }
4248d5c65159SKalle Valo 
4249d5c65159SKalle Valo static void
4250d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
4251d5c65159SKalle Valo 				 char *buf, u32 *length)
4252d5c65159SKalle Valo {
4253d5c65159SKalle Valo 	u32 len = *length;
4254d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
4255d5c65159SKalle Valo 
4256d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
4257d5c65159SKalle Valo 			 "ath11k PDEV RX stats");
4258d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
4259d5c65159SKalle Valo 			 "====================");
4260d5c65159SKalle Valo 
4261d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4262d5c65159SKalle Valo 			 "Mid PPDU route change",
4263d5c65159SKalle Valo 			 pdev->mid_ppdu_route_change);
4264d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4265d5c65159SKalle Valo 			 "Tot. number of statuses", pdev->status_rcvd);
4266d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4267d5c65159SKalle Valo 			 "Extra frags on rings 0", pdev->r0_frags);
4268d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4269d5c65159SKalle Valo 			 "Extra frags on rings 1", pdev->r1_frags);
4270d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4271d5c65159SKalle Valo 			 "Extra frags on rings 2", pdev->r2_frags);
4272d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4273d5c65159SKalle Valo 			 "Extra frags on rings 3", pdev->r3_frags);
4274d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4275d5c65159SKalle Valo 			 "MSDUs delivered to HTT", pdev->htt_msdus);
4276d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4277d5c65159SKalle Valo 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
4278d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4279d5c65159SKalle Valo 			 "MSDUs delivered to stack", pdev->loc_msdus);
4280d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4281d5c65159SKalle Valo 			 "MPDUs delivered to stack", pdev->loc_mpdus);
4282d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4283d5c65159SKalle Valo 			 "Oversized AMSUs", pdev->oversize_amsdu);
4284d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4285d5c65159SKalle Valo 			 "PHY errors", pdev->phy_errs);
4286d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4287d5c65159SKalle Valo 			 "PHY errors drops", pdev->phy_err_drop);
4288d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
4289d5c65159SKalle Valo 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
4290d5c65159SKalle Valo 	*length = len;
4291d5c65159SKalle Valo }
4292d5c65159SKalle Valo 
4293d5c65159SKalle Valo static void
4294d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
4295d5c65159SKalle Valo 			      const struct ath11k_fw_stats_vdev *vdev,
4296d5c65159SKalle Valo 			      char *buf, u32 *length)
4297d5c65159SKalle Valo {
4298d5c65159SKalle Valo 	u32 len = *length;
4299d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
4300d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
4301d5c65159SKalle Valo 	u8 *vif_macaddr;
4302d5c65159SKalle Valo 	int i;
4303d5c65159SKalle Valo 
4304d5c65159SKalle Valo 	/* VDEV stats has all the active VDEVs of other PDEVs as well,
4305d5c65159SKalle Valo 	 * ignoring those not part of requested PDEV
4306d5c65159SKalle Valo 	 */
4307d5c65159SKalle Valo 	if (!arvif)
4308d5c65159SKalle Valo 		return;
4309d5c65159SKalle Valo 
4310d5c65159SKalle Valo 	vif_macaddr = arvif->vif->addr;
4311d5c65159SKalle Valo 
4312d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4313d5c65159SKalle Valo 			 "VDEV ID", vdev->vdev_id);
4314d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
4315d5c65159SKalle Valo 			 "VDEV MAC address", vif_macaddr);
4316d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4317d5c65159SKalle Valo 			 "beacon snr", vdev->beacon_snr);
4318d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4319d5c65159SKalle Valo 			 "data snr", vdev->data_snr);
4320d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4321d5c65159SKalle Valo 			 "num rx frames", vdev->num_rx_frames);
4322d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4323d5c65159SKalle Valo 			 "num rts fail", vdev->num_rts_fail);
4324d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4325d5c65159SKalle Valo 			 "num rts success", vdev->num_rts_success);
4326d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4327d5c65159SKalle Valo 			 "num rx err", vdev->num_rx_err);
4328d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4329d5c65159SKalle Valo 			 "num rx discard", vdev->num_rx_discard);
4330d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4331d5c65159SKalle Valo 			 "num tx not acked", vdev->num_tx_not_acked);
4332d5c65159SKalle Valo 
4333d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
4334d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
4335d5c65159SKalle Valo 				"%25s [%02d] %u\n",
4336d5c65159SKalle Valo 				"num tx frames", i,
4337d5c65159SKalle Valo 				vdev->num_tx_frames[i]);
4338d5c65159SKalle Valo 
4339d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
4340d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
4341d5c65159SKalle Valo 				"%25s [%02d] %u\n",
4342d5c65159SKalle Valo 				"num tx frames retries", i,
4343d5c65159SKalle Valo 				vdev->num_tx_frames_retries[i]);
4344d5c65159SKalle Valo 
4345d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
4346d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
4347d5c65159SKalle Valo 				"%25s [%02d] %u\n",
4348d5c65159SKalle Valo 				"num tx frames failures", i,
4349d5c65159SKalle Valo 				vdev->num_tx_frames_failures[i]);
4350d5c65159SKalle Valo 
4351d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
4352d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
4353d5c65159SKalle Valo 				"%25s [%02d] 0x%08x\n",
4354d5c65159SKalle Valo 				"tx rate history", i,
4355d5c65159SKalle Valo 				vdev->tx_rate_history[i]);
4356d5c65159SKalle Valo 
4357d5c65159SKalle Valo 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
4358d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len,
4359d5c65159SKalle Valo 				"%25s [%02d] %u\n",
4360d5c65159SKalle Valo 				"beacon rssi history", i,
4361d5c65159SKalle Valo 				vdev->beacon_rssi_history[i]);
4362d5c65159SKalle Valo 
4363d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
4364d5c65159SKalle Valo 	*length = len;
4365d5c65159SKalle Valo }
4366d5c65159SKalle Valo 
4367d5c65159SKalle Valo static void
4368d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
4369d5c65159SKalle Valo 			     const struct ath11k_fw_stats_bcn *bcn,
4370d5c65159SKalle Valo 			     char *buf, u32 *length)
4371d5c65159SKalle Valo {
4372d5c65159SKalle Valo 	u32 len = *length;
4373d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
4374d5c65159SKalle Valo 	struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
4375d5c65159SKalle Valo 	u8 *vdev_macaddr;
4376d5c65159SKalle Valo 
4377d5c65159SKalle Valo 	if (!arvif) {
4378d5c65159SKalle Valo 		ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
4379d5c65159SKalle Valo 			    bcn->vdev_id);
4380d5c65159SKalle Valo 		return;
4381d5c65159SKalle Valo 	}
4382d5c65159SKalle Valo 
4383d5c65159SKalle Valo 	vdev_macaddr = arvif->vif->addr;
4384d5c65159SKalle Valo 
4385d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4386d5c65159SKalle Valo 			 "VDEV ID", bcn->vdev_id);
4387d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
4388d5c65159SKalle Valo 			 "VDEV MAC address", vdev_macaddr);
4389d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
4390d5c65159SKalle Valo 			 "================");
4391d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4392d5c65159SKalle Valo 			 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
4393d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
4394d5c65159SKalle Valo 			 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
4395d5c65159SKalle Valo 
4396d5c65159SKalle Valo 	len += scnprintf(buf + len, buf_len - len, "\n");
4397d5c65159SKalle Valo 	*length = len;
4398d5c65159SKalle Valo }
4399d5c65159SKalle Valo 
4400d5c65159SKalle Valo void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
4401d5c65159SKalle Valo 			      struct ath11k_fw_stats *fw_stats,
4402d5c65159SKalle Valo 			      u32 stats_id, char *buf)
4403d5c65159SKalle Valo {
4404d5c65159SKalle Valo 	u32 len = 0;
4405d5c65159SKalle Valo 	u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
4406d5c65159SKalle Valo 	const struct ath11k_fw_stats_pdev *pdev;
4407d5c65159SKalle Valo 	const struct ath11k_fw_stats_vdev *vdev;
4408d5c65159SKalle Valo 	const struct ath11k_fw_stats_bcn *bcn;
4409d5c65159SKalle Valo 	size_t num_bcn;
4410d5c65159SKalle Valo 
4411d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
4412d5c65159SKalle Valo 
4413d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_PDEV_STAT) {
4414d5c65159SKalle Valo 		pdev = list_first_entry_or_null(&fw_stats->pdevs,
4415d5c65159SKalle Valo 						struct ath11k_fw_stats_pdev, list);
4416d5c65159SKalle Valo 		if (!pdev) {
4417d5c65159SKalle Valo 			ath11k_warn(ar->ab, "failed to get pdev stats\n");
4418d5c65159SKalle Valo 			goto unlock;
4419d5c65159SKalle Valo 		}
4420d5c65159SKalle Valo 
4421d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
4422d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
4423d5c65159SKalle Valo 		ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
4424d5c65159SKalle Valo 	}
4425d5c65159SKalle Valo 
4426d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_VDEV_STAT) {
4427d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
4428d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n",
4429d5c65159SKalle Valo 				 "ath11k VDEV stats");
4430d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
4431d5c65159SKalle Valo 				 "=================");
4432d5c65159SKalle Valo 
4433d5c65159SKalle Valo 		list_for_each_entry(vdev, &fw_stats->vdevs, list)
4434d5c65159SKalle Valo 			ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
4435d5c65159SKalle Valo 	}
4436d5c65159SKalle Valo 
4437d5c65159SKalle Valo 	if (stats_id == WMI_REQUEST_BCN_STAT) {
4438d5c65159SKalle Valo 		num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn);
4439d5c65159SKalle Valo 
4440d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "\n");
4441d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
4442d5c65159SKalle Valo 				 "ath11k Beacon stats", num_bcn);
4443d5c65159SKalle Valo 		len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
4444d5c65159SKalle Valo 				 "===================");
4445d5c65159SKalle Valo 
4446d5c65159SKalle Valo 		list_for_each_entry(bcn, &fw_stats->bcn, list)
4447d5c65159SKalle Valo 			ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
4448d5c65159SKalle Valo 	}
4449d5c65159SKalle Valo 
4450d5c65159SKalle Valo unlock:
4451d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
4452d5c65159SKalle Valo 
4453d5c65159SKalle Valo 	if (len >= buf_len)
4454d5c65159SKalle Valo 		buf[len - 1] = 0;
4455d5c65159SKalle Valo 	else
4456d5c65159SKalle Valo 		buf[len] = 0;
4457d5c65159SKalle Valo }
4458d5c65159SKalle Valo 
4459d5c65159SKalle Valo static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
4460d5c65159SKalle Valo {
4461d5c65159SKalle Valo 	/* try to send pending beacons first. they take priority */
4462d5c65159SKalle Valo 	wake_up(&ab->wmi_sc.tx_credits_wq);
4463d5c65159SKalle Valo }
4464d5c65159SKalle Valo 
4465d5c65159SKalle Valo static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
4466d5c65159SKalle Valo 				       struct sk_buff *skb)
4467d5c65159SKalle Valo {
4468d5c65159SKalle Valo 	dev_kfree_skb(skb);
4469d5c65159SKalle Valo }
4470d5c65159SKalle Valo 
4471d5c65159SKalle Valo static bool ath11k_reg_is_world_alpha(char *alpha)
4472d5c65159SKalle Valo {
4473d5c65159SKalle Valo 	return alpha[0] == '0' && alpha[1] == '0';
4474d5c65159SKalle Valo }
4475d5c65159SKalle Valo 
4476d5c65159SKalle Valo static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb)
4477d5c65159SKalle Valo {
4478d5c65159SKalle Valo 	struct cur_regulatory_info *reg_info = NULL;
4479d5c65159SKalle Valo 	struct ieee80211_regdomain *regd = NULL;
4480d5c65159SKalle Valo 	bool intersect = false;
4481d5c65159SKalle Valo 	int ret = 0, pdev_idx;
4482d5c65159SKalle Valo 	struct ath11k *ar;
4483d5c65159SKalle Valo 
4484d5c65159SKalle Valo 	reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
4485d5c65159SKalle Valo 	if (!reg_info) {
4486d5c65159SKalle Valo 		ret = -ENOMEM;
4487d5c65159SKalle Valo 		goto fallback;
4488d5c65159SKalle Valo 	}
4489d5c65159SKalle Valo 
4490d5c65159SKalle Valo 	ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
4491d5c65159SKalle Valo 	if (ret) {
4492d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract regulatory info from received event\n");
4493d5c65159SKalle Valo 		goto fallback;
4494d5c65159SKalle Valo 	}
4495d5c65159SKalle Valo 
4496d5c65159SKalle Valo 	if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
4497d5c65159SKalle Valo 		/* In case of failure to set the requested ctry,
4498d5c65159SKalle Valo 		 * fw retains the current regd. We print a failure info
4499d5c65159SKalle Valo 		 * and return from here.
4500d5c65159SKalle Valo 		 */
4501d5c65159SKalle Valo 		ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
4502d5c65159SKalle Valo 		goto mem_free;
4503d5c65159SKalle Valo 	}
4504d5c65159SKalle Valo 
4505d5c65159SKalle Valo 	pdev_idx = reg_info->phy_id;
4506d5c65159SKalle Valo 
4507d5c65159SKalle Valo 	if (pdev_idx >= ab->num_radios)
4508d5c65159SKalle Valo 		goto fallback;
4509d5c65159SKalle Valo 
4510d5c65159SKalle Valo 	/* Avoid multiple overwrites to default regd, during core
4511d5c65159SKalle Valo 	 * stop-start after mac registration.
4512d5c65159SKalle Valo 	 */
4513d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
4514d5c65159SKalle Valo 	    !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
4515d5c65159SKalle Valo 		    (char *)reg_info->alpha2, 2))
4516d5c65159SKalle Valo 		return 0;
4517d5c65159SKalle Valo 
4518d5c65159SKalle Valo 	/* Intersect new rules with default regd if a new country setting was
4519d5c65159SKalle Valo 	 * requested, i.e a default regd was already set during initialization
4520d5c65159SKalle Valo 	 * and the regd coming from this event has a valid country info.
4521d5c65159SKalle Valo 	 */
4522d5c65159SKalle Valo 	if (ab->default_regd[pdev_idx] &&
4523d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)
4524d5c65159SKalle Valo 		ab->default_regd[pdev_idx]->alpha2) &&
4525d5c65159SKalle Valo 	    !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
4526d5c65159SKalle Valo 		intersect = true;
4527d5c65159SKalle Valo 
4528d5c65159SKalle Valo 	regd = ath11k_reg_build_regd(ab, reg_info, intersect);
4529d5c65159SKalle Valo 	if (!regd) {
4530d5c65159SKalle Valo 		ath11k_warn(ab, "failed to build regd from reg_info\n");
4531d5c65159SKalle Valo 		goto fallback;
4532d5c65159SKalle Valo 	}
4533d5c65159SKalle Valo 
4534d5c65159SKalle Valo 	spin_lock(&ab->base_lock);
4535d5c65159SKalle Valo 	if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) {
4536d5c65159SKalle Valo 		/* Once mac is registered, ar is valid and all CC events from
4537d5c65159SKalle Valo 		 * fw is considered to be received due to user requests
4538d5c65159SKalle Valo 		 * currently.
4539d5c65159SKalle Valo 		 * Free previously built regd before assigning the newly
4540d5c65159SKalle Valo 		 * generated regd to ar. NULL pointer handling will be
4541d5c65159SKalle Valo 		 * taken care by kfree itself.
4542d5c65159SKalle Valo 		 */
4543d5c65159SKalle Valo 		ar = ab->pdevs[pdev_idx].ar;
4544d5c65159SKalle Valo 		kfree(ab->new_regd[pdev_idx]);
4545d5c65159SKalle Valo 		ab->new_regd[pdev_idx] = regd;
4546d5c65159SKalle Valo 		ieee80211_queue_work(ar->hw, &ar->regd_update_work);
4547d5c65159SKalle Valo 	} else {
4548d5c65159SKalle Valo 		/* Multiple events for the same *ar is not expected. But we
4549d5c65159SKalle Valo 		 * can still clear any previously stored default_regd if we
4550d5c65159SKalle Valo 		 * are receiving this event for the same radio by mistake.
4551d5c65159SKalle Valo 		 * NULL pointer handling will be taken care by kfree itself.
4552d5c65159SKalle Valo 		 */
4553d5c65159SKalle Valo 		kfree(ab->default_regd[pdev_idx]);
4554d5c65159SKalle Valo 		/* This regd would be applied during mac registration */
4555d5c65159SKalle Valo 		ab->default_regd[pdev_idx] = regd;
4556d5c65159SKalle Valo 	}
4557d5c65159SKalle Valo 	ab->dfs_region = reg_info->dfs_region;
4558d5c65159SKalle Valo 	spin_unlock(&ab->base_lock);
4559d5c65159SKalle Valo 
4560d5c65159SKalle Valo 	goto mem_free;
4561d5c65159SKalle Valo 
4562d5c65159SKalle Valo fallback:
4563d5c65159SKalle Valo 	/* Fallback to older reg (by sending previous country setting
4564d5c65159SKalle Valo 	 * again if fw has succeded and we failed to process here.
4565d5c65159SKalle Valo 	 * The Regdomain should be uniform across driver and fw. Since the
4566d5c65159SKalle Valo 	 * FW has processed the command and sent a success status, we expect
4567d5c65159SKalle Valo 	 * this function to succeed as well. If it doesn't, CTRY needs to be
4568d5c65159SKalle Valo 	 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
4569d5c65159SKalle Valo 	 */
4570d5c65159SKalle Valo 	/* TODO: This is rare, but still should also be handled */
4571d5c65159SKalle Valo 	WARN_ON(1);
4572d5c65159SKalle Valo mem_free:
4573d5c65159SKalle Valo 	if (reg_info) {
4574d5c65159SKalle Valo 		kfree(reg_info->reg_rules_2g_ptr);
4575d5c65159SKalle Valo 		kfree(reg_info->reg_rules_5g_ptr);
4576d5c65159SKalle Valo 		kfree(reg_info);
4577d5c65159SKalle Valo 	}
4578d5c65159SKalle Valo 	return ret;
4579d5c65159SKalle Valo }
4580d5c65159SKalle Valo 
4581d5c65159SKalle Valo static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
4582d5c65159SKalle Valo 				    const void *ptr, void *data)
4583d5c65159SKalle Valo {
4584d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse *rdy_parse = data;
4585d5c65159SKalle Valo 	struct wmi_ready_event *fixed_param;
4586d5c65159SKalle Valo 	struct wmi_mac_addr *addr_list;
4587d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
4588d5c65159SKalle Valo 	u32 num_mac_addr;
4589d5c65159SKalle Valo 	int i;
4590d5c65159SKalle Valo 
4591d5c65159SKalle Valo 	switch (tag) {
4592d5c65159SKalle Valo 	case WMI_TAG_READY_EVENT:
4593d5c65159SKalle Valo 		fixed_param = (struct wmi_ready_event *)ptr;
4594d5c65159SKalle Valo 		ab->wlan_init_status = fixed_param->status;
4595d5c65159SKalle Valo 		rdy_parse->num_extra_mac_addr = fixed_param->num_extra_mac_addr;
4596d5c65159SKalle Valo 
4597d5c65159SKalle Valo 		ether_addr_copy(ab->mac_addr, fixed_param->mac_addr.addr);
4598d5c65159SKalle Valo 		ab->wmi_ready = true;
4599d5c65159SKalle Valo 		break;
4600d5c65159SKalle Valo 	case WMI_TAG_ARRAY_FIXED_STRUCT:
4601d5c65159SKalle Valo 		addr_list = (struct wmi_mac_addr *)ptr;
4602d5c65159SKalle Valo 		num_mac_addr = rdy_parse->num_extra_mac_addr;
4603d5c65159SKalle Valo 
4604d5c65159SKalle Valo 		if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
4605d5c65159SKalle Valo 			break;
4606d5c65159SKalle Valo 
4607d5c65159SKalle Valo 		for (i = 0; i < ab->num_radios; i++) {
4608d5c65159SKalle Valo 			pdev = &ab->pdevs[i];
4609d5c65159SKalle Valo 			ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
4610d5c65159SKalle Valo 		}
4611d5c65159SKalle Valo 		ab->pdevs_macaddr_valid = true;
4612d5c65159SKalle Valo 		break;
4613d5c65159SKalle Valo 	default:
4614d5c65159SKalle Valo 		break;
4615d5c65159SKalle Valo 	}
4616d5c65159SKalle Valo 
4617d5c65159SKalle Valo 	return 0;
4618d5c65159SKalle Valo }
4619d5c65159SKalle Valo 
4620d5c65159SKalle Valo static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
4621d5c65159SKalle Valo {
4622d5c65159SKalle Valo 	struct wmi_tlv_rdy_parse rdy_parse = { };
4623d5c65159SKalle Valo 	int ret;
4624d5c65159SKalle Valo 
4625d5c65159SKalle Valo 	ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4626d5c65159SKalle Valo 				  ath11k_wmi_tlv_rdy_parse, &rdy_parse);
4627d5c65159SKalle Valo 	if (ret) {
4628d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4629d5c65159SKalle Valo 		return ret;
4630d5c65159SKalle Valo 	}
4631d5c65159SKalle Valo 
4632d5c65159SKalle Valo 	complete(&ab->wmi_sc.unified_ready);
4633d5c65159SKalle Valo 	return 0;
4634d5c65159SKalle Valo }
4635d5c65159SKalle Valo 
4636d5c65159SKalle Valo static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
4637d5c65159SKalle Valo {
4638d5c65159SKalle Valo 	struct wmi_peer_delete_resp_event peer_del_resp;
4639d5c65159SKalle Valo 
4640d5c65159SKalle Valo 	if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
4641d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer delete resp");
4642d5c65159SKalle Valo 		return;
4643d5c65159SKalle Valo 	}
4644d5c65159SKalle Valo 
4645d5c65159SKalle Valo 	/* TODO: Do we need to validate whether ath11k_peer_find() return NULL
4646d5c65159SKalle Valo 	 *	 Why this is needed when there is HTT event for peer delete
4647d5c65159SKalle Valo 	 */
4648d5c65159SKalle Valo }
4649d5c65159SKalle Valo 
4650d5c65159SKalle Valo static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
4651d5c65159SKalle Valo {
4652d5c65159SKalle Valo 	switch (vdev_resp_status) {
4653d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
4654d5c65159SKalle Valo 		return "invalid vdev id";
4655d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
4656d5c65159SKalle Valo 		return "not supported";
4657d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
4658d5c65159SKalle Valo 		return "dfs violation";
4659d5c65159SKalle Valo 	case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
4660d5c65159SKalle Valo 		return "invalid regdomain";
4661d5c65159SKalle Valo 	default:
4662d5c65159SKalle Valo 		return "unknown";
4663d5c65159SKalle Valo 	}
4664d5c65159SKalle Valo }
4665d5c65159SKalle Valo 
4666d5c65159SKalle Valo static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
4667d5c65159SKalle Valo {
4668d5c65159SKalle Valo 	struct wmi_vdev_start_resp_event vdev_start_resp;
4669d5c65159SKalle Valo 	struct ath11k *ar;
4670d5c65159SKalle Valo 	u32 status;
4671d5c65159SKalle Valo 
4672d5c65159SKalle Valo 	if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
4673d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev start resp");
4674d5c65159SKalle Valo 		return;
4675d5c65159SKalle Valo 	}
4676d5c65159SKalle Valo 
4677d5c65159SKalle Valo 	rcu_read_lock();
4678d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
4679d5c65159SKalle Valo 	if (!ar) {
4680d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
4681d5c65159SKalle Valo 			    vdev_start_resp.vdev_id);
4682d5c65159SKalle Valo 		rcu_read_unlock();
4683d5c65159SKalle Valo 		return;
4684d5c65159SKalle Valo 	}
4685d5c65159SKalle Valo 
4686d5c65159SKalle Valo 	ar->last_wmi_vdev_start_status = 0;
4687d5c65159SKalle Valo 
4688d5c65159SKalle Valo 	status = vdev_start_resp.status;
4689d5c65159SKalle Valo 
4690d5c65159SKalle Valo 	if (WARN_ON_ONCE(status)) {
4691d5c65159SKalle Valo 		ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
4692d5c65159SKalle Valo 			    status, ath11k_wmi_vdev_resp_print(status));
4693d5c65159SKalle Valo 		ar->last_wmi_vdev_start_status = status;
4694d5c65159SKalle Valo 	}
4695d5c65159SKalle Valo 
4696d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
4697d5c65159SKalle Valo 
4698d5c65159SKalle Valo 	rcu_read_unlock();
4699d5c65159SKalle Valo 
4700d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
4701d5c65159SKalle Valo 		   vdev_start_resp.vdev_id);
4702d5c65159SKalle Valo }
4703d5c65159SKalle Valo 
4704d5c65159SKalle Valo static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
4705d5c65159SKalle Valo {
4706d5c65159SKalle Valo 	u32 vdev_id, tx_status;
4707d5c65159SKalle Valo 
4708d5c65159SKalle Valo 	if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
4709d5c65159SKalle Valo 					 &vdev_id, &tx_status) != 0) {
4710d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract bcn tx status");
4711d5c65159SKalle Valo 		return;
4712d5c65159SKalle Valo 	}
4713d5c65159SKalle Valo }
4714d5c65159SKalle Valo 
4715d5c65159SKalle Valo static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
4716d5c65159SKalle Valo {
4717d5c65159SKalle Valo 	struct ath11k *ar;
4718d5c65159SKalle Valo 	u32 vdev_id = 0;
4719d5c65159SKalle Valo 
4720d5c65159SKalle Valo 	if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
4721d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract vdev stopped event");
4722d5c65159SKalle Valo 		return;
4723d5c65159SKalle Valo 	}
4724d5c65159SKalle Valo 
4725d5c65159SKalle Valo 	rcu_read_lock();
4726d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_vdev_stop_status(ab, vdev_id);
4727d5c65159SKalle Valo 	if (!ar) {
4728d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
4729d5c65159SKalle Valo 			    vdev_id);
4730d5c65159SKalle Valo 		rcu_read_unlock();
4731d5c65159SKalle Valo 		return;
4732d5c65159SKalle Valo 	}
4733d5c65159SKalle Valo 
4734d5c65159SKalle Valo 	complete(&ar->vdev_setup_done);
4735d5c65159SKalle Valo 
4736d5c65159SKalle Valo 	rcu_read_unlock();
4737d5c65159SKalle Valo 
4738d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
4739d5c65159SKalle Valo }
4740d5c65159SKalle Valo 
4741d5c65159SKalle Valo static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
4742d5c65159SKalle Valo {
4743d5c65159SKalle Valo 	struct mgmt_rx_event_params rx_ev = {0};
4744d5c65159SKalle Valo 	struct ath11k *ar;
4745d5c65159SKalle Valo 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4746d5c65159SKalle Valo 	struct ieee80211_hdr *hdr;
4747d5c65159SKalle Valo 	u16 fc;
4748d5c65159SKalle Valo 	struct ieee80211_supported_band *sband;
4749d5c65159SKalle Valo 
4750d5c65159SKalle Valo 	if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
4751d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt rx event");
4752d5c65159SKalle Valo 		dev_kfree_skb(skb);
4753d5c65159SKalle Valo 		return;
4754d5c65159SKalle Valo 	}
4755d5c65159SKalle Valo 
4756d5c65159SKalle Valo 	memset(status, 0, sizeof(*status));
4757d5c65159SKalle Valo 
4758d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n",
4759d5c65159SKalle Valo 		   rx_ev.status);
4760d5c65159SKalle Valo 
4761d5c65159SKalle Valo 	rcu_read_lock();
4762d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
4763d5c65159SKalle Valo 
4764d5c65159SKalle Valo 	if (!ar) {
4765d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
4766d5c65159SKalle Valo 			    rx_ev.pdev_id);
4767d5c65159SKalle Valo 		dev_kfree_skb(skb);
4768d5c65159SKalle Valo 		goto exit;
4769d5c65159SKalle Valo 	}
4770d5c65159SKalle Valo 
4771d5c65159SKalle Valo 	if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
4772d5c65159SKalle Valo 	    (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
4773d5c65159SKalle Valo 	    WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
4774d5c65159SKalle Valo 		dev_kfree_skb(skb);
4775d5c65159SKalle Valo 		goto exit;
4776d5c65159SKalle Valo 	}
4777d5c65159SKalle Valo 
4778d5c65159SKalle Valo 	if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
4779d5c65159SKalle Valo 		status->flag |= RX_FLAG_MMIC_ERROR;
4780d5c65159SKalle Valo 
4781d5c65159SKalle Valo 	if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
4782d5c65159SKalle Valo 		status->band = NL80211_BAND_2GHZ;
4783d5c65159SKalle Valo 	} else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
4784d5c65159SKalle Valo 		status->band = NL80211_BAND_5GHZ;
4785d5c65159SKalle Valo 	} else {
4786d5c65159SKalle Valo 		/* Shouldn't happen unless list of advertised channels to
4787d5c65159SKalle Valo 		 * mac80211 has been changed.
4788d5c65159SKalle Valo 		 */
4789d5c65159SKalle Valo 		WARN_ON_ONCE(1);
4790d5c65159SKalle Valo 		dev_kfree_skb(skb);
4791d5c65159SKalle Valo 		goto exit;
4792d5c65159SKalle Valo 	}
4793d5c65159SKalle Valo 
4794d5c65159SKalle Valo 	if (rx_ev.phy_mode == MODE_11B && status->band == NL80211_BAND_5GHZ)
4795d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
4796d5c65159SKalle Valo 			   "wmi mgmt rx 11b (CCK) on 5GHz\n");
4797d5c65159SKalle Valo 
4798d5c65159SKalle Valo 	sband = &ar->mac.sbands[status->band];
4799d5c65159SKalle Valo 
4800d5c65159SKalle Valo 	status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
4801d5c65159SKalle Valo 						      status->band);
4802d5c65159SKalle Valo 	status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
4803d5c65159SKalle Valo 	status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
4804d5c65159SKalle Valo 
4805d5c65159SKalle Valo 	hdr = (struct ieee80211_hdr *)skb->data;
4806d5c65159SKalle Valo 	fc = le16_to_cpu(hdr->frame_control);
4807d5c65159SKalle Valo 
4808d5c65159SKalle Valo 	/* Firmware is guaranteed to report all essential management frames via
4809d5c65159SKalle Valo 	 * WMI while it can deliver some extra via HTT. Since there can be
4810d5c65159SKalle Valo 	 * duplicates split the reporting wrt monitor/sniffing.
4811d5c65159SKalle Valo 	 */
4812d5c65159SKalle Valo 	status->flag |= RX_FLAG_SKIP_MONITOR;
4813d5c65159SKalle Valo 
4814d5c65159SKalle Valo 	/* In case of PMF, FW delivers decrypted frames with Protected Bit set.
4815d5c65159SKalle Valo 	 * Don't clear that. Also, FW delivers broadcast management frames
4816d5c65159SKalle Valo 	 * (ex: group privacy action frames in mesh) as encrypted payload.
4817d5c65159SKalle Valo 	 */
4818d5c65159SKalle Valo 	if (ieee80211_has_protected(hdr->frame_control) &&
4819d5c65159SKalle Valo 	    !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
4820d5c65159SKalle Valo 		status->flag |= RX_FLAG_DECRYPTED;
4821d5c65159SKalle Valo 
4822d5c65159SKalle Valo 		if (!ieee80211_is_robust_mgmt_frame(skb)) {
4823d5c65159SKalle Valo 			status->flag |= RX_FLAG_IV_STRIPPED |
4824d5c65159SKalle Valo 					RX_FLAG_MMIC_STRIPPED;
4825d5c65159SKalle Valo 			hdr->frame_control = __cpu_to_le16(fc &
4826d5c65159SKalle Valo 					     ~IEEE80211_FCTL_PROTECTED);
4827d5c65159SKalle Valo 		}
4828d5c65159SKalle Valo 	}
4829d5c65159SKalle Valo 
4830d5c65159SKalle Valo 	/* TODO: Pending handle beacon implementation
4831d5c65159SKalle Valo 	 *if (ieee80211_is_beacon(hdr->frame_control))
4832d5c65159SKalle Valo 	 *	ath11k_mac_handle_beacon(ar, skb);
4833d5c65159SKalle Valo 	 */
4834d5c65159SKalle Valo 
4835d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
4836d5c65159SKalle Valo 		   "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
4837d5c65159SKalle Valo 		   skb, skb->len,
4838d5c65159SKalle Valo 		   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
4839d5c65159SKalle Valo 
4840d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
4841d5c65159SKalle Valo 		   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
4842d5c65159SKalle Valo 		   status->freq, status->band, status->signal,
4843d5c65159SKalle Valo 		   status->rate_idx);
4844d5c65159SKalle Valo 
4845d5c65159SKalle Valo 	ieee80211_rx_ni(ar->hw, skb);
4846d5c65159SKalle Valo 
4847d5c65159SKalle Valo exit:
4848d5c65159SKalle Valo 	rcu_read_unlock();
4849d5c65159SKalle Valo }
4850d5c65159SKalle Valo 
4851d5c65159SKalle Valo static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
4852d5c65159SKalle Valo {
4853d5c65159SKalle Valo 	struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
4854d5c65159SKalle Valo 	struct ath11k *ar;
4855d5c65159SKalle Valo 
4856d5c65159SKalle Valo 	if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
4857d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract mgmt tx compl event");
4858d5c65159SKalle Valo 		return;
4859d5c65159SKalle Valo 	}
4860d5c65159SKalle Valo 
4861d5c65159SKalle Valo 	rcu_read_lock();
4862d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
4863d5c65159SKalle Valo 	if (!ar) {
4864d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
4865d5c65159SKalle Valo 			    tx_compl_param.pdev_id);
4866d5c65159SKalle Valo 		goto exit;
4867d5c65159SKalle Valo 	}
4868d5c65159SKalle Valo 
4869d5c65159SKalle Valo 	wmi_process_mgmt_tx_comp(ar, tx_compl_param.desc_id,
4870d5c65159SKalle Valo 				 tx_compl_param.status);
4871d5c65159SKalle Valo 
4872d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_MGMT,
4873d5c65159SKalle Valo 		   "mgmt tx compl ev pdev_id %d, desc_id %d, status %d",
4874d5c65159SKalle Valo 		   tx_compl_param.pdev_id, tx_compl_param.desc_id,
4875d5c65159SKalle Valo 		   tx_compl_param.status);
4876d5c65159SKalle Valo 
4877d5c65159SKalle Valo exit:
4878d5c65159SKalle Valo 	rcu_read_unlock();
4879d5c65159SKalle Valo }
4880d5c65159SKalle Valo 
4881d5c65159SKalle Valo static struct ath11k *ath11k_get_ar_on_scan_abort(struct ath11k_base *ab,
4882d5c65159SKalle Valo 						  u32 vdev_id)
4883d5c65159SKalle Valo {
4884d5c65159SKalle Valo 	int i;
4885d5c65159SKalle Valo 	struct ath11k_pdev *pdev;
4886d5c65159SKalle Valo 	struct ath11k *ar;
4887d5c65159SKalle Valo 
4888d5c65159SKalle Valo 	for (i = 0; i < ab->num_radios; i++) {
4889d5c65159SKalle Valo 		pdev = rcu_dereference(ab->pdevs_active[i]);
4890d5c65159SKalle Valo 		if (pdev && pdev->ar) {
4891d5c65159SKalle Valo 			ar = pdev->ar;
4892d5c65159SKalle Valo 
4893d5c65159SKalle Valo 			spin_lock_bh(&ar->data_lock);
4894d5c65159SKalle Valo 			if (ar->scan.state == ATH11K_SCAN_ABORTING &&
4895d5c65159SKalle Valo 			    ar->scan.vdev_id == vdev_id) {
4896d5c65159SKalle Valo 				spin_unlock_bh(&ar->data_lock);
4897d5c65159SKalle Valo 				return ar;
4898d5c65159SKalle Valo 			}
4899d5c65159SKalle Valo 			spin_unlock_bh(&ar->data_lock);
4900d5c65159SKalle Valo 		}
4901d5c65159SKalle Valo 	}
4902d5c65159SKalle Valo 	return NULL;
4903d5c65159SKalle Valo }
4904d5c65159SKalle Valo 
4905d5c65159SKalle Valo static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
4906d5c65159SKalle Valo {
4907d5c65159SKalle Valo 	struct ath11k *ar;
4908d5c65159SKalle Valo 	struct wmi_scan_event scan_ev = {0};
4909d5c65159SKalle Valo 
4910d5c65159SKalle Valo 	if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
4911d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract scan event");
4912d5c65159SKalle Valo 		return;
4913d5c65159SKalle Valo 	}
4914d5c65159SKalle Valo 
4915d5c65159SKalle Valo 	rcu_read_lock();
4916d5c65159SKalle Valo 
4917d5c65159SKalle Valo 	/* In case the scan was cancelled, ex. during interface teardown,
4918d5c65159SKalle Valo 	 * the interface will not be found in active interfaces.
4919d5c65159SKalle Valo 	 * Rather, in such scenarios, iterate over the active pdev's to
4920d5c65159SKalle Valo 	 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
4921d5c65159SKalle Valo 	 * aborting scan's vdev id matches this event info.
4922d5c65159SKalle Valo 	 */
4923d5c65159SKalle Valo 	if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
4924d5c65159SKalle Valo 	    scan_ev.reason == WMI_SCAN_REASON_CANCELLED)
4925d5c65159SKalle Valo 		ar = ath11k_get_ar_on_scan_abort(ab, scan_ev.vdev_id);
4926d5c65159SKalle Valo 	else
4927d5c65159SKalle Valo 		ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
4928d5c65159SKalle Valo 
4929d5c65159SKalle Valo 	if (!ar) {
4930d5c65159SKalle Valo 		ath11k_warn(ab, "Received scan event for unknown vdev");
4931d5c65159SKalle Valo 		rcu_read_unlock();
4932d5c65159SKalle Valo 		return;
4933d5c65159SKalle Valo 	}
4934d5c65159SKalle Valo 
4935d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
4936d5c65159SKalle Valo 
4937d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
4938d5c65159SKalle Valo 		   "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
4939d5c65159SKalle Valo 		   ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
4940d5c65159SKalle Valo 		   scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
4941d5c65159SKalle Valo 		   scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
4942d5c65159SKalle Valo 		   ath11k_scan_state_str(ar->scan.state), ar->scan.state);
4943d5c65159SKalle Valo 
4944d5c65159SKalle Valo 	switch (scan_ev.event_type) {
4945d5c65159SKalle Valo 	case WMI_SCAN_EVENT_STARTED:
4946d5c65159SKalle Valo 		ath11k_wmi_event_scan_started(ar);
4947d5c65159SKalle Valo 		break;
4948d5c65159SKalle Valo 	case WMI_SCAN_EVENT_COMPLETED:
4949d5c65159SKalle Valo 		ath11k_wmi_event_scan_completed(ar);
4950d5c65159SKalle Valo 		break;
4951d5c65159SKalle Valo 	case WMI_SCAN_EVENT_BSS_CHANNEL:
4952d5c65159SKalle Valo 		ath11k_wmi_event_scan_bss_chan(ar);
4953d5c65159SKalle Valo 		break;
4954d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN:
4955d5c65159SKalle Valo 		ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
4956d5c65159SKalle Valo 		break;
4957d5c65159SKalle Valo 	case WMI_SCAN_EVENT_START_FAILED:
4958d5c65159SKalle Valo 		ath11k_warn(ab, "received scan start failure event\n");
4959d5c65159SKalle Valo 		ath11k_wmi_event_scan_start_failed(ar);
4960d5c65159SKalle Valo 		break;
4961d5c65159SKalle Valo 	case WMI_SCAN_EVENT_DEQUEUED:
4962d5c65159SKalle Valo 	case WMI_SCAN_EVENT_PREEMPTED:
4963d5c65159SKalle Valo 	case WMI_SCAN_EVENT_RESTARTED:
4964d5c65159SKalle Valo 	case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
4965d5c65159SKalle Valo 	default:
4966d5c65159SKalle Valo 		break;
4967d5c65159SKalle Valo 	}
4968d5c65159SKalle Valo 
4969d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
4970d5c65159SKalle Valo 
4971d5c65159SKalle Valo 	rcu_read_unlock();
4972d5c65159SKalle Valo }
4973d5c65159SKalle Valo 
4974d5c65159SKalle Valo static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
4975d5c65159SKalle Valo {
4976d5c65159SKalle Valo 	struct wmi_peer_sta_kickout_arg arg = {};
4977d5c65159SKalle Valo 	struct ieee80211_sta *sta;
4978d5c65159SKalle Valo 	struct ath11k_peer *peer;
4979d5c65159SKalle Valo 	struct ath11k *ar;
4980d5c65159SKalle Valo 
4981d5c65159SKalle Valo 	if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
4982d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer sta kickout event");
4983d5c65159SKalle Valo 		return;
4984d5c65159SKalle Valo 	}
4985d5c65159SKalle Valo 
4986d5c65159SKalle Valo 	rcu_read_lock();
4987d5c65159SKalle Valo 
4988d5c65159SKalle Valo 	spin_lock_bh(&ab->base_lock);
4989d5c65159SKalle Valo 
4990d5c65159SKalle Valo 	peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
4991d5c65159SKalle Valo 
4992d5c65159SKalle Valo 	if (!peer) {
4993d5c65159SKalle Valo 		ath11k_warn(ab, "peer not found %pM\n",
4994d5c65159SKalle Valo 			    arg.mac_addr);
4995d5c65159SKalle Valo 		goto exit;
4996d5c65159SKalle Valo 	}
4997d5c65159SKalle Valo 
4998d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id);
4999d5c65159SKalle Valo 	if (!ar) {
5000d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
5001d5c65159SKalle Valo 			    peer->vdev_id);
5002d5c65159SKalle Valo 		goto exit;
5003d5c65159SKalle Valo 	}
5004d5c65159SKalle Valo 
5005d5c65159SKalle Valo 	sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5006d5c65159SKalle Valo 					   arg.mac_addr, NULL);
5007d5c65159SKalle Valo 	if (!sta) {
5008d5c65159SKalle Valo 		ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
5009d5c65159SKalle Valo 			    arg.mac_addr);
5010d5c65159SKalle Valo 		goto exit;
5011d5c65159SKalle Valo 	}
5012d5c65159SKalle Valo 
5013d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM",
5014d5c65159SKalle Valo 		   arg.mac_addr);
5015d5c65159SKalle Valo 
5016d5c65159SKalle Valo 	ieee80211_report_low_ack(sta, 10);
5017d5c65159SKalle Valo 
5018d5c65159SKalle Valo exit:
5019d5c65159SKalle Valo 	spin_unlock_bh(&ab->base_lock);
5020d5c65159SKalle Valo 	rcu_read_unlock();
5021d5c65159SKalle Valo }
5022d5c65159SKalle Valo 
5023d5c65159SKalle Valo static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
5024d5c65159SKalle Valo {
5025d5c65159SKalle Valo 	struct wmi_roam_event roam_ev = {};
5026d5c65159SKalle Valo 	struct ath11k *ar;
5027d5c65159SKalle Valo 
5028d5c65159SKalle Valo 	if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
5029d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract roam event");
5030d5c65159SKalle Valo 		return;
5031d5c65159SKalle Valo 	}
5032d5c65159SKalle Valo 
5033d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5034d5c65159SKalle Valo 		   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
5035d5c65159SKalle Valo 		   roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
5036d5c65159SKalle Valo 
5037d5c65159SKalle Valo 	rcu_read_lock();
5038d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
5039d5c65159SKalle Valo 	if (!ar) {
5040d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in roam ev %d",
5041d5c65159SKalle Valo 			    roam_ev.vdev_id);
5042d5c65159SKalle Valo 		rcu_read_unlock();
5043d5c65159SKalle Valo 		return;
5044d5c65159SKalle Valo 	}
5045d5c65159SKalle Valo 
5046d5c65159SKalle Valo 	if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
5047d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
5048d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
5049d5c65159SKalle Valo 
5050d5c65159SKalle Valo 	switch (roam_ev.reason) {
5051d5c65159SKalle Valo 	case WMI_ROAM_REASON_BEACON_MISS:
5052d5c65159SKalle Valo 		/* TODO: Pending beacon miss and connection_loss_work
5053d5c65159SKalle Valo 		 * implementation
5054d5c65159SKalle Valo 		 * ath11k_mac_handle_beacon_miss(ar, vdev_id);
5055d5c65159SKalle Valo 		 */
5056d5c65159SKalle Valo 		break;
5057d5c65159SKalle Valo 	case WMI_ROAM_REASON_BETTER_AP:
5058d5c65159SKalle Valo 	case WMI_ROAM_REASON_LOW_RSSI:
5059d5c65159SKalle Valo 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
5060d5c65159SKalle Valo 	case WMI_ROAM_REASON_HO_FAILED:
5061d5c65159SKalle Valo 		ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
5062d5c65159SKalle Valo 			    roam_ev.reason, roam_ev.vdev_id);
5063d5c65159SKalle Valo 		break;
5064d5c65159SKalle Valo 	}
5065d5c65159SKalle Valo 
5066d5c65159SKalle Valo 	rcu_read_unlock();
5067d5c65159SKalle Valo }
5068d5c65159SKalle Valo 
5069d5c65159SKalle Valo static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
5070d5c65159SKalle Valo {
5071d5c65159SKalle Valo 	struct wmi_chan_info_event ch_info_ev = {0};
5072d5c65159SKalle Valo 	struct ath11k *ar;
5073d5c65159SKalle Valo 	struct survey_info *survey;
5074d5c65159SKalle Valo 	int idx;
5075d5c65159SKalle Valo 	/* HW channel counters frequency value in hertz */
5076d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
5077d5c65159SKalle Valo 
5078d5c65159SKalle Valo 	if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
5079d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract chan info event");
5080d5c65159SKalle Valo 		return;
5081d5c65159SKalle Valo 	}
5082d5c65159SKalle Valo 
5083d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5084d5c65159SKalle 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",
5085d5c65159SKalle Valo 		   ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
5086d5c65159SKalle Valo 		   ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
5087d5c65159SKalle Valo 		   ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
5088d5c65159SKalle Valo 		   ch_info_ev.mac_clk_mhz);
5089d5c65159SKalle Valo 
5090d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
5091d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
5092d5c65159SKalle Valo 		return;
5093d5c65159SKalle Valo 	}
5094d5c65159SKalle Valo 
5095d5c65159SKalle Valo 	rcu_read_lock();
5096d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
5097d5c65159SKalle Valo 	if (!ar) {
5098d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in chan info ev %d",
5099d5c65159SKalle Valo 			    ch_info_ev.vdev_id);
5100d5c65159SKalle Valo 		rcu_read_unlock();
5101d5c65159SKalle Valo 		return;
5102d5c65159SKalle Valo 	}
5103d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
5104d5c65159SKalle Valo 
5105d5c65159SKalle Valo 	switch (ar->scan.state) {
5106d5c65159SKalle Valo 	case ATH11K_SCAN_IDLE:
5107d5c65159SKalle Valo 	case ATH11K_SCAN_STARTING:
5108d5c65159SKalle Valo 		ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
5109d5c65159SKalle Valo 		goto exit;
5110d5c65159SKalle Valo 	case ATH11K_SCAN_RUNNING:
5111d5c65159SKalle Valo 	case ATH11K_SCAN_ABORTING:
5112d5c65159SKalle Valo 		break;
5113d5c65159SKalle Valo 	}
5114d5c65159SKalle Valo 
5115d5c65159SKalle Valo 	idx = freq_to_idx(ar, ch_info_ev.freq);
5116d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
5117d5c65159SKalle Valo 		ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
5118d5c65159SKalle Valo 			    ch_info_ev.freq, idx);
5119d5c65159SKalle Valo 		goto exit;
5120d5c65159SKalle Valo 	}
5121d5c65159SKalle Valo 
5122d5c65159SKalle Valo 	/* If FW provides MAC clock frequency in Mhz, overriding the initialized
5123d5c65159SKalle Valo 	 * HW channel counters frequency value
5124d5c65159SKalle Valo 	 */
5125d5c65159SKalle Valo 	if (ch_info_ev.mac_clk_mhz)
5126d5c65159SKalle Valo 		cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
5127d5c65159SKalle Valo 
5128d5c65159SKalle Valo 	if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
5129d5c65159SKalle Valo 		survey = &ar->survey[idx];
5130d5c65159SKalle Valo 		memset(survey, 0, sizeof(*survey));
5131d5c65159SKalle Valo 		survey->noise = ch_info_ev.noise_floor;
5132d5c65159SKalle Valo 		survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
5133d5c65159SKalle Valo 				 SURVEY_INFO_TIME_BUSY;
5134d5c65159SKalle Valo 		survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
5135d5c65159SKalle Valo 		survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
5136d5c65159SKalle Valo 	}
5137d5c65159SKalle Valo exit:
5138d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
5139d5c65159SKalle Valo 	rcu_read_unlock();
5140d5c65159SKalle Valo }
5141d5c65159SKalle Valo 
5142d5c65159SKalle Valo static void
5143d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
5144d5c65159SKalle Valo {
5145d5c65159SKalle Valo 	struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
5146d5c65159SKalle Valo 	struct survey_info *survey;
5147d5c65159SKalle Valo 	struct ath11k *ar;
5148d5c65159SKalle Valo 	u32 cc_freq_hz = ab->cc_freq_hz;
5149d5c65159SKalle Valo 	u64 busy, total, tx, rx, rx_bss;
5150d5c65159SKalle Valo 	int idx;
5151d5c65159SKalle Valo 
5152d5c65159SKalle Valo 	if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
5153d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract pdev bss chan info event");
5154d5c65159SKalle Valo 		return;
5155d5c65159SKalle Valo 	}
5156d5c65159SKalle Valo 
5157d5c65159SKalle Valo 	busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
5158d5c65159SKalle Valo 			bss_ch_info_ev.rx_clear_count_low;
5159d5c65159SKalle Valo 
5160d5c65159SKalle Valo 	total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
5161d5c65159SKalle Valo 			bss_ch_info_ev.cycle_count_low;
5162d5c65159SKalle Valo 
5163d5c65159SKalle Valo 	tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
5164d5c65159SKalle Valo 			bss_ch_info_ev.tx_cycle_count_low;
5165d5c65159SKalle Valo 
5166d5c65159SKalle Valo 	rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
5167d5c65159SKalle Valo 			bss_ch_info_ev.rx_cycle_count_low;
5168d5c65159SKalle Valo 
5169d5c65159SKalle Valo 	rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
5170d5c65159SKalle Valo 			bss_ch_info_ev.rx_bss_cycle_count_low;
5171d5c65159SKalle Valo 
5172d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5173d5c65159SKalle 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",
5174d5c65159SKalle Valo 		   bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
5175d5c65159SKalle Valo 		   bss_ch_info_ev.noise_floor, busy, total,
5176d5c65159SKalle Valo 		   tx, rx, rx_bss);
5177d5c65159SKalle Valo 
5178d5c65159SKalle Valo 	rcu_read_lock();
5179d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
5180d5c65159SKalle Valo 
5181d5c65159SKalle Valo 	if (!ar) {
5182d5c65159SKalle Valo 		ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
5183d5c65159SKalle Valo 			    bss_ch_info_ev.pdev_id);
5184d5c65159SKalle Valo 		rcu_read_unlock();
5185d5c65159SKalle Valo 		return;
5186d5c65159SKalle Valo 	}
5187d5c65159SKalle Valo 
5188d5c65159SKalle Valo 	spin_lock_bh(&ar->data_lock);
5189d5c65159SKalle Valo 	idx = freq_to_idx(ar, bss_ch_info_ev.freq);
5190d5c65159SKalle Valo 	if (idx >= ARRAY_SIZE(ar->survey)) {
5191d5c65159SKalle Valo 		ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
5192d5c65159SKalle Valo 			    bss_ch_info_ev.freq, idx);
5193d5c65159SKalle Valo 		goto exit;
5194d5c65159SKalle Valo 	}
5195d5c65159SKalle Valo 
5196d5c65159SKalle Valo 	survey = &ar->survey[idx];
5197d5c65159SKalle Valo 
5198d5c65159SKalle Valo 	survey->noise     = bss_ch_info_ev.noise_floor;
5199d5c65159SKalle Valo 	survey->time      = div_u64(total, cc_freq_hz);
5200d5c65159SKalle Valo 	survey->time_busy = div_u64(busy, cc_freq_hz);
5201d5c65159SKalle Valo 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
5202d5c65159SKalle Valo 	survey->time_tx   = div_u64(tx, cc_freq_hz);
5203d5c65159SKalle Valo 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
5204d5c65159SKalle Valo 			     SURVEY_INFO_TIME |
5205d5c65159SKalle Valo 			     SURVEY_INFO_TIME_BUSY |
5206d5c65159SKalle Valo 			     SURVEY_INFO_TIME_RX |
5207d5c65159SKalle Valo 			     SURVEY_INFO_TIME_TX);
5208d5c65159SKalle Valo exit:
5209d5c65159SKalle Valo 	spin_unlock_bh(&ar->data_lock);
5210d5c65159SKalle Valo 	complete(&ar->bss_survey_done);
5211d5c65159SKalle Valo 
5212d5c65159SKalle Valo 	rcu_read_unlock();
5213d5c65159SKalle Valo }
5214d5c65159SKalle Valo 
5215d5c65159SKalle Valo static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
5216d5c65159SKalle Valo 						struct sk_buff *skb)
5217d5c65159SKalle Valo {
5218d5c65159SKalle Valo 	struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
5219d5c65159SKalle Valo 	struct ath11k *ar;
5220d5c65159SKalle Valo 
5221d5c65159SKalle Valo 	if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
5222d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract install key compl event");
5223d5c65159SKalle Valo 		return;
5224d5c65159SKalle Valo 	}
5225d5c65159SKalle Valo 
5226d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5227d5c65159SKalle Valo 		   "vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
5228d5c65159SKalle Valo 		   install_key_compl.key_idx, install_key_compl.key_flags,
5229d5c65159SKalle Valo 		   install_key_compl.macaddr, install_key_compl.status);
5230d5c65159SKalle Valo 
5231d5c65159SKalle Valo 	rcu_read_lock();
5232d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
5233d5c65159SKalle Valo 	if (!ar) {
5234d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
5235d5c65159SKalle Valo 			    install_key_compl.vdev_id);
5236d5c65159SKalle Valo 		rcu_read_unlock();
5237d5c65159SKalle Valo 		return;
5238d5c65159SKalle Valo 	}
5239d5c65159SKalle Valo 
5240d5c65159SKalle Valo 	ar->install_key_status = 0;
5241d5c65159SKalle Valo 
5242d5c65159SKalle Valo 	if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
5243d5c65159SKalle Valo 		ath11k_warn(ab, "install key failed for %pM status %d\n",
5244d5c65159SKalle Valo 			    install_key_compl.macaddr, install_key_compl.status);
5245d5c65159SKalle Valo 		ar->install_key_status = install_key_compl.status;
5246d5c65159SKalle Valo 	}
5247d5c65159SKalle Valo 
5248d5c65159SKalle Valo 	complete(&ar->install_key_done);
5249d5c65159SKalle Valo 	rcu_read_unlock();
5250d5c65159SKalle Valo }
5251d5c65159SKalle Valo 
5252d5c65159SKalle Valo static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
5253d5c65159SKalle Valo {
5254d5c65159SKalle Valo 	const void **tb;
5255d5c65159SKalle Valo 	const struct wmi_service_available_event *ev;
5256d5c65159SKalle Valo 	int ret;
5257d5c65159SKalle Valo 	int i, j;
5258d5c65159SKalle Valo 
5259d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5260d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5261d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5262d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5263d5c65159SKalle Valo 		return;
5264d5c65159SKalle Valo 	}
5265d5c65159SKalle Valo 
5266d5c65159SKalle Valo 	ev = tb[WMI_TAG_SERVICE_AVAILABLE_EVENT];
5267d5c65159SKalle Valo 	if (!ev) {
5268d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch svc available ev");
5269d5c65159SKalle Valo 		kfree(tb);
5270d5c65159SKalle Valo 		return;
5271d5c65159SKalle Valo 	}
5272d5c65159SKalle Valo 
5273d5c65159SKalle Valo 	/* TODO: Use wmi_service_segment_offset information to get the service
5274d5c65159SKalle Valo 	 * especially when more services are advertised in multiple sevice
5275d5c65159SKalle Valo 	 * available events.
5276d5c65159SKalle Valo 	 */
5277d5c65159SKalle Valo 	for (i = 0, j = WMI_MAX_SERVICE;
5278d5c65159SKalle Valo 	     i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
5279d5c65159SKalle Valo 	     i++) {
5280d5c65159SKalle Valo 		do {
5281d5c65159SKalle Valo 			if (ev->wmi_service_segment_bitmap[i] &
5282d5c65159SKalle Valo 			    BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
5283d5c65159SKalle Valo 				set_bit(j, ab->wmi_sc.svc_map);
5284d5c65159SKalle Valo 		} while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
5285d5c65159SKalle Valo 	}
5286d5c65159SKalle Valo 
5287d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5288d5c65159SKalle Valo 		   "wmi_ext_service_bitmap 0:0x%x, 1:0x%x, 2:0x%x, 3:0x%x",
5289d5c65159SKalle Valo 		   ev->wmi_service_segment_bitmap[0], ev->wmi_service_segment_bitmap[1],
5290d5c65159SKalle Valo 		   ev->wmi_service_segment_bitmap[2], ev->wmi_service_segment_bitmap[3]);
5291d5c65159SKalle Valo 
5292d5c65159SKalle Valo 	kfree(tb);
5293d5c65159SKalle Valo }
5294d5c65159SKalle Valo 
5295d5c65159SKalle Valo static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
5296d5c65159SKalle Valo {
5297d5c65159SKalle Valo 	struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
5298d5c65159SKalle Valo 	struct ath11k *ar;
5299d5c65159SKalle Valo 
5300d5c65159SKalle Valo 	if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
5301d5c65159SKalle Valo 		ath11k_warn(ab, "failed to extract peer assoc conf event");
5302d5c65159SKalle Valo 		return;
5303d5c65159SKalle Valo 	}
5304d5c65159SKalle Valo 
5305d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5306d5c65159SKalle Valo 		   "peer assoc conf ev vdev id %d macaddr %pM\n",
5307d5c65159SKalle Valo 		   peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
5308d5c65159SKalle Valo 
5309d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
5310d5c65159SKalle Valo 
5311d5c65159SKalle Valo 	if (!ar) {
5312d5c65159SKalle Valo 		ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
5313d5c65159SKalle Valo 			    peer_assoc_conf.vdev_id);
5314d5c65159SKalle Valo 		return;
5315d5c65159SKalle Valo 	}
5316d5c65159SKalle Valo 
5317d5c65159SKalle Valo 	complete(&ar->peer_assoc_done);
5318d5c65159SKalle Valo }
5319d5c65159SKalle Valo 
5320d5c65159SKalle Valo static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
5321d5c65159SKalle Valo {
5322d5c65159SKalle Valo 	ath11k_debug_fw_stats_process(ab, skb);
5323d5c65159SKalle Valo }
5324d5c65159SKalle Valo 
5325d5c65159SKalle Valo /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
5326d5c65159SKalle Valo  * is not part of BDF CTL(Conformance test limits) table entries.
5327d5c65159SKalle Valo  */
5328d5c65159SKalle Valo static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
5329d5c65159SKalle Valo 						 struct sk_buff *skb)
5330d5c65159SKalle Valo {
5331d5c65159SKalle Valo 	const void **tb;
5332d5c65159SKalle Valo 	const struct wmi_pdev_ctl_failsafe_chk_event *ev;
5333d5c65159SKalle Valo 	int ret;
5334d5c65159SKalle Valo 
5335d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5336d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5337d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5338d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5339d5c65159SKalle Valo 		return;
5340d5c65159SKalle Valo 	}
5341d5c65159SKalle Valo 
5342d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
5343d5c65159SKalle Valo 	if (!ev) {
5344d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
5345d5c65159SKalle Valo 		kfree(tb);
5346d5c65159SKalle Valo 		return;
5347d5c65159SKalle Valo 	}
5348d5c65159SKalle Valo 
5349d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5350d5c65159SKalle Valo 		   "pdev ctl failsafe check ev status %d\n",
5351d5c65159SKalle Valo 		   ev->ctl_failsafe_status);
5352d5c65159SKalle Valo 
5353d5c65159SKalle Valo 	/* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
5354d5c65159SKalle Valo 	 * to 10 dBm else the CTL power entry in the BDF would be picked up.
5355d5c65159SKalle Valo 	 */
5356d5c65159SKalle Valo 	if (ev->ctl_failsafe_status != 0)
5357d5c65159SKalle Valo 		ath11k_warn(ab, "pdev ctl failsafe failure status %d",
5358d5c65159SKalle Valo 			    ev->ctl_failsafe_status);
5359d5c65159SKalle Valo 
5360d5c65159SKalle Valo 	kfree(tb);
5361d5c65159SKalle Valo }
5362d5c65159SKalle Valo 
5363d5c65159SKalle Valo static void
5364d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
5365d5c65159SKalle Valo 					  const struct wmi_pdev_csa_switch_ev *ev,
5366d5c65159SKalle Valo 					  const u32 *vdev_ids)
5367d5c65159SKalle Valo {
5368d5c65159SKalle Valo 	int i;
5369d5c65159SKalle Valo 	struct ath11k_vif *arvif;
5370d5c65159SKalle Valo 
5371d5c65159SKalle Valo 	/* Finish CSA once the switch count becomes NULL */
5372d5c65159SKalle Valo 	if (ev->current_switch_count)
5373d5c65159SKalle Valo 		return;
5374d5c65159SKalle Valo 
5375d5c65159SKalle Valo 	rcu_read_lock();
5376d5c65159SKalle Valo 	for (i = 0; i < ev->num_vdevs; i++) {
5377d5c65159SKalle Valo 		arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
5378d5c65159SKalle Valo 
5379d5c65159SKalle Valo 		if (!arvif) {
5380d5c65159SKalle Valo 			ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
5381d5c65159SKalle Valo 				    vdev_ids[i]);
5382d5c65159SKalle Valo 			continue;
5383d5c65159SKalle Valo 		}
5384d5c65159SKalle Valo 
5385d5c65159SKalle Valo 		if (arvif->is_up && arvif->vif->csa_active)
5386d5c65159SKalle Valo 			ieee80211_csa_finish(arvif->vif);
5387d5c65159SKalle Valo 	}
5388d5c65159SKalle Valo 	rcu_read_unlock();
5389d5c65159SKalle Valo }
5390d5c65159SKalle Valo 
5391d5c65159SKalle Valo static void
5392d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
5393d5c65159SKalle Valo 					      struct sk_buff *skb)
5394d5c65159SKalle Valo {
5395d5c65159SKalle Valo 	const void **tb;
5396d5c65159SKalle Valo 	const struct wmi_pdev_csa_switch_ev *ev;
5397d5c65159SKalle Valo 	const u32 *vdev_ids;
5398d5c65159SKalle Valo 	int ret;
5399d5c65159SKalle Valo 
5400d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5401d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5402d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5403d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5404d5c65159SKalle Valo 		return;
5405d5c65159SKalle Valo 	}
5406d5c65159SKalle Valo 
5407d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
5408d5c65159SKalle Valo 	vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
5409d5c65159SKalle Valo 
5410d5c65159SKalle Valo 	if (!ev || !vdev_ids) {
5411d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
5412d5c65159SKalle Valo 		kfree(tb);
5413d5c65159SKalle Valo 		return;
5414d5c65159SKalle Valo 	}
5415d5c65159SKalle Valo 
5416d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5417d5c65159SKalle Valo 		   "pdev csa switch count %d for pdev %d, num_vdevs %d",
5418d5c65159SKalle Valo 		   ev->current_switch_count, ev->pdev_id,
5419d5c65159SKalle Valo 		   ev->num_vdevs);
5420d5c65159SKalle Valo 
5421d5c65159SKalle Valo 	ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
5422d5c65159SKalle Valo 
5423d5c65159SKalle Valo 	kfree(tb);
5424d5c65159SKalle Valo }
5425d5c65159SKalle Valo 
5426d5c65159SKalle Valo static void
5427d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
5428d5c65159SKalle Valo {
5429d5c65159SKalle Valo 	const void **tb;
5430d5c65159SKalle Valo 	const struct wmi_pdev_radar_ev *ev;
5431d5c65159SKalle Valo 	struct ath11k *ar;
5432d5c65159SKalle Valo 	int ret;
5433d5c65159SKalle Valo 
5434d5c65159SKalle Valo 	tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5435d5c65159SKalle Valo 	if (IS_ERR(tb)) {
5436d5c65159SKalle Valo 		ret = PTR_ERR(tb);
5437d5c65159SKalle Valo 		ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5438d5c65159SKalle Valo 		return;
5439d5c65159SKalle Valo 	}
5440d5c65159SKalle Valo 
5441d5c65159SKalle Valo 	ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
5442d5c65159SKalle Valo 
5443d5c65159SKalle Valo 	if (!ev) {
5444d5c65159SKalle Valo 		ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
5445d5c65159SKalle Valo 		kfree(tb);
5446d5c65159SKalle Valo 		return;
5447d5c65159SKalle Valo 	}
5448d5c65159SKalle Valo 
5449d5c65159SKalle Valo 	ath11k_dbg(ab, ATH11K_DBG_WMI,
5450d5c65159SKalle 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",
5451d5c65159SKalle Valo 		   ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
5452d5c65159SKalle Valo 		   ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
5453d5c65159SKalle Valo 		   ev->freq_offset, ev->sidx);
5454d5c65159SKalle Valo 
5455d5c65159SKalle Valo 	ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5456d5c65159SKalle Valo 
5457d5c65159SKalle Valo 	if (!ar) {
5458d5c65159SKalle Valo 		ath11k_warn(ab, "radar detected in invalid pdev %d\n",
5459d5c65159SKalle Valo 			    ev->pdev_id);
5460d5c65159SKalle Valo 		goto exit;
5461d5c65159SKalle Valo 	}
5462d5c65159SKalle Valo 
5463d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
5464d5c65159SKalle Valo 		   ev->pdev_id);
5465d5c65159SKalle Valo 
5466d5c65159SKalle Valo 	if (ar->dfs_block_radar_events)
5467d5c65159SKalle Valo 		ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
5468d5c65159SKalle Valo 	else
5469d5c65159SKalle Valo 		ieee80211_radar_detected(ar->hw);
5470d5c65159SKalle Valo 
5471d5c65159SKalle Valo exit:
5472d5c65159SKalle Valo 	kfree(tb);
5473d5c65159SKalle Valo }
5474d5c65159SKalle Valo 
5475d5c65159SKalle Valo static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
5476d5c65159SKalle Valo {
5477d5c65159SKalle Valo 	struct wmi_cmd_hdr *cmd_hdr;
5478d5c65159SKalle Valo 	enum wmi_tlv_event_id id;
5479d5c65159SKalle Valo 
5480d5c65159SKalle Valo 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5481d5c65159SKalle Valo 	id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
5482d5c65159SKalle Valo 
5483d5c65159SKalle Valo 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5484d5c65159SKalle Valo 		goto out;
5485d5c65159SKalle Valo 
5486d5c65159SKalle Valo 	switch (id) {
5487d5c65159SKalle Valo 		/* Process all the WMI events here */
5488d5c65159SKalle Valo 	case WMI_SERVICE_READY_EVENTID:
5489d5c65159SKalle Valo 		ath11k_service_ready_event(ab, skb);
5490d5c65159SKalle Valo 		break;
5491d5c65159SKalle Valo 	case WMI_SERVICE_READY_EXT_EVENTID:
5492d5c65159SKalle Valo 		ath11k_service_ready_ext_event(ab, skb);
5493d5c65159SKalle Valo 		break;
5494d5c65159SKalle Valo 	case WMI_REG_CHAN_LIST_CC_EVENTID:
5495d5c65159SKalle Valo 		ath11k_reg_chan_list_event(ab, skb);
5496d5c65159SKalle Valo 		break;
5497d5c65159SKalle Valo 	case WMI_READY_EVENTID:
5498d5c65159SKalle Valo 		ath11k_ready_event(ab, skb);
5499d5c65159SKalle Valo 		break;
5500d5c65159SKalle Valo 	case WMI_PEER_DELETE_RESP_EVENTID:
5501d5c65159SKalle Valo 		ath11k_peer_delete_resp_event(ab, skb);
5502d5c65159SKalle Valo 		break;
5503d5c65159SKalle Valo 	case WMI_VDEV_START_RESP_EVENTID:
5504d5c65159SKalle Valo 		ath11k_vdev_start_resp_event(ab, skb);
5505d5c65159SKalle Valo 		break;
5506d5c65159SKalle Valo 	case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
5507d5c65159SKalle Valo 		ath11k_bcn_tx_status_event(ab, skb);
5508d5c65159SKalle Valo 		break;
5509d5c65159SKalle Valo 	case WMI_VDEV_STOPPED_EVENTID:
5510d5c65159SKalle Valo 		ath11k_vdev_stopped_event(ab, skb);
5511d5c65159SKalle Valo 		break;
5512d5c65159SKalle Valo 	case WMI_MGMT_RX_EVENTID:
5513d5c65159SKalle Valo 		ath11k_mgmt_rx_event(ab, skb);
5514d5c65159SKalle Valo 		/* mgmt_rx_event() owns the skb now! */
5515d5c65159SKalle Valo 		return;
5516d5c65159SKalle Valo 	case WMI_MGMT_TX_COMPLETION_EVENTID:
5517d5c65159SKalle Valo 		ath11k_mgmt_tx_compl_event(ab, skb);
5518d5c65159SKalle Valo 		break;
5519d5c65159SKalle Valo 	case WMI_SCAN_EVENTID:
5520d5c65159SKalle Valo 		ath11k_scan_event(ab, skb);
5521d5c65159SKalle Valo 		break;
5522d5c65159SKalle Valo 	case WMI_PEER_STA_KICKOUT_EVENTID:
5523d5c65159SKalle Valo 		ath11k_peer_sta_kickout_event(ab, skb);
5524d5c65159SKalle Valo 		break;
5525d5c65159SKalle Valo 	case WMI_ROAM_EVENTID:
5526d5c65159SKalle Valo 		ath11k_roam_event(ab, skb);
5527d5c65159SKalle Valo 		break;
5528d5c65159SKalle Valo 	case WMI_CHAN_INFO_EVENTID:
5529d5c65159SKalle Valo 		ath11k_chan_info_event(ab, skb);
5530d5c65159SKalle Valo 		break;
5531d5c65159SKalle Valo 	case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
5532d5c65159SKalle Valo 		ath11k_pdev_bss_chan_info_event(ab, skb);
5533d5c65159SKalle Valo 		break;
5534d5c65159SKalle Valo 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
5535d5c65159SKalle Valo 		ath11k_vdev_install_key_compl_event(ab, skb);
5536d5c65159SKalle Valo 		break;
5537d5c65159SKalle Valo 	case WMI_SERVICE_AVAILABLE_EVENTID:
5538d5c65159SKalle Valo 		ath11k_service_available_event(ab, skb);
5539d5c65159SKalle Valo 		break;
5540d5c65159SKalle Valo 	case WMI_PEER_ASSOC_CONF_EVENTID:
5541d5c65159SKalle Valo 		ath11k_peer_assoc_conf_event(ab, skb);
5542d5c65159SKalle Valo 		break;
5543d5c65159SKalle Valo 	case WMI_UPDATE_STATS_EVENTID:
5544d5c65159SKalle Valo 		ath11k_update_stats_event(ab, skb);
5545d5c65159SKalle Valo 		break;
5546d5c65159SKalle Valo 	case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
5547d5c65159SKalle Valo 		ath11k_pdev_ctl_failsafe_check_event(ab, skb);
5548d5c65159SKalle Valo 		break;
5549d5c65159SKalle Valo 	case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
5550d5c65159SKalle Valo 		ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
5551d5c65159SKalle Valo 		break;
5552d5c65159SKalle Valo 	/* add Unsupported events here */
5553d5c65159SKalle Valo 	case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID:
5554d5c65159SKalle Valo 	case WMI_VDEV_DELETE_RESP_EVENTID:
55559cfbae46SJohn Crispin 	case WMI_PEER_OPER_MODE_CHANGE_EVENTID:
55566d293d44SJohn Crispin 	case WMI_TWT_ENABLE_EVENTID:
55576d293d44SJohn Crispin 	case WMI_TWT_DISABLE_EVENTID:
5558d5c65159SKalle Valo 		ath11k_dbg(ab, ATH11K_DBG_WMI,
5559d5c65159SKalle Valo 			   "ignoring unsupported event 0x%x\n", id);
5560d5c65159SKalle Valo 		break;
5561d5c65159SKalle Valo 	case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
5562d5c65159SKalle Valo 		ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
5563d5c65159SKalle Valo 		break;
5564d5c65159SKalle Valo 	/* TODO: Add remaining events */
5565d5c65159SKalle Valo 	default:
5566d5c65159SKalle Valo 		ath11k_warn(ab, "Unknown eventid: 0x%x\n", id);
5567d5c65159SKalle Valo 		break;
5568d5c65159SKalle Valo 	}
5569d5c65159SKalle Valo 
5570d5c65159SKalle Valo out:
5571d5c65159SKalle Valo 	dev_kfree_skb(skb);
5572d5c65159SKalle Valo }
5573d5c65159SKalle Valo 
5574d5c65159SKalle Valo static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
5575d5c65159SKalle Valo 					   u32 pdev_idx)
5576d5c65159SKalle Valo {
5577d5c65159SKalle Valo 	int status;
5578d5c65159SKalle Valo 	u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
5579d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
5580d5c65159SKalle Valo 			 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
5581d5c65159SKalle Valo 
5582d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_req conn_req;
5583d5c65159SKalle Valo 	struct ath11k_htc_svc_conn_resp conn_resp;
5584d5c65159SKalle Valo 
5585d5c65159SKalle Valo 	memset(&conn_req, 0, sizeof(conn_req));
5586d5c65159SKalle Valo 	memset(&conn_resp, 0, sizeof(conn_resp));
5587d5c65159SKalle Valo 
5588d5c65159SKalle Valo 	/* these fields are the same for all service endpoints */
5589d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
5590d5c65159SKalle Valo 	conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
5591d5c65159SKalle Valo 	conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
5592d5c65159SKalle Valo 
5593d5c65159SKalle Valo 	/* connect to control service */
5594d5c65159SKalle Valo 	conn_req.service_id = svc_id[pdev_idx];
5595d5c65159SKalle Valo 
5596d5c65159SKalle Valo 	status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
5597d5c65159SKalle Valo 	if (status) {
5598d5c65159SKalle Valo 		ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
5599d5c65159SKalle Valo 			    status);
5600d5c65159SKalle Valo 		return status;
5601d5c65159SKalle Valo 	}
5602d5c65159SKalle Valo 
5603d5c65159SKalle Valo 	ab->wmi_sc.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
5604d5c65159SKalle Valo 	ab->wmi_sc.wmi[pdev_idx].eid = conn_resp.eid;
5605d5c65159SKalle Valo 	ab->wmi_sc.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
5606d5c65159SKalle Valo 
5607d5c65159SKalle Valo 	return 0;
5608d5c65159SKalle Valo }
5609d5c65159SKalle Valo 
5610d5c65159SKalle Valo static int
5611d5c65159SKalle Valo ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
5612d5c65159SKalle Valo 			      struct wmi_unit_test_cmd ut_cmd,
5613d5c65159SKalle Valo 			      u32 *test_args)
5614d5c65159SKalle Valo {
5615d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi = ar->wmi;
5616d5c65159SKalle Valo 	struct wmi_unit_test_cmd *cmd;
5617d5c65159SKalle Valo 	struct sk_buff *skb;
5618d5c65159SKalle Valo 	struct wmi_tlv *tlv;
5619d5c65159SKalle Valo 	void *ptr;
5620d5c65159SKalle Valo 	u32 *ut_cmd_args;
5621d5c65159SKalle Valo 	int buf_len, arg_len;
5622d5c65159SKalle Valo 	int ret;
5623d5c65159SKalle Valo 	int i;
5624d5c65159SKalle Valo 
5625d5c65159SKalle Valo 	arg_len = sizeof(u32) * ut_cmd.num_args;
5626d5c65159SKalle Valo 	buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
5627d5c65159SKalle Valo 
5628d5c65159SKalle Valo 	skb = ath11k_wmi_alloc_skb(wmi->wmi_sc, buf_len);
5629d5c65159SKalle Valo 	if (!skb)
5630d5c65159SKalle Valo 		return -ENOMEM;
5631d5c65159SKalle Valo 
5632d5c65159SKalle Valo 	cmd = (struct wmi_unit_test_cmd *)skb->data;
5633d5c65159SKalle Valo 	cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
5634d5c65159SKalle Valo 			  FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
5635d5c65159SKalle Valo 
5636d5c65159SKalle Valo 	cmd->vdev_id = ut_cmd.vdev_id;
5637d5c65159SKalle Valo 	cmd->module_id = ut_cmd.module_id;
5638d5c65159SKalle Valo 	cmd->num_args = ut_cmd.num_args;
5639d5c65159SKalle Valo 	cmd->diag_token = ut_cmd.diag_token;
5640d5c65159SKalle Valo 
5641d5c65159SKalle Valo 	ptr = skb->data + sizeof(ut_cmd);
5642d5c65159SKalle Valo 
5643d5c65159SKalle Valo 	tlv = ptr;
5644d5c65159SKalle Valo 	tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
5645d5c65159SKalle Valo 		      FIELD_PREP(WMI_TLV_LEN, arg_len);
5646d5c65159SKalle Valo 
5647d5c65159SKalle Valo 	ptr += TLV_HDR_SIZE;
5648d5c65159SKalle Valo 
5649d5c65159SKalle Valo 	ut_cmd_args = ptr;
5650d5c65159SKalle Valo 	for (i = 0; i < ut_cmd.num_args; i++)
5651d5c65159SKalle Valo 		ut_cmd_args[i] = test_args[i];
5652d5c65159SKalle Valo 
5653d5c65159SKalle Valo 	ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
5654d5c65159SKalle Valo 
5655d5c65159SKalle Valo 	if (ret) {
5656d5c65159SKalle Valo 		ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
5657d5c65159SKalle Valo 			    ret);
5658d5c65159SKalle Valo 		dev_kfree_skb(skb);
5659d5c65159SKalle Valo 	}
5660d5c65159SKalle Valo 
5661d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5662d5c65159SKalle Valo 		   "WMI unit test : module %d vdev %d n_args %d token %d\n",
5663d5c65159SKalle Valo 		   cmd->module_id, cmd->vdev_id, cmd->num_args,
5664d5c65159SKalle Valo 		   cmd->diag_token);
5665d5c65159SKalle Valo 
5666d5c65159SKalle Valo 	return ret;
5667d5c65159SKalle Valo }
5668d5c65159SKalle Valo 
5669d5c65159SKalle Valo int ath11k_wmi_simulate_radar(struct ath11k *ar)
5670d5c65159SKalle Valo {
5671d5c65159SKalle Valo 	struct ath11k_vif *arvif;
5672d5c65159SKalle Valo 	u32 dfs_args[DFS_MAX_TEST_ARGS];
5673d5c65159SKalle Valo 	struct wmi_unit_test_cmd wmi_ut;
5674d5c65159SKalle Valo 	bool arvif_found = false;
5675d5c65159SKalle Valo 
5676d5c65159SKalle Valo 	list_for_each_entry(arvif, &ar->arvifs, list) {
5677d5c65159SKalle Valo 		if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5678d5c65159SKalle Valo 			arvif_found = true;
5679d5c65159SKalle Valo 			break;
5680d5c65159SKalle Valo 		}
5681d5c65159SKalle Valo 	}
5682d5c65159SKalle Valo 
5683d5c65159SKalle Valo 	if (!arvif_found)
5684d5c65159SKalle Valo 		return -EINVAL;
5685d5c65159SKalle Valo 
5686d5c65159SKalle Valo 	dfs_args[DFS_TEST_CMDID] = 0;
5687d5c65159SKalle Valo 	dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
5688d5c65159SKalle Valo 	/* Currently we could pass segment_id(b0 - b1), chirp(b2)
5689d5c65159SKalle Valo 	 * freq offset (b3 - b10) to unit test. For simulation
5690d5c65159SKalle Valo 	 * purpose this can be set to 0 which is valid.
5691d5c65159SKalle Valo 	 */
5692d5c65159SKalle Valo 	dfs_args[DFS_TEST_RADAR_PARAM] = 0;
5693d5c65159SKalle Valo 
5694d5c65159SKalle Valo 	wmi_ut.vdev_id = arvif->vdev_id;
5695d5c65159SKalle Valo 	wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
5696d5c65159SKalle Valo 	wmi_ut.num_args = DFS_MAX_TEST_ARGS;
5697d5c65159SKalle Valo 	wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
5698d5c65159SKalle Valo 
5699d5c65159SKalle Valo 	ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
5700d5c65159SKalle Valo 
5701d5c65159SKalle Valo 	return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
5702d5c65159SKalle Valo }
5703d5c65159SKalle Valo 
5704d5c65159SKalle Valo int ath11k_wmi_connect(struct ath11k_base *ab)
5705d5c65159SKalle Valo {
5706d5c65159SKalle Valo 	u32 i;
5707d5c65159SKalle Valo 	u8 wmi_ep_count;
5708d5c65159SKalle Valo 
5709d5c65159SKalle Valo 	wmi_ep_count = ab->htc.wmi_ep_count;
5710d5c65159SKalle Valo 	if (wmi_ep_count > MAX_RADIOS)
5711d5c65159SKalle Valo 		return -1;
5712d5c65159SKalle Valo 
5713d5c65159SKalle Valo 	for (i = 0; i < wmi_ep_count; i++)
5714d5c65159SKalle Valo 		ath11k_connect_pdev_htc_service(ab, i);
5715d5c65159SKalle Valo 
5716d5c65159SKalle Valo 	return 0;
5717d5c65159SKalle Valo }
5718d5c65159SKalle Valo 
5719d5c65159SKalle Valo static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
5720d5c65159SKalle Valo {
5721d5c65159SKalle Valo 	if (WARN_ON(pdev_id >= MAX_RADIOS))
5722d5c65159SKalle Valo 		return;
5723d5c65159SKalle Valo 
5724d5c65159SKalle Valo 	/* TODO: Deinit any pdev specific wmi resource */
5725d5c65159SKalle Valo }
5726d5c65159SKalle Valo 
5727d5c65159SKalle Valo int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
5728d5c65159SKalle Valo 			   u8 pdev_id)
5729d5c65159SKalle Valo {
5730d5c65159SKalle Valo 	struct ath11k_pdev_wmi *wmi_handle;
5731d5c65159SKalle Valo 
5732d5c65159SKalle Valo 	if (pdev_id >= MAX_RADIOS)
5733d5c65159SKalle Valo 		return -EINVAL;
5734d5c65159SKalle Valo 
5735d5c65159SKalle Valo 	wmi_handle = &ab->wmi_sc.wmi[pdev_id];
5736d5c65159SKalle Valo 
5737d5c65159SKalle Valo 	wmi_handle->wmi_sc = &ab->wmi_sc;
5738d5c65159SKalle Valo 
5739d5c65159SKalle Valo 	ab->wmi_sc.ab = ab;
5740d5c65159SKalle Valo 	/* TODO: Init remaining resource specific to pdev */
5741d5c65159SKalle Valo 
5742d5c65159SKalle Valo 	return 0;
5743d5c65159SKalle Valo }
5744d5c65159SKalle Valo 
5745d5c65159SKalle Valo int ath11k_wmi_attach(struct ath11k_base *ab)
5746d5c65159SKalle Valo {
5747d5c65159SKalle Valo 	int ret;
5748d5c65159SKalle Valo 
5749d5c65159SKalle Valo 	ret = ath11k_wmi_pdev_attach(ab, 0);
5750d5c65159SKalle Valo 	if (ret)
5751d5c65159SKalle Valo 		return ret;
5752d5c65159SKalle Valo 
5753d5c65159SKalle Valo 	ab->wmi_sc.ab = ab;
5754d5c65159SKalle Valo 	ab->wmi_sc.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
5755d5c65159SKalle Valo 
5756d5c65159SKalle Valo 	/* TODO: Init remaining wmi soc resources required */
5757d5c65159SKalle Valo 	init_completion(&ab->wmi_sc.service_ready);
5758d5c65159SKalle Valo 	init_completion(&ab->wmi_sc.unified_ready);
5759d5c65159SKalle Valo 
5760d5c65159SKalle Valo 	return 0;
5761d5c65159SKalle Valo }
5762d5c65159SKalle Valo 
5763d5c65159SKalle Valo void ath11k_wmi_detach(struct ath11k_base *ab)
5764d5c65159SKalle Valo {
5765d5c65159SKalle Valo 	int i;
5766d5c65159SKalle Valo 
5767d5c65159SKalle Valo 	/* TODO: Deinit wmi resource specific to SOC as required */
5768d5c65159SKalle Valo 
5769d5c65159SKalle Valo 	for (i = 0; i < ab->htc.wmi_ep_count; i++)
5770d5c65159SKalle Valo 		ath11k_wmi_pdev_detach(ab, i);
5771d5c65159SKalle Valo }
5772