1d5c65159SKalle Valo // SPDX-License-Identifier: BSD-3-Clause-Clear
2d5c65159SKalle Valo /*
3d5c65159SKalle Valo * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4*586c7fb1SJeff Johnson * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
5d5c65159SKalle Valo */
6d5c65159SKalle Valo #include <linux/skbuff.h>
7d5c65159SKalle Valo #include <linux/ctype.h>
8d5c65159SKalle Valo #include <net/mac80211.h>
9d5c65159SKalle Valo #include <net/cfg80211.h>
10d5c65159SKalle Valo #include <linux/completion.h>
11d5c65159SKalle Valo #include <linux/if_ether.h>
12d5c65159SKalle Valo #include <linux/types.h>
13d5c65159SKalle Valo #include <linux/pci.h>
14d5c65159SKalle Valo #include <linux/uuid.h>
15d5c65159SKalle Valo #include <linux/time.h>
16d5c65159SKalle Valo #include <linux/of.h>
17d5c65159SKalle Valo #include "core.h"
18d5c65159SKalle Valo #include "debug.h"
19d5c65159SKalle Valo #include "mac.h"
20d5c65159SKalle Valo #include "hw.h"
21d5c65159SKalle Valo #include "peer.h"
22b43310e4SGovindaraj Saminathan #include "testmode.h"
23d5c65159SKalle Valo
24d5c65159SKalle Valo struct wmi_tlv_policy {
25d5c65159SKalle Valo size_t min_len;
26d5c65159SKalle Valo };
27d5c65159SKalle Valo
28d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse {
29d5c65159SKalle Valo bool wmi_svc_bitmap_done;
30d5c65159SKalle Valo };
31d5c65159SKalle Valo
32bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse {
33bd647855SKarthikeyan Periyasamy struct wmi_dma_ring_capabilities *dma_ring_caps;
34bd647855SKarthikeyan Periyasamy u32 n_dma_ring_caps;
35bd647855SKarthikeyan Periyasamy };
36bd647855SKarthikeyan Periyasamy
37d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse {
38d5c65159SKalle Valo struct ath11k_service_ext_param param;
39d5c65159SKalle Valo struct wmi_soc_mac_phy_hw_mode_caps *hw_caps;
40d5c65159SKalle Valo struct wmi_hw_mode_capabilities *hw_mode_caps;
41d5c65159SKalle Valo u32 n_hw_mode_caps;
42d5c65159SKalle Valo u32 tot_phy_id;
43d5c65159SKalle Valo struct wmi_hw_mode_capabilities pref_hw_mode_caps;
44d5c65159SKalle Valo struct wmi_mac_phy_capabilities *mac_phy_caps;
45d5c65159SKalle Valo u32 n_mac_phy_caps;
46d5c65159SKalle Valo struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps;
47d5c65159SKalle Valo struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps;
48d5c65159SKalle Valo u32 n_ext_hal_reg_caps;
49bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
50d5c65159SKalle Valo bool hw_mode_done;
51d5c65159SKalle Valo bool mac_phy_done;
52d5c65159SKalle Valo bool ext_hal_reg_done;
53bd647855SKarthikeyan Periyasamy bool mac_phy_chainmask_combo_done;
54bd647855SKarthikeyan Periyasamy bool mac_phy_chainmask_cap_done;
55bd647855SKarthikeyan Periyasamy bool oem_dma_ring_cap_done;
56bd647855SKarthikeyan Periyasamy bool dma_ring_cap_done;
57bd647855SKarthikeyan Periyasamy };
58bd647855SKarthikeyan Periyasamy
59bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse {
60bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
61bd647855SKarthikeyan Periyasamy bool dma_ring_cap_done;
62d5c65159SKalle Valo };
63d5c65159SKalle Valo
64d5c65159SKalle Valo struct wmi_tlv_rdy_parse {
65d5c65159SKalle Valo u32 num_extra_mac_addr;
66d5c65159SKalle Valo };
67d5c65159SKalle Valo
689d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse {
699d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_dma_buf_release_fixed_param fixed;
709d11b7bfSKarthikeyan Periyasamy struct wmi_dma_buf_release_entry *buf_entry;
719d11b7bfSKarthikeyan Periyasamy struct wmi_dma_buf_release_meta_data *meta_data;
729d11b7bfSKarthikeyan Periyasamy u32 num_buf_entry;
739d11b7bfSKarthikeyan Periyasamy u32 num_meta;
749d11b7bfSKarthikeyan Periyasamy bool buf_entry_done;
759d11b7bfSKarthikeyan Periyasamy bool meta_data_done;
769d11b7bfSKarthikeyan Periyasamy };
779d11b7bfSKarthikeyan Periyasamy
78b488c766SWen Gong struct wmi_tlv_fw_stats_parse {
79b488c766SWen Gong const struct wmi_stats_event *ev;
80b488c766SWen Gong const struct wmi_per_chain_rssi_stats *rssi;
81b488c766SWen Gong struct ath11k_fw_stats *stats;
82b488c766SWen Gong int rssi_num;
83b488c766SWen Gong bool chain_rssi_done;
84b488c766SWen Gong };
85b488c766SWen Gong
86447b0398SBhagavathi Perumal S struct wmi_tlv_mgmt_rx_parse {
87447b0398SBhagavathi Perumal S const struct wmi_mgmt_rx_hdr *fixed;
88447b0398SBhagavathi Perumal S const u8 *frame_buf;
89447b0398SBhagavathi Perumal S bool frame_buf_done;
90447b0398SBhagavathi Perumal S };
91447b0398SBhagavathi Perumal S
92d5c65159SKalle Valo static const struct wmi_tlv_policy wmi_tlv_policies[] = {
93d5c65159SKalle Valo [WMI_TAG_ARRAY_BYTE]
94d5c65159SKalle Valo = { .min_len = 0 },
95d5c65159SKalle Valo [WMI_TAG_ARRAY_UINT32]
96d5c65159SKalle Valo = { .min_len = 0 },
97d5c65159SKalle Valo [WMI_TAG_SERVICE_READY_EVENT]
98d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_service_ready_event) },
99d5c65159SKalle Valo [WMI_TAG_SERVICE_READY_EXT_EVENT]
100d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_service_ready_ext_event) },
101d5c65159SKalle Valo [WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS]
102d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) },
103d5c65159SKalle Valo [WMI_TAG_SOC_HAL_REG_CAPABILITIES]
104d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) },
105d5c65159SKalle Valo [WMI_TAG_VDEV_START_RESPONSE_EVENT]
106d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_vdev_start_resp_event) },
107d5c65159SKalle Valo [WMI_TAG_PEER_DELETE_RESP_EVENT]
108d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_peer_delete_resp_event) },
109d5c65159SKalle Valo [WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]
110d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_bcn_tx_status_event) },
111d5c65159SKalle Valo [WMI_TAG_VDEV_STOPPED_EVENT]
112d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_vdev_stopped_event) },
113d5c65159SKalle Valo [WMI_TAG_REG_CHAN_LIST_CC_EVENT]
114d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) },
11591fa00faSAditya Kumar Singh [WMI_TAG_REG_CHAN_LIST_CC_EXT_EVENT]
11691fa00faSAditya Kumar Singh = { .min_len = sizeof(struct wmi_reg_chan_list_cc_ext_event) },
117d5c65159SKalle Valo [WMI_TAG_MGMT_RX_HDR]
118d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_mgmt_rx_hdr) },
119d5c65159SKalle Valo [WMI_TAG_MGMT_TX_COMPL_EVENT]
120d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) },
121d5c65159SKalle Valo [WMI_TAG_SCAN_EVENT]
122d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_scan_event) },
123d5c65159SKalle Valo [WMI_TAG_PEER_STA_KICKOUT_EVENT]
124d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
125d5c65159SKalle Valo [WMI_TAG_ROAM_EVENT]
126d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_roam_event) },
127d5c65159SKalle Valo [WMI_TAG_CHAN_INFO_EVENT]
128d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_chan_info_event) },
129d5c65159SKalle Valo [WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]
130d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) },
131d5c65159SKalle Valo [WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]
132d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) },
13321c1b063SMaharaja Kennadyrajan [WMI_TAG_READY_EVENT] = {
13421c1b063SMaharaja Kennadyrajan .min_len = sizeof(struct wmi_ready_event_min) },
135d5c65159SKalle Valo [WMI_TAG_SERVICE_AVAILABLE_EVENT]
136d5c65159SKalle Valo = {.min_len = sizeof(struct wmi_service_available_event) },
137d5c65159SKalle Valo [WMI_TAG_PEER_ASSOC_CONF_EVENT]
138d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_peer_assoc_conf_event) },
139d5c65159SKalle Valo [WMI_TAG_STATS_EVENT]
140d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_stats_event) },
141d5c65159SKalle Valo [WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]
142d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) },
143047679e3SAloka Dixit [WMI_TAG_HOST_SWFDA_EVENT] = {
144047679e3SAloka Dixit .min_len = sizeof(struct wmi_fils_discovery_event) },
145047679e3SAloka Dixit [WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT] = {
146047679e3SAloka Dixit .min_len = sizeof(struct wmi_probe_resp_tx_status_event) },
1473cbbdfbeSRitesh Singh [WMI_TAG_VDEV_DELETE_RESP_EVENT] = {
1483cbbdfbeSRitesh Singh .min_len = sizeof(struct wmi_vdev_delete_resp_event) },
149886433a9SJohn Crispin [WMI_TAG_OBSS_COLOR_COLLISION_EVT] = {
150886433a9SJohn Crispin .min_len = sizeof(struct wmi_obss_color_collision_event) },
1519dcf6808SWen Gong [WMI_TAG_11D_NEW_COUNTRY_EVENT] = {
1529dcf6808SWen Gong .min_len = sizeof(struct wmi_11d_new_cc_ev) },
153b488c766SWen Gong [WMI_TAG_PER_CHAIN_RSSI_STATS] = {
154b488c766SWen Gong .min_len = sizeof(struct wmi_per_chain_rssi_stats) },
1553d00e8b5SJohn Crispin [WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT] = {
1563d00e8b5SJohn Crispin .min_len = sizeof(struct wmi_twt_add_dialog_event) },
157d5c65159SKalle Valo };
158d5c65159SKalle Valo
159d5c65159SKalle Valo #define PRIMAP(_hw_mode_) \
160d5c65159SKalle Valo [_hw_mode_] = _hw_mode_##_PRI
161d5c65159SKalle Valo
162d5c65159SKalle Valo static const int ath11k_hw_mode_pri_map[] = {
163d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_SINGLE),
164d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_DBS),
165d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE),
166d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_SBS),
167d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_DBS_SBS),
168d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS),
169d5c65159SKalle Valo /* keep last */
170d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_MAX),
171d5c65159SKalle Valo };
172d5c65159SKalle Valo
173d5c65159SKalle Valo static int
ath11k_wmi_tlv_iter(struct ath11k_base * ab,const void * ptr,size_t len,int (* iter)(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data),void * data)174d5c65159SKalle Valo ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
175d5c65159SKalle Valo int (*iter)(struct ath11k_base *ab, u16 tag, u16 len,
176d5c65159SKalle Valo const void *ptr, void *data),
177d5c65159SKalle Valo void *data)
178d5c65159SKalle Valo {
179d5c65159SKalle Valo const void *begin = ptr;
180d5c65159SKalle Valo const struct wmi_tlv *tlv;
181d5c65159SKalle Valo u16 tlv_tag, tlv_len;
182d5c65159SKalle Valo int ret;
183d5c65159SKalle Valo
184d5c65159SKalle Valo while (len > 0) {
185d5c65159SKalle Valo if (len < sizeof(*tlv)) {
186d5c65159SKalle Valo ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
187d5c65159SKalle Valo ptr - begin, len, sizeof(*tlv));
188d5c65159SKalle Valo return -EINVAL;
189d5c65159SKalle Valo }
190d5c65159SKalle Valo
191d5c65159SKalle Valo tlv = ptr;
192d5c65159SKalle Valo tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header);
193d5c65159SKalle Valo tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header);
194d5c65159SKalle Valo ptr += sizeof(*tlv);
195d5c65159SKalle Valo len -= sizeof(*tlv);
196d5c65159SKalle Valo
197d5c65159SKalle Valo if (tlv_len > len) {
198bb2d2dfdSTom Rix ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n",
199d5c65159SKalle Valo tlv_tag, ptr - begin, len, tlv_len);
200d5c65159SKalle Valo return -EINVAL;
201d5c65159SKalle Valo }
202d5c65159SKalle Valo
203d5c65159SKalle Valo if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
204d5c65159SKalle Valo wmi_tlv_policies[tlv_tag].min_len &&
205d5c65159SKalle Valo wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
206bb2d2dfdSTom Rix ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%u bytes is less than min length %zu)\n",
207d5c65159SKalle Valo tlv_tag, ptr - begin, tlv_len,
208d5c65159SKalle Valo wmi_tlv_policies[tlv_tag].min_len);
209d5c65159SKalle Valo return -EINVAL;
210d5c65159SKalle Valo }
211d5c65159SKalle Valo
212d5c65159SKalle Valo ret = iter(ab, tlv_tag, tlv_len, ptr, data);
213d5c65159SKalle Valo if (ret)
214d5c65159SKalle Valo return ret;
215d5c65159SKalle Valo
216d5c65159SKalle Valo ptr += tlv_len;
217d5c65159SKalle Valo len -= tlv_len;
218d5c65159SKalle Valo }
219d5c65159SKalle Valo
220d5c65159SKalle Valo return 0;
221d5c65159SKalle Valo }
222d5c65159SKalle Valo
ath11k_wmi_tlv_iter_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)223d5c65159SKalle Valo static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len,
224d5c65159SKalle Valo const void *ptr, void *data)
225d5c65159SKalle Valo {
226d5c65159SKalle Valo const void **tb = data;
227d5c65159SKalle Valo
228d5c65159SKalle Valo if (tag < WMI_TAG_MAX)
229d5c65159SKalle Valo tb[tag] = ptr;
230d5c65159SKalle Valo
231d5c65159SKalle Valo return 0;
232d5c65159SKalle Valo }
233d5c65159SKalle Valo
ath11k_wmi_tlv_parse(struct ath11k_base * ar,const void ** tb,const void * ptr,size_t len)234d5c65159SKalle Valo static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb,
235d5c65159SKalle Valo const void *ptr, size_t len)
236d5c65159SKalle Valo {
237d5c65159SKalle Valo return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse,
238d5c65159SKalle Valo (void *)tb);
239d5c65159SKalle Valo }
240d5c65159SKalle Valo
ath11k_wmi_tlv_parse_alloc(struct ath11k_base * ab,const void * ptr,size_t len,gfp_t gfp)241b43310e4SGovindaraj Saminathan const void **ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr,
242d5c65159SKalle Valo size_t len, gfp_t gfp)
243d5c65159SKalle Valo {
244d5c65159SKalle Valo const void **tb;
245d5c65159SKalle Valo int ret;
246d5c65159SKalle Valo
247d5c65159SKalle Valo tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp);
248d5c65159SKalle Valo if (!tb)
249d5c65159SKalle Valo return ERR_PTR(-ENOMEM);
250d5c65159SKalle Valo
251d5c65159SKalle Valo ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len);
252d5c65159SKalle Valo if (ret) {
253d5c65159SKalle Valo kfree(tb);
254d5c65159SKalle Valo return ERR_PTR(ret);
255d5c65159SKalle Valo }
256d5c65159SKalle Valo
257d5c65159SKalle Valo return tb;
258d5c65159SKalle Valo }
259d5c65159SKalle Valo
ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi * wmi,struct sk_buff * skb,u32 cmd_id)260d5c65159SKalle Valo static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
261d5c65159SKalle Valo u32 cmd_id)
262d5c65159SKalle Valo {
263d5c65159SKalle Valo struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
2646bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
265d5c65159SKalle Valo struct wmi_cmd_hdr *cmd_hdr;
266d5c65159SKalle Valo int ret;
267d5c65159SKalle Valo u32 cmd = 0;
268d5c65159SKalle Valo
269d5c65159SKalle Valo if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
270d5c65159SKalle Valo return -ENOMEM;
271d5c65159SKalle Valo
272d5c65159SKalle Valo cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id);
273d5c65159SKalle Valo
274d5c65159SKalle Valo cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
275d5c65159SKalle Valo cmd_hdr->cmd_id = cmd;
276d5c65159SKalle Valo
277fb12305aSVenkateswara Naralasetty trace_ath11k_wmi_cmd(ab, cmd_id, skb->data, skb->len);
278fb12305aSVenkateswara Naralasetty
279d5c65159SKalle Valo memset(skb_cb, 0, sizeof(*skb_cb));
280d5c65159SKalle Valo ret = ath11k_htc_send(&ab->htc, wmi->eid, skb);
281d5c65159SKalle Valo
282d5c65159SKalle Valo if (ret)
283d5c65159SKalle Valo goto err_pull;
284d5c65159SKalle Valo
285d5c65159SKalle Valo return 0;
286d5c65159SKalle Valo
287d5c65159SKalle Valo err_pull:
288d5c65159SKalle Valo skb_pull(skb, sizeof(struct wmi_cmd_hdr));
289d5c65159SKalle Valo return ret;
290d5c65159SKalle Valo }
291d5c65159SKalle Valo
ath11k_wmi_cmd_send(struct ath11k_pdev_wmi * wmi,struct sk_buff * skb,u32 cmd_id)292d5c65159SKalle Valo int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
293d5c65159SKalle Valo u32 cmd_id)
294d5c65159SKalle Valo {
2956bc9d6f7SJohn Crispin struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab;
296d5c65159SKalle Valo int ret = -EOPNOTSUPP;
297f951380aSP Praneesh struct ath11k_base *ab = wmi_sc->ab;
298d5c65159SKalle Valo
299d5c65159SKalle Valo might_sleep();
300d5c65159SKalle Valo
301f951380aSP Praneesh if (ab->hw_params.credit_flow) {
302d5c65159SKalle Valo wait_event_timeout(wmi_sc->tx_credits_wq, ({
303d5c65159SKalle Valo ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
304d5c65159SKalle Valo
305f951380aSP Praneesh if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
306f951380aSP Praneesh &wmi_sc->ab->dev_flags))
307d5c65159SKalle Valo ret = -ESHUTDOWN;
308d5c65159SKalle Valo
309d5c65159SKalle Valo (ret != -EAGAIN);
310d5c65159SKalle Valo }), WMI_SEND_TIMEOUT_HZ);
311f951380aSP Praneesh } else {
312f951380aSP Praneesh wait_event_timeout(wmi->tx_ce_desc_wq, ({
313f951380aSP Praneesh ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
314f951380aSP Praneesh
315f951380aSP Praneesh if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
316f951380aSP Praneesh &wmi_sc->ab->dev_flags))
317f951380aSP Praneesh ret = -ESHUTDOWN;
318f951380aSP Praneesh
319f951380aSP Praneesh (ret != -ENOBUFS);
320f951380aSP Praneesh }), WMI_SEND_TIMEOUT_HZ);
321f951380aSP Praneesh }
322d5c65159SKalle Valo
323d5c65159SKalle Valo if (ret == -EAGAIN)
324d5c65159SKalle Valo ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id);
325d5c65159SKalle Valo
326f951380aSP Praneesh if (ret == -ENOBUFS)
327f951380aSP Praneesh ath11k_warn(wmi_sc->ab, "ce desc not available for wmi command %d\n",
328f951380aSP Praneesh cmd_id);
329f951380aSP Praneesh
330d5c65159SKalle Valo return ret;
331d5c65159SKalle Valo }
332d5c65159SKalle Valo
ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi * wmi_handle,const void * ptr,struct ath11k_service_ext_param * param)333d5c65159SKalle Valo static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
334d5c65159SKalle Valo const void *ptr,
335d5c65159SKalle Valo struct ath11k_service_ext_param *param)
336d5c65159SKalle Valo {
337d5c65159SKalle Valo const struct wmi_service_ready_ext_event *ev = ptr;
338d5c65159SKalle Valo
339d5c65159SKalle Valo if (!ev)
340d5c65159SKalle Valo return -EINVAL;
341d5c65159SKalle Valo
342d5c65159SKalle Valo /* Move this to host based bitmap */
343d5c65159SKalle Valo param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits;
344d5c65159SKalle Valo param->default_fw_config_bits = ev->default_fw_config_bits;
345d5c65159SKalle Valo param->he_cap_info = ev->he_cap_info;
346d5c65159SKalle Valo param->mpdu_density = ev->mpdu_density;
347d5c65159SKalle Valo param->max_bssid_rx_filters = ev->max_bssid_rx_filters;
348d5c65159SKalle Valo memcpy(¶m->ppet, &ev->ppet, sizeof(param->ppet));
349d5c65159SKalle Valo
350d5c65159SKalle Valo return 0;
351d5c65159SKalle Valo }
352d5c65159SKalle Valo
353d5c65159SKalle Valo static int
ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi * wmi_handle,struct wmi_soc_mac_phy_hw_mode_caps * hw_caps,struct wmi_hw_mode_capabilities * wmi_hw_mode_caps,struct wmi_soc_hal_reg_capabilities * hal_reg_caps,struct wmi_mac_phy_capabilities * wmi_mac_phy_caps,u8 hw_mode_id,u8 phy_id,struct ath11k_pdev * pdev)354d5c65159SKalle Valo ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
355d5c65159SKalle Valo struct wmi_soc_mac_phy_hw_mode_caps *hw_caps,
356d5c65159SKalle Valo struct wmi_hw_mode_capabilities *wmi_hw_mode_caps,
357d5c65159SKalle Valo struct wmi_soc_hal_reg_capabilities *hal_reg_caps,
358d5c65159SKalle Valo struct wmi_mac_phy_capabilities *wmi_mac_phy_caps,
359d5c65159SKalle Valo u8 hw_mode_id, u8 phy_id,
360d5c65159SKalle Valo struct ath11k_pdev *pdev)
361d5c65159SKalle Valo {
362d5c65159SKalle Valo struct wmi_mac_phy_capabilities *mac_phy_caps;
36313706340SWen Gong struct ath11k_base *ab = wmi_handle->wmi_ab->ab;
364d5c65159SKalle Valo struct ath11k_band_cap *cap_band;
365d5c65159SKalle Valo struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
366d5c65159SKalle Valo u32 phy_map;
367d5c65159SKalle Valo u32 hw_idx, phy_idx = 0;
368d5c65159SKalle Valo
369d5c65159SKalle Valo if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps)
370d5c65159SKalle Valo return -EINVAL;
371d5c65159SKalle Valo
372d5c65159SKalle Valo for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) {
373d5c65159SKalle Valo if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id)
374d5c65159SKalle Valo break;
375d5c65159SKalle Valo
376d5c65159SKalle Valo phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map;
377d5c65159SKalle Valo while (phy_map) {
378d5c65159SKalle Valo phy_map >>= 1;
379d5c65159SKalle Valo phy_idx++;
380d5c65159SKalle Valo }
381d5c65159SKalle Valo }
382d5c65159SKalle Valo
383d5c65159SKalle Valo if (hw_idx == hw_caps->num_hw_modes)
384d5c65159SKalle Valo return -EINVAL;
385d5c65159SKalle Valo
386d5c65159SKalle Valo phy_idx += phy_id;
387d5c65159SKalle Valo if (phy_id >= hal_reg_caps->num_phy)
388d5c65159SKalle Valo return -EINVAL;
389d5c65159SKalle Valo
3905b90fc76SAnilkumar Kolli mac_phy_caps = wmi_mac_phy_caps + phy_idx;
391d5c65159SKalle Valo
392d5c65159SKalle Valo pdev->pdev_id = mac_phy_caps->pdev_id;
3935f859bc0SCarl Huang pdev_cap->supported_bands |= mac_phy_caps->supported_bands;
394d5c65159SKalle Valo pdev_cap->ampdu_density = mac_phy_caps->ampdu_density;
39513706340SWen Gong ab->target_pdev_ids[ab->target_pdev_count].supported_bands =
39613706340SWen Gong mac_phy_caps->supported_bands;
39713706340SWen Gong ab->target_pdev_ids[ab->target_pdev_count].pdev_id = mac_phy_caps->pdev_id;
39813706340SWen Gong ab->target_pdev_count++;
399d5c65159SKalle Valo
40095959d70SManikanta Pubbisetty if (!(mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) &&
40195959d70SManikanta Pubbisetty !(mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP))
40295959d70SManikanta Pubbisetty return -EINVAL;
40395959d70SManikanta Pubbisetty
404d5c65159SKalle Valo /* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from
405d5c65159SKalle Valo * band to band for a single radio, need to see how this should be
406d5c65159SKalle Valo * handled.
407d5c65159SKalle Valo */
408d5c65159SKalle Valo if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
409d5c65159SKalle Valo pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g;
410d5c65159SKalle Valo pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g;
41195959d70SManikanta Pubbisetty }
41295959d70SManikanta Pubbisetty
41395959d70SManikanta Pubbisetty if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
414d5c65159SKalle Valo pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g;
415d5c65159SKalle Valo pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g;
416d5c65159SKalle Valo pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g;
417d5c65159SKalle Valo pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g;
418d5c65159SKalle Valo pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g;
419f552d6fdSP Praneesh pdev_cap->nss_ratio_enabled =
420f552d6fdSP Praneesh WMI_NSS_RATIO_ENABLE_DISABLE_GET(mac_phy_caps->nss_ratio);
421f552d6fdSP Praneesh pdev_cap->nss_ratio_info =
422f552d6fdSP Praneesh WMI_NSS_RATIO_INFO_GET(mac_phy_caps->nss_ratio);
423d5c65159SKalle Valo }
424d5c65159SKalle Valo
425d5c65159SKalle Valo /* tx/rx chainmask reported from fw depends on the actual hw chains used,
426d5c65159SKalle Valo * For example, for 4x4 capable macphys, first 4 chains can be used for first
4273fecca0eSJeff Johnson * mac and the remaining 4 chains can be used for the second mac or vice-versa.
428d5c65159SKalle Valo * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0
42916f283f0SKalle Valo * will be advertised for second mac or vice-versa. Compute the shift value
430d5c65159SKalle Valo * for tx/rx chainmask which will be used to advertise supported ht/vht rates to
431d5c65159SKalle Valo * mac80211.
432d5c65159SKalle Valo */
433d5c65159SKalle Valo pdev_cap->tx_chain_mask_shift =
434d5c65159SKalle Valo find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32);
435d5c65159SKalle Valo pdev_cap->rx_chain_mask_shift =
436d5c65159SKalle Valo find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32);
437d5c65159SKalle Valo
4385f859bc0SCarl Huang if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
439d5c65159SKalle Valo cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
4405f859bc0SCarl Huang cap_band->phy_id = mac_phy_caps->phy_id;
441d5c65159SKalle Valo cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g;
442d5c65159SKalle Valo cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g;
443d5c65159SKalle Valo cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g;
444d5c65159SKalle Valo cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext;
445d5c65159SKalle Valo cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g;
446d5c65159SKalle Valo memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g,
447d5c65159SKalle Valo sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
448d5c65159SKalle Valo memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g,
449d5c65159SKalle Valo sizeof(struct ath11k_ppe_threshold));
4505f859bc0SCarl Huang }
451d5c65159SKalle Valo
4525f859bc0SCarl Huang if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
453d5c65159SKalle Valo cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
4545f859bc0SCarl Huang cap_band->phy_id = mac_phy_caps->phy_id;
455d5c65159SKalle Valo cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
456d5c65159SKalle Valo cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
457d5c65159SKalle Valo cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
458d5c65159SKalle Valo cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
459d5c65159SKalle Valo cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
460d5c65159SKalle Valo memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
461d5c65159SKalle Valo sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
462d5c65159SKalle Valo memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
463d5c65159SKalle Valo sizeof(struct ath11k_ppe_threshold));
464d5c65159SKalle Valo
46522eeadcdSPradeep Kumar Chitrapu cap_band = &pdev_cap->band[NL80211_BAND_6GHZ];
46622eeadcdSPradeep Kumar Chitrapu cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
46722eeadcdSPradeep Kumar Chitrapu cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
46822eeadcdSPradeep Kumar Chitrapu cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
46922eeadcdSPradeep Kumar Chitrapu cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
47022eeadcdSPradeep Kumar Chitrapu cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
47122eeadcdSPradeep Kumar Chitrapu memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
47222eeadcdSPradeep Kumar Chitrapu sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
47322eeadcdSPradeep Kumar Chitrapu memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
47422eeadcdSPradeep Kumar Chitrapu sizeof(struct ath11k_ppe_threshold));
4750f17ae43SWen Gong }
47622eeadcdSPradeep Kumar Chitrapu
477d5c65159SKalle Valo return 0;
478d5c65159SKalle Valo }
479d5c65159SKalle Valo
480d5c65159SKalle Valo static int
ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi * wmi_handle,struct wmi_soc_hal_reg_capabilities * reg_caps,struct wmi_hal_reg_capabilities_ext * wmi_ext_reg_cap,u8 phy_idx,struct ath11k_hal_reg_capabilities_ext * param)481d5c65159SKalle Valo ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle,
482d5c65159SKalle Valo struct wmi_soc_hal_reg_capabilities *reg_caps,
483d5c65159SKalle Valo struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap,
484d5c65159SKalle Valo u8 phy_idx,
485d5c65159SKalle Valo struct ath11k_hal_reg_capabilities_ext *param)
486d5c65159SKalle Valo {
487d5c65159SKalle Valo struct wmi_hal_reg_capabilities_ext *ext_reg_cap;
488d5c65159SKalle Valo
489d5c65159SKalle Valo if (!reg_caps || !wmi_ext_reg_cap)
490d5c65159SKalle Valo return -EINVAL;
491d5c65159SKalle Valo
492d5c65159SKalle Valo if (phy_idx >= reg_caps->num_phy)
493d5c65159SKalle Valo return -EINVAL;
494d5c65159SKalle Valo
495d5c65159SKalle Valo ext_reg_cap = &wmi_ext_reg_cap[phy_idx];
496d5c65159SKalle Valo
497d5c65159SKalle Valo param->phy_id = ext_reg_cap->phy_id;
498d5c65159SKalle Valo param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain;
499d5c65159SKalle Valo param->eeprom_reg_domain_ext =
500d5c65159SKalle Valo ext_reg_cap->eeprom_reg_domain_ext;
501d5c65159SKalle Valo param->regcap1 = ext_reg_cap->regcap1;
502d5c65159SKalle Valo param->regcap2 = ext_reg_cap->regcap2;
503d5c65159SKalle Valo /* check if param->wireless_mode is needed */
504d5c65159SKalle Valo param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan;
505d5c65159SKalle Valo param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan;
506d5c65159SKalle Valo param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan;
507d5c65159SKalle Valo param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan;
508d5c65159SKalle Valo
509d5c65159SKalle Valo return 0;
510d5c65159SKalle Valo }
511d5c65159SKalle Valo
ath11k_pull_service_ready_tlv(struct ath11k_base * ab,const void * evt_buf,struct ath11k_targ_cap * cap)512d5c65159SKalle Valo static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab,
513d5c65159SKalle Valo const void *evt_buf,
514d5c65159SKalle Valo struct ath11k_targ_cap *cap)
515d5c65159SKalle Valo {
516d5c65159SKalle Valo const struct wmi_service_ready_event *ev = evt_buf;
517d5c65159SKalle Valo
518d5c65159SKalle Valo if (!ev) {
519d5c65159SKalle Valo ath11k_err(ab, "%s: failed by NULL param\n",
520d5c65159SKalle Valo __func__);
521d5c65159SKalle Valo return -EINVAL;
522d5c65159SKalle Valo }
523d5c65159SKalle Valo
524d5c65159SKalle Valo cap->phy_capability = ev->phy_capability;
525d5c65159SKalle Valo cap->max_frag_entry = ev->max_frag_entry;
526d5c65159SKalle Valo cap->num_rf_chains = ev->num_rf_chains;
527d5c65159SKalle Valo cap->ht_cap_info = ev->ht_cap_info;
528d5c65159SKalle Valo cap->vht_cap_info = ev->vht_cap_info;
529d5c65159SKalle Valo cap->vht_supp_mcs = ev->vht_supp_mcs;
530d5c65159SKalle Valo cap->hw_min_tx_power = ev->hw_min_tx_power;
531d5c65159SKalle Valo cap->hw_max_tx_power = ev->hw_max_tx_power;
532d5c65159SKalle Valo cap->sys_cap_info = ev->sys_cap_info;
533d5c65159SKalle Valo cap->min_pkt_size_enable = ev->min_pkt_size_enable;
534d5c65159SKalle Valo cap->max_bcn_ie_size = ev->max_bcn_ie_size;
535d5c65159SKalle Valo cap->max_num_scan_channels = ev->max_num_scan_channels;
536d5c65159SKalle Valo cap->max_supported_macs = ev->max_supported_macs;
537d5c65159SKalle Valo cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps;
538d5c65159SKalle Valo cap->txrx_chainmask = ev->txrx_chainmask;
539d5c65159SKalle Valo cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index;
540d5c65159SKalle Valo cap->num_msdu_desc = ev->num_msdu_desc;
541d5c65159SKalle Valo
542d5c65159SKalle Valo return 0;
543d5c65159SKalle Valo }
544d5c65159SKalle Valo
545d5c65159SKalle Valo /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in
546d5c65159SKalle Valo * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each
547d5c65159SKalle Valo * 4-byte word.
548d5c65159SKalle Valo */
ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi * wmi,const u32 * wmi_svc_bm)549d5c65159SKalle Valo static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi,
550d5c65159SKalle Valo const u32 *wmi_svc_bm)
551d5c65159SKalle Valo {
552d5c65159SKalle Valo int i, j;
553d5c65159SKalle Valo
554d5c65159SKalle Valo for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) {
555d5c65159SKalle Valo do {
556d5c65159SKalle Valo if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32))
5576bc9d6f7SJohn Crispin set_bit(j, wmi->wmi_ab->svc_map);
558d5c65159SKalle Valo } while (++j % WMI_SERVICE_BITS_IN_SIZE32);
559d5c65159SKalle Valo }
560d5c65159SKalle Valo }
561d5c65159SKalle Valo
ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)562d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
563d5c65159SKalle Valo const void *ptr, void *data)
564d5c65159SKalle Valo {
565d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse *svc_ready = data;
5666bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
567d5c65159SKalle Valo u16 expect_len;
568d5c65159SKalle Valo
569d5c65159SKalle Valo switch (tag) {
570d5c65159SKalle Valo case WMI_TAG_SERVICE_READY_EVENT:
571d5c65159SKalle Valo if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps))
572d5c65159SKalle Valo return -EINVAL;
573d5c65159SKalle Valo break;
574d5c65159SKalle Valo
575d5c65159SKalle Valo case WMI_TAG_ARRAY_UINT32:
576d5c65159SKalle Valo if (!svc_ready->wmi_svc_bitmap_done) {
577d5c65159SKalle Valo expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32);
578d5c65159SKalle Valo if (len < expect_len) {
579d5c65159SKalle Valo ath11k_warn(ab, "invalid len %d for the tag 0x%x\n",
580d5c65159SKalle Valo len, tag);
581d5c65159SKalle Valo return -EINVAL;
582d5c65159SKalle Valo }
583d5c65159SKalle Valo
584d5c65159SKalle Valo ath11k_wmi_service_bitmap_copy(wmi_handle, ptr);
585d5c65159SKalle Valo
586d5c65159SKalle Valo svc_ready->wmi_svc_bitmap_done = true;
587d5c65159SKalle Valo }
588d5c65159SKalle Valo break;
589d5c65159SKalle Valo default:
590d5c65159SKalle Valo break;
591d5c65159SKalle Valo }
592d5c65159SKalle Valo
593d5c65159SKalle Valo return 0;
594d5c65159SKalle Valo }
595d5c65159SKalle Valo
ath11k_service_ready_event(struct ath11k_base * ab,struct sk_buff * skb)596d5c65159SKalle Valo static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
597d5c65159SKalle Valo {
598d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse svc_ready = { };
599d5c65159SKalle Valo int ret;
600d5c65159SKalle Valo
601d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
602d5c65159SKalle Valo ath11k_wmi_tlv_svc_rdy_parse,
603d5c65159SKalle Valo &svc_ready);
604d5c65159SKalle Valo if (ret) {
605d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret);
606d5c65159SKalle Valo return ret;
607d5c65159SKalle Valo }
608d5c65159SKalle Valo
609e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event service ready");
610e5df1577SKalle Valo
611d5c65159SKalle Valo return 0;
612d5c65159SKalle Valo }
613d5c65159SKalle Valo
ath11k_wmi_alloc_skb(struct ath11k_wmi_base * wmi_sc,u32 len)614d5c65159SKalle Valo struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len)
615d5c65159SKalle Valo {
616d5c65159SKalle Valo struct sk_buff *skb;
617d5c65159SKalle Valo struct ath11k_base *ab = wmi_sc->ab;
618d5c65159SKalle Valo u32 round_len = roundup(len, 4);
619d5c65159SKalle Valo
620d5c65159SKalle Valo skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len);
621d5c65159SKalle Valo if (!skb)
622d5c65159SKalle Valo return NULL;
623d5c65159SKalle Valo
624d5c65159SKalle Valo skb_reserve(skb, WMI_SKB_HEADROOM);
625d5c65159SKalle Valo if (!IS_ALIGNED((unsigned long)skb->data, 4))
626d5c65159SKalle Valo ath11k_warn(ab, "unaligned WMI skb data\n");
627d5c65159SKalle Valo
628d5c65159SKalle Valo skb_put(skb, round_len);
629d5c65159SKalle Valo memset(skb->data, 0, round_len);
630d5c65159SKalle Valo
631d5c65159SKalle Valo return skb;
632d5c65159SKalle Valo }
633d5c65159SKalle Valo
ath11k_wmi_mgmt_get_freq(struct ath11k * ar,struct ieee80211_tx_info * info)6341d7f5145SBaochen Qiang static u32 ath11k_wmi_mgmt_get_freq(struct ath11k *ar,
6351d7f5145SBaochen Qiang struct ieee80211_tx_info *info)
6361d7f5145SBaochen Qiang {
6371d7f5145SBaochen Qiang struct ath11k_base *ab = ar->ab;
6381d7f5145SBaochen Qiang u32 freq = 0;
6391d7f5145SBaochen Qiang
6401d7f5145SBaochen Qiang if (ab->hw_params.support_off_channel_tx &&
6411d7f5145SBaochen Qiang ar->scan.is_roc &&
6421d7f5145SBaochen Qiang (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
6431d7f5145SBaochen Qiang freq = ar->scan.roc_freq;
6441d7f5145SBaochen Qiang
6451d7f5145SBaochen Qiang return freq;
6461d7f5145SBaochen Qiang }
6471d7f5145SBaochen Qiang
ath11k_wmi_mgmt_send(struct ath11k * ar,u32 vdev_id,u32 buf_id,struct sk_buff * frame)648d5c65159SKalle Valo int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id,
649d5c65159SKalle Valo struct sk_buff *frame)
650d5c65159SKalle Valo {
651d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
6521d7f5145SBaochen Qiang struct ieee80211_tx_info *info = IEEE80211_SKB_CB(frame);
653d5c65159SKalle Valo struct wmi_mgmt_send_cmd *cmd;
654d5c65159SKalle Valo struct wmi_tlv *frame_tlv;
655d5c65159SKalle Valo struct sk_buff *skb;
656d5c65159SKalle Valo u32 buf_len;
657d5c65159SKalle Valo int ret, len;
658d5c65159SKalle Valo
659d5c65159SKalle Valo buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ?
660d5c65159SKalle Valo frame->len : WMI_MGMT_SEND_DOWNLD_LEN;
661d5c65159SKalle Valo
662d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4);
663d5c65159SKalle Valo
6646bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
665d5c65159SKalle Valo if (!skb)
666d5c65159SKalle Valo return -ENOMEM;
667d5c65159SKalle Valo
668d5c65159SKalle Valo cmd = (struct wmi_mgmt_send_cmd *)skb->data;
669d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) |
670d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
671d5c65159SKalle Valo cmd->vdev_id = vdev_id;
672d5c65159SKalle Valo cmd->desc_id = buf_id;
6731d7f5145SBaochen Qiang cmd->chanfreq = ath11k_wmi_mgmt_get_freq(ar, info);
674d5c65159SKalle Valo cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr);
675d5c65159SKalle Valo cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr);
676d5c65159SKalle Valo cmd->frame_len = frame->len;
677d5c65159SKalle Valo cmd->buf_len = buf_len;
678d5c65159SKalle Valo cmd->tx_params_valid = 0;
679d5c65159SKalle Valo
680d5c65159SKalle Valo frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
681d5c65159SKalle Valo frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
682d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, buf_len);
683d5c65159SKalle Valo
684d5c65159SKalle Valo memcpy(frame_tlv->value, frame->data, buf_len);
685d5c65159SKalle Valo
686d5c65159SKalle Valo ath11k_ce_byte_swap(frame_tlv->value, buf_len);
687d5c65159SKalle Valo
688d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID);
689d5c65159SKalle Valo if (ret) {
690d5c65159SKalle Valo ath11k_warn(ar->ab,
691d5c65159SKalle Valo "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n");
692d5c65159SKalle Valo dev_kfree_skb(skb);
693d5c65159SKalle Valo }
694d5c65159SKalle Valo
69500608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd mgmt tx send");
69600608b40SKalle Valo
697d5c65159SKalle Valo return ret;
698d5c65159SKalle Valo }
699d5c65159SKalle Valo
ath11k_wmi_vdev_create(struct ath11k * ar,u8 * macaddr,struct vdev_create_params * param)700d5c65159SKalle Valo int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr,
701d5c65159SKalle Valo struct vdev_create_params *param)
702d5c65159SKalle Valo {
703d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
704d5c65159SKalle Valo struct wmi_vdev_create_cmd *cmd;
705d5c65159SKalle Valo struct sk_buff *skb;
706d5c65159SKalle Valo struct wmi_vdev_txrx_streams *txrx_streams;
707d5c65159SKalle Valo struct wmi_tlv *tlv;
708d5c65159SKalle Valo int ret, len;
709d5c65159SKalle Valo void *ptr;
710d5c65159SKalle Valo
711d5c65159SKalle Valo /* It can be optimized my sending tx/rx chain configuration
712d5c65159SKalle Valo * only for supported bands instead of always sending it for
713d5c65159SKalle Valo * both the bands.
714d5c65159SKalle Valo */
715d5c65159SKalle Valo len = sizeof(*cmd) + TLV_HDR_SIZE +
716d5c65159SKalle Valo (WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams));
717d5c65159SKalle Valo
7186bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
719d5c65159SKalle Valo if (!skb)
720d5c65159SKalle Valo return -ENOMEM;
721d5c65159SKalle Valo
722d5c65159SKalle Valo cmd = (struct wmi_vdev_create_cmd *)skb->data;
723d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) |
724d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
725d5c65159SKalle Valo
726d5c65159SKalle Valo cmd->vdev_id = param->if_id;
727d5c65159SKalle Valo cmd->vdev_type = param->type;
728d5c65159SKalle Valo cmd->vdev_subtype = param->subtype;
729d5c65159SKalle Valo cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX;
730d5c65159SKalle Valo cmd->pdev_id = param->pdev_id;
7315a81610aSAloka Dixit cmd->mbssid_flags = param->mbssid_flags;
7325a81610aSAloka Dixit cmd->mbssid_tx_vdev_id = param->mbssid_tx_vdev_id;
7335a81610aSAloka Dixit
734d5c65159SKalle Valo ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
735d5c65159SKalle Valo
736d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd);
737d5c65159SKalle Valo len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams);
738d5c65159SKalle Valo
739d5c65159SKalle Valo tlv = ptr;
740d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
741d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
742d5c65159SKalle Valo
743d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
744d5c65159SKalle Valo txrx_streams = ptr;
745d5c65159SKalle Valo len = sizeof(*txrx_streams);
746d5c65159SKalle Valo txrx_streams->tlv_header =
747d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
748d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
749d5c65159SKalle Valo txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G;
750d5c65159SKalle Valo txrx_streams->supported_tx_streams =
751d5c65159SKalle Valo param->chains[NL80211_BAND_2GHZ].tx;
752d5c65159SKalle Valo txrx_streams->supported_rx_streams =
753d5c65159SKalle Valo param->chains[NL80211_BAND_2GHZ].rx;
754d5c65159SKalle Valo
755d5c65159SKalle Valo txrx_streams++;
756d5c65159SKalle Valo txrx_streams->tlv_header =
757d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
758d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
759d5c65159SKalle Valo txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G;
760d5c65159SKalle Valo txrx_streams->supported_tx_streams =
761d5c65159SKalle Valo param->chains[NL80211_BAND_5GHZ].tx;
762d5c65159SKalle Valo txrx_streams->supported_rx_streams =
763d5c65159SKalle Valo param->chains[NL80211_BAND_5GHZ].rx;
764d5c65159SKalle Valo
765d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID);
766d5c65159SKalle Valo if (ret) {
767d5c65159SKalle Valo ath11k_warn(ar->ab,
768d5c65159SKalle Valo "failed to submit WMI_VDEV_CREATE_CMDID\n");
769d5c65159SKalle Valo dev_kfree_skb(skb);
770d5c65159SKalle Valo }
771d5c65159SKalle Valo
772d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
77300608b40SKalle Valo "cmd vdev create id %d type %d subtype %d macaddr %pM pdevid %d\n",
774d5c65159SKalle Valo param->if_id, param->type, param->subtype,
775d5c65159SKalle Valo macaddr, param->pdev_id);
776d5c65159SKalle Valo
777d5c65159SKalle Valo return ret;
778d5c65159SKalle Valo }
779d5c65159SKalle Valo
ath11k_wmi_vdev_delete(struct ath11k * ar,u8 vdev_id)780d5c65159SKalle Valo int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id)
781d5c65159SKalle Valo {
782d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
783d5c65159SKalle Valo struct wmi_vdev_delete_cmd *cmd;
784d5c65159SKalle Valo struct sk_buff *skb;
785d5c65159SKalle Valo int ret;
786d5c65159SKalle Valo
7876bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
788d5c65159SKalle Valo if (!skb)
789d5c65159SKalle Valo return -ENOMEM;
790d5c65159SKalle Valo
791d5c65159SKalle Valo cmd = (struct wmi_vdev_delete_cmd *)skb->data;
792d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) |
793d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
794d5c65159SKalle Valo cmd->vdev_id = vdev_id;
795d5c65159SKalle Valo
796d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID);
797d5c65159SKalle Valo if (ret) {
798d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n");
799d5c65159SKalle Valo dev_kfree_skb(skb);
800d5c65159SKalle Valo }
801d5c65159SKalle Valo
80200608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev delete id %d\n", vdev_id);
803d5c65159SKalle Valo
804d5c65159SKalle Valo return ret;
805d5c65159SKalle Valo }
806d5c65159SKalle Valo
ath11k_wmi_vdev_stop(struct ath11k * ar,u8 vdev_id)807d5c65159SKalle Valo int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id)
808d5c65159SKalle Valo {
809d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
810d5c65159SKalle Valo struct wmi_vdev_stop_cmd *cmd;
811d5c65159SKalle Valo struct sk_buff *skb;
812d5c65159SKalle Valo int ret;
813d5c65159SKalle Valo
8146bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
815d5c65159SKalle Valo if (!skb)
816d5c65159SKalle Valo return -ENOMEM;
817d5c65159SKalle Valo
818d5c65159SKalle Valo cmd = (struct wmi_vdev_stop_cmd *)skb->data;
819d5c65159SKalle Valo
820d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) |
821d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
822d5c65159SKalle Valo cmd->vdev_id = vdev_id;
823d5c65159SKalle Valo
824d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID);
825d5c65159SKalle Valo if (ret) {
826d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n");
827d5c65159SKalle Valo dev_kfree_skb(skb);
828d5c65159SKalle Valo }
829d5c65159SKalle Valo
83000608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev stop id 0x%x\n", vdev_id);
831d5c65159SKalle Valo
832d5c65159SKalle Valo return ret;
833d5c65159SKalle Valo }
834d5c65159SKalle Valo
ath11k_wmi_vdev_down(struct ath11k * ar,u8 vdev_id)835d5c65159SKalle Valo int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id)
836d5c65159SKalle Valo {
837d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
838d5c65159SKalle Valo struct wmi_vdev_down_cmd *cmd;
839d5c65159SKalle Valo struct sk_buff *skb;
840d5c65159SKalle Valo int ret;
841d5c65159SKalle Valo
8426bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
843d5c65159SKalle Valo if (!skb)
844d5c65159SKalle Valo return -ENOMEM;
845d5c65159SKalle Valo
846d5c65159SKalle Valo cmd = (struct wmi_vdev_down_cmd *)skb->data;
847d5c65159SKalle Valo
848d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) |
849d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
850d5c65159SKalle Valo cmd->vdev_id = vdev_id;
851d5c65159SKalle Valo
852d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID);
853d5c65159SKalle Valo if (ret) {
854d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n");
855d5c65159SKalle Valo dev_kfree_skb(skb);
856d5c65159SKalle Valo }
857d5c65159SKalle Valo
85800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev down id 0x%x\n", vdev_id);
859d5c65159SKalle Valo
860d5c65159SKalle Valo return ret;
861d5c65159SKalle Valo }
862d5c65159SKalle Valo
ath11k_wmi_put_wmi_channel(struct wmi_channel * chan,struct wmi_vdev_start_req_arg * arg)863d5c65159SKalle Valo static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan,
864d5c65159SKalle Valo struct wmi_vdev_start_req_arg *arg)
865d5c65159SKalle Valo {
866f552d6fdSP Praneesh u32 center_freq1 = arg->channel.band_center_freq1;
867f552d6fdSP Praneesh
868d5c65159SKalle Valo memset(chan, 0, sizeof(*chan));
869d5c65159SKalle Valo
870d5c65159SKalle Valo chan->mhz = arg->channel.freq;
871d5c65159SKalle Valo chan->band_center_freq1 = arg->channel.band_center_freq1;
872f552d6fdSP Praneesh
873f552d6fdSP Praneesh if (arg->channel.mode == MODE_11AX_HE160) {
874f552d6fdSP Praneesh if (arg->channel.freq > arg->channel.band_center_freq1)
875f552d6fdSP Praneesh chan->band_center_freq1 = center_freq1 + 40;
876d5c65159SKalle Valo else
877f552d6fdSP Praneesh chan->band_center_freq1 = center_freq1 - 40;
878f552d6fdSP Praneesh
879f552d6fdSP Praneesh chan->band_center_freq2 = arg->channel.band_center_freq1;
880f552d6fdSP Praneesh
881b100722aSMuna Sinada } else if ((arg->channel.mode == MODE_11AC_VHT80_80) ||
882b100722aSMuna Sinada (arg->channel.mode == MODE_11AX_HE80_80)) {
883f552d6fdSP Praneesh chan->band_center_freq2 = arg->channel.band_center_freq2;
884f552d6fdSP Praneesh } else {
885d5c65159SKalle Valo chan->band_center_freq2 = 0;
886f552d6fdSP Praneesh }
887d5c65159SKalle Valo
888d5c65159SKalle Valo chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode);
889d5c65159SKalle Valo if (arg->channel.passive)
890d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_PASSIVE;
891d5c65159SKalle Valo if (arg->channel.allow_ibss)
892d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED;
893d5c65159SKalle Valo if (arg->channel.allow_ht)
894d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_ALLOW_HT;
895d5c65159SKalle Valo if (arg->channel.allow_vht)
896d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_ALLOW_VHT;
8979f056ed8SJohn Crispin if (arg->channel.allow_he)
8989f056ed8SJohn Crispin chan->info |= WMI_CHAN_INFO_ALLOW_HE;
899d5c65159SKalle Valo if (arg->channel.ht40plus)
900d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_HT40_PLUS;
901d5c65159SKalle Valo if (arg->channel.chan_radar)
902d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_DFS;
903d5c65159SKalle Valo if (arg->channel.freq2_radar)
904d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_DFS_FREQ2;
905d5c65159SKalle Valo
906d5c65159SKalle Valo chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
907d5c65159SKalle Valo arg->channel.max_power) |
908d5c65159SKalle Valo FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
909d5c65159SKalle Valo arg->channel.max_reg_power);
910d5c65159SKalle Valo
911d5c65159SKalle Valo chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
912d5c65159SKalle Valo arg->channel.max_antenna_gain) |
913d5c65159SKalle Valo FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
914d5c65159SKalle Valo arg->channel.max_power);
915d5c65159SKalle Valo }
916d5c65159SKalle Valo
ath11k_wmi_vdev_start(struct ath11k * ar,struct wmi_vdev_start_req_arg * arg,bool restart)917d5c65159SKalle Valo int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg,
918d5c65159SKalle Valo bool restart)
919d5c65159SKalle Valo {
920d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
921d5c65159SKalle Valo struct wmi_vdev_start_request_cmd *cmd;
922d5c65159SKalle Valo struct sk_buff *skb;
923d5c65159SKalle Valo struct wmi_channel *chan;
924d5c65159SKalle Valo struct wmi_tlv *tlv;
925d5c65159SKalle Valo void *ptr;
926d5c65159SKalle Valo int ret, len;
927d5c65159SKalle Valo
928d5c65159SKalle Valo if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
929d5c65159SKalle Valo return -EINVAL;
930d5c65159SKalle Valo
931d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE;
932d5c65159SKalle Valo
9336bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
934d5c65159SKalle Valo if (!skb)
935d5c65159SKalle Valo return -ENOMEM;
936d5c65159SKalle Valo
937d5c65159SKalle Valo cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
938d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
939d5c65159SKalle Valo WMI_TAG_VDEV_START_REQUEST_CMD) |
940d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
941d5c65159SKalle Valo cmd->vdev_id = arg->vdev_id;
942d5c65159SKalle Valo cmd->beacon_interval = arg->bcn_intval;
943d5c65159SKalle Valo cmd->bcn_tx_rate = arg->bcn_tx_rate;
944d5c65159SKalle Valo cmd->dtim_period = arg->dtim_period;
945d5c65159SKalle Valo cmd->num_noa_descriptors = arg->num_noa_descriptors;
946d5c65159SKalle Valo cmd->preferred_rx_streams = arg->pref_rx_streams;
947d5c65159SKalle Valo cmd->preferred_tx_streams = arg->pref_tx_streams;
948d5c65159SKalle Valo cmd->cac_duration_ms = arg->cac_duration_ms;
949d5c65159SKalle Valo cmd->regdomain = arg->regdomain;
950d5c65159SKalle Valo cmd->he_ops = arg->he_ops;
9515a81610aSAloka Dixit cmd->mbssid_flags = arg->mbssid_flags;
9525a81610aSAloka Dixit cmd->mbssid_tx_vdev_id = arg->mbssid_tx_vdev_id;
953d5c65159SKalle Valo
954d5c65159SKalle Valo if (!restart) {
955d5c65159SKalle Valo if (arg->ssid) {
956d5c65159SKalle Valo cmd->ssid.ssid_len = arg->ssid_len;
957d5c65159SKalle Valo memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
958d5c65159SKalle Valo }
959d5c65159SKalle Valo if (arg->hidden_ssid)
960d5c65159SKalle Valo cmd->flags |= WMI_VDEV_START_HIDDEN_SSID;
961d5c65159SKalle Valo if (arg->pmf_enabled)
962d5c65159SKalle Valo cmd->flags |= WMI_VDEV_START_PMF_ENABLED;
963d5c65159SKalle Valo }
964d5c65159SKalle Valo
965d5c65159SKalle Valo cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED;
9668717db7eSSeevalamuthu Mariappan if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
9678717db7eSSeevalamuthu Mariappan cmd->flags |= WMI_VDEV_START_HW_ENCRYPTION_DISABLED;
968d5c65159SKalle Valo
969d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd);
970d5c65159SKalle Valo chan = ptr;
971d5c65159SKalle Valo
972d5c65159SKalle Valo ath11k_wmi_put_wmi_channel(chan, arg);
973d5c65159SKalle Valo
974d5c65159SKalle Valo chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) |
975d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
976d5c65159SKalle Valo sizeof(*chan) - TLV_HDR_SIZE);
977d5c65159SKalle Valo ptr += sizeof(*chan);
978d5c65159SKalle Valo
979d5c65159SKalle Valo tlv = ptr;
980d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
981d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 0);
982d5c65159SKalle Valo
983d5c65159SKalle Valo /* Note: This is a nested TLV containing:
984d5c65159SKalle Valo * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
985d5c65159SKalle Valo */
986d5c65159SKalle Valo
987d5c65159SKalle Valo ptr += sizeof(*tlv);
988d5c65159SKalle Valo
989d5c65159SKalle Valo if (restart)
990d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
991d5c65159SKalle Valo WMI_VDEV_RESTART_REQUEST_CMDID);
992d5c65159SKalle Valo else
993d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
994d5c65159SKalle Valo WMI_VDEV_START_REQUEST_CMDID);
995d5c65159SKalle Valo if (ret) {
996d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n",
997d5c65159SKalle Valo restart ? "restart" : "start");
998d5c65159SKalle Valo dev_kfree_skb(skb);
999d5c65159SKalle Valo }
1000d5c65159SKalle Valo
100100608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev %s id 0x%x freq 0x%x mode 0x%x\n",
1002d5c65159SKalle Valo restart ? "restart" : "start", arg->vdev_id,
1003d5c65159SKalle Valo arg->channel.freq, arg->channel.mode);
1004d5c65159SKalle Valo
1005d5c65159SKalle Valo return ret;
1006d5c65159SKalle Valo }
1007d5c65159SKalle Valo
ath11k_wmi_vdev_up(struct ath11k * ar,u32 vdev_id,u32 aid,const u8 * bssid,u8 * tx_bssid,u32 nontx_profile_idx,u32 nontx_profile_cnt)1008c82dc33fSAloka Dixit int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid,
1009c82dc33fSAloka Dixit u8 *tx_bssid, u32 nontx_profile_idx, u32 nontx_profile_cnt)
1010d5c65159SKalle Valo {
1011d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1012d5c65159SKalle Valo struct wmi_vdev_up_cmd *cmd;
10137d992bd4SManikanta Pubbisetty struct ieee80211_bss_conf *bss_conf;
10147d992bd4SManikanta Pubbisetty struct ath11k_vif *arvif;
1015d5c65159SKalle Valo struct sk_buff *skb;
1016d5c65159SKalle Valo int ret;
1017d5c65159SKalle Valo
10187d992bd4SManikanta Pubbisetty arvif = ath11k_mac_get_arvif(ar, vdev_id);
10197d992bd4SManikanta Pubbisetty
10206bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1021d5c65159SKalle Valo if (!skb)
1022d5c65159SKalle Valo return -ENOMEM;
1023d5c65159SKalle Valo
1024d5c65159SKalle Valo cmd = (struct wmi_vdev_up_cmd *)skb->data;
1025d5c65159SKalle Valo
1026d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) |
1027d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1028d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1029d5c65159SKalle Valo cmd->vdev_assoc_id = aid;
1030d5c65159SKalle Valo
1031d5c65159SKalle Valo ether_addr_copy(cmd->vdev_bssid.addr, bssid);
1032d5c65159SKalle Valo
1033c82dc33fSAloka Dixit cmd->nontx_profile_idx = nontx_profile_idx;
1034c82dc33fSAloka Dixit cmd->nontx_profile_cnt = nontx_profile_cnt;
1035c82dc33fSAloka Dixit if (tx_bssid)
1036c82dc33fSAloka Dixit ether_addr_copy(cmd->tx_vdev_bssid.addr, tx_bssid);
1037c82dc33fSAloka Dixit
10387d992bd4SManikanta Pubbisetty if (arvif && arvif->vif->type == NL80211_IFTYPE_STATION) {
10397d992bd4SManikanta Pubbisetty bss_conf = &arvif->vif->bss_conf;
10407d992bd4SManikanta Pubbisetty
10417d992bd4SManikanta Pubbisetty if (bss_conf->nontransmitted) {
1042cf604e72SAloka Dixit ether_addr_copy(cmd->tx_vdev_bssid.addr,
10437d992bd4SManikanta Pubbisetty bss_conf->transmitter_bssid);
1044cf604e72SAloka Dixit cmd->nontx_profile_idx = bss_conf->bssid_index;
1045cf604e72SAloka Dixit cmd->nontx_profile_cnt = bss_conf->bssid_indicator;
10467d992bd4SManikanta Pubbisetty }
10477d992bd4SManikanta Pubbisetty }
10487d992bd4SManikanta Pubbisetty
1049d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID);
1050d5c65159SKalle Valo if (ret) {
1051d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n");
1052d5c65159SKalle Valo dev_kfree_skb(skb);
1053d5c65159SKalle Valo }
1054d5c65159SKalle Valo
1055d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
105600608b40SKalle Valo "cmd vdev up id 0x%x assoc id %d bssid %pM\n",
1057d5c65159SKalle Valo vdev_id, aid, bssid);
1058d5c65159SKalle Valo
1059d5c65159SKalle Valo return ret;
1060d5c65159SKalle Valo }
1061d5c65159SKalle Valo
ath11k_wmi_send_peer_create_cmd(struct ath11k * ar,struct peer_create_params * param)1062d5c65159SKalle Valo int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar,
1063d5c65159SKalle Valo struct peer_create_params *param)
1064d5c65159SKalle Valo {
1065d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1066d5c65159SKalle Valo struct wmi_peer_create_cmd *cmd;
1067d5c65159SKalle Valo struct sk_buff *skb;
1068d5c65159SKalle Valo int ret;
1069d5c65159SKalle Valo
10706bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1071d5c65159SKalle Valo if (!skb)
1072d5c65159SKalle Valo return -ENOMEM;
1073d5c65159SKalle Valo
1074d5c65159SKalle Valo cmd = (struct wmi_peer_create_cmd *)skb->data;
1075d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) |
1076d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1077d5c65159SKalle Valo
1078d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr);
1079d5c65159SKalle Valo cmd->peer_type = param->peer_type;
1080d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
1081d5c65159SKalle Valo
1082d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID);
1083d5c65159SKalle Valo if (ret) {
1084d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n");
1085d5c65159SKalle Valo dev_kfree_skb(skb);
1086d5c65159SKalle Valo }
1087d5c65159SKalle Valo
1088d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
108900608b40SKalle Valo "cmd peer create vdev_id %d peer_addr %pM\n",
1090d5c65159SKalle Valo param->vdev_id, param->peer_addr);
1091d5c65159SKalle Valo
1092d5c65159SKalle Valo return ret;
1093d5c65159SKalle Valo }
1094d5c65159SKalle Valo
ath11k_wmi_send_peer_delete_cmd(struct ath11k * ar,const u8 * peer_addr,u8 vdev_id)1095d5c65159SKalle Valo int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar,
1096d5c65159SKalle Valo const u8 *peer_addr, u8 vdev_id)
1097d5c65159SKalle Valo {
1098d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1099d5c65159SKalle Valo struct wmi_peer_delete_cmd *cmd;
1100d5c65159SKalle Valo struct sk_buff *skb;
1101d5c65159SKalle Valo int ret;
1102d5c65159SKalle Valo
11036bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1104d5c65159SKalle Valo if (!skb)
1105d5c65159SKalle Valo return -ENOMEM;
1106d5c65159SKalle Valo
1107d5c65159SKalle Valo cmd = (struct wmi_peer_delete_cmd *)skb->data;
1108d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) |
1109d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1110d5c65159SKalle Valo
1111d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1112d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1113d5c65159SKalle Valo
1114d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID);
1115d5c65159SKalle Valo if (ret) {
1116d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n");
1117d5c65159SKalle Valo dev_kfree_skb(skb);
1118d5c65159SKalle Valo }
1119d5c65159SKalle Valo
112000608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
112100608b40SKalle Valo "cmd peer delete vdev_id %d peer_addr %pM\n",
112200608b40SKalle Valo vdev_id, peer_addr);
112300608b40SKalle Valo
1124d5c65159SKalle Valo return ret;
1125d5c65159SKalle Valo }
1126d5c65159SKalle Valo
ath11k_wmi_send_pdev_set_regdomain(struct ath11k * ar,struct pdev_set_regdomain_params * param)1127d5c65159SKalle Valo int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar,
1128d5c65159SKalle Valo struct pdev_set_regdomain_params *param)
1129d5c65159SKalle Valo {
1130d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1131d5c65159SKalle Valo struct wmi_pdev_set_regdomain_cmd *cmd;
1132d5c65159SKalle Valo struct sk_buff *skb;
1133d5c65159SKalle Valo int ret;
1134d5c65159SKalle Valo
11356bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1136d5c65159SKalle Valo if (!skb)
1137d5c65159SKalle Valo return -ENOMEM;
1138d5c65159SKalle Valo
1139d5c65159SKalle Valo cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1140d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1141d5c65159SKalle Valo WMI_TAG_PDEV_SET_REGDOMAIN_CMD) |
1142d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1143d5c65159SKalle Valo
1144d5c65159SKalle Valo cmd->reg_domain = param->current_rd_in_use;
1145d5c65159SKalle Valo cmd->reg_domain_2g = param->current_rd_2g;
1146d5c65159SKalle Valo cmd->reg_domain_5g = param->current_rd_5g;
1147d5c65159SKalle Valo cmd->conformance_test_limit_2g = param->ctl_2g;
1148d5c65159SKalle Valo cmd->conformance_test_limit_5g = param->ctl_5g;
1149d5c65159SKalle Valo cmd->dfs_domain = param->dfs_domain;
1150d5c65159SKalle Valo cmd->pdev_id = param->pdev_id;
1151d5c65159SKalle Valo
1152d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1153d5c65159SKalle Valo if (ret) {
1154d5c65159SKalle Valo ath11k_warn(ar->ab,
1155d5c65159SKalle Valo "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n");
1156d5c65159SKalle Valo dev_kfree_skb(skb);
1157d5c65159SKalle Valo }
1158d5c65159SKalle Valo
115900608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
116000608b40SKalle Valo "cmd pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n",
116100608b40SKalle Valo param->current_rd_in_use, param->current_rd_2g,
116200608b40SKalle Valo param->current_rd_5g, param->dfs_domain, param->pdev_id);
116300608b40SKalle Valo
1164d5c65159SKalle Valo return ret;
1165d5c65159SKalle Valo }
1166d5c65159SKalle Valo
ath11k_wmi_set_peer_param(struct ath11k * ar,const u8 * peer_addr,u32 vdev_id,u32 param_id,u32 param_val)1167d5c65159SKalle Valo int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr,
1168d5c65159SKalle Valo u32 vdev_id, u32 param_id, u32 param_val)
1169d5c65159SKalle Valo {
1170d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1171d5c65159SKalle Valo struct wmi_peer_set_param_cmd *cmd;
1172d5c65159SKalle Valo struct sk_buff *skb;
1173d5c65159SKalle Valo int ret;
1174d5c65159SKalle Valo
11756bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1176d5c65159SKalle Valo if (!skb)
1177d5c65159SKalle Valo return -ENOMEM;
1178d5c65159SKalle Valo
1179d5c65159SKalle Valo cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1180d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) |
1181d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1182d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1183d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1184d5c65159SKalle Valo cmd->param_id = param_id;
1185d5c65159SKalle Valo cmd->param_value = param_val;
1186d5c65159SKalle Valo
1187d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID);
1188d5c65159SKalle Valo if (ret) {
1189d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n");
1190d5c65159SKalle Valo dev_kfree_skb(skb);
1191d5c65159SKalle Valo }
1192d5c65159SKalle Valo
1193d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
119400608b40SKalle Valo "cmd peer set param vdev %d peer 0x%pM set param %d value %d\n",
1195d5c65159SKalle Valo vdev_id, peer_addr, param_id, param_val);
1196d5c65159SKalle Valo
1197d5c65159SKalle Valo return ret;
1198d5c65159SKalle Valo }
1199d5c65159SKalle Valo
ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k * ar,u8 peer_addr[ETH_ALEN],struct peer_flush_params * param)1200d5c65159SKalle Valo int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar,
1201d5c65159SKalle Valo u8 peer_addr[ETH_ALEN],
1202d5c65159SKalle Valo struct peer_flush_params *param)
1203d5c65159SKalle Valo {
1204d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1205d5c65159SKalle Valo struct wmi_peer_flush_tids_cmd *cmd;
1206d5c65159SKalle Valo struct sk_buff *skb;
1207d5c65159SKalle Valo int ret;
1208d5c65159SKalle Valo
12096bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1210d5c65159SKalle Valo if (!skb)
1211d5c65159SKalle Valo return -ENOMEM;
1212d5c65159SKalle Valo
1213d5c65159SKalle Valo cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1214d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) |
1215d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1216d5c65159SKalle Valo
1217d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1218d5c65159SKalle Valo cmd->peer_tid_bitmap = param->peer_tid_bitmap;
1219d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
1220d5c65159SKalle Valo
1221d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1222d5c65159SKalle Valo if (ret) {
1223d5c65159SKalle Valo ath11k_warn(ar->ab,
1224d5c65159SKalle Valo "failed to send WMI_PEER_FLUSH_TIDS cmd\n");
1225d5c65159SKalle Valo dev_kfree_skb(skb);
1226d5c65159SKalle Valo }
1227d5c65159SKalle Valo
1228d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
122900608b40SKalle Valo "cmd peer flush tids vdev_id %d peer_addr %pM tids %08x\n",
1230d5c65159SKalle Valo param->vdev_id, peer_addr, param->peer_tid_bitmap);
1231d5c65159SKalle Valo
1232d5c65159SKalle Valo return ret;
1233d5c65159SKalle Valo }
1234d5c65159SKalle Valo
ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k * ar,int vdev_id,const u8 * addr,dma_addr_t paddr,u8 tid,u8 ba_window_size_valid,u32 ba_window_size)1235d5c65159SKalle Valo int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar,
1236d5c65159SKalle Valo int vdev_id, const u8 *addr,
1237d5c65159SKalle Valo dma_addr_t paddr, u8 tid,
1238d5c65159SKalle Valo u8 ba_window_size_valid,
1239d5c65159SKalle Valo u32 ba_window_size)
1240d5c65159SKalle Valo {
1241d5c65159SKalle Valo struct wmi_peer_reorder_queue_setup_cmd *cmd;
1242d5c65159SKalle Valo struct sk_buff *skb;
1243d5c65159SKalle Valo int ret;
1244d5c65159SKalle Valo
12456bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
1246d5c65159SKalle Valo if (!skb)
1247d5c65159SKalle Valo return -ENOMEM;
1248d5c65159SKalle Valo
1249d5c65159SKalle Valo cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data;
1250d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1251d5c65159SKalle Valo WMI_TAG_REORDER_QUEUE_SETUP_CMD) |
1252d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1253d5c65159SKalle Valo
1254d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, addr);
1255d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1256d5c65159SKalle Valo cmd->tid = tid;
1257d5c65159SKalle Valo cmd->queue_ptr_lo = lower_32_bits(paddr);
1258d5c65159SKalle Valo cmd->queue_ptr_hi = upper_32_bits(paddr);
1259d5c65159SKalle Valo cmd->queue_no = tid;
1260d5c65159SKalle Valo cmd->ba_window_size_valid = ba_window_size_valid;
1261d5c65159SKalle Valo cmd->ba_window_size = ba_window_size;
1262d5c65159SKalle Valo
1263d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(ar->wmi, skb,
1264d5c65159SKalle Valo WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1265d5c65159SKalle Valo if (ret) {
1266d5c65159SKalle Valo ath11k_warn(ar->ab,
1267d5c65159SKalle Valo "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n");
1268d5c65159SKalle Valo dev_kfree_skb(skb);
1269d5c65159SKalle Valo }
1270d5c65159SKalle Valo
1271d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
127200608b40SKalle Valo "cmd peer reorder queue setup addr %pM vdev_id %d tid %d\n",
1273d5c65159SKalle Valo addr, vdev_id, tid);
1274d5c65159SKalle Valo
1275d5c65159SKalle Valo return ret;
1276d5c65159SKalle Valo }
1277d5c65159SKalle Valo
1278d5c65159SKalle Valo int
ath11k_wmi_rx_reord_queue_remove(struct ath11k * ar,struct rx_reorder_queue_remove_params * param)1279d5c65159SKalle Valo ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar,
1280d5c65159SKalle Valo struct rx_reorder_queue_remove_params *param)
1281d5c65159SKalle Valo {
1282d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1283d5c65159SKalle Valo struct wmi_peer_reorder_queue_remove_cmd *cmd;
1284d5c65159SKalle Valo struct sk_buff *skb;
1285d5c65159SKalle Valo int ret;
1286d5c65159SKalle Valo
12876bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1288d5c65159SKalle Valo if (!skb)
1289d5c65159SKalle Valo return -ENOMEM;
1290d5c65159SKalle Valo
1291d5c65159SKalle Valo cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data;
1292d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1293d5c65159SKalle Valo WMI_TAG_REORDER_QUEUE_REMOVE_CMD) |
1294d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1295d5c65159SKalle Valo
1296d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr);
1297d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
1298d5c65159SKalle Valo cmd->tid_mask = param->peer_tid_bitmap;
1299d5c65159SKalle Valo
1300d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
1301d5c65159SKalle Valo WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
1302d5c65159SKalle Valo if (ret) {
1303d5c65159SKalle Valo ath11k_warn(ar->ab,
1304d5c65159SKalle Valo "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID");
1305d5c65159SKalle Valo dev_kfree_skb(skb);
1306d5c65159SKalle Valo }
1307d5c65159SKalle Valo
130800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
130900608b40SKalle Valo "cmd peer reorder queue remove peer_macaddr %pM vdev_id %d tid_map %d",
131000608b40SKalle Valo param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap);
131100608b40SKalle Valo
1312d5c65159SKalle Valo return ret;
1313d5c65159SKalle Valo }
1314d5c65159SKalle Valo
ath11k_wmi_pdev_set_param(struct ath11k * ar,u32 param_id,u32 param_value,u8 pdev_id)1315d5c65159SKalle Valo int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id,
1316d5c65159SKalle Valo u32 param_value, u8 pdev_id)
1317d5c65159SKalle Valo {
1318d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1319d5c65159SKalle Valo struct wmi_pdev_set_param_cmd *cmd;
1320d5c65159SKalle Valo struct sk_buff *skb;
1321d5c65159SKalle Valo int ret;
1322d5c65159SKalle Valo
13236bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1324d5c65159SKalle Valo if (!skb)
1325d5c65159SKalle Valo return -ENOMEM;
1326d5c65159SKalle Valo
1327d5c65159SKalle Valo cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1328d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) |
1329d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1330d5c65159SKalle Valo cmd->pdev_id = pdev_id;
1331d5c65159SKalle Valo cmd->param_id = param_id;
1332d5c65159SKalle Valo cmd->param_value = param_value;
1333d5c65159SKalle Valo
1334d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID);
1335d5c65159SKalle Valo if (ret) {
1336d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1337d5c65159SKalle Valo dev_kfree_skb(skb);
1338d5c65159SKalle Valo }
1339d5c65159SKalle Valo
1340d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
134100608b40SKalle Valo "cmd pdev set param %d pdev id %d value %d\n",
1342d5c65159SKalle Valo param_id, pdev_id, param_value);
1343d5c65159SKalle Valo
1344d5c65159SKalle Valo return ret;
1345d5c65159SKalle Valo }
1346d5c65159SKalle Valo
ath11k_wmi_pdev_set_ps_mode(struct ath11k * ar,int vdev_id,enum wmi_sta_ps_mode psmode)1347af3d8964SKalle Valo int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id,
1348af3d8964SKalle Valo enum wmi_sta_ps_mode psmode)
134997c63746SJohn Crispin {
135097c63746SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
135197c63746SJohn Crispin struct wmi_pdev_set_ps_mode_cmd *cmd;
135297c63746SJohn Crispin struct sk_buff *skb;
135397c63746SJohn Crispin int ret;
135497c63746SJohn Crispin
13556bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
135697c63746SJohn Crispin if (!skb)
135797c63746SJohn Crispin return -ENOMEM;
135897c63746SJohn Crispin
135997c63746SJohn Crispin cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data;
136097c63746SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) |
136197c63746SJohn Crispin FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
136297c63746SJohn Crispin cmd->vdev_id = vdev_id;
1363af3d8964SKalle Valo cmd->sta_ps_mode = psmode;
136497c63746SJohn Crispin
136597c63746SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID);
136697c63746SJohn Crispin if (ret) {
136797c63746SJohn Crispin ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
136897c63746SJohn Crispin dev_kfree_skb(skb);
136997c63746SJohn Crispin }
137097c63746SJohn Crispin
137197c63746SJohn Crispin ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
137200608b40SKalle Valo "cmd sta powersave mode psmode %d vdev id %d\n",
1373af3d8964SKalle Valo psmode, vdev_id);
137497c63746SJohn Crispin
137597c63746SJohn Crispin return ret;
137697c63746SJohn Crispin }
137797c63746SJohn Crispin
ath11k_wmi_pdev_suspend(struct ath11k * ar,u32 suspend_opt,u32 pdev_id)1378d5c65159SKalle Valo int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt,
1379d5c65159SKalle Valo u32 pdev_id)
1380d5c65159SKalle Valo {
1381d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1382d5c65159SKalle Valo struct wmi_pdev_suspend_cmd *cmd;
1383d5c65159SKalle Valo struct sk_buff *skb;
1384d5c65159SKalle Valo int ret;
1385d5c65159SKalle Valo
13866bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1387d5c65159SKalle Valo if (!skb)
1388d5c65159SKalle Valo return -ENOMEM;
1389d5c65159SKalle Valo
1390d5c65159SKalle Valo cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1391d5c65159SKalle Valo
1392d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) |
1393d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1394d5c65159SKalle Valo
1395d5c65159SKalle Valo cmd->suspend_opt = suspend_opt;
1396d5c65159SKalle Valo cmd->pdev_id = pdev_id;
1397d5c65159SKalle Valo
1398d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID);
1399d5c65159SKalle Valo if (ret) {
1400d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n");
1401d5c65159SKalle Valo dev_kfree_skb(skb);
1402d5c65159SKalle Valo }
1403d5c65159SKalle Valo
1404d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
140500608b40SKalle Valo "cmd pdev suspend pdev_id %d\n", pdev_id);
1406d5c65159SKalle Valo
1407d5c65159SKalle Valo return ret;
1408d5c65159SKalle Valo }
1409d5c65159SKalle Valo
ath11k_wmi_pdev_resume(struct ath11k * ar,u32 pdev_id)1410d5c65159SKalle Valo int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id)
1411d5c65159SKalle Valo {
1412d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1413d5c65159SKalle Valo struct wmi_pdev_resume_cmd *cmd;
1414d5c65159SKalle Valo struct sk_buff *skb;
1415d5c65159SKalle Valo int ret;
1416d5c65159SKalle Valo
14176bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1418d5c65159SKalle Valo if (!skb)
1419d5c65159SKalle Valo return -ENOMEM;
1420d5c65159SKalle Valo
1421d5c65159SKalle Valo cmd = (struct wmi_pdev_resume_cmd *)skb->data;
1422d5c65159SKalle Valo
1423d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) |
1424d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1425d5c65159SKalle Valo cmd->pdev_id = pdev_id;
1426d5c65159SKalle Valo
1427d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID);
1428d5c65159SKalle Valo if (ret) {
1429d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n");
1430d5c65159SKalle Valo dev_kfree_skb(skb);
1431d5c65159SKalle Valo }
1432d5c65159SKalle Valo
143300608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
143400608b40SKalle Valo "cmd pdev resume pdev id %d\n", pdev_id);
143500608b40SKalle Valo
1436d5c65159SKalle Valo return ret;
1437d5c65159SKalle Valo }
1438d5c65159SKalle Valo
1439d5c65159SKalle Valo /* TODO FW Support for the cmd is not available yet.
1440d5c65159SKalle Valo * Can be tested once the command and corresponding
1441d5c65159SKalle Valo * event is implemented in FW
1442d5c65159SKalle Valo */
ath11k_wmi_pdev_bss_chan_info_request(struct ath11k * ar,enum wmi_bss_chan_info_req_type type)1443d5c65159SKalle Valo int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar,
1444d5c65159SKalle Valo enum wmi_bss_chan_info_req_type type)
1445d5c65159SKalle Valo {
1446d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1447d5c65159SKalle Valo struct wmi_pdev_bss_chan_info_req_cmd *cmd;
1448d5c65159SKalle Valo struct sk_buff *skb;
1449d5c65159SKalle Valo int ret;
1450d5c65159SKalle Valo
14516bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1452d5c65159SKalle Valo if (!skb)
1453d5c65159SKalle Valo return -ENOMEM;
1454d5c65159SKalle Valo
1455d5c65159SKalle Valo cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data;
1456d5c65159SKalle Valo
1457d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1458d5c65159SKalle Valo WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) |
1459d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1460d5c65159SKalle Valo cmd->req_type = type;
1461feab5bb8SSeevalamuthu Mariappan cmd->pdev_id = ar->pdev->pdev_id;
1462d5c65159SKalle Valo
1463d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
1464d5c65159SKalle Valo WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID);
1465d5c65159SKalle Valo if (ret) {
1466d5c65159SKalle Valo ath11k_warn(ar->ab,
1467d5c65159SKalle Valo "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n");
1468d5c65159SKalle Valo dev_kfree_skb(skb);
1469d5c65159SKalle Valo }
1470d5c65159SKalle Valo
147100608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
147200608b40SKalle Valo "cmd pdev bss chan info request type %d\n", type);
147300608b40SKalle Valo
1474d5c65159SKalle Valo return ret;
1475d5c65159SKalle Valo }
1476d5c65159SKalle Valo
ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k * ar,u8 * peer_addr,struct ap_ps_params * param)1477d5c65159SKalle Valo int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr,
1478d5c65159SKalle Valo struct ap_ps_params *param)
1479d5c65159SKalle Valo {
1480d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1481d5c65159SKalle Valo struct wmi_ap_ps_peer_cmd *cmd;
1482d5c65159SKalle Valo struct sk_buff *skb;
1483d5c65159SKalle Valo int ret;
1484d5c65159SKalle Valo
14856bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1486d5c65159SKalle Valo if (!skb)
1487d5c65159SKalle Valo return -ENOMEM;
1488d5c65159SKalle Valo
1489d5c65159SKalle Valo cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1490d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) |
1491d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1492d5c65159SKalle Valo
1493d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
1494d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1495d5c65159SKalle Valo cmd->param = param->param;
1496d5c65159SKalle Valo cmd->value = param->value;
1497d5c65159SKalle Valo
1498d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1499d5c65159SKalle Valo if (ret) {
1500d5c65159SKalle Valo ath11k_warn(ar->ab,
1501d5c65159SKalle Valo "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n");
1502d5c65159SKalle Valo dev_kfree_skb(skb);
1503d5c65159SKalle Valo }
1504d5c65159SKalle Valo
1505d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
150600608b40SKalle Valo "cmd ap ps peer param vdev id %d peer %pM param %d value %d\n",
1507d5c65159SKalle Valo param->vdev_id, peer_addr, param->param, param->value);
1508d5c65159SKalle Valo
1509d5c65159SKalle Valo return ret;
1510d5c65159SKalle Valo }
1511d5c65159SKalle Valo
ath11k_wmi_set_sta_ps_param(struct ath11k * ar,u32 vdev_id,u32 param,u32 param_value)1512d5c65159SKalle Valo int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id,
1513d5c65159SKalle Valo u32 param, u32 param_value)
1514d5c65159SKalle Valo {
1515d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1516d5c65159SKalle Valo struct wmi_sta_powersave_param_cmd *cmd;
1517d5c65159SKalle Valo struct sk_buff *skb;
1518d5c65159SKalle Valo int ret;
1519d5c65159SKalle Valo
15206bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1521d5c65159SKalle Valo if (!skb)
1522d5c65159SKalle Valo return -ENOMEM;
1523d5c65159SKalle Valo
1524d5c65159SKalle Valo cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1525d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1526d5c65159SKalle Valo WMI_TAG_STA_POWERSAVE_PARAM_CMD) |
1527d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1528d5c65159SKalle Valo
1529d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1530d5c65159SKalle Valo cmd->param = param;
1531d5c65159SKalle Valo cmd->value = param_value;
1532d5c65159SKalle Valo
1533d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1534d5c65159SKalle Valo if (ret) {
1535d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID");
1536d5c65159SKalle Valo dev_kfree_skb(skb);
1537d5c65159SKalle Valo }
1538d5c65159SKalle Valo
153900608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
154000608b40SKalle Valo "cmd set powersave param vdev_id %d param %d value %d\n",
154100608b40SKalle Valo vdev_id, param, param_value);
154200608b40SKalle Valo
1543d5c65159SKalle Valo return ret;
1544d5c65159SKalle Valo }
1545d5c65159SKalle Valo
ath11k_wmi_force_fw_hang_cmd(struct ath11k * ar,u32 type,u32 delay_time_ms)1546d5c65159SKalle Valo int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms)
1547d5c65159SKalle Valo {
1548d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1549d5c65159SKalle Valo struct wmi_force_fw_hang_cmd *cmd;
1550d5c65159SKalle Valo struct sk_buff *skb;
1551d5c65159SKalle Valo int ret, len;
1552d5c65159SKalle Valo
1553d5c65159SKalle Valo len = sizeof(*cmd);
1554d5c65159SKalle Valo
15556bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1556d5c65159SKalle Valo if (!skb)
1557d5c65159SKalle Valo return -ENOMEM;
1558d5c65159SKalle Valo
1559d5c65159SKalle Valo cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
1560d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) |
1561d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1562d5c65159SKalle Valo
1563d5c65159SKalle Valo cmd->type = type;
1564d5c65159SKalle Valo cmd->delay_time_ms = delay_time_ms;
1565d5c65159SKalle Valo
1566d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID);
1567d5c65159SKalle Valo
1568d5c65159SKalle Valo if (ret) {
1569d5c65159SKalle Valo ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID");
1570d5c65159SKalle Valo dev_kfree_skb(skb);
1571d5c65159SKalle Valo }
157200608b40SKalle Valo
157300608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd force fw hang");
157400608b40SKalle Valo
1575d5c65159SKalle Valo return ret;
1576d5c65159SKalle Valo }
1577d5c65159SKalle Valo
ath11k_wmi_vdev_set_param_cmd(struct ath11k * ar,u32 vdev_id,u32 param_id,u32 param_value)1578d5c65159SKalle Valo int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id,
1579d5c65159SKalle Valo u32 param_id, u32 param_value)
1580d5c65159SKalle Valo {
1581d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1582d5c65159SKalle Valo struct wmi_vdev_set_param_cmd *cmd;
1583d5c65159SKalle Valo struct sk_buff *skb;
1584d5c65159SKalle Valo int ret;
1585d5c65159SKalle Valo
15866bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1587d5c65159SKalle Valo if (!skb)
1588d5c65159SKalle Valo return -ENOMEM;
1589d5c65159SKalle Valo
1590d5c65159SKalle Valo cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1591d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) |
1592d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1593d5c65159SKalle Valo
1594d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1595d5c65159SKalle Valo cmd->param_id = param_id;
1596d5c65159SKalle Valo cmd->param_value = param_value;
1597d5c65159SKalle Valo
1598d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID);
1599d5c65159SKalle Valo if (ret) {
1600d5c65159SKalle Valo ath11k_warn(ar->ab,
1601d5c65159SKalle Valo "failed to send WMI_VDEV_SET_PARAM_CMDID\n");
1602d5c65159SKalle Valo dev_kfree_skb(skb);
1603d5c65159SKalle Valo }
1604d5c65159SKalle Valo
1605d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
160600608b40SKalle Valo "cmd vdev set param vdev 0x%x param %d value %d\n",
1607d5c65159SKalle Valo vdev_id, param_id, param_value);
1608d5c65159SKalle Valo
1609d5c65159SKalle Valo return ret;
1610d5c65159SKalle Valo }
1611d5c65159SKalle Valo
ath11k_wmi_send_stats_request_cmd(struct ath11k * ar,struct stats_request_params * param)1612d5c65159SKalle Valo int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar,
1613d5c65159SKalle Valo struct stats_request_params *param)
1614d5c65159SKalle Valo {
1615d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1616d5c65159SKalle Valo struct wmi_request_stats_cmd *cmd;
1617d5c65159SKalle Valo struct sk_buff *skb;
1618d5c65159SKalle Valo int ret;
1619d5c65159SKalle Valo
16206bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1621d5c65159SKalle Valo if (!skb)
1622d5c65159SKalle Valo return -ENOMEM;
1623d5c65159SKalle Valo
1624d5c65159SKalle Valo cmd = (struct wmi_request_stats_cmd *)skb->data;
1625d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) |
1626d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1627d5c65159SKalle Valo
1628d5c65159SKalle Valo cmd->stats_id = param->stats_id;
1629d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
1630d5c65159SKalle Valo cmd->pdev_id = param->pdev_id;
1631d5c65159SKalle Valo
1632d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID);
1633d5c65159SKalle Valo if (ret) {
1634d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n");
1635d5c65159SKalle Valo dev_kfree_skb(skb);
1636d5c65159SKalle Valo }
1637d5c65159SKalle Valo
1638d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
163900608b40SKalle Valo "cmd request stats 0x%x vdev id %d pdev id %d\n",
1640d5c65159SKalle Valo param->stats_id, param->vdev_id, param->pdev_id);
1641d5c65159SKalle Valo
1642d5c65159SKalle Valo return ret;
1643d5c65159SKalle Valo }
1644d5c65159SKalle Valo
ath11k_wmi_send_pdev_temperature_cmd(struct ath11k * ar)1645a41d1034SPradeep Kumar Chitrapu int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar)
1646a41d1034SPradeep Kumar Chitrapu {
1647a41d1034SPradeep Kumar Chitrapu struct ath11k_pdev_wmi *wmi = ar->wmi;
1648a41d1034SPradeep Kumar Chitrapu struct wmi_get_pdev_temperature_cmd *cmd;
1649a41d1034SPradeep Kumar Chitrapu struct sk_buff *skb;
1650a41d1034SPradeep Kumar Chitrapu int ret;
1651a41d1034SPradeep Kumar Chitrapu
1652a41d1034SPradeep Kumar Chitrapu skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1653a41d1034SPradeep Kumar Chitrapu if (!skb)
1654a41d1034SPradeep Kumar Chitrapu return -ENOMEM;
1655a41d1034SPradeep Kumar Chitrapu
1656a41d1034SPradeep Kumar Chitrapu cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data;
1657a41d1034SPradeep Kumar Chitrapu cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) |
1658a41d1034SPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1659a41d1034SPradeep Kumar Chitrapu cmd->pdev_id = ar->pdev->pdev_id;
1660a41d1034SPradeep Kumar Chitrapu
1661a41d1034SPradeep Kumar Chitrapu ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID);
1662a41d1034SPradeep Kumar Chitrapu if (ret) {
1663a41d1034SPradeep Kumar Chitrapu ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n");
1664a41d1034SPradeep Kumar Chitrapu dev_kfree_skb(skb);
1665a41d1034SPradeep Kumar Chitrapu }
1666a41d1034SPradeep Kumar Chitrapu
1667a41d1034SPradeep Kumar Chitrapu ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
166800608b40SKalle Valo "cmd pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id);
1669a41d1034SPradeep Kumar Chitrapu
1670a41d1034SPradeep Kumar Chitrapu return ret;
1671a41d1034SPradeep Kumar Chitrapu }
1672a41d1034SPradeep Kumar Chitrapu
ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k * ar,u32 vdev_id,u32 bcn_ctrl_op)1673d5c65159SKalle Valo int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar,
1674d5c65159SKalle Valo u32 vdev_id, u32 bcn_ctrl_op)
1675d5c65159SKalle Valo {
1676d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1677d5c65159SKalle Valo struct wmi_bcn_offload_ctrl_cmd *cmd;
1678d5c65159SKalle Valo struct sk_buff *skb;
1679d5c65159SKalle Valo int ret;
1680d5c65159SKalle Valo
16816bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1682d5c65159SKalle Valo if (!skb)
1683d5c65159SKalle Valo return -ENOMEM;
1684d5c65159SKalle Valo
1685d5c65159SKalle Valo cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data;
1686d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1687d5c65159SKalle Valo WMI_TAG_BCN_OFFLOAD_CTRL_CMD) |
1688d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1689d5c65159SKalle Valo
1690d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1691d5c65159SKalle Valo cmd->bcn_ctrl_op = bcn_ctrl_op;
1692d5c65159SKalle Valo
1693d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID);
1694d5c65159SKalle Valo if (ret) {
1695d5c65159SKalle Valo ath11k_warn(ar->ab,
1696d5c65159SKalle Valo "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n");
1697d5c65159SKalle Valo dev_kfree_skb(skb);
1698d5c65159SKalle Valo }
1699d5c65159SKalle Valo
170000608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
170100608b40SKalle Valo "cmd bcn offload ctrl vdev id %d ctrl_op %d\n",
170200608b40SKalle Valo vdev_id, bcn_ctrl_op);
170300608b40SKalle Valo
1704d5c65159SKalle Valo return ret;
1705d5c65159SKalle Valo }
1706d5c65159SKalle Valo
ath11k_wmi_bcn_tmpl(struct ath11k * ar,u32 vdev_id,struct ieee80211_mutable_offsets * offs,struct sk_buff * bcn,u32 ema_params)1707d5c65159SKalle Valo int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id,
1708d5c65159SKalle Valo struct ieee80211_mutable_offsets *offs,
170987bd4011SAloka Dixit struct sk_buff *bcn, u32 ema_params)
1710d5c65159SKalle Valo {
1711d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1712d5c65159SKalle Valo struct wmi_bcn_tmpl_cmd *cmd;
1713d5c65159SKalle Valo struct wmi_bcn_prb_info *bcn_prb_info;
1714d5c65159SKalle Valo struct wmi_tlv *tlv;
1715d5c65159SKalle Valo struct sk_buff *skb;
1716d5c65159SKalle Valo void *ptr;
1717d5c65159SKalle Valo int ret, len;
1718d5c65159SKalle Valo size_t aligned_len = roundup(bcn->len, 4);
1719886433a9SJohn Crispin struct ieee80211_vif *vif;
1720886433a9SJohn Crispin struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev_id);
1721886433a9SJohn Crispin
1722886433a9SJohn Crispin if (!arvif) {
1723886433a9SJohn Crispin ath11k_warn(ar->ab, "failed to find arvif with vdev id %d\n", vdev_id);
1724886433a9SJohn Crispin return -EINVAL;
1725886433a9SJohn Crispin }
1726886433a9SJohn Crispin
1727886433a9SJohn Crispin vif = arvif->vif;
1728d5c65159SKalle Valo
1729d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len;
1730d5c65159SKalle Valo
17316bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1732d5c65159SKalle Valo if (!skb)
1733d5c65159SKalle Valo return -ENOMEM;
1734d5c65159SKalle Valo
1735d5c65159SKalle Valo cmd = (struct wmi_bcn_tmpl_cmd *)skb->data;
1736d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) |
1737d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1738d5c65159SKalle Valo cmd->vdev_id = vdev_id;
1739d5c65159SKalle Valo cmd->tim_ie_offset = offs->tim_offset;
1740886433a9SJohn Crispin
1741d0a9123eSJohannes Berg if (vif->bss_conf.csa_active) {
17428552a434SJohn Crispin cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0];
17438552a434SJohn Crispin cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1];
1744886433a9SJohn Crispin }
1745886433a9SJohn Crispin
1746d5c65159SKalle Valo cmd->buf_len = bcn->len;
1747335a9276SAloka Dixit cmd->mbssid_ie_offset = offs->mbssid_off;
174887bd4011SAloka Dixit cmd->ema_params = ema_params;
1749d5c65159SKalle Valo
1750d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd);
1751d5c65159SKalle Valo
1752d5c65159SKalle Valo bcn_prb_info = ptr;
1753d5c65159SKalle Valo len = sizeof(*bcn_prb_info);
1754d5c65159SKalle Valo bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1755d5c65159SKalle Valo WMI_TAG_BCN_PRB_INFO) |
1756d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1757d5c65159SKalle Valo bcn_prb_info->caps = 0;
1758d5c65159SKalle Valo bcn_prb_info->erp = 0;
1759d5c65159SKalle Valo
1760d5c65159SKalle Valo ptr += sizeof(*bcn_prb_info);
1761d5c65159SKalle Valo
1762d5c65159SKalle Valo tlv = ptr;
1763d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1764d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, aligned_len);
1765d5c65159SKalle Valo memcpy(tlv->value, bcn->data, bcn->len);
1766d5c65159SKalle Valo
1767d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID);
1768d5c65159SKalle Valo if (ret) {
1769d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n");
1770d5c65159SKalle Valo dev_kfree_skb(skb);
1771d5c65159SKalle Valo }
1772d5c65159SKalle Valo
177300608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd bcn tmpl");
177400608b40SKalle Valo
1775d5c65159SKalle Valo return ret;
1776d5c65159SKalle Valo }
1777d5c65159SKalle Valo
ath11k_wmi_vdev_install_key(struct ath11k * ar,struct wmi_vdev_install_key_arg * arg)1778d5c65159SKalle Valo int ath11k_wmi_vdev_install_key(struct ath11k *ar,
1779d5c65159SKalle Valo struct wmi_vdev_install_key_arg *arg)
1780d5c65159SKalle Valo {
1781d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1782d5c65159SKalle Valo struct wmi_vdev_install_key_cmd *cmd;
1783d5c65159SKalle Valo struct wmi_tlv *tlv;
1784d5c65159SKalle Valo struct sk_buff *skb;
1785d5c65159SKalle Valo int ret, len;
1786d5c65159SKalle Valo int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t));
1787d5c65159SKalle Valo
1788d5c65159SKalle Valo len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned;
1789d5c65159SKalle Valo
17906bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1791d5c65159SKalle Valo if (!skb)
1792d5c65159SKalle Valo return -ENOMEM;
1793d5c65159SKalle Valo
1794d5c65159SKalle Valo cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1795d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) |
1796d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1797d5c65159SKalle Valo cmd->vdev_id = arg->vdev_id;
1798d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1799d5c65159SKalle Valo cmd->key_idx = arg->key_idx;
1800d5c65159SKalle Valo cmd->key_flags = arg->key_flags;
1801d5c65159SKalle Valo cmd->key_cipher = arg->key_cipher;
1802d5c65159SKalle Valo cmd->key_len = arg->key_len;
1803d5c65159SKalle Valo cmd->key_txmic_len = arg->key_txmic_len;
1804d5c65159SKalle Valo cmd->key_rxmic_len = arg->key_rxmic_len;
1805d5c65159SKalle Valo
1806d5c65159SKalle Valo if (arg->key_rsc_counter)
1807d5c65159SKalle Valo memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter,
1808d5c65159SKalle Valo sizeof(struct wmi_key_seq_counter));
1809d5c65159SKalle Valo
1810d5c65159SKalle Valo tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
1811d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1812d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, key_len_aligned);
1813436a4e88SKarthikeyan Kathirvel if (arg->key_data)
1814d5c65159SKalle Valo memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned);
1815d5c65159SKalle Valo
1816d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1817d5c65159SKalle Valo if (ret) {
1818d5c65159SKalle Valo ath11k_warn(ar->ab,
1819d5c65159SKalle Valo "failed to send WMI_VDEV_INSTALL_KEY cmd\n");
1820d5c65159SKalle Valo dev_kfree_skb(skb);
1821d5c65159SKalle Valo }
1822d5c65159SKalle Valo
1823d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
182400608b40SKalle Valo "cmd vdev install key idx %d cipher %d len %d\n",
1825d5c65159SKalle Valo arg->key_idx, arg->key_cipher, arg->key_len);
1826d5c65159SKalle Valo
1827d5c65159SKalle Valo return ret;
1828d5c65159SKalle Valo }
1829d5c65159SKalle Valo
1830d5c65159SKalle Valo static inline void
ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd * cmd,struct peer_assoc_params * param,bool hw_crypto_disabled)1831d5c65159SKalle Valo ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd,
18321daf58b2SSeevalamuthu Mariappan struct peer_assoc_params *param,
18331daf58b2SSeevalamuthu Mariappan bool hw_crypto_disabled)
1834d5c65159SKalle Valo {
1835d5c65159SKalle Valo cmd->peer_flags = 0;
1836d5c65159SKalle Valo
1837d5c65159SKalle Valo if (param->is_wme_set) {
1838d5c65159SKalle Valo if (param->qos_flag)
1839d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_QOS;
1840d5c65159SKalle Valo if (param->apsd_flag)
1841d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_APSD;
1842d5c65159SKalle Valo if (param->ht_flag)
1843d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_HT;
1844d5c65159SKalle Valo if (param->bw_40)
1845d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_40MHZ;
1846d5c65159SKalle Valo if (param->bw_80)
1847d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_80MHZ;
1848d5c65159SKalle Valo if (param->bw_160)
1849d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_160MHZ;
1850d5c65159SKalle Valo
1851d5c65159SKalle Valo /* Typically if STBC is enabled for VHT it should be enabled
1852d5c65159SKalle Valo * for HT as well
1853d5c65159SKalle Valo **/
1854d5c65159SKalle Valo if (param->stbc_flag)
1855d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_STBC;
1856d5c65159SKalle Valo
1857d5c65159SKalle Valo /* Typically if LDPC is enabled for VHT it should be enabled
1858d5c65159SKalle Valo * for HT as well
1859d5c65159SKalle Valo **/
1860d5c65159SKalle Valo if (param->ldpc_flag)
1861d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_LDPC;
1862d5c65159SKalle Valo
1863d5c65159SKalle Valo if (param->static_mimops_flag)
1864d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1865d5c65159SKalle Valo if (param->dynamic_mimops_flag)
1866d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_DYN_MIMOPS;
1867d5c65159SKalle Valo if (param->spatial_mux_flag)
1868d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_SPATIAL_MUX;
1869d5c65159SKalle Valo if (param->vht_flag)
1870d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_VHT;
1871d5c65159SKalle Valo if (param->he_flag)
1872d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_HE;
18736d293d44SJohn Crispin if (param->twt_requester)
18746d293d44SJohn Crispin cmd->peer_flags |= WMI_PEER_TWT_REQ;
18756d293d44SJohn Crispin if (param->twt_responder)
18766d293d44SJohn Crispin cmd->peer_flags |= WMI_PEER_TWT_RESP;
1877d5c65159SKalle Valo }
1878d5c65159SKalle Valo
1879d5c65159SKalle Valo /* Suppress authorization for all AUTH modes that need 4-way handshake
1880d5c65159SKalle Valo * (during re-association).
1881d5c65159SKalle Valo * Authorization will be done for these modes on key installation.
1882d5c65159SKalle Valo */
1883d5c65159SKalle Valo if (param->auth_flag)
1884d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_AUTH;
188501e34233SVenkateswara Naralasetty if (param->need_ptk_4_way) {
1886d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1887c802b6d7SRameshkumar Sundaram if (!hw_crypto_disabled && param->is_assoc)
188801e34233SVenkateswara Naralasetty cmd->peer_flags &= ~WMI_PEER_AUTH;
188901e34233SVenkateswara Naralasetty }
1890d5c65159SKalle Valo if (param->need_gtk_2_way)
1891d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1892d5c65159SKalle Valo /* safe mode bypass the 4-way handshake */
1893d5c65159SKalle Valo if (param->safe_mode_enabled)
1894d5c65159SKalle Valo cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY |
1895d5c65159SKalle Valo WMI_PEER_NEED_GTK_2_WAY);
1896d5c65159SKalle Valo
1897d5c65159SKalle Valo if (param->is_pmf_enabled)
1898d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_PMF;
1899d5c65159SKalle Valo
1900d5c65159SKalle Valo /* Disable AMSDU for station transmit, if user configures it */
1901d5c65159SKalle Valo /* Disable AMSDU for AP transmit to 11n Stations, if user configures
1902d5c65159SKalle Valo * it
1903d5c65159SKalle Valo * if (param->amsdu_disable) Add after FW support
1904d5c65159SKalle Valo **/
1905d5c65159SKalle Valo
1906d5c65159SKalle Valo /* Target asserts if node is marked HT and all MCS is set to 0.
1907d5c65159SKalle Valo * Mark the node as non-HT if all the mcs rates are disabled through
1908d5c65159SKalle Valo * iwpriv
1909d5c65159SKalle Valo **/
1910d5c65159SKalle Valo if (param->peer_ht_rates.num_rates == 0)
1911d5c65159SKalle Valo cmd->peer_flags &= ~WMI_PEER_HT;
1912d5c65159SKalle Valo }
1913d5c65159SKalle Valo
ath11k_wmi_send_peer_assoc_cmd(struct ath11k * ar,struct peer_assoc_params * param)1914d5c65159SKalle Valo int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar,
1915d5c65159SKalle Valo struct peer_assoc_params *param)
1916d5c65159SKalle Valo {
1917d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
1918d5c65159SKalle Valo struct wmi_peer_assoc_complete_cmd *cmd;
1919d5c65159SKalle Valo struct wmi_vht_rate_set *mcs;
1920d5c65159SKalle Valo struct wmi_he_rate_set *he_mcs;
1921d5c65159SKalle Valo struct sk_buff *skb;
1922d5c65159SKalle Valo struct wmi_tlv *tlv;
1923d5c65159SKalle Valo void *ptr;
1924d5c65159SKalle Valo u32 peer_legacy_rates_align;
1925d5c65159SKalle Valo u32 peer_ht_rates_align;
1926d5c65159SKalle Valo int i, ret, len;
1927d5c65159SKalle Valo
1928d5c65159SKalle Valo peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates,
1929d5c65159SKalle Valo sizeof(u32));
1930d5c65159SKalle Valo peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates,
1931d5c65159SKalle Valo sizeof(u32));
1932d5c65159SKalle Valo
1933d5c65159SKalle Valo len = sizeof(*cmd) +
1934d5c65159SKalle Valo TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) +
1935d5c65159SKalle Valo TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) +
1936d5c65159SKalle Valo sizeof(*mcs) + TLV_HDR_SIZE +
1937d5c65159SKalle Valo (sizeof(*he_mcs) * param->peer_he_mcs_count);
1938d5c65159SKalle Valo
19396bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1940d5c65159SKalle Valo if (!skb)
1941d5c65159SKalle Valo return -ENOMEM;
1942d5c65159SKalle Valo
1943d5c65159SKalle Valo ptr = skb->data;
1944d5c65159SKalle Valo
1945d5c65159SKalle Valo cmd = ptr;
1946d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1947d5c65159SKalle Valo WMI_TAG_PEER_ASSOC_COMPLETE_CMD) |
1948d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1949d5c65159SKalle Valo
1950d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
1951d5c65159SKalle Valo
1952d5c65159SKalle Valo cmd->peer_new_assoc = param->peer_new_assoc;
1953d5c65159SKalle Valo cmd->peer_associd = param->peer_associd;
1954d5c65159SKalle Valo
19551daf58b2SSeevalamuthu Mariappan ath11k_wmi_copy_peer_flags(cmd, param,
19561daf58b2SSeevalamuthu Mariappan test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED,
19571daf58b2SSeevalamuthu Mariappan &ar->ab->dev_flags));
1958d5c65159SKalle Valo
1959d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac);
1960d5c65159SKalle Valo
1961d5c65159SKalle Valo cmd->peer_rate_caps = param->peer_rate_caps;
1962d5c65159SKalle Valo cmd->peer_caps = param->peer_caps;
1963d5c65159SKalle Valo cmd->peer_listen_intval = param->peer_listen_intval;
1964d5c65159SKalle Valo cmd->peer_ht_caps = param->peer_ht_caps;
1965d5c65159SKalle Valo cmd->peer_max_mpdu = param->peer_max_mpdu;
1966d5c65159SKalle Valo cmd->peer_mpdu_density = param->peer_mpdu_density;
1967d5c65159SKalle Valo cmd->peer_vht_caps = param->peer_vht_caps;
1968d5c65159SKalle Valo cmd->peer_phymode = param->peer_phymode;
1969d5c65159SKalle Valo
1970d5c65159SKalle Valo /* Update 11ax capabilities */
1971d5c65159SKalle Valo cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0];
1972d5c65159SKalle Valo cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1];
1973d5c65159SKalle Valo cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal;
197491270d70SPradeep Kumar Chitrapu cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz;
1975d5c65159SKalle Valo cmd->peer_he_ops = param->peer_he_ops;
1976d5c65159SKalle Valo memcpy(&cmd->peer_he_cap_phy, ¶m->peer_he_cap_phyinfo,
1977d5c65159SKalle Valo sizeof(param->peer_he_cap_phyinfo));
1978d5c65159SKalle Valo memcpy(&cmd->peer_ppet, ¶m->peer_ppet,
1979d5c65159SKalle Valo sizeof(param->peer_ppet));
1980d5c65159SKalle Valo
1981d5c65159SKalle Valo /* Update peer legacy rate information */
1982d5c65159SKalle Valo ptr += sizeof(*cmd);
1983d5c65159SKalle Valo
1984d5c65159SKalle Valo tlv = ptr;
1985d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1986d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align);
1987d5c65159SKalle Valo
1988d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
1989d5c65159SKalle Valo
1990d5c65159SKalle Valo cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates;
1991d5c65159SKalle Valo memcpy(ptr, param->peer_legacy_rates.rates,
1992d5c65159SKalle Valo param->peer_legacy_rates.num_rates);
1993d5c65159SKalle Valo
1994d5c65159SKalle Valo /* Update peer HT rate information */
1995d5c65159SKalle Valo ptr += peer_legacy_rates_align;
1996d5c65159SKalle Valo
1997d5c65159SKalle Valo tlv = ptr;
1998d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1999d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align);
2000d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2001d5c65159SKalle Valo cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates;
2002d5c65159SKalle Valo memcpy(ptr, param->peer_ht_rates.rates,
2003d5c65159SKalle Valo param->peer_ht_rates.num_rates);
2004d5c65159SKalle Valo
2005d5c65159SKalle Valo /* VHT Rates */
2006d5c65159SKalle Valo ptr += peer_ht_rates_align;
2007d5c65159SKalle Valo
2008d5c65159SKalle Valo mcs = ptr;
2009d5c65159SKalle Valo
2010d5c65159SKalle Valo mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) |
2011d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE);
2012d5c65159SKalle Valo
2013d5c65159SKalle Valo cmd->peer_nss = param->peer_nss;
2014d5c65159SKalle Valo
2015d5c65159SKalle Valo /* Update bandwidth-NSS mapping */
2016d5c65159SKalle Valo cmd->peer_bw_rxnss_override = 0;
2017d5c65159SKalle Valo cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override;
2018d5c65159SKalle Valo
2019d5c65159SKalle Valo if (param->vht_capable) {
2020d5c65159SKalle Valo mcs->rx_max_rate = param->rx_max_rate;
2021d5c65159SKalle Valo mcs->rx_mcs_set = param->rx_mcs_set;
2022d5c65159SKalle Valo mcs->tx_max_rate = param->tx_max_rate;
2023d5c65159SKalle Valo mcs->tx_mcs_set = param->tx_mcs_set;
2024d5c65159SKalle Valo }
2025d5c65159SKalle Valo
2026d5c65159SKalle Valo /* HE Rates */
2027d5c65159SKalle Valo cmd->peer_he_mcs = param->peer_he_mcs_count;
202891270d70SPradeep Kumar Chitrapu cmd->min_data_rate = param->min_data_rate;
2029d5c65159SKalle Valo
2030d5c65159SKalle Valo ptr += sizeof(*mcs);
2031d5c65159SKalle Valo
2032d5c65159SKalle Valo len = param->peer_he_mcs_count * sizeof(*he_mcs);
2033d5c65159SKalle Valo
2034d5c65159SKalle Valo tlv = ptr;
2035d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2036d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
2037d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2038d5c65159SKalle Valo
2039d5c65159SKalle Valo /* Loop through the HE rate set */
2040d5c65159SKalle Valo for (i = 0; i < param->peer_he_mcs_count; i++) {
2041d5c65159SKalle Valo he_mcs = ptr;
2042d5c65159SKalle Valo he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2043d5c65159SKalle Valo WMI_TAG_HE_RATE_SET) |
2044d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
2045d5c65159SKalle Valo sizeof(*he_mcs) - TLV_HDR_SIZE);
2046d5c65159SKalle Valo
204761fe43e7SMiles Hu he_mcs->rx_mcs_set = param->peer_he_tx_mcs_set[i];
204861fe43e7SMiles Hu he_mcs->tx_mcs_set = param->peer_he_rx_mcs_set[i];
2049d5c65159SKalle Valo ptr += sizeof(*he_mcs);
2050d5c65159SKalle Valo }
2051d5c65159SKalle Valo
2052d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID);
2053d5c65159SKalle Valo if (ret) {
2054d5c65159SKalle Valo ath11k_warn(ar->ab,
2055d5c65159SKalle Valo "failed to send WMI_PEER_ASSOC_CMDID\n");
2056d5c65159SKalle Valo dev_kfree_skb(skb);
2057d5c65159SKalle Valo }
2058d5c65159SKalle Valo
2059d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
206000608b40SKalle Valo "cmd peer assoc vdev id %d assoc id %d peer mac %pM peer_flags %x rate_caps %x peer_caps %x listen_intval %d ht_caps %x max_mpdu %d nss %d phymode %d peer_mpdu_density %d vht_caps %x he cap_info %x he ops %x he cap_info_ext %x he phy %x %x %x peer_bw_rxnss_override %x\n",
20611cb616a3SSriram R cmd->vdev_id, cmd->peer_associd, param->peer_mac,
20621cb616a3SSriram R cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps,
20631cb616a3SSriram R cmd->peer_listen_intval, cmd->peer_ht_caps,
20641cb616a3SSriram R cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode,
20651cb616a3SSriram R cmd->peer_mpdu_density,
20661cb616a3SSriram R cmd->peer_vht_caps, cmd->peer_he_cap_info,
20671cb616a3SSriram R cmd->peer_he_ops, cmd->peer_he_cap_info_ext,
20681cb616a3SSriram R cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1],
20691cb616a3SSriram R cmd->peer_he_cap_phy[2],
20701cb616a3SSriram R cmd->peer_bw_rxnss_override);
2071d5c65159SKalle Valo
2072d5c65159SKalle Valo return ret;
2073d5c65159SKalle Valo }
2074d5c65159SKalle Valo
ath11k_wmi_start_scan_init(struct ath11k * ar,struct scan_req_params * arg)2075d5c65159SKalle Valo void ath11k_wmi_start_scan_init(struct ath11k *ar,
2076d5c65159SKalle Valo struct scan_req_params *arg)
2077d5c65159SKalle Valo {
2078d5c65159SKalle Valo /* setup commonly used values */
2079d5c65159SKalle Valo arg->scan_req_id = 1;
20801f682dc9SWen Gong if (ar->state_11d == ATH11K_11D_PREPARING)
20811f682dc9SWen Gong arg->scan_priority = WMI_SCAN_PRIORITY_MEDIUM;
20821f682dc9SWen Gong else
2083d5c65159SKalle Valo arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
2084d5c65159SKalle Valo arg->dwell_time_active = 50;
2085d5c65159SKalle Valo arg->dwell_time_active_2g = 0;
2086d5c65159SKalle Valo arg->dwell_time_passive = 150;
2087194b8ea1SPradeep Kumar Chitrapu arg->dwell_time_active_6g = 40;
2088194b8ea1SPradeep Kumar Chitrapu arg->dwell_time_passive_6g = 30;
2089d5c65159SKalle Valo arg->min_rest_time = 50;
2090d5c65159SKalle Valo arg->max_rest_time = 500;
2091d5c65159SKalle Valo arg->repeat_probe_time = 0;
2092d5c65159SKalle Valo arg->probe_spacing_time = 0;
2093d5c65159SKalle Valo arg->idle_time = 0;
2094d5c65159SKalle Valo arg->max_scan_time = 20000;
2095d5c65159SKalle Valo arg->probe_delay = 5;
2096d5c65159SKalle Valo arg->notify_scan_events = WMI_SCAN_EVENT_STARTED |
2097d5c65159SKalle Valo WMI_SCAN_EVENT_COMPLETED |
2098d5c65159SKalle Valo WMI_SCAN_EVENT_BSS_CHANNEL |
2099d5c65159SKalle Valo WMI_SCAN_EVENT_FOREIGN_CHAN |
2100d5c65159SKalle Valo WMI_SCAN_EVENT_DEQUEUED;
2101d5c65159SKalle Valo arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2102cf8f3d4dSTamizh Chelvam Raja
2103cf8f3d4dSTamizh Chelvam Raja if (test_bit(WMI_TLV_SERVICE_PASSIVE_SCAN_START_TIME_ENHANCE,
2104cf8f3d4dSTamizh Chelvam Raja ar->ab->wmi_ab.svc_map))
2105cf8f3d4dSTamizh Chelvam Raja arg->scan_ctrl_flags_ext |=
2106cf8f3d4dSTamizh Chelvam Raja WMI_SCAN_FLAG_EXT_PASSIVE_SCAN_START_TIME_ENHANCE;
2107cf8f3d4dSTamizh Chelvam Raja
2108d5c65159SKalle Valo arg->num_bssid = 1;
2109fa7572c2SCarl Huang
2110fa7572c2SCarl Huang /* fill bssid_list[0] with 0xff, otherwise bssid and RA will be
2111fa7572c2SCarl Huang * ZEROs in probe request
2112fa7572c2SCarl Huang */
2113fa7572c2SCarl Huang eth_broadcast_addr(arg->bssid_list[0].addr);
2114d5c65159SKalle Valo }
2115d5c65159SKalle Valo
2116d5c65159SKalle Valo static inline void
ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd * cmd,struct scan_req_params * param)2117d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
2118d5c65159SKalle Valo struct scan_req_params *param)
2119d5c65159SKalle Valo {
2120d5c65159SKalle Valo /* Scan events subscription */
2121d5c65159SKalle Valo if (param->scan_ev_started)
2122d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_STARTED;
2123d5c65159SKalle Valo if (param->scan_ev_completed)
2124d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_COMPLETED;
2125d5c65159SKalle Valo if (param->scan_ev_bss_chan)
2126d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_BSS_CHANNEL;
2127d5c65159SKalle Valo if (param->scan_ev_foreign_chan)
2128d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN;
2129d5c65159SKalle Valo if (param->scan_ev_dequeued)
2130d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_DEQUEUED;
2131d5c65159SKalle Valo if (param->scan_ev_preempted)
2132d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_PREEMPTED;
2133d5c65159SKalle Valo if (param->scan_ev_start_failed)
2134d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_START_FAILED;
2135d5c65159SKalle Valo if (param->scan_ev_restarted)
2136d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_RESTARTED;
2137d5c65159SKalle Valo if (param->scan_ev_foreign_chn_exit)
2138d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
2139d5c65159SKalle Valo if (param->scan_ev_suspended)
2140d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_SUSPENDED;
2141d5c65159SKalle Valo if (param->scan_ev_resumed)
2142d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_RESUMED;
2143d5c65159SKalle Valo
2144d5c65159SKalle Valo /** Set scan control flags */
2145d5c65159SKalle Valo cmd->scan_ctrl_flags = 0;
2146d5c65159SKalle Valo if (param->scan_f_passive)
2147d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2148d5c65159SKalle Valo if (param->scan_f_strict_passive_pch)
2149d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
2150d5c65159SKalle Valo if (param->scan_f_promisc_mode)
2151d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROMISCUOS;
2152d5c65159SKalle Valo if (param->scan_f_capture_phy_err)
2153d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_CAPTURE_PHY_ERROR;
2154d5c65159SKalle Valo if (param->scan_f_half_rate)
2155d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
2156d5c65159SKalle Valo if (param->scan_f_quarter_rate)
2157d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
2158d5c65159SKalle Valo if (param->scan_f_cck_rates)
2159d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2160d5c65159SKalle Valo if (param->scan_f_ofdm_rates)
2161d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
2162d5c65159SKalle Valo if (param->scan_f_chan_stat_evnt)
2163d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2164d5c65159SKalle Valo if (param->scan_f_filter_prb_req)
2165d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2166d5c65159SKalle Valo if (param->scan_f_bcast_probe)
2167d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_BCAST_PROBE_REQ;
2168d5c65159SKalle Valo if (param->scan_f_offchan_mgmt_tx)
2169d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_MGMT_TX;
2170d5c65159SKalle Valo if (param->scan_f_offchan_data_tx)
2171d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_DATA_TX;
2172d5c65159SKalle Valo if (param->scan_f_force_active_dfs_chn)
2173d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
2174d5c65159SKalle Valo if (param->scan_f_add_tpc_ie_in_probe)
2175d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
2176d5c65159SKalle Valo if (param->scan_f_add_ds_ie_in_probe)
2177d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
2178d5c65159SKalle Valo if (param->scan_f_add_spoofed_mac_in_probe)
2179d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
2180d5c65159SKalle Valo if (param->scan_f_add_rand_seq_in_probe)
2181d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
2182d5c65159SKalle Valo if (param->scan_f_en_ie_whitelist_in_probe)
2183d5c65159SKalle Valo cmd->scan_ctrl_flags |=
2184d5c65159SKalle Valo WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
2185d5c65159SKalle Valo
2186d5c65159SKalle Valo /* for adaptive scan mode using 3 bits (21 - 23 bits) */
2187d5c65159SKalle Valo WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
2188d5c65159SKalle Valo param->adaptive_dwell_time_mode);
2189cf8f3d4dSTamizh Chelvam Raja
2190cf8f3d4dSTamizh Chelvam Raja cmd->scan_ctrl_flags_ext = param->scan_ctrl_flags_ext;
2191d5c65159SKalle Valo }
2192d5c65159SKalle Valo
ath11k_wmi_send_scan_start_cmd(struct ath11k * ar,struct scan_req_params * params)2193d5c65159SKalle Valo int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
2194d5c65159SKalle Valo struct scan_req_params *params)
2195d5c65159SKalle Valo {
2196d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2197d5c65159SKalle Valo struct wmi_start_scan_cmd *cmd;
2198d5c65159SKalle Valo struct wmi_ssid *ssid = NULL;
2199d5c65159SKalle Valo struct wmi_mac_addr *bssid;
2200d5c65159SKalle Valo struct sk_buff *skb;
2201d5c65159SKalle Valo struct wmi_tlv *tlv;
2202d5c65159SKalle Valo void *ptr;
2203d5c65159SKalle Valo int i, ret, len;
2204d5c65159SKalle Valo u32 *tmp_ptr;
2205a658c929SSven Eckelmann u16 extraie_len_with_pad = 0;
220674601ecfSPradeep Kumar Chitrapu struct hint_short_ssid *s_ssid = NULL;
220774601ecfSPradeep Kumar Chitrapu struct hint_bssid *hint_bssid = NULL;
2208d5c65159SKalle Valo
2209d5c65159SKalle Valo len = sizeof(*cmd);
2210d5c65159SKalle Valo
2211d5c65159SKalle Valo len += TLV_HDR_SIZE;
2212d5c65159SKalle Valo if (params->num_chan)
2213d5c65159SKalle Valo len += params->num_chan * sizeof(u32);
2214d5c65159SKalle Valo
2215d5c65159SKalle Valo len += TLV_HDR_SIZE;
2216d5c65159SKalle Valo if (params->num_ssids)
2217d5c65159SKalle Valo len += params->num_ssids * sizeof(*ssid);
2218d5c65159SKalle Valo
2219d5c65159SKalle Valo len += TLV_HDR_SIZE;
2220d5c65159SKalle Valo if (params->num_bssid)
2221d5c65159SKalle Valo len += sizeof(*bssid) * params->num_bssid;
2222d5c65159SKalle Valo
2223d5c65159SKalle Valo len += TLV_HDR_SIZE;
2224a658c929SSven Eckelmann if (params->extraie.len && params->extraie.len <= 0xFFFF)
2225d5c65159SKalle Valo extraie_len_with_pad =
2226d5c65159SKalle Valo roundup(params->extraie.len, sizeof(u32));
2227d5c65159SKalle Valo len += extraie_len_with_pad;
2228d5c65159SKalle Valo
222974601ecfSPradeep Kumar Chitrapu if (params->num_hint_bssid)
223074601ecfSPradeep Kumar Chitrapu len += TLV_HDR_SIZE +
223174601ecfSPradeep Kumar Chitrapu params->num_hint_bssid * sizeof(struct hint_bssid);
223274601ecfSPradeep Kumar Chitrapu
223374601ecfSPradeep Kumar Chitrapu if (params->num_hint_s_ssid)
223474601ecfSPradeep Kumar Chitrapu len += TLV_HDR_SIZE +
223574601ecfSPradeep Kumar Chitrapu params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
223674601ecfSPradeep Kumar Chitrapu
22376bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2238d5c65159SKalle Valo if (!skb)
2239d5c65159SKalle Valo return -ENOMEM;
2240d5c65159SKalle Valo
2241d5c65159SKalle Valo ptr = skb->data;
2242d5c65159SKalle Valo
2243d5c65159SKalle Valo cmd = ptr;
2244d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
2245d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2246d5c65159SKalle Valo
2247d5c65159SKalle Valo cmd->scan_id = params->scan_id;
2248d5c65159SKalle Valo cmd->scan_req_id = params->scan_req_id;
2249d5c65159SKalle Valo cmd->vdev_id = params->vdev_id;
2250d5c65159SKalle Valo cmd->scan_priority = params->scan_priority;
2251d5c65159SKalle Valo cmd->notify_scan_events = params->notify_scan_events;
2252d5c65159SKalle Valo
2253d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
2254d5c65159SKalle Valo
2255d5c65159SKalle Valo cmd->dwell_time_active = params->dwell_time_active;
2256d5c65159SKalle Valo cmd->dwell_time_active_2g = params->dwell_time_active_2g;
2257d5c65159SKalle Valo cmd->dwell_time_passive = params->dwell_time_passive;
2258194b8ea1SPradeep Kumar Chitrapu cmd->dwell_time_active_6g = params->dwell_time_active_6g;
2259194b8ea1SPradeep Kumar Chitrapu cmd->dwell_time_passive_6g = params->dwell_time_passive_6g;
2260d5c65159SKalle Valo cmd->min_rest_time = params->min_rest_time;
2261d5c65159SKalle Valo cmd->max_rest_time = params->max_rest_time;
2262d5c65159SKalle Valo cmd->repeat_probe_time = params->repeat_probe_time;
2263d5c65159SKalle Valo cmd->probe_spacing_time = params->probe_spacing_time;
2264d5c65159SKalle Valo cmd->idle_time = params->idle_time;
2265d5c65159SKalle Valo cmd->max_scan_time = params->max_scan_time;
2266d5c65159SKalle Valo cmd->probe_delay = params->probe_delay;
2267d5c65159SKalle Valo cmd->burst_duration = params->burst_duration;
2268d5c65159SKalle Valo cmd->num_chan = params->num_chan;
2269d5c65159SKalle Valo cmd->num_bssid = params->num_bssid;
2270d5c65159SKalle Valo cmd->num_ssids = params->num_ssids;
2271d5c65159SKalle Valo cmd->ie_len = params->extraie.len;
2272d5c65159SKalle Valo cmd->n_probes = params->n_probes;
22739cbd7fc9SCarl Huang ether_addr_copy(cmd->mac_addr.addr, params->mac_addr.addr);
22749cbd7fc9SCarl Huang ether_addr_copy(cmd->mac_mask.addr, params->mac_mask.addr);
2275d5c65159SKalle Valo
2276d5c65159SKalle Valo ptr += sizeof(*cmd);
2277d5c65159SKalle Valo
2278d5c65159SKalle Valo len = params->num_chan * sizeof(u32);
2279d5c65159SKalle Valo
2280d5c65159SKalle Valo tlv = ptr;
2281d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
2282d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
2283d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2284d5c65159SKalle Valo tmp_ptr = (u32 *)ptr;
2285d5c65159SKalle Valo
2286d5c65159SKalle Valo for (i = 0; i < params->num_chan; ++i)
2287d5c65159SKalle Valo tmp_ptr[i] = params->chan_list[i];
2288d5c65159SKalle Valo
2289d5c65159SKalle Valo ptr += len;
2290d5c65159SKalle Valo
2291d5c65159SKalle Valo len = params->num_ssids * sizeof(*ssid);
2292d5c65159SKalle Valo tlv = ptr;
2293d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2294d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
2295d5c65159SKalle Valo
2296d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2297d5c65159SKalle Valo
2298d5c65159SKalle Valo if (params->num_ssids) {
2299d5c65159SKalle Valo ssid = ptr;
2300d5c65159SKalle Valo for (i = 0; i < params->num_ssids; ++i) {
2301d5c65159SKalle Valo ssid->ssid_len = params->ssid[i].length;
2302d5c65159SKalle Valo memcpy(ssid->ssid, params->ssid[i].ssid,
2303d5c65159SKalle Valo params->ssid[i].length);
2304d5c65159SKalle Valo ssid++;
2305d5c65159SKalle Valo }
2306d5c65159SKalle Valo }
2307d5c65159SKalle Valo
2308d5c65159SKalle Valo ptr += (params->num_ssids * sizeof(*ssid));
2309d5c65159SKalle Valo len = params->num_bssid * sizeof(*bssid);
2310d5c65159SKalle Valo tlv = ptr;
2311d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2312d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
2313d5c65159SKalle Valo
2314d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2315d5c65159SKalle Valo bssid = ptr;
2316d5c65159SKalle Valo
2317d5c65159SKalle Valo if (params->num_bssid) {
2318d5c65159SKalle Valo for (i = 0; i < params->num_bssid; ++i) {
2319d5c65159SKalle Valo ether_addr_copy(bssid->addr,
2320d5c65159SKalle Valo params->bssid_list[i].addr);
2321d5c65159SKalle Valo bssid++;
2322d5c65159SKalle Valo }
2323d5c65159SKalle Valo }
2324d5c65159SKalle Valo
2325d5c65159SKalle Valo ptr += params->num_bssid * sizeof(*bssid);
2326d5c65159SKalle Valo
2327d5c65159SKalle Valo len = extraie_len_with_pad;
2328d5c65159SKalle Valo tlv = ptr;
2329d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2330d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
2331d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2332d5c65159SKalle Valo
2333a658c929SSven Eckelmann if (extraie_len_with_pad)
2334d5c65159SKalle Valo memcpy(ptr, params->extraie.ptr,
2335d5c65159SKalle Valo params->extraie.len);
2336d5c65159SKalle Valo
2337d5c65159SKalle Valo ptr += extraie_len_with_pad;
2338d5c65159SKalle Valo
233974601ecfSPradeep Kumar Chitrapu if (params->num_hint_s_ssid) {
234074601ecfSPradeep Kumar Chitrapu len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
234174601ecfSPradeep Kumar Chitrapu tlv = ptr;
234274601ecfSPradeep Kumar Chitrapu tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
234374601ecfSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, len);
234474601ecfSPradeep Kumar Chitrapu ptr += TLV_HDR_SIZE;
234574601ecfSPradeep Kumar Chitrapu s_ssid = ptr;
234674601ecfSPradeep Kumar Chitrapu for (i = 0; i < params->num_hint_s_ssid; ++i) {
234774601ecfSPradeep Kumar Chitrapu s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
234874601ecfSPradeep Kumar Chitrapu s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
234974601ecfSPradeep Kumar Chitrapu s_ssid++;
235074601ecfSPradeep Kumar Chitrapu }
235174601ecfSPradeep Kumar Chitrapu ptr += len;
235274601ecfSPradeep Kumar Chitrapu }
235374601ecfSPradeep Kumar Chitrapu
235474601ecfSPradeep Kumar Chitrapu if (params->num_hint_bssid) {
235574601ecfSPradeep Kumar Chitrapu len = params->num_hint_bssid * sizeof(struct hint_bssid);
235674601ecfSPradeep Kumar Chitrapu tlv = ptr;
235774601ecfSPradeep Kumar Chitrapu tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
235874601ecfSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, len);
235974601ecfSPradeep Kumar Chitrapu ptr += TLV_HDR_SIZE;
236074601ecfSPradeep Kumar Chitrapu hint_bssid = ptr;
236174601ecfSPradeep Kumar Chitrapu for (i = 0; i < params->num_hint_bssid; ++i) {
236274601ecfSPradeep Kumar Chitrapu hint_bssid->freq_flags =
236374601ecfSPradeep Kumar Chitrapu params->hint_bssid[i].freq_flags;
236474601ecfSPradeep Kumar Chitrapu ether_addr_copy(¶ms->hint_bssid[i].bssid.addr[0],
236574601ecfSPradeep Kumar Chitrapu &hint_bssid->bssid.addr[0]);
236674601ecfSPradeep Kumar Chitrapu hint_bssid++;
236774601ecfSPradeep Kumar Chitrapu }
236874601ecfSPradeep Kumar Chitrapu }
236974601ecfSPradeep Kumar Chitrapu
2370d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
2371d5c65159SKalle Valo WMI_START_SCAN_CMDID);
2372d5c65159SKalle Valo if (ret) {
2373d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2374d5c65159SKalle Valo dev_kfree_skb(skb);
2375d5c65159SKalle Valo }
2376d5c65159SKalle Valo
237700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd start scan");
237800608b40SKalle Valo
2379d5c65159SKalle Valo return ret;
2380d5c65159SKalle Valo }
2381d5c65159SKalle Valo
ath11k_wmi_send_scan_stop_cmd(struct ath11k * ar,struct scan_cancel_param * param)2382d5c65159SKalle Valo int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2383d5c65159SKalle Valo struct scan_cancel_param *param)
2384d5c65159SKalle Valo {
2385d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2386d5c65159SKalle Valo struct wmi_stop_scan_cmd *cmd;
2387d5c65159SKalle Valo struct sk_buff *skb;
2388d5c65159SKalle Valo int ret;
2389d5c65159SKalle Valo
23906bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2391d5c65159SKalle Valo if (!skb)
2392d5c65159SKalle Valo return -ENOMEM;
2393d5c65159SKalle Valo
2394d5c65159SKalle Valo cmd = (struct wmi_stop_scan_cmd *)skb->data;
2395d5c65159SKalle Valo
2396d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2397d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2398d5c65159SKalle Valo
2399d5c65159SKalle Valo cmd->vdev_id = param->vdev_id;
2400d5c65159SKalle Valo cmd->requestor = param->requester;
2401d5c65159SKalle Valo cmd->scan_id = param->scan_id;
2402d5c65159SKalle Valo cmd->pdev_id = param->pdev_id;
2403d5c65159SKalle Valo /* stop the scan with the corresponding scan_id */
2404d5c65159SKalle Valo if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2405d5c65159SKalle Valo /* Cancelling all scans */
2406d5c65159SKalle Valo cmd->req_type = WMI_SCAN_STOP_ALL;
2407d5c65159SKalle Valo } else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2408d5c65159SKalle Valo /* Cancelling VAP scans */
2409d5c65159SKalle Valo cmd->req_type = WMI_SCN_STOP_VAP_ALL;
2410d5c65159SKalle Valo } else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2411d5c65159SKalle Valo /* Cancelling specific scan */
2412d5c65159SKalle Valo cmd->req_type = WMI_SCAN_STOP_ONE;
2413d5c65159SKalle Valo } else {
2414d5c65159SKalle Valo ath11k_warn(ar->ab, "invalid scan cancel param %d",
2415d5c65159SKalle Valo param->req_type);
2416d5c65159SKalle Valo dev_kfree_skb(skb);
2417d5c65159SKalle Valo return -EINVAL;
2418d5c65159SKalle Valo }
2419d5c65159SKalle Valo
2420d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
2421d5c65159SKalle Valo WMI_STOP_SCAN_CMDID);
2422d5c65159SKalle Valo if (ret) {
2423d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2424d5c65159SKalle Valo dev_kfree_skb(skb);
2425d5c65159SKalle Valo }
2426d5c65159SKalle Valo
242700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd stop scan");
242800608b40SKalle Valo
2429d5c65159SKalle Valo return ret;
2430d5c65159SKalle Valo }
2431d5c65159SKalle Valo
ath11k_wmi_send_scan_chan_list_cmd(struct ath11k * ar,struct scan_chan_list_params * chan_list)2432d5c65159SKalle Valo int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2433d5c65159SKalle Valo struct scan_chan_list_params *chan_list)
2434d5c65159SKalle Valo {
2435d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2436d5c65159SKalle Valo struct wmi_scan_chan_list_cmd *cmd;
2437d5c65159SKalle Valo struct sk_buff *skb;
2438d5c65159SKalle Valo struct wmi_channel *chan_info;
2439d5c65159SKalle Valo struct channel_param *tchan_info;
2440d5c65159SKalle Valo struct wmi_tlv *tlv;
2441d5c65159SKalle Valo void *ptr;
2442d5c65159SKalle Valo int i, ret, len;
2443bff621fdSPradeep Kumar Chitrapu u16 num_send_chans, num_sends = 0, max_chan_limit = 0;
2444d5c65159SKalle Valo u32 *reg1, *reg2;
2445d5c65159SKalle Valo
2446b2549465SGustavo A. R. Silva tchan_info = chan_list->ch_param;
2447bff621fdSPradeep Kumar Chitrapu while (chan_list->nallchans) {
2448bff621fdSPradeep Kumar Chitrapu len = sizeof(*cmd) + TLV_HDR_SIZE;
2449bff621fdSPradeep Kumar Chitrapu max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) /
2450bff621fdSPradeep Kumar Chitrapu sizeof(*chan_info);
2451bff621fdSPradeep Kumar Chitrapu
2452bff621fdSPradeep Kumar Chitrapu if (chan_list->nallchans > max_chan_limit)
2453bff621fdSPradeep Kumar Chitrapu num_send_chans = max_chan_limit;
2454bff621fdSPradeep Kumar Chitrapu else
2455bff621fdSPradeep Kumar Chitrapu num_send_chans = chan_list->nallchans;
2456bff621fdSPradeep Kumar Chitrapu
2457bff621fdSPradeep Kumar Chitrapu chan_list->nallchans -= num_send_chans;
2458bff621fdSPradeep Kumar Chitrapu len += sizeof(*chan_info) * num_send_chans;
2459d5c65159SKalle Valo
24606bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2461d5c65159SKalle Valo if (!skb)
2462d5c65159SKalle Valo return -ENOMEM;
2463d5c65159SKalle Valo
2464d5c65159SKalle Valo cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2465d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2466d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2467bff621fdSPradeep Kumar Chitrapu cmd->pdev_id = chan_list->pdev_id;
2468bff621fdSPradeep Kumar Chitrapu cmd->num_scan_chans = num_send_chans;
2469bff621fdSPradeep Kumar Chitrapu if (num_sends)
2470bff621fdSPradeep Kumar Chitrapu cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG;
2471d5c65159SKalle Valo
2472d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2473fc3b984aSKalle Valo "no.of chan = %d len = %d pdev_id = %d num_sends = %d\n",
2474bff621fdSPradeep Kumar Chitrapu num_send_chans, len, cmd->pdev_id, num_sends);
2475d5c65159SKalle Valo
2476d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd);
2477d5c65159SKalle Valo
2478bff621fdSPradeep Kumar Chitrapu len = sizeof(*chan_info) * num_send_chans;
2479d5c65159SKalle Valo tlv = ptr;
2480d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2481d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2482d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2483d5c65159SKalle Valo
2484bff621fdSPradeep Kumar Chitrapu for (i = 0; i < num_send_chans; ++i) {
2485d5c65159SKalle Valo chan_info = ptr;
2486d5c65159SKalle Valo memset(chan_info, 0, sizeof(*chan_info));
2487d5c65159SKalle Valo len = sizeof(*chan_info);
2488d5c65159SKalle Valo chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2489d5c65159SKalle Valo WMI_TAG_CHANNEL) |
2490d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
2491d5c65159SKalle Valo len - TLV_HDR_SIZE);
2492d5c65159SKalle Valo
2493d5c65159SKalle Valo reg1 = &chan_info->reg_info_1;
2494d5c65159SKalle Valo reg2 = &chan_info->reg_info_2;
2495d5c65159SKalle Valo chan_info->mhz = tchan_info->mhz;
2496d5c65159SKalle Valo chan_info->band_center_freq1 = tchan_info->cfreq1;
2497d5c65159SKalle Valo chan_info->band_center_freq2 = tchan_info->cfreq2;
2498d5c65159SKalle Valo
2499d5c65159SKalle Valo if (tchan_info->is_chan_passive)
2500d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_PASSIVE;
25019f056ed8SJohn Crispin if (tchan_info->allow_he)
25029f056ed8SJohn Crispin chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
25039f056ed8SJohn Crispin else if (tchan_info->allow_vht)
2504d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2505d5c65159SKalle Valo else if (tchan_info->allow_ht)
2506d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2507d5c65159SKalle Valo if (tchan_info->half_rate)
2508d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2509d5c65159SKalle Valo if (tchan_info->quarter_rate)
2510d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2511bff621fdSPradeep Kumar Chitrapu if (tchan_info->psc_channel)
2512bff621fdSPradeep Kumar Chitrapu chan_info->info |= WMI_CHAN_INFO_PSC;
25138cd5c084SBaochen Qiang if (tchan_info->dfs_set)
25148cd5c084SBaochen Qiang chan_info->info |= WMI_CHAN_INFO_DFS;
2515d5c65159SKalle Valo
2516d5c65159SKalle Valo chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2517d5c65159SKalle Valo tchan_info->phy_mode);
2518d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2519d5c65159SKalle Valo tchan_info->minpower);
2520d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2521d5c65159SKalle Valo tchan_info->maxpower);
2522d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2523d5c65159SKalle Valo tchan_info->maxregpower);
2524d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2525d5c65159SKalle Valo tchan_info->reg_class_id);
2526d5c65159SKalle Valo *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2527d5c65159SKalle Valo tchan_info->antennamax);
25289212c1b9SP Praneesh *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
25299212c1b9SP Praneesh tchan_info->maxregpower);
2530d5c65159SKalle Valo
2531d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2532fc3b984aSKalle Valo "chan scan list chan[%d] = %u, chan_info->info %8x\n",
2533bff621fdSPradeep Kumar Chitrapu i, chan_info->mhz, chan_info->info);
2534d5c65159SKalle Valo
2535d5c65159SKalle Valo ptr += sizeof(*chan_info);
2536d5c65159SKalle Valo
2537d5c65159SKalle Valo tchan_info++;
2538d5c65159SKalle Valo }
2539d5c65159SKalle Valo
2540d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2541d5c65159SKalle Valo if (ret) {
2542d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2543d5c65159SKalle Valo dev_kfree_skb(skb);
2544bff621fdSPradeep Kumar Chitrapu return ret;
2545d5c65159SKalle Valo }
2546d5c65159SKalle Valo
254700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd scan chan list channels %d",
254800608b40SKalle Valo num_send_chans);
254900608b40SKalle Valo
2550bff621fdSPradeep Kumar Chitrapu num_sends++;
2551bff621fdSPradeep Kumar Chitrapu }
2552bff621fdSPradeep Kumar Chitrapu
2553bff621fdSPradeep Kumar Chitrapu return 0;
2554d5c65159SKalle Valo }
2555d5c65159SKalle Valo
ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k * ar,u32 vdev_id,struct wmi_wmm_params_all_arg * param)2556d5c65159SKalle Valo int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2557d5c65159SKalle Valo struct wmi_wmm_params_all_arg *param)
2558d5c65159SKalle Valo {
2559d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2560d5c65159SKalle Valo struct wmi_vdev_set_wmm_params_cmd *cmd;
2561d5c65159SKalle Valo struct wmi_wmm_params *wmm_param;
2562d5c65159SKalle Valo struct wmi_wmm_params_arg *wmi_wmm_arg;
2563d5c65159SKalle Valo struct sk_buff *skb;
2564d5c65159SKalle Valo int ret, ac;
2565d5c65159SKalle Valo
25666bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2567d5c65159SKalle Valo if (!skb)
2568d5c65159SKalle Valo return -ENOMEM;
2569d5c65159SKalle Valo
2570d5c65159SKalle Valo cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2571d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2572d5c65159SKalle Valo WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2573d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2574d5c65159SKalle Valo
2575d5c65159SKalle Valo cmd->vdev_id = vdev_id;
2576d5c65159SKalle Valo cmd->wmm_param_type = 0;
2577d5c65159SKalle Valo
2578d5c65159SKalle Valo for (ac = 0; ac < WME_NUM_AC; ac++) {
2579d5c65159SKalle Valo switch (ac) {
2580d5c65159SKalle Valo case WME_AC_BE:
2581d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_be;
2582d5c65159SKalle Valo break;
2583d5c65159SKalle Valo case WME_AC_BK:
2584d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_bk;
2585d5c65159SKalle Valo break;
2586d5c65159SKalle Valo case WME_AC_VI:
2587d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_vi;
2588d5c65159SKalle Valo break;
2589d5c65159SKalle Valo case WME_AC_VO:
2590d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_vo;
2591d5c65159SKalle Valo break;
2592d5c65159SKalle Valo }
2593d5c65159SKalle Valo
2594d5c65159SKalle Valo wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2595d5c65159SKalle Valo wmm_param->tlv_header =
2596d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG,
2597d5c65159SKalle Valo WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2598d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
2599d5c65159SKalle Valo sizeof(*wmm_param) - TLV_HDR_SIZE);
2600d5c65159SKalle Valo
2601d5c65159SKalle Valo wmm_param->aifs = wmi_wmm_arg->aifs;
2602d5c65159SKalle Valo wmm_param->cwmin = wmi_wmm_arg->cwmin;
2603d5c65159SKalle Valo wmm_param->cwmax = wmi_wmm_arg->cwmax;
2604d5c65159SKalle Valo wmm_param->txoplimit = wmi_wmm_arg->txop;
2605d5c65159SKalle Valo wmm_param->acm = wmi_wmm_arg->acm;
2606d5c65159SKalle Valo wmm_param->no_ack = wmi_wmm_arg->no_ack;
2607d5c65159SKalle Valo
2608d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2609fc3b984aSKalle Valo "wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2610d5c65159SKalle Valo ac, wmm_param->aifs, wmm_param->cwmin,
2611d5c65159SKalle Valo wmm_param->cwmax, wmm_param->txoplimit,
2612d5c65159SKalle Valo wmm_param->acm, wmm_param->no_ack);
2613d5c65159SKalle Valo }
2614d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
2615d5c65159SKalle Valo WMI_VDEV_SET_WMM_PARAMS_CMDID);
2616d5c65159SKalle Valo if (ret) {
2617d5c65159SKalle Valo ath11k_warn(ar->ab,
2618d5c65159SKalle Valo "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2619d5c65159SKalle Valo dev_kfree_skb(skb);
2620d5c65159SKalle Valo }
2621d5c65159SKalle Valo
262200608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd vdev set wmm params");
262300608b40SKalle Valo
2624d5c65159SKalle Valo return ret;
2625d5c65159SKalle Valo }
2626d5c65159SKalle Valo
ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k * ar,u32 pdev_id)2627d5c65159SKalle Valo int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2628d5c65159SKalle Valo u32 pdev_id)
2629d5c65159SKalle Valo {
2630d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2631d5c65159SKalle Valo struct wmi_dfs_phyerr_offload_cmd *cmd;
2632d5c65159SKalle Valo struct sk_buff *skb;
2633d5c65159SKalle Valo int ret;
2634d5c65159SKalle Valo
26356bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2636d5c65159SKalle Valo if (!skb)
2637d5c65159SKalle Valo return -ENOMEM;
2638d5c65159SKalle Valo
2639d5c65159SKalle Valo cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2640d5c65159SKalle Valo cmd->tlv_header =
2641d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG,
2642d5c65159SKalle Valo WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2643d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2644d5c65159SKalle Valo
2645d5c65159SKalle Valo cmd->pdev_id = pdev_id;
2646d5c65159SKalle Valo
2647d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
2648d5c65159SKalle Valo WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2649d5c65159SKalle Valo if (ret) {
2650d5c65159SKalle Valo ath11k_warn(ar->ab,
2651d5c65159SKalle Valo "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2652d5c65159SKalle Valo dev_kfree_skb(skb);
2653d5c65159SKalle Valo }
2654d5c65159SKalle Valo
265500608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
265600608b40SKalle Valo "cmd pdev dfs phyerr offload enable pdev id %d\n", pdev_id);
265700608b40SKalle Valo
2658d5c65159SKalle Valo return ret;
2659d5c65159SKalle Valo }
2660d5c65159SKalle Valo
ath11k_wmi_delba_send(struct ath11k * ar,u32 vdev_id,const u8 * mac,u32 tid,u32 initiator,u32 reason)26619556dfa2SMaharaja Kennadyrajan int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26629556dfa2SMaharaja Kennadyrajan u32 tid, u32 initiator, u32 reason)
26639556dfa2SMaharaja Kennadyrajan {
26649556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi;
26659556dfa2SMaharaja Kennadyrajan struct wmi_delba_send_cmd *cmd;
26669556dfa2SMaharaja Kennadyrajan struct sk_buff *skb;
26679556dfa2SMaharaja Kennadyrajan int ret;
26689556dfa2SMaharaja Kennadyrajan
26699556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
26709556dfa2SMaharaja Kennadyrajan if (!skb)
26719556dfa2SMaharaja Kennadyrajan return -ENOMEM;
26729556dfa2SMaharaja Kennadyrajan
26739556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_delba_send_cmd *)skb->data;
26749556dfa2SMaharaja Kennadyrajan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) |
26759556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
26769556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id;
26779556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac);
26789556dfa2SMaharaja Kennadyrajan cmd->tid = tid;
26799556dfa2SMaharaja Kennadyrajan cmd->initiator = initiator;
26809556dfa2SMaharaja Kennadyrajan cmd->reasoncode = reason;
26819556dfa2SMaharaja Kennadyrajan
26829556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID);
26839556dfa2SMaharaja Kennadyrajan
26849556dfa2SMaharaja Kennadyrajan if (ret) {
26859556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab,
26869556dfa2SMaharaja Kennadyrajan "failed to send WMI_DELBA_SEND_CMDID cmd\n");
26879556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb);
26889556dfa2SMaharaja Kennadyrajan }
26899556dfa2SMaharaja Kennadyrajan
269000608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
269100608b40SKalle Valo "cmd delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
269200608b40SKalle Valo vdev_id, mac, tid, initiator, reason);
269300608b40SKalle Valo
26949556dfa2SMaharaja Kennadyrajan return ret;
26959556dfa2SMaharaja Kennadyrajan }
26969556dfa2SMaharaja Kennadyrajan
ath11k_wmi_addba_set_resp(struct ath11k * ar,u32 vdev_id,const u8 * mac,u32 tid,u32 status)26979556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac,
26989556dfa2SMaharaja Kennadyrajan u32 tid, u32 status)
26999556dfa2SMaharaja Kennadyrajan {
27009556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi;
27019556dfa2SMaharaja Kennadyrajan struct wmi_addba_setresponse_cmd *cmd;
27029556dfa2SMaharaja Kennadyrajan struct sk_buff *skb;
27039556dfa2SMaharaja Kennadyrajan int ret;
27049556dfa2SMaharaja Kennadyrajan
27059556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
27069556dfa2SMaharaja Kennadyrajan if (!skb)
27079556dfa2SMaharaja Kennadyrajan return -ENOMEM;
27089556dfa2SMaharaja Kennadyrajan
27099556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
27109556dfa2SMaharaja Kennadyrajan cmd->tlv_header =
27119556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) |
27129556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27139556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id;
27149556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac);
27159556dfa2SMaharaja Kennadyrajan cmd->tid = tid;
27169556dfa2SMaharaja Kennadyrajan cmd->statuscode = status;
27179556dfa2SMaharaja Kennadyrajan
27189556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID);
27199556dfa2SMaharaja Kennadyrajan
27209556dfa2SMaharaja Kennadyrajan if (ret) {
27219556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab,
27229556dfa2SMaharaja Kennadyrajan "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n");
27239556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb);
27249556dfa2SMaharaja Kennadyrajan }
27259556dfa2SMaharaja Kennadyrajan
272600608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
272700608b40SKalle Valo "cmd addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
272800608b40SKalle Valo vdev_id, mac, tid, status);
272900608b40SKalle Valo
27309556dfa2SMaharaja Kennadyrajan return ret;
27319556dfa2SMaharaja Kennadyrajan }
27329556dfa2SMaharaja Kennadyrajan
ath11k_wmi_addba_send(struct ath11k * ar,u32 vdev_id,const u8 * mac,u32 tid,u32 buf_size)27339556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
27349556dfa2SMaharaja Kennadyrajan u32 tid, u32 buf_size)
27359556dfa2SMaharaja Kennadyrajan {
27369556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi;
27379556dfa2SMaharaja Kennadyrajan struct wmi_addba_send_cmd *cmd;
27389556dfa2SMaharaja Kennadyrajan struct sk_buff *skb;
27399556dfa2SMaharaja Kennadyrajan int ret;
27409556dfa2SMaharaja Kennadyrajan
27419556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
27429556dfa2SMaharaja Kennadyrajan if (!skb)
27439556dfa2SMaharaja Kennadyrajan return -ENOMEM;
27449556dfa2SMaharaja Kennadyrajan
27459556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_addba_send_cmd *)skb->data;
27469556dfa2SMaharaja Kennadyrajan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) |
27479556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27489556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id;
27499556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac);
27509556dfa2SMaharaja Kennadyrajan cmd->tid = tid;
27519556dfa2SMaharaja Kennadyrajan cmd->buffersize = buf_size;
27529556dfa2SMaharaja Kennadyrajan
27539556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID);
27549556dfa2SMaharaja Kennadyrajan
27559556dfa2SMaharaja Kennadyrajan if (ret) {
27569556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab,
27579556dfa2SMaharaja Kennadyrajan "failed to send WMI_ADDBA_SEND_CMDID cmd\n");
27589556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb);
27599556dfa2SMaharaja Kennadyrajan }
27609556dfa2SMaharaja Kennadyrajan
276100608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
276200608b40SKalle Valo "cmd addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
276300608b40SKalle Valo vdev_id, mac, tid, buf_size);
276400608b40SKalle Valo
27659556dfa2SMaharaja Kennadyrajan return ret;
27669556dfa2SMaharaja Kennadyrajan }
27679556dfa2SMaharaja Kennadyrajan
ath11k_wmi_addba_clear_resp(struct ath11k * ar,u32 vdev_id,const u8 * mac)27689556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac)
27699556dfa2SMaharaja Kennadyrajan {
27709556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi;
27719556dfa2SMaharaja Kennadyrajan struct wmi_addba_clear_resp_cmd *cmd;
27729556dfa2SMaharaja Kennadyrajan struct sk_buff *skb;
27739556dfa2SMaharaja Kennadyrajan int ret;
27749556dfa2SMaharaja Kennadyrajan
27759556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
27769556dfa2SMaharaja Kennadyrajan if (!skb)
27779556dfa2SMaharaja Kennadyrajan return -ENOMEM;
27789556dfa2SMaharaja Kennadyrajan
27799556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
27809556dfa2SMaharaja Kennadyrajan cmd->tlv_header =
27819556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) |
27829556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
27839556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id;
27849556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac);
27859556dfa2SMaharaja Kennadyrajan
27869556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID);
27879556dfa2SMaharaja Kennadyrajan
27889556dfa2SMaharaja Kennadyrajan if (ret) {
27899556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab,
27909556dfa2SMaharaja Kennadyrajan "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n");
27919556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb);
27929556dfa2SMaharaja Kennadyrajan }
27939556dfa2SMaharaja Kennadyrajan
279400608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
279500608b40SKalle Valo "cmd addba clear resp vdev_id 0x%X mac_addr %pM\n",
279600608b40SKalle Valo vdev_id, mac);
279700608b40SKalle Valo
27989556dfa2SMaharaja Kennadyrajan return ret;
27999556dfa2SMaharaja Kennadyrajan }
28009556dfa2SMaharaja Kennadyrajan
ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k * ar,u8 * addr,u8 enable)2801d5c65159SKalle Valo int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2802d5c65159SKalle Valo {
2803d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2804d5c65159SKalle Valo struct wmi_pdev_pktlog_filter_cmd *cmd;
2805d5c65159SKalle Valo struct wmi_pdev_pktlog_filter_info *info;
2806d5c65159SKalle Valo struct sk_buff *skb;
2807d5c65159SKalle Valo struct wmi_tlv *tlv;
2808d5c65159SKalle Valo void *ptr;
2809d5c65159SKalle Valo int ret, len;
2810d5c65159SKalle Valo
2811d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
28126bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2813d5c65159SKalle Valo if (!skb)
2814d5c65159SKalle Valo return -ENOMEM;
2815d5c65159SKalle Valo
2816d5c65159SKalle Valo cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2817d5c65159SKalle Valo
2818d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2819d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2820d5c65159SKalle Valo
2821d0f390eaSAnilkumar Kolli cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2822d5c65159SKalle Valo cmd->num_mac = 1;
2823d5c65159SKalle Valo cmd->enable = enable;
2824d5c65159SKalle Valo
2825d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd);
2826d5c65159SKalle Valo
2827d5c65159SKalle Valo tlv = ptr;
2828d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
282979c647a3SVikas Patel FIELD_PREP(WMI_TLV_LEN, sizeof(*info));
2830d5c65159SKalle Valo
2831d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
2832d5c65159SKalle Valo info = ptr;
2833d5c65159SKalle Valo
2834d5c65159SKalle Valo ether_addr_copy(info->peer_macaddr.addr, addr);
2835d5c65159SKalle Valo info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2836d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
2837d5c65159SKalle Valo sizeof(*info) - TLV_HDR_SIZE);
2838d5c65159SKalle Valo
2839d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
2840d5c65159SKalle Valo WMI_PDEV_PKTLOG_FILTER_CMDID);
2841d5c65159SKalle Valo if (ret) {
2842d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2843d5c65159SKalle Valo dev_kfree_skb(skb);
2844d5c65159SKalle Valo }
2845d5c65159SKalle Valo
284600608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd pdev pktlog filter");
284700608b40SKalle Valo
2848d5c65159SKalle Valo return ret;
2849d5c65159SKalle Valo }
2850d5c65159SKalle Valo
2851d5c65159SKalle Valo int
ath11k_wmi_send_init_country_cmd(struct ath11k * ar,struct wmi_init_country_params init_cc_params)2852d5c65159SKalle Valo ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2853d5c65159SKalle Valo struct wmi_init_country_params init_cc_params)
2854d5c65159SKalle Valo {
2855d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
2856d5c65159SKalle Valo struct wmi_init_country_cmd *cmd;
2857d5c65159SKalle Valo struct sk_buff *skb;
2858d5c65159SKalle Valo int ret;
2859d5c65159SKalle Valo
28606bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2861d5c65159SKalle Valo if (!skb)
2862d5c65159SKalle Valo return -ENOMEM;
2863d5c65159SKalle Valo
2864d5c65159SKalle Valo cmd = (struct wmi_init_country_cmd *)skb->data;
2865d5c65159SKalle Valo cmd->tlv_header =
2866d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG,
2867d5c65159SKalle Valo WMI_TAG_SET_INIT_COUNTRY_CMD) |
2868d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2869d5c65159SKalle Valo
2870d5c65159SKalle Valo cmd->pdev_id = ar->pdev->pdev_id;
2871d5c65159SKalle Valo
2872d5c65159SKalle Valo switch (init_cc_params.flags) {
2873d5c65159SKalle Valo case ALPHA_IS_SET:
2874d5c65159SKalle Valo cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2875d5c65159SKalle Valo memcpy((u8 *)&cmd->cc_info.alpha2,
2876d5c65159SKalle Valo init_cc_params.cc_info.alpha2, 3);
2877d5c65159SKalle Valo break;
2878d5c65159SKalle Valo case CC_IS_SET:
2879d5c65159SKalle Valo cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2880d5c65159SKalle Valo cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2881d5c65159SKalle Valo break;
2882d5c65159SKalle Valo case REGDMN_IS_SET:
2883d5c65159SKalle Valo cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2884d5c65159SKalle Valo cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2885d5c65159SKalle Valo break;
2886d5c65159SKalle Valo default:
288790a9fb5bSKalle Valo ath11k_warn(ar->ab, "unknown cc params flags: 0x%x",
288890a9fb5bSKalle Valo init_cc_params.flags);
2889d5c65159SKalle Valo ret = -EINVAL;
289090a9fb5bSKalle Valo goto err;
2891d5c65159SKalle Valo }
2892d5c65159SKalle Valo
2893d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
2894d5c65159SKalle Valo WMI_SET_INIT_COUNTRY_CMDID);
2895d5c65159SKalle Valo if (ret) {
2896d5c65159SKalle Valo ath11k_warn(ar->ab,
2897d5c65159SKalle Valo "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2898d5c65159SKalle Valo ret);
289990a9fb5bSKalle Valo goto err;
2900d5c65159SKalle Valo }
2901d5c65159SKalle Valo
290200608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd set init country");
290300608b40SKalle Valo
290490a9fb5bSKalle Valo return 0;
290590a9fb5bSKalle Valo
290690a9fb5bSKalle Valo err:
290790a9fb5bSKalle Valo dev_kfree_skb(skb);
2908d5c65159SKalle Valo return ret;
2909d5c65159SKalle Valo }
2910d5c65159SKalle Valo
ath11k_wmi_send_set_current_country_cmd(struct ath11k * ar,struct wmi_set_current_country_params * param)29110b05ddadSWen Gong int ath11k_wmi_send_set_current_country_cmd(struct ath11k *ar,
29120b05ddadSWen Gong struct wmi_set_current_country_params *param)
29130b05ddadSWen Gong {
29140b05ddadSWen Gong struct ath11k_pdev_wmi *wmi = ar->wmi;
29150b05ddadSWen Gong struct wmi_set_current_country_cmd *cmd;
29160b05ddadSWen Gong struct sk_buff *skb;
29170b05ddadSWen Gong int ret;
29180b05ddadSWen Gong
29190b05ddadSWen Gong skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
29200b05ddadSWen Gong if (!skb)
29210b05ddadSWen Gong return -ENOMEM;
29220b05ddadSWen Gong
29230b05ddadSWen Gong cmd = (struct wmi_set_current_country_cmd *)skb->data;
29240b05ddadSWen Gong cmd->tlv_header =
29250b05ddadSWen Gong FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SET_CURRENT_COUNTRY_CMD) |
29260b05ddadSWen Gong FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
29270b05ddadSWen Gong
29280b05ddadSWen Gong cmd->pdev_id = ar->pdev->pdev_id;
29290b05ddadSWen Gong memcpy(&cmd->new_alpha2, ¶m->alpha2, 3);
293000608b40SKalle Valo
29310b05ddadSWen Gong ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SET_CURRENT_COUNTRY_CMDID);
29320b05ddadSWen Gong if (ret) {
29330b05ddadSWen Gong ath11k_warn(ar->ab,
29340b05ddadSWen Gong "failed to send WMI_SET_CURRENT_COUNTRY_CMDID: %d\n", ret);
29350b05ddadSWen Gong dev_kfree_skb(skb);
29360b05ddadSWen Gong }
29370b05ddadSWen Gong
293800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
293900608b40SKalle Valo "cmd set current country pdev id %d alpha2 %c%c\n",
294000608b40SKalle Valo ar->pdev->pdev_id,
294100608b40SKalle Valo param->alpha2[0],
294200608b40SKalle Valo param->alpha2[1]);
294300608b40SKalle Valo
29440b05ddadSWen Gong return ret;
29450b05ddadSWen Gong }
29460b05ddadSWen Gong
29472a63bbcaSPradeep Kumar Chitrapu int
ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k * ar,struct thermal_mitigation_params * param)29482a63bbcaSPradeep Kumar Chitrapu ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar,
29492a63bbcaSPradeep Kumar Chitrapu struct thermal_mitigation_params *param)
29502a63bbcaSPradeep Kumar Chitrapu {
29512a63bbcaSPradeep Kumar Chitrapu struct ath11k_pdev_wmi *wmi = ar->wmi;
29522a63bbcaSPradeep Kumar Chitrapu struct wmi_therm_throt_config_request_cmd *cmd;
29532a63bbcaSPradeep Kumar Chitrapu struct wmi_therm_throt_level_config_info *lvl_conf;
29542a63bbcaSPradeep Kumar Chitrapu struct wmi_tlv *tlv;
29552a63bbcaSPradeep Kumar Chitrapu struct sk_buff *skb;
29562a63bbcaSPradeep Kumar Chitrapu int i, ret, len;
29572a63bbcaSPradeep Kumar Chitrapu
29582a63bbcaSPradeep Kumar Chitrapu len = sizeof(*cmd) + TLV_HDR_SIZE +
29592a63bbcaSPradeep Kumar Chitrapu THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info);
29602a63bbcaSPradeep Kumar Chitrapu
29612a63bbcaSPradeep Kumar Chitrapu skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
29622a63bbcaSPradeep Kumar Chitrapu if (!skb)
29632a63bbcaSPradeep Kumar Chitrapu return -ENOMEM;
29642a63bbcaSPradeep Kumar Chitrapu
29652a63bbcaSPradeep Kumar Chitrapu cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data;
29662a63bbcaSPradeep Kumar Chitrapu
29672a63bbcaSPradeep Kumar Chitrapu cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) |
29682a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
29692a63bbcaSPradeep Kumar Chitrapu
29702a63bbcaSPradeep Kumar Chitrapu cmd->pdev_id = ar->pdev->pdev_id;
29712a63bbcaSPradeep Kumar Chitrapu cmd->enable = param->enable;
29722a63bbcaSPradeep Kumar Chitrapu cmd->dc = param->dc;
29732a63bbcaSPradeep Kumar Chitrapu cmd->dc_per_event = param->dc_per_event;
29742a63bbcaSPradeep Kumar Chitrapu cmd->therm_throt_levels = THERMAL_LEVELS;
29752a63bbcaSPradeep Kumar Chitrapu
29762a63bbcaSPradeep Kumar Chitrapu tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
29772a63bbcaSPradeep Kumar Chitrapu tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
29782a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN,
29792a63bbcaSPradeep Kumar Chitrapu (THERMAL_LEVELS *
29802a63bbcaSPradeep Kumar Chitrapu sizeof(struct wmi_therm_throt_level_config_info)));
29812a63bbcaSPradeep Kumar Chitrapu
29822a63bbcaSPradeep Kumar Chitrapu lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data +
29832a63bbcaSPradeep Kumar Chitrapu sizeof(*cmd) +
29842a63bbcaSPradeep Kumar Chitrapu TLV_HDR_SIZE);
29852a63bbcaSPradeep Kumar Chitrapu for (i = 0; i < THERMAL_LEVELS; i++) {
29862a63bbcaSPradeep Kumar Chitrapu lvl_conf->tlv_header =
29872a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) |
29882a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE);
29892a63bbcaSPradeep Kumar Chitrapu
29902a63bbcaSPradeep Kumar Chitrapu lvl_conf->temp_lwm = param->levelconf[i].tmplwm;
29912a63bbcaSPradeep Kumar Chitrapu lvl_conf->temp_hwm = param->levelconf[i].tmphwm;
29922a63bbcaSPradeep Kumar Chitrapu lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent;
29932a63bbcaSPradeep Kumar Chitrapu lvl_conf->prio = param->levelconf[i].priority;
29942a63bbcaSPradeep Kumar Chitrapu lvl_conf++;
29952a63bbcaSPradeep Kumar Chitrapu }
29962a63bbcaSPradeep Kumar Chitrapu
29972a63bbcaSPradeep Kumar Chitrapu ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID);
29982a63bbcaSPradeep Kumar Chitrapu if (ret) {
29992a63bbcaSPradeep Kumar Chitrapu ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n");
30002a63bbcaSPradeep Kumar Chitrapu dev_kfree_skb(skb);
30012a63bbcaSPradeep Kumar Chitrapu }
30022a63bbcaSPradeep Kumar Chitrapu
30032a63bbcaSPradeep Kumar Chitrapu ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
300400608b40SKalle Valo "cmd therm throt set conf pdev_id %d enable %d dc %d dc_per_event %x levels %d\n",
30052a63bbcaSPradeep Kumar Chitrapu ar->pdev->pdev_id, param->enable, param->dc,
30062a63bbcaSPradeep Kumar Chitrapu param->dc_per_event, THERMAL_LEVELS);
30072a63bbcaSPradeep Kumar Chitrapu
30082a63bbcaSPradeep Kumar Chitrapu return ret;
30092a63bbcaSPradeep Kumar Chitrapu }
30102a63bbcaSPradeep Kumar Chitrapu
ath11k_wmi_send_11d_scan_start_cmd(struct ath11k * ar,struct wmi_11d_scan_start_params * param)30119dcf6808SWen Gong int ath11k_wmi_send_11d_scan_start_cmd(struct ath11k *ar,
30129dcf6808SWen Gong struct wmi_11d_scan_start_params *param)
30139dcf6808SWen Gong {
30149dcf6808SWen Gong struct ath11k_pdev_wmi *wmi = ar->wmi;
30159dcf6808SWen Gong struct wmi_11d_scan_start_cmd *cmd;
30169dcf6808SWen Gong struct sk_buff *skb;
30179dcf6808SWen Gong int ret;
30189dcf6808SWen Gong
30199dcf6808SWen Gong skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
30209dcf6808SWen Gong if (!skb)
30219dcf6808SWen Gong return -ENOMEM;
30229dcf6808SWen Gong
30239dcf6808SWen Gong cmd = (struct wmi_11d_scan_start_cmd *)skb->data;
30249dcf6808SWen Gong cmd->tlv_header =
30259dcf6808SWen Gong FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_START_CMD) |
30269dcf6808SWen Gong FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
30279dcf6808SWen Gong
30289dcf6808SWen Gong cmd->vdev_id = param->vdev_id;
30299dcf6808SWen Gong cmd->scan_period_msec = param->scan_period_msec;
30309dcf6808SWen Gong cmd->start_interval_msec = param->start_interval_msec;
303100608b40SKalle Valo
30329dcf6808SWen Gong ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_START_CMDID);
30339dcf6808SWen Gong if (ret) {
30349dcf6808SWen Gong ath11k_warn(ar->ab,
30359dcf6808SWen Gong "failed to send WMI_11D_SCAN_START_CMDID: %d\n", ret);
30369dcf6808SWen Gong dev_kfree_skb(skb);
30379dcf6808SWen Gong }
30389dcf6808SWen Gong
303900608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
304000608b40SKalle Valo "cmd 11d scan start vdev id %d period %d ms internal %d ms\n",
304100608b40SKalle Valo cmd->vdev_id,
304200608b40SKalle Valo cmd->scan_period_msec,
304300608b40SKalle Valo cmd->start_interval_msec);
304400608b40SKalle Valo
30459dcf6808SWen Gong return ret;
30469dcf6808SWen Gong }
30479dcf6808SWen Gong
ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k * ar,u32 vdev_id)30489dcf6808SWen Gong int ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k *ar, u32 vdev_id)
30499dcf6808SWen Gong {
30509dcf6808SWen Gong struct ath11k_pdev_wmi *wmi = ar->wmi;
30519dcf6808SWen Gong struct wmi_11d_scan_stop_cmd *cmd;
30529dcf6808SWen Gong struct sk_buff *skb;
30539dcf6808SWen Gong int ret;
30549dcf6808SWen Gong
30559dcf6808SWen Gong skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
30569dcf6808SWen Gong if (!skb)
30579dcf6808SWen Gong return -ENOMEM;
30589dcf6808SWen Gong
30599dcf6808SWen Gong cmd = (struct wmi_11d_scan_stop_cmd *)skb->data;
30609dcf6808SWen Gong cmd->tlv_header =
30619dcf6808SWen Gong FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_STOP_CMD) |
30629dcf6808SWen Gong FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
30639dcf6808SWen Gong
30649dcf6808SWen Gong cmd->vdev_id = vdev_id;
306500608b40SKalle Valo
30669dcf6808SWen Gong ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_STOP_CMDID);
30679dcf6808SWen Gong if (ret) {
30689dcf6808SWen Gong ath11k_warn(ar->ab,
30699dcf6808SWen Gong "failed to send WMI_11D_SCAN_STOP_CMDID: %d\n", ret);
30709dcf6808SWen Gong dev_kfree_skb(skb);
30719dcf6808SWen Gong }
30729dcf6808SWen Gong
307300608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
307400608b40SKalle Valo "cmd 11d scan stop vdev id %d\n",
307500608b40SKalle Valo cmd->vdev_id);
307600608b40SKalle Valo
30779dcf6808SWen Gong return ret;
30789dcf6808SWen Gong }
30799dcf6808SWen Gong
ath11k_wmi_pdev_pktlog_enable(struct ath11k * ar,u32 pktlog_filter)3080d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
3081d5c65159SKalle Valo {
3082d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
3083d5c65159SKalle Valo struct wmi_pktlog_enable_cmd *cmd;
3084d5c65159SKalle Valo struct sk_buff *skb;
3085d5c65159SKalle Valo int ret;
3086d5c65159SKalle Valo
30876bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3088d5c65159SKalle Valo if (!skb)
3089d5c65159SKalle Valo return -ENOMEM;
3090d5c65159SKalle Valo
3091d5c65159SKalle Valo cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
3092d5c65159SKalle Valo
3093d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
3094d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3095d5c65159SKalle Valo
3096d0f390eaSAnilkumar Kolli cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3097d5c65159SKalle Valo cmd->evlist = pktlog_filter;
3098d5c65159SKalle Valo cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
3099d5c65159SKalle Valo
3100d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
3101d5c65159SKalle Valo WMI_PDEV_PKTLOG_ENABLE_CMDID);
3102d5c65159SKalle Valo if (ret) {
3103d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3104d5c65159SKalle Valo dev_kfree_skb(skb);
3105d5c65159SKalle Valo }
3106d5c65159SKalle Valo
310700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd pdev pktlog enable");
310800608b40SKalle Valo
3109d5c65159SKalle Valo return ret;
3110d5c65159SKalle Valo }
3111d5c65159SKalle Valo
ath11k_wmi_pdev_pktlog_disable(struct ath11k * ar)3112d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
3113d5c65159SKalle Valo {
3114d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
3115d5c65159SKalle Valo struct wmi_pktlog_disable_cmd *cmd;
3116d5c65159SKalle Valo struct sk_buff *skb;
3117d5c65159SKalle Valo int ret;
3118d5c65159SKalle Valo
31196bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3120d5c65159SKalle Valo if (!skb)
3121d5c65159SKalle Valo return -ENOMEM;
3122d5c65159SKalle Valo
3123d5c65159SKalle Valo cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
3124d5c65159SKalle Valo
3125d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
3126d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3127d5c65159SKalle Valo
3128d0f390eaSAnilkumar Kolli cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3129d5c65159SKalle Valo
3130d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb,
3131d5c65159SKalle Valo WMI_PDEV_PKTLOG_DISABLE_CMDID);
3132d5c65159SKalle Valo if (ret) {
3133d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3134d5c65159SKalle Valo dev_kfree_skb(skb);
3135d5c65159SKalle Valo }
3136d5c65159SKalle Valo
313700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd pdev pktlog disable");
313800608b40SKalle Valo
3139d5c65159SKalle Valo return ret;
3140d5c65159SKalle Valo }
3141d5c65159SKalle Valo
ath11k_wmi_fill_default_twt_params(struct wmi_twt_enable_params * twt_params)31429e2747c3SManikanta Pubbisetty void ath11k_wmi_fill_default_twt_params(struct wmi_twt_enable_params *twt_params)
31439e2747c3SManikanta Pubbisetty {
31449e2747c3SManikanta Pubbisetty twt_params->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
31459e2747c3SManikanta Pubbisetty twt_params->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
31469e2747c3SManikanta Pubbisetty twt_params->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
31479e2747c3SManikanta Pubbisetty twt_params->congestion_thresh_teardown =
31489e2747c3SManikanta Pubbisetty ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
31499e2747c3SManikanta Pubbisetty twt_params->congestion_thresh_critical =
31509e2747c3SManikanta Pubbisetty ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
31519e2747c3SManikanta Pubbisetty twt_params->interference_thresh_teardown =
31529e2747c3SManikanta Pubbisetty ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
31539e2747c3SManikanta Pubbisetty twt_params->interference_thresh_setup =
31549e2747c3SManikanta Pubbisetty ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
31559e2747c3SManikanta Pubbisetty twt_params->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
31569e2747c3SManikanta Pubbisetty twt_params->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
31579e2747c3SManikanta Pubbisetty twt_params->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
31589e2747c3SManikanta Pubbisetty twt_params->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
31599e2747c3SManikanta Pubbisetty twt_params->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
31609e2747c3SManikanta Pubbisetty twt_params->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
31619e2747c3SManikanta Pubbisetty twt_params->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
31629e2747c3SManikanta Pubbisetty twt_params->remove_sta_slot_interval =
31639e2747c3SManikanta Pubbisetty ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
31649e2747c3SManikanta Pubbisetty /* TODO add MBSSID support */
31659e2747c3SManikanta Pubbisetty twt_params->mbss_support = 0;
31669e2747c3SManikanta Pubbisetty }
31679e2747c3SManikanta Pubbisetty
ath11k_wmi_send_twt_enable_cmd(struct ath11k * ar,u32 pdev_id,struct wmi_twt_enable_params * params)31689e2747c3SManikanta Pubbisetty int ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id,
31699e2747c3SManikanta Pubbisetty struct wmi_twt_enable_params *params)
31706d293d44SJohn Crispin {
31716d293d44SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
31726bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
31736d293d44SJohn Crispin struct wmi_twt_enable_params_cmd *cmd;
31746d293d44SJohn Crispin struct sk_buff *skb;
31756d293d44SJohn Crispin int ret, len;
31766d293d44SJohn Crispin
31776d293d44SJohn Crispin len = sizeof(*cmd);
31786d293d44SJohn Crispin
31796bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
31806d293d44SJohn Crispin if (!skb)
31816d293d44SJohn Crispin return -ENOMEM;
31826d293d44SJohn Crispin
318377ea8b45SJohn Crispin cmd = (struct wmi_twt_enable_params_cmd *)skb->data;
31846d293d44SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
31856d293d44SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
31866d293d44SJohn Crispin cmd->pdev_id = pdev_id;
31879e2747c3SManikanta Pubbisetty cmd->sta_cong_timer_ms = params->sta_cong_timer_ms;
31889e2747c3SManikanta Pubbisetty cmd->default_slot_size = params->default_slot_size;
31899e2747c3SManikanta Pubbisetty cmd->congestion_thresh_setup = params->congestion_thresh_setup;
31909e2747c3SManikanta Pubbisetty cmd->congestion_thresh_teardown = params->congestion_thresh_teardown;
31919e2747c3SManikanta Pubbisetty cmd->congestion_thresh_critical = params->congestion_thresh_critical;
31929e2747c3SManikanta Pubbisetty cmd->interference_thresh_teardown = params->interference_thresh_teardown;
31939e2747c3SManikanta Pubbisetty cmd->interference_thresh_setup = params->interference_thresh_setup;
31949e2747c3SManikanta Pubbisetty cmd->min_no_sta_setup = params->min_no_sta_setup;
31959e2747c3SManikanta Pubbisetty cmd->min_no_sta_teardown = params->min_no_sta_teardown;
31969e2747c3SManikanta Pubbisetty cmd->no_of_bcast_mcast_slots = params->no_of_bcast_mcast_slots;
31979e2747c3SManikanta Pubbisetty cmd->min_no_twt_slots = params->min_no_twt_slots;
31989e2747c3SManikanta Pubbisetty cmd->max_no_sta_twt = params->max_no_sta_twt;
31999e2747c3SManikanta Pubbisetty cmd->mode_check_interval = params->mode_check_interval;
32009e2747c3SManikanta Pubbisetty cmd->add_sta_slot_interval = params->add_sta_slot_interval;
32019e2747c3SManikanta Pubbisetty cmd->remove_sta_slot_interval = params->remove_sta_slot_interval;
32029e2747c3SManikanta Pubbisetty cmd->mbss_support = params->mbss_support;
32036d293d44SJohn Crispin
32043d00e8b5SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ENABLE_CMDID);
32056d293d44SJohn Crispin if (ret) {
32066d293d44SJohn Crispin ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
32076d293d44SJohn Crispin dev_kfree_skb(skb);
32086d293d44SJohn Crispin return ret;
32096d293d44SJohn Crispin }
32106d293d44SJohn Crispin
3211afba35d7SKalle Valo ar->twt_enabled = 1;
3212afba35d7SKalle Valo
321300608b40SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd twt enable");
321400608b40SKalle Valo
3215afba35d7SKalle Valo return 0;
3216afba35d7SKalle Valo }
3217afba35d7SKalle Valo
32186d293d44SJohn Crispin int
ath11k_wmi_send_twt_disable_cmd(struct ath11k * ar,u32 pdev_id)32196d293d44SJohn Crispin ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
32206d293d44SJohn Crispin {
32216d293d44SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
32226bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
32236d293d44SJohn Crispin struct wmi_twt_disable_params_cmd *cmd;
32246d293d44SJohn Crispin struct sk_buff *skb;
32256d293d44SJohn Crispin int ret, len;
32266d293d44SJohn Crispin
32276d293d44SJohn Crispin len = sizeof(*cmd);
32286d293d44SJohn Crispin
32296bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32306d293d44SJohn Crispin if (!skb)
32316d293d44SJohn Crispin return -ENOMEM;
32326d293d44SJohn Crispin
323377ea8b45SJohn Crispin cmd = (struct wmi_twt_disable_params_cmd *)skb->data;
32346d293d44SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
32356d293d44SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32366d293d44SJohn Crispin cmd->pdev_id = pdev_id;
32376d293d44SJohn Crispin
32383d00e8b5SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DISABLE_CMDID);
32396d293d44SJohn Crispin if (ret) {
3240345a4f22SColin Ian King ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID");
32416d293d44SJohn Crispin dev_kfree_skb(skb);
32423d00e8b5SJohn Crispin return ret;
32433d00e8b5SJohn Crispin }
32443d00e8b5SJohn Crispin
324500608b40SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd twt disable");
324600608b40SKalle Valo
3247afba35d7SKalle Valo ar->twt_enabled = 0;
3248afba35d7SKalle Valo
3249afba35d7SKalle Valo return 0;
3250afba35d7SKalle Valo }
3251afba35d7SKalle Valo
ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k * ar,struct wmi_twt_add_dialog_params * params)32523d00e8b5SJohn Crispin int ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k *ar,
32533d00e8b5SJohn Crispin struct wmi_twt_add_dialog_params *params)
32543d00e8b5SJohn Crispin {
32553d00e8b5SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
32563d00e8b5SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
32573d00e8b5SJohn Crispin struct wmi_twt_add_dialog_params_cmd *cmd;
32583d00e8b5SJohn Crispin struct sk_buff *skb;
32593d00e8b5SJohn Crispin int ret, len;
32603d00e8b5SJohn Crispin
32613d00e8b5SJohn Crispin len = sizeof(*cmd);
32623d00e8b5SJohn Crispin
32633d00e8b5SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
32643d00e8b5SJohn Crispin if (!skb)
32653d00e8b5SJohn Crispin return -ENOMEM;
32663d00e8b5SJohn Crispin
32673d00e8b5SJohn Crispin cmd = (struct wmi_twt_add_dialog_params_cmd *)skb->data;
32683d00e8b5SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ADD_DIALOG_CMD) |
32693d00e8b5SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
32703d00e8b5SJohn Crispin
32713d00e8b5SJohn Crispin cmd->vdev_id = params->vdev_id;
32723d00e8b5SJohn Crispin ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
32733d00e8b5SJohn Crispin cmd->dialog_id = params->dialog_id;
32743d00e8b5SJohn Crispin cmd->wake_intvl_us = params->wake_intvl_us;
32753d00e8b5SJohn Crispin cmd->wake_intvl_mantis = params->wake_intvl_mantis;
32763d00e8b5SJohn Crispin cmd->wake_dura_us = params->wake_dura_us;
32773d00e8b5SJohn Crispin cmd->sp_offset_us = params->sp_offset_us;
32783d00e8b5SJohn Crispin cmd->flags = params->twt_cmd;
32793d00e8b5SJohn Crispin if (params->flag_bcast)
32803d00e8b5SJohn Crispin cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_BCAST;
32813d00e8b5SJohn Crispin if (params->flag_trigger)
32823d00e8b5SJohn Crispin cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_TRIGGER;
32833d00e8b5SJohn Crispin if (params->flag_flow_type)
32843d00e8b5SJohn Crispin cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_FLOW_TYPE;
32853d00e8b5SJohn Crispin if (params->flag_protection)
32863d00e8b5SJohn Crispin cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_PROTECTION;
32873d00e8b5SJohn Crispin
32883d00e8b5SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ADD_DIALOG_CMDID);
32893d00e8b5SJohn Crispin if (ret) {
32903d00e8b5SJohn Crispin ath11k_warn(ab,
32913d00e8b5SJohn Crispin "failed to send wmi command to add twt dialog: %d",
32923d00e8b5SJohn Crispin ret);
32933d00e8b5SJohn Crispin dev_kfree_skb(skb);
32943d00e8b5SJohn Crispin return ret;
32953d00e8b5SJohn Crispin }
32963d00e8b5SJohn Crispin
329700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
329800608b40SKalle Valo "cmd twt add dialog vdev %u dialog id %u wake interval %u mantissa %u wake duration %u service period offset %u flags 0x%x\n",
329900608b40SKalle Valo cmd->vdev_id, cmd->dialog_id, cmd->wake_intvl_us,
330000608b40SKalle Valo cmd->wake_intvl_mantis, cmd->wake_dura_us, cmd->sp_offset_us,
330100608b40SKalle Valo cmd->flags);
330200608b40SKalle Valo
3303afba35d7SKalle Valo return 0;
3304afba35d7SKalle Valo }
3305afba35d7SKalle Valo
ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k * ar,struct wmi_twt_del_dialog_params * params)33063d00e8b5SJohn Crispin int ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k *ar,
33073d00e8b5SJohn Crispin struct wmi_twt_del_dialog_params *params)
33083d00e8b5SJohn Crispin {
33093d00e8b5SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
33103d00e8b5SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
33113d00e8b5SJohn Crispin struct wmi_twt_del_dialog_params_cmd *cmd;
33123d00e8b5SJohn Crispin struct sk_buff *skb;
33133d00e8b5SJohn Crispin int ret, len;
33143d00e8b5SJohn Crispin
33153d00e8b5SJohn Crispin len = sizeof(*cmd);
33163d00e8b5SJohn Crispin
33173d00e8b5SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33183d00e8b5SJohn Crispin if (!skb)
33193d00e8b5SJohn Crispin return -ENOMEM;
33203d00e8b5SJohn Crispin
33213d00e8b5SJohn Crispin cmd = (struct wmi_twt_del_dialog_params_cmd *)skb->data;
33223d00e8b5SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DEL_DIALOG_CMD) |
33233d00e8b5SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33243d00e8b5SJohn Crispin
33253d00e8b5SJohn Crispin cmd->vdev_id = params->vdev_id;
33263d00e8b5SJohn Crispin ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
33273d00e8b5SJohn Crispin cmd->dialog_id = params->dialog_id;
33283d00e8b5SJohn Crispin
33293d00e8b5SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DEL_DIALOG_CMDID);
33303d00e8b5SJohn Crispin if (ret) {
33313d00e8b5SJohn Crispin ath11k_warn(ab,
33323d00e8b5SJohn Crispin "failed to send wmi command to delete twt dialog: %d",
33333d00e8b5SJohn Crispin ret);
33343d00e8b5SJohn Crispin dev_kfree_skb(skb);
33353d00e8b5SJohn Crispin return ret;
33363d00e8b5SJohn Crispin }
33373d00e8b5SJohn Crispin
333800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
333900608b40SKalle Valo "cmd twt del dialog vdev %u dialog id %u\n",
334000608b40SKalle Valo cmd->vdev_id, cmd->dialog_id);
334100608b40SKalle Valo
3342afba35d7SKalle Valo return 0;
3343afba35d7SKalle Valo }
3344afba35d7SKalle Valo
ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k * ar,struct wmi_twt_pause_dialog_params * params)33453d00e8b5SJohn Crispin int ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k *ar,
33463d00e8b5SJohn Crispin struct wmi_twt_pause_dialog_params *params)
33473d00e8b5SJohn Crispin {
33483d00e8b5SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
33493d00e8b5SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
33503d00e8b5SJohn Crispin struct wmi_twt_pause_dialog_params_cmd *cmd;
33513d00e8b5SJohn Crispin struct sk_buff *skb;
33523d00e8b5SJohn Crispin int ret, len;
33533d00e8b5SJohn Crispin
33543d00e8b5SJohn Crispin len = sizeof(*cmd);
33553d00e8b5SJohn Crispin
33563d00e8b5SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33573d00e8b5SJohn Crispin if (!skb)
33583d00e8b5SJohn Crispin return -ENOMEM;
33593d00e8b5SJohn Crispin
33603d00e8b5SJohn Crispin cmd = (struct wmi_twt_pause_dialog_params_cmd *)skb->data;
33613d00e8b5SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
33623d00e8b5SJohn Crispin WMI_TAG_TWT_PAUSE_DIALOG_CMD) |
33633d00e8b5SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
33643d00e8b5SJohn Crispin
33653d00e8b5SJohn Crispin cmd->vdev_id = params->vdev_id;
33663d00e8b5SJohn Crispin ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
33673d00e8b5SJohn Crispin cmd->dialog_id = params->dialog_id;
33683d00e8b5SJohn Crispin
33693d00e8b5SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_PAUSE_DIALOG_CMDID);
33703d00e8b5SJohn Crispin if (ret) {
33713d00e8b5SJohn Crispin ath11k_warn(ab,
33723d00e8b5SJohn Crispin "failed to send wmi command to pause twt dialog: %d",
33733d00e8b5SJohn Crispin ret);
33743d00e8b5SJohn Crispin dev_kfree_skb(skb);
33753d00e8b5SJohn Crispin return ret;
33763d00e8b5SJohn Crispin }
33773d00e8b5SJohn Crispin
337800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
337900608b40SKalle Valo "cmd twt pause dialog vdev %u dialog id %u\n",
338000608b40SKalle Valo cmd->vdev_id, cmd->dialog_id);
338100608b40SKalle Valo
3382afba35d7SKalle Valo return 0;
3383afba35d7SKalle Valo }
3384afba35d7SKalle Valo
ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k * ar,struct wmi_twt_resume_dialog_params * params)33853d00e8b5SJohn Crispin int ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k *ar,
33863d00e8b5SJohn Crispin struct wmi_twt_resume_dialog_params *params)
33873d00e8b5SJohn Crispin {
33883d00e8b5SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
33893d00e8b5SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
33903d00e8b5SJohn Crispin struct wmi_twt_resume_dialog_params_cmd *cmd;
33913d00e8b5SJohn Crispin struct sk_buff *skb;
33923d00e8b5SJohn Crispin int ret, len;
33933d00e8b5SJohn Crispin
33943d00e8b5SJohn Crispin len = sizeof(*cmd);
33953d00e8b5SJohn Crispin
33963d00e8b5SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
33973d00e8b5SJohn Crispin if (!skb)
33983d00e8b5SJohn Crispin return -ENOMEM;
33993d00e8b5SJohn Crispin
34003d00e8b5SJohn Crispin cmd = (struct wmi_twt_resume_dialog_params_cmd *)skb->data;
34013d00e8b5SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
34023d00e8b5SJohn Crispin WMI_TAG_TWT_RESUME_DIALOG_CMD) |
34033d00e8b5SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
34043d00e8b5SJohn Crispin
34053d00e8b5SJohn Crispin cmd->vdev_id = params->vdev_id;
34063d00e8b5SJohn Crispin ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
34073d00e8b5SJohn Crispin cmd->dialog_id = params->dialog_id;
34083d00e8b5SJohn Crispin cmd->sp_offset_us = params->sp_offset_us;
34093d00e8b5SJohn Crispin cmd->next_twt_size = params->next_twt_size;
34103d00e8b5SJohn Crispin
34113d00e8b5SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_RESUME_DIALOG_CMDID);
34123d00e8b5SJohn Crispin if (ret) {
34133d00e8b5SJohn Crispin ath11k_warn(ab,
34143d00e8b5SJohn Crispin "failed to send wmi command to resume twt dialog: %d",
34153d00e8b5SJohn Crispin ret);
34163d00e8b5SJohn Crispin dev_kfree_skb(skb);
34176d293d44SJohn Crispin return ret;
34186d293d44SJohn Crispin }
34196d293d44SJohn Crispin
342000608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
342100608b40SKalle Valo "cmd twt resume dialog vdev %u dialog id %u service period offset %u next twt subfield size %u\n",
342200608b40SKalle Valo cmd->vdev_id, cmd->dialog_id, cmd->sp_offset_us,
342300608b40SKalle Valo cmd->next_twt_size);
342400608b40SKalle Valo
3425afba35d7SKalle Valo return 0;
3426afba35d7SKalle Valo }
3427afba35d7SKalle Valo
34283f8be640SJohn Crispin int
ath11k_wmi_send_obss_spr_cmd(struct ath11k * ar,u32 vdev_id,struct ieee80211_he_obss_pd * he_obss_pd)34293f8be640SJohn Crispin ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
34303f8be640SJohn Crispin struct ieee80211_he_obss_pd *he_obss_pd)
34313f8be640SJohn Crispin {
34323f8be640SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
34336bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
34343f8be640SJohn Crispin struct wmi_obss_spatial_reuse_params_cmd *cmd;
34353f8be640SJohn Crispin struct sk_buff *skb;
34363f8be640SJohn Crispin int ret, len;
34373f8be640SJohn Crispin
34383f8be640SJohn Crispin len = sizeof(*cmd);
34393f8be640SJohn Crispin
34406bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
34413f8be640SJohn Crispin if (!skb)
34423f8be640SJohn Crispin return -ENOMEM;
34433f8be640SJohn Crispin
344477ea8b45SJohn Crispin cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data;
34453f8be640SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
34463f8be640SJohn Crispin WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
34473f8be640SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
34483f8be640SJohn Crispin cmd->vdev_id = vdev_id;
34493f8be640SJohn Crispin cmd->enable = he_obss_pd->enable;
34503f8be640SJohn Crispin cmd->obss_min = he_obss_pd->min_offset;
34513f8be640SJohn Crispin cmd->obss_max = he_obss_pd->max_offset;
34523f8be640SJohn Crispin
34533f8be640SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb,
34543f8be640SJohn Crispin WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
34553f8be640SJohn Crispin if (ret) {
34563f8be640SJohn Crispin ath11k_warn(ab,
34573f8be640SJohn Crispin "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
34583f8be640SJohn Crispin dev_kfree_skb(skb);
34593f8be640SJohn Crispin return ret;
34603f8be640SJohn Crispin }
34613f8be640SJohn Crispin
346200608b40SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd pdev obss pd spatial reuse");
346300608b40SKalle Valo
3464afba35d7SKalle Valo return 0;
3465afba35d7SKalle Valo }
3466afba35d7SKalle Valo
34675a032c8dSJohn Crispin int
ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k * ar,u32 * bitmap)3468b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k *ar, u32 *bitmap)
3469b56b08aeSRajkumar Manoharan {
3470b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi;
3471b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab;
3472b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3473b56b08aeSRajkumar Manoharan struct sk_buff *skb;
3474b56b08aeSRajkumar Manoharan int ret, len;
3475b56b08aeSRajkumar Manoharan
3476b56b08aeSRajkumar Manoharan len = sizeof(*cmd);
3477b56b08aeSRajkumar Manoharan
3478b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3479b56b08aeSRajkumar Manoharan if (!skb)
3480b56b08aeSRajkumar Manoharan return -ENOMEM;
3481b56b08aeSRajkumar Manoharan
3482b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3483b56b08aeSRajkumar Manoharan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3484b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_BSS_COLOR_BITMAP_CMD) |
3485b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3486b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id;
3487b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3488b56b08aeSRajkumar Manoharan
3489b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb,
3490b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID);
3491b56b08aeSRajkumar Manoharan if (ret) {
3492b56b08aeSRajkumar Manoharan ath11k_warn(ab,
3493b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID");
3494b56b08aeSRajkumar Manoharan dev_kfree_skb(skb);
3495afba35d7SKalle Valo return ret;
3496b56b08aeSRajkumar Manoharan }
3497b56b08aeSRajkumar Manoharan
349800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
349900608b40SKalle Valo "cmd pdev set srg bss color bitmap pdev_id %d bss color bitmap %08x %08x\n",
350000608b40SKalle Valo cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
350100608b40SKalle Valo
3502afba35d7SKalle Valo return 0;
3503b56b08aeSRajkumar Manoharan }
3504b56b08aeSRajkumar Manoharan
3505b56b08aeSRajkumar Manoharan int
ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k * ar,u32 * bitmap)3506b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k *ar, u32 *bitmap)
3507b56b08aeSRajkumar Manoharan {
3508b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi;
3509b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab;
3510b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3511b56b08aeSRajkumar Manoharan struct sk_buff *skb;
3512b56b08aeSRajkumar Manoharan int ret, len;
3513b56b08aeSRajkumar Manoharan
3514b56b08aeSRajkumar Manoharan len = sizeof(*cmd);
3515b56b08aeSRajkumar Manoharan
3516b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3517b56b08aeSRajkumar Manoharan if (!skb)
3518b56b08aeSRajkumar Manoharan return -ENOMEM;
3519b56b08aeSRajkumar Manoharan
3520b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3521b56b08aeSRajkumar Manoharan cmd->tlv_header =
3522b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG,
3523b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_PARTIAL_BSSID_BITMAP_CMD) |
3524b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3525b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id;
3526b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3527b56b08aeSRajkumar Manoharan
3528b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb,
3529b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID);
3530b56b08aeSRajkumar Manoharan if (ret) {
3531b56b08aeSRajkumar Manoharan ath11k_warn(ab,
3532b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID");
3533b56b08aeSRajkumar Manoharan dev_kfree_skb(skb);
3534afba35d7SKalle Valo return ret;
3535b56b08aeSRajkumar Manoharan }
3536b56b08aeSRajkumar Manoharan
353700608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
353800608b40SKalle Valo "cmd pdev set srg partial bssid bitmap pdev_id %d partial bssid bitmap %08x %08x\n",
353900608b40SKalle Valo cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
354000608b40SKalle Valo
3541afba35d7SKalle Valo return 0;
3542b56b08aeSRajkumar Manoharan }
3543b56b08aeSRajkumar Manoharan
3544b56b08aeSRajkumar Manoharan int
ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k * ar,u32 * bitmap)3545b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3546b56b08aeSRajkumar Manoharan {
3547b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi;
3548b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab;
3549b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3550b56b08aeSRajkumar Manoharan struct sk_buff *skb;
3551b56b08aeSRajkumar Manoharan int ret, len;
3552b56b08aeSRajkumar Manoharan
3553b56b08aeSRajkumar Manoharan len = sizeof(*cmd);
3554b56b08aeSRajkumar Manoharan
3555b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3556b56b08aeSRajkumar Manoharan if (!skb)
3557b56b08aeSRajkumar Manoharan return -ENOMEM;
3558b56b08aeSRajkumar Manoharan
3559b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3560b56b08aeSRajkumar Manoharan cmd->tlv_header =
3561b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG,
3562b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3563b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3564b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id;
3565b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3566b56b08aeSRajkumar Manoharan
3567b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb,
3568b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3569b56b08aeSRajkumar Manoharan if (ret) {
3570b56b08aeSRajkumar Manoharan ath11k_warn(ab,
3571b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3572b56b08aeSRajkumar Manoharan dev_kfree_skb(skb);
3573afba35d7SKalle Valo return ret;
3574b56b08aeSRajkumar Manoharan }
3575b56b08aeSRajkumar Manoharan
357600608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
357700608b40SKalle Valo "cmd pdev set srg obsscolor enable pdev_id %d bss color enable bitmap %08x %08x\n",
357800608b40SKalle Valo cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
357900608b40SKalle Valo
3580afba35d7SKalle Valo return 0;
3581b56b08aeSRajkumar Manoharan }
3582b56b08aeSRajkumar Manoharan
3583b56b08aeSRajkumar Manoharan int
ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k * ar,u32 * bitmap)3584b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3585b56b08aeSRajkumar Manoharan {
3586b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi;
3587b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab;
3588b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3589b56b08aeSRajkumar Manoharan struct sk_buff *skb;
3590b56b08aeSRajkumar Manoharan int ret, len;
3591b56b08aeSRajkumar Manoharan
3592b56b08aeSRajkumar Manoharan len = sizeof(*cmd);
3593b56b08aeSRajkumar Manoharan
3594b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3595b56b08aeSRajkumar Manoharan if (!skb)
3596b56b08aeSRajkumar Manoharan return -ENOMEM;
3597b56b08aeSRajkumar Manoharan
3598b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3599b56b08aeSRajkumar Manoharan cmd->tlv_header =
3600b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG,
3601b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3602b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3603b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id;
3604b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3605b56b08aeSRajkumar Manoharan
3606b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb,
3607b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3608b56b08aeSRajkumar Manoharan if (ret) {
3609b56b08aeSRajkumar Manoharan ath11k_warn(ab,
3610b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3611b56b08aeSRajkumar Manoharan dev_kfree_skb(skb);
3612afba35d7SKalle Valo return ret;
3613b56b08aeSRajkumar Manoharan }
3614b56b08aeSRajkumar Manoharan
361500608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
361600608b40SKalle Valo "cmd pdev set srg obss bssid enable bitmap pdev_id %d bssid enable bitmap %08x %08x\n",
361700608b40SKalle Valo cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
361800608b40SKalle Valo
3619afba35d7SKalle Valo return 0;
3620b56b08aeSRajkumar Manoharan }
3621b56b08aeSRajkumar Manoharan
3622b56b08aeSRajkumar Manoharan int
ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k * ar,u32 * bitmap)3623b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3624b56b08aeSRajkumar Manoharan {
3625b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi;
3626b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab;
3627b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3628b56b08aeSRajkumar Manoharan struct sk_buff *skb;
3629b56b08aeSRajkumar Manoharan int ret, len;
3630b56b08aeSRajkumar Manoharan
3631b56b08aeSRajkumar Manoharan len = sizeof(*cmd);
3632b56b08aeSRajkumar Manoharan
3633b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3634b56b08aeSRajkumar Manoharan if (!skb)
3635b56b08aeSRajkumar Manoharan return -ENOMEM;
3636b56b08aeSRajkumar Manoharan
3637b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3638b56b08aeSRajkumar Manoharan cmd->tlv_header =
3639b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG,
3640b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3641b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3642b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id;
3643b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3644b56b08aeSRajkumar Manoharan
3645b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb,
3646b56b08aeSRajkumar Manoharan WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3647b56b08aeSRajkumar Manoharan if (ret) {
3648b56b08aeSRajkumar Manoharan ath11k_warn(ab,
3649b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3650b56b08aeSRajkumar Manoharan dev_kfree_skb(skb);
3651afba35d7SKalle Valo return ret;
3652b56b08aeSRajkumar Manoharan }
3653b56b08aeSRajkumar Manoharan
365400608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
365500608b40SKalle Valo "cmd pdev set non srg obss color enable bitmap pdev_id %d bss color enable bitmap %08x %08x\n",
365600608b40SKalle Valo cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
365700608b40SKalle Valo
3658afba35d7SKalle Valo return 0;
3659b56b08aeSRajkumar Manoharan }
3660b56b08aeSRajkumar Manoharan
3661b56b08aeSRajkumar Manoharan int
ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k * ar,u32 * bitmap)3662b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3663b56b08aeSRajkumar Manoharan {
3664b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi;
3665b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab;
3666b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3667b56b08aeSRajkumar Manoharan struct sk_buff *skb;
3668b56b08aeSRajkumar Manoharan int ret, len;
3669b56b08aeSRajkumar Manoharan
3670b56b08aeSRajkumar Manoharan len = sizeof(*cmd);
3671b56b08aeSRajkumar Manoharan
3672b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3673b56b08aeSRajkumar Manoharan if (!skb)
3674b56b08aeSRajkumar Manoharan return -ENOMEM;
3675b56b08aeSRajkumar Manoharan
3676b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3677b56b08aeSRajkumar Manoharan cmd->tlv_header =
3678b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG,
3679b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3680b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3681b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id;
3682b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3683b56b08aeSRajkumar Manoharan
3684b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb,
3685b56b08aeSRajkumar Manoharan WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3686b56b08aeSRajkumar Manoharan if (ret) {
3687b56b08aeSRajkumar Manoharan ath11k_warn(ab,
3688b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3689b56b08aeSRajkumar Manoharan dev_kfree_skb(skb);
3690afba35d7SKalle Valo return ret;
3691b56b08aeSRajkumar Manoharan }
3692b56b08aeSRajkumar Manoharan
369300608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
369400608b40SKalle Valo "cmd pdev set non srg obss bssid enable bitmap pdev_id %d bssid enable bitmap %08x %08x\n",
369500608b40SKalle Valo cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
369600608b40SKalle Valo
3697afba35d7SKalle Valo return 0;
3698b56b08aeSRajkumar Manoharan }
3699b56b08aeSRajkumar Manoharan
3700b56b08aeSRajkumar Manoharan int
ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k * ar,u32 vdev_id,u8 bss_color,u32 period,bool enable)37015a032c8dSJohn Crispin ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id,
37025a032c8dSJohn Crispin u8 bss_color, u32 period,
37035a032c8dSJohn Crispin bool enable)
37045a032c8dSJohn Crispin {
37055a032c8dSJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
37065a032c8dSJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
37075a032c8dSJohn Crispin struct wmi_obss_color_collision_cfg_params_cmd *cmd;
37085a032c8dSJohn Crispin struct sk_buff *skb;
37095a032c8dSJohn Crispin int ret, len;
37105a032c8dSJohn Crispin
37115a032c8dSJohn Crispin len = sizeof(*cmd);
37125a032c8dSJohn Crispin
37135a032c8dSJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
37145a032c8dSJohn Crispin if (!skb)
37155a032c8dSJohn Crispin return -ENOMEM;
37165a032c8dSJohn Crispin
37175a032c8dSJohn Crispin cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data;
37185a032c8dSJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
37195a032c8dSJohn Crispin WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) |
37205a032c8dSJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
37215a032c8dSJohn Crispin cmd->vdev_id = vdev_id;
37225a032c8dSJohn Crispin cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION :
37235a032c8dSJohn Crispin ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE;
37245a032c8dSJohn Crispin cmd->current_bss_color = bss_color;
37255a032c8dSJohn Crispin cmd->detection_period_ms = period;
37265a032c8dSJohn Crispin cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS;
37275a032c8dSJohn Crispin cmd->free_slot_expiry_time_ms = 0;
37285a032c8dSJohn Crispin cmd->flags = 0;
37295a032c8dSJohn Crispin
37305a032c8dSJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb,
37315a032c8dSJohn Crispin WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID);
37325a032c8dSJohn Crispin if (ret) {
37335a032c8dSJohn Crispin ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID");
37345a032c8dSJohn Crispin dev_kfree_skb(skb);
37355a032c8dSJohn Crispin return ret;
37365a032c8dSJohn Crispin }
37375a032c8dSJohn Crispin
373800608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
373900608b40SKalle Valo "cmd obss color collision det config id %d type %d bss_color %d detect_period %d scan_period %d\n",
374000608b40SKalle Valo cmd->vdev_id, cmd->evt_type, cmd->current_bss_color,
374100608b40SKalle Valo cmd->detection_period_ms, cmd->scan_period_ms);
374200608b40SKalle Valo
3743afba35d7SKalle Valo return 0;
3744afba35d7SKalle Valo }
3745afba35d7SKalle Valo
ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k * ar,u32 vdev_id,bool enable)37465a032c8dSJohn Crispin int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id,
37475a032c8dSJohn Crispin bool enable)
37485a032c8dSJohn Crispin {
37495a032c8dSJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi;
37505a032c8dSJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
37515a032c8dSJohn Crispin struct wmi_bss_color_change_enable_params_cmd *cmd;
37525a032c8dSJohn Crispin struct sk_buff *skb;
37535a032c8dSJohn Crispin int ret, len;
37545a032c8dSJohn Crispin
37555a032c8dSJohn Crispin len = sizeof(*cmd);
37565a032c8dSJohn Crispin
37575a032c8dSJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
37585a032c8dSJohn Crispin if (!skb)
37595a032c8dSJohn Crispin return -ENOMEM;
37605a032c8dSJohn Crispin
37615a032c8dSJohn Crispin cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data;
37625a032c8dSJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) |
37635a032c8dSJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
37645a032c8dSJohn Crispin cmd->vdev_id = vdev_id;
37655a032c8dSJohn Crispin cmd->enable = enable ? 1 : 0;
37665a032c8dSJohn Crispin
37675a032c8dSJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb,
37685a032c8dSJohn Crispin WMI_BSS_COLOR_CHANGE_ENABLE_CMDID);
37695a032c8dSJohn Crispin if (ret) {
37709a8074e3SColin Ian King ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID");
37715a032c8dSJohn Crispin dev_kfree_skb(skb);
37725a032c8dSJohn Crispin return ret;
37735a032c8dSJohn Crispin }
37745a032c8dSJohn Crispin
377500608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
377600608b40SKalle Valo "cmd bss color change enable id %d enable %d\n",
377700608b40SKalle Valo cmd->vdev_id, cmd->enable);
377800608b40SKalle Valo
3779afba35d7SKalle Valo return 0;
3780afba35d7SKalle Valo }
3781afba35d7SKalle Valo
ath11k_wmi_fils_discovery_tmpl(struct ath11k * ar,u32 vdev_id,struct sk_buff * tmpl)3782047679e3SAloka Dixit int ath11k_wmi_fils_discovery_tmpl(struct ath11k *ar, u32 vdev_id,
3783047679e3SAloka Dixit struct sk_buff *tmpl)
3784047679e3SAloka Dixit {
3785047679e3SAloka Dixit struct wmi_tlv *tlv;
3786047679e3SAloka Dixit struct sk_buff *skb;
3787047679e3SAloka Dixit void *ptr;
3788047679e3SAloka Dixit int ret, len;
3789047679e3SAloka Dixit size_t aligned_len;
3790047679e3SAloka Dixit struct wmi_fils_discovery_tmpl_cmd *cmd;
3791047679e3SAloka Dixit
3792047679e3SAloka Dixit aligned_len = roundup(tmpl->len, 4);
3793047679e3SAloka Dixit len = sizeof(*cmd) + TLV_HDR_SIZE + aligned_len;
3794047679e3SAloka Dixit
3795047679e3SAloka Dixit ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3796fc3b984aSKalle Valo "vdev %i set FILS discovery template\n", vdev_id);
3797047679e3SAloka Dixit
3798047679e3SAloka Dixit skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3799047679e3SAloka Dixit if (!skb)
3800047679e3SAloka Dixit return -ENOMEM;
3801047679e3SAloka Dixit
3802047679e3SAloka Dixit cmd = (struct wmi_fils_discovery_tmpl_cmd *)skb->data;
3803047679e3SAloka Dixit cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3804047679e3SAloka Dixit WMI_TAG_FILS_DISCOVERY_TMPL_CMD) |
3805047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3806047679e3SAloka Dixit cmd->vdev_id = vdev_id;
3807047679e3SAloka Dixit cmd->buf_len = tmpl->len;
3808047679e3SAloka Dixit ptr = skb->data + sizeof(*cmd);
3809047679e3SAloka Dixit
3810047679e3SAloka Dixit tlv = ptr;
3811047679e3SAloka Dixit tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3812047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, aligned_len);
3813047679e3SAloka Dixit memcpy(tlv->value, tmpl->data, tmpl->len);
3814047679e3SAloka Dixit
3815047679e3SAloka Dixit ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_FILS_DISCOVERY_TMPL_CMDID);
3816047679e3SAloka Dixit if (ret) {
3817047679e3SAloka Dixit ath11k_warn(ar->ab,
3818047679e3SAloka Dixit "WMI vdev %i failed to send FILS discovery template command\n",
3819047679e3SAloka Dixit vdev_id);
3820047679e3SAloka Dixit dev_kfree_skb(skb);
3821047679e3SAloka Dixit return ret;
3822047679e3SAloka Dixit }
3823047679e3SAloka Dixit
382400608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd fils discovery tmpl");
382500608b40SKalle Valo
3826afba35d7SKalle Valo return 0;
3827afba35d7SKalle Valo }
3828afba35d7SKalle Valo
ath11k_wmi_probe_resp_tmpl(struct ath11k * ar,u32 vdev_id,struct sk_buff * tmpl)3829047679e3SAloka Dixit int ath11k_wmi_probe_resp_tmpl(struct ath11k *ar, u32 vdev_id,
3830047679e3SAloka Dixit struct sk_buff *tmpl)
3831047679e3SAloka Dixit {
3832047679e3SAloka Dixit struct wmi_probe_tmpl_cmd *cmd;
3833047679e3SAloka Dixit struct wmi_bcn_prb_info *probe_info;
3834047679e3SAloka Dixit struct wmi_tlv *tlv;
3835047679e3SAloka Dixit struct sk_buff *skb;
3836047679e3SAloka Dixit void *ptr;
3837047679e3SAloka Dixit int ret, len;
3838047679e3SAloka Dixit size_t aligned_len = roundup(tmpl->len, 4);
3839047679e3SAloka Dixit
3840047679e3SAloka Dixit ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3841fc3b984aSKalle Valo "vdev %i set probe response template\n", vdev_id);
3842047679e3SAloka Dixit
3843047679e3SAloka Dixit len = sizeof(*cmd) + sizeof(*probe_info) + TLV_HDR_SIZE + aligned_len;
3844047679e3SAloka Dixit
3845047679e3SAloka Dixit skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3846047679e3SAloka Dixit if (!skb)
3847047679e3SAloka Dixit return -ENOMEM;
3848047679e3SAloka Dixit
3849047679e3SAloka Dixit cmd = (struct wmi_probe_tmpl_cmd *)skb->data;
3850047679e3SAloka Dixit cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PRB_TMPL_CMD) |
3851047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3852047679e3SAloka Dixit cmd->vdev_id = vdev_id;
3853047679e3SAloka Dixit cmd->buf_len = tmpl->len;
3854047679e3SAloka Dixit
3855047679e3SAloka Dixit ptr = skb->data + sizeof(*cmd);
3856047679e3SAloka Dixit
3857047679e3SAloka Dixit probe_info = ptr;
3858047679e3SAloka Dixit len = sizeof(*probe_info);
3859047679e3SAloka Dixit probe_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3860047679e3SAloka Dixit WMI_TAG_BCN_PRB_INFO) |
3861047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3862047679e3SAloka Dixit probe_info->caps = 0;
3863047679e3SAloka Dixit probe_info->erp = 0;
3864047679e3SAloka Dixit
3865047679e3SAloka Dixit ptr += sizeof(*probe_info);
3866047679e3SAloka Dixit
3867047679e3SAloka Dixit tlv = ptr;
3868047679e3SAloka Dixit tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3869047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, aligned_len);
3870047679e3SAloka Dixit memcpy(tlv->value, tmpl->data, tmpl->len);
3871047679e3SAloka Dixit
3872047679e3SAloka Dixit ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_PRB_TMPL_CMDID);
3873047679e3SAloka Dixit if (ret) {
3874047679e3SAloka Dixit ath11k_warn(ar->ab,
3875047679e3SAloka Dixit "WMI vdev %i failed to send probe response template command\n",
3876047679e3SAloka Dixit vdev_id);
3877047679e3SAloka Dixit dev_kfree_skb(skb);
3878047679e3SAloka Dixit return ret;
3879047679e3SAloka Dixit }
3880047679e3SAloka Dixit
388100608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd ");
388200608b40SKalle Valo
3883afba35d7SKalle Valo return 0;
3884afba35d7SKalle Valo }
3885afba35d7SKalle Valo
ath11k_wmi_fils_discovery(struct ath11k * ar,u32 vdev_id,u32 interval,bool unsol_bcast_probe_resp_enabled)3886047679e3SAloka Dixit int ath11k_wmi_fils_discovery(struct ath11k *ar, u32 vdev_id, u32 interval,
3887047679e3SAloka Dixit bool unsol_bcast_probe_resp_enabled)
3888047679e3SAloka Dixit {
3889047679e3SAloka Dixit struct sk_buff *skb;
3890047679e3SAloka Dixit int ret, len;
3891047679e3SAloka Dixit struct wmi_fils_discovery_cmd *cmd;
3892047679e3SAloka Dixit
3893047679e3SAloka Dixit ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3894fc3b984aSKalle Valo "vdev %i set %s interval to %u TU\n",
3895047679e3SAloka Dixit vdev_id, unsol_bcast_probe_resp_enabled ?
3896047679e3SAloka Dixit "unsolicited broadcast probe response" : "FILS discovery",
3897047679e3SAloka Dixit interval);
3898047679e3SAloka Dixit
3899047679e3SAloka Dixit len = sizeof(*cmd);
3900047679e3SAloka Dixit skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3901047679e3SAloka Dixit if (!skb)
3902047679e3SAloka Dixit return -ENOMEM;
3903047679e3SAloka Dixit
3904047679e3SAloka Dixit cmd = (struct wmi_fils_discovery_cmd *)skb->data;
3905047679e3SAloka Dixit cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ENABLE_FILS_CMD) |
3906047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3907047679e3SAloka Dixit cmd->vdev_id = vdev_id;
3908047679e3SAloka Dixit cmd->interval = interval;
3909047679e3SAloka Dixit cmd->config = unsol_bcast_probe_resp_enabled;
3910047679e3SAloka Dixit
3911047679e3SAloka Dixit ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_ENABLE_FILS_CMDID);
3912047679e3SAloka Dixit if (ret) {
3913047679e3SAloka Dixit ath11k_warn(ar->ab,
3914047679e3SAloka Dixit "WMI vdev %i failed to send FILS discovery enable/disable command\n",
3915047679e3SAloka Dixit vdev_id);
3916047679e3SAloka Dixit dev_kfree_skb(skb);
3917047679e3SAloka Dixit return ret;
3918047679e3SAloka Dixit }
3919047679e3SAloka Dixit
392000608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd enable fils");
392100608b40SKalle Valo
3922afba35d7SKalle Valo return 0;
3923afba35d7SKalle Valo }
3924afba35d7SKalle Valo
3925d5c65159SKalle Valo static void
ath11k_wmi_obss_color_collision_event(struct ath11k_base * ab,struct sk_buff * skb)3926886433a9SJohn Crispin ath11k_wmi_obss_color_collision_event(struct ath11k_base *ab, struct sk_buff *skb)
3927886433a9SJohn Crispin {
3928886433a9SJohn Crispin const void **tb;
3929886433a9SJohn Crispin const struct wmi_obss_color_collision_event *ev;
3930886433a9SJohn Crispin struct ath11k_vif *arvif;
3931886433a9SJohn Crispin int ret;
3932886433a9SJohn Crispin
3933886433a9SJohn Crispin tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3934886433a9SJohn Crispin if (IS_ERR(tb)) {
3935886433a9SJohn Crispin ret = PTR_ERR(tb);
3936886433a9SJohn Crispin ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3937886433a9SJohn Crispin return;
3938886433a9SJohn Crispin }
3939886433a9SJohn Crispin
3940e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event obss color collision");
3941e5df1577SKalle Valo
394201e782c8SWen Gong rcu_read_lock();
394301e782c8SWen Gong
3944886433a9SJohn Crispin ev = tb[WMI_TAG_OBSS_COLOR_COLLISION_EVT];
3945886433a9SJohn Crispin if (!ev) {
3946886433a9SJohn Crispin ath11k_warn(ab, "failed to fetch obss color collision ev");
3947886433a9SJohn Crispin goto exit;
3948886433a9SJohn Crispin }
3949886433a9SJohn Crispin
3950886433a9SJohn Crispin arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
3951886433a9SJohn Crispin if (!arvif) {
3952886433a9SJohn Crispin ath11k_warn(ab, "failed to find arvif with vedv id %d in obss_color_collision_event\n",
3953886433a9SJohn Crispin ev->vdev_id);
3954886433a9SJohn Crispin goto exit;
3955886433a9SJohn Crispin }
3956886433a9SJohn Crispin
3957886433a9SJohn Crispin switch (ev->evt_type) {
3958886433a9SJohn Crispin case WMI_BSS_COLOR_COLLISION_DETECTION:
395982253ddaSJohannes Berg ieee80211_obss_color_collision_notify(arvif->vif, ev->obss_color_bitmap,
396003895c84SLorenzo Bianconi GFP_KERNEL);
3961886433a9SJohn Crispin ath11k_dbg(ab, ATH11K_DBG_WMI,
3962886433a9SJohn Crispin "OBSS color collision detected vdev:%d, event:%d, bitmap:%08llx\n",
3963886433a9SJohn Crispin ev->vdev_id, ev->evt_type, ev->obss_color_bitmap);
3964886433a9SJohn Crispin break;
3965886433a9SJohn Crispin case WMI_BSS_COLOR_COLLISION_DISABLE:
3966886433a9SJohn Crispin case WMI_BSS_COLOR_FREE_SLOT_TIMER_EXPIRY:
3967886433a9SJohn Crispin case WMI_BSS_COLOR_FREE_SLOT_AVAILABLE:
3968886433a9SJohn Crispin break;
3969886433a9SJohn Crispin default:
3970c27506ccSColin Ian King ath11k_warn(ab, "received unknown obss color collision detection event\n");
3971886433a9SJohn Crispin }
3972886433a9SJohn Crispin
3973886433a9SJohn Crispin exit:
3974886433a9SJohn Crispin kfree(tb);
397501e782c8SWen Gong rcu_read_unlock();
3976886433a9SJohn Crispin }
3977886433a9SJohn Crispin
3978886433a9SJohn Crispin static void
ath11k_fill_band_to_mac_param(struct ath11k_base * soc,struct wmi_host_pdev_band_to_mac * band_to_mac)3979d5c65159SKalle Valo ath11k_fill_band_to_mac_param(struct ath11k_base *soc,
3980d5c65159SKalle Valo struct wmi_host_pdev_band_to_mac *band_to_mac)
3981d5c65159SKalle Valo {
3982d5c65159SKalle Valo u8 i;
3983d5c65159SKalle Valo struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
3984d5c65159SKalle Valo struct ath11k_pdev *pdev;
3985d5c65159SKalle Valo
3986d5c65159SKalle Valo for (i = 0; i < soc->num_radios; i++) {
3987d5c65159SKalle Valo pdev = &soc->pdevs[i];
3988d5c65159SKalle Valo hal_reg_cap = &soc->hal_reg_cap[i];
3989d5c65159SKalle Valo band_to_mac[i].pdev_id = pdev->pdev_id;
3990d5c65159SKalle Valo
3991d5c65159SKalle Valo switch (pdev->cap.supported_bands) {
3992d5c65159SKalle Valo case WMI_HOST_WLAN_2G_5G_CAP:
3993d5c65159SKalle Valo band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3994d5c65159SKalle Valo band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3995d5c65159SKalle Valo break;
3996d5c65159SKalle Valo case WMI_HOST_WLAN_2G_CAP:
3997d5c65159SKalle Valo band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3998d5c65159SKalle Valo band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
3999d5c65159SKalle Valo break;
4000d5c65159SKalle Valo case WMI_HOST_WLAN_5G_CAP:
4001d5c65159SKalle Valo band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
4002d5c65159SKalle Valo band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
4003d5c65159SKalle Valo break;
4004d5c65159SKalle Valo default:
4005d5c65159SKalle Valo break;
4006d5c65159SKalle Valo }
4007d5c65159SKalle Valo }
4008d5c65159SKalle Valo }
4009d5c65159SKalle Valo
4010d5c65159SKalle Valo static void
ath11k_wmi_copy_resource_config(struct wmi_resource_config * wmi_cfg,struct target_resource_config * tg_cfg)4011d5c65159SKalle Valo ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
4012d5c65159SKalle Valo struct target_resource_config *tg_cfg)
4013d5c65159SKalle Valo {
4014d5c65159SKalle Valo wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
4015d5c65159SKalle Valo wmi_cfg->num_peers = tg_cfg->num_peers;
4016d5c65159SKalle Valo wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
4017d5c65159SKalle Valo wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
4018d5c65159SKalle Valo wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
4019d5c65159SKalle Valo wmi_cfg->num_tids = tg_cfg->num_tids;
4020d5c65159SKalle Valo wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
4021d5c65159SKalle Valo wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
4022d5c65159SKalle Valo wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
4023d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
4024d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
4025d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
4026d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
4027d5c65159SKalle Valo wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
4028d5c65159SKalle Valo wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
4029d5c65159SKalle Valo wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
4030d5c65159SKalle Valo wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
4031d5c65159SKalle Valo wmi_cfg->roam_offload_max_ap_profiles =
4032d5c65159SKalle Valo tg_cfg->roam_offload_max_ap_profiles;
4033d5c65159SKalle Valo wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
4034d5c65159SKalle Valo wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
4035d5c65159SKalle Valo wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
4036d5c65159SKalle Valo wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
4037d5c65159SKalle Valo wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
4038d5c65159SKalle Valo wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
4039d5c65159SKalle Valo wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
4040d5c65159SKalle Valo wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
4041d5c65159SKalle Valo tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
4042d5c65159SKalle Valo wmi_cfg->vow_config = tg_cfg->vow_config;
4043d5c65159SKalle Valo wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
4044d5c65159SKalle Valo wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
4045d5c65159SKalle Valo wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
4046d5c65159SKalle Valo wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
4047d5c65159SKalle Valo wmi_cfg->num_tdls_conn_table_entries =
4048d5c65159SKalle Valo tg_cfg->num_tdls_conn_table_entries;
4049d5c65159SKalle Valo wmi_cfg->beacon_tx_offload_max_vdev =
4050d5c65159SKalle Valo tg_cfg->beacon_tx_offload_max_vdev;
4051d5c65159SKalle Valo wmi_cfg->num_multicast_filter_entries =
4052d5c65159SKalle Valo tg_cfg->num_multicast_filter_entries;
4053d5c65159SKalle Valo wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
4054d5c65159SKalle Valo wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
4055d5c65159SKalle Valo wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
4056d5c65159SKalle Valo wmi_cfg->max_tdls_concurrent_sleep_sta =
4057d5c65159SKalle Valo tg_cfg->max_tdls_concurrent_sleep_sta;
4058d5c65159SKalle Valo wmi_cfg->max_tdls_concurrent_buffer_sta =
4059d5c65159SKalle Valo tg_cfg->max_tdls_concurrent_buffer_sta;
4060d5c65159SKalle Valo wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
4061d5c65159SKalle Valo wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
4062d5c65159SKalle Valo wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
4063d5c65159SKalle Valo wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
4064d5c65159SKalle Valo wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
4065d5c65159SKalle Valo wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
4066d5c65159SKalle Valo wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
40677e9fb241SSeevalamuthu Mariappan wmi_cfg->flag1 = tg_cfg->flag1;
4068d5c65159SKalle Valo wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
40696d293d44SJohn Crispin wmi_cfg->sched_params = tg_cfg->sched_params;
40706d293d44SJohn Crispin wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
40716d293d44SJohn Crispin wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
407291fa00faSAditya Kumar Singh wmi_cfg->host_service_flags &=
407391fa00faSAditya Kumar Singh ~(1 << WMI_CFG_HOST_SERVICE_FLAG_REG_CC_EXT);
407491fa00faSAditya Kumar Singh wmi_cfg->host_service_flags |= (tg_cfg->is_reg_cc_ext_event_supported <<
407591fa00faSAditya Kumar Singh WMI_CFG_HOST_SERVICE_FLAG_REG_CC_EXT);
4076a08dbb04SAloka Dixit wmi_cfg->flags2 = WMI_RSRC_CFG_FLAG2_CALC_NEXT_DTIM_COUNT_SET;
4077a08dbb04SAloka Dixit wmi_cfg->ema_max_vap_cnt = tg_cfg->ema_max_vap_cnt;
4078a08dbb04SAloka Dixit wmi_cfg->ema_max_profile_period = tg_cfg->ema_max_profile_period;
4079d5c65159SKalle Valo }
4080d5c65159SKalle Valo
ath11k_init_cmd_send(struct ath11k_pdev_wmi * wmi,struct wmi_init_cmd_param * param)4081d5c65159SKalle Valo static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
4082d5c65159SKalle Valo struct wmi_init_cmd_param *param)
4083d5c65159SKalle Valo {
40846bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab;
4085d5c65159SKalle Valo struct sk_buff *skb;
4086d5c65159SKalle Valo struct wmi_init_cmd *cmd;
4087d5c65159SKalle Valo struct wmi_resource_config *cfg;
4088d5c65159SKalle Valo struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
4089d5c65159SKalle Valo struct wmi_pdev_band_to_mac *band_to_mac;
4090d5c65159SKalle Valo struct wlan_host_mem_chunk *host_mem_chunks;
4091d5c65159SKalle Valo struct wmi_tlv *tlv;
4092d5c65159SKalle Valo size_t ret, len;
4093d5c65159SKalle Valo void *ptr;
4094d5c65159SKalle Valo u32 hw_mode_len = 0;
4095d5c65159SKalle Valo u16 idx;
4096d5c65159SKalle Valo
4097d5c65159SKalle Valo if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
4098d5c65159SKalle Valo hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
4099d5c65159SKalle Valo (param->num_band_to_mac * sizeof(*band_to_mac));
4100d5c65159SKalle Valo
4101d5c65159SKalle Valo len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
41022d4bcbedSCarl Huang (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0);
4103d5c65159SKalle Valo
41046bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
4105d5c65159SKalle Valo if (!skb)
4106d5c65159SKalle Valo return -ENOMEM;
4107d5c65159SKalle Valo
4108d5c65159SKalle Valo cmd = (struct wmi_init_cmd *)skb->data;
4109d5c65159SKalle Valo
4110d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
4111d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4112d5c65159SKalle Valo
4113d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd);
4114d5c65159SKalle Valo cfg = ptr;
4115d5c65159SKalle Valo
4116d5c65159SKalle Valo ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
4117d5c65159SKalle Valo
4118d5c65159SKalle Valo cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
4119d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
4120d5c65159SKalle Valo
4121d5c65159SKalle Valo ptr += sizeof(*cfg);
4122d5c65159SKalle Valo host_mem_chunks = ptr + TLV_HDR_SIZE;
4123d5c65159SKalle Valo len = sizeof(struct wlan_host_mem_chunk);
4124d5c65159SKalle Valo
4125d5c65159SKalle Valo for (idx = 0; idx < param->num_mem_chunks; ++idx) {
4126d5c65159SKalle Valo host_mem_chunks[idx].tlv_header =
4127d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG,
4128d5c65159SKalle Valo WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
4129d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
4130d5c65159SKalle Valo
4131d5c65159SKalle Valo host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
4132d5c65159SKalle Valo host_mem_chunks[idx].size = param->mem_chunks[idx].len;
4133d5c65159SKalle Valo host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
4134d5c65159SKalle Valo
4135d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
4136fc3b984aSKalle Valo "host mem chunk req_id %d paddr 0x%llx len %d\n",
4137d5c65159SKalle Valo param->mem_chunks[idx].req_id,
4138d5c65159SKalle Valo (u64)param->mem_chunks[idx].paddr,
4139d5c65159SKalle Valo param->mem_chunks[idx].len);
4140d5c65159SKalle Valo }
4141d5c65159SKalle Valo cmd->num_host_mem_chunks = param->num_mem_chunks;
4142d5c65159SKalle Valo len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
4143d5c65159SKalle Valo
4144d5c65159SKalle Valo /* num_mem_chunks is zero */
4145d5c65159SKalle Valo tlv = ptr;
4146d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4147d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
4148d5c65159SKalle Valo ptr += TLV_HDR_SIZE + len;
4149d5c65159SKalle Valo
4150d5c65159SKalle Valo if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
4151d5c65159SKalle Valo hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr;
4152d5c65159SKalle Valo hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4153d5c65159SKalle Valo WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4154d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
4155d5c65159SKalle Valo sizeof(*hw_mode) - TLV_HDR_SIZE);
4156d5c65159SKalle Valo
4157d5c65159SKalle Valo hw_mode->hw_mode_index = param->hw_mode_id;
4158d5c65159SKalle Valo hw_mode->num_band_to_mac = param->num_band_to_mac;
4159d5c65159SKalle Valo
4160d5c65159SKalle Valo ptr += sizeof(*hw_mode);
4161d5c65159SKalle Valo
4162d5c65159SKalle Valo len = param->num_band_to_mac * sizeof(*band_to_mac);
4163d5c65159SKalle Valo tlv = ptr;
4164d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4165d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len);
4166d5c65159SKalle Valo
4167d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
4168d5c65159SKalle Valo len = sizeof(*band_to_mac);
4169d5c65159SKalle Valo
4170d5c65159SKalle Valo for (idx = 0; idx < param->num_band_to_mac; idx++) {
4171d5c65159SKalle Valo band_to_mac = (void *)ptr;
4172d5c65159SKalle Valo
4173d5c65159SKalle Valo band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4174d5c65159SKalle Valo WMI_TAG_PDEV_BAND_TO_MAC) |
4175d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN,
4176d5c65159SKalle Valo len - TLV_HDR_SIZE);
4177d5c65159SKalle Valo band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
4178d5c65159SKalle Valo band_to_mac->start_freq =
4179d5c65159SKalle Valo param->band_to_mac[idx].start_freq;
4180d5c65159SKalle Valo band_to_mac->end_freq =
4181d5c65159SKalle Valo param->band_to_mac[idx].end_freq;
4182d5c65159SKalle Valo ptr += sizeof(*band_to_mac);
4183d5c65159SKalle Valo }
4184d5c65159SKalle Valo }
4185d5c65159SKalle Valo
4186d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
4187d5c65159SKalle Valo if (ret) {
4188d5c65159SKalle Valo ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
4189d5c65159SKalle Valo dev_kfree_skb(skb);
4190afba35d7SKalle Valo return ret;
4191d5c65159SKalle Valo }
4192d5c65159SKalle Valo
419300608b40SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd wmi init");
419400608b40SKalle Valo
4195afba35d7SKalle Valo return 0;
4196d5c65159SKalle Valo }
4197d5c65159SKalle Valo
ath11k_wmi_pdev_lro_cfg(struct ath11k * ar,int pdev_id)419826c79927SSriram R int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar,
419926c79927SSriram R int pdev_id)
420026c79927SSriram R {
420126c79927SSriram R struct ath11k_wmi_pdev_lro_config_cmd *cmd;
420226c79927SSriram R struct sk_buff *skb;
420326c79927SSriram R int ret;
420426c79927SSriram R
420526c79927SSriram R skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
420626c79927SSriram R if (!skb)
420726c79927SSriram R return -ENOMEM;
420826c79927SSriram R
420926c79927SSriram R cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data;
421026c79927SSriram R cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) |
421126c79927SSriram R FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
421226c79927SSriram R
421326c79927SSriram R get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE);
421426c79927SSriram R get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE);
421526c79927SSriram R
421626c79927SSriram R cmd->pdev_id = pdev_id;
421726c79927SSriram R
421826c79927SSriram R ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID);
421926c79927SSriram R if (ret) {
422026c79927SSriram R ath11k_warn(ar->ab,
422126c79927SSriram R "failed to send lro cfg req wmi cmd\n");
422226c79927SSriram R goto err;
422326c79927SSriram R }
422426c79927SSriram R
422526c79927SSriram R ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
422600608b40SKalle Valo "cmd lro config pdev_id 0x%x\n", pdev_id);
422726c79927SSriram R return 0;
422826c79927SSriram R err:
422926c79927SSriram R dev_kfree_skb(skb);
423026c79927SSriram R return ret;
423126c79927SSriram R }
423226c79927SSriram R
ath11k_wmi_wait_for_service_ready(struct ath11k_base * ab)4233d5c65159SKalle Valo int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
4234d5c65159SKalle Valo {
4235d5c65159SKalle Valo unsigned long time_left;
4236d5c65159SKalle Valo
42376bc9d6f7SJohn Crispin time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready,
4238d5c65159SKalle Valo WMI_SERVICE_READY_TIMEOUT_HZ);
4239d5c65159SKalle Valo if (!time_left)
4240d5c65159SKalle Valo return -ETIMEDOUT;
4241d5c65159SKalle Valo
4242d5c65159SKalle Valo return 0;
4243d5c65159SKalle Valo }
4244d5c65159SKalle Valo
ath11k_wmi_wait_for_unified_ready(struct ath11k_base * ab)4245d5c65159SKalle Valo int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
4246d5c65159SKalle Valo {
4247d5c65159SKalle Valo unsigned long time_left;
4248d5c65159SKalle Valo
42496bc9d6f7SJohn Crispin time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready,
4250d5c65159SKalle Valo WMI_SERVICE_READY_TIMEOUT_HZ);
4251d5c65159SKalle Valo if (!time_left)
4252d5c65159SKalle Valo return -ETIMEDOUT;
4253d5c65159SKalle Valo
4254d5c65159SKalle Valo return 0;
4255d5c65159SKalle Valo }
4256d5c65159SKalle Valo
ath11k_wmi_set_hw_mode(struct ath11k_base * ab,enum wmi_host_hw_mode_config_type mode)425743ed15e1SCarl Huang int ath11k_wmi_set_hw_mode(struct ath11k_base *ab,
425843ed15e1SCarl Huang enum wmi_host_hw_mode_config_type mode)
425943ed15e1SCarl Huang {
426043ed15e1SCarl Huang struct wmi_pdev_set_hw_mode_cmd_param *cmd;
426143ed15e1SCarl Huang struct sk_buff *skb;
426243ed15e1SCarl Huang struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab;
426343ed15e1SCarl Huang int len;
426443ed15e1SCarl Huang int ret;
426543ed15e1SCarl Huang
426643ed15e1SCarl Huang len = sizeof(*cmd);
426743ed15e1SCarl Huang
426843ed15e1SCarl Huang skb = ath11k_wmi_alloc_skb(wmi_ab, len);
4269292bff94SColin Ian King if (!skb)
4270292bff94SColin Ian King return -ENOMEM;
4271292bff94SColin Ian King
427243ed15e1SCarl Huang cmd = (struct wmi_pdev_set_hw_mode_cmd_param *)skb->data;
427343ed15e1SCarl Huang
427443ed15e1SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_HW_MODE_CMD) |
427543ed15e1SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
427643ed15e1SCarl Huang
427743ed15e1SCarl Huang cmd->pdev_id = WMI_PDEV_ID_SOC;
427843ed15e1SCarl Huang cmd->hw_mode_index = mode;
427943ed15e1SCarl Huang
428043ed15e1SCarl Huang ret = ath11k_wmi_cmd_send(&wmi_ab->wmi[0], skb, WMI_PDEV_SET_HW_MODE_CMDID);
428143ed15e1SCarl Huang if (ret) {
428243ed15e1SCarl Huang ath11k_warn(ab, "failed to send WMI_PDEV_SET_HW_MODE_CMDID\n");
428343ed15e1SCarl Huang dev_kfree_skb(skb);
4284afba35d7SKalle Valo return ret;
428543ed15e1SCarl Huang }
428643ed15e1SCarl Huang
428700608b40SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "cmd pdev set hw mode %d", cmd->hw_mode_index);
428800608b40SKalle Valo
4289afba35d7SKalle Valo return 0;
429043ed15e1SCarl Huang }
429143ed15e1SCarl Huang
ath11k_wmi_cmd_init(struct ath11k_base * ab)4292d5c65159SKalle Valo int ath11k_wmi_cmd_init(struct ath11k_base *ab)
4293d5c65159SKalle Valo {
42946bc9d6f7SJohn Crispin struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab;
4295d5c65159SKalle Valo struct wmi_init_cmd_param init_param;
4296d5c65159SKalle Valo struct target_resource_config config;
4297d5c65159SKalle Valo
4298d5c65159SKalle Valo memset(&init_param, 0, sizeof(init_param));
4299d5c65159SKalle Valo memset(&config, 0, sizeof(config));
4300d5c65159SKalle Valo
43012d4bcbedSCarl Huang ab->hw_params.hw_ops->wmi_init_config(ab, &config);
43022d4bcbedSCarl Huang
430391fa00faSAditya Kumar Singh if (test_bit(WMI_TLV_SERVICE_REG_CC_EXT_EVENT_SUPPORT,
430491fa00faSAditya Kumar Singh ab->wmi_ab.svc_map))
430591fa00faSAditya Kumar Singh config.is_reg_cc_ext_event_supported = 1;
430691fa00faSAditya Kumar Singh
4307d5c65159SKalle Valo memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config));
4308d5c65159SKalle Valo
4309d5c65159SKalle Valo init_param.res_cfg = &wmi_sc->wlan_resource_config;
4310d5c65159SKalle Valo init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
4311d5c65159SKalle Valo init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
4312d5c65159SKalle Valo init_param.mem_chunks = wmi_sc->mem_chunks;
4313d5c65159SKalle Valo
431443ed15e1SCarl Huang if (ab->hw_params.single_pdev_only)
431543ed15e1SCarl Huang init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
431643ed15e1SCarl Huang
4317d5c65159SKalle Valo init_param.num_band_to_mac = ab->num_radios;
4318d5c65159SKalle Valo ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
4319d5c65159SKalle Valo
4320d5c65159SKalle Valo return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param);
4321d5c65159SKalle Valo }
4322d5c65159SKalle Valo
ath11k_wmi_vdev_spectral_conf(struct ath11k * ar,struct ath11k_wmi_vdev_spectral_conf_param * param)43239d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar,
43249d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_vdev_spectral_conf_param *param)
43259d11b7bfSKarthikeyan Periyasamy {
43269d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_vdev_spectral_conf_cmd *cmd;
43279d11b7bfSKarthikeyan Periyasamy struct sk_buff *skb;
43289d11b7bfSKarthikeyan Periyasamy int ret;
43299d11b7bfSKarthikeyan Periyasamy
43309d11b7bfSKarthikeyan Periyasamy skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
43319d11b7bfSKarthikeyan Periyasamy if (!skb)
43329d11b7bfSKarthikeyan Periyasamy return -ENOMEM;
43339d11b7bfSKarthikeyan Periyasamy
43349d11b7bfSKarthikeyan Periyasamy cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data;
43359d11b7bfSKarthikeyan Periyasamy cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
43369d11b7bfSKarthikeyan Periyasamy WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) |
43379d11b7bfSKarthikeyan Periyasamy FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
43389d11b7bfSKarthikeyan Periyasamy
43399d11b7bfSKarthikeyan Periyasamy memcpy(&cmd->param, param, sizeof(*param));
43409d11b7bfSKarthikeyan Periyasamy
43419d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_cmd_send(ar->wmi, skb,
43429d11b7bfSKarthikeyan Periyasamy WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
43439d11b7bfSKarthikeyan Periyasamy if (ret) {
43449d11b7bfSKarthikeyan Periyasamy ath11k_warn(ar->ab,
43459d11b7bfSKarthikeyan Periyasamy "failed to send spectral scan config wmi cmd\n");
43469d11b7bfSKarthikeyan Periyasamy goto err;
43479d11b7bfSKarthikeyan Periyasamy }
43489d11b7bfSKarthikeyan Periyasamy
43499d11b7bfSKarthikeyan Periyasamy ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
435000608b40SKalle Valo "cmd vdev spectral scan configure vdev_id 0x%x\n",
43519d11b7bfSKarthikeyan Periyasamy param->vdev_id);
43529d11b7bfSKarthikeyan Periyasamy
43539d11b7bfSKarthikeyan Periyasamy return 0;
43549d11b7bfSKarthikeyan Periyasamy err:
43559d11b7bfSKarthikeyan Periyasamy dev_kfree_skb(skb);
43569d11b7bfSKarthikeyan Periyasamy return ret;
43579d11b7bfSKarthikeyan Periyasamy }
43589d11b7bfSKarthikeyan Periyasamy
ath11k_wmi_vdev_spectral_enable(struct ath11k * ar,u32 vdev_id,u32 trigger,u32 enable)43599d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id,
43609d11b7bfSKarthikeyan Periyasamy u32 trigger, u32 enable)
43619d11b7bfSKarthikeyan Periyasamy {
43629d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_vdev_spectral_enable_cmd *cmd;
43639d11b7bfSKarthikeyan Periyasamy struct sk_buff *skb;
43649d11b7bfSKarthikeyan Periyasamy int ret;
43659d11b7bfSKarthikeyan Periyasamy
43669d11b7bfSKarthikeyan Periyasamy skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
43679d11b7bfSKarthikeyan Periyasamy if (!skb)
43689d11b7bfSKarthikeyan Periyasamy return -ENOMEM;
43699d11b7bfSKarthikeyan Periyasamy
43709d11b7bfSKarthikeyan Periyasamy cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data;
43719d11b7bfSKarthikeyan Periyasamy cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
43729d11b7bfSKarthikeyan Periyasamy WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) |
43739d11b7bfSKarthikeyan Periyasamy FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
43749d11b7bfSKarthikeyan Periyasamy
43759d11b7bfSKarthikeyan Periyasamy cmd->vdev_id = vdev_id;
43769d11b7bfSKarthikeyan Periyasamy cmd->trigger_cmd = trigger;
43779d11b7bfSKarthikeyan Periyasamy cmd->enable_cmd = enable;
43789d11b7bfSKarthikeyan Periyasamy
43799d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_cmd_send(ar->wmi, skb,
43809d11b7bfSKarthikeyan Periyasamy WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
43819d11b7bfSKarthikeyan Periyasamy if (ret) {
43829d11b7bfSKarthikeyan Periyasamy ath11k_warn(ar->ab,
43839d11b7bfSKarthikeyan Periyasamy "failed to send spectral enable wmi cmd\n");
43849d11b7bfSKarthikeyan Periyasamy goto err;
43859d11b7bfSKarthikeyan Periyasamy }
43869d11b7bfSKarthikeyan Periyasamy
43879d11b7bfSKarthikeyan Periyasamy ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
438800608b40SKalle Valo "cmd vdev spectral scan enable vdev id 0x%x\n",
43899d11b7bfSKarthikeyan Periyasamy vdev_id);
43909d11b7bfSKarthikeyan Periyasamy
43919d11b7bfSKarthikeyan Periyasamy return 0;
43929d11b7bfSKarthikeyan Periyasamy err:
43939d11b7bfSKarthikeyan Periyasamy dev_kfree_skb(skb);
43949d11b7bfSKarthikeyan Periyasamy return ret;
43959d11b7bfSKarthikeyan Periyasamy }
43969d11b7bfSKarthikeyan Periyasamy
ath11k_wmi_pdev_dma_ring_cfg(struct ath11k * ar,struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd * param)4397bd647855SKarthikeyan Periyasamy int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar,
4398bd647855SKarthikeyan Periyasamy struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param)
4399bd647855SKarthikeyan Periyasamy {
4400bd647855SKarthikeyan Periyasamy struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd;
4401bd647855SKarthikeyan Periyasamy struct sk_buff *skb;
4402bd647855SKarthikeyan Periyasamy int ret;
4403bd647855SKarthikeyan Periyasamy
4404bd647855SKarthikeyan Periyasamy skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4405bd647855SKarthikeyan Periyasamy if (!skb)
4406bd647855SKarthikeyan Periyasamy return -ENOMEM;
4407bd647855SKarthikeyan Periyasamy
4408bd647855SKarthikeyan Periyasamy cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data;
4409bd647855SKarthikeyan Periyasamy cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) |
4410bd647855SKarthikeyan Periyasamy FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4411bd647855SKarthikeyan Periyasamy
4412bd647855SKarthikeyan Periyasamy cmd->pdev_id = param->pdev_id;
4413bd647855SKarthikeyan Periyasamy cmd->module_id = param->module_id;
4414bd647855SKarthikeyan Periyasamy cmd->base_paddr_lo = param->base_paddr_lo;
4415bd647855SKarthikeyan Periyasamy cmd->base_paddr_hi = param->base_paddr_hi;
4416bd647855SKarthikeyan Periyasamy cmd->head_idx_paddr_lo = param->head_idx_paddr_lo;
4417bd647855SKarthikeyan Periyasamy cmd->head_idx_paddr_hi = param->head_idx_paddr_hi;
4418bd647855SKarthikeyan Periyasamy cmd->tail_idx_paddr_lo = param->tail_idx_paddr_lo;
4419bd647855SKarthikeyan Periyasamy cmd->tail_idx_paddr_hi = param->tail_idx_paddr_hi;
4420bd647855SKarthikeyan Periyasamy cmd->num_elems = param->num_elems;
4421bd647855SKarthikeyan Periyasamy cmd->buf_size = param->buf_size;
4422bd647855SKarthikeyan Periyasamy cmd->num_resp_per_event = param->num_resp_per_event;
4423bd647855SKarthikeyan Periyasamy cmd->event_timeout_ms = param->event_timeout_ms;
4424bd647855SKarthikeyan Periyasamy
4425bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4426bd647855SKarthikeyan Periyasamy WMI_PDEV_DMA_RING_CFG_REQ_CMDID);
4427bd647855SKarthikeyan Periyasamy if (ret) {
4428bd647855SKarthikeyan Periyasamy ath11k_warn(ar->ab,
4429bd647855SKarthikeyan Periyasamy "failed to send dma ring cfg req wmi cmd\n");
4430bd647855SKarthikeyan Periyasamy goto err;
4431bd647855SKarthikeyan Periyasamy }
4432bd647855SKarthikeyan Periyasamy
4433bd647855SKarthikeyan Periyasamy ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
443400608b40SKalle Valo "cmd pdev dma ring cfg req pdev_id 0x%x\n",
4435bd647855SKarthikeyan Periyasamy param->pdev_id);
4436bd647855SKarthikeyan Periyasamy
4437bd647855SKarthikeyan Periyasamy return 0;
4438bd647855SKarthikeyan Periyasamy err:
4439bd647855SKarthikeyan Periyasamy dev_kfree_skb(skb);
4440bd647855SKarthikeyan Periyasamy return ret;
4441bd647855SKarthikeyan Periyasamy }
4442bd647855SKarthikeyan Periyasamy
ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)44439d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc,
44449d11b7bfSKarthikeyan Periyasamy u16 tag, u16 len,
44459d11b7bfSKarthikeyan Periyasamy const void *ptr, void *data)
44469d11b7bfSKarthikeyan Periyasamy {
44479d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse *parse = data;
44489d11b7bfSKarthikeyan Periyasamy
44499d11b7bfSKarthikeyan Periyasamy if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY)
44509d11b7bfSKarthikeyan Periyasamy return -EPROTO;
44519d11b7bfSKarthikeyan Periyasamy
44529d11b7bfSKarthikeyan Periyasamy if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry)
44539d11b7bfSKarthikeyan Periyasamy return -ENOBUFS;
44549d11b7bfSKarthikeyan Periyasamy
44559d11b7bfSKarthikeyan Periyasamy parse->num_buf_entry++;
44569d11b7bfSKarthikeyan Periyasamy return 0;
44579d11b7bfSKarthikeyan Periyasamy }
44589d11b7bfSKarthikeyan Periyasamy
ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)44599d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc,
44609d11b7bfSKarthikeyan Periyasamy u16 tag, u16 len,
44619d11b7bfSKarthikeyan Periyasamy const void *ptr, void *data)
44629d11b7bfSKarthikeyan Periyasamy {
44639d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse *parse = data;
44649d11b7bfSKarthikeyan Periyasamy
44659d11b7bfSKarthikeyan Periyasamy if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA)
44669d11b7bfSKarthikeyan Periyasamy return -EPROTO;
44679d11b7bfSKarthikeyan Periyasamy
44689d11b7bfSKarthikeyan Periyasamy if (parse->num_meta >= parse->fixed.num_meta_data_entry)
44699d11b7bfSKarthikeyan Periyasamy return -ENOBUFS;
44709d11b7bfSKarthikeyan Periyasamy
44719d11b7bfSKarthikeyan Periyasamy parse->num_meta++;
44729d11b7bfSKarthikeyan Periyasamy return 0;
44739d11b7bfSKarthikeyan Periyasamy }
44749d11b7bfSKarthikeyan Periyasamy
ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)44759d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab,
44769d11b7bfSKarthikeyan Periyasamy u16 tag, u16 len,
44779d11b7bfSKarthikeyan Periyasamy const void *ptr, void *data)
44789d11b7bfSKarthikeyan Periyasamy {
44799d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse *parse = data;
44809d11b7bfSKarthikeyan Periyasamy int ret;
44819d11b7bfSKarthikeyan Periyasamy
44829d11b7bfSKarthikeyan Periyasamy switch (tag) {
44839d11b7bfSKarthikeyan Periyasamy case WMI_TAG_DMA_BUF_RELEASE:
44849d11b7bfSKarthikeyan Periyasamy memcpy(&parse->fixed, ptr,
44859d11b7bfSKarthikeyan Periyasamy sizeof(struct ath11k_wmi_dma_buf_release_fixed_param));
44869d11b7bfSKarthikeyan Periyasamy parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id);
44879d11b7bfSKarthikeyan Periyasamy break;
44889d11b7bfSKarthikeyan Periyasamy case WMI_TAG_ARRAY_STRUCT:
44899d11b7bfSKarthikeyan Periyasamy if (!parse->buf_entry_done) {
44909d11b7bfSKarthikeyan Periyasamy parse->num_buf_entry = 0;
44919d11b7bfSKarthikeyan Periyasamy parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr;
44929d11b7bfSKarthikeyan Periyasamy
44939d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, ptr, len,
44949d11b7bfSKarthikeyan Periyasamy ath11k_wmi_tlv_dma_buf_entry_parse,
44959d11b7bfSKarthikeyan Periyasamy parse);
44969d11b7bfSKarthikeyan Periyasamy if (ret) {
44979d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n",
44989d11b7bfSKarthikeyan Periyasamy ret);
44999d11b7bfSKarthikeyan Periyasamy return ret;
45009d11b7bfSKarthikeyan Periyasamy }
45019d11b7bfSKarthikeyan Periyasamy
45029d11b7bfSKarthikeyan Periyasamy parse->buf_entry_done = true;
45039d11b7bfSKarthikeyan Periyasamy } else if (!parse->meta_data_done) {
45049d11b7bfSKarthikeyan Periyasamy parse->num_meta = 0;
45059d11b7bfSKarthikeyan Periyasamy parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr;
45069d11b7bfSKarthikeyan Periyasamy
45079d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, ptr, len,
45089d11b7bfSKarthikeyan Periyasamy ath11k_wmi_tlv_dma_buf_meta_parse,
45099d11b7bfSKarthikeyan Periyasamy parse);
45109d11b7bfSKarthikeyan Periyasamy if (ret) {
45119d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n",
45129d11b7bfSKarthikeyan Periyasamy ret);
45139d11b7bfSKarthikeyan Periyasamy return ret;
45149d11b7bfSKarthikeyan Periyasamy }
45159d11b7bfSKarthikeyan Periyasamy
45169d11b7bfSKarthikeyan Periyasamy parse->meta_data_done = true;
45179d11b7bfSKarthikeyan Periyasamy }
45189d11b7bfSKarthikeyan Periyasamy break;
45199d11b7bfSKarthikeyan Periyasamy default:
45209d11b7bfSKarthikeyan Periyasamy break;
45219d11b7bfSKarthikeyan Periyasamy }
45229d11b7bfSKarthikeyan Periyasamy return 0;
45239d11b7bfSKarthikeyan Periyasamy }
45249d11b7bfSKarthikeyan Periyasamy
ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base * ab,struct sk_buff * skb)45259d11b7bfSKarthikeyan Periyasamy static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab,
45269d11b7bfSKarthikeyan Periyasamy struct sk_buff *skb)
45279d11b7bfSKarthikeyan Periyasamy {
45289d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse parse = { };
45299d11b7bfSKarthikeyan Periyasamy struct ath11k_dbring_buf_release_event param;
45309d11b7bfSKarthikeyan Periyasamy int ret;
45319d11b7bfSKarthikeyan Periyasamy
45329d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
45339d11b7bfSKarthikeyan Periyasamy ath11k_wmi_tlv_dma_buf_parse,
45349d11b7bfSKarthikeyan Periyasamy &parse);
45359d11b7bfSKarthikeyan Periyasamy if (ret) {
45369d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret);
45379d11b7bfSKarthikeyan Periyasamy return;
45389d11b7bfSKarthikeyan Periyasamy }
45399d11b7bfSKarthikeyan Periyasamy
4540e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev dma ring buf release");
4541e5df1577SKalle Valo
45429d11b7bfSKarthikeyan Periyasamy param.fixed = parse.fixed;
45439d11b7bfSKarthikeyan Periyasamy param.buf_entry = parse.buf_entry;
45449d11b7bfSKarthikeyan Periyasamy param.num_buf_entry = parse.num_buf_entry;
45459d11b7bfSKarthikeyan Periyasamy param.meta_data = parse.meta_data;
45469d11b7bfSKarthikeyan Periyasamy param.num_meta = parse.num_meta;
45479d11b7bfSKarthikeyan Periyasamy
45489d11b7bfSKarthikeyan Periyasamy ret = ath11k_dbring_buffer_release_event(ab, ¶m);
45499d11b7bfSKarthikeyan Periyasamy if (ret) {
45509d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
45519d11b7bfSKarthikeyan Periyasamy return;
45529d11b7bfSKarthikeyan Periyasamy }
45539d11b7bfSKarthikeyan Periyasamy }
45549d11b7bfSKarthikeyan Periyasamy
ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4555d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
4556d5c65159SKalle Valo u16 tag, u16 len,
4557d5c65159SKalle Valo const void *ptr, void *data)
4558d5c65159SKalle Valo {
4559d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4560d5c65159SKalle Valo struct wmi_hw_mode_capabilities *hw_mode_cap;
4561d5c65159SKalle Valo u32 phy_map = 0;
4562d5c65159SKalle Valo
4563d5c65159SKalle Valo if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
4564d5c65159SKalle Valo return -EPROTO;
4565d5c65159SKalle Valo
4566d5c65159SKalle Valo if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
4567d5c65159SKalle Valo return -ENOBUFS;
4568d5c65159SKalle Valo
4569d5c65159SKalle Valo hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
4570d5c65159SKalle Valo hw_mode_id);
4571d5c65159SKalle Valo svc_rdy_ext->n_hw_mode_caps++;
4572d5c65159SKalle Valo
4573d5c65159SKalle Valo phy_map = hw_mode_cap->phy_id_map;
4574d5c65159SKalle Valo while (phy_map) {
4575d5c65159SKalle Valo svc_rdy_ext->tot_phy_id++;
4576d5c65159SKalle Valo phy_map = phy_map >> 1;
4577d5c65159SKalle Valo }
4578d5c65159SKalle Valo
4579d5c65159SKalle Valo return 0;
4580d5c65159SKalle Valo }
4581d5c65159SKalle Valo
ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base * soc,u16 len,const void * ptr,void * data)4582d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
4583d5c65159SKalle Valo u16 len, const void *ptr, void *data)
4584d5c65159SKalle Valo {
4585d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4586d5c65159SKalle Valo struct wmi_hw_mode_capabilities *hw_mode_caps;
4587d5c65159SKalle Valo enum wmi_host_hw_mode_config_type mode, pref;
4588d5c65159SKalle Valo u32 i;
4589d5c65159SKalle Valo int ret;
4590d5c65159SKalle Valo
4591d5c65159SKalle Valo svc_rdy_ext->n_hw_mode_caps = 0;
4592d5c65159SKalle Valo svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
4593d5c65159SKalle Valo
4594d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4595d5c65159SKalle Valo ath11k_wmi_tlv_hw_mode_caps_parse,
4596d5c65159SKalle Valo svc_rdy_ext);
4597d5c65159SKalle Valo if (ret) {
4598d5c65159SKalle Valo ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4599d5c65159SKalle Valo return ret;
4600d5c65159SKalle Valo }
4601d5c65159SKalle Valo
4602d5c65159SKalle Valo i = 0;
4603d5c65159SKalle Valo while (i < svc_rdy_ext->n_hw_mode_caps) {
4604d5c65159SKalle Valo hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
4605d5c65159SKalle Valo mode = hw_mode_caps->hw_mode_id;
46066bc9d6f7SJohn Crispin pref = soc->wmi_ab.preferred_hw_mode;
4607d5c65159SKalle Valo
4608d5c65159SKalle Valo if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
4609d5c65159SKalle Valo svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
46106bc9d6f7SJohn Crispin soc->wmi_ab.preferred_hw_mode = mode;
4611d5c65159SKalle Valo }
4612d5c65159SKalle Valo i++;
4613d5c65159SKalle Valo }
4614d5c65159SKalle Valo
46155f859bc0SCarl Huang ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n",
46165f859bc0SCarl Huang soc->wmi_ab.preferred_hw_mode);
46176bc9d6f7SJohn Crispin if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
4618d5c65159SKalle Valo return -EINVAL;
4619d5c65159SKalle Valo
4620d5c65159SKalle Valo return 0;
4621d5c65159SKalle Valo }
4622d5c65159SKalle Valo
ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4623d5c65159SKalle Valo static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
4624d5c65159SKalle Valo u16 tag, u16 len,
4625d5c65159SKalle Valo const void *ptr, void *data)
4626d5c65159SKalle Valo {
4627d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4628d5c65159SKalle Valo
4629d5c65159SKalle Valo if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
4630d5c65159SKalle Valo return -EPROTO;
4631d5c65159SKalle Valo
4632d5c65159SKalle Valo if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
4633d5c65159SKalle Valo return -ENOBUFS;
4634d5c65159SKalle Valo
46355b90fc76SAnilkumar Kolli len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
46365b90fc76SAnilkumar Kolli if (!svc_rdy_ext->n_mac_phy_caps) {
4637ec436338SGustavo A. R. Silva svc_rdy_ext->mac_phy_caps = kcalloc(svc_rdy_ext->tot_phy_id,
4638ec436338SGustavo A. R. Silva len, GFP_ATOMIC);
46395b90fc76SAnilkumar Kolli if (!svc_rdy_ext->mac_phy_caps)
46405b90fc76SAnilkumar Kolli return -ENOMEM;
46415b90fc76SAnilkumar Kolli }
46425b90fc76SAnilkumar Kolli
46435b90fc76SAnilkumar Kolli memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
4644d5c65159SKalle Valo svc_rdy_ext->n_mac_phy_caps++;
4645d5c65159SKalle Valo return 0;
4646d5c65159SKalle Valo }
4647d5c65159SKalle Valo
ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4648d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
4649d5c65159SKalle Valo u16 tag, u16 len,
4650d5c65159SKalle Valo const void *ptr, void *data)
4651d5c65159SKalle Valo {
4652d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4653d5c65159SKalle Valo
4654d5c65159SKalle Valo if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
4655d5c65159SKalle Valo return -EPROTO;
4656d5c65159SKalle Valo
4657d5c65159SKalle Valo if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
4658d5c65159SKalle Valo return -ENOBUFS;
4659d5c65159SKalle Valo
4660d5c65159SKalle Valo svc_rdy_ext->n_ext_hal_reg_caps++;
4661d5c65159SKalle Valo return 0;
4662d5c65159SKalle Valo }
4663d5c65159SKalle Valo
ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base * soc,u16 len,const void * ptr,void * data)4664d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
4665d5c65159SKalle Valo u16 len, const void *ptr, void *data)
4666d5c65159SKalle Valo {
46676bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4668d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4669d5c65159SKalle Valo struct ath11k_hal_reg_capabilities_ext reg_cap;
4670d5c65159SKalle Valo int ret;
4671d5c65159SKalle Valo u32 i;
4672d5c65159SKalle Valo
4673d5c65159SKalle Valo svc_rdy_ext->n_ext_hal_reg_caps = 0;
4674d5c65159SKalle Valo svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
4675d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4676d5c65159SKalle Valo ath11k_wmi_tlv_ext_hal_reg_caps_parse,
4677d5c65159SKalle Valo svc_rdy_ext);
4678d5c65159SKalle Valo if (ret) {
4679d5c65159SKalle Valo ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4680d5c65159SKalle Valo return ret;
4681d5c65159SKalle Valo }
4682d5c65159SKalle Valo
4683d5c65159SKalle Valo for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
4684d5c65159SKalle Valo ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
4685d5c65159SKalle Valo svc_rdy_ext->soc_hal_reg_caps,
4686d5c65159SKalle Valo svc_rdy_ext->ext_hal_reg_caps, i,
4687d5c65159SKalle Valo ®_cap);
4688d5c65159SKalle Valo if (ret) {
4689d5c65159SKalle Valo ath11k_warn(soc, "failed to extract reg cap %d\n", i);
4690d5c65159SKalle Valo return ret;
4691d5c65159SKalle Valo }
4692d5c65159SKalle Valo
4693d5c65159SKalle Valo memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
4694d5c65159SKalle Valo ®_cap, sizeof(reg_cap));
4695d5c65159SKalle Valo }
4696d5c65159SKalle Valo return 0;
4697d5c65159SKalle Valo }
4698d5c65159SKalle Valo
ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base * soc,u16 len,const void * ptr,void * data)4699d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
4700d5c65159SKalle Valo u16 len, const void *ptr,
4701d5c65159SKalle Valo void *data)
4702d5c65159SKalle Valo {
47036bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4704d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4705d5c65159SKalle Valo u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
4706d5c65159SKalle Valo u32 phy_id_map;
47075f859bc0SCarl Huang int pdev_index = 0;
4708d5c65159SKalle Valo int ret;
4709d5c65159SKalle Valo
4710d5c65159SKalle Valo svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
4711d5c65159SKalle Valo svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
4712d5c65159SKalle Valo
4713d5c65159SKalle Valo soc->num_radios = 0;
471413706340SWen Gong soc->target_pdev_count = 0;
4715d5c65159SKalle Valo phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
4716d5c65159SKalle Valo
4717d5c65159SKalle Valo while (phy_id_map && soc->num_radios < MAX_RADIOS) {
4718d5c65159SKalle Valo ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
4719d5c65159SKalle Valo svc_rdy_ext->hw_caps,
4720d5c65159SKalle Valo svc_rdy_ext->hw_mode_caps,
4721d5c65159SKalle Valo svc_rdy_ext->soc_hal_reg_caps,
4722d5c65159SKalle Valo svc_rdy_ext->mac_phy_caps,
4723d5c65159SKalle Valo hw_mode_id, soc->num_radios,
47245f859bc0SCarl Huang &soc->pdevs[pdev_index]);
4725d5c65159SKalle Valo if (ret) {
4726d5c65159SKalle Valo ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
4727d5c65159SKalle Valo soc->num_radios);
4728d5c65159SKalle Valo return ret;
4729d5c65159SKalle Valo }
4730d5c65159SKalle Valo
4731d5c65159SKalle Valo soc->num_radios++;
4732d5c65159SKalle Valo
47335f859bc0SCarl Huang /* For QCA6390, save mac_phy capability in the same pdev */
47345f859bc0SCarl Huang if (soc->hw_params.single_pdev_only)
47355f859bc0SCarl Huang pdev_index = 0;
47365f859bc0SCarl Huang else
47375f859bc0SCarl Huang pdev_index = soc->num_radios;
47385f859bc0SCarl Huang
4739d5c65159SKalle Valo /* TODO: mac_phy_cap prints */
4740d5c65159SKalle Valo phy_id_map >>= 1;
4741d5c65159SKalle Valo }
47425f859bc0SCarl Huang
47435f859bc0SCarl Huang /* For QCA6390, set num_radios to 1 because host manages
47445f859bc0SCarl Huang * both 2G and 5G radio in one pdev.
47455f859bc0SCarl Huang * Set pdev_id = 0 and 0 means soc level.
47465f859bc0SCarl Huang */
47475f859bc0SCarl Huang if (soc->hw_params.single_pdev_only) {
47485f859bc0SCarl Huang soc->num_radios = 1;
47495f859bc0SCarl Huang soc->pdevs[0].pdev_id = 0;
47505f859bc0SCarl Huang }
47515f859bc0SCarl Huang
4752d5c65159SKalle Valo return 0;
4753d5c65159SKalle Valo }
4754d5c65159SKalle Valo
ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4755bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc,
4756bd647855SKarthikeyan Periyasamy u16 tag, u16 len,
4757bd647855SKarthikeyan Periyasamy const void *ptr, void *data)
4758bd647855SKarthikeyan Periyasamy {
4759bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse *parse = data;
4760bd647855SKarthikeyan Periyasamy
4761bd647855SKarthikeyan Periyasamy if (tag != WMI_TAG_DMA_RING_CAPABILITIES)
4762bd647855SKarthikeyan Periyasamy return -EPROTO;
4763bd647855SKarthikeyan Periyasamy
4764bd647855SKarthikeyan Periyasamy parse->n_dma_ring_caps++;
4765bd647855SKarthikeyan Periyasamy return 0;
4766bd647855SKarthikeyan Periyasamy }
4767bd647855SKarthikeyan Periyasamy
ath11k_wmi_alloc_dbring_caps(struct ath11k_base * ab,u32 num_cap)4768bd647855SKarthikeyan Periyasamy static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab,
4769bd647855SKarthikeyan Periyasamy u32 num_cap)
4770bd647855SKarthikeyan Periyasamy {
4771bd647855SKarthikeyan Periyasamy size_t sz;
4772bd647855SKarthikeyan Periyasamy void *ptr;
4773bd647855SKarthikeyan Periyasamy
4774bd647855SKarthikeyan Periyasamy sz = num_cap * sizeof(struct ath11k_dbring_cap);
4775bd647855SKarthikeyan Periyasamy ptr = kzalloc(sz, GFP_ATOMIC);
4776bd647855SKarthikeyan Periyasamy if (!ptr)
4777bd647855SKarthikeyan Periyasamy return -ENOMEM;
4778bd647855SKarthikeyan Periyasamy
4779bd647855SKarthikeyan Periyasamy ab->db_caps = ptr;
4780bd647855SKarthikeyan Periyasamy ab->num_db_cap = num_cap;
4781bd647855SKarthikeyan Periyasamy
4782bd647855SKarthikeyan Periyasamy return 0;
4783bd647855SKarthikeyan Periyasamy }
4784bd647855SKarthikeyan Periyasamy
ath11k_wmi_free_dbring_caps(struct ath11k_base * ab)4785bd647855SKarthikeyan Periyasamy static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
4786bd647855SKarthikeyan Periyasamy {
4787bd647855SKarthikeyan Periyasamy kfree(ab->db_caps);
4788bd647855SKarthikeyan Periyasamy ab->db_caps = NULL;
4789bd647855SKarthikeyan Periyasamy }
4790bd647855SKarthikeyan Periyasamy
ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base * ab,u16 len,const void * ptr,void * data)4791bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab,
4792bd647855SKarthikeyan Periyasamy u16 len, const void *ptr, void *data)
4793bd647855SKarthikeyan Periyasamy {
4794bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data;
4795bd647855SKarthikeyan Periyasamy struct wmi_dma_ring_capabilities *dma_caps;
4796bd647855SKarthikeyan Periyasamy struct ath11k_dbring_cap *dir_buff_caps;
4797bd647855SKarthikeyan Periyasamy int ret;
4798bd647855SKarthikeyan Periyasamy u32 i;
4799bd647855SKarthikeyan Periyasamy
4800bd647855SKarthikeyan Periyasamy dma_caps_parse->n_dma_ring_caps = 0;
4801bd647855SKarthikeyan Periyasamy dma_caps = (struct wmi_dma_ring_capabilities *)ptr;
4802bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4803bd647855SKarthikeyan Periyasamy ath11k_wmi_tlv_dma_ring_caps_parse,
4804bd647855SKarthikeyan Periyasamy dma_caps_parse);
4805bd647855SKarthikeyan Periyasamy if (ret) {
4806bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret);
4807bd647855SKarthikeyan Periyasamy return ret;
4808bd647855SKarthikeyan Periyasamy }
4809bd647855SKarthikeyan Periyasamy
4810bd647855SKarthikeyan Periyasamy if (!dma_caps_parse->n_dma_ring_caps)
4811bd647855SKarthikeyan Periyasamy return 0;
4812bd647855SKarthikeyan Periyasamy
4813bd647855SKarthikeyan Periyasamy if (ab->num_db_cap) {
4814bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n");
4815bd647855SKarthikeyan Periyasamy return 0;
4816bd647855SKarthikeyan Periyasamy }
4817bd647855SKarthikeyan Periyasamy
4818bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps);
4819bd647855SKarthikeyan Periyasamy if (ret)
4820bd647855SKarthikeyan Periyasamy return ret;
4821bd647855SKarthikeyan Periyasamy
4822bd647855SKarthikeyan Periyasamy dir_buff_caps = ab->db_caps;
4823bd647855SKarthikeyan Periyasamy for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) {
4824bd647855SKarthikeyan Periyasamy if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) {
4825bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id);
4826bd647855SKarthikeyan Periyasamy ret = -EINVAL;
4827bd647855SKarthikeyan Periyasamy goto free_dir_buff;
4828bd647855SKarthikeyan Periyasamy }
4829bd647855SKarthikeyan Periyasamy
4830bd647855SKarthikeyan Periyasamy dir_buff_caps[i].id = dma_caps[i].module_id;
4831bd647855SKarthikeyan Periyasamy dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id);
4832bd647855SKarthikeyan Periyasamy dir_buff_caps[i].min_elem = dma_caps[i].min_elem;
4833bd647855SKarthikeyan Periyasamy dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz;
4834bd647855SKarthikeyan Periyasamy dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align;
4835bd647855SKarthikeyan Periyasamy }
4836bd647855SKarthikeyan Periyasamy
4837bd647855SKarthikeyan Periyasamy return 0;
4838bd647855SKarthikeyan Periyasamy
4839bd647855SKarthikeyan Periyasamy free_dir_buff:
4840bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab);
4841bd647855SKarthikeyan Periyasamy return ret;
4842bd647855SKarthikeyan Periyasamy }
4843bd647855SKarthikeyan Periyasamy
ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)4844d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
4845d5c65159SKalle Valo u16 tag, u16 len,
4846d5c65159SKalle Valo const void *ptr, void *data)
4847d5c65159SKalle Valo {
48486bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
4849d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4850d5c65159SKalle Valo int ret;
4851d5c65159SKalle Valo
4852d5c65159SKalle Valo switch (tag) {
4853d5c65159SKalle Valo case WMI_TAG_SERVICE_READY_EXT_EVENT:
4854d5c65159SKalle Valo ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
4855d5c65159SKalle Valo &svc_rdy_ext->param);
4856d5c65159SKalle Valo if (ret) {
4857d5c65159SKalle Valo ath11k_warn(ab, "unable to extract ext params\n");
4858d5c65159SKalle Valo return ret;
4859d5c65159SKalle Valo }
4860d5c65159SKalle Valo break;
4861d5c65159SKalle Valo
4862d5c65159SKalle Valo case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
4863d5c65159SKalle Valo svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
4864d5c65159SKalle Valo svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
4865d5c65159SKalle Valo break;
4866d5c65159SKalle Valo
4867d5c65159SKalle Valo case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
4868d5c65159SKalle Valo ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
4869d5c65159SKalle Valo svc_rdy_ext);
4870d5c65159SKalle Valo if (ret)
4871d5c65159SKalle Valo return ret;
4872d5c65159SKalle Valo break;
4873d5c65159SKalle Valo
4874d5c65159SKalle Valo case WMI_TAG_ARRAY_STRUCT:
4875d5c65159SKalle Valo if (!svc_rdy_ext->hw_mode_done) {
4876d5c65159SKalle Valo ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
4877d5c65159SKalle Valo svc_rdy_ext);
4878d5c65159SKalle Valo if (ret)
4879d5c65159SKalle Valo return ret;
4880d5c65159SKalle Valo
4881d5c65159SKalle Valo svc_rdy_ext->hw_mode_done = true;
4882d5c65159SKalle Valo } else if (!svc_rdy_ext->mac_phy_done) {
4883d5c65159SKalle Valo svc_rdy_ext->n_mac_phy_caps = 0;
4884d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4885d5c65159SKalle Valo ath11k_wmi_tlv_mac_phy_caps_parse,
4886d5c65159SKalle Valo svc_rdy_ext);
4887d5c65159SKalle Valo if (ret) {
4888d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4889d5c65159SKalle Valo return ret;
4890d5c65159SKalle Valo }
4891d5c65159SKalle Valo
4892d5c65159SKalle Valo svc_rdy_ext->mac_phy_done = true;
4893d5c65159SKalle Valo } else if (!svc_rdy_ext->ext_hal_reg_done) {
4894d5c65159SKalle Valo ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
4895d5c65159SKalle Valo svc_rdy_ext);
4896d5c65159SKalle Valo if (ret)
4897d5c65159SKalle Valo return ret;
4898d5c65159SKalle Valo
4899d5c65159SKalle Valo svc_rdy_ext->ext_hal_reg_done = true;
4900bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) {
4901bd647855SKarthikeyan Periyasamy svc_rdy_ext->mac_phy_chainmask_combo_done = true;
4902bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) {
4903bd647855SKarthikeyan Periyasamy svc_rdy_ext->mac_phy_chainmask_cap_done = true;
4904bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->oem_dma_ring_cap_done) {
4905bd647855SKarthikeyan Periyasamy svc_rdy_ext->oem_dma_ring_cap_done = true;
4906bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->dma_ring_cap_done) {
4907bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4908bd647855SKarthikeyan Periyasamy &svc_rdy_ext->dma_caps_parse);
4909bd647855SKarthikeyan Periyasamy if (ret)
4910bd647855SKarthikeyan Periyasamy return ret;
4911bd647855SKarthikeyan Periyasamy
4912bd647855SKarthikeyan Periyasamy svc_rdy_ext->dma_ring_cap_done = true;
4913d5c65159SKalle Valo }
4914d5c65159SKalle Valo break;
4915d5c65159SKalle Valo
4916d5c65159SKalle Valo default:
4917d5c65159SKalle Valo break;
4918d5c65159SKalle Valo }
4919d5c65159SKalle Valo return 0;
4920d5c65159SKalle Valo }
4921d5c65159SKalle Valo
ath11k_service_ready_ext_event(struct ath11k_base * ab,struct sk_buff * skb)4922d5c65159SKalle Valo static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
4923d5c65159SKalle Valo struct sk_buff *skb)
4924d5c65159SKalle Valo {
4925d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
4926d5c65159SKalle Valo int ret;
4927d5c65159SKalle Valo
4928d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4929d5c65159SKalle Valo ath11k_wmi_tlv_svc_rdy_ext_parse,
4930d5c65159SKalle Valo &svc_rdy_ext);
4931d5c65159SKalle Valo if (ret) {
4932d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4933bd647855SKarthikeyan Periyasamy goto err;
4934d5c65159SKalle Valo }
4935d5c65159SKalle Valo
4936e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event service ready ext");
4937e5df1577SKalle Valo
4938bd647855SKarthikeyan Periyasamy if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map))
4939bd647855SKarthikeyan Periyasamy complete(&ab->wmi_ab.service_ready);
4940bd647855SKarthikeyan Periyasamy
49415b90fc76SAnilkumar Kolli kfree(svc_rdy_ext.mac_phy_caps);
4942d5c65159SKalle Valo return 0;
4943bd647855SKarthikeyan Periyasamy
4944bd647855SKarthikeyan Periyasamy err:
4945bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab);
4946bd647855SKarthikeyan Periyasamy return ret;
4947bd647855SKarthikeyan Periyasamy }
4948bd647855SKarthikeyan Periyasamy
ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)4949bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab,
4950bd647855SKarthikeyan Periyasamy u16 tag, u16 len,
4951bd647855SKarthikeyan Periyasamy const void *ptr, void *data)
4952bd647855SKarthikeyan Periyasamy {
4953bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse *parse = data;
4954bd647855SKarthikeyan Periyasamy int ret;
4955bd647855SKarthikeyan Periyasamy
4956bd647855SKarthikeyan Periyasamy switch (tag) {
4957bd647855SKarthikeyan Periyasamy case WMI_TAG_ARRAY_STRUCT:
4958bd647855SKarthikeyan Periyasamy if (!parse->dma_ring_cap_done) {
4959bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4960bd647855SKarthikeyan Periyasamy &parse->dma_caps_parse);
4961bd647855SKarthikeyan Periyasamy if (ret)
4962bd647855SKarthikeyan Periyasamy return ret;
4963bd647855SKarthikeyan Periyasamy
4964bd647855SKarthikeyan Periyasamy parse->dma_ring_cap_done = true;
4965bd647855SKarthikeyan Periyasamy }
4966bd647855SKarthikeyan Periyasamy break;
4967bd647855SKarthikeyan Periyasamy default:
4968bd647855SKarthikeyan Periyasamy break;
4969bd647855SKarthikeyan Periyasamy }
4970bd647855SKarthikeyan Periyasamy
4971bd647855SKarthikeyan Periyasamy return 0;
4972bd647855SKarthikeyan Periyasamy }
4973bd647855SKarthikeyan Periyasamy
ath11k_service_ready_ext2_event(struct ath11k_base * ab,struct sk_buff * skb)4974bd647855SKarthikeyan Periyasamy static int ath11k_service_ready_ext2_event(struct ath11k_base *ab,
4975bd647855SKarthikeyan Periyasamy struct sk_buff *skb)
4976bd647855SKarthikeyan Periyasamy {
4977bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { };
4978bd647855SKarthikeyan Periyasamy int ret;
4979bd647855SKarthikeyan Periyasamy
4980bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4981bd647855SKarthikeyan Periyasamy ath11k_wmi_tlv_svc_rdy_ext2_parse,
4982bd647855SKarthikeyan Periyasamy &svc_rdy_ext2);
4983bd647855SKarthikeyan Periyasamy if (ret) {
4984bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret);
4985bd647855SKarthikeyan Periyasamy goto err;
4986bd647855SKarthikeyan Periyasamy }
4987bd647855SKarthikeyan Periyasamy
4988e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event service ready ext2");
4989e5df1577SKalle Valo
4990bd647855SKarthikeyan Periyasamy complete(&ab->wmi_ab.service_ready);
4991bd647855SKarthikeyan Periyasamy
4992bd647855SKarthikeyan Periyasamy return 0;
4993bd647855SKarthikeyan Periyasamy
4994bd647855SKarthikeyan Periyasamy err:
4995bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab);
4996bd647855SKarthikeyan Periyasamy return ret;
4997d5c65159SKalle Valo }
4998d5c65159SKalle Valo
ath11k_pull_vdev_start_resp_tlv(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_vdev_start_resp_event * vdev_rsp)4999d5c65159SKalle Valo static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5000d5c65159SKalle Valo struct wmi_vdev_start_resp_event *vdev_rsp)
5001d5c65159SKalle Valo {
5002d5c65159SKalle Valo const void **tb;
5003d5c65159SKalle Valo const struct wmi_vdev_start_resp_event *ev;
5004d5c65159SKalle Valo int ret;
5005d5c65159SKalle Valo
5006d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5007d5c65159SKalle Valo if (IS_ERR(tb)) {
5008d5c65159SKalle Valo ret = PTR_ERR(tb);
5009d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5010d5c65159SKalle Valo return ret;
5011d5c65159SKalle Valo }
5012d5c65159SKalle Valo
5013d5c65159SKalle Valo ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
5014d5c65159SKalle Valo if (!ev) {
5015d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch vdev start resp ev");
5016d5c65159SKalle Valo kfree(tb);
5017d5c65159SKalle Valo return -EPROTO;
5018d5c65159SKalle Valo }
5019d5c65159SKalle Valo
5020d5c65159SKalle Valo memset(vdev_rsp, 0, sizeof(*vdev_rsp));
5021d5c65159SKalle Valo
5022d5c65159SKalle Valo vdev_rsp->vdev_id = ev->vdev_id;
5023d5c65159SKalle Valo vdev_rsp->requestor_id = ev->requestor_id;
5024d5c65159SKalle Valo vdev_rsp->resp_type = ev->resp_type;
5025d5c65159SKalle Valo vdev_rsp->status = ev->status;
5026d5c65159SKalle Valo vdev_rsp->chain_mask = ev->chain_mask;
5027d5c65159SKalle Valo vdev_rsp->smps_mode = ev->smps_mode;
5028d5c65159SKalle Valo vdev_rsp->mac_id = ev->mac_id;
5029d5c65159SKalle Valo vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
5030d5c65159SKalle Valo vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
5031d5c65159SKalle Valo
5032d5c65159SKalle Valo kfree(tb);
5033d5c65159SKalle Valo return 0;
5034d5c65159SKalle Valo }
5035d5c65159SKalle Valo
ath11k_print_reg_rule(struct ath11k_base * ab,const char * band,u32 num_reg_rules,struct cur_reg_rule * reg_rule_ptr)5036e238e62bSAditya Kumar Singh static void ath11k_print_reg_rule(struct ath11k_base *ab, const char *band,
5037e238e62bSAditya Kumar Singh u32 num_reg_rules,
5038e238e62bSAditya Kumar Singh struct cur_reg_rule *reg_rule_ptr)
5039e238e62bSAditya Kumar Singh {
5040e238e62bSAditya Kumar Singh struct cur_reg_rule *reg_rule = reg_rule_ptr;
5041e238e62bSAditya Kumar Singh u32 count;
5042e238e62bSAditya Kumar Singh
5043e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "number of reg rules in %s band: %d\n",
5044e238e62bSAditya Kumar Singh band, num_reg_rules);
5045e238e62bSAditya Kumar Singh
5046e238e62bSAditya Kumar Singh for (count = 0; count < num_reg_rules; count++) {
5047e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5048e238e62bSAditya Kumar Singh "reg rule %d: (%d - %d @ %d) (%d, %d) (FLAGS %d)\n",
5049e238e62bSAditya Kumar Singh count + 1, reg_rule->start_freq, reg_rule->end_freq,
5050e238e62bSAditya Kumar Singh reg_rule->max_bw, reg_rule->ant_gain,
5051e238e62bSAditya Kumar Singh reg_rule->reg_power, reg_rule->flags);
5052e238e62bSAditya Kumar Singh reg_rule++;
5053e238e62bSAditya Kumar Singh }
5054e238e62bSAditya Kumar Singh }
5055e238e62bSAditya Kumar Singh
5056d5c65159SKalle Valo static struct cur_reg_rule
create_reg_rules_from_wmi(u32 num_reg_rules,struct wmi_regulatory_rule_struct * wmi_reg_rule)5057d5c65159SKalle Valo *create_reg_rules_from_wmi(u32 num_reg_rules,
5058d5c65159SKalle Valo struct wmi_regulatory_rule_struct *wmi_reg_rule)
5059d5c65159SKalle Valo {
5060d5c65159SKalle Valo struct cur_reg_rule *reg_rule_ptr;
5061d5c65159SKalle Valo u32 count;
5062d5c65159SKalle Valo
5063ec436338SGustavo A. R. Silva reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr),
5064d5c65159SKalle Valo GFP_ATOMIC);
5065d5c65159SKalle Valo
5066d5c65159SKalle Valo if (!reg_rule_ptr)
5067d5c65159SKalle Valo return NULL;
5068d5c65159SKalle Valo
5069d5c65159SKalle Valo for (count = 0; count < num_reg_rules; count++) {
5070d5c65159SKalle Valo reg_rule_ptr[count].start_freq =
5071d5c65159SKalle Valo FIELD_GET(REG_RULE_START_FREQ,
5072d5c65159SKalle Valo wmi_reg_rule[count].freq_info);
5073d5c65159SKalle Valo reg_rule_ptr[count].end_freq =
5074d5c65159SKalle Valo FIELD_GET(REG_RULE_END_FREQ,
5075d5c65159SKalle Valo wmi_reg_rule[count].freq_info);
5076d5c65159SKalle Valo reg_rule_ptr[count].max_bw =
5077d5c65159SKalle Valo FIELD_GET(REG_RULE_MAX_BW,
5078d5c65159SKalle Valo wmi_reg_rule[count].bw_pwr_info);
5079d5c65159SKalle Valo reg_rule_ptr[count].reg_power =
5080d5c65159SKalle Valo FIELD_GET(REG_RULE_REG_PWR,
5081d5c65159SKalle Valo wmi_reg_rule[count].bw_pwr_info);
5082d5c65159SKalle Valo reg_rule_ptr[count].ant_gain =
5083d5c65159SKalle Valo FIELD_GET(REG_RULE_ANT_GAIN,
5084d5c65159SKalle Valo wmi_reg_rule[count].bw_pwr_info);
5085d5c65159SKalle Valo reg_rule_ptr[count].flags =
5086d5c65159SKalle Valo FIELD_GET(REG_RULE_FLAGS,
5087d5c65159SKalle Valo wmi_reg_rule[count].flag_info);
5088d5c65159SKalle Valo }
5089d5c65159SKalle Valo
5090d5c65159SKalle Valo return reg_rule_ptr;
5091d5c65159SKalle Valo }
5092d5c65159SKalle Valo
ath11k_pull_reg_chan_list_update_ev(struct ath11k_base * ab,struct sk_buff * skb,struct cur_regulatory_info * reg_info)5093d5c65159SKalle Valo static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
5094d5c65159SKalle Valo struct sk_buff *skb,
5095d5c65159SKalle Valo struct cur_regulatory_info *reg_info)
5096d5c65159SKalle Valo {
5097d5c65159SKalle Valo const void **tb;
5098d5c65159SKalle Valo const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
5099d5c65159SKalle Valo struct wmi_regulatory_rule_struct *wmi_reg_rule;
510025e289e1SAditya Kumar Singh u32 num_2ghz_reg_rules, num_5ghz_reg_rules;
5101d5c65159SKalle Valo int ret;
5102d5c65159SKalle Valo
5103d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
5104d5c65159SKalle Valo
5105d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5106d5c65159SKalle Valo if (IS_ERR(tb)) {
5107d5c65159SKalle Valo ret = PTR_ERR(tb);
5108d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5109d5c65159SKalle Valo return ret;
5110d5c65159SKalle Valo }
5111d5c65159SKalle Valo
5112d5c65159SKalle Valo chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
5113d5c65159SKalle Valo if (!chan_list_event_hdr) {
5114d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
5115d5c65159SKalle Valo kfree(tb);
5116d5c65159SKalle Valo return -EPROTO;
5117d5c65159SKalle Valo }
5118d5c65159SKalle Valo
511925e289e1SAditya Kumar Singh reg_info->num_2ghz_reg_rules = chan_list_event_hdr->num_2ghz_reg_rules;
512025e289e1SAditya Kumar Singh reg_info->num_5ghz_reg_rules = chan_list_event_hdr->num_5ghz_reg_rules;
5121d5c65159SKalle Valo
512225e289e1SAditya Kumar Singh if (!(reg_info->num_2ghz_reg_rules + reg_info->num_5ghz_reg_rules)) {
5123d5c65159SKalle Valo ath11k_warn(ab, "No regulatory rules available in the event info\n");
5124d5c65159SKalle Valo kfree(tb);
5125d5c65159SKalle Valo return -EINVAL;
5126d5c65159SKalle Valo }
5127d5c65159SKalle Valo
5128d5c65159SKalle Valo memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
5129d5c65159SKalle Valo REG_ALPHA2_LEN);
5130d5c65159SKalle Valo reg_info->dfs_region = chan_list_event_hdr->dfs_region;
5131d5c65159SKalle Valo reg_info->phybitmap = chan_list_event_hdr->phybitmap;
5132d5c65159SKalle Valo reg_info->num_phy = chan_list_event_hdr->num_phy;
5133d5c65159SKalle Valo reg_info->phy_id = chan_list_event_hdr->phy_id;
5134d5c65159SKalle Valo reg_info->ctry_code = chan_list_event_hdr->country_id;
5135d5c65159SKalle Valo reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
513691fa00faSAditya Kumar Singh
5137e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5138e238e62bSAditya Kumar Singh "status_code %s",
5139e238e62bSAditya Kumar Singh ath11k_cc_status_to_str(reg_info->status_code));
5140e238e62bSAditya Kumar Singh
514191fa00faSAditya Kumar Singh reg_info->status_code =
514291fa00faSAditya Kumar Singh ath11k_wmi_cc_setting_code_to_reg(chan_list_event_hdr->status_code);
514391fa00faSAditya Kumar Singh
514491fa00faSAditya Kumar Singh reg_info->is_ext_reg_event = false;
5145d5c65159SKalle Valo
514625e289e1SAditya Kumar Singh reg_info->min_bw_2ghz = chan_list_event_hdr->min_bw_2ghz;
514725e289e1SAditya Kumar Singh reg_info->max_bw_2ghz = chan_list_event_hdr->max_bw_2ghz;
514825e289e1SAditya Kumar Singh reg_info->min_bw_5ghz = chan_list_event_hdr->min_bw_5ghz;
514925e289e1SAditya Kumar Singh reg_info->max_bw_5ghz = chan_list_event_hdr->max_bw_5ghz;
5150d5c65159SKalle Valo
515125e289e1SAditya Kumar Singh num_2ghz_reg_rules = reg_info->num_2ghz_reg_rules;
515225e289e1SAditya Kumar Singh num_5ghz_reg_rules = reg_info->num_5ghz_reg_rules;
5153d5c65159SKalle Valo
5154d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
5155e238e62bSAditya Kumar Singh "cc %s dsf %d BW: min_2ghz %d max_2ghz %d min_5ghz %d max_5ghz %d",
5156e238e62bSAditya Kumar Singh reg_info->alpha2, reg_info->dfs_region,
515725e289e1SAditya Kumar Singh reg_info->min_bw_2ghz, reg_info->max_bw_2ghz,
515825e289e1SAditya Kumar Singh reg_info->min_bw_5ghz, reg_info->max_bw_5ghz);
5159d5c65159SKalle Valo
5160d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
5161e238e62bSAditya Kumar Singh "num_2ghz_reg_rules %d num_5ghz_reg_rules %d",
516225e289e1SAditya Kumar Singh num_2ghz_reg_rules, num_5ghz_reg_rules);
5163d5c65159SKalle Valo
5164d5c65159SKalle Valo wmi_reg_rule =
5165d5c65159SKalle Valo (struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
5166d5c65159SKalle Valo + sizeof(*chan_list_event_hdr)
5167d5c65159SKalle Valo + sizeof(struct wmi_tlv));
5168d5c65159SKalle Valo
516925e289e1SAditya Kumar Singh if (num_2ghz_reg_rules) {
517025e289e1SAditya Kumar Singh reg_info->reg_rules_2ghz_ptr =
517125e289e1SAditya Kumar Singh create_reg_rules_from_wmi(num_2ghz_reg_rules,
5172d5c65159SKalle Valo wmi_reg_rule);
517325e289e1SAditya Kumar Singh if (!reg_info->reg_rules_2ghz_ptr) {
5174d5c65159SKalle Valo kfree(tb);
517525e289e1SAditya Kumar Singh ath11k_warn(ab, "Unable to Allocate memory for 2 GHz rules\n");
5176d5c65159SKalle Valo return -ENOMEM;
5177d5c65159SKalle Valo }
5178e238e62bSAditya Kumar Singh
5179e238e62bSAditya Kumar Singh ath11k_print_reg_rule(ab, "2 GHz",
5180e238e62bSAditya Kumar Singh num_2ghz_reg_rules,
5181e238e62bSAditya Kumar Singh reg_info->reg_rules_2ghz_ptr);
5182d5c65159SKalle Valo }
5183d5c65159SKalle Valo
518425e289e1SAditya Kumar Singh if (num_5ghz_reg_rules) {
518525e289e1SAditya Kumar Singh wmi_reg_rule += num_2ghz_reg_rules;
518625e289e1SAditya Kumar Singh reg_info->reg_rules_5ghz_ptr =
518725e289e1SAditya Kumar Singh create_reg_rules_from_wmi(num_5ghz_reg_rules,
5188d5c65159SKalle Valo wmi_reg_rule);
518925e289e1SAditya Kumar Singh if (!reg_info->reg_rules_5ghz_ptr) {
5190d5c65159SKalle Valo kfree(tb);
519125e289e1SAditya Kumar Singh ath11k_warn(ab, "Unable to Allocate memory for 5 GHz rules\n");
5192d5c65159SKalle Valo return -ENOMEM;
5193d5c65159SKalle Valo }
5194e238e62bSAditya Kumar Singh
5195e238e62bSAditya Kumar Singh ath11k_print_reg_rule(ab, "5 GHz",
5196e238e62bSAditya Kumar Singh num_5ghz_reg_rules,
5197e238e62bSAditya Kumar Singh reg_info->reg_rules_5ghz_ptr);
5198d5c65159SKalle Valo }
5199d5c65159SKalle Valo
5200d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
5201d5c65159SKalle Valo
5202d5c65159SKalle Valo kfree(tb);
5203d5c65159SKalle Valo return 0;
5204d5c65159SKalle Valo }
5205d5c65159SKalle Valo
520691fa00faSAditya Kumar Singh static struct cur_reg_rule
create_ext_reg_rules_from_wmi(u32 num_reg_rules,struct wmi_regulatory_ext_rule * wmi_reg_rule)520791fa00faSAditya Kumar Singh *create_ext_reg_rules_from_wmi(u32 num_reg_rules,
520891fa00faSAditya Kumar Singh struct wmi_regulatory_ext_rule *wmi_reg_rule)
520991fa00faSAditya Kumar Singh {
521091fa00faSAditya Kumar Singh struct cur_reg_rule *reg_rule_ptr;
521191fa00faSAditya Kumar Singh u32 count;
521291fa00faSAditya Kumar Singh
521391fa00faSAditya Kumar Singh reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr), GFP_ATOMIC);
521491fa00faSAditya Kumar Singh
521591fa00faSAditya Kumar Singh if (!reg_rule_ptr)
521691fa00faSAditya Kumar Singh return NULL;
521791fa00faSAditya Kumar Singh
521891fa00faSAditya Kumar Singh for (count = 0; count < num_reg_rules; count++) {
521991fa00faSAditya Kumar Singh reg_rule_ptr[count].start_freq =
522091fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].freq_info,
522191fa00faSAditya Kumar Singh REG_RULE_START_FREQ);
522291fa00faSAditya Kumar Singh reg_rule_ptr[count].end_freq =
522391fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].freq_info,
522491fa00faSAditya Kumar Singh REG_RULE_END_FREQ);
522591fa00faSAditya Kumar Singh reg_rule_ptr[count].max_bw =
522691fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].bw_pwr_info,
522791fa00faSAditya Kumar Singh REG_RULE_MAX_BW);
522891fa00faSAditya Kumar Singh reg_rule_ptr[count].reg_power =
522991fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].bw_pwr_info,
523091fa00faSAditya Kumar Singh REG_RULE_REG_PWR);
523191fa00faSAditya Kumar Singh reg_rule_ptr[count].ant_gain =
523291fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].bw_pwr_info,
523391fa00faSAditya Kumar Singh REG_RULE_ANT_GAIN);
523491fa00faSAditya Kumar Singh reg_rule_ptr[count].flags =
523591fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].flag_info,
523691fa00faSAditya Kumar Singh REG_RULE_FLAGS);
523791fa00faSAditya Kumar Singh reg_rule_ptr[count].psd_flag =
523891fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].psd_power_info,
523991fa00faSAditya Kumar Singh REG_RULE_PSD_INFO);
524091fa00faSAditya Kumar Singh reg_rule_ptr[count].psd_eirp =
524191fa00faSAditya Kumar Singh u32_get_bits(wmi_reg_rule[count].psd_power_info,
524291fa00faSAditya Kumar Singh REG_RULE_PSD_EIRP);
524391fa00faSAditya Kumar Singh }
524491fa00faSAditya Kumar Singh
524591fa00faSAditya Kumar Singh return reg_rule_ptr;
524691fa00faSAditya Kumar Singh }
524791fa00faSAditya Kumar Singh
524891fa00faSAditya Kumar Singh static u8
ath11k_invalid_5ghz_reg_ext_rules_from_wmi(u32 num_reg_rules,const struct wmi_regulatory_ext_rule * rule)524991fa00faSAditya Kumar Singh ath11k_invalid_5ghz_reg_ext_rules_from_wmi(u32 num_reg_rules,
525091fa00faSAditya Kumar Singh const struct wmi_regulatory_ext_rule *rule)
525191fa00faSAditya Kumar Singh {
525291fa00faSAditya Kumar Singh u8 num_invalid_5ghz_rules = 0;
525391fa00faSAditya Kumar Singh u32 count, start_freq;
525491fa00faSAditya Kumar Singh
525591fa00faSAditya Kumar Singh for (count = 0; count < num_reg_rules; count++) {
525691fa00faSAditya Kumar Singh start_freq = u32_get_bits(rule[count].freq_info,
525791fa00faSAditya Kumar Singh REG_RULE_START_FREQ);
525891fa00faSAditya Kumar Singh
525991fa00faSAditya Kumar Singh if (start_freq >= ATH11K_MIN_6G_FREQ)
526091fa00faSAditya Kumar Singh num_invalid_5ghz_rules++;
526191fa00faSAditya Kumar Singh }
526291fa00faSAditya Kumar Singh
526391fa00faSAditya Kumar Singh return num_invalid_5ghz_rules;
526491fa00faSAditya Kumar Singh }
526591fa00faSAditya Kumar Singh
ath11k_pull_reg_chan_list_ext_update_ev(struct ath11k_base * ab,struct sk_buff * skb,struct cur_regulatory_info * reg_info)526691fa00faSAditya Kumar Singh static int ath11k_pull_reg_chan_list_ext_update_ev(struct ath11k_base *ab,
526791fa00faSAditya Kumar Singh struct sk_buff *skb,
526891fa00faSAditya Kumar Singh struct cur_regulatory_info *reg_info)
526991fa00faSAditya Kumar Singh {
527091fa00faSAditya Kumar Singh const void **tb;
5271e238e62bSAditya Kumar Singh const struct wmi_reg_chan_list_cc_ext_event *ev;
527291fa00faSAditya Kumar Singh struct wmi_regulatory_ext_rule *ext_wmi_reg_rule;
527391fa00faSAditya Kumar Singh u32 num_2ghz_reg_rules, num_5ghz_reg_rules;
527491fa00faSAditya Kumar Singh u32 num_6ghz_reg_rules_ap[WMI_REG_CURRENT_MAX_AP_TYPE];
527591fa00faSAditya Kumar Singh u32 num_6ghz_client[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];
527691fa00faSAditya Kumar Singh u32 total_reg_rules = 0;
527791fa00faSAditya Kumar Singh int ret, i, j, num_invalid_5ghz_ext_rules = 0;
527891fa00faSAditya Kumar Singh
527991fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory ext channel list\n");
528091fa00faSAditya Kumar Singh
528191fa00faSAditya Kumar Singh tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
528291fa00faSAditya Kumar Singh if (IS_ERR(tb)) {
528391fa00faSAditya Kumar Singh ret = PTR_ERR(tb);
528491fa00faSAditya Kumar Singh ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
528591fa00faSAditya Kumar Singh return ret;
528691fa00faSAditya Kumar Singh }
528791fa00faSAditya Kumar Singh
5288e238e62bSAditya Kumar Singh ev = tb[WMI_TAG_REG_CHAN_LIST_CC_EXT_EVENT];
5289e238e62bSAditya Kumar Singh if (!ev) {
529091fa00faSAditya Kumar Singh ath11k_warn(ab, "failed to fetch reg chan list ext update ev\n");
529191fa00faSAditya Kumar Singh kfree(tb);
529291fa00faSAditya Kumar Singh return -EPROTO;
529391fa00faSAditya Kumar Singh }
529491fa00faSAditya Kumar Singh
5295e238e62bSAditya Kumar Singh reg_info->num_2ghz_reg_rules = ev->num_2ghz_reg_rules;
5296e238e62bSAditya Kumar Singh reg_info->num_5ghz_reg_rules = ev->num_5ghz_reg_rules;
529791fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_ap[WMI_REG_INDOOR_AP] =
5298e238e62bSAditya Kumar Singh ev->num_6ghz_reg_rules_ap_lpi;
529991fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_ap[WMI_REG_STANDARD_POWER_AP] =
5300e238e62bSAditya Kumar Singh ev->num_6ghz_reg_rules_ap_sp;
530191fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_ap[WMI_REG_VERY_LOW_POWER_AP] =
5302e238e62bSAditya Kumar Singh ev->num_6ghz_reg_rules_ap_vlp;
530391fa00faSAditya Kumar Singh
530491fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
530591fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_client[WMI_REG_INDOOR_AP][i] =
5306e238e62bSAditya Kumar Singh ev->num_6ghz_reg_rules_client_lpi[i];
530791fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_client[WMI_REG_STANDARD_POWER_AP][i] =
5308e238e62bSAditya Kumar Singh ev->num_6ghz_reg_rules_client_sp[i];
530991fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5310e238e62bSAditya Kumar Singh ev->num_6ghz_reg_rules_client_vlp[i];
531191fa00faSAditya Kumar Singh }
531291fa00faSAditya Kumar Singh
531391fa00faSAditya Kumar Singh num_2ghz_reg_rules = reg_info->num_2ghz_reg_rules;
531491fa00faSAditya Kumar Singh num_5ghz_reg_rules = reg_info->num_5ghz_reg_rules;
531591fa00faSAditya Kumar Singh
531691fa00faSAditya Kumar Singh total_reg_rules += num_2ghz_reg_rules;
531791fa00faSAditya Kumar Singh total_reg_rules += num_5ghz_reg_rules;
531891fa00faSAditya Kumar Singh
531991fa00faSAditya Kumar Singh if ((num_2ghz_reg_rules > MAX_REG_RULES) ||
532091fa00faSAditya Kumar Singh (num_5ghz_reg_rules > MAX_REG_RULES)) {
532191fa00faSAditya Kumar Singh ath11k_warn(ab, "Num reg rules for 2.4 GHz/5 GHz exceeds max limit (num_2ghz_reg_rules: %d num_5ghz_reg_rules: %d max_rules: %d)\n",
532291fa00faSAditya Kumar Singh num_2ghz_reg_rules, num_5ghz_reg_rules, MAX_REG_RULES);
532391fa00faSAditya Kumar Singh kfree(tb);
532491fa00faSAditya Kumar Singh return -EINVAL;
532591fa00faSAditya Kumar Singh }
532691fa00faSAditya Kumar Singh
532791fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++) {
532891fa00faSAditya Kumar Singh num_6ghz_reg_rules_ap[i] = reg_info->num_6ghz_rules_ap[i];
532991fa00faSAditya Kumar Singh
533091fa00faSAditya Kumar Singh if (num_6ghz_reg_rules_ap[i] > MAX_6GHZ_REG_RULES) {
533191fa00faSAditya Kumar Singh ath11k_warn(ab, "Num 6 GHz reg rules for AP mode(%d) exceeds max limit (num_6ghz_reg_rules_ap: %d, max_rules: %d)\n",
533291fa00faSAditya Kumar Singh i, num_6ghz_reg_rules_ap[i], MAX_6GHZ_REG_RULES);
533391fa00faSAditya Kumar Singh kfree(tb);
533491fa00faSAditya Kumar Singh return -EINVAL;
533591fa00faSAditya Kumar Singh }
533691fa00faSAditya Kumar Singh
533791fa00faSAditya Kumar Singh total_reg_rules += num_6ghz_reg_rules_ap[i];
533891fa00faSAditya Kumar Singh }
533991fa00faSAditya Kumar Singh
534091fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
534191fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_INDOOR_AP][i] =
534291fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_client[WMI_REG_INDOOR_AP][i];
534391fa00faSAditya Kumar Singh total_reg_rules += num_6ghz_client[WMI_REG_INDOOR_AP][i];
534491fa00faSAditya Kumar Singh
534591fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
534691fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_client[WMI_REG_STANDARD_POWER_AP][i];
534791fa00faSAditya Kumar Singh total_reg_rules += num_6ghz_client[WMI_REG_STANDARD_POWER_AP][i];
534891fa00faSAditya Kumar Singh
534991fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
535091fa00faSAditya Kumar Singh reg_info->num_6ghz_rules_client[WMI_REG_VERY_LOW_POWER_AP][i];
535191fa00faSAditya Kumar Singh total_reg_rules += num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i];
535291fa00faSAditya Kumar Singh
535391fa00faSAditya Kumar Singh if ((num_6ghz_client[WMI_REG_INDOOR_AP][i] > MAX_6GHZ_REG_RULES) ||
535491fa00faSAditya Kumar Singh (num_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] >
535591fa00faSAditya Kumar Singh MAX_6GHZ_REG_RULES) ||
535691fa00faSAditya Kumar Singh (num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] >
535791fa00faSAditya Kumar Singh MAX_6GHZ_REG_RULES)) {
535891fa00faSAditya Kumar Singh ath11k_warn(ab,
535991fa00faSAditya Kumar Singh "Num 6 GHz client reg rules exceeds max limit, for client(type: %d)\n",
536091fa00faSAditya Kumar Singh i);
536191fa00faSAditya Kumar Singh kfree(tb);
536291fa00faSAditya Kumar Singh return -EINVAL;
536391fa00faSAditya Kumar Singh }
536491fa00faSAditya Kumar Singh }
536591fa00faSAditya Kumar Singh
536691fa00faSAditya Kumar Singh if (!total_reg_rules) {
536791fa00faSAditya Kumar Singh ath11k_warn(ab, "No reg rules available\n");
536891fa00faSAditya Kumar Singh kfree(tb);
536991fa00faSAditya Kumar Singh return -EINVAL;
537091fa00faSAditya Kumar Singh }
537191fa00faSAditya Kumar Singh
5372e238e62bSAditya Kumar Singh memcpy(reg_info->alpha2, &ev->alpha2, REG_ALPHA2_LEN);
537391fa00faSAditya Kumar Singh
5374e238e62bSAditya Kumar Singh reg_info->dfs_region = ev->dfs_region;
5375e238e62bSAditya Kumar Singh reg_info->phybitmap = ev->phybitmap;
5376e238e62bSAditya Kumar Singh reg_info->num_phy = ev->num_phy;
5377e238e62bSAditya Kumar Singh reg_info->phy_id = ev->phy_id;
5378e238e62bSAditya Kumar Singh reg_info->ctry_code = ev->country_id;
5379e238e62bSAditya Kumar Singh reg_info->reg_dmn_pair = ev->domain_code;
5380e238e62bSAditya Kumar Singh
5381e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5382e238e62bSAditya Kumar Singh "status_code %s",
5383e238e62bSAditya Kumar Singh ath11k_cc_status_to_str(reg_info->status_code));
538491fa00faSAditya Kumar Singh
538591fa00faSAditya Kumar Singh reg_info->status_code =
5386e238e62bSAditya Kumar Singh ath11k_wmi_cc_setting_code_to_reg(ev->status_code);
538791fa00faSAditya Kumar Singh
538891fa00faSAditya Kumar Singh reg_info->is_ext_reg_event = true;
538991fa00faSAditya Kumar Singh
5390e238e62bSAditya Kumar Singh reg_info->min_bw_2ghz = ev->min_bw_2ghz;
5391e238e62bSAditya Kumar Singh reg_info->max_bw_2ghz = ev->max_bw_2ghz;
5392e238e62bSAditya Kumar Singh reg_info->min_bw_5ghz = ev->min_bw_5ghz;
5393e238e62bSAditya Kumar Singh reg_info->max_bw_5ghz = ev->max_bw_5ghz;
539491fa00faSAditya Kumar Singh
539591fa00faSAditya Kumar Singh reg_info->min_bw_6ghz_ap[WMI_REG_INDOOR_AP] =
5396e238e62bSAditya Kumar Singh ev->min_bw_6ghz_ap_lpi;
539791fa00faSAditya Kumar Singh reg_info->max_bw_6ghz_ap[WMI_REG_INDOOR_AP] =
5398e238e62bSAditya Kumar Singh ev->max_bw_6ghz_ap_lpi;
539991fa00faSAditya Kumar Singh reg_info->min_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5400e238e62bSAditya Kumar Singh ev->min_bw_6ghz_ap_sp;
540191fa00faSAditya Kumar Singh reg_info->max_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5402e238e62bSAditya Kumar Singh ev->max_bw_6ghz_ap_sp;
540391fa00faSAditya Kumar Singh reg_info->min_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5404e238e62bSAditya Kumar Singh ev->min_bw_6ghz_ap_vlp;
540591fa00faSAditya Kumar Singh reg_info->max_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5406e238e62bSAditya Kumar Singh ev->max_bw_6ghz_ap_vlp;
5407e238e62bSAditya Kumar Singh
5408e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5409e238e62bSAditya Kumar Singh "6 GHz AP BW: LPI (%d - %d), SP (%d - %d), VLP (%d - %d)\n",
5410e238e62bSAditya Kumar Singh reg_info->min_bw_6ghz_ap[WMI_REG_INDOOR_AP],
5411e238e62bSAditya Kumar Singh reg_info->max_bw_6ghz_ap[WMI_REG_INDOOR_AP],
5412e238e62bSAditya Kumar Singh reg_info->min_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP],
5413e238e62bSAditya Kumar Singh reg_info->max_bw_6ghz_ap[WMI_REG_STANDARD_POWER_AP],
5414e238e62bSAditya Kumar Singh reg_info->min_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP],
5415e238e62bSAditya Kumar Singh reg_info->max_bw_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP]);
541691fa00faSAditya Kumar Singh
541791fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
541891fa00faSAditya Kumar Singh reg_info->min_bw_6ghz_client[WMI_REG_INDOOR_AP][i] =
5419e238e62bSAditya Kumar Singh ev->min_bw_6ghz_client_lpi[i];
542091fa00faSAditya Kumar Singh reg_info->max_bw_6ghz_client[WMI_REG_INDOOR_AP][i] =
5421e238e62bSAditya Kumar Singh ev->max_bw_6ghz_client_lpi[i];
542291fa00faSAditya Kumar Singh reg_info->min_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5423e238e62bSAditya Kumar Singh ev->min_bw_6ghz_client_sp[i];
542491fa00faSAditya Kumar Singh reg_info->max_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5425e238e62bSAditya Kumar Singh ev->max_bw_6ghz_client_sp[i];
542691fa00faSAditya Kumar Singh reg_info->min_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5427e238e62bSAditya Kumar Singh ev->min_bw_6ghz_client_vlp[i];
542891fa00faSAditya Kumar Singh reg_info->max_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5429e238e62bSAditya Kumar Singh ev->max_bw_6ghz_client_vlp[i];
5430e238e62bSAditya Kumar Singh
5431e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5432e238e62bSAditya Kumar Singh "6 GHz %s BW: LPI (%d - %d), SP (%d - %d), VLP (%d - %d)\n",
5433e238e62bSAditya Kumar Singh ath11k_6ghz_client_type_to_str(i),
5434e238e62bSAditya Kumar Singh reg_info->min_bw_6ghz_client[WMI_REG_INDOOR_AP][i],
5435e238e62bSAditya Kumar Singh reg_info->max_bw_6ghz_client[WMI_REG_INDOOR_AP][i],
5436e238e62bSAditya Kumar Singh reg_info->min_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i],
5437e238e62bSAditya Kumar Singh reg_info->max_bw_6ghz_client[WMI_REG_STANDARD_POWER_AP][i],
5438e238e62bSAditya Kumar Singh reg_info->min_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i],
5439e238e62bSAditya Kumar Singh reg_info->max_bw_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i]);
544091fa00faSAditya Kumar Singh }
544191fa00faSAditya Kumar Singh
544291fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5443e238e62bSAditya Kumar Singh "cc_ext %s dsf %d BW: min_2ghz %d max_2ghz %d min_5ghz %d max_5ghz %d",
5444e238e62bSAditya Kumar Singh reg_info->alpha2, reg_info->dfs_region,
544591fa00faSAditya Kumar Singh reg_info->min_bw_2ghz, reg_info->max_bw_2ghz,
544691fa00faSAditya Kumar Singh reg_info->min_bw_5ghz, reg_info->max_bw_5ghz);
544791fa00faSAditya Kumar Singh
544891fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
544991fa00faSAditya Kumar Singh "num_2ghz_reg_rules %d num_5ghz_reg_rules %d",
545091fa00faSAditya Kumar Singh num_2ghz_reg_rules, num_5ghz_reg_rules);
545191fa00faSAditya Kumar Singh
545291fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
545391fa00faSAditya Kumar Singh "num_6ghz_reg_rules_ap_lpi: %d num_6ghz_reg_rules_ap_sp: %d num_6ghz_reg_rules_ap_vlp: %d",
545491fa00faSAditya Kumar Singh num_6ghz_reg_rules_ap[WMI_REG_INDOOR_AP],
545591fa00faSAditya Kumar Singh num_6ghz_reg_rules_ap[WMI_REG_STANDARD_POWER_AP],
545691fa00faSAditya Kumar Singh num_6ghz_reg_rules_ap[WMI_REG_VERY_LOW_POWER_AP]);
545791fa00faSAditya Kumar Singh
545891fa00faSAditya Kumar Singh j = WMI_REG_DEFAULT_CLIENT;
545991fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
546091fa00faSAditya Kumar Singh "6 GHz Regular client: num_6ghz_reg_rules_lpi: %d num_6ghz_reg_rules_sp: %d num_6ghz_reg_rules_vlp: %d",
546191fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_INDOOR_AP][j],
546291fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_STANDARD_POWER_AP][j],
546391fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][j]);
546491fa00faSAditya Kumar Singh
546591fa00faSAditya Kumar Singh j = WMI_REG_SUBORDINATE_CLIENT;
546691fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
546791fa00faSAditya Kumar Singh "6 GHz Subordinate client: num_6ghz_reg_rules_lpi: %d num_6ghz_reg_rules_sp: %d num_6ghz_reg_rules_vlp: %d",
546891fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_INDOOR_AP][j],
546991fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_STANDARD_POWER_AP][j],
547091fa00faSAditya Kumar Singh num_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][j]);
547191fa00faSAditya Kumar Singh
547291fa00faSAditya Kumar Singh ext_wmi_reg_rule =
5473e238e62bSAditya Kumar Singh (struct wmi_regulatory_ext_rule *)((u8 *)ev + sizeof(*ev) +
5474e238e62bSAditya Kumar Singh sizeof(struct wmi_tlv));
547591fa00faSAditya Kumar Singh if (num_2ghz_reg_rules) {
547691fa00faSAditya Kumar Singh reg_info->reg_rules_2ghz_ptr =
547791fa00faSAditya Kumar Singh create_ext_reg_rules_from_wmi(num_2ghz_reg_rules,
547891fa00faSAditya Kumar Singh ext_wmi_reg_rule);
547991fa00faSAditya Kumar Singh
548091fa00faSAditya Kumar Singh if (!reg_info->reg_rules_2ghz_ptr) {
548191fa00faSAditya Kumar Singh kfree(tb);
548291fa00faSAditya Kumar Singh ath11k_warn(ab, "Unable to Allocate memory for 2 GHz rules\n");
548391fa00faSAditya Kumar Singh return -ENOMEM;
548491fa00faSAditya Kumar Singh }
5485e238e62bSAditya Kumar Singh
5486e238e62bSAditya Kumar Singh ath11k_print_reg_rule(ab, "2 GHz",
5487e238e62bSAditya Kumar Singh num_2ghz_reg_rules,
5488e238e62bSAditya Kumar Singh reg_info->reg_rules_2ghz_ptr);
548991fa00faSAditya Kumar Singh }
549091fa00faSAditya Kumar Singh
549191fa00faSAditya Kumar Singh ext_wmi_reg_rule += num_2ghz_reg_rules;
549291fa00faSAditya Kumar Singh
549391fa00faSAditya Kumar Singh /* Firmware might include 6 GHz reg rule in 5 GHz rule list
549491fa00faSAditya Kumar Singh * for few countries along with separate 6 GHz rule.
549591fa00faSAditya Kumar Singh * Having same 6 GHz reg rule in 5 GHz and 6 GHz rules list
549691fa00faSAditya Kumar Singh * causes intersect check to be true, and same rules will be
549791fa00faSAditya Kumar Singh * shown multiple times in iw cmd.
549891fa00faSAditya Kumar Singh * Hence, avoid parsing 6 GHz rule from 5 GHz reg rule list
549991fa00faSAditya Kumar Singh */
550091fa00faSAditya Kumar Singh num_invalid_5ghz_ext_rules =
550191fa00faSAditya Kumar Singh ath11k_invalid_5ghz_reg_ext_rules_from_wmi(num_5ghz_reg_rules,
550291fa00faSAditya Kumar Singh ext_wmi_reg_rule);
550391fa00faSAditya Kumar Singh
550491fa00faSAditya Kumar Singh if (num_invalid_5ghz_ext_rules) {
550591fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
550691fa00faSAditya Kumar Singh "CC: %s 5 GHz reg rules number %d from fw, %d number of invalid 5 GHz rules",
550791fa00faSAditya Kumar Singh reg_info->alpha2, reg_info->num_5ghz_reg_rules,
550891fa00faSAditya Kumar Singh num_invalid_5ghz_ext_rules);
550991fa00faSAditya Kumar Singh
551091fa00faSAditya Kumar Singh num_5ghz_reg_rules = num_5ghz_reg_rules - num_invalid_5ghz_ext_rules;
551191fa00faSAditya Kumar Singh reg_info->num_5ghz_reg_rules = num_5ghz_reg_rules;
551291fa00faSAditya Kumar Singh }
551391fa00faSAditya Kumar Singh
551491fa00faSAditya Kumar Singh if (num_5ghz_reg_rules) {
551591fa00faSAditya Kumar Singh reg_info->reg_rules_5ghz_ptr =
551691fa00faSAditya Kumar Singh create_ext_reg_rules_from_wmi(num_5ghz_reg_rules,
551791fa00faSAditya Kumar Singh ext_wmi_reg_rule);
551891fa00faSAditya Kumar Singh
551991fa00faSAditya Kumar Singh if (!reg_info->reg_rules_5ghz_ptr) {
552091fa00faSAditya Kumar Singh kfree(tb);
552191fa00faSAditya Kumar Singh ath11k_warn(ab, "Unable to Allocate memory for 5 GHz rules\n");
552291fa00faSAditya Kumar Singh return -ENOMEM;
552391fa00faSAditya Kumar Singh }
5524e238e62bSAditya Kumar Singh
5525e238e62bSAditya Kumar Singh ath11k_print_reg_rule(ab, "5 GHz",
5526e238e62bSAditya Kumar Singh num_5ghz_reg_rules,
5527e238e62bSAditya Kumar Singh reg_info->reg_rules_5ghz_ptr);
552891fa00faSAditya Kumar Singh }
552991fa00faSAditya Kumar Singh
553091fa00faSAditya Kumar Singh /* We have adjusted the number of 5 GHz reg rules above. But still those
553191fa00faSAditya Kumar Singh * many rules needs to be adjusted in ext_wmi_reg_rule.
553291fa00faSAditya Kumar Singh *
553391fa00faSAditya Kumar Singh * NOTE: num_invalid_5ghz_ext_rules will be 0 for rest other cases.
553491fa00faSAditya Kumar Singh */
553591fa00faSAditya Kumar Singh ext_wmi_reg_rule += (num_5ghz_reg_rules + num_invalid_5ghz_ext_rules);
553691fa00faSAditya Kumar Singh
553791fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++) {
553891fa00faSAditya Kumar Singh reg_info->reg_rules_6ghz_ap_ptr[i] =
553991fa00faSAditya Kumar Singh create_ext_reg_rules_from_wmi(num_6ghz_reg_rules_ap[i],
554091fa00faSAditya Kumar Singh ext_wmi_reg_rule);
554191fa00faSAditya Kumar Singh
554291fa00faSAditya Kumar Singh if (!reg_info->reg_rules_6ghz_ap_ptr[i]) {
554391fa00faSAditya Kumar Singh kfree(tb);
554491fa00faSAditya Kumar Singh ath11k_warn(ab, "Unable to Allocate memory for 6 GHz AP rules\n");
554591fa00faSAditya Kumar Singh return -ENOMEM;
554691fa00faSAditya Kumar Singh }
554791fa00faSAditya Kumar Singh
5548e238e62bSAditya Kumar Singh ath11k_print_reg_rule(ab, ath11k_6ghz_ap_type_to_str(i),
5549e238e62bSAditya Kumar Singh num_6ghz_reg_rules_ap[i],
5550e238e62bSAditya Kumar Singh reg_info->reg_rules_6ghz_ap_ptr[i]);
5551e238e62bSAditya Kumar Singh
555291fa00faSAditya Kumar Singh ext_wmi_reg_rule += num_6ghz_reg_rules_ap[i];
555391fa00faSAditya Kumar Singh }
555491fa00faSAditya Kumar Singh
555591fa00faSAditya Kumar Singh for (j = 0; j < WMI_REG_CURRENT_MAX_AP_TYPE; j++) {
5556e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5557e238e62bSAditya Kumar Singh "6 GHz AP type %s", ath11k_6ghz_ap_type_to_str(j));
5558e238e62bSAditya Kumar Singh
555991fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
556091fa00faSAditya Kumar Singh reg_info->reg_rules_6ghz_client_ptr[j][i] =
556191fa00faSAditya Kumar Singh create_ext_reg_rules_from_wmi(num_6ghz_client[j][i],
556291fa00faSAditya Kumar Singh ext_wmi_reg_rule);
556391fa00faSAditya Kumar Singh
556491fa00faSAditya Kumar Singh if (!reg_info->reg_rules_6ghz_client_ptr[j][i]) {
556591fa00faSAditya Kumar Singh kfree(tb);
556691fa00faSAditya Kumar Singh ath11k_warn(ab, "Unable to Allocate memory for 6 GHz client rules\n");
556791fa00faSAditya Kumar Singh return -ENOMEM;
556891fa00faSAditya Kumar Singh }
556991fa00faSAditya Kumar Singh
5570e238e62bSAditya Kumar Singh ath11k_print_reg_rule(ab,
5571e238e62bSAditya Kumar Singh ath11k_6ghz_client_type_to_str(i),
5572e238e62bSAditya Kumar Singh num_6ghz_client[j][i],
5573e238e62bSAditya Kumar Singh reg_info->reg_rules_6ghz_client_ptr[j][i]);
5574e238e62bSAditya Kumar Singh
557591fa00faSAditya Kumar Singh ext_wmi_reg_rule += num_6ghz_client[j][i];
557691fa00faSAditya Kumar Singh }
557791fa00faSAditya Kumar Singh }
557891fa00faSAditya Kumar Singh
5579e238e62bSAditya Kumar Singh reg_info->client_type = ev->client_type;
5580e238e62bSAditya Kumar Singh reg_info->rnr_tpe_usable = ev->rnr_tpe_usable;
558191fa00faSAditya Kumar Singh reg_info->unspecified_ap_usable =
5582e238e62bSAditya Kumar Singh ev->unspecified_ap_usable;
558391fa00faSAditya Kumar Singh reg_info->domain_code_6ghz_ap[WMI_REG_INDOOR_AP] =
5584e238e62bSAditya Kumar Singh ev->domain_code_6ghz_ap_lpi;
558591fa00faSAditya Kumar Singh reg_info->domain_code_6ghz_ap[WMI_REG_STANDARD_POWER_AP] =
5586e238e62bSAditya Kumar Singh ev->domain_code_6ghz_ap_sp;
558791fa00faSAditya Kumar Singh reg_info->domain_code_6ghz_ap[WMI_REG_VERY_LOW_POWER_AP] =
5588e238e62bSAditya Kumar Singh ev->domain_code_6ghz_ap_vlp;
5589e238e62bSAditya Kumar Singh
5590e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5591e238e62bSAditya Kumar Singh "6 GHz reg info client type %s rnr_tpe_usable %d unspecified_ap_usable %d AP sub domain: lpi %s, sp %s, vlp %s\n",
5592e238e62bSAditya Kumar Singh ath11k_6ghz_client_type_to_str(reg_info->client_type),
5593e238e62bSAditya Kumar Singh reg_info->rnr_tpe_usable,
5594e238e62bSAditya Kumar Singh reg_info->unspecified_ap_usable,
5595e238e62bSAditya Kumar Singh ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_lpi),
5596e238e62bSAditya Kumar Singh ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_sp),
5597e238e62bSAditya Kumar Singh ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_ap_vlp));
559891fa00faSAditya Kumar Singh
559991fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++) {
560091fa00faSAditya Kumar Singh reg_info->domain_code_6ghz_client[WMI_REG_INDOOR_AP][i] =
5601e238e62bSAditya Kumar Singh ev->domain_code_6ghz_client_lpi[i];
560291fa00faSAditya Kumar Singh reg_info->domain_code_6ghz_client[WMI_REG_STANDARD_POWER_AP][i] =
5603e238e62bSAditya Kumar Singh ev->domain_code_6ghz_client_sp[i];
560491fa00faSAditya Kumar Singh reg_info->domain_code_6ghz_client[WMI_REG_VERY_LOW_POWER_AP][i] =
5605e238e62bSAditya Kumar Singh ev->domain_code_6ghz_client_vlp[i];
5606e238e62bSAditya Kumar Singh
5607e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5608e238e62bSAditya Kumar Singh "6 GHz client type %s client sub domain: lpi %s, sp %s, vlp %s\n",
5609e238e62bSAditya Kumar Singh ath11k_6ghz_client_type_to_str(i),
5610e238e62bSAditya Kumar Singh ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_lpi[i]),
5611e238e62bSAditya Kumar Singh ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_sp[i]),
5612e238e62bSAditya Kumar Singh ath11k_sub_reg_6ghz_to_str(ev->domain_code_6ghz_client_vlp[i])
5613e238e62bSAditya Kumar Singh );
561491fa00faSAditya Kumar Singh }
561591fa00faSAditya Kumar Singh
5616e238e62bSAditya Kumar Singh reg_info->domain_code_6ghz_super_id = ev->domain_code_6ghz_super_id;
561791fa00faSAditya Kumar Singh
5618e238e62bSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI,
5619e238e62bSAditya Kumar Singh "6 GHz client_type %s 6 GHz super domain %s",
5620e238e62bSAditya Kumar Singh ath11k_6ghz_client_type_to_str(reg_info->client_type),
5621e238e62bSAditya Kumar Singh ath11k_super_reg_6ghz_to_str(reg_info->domain_code_6ghz_super_id));
562291fa00faSAditya Kumar Singh
562391fa00faSAditya Kumar Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory ext channel list\n");
562491fa00faSAditya Kumar Singh
562591fa00faSAditya Kumar Singh kfree(tb);
562691fa00faSAditya Kumar Singh return 0;
562791fa00faSAditya Kumar Singh }
562891fa00faSAditya Kumar Singh
ath11k_pull_peer_del_resp_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_peer_delete_resp_event * peer_del_resp)5629d5c65159SKalle Valo static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
5630d5c65159SKalle Valo struct wmi_peer_delete_resp_event *peer_del_resp)
5631d5c65159SKalle Valo {
5632d5c65159SKalle Valo const void **tb;
5633d5c65159SKalle Valo const struct wmi_peer_delete_resp_event *ev;
5634d5c65159SKalle Valo int ret;
5635d5c65159SKalle Valo
5636d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5637d5c65159SKalle Valo if (IS_ERR(tb)) {
5638d5c65159SKalle Valo ret = PTR_ERR(tb);
5639d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5640d5c65159SKalle Valo return ret;
5641d5c65159SKalle Valo }
5642d5c65159SKalle Valo
5643d5c65159SKalle Valo ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
5644d5c65159SKalle Valo if (!ev) {
5645d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch peer delete resp ev");
5646d5c65159SKalle Valo kfree(tb);
5647d5c65159SKalle Valo return -EPROTO;
5648d5c65159SKalle Valo }
5649d5c65159SKalle Valo
5650d5c65159SKalle Valo memset(peer_del_resp, 0, sizeof(*peer_del_resp));
5651d5c65159SKalle Valo
5652d5c65159SKalle Valo peer_del_resp->vdev_id = ev->vdev_id;
5653d5c65159SKalle Valo ether_addr_copy(peer_del_resp->peer_macaddr.addr,
5654d5c65159SKalle Valo ev->peer_macaddr.addr);
5655d5c65159SKalle Valo
5656d5c65159SKalle Valo kfree(tb);
5657d5c65159SKalle Valo return 0;
5658d5c65159SKalle Valo }
5659d5c65159SKalle Valo
ath11k_pull_vdev_del_resp_ev(struct ath11k_base * ab,struct sk_buff * skb,u32 * vdev_id)56603cbbdfbeSRitesh Singh static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab,
56613cbbdfbeSRitesh Singh struct sk_buff *skb,
56623cbbdfbeSRitesh Singh u32 *vdev_id)
56633cbbdfbeSRitesh Singh {
56643cbbdfbeSRitesh Singh const void **tb;
56653cbbdfbeSRitesh Singh const struct wmi_vdev_delete_resp_event *ev;
56663cbbdfbeSRitesh Singh int ret;
56673cbbdfbeSRitesh Singh
56683cbbdfbeSRitesh Singh tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
56693cbbdfbeSRitesh Singh if (IS_ERR(tb)) {
56703cbbdfbeSRitesh Singh ret = PTR_ERR(tb);
56713cbbdfbeSRitesh Singh ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
56723cbbdfbeSRitesh Singh return ret;
56733cbbdfbeSRitesh Singh }
56743cbbdfbeSRitesh Singh
56753cbbdfbeSRitesh Singh ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT];
56763cbbdfbeSRitesh Singh if (!ev) {
56773cbbdfbeSRitesh Singh ath11k_warn(ab, "failed to fetch vdev delete resp ev");
56783cbbdfbeSRitesh Singh kfree(tb);
56793cbbdfbeSRitesh Singh return -EPROTO;
56803cbbdfbeSRitesh Singh }
56813cbbdfbeSRitesh Singh
56823cbbdfbeSRitesh Singh *vdev_id = ev->vdev_id;
56833cbbdfbeSRitesh Singh
56843cbbdfbeSRitesh Singh kfree(tb);
56853cbbdfbeSRitesh Singh return 0;
56863cbbdfbeSRitesh Singh }
56873cbbdfbeSRitesh Singh
ath11k_pull_bcn_tx_status_ev(struct ath11k_base * ab,void * evt_buf,u32 len,u32 * vdev_id,u32 * tx_status)5688d5c65159SKalle Valo static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
5689d5c65159SKalle Valo u32 len, u32 *vdev_id,
5690d5c65159SKalle Valo u32 *tx_status)
5691d5c65159SKalle Valo {
5692d5c65159SKalle Valo const void **tb;
5693d5c65159SKalle Valo const struct wmi_bcn_tx_status_event *ev;
5694d5c65159SKalle Valo int ret;
5695d5c65159SKalle Valo
5696d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5697d5c65159SKalle Valo if (IS_ERR(tb)) {
5698d5c65159SKalle Valo ret = PTR_ERR(tb);
5699d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5700d5c65159SKalle Valo return ret;
5701d5c65159SKalle Valo }
5702d5c65159SKalle Valo
5703d5c65159SKalle Valo ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
5704d5c65159SKalle Valo if (!ev) {
5705d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch bcn tx status ev");
5706d5c65159SKalle Valo kfree(tb);
5707d5c65159SKalle Valo return -EPROTO;
5708d5c65159SKalle Valo }
5709d5c65159SKalle Valo
5710d5c65159SKalle Valo *vdev_id = ev->vdev_id;
5711d5c65159SKalle Valo *tx_status = ev->tx_status;
5712d5c65159SKalle Valo
5713d5c65159SKalle Valo kfree(tb);
5714d5c65159SKalle Valo return 0;
5715d5c65159SKalle Valo }
5716d5c65159SKalle Valo
ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base * ab,struct sk_buff * skb,u32 * vdev_id)5717d5c65159SKalle Valo static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5718d5c65159SKalle Valo u32 *vdev_id)
5719d5c65159SKalle Valo {
5720d5c65159SKalle Valo const void **tb;
5721d5c65159SKalle Valo const struct wmi_vdev_stopped_event *ev;
5722d5c65159SKalle Valo int ret;
5723d5c65159SKalle Valo
5724d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5725d5c65159SKalle Valo if (IS_ERR(tb)) {
5726d5c65159SKalle Valo ret = PTR_ERR(tb);
5727d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5728d5c65159SKalle Valo return ret;
5729d5c65159SKalle Valo }
5730d5c65159SKalle Valo
5731d5c65159SKalle Valo ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
5732d5c65159SKalle Valo if (!ev) {
5733d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch vdev stop ev");
5734d5c65159SKalle Valo kfree(tb);
5735d5c65159SKalle Valo return -EPROTO;
5736d5c65159SKalle Valo }
5737d5c65159SKalle Valo
5738d5c65159SKalle Valo *vdev_id = ev->vdev_id;
5739d5c65159SKalle Valo
5740d5c65159SKalle Valo kfree(tb);
5741d5c65159SKalle Valo return 0;
5742d5c65159SKalle Valo }
5743d5c65159SKalle Valo
ath11k_wmi_tlv_mgmt_rx_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)5744447b0398SBhagavathi Perumal S static int ath11k_wmi_tlv_mgmt_rx_parse(struct ath11k_base *ab,
5745447b0398SBhagavathi Perumal S u16 tag, u16 len,
5746447b0398SBhagavathi Perumal S const void *ptr, void *data)
5747447b0398SBhagavathi Perumal S {
5748447b0398SBhagavathi Perumal S struct wmi_tlv_mgmt_rx_parse *parse = data;
5749447b0398SBhagavathi Perumal S
5750447b0398SBhagavathi Perumal S switch (tag) {
5751447b0398SBhagavathi Perumal S case WMI_TAG_MGMT_RX_HDR:
5752447b0398SBhagavathi Perumal S parse->fixed = ptr;
5753447b0398SBhagavathi Perumal S break;
5754447b0398SBhagavathi Perumal S case WMI_TAG_ARRAY_BYTE:
5755447b0398SBhagavathi Perumal S if (!parse->frame_buf_done) {
5756447b0398SBhagavathi Perumal S parse->frame_buf = ptr;
5757447b0398SBhagavathi Perumal S parse->frame_buf_done = true;
5758447b0398SBhagavathi Perumal S }
5759447b0398SBhagavathi Perumal S break;
5760447b0398SBhagavathi Perumal S }
5761447b0398SBhagavathi Perumal S return 0;
5762447b0398SBhagavathi Perumal S }
5763447b0398SBhagavathi Perumal S
ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base * ab,struct sk_buff * skb,struct mgmt_rx_event_params * hdr)5764d5c65159SKalle Valo static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
5765d5c65159SKalle Valo struct sk_buff *skb,
5766d5c65159SKalle Valo struct mgmt_rx_event_params *hdr)
5767d5c65159SKalle Valo {
5768447b0398SBhagavathi Perumal S struct wmi_tlv_mgmt_rx_parse parse = { };
5769d5c65159SKalle Valo const struct wmi_mgmt_rx_hdr *ev;
5770d5c65159SKalle Valo const u8 *frame;
5771d5c65159SKalle Valo int ret;
5772d5c65159SKalle Valo
5773447b0398SBhagavathi Perumal S ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
5774447b0398SBhagavathi Perumal S ath11k_wmi_tlv_mgmt_rx_parse,
5775447b0398SBhagavathi Perumal S &parse);
5776447b0398SBhagavathi Perumal S if (ret) {
5777447b0398SBhagavathi Perumal S ath11k_warn(ab, "failed to parse mgmt rx tlv %d\n",
5778447b0398SBhagavathi Perumal S ret);
5779d5c65159SKalle Valo return ret;
5780d5c65159SKalle Valo }
5781d5c65159SKalle Valo
5782447b0398SBhagavathi Perumal S ev = parse.fixed;
5783447b0398SBhagavathi Perumal S frame = parse.frame_buf;
5784d5c65159SKalle Valo
5785d5c65159SKalle Valo if (!ev || !frame) {
5786d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch mgmt rx hdr");
5787d5c65159SKalle Valo return -EPROTO;
5788d5c65159SKalle Valo }
5789d5c65159SKalle Valo
5790d5c65159SKalle Valo hdr->pdev_id = ev->pdev_id;
57915dcf42f8SPradeep Kumar Chitrapu hdr->chan_freq = ev->chan_freq;
5792d5c65159SKalle Valo hdr->channel = ev->channel;
5793d5c65159SKalle Valo hdr->snr = ev->snr;
5794d5c65159SKalle Valo hdr->rate = ev->rate;
5795d5c65159SKalle Valo hdr->phy_mode = ev->phy_mode;
5796d5c65159SKalle Valo hdr->buf_len = ev->buf_len;
5797d5c65159SKalle Valo hdr->status = ev->status;
5798d5c65159SKalle Valo hdr->flags = ev->flags;
5799d5c65159SKalle Valo hdr->rssi = ev->rssi;
5800d5c65159SKalle Valo hdr->tsf_delta = ev->tsf_delta;
5801d5c65159SKalle Valo memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
5802d5c65159SKalle Valo
5803d5c65159SKalle Valo if (skb->len < (frame - skb->data) + hdr->buf_len) {
5804d5c65159SKalle Valo ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
5805d5c65159SKalle Valo return -EPROTO;
5806d5c65159SKalle Valo }
5807d5c65159SKalle Valo
5808d5c65159SKalle Valo /* shift the sk_buff to point to `frame` */
5809d5c65159SKalle Valo skb_trim(skb, 0);
5810d5c65159SKalle Valo skb_put(skb, frame - skb->data);
5811d5c65159SKalle Valo skb_pull(skb, frame - skb->data);
5812d5c65159SKalle Valo skb_put(skb, hdr->buf_len);
5813d5c65159SKalle Valo
5814d5c65159SKalle Valo ath11k_ce_byte_swap(skb->data, hdr->buf_len);
5815d5c65159SKalle Valo
5816d5c65159SKalle Valo return 0;
5817d5c65159SKalle Valo }
5818d5c65159SKalle Valo
wmi_process_mgmt_tx_comp(struct ath11k * ar,struct wmi_mgmt_tx_compl_event * tx_compl_param)581901c6c9fcSAbinaya Kalaiselvan static int wmi_process_mgmt_tx_comp(struct ath11k *ar,
582001c6c9fcSAbinaya Kalaiselvan struct wmi_mgmt_tx_compl_event *tx_compl_param)
5821d5c65159SKalle Valo {
5822d5c65159SKalle Valo struct sk_buff *msdu;
5823d5c65159SKalle Valo struct ieee80211_tx_info *info;
5824d5c65159SKalle Valo struct ath11k_skb_cb *skb_cb;
5825dddaa64dSWen Gong int num_mgmt;
5826d5c65159SKalle Valo
5827d5c65159SKalle Valo spin_lock_bh(&ar->txmgmt_idr_lock);
582801c6c9fcSAbinaya Kalaiselvan msdu = idr_find(&ar->txmgmt_idr, tx_compl_param->desc_id);
5829d5c65159SKalle Valo
5830d5c65159SKalle Valo if (!msdu) {
5831d5c65159SKalle Valo ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
583201c6c9fcSAbinaya Kalaiselvan tx_compl_param->desc_id);
5833d5c65159SKalle Valo spin_unlock_bh(&ar->txmgmt_idr_lock);
5834d5c65159SKalle Valo return -ENOENT;
5835d5c65159SKalle Valo }
5836d5c65159SKalle Valo
583701c6c9fcSAbinaya Kalaiselvan idr_remove(&ar->txmgmt_idr, tx_compl_param->desc_id);
5838d5c65159SKalle Valo spin_unlock_bh(&ar->txmgmt_idr_lock);
5839d5c65159SKalle Valo
5840d5c65159SKalle Valo skb_cb = ATH11K_SKB_CB(msdu);
5841d5c65159SKalle Valo dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
5842d5c65159SKalle Valo
5843d5c65159SKalle Valo info = IEEE80211_SKB_CB(msdu);
584401c6c9fcSAbinaya Kalaiselvan if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) &&
584501c6c9fcSAbinaya Kalaiselvan !tx_compl_param->status) {
5846d5c65159SKalle Valo info->flags |= IEEE80211_TX_STAT_ACK;
584701c6c9fcSAbinaya Kalaiselvan if (test_bit(WMI_TLV_SERVICE_TX_DATA_MGMT_ACK_RSSI,
584801c6c9fcSAbinaya Kalaiselvan ar->ab->wmi_ab.svc_map))
584901c6c9fcSAbinaya Kalaiselvan info->status.ack_signal = tx_compl_param->ack_rssi;
585001c6c9fcSAbinaya Kalaiselvan }
5851d5c65159SKalle Valo
5852d5c65159SKalle Valo ieee80211_tx_status_irqsafe(ar->hw, msdu);
5853d5c65159SKalle Valo
5854dddaa64dSWen Gong num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5855dddaa64dSWen Gong
5856800113ffSSriram R /* WARN when we received this event without doing any mgmt tx */
5857dddaa64dSWen Gong if (num_mgmt < 0)
5858800113ffSSriram R WARN_ON_ONCE(1);
5859d5c65159SKalle Valo
5860dddaa64dSWen Gong ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5861fc3b984aSKalle Valo "mgmt tx comp pending %d desc id %d\n",
586201c6c9fcSAbinaya Kalaiselvan num_mgmt, tx_compl_param->desc_id);
5863dddaa64dSWen Gong
5864dddaa64dSWen Gong if (!num_mgmt)
5865dddaa64dSWen Gong wake_up(&ar->txmgmt_empty_waitq);
5866dddaa64dSWen Gong
5867d5c65159SKalle Valo return 0;
5868d5c65159SKalle Valo }
5869d5c65159SKalle Valo
ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_mgmt_tx_compl_event * param)5870d5c65159SKalle Valo static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
5871d5c65159SKalle Valo struct sk_buff *skb,
5872d5c65159SKalle Valo struct wmi_mgmt_tx_compl_event *param)
5873d5c65159SKalle Valo {
5874d5c65159SKalle Valo const void **tb;
5875d5c65159SKalle Valo const struct wmi_mgmt_tx_compl_event *ev;
5876d5c65159SKalle Valo int ret;
5877d5c65159SKalle Valo
5878d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5879d5c65159SKalle Valo if (IS_ERR(tb)) {
5880d5c65159SKalle Valo ret = PTR_ERR(tb);
5881d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5882d5c65159SKalle Valo return ret;
5883d5c65159SKalle Valo }
5884d5c65159SKalle Valo
5885d5c65159SKalle Valo ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
5886d5c65159SKalle Valo if (!ev) {
5887d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
5888d5c65159SKalle Valo kfree(tb);
5889d5c65159SKalle Valo return -EPROTO;
5890d5c65159SKalle Valo }
5891d5c65159SKalle Valo
5892d5c65159SKalle Valo param->pdev_id = ev->pdev_id;
5893d5c65159SKalle Valo param->desc_id = ev->desc_id;
5894d5c65159SKalle Valo param->status = ev->status;
589501c6c9fcSAbinaya Kalaiselvan param->ack_rssi = ev->ack_rssi;
5896d5c65159SKalle Valo
5897d5c65159SKalle Valo kfree(tb);
5898d5c65159SKalle Valo return 0;
5899d5c65159SKalle Valo }
5900d5c65159SKalle Valo
ath11k_wmi_event_scan_started(struct ath11k * ar)5901d5c65159SKalle Valo static void ath11k_wmi_event_scan_started(struct ath11k *ar)
5902d5c65159SKalle Valo {
5903d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock);
5904d5c65159SKalle Valo
5905d5c65159SKalle Valo switch (ar->scan.state) {
5906d5c65159SKalle Valo case ATH11K_SCAN_IDLE:
5907d5c65159SKalle Valo case ATH11K_SCAN_RUNNING:
5908d5c65159SKalle Valo case ATH11K_SCAN_ABORTING:
5909d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
5910d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state),
5911d5c65159SKalle Valo ar->scan.state);
5912d5c65159SKalle Valo break;
5913d5c65159SKalle Valo case ATH11K_SCAN_STARTING:
5914d5c65159SKalle Valo ar->scan.state = ATH11K_SCAN_RUNNING;
59153a5627b9SBaochen Qiang if (ar->scan.is_roc)
59163a5627b9SBaochen Qiang ieee80211_ready_on_channel(ar->hw);
5917d5c65159SKalle Valo complete(&ar->scan.started);
5918d5c65159SKalle Valo break;
5919d5c65159SKalle Valo }
5920d5c65159SKalle Valo }
5921d5c65159SKalle Valo
ath11k_wmi_event_scan_start_failed(struct ath11k * ar)5922d5c65159SKalle Valo static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
5923d5c65159SKalle Valo {
5924d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock);
5925d5c65159SKalle Valo
5926d5c65159SKalle Valo switch (ar->scan.state) {
5927d5c65159SKalle Valo case ATH11K_SCAN_IDLE:
5928d5c65159SKalle Valo case ATH11K_SCAN_RUNNING:
5929d5c65159SKalle Valo case ATH11K_SCAN_ABORTING:
5930d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
5931d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state),
5932d5c65159SKalle Valo ar->scan.state);
5933d5c65159SKalle Valo break;
5934d5c65159SKalle Valo case ATH11K_SCAN_STARTING:
5935d5c65159SKalle Valo complete(&ar->scan.started);
5936d5c65159SKalle Valo __ath11k_mac_scan_finish(ar);
5937d5c65159SKalle Valo break;
5938d5c65159SKalle Valo }
5939d5c65159SKalle Valo }
5940d5c65159SKalle Valo
ath11k_wmi_event_scan_completed(struct ath11k * ar)5941d5c65159SKalle Valo static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
5942d5c65159SKalle Valo {
5943d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock);
5944d5c65159SKalle Valo
5945d5c65159SKalle Valo switch (ar->scan.state) {
5946d5c65159SKalle Valo case ATH11K_SCAN_IDLE:
5947d5c65159SKalle Valo case ATH11K_SCAN_STARTING:
5948d5c65159SKalle Valo /* One suspected reason scan can be completed while starting is
5949d5c65159SKalle Valo * if firmware fails to deliver all scan events to the host,
5950d5c65159SKalle Valo * e.g. when transport pipe is full. This has been observed
5951d5c65159SKalle Valo * with spectral scan phyerr events starving wmi transport
5952d5c65159SKalle Valo * pipe. In such case the "scan completed" event should be (and
5953d5c65159SKalle Valo * is) ignored by the host as it may be just firmware's scan
5954d5c65159SKalle Valo * state machine recovering.
5955d5c65159SKalle Valo */
5956d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
5957d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state),
5958d5c65159SKalle Valo ar->scan.state);
5959d5c65159SKalle Valo break;
5960d5c65159SKalle Valo case ATH11K_SCAN_RUNNING:
5961d5c65159SKalle Valo case ATH11K_SCAN_ABORTING:
5962d5c65159SKalle Valo __ath11k_mac_scan_finish(ar);
5963d5c65159SKalle Valo break;
5964d5c65159SKalle Valo }
5965d5c65159SKalle Valo }
5966d5c65159SKalle Valo
ath11k_wmi_event_scan_bss_chan(struct ath11k * ar)5967d5c65159SKalle Valo static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
5968d5c65159SKalle Valo {
5969d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock);
5970d5c65159SKalle Valo
5971d5c65159SKalle Valo switch (ar->scan.state) {
5972d5c65159SKalle Valo case ATH11K_SCAN_IDLE:
5973d5c65159SKalle Valo case ATH11K_SCAN_STARTING:
5974d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
5975d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state),
5976d5c65159SKalle Valo ar->scan.state);
5977d5c65159SKalle Valo break;
5978d5c65159SKalle Valo case ATH11K_SCAN_RUNNING:
5979d5c65159SKalle Valo case ATH11K_SCAN_ABORTING:
5980d5c65159SKalle Valo ar->scan_channel = NULL;
5981d5c65159SKalle Valo break;
5982d5c65159SKalle Valo }
5983d5c65159SKalle Valo }
5984d5c65159SKalle Valo
ath11k_wmi_event_scan_foreign_chan(struct ath11k * ar,u32 freq)5985d5c65159SKalle Valo static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
5986d5c65159SKalle Valo {
5987d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock);
5988d5c65159SKalle Valo
5989d5c65159SKalle Valo switch (ar->scan.state) {
5990d5c65159SKalle Valo case ATH11K_SCAN_IDLE:
5991d5c65159SKalle Valo case ATH11K_SCAN_STARTING:
5992d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
5993d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state),
5994d5c65159SKalle Valo ar->scan.state);
5995d5c65159SKalle Valo break;
5996d5c65159SKalle Valo case ATH11K_SCAN_RUNNING:
5997d5c65159SKalle Valo case ATH11K_SCAN_ABORTING:
5998d5c65159SKalle Valo ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
59993a5627b9SBaochen Qiang if (ar->scan.is_roc && ar->scan.roc_freq == freq)
60003a5627b9SBaochen Qiang complete(&ar->scan.on_channel);
6001d5c65159SKalle Valo break;
6002d5c65159SKalle Valo }
6003d5c65159SKalle Valo }
6004d5c65159SKalle Valo
6005d5c65159SKalle Valo static const char *
ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,enum wmi_scan_completion_reason reason)6006d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
6007d5c65159SKalle Valo enum wmi_scan_completion_reason reason)
6008d5c65159SKalle Valo {
6009d5c65159SKalle Valo switch (type) {
6010d5c65159SKalle Valo case WMI_SCAN_EVENT_STARTED:
6011d5c65159SKalle Valo return "started";
6012d5c65159SKalle Valo case WMI_SCAN_EVENT_COMPLETED:
6013d5c65159SKalle Valo switch (reason) {
6014d5c65159SKalle Valo case WMI_SCAN_REASON_COMPLETED:
6015d5c65159SKalle Valo return "completed";
6016d5c65159SKalle Valo case WMI_SCAN_REASON_CANCELLED:
6017d5c65159SKalle Valo return "completed [cancelled]";
6018d5c65159SKalle Valo case WMI_SCAN_REASON_PREEMPTED:
6019d5c65159SKalle Valo return "completed [preempted]";
6020d5c65159SKalle Valo case WMI_SCAN_REASON_TIMEDOUT:
6021d5c65159SKalle Valo return "completed [timedout]";
6022d5c65159SKalle Valo case WMI_SCAN_REASON_INTERNAL_FAILURE:
6023d5c65159SKalle Valo return "completed [internal err]";
6024d5c65159SKalle Valo case WMI_SCAN_REASON_MAX:
6025d5c65159SKalle Valo break;
6026d5c65159SKalle Valo }
6027d5c65159SKalle Valo return "completed [unknown]";
6028d5c65159SKalle Valo case WMI_SCAN_EVENT_BSS_CHANNEL:
6029d5c65159SKalle Valo return "bss channel";
6030d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN:
6031d5c65159SKalle Valo return "foreign channel";
6032d5c65159SKalle Valo case WMI_SCAN_EVENT_DEQUEUED:
6033d5c65159SKalle Valo return "dequeued";
6034d5c65159SKalle Valo case WMI_SCAN_EVENT_PREEMPTED:
6035d5c65159SKalle Valo return "preempted";
6036d5c65159SKalle Valo case WMI_SCAN_EVENT_START_FAILED:
6037d5c65159SKalle Valo return "start failed";
6038d5c65159SKalle Valo case WMI_SCAN_EVENT_RESTARTED:
6039d5c65159SKalle Valo return "restarted";
6040d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
6041d5c65159SKalle Valo return "foreign channel exit";
6042d5c65159SKalle Valo default:
6043d5c65159SKalle Valo return "unknown";
6044d5c65159SKalle Valo }
6045d5c65159SKalle Valo }
6046d5c65159SKalle Valo
ath11k_pull_scan_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_scan_event * scan_evt_param)6047d5c65159SKalle Valo static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
6048d5c65159SKalle Valo struct wmi_scan_event *scan_evt_param)
6049d5c65159SKalle Valo {
6050d5c65159SKalle Valo const void **tb;
6051d5c65159SKalle Valo const struct wmi_scan_event *ev;
6052d5c65159SKalle Valo int ret;
6053d5c65159SKalle Valo
6054d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6055d5c65159SKalle Valo if (IS_ERR(tb)) {
6056d5c65159SKalle Valo ret = PTR_ERR(tb);
6057d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6058d5c65159SKalle Valo return ret;
6059d5c65159SKalle Valo }
6060d5c65159SKalle Valo
6061d5c65159SKalle Valo ev = tb[WMI_TAG_SCAN_EVENT];
6062d5c65159SKalle Valo if (!ev) {
6063d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch scan ev");
6064d5c65159SKalle Valo kfree(tb);
6065d5c65159SKalle Valo return -EPROTO;
6066d5c65159SKalle Valo }
6067d5c65159SKalle Valo
6068d5c65159SKalle Valo scan_evt_param->event_type = ev->event_type;
6069d5c65159SKalle Valo scan_evt_param->reason = ev->reason;
6070d5c65159SKalle Valo scan_evt_param->channel_freq = ev->channel_freq;
6071d5c65159SKalle Valo scan_evt_param->scan_req_id = ev->scan_req_id;
6072d5c65159SKalle Valo scan_evt_param->scan_id = ev->scan_id;
6073d5c65159SKalle Valo scan_evt_param->vdev_id = ev->vdev_id;
6074d5c65159SKalle Valo scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
6075d5c65159SKalle Valo
6076d5c65159SKalle Valo kfree(tb);
6077d5c65159SKalle Valo return 0;
6078d5c65159SKalle Valo }
6079d5c65159SKalle Valo
ath11k_pull_peer_sta_kickout_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_peer_sta_kickout_arg * arg)6080d5c65159SKalle Valo static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
6081d5c65159SKalle Valo struct wmi_peer_sta_kickout_arg *arg)
6082d5c65159SKalle Valo {
6083d5c65159SKalle Valo const void **tb;
6084d5c65159SKalle Valo const struct wmi_peer_sta_kickout_event *ev;
6085d5c65159SKalle Valo int ret;
6086d5c65159SKalle Valo
6087d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6088d5c65159SKalle Valo if (IS_ERR(tb)) {
6089d5c65159SKalle Valo ret = PTR_ERR(tb);
6090d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6091d5c65159SKalle Valo return ret;
6092d5c65159SKalle Valo }
6093d5c65159SKalle Valo
6094d5c65159SKalle Valo ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
6095d5c65159SKalle Valo if (!ev) {
6096d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch peer sta kickout ev");
6097d5c65159SKalle Valo kfree(tb);
6098d5c65159SKalle Valo return -EPROTO;
6099d5c65159SKalle Valo }
6100d5c65159SKalle Valo
6101d5c65159SKalle Valo arg->mac_addr = ev->peer_macaddr.addr;
6102d5c65159SKalle Valo
6103d5c65159SKalle Valo kfree(tb);
6104d5c65159SKalle Valo return 0;
6105d5c65159SKalle Valo }
6106d5c65159SKalle Valo
ath11k_pull_roam_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_roam_event * roam_ev)6107d5c65159SKalle Valo static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
6108d5c65159SKalle Valo struct wmi_roam_event *roam_ev)
6109d5c65159SKalle Valo {
6110d5c65159SKalle Valo const void **tb;
6111d5c65159SKalle Valo const struct wmi_roam_event *ev;
6112d5c65159SKalle Valo int ret;
6113d5c65159SKalle Valo
6114d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6115d5c65159SKalle Valo if (IS_ERR(tb)) {
6116d5c65159SKalle Valo ret = PTR_ERR(tb);
6117d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6118d5c65159SKalle Valo return ret;
6119d5c65159SKalle Valo }
6120d5c65159SKalle Valo
6121d5c65159SKalle Valo ev = tb[WMI_TAG_ROAM_EVENT];
6122d5c65159SKalle Valo if (!ev) {
6123d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch roam ev");
6124d5c65159SKalle Valo kfree(tb);
6125d5c65159SKalle Valo return -EPROTO;
6126d5c65159SKalle Valo }
6127d5c65159SKalle Valo
6128d5c65159SKalle Valo roam_ev->vdev_id = ev->vdev_id;
6129d5c65159SKalle Valo roam_ev->reason = ev->reason;
6130d5c65159SKalle Valo roam_ev->rssi = ev->rssi;
6131d5c65159SKalle Valo
6132d5c65159SKalle Valo kfree(tb);
6133d5c65159SKalle Valo return 0;
6134d5c65159SKalle Valo }
6135d5c65159SKalle Valo
freq_to_idx(struct ath11k * ar,int freq)6136d5c65159SKalle Valo static int freq_to_idx(struct ath11k *ar, int freq)
6137d5c65159SKalle Valo {
6138d5c65159SKalle Valo struct ieee80211_supported_band *sband;
6139d5c65159SKalle Valo int band, ch, idx = 0;
6140d5c65159SKalle Valo
6141d5c65159SKalle Valo for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
6142d5c65159SKalle Valo sband = ar->hw->wiphy->bands[band];
6143d5c65159SKalle Valo if (!sband)
6144d5c65159SKalle Valo continue;
6145d5c65159SKalle Valo
6146d5c65159SKalle Valo for (ch = 0; ch < sband->n_channels; ch++, idx++)
6147d5c65159SKalle Valo if (sband->channels[ch].center_freq == freq)
6148d5c65159SKalle Valo goto exit;
6149d5c65159SKalle Valo }
6150d5c65159SKalle Valo
6151d5c65159SKalle Valo exit:
6152d5c65159SKalle Valo return idx;
6153d5c65159SKalle Valo }
6154d5c65159SKalle Valo
ath11k_pull_chan_info_ev(struct ath11k_base * ab,u8 * evt_buf,u32 len,struct wmi_chan_info_event * ch_info_ev)6155d5c65159SKalle Valo static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
6156d5c65159SKalle Valo u32 len, struct wmi_chan_info_event *ch_info_ev)
6157d5c65159SKalle Valo {
6158d5c65159SKalle Valo const void **tb;
6159d5c65159SKalle Valo const struct wmi_chan_info_event *ev;
6160d5c65159SKalle Valo int ret;
6161d5c65159SKalle Valo
6162d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
6163d5c65159SKalle Valo if (IS_ERR(tb)) {
6164d5c65159SKalle Valo ret = PTR_ERR(tb);
6165d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6166d5c65159SKalle Valo return ret;
6167d5c65159SKalle Valo }
6168d5c65159SKalle Valo
6169d5c65159SKalle Valo ev = tb[WMI_TAG_CHAN_INFO_EVENT];
6170d5c65159SKalle Valo if (!ev) {
6171d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch chan info ev");
6172d5c65159SKalle Valo kfree(tb);
6173d5c65159SKalle Valo return -EPROTO;
6174d5c65159SKalle Valo }
6175d5c65159SKalle Valo
6176d5c65159SKalle Valo ch_info_ev->err_code = ev->err_code;
6177d5c65159SKalle Valo ch_info_ev->freq = ev->freq;
6178d5c65159SKalle Valo ch_info_ev->cmd_flags = ev->cmd_flags;
6179d5c65159SKalle Valo ch_info_ev->noise_floor = ev->noise_floor;
6180d5c65159SKalle Valo ch_info_ev->rx_clear_count = ev->rx_clear_count;
6181d5c65159SKalle Valo ch_info_ev->cycle_count = ev->cycle_count;
6182d5c65159SKalle Valo ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
6183d5c65159SKalle Valo ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
6184d5c65159SKalle Valo ch_info_ev->rx_frame_count = ev->rx_frame_count;
6185d5c65159SKalle Valo ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
6186d5c65159SKalle Valo ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
6187d5c65159SKalle Valo ch_info_ev->vdev_id = ev->vdev_id;
6188d5c65159SKalle Valo
6189d5c65159SKalle Valo kfree(tb);
6190d5c65159SKalle Valo return 0;
6191d5c65159SKalle Valo }
6192d5c65159SKalle Valo
6193d5c65159SKalle Valo static int
ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_pdev_bss_chan_info_event * bss_ch_info_ev)6194d5c65159SKalle Valo ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
6195d5c65159SKalle Valo struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
6196d5c65159SKalle Valo {
6197d5c65159SKalle Valo const void **tb;
6198d5c65159SKalle Valo const struct wmi_pdev_bss_chan_info_event *ev;
6199d5c65159SKalle Valo int ret;
6200d5c65159SKalle Valo
6201d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6202d5c65159SKalle Valo if (IS_ERR(tb)) {
6203d5c65159SKalle Valo ret = PTR_ERR(tb);
6204d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6205d5c65159SKalle Valo return ret;
6206d5c65159SKalle Valo }
6207d5c65159SKalle Valo
6208d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
6209d5c65159SKalle Valo if (!ev) {
6210d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
6211d5c65159SKalle Valo kfree(tb);
6212d5c65159SKalle Valo return -EPROTO;
6213d5c65159SKalle Valo }
6214d5c65159SKalle Valo
6215d5c65159SKalle Valo bss_ch_info_ev->pdev_id = ev->pdev_id;
6216d5c65159SKalle Valo bss_ch_info_ev->freq = ev->freq;
6217d5c65159SKalle Valo bss_ch_info_ev->noise_floor = ev->noise_floor;
6218d5c65159SKalle Valo bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
6219d5c65159SKalle Valo bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
6220d5c65159SKalle Valo bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
6221d5c65159SKalle Valo bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
6222d5c65159SKalle Valo bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
6223d5c65159SKalle Valo bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
6224d5c65159SKalle Valo bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
6225d5c65159SKalle Valo bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
6226d5c65159SKalle Valo bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
6227d5c65159SKalle Valo bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
6228d5c65159SKalle Valo
6229d5c65159SKalle Valo kfree(tb);
6230d5c65159SKalle Valo return 0;
6231d5c65159SKalle Valo }
6232d5c65159SKalle Valo
6233d5c65159SKalle Valo static int
ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_vdev_install_key_complete_arg * arg)6234d5c65159SKalle Valo ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
6235d5c65159SKalle Valo struct wmi_vdev_install_key_complete_arg *arg)
6236d5c65159SKalle Valo {
6237d5c65159SKalle Valo const void **tb;
6238d5c65159SKalle Valo const struct wmi_vdev_install_key_compl_event *ev;
6239d5c65159SKalle Valo int ret;
6240d5c65159SKalle Valo
6241d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6242d5c65159SKalle Valo if (IS_ERR(tb)) {
6243d5c65159SKalle Valo ret = PTR_ERR(tb);
6244d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6245d5c65159SKalle Valo return ret;
6246d5c65159SKalle Valo }
6247d5c65159SKalle Valo
6248d5c65159SKalle Valo ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
6249d5c65159SKalle Valo if (!ev) {
6250d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch vdev install key compl ev");
6251d5c65159SKalle Valo kfree(tb);
6252d5c65159SKalle Valo return -EPROTO;
6253d5c65159SKalle Valo }
6254d5c65159SKalle Valo
6255d5c65159SKalle Valo arg->vdev_id = ev->vdev_id;
6256d5c65159SKalle Valo arg->macaddr = ev->peer_macaddr.addr;
6257d5c65159SKalle Valo arg->key_idx = ev->key_idx;
6258d5c65159SKalle Valo arg->key_flags = ev->key_flags;
6259d5c65159SKalle Valo arg->status = ev->status;
6260d5c65159SKalle Valo
6261d5c65159SKalle Valo kfree(tb);
6262d5c65159SKalle Valo return 0;
6263d5c65159SKalle Valo }
6264d5c65159SKalle Valo
ath11k_pull_peer_assoc_conf_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_peer_assoc_conf_arg * peer_assoc_conf)6265d5c65159SKalle Valo static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
6266d5c65159SKalle Valo struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
6267d5c65159SKalle Valo {
6268d5c65159SKalle Valo const void **tb;
6269d5c65159SKalle Valo const struct wmi_peer_assoc_conf_event *ev;
6270d5c65159SKalle Valo int ret;
6271d5c65159SKalle Valo
6272d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6273d5c65159SKalle Valo if (IS_ERR(tb)) {
6274d5c65159SKalle Valo ret = PTR_ERR(tb);
6275d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6276d5c65159SKalle Valo return ret;
6277d5c65159SKalle Valo }
6278d5c65159SKalle Valo
6279d5c65159SKalle Valo ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
6280d5c65159SKalle Valo if (!ev) {
6281d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch peer assoc conf ev");
6282d5c65159SKalle Valo kfree(tb);
6283d5c65159SKalle Valo return -EPROTO;
6284d5c65159SKalle Valo }
6285d5c65159SKalle Valo
6286d5c65159SKalle Valo peer_assoc_conf->vdev_id = ev->vdev_id;
6287d5c65159SKalle Valo peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
6288d5c65159SKalle Valo
6289d5c65159SKalle Valo kfree(tb);
6290d5c65159SKalle Valo return 0;
6291d5c65159SKalle Valo }
6292d5c65159SKalle Valo
ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base * src,struct ath11k_fw_stats_pdev * dst)6293d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
6294d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst)
6295d5c65159SKalle Valo {
6296d5c65159SKalle Valo dst->ch_noise_floor = src->chan_nf;
6297d5c65159SKalle Valo dst->tx_frame_count = src->tx_frame_count;
6298d5c65159SKalle Valo dst->rx_frame_count = src->rx_frame_count;
6299d5c65159SKalle Valo dst->rx_clear_count = src->rx_clear_count;
6300d5c65159SKalle Valo dst->cycle_count = src->cycle_count;
6301d5c65159SKalle Valo dst->phy_err_count = src->phy_err_count;
6302d5c65159SKalle Valo dst->chan_tx_power = src->chan_tx_pwr;
6303d5c65159SKalle Valo }
6304d5c65159SKalle Valo
6305d5c65159SKalle Valo static void
ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx * src,struct ath11k_fw_stats_pdev * dst)6306d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
6307d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst)
6308d5c65159SKalle Valo {
6309d5c65159SKalle Valo dst->comp_queued = src->comp_queued;
6310d5c65159SKalle Valo dst->comp_delivered = src->comp_delivered;
6311d5c65159SKalle Valo dst->msdu_enqued = src->msdu_enqued;
6312d5c65159SKalle Valo dst->mpdu_enqued = src->mpdu_enqued;
6313d5c65159SKalle Valo dst->wmm_drop = src->wmm_drop;
6314d5c65159SKalle Valo dst->local_enqued = src->local_enqued;
6315d5c65159SKalle Valo dst->local_freed = src->local_freed;
6316d5c65159SKalle Valo dst->hw_queued = src->hw_queued;
6317d5c65159SKalle Valo dst->hw_reaped = src->hw_reaped;
6318d5c65159SKalle Valo dst->underrun = src->underrun;
6319f394e4eaSSriram R dst->hw_paused = src->hw_paused;
6320d5c65159SKalle Valo dst->tx_abort = src->tx_abort;
632117818dfaSColin Ian King dst->mpdus_requeued = src->mpdus_requeued;
6322d5c65159SKalle Valo dst->tx_ko = src->tx_ko;
6323f394e4eaSSriram R dst->tx_xretry = src->tx_xretry;
6324d5c65159SKalle Valo dst->data_rc = src->data_rc;
6325d5c65159SKalle Valo dst->self_triggers = src->self_triggers;
6326d5c65159SKalle Valo dst->sw_retry_failure = src->sw_retry_failure;
6327d5c65159SKalle Valo dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
6328d5c65159SKalle Valo dst->pdev_cont_xretry = src->pdev_cont_xretry;
6329d5c65159SKalle Valo dst->pdev_tx_timeout = src->pdev_tx_timeout;
6330d5c65159SKalle Valo dst->pdev_resets = src->pdev_resets;
6331d5c65159SKalle Valo dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
6332d5c65159SKalle Valo dst->phy_underrun = src->phy_underrun;
6333d5c65159SKalle Valo dst->txop_ovf = src->txop_ovf;
6334f394e4eaSSriram R dst->seq_posted = src->seq_posted;
6335f394e4eaSSriram R dst->seq_failed_queueing = src->seq_failed_queueing;
6336f394e4eaSSriram R dst->seq_completed = src->seq_completed;
6337f394e4eaSSriram R dst->seq_restarted = src->seq_restarted;
6338f394e4eaSSriram R dst->mu_seq_posted = src->mu_seq_posted;
6339f394e4eaSSriram R dst->mpdus_sw_flush = src->mpdus_sw_flush;
6340f394e4eaSSriram R dst->mpdus_hw_filter = src->mpdus_hw_filter;
6341f394e4eaSSriram R dst->mpdus_truncated = src->mpdus_truncated;
6342f394e4eaSSriram R dst->mpdus_ack_failed = src->mpdus_ack_failed;
6343f394e4eaSSriram R dst->mpdus_expired = src->mpdus_expired;
6344d5c65159SKalle Valo }
6345d5c65159SKalle Valo
ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx * src,struct ath11k_fw_stats_pdev * dst)6346d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
6347d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst)
6348d5c65159SKalle Valo {
6349d5c65159SKalle Valo dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
6350d5c65159SKalle Valo dst->status_rcvd = src->status_rcvd;
6351d5c65159SKalle Valo dst->r0_frags = src->r0_frags;
6352d5c65159SKalle Valo dst->r1_frags = src->r1_frags;
6353d5c65159SKalle Valo dst->r2_frags = src->r2_frags;
6354d5c65159SKalle Valo dst->r3_frags = src->r3_frags;
6355d5c65159SKalle Valo dst->htt_msdus = src->htt_msdus;
6356d5c65159SKalle Valo dst->htt_mpdus = src->htt_mpdus;
6357d5c65159SKalle Valo dst->loc_msdus = src->loc_msdus;
6358d5c65159SKalle Valo dst->loc_mpdus = src->loc_mpdus;
6359d5c65159SKalle Valo dst->oversize_amsdu = src->oversize_amsdu;
6360d5c65159SKalle Valo dst->phy_errs = src->phy_errs;
6361d5c65159SKalle Valo dst->phy_err_drop = src->phy_err_drop;
6362d5c65159SKalle Valo dst->mpdu_errs = src->mpdu_errs;
6363f394e4eaSSriram R dst->rx_ovfl_errs = src->rx_ovfl_errs;
6364d5c65159SKalle Valo }
6365d5c65159SKalle Valo
6366d5c65159SKalle Valo static void
ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats * src,struct ath11k_fw_stats_vdev * dst)6367d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
6368d5c65159SKalle Valo struct ath11k_fw_stats_vdev *dst)
6369d5c65159SKalle Valo {
6370d5c65159SKalle Valo int i;
6371d5c65159SKalle Valo
6372d5c65159SKalle Valo dst->vdev_id = src->vdev_id;
6373d5c65159SKalle Valo dst->beacon_snr = src->beacon_snr;
6374d5c65159SKalle Valo dst->data_snr = src->data_snr;
6375d5c65159SKalle Valo dst->num_rx_frames = src->num_rx_frames;
6376d5c65159SKalle Valo dst->num_rts_fail = src->num_rts_fail;
6377d5c65159SKalle Valo dst->num_rts_success = src->num_rts_success;
6378d5c65159SKalle Valo dst->num_rx_err = src->num_rx_err;
6379d5c65159SKalle Valo dst->num_rx_discard = src->num_rx_discard;
6380d5c65159SKalle Valo dst->num_tx_not_acked = src->num_tx_not_acked;
6381d5c65159SKalle Valo
6382d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
6383d5c65159SKalle Valo dst->num_tx_frames[i] = src->num_tx_frames[i];
6384d5c65159SKalle Valo
6385d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
6386d5c65159SKalle Valo dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
6387d5c65159SKalle Valo
6388d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
6389d5c65159SKalle Valo dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
6390d5c65159SKalle Valo
6391d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
6392d5c65159SKalle Valo dst->tx_rate_history[i] = src->tx_rate_history[i];
6393d5c65159SKalle Valo
6394d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
6395d5c65159SKalle Valo dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
6396d5c65159SKalle Valo }
6397d5c65159SKalle Valo
6398d5c65159SKalle Valo static void
ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats * src,struct ath11k_fw_stats_bcn * dst)6399d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
6400d5c65159SKalle Valo struct ath11k_fw_stats_bcn *dst)
6401d5c65159SKalle Valo {
6402d5c65159SKalle Valo dst->vdev_id = src->vdev_id;
6403d5c65159SKalle Valo dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
6404d5c65159SKalle Valo dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
6405d5c65159SKalle Valo }
6406d5c65159SKalle Valo
ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)6407b488c766SWen Gong static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
6408b488c766SWen Gong u16 tag, u16 len,
6409b488c766SWen Gong const void *ptr, void *data)
6410d5c65159SKalle Valo {
6411b488c766SWen Gong struct wmi_tlv_fw_stats_parse *parse = data;
6412b488c766SWen Gong const struct wmi_stats_event *ev = parse->ev;
6413b488c766SWen Gong struct ath11k_fw_stats *stats = parse->stats;
6414b488c766SWen Gong struct ath11k *ar;
6415b488c766SWen Gong struct ath11k_vif *arvif;
6416b488c766SWen Gong struct ieee80211_sta *sta;
6417b488c766SWen Gong struct ath11k_sta *arsta;
6418b488c766SWen Gong const struct wmi_rssi_stats *stats_rssi = (const struct wmi_rssi_stats *)ptr;
6419b488c766SWen Gong int j, ret = 0;
6420d5c65159SKalle Valo
6421b488c766SWen Gong if (tag != WMI_TAG_RSSI_STATS)
6422d5c65159SKalle Valo return -EPROTO;
6423b488c766SWen Gong
6424b488c766SWen Gong rcu_read_lock();
6425b488c766SWen Gong
6426b488c766SWen Gong ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6427b488c766SWen Gong stats->stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
6428b488c766SWen Gong
6429b488c766SWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
6430fc3b984aSKalle Valo "stats vdev id %d mac %pM\n",
6431b488c766SWen Gong stats_rssi->vdev_id, stats_rssi->peer_macaddr.addr);
6432b488c766SWen Gong
6433b488c766SWen Gong arvif = ath11k_mac_get_arvif(ar, stats_rssi->vdev_id);
6434b488c766SWen Gong if (!arvif) {
6435b488c766SWen Gong ath11k_warn(ab, "not found vif for vdev id %d\n",
6436b488c766SWen Gong stats_rssi->vdev_id);
6437b488c766SWen Gong ret = -EPROTO;
6438b488c766SWen Gong goto exit;
6439d5c65159SKalle Valo }
6440d5c65159SKalle Valo
6441d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
6442cf036c41SKalle Valo "stats bssid %pM vif %p\n",
6443b488c766SWen Gong arvif->bssid, arvif->vif);
6444d5c65159SKalle Valo
6445b488c766SWen Gong sta = ieee80211_find_sta_by_ifaddr(ar->hw,
6446b488c766SWen Gong arvif->bssid,
6447b488c766SWen Gong NULL);
6448b488c766SWen Gong if (!sta) {
64497330e1ecSWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
64507330e1ecSWen Gong "not found station of bssid %pM for rssi chain\n",
6451b488c766SWen Gong arvif->bssid);
6452b488c766SWen Gong goto exit;
6453b488c766SWen Gong }
6454b488c766SWen Gong
6455b488c766SWen Gong arsta = (struct ath11k_sta *)sta->drv_priv;
6456b488c766SWen Gong
6457b488c766SWen Gong BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
6458b488c766SWen Gong ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
6459b488c766SWen Gong
6460b488c766SWen Gong for (j = 0; j < ARRAY_SIZE(arsta->chain_signal); j++) {
6461b488c766SWen Gong arsta->chain_signal[j] = stats_rssi->rssi_avg_beacon[j];
6462b488c766SWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
6463fc3b984aSKalle Valo "stats beacon rssi[%d] %d data rssi[%d] %d\n",
6464b488c766SWen Gong j,
6465b488c766SWen Gong stats_rssi->rssi_avg_beacon[j],
6466b488c766SWen Gong j,
6467b488c766SWen Gong stats_rssi->rssi_avg_data[j]);
6468b488c766SWen Gong }
6469b488c766SWen Gong
6470b488c766SWen Gong exit:
6471b488c766SWen Gong rcu_read_unlock();
6472b488c766SWen Gong return ret;
6473b488c766SWen Gong }
6474b488c766SWen Gong
ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base * ab,struct wmi_tlv_fw_stats_parse * parse,const void * ptr,u16 len)6475b488c766SWen Gong static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
6476b488c766SWen Gong struct wmi_tlv_fw_stats_parse *parse,
6477b488c766SWen Gong const void *ptr,
6478b488c766SWen Gong u16 len)
6479b488c766SWen Gong {
6480b488c766SWen Gong struct ath11k_fw_stats *stats = parse->stats;
6481b488c766SWen Gong const struct wmi_stats_event *ev = parse->ev;
6482c3b39553SWen Gong struct ath11k *ar;
6483c3b39553SWen Gong struct ath11k_vif *arvif;
6484c3b39553SWen Gong struct ieee80211_sta *sta;
6485c3b39553SWen Gong struct ath11k_sta *arsta;
6486c3b39553SWen Gong int i, ret = 0;
6487b488c766SWen Gong const void *data = ptr;
6488b488c766SWen Gong
6489b488c766SWen Gong if (!ev) {
6490b488c766SWen Gong ath11k_warn(ab, "failed to fetch update stats ev");
6491b488c766SWen Gong return -EPROTO;
6492b488c766SWen Gong }
6493b488c766SWen Gong
6494d5c65159SKalle Valo stats->stats_id = 0;
6495d5c65159SKalle Valo
6496c3b39553SWen Gong rcu_read_lock();
6497c3b39553SWen Gong
6498c3b39553SWen Gong ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
6499c3b39553SWen Gong
6500d5c65159SKalle Valo for (i = 0; i < ev->num_pdev_stats; i++) {
6501d5c65159SKalle Valo const struct wmi_pdev_stats *src;
6502d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst;
6503d5c65159SKalle Valo
6504d5c65159SKalle Valo src = data;
6505c3b39553SWen Gong if (len < sizeof(*src)) {
6506c3b39553SWen Gong ret = -EPROTO;
6507c3b39553SWen Gong goto exit;
6508c3b39553SWen Gong }
6509d5c65159SKalle Valo
6510d5c65159SKalle Valo stats->stats_id = WMI_REQUEST_PDEV_STAT;
6511d5c65159SKalle Valo
6512d5c65159SKalle Valo data += sizeof(*src);
6513d5c65159SKalle Valo len -= sizeof(*src);
6514d5c65159SKalle Valo
6515d5c65159SKalle Valo dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6516d5c65159SKalle Valo if (!dst)
6517d5c65159SKalle Valo continue;
6518d5c65159SKalle Valo
6519d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
6520d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
6521d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
6522d5c65159SKalle Valo list_add_tail(&dst->list, &stats->pdevs);
6523d5c65159SKalle Valo }
6524d5c65159SKalle Valo
6525d5c65159SKalle Valo for (i = 0; i < ev->num_vdev_stats; i++) {
6526d5c65159SKalle Valo const struct wmi_vdev_stats *src;
6527d5c65159SKalle Valo struct ath11k_fw_stats_vdev *dst;
6528d5c65159SKalle Valo
6529d5c65159SKalle Valo src = data;
6530c3b39553SWen Gong if (len < sizeof(*src)) {
6531c3b39553SWen Gong ret = -EPROTO;
6532c3b39553SWen Gong goto exit;
6533c3b39553SWen Gong }
6534d5c65159SKalle Valo
6535d5c65159SKalle Valo stats->stats_id = WMI_REQUEST_VDEV_STAT;
6536d5c65159SKalle Valo
6537c3b39553SWen Gong arvif = ath11k_mac_get_arvif(ar, src->vdev_id);
6538c3b39553SWen Gong if (arvif) {
6539c3b39553SWen Gong sta = ieee80211_find_sta_by_ifaddr(ar->hw,
6540c3b39553SWen Gong arvif->bssid,
6541c3b39553SWen Gong NULL);
6542c3b39553SWen Gong if (sta) {
6543c3b39553SWen Gong arsta = (struct ath11k_sta *)sta->drv_priv;
6544c3b39553SWen Gong arsta->rssi_beacon = src->beacon_snr;
6545c3b39553SWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
6546fc3b984aSKalle Valo "stats vdev id %d snr %d\n",
6547c3b39553SWen Gong src->vdev_id, src->beacon_snr);
6548c3b39553SWen Gong } else {
65497330e1ecSWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
65507330e1ecSWen Gong "not found station of bssid %pM for vdev stat\n",
6551c3b39553SWen Gong arvif->bssid);
6552c3b39553SWen Gong }
6553c3b39553SWen Gong }
6554c3b39553SWen Gong
6555d5c65159SKalle Valo data += sizeof(*src);
6556d5c65159SKalle Valo len -= sizeof(*src);
6557d5c65159SKalle Valo
6558d5c65159SKalle Valo dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6559d5c65159SKalle Valo if (!dst)
6560d5c65159SKalle Valo continue;
6561d5c65159SKalle Valo
6562d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(src, dst);
6563d5c65159SKalle Valo list_add_tail(&dst->list, &stats->vdevs);
6564d5c65159SKalle Valo }
6565d5c65159SKalle Valo
6566d5c65159SKalle Valo for (i = 0; i < ev->num_bcn_stats; i++) {
6567d5c65159SKalle Valo const struct wmi_bcn_stats *src;
6568d5c65159SKalle Valo struct ath11k_fw_stats_bcn *dst;
6569d5c65159SKalle Valo
6570d5c65159SKalle Valo src = data;
6571c3b39553SWen Gong if (len < sizeof(*src)) {
6572c3b39553SWen Gong ret = -EPROTO;
6573c3b39553SWen Gong goto exit;
6574c3b39553SWen Gong }
6575d5c65159SKalle Valo
6576d5c65159SKalle Valo stats->stats_id = WMI_REQUEST_BCN_STAT;
6577d5c65159SKalle Valo
6578d5c65159SKalle Valo data += sizeof(*src);
6579d5c65159SKalle Valo len -= sizeof(*src);
6580d5c65159SKalle Valo
6581d5c65159SKalle Valo dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
6582d5c65159SKalle Valo if (!dst)
6583d5c65159SKalle Valo continue;
6584d5c65159SKalle Valo
6585d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(src, dst);
6586d5c65159SKalle Valo list_add_tail(&dst->list, &stats->bcn);
6587d5c65159SKalle Valo }
6588d5c65159SKalle Valo
6589c3b39553SWen Gong exit:
6590c3b39553SWen Gong rcu_read_unlock();
6591c3b39553SWen Gong return ret;
6592d5c65159SKalle Valo }
6593d5c65159SKalle Valo
ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)6594b488c766SWen Gong static int ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base *ab,
6595b488c766SWen Gong u16 tag, u16 len,
6596b488c766SWen Gong const void *ptr, void *data)
6597b488c766SWen Gong {
6598b488c766SWen Gong struct wmi_tlv_fw_stats_parse *parse = data;
6599b488c766SWen Gong int ret = 0;
6600b488c766SWen Gong
6601b488c766SWen Gong switch (tag) {
6602b488c766SWen Gong case WMI_TAG_STATS_EVENT:
6603b488c766SWen Gong parse->ev = (struct wmi_stats_event *)ptr;
6604b488c766SWen Gong parse->stats->pdev_id = parse->ev->pdev_id;
6605b488c766SWen Gong break;
6606b488c766SWen Gong case WMI_TAG_ARRAY_BYTE:
6607b488c766SWen Gong ret = ath11k_wmi_tlv_fw_stats_data_parse(ab, parse, ptr, len);
6608b488c766SWen Gong break;
6609b488c766SWen Gong case WMI_TAG_PER_CHAIN_RSSI_STATS:
6610b488c766SWen Gong parse->rssi = (struct wmi_per_chain_rssi_stats *)ptr;
6611b488c766SWen Gong
6612b488c766SWen Gong if (parse->ev->stats_id & WMI_REQUEST_RSSI_PER_CHAIN_STAT)
6613b488c766SWen Gong parse->rssi_num = parse->rssi->num_per_chain_rssi_stats;
6614b488c766SWen Gong
6615b488c766SWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
6616fc3b984aSKalle Valo "stats id 0x%x num chain %d\n",
6617b488c766SWen Gong parse->ev->stats_id,
6618b488c766SWen Gong parse->rssi_num);
6619b488c766SWen Gong break;
6620b488c766SWen Gong case WMI_TAG_ARRAY_STRUCT:
6621b488c766SWen Gong if (parse->rssi_num && !parse->chain_rssi_done) {
6622b488c766SWen Gong ret = ath11k_wmi_tlv_iter(ab, ptr, len,
6623b488c766SWen Gong ath11k_wmi_tlv_rssi_chain_parse,
6624b488c766SWen Gong parse);
6625b488c766SWen Gong if (ret) {
6626b488c766SWen Gong ath11k_warn(ab, "failed to parse rssi chain %d\n",
6627b488c766SWen Gong ret);
6628b488c766SWen Gong return ret;
6629b488c766SWen Gong }
6630b488c766SWen Gong parse->chain_rssi_done = true;
6631b488c766SWen Gong }
6632b488c766SWen Gong break;
6633b488c766SWen Gong default:
6634b488c766SWen Gong break;
6635b488c766SWen Gong }
6636b488c766SWen Gong return ret;
6637b488c766SWen Gong }
6638b488c766SWen Gong
ath11k_wmi_pull_fw_stats(struct ath11k_base * ab,struct sk_buff * skb,struct ath11k_fw_stats * stats)6639b488c766SWen Gong int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
6640b488c766SWen Gong struct ath11k_fw_stats *stats)
6641b488c766SWen Gong {
6642b488c766SWen Gong struct wmi_tlv_fw_stats_parse parse = { };
6643b488c766SWen Gong
6644b488c766SWen Gong stats->stats_id = 0;
6645b488c766SWen Gong parse.stats = stats;
6646b488c766SWen Gong
6647b488c766SWen Gong return ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6648b488c766SWen Gong ath11k_wmi_tlv_fw_stats_parse,
6649b488c766SWen Gong &parse);
6650b488c766SWen Gong }
6651b488c766SWen Gong
6652d5c65159SKalle Valo static void
ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev * pdev,char * buf,u32 * length)6653d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6654d5c65159SKalle Valo char *buf, u32 *length)
6655d5c65159SKalle Valo {
6656d5c65159SKalle Valo u32 len = *length;
6657d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6658d5c65159SKalle Valo
6659d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n");
6660d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n",
6661d5c65159SKalle Valo "ath11k PDEV stats");
6662d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6663d5c65159SKalle Valo "=================");
6664d5c65159SKalle Valo
6665d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6666d5c65159SKalle Valo "Channel noise floor", pdev->ch_noise_floor);
6667d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6668d5c65159SKalle Valo "Channel TX power", pdev->chan_tx_power);
6669d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6670d5c65159SKalle Valo "TX frame count", pdev->tx_frame_count);
6671d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6672d5c65159SKalle Valo "RX frame count", pdev->rx_frame_count);
6673d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6674d5c65159SKalle Valo "RX clear count", pdev->rx_clear_count);
6675d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6676d5c65159SKalle Valo "Cycle count", pdev->cycle_count);
6677d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6678d5c65159SKalle Valo "PHY error count", pdev->phy_err_count);
6679d5c65159SKalle Valo
6680d5c65159SKalle Valo *length = len;
6681d5c65159SKalle Valo }
6682d5c65159SKalle Valo
6683d5c65159SKalle Valo static void
ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev * pdev,char * buf,u32 * length)6684d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6685d5c65159SKalle Valo char *buf, u32 *length)
6686d5c65159SKalle Valo {
6687d5c65159SKalle Valo u32 len = *length;
6688d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6689d5c65159SKalle Valo
6690d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6691d5c65159SKalle Valo "ath11k PDEV TX stats");
6692d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6693d5c65159SKalle Valo "====================");
6694d5c65159SKalle Valo
6695d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6696d5c65159SKalle Valo "HTT cookies queued", pdev->comp_queued);
6697d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6698d5c65159SKalle Valo "HTT cookies disp.", pdev->comp_delivered);
6699d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6700d5c65159SKalle Valo "MSDU queued", pdev->msdu_enqued);
6701d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6702d5c65159SKalle Valo "MPDU queued", pdev->mpdu_enqued);
6703d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6704d5c65159SKalle Valo "MSDUs dropped", pdev->wmm_drop);
6705d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6706d5c65159SKalle Valo "Local enqued", pdev->local_enqued);
6707d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6708d5c65159SKalle Valo "Local freed", pdev->local_freed);
6709d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6710d5c65159SKalle Valo "HW queued", pdev->hw_queued);
6711d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6712d5c65159SKalle Valo "PPDUs reaped", pdev->hw_reaped);
6713d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6714d5c65159SKalle Valo "Num underruns", pdev->underrun);
6715d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6716f394e4eaSSriram R "Num HW Paused", pdev->hw_paused);
6717f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6718d5c65159SKalle Valo "PPDUs cleaned", pdev->tx_abort);
6719d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
672017818dfaSColin Ian King "MPDUs requeued", pdev->mpdus_requeued);
6721d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6722f394e4eaSSriram R "PPDU OK", pdev->tx_ko);
6723f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6724f394e4eaSSriram R "Excessive retries", pdev->tx_xretry);
6725d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6726d5c65159SKalle Valo "HW rate", pdev->data_rc);
6727d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6728d5c65159SKalle Valo "Sched self triggers", pdev->self_triggers);
6729d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6730d5c65159SKalle Valo "Dropped due to SW retries",
6731d5c65159SKalle Valo pdev->sw_retry_failure);
6732d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6733d5c65159SKalle Valo "Illegal rate phy errors",
6734d5c65159SKalle Valo pdev->illgl_rate_phy_err);
6735d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6736d5c65159SKalle Valo "PDEV continuous xretry", pdev->pdev_cont_xretry);
6737d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6738d5c65159SKalle Valo "TX timeout", pdev->pdev_tx_timeout);
6739d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6740d5c65159SKalle Valo "PDEV resets", pdev->pdev_resets);
6741d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6742d5c65159SKalle Valo "Stateless TIDs alloc failures",
6743d5c65159SKalle Valo pdev->stateless_tid_alloc_failure);
6744d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6745d5c65159SKalle Valo "PHY underrun", pdev->phy_underrun);
6746d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6747d5c65159SKalle Valo "MPDU is more than txop limit", pdev->txop_ovf);
6748f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6749f394e4eaSSriram R "Num sequences posted", pdev->seq_posted);
6750f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6751f394e4eaSSriram R "Num seq failed queueing ", pdev->seq_failed_queueing);
6752f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6753f394e4eaSSriram R "Num sequences completed ", pdev->seq_completed);
6754f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6755f394e4eaSSriram R "Num sequences restarted ", pdev->seq_restarted);
6756f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6757f394e4eaSSriram R "Num of MU sequences posted ", pdev->mu_seq_posted);
6758f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6759f394e4eaSSriram R "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush);
6760f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6761f394e4eaSSriram R "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter);
6762f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6763f394e4eaSSriram R "Num of MPDUS truncated ", pdev->mpdus_truncated);
6764f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6765f394e4eaSSriram R "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed);
6766f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6767f394e4eaSSriram R "Num of MPDUS expired ", pdev->mpdus_expired);
6768d5c65159SKalle Valo *length = len;
6769d5c65159SKalle Valo }
6770d5c65159SKalle Valo
6771d5c65159SKalle Valo static void
ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev * pdev,char * buf,u32 * length)6772d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6773d5c65159SKalle Valo char *buf, u32 *length)
6774d5c65159SKalle Valo {
6775d5c65159SKalle Valo u32 len = *length;
6776d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6777d5c65159SKalle Valo
6778d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6779d5c65159SKalle Valo "ath11k PDEV RX stats");
6780d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6781d5c65159SKalle Valo "====================");
6782d5c65159SKalle Valo
6783d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6784d5c65159SKalle Valo "Mid PPDU route change",
6785d5c65159SKalle Valo pdev->mid_ppdu_route_change);
6786d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6787d5c65159SKalle Valo "Tot. number of statuses", pdev->status_rcvd);
6788d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6789d5c65159SKalle Valo "Extra frags on rings 0", pdev->r0_frags);
6790d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6791d5c65159SKalle Valo "Extra frags on rings 1", pdev->r1_frags);
6792d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6793d5c65159SKalle Valo "Extra frags on rings 2", pdev->r2_frags);
6794d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6795d5c65159SKalle Valo "Extra frags on rings 3", pdev->r3_frags);
6796d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6797d5c65159SKalle Valo "MSDUs delivered to HTT", pdev->htt_msdus);
6798d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6799d5c65159SKalle Valo "MPDUs delivered to HTT", pdev->htt_mpdus);
6800d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6801d5c65159SKalle Valo "MSDUs delivered to stack", pdev->loc_msdus);
6802d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6803d5c65159SKalle Valo "MPDUs delivered to stack", pdev->loc_mpdus);
6804d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6805d5c65159SKalle Valo "Oversized AMSUs", pdev->oversize_amsdu);
6806d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6807d5c65159SKalle Valo "PHY errors", pdev->phy_errs);
6808d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6809d5c65159SKalle Valo "PHY errors drops", pdev->phy_err_drop);
6810d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6811d5c65159SKalle Valo "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
6812f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6813f394e4eaSSriram R "Overflow errors", pdev->rx_ovfl_errs);
6814d5c65159SKalle Valo *length = len;
6815d5c65159SKalle Valo }
6816d5c65159SKalle Valo
6817d5c65159SKalle Valo static void
ath11k_wmi_fw_vdev_stats_fill(struct ath11k * ar,const struct ath11k_fw_stats_vdev * vdev,char * buf,u32 * length)6818d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
6819d5c65159SKalle Valo const struct ath11k_fw_stats_vdev *vdev,
6820d5c65159SKalle Valo char *buf, u32 *length)
6821d5c65159SKalle Valo {
6822d5c65159SKalle Valo u32 len = *length;
6823d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6824d5c65159SKalle Valo struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
6825d5c65159SKalle Valo u8 *vif_macaddr;
6826d5c65159SKalle Valo int i;
6827d5c65159SKalle Valo
6828d5c65159SKalle Valo /* VDEV stats has all the active VDEVs of other PDEVs as well,
6829d5c65159SKalle Valo * ignoring those not part of requested PDEV
6830d5c65159SKalle Valo */
6831d5c65159SKalle Valo if (!arvif)
6832d5c65159SKalle Valo return;
6833d5c65159SKalle Valo
6834d5c65159SKalle Valo vif_macaddr = arvif->vif->addr;
6835d5c65159SKalle Valo
6836d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6837d5c65159SKalle Valo "VDEV ID", vdev->vdev_id);
6838d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6839d5c65159SKalle Valo "VDEV MAC address", vif_macaddr);
6840d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6841d5c65159SKalle Valo "beacon snr", vdev->beacon_snr);
6842d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6843d5c65159SKalle Valo "data snr", vdev->data_snr);
6844d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6845d5c65159SKalle Valo "num rx frames", vdev->num_rx_frames);
6846d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6847d5c65159SKalle Valo "num rts fail", vdev->num_rts_fail);
6848d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6849d5c65159SKalle Valo "num rts success", vdev->num_rts_success);
6850d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6851d5c65159SKalle Valo "num rx err", vdev->num_rx_err);
6852d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6853d5c65159SKalle Valo "num rx discard", vdev->num_rx_discard);
6854d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6855d5c65159SKalle Valo "num tx not acked", vdev->num_tx_not_acked);
6856d5c65159SKalle Valo
6857d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
6858d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len,
6859d5c65159SKalle Valo "%25s [%02d] %u\n",
6860d5c65159SKalle Valo "num tx frames", i,
6861d5c65159SKalle Valo vdev->num_tx_frames[i]);
6862d5c65159SKalle Valo
6863d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
6864d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len,
6865d5c65159SKalle Valo "%25s [%02d] %u\n",
6866d5c65159SKalle Valo "num tx frames retries", i,
6867d5c65159SKalle Valo vdev->num_tx_frames_retries[i]);
6868d5c65159SKalle Valo
6869d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
6870d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len,
6871d5c65159SKalle Valo "%25s [%02d] %u\n",
6872d5c65159SKalle Valo "num tx frames failures", i,
6873d5c65159SKalle Valo vdev->num_tx_frames_failures[i]);
6874d5c65159SKalle Valo
6875d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
6876d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len,
6877d5c65159SKalle Valo "%25s [%02d] 0x%08x\n",
6878d5c65159SKalle Valo "tx rate history", i,
6879d5c65159SKalle Valo vdev->tx_rate_history[i]);
6880d5c65159SKalle Valo
6881d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
6882d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len,
6883d5c65159SKalle Valo "%25s [%02d] %u\n",
6884d5c65159SKalle Valo "beacon rssi history", i,
6885d5c65159SKalle Valo vdev->beacon_rssi_history[i]);
6886d5c65159SKalle Valo
6887d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n");
6888d5c65159SKalle Valo *length = len;
6889d5c65159SKalle Valo }
6890d5c65159SKalle Valo
6891d5c65159SKalle Valo static void
ath11k_wmi_fw_bcn_stats_fill(struct ath11k * ar,const struct ath11k_fw_stats_bcn * bcn,char * buf,u32 * length)6892d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
6893d5c65159SKalle Valo const struct ath11k_fw_stats_bcn *bcn,
6894d5c65159SKalle Valo char *buf, u32 *length)
6895d5c65159SKalle Valo {
6896d5c65159SKalle Valo u32 len = *length;
6897d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6898d5c65159SKalle Valo struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
6899d5c65159SKalle Valo u8 *vdev_macaddr;
6900d5c65159SKalle Valo
6901d5c65159SKalle Valo if (!arvif) {
6902d5c65159SKalle Valo ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
6903d5c65159SKalle Valo bcn->vdev_id);
6904d5c65159SKalle Valo return;
6905d5c65159SKalle Valo }
6906d5c65159SKalle Valo
6907d5c65159SKalle Valo vdev_macaddr = arvif->vif->addr;
6908d5c65159SKalle Valo
6909d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6910d5c65159SKalle Valo "VDEV ID", bcn->vdev_id);
6911d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6912d5c65159SKalle Valo "VDEV MAC address", vdev_macaddr);
6913d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6914d5c65159SKalle Valo "================");
6915d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6916d5c65159SKalle Valo "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
6917d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6918d5c65159SKalle Valo "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
6919d5c65159SKalle Valo
6920d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n");
6921d5c65159SKalle Valo *length = len;
6922d5c65159SKalle Valo }
6923d5c65159SKalle Valo
ath11k_wmi_fw_stats_fill(struct ath11k * ar,struct ath11k_fw_stats * fw_stats,u32 stats_id,char * buf)6924d5c65159SKalle Valo void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
6925d5c65159SKalle Valo struct ath11k_fw_stats *fw_stats,
6926d5c65159SKalle Valo u32 stats_id, char *buf)
6927d5c65159SKalle Valo {
6928d5c65159SKalle Valo u32 len = 0;
6929d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6930d5c65159SKalle Valo const struct ath11k_fw_stats_pdev *pdev;
6931d5c65159SKalle Valo const struct ath11k_fw_stats_vdev *vdev;
6932d5c65159SKalle Valo const struct ath11k_fw_stats_bcn *bcn;
6933d5c65159SKalle Valo size_t num_bcn;
6934d5c65159SKalle Valo
6935d5c65159SKalle Valo spin_lock_bh(&ar->data_lock);
6936d5c65159SKalle Valo
6937d5c65159SKalle Valo if (stats_id == WMI_REQUEST_PDEV_STAT) {
6938d5c65159SKalle Valo pdev = list_first_entry_or_null(&fw_stats->pdevs,
6939d5c65159SKalle Valo struct ath11k_fw_stats_pdev, list);
6940d5c65159SKalle Valo if (!pdev) {
6941d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to get pdev stats\n");
6942d5c65159SKalle Valo goto unlock;
6943d5c65159SKalle Valo }
6944d5c65159SKalle Valo
6945d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
6946d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
6947d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
6948d5c65159SKalle Valo }
6949d5c65159SKalle Valo
6950d5c65159SKalle Valo if (stats_id == WMI_REQUEST_VDEV_STAT) {
6951d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n");
6952d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n",
6953d5c65159SKalle Valo "ath11k VDEV stats");
6954d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6955d5c65159SKalle Valo "=================");
6956d5c65159SKalle Valo
6957d5c65159SKalle Valo list_for_each_entry(vdev, &fw_stats->vdevs, list)
6958d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
6959d5c65159SKalle Valo }
6960d5c65159SKalle Valo
6961d5c65159SKalle Valo if (stats_id == WMI_REQUEST_BCN_STAT) {
696291dce409SChristophe JAILLET num_bcn = list_count_nodes(&fw_stats->bcn);
6963d5c65159SKalle Valo
6964d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n");
6965d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
6966d5c65159SKalle Valo "ath11k Beacon stats", num_bcn);
6967d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6968d5c65159SKalle Valo "===================");
6969d5c65159SKalle Valo
6970d5c65159SKalle Valo list_for_each_entry(bcn, &fw_stats->bcn, list)
6971d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
6972d5c65159SKalle Valo }
6973d5c65159SKalle Valo
6974d5c65159SKalle Valo unlock:
6975d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock);
6976d5c65159SKalle Valo
6977d5c65159SKalle Valo if (len >= buf_len)
6978d5c65159SKalle Valo buf[len - 1] = 0;
6979d5c65159SKalle Valo else
6980d5c65159SKalle Valo buf[len] = 0;
6981d5c65159SKalle Valo }
6982d5c65159SKalle Valo
ath11k_wmi_op_ep_tx_credits(struct ath11k_base * ab)6983d5c65159SKalle Valo static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
6984d5c65159SKalle Valo {
6985d5c65159SKalle Valo /* try to send pending beacons first. they take priority */
69866bc9d6f7SJohn Crispin wake_up(&ab->wmi_ab.tx_credits_wq);
6987d5c65159SKalle Valo }
6988d5c65159SKalle Valo
ath11k_reg_11d_new_cc_event(struct ath11k_base * ab,struct sk_buff * skb)69899dcf6808SWen Gong static int ath11k_reg_11d_new_cc_event(struct ath11k_base *ab, struct sk_buff *skb)
69909dcf6808SWen Gong {
69919dcf6808SWen Gong const struct wmi_11d_new_cc_ev *ev;
69921f682dc9SWen Gong struct ath11k *ar;
69931f682dc9SWen Gong struct ath11k_pdev *pdev;
69949dcf6808SWen Gong const void **tb;
69951f682dc9SWen Gong int ret, i;
69969dcf6808SWen Gong
69979dcf6808SWen Gong tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
69989dcf6808SWen Gong if (IS_ERR(tb)) {
69999dcf6808SWen Gong ret = PTR_ERR(tb);
70009dcf6808SWen Gong ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
70019dcf6808SWen Gong return ret;
70029dcf6808SWen Gong }
70039dcf6808SWen Gong
70049dcf6808SWen Gong ev = tb[WMI_TAG_11D_NEW_COUNTRY_EVENT];
70059dcf6808SWen Gong if (!ev) {
70069dcf6808SWen Gong kfree(tb);
70079dcf6808SWen Gong ath11k_warn(ab, "failed to fetch 11d new cc ev");
70089dcf6808SWen Gong return -EPROTO;
70099dcf6808SWen Gong }
70109dcf6808SWen Gong
70119dcf6808SWen Gong spin_lock_bh(&ab->base_lock);
70129dcf6808SWen Gong memcpy(&ab->new_alpha2, &ev->new_alpha2, 2);
70139dcf6808SWen Gong spin_unlock_bh(&ab->base_lock);
70149dcf6808SWen Gong
7015e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event 11d new cc %c%c\n",
70169dcf6808SWen Gong ab->new_alpha2[0],
70179dcf6808SWen Gong ab->new_alpha2[1]);
70189dcf6808SWen Gong
70199dcf6808SWen Gong kfree(tb);
70209dcf6808SWen Gong
70211f682dc9SWen Gong for (i = 0; i < ab->num_radios; i++) {
70221f682dc9SWen Gong pdev = &ab->pdevs[i];
70231f682dc9SWen Gong ar = pdev->ar;
70241f682dc9SWen Gong ar->state_11d = ATH11K_11D_IDLE;
70251f682dc9SWen Gong complete(&ar->completed_11d_scan);
70261f682dc9SWen Gong }
70271f682dc9SWen Gong
70289dcf6808SWen Gong queue_work(ab->workqueue, &ab->update_11d_work);
70299dcf6808SWen Gong
70309dcf6808SWen Gong return 0;
70319dcf6808SWen Gong }
70329dcf6808SWen Gong
ath11k_wmi_htc_tx_complete(struct ath11k_base * ab,struct sk_buff * skb)7033d5c65159SKalle Valo static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
7034d5c65159SKalle Valo struct sk_buff *skb)
7035d5c65159SKalle Valo {
7036f951380aSP Praneesh struct ath11k_pdev_wmi *wmi = NULL;
7037f951380aSP Praneesh u32 i;
7038f951380aSP Praneesh u8 wmi_ep_count;
7039f951380aSP Praneesh u8 eid;
7040f951380aSP Praneesh
7041f951380aSP Praneesh eid = ATH11K_SKB_CB(skb)->eid;
7042d5c65159SKalle Valo dev_kfree_skb(skb);
7043f951380aSP Praneesh
7044f951380aSP Praneesh if (eid >= ATH11K_HTC_EP_COUNT)
7045f951380aSP Praneesh return;
7046f951380aSP Praneesh
7047f951380aSP Praneesh wmi_ep_count = ab->htc.wmi_ep_count;
7048f951380aSP Praneesh if (wmi_ep_count > ab->hw_params.max_radios)
7049f951380aSP Praneesh return;
7050f951380aSP Praneesh
7051f951380aSP Praneesh for (i = 0; i < ab->htc.wmi_ep_count; i++) {
7052f951380aSP Praneesh if (ab->wmi_ab.wmi[i].eid == eid) {
7053f951380aSP Praneesh wmi = &ab->wmi_ab.wmi[i];
7054f951380aSP Praneesh break;
7055f951380aSP Praneesh }
7056f951380aSP Praneesh }
7057f951380aSP Praneesh
7058f951380aSP Praneesh if (wmi)
7059f951380aSP Praneesh wake_up(&wmi->tx_ce_desc_wq);
7060d5c65159SKalle Valo }
7061d5c65159SKalle Valo
ath11k_reg_is_world_alpha(char * alpha)7062d5c65159SKalle Valo static bool ath11k_reg_is_world_alpha(char *alpha)
7063d5c65159SKalle Valo {
7064f8108250SWen Gong if (alpha[0] == '0' && alpha[1] == '0')
7065f8108250SWen Gong return true;
7066f8108250SWen Gong
7067f8108250SWen Gong if (alpha[0] == 'n' && alpha[1] == 'a')
7068f8108250SWen Gong return true;
7069f8108250SWen Gong
7070f8108250SWen Gong return false;
7071d5c65159SKalle Valo }
7072d5c65159SKalle Valo
ath11k_reg_chan_list_event(struct ath11k_base * ab,struct sk_buff * skb,enum wmi_reg_chan_list_cmd_type id)707391fa00faSAditya Kumar Singh static int ath11k_reg_chan_list_event(struct ath11k_base *ab,
707491fa00faSAditya Kumar Singh struct sk_buff *skb,
707591fa00faSAditya Kumar Singh enum wmi_reg_chan_list_cmd_type id)
7076d5c65159SKalle Valo {
7077d5c65159SKalle Valo struct cur_regulatory_info *reg_info = NULL;
7078d5c65159SKalle Valo struct ieee80211_regdomain *regd = NULL;
7079d5c65159SKalle Valo bool intersect = false;
708091fa00faSAditya Kumar Singh int ret = 0, pdev_idx, i, j;
7081d5c65159SKalle Valo struct ath11k *ar;
7082d5c65159SKalle Valo
7083d5c65159SKalle Valo reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
7084d5c65159SKalle Valo if (!reg_info) {
7085d5c65159SKalle Valo ret = -ENOMEM;
7086d5c65159SKalle Valo goto fallback;
7087d5c65159SKalle Valo }
7088d5c65159SKalle Valo
708991fa00faSAditya Kumar Singh if (id == WMI_REG_CHAN_LIST_CC_ID)
7090d5c65159SKalle Valo ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
709191fa00faSAditya Kumar Singh else
709291fa00faSAditya Kumar Singh ret = ath11k_pull_reg_chan_list_ext_update_ev(ab, skb, reg_info);
709391fa00faSAditya Kumar Singh
7094d5c65159SKalle Valo if (ret) {
7095d5c65159SKalle Valo ath11k_warn(ab, "failed to extract regulatory info from received event\n");
7096d5c65159SKalle Valo goto fallback;
7097d5c65159SKalle Valo }
7098d5c65159SKalle Valo
7099e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event reg chan list id %d", id);
7100e5df1577SKalle Valo
7101d5c65159SKalle Valo if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
7102d5c65159SKalle Valo /* In case of failure to set the requested ctry,
7103d5c65159SKalle Valo * fw retains the current regd. We print a failure info
7104d5c65159SKalle Valo * and return from here.
7105d5c65159SKalle Valo */
7106d5c65159SKalle Valo ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
7107d5c65159SKalle Valo goto mem_free;
7108d5c65159SKalle Valo }
7109d5c65159SKalle Valo
7110d5c65159SKalle Valo pdev_idx = reg_info->phy_id;
7111d5c65159SKalle Valo
711269a0fcf8SSriram R /* Avoid default reg rule updates sent during FW recovery if
711369a0fcf8SSriram R * it is already available
711469a0fcf8SSriram R */
711569a0fcf8SSriram R spin_lock(&ab->base_lock);
711669a0fcf8SSriram R if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) &&
711769a0fcf8SSriram R ab->default_regd[pdev_idx]) {
711869a0fcf8SSriram R spin_unlock(&ab->base_lock);
711969a0fcf8SSriram R goto mem_free;
712069a0fcf8SSriram R }
712169a0fcf8SSriram R spin_unlock(&ab->base_lock);
712269a0fcf8SSriram R
71235f859bc0SCarl Huang if (pdev_idx >= ab->num_radios) {
712484eee3c8SCarl Huang /* Process the event for phy0 only if single_pdev_only
712584eee3c8SCarl Huang * is true. If pdev_idx is valid but not 0, discard the
712684eee3c8SCarl Huang * event. Otherwise, it goes to fallback.
712784eee3c8SCarl Huang */
712884eee3c8SCarl Huang if (ab->hw_params.single_pdev_only &&
712984eee3c8SCarl Huang pdev_idx < ab->hw_params.num_rxmda_per_pdev)
71305f859bc0SCarl Huang goto mem_free;
71315f859bc0SCarl Huang else
7132d5c65159SKalle Valo goto fallback;
71335f859bc0SCarl Huang }
7134d5c65159SKalle Valo
7135d5c65159SKalle Valo /* Avoid multiple overwrites to default regd, during core
7136d5c65159SKalle Valo * stop-start after mac registration.
7137d5c65159SKalle Valo */
7138d5c65159SKalle Valo if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
7139d5c65159SKalle Valo !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
7140d5c65159SKalle Valo (char *)reg_info->alpha2, 2))
7141b5316db2SColin Ian King goto mem_free;
7142d5c65159SKalle Valo
7143d5c65159SKalle Valo /* Intersect new rules with default regd if a new country setting was
7144d5c65159SKalle Valo * requested, i.e a default regd was already set during initialization
7145d5c65159SKalle Valo * and the regd coming from this event has a valid country info.
7146d5c65159SKalle Valo */
7147d5c65159SKalle Valo if (ab->default_regd[pdev_idx] &&
7148d5c65159SKalle Valo !ath11k_reg_is_world_alpha((char *)
7149d5c65159SKalle Valo ab->default_regd[pdev_idx]->alpha2) &&
7150d5c65159SKalle Valo !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
7151d5c65159SKalle Valo intersect = true;
7152d5c65159SKalle Valo
7153d5c65159SKalle Valo regd = ath11k_reg_build_regd(ab, reg_info, intersect);
7154d5c65159SKalle Valo if (!regd) {
7155d5c65159SKalle Valo ath11k_warn(ab, "failed to build regd from reg_info\n");
7156d5c65159SKalle Valo goto fallback;
7157d5c65159SKalle Valo }
7158d5c65159SKalle Valo
7159d5c65159SKalle Valo spin_lock(&ab->base_lock);
71601db2b0d0SSriram R if (ab->default_regd[pdev_idx]) {
71611db2b0d0SSriram R /* The initial rules from FW after WMI Init is to build
71621db2b0d0SSriram R * the default regd. From then on, any rules updated for
71631db2b0d0SSriram R * the pdev could be due to user reg changes.
7164d5c65159SKalle Valo * Free previously built regd before assigning the newly
7165d5c65159SKalle Valo * generated regd to ar. NULL pointer handling will be
7166d5c65159SKalle Valo * taken care by kfree itself.
7167d5c65159SKalle Valo */
7168d5c65159SKalle Valo ar = ab->pdevs[pdev_idx].ar;
7169d5c65159SKalle Valo kfree(ab->new_regd[pdev_idx]);
7170d5c65159SKalle Valo ab->new_regd[pdev_idx] = regd;
7171ed05c7cfSWen Gong queue_work(ab->workqueue, &ar->regd_update_work);
7172d5c65159SKalle Valo } else {
71731db2b0d0SSriram R /* This regd would be applied during mac registration and is
71741db2b0d0SSriram R * held constant throughout for regd intersection purpose
7175d5c65159SKalle Valo */
7176d5c65159SKalle Valo ab->default_regd[pdev_idx] = regd;
7177d5c65159SKalle Valo }
7178d5c65159SKalle Valo ab->dfs_region = reg_info->dfs_region;
7179d5c65159SKalle Valo spin_unlock(&ab->base_lock);
7180d5c65159SKalle Valo
7181d5c65159SKalle Valo goto mem_free;
7182d5c65159SKalle Valo
7183d5c65159SKalle Valo fallback:
7184d5c65159SKalle Valo /* Fallback to older reg (by sending previous country setting
71853926e0c1SManikanta Pubbisetty * again if fw has succeeded and we failed to process here.
7186d5c65159SKalle Valo * The Regdomain should be uniform across driver and fw. Since the
7187d5c65159SKalle Valo * FW has processed the command and sent a success status, we expect
7188d5c65159SKalle Valo * this function to succeed as well. If it doesn't, CTRY needs to be
7189d5c65159SKalle Valo * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
7190d5c65159SKalle Valo */
7191d5c65159SKalle Valo /* TODO: This is rare, but still should also be handled */
7192d5c65159SKalle Valo WARN_ON(1);
7193d5c65159SKalle Valo mem_free:
7194d5c65159SKalle Valo if (reg_info) {
719525e289e1SAditya Kumar Singh kfree(reg_info->reg_rules_2ghz_ptr);
719625e289e1SAditya Kumar Singh kfree(reg_info->reg_rules_5ghz_ptr);
719791fa00faSAditya Kumar Singh if (reg_info->is_ext_reg_event) {
719891fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++)
719991fa00faSAditya Kumar Singh kfree(reg_info->reg_rules_6ghz_ap_ptr[i]);
720091fa00faSAditya Kumar Singh
720191fa00faSAditya Kumar Singh for (j = 0; j < WMI_REG_CURRENT_MAX_AP_TYPE; j++)
720291fa00faSAditya Kumar Singh for (i = 0; i < WMI_REG_MAX_CLIENT_TYPE; i++)
720391fa00faSAditya Kumar Singh kfree(reg_info->reg_rules_6ghz_client_ptr[j][i]);
720491fa00faSAditya Kumar Singh }
7205d5c65159SKalle Valo kfree(reg_info);
7206d5c65159SKalle Valo }
7207d5c65159SKalle Valo return ret;
7208d5c65159SKalle Valo }
7209d5c65159SKalle Valo
ath11k_wmi_tlv_rdy_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)7210d5c65159SKalle Valo static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
7211d5c65159SKalle Valo const void *ptr, void *data)
7212d5c65159SKalle Valo {
7213d5c65159SKalle Valo struct wmi_tlv_rdy_parse *rdy_parse = data;
721421c1b063SMaharaja Kennadyrajan struct wmi_ready_event fixed_param;
7215d5c65159SKalle Valo struct wmi_mac_addr *addr_list;
7216d5c65159SKalle Valo struct ath11k_pdev *pdev;
7217d5c65159SKalle Valo u32 num_mac_addr;
7218d5c65159SKalle Valo int i;
7219d5c65159SKalle Valo
7220d5c65159SKalle Valo switch (tag) {
7221d5c65159SKalle Valo case WMI_TAG_READY_EVENT:
722221c1b063SMaharaja Kennadyrajan memset(&fixed_param, 0, sizeof(fixed_param));
722321c1b063SMaharaja Kennadyrajan memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
722421c1b063SMaharaja Kennadyrajan min_t(u16, sizeof(fixed_param), len));
722521c1b063SMaharaja Kennadyrajan ab->wlan_init_status = fixed_param.ready_event_min.status;
722621c1b063SMaharaja Kennadyrajan rdy_parse->num_extra_mac_addr =
722721c1b063SMaharaja Kennadyrajan fixed_param.ready_event_min.num_extra_mac_addr;
7228d5c65159SKalle Valo
722921c1b063SMaharaja Kennadyrajan ether_addr_copy(ab->mac_addr,
723021c1b063SMaharaja Kennadyrajan fixed_param.ready_event_min.mac_addr.addr);
723121c1b063SMaharaja Kennadyrajan ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum;
7232d5c65159SKalle Valo ab->wmi_ready = true;
7233d5c65159SKalle Valo break;
7234d5c65159SKalle Valo case WMI_TAG_ARRAY_FIXED_STRUCT:
7235d5c65159SKalle Valo addr_list = (struct wmi_mac_addr *)ptr;
7236d5c65159SKalle Valo num_mac_addr = rdy_parse->num_extra_mac_addr;
7237d5c65159SKalle Valo
7238d5c65159SKalle Valo if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
7239d5c65159SKalle Valo break;
7240d5c65159SKalle Valo
7241d5c65159SKalle Valo for (i = 0; i < ab->num_radios; i++) {
7242d5c65159SKalle Valo pdev = &ab->pdevs[i];
7243d5c65159SKalle Valo ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
7244d5c65159SKalle Valo }
7245d5c65159SKalle Valo ab->pdevs_macaddr_valid = true;
7246d5c65159SKalle Valo break;
7247d5c65159SKalle Valo default:
7248d5c65159SKalle Valo break;
7249d5c65159SKalle Valo }
7250d5c65159SKalle Valo
7251d5c65159SKalle Valo return 0;
7252d5c65159SKalle Valo }
7253d5c65159SKalle Valo
ath11k_ready_event(struct ath11k_base * ab,struct sk_buff * skb)7254d5c65159SKalle Valo static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
7255d5c65159SKalle Valo {
7256d5c65159SKalle Valo struct wmi_tlv_rdy_parse rdy_parse = { };
7257d5c65159SKalle Valo int ret;
7258d5c65159SKalle Valo
7259d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7260d5c65159SKalle Valo ath11k_wmi_tlv_rdy_parse, &rdy_parse);
7261d5c65159SKalle Valo if (ret) {
7262d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret);
7263d5c65159SKalle Valo return ret;
7264d5c65159SKalle Valo }
7265d5c65159SKalle Valo
7266e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event ready");
7267e5df1577SKalle Valo
72686bc9d6f7SJohn Crispin complete(&ab->wmi_ab.unified_ready);
7269d5c65159SKalle Valo return 0;
7270d5c65159SKalle Valo }
7271d5c65159SKalle Valo
ath11k_peer_delete_resp_event(struct ath11k_base * ab,struct sk_buff * skb)7272d5c65159SKalle Valo static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
7273d5c65159SKalle Valo {
7274d5c65159SKalle Valo struct wmi_peer_delete_resp_event peer_del_resp;
7275690ace20SRitesh Singh struct ath11k *ar;
7276d5c65159SKalle Valo
7277d5c65159SKalle Valo if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
7278d5c65159SKalle Valo ath11k_warn(ab, "failed to extract peer delete resp");
7279d5c65159SKalle Valo return;
7280d5c65159SKalle Valo }
7281d5c65159SKalle Valo
7282e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event peer delete resp");
7283e5df1577SKalle Valo
7284690ace20SRitesh Singh rcu_read_lock();
7285690ace20SRitesh Singh ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id);
7286690ace20SRitesh Singh if (!ar) {
7287690ace20SRitesh Singh ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d",
7288690ace20SRitesh Singh peer_del_resp.vdev_id);
7289690ace20SRitesh Singh rcu_read_unlock();
7290690ace20SRitesh Singh return;
7291690ace20SRitesh Singh }
7292690ace20SRitesh Singh
7293690ace20SRitesh Singh complete(&ar->peer_delete_done);
7294690ace20SRitesh Singh rcu_read_unlock();
7295690ace20SRitesh Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n",
7296690ace20SRitesh Singh peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr);
7297d5c65159SKalle Valo }
7298d5c65159SKalle Valo
ath11k_vdev_delete_resp_event(struct ath11k_base * ab,struct sk_buff * skb)72993cbbdfbeSRitesh Singh static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab,
73003cbbdfbeSRitesh Singh struct sk_buff *skb)
73013cbbdfbeSRitesh Singh {
73023cbbdfbeSRitesh Singh struct ath11k *ar;
73033cbbdfbeSRitesh Singh u32 vdev_id = 0;
73043cbbdfbeSRitesh Singh
73053cbbdfbeSRitesh Singh if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) {
73063cbbdfbeSRitesh Singh ath11k_warn(ab, "failed to extract vdev delete resp");
73073cbbdfbeSRitesh Singh return;
73083cbbdfbeSRitesh Singh }
73093cbbdfbeSRitesh Singh
73103cbbdfbeSRitesh Singh rcu_read_lock();
73113cbbdfbeSRitesh Singh ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
73123cbbdfbeSRitesh Singh if (!ar) {
73133cbbdfbeSRitesh Singh ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d",
73143cbbdfbeSRitesh Singh vdev_id);
73153cbbdfbeSRitesh Singh rcu_read_unlock();
73163cbbdfbeSRitesh Singh return;
73173cbbdfbeSRitesh Singh }
73183cbbdfbeSRitesh Singh
73193cbbdfbeSRitesh Singh complete(&ar->vdev_delete_done);
73203cbbdfbeSRitesh Singh
73213cbbdfbeSRitesh Singh rcu_read_unlock();
73223cbbdfbeSRitesh Singh
7323e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event vdev delete resp for vdev id %d\n",
73243cbbdfbeSRitesh Singh vdev_id);
73253cbbdfbeSRitesh Singh }
73263cbbdfbeSRitesh Singh
ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)7327d5c65159SKalle Valo static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
7328d5c65159SKalle Valo {
7329d5c65159SKalle Valo switch (vdev_resp_status) {
7330d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
7331d5c65159SKalle Valo return "invalid vdev id";
7332d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
7333d5c65159SKalle Valo return "not supported";
7334d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
7335d5c65159SKalle Valo return "dfs violation";
7336d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
7337d5c65159SKalle Valo return "invalid regdomain";
7338d5c65159SKalle Valo default:
7339d5c65159SKalle Valo return "unknown";
7340d5c65159SKalle Valo }
7341d5c65159SKalle Valo }
7342d5c65159SKalle Valo
ath11k_vdev_start_resp_event(struct ath11k_base * ab,struct sk_buff * skb)7343d5c65159SKalle Valo static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
7344d5c65159SKalle Valo {
7345d5c65159SKalle Valo struct wmi_vdev_start_resp_event vdev_start_resp;
7346d5c65159SKalle Valo struct ath11k *ar;
7347d5c65159SKalle Valo u32 status;
7348d5c65159SKalle Valo
7349d5c65159SKalle Valo if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
7350d5c65159SKalle Valo ath11k_warn(ab, "failed to extract vdev start resp");
7351d5c65159SKalle Valo return;
7352d5c65159SKalle Valo }
7353d5c65159SKalle Valo
7354e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event start resp event");
7355e5df1577SKalle Valo
7356d5c65159SKalle Valo rcu_read_lock();
7357d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
7358d5c65159SKalle Valo if (!ar) {
7359d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
7360d5c65159SKalle Valo vdev_start_resp.vdev_id);
7361d5c65159SKalle Valo rcu_read_unlock();
7362d5c65159SKalle Valo return;
7363d5c65159SKalle Valo }
7364d5c65159SKalle Valo
7365d5c65159SKalle Valo ar->last_wmi_vdev_start_status = 0;
7366d5c65159SKalle Valo
7367d5c65159SKalle Valo status = vdev_start_resp.status;
7368d5c65159SKalle Valo
7369d5c65159SKalle Valo if (WARN_ON_ONCE(status)) {
7370d5c65159SKalle Valo ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
7371d5c65159SKalle Valo status, ath11k_wmi_vdev_resp_print(status));
7372d5c65159SKalle Valo ar->last_wmi_vdev_start_status = status;
7373d5c65159SKalle Valo }
7374d5c65159SKalle Valo
7375d5c65159SKalle Valo complete(&ar->vdev_setup_done);
7376d5c65159SKalle Valo
7377d5c65159SKalle Valo rcu_read_unlock();
7378d5c65159SKalle Valo
7379d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
7380d5c65159SKalle Valo vdev_start_resp.vdev_id);
7381d5c65159SKalle Valo }
7382d5c65159SKalle Valo
ath11k_bcn_tx_status_event(struct ath11k_base * ab,struct sk_buff * skb)7383d5c65159SKalle Valo static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
7384d5c65159SKalle Valo {
7385886433a9SJohn Crispin struct ath11k_vif *arvif;
7386d5c65159SKalle Valo u32 vdev_id, tx_status;
7387d5c65159SKalle Valo
7388d5c65159SKalle Valo if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
7389d5c65159SKalle Valo &vdev_id, &tx_status) != 0) {
7390d5c65159SKalle Valo ath11k_warn(ab, "failed to extract bcn tx status");
7391d5c65159SKalle Valo return;
7392d5c65159SKalle Valo }
7393886433a9SJohn Crispin
7394e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event offload bcn tx status");
7395e5df1577SKalle Valo
739601e782c8SWen Gong rcu_read_lock();
7397886433a9SJohn Crispin arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_id);
7398886433a9SJohn Crispin if (!arvif) {
7399886433a9SJohn Crispin ath11k_warn(ab, "invalid vdev id %d in bcn_tx_status",
7400886433a9SJohn Crispin vdev_id);
740101e782c8SWen Gong rcu_read_unlock();
7402886433a9SJohn Crispin return;
7403886433a9SJohn Crispin }
7404886433a9SJohn Crispin ath11k_mac_bcn_tx_event(arvif);
740501e782c8SWen Gong rcu_read_unlock();
7406d5c65159SKalle Valo }
7407d5c65159SKalle Valo
ath11k_wmi_event_peer_sta_ps_state_chg(struct ath11k_base * ab,struct sk_buff * skb)7408710a95f9SVenkateswara Naralasetty static void ath11k_wmi_event_peer_sta_ps_state_chg(struct ath11k_base *ab,
7409710a95f9SVenkateswara Naralasetty struct sk_buff *skb)
7410710a95f9SVenkateswara Naralasetty {
7411710a95f9SVenkateswara Naralasetty const struct wmi_peer_sta_ps_state_chg_event *ev;
7412710a95f9SVenkateswara Naralasetty struct ieee80211_sta *sta;
7413710a95f9SVenkateswara Naralasetty struct ath11k_peer *peer;
7414710a95f9SVenkateswara Naralasetty struct ath11k *ar;
7415710a95f9SVenkateswara Naralasetty struct ath11k_sta *arsta;
7416710a95f9SVenkateswara Naralasetty const void **tb;
7417710a95f9SVenkateswara Naralasetty enum ath11k_wmi_peer_ps_state peer_previous_ps_state;
7418710a95f9SVenkateswara Naralasetty int ret;
7419710a95f9SVenkateswara Naralasetty
7420710a95f9SVenkateswara Naralasetty tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7421710a95f9SVenkateswara Naralasetty if (IS_ERR(tb)) {
7422710a95f9SVenkateswara Naralasetty ret = PTR_ERR(tb);
7423710a95f9SVenkateswara Naralasetty ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7424710a95f9SVenkateswara Naralasetty return;
7425710a95f9SVenkateswara Naralasetty }
7426710a95f9SVenkateswara Naralasetty
7427710a95f9SVenkateswara Naralasetty ev = tb[WMI_TAG_PEER_STA_PS_STATECHANGE_EVENT];
7428710a95f9SVenkateswara Naralasetty if (!ev) {
7429710a95f9SVenkateswara Naralasetty ath11k_warn(ab, "failed to fetch sta ps change ev");
7430710a95f9SVenkateswara Naralasetty kfree(tb);
7431710a95f9SVenkateswara Naralasetty return;
7432710a95f9SVenkateswara Naralasetty }
7433710a95f9SVenkateswara Naralasetty
7434710a95f9SVenkateswara Naralasetty ath11k_dbg(ab, ATH11K_DBG_WMI,
7435e5df1577SKalle Valo "event peer sta ps change ev addr %pM state %u sup_bitmap %x ps_valid %u ts %u\n",
7436710a95f9SVenkateswara Naralasetty ev->peer_macaddr.addr, ev->peer_ps_state,
7437710a95f9SVenkateswara Naralasetty ev->ps_supported_bitmap, ev->peer_ps_valid,
7438710a95f9SVenkateswara Naralasetty ev->peer_ps_timestamp);
7439710a95f9SVenkateswara Naralasetty
7440710a95f9SVenkateswara Naralasetty rcu_read_lock();
7441710a95f9SVenkateswara Naralasetty
7442710a95f9SVenkateswara Naralasetty spin_lock_bh(&ab->base_lock);
7443710a95f9SVenkateswara Naralasetty
7444710a95f9SVenkateswara Naralasetty peer = ath11k_peer_find_by_addr(ab, ev->peer_macaddr.addr);
7445710a95f9SVenkateswara Naralasetty
7446710a95f9SVenkateswara Naralasetty if (!peer) {
7447710a95f9SVenkateswara Naralasetty spin_unlock_bh(&ab->base_lock);
7448710a95f9SVenkateswara Naralasetty ath11k_warn(ab, "peer not found %pM\n", ev->peer_macaddr.addr);
7449710a95f9SVenkateswara Naralasetty goto exit;
7450710a95f9SVenkateswara Naralasetty }
7451710a95f9SVenkateswara Naralasetty
7452710a95f9SVenkateswara Naralasetty ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id);
7453710a95f9SVenkateswara Naralasetty
7454710a95f9SVenkateswara Naralasetty if (!ar) {
7455710a95f9SVenkateswara Naralasetty spin_unlock_bh(&ab->base_lock);
7456710a95f9SVenkateswara Naralasetty ath11k_warn(ab, "invalid vdev id in peer sta ps state change ev %d",
7457710a95f9SVenkateswara Naralasetty peer->vdev_id);
7458710a95f9SVenkateswara Naralasetty
7459710a95f9SVenkateswara Naralasetty goto exit;
7460710a95f9SVenkateswara Naralasetty }
7461710a95f9SVenkateswara Naralasetty
7462710a95f9SVenkateswara Naralasetty sta = peer->sta;
7463710a95f9SVenkateswara Naralasetty
7464710a95f9SVenkateswara Naralasetty spin_unlock_bh(&ab->base_lock);
7465710a95f9SVenkateswara Naralasetty
7466710a95f9SVenkateswara Naralasetty if (!sta) {
7467710a95f9SVenkateswara Naralasetty ath11k_warn(ab, "failed to find station entry %pM\n",
7468710a95f9SVenkateswara Naralasetty ev->peer_macaddr.addr);
7469710a95f9SVenkateswara Naralasetty goto exit;
7470710a95f9SVenkateswara Naralasetty }
7471710a95f9SVenkateswara Naralasetty
7472710a95f9SVenkateswara Naralasetty arsta = (struct ath11k_sta *)sta->drv_priv;
7473710a95f9SVenkateswara Naralasetty
7474710a95f9SVenkateswara Naralasetty spin_lock_bh(&ar->data_lock);
7475710a95f9SVenkateswara Naralasetty
7476710a95f9SVenkateswara Naralasetty peer_previous_ps_state = arsta->peer_ps_state;
7477710a95f9SVenkateswara Naralasetty arsta->peer_ps_state = ev->peer_ps_state;
7478710a95f9SVenkateswara Naralasetty arsta->peer_current_ps_valid = !!ev->peer_ps_valid;
7479710a95f9SVenkateswara Naralasetty
7480710a95f9SVenkateswara Naralasetty if (test_bit(WMI_TLV_SERVICE_PEER_POWER_SAVE_DURATION_SUPPORT,
7481710a95f9SVenkateswara Naralasetty ar->ab->wmi_ab.svc_map)) {
7482710a95f9SVenkateswara Naralasetty if (!(ev->ps_supported_bitmap & WMI_PEER_PS_VALID) ||
7483710a95f9SVenkateswara Naralasetty !(ev->ps_supported_bitmap & WMI_PEER_PS_STATE_TIMESTAMP) ||
7484710a95f9SVenkateswara Naralasetty !ev->peer_ps_valid)
7485710a95f9SVenkateswara Naralasetty goto out;
7486710a95f9SVenkateswara Naralasetty
7487710a95f9SVenkateswara Naralasetty if (arsta->peer_ps_state == WMI_PEER_PS_STATE_ON) {
7488710a95f9SVenkateswara Naralasetty arsta->ps_start_time = ev->peer_ps_timestamp;
7489710a95f9SVenkateswara Naralasetty arsta->ps_start_jiffies = jiffies;
7490710a95f9SVenkateswara Naralasetty } else if (arsta->peer_ps_state == WMI_PEER_PS_STATE_OFF &&
7491710a95f9SVenkateswara Naralasetty peer_previous_ps_state == WMI_PEER_PS_STATE_ON) {
7492710a95f9SVenkateswara Naralasetty arsta->ps_total_duration = arsta->ps_total_duration +
7493710a95f9SVenkateswara Naralasetty (ev->peer_ps_timestamp - arsta->ps_start_time);
7494710a95f9SVenkateswara Naralasetty }
7495710a95f9SVenkateswara Naralasetty
7496710a95f9SVenkateswara Naralasetty if (ar->ps_timekeeper_enable)
7497710a95f9SVenkateswara Naralasetty trace_ath11k_ps_timekeeper(ar, ev->peer_macaddr.addr,
7498710a95f9SVenkateswara Naralasetty ev->peer_ps_timestamp,
7499710a95f9SVenkateswara Naralasetty arsta->peer_ps_state);
7500710a95f9SVenkateswara Naralasetty }
7501710a95f9SVenkateswara Naralasetty
7502710a95f9SVenkateswara Naralasetty out:
7503710a95f9SVenkateswara Naralasetty spin_unlock_bh(&ar->data_lock);
7504710a95f9SVenkateswara Naralasetty exit:
7505710a95f9SVenkateswara Naralasetty rcu_read_unlock();
7506710a95f9SVenkateswara Naralasetty kfree(tb);
7507710a95f9SVenkateswara Naralasetty }
7508710a95f9SVenkateswara Naralasetty
ath11k_vdev_stopped_event(struct ath11k_base * ab,struct sk_buff * skb)7509d5c65159SKalle Valo static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
7510d5c65159SKalle Valo {
7511d5c65159SKalle Valo struct ath11k *ar;
7512d5c65159SKalle Valo u32 vdev_id = 0;
7513d5c65159SKalle Valo
7514d5c65159SKalle Valo if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
7515d5c65159SKalle Valo ath11k_warn(ab, "failed to extract vdev stopped event");
7516d5c65159SKalle Valo return;
7517d5c65159SKalle Valo }
7518d5c65159SKalle Valo
7519e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event vdev stopped");
7520e5df1577SKalle Valo
7521d5c65159SKalle Valo rcu_read_lock();
7522fae0385bSRitesh Singh ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7523d5c65159SKalle Valo if (!ar) {
7524d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
7525d5c65159SKalle Valo vdev_id);
7526d5c65159SKalle Valo rcu_read_unlock();
7527d5c65159SKalle Valo return;
7528d5c65159SKalle Valo }
7529d5c65159SKalle Valo
7530d5c65159SKalle Valo complete(&ar->vdev_setup_done);
7531d5c65159SKalle Valo
7532d5c65159SKalle Valo rcu_read_unlock();
7533d5c65159SKalle Valo
7534d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
7535d5c65159SKalle Valo }
7536d5c65159SKalle Valo
ath11k_mgmt_rx_event(struct ath11k_base * ab,struct sk_buff * skb)7537d5c65159SKalle Valo static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
7538d5c65159SKalle Valo {
7539d5c65159SKalle Valo struct mgmt_rx_event_params rx_ev = {0};
7540d5c65159SKalle Valo struct ath11k *ar;
7541d5c65159SKalle Valo struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
7542d5c65159SKalle Valo struct ieee80211_hdr *hdr;
7543d5c65159SKalle Valo u16 fc;
7544d5c65159SKalle Valo struct ieee80211_supported_band *sband;
7545d5c65159SKalle Valo
7546d5c65159SKalle Valo if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
7547d5c65159SKalle Valo ath11k_warn(ab, "failed to extract mgmt rx event");
7548d5c65159SKalle Valo dev_kfree_skb(skb);
7549d5c65159SKalle Valo return;
7550d5c65159SKalle Valo }
7551d5c65159SKalle Valo
7552d5c65159SKalle Valo memset(status, 0, sizeof(*status));
7553d5c65159SKalle Valo
7554e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT, "event mgmt rx status %08x\n",
7555d5c65159SKalle Valo rx_ev.status);
7556d5c65159SKalle Valo
7557d5c65159SKalle Valo rcu_read_lock();
7558d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
7559d5c65159SKalle Valo
7560d5c65159SKalle Valo if (!ar) {
7561d5c65159SKalle Valo ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
7562d5c65159SKalle Valo rx_ev.pdev_id);
7563d5c65159SKalle Valo dev_kfree_skb(skb);
7564d5c65159SKalle Valo goto exit;
7565d5c65159SKalle Valo }
7566d5c65159SKalle Valo
7567d5c65159SKalle Valo if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
7568d5c65159SKalle Valo (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
7569d5c65159SKalle Valo WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
7570d5c65159SKalle Valo dev_kfree_skb(skb);
7571d5c65159SKalle Valo goto exit;
7572d5c65159SKalle Valo }
7573d5c65159SKalle Valo
7574d5c65159SKalle Valo if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
7575d5c65159SKalle Valo status->flag |= RX_FLAG_MMIC_ERROR;
7576d5c65159SKalle Valo
75779d6ae1f5SPradeep Kumar Chitrapu if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ &&
75789d6ae1f5SPradeep Kumar Chitrapu rx_ev.chan_freq <= ATH11K_MAX_6G_FREQ) {
75795dcf42f8SPradeep Kumar Chitrapu status->band = NL80211_BAND_6GHZ;
75809d6ae1f5SPradeep Kumar Chitrapu status->freq = rx_ev.chan_freq;
75815dcf42f8SPradeep Kumar Chitrapu } else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
7582d5c65159SKalle Valo status->band = NL80211_BAND_2GHZ;
7583d5c65159SKalle Valo } else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
7584d5c65159SKalle Valo status->band = NL80211_BAND_5GHZ;
7585d5c65159SKalle Valo } else {
7586d5c65159SKalle Valo /* Shouldn't happen unless list of advertised channels to
7587d5c65159SKalle Valo * mac80211 has been changed.
7588d5c65159SKalle Valo */
7589d5c65159SKalle Valo WARN_ON_ONCE(1);
7590d5c65159SKalle Valo dev_kfree_skb(skb);
7591d5c65159SKalle Valo goto exit;
7592d5c65159SKalle Valo }
7593d5c65159SKalle Valo
759422eeadcdSPradeep Kumar Chitrapu if (rx_ev.phy_mode == MODE_11B &&
759522eeadcdSPradeep Kumar Chitrapu (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
7596d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
7597fc3b984aSKalle Valo "mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
7598d5c65159SKalle Valo
7599d5c65159SKalle Valo sband = &ar->mac.sbands[status->band];
7600d5c65159SKalle Valo
76019d6ae1f5SPradeep Kumar Chitrapu if (status->band != NL80211_BAND_6GHZ)
7602d5c65159SKalle Valo status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
7603d5c65159SKalle Valo status->band);
76049d6ae1f5SPradeep Kumar Chitrapu
7605d5c65159SKalle Valo status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
7606d5c65159SKalle Valo status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
7607d5c65159SKalle Valo
7608d5c65159SKalle Valo hdr = (struct ieee80211_hdr *)skb->data;
7609d5c65159SKalle Valo fc = le16_to_cpu(hdr->frame_control);
7610d5c65159SKalle Valo
7611d5c65159SKalle Valo /* Firmware is guaranteed to report all essential management frames via
7612d5c65159SKalle Valo * WMI while it can deliver some extra via HTT. Since there can be
7613d5c65159SKalle Valo * duplicates split the reporting wrt monitor/sniffing.
7614d5c65159SKalle Valo */
7615d5c65159SKalle Valo status->flag |= RX_FLAG_SKIP_MONITOR;
7616d5c65159SKalle Valo
7617d5c65159SKalle Valo /* In case of PMF, FW delivers decrypted frames with Protected Bit set.
7618d5c65159SKalle Valo * Don't clear that. Also, FW delivers broadcast management frames
7619d5c65159SKalle Valo * (ex: group privacy action frames in mesh) as encrypted payload.
7620d5c65159SKalle Valo */
7621d5c65159SKalle Valo if (ieee80211_has_protected(hdr->frame_control) &&
7622d5c65159SKalle Valo !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
7623d5c65159SKalle Valo status->flag |= RX_FLAG_DECRYPTED;
7624d5c65159SKalle Valo
7625d5c65159SKalle Valo if (!ieee80211_is_robust_mgmt_frame(skb)) {
7626d5c65159SKalle Valo status->flag |= RX_FLAG_IV_STRIPPED |
7627d5c65159SKalle Valo RX_FLAG_MMIC_STRIPPED;
7628d5c65159SKalle Valo hdr->frame_control = __cpu_to_le16(fc &
7629d5c65159SKalle Valo ~IEEE80211_FCTL_PROTECTED);
7630d5c65159SKalle Valo }
7631d5c65159SKalle Valo }
7632d5c65159SKalle Valo
763326f69792SLavanya Suresh if (ieee80211_is_beacon(hdr->frame_control))
763426f69792SLavanya Suresh ath11k_mac_handle_beacon(ar, skb);
7635d5c65159SKalle Valo
7636d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT,
7637cf036c41SKalle Valo "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
7638d5c65159SKalle Valo skb, skb->len,
7639d5c65159SKalle Valo fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
7640d5c65159SKalle Valo
7641d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT,
7642d5c65159SKalle Valo "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
7643d5c65159SKalle Valo status->freq, status->band, status->signal,
7644d5c65159SKalle Valo status->rate_idx);
7645d5c65159SKalle Valo
7646d5c65159SKalle Valo ieee80211_rx_ni(ar->hw, skb);
7647d5c65159SKalle Valo
7648d5c65159SKalle Valo exit:
7649d5c65159SKalle Valo rcu_read_unlock();
7650d5c65159SKalle Valo }
7651d5c65159SKalle Valo
ath11k_mgmt_tx_compl_event(struct ath11k_base * ab,struct sk_buff * skb)7652d5c65159SKalle Valo static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
7653d5c65159SKalle Valo {
7654d5c65159SKalle Valo struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
7655d5c65159SKalle Valo struct ath11k *ar;
7656d5c65159SKalle Valo
7657d5c65159SKalle Valo if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
7658d5c65159SKalle Valo ath11k_warn(ab, "failed to extract mgmt tx compl event");
7659d5c65159SKalle Valo return;
7660d5c65159SKalle Valo }
7661d5c65159SKalle Valo
7662d5c65159SKalle Valo rcu_read_lock();
7663d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
7664d5c65159SKalle Valo if (!ar) {
7665d5c65159SKalle Valo ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
7666d5c65159SKalle Valo tx_compl_param.pdev_id);
7667d5c65159SKalle Valo goto exit;
7668d5c65159SKalle Valo }
7669d5c65159SKalle Valo
767001c6c9fcSAbinaya Kalaiselvan wmi_process_mgmt_tx_comp(ar, &tx_compl_param);
7671d5c65159SKalle Valo
7672d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT,
7673e5df1577SKalle Valo "event mgmt tx compl ev pdev_id %d, desc_id %d, status %d ack_rssi %d",
7674d5c65159SKalle Valo tx_compl_param.pdev_id, tx_compl_param.desc_id,
767501c6c9fcSAbinaya Kalaiselvan tx_compl_param.status, tx_compl_param.ack_rssi);
7676d5c65159SKalle Valo
7677d5c65159SKalle Valo exit:
7678d5c65159SKalle Valo rcu_read_unlock();
7679d5c65159SKalle Valo }
7680d5c65159SKalle Valo
ath11k_get_ar_on_scan_state(struct ath11k_base * ab,u32 vdev_id,enum ath11k_scan_state state)7681c677d4b1SWen Gong static struct ath11k *ath11k_get_ar_on_scan_state(struct ath11k_base *ab,
7682c677d4b1SWen Gong u32 vdev_id,
7683c677d4b1SWen Gong enum ath11k_scan_state state)
7684d5c65159SKalle Valo {
7685d5c65159SKalle Valo int i;
7686d5c65159SKalle Valo struct ath11k_pdev *pdev;
7687d5c65159SKalle Valo struct ath11k *ar;
7688d5c65159SKalle Valo
7689d5c65159SKalle Valo for (i = 0; i < ab->num_radios; i++) {
7690d5c65159SKalle Valo pdev = rcu_dereference(ab->pdevs_active[i]);
7691d5c65159SKalle Valo if (pdev && pdev->ar) {
7692d5c65159SKalle Valo ar = pdev->ar;
7693d5c65159SKalle Valo
7694d5c65159SKalle Valo spin_lock_bh(&ar->data_lock);
7695c677d4b1SWen Gong if (ar->scan.state == state &&
7696d5c65159SKalle Valo ar->scan.vdev_id == vdev_id) {
7697d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock);
7698d5c65159SKalle Valo return ar;
7699d5c65159SKalle Valo }
7700d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock);
7701d5c65159SKalle Valo }
7702d5c65159SKalle Valo }
7703d5c65159SKalle Valo return NULL;
7704d5c65159SKalle Valo }
7705d5c65159SKalle Valo
ath11k_scan_event(struct ath11k_base * ab,struct sk_buff * skb)7706d5c65159SKalle Valo static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
7707d5c65159SKalle Valo {
7708d5c65159SKalle Valo struct ath11k *ar;
7709d5c65159SKalle Valo struct wmi_scan_event scan_ev = {0};
7710d5c65159SKalle Valo
7711d5c65159SKalle Valo if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
7712d5c65159SKalle Valo ath11k_warn(ab, "failed to extract scan event");
7713d5c65159SKalle Valo return;
7714d5c65159SKalle Valo }
7715d5c65159SKalle Valo
7716d5c65159SKalle Valo rcu_read_lock();
7717d5c65159SKalle Valo
7718d5c65159SKalle Valo /* In case the scan was cancelled, ex. during interface teardown,
7719d5c65159SKalle Valo * the interface will not be found in active interfaces.
7720d5c65159SKalle Valo * Rather, in such scenarios, iterate over the active pdev's to
7721d5c65159SKalle Valo * search 'ar' if the corresponding 'ar' scan is ABORTING and the
7722d5c65159SKalle Valo * aborting scan's vdev id matches this event info.
7723d5c65159SKalle Valo */
7724d5c65159SKalle Valo if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
7725c677d4b1SWen Gong scan_ev.reason == WMI_SCAN_REASON_CANCELLED) {
7726c677d4b1SWen Gong ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7727c677d4b1SWen Gong ATH11K_SCAN_ABORTING);
7728c677d4b1SWen Gong if (!ar)
7729c677d4b1SWen Gong ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
7730c677d4b1SWen Gong ATH11K_SCAN_RUNNING);
7731c677d4b1SWen Gong } else {
7732d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
7733c677d4b1SWen Gong }
7734d5c65159SKalle Valo
7735d5c65159SKalle Valo if (!ar) {
7736d5c65159SKalle Valo ath11k_warn(ab, "Received scan event for unknown vdev");
7737d5c65159SKalle Valo rcu_read_unlock();
7738d5c65159SKalle Valo return;
7739d5c65159SKalle Valo }
7740d5c65159SKalle Valo
7741d5c65159SKalle Valo spin_lock_bh(&ar->data_lock);
7742d5c65159SKalle Valo
7743d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
7744e5df1577SKalle Valo "event scan %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
7745d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
7746d5c65159SKalle Valo scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
7747d5c65159SKalle Valo scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
7748d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), ar->scan.state);
7749d5c65159SKalle Valo
7750d5c65159SKalle Valo switch (scan_ev.event_type) {
7751d5c65159SKalle Valo case WMI_SCAN_EVENT_STARTED:
7752d5c65159SKalle Valo ath11k_wmi_event_scan_started(ar);
7753d5c65159SKalle Valo break;
7754d5c65159SKalle Valo case WMI_SCAN_EVENT_COMPLETED:
7755d5c65159SKalle Valo ath11k_wmi_event_scan_completed(ar);
7756d5c65159SKalle Valo break;
7757d5c65159SKalle Valo case WMI_SCAN_EVENT_BSS_CHANNEL:
7758d5c65159SKalle Valo ath11k_wmi_event_scan_bss_chan(ar);
7759d5c65159SKalle Valo break;
7760d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN:
7761d5c65159SKalle Valo ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
7762d5c65159SKalle Valo break;
7763d5c65159SKalle Valo case WMI_SCAN_EVENT_START_FAILED:
7764d5c65159SKalle Valo ath11k_warn(ab, "received scan start failure event\n");
7765d5c65159SKalle Valo ath11k_wmi_event_scan_start_failed(ar);
7766d5c65159SKalle Valo break;
7767d5c65159SKalle Valo case WMI_SCAN_EVENT_DEQUEUED:
7768441b3b59SWen Gong __ath11k_mac_scan_finish(ar);
7769441b3b59SWen Gong break;
7770d5c65159SKalle Valo case WMI_SCAN_EVENT_PREEMPTED:
7771d5c65159SKalle Valo case WMI_SCAN_EVENT_RESTARTED:
7772d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
7773d5c65159SKalle Valo default:
7774d5c65159SKalle Valo break;
7775d5c65159SKalle Valo }
7776d5c65159SKalle Valo
7777d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock);
7778d5c65159SKalle Valo
7779d5c65159SKalle Valo rcu_read_unlock();
7780d5c65159SKalle Valo }
7781d5c65159SKalle Valo
ath11k_peer_sta_kickout_event(struct ath11k_base * ab,struct sk_buff * skb)7782d5c65159SKalle Valo static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
7783d5c65159SKalle Valo {
7784d5c65159SKalle Valo struct wmi_peer_sta_kickout_arg arg = {};
7785d5c65159SKalle Valo struct ieee80211_sta *sta;
7786d5c65159SKalle Valo struct ath11k_peer *peer;
7787d5c65159SKalle Valo struct ath11k *ar;
77884c375743SKarthikeyan Periyasamy u32 vdev_id;
7789d5c65159SKalle Valo
7790d5c65159SKalle Valo if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
7791d5c65159SKalle Valo ath11k_warn(ab, "failed to extract peer sta kickout event");
7792d5c65159SKalle Valo return;
7793d5c65159SKalle Valo }
7794d5c65159SKalle Valo
7795d5c65159SKalle Valo rcu_read_lock();
7796d5c65159SKalle Valo
7797d5c65159SKalle Valo spin_lock_bh(&ab->base_lock);
7798d5c65159SKalle Valo
7799d5c65159SKalle Valo peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
7800d5c65159SKalle Valo
7801d5c65159SKalle Valo if (!peer) {
7802d5c65159SKalle Valo ath11k_warn(ab, "peer not found %pM\n",
7803d5c65159SKalle Valo arg.mac_addr);
78044c375743SKarthikeyan Periyasamy spin_unlock_bh(&ab->base_lock);
7805d5c65159SKalle Valo goto exit;
7806d5c65159SKalle Valo }
7807d5c65159SKalle Valo
78084c375743SKarthikeyan Periyasamy vdev_id = peer->vdev_id;
78094c375743SKarthikeyan Periyasamy
78104c375743SKarthikeyan Periyasamy spin_unlock_bh(&ab->base_lock);
78114c375743SKarthikeyan Periyasamy
78124c375743SKarthikeyan Periyasamy ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7813d5c65159SKalle Valo if (!ar) {
7814d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
7815d5c65159SKalle Valo peer->vdev_id);
7816d5c65159SKalle Valo goto exit;
7817d5c65159SKalle Valo }
7818d5c65159SKalle Valo
7819d5c65159SKalle Valo sta = ieee80211_find_sta_by_ifaddr(ar->hw,
7820d5c65159SKalle Valo arg.mac_addr, NULL);
7821d5c65159SKalle Valo if (!sta) {
7822d5c65159SKalle Valo ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
7823d5c65159SKalle Valo arg.mac_addr);
7824d5c65159SKalle Valo goto exit;
7825d5c65159SKalle Valo }
7826d5c65159SKalle Valo
7827e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event peer sta kickout %pM",
7828d5c65159SKalle Valo arg.mac_addr);
7829d5c65159SKalle Valo
7830d5c65159SKalle Valo ieee80211_report_low_ack(sta, 10);
7831d5c65159SKalle Valo
7832d5c65159SKalle Valo exit:
7833d5c65159SKalle Valo rcu_read_unlock();
7834d5c65159SKalle Valo }
7835d5c65159SKalle Valo
ath11k_roam_event(struct ath11k_base * ab,struct sk_buff * skb)7836d5c65159SKalle Valo static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
7837d5c65159SKalle Valo {
7838d5c65159SKalle Valo struct wmi_roam_event roam_ev = {};
7839d5c65159SKalle Valo struct ath11k *ar;
7840d5c65159SKalle Valo
7841d5c65159SKalle Valo if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
7842d5c65159SKalle Valo ath11k_warn(ab, "failed to extract roam event");
7843d5c65159SKalle Valo return;
7844d5c65159SKalle Valo }
7845d5c65159SKalle Valo
7846d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
7847e5df1577SKalle Valo "event roam vdev %u reason 0x%08x rssi %d\n",
7848d5c65159SKalle Valo roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
7849d5c65159SKalle Valo
7850d5c65159SKalle Valo rcu_read_lock();
7851d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
7852d5c65159SKalle Valo if (!ar) {
7853d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in roam ev %d",
7854d5c65159SKalle Valo roam_ev.vdev_id);
7855d5c65159SKalle Valo rcu_read_unlock();
7856d5c65159SKalle Valo return;
7857d5c65159SKalle Valo }
7858d5c65159SKalle Valo
7859d5c65159SKalle Valo if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
7860d5c65159SKalle Valo ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
7861d5c65159SKalle Valo roam_ev.reason, roam_ev.vdev_id);
7862d5c65159SKalle Valo
7863d5c65159SKalle Valo switch (roam_ev.reason) {
7864d5c65159SKalle Valo case WMI_ROAM_REASON_BEACON_MISS:
786526f69792SLavanya Suresh ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id);
7866d5c65159SKalle Valo break;
7867d5c65159SKalle Valo case WMI_ROAM_REASON_BETTER_AP:
7868d5c65159SKalle Valo case WMI_ROAM_REASON_LOW_RSSI:
7869d5c65159SKalle Valo case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
7870d5c65159SKalle Valo case WMI_ROAM_REASON_HO_FAILED:
7871d5c65159SKalle Valo ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
7872d5c65159SKalle Valo roam_ev.reason, roam_ev.vdev_id);
7873d5c65159SKalle Valo break;
7874d5c65159SKalle Valo }
7875d5c65159SKalle Valo
7876d5c65159SKalle Valo rcu_read_unlock();
7877d5c65159SKalle Valo }
7878d5c65159SKalle Valo
ath11k_chan_info_event(struct ath11k_base * ab,struct sk_buff * skb)7879d5c65159SKalle Valo static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7880d5c65159SKalle Valo {
7881d5c65159SKalle Valo struct wmi_chan_info_event ch_info_ev = {0};
7882d5c65159SKalle Valo struct ath11k *ar;
7883d5c65159SKalle Valo struct survey_info *survey;
7884d5c65159SKalle Valo int idx;
7885d5c65159SKalle Valo /* HW channel counters frequency value in hertz */
7886d5c65159SKalle Valo u32 cc_freq_hz = ab->cc_freq_hz;
7887d5c65159SKalle Valo
7888d5c65159SKalle Valo if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
7889d5c65159SKalle Valo ath11k_warn(ab, "failed to extract chan info event");
7890d5c65159SKalle Valo return;
7891d5c65159SKalle Valo }
7892d5c65159SKalle Valo
7893d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
7894e5df1577SKalle Valo "event chan info vdev_id %d err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d mac_clk_mhz %d\n",
7895d5c65159SKalle Valo ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
7896d5c65159SKalle Valo ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
7897d5c65159SKalle Valo ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
7898d5c65159SKalle Valo ch_info_ev.mac_clk_mhz);
7899d5c65159SKalle Valo
7900d5c65159SKalle Valo if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
7901d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
7902d5c65159SKalle Valo return;
7903d5c65159SKalle Valo }
7904d5c65159SKalle Valo
7905d5c65159SKalle Valo rcu_read_lock();
7906d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
7907d5c65159SKalle Valo if (!ar) {
7908d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in chan info ev %d",
7909d5c65159SKalle Valo ch_info_ev.vdev_id);
7910d5c65159SKalle Valo rcu_read_unlock();
7911d5c65159SKalle Valo return;
7912d5c65159SKalle Valo }
7913d5c65159SKalle Valo spin_lock_bh(&ar->data_lock);
7914d5c65159SKalle Valo
7915d5c65159SKalle Valo switch (ar->scan.state) {
7916d5c65159SKalle Valo case ATH11K_SCAN_IDLE:
7917d5c65159SKalle Valo case ATH11K_SCAN_STARTING:
7918d5c65159SKalle Valo ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
7919d5c65159SKalle Valo goto exit;
7920d5c65159SKalle Valo case ATH11K_SCAN_RUNNING:
7921d5c65159SKalle Valo case ATH11K_SCAN_ABORTING:
7922d5c65159SKalle Valo break;
7923d5c65159SKalle Valo }
7924d5c65159SKalle Valo
7925d5c65159SKalle Valo idx = freq_to_idx(ar, ch_info_ev.freq);
7926d5c65159SKalle Valo if (idx >= ARRAY_SIZE(ar->survey)) {
7927d5c65159SKalle Valo ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
7928d5c65159SKalle Valo ch_info_ev.freq, idx);
7929d5c65159SKalle Valo goto exit;
7930d5c65159SKalle Valo }
7931d5c65159SKalle Valo
7932d5c65159SKalle Valo /* If FW provides MAC clock frequency in Mhz, overriding the initialized
7933d5c65159SKalle Valo * HW channel counters frequency value
7934d5c65159SKalle Valo */
7935d5c65159SKalle Valo if (ch_info_ev.mac_clk_mhz)
7936d5c65159SKalle Valo cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
7937d5c65159SKalle Valo
7938d5c65159SKalle Valo if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
7939d5c65159SKalle Valo survey = &ar->survey[idx];
7940d5c65159SKalle Valo memset(survey, 0, sizeof(*survey));
7941d5c65159SKalle Valo survey->noise = ch_info_ev.noise_floor;
7942d5c65159SKalle Valo survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
7943d5c65159SKalle Valo SURVEY_INFO_TIME_BUSY;
7944d5c65159SKalle Valo survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
7945d5c65159SKalle Valo survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
7946d5c65159SKalle Valo }
7947d5c65159SKalle Valo exit:
7948d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock);
7949d5c65159SKalle Valo rcu_read_unlock();
7950d5c65159SKalle Valo }
7951d5c65159SKalle Valo
7952d5c65159SKalle Valo static void
ath11k_pdev_bss_chan_info_event(struct ath11k_base * ab,struct sk_buff * skb)7953d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7954d5c65159SKalle Valo {
7955d5c65159SKalle Valo struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
7956d5c65159SKalle Valo struct survey_info *survey;
7957d5c65159SKalle Valo struct ath11k *ar;
7958d5c65159SKalle Valo u32 cc_freq_hz = ab->cc_freq_hz;
7959d5c65159SKalle Valo u64 busy, total, tx, rx, rx_bss;
7960d5c65159SKalle Valo int idx;
7961d5c65159SKalle Valo
7962d5c65159SKalle Valo if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
7963d5c65159SKalle Valo ath11k_warn(ab, "failed to extract pdev bss chan info event");
7964d5c65159SKalle Valo return;
7965d5c65159SKalle Valo }
7966d5c65159SKalle Valo
7967d5c65159SKalle Valo busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
7968d5c65159SKalle Valo bss_ch_info_ev.rx_clear_count_low;
7969d5c65159SKalle Valo
7970d5c65159SKalle Valo total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
7971d5c65159SKalle Valo bss_ch_info_ev.cycle_count_low;
7972d5c65159SKalle Valo
7973d5c65159SKalle Valo tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
7974d5c65159SKalle Valo bss_ch_info_ev.tx_cycle_count_low;
7975d5c65159SKalle Valo
7976d5c65159SKalle Valo rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
7977d5c65159SKalle Valo bss_ch_info_ev.rx_cycle_count_low;
7978d5c65159SKalle Valo
7979d5c65159SKalle Valo rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
7980d5c65159SKalle Valo bss_ch_info_ev.rx_bss_cycle_count_low;
7981d5c65159SKalle Valo
7982d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
7983e5df1577SKalle Valo "event pdev bss chan info:\n pdev_id: %d freq: %d noise: %d cycle: busy %llu total %llu tx %llu rx %llu rx_bss %llu\n",
7984d5c65159SKalle Valo bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
7985d5c65159SKalle Valo bss_ch_info_ev.noise_floor, busy, total,
7986d5c65159SKalle Valo tx, rx, rx_bss);
7987d5c65159SKalle Valo
7988d5c65159SKalle Valo rcu_read_lock();
7989d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
7990d5c65159SKalle Valo
7991d5c65159SKalle Valo if (!ar) {
7992d5c65159SKalle Valo ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
7993d5c65159SKalle Valo bss_ch_info_ev.pdev_id);
7994d5c65159SKalle Valo rcu_read_unlock();
7995d5c65159SKalle Valo return;
7996d5c65159SKalle Valo }
7997d5c65159SKalle Valo
7998d5c65159SKalle Valo spin_lock_bh(&ar->data_lock);
7999d5c65159SKalle Valo idx = freq_to_idx(ar, bss_ch_info_ev.freq);
8000d5c65159SKalle Valo if (idx >= ARRAY_SIZE(ar->survey)) {
8001d5c65159SKalle Valo ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
8002d5c65159SKalle Valo bss_ch_info_ev.freq, idx);
8003d5c65159SKalle Valo goto exit;
8004d5c65159SKalle Valo }
8005d5c65159SKalle Valo
8006d5c65159SKalle Valo survey = &ar->survey[idx];
8007d5c65159SKalle Valo
8008d5c65159SKalle Valo survey->noise = bss_ch_info_ev.noise_floor;
8009d5c65159SKalle Valo survey->time = div_u64(total, cc_freq_hz);
8010d5c65159SKalle Valo survey->time_busy = div_u64(busy, cc_freq_hz);
8011d5c65159SKalle Valo survey->time_rx = div_u64(rx_bss, cc_freq_hz);
8012d5c65159SKalle Valo survey->time_tx = div_u64(tx, cc_freq_hz);
8013d5c65159SKalle Valo survey->filled |= (SURVEY_INFO_NOISE_DBM |
8014d5c65159SKalle Valo SURVEY_INFO_TIME |
8015d5c65159SKalle Valo SURVEY_INFO_TIME_BUSY |
8016d5c65159SKalle Valo SURVEY_INFO_TIME_RX |
8017d5c65159SKalle Valo SURVEY_INFO_TIME_TX);
8018d5c65159SKalle Valo exit:
8019d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock);
8020d5c65159SKalle Valo complete(&ar->bss_survey_done);
8021d5c65159SKalle Valo
8022d5c65159SKalle Valo rcu_read_unlock();
8023d5c65159SKalle Valo }
8024d5c65159SKalle Valo
ath11k_vdev_install_key_compl_event(struct ath11k_base * ab,struct sk_buff * skb)8025d5c65159SKalle Valo static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
8026d5c65159SKalle Valo struct sk_buff *skb)
8027d5c65159SKalle Valo {
8028d5c65159SKalle Valo struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
8029d5c65159SKalle Valo struct ath11k *ar;
8030d5c65159SKalle Valo
8031d5c65159SKalle Valo if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
8032d5c65159SKalle Valo ath11k_warn(ab, "failed to extract install key compl event");
8033d5c65159SKalle Valo return;
8034d5c65159SKalle Valo }
8035d5c65159SKalle Valo
8036d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
8037e5df1577SKalle Valo "event vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
8038d5c65159SKalle Valo install_key_compl.key_idx, install_key_compl.key_flags,
8039d5c65159SKalle Valo install_key_compl.macaddr, install_key_compl.status);
8040d5c65159SKalle Valo
8041d5c65159SKalle Valo rcu_read_lock();
8042d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
8043d5c65159SKalle Valo if (!ar) {
8044d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
8045d5c65159SKalle Valo install_key_compl.vdev_id);
8046d5c65159SKalle Valo rcu_read_unlock();
8047d5c65159SKalle Valo return;
8048d5c65159SKalle Valo }
8049d5c65159SKalle Valo
8050d5c65159SKalle Valo ar->install_key_status = 0;
8051d5c65159SKalle Valo
8052d5c65159SKalle Valo if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
8053d5c65159SKalle Valo ath11k_warn(ab, "install key failed for %pM status %d\n",
8054d5c65159SKalle Valo install_key_compl.macaddr, install_key_compl.status);
8055d5c65159SKalle Valo ar->install_key_status = install_key_compl.status;
8056d5c65159SKalle Valo }
8057d5c65159SKalle Valo
8058d5c65159SKalle Valo complete(&ar->install_key_done);
8059d5c65159SKalle Valo rcu_read_unlock();
8060d5c65159SKalle Valo }
8061d5c65159SKalle Valo
ath11k_wmi_tlv_services_parser(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)8062e2e23a79SWen Gong static int ath11k_wmi_tlv_services_parser(struct ath11k_base *ab,
8063e2e23a79SWen Gong u16 tag, u16 len,
8064e2e23a79SWen Gong const void *ptr, void *data)
8065d5c65159SKalle Valo {
8066d5c65159SKalle Valo const struct wmi_service_available_event *ev;
8067e2e23a79SWen Gong u32 *wmi_ext2_service_bitmap;
8068d5c65159SKalle Valo int i, j;
8069d5c65159SKalle Valo
8070e2e23a79SWen Gong switch (tag) {
8071e2e23a79SWen Gong case WMI_TAG_SERVICE_AVAILABLE_EVENT:
8072e2e23a79SWen Gong ev = (struct wmi_service_available_event *)ptr;
8073d5c65159SKalle Valo for (i = 0, j = WMI_MAX_SERVICE;
8074d5c65159SKalle Valo i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
8075d5c65159SKalle Valo i++) {
8076d5c65159SKalle Valo do {
8077d5c65159SKalle Valo if (ev->wmi_service_segment_bitmap[i] &
8078d5c65159SKalle Valo BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
80796bc9d6f7SJohn Crispin set_bit(j, ab->wmi_ab.svc_map);
8080d5c65159SKalle Valo } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
8081d5c65159SKalle Valo }
8082d5c65159SKalle Valo
8083d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
8084e2e23a79SWen Gong "wmi_ext_service_bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
8085e2e23a79SWen Gong ev->wmi_service_segment_bitmap[0],
8086e2e23a79SWen Gong ev->wmi_service_segment_bitmap[1],
8087e2e23a79SWen Gong ev->wmi_service_segment_bitmap[2],
8088e2e23a79SWen Gong ev->wmi_service_segment_bitmap[3]);
8089e2e23a79SWen Gong break;
8090e2e23a79SWen Gong case WMI_TAG_ARRAY_UINT32:
8091e2e23a79SWen Gong wmi_ext2_service_bitmap = (u32 *)ptr;
8092e2e23a79SWen Gong for (i = 0, j = WMI_MAX_EXT_SERVICE;
8093e2e23a79SWen Gong i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT2_SERVICE;
8094e2e23a79SWen Gong i++) {
8095e2e23a79SWen Gong do {
8096e2e23a79SWen Gong if (wmi_ext2_service_bitmap[i] &
8097e2e23a79SWen Gong BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
8098e2e23a79SWen Gong set_bit(j, ab->wmi_ab.svc_map);
8099e2e23a79SWen Gong } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
8100e2e23a79SWen Gong }
8101d5c65159SKalle Valo
8102e2e23a79SWen Gong ath11k_dbg(ab, ATH11K_DBG_WMI,
8103e2e23a79SWen Gong "wmi_ext2_service__bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
8104e2e23a79SWen Gong wmi_ext2_service_bitmap[0], wmi_ext2_service_bitmap[1],
8105e2e23a79SWen Gong wmi_ext2_service_bitmap[2], wmi_ext2_service_bitmap[3]);
8106e2e23a79SWen Gong break;
8107e2e23a79SWen Gong }
8108e2e23a79SWen Gong return 0;
8109e2e23a79SWen Gong }
8110e2e23a79SWen Gong
ath11k_service_available_event(struct ath11k_base * ab,struct sk_buff * skb)8111e2e23a79SWen Gong static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
8112e2e23a79SWen Gong {
8113e2e23a79SWen Gong int ret;
8114e2e23a79SWen Gong
8115e2e23a79SWen Gong ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
8116e2e23a79SWen Gong ath11k_wmi_tlv_services_parser,
8117e2e23a79SWen Gong NULL);
8118e2e23a79SWen Gong if (ret)
8119e2e23a79SWen Gong ath11k_warn(ab, "failed to parse services available tlv %d\n", ret);
8120e5df1577SKalle Valo
8121e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event service available");
8122d5c65159SKalle Valo }
8123d5c65159SKalle Valo
ath11k_peer_assoc_conf_event(struct ath11k_base * ab,struct sk_buff * skb)8124d5c65159SKalle Valo static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
8125d5c65159SKalle Valo {
8126d5c65159SKalle Valo struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
8127d5c65159SKalle Valo struct ath11k *ar;
8128d5c65159SKalle Valo
8129d5c65159SKalle Valo if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
8130d5c65159SKalle Valo ath11k_warn(ab, "failed to extract peer assoc conf event");
8131d5c65159SKalle Valo return;
8132d5c65159SKalle Valo }
8133d5c65159SKalle Valo
8134d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
8135e5df1577SKalle Valo "event peer assoc conf ev vdev id %d macaddr %pM\n",
8136d5c65159SKalle Valo peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
8137d5c65159SKalle Valo
8138db0889abSKarthikeyan Periyasamy rcu_read_lock();
8139d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
8140d5c65159SKalle Valo
8141d5c65159SKalle Valo if (!ar) {
8142d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
8143d5c65159SKalle Valo peer_assoc_conf.vdev_id);
8144db0889abSKarthikeyan Periyasamy rcu_read_unlock();
8145d5c65159SKalle Valo return;
8146d5c65159SKalle Valo }
8147d5c65159SKalle Valo
8148d5c65159SKalle Valo complete(&ar->peer_assoc_done);
8149db0889abSKarthikeyan Periyasamy rcu_read_unlock();
8150d5c65159SKalle Valo }
8151d5c65159SKalle Valo
ath11k_update_stats_event(struct ath11k_base * ab,struct sk_buff * skb)8152d5c65159SKalle Valo static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
8153d5c65159SKalle Valo {
8154ec8918f9SAditya Kumar Singh struct ath11k_fw_stats stats = {};
8155ec8918f9SAditya Kumar Singh struct ath11k *ar;
8156ec8918f9SAditya Kumar Singh int ret;
8157ec8918f9SAditya Kumar Singh
8158ec8918f9SAditya Kumar Singh INIT_LIST_HEAD(&stats.pdevs);
8159ec8918f9SAditya Kumar Singh INIT_LIST_HEAD(&stats.vdevs);
8160ec8918f9SAditya Kumar Singh INIT_LIST_HEAD(&stats.bcn);
8161ec8918f9SAditya Kumar Singh
8162ec8918f9SAditya Kumar Singh ret = ath11k_wmi_pull_fw_stats(ab, skb, &stats);
8163ec8918f9SAditya Kumar Singh if (ret) {
8164ec8918f9SAditya Kumar Singh ath11k_warn(ab, "failed to pull fw stats: %d\n", ret);
8165ec8918f9SAditya Kumar Singh goto free;
8166ec8918f9SAditya Kumar Singh }
8167ec8918f9SAditya Kumar Singh
8168e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event update stats");
8169e5df1577SKalle Valo
8170ec8918f9SAditya Kumar Singh rcu_read_lock();
8171ec8918f9SAditya Kumar Singh ar = ath11k_mac_get_ar_by_pdev_id(ab, stats.pdev_id);
8172ec8918f9SAditya Kumar Singh if (!ar) {
8173ec8918f9SAditya Kumar Singh rcu_read_unlock();
8174ec8918f9SAditya Kumar Singh ath11k_warn(ab, "failed to get ar for pdev_id %d: %d\n",
8175ec8918f9SAditya Kumar Singh stats.pdev_id, ret);
8176ec8918f9SAditya Kumar Singh goto free;
8177ec8918f9SAditya Kumar Singh }
8178ec8918f9SAditya Kumar Singh
8179ec8918f9SAditya Kumar Singh spin_lock_bh(&ar->data_lock);
8180ec8918f9SAditya Kumar Singh
8181ec8918f9SAditya Kumar Singh /* WMI_REQUEST_PDEV_STAT can be requested via .get_txpower mac ops or via
8182ec8918f9SAditya Kumar Singh * debugfs fw stats. Therefore, processing it separately.
8183ec8918f9SAditya Kumar Singh */
8184ec8918f9SAditya Kumar Singh if (stats.stats_id == WMI_REQUEST_PDEV_STAT) {
8185ec8918f9SAditya Kumar Singh list_splice_tail_init(&stats.pdevs, &ar->fw_stats.pdevs);
8186ec8918f9SAditya Kumar Singh ar->fw_stats_done = true;
8187ec8918f9SAditya Kumar Singh goto complete;
8188ec8918f9SAditya Kumar Singh }
8189ec8918f9SAditya Kumar Singh
8190ec8918f9SAditya Kumar Singh /* WMI_REQUEST_VDEV_STAT, WMI_REQUEST_BCN_STAT and WMI_REQUEST_RSSI_PER_CHAIN_STAT
8191ec8918f9SAditya Kumar Singh * are currently requested only via debugfs fw stats. Hence, processing these
8192ec8918f9SAditya Kumar Singh * in debugfs context
8193ec8918f9SAditya Kumar Singh */
8194ec8918f9SAditya Kumar Singh ath11k_debugfs_fw_stats_process(ar, &stats);
8195ec8918f9SAditya Kumar Singh
8196ec8918f9SAditya Kumar Singh complete:
8197ec8918f9SAditya Kumar Singh complete(&ar->fw_stats_complete);
8198ec8918f9SAditya Kumar Singh rcu_read_unlock();
8199ec8918f9SAditya Kumar Singh spin_unlock_bh(&ar->data_lock);
8200ec8918f9SAditya Kumar Singh
82016aafa1c2SP Praneesh /* Since the stats's pdev, vdev and beacon list are spliced and reinitialised
82026aafa1c2SP Praneesh * at this point, no need to free the individual list.
82036aafa1c2SP Praneesh */
82046aafa1c2SP Praneesh return;
82056aafa1c2SP Praneesh
8206ec8918f9SAditya Kumar Singh free:
8207ec8918f9SAditya Kumar Singh ath11k_fw_stats_free(&stats);
8208d5c65159SKalle Valo }
8209d5c65159SKalle Valo
8210d5c65159SKalle Valo /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
8211d5c65159SKalle Valo * is not part of BDF CTL(Conformance test limits) table entries.
8212d5c65159SKalle Valo */
ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base * ab,struct sk_buff * skb)8213d5c65159SKalle Valo static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
8214d5c65159SKalle Valo struct sk_buff *skb)
8215d5c65159SKalle Valo {
8216d5c65159SKalle Valo const void **tb;
8217d5c65159SKalle Valo const struct wmi_pdev_ctl_failsafe_chk_event *ev;
8218d5c65159SKalle Valo int ret;
8219d5c65159SKalle Valo
8220d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8221d5c65159SKalle Valo if (IS_ERR(tb)) {
8222d5c65159SKalle Valo ret = PTR_ERR(tb);
8223d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8224d5c65159SKalle Valo return;
8225d5c65159SKalle Valo }
8226d5c65159SKalle Valo
8227d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
8228d5c65159SKalle Valo if (!ev) {
8229d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
8230d5c65159SKalle Valo kfree(tb);
8231d5c65159SKalle Valo return;
8232d5c65159SKalle Valo }
8233d5c65159SKalle Valo
8234d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
8235e5df1577SKalle Valo "event pdev ctl failsafe check status %d\n",
8236d5c65159SKalle Valo ev->ctl_failsafe_status);
8237d5c65159SKalle Valo
8238d5c65159SKalle Valo /* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
8239d5c65159SKalle Valo * to 10 dBm else the CTL power entry in the BDF would be picked up.
8240d5c65159SKalle Valo */
8241d5c65159SKalle Valo if (ev->ctl_failsafe_status != 0)
8242d5c65159SKalle Valo ath11k_warn(ab, "pdev ctl failsafe failure status %d",
8243d5c65159SKalle Valo ev->ctl_failsafe_status);
8244d5c65159SKalle Valo
8245d5c65159SKalle Valo kfree(tb);
8246d5c65159SKalle Valo }
8247d5c65159SKalle Valo
8248d5c65159SKalle Valo static void
ath11k_wmi_process_csa_switch_count_event(struct ath11k_base * ab,const struct wmi_pdev_csa_switch_ev * ev,const u32 * vdev_ids)8249d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
8250d5c65159SKalle Valo const struct wmi_pdev_csa_switch_ev *ev,
8251d5c65159SKalle Valo const u32 *vdev_ids)
8252d5c65159SKalle Valo {
8253d5c65159SKalle Valo int i;
8254d5c65159SKalle Valo struct ath11k_vif *arvif;
8255d5c65159SKalle Valo
8256d5c65159SKalle Valo /* Finish CSA once the switch count becomes NULL */
8257d5c65159SKalle Valo if (ev->current_switch_count)
8258d5c65159SKalle Valo return;
8259d5c65159SKalle Valo
8260d5c65159SKalle Valo rcu_read_lock();
8261d5c65159SKalle Valo for (i = 0; i < ev->num_vdevs; i++) {
8262d5c65159SKalle Valo arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
8263d5c65159SKalle Valo
8264d5c65159SKalle Valo if (!arvif) {
8265d5c65159SKalle Valo ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
8266d5c65159SKalle Valo vdev_ids[i]);
8267d5c65159SKalle Valo continue;
8268d5c65159SKalle Valo }
8269d5c65159SKalle Valo
8270d0a9123eSJohannes Berg if (arvif->is_up && arvif->vif->bss_conf.csa_active)
8271d5c65159SKalle Valo ieee80211_csa_finish(arvif->vif);
8272d5c65159SKalle Valo }
8273d5c65159SKalle Valo rcu_read_unlock();
8274d5c65159SKalle Valo }
8275d5c65159SKalle Valo
8276d5c65159SKalle Valo static void
ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base * ab,struct sk_buff * skb)8277d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
8278d5c65159SKalle Valo struct sk_buff *skb)
8279d5c65159SKalle Valo {
8280d5c65159SKalle Valo const void **tb;
8281d5c65159SKalle Valo const struct wmi_pdev_csa_switch_ev *ev;
8282d5c65159SKalle Valo const u32 *vdev_ids;
8283d5c65159SKalle Valo int ret;
8284d5c65159SKalle Valo
8285d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8286d5c65159SKalle Valo if (IS_ERR(tb)) {
8287d5c65159SKalle Valo ret = PTR_ERR(tb);
8288d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8289d5c65159SKalle Valo return;
8290d5c65159SKalle Valo }
8291d5c65159SKalle Valo
8292d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
8293d5c65159SKalle Valo vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
8294d5c65159SKalle Valo
8295d5c65159SKalle Valo if (!ev || !vdev_ids) {
8296d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
8297d5c65159SKalle Valo kfree(tb);
8298d5c65159SKalle Valo return;
8299d5c65159SKalle Valo }
8300d5c65159SKalle Valo
8301d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
8302e5df1577SKalle Valo "event pdev csa switch count %d for pdev %d, num_vdevs %d",
8303d5c65159SKalle Valo ev->current_switch_count, ev->pdev_id,
8304d5c65159SKalle Valo ev->num_vdevs);
8305d5c65159SKalle Valo
8306d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
8307d5c65159SKalle Valo
8308d5c65159SKalle Valo kfree(tb);
8309d5c65159SKalle Valo }
8310d5c65159SKalle Valo
8311d5c65159SKalle Valo static void
ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base * ab,struct sk_buff * skb)8312d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
8313d5c65159SKalle Valo {
8314d5c65159SKalle Valo const void **tb;
8315d5c65159SKalle Valo const struct wmi_pdev_radar_ev *ev;
8316d5c65159SKalle Valo struct ath11k *ar;
8317d5c65159SKalle Valo int ret;
8318d5c65159SKalle Valo
8319d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8320d5c65159SKalle Valo if (IS_ERR(tb)) {
8321d5c65159SKalle Valo ret = PTR_ERR(tb);
8322d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8323d5c65159SKalle Valo return;
8324d5c65159SKalle Valo }
8325d5c65159SKalle Valo
8326d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
8327d5c65159SKalle Valo
8328d5c65159SKalle Valo if (!ev) {
8329d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
8330d5c65159SKalle Valo kfree(tb);
8331d5c65159SKalle Valo return;
8332d5c65159SKalle Valo }
8333d5c65159SKalle Valo
8334d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI,
8335e5df1577SKalle Valo "event pdev dfs radar detected on pdev %d, detection mode %d, chan freq %d, chan_width %d, detector id %d, seg id %d, timestamp %d, chirp %d, freq offset %d, sidx %d",
8336d5c65159SKalle Valo ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
8337d5c65159SKalle Valo ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
8338d5c65159SKalle Valo ev->freq_offset, ev->sidx);
8339d5c65159SKalle Valo
834021ebb0abSJohan Hovold rcu_read_lock();
834121ebb0abSJohan Hovold
8342d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
8343d5c65159SKalle Valo
8344d5c65159SKalle Valo if (!ar) {
8345d5c65159SKalle Valo ath11k_warn(ab, "radar detected in invalid pdev %d\n",
8346d5c65159SKalle Valo ev->pdev_id);
8347d5c65159SKalle Valo goto exit;
8348d5c65159SKalle Valo }
8349d5c65159SKalle Valo
8350d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
8351d5c65159SKalle Valo ev->pdev_id);
8352d5c65159SKalle Valo
8353d5c65159SKalle Valo if (ar->dfs_block_radar_events)
8354d5c65159SKalle Valo ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
8355d5c65159SKalle Valo else
8356d5c65159SKalle Valo ieee80211_radar_detected(ar->hw);
8357d5c65159SKalle Valo
8358d5c65159SKalle Valo exit:
835921ebb0abSJohan Hovold rcu_read_unlock();
836021ebb0abSJohan Hovold
8361d5c65159SKalle Valo kfree(tb);
8362d5c65159SKalle Valo }
8363d5c65159SKalle Valo
8364a41d1034SPradeep Kumar Chitrapu static void
ath11k_wmi_pdev_temperature_event(struct ath11k_base * ab,struct sk_buff * skb)8365a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
8366a41d1034SPradeep Kumar Chitrapu struct sk_buff *skb)
8367a41d1034SPradeep Kumar Chitrapu {
8368a41d1034SPradeep Kumar Chitrapu struct ath11k *ar;
8369e3de5bb7SPradeep Kumar Chitrapu const void **tb;
8370e3de5bb7SPradeep Kumar Chitrapu const struct wmi_pdev_temperature_event *ev;
8371e3de5bb7SPradeep Kumar Chitrapu int ret;
8372a41d1034SPradeep Kumar Chitrapu
8373e3de5bb7SPradeep Kumar Chitrapu tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8374e3de5bb7SPradeep Kumar Chitrapu if (IS_ERR(tb)) {
8375e3de5bb7SPradeep Kumar Chitrapu ret = PTR_ERR(tb);
8376e3de5bb7SPradeep Kumar Chitrapu ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8377e3de5bb7SPradeep Kumar Chitrapu return;
8378e3de5bb7SPradeep Kumar Chitrapu }
8379e3de5bb7SPradeep Kumar Chitrapu
8380e3de5bb7SPradeep Kumar Chitrapu ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
8381e3de5bb7SPradeep Kumar Chitrapu if (!ev) {
8382e3de5bb7SPradeep Kumar Chitrapu ath11k_warn(ab, "failed to fetch pdev temp ev");
8383e3de5bb7SPradeep Kumar Chitrapu kfree(tb);
8384a41d1034SPradeep Kumar Chitrapu return;
8385a41d1034SPradeep Kumar Chitrapu }
8386a41d1034SPradeep Kumar Chitrapu
8387e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event pdev temperature ev temp %d pdev_id %d\n",
8388e5df1577SKalle Valo ev->temp, ev->pdev_id);
8389a41d1034SPradeep Kumar Chitrapu
8390c5b91452SJohan Hovold rcu_read_lock();
8391c5b91452SJohan Hovold
8392e3de5bb7SPradeep Kumar Chitrapu ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
8393a41d1034SPradeep Kumar Chitrapu if (!ar) {
8394e3de5bb7SPradeep Kumar Chitrapu ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
8395c5b91452SJohan Hovold goto exit;
8396a41d1034SPradeep Kumar Chitrapu }
8397a41d1034SPradeep Kumar Chitrapu
8398e3de5bb7SPradeep Kumar Chitrapu ath11k_thermal_event_temperature(ar, ev->temp);
8399e3de5bb7SPradeep Kumar Chitrapu
8400c5b91452SJohan Hovold exit:
8401c5b91452SJohan Hovold rcu_read_unlock();
8402c5b91452SJohan Hovold
8403e3de5bb7SPradeep Kumar Chitrapu kfree(tb);
8404a41d1034SPradeep Kumar Chitrapu }
8405a41d1034SPradeep Kumar Chitrapu
ath11k_fils_discovery_event(struct ath11k_base * ab,struct sk_buff * skb)8406047679e3SAloka Dixit static void ath11k_fils_discovery_event(struct ath11k_base *ab,
8407047679e3SAloka Dixit struct sk_buff *skb)
8408047679e3SAloka Dixit {
8409047679e3SAloka Dixit const void **tb;
8410047679e3SAloka Dixit const struct wmi_fils_discovery_event *ev;
8411047679e3SAloka Dixit int ret;
8412047679e3SAloka Dixit
8413047679e3SAloka Dixit tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8414047679e3SAloka Dixit if (IS_ERR(tb)) {
8415047679e3SAloka Dixit ret = PTR_ERR(tb);
8416047679e3SAloka Dixit ath11k_warn(ab,
8417047679e3SAloka Dixit "failed to parse FILS discovery event tlv %d\n",
8418047679e3SAloka Dixit ret);
8419047679e3SAloka Dixit return;
8420047679e3SAloka Dixit }
8421047679e3SAloka Dixit
8422e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event fils discovery");
8423e5df1577SKalle Valo
8424047679e3SAloka Dixit ev = tb[WMI_TAG_HOST_SWFDA_EVENT];
8425047679e3SAloka Dixit if (!ev) {
8426047679e3SAloka Dixit ath11k_warn(ab, "failed to fetch FILS discovery event\n");
8427047679e3SAloka Dixit kfree(tb);
8428047679e3SAloka Dixit return;
8429047679e3SAloka Dixit }
8430047679e3SAloka Dixit
8431047679e3SAloka Dixit ath11k_warn(ab,
8432047679e3SAloka Dixit "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n",
8433047679e3SAloka Dixit ev->vdev_id, ev->fils_tt, ev->tbtt);
8434047679e3SAloka Dixit
8435047679e3SAloka Dixit kfree(tb);
8436047679e3SAloka Dixit }
8437047679e3SAloka Dixit
ath11k_probe_resp_tx_status_event(struct ath11k_base * ab,struct sk_buff * skb)8438047679e3SAloka Dixit static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab,
8439047679e3SAloka Dixit struct sk_buff *skb)
8440047679e3SAloka Dixit {
8441047679e3SAloka Dixit const void **tb;
8442047679e3SAloka Dixit const struct wmi_probe_resp_tx_status_event *ev;
8443047679e3SAloka Dixit int ret;
8444047679e3SAloka Dixit
8445047679e3SAloka Dixit tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8446047679e3SAloka Dixit if (IS_ERR(tb)) {
8447047679e3SAloka Dixit ret = PTR_ERR(tb);
8448047679e3SAloka Dixit ath11k_warn(ab,
8449047679e3SAloka Dixit "failed to parse probe response transmission status event tlv: %d\n",
8450047679e3SAloka Dixit ret);
8451047679e3SAloka Dixit return;
8452047679e3SAloka Dixit }
8453047679e3SAloka Dixit
8454e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event probe resp tx status");
8455e5df1577SKalle Valo
8456047679e3SAloka Dixit ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT];
8457047679e3SAloka Dixit if (!ev) {
8458047679e3SAloka Dixit ath11k_warn(ab,
8459047679e3SAloka Dixit "failed to fetch probe response transmission status event");
8460047679e3SAloka Dixit kfree(tb);
8461047679e3SAloka Dixit return;
8462047679e3SAloka Dixit }
8463047679e3SAloka Dixit
8464047679e3SAloka Dixit if (ev->tx_status)
8465047679e3SAloka Dixit ath11k_warn(ab,
8466047679e3SAloka Dixit "Probe response transmission failed for vdev_id %u, status %u\n",
8467047679e3SAloka Dixit ev->vdev_id, ev->tx_status);
8468047679e3SAloka Dixit
8469047679e3SAloka Dixit kfree(tb);
8470047679e3SAloka Dixit }
8471047679e3SAloka Dixit
ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)847279802b13SCarl Huang static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab,
847379802b13SCarl Huang u16 tag, u16 len,
847479802b13SCarl Huang const void *ptr, void *data)
847579802b13SCarl Huang {
847679802b13SCarl Huang struct wmi_wow_ev_arg *ev = data;
847779802b13SCarl Huang const char *wow_pg_fault;
847879802b13SCarl Huang int wow_pg_len;
847979802b13SCarl Huang
848079802b13SCarl Huang switch (tag) {
848179802b13SCarl Huang case WMI_TAG_WOW_EVENT_INFO:
848279802b13SCarl Huang memcpy(ev, ptr, sizeof(*ev));
848379802b13SCarl Huang ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n",
848479802b13SCarl Huang ev->wake_reason, wow_reason(ev->wake_reason));
848579802b13SCarl Huang break;
848679802b13SCarl Huang
848779802b13SCarl Huang case WMI_TAG_ARRAY_BYTE:
848879802b13SCarl Huang if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) {
848979802b13SCarl Huang wow_pg_fault = ptr;
849079802b13SCarl Huang /* the first 4 bytes are length */
849179802b13SCarl Huang wow_pg_len = *(int *)wow_pg_fault;
849279802b13SCarl Huang wow_pg_fault += sizeof(int);
849379802b13SCarl Huang ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n",
849479802b13SCarl Huang wow_pg_len);
849579802b13SCarl Huang ath11k_dbg_dump(ab, ATH11K_DBG_WMI,
849679802b13SCarl Huang "wow_event_info_type packet present",
849779802b13SCarl Huang "wow_pg_fault ",
849879802b13SCarl Huang wow_pg_fault,
849979802b13SCarl Huang wow_pg_len);
850079802b13SCarl Huang }
850179802b13SCarl Huang break;
850279802b13SCarl Huang default:
850379802b13SCarl Huang break;
850479802b13SCarl Huang }
850579802b13SCarl Huang
850679802b13SCarl Huang return 0;
850779802b13SCarl Huang }
850879802b13SCarl Huang
ath11k_wmi_event_wow_wakeup_host(struct ath11k_base * ab,struct sk_buff * skb)850979802b13SCarl Huang static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb)
851079802b13SCarl Huang {
851179802b13SCarl Huang struct wmi_wow_ev_arg ev = { };
851279802b13SCarl Huang int ret;
851379802b13SCarl Huang
851479802b13SCarl Huang ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
851579802b13SCarl Huang ath11k_wmi_tlv_wow_wakeup_host_parse,
851679802b13SCarl Huang &ev);
851779802b13SCarl Huang if (ret) {
851879802b13SCarl Huang ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret);
851979802b13SCarl Huang return;
852079802b13SCarl Huang }
852179802b13SCarl Huang
8522e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event wow wakeup host");
8523e5df1577SKalle Valo
852479802b13SCarl Huang complete(&ab->wow.wakeup_completed);
852579802b13SCarl Huang }
852679802b13SCarl Huang
852742da1cc7SCheng Wang static void
ath11k_wmi_diag_event(struct ath11k_base * ab,struct sk_buff * skb)852842da1cc7SCheng Wang ath11k_wmi_diag_event(struct ath11k_base *ab,
852942da1cc7SCheng Wang struct sk_buff *skb)
853042da1cc7SCheng Wang {
8531e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event diag");
8532e5df1577SKalle Valo
853342da1cc7SCheng Wang trace_ath11k_wmi_diag(ab, skb->data, skb->len);
853442da1cc7SCheng Wang }
853542da1cc7SCheng Wang
ath11k_wmi_twt_add_dialog_event_status(u32 status)85363d00e8b5SJohn Crispin static const char *ath11k_wmi_twt_add_dialog_event_status(u32 status)
85373d00e8b5SJohn Crispin {
85383d00e8b5SJohn Crispin switch (status) {
85393d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_OK:
85403d00e8b5SJohn Crispin return "ok";
85413d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
85423d00e8b5SJohn Crispin return "twt disabled";
85433d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
85443d00e8b5SJohn Crispin return "dialog id in use";
85453d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_INVALID_PARAM:
85463d00e8b5SJohn Crispin return "invalid parameters";
85473d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_NOT_READY:
85483d00e8b5SJohn Crispin return "not ready";
85493d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_NO_RESOURCE:
85503d00e8b5SJohn Crispin return "resource unavailable";
85513d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_NO_ACK:
85523d00e8b5SJohn Crispin return "no ack";
85533d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_NO_RESPONSE:
85543d00e8b5SJohn Crispin return "no response";
85553d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_DENIED:
85563d00e8b5SJohn Crispin return "denied";
85573d00e8b5SJohn Crispin case WMI_ADD_TWT_STATUS_UNKNOWN_ERROR:
85583d00e8b5SJohn Crispin fallthrough;
85593d00e8b5SJohn Crispin default:
85603d00e8b5SJohn Crispin return "unknown error";
85613d00e8b5SJohn Crispin }
85623d00e8b5SJohn Crispin }
85633d00e8b5SJohn Crispin
ath11k_wmi_twt_add_dialog_event(struct ath11k_base * ab,struct sk_buff * skb)85643d00e8b5SJohn Crispin static void ath11k_wmi_twt_add_dialog_event(struct ath11k_base *ab,
85653d00e8b5SJohn Crispin struct sk_buff *skb)
85663d00e8b5SJohn Crispin {
85673d00e8b5SJohn Crispin const void **tb;
85683d00e8b5SJohn Crispin const struct wmi_twt_add_dialog_event *ev;
85693d00e8b5SJohn Crispin int ret;
85703d00e8b5SJohn Crispin
85713d00e8b5SJohn Crispin tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
85723d00e8b5SJohn Crispin if (IS_ERR(tb)) {
85733d00e8b5SJohn Crispin ret = PTR_ERR(tb);
85743d00e8b5SJohn Crispin ath11k_warn(ab,
85753d00e8b5SJohn Crispin "failed to parse wmi twt add dialog status event tlv: %d\n",
85763d00e8b5SJohn Crispin ret);
85773d00e8b5SJohn Crispin return;
85783d00e8b5SJohn Crispin }
85793d00e8b5SJohn Crispin
8580e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event twt add dialog");
8581e5df1577SKalle Valo
85823d00e8b5SJohn Crispin ev = tb[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT];
85833d00e8b5SJohn Crispin if (!ev) {
85843d00e8b5SJohn Crispin ath11k_warn(ab, "failed to fetch twt add dialog wmi event\n");
85853d00e8b5SJohn Crispin goto exit;
85863d00e8b5SJohn Crispin }
85873d00e8b5SJohn Crispin
85883d00e8b5SJohn Crispin if (ev->status)
85893d00e8b5SJohn Crispin ath11k_warn(ab,
85903d00e8b5SJohn Crispin "wmi add twt dialog event vdev %d dialog id %d status %s\n",
85913d00e8b5SJohn Crispin ev->vdev_id, ev->dialog_id,
85923d00e8b5SJohn Crispin ath11k_wmi_twt_add_dialog_event_status(ev->status));
85933d00e8b5SJohn Crispin
85943d00e8b5SJohn Crispin exit:
85953d00e8b5SJohn Crispin kfree(tb);
85963d00e8b5SJohn Crispin }
85973d00e8b5SJohn Crispin
ath11k_wmi_gtk_offload_status_event(struct ath11k_base * ab,struct sk_buff * skb)8598a16d9b50SCarl Huang static void ath11k_wmi_gtk_offload_status_event(struct ath11k_base *ab,
8599a16d9b50SCarl Huang struct sk_buff *skb)
8600a16d9b50SCarl Huang {
8601a16d9b50SCarl Huang const void **tb;
8602a16d9b50SCarl Huang const struct wmi_gtk_offload_status_event *ev;
8603a16d9b50SCarl Huang struct ath11k_vif *arvif;
8604a16d9b50SCarl Huang __be64 replay_ctr_be;
8605a16d9b50SCarl Huang u64 replay_ctr;
8606a16d9b50SCarl Huang int ret;
8607a16d9b50SCarl Huang
8608a16d9b50SCarl Huang tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
8609a16d9b50SCarl Huang if (IS_ERR(tb)) {
8610a16d9b50SCarl Huang ret = PTR_ERR(tb);
8611a16d9b50SCarl Huang ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
8612a16d9b50SCarl Huang return;
8613a16d9b50SCarl Huang }
8614a16d9b50SCarl Huang
8615a16d9b50SCarl Huang ev = tb[WMI_TAG_GTK_OFFLOAD_STATUS_EVENT];
8616a16d9b50SCarl Huang if (!ev) {
8617a16d9b50SCarl Huang ath11k_warn(ab, "failed to fetch gtk offload status ev");
8618a16d9b50SCarl Huang kfree(tb);
8619a16d9b50SCarl Huang return;
8620a16d9b50SCarl Huang }
8621a16d9b50SCarl Huang
8622e83246ecSJohan Hovold rcu_read_lock();
8623e83246ecSJohan Hovold
8624a16d9b50SCarl Huang arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
8625a16d9b50SCarl Huang if (!arvif) {
8626a16d9b50SCarl Huang ath11k_warn(ab, "failed to get arvif for vdev_id:%d\n",
8627a16d9b50SCarl Huang ev->vdev_id);
8628e83246ecSJohan Hovold goto exit;
8629a16d9b50SCarl Huang }
8630a16d9b50SCarl Huang
8631e5df1577SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "event gtk offload refresh_cnt %d\n",
8632a16d9b50SCarl Huang ev->refresh_cnt);
8633a16d9b50SCarl Huang ath11k_dbg_dump(ab, ATH11K_DBG_WMI, "replay_cnt",
8634a16d9b50SCarl Huang NULL, ev->replay_ctr.counter, GTK_REPLAY_COUNTER_BYTES);
8635a16d9b50SCarl Huang
8636a16d9b50SCarl Huang replay_ctr = ev->replay_ctr.word1;
8637a16d9b50SCarl Huang replay_ctr = (replay_ctr << 32) | ev->replay_ctr.word0;
8638a16d9b50SCarl Huang arvif->rekey_data.replay_ctr = replay_ctr;
8639a16d9b50SCarl Huang
8640a16d9b50SCarl Huang /* supplicant expects big-endian replay counter */
8641a16d9b50SCarl Huang replay_ctr_be = cpu_to_be64(replay_ctr);
8642a16d9b50SCarl Huang
8643a16d9b50SCarl Huang ieee80211_gtk_rekey_notify(arvif->vif, arvif->bssid,
8644eee645ecSBaochen Qiang (void *)&replay_ctr_be, GFP_ATOMIC);
8645e83246ecSJohan Hovold exit:
8646e83246ecSJohan Hovold rcu_read_unlock();
8647a16d9b50SCarl Huang
8648a16d9b50SCarl Huang kfree(tb);
8649a16d9b50SCarl Huang }
8650a16d9b50SCarl Huang
ath11k_wmi_tlv_op_rx(struct ath11k_base * ab,struct sk_buff * skb)8651d5c65159SKalle Valo static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
8652d5c65159SKalle Valo {
8653d5c65159SKalle Valo struct wmi_cmd_hdr *cmd_hdr;
8654d5c65159SKalle Valo enum wmi_tlv_event_id id;
8655d5c65159SKalle Valo
8656d5c65159SKalle Valo cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
8657d5c65159SKalle Valo id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
8658d5c65159SKalle Valo
8659fb12305aSVenkateswara Naralasetty trace_ath11k_wmi_event(ab, id, skb->data, skb->len);
8660fb12305aSVenkateswara Naralasetty
8661d5c65159SKalle Valo if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
8662d5c65159SKalle Valo goto out;
8663d5c65159SKalle Valo
8664d5c65159SKalle Valo switch (id) {
8665d5c65159SKalle Valo /* Process all the WMI events here */
8666d5c65159SKalle Valo case WMI_SERVICE_READY_EVENTID:
8667d5c65159SKalle Valo ath11k_service_ready_event(ab, skb);
8668d5c65159SKalle Valo break;
8669d5c65159SKalle Valo case WMI_SERVICE_READY_EXT_EVENTID:
8670d5c65159SKalle Valo ath11k_service_ready_ext_event(ab, skb);
8671d5c65159SKalle Valo break;
8672bd647855SKarthikeyan Periyasamy case WMI_SERVICE_READY_EXT2_EVENTID:
8673bd647855SKarthikeyan Periyasamy ath11k_service_ready_ext2_event(ab, skb);
8674bd647855SKarthikeyan Periyasamy break;
8675d5c65159SKalle Valo case WMI_REG_CHAN_LIST_CC_EVENTID:
867691fa00faSAditya Kumar Singh ath11k_reg_chan_list_event(ab, skb, WMI_REG_CHAN_LIST_CC_ID);
867791fa00faSAditya Kumar Singh break;
867891fa00faSAditya Kumar Singh case WMI_REG_CHAN_LIST_CC_EXT_EVENTID:
867991fa00faSAditya Kumar Singh ath11k_reg_chan_list_event(ab, skb, WMI_REG_CHAN_LIST_CC_EXT_ID);
8680d5c65159SKalle Valo break;
8681d5c65159SKalle Valo case WMI_READY_EVENTID:
8682d5c65159SKalle Valo ath11k_ready_event(ab, skb);
8683d5c65159SKalle Valo break;
8684d5c65159SKalle Valo case WMI_PEER_DELETE_RESP_EVENTID:
8685d5c65159SKalle Valo ath11k_peer_delete_resp_event(ab, skb);
8686d5c65159SKalle Valo break;
8687d5c65159SKalle Valo case WMI_VDEV_START_RESP_EVENTID:
8688d5c65159SKalle Valo ath11k_vdev_start_resp_event(ab, skb);
8689d5c65159SKalle Valo break;
8690d5c65159SKalle Valo case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
8691d5c65159SKalle Valo ath11k_bcn_tx_status_event(ab, skb);
8692d5c65159SKalle Valo break;
8693d5c65159SKalle Valo case WMI_VDEV_STOPPED_EVENTID:
8694d5c65159SKalle Valo ath11k_vdev_stopped_event(ab, skb);
8695d5c65159SKalle Valo break;
8696d5c65159SKalle Valo case WMI_MGMT_RX_EVENTID:
8697d5c65159SKalle Valo ath11k_mgmt_rx_event(ab, skb);
8698d5c65159SKalle Valo /* mgmt_rx_event() owns the skb now! */
8699d5c65159SKalle Valo return;
8700d5c65159SKalle Valo case WMI_MGMT_TX_COMPLETION_EVENTID:
8701d5c65159SKalle Valo ath11k_mgmt_tx_compl_event(ab, skb);
8702d5c65159SKalle Valo break;
8703d5c65159SKalle Valo case WMI_SCAN_EVENTID:
8704d5c65159SKalle Valo ath11k_scan_event(ab, skb);
8705d5c65159SKalle Valo break;
8706d5c65159SKalle Valo case WMI_PEER_STA_KICKOUT_EVENTID:
8707d5c65159SKalle Valo ath11k_peer_sta_kickout_event(ab, skb);
8708d5c65159SKalle Valo break;
8709d5c65159SKalle Valo case WMI_ROAM_EVENTID:
8710d5c65159SKalle Valo ath11k_roam_event(ab, skb);
8711d5c65159SKalle Valo break;
8712d5c65159SKalle Valo case WMI_CHAN_INFO_EVENTID:
8713d5c65159SKalle Valo ath11k_chan_info_event(ab, skb);
8714d5c65159SKalle Valo break;
8715d5c65159SKalle Valo case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
8716d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(ab, skb);
8717d5c65159SKalle Valo break;
8718d5c65159SKalle Valo case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
8719d5c65159SKalle Valo ath11k_vdev_install_key_compl_event(ab, skb);
8720d5c65159SKalle Valo break;
8721d5c65159SKalle Valo case WMI_SERVICE_AVAILABLE_EVENTID:
8722d5c65159SKalle Valo ath11k_service_available_event(ab, skb);
8723d5c65159SKalle Valo break;
8724d5c65159SKalle Valo case WMI_PEER_ASSOC_CONF_EVENTID:
8725d5c65159SKalle Valo ath11k_peer_assoc_conf_event(ab, skb);
8726d5c65159SKalle Valo break;
8727d5c65159SKalle Valo case WMI_UPDATE_STATS_EVENTID:
8728d5c65159SKalle Valo ath11k_update_stats_event(ab, skb);
8729d5c65159SKalle Valo break;
8730d5c65159SKalle Valo case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
8731d5c65159SKalle Valo ath11k_pdev_ctl_failsafe_check_event(ab, skb);
8732d5c65159SKalle Valo break;
8733d5c65159SKalle Valo case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
8734d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
8735d5c65159SKalle Valo break;
8736b43310e4SGovindaraj Saminathan case WMI_PDEV_UTF_EVENTID:
8737b43310e4SGovindaraj Saminathan ath11k_tm_wmi_event(ab, id, skb);
8738b43310e4SGovindaraj Saminathan break;
8739a41d1034SPradeep Kumar Chitrapu case WMI_PDEV_TEMPERATURE_EVENTID:
8740a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(ab, skb);
8741a41d1034SPradeep Kumar Chitrapu break;
87429d11b7bfSKarthikeyan Periyasamy case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
87439d11b7bfSKarthikeyan Periyasamy ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
87449d11b7bfSKarthikeyan Periyasamy break;
8745047679e3SAloka Dixit case WMI_HOST_FILS_DISCOVERY_EVENTID:
8746047679e3SAloka Dixit ath11k_fils_discovery_event(ab, skb);
8747047679e3SAloka Dixit break;
8748047679e3SAloka Dixit case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID:
8749047679e3SAloka Dixit ath11k_probe_resp_tx_status_event(ab, skb);
8750047679e3SAloka Dixit break;
8751886433a9SJohn Crispin case WMI_OBSS_COLOR_COLLISION_DETECTION_EVENTID:
8752886433a9SJohn Crispin ath11k_wmi_obss_color_collision_event(ab, skb);
8753886433a9SJohn Crispin break;
87543d00e8b5SJohn Crispin case WMI_TWT_ADD_DIALOG_EVENTID:
87553d00e8b5SJohn Crispin ath11k_wmi_twt_add_dialog_event(ab, skb);
87563d00e8b5SJohn Crispin break;
8757d5c65159SKalle Valo case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
8758d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
8759d5c65159SKalle Valo break;
87603cbbdfbeSRitesh Singh case WMI_VDEV_DELETE_RESP_EVENTID:
87613cbbdfbeSRitesh Singh ath11k_vdev_delete_resp_event(ab, skb);
87623cbbdfbeSRitesh Singh break;
876379802b13SCarl Huang case WMI_WOW_WAKEUP_HOST_EVENTID:
876479802b13SCarl Huang ath11k_wmi_event_wow_wakeup_host(ab, skb);
876579802b13SCarl Huang break;
87669dcf6808SWen Gong case WMI_11D_NEW_COUNTRY_EVENTID:
87679dcf6808SWen Gong ath11k_reg_11d_new_cc_event(ab, skb);
87689dcf6808SWen Gong break;
876942da1cc7SCheng Wang case WMI_DIAG_EVENTID:
877042da1cc7SCheng Wang ath11k_wmi_diag_event(ab, skb);
877142da1cc7SCheng Wang break;
8772710a95f9SVenkateswara Naralasetty case WMI_PEER_STA_PS_STATECHG_EVENTID:
8773710a95f9SVenkateswara Naralasetty ath11k_wmi_event_peer_sta_ps_state_chg(ab, skb);
8774710a95f9SVenkateswara Naralasetty break;
8775a16d9b50SCarl Huang case WMI_GTK_OFFLOAD_STATUS_EVENTID:
8776a16d9b50SCarl Huang ath11k_wmi_gtk_offload_status_event(ab, skb);
8777a16d9b50SCarl Huang break;
8778d5c65159SKalle Valo default:
87798fbeaca7SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "unsupported event id 0x%x\n", id);
8780d5c65159SKalle Valo break;
8781d5c65159SKalle Valo }
8782d5c65159SKalle Valo
8783d5c65159SKalle Valo out:
8784d5c65159SKalle Valo dev_kfree_skb(skb);
8785d5c65159SKalle Valo }
8786d5c65159SKalle Valo
ath11k_connect_pdev_htc_service(struct ath11k_base * ab,u32 pdev_idx)8787d5c65159SKalle Valo static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
8788d5c65159SKalle Valo u32 pdev_idx)
8789d5c65159SKalle Valo {
8790d5c65159SKalle Valo int status;
8791d5c65159SKalle Valo u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
8792d5c65159SKalle Valo ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
8793d5c65159SKalle Valo ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
8794d5c65159SKalle Valo
8795d5c65159SKalle Valo struct ath11k_htc_svc_conn_req conn_req;
8796d5c65159SKalle Valo struct ath11k_htc_svc_conn_resp conn_resp;
8797d5c65159SKalle Valo
8798d5c65159SKalle Valo memset(&conn_req, 0, sizeof(conn_req));
8799d5c65159SKalle Valo memset(&conn_resp, 0, sizeof(conn_resp));
8800d5c65159SKalle Valo
8801d5c65159SKalle Valo /* these fields are the same for all service endpoints */
8802d5c65159SKalle Valo conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
8803d5c65159SKalle Valo conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
8804d5c65159SKalle Valo conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
8805d5c65159SKalle Valo
8806d5c65159SKalle Valo /* connect to control service */
8807d5c65159SKalle Valo conn_req.service_id = svc_id[pdev_idx];
8808d5c65159SKalle Valo
8809d5c65159SKalle Valo status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
8810d5c65159SKalle Valo if (status) {
8811d5c65159SKalle Valo ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
8812d5c65159SKalle Valo status);
8813d5c65159SKalle Valo return status;
8814d5c65159SKalle Valo }
8815d5c65159SKalle Valo
88166bc9d6f7SJohn Crispin ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
88176bc9d6f7SJohn Crispin ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
88186bc9d6f7SJohn Crispin ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
8819f951380aSP Praneesh init_waitqueue_head(&ab->wmi_ab.wmi[pdev_idx].tx_ce_desc_wq);
8820d5c65159SKalle Valo
8821d5c65159SKalle Valo return 0;
8822d5c65159SKalle Valo }
8823d5c65159SKalle Valo
8824d5c65159SKalle Valo static int
ath11k_wmi_send_unit_test_cmd(struct ath11k * ar,struct wmi_unit_test_cmd ut_cmd,u32 * test_args)8825d5c65159SKalle Valo ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
8826d5c65159SKalle Valo struct wmi_unit_test_cmd ut_cmd,
8827d5c65159SKalle Valo u32 *test_args)
8828d5c65159SKalle Valo {
8829d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi;
8830d5c65159SKalle Valo struct wmi_unit_test_cmd *cmd;
8831d5c65159SKalle Valo struct sk_buff *skb;
8832d5c65159SKalle Valo struct wmi_tlv *tlv;
8833d5c65159SKalle Valo void *ptr;
8834d5c65159SKalle Valo u32 *ut_cmd_args;
8835d5c65159SKalle Valo int buf_len, arg_len;
8836d5c65159SKalle Valo int ret;
8837d5c65159SKalle Valo int i;
8838d5c65159SKalle Valo
8839d5c65159SKalle Valo arg_len = sizeof(u32) * ut_cmd.num_args;
8840d5c65159SKalle Valo buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
8841d5c65159SKalle Valo
88426bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
8843d5c65159SKalle Valo if (!skb)
8844d5c65159SKalle Valo return -ENOMEM;
8845d5c65159SKalle Valo
8846d5c65159SKalle Valo cmd = (struct wmi_unit_test_cmd *)skb->data;
8847d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
8848d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
8849d5c65159SKalle Valo
8850d5c65159SKalle Valo cmd->vdev_id = ut_cmd.vdev_id;
8851d5c65159SKalle Valo cmd->module_id = ut_cmd.module_id;
8852d5c65159SKalle Valo cmd->num_args = ut_cmd.num_args;
8853d5c65159SKalle Valo cmd->diag_token = ut_cmd.diag_token;
8854d5c65159SKalle Valo
8855d5c65159SKalle Valo ptr = skb->data + sizeof(ut_cmd);
8856d5c65159SKalle Valo
8857d5c65159SKalle Valo tlv = ptr;
8858d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8859d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, arg_len);
8860d5c65159SKalle Valo
8861d5c65159SKalle Valo ptr += TLV_HDR_SIZE;
8862d5c65159SKalle Valo
8863d5c65159SKalle Valo ut_cmd_args = ptr;
8864d5c65159SKalle Valo for (i = 0; i < ut_cmd.num_args; i++)
8865d5c65159SKalle Valo ut_cmd_args[i] = test_args[i];
8866d5c65159SKalle Valo
8867d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
8868d5c65159SKalle Valo
8869d5c65159SKalle Valo if (ret) {
8870d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
8871d5c65159SKalle Valo ret);
8872d5c65159SKalle Valo dev_kfree_skb(skb);
8873d5c65159SKalle Valo }
8874d5c65159SKalle Valo
8875d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
887600608b40SKalle Valo "cmd unit test module %d vdev %d n_args %d token %d\n",
8877d5c65159SKalle Valo cmd->module_id, cmd->vdev_id, cmd->num_args,
8878d5c65159SKalle Valo cmd->diag_token);
8879d5c65159SKalle Valo
8880d5c65159SKalle Valo return ret;
8881d5c65159SKalle Valo }
8882d5c65159SKalle Valo
ath11k_wmi_simulate_radar(struct ath11k * ar)8883d5c65159SKalle Valo int ath11k_wmi_simulate_radar(struct ath11k *ar)
8884d5c65159SKalle Valo {
8885d5c65159SKalle Valo struct ath11k_vif *arvif;
8886d5c65159SKalle Valo u32 dfs_args[DFS_MAX_TEST_ARGS];
8887d5c65159SKalle Valo struct wmi_unit_test_cmd wmi_ut;
8888d5c65159SKalle Valo bool arvif_found = false;
8889d5c65159SKalle Valo
8890d5c65159SKalle Valo list_for_each_entry(arvif, &ar->arvifs, list) {
8891d5c65159SKalle Valo if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
8892d5c65159SKalle Valo arvif_found = true;
8893d5c65159SKalle Valo break;
8894d5c65159SKalle Valo }
8895d5c65159SKalle Valo }
8896d5c65159SKalle Valo
8897d5c65159SKalle Valo if (!arvif_found)
8898d5c65159SKalle Valo return -EINVAL;
8899d5c65159SKalle Valo
8900d5c65159SKalle Valo dfs_args[DFS_TEST_CMDID] = 0;
8901d5c65159SKalle Valo dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
8902d5c65159SKalle Valo /* Currently we could pass segment_id(b0 - b1), chirp(b2)
8903d5c65159SKalle Valo * freq offset (b3 - b10) to unit test. For simulation
8904d5c65159SKalle Valo * purpose this can be set to 0 which is valid.
8905d5c65159SKalle Valo */
8906d5c65159SKalle Valo dfs_args[DFS_TEST_RADAR_PARAM] = 0;
8907d5c65159SKalle Valo
8908d5c65159SKalle Valo wmi_ut.vdev_id = arvif->vdev_id;
8909d5c65159SKalle Valo wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
8910d5c65159SKalle Valo wmi_ut.num_args = DFS_MAX_TEST_ARGS;
8911d5c65159SKalle Valo wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
8912d5c65159SKalle Valo
8913d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
8914d5c65159SKalle Valo
8915d5c65159SKalle Valo return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
8916d5c65159SKalle Valo }
8917d5c65159SKalle Valo
ath11k_wmi_fw_dbglog_cfg(struct ath11k * ar,u32 * module_id_bitmap,struct ath11k_fw_dbglog * dbglog)8918f295ad91SSeevalamuthu Mariappan int ath11k_wmi_fw_dbglog_cfg(struct ath11k *ar, u32 *module_id_bitmap,
8919f295ad91SSeevalamuthu Mariappan struct ath11k_fw_dbglog *dbglog)
8920f295ad91SSeevalamuthu Mariappan {
8921f295ad91SSeevalamuthu Mariappan struct ath11k_pdev_wmi *wmi = ar->wmi;
8922f295ad91SSeevalamuthu Mariappan struct wmi_debug_log_config_cmd_fixed_param *cmd;
8923f295ad91SSeevalamuthu Mariappan struct sk_buff *skb;
8924f295ad91SSeevalamuthu Mariappan struct wmi_tlv *tlv;
8925f295ad91SSeevalamuthu Mariappan int ret, len;
8926f295ad91SSeevalamuthu Mariappan
8927f295ad91SSeevalamuthu Mariappan len = sizeof(*cmd) + TLV_HDR_SIZE + (MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8928f295ad91SSeevalamuthu Mariappan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8929f295ad91SSeevalamuthu Mariappan if (!skb)
8930f295ad91SSeevalamuthu Mariappan return -ENOMEM;
8931f295ad91SSeevalamuthu Mariappan
8932f295ad91SSeevalamuthu Mariappan cmd = (struct wmi_debug_log_config_cmd_fixed_param *)skb->data;
8933f295ad91SSeevalamuthu Mariappan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DEBUG_LOG_CONFIG_CMD) |
8934f295ad91SSeevalamuthu Mariappan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8935f295ad91SSeevalamuthu Mariappan cmd->dbg_log_param = dbglog->param;
8936f295ad91SSeevalamuthu Mariappan
8937f295ad91SSeevalamuthu Mariappan tlv = (struct wmi_tlv *)((u8 *)cmd + sizeof(*cmd));
8938f295ad91SSeevalamuthu Mariappan tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8939f295ad91SSeevalamuthu Mariappan FIELD_PREP(WMI_TLV_LEN, MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8940f295ad91SSeevalamuthu Mariappan
8941f295ad91SSeevalamuthu Mariappan switch (dbglog->param) {
8942f295ad91SSeevalamuthu Mariappan case WMI_DEBUG_LOG_PARAM_LOG_LEVEL:
8943f295ad91SSeevalamuthu Mariappan case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE:
8944f295ad91SSeevalamuthu Mariappan case WMI_DEBUG_LOG_PARAM_VDEV_DISABLE:
8945f295ad91SSeevalamuthu Mariappan case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE_BITMAP:
8946f295ad91SSeevalamuthu Mariappan cmd->value = dbglog->value;
8947f295ad91SSeevalamuthu Mariappan break;
8948f295ad91SSeevalamuthu Mariappan case WMI_DEBUG_LOG_PARAM_MOD_ENABLE_BITMAP:
8949f295ad91SSeevalamuthu Mariappan case WMI_DEBUG_LOG_PARAM_WOW_MOD_ENABLE_BITMAP:
8950f295ad91SSeevalamuthu Mariappan cmd->value = dbglog->value;
8951f295ad91SSeevalamuthu Mariappan memcpy(tlv->value, module_id_bitmap,
8952f295ad91SSeevalamuthu Mariappan MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8953f295ad91SSeevalamuthu Mariappan /* clear current config to be used for next user config */
8954f295ad91SSeevalamuthu Mariappan memset(module_id_bitmap, 0,
8955f295ad91SSeevalamuthu Mariappan MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8956f295ad91SSeevalamuthu Mariappan break;
8957f295ad91SSeevalamuthu Mariappan default:
8958f295ad91SSeevalamuthu Mariappan dev_kfree_skb(skb);
8959f295ad91SSeevalamuthu Mariappan return -EINVAL;
8960f295ad91SSeevalamuthu Mariappan }
8961f295ad91SSeevalamuthu Mariappan
8962f295ad91SSeevalamuthu Mariappan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DBGLOG_CFG_CMDID);
8963f295ad91SSeevalamuthu Mariappan if (ret) {
8964f295ad91SSeevalamuthu Mariappan ath11k_warn(ar->ab,
8965f295ad91SSeevalamuthu Mariappan "failed to send WMI_DBGLOG_CFG_CMDID\n");
8966f295ad91SSeevalamuthu Mariappan dev_kfree_skb(skb);
8967f295ad91SSeevalamuthu Mariappan }
896800608b40SKalle Valo
896900608b40SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "cmd dbglog cfg");
897000608b40SKalle Valo
8971f295ad91SSeevalamuthu Mariappan return ret;
8972f295ad91SSeevalamuthu Mariappan }
8973f295ad91SSeevalamuthu Mariappan
ath11k_wmi_connect(struct ath11k_base * ab)8974d5c65159SKalle Valo int ath11k_wmi_connect(struct ath11k_base *ab)
8975d5c65159SKalle Valo {
8976d5c65159SKalle Valo u32 i;
8977d5c65159SKalle Valo u8 wmi_ep_count;
8978d5c65159SKalle Valo
8979d5c65159SKalle Valo wmi_ep_count = ab->htc.wmi_ep_count;
8980b1cc29e9SAnilkumar Kolli if (wmi_ep_count > ab->hw_params.max_radios)
8981d5c65159SKalle Valo return -1;
8982d5c65159SKalle Valo
8983d5c65159SKalle Valo for (i = 0; i < wmi_ep_count; i++)
8984d5c65159SKalle Valo ath11k_connect_pdev_htc_service(ab, i);
8985d5c65159SKalle Valo
8986d5c65159SKalle Valo return 0;
8987d5c65159SKalle Valo }
8988d5c65159SKalle Valo
ath11k_wmi_pdev_detach(struct ath11k_base * ab,u8 pdev_id)8989d5c65159SKalle Valo static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
8990d5c65159SKalle Valo {
8991d5c65159SKalle Valo if (WARN_ON(pdev_id >= MAX_RADIOS))
8992d5c65159SKalle Valo return;
8993d5c65159SKalle Valo
8994d5c65159SKalle Valo /* TODO: Deinit any pdev specific wmi resource */
8995d5c65159SKalle Valo }
8996d5c65159SKalle Valo
ath11k_wmi_pdev_attach(struct ath11k_base * ab,u8 pdev_id)8997d5c65159SKalle Valo int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
8998d5c65159SKalle Valo u8 pdev_id)
8999d5c65159SKalle Valo {
9000d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi_handle;
9001d5c65159SKalle Valo
9002b1cc29e9SAnilkumar Kolli if (pdev_id >= ab->hw_params.max_radios)
9003d5c65159SKalle Valo return -EINVAL;
9004d5c65159SKalle Valo
90056bc9d6f7SJohn Crispin wmi_handle = &ab->wmi_ab.wmi[pdev_id];
9006d5c65159SKalle Valo
90076bc9d6f7SJohn Crispin wmi_handle->wmi_ab = &ab->wmi_ab;
9008d5c65159SKalle Valo
90096bc9d6f7SJohn Crispin ab->wmi_ab.ab = ab;
9010d5c65159SKalle Valo /* TODO: Init remaining resource specific to pdev */
9011d5c65159SKalle Valo
9012d5c65159SKalle Valo return 0;
9013d5c65159SKalle Valo }
9014d5c65159SKalle Valo
ath11k_wmi_attach(struct ath11k_base * ab)9015d5c65159SKalle Valo int ath11k_wmi_attach(struct ath11k_base *ab)
9016d5c65159SKalle Valo {
9017d5c65159SKalle Valo int ret;
9018d5c65159SKalle Valo
9019d5c65159SKalle Valo ret = ath11k_wmi_pdev_attach(ab, 0);
9020d5c65159SKalle Valo if (ret)
9021d5c65159SKalle Valo return ret;
9022d5c65159SKalle Valo
90236bc9d6f7SJohn Crispin ab->wmi_ab.ab = ab;
90246bc9d6f7SJohn Crispin ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
9025d5c65159SKalle Valo
90265f859bc0SCarl Huang /* It's overwritten when service_ext_ready is handled */
9027b6f63010SManikanta Pubbisetty if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1)
90285f859bc0SCarl Huang ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
90295f859bc0SCarl Huang
9030d5c65159SKalle Valo /* TODO: Init remaining wmi soc resources required */
90316bc9d6f7SJohn Crispin init_completion(&ab->wmi_ab.service_ready);
90326bc9d6f7SJohn Crispin init_completion(&ab->wmi_ab.unified_ready);
9033d5c65159SKalle Valo
9034d5c65159SKalle Valo return 0;
9035d5c65159SKalle Valo }
9036d5c65159SKalle Valo
ath11k_wmi_detach(struct ath11k_base * ab)9037d5c65159SKalle Valo void ath11k_wmi_detach(struct ath11k_base *ab)
9038d5c65159SKalle Valo {
9039d5c65159SKalle Valo int i;
9040d5c65159SKalle Valo
9041d5c65159SKalle Valo /* TODO: Deinit wmi resource specific to SOC as required */
9042d5c65159SKalle Valo
9043d5c65159SKalle Valo for (i = 0; i < ab->htc.wmi_ep_count; i++)
9044d5c65159SKalle Valo ath11k_wmi_pdev_detach(ab, i);
9045bd647855SKarthikeyan Periyasamy
9046bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab);
9047d5c65159SKalle Valo }
904879802b13SCarl Huang
ath11k_wmi_hw_data_filter_cmd(struct ath11k * ar,u32 vdev_id,u32 filter_bitmap,bool enable)9049c417b247SCarl Huang int ath11k_wmi_hw_data_filter_cmd(struct ath11k *ar, u32 vdev_id,
9050c417b247SCarl Huang u32 filter_bitmap, bool enable)
9051c417b247SCarl Huang {
9052c417b247SCarl Huang struct wmi_hw_data_filter_cmd *cmd;
9053c417b247SCarl Huang struct sk_buff *skb;
9054c417b247SCarl Huang int len;
9055c417b247SCarl Huang
9056c417b247SCarl Huang len = sizeof(*cmd);
9057c417b247SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9058c417b247SCarl Huang
9059c417b247SCarl Huang if (!skb)
9060c417b247SCarl Huang return -ENOMEM;
9061c417b247SCarl Huang
9062c417b247SCarl Huang cmd = (struct wmi_hw_data_filter_cmd *)skb->data;
9063c417b247SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_HW_DATA_FILTER_CMD) |
9064c417b247SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9065c417b247SCarl Huang
9066c417b247SCarl Huang cmd->vdev_id = vdev_id;
9067c417b247SCarl Huang cmd->enable = enable;
9068c417b247SCarl Huang
9069c417b247SCarl Huang /* Set all modes in case of disable */
9070c417b247SCarl Huang if (cmd->enable)
9071c417b247SCarl Huang cmd->hw_filter_bitmap = filter_bitmap;
9072c417b247SCarl Huang else
9073c417b247SCarl Huang cmd->hw_filter_bitmap = ((u32)~0U);
9074c417b247SCarl Huang
9075c417b247SCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9076fc3b984aSKalle Valo "hw data filter enable %d filter_bitmap 0x%x\n",
9077c417b247SCarl Huang enable, filter_bitmap);
9078c417b247SCarl Huang
9079c417b247SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_HW_DATA_FILTER_CMDID);
9080c417b247SCarl Huang }
9081c417b247SCarl Huang
ath11k_wmi_wow_host_wakeup_ind(struct ath11k * ar)908279802b13SCarl Huang int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar)
908379802b13SCarl Huang {
908479802b13SCarl Huang struct wmi_wow_host_wakeup_ind *cmd;
908579802b13SCarl Huang struct sk_buff *skb;
908679802b13SCarl Huang size_t len;
908779802b13SCarl Huang
908879802b13SCarl Huang len = sizeof(*cmd);
908979802b13SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
909079802b13SCarl Huang if (!skb)
909179802b13SCarl Huang return -ENOMEM;
909279802b13SCarl Huang
909379802b13SCarl Huang cmd = (struct wmi_wow_host_wakeup_ind *)skb->data;
909479802b13SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
909579802b13SCarl Huang WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) |
909679802b13SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
909779802b13SCarl Huang
9098fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow host wakeup ind\n");
909979802b13SCarl Huang
910079802b13SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
910179802b13SCarl Huang }
910279802b13SCarl Huang
ath11k_wmi_wow_enable(struct ath11k * ar)910379802b13SCarl Huang int ath11k_wmi_wow_enable(struct ath11k *ar)
910479802b13SCarl Huang {
910579802b13SCarl Huang struct wmi_wow_enable_cmd *cmd;
910679802b13SCarl Huang struct sk_buff *skb;
910779802b13SCarl Huang int len;
910879802b13SCarl Huang
910979802b13SCarl Huang len = sizeof(*cmd);
911079802b13SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
911179802b13SCarl Huang if (!skb)
911279802b13SCarl Huang return -ENOMEM;
911379802b13SCarl Huang
911479802b13SCarl Huang cmd = (struct wmi_wow_enable_cmd *)skb->data;
911579802b13SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) |
911679802b13SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
911779802b13SCarl Huang
911879802b13SCarl Huang cmd->enable = 1;
911979802b13SCarl Huang cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
9120fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow enable\n");
912179802b13SCarl Huang
912279802b13SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID);
912379802b13SCarl Huang }
91249cbd7fc9SCarl Huang
ath11k_wmi_scan_prob_req_oui(struct ath11k * ar,const u8 mac_addr[ETH_ALEN])91259cbd7fc9SCarl Huang int ath11k_wmi_scan_prob_req_oui(struct ath11k *ar,
91269cbd7fc9SCarl Huang const u8 mac_addr[ETH_ALEN])
91279cbd7fc9SCarl Huang {
91289cbd7fc9SCarl Huang struct sk_buff *skb;
91299cbd7fc9SCarl Huang struct wmi_scan_prob_req_oui_cmd *cmd;
91309cbd7fc9SCarl Huang u32 prob_req_oui;
91319cbd7fc9SCarl Huang int len;
91329cbd7fc9SCarl Huang
91339cbd7fc9SCarl Huang prob_req_oui = (((u32)mac_addr[0]) << 16) |
91349cbd7fc9SCarl Huang (((u32)mac_addr[1]) << 8) | mac_addr[2];
91359cbd7fc9SCarl Huang
91369cbd7fc9SCarl Huang len = sizeof(*cmd);
91379cbd7fc9SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
91389cbd7fc9SCarl Huang if (!skb)
91399cbd7fc9SCarl Huang return -ENOMEM;
91409cbd7fc9SCarl Huang
91419cbd7fc9SCarl Huang cmd = (struct wmi_scan_prob_req_oui_cmd *)skb->data;
91429cbd7fc9SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
91439cbd7fc9SCarl Huang WMI_TAG_SCAN_PROB_REQ_OUI_CMD) |
91449cbd7fc9SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
91459cbd7fc9SCarl Huang cmd->prob_req_oui = prob_req_oui;
91469cbd7fc9SCarl Huang
9147fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "scan prob req oui %d\n",
91489cbd7fc9SCarl Huang prob_req_oui);
91499cbd7fc9SCarl Huang
91509cbd7fc9SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SCAN_PROB_REQ_OUI_CMDID);
91519cbd7fc9SCarl Huang }
9152ba9177fcSCarl Huang
ath11k_wmi_wow_add_wakeup_event(struct ath11k * ar,u32 vdev_id,enum wmi_wow_wakeup_event event,u32 enable)9153ba9177fcSCarl Huang int ath11k_wmi_wow_add_wakeup_event(struct ath11k *ar, u32 vdev_id,
9154ba9177fcSCarl Huang enum wmi_wow_wakeup_event event,
9155ba9177fcSCarl Huang u32 enable)
9156ba9177fcSCarl Huang {
9157ba9177fcSCarl Huang struct wmi_wow_add_del_event_cmd *cmd;
9158ba9177fcSCarl Huang struct sk_buff *skb;
9159ba9177fcSCarl Huang size_t len;
9160ba9177fcSCarl Huang
9161ba9177fcSCarl Huang len = sizeof(*cmd);
9162ba9177fcSCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9163ba9177fcSCarl Huang if (!skb)
9164ba9177fcSCarl Huang return -ENOMEM;
9165ba9177fcSCarl Huang
9166ba9177fcSCarl Huang cmd = (struct wmi_wow_add_del_event_cmd *)skb->data;
9167ba9177fcSCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ADD_DEL_EVT_CMD) |
9168ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9169ba9177fcSCarl Huang
9170ba9177fcSCarl Huang cmd->vdev_id = vdev_id;
9171ba9177fcSCarl Huang cmd->is_add = enable;
9172ba9177fcSCarl Huang cmd->event_bitmap = (1 << event);
9173ba9177fcSCarl Huang
9174fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow add wakeup event %s enable %d vdev_id %d\n",
9175ba9177fcSCarl Huang wow_wakeup_event(event), enable, vdev_id);
9176ba9177fcSCarl Huang
9177ba9177fcSCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
9178ba9177fcSCarl Huang }
9179ba9177fcSCarl Huang
ath11k_wmi_wow_add_pattern(struct ath11k * ar,u32 vdev_id,u32 pattern_id,const u8 * pattern,const u8 * mask,int pattern_len,int pattern_offset)9180ba9177fcSCarl Huang int ath11k_wmi_wow_add_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id,
9181ba9177fcSCarl Huang const u8 *pattern, const u8 *mask,
9182ba9177fcSCarl Huang int pattern_len, int pattern_offset)
9183ba9177fcSCarl Huang {
9184ba9177fcSCarl Huang struct wmi_wow_add_pattern_cmd *cmd;
9185ba9177fcSCarl Huang struct wmi_wow_bitmap_pattern *bitmap;
9186ba9177fcSCarl Huang struct wmi_tlv *tlv;
9187ba9177fcSCarl Huang struct sk_buff *skb;
9188ba9177fcSCarl Huang u8 *ptr;
9189ba9177fcSCarl Huang size_t len;
9190ba9177fcSCarl Huang
9191ba9177fcSCarl Huang len = sizeof(*cmd) +
9192ba9177fcSCarl Huang sizeof(*tlv) + /* array struct */
9193ba9177fcSCarl Huang sizeof(*bitmap) + /* bitmap */
9194ba9177fcSCarl Huang sizeof(*tlv) + /* empty ipv4 sync */
9195ba9177fcSCarl Huang sizeof(*tlv) + /* empty ipv6 sync */
9196ba9177fcSCarl Huang sizeof(*tlv) + /* empty magic */
9197ba9177fcSCarl Huang sizeof(*tlv) + /* empty info timeout */
9198ba9177fcSCarl Huang sizeof(*tlv) + sizeof(u32); /* ratelimit interval */
9199ba9177fcSCarl Huang
9200ba9177fcSCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9201ba9177fcSCarl Huang if (!skb)
9202ba9177fcSCarl Huang return -ENOMEM;
9203ba9177fcSCarl Huang
9204ba9177fcSCarl Huang /* cmd */
9205ba9177fcSCarl Huang ptr = (u8 *)skb->data;
9206ba9177fcSCarl Huang cmd = (struct wmi_wow_add_pattern_cmd *)ptr;
9207ba9177fcSCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9208ba9177fcSCarl Huang WMI_TAG_WOW_ADD_PATTERN_CMD) |
9209ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9210ba9177fcSCarl Huang
9211ba9177fcSCarl Huang cmd->vdev_id = vdev_id;
9212ba9177fcSCarl Huang cmd->pattern_id = pattern_id;
9213ba9177fcSCarl Huang cmd->pattern_type = WOW_BITMAP_PATTERN;
9214ba9177fcSCarl Huang
9215ba9177fcSCarl Huang ptr += sizeof(*cmd);
9216ba9177fcSCarl Huang
9217ba9177fcSCarl Huang /* bitmap */
9218ba9177fcSCarl Huang tlv = (struct wmi_tlv *)ptr;
9219ba9177fcSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9220ba9177fcSCarl Huang WMI_TAG_ARRAY_STRUCT) |
9221ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap));
9222ba9177fcSCarl Huang
9223ba9177fcSCarl Huang ptr += sizeof(*tlv);
9224ba9177fcSCarl Huang
9225ba9177fcSCarl Huang bitmap = (struct wmi_wow_bitmap_pattern *)ptr;
9226ba9177fcSCarl Huang bitmap->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9227ba9177fcSCarl Huang WMI_TAG_WOW_BITMAP_PATTERN_T) |
9228ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap) - TLV_HDR_SIZE);
9229ba9177fcSCarl Huang
9230ba9177fcSCarl Huang memcpy(bitmap->patternbuf, pattern, pattern_len);
9231ba9177fcSCarl Huang ath11k_ce_byte_swap(bitmap->patternbuf, roundup(pattern_len, 4));
9232ba9177fcSCarl Huang memcpy(bitmap->bitmaskbuf, mask, pattern_len);
9233ba9177fcSCarl Huang ath11k_ce_byte_swap(bitmap->bitmaskbuf, roundup(pattern_len, 4));
9234ba9177fcSCarl Huang bitmap->pattern_offset = pattern_offset;
9235ba9177fcSCarl Huang bitmap->pattern_len = pattern_len;
9236ba9177fcSCarl Huang bitmap->bitmask_len = pattern_len;
9237ba9177fcSCarl Huang bitmap->pattern_id = pattern_id;
9238ba9177fcSCarl Huang
9239ba9177fcSCarl Huang ptr += sizeof(*bitmap);
9240ba9177fcSCarl Huang
9241ba9177fcSCarl Huang /* ipv4 sync */
9242ba9177fcSCarl Huang tlv = (struct wmi_tlv *)ptr;
9243ba9177fcSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9244ba9177fcSCarl Huang WMI_TAG_ARRAY_STRUCT) |
9245ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, 0);
9246ba9177fcSCarl Huang
9247ba9177fcSCarl Huang ptr += sizeof(*tlv);
9248ba9177fcSCarl Huang
9249ba9177fcSCarl Huang /* ipv6 sync */
9250ba9177fcSCarl Huang tlv = (struct wmi_tlv *)ptr;
9251ba9177fcSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9252ba9177fcSCarl Huang WMI_TAG_ARRAY_STRUCT) |
9253ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, 0);
9254ba9177fcSCarl Huang
9255ba9177fcSCarl Huang ptr += sizeof(*tlv);
9256ba9177fcSCarl Huang
9257ba9177fcSCarl Huang /* magic */
9258ba9177fcSCarl Huang tlv = (struct wmi_tlv *)ptr;
9259ba9177fcSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9260ba9177fcSCarl Huang WMI_TAG_ARRAY_STRUCT) |
9261ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, 0);
9262ba9177fcSCarl Huang
9263ba9177fcSCarl Huang ptr += sizeof(*tlv);
9264ba9177fcSCarl Huang
9265ba9177fcSCarl Huang /* pattern info timeout */
9266ba9177fcSCarl Huang tlv = (struct wmi_tlv *)ptr;
9267ba9177fcSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9268ba9177fcSCarl Huang WMI_TAG_ARRAY_UINT32) |
9269ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, 0);
9270ba9177fcSCarl Huang
9271ba9177fcSCarl Huang ptr += sizeof(*tlv);
9272ba9177fcSCarl Huang
9273ba9177fcSCarl Huang /* ratelimit interval */
9274ba9177fcSCarl Huang tlv = (struct wmi_tlv *)ptr;
9275ba9177fcSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9276ba9177fcSCarl Huang WMI_TAG_ARRAY_UINT32) |
9277ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(u32));
9278ba9177fcSCarl Huang
9279fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow add pattern vdev_id %d pattern_id %d pattern_offset %d\n",
9280ba9177fcSCarl Huang vdev_id, pattern_id, pattern_offset);
9281ba9177fcSCarl Huang
9282ba9177fcSCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ADD_WAKE_PATTERN_CMDID);
9283ba9177fcSCarl Huang }
9284ba9177fcSCarl Huang
ath11k_wmi_wow_del_pattern(struct ath11k * ar,u32 vdev_id,u32 pattern_id)9285ba9177fcSCarl Huang int ath11k_wmi_wow_del_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id)
9286ba9177fcSCarl Huang {
9287ba9177fcSCarl Huang struct wmi_wow_del_pattern_cmd *cmd;
9288ba9177fcSCarl Huang struct sk_buff *skb;
9289ba9177fcSCarl Huang size_t len;
9290ba9177fcSCarl Huang
9291ba9177fcSCarl Huang len = sizeof(*cmd);
9292ba9177fcSCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9293ba9177fcSCarl Huang if (!skb)
9294ba9177fcSCarl Huang return -ENOMEM;
9295ba9177fcSCarl Huang
9296ba9177fcSCarl Huang cmd = (struct wmi_wow_del_pattern_cmd *)skb->data;
9297ba9177fcSCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9298ba9177fcSCarl Huang WMI_TAG_WOW_DEL_PATTERN_CMD) |
9299ba9177fcSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9300ba9177fcSCarl Huang
9301ba9177fcSCarl Huang cmd->vdev_id = vdev_id;
9302ba9177fcSCarl Huang cmd->pattern_id = pattern_id;
9303ba9177fcSCarl Huang cmd->pattern_type = WOW_BITMAP_PATTERN;
9304ba9177fcSCarl Huang
9305fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv wow del pattern vdev_id %d pattern_id %d\n",
9306ba9177fcSCarl Huang vdev_id, pattern_id);
9307ba9177fcSCarl Huang
9308ba9177fcSCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_DEL_WAKE_PATTERN_CMDID);
9309ba9177fcSCarl Huang }
9310fec4b898SCarl Huang
9311fec4b898SCarl Huang static struct sk_buff *
ath11k_wmi_op_gen_config_pno_start(struct ath11k * ar,u32 vdev_id,struct wmi_pno_scan_req * pno)9312fec4b898SCarl Huang ath11k_wmi_op_gen_config_pno_start(struct ath11k *ar,
9313fec4b898SCarl Huang u32 vdev_id,
9314fec4b898SCarl Huang struct wmi_pno_scan_req *pno)
9315fec4b898SCarl Huang {
9316fec4b898SCarl Huang struct nlo_configured_parameters *nlo_list;
9317fec4b898SCarl Huang struct wmi_wow_nlo_config_cmd *cmd;
9318fec4b898SCarl Huang struct wmi_tlv *tlv;
9319fec4b898SCarl Huang struct sk_buff *skb;
9320fec4b898SCarl Huang u32 *channel_list;
9321fec4b898SCarl Huang size_t len, nlo_list_len, channel_list_len;
9322fec4b898SCarl Huang u8 *ptr;
9323fec4b898SCarl Huang u32 i;
9324fec4b898SCarl Huang
9325fec4b898SCarl Huang len = sizeof(*cmd) +
9326fec4b898SCarl Huang sizeof(*tlv) +
9327fec4b898SCarl Huang /* TLV place holder for array of structures
9328fec4b898SCarl Huang * nlo_configured_parameters(nlo_list)
9329fec4b898SCarl Huang */
9330fec4b898SCarl Huang sizeof(*tlv);
9331fec4b898SCarl Huang /* TLV place holder for array of uint32 channel_list */
9332fec4b898SCarl Huang
9333fec4b898SCarl Huang channel_list_len = sizeof(u32) * pno->a_networks[0].channel_count;
9334fec4b898SCarl Huang len += channel_list_len;
9335fec4b898SCarl Huang
9336fec4b898SCarl Huang nlo_list_len = sizeof(*nlo_list) * pno->uc_networks_count;
9337fec4b898SCarl Huang len += nlo_list_len;
9338fec4b898SCarl Huang
9339fec4b898SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9340fec4b898SCarl Huang if (!skb)
9341fec4b898SCarl Huang return ERR_PTR(-ENOMEM);
9342fec4b898SCarl Huang
9343fec4b898SCarl Huang ptr = (u8 *)skb->data;
9344fec4b898SCarl Huang cmd = (struct wmi_wow_nlo_config_cmd *)ptr;
9345fec4b898SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
9346fec4b898SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9347fec4b898SCarl Huang
9348fec4b898SCarl Huang cmd->vdev_id = pno->vdev_id;
9349fec4b898SCarl Huang cmd->flags = WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN;
9350fec4b898SCarl Huang
9351fec4b898SCarl Huang /* current FW does not support min-max range for dwell time */
9352fec4b898SCarl Huang cmd->active_dwell_time = pno->active_max_time;
9353fec4b898SCarl Huang cmd->passive_dwell_time = pno->passive_max_time;
9354fec4b898SCarl Huang
9355fec4b898SCarl Huang if (pno->do_passive_scan)
9356fec4b898SCarl Huang cmd->flags |= WMI_NLO_CONFIG_SCAN_PASSIVE;
9357fec4b898SCarl Huang
9358fec4b898SCarl Huang cmd->fast_scan_period = pno->fast_scan_period;
9359fec4b898SCarl Huang cmd->slow_scan_period = pno->slow_scan_period;
9360fec4b898SCarl Huang cmd->fast_scan_max_cycles = pno->fast_scan_max_cycles;
9361fec4b898SCarl Huang cmd->delay_start_time = pno->delay_start_time;
9362fec4b898SCarl Huang
9363fec4b898SCarl Huang if (pno->enable_pno_scan_randomization) {
9364fec4b898SCarl Huang cmd->flags |= WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
9365fec4b898SCarl Huang WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ;
9366fec4b898SCarl Huang ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
9367fec4b898SCarl Huang ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
9368fec4b898SCarl Huang ath11k_ce_byte_swap(cmd->mac_addr.addr, 8);
9369fec4b898SCarl Huang ath11k_ce_byte_swap(cmd->mac_mask.addr, 8);
9370fec4b898SCarl Huang }
9371fec4b898SCarl Huang
9372fec4b898SCarl Huang ptr += sizeof(*cmd);
9373fec4b898SCarl Huang
9374fec4b898SCarl Huang /* nlo_configured_parameters(nlo_list) */
9375fec4b898SCarl Huang cmd->no_of_ssids = pno->uc_networks_count;
9376fec4b898SCarl Huang tlv = (struct wmi_tlv *)ptr;
9377fec4b898SCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG,
9378fec4b898SCarl Huang WMI_TAG_ARRAY_STRUCT) |
9379fec4b898SCarl Huang FIELD_PREP(WMI_TLV_LEN, nlo_list_len);
9380fec4b898SCarl Huang
9381fec4b898SCarl Huang ptr += sizeof(*tlv);
9382fec4b898SCarl Huang nlo_list = (struct nlo_configured_parameters *)ptr;
9383fec4b898SCarl Huang for (i = 0; i < cmd->no_of_ssids; i++) {
9384fec4b898SCarl Huang tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
9385fec4b898SCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9386fec4b898SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*nlo_list) - sizeof(*tlv));
9387fec4b898SCarl Huang
9388fec4b898SCarl Huang nlo_list[i].ssid.valid = true;
9389fec4b898SCarl Huang nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
9390fec4b898SCarl Huang memcpy(nlo_list[i].ssid.ssid.ssid,
9391fec4b898SCarl Huang pno->a_networks[i].ssid.ssid,
9392fec4b898SCarl Huang nlo_list[i].ssid.ssid.ssid_len);
9393fec4b898SCarl Huang ath11k_ce_byte_swap(nlo_list[i].ssid.ssid.ssid,
9394fec4b898SCarl Huang roundup(nlo_list[i].ssid.ssid.ssid_len, 4));
9395fec4b898SCarl Huang
9396fec4b898SCarl Huang if (pno->a_networks[i].rssi_threshold &&
9397fec4b898SCarl Huang pno->a_networks[i].rssi_threshold > -300) {
9398fec4b898SCarl Huang nlo_list[i].rssi_cond.valid = true;
9399fec4b898SCarl Huang nlo_list[i].rssi_cond.rssi =
9400fec4b898SCarl Huang pno->a_networks[i].rssi_threshold;
9401fec4b898SCarl Huang }
9402fec4b898SCarl Huang
9403fec4b898SCarl Huang nlo_list[i].bcast_nw_type.valid = true;
9404fec4b898SCarl Huang nlo_list[i].bcast_nw_type.bcast_nw_type =
9405fec4b898SCarl Huang pno->a_networks[i].bcast_nw_type;
9406fec4b898SCarl Huang }
9407fec4b898SCarl Huang
9408fec4b898SCarl Huang ptr += nlo_list_len;
9409fec4b898SCarl Huang cmd->num_of_channels = pno->a_networks[0].channel_count;
9410fec4b898SCarl Huang tlv = (struct wmi_tlv *)ptr;
9411fec4b898SCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
9412fec4b898SCarl Huang FIELD_PREP(WMI_TLV_LEN, channel_list_len);
9413fec4b898SCarl Huang ptr += sizeof(*tlv);
9414fec4b898SCarl Huang channel_list = (u32 *)ptr;
9415fec4b898SCarl Huang for (i = 0; i < cmd->num_of_channels; i++)
9416fec4b898SCarl Huang channel_list[i] = pno->a_networks[0].channels[i];
9417fec4b898SCarl Huang
9418fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "tlv start pno config vdev_id %d\n",
9419fec4b898SCarl Huang vdev_id);
9420fec4b898SCarl Huang
9421fec4b898SCarl Huang return skb;
9422fec4b898SCarl Huang }
9423fec4b898SCarl Huang
ath11k_wmi_op_gen_config_pno_stop(struct ath11k * ar,u32 vdev_id)9424fec4b898SCarl Huang static struct sk_buff *ath11k_wmi_op_gen_config_pno_stop(struct ath11k *ar,
9425fec4b898SCarl Huang u32 vdev_id)
9426fec4b898SCarl Huang {
9427fec4b898SCarl Huang struct wmi_wow_nlo_config_cmd *cmd;
9428fec4b898SCarl Huang struct sk_buff *skb;
9429fec4b898SCarl Huang size_t len;
9430fec4b898SCarl Huang
9431fec4b898SCarl Huang len = sizeof(*cmd);
9432fec4b898SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9433fec4b898SCarl Huang if (!skb)
9434fec4b898SCarl Huang return ERR_PTR(-ENOMEM);
9435fec4b898SCarl Huang
9436fec4b898SCarl Huang cmd = (struct wmi_wow_nlo_config_cmd *)skb->data;
9437fec4b898SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
9438fec4b898SCarl Huang FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
9439fec4b898SCarl Huang
9440fec4b898SCarl Huang cmd->vdev_id = vdev_id;
9441fec4b898SCarl Huang cmd->flags = WMI_NLO_CONFIG_STOP;
9442fec4b898SCarl Huang
9443fec4b898SCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9444fc3b984aSKalle Valo "tlv stop pno config vdev_id %d\n", vdev_id);
9445fec4b898SCarl Huang return skb;
9446fec4b898SCarl Huang }
9447fec4b898SCarl Huang
ath11k_wmi_wow_config_pno(struct ath11k * ar,u32 vdev_id,struct wmi_pno_scan_req * pno_scan)9448fec4b898SCarl Huang int ath11k_wmi_wow_config_pno(struct ath11k *ar, u32 vdev_id,
9449fec4b898SCarl Huang struct wmi_pno_scan_req *pno_scan)
9450fec4b898SCarl Huang {
9451fec4b898SCarl Huang struct sk_buff *skb;
9452fec4b898SCarl Huang
9453fec4b898SCarl Huang if (pno_scan->enable)
9454fec4b898SCarl Huang skb = ath11k_wmi_op_gen_config_pno_start(ar, vdev_id, pno_scan);
9455fec4b898SCarl Huang else
9456fec4b898SCarl Huang skb = ath11k_wmi_op_gen_config_pno_stop(ar, vdev_id);
9457fec4b898SCarl Huang
9458fec4b898SCarl Huang if (IS_ERR_OR_NULL(skb))
9459fec4b898SCarl Huang return -ENOMEM;
9460fec4b898SCarl Huang
9461fec4b898SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
9462fec4b898SCarl Huang }
9463fec4b898SCarl Huang
ath11k_wmi_fill_ns_offload(struct ath11k * ar,struct ath11k_arp_ns_offload * offload,u8 ** ptr,bool enable,bool ext)9464c3c36bfeSCarl Huang static void ath11k_wmi_fill_ns_offload(struct ath11k *ar,
9465c3c36bfeSCarl Huang struct ath11k_arp_ns_offload *offload,
9466c3c36bfeSCarl Huang u8 **ptr,
9467c3c36bfeSCarl Huang bool enable,
9468c3c36bfeSCarl Huang bool ext)
9469c3c36bfeSCarl Huang {
9470c3c36bfeSCarl Huang struct wmi_ns_offload_tuple *ns;
9471c3c36bfeSCarl Huang struct wmi_tlv *tlv;
9472c3c36bfeSCarl Huang u8 *buf_ptr = *ptr;
9473c3c36bfeSCarl Huang u32 ns_cnt, ns_ext_tuples;
9474c3c36bfeSCarl Huang int i, max_offloads;
9475c3c36bfeSCarl Huang
9476c3c36bfeSCarl Huang ns_cnt = offload->ipv6_count;
9477c3c36bfeSCarl Huang
9478c3c36bfeSCarl Huang tlv = (struct wmi_tlv *)buf_ptr;
9479c3c36bfeSCarl Huang
9480c3c36bfeSCarl Huang if (ext) {
9481c3c36bfeSCarl Huang ns_ext_tuples = offload->ipv6_count - WMI_MAX_NS_OFFLOADS;
9482c3c36bfeSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9483c3c36bfeSCarl Huang FIELD_PREP(WMI_TLV_LEN, ns_ext_tuples * sizeof(*ns));
9484c3c36bfeSCarl Huang i = WMI_MAX_NS_OFFLOADS;
9485c3c36bfeSCarl Huang max_offloads = offload->ipv6_count;
9486c3c36bfeSCarl Huang } else {
9487c3c36bfeSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9488c3c36bfeSCarl Huang FIELD_PREP(WMI_TLV_LEN, WMI_MAX_NS_OFFLOADS * sizeof(*ns));
9489c3c36bfeSCarl Huang i = 0;
9490c3c36bfeSCarl Huang max_offloads = WMI_MAX_NS_OFFLOADS;
9491c3c36bfeSCarl Huang }
9492c3c36bfeSCarl Huang
9493c3c36bfeSCarl Huang buf_ptr += sizeof(*tlv);
9494c3c36bfeSCarl Huang
9495c3c36bfeSCarl Huang for (; i < max_offloads; i++) {
9496c3c36bfeSCarl Huang ns = (struct wmi_ns_offload_tuple *)buf_ptr;
9497c3c36bfeSCarl Huang ns->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NS_OFFLOAD_TUPLE) |
9498c3c36bfeSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*ns) - TLV_HDR_SIZE);
9499c3c36bfeSCarl Huang
9500c3c36bfeSCarl Huang if (enable) {
9501c3c36bfeSCarl Huang if (i < ns_cnt)
9502c3c36bfeSCarl Huang ns->flags |= WMI_NSOL_FLAGS_VALID;
9503c3c36bfeSCarl Huang
9504c3c36bfeSCarl Huang memcpy(ns->target_ipaddr[0], offload->ipv6_addr[i], 16);
9505c3c36bfeSCarl Huang memcpy(ns->solicitation_ipaddr, offload->self_ipv6_addr[i], 16);
9506c3c36bfeSCarl Huang ath11k_ce_byte_swap(ns->target_ipaddr[0], 16);
9507c3c36bfeSCarl Huang ath11k_ce_byte_swap(ns->solicitation_ipaddr, 16);
9508c3c36bfeSCarl Huang
9509c3c36bfeSCarl Huang if (offload->ipv6_type[i])
9510c3c36bfeSCarl Huang ns->flags |= WMI_NSOL_FLAGS_IS_IPV6_ANYCAST;
9511c3c36bfeSCarl Huang
9512c3c36bfeSCarl Huang memcpy(ns->target_mac.addr, offload->mac_addr, ETH_ALEN);
9513c3c36bfeSCarl Huang ath11k_ce_byte_swap(ns->target_mac.addr, 8);
9514c3c36bfeSCarl Huang
9515c3c36bfeSCarl Huang if (ns->target_mac.word0 != 0 ||
9516c3c36bfeSCarl Huang ns->target_mac.word1 != 0) {
9517c3c36bfeSCarl Huang ns->flags |= WMI_NSOL_FLAGS_MAC_VALID;
9518c3c36bfeSCarl Huang }
9519c3c36bfeSCarl Huang
9520c3c36bfeSCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9521fc3b984aSKalle Valo "index %d ns_solicited %pI6 target %pI6",
9522c3c36bfeSCarl Huang i, ns->solicitation_ipaddr,
9523c3c36bfeSCarl Huang ns->target_ipaddr[0]);
9524c3c36bfeSCarl Huang }
9525c3c36bfeSCarl Huang
9526c3c36bfeSCarl Huang buf_ptr += sizeof(*ns);
9527c3c36bfeSCarl Huang }
9528c3c36bfeSCarl Huang
9529c3c36bfeSCarl Huang *ptr = buf_ptr;
9530c3c36bfeSCarl Huang }
9531c3c36bfeSCarl Huang
ath11k_wmi_fill_arp_offload(struct ath11k * ar,struct ath11k_arp_ns_offload * offload,u8 ** ptr,bool enable)9532c3c36bfeSCarl Huang static void ath11k_wmi_fill_arp_offload(struct ath11k *ar,
9533c3c36bfeSCarl Huang struct ath11k_arp_ns_offload *offload,
9534c3c36bfeSCarl Huang u8 **ptr,
9535c3c36bfeSCarl Huang bool enable)
9536c3c36bfeSCarl Huang {
9537c3c36bfeSCarl Huang struct wmi_arp_offload_tuple *arp;
9538c3c36bfeSCarl Huang struct wmi_tlv *tlv;
9539c3c36bfeSCarl Huang u8 *buf_ptr = *ptr;
9540c3c36bfeSCarl Huang int i;
9541c3c36bfeSCarl Huang
9542c3c36bfeSCarl Huang /* fill arp tuple */
9543c3c36bfeSCarl Huang tlv = (struct wmi_tlv *)buf_ptr;
9544c3c36bfeSCarl Huang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
9545c3c36bfeSCarl Huang FIELD_PREP(WMI_TLV_LEN, WMI_MAX_ARP_OFFLOADS * sizeof(*arp));
9546c3c36bfeSCarl Huang buf_ptr += sizeof(*tlv);
9547c3c36bfeSCarl Huang
9548c3c36bfeSCarl Huang for (i = 0; i < WMI_MAX_ARP_OFFLOADS; i++) {
9549c3c36bfeSCarl Huang arp = (struct wmi_arp_offload_tuple *)buf_ptr;
9550c3c36bfeSCarl Huang arp->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARP_OFFLOAD_TUPLE) |
9551c3c36bfeSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9552c3c36bfeSCarl Huang
9553c3c36bfeSCarl Huang if (enable && i < offload->ipv4_count) {
9554c3c36bfeSCarl Huang /* Copy the target ip addr and flags */
9555c3c36bfeSCarl Huang arp->flags = WMI_ARPOL_FLAGS_VALID;
9556c3c36bfeSCarl Huang memcpy(arp->target_ipaddr, offload->ipv4_addr[i], 4);
9557c3c36bfeSCarl Huang ath11k_ce_byte_swap(arp->target_ipaddr, 4);
9558c3c36bfeSCarl Huang
9559fc3b984aSKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "arp offload address %pI4",
9560c3c36bfeSCarl Huang arp->target_ipaddr);
9561c3c36bfeSCarl Huang }
9562c3c36bfeSCarl Huang
9563c3c36bfeSCarl Huang buf_ptr += sizeof(*arp);
9564c3c36bfeSCarl Huang }
9565c3c36bfeSCarl Huang
9566c3c36bfeSCarl Huang *ptr = buf_ptr;
9567c3c36bfeSCarl Huang }
9568c3c36bfeSCarl Huang
ath11k_wmi_arp_ns_offload(struct ath11k * ar,struct ath11k_vif * arvif,bool enable)9569c3c36bfeSCarl Huang int ath11k_wmi_arp_ns_offload(struct ath11k *ar,
9570c3c36bfeSCarl Huang struct ath11k_vif *arvif, bool enable)
9571c3c36bfeSCarl Huang {
9572c3c36bfeSCarl Huang struct ath11k_arp_ns_offload *offload;
9573c3c36bfeSCarl Huang struct wmi_set_arp_ns_offload_cmd *cmd;
9574c3c36bfeSCarl Huang struct wmi_tlv *tlv;
9575c3c36bfeSCarl Huang struct sk_buff *skb;
9576c3c36bfeSCarl Huang u8 *buf_ptr;
9577c3c36bfeSCarl Huang size_t len;
9578c3c36bfeSCarl Huang u8 ns_cnt, ns_ext_tuples = 0;
9579c3c36bfeSCarl Huang
9580c3c36bfeSCarl Huang offload = &arvif->arp_ns_offload;
9581c3c36bfeSCarl Huang ns_cnt = offload->ipv6_count;
9582c3c36bfeSCarl Huang
9583c3c36bfeSCarl Huang len = sizeof(*cmd) +
9584c3c36bfeSCarl Huang sizeof(*tlv) +
9585c3c36bfeSCarl Huang WMI_MAX_NS_OFFLOADS * sizeof(struct wmi_ns_offload_tuple) +
9586c3c36bfeSCarl Huang sizeof(*tlv) +
9587c3c36bfeSCarl Huang WMI_MAX_ARP_OFFLOADS * sizeof(struct wmi_arp_offload_tuple);
9588c3c36bfeSCarl Huang
9589c3c36bfeSCarl Huang if (ns_cnt > WMI_MAX_NS_OFFLOADS) {
9590c3c36bfeSCarl Huang ns_ext_tuples = ns_cnt - WMI_MAX_NS_OFFLOADS;
9591c3c36bfeSCarl Huang len += sizeof(*tlv) +
9592c3c36bfeSCarl Huang ns_ext_tuples * sizeof(struct wmi_ns_offload_tuple);
9593c3c36bfeSCarl Huang }
9594c3c36bfeSCarl Huang
9595c3c36bfeSCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9596c3c36bfeSCarl Huang if (!skb)
9597c3c36bfeSCarl Huang return -ENOMEM;
9598c3c36bfeSCarl Huang
9599c3c36bfeSCarl Huang buf_ptr = skb->data;
9600c3c36bfeSCarl Huang cmd = (struct wmi_set_arp_ns_offload_cmd *)buf_ptr;
9601c3c36bfeSCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9602c3c36bfeSCarl Huang WMI_TAG_SET_ARP_NS_OFFLOAD_CMD) |
9603c3c36bfeSCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9604c3c36bfeSCarl Huang
9605c3c36bfeSCarl Huang cmd->flags = 0;
9606c3c36bfeSCarl Huang cmd->vdev_id = arvif->vdev_id;
9607c3c36bfeSCarl Huang cmd->num_ns_ext_tuples = ns_ext_tuples;
9608c3c36bfeSCarl Huang
9609c3c36bfeSCarl Huang buf_ptr += sizeof(*cmd);
9610c3c36bfeSCarl Huang
9611c3c36bfeSCarl Huang ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 0);
9612c3c36bfeSCarl Huang ath11k_wmi_fill_arp_offload(ar, offload, &buf_ptr, enable);
9613c3c36bfeSCarl Huang
9614c3c36bfeSCarl Huang if (ns_ext_tuples)
9615c3c36bfeSCarl Huang ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 1);
9616c3c36bfeSCarl Huang
9617c3c36bfeSCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SET_ARP_NS_OFFLOAD_CMDID);
9618c3c36bfeSCarl Huang }
9619a16d9b50SCarl Huang
ath11k_wmi_gtk_rekey_offload(struct ath11k * ar,struct ath11k_vif * arvif,bool enable)9620a16d9b50SCarl Huang int ath11k_wmi_gtk_rekey_offload(struct ath11k *ar,
9621a16d9b50SCarl Huang struct ath11k_vif *arvif, bool enable)
9622a16d9b50SCarl Huang {
9623a16d9b50SCarl Huang struct wmi_gtk_rekey_offload_cmd *cmd;
9624a16d9b50SCarl Huang struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
9625a16d9b50SCarl Huang int len;
9626a16d9b50SCarl Huang struct sk_buff *skb;
9627a16d9b50SCarl Huang __le64 replay_ctr;
9628a16d9b50SCarl Huang
9629a16d9b50SCarl Huang len = sizeof(*cmd);
9630a16d9b50SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9631a16d9b50SCarl Huang if (!skb)
9632a16d9b50SCarl Huang return -ENOMEM;
9633a16d9b50SCarl Huang
9634a16d9b50SCarl Huang cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9635a16d9b50SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9636a16d9b50SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9637a16d9b50SCarl Huang
9638a16d9b50SCarl Huang cmd->vdev_id = arvif->vdev_id;
9639a16d9b50SCarl Huang
9640a16d9b50SCarl Huang if (enable) {
9641a16d9b50SCarl Huang cmd->flags = GTK_OFFLOAD_ENABLE_OPCODE;
9642a16d9b50SCarl Huang
9643a16d9b50SCarl Huang /* the length in rekey_data and cmd is equal */
9644a16d9b50SCarl Huang memcpy(cmd->kck, rekey_data->kck, sizeof(cmd->kck));
9645a16d9b50SCarl Huang ath11k_ce_byte_swap(cmd->kck, GTK_OFFLOAD_KEK_BYTES);
9646a16d9b50SCarl Huang memcpy(cmd->kek, rekey_data->kek, sizeof(cmd->kek));
9647a16d9b50SCarl Huang ath11k_ce_byte_swap(cmd->kek, GTK_OFFLOAD_KEK_BYTES);
9648a16d9b50SCarl Huang
9649a16d9b50SCarl Huang replay_ctr = cpu_to_le64(rekey_data->replay_ctr);
9650a16d9b50SCarl Huang memcpy(cmd->replay_ctr, &replay_ctr,
9651a16d9b50SCarl Huang sizeof(replay_ctr));
9652a16d9b50SCarl Huang ath11k_ce_byte_swap(cmd->replay_ctr, GTK_REPLAY_COUNTER_BYTES);
9653a16d9b50SCarl Huang } else {
9654a16d9b50SCarl Huang cmd->flags = GTK_OFFLOAD_DISABLE_OPCODE;
9655a16d9b50SCarl Huang }
9656a16d9b50SCarl Huang
9657a16d9b50SCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "offload gtk rekey vdev: %d %d\n",
9658a16d9b50SCarl Huang arvif->vdev_id, enable);
9659a16d9b50SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9660a16d9b50SCarl Huang }
9661a16d9b50SCarl Huang
ath11k_wmi_gtk_rekey_getinfo(struct ath11k * ar,struct ath11k_vif * arvif)9662a16d9b50SCarl Huang int ath11k_wmi_gtk_rekey_getinfo(struct ath11k *ar,
9663a16d9b50SCarl Huang struct ath11k_vif *arvif)
9664a16d9b50SCarl Huang {
9665a16d9b50SCarl Huang struct wmi_gtk_rekey_offload_cmd *cmd;
9666a16d9b50SCarl Huang int len;
9667a16d9b50SCarl Huang struct sk_buff *skb;
9668a16d9b50SCarl Huang
9669a16d9b50SCarl Huang len = sizeof(*cmd);
9670a16d9b50SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
9671a16d9b50SCarl Huang if (!skb)
9672a16d9b50SCarl Huang return -ENOMEM;
9673a16d9b50SCarl Huang
9674a16d9b50SCarl Huang cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
9675a16d9b50SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
9676a16d9b50SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9677a16d9b50SCarl Huang
9678a16d9b50SCarl Huang cmd->vdev_id = arvif->vdev_id;
9679a16d9b50SCarl Huang cmd->flags = GTK_OFFLOAD_REQUEST_STATUS_OPCODE;
9680a16d9b50SCarl Huang
9681a16d9b50SCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "get gtk rekey vdev_id: %d\n",
9682a16d9b50SCarl Huang arvif->vdev_id);
9683a16d9b50SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
9684a16d9b50SCarl Huang }
9685652f69edSBaochen Qiang
ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k * ar,const u8 * sar_val)9686652f69edSBaochen Qiang int ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k *ar, const u8 *sar_val)
9687652f69edSBaochen Qiang { struct ath11k_pdev_wmi *wmi = ar->wmi;
9688652f69edSBaochen Qiang struct wmi_pdev_set_sar_table_cmd *cmd;
9689652f69edSBaochen Qiang struct wmi_tlv *tlv;
9690652f69edSBaochen Qiang struct sk_buff *skb;
9691652f69edSBaochen Qiang u8 *buf_ptr;
9692652f69edSBaochen Qiang u32 len, sar_len_aligned, rsvd_len_aligned;
9693652f69edSBaochen Qiang
9694652f69edSBaochen Qiang sar_len_aligned = roundup(BIOS_SAR_TABLE_LEN, sizeof(u32));
9695652f69edSBaochen Qiang rsvd_len_aligned = roundup(BIOS_SAR_RSVD1_LEN, sizeof(u32));
9696652f69edSBaochen Qiang len = sizeof(*cmd) +
9697652f69edSBaochen Qiang TLV_HDR_SIZE + sar_len_aligned +
9698652f69edSBaochen Qiang TLV_HDR_SIZE + rsvd_len_aligned;
9699652f69edSBaochen Qiang
9700652f69edSBaochen Qiang skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9701652f69edSBaochen Qiang if (!skb)
9702652f69edSBaochen Qiang return -ENOMEM;
9703652f69edSBaochen Qiang
9704652f69edSBaochen Qiang cmd = (struct wmi_pdev_set_sar_table_cmd *)skb->data;
9705652f69edSBaochen Qiang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_SAR_TABLE_CMD) |
9706652f69edSBaochen Qiang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9707652f69edSBaochen Qiang cmd->pdev_id = ar->pdev->pdev_id;
9708652f69edSBaochen Qiang cmd->sar_len = BIOS_SAR_TABLE_LEN;
9709652f69edSBaochen Qiang cmd->rsvd_len = BIOS_SAR_RSVD1_LEN;
9710652f69edSBaochen Qiang
9711652f69edSBaochen Qiang buf_ptr = skb->data + sizeof(*cmd);
9712652f69edSBaochen Qiang tlv = (struct wmi_tlv *)buf_ptr;
9713652f69edSBaochen Qiang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9714652f69edSBaochen Qiang FIELD_PREP(WMI_TLV_LEN, sar_len_aligned);
9715652f69edSBaochen Qiang buf_ptr += TLV_HDR_SIZE;
9716652f69edSBaochen Qiang memcpy(buf_ptr, sar_val, BIOS_SAR_TABLE_LEN);
9717652f69edSBaochen Qiang
9718652f69edSBaochen Qiang buf_ptr += sar_len_aligned;
9719652f69edSBaochen Qiang tlv = (struct wmi_tlv *)buf_ptr;
9720652f69edSBaochen Qiang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9721652f69edSBaochen Qiang FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9722652f69edSBaochen Qiang
9723652f69edSBaochen Qiang return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_SAR_TABLE_CMDID);
9724652f69edSBaochen Qiang }
9725652f69edSBaochen Qiang
ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k * ar)9726652f69edSBaochen Qiang int ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k *ar)
9727652f69edSBaochen Qiang {
9728652f69edSBaochen Qiang struct ath11k_pdev_wmi *wmi = ar->wmi;
9729652f69edSBaochen Qiang struct wmi_pdev_set_geo_table_cmd *cmd;
9730652f69edSBaochen Qiang struct wmi_tlv *tlv;
9731652f69edSBaochen Qiang struct sk_buff *skb;
9732652f69edSBaochen Qiang u8 *buf_ptr;
9733652f69edSBaochen Qiang u32 len, rsvd_len_aligned;
9734652f69edSBaochen Qiang
9735652f69edSBaochen Qiang rsvd_len_aligned = roundup(BIOS_SAR_RSVD2_LEN, sizeof(u32));
9736652f69edSBaochen Qiang len = sizeof(*cmd) + TLV_HDR_SIZE + rsvd_len_aligned;
9737652f69edSBaochen Qiang
9738652f69edSBaochen Qiang skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
9739652f69edSBaochen Qiang if (!skb)
9740652f69edSBaochen Qiang return -ENOMEM;
9741652f69edSBaochen Qiang
9742652f69edSBaochen Qiang cmd = (struct wmi_pdev_set_geo_table_cmd *)skb->data;
9743652f69edSBaochen Qiang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_GEO_TABLE_CMD) |
9744652f69edSBaochen Qiang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9745652f69edSBaochen Qiang cmd->pdev_id = ar->pdev->pdev_id;
9746652f69edSBaochen Qiang cmd->rsvd_len = BIOS_SAR_RSVD2_LEN;
9747652f69edSBaochen Qiang
9748652f69edSBaochen Qiang buf_ptr = skb->data + sizeof(*cmd);
9749652f69edSBaochen Qiang tlv = (struct wmi_tlv *)buf_ptr;
9750652f69edSBaochen Qiang tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
9751652f69edSBaochen Qiang FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
9752652f69edSBaochen Qiang
9753652f69edSBaochen Qiang return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_GEO_TABLE_CMDID);
9754652f69edSBaochen Qiang }
97550f84a156SBaochen Qiang
ath11k_wmi_sta_keepalive(struct ath11k * ar,const struct wmi_sta_keepalive_arg * arg)97560f84a156SBaochen Qiang int ath11k_wmi_sta_keepalive(struct ath11k *ar,
97570f84a156SBaochen Qiang const struct wmi_sta_keepalive_arg *arg)
97580f84a156SBaochen Qiang {
97590f84a156SBaochen Qiang struct ath11k_pdev_wmi *wmi = ar->wmi;
97600f84a156SBaochen Qiang struct wmi_sta_keepalive_cmd *cmd;
97610f84a156SBaochen Qiang struct wmi_sta_keepalive_arp_resp *arp;
97620f84a156SBaochen Qiang struct sk_buff *skb;
97630f84a156SBaochen Qiang size_t len;
97640f84a156SBaochen Qiang
97650f84a156SBaochen Qiang len = sizeof(*cmd) + sizeof(*arp);
97660f84a156SBaochen Qiang skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
97670f84a156SBaochen Qiang if (!skb)
97680f84a156SBaochen Qiang return -ENOMEM;
97690f84a156SBaochen Qiang
97700f84a156SBaochen Qiang cmd = (struct wmi_sta_keepalive_cmd *)skb->data;
97710f84a156SBaochen Qiang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
97720f84a156SBaochen Qiang WMI_TAG_STA_KEEPALIVE_CMD) |
97730f84a156SBaochen Qiang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
97740f84a156SBaochen Qiang cmd->vdev_id = arg->vdev_id;
97750f84a156SBaochen Qiang cmd->enabled = arg->enabled;
97760f84a156SBaochen Qiang cmd->interval = arg->interval;
97770f84a156SBaochen Qiang cmd->method = arg->method;
97780f84a156SBaochen Qiang
97790f84a156SBaochen Qiang arp = (struct wmi_sta_keepalive_arp_resp *)(cmd + 1);
97800f84a156SBaochen Qiang arp->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9781b7b6f861SBaochen Qiang WMI_TAG_STA_KEEPALIVE_ARP_RESPONSE) |
97820f84a156SBaochen Qiang FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9783b7b6f861SBaochen Qiang
9784b7b6f861SBaochen Qiang if (arg->method == WMI_STA_KEEPALIVE_METHOD_UNSOLICITED_ARP_RESPONSE ||
9785b7b6f861SBaochen Qiang arg->method == WMI_STA_KEEPALIVE_METHOD_GRATUITOUS_ARP_REQUEST) {
97860f84a156SBaochen Qiang arp->src_ip4_addr = arg->src_ip4_addr;
97870f84a156SBaochen Qiang arp->dest_ip4_addr = arg->dest_ip4_addr;
97880f84a156SBaochen Qiang ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
97890f84a156SBaochen Qiang }
97900f84a156SBaochen Qiang
97910f84a156SBaochen Qiang ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9792fc3b984aSKalle Valo "sta keepalive vdev %d enabled %d method %d interval %d\n",
97930f84a156SBaochen Qiang arg->vdev_id, arg->enabled, arg->method, arg->interval);
97940f84a156SBaochen Qiang
97950f84a156SBaochen Qiang return ath11k_wmi_cmd_send(wmi, skb, WMI_STA_KEEPALIVE_CMDID);
97960f84a156SBaochen Qiang }
9797