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