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