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