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