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