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