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