1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021, Qualcomm Innovation Center, Inc. All rights reserved.
5 */
6 #include <linux/skbuff.h>
7 #include <linux/ctype.h>
8 #include <net/mac80211.h>
9 #include <net/cfg80211.h>
10 #include <linux/completion.h>
11 #include <linux/if_ether.h>
12 #include <linux/types.h>
13 #include <linux/pci.h>
14 #include <linux/uuid.h>
15 #include <linux/time.h>
16 #include <linux/of.h>
17 #include "core.h"
18 #include "debug.h"
19 #include "mac.h"
20 #include "hw.h"
21 #include "peer.h"
22
23 struct wmi_tlv_policy {
24 size_t min_len;
25 };
26
27 struct wmi_tlv_svc_ready_parse {
28 bool wmi_svc_bitmap_done;
29 };
30
31 struct wmi_tlv_dma_ring_caps_parse {
32 struct wmi_dma_ring_capabilities *dma_ring_caps;
33 u32 n_dma_ring_caps;
34 };
35
36 struct wmi_tlv_svc_rdy_ext_parse {
37 struct ath11k_service_ext_param param;
38 struct wmi_soc_mac_phy_hw_mode_caps *hw_caps;
39 struct wmi_hw_mode_capabilities *hw_mode_caps;
40 u32 n_hw_mode_caps;
41 u32 tot_phy_id;
42 struct wmi_hw_mode_capabilities pref_hw_mode_caps;
43 struct wmi_mac_phy_capabilities *mac_phy_caps;
44 u32 n_mac_phy_caps;
45 struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps;
46 struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps;
47 u32 n_ext_hal_reg_caps;
48 struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
49 bool hw_mode_done;
50 bool mac_phy_done;
51 bool ext_hal_reg_done;
52 bool mac_phy_chainmask_combo_done;
53 bool mac_phy_chainmask_cap_done;
54 bool oem_dma_ring_cap_done;
55 bool dma_ring_cap_done;
56 };
57
58 struct wmi_tlv_svc_rdy_ext2_parse {
59 struct wmi_tlv_dma_ring_caps_parse dma_caps_parse;
60 bool dma_ring_cap_done;
61 };
62
63 struct wmi_tlv_rdy_parse {
64 u32 num_extra_mac_addr;
65 };
66
67 struct wmi_tlv_dma_buf_release_parse {
68 struct ath11k_wmi_dma_buf_release_fixed_param fixed;
69 struct wmi_dma_buf_release_entry *buf_entry;
70 struct wmi_dma_buf_release_meta_data *meta_data;
71 u32 num_buf_entry;
72 u32 num_meta;
73 bool buf_entry_done;
74 bool meta_data_done;
75 };
76
77 struct wmi_tlv_fw_stats_parse {
78 const struct wmi_stats_event *ev;
79 const struct wmi_per_chain_rssi_stats *rssi;
80 struct ath11k_fw_stats *stats;
81 int rssi_num;
82 bool chain_rssi_done;
83 };
84
85 static const struct wmi_tlv_policy wmi_tlv_policies[] = {
86 [WMI_TAG_ARRAY_BYTE]
87 = { .min_len = 0 },
88 [WMI_TAG_ARRAY_UINT32]
89 = { .min_len = 0 },
90 [WMI_TAG_SERVICE_READY_EVENT]
91 = { .min_len = sizeof(struct wmi_service_ready_event) },
92 [WMI_TAG_SERVICE_READY_EXT_EVENT]
93 = { .min_len = sizeof(struct wmi_service_ready_ext_event) },
94 [WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS]
95 = { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) },
96 [WMI_TAG_SOC_HAL_REG_CAPABILITIES]
97 = { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) },
98 [WMI_TAG_VDEV_START_RESPONSE_EVENT]
99 = { .min_len = sizeof(struct wmi_vdev_start_resp_event) },
100 [WMI_TAG_PEER_DELETE_RESP_EVENT]
101 = { .min_len = sizeof(struct wmi_peer_delete_resp_event) },
102 [WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]
103 = { .min_len = sizeof(struct wmi_bcn_tx_status_event) },
104 [WMI_TAG_VDEV_STOPPED_EVENT]
105 = { .min_len = sizeof(struct wmi_vdev_stopped_event) },
106 [WMI_TAG_REG_CHAN_LIST_CC_EVENT]
107 = { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) },
108 [WMI_TAG_MGMT_RX_HDR]
109 = { .min_len = sizeof(struct wmi_mgmt_rx_hdr) },
110 [WMI_TAG_MGMT_TX_COMPL_EVENT]
111 = { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) },
112 [WMI_TAG_SCAN_EVENT]
113 = { .min_len = sizeof(struct wmi_scan_event) },
114 [WMI_TAG_PEER_STA_KICKOUT_EVENT]
115 = { .min_len = sizeof(struct wmi_peer_sta_kickout_event) },
116 [WMI_TAG_ROAM_EVENT]
117 = { .min_len = sizeof(struct wmi_roam_event) },
118 [WMI_TAG_CHAN_INFO_EVENT]
119 = { .min_len = sizeof(struct wmi_chan_info_event) },
120 [WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]
121 = { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) },
122 [WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]
123 = { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) },
124 [WMI_TAG_READY_EVENT] = {
125 .min_len = sizeof(struct wmi_ready_event_min) },
126 [WMI_TAG_SERVICE_AVAILABLE_EVENT]
127 = {.min_len = sizeof(struct wmi_service_available_event) },
128 [WMI_TAG_PEER_ASSOC_CONF_EVENT]
129 = { .min_len = sizeof(struct wmi_peer_assoc_conf_event) },
130 [WMI_TAG_STATS_EVENT]
131 = { .min_len = sizeof(struct wmi_stats_event) },
132 [WMI_TAG_RFKILL_EVENT] = {
133 .min_len = sizeof(struct wmi_rfkill_state_change_ev) },
134 [WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]
135 = { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) },
136 [WMI_TAG_HOST_SWFDA_EVENT] = {
137 .min_len = sizeof(struct wmi_fils_discovery_event) },
138 [WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT] = {
139 .min_len = sizeof(struct wmi_probe_resp_tx_status_event) },
140 [WMI_TAG_VDEV_DELETE_RESP_EVENT] = {
141 .min_len = sizeof(struct wmi_vdev_delete_resp_event) },
142 [WMI_TAG_OBSS_COLOR_COLLISION_EVT] = {
143 .min_len = sizeof(struct wmi_obss_color_collision_event) },
144 [WMI_TAG_11D_NEW_COUNTRY_EVENT] = {
145 .min_len = sizeof(struct wmi_11d_new_cc_ev) },
146 [WMI_TAG_PER_CHAIN_RSSI_STATS] = {
147 .min_len = sizeof(struct wmi_per_chain_rssi_stats) },
148 [WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT] = {
149 .min_len = sizeof(struct wmi_twt_add_dialog_event) },
150 };
151
152 #define PRIMAP(_hw_mode_) \
153 [_hw_mode_] = _hw_mode_##_PRI
154
155 static const int ath11k_hw_mode_pri_map[] = {
156 PRIMAP(WMI_HOST_HW_MODE_SINGLE),
157 PRIMAP(WMI_HOST_HW_MODE_DBS),
158 PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE),
159 PRIMAP(WMI_HOST_HW_MODE_SBS),
160 PRIMAP(WMI_HOST_HW_MODE_DBS_SBS),
161 PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS),
162 /* keep last */
163 PRIMAP(WMI_HOST_HW_MODE_MAX),
164 };
165
166 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)167 ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len,
168 int (*iter)(struct ath11k_base *ab, u16 tag, u16 len,
169 const void *ptr, void *data),
170 void *data)
171 {
172 const void *begin = ptr;
173 const struct wmi_tlv *tlv;
174 u16 tlv_tag, tlv_len;
175 int ret;
176
177 while (len > 0) {
178 if (len < sizeof(*tlv)) {
179 ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n",
180 ptr - begin, len, sizeof(*tlv));
181 return -EINVAL;
182 }
183
184 tlv = ptr;
185 tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header);
186 tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header);
187 ptr += sizeof(*tlv);
188 len -= sizeof(*tlv);
189
190 if (tlv_len > len) {
191 ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n",
192 tlv_tag, ptr - begin, len, tlv_len);
193 return -EINVAL;
194 }
195
196 if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) &&
197 wmi_tlv_policies[tlv_tag].min_len &&
198 wmi_tlv_policies[tlv_tag].min_len > tlv_len) {
199 ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%u bytes is less than min length %zu)\n",
200 tlv_tag, ptr - begin, tlv_len,
201 wmi_tlv_policies[tlv_tag].min_len);
202 return -EINVAL;
203 }
204
205 ret = iter(ab, tlv_tag, tlv_len, ptr, data);
206 if (ret)
207 return ret;
208
209 ptr += tlv_len;
210 len -= tlv_len;
211 }
212
213 return 0;
214 }
215
ath11k_wmi_tlv_iter_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)216 static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len,
217 const void *ptr, void *data)
218 {
219 const void **tb = data;
220
221 if (tag < WMI_TAG_MAX)
222 tb[tag] = ptr;
223
224 return 0;
225 }
226
ath11k_wmi_tlv_parse(struct ath11k_base * ar,const void ** tb,const void * ptr,size_t len)227 static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb,
228 const void *ptr, size_t len)
229 {
230 return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse,
231 (void *)tb);
232 }
233
234 static const void **
ath11k_wmi_tlv_parse_alloc(struct ath11k_base * ab,const void * ptr,size_t len,gfp_t gfp)235 ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr,
236 size_t len, gfp_t gfp)
237 {
238 const void **tb;
239 int ret;
240
241 tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp);
242 if (!tb)
243 return ERR_PTR(-ENOMEM);
244
245 ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len);
246 if (ret) {
247 kfree(tb);
248 return ERR_PTR(ret);
249 }
250
251 return tb;
252 }
253
ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi * wmi,struct sk_buff * skb,u32 cmd_id)254 static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
255 u32 cmd_id)
256 {
257 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
258 struct ath11k_base *ab = wmi->wmi_ab->ab;
259 struct wmi_cmd_hdr *cmd_hdr;
260 int ret;
261 u32 cmd = 0;
262
263 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
264 return -ENOMEM;
265
266 cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id);
267
268 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
269 cmd_hdr->cmd_id = cmd;
270
271 trace_ath11k_wmi_cmd(ab, cmd_id, skb->data, skb->len);
272
273 memset(skb_cb, 0, sizeof(*skb_cb));
274 ret = ath11k_htc_send(&ab->htc, wmi->eid, skb);
275
276 if (ret)
277 goto err_pull;
278
279 return 0;
280
281 err_pull:
282 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
283 return ret;
284 }
285
ath11k_wmi_cmd_send(struct ath11k_pdev_wmi * wmi,struct sk_buff * skb,u32 cmd_id)286 int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb,
287 u32 cmd_id)
288 {
289 struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab;
290 int ret = -EOPNOTSUPP;
291 struct ath11k_base *ab = wmi_sc->ab;
292
293 might_sleep();
294
295 if (ab->hw_params.credit_flow) {
296 wait_event_timeout(wmi_sc->tx_credits_wq, ({
297 ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
298
299 if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
300 &wmi_sc->ab->dev_flags))
301 ret = -ESHUTDOWN;
302
303 (ret != -EAGAIN);
304 }), WMI_SEND_TIMEOUT_HZ);
305 } else {
306 wait_event_timeout(wmi->tx_ce_desc_wq, ({
307 ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id);
308
309 if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH,
310 &wmi_sc->ab->dev_flags))
311 ret = -ESHUTDOWN;
312
313 (ret != -ENOBUFS);
314 }), WMI_SEND_TIMEOUT_HZ);
315 }
316
317 if (ret == -EAGAIN)
318 ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id);
319
320 if (ret == -ENOBUFS)
321 ath11k_warn(wmi_sc->ab, "ce desc not available for wmi command %d\n",
322 cmd_id);
323
324 return ret;
325 }
326
ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi * wmi_handle,const void * ptr,struct ath11k_service_ext_param * param)327 static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
328 const void *ptr,
329 struct ath11k_service_ext_param *param)
330 {
331 const struct wmi_service_ready_ext_event *ev = ptr;
332
333 if (!ev)
334 return -EINVAL;
335
336 /* Move this to host based bitmap */
337 param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits;
338 param->default_fw_config_bits = ev->default_fw_config_bits;
339 param->he_cap_info = ev->he_cap_info;
340 param->mpdu_density = ev->mpdu_density;
341 param->max_bssid_rx_filters = ev->max_bssid_rx_filters;
342 memcpy(¶m->ppet, &ev->ppet, sizeof(param->ppet));
343
344 return 0;
345 }
346
347 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)348 ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle,
349 struct wmi_soc_mac_phy_hw_mode_caps *hw_caps,
350 struct wmi_hw_mode_capabilities *wmi_hw_mode_caps,
351 struct wmi_soc_hal_reg_capabilities *hal_reg_caps,
352 struct wmi_mac_phy_capabilities *wmi_mac_phy_caps,
353 u8 hw_mode_id, u8 phy_id,
354 struct ath11k_pdev *pdev)
355 {
356 struct wmi_mac_phy_capabilities *mac_phy_caps;
357 struct ath11k_base *ab = wmi_handle->wmi_ab->ab;
358 struct ath11k_band_cap *cap_band;
359 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
360 u32 phy_map;
361 u32 hw_idx, phy_idx = 0;
362
363 if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps)
364 return -EINVAL;
365
366 for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) {
367 if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id)
368 break;
369
370 phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map;
371 while (phy_map) {
372 phy_map >>= 1;
373 phy_idx++;
374 }
375 }
376
377 if (hw_idx == hw_caps->num_hw_modes)
378 return -EINVAL;
379
380 phy_idx += phy_id;
381 if (phy_id >= hal_reg_caps->num_phy)
382 return -EINVAL;
383
384 mac_phy_caps = wmi_mac_phy_caps + phy_idx;
385
386 pdev->pdev_id = mac_phy_caps->pdev_id;
387 pdev_cap->supported_bands |= mac_phy_caps->supported_bands;
388 pdev_cap->ampdu_density = mac_phy_caps->ampdu_density;
389 ab->target_pdev_ids[ab->target_pdev_count].supported_bands =
390 mac_phy_caps->supported_bands;
391 ab->target_pdev_ids[ab->target_pdev_count].pdev_id = mac_phy_caps->pdev_id;
392 ab->target_pdev_count++;
393
394 if (!(mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) &&
395 !(mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP))
396 return -EINVAL;
397
398 /* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from
399 * band to band for a single radio, need to see how this should be
400 * handled.
401 */
402 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
403 pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g;
404 pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g;
405 }
406
407 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
408 pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g;
409 pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g;
410 pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g;
411 pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g;
412 pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g;
413 pdev_cap->nss_ratio_enabled =
414 WMI_NSS_RATIO_ENABLE_DISABLE_GET(mac_phy_caps->nss_ratio);
415 pdev_cap->nss_ratio_info =
416 WMI_NSS_RATIO_INFO_GET(mac_phy_caps->nss_ratio);
417 }
418
419 /* tx/rx chainmask reported from fw depends on the actual hw chains used,
420 * For example, for 4x4 capable macphys, first 4 chains can be used for first
421 * mac and the remaing 4 chains can be used for the second mac or vice-versa.
422 * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0
423 * will be advertised for second mac or vice-versa. Compute the shift value
424 * for tx/rx chainmask which will be used to advertise supported ht/vht rates to
425 * mac80211.
426 */
427 pdev_cap->tx_chain_mask_shift =
428 find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32);
429 pdev_cap->rx_chain_mask_shift =
430 find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32);
431
432 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) {
433 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
434 cap_band->phy_id = mac_phy_caps->phy_id;
435 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g;
436 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g;
437 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g;
438 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext;
439 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g;
440 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g,
441 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
442 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g,
443 sizeof(struct ath11k_ppe_threshold));
444 }
445
446 if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) {
447 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
448 cap_band->phy_id = mac_phy_caps->phy_id;
449 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
450 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
451 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
452 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
453 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
454 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
455 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
456 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
457 sizeof(struct ath11k_ppe_threshold));
458
459 cap_band = &pdev_cap->band[NL80211_BAND_6GHZ];
460 cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g;
461 cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g;
462 cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g;
463 cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext;
464 cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g;
465 memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g,
466 sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE);
467 memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g,
468 sizeof(struct ath11k_ppe_threshold));
469 }
470
471 return 0;
472 }
473
474 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)475 ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle,
476 struct wmi_soc_hal_reg_capabilities *reg_caps,
477 struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap,
478 u8 phy_idx,
479 struct ath11k_hal_reg_capabilities_ext *param)
480 {
481 struct wmi_hal_reg_capabilities_ext *ext_reg_cap;
482
483 if (!reg_caps || !wmi_ext_reg_cap)
484 return -EINVAL;
485
486 if (phy_idx >= reg_caps->num_phy)
487 return -EINVAL;
488
489 ext_reg_cap = &wmi_ext_reg_cap[phy_idx];
490
491 param->phy_id = ext_reg_cap->phy_id;
492 param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain;
493 param->eeprom_reg_domain_ext =
494 ext_reg_cap->eeprom_reg_domain_ext;
495 param->regcap1 = ext_reg_cap->regcap1;
496 param->regcap2 = ext_reg_cap->regcap2;
497 /* check if param->wireless_mode is needed */
498 param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan;
499 param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan;
500 param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan;
501 param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan;
502
503 return 0;
504 }
505
ath11k_pull_service_ready_tlv(struct ath11k_base * ab,const void * evt_buf,struct ath11k_targ_cap * cap)506 static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab,
507 const void *evt_buf,
508 struct ath11k_targ_cap *cap)
509 {
510 const struct wmi_service_ready_event *ev = evt_buf;
511
512 if (!ev) {
513 ath11k_err(ab, "%s: failed by NULL param\n",
514 __func__);
515 return -EINVAL;
516 }
517
518 cap->phy_capability = ev->phy_capability;
519 cap->max_frag_entry = ev->max_frag_entry;
520 cap->num_rf_chains = ev->num_rf_chains;
521 cap->ht_cap_info = ev->ht_cap_info;
522 cap->vht_cap_info = ev->vht_cap_info;
523 cap->vht_supp_mcs = ev->vht_supp_mcs;
524 cap->hw_min_tx_power = ev->hw_min_tx_power;
525 cap->hw_max_tx_power = ev->hw_max_tx_power;
526 cap->sys_cap_info = ev->sys_cap_info;
527 cap->min_pkt_size_enable = ev->min_pkt_size_enable;
528 cap->max_bcn_ie_size = ev->max_bcn_ie_size;
529 cap->max_num_scan_channels = ev->max_num_scan_channels;
530 cap->max_supported_macs = ev->max_supported_macs;
531 cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps;
532 cap->txrx_chainmask = ev->txrx_chainmask;
533 cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index;
534 cap->num_msdu_desc = ev->num_msdu_desc;
535
536 ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi sys cap info 0x%x\n", cap->sys_cap_info);
537
538 return 0;
539 }
540
541 /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in
542 * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each
543 * 4-byte word.
544 */
ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi * wmi,const u32 * wmi_svc_bm)545 static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi,
546 const u32 *wmi_svc_bm)
547 {
548 int i, j;
549
550 for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) {
551 do {
552 if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32))
553 set_bit(j, wmi->wmi_ab->svc_map);
554 } while (++j % WMI_SERVICE_BITS_IN_SIZE32);
555 }
556 }
557
ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)558 static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
559 const void *ptr, void *data)
560 {
561 struct wmi_tlv_svc_ready_parse *svc_ready = data;
562 struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
563 u16 expect_len;
564
565 switch (tag) {
566 case WMI_TAG_SERVICE_READY_EVENT:
567 if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps))
568 return -EINVAL;
569 break;
570
571 case WMI_TAG_ARRAY_UINT32:
572 if (!svc_ready->wmi_svc_bitmap_done) {
573 expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32);
574 if (len < expect_len) {
575 ath11k_warn(ab, "invalid len %d for the tag 0x%x\n",
576 len, tag);
577 return -EINVAL;
578 }
579
580 ath11k_wmi_service_bitmap_copy(wmi_handle, ptr);
581
582 svc_ready->wmi_svc_bitmap_done = true;
583 }
584 break;
585 default:
586 break;
587 }
588
589 return 0;
590 }
591
ath11k_service_ready_event(struct ath11k_base * ab,struct sk_buff * skb)592 static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
593 {
594 struct wmi_tlv_svc_ready_parse svc_ready = { };
595 int ret;
596
597 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
598 ath11k_wmi_tlv_svc_rdy_parse,
599 &svc_ready);
600 if (ret) {
601 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
602 return ret;
603 }
604
605 return 0;
606 }
607
ath11k_wmi_alloc_skb(struct ath11k_wmi_base * wmi_sc,u32 len)608 struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len)
609 {
610 struct sk_buff *skb;
611 struct ath11k_base *ab = wmi_sc->ab;
612 u32 round_len = roundup(len, 4);
613
614 skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len);
615 if (!skb)
616 return NULL;
617
618 skb_reserve(skb, WMI_SKB_HEADROOM);
619 if (!IS_ALIGNED((unsigned long)skb->data, 4))
620 ath11k_warn(ab, "unaligned WMI skb data\n");
621
622 skb_put(skb, round_len);
623 memset(skb->data, 0, round_len);
624
625 return skb;
626 }
627
ath11k_wmi_mgmt_get_freq(struct ath11k * ar,struct ieee80211_tx_info * info)628 static u32 ath11k_wmi_mgmt_get_freq(struct ath11k *ar,
629 struct ieee80211_tx_info *info)
630 {
631 struct ath11k_base *ab = ar->ab;
632 u32 freq = 0;
633
634 if (ab->hw_params.support_off_channel_tx &&
635 ar->scan.is_roc &&
636 (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN))
637 freq = ar->scan.roc_freq;
638
639 return freq;
640 }
641
ath11k_wmi_mgmt_send(struct ath11k * ar,u32 vdev_id,u32 buf_id,struct sk_buff * frame)642 int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id,
643 struct sk_buff *frame)
644 {
645 struct ath11k_pdev_wmi *wmi = ar->wmi;
646 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(frame);
647 struct wmi_mgmt_send_cmd *cmd;
648 struct wmi_tlv *frame_tlv;
649 struct sk_buff *skb;
650 u32 buf_len;
651 int ret, len;
652
653 buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ?
654 frame->len : WMI_MGMT_SEND_DOWNLD_LEN;
655
656 len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4);
657
658 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
659 if (!skb)
660 return -ENOMEM;
661
662 cmd = (struct wmi_mgmt_send_cmd *)skb->data;
663 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) |
664 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
665 cmd->vdev_id = vdev_id;
666 cmd->desc_id = buf_id;
667 cmd->chanfreq = ath11k_wmi_mgmt_get_freq(ar, info);
668 cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr);
669 cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr);
670 cmd->frame_len = frame->len;
671 cmd->buf_len = buf_len;
672 cmd->tx_params_valid = 0;
673
674 frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
675 frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
676 FIELD_PREP(WMI_TLV_LEN, buf_len);
677
678 memcpy(frame_tlv->value, frame->data, buf_len);
679
680 ath11k_ce_byte_swap(frame_tlv->value, buf_len);
681
682 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID);
683 if (ret) {
684 ath11k_warn(ar->ab,
685 "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n");
686 dev_kfree_skb(skb);
687 }
688
689 return ret;
690 }
691
ath11k_wmi_vdev_create(struct ath11k * ar,u8 * macaddr,struct vdev_create_params * param)692 int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr,
693 struct vdev_create_params *param)
694 {
695 struct ath11k_pdev_wmi *wmi = ar->wmi;
696 struct wmi_vdev_create_cmd *cmd;
697 struct sk_buff *skb;
698 struct wmi_vdev_txrx_streams *txrx_streams;
699 struct wmi_tlv *tlv;
700 int ret, len;
701 void *ptr;
702
703 /* It can be optimized my sending tx/rx chain configuration
704 * only for supported bands instead of always sending it for
705 * both the bands.
706 */
707 len = sizeof(*cmd) + TLV_HDR_SIZE +
708 (WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams));
709
710 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
711 if (!skb)
712 return -ENOMEM;
713
714 cmd = (struct wmi_vdev_create_cmd *)skb->data;
715 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) |
716 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
717
718 cmd->vdev_id = param->if_id;
719 cmd->vdev_type = param->type;
720 cmd->vdev_subtype = param->subtype;
721 cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX;
722 cmd->pdev_id = param->pdev_id;
723 ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
724
725 ptr = skb->data + sizeof(*cmd);
726 len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams);
727
728 tlv = ptr;
729 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
730 FIELD_PREP(WMI_TLV_LEN, len);
731
732 ptr += TLV_HDR_SIZE;
733 txrx_streams = ptr;
734 len = sizeof(*txrx_streams);
735 txrx_streams->tlv_header =
736 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
737 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
738 txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G;
739 txrx_streams->supported_tx_streams =
740 param->chains[NL80211_BAND_2GHZ].tx;
741 txrx_streams->supported_rx_streams =
742 param->chains[NL80211_BAND_2GHZ].rx;
743
744 txrx_streams++;
745 txrx_streams->tlv_header =
746 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) |
747 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
748 txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G;
749 txrx_streams->supported_tx_streams =
750 param->chains[NL80211_BAND_5GHZ].tx;
751 txrx_streams->supported_rx_streams =
752 param->chains[NL80211_BAND_5GHZ].rx;
753
754 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID);
755 if (ret) {
756 ath11k_warn(ar->ab,
757 "failed to submit WMI_VDEV_CREATE_CMDID\n");
758 dev_kfree_skb(skb);
759 }
760
761 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
762 "WMI vdev create: id %d type %d subtype %d macaddr %pM pdevid %d\n",
763 param->if_id, param->type, param->subtype,
764 macaddr, param->pdev_id);
765
766 return ret;
767 }
768
ath11k_wmi_vdev_delete(struct ath11k * ar,u8 vdev_id)769 int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id)
770 {
771 struct ath11k_pdev_wmi *wmi = ar->wmi;
772 struct wmi_vdev_delete_cmd *cmd;
773 struct sk_buff *skb;
774 int ret;
775
776 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
777 if (!skb)
778 return -ENOMEM;
779
780 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
781 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) |
782 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
783 cmd->vdev_id = vdev_id;
784
785 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID);
786 if (ret) {
787 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n");
788 dev_kfree_skb(skb);
789 }
790
791 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev delete id %d\n", vdev_id);
792
793 return ret;
794 }
795
ath11k_wmi_vdev_stop(struct ath11k * ar,u8 vdev_id)796 int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id)
797 {
798 struct ath11k_pdev_wmi *wmi = ar->wmi;
799 struct wmi_vdev_stop_cmd *cmd;
800 struct sk_buff *skb;
801 int ret;
802
803 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
804 if (!skb)
805 return -ENOMEM;
806
807 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
808
809 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) |
810 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
811 cmd->vdev_id = vdev_id;
812
813 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID);
814 if (ret) {
815 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n");
816 dev_kfree_skb(skb);
817 }
818
819 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev stop id 0x%x\n", vdev_id);
820
821 return ret;
822 }
823
ath11k_wmi_vdev_down(struct ath11k * ar,u8 vdev_id)824 int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id)
825 {
826 struct ath11k_pdev_wmi *wmi = ar->wmi;
827 struct wmi_vdev_down_cmd *cmd;
828 struct sk_buff *skb;
829 int ret;
830
831 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
832 if (!skb)
833 return -ENOMEM;
834
835 cmd = (struct wmi_vdev_down_cmd *)skb->data;
836
837 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) |
838 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
839 cmd->vdev_id = vdev_id;
840
841 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID);
842 if (ret) {
843 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n");
844 dev_kfree_skb(skb);
845 }
846
847 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev down id 0x%x\n", vdev_id);
848
849 return ret;
850 }
851
ath11k_wmi_put_wmi_channel(struct wmi_channel * chan,struct wmi_vdev_start_req_arg * arg)852 static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan,
853 struct wmi_vdev_start_req_arg *arg)
854 {
855 u32 center_freq1 = arg->channel.band_center_freq1;
856
857 memset(chan, 0, sizeof(*chan));
858
859 chan->mhz = arg->channel.freq;
860 chan->band_center_freq1 = arg->channel.band_center_freq1;
861
862 if (arg->channel.mode == MODE_11AX_HE160) {
863 if (arg->channel.freq > arg->channel.band_center_freq1)
864 chan->band_center_freq1 = center_freq1 + 40;
865 else
866 chan->band_center_freq1 = center_freq1 - 40;
867
868 chan->band_center_freq2 = arg->channel.band_center_freq1;
869
870 } else if (arg->channel.mode == MODE_11AC_VHT80_80) {
871 chan->band_center_freq2 = arg->channel.band_center_freq2;
872 } else {
873 chan->band_center_freq2 = 0;
874 }
875
876 chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode);
877 if (arg->channel.passive)
878 chan->info |= WMI_CHAN_INFO_PASSIVE;
879 if (arg->channel.allow_ibss)
880 chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED;
881 if (arg->channel.allow_ht)
882 chan->info |= WMI_CHAN_INFO_ALLOW_HT;
883 if (arg->channel.allow_vht)
884 chan->info |= WMI_CHAN_INFO_ALLOW_VHT;
885 if (arg->channel.allow_he)
886 chan->info |= WMI_CHAN_INFO_ALLOW_HE;
887 if (arg->channel.ht40plus)
888 chan->info |= WMI_CHAN_INFO_HT40_PLUS;
889 if (arg->channel.chan_radar)
890 chan->info |= WMI_CHAN_INFO_DFS;
891 if (arg->channel.freq2_radar)
892 chan->info |= WMI_CHAN_INFO_DFS_FREQ2;
893
894 chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
895 arg->channel.max_power) |
896 FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
897 arg->channel.max_reg_power);
898
899 chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
900 arg->channel.max_antenna_gain) |
901 FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
902 arg->channel.max_power);
903 }
904
ath11k_wmi_vdev_start(struct ath11k * ar,struct wmi_vdev_start_req_arg * arg,bool restart)905 int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg,
906 bool restart)
907 {
908 struct ath11k_pdev_wmi *wmi = ar->wmi;
909 struct wmi_vdev_start_request_cmd *cmd;
910 struct sk_buff *skb;
911 struct wmi_channel *chan;
912 struct wmi_tlv *tlv;
913 void *ptr;
914 int ret, len;
915
916 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
917 return -EINVAL;
918
919 len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE;
920
921 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
922 if (!skb)
923 return -ENOMEM;
924
925 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
926 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
927 WMI_TAG_VDEV_START_REQUEST_CMD) |
928 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
929 cmd->vdev_id = arg->vdev_id;
930 cmd->beacon_interval = arg->bcn_intval;
931 cmd->bcn_tx_rate = arg->bcn_tx_rate;
932 cmd->dtim_period = arg->dtim_period;
933 cmd->num_noa_descriptors = arg->num_noa_descriptors;
934 cmd->preferred_rx_streams = arg->pref_rx_streams;
935 cmd->preferred_tx_streams = arg->pref_tx_streams;
936 cmd->cac_duration_ms = arg->cac_duration_ms;
937 cmd->regdomain = arg->regdomain;
938 cmd->he_ops = arg->he_ops;
939
940 if (!restart) {
941 if (arg->ssid) {
942 cmd->ssid.ssid_len = arg->ssid_len;
943 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
944 }
945 if (arg->hidden_ssid)
946 cmd->flags |= WMI_VDEV_START_HIDDEN_SSID;
947 if (arg->pmf_enabled)
948 cmd->flags |= WMI_VDEV_START_PMF_ENABLED;
949 }
950
951 cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED;
952 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
953 cmd->flags |= WMI_VDEV_START_HW_ENCRYPTION_DISABLED;
954
955 ptr = skb->data + sizeof(*cmd);
956 chan = ptr;
957
958 ath11k_wmi_put_wmi_channel(chan, arg);
959
960 chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) |
961 FIELD_PREP(WMI_TLV_LEN,
962 sizeof(*chan) - TLV_HDR_SIZE);
963 ptr += sizeof(*chan);
964
965 tlv = ptr;
966 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
967 FIELD_PREP(WMI_TLV_LEN, 0);
968
969 /* Note: This is a nested TLV containing:
970 * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv]..
971 */
972
973 ptr += sizeof(*tlv);
974
975 if (restart)
976 ret = ath11k_wmi_cmd_send(wmi, skb,
977 WMI_VDEV_RESTART_REQUEST_CMDID);
978 else
979 ret = ath11k_wmi_cmd_send(wmi, skb,
980 WMI_VDEV_START_REQUEST_CMDID);
981 if (ret) {
982 ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n",
983 restart ? "restart" : "start");
984 dev_kfree_skb(skb);
985 }
986
987 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "vdev %s id 0x%x freq 0x%x mode 0x%x\n",
988 restart ? "restart" : "start", arg->vdev_id,
989 arg->channel.freq, arg->channel.mode);
990
991 return ret;
992 }
993
ath11k_wmi_vdev_up(struct ath11k * ar,u32 vdev_id,u32 aid,const u8 * bssid)994 int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
995 {
996 struct ath11k_pdev_wmi *wmi = ar->wmi;
997 struct wmi_vdev_up_cmd *cmd;
998 struct sk_buff *skb;
999 int ret;
1000
1001 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1002 if (!skb)
1003 return -ENOMEM;
1004
1005 cmd = (struct wmi_vdev_up_cmd *)skb->data;
1006
1007 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) |
1008 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1009 cmd->vdev_id = vdev_id;
1010 cmd->vdev_assoc_id = aid;
1011
1012 ether_addr_copy(cmd->vdev_bssid.addr, bssid);
1013
1014 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID);
1015 if (ret) {
1016 ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n");
1017 dev_kfree_skb(skb);
1018 }
1019
1020 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1021 "WMI mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
1022 vdev_id, aid, bssid);
1023
1024 return ret;
1025 }
1026
ath11k_wmi_send_peer_create_cmd(struct ath11k * ar,struct peer_create_params * param)1027 int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar,
1028 struct peer_create_params *param)
1029 {
1030 struct ath11k_pdev_wmi *wmi = ar->wmi;
1031 struct wmi_peer_create_cmd *cmd;
1032 struct sk_buff *skb;
1033 int ret;
1034
1035 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1036 if (!skb)
1037 return -ENOMEM;
1038
1039 cmd = (struct wmi_peer_create_cmd *)skb->data;
1040 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) |
1041 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1042
1043 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr);
1044 cmd->peer_type = param->peer_type;
1045 cmd->vdev_id = param->vdev_id;
1046
1047 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID);
1048 if (ret) {
1049 ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n");
1050 dev_kfree_skb(skb);
1051 }
1052
1053 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1054 "WMI peer create vdev_id %d peer_addr %pM\n",
1055 param->vdev_id, param->peer_addr);
1056
1057 return ret;
1058 }
1059
ath11k_wmi_send_peer_delete_cmd(struct ath11k * ar,const u8 * peer_addr,u8 vdev_id)1060 int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar,
1061 const u8 *peer_addr, u8 vdev_id)
1062 {
1063 struct ath11k_pdev_wmi *wmi = ar->wmi;
1064 struct wmi_peer_delete_cmd *cmd;
1065 struct sk_buff *skb;
1066 int ret;
1067
1068 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1069 if (!skb)
1070 return -ENOMEM;
1071
1072 cmd = (struct wmi_peer_delete_cmd *)skb->data;
1073 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) |
1074 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1075
1076 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1077 cmd->vdev_id = vdev_id;
1078
1079 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1080 "WMI peer delete vdev_id %d peer_addr %pM\n",
1081 vdev_id, peer_addr);
1082
1083 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID);
1084 if (ret) {
1085 ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n");
1086 dev_kfree_skb(skb);
1087 }
1088
1089 return ret;
1090 }
1091
ath11k_wmi_send_pdev_set_regdomain(struct ath11k * ar,struct pdev_set_regdomain_params * param)1092 int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar,
1093 struct pdev_set_regdomain_params *param)
1094 {
1095 struct ath11k_pdev_wmi *wmi = ar->wmi;
1096 struct wmi_pdev_set_regdomain_cmd *cmd;
1097 struct sk_buff *skb;
1098 int ret;
1099
1100 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1101 if (!skb)
1102 return -ENOMEM;
1103
1104 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1105 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1106 WMI_TAG_PDEV_SET_REGDOMAIN_CMD) |
1107 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1108
1109 cmd->reg_domain = param->current_rd_in_use;
1110 cmd->reg_domain_2g = param->current_rd_2g;
1111 cmd->reg_domain_5g = param->current_rd_5g;
1112 cmd->conformance_test_limit_2g = param->ctl_2g;
1113 cmd->conformance_test_limit_5g = param->ctl_5g;
1114 cmd->dfs_domain = param->dfs_domain;
1115 cmd->pdev_id = param->pdev_id;
1116
1117 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1118 "WMI pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n",
1119 param->current_rd_in_use, param->current_rd_2g,
1120 param->current_rd_5g, param->dfs_domain, param->pdev_id);
1121
1122 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1123 if (ret) {
1124 ath11k_warn(ar->ab,
1125 "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n");
1126 dev_kfree_skb(skb);
1127 }
1128
1129 return ret;
1130 }
1131
ath11k_wmi_set_peer_param(struct ath11k * ar,const u8 * peer_addr,u32 vdev_id,u32 param_id,u32 param_val)1132 int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr,
1133 u32 vdev_id, u32 param_id, u32 param_val)
1134 {
1135 struct ath11k_pdev_wmi *wmi = ar->wmi;
1136 struct wmi_peer_set_param_cmd *cmd;
1137 struct sk_buff *skb;
1138 int ret;
1139
1140 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1141 if (!skb)
1142 return -ENOMEM;
1143
1144 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1145 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) |
1146 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1147 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1148 cmd->vdev_id = vdev_id;
1149 cmd->param_id = param_id;
1150 cmd->param_value = param_val;
1151
1152 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID);
1153 if (ret) {
1154 ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n");
1155 dev_kfree_skb(skb);
1156 }
1157
1158 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1159 "WMI vdev %d peer 0x%pM set param %d value %d\n",
1160 vdev_id, peer_addr, param_id, param_val);
1161
1162 return ret;
1163 }
1164
ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k * ar,u8 peer_addr[ETH_ALEN],struct peer_flush_params * param)1165 int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar,
1166 u8 peer_addr[ETH_ALEN],
1167 struct peer_flush_params *param)
1168 {
1169 struct ath11k_pdev_wmi *wmi = ar->wmi;
1170 struct wmi_peer_flush_tids_cmd *cmd;
1171 struct sk_buff *skb;
1172 int ret;
1173
1174 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1175 if (!skb)
1176 return -ENOMEM;
1177
1178 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1179 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) |
1180 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1181
1182 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1183 cmd->peer_tid_bitmap = param->peer_tid_bitmap;
1184 cmd->vdev_id = param->vdev_id;
1185
1186 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1187 if (ret) {
1188 ath11k_warn(ar->ab,
1189 "failed to send WMI_PEER_FLUSH_TIDS cmd\n");
1190 dev_kfree_skb(skb);
1191 }
1192
1193 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1194 "WMI peer flush vdev_id %d peer_addr %pM tids %08x\n",
1195 param->vdev_id, peer_addr, param->peer_tid_bitmap);
1196
1197 return ret;
1198 }
1199
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)1200 int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar,
1201 int vdev_id, const u8 *addr,
1202 dma_addr_t paddr, u8 tid,
1203 u8 ba_window_size_valid,
1204 u32 ba_window_size)
1205 {
1206 struct wmi_peer_reorder_queue_setup_cmd *cmd;
1207 struct sk_buff *skb;
1208 int ret;
1209
1210 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
1211 if (!skb)
1212 return -ENOMEM;
1213
1214 cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data;
1215 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1216 WMI_TAG_REORDER_QUEUE_SETUP_CMD) |
1217 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1218
1219 ether_addr_copy(cmd->peer_macaddr.addr, addr);
1220 cmd->vdev_id = vdev_id;
1221 cmd->tid = tid;
1222 cmd->queue_ptr_lo = lower_32_bits(paddr);
1223 cmd->queue_ptr_hi = upper_32_bits(paddr);
1224 cmd->queue_no = tid;
1225 cmd->ba_window_size_valid = ba_window_size_valid;
1226 cmd->ba_window_size = ba_window_size;
1227
1228 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
1229 WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1230 if (ret) {
1231 ath11k_warn(ar->ab,
1232 "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n");
1233 dev_kfree_skb(skb);
1234 }
1235
1236 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1237 "wmi rx reorder queue setup addr %pM vdev_id %d tid %d\n",
1238 addr, vdev_id, tid);
1239
1240 return ret;
1241 }
1242
1243 int
ath11k_wmi_rx_reord_queue_remove(struct ath11k * ar,struct rx_reorder_queue_remove_params * param)1244 ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar,
1245 struct rx_reorder_queue_remove_params *param)
1246 {
1247 struct ath11k_pdev_wmi *wmi = ar->wmi;
1248 struct wmi_peer_reorder_queue_remove_cmd *cmd;
1249 struct sk_buff *skb;
1250 int ret;
1251
1252 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1253 if (!skb)
1254 return -ENOMEM;
1255
1256 cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data;
1257 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1258 WMI_TAG_REORDER_QUEUE_REMOVE_CMD) |
1259 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1260
1261 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr);
1262 cmd->vdev_id = param->vdev_id;
1263 cmd->tid_mask = param->peer_tid_bitmap;
1264
1265 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1266 "%s: peer_macaddr %pM vdev_id %d, tid_map %d", __func__,
1267 param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap);
1268
1269 ret = ath11k_wmi_cmd_send(wmi, skb,
1270 WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
1271 if (ret) {
1272 ath11k_warn(ar->ab,
1273 "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID");
1274 dev_kfree_skb(skb);
1275 }
1276
1277 return ret;
1278 }
1279
ath11k_wmi_pdev_set_param(struct ath11k * ar,u32 param_id,u32 param_value,u8 pdev_id)1280 int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id,
1281 u32 param_value, u8 pdev_id)
1282 {
1283 struct ath11k_pdev_wmi *wmi = ar->wmi;
1284 struct wmi_pdev_set_param_cmd *cmd;
1285 struct sk_buff *skb;
1286 int ret;
1287
1288 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1289 if (!skb)
1290 return -ENOMEM;
1291
1292 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1293 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) |
1294 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1295 cmd->pdev_id = pdev_id;
1296 cmd->param_id = param_id;
1297 cmd->param_value = param_value;
1298
1299 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID);
1300 if (ret) {
1301 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1302 dev_kfree_skb(skb);
1303 }
1304
1305 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1306 "WMI pdev set param %d pdev id %d value %d\n",
1307 param_id, pdev_id, param_value);
1308
1309 return ret;
1310 }
1311
ath11k_wmi_pdev_set_ps_mode(struct ath11k * ar,int vdev_id,enum wmi_sta_ps_mode psmode)1312 int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id,
1313 enum wmi_sta_ps_mode psmode)
1314 {
1315 struct ath11k_pdev_wmi *wmi = ar->wmi;
1316 struct wmi_pdev_set_ps_mode_cmd *cmd;
1317 struct sk_buff *skb;
1318 int ret;
1319
1320 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1321 if (!skb)
1322 return -ENOMEM;
1323
1324 cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data;
1325 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) |
1326 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1327 cmd->vdev_id = vdev_id;
1328 cmd->sta_ps_mode = psmode;
1329
1330 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID);
1331 if (ret) {
1332 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n");
1333 dev_kfree_skb(skb);
1334 }
1335
1336 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1337 "WMI vdev set psmode %d vdev id %d\n",
1338 psmode, vdev_id);
1339
1340 return ret;
1341 }
1342
ath11k_wmi_pdev_suspend(struct ath11k * ar,u32 suspend_opt,u32 pdev_id)1343 int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt,
1344 u32 pdev_id)
1345 {
1346 struct ath11k_pdev_wmi *wmi = ar->wmi;
1347 struct wmi_pdev_suspend_cmd *cmd;
1348 struct sk_buff *skb;
1349 int ret;
1350
1351 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1352 if (!skb)
1353 return -ENOMEM;
1354
1355 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1356
1357 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) |
1358 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1359
1360 cmd->suspend_opt = suspend_opt;
1361 cmd->pdev_id = pdev_id;
1362
1363 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID);
1364 if (ret) {
1365 ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n");
1366 dev_kfree_skb(skb);
1367 }
1368
1369 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1370 "WMI pdev suspend pdev_id %d\n", pdev_id);
1371
1372 return ret;
1373 }
1374
ath11k_wmi_pdev_resume(struct ath11k * ar,u32 pdev_id)1375 int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id)
1376 {
1377 struct ath11k_pdev_wmi *wmi = ar->wmi;
1378 struct wmi_pdev_resume_cmd *cmd;
1379 struct sk_buff *skb;
1380 int ret;
1381
1382 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1383 if (!skb)
1384 return -ENOMEM;
1385
1386 cmd = (struct wmi_pdev_resume_cmd *)skb->data;
1387
1388 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) |
1389 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1390 cmd->pdev_id = pdev_id;
1391
1392 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1393 "WMI pdev resume pdev id %d\n", pdev_id);
1394
1395 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID);
1396 if (ret) {
1397 ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n");
1398 dev_kfree_skb(skb);
1399 }
1400
1401 return ret;
1402 }
1403
1404 /* TODO FW Support for the cmd is not available yet.
1405 * Can be tested once the command and corresponding
1406 * event is implemented in FW
1407 */
ath11k_wmi_pdev_bss_chan_info_request(struct ath11k * ar,enum wmi_bss_chan_info_req_type type)1408 int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar,
1409 enum wmi_bss_chan_info_req_type type)
1410 {
1411 struct ath11k_pdev_wmi *wmi = ar->wmi;
1412 struct wmi_pdev_bss_chan_info_req_cmd *cmd;
1413 struct sk_buff *skb;
1414 int ret;
1415
1416 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1417 if (!skb)
1418 return -ENOMEM;
1419
1420 cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data;
1421
1422 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1423 WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) |
1424 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1425 cmd->req_type = type;
1426 cmd->pdev_id = ar->pdev->pdev_id;
1427
1428 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1429 "WMI bss chan info req type %d\n", type);
1430
1431 ret = ath11k_wmi_cmd_send(wmi, skb,
1432 WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID);
1433 if (ret) {
1434 ath11k_warn(ar->ab,
1435 "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n");
1436 dev_kfree_skb(skb);
1437 }
1438
1439 return ret;
1440 }
1441
ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k * ar,u8 * peer_addr,struct ap_ps_params * param)1442 int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr,
1443 struct ap_ps_params *param)
1444 {
1445 struct ath11k_pdev_wmi *wmi = ar->wmi;
1446 struct wmi_ap_ps_peer_cmd *cmd;
1447 struct sk_buff *skb;
1448 int ret;
1449
1450 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1451 if (!skb)
1452 return -ENOMEM;
1453
1454 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1455 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) |
1456 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1457
1458 cmd->vdev_id = param->vdev_id;
1459 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
1460 cmd->param = param->param;
1461 cmd->value = param->value;
1462
1463 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1464 if (ret) {
1465 ath11k_warn(ar->ab,
1466 "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n");
1467 dev_kfree_skb(skb);
1468 }
1469
1470 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1471 "WMI set ap ps vdev id %d peer %pM param %d value %d\n",
1472 param->vdev_id, peer_addr, param->param, param->value);
1473
1474 return ret;
1475 }
1476
ath11k_wmi_set_sta_ps_param(struct ath11k * ar,u32 vdev_id,u32 param,u32 param_value)1477 int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id,
1478 u32 param, u32 param_value)
1479 {
1480 struct ath11k_pdev_wmi *wmi = ar->wmi;
1481 struct wmi_sta_powersave_param_cmd *cmd;
1482 struct sk_buff *skb;
1483 int ret;
1484
1485 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1486 if (!skb)
1487 return -ENOMEM;
1488
1489 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1490 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1491 WMI_TAG_STA_POWERSAVE_PARAM_CMD) |
1492 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1493
1494 cmd->vdev_id = vdev_id;
1495 cmd->param = param;
1496 cmd->value = param_value;
1497
1498 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1499 "WMI set sta ps vdev_id %d param %d value %d\n",
1500 vdev_id, param, param_value);
1501
1502 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1503 if (ret) {
1504 ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID");
1505 dev_kfree_skb(skb);
1506 }
1507
1508 return ret;
1509 }
1510
ath11k_wmi_force_fw_hang_cmd(struct ath11k * ar,u32 type,u32 delay_time_ms)1511 int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms)
1512 {
1513 struct ath11k_pdev_wmi *wmi = ar->wmi;
1514 struct wmi_force_fw_hang_cmd *cmd;
1515 struct sk_buff *skb;
1516 int ret, len;
1517
1518 len = sizeof(*cmd);
1519
1520 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1521 if (!skb)
1522 return -ENOMEM;
1523
1524 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
1525 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) |
1526 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1527
1528 cmd->type = type;
1529 cmd->delay_time_ms = delay_time_ms;
1530
1531 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID);
1532
1533 if (ret) {
1534 ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID");
1535 dev_kfree_skb(skb);
1536 }
1537 return ret;
1538 }
1539
ath11k_wmi_vdev_set_param_cmd(struct ath11k * ar,u32 vdev_id,u32 param_id,u32 param_value)1540 int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id,
1541 u32 param_id, u32 param_value)
1542 {
1543 struct ath11k_pdev_wmi *wmi = ar->wmi;
1544 struct wmi_vdev_set_param_cmd *cmd;
1545 struct sk_buff *skb;
1546 int ret;
1547
1548 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1549 if (!skb)
1550 return -ENOMEM;
1551
1552 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1553 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) |
1554 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1555
1556 cmd->vdev_id = vdev_id;
1557 cmd->param_id = param_id;
1558 cmd->param_value = param_value;
1559
1560 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID);
1561 if (ret) {
1562 ath11k_warn(ar->ab,
1563 "failed to send WMI_VDEV_SET_PARAM_CMDID\n");
1564 dev_kfree_skb(skb);
1565 }
1566
1567 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1568 "WMI vdev id 0x%x set param %d value %d\n",
1569 vdev_id, param_id, param_value);
1570
1571 return ret;
1572 }
1573
ath11k_wmi_send_stats_request_cmd(struct ath11k * ar,struct stats_request_params * param)1574 int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar,
1575 struct stats_request_params *param)
1576 {
1577 struct ath11k_pdev_wmi *wmi = ar->wmi;
1578 struct wmi_request_stats_cmd *cmd;
1579 struct sk_buff *skb;
1580 int ret;
1581
1582 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1583 if (!skb)
1584 return -ENOMEM;
1585
1586 cmd = (struct wmi_request_stats_cmd *)skb->data;
1587 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) |
1588 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1589
1590 cmd->stats_id = param->stats_id;
1591 cmd->vdev_id = param->vdev_id;
1592 cmd->pdev_id = param->pdev_id;
1593
1594 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID);
1595 if (ret) {
1596 ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n");
1597 dev_kfree_skb(skb);
1598 }
1599
1600 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1601 "WMI request stats 0x%x vdev id %d pdev id %d\n",
1602 param->stats_id, param->vdev_id, param->pdev_id);
1603
1604 return ret;
1605 }
1606
ath11k_wmi_send_pdev_temperature_cmd(struct ath11k * ar)1607 int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar)
1608 {
1609 struct ath11k_pdev_wmi *wmi = ar->wmi;
1610 struct wmi_get_pdev_temperature_cmd *cmd;
1611 struct sk_buff *skb;
1612 int ret;
1613
1614 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1615 if (!skb)
1616 return -ENOMEM;
1617
1618 cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data;
1619 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) |
1620 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1621 cmd->pdev_id = ar->pdev->pdev_id;
1622
1623 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID);
1624 if (ret) {
1625 ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n");
1626 dev_kfree_skb(skb);
1627 }
1628
1629 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1630 "WMI pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id);
1631
1632 return ret;
1633 }
1634
ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k * ar,u32 vdev_id,u32 bcn_ctrl_op)1635 int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar,
1636 u32 vdev_id, u32 bcn_ctrl_op)
1637 {
1638 struct ath11k_pdev_wmi *wmi = ar->wmi;
1639 struct wmi_bcn_offload_ctrl_cmd *cmd;
1640 struct sk_buff *skb;
1641 int ret;
1642
1643 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
1644 if (!skb)
1645 return -ENOMEM;
1646
1647 cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data;
1648 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1649 WMI_TAG_BCN_OFFLOAD_CTRL_CMD) |
1650 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1651
1652 cmd->vdev_id = vdev_id;
1653 cmd->bcn_ctrl_op = bcn_ctrl_op;
1654
1655 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1656 "WMI bcn ctrl offload vdev id %d ctrl_op %d\n",
1657 vdev_id, bcn_ctrl_op);
1658
1659 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID);
1660 if (ret) {
1661 ath11k_warn(ar->ab,
1662 "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n");
1663 dev_kfree_skb(skb);
1664 }
1665
1666 return ret;
1667 }
1668
ath11k_wmi_bcn_tmpl(struct ath11k * ar,u32 vdev_id,struct ieee80211_mutable_offsets * offs,struct sk_buff * bcn)1669 int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id,
1670 struct ieee80211_mutable_offsets *offs,
1671 struct sk_buff *bcn)
1672 {
1673 struct ath11k_pdev_wmi *wmi = ar->wmi;
1674 struct wmi_bcn_tmpl_cmd *cmd;
1675 struct wmi_bcn_prb_info *bcn_prb_info;
1676 struct wmi_tlv *tlv;
1677 struct sk_buff *skb;
1678 void *ptr;
1679 int ret, len;
1680 size_t aligned_len = roundup(bcn->len, 4);
1681 struct ieee80211_vif *vif;
1682 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev_id);
1683
1684 if (!arvif) {
1685 ath11k_warn(ar->ab, "failed to find arvif with vdev id %d\n", vdev_id);
1686 return -EINVAL;
1687 }
1688
1689 vif = arvif->vif;
1690
1691 len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len;
1692
1693 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1694 if (!skb)
1695 return -ENOMEM;
1696
1697 cmd = (struct wmi_bcn_tmpl_cmd *)skb->data;
1698 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) |
1699 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1700 cmd->vdev_id = vdev_id;
1701 cmd->tim_ie_offset = offs->tim_offset;
1702
1703 if (vif->bss_conf.csa_active) {
1704 cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0];
1705 cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1];
1706 }
1707
1708 cmd->buf_len = bcn->len;
1709
1710 ptr = skb->data + sizeof(*cmd);
1711
1712 bcn_prb_info = ptr;
1713 len = sizeof(*bcn_prb_info);
1714 bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1715 WMI_TAG_BCN_PRB_INFO) |
1716 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
1717 bcn_prb_info->caps = 0;
1718 bcn_prb_info->erp = 0;
1719
1720 ptr += sizeof(*bcn_prb_info);
1721
1722 tlv = ptr;
1723 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1724 FIELD_PREP(WMI_TLV_LEN, aligned_len);
1725 memcpy(tlv->value, bcn->data, bcn->len);
1726
1727 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID);
1728 if (ret) {
1729 ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n");
1730 dev_kfree_skb(skb);
1731 }
1732
1733 return ret;
1734 }
1735
ath11k_wmi_vdev_install_key(struct ath11k * ar,struct wmi_vdev_install_key_arg * arg)1736 int ath11k_wmi_vdev_install_key(struct ath11k *ar,
1737 struct wmi_vdev_install_key_arg *arg)
1738 {
1739 struct ath11k_pdev_wmi *wmi = ar->wmi;
1740 struct wmi_vdev_install_key_cmd *cmd;
1741 struct wmi_tlv *tlv;
1742 struct sk_buff *skb;
1743 int ret, len;
1744 int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t));
1745
1746 len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned;
1747
1748 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1749 if (!skb)
1750 return -ENOMEM;
1751
1752 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1753 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) |
1754 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1755 cmd->vdev_id = arg->vdev_id;
1756 ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
1757 cmd->key_idx = arg->key_idx;
1758 cmd->key_flags = arg->key_flags;
1759 cmd->key_cipher = arg->key_cipher;
1760 cmd->key_len = arg->key_len;
1761 cmd->key_txmic_len = arg->key_txmic_len;
1762 cmd->key_rxmic_len = arg->key_rxmic_len;
1763
1764 if (arg->key_rsc_counter)
1765 memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter,
1766 sizeof(struct wmi_key_seq_counter));
1767
1768 tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
1769 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1770 FIELD_PREP(WMI_TLV_LEN, key_len_aligned);
1771 if (arg->key_data)
1772 memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned);
1773
1774 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1775 if (ret) {
1776 ath11k_warn(ar->ab,
1777 "failed to send WMI_VDEV_INSTALL_KEY cmd\n");
1778 dev_kfree_skb(skb);
1779 }
1780
1781 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1782 "WMI vdev install key idx %d cipher %d len %d\n",
1783 arg->key_idx, arg->key_cipher, arg->key_len);
1784
1785 return ret;
1786 }
1787
1788 static inline void
ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd * cmd,struct peer_assoc_params * param,bool hw_crypto_disabled)1789 ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd,
1790 struct peer_assoc_params *param,
1791 bool hw_crypto_disabled)
1792 {
1793 cmd->peer_flags = 0;
1794
1795 if (param->is_wme_set) {
1796 if (param->qos_flag)
1797 cmd->peer_flags |= WMI_PEER_QOS;
1798 if (param->apsd_flag)
1799 cmd->peer_flags |= WMI_PEER_APSD;
1800 if (param->ht_flag)
1801 cmd->peer_flags |= WMI_PEER_HT;
1802 if (param->bw_40)
1803 cmd->peer_flags |= WMI_PEER_40MHZ;
1804 if (param->bw_80)
1805 cmd->peer_flags |= WMI_PEER_80MHZ;
1806 if (param->bw_160)
1807 cmd->peer_flags |= WMI_PEER_160MHZ;
1808
1809 /* Typically if STBC is enabled for VHT it should be enabled
1810 * for HT as well
1811 **/
1812 if (param->stbc_flag)
1813 cmd->peer_flags |= WMI_PEER_STBC;
1814
1815 /* Typically if LDPC is enabled for VHT it should be enabled
1816 * for HT as well
1817 **/
1818 if (param->ldpc_flag)
1819 cmd->peer_flags |= WMI_PEER_LDPC;
1820
1821 if (param->static_mimops_flag)
1822 cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1823 if (param->dynamic_mimops_flag)
1824 cmd->peer_flags |= WMI_PEER_DYN_MIMOPS;
1825 if (param->spatial_mux_flag)
1826 cmd->peer_flags |= WMI_PEER_SPATIAL_MUX;
1827 if (param->vht_flag)
1828 cmd->peer_flags |= WMI_PEER_VHT;
1829 if (param->he_flag)
1830 cmd->peer_flags |= WMI_PEER_HE;
1831 if (param->twt_requester)
1832 cmd->peer_flags |= WMI_PEER_TWT_REQ;
1833 if (param->twt_responder)
1834 cmd->peer_flags |= WMI_PEER_TWT_RESP;
1835 }
1836
1837 /* Suppress authorization for all AUTH modes that need 4-way handshake
1838 * (during re-association).
1839 * Authorization will be done for these modes on key installation.
1840 */
1841 if (param->auth_flag)
1842 cmd->peer_flags |= WMI_PEER_AUTH;
1843 if (param->need_ptk_4_way) {
1844 cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1845 if (!hw_crypto_disabled && param->is_assoc)
1846 cmd->peer_flags &= ~WMI_PEER_AUTH;
1847 }
1848 if (param->need_gtk_2_way)
1849 cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1850 /* safe mode bypass the 4-way handshake */
1851 if (param->safe_mode_enabled)
1852 cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY |
1853 WMI_PEER_NEED_GTK_2_WAY);
1854
1855 if (param->is_pmf_enabled)
1856 cmd->peer_flags |= WMI_PEER_PMF;
1857
1858 /* Disable AMSDU for station transmit, if user configures it */
1859 /* Disable AMSDU for AP transmit to 11n Stations, if user configures
1860 * it
1861 * if (param->amsdu_disable) Add after FW support
1862 **/
1863
1864 /* Target asserts if node is marked HT and all MCS is set to 0.
1865 * Mark the node as non-HT if all the mcs rates are disabled through
1866 * iwpriv
1867 **/
1868 if (param->peer_ht_rates.num_rates == 0)
1869 cmd->peer_flags &= ~WMI_PEER_HT;
1870 }
1871
ath11k_wmi_send_peer_assoc_cmd(struct ath11k * ar,struct peer_assoc_params * param)1872 int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar,
1873 struct peer_assoc_params *param)
1874 {
1875 struct ath11k_pdev_wmi *wmi = ar->wmi;
1876 struct wmi_peer_assoc_complete_cmd *cmd;
1877 struct wmi_vht_rate_set *mcs;
1878 struct wmi_he_rate_set *he_mcs;
1879 struct sk_buff *skb;
1880 struct wmi_tlv *tlv;
1881 void *ptr;
1882 u32 peer_legacy_rates_align;
1883 u32 peer_ht_rates_align;
1884 int i, ret, len;
1885
1886 peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates,
1887 sizeof(u32));
1888 peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates,
1889 sizeof(u32));
1890
1891 len = sizeof(*cmd) +
1892 TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) +
1893 TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) +
1894 sizeof(*mcs) + TLV_HDR_SIZE +
1895 (sizeof(*he_mcs) * param->peer_he_mcs_count);
1896
1897 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
1898 if (!skb)
1899 return -ENOMEM;
1900
1901 ptr = skb->data;
1902
1903 cmd = ptr;
1904 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
1905 WMI_TAG_PEER_ASSOC_COMPLETE_CMD) |
1906 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
1907
1908 cmd->vdev_id = param->vdev_id;
1909
1910 cmd->peer_new_assoc = param->peer_new_assoc;
1911 cmd->peer_associd = param->peer_associd;
1912
1913 ath11k_wmi_copy_peer_flags(cmd, param,
1914 test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED,
1915 &ar->ab->dev_flags));
1916
1917 ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac);
1918
1919 cmd->peer_rate_caps = param->peer_rate_caps;
1920 cmd->peer_caps = param->peer_caps;
1921 cmd->peer_listen_intval = param->peer_listen_intval;
1922 cmd->peer_ht_caps = param->peer_ht_caps;
1923 cmd->peer_max_mpdu = param->peer_max_mpdu;
1924 cmd->peer_mpdu_density = param->peer_mpdu_density;
1925 cmd->peer_vht_caps = param->peer_vht_caps;
1926 cmd->peer_phymode = param->peer_phymode;
1927
1928 /* Update 11ax capabilities */
1929 cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0];
1930 cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1];
1931 cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal;
1932 cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz;
1933 cmd->peer_he_ops = param->peer_he_ops;
1934 memcpy(&cmd->peer_he_cap_phy, ¶m->peer_he_cap_phyinfo,
1935 sizeof(param->peer_he_cap_phyinfo));
1936 memcpy(&cmd->peer_ppet, ¶m->peer_ppet,
1937 sizeof(param->peer_ppet));
1938
1939 /* Update peer legacy rate information */
1940 ptr += sizeof(*cmd);
1941
1942 tlv = ptr;
1943 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1944 FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align);
1945
1946 ptr += TLV_HDR_SIZE;
1947
1948 cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates;
1949 memcpy(ptr, param->peer_legacy_rates.rates,
1950 param->peer_legacy_rates.num_rates);
1951
1952 /* Update peer HT rate information */
1953 ptr += peer_legacy_rates_align;
1954
1955 tlv = ptr;
1956 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
1957 FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align);
1958 ptr += TLV_HDR_SIZE;
1959 cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates;
1960 memcpy(ptr, param->peer_ht_rates.rates,
1961 param->peer_ht_rates.num_rates);
1962
1963 /* VHT Rates */
1964 ptr += peer_ht_rates_align;
1965
1966 mcs = ptr;
1967
1968 mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) |
1969 FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE);
1970
1971 cmd->peer_nss = param->peer_nss;
1972
1973 /* Update bandwidth-NSS mapping */
1974 cmd->peer_bw_rxnss_override = 0;
1975 cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override;
1976
1977 if (param->vht_capable) {
1978 mcs->rx_max_rate = param->rx_max_rate;
1979 mcs->rx_mcs_set = param->rx_mcs_set;
1980 mcs->tx_max_rate = param->tx_max_rate;
1981 mcs->tx_mcs_set = param->tx_mcs_set;
1982 }
1983
1984 /* HE Rates */
1985 cmd->peer_he_mcs = param->peer_he_mcs_count;
1986 cmd->min_data_rate = param->min_data_rate;
1987
1988 ptr += sizeof(*mcs);
1989
1990 len = param->peer_he_mcs_count * sizeof(*he_mcs);
1991
1992 tlv = ptr;
1993 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
1994 FIELD_PREP(WMI_TLV_LEN, len);
1995 ptr += TLV_HDR_SIZE;
1996
1997 /* Loop through the HE rate set */
1998 for (i = 0; i < param->peer_he_mcs_count; i++) {
1999 he_mcs = ptr;
2000 he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2001 WMI_TAG_HE_RATE_SET) |
2002 FIELD_PREP(WMI_TLV_LEN,
2003 sizeof(*he_mcs) - TLV_HDR_SIZE);
2004
2005 he_mcs->rx_mcs_set = param->peer_he_tx_mcs_set[i];
2006 he_mcs->tx_mcs_set = param->peer_he_rx_mcs_set[i];
2007 ptr += sizeof(*he_mcs);
2008 }
2009
2010 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID);
2011 if (ret) {
2012 ath11k_warn(ar->ab,
2013 "failed to send WMI_PEER_ASSOC_CMDID\n");
2014 dev_kfree_skb(skb);
2015 }
2016
2017 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2018 "wmi peer assoc vdev id %d assoc id %d peer mac %pM peer_flags %x rate_caps %x peer_caps %x listen_intval %d ht_caps %x max_mpdu %d nss %d phymode %d peer_mpdu_density %d vht_caps %x he cap_info %x he ops %x he cap_info_ext %x he phy %x %x %x peer_bw_rxnss_override %x\n",
2019 cmd->vdev_id, cmd->peer_associd, param->peer_mac,
2020 cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps,
2021 cmd->peer_listen_intval, cmd->peer_ht_caps,
2022 cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode,
2023 cmd->peer_mpdu_density,
2024 cmd->peer_vht_caps, cmd->peer_he_cap_info,
2025 cmd->peer_he_ops, cmd->peer_he_cap_info_ext,
2026 cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1],
2027 cmd->peer_he_cap_phy[2],
2028 cmd->peer_bw_rxnss_override);
2029
2030 return ret;
2031 }
2032
ath11k_wmi_start_scan_init(struct ath11k * ar,struct scan_req_params * arg)2033 void ath11k_wmi_start_scan_init(struct ath11k *ar,
2034 struct scan_req_params *arg)
2035 {
2036 /* setup commonly used values */
2037 arg->scan_req_id = 1;
2038 if (ar->state_11d == ATH11K_11D_PREPARING)
2039 arg->scan_priority = WMI_SCAN_PRIORITY_MEDIUM;
2040 else
2041 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
2042 arg->dwell_time_active = 50;
2043 arg->dwell_time_active_2g = 0;
2044 arg->dwell_time_passive = 150;
2045 arg->dwell_time_active_6g = 40;
2046 arg->dwell_time_passive_6g = 30;
2047 arg->min_rest_time = 50;
2048 arg->max_rest_time = 500;
2049 arg->repeat_probe_time = 0;
2050 arg->probe_spacing_time = 0;
2051 arg->idle_time = 0;
2052 arg->max_scan_time = 20000;
2053 arg->probe_delay = 5;
2054 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED |
2055 WMI_SCAN_EVENT_COMPLETED |
2056 WMI_SCAN_EVENT_BSS_CHANNEL |
2057 WMI_SCAN_EVENT_FOREIGN_CHAN |
2058 WMI_SCAN_EVENT_DEQUEUED;
2059 arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2060 arg->num_bssid = 1;
2061
2062 /* fill bssid_list[0] with 0xff, otherwise bssid and RA will be
2063 * ZEROs in probe request
2064 */
2065 eth_broadcast_addr(arg->bssid_list[0].addr);
2066 }
2067
2068 static inline void
ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd * cmd,struct scan_req_params * param)2069 ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd,
2070 struct scan_req_params *param)
2071 {
2072 /* Scan events subscription */
2073 if (param->scan_ev_started)
2074 cmd->notify_scan_events |= WMI_SCAN_EVENT_STARTED;
2075 if (param->scan_ev_completed)
2076 cmd->notify_scan_events |= WMI_SCAN_EVENT_COMPLETED;
2077 if (param->scan_ev_bss_chan)
2078 cmd->notify_scan_events |= WMI_SCAN_EVENT_BSS_CHANNEL;
2079 if (param->scan_ev_foreign_chan)
2080 cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN;
2081 if (param->scan_ev_dequeued)
2082 cmd->notify_scan_events |= WMI_SCAN_EVENT_DEQUEUED;
2083 if (param->scan_ev_preempted)
2084 cmd->notify_scan_events |= WMI_SCAN_EVENT_PREEMPTED;
2085 if (param->scan_ev_start_failed)
2086 cmd->notify_scan_events |= WMI_SCAN_EVENT_START_FAILED;
2087 if (param->scan_ev_restarted)
2088 cmd->notify_scan_events |= WMI_SCAN_EVENT_RESTARTED;
2089 if (param->scan_ev_foreign_chn_exit)
2090 cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT;
2091 if (param->scan_ev_suspended)
2092 cmd->notify_scan_events |= WMI_SCAN_EVENT_SUSPENDED;
2093 if (param->scan_ev_resumed)
2094 cmd->notify_scan_events |= WMI_SCAN_EVENT_RESUMED;
2095
2096 /** Set scan control flags */
2097 cmd->scan_ctrl_flags = 0;
2098 if (param->scan_f_passive)
2099 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2100 if (param->scan_f_strict_passive_pch)
2101 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN;
2102 if (param->scan_f_promisc_mode)
2103 cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROMISCUOS;
2104 if (param->scan_f_capture_phy_err)
2105 cmd->scan_ctrl_flags |= WMI_SCAN_CAPTURE_PHY_ERROR;
2106 if (param->scan_f_half_rate)
2107 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_HALF_RATE_SUPPORT;
2108 if (param->scan_f_quarter_rate)
2109 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT;
2110 if (param->scan_f_cck_rates)
2111 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2112 if (param->scan_f_ofdm_rates)
2113 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
2114 if (param->scan_f_chan_stat_evnt)
2115 cmd->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2116 if (param->scan_f_filter_prb_req)
2117 cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2118 if (param->scan_f_bcast_probe)
2119 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_BCAST_PROBE_REQ;
2120 if (param->scan_f_offchan_mgmt_tx)
2121 cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_MGMT_TX;
2122 if (param->scan_f_offchan_data_tx)
2123 cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_DATA_TX;
2124 if (param->scan_f_force_active_dfs_chn)
2125 cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS;
2126 if (param->scan_f_add_tpc_ie_in_probe)
2127 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ;
2128 if (param->scan_f_add_ds_ie_in_probe)
2129 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ;
2130 if (param->scan_f_add_spoofed_mac_in_probe)
2131 cmd->scan_ctrl_flags |= WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ;
2132 if (param->scan_f_add_rand_seq_in_probe)
2133 cmd->scan_ctrl_flags |= WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ;
2134 if (param->scan_f_en_ie_whitelist_in_probe)
2135 cmd->scan_ctrl_flags |=
2136 WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ;
2137
2138 /* for adaptive scan mode using 3 bits (21 - 23 bits) */
2139 WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags,
2140 param->adaptive_dwell_time_mode);
2141 }
2142
ath11k_wmi_send_scan_start_cmd(struct ath11k * ar,struct scan_req_params * params)2143 int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar,
2144 struct scan_req_params *params)
2145 {
2146 struct ath11k_pdev_wmi *wmi = ar->wmi;
2147 struct wmi_start_scan_cmd *cmd;
2148 struct wmi_ssid *ssid = NULL;
2149 struct wmi_mac_addr *bssid;
2150 struct sk_buff *skb;
2151 struct wmi_tlv *tlv;
2152 void *ptr;
2153 int i, ret, len;
2154 u32 *tmp_ptr;
2155 u16 extraie_len_with_pad = 0;
2156 struct hint_short_ssid *s_ssid = NULL;
2157 struct hint_bssid *hint_bssid = NULL;
2158
2159 len = sizeof(*cmd);
2160
2161 len += TLV_HDR_SIZE;
2162 if (params->num_chan)
2163 len += params->num_chan * sizeof(u32);
2164
2165 len += TLV_HDR_SIZE;
2166 if (params->num_ssids)
2167 len += params->num_ssids * sizeof(*ssid);
2168
2169 len += TLV_HDR_SIZE;
2170 if (params->num_bssid)
2171 len += sizeof(*bssid) * params->num_bssid;
2172
2173 len += TLV_HDR_SIZE;
2174 if (params->extraie.len && params->extraie.len <= 0xFFFF)
2175 extraie_len_with_pad =
2176 roundup(params->extraie.len, sizeof(u32));
2177 len += extraie_len_with_pad;
2178
2179 if (params->num_hint_bssid)
2180 len += TLV_HDR_SIZE +
2181 params->num_hint_bssid * sizeof(struct hint_bssid);
2182
2183 if (params->num_hint_s_ssid)
2184 len += TLV_HDR_SIZE +
2185 params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
2186
2187 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2188 if (!skb)
2189 return -ENOMEM;
2190
2191 ptr = skb->data;
2192
2193 cmd = ptr;
2194 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) |
2195 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2196
2197 cmd->scan_id = params->scan_id;
2198 cmd->scan_req_id = params->scan_req_id;
2199 cmd->vdev_id = params->vdev_id;
2200 cmd->scan_priority = params->scan_priority;
2201 cmd->notify_scan_events = params->notify_scan_events;
2202
2203 ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params);
2204
2205 cmd->dwell_time_active = params->dwell_time_active;
2206 cmd->dwell_time_active_2g = params->dwell_time_active_2g;
2207 cmd->dwell_time_passive = params->dwell_time_passive;
2208 cmd->dwell_time_active_6g = params->dwell_time_active_6g;
2209 cmd->dwell_time_passive_6g = params->dwell_time_passive_6g;
2210 cmd->min_rest_time = params->min_rest_time;
2211 cmd->max_rest_time = params->max_rest_time;
2212 cmd->repeat_probe_time = params->repeat_probe_time;
2213 cmd->probe_spacing_time = params->probe_spacing_time;
2214 cmd->idle_time = params->idle_time;
2215 cmd->max_scan_time = params->max_scan_time;
2216 cmd->probe_delay = params->probe_delay;
2217 cmd->burst_duration = params->burst_duration;
2218 cmd->num_chan = params->num_chan;
2219 cmd->num_bssid = params->num_bssid;
2220 cmd->num_ssids = params->num_ssids;
2221 cmd->ie_len = params->extraie.len;
2222 cmd->n_probes = params->n_probes;
2223 ether_addr_copy(cmd->mac_addr.addr, params->mac_addr.addr);
2224 ether_addr_copy(cmd->mac_mask.addr, params->mac_mask.addr);
2225
2226 ptr += sizeof(*cmd);
2227
2228 len = params->num_chan * sizeof(u32);
2229
2230 tlv = ptr;
2231 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
2232 FIELD_PREP(WMI_TLV_LEN, len);
2233 ptr += TLV_HDR_SIZE;
2234 tmp_ptr = (u32 *)ptr;
2235
2236 for (i = 0; i < params->num_chan; ++i)
2237 tmp_ptr[i] = params->chan_list[i];
2238
2239 ptr += len;
2240
2241 len = params->num_ssids * sizeof(*ssid);
2242 tlv = ptr;
2243 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2244 FIELD_PREP(WMI_TLV_LEN, len);
2245
2246 ptr += TLV_HDR_SIZE;
2247
2248 if (params->num_ssids) {
2249 ssid = ptr;
2250 for (i = 0; i < params->num_ssids; ++i) {
2251 ssid->ssid_len = params->ssid[i].length;
2252 memcpy(ssid->ssid, params->ssid[i].ssid,
2253 params->ssid[i].length);
2254 ssid++;
2255 }
2256 }
2257
2258 ptr += (params->num_ssids * sizeof(*ssid));
2259 len = params->num_bssid * sizeof(*bssid);
2260 tlv = ptr;
2261 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2262 FIELD_PREP(WMI_TLV_LEN, len);
2263
2264 ptr += TLV_HDR_SIZE;
2265 bssid = ptr;
2266
2267 if (params->num_bssid) {
2268 for (i = 0; i < params->num_bssid; ++i) {
2269 ether_addr_copy(bssid->addr,
2270 params->bssid_list[i].addr);
2271 bssid++;
2272 }
2273 }
2274
2275 ptr += params->num_bssid * sizeof(*bssid);
2276
2277 len = extraie_len_with_pad;
2278 tlv = ptr;
2279 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
2280 FIELD_PREP(WMI_TLV_LEN, len);
2281 ptr += TLV_HDR_SIZE;
2282
2283 if (extraie_len_with_pad)
2284 memcpy(ptr, params->extraie.ptr,
2285 params->extraie.len);
2286
2287 ptr += extraie_len_with_pad;
2288
2289 if (params->num_hint_s_ssid) {
2290 len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid);
2291 tlv = ptr;
2292 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2293 FIELD_PREP(WMI_TLV_LEN, len);
2294 ptr += TLV_HDR_SIZE;
2295 s_ssid = ptr;
2296 for (i = 0; i < params->num_hint_s_ssid; ++i) {
2297 s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags;
2298 s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid;
2299 s_ssid++;
2300 }
2301 ptr += len;
2302 }
2303
2304 if (params->num_hint_bssid) {
2305 len = params->num_hint_bssid * sizeof(struct hint_bssid);
2306 tlv = ptr;
2307 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) |
2308 FIELD_PREP(WMI_TLV_LEN, len);
2309 ptr += TLV_HDR_SIZE;
2310 hint_bssid = ptr;
2311 for (i = 0; i < params->num_hint_bssid; ++i) {
2312 hint_bssid->freq_flags =
2313 params->hint_bssid[i].freq_flags;
2314 ether_addr_copy(¶ms->hint_bssid[i].bssid.addr[0],
2315 &hint_bssid->bssid.addr[0]);
2316 hint_bssid++;
2317 }
2318 }
2319
2320 ret = ath11k_wmi_cmd_send(wmi, skb,
2321 WMI_START_SCAN_CMDID);
2322 if (ret) {
2323 ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n");
2324 dev_kfree_skb(skb);
2325 }
2326
2327 return ret;
2328 }
2329
ath11k_wmi_send_scan_stop_cmd(struct ath11k * ar,struct scan_cancel_param * param)2330 int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar,
2331 struct scan_cancel_param *param)
2332 {
2333 struct ath11k_pdev_wmi *wmi = ar->wmi;
2334 struct wmi_stop_scan_cmd *cmd;
2335 struct sk_buff *skb;
2336 int ret;
2337
2338 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2339 if (!skb)
2340 return -ENOMEM;
2341
2342 cmd = (struct wmi_stop_scan_cmd *)skb->data;
2343
2344 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) |
2345 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2346
2347 cmd->vdev_id = param->vdev_id;
2348 cmd->requestor = param->requester;
2349 cmd->scan_id = param->scan_id;
2350 cmd->pdev_id = param->pdev_id;
2351 /* stop the scan with the corresponding scan_id */
2352 if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) {
2353 /* Cancelling all scans */
2354 cmd->req_type = WMI_SCAN_STOP_ALL;
2355 } else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) {
2356 /* Cancelling VAP scans */
2357 cmd->req_type = WMI_SCN_STOP_VAP_ALL;
2358 } else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) {
2359 /* Cancelling specific scan */
2360 cmd->req_type = WMI_SCAN_STOP_ONE;
2361 } else {
2362 ath11k_warn(ar->ab, "invalid scan cancel param %d",
2363 param->req_type);
2364 dev_kfree_skb(skb);
2365 return -EINVAL;
2366 }
2367
2368 ret = ath11k_wmi_cmd_send(wmi, skb,
2369 WMI_STOP_SCAN_CMDID);
2370 if (ret) {
2371 ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n");
2372 dev_kfree_skb(skb);
2373 }
2374
2375 return ret;
2376 }
2377
ath11k_wmi_send_scan_chan_list_cmd(struct ath11k * ar,struct scan_chan_list_params * chan_list)2378 int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar,
2379 struct scan_chan_list_params *chan_list)
2380 {
2381 struct ath11k_pdev_wmi *wmi = ar->wmi;
2382 struct wmi_scan_chan_list_cmd *cmd;
2383 struct sk_buff *skb;
2384 struct wmi_channel *chan_info;
2385 struct channel_param *tchan_info;
2386 struct wmi_tlv *tlv;
2387 void *ptr;
2388 int i, ret, len;
2389 u16 num_send_chans, num_sends = 0, max_chan_limit = 0;
2390 u32 *reg1, *reg2;
2391
2392 tchan_info = chan_list->ch_param;
2393 while (chan_list->nallchans) {
2394 len = sizeof(*cmd) + TLV_HDR_SIZE;
2395 max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) /
2396 sizeof(*chan_info);
2397
2398 if (chan_list->nallchans > max_chan_limit)
2399 num_send_chans = max_chan_limit;
2400 else
2401 num_send_chans = chan_list->nallchans;
2402
2403 chan_list->nallchans -= num_send_chans;
2404 len += sizeof(*chan_info) * num_send_chans;
2405
2406 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2407 if (!skb)
2408 return -ENOMEM;
2409
2410 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2411 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) |
2412 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2413 cmd->pdev_id = chan_list->pdev_id;
2414 cmd->num_scan_chans = num_send_chans;
2415 if (num_sends)
2416 cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG;
2417
2418 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2419 "WMI no.of chan = %d len = %d pdev_id = %d num_sends = %d\n",
2420 num_send_chans, len, cmd->pdev_id, num_sends);
2421
2422 ptr = skb->data + sizeof(*cmd);
2423
2424 len = sizeof(*chan_info) * num_send_chans;
2425 tlv = ptr;
2426 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2427 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
2428 ptr += TLV_HDR_SIZE;
2429
2430 for (i = 0; i < num_send_chans; ++i) {
2431 chan_info = ptr;
2432 memset(chan_info, 0, sizeof(*chan_info));
2433 len = sizeof(*chan_info);
2434 chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2435 WMI_TAG_CHANNEL) |
2436 FIELD_PREP(WMI_TLV_LEN,
2437 len - TLV_HDR_SIZE);
2438
2439 reg1 = &chan_info->reg_info_1;
2440 reg2 = &chan_info->reg_info_2;
2441 chan_info->mhz = tchan_info->mhz;
2442 chan_info->band_center_freq1 = tchan_info->cfreq1;
2443 chan_info->band_center_freq2 = tchan_info->cfreq2;
2444
2445 if (tchan_info->is_chan_passive)
2446 chan_info->info |= WMI_CHAN_INFO_PASSIVE;
2447 if (tchan_info->allow_he)
2448 chan_info->info |= WMI_CHAN_INFO_ALLOW_HE;
2449 else if (tchan_info->allow_vht)
2450 chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT;
2451 else if (tchan_info->allow_ht)
2452 chan_info->info |= WMI_CHAN_INFO_ALLOW_HT;
2453 if (tchan_info->half_rate)
2454 chan_info->info |= WMI_CHAN_INFO_HALF_RATE;
2455 if (tchan_info->quarter_rate)
2456 chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE;
2457 if (tchan_info->psc_channel)
2458 chan_info->info |= WMI_CHAN_INFO_PSC;
2459 if (tchan_info->dfs_set)
2460 chan_info->info |= WMI_CHAN_INFO_DFS;
2461
2462 chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE,
2463 tchan_info->phy_mode);
2464 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR,
2465 tchan_info->minpower);
2466 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR,
2467 tchan_info->maxpower);
2468 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR,
2469 tchan_info->maxregpower);
2470 *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS,
2471 tchan_info->reg_class_id);
2472 *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX,
2473 tchan_info->antennamax);
2474 *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR,
2475 tchan_info->maxregpower);
2476
2477 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2478 "WMI chan scan list chan[%d] = %u, chan_info->info %8x\n",
2479 i, chan_info->mhz, chan_info->info);
2480
2481 ptr += sizeof(*chan_info);
2482
2483 tchan_info++;
2484 }
2485
2486 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID);
2487 if (ret) {
2488 ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n");
2489 dev_kfree_skb(skb);
2490 return ret;
2491 }
2492
2493 num_sends++;
2494 }
2495
2496 return 0;
2497 }
2498
ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k * ar,u32 vdev_id,struct wmi_wmm_params_all_arg * param)2499 int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id,
2500 struct wmi_wmm_params_all_arg *param)
2501 {
2502 struct ath11k_pdev_wmi *wmi = ar->wmi;
2503 struct wmi_vdev_set_wmm_params_cmd *cmd;
2504 struct wmi_wmm_params *wmm_param;
2505 struct wmi_wmm_params_arg *wmi_wmm_arg;
2506 struct sk_buff *skb;
2507 int ret, ac;
2508
2509 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2510 if (!skb)
2511 return -ENOMEM;
2512
2513 cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data;
2514 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
2515 WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2516 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2517
2518 cmd->vdev_id = vdev_id;
2519 cmd->wmm_param_type = 0;
2520
2521 for (ac = 0; ac < WME_NUM_AC; ac++) {
2522 switch (ac) {
2523 case WME_AC_BE:
2524 wmi_wmm_arg = ¶m->ac_be;
2525 break;
2526 case WME_AC_BK:
2527 wmi_wmm_arg = ¶m->ac_bk;
2528 break;
2529 case WME_AC_VI:
2530 wmi_wmm_arg = ¶m->ac_vi;
2531 break;
2532 case WME_AC_VO:
2533 wmi_wmm_arg = ¶m->ac_vo;
2534 break;
2535 }
2536
2537 wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac];
2538 wmm_param->tlv_header =
2539 FIELD_PREP(WMI_TLV_TAG,
2540 WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) |
2541 FIELD_PREP(WMI_TLV_LEN,
2542 sizeof(*wmm_param) - TLV_HDR_SIZE);
2543
2544 wmm_param->aifs = wmi_wmm_arg->aifs;
2545 wmm_param->cwmin = wmi_wmm_arg->cwmin;
2546 wmm_param->cwmax = wmi_wmm_arg->cwmax;
2547 wmm_param->txoplimit = wmi_wmm_arg->txop;
2548 wmm_param->acm = wmi_wmm_arg->acm;
2549 wmm_param->no_ack = wmi_wmm_arg->no_ack;
2550
2551 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2552 "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n",
2553 ac, wmm_param->aifs, wmm_param->cwmin,
2554 wmm_param->cwmax, wmm_param->txoplimit,
2555 wmm_param->acm, wmm_param->no_ack);
2556 }
2557 ret = ath11k_wmi_cmd_send(wmi, skb,
2558 WMI_VDEV_SET_WMM_PARAMS_CMDID);
2559 if (ret) {
2560 ath11k_warn(ar->ab,
2561 "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID");
2562 dev_kfree_skb(skb);
2563 }
2564
2565 return ret;
2566 }
2567
ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k * ar,u32 pdev_id)2568 int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar,
2569 u32 pdev_id)
2570 {
2571 struct ath11k_pdev_wmi *wmi = ar->wmi;
2572 struct wmi_dfs_phyerr_offload_cmd *cmd;
2573 struct sk_buff *skb;
2574 int ret;
2575
2576 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2577 if (!skb)
2578 return -ENOMEM;
2579
2580 cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data;
2581 cmd->tlv_header =
2582 FIELD_PREP(WMI_TLV_TAG,
2583 WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) |
2584 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2585
2586 cmd->pdev_id = pdev_id;
2587
2588 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2589 "WMI dfs phy err offload enable pdev id %d\n", pdev_id);
2590
2591 ret = ath11k_wmi_cmd_send(wmi, skb,
2592 WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
2593 if (ret) {
2594 ath11k_warn(ar->ab,
2595 "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n");
2596 dev_kfree_skb(skb);
2597 }
2598
2599 return ret;
2600 }
2601
ath11k_wmi_delba_send(struct ath11k * ar,u32 vdev_id,const u8 * mac,u32 tid,u32 initiator,u32 reason)2602 int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
2603 u32 tid, u32 initiator, u32 reason)
2604 {
2605 struct ath11k_pdev_wmi *wmi = ar->wmi;
2606 struct wmi_delba_send_cmd *cmd;
2607 struct sk_buff *skb;
2608 int ret;
2609
2610 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2611 if (!skb)
2612 return -ENOMEM;
2613
2614 cmd = (struct wmi_delba_send_cmd *)skb->data;
2615 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) |
2616 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2617 cmd->vdev_id = vdev_id;
2618 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2619 cmd->tid = tid;
2620 cmd->initiator = initiator;
2621 cmd->reasoncode = reason;
2622
2623 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2624 "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
2625 vdev_id, mac, tid, initiator, reason);
2626
2627 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID);
2628
2629 if (ret) {
2630 ath11k_warn(ar->ab,
2631 "failed to send WMI_DELBA_SEND_CMDID cmd\n");
2632 dev_kfree_skb(skb);
2633 }
2634
2635 return ret;
2636 }
2637
ath11k_wmi_addba_set_resp(struct ath11k * ar,u32 vdev_id,const u8 * mac,u32 tid,u32 status)2638 int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac,
2639 u32 tid, u32 status)
2640 {
2641 struct ath11k_pdev_wmi *wmi = ar->wmi;
2642 struct wmi_addba_setresponse_cmd *cmd;
2643 struct sk_buff *skb;
2644 int ret;
2645
2646 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2647 if (!skb)
2648 return -ENOMEM;
2649
2650 cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
2651 cmd->tlv_header =
2652 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) |
2653 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2654 cmd->vdev_id = vdev_id;
2655 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2656 cmd->tid = tid;
2657 cmd->statuscode = status;
2658
2659 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2660 "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
2661 vdev_id, mac, tid, status);
2662
2663 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID);
2664
2665 if (ret) {
2666 ath11k_warn(ar->ab,
2667 "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n");
2668 dev_kfree_skb(skb);
2669 }
2670
2671 return ret;
2672 }
2673
ath11k_wmi_addba_send(struct ath11k * ar,u32 vdev_id,const u8 * mac,u32 tid,u32 buf_size)2674 int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac,
2675 u32 tid, u32 buf_size)
2676 {
2677 struct ath11k_pdev_wmi *wmi = ar->wmi;
2678 struct wmi_addba_send_cmd *cmd;
2679 struct sk_buff *skb;
2680 int ret;
2681
2682 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2683 if (!skb)
2684 return -ENOMEM;
2685
2686 cmd = (struct wmi_addba_send_cmd *)skb->data;
2687 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) |
2688 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2689 cmd->vdev_id = vdev_id;
2690 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2691 cmd->tid = tid;
2692 cmd->buffersize = buf_size;
2693
2694 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2695 "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
2696 vdev_id, mac, tid, buf_size);
2697
2698 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID);
2699
2700 if (ret) {
2701 ath11k_warn(ar->ab,
2702 "failed to send WMI_ADDBA_SEND_CMDID cmd\n");
2703 dev_kfree_skb(skb);
2704 }
2705
2706 return ret;
2707 }
2708
ath11k_wmi_addba_clear_resp(struct ath11k * ar,u32 vdev_id,const u8 * mac)2709 int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac)
2710 {
2711 struct ath11k_pdev_wmi *wmi = ar->wmi;
2712 struct wmi_addba_clear_resp_cmd *cmd;
2713 struct sk_buff *skb;
2714 int ret;
2715
2716 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2717 if (!skb)
2718 return -ENOMEM;
2719
2720 cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
2721 cmd->tlv_header =
2722 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) |
2723 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2724 cmd->vdev_id = vdev_id;
2725 ether_addr_copy(cmd->peer_macaddr.addr, mac);
2726
2727 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2728 "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
2729 vdev_id, mac);
2730
2731 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID);
2732
2733 if (ret) {
2734 ath11k_warn(ar->ab,
2735 "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n");
2736 dev_kfree_skb(skb);
2737 }
2738
2739 return ret;
2740 }
2741
ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k * ar,u8 * addr,u8 enable)2742 int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable)
2743 {
2744 struct ath11k_pdev_wmi *wmi = ar->wmi;
2745 struct wmi_pdev_pktlog_filter_cmd *cmd;
2746 struct wmi_pdev_pktlog_filter_info *info;
2747 struct sk_buff *skb;
2748 struct wmi_tlv *tlv;
2749 void *ptr;
2750 int ret, len;
2751
2752 len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE;
2753 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2754 if (!skb)
2755 return -ENOMEM;
2756
2757 cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data;
2758
2759 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) |
2760 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2761
2762 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
2763 cmd->num_mac = 1;
2764 cmd->enable = enable;
2765
2766 ptr = skb->data + sizeof(*cmd);
2767
2768 tlv = ptr;
2769 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2770 FIELD_PREP(WMI_TLV_LEN, sizeof(*info));
2771
2772 ptr += TLV_HDR_SIZE;
2773 info = ptr;
2774
2775 ether_addr_copy(info->peer_macaddr.addr, addr);
2776 info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) |
2777 FIELD_PREP(WMI_TLV_LEN,
2778 sizeof(*info) - TLV_HDR_SIZE);
2779
2780 ret = ath11k_wmi_cmd_send(wmi, skb,
2781 WMI_PDEV_PKTLOG_FILTER_CMDID);
2782 if (ret) {
2783 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
2784 dev_kfree_skb(skb);
2785 }
2786
2787 return ret;
2788 }
2789
2790 int
ath11k_wmi_send_init_country_cmd(struct ath11k * ar,struct wmi_init_country_params init_cc_params)2791 ath11k_wmi_send_init_country_cmd(struct ath11k *ar,
2792 struct wmi_init_country_params init_cc_params)
2793 {
2794 struct ath11k_pdev_wmi *wmi = ar->wmi;
2795 struct wmi_init_country_cmd *cmd;
2796 struct sk_buff *skb;
2797 int ret;
2798
2799 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2800 if (!skb)
2801 return -ENOMEM;
2802
2803 cmd = (struct wmi_init_country_cmd *)skb->data;
2804 cmd->tlv_header =
2805 FIELD_PREP(WMI_TLV_TAG,
2806 WMI_TAG_SET_INIT_COUNTRY_CMD) |
2807 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2808
2809 cmd->pdev_id = ar->pdev->pdev_id;
2810
2811 switch (init_cc_params.flags) {
2812 case ALPHA_IS_SET:
2813 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA;
2814 memcpy((u8 *)&cmd->cc_info.alpha2,
2815 init_cc_params.cc_info.alpha2, 3);
2816 break;
2817 case CC_IS_SET:
2818 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE;
2819 cmd->cc_info.country_code = init_cc_params.cc_info.country_code;
2820 break;
2821 case REGDMN_IS_SET:
2822 cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN;
2823 cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id;
2824 break;
2825 default:
2826 ret = -EINVAL;
2827 goto out;
2828 }
2829
2830 ret = ath11k_wmi_cmd_send(wmi, skb,
2831 WMI_SET_INIT_COUNTRY_CMDID);
2832
2833 out:
2834 if (ret) {
2835 ath11k_warn(ar->ab,
2836 "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n",
2837 ret);
2838 dev_kfree_skb(skb);
2839 }
2840
2841 return ret;
2842 }
2843
ath11k_wmi_send_set_current_country_cmd(struct ath11k * ar,struct wmi_set_current_country_params * param)2844 int ath11k_wmi_send_set_current_country_cmd(struct ath11k *ar,
2845 struct wmi_set_current_country_params *param)
2846 {
2847 struct ath11k_pdev_wmi *wmi = ar->wmi;
2848 struct wmi_set_current_country_cmd *cmd;
2849 struct sk_buff *skb;
2850 int ret;
2851
2852 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2853 if (!skb)
2854 return -ENOMEM;
2855
2856 cmd = (struct wmi_set_current_country_cmd *)skb->data;
2857 cmd->tlv_header =
2858 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SET_CURRENT_COUNTRY_CMD) |
2859 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2860
2861 cmd->pdev_id = ar->pdev->pdev_id;
2862 memcpy(&cmd->new_alpha2, ¶m->alpha2, 3);
2863 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SET_CURRENT_COUNTRY_CMDID);
2864
2865 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2866 "set current country pdev id %d alpha2 %c%c\n",
2867 ar->pdev->pdev_id,
2868 param->alpha2[0],
2869 param->alpha2[1]);
2870
2871 if (ret) {
2872 ath11k_warn(ar->ab,
2873 "failed to send WMI_SET_CURRENT_COUNTRY_CMDID: %d\n", ret);
2874 dev_kfree_skb(skb);
2875 }
2876
2877 return ret;
2878 }
2879
2880 int
ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k * ar,struct thermal_mitigation_params * param)2881 ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar,
2882 struct thermal_mitigation_params *param)
2883 {
2884 struct ath11k_pdev_wmi *wmi = ar->wmi;
2885 struct wmi_therm_throt_config_request_cmd *cmd;
2886 struct wmi_therm_throt_level_config_info *lvl_conf;
2887 struct wmi_tlv *tlv;
2888 struct sk_buff *skb;
2889 int i, ret, len;
2890
2891 len = sizeof(*cmd) + TLV_HDR_SIZE +
2892 THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info);
2893
2894 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
2895 if (!skb)
2896 return -ENOMEM;
2897
2898 cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data;
2899
2900 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) |
2901 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2902
2903 cmd->pdev_id = ar->pdev->pdev_id;
2904 cmd->enable = param->enable;
2905 cmd->dc = param->dc;
2906 cmd->dc_per_event = param->dc_per_event;
2907 cmd->therm_throt_levels = THERMAL_LEVELS;
2908
2909 tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd));
2910 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
2911 FIELD_PREP(WMI_TLV_LEN,
2912 (THERMAL_LEVELS *
2913 sizeof(struct wmi_therm_throt_level_config_info)));
2914
2915 lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data +
2916 sizeof(*cmd) +
2917 TLV_HDR_SIZE);
2918 for (i = 0; i < THERMAL_LEVELS; i++) {
2919 lvl_conf->tlv_header =
2920 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) |
2921 FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE);
2922
2923 lvl_conf->temp_lwm = param->levelconf[i].tmplwm;
2924 lvl_conf->temp_hwm = param->levelconf[i].tmphwm;
2925 lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent;
2926 lvl_conf->prio = param->levelconf[i].priority;
2927 lvl_conf++;
2928 }
2929
2930 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID);
2931 if (ret) {
2932 ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n");
2933 dev_kfree_skb(skb);
2934 }
2935
2936 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2937 "WMI vdev set thermal throt pdev_id %d enable %d dc %d dc_per_event %x levels %d\n",
2938 ar->pdev->pdev_id, param->enable, param->dc,
2939 param->dc_per_event, THERMAL_LEVELS);
2940
2941 return ret;
2942 }
2943
ath11k_wmi_send_11d_scan_start_cmd(struct ath11k * ar,struct wmi_11d_scan_start_params * param)2944 int ath11k_wmi_send_11d_scan_start_cmd(struct ath11k *ar,
2945 struct wmi_11d_scan_start_params *param)
2946 {
2947 struct ath11k_pdev_wmi *wmi = ar->wmi;
2948 struct wmi_11d_scan_start_cmd *cmd;
2949 struct sk_buff *skb;
2950 int ret;
2951
2952 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2953 if (!skb)
2954 return -ENOMEM;
2955
2956 cmd = (struct wmi_11d_scan_start_cmd *)skb->data;
2957 cmd->tlv_header =
2958 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_START_CMD) |
2959 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2960
2961 cmd->vdev_id = param->vdev_id;
2962 cmd->scan_period_msec = param->scan_period_msec;
2963 cmd->start_interval_msec = param->start_interval_msec;
2964 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_START_CMDID);
2965
2966 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
2967 "send 11d scan start vdev id %d period %d ms internal %d ms\n",
2968 cmd->vdev_id,
2969 cmd->scan_period_msec,
2970 cmd->start_interval_msec);
2971
2972 if (ret) {
2973 ath11k_warn(ar->ab,
2974 "failed to send WMI_11D_SCAN_START_CMDID: %d\n", ret);
2975 dev_kfree_skb(skb);
2976 }
2977
2978 return ret;
2979 }
2980
ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k * ar,u32 vdev_id)2981 int ath11k_wmi_send_11d_scan_stop_cmd(struct ath11k *ar, u32 vdev_id)
2982 {
2983 struct ath11k_pdev_wmi *wmi = ar->wmi;
2984 struct wmi_11d_scan_stop_cmd *cmd;
2985 struct sk_buff *skb;
2986 int ret;
2987
2988 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
2989 if (!skb)
2990 return -ENOMEM;
2991
2992 cmd = (struct wmi_11d_scan_stop_cmd *)skb->data;
2993 cmd->tlv_header =
2994 FIELD_PREP(WMI_TLV_TAG, WMI_TAG_11D_SCAN_STOP_CMD) |
2995 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
2996
2997 cmd->vdev_id = vdev_id;
2998 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_11D_SCAN_STOP_CMDID);
2999
3000 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3001 "send 11d scan stop vdev id %d\n",
3002 cmd->vdev_id);
3003
3004 if (ret) {
3005 ath11k_warn(ar->ab,
3006 "failed to send WMI_11D_SCAN_STOP_CMDID: %d\n", ret);
3007 dev_kfree_skb(skb);
3008 }
3009
3010 return ret;
3011 }
3012
ath11k_wmi_pdev_pktlog_enable(struct ath11k * ar,u32 pktlog_filter)3013 int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter)
3014 {
3015 struct ath11k_pdev_wmi *wmi = ar->wmi;
3016 struct wmi_pktlog_enable_cmd *cmd;
3017 struct sk_buff *skb;
3018 int ret;
3019
3020 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3021 if (!skb)
3022 return -ENOMEM;
3023
3024 cmd = (struct wmi_pktlog_enable_cmd *)skb->data;
3025
3026 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) |
3027 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3028
3029 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3030 cmd->evlist = pktlog_filter;
3031 cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE;
3032
3033 ret = ath11k_wmi_cmd_send(wmi, skb,
3034 WMI_PDEV_PKTLOG_ENABLE_CMDID);
3035 if (ret) {
3036 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3037 dev_kfree_skb(skb);
3038 }
3039
3040 return ret;
3041 }
3042
ath11k_wmi_pdev_pktlog_disable(struct ath11k * ar)3043 int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar)
3044 {
3045 struct ath11k_pdev_wmi *wmi = ar->wmi;
3046 struct wmi_pktlog_disable_cmd *cmd;
3047 struct sk_buff *skb;
3048 int ret;
3049
3050 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd));
3051 if (!skb)
3052 return -ENOMEM;
3053
3054 cmd = (struct wmi_pktlog_disable_cmd *)skb->data;
3055
3056 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) |
3057 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3058
3059 cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id);
3060
3061 ret = ath11k_wmi_cmd_send(wmi, skb,
3062 WMI_PDEV_PKTLOG_DISABLE_CMDID);
3063 if (ret) {
3064 ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n");
3065 dev_kfree_skb(skb);
3066 }
3067
3068 return ret;
3069 }
3070
3071 int
ath11k_wmi_send_twt_enable_cmd(struct ath11k * ar,u32 pdev_id)3072 ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id)
3073 {
3074 struct ath11k_pdev_wmi *wmi = ar->wmi;
3075 struct ath11k_base *ab = wmi->wmi_ab->ab;
3076 struct wmi_twt_enable_params_cmd *cmd;
3077 struct sk_buff *skb;
3078 int ret, len;
3079
3080 len = sizeof(*cmd);
3081
3082 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3083 if (!skb)
3084 return -ENOMEM;
3085
3086 cmd = (struct wmi_twt_enable_params_cmd *)skb->data;
3087 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) |
3088 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3089 cmd->pdev_id = pdev_id;
3090 cmd->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS;
3091 cmd->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE;
3092 cmd->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP;
3093 cmd->congestion_thresh_teardown =
3094 ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN;
3095 cmd->congestion_thresh_critical =
3096 ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL;
3097 cmd->interference_thresh_teardown =
3098 ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN;
3099 cmd->interference_thresh_setup =
3100 ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP;
3101 cmd->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP;
3102 cmd->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN;
3103 cmd->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS;
3104 cmd->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS;
3105 cmd->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT;
3106 cmd->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL;
3107 cmd->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL;
3108 cmd->remove_sta_slot_interval =
3109 ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL;
3110 /* TODO add MBSSID support */
3111 cmd->mbss_support = 0;
3112
3113 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ENABLE_CMDID);
3114 if (ret) {
3115 ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID");
3116 dev_kfree_skb(skb);
3117 } else {
3118 ar->twt_enabled = 1;
3119 }
3120 return ret;
3121 }
3122
3123 int
ath11k_wmi_send_twt_disable_cmd(struct ath11k * ar,u32 pdev_id)3124 ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id)
3125 {
3126 struct ath11k_pdev_wmi *wmi = ar->wmi;
3127 struct ath11k_base *ab = wmi->wmi_ab->ab;
3128 struct wmi_twt_disable_params_cmd *cmd;
3129 struct sk_buff *skb;
3130 int ret, len;
3131
3132 len = sizeof(*cmd);
3133
3134 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3135 if (!skb)
3136 return -ENOMEM;
3137
3138 cmd = (struct wmi_twt_disable_params_cmd *)skb->data;
3139 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) |
3140 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3141 cmd->pdev_id = pdev_id;
3142
3143 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DISABLE_CMDID);
3144 if (ret) {
3145 ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID");
3146 dev_kfree_skb(skb);
3147 } else {
3148 ar->twt_enabled = 0;
3149 }
3150 return ret;
3151 }
3152
ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k * ar,struct wmi_twt_add_dialog_params * params)3153 int ath11k_wmi_send_twt_add_dialog_cmd(struct ath11k *ar,
3154 struct wmi_twt_add_dialog_params *params)
3155 {
3156 struct ath11k_pdev_wmi *wmi = ar->wmi;
3157 struct ath11k_base *ab = wmi->wmi_ab->ab;
3158 struct wmi_twt_add_dialog_params_cmd *cmd;
3159 struct sk_buff *skb;
3160 int ret, len;
3161
3162 len = sizeof(*cmd);
3163
3164 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3165 if (!skb)
3166 return -ENOMEM;
3167
3168 cmd = (struct wmi_twt_add_dialog_params_cmd *)skb->data;
3169 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ADD_DIALOG_CMD) |
3170 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3171
3172 cmd->vdev_id = params->vdev_id;
3173 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3174 cmd->dialog_id = params->dialog_id;
3175 cmd->wake_intvl_us = params->wake_intvl_us;
3176 cmd->wake_intvl_mantis = params->wake_intvl_mantis;
3177 cmd->wake_dura_us = params->wake_dura_us;
3178 cmd->sp_offset_us = params->sp_offset_us;
3179 cmd->flags = params->twt_cmd;
3180 if (params->flag_bcast)
3181 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_BCAST;
3182 if (params->flag_trigger)
3183 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_TRIGGER;
3184 if (params->flag_flow_type)
3185 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_FLOW_TYPE;
3186 if (params->flag_protection)
3187 cmd->flags |= WMI_TWT_ADD_DIALOG_FLAG_PROTECTION;
3188
3189 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3190 "wmi add twt dialog vdev %u dialog id %u wake interval %u mantissa %u wake duration %u service period offset %u flags 0x%x\n",
3191 cmd->vdev_id, cmd->dialog_id, cmd->wake_intvl_us,
3192 cmd->wake_intvl_mantis, cmd->wake_dura_us, cmd->sp_offset_us,
3193 cmd->flags);
3194
3195 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_ADD_DIALOG_CMDID);
3196
3197 if (ret) {
3198 ath11k_warn(ab,
3199 "failed to send wmi command to add twt dialog: %d",
3200 ret);
3201 dev_kfree_skb(skb);
3202 }
3203 return ret;
3204 }
3205
ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k * ar,struct wmi_twt_del_dialog_params * params)3206 int ath11k_wmi_send_twt_del_dialog_cmd(struct ath11k *ar,
3207 struct wmi_twt_del_dialog_params *params)
3208 {
3209 struct ath11k_pdev_wmi *wmi = ar->wmi;
3210 struct ath11k_base *ab = wmi->wmi_ab->ab;
3211 struct wmi_twt_del_dialog_params_cmd *cmd;
3212 struct sk_buff *skb;
3213 int ret, len;
3214
3215 len = sizeof(*cmd);
3216
3217 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3218 if (!skb)
3219 return -ENOMEM;
3220
3221 cmd = (struct wmi_twt_del_dialog_params_cmd *)skb->data;
3222 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DEL_DIALOG_CMD) |
3223 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3224
3225 cmd->vdev_id = params->vdev_id;
3226 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3227 cmd->dialog_id = params->dialog_id;
3228
3229 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3230 "wmi delete twt dialog vdev %u dialog id %u\n",
3231 cmd->vdev_id, cmd->dialog_id);
3232
3233 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_DEL_DIALOG_CMDID);
3234 if (ret) {
3235 ath11k_warn(ab,
3236 "failed to send wmi command to delete twt dialog: %d",
3237 ret);
3238 dev_kfree_skb(skb);
3239 }
3240 return ret;
3241 }
3242
ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k * ar,struct wmi_twt_pause_dialog_params * params)3243 int ath11k_wmi_send_twt_pause_dialog_cmd(struct ath11k *ar,
3244 struct wmi_twt_pause_dialog_params *params)
3245 {
3246 struct ath11k_pdev_wmi *wmi = ar->wmi;
3247 struct ath11k_base *ab = wmi->wmi_ab->ab;
3248 struct wmi_twt_pause_dialog_params_cmd *cmd;
3249 struct sk_buff *skb;
3250 int ret, len;
3251
3252 len = sizeof(*cmd);
3253
3254 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3255 if (!skb)
3256 return -ENOMEM;
3257
3258 cmd = (struct wmi_twt_pause_dialog_params_cmd *)skb->data;
3259 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3260 WMI_TAG_TWT_PAUSE_DIALOG_CMD) |
3261 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3262
3263 cmd->vdev_id = params->vdev_id;
3264 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3265 cmd->dialog_id = params->dialog_id;
3266
3267 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3268 "wmi pause twt dialog vdev %u dialog id %u\n",
3269 cmd->vdev_id, cmd->dialog_id);
3270
3271 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_PAUSE_DIALOG_CMDID);
3272 if (ret) {
3273 ath11k_warn(ab,
3274 "failed to send wmi command to pause twt dialog: %d",
3275 ret);
3276 dev_kfree_skb(skb);
3277 }
3278 return ret;
3279 }
3280
ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k * ar,struct wmi_twt_resume_dialog_params * params)3281 int ath11k_wmi_send_twt_resume_dialog_cmd(struct ath11k *ar,
3282 struct wmi_twt_resume_dialog_params *params)
3283 {
3284 struct ath11k_pdev_wmi *wmi = ar->wmi;
3285 struct ath11k_base *ab = wmi->wmi_ab->ab;
3286 struct wmi_twt_resume_dialog_params_cmd *cmd;
3287 struct sk_buff *skb;
3288 int ret, len;
3289
3290 len = sizeof(*cmd);
3291
3292 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3293 if (!skb)
3294 return -ENOMEM;
3295
3296 cmd = (struct wmi_twt_resume_dialog_params_cmd *)skb->data;
3297 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3298 WMI_TAG_TWT_RESUME_DIALOG_CMD) |
3299 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3300
3301 cmd->vdev_id = params->vdev_id;
3302 ether_addr_copy(cmd->peer_macaddr.addr, params->peer_macaddr);
3303 cmd->dialog_id = params->dialog_id;
3304 cmd->sp_offset_us = params->sp_offset_us;
3305 cmd->next_twt_size = params->next_twt_size;
3306
3307 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3308 "wmi resume twt dialog vdev %u dialog id %u service period offset %u next twt subfield size %u\n",
3309 cmd->vdev_id, cmd->dialog_id, cmd->sp_offset_us,
3310 cmd->next_twt_size);
3311
3312 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_TWT_RESUME_DIALOG_CMDID);
3313 if (ret) {
3314 ath11k_warn(ab,
3315 "failed to send wmi command to resume twt dialog: %d",
3316 ret);
3317 dev_kfree_skb(skb);
3318 }
3319 return ret;
3320 }
3321
3322 int
ath11k_wmi_send_obss_spr_cmd(struct ath11k * ar,u32 vdev_id,struct ieee80211_he_obss_pd * he_obss_pd)3323 ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id,
3324 struct ieee80211_he_obss_pd *he_obss_pd)
3325 {
3326 struct ath11k_pdev_wmi *wmi = ar->wmi;
3327 struct ath11k_base *ab = wmi->wmi_ab->ab;
3328 struct wmi_obss_spatial_reuse_params_cmd *cmd;
3329 struct sk_buff *skb;
3330 int ret, len;
3331
3332 len = sizeof(*cmd);
3333
3334 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3335 if (!skb)
3336 return -ENOMEM;
3337
3338 cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data;
3339 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3340 WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) |
3341 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3342 cmd->vdev_id = vdev_id;
3343 cmd->enable = he_obss_pd->enable;
3344 cmd->obss_min = he_obss_pd->min_offset;
3345 cmd->obss_max = he_obss_pd->max_offset;
3346
3347 ret = ath11k_wmi_cmd_send(wmi, skb,
3348 WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID);
3349 if (ret) {
3350 ath11k_warn(ab,
3351 "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID");
3352 dev_kfree_skb(skb);
3353 }
3354 return ret;
3355 }
3356
3357 int
ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k * ar,u32 * bitmap)3358 ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k *ar, u32 *bitmap)
3359 {
3360 struct ath11k_pdev_wmi *wmi = ar->wmi;
3361 struct ath11k_base *ab = wmi->wmi_ab->ab;
3362 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3363 struct sk_buff *skb;
3364 int ret, len;
3365
3366 len = sizeof(*cmd);
3367
3368 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3369 if (!skb)
3370 return -ENOMEM;
3371
3372 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3373 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3374 WMI_TAG_PDEV_SRG_BSS_COLOR_BITMAP_CMD) |
3375 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3376 cmd->pdev_id = ar->pdev->pdev_id;
3377 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3378
3379 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3380 "obss pd pdev_id %d bss color bitmap %08x %08x\n",
3381 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3382
3383 ret = ath11k_wmi_cmd_send(wmi, skb,
3384 WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID);
3385 if (ret) {
3386 ath11k_warn(ab,
3387 "failed to send WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID");
3388 dev_kfree_skb(skb);
3389 }
3390
3391 return ret;
3392 }
3393
3394 int
ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k * ar,u32 * bitmap)3395 ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k *ar, u32 *bitmap)
3396 {
3397 struct ath11k_pdev_wmi *wmi = ar->wmi;
3398 struct ath11k_base *ab = wmi->wmi_ab->ab;
3399 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3400 struct sk_buff *skb;
3401 int ret, len;
3402
3403 len = sizeof(*cmd);
3404
3405 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3406 if (!skb)
3407 return -ENOMEM;
3408
3409 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3410 cmd->tlv_header =
3411 FIELD_PREP(WMI_TLV_TAG,
3412 WMI_TAG_PDEV_SRG_PARTIAL_BSSID_BITMAP_CMD) |
3413 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3414 cmd->pdev_id = ar->pdev->pdev_id;
3415 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3416
3417 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3418 "obss pd pdev_id %d partial bssid bitmap %08x %08x\n",
3419 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3420
3421 ret = ath11k_wmi_cmd_send(wmi, skb,
3422 WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID);
3423 if (ret) {
3424 ath11k_warn(ab,
3425 "failed to send WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID");
3426 dev_kfree_skb(skb);
3427 }
3428
3429 return ret;
3430 }
3431
3432 int
ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k * ar,u32 * bitmap)3433 ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3434 {
3435 struct ath11k_pdev_wmi *wmi = ar->wmi;
3436 struct ath11k_base *ab = wmi->wmi_ab->ab;
3437 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3438 struct sk_buff *skb;
3439 int ret, len;
3440
3441 len = sizeof(*cmd);
3442
3443 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3444 if (!skb)
3445 return -ENOMEM;
3446
3447 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3448 cmd->tlv_header =
3449 FIELD_PREP(WMI_TLV_TAG,
3450 WMI_TAG_PDEV_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3451 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3452 cmd->pdev_id = ar->pdev->pdev_id;
3453 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3454
3455 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3456 "obss pd srg pdev_id %d bss color enable bitmap %08x %08x\n",
3457 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3458
3459 ret = ath11k_wmi_cmd_send(wmi, skb,
3460 WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3461 if (ret) {
3462 ath11k_warn(ab,
3463 "failed to send WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3464 dev_kfree_skb(skb);
3465 }
3466
3467 return ret;
3468 }
3469
3470 int
ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k * ar,u32 * bitmap)3471 ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3472 {
3473 struct ath11k_pdev_wmi *wmi = ar->wmi;
3474 struct ath11k_base *ab = wmi->wmi_ab->ab;
3475 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3476 struct sk_buff *skb;
3477 int ret, len;
3478
3479 len = sizeof(*cmd);
3480
3481 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3482 if (!skb)
3483 return -ENOMEM;
3484
3485 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3486 cmd->tlv_header =
3487 FIELD_PREP(WMI_TLV_TAG,
3488 WMI_TAG_PDEV_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3489 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3490 cmd->pdev_id = ar->pdev->pdev_id;
3491 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3492
3493 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3494 "obss pd srg pdev_id %d bssid enable bitmap %08x %08x\n",
3495 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3496
3497 ret = ath11k_wmi_cmd_send(wmi, skb,
3498 WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3499 if (ret) {
3500 ath11k_warn(ab,
3501 "failed to send WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3502 dev_kfree_skb(skb);
3503 }
3504
3505 return ret;
3506 }
3507
3508 int
ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k * ar,u32 * bitmap)3509 ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3510 {
3511 struct ath11k_pdev_wmi *wmi = ar->wmi;
3512 struct ath11k_base *ab = wmi->wmi_ab->ab;
3513 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3514 struct sk_buff *skb;
3515 int ret, len;
3516
3517 len = sizeof(*cmd);
3518
3519 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3520 if (!skb)
3521 return -ENOMEM;
3522
3523 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3524 cmd->tlv_header =
3525 FIELD_PREP(WMI_TLV_TAG,
3526 WMI_TAG_PDEV_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) |
3527 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3528 cmd->pdev_id = ar->pdev->pdev_id;
3529 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3530
3531 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3532 "obss pd non_srg pdev_id %d bss color enable bitmap %08x %08x\n",
3533 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3534
3535 ret = ath11k_wmi_cmd_send(wmi, skb,
3536 WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID);
3537 if (ret) {
3538 ath11k_warn(ab,
3539 "failed to send WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID");
3540 dev_kfree_skb(skb);
3541 }
3542
3543 return ret;
3544 }
3545
3546 int
ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k * ar,u32 * bitmap)3547 ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap)
3548 {
3549 struct ath11k_pdev_wmi *wmi = ar->wmi;
3550 struct ath11k_base *ab = wmi->wmi_ab->ab;
3551 struct wmi_pdev_obss_pd_bitmap_cmd *cmd;
3552 struct sk_buff *skb;
3553 int ret, len;
3554
3555 len = sizeof(*cmd);
3556
3557 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3558 if (!skb)
3559 return -ENOMEM;
3560
3561 cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data;
3562 cmd->tlv_header =
3563 FIELD_PREP(WMI_TLV_TAG,
3564 WMI_TAG_PDEV_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) |
3565 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3566 cmd->pdev_id = ar->pdev->pdev_id;
3567 memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap));
3568
3569 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3570 "obss pd non_srg pdev_id %d bssid enable bitmap %08x %08x\n",
3571 cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]);
3572
3573 ret = ath11k_wmi_cmd_send(wmi, skb,
3574 WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID);
3575 if (ret) {
3576 ath11k_warn(ab,
3577 "failed to send WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID");
3578 dev_kfree_skb(skb);
3579 }
3580
3581 return ret;
3582 }
3583
3584 int
ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k * ar,u32 vdev_id,u8 bss_color,u32 period,bool enable)3585 ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id,
3586 u8 bss_color, u32 period,
3587 bool enable)
3588 {
3589 struct ath11k_pdev_wmi *wmi = ar->wmi;
3590 struct ath11k_base *ab = wmi->wmi_ab->ab;
3591 struct wmi_obss_color_collision_cfg_params_cmd *cmd;
3592 struct sk_buff *skb;
3593 int ret, len;
3594
3595 len = sizeof(*cmd);
3596
3597 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3598 if (!skb)
3599 return -ENOMEM;
3600
3601 cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data;
3602 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3603 WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) |
3604 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3605 cmd->vdev_id = vdev_id;
3606 cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION :
3607 ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE;
3608 cmd->current_bss_color = bss_color;
3609 cmd->detection_period_ms = period;
3610 cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS;
3611 cmd->free_slot_expiry_time_ms = 0;
3612 cmd->flags = 0;
3613
3614 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3615 "wmi_send_obss_color_collision_cfg id %d type %d bss_color %d detect_period %d scan_period %d\n",
3616 cmd->vdev_id, cmd->evt_type, cmd->current_bss_color,
3617 cmd->detection_period_ms, cmd->scan_period_ms);
3618
3619 ret = ath11k_wmi_cmd_send(wmi, skb,
3620 WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID);
3621 if (ret) {
3622 ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID");
3623 dev_kfree_skb(skb);
3624 }
3625 return ret;
3626 }
3627
ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k * ar,u32 vdev_id,bool enable)3628 int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id,
3629 bool enable)
3630 {
3631 struct ath11k_pdev_wmi *wmi = ar->wmi;
3632 struct ath11k_base *ab = wmi->wmi_ab->ab;
3633 struct wmi_bss_color_change_enable_params_cmd *cmd;
3634 struct sk_buff *skb;
3635 int ret, len;
3636
3637 len = sizeof(*cmd);
3638
3639 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3640 if (!skb)
3641 return -ENOMEM;
3642
3643 cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data;
3644 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) |
3645 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3646 cmd->vdev_id = vdev_id;
3647 cmd->enable = enable ? 1 : 0;
3648
3649 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3650 "wmi_send_bss_color_change_enable id %d enable %d\n",
3651 cmd->vdev_id, cmd->enable);
3652
3653 ret = ath11k_wmi_cmd_send(wmi, skb,
3654 WMI_BSS_COLOR_CHANGE_ENABLE_CMDID);
3655 if (ret) {
3656 ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID");
3657 dev_kfree_skb(skb);
3658 }
3659 return ret;
3660 }
3661
ath11k_wmi_fils_discovery_tmpl(struct ath11k * ar,u32 vdev_id,struct sk_buff * tmpl)3662 int ath11k_wmi_fils_discovery_tmpl(struct ath11k *ar, u32 vdev_id,
3663 struct sk_buff *tmpl)
3664 {
3665 struct wmi_tlv *tlv;
3666 struct sk_buff *skb;
3667 void *ptr;
3668 int ret, len;
3669 size_t aligned_len;
3670 struct wmi_fils_discovery_tmpl_cmd *cmd;
3671
3672 aligned_len = roundup(tmpl->len, 4);
3673 len = sizeof(*cmd) + TLV_HDR_SIZE + aligned_len;
3674
3675 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3676 "WMI vdev %i set FILS discovery template\n", vdev_id);
3677
3678 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3679 if (!skb)
3680 return -ENOMEM;
3681
3682 cmd = (struct wmi_fils_discovery_tmpl_cmd *)skb->data;
3683 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3684 WMI_TAG_FILS_DISCOVERY_TMPL_CMD) |
3685 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3686 cmd->vdev_id = vdev_id;
3687 cmd->buf_len = tmpl->len;
3688 ptr = skb->data + sizeof(*cmd);
3689
3690 tlv = ptr;
3691 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3692 FIELD_PREP(WMI_TLV_LEN, aligned_len);
3693 memcpy(tlv->value, tmpl->data, tmpl->len);
3694
3695 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_FILS_DISCOVERY_TMPL_CMDID);
3696 if (ret) {
3697 ath11k_warn(ar->ab,
3698 "WMI vdev %i failed to send FILS discovery template command\n",
3699 vdev_id);
3700 dev_kfree_skb(skb);
3701 }
3702 return ret;
3703 }
3704
ath11k_wmi_probe_resp_tmpl(struct ath11k * ar,u32 vdev_id,struct sk_buff * tmpl)3705 int ath11k_wmi_probe_resp_tmpl(struct ath11k *ar, u32 vdev_id,
3706 struct sk_buff *tmpl)
3707 {
3708 struct wmi_probe_tmpl_cmd *cmd;
3709 struct wmi_bcn_prb_info *probe_info;
3710 struct wmi_tlv *tlv;
3711 struct sk_buff *skb;
3712 void *ptr;
3713 int ret, len;
3714 size_t aligned_len = roundup(tmpl->len, 4);
3715
3716 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3717 "WMI vdev %i set probe response template\n", vdev_id);
3718
3719 len = sizeof(*cmd) + sizeof(*probe_info) + TLV_HDR_SIZE + aligned_len;
3720
3721 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3722 if (!skb)
3723 return -ENOMEM;
3724
3725 cmd = (struct wmi_probe_tmpl_cmd *)skb->data;
3726 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PRB_TMPL_CMD) |
3727 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3728 cmd->vdev_id = vdev_id;
3729 cmd->buf_len = tmpl->len;
3730
3731 ptr = skb->data + sizeof(*cmd);
3732
3733 probe_info = ptr;
3734 len = sizeof(*probe_info);
3735 probe_info->tlv_header = FIELD_PREP(WMI_TLV_TAG,
3736 WMI_TAG_BCN_PRB_INFO) |
3737 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3738 probe_info->caps = 0;
3739 probe_info->erp = 0;
3740
3741 ptr += sizeof(*probe_info);
3742
3743 tlv = ptr;
3744 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
3745 FIELD_PREP(WMI_TLV_LEN, aligned_len);
3746 memcpy(tlv->value, tmpl->data, tmpl->len);
3747
3748 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_PRB_TMPL_CMDID);
3749 if (ret) {
3750 ath11k_warn(ar->ab,
3751 "WMI vdev %i failed to send probe response template command\n",
3752 vdev_id);
3753 dev_kfree_skb(skb);
3754 }
3755 return ret;
3756 }
3757
ath11k_wmi_fils_discovery(struct ath11k * ar,u32 vdev_id,u32 interval,bool unsol_bcast_probe_resp_enabled)3758 int ath11k_wmi_fils_discovery(struct ath11k *ar, u32 vdev_id, u32 interval,
3759 bool unsol_bcast_probe_resp_enabled)
3760 {
3761 struct sk_buff *skb;
3762 int ret, len;
3763 struct wmi_fils_discovery_cmd *cmd;
3764
3765 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
3766 "WMI vdev %i set %s interval to %u TU\n",
3767 vdev_id, unsol_bcast_probe_resp_enabled ?
3768 "unsolicited broadcast probe response" : "FILS discovery",
3769 interval);
3770
3771 len = sizeof(*cmd);
3772 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
3773 if (!skb)
3774 return -ENOMEM;
3775
3776 cmd = (struct wmi_fils_discovery_cmd *)skb->data;
3777 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ENABLE_FILS_CMD) |
3778 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
3779 cmd->vdev_id = vdev_id;
3780 cmd->interval = interval;
3781 cmd->config = unsol_bcast_probe_resp_enabled;
3782
3783 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_ENABLE_FILS_CMDID);
3784 if (ret) {
3785 ath11k_warn(ar->ab,
3786 "WMI vdev %i failed to send FILS discovery enable/disable command\n",
3787 vdev_id);
3788 dev_kfree_skb(skb);
3789 }
3790 return ret;
3791 }
3792
3793 static void
ath11k_wmi_obss_color_collision_event(struct ath11k_base * ab,struct sk_buff * skb)3794 ath11k_wmi_obss_color_collision_event(struct ath11k_base *ab, struct sk_buff *skb)
3795 {
3796 const void **tb;
3797 const struct wmi_obss_color_collision_event *ev;
3798 struct ath11k_vif *arvif;
3799 int ret;
3800
3801 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
3802 if (IS_ERR(tb)) {
3803 ret = PTR_ERR(tb);
3804 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
3805 return;
3806 }
3807
3808 rcu_read_lock();
3809
3810 ev = tb[WMI_TAG_OBSS_COLOR_COLLISION_EVT];
3811 if (!ev) {
3812 ath11k_warn(ab, "failed to fetch obss color collision ev");
3813 goto exit;
3814 }
3815
3816 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
3817 if (!arvif) {
3818 ath11k_warn(ab, "failed to find arvif with vedv id %d in obss_color_collision_event\n",
3819 ev->vdev_id);
3820 goto exit;
3821 }
3822
3823 switch (ev->evt_type) {
3824 case WMI_BSS_COLOR_COLLISION_DETECTION:
3825 ieeee80211_obss_color_collision_notify(arvif->vif, ev->obss_color_bitmap,
3826 GFP_KERNEL);
3827 ath11k_dbg(ab, ATH11K_DBG_WMI,
3828 "OBSS color collision detected vdev:%d, event:%d, bitmap:%08llx\n",
3829 ev->vdev_id, ev->evt_type, ev->obss_color_bitmap);
3830 break;
3831 case WMI_BSS_COLOR_COLLISION_DISABLE:
3832 case WMI_BSS_COLOR_FREE_SLOT_TIMER_EXPIRY:
3833 case WMI_BSS_COLOR_FREE_SLOT_AVAILABLE:
3834 break;
3835 default:
3836 ath11k_warn(ab, "received unknown obss color collision detection event\n");
3837 }
3838
3839 exit:
3840 kfree(tb);
3841 rcu_read_unlock();
3842 }
3843
3844 static void
ath11k_fill_band_to_mac_param(struct ath11k_base * soc,struct wmi_host_pdev_band_to_mac * band_to_mac)3845 ath11k_fill_band_to_mac_param(struct ath11k_base *soc,
3846 struct wmi_host_pdev_band_to_mac *band_to_mac)
3847 {
3848 u8 i;
3849 struct ath11k_hal_reg_capabilities_ext *hal_reg_cap;
3850 struct ath11k_pdev *pdev;
3851
3852 for (i = 0; i < soc->num_radios; i++) {
3853 pdev = &soc->pdevs[i];
3854 hal_reg_cap = &soc->hal_reg_cap[i];
3855 band_to_mac[i].pdev_id = pdev->pdev_id;
3856
3857 switch (pdev->cap.supported_bands) {
3858 case WMI_HOST_WLAN_2G_5G_CAP:
3859 band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3860 band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3861 break;
3862 case WMI_HOST_WLAN_2G_CAP:
3863 band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan;
3864 band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan;
3865 break;
3866 case WMI_HOST_WLAN_5G_CAP:
3867 band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan;
3868 band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan;
3869 break;
3870 default:
3871 break;
3872 }
3873 }
3874 }
3875
3876 static void
ath11k_wmi_copy_resource_config(struct wmi_resource_config * wmi_cfg,struct target_resource_config * tg_cfg)3877 ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg,
3878 struct target_resource_config *tg_cfg)
3879 {
3880 wmi_cfg->num_vdevs = tg_cfg->num_vdevs;
3881 wmi_cfg->num_peers = tg_cfg->num_peers;
3882 wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers;
3883 wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs;
3884 wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys;
3885 wmi_cfg->num_tids = tg_cfg->num_tids;
3886 wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit;
3887 wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask;
3888 wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask;
3889 wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0];
3890 wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1];
3891 wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2];
3892 wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3];
3893 wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode;
3894 wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req;
3895 wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev;
3896 wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev;
3897 wmi_cfg->roam_offload_max_ap_profiles =
3898 tg_cfg->roam_offload_max_ap_profiles;
3899 wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups;
3900 wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems;
3901 wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode;
3902 wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size;
3903 wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries;
3904 wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size;
3905 wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim;
3906 wmi_cfg->rx_skip_defrag_timeout_dup_detection_check =
3907 tg_cfg->rx_skip_defrag_timeout_dup_detection_check;
3908 wmi_cfg->vow_config = tg_cfg->vow_config;
3909 wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev;
3910 wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc;
3911 wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries;
3912 wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs;
3913 wmi_cfg->num_tdls_conn_table_entries =
3914 tg_cfg->num_tdls_conn_table_entries;
3915 wmi_cfg->beacon_tx_offload_max_vdev =
3916 tg_cfg->beacon_tx_offload_max_vdev;
3917 wmi_cfg->num_multicast_filter_entries =
3918 tg_cfg->num_multicast_filter_entries;
3919 wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters;
3920 wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern;
3921 wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size;
3922 wmi_cfg->max_tdls_concurrent_sleep_sta =
3923 tg_cfg->max_tdls_concurrent_sleep_sta;
3924 wmi_cfg->max_tdls_concurrent_buffer_sta =
3925 tg_cfg->max_tdls_concurrent_buffer_sta;
3926 wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate;
3927 wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs;
3928 wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels;
3929 wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules;
3930 wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size;
3931 wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters;
3932 wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id;
3933 wmi_cfg->flag1 = tg_cfg->flag1;
3934 wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support;
3935 wmi_cfg->sched_params = tg_cfg->sched_params;
3936 wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count;
3937 wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count;
3938 }
3939
ath11k_init_cmd_send(struct ath11k_pdev_wmi * wmi,struct wmi_init_cmd_param * param)3940 static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi,
3941 struct wmi_init_cmd_param *param)
3942 {
3943 struct ath11k_base *ab = wmi->wmi_ab->ab;
3944 struct sk_buff *skb;
3945 struct wmi_init_cmd *cmd;
3946 struct wmi_resource_config *cfg;
3947 struct wmi_pdev_set_hw_mode_cmd_param *hw_mode;
3948 struct wmi_pdev_band_to_mac *band_to_mac;
3949 struct wlan_host_mem_chunk *host_mem_chunks;
3950 struct wmi_tlv *tlv;
3951 size_t ret, len;
3952 void *ptr;
3953 u32 hw_mode_len = 0;
3954 u16 idx;
3955
3956 if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX)
3957 hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE +
3958 (param->num_band_to_mac * sizeof(*band_to_mac));
3959
3960 len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len +
3961 (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0);
3962
3963 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
3964 if (!skb)
3965 return -ENOMEM;
3966
3967 cmd = (struct wmi_init_cmd *)skb->data;
3968
3969 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) |
3970 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
3971
3972 ptr = skb->data + sizeof(*cmd);
3973 cfg = ptr;
3974
3975 ath11k_wmi_copy_resource_config(cfg, param->res_cfg);
3976
3977 cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) |
3978 FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE);
3979
3980 ptr += sizeof(*cfg);
3981 host_mem_chunks = ptr + TLV_HDR_SIZE;
3982 len = sizeof(struct wlan_host_mem_chunk);
3983
3984 for (idx = 0; idx < param->num_mem_chunks; ++idx) {
3985 host_mem_chunks[idx].tlv_header =
3986 FIELD_PREP(WMI_TLV_TAG,
3987 WMI_TAG_WLAN_HOST_MEMORY_CHUNK) |
3988 FIELD_PREP(WMI_TLV_LEN, len);
3989
3990 host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr;
3991 host_mem_chunks[idx].size = param->mem_chunks[idx].len;
3992 host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id;
3993
3994 ath11k_dbg(ab, ATH11K_DBG_WMI,
3995 "WMI host mem chunk req_id %d paddr 0x%llx len %d\n",
3996 param->mem_chunks[idx].req_id,
3997 (u64)param->mem_chunks[idx].paddr,
3998 param->mem_chunks[idx].len);
3999 }
4000 cmd->num_host_mem_chunks = param->num_mem_chunks;
4001 len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks;
4002
4003 /* num_mem_chunks is zero */
4004 tlv = ptr;
4005 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4006 FIELD_PREP(WMI_TLV_LEN, len);
4007 ptr += TLV_HDR_SIZE + len;
4008
4009 if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) {
4010 hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr;
4011 hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4012 WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4013 FIELD_PREP(WMI_TLV_LEN,
4014 sizeof(*hw_mode) - TLV_HDR_SIZE);
4015
4016 hw_mode->hw_mode_index = param->hw_mode_id;
4017 hw_mode->num_band_to_mac = param->num_band_to_mac;
4018
4019 ptr += sizeof(*hw_mode);
4020
4021 len = param->num_band_to_mac * sizeof(*band_to_mac);
4022 tlv = ptr;
4023 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
4024 FIELD_PREP(WMI_TLV_LEN, len);
4025
4026 ptr += TLV_HDR_SIZE;
4027 len = sizeof(*band_to_mac);
4028
4029 for (idx = 0; idx < param->num_band_to_mac; idx++) {
4030 band_to_mac = (void *)ptr;
4031
4032 band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4033 WMI_TAG_PDEV_BAND_TO_MAC) |
4034 FIELD_PREP(WMI_TLV_LEN,
4035 len - TLV_HDR_SIZE);
4036 band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id;
4037 band_to_mac->start_freq =
4038 param->band_to_mac[idx].start_freq;
4039 band_to_mac->end_freq =
4040 param->band_to_mac[idx].end_freq;
4041 ptr += sizeof(*band_to_mac);
4042 }
4043 }
4044
4045 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID);
4046 if (ret) {
4047 ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n");
4048 dev_kfree_skb(skb);
4049 }
4050
4051 return ret;
4052 }
4053
ath11k_wmi_pdev_lro_cfg(struct ath11k * ar,int pdev_id)4054 int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar,
4055 int pdev_id)
4056 {
4057 struct ath11k_wmi_pdev_lro_config_cmd *cmd;
4058 struct sk_buff *skb;
4059 int ret;
4060
4061 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4062 if (!skb)
4063 return -ENOMEM;
4064
4065 cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data;
4066 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) |
4067 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4068
4069 get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE);
4070 get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE);
4071
4072 cmd->pdev_id = pdev_id;
4073
4074 ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID);
4075 if (ret) {
4076 ath11k_warn(ar->ab,
4077 "failed to send lro cfg req wmi cmd\n");
4078 goto err;
4079 }
4080
4081 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4082 "WMI lro cfg cmd pdev_id 0x%x\n", pdev_id);
4083 return 0;
4084 err:
4085 dev_kfree_skb(skb);
4086 return ret;
4087 }
4088
ath11k_wmi_wait_for_service_ready(struct ath11k_base * ab)4089 int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab)
4090 {
4091 unsigned long time_left;
4092
4093 time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready,
4094 WMI_SERVICE_READY_TIMEOUT_HZ);
4095 if (!time_left)
4096 return -ETIMEDOUT;
4097
4098 return 0;
4099 }
4100
ath11k_wmi_wait_for_unified_ready(struct ath11k_base * ab)4101 int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab)
4102 {
4103 unsigned long time_left;
4104
4105 time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready,
4106 WMI_SERVICE_READY_TIMEOUT_HZ);
4107 if (!time_left)
4108 return -ETIMEDOUT;
4109
4110 return 0;
4111 }
4112
ath11k_wmi_set_hw_mode(struct ath11k_base * ab,enum wmi_host_hw_mode_config_type mode)4113 int ath11k_wmi_set_hw_mode(struct ath11k_base *ab,
4114 enum wmi_host_hw_mode_config_type mode)
4115 {
4116 struct wmi_pdev_set_hw_mode_cmd_param *cmd;
4117 struct sk_buff *skb;
4118 struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab;
4119 int len;
4120 int ret;
4121
4122 len = sizeof(*cmd);
4123
4124 skb = ath11k_wmi_alloc_skb(wmi_ab, len);
4125 if (!skb)
4126 return -ENOMEM;
4127
4128 cmd = (struct wmi_pdev_set_hw_mode_cmd_param *)skb->data;
4129
4130 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_HW_MODE_CMD) |
4131 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4132
4133 cmd->pdev_id = WMI_PDEV_ID_SOC;
4134 cmd->hw_mode_index = mode;
4135
4136 ret = ath11k_wmi_cmd_send(&wmi_ab->wmi[0], skb, WMI_PDEV_SET_HW_MODE_CMDID);
4137 if (ret) {
4138 ath11k_warn(ab, "failed to send WMI_PDEV_SET_HW_MODE_CMDID\n");
4139 dev_kfree_skb(skb);
4140 }
4141
4142 return ret;
4143 }
4144
ath11k_wmi_cmd_init(struct ath11k_base * ab)4145 int ath11k_wmi_cmd_init(struct ath11k_base *ab)
4146 {
4147 struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab;
4148 struct wmi_init_cmd_param init_param;
4149 struct target_resource_config config;
4150
4151 memset(&init_param, 0, sizeof(init_param));
4152 memset(&config, 0, sizeof(config));
4153
4154 ab->hw_params.hw_ops->wmi_init_config(ab, &config);
4155
4156 memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config));
4157
4158 init_param.res_cfg = &wmi_sc->wlan_resource_config;
4159 init_param.num_mem_chunks = wmi_sc->num_mem_chunks;
4160 init_param.hw_mode_id = wmi_sc->preferred_hw_mode;
4161 init_param.mem_chunks = wmi_sc->mem_chunks;
4162
4163 if (ab->hw_params.single_pdev_only)
4164 init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX;
4165
4166 init_param.num_band_to_mac = ab->num_radios;
4167 ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac);
4168
4169 return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param);
4170 }
4171
ath11k_wmi_vdev_spectral_conf(struct ath11k * ar,struct ath11k_wmi_vdev_spectral_conf_param * param)4172 int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar,
4173 struct ath11k_wmi_vdev_spectral_conf_param *param)
4174 {
4175 struct ath11k_wmi_vdev_spectral_conf_cmd *cmd;
4176 struct sk_buff *skb;
4177 int ret;
4178
4179 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4180 if (!skb)
4181 return -ENOMEM;
4182
4183 cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data;
4184 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4185 WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) |
4186 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4187
4188 memcpy(&cmd->param, param, sizeof(*param));
4189
4190 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4191 WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
4192 if (ret) {
4193 ath11k_warn(ar->ab,
4194 "failed to send spectral scan config wmi cmd\n");
4195 goto err;
4196 }
4197
4198 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4199 "WMI spectral scan config cmd vdev_id 0x%x\n",
4200 param->vdev_id);
4201
4202 return 0;
4203 err:
4204 dev_kfree_skb(skb);
4205 return ret;
4206 }
4207
ath11k_wmi_vdev_spectral_enable(struct ath11k * ar,u32 vdev_id,u32 trigger,u32 enable)4208 int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id,
4209 u32 trigger, u32 enable)
4210 {
4211 struct ath11k_wmi_vdev_spectral_enable_cmd *cmd;
4212 struct sk_buff *skb;
4213 int ret;
4214
4215 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4216 if (!skb)
4217 return -ENOMEM;
4218
4219 cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data;
4220 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
4221 WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) |
4222 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4223
4224 cmd->vdev_id = vdev_id;
4225 cmd->trigger_cmd = trigger;
4226 cmd->enable_cmd = enable;
4227
4228 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4229 WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
4230 if (ret) {
4231 ath11k_warn(ar->ab,
4232 "failed to send spectral enable wmi cmd\n");
4233 goto err;
4234 }
4235
4236 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4237 "WMI spectral enable cmd vdev id 0x%x\n",
4238 vdev_id);
4239
4240 return 0;
4241 err:
4242 dev_kfree_skb(skb);
4243 return ret;
4244 }
4245
ath11k_wmi_pdev_dma_ring_cfg(struct ath11k * ar,struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd * param)4246 int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar,
4247 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param)
4248 {
4249 struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd;
4250 struct sk_buff *skb;
4251 int ret;
4252
4253 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd));
4254 if (!skb)
4255 return -ENOMEM;
4256
4257 cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data;
4258 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) |
4259 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
4260
4261 cmd->pdev_id = param->pdev_id;
4262 cmd->module_id = param->module_id;
4263 cmd->base_paddr_lo = param->base_paddr_lo;
4264 cmd->base_paddr_hi = param->base_paddr_hi;
4265 cmd->head_idx_paddr_lo = param->head_idx_paddr_lo;
4266 cmd->head_idx_paddr_hi = param->head_idx_paddr_hi;
4267 cmd->tail_idx_paddr_lo = param->tail_idx_paddr_lo;
4268 cmd->tail_idx_paddr_hi = param->tail_idx_paddr_hi;
4269 cmd->num_elems = param->num_elems;
4270 cmd->buf_size = param->buf_size;
4271 cmd->num_resp_per_event = param->num_resp_per_event;
4272 cmd->event_timeout_ms = param->event_timeout_ms;
4273
4274 ret = ath11k_wmi_cmd_send(ar->wmi, skb,
4275 WMI_PDEV_DMA_RING_CFG_REQ_CMDID);
4276 if (ret) {
4277 ath11k_warn(ar->ab,
4278 "failed to send dma ring cfg req wmi cmd\n");
4279 goto err;
4280 }
4281
4282 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
4283 "WMI DMA ring cfg req cmd pdev_id 0x%x\n",
4284 param->pdev_id);
4285
4286 return 0;
4287 err:
4288 dev_kfree_skb(skb);
4289 return ret;
4290 }
4291
ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4292 static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc,
4293 u16 tag, u16 len,
4294 const void *ptr, void *data)
4295 {
4296 struct wmi_tlv_dma_buf_release_parse *parse = data;
4297
4298 if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY)
4299 return -EPROTO;
4300
4301 if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry)
4302 return -ENOBUFS;
4303
4304 parse->num_buf_entry++;
4305 return 0;
4306 }
4307
ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4308 static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc,
4309 u16 tag, u16 len,
4310 const void *ptr, void *data)
4311 {
4312 struct wmi_tlv_dma_buf_release_parse *parse = data;
4313
4314 if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA)
4315 return -EPROTO;
4316
4317 if (parse->num_meta >= parse->fixed.num_meta_data_entry)
4318 return -ENOBUFS;
4319
4320 parse->num_meta++;
4321 return 0;
4322 }
4323
ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)4324 static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab,
4325 u16 tag, u16 len,
4326 const void *ptr, void *data)
4327 {
4328 struct wmi_tlv_dma_buf_release_parse *parse = data;
4329 int ret;
4330
4331 switch (tag) {
4332 case WMI_TAG_DMA_BUF_RELEASE:
4333 memcpy(&parse->fixed, ptr,
4334 sizeof(struct ath11k_wmi_dma_buf_release_fixed_param));
4335 parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id);
4336 break;
4337 case WMI_TAG_ARRAY_STRUCT:
4338 if (!parse->buf_entry_done) {
4339 parse->num_buf_entry = 0;
4340 parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr;
4341
4342 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4343 ath11k_wmi_tlv_dma_buf_entry_parse,
4344 parse);
4345 if (ret) {
4346 ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n",
4347 ret);
4348 return ret;
4349 }
4350
4351 parse->buf_entry_done = true;
4352 } else if (!parse->meta_data_done) {
4353 parse->num_meta = 0;
4354 parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr;
4355
4356 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4357 ath11k_wmi_tlv_dma_buf_meta_parse,
4358 parse);
4359 if (ret) {
4360 ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n",
4361 ret);
4362 return ret;
4363 }
4364
4365 parse->meta_data_done = true;
4366 }
4367 break;
4368 default:
4369 break;
4370 }
4371 return 0;
4372 }
4373
ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base * ab,struct sk_buff * skb)4374 static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab,
4375 struct sk_buff *skb)
4376 {
4377 struct wmi_tlv_dma_buf_release_parse parse = { };
4378 struct ath11k_dbring_buf_release_event param;
4379 int ret;
4380
4381 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4382 ath11k_wmi_tlv_dma_buf_parse,
4383 &parse);
4384 if (ret) {
4385 ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret);
4386 return;
4387 }
4388
4389 param.fixed = parse.fixed;
4390 param.buf_entry = parse.buf_entry;
4391 param.num_buf_entry = parse.num_buf_entry;
4392 param.meta_data = parse.meta_data;
4393 param.num_meta = parse.num_meta;
4394
4395 ret = ath11k_dbring_buffer_release_event(ab, ¶m);
4396 if (ret) {
4397 ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret);
4398 return;
4399 }
4400 }
4401
ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4402 static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc,
4403 u16 tag, u16 len,
4404 const void *ptr, void *data)
4405 {
4406 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4407 struct wmi_hw_mode_capabilities *hw_mode_cap;
4408 u32 phy_map = 0;
4409
4410 if (tag != WMI_TAG_HW_MODE_CAPABILITIES)
4411 return -EPROTO;
4412
4413 if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes)
4414 return -ENOBUFS;
4415
4416 hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities,
4417 hw_mode_id);
4418 svc_rdy_ext->n_hw_mode_caps++;
4419
4420 phy_map = hw_mode_cap->phy_id_map;
4421 while (phy_map) {
4422 svc_rdy_ext->tot_phy_id++;
4423 phy_map = phy_map >> 1;
4424 }
4425
4426 return 0;
4427 }
4428
ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base * soc,u16 len,const void * ptr,void * data)4429 static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc,
4430 u16 len, const void *ptr, void *data)
4431 {
4432 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4433 struct wmi_hw_mode_capabilities *hw_mode_caps;
4434 enum wmi_host_hw_mode_config_type mode, pref;
4435 u32 i;
4436 int ret;
4437
4438 svc_rdy_ext->n_hw_mode_caps = 0;
4439 svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr;
4440
4441 ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4442 ath11k_wmi_tlv_hw_mode_caps_parse,
4443 svc_rdy_ext);
4444 if (ret) {
4445 ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4446 return ret;
4447 }
4448
4449 i = 0;
4450 while (i < svc_rdy_ext->n_hw_mode_caps) {
4451 hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i];
4452 mode = hw_mode_caps->hw_mode_id;
4453 pref = soc->wmi_ab.preferred_hw_mode;
4454
4455 if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) {
4456 svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps;
4457 soc->wmi_ab.preferred_hw_mode = mode;
4458 }
4459 i++;
4460 }
4461
4462 ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n",
4463 soc->wmi_ab.preferred_hw_mode);
4464 if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX)
4465 return -EINVAL;
4466
4467 return 0;
4468 }
4469
ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4470 static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc,
4471 u16 tag, u16 len,
4472 const void *ptr, void *data)
4473 {
4474 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4475
4476 if (tag != WMI_TAG_MAC_PHY_CAPABILITIES)
4477 return -EPROTO;
4478
4479 if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id)
4480 return -ENOBUFS;
4481
4482 len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities));
4483 if (!svc_rdy_ext->n_mac_phy_caps) {
4484 svc_rdy_ext->mac_phy_caps = kcalloc(svc_rdy_ext->tot_phy_id,
4485 len, GFP_ATOMIC);
4486 if (!svc_rdy_ext->mac_phy_caps)
4487 return -ENOMEM;
4488 }
4489
4490 memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len);
4491 svc_rdy_ext->n_mac_phy_caps++;
4492 return 0;
4493 }
4494
ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4495 static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc,
4496 u16 tag, u16 len,
4497 const void *ptr, void *data)
4498 {
4499 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4500
4501 if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT)
4502 return -EPROTO;
4503
4504 if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy)
4505 return -ENOBUFS;
4506
4507 svc_rdy_ext->n_ext_hal_reg_caps++;
4508 return 0;
4509 }
4510
ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base * soc,u16 len,const void * ptr,void * data)4511 static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc,
4512 u16 len, const void *ptr, void *data)
4513 {
4514 struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4515 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4516 struct ath11k_hal_reg_capabilities_ext reg_cap;
4517 int ret;
4518 u32 i;
4519
4520 svc_rdy_ext->n_ext_hal_reg_caps = 0;
4521 svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr;
4522 ret = ath11k_wmi_tlv_iter(soc, ptr, len,
4523 ath11k_wmi_tlv_ext_hal_reg_caps_parse,
4524 svc_rdy_ext);
4525 if (ret) {
4526 ath11k_warn(soc, "failed to parse tlv %d\n", ret);
4527 return ret;
4528 }
4529
4530 for (i = 0; i < svc_rdy_ext->param.num_phy; i++) {
4531 ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle,
4532 svc_rdy_ext->soc_hal_reg_caps,
4533 svc_rdy_ext->ext_hal_reg_caps, i,
4534 ®_cap);
4535 if (ret) {
4536 ath11k_warn(soc, "failed to extract reg cap %d\n", i);
4537 return ret;
4538 }
4539
4540 memcpy(&soc->hal_reg_cap[reg_cap.phy_id],
4541 ®_cap, sizeof(reg_cap));
4542 }
4543 return 0;
4544 }
4545
ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base * soc,u16 len,const void * ptr,void * data)4546 static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc,
4547 u16 len, const void *ptr,
4548 void *data)
4549 {
4550 struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0];
4551 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4552 u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id;
4553 u32 phy_id_map;
4554 int pdev_index = 0;
4555 int ret;
4556
4557 svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr;
4558 svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy;
4559
4560 soc->num_radios = 0;
4561 soc->target_pdev_count = 0;
4562 phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map;
4563
4564 while (phy_id_map && soc->num_radios < MAX_RADIOS) {
4565 ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle,
4566 svc_rdy_ext->hw_caps,
4567 svc_rdy_ext->hw_mode_caps,
4568 svc_rdy_ext->soc_hal_reg_caps,
4569 svc_rdy_ext->mac_phy_caps,
4570 hw_mode_id, soc->num_radios,
4571 &soc->pdevs[pdev_index]);
4572 if (ret) {
4573 ath11k_warn(soc, "failed to extract mac caps, idx :%d\n",
4574 soc->num_radios);
4575 return ret;
4576 }
4577
4578 soc->num_radios++;
4579
4580 /* For QCA6390, save mac_phy capability in the same pdev */
4581 if (soc->hw_params.single_pdev_only)
4582 pdev_index = 0;
4583 else
4584 pdev_index = soc->num_radios;
4585
4586 /* TODO: mac_phy_cap prints */
4587 phy_id_map >>= 1;
4588 }
4589
4590 /* For QCA6390, set num_radios to 1 because host manages
4591 * both 2G and 5G radio in one pdev.
4592 * Set pdev_id = 0 and 0 means soc level.
4593 */
4594 if (soc->hw_params.single_pdev_only) {
4595 soc->num_radios = 1;
4596 soc->pdevs[0].pdev_id = 0;
4597 }
4598
4599 return 0;
4600 }
4601
ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base * soc,u16 tag,u16 len,const void * ptr,void * data)4602 static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc,
4603 u16 tag, u16 len,
4604 const void *ptr, void *data)
4605 {
4606 struct wmi_tlv_dma_ring_caps_parse *parse = data;
4607
4608 if (tag != WMI_TAG_DMA_RING_CAPABILITIES)
4609 return -EPROTO;
4610
4611 parse->n_dma_ring_caps++;
4612 return 0;
4613 }
4614
ath11k_wmi_alloc_dbring_caps(struct ath11k_base * ab,u32 num_cap)4615 static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab,
4616 u32 num_cap)
4617 {
4618 size_t sz;
4619 void *ptr;
4620
4621 sz = num_cap * sizeof(struct ath11k_dbring_cap);
4622 ptr = kzalloc(sz, GFP_ATOMIC);
4623 if (!ptr)
4624 return -ENOMEM;
4625
4626 ab->db_caps = ptr;
4627 ab->num_db_cap = num_cap;
4628
4629 return 0;
4630 }
4631
ath11k_wmi_free_dbring_caps(struct ath11k_base * ab)4632 static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab)
4633 {
4634 kfree(ab->db_caps);
4635 ab->db_caps = NULL;
4636 }
4637
ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base * ab,u16 len,const void * ptr,void * data)4638 static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab,
4639 u16 len, const void *ptr, void *data)
4640 {
4641 struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data;
4642 struct wmi_dma_ring_capabilities *dma_caps;
4643 struct ath11k_dbring_cap *dir_buff_caps;
4644 int ret;
4645 u32 i;
4646
4647 dma_caps_parse->n_dma_ring_caps = 0;
4648 dma_caps = (struct wmi_dma_ring_capabilities *)ptr;
4649 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4650 ath11k_wmi_tlv_dma_ring_caps_parse,
4651 dma_caps_parse);
4652 if (ret) {
4653 ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret);
4654 return ret;
4655 }
4656
4657 if (!dma_caps_parse->n_dma_ring_caps)
4658 return 0;
4659
4660 if (ab->num_db_cap) {
4661 ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n");
4662 return 0;
4663 }
4664
4665 ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps);
4666 if (ret)
4667 return ret;
4668
4669 dir_buff_caps = ab->db_caps;
4670 for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) {
4671 if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) {
4672 ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id);
4673 ret = -EINVAL;
4674 goto free_dir_buff;
4675 }
4676
4677 dir_buff_caps[i].id = dma_caps[i].module_id;
4678 dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id);
4679 dir_buff_caps[i].min_elem = dma_caps[i].min_elem;
4680 dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz;
4681 dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align;
4682 }
4683
4684 return 0;
4685
4686 free_dir_buff:
4687 ath11k_wmi_free_dbring_caps(ab);
4688 return ret;
4689 }
4690
ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)4691 static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab,
4692 u16 tag, u16 len,
4693 const void *ptr, void *data)
4694 {
4695 struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0];
4696 struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data;
4697 int ret;
4698
4699 switch (tag) {
4700 case WMI_TAG_SERVICE_READY_EXT_EVENT:
4701 ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr,
4702 &svc_rdy_ext->param);
4703 if (ret) {
4704 ath11k_warn(ab, "unable to extract ext params\n");
4705 return ret;
4706 }
4707 break;
4708
4709 case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS:
4710 svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr;
4711 svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes;
4712 break;
4713
4714 case WMI_TAG_SOC_HAL_REG_CAPABILITIES:
4715 ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr,
4716 svc_rdy_ext);
4717 if (ret)
4718 return ret;
4719 break;
4720
4721 case WMI_TAG_ARRAY_STRUCT:
4722 if (!svc_rdy_ext->hw_mode_done) {
4723 ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr,
4724 svc_rdy_ext);
4725 if (ret)
4726 return ret;
4727
4728 svc_rdy_ext->hw_mode_done = true;
4729 } else if (!svc_rdy_ext->mac_phy_done) {
4730 svc_rdy_ext->n_mac_phy_caps = 0;
4731 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
4732 ath11k_wmi_tlv_mac_phy_caps_parse,
4733 svc_rdy_ext);
4734 if (ret) {
4735 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4736 return ret;
4737 }
4738
4739 svc_rdy_ext->mac_phy_done = true;
4740 } else if (!svc_rdy_ext->ext_hal_reg_done) {
4741 ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr,
4742 svc_rdy_ext);
4743 if (ret)
4744 return ret;
4745
4746 svc_rdy_ext->ext_hal_reg_done = true;
4747 } else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) {
4748 svc_rdy_ext->mac_phy_chainmask_combo_done = true;
4749 } else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) {
4750 svc_rdy_ext->mac_phy_chainmask_cap_done = true;
4751 } else if (!svc_rdy_ext->oem_dma_ring_cap_done) {
4752 svc_rdy_ext->oem_dma_ring_cap_done = true;
4753 } else if (!svc_rdy_ext->dma_ring_cap_done) {
4754 ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4755 &svc_rdy_ext->dma_caps_parse);
4756 if (ret)
4757 return ret;
4758
4759 svc_rdy_ext->dma_ring_cap_done = true;
4760 }
4761 break;
4762
4763 default:
4764 break;
4765 }
4766 return 0;
4767 }
4768
ath11k_service_ready_ext_event(struct ath11k_base * ab,struct sk_buff * skb)4769 static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
4770 struct sk_buff *skb)
4771 {
4772 struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { };
4773 int ret;
4774
4775 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4776 ath11k_wmi_tlv_svc_rdy_ext_parse,
4777 &svc_rdy_ext);
4778 if (ret) {
4779 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
4780 goto err;
4781 }
4782
4783 if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map))
4784 complete(&ab->wmi_ab.service_ready);
4785
4786 kfree(svc_rdy_ext.mac_phy_caps);
4787 return 0;
4788
4789 err:
4790 ath11k_wmi_free_dbring_caps(ab);
4791 return ret;
4792 }
4793
ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)4794 static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab,
4795 u16 tag, u16 len,
4796 const void *ptr, void *data)
4797 {
4798 struct wmi_tlv_svc_rdy_ext2_parse *parse = data;
4799 int ret;
4800
4801 switch (tag) {
4802 case WMI_TAG_ARRAY_STRUCT:
4803 if (!parse->dma_ring_cap_done) {
4804 ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr,
4805 &parse->dma_caps_parse);
4806 if (ret)
4807 return ret;
4808
4809 parse->dma_ring_cap_done = true;
4810 }
4811 break;
4812 default:
4813 break;
4814 }
4815
4816 return 0;
4817 }
4818
ath11k_service_ready_ext2_event(struct ath11k_base * ab,struct sk_buff * skb)4819 static int ath11k_service_ready_ext2_event(struct ath11k_base *ab,
4820 struct sk_buff *skb)
4821 {
4822 struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { };
4823 int ret;
4824
4825 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
4826 ath11k_wmi_tlv_svc_rdy_ext2_parse,
4827 &svc_rdy_ext2);
4828 if (ret) {
4829 ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret);
4830 goto err;
4831 }
4832
4833 complete(&ab->wmi_ab.service_ready);
4834
4835 return 0;
4836
4837 err:
4838 ath11k_wmi_free_dbring_caps(ab);
4839 return ret;
4840 }
4841
ath11k_pull_vdev_start_resp_tlv(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_vdev_start_resp_event * vdev_rsp)4842 static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb,
4843 struct wmi_vdev_start_resp_event *vdev_rsp)
4844 {
4845 const void **tb;
4846 const struct wmi_vdev_start_resp_event *ev;
4847 int ret;
4848
4849 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4850 if (IS_ERR(tb)) {
4851 ret = PTR_ERR(tb);
4852 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4853 return ret;
4854 }
4855
4856 ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT];
4857 if (!ev) {
4858 ath11k_warn(ab, "failed to fetch vdev start resp ev");
4859 kfree(tb);
4860 return -EPROTO;
4861 }
4862
4863 memset(vdev_rsp, 0, sizeof(*vdev_rsp));
4864
4865 vdev_rsp->vdev_id = ev->vdev_id;
4866 vdev_rsp->requestor_id = ev->requestor_id;
4867 vdev_rsp->resp_type = ev->resp_type;
4868 vdev_rsp->status = ev->status;
4869 vdev_rsp->chain_mask = ev->chain_mask;
4870 vdev_rsp->smps_mode = ev->smps_mode;
4871 vdev_rsp->mac_id = ev->mac_id;
4872 vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams;
4873 vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams;
4874
4875 kfree(tb);
4876 return 0;
4877 }
4878
4879 static struct cur_reg_rule
create_reg_rules_from_wmi(u32 num_reg_rules,struct wmi_regulatory_rule_struct * wmi_reg_rule)4880 *create_reg_rules_from_wmi(u32 num_reg_rules,
4881 struct wmi_regulatory_rule_struct *wmi_reg_rule)
4882 {
4883 struct cur_reg_rule *reg_rule_ptr;
4884 u32 count;
4885
4886 reg_rule_ptr = kcalloc(num_reg_rules, sizeof(*reg_rule_ptr),
4887 GFP_ATOMIC);
4888
4889 if (!reg_rule_ptr)
4890 return NULL;
4891
4892 for (count = 0; count < num_reg_rules; count++) {
4893 reg_rule_ptr[count].start_freq =
4894 FIELD_GET(REG_RULE_START_FREQ,
4895 wmi_reg_rule[count].freq_info);
4896 reg_rule_ptr[count].end_freq =
4897 FIELD_GET(REG_RULE_END_FREQ,
4898 wmi_reg_rule[count].freq_info);
4899 reg_rule_ptr[count].max_bw =
4900 FIELD_GET(REG_RULE_MAX_BW,
4901 wmi_reg_rule[count].bw_pwr_info);
4902 reg_rule_ptr[count].reg_power =
4903 FIELD_GET(REG_RULE_REG_PWR,
4904 wmi_reg_rule[count].bw_pwr_info);
4905 reg_rule_ptr[count].ant_gain =
4906 FIELD_GET(REG_RULE_ANT_GAIN,
4907 wmi_reg_rule[count].bw_pwr_info);
4908 reg_rule_ptr[count].flags =
4909 FIELD_GET(REG_RULE_FLAGS,
4910 wmi_reg_rule[count].flag_info);
4911 }
4912
4913 return reg_rule_ptr;
4914 }
4915
ath11k_pull_reg_chan_list_update_ev(struct ath11k_base * ab,struct sk_buff * skb,struct cur_regulatory_info * reg_info)4916 static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab,
4917 struct sk_buff *skb,
4918 struct cur_regulatory_info *reg_info)
4919 {
4920 const void **tb;
4921 const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr;
4922 struct wmi_regulatory_rule_struct *wmi_reg_rule;
4923 u32 num_2g_reg_rules, num_5g_reg_rules;
4924 int ret;
4925
4926 ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n");
4927
4928 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
4929 if (IS_ERR(tb)) {
4930 ret = PTR_ERR(tb);
4931 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
4932 return ret;
4933 }
4934
4935 chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT];
4936 if (!chan_list_event_hdr) {
4937 ath11k_warn(ab, "failed to fetch reg chan list update ev\n");
4938 kfree(tb);
4939 return -EPROTO;
4940 }
4941
4942 reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules;
4943 reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules;
4944
4945 if (!(reg_info->num_2g_reg_rules + reg_info->num_5g_reg_rules)) {
4946 ath11k_warn(ab, "No regulatory rules available in the event info\n");
4947 kfree(tb);
4948 return -EINVAL;
4949 }
4950
4951 memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2,
4952 REG_ALPHA2_LEN);
4953 reg_info->dfs_region = chan_list_event_hdr->dfs_region;
4954 reg_info->phybitmap = chan_list_event_hdr->phybitmap;
4955 reg_info->num_phy = chan_list_event_hdr->num_phy;
4956 reg_info->phy_id = chan_list_event_hdr->phy_id;
4957 reg_info->ctry_code = chan_list_event_hdr->country_id;
4958 reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code;
4959 if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS)
4960 reg_info->status_code = REG_SET_CC_STATUS_PASS;
4961 else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND)
4962 reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND;
4963 else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND)
4964 reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND;
4965 else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED)
4966 reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED;
4967 else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY)
4968 reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY;
4969 else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL)
4970 reg_info->status_code = REG_SET_CC_STATUS_FAIL;
4971
4972 reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g;
4973 reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g;
4974 reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g;
4975 reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g;
4976
4977 num_2g_reg_rules = reg_info->num_2g_reg_rules;
4978 num_5g_reg_rules = reg_info->num_5g_reg_rules;
4979
4980 ath11k_dbg(ab, ATH11K_DBG_WMI,
4981 "%s:cc %s dsf %d BW: min_2g %d max_2g %d min_5g %d max_5g %d",
4982 __func__, reg_info->alpha2, reg_info->dfs_region,
4983 reg_info->min_bw_2g, reg_info->max_bw_2g,
4984 reg_info->min_bw_5g, reg_info->max_bw_5g);
4985
4986 ath11k_dbg(ab, ATH11K_DBG_WMI,
4987 "%s: num_2g_reg_rules %d num_5g_reg_rules %d", __func__,
4988 num_2g_reg_rules, num_5g_reg_rules);
4989
4990 wmi_reg_rule =
4991 (struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr
4992 + sizeof(*chan_list_event_hdr)
4993 + sizeof(struct wmi_tlv));
4994
4995 if (num_2g_reg_rules) {
4996 reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules,
4997 wmi_reg_rule);
4998 if (!reg_info->reg_rules_2g_ptr) {
4999 kfree(tb);
5000 ath11k_warn(ab, "Unable to Allocate memory for 2g rules\n");
5001 return -ENOMEM;
5002 }
5003 }
5004
5005 if (num_5g_reg_rules) {
5006 wmi_reg_rule += num_2g_reg_rules;
5007 reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules,
5008 wmi_reg_rule);
5009 if (!reg_info->reg_rules_5g_ptr) {
5010 kfree(tb);
5011 ath11k_warn(ab, "Unable to Allocate memory for 5g rules\n");
5012 return -ENOMEM;
5013 }
5014 }
5015
5016 ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n");
5017
5018 kfree(tb);
5019 return 0;
5020 }
5021
ath11k_pull_peer_del_resp_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_peer_delete_resp_event * peer_del_resp)5022 static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb,
5023 struct wmi_peer_delete_resp_event *peer_del_resp)
5024 {
5025 const void **tb;
5026 const struct wmi_peer_delete_resp_event *ev;
5027 int ret;
5028
5029 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5030 if (IS_ERR(tb)) {
5031 ret = PTR_ERR(tb);
5032 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5033 return ret;
5034 }
5035
5036 ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT];
5037 if (!ev) {
5038 ath11k_warn(ab, "failed to fetch peer delete resp ev");
5039 kfree(tb);
5040 return -EPROTO;
5041 }
5042
5043 memset(peer_del_resp, 0, sizeof(*peer_del_resp));
5044
5045 peer_del_resp->vdev_id = ev->vdev_id;
5046 ether_addr_copy(peer_del_resp->peer_macaddr.addr,
5047 ev->peer_macaddr.addr);
5048
5049 kfree(tb);
5050 return 0;
5051 }
5052
ath11k_pull_vdev_del_resp_ev(struct ath11k_base * ab,struct sk_buff * skb,u32 * vdev_id)5053 static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab,
5054 struct sk_buff *skb,
5055 u32 *vdev_id)
5056 {
5057 const void **tb;
5058 const struct wmi_vdev_delete_resp_event *ev;
5059 int ret;
5060
5061 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5062 if (IS_ERR(tb)) {
5063 ret = PTR_ERR(tb);
5064 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5065 return ret;
5066 }
5067
5068 ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT];
5069 if (!ev) {
5070 ath11k_warn(ab, "failed to fetch vdev delete resp ev");
5071 kfree(tb);
5072 return -EPROTO;
5073 }
5074
5075 *vdev_id = ev->vdev_id;
5076
5077 kfree(tb);
5078 return 0;
5079 }
5080
ath11k_pull_bcn_tx_status_ev(struct ath11k_base * ab,void * evt_buf,u32 len,u32 * vdev_id,u32 * tx_status)5081 static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf,
5082 u32 len, u32 *vdev_id,
5083 u32 *tx_status)
5084 {
5085 const void **tb;
5086 const struct wmi_bcn_tx_status_event *ev;
5087 int ret;
5088
5089 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5090 if (IS_ERR(tb)) {
5091 ret = PTR_ERR(tb);
5092 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5093 return ret;
5094 }
5095
5096 ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT];
5097 if (!ev) {
5098 ath11k_warn(ab, "failed to fetch bcn tx status ev");
5099 kfree(tb);
5100 return -EPROTO;
5101 }
5102
5103 *vdev_id = ev->vdev_id;
5104 *tx_status = ev->tx_status;
5105
5106 kfree(tb);
5107 return 0;
5108 }
5109
ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base * ab,struct sk_buff * skb,u32 * vdev_id)5110 static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb,
5111 u32 *vdev_id)
5112 {
5113 const void **tb;
5114 const struct wmi_vdev_stopped_event *ev;
5115 int ret;
5116
5117 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5118 if (IS_ERR(tb)) {
5119 ret = PTR_ERR(tb);
5120 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5121 return ret;
5122 }
5123
5124 ev = tb[WMI_TAG_VDEV_STOPPED_EVENT];
5125 if (!ev) {
5126 ath11k_warn(ab, "failed to fetch vdev stop ev");
5127 kfree(tb);
5128 return -EPROTO;
5129 }
5130
5131 *vdev_id = ev->vdev_id;
5132
5133 kfree(tb);
5134 return 0;
5135 }
5136
ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base * ab,struct sk_buff * skb,struct mgmt_rx_event_params * hdr)5137 static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab,
5138 struct sk_buff *skb,
5139 struct mgmt_rx_event_params *hdr)
5140 {
5141 const void **tb;
5142 const struct wmi_mgmt_rx_hdr *ev;
5143 const u8 *frame;
5144 int ret;
5145
5146 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5147 if (IS_ERR(tb)) {
5148 ret = PTR_ERR(tb);
5149 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5150 return ret;
5151 }
5152
5153 ev = tb[WMI_TAG_MGMT_RX_HDR];
5154 frame = tb[WMI_TAG_ARRAY_BYTE];
5155
5156 if (!ev || !frame) {
5157 ath11k_warn(ab, "failed to fetch mgmt rx hdr");
5158 kfree(tb);
5159 return -EPROTO;
5160 }
5161
5162 hdr->pdev_id = ev->pdev_id;
5163 hdr->chan_freq = ev->chan_freq;
5164 hdr->channel = ev->channel;
5165 hdr->snr = ev->snr;
5166 hdr->rate = ev->rate;
5167 hdr->phy_mode = ev->phy_mode;
5168 hdr->buf_len = ev->buf_len;
5169 hdr->status = ev->status;
5170 hdr->flags = ev->flags;
5171 hdr->rssi = ev->rssi;
5172 hdr->tsf_delta = ev->tsf_delta;
5173 memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl));
5174
5175 if (skb->len < (frame - skb->data) + hdr->buf_len) {
5176 ath11k_warn(ab, "invalid length in mgmt rx hdr ev");
5177 kfree(tb);
5178 return -EPROTO;
5179 }
5180
5181 /* shift the sk_buff to point to `frame` */
5182 skb_trim(skb, 0);
5183 skb_put(skb, frame - skb->data);
5184 skb_pull(skb, frame - skb->data);
5185 skb_put(skb, hdr->buf_len);
5186
5187 ath11k_ce_byte_swap(skb->data, hdr->buf_len);
5188
5189 kfree(tb);
5190 return 0;
5191 }
5192
wmi_process_mgmt_tx_comp(struct ath11k * ar,u32 desc_id,u32 status)5193 static int wmi_process_mgmt_tx_comp(struct ath11k *ar, u32 desc_id,
5194 u32 status)
5195 {
5196 struct sk_buff *msdu;
5197 struct ieee80211_tx_info *info;
5198 struct ath11k_skb_cb *skb_cb;
5199 int num_mgmt;
5200
5201 spin_lock_bh(&ar->txmgmt_idr_lock);
5202 msdu = idr_find(&ar->txmgmt_idr, desc_id);
5203
5204 if (!msdu) {
5205 ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n",
5206 desc_id);
5207 spin_unlock_bh(&ar->txmgmt_idr_lock);
5208 return -ENOENT;
5209 }
5210
5211 idr_remove(&ar->txmgmt_idr, desc_id);
5212 spin_unlock_bh(&ar->txmgmt_idr_lock);
5213
5214 skb_cb = ATH11K_SKB_CB(msdu);
5215 dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
5216
5217 info = IEEE80211_SKB_CB(msdu);
5218 if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) && !status)
5219 info->flags |= IEEE80211_TX_STAT_ACK;
5220
5221 ieee80211_tx_status_irqsafe(ar->hw, msdu);
5222
5223 num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5224
5225 /* WARN when we received this event without doing any mgmt tx */
5226 if (num_mgmt < 0)
5227 WARN_ON_ONCE(1);
5228
5229 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
5230 "wmi mgmt tx comp pending %d desc id %d\n",
5231 num_mgmt, desc_id);
5232
5233 if (!num_mgmt)
5234 wake_up(&ar->txmgmt_empty_waitq);
5235
5236 return 0;
5237 }
5238
ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_mgmt_tx_compl_event * param)5239 static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab,
5240 struct sk_buff *skb,
5241 struct wmi_mgmt_tx_compl_event *param)
5242 {
5243 const void **tb;
5244 const struct wmi_mgmt_tx_compl_event *ev;
5245 int ret;
5246
5247 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5248 if (IS_ERR(tb)) {
5249 ret = PTR_ERR(tb);
5250 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5251 return ret;
5252 }
5253
5254 ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT];
5255 if (!ev) {
5256 ath11k_warn(ab, "failed to fetch mgmt tx compl ev");
5257 kfree(tb);
5258 return -EPROTO;
5259 }
5260
5261 param->pdev_id = ev->pdev_id;
5262 param->desc_id = ev->desc_id;
5263 param->status = ev->status;
5264
5265 kfree(tb);
5266 return 0;
5267 }
5268
ath11k_wmi_event_scan_started(struct ath11k * ar)5269 static void ath11k_wmi_event_scan_started(struct ath11k *ar)
5270 {
5271 lockdep_assert_held(&ar->data_lock);
5272
5273 switch (ar->scan.state) {
5274 case ATH11K_SCAN_IDLE:
5275 case ATH11K_SCAN_RUNNING:
5276 case ATH11K_SCAN_ABORTING:
5277 ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n",
5278 ath11k_scan_state_str(ar->scan.state),
5279 ar->scan.state);
5280 break;
5281 case ATH11K_SCAN_STARTING:
5282 ar->scan.state = ATH11K_SCAN_RUNNING;
5283 if (ar->scan.is_roc)
5284 ieee80211_ready_on_channel(ar->hw);
5285 complete(&ar->scan.started);
5286 break;
5287 }
5288 }
5289
ath11k_wmi_event_scan_start_failed(struct ath11k * ar)5290 static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar)
5291 {
5292 lockdep_assert_held(&ar->data_lock);
5293
5294 switch (ar->scan.state) {
5295 case ATH11K_SCAN_IDLE:
5296 case ATH11K_SCAN_RUNNING:
5297 case ATH11K_SCAN_ABORTING:
5298 ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n",
5299 ath11k_scan_state_str(ar->scan.state),
5300 ar->scan.state);
5301 break;
5302 case ATH11K_SCAN_STARTING:
5303 complete(&ar->scan.started);
5304 __ath11k_mac_scan_finish(ar);
5305 break;
5306 }
5307 }
5308
ath11k_wmi_event_scan_completed(struct ath11k * ar)5309 static void ath11k_wmi_event_scan_completed(struct ath11k *ar)
5310 {
5311 lockdep_assert_held(&ar->data_lock);
5312
5313 switch (ar->scan.state) {
5314 case ATH11K_SCAN_IDLE:
5315 case ATH11K_SCAN_STARTING:
5316 /* One suspected reason scan can be completed while starting is
5317 * if firmware fails to deliver all scan events to the host,
5318 * e.g. when transport pipe is full. This has been observed
5319 * with spectral scan phyerr events starving wmi transport
5320 * pipe. In such case the "scan completed" event should be (and
5321 * is) ignored by the host as it may be just firmware's scan
5322 * state machine recovering.
5323 */
5324 ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n",
5325 ath11k_scan_state_str(ar->scan.state),
5326 ar->scan.state);
5327 break;
5328 case ATH11K_SCAN_RUNNING:
5329 case ATH11K_SCAN_ABORTING:
5330 __ath11k_mac_scan_finish(ar);
5331 break;
5332 }
5333 }
5334
ath11k_wmi_event_scan_bss_chan(struct ath11k * ar)5335 static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar)
5336 {
5337 lockdep_assert_held(&ar->data_lock);
5338
5339 switch (ar->scan.state) {
5340 case ATH11K_SCAN_IDLE:
5341 case ATH11K_SCAN_STARTING:
5342 ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n",
5343 ath11k_scan_state_str(ar->scan.state),
5344 ar->scan.state);
5345 break;
5346 case ATH11K_SCAN_RUNNING:
5347 case ATH11K_SCAN_ABORTING:
5348 ar->scan_channel = NULL;
5349 break;
5350 }
5351 }
5352
ath11k_wmi_event_scan_foreign_chan(struct ath11k * ar,u32 freq)5353 static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq)
5354 {
5355 lockdep_assert_held(&ar->data_lock);
5356
5357 switch (ar->scan.state) {
5358 case ATH11K_SCAN_IDLE:
5359 case ATH11K_SCAN_STARTING:
5360 ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
5361 ath11k_scan_state_str(ar->scan.state),
5362 ar->scan.state);
5363 break;
5364 case ATH11K_SCAN_RUNNING:
5365 case ATH11K_SCAN_ABORTING:
5366 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
5367 if (ar->scan.is_roc && ar->scan.roc_freq == freq)
5368 complete(&ar->scan.on_channel);
5369 break;
5370 }
5371 }
5372
5373 static const char *
ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,enum wmi_scan_completion_reason reason)5374 ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
5375 enum wmi_scan_completion_reason reason)
5376 {
5377 switch (type) {
5378 case WMI_SCAN_EVENT_STARTED:
5379 return "started";
5380 case WMI_SCAN_EVENT_COMPLETED:
5381 switch (reason) {
5382 case WMI_SCAN_REASON_COMPLETED:
5383 return "completed";
5384 case WMI_SCAN_REASON_CANCELLED:
5385 return "completed [cancelled]";
5386 case WMI_SCAN_REASON_PREEMPTED:
5387 return "completed [preempted]";
5388 case WMI_SCAN_REASON_TIMEDOUT:
5389 return "completed [timedout]";
5390 case WMI_SCAN_REASON_INTERNAL_FAILURE:
5391 return "completed [internal err]";
5392 case WMI_SCAN_REASON_MAX:
5393 break;
5394 }
5395 return "completed [unknown]";
5396 case WMI_SCAN_EVENT_BSS_CHANNEL:
5397 return "bss channel";
5398 case WMI_SCAN_EVENT_FOREIGN_CHAN:
5399 return "foreign channel";
5400 case WMI_SCAN_EVENT_DEQUEUED:
5401 return "dequeued";
5402 case WMI_SCAN_EVENT_PREEMPTED:
5403 return "preempted";
5404 case WMI_SCAN_EVENT_START_FAILED:
5405 return "start failed";
5406 case WMI_SCAN_EVENT_RESTARTED:
5407 return "restarted";
5408 case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
5409 return "foreign channel exit";
5410 default:
5411 return "unknown";
5412 }
5413 }
5414
ath11k_pull_scan_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_scan_event * scan_evt_param)5415 static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb,
5416 struct wmi_scan_event *scan_evt_param)
5417 {
5418 const void **tb;
5419 const struct wmi_scan_event *ev;
5420 int ret;
5421
5422 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5423 if (IS_ERR(tb)) {
5424 ret = PTR_ERR(tb);
5425 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5426 return ret;
5427 }
5428
5429 ev = tb[WMI_TAG_SCAN_EVENT];
5430 if (!ev) {
5431 ath11k_warn(ab, "failed to fetch scan ev");
5432 kfree(tb);
5433 return -EPROTO;
5434 }
5435
5436 scan_evt_param->event_type = ev->event_type;
5437 scan_evt_param->reason = ev->reason;
5438 scan_evt_param->channel_freq = ev->channel_freq;
5439 scan_evt_param->scan_req_id = ev->scan_req_id;
5440 scan_evt_param->scan_id = ev->scan_id;
5441 scan_evt_param->vdev_id = ev->vdev_id;
5442 scan_evt_param->tsf_timestamp = ev->tsf_timestamp;
5443
5444 kfree(tb);
5445 return 0;
5446 }
5447
ath11k_pull_peer_sta_kickout_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_peer_sta_kickout_arg * arg)5448 static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb,
5449 struct wmi_peer_sta_kickout_arg *arg)
5450 {
5451 const void **tb;
5452 const struct wmi_peer_sta_kickout_event *ev;
5453 int ret;
5454
5455 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5456 if (IS_ERR(tb)) {
5457 ret = PTR_ERR(tb);
5458 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5459 return ret;
5460 }
5461
5462 ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT];
5463 if (!ev) {
5464 ath11k_warn(ab, "failed to fetch peer sta kickout ev");
5465 kfree(tb);
5466 return -EPROTO;
5467 }
5468
5469 arg->mac_addr = ev->peer_macaddr.addr;
5470
5471 kfree(tb);
5472 return 0;
5473 }
5474
ath11k_pull_roam_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_roam_event * roam_ev)5475 static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb,
5476 struct wmi_roam_event *roam_ev)
5477 {
5478 const void **tb;
5479 const struct wmi_roam_event *ev;
5480 int ret;
5481
5482 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5483 if (IS_ERR(tb)) {
5484 ret = PTR_ERR(tb);
5485 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5486 return ret;
5487 }
5488
5489 ev = tb[WMI_TAG_ROAM_EVENT];
5490 if (!ev) {
5491 ath11k_warn(ab, "failed to fetch roam ev");
5492 kfree(tb);
5493 return -EPROTO;
5494 }
5495
5496 roam_ev->vdev_id = ev->vdev_id;
5497 roam_ev->reason = ev->reason;
5498 roam_ev->rssi = ev->rssi;
5499
5500 kfree(tb);
5501 return 0;
5502 }
5503
freq_to_idx(struct ath11k * ar,int freq)5504 static int freq_to_idx(struct ath11k *ar, int freq)
5505 {
5506 struct ieee80211_supported_band *sband;
5507 int band, ch, idx = 0;
5508
5509 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
5510 sband = ar->hw->wiphy->bands[band];
5511 if (!sband)
5512 continue;
5513
5514 for (ch = 0; ch < sband->n_channels; ch++, idx++)
5515 if (sband->channels[ch].center_freq == freq)
5516 goto exit;
5517 }
5518
5519 exit:
5520 return idx;
5521 }
5522
ath11k_pull_chan_info_ev(struct ath11k_base * ab,u8 * evt_buf,u32 len,struct wmi_chan_info_event * ch_info_ev)5523 static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf,
5524 u32 len, struct wmi_chan_info_event *ch_info_ev)
5525 {
5526 const void **tb;
5527 const struct wmi_chan_info_event *ev;
5528 int ret;
5529
5530 tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC);
5531 if (IS_ERR(tb)) {
5532 ret = PTR_ERR(tb);
5533 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5534 return ret;
5535 }
5536
5537 ev = tb[WMI_TAG_CHAN_INFO_EVENT];
5538 if (!ev) {
5539 ath11k_warn(ab, "failed to fetch chan info ev");
5540 kfree(tb);
5541 return -EPROTO;
5542 }
5543
5544 ch_info_ev->err_code = ev->err_code;
5545 ch_info_ev->freq = ev->freq;
5546 ch_info_ev->cmd_flags = ev->cmd_flags;
5547 ch_info_ev->noise_floor = ev->noise_floor;
5548 ch_info_ev->rx_clear_count = ev->rx_clear_count;
5549 ch_info_ev->cycle_count = ev->cycle_count;
5550 ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range;
5551 ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
5552 ch_info_ev->rx_frame_count = ev->rx_frame_count;
5553 ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt;
5554 ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz;
5555 ch_info_ev->vdev_id = ev->vdev_id;
5556
5557 kfree(tb);
5558 return 0;
5559 }
5560
5561 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)5562 ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb,
5563 struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev)
5564 {
5565 const void **tb;
5566 const struct wmi_pdev_bss_chan_info_event *ev;
5567 int ret;
5568
5569 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5570 if (IS_ERR(tb)) {
5571 ret = PTR_ERR(tb);
5572 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5573 return ret;
5574 }
5575
5576 ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT];
5577 if (!ev) {
5578 ath11k_warn(ab, "failed to fetch pdev bss chan info ev");
5579 kfree(tb);
5580 return -EPROTO;
5581 }
5582
5583 bss_ch_info_ev->pdev_id = ev->pdev_id;
5584 bss_ch_info_ev->freq = ev->freq;
5585 bss_ch_info_ev->noise_floor = ev->noise_floor;
5586 bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low;
5587 bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high;
5588 bss_ch_info_ev->cycle_count_low = ev->cycle_count_low;
5589 bss_ch_info_ev->cycle_count_high = ev->cycle_count_high;
5590 bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low;
5591 bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high;
5592 bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low;
5593 bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high;
5594 bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low;
5595 bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high;
5596
5597 kfree(tb);
5598 return 0;
5599 }
5600
5601 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)5602 ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb,
5603 struct wmi_vdev_install_key_complete_arg *arg)
5604 {
5605 const void **tb;
5606 const struct wmi_vdev_install_key_compl_event *ev;
5607 int ret;
5608
5609 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5610 if (IS_ERR(tb)) {
5611 ret = PTR_ERR(tb);
5612 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5613 return ret;
5614 }
5615
5616 ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT];
5617 if (!ev) {
5618 ath11k_warn(ab, "failed to fetch vdev install key compl ev");
5619 kfree(tb);
5620 return -EPROTO;
5621 }
5622
5623 arg->vdev_id = ev->vdev_id;
5624 arg->macaddr = ev->peer_macaddr.addr;
5625 arg->key_idx = ev->key_idx;
5626 arg->key_flags = ev->key_flags;
5627 arg->status = ev->status;
5628
5629 kfree(tb);
5630 return 0;
5631 }
5632
ath11k_pull_peer_assoc_conf_ev(struct ath11k_base * ab,struct sk_buff * skb,struct wmi_peer_assoc_conf_arg * peer_assoc_conf)5633 static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb,
5634 struct wmi_peer_assoc_conf_arg *peer_assoc_conf)
5635 {
5636 const void **tb;
5637 const struct wmi_peer_assoc_conf_event *ev;
5638 int ret;
5639
5640 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
5641 if (IS_ERR(tb)) {
5642 ret = PTR_ERR(tb);
5643 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
5644 return ret;
5645 }
5646
5647 ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT];
5648 if (!ev) {
5649 ath11k_warn(ab, "failed to fetch peer assoc conf ev");
5650 kfree(tb);
5651 return -EPROTO;
5652 }
5653
5654 peer_assoc_conf->vdev_id = ev->vdev_id;
5655 peer_assoc_conf->macaddr = ev->peer_macaddr.addr;
5656
5657 kfree(tb);
5658 return 0;
5659 }
5660
ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base * src,struct ath11k_fw_stats_pdev * dst)5661 static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
5662 struct ath11k_fw_stats_pdev *dst)
5663 {
5664 dst->ch_noise_floor = src->chan_nf;
5665 dst->tx_frame_count = src->tx_frame_count;
5666 dst->rx_frame_count = src->rx_frame_count;
5667 dst->rx_clear_count = src->rx_clear_count;
5668 dst->cycle_count = src->cycle_count;
5669 dst->phy_err_count = src->phy_err_count;
5670 dst->chan_tx_power = src->chan_tx_pwr;
5671 }
5672
5673 static void
ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx * src,struct ath11k_fw_stats_pdev * dst)5674 ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
5675 struct ath11k_fw_stats_pdev *dst)
5676 {
5677 dst->comp_queued = src->comp_queued;
5678 dst->comp_delivered = src->comp_delivered;
5679 dst->msdu_enqued = src->msdu_enqued;
5680 dst->mpdu_enqued = src->mpdu_enqued;
5681 dst->wmm_drop = src->wmm_drop;
5682 dst->local_enqued = src->local_enqued;
5683 dst->local_freed = src->local_freed;
5684 dst->hw_queued = src->hw_queued;
5685 dst->hw_reaped = src->hw_reaped;
5686 dst->underrun = src->underrun;
5687 dst->hw_paused = src->hw_paused;
5688 dst->tx_abort = src->tx_abort;
5689 dst->mpdus_requeued = src->mpdus_requeued;
5690 dst->tx_ko = src->tx_ko;
5691 dst->tx_xretry = src->tx_xretry;
5692 dst->data_rc = src->data_rc;
5693 dst->self_triggers = src->self_triggers;
5694 dst->sw_retry_failure = src->sw_retry_failure;
5695 dst->illgl_rate_phy_err = src->illgl_rate_phy_err;
5696 dst->pdev_cont_xretry = src->pdev_cont_xretry;
5697 dst->pdev_tx_timeout = src->pdev_tx_timeout;
5698 dst->pdev_resets = src->pdev_resets;
5699 dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure;
5700 dst->phy_underrun = src->phy_underrun;
5701 dst->txop_ovf = src->txop_ovf;
5702 dst->seq_posted = src->seq_posted;
5703 dst->seq_failed_queueing = src->seq_failed_queueing;
5704 dst->seq_completed = src->seq_completed;
5705 dst->seq_restarted = src->seq_restarted;
5706 dst->mu_seq_posted = src->mu_seq_posted;
5707 dst->mpdus_sw_flush = src->mpdus_sw_flush;
5708 dst->mpdus_hw_filter = src->mpdus_hw_filter;
5709 dst->mpdus_truncated = src->mpdus_truncated;
5710 dst->mpdus_ack_failed = src->mpdus_ack_failed;
5711 dst->mpdus_expired = src->mpdus_expired;
5712 }
5713
ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx * src,struct ath11k_fw_stats_pdev * dst)5714 static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
5715 struct ath11k_fw_stats_pdev *dst)
5716 {
5717 dst->mid_ppdu_route_change = src->mid_ppdu_route_change;
5718 dst->status_rcvd = src->status_rcvd;
5719 dst->r0_frags = src->r0_frags;
5720 dst->r1_frags = src->r1_frags;
5721 dst->r2_frags = src->r2_frags;
5722 dst->r3_frags = src->r3_frags;
5723 dst->htt_msdus = src->htt_msdus;
5724 dst->htt_mpdus = src->htt_mpdus;
5725 dst->loc_msdus = src->loc_msdus;
5726 dst->loc_mpdus = src->loc_mpdus;
5727 dst->oversize_amsdu = src->oversize_amsdu;
5728 dst->phy_errs = src->phy_errs;
5729 dst->phy_err_drop = src->phy_err_drop;
5730 dst->mpdu_errs = src->mpdu_errs;
5731 dst->rx_ovfl_errs = src->rx_ovfl_errs;
5732 }
5733
5734 static void
ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats * src,struct ath11k_fw_stats_vdev * dst)5735 ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src,
5736 struct ath11k_fw_stats_vdev *dst)
5737 {
5738 int i;
5739
5740 dst->vdev_id = src->vdev_id;
5741 dst->beacon_snr = src->beacon_snr;
5742 dst->data_snr = src->data_snr;
5743 dst->num_rx_frames = src->num_rx_frames;
5744 dst->num_rts_fail = src->num_rts_fail;
5745 dst->num_rts_success = src->num_rts_success;
5746 dst->num_rx_err = src->num_rx_err;
5747 dst->num_rx_discard = src->num_rx_discard;
5748 dst->num_tx_not_acked = src->num_tx_not_acked;
5749
5750 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++)
5751 dst->num_tx_frames[i] = src->num_tx_frames[i];
5752
5753 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++)
5754 dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i];
5755
5756 for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++)
5757 dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i];
5758
5759 for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++)
5760 dst->tx_rate_history[i] = src->tx_rate_history[i];
5761
5762 for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++)
5763 dst->beacon_rssi_history[i] = src->beacon_rssi_history[i];
5764 }
5765
5766 static void
ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats * src,struct ath11k_fw_stats_bcn * dst)5767 ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src,
5768 struct ath11k_fw_stats_bcn *dst)
5769 {
5770 dst->vdev_id = src->vdev_id;
5771 dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt;
5772 dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt;
5773 }
5774
ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)5775 static int ath11k_wmi_tlv_rssi_chain_parse(struct ath11k_base *ab,
5776 u16 tag, u16 len,
5777 const void *ptr, void *data)
5778 {
5779 struct wmi_tlv_fw_stats_parse *parse = data;
5780 const struct wmi_stats_event *ev = parse->ev;
5781 struct ath11k_fw_stats *stats = parse->stats;
5782 struct ath11k *ar;
5783 struct ath11k_vif *arvif;
5784 struct ieee80211_sta *sta;
5785 struct ath11k_sta *arsta;
5786 const struct wmi_rssi_stats *stats_rssi = (const struct wmi_rssi_stats *)ptr;
5787 int j, ret = 0;
5788
5789 if (tag != WMI_TAG_RSSI_STATS)
5790 return -EPROTO;
5791
5792 rcu_read_lock();
5793
5794 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5795 stats->stats_id = WMI_REQUEST_RSSI_PER_CHAIN_STAT;
5796
5797 ath11k_dbg(ab, ATH11K_DBG_WMI,
5798 "wmi stats vdev id %d mac %pM\n",
5799 stats_rssi->vdev_id, stats_rssi->peer_macaddr.addr);
5800
5801 arvif = ath11k_mac_get_arvif(ar, stats_rssi->vdev_id);
5802 if (!arvif) {
5803 ath11k_warn(ab, "not found vif for vdev id %d\n",
5804 stats_rssi->vdev_id);
5805 ret = -EPROTO;
5806 goto exit;
5807 }
5808
5809 ath11k_dbg(ab, ATH11K_DBG_WMI,
5810 "wmi stats bssid %pM vif %pK\n",
5811 arvif->bssid, arvif->vif);
5812
5813 sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5814 arvif->bssid,
5815 NULL);
5816 if (!sta) {
5817 ath11k_dbg(ab, ATH11K_DBG_WMI,
5818 "not found station of bssid %pM for rssi chain\n",
5819 arvif->bssid);
5820 goto exit;
5821 }
5822
5823 arsta = (struct ath11k_sta *)sta->drv_priv;
5824
5825 BUILD_BUG_ON(ARRAY_SIZE(arsta->chain_signal) >
5826 ARRAY_SIZE(stats_rssi->rssi_avg_beacon));
5827
5828 for (j = 0; j < ARRAY_SIZE(arsta->chain_signal); j++) {
5829 arsta->chain_signal[j] = stats_rssi->rssi_avg_beacon[j];
5830 ath11k_dbg(ab, ATH11K_DBG_WMI,
5831 "wmi stats beacon rssi[%d] %d data rssi[%d] %d\n",
5832 j,
5833 stats_rssi->rssi_avg_beacon[j],
5834 j,
5835 stats_rssi->rssi_avg_data[j]);
5836 }
5837
5838 exit:
5839 rcu_read_unlock();
5840 return ret;
5841 }
5842
ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base * ab,struct wmi_tlv_fw_stats_parse * parse,const void * ptr,u16 len)5843 static int ath11k_wmi_tlv_fw_stats_data_parse(struct ath11k_base *ab,
5844 struct wmi_tlv_fw_stats_parse *parse,
5845 const void *ptr,
5846 u16 len)
5847 {
5848 struct ath11k_fw_stats *stats = parse->stats;
5849 const struct wmi_stats_event *ev = parse->ev;
5850 struct ath11k *ar;
5851 struct ath11k_vif *arvif;
5852 struct ieee80211_sta *sta;
5853 struct ath11k_sta *arsta;
5854 int i, ret = 0;
5855 const void *data = ptr;
5856
5857 if (!ev) {
5858 ath11k_warn(ab, "failed to fetch update stats ev");
5859 return -EPROTO;
5860 }
5861
5862 stats->stats_id = 0;
5863
5864 rcu_read_lock();
5865
5866 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
5867
5868 for (i = 0; i < ev->num_pdev_stats; i++) {
5869 const struct wmi_pdev_stats *src;
5870 struct ath11k_fw_stats_pdev *dst;
5871
5872 src = data;
5873 if (len < sizeof(*src)) {
5874 ret = -EPROTO;
5875 goto exit;
5876 }
5877
5878 stats->stats_id = WMI_REQUEST_PDEV_STAT;
5879
5880 data += sizeof(*src);
5881 len -= sizeof(*src);
5882
5883 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5884 if (!dst)
5885 continue;
5886
5887 ath11k_wmi_pull_pdev_stats_base(&src->base, dst);
5888 ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst);
5889 ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst);
5890 list_add_tail(&dst->list, &stats->pdevs);
5891 }
5892
5893 for (i = 0; i < ev->num_vdev_stats; i++) {
5894 const struct wmi_vdev_stats *src;
5895 struct ath11k_fw_stats_vdev *dst;
5896
5897 src = data;
5898 if (len < sizeof(*src)) {
5899 ret = -EPROTO;
5900 goto exit;
5901 }
5902
5903 stats->stats_id = WMI_REQUEST_VDEV_STAT;
5904
5905 arvif = ath11k_mac_get_arvif(ar, src->vdev_id);
5906 if (arvif) {
5907 sta = ieee80211_find_sta_by_ifaddr(ar->hw,
5908 arvif->bssid,
5909 NULL);
5910 if (sta) {
5911 arsta = (struct ath11k_sta *)sta->drv_priv;
5912 arsta->rssi_beacon = src->beacon_snr;
5913 ath11k_dbg(ab, ATH11K_DBG_WMI,
5914 "wmi stats vdev id %d snr %d\n",
5915 src->vdev_id, src->beacon_snr);
5916 } else {
5917 ath11k_dbg(ab, ATH11K_DBG_WMI,
5918 "not found station of bssid %pM for vdev stat\n",
5919 arvif->bssid);
5920 }
5921 }
5922
5923 data += sizeof(*src);
5924 len -= sizeof(*src);
5925
5926 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5927 if (!dst)
5928 continue;
5929
5930 ath11k_wmi_pull_vdev_stats(src, dst);
5931 list_add_tail(&dst->list, &stats->vdevs);
5932 }
5933
5934 for (i = 0; i < ev->num_bcn_stats; i++) {
5935 const struct wmi_bcn_stats *src;
5936 struct ath11k_fw_stats_bcn *dst;
5937
5938 src = data;
5939 if (len < sizeof(*src)) {
5940 ret = -EPROTO;
5941 goto exit;
5942 }
5943
5944 stats->stats_id = WMI_REQUEST_BCN_STAT;
5945
5946 data += sizeof(*src);
5947 len -= sizeof(*src);
5948
5949 dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
5950 if (!dst)
5951 continue;
5952
5953 ath11k_wmi_pull_bcn_stats(src, dst);
5954 list_add_tail(&dst->list, &stats->bcn);
5955 }
5956
5957 exit:
5958 rcu_read_unlock();
5959 return ret;
5960 }
5961
ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)5962 static int ath11k_wmi_tlv_fw_stats_parse(struct ath11k_base *ab,
5963 u16 tag, u16 len,
5964 const void *ptr, void *data)
5965 {
5966 struct wmi_tlv_fw_stats_parse *parse = data;
5967 int ret = 0;
5968
5969 switch (tag) {
5970 case WMI_TAG_STATS_EVENT:
5971 parse->ev = (struct wmi_stats_event *)ptr;
5972 parse->stats->pdev_id = parse->ev->pdev_id;
5973 break;
5974 case WMI_TAG_ARRAY_BYTE:
5975 ret = ath11k_wmi_tlv_fw_stats_data_parse(ab, parse, ptr, len);
5976 break;
5977 case WMI_TAG_PER_CHAIN_RSSI_STATS:
5978 parse->rssi = (struct wmi_per_chain_rssi_stats *)ptr;
5979
5980 if (parse->ev->stats_id & WMI_REQUEST_RSSI_PER_CHAIN_STAT)
5981 parse->rssi_num = parse->rssi->num_per_chain_rssi_stats;
5982
5983 ath11k_dbg(ab, ATH11K_DBG_WMI,
5984 "wmi stats id 0x%x num chain %d\n",
5985 parse->ev->stats_id,
5986 parse->rssi_num);
5987 break;
5988 case WMI_TAG_ARRAY_STRUCT:
5989 if (parse->rssi_num && !parse->chain_rssi_done) {
5990 ret = ath11k_wmi_tlv_iter(ab, ptr, len,
5991 ath11k_wmi_tlv_rssi_chain_parse,
5992 parse);
5993 if (ret) {
5994 ath11k_warn(ab, "failed to parse rssi chain %d\n",
5995 ret);
5996 return ret;
5997 }
5998 parse->chain_rssi_done = true;
5999 }
6000 break;
6001 default:
6002 break;
6003 }
6004 return ret;
6005 }
6006
ath11k_wmi_pull_fw_stats(struct ath11k_base * ab,struct sk_buff * skb,struct ath11k_fw_stats * stats)6007 int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb,
6008 struct ath11k_fw_stats *stats)
6009 {
6010 struct wmi_tlv_fw_stats_parse parse = { };
6011
6012 stats->stats_id = 0;
6013 parse.stats = stats;
6014
6015 return ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6016 ath11k_wmi_tlv_fw_stats_parse,
6017 &parse);
6018 }
6019
ath11k_wmi_fw_stats_num_vdevs(struct list_head * head)6020 size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head)
6021 {
6022 struct ath11k_fw_stats_vdev *i;
6023 size_t num = 0;
6024
6025 list_for_each_entry(i, head, list)
6026 ++num;
6027
6028 return num;
6029 }
6030
ath11k_wmi_fw_stats_num_bcn(struct list_head * head)6031 static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head)
6032 {
6033 struct ath11k_fw_stats_bcn *i;
6034 size_t num = 0;
6035
6036 list_for_each_entry(i, head, list)
6037 ++num;
6038
6039 return num;
6040 }
6041
6042 static void
ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev * pdev,char * buf,u32 * length)6043 ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6044 char *buf, u32 *length)
6045 {
6046 u32 len = *length;
6047 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6048
6049 len += scnprintf(buf + len, buf_len - len, "\n");
6050 len += scnprintf(buf + len, buf_len - len, "%30s\n",
6051 "ath11k PDEV stats");
6052 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6053 "=================");
6054
6055 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6056 "Channel noise floor", pdev->ch_noise_floor);
6057 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6058 "Channel TX power", pdev->chan_tx_power);
6059 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6060 "TX frame count", pdev->tx_frame_count);
6061 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6062 "RX frame count", pdev->rx_frame_count);
6063 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6064 "RX clear count", pdev->rx_clear_count);
6065 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6066 "Cycle count", pdev->cycle_count);
6067 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6068 "PHY error count", pdev->phy_err_count);
6069
6070 *length = len;
6071 }
6072
6073 static void
ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev * pdev,char * buf,u32 * length)6074 ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6075 char *buf, u32 *length)
6076 {
6077 u32 len = *length;
6078 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6079
6080 len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6081 "ath11k PDEV TX stats");
6082 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6083 "====================");
6084
6085 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6086 "HTT cookies queued", pdev->comp_queued);
6087 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6088 "HTT cookies disp.", pdev->comp_delivered);
6089 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6090 "MSDU queued", pdev->msdu_enqued);
6091 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6092 "MPDU queued", pdev->mpdu_enqued);
6093 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6094 "MSDUs dropped", pdev->wmm_drop);
6095 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6096 "Local enqued", pdev->local_enqued);
6097 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6098 "Local freed", pdev->local_freed);
6099 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6100 "HW queued", pdev->hw_queued);
6101 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6102 "PPDUs reaped", pdev->hw_reaped);
6103 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6104 "Num underruns", pdev->underrun);
6105 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6106 "Num HW Paused", pdev->hw_paused);
6107 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6108 "PPDUs cleaned", pdev->tx_abort);
6109 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6110 "MPDUs requeued", pdev->mpdus_requeued);
6111 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6112 "PPDU OK", pdev->tx_ko);
6113 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6114 "Excessive retries", pdev->tx_xretry);
6115 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6116 "HW rate", pdev->data_rc);
6117 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6118 "Sched self triggers", pdev->self_triggers);
6119 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6120 "Dropped due to SW retries",
6121 pdev->sw_retry_failure);
6122 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6123 "Illegal rate phy errors",
6124 pdev->illgl_rate_phy_err);
6125 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6126 "PDEV continuous xretry", pdev->pdev_cont_xretry);
6127 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6128 "TX timeout", pdev->pdev_tx_timeout);
6129 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6130 "PDEV resets", pdev->pdev_resets);
6131 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6132 "Stateless TIDs alloc failures",
6133 pdev->stateless_tid_alloc_failure);
6134 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6135 "PHY underrun", pdev->phy_underrun);
6136 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6137 "MPDU is more than txop limit", pdev->txop_ovf);
6138 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6139 "Num sequences posted", pdev->seq_posted);
6140 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6141 "Num seq failed queueing ", pdev->seq_failed_queueing);
6142 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6143 "Num sequences completed ", pdev->seq_completed);
6144 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6145 "Num sequences restarted ", pdev->seq_restarted);
6146 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6147 "Num of MU sequences posted ", pdev->mu_seq_posted);
6148 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6149 "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush);
6150 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6151 "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter);
6152 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6153 "Num of MPDUS truncated ", pdev->mpdus_truncated);
6154 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6155 "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed);
6156 len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
6157 "Num of MPDUS expired ", pdev->mpdus_expired);
6158 *length = len;
6159 }
6160
6161 static void
ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev * pdev,char * buf,u32 * length)6162 ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev,
6163 char *buf, u32 *length)
6164 {
6165 u32 len = *length;
6166 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6167
6168 len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
6169 "ath11k PDEV RX stats");
6170 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6171 "====================");
6172
6173 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6174 "Mid PPDU route change",
6175 pdev->mid_ppdu_route_change);
6176 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6177 "Tot. number of statuses", pdev->status_rcvd);
6178 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6179 "Extra frags on rings 0", pdev->r0_frags);
6180 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6181 "Extra frags on rings 1", pdev->r1_frags);
6182 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6183 "Extra frags on rings 2", pdev->r2_frags);
6184 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6185 "Extra frags on rings 3", pdev->r3_frags);
6186 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6187 "MSDUs delivered to HTT", pdev->htt_msdus);
6188 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6189 "MPDUs delivered to HTT", pdev->htt_mpdus);
6190 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6191 "MSDUs delivered to stack", pdev->loc_msdus);
6192 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6193 "MPDUs delivered to stack", pdev->loc_mpdus);
6194 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6195 "Oversized AMSUs", pdev->oversize_amsdu);
6196 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6197 "PHY errors", pdev->phy_errs);
6198 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6199 "PHY errors drops", pdev->phy_err_drop);
6200 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6201 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
6202 len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
6203 "Overflow errors", pdev->rx_ovfl_errs);
6204 *length = len;
6205 }
6206
6207 static void
ath11k_wmi_fw_vdev_stats_fill(struct ath11k * ar,const struct ath11k_fw_stats_vdev * vdev,char * buf,u32 * length)6208 ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar,
6209 const struct ath11k_fw_stats_vdev *vdev,
6210 char *buf, u32 *length)
6211 {
6212 u32 len = *length;
6213 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6214 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id);
6215 u8 *vif_macaddr;
6216 int i;
6217
6218 /* VDEV stats has all the active VDEVs of other PDEVs as well,
6219 * ignoring those not part of requested PDEV
6220 */
6221 if (!arvif)
6222 return;
6223
6224 vif_macaddr = arvif->vif->addr;
6225
6226 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6227 "VDEV ID", vdev->vdev_id);
6228 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6229 "VDEV MAC address", vif_macaddr);
6230 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6231 "beacon snr", vdev->beacon_snr);
6232 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6233 "data snr", vdev->data_snr);
6234 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6235 "num rx frames", vdev->num_rx_frames);
6236 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6237 "num rts fail", vdev->num_rts_fail);
6238 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6239 "num rts success", vdev->num_rts_success);
6240 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6241 "num rx err", vdev->num_rx_err);
6242 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6243 "num rx discard", vdev->num_rx_discard);
6244 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6245 "num tx not acked", vdev->num_tx_not_acked);
6246
6247 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
6248 len += scnprintf(buf + len, buf_len - len,
6249 "%25s [%02d] %u\n",
6250 "num tx frames", i,
6251 vdev->num_tx_frames[i]);
6252
6253 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
6254 len += scnprintf(buf + len, buf_len - len,
6255 "%25s [%02d] %u\n",
6256 "num tx frames retries", i,
6257 vdev->num_tx_frames_retries[i]);
6258
6259 for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
6260 len += scnprintf(buf + len, buf_len - len,
6261 "%25s [%02d] %u\n",
6262 "num tx frames failures", i,
6263 vdev->num_tx_frames_failures[i]);
6264
6265 for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
6266 len += scnprintf(buf + len, buf_len - len,
6267 "%25s [%02d] 0x%08x\n",
6268 "tx rate history", i,
6269 vdev->tx_rate_history[i]);
6270
6271 for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
6272 len += scnprintf(buf + len, buf_len - len,
6273 "%25s [%02d] %u\n",
6274 "beacon rssi history", i,
6275 vdev->beacon_rssi_history[i]);
6276
6277 len += scnprintf(buf + len, buf_len - len, "\n");
6278 *length = len;
6279 }
6280
6281 static void
ath11k_wmi_fw_bcn_stats_fill(struct ath11k * ar,const struct ath11k_fw_stats_bcn * bcn,char * buf,u32 * length)6282 ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar,
6283 const struct ath11k_fw_stats_bcn *bcn,
6284 char *buf, u32 *length)
6285 {
6286 u32 len = *length;
6287 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6288 struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id);
6289 u8 *vdev_macaddr;
6290
6291 if (!arvif) {
6292 ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats",
6293 bcn->vdev_id);
6294 return;
6295 }
6296
6297 vdev_macaddr = arvif->vif->addr;
6298
6299 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6300 "VDEV ID", bcn->vdev_id);
6301 len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
6302 "VDEV MAC address", vdev_macaddr);
6303 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6304 "================");
6305 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6306 "Num of beacon tx success", bcn->tx_bcn_succ_cnt);
6307 len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
6308 "Num of beacon tx failures", bcn->tx_bcn_outage_cnt);
6309
6310 len += scnprintf(buf + len, buf_len - len, "\n");
6311 *length = len;
6312 }
6313
ath11k_wmi_fw_stats_fill(struct ath11k * ar,struct ath11k_fw_stats * fw_stats,u32 stats_id,char * buf)6314 void ath11k_wmi_fw_stats_fill(struct ath11k *ar,
6315 struct ath11k_fw_stats *fw_stats,
6316 u32 stats_id, char *buf)
6317 {
6318 u32 len = 0;
6319 u32 buf_len = ATH11K_FW_STATS_BUF_SIZE;
6320 const struct ath11k_fw_stats_pdev *pdev;
6321 const struct ath11k_fw_stats_vdev *vdev;
6322 const struct ath11k_fw_stats_bcn *bcn;
6323 size_t num_bcn;
6324
6325 spin_lock_bh(&ar->data_lock);
6326
6327 if (stats_id == WMI_REQUEST_PDEV_STAT) {
6328 pdev = list_first_entry_or_null(&fw_stats->pdevs,
6329 struct ath11k_fw_stats_pdev, list);
6330 if (!pdev) {
6331 ath11k_warn(ar->ab, "failed to get pdev stats\n");
6332 goto unlock;
6333 }
6334
6335 ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
6336 ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
6337 ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
6338 }
6339
6340 if (stats_id == WMI_REQUEST_VDEV_STAT) {
6341 len += scnprintf(buf + len, buf_len - len, "\n");
6342 len += scnprintf(buf + len, buf_len - len, "%30s\n",
6343 "ath11k VDEV stats");
6344 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6345 "=================");
6346
6347 list_for_each_entry(vdev, &fw_stats->vdevs, list)
6348 ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len);
6349 }
6350
6351 if (stats_id == WMI_REQUEST_BCN_STAT) {
6352 num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn);
6353
6354 len += scnprintf(buf + len, buf_len - len, "\n");
6355 len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
6356 "ath11k Beacon stats", num_bcn);
6357 len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
6358 "===================");
6359
6360 list_for_each_entry(bcn, &fw_stats->bcn, list)
6361 ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len);
6362 }
6363
6364 unlock:
6365 spin_unlock_bh(&ar->data_lock);
6366
6367 if (len >= buf_len)
6368 buf[len - 1] = 0;
6369 else
6370 buf[len] = 0;
6371 }
6372
ath11k_wmi_op_ep_tx_credits(struct ath11k_base * ab)6373 static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab)
6374 {
6375 /* try to send pending beacons first. they take priority */
6376 wake_up(&ab->wmi_ab.tx_credits_wq);
6377 }
6378
ath11k_reg_11d_new_cc_event(struct ath11k_base * ab,struct sk_buff * skb)6379 static int ath11k_reg_11d_new_cc_event(struct ath11k_base *ab, struct sk_buff *skb)
6380 {
6381 const struct wmi_11d_new_cc_ev *ev;
6382 struct ath11k *ar;
6383 struct ath11k_pdev *pdev;
6384 const void **tb;
6385 int ret, i;
6386
6387 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
6388 if (IS_ERR(tb)) {
6389 ret = PTR_ERR(tb);
6390 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
6391 return ret;
6392 }
6393
6394 ev = tb[WMI_TAG_11D_NEW_COUNTRY_EVENT];
6395 if (!ev) {
6396 kfree(tb);
6397 ath11k_warn(ab, "failed to fetch 11d new cc ev");
6398 return -EPROTO;
6399 }
6400
6401 spin_lock_bh(&ab->base_lock);
6402 memcpy(&ab->new_alpha2, &ev->new_alpha2, 2);
6403 spin_unlock_bh(&ab->base_lock);
6404
6405 ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi 11d new cc %c%c\n",
6406 ab->new_alpha2[0],
6407 ab->new_alpha2[1]);
6408
6409 kfree(tb);
6410
6411 for (i = 0; i < ab->num_radios; i++) {
6412 pdev = &ab->pdevs[i];
6413 ar = pdev->ar;
6414 ar->state_11d = ATH11K_11D_IDLE;
6415 complete(&ar->completed_11d_scan);
6416 }
6417
6418 queue_work(ab->workqueue, &ab->update_11d_work);
6419
6420 return 0;
6421 }
6422
ath11k_wmi_htc_tx_complete(struct ath11k_base * ab,struct sk_buff * skb)6423 static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab,
6424 struct sk_buff *skb)
6425 {
6426 struct ath11k_pdev_wmi *wmi = NULL;
6427 u32 i;
6428 u8 wmi_ep_count;
6429 u8 eid;
6430
6431 eid = ATH11K_SKB_CB(skb)->eid;
6432 dev_kfree_skb(skb);
6433
6434 if (eid >= ATH11K_HTC_EP_COUNT)
6435 return;
6436
6437 wmi_ep_count = ab->htc.wmi_ep_count;
6438 if (wmi_ep_count > ab->hw_params.max_radios)
6439 return;
6440
6441 for (i = 0; i < ab->htc.wmi_ep_count; i++) {
6442 if (ab->wmi_ab.wmi[i].eid == eid) {
6443 wmi = &ab->wmi_ab.wmi[i];
6444 break;
6445 }
6446 }
6447
6448 if (wmi)
6449 wake_up(&wmi->tx_ce_desc_wq);
6450 }
6451
ath11k_reg_is_world_alpha(char * alpha)6452 static bool ath11k_reg_is_world_alpha(char *alpha)
6453 {
6454 if (alpha[0] == '0' && alpha[1] == '0')
6455 return true;
6456
6457 if (alpha[0] == 'n' && alpha[1] == 'a')
6458 return true;
6459
6460 return false;
6461 }
6462
ath11k_reg_chan_list_event(struct ath11k_base * ab,struct sk_buff * skb)6463 static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb)
6464 {
6465 struct cur_regulatory_info *reg_info = NULL;
6466 struct ieee80211_regdomain *regd = NULL;
6467 bool intersect = false;
6468 int ret = 0, pdev_idx;
6469 struct ath11k *ar;
6470
6471 reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC);
6472 if (!reg_info) {
6473 ret = -ENOMEM;
6474 goto fallback;
6475 }
6476
6477 ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info);
6478 if (ret) {
6479 ath11k_warn(ab, "failed to extract regulatory info from received event\n");
6480 goto fallback;
6481 }
6482
6483 if (reg_info->status_code != REG_SET_CC_STATUS_PASS) {
6484 /* In case of failure to set the requested ctry,
6485 * fw retains the current regd. We print a failure info
6486 * and return from here.
6487 */
6488 ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n");
6489 goto mem_free;
6490 }
6491
6492 pdev_idx = reg_info->phy_id;
6493
6494 /* Avoid default reg rule updates sent during FW recovery if
6495 * it is already available
6496 */
6497 spin_lock(&ab->base_lock);
6498 if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) &&
6499 ab->default_regd[pdev_idx]) {
6500 spin_unlock(&ab->base_lock);
6501 goto mem_free;
6502 }
6503 spin_unlock(&ab->base_lock);
6504
6505 if (pdev_idx >= ab->num_radios) {
6506 /* Process the event for phy0 only if single_pdev_only
6507 * is true. If pdev_idx is valid but not 0, discard the
6508 * event. Otherwise, it goes to fallback.
6509 */
6510 if (ab->hw_params.single_pdev_only &&
6511 pdev_idx < ab->hw_params.num_rxmda_per_pdev)
6512 goto mem_free;
6513 else
6514 goto fallback;
6515 }
6516
6517 /* Avoid multiple overwrites to default regd, during core
6518 * stop-start after mac registration.
6519 */
6520 if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] &&
6521 !memcmp((char *)ab->default_regd[pdev_idx]->alpha2,
6522 (char *)reg_info->alpha2, 2))
6523 goto mem_free;
6524
6525 /* Intersect new rules with default regd if a new country setting was
6526 * requested, i.e a default regd was already set during initialization
6527 * and the regd coming from this event has a valid country info.
6528 */
6529 if (ab->default_regd[pdev_idx] &&
6530 !ath11k_reg_is_world_alpha((char *)
6531 ab->default_regd[pdev_idx]->alpha2) &&
6532 !ath11k_reg_is_world_alpha((char *)reg_info->alpha2))
6533 intersect = true;
6534
6535 regd = ath11k_reg_build_regd(ab, reg_info, intersect);
6536 if (!regd) {
6537 ath11k_warn(ab, "failed to build regd from reg_info\n");
6538 goto fallback;
6539 }
6540
6541 spin_lock(&ab->base_lock);
6542 if (ab->default_regd[pdev_idx]) {
6543 /* The initial rules from FW after WMI Init is to build
6544 * the default regd. From then on, any rules updated for
6545 * the pdev could be due to user reg changes.
6546 * Free previously built regd before assigning the newly
6547 * generated regd to ar. NULL pointer handling will be
6548 * taken care by kfree itself.
6549 */
6550 ar = ab->pdevs[pdev_idx].ar;
6551 kfree(ab->new_regd[pdev_idx]);
6552 ab->new_regd[pdev_idx] = regd;
6553 queue_work(ab->workqueue, &ar->regd_update_work);
6554 } else {
6555 /* This regd would be applied during mac registration and is
6556 * held constant throughout for regd intersection purpose
6557 */
6558 ab->default_regd[pdev_idx] = regd;
6559 }
6560 ab->dfs_region = reg_info->dfs_region;
6561 spin_unlock(&ab->base_lock);
6562
6563 goto mem_free;
6564
6565 fallback:
6566 /* Fallback to older reg (by sending previous country setting
6567 * again if fw has succeded and we failed to process here.
6568 * The Regdomain should be uniform across driver and fw. Since the
6569 * FW has processed the command and sent a success status, we expect
6570 * this function to succeed as well. If it doesn't, CTRY needs to be
6571 * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent.
6572 */
6573 /* TODO: This is rare, but still should also be handled */
6574 WARN_ON(1);
6575 mem_free:
6576 if (reg_info) {
6577 kfree(reg_info->reg_rules_2g_ptr);
6578 kfree(reg_info->reg_rules_5g_ptr);
6579 kfree(reg_info);
6580 }
6581 return ret;
6582 }
6583
ath11k_wmi_tlv_rdy_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)6584 static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len,
6585 const void *ptr, void *data)
6586 {
6587 struct wmi_tlv_rdy_parse *rdy_parse = data;
6588 struct wmi_ready_event fixed_param;
6589 struct wmi_mac_addr *addr_list;
6590 struct ath11k_pdev *pdev;
6591 u32 num_mac_addr;
6592 int i;
6593
6594 switch (tag) {
6595 case WMI_TAG_READY_EVENT:
6596 memset(&fixed_param, 0, sizeof(fixed_param));
6597 memcpy(&fixed_param, (struct wmi_ready_event *)ptr,
6598 min_t(u16, sizeof(fixed_param), len));
6599 ab->wlan_init_status = fixed_param.ready_event_min.status;
6600 rdy_parse->num_extra_mac_addr =
6601 fixed_param.ready_event_min.num_extra_mac_addr;
6602
6603 ether_addr_copy(ab->mac_addr,
6604 fixed_param.ready_event_min.mac_addr.addr);
6605 ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum;
6606 ab->wmi_ready = true;
6607 break;
6608 case WMI_TAG_ARRAY_FIXED_STRUCT:
6609 addr_list = (struct wmi_mac_addr *)ptr;
6610 num_mac_addr = rdy_parse->num_extra_mac_addr;
6611
6612 if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios))
6613 break;
6614
6615 for (i = 0; i < ab->num_radios; i++) {
6616 pdev = &ab->pdevs[i];
6617 ether_addr_copy(pdev->mac_addr, addr_list[i].addr);
6618 }
6619 ab->pdevs_macaddr_valid = true;
6620 break;
6621 default:
6622 break;
6623 }
6624
6625 return 0;
6626 }
6627
ath11k_ready_event(struct ath11k_base * ab,struct sk_buff * skb)6628 static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb)
6629 {
6630 struct wmi_tlv_rdy_parse rdy_parse = { };
6631 int ret;
6632
6633 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
6634 ath11k_wmi_tlv_rdy_parse, &rdy_parse);
6635 if (ret) {
6636 ath11k_warn(ab, "failed to parse tlv %d\n", ret);
6637 return ret;
6638 }
6639
6640 complete(&ab->wmi_ab.unified_ready);
6641 return 0;
6642 }
6643
ath11k_peer_delete_resp_event(struct ath11k_base * ab,struct sk_buff * skb)6644 static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
6645 {
6646 struct wmi_peer_delete_resp_event peer_del_resp;
6647 struct ath11k *ar;
6648
6649 if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) {
6650 ath11k_warn(ab, "failed to extract peer delete resp");
6651 return;
6652 }
6653
6654 rcu_read_lock();
6655 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id);
6656 if (!ar) {
6657 ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d",
6658 peer_del_resp.vdev_id);
6659 rcu_read_unlock();
6660 return;
6661 }
6662
6663 complete(&ar->peer_delete_done);
6664 rcu_read_unlock();
6665 ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n",
6666 peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr);
6667 }
6668
ath11k_vdev_delete_resp_event(struct ath11k_base * ab,struct sk_buff * skb)6669 static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab,
6670 struct sk_buff *skb)
6671 {
6672 struct ath11k *ar;
6673 u32 vdev_id = 0;
6674
6675 if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) {
6676 ath11k_warn(ab, "failed to extract vdev delete resp");
6677 return;
6678 }
6679
6680 rcu_read_lock();
6681 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
6682 if (!ar) {
6683 ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d",
6684 vdev_id);
6685 rcu_read_unlock();
6686 return;
6687 }
6688
6689 complete(&ar->vdev_delete_done);
6690
6691 rcu_read_unlock();
6692
6693 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev delete resp for vdev id %d\n",
6694 vdev_id);
6695 }
6696
ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)6697 static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status)
6698 {
6699 switch (vdev_resp_status) {
6700 case WMI_VDEV_START_RESPONSE_INVALID_VDEVID:
6701 return "invalid vdev id";
6702 case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED:
6703 return "not supported";
6704 case WMI_VDEV_START_RESPONSE_DFS_VIOLATION:
6705 return "dfs violation";
6706 case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN:
6707 return "invalid regdomain";
6708 default:
6709 return "unknown";
6710 }
6711 }
6712
ath11k_vdev_start_resp_event(struct ath11k_base * ab,struct sk_buff * skb)6713 static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb)
6714 {
6715 struct wmi_vdev_start_resp_event vdev_start_resp;
6716 struct ath11k *ar;
6717 u32 status;
6718
6719 if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) {
6720 ath11k_warn(ab, "failed to extract vdev start resp");
6721 return;
6722 }
6723
6724 rcu_read_lock();
6725 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id);
6726 if (!ar) {
6727 ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d",
6728 vdev_start_resp.vdev_id);
6729 rcu_read_unlock();
6730 return;
6731 }
6732
6733 ar->last_wmi_vdev_start_status = 0;
6734
6735 status = vdev_start_resp.status;
6736
6737 if (WARN_ON_ONCE(status)) {
6738 ath11k_warn(ab, "vdev start resp error status %d (%s)\n",
6739 status, ath11k_wmi_vdev_resp_print(status));
6740 ar->last_wmi_vdev_start_status = status;
6741 }
6742
6743 complete(&ar->vdev_setup_done);
6744
6745 rcu_read_unlock();
6746
6747 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d",
6748 vdev_start_resp.vdev_id);
6749 }
6750
ath11k_bcn_tx_status_event(struct ath11k_base * ab,struct sk_buff * skb)6751 static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb)
6752 {
6753 struct ath11k_vif *arvif;
6754 u32 vdev_id, tx_status;
6755
6756 if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len,
6757 &vdev_id, &tx_status) != 0) {
6758 ath11k_warn(ab, "failed to extract bcn tx status");
6759 return;
6760 }
6761
6762 rcu_read_lock();
6763 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_id);
6764 if (!arvif) {
6765 ath11k_warn(ab, "invalid vdev id %d in bcn_tx_status",
6766 vdev_id);
6767 rcu_read_unlock();
6768 return;
6769 }
6770 ath11k_mac_bcn_tx_event(arvif);
6771 rcu_read_unlock();
6772 }
6773
ath11k_vdev_stopped_event(struct ath11k_base * ab,struct sk_buff * skb)6774 static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb)
6775 {
6776 struct ath11k *ar;
6777 u32 vdev_id = 0;
6778
6779 if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) {
6780 ath11k_warn(ab, "failed to extract vdev stopped event");
6781 return;
6782 }
6783
6784 rcu_read_lock();
6785 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
6786 if (!ar) {
6787 ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d",
6788 vdev_id);
6789 rcu_read_unlock();
6790 return;
6791 }
6792
6793 complete(&ar->vdev_setup_done);
6794
6795 rcu_read_unlock();
6796
6797 ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id);
6798 }
6799
ath11k_mgmt_rx_event(struct ath11k_base * ab,struct sk_buff * skb)6800 static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb)
6801 {
6802 struct mgmt_rx_event_params rx_ev = {0};
6803 struct ath11k *ar;
6804 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
6805 struct ieee80211_hdr *hdr;
6806 u16 fc;
6807 struct ieee80211_supported_band *sband;
6808
6809 if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) {
6810 ath11k_warn(ab, "failed to extract mgmt rx event");
6811 dev_kfree_skb(skb);
6812 return;
6813 }
6814
6815 memset(status, 0, sizeof(*status));
6816
6817 ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n",
6818 rx_ev.status);
6819
6820 rcu_read_lock();
6821 ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id);
6822
6823 if (!ar) {
6824 ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n",
6825 rx_ev.pdev_id);
6826 dev_kfree_skb(skb);
6827 goto exit;
6828 }
6829
6830 if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) ||
6831 (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT |
6832 WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
6833 dev_kfree_skb(skb);
6834 goto exit;
6835 }
6836
6837 if (rx_ev.status & WMI_RX_STATUS_ERR_MIC)
6838 status->flag |= RX_FLAG_MMIC_ERROR;
6839
6840 if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ &&
6841 rx_ev.chan_freq <= ATH11K_MAX_6G_FREQ) {
6842 status->band = NL80211_BAND_6GHZ;
6843 status->freq = rx_ev.chan_freq;
6844 } else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) {
6845 status->band = NL80211_BAND_2GHZ;
6846 } else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) {
6847 status->band = NL80211_BAND_5GHZ;
6848 } else {
6849 /* Shouldn't happen unless list of advertised channels to
6850 * mac80211 has been changed.
6851 */
6852 WARN_ON_ONCE(1);
6853 dev_kfree_skb(skb);
6854 goto exit;
6855 }
6856
6857 if (rx_ev.phy_mode == MODE_11B &&
6858 (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ))
6859 ath11k_dbg(ab, ATH11K_DBG_WMI,
6860 "wmi mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band);
6861
6862 sband = &ar->mac.sbands[status->band];
6863
6864 if (status->band != NL80211_BAND_6GHZ)
6865 status->freq = ieee80211_channel_to_frequency(rx_ev.channel,
6866 status->band);
6867
6868 status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR;
6869 status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100);
6870
6871 hdr = (struct ieee80211_hdr *)skb->data;
6872 fc = le16_to_cpu(hdr->frame_control);
6873
6874 /* Firmware is guaranteed to report all essential management frames via
6875 * WMI while it can deliver some extra via HTT. Since there can be
6876 * duplicates split the reporting wrt monitor/sniffing.
6877 */
6878 status->flag |= RX_FLAG_SKIP_MONITOR;
6879
6880 /* In case of PMF, FW delivers decrypted frames with Protected Bit set.
6881 * Don't clear that. Also, FW delivers broadcast management frames
6882 * (ex: group privacy action frames in mesh) as encrypted payload.
6883 */
6884 if (ieee80211_has_protected(hdr->frame_control) &&
6885 !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
6886 status->flag |= RX_FLAG_DECRYPTED;
6887
6888 if (!ieee80211_is_robust_mgmt_frame(skb)) {
6889 status->flag |= RX_FLAG_IV_STRIPPED |
6890 RX_FLAG_MMIC_STRIPPED;
6891 hdr->frame_control = __cpu_to_le16(fc &
6892 ~IEEE80211_FCTL_PROTECTED);
6893 }
6894 }
6895
6896 if (ieee80211_is_beacon(hdr->frame_control))
6897 ath11k_mac_handle_beacon(ar, skb);
6898
6899 ath11k_dbg(ab, ATH11K_DBG_MGMT,
6900 "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
6901 skb, skb->len,
6902 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
6903
6904 ath11k_dbg(ab, ATH11K_DBG_MGMT,
6905 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
6906 status->freq, status->band, status->signal,
6907 status->rate_idx);
6908
6909 ieee80211_rx_ni(ar->hw, skb);
6910
6911 exit:
6912 rcu_read_unlock();
6913 }
6914
ath11k_mgmt_tx_compl_event(struct ath11k_base * ab,struct sk_buff * skb)6915 static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb)
6916 {
6917 struct wmi_mgmt_tx_compl_event tx_compl_param = {0};
6918 struct ath11k *ar;
6919
6920 if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) {
6921 ath11k_warn(ab, "failed to extract mgmt tx compl event");
6922 return;
6923 }
6924
6925 rcu_read_lock();
6926 ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id);
6927 if (!ar) {
6928 ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n",
6929 tx_compl_param.pdev_id);
6930 goto exit;
6931 }
6932
6933 wmi_process_mgmt_tx_comp(ar, tx_compl_param.desc_id,
6934 tx_compl_param.status);
6935
6936 ath11k_dbg(ab, ATH11K_DBG_MGMT,
6937 "mgmt tx compl ev pdev_id %d, desc_id %d, status %d",
6938 tx_compl_param.pdev_id, tx_compl_param.desc_id,
6939 tx_compl_param.status);
6940
6941 exit:
6942 rcu_read_unlock();
6943 }
6944
ath11k_get_ar_on_scan_state(struct ath11k_base * ab,u32 vdev_id,enum ath11k_scan_state state)6945 static struct ath11k *ath11k_get_ar_on_scan_state(struct ath11k_base *ab,
6946 u32 vdev_id,
6947 enum ath11k_scan_state state)
6948 {
6949 int i;
6950 struct ath11k_pdev *pdev;
6951 struct ath11k *ar;
6952
6953 for (i = 0; i < ab->num_radios; i++) {
6954 pdev = rcu_dereference(ab->pdevs_active[i]);
6955 if (pdev && pdev->ar) {
6956 ar = pdev->ar;
6957
6958 spin_lock_bh(&ar->data_lock);
6959 if (ar->scan.state == state &&
6960 ar->scan.vdev_id == vdev_id) {
6961 spin_unlock_bh(&ar->data_lock);
6962 return ar;
6963 }
6964 spin_unlock_bh(&ar->data_lock);
6965 }
6966 }
6967 return NULL;
6968 }
6969
ath11k_scan_event(struct ath11k_base * ab,struct sk_buff * skb)6970 static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb)
6971 {
6972 struct ath11k *ar;
6973 struct wmi_scan_event scan_ev = {0};
6974
6975 if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) {
6976 ath11k_warn(ab, "failed to extract scan event");
6977 return;
6978 }
6979
6980 rcu_read_lock();
6981
6982 /* In case the scan was cancelled, ex. during interface teardown,
6983 * the interface will not be found in active interfaces.
6984 * Rather, in such scenarios, iterate over the active pdev's to
6985 * search 'ar' if the corresponding 'ar' scan is ABORTING and the
6986 * aborting scan's vdev id matches this event info.
6987 */
6988 if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED &&
6989 scan_ev.reason == WMI_SCAN_REASON_CANCELLED) {
6990 ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
6991 ATH11K_SCAN_ABORTING);
6992 if (!ar)
6993 ar = ath11k_get_ar_on_scan_state(ab, scan_ev.vdev_id,
6994 ATH11K_SCAN_RUNNING);
6995 } else {
6996 ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id);
6997 }
6998
6999 if (!ar) {
7000 ath11k_warn(ab, "Received scan event for unknown vdev");
7001 rcu_read_unlock();
7002 return;
7003 }
7004
7005 spin_lock_bh(&ar->data_lock);
7006
7007 ath11k_dbg(ab, ATH11K_DBG_WMI,
7008 "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
7009 ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason),
7010 scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq,
7011 scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id,
7012 ath11k_scan_state_str(ar->scan.state), ar->scan.state);
7013
7014 switch (scan_ev.event_type) {
7015 case WMI_SCAN_EVENT_STARTED:
7016 ath11k_wmi_event_scan_started(ar);
7017 break;
7018 case WMI_SCAN_EVENT_COMPLETED:
7019 ath11k_wmi_event_scan_completed(ar);
7020 break;
7021 case WMI_SCAN_EVENT_BSS_CHANNEL:
7022 ath11k_wmi_event_scan_bss_chan(ar);
7023 break;
7024 case WMI_SCAN_EVENT_FOREIGN_CHAN:
7025 ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq);
7026 break;
7027 case WMI_SCAN_EVENT_START_FAILED:
7028 ath11k_warn(ab, "received scan start failure event\n");
7029 ath11k_wmi_event_scan_start_failed(ar);
7030 break;
7031 case WMI_SCAN_EVENT_DEQUEUED:
7032 __ath11k_mac_scan_finish(ar);
7033 break;
7034 case WMI_SCAN_EVENT_PREEMPTED:
7035 case WMI_SCAN_EVENT_RESTARTED:
7036 case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT:
7037 default:
7038 break;
7039 }
7040
7041 spin_unlock_bh(&ar->data_lock);
7042
7043 rcu_read_unlock();
7044 }
7045
ath11k_peer_sta_kickout_event(struct ath11k_base * ab,struct sk_buff * skb)7046 static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb)
7047 {
7048 struct wmi_peer_sta_kickout_arg arg = {};
7049 struct ieee80211_sta *sta;
7050 struct ath11k_peer *peer;
7051 struct ath11k *ar;
7052 u32 vdev_id;
7053
7054 if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) {
7055 ath11k_warn(ab, "failed to extract peer sta kickout event");
7056 return;
7057 }
7058
7059 rcu_read_lock();
7060
7061 spin_lock_bh(&ab->base_lock);
7062
7063 peer = ath11k_peer_find_by_addr(ab, arg.mac_addr);
7064
7065 if (!peer) {
7066 ath11k_warn(ab, "peer not found %pM\n",
7067 arg.mac_addr);
7068 spin_unlock_bh(&ab->base_lock);
7069 goto exit;
7070 }
7071
7072 vdev_id = peer->vdev_id;
7073
7074 spin_unlock_bh(&ab->base_lock);
7075
7076 ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id);
7077 if (!ar) {
7078 ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d",
7079 peer->vdev_id);
7080 goto exit;
7081 }
7082
7083 sta = ieee80211_find_sta_by_ifaddr(ar->hw,
7084 arg.mac_addr, NULL);
7085 if (!sta) {
7086 ath11k_warn(ab, "Spurious quick kickout for STA %pM\n",
7087 arg.mac_addr);
7088 goto exit;
7089 }
7090
7091 ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM",
7092 arg.mac_addr);
7093
7094 ieee80211_report_low_ack(sta, 10);
7095
7096 exit:
7097 rcu_read_unlock();
7098 }
7099
ath11k_roam_event(struct ath11k_base * ab,struct sk_buff * skb)7100 static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb)
7101 {
7102 struct wmi_roam_event roam_ev = {};
7103 struct ath11k *ar;
7104
7105 if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) {
7106 ath11k_warn(ab, "failed to extract roam event");
7107 return;
7108 }
7109
7110 ath11k_dbg(ab, ATH11K_DBG_WMI,
7111 "wmi roam event vdev %u reason 0x%08x rssi %d\n",
7112 roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi);
7113
7114 rcu_read_lock();
7115 ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id);
7116 if (!ar) {
7117 ath11k_warn(ab, "invalid vdev id in roam ev %d",
7118 roam_ev.vdev_id);
7119 rcu_read_unlock();
7120 return;
7121 }
7122
7123 if (roam_ev.reason >= WMI_ROAM_REASON_MAX)
7124 ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n",
7125 roam_ev.reason, roam_ev.vdev_id);
7126
7127 switch (roam_ev.reason) {
7128 case WMI_ROAM_REASON_BEACON_MISS:
7129 ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id);
7130 break;
7131 case WMI_ROAM_REASON_BETTER_AP:
7132 case WMI_ROAM_REASON_LOW_RSSI:
7133 case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
7134 case WMI_ROAM_REASON_HO_FAILED:
7135 ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n",
7136 roam_ev.reason, roam_ev.vdev_id);
7137 break;
7138 }
7139
7140 rcu_read_unlock();
7141 }
7142
ath11k_chan_info_event(struct ath11k_base * ab,struct sk_buff * skb)7143 static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7144 {
7145 struct wmi_chan_info_event ch_info_ev = {0};
7146 struct ath11k *ar;
7147 struct survey_info *survey;
7148 int idx;
7149 /* HW channel counters frequency value in hertz */
7150 u32 cc_freq_hz = ab->cc_freq_hz;
7151
7152 if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) {
7153 ath11k_warn(ab, "failed to extract chan info event");
7154 return;
7155 }
7156
7157 ath11k_dbg(ab, ATH11K_DBG_WMI,
7158 "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",
7159 ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq,
7160 ch_info_ev.cmd_flags, ch_info_ev.noise_floor,
7161 ch_info_ev.rx_clear_count, ch_info_ev.cycle_count,
7162 ch_info_ev.mac_clk_mhz);
7163
7164 if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) {
7165 ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n");
7166 return;
7167 }
7168
7169 rcu_read_lock();
7170 ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id);
7171 if (!ar) {
7172 ath11k_warn(ab, "invalid vdev id in chan info ev %d",
7173 ch_info_ev.vdev_id);
7174 rcu_read_unlock();
7175 return;
7176 }
7177 spin_lock_bh(&ar->data_lock);
7178
7179 switch (ar->scan.state) {
7180 case ATH11K_SCAN_IDLE:
7181 case ATH11K_SCAN_STARTING:
7182 ath11k_warn(ab, "received chan info event without a scan request, ignoring\n");
7183 goto exit;
7184 case ATH11K_SCAN_RUNNING:
7185 case ATH11K_SCAN_ABORTING:
7186 break;
7187 }
7188
7189 idx = freq_to_idx(ar, ch_info_ev.freq);
7190 if (idx >= ARRAY_SIZE(ar->survey)) {
7191 ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n",
7192 ch_info_ev.freq, idx);
7193 goto exit;
7194 }
7195
7196 /* If FW provides MAC clock frequency in Mhz, overriding the initialized
7197 * HW channel counters frequency value
7198 */
7199 if (ch_info_ev.mac_clk_mhz)
7200 cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000);
7201
7202 if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) {
7203 survey = &ar->survey[idx];
7204 memset(survey, 0, sizeof(*survey));
7205 survey->noise = ch_info_ev.noise_floor;
7206 survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
7207 SURVEY_INFO_TIME_BUSY;
7208 survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz);
7209 survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz);
7210 }
7211 exit:
7212 spin_unlock_bh(&ar->data_lock);
7213 rcu_read_unlock();
7214 }
7215
7216 static void
ath11k_pdev_bss_chan_info_event(struct ath11k_base * ab,struct sk_buff * skb)7217 ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb)
7218 {
7219 struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {};
7220 struct survey_info *survey;
7221 struct ath11k *ar;
7222 u32 cc_freq_hz = ab->cc_freq_hz;
7223 u64 busy, total, tx, rx, rx_bss;
7224 int idx;
7225
7226 if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) {
7227 ath11k_warn(ab, "failed to extract pdev bss chan info event");
7228 return;
7229 }
7230
7231 busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 |
7232 bss_ch_info_ev.rx_clear_count_low;
7233
7234 total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 |
7235 bss_ch_info_ev.cycle_count_low;
7236
7237 tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 |
7238 bss_ch_info_ev.tx_cycle_count_low;
7239
7240 rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 |
7241 bss_ch_info_ev.rx_cycle_count_low;
7242
7243 rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 |
7244 bss_ch_info_ev.rx_bss_cycle_count_low;
7245
7246 ath11k_dbg(ab, ATH11K_DBG_WMI,
7247 "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",
7248 bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq,
7249 bss_ch_info_ev.noise_floor, busy, total,
7250 tx, rx, rx_bss);
7251
7252 rcu_read_lock();
7253 ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id);
7254
7255 if (!ar) {
7256 ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n",
7257 bss_ch_info_ev.pdev_id);
7258 rcu_read_unlock();
7259 return;
7260 }
7261
7262 spin_lock_bh(&ar->data_lock);
7263 idx = freq_to_idx(ar, bss_ch_info_ev.freq);
7264 if (idx >= ARRAY_SIZE(ar->survey)) {
7265 ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
7266 bss_ch_info_ev.freq, idx);
7267 goto exit;
7268 }
7269
7270 survey = &ar->survey[idx];
7271
7272 survey->noise = bss_ch_info_ev.noise_floor;
7273 survey->time = div_u64(total, cc_freq_hz);
7274 survey->time_busy = div_u64(busy, cc_freq_hz);
7275 survey->time_rx = div_u64(rx_bss, cc_freq_hz);
7276 survey->time_tx = div_u64(tx, cc_freq_hz);
7277 survey->filled |= (SURVEY_INFO_NOISE_DBM |
7278 SURVEY_INFO_TIME |
7279 SURVEY_INFO_TIME_BUSY |
7280 SURVEY_INFO_TIME_RX |
7281 SURVEY_INFO_TIME_TX);
7282 exit:
7283 spin_unlock_bh(&ar->data_lock);
7284 complete(&ar->bss_survey_done);
7285
7286 rcu_read_unlock();
7287 }
7288
ath11k_vdev_install_key_compl_event(struct ath11k_base * ab,struct sk_buff * skb)7289 static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab,
7290 struct sk_buff *skb)
7291 {
7292 struct wmi_vdev_install_key_complete_arg install_key_compl = {0};
7293 struct ath11k *ar;
7294
7295 if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) {
7296 ath11k_warn(ab, "failed to extract install key compl event");
7297 return;
7298 }
7299
7300 ath11k_dbg(ab, ATH11K_DBG_WMI,
7301 "vdev install key ev idx %d flags %08x macaddr %pM status %d\n",
7302 install_key_compl.key_idx, install_key_compl.key_flags,
7303 install_key_compl.macaddr, install_key_compl.status);
7304
7305 rcu_read_lock();
7306 ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id);
7307 if (!ar) {
7308 ath11k_warn(ab, "invalid vdev id in install key compl ev %d",
7309 install_key_compl.vdev_id);
7310 rcu_read_unlock();
7311 return;
7312 }
7313
7314 ar->install_key_status = 0;
7315
7316 if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) {
7317 ath11k_warn(ab, "install key failed for %pM status %d\n",
7318 install_key_compl.macaddr, install_key_compl.status);
7319 ar->install_key_status = install_key_compl.status;
7320 }
7321
7322 complete(&ar->install_key_done);
7323 rcu_read_unlock();
7324 }
7325
ath11k_wmi_tlv_services_parser(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)7326 static int ath11k_wmi_tlv_services_parser(struct ath11k_base *ab,
7327 u16 tag, u16 len,
7328 const void *ptr, void *data)
7329 {
7330 const struct wmi_service_available_event *ev;
7331 u32 *wmi_ext2_service_bitmap;
7332 int i, j;
7333
7334 switch (tag) {
7335 case WMI_TAG_SERVICE_AVAILABLE_EVENT:
7336 ev = (struct wmi_service_available_event *)ptr;
7337 for (i = 0, j = WMI_MAX_SERVICE;
7338 i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE;
7339 i++) {
7340 do {
7341 if (ev->wmi_service_segment_bitmap[i] &
7342 BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
7343 set_bit(j, ab->wmi_ab.svc_map);
7344 } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
7345 }
7346
7347 ath11k_dbg(ab, ATH11K_DBG_WMI,
7348 "wmi_ext_service_bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
7349 ev->wmi_service_segment_bitmap[0],
7350 ev->wmi_service_segment_bitmap[1],
7351 ev->wmi_service_segment_bitmap[2],
7352 ev->wmi_service_segment_bitmap[3]);
7353 break;
7354 case WMI_TAG_ARRAY_UINT32:
7355 wmi_ext2_service_bitmap = (u32 *)ptr;
7356 for (i = 0, j = WMI_MAX_EXT_SERVICE;
7357 i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT2_SERVICE;
7358 i++) {
7359 do {
7360 if (wmi_ext2_service_bitmap[i] &
7361 BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32))
7362 set_bit(j, ab->wmi_ab.svc_map);
7363 } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32);
7364 }
7365
7366 ath11k_dbg(ab, ATH11K_DBG_WMI,
7367 "wmi_ext2_service__bitmap 0:0x%04x, 1:0x%04x, 2:0x%04x, 3:0x%04x",
7368 wmi_ext2_service_bitmap[0], wmi_ext2_service_bitmap[1],
7369 wmi_ext2_service_bitmap[2], wmi_ext2_service_bitmap[3]);
7370 break;
7371 }
7372 return 0;
7373 }
7374
ath11k_service_available_event(struct ath11k_base * ab,struct sk_buff * skb)7375 static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb)
7376 {
7377 int ret;
7378
7379 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7380 ath11k_wmi_tlv_services_parser,
7381 NULL);
7382 if (ret)
7383 ath11k_warn(ab, "failed to parse services available tlv %d\n", ret);
7384 }
7385
ath11k_peer_assoc_conf_event(struct ath11k_base * ab,struct sk_buff * skb)7386 static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb)
7387 {
7388 struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0};
7389 struct ath11k *ar;
7390
7391 if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) {
7392 ath11k_warn(ab, "failed to extract peer assoc conf event");
7393 return;
7394 }
7395
7396 ath11k_dbg(ab, ATH11K_DBG_WMI,
7397 "peer assoc conf ev vdev id %d macaddr %pM\n",
7398 peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr);
7399
7400 rcu_read_lock();
7401 ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id);
7402
7403 if (!ar) {
7404 ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d",
7405 peer_assoc_conf.vdev_id);
7406 rcu_read_unlock();
7407 return;
7408 }
7409
7410 complete(&ar->peer_assoc_done);
7411 rcu_read_unlock();
7412 }
7413
ath11k_update_stats_event(struct ath11k_base * ab,struct sk_buff * skb)7414 static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
7415 {
7416 ath11k_debugfs_fw_stats_process(ab, skb);
7417 }
7418
7419 /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
7420 * is not part of BDF CTL(Conformance test limits) table entries.
7421 */
ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base * ab,struct sk_buff * skb)7422 static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab,
7423 struct sk_buff *skb)
7424 {
7425 const void **tb;
7426 const struct wmi_pdev_ctl_failsafe_chk_event *ev;
7427 int ret;
7428
7429 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7430 if (IS_ERR(tb)) {
7431 ret = PTR_ERR(tb);
7432 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7433 return;
7434 }
7435
7436 ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT];
7437 if (!ev) {
7438 ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev");
7439 kfree(tb);
7440 return;
7441 }
7442
7443 ath11k_dbg(ab, ATH11K_DBG_WMI,
7444 "pdev ctl failsafe check ev status %d\n",
7445 ev->ctl_failsafe_status);
7446
7447 /* If ctl_failsafe_status is set to 1 FW will max out the Transmit power
7448 * to 10 dBm else the CTL power entry in the BDF would be picked up.
7449 */
7450 if (ev->ctl_failsafe_status != 0)
7451 ath11k_warn(ab, "pdev ctl failsafe failure status %d",
7452 ev->ctl_failsafe_status);
7453
7454 kfree(tb);
7455 }
7456
7457 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)7458 ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab,
7459 const struct wmi_pdev_csa_switch_ev *ev,
7460 const u32 *vdev_ids)
7461 {
7462 int i;
7463 struct ath11k_vif *arvif;
7464
7465 /* Finish CSA once the switch count becomes NULL */
7466 if (ev->current_switch_count)
7467 return;
7468
7469 rcu_read_lock();
7470 for (i = 0; i < ev->num_vdevs; i++) {
7471 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]);
7472
7473 if (!arvif) {
7474 ath11k_warn(ab, "Recvd csa status for unknown vdev %d",
7475 vdev_ids[i]);
7476 continue;
7477 }
7478
7479 if (arvif->is_up && arvif->vif->bss_conf.csa_active)
7480 ieee80211_csa_finish(arvif->vif);
7481 }
7482 rcu_read_unlock();
7483 }
7484
7485 static void
ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base * ab,struct sk_buff * skb)7486 ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab,
7487 struct sk_buff *skb)
7488 {
7489 const void **tb;
7490 const struct wmi_pdev_csa_switch_ev *ev;
7491 const u32 *vdev_ids;
7492 int ret;
7493
7494 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7495 if (IS_ERR(tb)) {
7496 ret = PTR_ERR(tb);
7497 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7498 return;
7499 }
7500
7501 ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT];
7502 vdev_ids = tb[WMI_TAG_ARRAY_UINT32];
7503
7504 if (!ev || !vdev_ids) {
7505 ath11k_warn(ab, "failed to fetch pdev csa switch count ev");
7506 kfree(tb);
7507 return;
7508 }
7509
7510 ath11k_dbg(ab, ATH11K_DBG_WMI,
7511 "pdev csa switch count %d for pdev %d, num_vdevs %d",
7512 ev->current_switch_count, ev->pdev_id,
7513 ev->num_vdevs);
7514
7515 ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids);
7516
7517 kfree(tb);
7518 }
7519
7520 static void
ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base * ab,struct sk_buff * skb)7521 ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb)
7522 {
7523 const void **tb;
7524 const struct wmi_pdev_radar_ev *ev;
7525 struct ath11k *ar;
7526 int ret;
7527
7528 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7529 if (IS_ERR(tb)) {
7530 ret = PTR_ERR(tb);
7531 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7532 return;
7533 }
7534
7535 ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT];
7536
7537 if (!ev) {
7538 ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev");
7539 kfree(tb);
7540 return;
7541 }
7542
7543 ath11k_dbg(ab, ATH11K_DBG_WMI,
7544 "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",
7545 ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width,
7546 ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp,
7547 ev->freq_offset, ev->sidx);
7548
7549 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
7550
7551 if (!ar) {
7552 ath11k_warn(ab, "radar detected in invalid pdev %d\n",
7553 ev->pdev_id);
7554 goto exit;
7555 }
7556
7557 ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n",
7558 ev->pdev_id);
7559
7560 if (ar->dfs_block_radar_events)
7561 ath11k_info(ab, "DFS Radar detected, but ignored as requested\n");
7562 else
7563 ieee80211_radar_detected(ar->hw);
7564
7565 exit:
7566 kfree(tb);
7567 }
7568
ath11k_rfkill_state_change_event(struct ath11k_base * ab,struct sk_buff * skb)7569 static void ath11k_rfkill_state_change_event(struct ath11k_base *ab,
7570 struct sk_buff *skb)
7571 {
7572 const struct wmi_rfkill_state_change_ev *ev;
7573 const void **tb;
7574 int ret;
7575
7576 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7577 if (IS_ERR(tb)) {
7578 ret = PTR_ERR(tb);
7579 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7580 return;
7581 }
7582
7583 ev = tb[WMI_TAG_RFKILL_EVENT];
7584 if (!ev) {
7585 kfree(tb);
7586 return;
7587 }
7588
7589 ath11k_dbg(ab, ATH11K_DBG_MAC,
7590 "wmi tlv rfkill state change gpio %d type %d radio_state %d\n",
7591 ev->gpio_pin_num,
7592 ev->int_type,
7593 ev->radio_state);
7594
7595 spin_lock_bh(&ab->base_lock);
7596 ab->rfkill_radio_on = (ev->radio_state == WMI_RFKILL_RADIO_STATE_ON);
7597 spin_unlock_bh(&ab->base_lock);
7598
7599 queue_work(ab->workqueue, &ab->rfkill_work);
7600 kfree(tb);
7601 }
7602
7603 static void
ath11k_wmi_pdev_temperature_event(struct ath11k_base * ab,struct sk_buff * skb)7604 ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab,
7605 struct sk_buff *skb)
7606 {
7607 struct ath11k *ar;
7608 const void **tb;
7609 const struct wmi_pdev_temperature_event *ev;
7610 int ret;
7611
7612 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7613 if (IS_ERR(tb)) {
7614 ret = PTR_ERR(tb);
7615 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7616 return;
7617 }
7618
7619 ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT];
7620 if (!ev) {
7621 ath11k_warn(ab, "failed to fetch pdev temp ev");
7622 kfree(tb);
7623 return;
7624 }
7625
7626 ath11k_dbg(ab, ATH11K_DBG_WMI,
7627 "pdev temperature ev temp %d pdev_id %d\n", ev->temp, ev->pdev_id);
7628
7629 ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id);
7630 if (!ar) {
7631 ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id);
7632 kfree(tb);
7633 return;
7634 }
7635
7636 ath11k_thermal_event_temperature(ar, ev->temp);
7637
7638 kfree(tb);
7639 }
7640
ath11k_fils_discovery_event(struct ath11k_base * ab,struct sk_buff * skb)7641 static void ath11k_fils_discovery_event(struct ath11k_base *ab,
7642 struct sk_buff *skb)
7643 {
7644 const void **tb;
7645 const struct wmi_fils_discovery_event *ev;
7646 int ret;
7647
7648 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7649 if (IS_ERR(tb)) {
7650 ret = PTR_ERR(tb);
7651 ath11k_warn(ab,
7652 "failed to parse FILS discovery event tlv %d\n",
7653 ret);
7654 return;
7655 }
7656
7657 ev = tb[WMI_TAG_HOST_SWFDA_EVENT];
7658 if (!ev) {
7659 ath11k_warn(ab, "failed to fetch FILS discovery event\n");
7660 kfree(tb);
7661 return;
7662 }
7663
7664 ath11k_warn(ab,
7665 "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n",
7666 ev->vdev_id, ev->fils_tt, ev->tbtt);
7667
7668 kfree(tb);
7669 }
7670
ath11k_probe_resp_tx_status_event(struct ath11k_base * ab,struct sk_buff * skb)7671 static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab,
7672 struct sk_buff *skb)
7673 {
7674 const void **tb;
7675 const struct wmi_probe_resp_tx_status_event *ev;
7676 int ret;
7677
7678 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7679 if (IS_ERR(tb)) {
7680 ret = PTR_ERR(tb);
7681 ath11k_warn(ab,
7682 "failed to parse probe response transmission status event tlv: %d\n",
7683 ret);
7684 return;
7685 }
7686
7687 ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT];
7688 if (!ev) {
7689 ath11k_warn(ab,
7690 "failed to fetch probe response transmission status event");
7691 kfree(tb);
7692 return;
7693 }
7694
7695 if (ev->tx_status)
7696 ath11k_warn(ab,
7697 "Probe response transmission failed for vdev_id %u, status %u\n",
7698 ev->vdev_id, ev->tx_status);
7699
7700 kfree(tb);
7701 }
7702
ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base * ab,u16 tag,u16 len,const void * ptr,void * data)7703 static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab,
7704 u16 tag, u16 len,
7705 const void *ptr, void *data)
7706 {
7707 struct wmi_wow_ev_arg *ev = data;
7708 const char *wow_pg_fault;
7709 int wow_pg_len;
7710
7711 switch (tag) {
7712 case WMI_TAG_WOW_EVENT_INFO:
7713 memcpy(ev, ptr, sizeof(*ev));
7714 ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n",
7715 ev->wake_reason, wow_reason(ev->wake_reason));
7716 break;
7717
7718 case WMI_TAG_ARRAY_BYTE:
7719 if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) {
7720 wow_pg_fault = ptr;
7721 /* the first 4 bytes are length */
7722 wow_pg_len = *(int *)wow_pg_fault;
7723 wow_pg_fault += sizeof(int);
7724 ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n",
7725 wow_pg_len);
7726 ath11k_dbg_dump(ab, ATH11K_DBG_WMI,
7727 "wow_event_info_type packet present",
7728 "wow_pg_fault ",
7729 wow_pg_fault,
7730 wow_pg_len);
7731 }
7732 break;
7733 default:
7734 break;
7735 }
7736
7737 return 0;
7738 }
7739
ath11k_wmi_event_wow_wakeup_host(struct ath11k_base * ab,struct sk_buff * skb)7740 static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb)
7741 {
7742 struct wmi_wow_ev_arg ev = { };
7743 int ret;
7744
7745 ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len,
7746 ath11k_wmi_tlv_wow_wakeup_host_parse,
7747 &ev);
7748 if (ret) {
7749 ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret);
7750 return;
7751 }
7752
7753 complete(&ab->wow.wakeup_completed);
7754 }
7755
7756 static void
ath11k_wmi_diag_event(struct ath11k_base * ab,struct sk_buff * skb)7757 ath11k_wmi_diag_event(struct ath11k_base *ab,
7758 struct sk_buff *skb)
7759 {
7760 trace_ath11k_wmi_diag(ab, skb->data, skb->len);
7761 }
7762
ath11k_wmi_twt_add_dialog_event_status(u32 status)7763 static const char *ath11k_wmi_twt_add_dialog_event_status(u32 status)
7764 {
7765 switch (status) {
7766 case WMI_ADD_TWT_STATUS_OK:
7767 return "ok";
7768 case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
7769 return "twt disabled";
7770 case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
7771 return "dialog id in use";
7772 case WMI_ADD_TWT_STATUS_INVALID_PARAM:
7773 return "invalid parameters";
7774 case WMI_ADD_TWT_STATUS_NOT_READY:
7775 return "not ready";
7776 case WMI_ADD_TWT_STATUS_NO_RESOURCE:
7777 return "resource unavailable";
7778 case WMI_ADD_TWT_STATUS_NO_ACK:
7779 return "no ack";
7780 case WMI_ADD_TWT_STATUS_NO_RESPONSE:
7781 return "no response";
7782 case WMI_ADD_TWT_STATUS_DENIED:
7783 return "denied";
7784 case WMI_ADD_TWT_STATUS_UNKNOWN_ERROR:
7785 fallthrough;
7786 default:
7787 return "unknown error";
7788 }
7789 }
7790
ath11k_wmi_twt_add_dialog_event(struct ath11k_base * ab,struct sk_buff * skb)7791 static void ath11k_wmi_twt_add_dialog_event(struct ath11k_base *ab,
7792 struct sk_buff *skb)
7793 {
7794 const void **tb;
7795 const struct wmi_twt_add_dialog_event *ev;
7796 int ret;
7797
7798 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7799 if (IS_ERR(tb)) {
7800 ret = PTR_ERR(tb);
7801 ath11k_warn(ab,
7802 "failed to parse wmi twt add dialog status event tlv: %d\n",
7803 ret);
7804 return;
7805 }
7806
7807 ev = tb[WMI_TAG_TWT_ADD_DIALOG_COMPLETE_EVENT];
7808 if (!ev) {
7809 ath11k_warn(ab, "failed to fetch twt add dialog wmi event\n");
7810 goto exit;
7811 }
7812
7813 if (ev->status)
7814 ath11k_warn(ab,
7815 "wmi add twt dialog event vdev %d dialog id %d status %s\n",
7816 ev->vdev_id, ev->dialog_id,
7817 ath11k_wmi_twt_add_dialog_event_status(ev->status));
7818
7819 exit:
7820 kfree(tb);
7821 }
7822
ath11k_wmi_gtk_offload_status_event(struct ath11k_base * ab,struct sk_buff * skb)7823 static void ath11k_wmi_gtk_offload_status_event(struct ath11k_base *ab,
7824 struct sk_buff *skb)
7825 {
7826 const void **tb;
7827 const struct wmi_gtk_offload_status_event *ev;
7828 struct ath11k_vif *arvif;
7829 __be64 replay_ctr_be;
7830 u64 replay_ctr;
7831 int ret;
7832
7833 tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC);
7834 if (IS_ERR(tb)) {
7835 ret = PTR_ERR(tb);
7836 ath11k_warn(ab, "failed to parse tlv: %d\n", ret);
7837 return;
7838 }
7839
7840 ev = tb[WMI_TAG_GTK_OFFLOAD_STATUS_EVENT];
7841 if (!ev) {
7842 ath11k_warn(ab, "failed to fetch gtk offload status ev");
7843 kfree(tb);
7844 return;
7845 }
7846
7847 arvif = ath11k_mac_get_arvif_by_vdev_id(ab, ev->vdev_id);
7848 if (!arvif) {
7849 ath11k_warn(ab, "failed to get arvif for vdev_id:%d\n",
7850 ev->vdev_id);
7851 kfree(tb);
7852 return;
7853 }
7854
7855 ath11k_dbg(ab, ATH11K_DBG_WMI, "wmi gtk offload event refresh_cnt %d\n",
7856 ev->refresh_cnt);
7857 ath11k_dbg_dump(ab, ATH11K_DBG_WMI, "replay_cnt",
7858 NULL, ev->replay_ctr.counter, GTK_REPLAY_COUNTER_BYTES);
7859
7860 replay_ctr = ev->replay_ctr.word1;
7861 replay_ctr = (replay_ctr << 32) | ev->replay_ctr.word0;
7862 arvif->rekey_data.replay_ctr = replay_ctr;
7863
7864 /* supplicant expects big-endian replay counter */
7865 replay_ctr_be = cpu_to_be64(replay_ctr);
7866
7867 ieee80211_gtk_rekey_notify(arvif->vif, arvif->bssid,
7868 (void *)&replay_ctr_be, GFP_ATOMIC);
7869
7870 kfree(tb);
7871 }
7872
ath11k_wmi_tlv_op_rx(struct ath11k_base * ab,struct sk_buff * skb)7873 static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb)
7874 {
7875 struct wmi_cmd_hdr *cmd_hdr;
7876 enum wmi_tlv_event_id id;
7877
7878 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
7879 id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id));
7880
7881 trace_ath11k_wmi_event(ab, id, skb->data, skb->len);
7882
7883 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
7884 goto out;
7885
7886 switch (id) {
7887 /* Process all the WMI events here */
7888 case WMI_SERVICE_READY_EVENTID:
7889 ath11k_service_ready_event(ab, skb);
7890 break;
7891 case WMI_SERVICE_READY_EXT_EVENTID:
7892 ath11k_service_ready_ext_event(ab, skb);
7893 break;
7894 case WMI_SERVICE_READY_EXT2_EVENTID:
7895 ath11k_service_ready_ext2_event(ab, skb);
7896 break;
7897 case WMI_REG_CHAN_LIST_CC_EVENTID:
7898 ath11k_reg_chan_list_event(ab, skb);
7899 break;
7900 case WMI_READY_EVENTID:
7901 ath11k_ready_event(ab, skb);
7902 break;
7903 case WMI_PEER_DELETE_RESP_EVENTID:
7904 ath11k_peer_delete_resp_event(ab, skb);
7905 break;
7906 case WMI_VDEV_START_RESP_EVENTID:
7907 ath11k_vdev_start_resp_event(ab, skb);
7908 break;
7909 case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID:
7910 ath11k_bcn_tx_status_event(ab, skb);
7911 break;
7912 case WMI_VDEV_STOPPED_EVENTID:
7913 ath11k_vdev_stopped_event(ab, skb);
7914 break;
7915 case WMI_MGMT_RX_EVENTID:
7916 ath11k_mgmt_rx_event(ab, skb);
7917 /* mgmt_rx_event() owns the skb now! */
7918 return;
7919 case WMI_MGMT_TX_COMPLETION_EVENTID:
7920 ath11k_mgmt_tx_compl_event(ab, skb);
7921 break;
7922 case WMI_SCAN_EVENTID:
7923 ath11k_scan_event(ab, skb);
7924 break;
7925 case WMI_PEER_STA_KICKOUT_EVENTID:
7926 ath11k_peer_sta_kickout_event(ab, skb);
7927 break;
7928 case WMI_ROAM_EVENTID:
7929 ath11k_roam_event(ab, skb);
7930 break;
7931 case WMI_CHAN_INFO_EVENTID:
7932 ath11k_chan_info_event(ab, skb);
7933 break;
7934 case WMI_PDEV_BSS_CHAN_INFO_EVENTID:
7935 ath11k_pdev_bss_chan_info_event(ab, skb);
7936 break;
7937 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
7938 ath11k_vdev_install_key_compl_event(ab, skb);
7939 break;
7940 case WMI_SERVICE_AVAILABLE_EVENTID:
7941 ath11k_service_available_event(ab, skb);
7942 break;
7943 case WMI_PEER_ASSOC_CONF_EVENTID:
7944 ath11k_peer_assoc_conf_event(ab, skb);
7945 break;
7946 case WMI_UPDATE_STATS_EVENTID:
7947 ath11k_update_stats_event(ab, skb);
7948 break;
7949 case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID:
7950 ath11k_pdev_ctl_failsafe_check_event(ab, skb);
7951 break;
7952 case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID:
7953 ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb);
7954 break;
7955 case WMI_PDEV_TEMPERATURE_EVENTID:
7956 ath11k_wmi_pdev_temperature_event(ab, skb);
7957 break;
7958 case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID:
7959 ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb);
7960 break;
7961 case WMI_HOST_FILS_DISCOVERY_EVENTID:
7962 ath11k_fils_discovery_event(ab, skb);
7963 break;
7964 case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID:
7965 ath11k_probe_resp_tx_status_event(ab, skb);
7966 break;
7967 case WMI_OBSS_COLOR_COLLISION_DETECTION_EVENTID:
7968 ath11k_wmi_obss_color_collision_event(ab, skb);
7969 break;
7970 case WMI_TWT_ADD_DIALOG_EVENTID:
7971 ath11k_wmi_twt_add_dialog_event(ab, skb);
7972 break;
7973 /* add Unsupported events here */
7974 case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID:
7975 case WMI_PEER_OPER_MODE_CHANGE_EVENTID:
7976 case WMI_TWT_ENABLE_EVENTID:
7977 case WMI_TWT_DISABLE_EVENTID:
7978 case WMI_TWT_DEL_DIALOG_EVENTID:
7979 case WMI_TWT_PAUSE_DIALOG_EVENTID:
7980 case WMI_TWT_RESUME_DIALOG_EVENTID:
7981 case WMI_PDEV_DMA_RING_CFG_RSP_EVENTID:
7982 case WMI_PEER_CREATE_CONF_EVENTID:
7983 ath11k_dbg(ab, ATH11K_DBG_WMI,
7984 "ignoring unsupported event 0x%x\n", id);
7985 break;
7986 case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID:
7987 ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb);
7988 break;
7989 case WMI_VDEV_DELETE_RESP_EVENTID:
7990 ath11k_vdev_delete_resp_event(ab, skb);
7991 break;
7992 case WMI_WOW_WAKEUP_HOST_EVENTID:
7993 ath11k_wmi_event_wow_wakeup_host(ab, skb);
7994 break;
7995 case WMI_11D_NEW_COUNTRY_EVENTID:
7996 ath11k_reg_11d_new_cc_event(ab, skb);
7997 break;
7998 case WMI_RFKILL_STATE_CHANGE_EVENTID:
7999 ath11k_rfkill_state_change_event(ab, skb);
8000 break;
8001 case WMI_DIAG_EVENTID:
8002 ath11k_wmi_diag_event(ab, skb);
8003 break;
8004 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
8005 ath11k_wmi_gtk_offload_status_event(ab, skb);
8006 break;
8007 /* TODO: Add remaining events */
8008 default:
8009 ath11k_dbg(ab, ATH11K_DBG_WMI, "Unknown eventid: 0x%x\n", id);
8010 break;
8011 }
8012
8013 out:
8014 dev_kfree_skb(skb);
8015 }
8016
ath11k_connect_pdev_htc_service(struct ath11k_base * ab,u32 pdev_idx)8017 static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab,
8018 u32 pdev_idx)
8019 {
8020 int status;
8021 u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL,
8022 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1,
8023 ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 };
8024
8025 struct ath11k_htc_svc_conn_req conn_req;
8026 struct ath11k_htc_svc_conn_resp conn_resp;
8027
8028 memset(&conn_req, 0, sizeof(conn_req));
8029 memset(&conn_resp, 0, sizeof(conn_resp));
8030
8031 /* these fields are the same for all service endpoints */
8032 conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete;
8033 conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx;
8034 conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits;
8035
8036 /* connect to control service */
8037 conn_req.service_id = svc_id[pdev_idx];
8038
8039 status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp);
8040 if (status) {
8041 ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n",
8042 status);
8043 return status;
8044 }
8045
8046 ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid;
8047 ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid;
8048 ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len;
8049 init_waitqueue_head(&ab->wmi_ab.wmi[pdev_idx].tx_ce_desc_wq);
8050
8051 return 0;
8052 }
8053
8054 static int
ath11k_wmi_send_unit_test_cmd(struct ath11k * ar,struct wmi_unit_test_cmd ut_cmd,u32 * test_args)8055 ath11k_wmi_send_unit_test_cmd(struct ath11k *ar,
8056 struct wmi_unit_test_cmd ut_cmd,
8057 u32 *test_args)
8058 {
8059 struct ath11k_pdev_wmi *wmi = ar->wmi;
8060 struct wmi_unit_test_cmd *cmd;
8061 struct sk_buff *skb;
8062 struct wmi_tlv *tlv;
8063 void *ptr;
8064 u32 *ut_cmd_args;
8065 int buf_len, arg_len;
8066 int ret;
8067 int i;
8068
8069 arg_len = sizeof(u32) * ut_cmd.num_args;
8070 buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
8071
8072 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
8073 if (!skb)
8074 return -ENOMEM;
8075
8076 cmd = (struct wmi_unit_test_cmd *)skb->data;
8077 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) |
8078 FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE);
8079
8080 cmd->vdev_id = ut_cmd.vdev_id;
8081 cmd->module_id = ut_cmd.module_id;
8082 cmd->num_args = ut_cmd.num_args;
8083 cmd->diag_token = ut_cmd.diag_token;
8084
8085 ptr = skb->data + sizeof(ut_cmd);
8086
8087 tlv = ptr;
8088 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8089 FIELD_PREP(WMI_TLV_LEN, arg_len);
8090
8091 ptr += TLV_HDR_SIZE;
8092
8093 ut_cmd_args = ptr;
8094 for (i = 0; i < ut_cmd.num_args; i++)
8095 ut_cmd_args[i] = test_args[i];
8096
8097 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
8098
8099 if (ret) {
8100 ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n",
8101 ret);
8102 dev_kfree_skb(skb);
8103 }
8104
8105 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8106 "WMI unit test : module %d vdev %d n_args %d token %d\n",
8107 cmd->module_id, cmd->vdev_id, cmd->num_args,
8108 cmd->diag_token);
8109
8110 return ret;
8111 }
8112
ath11k_wmi_simulate_radar(struct ath11k * ar)8113 int ath11k_wmi_simulate_radar(struct ath11k *ar)
8114 {
8115 struct ath11k_vif *arvif;
8116 u32 dfs_args[DFS_MAX_TEST_ARGS];
8117 struct wmi_unit_test_cmd wmi_ut;
8118 bool arvif_found = false;
8119
8120 list_for_each_entry(arvif, &ar->arvifs, list) {
8121 if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) {
8122 arvif_found = true;
8123 break;
8124 }
8125 }
8126
8127 if (!arvif_found)
8128 return -EINVAL;
8129
8130 dfs_args[DFS_TEST_CMDID] = 0;
8131 dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
8132 /* Currently we could pass segment_id(b0 - b1), chirp(b2)
8133 * freq offset (b3 - b10) to unit test. For simulation
8134 * purpose this can be set to 0 which is valid.
8135 */
8136 dfs_args[DFS_TEST_RADAR_PARAM] = 0;
8137
8138 wmi_ut.vdev_id = arvif->vdev_id;
8139 wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
8140 wmi_ut.num_args = DFS_MAX_TEST_ARGS;
8141 wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
8142
8143 ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n");
8144
8145 return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
8146 }
8147
ath11k_wmi_fw_dbglog_cfg(struct ath11k * ar,u32 * module_id_bitmap,struct ath11k_fw_dbglog * dbglog)8148 int ath11k_wmi_fw_dbglog_cfg(struct ath11k *ar, u32 *module_id_bitmap,
8149 struct ath11k_fw_dbglog *dbglog)
8150 {
8151 struct ath11k_pdev_wmi *wmi = ar->wmi;
8152 struct wmi_debug_log_config_cmd_fixed_param *cmd;
8153 struct sk_buff *skb;
8154 struct wmi_tlv *tlv;
8155 int ret, len;
8156
8157 len = sizeof(*cmd) + TLV_HDR_SIZE + (MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8158 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8159 if (!skb)
8160 return -ENOMEM;
8161
8162 cmd = (struct wmi_debug_log_config_cmd_fixed_param *)skb->data;
8163 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DEBUG_LOG_CONFIG_CMD) |
8164 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8165 cmd->dbg_log_param = dbglog->param;
8166
8167 tlv = (struct wmi_tlv *)((u8 *)cmd + sizeof(*cmd));
8168 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8169 FIELD_PREP(WMI_TLV_LEN, MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8170
8171 switch (dbglog->param) {
8172 case WMI_DEBUG_LOG_PARAM_LOG_LEVEL:
8173 case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE:
8174 case WMI_DEBUG_LOG_PARAM_VDEV_DISABLE:
8175 case WMI_DEBUG_LOG_PARAM_VDEV_ENABLE_BITMAP:
8176 cmd->value = dbglog->value;
8177 break;
8178 case WMI_DEBUG_LOG_PARAM_MOD_ENABLE_BITMAP:
8179 case WMI_DEBUG_LOG_PARAM_WOW_MOD_ENABLE_BITMAP:
8180 cmd->value = dbglog->value;
8181 memcpy(tlv->value, module_id_bitmap,
8182 MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8183 /* clear current config to be used for next user config */
8184 memset(module_id_bitmap, 0,
8185 MAX_MODULE_ID_BITMAP_WORDS * sizeof(u32));
8186 break;
8187 default:
8188 dev_kfree_skb(skb);
8189 return -EINVAL;
8190 }
8191
8192 ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DBGLOG_CFG_CMDID);
8193 if (ret) {
8194 ath11k_warn(ar->ab,
8195 "failed to send WMI_DBGLOG_CFG_CMDID\n");
8196 dev_kfree_skb(skb);
8197 }
8198 return ret;
8199 }
8200
ath11k_wmi_connect(struct ath11k_base * ab)8201 int ath11k_wmi_connect(struct ath11k_base *ab)
8202 {
8203 u32 i;
8204 u8 wmi_ep_count;
8205
8206 wmi_ep_count = ab->htc.wmi_ep_count;
8207 if (wmi_ep_count > ab->hw_params.max_radios)
8208 return -1;
8209
8210 for (i = 0; i < wmi_ep_count; i++)
8211 ath11k_connect_pdev_htc_service(ab, i);
8212
8213 return 0;
8214 }
8215
ath11k_wmi_pdev_detach(struct ath11k_base * ab,u8 pdev_id)8216 static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id)
8217 {
8218 if (WARN_ON(pdev_id >= MAX_RADIOS))
8219 return;
8220
8221 /* TODO: Deinit any pdev specific wmi resource */
8222 }
8223
ath11k_wmi_pdev_attach(struct ath11k_base * ab,u8 pdev_id)8224 int ath11k_wmi_pdev_attach(struct ath11k_base *ab,
8225 u8 pdev_id)
8226 {
8227 struct ath11k_pdev_wmi *wmi_handle;
8228
8229 if (pdev_id >= ab->hw_params.max_radios)
8230 return -EINVAL;
8231
8232 wmi_handle = &ab->wmi_ab.wmi[pdev_id];
8233
8234 wmi_handle->wmi_ab = &ab->wmi_ab;
8235
8236 ab->wmi_ab.ab = ab;
8237 /* TODO: Init remaining resource specific to pdev */
8238
8239 return 0;
8240 }
8241
ath11k_wmi_attach(struct ath11k_base * ab)8242 int ath11k_wmi_attach(struct ath11k_base *ab)
8243 {
8244 int ret;
8245
8246 ret = ath11k_wmi_pdev_attach(ab, 0);
8247 if (ret)
8248 return ret;
8249
8250 ab->wmi_ab.ab = ab;
8251 ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX;
8252
8253 /* It's overwritten when service_ext_ready is handled */
8254 if (ab->hw_params.single_pdev_only && ab->hw_params.num_rxmda_per_pdev > 1)
8255 ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE;
8256
8257 /* TODO: Init remaining wmi soc resources required */
8258 init_completion(&ab->wmi_ab.service_ready);
8259 init_completion(&ab->wmi_ab.unified_ready);
8260
8261 return 0;
8262 }
8263
ath11k_wmi_detach(struct ath11k_base * ab)8264 void ath11k_wmi_detach(struct ath11k_base *ab)
8265 {
8266 int i;
8267
8268 /* TODO: Deinit wmi resource specific to SOC as required */
8269
8270 for (i = 0; i < ab->htc.wmi_ep_count; i++)
8271 ath11k_wmi_pdev_detach(ab, i);
8272
8273 ath11k_wmi_free_dbring_caps(ab);
8274 }
8275
ath11k_wmi_hw_data_filter_cmd(struct ath11k * ar,u32 vdev_id,u32 filter_bitmap,bool enable)8276 int ath11k_wmi_hw_data_filter_cmd(struct ath11k *ar, u32 vdev_id,
8277 u32 filter_bitmap, bool enable)
8278 {
8279 struct wmi_hw_data_filter_cmd *cmd;
8280 struct sk_buff *skb;
8281 int len;
8282
8283 len = sizeof(*cmd);
8284 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8285
8286 if (!skb)
8287 return -ENOMEM;
8288
8289 cmd = (struct wmi_hw_data_filter_cmd *)skb->data;
8290 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_HW_DATA_FILTER_CMD) |
8291 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8292
8293 cmd->vdev_id = vdev_id;
8294 cmd->enable = enable;
8295
8296 /* Set all modes in case of disable */
8297 if (cmd->enable)
8298 cmd->hw_filter_bitmap = filter_bitmap;
8299 else
8300 cmd->hw_filter_bitmap = ((u32)~0U);
8301
8302 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8303 "wmi hw data filter enable %d filter_bitmap 0x%x\n",
8304 enable, filter_bitmap);
8305
8306 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_HW_DATA_FILTER_CMDID);
8307 }
8308
ath11k_wmi_wow_host_wakeup_ind(struct ath11k * ar)8309 int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar)
8310 {
8311 struct wmi_wow_host_wakeup_ind *cmd;
8312 struct sk_buff *skb;
8313 size_t len;
8314
8315 len = sizeof(*cmd);
8316 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8317 if (!skb)
8318 return -ENOMEM;
8319
8320 cmd = (struct wmi_wow_host_wakeup_ind *)skb->data;
8321 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8322 WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) |
8323 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8324
8325 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow host wakeup ind\n");
8326
8327 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
8328 }
8329
ath11k_wmi_wow_enable(struct ath11k * ar)8330 int ath11k_wmi_wow_enable(struct ath11k *ar)
8331 {
8332 struct wmi_wow_enable_cmd *cmd;
8333 struct sk_buff *skb;
8334 int len;
8335
8336 len = sizeof(*cmd);
8337 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8338 if (!skb)
8339 return -ENOMEM;
8340
8341 cmd = (struct wmi_wow_enable_cmd *)skb->data;
8342 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) |
8343 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8344
8345 cmd->enable = 1;
8346 cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED;
8347 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow enable\n");
8348
8349 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID);
8350 }
8351
ath11k_wmi_scan_prob_req_oui(struct ath11k * ar,const u8 mac_addr[ETH_ALEN])8352 int ath11k_wmi_scan_prob_req_oui(struct ath11k *ar,
8353 const u8 mac_addr[ETH_ALEN])
8354 {
8355 struct sk_buff *skb;
8356 struct wmi_scan_prob_req_oui_cmd *cmd;
8357 u32 prob_req_oui;
8358 int len;
8359
8360 prob_req_oui = (((u32)mac_addr[0]) << 16) |
8361 (((u32)mac_addr[1]) << 8) | mac_addr[2];
8362
8363 len = sizeof(*cmd);
8364 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8365 if (!skb)
8366 return -ENOMEM;
8367
8368 cmd = (struct wmi_scan_prob_req_oui_cmd *)skb->data;
8369 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8370 WMI_TAG_SCAN_PROB_REQ_OUI_CMD) |
8371 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8372 cmd->prob_req_oui = prob_req_oui;
8373
8374 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi scan prob req oui %d\n",
8375 prob_req_oui);
8376
8377 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SCAN_PROB_REQ_OUI_CMDID);
8378 }
8379
ath11k_wmi_wow_add_wakeup_event(struct ath11k * ar,u32 vdev_id,enum wmi_wow_wakeup_event event,u32 enable)8380 int ath11k_wmi_wow_add_wakeup_event(struct ath11k *ar, u32 vdev_id,
8381 enum wmi_wow_wakeup_event event,
8382 u32 enable)
8383 {
8384 struct wmi_wow_add_del_event_cmd *cmd;
8385 struct sk_buff *skb;
8386 size_t len;
8387
8388 len = sizeof(*cmd);
8389 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8390 if (!skb)
8391 return -ENOMEM;
8392
8393 cmd = (struct wmi_wow_add_del_event_cmd *)skb->data;
8394 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ADD_DEL_EVT_CMD) |
8395 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8396
8397 cmd->vdev_id = vdev_id;
8398 cmd->is_add = enable;
8399 cmd->event_bitmap = (1 << event);
8400
8401 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow add wakeup event %s enable %d vdev_id %d\n",
8402 wow_wakeup_event(event), enable, vdev_id);
8403
8404 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
8405 }
8406
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)8407 int ath11k_wmi_wow_add_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id,
8408 const u8 *pattern, const u8 *mask,
8409 int pattern_len, int pattern_offset)
8410 {
8411 struct wmi_wow_add_pattern_cmd *cmd;
8412 struct wmi_wow_bitmap_pattern *bitmap;
8413 struct wmi_tlv *tlv;
8414 struct sk_buff *skb;
8415 u8 *ptr;
8416 size_t len;
8417
8418 len = sizeof(*cmd) +
8419 sizeof(*tlv) + /* array struct */
8420 sizeof(*bitmap) + /* bitmap */
8421 sizeof(*tlv) + /* empty ipv4 sync */
8422 sizeof(*tlv) + /* empty ipv6 sync */
8423 sizeof(*tlv) + /* empty magic */
8424 sizeof(*tlv) + /* empty info timeout */
8425 sizeof(*tlv) + sizeof(u32); /* ratelimit interval */
8426
8427 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8428 if (!skb)
8429 return -ENOMEM;
8430
8431 /* cmd */
8432 ptr = (u8 *)skb->data;
8433 cmd = (struct wmi_wow_add_pattern_cmd *)ptr;
8434 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8435 WMI_TAG_WOW_ADD_PATTERN_CMD) |
8436 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8437
8438 cmd->vdev_id = vdev_id;
8439 cmd->pattern_id = pattern_id;
8440 cmd->pattern_type = WOW_BITMAP_PATTERN;
8441
8442 ptr += sizeof(*cmd);
8443
8444 /* bitmap */
8445 tlv = (struct wmi_tlv *)ptr;
8446 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8447 WMI_TAG_ARRAY_STRUCT) |
8448 FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap));
8449
8450 ptr += sizeof(*tlv);
8451
8452 bitmap = (struct wmi_wow_bitmap_pattern *)ptr;
8453 bitmap->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8454 WMI_TAG_WOW_BITMAP_PATTERN_T) |
8455 FIELD_PREP(WMI_TLV_LEN, sizeof(*bitmap) - TLV_HDR_SIZE);
8456
8457 memcpy(bitmap->patternbuf, pattern, pattern_len);
8458 ath11k_ce_byte_swap(bitmap->patternbuf, roundup(pattern_len, 4));
8459 memcpy(bitmap->bitmaskbuf, mask, pattern_len);
8460 ath11k_ce_byte_swap(bitmap->bitmaskbuf, roundup(pattern_len, 4));
8461 bitmap->pattern_offset = pattern_offset;
8462 bitmap->pattern_len = pattern_len;
8463 bitmap->bitmask_len = pattern_len;
8464 bitmap->pattern_id = pattern_id;
8465
8466 ptr += sizeof(*bitmap);
8467
8468 /* ipv4 sync */
8469 tlv = (struct wmi_tlv *)ptr;
8470 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8471 WMI_TAG_ARRAY_STRUCT) |
8472 FIELD_PREP(WMI_TLV_LEN, 0);
8473
8474 ptr += sizeof(*tlv);
8475
8476 /* ipv6 sync */
8477 tlv = (struct wmi_tlv *)ptr;
8478 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8479 WMI_TAG_ARRAY_STRUCT) |
8480 FIELD_PREP(WMI_TLV_LEN, 0);
8481
8482 ptr += sizeof(*tlv);
8483
8484 /* magic */
8485 tlv = (struct wmi_tlv *)ptr;
8486 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8487 WMI_TAG_ARRAY_STRUCT) |
8488 FIELD_PREP(WMI_TLV_LEN, 0);
8489
8490 ptr += sizeof(*tlv);
8491
8492 /* pattern info timeout */
8493 tlv = (struct wmi_tlv *)ptr;
8494 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8495 WMI_TAG_ARRAY_UINT32) |
8496 FIELD_PREP(WMI_TLV_LEN, 0);
8497
8498 ptr += sizeof(*tlv);
8499
8500 /* ratelimit interval */
8501 tlv = (struct wmi_tlv *)ptr;
8502 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8503 WMI_TAG_ARRAY_UINT32) |
8504 FIELD_PREP(WMI_TLV_LEN, sizeof(u32));
8505
8506 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow add pattern vdev_id %d pattern_id %d pattern_offset %d\n",
8507 vdev_id, pattern_id, pattern_offset);
8508
8509 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ADD_WAKE_PATTERN_CMDID);
8510 }
8511
ath11k_wmi_wow_del_pattern(struct ath11k * ar,u32 vdev_id,u32 pattern_id)8512 int ath11k_wmi_wow_del_pattern(struct ath11k *ar, u32 vdev_id, u32 pattern_id)
8513 {
8514 struct wmi_wow_del_pattern_cmd *cmd;
8515 struct sk_buff *skb;
8516 size_t len;
8517
8518 len = sizeof(*cmd);
8519 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8520 if (!skb)
8521 return -ENOMEM;
8522
8523 cmd = (struct wmi_wow_del_pattern_cmd *)skb->data;
8524 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8525 WMI_TAG_WOW_DEL_PATTERN_CMD) |
8526 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8527
8528 cmd->vdev_id = vdev_id;
8529 cmd->pattern_id = pattern_id;
8530 cmd->pattern_type = WOW_BITMAP_PATTERN;
8531
8532 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow del pattern vdev_id %d pattern_id %d\n",
8533 vdev_id, pattern_id);
8534
8535 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_DEL_WAKE_PATTERN_CMDID);
8536 }
8537
8538 static struct sk_buff *
ath11k_wmi_op_gen_config_pno_start(struct ath11k * ar,u32 vdev_id,struct wmi_pno_scan_req * pno)8539 ath11k_wmi_op_gen_config_pno_start(struct ath11k *ar,
8540 u32 vdev_id,
8541 struct wmi_pno_scan_req *pno)
8542 {
8543 struct nlo_configured_parameters *nlo_list;
8544 struct wmi_wow_nlo_config_cmd *cmd;
8545 struct wmi_tlv *tlv;
8546 struct sk_buff *skb;
8547 u32 *channel_list;
8548 size_t len, nlo_list_len, channel_list_len;
8549 u8 *ptr;
8550 u32 i;
8551
8552 len = sizeof(*cmd) +
8553 sizeof(*tlv) +
8554 /* TLV place holder for array of structures
8555 * nlo_configured_parameters(nlo_list)
8556 */
8557 sizeof(*tlv);
8558 /* TLV place holder for array of uint32 channel_list */
8559
8560 channel_list_len = sizeof(u32) * pno->a_networks[0].channel_count;
8561 len += channel_list_len;
8562
8563 nlo_list_len = sizeof(*nlo_list) * pno->uc_networks_count;
8564 len += nlo_list_len;
8565
8566 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8567 if (!skb)
8568 return ERR_PTR(-ENOMEM);
8569
8570 ptr = (u8 *)skb->data;
8571 cmd = (struct wmi_wow_nlo_config_cmd *)ptr;
8572 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
8573 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8574
8575 cmd->vdev_id = pno->vdev_id;
8576 cmd->flags = WMI_NLO_CONFIG_START | WMI_NLO_CONFIG_SSID_HIDE_EN;
8577
8578 /* current FW does not support min-max range for dwell time */
8579 cmd->active_dwell_time = pno->active_max_time;
8580 cmd->passive_dwell_time = pno->passive_max_time;
8581
8582 if (pno->do_passive_scan)
8583 cmd->flags |= WMI_NLO_CONFIG_SCAN_PASSIVE;
8584
8585 cmd->fast_scan_period = pno->fast_scan_period;
8586 cmd->slow_scan_period = pno->slow_scan_period;
8587 cmd->fast_scan_max_cycles = pno->fast_scan_max_cycles;
8588 cmd->delay_start_time = pno->delay_start_time;
8589
8590 if (pno->enable_pno_scan_randomization) {
8591 cmd->flags |= WMI_NLO_CONFIG_SPOOFED_MAC_IN_PROBE_REQ |
8592 WMI_NLO_CONFIG_RANDOM_SEQ_NO_IN_PROBE_REQ;
8593 ether_addr_copy(cmd->mac_addr.addr, pno->mac_addr);
8594 ether_addr_copy(cmd->mac_mask.addr, pno->mac_addr_mask);
8595 ath11k_ce_byte_swap(cmd->mac_addr.addr, 8);
8596 ath11k_ce_byte_swap(cmd->mac_mask.addr, 8);
8597 }
8598
8599 ptr += sizeof(*cmd);
8600
8601 /* nlo_configured_parameters(nlo_list) */
8602 cmd->no_of_ssids = pno->uc_networks_count;
8603 tlv = (struct wmi_tlv *)ptr;
8604 tlv->header = FIELD_PREP(WMI_TLV_TAG,
8605 WMI_TAG_ARRAY_STRUCT) |
8606 FIELD_PREP(WMI_TLV_LEN, nlo_list_len);
8607
8608 ptr += sizeof(*tlv);
8609 nlo_list = (struct nlo_configured_parameters *)ptr;
8610 for (i = 0; i < cmd->no_of_ssids; i++) {
8611 tlv = (struct wmi_tlv *)(&nlo_list[i].tlv_header);
8612 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8613 FIELD_PREP(WMI_TLV_LEN, sizeof(*nlo_list) - sizeof(*tlv));
8614
8615 nlo_list[i].ssid.valid = true;
8616 nlo_list[i].ssid.ssid.ssid_len = pno->a_networks[i].ssid.ssid_len;
8617 memcpy(nlo_list[i].ssid.ssid.ssid,
8618 pno->a_networks[i].ssid.ssid,
8619 nlo_list[i].ssid.ssid.ssid_len);
8620 ath11k_ce_byte_swap(nlo_list[i].ssid.ssid.ssid,
8621 roundup(nlo_list[i].ssid.ssid.ssid_len, 4));
8622
8623 if (pno->a_networks[i].rssi_threshold &&
8624 pno->a_networks[i].rssi_threshold > -300) {
8625 nlo_list[i].rssi_cond.valid = true;
8626 nlo_list[i].rssi_cond.rssi =
8627 pno->a_networks[i].rssi_threshold;
8628 }
8629
8630 nlo_list[i].bcast_nw_type.valid = true;
8631 nlo_list[i].bcast_nw_type.bcast_nw_type =
8632 pno->a_networks[i].bcast_nw_type;
8633 }
8634
8635 ptr += nlo_list_len;
8636 cmd->num_of_channels = pno->a_networks[0].channel_count;
8637 tlv = (struct wmi_tlv *)ptr;
8638 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) |
8639 FIELD_PREP(WMI_TLV_LEN, channel_list_len);
8640 ptr += sizeof(*tlv);
8641 channel_list = (u32 *)ptr;
8642 for (i = 0; i < cmd->num_of_channels; i++)
8643 channel_list[i] = pno->a_networks[0].channels[i];
8644
8645 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv start pno config vdev_id %d\n",
8646 vdev_id);
8647
8648 return skb;
8649 }
8650
ath11k_wmi_op_gen_config_pno_stop(struct ath11k * ar,u32 vdev_id)8651 static struct sk_buff *ath11k_wmi_op_gen_config_pno_stop(struct ath11k *ar,
8652 u32 vdev_id)
8653 {
8654 struct wmi_wow_nlo_config_cmd *cmd;
8655 struct sk_buff *skb;
8656 size_t len;
8657
8658 len = sizeof(*cmd);
8659 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8660 if (!skb)
8661 return ERR_PTR(-ENOMEM);
8662
8663 cmd = (struct wmi_wow_nlo_config_cmd *)skb->data;
8664 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NLO_CONFIG_CMD) |
8665 FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE);
8666
8667 cmd->vdev_id = vdev_id;
8668 cmd->flags = WMI_NLO_CONFIG_STOP;
8669
8670 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8671 "wmi tlv stop pno config vdev_id %d\n", vdev_id);
8672 return skb;
8673 }
8674
ath11k_wmi_wow_config_pno(struct ath11k * ar,u32 vdev_id,struct wmi_pno_scan_req * pno_scan)8675 int ath11k_wmi_wow_config_pno(struct ath11k *ar, u32 vdev_id,
8676 struct wmi_pno_scan_req *pno_scan)
8677 {
8678 struct sk_buff *skb;
8679
8680 if (pno_scan->enable)
8681 skb = ath11k_wmi_op_gen_config_pno_start(ar, vdev_id, pno_scan);
8682 else
8683 skb = ath11k_wmi_op_gen_config_pno_stop(ar, vdev_id);
8684
8685 if (IS_ERR_OR_NULL(skb))
8686 return -ENOMEM;
8687
8688 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
8689 }
8690
ath11k_wmi_fill_ns_offload(struct ath11k * ar,struct ath11k_arp_ns_offload * offload,u8 ** ptr,bool enable,bool ext)8691 static void ath11k_wmi_fill_ns_offload(struct ath11k *ar,
8692 struct ath11k_arp_ns_offload *offload,
8693 u8 **ptr,
8694 bool enable,
8695 bool ext)
8696 {
8697 struct wmi_ns_offload_tuple *ns;
8698 struct wmi_tlv *tlv;
8699 u8 *buf_ptr = *ptr;
8700 u32 ns_cnt, ns_ext_tuples;
8701 int i, max_offloads;
8702
8703 ns_cnt = offload->ipv6_count;
8704
8705 tlv = (struct wmi_tlv *)buf_ptr;
8706
8707 if (ext) {
8708 ns_ext_tuples = offload->ipv6_count - WMI_MAX_NS_OFFLOADS;
8709 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8710 FIELD_PREP(WMI_TLV_LEN, ns_ext_tuples * sizeof(*ns));
8711 i = WMI_MAX_NS_OFFLOADS;
8712 max_offloads = offload->ipv6_count;
8713 } else {
8714 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8715 FIELD_PREP(WMI_TLV_LEN, WMI_MAX_NS_OFFLOADS * sizeof(*ns));
8716 i = 0;
8717 max_offloads = WMI_MAX_NS_OFFLOADS;
8718 }
8719
8720 buf_ptr += sizeof(*tlv);
8721
8722 for (; i < max_offloads; i++) {
8723 ns = (struct wmi_ns_offload_tuple *)buf_ptr;
8724 ns->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_NS_OFFLOAD_TUPLE) |
8725 FIELD_PREP(WMI_TLV_LEN, sizeof(*ns) - TLV_HDR_SIZE);
8726
8727 if (enable) {
8728 if (i < ns_cnt)
8729 ns->flags |= WMI_NSOL_FLAGS_VALID;
8730
8731 memcpy(ns->target_ipaddr[0], offload->ipv6_addr[i], 16);
8732 memcpy(ns->solicitation_ipaddr, offload->self_ipv6_addr[i], 16);
8733 ath11k_ce_byte_swap(ns->target_ipaddr[0], 16);
8734 ath11k_ce_byte_swap(ns->solicitation_ipaddr, 16);
8735
8736 if (offload->ipv6_type[i])
8737 ns->flags |= WMI_NSOL_FLAGS_IS_IPV6_ANYCAST;
8738
8739 memcpy(ns->target_mac.addr, offload->mac_addr, ETH_ALEN);
8740 ath11k_ce_byte_swap(ns->target_mac.addr, 8);
8741
8742 if (ns->target_mac.word0 != 0 ||
8743 ns->target_mac.word1 != 0) {
8744 ns->flags |= WMI_NSOL_FLAGS_MAC_VALID;
8745 }
8746
8747 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
8748 "wmi index %d ns_solicited %pI6 target %pI6",
8749 i, ns->solicitation_ipaddr,
8750 ns->target_ipaddr[0]);
8751 }
8752
8753 buf_ptr += sizeof(*ns);
8754 }
8755
8756 *ptr = buf_ptr;
8757 }
8758
ath11k_wmi_fill_arp_offload(struct ath11k * ar,struct ath11k_arp_ns_offload * offload,u8 ** ptr,bool enable)8759 static void ath11k_wmi_fill_arp_offload(struct ath11k *ar,
8760 struct ath11k_arp_ns_offload *offload,
8761 u8 **ptr,
8762 bool enable)
8763 {
8764 struct wmi_arp_offload_tuple *arp;
8765 struct wmi_tlv *tlv;
8766 u8 *buf_ptr = *ptr;
8767 int i;
8768
8769 /* fill arp tuple */
8770 tlv = (struct wmi_tlv *)buf_ptr;
8771 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) |
8772 FIELD_PREP(WMI_TLV_LEN, WMI_MAX_ARP_OFFLOADS * sizeof(*arp));
8773 buf_ptr += sizeof(*tlv);
8774
8775 for (i = 0; i < WMI_MAX_ARP_OFFLOADS; i++) {
8776 arp = (struct wmi_arp_offload_tuple *)buf_ptr;
8777 arp->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARP_OFFLOAD_TUPLE) |
8778 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
8779
8780 if (enable && i < offload->ipv4_count) {
8781 /* Copy the target ip addr and flags */
8782 arp->flags = WMI_ARPOL_FLAGS_VALID;
8783 memcpy(arp->target_ipaddr, offload->ipv4_addr[i], 4);
8784 ath11k_ce_byte_swap(arp->target_ipaddr, 4);
8785
8786 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi arp offload address %pI4",
8787 arp->target_ipaddr);
8788 }
8789
8790 buf_ptr += sizeof(*arp);
8791 }
8792
8793 *ptr = buf_ptr;
8794 }
8795
ath11k_wmi_arp_ns_offload(struct ath11k * ar,struct ath11k_vif * arvif,bool enable)8796 int ath11k_wmi_arp_ns_offload(struct ath11k *ar,
8797 struct ath11k_vif *arvif, bool enable)
8798 {
8799 struct ath11k_arp_ns_offload *offload;
8800 struct wmi_set_arp_ns_offload_cmd *cmd;
8801 struct wmi_tlv *tlv;
8802 struct sk_buff *skb;
8803 u8 *buf_ptr;
8804 size_t len;
8805 u8 ns_cnt, ns_ext_tuples = 0;
8806
8807 offload = &arvif->arp_ns_offload;
8808 ns_cnt = offload->ipv6_count;
8809
8810 len = sizeof(*cmd) +
8811 sizeof(*tlv) +
8812 WMI_MAX_NS_OFFLOADS * sizeof(struct wmi_ns_offload_tuple) +
8813 sizeof(*tlv) +
8814 WMI_MAX_ARP_OFFLOADS * sizeof(struct wmi_arp_offload_tuple);
8815
8816 if (ns_cnt > WMI_MAX_NS_OFFLOADS) {
8817 ns_ext_tuples = ns_cnt - WMI_MAX_NS_OFFLOADS;
8818 len += sizeof(*tlv) +
8819 ns_ext_tuples * sizeof(struct wmi_ns_offload_tuple);
8820 }
8821
8822 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8823 if (!skb)
8824 return -ENOMEM;
8825
8826 buf_ptr = skb->data;
8827 cmd = (struct wmi_set_arp_ns_offload_cmd *)buf_ptr;
8828 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8829 WMI_TAG_SET_ARP_NS_OFFLOAD_CMD) |
8830 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8831
8832 cmd->flags = 0;
8833 cmd->vdev_id = arvif->vdev_id;
8834 cmd->num_ns_ext_tuples = ns_ext_tuples;
8835
8836 buf_ptr += sizeof(*cmd);
8837
8838 ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 0);
8839 ath11k_wmi_fill_arp_offload(ar, offload, &buf_ptr, enable);
8840
8841 if (ns_ext_tuples)
8842 ath11k_wmi_fill_ns_offload(ar, offload, &buf_ptr, enable, 1);
8843
8844 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_SET_ARP_NS_OFFLOAD_CMDID);
8845 }
8846
ath11k_wmi_gtk_rekey_offload(struct ath11k * ar,struct ath11k_vif * arvif,bool enable)8847 int ath11k_wmi_gtk_rekey_offload(struct ath11k *ar,
8848 struct ath11k_vif *arvif, bool enable)
8849 {
8850 struct wmi_gtk_rekey_offload_cmd *cmd;
8851 struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
8852 int len;
8853 struct sk_buff *skb;
8854 __le64 replay_ctr;
8855
8856 len = sizeof(*cmd);
8857 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8858 if (!skb)
8859 return -ENOMEM;
8860
8861 cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
8862 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
8863 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8864
8865 cmd->vdev_id = arvif->vdev_id;
8866
8867 if (enable) {
8868 cmd->flags = GTK_OFFLOAD_ENABLE_OPCODE;
8869
8870 /* the length in rekey_data and cmd is equal */
8871 memcpy(cmd->kck, rekey_data->kck, sizeof(cmd->kck));
8872 ath11k_ce_byte_swap(cmd->kck, GTK_OFFLOAD_KEK_BYTES);
8873 memcpy(cmd->kek, rekey_data->kek, sizeof(cmd->kek));
8874 ath11k_ce_byte_swap(cmd->kek, GTK_OFFLOAD_KEK_BYTES);
8875
8876 replay_ctr = cpu_to_le64(rekey_data->replay_ctr);
8877 memcpy(cmd->replay_ctr, &replay_ctr,
8878 sizeof(replay_ctr));
8879 ath11k_ce_byte_swap(cmd->replay_ctr, GTK_REPLAY_COUNTER_BYTES);
8880 } else {
8881 cmd->flags = GTK_OFFLOAD_DISABLE_OPCODE;
8882 }
8883
8884 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "offload gtk rekey vdev: %d %d\n",
8885 arvif->vdev_id, enable);
8886 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
8887 }
8888
ath11k_wmi_gtk_rekey_getinfo(struct ath11k * ar,struct ath11k_vif * arvif)8889 int ath11k_wmi_gtk_rekey_getinfo(struct ath11k *ar,
8890 struct ath11k_vif *arvif)
8891 {
8892 struct wmi_gtk_rekey_offload_cmd *cmd;
8893 int len;
8894 struct sk_buff *skb;
8895
8896 len = sizeof(*cmd);
8897 skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len);
8898 if (!skb)
8899 return -ENOMEM;
8900
8901 cmd = (struct wmi_gtk_rekey_offload_cmd *)skb->data;
8902 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_GTK_OFFLOAD_CMD) |
8903 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8904
8905 cmd->vdev_id = arvif->vdev_id;
8906 cmd->flags = GTK_OFFLOAD_REQUEST_STATUS_OPCODE;
8907
8908 ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "get gtk rekey vdev_id: %d\n",
8909 arvif->vdev_id);
8910 return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_GTK_OFFLOAD_CMDID);
8911 }
8912
ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k * ar,const u8 * sar_val)8913 int ath11k_wmi_pdev_set_bios_sar_table_param(struct ath11k *ar, const u8 *sar_val)
8914 { struct ath11k_pdev_wmi *wmi = ar->wmi;
8915 struct wmi_pdev_set_sar_table_cmd *cmd;
8916 struct wmi_tlv *tlv;
8917 struct sk_buff *skb;
8918 u8 *buf_ptr;
8919 u32 len, sar_len_aligned, rsvd_len_aligned;
8920
8921 sar_len_aligned = roundup(BIOS_SAR_TABLE_LEN, sizeof(u32));
8922 rsvd_len_aligned = roundup(BIOS_SAR_RSVD1_LEN, sizeof(u32));
8923 len = sizeof(*cmd) +
8924 TLV_HDR_SIZE + sar_len_aligned +
8925 TLV_HDR_SIZE + rsvd_len_aligned;
8926
8927 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8928 if (!skb)
8929 return -ENOMEM;
8930
8931 cmd = (struct wmi_pdev_set_sar_table_cmd *)skb->data;
8932 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_SAR_TABLE_CMD) |
8933 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8934 cmd->pdev_id = ar->pdev->pdev_id;
8935 cmd->sar_len = BIOS_SAR_TABLE_LEN;
8936 cmd->rsvd_len = BIOS_SAR_RSVD1_LEN;
8937
8938 buf_ptr = skb->data + sizeof(*cmd);
8939 tlv = (struct wmi_tlv *)buf_ptr;
8940 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8941 FIELD_PREP(WMI_TLV_LEN, sar_len_aligned);
8942 buf_ptr += TLV_HDR_SIZE;
8943 memcpy(buf_ptr, sar_val, BIOS_SAR_TABLE_LEN);
8944
8945 buf_ptr += sar_len_aligned;
8946 tlv = (struct wmi_tlv *)buf_ptr;
8947 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8948 FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
8949
8950 return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_SAR_TABLE_CMDID);
8951 }
8952
ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k * ar)8953 int ath11k_wmi_pdev_set_bios_geo_table_param(struct ath11k *ar)
8954 {
8955 struct ath11k_pdev_wmi *wmi = ar->wmi;
8956 struct wmi_pdev_set_geo_table_cmd *cmd;
8957 struct wmi_tlv *tlv;
8958 struct sk_buff *skb;
8959 u8 *buf_ptr;
8960 u32 len, rsvd_len_aligned;
8961
8962 rsvd_len_aligned = roundup(BIOS_SAR_RSVD2_LEN, sizeof(u32));
8963 len = sizeof(*cmd) + TLV_HDR_SIZE + rsvd_len_aligned;
8964
8965 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8966 if (!skb)
8967 return -ENOMEM;
8968
8969 cmd = (struct wmi_pdev_set_geo_table_cmd *)skb->data;
8970 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_BIOS_GEO_TABLE_CMD) |
8971 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
8972 cmd->pdev_id = ar->pdev->pdev_id;
8973 cmd->rsvd_len = BIOS_SAR_RSVD2_LEN;
8974
8975 buf_ptr = skb->data + sizeof(*cmd);
8976 tlv = (struct wmi_tlv *)buf_ptr;
8977 tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) |
8978 FIELD_PREP(WMI_TLV_LEN, rsvd_len_aligned);
8979
8980 return ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_BIOS_GEO_TABLE_CMDID);
8981 }
8982
ath11k_wmi_sta_keepalive(struct ath11k * ar,const struct wmi_sta_keepalive_arg * arg)8983 int ath11k_wmi_sta_keepalive(struct ath11k *ar,
8984 const struct wmi_sta_keepalive_arg *arg)
8985 {
8986 struct ath11k_pdev_wmi *wmi = ar->wmi;
8987 struct wmi_sta_keepalive_cmd *cmd;
8988 struct wmi_sta_keepalive_arp_resp *arp;
8989 struct sk_buff *skb;
8990 size_t len;
8991
8992 len = sizeof(*cmd) + sizeof(*arp);
8993 skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len);
8994 if (!skb)
8995 return -ENOMEM;
8996
8997 cmd = (struct wmi_sta_keepalive_cmd *)skb->data;
8998 cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG,
8999 WMI_TAG_STA_KEEPALIVE_CMD) |
9000 FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE);
9001 cmd->vdev_id = arg->vdev_id;
9002 cmd->enabled = arg->enabled;
9003 cmd->interval = arg->interval;
9004 cmd->method = arg->method;
9005
9006 if (arg->method == WMI_STA_KEEPALIVE_METHOD_UNSOLICITED_ARP_RESPONSE ||
9007 arg->method == WMI_STA_KEEPALIVE_METHOD_GRATUITOUS_ARP_REQUEST) {
9008 arp = (struct wmi_sta_keepalive_arp_resp *)(cmd + 1);
9009 arp->tlv_header = FIELD_PREP(WMI_TLV_TAG,
9010 WMI_TAG_STA_KEEPALVE_ARP_RESPONSE) |
9011 FIELD_PREP(WMI_TLV_LEN, sizeof(*arp) - TLV_HDR_SIZE);
9012 arp->src_ip4_addr = arg->src_ip4_addr;
9013 arp->dest_ip4_addr = arg->dest_ip4_addr;
9014 ether_addr_copy(arp->dest_mac_addr.addr, arg->dest_mac_addr);
9015 }
9016
9017 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
9018 "wmi sta keepalive vdev %d enabled %d method %d interval %d\n",
9019 arg->vdev_id, arg->enabled, arg->method, arg->interval);
9020
9021 return ath11k_wmi_cmd_send(wmi, skb, WMI_STA_KEEPALIVE_CMDID);
9022 }
9023