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