1d5c65159SKalle Valo // SPDX-License-Identifier: BSD-3-Clause-Clear 2d5c65159SKalle Valo /* 3d5c65159SKalle Valo * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 4d5c65159SKalle Valo */ 5d5c65159SKalle Valo #include <linux/skbuff.h> 6d5c65159SKalle Valo #include <linux/ctype.h> 7d5c65159SKalle Valo #include <net/mac80211.h> 8d5c65159SKalle Valo #include <net/cfg80211.h> 9d5c65159SKalle Valo #include <linux/completion.h> 10d5c65159SKalle Valo #include <linux/if_ether.h> 11d5c65159SKalle Valo #include <linux/types.h> 12d5c65159SKalle Valo #include <linux/pci.h> 13d5c65159SKalle Valo #include <linux/uuid.h> 14d5c65159SKalle Valo #include <linux/time.h> 15d5c65159SKalle Valo #include <linux/of.h> 16d5c65159SKalle Valo #include "core.h" 17d5c65159SKalle Valo #include "debug.h" 18d5c65159SKalle Valo #include "mac.h" 19d5c65159SKalle Valo #include "hw.h" 20d5c65159SKalle Valo #include "peer.h" 21d5c65159SKalle Valo 22d5c65159SKalle Valo struct wmi_tlv_policy { 23d5c65159SKalle Valo size_t min_len; 24d5c65159SKalle Valo }; 25d5c65159SKalle Valo 26d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse { 27d5c65159SKalle Valo bool wmi_svc_bitmap_done; 28d5c65159SKalle Valo }; 29d5c65159SKalle Valo 30bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse { 31bd647855SKarthikeyan Periyasamy struct wmi_dma_ring_capabilities *dma_ring_caps; 32bd647855SKarthikeyan Periyasamy u32 n_dma_ring_caps; 33bd647855SKarthikeyan Periyasamy }; 34bd647855SKarthikeyan Periyasamy 35d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse { 36d5c65159SKalle Valo struct ath11k_service_ext_param param; 37d5c65159SKalle Valo struct wmi_soc_mac_phy_hw_mode_caps *hw_caps; 38d5c65159SKalle Valo struct wmi_hw_mode_capabilities *hw_mode_caps; 39d5c65159SKalle Valo u32 n_hw_mode_caps; 40d5c65159SKalle Valo u32 tot_phy_id; 41d5c65159SKalle Valo struct wmi_hw_mode_capabilities pref_hw_mode_caps; 42d5c65159SKalle Valo struct wmi_mac_phy_capabilities *mac_phy_caps; 43d5c65159SKalle Valo u32 n_mac_phy_caps; 44d5c65159SKalle Valo struct wmi_soc_hal_reg_capabilities *soc_hal_reg_caps; 45d5c65159SKalle Valo struct wmi_hal_reg_capabilities_ext *ext_hal_reg_caps; 46d5c65159SKalle Valo u32 n_ext_hal_reg_caps; 47bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse dma_caps_parse; 48d5c65159SKalle Valo bool hw_mode_done; 49d5c65159SKalle Valo bool mac_phy_done; 50d5c65159SKalle Valo bool ext_hal_reg_done; 51bd647855SKarthikeyan Periyasamy bool mac_phy_chainmask_combo_done; 52bd647855SKarthikeyan Periyasamy bool mac_phy_chainmask_cap_done; 53bd647855SKarthikeyan Periyasamy bool oem_dma_ring_cap_done; 54bd647855SKarthikeyan Periyasamy bool dma_ring_cap_done; 55bd647855SKarthikeyan Periyasamy }; 56bd647855SKarthikeyan Periyasamy 57bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse { 58bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse dma_caps_parse; 59bd647855SKarthikeyan Periyasamy bool dma_ring_cap_done; 60d5c65159SKalle Valo }; 61d5c65159SKalle Valo 62d5c65159SKalle Valo struct wmi_tlv_rdy_parse { 63d5c65159SKalle Valo u32 num_extra_mac_addr; 64d5c65159SKalle Valo }; 65d5c65159SKalle Valo 669d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse { 679d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_dma_buf_release_fixed_param fixed; 689d11b7bfSKarthikeyan Periyasamy struct wmi_dma_buf_release_entry *buf_entry; 699d11b7bfSKarthikeyan Periyasamy struct wmi_dma_buf_release_meta_data *meta_data; 709d11b7bfSKarthikeyan Periyasamy u32 num_buf_entry; 719d11b7bfSKarthikeyan Periyasamy u32 num_meta; 729d11b7bfSKarthikeyan Periyasamy bool buf_entry_done; 739d11b7bfSKarthikeyan Periyasamy bool meta_data_done; 749d11b7bfSKarthikeyan Periyasamy }; 759d11b7bfSKarthikeyan Periyasamy 76d5c65159SKalle Valo static const struct wmi_tlv_policy wmi_tlv_policies[] = { 77d5c65159SKalle Valo [WMI_TAG_ARRAY_BYTE] 78d5c65159SKalle Valo = { .min_len = 0 }, 79d5c65159SKalle Valo [WMI_TAG_ARRAY_UINT32] 80d5c65159SKalle Valo = { .min_len = 0 }, 81d5c65159SKalle Valo [WMI_TAG_SERVICE_READY_EVENT] 82d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_service_ready_event) }, 83d5c65159SKalle Valo [WMI_TAG_SERVICE_READY_EXT_EVENT] 84d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_service_ready_ext_event) }, 85d5c65159SKalle Valo [WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS] 86d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_soc_mac_phy_hw_mode_caps) }, 87d5c65159SKalle Valo [WMI_TAG_SOC_HAL_REG_CAPABILITIES] 88d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_soc_hal_reg_capabilities) }, 89d5c65159SKalle Valo [WMI_TAG_VDEV_START_RESPONSE_EVENT] 90d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_vdev_start_resp_event) }, 91d5c65159SKalle Valo [WMI_TAG_PEER_DELETE_RESP_EVENT] 92d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_peer_delete_resp_event) }, 93d5c65159SKalle Valo [WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT] 94d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_bcn_tx_status_event) }, 95d5c65159SKalle Valo [WMI_TAG_VDEV_STOPPED_EVENT] 96d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_vdev_stopped_event) }, 97d5c65159SKalle Valo [WMI_TAG_REG_CHAN_LIST_CC_EVENT] 98d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_reg_chan_list_cc_event) }, 99d5c65159SKalle Valo [WMI_TAG_MGMT_RX_HDR] 100d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_mgmt_rx_hdr) }, 101d5c65159SKalle Valo [WMI_TAG_MGMT_TX_COMPL_EVENT] 102d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_mgmt_tx_compl_event) }, 103d5c65159SKalle Valo [WMI_TAG_SCAN_EVENT] 104d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_scan_event) }, 105d5c65159SKalle Valo [WMI_TAG_PEER_STA_KICKOUT_EVENT] 106d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_peer_sta_kickout_event) }, 107d5c65159SKalle Valo [WMI_TAG_ROAM_EVENT] 108d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_roam_event) }, 109d5c65159SKalle Valo [WMI_TAG_CHAN_INFO_EVENT] 110d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_chan_info_event) }, 111d5c65159SKalle Valo [WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT] 112d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_pdev_bss_chan_info_event) }, 113d5c65159SKalle Valo [WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT] 114d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_vdev_install_key_compl_event) }, 11521c1b063SMaharaja Kennadyrajan [WMI_TAG_READY_EVENT] = { 11621c1b063SMaharaja Kennadyrajan .min_len = sizeof(struct wmi_ready_event_min) }, 117d5c65159SKalle Valo [WMI_TAG_SERVICE_AVAILABLE_EVENT] 118d5c65159SKalle Valo = {.min_len = sizeof(struct wmi_service_available_event) }, 119d5c65159SKalle Valo [WMI_TAG_PEER_ASSOC_CONF_EVENT] 120d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_peer_assoc_conf_event) }, 121d5c65159SKalle Valo [WMI_TAG_STATS_EVENT] 122d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_stats_event) }, 123d5c65159SKalle Valo [WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT] 124d5c65159SKalle Valo = { .min_len = sizeof(struct wmi_pdev_ctl_failsafe_chk_event) }, 125047679e3SAloka Dixit [WMI_TAG_HOST_SWFDA_EVENT] = { 126047679e3SAloka Dixit .min_len = sizeof(struct wmi_fils_discovery_event) }, 127047679e3SAloka Dixit [WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT] = { 128047679e3SAloka Dixit .min_len = sizeof(struct wmi_probe_resp_tx_status_event) }, 1293cbbdfbeSRitesh Singh [WMI_TAG_VDEV_DELETE_RESP_EVENT] = { 1303cbbdfbeSRitesh Singh .min_len = sizeof(struct wmi_vdev_delete_resp_event) }, 131d5c65159SKalle Valo }; 132d5c65159SKalle Valo 133d5c65159SKalle Valo #define PRIMAP(_hw_mode_) \ 134d5c65159SKalle Valo [_hw_mode_] = _hw_mode_##_PRI 135d5c65159SKalle Valo 136d5c65159SKalle Valo static const int ath11k_hw_mode_pri_map[] = { 137d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_SINGLE), 138d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_DBS), 139d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_SBS_PASSIVE), 140d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_SBS), 141d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_DBS_SBS), 142d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_DBS_OR_SBS), 143d5c65159SKalle Valo /* keep last */ 144d5c65159SKalle Valo PRIMAP(WMI_HOST_HW_MODE_MAX), 145d5c65159SKalle Valo }; 146d5c65159SKalle Valo 147d5c65159SKalle Valo static int 148d5c65159SKalle Valo ath11k_wmi_tlv_iter(struct ath11k_base *ab, const void *ptr, size_t len, 149d5c65159SKalle Valo int (*iter)(struct ath11k_base *ab, u16 tag, u16 len, 150d5c65159SKalle Valo const void *ptr, void *data), 151d5c65159SKalle Valo void *data) 152d5c65159SKalle Valo { 153d5c65159SKalle Valo const void *begin = ptr; 154d5c65159SKalle Valo const struct wmi_tlv *tlv; 155d5c65159SKalle Valo u16 tlv_tag, tlv_len; 156d5c65159SKalle Valo int ret; 157d5c65159SKalle Valo 158d5c65159SKalle Valo while (len > 0) { 159d5c65159SKalle Valo if (len < sizeof(*tlv)) { 160d5c65159SKalle Valo ath11k_err(ab, "wmi tlv parse failure at byte %zd (%zu bytes left, %zu expected)\n", 161d5c65159SKalle Valo ptr - begin, len, sizeof(*tlv)); 162d5c65159SKalle Valo return -EINVAL; 163d5c65159SKalle Valo } 164d5c65159SKalle Valo 165d5c65159SKalle Valo tlv = ptr; 166d5c65159SKalle Valo tlv_tag = FIELD_GET(WMI_TLV_TAG, tlv->header); 167d5c65159SKalle Valo tlv_len = FIELD_GET(WMI_TLV_LEN, tlv->header); 168d5c65159SKalle Valo ptr += sizeof(*tlv); 169d5c65159SKalle Valo len -= sizeof(*tlv); 170d5c65159SKalle Valo 171d5c65159SKalle Valo if (tlv_len > len) { 172bb2d2dfdSTom Rix ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%zu bytes left, %u expected)\n", 173d5c65159SKalle Valo tlv_tag, ptr - begin, len, tlv_len); 174d5c65159SKalle Valo return -EINVAL; 175d5c65159SKalle Valo } 176d5c65159SKalle Valo 177d5c65159SKalle Valo if (tlv_tag < ARRAY_SIZE(wmi_tlv_policies) && 178d5c65159SKalle Valo wmi_tlv_policies[tlv_tag].min_len && 179d5c65159SKalle Valo wmi_tlv_policies[tlv_tag].min_len > tlv_len) { 180bb2d2dfdSTom Rix ath11k_err(ab, "wmi tlv parse failure of tag %u at byte %zd (%u bytes is less than min length %zu)\n", 181d5c65159SKalle Valo tlv_tag, ptr - begin, tlv_len, 182d5c65159SKalle Valo wmi_tlv_policies[tlv_tag].min_len); 183d5c65159SKalle Valo return -EINVAL; 184d5c65159SKalle Valo } 185d5c65159SKalle Valo 186d5c65159SKalle Valo ret = iter(ab, tlv_tag, tlv_len, ptr, data); 187d5c65159SKalle Valo if (ret) 188d5c65159SKalle Valo return ret; 189d5c65159SKalle Valo 190d5c65159SKalle Valo ptr += tlv_len; 191d5c65159SKalle Valo len -= tlv_len; 192d5c65159SKalle Valo } 193d5c65159SKalle Valo 194d5c65159SKalle Valo return 0; 195d5c65159SKalle Valo } 196d5c65159SKalle Valo 197d5c65159SKalle Valo static int ath11k_wmi_tlv_iter_parse(struct ath11k_base *ab, u16 tag, u16 len, 198d5c65159SKalle Valo const void *ptr, void *data) 199d5c65159SKalle Valo { 200d5c65159SKalle Valo const void **tb = data; 201d5c65159SKalle Valo 202d5c65159SKalle Valo if (tag < WMI_TAG_MAX) 203d5c65159SKalle Valo tb[tag] = ptr; 204d5c65159SKalle Valo 205d5c65159SKalle Valo return 0; 206d5c65159SKalle Valo } 207d5c65159SKalle Valo 208d5c65159SKalle Valo static int ath11k_wmi_tlv_parse(struct ath11k_base *ar, const void **tb, 209d5c65159SKalle Valo const void *ptr, size_t len) 210d5c65159SKalle Valo { 211d5c65159SKalle Valo return ath11k_wmi_tlv_iter(ar, ptr, len, ath11k_wmi_tlv_iter_parse, 212d5c65159SKalle Valo (void *)tb); 213d5c65159SKalle Valo } 214d5c65159SKalle Valo 215d5c65159SKalle Valo static const void ** 216d5c65159SKalle Valo ath11k_wmi_tlv_parse_alloc(struct ath11k_base *ab, const void *ptr, 217d5c65159SKalle Valo size_t len, gfp_t gfp) 218d5c65159SKalle Valo { 219d5c65159SKalle Valo const void **tb; 220d5c65159SKalle Valo int ret; 221d5c65159SKalle Valo 222d5c65159SKalle Valo tb = kcalloc(WMI_TAG_MAX, sizeof(*tb), gfp); 223d5c65159SKalle Valo if (!tb) 224d5c65159SKalle Valo return ERR_PTR(-ENOMEM); 225d5c65159SKalle Valo 226d5c65159SKalle Valo ret = ath11k_wmi_tlv_parse(ab, tb, ptr, len); 227d5c65159SKalle Valo if (ret) { 228d5c65159SKalle Valo kfree(tb); 229d5c65159SKalle Valo return ERR_PTR(ret); 230d5c65159SKalle Valo } 231d5c65159SKalle Valo 232d5c65159SKalle Valo return tb; 233d5c65159SKalle Valo } 234d5c65159SKalle Valo 235d5c65159SKalle Valo static int ath11k_wmi_cmd_send_nowait(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb, 236d5c65159SKalle Valo u32 cmd_id) 237d5c65159SKalle Valo { 238d5c65159SKalle Valo struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb); 2396bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 240d5c65159SKalle Valo struct wmi_cmd_hdr *cmd_hdr; 241d5c65159SKalle Valo int ret; 242d5c65159SKalle Valo u32 cmd = 0; 243d5c65159SKalle Valo 244d5c65159SKalle Valo if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL) 245d5c65159SKalle Valo return -ENOMEM; 246d5c65159SKalle Valo 247d5c65159SKalle Valo cmd |= FIELD_PREP(WMI_CMD_HDR_CMD_ID, cmd_id); 248d5c65159SKalle Valo 249d5c65159SKalle Valo cmd_hdr = (struct wmi_cmd_hdr *)skb->data; 250d5c65159SKalle Valo cmd_hdr->cmd_id = cmd; 251d5c65159SKalle Valo 252d5c65159SKalle Valo memset(skb_cb, 0, sizeof(*skb_cb)); 253d5c65159SKalle Valo ret = ath11k_htc_send(&ab->htc, wmi->eid, skb); 254d5c65159SKalle Valo 255d5c65159SKalle Valo if (ret) 256d5c65159SKalle Valo goto err_pull; 257d5c65159SKalle Valo 258d5c65159SKalle Valo return 0; 259d5c65159SKalle Valo 260d5c65159SKalle Valo err_pull: 261d5c65159SKalle Valo skb_pull(skb, sizeof(struct wmi_cmd_hdr)); 262d5c65159SKalle Valo return ret; 263d5c65159SKalle Valo } 264d5c65159SKalle Valo 265d5c65159SKalle Valo int ath11k_wmi_cmd_send(struct ath11k_pdev_wmi *wmi, struct sk_buff *skb, 266d5c65159SKalle Valo u32 cmd_id) 267d5c65159SKalle Valo { 2686bc9d6f7SJohn Crispin struct ath11k_wmi_base *wmi_sc = wmi->wmi_ab; 269d5c65159SKalle Valo int ret = -EOPNOTSUPP; 270d5c65159SKalle Valo 271d5c65159SKalle Valo might_sleep(); 272d5c65159SKalle Valo 273d5c65159SKalle Valo wait_event_timeout(wmi_sc->tx_credits_wq, ({ 274d5c65159SKalle Valo ret = ath11k_wmi_cmd_send_nowait(wmi, skb, cmd_id); 275d5c65159SKalle Valo 276d5c65159SKalle Valo if (ret && test_bit(ATH11K_FLAG_CRASH_FLUSH, &wmi_sc->ab->dev_flags)) 277d5c65159SKalle Valo ret = -ESHUTDOWN; 278d5c65159SKalle Valo 279d5c65159SKalle Valo (ret != -EAGAIN); 280d5c65159SKalle Valo }), WMI_SEND_TIMEOUT_HZ); 281d5c65159SKalle Valo 282d5c65159SKalle Valo if (ret == -EAGAIN) 283d5c65159SKalle Valo ath11k_warn(wmi_sc->ab, "wmi command %d timeout\n", cmd_id); 284d5c65159SKalle Valo 285d5c65159SKalle Valo return ret; 286d5c65159SKalle Valo } 287d5c65159SKalle Valo 288d5c65159SKalle Valo static int ath11k_pull_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle, 289d5c65159SKalle Valo const void *ptr, 290d5c65159SKalle Valo struct ath11k_service_ext_param *param) 291d5c65159SKalle Valo { 292d5c65159SKalle Valo const struct wmi_service_ready_ext_event *ev = ptr; 293d5c65159SKalle Valo 294d5c65159SKalle Valo if (!ev) 295d5c65159SKalle Valo return -EINVAL; 296d5c65159SKalle Valo 297d5c65159SKalle Valo /* Move this to host based bitmap */ 298d5c65159SKalle Valo param->default_conc_scan_config_bits = ev->default_conc_scan_config_bits; 299d5c65159SKalle Valo param->default_fw_config_bits = ev->default_fw_config_bits; 300d5c65159SKalle Valo param->he_cap_info = ev->he_cap_info; 301d5c65159SKalle Valo param->mpdu_density = ev->mpdu_density; 302d5c65159SKalle Valo param->max_bssid_rx_filters = ev->max_bssid_rx_filters; 303d5c65159SKalle Valo memcpy(¶m->ppet, &ev->ppet, sizeof(param->ppet)); 304d5c65159SKalle Valo 305d5c65159SKalle Valo return 0; 306d5c65159SKalle Valo } 307d5c65159SKalle Valo 308d5c65159SKalle Valo static int 309d5c65159SKalle Valo ath11k_pull_mac_phy_cap_svc_ready_ext(struct ath11k_pdev_wmi *wmi_handle, 310d5c65159SKalle Valo struct wmi_soc_mac_phy_hw_mode_caps *hw_caps, 311d5c65159SKalle Valo struct wmi_hw_mode_capabilities *wmi_hw_mode_caps, 312d5c65159SKalle Valo struct wmi_soc_hal_reg_capabilities *hal_reg_caps, 313d5c65159SKalle Valo struct wmi_mac_phy_capabilities *wmi_mac_phy_caps, 314d5c65159SKalle Valo u8 hw_mode_id, u8 phy_id, 315d5c65159SKalle Valo struct ath11k_pdev *pdev) 316d5c65159SKalle Valo { 317d5c65159SKalle Valo struct wmi_mac_phy_capabilities *mac_phy_caps; 318d5c65159SKalle Valo struct ath11k_band_cap *cap_band; 319d5c65159SKalle Valo struct ath11k_pdev_cap *pdev_cap = &pdev->cap; 320d5c65159SKalle Valo u32 phy_map; 321d5c65159SKalle Valo u32 hw_idx, phy_idx = 0; 322d5c65159SKalle Valo 323d5c65159SKalle Valo if (!hw_caps || !wmi_hw_mode_caps || !hal_reg_caps) 324d5c65159SKalle Valo return -EINVAL; 325d5c65159SKalle Valo 326d5c65159SKalle Valo for (hw_idx = 0; hw_idx < hw_caps->num_hw_modes; hw_idx++) { 327d5c65159SKalle Valo if (hw_mode_id == wmi_hw_mode_caps[hw_idx].hw_mode_id) 328d5c65159SKalle Valo break; 329d5c65159SKalle Valo 330d5c65159SKalle Valo phy_map = wmi_hw_mode_caps[hw_idx].phy_id_map; 331d5c65159SKalle Valo while (phy_map) { 332d5c65159SKalle Valo phy_map >>= 1; 333d5c65159SKalle Valo phy_idx++; 334d5c65159SKalle Valo } 335d5c65159SKalle Valo } 336d5c65159SKalle Valo 337d5c65159SKalle Valo if (hw_idx == hw_caps->num_hw_modes) 338d5c65159SKalle Valo return -EINVAL; 339d5c65159SKalle Valo 340d5c65159SKalle Valo phy_idx += phy_id; 341d5c65159SKalle Valo if (phy_id >= hal_reg_caps->num_phy) 342d5c65159SKalle Valo return -EINVAL; 343d5c65159SKalle Valo 3445b90fc76SAnilkumar Kolli mac_phy_caps = wmi_mac_phy_caps + phy_idx; 345d5c65159SKalle Valo 346d5c65159SKalle Valo pdev->pdev_id = mac_phy_caps->pdev_id; 3475f859bc0SCarl Huang pdev_cap->supported_bands |= mac_phy_caps->supported_bands; 348d5c65159SKalle Valo pdev_cap->ampdu_density = mac_phy_caps->ampdu_density; 349d5c65159SKalle Valo 350d5c65159SKalle Valo /* Take non-zero tx/rx chainmask. If tx/rx chainmask differs from 351d5c65159SKalle Valo * band to band for a single radio, need to see how this should be 352d5c65159SKalle Valo * handled. 353d5c65159SKalle Valo */ 354d5c65159SKalle Valo if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) { 355d5c65159SKalle Valo pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_2g; 356d5c65159SKalle Valo pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_2g; 357d5c65159SKalle Valo } else if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) { 358d5c65159SKalle Valo pdev_cap->vht_cap = mac_phy_caps->vht_cap_info_5g; 359d5c65159SKalle Valo pdev_cap->vht_mcs = mac_phy_caps->vht_supp_mcs_5g; 360d5c65159SKalle Valo pdev_cap->he_mcs = mac_phy_caps->he_supp_mcs_5g; 361d5c65159SKalle Valo pdev_cap->tx_chain_mask = mac_phy_caps->tx_chain_mask_5g; 362d5c65159SKalle Valo pdev_cap->rx_chain_mask = mac_phy_caps->rx_chain_mask_5g; 363f552d6fdSP Praneesh pdev_cap->nss_ratio_enabled = 364f552d6fdSP Praneesh WMI_NSS_RATIO_ENABLE_DISABLE_GET(mac_phy_caps->nss_ratio); 365f552d6fdSP Praneesh pdev_cap->nss_ratio_info = 366f552d6fdSP Praneesh WMI_NSS_RATIO_INFO_GET(mac_phy_caps->nss_ratio); 367d5c65159SKalle Valo } else { 368d5c65159SKalle Valo return -EINVAL; 369d5c65159SKalle Valo } 370d5c65159SKalle Valo 371d5c65159SKalle Valo /* tx/rx chainmask reported from fw depends on the actual hw chains used, 372d5c65159SKalle Valo * For example, for 4x4 capable macphys, first 4 chains can be used for first 373d5c65159SKalle Valo * mac and the remaing 4 chains can be used for the second mac or vice-versa. 374d5c65159SKalle Valo * In this case, tx/rx chainmask 0xf will be advertised for first mac and 0xf0 37516f283f0SKalle Valo * will be advertised for second mac or vice-versa. Compute the shift value 376d5c65159SKalle Valo * for tx/rx chainmask which will be used to advertise supported ht/vht rates to 377d5c65159SKalle Valo * mac80211. 378d5c65159SKalle Valo */ 379d5c65159SKalle Valo pdev_cap->tx_chain_mask_shift = 380d5c65159SKalle Valo find_first_bit((unsigned long *)&pdev_cap->tx_chain_mask, 32); 381d5c65159SKalle Valo pdev_cap->rx_chain_mask_shift = 382d5c65159SKalle Valo find_first_bit((unsigned long *)&pdev_cap->rx_chain_mask, 32); 383d5c65159SKalle Valo 3845f859bc0SCarl Huang if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_2G_CAP) { 385d5c65159SKalle Valo cap_band = &pdev_cap->band[NL80211_BAND_2GHZ]; 3865f859bc0SCarl Huang cap_band->phy_id = mac_phy_caps->phy_id; 387d5c65159SKalle Valo cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_2g; 388d5c65159SKalle Valo cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_2g; 389d5c65159SKalle Valo cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_2g; 390d5c65159SKalle Valo cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_2g_ext; 391d5c65159SKalle Valo cap_band->he_mcs = mac_phy_caps->he_supp_mcs_2g; 392d5c65159SKalle Valo memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_2g, 393d5c65159SKalle Valo sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE); 394d5c65159SKalle Valo memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet2g, 395d5c65159SKalle Valo sizeof(struct ath11k_ppe_threshold)); 3965f859bc0SCarl Huang } 397d5c65159SKalle Valo 3985f859bc0SCarl Huang if (mac_phy_caps->supported_bands & WMI_HOST_WLAN_5G_CAP) { 399d5c65159SKalle Valo cap_band = &pdev_cap->band[NL80211_BAND_5GHZ]; 4005f859bc0SCarl Huang cap_band->phy_id = mac_phy_caps->phy_id; 401d5c65159SKalle Valo cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g; 402d5c65159SKalle Valo cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g; 403d5c65159SKalle Valo cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g; 404d5c65159SKalle Valo cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext; 405d5c65159SKalle Valo cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g; 406d5c65159SKalle Valo memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g, 407d5c65159SKalle Valo sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE); 408d5c65159SKalle Valo memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g, 409d5c65159SKalle Valo sizeof(struct ath11k_ppe_threshold)); 4105f859bc0SCarl Huang } 411d5c65159SKalle Valo 41222eeadcdSPradeep Kumar Chitrapu cap_band = &pdev_cap->band[NL80211_BAND_6GHZ]; 41322eeadcdSPradeep Kumar Chitrapu cap_band->max_bw_supported = mac_phy_caps->max_bw_supported_5g; 41422eeadcdSPradeep Kumar Chitrapu cap_band->ht_cap_info = mac_phy_caps->ht_cap_info_5g; 41522eeadcdSPradeep Kumar Chitrapu cap_band->he_cap_info[0] = mac_phy_caps->he_cap_info_5g; 41622eeadcdSPradeep Kumar Chitrapu cap_band->he_cap_info[1] = mac_phy_caps->he_cap_info_5g_ext; 41722eeadcdSPradeep Kumar Chitrapu cap_band->he_mcs = mac_phy_caps->he_supp_mcs_5g; 41822eeadcdSPradeep Kumar Chitrapu memcpy(cap_band->he_cap_phy_info, &mac_phy_caps->he_cap_phy_info_5g, 41922eeadcdSPradeep Kumar Chitrapu sizeof(u32) * PSOC_HOST_MAX_PHY_SIZE); 42022eeadcdSPradeep Kumar Chitrapu memcpy(&cap_band->he_ppet, &mac_phy_caps->he_ppet5g, 42122eeadcdSPradeep Kumar Chitrapu sizeof(struct ath11k_ppe_threshold)); 42222eeadcdSPradeep Kumar Chitrapu 423d5c65159SKalle Valo return 0; 424d5c65159SKalle Valo } 425d5c65159SKalle Valo 426d5c65159SKalle Valo static int 427d5c65159SKalle Valo ath11k_pull_reg_cap_svc_rdy_ext(struct ath11k_pdev_wmi *wmi_handle, 428d5c65159SKalle Valo struct wmi_soc_hal_reg_capabilities *reg_caps, 429d5c65159SKalle Valo struct wmi_hal_reg_capabilities_ext *wmi_ext_reg_cap, 430d5c65159SKalle Valo u8 phy_idx, 431d5c65159SKalle Valo struct ath11k_hal_reg_capabilities_ext *param) 432d5c65159SKalle Valo { 433d5c65159SKalle Valo struct wmi_hal_reg_capabilities_ext *ext_reg_cap; 434d5c65159SKalle Valo 435d5c65159SKalle Valo if (!reg_caps || !wmi_ext_reg_cap) 436d5c65159SKalle Valo return -EINVAL; 437d5c65159SKalle Valo 438d5c65159SKalle Valo if (phy_idx >= reg_caps->num_phy) 439d5c65159SKalle Valo return -EINVAL; 440d5c65159SKalle Valo 441d5c65159SKalle Valo ext_reg_cap = &wmi_ext_reg_cap[phy_idx]; 442d5c65159SKalle Valo 443d5c65159SKalle Valo param->phy_id = ext_reg_cap->phy_id; 444d5c65159SKalle Valo param->eeprom_reg_domain = ext_reg_cap->eeprom_reg_domain; 445d5c65159SKalle Valo param->eeprom_reg_domain_ext = 446d5c65159SKalle Valo ext_reg_cap->eeprom_reg_domain_ext; 447d5c65159SKalle Valo param->regcap1 = ext_reg_cap->regcap1; 448d5c65159SKalle Valo param->regcap2 = ext_reg_cap->regcap2; 449d5c65159SKalle Valo /* check if param->wireless_mode is needed */ 450d5c65159SKalle Valo param->low_2ghz_chan = ext_reg_cap->low_2ghz_chan; 451d5c65159SKalle Valo param->high_2ghz_chan = ext_reg_cap->high_2ghz_chan; 452d5c65159SKalle Valo param->low_5ghz_chan = ext_reg_cap->low_5ghz_chan; 453d5c65159SKalle Valo param->high_5ghz_chan = ext_reg_cap->high_5ghz_chan; 454d5c65159SKalle Valo 455d5c65159SKalle Valo return 0; 456d5c65159SKalle Valo } 457d5c65159SKalle Valo 458d5c65159SKalle Valo static int ath11k_pull_service_ready_tlv(struct ath11k_base *ab, 459d5c65159SKalle Valo const void *evt_buf, 460d5c65159SKalle Valo struct ath11k_targ_cap *cap) 461d5c65159SKalle Valo { 462d5c65159SKalle Valo const struct wmi_service_ready_event *ev = evt_buf; 463d5c65159SKalle Valo 464d5c65159SKalle Valo if (!ev) { 465d5c65159SKalle Valo ath11k_err(ab, "%s: failed by NULL param\n", 466d5c65159SKalle Valo __func__); 467d5c65159SKalle Valo return -EINVAL; 468d5c65159SKalle Valo } 469d5c65159SKalle Valo 470d5c65159SKalle Valo cap->phy_capability = ev->phy_capability; 471d5c65159SKalle Valo cap->max_frag_entry = ev->max_frag_entry; 472d5c65159SKalle Valo cap->num_rf_chains = ev->num_rf_chains; 473d5c65159SKalle Valo cap->ht_cap_info = ev->ht_cap_info; 474d5c65159SKalle Valo cap->vht_cap_info = ev->vht_cap_info; 475d5c65159SKalle Valo cap->vht_supp_mcs = ev->vht_supp_mcs; 476d5c65159SKalle Valo cap->hw_min_tx_power = ev->hw_min_tx_power; 477d5c65159SKalle Valo cap->hw_max_tx_power = ev->hw_max_tx_power; 478d5c65159SKalle Valo cap->sys_cap_info = ev->sys_cap_info; 479d5c65159SKalle Valo cap->min_pkt_size_enable = ev->min_pkt_size_enable; 480d5c65159SKalle Valo cap->max_bcn_ie_size = ev->max_bcn_ie_size; 481d5c65159SKalle Valo cap->max_num_scan_channels = ev->max_num_scan_channels; 482d5c65159SKalle Valo cap->max_supported_macs = ev->max_supported_macs; 483d5c65159SKalle Valo cap->wmi_fw_sub_feat_caps = ev->wmi_fw_sub_feat_caps; 484d5c65159SKalle Valo cap->txrx_chainmask = ev->txrx_chainmask; 485d5c65159SKalle Valo cap->default_dbs_hw_mode_index = ev->default_dbs_hw_mode_index; 486d5c65159SKalle Valo cap->num_msdu_desc = ev->num_msdu_desc; 487d5c65159SKalle Valo 488d5c65159SKalle Valo return 0; 489d5c65159SKalle Valo } 490d5c65159SKalle Valo 491d5c65159SKalle Valo /* Save the wmi_service_bitmap into a linear bitmap. The wmi_services in 492d5c65159SKalle Valo * wmi_service ready event are advertised in b0-b3 (LSB 4-bits) of each 493d5c65159SKalle Valo * 4-byte word. 494d5c65159SKalle Valo */ 495d5c65159SKalle Valo static void ath11k_wmi_service_bitmap_copy(struct ath11k_pdev_wmi *wmi, 496d5c65159SKalle Valo const u32 *wmi_svc_bm) 497d5c65159SKalle Valo { 498d5c65159SKalle Valo int i, j; 499d5c65159SKalle Valo 500d5c65159SKalle Valo for (i = 0, j = 0; i < WMI_SERVICE_BM_SIZE && j < WMI_MAX_SERVICE; i++) { 501d5c65159SKalle Valo do { 502d5c65159SKalle Valo if (wmi_svc_bm[i] & BIT(j % WMI_SERVICE_BITS_IN_SIZE32)) 5036bc9d6f7SJohn Crispin set_bit(j, wmi->wmi_ab->svc_map); 504d5c65159SKalle Valo } while (++j % WMI_SERVICE_BITS_IN_SIZE32); 505d5c65159SKalle Valo } 506d5c65159SKalle Valo } 507d5c65159SKalle Valo 508d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len, 509d5c65159SKalle Valo const void *ptr, void *data) 510d5c65159SKalle Valo { 511d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse *svc_ready = data; 5126bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0]; 513d5c65159SKalle Valo u16 expect_len; 514d5c65159SKalle Valo 515d5c65159SKalle Valo switch (tag) { 516d5c65159SKalle Valo case WMI_TAG_SERVICE_READY_EVENT: 517d5c65159SKalle Valo if (ath11k_pull_service_ready_tlv(ab, ptr, &ab->target_caps)) 518d5c65159SKalle Valo return -EINVAL; 519d5c65159SKalle Valo break; 520d5c65159SKalle Valo 521d5c65159SKalle Valo case WMI_TAG_ARRAY_UINT32: 522d5c65159SKalle Valo if (!svc_ready->wmi_svc_bitmap_done) { 523d5c65159SKalle Valo expect_len = WMI_SERVICE_BM_SIZE * sizeof(u32); 524d5c65159SKalle Valo if (len < expect_len) { 525d5c65159SKalle Valo ath11k_warn(ab, "invalid len %d for the tag 0x%x\n", 526d5c65159SKalle Valo len, tag); 527d5c65159SKalle Valo return -EINVAL; 528d5c65159SKalle Valo } 529d5c65159SKalle Valo 530d5c65159SKalle Valo ath11k_wmi_service_bitmap_copy(wmi_handle, ptr); 531d5c65159SKalle Valo 532d5c65159SKalle Valo svc_ready->wmi_svc_bitmap_done = true; 533d5c65159SKalle Valo } 534d5c65159SKalle Valo break; 535d5c65159SKalle Valo default: 536d5c65159SKalle Valo break; 537d5c65159SKalle Valo } 538d5c65159SKalle Valo 539d5c65159SKalle Valo return 0; 540d5c65159SKalle Valo } 541d5c65159SKalle Valo 542d5c65159SKalle Valo static int ath11k_service_ready_event(struct ath11k_base *ab, struct sk_buff *skb) 543d5c65159SKalle Valo { 544d5c65159SKalle Valo struct wmi_tlv_svc_ready_parse svc_ready = { }; 545d5c65159SKalle Valo int ret; 546d5c65159SKalle Valo 547d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 548d5c65159SKalle Valo ath11k_wmi_tlv_svc_rdy_parse, 549d5c65159SKalle Valo &svc_ready); 550d5c65159SKalle Valo if (ret) { 551d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret); 552d5c65159SKalle Valo return ret; 553d5c65159SKalle Valo } 554d5c65159SKalle Valo 555d5c65159SKalle Valo return 0; 556d5c65159SKalle Valo } 557d5c65159SKalle Valo 558d5c65159SKalle Valo struct sk_buff *ath11k_wmi_alloc_skb(struct ath11k_wmi_base *wmi_sc, u32 len) 559d5c65159SKalle Valo { 560d5c65159SKalle Valo struct sk_buff *skb; 561d5c65159SKalle Valo struct ath11k_base *ab = wmi_sc->ab; 562d5c65159SKalle Valo u32 round_len = roundup(len, 4); 563d5c65159SKalle Valo 564d5c65159SKalle Valo skb = ath11k_htc_alloc_skb(ab, WMI_SKB_HEADROOM + round_len); 565d5c65159SKalle Valo if (!skb) 566d5c65159SKalle Valo return NULL; 567d5c65159SKalle Valo 568d5c65159SKalle Valo skb_reserve(skb, WMI_SKB_HEADROOM); 569d5c65159SKalle Valo if (!IS_ALIGNED((unsigned long)skb->data, 4)) 570d5c65159SKalle Valo ath11k_warn(ab, "unaligned WMI skb data\n"); 571d5c65159SKalle Valo 572d5c65159SKalle Valo skb_put(skb, round_len); 573d5c65159SKalle Valo memset(skb->data, 0, round_len); 574d5c65159SKalle Valo 575d5c65159SKalle Valo return skb; 576d5c65159SKalle Valo } 577d5c65159SKalle Valo 578d5c65159SKalle Valo int ath11k_wmi_mgmt_send(struct ath11k *ar, u32 vdev_id, u32 buf_id, 579d5c65159SKalle Valo struct sk_buff *frame) 580d5c65159SKalle Valo { 581d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 582d5c65159SKalle Valo struct wmi_mgmt_send_cmd *cmd; 583d5c65159SKalle Valo struct wmi_tlv *frame_tlv; 584d5c65159SKalle Valo struct sk_buff *skb; 585d5c65159SKalle Valo u32 buf_len; 586d5c65159SKalle Valo int ret, len; 587d5c65159SKalle Valo 588d5c65159SKalle Valo buf_len = frame->len < WMI_MGMT_SEND_DOWNLD_LEN ? 589d5c65159SKalle Valo frame->len : WMI_MGMT_SEND_DOWNLD_LEN; 590d5c65159SKalle Valo 591d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*frame_tlv) + roundup(buf_len, 4); 592d5c65159SKalle Valo 5936bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 594d5c65159SKalle Valo if (!skb) 595d5c65159SKalle Valo return -ENOMEM; 596d5c65159SKalle Valo 597d5c65159SKalle Valo cmd = (struct wmi_mgmt_send_cmd *)skb->data; 598d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_MGMT_TX_SEND_CMD) | 599d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 600d5c65159SKalle Valo cmd->vdev_id = vdev_id; 601d5c65159SKalle Valo cmd->desc_id = buf_id; 602d5c65159SKalle Valo cmd->chanfreq = 0; 603d5c65159SKalle Valo cmd->paddr_lo = lower_32_bits(ATH11K_SKB_CB(frame)->paddr); 604d5c65159SKalle Valo cmd->paddr_hi = upper_32_bits(ATH11K_SKB_CB(frame)->paddr); 605d5c65159SKalle Valo cmd->frame_len = frame->len; 606d5c65159SKalle Valo cmd->buf_len = buf_len; 607d5c65159SKalle Valo cmd->tx_params_valid = 0; 608d5c65159SKalle Valo 609d5c65159SKalle Valo frame_tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd)); 610d5c65159SKalle Valo frame_tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 611d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, buf_len); 612d5c65159SKalle Valo 613d5c65159SKalle Valo memcpy(frame_tlv->value, frame->data, buf_len); 614d5c65159SKalle Valo 615d5c65159SKalle Valo ath11k_ce_byte_swap(frame_tlv->value, buf_len); 616d5c65159SKalle Valo 617d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_MGMT_TX_SEND_CMDID); 618d5c65159SKalle Valo if (ret) { 619d5c65159SKalle Valo ath11k_warn(ar->ab, 620d5c65159SKalle Valo "failed to submit WMI_MGMT_TX_SEND_CMDID cmd\n"); 621d5c65159SKalle Valo dev_kfree_skb(skb); 622d5c65159SKalle Valo } 623d5c65159SKalle Valo 624d5c65159SKalle Valo return ret; 625d5c65159SKalle Valo } 626d5c65159SKalle Valo 627d5c65159SKalle Valo int ath11k_wmi_vdev_create(struct ath11k *ar, u8 *macaddr, 628d5c65159SKalle Valo struct vdev_create_params *param) 629d5c65159SKalle Valo { 630d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 631d5c65159SKalle Valo struct wmi_vdev_create_cmd *cmd; 632d5c65159SKalle Valo struct sk_buff *skb; 633d5c65159SKalle Valo struct wmi_vdev_txrx_streams *txrx_streams; 634d5c65159SKalle Valo struct wmi_tlv *tlv; 635d5c65159SKalle Valo int ret, len; 636d5c65159SKalle Valo void *ptr; 637d5c65159SKalle Valo 638d5c65159SKalle Valo /* It can be optimized my sending tx/rx chain configuration 639d5c65159SKalle Valo * only for supported bands instead of always sending it for 640d5c65159SKalle Valo * both the bands. 641d5c65159SKalle Valo */ 642d5c65159SKalle Valo len = sizeof(*cmd) + TLV_HDR_SIZE + 643d5c65159SKalle Valo (WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams)); 644d5c65159SKalle Valo 6456bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 646d5c65159SKalle Valo if (!skb) 647d5c65159SKalle Valo return -ENOMEM; 648d5c65159SKalle Valo 649d5c65159SKalle Valo cmd = (struct wmi_vdev_create_cmd *)skb->data; 650d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_CREATE_CMD) | 651d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 652d5c65159SKalle Valo 653d5c65159SKalle Valo cmd->vdev_id = param->if_id; 654d5c65159SKalle Valo cmd->vdev_type = param->type; 655d5c65159SKalle Valo cmd->vdev_subtype = param->subtype; 656d5c65159SKalle Valo cmd->num_cfg_txrx_streams = WMI_NUM_SUPPORTED_BAND_MAX; 657d5c65159SKalle Valo cmd->pdev_id = param->pdev_id; 658d5c65159SKalle Valo ether_addr_copy(cmd->vdev_macaddr.addr, macaddr); 659d5c65159SKalle Valo 660d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd); 661d5c65159SKalle Valo len = WMI_NUM_SUPPORTED_BAND_MAX * sizeof(*txrx_streams); 662d5c65159SKalle Valo 663d5c65159SKalle Valo tlv = ptr; 664d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 665d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 666d5c65159SKalle Valo 667d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 668d5c65159SKalle Valo txrx_streams = ptr; 669d5c65159SKalle Valo len = sizeof(*txrx_streams); 670d5c65159SKalle Valo txrx_streams->tlv_header = 671d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) | 672d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 673d5c65159SKalle Valo txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_2G; 674d5c65159SKalle Valo txrx_streams->supported_tx_streams = 675d5c65159SKalle Valo param->chains[NL80211_BAND_2GHZ].tx; 676d5c65159SKalle Valo txrx_streams->supported_rx_streams = 677d5c65159SKalle Valo param->chains[NL80211_BAND_2GHZ].rx; 678d5c65159SKalle Valo 679d5c65159SKalle Valo txrx_streams++; 680d5c65159SKalle Valo txrx_streams->tlv_header = 681d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_TXRX_STREAMS) | 682d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 683d5c65159SKalle Valo txrx_streams->band = WMI_TPC_CHAINMASK_CONFIG_BAND_5G; 684d5c65159SKalle Valo txrx_streams->supported_tx_streams = 685d5c65159SKalle Valo param->chains[NL80211_BAND_5GHZ].tx; 686d5c65159SKalle Valo txrx_streams->supported_rx_streams = 687d5c65159SKalle Valo param->chains[NL80211_BAND_5GHZ].rx; 688d5c65159SKalle Valo 689d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_CREATE_CMDID); 690d5c65159SKalle Valo if (ret) { 691d5c65159SKalle Valo ath11k_warn(ar->ab, 692d5c65159SKalle Valo "failed to submit WMI_VDEV_CREATE_CMDID\n"); 693d5c65159SKalle Valo dev_kfree_skb(skb); 694d5c65159SKalle Valo } 695d5c65159SKalle Valo 696d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 697d5c65159SKalle Valo "WMI vdev create: id %d type %d subtype %d macaddr %pM pdevid %d\n", 698d5c65159SKalle Valo param->if_id, param->type, param->subtype, 699d5c65159SKalle Valo macaddr, param->pdev_id); 700d5c65159SKalle Valo 701d5c65159SKalle Valo return ret; 702d5c65159SKalle Valo } 703d5c65159SKalle Valo 704d5c65159SKalle Valo int ath11k_wmi_vdev_delete(struct ath11k *ar, u8 vdev_id) 705d5c65159SKalle Valo { 706d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 707d5c65159SKalle Valo struct wmi_vdev_delete_cmd *cmd; 708d5c65159SKalle Valo struct sk_buff *skb; 709d5c65159SKalle Valo int ret; 710d5c65159SKalle Valo 7116bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 712d5c65159SKalle Valo if (!skb) 713d5c65159SKalle Valo return -ENOMEM; 714d5c65159SKalle Valo 715d5c65159SKalle Valo cmd = (struct wmi_vdev_delete_cmd *)skb->data; 716d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DELETE_CMD) | 717d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 718d5c65159SKalle Valo cmd->vdev_id = vdev_id; 719d5c65159SKalle Valo 720d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DELETE_CMDID); 721d5c65159SKalle Valo if (ret) { 722d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DELETE_CMDID\n"); 723d5c65159SKalle Valo dev_kfree_skb(skb); 724d5c65159SKalle Valo } 725d5c65159SKalle Valo 726d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev delete id %d\n", vdev_id); 727d5c65159SKalle Valo 728d5c65159SKalle Valo return ret; 729d5c65159SKalle Valo } 730d5c65159SKalle Valo 731d5c65159SKalle Valo int ath11k_wmi_vdev_stop(struct ath11k *ar, u8 vdev_id) 732d5c65159SKalle Valo { 733d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 734d5c65159SKalle Valo struct wmi_vdev_stop_cmd *cmd; 735d5c65159SKalle Valo struct sk_buff *skb; 736d5c65159SKalle Valo int ret; 737d5c65159SKalle Valo 7386bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 739d5c65159SKalle Valo if (!skb) 740d5c65159SKalle Valo return -ENOMEM; 741d5c65159SKalle Valo 742d5c65159SKalle Valo cmd = (struct wmi_vdev_stop_cmd *)skb->data; 743d5c65159SKalle Valo 744d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_STOP_CMD) | 745d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 746d5c65159SKalle Valo cmd->vdev_id = vdev_id; 747d5c65159SKalle Valo 748d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_STOP_CMDID); 749d5c65159SKalle Valo if (ret) { 750d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_STOP cmd\n"); 751d5c65159SKalle Valo dev_kfree_skb(skb); 752d5c65159SKalle Valo } 753d5c65159SKalle Valo 754d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev stop id 0x%x\n", vdev_id); 755d5c65159SKalle Valo 756d5c65159SKalle Valo return ret; 757d5c65159SKalle Valo } 758d5c65159SKalle Valo 759d5c65159SKalle Valo int ath11k_wmi_vdev_down(struct ath11k *ar, u8 vdev_id) 760d5c65159SKalle Valo { 761d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 762d5c65159SKalle Valo struct wmi_vdev_down_cmd *cmd; 763d5c65159SKalle Valo struct sk_buff *skb; 764d5c65159SKalle Valo int ret; 765d5c65159SKalle Valo 7666bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 767d5c65159SKalle Valo if (!skb) 768d5c65159SKalle Valo return -ENOMEM; 769d5c65159SKalle Valo 770d5c65159SKalle Valo cmd = (struct wmi_vdev_down_cmd *)skb->data; 771d5c65159SKalle Valo 772d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_DOWN_CMD) | 773d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 774d5c65159SKalle Valo cmd->vdev_id = vdev_id; 775d5c65159SKalle Valo 776d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_DOWN_CMDID); 777d5c65159SKalle Valo if (ret) { 778d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_DOWN cmd\n"); 779d5c65159SKalle Valo dev_kfree_skb(skb); 780d5c65159SKalle Valo } 781d5c65159SKalle Valo 782d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "WMI vdev down id 0x%x\n", vdev_id); 783d5c65159SKalle Valo 784d5c65159SKalle Valo return ret; 785d5c65159SKalle Valo } 786d5c65159SKalle Valo 787d5c65159SKalle Valo static void ath11k_wmi_put_wmi_channel(struct wmi_channel *chan, 788d5c65159SKalle Valo struct wmi_vdev_start_req_arg *arg) 789d5c65159SKalle Valo { 790f552d6fdSP Praneesh u32 center_freq1 = arg->channel.band_center_freq1; 791f552d6fdSP Praneesh 792d5c65159SKalle Valo memset(chan, 0, sizeof(*chan)); 793d5c65159SKalle Valo 794d5c65159SKalle Valo chan->mhz = arg->channel.freq; 795d5c65159SKalle Valo chan->band_center_freq1 = arg->channel.band_center_freq1; 796f552d6fdSP Praneesh 797f552d6fdSP Praneesh if (arg->channel.mode == MODE_11AX_HE160) { 798f552d6fdSP Praneesh if (arg->channel.freq > arg->channel.band_center_freq1) 799f552d6fdSP Praneesh chan->band_center_freq1 = center_freq1 + 40; 800d5c65159SKalle Valo else 801f552d6fdSP Praneesh chan->band_center_freq1 = center_freq1 - 40; 802f552d6fdSP Praneesh 803f552d6fdSP Praneesh chan->band_center_freq2 = arg->channel.band_center_freq1; 804f552d6fdSP Praneesh 805f552d6fdSP Praneesh } else if (arg->channel.mode == MODE_11AC_VHT80_80) { 806f552d6fdSP Praneesh chan->band_center_freq2 = arg->channel.band_center_freq2; 807f552d6fdSP Praneesh } else { 808d5c65159SKalle Valo chan->band_center_freq2 = 0; 809f552d6fdSP Praneesh } 810d5c65159SKalle Valo 811d5c65159SKalle Valo chan->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, arg->channel.mode); 812d5c65159SKalle Valo if (arg->channel.passive) 813d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_PASSIVE; 814d5c65159SKalle Valo if (arg->channel.allow_ibss) 815d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_ADHOC_ALLOWED; 816d5c65159SKalle Valo if (arg->channel.allow_ht) 817d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_ALLOW_HT; 818d5c65159SKalle Valo if (arg->channel.allow_vht) 819d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_ALLOW_VHT; 8209f056ed8SJohn Crispin if (arg->channel.allow_he) 8219f056ed8SJohn Crispin chan->info |= WMI_CHAN_INFO_ALLOW_HE; 822d5c65159SKalle Valo if (arg->channel.ht40plus) 823d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_HT40_PLUS; 824d5c65159SKalle Valo if (arg->channel.chan_radar) 825d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_DFS; 826d5c65159SKalle Valo if (arg->channel.freq2_radar) 827d5c65159SKalle Valo chan->info |= WMI_CHAN_INFO_DFS_FREQ2; 828d5c65159SKalle Valo 829d5c65159SKalle Valo chan->reg_info_1 = FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR, 830d5c65159SKalle Valo arg->channel.max_power) | 831d5c65159SKalle Valo FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR, 832d5c65159SKalle Valo arg->channel.max_reg_power); 833d5c65159SKalle Valo 834d5c65159SKalle Valo chan->reg_info_2 = FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX, 835d5c65159SKalle Valo arg->channel.max_antenna_gain) | 836d5c65159SKalle Valo FIELD_PREP(WMI_CHAN_REG_INFO2_MAX_TX_PWR, 837d5c65159SKalle Valo arg->channel.max_power); 838d5c65159SKalle Valo } 839d5c65159SKalle Valo 840d5c65159SKalle Valo int ath11k_wmi_vdev_start(struct ath11k *ar, struct wmi_vdev_start_req_arg *arg, 841d5c65159SKalle Valo bool restart) 842d5c65159SKalle Valo { 843d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 844d5c65159SKalle Valo struct wmi_vdev_start_request_cmd *cmd; 845d5c65159SKalle Valo struct sk_buff *skb; 846d5c65159SKalle Valo struct wmi_channel *chan; 847d5c65159SKalle Valo struct wmi_tlv *tlv; 848d5c65159SKalle Valo void *ptr; 849d5c65159SKalle Valo int ret, len; 850d5c65159SKalle Valo 851d5c65159SKalle Valo if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid))) 852d5c65159SKalle Valo return -EINVAL; 853d5c65159SKalle Valo 854d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*chan) + TLV_HDR_SIZE; 855d5c65159SKalle Valo 8566bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 857d5c65159SKalle Valo if (!skb) 858d5c65159SKalle Valo return -ENOMEM; 859d5c65159SKalle Valo 860d5c65159SKalle Valo cmd = (struct wmi_vdev_start_request_cmd *)skb->data; 861d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 862d5c65159SKalle Valo WMI_TAG_VDEV_START_REQUEST_CMD) | 863d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 864d5c65159SKalle Valo cmd->vdev_id = arg->vdev_id; 865d5c65159SKalle Valo cmd->beacon_interval = arg->bcn_intval; 866d5c65159SKalle Valo cmd->bcn_tx_rate = arg->bcn_tx_rate; 867d5c65159SKalle Valo cmd->dtim_period = arg->dtim_period; 868d5c65159SKalle Valo cmd->num_noa_descriptors = arg->num_noa_descriptors; 869d5c65159SKalle Valo cmd->preferred_rx_streams = arg->pref_rx_streams; 870d5c65159SKalle Valo cmd->preferred_tx_streams = arg->pref_tx_streams; 871d5c65159SKalle Valo cmd->cac_duration_ms = arg->cac_duration_ms; 872d5c65159SKalle Valo cmd->regdomain = arg->regdomain; 873d5c65159SKalle Valo cmd->he_ops = arg->he_ops; 874d5c65159SKalle Valo 875d5c65159SKalle Valo if (!restart) { 876d5c65159SKalle Valo if (arg->ssid) { 877d5c65159SKalle Valo cmd->ssid.ssid_len = arg->ssid_len; 878d5c65159SKalle Valo memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len); 879d5c65159SKalle Valo } 880d5c65159SKalle Valo if (arg->hidden_ssid) 881d5c65159SKalle Valo cmd->flags |= WMI_VDEV_START_HIDDEN_SSID; 882d5c65159SKalle Valo if (arg->pmf_enabled) 883d5c65159SKalle Valo cmd->flags |= WMI_VDEV_START_PMF_ENABLED; 884d5c65159SKalle Valo } 885d5c65159SKalle Valo 886d5c65159SKalle Valo cmd->flags |= WMI_VDEV_START_LDPC_RX_ENABLED; 8878717db7eSSeevalamuthu Mariappan if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags)) 8888717db7eSSeevalamuthu Mariappan cmd->flags |= WMI_VDEV_START_HW_ENCRYPTION_DISABLED; 889d5c65159SKalle Valo 890d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd); 891d5c65159SKalle Valo chan = ptr; 892d5c65159SKalle Valo 893d5c65159SKalle Valo ath11k_wmi_put_wmi_channel(chan, arg); 894d5c65159SKalle Valo 895d5c65159SKalle Valo chan->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_CHANNEL) | 896d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 897d5c65159SKalle Valo sizeof(*chan) - TLV_HDR_SIZE); 898d5c65159SKalle Valo ptr += sizeof(*chan); 899d5c65159SKalle Valo 900d5c65159SKalle Valo tlv = ptr; 901d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 902d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 0); 903d5c65159SKalle Valo 904d5c65159SKalle Valo /* Note: This is a nested TLV containing: 905d5c65159SKalle Valo * [wmi_tlv][wmi_p2p_noa_descriptor][wmi_tlv].. 906d5c65159SKalle Valo */ 907d5c65159SKalle Valo 908d5c65159SKalle Valo ptr += sizeof(*tlv); 909d5c65159SKalle Valo 910d5c65159SKalle Valo if (restart) 911d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 912d5c65159SKalle Valo WMI_VDEV_RESTART_REQUEST_CMDID); 913d5c65159SKalle Valo else 914d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 915d5c65159SKalle Valo WMI_VDEV_START_REQUEST_CMDID); 916d5c65159SKalle Valo if (ret) { 917d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit vdev_%s cmd\n", 918d5c65159SKalle Valo restart ? "restart" : "start"); 919d5c65159SKalle Valo dev_kfree_skb(skb); 920d5c65159SKalle Valo } 921d5c65159SKalle Valo 922d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "vdev %s id 0x%x freq 0x%x mode 0x%x\n", 923d5c65159SKalle Valo restart ? "restart" : "start", arg->vdev_id, 924d5c65159SKalle Valo arg->channel.freq, arg->channel.mode); 925d5c65159SKalle Valo 926d5c65159SKalle Valo return ret; 927d5c65159SKalle Valo } 928d5c65159SKalle Valo 929d5c65159SKalle Valo int ath11k_wmi_vdev_up(struct ath11k *ar, u32 vdev_id, u32 aid, const u8 *bssid) 930d5c65159SKalle Valo { 931d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 932d5c65159SKalle Valo struct wmi_vdev_up_cmd *cmd; 933d5c65159SKalle Valo struct sk_buff *skb; 934d5c65159SKalle Valo int ret; 935d5c65159SKalle Valo 9366bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 937d5c65159SKalle Valo if (!skb) 938d5c65159SKalle Valo return -ENOMEM; 939d5c65159SKalle Valo 940d5c65159SKalle Valo cmd = (struct wmi_vdev_up_cmd *)skb->data; 941d5c65159SKalle Valo 942d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_UP_CMD) | 943d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 944d5c65159SKalle Valo cmd->vdev_id = vdev_id; 945d5c65159SKalle Valo cmd->vdev_assoc_id = aid; 946d5c65159SKalle Valo 947d5c65159SKalle Valo ether_addr_copy(cmd->vdev_bssid.addr, bssid); 948d5c65159SKalle Valo 949d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_UP_CMDID); 950d5c65159SKalle Valo if (ret) { 951d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_VDEV_UP cmd\n"); 952d5c65159SKalle Valo dev_kfree_skb(skb); 953d5c65159SKalle Valo } 954d5c65159SKalle Valo 955d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 956d5c65159SKalle Valo "WMI mgmt vdev up id 0x%x assoc id %d bssid %pM\n", 957d5c65159SKalle Valo vdev_id, aid, bssid); 958d5c65159SKalle Valo 959d5c65159SKalle Valo return ret; 960d5c65159SKalle Valo } 961d5c65159SKalle Valo 962d5c65159SKalle Valo int ath11k_wmi_send_peer_create_cmd(struct ath11k *ar, 963d5c65159SKalle Valo struct peer_create_params *param) 964d5c65159SKalle Valo { 965d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 966d5c65159SKalle Valo struct wmi_peer_create_cmd *cmd; 967d5c65159SKalle Valo struct sk_buff *skb; 968d5c65159SKalle Valo int ret; 969d5c65159SKalle Valo 9706bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 971d5c65159SKalle Valo if (!skb) 972d5c65159SKalle Valo return -ENOMEM; 973d5c65159SKalle Valo 974d5c65159SKalle Valo cmd = (struct wmi_peer_create_cmd *)skb->data; 975d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_CREATE_CMD) | 976d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 977d5c65159SKalle Valo 978d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, param->peer_addr); 979d5c65159SKalle Valo cmd->peer_type = param->peer_type; 980d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 981d5c65159SKalle Valo 982d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_CREATE_CMDID); 983d5c65159SKalle Valo if (ret) { 984d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to submit WMI_PEER_CREATE cmd\n"); 985d5c65159SKalle Valo dev_kfree_skb(skb); 986d5c65159SKalle Valo } 987d5c65159SKalle Valo 988d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 989d5c65159SKalle Valo "WMI peer create vdev_id %d peer_addr %pM\n", 990d5c65159SKalle Valo param->vdev_id, param->peer_addr); 991d5c65159SKalle Valo 992d5c65159SKalle Valo return ret; 993d5c65159SKalle Valo } 994d5c65159SKalle Valo 995d5c65159SKalle Valo int ath11k_wmi_send_peer_delete_cmd(struct ath11k *ar, 996d5c65159SKalle Valo const u8 *peer_addr, u8 vdev_id) 997d5c65159SKalle Valo { 998d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 999d5c65159SKalle Valo struct wmi_peer_delete_cmd *cmd; 1000d5c65159SKalle Valo struct sk_buff *skb; 1001d5c65159SKalle Valo int ret; 1002d5c65159SKalle Valo 10036bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1004d5c65159SKalle Valo if (!skb) 1005d5c65159SKalle Valo return -ENOMEM; 1006d5c65159SKalle Valo 1007d5c65159SKalle Valo cmd = (struct wmi_peer_delete_cmd *)skb->data; 1008d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_DELETE_CMD) | 1009d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1010d5c65159SKalle Valo 1011d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1012d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1013d5c65159SKalle Valo 1014d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1015d5c65159SKalle Valo "WMI peer delete vdev_id %d peer_addr %pM\n", 1016d5c65159SKalle Valo vdev_id, peer_addr); 1017d5c65159SKalle Valo 1018d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_DELETE_CMDID); 1019d5c65159SKalle Valo if (ret) { 1020d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PEER_DELETE cmd\n"); 1021d5c65159SKalle Valo dev_kfree_skb(skb); 1022d5c65159SKalle Valo } 1023d5c65159SKalle Valo 1024d5c65159SKalle Valo return ret; 1025d5c65159SKalle Valo } 1026d5c65159SKalle Valo 1027d5c65159SKalle Valo int ath11k_wmi_send_pdev_set_regdomain(struct ath11k *ar, 1028d5c65159SKalle Valo struct pdev_set_regdomain_params *param) 1029d5c65159SKalle Valo { 1030d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1031d5c65159SKalle Valo struct wmi_pdev_set_regdomain_cmd *cmd; 1032d5c65159SKalle Valo struct sk_buff *skb; 1033d5c65159SKalle Valo int ret; 1034d5c65159SKalle Valo 10356bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1036d5c65159SKalle Valo if (!skb) 1037d5c65159SKalle Valo return -ENOMEM; 1038d5c65159SKalle Valo 1039d5c65159SKalle Valo cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data; 1040d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1041d5c65159SKalle Valo WMI_TAG_PDEV_SET_REGDOMAIN_CMD) | 1042d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1043d5c65159SKalle Valo 1044d5c65159SKalle Valo cmd->reg_domain = param->current_rd_in_use; 1045d5c65159SKalle Valo cmd->reg_domain_2g = param->current_rd_2g; 1046d5c65159SKalle Valo cmd->reg_domain_5g = param->current_rd_5g; 1047d5c65159SKalle Valo cmd->conformance_test_limit_2g = param->ctl_2g; 1048d5c65159SKalle Valo cmd->conformance_test_limit_5g = param->ctl_5g; 1049d5c65159SKalle Valo cmd->dfs_domain = param->dfs_domain; 1050d5c65159SKalle Valo cmd->pdev_id = param->pdev_id; 1051d5c65159SKalle Valo 1052d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1053d5c65159SKalle Valo "WMI pdev regd rd %d rd2g %d rd5g %d domain %d pdev id %d\n", 1054d5c65159SKalle Valo param->current_rd_in_use, param->current_rd_2g, 1055d5c65159SKalle Valo param->current_rd_5g, param->dfs_domain, param->pdev_id); 1056d5c65159SKalle Valo 1057d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_REGDOMAIN_CMDID); 1058d5c65159SKalle Valo if (ret) { 1059d5c65159SKalle Valo ath11k_warn(ar->ab, 1060d5c65159SKalle Valo "failed to send WMI_PDEV_SET_REGDOMAIN cmd\n"); 1061d5c65159SKalle Valo dev_kfree_skb(skb); 1062d5c65159SKalle Valo } 1063d5c65159SKalle Valo 1064d5c65159SKalle Valo return ret; 1065d5c65159SKalle Valo } 1066d5c65159SKalle Valo 1067d5c65159SKalle Valo int ath11k_wmi_set_peer_param(struct ath11k *ar, const u8 *peer_addr, 1068d5c65159SKalle Valo u32 vdev_id, u32 param_id, u32 param_val) 1069d5c65159SKalle Valo { 1070d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1071d5c65159SKalle Valo struct wmi_peer_set_param_cmd *cmd; 1072d5c65159SKalle Valo struct sk_buff *skb; 1073d5c65159SKalle Valo int ret; 1074d5c65159SKalle Valo 10756bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1076d5c65159SKalle Valo if (!skb) 1077d5c65159SKalle Valo return -ENOMEM; 1078d5c65159SKalle Valo 1079d5c65159SKalle Valo cmd = (struct wmi_peer_set_param_cmd *)skb->data; 1080d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_SET_PARAM_CMD) | 1081d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1082d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1083d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1084d5c65159SKalle Valo cmd->param_id = param_id; 1085d5c65159SKalle Valo cmd->param_value = param_val; 1086d5c65159SKalle Valo 1087d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_SET_PARAM_CMDID); 1088d5c65159SKalle Valo if (ret) { 1089d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PEER_SET_PARAM cmd\n"); 1090d5c65159SKalle Valo dev_kfree_skb(skb); 1091d5c65159SKalle Valo } 1092d5c65159SKalle Valo 1093d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1094d5c65159SKalle Valo "WMI vdev %d peer 0x%pM set param %d value %d\n", 1095d5c65159SKalle Valo vdev_id, peer_addr, param_id, param_val); 1096d5c65159SKalle Valo 1097d5c65159SKalle Valo return ret; 1098d5c65159SKalle Valo } 1099d5c65159SKalle Valo 1100d5c65159SKalle Valo int ath11k_wmi_send_peer_flush_tids_cmd(struct ath11k *ar, 1101d5c65159SKalle Valo u8 peer_addr[ETH_ALEN], 1102d5c65159SKalle Valo struct peer_flush_params *param) 1103d5c65159SKalle Valo { 1104d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1105d5c65159SKalle Valo struct wmi_peer_flush_tids_cmd *cmd; 1106d5c65159SKalle Valo struct sk_buff *skb; 1107d5c65159SKalle Valo int ret; 1108d5c65159SKalle Valo 11096bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1110d5c65159SKalle Valo if (!skb) 1111d5c65159SKalle Valo return -ENOMEM; 1112d5c65159SKalle Valo 1113d5c65159SKalle Valo cmd = (struct wmi_peer_flush_tids_cmd *)skb->data; 1114d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PEER_FLUSH_TIDS_CMD) | 1115d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1116d5c65159SKalle Valo 1117d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1118d5c65159SKalle Valo cmd->peer_tid_bitmap = param->peer_tid_bitmap; 1119d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 1120d5c65159SKalle Valo 1121d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_FLUSH_TIDS_CMDID); 1122d5c65159SKalle Valo if (ret) { 1123d5c65159SKalle Valo ath11k_warn(ar->ab, 1124d5c65159SKalle Valo "failed to send WMI_PEER_FLUSH_TIDS cmd\n"); 1125d5c65159SKalle Valo dev_kfree_skb(skb); 1126d5c65159SKalle Valo } 1127d5c65159SKalle Valo 1128d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1129d5c65159SKalle Valo "WMI peer flush vdev_id %d peer_addr %pM tids %08x\n", 1130d5c65159SKalle Valo param->vdev_id, peer_addr, param->peer_tid_bitmap); 1131d5c65159SKalle Valo 1132d5c65159SKalle Valo return ret; 1133d5c65159SKalle Valo } 1134d5c65159SKalle Valo 1135d5c65159SKalle Valo int ath11k_wmi_peer_rx_reorder_queue_setup(struct ath11k *ar, 1136d5c65159SKalle Valo int vdev_id, const u8 *addr, 1137d5c65159SKalle Valo dma_addr_t paddr, u8 tid, 1138d5c65159SKalle Valo u8 ba_window_size_valid, 1139d5c65159SKalle Valo u32 ba_window_size) 1140d5c65159SKalle Valo { 1141d5c65159SKalle Valo struct wmi_peer_reorder_queue_setup_cmd *cmd; 1142d5c65159SKalle Valo struct sk_buff *skb; 1143d5c65159SKalle Valo int ret; 1144d5c65159SKalle Valo 11456bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 1146d5c65159SKalle Valo if (!skb) 1147d5c65159SKalle Valo return -ENOMEM; 1148d5c65159SKalle Valo 1149d5c65159SKalle Valo cmd = (struct wmi_peer_reorder_queue_setup_cmd *)skb->data; 1150d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1151d5c65159SKalle Valo WMI_TAG_REORDER_QUEUE_SETUP_CMD) | 1152d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1153d5c65159SKalle Valo 1154d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, addr); 1155d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1156d5c65159SKalle Valo cmd->tid = tid; 1157d5c65159SKalle Valo cmd->queue_ptr_lo = lower_32_bits(paddr); 1158d5c65159SKalle Valo cmd->queue_ptr_hi = upper_32_bits(paddr); 1159d5c65159SKalle Valo cmd->queue_no = tid; 1160d5c65159SKalle Valo cmd->ba_window_size_valid = ba_window_size_valid; 1161d5c65159SKalle Valo cmd->ba_window_size = ba_window_size; 1162d5c65159SKalle Valo 1163d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(ar->wmi, skb, 1164d5c65159SKalle Valo WMI_PEER_REORDER_QUEUE_SETUP_CMDID); 1165d5c65159SKalle Valo if (ret) { 1166d5c65159SKalle Valo ath11k_warn(ar->ab, 1167d5c65159SKalle Valo "failed to send WMI_PEER_REORDER_QUEUE_SETUP\n"); 1168d5c65159SKalle Valo dev_kfree_skb(skb); 1169d5c65159SKalle Valo } 1170d5c65159SKalle Valo 1171d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1172d5c65159SKalle Valo "wmi rx reorder queue setup addr %pM vdev_id %d tid %d\n", 1173d5c65159SKalle Valo addr, vdev_id, tid); 1174d5c65159SKalle Valo 1175d5c65159SKalle Valo return ret; 1176d5c65159SKalle Valo } 1177d5c65159SKalle Valo 1178d5c65159SKalle Valo int 1179d5c65159SKalle Valo ath11k_wmi_rx_reord_queue_remove(struct ath11k *ar, 1180d5c65159SKalle Valo struct rx_reorder_queue_remove_params *param) 1181d5c65159SKalle Valo { 1182d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1183d5c65159SKalle Valo struct wmi_peer_reorder_queue_remove_cmd *cmd; 1184d5c65159SKalle Valo struct sk_buff *skb; 1185d5c65159SKalle Valo int ret; 1186d5c65159SKalle Valo 11876bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1188d5c65159SKalle Valo if (!skb) 1189d5c65159SKalle Valo return -ENOMEM; 1190d5c65159SKalle Valo 1191d5c65159SKalle Valo cmd = (struct wmi_peer_reorder_queue_remove_cmd *)skb->data; 1192d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1193d5c65159SKalle Valo WMI_TAG_REORDER_QUEUE_REMOVE_CMD) | 1194d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1195d5c65159SKalle Valo 1196d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, param->peer_macaddr); 1197d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 1198d5c65159SKalle Valo cmd->tid_mask = param->peer_tid_bitmap; 1199d5c65159SKalle Valo 1200d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1201d5c65159SKalle Valo "%s: peer_macaddr %pM vdev_id %d, tid_map %d", __func__, 1202d5c65159SKalle Valo param->peer_macaddr, param->vdev_id, param->peer_tid_bitmap); 1203d5c65159SKalle Valo 1204d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 1205d5c65159SKalle Valo WMI_PEER_REORDER_QUEUE_REMOVE_CMDID); 1206d5c65159SKalle Valo if (ret) { 1207d5c65159SKalle Valo ath11k_warn(ar->ab, 1208d5c65159SKalle Valo "failed to send WMI_PEER_REORDER_QUEUE_REMOVE_CMDID"); 1209d5c65159SKalle Valo dev_kfree_skb(skb); 1210d5c65159SKalle Valo } 1211d5c65159SKalle Valo 1212d5c65159SKalle Valo return ret; 1213d5c65159SKalle Valo } 1214d5c65159SKalle Valo 1215d5c65159SKalle Valo int ath11k_wmi_pdev_set_param(struct ath11k *ar, u32 param_id, 1216d5c65159SKalle Valo u32 param_value, u8 pdev_id) 1217d5c65159SKalle Valo { 1218d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1219d5c65159SKalle Valo struct wmi_pdev_set_param_cmd *cmd; 1220d5c65159SKalle Valo struct sk_buff *skb; 1221d5c65159SKalle Valo int ret; 1222d5c65159SKalle Valo 12236bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1224d5c65159SKalle Valo if (!skb) 1225d5c65159SKalle Valo return -ENOMEM; 1226d5c65159SKalle Valo 1227d5c65159SKalle Valo cmd = (struct wmi_pdev_set_param_cmd *)skb->data; 1228d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_PARAM_CMD) | 1229d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1230d5c65159SKalle Valo cmd->pdev_id = pdev_id; 1231d5c65159SKalle Valo cmd->param_id = param_id; 1232d5c65159SKalle Valo cmd->param_value = param_value; 1233d5c65159SKalle Valo 1234d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SET_PARAM_CMDID); 1235d5c65159SKalle Valo if (ret) { 1236d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n"); 1237d5c65159SKalle Valo dev_kfree_skb(skb); 1238d5c65159SKalle Valo } 1239d5c65159SKalle Valo 1240d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1241d5c65159SKalle Valo "WMI pdev set param %d pdev id %d value %d\n", 1242d5c65159SKalle Valo param_id, pdev_id, param_value); 1243d5c65159SKalle Valo 1244d5c65159SKalle Valo return ret; 1245d5c65159SKalle Valo } 1246d5c65159SKalle Valo 124797c63746SJohn Crispin int ath11k_wmi_pdev_set_ps_mode(struct ath11k *ar, int vdev_id, u32 enable) 124897c63746SJohn Crispin { 124997c63746SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi; 125097c63746SJohn Crispin struct wmi_pdev_set_ps_mode_cmd *cmd; 125197c63746SJohn Crispin struct sk_buff *skb; 125297c63746SJohn Crispin int ret; 125397c63746SJohn Crispin 12546bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 125597c63746SJohn Crispin if (!skb) 125697c63746SJohn Crispin return -ENOMEM; 125797c63746SJohn Crispin 125897c63746SJohn Crispin cmd = (struct wmi_pdev_set_ps_mode_cmd *)skb->data; 125997c63746SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STA_POWERSAVE_MODE_CMD) | 126097c63746SJohn Crispin FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 126197c63746SJohn Crispin cmd->vdev_id = vdev_id; 126297c63746SJohn Crispin cmd->sta_ps_mode = enable; 126397c63746SJohn Crispin 126497c63746SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_MODE_CMDID); 126597c63746SJohn Crispin if (ret) { 126697c63746SJohn Crispin ath11k_warn(ar->ab, "failed to send WMI_PDEV_SET_PARAM cmd\n"); 126797c63746SJohn Crispin dev_kfree_skb(skb); 126897c63746SJohn Crispin } 126997c63746SJohn Crispin 127097c63746SJohn Crispin ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 127197c63746SJohn Crispin "WMI vdev set psmode %d vdev id %d\n", 127297c63746SJohn Crispin enable, vdev_id); 127397c63746SJohn Crispin 127497c63746SJohn Crispin return ret; 127597c63746SJohn Crispin } 127697c63746SJohn Crispin 1277d5c65159SKalle Valo int ath11k_wmi_pdev_suspend(struct ath11k *ar, u32 suspend_opt, 1278d5c65159SKalle Valo u32 pdev_id) 1279d5c65159SKalle Valo { 1280d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1281d5c65159SKalle Valo struct wmi_pdev_suspend_cmd *cmd; 1282d5c65159SKalle Valo struct sk_buff *skb; 1283d5c65159SKalle Valo int ret; 1284d5c65159SKalle Valo 12856bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1286d5c65159SKalle Valo if (!skb) 1287d5c65159SKalle Valo return -ENOMEM; 1288d5c65159SKalle Valo 1289d5c65159SKalle Valo cmd = (struct wmi_pdev_suspend_cmd *)skb->data; 1290d5c65159SKalle Valo 1291d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SUSPEND_CMD) | 1292d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1293d5c65159SKalle Valo 1294d5c65159SKalle Valo cmd->suspend_opt = suspend_opt; 1295d5c65159SKalle Valo cmd->pdev_id = pdev_id; 1296d5c65159SKalle Valo 1297d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_SUSPEND_CMDID); 1298d5c65159SKalle Valo if (ret) { 1299d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_SUSPEND cmd\n"); 1300d5c65159SKalle Valo dev_kfree_skb(skb); 1301d5c65159SKalle Valo } 1302d5c65159SKalle Valo 1303d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1304d5c65159SKalle Valo "WMI pdev suspend pdev_id %d\n", pdev_id); 1305d5c65159SKalle Valo 1306d5c65159SKalle Valo return ret; 1307d5c65159SKalle Valo } 1308d5c65159SKalle Valo 1309d5c65159SKalle Valo int ath11k_wmi_pdev_resume(struct ath11k *ar, u32 pdev_id) 1310d5c65159SKalle Valo { 1311d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1312d5c65159SKalle Valo struct wmi_pdev_resume_cmd *cmd; 1313d5c65159SKalle Valo struct sk_buff *skb; 1314d5c65159SKalle Valo int ret; 1315d5c65159SKalle Valo 13166bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1317d5c65159SKalle Valo if (!skb) 1318d5c65159SKalle Valo return -ENOMEM; 1319d5c65159SKalle Valo 1320d5c65159SKalle Valo cmd = (struct wmi_pdev_resume_cmd *)skb->data; 1321d5c65159SKalle Valo 1322d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_RESUME_CMD) | 1323d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1324d5c65159SKalle Valo cmd->pdev_id = pdev_id; 1325d5c65159SKalle Valo 1326d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1327d5c65159SKalle Valo "WMI pdev resume pdev id %d\n", pdev_id); 1328d5c65159SKalle Valo 1329d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_RESUME_CMDID); 1330d5c65159SKalle Valo if (ret) { 1331d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_RESUME cmd\n"); 1332d5c65159SKalle Valo dev_kfree_skb(skb); 1333d5c65159SKalle Valo } 1334d5c65159SKalle Valo 1335d5c65159SKalle Valo return ret; 1336d5c65159SKalle Valo } 1337d5c65159SKalle Valo 1338d5c65159SKalle Valo /* TODO FW Support for the cmd is not available yet. 1339d5c65159SKalle Valo * Can be tested once the command and corresponding 1340d5c65159SKalle Valo * event is implemented in FW 1341d5c65159SKalle Valo */ 1342d5c65159SKalle Valo int ath11k_wmi_pdev_bss_chan_info_request(struct ath11k *ar, 1343d5c65159SKalle Valo enum wmi_bss_chan_info_req_type type) 1344d5c65159SKalle Valo { 1345d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1346d5c65159SKalle Valo struct wmi_pdev_bss_chan_info_req_cmd *cmd; 1347d5c65159SKalle Valo struct sk_buff *skb; 1348d5c65159SKalle Valo int ret; 1349d5c65159SKalle Valo 13506bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1351d5c65159SKalle Valo if (!skb) 1352d5c65159SKalle Valo return -ENOMEM; 1353d5c65159SKalle Valo 1354d5c65159SKalle Valo cmd = (struct wmi_pdev_bss_chan_info_req_cmd *)skb->data; 1355d5c65159SKalle Valo 1356d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1357d5c65159SKalle Valo WMI_TAG_PDEV_BSS_CHAN_INFO_REQUEST) | 1358d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1359d5c65159SKalle Valo cmd->req_type = type; 1360feab5bb8SSeevalamuthu Mariappan cmd->pdev_id = ar->pdev->pdev_id; 1361d5c65159SKalle Valo 1362d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1363d5c65159SKalle Valo "WMI bss chan info req type %d\n", type); 1364d5c65159SKalle Valo 1365d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 1366d5c65159SKalle Valo WMI_PDEV_BSS_CHAN_INFO_REQUEST_CMDID); 1367d5c65159SKalle Valo if (ret) { 1368d5c65159SKalle Valo ath11k_warn(ar->ab, 1369d5c65159SKalle Valo "failed to send WMI_PDEV_BSS_CHAN_INFO_REQUEST cmd\n"); 1370d5c65159SKalle Valo dev_kfree_skb(skb); 1371d5c65159SKalle Valo } 1372d5c65159SKalle Valo 1373d5c65159SKalle Valo return ret; 1374d5c65159SKalle Valo } 1375d5c65159SKalle Valo 1376d5c65159SKalle Valo int ath11k_wmi_send_set_ap_ps_param_cmd(struct ath11k *ar, u8 *peer_addr, 1377d5c65159SKalle Valo struct ap_ps_params *param) 1378d5c65159SKalle Valo { 1379d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1380d5c65159SKalle Valo struct wmi_ap_ps_peer_cmd *cmd; 1381d5c65159SKalle Valo struct sk_buff *skb; 1382d5c65159SKalle Valo int ret; 1383d5c65159SKalle Valo 13846bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1385d5c65159SKalle Valo if (!skb) 1386d5c65159SKalle Valo return -ENOMEM; 1387d5c65159SKalle Valo 1388d5c65159SKalle Valo cmd = (struct wmi_ap_ps_peer_cmd *)skb->data; 1389d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_AP_PS_PEER_CMD) | 1390d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1391d5c65159SKalle Valo 1392d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 1393d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, peer_addr); 1394d5c65159SKalle Valo cmd->param = param->param; 1395d5c65159SKalle Valo cmd->value = param->value; 1396d5c65159SKalle Valo 1397d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_AP_PS_PEER_PARAM_CMDID); 1398d5c65159SKalle Valo if (ret) { 1399d5c65159SKalle Valo ath11k_warn(ar->ab, 1400d5c65159SKalle Valo "failed to send WMI_AP_PS_PEER_PARAM_CMDID\n"); 1401d5c65159SKalle Valo dev_kfree_skb(skb); 1402d5c65159SKalle Valo } 1403d5c65159SKalle Valo 1404d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1405d5c65159SKalle Valo "WMI set ap ps vdev id %d peer %pM param %d value %d\n", 1406d5c65159SKalle Valo param->vdev_id, peer_addr, param->param, param->value); 1407d5c65159SKalle Valo 1408d5c65159SKalle Valo return ret; 1409d5c65159SKalle Valo } 1410d5c65159SKalle Valo 1411d5c65159SKalle Valo int ath11k_wmi_set_sta_ps_param(struct ath11k *ar, u32 vdev_id, 1412d5c65159SKalle Valo u32 param, u32 param_value) 1413d5c65159SKalle Valo { 1414d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1415d5c65159SKalle Valo struct wmi_sta_powersave_param_cmd *cmd; 1416d5c65159SKalle Valo struct sk_buff *skb; 1417d5c65159SKalle Valo int ret; 1418d5c65159SKalle Valo 14196bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1420d5c65159SKalle Valo if (!skb) 1421d5c65159SKalle Valo return -ENOMEM; 1422d5c65159SKalle Valo 1423d5c65159SKalle Valo cmd = (struct wmi_sta_powersave_param_cmd *)skb->data; 1424d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1425d5c65159SKalle Valo WMI_TAG_STA_POWERSAVE_PARAM_CMD) | 1426d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1427d5c65159SKalle Valo 1428d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1429d5c65159SKalle Valo cmd->param = param; 1430d5c65159SKalle Valo cmd->value = param_value; 1431d5c65159SKalle Valo 1432d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1433d5c65159SKalle Valo "WMI set sta ps vdev_id %d param %d value %d\n", 1434d5c65159SKalle Valo vdev_id, param, param_value); 1435d5c65159SKalle Valo 1436d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_STA_POWERSAVE_PARAM_CMDID); 1437d5c65159SKalle Valo if (ret) { 1438d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_STA_POWERSAVE_PARAM_CMDID"); 1439d5c65159SKalle Valo dev_kfree_skb(skb); 1440d5c65159SKalle Valo } 1441d5c65159SKalle Valo 1442d5c65159SKalle Valo return ret; 1443d5c65159SKalle Valo } 1444d5c65159SKalle Valo 1445d5c65159SKalle Valo int ath11k_wmi_force_fw_hang_cmd(struct ath11k *ar, u32 type, u32 delay_time_ms) 1446d5c65159SKalle Valo { 1447d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1448d5c65159SKalle Valo struct wmi_force_fw_hang_cmd *cmd; 1449d5c65159SKalle Valo struct sk_buff *skb; 1450d5c65159SKalle Valo int ret, len; 1451d5c65159SKalle Valo 1452d5c65159SKalle Valo len = sizeof(*cmd); 1453d5c65159SKalle Valo 14546bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1455d5c65159SKalle Valo if (!skb) 1456d5c65159SKalle Valo return -ENOMEM; 1457d5c65159SKalle Valo 1458d5c65159SKalle Valo cmd = (struct wmi_force_fw_hang_cmd *)skb->data; 1459d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_FORCE_FW_HANG_CMD) | 1460d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 1461d5c65159SKalle Valo 1462d5c65159SKalle Valo cmd->type = type; 1463d5c65159SKalle Valo cmd->delay_time_ms = delay_time_ms; 1464d5c65159SKalle Valo 1465d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_FORCE_FW_HANG_CMDID); 1466d5c65159SKalle Valo 1467d5c65159SKalle Valo if (ret) { 1468d5c65159SKalle Valo ath11k_warn(ar->ab, "Failed to send WMI_FORCE_FW_HANG_CMDID"); 1469d5c65159SKalle Valo dev_kfree_skb(skb); 1470d5c65159SKalle Valo } 1471d5c65159SKalle Valo return ret; 1472d5c65159SKalle Valo } 1473d5c65159SKalle Valo 1474d5c65159SKalle Valo int ath11k_wmi_vdev_set_param_cmd(struct ath11k *ar, u32 vdev_id, 1475d5c65159SKalle Valo u32 param_id, u32 param_value) 1476d5c65159SKalle Valo { 1477d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1478d5c65159SKalle Valo struct wmi_vdev_set_param_cmd *cmd; 1479d5c65159SKalle Valo struct sk_buff *skb; 1480d5c65159SKalle Valo int ret; 1481d5c65159SKalle Valo 14826bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1483d5c65159SKalle Valo if (!skb) 1484d5c65159SKalle Valo return -ENOMEM; 1485d5c65159SKalle Valo 1486d5c65159SKalle Valo cmd = (struct wmi_vdev_set_param_cmd *)skb->data; 1487d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_SET_PARAM_CMD) | 1488d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1489d5c65159SKalle Valo 1490d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1491d5c65159SKalle Valo cmd->param_id = param_id; 1492d5c65159SKalle Valo cmd->param_value = param_value; 1493d5c65159SKalle Valo 1494d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_SET_PARAM_CMDID); 1495d5c65159SKalle Valo if (ret) { 1496d5c65159SKalle Valo ath11k_warn(ar->ab, 1497d5c65159SKalle Valo "failed to send WMI_VDEV_SET_PARAM_CMDID\n"); 1498d5c65159SKalle Valo dev_kfree_skb(skb); 1499d5c65159SKalle Valo } 1500d5c65159SKalle Valo 1501d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1502d5c65159SKalle Valo "WMI vdev id 0x%x set param %d value %d\n", 1503d5c65159SKalle Valo vdev_id, param_id, param_value); 1504d5c65159SKalle Valo 1505d5c65159SKalle Valo return ret; 1506d5c65159SKalle Valo } 1507d5c65159SKalle Valo 1508d5c65159SKalle Valo int ath11k_wmi_send_stats_request_cmd(struct ath11k *ar, 1509d5c65159SKalle Valo struct stats_request_params *param) 1510d5c65159SKalle Valo { 1511d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1512d5c65159SKalle Valo struct wmi_request_stats_cmd *cmd; 1513d5c65159SKalle Valo struct sk_buff *skb; 1514d5c65159SKalle Valo int ret; 1515d5c65159SKalle Valo 15166bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1517d5c65159SKalle Valo if (!skb) 1518d5c65159SKalle Valo return -ENOMEM; 1519d5c65159SKalle Valo 1520d5c65159SKalle Valo cmd = (struct wmi_request_stats_cmd *)skb->data; 1521d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_REQUEST_STATS_CMD) | 1522d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1523d5c65159SKalle Valo 1524d5c65159SKalle Valo cmd->stats_id = param->stats_id; 1525d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 1526d5c65159SKalle Valo cmd->pdev_id = param->pdev_id; 1527d5c65159SKalle Valo 1528d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_REQUEST_STATS_CMDID); 1529d5c65159SKalle Valo if (ret) { 1530d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_REQUEST_STATS cmd\n"); 1531d5c65159SKalle Valo dev_kfree_skb(skb); 1532d5c65159SKalle Valo } 1533d5c65159SKalle Valo 1534d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1535d5c65159SKalle Valo "WMI request stats 0x%x vdev id %d pdev id %d\n", 1536d5c65159SKalle Valo param->stats_id, param->vdev_id, param->pdev_id); 1537d5c65159SKalle Valo 1538d5c65159SKalle Valo return ret; 1539d5c65159SKalle Valo } 1540d5c65159SKalle Valo 1541a41d1034SPradeep Kumar Chitrapu int ath11k_wmi_send_pdev_temperature_cmd(struct ath11k *ar) 1542a41d1034SPradeep Kumar Chitrapu { 1543a41d1034SPradeep Kumar Chitrapu struct ath11k_pdev_wmi *wmi = ar->wmi; 1544a41d1034SPradeep Kumar Chitrapu struct wmi_get_pdev_temperature_cmd *cmd; 1545a41d1034SPradeep Kumar Chitrapu struct sk_buff *skb; 1546a41d1034SPradeep Kumar Chitrapu int ret; 1547a41d1034SPradeep Kumar Chitrapu 1548a41d1034SPradeep Kumar Chitrapu skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1549a41d1034SPradeep Kumar Chitrapu if (!skb) 1550a41d1034SPradeep Kumar Chitrapu return -ENOMEM; 1551a41d1034SPradeep Kumar Chitrapu 1552a41d1034SPradeep Kumar Chitrapu cmd = (struct wmi_get_pdev_temperature_cmd *)skb->data; 1553a41d1034SPradeep Kumar Chitrapu cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_GET_TEMPERATURE_CMD) | 1554a41d1034SPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1555a41d1034SPradeep Kumar Chitrapu cmd->pdev_id = ar->pdev->pdev_id; 1556a41d1034SPradeep Kumar Chitrapu 1557a41d1034SPradeep Kumar Chitrapu ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PDEV_GET_TEMPERATURE_CMDID); 1558a41d1034SPradeep Kumar Chitrapu if (ret) { 1559a41d1034SPradeep Kumar Chitrapu ath11k_warn(ar->ab, "failed to send WMI_PDEV_GET_TEMPERATURE cmd\n"); 1560a41d1034SPradeep Kumar Chitrapu dev_kfree_skb(skb); 1561a41d1034SPradeep Kumar Chitrapu } 1562a41d1034SPradeep Kumar Chitrapu 1563a41d1034SPradeep Kumar Chitrapu ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1564a41d1034SPradeep Kumar Chitrapu "WMI pdev get temperature for pdev_id %d\n", ar->pdev->pdev_id); 1565a41d1034SPradeep Kumar Chitrapu 1566a41d1034SPradeep Kumar Chitrapu return ret; 1567a41d1034SPradeep Kumar Chitrapu } 1568a41d1034SPradeep Kumar Chitrapu 1569d5c65159SKalle Valo int ath11k_wmi_send_bcn_offload_control_cmd(struct ath11k *ar, 1570d5c65159SKalle Valo u32 vdev_id, u32 bcn_ctrl_op) 1571d5c65159SKalle Valo { 1572d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1573d5c65159SKalle Valo struct wmi_bcn_offload_ctrl_cmd *cmd; 1574d5c65159SKalle Valo struct sk_buff *skb; 1575d5c65159SKalle Valo int ret; 1576d5c65159SKalle Valo 15776bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 1578d5c65159SKalle Valo if (!skb) 1579d5c65159SKalle Valo return -ENOMEM; 1580d5c65159SKalle Valo 1581d5c65159SKalle Valo cmd = (struct wmi_bcn_offload_ctrl_cmd *)skb->data; 1582d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1583d5c65159SKalle Valo WMI_TAG_BCN_OFFLOAD_CTRL_CMD) | 1584d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1585d5c65159SKalle Valo 1586d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1587d5c65159SKalle Valo cmd->bcn_ctrl_op = bcn_ctrl_op; 1588d5c65159SKalle Valo 1589d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1590d5c65159SKalle Valo "WMI bcn ctrl offload vdev id %d ctrl_op %d\n", 1591d5c65159SKalle Valo vdev_id, bcn_ctrl_op); 1592d5c65159SKalle Valo 1593d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_OFFLOAD_CTRL_CMDID); 1594d5c65159SKalle Valo if (ret) { 1595d5c65159SKalle Valo ath11k_warn(ar->ab, 1596d5c65159SKalle Valo "failed to send WMI_BCN_OFFLOAD_CTRL_CMDID\n"); 1597d5c65159SKalle Valo dev_kfree_skb(skb); 1598d5c65159SKalle Valo } 1599d5c65159SKalle Valo 1600d5c65159SKalle Valo return ret; 1601d5c65159SKalle Valo } 1602d5c65159SKalle Valo 1603d5c65159SKalle Valo int ath11k_wmi_bcn_tmpl(struct ath11k *ar, u32 vdev_id, 1604d5c65159SKalle Valo struct ieee80211_mutable_offsets *offs, 1605d5c65159SKalle Valo struct sk_buff *bcn) 1606d5c65159SKalle Valo { 1607d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1608d5c65159SKalle Valo struct wmi_bcn_tmpl_cmd *cmd; 1609d5c65159SKalle Valo struct wmi_bcn_prb_info *bcn_prb_info; 1610d5c65159SKalle Valo struct wmi_tlv *tlv; 1611d5c65159SKalle Valo struct sk_buff *skb; 1612d5c65159SKalle Valo void *ptr; 1613d5c65159SKalle Valo int ret, len; 1614d5c65159SKalle Valo size_t aligned_len = roundup(bcn->len, 4); 1615d5c65159SKalle Valo 1616d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*bcn_prb_info) + TLV_HDR_SIZE + aligned_len; 1617d5c65159SKalle Valo 16186bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1619d5c65159SKalle Valo if (!skb) 1620d5c65159SKalle Valo return -ENOMEM; 1621d5c65159SKalle Valo 1622d5c65159SKalle Valo cmd = (struct wmi_bcn_tmpl_cmd *)skb->data; 1623d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BCN_TMPL_CMD) | 1624d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1625d5c65159SKalle Valo cmd->vdev_id = vdev_id; 1626d5c65159SKalle Valo cmd->tim_ie_offset = offs->tim_offset; 16278552a434SJohn Crispin cmd->csa_switch_count_offset = offs->cntdwn_counter_offs[0]; 16288552a434SJohn Crispin cmd->ext_csa_switch_count_offset = offs->cntdwn_counter_offs[1]; 1629d5c65159SKalle Valo cmd->buf_len = bcn->len; 1630d5c65159SKalle Valo 1631d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd); 1632d5c65159SKalle Valo 1633d5c65159SKalle Valo bcn_prb_info = ptr; 1634d5c65159SKalle Valo len = sizeof(*bcn_prb_info); 1635d5c65159SKalle Valo bcn_prb_info->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1636d5c65159SKalle Valo WMI_TAG_BCN_PRB_INFO) | 1637d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 1638d5c65159SKalle Valo bcn_prb_info->caps = 0; 1639d5c65159SKalle Valo bcn_prb_info->erp = 0; 1640d5c65159SKalle Valo 1641d5c65159SKalle Valo ptr += sizeof(*bcn_prb_info); 1642d5c65159SKalle Valo 1643d5c65159SKalle Valo tlv = ptr; 1644d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1645d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, aligned_len); 1646d5c65159SKalle Valo memcpy(tlv->value, bcn->data, bcn->len); 1647d5c65159SKalle Valo 1648d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_BCN_TMPL_CMDID); 1649d5c65159SKalle Valo if (ret) { 1650d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_BCN_TMPL_CMDID\n"); 1651d5c65159SKalle Valo dev_kfree_skb(skb); 1652d5c65159SKalle Valo } 1653d5c65159SKalle Valo 1654d5c65159SKalle Valo return ret; 1655d5c65159SKalle Valo } 1656d5c65159SKalle Valo 1657d5c65159SKalle Valo int ath11k_wmi_vdev_install_key(struct ath11k *ar, 1658d5c65159SKalle Valo struct wmi_vdev_install_key_arg *arg) 1659d5c65159SKalle Valo { 1660d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1661d5c65159SKalle Valo struct wmi_vdev_install_key_cmd *cmd; 1662d5c65159SKalle Valo struct wmi_tlv *tlv; 1663d5c65159SKalle Valo struct sk_buff *skb; 1664d5c65159SKalle Valo int ret, len; 1665d5c65159SKalle Valo int key_len_aligned = roundup(arg->key_len, sizeof(uint32_t)); 1666d5c65159SKalle Valo 1667d5c65159SKalle Valo len = sizeof(*cmd) + TLV_HDR_SIZE + key_len_aligned; 1668d5c65159SKalle Valo 16696bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1670d5c65159SKalle Valo if (!skb) 1671d5c65159SKalle Valo return -ENOMEM; 1672d5c65159SKalle Valo 1673d5c65159SKalle Valo cmd = (struct wmi_vdev_install_key_cmd *)skb->data; 1674d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VDEV_INSTALL_KEY_CMD) | 1675d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1676d5c65159SKalle Valo cmd->vdev_id = arg->vdev_id; 1677d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr); 1678d5c65159SKalle Valo cmd->key_idx = arg->key_idx; 1679d5c65159SKalle Valo cmd->key_flags = arg->key_flags; 1680d5c65159SKalle Valo cmd->key_cipher = arg->key_cipher; 1681d5c65159SKalle Valo cmd->key_len = arg->key_len; 1682d5c65159SKalle Valo cmd->key_txmic_len = arg->key_txmic_len; 1683d5c65159SKalle Valo cmd->key_rxmic_len = arg->key_rxmic_len; 1684d5c65159SKalle Valo 1685d5c65159SKalle Valo if (arg->key_rsc_counter) 1686d5c65159SKalle Valo memcpy(&cmd->key_rsc_counter, &arg->key_rsc_counter, 1687d5c65159SKalle Valo sizeof(struct wmi_key_seq_counter)); 1688d5c65159SKalle Valo 1689d5c65159SKalle Valo tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd)); 1690d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1691d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, key_len_aligned); 1692d5c65159SKalle Valo memcpy(tlv->value, (u8 *)arg->key_data, key_len_aligned); 1693d5c65159SKalle Valo 1694d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_VDEV_INSTALL_KEY_CMDID); 1695d5c65159SKalle Valo if (ret) { 1696d5c65159SKalle Valo ath11k_warn(ar->ab, 1697d5c65159SKalle Valo "failed to send WMI_VDEV_INSTALL_KEY cmd\n"); 1698d5c65159SKalle Valo dev_kfree_skb(skb); 1699d5c65159SKalle Valo } 1700d5c65159SKalle Valo 1701d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 1702d5c65159SKalle Valo "WMI vdev install key idx %d cipher %d len %d\n", 1703d5c65159SKalle Valo arg->key_idx, arg->key_cipher, arg->key_len); 1704d5c65159SKalle Valo 1705d5c65159SKalle Valo return ret; 1706d5c65159SKalle Valo } 1707d5c65159SKalle Valo 1708d5c65159SKalle Valo static inline void 1709d5c65159SKalle Valo ath11k_wmi_copy_peer_flags(struct wmi_peer_assoc_complete_cmd *cmd, 17101daf58b2SSeevalamuthu Mariappan struct peer_assoc_params *param, 17111daf58b2SSeevalamuthu Mariappan bool hw_crypto_disabled) 1712d5c65159SKalle Valo { 1713d5c65159SKalle Valo cmd->peer_flags = 0; 1714d5c65159SKalle Valo 1715d5c65159SKalle Valo if (param->is_wme_set) { 1716d5c65159SKalle Valo if (param->qos_flag) 1717d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_QOS; 1718d5c65159SKalle Valo if (param->apsd_flag) 1719d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_APSD; 1720d5c65159SKalle Valo if (param->ht_flag) 1721d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_HT; 1722d5c65159SKalle Valo if (param->bw_40) 1723d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_40MHZ; 1724d5c65159SKalle Valo if (param->bw_80) 1725d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_80MHZ; 1726d5c65159SKalle Valo if (param->bw_160) 1727d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_160MHZ; 1728d5c65159SKalle Valo 1729d5c65159SKalle Valo /* Typically if STBC is enabled for VHT it should be enabled 1730d5c65159SKalle Valo * for HT as well 1731d5c65159SKalle Valo **/ 1732d5c65159SKalle Valo if (param->stbc_flag) 1733d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_STBC; 1734d5c65159SKalle Valo 1735d5c65159SKalle Valo /* Typically if LDPC is enabled for VHT it should be enabled 1736d5c65159SKalle Valo * for HT as well 1737d5c65159SKalle Valo **/ 1738d5c65159SKalle Valo if (param->ldpc_flag) 1739d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_LDPC; 1740d5c65159SKalle Valo 1741d5c65159SKalle Valo if (param->static_mimops_flag) 1742d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_STATIC_MIMOPS; 1743d5c65159SKalle Valo if (param->dynamic_mimops_flag) 1744d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_DYN_MIMOPS; 1745d5c65159SKalle Valo if (param->spatial_mux_flag) 1746d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_SPATIAL_MUX; 1747d5c65159SKalle Valo if (param->vht_flag) 1748d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_VHT; 1749d5c65159SKalle Valo if (param->he_flag) 1750d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_HE; 17516d293d44SJohn Crispin if (param->twt_requester) 17526d293d44SJohn Crispin cmd->peer_flags |= WMI_PEER_TWT_REQ; 17536d293d44SJohn Crispin if (param->twt_responder) 17546d293d44SJohn Crispin cmd->peer_flags |= WMI_PEER_TWT_RESP; 1755d5c65159SKalle Valo } 1756d5c65159SKalle Valo 1757d5c65159SKalle Valo /* Suppress authorization for all AUTH modes that need 4-way handshake 1758d5c65159SKalle Valo * (during re-association). 1759d5c65159SKalle Valo * Authorization will be done for these modes on key installation. 1760d5c65159SKalle Valo */ 1761d5c65159SKalle Valo if (param->auth_flag) 1762d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_AUTH; 176301e34233SVenkateswara Naralasetty if (param->need_ptk_4_way) { 1764d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; 17651daf58b2SSeevalamuthu Mariappan if (!hw_crypto_disabled) 176601e34233SVenkateswara Naralasetty cmd->peer_flags &= ~WMI_PEER_AUTH; 176701e34233SVenkateswara Naralasetty } 1768d5c65159SKalle Valo if (param->need_gtk_2_way) 1769d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; 1770d5c65159SKalle Valo /* safe mode bypass the 4-way handshake */ 1771d5c65159SKalle Valo if (param->safe_mode_enabled) 1772d5c65159SKalle Valo cmd->peer_flags &= ~(WMI_PEER_NEED_PTK_4_WAY | 1773d5c65159SKalle Valo WMI_PEER_NEED_GTK_2_WAY); 1774d5c65159SKalle Valo 1775d5c65159SKalle Valo if (param->is_pmf_enabled) 1776d5c65159SKalle Valo cmd->peer_flags |= WMI_PEER_PMF; 1777d5c65159SKalle Valo 1778d5c65159SKalle Valo /* Disable AMSDU for station transmit, if user configures it */ 1779d5c65159SKalle Valo /* Disable AMSDU for AP transmit to 11n Stations, if user configures 1780d5c65159SKalle Valo * it 1781d5c65159SKalle Valo * if (param->amsdu_disable) Add after FW support 1782d5c65159SKalle Valo **/ 1783d5c65159SKalle Valo 1784d5c65159SKalle Valo /* Target asserts if node is marked HT and all MCS is set to 0. 1785d5c65159SKalle Valo * Mark the node as non-HT if all the mcs rates are disabled through 1786d5c65159SKalle Valo * iwpriv 1787d5c65159SKalle Valo **/ 1788d5c65159SKalle Valo if (param->peer_ht_rates.num_rates == 0) 1789d5c65159SKalle Valo cmd->peer_flags &= ~WMI_PEER_HT; 1790d5c65159SKalle Valo } 1791d5c65159SKalle Valo 1792d5c65159SKalle Valo int ath11k_wmi_send_peer_assoc_cmd(struct ath11k *ar, 1793d5c65159SKalle Valo struct peer_assoc_params *param) 1794d5c65159SKalle Valo { 1795d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 1796d5c65159SKalle Valo struct wmi_peer_assoc_complete_cmd *cmd; 1797d5c65159SKalle Valo struct wmi_vht_rate_set *mcs; 1798d5c65159SKalle Valo struct wmi_he_rate_set *he_mcs; 1799d5c65159SKalle Valo struct sk_buff *skb; 1800d5c65159SKalle Valo struct wmi_tlv *tlv; 1801d5c65159SKalle Valo void *ptr; 1802d5c65159SKalle Valo u32 peer_legacy_rates_align; 1803d5c65159SKalle Valo u32 peer_ht_rates_align; 1804d5c65159SKalle Valo int i, ret, len; 1805d5c65159SKalle Valo 1806d5c65159SKalle Valo peer_legacy_rates_align = roundup(param->peer_legacy_rates.num_rates, 1807d5c65159SKalle Valo sizeof(u32)); 1808d5c65159SKalle Valo peer_ht_rates_align = roundup(param->peer_ht_rates.num_rates, 1809d5c65159SKalle Valo sizeof(u32)); 1810d5c65159SKalle Valo 1811d5c65159SKalle Valo len = sizeof(*cmd) + 1812d5c65159SKalle Valo TLV_HDR_SIZE + (peer_legacy_rates_align * sizeof(u8)) + 1813d5c65159SKalle Valo TLV_HDR_SIZE + (peer_ht_rates_align * sizeof(u8)) + 1814d5c65159SKalle Valo sizeof(*mcs) + TLV_HDR_SIZE + 1815d5c65159SKalle Valo (sizeof(*he_mcs) * param->peer_he_mcs_count); 1816d5c65159SKalle Valo 18176bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 1818d5c65159SKalle Valo if (!skb) 1819d5c65159SKalle Valo return -ENOMEM; 1820d5c65159SKalle Valo 1821d5c65159SKalle Valo ptr = skb->data; 1822d5c65159SKalle Valo 1823d5c65159SKalle Valo cmd = ptr; 1824d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1825d5c65159SKalle Valo WMI_TAG_PEER_ASSOC_COMPLETE_CMD) | 1826d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 1827d5c65159SKalle Valo 1828d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 1829d5c65159SKalle Valo 1830d5c65159SKalle Valo cmd->peer_new_assoc = param->peer_new_assoc; 1831d5c65159SKalle Valo cmd->peer_associd = param->peer_associd; 1832d5c65159SKalle Valo 18331daf58b2SSeevalamuthu Mariappan ath11k_wmi_copy_peer_flags(cmd, param, 18341daf58b2SSeevalamuthu Mariappan test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, 18351daf58b2SSeevalamuthu Mariappan &ar->ab->dev_flags)); 1836d5c65159SKalle Valo 1837d5c65159SKalle Valo ether_addr_copy(cmd->peer_macaddr.addr, param->peer_mac); 1838d5c65159SKalle Valo 1839d5c65159SKalle Valo cmd->peer_rate_caps = param->peer_rate_caps; 1840d5c65159SKalle Valo cmd->peer_caps = param->peer_caps; 1841d5c65159SKalle Valo cmd->peer_listen_intval = param->peer_listen_intval; 1842d5c65159SKalle Valo cmd->peer_ht_caps = param->peer_ht_caps; 1843d5c65159SKalle Valo cmd->peer_max_mpdu = param->peer_max_mpdu; 1844d5c65159SKalle Valo cmd->peer_mpdu_density = param->peer_mpdu_density; 1845d5c65159SKalle Valo cmd->peer_vht_caps = param->peer_vht_caps; 1846d5c65159SKalle Valo cmd->peer_phymode = param->peer_phymode; 1847d5c65159SKalle Valo 1848d5c65159SKalle Valo /* Update 11ax capabilities */ 1849d5c65159SKalle Valo cmd->peer_he_cap_info = param->peer_he_cap_macinfo[0]; 1850d5c65159SKalle Valo cmd->peer_he_cap_info_ext = param->peer_he_cap_macinfo[1]; 1851d5c65159SKalle Valo cmd->peer_he_cap_info_internal = param->peer_he_cap_macinfo_internal; 185291270d70SPradeep Kumar Chitrapu cmd->peer_he_caps_6ghz = param->peer_he_caps_6ghz; 1853d5c65159SKalle Valo cmd->peer_he_ops = param->peer_he_ops; 1854d5c65159SKalle Valo memcpy(&cmd->peer_he_cap_phy, ¶m->peer_he_cap_phyinfo, 1855d5c65159SKalle Valo sizeof(param->peer_he_cap_phyinfo)); 1856d5c65159SKalle Valo memcpy(&cmd->peer_ppet, ¶m->peer_ppet, 1857d5c65159SKalle Valo sizeof(param->peer_ppet)); 1858d5c65159SKalle Valo 1859d5c65159SKalle Valo /* Update peer legacy rate information */ 1860d5c65159SKalle Valo ptr += sizeof(*cmd); 1861d5c65159SKalle Valo 1862d5c65159SKalle Valo tlv = ptr; 1863d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1864d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, peer_legacy_rates_align); 1865d5c65159SKalle Valo 1866d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 1867d5c65159SKalle Valo 1868d5c65159SKalle Valo cmd->num_peer_legacy_rates = param->peer_legacy_rates.num_rates; 1869d5c65159SKalle Valo memcpy(ptr, param->peer_legacy_rates.rates, 1870d5c65159SKalle Valo param->peer_legacy_rates.num_rates); 1871d5c65159SKalle Valo 1872d5c65159SKalle Valo /* Update peer HT rate information */ 1873d5c65159SKalle Valo ptr += peer_legacy_rates_align; 1874d5c65159SKalle Valo 1875d5c65159SKalle Valo tlv = ptr; 1876d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 1877d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, peer_ht_rates_align); 1878d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 1879d5c65159SKalle Valo cmd->num_peer_ht_rates = param->peer_ht_rates.num_rates; 1880d5c65159SKalle Valo memcpy(ptr, param->peer_ht_rates.rates, 1881d5c65159SKalle Valo param->peer_ht_rates.num_rates); 1882d5c65159SKalle Valo 1883d5c65159SKalle Valo /* VHT Rates */ 1884d5c65159SKalle Valo ptr += peer_ht_rates_align; 1885d5c65159SKalle Valo 1886d5c65159SKalle Valo mcs = ptr; 1887d5c65159SKalle Valo 1888d5c65159SKalle Valo mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_VHT_RATE_SET) | 1889d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*mcs) - TLV_HDR_SIZE); 1890d5c65159SKalle Valo 1891d5c65159SKalle Valo cmd->peer_nss = param->peer_nss; 1892d5c65159SKalle Valo 1893d5c65159SKalle Valo /* Update bandwidth-NSS mapping */ 1894d5c65159SKalle Valo cmd->peer_bw_rxnss_override = 0; 1895d5c65159SKalle Valo cmd->peer_bw_rxnss_override |= param->peer_bw_rxnss_override; 1896d5c65159SKalle Valo 1897d5c65159SKalle Valo if (param->vht_capable) { 1898d5c65159SKalle Valo mcs->rx_max_rate = param->rx_max_rate; 1899d5c65159SKalle Valo mcs->rx_mcs_set = param->rx_mcs_set; 1900d5c65159SKalle Valo mcs->tx_max_rate = param->tx_max_rate; 1901d5c65159SKalle Valo mcs->tx_mcs_set = param->tx_mcs_set; 1902d5c65159SKalle Valo } 1903d5c65159SKalle Valo 1904d5c65159SKalle Valo /* HE Rates */ 1905d5c65159SKalle Valo cmd->peer_he_mcs = param->peer_he_mcs_count; 190691270d70SPradeep Kumar Chitrapu cmd->min_data_rate = param->min_data_rate; 1907d5c65159SKalle Valo 1908d5c65159SKalle Valo ptr += sizeof(*mcs); 1909d5c65159SKalle Valo 1910d5c65159SKalle Valo len = param->peer_he_mcs_count * sizeof(*he_mcs); 1911d5c65159SKalle Valo 1912d5c65159SKalle Valo tlv = ptr; 1913d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 1914d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 1915d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 1916d5c65159SKalle Valo 1917d5c65159SKalle Valo /* Loop through the HE rate set */ 1918d5c65159SKalle Valo for (i = 0; i < param->peer_he_mcs_count; i++) { 1919d5c65159SKalle Valo he_mcs = ptr; 1920d5c65159SKalle Valo he_mcs->tlv_header = FIELD_PREP(WMI_TLV_TAG, 1921d5c65159SKalle Valo WMI_TAG_HE_RATE_SET) | 1922d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 1923d5c65159SKalle Valo sizeof(*he_mcs) - TLV_HDR_SIZE); 1924d5c65159SKalle Valo 192561fe43e7SMiles Hu he_mcs->rx_mcs_set = param->peer_he_tx_mcs_set[i]; 192661fe43e7SMiles Hu he_mcs->tx_mcs_set = param->peer_he_rx_mcs_set[i]; 1927d5c65159SKalle Valo ptr += sizeof(*he_mcs); 1928d5c65159SKalle Valo } 1929d5c65159SKalle Valo 1930d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_PEER_ASSOC_CMDID); 1931d5c65159SKalle Valo if (ret) { 1932d5c65159SKalle Valo ath11k_warn(ar->ab, 1933d5c65159SKalle Valo "failed to send WMI_PEER_ASSOC_CMDID\n"); 1934d5c65159SKalle Valo dev_kfree_skb(skb); 1935d5c65159SKalle Valo } 1936d5c65159SKalle Valo 1937d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 19381cb616a3SSriram R "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", 19391cb616a3SSriram R cmd->vdev_id, cmd->peer_associd, param->peer_mac, 19401cb616a3SSriram R cmd->peer_flags, cmd->peer_rate_caps, cmd->peer_caps, 19411cb616a3SSriram R cmd->peer_listen_intval, cmd->peer_ht_caps, 19421cb616a3SSriram R cmd->peer_max_mpdu, cmd->peer_nss, cmd->peer_phymode, 19431cb616a3SSriram R cmd->peer_mpdu_density, 19441cb616a3SSriram R cmd->peer_vht_caps, cmd->peer_he_cap_info, 19451cb616a3SSriram R cmd->peer_he_ops, cmd->peer_he_cap_info_ext, 19461cb616a3SSriram R cmd->peer_he_cap_phy[0], cmd->peer_he_cap_phy[1], 19471cb616a3SSriram R cmd->peer_he_cap_phy[2], 19481cb616a3SSriram R cmd->peer_bw_rxnss_override); 1949d5c65159SKalle Valo 1950d5c65159SKalle Valo return ret; 1951d5c65159SKalle Valo } 1952d5c65159SKalle Valo 1953d5c65159SKalle Valo void ath11k_wmi_start_scan_init(struct ath11k *ar, 1954d5c65159SKalle Valo struct scan_req_params *arg) 1955d5c65159SKalle Valo { 1956d5c65159SKalle Valo /* setup commonly used values */ 1957d5c65159SKalle Valo arg->scan_req_id = 1; 1958d5c65159SKalle Valo arg->scan_priority = WMI_SCAN_PRIORITY_LOW; 1959d5c65159SKalle Valo arg->dwell_time_active = 50; 1960d5c65159SKalle Valo arg->dwell_time_active_2g = 0; 1961d5c65159SKalle Valo arg->dwell_time_passive = 150; 1962194b8ea1SPradeep Kumar Chitrapu arg->dwell_time_active_6g = 40; 1963194b8ea1SPradeep Kumar Chitrapu arg->dwell_time_passive_6g = 30; 1964d5c65159SKalle Valo arg->min_rest_time = 50; 1965d5c65159SKalle Valo arg->max_rest_time = 500; 1966d5c65159SKalle Valo arg->repeat_probe_time = 0; 1967d5c65159SKalle Valo arg->probe_spacing_time = 0; 1968d5c65159SKalle Valo arg->idle_time = 0; 1969d5c65159SKalle Valo arg->max_scan_time = 20000; 1970d5c65159SKalle Valo arg->probe_delay = 5; 1971d5c65159SKalle Valo arg->notify_scan_events = WMI_SCAN_EVENT_STARTED | 1972d5c65159SKalle Valo WMI_SCAN_EVENT_COMPLETED | 1973d5c65159SKalle Valo WMI_SCAN_EVENT_BSS_CHANNEL | 1974d5c65159SKalle Valo WMI_SCAN_EVENT_FOREIGN_CHAN | 1975d5c65159SKalle Valo WMI_SCAN_EVENT_DEQUEUED; 1976d5c65159SKalle Valo arg->scan_flags |= WMI_SCAN_CHAN_STAT_EVENT; 1977d5c65159SKalle Valo arg->num_bssid = 1; 1978fa7572c2SCarl Huang 1979fa7572c2SCarl Huang /* fill bssid_list[0] with 0xff, otherwise bssid and RA will be 1980fa7572c2SCarl Huang * ZEROs in probe request 1981fa7572c2SCarl Huang */ 1982fa7572c2SCarl Huang eth_broadcast_addr(arg->bssid_list[0].addr); 1983d5c65159SKalle Valo } 1984d5c65159SKalle Valo 1985d5c65159SKalle Valo static inline void 1986d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(struct wmi_start_scan_cmd *cmd, 1987d5c65159SKalle Valo struct scan_req_params *param) 1988d5c65159SKalle Valo { 1989d5c65159SKalle Valo /* Scan events subscription */ 1990d5c65159SKalle Valo if (param->scan_ev_started) 1991d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_STARTED; 1992d5c65159SKalle Valo if (param->scan_ev_completed) 1993d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_COMPLETED; 1994d5c65159SKalle Valo if (param->scan_ev_bss_chan) 1995d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_BSS_CHANNEL; 1996d5c65159SKalle Valo if (param->scan_ev_foreign_chan) 1997d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN; 1998d5c65159SKalle Valo if (param->scan_ev_dequeued) 1999d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_DEQUEUED; 2000d5c65159SKalle Valo if (param->scan_ev_preempted) 2001d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_PREEMPTED; 2002d5c65159SKalle Valo if (param->scan_ev_start_failed) 2003d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_START_FAILED; 2004d5c65159SKalle Valo if (param->scan_ev_restarted) 2005d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_RESTARTED; 2006d5c65159SKalle Valo if (param->scan_ev_foreign_chn_exit) 2007d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT; 2008d5c65159SKalle Valo if (param->scan_ev_suspended) 2009d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_SUSPENDED; 2010d5c65159SKalle Valo if (param->scan_ev_resumed) 2011d5c65159SKalle Valo cmd->notify_scan_events |= WMI_SCAN_EVENT_RESUMED; 2012d5c65159SKalle Valo 2013d5c65159SKalle Valo /** Set scan control flags */ 2014d5c65159SKalle Valo cmd->scan_ctrl_flags = 0; 2015d5c65159SKalle Valo if (param->scan_f_passive) 2016d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; 2017d5c65159SKalle Valo if (param->scan_f_strict_passive_pch) 2018d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_STRICT_PASSIVE_ON_PCHN; 2019d5c65159SKalle Valo if (param->scan_f_promisc_mode) 2020d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROMISCUOS; 2021d5c65159SKalle Valo if (param->scan_f_capture_phy_err) 2022d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_CAPTURE_PHY_ERROR; 2023d5c65159SKalle Valo if (param->scan_f_half_rate) 2024d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_HALF_RATE_SUPPORT; 2025d5c65159SKalle Valo if (param->scan_f_quarter_rate) 2026d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_QUARTER_RATE_SUPPORT; 2027d5c65159SKalle Valo if (param->scan_f_cck_rates) 2028d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES; 2029d5c65159SKalle Valo if (param->scan_f_ofdm_rates) 2030d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES; 2031d5c65159SKalle Valo if (param->scan_f_chan_stat_evnt) 2032d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT; 2033d5c65159SKalle Valo if (param->scan_f_filter_prb_req) 2034d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; 2035d5c65159SKalle Valo if (param->scan_f_bcast_probe) 2036d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_BCAST_PROBE_REQ; 2037d5c65159SKalle Valo if (param->scan_f_offchan_mgmt_tx) 2038d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_MGMT_TX; 2039d5c65159SKalle Valo if (param->scan_f_offchan_data_tx) 2040d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_OFFCHAN_DATA_TX; 2041d5c65159SKalle Valo if (param->scan_f_force_active_dfs_chn) 2042d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_FLAG_FORCE_ACTIVE_ON_DFS; 2043d5c65159SKalle Valo if (param->scan_f_add_tpc_ie_in_probe) 2044d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_TPC_IE_IN_PROBE_REQ; 2045d5c65159SKalle Valo if (param->scan_f_add_ds_ie_in_probe) 2046d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_DS_IE_IN_PROBE_REQ; 2047d5c65159SKalle Valo if (param->scan_f_add_spoofed_mac_in_probe) 2048d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_ADD_SPOOF_MAC_IN_PROBE_REQ; 2049d5c65159SKalle Valo if (param->scan_f_add_rand_seq_in_probe) 2050d5c65159SKalle Valo cmd->scan_ctrl_flags |= WMI_SCAN_RANDOM_SEQ_NO_IN_PROBE_REQ; 2051d5c65159SKalle Valo if (param->scan_f_en_ie_whitelist_in_probe) 2052d5c65159SKalle Valo cmd->scan_ctrl_flags |= 2053d5c65159SKalle Valo WMI_SCAN_ENABLE_IE_WHTELIST_IN_PROBE_REQ; 2054d5c65159SKalle Valo 2055d5c65159SKalle Valo /* for adaptive scan mode using 3 bits (21 - 23 bits) */ 2056d5c65159SKalle Valo WMI_SCAN_SET_DWELL_MODE(cmd->scan_ctrl_flags, 2057d5c65159SKalle Valo param->adaptive_dwell_time_mode); 2058d5c65159SKalle Valo } 2059d5c65159SKalle Valo 2060d5c65159SKalle Valo int ath11k_wmi_send_scan_start_cmd(struct ath11k *ar, 2061d5c65159SKalle Valo struct scan_req_params *params) 2062d5c65159SKalle Valo { 2063d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2064d5c65159SKalle Valo struct wmi_start_scan_cmd *cmd; 2065d5c65159SKalle Valo struct wmi_ssid *ssid = NULL; 2066d5c65159SKalle Valo struct wmi_mac_addr *bssid; 2067d5c65159SKalle Valo struct sk_buff *skb; 2068d5c65159SKalle Valo struct wmi_tlv *tlv; 2069d5c65159SKalle Valo void *ptr; 2070d5c65159SKalle Valo int i, ret, len; 2071d5c65159SKalle Valo u32 *tmp_ptr; 2072d5c65159SKalle Valo u8 extraie_len_with_pad = 0; 207374601ecfSPradeep Kumar Chitrapu struct hint_short_ssid *s_ssid = NULL; 207474601ecfSPradeep Kumar Chitrapu struct hint_bssid *hint_bssid = NULL; 2075d5c65159SKalle Valo 2076d5c65159SKalle Valo len = sizeof(*cmd); 2077d5c65159SKalle Valo 2078d5c65159SKalle Valo len += TLV_HDR_SIZE; 2079d5c65159SKalle Valo if (params->num_chan) 2080d5c65159SKalle Valo len += params->num_chan * sizeof(u32); 2081d5c65159SKalle Valo 2082d5c65159SKalle Valo len += TLV_HDR_SIZE; 2083d5c65159SKalle Valo if (params->num_ssids) 2084d5c65159SKalle Valo len += params->num_ssids * sizeof(*ssid); 2085d5c65159SKalle Valo 2086d5c65159SKalle Valo len += TLV_HDR_SIZE; 2087d5c65159SKalle Valo if (params->num_bssid) 2088d5c65159SKalle Valo len += sizeof(*bssid) * params->num_bssid; 2089d5c65159SKalle Valo 2090d5c65159SKalle Valo len += TLV_HDR_SIZE; 2091d5c65159SKalle Valo if (params->extraie.len) 2092d5c65159SKalle Valo extraie_len_with_pad = 2093d5c65159SKalle Valo roundup(params->extraie.len, sizeof(u32)); 2094d5c65159SKalle Valo len += extraie_len_with_pad; 2095d5c65159SKalle Valo 209674601ecfSPradeep Kumar Chitrapu if (params->num_hint_bssid) 209774601ecfSPradeep Kumar Chitrapu len += TLV_HDR_SIZE + 209874601ecfSPradeep Kumar Chitrapu params->num_hint_bssid * sizeof(struct hint_bssid); 209974601ecfSPradeep Kumar Chitrapu 210074601ecfSPradeep Kumar Chitrapu if (params->num_hint_s_ssid) 210174601ecfSPradeep Kumar Chitrapu len += TLV_HDR_SIZE + 210274601ecfSPradeep Kumar Chitrapu params->num_hint_s_ssid * sizeof(struct hint_short_ssid); 210374601ecfSPradeep Kumar Chitrapu 21046bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2105d5c65159SKalle Valo if (!skb) 2106d5c65159SKalle Valo return -ENOMEM; 2107d5c65159SKalle Valo 2108d5c65159SKalle Valo ptr = skb->data; 2109d5c65159SKalle Valo 2110d5c65159SKalle Valo cmd = ptr; 2111d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_START_SCAN_CMD) | 2112d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2113d5c65159SKalle Valo 2114d5c65159SKalle Valo cmd->scan_id = params->scan_id; 2115d5c65159SKalle Valo cmd->scan_req_id = params->scan_req_id; 2116d5c65159SKalle Valo cmd->vdev_id = params->vdev_id; 2117d5c65159SKalle Valo cmd->scan_priority = params->scan_priority; 2118d5c65159SKalle Valo cmd->notify_scan_events = params->notify_scan_events; 2119d5c65159SKalle Valo 2120d5c65159SKalle Valo ath11k_wmi_copy_scan_event_cntrl_flags(cmd, params); 2121d5c65159SKalle Valo 2122d5c65159SKalle Valo cmd->dwell_time_active = params->dwell_time_active; 2123d5c65159SKalle Valo cmd->dwell_time_active_2g = params->dwell_time_active_2g; 2124d5c65159SKalle Valo cmd->dwell_time_passive = params->dwell_time_passive; 2125194b8ea1SPradeep Kumar Chitrapu cmd->dwell_time_active_6g = params->dwell_time_active_6g; 2126194b8ea1SPradeep Kumar Chitrapu cmd->dwell_time_passive_6g = params->dwell_time_passive_6g; 2127d5c65159SKalle Valo cmd->min_rest_time = params->min_rest_time; 2128d5c65159SKalle Valo cmd->max_rest_time = params->max_rest_time; 2129d5c65159SKalle Valo cmd->repeat_probe_time = params->repeat_probe_time; 2130d5c65159SKalle Valo cmd->probe_spacing_time = params->probe_spacing_time; 2131d5c65159SKalle Valo cmd->idle_time = params->idle_time; 2132d5c65159SKalle Valo cmd->max_scan_time = params->max_scan_time; 2133d5c65159SKalle Valo cmd->probe_delay = params->probe_delay; 2134d5c65159SKalle Valo cmd->burst_duration = params->burst_duration; 2135d5c65159SKalle Valo cmd->num_chan = params->num_chan; 2136d5c65159SKalle Valo cmd->num_bssid = params->num_bssid; 2137d5c65159SKalle Valo cmd->num_ssids = params->num_ssids; 2138d5c65159SKalle Valo cmd->ie_len = params->extraie.len; 2139d5c65159SKalle Valo cmd->n_probes = params->n_probes; 2140d5c65159SKalle Valo 2141d5c65159SKalle Valo ptr += sizeof(*cmd); 2142d5c65159SKalle Valo 2143d5c65159SKalle Valo len = params->num_chan * sizeof(u32); 2144d5c65159SKalle Valo 2145d5c65159SKalle Valo tlv = ptr; 2146d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) | 2147d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 2148d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 2149d5c65159SKalle Valo tmp_ptr = (u32 *)ptr; 2150d5c65159SKalle Valo 2151d5c65159SKalle Valo for (i = 0; i < params->num_chan; ++i) 2152d5c65159SKalle Valo tmp_ptr[i] = params->chan_list[i]; 2153d5c65159SKalle Valo 2154d5c65159SKalle Valo ptr += len; 2155d5c65159SKalle Valo 2156d5c65159SKalle Valo len = params->num_ssids * sizeof(*ssid); 2157d5c65159SKalle Valo tlv = ptr; 2158d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2159d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 2160d5c65159SKalle Valo 2161d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 2162d5c65159SKalle Valo 2163d5c65159SKalle Valo if (params->num_ssids) { 2164d5c65159SKalle Valo ssid = ptr; 2165d5c65159SKalle Valo for (i = 0; i < params->num_ssids; ++i) { 2166d5c65159SKalle Valo ssid->ssid_len = params->ssid[i].length; 2167d5c65159SKalle Valo memcpy(ssid->ssid, params->ssid[i].ssid, 2168d5c65159SKalle Valo params->ssid[i].length); 2169d5c65159SKalle Valo ssid++; 2170d5c65159SKalle Valo } 2171d5c65159SKalle Valo } 2172d5c65159SKalle Valo 2173d5c65159SKalle Valo ptr += (params->num_ssids * sizeof(*ssid)); 2174d5c65159SKalle Valo len = params->num_bssid * sizeof(*bssid); 2175d5c65159SKalle Valo tlv = ptr; 2176d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 2177d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 2178d5c65159SKalle Valo 2179d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 2180d5c65159SKalle Valo bssid = ptr; 2181d5c65159SKalle Valo 2182d5c65159SKalle Valo if (params->num_bssid) { 2183d5c65159SKalle Valo for (i = 0; i < params->num_bssid; ++i) { 2184d5c65159SKalle Valo ether_addr_copy(bssid->addr, 2185d5c65159SKalle Valo params->bssid_list[i].addr); 2186d5c65159SKalle Valo bssid++; 2187d5c65159SKalle Valo } 2188d5c65159SKalle Valo } 2189d5c65159SKalle Valo 2190d5c65159SKalle Valo ptr += params->num_bssid * sizeof(*bssid); 2191d5c65159SKalle Valo 2192d5c65159SKalle Valo len = extraie_len_with_pad; 2193d5c65159SKalle Valo tlv = ptr; 2194d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 2195d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 2196d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 2197d5c65159SKalle Valo 2198d5c65159SKalle Valo if (params->extraie.len) 2199d5c65159SKalle Valo memcpy(ptr, params->extraie.ptr, 2200d5c65159SKalle Valo params->extraie.len); 2201d5c65159SKalle Valo 2202d5c65159SKalle Valo ptr += extraie_len_with_pad; 2203d5c65159SKalle Valo 220474601ecfSPradeep Kumar Chitrapu if (params->num_hint_s_ssid) { 220574601ecfSPradeep Kumar Chitrapu len = params->num_hint_s_ssid * sizeof(struct hint_short_ssid); 220674601ecfSPradeep Kumar Chitrapu tlv = ptr; 220774601ecfSPradeep Kumar Chitrapu tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 220874601ecfSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, len); 220974601ecfSPradeep Kumar Chitrapu ptr += TLV_HDR_SIZE; 221074601ecfSPradeep Kumar Chitrapu s_ssid = ptr; 221174601ecfSPradeep Kumar Chitrapu for (i = 0; i < params->num_hint_s_ssid; ++i) { 221274601ecfSPradeep Kumar Chitrapu s_ssid->freq_flags = params->hint_s_ssid[i].freq_flags; 221374601ecfSPradeep Kumar Chitrapu s_ssid->short_ssid = params->hint_s_ssid[i].short_ssid; 221474601ecfSPradeep Kumar Chitrapu s_ssid++; 221574601ecfSPradeep Kumar Chitrapu } 221674601ecfSPradeep Kumar Chitrapu ptr += len; 221774601ecfSPradeep Kumar Chitrapu } 221874601ecfSPradeep Kumar Chitrapu 221974601ecfSPradeep Kumar Chitrapu if (params->num_hint_bssid) { 222074601ecfSPradeep Kumar Chitrapu len = params->num_hint_bssid * sizeof(struct hint_bssid); 222174601ecfSPradeep Kumar Chitrapu tlv = ptr; 222274601ecfSPradeep Kumar Chitrapu tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_FIXED_STRUCT) | 222374601ecfSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, len); 222474601ecfSPradeep Kumar Chitrapu ptr += TLV_HDR_SIZE; 222574601ecfSPradeep Kumar Chitrapu hint_bssid = ptr; 222674601ecfSPradeep Kumar Chitrapu for (i = 0; i < params->num_hint_bssid; ++i) { 222774601ecfSPradeep Kumar Chitrapu hint_bssid->freq_flags = 222874601ecfSPradeep Kumar Chitrapu params->hint_bssid[i].freq_flags; 222974601ecfSPradeep Kumar Chitrapu ether_addr_copy(¶ms->hint_bssid[i].bssid.addr[0], 223074601ecfSPradeep Kumar Chitrapu &hint_bssid->bssid.addr[0]); 223174601ecfSPradeep Kumar Chitrapu hint_bssid++; 223274601ecfSPradeep Kumar Chitrapu } 223374601ecfSPradeep Kumar Chitrapu } 223474601ecfSPradeep Kumar Chitrapu 2235d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2236d5c65159SKalle Valo WMI_START_SCAN_CMDID); 2237d5c65159SKalle Valo if (ret) { 2238d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_START_SCAN_CMDID\n"); 2239d5c65159SKalle Valo dev_kfree_skb(skb); 2240d5c65159SKalle Valo } 2241d5c65159SKalle Valo 2242d5c65159SKalle Valo return ret; 2243d5c65159SKalle Valo } 2244d5c65159SKalle Valo 2245d5c65159SKalle Valo int ath11k_wmi_send_scan_stop_cmd(struct ath11k *ar, 2246d5c65159SKalle Valo struct scan_cancel_param *param) 2247d5c65159SKalle Valo { 2248d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2249d5c65159SKalle Valo struct wmi_stop_scan_cmd *cmd; 2250d5c65159SKalle Valo struct sk_buff *skb; 2251d5c65159SKalle Valo int ret; 2252d5c65159SKalle Valo 22536bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2254d5c65159SKalle Valo if (!skb) 2255d5c65159SKalle Valo return -ENOMEM; 2256d5c65159SKalle Valo 2257d5c65159SKalle Valo cmd = (struct wmi_stop_scan_cmd *)skb->data; 2258d5c65159SKalle Valo 2259d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_STOP_SCAN_CMD) | 2260d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2261d5c65159SKalle Valo 2262d5c65159SKalle Valo cmd->vdev_id = param->vdev_id; 2263d5c65159SKalle Valo cmd->requestor = param->requester; 2264d5c65159SKalle Valo cmd->scan_id = param->scan_id; 2265d5c65159SKalle Valo cmd->pdev_id = param->pdev_id; 2266d5c65159SKalle Valo /* stop the scan with the corresponding scan_id */ 2267d5c65159SKalle Valo if (param->req_type == WLAN_SCAN_CANCEL_PDEV_ALL) { 2268d5c65159SKalle Valo /* Cancelling all scans */ 2269d5c65159SKalle Valo cmd->req_type = WMI_SCAN_STOP_ALL; 2270d5c65159SKalle Valo } else if (param->req_type == WLAN_SCAN_CANCEL_VDEV_ALL) { 2271d5c65159SKalle Valo /* Cancelling VAP scans */ 2272d5c65159SKalle Valo cmd->req_type = WMI_SCN_STOP_VAP_ALL; 2273d5c65159SKalle Valo } else if (param->req_type == WLAN_SCAN_CANCEL_SINGLE) { 2274d5c65159SKalle Valo /* Cancelling specific scan */ 2275d5c65159SKalle Valo cmd->req_type = WMI_SCAN_STOP_ONE; 2276d5c65159SKalle Valo } else { 2277d5c65159SKalle Valo ath11k_warn(ar->ab, "invalid scan cancel param %d", 2278d5c65159SKalle Valo param->req_type); 2279d5c65159SKalle Valo dev_kfree_skb(skb); 2280d5c65159SKalle Valo return -EINVAL; 2281d5c65159SKalle Valo } 2282d5c65159SKalle Valo 2283d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2284d5c65159SKalle Valo WMI_STOP_SCAN_CMDID); 2285d5c65159SKalle Valo if (ret) { 2286d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_STOP_SCAN_CMDID\n"); 2287d5c65159SKalle Valo dev_kfree_skb(skb); 2288d5c65159SKalle Valo } 2289d5c65159SKalle Valo 2290d5c65159SKalle Valo return ret; 2291d5c65159SKalle Valo } 2292d5c65159SKalle Valo 2293d5c65159SKalle Valo int ath11k_wmi_send_scan_chan_list_cmd(struct ath11k *ar, 2294d5c65159SKalle Valo struct scan_chan_list_params *chan_list) 2295d5c65159SKalle Valo { 2296d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2297d5c65159SKalle Valo struct wmi_scan_chan_list_cmd *cmd; 2298d5c65159SKalle Valo struct sk_buff *skb; 2299d5c65159SKalle Valo struct wmi_channel *chan_info; 2300d5c65159SKalle Valo struct channel_param *tchan_info; 2301d5c65159SKalle Valo struct wmi_tlv *tlv; 2302d5c65159SKalle Valo void *ptr; 2303d5c65159SKalle Valo int i, ret, len; 2304bff621fdSPradeep Kumar Chitrapu u16 num_send_chans, num_sends = 0, max_chan_limit = 0; 2305d5c65159SKalle Valo u32 *reg1, *reg2; 2306d5c65159SKalle Valo 2307b2549465SGustavo A. R. Silva tchan_info = chan_list->ch_param; 2308bff621fdSPradeep Kumar Chitrapu while (chan_list->nallchans) { 2309bff621fdSPradeep Kumar Chitrapu len = sizeof(*cmd) + TLV_HDR_SIZE; 2310bff621fdSPradeep Kumar Chitrapu max_chan_limit = (wmi->wmi_ab->max_msg_len[ar->pdev_idx] - len) / 2311bff621fdSPradeep Kumar Chitrapu sizeof(*chan_info); 2312bff621fdSPradeep Kumar Chitrapu 2313bff621fdSPradeep Kumar Chitrapu if (chan_list->nallchans > max_chan_limit) 2314bff621fdSPradeep Kumar Chitrapu num_send_chans = max_chan_limit; 2315bff621fdSPradeep Kumar Chitrapu else 2316bff621fdSPradeep Kumar Chitrapu num_send_chans = chan_list->nallchans; 2317bff621fdSPradeep Kumar Chitrapu 2318bff621fdSPradeep Kumar Chitrapu chan_list->nallchans -= num_send_chans; 2319bff621fdSPradeep Kumar Chitrapu len += sizeof(*chan_info) * num_send_chans; 2320d5c65159SKalle Valo 23216bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2322d5c65159SKalle Valo if (!skb) 2323d5c65159SKalle Valo return -ENOMEM; 2324d5c65159SKalle Valo 2325d5c65159SKalle Valo cmd = (struct wmi_scan_chan_list_cmd *)skb->data; 2326d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_SCAN_CHAN_LIST_CMD) | 2327d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2328bff621fdSPradeep Kumar Chitrapu cmd->pdev_id = chan_list->pdev_id; 2329bff621fdSPradeep Kumar Chitrapu cmd->num_scan_chans = num_send_chans; 2330bff621fdSPradeep Kumar Chitrapu if (num_sends) 2331bff621fdSPradeep Kumar Chitrapu cmd->flags |= WMI_APPEND_TO_EXISTING_CHAN_LIST_FLAG; 2332d5c65159SKalle Valo 2333d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2334bff621fdSPradeep Kumar Chitrapu "WMI no.of chan = %d len = %d pdev_id = %d num_sends = %d\n", 2335bff621fdSPradeep Kumar Chitrapu num_send_chans, len, cmd->pdev_id, num_sends); 2336d5c65159SKalle Valo 2337d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd); 2338d5c65159SKalle Valo 2339bff621fdSPradeep Kumar Chitrapu len = sizeof(*chan_info) * num_send_chans; 2340d5c65159SKalle Valo tlv = ptr; 2341d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 2342d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 2343d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 2344d5c65159SKalle Valo 2345bff621fdSPradeep Kumar Chitrapu for (i = 0; i < num_send_chans; ++i) { 2346d5c65159SKalle Valo chan_info = ptr; 2347d5c65159SKalle Valo memset(chan_info, 0, sizeof(*chan_info)); 2348d5c65159SKalle Valo len = sizeof(*chan_info); 2349d5c65159SKalle Valo chan_info->tlv_header = FIELD_PREP(WMI_TLV_TAG, 2350d5c65159SKalle Valo WMI_TAG_CHANNEL) | 2351d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 2352d5c65159SKalle Valo len - TLV_HDR_SIZE); 2353d5c65159SKalle Valo 2354d5c65159SKalle Valo reg1 = &chan_info->reg_info_1; 2355d5c65159SKalle Valo reg2 = &chan_info->reg_info_2; 2356d5c65159SKalle Valo chan_info->mhz = tchan_info->mhz; 2357d5c65159SKalle Valo chan_info->band_center_freq1 = tchan_info->cfreq1; 2358d5c65159SKalle Valo chan_info->band_center_freq2 = tchan_info->cfreq2; 2359d5c65159SKalle Valo 2360d5c65159SKalle Valo if (tchan_info->is_chan_passive) 2361d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_PASSIVE; 23629f056ed8SJohn Crispin if (tchan_info->allow_he) 23639f056ed8SJohn Crispin chan_info->info |= WMI_CHAN_INFO_ALLOW_HE; 23649f056ed8SJohn Crispin else if (tchan_info->allow_vht) 2365d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_ALLOW_VHT; 2366d5c65159SKalle Valo else if (tchan_info->allow_ht) 2367d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_ALLOW_HT; 2368d5c65159SKalle Valo if (tchan_info->half_rate) 2369d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_HALF_RATE; 2370d5c65159SKalle Valo if (tchan_info->quarter_rate) 2371d5c65159SKalle Valo chan_info->info |= WMI_CHAN_INFO_QUARTER_RATE; 2372bff621fdSPradeep Kumar Chitrapu if (tchan_info->psc_channel) 2373bff621fdSPradeep Kumar Chitrapu chan_info->info |= WMI_CHAN_INFO_PSC; 2374d5c65159SKalle Valo 2375d5c65159SKalle Valo chan_info->info |= FIELD_PREP(WMI_CHAN_INFO_MODE, 2376d5c65159SKalle Valo tchan_info->phy_mode); 2377d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MIN_PWR, 2378d5c65159SKalle Valo tchan_info->minpower); 2379d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_PWR, 2380d5c65159SKalle Valo tchan_info->maxpower); 2381d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_MAX_REG_PWR, 2382d5c65159SKalle Valo tchan_info->maxregpower); 2383d5c65159SKalle Valo *reg1 |= FIELD_PREP(WMI_CHAN_REG_INFO1_REG_CLS, 2384d5c65159SKalle Valo tchan_info->reg_class_id); 2385d5c65159SKalle Valo *reg2 |= FIELD_PREP(WMI_CHAN_REG_INFO2_ANT_MAX, 2386d5c65159SKalle Valo tchan_info->antennamax); 2387d5c65159SKalle Valo 2388d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2389bff621fdSPradeep Kumar Chitrapu "WMI chan scan list chan[%d] = %u, chan_info->info %8x\n", 2390bff621fdSPradeep Kumar Chitrapu i, chan_info->mhz, chan_info->info); 2391d5c65159SKalle Valo 2392d5c65159SKalle Valo ptr += sizeof(*chan_info); 2393d5c65159SKalle Valo 2394d5c65159SKalle Valo tchan_info++; 2395d5c65159SKalle Valo } 2396d5c65159SKalle Valo 2397d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_SCAN_CHAN_LIST_CMDID); 2398d5c65159SKalle Valo if (ret) { 2399d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_SCAN_CHAN_LIST cmd\n"); 2400d5c65159SKalle Valo dev_kfree_skb(skb); 2401bff621fdSPradeep Kumar Chitrapu return ret; 2402d5c65159SKalle Valo } 2403d5c65159SKalle Valo 2404bff621fdSPradeep Kumar Chitrapu num_sends++; 2405bff621fdSPradeep Kumar Chitrapu } 2406bff621fdSPradeep Kumar Chitrapu 2407bff621fdSPradeep Kumar Chitrapu return 0; 2408d5c65159SKalle Valo } 2409d5c65159SKalle Valo 2410d5c65159SKalle Valo int ath11k_wmi_send_wmm_update_cmd_tlv(struct ath11k *ar, u32 vdev_id, 2411d5c65159SKalle Valo struct wmi_wmm_params_all_arg *param) 2412d5c65159SKalle Valo { 2413d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2414d5c65159SKalle Valo struct wmi_vdev_set_wmm_params_cmd *cmd; 2415d5c65159SKalle Valo struct wmi_wmm_params *wmm_param; 2416d5c65159SKalle Valo struct wmi_wmm_params_arg *wmi_wmm_arg; 2417d5c65159SKalle Valo struct sk_buff *skb; 2418d5c65159SKalle Valo int ret, ac; 2419d5c65159SKalle Valo 24206bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2421d5c65159SKalle Valo if (!skb) 2422d5c65159SKalle Valo return -ENOMEM; 2423d5c65159SKalle Valo 2424d5c65159SKalle Valo cmd = (struct wmi_vdev_set_wmm_params_cmd *)skb->data; 2425d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 2426d5c65159SKalle Valo WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) | 2427d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2428d5c65159SKalle Valo 2429d5c65159SKalle Valo cmd->vdev_id = vdev_id; 2430d5c65159SKalle Valo cmd->wmm_param_type = 0; 2431d5c65159SKalle Valo 2432d5c65159SKalle Valo for (ac = 0; ac < WME_NUM_AC; ac++) { 2433d5c65159SKalle Valo switch (ac) { 2434d5c65159SKalle Valo case WME_AC_BE: 2435d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_be; 2436d5c65159SKalle Valo break; 2437d5c65159SKalle Valo case WME_AC_BK: 2438d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_bk; 2439d5c65159SKalle Valo break; 2440d5c65159SKalle Valo case WME_AC_VI: 2441d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_vi; 2442d5c65159SKalle Valo break; 2443d5c65159SKalle Valo case WME_AC_VO: 2444d5c65159SKalle Valo wmi_wmm_arg = ¶m->ac_vo; 2445d5c65159SKalle Valo break; 2446d5c65159SKalle Valo } 2447d5c65159SKalle Valo 2448d5c65159SKalle Valo wmm_param = (struct wmi_wmm_params *)&cmd->wmm_params[ac]; 2449d5c65159SKalle Valo wmm_param->tlv_header = 2450d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, 2451d5c65159SKalle Valo WMI_TAG_VDEV_SET_WMM_PARAMS_CMD) | 2452d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 2453d5c65159SKalle Valo sizeof(*wmm_param) - TLV_HDR_SIZE); 2454d5c65159SKalle Valo 2455d5c65159SKalle Valo wmm_param->aifs = wmi_wmm_arg->aifs; 2456d5c65159SKalle Valo wmm_param->cwmin = wmi_wmm_arg->cwmin; 2457d5c65159SKalle Valo wmm_param->cwmax = wmi_wmm_arg->cwmax; 2458d5c65159SKalle Valo wmm_param->txoplimit = wmi_wmm_arg->txop; 2459d5c65159SKalle Valo wmm_param->acm = wmi_wmm_arg->acm; 2460d5c65159SKalle Valo wmm_param->no_ack = wmi_wmm_arg->no_ack; 2461d5c65159SKalle Valo 2462d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2463d5c65159SKalle Valo "wmi wmm set ac %d aifs %d cwmin %d cwmax %d txop %d acm %d no_ack %d\n", 2464d5c65159SKalle Valo ac, wmm_param->aifs, wmm_param->cwmin, 2465d5c65159SKalle Valo wmm_param->cwmax, wmm_param->txoplimit, 2466d5c65159SKalle Valo wmm_param->acm, wmm_param->no_ack); 2467d5c65159SKalle Valo } 2468d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2469d5c65159SKalle Valo WMI_VDEV_SET_WMM_PARAMS_CMDID); 2470d5c65159SKalle Valo if (ret) { 2471d5c65159SKalle Valo ath11k_warn(ar->ab, 2472d5c65159SKalle Valo "failed to send WMI_VDEV_SET_WMM_PARAMS_CMDID"); 2473d5c65159SKalle Valo dev_kfree_skb(skb); 2474d5c65159SKalle Valo } 2475d5c65159SKalle Valo 2476d5c65159SKalle Valo return ret; 2477d5c65159SKalle Valo } 2478d5c65159SKalle Valo 2479d5c65159SKalle Valo int ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(struct ath11k *ar, 2480d5c65159SKalle Valo u32 pdev_id) 2481d5c65159SKalle Valo { 2482d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2483d5c65159SKalle Valo struct wmi_dfs_phyerr_offload_cmd *cmd; 2484d5c65159SKalle Valo struct sk_buff *skb; 2485d5c65159SKalle Valo int ret; 2486d5c65159SKalle Valo 24876bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2488d5c65159SKalle Valo if (!skb) 2489d5c65159SKalle Valo return -ENOMEM; 2490d5c65159SKalle Valo 2491d5c65159SKalle Valo cmd = (struct wmi_dfs_phyerr_offload_cmd *)skb->data; 2492d5c65159SKalle Valo cmd->tlv_header = 2493d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, 2494d5c65159SKalle Valo WMI_TAG_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMD) | 2495d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2496d5c65159SKalle Valo 2497d5c65159SKalle Valo cmd->pdev_id = pdev_id; 2498d5c65159SKalle Valo 2499d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 2500d5c65159SKalle Valo "WMI dfs phy err offload enable pdev id %d\n", pdev_id); 2501d5c65159SKalle Valo 2502d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2503d5c65159SKalle Valo WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID); 2504d5c65159SKalle Valo if (ret) { 2505d5c65159SKalle Valo ath11k_warn(ar->ab, 2506d5c65159SKalle Valo "failed to send WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE cmd\n"); 2507d5c65159SKalle Valo dev_kfree_skb(skb); 2508d5c65159SKalle Valo } 2509d5c65159SKalle Valo 2510d5c65159SKalle Valo return ret; 2511d5c65159SKalle Valo } 2512d5c65159SKalle Valo 25139556dfa2SMaharaja Kennadyrajan int ath11k_wmi_delba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac, 25149556dfa2SMaharaja Kennadyrajan u32 tid, u32 initiator, u32 reason) 25159556dfa2SMaharaja Kennadyrajan { 25169556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi; 25179556dfa2SMaharaja Kennadyrajan struct wmi_delba_send_cmd *cmd; 25189556dfa2SMaharaja Kennadyrajan struct sk_buff *skb; 25199556dfa2SMaharaja Kennadyrajan int ret; 25209556dfa2SMaharaja Kennadyrajan 25219556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 25229556dfa2SMaharaja Kennadyrajan if (!skb) 25239556dfa2SMaharaja Kennadyrajan return -ENOMEM; 25249556dfa2SMaharaja Kennadyrajan 25259556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_delba_send_cmd *)skb->data; 25269556dfa2SMaharaja Kennadyrajan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DELBA_SEND_CMD) | 25279556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 25289556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id; 25299556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac); 25309556dfa2SMaharaja Kennadyrajan cmd->tid = tid; 25319556dfa2SMaharaja Kennadyrajan cmd->initiator = initiator; 25329556dfa2SMaharaja Kennadyrajan cmd->reasoncode = reason; 25339556dfa2SMaharaja Kennadyrajan 25349556dfa2SMaharaja Kennadyrajan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 25359556dfa2SMaharaja Kennadyrajan "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n", 25369556dfa2SMaharaja Kennadyrajan vdev_id, mac, tid, initiator, reason); 25379556dfa2SMaharaja Kennadyrajan 25389556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_DELBA_SEND_CMDID); 25399556dfa2SMaharaja Kennadyrajan 25409556dfa2SMaharaja Kennadyrajan if (ret) { 25419556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab, 25429556dfa2SMaharaja Kennadyrajan "failed to send WMI_DELBA_SEND_CMDID cmd\n"); 25439556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb); 25449556dfa2SMaharaja Kennadyrajan } 25459556dfa2SMaharaja Kennadyrajan 25469556dfa2SMaharaja Kennadyrajan return ret; 25479556dfa2SMaharaja Kennadyrajan } 25489556dfa2SMaharaja Kennadyrajan 25499556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_set_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac, 25509556dfa2SMaharaja Kennadyrajan u32 tid, u32 status) 25519556dfa2SMaharaja Kennadyrajan { 25529556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi; 25539556dfa2SMaharaja Kennadyrajan struct wmi_addba_setresponse_cmd *cmd; 25549556dfa2SMaharaja Kennadyrajan struct sk_buff *skb; 25559556dfa2SMaharaja Kennadyrajan int ret; 25569556dfa2SMaharaja Kennadyrajan 25579556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 25589556dfa2SMaharaja Kennadyrajan if (!skb) 25599556dfa2SMaharaja Kennadyrajan return -ENOMEM; 25609556dfa2SMaharaja Kennadyrajan 25619556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_addba_setresponse_cmd *)skb->data; 25629556dfa2SMaharaja Kennadyrajan cmd->tlv_header = 25639556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SETRESPONSE_CMD) | 25649556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 25659556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id; 25669556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac); 25679556dfa2SMaharaja Kennadyrajan cmd->tid = tid; 25689556dfa2SMaharaja Kennadyrajan cmd->statuscode = status; 25699556dfa2SMaharaja Kennadyrajan 25709556dfa2SMaharaja Kennadyrajan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 25719556dfa2SMaharaja Kennadyrajan "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n", 25729556dfa2SMaharaja Kennadyrajan vdev_id, mac, tid, status); 25739556dfa2SMaharaja Kennadyrajan 25749556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SET_RESP_CMDID); 25759556dfa2SMaharaja Kennadyrajan 25769556dfa2SMaharaja Kennadyrajan if (ret) { 25779556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab, 25789556dfa2SMaharaja Kennadyrajan "failed to send WMI_ADDBA_SET_RESP_CMDID cmd\n"); 25799556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb); 25809556dfa2SMaharaja Kennadyrajan } 25819556dfa2SMaharaja Kennadyrajan 25829556dfa2SMaharaja Kennadyrajan return ret; 25839556dfa2SMaharaja Kennadyrajan } 25849556dfa2SMaharaja Kennadyrajan 25859556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_send(struct ath11k *ar, u32 vdev_id, const u8 *mac, 25869556dfa2SMaharaja Kennadyrajan u32 tid, u32 buf_size) 25879556dfa2SMaharaja Kennadyrajan { 25889556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi; 25899556dfa2SMaharaja Kennadyrajan struct wmi_addba_send_cmd *cmd; 25909556dfa2SMaharaja Kennadyrajan struct sk_buff *skb; 25919556dfa2SMaharaja Kennadyrajan int ret; 25929556dfa2SMaharaja Kennadyrajan 25939556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 25949556dfa2SMaharaja Kennadyrajan if (!skb) 25959556dfa2SMaharaja Kennadyrajan return -ENOMEM; 25969556dfa2SMaharaja Kennadyrajan 25979556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_addba_send_cmd *)skb->data; 25989556dfa2SMaharaja Kennadyrajan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_SEND_CMD) | 25999556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 26009556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id; 26019556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac); 26029556dfa2SMaharaja Kennadyrajan cmd->tid = tid; 26039556dfa2SMaharaja Kennadyrajan cmd->buffersize = buf_size; 26049556dfa2SMaharaja Kennadyrajan 26059556dfa2SMaharaja Kennadyrajan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 26069556dfa2SMaharaja Kennadyrajan "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n", 26079556dfa2SMaharaja Kennadyrajan vdev_id, mac, tid, buf_size); 26089556dfa2SMaharaja Kennadyrajan 26099556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_SEND_CMDID); 26109556dfa2SMaharaja Kennadyrajan 26119556dfa2SMaharaja Kennadyrajan if (ret) { 26129556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab, 26139556dfa2SMaharaja Kennadyrajan "failed to send WMI_ADDBA_SEND_CMDID cmd\n"); 26149556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb); 26159556dfa2SMaharaja Kennadyrajan } 26169556dfa2SMaharaja Kennadyrajan 26179556dfa2SMaharaja Kennadyrajan return ret; 26189556dfa2SMaharaja Kennadyrajan } 26199556dfa2SMaharaja Kennadyrajan 26209556dfa2SMaharaja Kennadyrajan int ath11k_wmi_addba_clear_resp(struct ath11k *ar, u32 vdev_id, const u8 *mac) 26219556dfa2SMaharaja Kennadyrajan { 26229556dfa2SMaharaja Kennadyrajan struct ath11k_pdev_wmi *wmi = ar->wmi; 26239556dfa2SMaharaja Kennadyrajan struct wmi_addba_clear_resp_cmd *cmd; 26249556dfa2SMaharaja Kennadyrajan struct sk_buff *skb; 26259556dfa2SMaharaja Kennadyrajan int ret; 26269556dfa2SMaharaja Kennadyrajan 26279556dfa2SMaharaja Kennadyrajan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 26289556dfa2SMaharaja Kennadyrajan if (!skb) 26299556dfa2SMaharaja Kennadyrajan return -ENOMEM; 26309556dfa2SMaharaja Kennadyrajan 26319556dfa2SMaharaja Kennadyrajan cmd = (struct wmi_addba_clear_resp_cmd *)skb->data; 26329556dfa2SMaharaja Kennadyrajan cmd->tlv_header = 26339556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ADDBA_CLEAR_RESP_CMD) | 26349556dfa2SMaharaja Kennadyrajan FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 26359556dfa2SMaharaja Kennadyrajan cmd->vdev_id = vdev_id; 26369556dfa2SMaharaja Kennadyrajan ether_addr_copy(cmd->peer_macaddr.addr, mac); 26379556dfa2SMaharaja Kennadyrajan 26389556dfa2SMaharaja Kennadyrajan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 26399556dfa2SMaharaja Kennadyrajan "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n", 26409556dfa2SMaharaja Kennadyrajan vdev_id, mac); 26419556dfa2SMaharaja Kennadyrajan 26429556dfa2SMaharaja Kennadyrajan ret = ath11k_wmi_cmd_send(wmi, skb, WMI_ADDBA_CLEAR_RESP_CMDID); 26439556dfa2SMaharaja Kennadyrajan 26449556dfa2SMaharaja Kennadyrajan if (ret) { 26459556dfa2SMaharaja Kennadyrajan ath11k_warn(ar->ab, 26469556dfa2SMaharaja Kennadyrajan "failed to send WMI_ADDBA_CLEAR_RESP_CMDID cmd\n"); 26479556dfa2SMaharaja Kennadyrajan dev_kfree_skb(skb); 26489556dfa2SMaharaja Kennadyrajan } 26499556dfa2SMaharaja Kennadyrajan 26509556dfa2SMaharaja Kennadyrajan return ret; 26519556dfa2SMaharaja Kennadyrajan } 26529556dfa2SMaharaja Kennadyrajan 2653d5c65159SKalle Valo int ath11k_wmi_pdev_peer_pktlog_filter(struct ath11k *ar, u8 *addr, u8 enable) 2654d5c65159SKalle Valo { 2655d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2656d5c65159SKalle Valo struct wmi_pdev_pktlog_filter_cmd *cmd; 2657d5c65159SKalle Valo struct wmi_pdev_pktlog_filter_info *info; 2658d5c65159SKalle Valo struct sk_buff *skb; 2659d5c65159SKalle Valo struct wmi_tlv *tlv; 2660d5c65159SKalle Valo void *ptr; 2661d5c65159SKalle Valo int ret, len; 2662d5c65159SKalle Valo 2663d5c65159SKalle Valo len = sizeof(*cmd) + sizeof(*info) + TLV_HDR_SIZE; 26646bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 2665d5c65159SKalle Valo if (!skb) 2666d5c65159SKalle Valo return -ENOMEM; 2667d5c65159SKalle Valo 2668d5c65159SKalle Valo cmd = (struct wmi_pdev_pktlog_filter_cmd *)skb->data; 2669d5c65159SKalle Valo 2670d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_CMD) | 2671d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2672d5c65159SKalle Valo 2673d0f390eaSAnilkumar Kolli cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id); 2674d5c65159SKalle Valo cmd->num_mac = 1; 2675d5c65159SKalle Valo cmd->enable = enable; 2676d5c65159SKalle Valo 2677d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd); 2678d5c65159SKalle Valo 2679d5c65159SKalle Valo tlv = ptr; 2680d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 268179c647a3SVikas Patel FIELD_PREP(WMI_TLV_LEN, sizeof(*info)); 2682d5c65159SKalle Valo 2683d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 2684d5c65159SKalle Valo info = ptr; 2685d5c65159SKalle Valo 2686d5c65159SKalle Valo ether_addr_copy(info->peer_macaddr.addr, addr); 2687d5c65159SKalle Valo info->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PEER_PKTLOG_FILTER_INFO) | 2688d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 2689d5c65159SKalle Valo sizeof(*info) - TLV_HDR_SIZE); 2690d5c65159SKalle Valo 2691d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2692d5c65159SKalle Valo WMI_PDEV_PKTLOG_FILTER_CMDID); 2693d5c65159SKalle Valo if (ret) { 2694d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n"); 2695d5c65159SKalle Valo dev_kfree_skb(skb); 2696d5c65159SKalle Valo } 2697d5c65159SKalle Valo 2698d5c65159SKalle Valo return ret; 2699d5c65159SKalle Valo } 2700d5c65159SKalle Valo 2701d5c65159SKalle Valo int 2702d5c65159SKalle Valo ath11k_wmi_send_init_country_cmd(struct ath11k *ar, 2703d5c65159SKalle Valo struct wmi_init_country_params init_cc_params) 2704d5c65159SKalle Valo { 2705d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2706d5c65159SKalle Valo struct wmi_init_country_cmd *cmd; 2707d5c65159SKalle Valo struct sk_buff *skb; 2708d5c65159SKalle Valo int ret; 2709d5c65159SKalle Valo 27106bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2711d5c65159SKalle Valo if (!skb) 2712d5c65159SKalle Valo return -ENOMEM; 2713d5c65159SKalle Valo 2714d5c65159SKalle Valo cmd = (struct wmi_init_country_cmd *)skb->data; 2715d5c65159SKalle Valo cmd->tlv_header = 2716d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, 2717d5c65159SKalle Valo WMI_TAG_SET_INIT_COUNTRY_CMD) | 2718d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2719d5c65159SKalle Valo 2720d5c65159SKalle Valo cmd->pdev_id = ar->pdev->pdev_id; 2721d5c65159SKalle Valo 2722d5c65159SKalle Valo switch (init_cc_params.flags) { 2723d5c65159SKalle Valo case ALPHA_IS_SET: 2724d5c65159SKalle Valo cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_ALPHA; 2725d5c65159SKalle Valo memcpy((u8 *)&cmd->cc_info.alpha2, 2726d5c65159SKalle Valo init_cc_params.cc_info.alpha2, 3); 2727d5c65159SKalle Valo break; 2728d5c65159SKalle Valo case CC_IS_SET: 2729d5c65159SKalle Valo cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_COUNTRY_CODE; 2730d5c65159SKalle Valo cmd->cc_info.country_code = init_cc_params.cc_info.country_code; 2731d5c65159SKalle Valo break; 2732d5c65159SKalle Valo case REGDMN_IS_SET: 2733d5c65159SKalle Valo cmd->init_cc_type = WMI_COUNTRY_INFO_TYPE_REGDOMAIN; 2734d5c65159SKalle Valo cmd->cc_info.regdom_id = init_cc_params.cc_info.regdom_id; 2735d5c65159SKalle Valo break; 2736d5c65159SKalle Valo default: 2737d5c65159SKalle Valo ret = -EINVAL; 2738d5c65159SKalle Valo goto out; 2739d5c65159SKalle Valo } 2740d5c65159SKalle Valo 2741d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2742d5c65159SKalle Valo WMI_SET_INIT_COUNTRY_CMDID); 2743d5c65159SKalle Valo 2744d5c65159SKalle Valo out: 2745d5c65159SKalle Valo if (ret) { 2746d5c65159SKalle Valo ath11k_warn(ar->ab, 2747d5c65159SKalle Valo "failed to send WMI_SET_INIT_COUNTRY CMD :%d\n", 2748d5c65159SKalle Valo ret); 2749d5c65159SKalle Valo dev_kfree_skb(skb); 2750d5c65159SKalle Valo } 2751d5c65159SKalle Valo 2752d5c65159SKalle Valo return ret; 2753d5c65159SKalle Valo } 2754d5c65159SKalle Valo 27552a63bbcaSPradeep Kumar Chitrapu int 27562a63bbcaSPradeep Kumar Chitrapu ath11k_wmi_send_thermal_mitigation_param_cmd(struct ath11k *ar, 27572a63bbcaSPradeep Kumar Chitrapu struct thermal_mitigation_params *param) 27582a63bbcaSPradeep Kumar Chitrapu { 27592a63bbcaSPradeep Kumar Chitrapu struct ath11k_pdev_wmi *wmi = ar->wmi; 27602a63bbcaSPradeep Kumar Chitrapu struct wmi_therm_throt_config_request_cmd *cmd; 27612a63bbcaSPradeep Kumar Chitrapu struct wmi_therm_throt_level_config_info *lvl_conf; 27622a63bbcaSPradeep Kumar Chitrapu struct wmi_tlv *tlv; 27632a63bbcaSPradeep Kumar Chitrapu struct sk_buff *skb; 27642a63bbcaSPradeep Kumar Chitrapu int i, ret, len; 27652a63bbcaSPradeep Kumar Chitrapu 27662a63bbcaSPradeep Kumar Chitrapu len = sizeof(*cmd) + TLV_HDR_SIZE + 27672a63bbcaSPradeep Kumar Chitrapu THERMAL_LEVELS * sizeof(struct wmi_therm_throt_level_config_info); 27682a63bbcaSPradeep Kumar Chitrapu 27692a63bbcaSPradeep Kumar Chitrapu skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 27702a63bbcaSPradeep Kumar Chitrapu if (!skb) 27712a63bbcaSPradeep Kumar Chitrapu return -ENOMEM; 27722a63bbcaSPradeep Kumar Chitrapu 27732a63bbcaSPradeep Kumar Chitrapu cmd = (struct wmi_therm_throt_config_request_cmd *)skb->data; 27742a63bbcaSPradeep Kumar Chitrapu 27752a63bbcaSPradeep Kumar Chitrapu cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_CONFIG_REQUEST) | 27762a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 27772a63bbcaSPradeep Kumar Chitrapu 27782a63bbcaSPradeep Kumar Chitrapu cmd->pdev_id = ar->pdev->pdev_id; 27792a63bbcaSPradeep Kumar Chitrapu cmd->enable = param->enable; 27802a63bbcaSPradeep Kumar Chitrapu cmd->dc = param->dc; 27812a63bbcaSPradeep Kumar Chitrapu cmd->dc_per_event = param->dc_per_event; 27822a63bbcaSPradeep Kumar Chitrapu cmd->therm_throt_levels = THERMAL_LEVELS; 27832a63bbcaSPradeep Kumar Chitrapu 27842a63bbcaSPradeep Kumar Chitrapu tlv = (struct wmi_tlv *)(skb->data + sizeof(*cmd)); 27852a63bbcaSPradeep Kumar Chitrapu tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 27862a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, 27872a63bbcaSPradeep Kumar Chitrapu (THERMAL_LEVELS * 27882a63bbcaSPradeep Kumar Chitrapu sizeof(struct wmi_therm_throt_level_config_info))); 27892a63bbcaSPradeep Kumar Chitrapu 27902a63bbcaSPradeep Kumar Chitrapu lvl_conf = (struct wmi_therm_throt_level_config_info *)(skb->data + 27912a63bbcaSPradeep Kumar Chitrapu sizeof(*cmd) + 27922a63bbcaSPradeep Kumar Chitrapu TLV_HDR_SIZE); 27932a63bbcaSPradeep Kumar Chitrapu for (i = 0; i < THERMAL_LEVELS; i++) { 27942a63bbcaSPradeep Kumar Chitrapu lvl_conf->tlv_header = 27952a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_TAG, WMI_TAG_THERM_THROT_LEVEL_CONFIG_INFO) | 27962a63bbcaSPradeep Kumar Chitrapu FIELD_PREP(WMI_TLV_LEN, sizeof(*lvl_conf) - TLV_HDR_SIZE); 27972a63bbcaSPradeep Kumar Chitrapu 27982a63bbcaSPradeep Kumar Chitrapu lvl_conf->temp_lwm = param->levelconf[i].tmplwm; 27992a63bbcaSPradeep Kumar Chitrapu lvl_conf->temp_hwm = param->levelconf[i].tmphwm; 28002a63bbcaSPradeep Kumar Chitrapu lvl_conf->dc_off_percent = param->levelconf[i].dcoffpercent; 28012a63bbcaSPradeep Kumar Chitrapu lvl_conf->prio = param->levelconf[i].priority; 28022a63bbcaSPradeep Kumar Chitrapu lvl_conf++; 28032a63bbcaSPradeep Kumar Chitrapu } 28042a63bbcaSPradeep Kumar Chitrapu 28052a63bbcaSPradeep Kumar Chitrapu ret = ath11k_wmi_cmd_send(wmi, skb, WMI_THERM_THROT_SET_CONF_CMDID); 28062a63bbcaSPradeep Kumar Chitrapu if (ret) { 28072a63bbcaSPradeep Kumar Chitrapu ath11k_warn(ar->ab, "failed to send THERM_THROT_SET_CONF cmd\n"); 28082a63bbcaSPradeep Kumar Chitrapu dev_kfree_skb(skb); 28092a63bbcaSPradeep Kumar Chitrapu } 28102a63bbcaSPradeep Kumar Chitrapu 28112a63bbcaSPradeep Kumar Chitrapu ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 28122a63bbcaSPradeep Kumar Chitrapu "WMI vdev set thermal throt pdev_id %d enable %d dc %d dc_per_event %x levels %d\n", 28132a63bbcaSPradeep Kumar Chitrapu ar->pdev->pdev_id, param->enable, param->dc, 28142a63bbcaSPradeep Kumar Chitrapu param->dc_per_event, THERMAL_LEVELS); 28152a63bbcaSPradeep Kumar Chitrapu 28162a63bbcaSPradeep Kumar Chitrapu return ret; 28172a63bbcaSPradeep Kumar Chitrapu } 28182a63bbcaSPradeep Kumar Chitrapu 2819d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_enable(struct ath11k *ar, u32 pktlog_filter) 2820d5c65159SKalle Valo { 2821d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2822d5c65159SKalle Valo struct wmi_pktlog_enable_cmd *cmd; 2823d5c65159SKalle Valo struct sk_buff *skb; 2824d5c65159SKalle Valo int ret; 2825d5c65159SKalle Valo 28266bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2827d5c65159SKalle Valo if (!skb) 2828d5c65159SKalle Valo return -ENOMEM; 2829d5c65159SKalle Valo 2830d5c65159SKalle Valo cmd = (struct wmi_pktlog_enable_cmd *)skb->data; 2831d5c65159SKalle Valo 2832d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_ENABLE_CMD) | 2833d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2834d5c65159SKalle Valo 2835d0f390eaSAnilkumar Kolli cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id); 2836d5c65159SKalle Valo cmd->evlist = pktlog_filter; 2837d5c65159SKalle Valo cmd->enable = ATH11K_WMI_PKTLOG_ENABLE_FORCE; 2838d5c65159SKalle Valo 2839d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2840d5c65159SKalle Valo WMI_PDEV_PKTLOG_ENABLE_CMDID); 2841d5c65159SKalle Valo if (ret) { 2842d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n"); 2843d5c65159SKalle Valo dev_kfree_skb(skb); 2844d5c65159SKalle Valo } 2845d5c65159SKalle Valo 2846d5c65159SKalle Valo return ret; 2847d5c65159SKalle Valo } 2848d5c65159SKalle Valo 2849d5c65159SKalle Valo int ath11k_wmi_pdev_pktlog_disable(struct ath11k *ar) 2850d5c65159SKalle Valo { 2851d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 2852d5c65159SKalle Valo struct wmi_pktlog_disable_cmd *cmd; 2853d5c65159SKalle Valo struct sk_buff *skb; 2854d5c65159SKalle Valo int ret; 2855d5c65159SKalle Valo 28566bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, sizeof(*cmd)); 2857d5c65159SKalle Valo if (!skb) 2858d5c65159SKalle Valo return -ENOMEM; 2859d5c65159SKalle Valo 2860d5c65159SKalle Valo cmd = (struct wmi_pktlog_disable_cmd *)skb->data; 2861d5c65159SKalle Valo 2862d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_PKTLOG_DISABLE_CMD) | 2863d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 2864d5c65159SKalle Valo 2865d0f390eaSAnilkumar Kolli cmd->pdev_id = DP_HW2SW_MACID(ar->pdev->pdev_id); 2866d5c65159SKalle Valo 2867d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, 2868d5c65159SKalle Valo WMI_PDEV_PKTLOG_DISABLE_CMDID); 2869d5c65159SKalle Valo if (ret) { 2870d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_PDEV_PKTLOG_ENABLE_CMDID\n"); 2871d5c65159SKalle Valo dev_kfree_skb(skb); 2872d5c65159SKalle Valo } 2873d5c65159SKalle Valo 2874d5c65159SKalle Valo return ret; 2875d5c65159SKalle Valo } 2876d5c65159SKalle Valo 28776d293d44SJohn Crispin int 28786d293d44SJohn Crispin ath11k_wmi_send_twt_enable_cmd(struct ath11k *ar, u32 pdev_id) 28796d293d44SJohn Crispin { 28806d293d44SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi; 28816bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 28826d293d44SJohn Crispin struct wmi_twt_enable_params_cmd *cmd; 28836d293d44SJohn Crispin struct sk_buff *skb; 28846d293d44SJohn Crispin int ret, len; 28856d293d44SJohn Crispin 28866d293d44SJohn Crispin len = sizeof(*cmd); 28876d293d44SJohn Crispin 28886bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 28896d293d44SJohn Crispin if (!skb) 28906d293d44SJohn Crispin return -ENOMEM; 28916d293d44SJohn Crispin 289277ea8b45SJohn Crispin cmd = (struct wmi_twt_enable_params_cmd *)skb->data; 28936d293d44SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_ENABLE_CMD) | 28946d293d44SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 28956d293d44SJohn Crispin cmd->pdev_id = pdev_id; 28966d293d44SJohn Crispin cmd->sta_cong_timer_ms = ATH11K_TWT_DEF_STA_CONG_TIMER_MS; 28976d293d44SJohn Crispin cmd->default_slot_size = ATH11K_TWT_DEF_DEFAULT_SLOT_SIZE; 28986d293d44SJohn Crispin cmd->congestion_thresh_setup = ATH11K_TWT_DEF_CONGESTION_THRESH_SETUP; 28996d293d44SJohn Crispin cmd->congestion_thresh_teardown = 29006d293d44SJohn Crispin ATH11K_TWT_DEF_CONGESTION_THRESH_TEARDOWN; 29016d293d44SJohn Crispin cmd->congestion_thresh_critical = 29026d293d44SJohn Crispin ATH11K_TWT_DEF_CONGESTION_THRESH_CRITICAL; 29036d293d44SJohn Crispin cmd->interference_thresh_teardown = 29046d293d44SJohn Crispin ATH11K_TWT_DEF_INTERFERENCE_THRESH_TEARDOWN; 29056d293d44SJohn Crispin cmd->interference_thresh_setup = 29066d293d44SJohn Crispin ATH11K_TWT_DEF_INTERFERENCE_THRESH_SETUP; 29076d293d44SJohn Crispin cmd->min_no_sta_setup = ATH11K_TWT_DEF_MIN_NO_STA_SETUP; 29086d293d44SJohn Crispin cmd->min_no_sta_teardown = ATH11K_TWT_DEF_MIN_NO_STA_TEARDOWN; 29096d293d44SJohn Crispin cmd->no_of_bcast_mcast_slots = ATH11K_TWT_DEF_NO_OF_BCAST_MCAST_SLOTS; 29106d293d44SJohn Crispin cmd->min_no_twt_slots = ATH11K_TWT_DEF_MIN_NO_TWT_SLOTS; 29116d293d44SJohn Crispin cmd->max_no_sta_twt = ATH11K_TWT_DEF_MAX_NO_STA_TWT; 29126d293d44SJohn Crispin cmd->mode_check_interval = ATH11K_TWT_DEF_MODE_CHECK_INTERVAL; 29136d293d44SJohn Crispin cmd->add_sta_slot_interval = ATH11K_TWT_DEF_ADD_STA_SLOT_INTERVAL; 29146d293d44SJohn Crispin cmd->remove_sta_slot_interval = 29156d293d44SJohn Crispin ATH11K_TWT_DEF_REMOVE_STA_SLOT_INTERVAL; 29166d293d44SJohn Crispin /* TODO add MBSSID support */ 29176d293d44SJohn Crispin cmd->mbss_support = 0; 29186d293d44SJohn Crispin 29196d293d44SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, 29206d293d44SJohn Crispin WMI_TWT_ENABLE_CMDID); 29216d293d44SJohn Crispin if (ret) { 29226d293d44SJohn Crispin ath11k_warn(ab, "Failed to send WMI_TWT_ENABLE_CMDID"); 29236d293d44SJohn Crispin dev_kfree_skb(skb); 29246d293d44SJohn Crispin } 29256d293d44SJohn Crispin return ret; 29266d293d44SJohn Crispin } 29276d293d44SJohn Crispin 29286d293d44SJohn Crispin int 29296d293d44SJohn Crispin ath11k_wmi_send_twt_disable_cmd(struct ath11k *ar, u32 pdev_id) 29306d293d44SJohn Crispin { 29316d293d44SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi; 29326bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 29336d293d44SJohn Crispin struct wmi_twt_disable_params_cmd *cmd; 29346d293d44SJohn Crispin struct sk_buff *skb; 29356d293d44SJohn Crispin int ret, len; 29366d293d44SJohn Crispin 29376d293d44SJohn Crispin len = sizeof(*cmd); 29386d293d44SJohn Crispin 29396bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 29406d293d44SJohn Crispin if (!skb) 29416d293d44SJohn Crispin return -ENOMEM; 29426d293d44SJohn Crispin 294377ea8b45SJohn Crispin cmd = (struct wmi_twt_disable_params_cmd *)skb->data; 29446d293d44SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_TWT_DISABLE_CMD) | 29456d293d44SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 29466d293d44SJohn Crispin cmd->pdev_id = pdev_id; 29476d293d44SJohn Crispin 29486d293d44SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, 29496d293d44SJohn Crispin WMI_TWT_DISABLE_CMDID); 29506d293d44SJohn Crispin if (ret) { 2951345a4f22SColin Ian King ath11k_warn(ab, "Failed to send WMI_TWT_DISABLE_CMDID"); 29526d293d44SJohn Crispin dev_kfree_skb(skb); 29536d293d44SJohn Crispin } 29546d293d44SJohn Crispin return ret; 29556d293d44SJohn Crispin } 29566d293d44SJohn Crispin 29573f8be640SJohn Crispin int 29583f8be640SJohn Crispin ath11k_wmi_send_obss_spr_cmd(struct ath11k *ar, u32 vdev_id, 29593f8be640SJohn Crispin struct ieee80211_he_obss_pd *he_obss_pd) 29603f8be640SJohn Crispin { 29613f8be640SJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi; 29626bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 29633f8be640SJohn Crispin struct wmi_obss_spatial_reuse_params_cmd *cmd; 29643f8be640SJohn Crispin struct sk_buff *skb; 29653f8be640SJohn Crispin int ret, len; 29663f8be640SJohn Crispin 29673f8be640SJohn Crispin len = sizeof(*cmd); 29683f8be640SJohn Crispin 29696bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 29703f8be640SJohn Crispin if (!skb) 29713f8be640SJohn Crispin return -ENOMEM; 29723f8be640SJohn Crispin 297377ea8b45SJohn Crispin cmd = (struct wmi_obss_spatial_reuse_params_cmd *)skb->data; 29743f8be640SJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 29753f8be640SJohn Crispin WMI_TAG_OBSS_SPATIAL_REUSE_SET_CMD) | 29763f8be640SJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 29773f8be640SJohn Crispin cmd->vdev_id = vdev_id; 29783f8be640SJohn Crispin cmd->enable = he_obss_pd->enable; 29793f8be640SJohn Crispin cmd->obss_min = he_obss_pd->min_offset; 29803f8be640SJohn Crispin cmd->obss_max = he_obss_pd->max_offset; 29813f8be640SJohn Crispin 29823f8be640SJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, 29833f8be640SJohn Crispin WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID); 29843f8be640SJohn Crispin if (ret) { 29853f8be640SJohn Crispin ath11k_warn(ab, 29863f8be640SJohn Crispin "Failed to send WMI_PDEV_OBSS_PD_SPATIAL_REUSE_CMDID"); 29873f8be640SJohn Crispin dev_kfree_skb(skb); 29883f8be640SJohn Crispin } 29893f8be640SJohn Crispin return ret; 29903f8be640SJohn Crispin } 29913f8be640SJohn Crispin 29925a032c8dSJohn Crispin int 2993b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_bss_color_bitmap(struct ath11k *ar, u32 *bitmap) 2994b56b08aeSRajkumar Manoharan { 2995b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi; 2996b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab; 2997b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd; 2998b56b08aeSRajkumar Manoharan struct sk_buff *skb; 2999b56b08aeSRajkumar Manoharan int ret, len; 3000b56b08aeSRajkumar Manoharan 3001b56b08aeSRajkumar Manoharan len = sizeof(*cmd); 3002b56b08aeSRajkumar Manoharan 3003b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3004b56b08aeSRajkumar Manoharan if (!skb) 3005b56b08aeSRajkumar Manoharan return -ENOMEM; 3006b56b08aeSRajkumar Manoharan 3007b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data; 3008b56b08aeSRajkumar Manoharan cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3009b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_BSS_COLOR_BITMAP_CMD) | 3010b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3011b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id; 3012b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap)); 3013b56b08aeSRajkumar Manoharan 3014b56b08aeSRajkumar Manoharan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3015b56b08aeSRajkumar Manoharan "obss pd pdev_id %d bss color bitmap %08x %08x\n", 3016b56b08aeSRajkumar Manoharan cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]); 3017b56b08aeSRajkumar Manoharan 3018b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb, 3019b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID); 3020b56b08aeSRajkumar Manoharan if (ret) { 3021b56b08aeSRajkumar Manoharan ath11k_warn(ab, 3022b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_BSS_COLOR_BITMAP_CMDID"); 3023b56b08aeSRajkumar Manoharan dev_kfree_skb(skb); 3024b56b08aeSRajkumar Manoharan } 3025b56b08aeSRajkumar Manoharan 3026b56b08aeSRajkumar Manoharan return ret; 3027b56b08aeSRajkumar Manoharan } 3028b56b08aeSRajkumar Manoharan 3029b56b08aeSRajkumar Manoharan int 3030b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(struct ath11k *ar, u32 *bitmap) 3031b56b08aeSRajkumar Manoharan { 3032b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi; 3033b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab; 3034b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd; 3035b56b08aeSRajkumar Manoharan struct sk_buff *skb; 3036b56b08aeSRajkumar Manoharan int ret, len; 3037b56b08aeSRajkumar Manoharan 3038b56b08aeSRajkumar Manoharan len = sizeof(*cmd); 3039b56b08aeSRajkumar Manoharan 3040b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3041b56b08aeSRajkumar Manoharan if (!skb) 3042b56b08aeSRajkumar Manoharan return -ENOMEM; 3043b56b08aeSRajkumar Manoharan 3044b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data; 3045b56b08aeSRajkumar Manoharan cmd->tlv_header = 3046b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG, 3047b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_PARTIAL_BSSID_BITMAP_CMD) | 3048b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3049b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id; 3050b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap)); 3051b56b08aeSRajkumar Manoharan 3052b56b08aeSRajkumar Manoharan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3053b56b08aeSRajkumar Manoharan "obss pd pdev_id %d partial bssid bitmap %08x %08x\n", 3054b56b08aeSRajkumar Manoharan cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]); 3055b56b08aeSRajkumar Manoharan 3056b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb, 3057b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID); 3058b56b08aeSRajkumar Manoharan if (ret) { 3059b56b08aeSRajkumar Manoharan ath11k_warn(ab, 3060b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_PARTIAL_BSSID_BITMAP_CMDID"); 3061b56b08aeSRajkumar Manoharan dev_kfree_skb(skb); 3062b56b08aeSRajkumar Manoharan } 3063b56b08aeSRajkumar Manoharan 3064b56b08aeSRajkumar Manoharan return ret; 3065b56b08aeSRajkumar Manoharan } 3066b56b08aeSRajkumar Manoharan 3067b56b08aeSRajkumar Manoharan int 3068b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap) 3069b56b08aeSRajkumar Manoharan { 3070b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi; 3071b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab; 3072b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd; 3073b56b08aeSRajkumar Manoharan struct sk_buff *skb; 3074b56b08aeSRajkumar Manoharan int ret, len; 3075b56b08aeSRajkumar Manoharan 3076b56b08aeSRajkumar Manoharan len = sizeof(*cmd); 3077b56b08aeSRajkumar Manoharan 3078b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3079b56b08aeSRajkumar Manoharan if (!skb) 3080b56b08aeSRajkumar Manoharan return -ENOMEM; 3081b56b08aeSRajkumar Manoharan 3082b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data; 3083b56b08aeSRajkumar Manoharan cmd->tlv_header = 3084b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG, 3085b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) | 3086b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3087b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id; 3088b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap)); 3089b56b08aeSRajkumar Manoharan 3090b56b08aeSRajkumar Manoharan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3091b56b08aeSRajkumar Manoharan "obss pd srg pdev_id %d bss color enable bitmap %08x %08x\n", 3092b56b08aeSRajkumar Manoharan cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]); 3093b56b08aeSRajkumar Manoharan 3094b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb, 3095b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID); 3096b56b08aeSRajkumar Manoharan if (ret) { 3097b56b08aeSRajkumar Manoharan ath11k_warn(ab, 3098b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID"); 3099b56b08aeSRajkumar Manoharan dev_kfree_skb(skb); 3100b56b08aeSRajkumar Manoharan } 3101b56b08aeSRajkumar Manoharan 3102b56b08aeSRajkumar Manoharan return ret; 3103b56b08aeSRajkumar Manoharan } 3104b56b08aeSRajkumar Manoharan 3105b56b08aeSRajkumar Manoharan int 3106b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap) 3107b56b08aeSRajkumar Manoharan { 3108b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi; 3109b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab; 3110b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd; 3111b56b08aeSRajkumar Manoharan struct sk_buff *skb; 3112b56b08aeSRajkumar Manoharan int ret, len; 3113b56b08aeSRajkumar Manoharan 3114b56b08aeSRajkumar Manoharan len = sizeof(*cmd); 3115b56b08aeSRajkumar Manoharan 3116b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3117b56b08aeSRajkumar Manoharan if (!skb) 3118b56b08aeSRajkumar Manoharan return -ENOMEM; 3119b56b08aeSRajkumar Manoharan 3120b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data; 3121b56b08aeSRajkumar Manoharan cmd->tlv_header = 3122b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG, 3123b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) | 3124b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3125b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id; 3126b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap)); 3127b56b08aeSRajkumar Manoharan 3128b56b08aeSRajkumar Manoharan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3129b56b08aeSRajkumar Manoharan "obss pd srg pdev_id %d bssid enable bitmap %08x %08x\n", 3130b56b08aeSRajkumar Manoharan cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]); 3131b56b08aeSRajkumar Manoharan 3132b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb, 3133b56b08aeSRajkumar Manoharan WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID); 3134b56b08aeSRajkumar Manoharan if (ret) { 3135b56b08aeSRajkumar Manoharan ath11k_warn(ab, 3136b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID"); 3137b56b08aeSRajkumar Manoharan dev_kfree_skb(skb); 3138b56b08aeSRajkumar Manoharan } 3139b56b08aeSRajkumar Manoharan 3140b56b08aeSRajkumar Manoharan return ret; 3141b56b08aeSRajkumar Manoharan } 3142b56b08aeSRajkumar Manoharan 3143b56b08aeSRajkumar Manoharan int 3144b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(struct ath11k *ar, u32 *bitmap) 3145b56b08aeSRajkumar Manoharan { 3146b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi; 3147b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab; 3148b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd; 3149b56b08aeSRajkumar Manoharan struct sk_buff *skb; 3150b56b08aeSRajkumar Manoharan int ret, len; 3151b56b08aeSRajkumar Manoharan 3152b56b08aeSRajkumar Manoharan len = sizeof(*cmd); 3153b56b08aeSRajkumar Manoharan 3154b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3155b56b08aeSRajkumar Manoharan if (!skb) 3156b56b08aeSRajkumar Manoharan return -ENOMEM; 3157b56b08aeSRajkumar Manoharan 3158b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data; 3159b56b08aeSRajkumar Manoharan cmd->tlv_header = 3160b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG, 3161b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMD) | 3162b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3163b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id; 3164b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap)); 3165b56b08aeSRajkumar Manoharan 3166b56b08aeSRajkumar Manoharan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3167b56b08aeSRajkumar Manoharan "obss pd non_srg pdev_id %d bss color enable bitmap %08x %08x\n", 3168b56b08aeSRajkumar Manoharan cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]); 3169b56b08aeSRajkumar Manoharan 3170b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb, 3171b56b08aeSRajkumar Manoharan WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID); 3172b56b08aeSRajkumar Manoharan if (ret) { 3173b56b08aeSRajkumar Manoharan ath11k_warn(ab, 3174b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_NON_SRG_OBSS_COLOR_ENABLE_BITMAP_CMDID"); 3175b56b08aeSRajkumar Manoharan dev_kfree_skb(skb); 3176b56b08aeSRajkumar Manoharan } 3177b56b08aeSRajkumar Manoharan 3178b56b08aeSRajkumar Manoharan return ret; 3179b56b08aeSRajkumar Manoharan } 3180b56b08aeSRajkumar Manoharan 3181b56b08aeSRajkumar Manoharan int 3182b56b08aeSRajkumar Manoharan ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(struct ath11k *ar, u32 *bitmap) 3183b56b08aeSRajkumar Manoharan { 3184b56b08aeSRajkumar Manoharan struct ath11k_pdev_wmi *wmi = ar->wmi; 3185b56b08aeSRajkumar Manoharan struct ath11k_base *ab = wmi->wmi_ab->ab; 3186b56b08aeSRajkumar Manoharan struct wmi_pdev_obss_pd_bitmap_cmd *cmd; 3187b56b08aeSRajkumar Manoharan struct sk_buff *skb; 3188b56b08aeSRajkumar Manoharan int ret, len; 3189b56b08aeSRajkumar Manoharan 3190b56b08aeSRajkumar Manoharan len = sizeof(*cmd); 3191b56b08aeSRajkumar Manoharan 3192b56b08aeSRajkumar Manoharan skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3193b56b08aeSRajkumar Manoharan if (!skb) 3194b56b08aeSRajkumar Manoharan return -ENOMEM; 3195b56b08aeSRajkumar Manoharan 3196b56b08aeSRajkumar Manoharan cmd = (struct wmi_pdev_obss_pd_bitmap_cmd *)skb->data; 3197b56b08aeSRajkumar Manoharan cmd->tlv_header = 3198b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_TAG, 3199b56b08aeSRajkumar Manoharan WMI_TAG_PDEV_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMD) | 3200b56b08aeSRajkumar Manoharan FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3201b56b08aeSRajkumar Manoharan cmd->pdev_id = ar->pdev->pdev_id; 3202b56b08aeSRajkumar Manoharan memcpy(cmd->bitmap, bitmap, sizeof(cmd->bitmap)); 3203b56b08aeSRajkumar Manoharan 3204b56b08aeSRajkumar Manoharan ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3205b56b08aeSRajkumar Manoharan "obss pd non_srg pdev_id %d bssid enable bitmap %08x %08x\n", 3206b56b08aeSRajkumar Manoharan cmd->pdev_id, cmd->bitmap[0], cmd->bitmap[1]); 3207b56b08aeSRajkumar Manoharan 3208b56b08aeSRajkumar Manoharan ret = ath11k_wmi_cmd_send(wmi, skb, 3209b56b08aeSRajkumar Manoharan WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID); 3210b56b08aeSRajkumar Manoharan if (ret) { 3211b56b08aeSRajkumar Manoharan ath11k_warn(ab, 3212b56b08aeSRajkumar Manoharan "failed to send WMI_PDEV_SET_NON_SRG_OBSS_BSSID_ENABLE_BITMAP_CMDID"); 3213b56b08aeSRajkumar Manoharan dev_kfree_skb(skb); 3214b56b08aeSRajkumar Manoharan } 3215b56b08aeSRajkumar Manoharan 3216b56b08aeSRajkumar Manoharan return ret; 3217b56b08aeSRajkumar Manoharan } 3218b56b08aeSRajkumar Manoharan 3219b56b08aeSRajkumar Manoharan int 32205a032c8dSJohn Crispin ath11k_wmi_send_obss_color_collision_cfg_cmd(struct ath11k *ar, u32 vdev_id, 32215a032c8dSJohn Crispin u8 bss_color, u32 period, 32225a032c8dSJohn Crispin bool enable) 32235a032c8dSJohn Crispin { 32245a032c8dSJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi; 32255a032c8dSJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 32265a032c8dSJohn Crispin struct wmi_obss_color_collision_cfg_params_cmd *cmd; 32275a032c8dSJohn Crispin struct sk_buff *skb; 32285a032c8dSJohn Crispin int ret, len; 32295a032c8dSJohn Crispin 32305a032c8dSJohn Crispin len = sizeof(*cmd); 32315a032c8dSJohn Crispin 32325a032c8dSJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 32335a032c8dSJohn Crispin if (!skb) 32345a032c8dSJohn Crispin return -ENOMEM; 32355a032c8dSJohn Crispin 32365a032c8dSJohn Crispin cmd = (struct wmi_obss_color_collision_cfg_params_cmd *)skb->data; 32375a032c8dSJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 32385a032c8dSJohn Crispin WMI_TAG_OBSS_COLOR_COLLISION_DET_CONFIG) | 32395a032c8dSJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 32405a032c8dSJohn Crispin cmd->vdev_id = vdev_id; 32415a032c8dSJohn Crispin cmd->evt_type = enable ? ATH11K_OBSS_COLOR_COLLISION_DETECTION : 32425a032c8dSJohn Crispin ATH11K_OBSS_COLOR_COLLISION_DETECTION_DISABLE; 32435a032c8dSJohn Crispin cmd->current_bss_color = bss_color; 32445a032c8dSJohn Crispin cmd->detection_period_ms = period; 32455a032c8dSJohn Crispin cmd->scan_period_ms = ATH11K_BSS_COLOR_COLLISION_SCAN_PERIOD_MS; 32465a032c8dSJohn Crispin cmd->free_slot_expiry_time_ms = 0; 32475a032c8dSJohn Crispin cmd->flags = 0; 32485a032c8dSJohn Crispin 32495a032c8dSJohn Crispin ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 32505a032c8dSJohn Crispin "wmi_send_obss_color_collision_cfg id %d type %d bss_color %d detect_period %d scan_period %d\n", 32515a032c8dSJohn Crispin cmd->vdev_id, cmd->evt_type, cmd->current_bss_color, 32525a032c8dSJohn Crispin cmd->detection_period_ms, cmd->scan_period_ms); 32535a032c8dSJohn Crispin 32545a032c8dSJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, 32555a032c8dSJohn Crispin WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID); 32565a032c8dSJohn Crispin if (ret) { 32575a032c8dSJohn Crispin ath11k_warn(ab, "Failed to send WMI_OBSS_COLOR_COLLISION_DET_CONFIG_CMDID"); 32585a032c8dSJohn Crispin dev_kfree_skb(skb); 32595a032c8dSJohn Crispin } 32605a032c8dSJohn Crispin return ret; 32615a032c8dSJohn Crispin } 32625a032c8dSJohn Crispin 32635a032c8dSJohn Crispin int ath11k_wmi_send_bss_color_change_enable_cmd(struct ath11k *ar, u32 vdev_id, 32645a032c8dSJohn Crispin bool enable) 32655a032c8dSJohn Crispin { 32665a032c8dSJohn Crispin struct ath11k_pdev_wmi *wmi = ar->wmi; 32675a032c8dSJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 32685a032c8dSJohn Crispin struct wmi_bss_color_change_enable_params_cmd *cmd; 32695a032c8dSJohn Crispin struct sk_buff *skb; 32705a032c8dSJohn Crispin int ret, len; 32715a032c8dSJohn Crispin 32725a032c8dSJohn Crispin len = sizeof(*cmd); 32735a032c8dSJohn Crispin 32745a032c8dSJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 32755a032c8dSJohn Crispin if (!skb) 32765a032c8dSJohn Crispin return -ENOMEM; 32775a032c8dSJohn Crispin 32785a032c8dSJohn Crispin cmd = (struct wmi_bss_color_change_enable_params_cmd *)skb->data; 32795a032c8dSJohn Crispin cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_BSS_COLOR_CHANGE_ENABLE) | 32805a032c8dSJohn Crispin FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 32815a032c8dSJohn Crispin cmd->vdev_id = vdev_id; 32825a032c8dSJohn Crispin cmd->enable = enable ? 1 : 0; 32835a032c8dSJohn Crispin 32845a032c8dSJohn Crispin ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 32855a032c8dSJohn Crispin "wmi_send_bss_color_change_enable id %d enable %d\n", 32865a032c8dSJohn Crispin cmd->vdev_id, cmd->enable); 32875a032c8dSJohn Crispin 32885a032c8dSJohn Crispin ret = ath11k_wmi_cmd_send(wmi, skb, 32895a032c8dSJohn Crispin WMI_BSS_COLOR_CHANGE_ENABLE_CMDID); 32905a032c8dSJohn Crispin if (ret) { 32919a8074e3SColin Ian King ath11k_warn(ab, "Failed to send WMI_BSS_COLOR_CHANGE_ENABLE_CMDID"); 32925a032c8dSJohn Crispin dev_kfree_skb(skb); 32935a032c8dSJohn Crispin } 32945a032c8dSJohn Crispin return ret; 32955a032c8dSJohn Crispin } 32965a032c8dSJohn Crispin 3297047679e3SAloka Dixit int ath11k_wmi_fils_discovery_tmpl(struct ath11k *ar, u32 vdev_id, 3298047679e3SAloka Dixit struct sk_buff *tmpl) 3299047679e3SAloka Dixit { 3300047679e3SAloka Dixit struct wmi_tlv *tlv; 3301047679e3SAloka Dixit struct sk_buff *skb; 3302047679e3SAloka Dixit void *ptr; 3303047679e3SAloka Dixit int ret, len; 3304047679e3SAloka Dixit size_t aligned_len; 3305047679e3SAloka Dixit struct wmi_fils_discovery_tmpl_cmd *cmd; 3306047679e3SAloka Dixit 3307047679e3SAloka Dixit aligned_len = roundup(tmpl->len, 4); 3308047679e3SAloka Dixit len = sizeof(*cmd) + TLV_HDR_SIZE + aligned_len; 3309047679e3SAloka Dixit 3310047679e3SAloka Dixit ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3311047679e3SAloka Dixit "WMI vdev %i set FILS discovery template\n", vdev_id); 3312047679e3SAloka Dixit 3313047679e3SAloka Dixit skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len); 3314047679e3SAloka Dixit if (!skb) 3315047679e3SAloka Dixit return -ENOMEM; 3316047679e3SAloka Dixit 3317047679e3SAloka Dixit cmd = (struct wmi_fils_discovery_tmpl_cmd *)skb->data; 3318047679e3SAloka Dixit cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3319047679e3SAloka Dixit WMI_TAG_FILS_DISCOVERY_TMPL_CMD) | 3320047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3321047679e3SAloka Dixit cmd->vdev_id = vdev_id; 3322047679e3SAloka Dixit cmd->buf_len = tmpl->len; 3323047679e3SAloka Dixit ptr = skb->data + sizeof(*cmd); 3324047679e3SAloka Dixit 3325047679e3SAloka Dixit tlv = ptr; 3326047679e3SAloka Dixit tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 3327047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, aligned_len); 3328047679e3SAloka Dixit memcpy(tlv->value, tmpl->data, tmpl->len); 3329047679e3SAloka Dixit 3330047679e3SAloka Dixit ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_FILS_DISCOVERY_TMPL_CMDID); 3331047679e3SAloka Dixit if (ret) { 3332047679e3SAloka Dixit ath11k_warn(ar->ab, 3333047679e3SAloka Dixit "WMI vdev %i failed to send FILS discovery template command\n", 3334047679e3SAloka Dixit vdev_id); 3335047679e3SAloka Dixit dev_kfree_skb(skb); 3336047679e3SAloka Dixit } 3337047679e3SAloka Dixit return ret; 3338047679e3SAloka Dixit } 3339047679e3SAloka Dixit 3340047679e3SAloka Dixit int ath11k_wmi_probe_resp_tmpl(struct ath11k *ar, u32 vdev_id, 3341047679e3SAloka Dixit struct sk_buff *tmpl) 3342047679e3SAloka Dixit { 3343047679e3SAloka Dixit struct wmi_probe_tmpl_cmd *cmd; 3344047679e3SAloka Dixit struct wmi_bcn_prb_info *probe_info; 3345047679e3SAloka Dixit struct wmi_tlv *tlv; 3346047679e3SAloka Dixit struct sk_buff *skb; 3347047679e3SAloka Dixit void *ptr; 3348047679e3SAloka Dixit int ret, len; 3349047679e3SAloka Dixit size_t aligned_len = roundup(tmpl->len, 4); 3350047679e3SAloka Dixit 3351047679e3SAloka Dixit ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3352047679e3SAloka Dixit "WMI vdev %i set probe response template\n", vdev_id); 3353047679e3SAloka Dixit 3354047679e3SAloka Dixit len = sizeof(*cmd) + sizeof(*probe_info) + TLV_HDR_SIZE + aligned_len; 3355047679e3SAloka Dixit 3356047679e3SAloka Dixit skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len); 3357047679e3SAloka Dixit if (!skb) 3358047679e3SAloka Dixit return -ENOMEM; 3359047679e3SAloka Dixit 3360047679e3SAloka Dixit cmd = (struct wmi_probe_tmpl_cmd *)skb->data; 3361047679e3SAloka Dixit cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PRB_TMPL_CMD) | 3362047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3363047679e3SAloka Dixit cmd->vdev_id = vdev_id; 3364047679e3SAloka Dixit cmd->buf_len = tmpl->len; 3365047679e3SAloka Dixit 3366047679e3SAloka Dixit ptr = skb->data + sizeof(*cmd); 3367047679e3SAloka Dixit 3368047679e3SAloka Dixit probe_info = ptr; 3369047679e3SAloka Dixit len = sizeof(*probe_info); 3370047679e3SAloka Dixit probe_info->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3371047679e3SAloka Dixit WMI_TAG_BCN_PRB_INFO) | 3372047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3373047679e3SAloka Dixit probe_info->caps = 0; 3374047679e3SAloka Dixit probe_info->erp = 0; 3375047679e3SAloka Dixit 3376047679e3SAloka Dixit ptr += sizeof(*probe_info); 3377047679e3SAloka Dixit 3378047679e3SAloka Dixit tlv = ptr; 3379047679e3SAloka Dixit tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_BYTE) | 3380047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, aligned_len); 3381047679e3SAloka Dixit memcpy(tlv->value, tmpl->data, tmpl->len); 3382047679e3SAloka Dixit 3383047679e3SAloka Dixit ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_PRB_TMPL_CMDID); 3384047679e3SAloka Dixit if (ret) { 3385047679e3SAloka Dixit ath11k_warn(ar->ab, 3386047679e3SAloka Dixit "WMI vdev %i failed to send probe response template command\n", 3387047679e3SAloka Dixit vdev_id); 3388047679e3SAloka Dixit dev_kfree_skb(skb); 3389047679e3SAloka Dixit } 3390047679e3SAloka Dixit return ret; 3391047679e3SAloka Dixit } 3392047679e3SAloka Dixit 3393047679e3SAloka Dixit int ath11k_wmi_fils_discovery(struct ath11k *ar, u32 vdev_id, u32 interval, 3394047679e3SAloka Dixit bool unsol_bcast_probe_resp_enabled) 3395047679e3SAloka Dixit { 3396047679e3SAloka Dixit struct sk_buff *skb; 3397047679e3SAloka Dixit int ret, len; 3398047679e3SAloka Dixit struct wmi_fils_discovery_cmd *cmd; 3399047679e3SAloka Dixit 3400047679e3SAloka Dixit ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3401047679e3SAloka Dixit "WMI vdev %i set %s interval to %u TU\n", 3402047679e3SAloka Dixit vdev_id, unsol_bcast_probe_resp_enabled ? 3403047679e3SAloka Dixit "unsolicited broadcast probe response" : "FILS discovery", 3404047679e3SAloka Dixit interval); 3405047679e3SAloka Dixit 3406047679e3SAloka Dixit len = sizeof(*cmd); 3407047679e3SAloka Dixit skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len); 3408047679e3SAloka Dixit if (!skb) 3409047679e3SAloka Dixit return -ENOMEM; 3410047679e3SAloka Dixit 3411047679e3SAloka Dixit cmd = (struct wmi_fils_discovery_cmd *)skb->data; 3412047679e3SAloka Dixit cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ENABLE_FILS_CMD) | 3413047679e3SAloka Dixit FIELD_PREP(WMI_TLV_LEN, len - TLV_HDR_SIZE); 3414047679e3SAloka Dixit cmd->vdev_id = vdev_id; 3415047679e3SAloka Dixit cmd->interval = interval; 3416047679e3SAloka Dixit cmd->config = unsol_bcast_probe_resp_enabled; 3417047679e3SAloka Dixit 3418047679e3SAloka Dixit ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_ENABLE_FILS_CMDID); 3419047679e3SAloka Dixit if (ret) { 3420047679e3SAloka Dixit ath11k_warn(ar->ab, 3421047679e3SAloka Dixit "WMI vdev %i failed to send FILS discovery enable/disable command\n", 3422047679e3SAloka Dixit vdev_id); 3423047679e3SAloka Dixit dev_kfree_skb(skb); 3424047679e3SAloka Dixit } 3425047679e3SAloka Dixit return ret; 3426047679e3SAloka Dixit } 3427047679e3SAloka Dixit 3428d5c65159SKalle Valo static void 3429d5c65159SKalle Valo ath11k_fill_band_to_mac_param(struct ath11k_base *soc, 3430d5c65159SKalle Valo struct wmi_host_pdev_band_to_mac *band_to_mac) 3431d5c65159SKalle Valo { 3432d5c65159SKalle Valo u8 i; 3433d5c65159SKalle Valo struct ath11k_hal_reg_capabilities_ext *hal_reg_cap; 3434d5c65159SKalle Valo struct ath11k_pdev *pdev; 3435d5c65159SKalle Valo 3436d5c65159SKalle Valo for (i = 0; i < soc->num_radios; i++) { 3437d5c65159SKalle Valo pdev = &soc->pdevs[i]; 3438d5c65159SKalle Valo hal_reg_cap = &soc->hal_reg_cap[i]; 3439d5c65159SKalle Valo band_to_mac[i].pdev_id = pdev->pdev_id; 3440d5c65159SKalle Valo 3441d5c65159SKalle Valo switch (pdev->cap.supported_bands) { 3442d5c65159SKalle Valo case WMI_HOST_WLAN_2G_5G_CAP: 3443d5c65159SKalle Valo band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan; 3444d5c65159SKalle Valo band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan; 3445d5c65159SKalle Valo break; 3446d5c65159SKalle Valo case WMI_HOST_WLAN_2G_CAP: 3447d5c65159SKalle Valo band_to_mac[i].start_freq = hal_reg_cap->low_2ghz_chan; 3448d5c65159SKalle Valo band_to_mac[i].end_freq = hal_reg_cap->high_2ghz_chan; 3449d5c65159SKalle Valo break; 3450d5c65159SKalle Valo case WMI_HOST_WLAN_5G_CAP: 3451d5c65159SKalle Valo band_to_mac[i].start_freq = hal_reg_cap->low_5ghz_chan; 3452d5c65159SKalle Valo band_to_mac[i].end_freq = hal_reg_cap->high_5ghz_chan; 3453d5c65159SKalle Valo break; 3454d5c65159SKalle Valo default: 3455d5c65159SKalle Valo break; 3456d5c65159SKalle Valo } 3457d5c65159SKalle Valo } 3458d5c65159SKalle Valo } 3459d5c65159SKalle Valo 3460d5c65159SKalle Valo static void 3461d5c65159SKalle Valo ath11k_wmi_copy_resource_config(struct wmi_resource_config *wmi_cfg, 3462d5c65159SKalle Valo struct target_resource_config *tg_cfg) 3463d5c65159SKalle Valo { 3464d5c65159SKalle Valo wmi_cfg->num_vdevs = tg_cfg->num_vdevs; 3465d5c65159SKalle Valo wmi_cfg->num_peers = tg_cfg->num_peers; 3466d5c65159SKalle Valo wmi_cfg->num_offload_peers = tg_cfg->num_offload_peers; 3467d5c65159SKalle Valo wmi_cfg->num_offload_reorder_buffs = tg_cfg->num_offload_reorder_buffs; 3468d5c65159SKalle Valo wmi_cfg->num_peer_keys = tg_cfg->num_peer_keys; 3469d5c65159SKalle Valo wmi_cfg->num_tids = tg_cfg->num_tids; 3470d5c65159SKalle Valo wmi_cfg->ast_skid_limit = tg_cfg->ast_skid_limit; 3471d5c65159SKalle Valo wmi_cfg->tx_chain_mask = tg_cfg->tx_chain_mask; 3472d5c65159SKalle Valo wmi_cfg->rx_chain_mask = tg_cfg->rx_chain_mask; 3473d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[0] = tg_cfg->rx_timeout_pri[0]; 3474d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[1] = tg_cfg->rx_timeout_pri[1]; 3475d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[2] = tg_cfg->rx_timeout_pri[2]; 3476d5c65159SKalle Valo wmi_cfg->rx_timeout_pri[3] = tg_cfg->rx_timeout_pri[3]; 3477d5c65159SKalle Valo wmi_cfg->rx_decap_mode = tg_cfg->rx_decap_mode; 3478d5c65159SKalle Valo wmi_cfg->scan_max_pending_req = tg_cfg->scan_max_pending_req; 3479d5c65159SKalle Valo wmi_cfg->bmiss_offload_max_vdev = tg_cfg->bmiss_offload_max_vdev; 3480d5c65159SKalle Valo wmi_cfg->roam_offload_max_vdev = tg_cfg->roam_offload_max_vdev; 3481d5c65159SKalle Valo wmi_cfg->roam_offload_max_ap_profiles = 3482d5c65159SKalle Valo tg_cfg->roam_offload_max_ap_profiles; 3483d5c65159SKalle Valo wmi_cfg->num_mcast_groups = tg_cfg->num_mcast_groups; 3484d5c65159SKalle Valo wmi_cfg->num_mcast_table_elems = tg_cfg->num_mcast_table_elems; 3485d5c65159SKalle Valo wmi_cfg->mcast2ucast_mode = tg_cfg->mcast2ucast_mode; 3486d5c65159SKalle Valo wmi_cfg->tx_dbg_log_size = tg_cfg->tx_dbg_log_size; 3487d5c65159SKalle Valo wmi_cfg->num_wds_entries = tg_cfg->num_wds_entries; 3488d5c65159SKalle Valo wmi_cfg->dma_burst_size = tg_cfg->dma_burst_size; 3489d5c65159SKalle Valo wmi_cfg->mac_aggr_delim = tg_cfg->mac_aggr_delim; 3490d5c65159SKalle Valo wmi_cfg->rx_skip_defrag_timeout_dup_detection_check = 3491d5c65159SKalle Valo tg_cfg->rx_skip_defrag_timeout_dup_detection_check; 3492d5c65159SKalle Valo wmi_cfg->vow_config = tg_cfg->vow_config; 3493d5c65159SKalle Valo wmi_cfg->gtk_offload_max_vdev = tg_cfg->gtk_offload_max_vdev; 3494d5c65159SKalle Valo wmi_cfg->num_msdu_desc = tg_cfg->num_msdu_desc; 3495d5c65159SKalle Valo wmi_cfg->max_frag_entries = tg_cfg->max_frag_entries; 3496d5c65159SKalle Valo wmi_cfg->num_tdls_vdevs = tg_cfg->num_tdls_vdevs; 3497d5c65159SKalle Valo wmi_cfg->num_tdls_conn_table_entries = 3498d5c65159SKalle Valo tg_cfg->num_tdls_conn_table_entries; 3499d5c65159SKalle Valo wmi_cfg->beacon_tx_offload_max_vdev = 3500d5c65159SKalle Valo tg_cfg->beacon_tx_offload_max_vdev; 3501d5c65159SKalle Valo wmi_cfg->num_multicast_filter_entries = 3502d5c65159SKalle Valo tg_cfg->num_multicast_filter_entries; 3503d5c65159SKalle Valo wmi_cfg->num_wow_filters = tg_cfg->num_wow_filters; 3504d5c65159SKalle Valo wmi_cfg->num_keep_alive_pattern = tg_cfg->num_keep_alive_pattern; 3505d5c65159SKalle Valo wmi_cfg->keep_alive_pattern_size = tg_cfg->keep_alive_pattern_size; 3506d5c65159SKalle Valo wmi_cfg->max_tdls_concurrent_sleep_sta = 3507d5c65159SKalle Valo tg_cfg->max_tdls_concurrent_sleep_sta; 3508d5c65159SKalle Valo wmi_cfg->max_tdls_concurrent_buffer_sta = 3509d5c65159SKalle Valo tg_cfg->max_tdls_concurrent_buffer_sta; 3510d5c65159SKalle Valo wmi_cfg->wmi_send_separate = tg_cfg->wmi_send_separate; 3511d5c65159SKalle Valo wmi_cfg->num_ocb_vdevs = tg_cfg->num_ocb_vdevs; 3512d5c65159SKalle Valo wmi_cfg->num_ocb_channels = tg_cfg->num_ocb_channels; 3513d5c65159SKalle Valo wmi_cfg->num_ocb_schedules = tg_cfg->num_ocb_schedules; 3514d5c65159SKalle Valo wmi_cfg->bpf_instruction_size = tg_cfg->bpf_instruction_size; 3515d5c65159SKalle Valo wmi_cfg->max_bssid_rx_filters = tg_cfg->max_bssid_rx_filters; 3516d5c65159SKalle Valo wmi_cfg->use_pdev_id = tg_cfg->use_pdev_id; 35177e9fb241SSeevalamuthu Mariappan wmi_cfg->flag1 = tg_cfg->flag1; 3518d5c65159SKalle Valo wmi_cfg->peer_map_unmap_v2_support = tg_cfg->peer_map_unmap_v2_support; 35196d293d44SJohn Crispin wmi_cfg->sched_params = tg_cfg->sched_params; 35206d293d44SJohn Crispin wmi_cfg->twt_ap_pdev_count = tg_cfg->twt_ap_pdev_count; 35216d293d44SJohn Crispin wmi_cfg->twt_ap_sta_count = tg_cfg->twt_ap_sta_count; 3522d5c65159SKalle Valo } 3523d5c65159SKalle Valo 3524d5c65159SKalle Valo static int ath11k_init_cmd_send(struct ath11k_pdev_wmi *wmi, 3525d5c65159SKalle Valo struct wmi_init_cmd_param *param) 3526d5c65159SKalle Valo { 35276bc9d6f7SJohn Crispin struct ath11k_base *ab = wmi->wmi_ab->ab; 3528d5c65159SKalle Valo struct sk_buff *skb; 3529d5c65159SKalle Valo struct wmi_init_cmd *cmd; 3530d5c65159SKalle Valo struct wmi_resource_config *cfg; 3531d5c65159SKalle Valo struct wmi_pdev_set_hw_mode_cmd_param *hw_mode; 3532d5c65159SKalle Valo struct wmi_pdev_band_to_mac *band_to_mac; 3533d5c65159SKalle Valo struct wlan_host_mem_chunk *host_mem_chunks; 3534d5c65159SKalle Valo struct wmi_tlv *tlv; 3535d5c65159SKalle Valo size_t ret, len; 3536d5c65159SKalle Valo void *ptr; 3537d5c65159SKalle Valo u32 hw_mode_len = 0; 3538d5c65159SKalle Valo u16 idx; 3539d5c65159SKalle Valo 3540d5c65159SKalle Valo if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) 3541d5c65159SKalle Valo hw_mode_len = sizeof(*hw_mode) + TLV_HDR_SIZE + 3542d5c65159SKalle Valo (param->num_band_to_mac * sizeof(*band_to_mac)); 3543d5c65159SKalle Valo 3544d5c65159SKalle Valo len = sizeof(*cmd) + TLV_HDR_SIZE + sizeof(*cfg) + hw_mode_len + 35452d4bcbedSCarl Huang (param->num_mem_chunks ? (sizeof(*host_mem_chunks) * WMI_MAX_MEM_REQS) : 0); 3546d5c65159SKalle Valo 35476bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, len); 3548d5c65159SKalle Valo if (!skb) 3549d5c65159SKalle Valo return -ENOMEM; 3550d5c65159SKalle Valo 3551d5c65159SKalle Valo cmd = (struct wmi_init_cmd *)skb->data; 3552d5c65159SKalle Valo 3553d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_INIT_CMD) | 3554d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3555d5c65159SKalle Valo 3556d5c65159SKalle Valo ptr = skb->data + sizeof(*cmd); 3557d5c65159SKalle Valo cfg = ptr; 3558d5c65159SKalle Valo 3559d5c65159SKalle Valo ath11k_wmi_copy_resource_config(cfg, param->res_cfg); 3560d5c65159SKalle Valo 3561d5c65159SKalle Valo cfg->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_RESOURCE_CONFIG) | 3562d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(*cfg) - TLV_HDR_SIZE); 3563d5c65159SKalle Valo 3564d5c65159SKalle Valo ptr += sizeof(*cfg); 3565d5c65159SKalle Valo host_mem_chunks = ptr + TLV_HDR_SIZE; 3566d5c65159SKalle Valo len = sizeof(struct wlan_host_mem_chunk); 3567d5c65159SKalle Valo 3568d5c65159SKalle Valo for (idx = 0; idx < param->num_mem_chunks; ++idx) { 3569d5c65159SKalle Valo host_mem_chunks[idx].tlv_header = 3570d5c65159SKalle Valo FIELD_PREP(WMI_TLV_TAG, 3571d5c65159SKalle Valo WMI_TAG_WLAN_HOST_MEMORY_CHUNK) | 3572d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 3573d5c65159SKalle Valo 3574d5c65159SKalle Valo host_mem_chunks[idx].ptr = param->mem_chunks[idx].paddr; 3575d5c65159SKalle Valo host_mem_chunks[idx].size = param->mem_chunks[idx].len; 3576d5c65159SKalle Valo host_mem_chunks[idx].req_id = param->mem_chunks[idx].req_id; 3577d5c65159SKalle Valo 3578d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 3579d5c65159SKalle Valo "WMI host mem chunk req_id %d paddr 0x%llx len %d\n", 3580d5c65159SKalle Valo param->mem_chunks[idx].req_id, 3581d5c65159SKalle Valo (u64)param->mem_chunks[idx].paddr, 3582d5c65159SKalle Valo param->mem_chunks[idx].len); 3583d5c65159SKalle Valo } 3584d5c65159SKalle Valo cmd->num_host_mem_chunks = param->num_mem_chunks; 3585d5c65159SKalle Valo len = sizeof(struct wlan_host_mem_chunk) * param->num_mem_chunks; 3586d5c65159SKalle Valo 3587d5c65159SKalle Valo /* num_mem_chunks is zero */ 3588d5c65159SKalle Valo tlv = ptr; 3589d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 3590d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 3591d5c65159SKalle Valo ptr += TLV_HDR_SIZE + len; 3592d5c65159SKalle Valo 3593d5c65159SKalle Valo if (param->hw_mode_id != WMI_HOST_HW_MODE_MAX) { 3594d5c65159SKalle Valo hw_mode = (struct wmi_pdev_set_hw_mode_cmd_param *)ptr; 3595d5c65159SKalle Valo hw_mode->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3596d5c65159SKalle Valo WMI_TAG_PDEV_SET_HW_MODE_CMD) | 3597d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 3598d5c65159SKalle Valo sizeof(*hw_mode) - TLV_HDR_SIZE); 3599d5c65159SKalle Valo 3600d5c65159SKalle Valo hw_mode->hw_mode_index = param->hw_mode_id; 3601d5c65159SKalle Valo hw_mode->num_band_to_mac = param->num_band_to_mac; 3602d5c65159SKalle Valo 3603d5c65159SKalle Valo ptr += sizeof(*hw_mode); 3604d5c65159SKalle Valo 3605d5c65159SKalle Valo len = param->num_band_to_mac * sizeof(*band_to_mac); 3606d5c65159SKalle Valo tlv = ptr; 3607d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_STRUCT) | 3608d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, len); 3609d5c65159SKalle Valo 3610d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 3611d5c65159SKalle Valo len = sizeof(*band_to_mac); 3612d5c65159SKalle Valo 3613d5c65159SKalle Valo for (idx = 0; idx < param->num_band_to_mac; idx++) { 3614d5c65159SKalle Valo band_to_mac = (void *)ptr; 3615d5c65159SKalle Valo 3616d5c65159SKalle Valo band_to_mac->tlv_header = FIELD_PREP(WMI_TLV_TAG, 3617d5c65159SKalle Valo WMI_TAG_PDEV_BAND_TO_MAC) | 3618d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, 3619d5c65159SKalle Valo len - TLV_HDR_SIZE); 3620d5c65159SKalle Valo band_to_mac->pdev_id = param->band_to_mac[idx].pdev_id; 3621d5c65159SKalle Valo band_to_mac->start_freq = 3622d5c65159SKalle Valo param->band_to_mac[idx].start_freq; 3623d5c65159SKalle Valo band_to_mac->end_freq = 3624d5c65159SKalle Valo param->band_to_mac[idx].end_freq; 3625d5c65159SKalle Valo ptr += sizeof(*band_to_mac); 3626d5c65159SKalle Valo } 3627d5c65159SKalle Valo } 3628d5c65159SKalle Valo 3629d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_INIT_CMDID); 3630d5c65159SKalle Valo if (ret) { 3631d5c65159SKalle Valo ath11k_warn(ab, "failed to send WMI_INIT_CMDID\n"); 3632d5c65159SKalle Valo dev_kfree_skb(skb); 3633d5c65159SKalle Valo } 3634d5c65159SKalle Valo 3635d5c65159SKalle Valo return ret; 3636d5c65159SKalle Valo } 3637d5c65159SKalle Valo 363826c79927SSriram R int ath11k_wmi_pdev_lro_cfg(struct ath11k *ar, 363926c79927SSriram R int pdev_id) 364026c79927SSriram R { 364126c79927SSriram R struct ath11k_wmi_pdev_lro_config_cmd *cmd; 364226c79927SSriram R struct sk_buff *skb; 364326c79927SSriram R int ret; 364426c79927SSriram R 364526c79927SSriram R skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 364626c79927SSriram R if (!skb) 364726c79927SSriram R return -ENOMEM; 364826c79927SSriram R 364926c79927SSriram R cmd = (struct ath11k_wmi_pdev_lro_config_cmd *)skb->data; 365026c79927SSriram R cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_LRO_INFO_CMD) | 365126c79927SSriram R FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 365226c79927SSriram R 365326c79927SSriram R get_random_bytes(cmd->th_4, sizeof(uint32_t) * ATH11K_IPV4_TH_SEED_SIZE); 365426c79927SSriram R get_random_bytes(cmd->th_6, sizeof(uint32_t) * ATH11K_IPV6_TH_SEED_SIZE); 365526c79927SSriram R 365626c79927SSriram R cmd->pdev_id = pdev_id; 365726c79927SSriram R 365826c79927SSriram R ret = ath11k_wmi_cmd_send(ar->wmi, skb, WMI_LRO_CONFIG_CMDID); 365926c79927SSriram R if (ret) { 366026c79927SSriram R ath11k_warn(ar->ab, 366126c79927SSriram R "failed to send lro cfg req wmi cmd\n"); 366226c79927SSriram R goto err; 366326c79927SSriram R } 366426c79927SSriram R 366526c79927SSriram R ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 366626c79927SSriram R "WMI lro cfg cmd pdev_id 0x%x\n", pdev_id); 366726c79927SSriram R return 0; 366826c79927SSriram R err: 366926c79927SSriram R dev_kfree_skb(skb); 367026c79927SSriram R return ret; 367126c79927SSriram R } 367226c79927SSriram R 3673d5c65159SKalle Valo int ath11k_wmi_wait_for_service_ready(struct ath11k_base *ab) 3674d5c65159SKalle Valo { 3675d5c65159SKalle Valo unsigned long time_left; 3676d5c65159SKalle Valo 36776bc9d6f7SJohn Crispin time_left = wait_for_completion_timeout(&ab->wmi_ab.service_ready, 3678d5c65159SKalle Valo WMI_SERVICE_READY_TIMEOUT_HZ); 3679d5c65159SKalle Valo if (!time_left) 3680d5c65159SKalle Valo return -ETIMEDOUT; 3681d5c65159SKalle Valo 3682d5c65159SKalle Valo return 0; 3683d5c65159SKalle Valo } 3684d5c65159SKalle Valo 3685d5c65159SKalle Valo int ath11k_wmi_wait_for_unified_ready(struct ath11k_base *ab) 3686d5c65159SKalle Valo { 3687d5c65159SKalle Valo unsigned long time_left; 3688d5c65159SKalle Valo 36896bc9d6f7SJohn Crispin time_left = wait_for_completion_timeout(&ab->wmi_ab.unified_ready, 3690d5c65159SKalle Valo WMI_SERVICE_READY_TIMEOUT_HZ); 3691d5c65159SKalle Valo if (!time_left) 3692d5c65159SKalle Valo return -ETIMEDOUT; 3693d5c65159SKalle Valo 3694d5c65159SKalle Valo return 0; 3695d5c65159SKalle Valo } 3696d5c65159SKalle Valo 369743ed15e1SCarl Huang int ath11k_wmi_set_hw_mode(struct ath11k_base *ab, 369843ed15e1SCarl Huang enum wmi_host_hw_mode_config_type mode) 369943ed15e1SCarl Huang { 370043ed15e1SCarl Huang struct wmi_pdev_set_hw_mode_cmd_param *cmd; 370143ed15e1SCarl Huang struct sk_buff *skb; 370243ed15e1SCarl Huang struct ath11k_wmi_base *wmi_ab = &ab->wmi_ab; 370343ed15e1SCarl Huang int len; 370443ed15e1SCarl Huang int ret; 370543ed15e1SCarl Huang 370643ed15e1SCarl Huang len = sizeof(*cmd); 370743ed15e1SCarl Huang 370843ed15e1SCarl Huang skb = ath11k_wmi_alloc_skb(wmi_ab, len); 3709292bff94SColin Ian King if (!skb) 3710292bff94SColin Ian King return -ENOMEM; 3711292bff94SColin Ian King 371243ed15e1SCarl Huang cmd = (struct wmi_pdev_set_hw_mode_cmd_param *)skb->data; 371343ed15e1SCarl Huang 371443ed15e1SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_PDEV_SET_HW_MODE_CMD) | 371543ed15e1SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 371643ed15e1SCarl Huang 371743ed15e1SCarl Huang cmd->pdev_id = WMI_PDEV_ID_SOC; 371843ed15e1SCarl Huang cmd->hw_mode_index = mode; 371943ed15e1SCarl Huang 372043ed15e1SCarl Huang ret = ath11k_wmi_cmd_send(&wmi_ab->wmi[0], skb, WMI_PDEV_SET_HW_MODE_CMDID); 372143ed15e1SCarl Huang if (ret) { 372243ed15e1SCarl Huang ath11k_warn(ab, "failed to send WMI_PDEV_SET_HW_MODE_CMDID\n"); 372343ed15e1SCarl Huang dev_kfree_skb(skb); 372443ed15e1SCarl Huang } 372543ed15e1SCarl Huang 372643ed15e1SCarl Huang return ret; 372743ed15e1SCarl Huang } 372843ed15e1SCarl Huang 3729d5c65159SKalle Valo int ath11k_wmi_cmd_init(struct ath11k_base *ab) 3730d5c65159SKalle Valo { 37316bc9d6f7SJohn Crispin struct ath11k_wmi_base *wmi_sc = &ab->wmi_ab; 3732d5c65159SKalle Valo struct wmi_init_cmd_param init_param; 3733d5c65159SKalle Valo struct target_resource_config config; 3734d5c65159SKalle Valo 3735d5c65159SKalle Valo memset(&init_param, 0, sizeof(init_param)); 3736d5c65159SKalle Valo memset(&config, 0, sizeof(config)); 3737d5c65159SKalle Valo 37382d4bcbedSCarl Huang ab->hw_params.hw_ops->wmi_init_config(ab, &config); 37392d4bcbedSCarl Huang 3740d5c65159SKalle Valo memcpy(&wmi_sc->wlan_resource_config, &config, sizeof(config)); 3741d5c65159SKalle Valo 3742d5c65159SKalle Valo init_param.res_cfg = &wmi_sc->wlan_resource_config; 3743d5c65159SKalle Valo init_param.num_mem_chunks = wmi_sc->num_mem_chunks; 3744d5c65159SKalle Valo init_param.hw_mode_id = wmi_sc->preferred_hw_mode; 3745d5c65159SKalle Valo init_param.mem_chunks = wmi_sc->mem_chunks; 3746d5c65159SKalle Valo 374743ed15e1SCarl Huang if (ab->hw_params.single_pdev_only) 374843ed15e1SCarl Huang init_param.hw_mode_id = WMI_HOST_HW_MODE_MAX; 374943ed15e1SCarl Huang 3750d5c65159SKalle Valo init_param.num_band_to_mac = ab->num_radios; 3751d5c65159SKalle Valo ath11k_fill_band_to_mac_param(ab, init_param.band_to_mac); 3752d5c65159SKalle Valo 3753d5c65159SKalle Valo return ath11k_init_cmd_send(&wmi_sc->wmi[0], &init_param); 3754d5c65159SKalle Valo } 3755d5c65159SKalle Valo 37569d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_conf(struct ath11k *ar, 37579d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_vdev_spectral_conf_param *param) 37589d11b7bfSKarthikeyan Periyasamy { 37599d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_vdev_spectral_conf_cmd *cmd; 37609d11b7bfSKarthikeyan Periyasamy struct sk_buff *skb; 37619d11b7bfSKarthikeyan Periyasamy int ret; 37629d11b7bfSKarthikeyan Periyasamy 37639d11b7bfSKarthikeyan Periyasamy skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 37649d11b7bfSKarthikeyan Periyasamy if (!skb) 37659d11b7bfSKarthikeyan Periyasamy return -ENOMEM; 37669d11b7bfSKarthikeyan Periyasamy 37679d11b7bfSKarthikeyan Periyasamy cmd = (struct ath11k_wmi_vdev_spectral_conf_cmd *)skb->data; 37689d11b7bfSKarthikeyan Periyasamy cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 37699d11b7bfSKarthikeyan Periyasamy WMI_TAG_VDEV_SPECTRAL_CONFIGURE_CMD) | 37709d11b7bfSKarthikeyan Periyasamy FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 37719d11b7bfSKarthikeyan Periyasamy 37729d11b7bfSKarthikeyan Periyasamy memcpy(&cmd->param, param, sizeof(*param)); 37739d11b7bfSKarthikeyan Periyasamy 37749d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_cmd_send(ar->wmi, skb, 37759d11b7bfSKarthikeyan Periyasamy WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID); 37769d11b7bfSKarthikeyan Periyasamy if (ret) { 37779d11b7bfSKarthikeyan Periyasamy ath11k_warn(ar->ab, 37789d11b7bfSKarthikeyan Periyasamy "failed to send spectral scan config wmi cmd\n"); 37799d11b7bfSKarthikeyan Periyasamy goto err; 37809d11b7bfSKarthikeyan Periyasamy } 37819d11b7bfSKarthikeyan Periyasamy 37829d11b7bfSKarthikeyan Periyasamy ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 37839d11b7bfSKarthikeyan Periyasamy "WMI spectral scan config cmd vdev_id 0x%x\n", 37849d11b7bfSKarthikeyan Periyasamy param->vdev_id); 37859d11b7bfSKarthikeyan Periyasamy 37869d11b7bfSKarthikeyan Periyasamy return 0; 37879d11b7bfSKarthikeyan Periyasamy err: 37889d11b7bfSKarthikeyan Periyasamy dev_kfree_skb(skb); 37899d11b7bfSKarthikeyan Periyasamy return ret; 37909d11b7bfSKarthikeyan Periyasamy } 37919d11b7bfSKarthikeyan Periyasamy 37929d11b7bfSKarthikeyan Periyasamy int ath11k_wmi_vdev_spectral_enable(struct ath11k *ar, u32 vdev_id, 37939d11b7bfSKarthikeyan Periyasamy u32 trigger, u32 enable) 37949d11b7bfSKarthikeyan Periyasamy { 37959d11b7bfSKarthikeyan Periyasamy struct ath11k_wmi_vdev_spectral_enable_cmd *cmd; 37969d11b7bfSKarthikeyan Periyasamy struct sk_buff *skb; 37979d11b7bfSKarthikeyan Periyasamy int ret; 37989d11b7bfSKarthikeyan Periyasamy 37999d11b7bfSKarthikeyan Periyasamy skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 38009d11b7bfSKarthikeyan Periyasamy if (!skb) 38019d11b7bfSKarthikeyan Periyasamy return -ENOMEM; 38029d11b7bfSKarthikeyan Periyasamy 38039d11b7bfSKarthikeyan Periyasamy cmd = (struct ath11k_wmi_vdev_spectral_enable_cmd *)skb->data; 38049d11b7bfSKarthikeyan Periyasamy cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 38059d11b7bfSKarthikeyan Periyasamy WMI_TAG_VDEV_SPECTRAL_ENABLE_CMD) | 38069d11b7bfSKarthikeyan Periyasamy FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 38079d11b7bfSKarthikeyan Periyasamy 38089d11b7bfSKarthikeyan Periyasamy cmd->vdev_id = vdev_id; 38099d11b7bfSKarthikeyan Periyasamy cmd->trigger_cmd = trigger; 38109d11b7bfSKarthikeyan Periyasamy cmd->enable_cmd = enable; 38119d11b7bfSKarthikeyan Periyasamy 38129d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_cmd_send(ar->wmi, skb, 38139d11b7bfSKarthikeyan Periyasamy WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID); 38149d11b7bfSKarthikeyan Periyasamy if (ret) { 38159d11b7bfSKarthikeyan Periyasamy ath11k_warn(ar->ab, 38169d11b7bfSKarthikeyan Periyasamy "failed to send spectral enable wmi cmd\n"); 38179d11b7bfSKarthikeyan Periyasamy goto err; 38189d11b7bfSKarthikeyan Periyasamy } 38199d11b7bfSKarthikeyan Periyasamy 38209d11b7bfSKarthikeyan Periyasamy ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 38219d11b7bfSKarthikeyan Periyasamy "WMI spectral enable cmd vdev id 0x%x\n", 38229d11b7bfSKarthikeyan Periyasamy vdev_id); 38239d11b7bfSKarthikeyan Periyasamy 38249d11b7bfSKarthikeyan Periyasamy return 0; 38259d11b7bfSKarthikeyan Periyasamy err: 38269d11b7bfSKarthikeyan Periyasamy dev_kfree_skb(skb); 38279d11b7bfSKarthikeyan Periyasamy return ret; 38289d11b7bfSKarthikeyan Periyasamy } 38299d11b7bfSKarthikeyan Periyasamy 3830bd647855SKarthikeyan Periyasamy int ath11k_wmi_pdev_dma_ring_cfg(struct ath11k *ar, 3831bd647855SKarthikeyan Periyasamy struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *param) 3832bd647855SKarthikeyan Periyasamy { 3833bd647855SKarthikeyan Periyasamy struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *cmd; 3834bd647855SKarthikeyan Periyasamy struct sk_buff *skb; 3835bd647855SKarthikeyan Periyasamy int ret; 3836bd647855SKarthikeyan Periyasamy 3837bd647855SKarthikeyan Periyasamy skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, sizeof(*cmd)); 3838bd647855SKarthikeyan Periyasamy if (!skb) 3839bd647855SKarthikeyan Periyasamy return -ENOMEM; 3840bd647855SKarthikeyan Periyasamy 3841bd647855SKarthikeyan Periyasamy cmd = (struct ath11k_wmi_pdev_dma_ring_cfg_req_cmd *)skb->data; 3842bd647855SKarthikeyan Periyasamy cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_DMA_RING_CFG_REQ) | 3843bd647855SKarthikeyan Periyasamy FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 3844bd647855SKarthikeyan Periyasamy 3845bd647855SKarthikeyan Periyasamy cmd->pdev_id = param->pdev_id; 3846bd647855SKarthikeyan Periyasamy cmd->module_id = param->module_id; 3847bd647855SKarthikeyan Periyasamy cmd->base_paddr_lo = param->base_paddr_lo; 3848bd647855SKarthikeyan Periyasamy cmd->base_paddr_hi = param->base_paddr_hi; 3849bd647855SKarthikeyan Periyasamy cmd->head_idx_paddr_lo = param->head_idx_paddr_lo; 3850bd647855SKarthikeyan Periyasamy cmd->head_idx_paddr_hi = param->head_idx_paddr_hi; 3851bd647855SKarthikeyan Periyasamy cmd->tail_idx_paddr_lo = param->tail_idx_paddr_lo; 3852bd647855SKarthikeyan Periyasamy cmd->tail_idx_paddr_hi = param->tail_idx_paddr_hi; 3853bd647855SKarthikeyan Periyasamy cmd->num_elems = param->num_elems; 3854bd647855SKarthikeyan Periyasamy cmd->buf_size = param->buf_size; 3855bd647855SKarthikeyan Periyasamy cmd->num_resp_per_event = param->num_resp_per_event; 3856bd647855SKarthikeyan Periyasamy cmd->event_timeout_ms = param->event_timeout_ms; 3857bd647855SKarthikeyan Periyasamy 3858bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_cmd_send(ar->wmi, skb, 3859bd647855SKarthikeyan Periyasamy WMI_PDEV_DMA_RING_CFG_REQ_CMDID); 3860bd647855SKarthikeyan Periyasamy if (ret) { 3861bd647855SKarthikeyan Periyasamy ath11k_warn(ar->ab, 3862bd647855SKarthikeyan Periyasamy "failed to send dma ring cfg req wmi cmd\n"); 3863bd647855SKarthikeyan Periyasamy goto err; 3864bd647855SKarthikeyan Periyasamy } 3865bd647855SKarthikeyan Periyasamy 3866bd647855SKarthikeyan Periyasamy ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 3867bd647855SKarthikeyan Periyasamy "WMI DMA ring cfg req cmd pdev_id 0x%x\n", 3868bd647855SKarthikeyan Periyasamy param->pdev_id); 3869bd647855SKarthikeyan Periyasamy 3870bd647855SKarthikeyan Periyasamy return 0; 3871bd647855SKarthikeyan Periyasamy err: 3872bd647855SKarthikeyan Periyasamy dev_kfree_skb(skb); 3873bd647855SKarthikeyan Periyasamy return ret; 3874bd647855SKarthikeyan Periyasamy } 3875bd647855SKarthikeyan Periyasamy 38769d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_entry_parse(struct ath11k_base *soc, 38779d11b7bfSKarthikeyan Periyasamy u16 tag, u16 len, 38789d11b7bfSKarthikeyan Periyasamy const void *ptr, void *data) 38799d11b7bfSKarthikeyan Periyasamy { 38809d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse *parse = data; 38819d11b7bfSKarthikeyan Periyasamy 38829d11b7bfSKarthikeyan Periyasamy if (tag != WMI_TAG_DMA_BUF_RELEASE_ENTRY) 38839d11b7bfSKarthikeyan Periyasamy return -EPROTO; 38849d11b7bfSKarthikeyan Periyasamy 38859d11b7bfSKarthikeyan Periyasamy if (parse->num_buf_entry >= parse->fixed.num_buf_release_entry) 38869d11b7bfSKarthikeyan Periyasamy return -ENOBUFS; 38879d11b7bfSKarthikeyan Periyasamy 38889d11b7bfSKarthikeyan Periyasamy parse->num_buf_entry++; 38899d11b7bfSKarthikeyan Periyasamy return 0; 38909d11b7bfSKarthikeyan Periyasamy } 38919d11b7bfSKarthikeyan Periyasamy 38929d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_meta_parse(struct ath11k_base *soc, 38939d11b7bfSKarthikeyan Periyasamy u16 tag, u16 len, 38949d11b7bfSKarthikeyan Periyasamy const void *ptr, void *data) 38959d11b7bfSKarthikeyan Periyasamy { 38969d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse *parse = data; 38979d11b7bfSKarthikeyan Periyasamy 38989d11b7bfSKarthikeyan Periyasamy if (tag != WMI_TAG_DMA_BUF_RELEASE_SPECTRAL_META_DATA) 38999d11b7bfSKarthikeyan Periyasamy return -EPROTO; 39009d11b7bfSKarthikeyan Periyasamy 39019d11b7bfSKarthikeyan Periyasamy if (parse->num_meta >= parse->fixed.num_meta_data_entry) 39029d11b7bfSKarthikeyan Periyasamy return -ENOBUFS; 39039d11b7bfSKarthikeyan Periyasamy 39049d11b7bfSKarthikeyan Periyasamy parse->num_meta++; 39059d11b7bfSKarthikeyan Periyasamy return 0; 39069d11b7bfSKarthikeyan Periyasamy } 39079d11b7bfSKarthikeyan Periyasamy 39089d11b7bfSKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_buf_parse(struct ath11k_base *ab, 39099d11b7bfSKarthikeyan Periyasamy u16 tag, u16 len, 39109d11b7bfSKarthikeyan Periyasamy const void *ptr, void *data) 39119d11b7bfSKarthikeyan Periyasamy { 39129d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse *parse = data; 39139d11b7bfSKarthikeyan Periyasamy int ret; 39149d11b7bfSKarthikeyan Periyasamy 39159d11b7bfSKarthikeyan Periyasamy switch (tag) { 39169d11b7bfSKarthikeyan Periyasamy case WMI_TAG_DMA_BUF_RELEASE: 39179d11b7bfSKarthikeyan Periyasamy memcpy(&parse->fixed, ptr, 39189d11b7bfSKarthikeyan Periyasamy sizeof(struct ath11k_wmi_dma_buf_release_fixed_param)); 39199d11b7bfSKarthikeyan Periyasamy parse->fixed.pdev_id = DP_HW2SW_MACID(parse->fixed.pdev_id); 39209d11b7bfSKarthikeyan Periyasamy break; 39219d11b7bfSKarthikeyan Periyasamy case WMI_TAG_ARRAY_STRUCT: 39229d11b7bfSKarthikeyan Periyasamy if (!parse->buf_entry_done) { 39239d11b7bfSKarthikeyan Periyasamy parse->num_buf_entry = 0; 39249d11b7bfSKarthikeyan Periyasamy parse->buf_entry = (struct wmi_dma_buf_release_entry *)ptr; 39259d11b7bfSKarthikeyan Periyasamy 39269d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, ptr, len, 39279d11b7bfSKarthikeyan Periyasamy ath11k_wmi_tlv_dma_buf_entry_parse, 39289d11b7bfSKarthikeyan Periyasamy parse); 39299d11b7bfSKarthikeyan Periyasamy if (ret) { 39309d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma buf entry tlv %d\n", 39319d11b7bfSKarthikeyan Periyasamy ret); 39329d11b7bfSKarthikeyan Periyasamy return ret; 39339d11b7bfSKarthikeyan Periyasamy } 39349d11b7bfSKarthikeyan Periyasamy 39359d11b7bfSKarthikeyan Periyasamy parse->buf_entry_done = true; 39369d11b7bfSKarthikeyan Periyasamy } else if (!parse->meta_data_done) { 39379d11b7bfSKarthikeyan Periyasamy parse->num_meta = 0; 39389d11b7bfSKarthikeyan Periyasamy parse->meta_data = (struct wmi_dma_buf_release_meta_data *)ptr; 39399d11b7bfSKarthikeyan Periyasamy 39409d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, ptr, len, 39419d11b7bfSKarthikeyan Periyasamy ath11k_wmi_tlv_dma_buf_meta_parse, 39429d11b7bfSKarthikeyan Periyasamy parse); 39439d11b7bfSKarthikeyan Periyasamy if (ret) { 39449d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma buf meta tlv %d\n", 39459d11b7bfSKarthikeyan Periyasamy ret); 39469d11b7bfSKarthikeyan Periyasamy return ret; 39479d11b7bfSKarthikeyan Periyasamy } 39489d11b7bfSKarthikeyan Periyasamy 39499d11b7bfSKarthikeyan Periyasamy parse->meta_data_done = true; 39509d11b7bfSKarthikeyan Periyasamy } 39519d11b7bfSKarthikeyan Periyasamy break; 39529d11b7bfSKarthikeyan Periyasamy default: 39539d11b7bfSKarthikeyan Periyasamy break; 39549d11b7bfSKarthikeyan Periyasamy } 39559d11b7bfSKarthikeyan Periyasamy return 0; 39569d11b7bfSKarthikeyan Periyasamy } 39579d11b7bfSKarthikeyan Periyasamy 39589d11b7bfSKarthikeyan Periyasamy static void ath11k_wmi_pdev_dma_ring_buf_release_event(struct ath11k_base *ab, 39599d11b7bfSKarthikeyan Periyasamy struct sk_buff *skb) 39609d11b7bfSKarthikeyan Periyasamy { 39619d11b7bfSKarthikeyan Periyasamy struct wmi_tlv_dma_buf_release_parse parse = { }; 39629d11b7bfSKarthikeyan Periyasamy struct ath11k_dbring_buf_release_event param; 39639d11b7bfSKarthikeyan Periyasamy int ret; 39649d11b7bfSKarthikeyan Periyasamy 39659d11b7bfSKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 39669d11b7bfSKarthikeyan Periyasamy ath11k_wmi_tlv_dma_buf_parse, 39679d11b7bfSKarthikeyan Periyasamy &parse); 39689d11b7bfSKarthikeyan Periyasamy if (ret) { 39699d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma buf release tlv %d\n", ret); 39709d11b7bfSKarthikeyan Periyasamy return; 39719d11b7bfSKarthikeyan Periyasamy } 39729d11b7bfSKarthikeyan Periyasamy 39739d11b7bfSKarthikeyan Periyasamy param.fixed = parse.fixed; 39749d11b7bfSKarthikeyan Periyasamy param.buf_entry = parse.buf_entry; 39759d11b7bfSKarthikeyan Periyasamy param.num_buf_entry = parse.num_buf_entry; 39769d11b7bfSKarthikeyan Periyasamy param.meta_data = parse.meta_data; 39779d11b7bfSKarthikeyan Periyasamy param.num_meta = parse.num_meta; 39789d11b7bfSKarthikeyan Periyasamy 39799d11b7bfSKarthikeyan Periyasamy ret = ath11k_dbring_buffer_release_event(ab, ¶m); 39809d11b7bfSKarthikeyan Periyasamy if (ret) { 39819d11b7bfSKarthikeyan Periyasamy ath11k_warn(ab, "failed to handle dma buf release event %d\n", ret); 39829d11b7bfSKarthikeyan Periyasamy return; 39839d11b7bfSKarthikeyan Periyasamy } 39849d11b7bfSKarthikeyan Periyasamy } 39859d11b7bfSKarthikeyan Periyasamy 3986d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps_parse(struct ath11k_base *soc, 3987d5c65159SKalle Valo u16 tag, u16 len, 3988d5c65159SKalle Valo const void *ptr, void *data) 3989d5c65159SKalle Valo { 3990d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 3991d5c65159SKalle Valo struct wmi_hw_mode_capabilities *hw_mode_cap; 3992d5c65159SKalle Valo u32 phy_map = 0; 3993d5c65159SKalle Valo 3994d5c65159SKalle Valo if (tag != WMI_TAG_HW_MODE_CAPABILITIES) 3995d5c65159SKalle Valo return -EPROTO; 3996d5c65159SKalle Valo 3997d5c65159SKalle Valo if (svc_rdy_ext->n_hw_mode_caps >= svc_rdy_ext->param.num_hw_modes) 3998d5c65159SKalle Valo return -ENOBUFS; 3999d5c65159SKalle Valo 4000d5c65159SKalle Valo hw_mode_cap = container_of(ptr, struct wmi_hw_mode_capabilities, 4001d5c65159SKalle Valo hw_mode_id); 4002d5c65159SKalle Valo svc_rdy_ext->n_hw_mode_caps++; 4003d5c65159SKalle Valo 4004d5c65159SKalle Valo phy_map = hw_mode_cap->phy_id_map; 4005d5c65159SKalle Valo while (phy_map) { 4006d5c65159SKalle Valo svc_rdy_ext->tot_phy_id++; 4007d5c65159SKalle Valo phy_map = phy_map >> 1; 4008d5c65159SKalle Valo } 4009d5c65159SKalle Valo 4010d5c65159SKalle Valo return 0; 4011d5c65159SKalle Valo } 4012d5c65159SKalle Valo 4013d5c65159SKalle Valo static int ath11k_wmi_tlv_hw_mode_caps(struct ath11k_base *soc, 4014d5c65159SKalle Valo u16 len, const void *ptr, void *data) 4015d5c65159SKalle Valo { 4016d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 4017d5c65159SKalle Valo struct wmi_hw_mode_capabilities *hw_mode_caps; 4018d5c65159SKalle Valo enum wmi_host_hw_mode_config_type mode, pref; 4019d5c65159SKalle Valo u32 i; 4020d5c65159SKalle Valo int ret; 4021d5c65159SKalle Valo 4022d5c65159SKalle Valo svc_rdy_ext->n_hw_mode_caps = 0; 4023d5c65159SKalle Valo svc_rdy_ext->hw_mode_caps = (struct wmi_hw_mode_capabilities *)ptr; 4024d5c65159SKalle Valo 4025d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(soc, ptr, len, 4026d5c65159SKalle Valo ath11k_wmi_tlv_hw_mode_caps_parse, 4027d5c65159SKalle Valo svc_rdy_ext); 4028d5c65159SKalle Valo if (ret) { 4029d5c65159SKalle Valo ath11k_warn(soc, "failed to parse tlv %d\n", ret); 4030d5c65159SKalle Valo return ret; 4031d5c65159SKalle Valo } 4032d5c65159SKalle Valo 4033d5c65159SKalle Valo i = 0; 4034d5c65159SKalle Valo while (i < svc_rdy_ext->n_hw_mode_caps) { 4035d5c65159SKalle Valo hw_mode_caps = &svc_rdy_ext->hw_mode_caps[i]; 4036d5c65159SKalle Valo mode = hw_mode_caps->hw_mode_id; 40376bc9d6f7SJohn Crispin pref = soc->wmi_ab.preferred_hw_mode; 4038d5c65159SKalle Valo 4039d5c65159SKalle Valo if (ath11k_hw_mode_pri_map[mode] < ath11k_hw_mode_pri_map[pref]) { 4040d5c65159SKalle Valo svc_rdy_ext->pref_hw_mode_caps = *hw_mode_caps; 40416bc9d6f7SJohn Crispin soc->wmi_ab.preferred_hw_mode = mode; 4042d5c65159SKalle Valo } 4043d5c65159SKalle Valo i++; 4044d5c65159SKalle Valo } 4045d5c65159SKalle Valo 40465f859bc0SCarl Huang ath11k_dbg(soc, ATH11K_DBG_WMI, "preferred_hw_mode:%d\n", 40475f859bc0SCarl Huang soc->wmi_ab.preferred_hw_mode); 40486bc9d6f7SJohn Crispin if (soc->wmi_ab.preferred_hw_mode == WMI_HOST_HW_MODE_MAX) 4049d5c65159SKalle Valo return -EINVAL; 4050d5c65159SKalle Valo 4051d5c65159SKalle Valo return 0; 4052d5c65159SKalle Valo } 4053d5c65159SKalle Valo 4054d5c65159SKalle Valo static int ath11k_wmi_tlv_mac_phy_caps_parse(struct ath11k_base *soc, 4055d5c65159SKalle Valo u16 tag, u16 len, 4056d5c65159SKalle Valo const void *ptr, void *data) 4057d5c65159SKalle Valo { 4058d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 4059d5c65159SKalle Valo 4060d5c65159SKalle Valo if (tag != WMI_TAG_MAC_PHY_CAPABILITIES) 4061d5c65159SKalle Valo return -EPROTO; 4062d5c65159SKalle Valo 4063d5c65159SKalle Valo if (svc_rdy_ext->n_mac_phy_caps >= svc_rdy_ext->tot_phy_id) 4064d5c65159SKalle Valo return -ENOBUFS; 4065d5c65159SKalle Valo 40665b90fc76SAnilkumar Kolli len = min_t(u16, len, sizeof(struct wmi_mac_phy_capabilities)); 40675b90fc76SAnilkumar Kolli if (!svc_rdy_ext->n_mac_phy_caps) { 40685b90fc76SAnilkumar Kolli svc_rdy_ext->mac_phy_caps = kzalloc((svc_rdy_ext->tot_phy_id) * len, 40695b90fc76SAnilkumar Kolli GFP_ATOMIC); 40705b90fc76SAnilkumar Kolli if (!svc_rdy_ext->mac_phy_caps) 40715b90fc76SAnilkumar Kolli return -ENOMEM; 40725b90fc76SAnilkumar Kolli } 40735b90fc76SAnilkumar Kolli 40745b90fc76SAnilkumar Kolli memcpy(svc_rdy_ext->mac_phy_caps + svc_rdy_ext->n_mac_phy_caps, ptr, len); 4075d5c65159SKalle Valo svc_rdy_ext->n_mac_phy_caps++; 4076d5c65159SKalle Valo return 0; 4077d5c65159SKalle Valo } 4078d5c65159SKalle Valo 4079d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps_parse(struct ath11k_base *soc, 4080d5c65159SKalle Valo u16 tag, u16 len, 4081d5c65159SKalle Valo const void *ptr, void *data) 4082d5c65159SKalle Valo { 4083d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 4084d5c65159SKalle Valo 4085d5c65159SKalle Valo if (tag != WMI_TAG_HAL_REG_CAPABILITIES_EXT) 4086d5c65159SKalle Valo return -EPROTO; 4087d5c65159SKalle Valo 4088d5c65159SKalle Valo if (svc_rdy_ext->n_ext_hal_reg_caps >= svc_rdy_ext->param.num_phy) 4089d5c65159SKalle Valo return -ENOBUFS; 4090d5c65159SKalle Valo 4091d5c65159SKalle Valo svc_rdy_ext->n_ext_hal_reg_caps++; 4092d5c65159SKalle Valo return 0; 4093d5c65159SKalle Valo } 4094d5c65159SKalle Valo 4095d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_hal_reg_caps(struct ath11k_base *soc, 4096d5c65159SKalle Valo u16 len, const void *ptr, void *data) 4097d5c65159SKalle Valo { 40986bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0]; 4099d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 4100d5c65159SKalle Valo struct ath11k_hal_reg_capabilities_ext reg_cap; 4101d5c65159SKalle Valo int ret; 4102d5c65159SKalle Valo u32 i; 4103d5c65159SKalle Valo 4104d5c65159SKalle Valo svc_rdy_ext->n_ext_hal_reg_caps = 0; 4105d5c65159SKalle Valo svc_rdy_ext->ext_hal_reg_caps = (struct wmi_hal_reg_capabilities_ext *)ptr; 4106d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(soc, ptr, len, 4107d5c65159SKalle Valo ath11k_wmi_tlv_ext_hal_reg_caps_parse, 4108d5c65159SKalle Valo svc_rdy_ext); 4109d5c65159SKalle Valo if (ret) { 4110d5c65159SKalle Valo ath11k_warn(soc, "failed to parse tlv %d\n", ret); 4111d5c65159SKalle Valo return ret; 4112d5c65159SKalle Valo } 4113d5c65159SKalle Valo 4114d5c65159SKalle Valo for (i = 0; i < svc_rdy_ext->param.num_phy; i++) { 4115d5c65159SKalle Valo ret = ath11k_pull_reg_cap_svc_rdy_ext(wmi_handle, 4116d5c65159SKalle Valo svc_rdy_ext->soc_hal_reg_caps, 4117d5c65159SKalle Valo svc_rdy_ext->ext_hal_reg_caps, i, 4118d5c65159SKalle Valo ®_cap); 4119d5c65159SKalle Valo if (ret) { 4120d5c65159SKalle Valo ath11k_warn(soc, "failed to extract reg cap %d\n", i); 4121d5c65159SKalle Valo return ret; 4122d5c65159SKalle Valo } 4123d5c65159SKalle Valo 4124d5c65159SKalle Valo memcpy(&soc->hal_reg_cap[reg_cap.phy_id], 4125d5c65159SKalle Valo ®_cap, sizeof(reg_cap)); 4126d5c65159SKalle Valo } 4127d5c65159SKalle Valo return 0; 4128d5c65159SKalle Valo } 4129d5c65159SKalle Valo 4130d5c65159SKalle Valo static int ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(struct ath11k_base *soc, 4131d5c65159SKalle Valo u16 len, const void *ptr, 4132d5c65159SKalle Valo void *data) 4133d5c65159SKalle Valo { 41346bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &soc->wmi_ab.wmi[0]; 4135d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 4136d5c65159SKalle Valo u8 hw_mode_id = svc_rdy_ext->pref_hw_mode_caps.hw_mode_id; 4137d5c65159SKalle Valo u32 phy_id_map; 41385f859bc0SCarl Huang int pdev_index = 0; 4139d5c65159SKalle Valo int ret; 4140d5c65159SKalle Valo 4141d5c65159SKalle Valo svc_rdy_ext->soc_hal_reg_caps = (struct wmi_soc_hal_reg_capabilities *)ptr; 4142d5c65159SKalle Valo svc_rdy_ext->param.num_phy = svc_rdy_ext->soc_hal_reg_caps->num_phy; 4143d5c65159SKalle Valo 4144d5c65159SKalle Valo soc->num_radios = 0; 4145d5c65159SKalle Valo phy_id_map = svc_rdy_ext->pref_hw_mode_caps.phy_id_map; 4146d5c65159SKalle Valo 4147d5c65159SKalle Valo while (phy_id_map && soc->num_radios < MAX_RADIOS) { 4148d5c65159SKalle Valo ret = ath11k_pull_mac_phy_cap_svc_ready_ext(wmi_handle, 4149d5c65159SKalle Valo svc_rdy_ext->hw_caps, 4150d5c65159SKalle Valo svc_rdy_ext->hw_mode_caps, 4151d5c65159SKalle Valo svc_rdy_ext->soc_hal_reg_caps, 4152d5c65159SKalle Valo svc_rdy_ext->mac_phy_caps, 4153d5c65159SKalle Valo hw_mode_id, soc->num_radios, 41545f859bc0SCarl Huang &soc->pdevs[pdev_index]); 4155d5c65159SKalle Valo if (ret) { 4156d5c65159SKalle Valo ath11k_warn(soc, "failed to extract mac caps, idx :%d\n", 4157d5c65159SKalle Valo soc->num_radios); 4158d5c65159SKalle Valo return ret; 4159d5c65159SKalle Valo } 4160d5c65159SKalle Valo 4161d5c65159SKalle Valo soc->num_radios++; 4162d5c65159SKalle Valo 41635f859bc0SCarl Huang /* For QCA6390, save mac_phy capability in the same pdev */ 41645f859bc0SCarl Huang if (soc->hw_params.single_pdev_only) 41655f859bc0SCarl Huang pdev_index = 0; 41665f859bc0SCarl Huang else 41675f859bc0SCarl Huang pdev_index = soc->num_radios; 41685f859bc0SCarl Huang 4169d5c65159SKalle Valo /* TODO: mac_phy_cap prints */ 4170d5c65159SKalle Valo phy_id_map >>= 1; 4171d5c65159SKalle Valo } 41725f859bc0SCarl Huang 41735f859bc0SCarl Huang /* For QCA6390, set num_radios to 1 because host manages 41745f859bc0SCarl Huang * both 2G and 5G radio in one pdev. 41755f859bc0SCarl Huang * Set pdev_id = 0 and 0 means soc level. 41765f859bc0SCarl Huang */ 41775f859bc0SCarl Huang if (soc->hw_params.single_pdev_only) { 41785f859bc0SCarl Huang soc->num_radios = 1; 41795f859bc0SCarl Huang soc->pdevs[0].pdev_id = 0; 41805f859bc0SCarl Huang } 41815f859bc0SCarl Huang 4182d5c65159SKalle Valo return 0; 4183d5c65159SKalle Valo } 4184d5c65159SKalle Valo 4185bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps_parse(struct ath11k_base *soc, 4186bd647855SKarthikeyan Periyasamy u16 tag, u16 len, 4187bd647855SKarthikeyan Periyasamy const void *ptr, void *data) 4188bd647855SKarthikeyan Periyasamy { 4189bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse *parse = data; 4190bd647855SKarthikeyan Periyasamy 4191bd647855SKarthikeyan Periyasamy if (tag != WMI_TAG_DMA_RING_CAPABILITIES) 4192bd647855SKarthikeyan Periyasamy return -EPROTO; 4193bd647855SKarthikeyan Periyasamy 4194bd647855SKarthikeyan Periyasamy parse->n_dma_ring_caps++; 4195bd647855SKarthikeyan Periyasamy return 0; 4196bd647855SKarthikeyan Periyasamy } 4197bd647855SKarthikeyan Periyasamy 4198bd647855SKarthikeyan Periyasamy static int ath11k_wmi_alloc_dbring_caps(struct ath11k_base *ab, 4199bd647855SKarthikeyan Periyasamy u32 num_cap) 4200bd647855SKarthikeyan Periyasamy { 4201bd647855SKarthikeyan Periyasamy size_t sz; 4202bd647855SKarthikeyan Periyasamy void *ptr; 4203bd647855SKarthikeyan Periyasamy 4204bd647855SKarthikeyan Periyasamy sz = num_cap * sizeof(struct ath11k_dbring_cap); 4205bd647855SKarthikeyan Periyasamy ptr = kzalloc(sz, GFP_ATOMIC); 4206bd647855SKarthikeyan Periyasamy if (!ptr) 4207bd647855SKarthikeyan Periyasamy return -ENOMEM; 4208bd647855SKarthikeyan Periyasamy 4209bd647855SKarthikeyan Periyasamy ab->db_caps = ptr; 4210bd647855SKarthikeyan Periyasamy ab->num_db_cap = num_cap; 4211bd647855SKarthikeyan Periyasamy 4212bd647855SKarthikeyan Periyasamy return 0; 4213bd647855SKarthikeyan Periyasamy } 4214bd647855SKarthikeyan Periyasamy 4215bd647855SKarthikeyan Periyasamy static void ath11k_wmi_free_dbring_caps(struct ath11k_base *ab) 4216bd647855SKarthikeyan Periyasamy { 4217bd647855SKarthikeyan Periyasamy kfree(ab->db_caps); 4218bd647855SKarthikeyan Periyasamy ab->db_caps = NULL; 4219bd647855SKarthikeyan Periyasamy } 4220bd647855SKarthikeyan Periyasamy 4221bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_dma_ring_caps(struct ath11k_base *ab, 4222bd647855SKarthikeyan Periyasamy u16 len, const void *ptr, void *data) 4223bd647855SKarthikeyan Periyasamy { 4224bd647855SKarthikeyan Periyasamy struct wmi_tlv_dma_ring_caps_parse *dma_caps_parse = data; 4225bd647855SKarthikeyan Periyasamy struct wmi_dma_ring_capabilities *dma_caps; 4226bd647855SKarthikeyan Periyasamy struct ath11k_dbring_cap *dir_buff_caps; 4227bd647855SKarthikeyan Periyasamy int ret; 4228bd647855SKarthikeyan Periyasamy u32 i; 4229bd647855SKarthikeyan Periyasamy 4230bd647855SKarthikeyan Periyasamy dma_caps_parse->n_dma_ring_caps = 0; 4231bd647855SKarthikeyan Periyasamy dma_caps = (struct wmi_dma_ring_capabilities *)ptr; 4232bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, ptr, len, 4233bd647855SKarthikeyan Periyasamy ath11k_wmi_tlv_dma_ring_caps_parse, 4234bd647855SKarthikeyan Periyasamy dma_caps_parse); 4235bd647855SKarthikeyan Periyasamy if (ret) { 4236bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse dma ring caps tlv %d\n", ret); 4237bd647855SKarthikeyan Periyasamy return ret; 4238bd647855SKarthikeyan Periyasamy } 4239bd647855SKarthikeyan Periyasamy 4240bd647855SKarthikeyan Periyasamy if (!dma_caps_parse->n_dma_ring_caps) 4241bd647855SKarthikeyan Periyasamy return 0; 4242bd647855SKarthikeyan Periyasamy 4243bd647855SKarthikeyan Periyasamy if (ab->num_db_cap) { 4244bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "Already processed, so ignoring dma ring caps\n"); 4245bd647855SKarthikeyan Periyasamy return 0; 4246bd647855SKarthikeyan Periyasamy } 4247bd647855SKarthikeyan Periyasamy 4248bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_alloc_dbring_caps(ab, dma_caps_parse->n_dma_ring_caps); 4249bd647855SKarthikeyan Periyasamy if (ret) 4250bd647855SKarthikeyan Periyasamy return ret; 4251bd647855SKarthikeyan Periyasamy 4252bd647855SKarthikeyan Periyasamy dir_buff_caps = ab->db_caps; 4253bd647855SKarthikeyan Periyasamy for (i = 0; i < dma_caps_parse->n_dma_ring_caps; i++) { 4254bd647855SKarthikeyan Periyasamy if (dma_caps[i].module_id >= WMI_DIRECT_BUF_MAX) { 4255bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "Invalid module id %d\n", dma_caps[i].module_id); 4256bd647855SKarthikeyan Periyasamy ret = -EINVAL; 4257bd647855SKarthikeyan Periyasamy goto free_dir_buff; 4258bd647855SKarthikeyan Periyasamy } 4259bd647855SKarthikeyan Periyasamy 4260bd647855SKarthikeyan Periyasamy dir_buff_caps[i].id = dma_caps[i].module_id; 4261bd647855SKarthikeyan Periyasamy dir_buff_caps[i].pdev_id = DP_HW2SW_MACID(dma_caps[i].pdev_id); 4262bd647855SKarthikeyan Periyasamy dir_buff_caps[i].min_elem = dma_caps[i].min_elem; 4263bd647855SKarthikeyan Periyasamy dir_buff_caps[i].min_buf_sz = dma_caps[i].min_buf_sz; 4264bd647855SKarthikeyan Periyasamy dir_buff_caps[i].min_buf_align = dma_caps[i].min_buf_align; 4265bd647855SKarthikeyan Periyasamy } 4266bd647855SKarthikeyan Periyasamy 4267bd647855SKarthikeyan Periyasamy return 0; 4268bd647855SKarthikeyan Periyasamy 4269bd647855SKarthikeyan Periyasamy free_dir_buff: 4270bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab); 4271bd647855SKarthikeyan Periyasamy return ret; 4272bd647855SKarthikeyan Periyasamy } 4273bd647855SKarthikeyan Periyasamy 4274d5c65159SKalle Valo static int ath11k_wmi_tlv_svc_rdy_ext_parse(struct ath11k_base *ab, 4275d5c65159SKalle Valo u16 tag, u16 len, 4276d5c65159SKalle Valo const void *ptr, void *data) 4277d5c65159SKalle Valo { 42786bc9d6f7SJohn Crispin struct ath11k_pdev_wmi *wmi_handle = &ab->wmi_ab.wmi[0]; 4279d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse *svc_rdy_ext = data; 4280d5c65159SKalle Valo int ret; 4281d5c65159SKalle Valo 4282d5c65159SKalle Valo switch (tag) { 4283d5c65159SKalle Valo case WMI_TAG_SERVICE_READY_EXT_EVENT: 4284d5c65159SKalle Valo ret = ath11k_pull_svc_ready_ext(wmi_handle, ptr, 4285d5c65159SKalle Valo &svc_rdy_ext->param); 4286d5c65159SKalle Valo if (ret) { 4287d5c65159SKalle Valo ath11k_warn(ab, "unable to extract ext params\n"); 4288d5c65159SKalle Valo return ret; 4289d5c65159SKalle Valo } 4290d5c65159SKalle Valo break; 4291d5c65159SKalle Valo 4292d5c65159SKalle Valo case WMI_TAG_SOC_MAC_PHY_HW_MODE_CAPS: 4293d5c65159SKalle Valo svc_rdy_ext->hw_caps = (struct wmi_soc_mac_phy_hw_mode_caps *)ptr; 4294d5c65159SKalle Valo svc_rdy_ext->param.num_hw_modes = svc_rdy_ext->hw_caps->num_hw_modes; 4295d5c65159SKalle Valo break; 4296d5c65159SKalle Valo 4297d5c65159SKalle Valo case WMI_TAG_SOC_HAL_REG_CAPABILITIES: 4298d5c65159SKalle Valo ret = ath11k_wmi_tlv_ext_soc_hal_reg_caps_parse(ab, len, ptr, 4299d5c65159SKalle Valo svc_rdy_ext); 4300d5c65159SKalle Valo if (ret) 4301d5c65159SKalle Valo return ret; 4302d5c65159SKalle Valo break; 4303d5c65159SKalle Valo 4304d5c65159SKalle Valo case WMI_TAG_ARRAY_STRUCT: 4305d5c65159SKalle Valo if (!svc_rdy_ext->hw_mode_done) { 4306d5c65159SKalle Valo ret = ath11k_wmi_tlv_hw_mode_caps(ab, len, ptr, 4307d5c65159SKalle Valo svc_rdy_ext); 4308d5c65159SKalle Valo if (ret) 4309d5c65159SKalle Valo return ret; 4310d5c65159SKalle Valo 4311d5c65159SKalle Valo svc_rdy_ext->hw_mode_done = true; 4312d5c65159SKalle Valo } else if (!svc_rdy_ext->mac_phy_done) { 4313d5c65159SKalle Valo svc_rdy_ext->n_mac_phy_caps = 0; 4314d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, ptr, len, 4315d5c65159SKalle Valo ath11k_wmi_tlv_mac_phy_caps_parse, 4316d5c65159SKalle Valo svc_rdy_ext); 4317d5c65159SKalle Valo if (ret) { 4318d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret); 4319d5c65159SKalle Valo return ret; 4320d5c65159SKalle Valo } 4321d5c65159SKalle Valo 4322d5c65159SKalle Valo svc_rdy_ext->mac_phy_done = true; 4323d5c65159SKalle Valo } else if (!svc_rdy_ext->ext_hal_reg_done) { 4324d5c65159SKalle Valo ret = ath11k_wmi_tlv_ext_hal_reg_caps(ab, len, ptr, 4325d5c65159SKalle Valo svc_rdy_ext); 4326d5c65159SKalle Valo if (ret) 4327d5c65159SKalle Valo return ret; 4328d5c65159SKalle Valo 4329d5c65159SKalle Valo svc_rdy_ext->ext_hal_reg_done = true; 4330bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->mac_phy_chainmask_combo_done) { 4331bd647855SKarthikeyan Periyasamy svc_rdy_ext->mac_phy_chainmask_combo_done = true; 4332bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->mac_phy_chainmask_cap_done) { 4333bd647855SKarthikeyan Periyasamy svc_rdy_ext->mac_phy_chainmask_cap_done = true; 4334bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->oem_dma_ring_cap_done) { 4335bd647855SKarthikeyan Periyasamy svc_rdy_ext->oem_dma_ring_cap_done = true; 4336bd647855SKarthikeyan Periyasamy } else if (!svc_rdy_ext->dma_ring_cap_done) { 4337bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr, 4338bd647855SKarthikeyan Periyasamy &svc_rdy_ext->dma_caps_parse); 4339bd647855SKarthikeyan Periyasamy if (ret) 4340bd647855SKarthikeyan Periyasamy return ret; 4341bd647855SKarthikeyan Periyasamy 4342bd647855SKarthikeyan Periyasamy svc_rdy_ext->dma_ring_cap_done = true; 4343d5c65159SKalle Valo } 4344d5c65159SKalle Valo break; 4345d5c65159SKalle Valo 4346d5c65159SKalle Valo default: 4347d5c65159SKalle Valo break; 4348d5c65159SKalle Valo } 4349d5c65159SKalle Valo return 0; 4350d5c65159SKalle Valo } 4351d5c65159SKalle Valo 4352d5c65159SKalle Valo static int ath11k_service_ready_ext_event(struct ath11k_base *ab, 4353d5c65159SKalle Valo struct sk_buff *skb) 4354d5c65159SKalle Valo { 4355d5c65159SKalle Valo struct wmi_tlv_svc_rdy_ext_parse svc_rdy_ext = { }; 4356d5c65159SKalle Valo int ret; 4357d5c65159SKalle Valo 4358d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 4359d5c65159SKalle Valo ath11k_wmi_tlv_svc_rdy_ext_parse, 4360d5c65159SKalle Valo &svc_rdy_ext); 4361d5c65159SKalle Valo if (ret) { 4362d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret); 4363bd647855SKarthikeyan Periyasamy goto err; 4364d5c65159SKalle Valo } 4365d5c65159SKalle Valo 4366bd647855SKarthikeyan Periyasamy if (!test_bit(WMI_TLV_SERVICE_EXT2_MSG, ab->wmi_ab.svc_map)) 4367bd647855SKarthikeyan Periyasamy complete(&ab->wmi_ab.service_ready); 4368bd647855SKarthikeyan Periyasamy 43695b90fc76SAnilkumar Kolli kfree(svc_rdy_ext.mac_phy_caps); 4370d5c65159SKalle Valo return 0; 4371bd647855SKarthikeyan Periyasamy 4372bd647855SKarthikeyan Periyasamy err: 4373bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab); 4374bd647855SKarthikeyan Periyasamy return ret; 4375bd647855SKarthikeyan Periyasamy } 4376bd647855SKarthikeyan Periyasamy 4377bd647855SKarthikeyan Periyasamy static int ath11k_wmi_tlv_svc_rdy_ext2_parse(struct ath11k_base *ab, 4378bd647855SKarthikeyan Periyasamy u16 tag, u16 len, 4379bd647855SKarthikeyan Periyasamy const void *ptr, void *data) 4380bd647855SKarthikeyan Periyasamy { 4381bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse *parse = data; 4382bd647855SKarthikeyan Periyasamy int ret; 4383bd647855SKarthikeyan Periyasamy 4384bd647855SKarthikeyan Periyasamy switch (tag) { 4385bd647855SKarthikeyan Periyasamy case WMI_TAG_ARRAY_STRUCT: 4386bd647855SKarthikeyan Periyasamy if (!parse->dma_ring_cap_done) { 4387bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_dma_ring_caps(ab, len, ptr, 4388bd647855SKarthikeyan Periyasamy &parse->dma_caps_parse); 4389bd647855SKarthikeyan Periyasamy if (ret) 4390bd647855SKarthikeyan Periyasamy return ret; 4391bd647855SKarthikeyan Periyasamy 4392bd647855SKarthikeyan Periyasamy parse->dma_ring_cap_done = true; 4393bd647855SKarthikeyan Periyasamy } 4394bd647855SKarthikeyan Periyasamy break; 4395bd647855SKarthikeyan Periyasamy default: 4396bd647855SKarthikeyan Periyasamy break; 4397bd647855SKarthikeyan Periyasamy } 4398bd647855SKarthikeyan Periyasamy 4399bd647855SKarthikeyan Periyasamy return 0; 4400bd647855SKarthikeyan Periyasamy } 4401bd647855SKarthikeyan Periyasamy 4402bd647855SKarthikeyan Periyasamy static int ath11k_service_ready_ext2_event(struct ath11k_base *ab, 4403bd647855SKarthikeyan Periyasamy struct sk_buff *skb) 4404bd647855SKarthikeyan Periyasamy { 4405bd647855SKarthikeyan Periyasamy struct wmi_tlv_svc_rdy_ext2_parse svc_rdy_ext2 = { }; 4406bd647855SKarthikeyan Periyasamy int ret; 4407bd647855SKarthikeyan Periyasamy 4408bd647855SKarthikeyan Periyasamy ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 4409bd647855SKarthikeyan Periyasamy ath11k_wmi_tlv_svc_rdy_ext2_parse, 4410bd647855SKarthikeyan Periyasamy &svc_rdy_ext2); 4411bd647855SKarthikeyan Periyasamy if (ret) { 4412bd647855SKarthikeyan Periyasamy ath11k_warn(ab, "failed to parse ext2 event tlv %d\n", ret); 4413bd647855SKarthikeyan Periyasamy goto err; 4414bd647855SKarthikeyan Periyasamy } 4415bd647855SKarthikeyan Periyasamy 4416bd647855SKarthikeyan Periyasamy complete(&ab->wmi_ab.service_ready); 4417bd647855SKarthikeyan Periyasamy 4418bd647855SKarthikeyan Periyasamy return 0; 4419bd647855SKarthikeyan Periyasamy 4420bd647855SKarthikeyan Periyasamy err: 4421bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab); 4422bd647855SKarthikeyan Periyasamy return ret; 4423d5c65159SKalle Valo } 4424d5c65159SKalle Valo 4425d5c65159SKalle Valo static int ath11k_pull_vdev_start_resp_tlv(struct ath11k_base *ab, struct sk_buff *skb, 4426d5c65159SKalle Valo struct wmi_vdev_start_resp_event *vdev_rsp) 4427d5c65159SKalle Valo { 4428d5c65159SKalle Valo const void **tb; 4429d5c65159SKalle Valo const struct wmi_vdev_start_resp_event *ev; 4430d5c65159SKalle Valo int ret; 4431d5c65159SKalle Valo 4432d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4433d5c65159SKalle Valo if (IS_ERR(tb)) { 4434d5c65159SKalle Valo ret = PTR_ERR(tb); 4435d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4436d5c65159SKalle Valo return ret; 4437d5c65159SKalle Valo } 4438d5c65159SKalle Valo 4439d5c65159SKalle Valo ev = tb[WMI_TAG_VDEV_START_RESPONSE_EVENT]; 4440d5c65159SKalle Valo if (!ev) { 4441d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch vdev start resp ev"); 4442d5c65159SKalle Valo kfree(tb); 4443d5c65159SKalle Valo return -EPROTO; 4444d5c65159SKalle Valo } 4445d5c65159SKalle Valo 4446d5c65159SKalle Valo memset(vdev_rsp, 0, sizeof(*vdev_rsp)); 4447d5c65159SKalle Valo 4448d5c65159SKalle Valo vdev_rsp->vdev_id = ev->vdev_id; 4449d5c65159SKalle Valo vdev_rsp->requestor_id = ev->requestor_id; 4450d5c65159SKalle Valo vdev_rsp->resp_type = ev->resp_type; 4451d5c65159SKalle Valo vdev_rsp->status = ev->status; 4452d5c65159SKalle Valo vdev_rsp->chain_mask = ev->chain_mask; 4453d5c65159SKalle Valo vdev_rsp->smps_mode = ev->smps_mode; 4454d5c65159SKalle Valo vdev_rsp->mac_id = ev->mac_id; 4455d5c65159SKalle Valo vdev_rsp->cfgd_tx_streams = ev->cfgd_tx_streams; 4456d5c65159SKalle Valo vdev_rsp->cfgd_rx_streams = ev->cfgd_rx_streams; 4457d5c65159SKalle Valo 4458d5c65159SKalle Valo kfree(tb); 4459d5c65159SKalle Valo return 0; 4460d5c65159SKalle Valo } 4461d5c65159SKalle Valo 4462d5c65159SKalle Valo static struct cur_reg_rule 4463d5c65159SKalle Valo *create_reg_rules_from_wmi(u32 num_reg_rules, 4464d5c65159SKalle Valo struct wmi_regulatory_rule_struct *wmi_reg_rule) 4465d5c65159SKalle Valo { 4466d5c65159SKalle Valo struct cur_reg_rule *reg_rule_ptr; 4467d5c65159SKalle Valo u32 count; 4468d5c65159SKalle Valo 4469d5c65159SKalle Valo reg_rule_ptr = kzalloc((num_reg_rules * sizeof(*reg_rule_ptr)), 4470d5c65159SKalle Valo GFP_ATOMIC); 4471d5c65159SKalle Valo 4472d5c65159SKalle Valo if (!reg_rule_ptr) 4473d5c65159SKalle Valo return NULL; 4474d5c65159SKalle Valo 4475d5c65159SKalle Valo for (count = 0; count < num_reg_rules; count++) { 4476d5c65159SKalle Valo reg_rule_ptr[count].start_freq = 4477d5c65159SKalle Valo FIELD_GET(REG_RULE_START_FREQ, 4478d5c65159SKalle Valo wmi_reg_rule[count].freq_info); 4479d5c65159SKalle Valo reg_rule_ptr[count].end_freq = 4480d5c65159SKalle Valo FIELD_GET(REG_RULE_END_FREQ, 4481d5c65159SKalle Valo wmi_reg_rule[count].freq_info); 4482d5c65159SKalle Valo reg_rule_ptr[count].max_bw = 4483d5c65159SKalle Valo FIELD_GET(REG_RULE_MAX_BW, 4484d5c65159SKalle Valo wmi_reg_rule[count].bw_pwr_info); 4485d5c65159SKalle Valo reg_rule_ptr[count].reg_power = 4486d5c65159SKalle Valo FIELD_GET(REG_RULE_REG_PWR, 4487d5c65159SKalle Valo wmi_reg_rule[count].bw_pwr_info); 4488d5c65159SKalle Valo reg_rule_ptr[count].ant_gain = 4489d5c65159SKalle Valo FIELD_GET(REG_RULE_ANT_GAIN, 4490d5c65159SKalle Valo wmi_reg_rule[count].bw_pwr_info); 4491d5c65159SKalle Valo reg_rule_ptr[count].flags = 4492d5c65159SKalle Valo FIELD_GET(REG_RULE_FLAGS, 4493d5c65159SKalle Valo wmi_reg_rule[count].flag_info); 4494d5c65159SKalle Valo } 4495d5c65159SKalle Valo 4496d5c65159SKalle Valo return reg_rule_ptr; 4497d5c65159SKalle Valo } 4498d5c65159SKalle Valo 4499d5c65159SKalle Valo static int ath11k_pull_reg_chan_list_update_ev(struct ath11k_base *ab, 4500d5c65159SKalle Valo struct sk_buff *skb, 4501d5c65159SKalle Valo struct cur_regulatory_info *reg_info) 4502d5c65159SKalle Valo { 4503d5c65159SKalle Valo const void **tb; 4504d5c65159SKalle Valo const struct wmi_reg_chan_list_cc_event *chan_list_event_hdr; 4505d5c65159SKalle Valo struct wmi_regulatory_rule_struct *wmi_reg_rule; 4506d5c65159SKalle Valo u32 num_2g_reg_rules, num_5g_reg_rules; 4507d5c65159SKalle Valo int ret; 4508d5c65159SKalle Valo 4509d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "processing regulatory channel list\n"); 4510d5c65159SKalle Valo 4511d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4512d5c65159SKalle Valo if (IS_ERR(tb)) { 4513d5c65159SKalle Valo ret = PTR_ERR(tb); 4514d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4515d5c65159SKalle Valo return ret; 4516d5c65159SKalle Valo } 4517d5c65159SKalle Valo 4518d5c65159SKalle Valo chan_list_event_hdr = tb[WMI_TAG_REG_CHAN_LIST_CC_EVENT]; 4519d5c65159SKalle Valo if (!chan_list_event_hdr) { 4520d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch reg chan list update ev\n"); 4521d5c65159SKalle Valo kfree(tb); 4522d5c65159SKalle Valo return -EPROTO; 4523d5c65159SKalle Valo } 4524d5c65159SKalle Valo 4525d5c65159SKalle Valo reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules; 4526d5c65159SKalle Valo reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules; 4527d5c65159SKalle Valo 4528d5c65159SKalle Valo if (!(reg_info->num_2g_reg_rules + reg_info->num_5g_reg_rules)) { 4529d5c65159SKalle Valo ath11k_warn(ab, "No regulatory rules available in the event info\n"); 4530d5c65159SKalle Valo kfree(tb); 4531d5c65159SKalle Valo return -EINVAL; 4532d5c65159SKalle Valo } 4533d5c65159SKalle Valo 4534d5c65159SKalle Valo memcpy(reg_info->alpha2, &chan_list_event_hdr->alpha2, 4535d5c65159SKalle Valo REG_ALPHA2_LEN); 4536d5c65159SKalle Valo reg_info->dfs_region = chan_list_event_hdr->dfs_region; 4537d5c65159SKalle Valo reg_info->phybitmap = chan_list_event_hdr->phybitmap; 4538d5c65159SKalle Valo reg_info->num_phy = chan_list_event_hdr->num_phy; 4539d5c65159SKalle Valo reg_info->phy_id = chan_list_event_hdr->phy_id; 4540d5c65159SKalle Valo reg_info->ctry_code = chan_list_event_hdr->country_id; 4541d5c65159SKalle Valo reg_info->reg_dmn_pair = chan_list_event_hdr->domain_code; 4542d5c65159SKalle Valo if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_PASS) 4543d5c65159SKalle Valo reg_info->status_code = REG_SET_CC_STATUS_PASS; 4544d5c65159SKalle Valo else if (chan_list_event_hdr->status_code == WMI_REG_CURRENT_ALPHA2_NOT_FOUND) 4545d5c65159SKalle Valo reg_info->status_code = REG_CURRENT_ALPHA2_NOT_FOUND; 4546d5c65159SKalle Valo else if (chan_list_event_hdr->status_code == WMI_REG_INIT_ALPHA2_NOT_FOUND) 4547d5c65159SKalle Valo reg_info->status_code = REG_INIT_ALPHA2_NOT_FOUND; 4548d5c65159SKalle Valo else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_CHANGE_NOT_ALLOWED) 4549d5c65159SKalle Valo reg_info->status_code = REG_SET_CC_CHANGE_NOT_ALLOWED; 4550d5c65159SKalle Valo else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_NO_MEMORY) 4551d5c65159SKalle Valo reg_info->status_code = REG_SET_CC_STATUS_NO_MEMORY; 4552d5c65159SKalle Valo else if (chan_list_event_hdr->status_code == WMI_REG_SET_CC_STATUS_FAIL) 4553d5c65159SKalle Valo reg_info->status_code = REG_SET_CC_STATUS_FAIL; 4554d5c65159SKalle Valo 4555d5c65159SKalle Valo reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g; 4556d5c65159SKalle Valo reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g; 4557d5c65159SKalle Valo reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g; 4558d5c65159SKalle Valo reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g; 4559d5c65159SKalle Valo 4560d5c65159SKalle Valo num_2g_reg_rules = reg_info->num_2g_reg_rules; 4561d5c65159SKalle Valo num_5g_reg_rules = reg_info->num_5g_reg_rules; 4562d5c65159SKalle Valo 4563d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 4564d5c65159SKalle Valo "%s:cc %s dsf %d BW: min_2g %d max_2g %d min_5g %d max_5g %d", 4565d5c65159SKalle Valo __func__, reg_info->alpha2, reg_info->dfs_region, 4566d5c65159SKalle Valo reg_info->min_bw_2g, reg_info->max_bw_2g, 4567d5c65159SKalle Valo reg_info->min_bw_5g, reg_info->max_bw_5g); 4568d5c65159SKalle Valo 4569d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 4570d5c65159SKalle Valo "%s: num_2g_reg_rules %d num_5g_reg_rules %d", __func__, 4571d5c65159SKalle Valo num_2g_reg_rules, num_5g_reg_rules); 4572d5c65159SKalle Valo 4573d5c65159SKalle Valo wmi_reg_rule = 4574d5c65159SKalle Valo (struct wmi_regulatory_rule_struct *)((u8 *)chan_list_event_hdr 4575d5c65159SKalle Valo + sizeof(*chan_list_event_hdr) 4576d5c65159SKalle Valo + sizeof(struct wmi_tlv)); 4577d5c65159SKalle Valo 4578d5c65159SKalle Valo if (num_2g_reg_rules) { 4579d5c65159SKalle Valo reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules, 4580d5c65159SKalle Valo wmi_reg_rule); 4581d5c65159SKalle Valo if (!reg_info->reg_rules_2g_ptr) { 4582d5c65159SKalle Valo kfree(tb); 4583d5c65159SKalle Valo ath11k_warn(ab, "Unable to Allocate memory for 2g rules\n"); 4584d5c65159SKalle Valo return -ENOMEM; 4585d5c65159SKalle Valo } 4586d5c65159SKalle Valo } 4587d5c65159SKalle Valo 4588d5c65159SKalle Valo if (num_5g_reg_rules) { 4589d5c65159SKalle Valo wmi_reg_rule += num_2g_reg_rules; 4590d5c65159SKalle Valo reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules, 4591d5c65159SKalle Valo wmi_reg_rule); 4592d5c65159SKalle Valo if (!reg_info->reg_rules_5g_ptr) { 4593d5c65159SKalle Valo kfree(tb); 4594d5c65159SKalle Valo ath11k_warn(ab, "Unable to Allocate memory for 5g rules\n"); 4595d5c65159SKalle Valo return -ENOMEM; 4596d5c65159SKalle Valo } 4597d5c65159SKalle Valo } 4598d5c65159SKalle Valo 4599d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "processed regulatory channel list\n"); 4600d5c65159SKalle Valo 4601d5c65159SKalle Valo kfree(tb); 4602d5c65159SKalle Valo return 0; 4603d5c65159SKalle Valo } 4604d5c65159SKalle Valo 4605d5c65159SKalle Valo static int ath11k_pull_peer_del_resp_ev(struct ath11k_base *ab, struct sk_buff *skb, 4606d5c65159SKalle Valo struct wmi_peer_delete_resp_event *peer_del_resp) 4607d5c65159SKalle Valo { 4608d5c65159SKalle Valo const void **tb; 4609d5c65159SKalle Valo const struct wmi_peer_delete_resp_event *ev; 4610d5c65159SKalle Valo int ret; 4611d5c65159SKalle Valo 4612d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4613d5c65159SKalle Valo if (IS_ERR(tb)) { 4614d5c65159SKalle Valo ret = PTR_ERR(tb); 4615d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4616d5c65159SKalle Valo return ret; 4617d5c65159SKalle Valo } 4618d5c65159SKalle Valo 4619d5c65159SKalle Valo ev = tb[WMI_TAG_PEER_DELETE_RESP_EVENT]; 4620d5c65159SKalle Valo if (!ev) { 4621d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch peer delete resp ev"); 4622d5c65159SKalle Valo kfree(tb); 4623d5c65159SKalle Valo return -EPROTO; 4624d5c65159SKalle Valo } 4625d5c65159SKalle Valo 4626d5c65159SKalle Valo memset(peer_del_resp, 0, sizeof(*peer_del_resp)); 4627d5c65159SKalle Valo 4628d5c65159SKalle Valo peer_del_resp->vdev_id = ev->vdev_id; 4629d5c65159SKalle Valo ether_addr_copy(peer_del_resp->peer_macaddr.addr, 4630d5c65159SKalle Valo ev->peer_macaddr.addr); 4631d5c65159SKalle Valo 4632d5c65159SKalle Valo kfree(tb); 4633d5c65159SKalle Valo return 0; 4634d5c65159SKalle Valo } 4635d5c65159SKalle Valo 46363cbbdfbeSRitesh Singh static int ath11k_pull_vdev_del_resp_ev(struct ath11k_base *ab, 46373cbbdfbeSRitesh Singh struct sk_buff *skb, 46383cbbdfbeSRitesh Singh u32 *vdev_id) 46393cbbdfbeSRitesh Singh { 46403cbbdfbeSRitesh Singh const void **tb; 46413cbbdfbeSRitesh Singh const struct wmi_vdev_delete_resp_event *ev; 46423cbbdfbeSRitesh Singh int ret; 46433cbbdfbeSRitesh Singh 46443cbbdfbeSRitesh Singh tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 46453cbbdfbeSRitesh Singh if (IS_ERR(tb)) { 46463cbbdfbeSRitesh Singh ret = PTR_ERR(tb); 46473cbbdfbeSRitesh Singh ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 46483cbbdfbeSRitesh Singh return ret; 46493cbbdfbeSRitesh Singh } 46503cbbdfbeSRitesh Singh 46513cbbdfbeSRitesh Singh ev = tb[WMI_TAG_VDEV_DELETE_RESP_EVENT]; 46523cbbdfbeSRitesh Singh if (!ev) { 46533cbbdfbeSRitesh Singh ath11k_warn(ab, "failed to fetch vdev delete resp ev"); 46543cbbdfbeSRitesh Singh kfree(tb); 46553cbbdfbeSRitesh Singh return -EPROTO; 46563cbbdfbeSRitesh Singh } 46573cbbdfbeSRitesh Singh 46583cbbdfbeSRitesh Singh *vdev_id = ev->vdev_id; 46593cbbdfbeSRitesh Singh 46603cbbdfbeSRitesh Singh kfree(tb); 46613cbbdfbeSRitesh Singh return 0; 46623cbbdfbeSRitesh Singh } 46633cbbdfbeSRitesh Singh 4664d5c65159SKalle Valo static int ath11k_pull_bcn_tx_status_ev(struct ath11k_base *ab, void *evt_buf, 4665d5c65159SKalle Valo u32 len, u32 *vdev_id, 4666d5c65159SKalle Valo u32 *tx_status) 4667d5c65159SKalle Valo { 4668d5c65159SKalle Valo const void **tb; 4669d5c65159SKalle Valo const struct wmi_bcn_tx_status_event *ev; 4670d5c65159SKalle Valo int ret; 4671d5c65159SKalle Valo 4672d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC); 4673d5c65159SKalle Valo if (IS_ERR(tb)) { 4674d5c65159SKalle Valo ret = PTR_ERR(tb); 4675d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4676d5c65159SKalle Valo return ret; 4677d5c65159SKalle Valo } 4678d5c65159SKalle Valo 4679d5c65159SKalle Valo ev = tb[WMI_TAG_OFFLOAD_BCN_TX_STATUS_EVENT]; 4680d5c65159SKalle Valo if (!ev) { 4681d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch bcn tx status ev"); 4682d5c65159SKalle Valo kfree(tb); 4683d5c65159SKalle Valo return -EPROTO; 4684d5c65159SKalle Valo } 4685d5c65159SKalle Valo 4686d5c65159SKalle Valo *vdev_id = ev->vdev_id; 4687d5c65159SKalle Valo *tx_status = ev->tx_status; 4688d5c65159SKalle Valo 4689d5c65159SKalle Valo kfree(tb); 4690d5c65159SKalle Valo return 0; 4691d5c65159SKalle Valo } 4692d5c65159SKalle Valo 4693d5c65159SKalle Valo static int ath11k_pull_vdev_stopped_param_tlv(struct ath11k_base *ab, struct sk_buff *skb, 4694d5c65159SKalle Valo u32 *vdev_id) 4695d5c65159SKalle Valo { 4696d5c65159SKalle Valo const void **tb; 4697d5c65159SKalle Valo const struct wmi_vdev_stopped_event *ev; 4698d5c65159SKalle Valo int ret; 4699d5c65159SKalle Valo 4700d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4701d5c65159SKalle Valo if (IS_ERR(tb)) { 4702d5c65159SKalle Valo ret = PTR_ERR(tb); 4703d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4704d5c65159SKalle Valo return ret; 4705d5c65159SKalle Valo } 4706d5c65159SKalle Valo 4707d5c65159SKalle Valo ev = tb[WMI_TAG_VDEV_STOPPED_EVENT]; 4708d5c65159SKalle Valo if (!ev) { 4709d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch vdev stop ev"); 4710d5c65159SKalle Valo kfree(tb); 4711d5c65159SKalle Valo return -EPROTO; 4712d5c65159SKalle Valo } 4713d5c65159SKalle Valo 4714d5c65159SKalle Valo *vdev_id = ev->vdev_id; 4715d5c65159SKalle Valo 4716d5c65159SKalle Valo kfree(tb); 4717d5c65159SKalle Valo return 0; 4718d5c65159SKalle Valo } 4719d5c65159SKalle Valo 4720d5c65159SKalle Valo static int ath11k_pull_mgmt_rx_params_tlv(struct ath11k_base *ab, 4721d5c65159SKalle Valo struct sk_buff *skb, 4722d5c65159SKalle Valo struct mgmt_rx_event_params *hdr) 4723d5c65159SKalle Valo { 4724d5c65159SKalle Valo const void **tb; 4725d5c65159SKalle Valo const struct wmi_mgmt_rx_hdr *ev; 4726d5c65159SKalle Valo const u8 *frame; 4727d5c65159SKalle Valo int ret; 4728d5c65159SKalle Valo 4729d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4730d5c65159SKalle Valo if (IS_ERR(tb)) { 4731d5c65159SKalle Valo ret = PTR_ERR(tb); 4732d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4733d5c65159SKalle Valo return ret; 4734d5c65159SKalle Valo } 4735d5c65159SKalle Valo 4736d5c65159SKalle Valo ev = tb[WMI_TAG_MGMT_RX_HDR]; 4737d5c65159SKalle Valo frame = tb[WMI_TAG_ARRAY_BYTE]; 4738d5c65159SKalle Valo 4739d5c65159SKalle Valo if (!ev || !frame) { 4740d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch mgmt rx hdr"); 4741d5c65159SKalle Valo kfree(tb); 4742d5c65159SKalle Valo return -EPROTO; 4743d5c65159SKalle Valo } 4744d5c65159SKalle Valo 4745d5c65159SKalle Valo hdr->pdev_id = ev->pdev_id; 47465dcf42f8SPradeep Kumar Chitrapu hdr->chan_freq = ev->chan_freq; 4747d5c65159SKalle Valo hdr->channel = ev->channel; 4748d5c65159SKalle Valo hdr->snr = ev->snr; 4749d5c65159SKalle Valo hdr->rate = ev->rate; 4750d5c65159SKalle Valo hdr->phy_mode = ev->phy_mode; 4751d5c65159SKalle Valo hdr->buf_len = ev->buf_len; 4752d5c65159SKalle Valo hdr->status = ev->status; 4753d5c65159SKalle Valo hdr->flags = ev->flags; 4754d5c65159SKalle Valo hdr->rssi = ev->rssi; 4755d5c65159SKalle Valo hdr->tsf_delta = ev->tsf_delta; 4756d5c65159SKalle Valo memcpy(hdr->rssi_ctl, ev->rssi_ctl, sizeof(hdr->rssi_ctl)); 4757d5c65159SKalle Valo 4758d5c65159SKalle Valo if (skb->len < (frame - skb->data) + hdr->buf_len) { 4759d5c65159SKalle Valo ath11k_warn(ab, "invalid length in mgmt rx hdr ev"); 4760d5c65159SKalle Valo kfree(tb); 4761d5c65159SKalle Valo return -EPROTO; 4762d5c65159SKalle Valo } 4763d5c65159SKalle Valo 4764d5c65159SKalle Valo /* shift the sk_buff to point to `frame` */ 4765d5c65159SKalle Valo skb_trim(skb, 0); 4766d5c65159SKalle Valo skb_put(skb, frame - skb->data); 4767d5c65159SKalle Valo skb_pull(skb, frame - skb->data); 4768d5c65159SKalle Valo skb_put(skb, hdr->buf_len); 4769d5c65159SKalle Valo 4770d5c65159SKalle Valo ath11k_ce_byte_swap(skb->data, hdr->buf_len); 4771d5c65159SKalle Valo 4772d5c65159SKalle Valo kfree(tb); 4773d5c65159SKalle Valo return 0; 4774d5c65159SKalle Valo } 4775d5c65159SKalle Valo 4776d5c65159SKalle Valo static int wmi_process_mgmt_tx_comp(struct ath11k *ar, u32 desc_id, 4777d5c65159SKalle Valo u32 status) 4778d5c65159SKalle Valo { 4779d5c65159SKalle Valo struct sk_buff *msdu; 4780d5c65159SKalle Valo struct ieee80211_tx_info *info; 4781d5c65159SKalle Valo struct ath11k_skb_cb *skb_cb; 4782d5c65159SKalle Valo 4783d5c65159SKalle Valo spin_lock_bh(&ar->txmgmt_idr_lock); 4784d5c65159SKalle Valo msdu = idr_find(&ar->txmgmt_idr, desc_id); 4785d5c65159SKalle Valo 4786d5c65159SKalle Valo if (!msdu) { 4787d5c65159SKalle Valo ath11k_warn(ar->ab, "received mgmt tx compl for invalid msdu_id: %d\n", 4788d5c65159SKalle Valo desc_id); 4789d5c65159SKalle Valo spin_unlock_bh(&ar->txmgmt_idr_lock); 4790d5c65159SKalle Valo return -ENOENT; 4791d5c65159SKalle Valo } 4792d5c65159SKalle Valo 4793d5c65159SKalle Valo idr_remove(&ar->txmgmt_idr, desc_id); 4794d5c65159SKalle Valo spin_unlock_bh(&ar->txmgmt_idr_lock); 4795d5c65159SKalle Valo 4796d5c65159SKalle Valo skb_cb = ATH11K_SKB_CB(msdu); 4797d5c65159SKalle Valo dma_unmap_single(ar->ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); 4798d5c65159SKalle Valo 4799d5c65159SKalle Valo info = IEEE80211_SKB_CB(msdu); 4800d5c65159SKalle Valo if ((!(info->flags & IEEE80211_TX_CTL_NO_ACK)) && !status) 4801d5c65159SKalle Valo info->flags |= IEEE80211_TX_STAT_ACK; 4802d5c65159SKalle Valo 4803d5c65159SKalle Valo ieee80211_tx_status_irqsafe(ar->hw, msdu); 4804d5c65159SKalle Valo 4805800113ffSSriram R /* WARN when we received this event without doing any mgmt tx */ 4806800113ffSSriram R if (atomic_dec_if_positive(&ar->num_pending_mgmt_tx) < 0) 4807800113ffSSriram R WARN_ON_ONCE(1); 4808d5c65159SKalle Valo 4809d5c65159SKalle Valo return 0; 4810d5c65159SKalle Valo } 4811d5c65159SKalle Valo 4812d5c65159SKalle Valo static int ath11k_pull_mgmt_tx_compl_param_tlv(struct ath11k_base *ab, 4813d5c65159SKalle Valo struct sk_buff *skb, 4814d5c65159SKalle Valo struct wmi_mgmt_tx_compl_event *param) 4815d5c65159SKalle Valo { 4816d5c65159SKalle Valo const void **tb; 4817d5c65159SKalle Valo const struct wmi_mgmt_tx_compl_event *ev; 4818d5c65159SKalle Valo int ret; 4819d5c65159SKalle Valo 4820d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4821d5c65159SKalle Valo if (IS_ERR(tb)) { 4822d5c65159SKalle Valo ret = PTR_ERR(tb); 4823d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4824d5c65159SKalle Valo return ret; 4825d5c65159SKalle Valo } 4826d5c65159SKalle Valo 4827d5c65159SKalle Valo ev = tb[WMI_TAG_MGMT_TX_COMPL_EVENT]; 4828d5c65159SKalle Valo if (!ev) { 4829d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch mgmt tx compl ev"); 4830d5c65159SKalle Valo kfree(tb); 4831d5c65159SKalle Valo return -EPROTO; 4832d5c65159SKalle Valo } 4833d5c65159SKalle Valo 4834d5c65159SKalle Valo param->pdev_id = ev->pdev_id; 4835d5c65159SKalle Valo param->desc_id = ev->desc_id; 4836d5c65159SKalle Valo param->status = ev->status; 4837d5c65159SKalle Valo 4838d5c65159SKalle Valo kfree(tb); 4839d5c65159SKalle Valo return 0; 4840d5c65159SKalle Valo } 4841d5c65159SKalle Valo 4842d5c65159SKalle Valo static void ath11k_wmi_event_scan_started(struct ath11k *ar) 4843d5c65159SKalle Valo { 4844d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock); 4845d5c65159SKalle Valo 4846d5c65159SKalle Valo switch (ar->scan.state) { 4847d5c65159SKalle Valo case ATH11K_SCAN_IDLE: 4848d5c65159SKalle Valo case ATH11K_SCAN_RUNNING: 4849d5c65159SKalle Valo case ATH11K_SCAN_ABORTING: 4850d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan started event in an invalid scan state: %s (%d)\n", 4851d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), 4852d5c65159SKalle Valo ar->scan.state); 4853d5c65159SKalle Valo break; 4854d5c65159SKalle Valo case ATH11K_SCAN_STARTING: 4855d5c65159SKalle Valo ar->scan.state = ATH11K_SCAN_RUNNING; 4856d5c65159SKalle Valo complete(&ar->scan.started); 4857d5c65159SKalle Valo break; 4858d5c65159SKalle Valo } 4859d5c65159SKalle Valo } 4860d5c65159SKalle Valo 4861d5c65159SKalle Valo static void ath11k_wmi_event_scan_start_failed(struct ath11k *ar) 4862d5c65159SKalle Valo { 4863d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock); 4864d5c65159SKalle Valo 4865d5c65159SKalle Valo switch (ar->scan.state) { 4866d5c65159SKalle Valo case ATH11K_SCAN_IDLE: 4867d5c65159SKalle Valo case ATH11K_SCAN_RUNNING: 4868d5c65159SKalle Valo case ATH11K_SCAN_ABORTING: 4869d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan start failed event in an invalid scan state: %s (%d)\n", 4870d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), 4871d5c65159SKalle Valo ar->scan.state); 4872d5c65159SKalle Valo break; 4873d5c65159SKalle Valo case ATH11K_SCAN_STARTING: 4874d5c65159SKalle Valo complete(&ar->scan.started); 4875d5c65159SKalle Valo __ath11k_mac_scan_finish(ar); 4876d5c65159SKalle Valo break; 4877d5c65159SKalle Valo } 4878d5c65159SKalle Valo } 4879d5c65159SKalle Valo 4880d5c65159SKalle Valo static void ath11k_wmi_event_scan_completed(struct ath11k *ar) 4881d5c65159SKalle Valo { 4882d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock); 4883d5c65159SKalle Valo 4884d5c65159SKalle Valo switch (ar->scan.state) { 4885d5c65159SKalle Valo case ATH11K_SCAN_IDLE: 4886d5c65159SKalle Valo case ATH11K_SCAN_STARTING: 4887d5c65159SKalle Valo /* One suspected reason scan can be completed while starting is 4888d5c65159SKalle Valo * if firmware fails to deliver all scan events to the host, 4889d5c65159SKalle Valo * e.g. when transport pipe is full. This has been observed 4890d5c65159SKalle Valo * with spectral scan phyerr events starving wmi transport 4891d5c65159SKalle Valo * pipe. In such case the "scan completed" event should be (and 4892d5c65159SKalle Valo * is) ignored by the host as it may be just firmware's scan 4893d5c65159SKalle Valo * state machine recovering. 4894d5c65159SKalle Valo */ 4895d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan completed event in an invalid scan state: %s (%d)\n", 4896d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), 4897d5c65159SKalle Valo ar->scan.state); 4898d5c65159SKalle Valo break; 4899d5c65159SKalle Valo case ATH11K_SCAN_RUNNING: 4900d5c65159SKalle Valo case ATH11K_SCAN_ABORTING: 4901d5c65159SKalle Valo __ath11k_mac_scan_finish(ar); 4902d5c65159SKalle Valo break; 4903d5c65159SKalle Valo } 4904d5c65159SKalle Valo } 4905d5c65159SKalle Valo 4906d5c65159SKalle Valo static void ath11k_wmi_event_scan_bss_chan(struct ath11k *ar) 4907d5c65159SKalle Valo { 4908d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock); 4909d5c65159SKalle Valo 4910d5c65159SKalle Valo switch (ar->scan.state) { 4911d5c65159SKalle Valo case ATH11K_SCAN_IDLE: 4912d5c65159SKalle Valo case ATH11K_SCAN_STARTING: 4913d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan bss chan event in an invalid scan state: %s (%d)\n", 4914d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), 4915d5c65159SKalle Valo ar->scan.state); 4916d5c65159SKalle Valo break; 4917d5c65159SKalle Valo case ATH11K_SCAN_RUNNING: 4918d5c65159SKalle Valo case ATH11K_SCAN_ABORTING: 4919d5c65159SKalle Valo ar->scan_channel = NULL; 4920d5c65159SKalle Valo break; 4921d5c65159SKalle Valo } 4922d5c65159SKalle Valo } 4923d5c65159SKalle Valo 4924d5c65159SKalle Valo static void ath11k_wmi_event_scan_foreign_chan(struct ath11k *ar, u32 freq) 4925d5c65159SKalle Valo { 4926d5c65159SKalle Valo lockdep_assert_held(&ar->data_lock); 4927d5c65159SKalle Valo 4928d5c65159SKalle Valo switch (ar->scan.state) { 4929d5c65159SKalle Valo case ATH11K_SCAN_IDLE: 4930d5c65159SKalle Valo case ATH11K_SCAN_STARTING: 4931d5c65159SKalle Valo ath11k_warn(ar->ab, "received scan foreign chan event in an invalid scan state: %s (%d)\n", 4932d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), 4933d5c65159SKalle Valo ar->scan.state); 4934d5c65159SKalle Valo break; 4935d5c65159SKalle Valo case ATH11K_SCAN_RUNNING: 4936d5c65159SKalle Valo case ATH11K_SCAN_ABORTING: 4937d5c65159SKalle Valo ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq); 4938d5c65159SKalle Valo break; 4939d5c65159SKalle Valo } 4940d5c65159SKalle Valo } 4941d5c65159SKalle Valo 4942d5c65159SKalle Valo static const char * 4943d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(enum wmi_scan_event_type type, 4944d5c65159SKalle Valo enum wmi_scan_completion_reason reason) 4945d5c65159SKalle Valo { 4946d5c65159SKalle Valo switch (type) { 4947d5c65159SKalle Valo case WMI_SCAN_EVENT_STARTED: 4948d5c65159SKalle Valo return "started"; 4949d5c65159SKalle Valo case WMI_SCAN_EVENT_COMPLETED: 4950d5c65159SKalle Valo switch (reason) { 4951d5c65159SKalle Valo case WMI_SCAN_REASON_COMPLETED: 4952d5c65159SKalle Valo return "completed"; 4953d5c65159SKalle Valo case WMI_SCAN_REASON_CANCELLED: 4954d5c65159SKalle Valo return "completed [cancelled]"; 4955d5c65159SKalle Valo case WMI_SCAN_REASON_PREEMPTED: 4956d5c65159SKalle Valo return "completed [preempted]"; 4957d5c65159SKalle Valo case WMI_SCAN_REASON_TIMEDOUT: 4958d5c65159SKalle Valo return "completed [timedout]"; 4959d5c65159SKalle Valo case WMI_SCAN_REASON_INTERNAL_FAILURE: 4960d5c65159SKalle Valo return "completed [internal err]"; 4961d5c65159SKalle Valo case WMI_SCAN_REASON_MAX: 4962d5c65159SKalle Valo break; 4963d5c65159SKalle Valo } 4964d5c65159SKalle Valo return "completed [unknown]"; 4965d5c65159SKalle Valo case WMI_SCAN_EVENT_BSS_CHANNEL: 4966d5c65159SKalle Valo return "bss channel"; 4967d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN: 4968d5c65159SKalle Valo return "foreign channel"; 4969d5c65159SKalle Valo case WMI_SCAN_EVENT_DEQUEUED: 4970d5c65159SKalle Valo return "dequeued"; 4971d5c65159SKalle Valo case WMI_SCAN_EVENT_PREEMPTED: 4972d5c65159SKalle Valo return "preempted"; 4973d5c65159SKalle Valo case WMI_SCAN_EVENT_START_FAILED: 4974d5c65159SKalle Valo return "start failed"; 4975d5c65159SKalle Valo case WMI_SCAN_EVENT_RESTARTED: 4976d5c65159SKalle Valo return "restarted"; 4977d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT: 4978d5c65159SKalle Valo return "foreign channel exit"; 4979d5c65159SKalle Valo default: 4980d5c65159SKalle Valo return "unknown"; 4981d5c65159SKalle Valo } 4982d5c65159SKalle Valo } 4983d5c65159SKalle Valo 4984d5c65159SKalle Valo static int ath11k_pull_scan_ev(struct ath11k_base *ab, struct sk_buff *skb, 4985d5c65159SKalle Valo struct wmi_scan_event *scan_evt_param) 4986d5c65159SKalle Valo { 4987d5c65159SKalle Valo const void **tb; 4988d5c65159SKalle Valo const struct wmi_scan_event *ev; 4989d5c65159SKalle Valo int ret; 4990d5c65159SKalle Valo 4991d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 4992d5c65159SKalle Valo if (IS_ERR(tb)) { 4993d5c65159SKalle Valo ret = PTR_ERR(tb); 4994d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 4995d5c65159SKalle Valo return ret; 4996d5c65159SKalle Valo } 4997d5c65159SKalle Valo 4998d5c65159SKalle Valo ev = tb[WMI_TAG_SCAN_EVENT]; 4999d5c65159SKalle Valo if (!ev) { 5000d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch scan ev"); 5001d5c65159SKalle Valo kfree(tb); 5002d5c65159SKalle Valo return -EPROTO; 5003d5c65159SKalle Valo } 5004d5c65159SKalle Valo 5005d5c65159SKalle Valo scan_evt_param->event_type = ev->event_type; 5006d5c65159SKalle Valo scan_evt_param->reason = ev->reason; 5007d5c65159SKalle Valo scan_evt_param->channel_freq = ev->channel_freq; 5008d5c65159SKalle Valo scan_evt_param->scan_req_id = ev->scan_req_id; 5009d5c65159SKalle Valo scan_evt_param->scan_id = ev->scan_id; 5010d5c65159SKalle Valo scan_evt_param->vdev_id = ev->vdev_id; 5011d5c65159SKalle Valo scan_evt_param->tsf_timestamp = ev->tsf_timestamp; 5012d5c65159SKalle Valo 5013d5c65159SKalle Valo kfree(tb); 5014d5c65159SKalle Valo return 0; 5015d5c65159SKalle Valo } 5016d5c65159SKalle Valo 5017d5c65159SKalle Valo static int ath11k_pull_peer_sta_kickout_ev(struct ath11k_base *ab, struct sk_buff *skb, 5018d5c65159SKalle Valo struct wmi_peer_sta_kickout_arg *arg) 5019d5c65159SKalle Valo { 5020d5c65159SKalle Valo const void **tb; 5021d5c65159SKalle Valo const struct wmi_peer_sta_kickout_event *ev; 5022d5c65159SKalle Valo int ret; 5023d5c65159SKalle Valo 5024d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 5025d5c65159SKalle Valo if (IS_ERR(tb)) { 5026d5c65159SKalle Valo ret = PTR_ERR(tb); 5027d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5028d5c65159SKalle Valo return ret; 5029d5c65159SKalle Valo } 5030d5c65159SKalle Valo 5031d5c65159SKalle Valo ev = tb[WMI_TAG_PEER_STA_KICKOUT_EVENT]; 5032d5c65159SKalle Valo if (!ev) { 5033d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch peer sta kickout ev"); 5034d5c65159SKalle Valo kfree(tb); 5035d5c65159SKalle Valo return -EPROTO; 5036d5c65159SKalle Valo } 5037d5c65159SKalle Valo 5038d5c65159SKalle Valo arg->mac_addr = ev->peer_macaddr.addr; 5039d5c65159SKalle Valo 5040d5c65159SKalle Valo kfree(tb); 5041d5c65159SKalle Valo return 0; 5042d5c65159SKalle Valo } 5043d5c65159SKalle Valo 5044d5c65159SKalle Valo static int ath11k_pull_roam_ev(struct ath11k_base *ab, struct sk_buff *skb, 5045d5c65159SKalle Valo struct wmi_roam_event *roam_ev) 5046d5c65159SKalle Valo { 5047d5c65159SKalle Valo const void **tb; 5048d5c65159SKalle Valo const struct wmi_roam_event *ev; 5049d5c65159SKalle Valo int ret; 5050d5c65159SKalle Valo 5051d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 5052d5c65159SKalle Valo if (IS_ERR(tb)) { 5053d5c65159SKalle Valo ret = PTR_ERR(tb); 5054d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5055d5c65159SKalle Valo return ret; 5056d5c65159SKalle Valo } 5057d5c65159SKalle Valo 5058d5c65159SKalle Valo ev = tb[WMI_TAG_ROAM_EVENT]; 5059d5c65159SKalle Valo if (!ev) { 5060d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch roam ev"); 5061d5c65159SKalle Valo kfree(tb); 5062d5c65159SKalle Valo return -EPROTO; 5063d5c65159SKalle Valo } 5064d5c65159SKalle Valo 5065d5c65159SKalle Valo roam_ev->vdev_id = ev->vdev_id; 5066d5c65159SKalle Valo roam_ev->reason = ev->reason; 5067d5c65159SKalle Valo roam_ev->rssi = ev->rssi; 5068d5c65159SKalle Valo 5069d5c65159SKalle Valo kfree(tb); 5070d5c65159SKalle Valo return 0; 5071d5c65159SKalle Valo } 5072d5c65159SKalle Valo 5073d5c65159SKalle Valo static int freq_to_idx(struct ath11k *ar, int freq) 5074d5c65159SKalle Valo { 5075d5c65159SKalle Valo struct ieee80211_supported_band *sband; 5076d5c65159SKalle Valo int band, ch, idx = 0; 5077d5c65159SKalle Valo 5078d5c65159SKalle Valo for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) { 5079d5c65159SKalle Valo sband = ar->hw->wiphy->bands[band]; 5080d5c65159SKalle Valo if (!sband) 5081d5c65159SKalle Valo continue; 5082d5c65159SKalle Valo 5083d5c65159SKalle Valo for (ch = 0; ch < sband->n_channels; ch++, idx++) 5084d5c65159SKalle Valo if (sband->channels[ch].center_freq == freq) 5085d5c65159SKalle Valo goto exit; 5086d5c65159SKalle Valo } 5087d5c65159SKalle Valo 5088d5c65159SKalle Valo exit: 5089d5c65159SKalle Valo return idx; 5090d5c65159SKalle Valo } 5091d5c65159SKalle Valo 5092d5c65159SKalle Valo static int ath11k_pull_chan_info_ev(struct ath11k_base *ab, u8 *evt_buf, 5093d5c65159SKalle Valo u32 len, struct wmi_chan_info_event *ch_info_ev) 5094d5c65159SKalle Valo { 5095d5c65159SKalle Valo const void **tb; 5096d5c65159SKalle Valo const struct wmi_chan_info_event *ev; 5097d5c65159SKalle Valo int ret; 5098d5c65159SKalle Valo 5099d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, evt_buf, len, GFP_ATOMIC); 5100d5c65159SKalle Valo if (IS_ERR(tb)) { 5101d5c65159SKalle Valo ret = PTR_ERR(tb); 5102d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5103d5c65159SKalle Valo return ret; 5104d5c65159SKalle Valo } 5105d5c65159SKalle Valo 5106d5c65159SKalle Valo ev = tb[WMI_TAG_CHAN_INFO_EVENT]; 5107d5c65159SKalle Valo if (!ev) { 5108d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch chan info ev"); 5109d5c65159SKalle Valo kfree(tb); 5110d5c65159SKalle Valo return -EPROTO; 5111d5c65159SKalle Valo } 5112d5c65159SKalle Valo 5113d5c65159SKalle Valo ch_info_ev->err_code = ev->err_code; 5114d5c65159SKalle Valo ch_info_ev->freq = ev->freq; 5115d5c65159SKalle Valo ch_info_ev->cmd_flags = ev->cmd_flags; 5116d5c65159SKalle Valo ch_info_ev->noise_floor = ev->noise_floor; 5117d5c65159SKalle Valo ch_info_ev->rx_clear_count = ev->rx_clear_count; 5118d5c65159SKalle Valo ch_info_ev->cycle_count = ev->cycle_count; 5119d5c65159SKalle Valo ch_info_ev->chan_tx_pwr_range = ev->chan_tx_pwr_range; 5120d5c65159SKalle Valo ch_info_ev->chan_tx_pwr_tp = ev->chan_tx_pwr_tp; 5121d5c65159SKalle Valo ch_info_ev->rx_frame_count = ev->rx_frame_count; 5122d5c65159SKalle Valo ch_info_ev->tx_frame_cnt = ev->tx_frame_cnt; 5123d5c65159SKalle Valo ch_info_ev->mac_clk_mhz = ev->mac_clk_mhz; 5124d5c65159SKalle Valo ch_info_ev->vdev_id = ev->vdev_id; 5125d5c65159SKalle Valo 5126d5c65159SKalle Valo kfree(tb); 5127d5c65159SKalle Valo return 0; 5128d5c65159SKalle Valo } 5129d5c65159SKalle Valo 5130d5c65159SKalle Valo static int 5131d5c65159SKalle Valo ath11k_pull_pdev_bss_chan_info_ev(struct ath11k_base *ab, struct sk_buff *skb, 5132d5c65159SKalle Valo struct wmi_pdev_bss_chan_info_event *bss_ch_info_ev) 5133d5c65159SKalle Valo { 5134d5c65159SKalle Valo const void **tb; 5135d5c65159SKalle Valo const struct wmi_pdev_bss_chan_info_event *ev; 5136d5c65159SKalle Valo int ret; 5137d5c65159SKalle Valo 5138d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 5139d5c65159SKalle Valo if (IS_ERR(tb)) { 5140d5c65159SKalle Valo ret = PTR_ERR(tb); 5141d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5142d5c65159SKalle Valo return ret; 5143d5c65159SKalle Valo } 5144d5c65159SKalle Valo 5145d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_BSS_CHAN_INFO_EVENT]; 5146d5c65159SKalle Valo if (!ev) { 5147d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev bss chan info ev"); 5148d5c65159SKalle Valo kfree(tb); 5149d5c65159SKalle Valo return -EPROTO; 5150d5c65159SKalle Valo } 5151d5c65159SKalle Valo 5152d5c65159SKalle Valo bss_ch_info_ev->pdev_id = ev->pdev_id; 5153d5c65159SKalle Valo bss_ch_info_ev->freq = ev->freq; 5154d5c65159SKalle Valo bss_ch_info_ev->noise_floor = ev->noise_floor; 5155d5c65159SKalle Valo bss_ch_info_ev->rx_clear_count_low = ev->rx_clear_count_low; 5156d5c65159SKalle Valo bss_ch_info_ev->rx_clear_count_high = ev->rx_clear_count_high; 5157d5c65159SKalle Valo bss_ch_info_ev->cycle_count_low = ev->cycle_count_low; 5158d5c65159SKalle Valo bss_ch_info_ev->cycle_count_high = ev->cycle_count_high; 5159d5c65159SKalle Valo bss_ch_info_ev->tx_cycle_count_low = ev->tx_cycle_count_low; 5160d5c65159SKalle Valo bss_ch_info_ev->tx_cycle_count_high = ev->tx_cycle_count_high; 5161d5c65159SKalle Valo bss_ch_info_ev->rx_cycle_count_low = ev->rx_cycle_count_low; 5162d5c65159SKalle Valo bss_ch_info_ev->rx_cycle_count_high = ev->rx_cycle_count_high; 5163d5c65159SKalle Valo bss_ch_info_ev->rx_bss_cycle_count_low = ev->rx_bss_cycle_count_low; 5164d5c65159SKalle Valo bss_ch_info_ev->rx_bss_cycle_count_high = ev->rx_bss_cycle_count_high; 5165d5c65159SKalle Valo 5166d5c65159SKalle Valo kfree(tb); 5167d5c65159SKalle Valo return 0; 5168d5c65159SKalle Valo } 5169d5c65159SKalle Valo 5170d5c65159SKalle Valo static int 5171d5c65159SKalle Valo ath11k_pull_vdev_install_key_compl_ev(struct ath11k_base *ab, struct sk_buff *skb, 5172d5c65159SKalle Valo struct wmi_vdev_install_key_complete_arg *arg) 5173d5c65159SKalle Valo { 5174d5c65159SKalle Valo const void **tb; 5175d5c65159SKalle Valo const struct wmi_vdev_install_key_compl_event *ev; 5176d5c65159SKalle Valo int ret; 5177d5c65159SKalle Valo 5178d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 5179d5c65159SKalle Valo if (IS_ERR(tb)) { 5180d5c65159SKalle Valo ret = PTR_ERR(tb); 5181d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5182d5c65159SKalle Valo return ret; 5183d5c65159SKalle Valo } 5184d5c65159SKalle Valo 5185d5c65159SKalle Valo ev = tb[WMI_TAG_VDEV_INSTALL_KEY_COMPLETE_EVENT]; 5186d5c65159SKalle Valo if (!ev) { 5187d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch vdev install key compl ev"); 5188d5c65159SKalle Valo kfree(tb); 5189d5c65159SKalle Valo return -EPROTO; 5190d5c65159SKalle Valo } 5191d5c65159SKalle Valo 5192d5c65159SKalle Valo arg->vdev_id = ev->vdev_id; 5193d5c65159SKalle Valo arg->macaddr = ev->peer_macaddr.addr; 5194d5c65159SKalle Valo arg->key_idx = ev->key_idx; 5195d5c65159SKalle Valo arg->key_flags = ev->key_flags; 5196d5c65159SKalle Valo arg->status = ev->status; 5197d5c65159SKalle Valo 5198d5c65159SKalle Valo kfree(tb); 5199d5c65159SKalle Valo return 0; 5200d5c65159SKalle Valo } 5201d5c65159SKalle Valo 5202d5c65159SKalle Valo static int ath11k_pull_peer_assoc_conf_ev(struct ath11k_base *ab, struct sk_buff *skb, 5203d5c65159SKalle Valo struct wmi_peer_assoc_conf_arg *peer_assoc_conf) 5204d5c65159SKalle Valo { 5205d5c65159SKalle Valo const void **tb; 5206d5c65159SKalle Valo const struct wmi_peer_assoc_conf_event *ev; 5207d5c65159SKalle Valo int ret; 5208d5c65159SKalle Valo 5209d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 5210d5c65159SKalle Valo if (IS_ERR(tb)) { 5211d5c65159SKalle Valo ret = PTR_ERR(tb); 5212d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5213d5c65159SKalle Valo return ret; 5214d5c65159SKalle Valo } 5215d5c65159SKalle Valo 5216d5c65159SKalle Valo ev = tb[WMI_TAG_PEER_ASSOC_CONF_EVENT]; 5217d5c65159SKalle Valo if (!ev) { 5218d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch peer assoc conf ev"); 5219d5c65159SKalle Valo kfree(tb); 5220d5c65159SKalle Valo return -EPROTO; 5221d5c65159SKalle Valo } 5222d5c65159SKalle Valo 5223d5c65159SKalle Valo peer_assoc_conf->vdev_id = ev->vdev_id; 5224d5c65159SKalle Valo peer_assoc_conf->macaddr = ev->peer_macaddr.addr; 5225d5c65159SKalle Valo 5226d5c65159SKalle Valo kfree(tb); 5227d5c65159SKalle Valo return 0; 5228d5c65159SKalle Valo } 5229d5c65159SKalle Valo 5230d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src, 5231d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst) 5232d5c65159SKalle Valo { 5233d5c65159SKalle Valo dst->ch_noise_floor = src->chan_nf; 5234d5c65159SKalle Valo dst->tx_frame_count = src->tx_frame_count; 5235d5c65159SKalle Valo dst->rx_frame_count = src->rx_frame_count; 5236d5c65159SKalle Valo dst->rx_clear_count = src->rx_clear_count; 5237d5c65159SKalle Valo dst->cycle_count = src->cycle_count; 5238d5c65159SKalle Valo dst->phy_err_count = src->phy_err_count; 5239d5c65159SKalle Valo dst->chan_tx_power = src->chan_tx_pwr; 5240d5c65159SKalle Valo } 5241d5c65159SKalle Valo 5242d5c65159SKalle Valo static void 5243d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src, 5244d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst) 5245d5c65159SKalle Valo { 5246d5c65159SKalle Valo dst->comp_queued = src->comp_queued; 5247d5c65159SKalle Valo dst->comp_delivered = src->comp_delivered; 5248d5c65159SKalle Valo dst->msdu_enqued = src->msdu_enqued; 5249d5c65159SKalle Valo dst->mpdu_enqued = src->mpdu_enqued; 5250d5c65159SKalle Valo dst->wmm_drop = src->wmm_drop; 5251d5c65159SKalle Valo dst->local_enqued = src->local_enqued; 5252d5c65159SKalle Valo dst->local_freed = src->local_freed; 5253d5c65159SKalle Valo dst->hw_queued = src->hw_queued; 5254d5c65159SKalle Valo dst->hw_reaped = src->hw_reaped; 5255d5c65159SKalle Valo dst->underrun = src->underrun; 5256f394e4eaSSriram R dst->hw_paused = src->hw_paused; 5257d5c65159SKalle Valo dst->tx_abort = src->tx_abort; 525817818dfaSColin Ian King dst->mpdus_requeued = src->mpdus_requeued; 5259d5c65159SKalle Valo dst->tx_ko = src->tx_ko; 5260f394e4eaSSriram R dst->tx_xretry = src->tx_xretry; 5261d5c65159SKalle Valo dst->data_rc = src->data_rc; 5262d5c65159SKalle Valo dst->self_triggers = src->self_triggers; 5263d5c65159SKalle Valo dst->sw_retry_failure = src->sw_retry_failure; 5264d5c65159SKalle Valo dst->illgl_rate_phy_err = src->illgl_rate_phy_err; 5265d5c65159SKalle Valo dst->pdev_cont_xretry = src->pdev_cont_xretry; 5266d5c65159SKalle Valo dst->pdev_tx_timeout = src->pdev_tx_timeout; 5267d5c65159SKalle Valo dst->pdev_resets = src->pdev_resets; 5268d5c65159SKalle Valo dst->stateless_tid_alloc_failure = src->stateless_tid_alloc_failure; 5269d5c65159SKalle Valo dst->phy_underrun = src->phy_underrun; 5270d5c65159SKalle Valo dst->txop_ovf = src->txop_ovf; 5271f394e4eaSSriram R dst->seq_posted = src->seq_posted; 5272f394e4eaSSriram R dst->seq_failed_queueing = src->seq_failed_queueing; 5273f394e4eaSSriram R dst->seq_completed = src->seq_completed; 5274f394e4eaSSriram R dst->seq_restarted = src->seq_restarted; 5275f394e4eaSSriram R dst->mu_seq_posted = src->mu_seq_posted; 5276f394e4eaSSriram R dst->mpdus_sw_flush = src->mpdus_sw_flush; 5277f394e4eaSSriram R dst->mpdus_hw_filter = src->mpdus_hw_filter; 5278f394e4eaSSriram R dst->mpdus_truncated = src->mpdus_truncated; 5279f394e4eaSSriram R dst->mpdus_ack_failed = src->mpdus_ack_failed; 5280f394e4eaSSriram R dst->mpdus_expired = src->mpdus_expired; 5281d5c65159SKalle Valo } 5282d5c65159SKalle Valo 5283d5c65159SKalle Valo static void ath11k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src, 5284d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst) 5285d5c65159SKalle Valo { 5286d5c65159SKalle Valo dst->mid_ppdu_route_change = src->mid_ppdu_route_change; 5287d5c65159SKalle Valo dst->status_rcvd = src->status_rcvd; 5288d5c65159SKalle Valo dst->r0_frags = src->r0_frags; 5289d5c65159SKalle Valo dst->r1_frags = src->r1_frags; 5290d5c65159SKalle Valo dst->r2_frags = src->r2_frags; 5291d5c65159SKalle Valo dst->r3_frags = src->r3_frags; 5292d5c65159SKalle Valo dst->htt_msdus = src->htt_msdus; 5293d5c65159SKalle Valo dst->htt_mpdus = src->htt_mpdus; 5294d5c65159SKalle Valo dst->loc_msdus = src->loc_msdus; 5295d5c65159SKalle Valo dst->loc_mpdus = src->loc_mpdus; 5296d5c65159SKalle Valo dst->oversize_amsdu = src->oversize_amsdu; 5297d5c65159SKalle Valo dst->phy_errs = src->phy_errs; 5298d5c65159SKalle Valo dst->phy_err_drop = src->phy_err_drop; 5299d5c65159SKalle Valo dst->mpdu_errs = src->mpdu_errs; 5300f394e4eaSSriram R dst->rx_ovfl_errs = src->rx_ovfl_errs; 5301d5c65159SKalle Valo } 5302d5c65159SKalle Valo 5303d5c65159SKalle Valo static void 5304d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(const struct wmi_vdev_stats *src, 5305d5c65159SKalle Valo struct ath11k_fw_stats_vdev *dst) 5306d5c65159SKalle Valo { 5307d5c65159SKalle Valo int i; 5308d5c65159SKalle Valo 5309d5c65159SKalle Valo dst->vdev_id = src->vdev_id; 5310d5c65159SKalle Valo dst->beacon_snr = src->beacon_snr; 5311d5c65159SKalle Valo dst->data_snr = src->data_snr; 5312d5c65159SKalle Valo dst->num_rx_frames = src->num_rx_frames; 5313d5c65159SKalle Valo dst->num_rts_fail = src->num_rts_fail; 5314d5c65159SKalle Valo dst->num_rts_success = src->num_rts_success; 5315d5c65159SKalle Valo dst->num_rx_err = src->num_rx_err; 5316d5c65159SKalle Valo dst->num_rx_discard = src->num_rx_discard; 5317d5c65159SKalle Valo dst->num_tx_not_acked = src->num_tx_not_acked; 5318d5c65159SKalle Valo 5319d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->num_tx_frames); i++) 5320d5c65159SKalle Valo dst->num_tx_frames[i] = src->num_tx_frames[i]; 5321d5c65159SKalle Valo 5322d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_retries); i++) 5323d5c65159SKalle Valo dst->num_tx_frames_retries[i] = src->num_tx_frames_retries[i]; 5324d5c65159SKalle Valo 5325d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->num_tx_frames_failures); i++) 5326d5c65159SKalle Valo dst->num_tx_frames_failures[i] = src->num_tx_frames_failures[i]; 5327d5c65159SKalle Valo 5328d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->tx_rate_history); i++) 5329d5c65159SKalle Valo dst->tx_rate_history[i] = src->tx_rate_history[i]; 5330d5c65159SKalle Valo 5331d5c65159SKalle Valo for (i = 0; i < ARRAY_SIZE(src->beacon_rssi_history); i++) 5332d5c65159SKalle Valo dst->beacon_rssi_history[i] = src->beacon_rssi_history[i]; 5333d5c65159SKalle Valo } 5334d5c65159SKalle Valo 5335d5c65159SKalle Valo static void 5336d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(const struct wmi_bcn_stats *src, 5337d5c65159SKalle Valo struct ath11k_fw_stats_bcn *dst) 5338d5c65159SKalle Valo { 5339d5c65159SKalle Valo dst->vdev_id = src->vdev_id; 5340d5c65159SKalle Valo dst->tx_bcn_succ_cnt = src->tx_bcn_succ_cnt; 5341d5c65159SKalle Valo dst->tx_bcn_outage_cnt = src->tx_bcn_outage_cnt; 5342d5c65159SKalle Valo } 5343d5c65159SKalle Valo 5344d5c65159SKalle Valo int ath11k_wmi_pull_fw_stats(struct ath11k_base *ab, struct sk_buff *skb, 5345d5c65159SKalle Valo struct ath11k_fw_stats *stats) 5346d5c65159SKalle Valo { 5347d5c65159SKalle Valo const void **tb; 5348d5c65159SKalle Valo const struct wmi_stats_event *ev; 5349d5c65159SKalle Valo const void *data; 5350d5c65159SKalle Valo int i, ret; 5351d5c65159SKalle Valo u32 len = skb->len; 5352d5c65159SKalle Valo 5353d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, len, GFP_ATOMIC); 5354d5c65159SKalle Valo if (IS_ERR(tb)) { 5355d5c65159SKalle Valo ret = PTR_ERR(tb); 5356d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 5357d5c65159SKalle Valo return ret; 5358d5c65159SKalle Valo } 5359d5c65159SKalle Valo 5360d5c65159SKalle Valo ev = tb[WMI_TAG_STATS_EVENT]; 5361d5c65159SKalle Valo data = tb[WMI_TAG_ARRAY_BYTE]; 5362d5c65159SKalle Valo if (!ev || !data) { 5363d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch update stats ev"); 5364d5c65159SKalle Valo kfree(tb); 5365d5c65159SKalle Valo return -EPROTO; 5366d5c65159SKalle Valo } 5367d5c65159SKalle Valo 5368d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 5369d5c65159SKalle Valo "wmi stats update ev pdev_id %d pdev %i vdev %i bcn %i\n", 5370d5c65159SKalle Valo ev->pdev_id, 5371d5c65159SKalle Valo ev->num_pdev_stats, ev->num_vdev_stats, 5372d5c65159SKalle Valo ev->num_bcn_stats); 5373d5c65159SKalle Valo 5374d5c65159SKalle Valo stats->pdev_id = ev->pdev_id; 5375d5c65159SKalle Valo stats->stats_id = 0; 5376d5c65159SKalle Valo 5377d5c65159SKalle Valo for (i = 0; i < ev->num_pdev_stats; i++) { 5378d5c65159SKalle Valo const struct wmi_pdev_stats *src; 5379d5c65159SKalle Valo struct ath11k_fw_stats_pdev *dst; 5380d5c65159SKalle Valo 5381d5c65159SKalle Valo src = data; 5382d5c65159SKalle Valo if (len < sizeof(*src)) { 5383d5c65159SKalle Valo kfree(tb); 5384d5c65159SKalle Valo return -EPROTO; 5385d5c65159SKalle Valo } 5386d5c65159SKalle Valo 5387d5c65159SKalle Valo stats->stats_id = WMI_REQUEST_PDEV_STAT; 5388d5c65159SKalle Valo 5389d5c65159SKalle Valo data += sizeof(*src); 5390d5c65159SKalle Valo len -= sizeof(*src); 5391d5c65159SKalle Valo 5392d5c65159SKalle Valo dst = kzalloc(sizeof(*dst), GFP_ATOMIC); 5393d5c65159SKalle Valo if (!dst) 5394d5c65159SKalle Valo continue; 5395d5c65159SKalle Valo 5396d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_base(&src->base, dst); 5397d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_tx(&src->tx, dst); 5398d5c65159SKalle Valo ath11k_wmi_pull_pdev_stats_rx(&src->rx, dst); 5399d5c65159SKalle Valo list_add_tail(&dst->list, &stats->pdevs); 5400d5c65159SKalle Valo } 5401d5c65159SKalle Valo 5402d5c65159SKalle Valo for (i = 0; i < ev->num_vdev_stats; i++) { 5403d5c65159SKalle Valo const struct wmi_vdev_stats *src; 5404d5c65159SKalle Valo struct ath11k_fw_stats_vdev *dst; 5405d5c65159SKalle Valo 5406d5c65159SKalle Valo src = data; 5407d5c65159SKalle Valo if (len < sizeof(*src)) { 5408d5c65159SKalle Valo kfree(tb); 5409d5c65159SKalle Valo return -EPROTO; 5410d5c65159SKalle Valo } 5411d5c65159SKalle Valo 5412d5c65159SKalle Valo stats->stats_id = WMI_REQUEST_VDEV_STAT; 5413d5c65159SKalle Valo 5414d5c65159SKalle Valo data += sizeof(*src); 5415d5c65159SKalle Valo len -= sizeof(*src); 5416d5c65159SKalle Valo 5417d5c65159SKalle Valo dst = kzalloc(sizeof(*dst), GFP_ATOMIC); 5418d5c65159SKalle Valo if (!dst) 5419d5c65159SKalle Valo continue; 5420d5c65159SKalle Valo 5421d5c65159SKalle Valo ath11k_wmi_pull_vdev_stats(src, dst); 5422d5c65159SKalle Valo list_add_tail(&dst->list, &stats->vdevs); 5423d5c65159SKalle Valo } 5424d5c65159SKalle Valo 5425d5c65159SKalle Valo for (i = 0; i < ev->num_bcn_stats; i++) { 5426d5c65159SKalle Valo const struct wmi_bcn_stats *src; 5427d5c65159SKalle Valo struct ath11k_fw_stats_bcn *dst; 5428d5c65159SKalle Valo 5429d5c65159SKalle Valo src = data; 5430d5c65159SKalle Valo if (len < sizeof(*src)) { 5431d5c65159SKalle Valo kfree(tb); 5432d5c65159SKalle Valo return -EPROTO; 5433d5c65159SKalle Valo } 5434d5c65159SKalle Valo 5435d5c65159SKalle Valo stats->stats_id = WMI_REQUEST_BCN_STAT; 5436d5c65159SKalle Valo 5437d5c65159SKalle Valo data += sizeof(*src); 5438d5c65159SKalle Valo len -= sizeof(*src); 5439d5c65159SKalle Valo 5440d5c65159SKalle Valo dst = kzalloc(sizeof(*dst), GFP_ATOMIC); 5441d5c65159SKalle Valo if (!dst) 5442d5c65159SKalle Valo continue; 5443d5c65159SKalle Valo 5444d5c65159SKalle Valo ath11k_wmi_pull_bcn_stats(src, dst); 5445d5c65159SKalle Valo list_add_tail(&dst->list, &stats->bcn); 5446d5c65159SKalle Valo } 5447d5c65159SKalle Valo 5448d5c65159SKalle Valo kfree(tb); 5449d5c65159SKalle Valo return 0; 5450d5c65159SKalle Valo } 5451d5c65159SKalle Valo 5452d5c65159SKalle Valo size_t ath11k_wmi_fw_stats_num_vdevs(struct list_head *head) 5453d5c65159SKalle Valo { 5454d5c65159SKalle Valo struct ath11k_fw_stats_vdev *i; 5455d5c65159SKalle Valo size_t num = 0; 5456d5c65159SKalle Valo 5457d5c65159SKalle Valo list_for_each_entry(i, head, list) 5458d5c65159SKalle Valo ++num; 5459d5c65159SKalle Valo 5460d5c65159SKalle Valo return num; 5461d5c65159SKalle Valo } 5462d5c65159SKalle Valo 5463d5c65159SKalle Valo static size_t ath11k_wmi_fw_stats_num_bcn(struct list_head *head) 5464d5c65159SKalle Valo { 5465d5c65159SKalle Valo struct ath11k_fw_stats_bcn *i; 5466d5c65159SKalle Valo size_t num = 0; 5467d5c65159SKalle Valo 5468d5c65159SKalle Valo list_for_each_entry(i, head, list) 5469d5c65159SKalle Valo ++num; 5470d5c65159SKalle Valo 5471d5c65159SKalle Valo return num; 5472d5c65159SKalle Valo } 5473d5c65159SKalle Valo 5474d5c65159SKalle Valo static void 5475d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(const struct ath11k_fw_stats_pdev *pdev, 5476d5c65159SKalle Valo char *buf, u32 *length) 5477d5c65159SKalle Valo { 5478d5c65159SKalle Valo u32 len = *length; 5479d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5480d5c65159SKalle Valo 5481d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n"); 5482d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n", 5483d5c65159SKalle Valo "ath11k PDEV stats"); 5484d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5485d5c65159SKalle Valo "================="); 5486d5c65159SKalle Valo 5487d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5488d5c65159SKalle Valo "Channel noise floor", pdev->ch_noise_floor); 5489d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5490d5c65159SKalle Valo "Channel TX power", pdev->chan_tx_power); 5491d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5492d5c65159SKalle Valo "TX frame count", pdev->tx_frame_count); 5493d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5494d5c65159SKalle Valo "RX frame count", pdev->rx_frame_count); 5495d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5496d5c65159SKalle Valo "RX clear count", pdev->rx_clear_count); 5497d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5498d5c65159SKalle Valo "Cycle count", pdev->cycle_count); 5499d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5500d5c65159SKalle Valo "PHY error count", pdev->phy_err_count); 5501d5c65159SKalle Valo 5502d5c65159SKalle Valo *length = len; 5503d5c65159SKalle Valo } 5504d5c65159SKalle Valo 5505d5c65159SKalle Valo static void 5506d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(const struct ath11k_fw_stats_pdev *pdev, 5507d5c65159SKalle Valo char *buf, u32 *length) 5508d5c65159SKalle Valo { 5509d5c65159SKalle Valo u32 len = *length; 5510d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5511d5c65159SKalle Valo 5512d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n%30s\n", 5513d5c65159SKalle Valo "ath11k PDEV TX stats"); 5514d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5515d5c65159SKalle Valo "===================="); 5516d5c65159SKalle Valo 5517d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5518d5c65159SKalle Valo "HTT cookies queued", pdev->comp_queued); 5519d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5520d5c65159SKalle Valo "HTT cookies disp.", pdev->comp_delivered); 5521d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5522d5c65159SKalle Valo "MSDU queued", pdev->msdu_enqued); 5523d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5524d5c65159SKalle Valo "MPDU queued", pdev->mpdu_enqued); 5525d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5526d5c65159SKalle Valo "MSDUs dropped", pdev->wmm_drop); 5527d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5528d5c65159SKalle Valo "Local enqued", pdev->local_enqued); 5529d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5530d5c65159SKalle Valo "Local freed", pdev->local_freed); 5531d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5532d5c65159SKalle Valo "HW queued", pdev->hw_queued); 5533d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5534d5c65159SKalle Valo "PPDUs reaped", pdev->hw_reaped); 5535d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5536d5c65159SKalle Valo "Num underruns", pdev->underrun); 5537d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5538f394e4eaSSriram R "Num HW Paused", pdev->hw_paused); 5539f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5540d5c65159SKalle Valo "PPDUs cleaned", pdev->tx_abort); 5541d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 554217818dfaSColin Ian King "MPDUs requeued", pdev->mpdus_requeued); 5543d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5544f394e4eaSSriram R "PPDU OK", pdev->tx_ko); 5545f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5546f394e4eaSSriram R "Excessive retries", pdev->tx_xretry); 5547d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5548d5c65159SKalle Valo "HW rate", pdev->data_rc); 5549d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5550d5c65159SKalle Valo "Sched self triggers", pdev->self_triggers); 5551d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5552d5c65159SKalle Valo "Dropped due to SW retries", 5553d5c65159SKalle Valo pdev->sw_retry_failure); 5554d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5555d5c65159SKalle Valo "Illegal rate phy errors", 5556d5c65159SKalle Valo pdev->illgl_rate_phy_err); 5557d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5558d5c65159SKalle Valo "PDEV continuous xretry", pdev->pdev_cont_xretry); 5559d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5560d5c65159SKalle Valo "TX timeout", pdev->pdev_tx_timeout); 5561d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5562d5c65159SKalle Valo "PDEV resets", pdev->pdev_resets); 5563d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5564d5c65159SKalle Valo "Stateless TIDs alloc failures", 5565d5c65159SKalle Valo pdev->stateless_tid_alloc_failure); 5566d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5567d5c65159SKalle Valo "PHY underrun", pdev->phy_underrun); 5568d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5569d5c65159SKalle Valo "MPDU is more than txop limit", pdev->txop_ovf); 5570f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5571f394e4eaSSriram R "Num sequences posted", pdev->seq_posted); 5572f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5573f394e4eaSSriram R "Num seq failed queueing ", pdev->seq_failed_queueing); 5574f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5575f394e4eaSSriram R "Num sequences completed ", pdev->seq_completed); 5576f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5577f394e4eaSSriram R "Num sequences restarted ", pdev->seq_restarted); 5578f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5579f394e4eaSSriram R "Num of MU sequences posted ", pdev->mu_seq_posted); 5580f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5581f394e4eaSSriram R "Num of MPDUS SW flushed ", pdev->mpdus_sw_flush); 5582f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5583f394e4eaSSriram R "Num of MPDUS HW filtered ", pdev->mpdus_hw_filter); 5584f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5585f394e4eaSSriram R "Num of MPDUS truncated ", pdev->mpdus_truncated); 5586f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5587f394e4eaSSriram R "Num of MPDUS ACK failed ", pdev->mpdus_ack_failed); 5588f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10u\n", 5589f394e4eaSSriram R "Num of MPDUS expired ", pdev->mpdus_expired); 5590d5c65159SKalle Valo *length = len; 5591d5c65159SKalle Valo } 5592d5c65159SKalle Valo 5593d5c65159SKalle Valo static void 5594d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(const struct ath11k_fw_stats_pdev *pdev, 5595d5c65159SKalle Valo char *buf, u32 *length) 5596d5c65159SKalle Valo { 5597d5c65159SKalle Valo u32 len = *length; 5598d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5599d5c65159SKalle Valo 5600d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n%30s\n", 5601d5c65159SKalle Valo "ath11k PDEV RX stats"); 5602d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5603d5c65159SKalle Valo "===================="); 5604d5c65159SKalle Valo 5605d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5606d5c65159SKalle Valo "Mid PPDU route change", 5607d5c65159SKalle Valo pdev->mid_ppdu_route_change); 5608d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5609d5c65159SKalle Valo "Tot. number of statuses", pdev->status_rcvd); 5610d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5611d5c65159SKalle Valo "Extra frags on rings 0", pdev->r0_frags); 5612d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5613d5c65159SKalle Valo "Extra frags on rings 1", pdev->r1_frags); 5614d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5615d5c65159SKalle Valo "Extra frags on rings 2", pdev->r2_frags); 5616d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5617d5c65159SKalle Valo "Extra frags on rings 3", pdev->r3_frags); 5618d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5619d5c65159SKalle Valo "MSDUs delivered to HTT", pdev->htt_msdus); 5620d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5621d5c65159SKalle Valo "MPDUs delivered to HTT", pdev->htt_mpdus); 5622d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5623d5c65159SKalle Valo "MSDUs delivered to stack", pdev->loc_msdus); 5624d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5625d5c65159SKalle Valo "MPDUs delivered to stack", pdev->loc_mpdus); 5626d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5627d5c65159SKalle Valo "Oversized AMSUs", pdev->oversize_amsdu); 5628d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5629d5c65159SKalle Valo "PHY errors", pdev->phy_errs); 5630d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5631d5c65159SKalle Valo "PHY errors drops", pdev->phy_err_drop); 5632d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5633d5c65159SKalle Valo "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs); 5634f394e4eaSSriram R len += scnprintf(buf + len, buf_len - len, "%30s %10d\n", 5635f394e4eaSSriram R "Overflow errors", pdev->rx_ovfl_errs); 5636d5c65159SKalle Valo *length = len; 5637d5c65159SKalle Valo } 5638d5c65159SKalle Valo 5639d5c65159SKalle Valo static void 5640d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(struct ath11k *ar, 5641d5c65159SKalle Valo const struct ath11k_fw_stats_vdev *vdev, 5642d5c65159SKalle Valo char *buf, u32 *length) 5643d5c65159SKalle Valo { 5644d5c65159SKalle Valo u32 len = *length; 5645d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5646d5c65159SKalle Valo struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, vdev->vdev_id); 5647d5c65159SKalle Valo u8 *vif_macaddr; 5648d5c65159SKalle Valo int i; 5649d5c65159SKalle Valo 5650d5c65159SKalle Valo /* VDEV stats has all the active VDEVs of other PDEVs as well, 5651d5c65159SKalle Valo * ignoring those not part of requested PDEV 5652d5c65159SKalle Valo */ 5653d5c65159SKalle Valo if (!arvif) 5654d5c65159SKalle Valo return; 5655d5c65159SKalle Valo 5656d5c65159SKalle Valo vif_macaddr = arvif->vif->addr; 5657d5c65159SKalle Valo 5658d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5659d5c65159SKalle Valo "VDEV ID", vdev->vdev_id); 5660d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", 5661d5c65159SKalle Valo "VDEV MAC address", vif_macaddr); 5662d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5663d5c65159SKalle Valo "beacon snr", vdev->beacon_snr); 5664d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5665d5c65159SKalle Valo "data snr", vdev->data_snr); 5666d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5667d5c65159SKalle Valo "num rx frames", vdev->num_rx_frames); 5668d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5669d5c65159SKalle Valo "num rts fail", vdev->num_rts_fail); 5670d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5671d5c65159SKalle Valo "num rts success", vdev->num_rts_success); 5672d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5673d5c65159SKalle Valo "num rx err", vdev->num_rx_err); 5674d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5675d5c65159SKalle Valo "num rx discard", vdev->num_rx_discard); 5676d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5677d5c65159SKalle Valo "num tx not acked", vdev->num_tx_not_acked); 5678d5c65159SKalle Valo 5679d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++) 5680d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, 5681d5c65159SKalle Valo "%25s [%02d] %u\n", 5682d5c65159SKalle Valo "num tx frames", i, 5683d5c65159SKalle Valo vdev->num_tx_frames[i]); 5684d5c65159SKalle Valo 5685d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++) 5686d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, 5687d5c65159SKalle Valo "%25s [%02d] %u\n", 5688d5c65159SKalle Valo "num tx frames retries", i, 5689d5c65159SKalle Valo vdev->num_tx_frames_retries[i]); 5690d5c65159SKalle Valo 5691d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++) 5692d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, 5693d5c65159SKalle Valo "%25s [%02d] %u\n", 5694d5c65159SKalle Valo "num tx frames failures", i, 5695d5c65159SKalle Valo vdev->num_tx_frames_failures[i]); 5696d5c65159SKalle Valo 5697d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++) 5698d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, 5699d5c65159SKalle Valo "%25s [%02d] 0x%08x\n", 5700d5c65159SKalle Valo "tx rate history", i, 5701d5c65159SKalle Valo vdev->tx_rate_history[i]); 5702d5c65159SKalle Valo 5703d5c65159SKalle Valo for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++) 5704d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, 5705d5c65159SKalle Valo "%25s [%02d] %u\n", 5706d5c65159SKalle Valo "beacon rssi history", i, 5707d5c65159SKalle Valo vdev->beacon_rssi_history[i]); 5708d5c65159SKalle Valo 5709d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n"); 5710d5c65159SKalle Valo *length = len; 5711d5c65159SKalle Valo } 5712d5c65159SKalle Valo 5713d5c65159SKalle Valo static void 5714d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(struct ath11k *ar, 5715d5c65159SKalle Valo const struct ath11k_fw_stats_bcn *bcn, 5716d5c65159SKalle Valo char *buf, u32 *length) 5717d5c65159SKalle Valo { 5718d5c65159SKalle Valo u32 len = *length; 5719d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5720d5c65159SKalle Valo struct ath11k_vif *arvif = ath11k_mac_get_arvif(ar, bcn->vdev_id); 5721d5c65159SKalle Valo u8 *vdev_macaddr; 5722d5c65159SKalle Valo 5723d5c65159SKalle Valo if (!arvif) { 5724d5c65159SKalle Valo ath11k_warn(ar->ab, "invalid vdev id %d in bcn stats", 5725d5c65159SKalle Valo bcn->vdev_id); 5726d5c65159SKalle Valo return; 5727d5c65159SKalle Valo } 5728d5c65159SKalle Valo 5729d5c65159SKalle Valo vdev_macaddr = arvif->vif->addr; 5730d5c65159SKalle Valo 5731d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5732d5c65159SKalle Valo "VDEV ID", bcn->vdev_id); 5733d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %pM\n", 5734d5c65159SKalle Valo "VDEV MAC address", vdev_macaddr); 5735d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5736d5c65159SKalle Valo "================"); 5737d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5738d5c65159SKalle Valo "Num of beacon tx success", bcn->tx_bcn_succ_cnt); 5739d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s %u\n", 5740d5c65159SKalle Valo "Num of beacon tx failures", bcn->tx_bcn_outage_cnt); 5741d5c65159SKalle Valo 5742d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n"); 5743d5c65159SKalle Valo *length = len; 5744d5c65159SKalle Valo } 5745d5c65159SKalle Valo 5746d5c65159SKalle Valo void ath11k_wmi_fw_stats_fill(struct ath11k *ar, 5747d5c65159SKalle Valo struct ath11k_fw_stats *fw_stats, 5748d5c65159SKalle Valo u32 stats_id, char *buf) 5749d5c65159SKalle Valo { 5750d5c65159SKalle Valo u32 len = 0; 5751d5c65159SKalle Valo u32 buf_len = ATH11K_FW_STATS_BUF_SIZE; 5752d5c65159SKalle Valo const struct ath11k_fw_stats_pdev *pdev; 5753d5c65159SKalle Valo const struct ath11k_fw_stats_vdev *vdev; 5754d5c65159SKalle Valo const struct ath11k_fw_stats_bcn *bcn; 5755d5c65159SKalle Valo size_t num_bcn; 5756d5c65159SKalle Valo 5757d5c65159SKalle Valo spin_lock_bh(&ar->data_lock); 5758d5c65159SKalle Valo 5759d5c65159SKalle Valo if (stats_id == WMI_REQUEST_PDEV_STAT) { 5760d5c65159SKalle Valo pdev = list_first_entry_or_null(&fw_stats->pdevs, 5761d5c65159SKalle Valo struct ath11k_fw_stats_pdev, list); 5762d5c65159SKalle Valo if (!pdev) { 5763d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to get pdev stats\n"); 5764d5c65159SKalle Valo goto unlock; 5765d5c65159SKalle Valo } 5766d5c65159SKalle Valo 5767d5c65159SKalle Valo ath11k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len); 5768d5c65159SKalle Valo ath11k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len); 5769d5c65159SKalle Valo ath11k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len); 5770d5c65159SKalle Valo } 5771d5c65159SKalle Valo 5772d5c65159SKalle Valo if (stats_id == WMI_REQUEST_VDEV_STAT) { 5773d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n"); 5774d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n", 5775d5c65159SKalle Valo "ath11k VDEV stats"); 5776d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5777d5c65159SKalle Valo "================="); 5778d5c65159SKalle Valo 5779d5c65159SKalle Valo list_for_each_entry(vdev, &fw_stats->vdevs, list) 5780d5c65159SKalle Valo ath11k_wmi_fw_vdev_stats_fill(ar, vdev, buf, &len); 5781d5c65159SKalle Valo } 5782d5c65159SKalle Valo 5783d5c65159SKalle Valo if (stats_id == WMI_REQUEST_BCN_STAT) { 5784d5c65159SKalle Valo num_bcn = ath11k_wmi_fw_stats_num_bcn(&fw_stats->bcn); 5785d5c65159SKalle Valo 5786d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "\n"); 5787d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n", 5788d5c65159SKalle Valo "ath11k Beacon stats", num_bcn); 5789d5c65159SKalle Valo len += scnprintf(buf + len, buf_len - len, "%30s\n\n", 5790d5c65159SKalle Valo "==================="); 5791d5c65159SKalle Valo 5792d5c65159SKalle Valo list_for_each_entry(bcn, &fw_stats->bcn, list) 5793d5c65159SKalle Valo ath11k_wmi_fw_bcn_stats_fill(ar, bcn, buf, &len); 5794d5c65159SKalle Valo } 5795d5c65159SKalle Valo 5796d5c65159SKalle Valo unlock: 5797d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock); 5798d5c65159SKalle Valo 5799d5c65159SKalle Valo if (len >= buf_len) 5800d5c65159SKalle Valo buf[len - 1] = 0; 5801d5c65159SKalle Valo else 5802d5c65159SKalle Valo buf[len] = 0; 5803d5c65159SKalle Valo } 5804d5c65159SKalle Valo 5805d5c65159SKalle Valo static void ath11k_wmi_op_ep_tx_credits(struct ath11k_base *ab) 5806d5c65159SKalle Valo { 5807d5c65159SKalle Valo /* try to send pending beacons first. they take priority */ 58086bc9d6f7SJohn Crispin wake_up(&ab->wmi_ab.tx_credits_wq); 5809d5c65159SKalle Valo } 5810d5c65159SKalle Valo 5811d5c65159SKalle Valo static void ath11k_wmi_htc_tx_complete(struct ath11k_base *ab, 5812d5c65159SKalle Valo struct sk_buff *skb) 5813d5c65159SKalle Valo { 5814d5c65159SKalle Valo dev_kfree_skb(skb); 5815d5c65159SKalle Valo } 5816d5c65159SKalle Valo 5817d5c65159SKalle Valo static bool ath11k_reg_is_world_alpha(char *alpha) 5818d5c65159SKalle Valo { 5819d5c65159SKalle Valo return alpha[0] == '0' && alpha[1] == '0'; 5820d5c65159SKalle Valo } 5821d5c65159SKalle Valo 5822d5c65159SKalle Valo static int ath11k_reg_chan_list_event(struct ath11k_base *ab, struct sk_buff *skb) 5823d5c65159SKalle Valo { 5824d5c65159SKalle Valo struct cur_regulatory_info *reg_info = NULL; 5825d5c65159SKalle Valo struct ieee80211_regdomain *regd = NULL; 5826d5c65159SKalle Valo bool intersect = false; 5827d5c65159SKalle Valo int ret = 0, pdev_idx; 5828d5c65159SKalle Valo struct ath11k *ar; 5829d5c65159SKalle Valo 5830d5c65159SKalle Valo reg_info = kzalloc(sizeof(*reg_info), GFP_ATOMIC); 5831d5c65159SKalle Valo if (!reg_info) { 5832d5c65159SKalle Valo ret = -ENOMEM; 5833d5c65159SKalle Valo goto fallback; 5834d5c65159SKalle Valo } 5835d5c65159SKalle Valo 5836d5c65159SKalle Valo ret = ath11k_pull_reg_chan_list_update_ev(ab, skb, reg_info); 5837d5c65159SKalle Valo if (ret) { 5838d5c65159SKalle Valo ath11k_warn(ab, "failed to extract regulatory info from received event\n"); 5839d5c65159SKalle Valo goto fallback; 5840d5c65159SKalle Valo } 5841d5c65159SKalle Valo 5842d5c65159SKalle Valo if (reg_info->status_code != REG_SET_CC_STATUS_PASS) { 5843d5c65159SKalle Valo /* In case of failure to set the requested ctry, 5844d5c65159SKalle Valo * fw retains the current regd. We print a failure info 5845d5c65159SKalle Valo * and return from here. 5846d5c65159SKalle Valo */ 5847d5c65159SKalle Valo ath11k_warn(ab, "Failed to set the requested Country regulatory setting\n"); 5848d5c65159SKalle Valo goto mem_free; 5849d5c65159SKalle Valo } 5850d5c65159SKalle Valo 5851d5c65159SKalle Valo pdev_idx = reg_info->phy_id; 5852d5c65159SKalle Valo 585369a0fcf8SSriram R /* Avoid default reg rule updates sent during FW recovery if 585469a0fcf8SSriram R * it is already available 585569a0fcf8SSriram R */ 585669a0fcf8SSriram R spin_lock(&ab->base_lock); 585769a0fcf8SSriram R if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags) && 585869a0fcf8SSriram R ab->default_regd[pdev_idx]) { 585969a0fcf8SSriram R spin_unlock(&ab->base_lock); 586069a0fcf8SSriram R goto mem_free; 586169a0fcf8SSriram R } 586269a0fcf8SSriram R spin_unlock(&ab->base_lock); 586369a0fcf8SSriram R 58645f859bc0SCarl Huang if (pdev_idx >= ab->num_radios) { 586584eee3c8SCarl Huang /* Process the event for phy0 only if single_pdev_only 586684eee3c8SCarl Huang * is true. If pdev_idx is valid but not 0, discard the 586784eee3c8SCarl Huang * event. Otherwise, it goes to fallback. 586884eee3c8SCarl Huang */ 586984eee3c8SCarl Huang if (ab->hw_params.single_pdev_only && 587084eee3c8SCarl Huang pdev_idx < ab->hw_params.num_rxmda_per_pdev) 58715f859bc0SCarl Huang goto mem_free; 58725f859bc0SCarl Huang else 5873d5c65159SKalle Valo goto fallback; 58745f859bc0SCarl Huang } 5875d5c65159SKalle Valo 5876d5c65159SKalle Valo /* Avoid multiple overwrites to default regd, during core 5877d5c65159SKalle Valo * stop-start after mac registration. 5878d5c65159SKalle Valo */ 5879d5c65159SKalle Valo if (ab->default_regd[pdev_idx] && !ab->new_regd[pdev_idx] && 5880d5c65159SKalle Valo !memcmp((char *)ab->default_regd[pdev_idx]->alpha2, 5881d5c65159SKalle Valo (char *)reg_info->alpha2, 2)) 5882b5316db2SColin Ian King goto mem_free; 5883d5c65159SKalle Valo 5884d5c65159SKalle Valo /* Intersect new rules with default regd if a new country setting was 5885d5c65159SKalle Valo * requested, i.e a default regd was already set during initialization 5886d5c65159SKalle Valo * and the regd coming from this event has a valid country info. 5887d5c65159SKalle Valo */ 5888d5c65159SKalle Valo if (ab->default_regd[pdev_idx] && 5889d5c65159SKalle Valo !ath11k_reg_is_world_alpha((char *) 5890d5c65159SKalle Valo ab->default_regd[pdev_idx]->alpha2) && 5891d5c65159SKalle Valo !ath11k_reg_is_world_alpha((char *)reg_info->alpha2)) 5892d5c65159SKalle Valo intersect = true; 5893d5c65159SKalle Valo 5894d5c65159SKalle Valo regd = ath11k_reg_build_regd(ab, reg_info, intersect); 5895d5c65159SKalle Valo if (!regd) { 5896d5c65159SKalle Valo ath11k_warn(ab, "failed to build regd from reg_info\n"); 5897d5c65159SKalle Valo goto fallback; 5898d5c65159SKalle Valo } 5899d5c65159SKalle Valo 5900d5c65159SKalle Valo spin_lock(&ab->base_lock); 59011db2b0d0SSriram R if (ab->default_regd[pdev_idx]) { 59021db2b0d0SSriram R /* The initial rules from FW after WMI Init is to build 59031db2b0d0SSriram R * the default regd. From then on, any rules updated for 59041db2b0d0SSriram R * the pdev could be due to user reg changes. 5905d5c65159SKalle Valo * Free previously built regd before assigning the newly 5906d5c65159SKalle Valo * generated regd to ar. NULL pointer handling will be 5907d5c65159SKalle Valo * taken care by kfree itself. 5908d5c65159SKalle Valo */ 5909d5c65159SKalle Valo ar = ab->pdevs[pdev_idx].ar; 5910d5c65159SKalle Valo kfree(ab->new_regd[pdev_idx]); 5911d5c65159SKalle Valo ab->new_regd[pdev_idx] = regd; 5912d5c65159SKalle Valo ieee80211_queue_work(ar->hw, &ar->regd_update_work); 5913d5c65159SKalle Valo } else { 59141db2b0d0SSriram R /* This regd would be applied during mac registration and is 59151db2b0d0SSriram R * held constant throughout for regd intersection purpose 5916d5c65159SKalle Valo */ 5917d5c65159SKalle Valo ab->default_regd[pdev_idx] = regd; 5918d5c65159SKalle Valo } 5919d5c65159SKalle Valo ab->dfs_region = reg_info->dfs_region; 5920d5c65159SKalle Valo spin_unlock(&ab->base_lock); 5921d5c65159SKalle Valo 5922d5c65159SKalle Valo goto mem_free; 5923d5c65159SKalle Valo 5924d5c65159SKalle Valo fallback: 5925d5c65159SKalle Valo /* Fallback to older reg (by sending previous country setting 5926d5c65159SKalle Valo * again if fw has succeded and we failed to process here. 5927d5c65159SKalle Valo * The Regdomain should be uniform across driver and fw. Since the 5928d5c65159SKalle Valo * FW has processed the command and sent a success status, we expect 5929d5c65159SKalle Valo * this function to succeed as well. If it doesn't, CTRY needs to be 5930d5c65159SKalle Valo * reverted at the fw and the old SCAN_CHAN_LIST cmd needs to be sent. 5931d5c65159SKalle Valo */ 5932d5c65159SKalle Valo /* TODO: This is rare, but still should also be handled */ 5933d5c65159SKalle Valo WARN_ON(1); 5934d5c65159SKalle Valo mem_free: 5935d5c65159SKalle Valo if (reg_info) { 5936d5c65159SKalle Valo kfree(reg_info->reg_rules_2g_ptr); 5937d5c65159SKalle Valo kfree(reg_info->reg_rules_5g_ptr); 5938d5c65159SKalle Valo kfree(reg_info); 5939d5c65159SKalle Valo } 5940d5c65159SKalle Valo return ret; 5941d5c65159SKalle Valo } 5942d5c65159SKalle Valo 5943d5c65159SKalle Valo static int ath11k_wmi_tlv_rdy_parse(struct ath11k_base *ab, u16 tag, u16 len, 5944d5c65159SKalle Valo const void *ptr, void *data) 5945d5c65159SKalle Valo { 5946d5c65159SKalle Valo struct wmi_tlv_rdy_parse *rdy_parse = data; 594721c1b063SMaharaja Kennadyrajan struct wmi_ready_event fixed_param; 5948d5c65159SKalle Valo struct wmi_mac_addr *addr_list; 5949d5c65159SKalle Valo struct ath11k_pdev *pdev; 5950d5c65159SKalle Valo u32 num_mac_addr; 5951d5c65159SKalle Valo int i; 5952d5c65159SKalle Valo 5953d5c65159SKalle Valo switch (tag) { 5954d5c65159SKalle Valo case WMI_TAG_READY_EVENT: 595521c1b063SMaharaja Kennadyrajan memset(&fixed_param, 0, sizeof(fixed_param)); 595621c1b063SMaharaja Kennadyrajan memcpy(&fixed_param, (struct wmi_ready_event *)ptr, 595721c1b063SMaharaja Kennadyrajan min_t(u16, sizeof(fixed_param), len)); 595821c1b063SMaharaja Kennadyrajan ab->wlan_init_status = fixed_param.ready_event_min.status; 595921c1b063SMaharaja Kennadyrajan rdy_parse->num_extra_mac_addr = 596021c1b063SMaharaja Kennadyrajan fixed_param.ready_event_min.num_extra_mac_addr; 5961d5c65159SKalle Valo 596221c1b063SMaharaja Kennadyrajan ether_addr_copy(ab->mac_addr, 596321c1b063SMaharaja Kennadyrajan fixed_param.ready_event_min.mac_addr.addr); 596421c1b063SMaharaja Kennadyrajan ab->pktlog_defs_checksum = fixed_param.pktlog_defs_checksum; 5965d5c65159SKalle Valo ab->wmi_ready = true; 5966d5c65159SKalle Valo break; 5967d5c65159SKalle Valo case WMI_TAG_ARRAY_FIXED_STRUCT: 5968d5c65159SKalle Valo addr_list = (struct wmi_mac_addr *)ptr; 5969d5c65159SKalle Valo num_mac_addr = rdy_parse->num_extra_mac_addr; 5970d5c65159SKalle Valo 5971d5c65159SKalle Valo if (!(ab->num_radios > 1 && num_mac_addr >= ab->num_radios)) 5972d5c65159SKalle Valo break; 5973d5c65159SKalle Valo 5974d5c65159SKalle Valo for (i = 0; i < ab->num_radios; i++) { 5975d5c65159SKalle Valo pdev = &ab->pdevs[i]; 5976d5c65159SKalle Valo ether_addr_copy(pdev->mac_addr, addr_list[i].addr); 5977d5c65159SKalle Valo } 5978d5c65159SKalle Valo ab->pdevs_macaddr_valid = true; 5979d5c65159SKalle Valo break; 5980d5c65159SKalle Valo default: 5981d5c65159SKalle Valo break; 5982d5c65159SKalle Valo } 5983d5c65159SKalle Valo 5984d5c65159SKalle Valo return 0; 5985d5c65159SKalle Valo } 5986d5c65159SKalle Valo 5987d5c65159SKalle Valo static int ath11k_ready_event(struct ath11k_base *ab, struct sk_buff *skb) 5988d5c65159SKalle Valo { 5989d5c65159SKalle Valo struct wmi_tlv_rdy_parse rdy_parse = { }; 5990d5c65159SKalle Valo int ret; 5991d5c65159SKalle Valo 5992d5c65159SKalle Valo ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 5993d5c65159SKalle Valo ath11k_wmi_tlv_rdy_parse, &rdy_parse); 5994d5c65159SKalle Valo if (ret) { 5995d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv %d\n", ret); 5996d5c65159SKalle Valo return ret; 5997d5c65159SKalle Valo } 5998d5c65159SKalle Valo 59996bc9d6f7SJohn Crispin complete(&ab->wmi_ab.unified_ready); 6000d5c65159SKalle Valo return 0; 6001d5c65159SKalle Valo } 6002d5c65159SKalle Valo 6003d5c65159SKalle Valo static void ath11k_peer_delete_resp_event(struct ath11k_base *ab, struct sk_buff *skb) 6004d5c65159SKalle Valo { 6005d5c65159SKalle Valo struct wmi_peer_delete_resp_event peer_del_resp; 6006690ace20SRitesh Singh struct ath11k *ar; 6007d5c65159SKalle Valo 6008d5c65159SKalle Valo if (ath11k_pull_peer_del_resp_ev(ab, skb, &peer_del_resp) != 0) { 6009d5c65159SKalle Valo ath11k_warn(ab, "failed to extract peer delete resp"); 6010d5c65159SKalle Valo return; 6011d5c65159SKalle Valo } 6012d5c65159SKalle Valo 6013690ace20SRitesh Singh rcu_read_lock(); 6014690ace20SRitesh Singh ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_del_resp.vdev_id); 6015690ace20SRitesh Singh if (!ar) { 6016690ace20SRitesh Singh ath11k_warn(ab, "invalid vdev id in peer delete resp ev %d", 6017690ace20SRitesh Singh peer_del_resp.vdev_id); 6018690ace20SRitesh Singh rcu_read_unlock(); 6019690ace20SRitesh Singh return; 6020690ace20SRitesh Singh } 6021690ace20SRitesh Singh 6022690ace20SRitesh Singh complete(&ar->peer_delete_done); 6023690ace20SRitesh Singh rcu_read_unlock(); 6024690ace20SRitesh Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "peer delete resp for vdev id %d addr %pM\n", 6025690ace20SRitesh Singh peer_del_resp.vdev_id, peer_del_resp.peer_macaddr.addr); 6026d5c65159SKalle Valo } 6027d5c65159SKalle Valo 60283cbbdfbeSRitesh Singh static void ath11k_vdev_delete_resp_event(struct ath11k_base *ab, 60293cbbdfbeSRitesh Singh struct sk_buff *skb) 60303cbbdfbeSRitesh Singh { 60313cbbdfbeSRitesh Singh struct ath11k *ar; 60323cbbdfbeSRitesh Singh u32 vdev_id = 0; 60333cbbdfbeSRitesh Singh 60343cbbdfbeSRitesh Singh if (ath11k_pull_vdev_del_resp_ev(ab, skb, &vdev_id) != 0) { 60353cbbdfbeSRitesh Singh ath11k_warn(ab, "failed to extract vdev delete resp"); 60363cbbdfbeSRitesh Singh return; 60373cbbdfbeSRitesh Singh } 60383cbbdfbeSRitesh Singh 60393cbbdfbeSRitesh Singh rcu_read_lock(); 60403cbbdfbeSRitesh Singh ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id); 60413cbbdfbeSRitesh Singh if (!ar) { 60423cbbdfbeSRitesh Singh ath11k_warn(ab, "invalid vdev id in vdev delete resp ev %d", 60433cbbdfbeSRitesh Singh vdev_id); 60443cbbdfbeSRitesh Singh rcu_read_unlock(); 60453cbbdfbeSRitesh Singh return; 60463cbbdfbeSRitesh Singh } 60473cbbdfbeSRitesh Singh 60483cbbdfbeSRitesh Singh complete(&ar->vdev_delete_done); 60493cbbdfbeSRitesh Singh 60503cbbdfbeSRitesh Singh rcu_read_unlock(); 60513cbbdfbeSRitesh Singh 60523cbbdfbeSRitesh Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev delete resp for vdev id %d\n", 60533cbbdfbeSRitesh Singh vdev_id); 60543cbbdfbeSRitesh Singh } 60553cbbdfbeSRitesh Singh 6056d5c65159SKalle Valo static inline const char *ath11k_wmi_vdev_resp_print(u32 vdev_resp_status) 6057d5c65159SKalle Valo { 6058d5c65159SKalle Valo switch (vdev_resp_status) { 6059d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_INVALID_VDEVID: 6060d5c65159SKalle Valo return "invalid vdev id"; 6061d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_NOT_SUPPORTED: 6062d5c65159SKalle Valo return "not supported"; 6063d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_DFS_VIOLATION: 6064d5c65159SKalle Valo return "dfs violation"; 6065d5c65159SKalle Valo case WMI_VDEV_START_RESPONSE_INVALID_REGDOMAIN: 6066d5c65159SKalle Valo return "invalid regdomain"; 6067d5c65159SKalle Valo default: 6068d5c65159SKalle Valo return "unknown"; 6069d5c65159SKalle Valo } 6070d5c65159SKalle Valo } 6071d5c65159SKalle Valo 6072d5c65159SKalle Valo static void ath11k_vdev_start_resp_event(struct ath11k_base *ab, struct sk_buff *skb) 6073d5c65159SKalle Valo { 6074d5c65159SKalle Valo struct wmi_vdev_start_resp_event vdev_start_resp; 6075d5c65159SKalle Valo struct ath11k *ar; 6076d5c65159SKalle Valo u32 status; 6077d5c65159SKalle Valo 6078d5c65159SKalle Valo if (ath11k_pull_vdev_start_resp_tlv(ab, skb, &vdev_start_resp) != 0) { 6079d5c65159SKalle Valo ath11k_warn(ab, "failed to extract vdev start resp"); 6080d5c65159SKalle Valo return; 6081d5c65159SKalle Valo } 6082d5c65159SKalle Valo 6083d5c65159SKalle Valo rcu_read_lock(); 6084d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_start_resp.vdev_id); 6085d5c65159SKalle Valo if (!ar) { 6086d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in vdev start resp ev %d", 6087d5c65159SKalle Valo vdev_start_resp.vdev_id); 6088d5c65159SKalle Valo rcu_read_unlock(); 6089d5c65159SKalle Valo return; 6090d5c65159SKalle Valo } 6091d5c65159SKalle Valo 6092d5c65159SKalle Valo ar->last_wmi_vdev_start_status = 0; 6093d5c65159SKalle Valo 6094d5c65159SKalle Valo status = vdev_start_resp.status; 6095d5c65159SKalle Valo 6096d5c65159SKalle Valo if (WARN_ON_ONCE(status)) { 6097d5c65159SKalle Valo ath11k_warn(ab, "vdev start resp error status %d (%s)\n", 6098d5c65159SKalle Valo status, ath11k_wmi_vdev_resp_print(status)); 6099d5c65159SKalle Valo ar->last_wmi_vdev_start_status = status; 6100d5c65159SKalle Valo } 6101d5c65159SKalle Valo 6102d5c65159SKalle Valo complete(&ar->vdev_setup_done); 6103d5c65159SKalle Valo 6104d5c65159SKalle Valo rcu_read_unlock(); 6105d5c65159SKalle Valo 6106d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev start resp for vdev id %d", 6107d5c65159SKalle Valo vdev_start_resp.vdev_id); 6108d5c65159SKalle Valo } 6109d5c65159SKalle Valo 6110d5c65159SKalle Valo static void ath11k_bcn_tx_status_event(struct ath11k_base *ab, struct sk_buff *skb) 6111d5c65159SKalle Valo { 6112d5c65159SKalle Valo u32 vdev_id, tx_status; 6113d5c65159SKalle Valo 6114d5c65159SKalle Valo if (ath11k_pull_bcn_tx_status_ev(ab, skb->data, skb->len, 6115d5c65159SKalle Valo &vdev_id, &tx_status) != 0) { 6116d5c65159SKalle Valo ath11k_warn(ab, "failed to extract bcn tx status"); 6117d5c65159SKalle Valo return; 6118d5c65159SKalle Valo } 6119d5c65159SKalle Valo } 6120d5c65159SKalle Valo 6121d5c65159SKalle Valo static void ath11k_vdev_stopped_event(struct ath11k_base *ab, struct sk_buff *skb) 6122d5c65159SKalle Valo { 6123d5c65159SKalle Valo struct ath11k *ar; 6124d5c65159SKalle Valo u32 vdev_id = 0; 6125d5c65159SKalle Valo 6126d5c65159SKalle Valo if (ath11k_pull_vdev_stopped_param_tlv(ab, skb, &vdev_id) != 0) { 6127d5c65159SKalle Valo ath11k_warn(ab, "failed to extract vdev stopped event"); 6128d5c65159SKalle Valo return; 6129d5c65159SKalle Valo } 6130d5c65159SKalle Valo 6131d5c65159SKalle Valo rcu_read_lock(); 6132fae0385bSRitesh Singh ar = ath11k_mac_get_ar_by_vdev_id(ab, vdev_id); 6133d5c65159SKalle Valo if (!ar) { 6134d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in vdev stopped ev %d", 6135d5c65159SKalle Valo vdev_id); 6136d5c65159SKalle Valo rcu_read_unlock(); 6137d5c65159SKalle Valo return; 6138d5c65159SKalle Valo } 6139d5c65159SKalle Valo 6140d5c65159SKalle Valo complete(&ar->vdev_setup_done); 6141d5c65159SKalle Valo 6142d5c65159SKalle Valo rcu_read_unlock(); 6143d5c65159SKalle Valo 6144d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "vdev stopped for vdev id %d", vdev_id); 6145d5c65159SKalle Valo } 6146d5c65159SKalle Valo 6147d5c65159SKalle Valo static void ath11k_mgmt_rx_event(struct ath11k_base *ab, struct sk_buff *skb) 6148d5c65159SKalle Valo { 6149d5c65159SKalle Valo struct mgmt_rx_event_params rx_ev = {0}; 6150d5c65159SKalle Valo struct ath11k *ar; 6151d5c65159SKalle Valo struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 6152d5c65159SKalle Valo struct ieee80211_hdr *hdr; 6153d5c65159SKalle Valo u16 fc; 6154d5c65159SKalle Valo struct ieee80211_supported_band *sband; 6155d5c65159SKalle Valo 6156d5c65159SKalle Valo if (ath11k_pull_mgmt_rx_params_tlv(ab, skb, &rx_ev) != 0) { 6157d5c65159SKalle Valo ath11k_warn(ab, "failed to extract mgmt rx event"); 6158d5c65159SKalle Valo dev_kfree_skb(skb); 6159d5c65159SKalle Valo return; 6160d5c65159SKalle Valo } 6161d5c65159SKalle Valo 6162d5c65159SKalle Valo memset(status, 0, sizeof(*status)); 6163d5c65159SKalle Valo 6164d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT, "mgmt rx event status %08x\n", 6165d5c65159SKalle Valo rx_ev.status); 6166d5c65159SKalle Valo 6167d5c65159SKalle Valo rcu_read_lock(); 6168d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, rx_ev.pdev_id); 6169d5c65159SKalle Valo 6170d5c65159SKalle Valo if (!ar) { 6171d5c65159SKalle Valo ath11k_warn(ab, "invalid pdev_id %d in mgmt_rx_event\n", 6172d5c65159SKalle Valo rx_ev.pdev_id); 6173d5c65159SKalle Valo dev_kfree_skb(skb); 6174d5c65159SKalle Valo goto exit; 6175d5c65159SKalle Valo } 6176d5c65159SKalle Valo 6177d5c65159SKalle Valo if ((test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) || 6178d5c65159SKalle Valo (rx_ev.status & (WMI_RX_STATUS_ERR_DECRYPT | 6179d5c65159SKalle Valo WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) { 6180d5c65159SKalle Valo dev_kfree_skb(skb); 6181d5c65159SKalle Valo goto exit; 6182d5c65159SKalle Valo } 6183d5c65159SKalle Valo 6184d5c65159SKalle Valo if (rx_ev.status & WMI_RX_STATUS_ERR_MIC) 6185d5c65159SKalle Valo status->flag |= RX_FLAG_MMIC_ERROR; 6186d5c65159SKalle Valo 61875dcf42f8SPradeep Kumar Chitrapu if (rx_ev.chan_freq >= ATH11K_MIN_6G_FREQ) { 61885dcf42f8SPradeep Kumar Chitrapu status->band = NL80211_BAND_6GHZ; 61895dcf42f8SPradeep Kumar Chitrapu } else if (rx_ev.channel >= 1 && rx_ev.channel <= 14) { 6190d5c65159SKalle Valo status->band = NL80211_BAND_2GHZ; 6191d5c65159SKalle Valo } else if (rx_ev.channel >= 36 && rx_ev.channel <= ATH11K_MAX_5G_CHAN) { 6192d5c65159SKalle Valo status->band = NL80211_BAND_5GHZ; 6193d5c65159SKalle Valo } else { 6194d5c65159SKalle Valo /* Shouldn't happen unless list of advertised channels to 6195d5c65159SKalle Valo * mac80211 has been changed. 6196d5c65159SKalle Valo */ 6197d5c65159SKalle Valo WARN_ON_ONCE(1); 6198d5c65159SKalle Valo dev_kfree_skb(skb); 6199d5c65159SKalle Valo goto exit; 6200d5c65159SKalle Valo } 6201d5c65159SKalle Valo 620222eeadcdSPradeep Kumar Chitrapu if (rx_ev.phy_mode == MODE_11B && 620322eeadcdSPradeep Kumar Chitrapu (status->band == NL80211_BAND_5GHZ || status->band == NL80211_BAND_6GHZ)) 6204d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 620522eeadcdSPradeep Kumar Chitrapu "wmi mgmt rx 11b (CCK) on 5/6GHz, band = %d\n", status->band); 6206d5c65159SKalle Valo 6207d5c65159SKalle Valo sband = &ar->mac.sbands[status->band]; 6208d5c65159SKalle Valo 6209d5c65159SKalle Valo status->freq = ieee80211_channel_to_frequency(rx_ev.channel, 6210d5c65159SKalle Valo status->band); 6211d5c65159SKalle Valo status->signal = rx_ev.snr + ATH11K_DEFAULT_NOISE_FLOOR; 6212d5c65159SKalle Valo status->rate_idx = ath11k_mac_bitrate_to_idx(sband, rx_ev.rate / 100); 6213d5c65159SKalle Valo 6214d5c65159SKalle Valo hdr = (struct ieee80211_hdr *)skb->data; 6215d5c65159SKalle Valo fc = le16_to_cpu(hdr->frame_control); 6216d5c65159SKalle Valo 6217d5c65159SKalle Valo /* Firmware is guaranteed to report all essential management frames via 6218d5c65159SKalle Valo * WMI while it can deliver some extra via HTT. Since there can be 6219d5c65159SKalle Valo * duplicates split the reporting wrt monitor/sniffing. 6220d5c65159SKalle Valo */ 6221d5c65159SKalle Valo status->flag |= RX_FLAG_SKIP_MONITOR; 6222d5c65159SKalle Valo 6223d5c65159SKalle Valo /* In case of PMF, FW delivers decrypted frames with Protected Bit set. 6224d5c65159SKalle Valo * Don't clear that. Also, FW delivers broadcast management frames 6225d5c65159SKalle Valo * (ex: group privacy action frames in mesh) as encrypted payload. 6226d5c65159SKalle Valo */ 6227d5c65159SKalle Valo if (ieee80211_has_protected(hdr->frame_control) && 6228d5c65159SKalle Valo !is_multicast_ether_addr(ieee80211_get_DA(hdr))) { 6229d5c65159SKalle Valo status->flag |= RX_FLAG_DECRYPTED; 6230d5c65159SKalle Valo 6231d5c65159SKalle Valo if (!ieee80211_is_robust_mgmt_frame(skb)) { 6232d5c65159SKalle Valo status->flag |= RX_FLAG_IV_STRIPPED | 6233d5c65159SKalle Valo RX_FLAG_MMIC_STRIPPED; 6234d5c65159SKalle Valo hdr->frame_control = __cpu_to_le16(fc & 6235d5c65159SKalle Valo ~IEEE80211_FCTL_PROTECTED); 6236d5c65159SKalle Valo } 6237d5c65159SKalle Valo } 6238d5c65159SKalle Valo 623926f69792SLavanya Suresh if (ieee80211_is_beacon(hdr->frame_control)) 624026f69792SLavanya Suresh ath11k_mac_handle_beacon(ar, skb); 6241d5c65159SKalle Valo 6242d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT, 6243d5c65159SKalle Valo "event mgmt rx skb %pK len %d ftype %02x stype %02x\n", 6244d5c65159SKalle Valo skb, skb->len, 6245d5c65159SKalle Valo fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE); 6246d5c65159SKalle Valo 6247d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT, 6248d5c65159SKalle Valo "event mgmt rx freq %d band %d snr %d, rate_idx %d\n", 6249d5c65159SKalle Valo status->freq, status->band, status->signal, 6250d5c65159SKalle Valo status->rate_idx); 6251d5c65159SKalle Valo 6252d5c65159SKalle Valo ieee80211_rx_ni(ar->hw, skb); 6253d5c65159SKalle Valo 6254d5c65159SKalle Valo exit: 6255d5c65159SKalle Valo rcu_read_unlock(); 6256d5c65159SKalle Valo } 6257d5c65159SKalle Valo 6258d5c65159SKalle Valo static void ath11k_mgmt_tx_compl_event(struct ath11k_base *ab, struct sk_buff *skb) 6259d5c65159SKalle Valo { 6260d5c65159SKalle Valo struct wmi_mgmt_tx_compl_event tx_compl_param = {0}; 6261d5c65159SKalle Valo struct ath11k *ar; 6262d5c65159SKalle Valo 6263d5c65159SKalle Valo if (ath11k_pull_mgmt_tx_compl_param_tlv(ab, skb, &tx_compl_param) != 0) { 6264d5c65159SKalle Valo ath11k_warn(ab, "failed to extract mgmt tx compl event"); 6265d5c65159SKalle Valo return; 6266d5c65159SKalle Valo } 6267d5c65159SKalle Valo 6268d5c65159SKalle Valo rcu_read_lock(); 6269d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, tx_compl_param.pdev_id); 6270d5c65159SKalle Valo if (!ar) { 6271d5c65159SKalle Valo ath11k_warn(ab, "invalid pdev id %d in mgmt_tx_compl_event\n", 6272d5c65159SKalle Valo tx_compl_param.pdev_id); 6273d5c65159SKalle Valo goto exit; 6274d5c65159SKalle Valo } 6275d5c65159SKalle Valo 6276d5c65159SKalle Valo wmi_process_mgmt_tx_comp(ar, tx_compl_param.desc_id, 6277d5c65159SKalle Valo tx_compl_param.status); 6278d5c65159SKalle Valo 6279d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_MGMT, 6280d5c65159SKalle Valo "mgmt tx compl ev pdev_id %d, desc_id %d, status %d", 6281d5c65159SKalle Valo tx_compl_param.pdev_id, tx_compl_param.desc_id, 6282d5c65159SKalle Valo tx_compl_param.status); 6283d5c65159SKalle Valo 6284d5c65159SKalle Valo exit: 6285d5c65159SKalle Valo rcu_read_unlock(); 6286d5c65159SKalle Valo } 6287d5c65159SKalle Valo 6288d5c65159SKalle Valo static struct ath11k *ath11k_get_ar_on_scan_abort(struct ath11k_base *ab, 6289d5c65159SKalle Valo u32 vdev_id) 6290d5c65159SKalle Valo { 6291d5c65159SKalle Valo int i; 6292d5c65159SKalle Valo struct ath11k_pdev *pdev; 6293d5c65159SKalle Valo struct ath11k *ar; 6294d5c65159SKalle Valo 6295d5c65159SKalle Valo for (i = 0; i < ab->num_radios; i++) { 6296d5c65159SKalle Valo pdev = rcu_dereference(ab->pdevs_active[i]); 6297d5c65159SKalle Valo if (pdev && pdev->ar) { 6298d5c65159SKalle Valo ar = pdev->ar; 6299d5c65159SKalle Valo 6300d5c65159SKalle Valo spin_lock_bh(&ar->data_lock); 6301d5c65159SKalle Valo if (ar->scan.state == ATH11K_SCAN_ABORTING && 6302d5c65159SKalle Valo ar->scan.vdev_id == vdev_id) { 6303d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock); 6304d5c65159SKalle Valo return ar; 6305d5c65159SKalle Valo } 6306d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock); 6307d5c65159SKalle Valo } 6308d5c65159SKalle Valo } 6309d5c65159SKalle Valo return NULL; 6310d5c65159SKalle Valo } 6311d5c65159SKalle Valo 6312d5c65159SKalle Valo static void ath11k_scan_event(struct ath11k_base *ab, struct sk_buff *skb) 6313d5c65159SKalle Valo { 6314d5c65159SKalle Valo struct ath11k *ar; 6315d5c65159SKalle Valo struct wmi_scan_event scan_ev = {0}; 6316d5c65159SKalle Valo 6317d5c65159SKalle Valo if (ath11k_pull_scan_ev(ab, skb, &scan_ev) != 0) { 6318d5c65159SKalle Valo ath11k_warn(ab, "failed to extract scan event"); 6319d5c65159SKalle Valo return; 6320d5c65159SKalle Valo } 6321d5c65159SKalle Valo 6322d5c65159SKalle Valo rcu_read_lock(); 6323d5c65159SKalle Valo 6324d5c65159SKalle Valo /* In case the scan was cancelled, ex. during interface teardown, 6325d5c65159SKalle Valo * the interface will not be found in active interfaces. 6326d5c65159SKalle Valo * Rather, in such scenarios, iterate over the active pdev's to 6327d5c65159SKalle Valo * search 'ar' if the corresponding 'ar' scan is ABORTING and the 6328d5c65159SKalle Valo * aborting scan's vdev id matches this event info. 6329d5c65159SKalle Valo */ 6330d5c65159SKalle Valo if (scan_ev.event_type == WMI_SCAN_EVENT_COMPLETED && 6331d5c65159SKalle Valo scan_ev.reason == WMI_SCAN_REASON_CANCELLED) 6332d5c65159SKalle Valo ar = ath11k_get_ar_on_scan_abort(ab, scan_ev.vdev_id); 6333d5c65159SKalle Valo else 6334d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, scan_ev.vdev_id); 6335d5c65159SKalle Valo 6336d5c65159SKalle Valo if (!ar) { 6337d5c65159SKalle Valo ath11k_warn(ab, "Received scan event for unknown vdev"); 6338d5c65159SKalle Valo rcu_read_unlock(); 6339d5c65159SKalle Valo return; 6340d5c65159SKalle Valo } 6341d5c65159SKalle Valo 6342d5c65159SKalle Valo spin_lock_bh(&ar->data_lock); 6343d5c65159SKalle Valo 6344d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6345d5c65159SKalle Valo "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n", 6346d5c65159SKalle Valo ath11k_wmi_event_scan_type_str(scan_ev.event_type, scan_ev.reason), 6347d5c65159SKalle Valo scan_ev.event_type, scan_ev.reason, scan_ev.channel_freq, 6348d5c65159SKalle Valo scan_ev.scan_req_id, scan_ev.scan_id, scan_ev.vdev_id, 6349d5c65159SKalle Valo ath11k_scan_state_str(ar->scan.state), ar->scan.state); 6350d5c65159SKalle Valo 6351d5c65159SKalle Valo switch (scan_ev.event_type) { 6352d5c65159SKalle Valo case WMI_SCAN_EVENT_STARTED: 6353d5c65159SKalle Valo ath11k_wmi_event_scan_started(ar); 6354d5c65159SKalle Valo break; 6355d5c65159SKalle Valo case WMI_SCAN_EVENT_COMPLETED: 6356d5c65159SKalle Valo ath11k_wmi_event_scan_completed(ar); 6357d5c65159SKalle Valo break; 6358d5c65159SKalle Valo case WMI_SCAN_EVENT_BSS_CHANNEL: 6359d5c65159SKalle Valo ath11k_wmi_event_scan_bss_chan(ar); 6360d5c65159SKalle Valo break; 6361d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN: 6362d5c65159SKalle Valo ath11k_wmi_event_scan_foreign_chan(ar, scan_ev.channel_freq); 6363d5c65159SKalle Valo break; 6364d5c65159SKalle Valo case WMI_SCAN_EVENT_START_FAILED: 6365d5c65159SKalle Valo ath11k_warn(ab, "received scan start failure event\n"); 6366d5c65159SKalle Valo ath11k_wmi_event_scan_start_failed(ar); 6367d5c65159SKalle Valo break; 6368d5c65159SKalle Valo case WMI_SCAN_EVENT_DEQUEUED: 6369d5c65159SKalle Valo case WMI_SCAN_EVENT_PREEMPTED: 6370d5c65159SKalle Valo case WMI_SCAN_EVENT_RESTARTED: 6371d5c65159SKalle Valo case WMI_SCAN_EVENT_FOREIGN_CHAN_EXIT: 6372d5c65159SKalle Valo default: 6373d5c65159SKalle Valo break; 6374d5c65159SKalle Valo } 6375d5c65159SKalle Valo 6376d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock); 6377d5c65159SKalle Valo 6378d5c65159SKalle Valo rcu_read_unlock(); 6379d5c65159SKalle Valo } 6380d5c65159SKalle Valo 6381d5c65159SKalle Valo static void ath11k_peer_sta_kickout_event(struct ath11k_base *ab, struct sk_buff *skb) 6382d5c65159SKalle Valo { 6383d5c65159SKalle Valo struct wmi_peer_sta_kickout_arg arg = {}; 6384d5c65159SKalle Valo struct ieee80211_sta *sta; 6385d5c65159SKalle Valo struct ath11k_peer *peer; 6386d5c65159SKalle Valo struct ath11k *ar; 6387d5c65159SKalle Valo 6388d5c65159SKalle Valo if (ath11k_pull_peer_sta_kickout_ev(ab, skb, &arg) != 0) { 6389d5c65159SKalle Valo ath11k_warn(ab, "failed to extract peer sta kickout event"); 6390d5c65159SKalle Valo return; 6391d5c65159SKalle Valo } 6392d5c65159SKalle Valo 6393d5c65159SKalle Valo rcu_read_lock(); 6394d5c65159SKalle Valo 6395d5c65159SKalle Valo spin_lock_bh(&ab->base_lock); 6396d5c65159SKalle Valo 6397d5c65159SKalle Valo peer = ath11k_peer_find_by_addr(ab, arg.mac_addr); 6398d5c65159SKalle Valo 6399d5c65159SKalle Valo if (!peer) { 6400d5c65159SKalle Valo ath11k_warn(ab, "peer not found %pM\n", 6401d5c65159SKalle Valo arg.mac_addr); 6402d5c65159SKalle Valo goto exit; 6403d5c65159SKalle Valo } 6404d5c65159SKalle Valo 6405d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, peer->vdev_id); 6406d5c65159SKalle Valo if (!ar) { 6407d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in peer sta kickout ev %d", 6408d5c65159SKalle Valo peer->vdev_id); 6409d5c65159SKalle Valo goto exit; 6410d5c65159SKalle Valo } 6411d5c65159SKalle Valo 6412d5c65159SKalle Valo sta = ieee80211_find_sta_by_ifaddr(ar->hw, 6413d5c65159SKalle Valo arg.mac_addr, NULL); 6414d5c65159SKalle Valo if (!sta) { 6415d5c65159SKalle Valo ath11k_warn(ab, "Spurious quick kickout for STA %pM\n", 6416d5c65159SKalle Valo arg.mac_addr); 6417d5c65159SKalle Valo goto exit; 6418d5c65159SKalle Valo } 6419d5c65159SKalle Valo 6420d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "peer sta kickout event %pM", 6421d5c65159SKalle Valo arg.mac_addr); 6422d5c65159SKalle Valo 6423d5c65159SKalle Valo ieee80211_report_low_ack(sta, 10); 6424d5c65159SKalle Valo 6425d5c65159SKalle Valo exit: 6426d5c65159SKalle Valo spin_unlock_bh(&ab->base_lock); 6427d5c65159SKalle Valo rcu_read_unlock(); 6428d5c65159SKalle Valo } 6429d5c65159SKalle Valo 6430d5c65159SKalle Valo static void ath11k_roam_event(struct ath11k_base *ab, struct sk_buff *skb) 6431d5c65159SKalle Valo { 6432d5c65159SKalle Valo struct wmi_roam_event roam_ev = {}; 6433d5c65159SKalle Valo struct ath11k *ar; 6434d5c65159SKalle Valo 6435d5c65159SKalle Valo if (ath11k_pull_roam_ev(ab, skb, &roam_ev) != 0) { 6436d5c65159SKalle Valo ath11k_warn(ab, "failed to extract roam event"); 6437d5c65159SKalle Valo return; 6438d5c65159SKalle Valo } 6439d5c65159SKalle Valo 6440d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6441d5c65159SKalle Valo "wmi roam event vdev %u reason 0x%08x rssi %d\n", 6442d5c65159SKalle Valo roam_ev.vdev_id, roam_ev.reason, roam_ev.rssi); 6443d5c65159SKalle Valo 6444d5c65159SKalle Valo rcu_read_lock(); 6445d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, roam_ev.vdev_id); 6446d5c65159SKalle Valo if (!ar) { 6447d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in roam ev %d", 6448d5c65159SKalle Valo roam_ev.vdev_id); 6449d5c65159SKalle Valo rcu_read_unlock(); 6450d5c65159SKalle Valo return; 6451d5c65159SKalle Valo } 6452d5c65159SKalle Valo 6453d5c65159SKalle Valo if (roam_ev.reason >= WMI_ROAM_REASON_MAX) 6454d5c65159SKalle Valo ath11k_warn(ab, "ignoring unknown roam event reason %d on vdev %i\n", 6455d5c65159SKalle Valo roam_ev.reason, roam_ev.vdev_id); 6456d5c65159SKalle Valo 6457d5c65159SKalle Valo switch (roam_ev.reason) { 6458d5c65159SKalle Valo case WMI_ROAM_REASON_BEACON_MISS: 645926f69792SLavanya Suresh ath11k_mac_handle_beacon_miss(ar, roam_ev.vdev_id); 6460d5c65159SKalle Valo break; 6461d5c65159SKalle Valo case WMI_ROAM_REASON_BETTER_AP: 6462d5c65159SKalle Valo case WMI_ROAM_REASON_LOW_RSSI: 6463d5c65159SKalle Valo case WMI_ROAM_REASON_SUITABLE_AP_FOUND: 6464d5c65159SKalle Valo case WMI_ROAM_REASON_HO_FAILED: 6465d5c65159SKalle Valo ath11k_warn(ab, "ignoring not implemented roam event reason %d on vdev %i\n", 6466d5c65159SKalle Valo roam_ev.reason, roam_ev.vdev_id); 6467d5c65159SKalle Valo break; 6468d5c65159SKalle Valo } 6469d5c65159SKalle Valo 6470d5c65159SKalle Valo rcu_read_unlock(); 6471d5c65159SKalle Valo } 6472d5c65159SKalle Valo 6473d5c65159SKalle Valo static void ath11k_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb) 6474d5c65159SKalle Valo { 6475d5c65159SKalle Valo struct wmi_chan_info_event ch_info_ev = {0}; 6476d5c65159SKalle Valo struct ath11k *ar; 6477d5c65159SKalle Valo struct survey_info *survey; 6478d5c65159SKalle Valo int idx; 6479d5c65159SKalle Valo /* HW channel counters frequency value in hertz */ 6480d5c65159SKalle Valo u32 cc_freq_hz = ab->cc_freq_hz; 6481d5c65159SKalle Valo 6482d5c65159SKalle Valo if (ath11k_pull_chan_info_ev(ab, skb->data, skb->len, &ch_info_ev) != 0) { 6483d5c65159SKalle Valo ath11k_warn(ab, "failed to extract chan info event"); 6484d5c65159SKalle Valo return; 6485d5c65159SKalle Valo } 6486d5c65159SKalle Valo 6487d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6488d5c65159SKalle Valo "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", 6489d5c65159SKalle Valo ch_info_ev.vdev_id, ch_info_ev.err_code, ch_info_ev.freq, 6490d5c65159SKalle Valo ch_info_ev.cmd_flags, ch_info_ev.noise_floor, 6491d5c65159SKalle Valo ch_info_ev.rx_clear_count, ch_info_ev.cycle_count, 6492d5c65159SKalle Valo ch_info_ev.mac_clk_mhz); 6493d5c65159SKalle Valo 6494d5c65159SKalle Valo if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_END_RESP) { 6495d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, "chan info report completed\n"); 6496d5c65159SKalle Valo return; 6497d5c65159SKalle Valo } 6498d5c65159SKalle Valo 6499d5c65159SKalle Valo rcu_read_lock(); 6500d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, ch_info_ev.vdev_id); 6501d5c65159SKalle Valo if (!ar) { 6502d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in chan info ev %d", 6503d5c65159SKalle Valo ch_info_ev.vdev_id); 6504d5c65159SKalle Valo rcu_read_unlock(); 6505d5c65159SKalle Valo return; 6506d5c65159SKalle Valo } 6507d5c65159SKalle Valo spin_lock_bh(&ar->data_lock); 6508d5c65159SKalle Valo 6509d5c65159SKalle Valo switch (ar->scan.state) { 6510d5c65159SKalle Valo case ATH11K_SCAN_IDLE: 6511d5c65159SKalle Valo case ATH11K_SCAN_STARTING: 6512d5c65159SKalle Valo ath11k_warn(ab, "received chan info event without a scan request, ignoring\n"); 6513d5c65159SKalle Valo goto exit; 6514d5c65159SKalle Valo case ATH11K_SCAN_RUNNING: 6515d5c65159SKalle Valo case ATH11K_SCAN_ABORTING: 6516d5c65159SKalle Valo break; 6517d5c65159SKalle Valo } 6518d5c65159SKalle Valo 6519d5c65159SKalle Valo idx = freq_to_idx(ar, ch_info_ev.freq); 6520d5c65159SKalle Valo if (idx >= ARRAY_SIZE(ar->survey)) { 6521d5c65159SKalle Valo ath11k_warn(ab, "chan info: invalid frequency %d (idx %d out of bounds)\n", 6522d5c65159SKalle Valo ch_info_ev.freq, idx); 6523d5c65159SKalle Valo goto exit; 6524d5c65159SKalle Valo } 6525d5c65159SKalle Valo 6526d5c65159SKalle Valo /* If FW provides MAC clock frequency in Mhz, overriding the initialized 6527d5c65159SKalle Valo * HW channel counters frequency value 6528d5c65159SKalle Valo */ 6529d5c65159SKalle Valo if (ch_info_ev.mac_clk_mhz) 6530d5c65159SKalle Valo cc_freq_hz = (ch_info_ev.mac_clk_mhz * 1000); 6531d5c65159SKalle Valo 6532d5c65159SKalle Valo if (ch_info_ev.cmd_flags == WMI_CHAN_INFO_START_RESP) { 6533d5c65159SKalle Valo survey = &ar->survey[idx]; 6534d5c65159SKalle Valo memset(survey, 0, sizeof(*survey)); 6535d5c65159SKalle Valo survey->noise = ch_info_ev.noise_floor; 6536d5c65159SKalle Valo survey->filled = SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME | 6537d5c65159SKalle Valo SURVEY_INFO_TIME_BUSY; 6538d5c65159SKalle Valo survey->time = div_u64(ch_info_ev.cycle_count, cc_freq_hz); 6539d5c65159SKalle Valo survey->time_busy = div_u64(ch_info_ev.rx_clear_count, cc_freq_hz); 6540d5c65159SKalle Valo } 6541d5c65159SKalle Valo exit: 6542d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock); 6543d5c65159SKalle Valo rcu_read_unlock(); 6544d5c65159SKalle Valo } 6545d5c65159SKalle Valo 6546d5c65159SKalle Valo static void 6547d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(struct ath11k_base *ab, struct sk_buff *skb) 6548d5c65159SKalle Valo { 6549d5c65159SKalle Valo struct wmi_pdev_bss_chan_info_event bss_ch_info_ev = {}; 6550d5c65159SKalle Valo struct survey_info *survey; 6551d5c65159SKalle Valo struct ath11k *ar; 6552d5c65159SKalle Valo u32 cc_freq_hz = ab->cc_freq_hz; 6553d5c65159SKalle Valo u64 busy, total, tx, rx, rx_bss; 6554d5c65159SKalle Valo int idx; 6555d5c65159SKalle Valo 6556d5c65159SKalle Valo if (ath11k_pull_pdev_bss_chan_info_ev(ab, skb, &bss_ch_info_ev) != 0) { 6557d5c65159SKalle Valo ath11k_warn(ab, "failed to extract pdev bss chan info event"); 6558d5c65159SKalle Valo return; 6559d5c65159SKalle Valo } 6560d5c65159SKalle Valo 6561d5c65159SKalle Valo busy = (u64)(bss_ch_info_ev.rx_clear_count_high) << 32 | 6562d5c65159SKalle Valo bss_ch_info_ev.rx_clear_count_low; 6563d5c65159SKalle Valo 6564d5c65159SKalle Valo total = (u64)(bss_ch_info_ev.cycle_count_high) << 32 | 6565d5c65159SKalle Valo bss_ch_info_ev.cycle_count_low; 6566d5c65159SKalle Valo 6567d5c65159SKalle Valo tx = (u64)(bss_ch_info_ev.tx_cycle_count_high) << 32 | 6568d5c65159SKalle Valo bss_ch_info_ev.tx_cycle_count_low; 6569d5c65159SKalle Valo 6570d5c65159SKalle Valo rx = (u64)(bss_ch_info_ev.rx_cycle_count_high) << 32 | 6571d5c65159SKalle Valo bss_ch_info_ev.rx_cycle_count_low; 6572d5c65159SKalle Valo 6573d5c65159SKalle Valo rx_bss = (u64)(bss_ch_info_ev.rx_bss_cycle_count_high) << 32 | 6574d5c65159SKalle Valo bss_ch_info_ev.rx_bss_cycle_count_low; 6575d5c65159SKalle Valo 6576d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6577d5c65159SKalle Valo "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", 6578d5c65159SKalle Valo bss_ch_info_ev.pdev_id, bss_ch_info_ev.freq, 6579d5c65159SKalle Valo bss_ch_info_ev.noise_floor, busy, total, 6580d5c65159SKalle Valo tx, rx, rx_bss); 6581d5c65159SKalle Valo 6582d5c65159SKalle Valo rcu_read_lock(); 6583d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, bss_ch_info_ev.pdev_id); 6584d5c65159SKalle Valo 6585d5c65159SKalle Valo if (!ar) { 6586d5c65159SKalle Valo ath11k_warn(ab, "invalid pdev id %d in bss_chan_info event\n", 6587d5c65159SKalle Valo bss_ch_info_ev.pdev_id); 6588d5c65159SKalle Valo rcu_read_unlock(); 6589d5c65159SKalle Valo return; 6590d5c65159SKalle Valo } 6591d5c65159SKalle Valo 6592d5c65159SKalle Valo spin_lock_bh(&ar->data_lock); 6593d5c65159SKalle Valo idx = freq_to_idx(ar, bss_ch_info_ev.freq); 6594d5c65159SKalle Valo if (idx >= ARRAY_SIZE(ar->survey)) { 6595d5c65159SKalle Valo ath11k_warn(ab, "bss chan info: invalid frequency %d (idx %d out of bounds)\n", 6596d5c65159SKalle Valo bss_ch_info_ev.freq, idx); 6597d5c65159SKalle Valo goto exit; 6598d5c65159SKalle Valo } 6599d5c65159SKalle Valo 6600d5c65159SKalle Valo survey = &ar->survey[idx]; 6601d5c65159SKalle Valo 6602d5c65159SKalle Valo survey->noise = bss_ch_info_ev.noise_floor; 6603d5c65159SKalle Valo survey->time = div_u64(total, cc_freq_hz); 6604d5c65159SKalle Valo survey->time_busy = div_u64(busy, cc_freq_hz); 6605d5c65159SKalle Valo survey->time_rx = div_u64(rx_bss, cc_freq_hz); 6606d5c65159SKalle Valo survey->time_tx = div_u64(tx, cc_freq_hz); 6607d5c65159SKalle Valo survey->filled |= (SURVEY_INFO_NOISE_DBM | 6608d5c65159SKalle Valo SURVEY_INFO_TIME | 6609d5c65159SKalle Valo SURVEY_INFO_TIME_BUSY | 6610d5c65159SKalle Valo SURVEY_INFO_TIME_RX | 6611d5c65159SKalle Valo SURVEY_INFO_TIME_TX); 6612d5c65159SKalle Valo exit: 6613d5c65159SKalle Valo spin_unlock_bh(&ar->data_lock); 6614d5c65159SKalle Valo complete(&ar->bss_survey_done); 6615d5c65159SKalle Valo 6616d5c65159SKalle Valo rcu_read_unlock(); 6617d5c65159SKalle Valo } 6618d5c65159SKalle Valo 6619d5c65159SKalle Valo static void ath11k_vdev_install_key_compl_event(struct ath11k_base *ab, 6620d5c65159SKalle Valo struct sk_buff *skb) 6621d5c65159SKalle Valo { 6622d5c65159SKalle Valo struct wmi_vdev_install_key_complete_arg install_key_compl = {0}; 6623d5c65159SKalle Valo struct ath11k *ar; 6624d5c65159SKalle Valo 6625d5c65159SKalle Valo if (ath11k_pull_vdev_install_key_compl_ev(ab, skb, &install_key_compl) != 0) { 6626d5c65159SKalle Valo ath11k_warn(ab, "failed to extract install key compl event"); 6627d5c65159SKalle Valo return; 6628d5c65159SKalle Valo } 6629d5c65159SKalle Valo 6630d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6631d5c65159SKalle Valo "vdev install key ev idx %d flags %08x macaddr %pM status %d\n", 6632d5c65159SKalle Valo install_key_compl.key_idx, install_key_compl.key_flags, 6633d5c65159SKalle Valo install_key_compl.macaddr, install_key_compl.status); 6634d5c65159SKalle Valo 6635d5c65159SKalle Valo rcu_read_lock(); 6636d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, install_key_compl.vdev_id); 6637d5c65159SKalle Valo if (!ar) { 6638d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in install key compl ev %d", 6639d5c65159SKalle Valo install_key_compl.vdev_id); 6640d5c65159SKalle Valo rcu_read_unlock(); 6641d5c65159SKalle Valo return; 6642d5c65159SKalle Valo } 6643d5c65159SKalle Valo 6644d5c65159SKalle Valo ar->install_key_status = 0; 6645d5c65159SKalle Valo 6646d5c65159SKalle Valo if (install_key_compl.status != WMI_VDEV_INSTALL_KEY_COMPL_STATUS_SUCCESS) { 6647d5c65159SKalle Valo ath11k_warn(ab, "install key failed for %pM status %d\n", 6648d5c65159SKalle Valo install_key_compl.macaddr, install_key_compl.status); 6649d5c65159SKalle Valo ar->install_key_status = install_key_compl.status; 6650d5c65159SKalle Valo } 6651d5c65159SKalle Valo 6652d5c65159SKalle Valo complete(&ar->install_key_done); 6653d5c65159SKalle Valo rcu_read_unlock(); 6654d5c65159SKalle Valo } 6655d5c65159SKalle Valo 6656d5c65159SKalle Valo static void ath11k_service_available_event(struct ath11k_base *ab, struct sk_buff *skb) 6657d5c65159SKalle Valo { 6658d5c65159SKalle Valo const void **tb; 6659d5c65159SKalle Valo const struct wmi_service_available_event *ev; 6660d5c65159SKalle Valo int ret; 6661d5c65159SKalle Valo int i, j; 6662d5c65159SKalle Valo 6663d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6664d5c65159SKalle Valo if (IS_ERR(tb)) { 6665d5c65159SKalle Valo ret = PTR_ERR(tb); 6666d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6667d5c65159SKalle Valo return; 6668d5c65159SKalle Valo } 6669d5c65159SKalle Valo 6670d5c65159SKalle Valo ev = tb[WMI_TAG_SERVICE_AVAILABLE_EVENT]; 6671d5c65159SKalle Valo if (!ev) { 6672d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch svc available ev"); 6673d5c65159SKalle Valo kfree(tb); 6674d5c65159SKalle Valo return; 6675d5c65159SKalle Valo } 6676d5c65159SKalle Valo 6677d5c65159SKalle Valo /* TODO: Use wmi_service_segment_offset information to get the service 6678d5c65159SKalle Valo * especially when more services are advertised in multiple sevice 6679d5c65159SKalle Valo * available events. 6680d5c65159SKalle Valo */ 6681d5c65159SKalle Valo for (i = 0, j = WMI_MAX_SERVICE; 6682d5c65159SKalle Valo i < WMI_SERVICE_SEGMENT_BM_SIZE32 && j < WMI_MAX_EXT_SERVICE; 6683d5c65159SKalle Valo i++) { 6684d5c65159SKalle Valo do { 6685d5c65159SKalle Valo if (ev->wmi_service_segment_bitmap[i] & 6686d5c65159SKalle Valo BIT(j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32)) 66876bc9d6f7SJohn Crispin set_bit(j, ab->wmi_ab.svc_map); 6688d5c65159SKalle Valo } while (++j % WMI_AVAIL_SERVICE_BITS_IN_SIZE32); 6689d5c65159SKalle Valo } 6690d5c65159SKalle Valo 6691d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6692d5c65159SKalle Valo "wmi_ext_service_bitmap 0:0x%x, 1:0x%x, 2:0x%x, 3:0x%x", 6693d5c65159SKalle Valo ev->wmi_service_segment_bitmap[0], ev->wmi_service_segment_bitmap[1], 6694d5c65159SKalle Valo ev->wmi_service_segment_bitmap[2], ev->wmi_service_segment_bitmap[3]); 6695d5c65159SKalle Valo 6696d5c65159SKalle Valo kfree(tb); 6697d5c65159SKalle Valo } 6698d5c65159SKalle Valo 6699d5c65159SKalle Valo static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff *skb) 6700d5c65159SKalle Valo { 6701d5c65159SKalle Valo struct wmi_peer_assoc_conf_arg peer_assoc_conf = {0}; 6702d5c65159SKalle Valo struct ath11k *ar; 6703d5c65159SKalle Valo 6704d5c65159SKalle Valo if (ath11k_pull_peer_assoc_conf_ev(ab, skb, &peer_assoc_conf) != 0) { 6705d5c65159SKalle Valo ath11k_warn(ab, "failed to extract peer assoc conf event"); 6706d5c65159SKalle Valo return; 6707d5c65159SKalle Valo } 6708d5c65159SKalle Valo 6709d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6710d5c65159SKalle Valo "peer assoc conf ev vdev id %d macaddr %pM\n", 6711d5c65159SKalle Valo peer_assoc_conf.vdev_id, peer_assoc_conf.macaddr); 6712d5c65159SKalle Valo 6713db0889abSKarthikeyan Periyasamy rcu_read_lock(); 6714d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_vdev_id(ab, peer_assoc_conf.vdev_id); 6715d5c65159SKalle Valo 6716d5c65159SKalle Valo if (!ar) { 6717d5c65159SKalle Valo ath11k_warn(ab, "invalid vdev id in peer assoc conf ev %d", 6718d5c65159SKalle Valo peer_assoc_conf.vdev_id); 6719db0889abSKarthikeyan Periyasamy rcu_read_unlock(); 6720d5c65159SKalle Valo return; 6721d5c65159SKalle Valo } 6722d5c65159SKalle Valo 6723d5c65159SKalle Valo complete(&ar->peer_assoc_done); 6724db0889abSKarthikeyan Periyasamy rcu_read_unlock(); 6725d5c65159SKalle Valo } 6726d5c65159SKalle Valo 6727d5c65159SKalle Valo static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb) 6728d5c65159SKalle Valo { 6729cb4e57dbSKalle Valo ath11k_debugfs_fw_stats_process(ab, skb); 6730d5c65159SKalle Valo } 6731d5c65159SKalle Valo 6732d5c65159SKalle Valo /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned 6733d5c65159SKalle Valo * is not part of BDF CTL(Conformance test limits) table entries. 6734d5c65159SKalle Valo */ 6735d5c65159SKalle Valo static void ath11k_pdev_ctl_failsafe_check_event(struct ath11k_base *ab, 6736d5c65159SKalle Valo struct sk_buff *skb) 6737d5c65159SKalle Valo { 6738d5c65159SKalle Valo const void **tb; 6739d5c65159SKalle Valo const struct wmi_pdev_ctl_failsafe_chk_event *ev; 6740d5c65159SKalle Valo int ret; 6741d5c65159SKalle Valo 6742d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6743d5c65159SKalle Valo if (IS_ERR(tb)) { 6744d5c65159SKalle Valo ret = PTR_ERR(tb); 6745d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6746d5c65159SKalle Valo return; 6747d5c65159SKalle Valo } 6748d5c65159SKalle Valo 6749d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_CTL_FAILSAFE_CHECK_EVENT]; 6750d5c65159SKalle Valo if (!ev) { 6751d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev ctl failsafe check ev"); 6752d5c65159SKalle Valo kfree(tb); 6753d5c65159SKalle Valo return; 6754d5c65159SKalle Valo } 6755d5c65159SKalle Valo 6756d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6757d5c65159SKalle Valo "pdev ctl failsafe check ev status %d\n", 6758d5c65159SKalle Valo ev->ctl_failsafe_status); 6759d5c65159SKalle Valo 6760d5c65159SKalle Valo /* If ctl_failsafe_status is set to 1 FW will max out the Transmit power 6761d5c65159SKalle Valo * to 10 dBm else the CTL power entry in the BDF would be picked up. 6762d5c65159SKalle Valo */ 6763d5c65159SKalle Valo if (ev->ctl_failsafe_status != 0) 6764d5c65159SKalle Valo ath11k_warn(ab, "pdev ctl failsafe failure status %d", 6765d5c65159SKalle Valo ev->ctl_failsafe_status); 6766d5c65159SKalle Valo 6767d5c65159SKalle Valo kfree(tb); 6768d5c65159SKalle Valo } 6769d5c65159SKalle Valo 6770d5c65159SKalle Valo static void 6771d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(struct ath11k_base *ab, 6772d5c65159SKalle Valo const struct wmi_pdev_csa_switch_ev *ev, 6773d5c65159SKalle Valo const u32 *vdev_ids) 6774d5c65159SKalle Valo { 6775d5c65159SKalle Valo int i; 6776d5c65159SKalle Valo struct ath11k_vif *arvif; 6777d5c65159SKalle Valo 6778d5c65159SKalle Valo /* Finish CSA once the switch count becomes NULL */ 6779d5c65159SKalle Valo if (ev->current_switch_count) 6780d5c65159SKalle Valo return; 6781d5c65159SKalle Valo 6782d5c65159SKalle Valo rcu_read_lock(); 6783d5c65159SKalle Valo for (i = 0; i < ev->num_vdevs; i++) { 6784d5c65159SKalle Valo arvif = ath11k_mac_get_arvif_by_vdev_id(ab, vdev_ids[i]); 6785d5c65159SKalle Valo 6786d5c65159SKalle Valo if (!arvif) { 6787d5c65159SKalle Valo ath11k_warn(ab, "Recvd csa status for unknown vdev %d", 6788d5c65159SKalle Valo vdev_ids[i]); 6789d5c65159SKalle Valo continue; 6790d5c65159SKalle Valo } 6791d5c65159SKalle Valo 6792d5c65159SKalle Valo if (arvif->is_up && arvif->vif->csa_active) 6793d5c65159SKalle Valo ieee80211_csa_finish(arvif->vif); 6794d5c65159SKalle Valo } 6795d5c65159SKalle Valo rcu_read_unlock(); 6796d5c65159SKalle Valo } 6797d5c65159SKalle Valo 6798d5c65159SKalle Valo static void 6799d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(struct ath11k_base *ab, 6800d5c65159SKalle Valo struct sk_buff *skb) 6801d5c65159SKalle Valo { 6802d5c65159SKalle Valo const void **tb; 6803d5c65159SKalle Valo const struct wmi_pdev_csa_switch_ev *ev; 6804d5c65159SKalle Valo const u32 *vdev_ids; 6805d5c65159SKalle Valo int ret; 6806d5c65159SKalle Valo 6807d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6808d5c65159SKalle Valo if (IS_ERR(tb)) { 6809d5c65159SKalle Valo ret = PTR_ERR(tb); 6810d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6811d5c65159SKalle Valo return; 6812d5c65159SKalle Valo } 6813d5c65159SKalle Valo 6814d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_CSA_SWITCH_COUNT_STATUS_EVENT]; 6815d5c65159SKalle Valo vdev_ids = tb[WMI_TAG_ARRAY_UINT32]; 6816d5c65159SKalle Valo 6817d5c65159SKalle Valo if (!ev || !vdev_ids) { 6818d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev csa switch count ev"); 6819d5c65159SKalle Valo kfree(tb); 6820d5c65159SKalle Valo return; 6821d5c65159SKalle Valo } 6822d5c65159SKalle Valo 6823d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6824d5c65159SKalle Valo "pdev csa switch count %d for pdev %d, num_vdevs %d", 6825d5c65159SKalle Valo ev->current_switch_count, ev->pdev_id, 6826d5c65159SKalle Valo ev->num_vdevs); 6827d5c65159SKalle Valo 6828d5c65159SKalle Valo ath11k_wmi_process_csa_switch_count_event(ab, ev, vdev_ids); 6829d5c65159SKalle Valo 6830d5c65159SKalle Valo kfree(tb); 6831d5c65159SKalle Valo } 6832d5c65159SKalle Valo 6833d5c65159SKalle Valo static void 6834d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(struct ath11k_base *ab, struct sk_buff *skb) 6835d5c65159SKalle Valo { 6836d5c65159SKalle Valo const void **tb; 6837d5c65159SKalle Valo const struct wmi_pdev_radar_ev *ev; 6838d5c65159SKalle Valo struct ath11k *ar; 6839d5c65159SKalle Valo int ret; 6840d5c65159SKalle Valo 6841d5c65159SKalle Valo tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6842d5c65159SKalle Valo if (IS_ERR(tb)) { 6843d5c65159SKalle Valo ret = PTR_ERR(tb); 6844d5c65159SKalle Valo ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6845d5c65159SKalle Valo return; 6846d5c65159SKalle Valo } 6847d5c65159SKalle Valo 6848d5c65159SKalle Valo ev = tb[WMI_TAG_PDEV_DFS_RADAR_DETECTION_EVENT]; 6849d5c65159SKalle Valo 6850d5c65159SKalle Valo if (!ev) { 6851d5c65159SKalle Valo ath11k_warn(ab, "failed to fetch pdev dfs radar detected ev"); 6852d5c65159SKalle Valo kfree(tb); 6853d5c65159SKalle Valo return; 6854d5c65159SKalle Valo } 6855d5c65159SKalle Valo 6856d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 6857d5c65159SKalle Valo "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", 6858d5c65159SKalle Valo ev->pdev_id, ev->detection_mode, ev->chan_freq, ev->chan_width, 6859d5c65159SKalle Valo ev->detector_id, ev->segment_id, ev->timestamp, ev->is_chirp, 6860d5c65159SKalle Valo ev->freq_offset, ev->sidx); 6861d5c65159SKalle Valo 6862d5c65159SKalle Valo ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id); 6863d5c65159SKalle Valo 6864d5c65159SKalle Valo if (!ar) { 6865d5c65159SKalle Valo ath11k_warn(ab, "radar detected in invalid pdev %d\n", 6866d5c65159SKalle Valo ev->pdev_id); 6867d5c65159SKalle Valo goto exit; 6868d5c65159SKalle Valo } 6869d5c65159SKalle Valo 6870d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_REG, "DFS Radar Detected in pdev %d\n", 6871d5c65159SKalle Valo ev->pdev_id); 6872d5c65159SKalle Valo 6873d5c65159SKalle Valo if (ar->dfs_block_radar_events) 6874d5c65159SKalle Valo ath11k_info(ab, "DFS Radar detected, but ignored as requested\n"); 6875d5c65159SKalle Valo else 6876d5c65159SKalle Valo ieee80211_radar_detected(ar->hw); 6877d5c65159SKalle Valo 6878d5c65159SKalle Valo exit: 6879d5c65159SKalle Valo kfree(tb); 6880d5c65159SKalle Valo } 6881d5c65159SKalle Valo 6882a41d1034SPradeep Kumar Chitrapu static void 6883a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(struct ath11k_base *ab, 6884a41d1034SPradeep Kumar Chitrapu struct sk_buff *skb) 6885a41d1034SPradeep Kumar Chitrapu { 6886a41d1034SPradeep Kumar Chitrapu struct ath11k *ar; 6887e3de5bb7SPradeep Kumar Chitrapu const void **tb; 6888e3de5bb7SPradeep Kumar Chitrapu const struct wmi_pdev_temperature_event *ev; 6889e3de5bb7SPradeep Kumar Chitrapu int ret; 6890a41d1034SPradeep Kumar Chitrapu 6891e3de5bb7SPradeep Kumar Chitrapu tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6892e3de5bb7SPradeep Kumar Chitrapu if (IS_ERR(tb)) { 6893e3de5bb7SPradeep Kumar Chitrapu ret = PTR_ERR(tb); 6894e3de5bb7SPradeep Kumar Chitrapu ath11k_warn(ab, "failed to parse tlv: %d\n", ret); 6895e3de5bb7SPradeep Kumar Chitrapu return; 6896e3de5bb7SPradeep Kumar Chitrapu } 6897e3de5bb7SPradeep Kumar Chitrapu 6898e3de5bb7SPradeep Kumar Chitrapu ev = tb[WMI_TAG_PDEV_TEMPERATURE_EVENT]; 6899e3de5bb7SPradeep Kumar Chitrapu if (!ev) { 6900e3de5bb7SPradeep Kumar Chitrapu ath11k_warn(ab, "failed to fetch pdev temp ev"); 6901e3de5bb7SPradeep Kumar Chitrapu kfree(tb); 6902a41d1034SPradeep Kumar Chitrapu return; 6903a41d1034SPradeep Kumar Chitrapu } 6904a41d1034SPradeep Kumar Chitrapu 6905a41d1034SPradeep Kumar Chitrapu ath11k_dbg(ab, ATH11K_DBG_WMI, 6906e3de5bb7SPradeep Kumar Chitrapu "pdev temperature ev temp %d pdev_id %d\n", ev->temp, ev->pdev_id); 6907a41d1034SPradeep Kumar Chitrapu 6908e3de5bb7SPradeep Kumar Chitrapu ar = ath11k_mac_get_ar_by_pdev_id(ab, ev->pdev_id); 6909a41d1034SPradeep Kumar Chitrapu if (!ar) { 6910e3de5bb7SPradeep Kumar Chitrapu ath11k_warn(ab, "invalid pdev id in pdev temperature ev %d", ev->pdev_id); 6911e3de5bb7SPradeep Kumar Chitrapu kfree(tb); 6912a41d1034SPradeep Kumar Chitrapu return; 6913a41d1034SPradeep Kumar Chitrapu } 6914a41d1034SPradeep Kumar Chitrapu 6915e3de5bb7SPradeep Kumar Chitrapu ath11k_thermal_event_temperature(ar, ev->temp); 6916e3de5bb7SPradeep Kumar Chitrapu 6917e3de5bb7SPradeep Kumar Chitrapu kfree(tb); 6918a41d1034SPradeep Kumar Chitrapu } 6919a41d1034SPradeep Kumar Chitrapu 6920047679e3SAloka Dixit static void ath11k_fils_discovery_event(struct ath11k_base *ab, 6921047679e3SAloka Dixit struct sk_buff *skb) 6922047679e3SAloka Dixit { 6923047679e3SAloka Dixit const void **tb; 6924047679e3SAloka Dixit const struct wmi_fils_discovery_event *ev; 6925047679e3SAloka Dixit int ret; 6926047679e3SAloka Dixit 6927047679e3SAloka Dixit tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6928047679e3SAloka Dixit if (IS_ERR(tb)) { 6929047679e3SAloka Dixit ret = PTR_ERR(tb); 6930047679e3SAloka Dixit ath11k_warn(ab, 6931047679e3SAloka Dixit "failed to parse FILS discovery event tlv %d\n", 6932047679e3SAloka Dixit ret); 6933047679e3SAloka Dixit return; 6934047679e3SAloka Dixit } 6935047679e3SAloka Dixit 6936047679e3SAloka Dixit ev = tb[WMI_TAG_HOST_SWFDA_EVENT]; 6937047679e3SAloka Dixit if (!ev) { 6938047679e3SAloka Dixit ath11k_warn(ab, "failed to fetch FILS discovery event\n"); 6939047679e3SAloka Dixit kfree(tb); 6940047679e3SAloka Dixit return; 6941047679e3SAloka Dixit } 6942047679e3SAloka Dixit 6943047679e3SAloka Dixit ath11k_warn(ab, 6944047679e3SAloka Dixit "FILS discovery frame expected from host for vdev_id: %u, transmission scheduled at %u, next TBTT: %u\n", 6945047679e3SAloka Dixit ev->vdev_id, ev->fils_tt, ev->tbtt); 6946047679e3SAloka Dixit 6947047679e3SAloka Dixit kfree(tb); 6948047679e3SAloka Dixit } 6949047679e3SAloka Dixit 6950047679e3SAloka Dixit static void ath11k_probe_resp_tx_status_event(struct ath11k_base *ab, 6951047679e3SAloka Dixit struct sk_buff *skb) 6952047679e3SAloka Dixit { 6953047679e3SAloka Dixit const void **tb; 6954047679e3SAloka Dixit const struct wmi_probe_resp_tx_status_event *ev; 6955047679e3SAloka Dixit int ret; 6956047679e3SAloka Dixit 6957047679e3SAloka Dixit tb = ath11k_wmi_tlv_parse_alloc(ab, skb->data, skb->len, GFP_ATOMIC); 6958047679e3SAloka Dixit if (IS_ERR(tb)) { 6959047679e3SAloka Dixit ret = PTR_ERR(tb); 6960047679e3SAloka Dixit ath11k_warn(ab, 6961047679e3SAloka Dixit "failed to parse probe response transmission status event tlv: %d\n", 6962047679e3SAloka Dixit ret); 6963047679e3SAloka Dixit return; 6964047679e3SAloka Dixit } 6965047679e3SAloka Dixit 6966047679e3SAloka Dixit ev = tb[WMI_TAG_OFFLOAD_PRB_RSP_TX_STATUS_EVENT]; 6967047679e3SAloka Dixit if (!ev) { 6968047679e3SAloka Dixit ath11k_warn(ab, 6969047679e3SAloka Dixit "failed to fetch probe response transmission status event"); 6970047679e3SAloka Dixit kfree(tb); 6971047679e3SAloka Dixit return; 6972047679e3SAloka Dixit } 6973047679e3SAloka Dixit 6974047679e3SAloka Dixit if (ev->tx_status) 6975047679e3SAloka Dixit ath11k_warn(ab, 6976047679e3SAloka Dixit "Probe response transmission failed for vdev_id %u, status %u\n", 6977047679e3SAloka Dixit ev->vdev_id, ev->tx_status); 6978047679e3SAloka Dixit 6979047679e3SAloka Dixit kfree(tb); 6980047679e3SAloka Dixit } 6981047679e3SAloka Dixit 698279802b13SCarl Huang static int ath11k_wmi_tlv_wow_wakeup_host_parse(struct ath11k_base *ab, 698379802b13SCarl Huang u16 tag, u16 len, 698479802b13SCarl Huang const void *ptr, void *data) 698579802b13SCarl Huang { 698679802b13SCarl Huang struct wmi_wow_ev_arg *ev = data; 698779802b13SCarl Huang const char *wow_pg_fault; 698879802b13SCarl Huang int wow_pg_len; 698979802b13SCarl Huang 699079802b13SCarl Huang switch (tag) { 699179802b13SCarl Huang case WMI_TAG_WOW_EVENT_INFO: 699279802b13SCarl Huang memcpy(ev, ptr, sizeof(*ev)); 699379802b13SCarl Huang ath11k_dbg(ab, ATH11K_DBG_WMI, "wow wakeup host reason %d %s\n", 699479802b13SCarl Huang ev->wake_reason, wow_reason(ev->wake_reason)); 699579802b13SCarl Huang break; 699679802b13SCarl Huang 699779802b13SCarl Huang case WMI_TAG_ARRAY_BYTE: 699879802b13SCarl Huang if (ev && ev->wake_reason == WOW_REASON_PAGE_FAULT) { 699979802b13SCarl Huang wow_pg_fault = ptr; 700079802b13SCarl Huang /* the first 4 bytes are length */ 700179802b13SCarl Huang wow_pg_len = *(int *)wow_pg_fault; 700279802b13SCarl Huang wow_pg_fault += sizeof(int); 700379802b13SCarl Huang ath11k_dbg(ab, ATH11K_DBG_WMI, "wow data_len = %d\n", 700479802b13SCarl Huang wow_pg_len); 700579802b13SCarl Huang ath11k_dbg_dump(ab, ATH11K_DBG_WMI, 700679802b13SCarl Huang "wow_event_info_type packet present", 700779802b13SCarl Huang "wow_pg_fault ", 700879802b13SCarl Huang wow_pg_fault, 700979802b13SCarl Huang wow_pg_len); 701079802b13SCarl Huang } 701179802b13SCarl Huang break; 701279802b13SCarl Huang default: 701379802b13SCarl Huang break; 701479802b13SCarl Huang } 701579802b13SCarl Huang 701679802b13SCarl Huang return 0; 701779802b13SCarl Huang } 701879802b13SCarl Huang 701979802b13SCarl Huang static void ath11k_wmi_event_wow_wakeup_host(struct ath11k_base *ab, struct sk_buff *skb) 702079802b13SCarl Huang { 702179802b13SCarl Huang struct wmi_wow_ev_arg ev = { }; 702279802b13SCarl Huang int ret; 702379802b13SCarl Huang 702479802b13SCarl Huang ret = ath11k_wmi_tlv_iter(ab, skb->data, skb->len, 702579802b13SCarl Huang ath11k_wmi_tlv_wow_wakeup_host_parse, 702679802b13SCarl Huang &ev); 702779802b13SCarl Huang if (ret) { 702879802b13SCarl Huang ath11k_warn(ab, "failed to parse wmi wow tlv: %d\n", ret); 702979802b13SCarl Huang return; 703079802b13SCarl Huang } 703179802b13SCarl Huang 703279802b13SCarl Huang complete(&ab->wow.wakeup_completed); 703379802b13SCarl Huang } 703479802b13SCarl Huang 7035d5c65159SKalle Valo static void ath11k_wmi_tlv_op_rx(struct ath11k_base *ab, struct sk_buff *skb) 7036d5c65159SKalle Valo { 7037d5c65159SKalle Valo struct wmi_cmd_hdr *cmd_hdr; 7038d5c65159SKalle Valo enum wmi_tlv_event_id id; 7039d5c65159SKalle Valo 7040d5c65159SKalle Valo cmd_hdr = (struct wmi_cmd_hdr *)skb->data; 7041d5c65159SKalle Valo id = FIELD_GET(WMI_CMD_HDR_CMD_ID, (cmd_hdr->cmd_id)); 7042d5c65159SKalle Valo 7043d5c65159SKalle Valo if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL) 7044d5c65159SKalle Valo goto out; 7045d5c65159SKalle Valo 7046d5c65159SKalle Valo switch (id) { 7047d5c65159SKalle Valo /* Process all the WMI events here */ 7048d5c65159SKalle Valo case WMI_SERVICE_READY_EVENTID: 7049d5c65159SKalle Valo ath11k_service_ready_event(ab, skb); 7050d5c65159SKalle Valo break; 7051d5c65159SKalle Valo case WMI_SERVICE_READY_EXT_EVENTID: 7052d5c65159SKalle Valo ath11k_service_ready_ext_event(ab, skb); 7053d5c65159SKalle Valo break; 7054bd647855SKarthikeyan Periyasamy case WMI_SERVICE_READY_EXT2_EVENTID: 7055bd647855SKarthikeyan Periyasamy ath11k_service_ready_ext2_event(ab, skb); 7056bd647855SKarthikeyan Periyasamy break; 7057d5c65159SKalle Valo case WMI_REG_CHAN_LIST_CC_EVENTID: 7058d5c65159SKalle Valo ath11k_reg_chan_list_event(ab, skb); 7059d5c65159SKalle Valo break; 7060d5c65159SKalle Valo case WMI_READY_EVENTID: 7061d5c65159SKalle Valo ath11k_ready_event(ab, skb); 7062d5c65159SKalle Valo break; 7063d5c65159SKalle Valo case WMI_PEER_DELETE_RESP_EVENTID: 7064d5c65159SKalle Valo ath11k_peer_delete_resp_event(ab, skb); 7065d5c65159SKalle Valo break; 7066d5c65159SKalle Valo case WMI_VDEV_START_RESP_EVENTID: 7067d5c65159SKalle Valo ath11k_vdev_start_resp_event(ab, skb); 7068d5c65159SKalle Valo break; 7069d5c65159SKalle Valo case WMI_OFFLOAD_BCN_TX_STATUS_EVENTID: 7070d5c65159SKalle Valo ath11k_bcn_tx_status_event(ab, skb); 7071d5c65159SKalle Valo break; 7072d5c65159SKalle Valo case WMI_VDEV_STOPPED_EVENTID: 7073d5c65159SKalle Valo ath11k_vdev_stopped_event(ab, skb); 7074d5c65159SKalle Valo break; 7075d5c65159SKalle Valo case WMI_MGMT_RX_EVENTID: 7076d5c65159SKalle Valo ath11k_mgmt_rx_event(ab, skb); 7077d5c65159SKalle Valo /* mgmt_rx_event() owns the skb now! */ 7078d5c65159SKalle Valo return; 7079d5c65159SKalle Valo case WMI_MGMT_TX_COMPLETION_EVENTID: 7080d5c65159SKalle Valo ath11k_mgmt_tx_compl_event(ab, skb); 7081d5c65159SKalle Valo break; 7082d5c65159SKalle Valo case WMI_SCAN_EVENTID: 7083d5c65159SKalle Valo ath11k_scan_event(ab, skb); 7084d5c65159SKalle Valo break; 7085d5c65159SKalle Valo case WMI_PEER_STA_KICKOUT_EVENTID: 7086d5c65159SKalle Valo ath11k_peer_sta_kickout_event(ab, skb); 7087d5c65159SKalle Valo break; 7088d5c65159SKalle Valo case WMI_ROAM_EVENTID: 7089d5c65159SKalle Valo ath11k_roam_event(ab, skb); 7090d5c65159SKalle Valo break; 7091d5c65159SKalle Valo case WMI_CHAN_INFO_EVENTID: 7092d5c65159SKalle Valo ath11k_chan_info_event(ab, skb); 7093d5c65159SKalle Valo break; 7094d5c65159SKalle Valo case WMI_PDEV_BSS_CHAN_INFO_EVENTID: 7095d5c65159SKalle Valo ath11k_pdev_bss_chan_info_event(ab, skb); 7096d5c65159SKalle Valo break; 7097d5c65159SKalle Valo case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID: 7098d5c65159SKalle Valo ath11k_vdev_install_key_compl_event(ab, skb); 7099d5c65159SKalle Valo break; 7100d5c65159SKalle Valo case WMI_SERVICE_AVAILABLE_EVENTID: 7101d5c65159SKalle Valo ath11k_service_available_event(ab, skb); 7102d5c65159SKalle Valo break; 7103d5c65159SKalle Valo case WMI_PEER_ASSOC_CONF_EVENTID: 7104d5c65159SKalle Valo ath11k_peer_assoc_conf_event(ab, skb); 7105d5c65159SKalle Valo break; 7106d5c65159SKalle Valo case WMI_UPDATE_STATS_EVENTID: 7107d5c65159SKalle Valo ath11k_update_stats_event(ab, skb); 7108d5c65159SKalle Valo break; 7109d5c65159SKalle Valo case WMI_PDEV_CTL_FAILSAFE_CHECK_EVENTID: 7110d5c65159SKalle Valo ath11k_pdev_ctl_failsafe_check_event(ab, skb); 7111d5c65159SKalle Valo break; 7112d5c65159SKalle Valo case WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID: 7113d5c65159SKalle Valo ath11k_wmi_pdev_csa_switch_count_status_event(ab, skb); 7114d5c65159SKalle Valo break; 7115a41d1034SPradeep Kumar Chitrapu case WMI_PDEV_TEMPERATURE_EVENTID: 7116a41d1034SPradeep Kumar Chitrapu ath11k_wmi_pdev_temperature_event(ab, skb); 7117a41d1034SPradeep Kumar Chitrapu break; 71189d11b7bfSKarthikeyan Periyasamy case WMI_PDEV_DMA_RING_BUF_RELEASE_EVENTID: 71199d11b7bfSKarthikeyan Periyasamy ath11k_wmi_pdev_dma_ring_buf_release_event(ab, skb); 71209d11b7bfSKarthikeyan Periyasamy break; 7121047679e3SAloka Dixit case WMI_HOST_FILS_DISCOVERY_EVENTID: 7122047679e3SAloka Dixit ath11k_fils_discovery_event(ab, skb); 7123047679e3SAloka Dixit break; 7124047679e3SAloka Dixit case WMI_OFFLOAD_PROB_RESP_TX_STATUS_EVENTID: 7125047679e3SAloka Dixit ath11k_probe_resp_tx_status_event(ab, skb); 7126047679e3SAloka Dixit break; 7127d5c65159SKalle Valo /* add Unsupported events here */ 7128d5c65159SKalle Valo case WMI_TBTTOFFSET_EXT_UPDATE_EVENTID: 71299cfbae46SJohn Crispin case WMI_PEER_OPER_MODE_CHANGE_EVENTID: 71306d293d44SJohn Crispin case WMI_TWT_ENABLE_EVENTID: 71316d293d44SJohn Crispin case WMI_TWT_DISABLE_EVENTID: 71329d11b7bfSKarthikeyan Periyasamy case WMI_PDEV_DMA_RING_CFG_RSP_EVENTID: 7133*94a6df31SP Praneesh case WMI_PEER_CREATE_CONF_EVENTID: 7134d5c65159SKalle Valo ath11k_dbg(ab, ATH11K_DBG_WMI, 7135d5c65159SKalle Valo "ignoring unsupported event 0x%x\n", id); 7136d5c65159SKalle Valo break; 7137d5c65159SKalle Valo case WMI_PDEV_DFS_RADAR_DETECTION_EVENTID: 7138d5c65159SKalle Valo ath11k_wmi_pdev_dfs_radar_detected_event(ab, skb); 7139d5c65159SKalle Valo break; 71403cbbdfbeSRitesh Singh case WMI_VDEV_DELETE_RESP_EVENTID: 71413cbbdfbeSRitesh Singh ath11k_vdev_delete_resp_event(ab, skb); 71423cbbdfbeSRitesh Singh break; 714379802b13SCarl Huang case WMI_WOW_WAKEUP_HOST_EVENTID: 714479802b13SCarl Huang ath11k_wmi_event_wow_wakeup_host(ab, skb); 714579802b13SCarl Huang break; 7146d5c65159SKalle Valo /* TODO: Add remaining events */ 7147d5c65159SKalle Valo default: 714882b4f9b8SGovind Singh ath11k_dbg(ab, ATH11K_DBG_WMI, "Unknown eventid: 0x%x\n", id); 7149d5c65159SKalle Valo break; 7150d5c65159SKalle Valo } 7151d5c65159SKalle Valo 7152d5c65159SKalle Valo out: 7153d5c65159SKalle Valo dev_kfree_skb(skb); 7154d5c65159SKalle Valo } 7155d5c65159SKalle Valo 7156d5c65159SKalle Valo static int ath11k_connect_pdev_htc_service(struct ath11k_base *ab, 7157d5c65159SKalle Valo u32 pdev_idx) 7158d5c65159SKalle Valo { 7159d5c65159SKalle Valo int status; 7160d5c65159SKalle Valo u32 svc_id[] = { ATH11K_HTC_SVC_ID_WMI_CONTROL, 7161d5c65159SKalle Valo ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1, 7162d5c65159SKalle Valo ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2 }; 7163d5c65159SKalle Valo 7164d5c65159SKalle Valo struct ath11k_htc_svc_conn_req conn_req; 7165d5c65159SKalle Valo struct ath11k_htc_svc_conn_resp conn_resp; 7166d5c65159SKalle Valo 7167d5c65159SKalle Valo memset(&conn_req, 0, sizeof(conn_req)); 7168d5c65159SKalle Valo memset(&conn_resp, 0, sizeof(conn_resp)); 7169d5c65159SKalle Valo 7170d5c65159SKalle Valo /* these fields are the same for all service endpoints */ 7171d5c65159SKalle Valo conn_req.ep_ops.ep_tx_complete = ath11k_wmi_htc_tx_complete; 7172d5c65159SKalle Valo conn_req.ep_ops.ep_rx_complete = ath11k_wmi_tlv_op_rx; 7173d5c65159SKalle Valo conn_req.ep_ops.ep_tx_credits = ath11k_wmi_op_ep_tx_credits; 7174d5c65159SKalle Valo 7175d5c65159SKalle Valo /* connect to control service */ 7176d5c65159SKalle Valo conn_req.service_id = svc_id[pdev_idx]; 7177d5c65159SKalle Valo 7178d5c65159SKalle Valo status = ath11k_htc_connect_service(&ab->htc, &conn_req, &conn_resp); 7179d5c65159SKalle Valo if (status) { 7180d5c65159SKalle Valo ath11k_warn(ab, "failed to connect to WMI CONTROL service status: %d\n", 7181d5c65159SKalle Valo status); 7182d5c65159SKalle Valo return status; 7183d5c65159SKalle Valo } 7184d5c65159SKalle Valo 71856bc9d6f7SJohn Crispin ab->wmi_ab.wmi_endpoint_id[pdev_idx] = conn_resp.eid; 71866bc9d6f7SJohn Crispin ab->wmi_ab.wmi[pdev_idx].eid = conn_resp.eid; 71876bc9d6f7SJohn Crispin ab->wmi_ab.max_msg_len[pdev_idx] = conn_resp.max_msg_len; 7188d5c65159SKalle Valo 7189d5c65159SKalle Valo return 0; 7190d5c65159SKalle Valo } 7191d5c65159SKalle Valo 7192d5c65159SKalle Valo static int 7193d5c65159SKalle Valo ath11k_wmi_send_unit_test_cmd(struct ath11k *ar, 7194d5c65159SKalle Valo struct wmi_unit_test_cmd ut_cmd, 7195d5c65159SKalle Valo u32 *test_args) 7196d5c65159SKalle Valo { 7197d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi = ar->wmi; 7198d5c65159SKalle Valo struct wmi_unit_test_cmd *cmd; 7199d5c65159SKalle Valo struct sk_buff *skb; 7200d5c65159SKalle Valo struct wmi_tlv *tlv; 7201d5c65159SKalle Valo void *ptr; 7202d5c65159SKalle Valo u32 *ut_cmd_args; 7203d5c65159SKalle Valo int buf_len, arg_len; 7204d5c65159SKalle Valo int ret; 7205d5c65159SKalle Valo int i; 7206d5c65159SKalle Valo 7207d5c65159SKalle Valo arg_len = sizeof(u32) * ut_cmd.num_args; 7208d5c65159SKalle Valo buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE; 7209d5c65159SKalle Valo 72106bc9d6f7SJohn Crispin skb = ath11k_wmi_alloc_skb(wmi->wmi_ab, buf_len); 7211d5c65159SKalle Valo if (!skb) 7212d5c65159SKalle Valo return -ENOMEM; 7213d5c65159SKalle Valo 7214d5c65159SKalle Valo cmd = (struct wmi_unit_test_cmd *)skb->data; 7215d5c65159SKalle Valo cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_UNIT_TEST_CMD) | 7216d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, sizeof(ut_cmd) - TLV_HDR_SIZE); 7217d5c65159SKalle Valo 7218d5c65159SKalle Valo cmd->vdev_id = ut_cmd.vdev_id; 7219d5c65159SKalle Valo cmd->module_id = ut_cmd.module_id; 7220d5c65159SKalle Valo cmd->num_args = ut_cmd.num_args; 7221d5c65159SKalle Valo cmd->diag_token = ut_cmd.diag_token; 7222d5c65159SKalle Valo 7223d5c65159SKalle Valo ptr = skb->data + sizeof(ut_cmd); 7224d5c65159SKalle Valo 7225d5c65159SKalle Valo tlv = ptr; 7226d5c65159SKalle Valo tlv->header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_ARRAY_UINT32) | 7227d5c65159SKalle Valo FIELD_PREP(WMI_TLV_LEN, arg_len); 7228d5c65159SKalle Valo 7229d5c65159SKalle Valo ptr += TLV_HDR_SIZE; 7230d5c65159SKalle Valo 7231d5c65159SKalle Valo ut_cmd_args = ptr; 7232d5c65159SKalle Valo for (i = 0; i < ut_cmd.num_args; i++) 7233d5c65159SKalle Valo ut_cmd_args[i] = test_args[i]; 7234d5c65159SKalle Valo 7235d5c65159SKalle Valo ret = ath11k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID); 7236d5c65159SKalle Valo 7237d5c65159SKalle Valo if (ret) { 7238d5c65159SKalle Valo ath11k_warn(ar->ab, "failed to send WMI_UNIT_TEST CMD :%d\n", 7239d5c65159SKalle Valo ret); 7240d5c65159SKalle Valo dev_kfree_skb(skb); 7241d5c65159SKalle Valo } 7242d5c65159SKalle Valo 7243d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_WMI, 7244d5c65159SKalle Valo "WMI unit test : module %d vdev %d n_args %d token %d\n", 7245d5c65159SKalle Valo cmd->module_id, cmd->vdev_id, cmd->num_args, 7246d5c65159SKalle Valo cmd->diag_token); 7247d5c65159SKalle Valo 7248d5c65159SKalle Valo return ret; 7249d5c65159SKalle Valo } 7250d5c65159SKalle Valo 7251d5c65159SKalle Valo int ath11k_wmi_simulate_radar(struct ath11k *ar) 7252d5c65159SKalle Valo { 7253d5c65159SKalle Valo struct ath11k_vif *arvif; 7254d5c65159SKalle Valo u32 dfs_args[DFS_MAX_TEST_ARGS]; 7255d5c65159SKalle Valo struct wmi_unit_test_cmd wmi_ut; 7256d5c65159SKalle Valo bool arvif_found = false; 7257d5c65159SKalle Valo 7258d5c65159SKalle Valo list_for_each_entry(arvif, &ar->arvifs, list) { 7259d5c65159SKalle Valo if (arvif->is_started && arvif->vdev_type == WMI_VDEV_TYPE_AP) { 7260d5c65159SKalle Valo arvif_found = true; 7261d5c65159SKalle Valo break; 7262d5c65159SKalle Valo } 7263d5c65159SKalle Valo } 7264d5c65159SKalle Valo 7265d5c65159SKalle Valo if (!arvif_found) 7266d5c65159SKalle Valo return -EINVAL; 7267d5c65159SKalle Valo 7268d5c65159SKalle Valo dfs_args[DFS_TEST_CMDID] = 0; 7269d5c65159SKalle Valo dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id; 7270d5c65159SKalle Valo /* Currently we could pass segment_id(b0 - b1), chirp(b2) 7271d5c65159SKalle Valo * freq offset (b3 - b10) to unit test. For simulation 7272d5c65159SKalle Valo * purpose this can be set to 0 which is valid. 7273d5c65159SKalle Valo */ 7274d5c65159SKalle Valo dfs_args[DFS_TEST_RADAR_PARAM] = 0; 7275d5c65159SKalle Valo 7276d5c65159SKalle Valo wmi_ut.vdev_id = arvif->vdev_id; 7277d5c65159SKalle Valo wmi_ut.module_id = DFS_UNIT_TEST_MODULE; 7278d5c65159SKalle Valo wmi_ut.num_args = DFS_MAX_TEST_ARGS; 7279d5c65159SKalle Valo wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN; 7280d5c65159SKalle Valo 7281d5c65159SKalle Valo ath11k_dbg(ar->ab, ATH11K_DBG_REG, "Triggering Radar Simulation\n"); 7282d5c65159SKalle Valo 7283d5c65159SKalle Valo return ath11k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args); 7284d5c65159SKalle Valo } 7285d5c65159SKalle Valo 7286d5c65159SKalle Valo int ath11k_wmi_connect(struct ath11k_base *ab) 7287d5c65159SKalle Valo { 7288d5c65159SKalle Valo u32 i; 7289d5c65159SKalle Valo u8 wmi_ep_count; 7290d5c65159SKalle Valo 7291d5c65159SKalle Valo wmi_ep_count = ab->htc.wmi_ep_count; 7292b1cc29e9SAnilkumar Kolli if (wmi_ep_count > ab->hw_params.max_radios) 7293d5c65159SKalle Valo return -1; 7294d5c65159SKalle Valo 7295d5c65159SKalle Valo for (i = 0; i < wmi_ep_count; i++) 7296d5c65159SKalle Valo ath11k_connect_pdev_htc_service(ab, i); 7297d5c65159SKalle Valo 7298d5c65159SKalle Valo return 0; 7299d5c65159SKalle Valo } 7300d5c65159SKalle Valo 7301d5c65159SKalle Valo static void ath11k_wmi_pdev_detach(struct ath11k_base *ab, u8 pdev_id) 7302d5c65159SKalle Valo { 7303d5c65159SKalle Valo if (WARN_ON(pdev_id >= MAX_RADIOS)) 7304d5c65159SKalle Valo return; 7305d5c65159SKalle Valo 7306d5c65159SKalle Valo /* TODO: Deinit any pdev specific wmi resource */ 7307d5c65159SKalle Valo } 7308d5c65159SKalle Valo 7309d5c65159SKalle Valo int ath11k_wmi_pdev_attach(struct ath11k_base *ab, 7310d5c65159SKalle Valo u8 pdev_id) 7311d5c65159SKalle Valo { 7312d5c65159SKalle Valo struct ath11k_pdev_wmi *wmi_handle; 7313d5c65159SKalle Valo 7314b1cc29e9SAnilkumar Kolli if (pdev_id >= ab->hw_params.max_radios) 7315d5c65159SKalle Valo return -EINVAL; 7316d5c65159SKalle Valo 73176bc9d6f7SJohn Crispin wmi_handle = &ab->wmi_ab.wmi[pdev_id]; 7318d5c65159SKalle Valo 73196bc9d6f7SJohn Crispin wmi_handle->wmi_ab = &ab->wmi_ab; 7320d5c65159SKalle Valo 73216bc9d6f7SJohn Crispin ab->wmi_ab.ab = ab; 7322d5c65159SKalle Valo /* TODO: Init remaining resource specific to pdev */ 7323d5c65159SKalle Valo 7324d5c65159SKalle Valo return 0; 7325d5c65159SKalle Valo } 7326d5c65159SKalle Valo 7327d5c65159SKalle Valo int ath11k_wmi_attach(struct ath11k_base *ab) 7328d5c65159SKalle Valo { 7329d5c65159SKalle Valo int ret; 7330d5c65159SKalle Valo 7331d5c65159SKalle Valo ret = ath11k_wmi_pdev_attach(ab, 0); 7332d5c65159SKalle Valo if (ret) 7333d5c65159SKalle Valo return ret; 7334d5c65159SKalle Valo 73356bc9d6f7SJohn Crispin ab->wmi_ab.ab = ab; 73366bc9d6f7SJohn Crispin ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_MAX; 7337d5c65159SKalle Valo 73385f859bc0SCarl Huang /* It's overwritten when service_ext_ready is handled */ 73395f859bc0SCarl Huang if (ab->hw_params.single_pdev_only) 73405f859bc0SCarl Huang ab->wmi_ab.preferred_hw_mode = WMI_HOST_HW_MODE_SINGLE; 73415f859bc0SCarl Huang 7342d5c65159SKalle Valo /* TODO: Init remaining wmi soc resources required */ 73436bc9d6f7SJohn Crispin init_completion(&ab->wmi_ab.service_ready); 73446bc9d6f7SJohn Crispin init_completion(&ab->wmi_ab.unified_ready); 7345d5c65159SKalle Valo 7346d5c65159SKalle Valo return 0; 7347d5c65159SKalle Valo } 7348d5c65159SKalle Valo 7349d5c65159SKalle Valo void ath11k_wmi_detach(struct ath11k_base *ab) 7350d5c65159SKalle Valo { 7351d5c65159SKalle Valo int i; 7352d5c65159SKalle Valo 7353d5c65159SKalle Valo /* TODO: Deinit wmi resource specific to SOC as required */ 7354d5c65159SKalle Valo 7355d5c65159SKalle Valo for (i = 0; i < ab->htc.wmi_ep_count; i++) 7356d5c65159SKalle Valo ath11k_wmi_pdev_detach(ab, i); 7357bd647855SKarthikeyan Periyasamy 7358bd647855SKarthikeyan Periyasamy ath11k_wmi_free_dbring_caps(ab); 7359d5c65159SKalle Valo } 736079802b13SCarl Huang 736179802b13SCarl Huang int ath11k_wmi_wow_host_wakeup_ind(struct ath11k *ar) 736279802b13SCarl Huang { 736379802b13SCarl Huang struct wmi_wow_host_wakeup_ind *cmd; 736479802b13SCarl Huang struct sk_buff *skb; 736579802b13SCarl Huang size_t len; 736679802b13SCarl Huang 736779802b13SCarl Huang len = sizeof(*cmd); 736879802b13SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len); 736979802b13SCarl Huang if (!skb) 737079802b13SCarl Huang return -ENOMEM; 737179802b13SCarl Huang 737279802b13SCarl Huang cmd = (struct wmi_wow_host_wakeup_ind *)skb->data; 737379802b13SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, 737479802b13SCarl Huang WMI_TAG_WOW_HOSTWAKEUP_FROM_SLEEP_CMD) | 737579802b13SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 737679802b13SCarl Huang 737779802b13SCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow host wakeup ind\n"); 737879802b13SCarl Huang 737979802b13SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID); 738079802b13SCarl Huang } 738179802b13SCarl Huang 738279802b13SCarl Huang int ath11k_wmi_wow_enable(struct ath11k *ar) 738379802b13SCarl Huang { 738479802b13SCarl Huang struct wmi_wow_enable_cmd *cmd; 738579802b13SCarl Huang struct sk_buff *skb; 738679802b13SCarl Huang int len; 738779802b13SCarl Huang 738879802b13SCarl Huang len = sizeof(*cmd); 738979802b13SCarl Huang skb = ath11k_wmi_alloc_skb(ar->wmi->wmi_ab, len); 739079802b13SCarl Huang if (!skb) 739179802b13SCarl Huang return -ENOMEM; 739279802b13SCarl Huang 739379802b13SCarl Huang cmd = (struct wmi_wow_enable_cmd *)skb->data; 739479802b13SCarl Huang cmd->tlv_header = FIELD_PREP(WMI_TLV_TAG, WMI_TAG_WOW_ENABLE_CMD) | 739579802b13SCarl Huang FIELD_PREP(WMI_TLV_LEN, sizeof(*cmd) - TLV_HDR_SIZE); 739679802b13SCarl Huang 739779802b13SCarl Huang cmd->enable = 1; 739879802b13SCarl Huang cmd->pause_iface_config = WOW_IFACE_PAUSE_ENABLED; 739979802b13SCarl Huang ath11k_dbg(ar->ab, ATH11K_DBG_WMI, "wmi tlv wow enable\n"); 740079802b13SCarl Huang 740179802b13SCarl Huang return ath11k_wmi_cmd_send(ar->wmi, skb, WMI_WOW_ENABLE_CMDID); 740279802b13SCarl Huang } 7403