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