linux/drivers/net/wireless/ath/ath10k/wmi.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2005-2011 Atheros Communications Inc.
   3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
   4 *
   5 * Permission to use, copy, modify, and/or distribute this software for any
   6 * purpose with or without fee is hereby granted, provided that the above
   7 * copyright notice and this permission notice appear in all copies.
   8 *
   9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16 */
  17
  18#include <linux/skbuff.h>
  19#include <linux/ctype.h>
  20
  21#include "core.h"
  22#include "htc.h"
  23#include "debug.h"
  24#include "wmi.h"
  25#include "wmi-tlv.h"
  26#include "mac.h"
  27#include "testmode.h"
  28#include "wmi-ops.h"
  29#include "p2p.h"
  30#include "hw.h"
  31
  32#define ATH10K_WMI_BARRIER_ECHO_ID 0xBA991E9
  33#define ATH10K_WMI_BARRIER_TIMEOUT_HZ (3 * HZ)
  34
  35/* MAIN WMI cmd track */
  36static struct wmi_cmd_map wmi_cmd_map = {
  37        .init_cmdid = WMI_INIT_CMDID,
  38        .start_scan_cmdid = WMI_START_SCAN_CMDID,
  39        .stop_scan_cmdid = WMI_STOP_SCAN_CMDID,
  40        .scan_chan_list_cmdid = WMI_SCAN_CHAN_LIST_CMDID,
  41        .scan_sch_prio_tbl_cmdid = WMI_SCAN_SCH_PRIO_TBL_CMDID,
  42        .pdev_set_regdomain_cmdid = WMI_PDEV_SET_REGDOMAIN_CMDID,
  43        .pdev_set_channel_cmdid = WMI_PDEV_SET_CHANNEL_CMDID,
  44        .pdev_set_param_cmdid = WMI_PDEV_SET_PARAM_CMDID,
  45        .pdev_pktlog_enable_cmdid = WMI_PDEV_PKTLOG_ENABLE_CMDID,
  46        .pdev_pktlog_disable_cmdid = WMI_PDEV_PKTLOG_DISABLE_CMDID,
  47        .pdev_set_wmm_params_cmdid = WMI_PDEV_SET_WMM_PARAMS_CMDID,
  48        .pdev_set_ht_cap_ie_cmdid = WMI_PDEV_SET_HT_CAP_IE_CMDID,
  49        .pdev_set_vht_cap_ie_cmdid = WMI_PDEV_SET_VHT_CAP_IE_CMDID,
  50        .pdev_set_dscp_tid_map_cmdid = WMI_PDEV_SET_DSCP_TID_MAP_CMDID,
  51        .pdev_set_quiet_mode_cmdid = WMI_PDEV_SET_QUIET_MODE_CMDID,
  52        .pdev_green_ap_ps_enable_cmdid = WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID,
  53        .pdev_get_tpc_config_cmdid = WMI_PDEV_GET_TPC_CONFIG_CMDID,
  54        .pdev_set_base_macaddr_cmdid = WMI_PDEV_SET_BASE_MACADDR_CMDID,
  55        .vdev_create_cmdid = WMI_VDEV_CREATE_CMDID,
  56        .vdev_delete_cmdid = WMI_VDEV_DELETE_CMDID,
  57        .vdev_start_request_cmdid = WMI_VDEV_START_REQUEST_CMDID,
  58        .vdev_restart_request_cmdid = WMI_VDEV_RESTART_REQUEST_CMDID,
  59        .vdev_up_cmdid = WMI_VDEV_UP_CMDID,
  60        .vdev_stop_cmdid = WMI_VDEV_STOP_CMDID,
  61        .vdev_down_cmdid = WMI_VDEV_DOWN_CMDID,
  62        .vdev_set_param_cmdid = WMI_VDEV_SET_PARAM_CMDID,
  63        .vdev_install_key_cmdid = WMI_VDEV_INSTALL_KEY_CMDID,
  64        .peer_create_cmdid = WMI_PEER_CREATE_CMDID,
  65        .peer_delete_cmdid = WMI_PEER_DELETE_CMDID,
  66        .peer_flush_tids_cmdid = WMI_PEER_FLUSH_TIDS_CMDID,
  67        .peer_set_param_cmdid = WMI_PEER_SET_PARAM_CMDID,
  68        .peer_assoc_cmdid = WMI_PEER_ASSOC_CMDID,
  69        .peer_add_wds_entry_cmdid = WMI_PEER_ADD_WDS_ENTRY_CMDID,
  70        .peer_remove_wds_entry_cmdid = WMI_PEER_REMOVE_WDS_ENTRY_CMDID,
  71        .peer_mcast_group_cmdid = WMI_PEER_MCAST_GROUP_CMDID,
  72        .bcn_tx_cmdid = WMI_BCN_TX_CMDID,
  73        .pdev_send_bcn_cmdid = WMI_PDEV_SEND_BCN_CMDID,
  74        .bcn_tmpl_cmdid = WMI_BCN_TMPL_CMDID,
  75        .bcn_filter_rx_cmdid = WMI_BCN_FILTER_RX_CMDID,
  76        .prb_req_filter_rx_cmdid = WMI_PRB_REQ_FILTER_RX_CMDID,
  77        .mgmt_tx_cmdid = WMI_MGMT_TX_CMDID,
  78        .prb_tmpl_cmdid = WMI_PRB_TMPL_CMDID,
  79        .addba_clear_resp_cmdid = WMI_ADDBA_CLEAR_RESP_CMDID,
  80        .addba_send_cmdid = WMI_ADDBA_SEND_CMDID,
  81        .addba_status_cmdid = WMI_ADDBA_STATUS_CMDID,
  82        .delba_send_cmdid = WMI_DELBA_SEND_CMDID,
  83        .addba_set_resp_cmdid = WMI_ADDBA_SET_RESP_CMDID,
  84        .send_singleamsdu_cmdid = WMI_SEND_SINGLEAMSDU_CMDID,
  85        .sta_powersave_mode_cmdid = WMI_STA_POWERSAVE_MODE_CMDID,
  86        .sta_powersave_param_cmdid = WMI_STA_POWERSAVE_PARAM_CMDID,
  87        .sta_mimo_ps_mode_cmdid = WMI_STA_MIMO_PS_MODE_CMDID,
  88        .pdev_dfs_enable_cmdid = WMI_PDEV_DFS_ENABLE_CMDID,
  89        .pdev_dfs_disable_cmdid = WMI_PDEV_DFS_DISABLE_CMDID,
  90        .roam_scan_mode = WMI_ROAM_SCAN_MODE,
  91        .roam_scan_rssi_threshold = WMI_ROAM_SCAN_RSSI_THRESHOLD,
  92        .roam_scan_period = WMI_ROAM_SCAN_PERIOD,
  93        .roam_scan_rssi_change_threshold = WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
  94        .roam_ap_profile = WMI_ROAM_AP_PROFILE,
  95        .ofl_scan_add_ap_profile = WMI_ROAM_AP_PROFILE,
  96        .ofl_scan_remove_ap_profile = WMI_OFL_SCAN_REMOVE_AP_PROFILE,
  97        .ofl_scan_period = WMI_OFL_SCAN_PERIOD,
  98        .p2p_dev_set_device_info = WMI_P2P_DEV_SET_DEVICE_INFO,
  99        .p2p_dev_set_discoverability = WMI_P2P_DEV_SET_DISCOVERABILITY,
 100        .p2p_go_set_beacon_ie = WMI_P2P_GO_SET_BEACON_IE,
 101        .p2p_go_set_probe_resp_ie = WMI_P2P_GO_SET_PROBE_RESP_IE,
 102        .p2p_set_vendor_ie_data_cmdid = WMI_P2P_SET_VENDOR_IE_DATA_CMDID,
 103        .ap_ps_peer_param_cmdid = WMI_AP_PS_PEER_PARAM_CMDID,
 104        .ap_ps_peer_uapsd_coex_cmdid = WMI_AP_PS_PEER_UAPSD_COEX_CMDID,
 105        .peer_rate_retry_sched_cmdid = WMI_PEER_RATE_RETRY_SCHED_CMDID,
 106        .wlan_profile_trigger_cmdid = WMI_WLAN_PROFILE_TRIGGER_CMDID,
 107        .wlan_profile_set_hist_intvl_cmdid =
 108                                WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
 109        .wlan_profile_get_profile_data_cmdid =
 110                                WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
 111        .wlan_profile_enable_profile_id_cmdid =
 112                                WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
 113        .wlan_profile_list_profile_id_cmdid =
 114                                WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
 115        .pdev_suspend_cmdid = WMI_PDEV_SUSPEND_CMDID,
 116        .pdev_resume_cmdid = WMI_PDEV_RESUME_CMDID,
 117        .add_bcn_filter_cmdid = WMI_ADD_BCN_FILTER_CMDID,
 118        .rmv_bcn_filter_cmdid = WMI_RMV_BCN_FILTER_CMDID,
 119        .wow_add_wake_pattern_cmdid = WMI_WOW_ADD_WAKE_PATTERN_CMDID,
 120        .wow_del_wake_pattern_cmdid = WMI_WOW_DEL_WAKE_PATTERN_CMDID,
 121        .wow_enable_disable_wake_event_cmdid =
 122                                WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
 123        .wow_enable_cmdid = WMI_WOW_ENABLE_CMDID,
 124        .wow_hostwakeup_from_sleep_cmdid = WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
 125        .rtt_measreq_cmdid = WMI_RTT_MEASREQ_CMDID,
 126        .rtt_tsf_cmdid = WMI_RTT_TSF_CMDID,
 127        .vdev_spectral_scan_configure_cmdid =
 128                                WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
 129        .vdev_spectral_scan_enable_cmdid = WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
 130        .request_stats_cmdid = WMI_REQUEST_STATS_CMDID,
 131        .set_arp_ns_offload_cmdid = WMI_SET_ARP_NS_OFFLOAD_CMDID,
 132        .network_list_offload_config_cmdid =
 133                                WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
 134        .gtk_offload_cmdid = WMI_GTK_OFFLOAD_CMDID,
 135        .csa_offload_enable_cmdid = WMI_CSA_OFFLOAD_ENABLE_CMDID,
 136        .csa_offload_chanswitch_cmdid = WMI_CSA_OFFLOAD_CHANSWITCH_CMDID,
 137        .chatter_set_mode_cmdid = WMI_CHATTER_SET_MODE_CMDID,
 138        .peer_tid_addba_cmdid = WMI_PEER_TID_ADDBA_CMDID,
 139        .peer_tid_delba_cmdid = WMI_PEER_TID_DELBA_CMDID,
 140        .sta_dtim_ps_method_cmdid = WMI_STA_DTIM_PS_METHOD_CMDID,
 141        .sta_uapsd_auto_trig_cmdid = WMI_STA_UAPSD_AUTO_TRIG_CMDID,
 142        .sta_keepalive_cmd = WMI_STA_KEEPALIVE_CMD,
 143        .echo_cmdid = WMI_ECHO_CMDID,
 144        .pdev_utf_cmdid = WMI_PDEV_UTF_CMDID,
 145        .dbglog_cfg_cmdid = WMI_DBGLOG_CFG_CMDID,
 146        .pdev_qvit_cmdid = WMI_PDEV_QVIT_CMDID,
 147        .pdev_ftm_intg_cmdid = WMI_PDEV_FTM_INTG_CMDID,
 148        .vdev_set_keepalive_cmdid = WMI_VDEV_SET_KEEPALIVE_CMDID,
 149        .vdev_get_keepalive_cmdid = WMI_VDEV_GET_KEEPALIVE_CMDID,
 150        .force_fw_hang_cmdid = WMI_FORCE_FW_HANG_CMDID,
 151        .gpio_config_cmdid = WMI_GPIO_CONFIG_CMDID,
 152        .gpio_output_cmdid = WMI_GPIO_OUTPUT_CMDID,
 153        .pdev_get_temperature_cmdid = WMI_CMD_UNSUPPORTED,
 154        .pdev_enable_adaptive_cca_cmdid = WMI_CMD_UNSUPPORTED,
 155        .scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
 156        .vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
 157        .vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
 158        .wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
 159        .wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
 160        .wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
 161        .wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
 162        .peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
 163        .peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
 164        .rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 165        .oem_req_cmdid = WMI_CMD_UNSUPPORTED,
 166        .nan_cmdid = WMI_CMD_UNSUPPORTED,
 167        .vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
 168        .qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
 169        .pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
 170        .pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
 171        .peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
 172        .peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
 173        .peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
 174        .pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
 175        .pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
 176        .pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
 177        .pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
 178        .pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
 179        .pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
 180        .tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
 181        .fwtest_cmdid = WMI_CMD_UNSUPPORTED,
 182        .vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
 183        .peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
 184        .pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
 185        .pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
 186        .pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
 187        .pdev_get_nfcal_power_cmdid = WMI_CMD_UNSUPPORTED,
 188        .pdev_get_tpc_cmdid = WMI_CMD_UNSUPPORTED,
 189        .pdev_get_ast_info_cmdid = WMI_CMD_UNSUPPORTED,
 190        .vdev_set_dscp_tid_map_cmdid = WMI_CMD_UNSUPPORTED,
 191        .pdev_get_info_cmdid = WMI_CMD_UNSUPPORTED,
 192        .vdev_get_info_cmdid = WMI_CMD_UNSUPPORTED,
 193        .vdev_filter_neighbor_rx_packets_cmdid = WMI_CMD_UNSUPPORTED,
 194        .mu_cal_start_cmdid = WMI_CMD_UNSUPPORTED,
 195        .set_cca_params_cmdid = WMI_CMD_UNSUPPORTED,
 196        .pdev_bss_chan_info_request_cmdid = WMI_CMD_UNSUPPORTED,
 197};
 198
 199/* 10.X WMI cmd track */
 200static struct wmi_cmd_map wmi_10x_cmd_map = {
 201        .init_cmdid = WMI_10X_INIT_CMDID,
 202        .start_scan_cmdid = WMI_10X_START_SCAN_CMDID,
 203        .stop_scan_cmdid = WMI_10X_STOP_SCAN_CMDID,
 204        .scan_chan_list_cmdid = WMI_10X_SCAN_CHAN_LIST_CMDID,
 205        .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
 206        .pdev_set_regdomain_cmdid = WMI_10X_PDEV_SET_REGDOMAIN_CMDID,
 207        .pdev_set_channel_cmdid = WMI_10X_PDEV_SET_CHANNEL_CMDID,
 208        .pdev_set_param_cmdid = WMI_10X_PDEV_SET_PARAM_CMDID,
 209        .pdev_pktlog_enable_cmdid = WMI_10X_PDEV_PKTLOG_ENABLE_CMDID,
 210        .pdev_pktlog_disable_cmdid = WMI_10X_PDEV_PKTLOG_DISABLE_CMDID,
 211        .pdev_set_wmm_params_cmdid = WMI_10X_PDEV_SET_WMM_PARAMS_CMDID,
 212        .pdev_set_ht_cap_ie_cmdid = WMI_10X_PDEV_SET_HT_CAP_IE_CMDID,
 213        .pdev_set_vht_cap_ie_cmdid = WMI_10X_PDEV_SET_VHT_CAP_IE_CMDID,
 214        .pdev_set_dscp_tid_map_cmdid = WMI_10X_PDEV_SET_DSCP_TID_MAP_CMDID,
 215        .pdev_set_quiet_mode_cmdid = WMI_10X_PDEV_SET_QUIET_MODE_CMDID,
 216        .pdev_green_ap_ps_enable_cmdid = WMI_10X_PDEV_GREEN_AP_PS_ENABLE_CMDID,
 217        .pdev_get_tpc_config_cmdid = WMI_10X_PDEV_GET_TPC_CONFIG_CMDID,
 218        .pdev_set_base_macaddr_cmdid = WMI_10X_PDEV_SET_BASE_MACADDR_CMDID,
 219        .vdev_create_cmdid = WMI_10X_VDEV_CREATE_CMDID,
 220        .vdev_delete_cmdid = WMI_10X_VDEV_DELETE_CMDID,
 221        .vdev_start_request_cmdid = WMI_10X_VDEV_START_REQUEST_CMDID,
 222        .vdev_restart_request_cmdid = WMI_10X_VDEV_RESTART_REQUEST_CMDID,
 223        .vdev_up_cmdid = WMI_10X_VDEV_UP_CMDID,
 224        .vdev_stop_cmdid = WMI_10X_VDEV_STOP_CMDID,
 225        .vdev_down_cmdid = WMI_10X_VDEV_DOWN_CMDID,
 226        .vdev_set_param_cmdid = WMI_10X_VDEV_SET_PARAM_CMDID,
 227        .vdev_install_key_cmdid = WMI_10X_VDEV_INSTALL_KEY_CMDID,
 228        .peer_create_cmdid = WMI_10X_PEER_CREATE_CMDID,
 229        .peer_delete_cmdid = WMI_10X_PEER_DELETE_CMDID,
 230        .peer_flush_tids_cmdid = WMI_10X_PEER_FLUSH_TIDS_CMDID,
 231        .peer_set_param_cmdid = WMI_10X_PEER_SET_PARAM_CMDID,
 232        .peer_assoc_cmdid = WMI_10X_PEER_ASSOC_CMDID,
 233        .peer_add_wds_entry_cmdid = WMI_10X_PEER_ADD_WDS_ENTRY_CMDID,
 234        .peer_remove_wds_entry_cmdid = WMI_10X_PEER_REMOVE_WDS_ENTRY_CMDID,
 235        .peer_mcast_group_cmdid = WMI_10X_PEER_MCAST_GROUP_CMDID,
 236        .bcn_tx_cmdid = WMI_10X_BCN_TX_CMDID,
 237        .pdev_send_bcn_cmdid = WMI_10X_PDEV_SEND_BCN_CMDID,
 238        .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
 239        .bcn_filter_rx_cmdid = WMI_10X_BCN_FILTER_RX_CMDID,
 240        .prb_req_filter_rx_cmdid = WMI_10X_PRB_REQ_FILTER_RX_CMDID,
 241        .mgmt_tx_cmdid = WMI_10X_MGMT_TX_CMDID,
 242        .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
 243        .addba_clear_resp_cmdid = WMI_10X_ADDBA_CLEAR_RESP_CMDID,
 244        .addba_send_cmdid = WMI_10X_ADDBA_SEND_CMDID,
 245        .addba_status_cmdid = WMI_10X_ADDBA_STATUS_CMDID,
 246        .delba_send_cmdid = WMI_10X_DELBA_SEND_CMDID,
 247        .addba_set_resp_cmdid = WMI_10X_ADDBA_SET_RESP_CMDID,
 248        .send_singleamsdu_cmdid = WMI_10X_SEND_SINGLEAMSDU_CMDID,
 249        .sta_powersave_mode_cmdid = WMI_10X_STA_POWERSAVE_MODE_CMDID,
 250        .sta_powersave_param_cmdid = WMI_10X_STA_POWERSAVE_PARAM_CMDID,
 251        .sta_mimo_ps_mode_cmdid = WMI_10X_STA_MIMO_PS_MODE_CMDID,
 252        .pdev_dfs_enable_cmdid = WMI_10X_PDEV_DFS_ENABLE_CMDID,
 253        .pdev_dfs_disable_cmdid = WMI_10X_PDEV_DFS_DISABLE_CMDID,
 254        .roam_scan_mode = WMI_10X_ROAM_SCAN_MODE,
 255        .roam_scan_rssi_threshold = WMI_10X_ROAM_SCAN_RSSI_THRESHOLD,
 256        .roam_scan_period = WMI_10X_ROAM_SCAN_PERIOD,
 257        .roam_scan_rssi_change_threshold =
 258                                WMI_10X_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
 259        .roam_ap_profile = WMI_10X_ROAM_AP_PROFILE,
 260        .ofl_scan_add_ap_profile = WMI_10X_OFL_SCAN_ADD_AP_PROFILE,
 261        .ofl_scan_remove_ap_profile = WMI_10X_OFL_SCAN_REMOVE_AP_PROFILE,
 262        .ofl_scan_period = WMI_10X_OFL_SCAN_PERIOD,
 263        .p2p_dev_set_device_info = WMI_10X_P2P_DEV_SET_DEVICE_INFO,
 264        .p2p_dev_set_discoverability = WMI_10X_P2P_DEV_SET_DISCOVERABILITY,
 265        .p2p_go_set_beacon_ie = WMI_10X_P2P_GO_SET_BEACON_IE,
 266        .p2p_go_set_probe_resp_ie = WMI_10X_P2P_GO_SET_PROBE_RESP_IE,
 267        .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
 268        .ap_ps_peer_param_cmdid = WMI_10X_AP_PS_PEER_PARAM_CMDID,
 269        .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
 270        .peer_rate_retry_sched_cmdid = WMI_10X_PEER_RATE_RETRY_SCHED_CMDID,
 271        .wlan_profile_trigger_cmdid = WMI_10X_WLAN_PROFILE_TRIGGER_CMDID,
 272        .wlan_profile_set_hist_intvl_cmdid =
 273                                WMI_10X_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
 274        .wlan_profile_get_profile_data_cmdid =
 275                                WMI_10X_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
 276        .wlan_profile_enable_profile_id_cmdid =
 277                                WMI_10X_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
 278        .wlan_profile_list_profile_id_cmdid =
 279                                WMI_10X_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
 280        .pdev_suspend_cmdid = WMI_10X_PDEV_SUSPEND_CMDID,
 281        .pdev_resume_cmdid = WMI_10X_PDEV_RESUME_CMDID,
 282        .add_bcn_filter_cmdid = WMI_10X_ADD_BCN_FILTER_CMDID,
 283        .rmv_bcn_filter_cmdid = WMI_10X_RMV_BCN_FILTER_CMDID,
 284        .wow_add_wake_pattern_cmdid = WMI_10X_WOW_ADD_WAKE_PATTERN_CMDID,
 285        .wow_del_wake_pattern_cmdid = WMI_10X_WOW_DEL_WAKE_PATTERN_CMDID,
 286        .wow_enable_disable_wake_event_cmdid =
 287                                WMI_10X_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
 288        .wow_enable_cmdid = WMI_10X_WOW_ENABLE_CMDID,
 289        .wow_hostwakeup_from_sleep_cmdid =
 290                                WMI_10X_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
 291        .rtt_measreq_cmdid = WMI_10X_RTT_MEASREQ_CMDID,
 292        .rtt_tsf_cmdid = WMI_10X_RTT_TSF_CMDID,
 293        .vdev_spectral_scan_configure_cmdid =
 294                                WMI_10X_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
 295        .vdev_spectral_scan_enable_cmdid =
 296                                WMI_10X_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
 297        .request_stats_cmdid = WMI_10X_REQUEST_STATS_CMDID,
 298        .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
 299        .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
 300        .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
 301        .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
 302        .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
 303        .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
 304        .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
 305        .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
 306        .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
 307        .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
 308        .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
 309        .echo_cmdid = WMI_10X_ECHO_CMDID,
 310        .pdev_utf_cmdid = WMI_10X_PDEV_UTF_CMDID,
 311        .dbglog_cfg_cmdid = WMI_10X_DBGLOG_CFG_CMDID,
 312        .pdev_qvit_cmdid = WMI_10X_PDEV_QVIT_CMDID,
 313        .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
 314        .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 315        .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 316        .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
 317        .gpio_config_cmdid = WMI_10X_GPIO_CONFIG_CMDID,
 318        .gpio_output_cmdid = WMI_10X_GPIO_OUTPUT_CMDID,
 319        .pdev_get_temperature_cmdid = WMI_CMD_UNSUPPORTED,
 320        .pdev_enable_adaptive_cca_cmdid = WMI_CMD_UNSUPPORTED,
 321        .scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
 322        .vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
 323        .vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
 324        .wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
 325        .wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
 326        .wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
 327        .wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
 328        .peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
 329        .peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
 330        .rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 331        .oem_req_cmdid = WMI_CMD_UNSUPPORTED,
 332        .nan_cmdid = WMI_CMD_UNSUPPORTED,
 333        .vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
 334        .qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
 335        .pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
 336        .pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
 337        .peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
 338        .peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
 339        .peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
 340        .pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
 341        .pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
 342        .pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
 343        .pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
 344        .pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
 345        .pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
 346        .tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
 347        .fwtest_cmdid = WMI_CMD_UNSUPPORTED,
 348        .vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
 349        .peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
 350        .pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
 351        .pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
 352        .pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
 353        .pdev_get_nfcal_power_cmdid = WMI_CMD_UNSUPPORTED,
 354        .pdev_get_tpc_cmdid = WMI_CMD_UNSUPPORTED,
 355        .pdev_get_ast_info_cmdid = WMI_CMD_UNSUPPORTED,
 356        .vdev_set_dscp_tid_map_cmdid = WMI_CMD_UNSUPPORTED,
 357        .pdev_get_info_cmdid = WMI_CMD_UNSUPPORTED,
 358        .vdev_get_info_cmdid = WMI_CMD_UNSUPPORTED,
 359        .vdev_filter_neighbor_rx_packets_cmdid = WMI_CMD_UNSUPPORTED,
 360        .mu_cal_start_cmdid = WMI_CMD_UNSUPPORTED,
 361        .set_cca_params_cmdid = WMI_CMD_UNSUPPORTED,
 362        .pdev_bss_chan_info_request_cmdid = WMI_CMD_UNSUPPORTED,
 363};
 364
 365/* 10.2.4 WMI cmd track */
 366static struct wmi_cmd_map wmi_10_2_4_cmd_map = {
 367        .init_cmdid = WMI_10_2_INIT_CMDID,
 368        .start_scan_cmdid = WMI_10_2_START_SCAN_CMDID,
 369        .stop_scan_cmdid = WMI_10_2_STOP_SCAN_CMDID,
 370        .scan_chan_list_cmdid = WMI_10_2_SCAN_CHAN_LIST_CMDID,
 371        .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
 372        .pdev_set_regdomain_cmdid = WMI_10_2_PDEV_SET_REGDOMAIN_CMDID,
 373        .pdev_set_channel_cmdid = WMI_10_2_PDEV_SET_CHANNEL_CMDID,
 374        .pdev_set_param_cmdid = WMI_10_2_PDEV_SET_PARAM_CMDID,
 375        .pdev_pktlog_enable_cmdid = WMI_10_2_PDEV_PKTLOG_ENABLE_CMDID,
 376        .pdev_pktlog_disable_cmdid = WMI_10_2_PDEV_PKTLOG_DISABLE_CMDID,
 377        .pdev_set_wmm_params_cmdid = WMI_10_2_PDEV_SET_WMM_PARAMS_CMDID,
 378        .pdev_set_ht_cap_ie_cmdid = WMI_10_2_PDEV_SET_HT_CAP_IE_CMDID,
 379        .pdev_set_vht_cap_ie_cmdid = WMI_10_2_PDEV_SET_VHT_CAP_IE_CMDID,
 380        .pdev_set_quiet_mode_cmdid = WMI_10_2_PDEV_SET_QUIET_MODE_CMDID,
 381        .pdev_green_ap_ps_enable_cmdid = WMI_10_2_PDEV_GREEN_AP_PS_ENABLE_CMDID,
 382        .pdev_get_tpc_config_cmdid = WMI_10_2_PDEV_GET_TPC_CONFIG_CMDID,
 383        .pdev_set_base_macaddr_cmdid = WMI_10_2_PDEV_SET_BASE_MACADDR_CMDID,
 384        .vdev_create_cmdid = WMI_10_2_VDEV_CREATE_CMDID,
 385        .vdev_delete_cmdid = WMI_10_2_VDEV_DELETE_CMDID,
 386        .vdev_start_request_cmdid = WMI_10_2_VDEV_START_REQUEST_CMDID,
 387        .vdev_restart_request_cmdid = WMI_10_2_VDEV_RESTART_REQUEST_CMDID,
 388        .vdev_up_cmdid = WMI_10_2_VDEV_UP_CMDID,
 389        .vdev_stop_cmdid = WMI_10_2_VDEV_STOP_CMDID,
 390        .vdev_down_cmdid = WMI_10_2_VDEV_DOWN_CMDID,
 391        .vdev_set_param_cmdid = WMI_10_2_VDEV_SET_PARAM_CMDID,
 392        .vdev_install_key_cmdid = WMI_10_2_VDEV_INSTALL_KEY_CMDID,
 393        .peer_create_cmdid = WMI_10_2_PEER_CREATE_CMDID,
 394        .peer_delete_cmdid = WMI_10_2_PEER_DELETE_CMDID,
 395        .peer_flush_tids_cmdid = WMI_10_2_PEER_FLUSH_TIDS_CMDID,
 396        .peer_set_param_cmdid = WMI_10_2_PEER_SET_PARAM_CMDID,
 397        .peer_assoc_cmdid = WMI_10_2_PEER_ASSOC_CMDID,
 398        .peer_add_wds_entry_cmdid = WMI_10_2_PEER_ADD_WDS_ENTRY_CMDID,
 399        .peer_remove_wds_entry_cmdid = WMI_10_2_PEER_REMOVE_WDS_ENTRY_CMDID,
 400        .peer_mcast_group_cmdid = WMI_10_2_PEER_MCAST_GROUP_CMDID,
 401        .bcn_tx_cmdid = WMI_10_2_BCN_TX_CMDID,
 402        .pdev_send_bcn_cmdid = WMI_10_2_PDEV_SEND_BCN_CMDID,
 403        .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
 404        .bcn_filter_rx_cmdid = WMI_10_2_BCN_FILTER_RX_CMDID,
 405        .prb_req_filter_rx_cmdid = WMI_10_2_PRB_REQ_FILTER_RX_CMDID,
 406        .mgmt_tx_cmdid = WMI_10_2_MGMT_TX_CMDID,
 407        .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
 408        .addba_clear_resp_cmdid = WMI_10_2_ADDBA_CLEAR_RESP_CMDID,
 409        .addba_send_cmdid = WMI_10_2_ADDBA_SEND_CMDID,
 410        .addba_status_cmdid = WMI_10_2_ADDBA_STATUS_CMDID,
 411        .delba_send_cmdid = WMI_10_2_DELBA_SEND_CMDID,
 412        .addba_set_resp_cmdid = WMI_10_2_ADDBA_SET_RESP_CMDID,
 413        .send_singleamsdu_cmdid = WMI_10_2_SEND_SINGLEAMSDU_CMDID,
 414        .sta_powersave_mode_cmdid = WMI_10_2_STA_POWERSAVE_MODE_CMDID,
 415        .sta_powersave_param_cmdid = WMI_10_2_STA_POWERSAVE_PARAM_CMDID,
 416        .sta_mimo_ps_mode_cmdid = WMI_10_2_STA_MIMO_PS_MODE_CMDID,
 417        .pdev_dfs_enable_cmdid = WMI_10_2_PDEV_DFS_ENABLE_CMDID,
 418        .pdev_dfs_disable_cmdid = WMI_10_2_PDEV_DFS_DISABLE_CMDID,
 419        .roam_scan_mode = WMI_10_2_ROAM_SCAN_MODE,
 420        .roam_scan_rssi_threshold = WMI_10_2_ROAM_SCAN_RSSI_THRESHOLD,
 421        .roam_scan_period = WMI_10_2_ROAM_SCAN_PERIOD,
 422        .roam_scan_rssi_change_threshold =
 423                                WMI_10_2_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
 424        .roam_ap_profile = WMI_10_2_ROAM_AP_PROFILE,
 425        .ofl_scan_add_ap_profile = WMI_10_2_OFL_SCAN_ADD_AP_PROFILE,
 426        .ofl_scan_remove_ap_profile = WMI_10_2_OFL_SCAN_REMOVE_AP_PROFILE,
 427        .ofl_scan_period = WMI_10_2_OFL_SCAN_PERIOD,
 428        .p2p_dev_set_device_info = WMI_10_2_P2P_DEV_SET_DEVICE_INFO,
 429        .p2p_dev_set_discoverability = WMI_10_2_P2P_DEV_SET_DISCOVERABILITY,
 430        .p2p_go_set_beacon_ie = WMI_10_2_P2P_GO_SET_BEACON_IE,
 431        .p2p_go_set_probe_resp_ie = WMI_10_2_P2P_GO_SET_PROBE_RESP_IE,
 432        .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
 433        .ap_ps_peer_param_cmdid = WMI_10_2_AP_PS_PEER_PARAM_CMDID,
 434        .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
 435        .peer_rate_retry_sched_cmdid = WMI_10_2_PEER_RATE_RETRY_SCHED_CMDID,
 436        .wlan_profile_trigger_cmdid = WMI_10_2_WLAN_PROFILE_TRIGGER_CMDID,
 437        .wlan_profile_set_hist_intvl_cmdid =
 438                                WMI_10_2_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
 439        .wlan_profile_get_profile_data_cmdid =
 440                                WMI_10_2_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
 441        .wlan_profile_enable_profile_id_cmdid =
 442                                WMI_10_2_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
 443        .wlan_profile_list_profile_id_cmdid =
 444                                WMI_10_2_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
 445        .pdev_suspend_cmdid = WMI_10_2_PDEV_SUSPEND_CMDID,
 446        .pdev_resume_cmdid = WMI_10_2_PDEV_RESUME_CMDID,
 447        .add_bcn_filter_cmdid = WMI_10_2_ADD_BCN_FILTER_CMDID,
 448        .rmv_bcn_filter_cmdid = WMI_10_2_RMV_BCN_FILTER_CMDID,
 449        .wow_add_wake_pattern_cmdid = WMI_10_2_WOW_ADD_WAKE_PATTERN_CMDID,
 450        .wow_del_wake_pattern_cmdid = WMI_10_2_WOW_DEL_WAKE_PATTERN_CMDID,
 451        .wow_enable_disable_wake_event_cmdid =
 452                                WMI_10_2_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
 453        .wow_enable_cmdid = WMI_10_2_WOW_ENABLE_CMDID,
 454        .wow_hostwakeup_from_sleep_cmdid =
 455                                WMI_10_2_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
 456        .rtt_measreq_cmdid = WMI_10_2_RTT_MEASREQ_CMDID,
 457        .rtt_tsf_cmdid = WMI_10_2_RTT_TSF_CMDID,
 458        .vdev_spectral_scan_configure_cmdid =
 459                                WMI_10_2_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
 460        .vdev_spectral_scan_enable_cmdid =
 461                                WMI_10_2_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
 462        .request_stats_cmdid = WMI_10_2_REQUEST_STATS_CMDID,
 463        .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
 464        .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
 465        .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
 466        .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
 467        .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
 468        .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
 469        .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
 470        .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
 471        .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
 472        .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
 473        .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
 474        .echo_cmdid = WMI_10_2_ECHO_CMDID,
 475        .pdev_utf_cmdid = WMI_10_2_PDEV_UTF_CMDID,
 476        .dbglog_cfg_cmdid = WMI_10_2_DBGLOG_CFG_CMDID,
 477        .pdev_qvit_cmdid = WMI_10_2_PDEV_QVIT_CMDID,
 478        .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
 479        .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 480        .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 481        .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
 482        .gpio_config_cmdid = WMI_10_2_GPIO_CONFIG_CMDID,
 483        .gpio_output_cmdid = WMI_10_2_GPIO_OUTPUT_CMDID,
 484        .pdev_get_temperature_cmdid = WMI_10_2_PDEV_GET_TEMPERATURE_CMDID,
 485        .pdev_enable_adaptive_cca_cmdid = WMI_10_2_SET_CCA_PARAMS,
 486        .scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
 487        .vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
 488        .vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
 489        .wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
 490        .wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
 491        .wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
 492        .wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
 493        .peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
 494        .peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
 495        .rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
 496        .oem_req_cmdid = WMI_CMD_UNSUPPORTED,
 497        .nan_cmdid = WMI_CMD_UNSUPPORTED,
 498        .vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
 499        .qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
 500        .pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
 501        .pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
 502        .peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
 503        .peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
 504        .peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
 505        .pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
 506        .pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
 507        .pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
 508        .pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
 509        .pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
 510        .pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
 511        .tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
 512        .fwtest_cmdid = WMI_CMD_UNSUPPORTED,
 513        .vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
 514        .peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
 515        .pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
 516        .pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
 517        .pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
 518        .pdev_get_nfcal_power_cmdid = WMI_CMD_UNSUPPORTED,
 519        .pdev_get_tpc_cmdid = WMI_CMD_UNSUPPORTED,
 520        .pdev_get_ast_info_cmdid = WMI_CMD_UNSUPPORTED,
 521        .vdev_set_dscp_tid_map_cmdid = WMI_CMD_UNSUPPORTED,
 522        .pdev_get_info_cmdid = WMI_CMD_UNSUPPORTED,
 523        .vdev_get_info_cmdid = WMI_CMD_UNSUPPORTED,
 524        .vdev_filter_neighbor_rx_packets_cmdid = WMI_CMD_UNSUPPORTED,
 525        .mu_cal_start_cmdid = WMI_CMD_UNSUPPORTED,
 526        .set_cca_params_cmdid = WMI_CMD_UNSUPPORTED,
 527        .pdev_bss_chan_info_request_cmdid =
 528                WMI_10_2_PDEV_BSS_CHAN_INFO_REQUEST_CMDID,
 529};
 530
 531/* 10.4 WMI cmd track */
 532static struct wmi_cmd_map wmi_10_4_cmd_map = {
 533        .init_cmdid = WMI_10_4_INIT_CMDID,
 534        .start_scan_cmdid = WMI_10_4_START_SCAN_CMDID,
 535        .stop_scan_cmdid = WMI_10_4_STOP_SCAN_CMDID,
 536        .scan_chan_list_cmdid = WMI_10_4_SCAN_CHAN_LIST_CMDID,
 537        .scan_sch_prio_tbl_cmdid = WMI_10_4_SCAN_SCH_PRIO_TBL_CMDID,
 538        .pdev_set_regdomain_cmdid = WMI_10_4_PDEV_SET_REGDOMAIN_CMDID,
 539        .pdev_set_channel_cmdid = WMI_10_4_PDEV_SET_CHANNEL_CMDID,
 540        .pdev_set_param_cmdid = WMI_10_4_PDEV_SET_PARAM_CMDID,
 541        .pdev_pktlog_enable_cmdid = WMI_10_4_PDEV_PKTLOG_ENABLE_CMDID,
 542        .pdev_pktlog_disable_cmdid = WMI_10_4_PDEV_PKTLOG_DISABLE_CMDID,
 543        .pdev_set_wmm_params_cmdid = WMI_10_4_PDEV_SET_WMM_PARAMS_CMDID,
 544        .pdev_set_ht_cap_ie_cmdid = WMI_10_4_PDEV_SET_HT_CAP_IE_CMDID,
 545        .pdev_set_vht_cap_ie_cmdid = WMI_10_4_PDEV_SET_VHT_CAP_IE_CMDID,
 546        .pdev_set_dscp_tid_map_cmdid = WMI_10_4_PDEV_SET_DSCP_TID_MAP_CMDID,
 547        .pdev_set_quiet_mode_cmdid = WMI_10_4_PDEV_SET_QUIET_MODE_CMDID,
 548        .pdev_green_ap_ps_enable_cmdid = WMI_10_4_PDEV_GREEN_AP_PS_ENABLE_CMDID,
 549        .pdev_get_tpc_config_cmdid = WMI_10_4_PDEV_GET_TPC_CONFIG_CMDID,
 550        .pdev_set_base_macaddr_cmdid = WMI_10_4_PDEV_SET_BASE_MACADDR_CMDID,
 551        .vdev_create_cmdid = WMI_10_4_VDEV_CREATE_CMDID,
 552        .vdev_delete_cmdid = WMI_10_4_VDEV_DELETE_CMDID,
 553        .vdev_start_request_cmdid = WMI_10_4_VDEV_START_REQUEST_CMDID,
 554        .vdev_restart_request_cmdid = WMI_10_4_VDEV_RESTART_REQUEST_CMDID,
 555        .vdev_up_cmdid = WMI_10_4_VDEV_UP_CMDID,
 556        .vdev_stop_cmdid = WMI_10_4_VDEV_STOP_CMDID,
 557        .vdev_down_cmdid = WMI_10_4_VDEV_DOWN_CMDID,
 558        .vdev_set_param_cmdid = WMI_10_4_VDEV_SET_PARAM_CMDID,
 559        .vdev_install_key_cmdid = WMI_10_4_VDEV_INSTALL_KEY_CMDID,
 560        .peer_create_cmdid = WMI_10_4_PEER_CREATE_CMDID,
 561        .peer_delete_cmdid = WMI_10_4_PEER_DELETE_CMDID,
 562        .peer_flush_tids_cmdid = WMI_10_4_PEER_FLUSH_TIDS_CMDID,
 563        .peer_set_param_cmdid = WMI_10_4_PEER_SET_PARAM_CMDID,
 564        .peer_assoc_cmdid = WMI_10_4_PEER_ASSOC_CMDID,
 565        .peer_add_wds_entry_cmdid = WMI_10_4_PEER_ADD_WDS_ENTRY_CMDID,
 566        .peer_remove_wds_entry_cmdid = WMI_10_4_PEER_REMOVE_WDS_ENTRY_CMDID,
 567        .peer_mcast_group_cmdid = WMI_10_4_PEER_MCAST_GROUP_CMDID,
 568        .bcn_tx_cmdid = WMI_10_4_BCN_TX_CMDID,
 569        .pdev_send_bcn_cmdid = WMI_10_4_PDEV_SEND_BCN_CMDID,
 570        .bcn_tmpl_cmdid = WMI_10_4_BCN_PRB_TMPL_CMDID,
 571        .bcn_filter_rx_cmdid = WMI_10_4_BCN_FILTER_RX_CMDID,
 572        .prb_req_filter_rx_cmdid = WMI_10_4_PRB_REQ_FILTER_RX_CMDID,
 573        .mgmt_tx_cmdid = WMI_10_4_MGMT_TX_CMDID,
 574        .prb_tmpl_cmdid = WMI_10_4_PRB_TMPL_CMDID,
 575        .addba_clear_resp_cmdid = WMI_10_4_ADDBA_CLEAR_RESP_CMDID,
 576        .addba_send_cmdid = WMI_10_4_ADDBA_SEND_CMDID,
 577        .addba_status_cmdid = WMI_10_4_ADDBA_STATUS_CMDID,
 578        .delba_send_cmdid = WMI_10_4_DELBA_SEND_CMDID,
 579        .addba_set_resp_cmdid = WMI_10_4_ADDBA_SET_RESP_CMDID,
 580        .send_singleamsdu_cmdid = WMI_10_4_SEND_SINGLEAMSDU_CMDID,
 581        .sta_powersave_mode_cmdid = WMI_10_4_STA_POWERSAVE_MODE_CMDID,
 582        .sta_powersave_param_cmdid = WMI_10_4_STA_POWERSAVE_PARAM_CMDID,
 583        .sta_mimo_ps_mode_cmdid = WMI_10_4_STA_MIMO_PS_MODE_CMDID,
 584        .pdev_dfs_enable_cmdid = WMI_10_4_PDEV_DFS_ENABLE_CMDID,
 585        .pdev_dfs_disable_cmdid = WMI_10_4_PDEV_DFS_DISABLE_CMDID,
 586        .roam_scan_mode = WMI_10_4_ROAM_SCAN_MODE,
 587        .roam_scan_rssi_threshold = WMI_10_4_ROAM_SCAN_RSSI_THRESHOLD,
 588        .roam_scan_period = WMI_10_4_ROAM_SCAN_PERIOD,
 589        .roam_scan_rssi_change_threshold =
 590                                WMI_10_4_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
 591        .roam_ap_profile = WMI_10_4_ROAM_AP_PROFILE,
 592        .ofl_scan_add_ap_profile = WMI_10_4_OFL_SCAN_ADD_AP_PROFILE,
 593        .ofl_scan_remove_ap_profile = WMI_10_4_OFL_SCAN_REMOVE_AP_PROFILE,
 594        .ofl_scan_period = WMI_10_4_OFL_SCAN_PERIOD,
 595        .p2p_dev_set_device_info = WMI_10_4_P2P_DEV_SET_DEVICE_INFO,
 596        .p2p_dev_set_discoverability = WMI_10_4_P2P_DEV_SET_DISCOVERABILITY,
 597        .p2p_go_set_beacon_ie = WMI_10_4_P2P_GO_SET_BEACON_IE,
 598        .p2p_go_set_probe_resp_ie = WMI_10_4_P2P_GO_SET_PROBE_RESP_IE,
 599        .p2p_set_vendor_ie_data_cmdid = WMI_10_4_P2P_SET_VENDOR_IE_DATA_CMDID,
 600        .ap_ps_peer_param_cmdid = WMI_10_4_AP_PS_PEER_PARAM_CMDID,
 601        .ap_ps_peer_uapsd_coex_cmdid = WMI_10_4_AP_PS_PEER_UAPSD_COEX_CMDID,
 602        .peer_rate_retry_sched_cmdid = WMI_10_4_PEER_RATE_RETRY_SCHED_CMDID,
 603        .wlan_profile_trigger_cmdid = WMI_10_4_WLAN_PROFILE_TRIGGER_CMDID,
 604        .wlan_profile_set_hist_intvl_cmdid =
 605                                WMI_10_4_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
 606        .wlan_profile_get_profile_data_cmdid =
 607                                WMI_10_4_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
 608        .wlan_profile_enable_profile_id_cmdid =
 609                                WMI_10_4_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
 610        .wlan_profile_list_profile_id_cmdid =
 611                                WMI_10_4_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
 612        .pdev_suspend_cmdid = WMI_10_4_PDEV_SUSPEND_CMDID,
 613        .pdev_resume_cmdid = WMI_10_4_PDEV_RESUME_CMDID,
 614        .add_bcn_filter_cmdid = WMI_10_4_ADD_BCN_FILTER_CMDID,
 615        .rmv_bcn_filter_cmdid = WMI_10_4_RMV_BCN_FILTER_CMDID,
 616        .wow_add_wake_pattern_cmdid = WMI_10_4_WOW_ADD_WAKE_PATTERN_CMDID,
 617        .wow_del_wake_pattern_cmdid = WMI_10_4_WOW_DEL_WAKE_PATTERN_CMDID,
 618        .wow_enable_disable_wake_event_cmdid =
 619                                WMI_10_4_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
 620        .wow_enable_cmdid = WMI_10_4_WOW_ENABLE_CMDID,
 621        .wow_hostwakeup_from_sleep_cmdid =
 622                                WMI_10_4_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
 623        .rtt_measreq_cmdid = WMI_10_4_RTT_MEASREQ_CMDID,
 624        .rtt_tsf_cmdid = WMI_10_4_RTT_TSF_CMDID,
 625        .vdev_spectral_scan_configure_cmdid =
 626                                WMI_10_4_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
 627        .vdev_spectral_scan_enable_cmdid =
 628                                WMI_10_4_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
 629        .request_stats_cmdid = WMI_10_4_REQUEST_STATS_CMDID,
 630        .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
 631        .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
 632        .gtk_offload_cmdid = WMI_10_4_GTK_OFFLOAD_CMDID,
 633        .csa_offload_enable_cmdid = WMI_10_4_CSA_OFFLOAD_ENABLE_CMDID,
 634        .csa_offload_chanswitch_cmdid = WMI_10_4_CSA_OFFLOAD_CHANSWITCH_CMDID,
 635        .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
 636        .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
 637        .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
 638        .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
 639        .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
 640        .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
 641        .echo_cmdid = WMI_10_4_ECHO_CMDID,
 642        .pdev_utf_cmdid = WMI_10_4_PDEV_UTF_CMDID,
 643        .dbglog_cfg_cmdid = WMI_10_4_DBGLOG_CFG_CMDID,
 644        .pdev_qvit_cmdid = WMI_10_4_PDEV_QVIT_CMDID,
 645        .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
 646        .vdev_set_keepalive_cmdid = WMI_10_4_VDEV_SET_KEEPALIVE_CMDID,
 647        .vdev_get_keepalive_cmdid = WMI_10_4_VDEV_GET_KEEPALIVE_CMDID,
 648        .force_fw_hang_cmdid = WMI_10_4_FORCE_FW_HANG_CMDID,
 649        .gpio_config_cmdid = WMI_10_4_GPIO_CONFIG_CMDID,
 650        .gpio_output_cmdid = WMI_10_4_GPIO_OUTPUT_CMDID,
 651        .pdev_get_temperature_cmdid = WMI_10_4_PDEV_GET_TEMPERATURE_CMDID,
 652        .vdev_set_wmm_params_cmdid = WMI_CMD_UNSUPPORTED,
 653        .tdls_set_state_cmdid = WMI_CMD_UNSUPPORTED,
 654        .tdls_peer_update_cmdid = WMI_CMD_UNSUPPORTED,
 655        .adaptive_qcs_cmdid = WMI_CMD_UNSUPPORTED,
 656        .scan_update_request_cmdid = WMI_10_4_SCAN_UPDATE_REQUEST_CMDID,
 657        .vdev_standby_response_cmdid = WMI_10_4_VDEV_STANDBY_RESPONSE_CMDID,
 658        .vdev_resume_response_cmdid = WMI_10_4_VDEV_RESUME_RESPONSE_CMDID,
 659        .wlan_peer_caching_add_peer_cmdid =
 660                        WMI_10_4_WLAN_PEER_CACHING_ADD_PEER_CMDID,
 661        .wlan_peer_caching_evict_peer_cmdid =
 662                        WMI_10_4_WLAN_PEER_CACHING_EVICT_PEER_CMDID,
 663        .wlan_peer_caching_restore_peer_cmdid =
 664                        WMI_10_4_WLAN_PEER_CACHING_RESTORE_PEER_CMDID,
 665        .wlan_peer_caching_print_all_peers_info_cmdid =
 666                        WMI_10_4_WLAN_PEER_CACHING_PRINT_ALL_PEERS_INFO_CMDID,
 667        .peer_update_wds_entry_cmdid = WMI_10_4_PEER_UPDATE_WDS_ENTRY_CMDID,
 668        .peer_add_proxy_sta_entry_cmdid =
 669                        WMI_10_4_PEER_ADD_PROXY_STA_ENTRY_CMDID,
 670        .rtt_keepalive_cmdid = WMI_10_4_RTT_KEEPALIVE_CMDID,
 671        .oem_req_cmdid = WMI_10_4_OEM_REQ_CMDID,
 672        .nan_cmdid = WMI_10_4_NAN_CMDID,
 673        .vdev_ratemask_cmdid = WMI_10_4_VDEV_RATEMASK_CMDID,
 674        .qboost_cfg_cmdid = WMI_10_4_QBOOST_CFG_CMDID,
 675        .pdev_smart_ant_enable_cmdid = WMI_10_4_PDEV_SMART_ANT_ENABLE_CMDID,
 676        .pdev_smart_ant_set_rx_antenna_cmdid =
 677                        WMI_10_4_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID,
 678        .peer_smart_ant_set_tx_antenna_cmdid =
 679                        WMI_10_4_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID,
 680        .peer_smart_ant_set_train_info_cmdid =
 681                        WMI_10_4_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID,
 682        .peer_smart_ant_set_node_config_ops_cmdid =
 683                        WMI_10_4_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID,
 684        .pdev_set_antenna_switch_table_cmdid =
 685                        WMI_10_4_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID,
 686        .pdev_set_ctl_table_cmdid = WMI_10_4_PDEV_SET_CTL_TABLE_CMDID,
 687        .pdev_set_mimogain_table_cmdid = WMI_10_4_PDEV_SET_MIMOGAIN_TABLE_CMDID,
 688        .pdev_ratepwr_table_cmdid = WMI_10_4_PDEV_RATEPWR_TABLE_CMDID,
 689        .pdev_ratepwr_chainmsk_table_cmdid =
 690                        WMI_10_4_PDEV_RATEPWR_CHAINMSK_TABLE_CMDID,
 691        .pdev_fips_cmdid = WMI_10_4_PDEV_FIPS_CMDID,
 692        .tt_set_conf_cmdid = WMI_10_4_TT_SET_CONF_CMDID,
 693        .fwtest_cmdid = WMI_10_4_FWTEST_CMDID,
 694        .vdev_atf_request_cmdid = WMI_10_4_VDEV_ATF_REQUEST_CMDID,
 695        .peer_atf_request_cmdid = WMI_10_4_PEER_ATF_REQUEST_CMDID,
 696        .pdev_get_ani_cck_config_cmdid = WMI_10_4_PDEV_GET_ANI_CCK_CONFIG_CMDID,
 697        .pdev_get_ani_ofdm_config_cmdid =
 698                        WMI_10_4_PDEV_GET_ANI_OFDM_CONFIG_CMDID,
 699        .pdev_reserve_ast_entry_cmdid = WMI_10_4_PDEV_RESERVE_AST_ENTRY_CMDID,
 700        .pdev_get_nfcal_power_cmdid = WMI_10_4_PDEV_GET_NFCAL_POWER_CMDID,
 701        .pdev_get_tpc_cmdid = WMI_10_4_PDEV_GET_TPC_CMDID,
 702        .pdev_get_ast_info_cmdid = WMI_10_4_PDEV_GET_AST_INFO_CMDID,
 703        .vdev_set_dscp_tid_map_cmdid = WMI_10_4_VDEV_SET_DSCP_TID_MAP_CMDID,
 704        .pdev_get_info_cmdid = WMI_10_4_PDEV_GET_INFO_CMDID,
 705        .vdev_get_info_cmdid = WMI_10_4_VDEV_GET_INFO_CMDID,
 706        .vdev_filter_neighbor_rx_packets_cmdid =
 707                        WMI_10_4_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID,
 708        .mu_cal_start_cmdid = WMI_10_4_MU_CAL_START_CMDID,
 709        .set_cca_params_cmdid = WMI_10_4_SET_CCA_PARAMS_CMDID,
 710        .pdev_bss_chan_info_request_cmdid =
 711                        WMI_10_4_PDEV_BSS_CHAN_INFO_REQUEST_CMDID,
 712        .ext_resource_cfg_cmdid = WMI_10_4_EXT_RESOURCE_CFG_CMDID,
 713};
 714
 715/* MAIN WMI VDEV param map */
 716static struct wmi_vdev_param_map wmi_vdev_param_map = {
 717        .rts_threshold = WMI_VDEV_PARAM_RTS_THRESHOLD,
 718        .fragmentation_threshold = WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
 719        .beacon_interval = WMI_VDEV_PARAM_BEACON_INTERVAL,
 720        .listen_interval = WMI_VDEV_PARAM_LISTEN_INTERVAL,
 721        .multicast_rate = WMI_VDEV_PARAM_MULTICAST_RATE,
 722        .mgmt_tx_rate = WMI_VDEV_PARAM_MGMT_TX_RATE,
 723        .slot_time = WMI_VDEV_PARAM_SLOT_TIME,
 724        .preamble = WMI_VDEV_PARAM_PREAMBLE,
 725        .swba_time = WMI_VDEV_PARAM_SWBA_TIME,
 726        .wmi_vdev_stats_update_period = WMI_VDEV_STATS_UPDATE_PERIOD,
 727        .wmi_vdev_pwrsave_ageout_time = WMI_VDEV_PWRSAVE_AGEOUT_TIME,
 728        .wmi_vdev_host_swba_interval = WMI_VDEV_HOST_SWBA_INTERVAL,
 729        .dtim_period = WMI_VDEV_PARAM_DTIM_PERIOD,
 730        .wmi_vdev_oc_scheduler_air_time_limit =
 731                                        WMI_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
 732        .wds = WMI_VDEV_PARAM_WDS,
 733        .atim_window = WMI_VDEV_PARAM_ATIM_WINDOW,
 734        .bmiss_count_max = WMI_VDEV_PARAM_BMISS_COUNT_MAX,
 735        .bmiss_first_bcnt = WMI_VDEV_PARAM_BMISS_FIRST_BCNT,
 736        .bmiss_final_bcnt = WMI_VDEV_PARAM_BMISS_FINAL_BCNT,
 737        .feature_wmm = WMI_VDEV_PARAM_FEATURE_WMM,
 738        .chwidth = WMI_VDEV_PARAM_CHWIDTH,
 739        .chextoffset = WMI_VDEV_PARAM_CHEXTOFFSET,
 740        .disable_htprotection = WMI_VDEV_PARAM_DISABLE_HTPROTECTION,
 741        .sta_quickkickout = WMI_VDEV_PARAM_STA_QUICKKICKOUT,
 742        .mgmt_rate = WMI_VDEV_PARAM_MGMT_RATE,
 743        .protection_mode = WMI_VDEV_PARAM_PROTECTION_MODE,
 744        .fixed_rate = WMI_VDEV_PARAM_FIXED_RATE,
 745        .sgi = WMI_VDEV_PARAM_SGI,
 746        .ldpc = WMI_VDEV_PARAM_LDPC,
 747        .tx_stbc = WMI_VDEV_PARAM_TX_STBC,
 748        .rx_stbc = WMI_VDEV_PARAM_RX_STBC,
 749        .intra_bss_fwd = WMI_VDEV_PARAM_INTRA_BSS_FWD,
 750        .def_keyid = WMI_VDEV_PARAM_DEF_KEYID,
 751        .nss = WMI_VDEV_PARAM_NSS,
 752        .bcast_data_rate = WMI_VDEV_PARAM_BCAST_DATA_RATE,
 753        .mcast_data_rate = WMI_VDEV_PARAM_MCAST_DATA_RATE,
 754        .mcast_indicate = WMI_VDEV_PARAM_MCAST_INDICATE,
 755        .dhcp_indicate = WMI_VDEV_PARAM_DHCP_INDICATE,
 756        .unknown_dest_indicate = WMI_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
 757        .ap_keepalive_min_idle_inactive_time_secs =
 758                        WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
 759        .ap_keepalive_max_idle_inactive_time_secs =
 760                        WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
 761        .ap_keepalive_max_unresponsive_time_secs =
 762                        WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
 763        .ap_enable_nawds = WMI_VDEV_PARAM_AP_ENABLE_NAWDS,
 764        .mcast2ucast_set = WMI_VDEV_PARAM_UNSUPPORTED,
 765        .enable_rtscts = WMI_VDEV_PARAM_ENABLE_RTSCTS,
 766        .txbf = WMI_VDEV_PARAM_TXBF,
 767        .packet_powersave = WMI_VDEV_PARAM_PACKET_POWERSAVE,
 768        .drop_unencry = WMI_VDEV_PARAM_DROP_UNENCRY,
 769        .tx_encap_type = WMI_VDEV_PARAM_TX_ENCAP_TYPE,
 770        .ap_detect_out_of_sync_sleeping_sta_time_secs =
 771                                        WMI_VDEV_PARAM_UNSUPPORTED,
 772        .rc_num_retries = WMI_VDEV_PARAM_UNSUPPORTED,
 773        .cabq_maxdur = WMI_VDEV_PARAM_UNSUPPORTED,
 774        .mfptest_set = WMI_VDEV_PARAM_UNSUPPORTED,
 775        .rts_fixed_rate = WMI_VDEV_PARAM_UNSUPPORTED,
 776        .vht_sgimask = WMI_VDEV_PARAM_UNSUPPORTED,
 777        .vht80_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
 778        .early_rx_adjust_enable = WMI_VDEV_PARAM_UNSUPPORTED,
 779        .early_rx_tgt_bmiss_num = WMI_VDEV_PARAM_UNSUPPORTED,
 780        .early_rx_bmiss_sample_cycle = WMI_VDEV_PARAM_UNSUPPORTED,
 781        .early_rx_slop_step = WMI_VDEV_PARAM_UNSUPPORTED,
 782        .early_rx_init_slop = WMI_VDEV_PARAM_UNSUPPORTED,
 783        .early_rx_adjust_pause = WMI_VDEV_PARAM_UNSUPPORTED,
 784        .proxy_sta = WMI_VDEV_PARAM_UNSUPPORTED,
 785        .meru_vc = WMI_VDEV_PARAM_UNSUPPORTED,
 786        .rx_decap_type = WMI_VDEV_PARAM_UNSUPPORTED,
 787        .bw_nss_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
 788};
 789
 790/* 10.X WMI VDEV param map */
 791static struct wmi_vdev_param_map wmi_10x_vdev_param_map = {
 792        .rts_threshold = WMI_10X_VDEV_PARAM_RTS_THRESHOLD,
 793        .fragmentation_threshold = WMI_10X_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
 794        .beacon_interval = WMI_10X_VDEV_PARAM_BEACON_INTERVAL,
 795        .listen_interval = WMI_10X_VDEV_PARAM_LISTEN_INTERVAL,
 796        .multicast_rate = WMI_10X_VDEV_PARAM_MULTICAST_RATE,
 797        .mgmt_tx_rate = WMI_10X_VDEV_PARAM_MGMT_TX_RATE,
 798        .slot_time = WMI_10X_VDEV_PARAM_SLOT_TIME,
 799        .preamble = WMI_10X_VDEV_PARAM_PREAMBLE,
 800        .swba_time = WMI_10X_VDEV_PARAM_SWBA_TIME,
 801        .wmi_vdev_stats_update_period = WMI_10X_VDEV_STATS_UPDATE_PERIOD,
 802        .wmi_vdev_pwrsave_ageout_time = WMI_10X_VDEV_PWRSAVE_AGEOUT_TIME,
 803        .wmi_vdev_host_swba_interval = WMI_10X_VDEV_HOST_SWBA_INTERVAL,
 804        .dtim_period = WMI_10X_VDEV_PARAM_DTIM_PERIOD,
 805        .wmi_vdev_oc_scheduler_air_time_limit =
 806                                WMI_10X_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
 807        .wds = WMI_10X_VDEV_PARAM_WDS,
 808        .atim_window = WMI_10X_VDEV_PARAM_ATIM_WINDOW,
 809        .bmiss_count_max = WMI_10X_VDEV_PARAM_BMISS_COUNT_MAX,
 810        .bmiss_first_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
 811        .bmiss_final_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
 812        .feature_wmm = WMI_10X_VDEV_PARAM_FEATURE_WMM,
 813        .chwidth = WMI_10X_VDEV_PARAM_CHWIDTH,
 814        .chextoffset = WMI_10X_VDEV_PARAM_CHEXTOFFSET,
 815        .disable_htprotection = WMI_10X_VDEV_PARAM_DISABLE_HTPROTECTION,
 816        .sta_quickkickout = WMI_10X_VDEV_PARAM_STA_QUICKKICKOUT,
 817        .mgmt_rate = WMI_10X_VDEV_PARAM_MGMT_RATE,
 818        .protection_mode = WMI_10X_VDEV_PARAM_PROTECTION_MODE,
 819        .fixed_rate = WMI_10X_VDEV_PARAM_FIXED_RATE,
 820        .sgi = WMI_10X_VDEV_PARAM_SGI,
 821        .ldpc = WMI_10X_VDEV_PARAM_LDPC,
 822        .tx_stbc = WMI_10X_VDEV_PARAM_TX_STBC,
 823        .rx_stbc = WMI_10X_VDEV_PARAM_RX_STBC,
 824        .intra_bss_fwd = WMI_10X_VDEV_PARAM_INTRA_BSS_FWD,
 825        .def_keyid = WMI_10X_VDEV_PARAM_DEF_KEYID,
 826        .nss = WMI_10X_VDEV_PARAM_NSS,
 827        .bcast_data_rate = WMI_10X_VDEV_PARAM_BCAST_DATA_RATE,
 828        .mcast_data_rate = WMI_10X_VDEV_PARAM_MCAST_DATA_RATE,
 829        .mcast_indicate = WMI_10X_VDEV_PARAM_MCAST_INDICATE,
 830        .dhcp_indicate = WMI_10X_VDEV_PARAM_DHCP_INDICATE,
 831        .unknown_dest_indicate = WMI_10X_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
 832        .ap_keepalive_min_idle_inactive_time_secs =
 833                WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
 834        .ap_keepalive_max_idle_inactive_time_secs =
 835                WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
 836        .ap_keepalive_max_unresponsive_time_secs =
 837                WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
 838        .ap_enable_nawds = WMI_10X_VDEV_PARAM_AP_ENABLE_NAWDS,
 839        .mcast2ucast_set = WMI_10X_VDEV_PARAM_MCAST2UCAST_SET,
 840        .enable_rtscts = WMI_10X_VDEV_PARAM_ENABLE_RTSCTS,
 841        .txbf = WMI_VDEV_PARAM_UNSUPPORTED,
 842        .packet_powersave = WMI_VDEV_PARAM_UNSUPPORTED,
 843        .drop_unencry = WMI_VDEV_PARAM_UNSUPPORTED,
 844        .tx_encap_type = WMI_VDEV_PARAM_UNSUPPORTED,
 845        .ap_detect_out_of_sync_sleeping_sta_time_secs =
 846                WMI_10X_VDEV_PARAM_AP_DETECT_OUT_OF_SYNC_SLEEPING_STA_TIME_SECS,
 847        .rc_num_retries = WMI_VDEV_PARAM_UNSUPPORTED,
 848        .cabq_maxdur = WMI_VDEV_PARAM_UNSUPPORTED,
 849        .mfptest_set = WMI_VDEV_PARAM_UNSUPPORTED,
 850        .rts_fixed_rate = WMI_VDEV_PARAM_UNSUPPORTED,
 851        .vht_sgimask = WMI_VDEV_PARAM_UNSUPPORTED,
 852        .vht80_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
 853        .early_rx_adjust_enable = WMI_VDEV_PARAM_UNSUPPORTED,
 854        .early_rx_tgt_bmiss_num = WMI_VDEV_PARAM_UNSUPPORTED,
 855        .early_rx_bmiss_sample_cycle = WMI_VDEV_PARAM_UNSUPPORTED,
 856        .early_rx_slop_step = WMI_VDEV_PARAM_UNSUPPORTED,
 857        .early_rx_init_slop = WMI_VDEV_PARAM_UNSUPPORTED,
 858        .early_rx_adjust_pause = WMI_VDEV_PARAM_UNSUPPORTED,
 859        .proxy_sta = WMI_VDEV_PARAM_UNSUPPORTED,
 860        .meru_vc = WMI_VDEV_PARAM_UNSUPPORTED,
 861        .rx_decap_type = WMI_VDEV_PARAM_UNSUPPORTED,
 862        .bw_nss_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
 863};
 864
 865static struct wmi_vdev_param_map wmi_10_2_4_vdev_param_map = {
 866        .rts_threshold = WMI_10X_VDEV_PARAM_RTS_THRESHOLD,
 867        .fragmentation_threshold = WMI_10X_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
 868        .beacon_interval = WMI_10X_VDEV_PARAM_BEACON_INTERVAL,
 869        .listen_interval = WMI_10X_VDEV_PARAM_LISTEN_INTERVAL,
 870        .multicast_rate = WMI_10X_VDEV_PARAM_MULTICAST_RATE,
 871        .mgmt_tx_rate = WMI_10X_VDEV_PARAM_MGMT_TX_RATE,
 872        .slot_time = WMI_10X_VDEV_PARAM_SLOT_TIME,
 873        .preamble = WMI_10X_VDEV_PARAM_PREAMBLE,
 874        .swba_time = WMI_10X_VDEV_PARAM_SWBA_TIME,
 875        .wmi_vdev_stats_update_period = WMI_10X_VDEV_STATS_UPDATE_PERIOD,
 876        .wmi_vdev_pwrsave_ageout_time = WMI_10X_VDEV_PWRSAVE_AGEOUT_TIME,
 877        .wmi_vdev_host_swba_interval = WMI_10X_VDEV_HOST_SWBA_INTERVAL,
 878        .dtim_period = WMI_10X_VDEV_PARAM_DTIM_PERIOD,
 879        .wmi_vdev_oc_scheduler_air_time_limit =
 880                                WMI_10X_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
 881        .wds = WMI_10X_VDEV_PARAM_WDS,
 882        .atim_window = WMI_10X_VDEV_PARAM_ATIM_WINDOW,
 883        .bmiss_count_max = WMI_10X_VDEV_PARAM_BMISS_COUNT_MAX,
 884        .bmiss_first_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
 885        .bmiss_final_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
 886        .feature_wmm = WMI_10X_VDEV_PARAM_FEATURE_WMM,
 887        .chwidth = WMI_10X_VDEV_PARAM_CHWIDTH,
 888        .chextoffset = WMI_10X_VDEV_PARAM_CHEXTOFFSET,
 889        .disable_htprotection = WMI_10X_VDEV_PARAM_DISABLE_HTPROTECTION,
 890        .sta_quickkickout = WMI_10X_VDEV_PARAM_STA_QUICKKICKOUT,
 891        .mgmt_rate = WMI_10X_VDEV_PARAM_MGMT_RATE,
 892        .protection_mode = WMI_10X_VDEV_PARAM_PROTECTION_MODE,
 893        .fixed_rate = WMI_10X_VDEV_PARAM_FIXED_RATE,
 894        .sgi = WMI_10X_VDEV_PARAM_SGI,
 895        .ldpc = WMI_10X_VDEV_PARAM_LDPC,
 896        .tx_stbc = WMI_10X_VDEV_PARAM_TX_STBC,
 897        .rx_stbc = WMI_10X_VDEV_PARAM_RX_STBC,
 898        .intra_bss_fwd = WMI_10X_VDEV_PARAM_INTRA_BSS_FWD,
 899        .def_keyid = WMI_10X_VDEV_PARAM_DEF_KEYID,
 900        .nss = WMI_10X_VDEV_PARAM_NSS,
 901        .bcast_data_rate = WMI_10X_VDEV_PARAM_BCAST_DATA_RATE,
 902        .mcast_data_rate = WMI_10X_VDEV_PARAM_MCAST_DATA_RATE,
 903        .mcast_indicate = WMI_10X_VDEV_PARAM_MCAST_INDICATE,
 904        .dhcp_indicate = WMI_10X_VDEV_PARAM_DHCP_INDICATE,
 905        .unknown_dest_indicate = WMI_10X_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
 906        .ap_keepalive_min_idle_inactive_time_secs =
 907                WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
 908        .ap_keepalive_max_idle_inactive_time_secs =
 909                WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
 910        .ap_keepalive_max_unresponsive_time_secs =
 911                WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
 912        .ap_enable_nawds = WMI_10X_VDEV_PARAM_AP_ENABLE_NAWDS,
 913        .mcast2ucast_set = WMI_10X_VDEV_PARAM_MCAST2UCAST_SET,
 914        .enable_rtscts = WMI_10X_VDEV_PARAM_ENABLE_RTSCTS,
 915        .txbf = WMI_VDEV_PARAM_UNSUPPORTED,
 916        .packet_powersave = WMI_VDEV_PARAM_UNSUPPORTED,
 917        .drop_unencry = WMI_VDEV_PARAM_UNSUPPORTED,
 918        .tx_encap_type = WMI_VDEV_PARAM_UNSUPPORTED,
 919        .ap_detect_out_of_sync_sleeping_sta_time_secs =
 920                WMI_10X_VDEV_PARAM_AP_DETECT_OUT_OF_SYNC_SLEEPING_STA_TIME_SECS,
 921        .rc_num_retries = WMI_VDEV_PARAM_UNSUPPORTED,
 922        .cabq_maxdur = WMI_VDEV_PARAM_UNSUPPORTED,
 923        .mfptest_set = WMI_VDEV_PARAM_UNSUPPORTED,
 924        .rts_fixed_rate = WMI_VDEV_PARAM_UNSUPPORTED,
 925        .vht_sgimask = WMI_VDEV_PARAM_UNSUPPORTED,
 926        .vht80_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
 927        .early_rx_adjust_enable = WMI_VDEV_PARAM_UNSUPPORTED,
 928        .early_rx_tgt_bmiss_num = WMI_VDEV_PARAM_UNSUPPORTED,
 929        .early_rx_bmiss_sample_cycle = WMI_VDEV_PARAM_UNSUPPORTED,
 930        .early_rx_slop_step = WMI_VDEV_PARAM_UNSUPPORTED,
 931        .early_rx_init_slop = WMI_VDEV_PARAM_UNSUPPORTED,
 932        .early_rx_adjust_pause = WMI_VDEV_PARAM_UNSUPPORTED,
 933        .proxy_sta = WMI_VDEV_PARAM_UNSUPPORTED,
 934        .meru_vc = WMI_VDEV_PARAM_UNSUPPORTED,
 935        .rx_decap_type = WMI_VDEV_PARAM_UNSUPPORTED,
 936        .bw_nss_ratemask = WMI_VDEV_PARAM_UNSUPPORTED,
 937};
 938
 939static struct wmi_vdev_param_map wmi_10_4_vdev_param_map = {
 940        .rts_threshold = WMI_10_4_VDEV_PARAM_RTS_THRESHOLD,
 941        .fragmentation_threshold = WMI_10_4_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
 942        .beacon_interval = WMI_10_4_VDEV_PARAM_BEACON_INTERVAL,
 943        .listen_interval = WMI_10_4_VDEV_PARAM_LISTEN_INTERVAL,
 944        .multicast_rate = WMI_10_4_VDEV_PARAM_MULTICAST_RATE,
 945        .mgmt_tx_rate = WMI_10_4_VDEV_PARAM_MGMT_TX_RATE,
 946        .slot_time = WMI_10_4_VDEV_PARAM_SLOT_TIME,
 947        .preamble = WMI_10_4_VDEV_PARAM_PREAMBLE,
 948        .swba_time = WMI_10_4_VDEV_PARAM_SWBA_TIME,
 949        .wmi_vdev_stats_update_period = WMI_10_4_VDEV_STATS_UPDATE_PERIOD,
 950        .wmi_vdev_pwrsave_ageout_time = WMI_10_4_VDEV_PWRSAVE_AGEOUT_TIME,
 951        .wmi_vdev_host_swba_interval = WMI_10_4_VDEV_HOST_SWBA_INTERVAL,
 952        .dtim_period = WMI_10_4_VDEV_PARAM_DTIM_PERIOD,
 953        .wmi_vdev_oc_scheduler_air_time_limit =
 954               WMI_10_4_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
 955        .wds = WMI_10_4_VDEV_PARAM_WDS,
 956        .atim_window = WMI_10_4_VDEV_PARAM_ATIM_WINDOW,
 957        .bmiss_count_max = WMI_10_4_VDEV_PARAM_BMISS_COUNT_MAX,
 958        .bmiss_first_bcnt = WMI_10_4_VDEV_PARAM_BMISS_FIRST_BCNT,
 959        .bmiss_final_bcnt = WMI_10_4_VDEV_PARAM_BMISS_FINAL_BCNT,
 960        .feature_wmm = WMI_10_4_VDEV_PARAM_FEATURE_WMM,
 961        .chwidth = WMI_10_4_VDEV_PARAM_CHWIDTH,
 962        .chextoffset = WMI_10_4_VDEV_PARAM_CHEXTOFFSET,
 963        .disable_htprotection = WMI_10_4_VDEV_PARAM_DISABLE_HTPROTECTION,
 964        .sta_quickkickout = WMI_10_4_VDEV_PARAM_STA_QUICKKICKOUT,
 965        .mgmt_rate = WMI_10_4_VDEV_PARAM_MGMT_RATE,
 966        .protection_mode = WMI_10_4_VDEV_PARAM_PROTECTION_MODE,
 967        .fixed_rate = WMI_10_4_VDEV_PARAM_FIXED_RATE,
 968        .sgi = WMI_10_4_VDEV_PARAM_SGI,
 969        .ldpc = WMI_10_4_VDEV_PARAM_LDPC,
 970        .tx_stbc = WMI_10_4_VDEV_PARAM_TX_STBC,
 971        .rx_stbc = WMI_10_4_VDEV_PARAM_RX_STBC,
 972        .intra_bss_fwd = WMI_10_4_VDEV_PARAM_INTRA_BSS_FWD,
 973        .def_keyid = WMI_10_4_VDEV_PARAM_DEF_KEYID,
 974        .nss = WMI_10_4_VDEV_PARAM_NSS,
 975        .bcast_data_rate = WMI_10_4_VDEV_PARAM_BCAST_DATA_RATE,
 976        .mcast_data_rate = WMI_10_4_VDEV_PARAM_MCAST_DATA_RATE,
 977        .mcast_indicate = WMI_10_4_VDEV_PARAM_MCAST_INDICATE,
 978        .dhcp_indicate = WMI_10_4_VDEV_PARAM_DHCP_INDICATE,
 979        .unknown_dest_indicate = WMI_10_4_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
 980        .ap_keepalive_min_idle_inactive_time_secs =
 981               WMI_10_4_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
 982        .ap_keepalive_max_idle_inactive_time_secs =
 983               WMI_10_4_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
 984        .ap_keepalive_max_unresponsive_time_secs =
 985               WMI_10_4_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
 986        .ap_enable_nawds = WMI_10_4_VDEV_PARAM_AP_ENABLE_NAWDS,
 987        .mcast2ucast_set = WMI_10_4_VDEV_PARAM_MCAST2UCAST_SET,
 988        .enable_rtscts = WMI_10_4_VDEV_PARAM_ENABLE_RTSCTS,
 989        .txbf = WMI_10_4_VDEV_PARAM_TXBF,
 990        .packet_powersave = WMI_10_4_VDEV_PARAM_PACKET_POWERSAVE,
 991        .drop_unencry = WMI_10_4_VDEV_PARAM_DROP_UNENCRY,
 992        .tx_encap_type = WMI_10_4_VDEV_PARAM_TX_ENCAP_TYPE,
 993        .ap_detect_out_of_sync_sleeping_sta_time_secs =
 994               WMI_10_4_VDEV_PARAM_AP_DETECT_OUT_OF_SYNC_SLEEPING_STA_TIME_SECS,
 995        .rc_num_retries = WMI_10_4_VDEV_PARAM_RC_NUM_RETRIES,
 996        .cabq_maxdur = WMI_10_4_VDEV_PARAM_CABQ_MAXDUR,
 997        .mfptest_set = WMI_10_4_VDEV_PARAM_MFPTEST_SET,
 998        .rts_fixed_rate = WMI_10_4_VDEV_PARAM_RTS_FIXED_RATE,
 999        .vht_sgimask = WMI_10_4_VDEV_PARAM_VHT_SGIMASK,
1000        .vht80_ratemask = WMI_10_4_VDEV_PARAM_VHT80_RATEMASK,
1001        .early_rx_adjust_enable = WMI_10_4_VDEV_PARAM_EARLY_RX_ADJUST_ENABLE,
1002        .early_rx_tgt_bmiss_num = WMI_10_4_VDEV_PARAM_EARLY_RX_TGT_BMISS_NUM,
1003        .early_rx_bmiss_sample_cycle =
1004               WMI_10_4_VDEV_PARAM_EARLY_RX_BMISS_SAMPLE_CYCLE,
1005        .early_rx_slop_step = WMI_10_4_VDEV_PARAM_EARLY_RX_SLOP_STEP,
1006        .early_rx_init_slop = WMI_10_4_VDEV_PARAM_EARLY_RX_INIT_SLOP,
1007        .early_rx_adjust_pause = WMI_10_4_VDEV_PARAM_EARLY_RX_ADJUST_PAUSE,
1008        .proxy_sta = WMI_10_4_VDEV_PARAM_PROXY_STA,
1009        .meru_vc = WMI_10_4_VDEV_PARAM_MERU_VC,
1010        .rx_decap_type = WMI_10_4_VDEV_PARAM_RX_DECAP_TYPE,
1011        .bw_nss_ratemask = WMI_10_4_VDEV_PARAM_BW_NSS_RATEMASK,
1012        .inc_tsf = WMI_10_4_VDEV_PARAM_TSF_INCREMENT,
1013        .dec_tsf = WMI_10_4_VDEV_PARAM_TSF_DECREMENT,
1014};
1015
1016static struct wmi_pdev_param_map wmi_pdev_param_map = {
1017        .tx_chain_mask = WMI_PDEV_PARAM_TX_CHAIN_MASK,
1018        .rx_chain_mask = WMI_PDEV_PARAM_RX_CHAIN_MASK,
1019        .txpower_limit2g = WMI_PDEV_PARAM_TXPOWER_LIMIT2G,
1020        .txpower_limit5g = WMI_PDEV_PARAM_TXPOWER_LIMIT5G,
1021        .txpower_scale = WMI_PDEV_PARAM_TXPOWER_SCALE,
1022        .beacon_gen_mode = WMI_PDEV_PARAM_BEACON_GEN_MODE,
1023        .beacon_tx_mode = WMI_PDEV_PARAM_BEACON_TX_MODE,
1024        .resmgr_offchan_mode = WMI_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
1025        .protection_mode = WMI_PDEV_PARAM_PROTECTION_MODE,
1026        .dynamic_bw = WMI_PDEV_PARAM_DYNAMIC_BW,
1027        .non_agg_sw_retry_th = WMI_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
1028        .agg_sw_retry_th = WMI_PDEV_PARAM_AGG_SW_RETRY_TH,
1029        .sta_kickout_th = WMI_PDEV_PARAM_STA_KICKOUT_TH,
1030        .ac_aggrsize_scaling = WMI_PDEV_PARAM_AC_AGGRSIZE_SCALING,
1031        .ltr_enable = WMI_PDEV_PARAM_LTR_ENABLE,
1032        .ltr_ac_latency_be = WMI_PDEV_PARAM_LTR_AC_LATENCY_BE,
1033        .ltr_ac_latency_bk = WMI_PDEV_PARAM_LTR_AC_LATENCY_BK,
1034        .ltr_ac_latency_vi = WMI_PDEV_PARAM_LTR_AC_LATENCY_VI,
1035        .ltr_ac_latency_vo = WMI_PDEV_PARAM_LTR_AC_LATENCY_VO,
1036        .ltr_ac_latency_timeout = WMI_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
1037        .ltr_sleep_override = WMI_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
1038        .ltr_rx_override = WMI_PDEV_PARAM_LTR_RX_OVERRIDE,
1039        .ltr_tx_activity_timeout = WMI_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
1040        .l1ss_enable = WMI_PDEV_PARAM_L1SS_ENABLE,
1041        .dsleep_enable = WMI_PDEV_PARAM_DSLEEP_ENABLE,
1042        .pcielp_txbuf_flush = WMI_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
1043        .pcielp_txbuf_watermark = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
1044        .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
1045        .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
1046        .pdev_stats_update_period = WMI_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
1047        .vdev_stats_update_period = WMI_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
1048        .peer_stats_update_period = WMI_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
1049        .bcnflt_stats_update_period = WMI_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
1050        .pmf_qos = WMI_PDEV_PARAM_PMF_QOS,
1051        .arp_ac_override = WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
1052        .dcs = WMI_PDEV_PARAM_DCS,
1053        .ani_enable = WMI_PDEV_PARAM_ANI_ENABLE,
1054        .ani_poll_period = WMI_PDEV_PARAM_ANI_POLL_PERIOD,
1055        .ani_listen_period = WMI_PDEV_PARAM_ANI_LISTEN_PERIOD,
1056        .ani_ofdm_level = WMI_PDEV_PARAM_ANI_OFDM_LEVEL,
1057        .ani_cck_level = WMI_PDEV_PARAM_ANI_CCK_LEVEL,
1058        .dyntxchain = WMI_PDEV_PARAM_DYNTXCHAIN,
1059        .proxy_sta = WMI_PDEV_PARAM_PROXY_STA,
1060        .idle_ps_config = WMI_PDEV_PARAM_IDLE_PS_CONFIG,
1061        .power_gating_sleep = WMI_PDEV_PARAM_POWER_GATING_SLEEP,
1062        .fast_channel_reset = WMI_PDEV_PARAM_UNSUPPORTED,
1063        .burst_dur = WMI_PDEV_PARAM_UNSUPPORTED,
1064        .burst_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1065        .cal_period = WMI_PDEV_PARAM_UNSUPPORTED,
1066        .aggr_burst = WMI_PDEV_PARAM_UNSUPPORTED,
1067        .rx_decap_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1068        .smart_antenna_default_antenna = WMI_PDEV_PARAM_UNSUPPORTED,
1069        .igmpmld_override = WMI_PDEV_PARAM_UNSUPPORTED,
1070        .igmpmld_tid = WMI_PDEV_PARAM_UNSUPPORTED,
1071        .antenna_gain = WMI_PDEV_PARAM_UNSUPPORTED,
1072        .rx_filter = WMI_PDEV_PARAM_UNSUPPORTED,
1073        .set_mcast_to_ucast_tid = WMI_PDEV_PARAM_UNSUPPORTED,
1074        .proxy_sta_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1075        .set_mcast2ucast_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1076        .set_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
1077        .remove_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
1078        .peer_sta_ps_statechg_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1079        .igmpmld_ac_override = WMI_PDEV_PARAM_UNSUPPORTED,
1080        .block_interbss = WMI_PDEV_PARAM_UNSUPPORTED,
1081        .set_disable_reset_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1082        .set_msdu_ttl_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1083        .set_ppdu_duration_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1084        .txbf_sound_period_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1085        .set_promisc_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1086        .set_burst_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1087        .en_stats = WMI_PDEV_PARAM_UNSUPPORTED,
1088        .mu_group_policy = WMI_PDEV_PARAM_UNSUPPORTED,
1089        .noise_detection = WMI_PDEV_PARAM_UNSUPPORTED,
1090        .noise_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
1091        .dpd_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1092        .set_mcast_bcast_echo = WMI_PDEV_PARAM_UNSUPPORTED,
1093        .atf_strict_sch = WMI_PDEV_PARAM_UNSUPPORTED,
1094        .atf_sched_duration = WMI_PDEV_PARAM_UNSUPPORTED,
1095        .ant_plzn = WMI_PDEV_PARAM_UNSUPPORTED,
1096        .mgmt_retry_limit = WMI_PDEV_PARAM_UNSUPPORTED,
1097        .sensitivity_level = WMI_PDEV_PARAM_UNSUPPORTED,
1098        .signed_txpower_2g = WMI_PDEV_PARAM_UNSUPPORTED,
1099        .signed_txpower_5g = WMI_PDEV_PARAM_UNSUPPORTED,
1100        .enable_per_tid_amsdu = WMI_PDEV_PARAM_UNSUPPORTED,
1101        .enable_per_tid_ampdu = WMI_PDEV_PARAM_UNSUPPORTED,
1102        .cca_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
1103        .rts_fixed_rate = WMI_PDEV_PARAM_UNSUPPORTED,
1104        .pdev_reset = WMI_PDEV_PARAM_UNSUPPORTED,
1105        .wapi_mbssid_offset = WMI_PDEV_PARAM_UNSUPPORTED,
1106        .arp_srcaddr = WMI_PDEV_PARAM_UNSUPPORTED,
1107        .arp_dstaddr = WMI_PDEV_PARAM_UNSUPPORTED,
1108        .enable_btcoex = WMI_PDEV_PARAM_UNSUPPORTED,
1109};
1110
1111static struct wmi_pdev_param_map wmi_10x_pdev_param_map = {
1112        .tx_chain_mask = WMI_10X_PDEV_PARAM_TX_CHAIN_MASK,
1113        .rx_chain_mask = WMI_10X_PDEV_PARAM_RX_CHAIN_MASK,
1114        .txpower_limit2g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT2G,
1115        .txpower_limit5g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT5G,
1116        .txpower_scale = WMI_10X_PDEV_PARAM_TXPOWER_SCALE,
1117        .beacon_gen_mode = WMI_10X_PDEV_PARAM_BEACON_GEN_MODE,
1118        .beacon_tx_mode = WMI_10X_PDEV_PARAM_BEACON_TX_MODE,
1119        .resmgr_offchan_mode = WMI_10X_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
1120        .protection_mode = WMI_10X_PDEV_PARAM_PROTECTION_MODE,
1121        .dynamic_bw = WMI_10X_PDEV_PARAM_DYNAMIC_BW,
1122        .non_agg_sw_retry_th = WMI_10X_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
1123        .agg_sw_retry_th = WMI_10X_PDEV_PARAM_AGG_SW_RETRY_TH,
1124        .sta_kickout_th = WMI_10X_PDEV_PARAM_STA_KICKOUT_TH,
1125        .ac_aggrsize_scaling = WMI_10X_PDEV_PARAM_AC_AGGRSIZE_SCALING,
1126        .ltr_enable = WMI_10X_PDEV_PARAM_LTR_ENABLE,
1127        .ltr_ac_latency_be = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BE,
1128        .ltr_ac_latency_bk = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BK,
1129        .ltr_ac_latency_vi = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VI,
1130        .ltr_ac_latency_vo = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VO,
1131        .ltr_ac_latency_timeout = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
1132        .ltr_sleep_override = WMI_10X_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
1133        .ltr_rx_override = WMI_10X_PDEV_PARAM_LTR_RX_OVERRIDE,
1134        .ltr_tx_activity_timeout = WMI_10X_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
1135        .l1ss_enable = WMI_10X_PDEV_PARAM_L1SS_ENABLE,
1136        .dsleep_enable = WMI_10X_PDEV_PARAM_DSLEEP_ENABLE,
1137        .pcielp_txbuf_flush = WMI_PDEV_PARAM_UNSUPPORTED,
1138        .pcielp_txbuf_watermark = WMI_PDEV_PARAM_UNSUPPORTED,
1139        .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_UNSUPPORTED,
1140        .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_UNSUPPORTED,
1141        .pdev_stats_update_period = WMI_10X_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
1142        .vdev_stats_update_period = WMI_10X_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
1143        .peer_stats_update_period = WMI_10X_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
1144        .bcnflt_stats_update_period =
1145                                WMI_10X_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
1146        .pmf_qos = WMI_10X_PDEV_PARAM_PMF_QOS,
1147        .arp_ac_override = WMI_10X_PDEV_PARAM_ARPDHCP_AC_OVERRIDE,
1148        .dcs = WMI_10X_PDEV_PARAM_DCS,
1149        .ani_enable = WMI_10X_PDEV_PARAM_ANI_ENABLE,
1150        .ani_poll_period = WMI_10X_PDEV_PARAM_ANI_POLL_PERIOD,
1151        .ani_listen_period = WMI_10X_PDEV_PARAM_ANI_LISTEN_PERIOD,
1152        .ani_ofdm_level = WMI_10X_PDEV_PARAM_ANI_OFDM_LEVEL,
1153        .ani_cck_level = WMI_10X_PDEV_PARAM_ANI_CCK_LEVEL,
1154        .dyntxchain = WMI_10X_PDEV_PARAM_DYNTXCHAIN,
1155        .proxy_sta = WMI_PDEV_PARAM_UNSUPPORTED,
1156        .idle_ps_config = WMI_PDEV_PARAM_UNSUPPORTED,
1157        .power_gating_sleep = WMI_PDEV_PARAM_UNSUPPORTED,
1158        .fast_channel_reset = WMI_10X_PDEV_PARAM_FAST_CHANNEL_RESET,
1159        .burst_dur = WMI_10X_PDEV_PARAM_BURST_DUR,
1160        .burst_enable = WMI_10X_PDEV_PARAM_BURST_ENABLE,
1161        .cal_period = WMI_10X_PDEV_PARAM_CAL_PERIOD,
1162        .aggr_burst = WMI_PDEV_PARAM_UNSUPPORTED,
1163        .rx_decap_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1164        .smart_antenna_default_antenna = WMI_PDEV_PARAM_UNSUPPORTED,
1165        .igmpmld_override = WMI_PDEV_PARAM_UNSUPPORTED,
1166        .igmpmld_tid = WMI_PDEV_PARAM_UNSUPPORTED,
1167        .antenna_gain = WMI_PDEV_PARAM_UNSUPPORTED,
1168        .rx_filter = WMI_PDEV_PARAM_UNSUPPORTED,
1169        .set_mcast_to_ucast_tid = WMI_PDEV_PARAM_UNSUPPORTED,
1170        .proxy_sta_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1171        .set_mcast2ucast_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1172        .set_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
1173        .remove_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
1174        .peer_sta_ps_statechg_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1175        .igmpmld_ac_override = WMI_PDEV_PARAM_UNSUPPORTED,
1176        .block_interbss = WMI_PDEV_PARAM_UNSUPPORTED,
1177        .set_disable_reset_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1178        .set_msdu_ttl_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1179        .set_ppdu_duration_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1180        .txbf_sound_period_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1181        .set_promisc_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1182        .set_burst_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1183        .en_stats = WMI_PDEV_PARAM_UNSUPPORTED,
1184        .mu_group_policy = WMI_PDEV_PARAM_UNSUPPORTED,
1185        .noise_detection = WMI_PDEV_PARAM_UNSUPPORTED,
1186        .noise_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
1187        .dpd_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1188        .set_mcast_bcast_echo = WMI_PDEV_PARAM_UNSUPPORTED,
1189        .atf_strict_sch = WMI_PDEV_PARAM_UNSUPPORTED,
1190        .atf_sched_duration = WMI_PDEV_PARAM_UNSUPPORTED,
1191        .ant_plzn = WMI_PDEV_PARAM_UNSUPPORTED,
1192        .mgmt_retry_limit = WMI_PDEV_PARAM_UNSUPPORTED,
1193        .sensitivity_level = WMI_PDEV_PARAM_UNSUPPORTED,
1194        .signed_txpower_2g = WMI_PDEV_PARAM_UNSUPPORTED,
1195        .signed_txpower_5g = WMI_PDEV_PARAM_UNSUPPORTED,
1196        .enable_per_tid_amsdu = WMI_PDEV_PARAM_UNSUPPORTED,
1197        .enable_per_tid_ampdu = WMI_PDEV_PARAM_UNSUPPORTED,
1198        .cca_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
1199        .rts_fixed_rate = WMI_PDEV_PARAM_UNSUPPORTED,
1200        .pdev_reset = WMI_PDEV_PARAM_UNSUPPORTED,
1201        .wapi_mbssid_offset = WMI_PDEV_PARAM_UNSUPPORTED,
1202        .arp_srcaddr = WMI_PDEV_PARAM_UNSUPPORTED,
1203        .arp_dstaddr = WMI_PDEV_PARAM_UNSUPPORTED,
1204        .enable_btcoex = WMI_PDEV_PARAM_UNSUPPORTED,
1205};
1206
1207static struct wmi_pdev_param_map wmi_10_2_4_pdev_param_map = {
1208        .tx_chain_mask = WMI_10X_PDEV_PARAM_TX_CHAIN_MASK,
1209        .rx_chain_mask = WMI_10X_PDEV_PARAM_RX_CHAIN_MASK,
1210        .txpower_limit2g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT2G,
1211        .txpower_limit5g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT5G,
1212        .txpower_scale = WMI_10X_PDEV_PARAM_TXPOWER_SCALE,
1213        .beacon_gen_mode = WMI_10X_PDEV_PARAM_BEACON_GEN_MODE,
1214        .beacon_tx_mode = WMI_10X_PDEV_PARAM_BEACON_TX_MODE,
1215        .resmgr_offchan_mode = WMI_10X_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
1216        .protection_mode = WMI_10X_PDEV_PARAM_PROTECTION_MODE,
1217        .dynamic_bw = WMI_10X_PDEV_PARAM_DYNAMIC_BW,
1218        .non_agg_sw_retry_th = WMI_10X_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
1219        .agg_sw_retry_th = WMI_10X_PDEV_PARAM_AGG_SW_RETRY_TH,
1220        .sta_kickout_th = WMI_10X_PDEV_PARAM_STA_KICKOUT_TH,
1221        .ac_aggrsize_scaling = WMI_10X_PDEV_PARAM_AC_AGGRSIZE_SCALING,
1222        .ltr_enable = WMI_10X_PDEV_PARAM_LTR_ENABLE,
1223        .ltr_ac_latency_be = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BE,
1224        .ltr_ac_latency_bk = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BK,
1225        .ltr_ac_latency_vi = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VI,
1226        .ltr_ac_latency_vo = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VO,
1227        .ltr_ac_latency_timeout = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
1228        .ltr_sleep_override = WMI_10X_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
1229        .ltr_rx_override = WMI_10X_PDEV_PARAM_LTR_RX_OVERRIDE,
1230        .ltr_tx_activity_timeout = WMI_10X_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
1231        .l1ss_enable = WMI_10X_PDEV_PARAM_L1SS_ENABLE,
1232        .dsleep_enable = WMI_10X_PDEV_PARAM_DSLEEP_ENABLE,
1233        .pcielp_txbuf_flush = WMI_PDEV_PARAM_UNSUPPORTED,
1234        .pcielp_txbuf_watermark = WMI_PDEV_PARAM_UNSUPPORTED,
1235        .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_UNSUPPORTED,
1236        .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_UNSUPPORTED,
1237        .pdev_stats_update_period = WMI_10X_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
1238        .vdev_stats_update_period = WMI_10X_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
1239        .peer_stats_update_period = WMI_10X_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
1240        .bcnflt_stats_update_period =
1241                                WMI_10X_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
1242        .pmf_qos = WMI_10X_PDEV_PARAM_PMF_QOS,
1243        .arp_ac_override = WMI_10X_PDEV_PARAM_ARPDHCP_AC_OVERRIDE,
1244        .dcs = WMI_10X_PDEV_PARAM_DCS,
1245        .ani_enable = WMI_10X_PDEV_PARAM_ANI_ENABLE,
1246        .ani_poll_period = WMI_10X_PDEV_PARAM_ANI_POLL_PERIOD,
1247        .ani_listen_period = WMI_10X_PDEV_PARAM_ANI_LISTEN_PERIOD,
1248        .ani_ofdm_level = WMI_10X_PDEV_PARAM_ANI_OFDM_LEVEL,
1249        .ani_cck_level = WMI_10X_PDEV_PARAM_ANI_CCK_LEVEL,
1250        .dyntxchain = WMI_10X_PDEV_PARAM_DYNTXCHAIN,
1251        .proxy_sta = WMI_PDEV_PARAM_UNSUPPORTED,
1252        .idle_ps_config = WMI_PDEV_PARAM_UNSUPPORTED,
1253        .power_gating_sleep = WMI_PDEV_PARAM_UNSUPPORTED,
1254        .fast_channel_reset = WMI_10X_PDEV_PARAM_FAST_CHANNEL_RESET,
1255        .burst_dur = WMI_10X_PDEV_PARAM_BURST_DUR,
1256        .burst_enable = WMI_10X_PDEV_PARAM_BURST_ENABLE,
1257        .cal_period = WMI_10X_PDEV_PARAM_CAL_PERIOD,
1258        .aggr_burst = WMI_PDEV_PARAM_UNSUPPORTED,
1259        .rx_decap_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1260        .smart_antenna_default_antenna = WMI_PDEV_PARAM_UNSUPPORTED,
1261        .igmpmld_override = WMI_PDEV_PARAM_UNSUPPORTED,
1262        .igmpmld_tid = WMI_PDEV_PARAM_UNSUPPORTED,
1263        .antenna_gain = WMI_PDEV_PARAM_UNSUPPORTED,
1264        .rx_filter = WMI_PDEV_PARAM_UNSUPPORTED,
1265        .set_mcast_to_ucast_tid = WMI_PDEV_PARAM_UNSUPPORTED,
1266        .proxy_sta_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1267        .set_mcast2ucast_mode = WMI_PDEV_PARAM_UNSUPPORTED,
1268        .set_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
1269        .remove_mcast2ucast_buffer = WMI_PDEV_PARAM_UNSUPPORTED,
1270        .peer_sta_ps_statechg_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1271        .igmpmld_ac_override = WMI_PDEV_PARAM_UNSUPPORTED,
1272        .block_interbss = WMI_PDEV_PARAM_UNSUPPORTED,
1273        .set_disable_reset_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1274        .set_msdu_ttl_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1275        .set_ppdu_duration_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1276        .txbf_sound_period_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1277        .set_promisc_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1278        .set_burst_mode_cmdid = WMI_PDEV_PARAM_UNSUPPORTED,
1279        .en_stats = WMI_PDEV_PARAM_UNSUPPORTED,
1280        .mu_group_policy = WMI_PDEV_PARAM_UNSUPPORTED,
1281        .noise_detection = WMI_PDEV_PARAM_UNSUPPORTED,
1282        .noise_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
1283        .dpd_enable = WMI_PDEV_PARAM_UNSUPPORTED,
1284        .set_mcast_bcast_echo = WMI_PDEV_PARAM_UNSUPPORTED,
1285        .atf_strict_sch = WMI_PDEV_PARAM_UNSUPPORTED,
1286        .atf_sched_duration = WMI_PDEV_PARAM_UNSUPPORTED,
1287        .ant_plzn = WMI_PDEV_PARAM_UNSUPPORTED,
1288        .mgmt_retry_limit = WMI_PDEV_PARAM_UNSUPPORTED,
1289        .sensitivity_level = WMI_PDEV_PARAM_UNSUPPORTED,
1290        .signed_txpower_2g = WMI_PDEV_PARAM_UNSUPPORTED,
1291        .signed_txpower_5g = WMI_PDEV_PARAM_UNSUPPORTED,
1292        .enable_per_tid_amsdu = WMI_PDEV_PARAM_UNSUPPORTED,
1293        .enable_per_tid_ampdu = WMI_PDEV_PARAM_UNSUPPORTED,
1294        .cca_threshold = WMI_PDEV_PARAM_UNSUPPORTED,
1295        .rts_fixed_rate = WMI_PDEV_PARAM_UNSUPPORTED,
1296        .pdev_reset = WMI_PDEV_PARAM_UNSUPPORTED,
1297        .wapi_mbssid_offset = WMI_PDEV_PARAM_UNSUPPORTED,
1298        .arp_srcaddr = WMI_PDEV_PARAM_UNSUPPORTED,
1299        .arp_dstaddr = WMI_PDEV_PARAM_UNSUPPORTED,
1300        .enable_btcoex = WMI_PDEV_PARAM_UNSUPPORTED,
1301};
1302
1303/* firmware 10.2 specific mappings */
1304static struct wmi_cmd_map wmi_10_2_cmd_map = {
1305        .init_cmdid = WMI_10_2_INIT_CMDID,
1306        .start_scan_cmdid = WMI_10_2_START_SCAN_CMDID,
1307        .stop_scan_cmdid = WMI_10_2_STOP_SCAN_CMDID,
1308        .scan_chan_list_cmdid = WMI_10_2_SCAN_CHAN_LIST_CMDID,
1309        .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
1310        .pdev_set_regdomain_cmdid = WMI_10_2_PDEV_SET_REGDOMAIN_CMDID,
1311        .pdev_set_channel_cmdid = WMI_10_2_PDEV_SET_CHANNEL_CMDID,
1312        .pdev_set_param_cmdid = WMI_10_2_PDEV_SET_PARAM_CMDID,
1313        .pdev_pktlog_enable_cmdid = WMI_10_2_PDEV_PKTLOG_ENABLE_CMDID,
1314        .pdev_pktlog_disable_cmdid = WMI_10_2_PDEV_PKTLOG_DISABLE_CMDID,
1315        .pdev_set_wmm_params_cmdid = WMI_10_2_PDEV_SET_WMM_PARAMS_CMDID,
1316        .pdev_set_ht_cap_ie_cmdid = WMI_10_2_PDEV_SET_HT_CAP_IE_CMDID,
1317        .pdev_set_vht_cap_ie_cmdid = WMI_10_2_PDEV_SET_VHT_CAP_IE_CMDID,
1318        .pdev_set_quiet_mode_cmdid = WMI_10_2_PDEV_SET_QUIET_MODE_CMDID,
1319        .pdev_green_ap_ps_enable_cmdid = WMI_10_2_PDEV_GREEN_AP_PS_ENABLE_CMDID,
1320        .pdev_get_tpc_config_cmdid = WMI_10_2_PDEV_GET_TPC_CONFIG_CMDID,
1321        .pdev_set_base_macaddr_cmdid = WMI_10_2_PDEV_SET_BASE_MACADDR_CMDID,
1322        .vdev_create_cmdid = WMI_10_2_VDEV_CREATE_CMDID,
1323        .vdev_delete_cmdid = WMI_10_2_VDEV_DELETE_CMDID,
1324        .vdev_start_request_cmdid = WMI_10_2_VDEV_START_REQUEST_CMDID,
1325        .vdev_restart_request_cmdid = WMI_10_2_VDEV_RESTART_REQUEST_CMDID,
1326        .vdev_up_cmdid = WMI_10_2_VDEV_UP_CMDID,
1327        .vdev_stop_cmdid = WMI_10_2_VDEV_STOP_CMDID,
1328        .vdev_down_cmdid = WMI_10_2_VDEV_DOWN_CMDID,
1329        .vdev_set_param_cmdid = WMI_10_2_VDEV_SET_PARAM_CMDID,
1330        .vdev_install_key_cmdid = WMI_10_2_VDEV_INSTALL_KEY_CMDID,
1331        .peer_create_cmdid = WMI_10_2_PEER_CREATE_CMDID,
1332        .peer_delete_cmdid = WMI_10_2_PEER_DELETE_CMDID,
1333        .peer_flush_tids_cmdid = WMI_10_2_PEER_FLUSH_TIDS_CMDID,
1334        .peer_set_param_cmdid = WMI_10_2_PEER_SET_PARAM_CMDID,
1335        .peer_assoc_cmdid = WMI_10_2_PEER_ASSOC_CMDID,
1336        .peer_add_wds_entry_cmdid = WMI_10_2_PEER_ADD_WDS_ENTRY_CMDID,
1337        .peer_remove_wds_entry_cmdid = WMI_10_2_PEER_REMOVE_WDS_ENTRY_CMDID,
1338        .peer_mcast_group_cmdid = WMI_10_2_PEER_MCAST_GROUP_CMDID,
1339        .bcn_tx_cmdid = WMI_10_2_BCN_TX_CMDID,
1340        .pdev_send_bcn_cmdid = WMI_10_2_PDEV_SEND_BCN_CMDID,
1341        .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
1342        .bcn_filter_rx_cmdid = WMI_10_2_BCN_FILTER_RX_CMDID,
1343        .prb_req_filter_rx_cmdid = WMI_10_2_PRB_REQ_FILTER_RX_CMDID,
1344        .mgmt_tx_cmdid = WMI_10_2_MGMT_TX_CMDID,
1345        .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
1346        .addba_clear_resp_cmdid = WMI_10_2_ADDBA_CLEAR_RESP_CMDID,
1347        .addba_send_cmdid = WMI_10_2_ADDBA_SEND_CMDID,
1348        .addba_status_cmdid = WMI_10_2_ADDBA_STATUS_CMDID,
1349        .delba_send_cmdid = WMI_10_2_DELBA_SEND_CMDID,
1350        .addba_set_resp_cmdid = WMI_10_2_ADDBA_SET_RESP_CMDID,
1351        .send_singleamsdu_cmdid = WMI_10_2_SEND_SINGLEAMSDU_CMDID,
1352        .sta_powersave_mode_cmdid = WMI_10_2_STA_POWERSAVE_MODE_CMDID,
1353        .sta_powersave_param_cmdid = WMI_10_2_STA_POWERSAVE_PARAM_CMDID,
1354        .sta_mimo_ps_mode_cmdid = WMI_10_2_STA_MIMO_PS_MODE_CMDID,
1355        .pdev_dfs_enable_cmdid = WMI_10_2_PDEV_DFS_ENABLE_CMDID,
1356        .pdev_dfs_disable_cmdid = WMI_10_2_PDEV_DFS_DISABLE_CMDID,
1357        .roam_scan_mode = WMI_10_2_ROAM_SCAN_MODE,
1358        .roam_scan_rssi_threshold = WMI_10_2_ROAM_SCAN_RSSI_THRESHOLD,
1359        .roam_scan_period = WMI_10_2_ROAM_SCAN_PERIOD,
1360        .roam_scan_rssi_change_threshold =
1361                                WMI_10_2_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
1362        .roam_ap_profile = WMI_10_2_ROAM_AP_PROFILE,
1363        .ofl_scan_add_ap_profile = WMI_10_2_OFL_SCAN_ADD_AP_PROFILE,
1364        .ofl_scan_remove_ap_profile = WMI_10_2_OFL_SCAN_REMOVE_AP_PROFILE,
1365        .ofl_scan_period = WMI_10_2_OFL_SCAN_PERIOD,
1366        .p2p_dev_set_device_info = WMI_10_2_P2P_DEV_SET_DEVICE_INFO,
1367        .p2p_dev_set_discoverability = WMI_10_2_P2P_DEV_SET_DISCOVERABILITY,
1368        .p2p_go_set_beacon_ie = WMI_10_2_P2P_GO_SET_BEACON_IE,
1369        .p2p_go_set_probe_resp_ie = WMI_10_2_P2P_GO_SET_PROBE_RESP_IE,
1370        .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
1371        .ap_ps_peer_param_cmdid = WMI_10_2_AP_PS_PEER_PARAM_CMDID,
1372        .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
1373        .peer_rate_retry_sched_cmdid = WMI_10_2_PEER_RATE_RETRY_SCHED_CMDID,
1374        .wlan_profile_trigger_cmdid = WMI_10_2_WLAN_PROFILE_TRIGGER_CMDID,
1375        .wlan_profile_set_hist_intvl_cmdid =
1376                                WMI_10_2_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
1377        .wlan_profile_get_profile_data_cmdid =
1378                                WMI_10_2_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
1379        .wlan_profile_enable_profile_id_cmdid =
1380                                WMI_10_2_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
1381        .wlan_profile_list_profile_id_cmdid =
1382                                WMI_10_2_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
1383        .pdev_suspend_cmdid = WMI_10_2_PDEV_SUSPEND_CMDID,
1384        .pdev_resume_cmdid = WMI_10_2_PDEV_RESUME_CMDID,
1385        .add_bcn_filter_cmdid = WMI_10_2_ADD_BCN_FILTER_CMDID,
1386        .rmv_bcn_filter_cmdid = WMI_10_2_RMV_BCN_FILTER_CMDID,
1387        .wow_add_wake_pattern_cmdid = WMI_10_2_WOW_ADD_WAKE_PATTERN_CMDID,
1388        .wow_del_wake_pattern_cmdid = WMI_10_2_WOW_DEL_WAKE_PATTERN_CMDID,
1389        .wow_enable_disable_wake_event_cmdid =
1390                                WMI_10_2_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
1391        .wow_enable_cmdid = WMI_10_2_WOW_ENABLE_CMDID,
1392        .wow_hostwakeup_from_sleep_cmdid =
1393                                WMI_10_2_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
1394        .rtt_measreq_cmdid = WMI_10_2_RTT_MEASREQ_CMDID,
1395        .rtt_tsf_cmdid = WMI_10_2_RTT_TSF_CMDID,
1396        .vdev_spectral_scan_configure_cmdid =
1397                                WMI_10_2_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
1398        .vdev_spectral_scan_enable_cmdid =
1399                                WMI_10_2_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
1400        .request_stats_cmdid = WMI_10_2_REQUEST_STATS_CMDID,
1401        .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
1402        .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
1403        .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
1404        .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
1405        .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
1406        .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
1407        .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
1408        .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
1409        .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
1410        .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
1411        .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
1412        .echo_cmdid = WMI_10_2_ECHO_CMDID,
1413        .pdev_utf_cmdid = WMI_10_2_PDEV_UTF_CMDID,
1414        .dbglog_cfg_cmdid = WMI_10_2_DBGLOG_CFG_CMDID,
1415        .pdev_qvit_cmdid = WMI_10_2_PDEV_QVIT_CMDID,
1416        .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
1417        .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
1418        .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
1419        .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
1420        .gpio_config_cmdid = WMI_10_2_GPIO_CONFIG_CMDID,
1421        .gpio_output_cmdid = WMI_10_2_GPIO_OUTPUT_CMDID,
1422        .pdev_get_temperature_cmdid = WMI_CMD_UNSUPPORTED,
1423        .pdev_enable_adaptive_cca_cmdid = WMI_CMD_UNSUPPORTED,
1424        .scan_update_request_cmdid = WMI_CMD_UNSUPPORTED,
1425        .vdev_standby_response_cmdid = WMI_CMD_UNSUPPORTED,
1426        .vdev_resume_response_cmdid = WMI_CMD_UNSUPPORTED,
1427        .wlan_peer_caching_add_peer_cmdid = WMI_CMD_UNSUPPORTED,
1428        .wlan_peer_caching_evict_peer_cmdid = WMI_CMD_UNSUPPORTED,
1429        .wlan_peer_caching_restore_peer_cmdid = WMI_CMD_UNSUPPORTED,
1430        .wlan_peer_caching_print_all_peers_info_cmdid = WMI_CMD_UNSUPPORTED,
1431        .peer_update_wds_entry_cmdid = WMI_CMD_UNSUPPORTED,
1432        .peer_add_proxy_sta_entry_cmdid = WMI_CMD_UNSUPPORTED,
1433        .rtt_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
1434        .oem_req_cmdid = WMI_CMD_UNSUPPORTED,
1435        .nan_cmdid = WMI_CMD_UNSUPPORTED,
1436        .vdev_ratemask_cmdid = WMI_CMD_UNSUPPORTED,
1437        .qboost_cfg_cmdid = WMI_CMD_UNSUPPORTED,
1438        .pdev_smart_ant_enable_cmdid = WMI_CMD_UNSUPPORTED,
1439        .pdev_smart_ant_set_rx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
1440        .peer_smart_ant_set_tx_antenna_cmdid = WMI_CMD_UNSUPPORTED,
1441        .peer_smart_ant_set_train_info_cmdid = WMI_CMD_UNSUPPORTED,
1442        .peer_smart_ant_set_node_config_ops_cmdid = WMI_CMD_UNSUPPORTED,
1443        .pdev_set_antenna_switch_table_cmdid = WMI_CMD_UNSUPPORTED,
1444        .pdev_set_ctl_table_cmdid = WMI_CMD_UNSUPPORTED,
1445        .pdev_set_mimogain_table_cmdid = WMI_CMD_UNSUPPORTED,
1446        .pdev_ratepwr_table_cmdid = WMI_CMD_UNSUPPORTED,
1447        .pdev_ratepwr_chainmsk_table_cmdid = WMI_CMD_UNSUPPORTED,
1448        .pdev_fips_cmdid = WMI_CMD_UNSUPPORTED,
1449        .tt_set_conf_cmdid = WMI_CMD_UNSUPPORTED,
1450        .fwtest_cmdid = WMI_CMD_UNSUPPORTED,
1451        .vdev_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
1452        .peer_atf_request_cmdid = WMI_CMD_UNSUPPORTED,
1453        .pdev_get_ani_cck_config_cmdid = WMI_CMD_UNSUPPORTED,
1454        .pdev_get_ani_ofdm_config_cmdid = WMI_CMD_UNSUPPORTED,
1455        .pdev_reserve_ast_entry_cmdid = WMI_CMD_UNSUPPORTED,
1456};
1457
1458static struct wmi_pdev_param_map wmi_10_4_pdev_param_map = {
1459        .tx_chain_mask = WMI_10_4_PDEV_PARAM_TX_CHAIN_MASK,
1460        .rx_chain_mask = WMI_10_4_PDEV_PARAM_RX_CHAIN_MASK,
1461        .txpower_limit2g = WMI_10_4_PDEV_PARAM_TXPOWER_LIMIT2G,
1462        .txpower_limit5g = WMI_10_4_PDEV_PARAM_TXPOWER_LIMIT5G,
1463        .txpower_scale = WMI_10_4_PDEV_PARAM_TXPOWER_SCALE,
1464        .beacon_gen_mode = WMI_10_4_PDEV_PARAM_BEACON_GEN_MODE,
1465        .beacon_tx_mode = WMI_10_4_PDEV_PARAM_BEACON_TX_MODE,
1466        .resmgr_offchan_mode = WMI_10_4_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
1467        .protection_mode = WMI_10_4_PDEV_PARAM_PROTECTION_MODE,
1468        .dynamic_bw = WMI_10_4_PDEV_PARAM_DYNAMIC_BW,
1469        .non_agg_sw_retry_th = WMI_10_4_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
1470        .agg_sw_retry_th = WMI_10_4_PDEV_PARAM_AGG_SW_RETRY_TH,
1471        .sta_kickout_th = WMI_10_4_PDEV_PARAM_STA_KICKOUT_TH,
1472        .ac_aggrsize_scaling = WMI_10_4_PDEV_PARAM_AC_AGGRSIZE_SCALING,
1473        .ltr_enable = WMI_10_4_PDEV_PARAM_LTR_ENABLE,
1474        .ltr_ac_latency_be = WMI_10_4_PDEV_PARAM_LTR_AC_LATENCY_BE,
1475        .ltr_ac_latency_bk = WMI_10_4_PDEV_PARAM_LTR_AC_LATENCY_BK,
1476        .ltr_ac_latency_vi = WMI_10_4_PDEV_PARAM_LTR_AC_LATENCY_VI,
1477        .ltr_ac_latency_vo = WMI_10_4_PDEV_PARAM_LTR_AC_LATENCY_VO,
1478        .ltr_ac_latency_timeout = WMI_10_4_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
1479        .ltr_sleep_override = WMI_10_4_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
1480        .ltr_rx_override = WMI_10_4_PDEV_PARAM_LTR_RX_OVERRIDE,
1481        .ltr_tx_activity_timeout = WMI_10_4_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
1482        .l1ss_enable = WMI_10_4_PDEV_PARAM_L1SS_ENABLE,
1483        .dsleep_enable = WMI_10_4_PDEV_PARAM_DSLEEP_ENABLE,
1484        .pcielp_txbuf_flush = WMI_10_4_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
1485        .pcielp_txbuf_watermark = WMI_10_4_PDEV_PARAM_PCIELP_TXBUF_WATERMARK,
1486        .pcielp_txbuf_tmo_en = WMI_10_4_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
1487        .pcielp_txbuf_tmo_value = WMI_10_4_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
1488        .pdev_stats_update_period =
1489                        WMI_10_4_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
1490        .vdev_stats_update_period =
1491                        WMI_10_4_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
1492        .peer_stats_update_period =
1493                        WMI_10_4_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
1494        .bcnflt_stats_update_period =
1495                        WMI_10_4_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
1496        .pmf_qos = WMI_10_4_PDEV_PARAM_PMF_QOS,
1497        .arp_ac_override = WMI_10_4_PDEV_PARAM_ARP_AC_OVERRIDE,
1498        .dcs = WMI_10_4_PDEV_PARAM_DCS,
1499        .ani_enable = WMI_10_4_PDEV_PARAM_ANI_ENABLE,
1500        .ani_poll_period = WMI_10_4_PDEV_PARAM_ANI_POLL_PERIOD,
1501        .ani_listen_period = WMI_10_4_PDEV_PARAM_ANI_LISTEN_PERIOD,
1502        .ani_ofdm_level = WMI_10_4_PDEV_PARAM_ANI_OFDM_LEVEL,
1503        .ani_cck_level = WMI_10_4_PDEV_PARAM_ANI_CCK_LEVEL,
1504        .dyntxchain = WMI_10_4_PDEV_PARAM_DYNTXCHAIN,
1505        .proxy_sta = WMI_10_4_PDEV_PARAM_PROXY_STA,
1506        .idle_ps_config = WMI_10_4_PDEV_PARAM_IDLE_PS_CONFIG,
1507        .power_gating_sleep = WMI_10_4_PDEV_PARAM_POWER_GATING_SLEEP,
1508        .fast_channel_reset = WMI_10_4_PDEV_PARAM_FAST_CHANNEL_RESET,
1509        .burst_dur = WMI_10_4_PDEV_PARAM_BURST_DUR,
1510        .burst_enable = WMI_10_4_PDEV_PARAM_BURST_ENABLE,
1511        .cal_period = WMI_10_4_PDEV_PARAM_CAL_PERIOD,
1512        .aggr_burst = WMI_10_4_PDEV_PARAM_AGGR_BURST,
1513        .rx_decap_mode = WMI_10_4_PDEV_PARAM_RX_DECAP_MODE,
1514        .smart_antenna_default_antenna =
1515                        WMI_10_4_PDEV_PARAM_SMART_ANTENNA_DEFAULT_ANTENNA,
1516        .igmpmld_override = WMI_10_4_PDEV_PARAM_IGMPMLD_OVERRIDE,
1517        .igmpmld_tid = WMI_10_4_PDEV_PARAM_IGMPMLD_TID,
1518        .antenna_gain = WMI_10_4_PDEV_PARAM_ANTENNA_GAIN,
1519        .rx_filter = WMI_10_4_PDEV_PARAM_RX_FILTER,
1520        .set_mcast_to_ucast_tid = WMI_10_4_PDEV_SET_MCAST_TO_UCAST_TID,
1521        .proxy_sta_mode = WMI_10_4_PDEV_PARAM_PROXY_STA_MODE,
1522        .set_mcast2ucast_mode = WMI_10_4_PDEV_PARAM_SET_MCAST2UCAST_MODE,
1523        .set_mcast2ucast_buffer = WMI_10_4_PDEV_PARAM_SET_MCAST2UCAST_BUFFER,
1524        .remove_mcast2ucast_buffer =
1525                        WMI_10_4_PDEV_PARAM_REMOVE_MCAST2UCAST_BUFFER,
1526        .peer_sta_ps_statechg_enable =
1527                        WMI_10_4_PDEV_PEER_STA_PS_STATECHG_ENABLE,
1528        .igmpmld_ac_override = WMI_10_4_PDEV_PARAM_IGMPMLD_AC_OVERRIDE,
1529        .block_interbss = WMI_10_4_PDEV_PARAM_BLOCK_INTERBSS,
1530        .set_disable_reset_cmdid = WMI_10_4_PDEV_PARAM_SET_DISABLE_RESET_CMDID,
1531        .set_msdu_ttl_cmdid = WMI_10_4_PDEV_PARAM_SET_MSDU_TTL_CMDID,
1532        .set_ppdu_duration_cmdid = WMI_10_4_PDEV_PARAM_SET_PPDU_DURATION_CMDID,
1533        .txbf_sound_period_cmdid = WMI_10_4_PDEV_PARAM_TXBF_SOUND_PERIOD_CMDID,
1534        .set_promisc_mode_cmdid = WMI_10_4_PDEV_PARAM_SET_PROMISC_MODE_CMDID,
1535        .set_burst_mode_cmdid = WMI_10_4_PDEV_PARAM_SET_BURST_MODE_CMDID,
1536        .en_stats = WMI_10_4_PDEV_PARAM_EN_STATS,
1537        .mu_group_policy = WMI_10_4_PDEV_PARAM_MU_GROUP_POLICY,
1538        .noise_detection = WMI_10_4_PDEV_PARAM_NOISE_DETECTION,
1539        .noise_threshold = WMI_10_4_PDEV_PARAM_NOISE_THRESHOLD,
1540        .dpd_enable = WMI_10_4_PDEV_PARAM_DPD_ENABLE,
1541        .set_mcast_bcast_echo = WMI_10_4_PDEV_PARAM_SET_MCAST_BCAST_ECHO,
1542        .atf_strict_sch = WMI_10_4_PDEV_PARAM_ATF_STRICT_SCH,
1543        .atf_sched_duration = WMI_10_4_PDEV_PARAM_ATF_SCHED_DURATION,
1544        .ant_plzn = WMI_10_4_PDEV_PARAM_ANT_PLZN,
1545        .mgmt_retry_limit = WMI_10_4_PDEV_PARAM_MGMT_RETRY_LIMIT,
1546        .sensitivity_level = WMI_10_4_PDEV_PARAM_SENSITIVITY_LEVEL,
1547        .signed_txpower_2g = WMI_10_4_PDEV_PARAM_SIGNED_TXPOWER_2G,
1548        .signed_txpower_5g = WMI_10_4_PDEV_PARAM_SIGNED_TXPOWER_5G,
1549        .enable_per_tid_amsdu = WMI_10_4_PDEV_PARAM_ENABLE_PER_TID_AMSDU,
1550        .enable_per_tid_ampdu = WMI_10_4_PDEV_PARAM_ENABLE_PER_TID_AMPDU,
1551        .cca_threshold = WMI_10_4_PDEV_PARAM_CCA_THRESHOLD,
1552        .rts_fixed_rate = WMI_10_4_PDEV_PARAM_RTS_FIXED_RATE,
1553        .pdev_reset = WMI_10_4_PDEV_PARAM_PDEV_RESET,
1554        .wapi_mbssid_offset = WMI_10_4_PDEV_PARAM_WAPI_MBSSID_OFFSET,
1555        .arp_srcaddr = WMI_10_4_PDEV_PARAM_ARP_SRCADDR,
1556        .arp_dstaddr = WMI_10_4_PDEV_PARAM_ARP_DSTADDR,
1557        .enable_btcoex = WMI_10_4_PDEV_PARAM_ENABLE_BTCOEX,
1558};
1559
1560static const struct wmi_peer_flags_map wmi_peer_flags_map = {
1561        .auth = WMI_PEER_AUTH,
1562        .qos = WMI_PEER_QOS,
1563        .need_ptk_4_way = WMI_PEER_NEED_PTK_4_WAY,
1564        .need_gtk_2_way = WMI_PEER_NEED_GTK_2_WAY,
1565        .apsd = WMI_PEER_APSD,
1566        .ht = WMI_PEER_HT,
1567        .bw40 = WMI_PEER_40MHZ,
1568        .stbc = WMI_PEER_STBC,
1569        .ldbc = WMI_PEER_LDPC,
1570        .dyn_mimops = WMI_PEER_DYN_MIMOPS,
1571        .static_mimops = WMI_PEER_STATIC_MIMOPS,
1572        .spatial_mux = WMI_PEER_SPATIAL_MUX,
1573        .vht = WMI_PEER_VHT,
1574        .bw80 = WMI_PEER_80MHZ,
1575        .vht_2g = WMI_PEER_VHT_2G,
1576        .pmf = WMI_PEER_PMF,
1577};
1578
1579static const struct wmi_peer_flags_map wmi_10x_peer_flags_map = {
1580        .auth = WMI_10X_PEER_AUTH,
1581        .qos = WMI_10X_PEER_QOS,
1582        .need_ptk_4_way = WMI_10X_PEER_NEED_PTK_4_WAY,
1583        .need_gtk_2_way = WMI_10X_PEER_NEED_GTK_2_WAY,
1584        .apsd = WMI_10X_PEER_APSD,
1585        .ht = WMI_10X_PEER_HT,
1586        .bw40 = WMI_10X_PEER_40MHZ,
1587        .stbc = WMI_10X_PEER_STBC,
1588        .ldbc = WMI_10X_PEER_LDPC,
1589        .dyn_mimops = WMI_10X_PEER_DYN_MIMOPS,
1590        .static_mimops = WMI_10X_PEER_STATIC_MIMOPS,
1591        .spatial_mux = WMI_10X_PEER_SPATIAL_MUX,
1592        .vht = WMI_10X_PEER_VHT,
1593        .bw80 = WMI_10X_PEER_80MHZ,
1594};
1595
1596static const struct wmi_peer_flags_map wmi_10_2_peer_flags_map = {
1597        .auth = WMI_10_2_PEER_AUTH,
1598        .qos = WMI_10_2_PEER_QOS,
1599        .need_ptk_4_way = WMI_10_2_PEER_NEED_PTK_4_WAY,
1600        .need_gtk_2_way = WMI_10_2_PEER_NEED_GTK_2_WAY,
1601        .apsd = WMI_10_2_PEER_APSD,
1602        .ht = WMI_10_2_PEER_HT,
1603        .bw40 = WMI_10_2_PEER_40MHZ,
1604        .stbc = WMI_10_2_PEER_STBC,
1605        .ldbc = WMI_10_2_PEER_LDPC,
1606        .dyn_mimops = WMI_10_2_PEER_DYN_MIMOPS,
1607        .static_mimops = WMI_10_2_PEER_STATIC_MIMOPS,
1608        .spatial_mux = WMI_10_2_PEER_SPATIAL_MUX,
1609        .vht = WMI_10_2_PEER_VHT,
1610        .bw80 = WMI_10_2_PEER_80MHZ,
1611        .vht_2g = WMI_10_2_PEER_VHT_2G,
1612        .pmf = WMI_10_2_PEER_PMF,
1613};
1614
1615void ath10k_wmi_put_wmi_channel(struct wmi_channel *ch,
1616                                const struct wmi_channel_arg *arg)
1617{
1618        u32 flags = 0;
1619
1620        memset(ch, 0, sizeof(*ch));
1621
1622        if (arg->passive)
1623                flags |= WMI_CHAN_FLAG_PASSIVE;
1624        if (arg->allow_ibss)
1625                flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
1626        if (arg->allow_ht)
1627                flags |= WMI_CHAN_FLAG_ALLOW_HT;
1628        if (arg->allow_vht)
1629                flags |= WMI_CHAN_FLAG_ALLOW_VHT;
1630        if (arg->ht40plus)
1631                flags |= WMI_CHAN_FLAG_HT40_PLUS;
1632        if (arg->chan_radar)
1633                flags |= WMI_CHAN_FLAG_DFS;
1634
1635        ch->mhz = __cpu_to_le32(arg->freq);
1636        ch->band_center_freq1 = __cpu_to_le32(arg->band_center_freq1);
1637        ch->band_center_freq2 = 0;
1638        ch->min_power = arg->min_power;
1639        ch->max_power = arg->max_power;
1640        ch->reg_power = arg->max_reg_power;
1641        ch->antenna_max = arg->max_antenna_gain;
1642        ch->max_tx_power = arg->max_power;
1643
1644        /* mode & flags share storage */
1645        ch->mode = arg->mode;
1646        ch->flags |= __cpu_to_le32(flags);
1647}
1648
1649int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
1650{
1651        unsigned long time_left;
1652
1653        time_left = wait_for_completion_timeout(&ar->wmi.service_ready,
1654                                                WMI_SERVICE_READY_TIMEOUT_HZ);
1655        if (!time_left)
1656                return -ETIMEDOUT;
1657        return 0;
1658}
1659
1660int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
1661{
1662        unsigned long time_left;
1663
1664        time_left = wait_for_completion_timeout(&ar->wmi.unified_ready,
1665                                                WMI_UNIFIED_READY_TIMEOUT_HZ);
1666        if (!time_left)
1667                return -ETIMEDOUT;
1668        return 0;
1669}
1670
1671struct sk_buff *ath10k_wmi_alloc_skb(struct ath10k *ar, u32 len)
1672{
1673        struct sk_buff *skb;
1674        u32 round_len = roundup(len, 4);
1675
1676        skb = ath10k_htc_alloc_skb(ar, WMI_SKB_HEADROOM + round_len);
1677        if (!skb)
1678                return NULL;
1679
1680        skb_reserve(skb, WMI_SKB_HEADROOM);
1681        if (!IS_ALIGNED((unsigned long)skb->data, 4))
1682                ath10k_warn(ar, "Unaligned WMI skb\n");
1683
1684        skb_put(skb, round_len);
1685        memset(skb->data, 0, round_len);
1686
1687        return skb;
1688}
1689
1690static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
1691{
1692        dev_kfree_skb(skb);
1693}
1694
1695int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
1696                               u32 cmd_id)
1697{
1698        struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
1699        struct wmi_cmd_hdr *cmd_hdr;
1700        int ret;
1701        u32 cmd = 0;
1702
1703        if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
1704                return -ENOMEM;
1705
1706        cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
1707
1708        cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
1709        cmd_hdr->cmd_id = __cpu_to_le32(cmd);
1710
1711        memset(skb_cb, 0, sizeof(*skb_cb));
1712        ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
1713        trace_ath10k_wmi_cmd(ar, cmd_id, skb->data, skb->len, ret);
1714
1715        if (ret)
1716                goto err_pull;
1717
1718        return 0;
1719
1720err_pull:
1721        skb_pull(skb, sizeof(struct wmi_cmd_hdr));
1722        return ret;
1723}
1724
1725static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
1726{
1727        struct ath10k *ar = arvif->ar;
1728        struct ath10k_skb_cb *cb;
1729        struct sk_buff *bcn;
1730        bool dtim_zero;
1731        bool deliver_cab;
1732        int ret;
1733
1734        spin_lock_bh(&ar->data_lock);
1735
1736        bcn = arvif->beacon;
1737
1738        if (!bcn)
1739                goto unlock;
1740
1741        cb = ATH10K_SKB_CB(bcn);
1742
1743        switch (arvif->beacon_state) {
1744        case ATH10K_BEACON_SENDING:
1745        case ATH10K_BEACON_SENT:
1746                break;
1747        case ATH10K_BEACON_SCHEDULED:
1748                arvif->beacon_state = ATH10K_BEACON_SENDING;
1749                spin_unlock_bh(&ar->data_lock);
1750
1751                dtim_zero = !!(cb->flags & ATH10K_SKB_F_DTIM_ZERO);
1752                deliver_cab = !!(cb->flags & ATH10K_SKB_F_DELIVER_CAB);
1753                ret = ath10k_wmi_beacon_send_ref_nowait(arvif->ar,
1754                                                        arvif->vdev_id,
1755                                                        bcn->data, bcn->len,
1756                                                        cb->paddr,
1757                                                        dtim_zero,
1758                                                        deliver_cab);
1759
1760                spin_lock_bh(&ar->data_lock);
1761
1762                if (ret == 0)
1763                        arvif->beacon_state = ATH10K_BEACON_SENT;
1764                else
1765                        arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
1766        }
1767
1768unlock:
1769        spin_unlock_bh(&ar->data_lock);
1770}
1771
1772static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
1773                                       struct ieee80211_vif *vif)
1774{
1775        struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1776
1777        ath10k_wmi_tx_beacon_nowait(arvif);
1778}
1779
1780static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
1781{
1782        ieee80211_iterate_active_interfaces_atomic(ar->hw,
1783                                                   IEEE80211_IFACE_ITER_NORMAL,
1784                                                   ath10k_wmi_tx_beacons_iter,
1785                                                   NULL);
1786}
1787
1788static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
1789{
1790        /* try to send pending beacons first. they take priority */
1791        ath10k_wmi_tx_beacons_nowait(ar);
1792
1793        wake_up(&ar->wmi.tx_credits_wq);
1794}
1795
1796int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id)
1797{
1798        int ret = -EOPNOTSUPP;
1799
1800        might_sleep();
1801
1802        if (cmd_id == WMI_CMD_UNSUPPORTED) {
1803                ath10k_warn(ar, "wmi command %d is not supported by firmware\n",
1804                            cmd_id);
1805                return ret;
1806        }
1807
1808        wait_event_timeout(ar->wmi.tx_credits_wq, ({
1809                /* try to send pending beacons first. they take priority */
1810                ath10k_wmi_tx_beacons_nowait(ar);
1811
1812                ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
1813
1814                if (ret && test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
1815                        ret = -ESHUTDOWN;
1816
1817                (ret != -EAGAIN);
1818        }), 3 * HZ);
1819
1820        if (ret)
1821                dev_kfree_skb_any(skb);
1822
1823        return ret;
1824}
1825
1826static struct sk_buff *
1827ath10k_wmi_op_gen_mgmt_tx(struct ath10k *ar, struct sk_buff *msdu)
1828{
1829        struct ath10k_skb_cb *cb = ATH10K_SKB_CB(msdu);
1830        struct ath10k_vif *arvif;
1831        struct wmi_mgmt_tx_cmd *cmd;
1832        struct ieee80211_hdr *hdr;
1833        struct sk_buff *skb;
1834        int len;
1835        u32 vdev_id;
1836        u32 buf_len = msdu->len;
1837        u16 fc;
1838
1839        hdr = (struct ieee80211_hdr *)msdu->data;
1840        fc = le16_to_cpu(hdr->frame_control);
1841
1842        if (cb->vif) {
1843                arvif = (void *)cb->vif->drv_priv;
1844                vdev_id = arvif->vdev_id;
1845        } else {
1846                vdev_id = 0;
1847        }
1848
1849        if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
1850                return ERR_PTR(-EINVAL);
1851
1852        len = sizeof(cmd->hdr) + msdu->len;
1853
1854        if ((ieee80211_is_action(hdr->frame_control) ||
1855             ieee80211_is_deauth(hdr->frame_control) ||
1856             ieee80211_is_disassoc(hdr->frame_control)) &&
1857             ieee80211_has_protected(hdr->frame_control)) {
1858                len += IEEE80211_CCMP_MIC_LEN;
1859                buf_len += IEEE80211_CCMP_MIC_LEN;
1860        }
1861
1862        len = round_up(len, 4);
1863
1864        skb = ath10k_wmi_alloc_skb(ar, len);
1865        if (!skb)
1866                return ERR_PTR(-ENOMEM);
1867
1868        cmd = (struct wmi_mgmt_tx_cmd *)skb->data;
1869
1870        cmd->hdr.vdev_id = __cpu_to_le32(vdev_id);
1871        cmd->hdr.tx_rate = 0;
1872        cmd->hdr.tx_power = 0;
1873        cmd->hdr.buf_len = __cpu_to_le32(buf_len);
1874
1875        ether_addr_copy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr));
1876        memcpy(cmd->buf, msdu->data, msdu->len);
1877
1878        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx skb %pK len %d ftype %02x stype %02x\n",
1879                   msdu, skb->len, fc & IEEE80211_FCTL_FTYPE,
1880                   fc & IEEE80211_FCTL_STYPE);
1881        trace_ath10k_tx_hdr(ar, skb->data, skb->len);
1882        trace_ath10k_tx_payload(ar, skb->data, skb->len);
1883
1884        return skb;
1885}
1886
1887static void ath10k_wmi_event_scan_started(struct ath10k *ar)
1888{
1889        lockdep_assert_held(&ar->data_lock);
1890
1891        switch (ar->scan.state) {
1892        case ATH10K_SCAN_IDLE:
1893        case ATH10K_SCAN_RUNNING:
1894        case ATH10K_SCAN_ABORTING:
1895                ath10k_warn(ar, "received scan started event in an invalid scan state: %s (%d)\n",
1896                            ath10k_scan_state_str(ar->scan.state),
1897                            ar->scan.state);
1898                break;
1899        case ATH10K_SCAN_STARTING:
1900                ar->scan.state = ATH10K_SCAN_RUNNING;
1901
1902                if (ar->scan.is_roc)
1903                        ieee80211_ready_on_channel(ar->hw);
1904
1905                complete(&ar->scan.started);
1906                break;
1907        }
1908}
1909
1910static void ath10k_wmi_event_scan_start_failed(struct ath10k *ar)
1911{
1912        lockdep_assert_held(&ar->data_lock);
1913
1914        switch (ar->scan.state) {
1915        case ATH10K_SCAN_IDLE:
1916        case ATH10K_SCAN_RUNNING:
1917        case ATH10K_SCAN_ABORTING:
1918                ath10k_warn(ar, "received scan start failed event in an invalid scan state: %s (%d)\n",
1919                            ath10k_scan_state_str(ar->scan.state),
1920                            ar->scan.state);
1921                break;
1922        case ATH10K_SCAN_STARTING:
1923                complete(&ar->scan.started);
1924                __ath10k_scan_finish(ar);
1925                break;
1926        }
1927}
1928
1929static void ath10k_wmi_event_scan_completed(struct ath10k *ar)
1930{
1931        lockdep_assert_held(&ar->data_lock);
1932
1933        switch (ar->scan.state) {
1934        case ATH10K_SCAN_IDLE:
1935        case ATH10K_SCAN_STARTING:
1936                /* One suspected reason scan can be completed while starting is
1937                 * if firmware fails to deliver all scan events to the host,
1938                 * e.g. when transport pipe is full. This has been observed
1939                 * with spectral scan phyerr events starving wmi transport
1940                 * pipe. In such case the "scan completed" event should be (and
1941                 * is) ignored by the host as it may be just firmware's scan
1942                 * state machine recovering.
1943                 */
1944                ath10k_warn(ar, "received scan completed event in an invalid scan state: %s (%d)\n",
1945                            ath10k_scan_state_str(ar->scan.state),
1946                            ar->scan.state);
1947                break;
1948        case ATH10K_SCAN_RUNNING:
1949        case ATH10K_SCAN_ABORTING:
1950                __ath10k_scan_finish(ar);
1951                break;
1952        }
1953}
1954
1955static void ath10k_wmi_event_scan_bss_chan(struct ath10k *ar)
1956{
1957        lockdep_assert_held(&ar->data_lock);
1958
1959        switch (ar->scan.state) {
1960        case ATH10K_SCAN_IDLE:
1961        case ATH10K_SCAN_STARTING:
1962                ath10k_warn(ar, "received scan bss chan event in an invalid scan state: %s (%d)\n",
1963                            ath10k_scan_state_str(ar->scan.state),
1964                            ar->scan.state);
1965                break;
1966        case ATH10K_SCAN_RUNNING:
1967        case ATH10K_SCAN_ABORTING:
1968                ar->scan_channel = NULL;
1969                break;
1970        }
1971}
1972
1973static void ath10k_wmi_event_scan_foreign_chan(struct ath10k *ar, u32 freq)
1974{
1975        lockdep_assert_held(&ar->data_lock);
1976
1977        switch (ar->scan.state) {
1978        case ATH10K_SCAN_IDLE:
1979        case ATH10K_SCAN_STARTING:
1980                ath10k_warn(ar, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
1981                            ath10k_scan_state_str(ar->scan.state),
1982                            ar->scan.state);
1983                break;
1984        case ATH10K_SCAN_RUNNING:
1985        case ATH10K_SCAN_ABORTING:
1986                ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
1987
1988                if (ar->scan.is_roc && ar->scan.roc_freq == freq)
1989                        complete(&ar->scan.on_channel);
1990                break;
1991        }
1992}
1993
1994static const char *
1995ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
1996                               enum wmi_scan_completion_reason reason)
1997{
1998        switch (type) {
1999        case WMI_SCAN_EVENT_STARTED:
2000                return "started";
2001        case WMI_SCAN_EVENT_COMPLETED:
2002                switch (reason) {
2003                case WMI_SCAN_REASON_COMPLETED:
2004                        return "completed";
2005                case WMI_SCAN_REASON_CANCELLED:
2006                        return "completed [cancelled]";
2007                case WMI_SCAN_REASON_PREEMPTED:
2008                        return "completed [preempted]";
2009                case WMI_SCAN_REASON_TIMEDOUT:
2010                        return "completed [timedout]";
2011                case WMI_SCAN_REASON_INTERNAL_FAILURE:
2012                        return "completed [internal err]";
2013                case WMI_SCAN_REASON_MAX:
2014                        break;
2015                }
2016                return "completed [unknown]";
2017        case WMI_SCAN_EVENT_BSS_CHANNEL:
2018                return "bss channel";
2019        case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
2020                return "foreign channel";
2021        case WMI_SCAN_EVENT_DEQUEUED:
2022                return "dequeued";
2023        case WMI_SCAN_EVENT_PREEMPTED:
2024                return "preempted";
2025        case WMI_SCAN_EVENT_START_FAILED:
2026                return "start failed";
2027        case WMI_SCAN_EVENT_RESTARTED:
2028                return "restarted";
2029        case WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT:
2030                return "foreign channel exit";
2031        default:
2032                return "unknown";
2033        }
2034}
2035
2036static int ath10k_wmi_op_pull_scan_ev(struct ath10k *ar, struct sk_buff *skb,
2037                                      struct wmi_scan_ev_arg *arg)
2038{
2039        struct wmi_scan_event *ev = (void *)skb->data;
2040
2041        if (skb->len < sizeof(*ev))
2042                return -EPROTO;
2043
2044        skb_pull(skb, sizeof(*ev));
2045        arg->event_type = ev->event_type;
2046        arg->reason = ev->reason;
2047        arg->channel_freq = ev->channel_freq;
2048        arg->scan_req_id = ev->scan_req_id;
2049        arg->scan_id = ev->scan_id;
2050        arg->vdev_id = ev->vdev_id;
2051
2052        return 0;
2053}
2054
2055int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
2056{
2057        struct wmi_scan_ev_arg arg = {};
2058        enum wmi_scan_event_type event_type;
2059        enum wmi_scan_completion_reason reason;
2060        u32 freq;
2061        u32 req_id;
2062        u32 scan_id;
2063        u32 vdev_id;
2064        int ret;
2065
2066        ret = ath10k_wmi_pull_scan(ar, skb, &arg);
2067        if (ret) {
2068                ath10k_warn(ar, "failed to parse scan event: %d\n", ret);
2069                return ret;
2070        }
2071
2072        event_type = __le32_to_cpu(arg.event_type);
2073        reason = __le32_to_cpu(arg.reason);
2074        freq = __le32_to_cpu(arg.channel_freq);
2075        req_id = __le32_to_cpu(arg.scan_req_id);
2076        scan_id = __le32_to_cpu(arg.scan_id);
2077        vdev_id = __le32_to_cpu(arg.vdev_id);
2078
2079        spin_lock_bh(&ar->data_lock);
2080
2081        ath10k_dbg(ar, ATH10K_DBG_WMI,
2082                   "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
2083                   ath10k_wmi_event_scan_type_str(event_type, reason),
2084                   event_type, reason, freq, req_id, scan_id, vdev_id,
2085                   ath10k_scan_state_str(ar->scan.state), ar->scan.state);
2086
2087        switch (event_type) {
2088        case WMI_SCAN_EVENT_STARTED:
2089                ath10k_wmi_event_scan_started(ar);
2090                break;
2091        case WMI_SCAN_EVENT_COMPLETED:
2092                ath10k_wmi_event_scan_completed(ar);
2093                break;
2094        case WMI_SCAN_EVENT_BSS_CHANNEL:
2095                ath10k_wmi_event_scan_bss_chan(ar);
2096                break;
2097        case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
2098                ath10k_wmi_event_scan_foreign_chan(ar, freq);
2099                break;
2100        case WMI_SCAN_EVENT_START_FAILED:
2101                ath10k_warn(ar, "received scan start failure event\n");
2102                ath10k_wmi_event_scan_start_failed(ar);
2103                break;
2104        case WMI_SCAN_EVENT_DEQUEUED:
2105        case WMI_SCAN_EVENT_PREEMPTED:
2106        case WMI_SCAN_EVENT_RESTARTED:
2107        case WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT:
2108        default:
2109                break;
2110        }
2111
2112        spin_unlock_bh(&ar->data_lock);
2113        return 0;
2114}
2115
2116/* If keys are configured, HW decrypts all frames
2117 * with protected bit set. Mark such frames as decrypted.
2118 */
2119static void ath10k_wmi_handle_wep_reauth(struct ath10k *ar,
2120                                         struct sk_buff *skb,
2121                                         struct ieee80211_rx_status *status)
2122{
2123        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2124        unsigned int hdrlen;
2125        bool peer_key;
2126        u8 *addr, keyidx;
2127
2128        if (!ieee80211_is_auth(hdr->frame_control) ||
2129            !ieee80211_has_protected(hdr->frame_control))
2130                return;
2131
2132        hdrlen = ieee80211_hdrlen(hdr->frame_control);
2133        if (skb->len < (hdrlen + IEEE80211_WEP_IV_LEN))
2134                return;
2135
2136        keyidx = skb->data[hdrlen + (IEEE80211_WEP_IV_LEN - 1)] >> WEP_KEYID_SHIFT;
2137        addr = ieee80211_get_SA(hdr);
2138
2139        spin_lock_bh(&ar->data_lock);
2140        peer_key = ath10k_mac_is_peer_wep_key_set(ar, addr, keyidx);
2141        spin_unlock_bh(&ar->data_lock);
2142
2143        if (peer_key) {
2144                ath10k_dbg(ar, ATH10K_DBG_MAC,
2145                           "mac wep key present for peer %pM\n", addr);
2146                status->flag |= RX_FLAG_DECRYPTED;
2147        }
2148}
2149
2150static int ath10k_wmi_op_pull_mgmt_rx_ev(struct ath10k *ar, struct sk_buff *skb,
2151                                         struct wmi_mgmt_rx_ev_arg *arg)
2152{
2153        struct wmi_mgmt_rx_event_v1 *ev_v1;
2154        struct wmi_mgmt_rx_event_v2 *ev_v2;
2155        struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
2156        struct wmi_mgmt_rx_ext_info *ext_info;
2157        size_t pull_len;
2158        u32 msdu_len;
2159        u32 len;
2160
2161        if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX,
2162                     ar->running_fw->fw_file.fw_features)) {
2163                ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
2164                ev_hdr = &ev_v2->hdr.v1;
2165                pull_len = sizeof(*ev_v2);
2166        } else {
2167                ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
2168                ev_hdr = &ev_v1->hdr;
2169                pull_len = sizeof(*ev_v1);
2170        }
2171
2172        if (skb->len < pull_len)
2173                return -EPROTO;
2174
2175        skb_pull(skb, pull_len);
2176        arg->channel = ev_hdr->channel;
2177        arg->buf_len = ev_hdr->buf_len;
2178        arg->status = ev_hdr->status;
2179        arg->snr = ev_hdr->snr;
2180        arg->phy_mode = ev_hdr->phy_mode;
2181        arg->rate = ev_hdr->rate;
2182
2183        msdu_len = __le32_to_cpu(arg->buf_len);
2184        if (skb->len < msdu_len)
2185                return -EPROTO;
2186
2187        if (le32_to_cpu(arg->status) & WMI_RX_STATUS_EXT_INFO) {
2188                len = ALIGN(le32_to_cpu(arg->buf_len), 4);
2189                ext_info = (struct wmi_mgmt_rx_ext_info *)(skb->data + len);
2190                memcpy(&arg->ext_info, ext_info,
2191                       sizeof(struct wmi_mgmt_rx_ext_info));
2192        }
2193        /* the WMI buffer might've ended up being padded to 4 bytes due to HTC
2194         * trailer with credit update. Trim the excess garbage.
2195         */
2196        skb_trim(skb, msdu_len);
2197
2198        return 0;
2199}
2200
2201static int ath10k_wmi_10_4_op_pull_mgmt_rx_ev(struct ath10k *ar,
2202                                              struct sk_buff *skb,
2203                                              struct wmi_mgmt_rx_ev_arg *arg)
2204{
2205        struct wmi_10_4_mgmt_rx_event *ev;
2206        struct wmi_10_4_mgmt_rx_hdr *ev_hdr;
2207        size_t pull_len;
2208        u32 msdu_len;
2209        struct wmi_mgmt_rx_ext_info *ext_info;
2210        u32 len;
2211
2212        ev = (struct wmi_10_4_mgmt_rx_event *)skb->data;
2213        ev_hdr = &ev->hdr;
2214        pull_len = sizeof(*ev);
2215
2216        if (skb->len < pull_len)
2217                return -EPROTO;
2218
2219        skb_pull(skb, pull_len);
2220        arg->channel = ev_hdr->channel;
2221        arg->buf_len = ev_hdr->buf_len;
2222        arg->status = ev_hdr->status;
2223        arg->snr = ev_hdr->snr;
2224        arg->phy_mode = ev_hdr->phy_mode;
2225        arg->rate = ev_hdr->rate;
2226
2227        msdu_len = __le32_to_cpu(arg->buf_len);
2228        if (skb->len < msdu_len)
2229                return -EPROTO;
2230
2231        if (le32_to_cpu(arg->status) & WMI_RX_STATUS_EXT_INFO) {
2232                len = ALIGN(le32_to_cpu(arg->buf_len), 4);
2233                ext_info = (struct wmi_mgmt_rx_ext_info *)(skb->data + len);
2234                memcpy(&arg->ext_info, ext_info,
2235                       sizeof(struct wmi_mgmt_rx_ext_info));
2236        }
2237
2238        /* Make sure bytes added for padding are removed. */
2239        skb_trim(skb, msdu_len);
2240
2241        return 0;
2242}
2243
2244static bool ath10k_wmi_rx_is_decrypted(struct ath10k *ar,
2245                                       struct ieee80211_hdr *hdr)
2246{
2247        if (!ieee80211_has_protected(hdr->frame_control))
2248                return false;
2249
2250        /* FW delivers WEP Shared Auth frame with Protected Bit set and
2251         * encrypted payload. However in case of PMF it delivers decrypted
2252         * frames with Protected Bit set.
2253         */
2254        if (ieee80211_is_auth(hdr->frame_control))
2255                return false;
2256
2257        /* qca99x0 based FW delivers broadcast or multicast management frames
2258         * (ex: group privacy action frames in mesh) as encrypted payload.
2259         */
2260        if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) &&
2261            ar->hw_params.sw_decrypt_mcast_mgmt)
2262                return false;
2263
2264        return true;
2265}
2266
2267int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
2268{
2269        struct wmi_mgmt_rx_ev_arg arg = {};
2270        struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2271        struct ieee80211_hdr *hdr;
2272        struct ieee80211_supported_band *sband;
2273        u32 rx_status;
2274        u32 channel;
2275        u32 phy_mode;
2276        u32 snr;
2277        u32 rate;
2278        u32 buf_len;
2279        u16 fc;
2280        int ret;
2281
2282        ret = ath10k_wmi_pull_mgmt_rx(ar, skb, &arg);
2283        if (ret) {
2284                ath10k_warn(ar, "failed to parse mgmt rx event: %d\n", ret);
2285                dev_kfree_skb(skb);
2286                return ret;
2287        }
2288
2289        channel = __le32_to_cpu(arg.channel);
2290        buf_len = __le32_to_cpu(arg.buf_len);
2291        rx_status = __le32_to_cpu(arg.status);
2292        snr = __le32_to_cpu(arg.snr);
2293        phy_mode = __le32_to_cpu(arg.phy_mode);
2294        rate = __le32_to_cpu(arg.rate);
2295
2296        memset(status, 0, sizeof(*status));
2297
2298        ath10k_dbg(ar, ATH10K_DBG_MGMT,
2299                   "event mgmt rx status %08x\n", rx_status);
2300
2301        if ((test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) ||
2302            (rx_status & (WMI_RX_STATUS_ERR_DECRYPT |
2303            WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
2304                dev_kfree_skb(skb);
2305                return 0;
2306        }
2307
2308        if (rx_status & WMI_RX_STATUS_ERR_MIC)
2309                status->flag |= RX_FLAG_MMIC_ERROR;
2310
2311        if (rx_status & WMI_RX_STATUS_EXT_INFO) {
2312                status->mactime =
2313                        __le64_to_cpu(arg.ext_info.rx_mac_timestamp);
2314                status->flag |= RX_FLAG_MACTIME_END;
2315        }
2316        /* Hardware can Rx CCK rates on 5GHz. In that case phy_mode is set to
2317         * MODE_11B. This means phy_mode is not a reliable source for the band
2318         * of mgmt rx.
2319         */
2320        if (channel >= 1 && channel <= 14) {
2321                status->band = NL80211_BAND_2GHZ;
2322        } else if (channel >= 36 && channel <= 165) {
2323                status->band = NL80211_BAND_5GHZ;
2324        } else {
2325                /* Shouldn't happen unless list of advertised channels to
2326                 * mac80211 has been changed.
2327                 */
2328                WARN_ON_ONCE(1);
2329                dev_kfree_skb(skb);
2330                return 0;
2331        }
2332
2333        if (phy_mode == MODE_11B && status->band == NL80211_BAND_5GHZ)
2334                ath10k_dbg(ar, ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
2335
2336        sband = &ar->mac.sbands[status->band];
2337
2338        status->freq = ieee80211_channel_to_frequency(channel, status->band);
2339        status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
2340        status->rate_idx = ath10k_mac_bitrate_to_idx(sband, rate / 100);
2341
2342        hdr = (struct ieee80211_hdr *)skb->data;
2343        fc = le16_to_cpu(hdr->frame_control);
2344
2345        /* Firmware is guaranteed to report all essential management frames via
2346         * WMI while it can deliver some extra via HTT. Since there can be
2347         * duplicates split the reporting wrt monitor/sniffing.
2348         */
2349        status->flag |= RX_FLAG_SKIP_MONITOR;
2350
2351        ath10k_wmi_handle_wep_reauth(ar, skb, status);
2352
2353        if (ath10k_wmi_rx_is_decrypted(ar, hdr)) {
2354                status->flag |= RX_FLAG_DECRYPTED;
2355
2356                if (!ieee80211_is_action(hdr->frame_control) &&
2357                    !ieee80211_is_deauth(hdr->frame_control) &&
2358                    !ieee80211_is_disassoc(hdr->frame_control)) {
2359                        status->flag |= RX_FLAG_IV_STRIPPED |
2360                                        RX_FLAG_MMIC_STRIPPED;
2361                        hdr->frame_control = __cpu_to_le16(fc &
2362                                        ~IEEE80211_FCTL_PROTECTED);
2363                }
2364        }
2365
2366        if (ieee80211_is_beacon(hdr->frame_control))
2367                ath10k_mac_handle_beacon(ar, skb);
2368
2369        ath10k_dbg(ar, ATH10K_DBG_MGMT,
2370                   "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
2371                   skb, skb->len,
2372                   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
2373
2374        ath10k_dbg(ar, ATH10K_DBG_MGMT,
2375                   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
2376                   status->freq, status->band, status->signal,
2377                   status->rate_idx);
2378
2379        ieee80211_rx(ar->hw, skb);
2380        return 0;
2381}
2382
2383static int freq_to_idx(struct ath10k *ar, int freq)
2384{
2385        struct ieee80211_supported_band *sband;
2386        int band, ch, idx = 0;
2387
2388        for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
2389                sband = ar->hw->wiphy->bands[band];
2390                if (!sband)
2391                        continue;
2392
2393                for (ch = 0; ch < sband->n_channels; ch++, idx++)
2394                        if (sband->channels[ch].center_freq == freq)
2395                                goto exit;
2396        }
2397
2398exit:
2399        return idx;
2400}
2401
2402static int ath10k_wmi_op_pull_ch_info_ev(struct ath10k *ar, struct sk_buff *skb,
2403                                         struct wmi_ch_info_ev_arg *arg)
2404{
2405        struct wmi_chan_info_event *ev = (void *)skb->data;
2406
2407        if (skb->len < sizeof(*ev))
2408                return -EPROTO;
2409
2410        skb_pull(skb, sizeof(*ev));
2411        arg->err_code = ev->err_code;
2412        arg->freq = ev->freq;
2413        arg->cmd_flags = ev->cmd_flags;
2414        arg->noise_floor = ev->noise_floor;
2415        arg->rx_clear_count = ev->rx_clear_count;
2416        arg->cycle_count = ev->cycle_count;
2417
2418        return 0;
2419}
2420
2421static int ath10k_wmi_10_4_op_pull_ch_info_ev(struct ath10k *ar,
2422                                              struct sk_buff *skb,
2423                                              struct wmi_ch_info_ev_arg *arg)
2424{
2425        struct wmi_10_4_chan_info_event *ev = (void *)skb->data;
2426
2427        if (skb->len < sizeof(*ev))
2428                return -EPROTO;
2429
2430        skb_pull(skb, sizeof(*ev));
2431        arg->err_code = ev->err_code;
2432        arg->freq = ev->freq;
2433        arg->cmd_flags = ev->cmd_flags;
2434        arg->noise_floor = ev->noise_floor;
2435        arg->rx_clear_count = ev->rx_clear_count;
2436        arg->cycle_count = ev->cycle_count;
2437        arg->chan_tx_pwr_range = ev->chan_tx_pwr_range;
2438        arg->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
2439        arg->rx_frame_count = ev->rx_frame_count;
2440
2441        return 0;
2442}
2443
2444void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
2445{
2446        struct wmi_ch_info_ev_arg arg = {};
2447        struct survey_info *survey;
2448        u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
2449        int idx, ret;
2450
2451        ret = ath10k_wmi_pull_ch_info(ar, skb, &arg);
2452        if (ret) {
2453                ath10k_warn(ar, "failed to parse chan info event: %d\n", ret);
2454                return;
2455        }
2456
2457        err_code = __le32_to_cpu(arg.err_code);
2458        freq = __le32_to_cpu(arg.freq);
2459        cmd_flags = __le32_to_cpu(arg.cmd_flags);
2460        noise_floor = __le32_to_cpu(arg.noise_floor);
2461        rx_clear_count = __le32_to_cpu(arg.rx_clear_count);
2462        cycle_count = __le32_to_cpu(arg.cycle_count);
2463
2464        ath10k_dbg(ar, ATH10K_DBG_WMI,
2465                   "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
2466                   err_code, freq, cmd_flags, noise_floor, rx_clear_count,
2467                   cycle_count);
2468
2469        spin_lock_bh(&ar->data_lock);
2470
2471        switch (ar->scan.state) {
2472        case ATH10K_SCAN_IDLE:
2473        case ATH10K_SCAN_STARTING:
2474                ath10k_warn(ar, "received chan info event without a scan request, ignoring\n");
2475                goto exit;
2476        case ATH10K_SCAN_RUNNING:
2477        case ATH10K_SCAN_ABORTING:
2478                break;
2479        }
2480
2481        idx = freq_to_idx(ar, freq);
2482        if (idx >= ARRAY_SIZE(ar->survey)) {
2483                ath10k_warn(ar, "chan info: invalid frequency %d (idx %d out of bounds)\n",
2484                            freq, idx);
2485                goto exit;
2486        }
2487
2488        if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
2489                if (ar->ch_info_can_report_survey) {
2490                        survey = &ar->survey[idx];
2491                        survey->noise = noise_floor;
2492                        survey->filled = SURVEY_INFO_NOISE_DBM;
2493
2494                        ath10k_hw_fill_survey_time(ar,
2495                                                   survey,
2496                                                   cycle_count,
2497                                                   rx_clear_count,
2498                                                   ar->survey_last_cycle_count,
2499                                                   ar->survey_last_rx_clear_count);
2500                }
2501
2502                ar->ch_info_can_report_survey = false;
2503        } else {
2504                ar->ch_info_can_report_survey = true;
2505        }
2506
2507        if (!(cmd_flags & WMI_CHAN_INFO_FLAG_PRE_COMPLETE)) {
2508                ar->survey_last_rx_clear_count = rx_clear_count;
2509                ar->survey_last_cycle_count = cycle_count;
2510        }
2511
2512exit:
2513        spin_unlock_bh(&ar->data_lock);
2514}
2515
2516void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
2517{
2518        struct wmi_echo_ev_arg arg = {};
2519        int ret;
2520
2521        ret = ath10k_wmi_pull_echo_ev(ar, skb, &arg);
2522        if (ret) {
2523                ath10k_warn(ar, "failed to parse echo: %d\n", ret);
2524                return;
2525        }
2526
2527        ath10k_dbg(ar, ATH10K_DBG_WMI,
2528                   "wmi event echo value 0x%08x\n",
2529                   le32_to_cpu(arg.value));
2530
2531        if (le32_to_cpu(arg.value) == ATH10K_WMI_BARRIER_ECHO_ID)
2532                complete(&ar->wmi.barrier);
2533}
2534
2535int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
2536{
2537        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
2538                   skb->len);
2539
2540        trace_ath10k_wmi_dbglog(ar, skb->data, skb->len);
2541
2542        return 0;
2543}
2544
2545void ath10k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
2546                                     struct ath10k_fw_stats_pdev *dst)
2547{
2548        dst->ch_noise_floor = __le32_to_cpu(src->chan_nf);
2549        dst->tx_frame_count = __le32_to_cpu(src->tx_frame_count);
2550        dst->rx_frame_count = __le32_to_cpu(src->rx_frame_count);
2551        dst->rx_clear_count = __le32_to_cpu(src->rx_clear_count);
2552        dst->cycle_count = __le32_to_cpu(src->cycle_count);
2553        dst->phy_err_count = __le32_to_cpu(src->phy_err_count);
2554        dst->chan_tx_power = __le32_to_cpu(src->chan_tx_pwr);
2555}
2556
2557void ath10k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
2558                                   struct ath10k_fw_stats_pdev *dst)
2559{
2560        dst->comp_queued = __le32_to_cpu(src->comp_queued);
2561        dst->comp_delivered = __le32_to_cpu(src->comp_delivered);
2562        dst->msdu_enqued = __le32_to_cpu(src->msdu_enqued);
2563        dst->mpdu_enqued = __le32_to_cpu(src->mpdu_enqued);
2564        dst->wmm_drop = __le32_to_cpu(src->wmm_drop);
2565        dst->local_enqued = __le32_to_cpu(src->local_enqued);
2566        dst->local_freed = __le32_to_cpu(src->local_freed);
2567        dst->hw_queued = __le32_to_cpu(src->hw_queued);
2568        dst->hw_reaped = __le32_to_cpu(src->hw_reaped);
2569        dst->underrun = __le32_to_cpu(src->underrun);
2570        dst->tx_abort = __le32_to_cpu(src->tx_abort);
2571        dst->mpdus_requed = __le32_to_cpu(src->mpdus_requed);
2572        dst->tx_ko = __le32_to_cpu(src->tx_ko);
2573        dst->data_rc = __le32_to_cpu(src->data_rc);
2574        dst->self_triggers = __le32_to_cpu(src->self_triggers);
2575        dst->sw_retry_failure = __le32_to_cpu(src->sw_retry_failure);
2576        dst->illgl_rate_phy_err = __le32_to_cpu(src->illgl_rate_phy_err);
2577        dst->pdev_cont_xretry = __le32_to_cpu(src->pdev_cont_xretry);
2578        dst->pdev_tx_timeout = __le32_to_cpu(src->pdev_tx_timeout);
2579        dst->pdev_resets = __le32_to_cpu(src->pdev_resets);
2580        dst->phy_underrun = __le32_to_cpu(src->phy_underrun);
2581        dst->txop_ovf = __le32_to_cpu(src->txop_ovf);
2582}
2583
2584static void
2585ath10k_wmi_10_4_pull_pdev_stats_tx(const struct wmi_10_4_pdev_stats_tx *src,
2586                                   struct ath10k_fw_stats_pdev *dst)
2587{
2588        dst->comp_queued = __le32_to_cpu(src->comp_queued);
2589        dst->comp_delivered = __le32_to_cpu(src->comp_delivered);
2590        dst->msdu_enqued = __le32_to_cpu(src->msdu_enqued);
2591        dst->mpdu_enqued = __le32_to_cpu(src->mpdu_enqued);
2592        dst->wmm_drop = __le32_to_cpu(src->wmm_drop);
2593        dst->local_enqued = __le32_to_cpu(src->local_enqued);
2594        dst->local_freed = __le32_to_cpu(src->local_freed);
2595        dst->hw_queued = __le32_to_cpu(src->hw_queued);
2596        dst->hw_reaped = __le32_to_cpu(src->hw_reaped);
2597        dst->underrun = __le32_to_cpu(src->underrun);
2598        dst->tx_abort = __le32_to_cpu(src->tx_abort);
2599        dst->mpdus_requed = __le32_to_cpu(src->mpdus_requed);
2600        dst->tx_ko = __le32_to_cpu(src->tx_ko);
2601        dst->data_rc = __le32_to_cpu(src->data_rc);
2602        dst->self_triggers = __le32_to_cpu(src->self_triggers);
2603        dst->sw_retry_failure = __le32_to_cpu(src->sw_retry_failure);
2604        dst->illgl_rate_phy_err = __le32_to_cpu(src->illgl_rate_phy_err);
2605        dst->pdev_cont_xretry = __le32_to_cpu(src->pdev_cont_xretry);
2606        dst->pdev_tx_timeout = __le32_to_cpu(src->pdev_tx_timeout);
2607        dst->pdev_resets = __le32_to_cpu(src->pdev_resets);
2608        dst->phy_underrun = __le32_to_cpu(src->phy_underrun);
2609        dst->txop_ovf = __le32_to_cpu(src->txop_ovf);
2610        dst->hw_paused = __le32_to_cpu(src->hw_paused);
2611        dst->seq_posted = __le32_to_cpu(src->seq_posted);
2612        dst->seq_failed_queueing =
2613                __le32_to_cpu(src->seq_failed_queueing);
2614        dst->seq_completed = __le32_to_cpu(src->seq_completed);
2615        dst->seq_restarted = __le32_to_cpu(src->seq_restarted);
2616        dst->mu_seq_posted = __le32_to_cpu(src->mu_seq_posted);
2617        dst->mpdus_sw_flush = __le32_to_cpu(src->mpdus_sw_flush);
2618        dst->mpdus_hw_filter = __le32_to_cpu(src->mpdus_hw_filter);
2619        dst->mpdus_truncated = __le32_to_cpu(src->mpdus_truncated);
2620        dst->mpdus_ack_failed = __le32_to_cpu(src->mpdus_ack_failed);
2621        dst->mpdus_hw_filter = __le32_to_cpu(src->mpdus_hw_filter);
2622        dst->mpdus_expired = __le32_to_cpu(src->mpdus_expired);
2623}
2624
2625void ath10k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
2626                                   struct ath10k_fw_stats_pdev *dst)
2627{
2628        dst->mid_ppdu_route_change = __le32_to_cpu(src->mid_ppdu_route_change);
2629        dst->status_rcvd = __le32_to_cpu(src->status_rcvd);
2630        dst->r0_frags = __le32_to_cpu(src->r0_frags);
2631        dst->r1_frags = __le32_to_cpu(src->r1_frags);
2632        dst->r2_frags = __le32_to_cpu(src->r2_frags);
2633        dst->r3_frags = __le32_to_cpu(src->r3_frags);
2634        dst->htt_msdus = __le32_to_cpu(src->htt_msdus);
2635        dst->htt_mpdus = __le32_to_cpu(src->htt_mpdus);
2636        dst->loc_msdus = __le32_to_cpu(src->loc_msdus);
2637        dst->loc_mpdus = __le32_to_cpu(src->loc_mpdus);
2638        dst->oversize_amsdu = __le32_to_cpu(src->oversize_amsdu);
2639        dst->phy_errs = __le32_to_cpu(src->phy_errs);
2640        dst->phy_err_drop = __le32_to_cpu(src->phy_err_drop);
2641        dst->mpdu_errs = __le32_to_cpu(src->mpdu_errs);
2642}
2643
2644void ath10k_wmi_pull_pdev_stats_extra(const struct wmi_pdev_stats_extra *src,
2645                                      struct ath10k_fw_stats_pdev *dst)
2646{
2647        dst->ack_rx_bad = __le32_to_cpu(src->ack_rx_bad);
2648        dst->rts_bad = __le32_to_cpu(src->rts_bad);
2649        dst->rts_good = __le32_to_cpu(src->rts_good);
2650        dst->fcs_bad = __le32_to_cpu(src->fcs_bad);
2651        dst->no_beacons = __le32_to_cpu(src->no_beacons);
2652        dst->mib_int_count = __le32_to_cpu(src->mib_int_count);
2653}
2654
2655void ath10k_wmi_pull_peer_stats(const struct wmi_peer_stats *src,
2656                                struct ath10k_fw_stats_peer *dst)
2657{
2658        ether_addr_copy(dst->peer_macaddr, src->peer_macaddr.addr);
2659        dst->peer_rssi = __le32_to_cpu(src->peer_rssi);
2660        dst->peer_tx_rate = __le32_to_cpu(src->peer_tx_rate);
2661}
2662
2663static void
2664ath10k_wmi_10_4_pull_peer_stats(const struct wmi_10_4_peer_stats *src,
2665                                struct ath10k_fw_stats_peer *dst)
2666{
2667        ether_addr_copy(dst->peer_macaddr, src->peer_macaddr.addr);
2668        dst->peer_rssi = __le32_to_cpu(src->peer_rssi);
2669        dst->peer_tx_rate = __le32_to_cpu(src->peer_tx_rate);
2670        dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
2671}
2672
2673static int ath10k_wmi_main_op_pull_fw_stats(struct ath10k *ar,
2674                                            struct sk_buff *skb,
2675                                            struct ath10k_fw_stats *stats)
2676{
2677        const struct wmi_stats_event *ev = (void *)skb->data;
2678        u32 num_pdev_stats, num_vdev_stats, num_peer_stats;
2679        int i;
2680
2681        if (!skb_pull(skb, sizeof(*ev)))
2682                return -EPROTO;
2683
2684        num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
2685        num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
2686        num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
2687
2688        for (i = 0; i < num_pdev_stats; i++) {
2689                const struct wmi_pdev_stats *src;
2690                struct ath10k_fw_stats_pdev *dst;
2691
2692                src = (void *)skb->data;
2693                if (!skb_pull(skb, sizeof(*src)))
2694                        return -EPROTO;
2695
2696                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2697                if (!dst)
2698                        continue;
2699
2700                ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
2701                ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
2702                ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
2703
2704                list_add_tail(&dst->list, &stats->pdevs);
2705        }
2706
2707        /* fw doesn't implement vdev stats */
2708
2709        for (i = 0; i < num_peer_stats; i++) {
2710                const struct wmi_peer_stats *src;
2711                struct ath10k_fw_stats_peer *dst;
2712
2713                src = (void *)skb->data;
2714                if (!skb_pull(skb, sizeof(*src)))
2715                        return -EPROTO;
2716
2717                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2718                if (!dst)
2719                        continue;
2720
2721                ath10k_wmi_pull_peer_stats(src, dst);
2722                list_add_tail(&dst->list, &stats->peers);
2723        }
2724
2725        return 0;
2726}
2727
2728static int ath10k_wmi_10x_op_pull_fw_stats(struct ath10k *ar,
2729                                           struct sk_buff *skb,
2730                                           struct ath10k_fw_stats *stats)
2731{
2732        const struct wmi_stats_event *ev = (void *)skb->data;
2733        u32 num_pdev_stats, num_vdev_stats, num_peer_stats;
2734        int i;
2735
2736        if (!skb_pull(skb, sizeof(*ev)))
2737                return -EPROTO;
2738
2739        num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
2740        num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
2741        num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
2742
2743        for (i = 0; i < num_pdev_stats; i++) {
2744                const struct wmi_10x_pdev_stats *src;
2745                struct ath10k_fw_stats_pdev *dst;
2746
2747                src = (void *)skb->data;
2748                if (!skb_pull(skb, sizeof(*src)))
2749                        return -EPROTO;
2750
2751                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2752                if (!dst)
2753                        continue;
2754
2755                ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
2756                ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
2757                ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
2758                ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
2759
2760                list_add_tail(&dst->list, &stats->pdevs);
2761        }
2762
2763        /* fw doesn't implement vdev stats */
2764
2765        for (i = 0; i < num_peer_stats; i++) {
2766                const struct wmi_10x_peer_stats *src;
2767                struct ath10k_fw_stats_peer *dst;
2768
2769                src = (void *)skb->data;
2770                if (!skb_pull(skb, sizeof(*src)))
2771                        return -EPROTO;
2772
2773                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2774                if (!dst)
2775                        continue;
2776
2777                ath10k_wmi_pull_peer_stats(&src->old, dst);
2778
2779                dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
2780
2781                list_add_tail(&dst->list, &stats->peers);
2782        }
2783
2784        return 0;
2785}
2786
2787static int ath10k_wmi_10_2_op_pull_fw_stats(struct ath10k *ar,
2788                                            struct sk_buff *skb,
2789                                            struct ath10k_fw_stats *stats)
2790{
2791        const struct wmi_10_2_stats_event *ev = (void *)skb->data;
2792        u32 num_pdev_stats;
2793        u32 num_pdev_ext_stats;
2794        u32 num_vdev_stats;
2795        u32 num_peer_stats;
2796        int i;
2797
2798        if (!skb_pull(skb, sizeof(*ev)))
2799                return -EPROTO;
2800
2801        num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
2802        num_pdev_ext_stats = __le32_to_cpu(ev->num_pdev_ext_stats);
2803        num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
2804        num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
2805
2806        for (i = 0; i < num_pdev_stats; i++) {
2807                const struct wmi_10_2_pdev_stats *src;
2808                struct ath10k_fw_stats_pdev *dst;
2809
2810                src = (void *)skb->data;
2811                if (!skb_pull(skb, sizeof(*src)))
2812                        return -EPROTO;
2813
2814                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2815                if (!dst)
2816                        continue;
2817
2818                ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
2819                ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
2820                ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
2821                ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
2822                /* FIXME: expose 10.2 specific values */
2823
2824                list_add_tail(&dst->list, &stats->pdevs);
2825        }
2826
2827        for (i = 0; i < num_pdev_ext_stats; i++) {
2828                const struct wmi_10_2_pdev_ext_stats *src;
2829
2830                src = (void *)skb->data;
2831                if (!skb_pull(skb, sizeof(*src)))
2832                        return -EPROTO;
2833
2834                /* FIXME: expose values to userspace
2835                 *
2836                 * Note: Even though this loop seems to do nothing it is
2837                 * required to parse following sub-structures properly.
2838                 */
2839        }
2840
2841        /* fw doesn't implement vdev stats */
2842
2843        for (i = 0; i < num_peer_stats; i++) {
2844                const struct wmi_10_2_peer_stats *src;
2845                struct ath10k_fw_stats_peer *dst;
2846
2847                src = (void *)skb->data;
2848                if (!skb_pull(skb, sizeof(*src)))
2849                        return -EPROTO;
2850
2851                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2852                if (!dst)
2853                        continue;
2854
2855                ath10k_wmi_pull_peer_stats(&src->old, dst);
2856
2857                dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
2858                /* FIXME: expose 10.2 specific values */
2859
2860                list_add_tail(&dst->list, &stats->peers);
2861        }
2862
2863        return 0;
2864}
2865
2866static int ath10k_wmi_10_2_4_op_pull_fw_stats(struct ath10k *ar,
2867                                              struct sk_buff *skb,
2868                                              struct ath10k_fw_stats *stats)
2869{
2870        const struct wmi_10_2_stats_event *ev = (void *)skb->data;
2871        u32 num_pdev_stats;
2872        u32 num_pdev_ext_stats;
2873        u32 num_vdev_stats;
2874        u32 num_peer_stats;
2875        int i;
2876
2877        if (!skb_pull(skb, sizeof(*ev)))
2878                return -EPROTO;
2879
2880        num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
2881        num_pdev_ext_stats = __le32_to_cpu(ev->num_pdev_ext_stats);
2882        num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
2883        num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
2884
2885        for (i = 0; i < num_pdev_stats; i++) {
2886                const struct wmi_10_2_pdev_stats *src;
2887                struct ath10k_fw_stats_pdev *dst;
2888
2889                src = (void *)skb->data;
2890                if (!skb_pull(skb, sizeof(*src)))
2891                        return -EPROTO;
2892
2893                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2894                if (!dst)
2895                        continue;
2896
2897                ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
2898                ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
2899                ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
2900                ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
2901                /* FIXME: expose 10.2 specific values */
2902
2903                list_add_tail(&dst->list, &stats->pdevs);
2904        }
2905
2906        for (i = 0; i < num_pdev_ext_stats; i++) {
2907                const struct wmi_10_2_pdev_ext_stats *src;
2908
2909                src = (void *)skb->data;
2910                if (!skb_pull(skb, sizeof(*src)))
2911                        return -EPROTO;
2912
2913                /* FIXME: expose values to userspace
2914                 *
2915                 * Note: Even though this loop seems to do nothing it is
2916                 * required to parse following sub-structures properly.
2917                 */
2918        }
2919
2920        /* fw doesn't implement vdev stats */
2921
2922        for (i = 0; i < num_peer_stats; i++) {
2923                const struct wmi_10_2_4_ext_peer_stats *src;
2924                struct ath10k_fw_stats_peer *dst;
2925                int stats_len;
2926
2927                if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
2928                        stats_len = sizeof(struct wmi_10_2_4_ext_peer_stats);
2929                else
2930                        stats_len = sizeof(struct wmi_10_2_4_peer_stats);
2931
2932                src = (void *)skb->data;
2933                if (!skb_pull(skb, stats_len))
2934                        return -EPROTO;
2935
2936                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2937                if (!dst)
2938                        continue;
2939
2940                ath10k_wmi_pull_peer_stats(&src->common.old, dst);
2941
2942                dst->peer_rx_rate = __le32_to_cpu(src->common.peer_rx_rate);
2943
2944                if (ath10k_peer_stats_enabled(ar))
2945                        dst->rx_duration = __le32_to_cpu(src->rx_duration);
2946                /* FIXME: expose 10.2 specific values */
2947
2948                list_add_tail(&dst->list, &stats->peers);
2949        }
2950
2951        return 0;
2952}
2953
2954static int ath10k_wmi_10_4_op_pull_fw_stats(struct ath10k *ar,
2955                                            struct sk_buff *skb,
2956                                            struct ath10k_fw_stats *stats)
2957{
2958        const struct wmi_10_2_stats_event *ev = (void *)skb->data;
2959        u32 num_pdev_stats;
2960        u32 num_pdev_ext_stats;
2961        u32 num_vdev_stats;
2962        u32 num_peer_stats;
2963        u32 num_bcnflt_stats;
2964        u32 stats_id;
2965        int i;
2966
2967        if (!skb_pull(skb, sizeof(*ev)))
2968                return -EPROTO;
2969
2970        num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
2971        num_pdev_ext_stats = __le32_to_cpu(ev->num_pdev_ext_stats);
2972        num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
2973        num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
2974        num_bcnflt_stats = __le32_to_cpu(ev->num_bcnflt_stats);
2975        stats_id = __le32_to_cpu(ev->stats_id);
2976
2977        for (i = 0; i < num_pdev_stats; i++) {
2978                const struct wmi_10_4_pdev_stats *src;
2979                struct ath10k_fw_stats_pdev *dst;
2980
2981                src = (void *)skb->data;
2982                if (!skb_pull(skb, sizeof(*src)))
2983                        return -EPROTO;
2984
2985                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2986                if (!dst)
2987                        continue;
2988
2989                ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
2990                ath10k_wmi_10_4_pull_pdev_stats_tx(&src->tx, dst);
2991                ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
2992                dst->rx_ovfl_errs = __le32_to_cpu(src->rx_ovfl_errs);
2993                ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
2994
2995                list_add_tail(&dst->list, &stats->pdevs);
2996        }
2997
2998        for (i = 0; i < num_pdev_ext_stats; i++) {
2999                const struct wmi_10_2_pdev_ext_stats *src;
3000
3001                src = (void *)skb->data;
3002                if (!skb_pull(skb, sizeof(*src)))
3003                        return -EPROTO;
3004
3005                /* FIXME: expose values to userspace
3006                 *
3007                 * Note: Even though this loop seems to do nothing it is
3008                 * required to parse following sub-structures properly.
3009                 */
3010        }
3011
3012        /* fw doesn't implement vdev stats */
3013
3014        for (i = 0; i < num_peer_stats; i++) {
3015                const struct wmi_10_4_peer_stats *src;
3016                struct ath10k_fw_stats_peer *dst;
3017
3018                src = (void *)skb->data;
3019                if (!skb_pull(skb, sizeof(*src)))
3020                        return -EPROTO;
3021
3022                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3023                if (!dst)
3024                        continue;
3025
3026                ath10k_wmi_10_4_pull_peer_stats(src, dst);
3027                list_add_tail(&dst->list, &stats->peers);
3028        }
3029
3030        for (i = 0; i < num_bcnflt_stats; i++) {
3031                const struct wmi_10_4_bss_bcn_filter_stats *src;
3032
3033                src = (void *)skb->data;
3034                if (!skb_pull(skb, sizeof(*src)))
3035                        return -EPROTO;
3036
3037                /* FIXME: expose values to userspace
3038                 *
3039                 * Note: Even though this loop seems to do nothing it is
3040                 * required to parse following sub-structures properly.
3041                 */
3042        }
3043
3044        if ((stats_id & WMI_10_4_STAT_PEER_EXTD) == 0)
3045                return 0;
3046
3047        stats->extended = true;
3048
3049        for (i = 0; i < num_peer_stats; i++) {
3050                const struct wmi_10_4_peer_extd_stats *src;
3051                struct ath10k_fw_extd_stats_peer *dst;
3052
3053                src = (void *)skb->data;
3054                if (!skb_pull(skb, sizeof(*src)))
3055                        return -EPROTO;
3056
3057                dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3058                if (!dst)
3059                        continue;
3060
3061                ether_addr_copy(dst->peer_macaddr, src->peer_macaddr.addr);
3062                dst->rx_duration = __le32_to_cpu(src->rx_duration);
3063                list_add_tail(&dst->list, &stats->peers_extd);
3064        }
3065
3066        return 0;
3067}
3068
3069void ath10k_wmi_event_update_stats(struct ath10k *ar, struct sk_buff *skb)
3070{
3071        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
3072        ath10k_debug_fw_stats_process(ar, skb);
3073}
3074
3075static int
3076ath10k_wmi_op_pull_vdev_start_ev(struct ath10k *ar, struct sk_buff *skb,
3077                                 struct wmi_vdev_start_ev_arg *arg)
3078{
3079        struct wmi_vdev_start_response_event *ev = (void *)skb->data;
3080
3081        if (skb->len < sizeof(*ev))
3082                return -EPROTO;
3083
3084        skb_pull(skb, sizeof(*ev));
3085        arg->vdev_id = ev->vdev_id;
3086        arg->req_id = ev->req_id;
3087        arg->resp_type = ev->resp_type;
3088        arg->status = ev->status;
3089
3090        return 0;
3091}
3092
3093void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar, struct sk_buff *skb)
3094{
3095        struct wmi_vdev_start_ev_arg arg = {};
3096        int ret;
3097
3098        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
3099
3100        ret = ath10k_wmi_pull_vdev_start(ar, skb, &arg);
3101        if (ret) {
3102                ath10k_warn(ar, "failed to parse vdev start event: %d\n", ret);
3103                return;
3104        }
3105
3106        if (WARN_ON(__le32_to_cpu(arg.status)))
3107                return;
3108
3109        complete(&ar->vdev_setup_done);
3110}
3111
3112void ath10k_wmi_event_vdev_stopped(struct ath10k *ar, struct sk_buff *skb)
3113{
3114        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
3115        complete(&ar->vdev_setup_done);
3116}
3117
3118static int
3119ath10k_wmi_op_pull_peer_kick_ev(struct ath10k *ar, struct sk_buff *skb,
3120                                struct wmi_peer_kick_ev_arg *arg)
3121{
3122        struct wmi_peer_sta_kickout_event *ev = (void *)skb->data;
3123
3124        if (skb->len < sizeof(*ev))
3125                return -EPROTO;
3126
3127        skb_pull(skb, sizeof(*ev));
3128        arg->mac_addr = ev->peer_macaddr.addr;
3129
3130        return 0;
3131}
3132
3133void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar, struct sk_buff *skb)
3134{
3135        struct wmi_peer_kick_ev_arg arg = {};
3136        struct ieee80211_sta *sta;
3137        int ret;
3138
3139        ret = ath10k_wmi_pull_peer_kick(ar, skb, &arg);
3140        if (ret) {
3141                ath10k_warn(ar, "failed to parse peer kickout event: %d\n",
3142                            ret);
3143                return;
3144        }
3145
3146        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
3147                   arg.mac_addr);
3148
3149        rcu_read_lock();
3150
3151        sta = ieee80211_find_sta_by_ifaddr(ar->hw, arg.mac_addr, NULL);
3152        if (!sta) {
3153                ath10k_warn(ar, "Spurious quick kickout for STA %pM\n",
3154                            arg.mac_addr);
3155                goto exit;
3156        }
3157
3158        ieee80211_report_low_ack(sta, 10);
3159
3160exit:
3161        rcu_read_unlock();
3162}
3163
3164/*
3165 * FIXME
3166 *
3167 * We don't report to mac80211 sleep state of connected
3168 * stations. Due to this mac80211 can't fill in TIM IE
3169 * correctly.
3170 *
3171 * I know of no way of getting nullfunc frames that contain
3172 * sleep transition from connected stations - these do not
3173 * seem to be sent from the target to the host. There also
3174 * doesn't seem to be a dedicated event for that. So the
3175 * only way left to do this would be to read tim_bitmap
3176 * during SWBA.
3177 *
3178 * We could probably try using tim_bitmap from SWBA to tell
3179 * mac80211 which stations are asleep and which are not. The
3180 * problem here is calling mac80211 functions so many times
3181 * could take too long and make us miss the time to submit
3182 * the beacon to the target.
3183 *
3184 * So as a workaround we try to extend the TIM IE if there
3185 * is unicast buffered for stations with aid > 7 and fill it
3186 * in ourselves.
3187 */
3188static void ath10k_wmi_update_tim(struct ath10k *ar,
3189                                  struct ath10k_vif *arvif,
3190                                  struct sk_buff *bcn,
3191                                  const struct wmi_tim_info_arg *tim_info)
3192{
3193        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
3194        struct ieee80211_tim_ie *tim;
3195        u8 *ies, *ie;
3196        u8 ie_len, pvm_len;
3197        __le32 t;
3198        u32 v, tim_len;
3199
3200        /* When FW reports 0 in tim_len, ensure atleast first byte
3201         * in tim_bitmap is considered for pvm calculation.
3202         */
3203        tim_len = tim_info->tim_len ? __le32_to_cpu(tim_info->tim_len) : 1;
3204
3205        /* if next SWBA has no tim_changed the tim_bitmap is garbage.
3206         * we must copy the bitmap upon change and reuse it later */
3207        if (__le32_to_cpu(tim_info->tim_changed)) {
3208                int i;
3209
3210                if (sizeof(arvif->u.ap.tim_bitmap) < tim_len) {
3211                        ath10k_warn(ar, "SWBA TIM field is too big (%u), truncated it to %zu",
3212                                    tim_len, sizeof(arvif->u.ap.tim_bitmap));
3213                        tim_len = sizeof(arvif->u.ap.tim_bitmap);
3214                }
3215
3216                for (i = 0; i < tim_len; i++) {
3217                        t = tim_info->tim_bitmap[i / 4];
3218                        v = __le32_to_cpu(t);
3219                        arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
3220                }
3221
3222                /* FW reports either length 0 or length based on max supported
3223                 * station. so we calculate this on our own
3224                 */
3225                arvif->u.ap.tim_len = 0;
3226                for (i = 0; i < tim_len; i++)
3227                        if (arvif->u.ap.tim_bitmap[i])
3228                                arvif->u.ap.tim_len = i;
3229
3230                arvif->u.ap.tim_len++;
3231        }
3232
3233        ies = bcn->data;
3234        ies += ieee80211_hdrlen(hdr->frame_control);
3235        ies += 12; /* fixed parameters */
3236
3237        ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
3238                                    (u8 *)skb_tail_pointer(bcn) - ies);
3239        if (!ie) {
3240                if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3241                        ath10k_warn(ar, "no tim ie found;\n");
3242                return;
3243        }
3244
3245        tim = (void *)ie + 2;
3246        ie_len = ie[1];
3247        pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
3248
3249        if (pvm_len < arvif->u.ap.tim_len) {
3250                int expand_size = tim_len - pvm_len;
3251                int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
3252                void *next_ie = ie + 2 + ie_len;
3253
3254                if (skb_put(bcn, expand_size)) {
3255                        memmove(next_ie + expand_size, next_ie, move_size);
3256
3257                        ie[1] += expand_size;
3258                        ie_len += expand_size;
3259                        pvm_len += expand_size;
3260                } else {
3261                        ath10k_warn(ar, "tim expansion failed\n");
3262                }
3263        }
3264
3265        if (pvm_len > tim_len) {
3266                ath10k_warn(ar, "tim pvm length is too great (%d)\n", pvm_len);
3267                return;
3268        }
3269
3270        tim->bitmap_ctrl = !!__le32_to_cpu(tim_info->tim_mcast);
3271        memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
3272
3273        if (tim->dtim_count == 0) {
3274                ATH10K_SKB_CB(bcn)->flags |= ATH10K_SKB_F_DTIM_ZERO;
3275
3276                if (__le32_to_cpu(tim_info->tim_mcast) == 1)
3277                        ATH10K_SKB_CB(bcn)->flags |= ATH10K_SKB_F_DELIVER_CAB;
3278        }
3279
3280        ath10k_dbg(ar, ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
3281                   tim->dtim_count, tim->dtim_period,
3282                   tim->bitmap_ctrl, pvm_len);
3283}
3284
3285static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
3286                                  struct sk_buff *bcn,
3287                                  const struct wmi_p2p_noa_info *noa)
3288{
3289        if (!arvif->vif->p2p)
3290                return;
3291
3292        ath10k_dbg(ar, ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
3293
3294        if (noa->changed & WMI_P2P_NOA_CHANGED_BIT)
3295                ath10k_p2p_noa_update(arvif, noa);
3296
3297        if (arvif->u.ap.noa_data)
3298                if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
3299                        memcpy(skb_put(bcn, arvif->u.ap.noa_len),
3300                               arvif->u.ap.noa_data,
3301                               arvif->u.ap.noa_len);
3302}
3303
3304static int ath10k_wmi_op_pull_swba_ev(struct ath10k *ar, struct sk_buff *skb,
3305                                      struct wmi_swba_ev_arg *arg)
3306{
3307        struct wmi_host_swba_event *ev = (void *)skb->data;
3308        u32 map;
3309        size_t i;
3310
3311        if (skb->len < sizeof(*ev))
3312                return -EPROTO;
3313
3314        skb_pull(skb, sizeof(*ev));
3315        arg->vdev_map = ev->vdev_map;
3316
3317        for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3318                if (!(map & BIT(0)))
3319                        continue;
3320
3321                /* If this happens there were some changes in firmware and
3322                 * ath10k should update the max size of tim_info array.
3323                 */
3324                if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3325                        break;
3326
3327                if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3328                     sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3329                        ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3330                        return -EPROTO;
3331                }
3332
3333                arg->tim_info[i].tim_len = ev->bcn_info[i].tim_info.tim_len;
3334                arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3335                arg->tim_info[i].tim_bitmap =
3336                                ev->bcn_info[i].tim_info.tim_bitmap;
3337                arg->tim_info[i].tim_changed =
3338                                ev->bcn_info[i].tim_info.tim_changed;
3339                arg->tim_info[i].tim_num_ps_pending =
3340                                ev->bcn_info[i].tim_info.tim_num_ps_pending;
3341
3342                arg->noa_info[i] = &ev->bcn_info[i].p2p_noa_info;
3343                i++;
3344        }
3345
3346        return 0;
3347}
3348
3349static int ath10k_wmi_10_2_4_op_pull_swba_ev(struct ath10k *ar,
3350                                             struct sk_buff *skb,
3351                                             struct wmi_swba_ev_arg *arg)
3352{
3353        struct wmi_10_2_4_host_swba_event *ev = (void *)skb->data;
3354        u32 map;
3355        size_t i;
3356
3357        if (skb->len < sizeof(*ev))
3358                return -EPROTO;
3359
3360        skb_pull(skb, sizeof(*ev));
3361        arg->vdev_map = ev->vdev_map;
3362
3363        for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3364                if (!(map & BIT(0)))
3365                        continue;
3366
3367                /* If this happens there were some changes in firmware and
3368                 * ath10k should update the max size of tim_info array.
3369                 */
3370                if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3371                        break;
3372
3373                if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3374                     sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3375                        ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3376                        return -EPROTO;
3377                }
3378
3379                arg->tim_info[i].tim_len = ev->bcn_info[i].tim_info.tim_len;
3380                arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3381                arg->tim_info[i].tim_bitmap =
3382                                ev->bcn_info[i].tim_info.tim_bitmap;
3383                arg->tim_info[i].tim_changed =
3384                                ev->bcn_info[i].tim_info.tim_changed;
3385                arg->tim_info[i].tim_num_ps_pending =
3386                                ev->bcn_info[i].tim_info.tim_num_ps_pending;
3387                i++;
3388        }
3389
3390        return 0;
3391}
3392
3393static int ath10k_wmi_10_4_op_pull_swba_ev(struct ath10k *ar,
3394                                           struct sk_buff *skb,
3395                                           struct wmi_swba_ev_arg *arg)
3396{
3397        struct wmi_10_4_host_swba_event *ev = (void *)skb->data;
3398        u32 map, tim_len;
3399        size_t i;
3400
3401        if (skb->len < sizeof(*ev))
3402                return -EPROTO;
3403
3404        skb_pull(skb, sizeof(*ev));
3405        arg->vdev_map = ev->vdev_map;
3406
3407        for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3408                if (!(map & BIT(0)))
3409                        continue;
3410
3411                /* If this happens there were some changes in firmware and
3412                 * ath10k should update the max size of tim_info array.
3413                 */
3414                if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3415                        break;
3416
3417                if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3418                      sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3419                        ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3420                        return -EPROTO;
3421                }
3422
3423                tim_len = __le32_to_cpu(ev->bcn_info[i].tim_info.tim_len);
3424                if (tim_len) {
3425                        /* Exclude 4 byte guard length */
3426                        tim_len -= 4;
3427                        arg->tim_info[i].tim_len = __cpu_to_le32(tim_len);
3428                } else {
3429                        arg->tim_info[i].tim_len = 0;
3430                }
3431
3432                arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3433                arg->tim_info[i].tim_bitmap =
3434                                ev->bcn_info[i].tim_info.tim_bitmap;
3435                arg->tim_info[i].tim_changed =
3436                                ev->bcn_info[i].tim_info.tim_changed;
3437                arg->tim_info[i].tim_num_ps_pending =
3438                                ev->bcn_info[i].tim_info.tim_num_ps_pending;
3439
3440                /* 10.4 firmware doesn't have p2p support. notice of absence
3441                 * info can be ignored for now.
3442                 */
3443
3444                i++;
3445        }
3446
3447        return 0;
3448}
3449
3450static enum wmi_txbf_conf ath10k_wmi_10_4_txbf_conf_scheme(struct ath10k *ar)
3451{
3452        return WMI_TXBF_CONF_BEFORE_ASSOC;
3453}
3454
3455void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
3456{
3457        struct wmi_swba_ev_arg arg = {};
3458        u32 map;
3459        int i = -1;
3460        const struct wmi_tim_info_arg *tim_info;
3461        const struct wmi_p2p_noa_info *noa_info;
3462        struct ath10k_vif *arvif;
3463        struct sk_buff *bcn;
3464        dma_addr_t paddr;
3465        int ret, vdev_id = 0;
3466
3467        ret = ath10k_wmi_pull_swba(ar, skb, &arg);
3468        if (ret) {
3469                ath10k_warn(ar, "failed to parse swba event: %d\n", ret);
3470                return;
3471        }
3472
3473        map = __le32_to_cpu(arg.vdev_map);
3474
3475        ath10k_dbg(ar, ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
3476                   map);
3477
3478        for (; map; map >>= 1, vdev_id++) {
3479                if (!(map & 0x1))
3480                        continue;
3481
3482                i++;
3483
3484                if (i >= WMI_MAX_AP_VDEV) {
3485                        ath10k_warn(ar, "swba has corrupted vdev map\n");
3486                        break;
3487                }
3488
3489                tim_info = &arg.tim_info[i];
3490                noa_info = arg.noa_info[i];
3491
3492                ath10k_dbg(ar, ATH10K_DBG_MGMT,
3493                           "mgmt event bcn_info %d tim_len %d mcast %d changed %d num_ps_pending %d bitmap 0x%08x%08x%08x%08x\n",
3494                           i,
3495                           __le32_to_cpu(tim_info->tim_len),
3496                           __le32_to_cpu(tim_info->tim_mcast),
3497                           __le32_to_cpu(tim_info->tim_changed),
3498                           __le32_to_cpu(tim_info->tim_num_ps_pending),
3499                           __le32_to_cpu(tim_info->tim_bitmap[3]),
3500                           __le32_to_cpu(tim_info->tim_bitmap[2]),
3501                           __le32_to_cpu(tim_info->tim_bitmap[1]),
3502                           __le32_to_cpu(tim_info->tim_bitmap[0]));
3503
3504                /* TODO: Only first 4 word from tim_bitmap is dumped.
3505                 * Extend debug code to dump full tim_bitmap.
3506                 */
3507
3508                arvif = ath10k_get_arvif(ar, vdev_id);
3509                if (arvif == NULL) {
3510                        ath10k_warn(ar, "no vif for vdev_id %d found\n",
3511                                    vdev_id);
3512                        continue;
3513                }
3514
3515                /* mac80211 would have already asked us to stop beaconing and
3516                 * bring the vdev down, so continue in that case
3517                 */
3518                if (!arvif->is_up)
3519                        continue;
3520
3521                /* There are no completions for beacons so wait for next SWBA
3522                 * before telling mac80211 to decrement CSA counter
3523                 *
3524                 * Once CSA counter is completed stop sending beacons until
3525                 * actual channel switch is done */
3526                if (arvif->vif->csa_active &&
3527                    ieee80211_csa_is_complete(arvif->vif)) {
3528                        ieee80211_csa_finish(arvif->vif);
3529                        continue;
3530                }
3531
3532                bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
3533                if (!bcn) {
3534                        ath10k_warn(ar, "could not get mac80211 beacon\n");
3535                        continue;
3536                }
3537
3538                ath10k_tx_h_seq_no(arvif->vif, bcn);
3539                ath10k_wmi_update_tim(ar, arvif, bcn, tim_info);
3540                ath10k_wmi_update_noa(ar, arvif, bcn, noa_info);
3541
3542                spin_lock_bh(&ar->data_lock);
3543
3544                if (arvif->beacon) {
3545                        switch (arvif->beacon_state) {
3546                        case ATH10K_BEACON_SENT:
3547                                break;
3548                        case ATH10K_BEACON_SCHEDULED:
3549                                ath10k_warn(ar, "SWBA overrun on vdev %d, skipped old beacon\n",
3550                                            arvif->vdev_id);
3551                                break;
3552                        case ATH10K_BEACON_SENDING:
3553                                ath10k_warn(ar, "SWBA overrun on vdev %d, skipped new beacon\n",
3554                                            arvif->vdev_id);
3555                                dev_kfree_skb(bcn);
3556                                goto skip;
3557                        }
3558
3559                        ath10k_mac_vif_beacon_free(arvif);
3560                }
3561
3562                if (!arvif->beacon_buf) {
3563                        paddr = dma_map_single(arvif->ar->dev, bcn->data,
3564                                               bcn->len, DMA_TO_DEVICE);
3565                        ret = dma_mapping_error(arvif->ar->dev, paddr);
3566                        if (ret) {
3567                                ath10k_warn(ar, "failed to map beacon: %d\n",
3568                                            ret);
3569                                dev_kfree_skb_any(bcn);
3570                                goto skip;
3571                        }
3572
3573                        ATH10K_SKB_CB(bcn)->paddr = paddr;
3574                } else {
3575                        if (bcn->len > IEEE80211_MAX_FRAME_LEN) {
3576                                ath10k_warn(ar, "trimming beacon %d -> %d bytes!\n",
3577                                            bcn->len, IEEE80211_MAX_FRAME_LEN);
3578                                skb_trim(bcn, IEEE80211_MAX_FRAME_LEN);
3579                        }
3580                        memcpy(arvif->beacon_buf, bcn->data, bcn->len);
3581                        ATH10K_SKB_CB(bcn)->paddr = arvif->beacon_paddr;
3582                }
3583
3584                arvif->beacon = bcn;
3585                arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
3586
3587                trace_ath10k_tx_hdr(ar, bcn->data, bcn->len);
3588                trace_ath10k_tx_payload(ar, bcn->data, bcn->len);
3589
3590skip:
3591                spin_unlock_bh(&ar->data_lock);
3592        }
3593
3594        ath10k_wmi_tx_beacons_nowait(ar);
3595}
3596
3597void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar, struct sk_buff *skb)
3598{
3599        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
3600}
3601
3602static void ath10k_dfs_radar_report(struct ath10k *ar,
3603                                    struct wmi_phyerr_ev_arg *phyerr,
3604                                    const struct phyerr_radar_report *rr,
3605                                    u64 tsf)
3606{
3607        u32 reg0, reg1, tsf32l;
3608        struct ieee80211_channel *ch;
3609        struct pulse_event pe;
3610        u64 tsf64;
3611        u8 rssi, width;
3612
3613        reg0 = __le32_to_cpu(rr->reg0);
3614        reg1 = __le32_to_cpu(rr->reg1);
3615
3616        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3617                   "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
3618                   MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
3619                   MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
3620                   MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
3621                   MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
3622        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3623                   "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
3624                   MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
3625                   MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
3626                   MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
3627                   MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
3628                   MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
3629        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3630                   "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
3631                   MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
3632                   MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
3633
3634        if (!ar->dfs_detector)
3635                return;
3636
3637        spin_lock_bh(&ar->data_lock);
3638        ch = ar->rx_channel;
3639        spin_unlock_bh(&ar->data_lock);
3640
3641        if (!ch) {
3642                ath10k_warn(ar, "failed to derive channel for radar pulse, treating as radar\n");
3643                goto radar_detected;
3644        }
3645
3646        /* report event to DFS pattern detector */
3647        tsf32l = phyerr->tsf_timestamp;
3648        tsf64 = tsf & (~0xFFFFFFFFULL);
3649        tsf64 |= tsf32l;
3650
3651        width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
3652        rssi = phyerr->rssi_combined;
3653
3654        /* hardware store this as 8 bit signed value,
3655         * set to zero if negative number
3656         */
3657        if (rssi & 0x80)
3658                rssi = 0;
3659
3660        pe.ts = tsf64;
3661        pe.freq = ch->center_freq;
3662        pe.width = width;
3663        pe.rssi = rssi;
3664        pe.chirp = (MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP) != 0);
3665        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3666                   "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
3667                   pe.freq, pe.width, pe.rssi, pe.ts);
3668
3669        ATH10K_DFS_STAT_INC(ar, pulses_detected);
3670
3671        if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
3672                ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3673                           "dfs no pulse pattern detected, yet\n");
3674                return;
3675        }
3676
3677radar_detected:
3678        ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs radar detected\n");
3679        ATH10K_DFS_STAT_INC(ar, radar_detected);
3680
3681        /* Control radar events reporting in debugfs file
3682           dfs_block_radar_events */
3683        if (ar->dfs_block_radar_events) {
3684                ath10k_info(ar, "DFS Radar detected, but ignored as requested\n");
3685                return;
3686        }
3687
3688        ieee80211_radar_detected(ar->hw);
3689}
3690
3691static int ath10k_dfs_fft_report(struct ath10k *ar,
3692                                 struct wmi_phyerr_ev_arg *phyerr,
3693                                 const struct phyerr_fft_report *fftr,
3694                                 u64 tsf)
3695{
3696        u32 reg0, reg1;
3697        u8 rssi, peak_mag;
3698
3699        reg0 = __le32_to_cpu(fftr->reg0);
3700        reg1 = __le32_to_cpu(fftr->reg1);
3701        rssi = phyerr->rssi_combined;
3702
3703        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3704                   "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
3705                   MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
3706                   MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
3707                   MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
3708                   MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
3709        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3710                   "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
3711                   MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
3712                   MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
3713                   MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
3714                   MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
3715
3716        peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
3717
3718        /* false event detection */
3719        if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
3720            peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
3721                ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
3722                ATH10K_DFS_STAT_INC(ar, pulses_discarded);
3723                return -EINVAL;
3724        }
3725
3726        return 0;
3727}
3728
3729void ath10k_wmi_event_dfs(struct ath10k *ar,
3730                          struct wmi_phyerr_ev_arg *phyerr,
3731                          u64 tsf)
3732{
3733        int buf_len, tlv_len, res, i = 0;
3734        const struct phyerr_tlv *tlv;
3735        const struct phyerr_radar_report *rr;
3736        const struct phyerr_fft_report *fftr;
3737        const u8 *tlv_buf;
3738
3739        buf_len = phyerr->buf_len;
3740        ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3741                   "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
3742                   phyerr->phy_err_code, phyerr->rssi_combined,
3743                   phyerr->tsf_timestamp, tsf, buf_len);
3744
3745        /* Skip event if DFS disabled */
3746        if (!IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED))
3747                return;
3748
3749        ATH10K_DFS_STAT_INC(ar, pulses_total);
3750
3751        while (i < buf_len) {
3752                if (i + sizeof(*tlv) > buf_len) {
3753                        ath10k_warn(ar, "too short buf for tlv header (%d)\n",
3754                                    i);
3755                        return;
3756                }
3757
3758                tlv = (struct phyerr_tlv *)&phyerr->buf[i];
3759                tlv_len = __le16_to_cpu(tlv->len);
3760                tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
3761                ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3762                           "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
3763                           tlv_len, tlv->tag, tlv->sig);
3764
3765                switch (tlv->tag) {
3766                case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
3767                        if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
3768                                ath10k_warn(ar, "too short radar pulse summary (%d)\n",
3769                                            i);
3770                                return;
3771                        }
3772
3773                        rr = (struct phyerr_radar_report *)tlv_buf;
3774                        ath10k_dfs_radar_report(ar, phyerr, rr, tsf);
3775                        break;
3776                case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
3777                        if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
3778                                ath10k_warn(ar, "too short fft report (%d)\n",
3779                                            i);
3780                                return;
3781                        }
3782
3783                        fftr = (struct phyerr_fft_report *)tlv_buf;
3784                        res = ath10k_dfs_fft_report(ar, phyerr, fftr, tsf);
3785                        if (res)
3786                                return;
3787                        break;
3788                }
3789
3790                i += sizeof(*tlv) + tlv_len;
3791        }
3792}
3793
3794void ath10k_wmi_event_spectral_scan(struct ath10k *ar,
3795                                    struct wmi_phyerr_ev_arg *phyerr,
3796                                    u64 tsf)
3797{
3798        int buf_len, tlv_len, res, i = 0;
3799        struct phyerr_tlv *tlv;
3800        const void *tlv_buf;
3801        const struct phyerr_fft_report *fftr;
3802        size_t fftr_len;
3803
3804        buf_len = phyerr->buf_len;
3805
3806        while (i < buf_len) {
3807                if (i + sizeof(*tlv) > buf_len) {
3808                        ath10k_warn(ar, "failed to parse phyerr tlv header at byte %d\n",
3809                                    i);
3810                        return;
3811                }
3812
3813                tlv = (struct phyerr_tlv *)&phyerr->buf[i];
3814                tlv_len = __le16_to_cpu(tlv->len);
3815                tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
3816
3817                if (i + sizeof(*tlv) + tlv_len > buf_len) {
3818                        ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n",
3819                                    i);
3820                        return;
3821                }
3822
3823                switch (tlv->tag) {
3824                case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
3825                        if (sizeof(*fftr) > tlv_len) {
3826                                ath10k_warn(ar, "failed to parse fft report at byte %d\n",
3827                                            i);
3828                                return;
3829                        }
3830
3831                        fftr_len = tlv_len - sizeof(*fftr);
3832                        fftr = tlv_buf;
3833                        res = ath10k_spectral_process_fft(ar, phyerr,
3834                                                          fftr, fftr_len,
3835                                                          tsf);
3836                        if (res < 0) {
3837                                ath10k_dbg(ar, ATH10K_DBG_WMI, "failed to process fft report: %d\n",
3838                                           res);
3839                                return;
3840                        }
3841                        break;
3842                }
3843
3844                i += sizeof(*tlv) + tlv_len;
3845        }
3846}
3847
3848static int ath10k_wmi_op_pull_phyerr_ev_hdr(struct ath10k *ar,
3849                                            struct sk_buff *skb,
3850                                            struct wmi_phyerr_hdr_arg *arg)
3851{
3852        struct wmi_phyerr_event *ev = (void *)skb->data;
3853
3854        if (skb->len < sizeof(*ev))
3855                return -EPROTO;
3856
3857        arg->num_phyerrs = __le32_to_cpu(ev->num_phyerrs);
3858        arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
3859        arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
3860        arg->buf_len = skb->len - sizeof(*ev);
3861        arg->phyerrs = ev->phyerrs;
3862
3863        return 0;
3864}
3865
3866static int ath10k_wmi_10_4_op_pull_phyerr_ev_hdr(struct ath10k *ar,
3867                                                 struct sk_buff *skb,
3868                                                 struct wmi_phyerr_hdr_arg *arg)
3869{
3870        struct wmi_10_4_phyerr_event *ev = (void *)skb->data;
3871
3872        if (skb->len < sizeof(*ev))
3873                return -EPROTO;
3874
3875        /* 10.4 firmware always reports only one phyerr */
3876        arg->num_phyerrs = 1;
3877
3878        arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
3879        arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
3880        arg->buf_len = skb->len;
3881        arg->phyerrs = skb->data;
3882
3883        return 0;
3884}
3885
3886int ath10k_wmi_op_pull_phyerr_ev(struct ath10k *ar,
3887                                 const void *phyerr_buf,
3888                                 int left_len,
3889                                 struct wmi_phyerr_ev_arg *arg)
3890{
3891        const struct wmi_phyerr *phyerr = phyerr_buf;
3892        int i;
3893
3894        if (left_len < sizeof(*phyerr)) {
3895                ath10k_warn(ar, "wrong phyerr event head len %d (need: >=%zd)\n",
3896                            left_len, sizeof(*phyerr));
3897                return -EINVAL;
3898        }
3899
3900        arg->tsf_timestamp = __le32_to_cpu(phyerr->tsf_timestamp);
3901        arg->freq1 = __le16_to_cpu(phyerr->freq1);
3902        arg->freq2 = __le16_to_cpu(phyerr->freq2);
3903        arg->rssi_combined = phyerr->rssi_combined;
3904        arg->chan_width_mhz = phyerr->chan_width_mhz;
3905        arg->buf_len = __le32_to_cpu(phyerr->buf_len);
3906        arg->buf = phyerr->buf;
3907        arg->hdr_len = sizeof(*phyerr);
3908
3909        for (i = 0; i < 4; i++)
3910                arg->nf_chains[i] = __le16_to_cpu(phyerr->nf_chains[i]);
3911
3912        switch (phyerr->phy_err_code) {
3913        case PHY_ERROR_GEN_SPECTRAL_SCAN:
3914                arg->phy_err_code = PHY_ERROR_SPECTRAL_SCAN;
3915                break;
3916        case PHY_ERROR_GEN_FALSE_RADAR_EXT:
3917                arg->phy_err_code = PHY_ERROR_FALSE_RADAR_EXT;
3918                break;
3919        case PHY_ERROR_GEN_RADAR:
3920                arg->phy_err_code = PHY_ERROR_RADAR;
3921                break;
3922        default:
3923                arg->phy_err_code = PHY_ERROR_UNKNOWN;
3924                break;
3925        }
3926
3927        return 0;
3928}
3929
3930static int ath10k_wmi_10_4_op_pull_phyerr_ev(struct ath10k *ar,
3931                                             const void *phyerr_buf,
3932                                             int left_len,
3933                                             struct wmi_phyerr_ev_arg *arg)
3934{
3935        const struct wmi_10_4_phyerr_event *phyerr = phyerr_buf;
3936        u32 phy_err_mask;
3937        int i;
3938
3939        if (left_len < sizeof(*phyerr)) {
3940                ath10k_warn(ar, "wrong phyerr event head len %d (need: >=%zd)\n",
3941                            left_len, sizeof(*phyerr));
3942                return -EINVAL;
3943        }
3944
3945        arg->tsf_timestamp = __le32_to_cpu(phyerr->tsf_timestamp);
3946        arg->freq1 = __le16_to_cpu(phyerr->freq1);
3947        arg->freq2 = __le16_to_cpu(phyerr->freq2);
3948        arg->rssi_combined = phyerr->rssi_combined;
3949        arg->chan_width_mhz = phyerr->chan_width_mhz;
3950        arg->buf_len = __le32_to_cpu(phyerr->buf_len);
3951        arg->buf = phyerr->buf;
3952        arg->hdr_len = sizeof(*phyerr);
3953
3954        for (i = 0; i < 4; i++)
3955                arg->nf_chains[i] = __le16_to_cpu(phyerr->nf_chains[i]);
3956
3957        phy_err_mask = __le32_to_cpu(phyerr->phy_err_mask[0]);
3958
3959        if (phy_err_mask & PHY_ERROR_10_4_SPECTRAL_SCAN_MASK)
3960                arg->phy_err_code = PHY_ERROR_SPECTRAL_SCAN;
3961        else if (phy_err_mask & PHY_ERROR_10_4_RADAR_MASK)
3962                arg->phy_err_code = PHY_ERROR_RADAR;
3963        else
3964                arg->phy_err_code = PHY_ERROR_UNKNOWN;
3965
3966        return 0;
3967}
3968
3969void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
3970{
3971        struct wmi_phyerr_hdr_arg hdr_arg = {};
3972        struct wmi_phyerr_ev_arg phyerr_arg = {};
3973        const void *phyerr;
3974        u32 count, i, buf_len, phy_err_code;
3975        u64 tsf;
3976        int left_len, ret;
3977
3978        ATH10K_DFS_STAT_INC(ar, phy_errors);
3979
3980        ret = ath10k_wmi_pull_phyerr_hdr(ar, skb, &hdr_arg);
3981        if (ret) {
3982                ath10k_warn(ar, "failed to parse phyerr event hdr: %d\n", ret);
3983                return;
3984        }
3985
3986        /* Check number of included events */
3987        count = hdr_arg.num_phyerrs;
3988
3989        left_len = hdr_arg.buf_len;
3990
3991        tsf = hdr_arg.tsf_u32;
3992        tsf <<= 32;
3993        tsf |= hdr_arg.tsf_l32;
3994
3995        ath10k_dbg(ar, ATH10K_DBG_WMI,
3996                   "wmi event phyerr count %d tsf64 0x%llX\n",
3997                   count, tsf);
3998
3999        phyerr = hdr_arg.phyerrs;
4000        for (i = 0; i < count; i++) {
4001                ret = ath10k_wmi_pull_phyerr(ar, phyerr, left_len, &phyerr_arg);
4002                if (ret) {
4003                        ath10k_warn(ar, "failed to parse phyerr event (%d)\n",
4004                                    i);
4005                        return;
4006                }
4007
4008                left_len -= phyerr_arg.hdr_len;
4009                buf_len = phyerr_arg.buf_len;
4010                phy_err_code = phyerr_arg.phy_err_code;
4011
4012                if (left_len < buf_len) {
4013                        ath10k_warn(ar, "single event (%d) wrong buf len\n", i);
4014                        return;
4015                }
4016
4017                left_len -= buf_len;
4018
4019                switch (phy_err_code) {
4020                case PHY_ERROR_RADAR:
4021                        ath10k_wmi_event_dfs(ar, &phyerr_arg, tsf);
4022                        break;
4023                case PHY_ERROR_SPECTRAL_SCAN:
4024                        ath10k_wmi_event_spectral_scan(ar, &phyerr_arg, tsf);
4025                        break;
4026                case PHY_ERROR_FALSE_RADAR_EXT:
4027                        ath10k_wmi_event_dfs(ar, &phyerr_arg, tsf);
4028                        ath10k_wmi_event_spectral_scan(ar, &phyerr_arg, tsf);
4029                        break;
4030                default:
4031                        break;
4032                }
4033
4034                phyerr = phyerr + phyerr_arg.hdr_len + buf_len;
4035        }
4036}
4037
4038void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
4039{
4040        struct wmi_roam_ev_arg arg = {};
4041        int ret;
4042        u32 vdev_id;
4043        u32 reason;
4044        s32 rssi;
4045
4046        ret = ath10k_wmi_pull_roam_ev(ar, skb, &arg);
4047        if (ret) {
4048                ath10k_warn(ar, "failed to parse roam event: %d\n", ret);
4049                return;
4050        }
4051
4052        vdev_id = __le32_to_cpu(arg.vdev_id);
4053        reason = __le32_to_cpu(arg.reason);
4054        rssi = __le32_to_cpu(arg.rssi);
4055        rssi += WMI_SPECTRAL_NOISE_FLOOR_REF_DEFAULT;
4056
4057        ath10k_dbg(ar, ATH10K_DBG_WMI,
4058                   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
4059                   vdev_id, reason, rssi);
4060
4061        if (reason >= WMI_ROAM_REASON_MAX)
4062                ath10k_warn(ar, "ignoring unknown roam event reason %d on vdev %i\n",
4063                            reason, vdev_id);
4064
4065        switch (reason) {
4066        case WMI_ROAM_REASON_BEACON_MISS:
4067                ath10k_mac_handle_beacon_miss(ar, vdev_id);
4068                break;
4069        case WMI_ROAM_REASON_BETTER_AP:
4070        case WMI_ROAM_REASON_LOW_RSSI:
4071        case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
4072        case WMI_ROAM_REASON_HO_FAILED:
4073                ath10k_warn(ar, "ignoring not implemented roam event reason %d on vdev %i\n",
4074                            reason, vdev_id);
4075                break;
4076        }
4077}
4078
4079void ath10k_wmi_event_profile_match(struct ath10k *ar, struct sk_buff *skb)
4080{
4081        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
4082}
4083
4084void ath10k_wmi_event_debug_print(struct ath10k *ar, struct sk_buff *skb)
4085{
4086        char buf[101], c;
4087        int i;
4088
4089        for (i = 0; i < sizeof(buf) - 1; i++) {
4090                if (i >= skb->len)
4091                        break;
4092
4093                c = skb->data[i];
4094
4095                if (c == '\0')
4096                        break;
4097
4098                if (isascii(c) && isprint(c))
4099                        buf[i] = c;
4100                else
4101                        buf[i] = '.';
4102        }
4103
4104        if (i == sizeof(buf) - 1)
4105                ath10k_warn(ar, "wmi debug print truncated: %d\n", skb->len);
4106
4107        /* for some reason the debug prints end with \n, remove that */
4108        if (skb->data[i - 1] == '\n')
4109                i--;
4110
4111        /* the last byte is always reserved for the null character */
4112        buf[i] = '\0';
4113
4114        ath10k_dbg(ar, ATH10K_DBG_WMI_PRINT, "wmi print '%s'\n", buf);
4115}
4116
4117void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
4118{
4119        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
4120}
4121
4122void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar, struct sk_buff *skb)
4123{
4124        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
4125}
4126
4127void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
4128                                             struct sk_buff *skb)
4129{
4130        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
4131}
4132
4133void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
4134                                             struct sk_buff *skb)
4135{
4136        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
4137}
4138
4139void ath10k_wmi_event_rtt_error_report(struct ath10k *ar, struct sk_buff *skb)
4140{
4141        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
4142}
4143
4144void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar, struct sk_buff *skb)
4145{
4146        struct wmi_wow_ev_arg ev = {};
4147        int ret;
4148
4149        complete(&ar->wow.wakeup_completed);
4150
4151        ret = ath10k_wmi_pull_wow_event(ar, skb, &ev);
4152        if (ret) {
4153                ath10k_warn(ar, "failed to parse wow wakeup event: %d\n", ret);
4154                return;
4155        }
4156
4157        ath10k_dbg(ar, ATH10K_DBG_WMI, "wow wakeup host reason %s\n",
4158                   wow_reason(ev.wake_reason));
4159}
4160
4161void ath10k_wmi_event_dcs_interference(struct ath10k *ar, struct sk_buff *skb)
4162{
4163        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
4164}
4165
4166static u8 ath10k_tpc_config_get_rate(struct ath10k *ar,
4167                                     struct wmi_pdev_tpc_config_event *ev,
4168                                     u32 rate_idx, u32 num_chains,
4169                                     u32 rate_code, u8 type)
4170{
4171        u8 tpc, num_streams, preamble, ch, stm_idx;
4172
4173        num_streams = ATH10K_HW_NSS(rate_code);
4174        preamble = ATH10K_HW_PREAMBLE(rate_code);
4175        ch = num_chains - 1;
4176
4177        tpc = min_t(u8, ev->rates_array[rate_idx], ev->max_reg_allow_pow[ch]);
4178
4179        if (__le32_to_cpu(ev->num_tx_chain) <= 1)
4180                goto out;
4181
4182        if (preamble == WMI_RATE_PREAMBLE_CCK)
4183                goto out;
4184
4185        stm_idx = num_streams - 1;
4186        if (num_chains <= num_streams)
4187                goto out;
4188
4189        switch (type) {
4190        case WMI_TPC_TABLE_TYPE_STBC:
4191                tpc = min_t(u8, tpc,
4192                            ev->max_reg_allow_pow_agstbc[ch - 1][stm_idx]);
4193                break;
4194        case WMI_TPC_TABLE_TYPE_TXBF:
4195                tpc = min_t(u8, tpc,
4196                            ev->max_reg_allow_pow_agtxbf[ch - 1][stm_idx]);
4197                break;
4198        case WMI_TPC_TABLE_TYPE_CDD:
4199                tpc = min_t(u8, tpc,
4200                            ev->max_reg_allow_pow_agcdd[ch - 1][stm_idx]);
4201                break;
4202        default:
4203                ath10k_warn(ar, "unknown wmi tpc table type: %d\n", type);
4204                tpc = 0;
4205                break;
4206        }
4207
4208out:
4209        return tpc;
4210}
4211
4212static void ath10k_tpc_config_disp_tables(struct ath10k *ar,
4213                                          struct wmi_pdev_tpc_config_event *ev,
4214                                          struct ath10k_tpc_stats *tpc_stats,
4215                                          u8 *rate_code, u16 *pream_table, u8 type)
4216{
4217        u32 i, j, pream_idx, flags;
4218        u8 tpc[WMI_TPC_TX_N_CHAIN];
4219        char tpc_value[WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
4220        char buff[WMI_TPC_BUF_SIZE];
4221
4222        flags = __le32_to_cpu(ev->flags);
4223
4224        switch (type) {
4225        case WMI_TPC_TABLE_TYPE_CDD:
4226                if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_CDD)) {
4227                        ath10k_dbg(ar, ATH10K_DBG_WMI, "CDD not supported\n");
4228                        tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4229                        return;
4230                }
4231                break;
4232        case WMI_TPC_TABLE_TYPE_STBC:
4233                if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_STBC)) {
4234                        ath10k_dbg(ar, ATH10K_DBG_WMI, "STBC not supported\n");
4235                        tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4236                        return;
4237                }
4238                break;
4239        case WMI_TPC_TABLE_TYPE_TXBF:
4240                if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_TXBF)) {
4241                        ath10k_dbg(ar, ATH10K_DBG_WMI, "TXBF not supported\n");
4242                        tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4243                        return;
4244                }
4245                break;
4246        default:
4247                ath10k_dbg(ar, ATH10K_DBG_WMI,
4248                           "invalid table type in wmi tpc event: %d\n", type);
4249                return;
4250        }
4251
4252        pream_idx = 0;
4253        for (i = 0; i < __le32_to_cpu(ev->rate_max); i++) {
4254                memset(tpc_value, 0, sizeof(tpc_value));
4255                memset(buff, 0, sizeof(buff));
4256                if (i == pream_table[pream_idx])
4257                        pream_idx++;
4258
4259                for (j = 0; j < WMI_TPC_TX_N_CHAIN; j++) {
4260                        if (j >= __le32_to_cpu(ev->num_tx_chain))
4261                                break;
4262
4263                        tpc[j] = ath10k_tpc_config_get_rate(ar, ev, i, j + 1,
4264                                                            rate_code[i],
4265                                                            type);
4266                        snprintf(buff, sizeof(buff), "%8d ", tpc[j]);
4267                        strncat(tpc_value, buff, strlen(buff));
4268                }
4269                tpc_stats->tpc_table[type].pream_idx[i] = pream_idx;
4270                tpc_stats->tpc_table[type].rate_code[i] = rate_code[i];
4271                memcpy(tpc_stats->tpc_table[type].tpc_value[i],
4272                       tpc_value, sizeof(tpc_value));
4273        }
4274}
4275
4276void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar, struct sk_buff *skb)
4277{
4278        u32 i, j, pream_idx, num_tx_chain;
4279        u8 rate_code[WMI_TPC_RATE_MAX], rate_idx;
4280        u16 pream_table[WMI_TPC_PREAM_TABLE_MAX];
4281        struct wmi_pdev_tpc_config_event *ev;
4282        struct ath10k_tpc_stats *tpc_stats;
4283
4284        ev = (struct wmi_pdev_tpc_config_event *)skb->data;
4285
4286        tpc_stats = kzalloc(sizeof(*tpc_stats), GFP_ATOMIC);
4287        if (!tpc_stats)
4288                return;
4289
4290        /* Create the rate code table based on the chains supported */
4291        rate_idx = 0;
4292        pream_idx = 0;
4293
4294        /* Fill CCK rate code */
4295        for (i = 0; i < 4; i++) {
4296                rate_code[rate_idx] =
4297                        ATH10K_HW_RATECODE(i, 0, WMI_RATE_PREAMBLE_CCK);
4298                rate_idx++;
4299        }
4300        pream_table[pream_idx] = rate_idx;
4301        pream_idx++;
4302
4303        /* Fill OFDM rate code */
4304        for (i = 0; i < 8; i++) {
4305                rate_code[rate_idx] =
4306                        ATH10K_HW_RATECODE(i, 0, WMI_RATE_PREAMBLE_OFDM);
4307                rate_idx++;
4308        }
4309        pream_table[pream_idx] = rate_idx;
4310        pream_idx++;
4311
4312        num_tx_chain = __le32_to_cpu(ev->num_tx_chain);
4313
4314        /* Fill HT20 rate code */
4315        for (i = 0; i < num_tx_chain; i++) {
4316                for (j = 0; j < 8; j++) {
4317                        rate_code[rate_idx] =
4318                        ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_HT);
4319                        rate_idx++;
4320                }
4321        }
4322        pream_table[pream_idx] = rate_idx;
4323        pream_idx++;
4324
4325        /* Fill HT40 rate code */
4326        for (i = 0; i < num_tx_chain; i++) {
4327                for (j = 0; j < 8; j++) {
4328                        rate_code[rate_idx] =
4329                        ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_HT);
4330                        rate_idx++;
4331                }
4332        }
4333        pream_table[pream_idx] = rate_idx;
4334        pream_idx++;
4335
4336        /* Fill VHT20 rate code */
4337        for (i = 0; i < __le32_to_cpu(ev->num_tx_chain); i++) {
4338                for (j = 0; j < 10; j++) {
4339                        rate_code[rate_idx] =
4340                        ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4341                        rate_idx++;
4342                }
4343        }
4344        pream_table[pream_idx] = rate_idx;
4345        pream_idx++;
4346
4347        /* Fill VHT40 rate code */
4348        for (i = 0; i < num_tx_chain; i++) {
4349                for (j = 0; j < 10; j++) {
4350                        rate_code[rate_idx] =
4351                        ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4352                        rate_idx++;
4353                }
4354        }
4355        pream_table[pream_idx] = rate_idx;
4356        pream_idx++;
4357
4358        /* Fill VHT80 rate code */
4359        for (i = 0; i < num_tx_chain; i++) {
4360                for (j = 0; j < 10; j++) {
4361                        rate_code[rate_idx] =
4362                        ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4363                        rate_idx++;
4364                }
4365        }
4366        pream_table[pream_idx] = rate_idx;
4367        pream_idx++;
4368
4369        rate_code[rate_idx++] =
4370                ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_CCK);
4371        rate_code[rate_idx++] =
4372                ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4373        rate_code[rate_idx++] =
4374                ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_CCK);
4375        rate_code[rate_idx++] =
4376                ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4377        rate_code[rate_idx++] =
4378                ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4379
4380        pream_table[pream_idx] = ATH10K_TPC_PREAM_TABLE_END;
4381
4382        tpc_stats->chan_freq = __le32_to_cpu(ev->chan_freq);
4383        tpc_stats->phy_mode = __le32_to_cpu(ev->phy_mode);
4384        tpc_stats->ctl = __le32_to_cpu(ev->ctl);
4385        tpc_stats->reg_domain = __le32_to_cpu(ev->reg_domain);
4386        tpc_stats->twice_antenna_gain = a_sle32_to_cpu(ev->twice_antenna_gain);
4387        tpc_stats->twice_antenna_reduction =
4388                __le32_to_cpu(ev->twice_antenna_reduction);
4389        tpc_stats->power_limit = __le32_to_cpu(ev->power_limit);
4390        tpc_stats->twice_max_rd_power = __le32_to_cpu(ev->twice_max_rd_power);
4391        tpc_stats->num_tx_chain = __le32_to_cpu(ev->num_tx_chain);
4392        tpc_stats->rate_max = __le32_to_cpu(ev->rate_max);
4393
4394        ath10k_tpc_config_disp_tables(ar, ev, tpc_stats,
4395                                      rate_code, pream_table,
4396                                      WMI_TPC_TABLE_TYPE_CDD);
4397        ath10k_tpc_config_disp_tables(ar, ev,  tpc_stats,
4398                                      rate_code, pream_table,
4399                                      WMI_TPC_TABLE_TYPE_STBC);
4400        ath10k_tpc_config_disp_tables(ar, ev, tpc_stats,
4401                                      rate_code, pream_table,
4402                                      WMI_TPC_TABLE_TYPE_TXBF);
4403
4404        ath10k_debug_tpc_stats_process(ar, tpc_stats);
4405
4406        ath10k_dbg(ar, ATH10K_DBG_WMI,
4407                   "wmi event tpc config channel %d mode %d ctl %d regd %d gain %d %d limit %d max_power %d tx_chanins %d rates %d\n",
4408                   __le32_to_cpu(ev->chan_freq),
4409                   __le32_to_cpu(ev->phy_mode),
4410                   __le32_to_cpu(ev->ctl),
4411                   __le32_to_cpu(ev->reg_domain),
4412                   a_sle32_to_cpu(ev->twice_antenna_gain),
4413                   __le32_to_cpu(ev->twice_antenna_reduction),
4414                   __le32_to_cpu(ev->power_limit),
4415                   __le32_to_cpu(ev->twice_max_rd_power) / 2,
4416                   __le32_to_cpu(ev->num_tx_chain),
4417                   __le32_to_cpu(ev->rate_max));
4418}
4419
4420void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar, struct sk_buff *skb)
4421{
4422        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
4423}
4424
4425void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar, struct sk_buff *skb)
4426{
4427        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
4428}
4429
4430void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar, struct sk_buff *skb)
4431{
4432        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
4433}
4434
4435void ath10k_wmi_event_delba_complete(struct ath10k *ar, struct sk_buff *skb)
4436{
4437        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
4438}
4439
4440void ath10k_wmi_event_addba_complete(struct ath10k *ar, struct sk_buff *skb)
4441{
4442        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
4443}
4444
4445void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
4446                                                struct sk_buff *skb)
4447{
4448        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
4449}
4450
4451void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar, struct sk_buff *skb)
4452{
4453        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
4454}
4455
4456void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar, struct sk_buff *skb)
4457{
4458        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
4459}
4460
4461void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar, struct sk_buff *skb)
4462{
4463        ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
4464}
4465
4466static int ath10k_wmi_alloc_chunk(struct ath10k *ar, u32 req_id,
4467                                  u32 num_units, u32 unit_len)
4468{
4469        dma_addr_t paddr;
4470        u32 pool_size = 0;
4471        int idx = ar->wmi.num_mem_chunks;
4472        void *vaddr = NULL;
4473
4474        if (ar->wmi.num_mem_chunks == ARRAY_SIZE(ar->wmi.mem_chunks))
4475                return -ENOMEM;
4476
4477        while (!vaddr && num_units) {
4478                pool_size = num_units * round_up(unit_len, 4);
4479                if (!pool_size)
4480                        return -EINVAL;
4481
4482                vaddr = kzalloc(pool_size, GFP_KERNEL | __GFP_NOWARN);
4483                if (!vaddr)
4484                        num_units /= 2;
4485        }
4486
4487        if (!num_units)
4488                return -ENOMEM;
4489
4490        paddr = dma_map_single(ar->dev, vaddr, pool_size, DMA_BIDIRECTIONAL);
4491        if (dma_mapping_error(ar->dev, paddr)) {
4492                kfree(vaddr);
4493                return -ENOMEM;
4494        }
4495
4496        ar->wmi.mem_chunks[idx].vaddr = vaddr;
4497        ar->wmi.mem_chunks[idx].paddr = paddr;
4498        ar->wmi.mem_chunks[idx].len = pool_size;
4499        ar->wmi.mem_chunks[idx].req_id = req_id;
4500        ar->wmi.num_mem_chunks++;
4501
4502        return num_units;
4503}
4504
4505static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
4506                                     u32 num_units, u32 unit_len)
4507{
4508        int ret;
4509
4510        while (num_units) {
4511                ret = ath10k_wmi_alloc_chunk(ar, req_id, num_units, unit_len);
4512                if (ret < 0)
4513                        return ret;
4514
4515                num_units -= ret;
4516        }
4517
4518        return 0;
4519}
4520
4521static bool
4522ath10k_wmi_is_host_mem_allocated(struct ath10k *ar,
4523                                 const struct wlan_host_mem_req **mem_reqs,
4524                                 u32 num_mem_reqs)
4525{
4526        u32 req_id, num_units, unit_size, num_unit_info;
4527        u32 pool_size;
4528        int i, j;
4529        bool found;
4530
4531        if (ar->wmi.num_mem_chunks != num_mem_reqs)
4532                return false;
4533
4534        for (i = 0; i < num_mem_reqs; ++i) {
4535                req_id = __le32_to_cpu(mem_reqs[i]->req_id);
4536                num_units = __le32_to_cpu(mem_reqs[i]->num_units);
4537                unit_size = __le32_to_cpu(mem_reqs[i]->unit_size);
4538                num_unit_info = __le32_to_cpu(mem_reqs[i]->num_unit_info);
4539
4540                if (num_unit_info & NUM_UNITS_IS_NUM_ACTIVE_PEERS) {
4541                        if (ar->num_active_peers)
4542                                num_units = ar->num_active_peers + 1;
4543                        else
4544                                num_units = ar->max_num_peers + 1;
4545                } else if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) {
4546                        num_units = ar->max_num_peers + 1;
4547                } else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS) {
4548                        num_units = ar->max_num_vdevs + 1;
4549                }
4550
4551                found = false;
4552                for (j = 0; j < ar->wmi.num_mem_chunks; j++) {
4553                        if (ar->wmi.mem_chunks[j].req_id == req_id) {
4554                                pool_size = num_units * round_up(unit_size, 4);
4555                                if (ar->wmi.mem_chunks[j].len == pool_size) {
4556                                        found = true;
4557                                        break;
4558                                }
4559                        }
4560                }
4561                if (!found)
4562                        return false;
4563        }
4564
4565        return true;
4566}
4567
4568static int
4569ath10k_wmi_main_op_pull_svc_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
4570                                   struct wmi_svc_rdy_ev_arg *arg)
4571{
4572        struct wmi_service_ready_event *ev;
4573        size_t i, n;
4574
4575        if (skb->len < sizeof(*ev))
4576                return -EPROTO;
4577
4578        ev = (void *)skb->data;
4579        skb_pull(skb, sizeof(*ev));
4580        arg->min_tx_power = ev->hw_min_tx_power;
4581        arg->max_tx_power = ev->hw_max_tx_power;
4582        arg->ht_cap = ev->ht_cap_info;
4583        arg->vht_cap = ev->vht_cap_info;
4584        arg->sw_ver0 = ev->sw_version;
4585        arg->sw_ver1 = ev->sw_version_1;
4586        arg->phy_capab = ev->phy_capability;
4587        arg->num_rf_chains = ev->num_rf_chains;
4588        arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
4589        arg->num_mem_reqs = ev->num_mem_reqs;
4590        arg->service_map = ev->wmi_service_bitmap;
4591        arg->service_map_len = sizeof(ev->wmi_service_bitmap);
4592
4593        n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
4594                  ARRAY_SIZE(arg->mem_reqs));
4595        for (i = 0; i < n; i++)
4596                arg->mem_reqs[i] = &ev->mem_reqs[i];
4597
4598        if (skb->len <
4599            __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
4600                return -EPROTO;
4601
4602        return 0;
4603}
4604
4605static int
4606ath10k_wmi_10x_op_pull_svc_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
4607                                  struct wmi_svc_rdy_ev_arg *arg)
4608{
4609        struct wmi_10x_service_ready_event *ev;
4610        int i, n;
4611
4612        if (skb->len < sizeof(*ev))
4613                return -EPROTO;
4614
4615        ev = (void *)skb->data;
4616        skb_pull(skb, sizeof(*ev));
4617        arg->min_tx_power = ev->hw_min_tx_power;
4618        arg->max_tx_power = ev->hw_max_tx_power;
4619        arg->ht_cap = ev->ht_cap_info;
4620        arg->vht_cap = ev->vht_cap_info;
4621        arg->sw_ver0 = ev->sw_version;
4622        arg->phy_capab = ev->phy_capability;
4623        arg->num_rf_chains = ev->num_rf_chains;
4624        arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
4625        arg->num_mem_reqs = ev->num_mem_reqs;
4626        arg->service_map = ev->wmi_service_bitmap;
4627        arg->service_map_len = sizeof(ev->wmi_service_bitmap);
4628
4629        n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
4630                  ARRAY_SIZE(arg->mem_reqs));
4631        for (i = 0; i < n; i++)
4632                arg->mem_reqs[i] = &ev->mem_reqs[i];
4633
4634        if (skb->len <
4635            __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
4636                return -EPROTO;
4637
4638        return 0;
4639}
4640
4641static void ath10k_wmi_event_service_ready_work(struct work_struct *work)
4642{
4643        struct ath10k *ar = container_of(work, struct ath10k, svc_rdy_work);
4644        struct sk_buff *skb = ar->svc_rdy_skb;
4645        struct wmi_svc_rdy_ev_arg arg = {};
4646        u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
4647        int ret;
4648        bool allocated;
4649
4650        if (!skb) {
4651                ath10k_warn(ar, "invalid service ready event skb\n");
4652                return;
4653        }
4654
4655        ret = ath10k_wmi_pull_svc_rdy(ar, skb, &arg);
4656        if (ret) {
4657                ath10k_warn(ar, "failed to parse service ready: %d\n", ret);
4658                return;
4659        }
4660
4661        memset(&ar->wmi.svc_map, 0, sizeof(ar->wmi.svc_map));
4662        ath10k_wmi_map_svc(ar, arg.service_map, ar->wmi.svc_map,
4663                           arg.service_map_len);
4664
4665        ar->hw_min_tx_power = __le32_to_cpu(arg.min_tx_power);
4666        ar->hw_max_tx_power = __le32_to_cpu(arg.max_tx_power);
4667        ar->ht_cap_info = __le32_to_cpu(arg.ht_cap);
4668        ar->vht_cap_info = __le32_to_cpu(arg.vht_cap);
4669        ar->fw_version_major =
4670                (__le32_to_cpu(arg.sw_ver0) & 0xff000000) >> 24;
4671        ar->fw_version_minor = (__le32_to_cpu(arg.sw_ver0) & 0x00ffffff);
4672        ar->fw_version_release =
4673                (__le32_to_cpu(arg.sw_ver1) & 0xffff0000) >> 16;
4674        ar->fw_version_build = (__le32_to_cpu(arg.sw_ver1) & 0x0000ffff);
4675        ar->phy_capability = __le32_to_cpu(arg.phy_capab);
4676        ar->num_rf_chains = __le32_to_cpu(arg.num_rf_chains);
4677        ar->hw_eeprom_rd = __le32_to_cpu(arg.eeprom_rd);
4678
4679        ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
4680                        arg.service_map, arg.service_map_len);
4681
4682        if (ar->num_rf_chains > ar->max_spatial_stream) {
4683                ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
4684                            ar->num_rf_chains, ar->max_spatial_stream);
4685                ar->num_rf_chains = ar->max_spatial_stream;
4686        }
4687
4688        if (!ar->cfg_tx_chainmask) {
4689                ar->cfg_tx_chainmask = (1 << ar->num_rf_chains) - 1;
4690                ar->cfg_rx_chainmask = (1 << ar->num_rf_chains) - 1;
4691        }
4692
4693        if (strlen(ar->hw->wiphy->fw_version) == 0) {
4694                snprintf(ar->hw->wiphy->fw_version,
4695                         sizeof(ar->hw->wiphy->fw_version),
4696                         "%u.%u.%u.%u",
4697                         ar->fw_version_major,
4698                         ar->fw_version_minor,
4699                         ar->fw_version_release,
4700                         ar->fw_version_build);
4701        }
4702
4703        num_mem_reqs = __le32_to_cpu(arg.num_mem_reqs);
4704        if (num_mem_reqs > WMI_MAX_MEM_REQS) {
4705                ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n",
4706                            num_mem_reqs);
4707                return;
4708        }
4709
4710        if (test_bit(WMI_SERVICE_PEER_CACHING, ar->wmi.svc_map)) {
4711                if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
4712                             ar->running_fw->fw_file.fw_features))
4713                        ar->num_active_peers = TARGET_10_4_QCACHE_ACTIVE_PEERS_PFC +
4714                                               ar->max_num_vdevs;
4715                else
4716                        ar->num_active_peers = TARGET_10_4_QCACHE_ACTIVE_PEERS +
4717                                               ar->max_num_vdevs;
4718
4719                ar->max_num_peers = TARGET_10_4_NUM_QCACHE_PEERS_MAX +
4720                                    ar->max_num_vdevs;
4721                ar->num_tids = ar->num_active_peers * 2;
4722                ar->max_num_stations = TARGET_10_4_NUM_QCACHE_PEERS_MAX;
4723        }
4724
4725        /* TODO: Adjust max peer count for cases like WMI_SERVICE_RATECTRL_CACHE
4726         * and WMI_SERVICE_IRAM_TIDS, etc.
4727         */
4728
4729        allocated = ath10k_wmi_is_host_mem_allocated(ar, arg.mem_reqs,
4730                                                     num_mem_reqs);
4731        if (allocated)
4732                goto skip_mem_alloc;
4733
4734        /* Either this event is received during boot time or there is a change
4735         * in memory requirement from firmware when compared to last request.
4736         * Free any old memory and do a fresh allocation based on the current
4737         * memory requirement.
4738         */
4739        ath10k_wmi_free_host_mem(ar);
4740
4741        for (i = 0; i < num_mem_reqs; ++i) {
4742                req_id = __le32_to_cpu(arg.mem_reqs[i]->req_id);
4743                num_units = __le32_to_cpu(arg.mem_reqs[i]->num_units);
4744                unit_size = __le32_to_cpu(arg.mem_reqs[i]->unit_size);
4745                num_unit_info = __le32_to_cpu(arg.mem_reqs[i]->num_unit_info);
4746
4747                if (num_unit_info & NUM_UNITS_IS_NUM_ACTIVE_PEERS) {
4748                        if (ar->num_active_peers)
4749                                num_units = ar->num_active_peers + 1;
4750                        else
4751                                num_units = ar->max_num_peers + 1;
4752                } else if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) {
4753                        /* number of units to allocate is number of
4754                         * peers, 1 extra for self peer on target */
4755                        /* this needs to be tied, host and target
4756                         * can get out of sync */
4757                        num_units = ar->max_num_peers + 1;
4758                } else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS) {
4759                        num_units = ar->max_num_vdevs + 1;
4760                }
4761
4762                ath10k_dbg(ar, ATH10K_DBG_WMI,
4763                           "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
4764                           req_id,
4765                           __le32_to_cpu(arg.mem_reqs[i]->num_units),
4766                           num_unit_info,
4767                           unit_size,
4768                           num_units);
4769
4770                ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
4771                                                unit_size);
4772                if (ret)
4773                        return;
4774        }
4775
4776skip_mem_alloc:
4777        ath10k_dbg(ar, ATH10K_DBG_WMI,
4778                   "wmi event service ready min_tx_power 0x%08x max_tx_power 0x%08x ht_cap 0x%08x vht_cap 0x%08x sw_ver0 0x%08x sw_ver1 0x%08x fw_build 0x%08x phy_capab 0x%08x num_rf_chains 0x%08x eeprom_rd 0x%08x num_mem_reqs 0x%08x\n",
4779                   __le32_to_cpu(arg.min_tx_power),
4780                   __le32_to_cpu(arg.max_tx_power),
4781                   __le32_to_cpu(arg.ht_cap),
4782                   __le32_to_cpu(arg.vht_cap),
4783                   __le32_to_cpu(arg.sw_ver0),
4784                   __le32_to_cpu(arg.sw_ver1),
4785                   __le32_to_cpu(arg.fw_build),
4786                   __le32_to_cpu(arg.phy_capab),
4787                   __le32_to_cpu(arg.num_rf_chains),
4788                   __le32_to_cpu(arg.eeprom_rd),
4789                   __le32_to_cpu(arg.num_mem_reqs));
4790
4791        dev_kfree_skb(skb);
4792        ar->svc_rdy_skb = NULL;
4793        complete(&ar->wmi.service_ready);
4794}
4795
4796void ath10k_wmi_event_service_ready(struct ath10k *ar, struct sk_buff *skb)
4797{
4798        ar->svc_rdy_skb = skb;
4799        queue_work(ar->workqueue_aux, &ar->svc_rdy_work);
4800}
4801
4802static int ath10k_wmi_op_pull_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
4803                                     struct wmi_rdy_ev_arg *arg)
4804{
4805        struct wmi_ready_event *ev = (void *)skb->data;
4806
4807        if (skb->len < sizeof(*ev))
4808                return -EPROTO;
4809
4810        skb_pull(skb, sizeof(*ev));
4811        arg->sw_version = ev->sw_version;
4812        arg->abi_version = ev->abi_version;
4813        arg->status = ev->status;
4814        arg->mac_addr = ev->mac_addr.addr;
4815
4816        return 0;
4817}
4818
4819static int ath10k_wmi_op_pull_roam_ev(struct ath10k *ar, struct sk_buff *skb,
4820                                      struct wmi_roam_ev_arg *arg)
4821{
4822        struct wmi_roam_ev *ev = (void *)skb->data;
4823
4824        if (skb->len < sizeof(*ev))
4825                return -EPROTO;
4826
4827        skb_pull(skb, sizeof(*ev));
4828        arg->vdev_id = ev->vdev_id;
4829        arg->reason = ev->reason;
4830
4831        return 0;
4832}
4833
4834static int ath10k_wmi_op_pull_echo_ev(struct ath10k *ar,
4835                                      struct sk_buff *skb,
4836                                      struct wmi_echo_ev_arg *arg)
4837{
4838        struct wmi_echo_event *ev = (void *)skb->data;
4839
4840        arg->value = ev->value;
4841
4842        return 0;
4843}
4844
4845int ath10k_wmi_event_ready(struct ath10k *ar, struct sk_buff *skb)
4846{
4847        struct wmi_rdy_ev_arg arg = {};
4848        int ret;
4849
4850        ret = ath10k_wmi_pull_rdy(ar, skb, &arg);
4851        if (ret) {
4852                ath10k_warn(ar, "failed to parse ready event: %d\n", ret);
4853                return ret;
4854        }
4855
4856        ath10k_dbg(ar, ATH10K_DBG_WMI,
4857                   "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d\n",
4858                   __le32_to_cpu(arg.sw_version),
4859                   __le32_to_cpu(arg.abi_version),
4860                   arg.mac_addr,
4861                   __le32_to_cpu(arg.status));
4862
4863        ether_addr_copy(ar->mac_addr, arg.mac_addr);
4864        complete(&ar->wmi.unified_ready);
4865        return 0;
4866}
4867
4868static int ath10k_wmi_event_temperature(struct ath10k *ar, struct sk_buff *skb)
4869{
4870        const struct wmi_pdev_temperature_event *ev;
4871
4872        ev = (struct wmi_pdev_temperature_event *)skb->data;
4873        if (WARN_ON(skb->len < sizeof(*ev)))
4874                return -EPROTO;
4875
4876        ath10k_thermal_event_temperature(ar, __le32_to_cpu(ev->temperature));
4877        return 0;
4878}
4879
4880static int ath10k_wmi_event_pdev_bss_chan_info(struct ath10k *ar,
4881                                               struct sk_buff *skb)
4882{
4883        struct wmi_pdev_bss_chan_info_event *ev;
4884        struct survey_info *survey;
4885        u64 busy, total, tx, rx, rx_bss;
4886        u32 freq, noise_floor;
4887        u32 cc_freq_hz = ar->hw_params.channel_counters_freq_hz;
4888        int idx;
4889
4890        ev = (struct wmi_pdev_bss_chan_info_event *)skb->data;
4891        if (WARN_ON(skb->len < sizeof(*ev)))
4892                return -EPROTO;
4893
4894        freq        = __le32_to_cpu(ev->freq);
4895        noise_floor = __le32_to_cpu(ev->noise_floor);
4896        busy        = __le64_to_cpu(ev->cycle_busy);
4897        total       = __le64_to_cpu(ev->cycle_total);
4898        tx          = __le64_to_cpu(ev->cycle_tx);
4899        rx          = __le64_to_cpu(ev->cycle_rx);
4900        rx_bss      = __le64_to_cpu(ev->cycle_rx_bss);
4901
4902        ath10k_dbg(ar, ATH10K_DBG_WMI,
4903                   "wmi event pdev bss chan info:\n freq: %d noise: %d cycle: busy %llu total %llu tx %llu rx %llu rx_bss %llu\n",
4904                   freq, noise_floor, busy, total, tx, rx, rx_bss);
4905
4906        spin_lock_bh(&ar->data_lock);
4907        idx = freq_to_idx(ar, freq);
4908        if (idx >= ARRAY_SIZE(ar->survey)) {
4909                ath10k_warn(ar, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
4910                            freq, idx);
4911                goto exit;
4912        }
4913
4914        survey = &ar->survey[idx];
4915
4916        survey->noise     = noise_floor;
4917        survey->time      = div_u64(total, cc_freq_hz);
4918        survey->time_busy = div_u64(busy, cc_freq_hz);
4919        survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
4920        survey->time_tx   = div_u64(tx, cc_freq_hz);
4921        survey->filled   |= (SURVEY_INFO_NOISE_DBM |
4922                             SURVEY_INFO_TIME |
4923                             SURVEY_INFO_TIME_BUSY |
4924                             SURVEY_INFO_TIME_RX |
4925                             SURVEY_INFO_TIME_TX);
4926exit:
4927        spin_unlock_bh(&ar->data_lock);
4928        complete(&ar->bss_survey_done);
4929        return 0;
4930}
4931
4932static inline void ath10k_wmi_queue_set_coverage_class_work(struct ath10k *ar)
4933{
4934        if (ar->hw_params.hw_ops->set_coverage_class) {
4935                spin_lock_bh(&ar->data_lock);
4936
4937                /* This call only ensures that the modified coverage class
4938                 * persists in case the firmware sets the registers back to
4939                 * their default value. So calling it is only necessary if the
4940                 * coverage class has a non-zero value.
4941                 */
4942                if (ar->fw_coverage.coverage_class)
4943                        queue_work(ar->workqueue, &ar->set_coverage_class_work);
4944
4945                spin_unlock_bh(&ar->data_lock);
4946        }
4947}
4948
4949static void ath10k_wmi_op_rx(struct ath10k *ar, struct sk_buff *skb)
4950{
4951        struct wmi_cmd_hdr *cmd_hdr;
4952        enum wmi_event_id id;
4953
4954        cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
4955        id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
4956
4957        if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
4958                goto out;
4959
4960        trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
4961
4962        switch (id) {
4963        case WMI_MGMT_RX_EVENTID:
4964                ath10k_wmi_event_mgmt_rx(ar, skb);
4965                /* mgmt_rx() owns the skb now! */
4966                return;
4967        case WMI_SCAN_EVENTID:
4968                ath10k_wmi_event_scan(ar, skb);
4969                ath10k_wmi_queue_set_coverage_class_work(ar);
4970                break;
4971        case WMI_CHAN_INFO_EVENTID:
4972                ath10k_wmi_event_chan_info(ar, skb);
4973                break;
4974        case WMI_ECHO_EVENTID:
4975                ath10k_wmi_event_echo(ar, skb);
4976                break;
4977        case WMI_DEBUG_MESG_EVENTID:
4978                ath10k_wmi_event_debug_mesg(ar, skb);
4979                ath10k_wmi_queue_set_coverage_class_work(ar);
4980                break;
4981        case WMI_UPDATE_STATS_EVENTID:
4982                ath10k_wmi_event_update_stats(ar, skb);
4983                break;
4984        case WMI_VDEV_START_RESP_EVENTID:
4985                ath10k_wmi_event_vdev_start_resp(ar, skb);
4986                ath10k_wmi_queue_set_coverage_class_work(ar);
4987                break;
4988        case WMI_VDEV_STOPPED_EVENTID:
4989                ath10k_wmi_event_vdev_stopped(ar, skb);
4990                ath10k_wmi_queue_set_coverage_class_work(ar);
4991                break;
4992        case WMI_PEER_STA_KICKOUT_EVENTID:
4993                ath10k_wmi_event_peer_sta_kickout(ar, skb);
4994                break;
4995        case WMI_HOST_SWBA_EVENTID:
4996                ath10k_wmi_event_host_swba(ar, skb);
4997                break;
4998        case WMI_TBTTOFFSET_UPDATE_EVENTID:
4999                ath10k_wmi_event_tbttoffset_update(ar, skb);
5000                break;
5001        case WMI_PHYERR_EVENTID:
5002                ath10k_wmi_event_phyerr(ar, skb);
5003                break;
5004        case WMI_ROAM_EVENTID:
5005                ath10k_wmi_event_roam(ar, skb);
5006                ath10k_wmi_queue_set_coverage_class_work(ar);
5007                break;
5008        case WMI_PROFILE_MATCH:
5009                ath10k_wmi_event_profile_match(ar, skb);
5010                break;
5011        case WMI_DEBUG_PRINT_EVENTID:
5012                ath10k_wmi_event_debug_print(ar, skb);
5013                ath10k_wmi_queue_set_coverage_class_work(ar);
5014                break;
5015        case WMI_PDEV_QVIT_EVENTID:
5016                ath10k_wmi_event_pdev_qvit(ar, skb);
5017                break;
5018        case WMI_WLAN_PROFILE_DATA_EVENTID:
5019                ath10k_wmi_event_wlan_profile_data(ar, skb);
5020                break;
5021        case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
5022                ath10k_wmi_event_rtt_measurement_report(ar, skb);
5023                break;
5024        case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
5025                ath10k_wmi_event_tsf_measurement_report(ar, skb);
5026                break;
5027        case WMI_RTT_ERROR_REPORT_EVENTID:
5028                ath10k_wmi_event_rtt_error_report(ar, skb);
5029                break;
5030        case WMI_WOW_WAKEUP_HOST_EVENTID:
5031                ath10k_wmi_event_wow_wakeup_host(ar, skb);
5032                break;
5033        case WMI_DCS_INTERFERENCE_EVENTID:
5034                ath10k_wmi_event_dcs_interference(ar, skb);
5035                break;
5036        case WMI_PDEV_TPC_CONFIG_EVENTID:
5037                ath10k_wmi_event_pdev_tpc_config(ar, skb);
5038                break;
5039        case WMI_PDEV_FTM_INTG_EVENTID:
5040                ath10k_wmi_event_pdev_ftm_intg(ar, skb);
5041                break;
5042        case WMI_GTK_OFFLOAD_STATUS_EVENTID:
5043                ath10k_wmi_event_gtk_offload_status(ar, skb);
5044                break;
5045        case WMI_GTK_REKEY_FAIL_EVENTID:
5046                ath10k_wmi_event_gtk_rekey_fail(ar, skb);
5047                break;
5048        case WMI_TX_DELBA_COMPLETE_EVENTID:
5049                ath10k_wmi_event_delba_complete(ar, skb);
5050                break;
5051        case WMI_TX_ADDBA_COMPLETE_EVENTID:
5052                ath10k_wmi_event_addba_complete(ar, skb);
5053                break;
5054        case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
5055                ath10k_wmi_event_vdev_install_key_complete(ar, skb);
5056                break;
5057        case WMI_SERVICE_READY_EVENTID:
5058                ath10k_wmi_event_service_ready(ar, skb);
5059                return;
5060        case WMI_READY_EVENTID:
5061                ath10k_wmi_event_ready(ar, skb);
5062                ath10k_wmi_queue_set_coverage_class_work(ar);
5063                break;
5064        default:
5065                ath10k_warn(ar, "Unknown eventid: %d\n", id);
5066                break;
5067        }
5068
5069out:
5070        dev_kfree_skb(skb);
5071}
5072
5073static void ath10k_wmi_10_1_op_rx(struct ath10k *ar, struct sk_buff *skb)
5074{
5075        struct wmi_cmd_hdr *cmd_hdr;
5076        enum wmi_10x_event_id id;
5077        bool consumed;
5078
5079        cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5080        id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5081
5082        if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5083                goto out;
5084
5085        trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5086
5087        consumed = ath10k_tm_event_wmi(ar, id, skb);
5088
5089        /* Ready event must be handled normally also in UTF mode so that we
5090         * know the UTF firmware has booted, others we are just bypass WMI
5091         * events to testmode.
5092         */
5093        if (consumed && id != WMI_10X_READY_EVENTID) {
5094                ath10k_dbg(ar, ATH10K_DBG_WMI,
5095                           "wmi testmode consumed 0x%x\n", id);
5096                goto out;
5097        }
5098
5099        switch (id) {
5100        case WMI_10X_MGMT_RX_EVENTID:
5101                ath10k_wmi_event_mgmt_rx(ar, skb);
5102                /* mgmt_rx() owns the skb now! */
5103                return;
5104        case WMI_10X_SCAN_EVENTID:
5105                ath10k_wmi_event_scan(ar, skb);
5106                ath10k_wmi_queue_set_coverage_class_work(ar);
5107                break;
5108        case WMI_10X_CHAN_INFO_EVENTID:
5109                ath10k_wmi_event_chan_info(ar, skb);
5110                break;
5111        case WMI_10X_ECHO_EVENTID:
5112                ath10k_wmi_event_echo(ar, skb);
5113                break;
5114        case WMI_10X_DEBUG_MESG_EVENTID:
5115                ath10k_wmi_event_debug_mesg(ar, skb);
5116                ath10k_wmi_queue_set_coverage_class_work(ar);
5117                break;
5118        case WMI_10X_UPDATE_STATS_EVENTID:
5119                ath10k_wmi_event_update_stats(ar, skb);
5120                break;
5121        case WMI_10X_VDEV_START_RESP_EVENTID:
5122                ath10k_wmi_event_vdev_start_resp(ar, skb);
5123                ath10k_wmi_queue_set_coverage_class_work(ar);
5124                break;
5125        case WMI_10X_VDEV_STOPPED_EVENTID:
5126                ath10k_wmi_event_vdev_stopped(ar, skb);
5127                ath10k_wmi_queue_set_coverage_class_work(ar);
5128                break;
5129        case WMI_10X_PEER_STA_KICKOUT_EVENTID:
5130                ath10k_wmi_event_peer_sta_kickout(ar, skb);
5131                break;
5132        case WMI_10X_HOST_SWBA_EVENTID:
5133                ath10k_wmi_event_host_swba(ar, skb);
5134                break;
5135        case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
5136                ath10k_wmi_event_tbttoffset_update(ar, skb);
5137                break;
5138        case WMI_10X_PHYERR_EVENTID:
5139                ath10k_wmi_event_phyerr(ar, skb);
5140                break;
5141        case WMI_10X_ROAM_EVENTID:
5142                ath10k_wmi_event_roam(ar, skb);
5143                ath10k_wmi_queue_set_coverage_class_work(ar);
5144                break;
5145        case WMI_10X_PROFILE_MATCH:
5146                ath10k_wmi_event_profile_match(ar, skb);
5147                break;
5148        case WMI_10X_DEBUG_PRINT_EVENTID:
5149                ath10k_wmi_event_debug_print(ar, skb);
5150                ath10k_wmi_queue_set_coverage_class_work(ar);
5151                break;
5152        case WMI_10X_PDEV_QVIT_EVENTID:
5153                ath10k_wmi_event_pdev_qvit(ar, skb);
5154                break;
5155        case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
5156                ath10k_wmi_event_wlan_profile_data(ar, skb);
5157                break;
5158        case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
5159                ath10k_wmi_event_rtt_measurement_report(ar, skb);
5160                break;
5161        case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
5162                ath10k_wmi_event_tsf_measurement_report(ar, skb);
5163                break;
5164        case WMI_10X_RTT_ERROR_REPORT_EVENTID:
5165                ath10k_wmi_event_rtt_error_report(ar, skb);
5166                break;
5167        case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
5168                ath10k_wmi_event_wow_wakeup_host(ar, skb);
5169                break;
5170        case WMI_10X_DCS_INTERFERENCE_EVENTID:
5171                ath10k_wmi_event_dcs_interference(ar, skb);
5172                break;
5173        case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
5174                ath10k_wmi_event_pdev_tpc_config(ar, skb);
5175                break;
5176        case WMI_10X_INST_RSSI_STATS_EVENTID:
5177                ath10k_wmi_event_inst_rssi_stats(ar, skb);
5178                break;
5179        case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
5180                ath10k_wmi_event_vdev_standby_req(ar, skb);
5181                break;
5182        case WMI_10X_VDEV_RESUME_REQ_EVENTID:
5183                ath10k_wmi_event_vdev_resume_req(ar, skb);
5184                break;
5185        case WMI_10X_SERVICE_READY_EVENTID:
5186                ath10k_wmi_event_service_ready(ar, skb);
5187                return;
5188        case WMI_10X_READY_EVENTID:
5189                ath10k_wmi_event_ready(ar, skb);
5190                ath10k_wmi_queue_set_coverage_class_work(ar);
5191                break;
5192        case WMI_10X_PDEV_UTF_EVENTID:
5193                /* ignore utf events */
5194                break;
5195        default:
5196                ath10k_warn(ar, "Unknown eventid: %d\n", id);
5197                break;
5198        }
5199
5200out:
5201        dev_kfree_skb(skb);
5202}
5203
5204static void ath10k_wmi_10_2_op_rx(struct ath10k *ar, struct sk_buff *skb)
5205{
5206        struct wmi_cmd_hdr *cmd_hdr;
5207        enum wmi_10_2_event_id id;
5208        bool consumed;
5209
5210        cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5211        id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5212
5213        if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5214                goto out;
5215
5216        trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5217
5218        consumed = ath10k_tm_event_wmi(ar, id, skb);
5219
5220        /* Ready event must be handled normally also in UTF mode so that we
5221         * know the UTF firmware has booted, others we are just bypass WMI
5222         * events to testmode.
5223         */
5224        if (consumed && id != WMI_10_2_READY_EVENTID) {
5225                ath10k_dbg(ar, ATH10K_DBG_WMI,
5226                           "wmi testmode consumed 0x%x\n", id);
5227                goto out;
5228        }
5229
5230        switch (id) {
5231        case WMI_10_2_MGMT_RX_EVENTID:
5232                ath10k_wmi_event_mgmt_rx(ar, skb);
5233                /* mgmt_rx() owns the skb now! */
5234                return;
5235        case WMI_10_2_SCAN_EVENTID:
5236                ath10k_wmi_event_scan(ar, skb);
5237                ath10k_wmi_queue_set_coverage_class_work(ar);
5238                break;
5239        case WMI_10_2_CHAN_INFO_EVENTID:
5240                ath10k_wmi_event_chan_info(ar, skb);
5241                break;
5242        case WMI_10_2_ECHO_EVENTID:
5243                ath10k_wmi_event_echo(ar, skb);
5244                break;
5245        case WMI_10_2_DEBUG_MESG_EVENTID:
5246                ath10k_wmi_event_debug_mesg(ar, skb);
5247                ath10k_wmi_queue_set_coverage_class_work(ar);
5248                break;
5249        case WMI_10_2_UPDATE_STATS_EVENTID:
5250                ath10k_wmi_event_update_stats(ar, skb);
5251                break;
5252        case WMI_10_2_VDEV_START_RESP_EVENTID:
5253                ath10k_wmi_event_vdev_start_resp(ar, skb);
5254                ath10k_wmi_queue_set_coverage_class_work(ar);
5255                break;
5256        case WMI_10_2_VDEV_STOPPED_EVENTID:
5257                ath10k_wmi_event_vdev_stopped(ar, skb);
5258                ath10k_wmi_queue_set_coverage_class_work(ar);
5259                break;
5260        case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
5261                ath10k_wmi_event_peer_sta_kickout(ar, skb);
5262                break;
5263        case WMI_10_2_HOST_SWBA_EVENTID:
5264                ath10k_wmi_event_host_swba(ar, skb);
5265                break;
5266        case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
5267                ath10k_wmi_event_tbttoffset_update(ar, skb);
5268                break;
5269        case WMI_10_2_PHYERR_EVENTID:
5270                ath10k_wmi_event_phyerr(ar, skb);
5271                break;
5272        case WMI_10_2_ROAM_EVENTID:
5273                ath10k_wmi_event_roam(ar, skb);
5274                ath10k_wmi_queue_set_coverage_class_work(ar);
5275                break;
5276        case WMI_10_2_PROFILE_MATCH:
5277                ath10k_wmi_event_profile_match(ar, skb);
5278                break;
5279        case WMI_10_2_DEBUG_PRINT_EVENTID:
5280                ath10k_wmi_event_debug_print(ar, skb);
5281                ath10k_wmi_queue_set_coverage_class_work(ar);
5282                break;
5283        case WMI_10_2_PDEV_QVIT_EVENTID:
5284                ath10k_wmi_event_pdev_qvit(ar, skb);
5285                break;
5286        case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
5287                ath10k_wmi_event_wlan_profile_data(ar, skb);
5288                break;
5289        case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
5290                ath10k_wmi_event_rtt_measurement_report(ar, skb);
5291                break;
5292        case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
5293                ath10k_wmi_event_tsf_measurement_report(ar, skb);
5294                break;
5295        case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
5296                ath10k_wmi_event_rtt_error_report(ar, skb);
5297                break;
5298        case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
5299                ath10k_wmi_event_wow_wakeup_host(ar, skb);
5300                break;
5301        case WMI_10_2_DCS_INTERFERENCE_EVENTID:
5302                ath10k_wmi_event_dcs_interference(ar, skb);
5303                break;
5304        case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
5305                ath10k_wmi_event_pdev_tpc_config(ar, skb);
5306                break;
5307        case WMI_10_2_INST_RSSI_STATS_EVENTID:
5308                ath10k_wmi_event_inst_rssi_stats(ar, skb);
5309                break;
5310        case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
5311                ath10k_wmi_event_vdev_standby_req(ar, skb);
5312                ath10k_wmi_queue_set_coverage_class_work(ar);
5313                break;
5314        case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
5315                ath10k_wmi_event_vdev_resume_req(ar, skb);
5316                ath10k_wmi_queue_set_coverage_class_work(ar);
5317                break;
5318        case WMI_10_2_SERVICE_READY_EVENTID:
5319                ath10k_wmi_event_service_ready(ar, skb);
5320                return;
5321        case WMI_10_2_READY_EVENTID:
5322                ath10k_wmi_event_ready(ar, skb);
5323                ath10k_wmi_queue_set_coverage_class_work(ar);
5324                break;
5325        case WMI_10_2_PDEV_TEMPERATURE_EVENTID:
5326                ath10k_wmi_event_temperature(ar, skb);
5327                break;
5328        case WMI_10_2_PDEV_BSS_CHAN_INFO_EVENTID:
5329                ath10k_wmi_event_pdev_bss_chan_info(ar, skb);
5330                break;
5331        case WMI_10_2_RTT_KEEPALIVE_EVENTID:
5332        case WMI_10_2_GPIO_INPUT_EVENTID:
5333        case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
5334        case WMI_10_2_GENERIC_BUFFER_EVENTID:
5335        case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
5336        case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
5337        case WMI_10_2_WDS_PEER_EVENTID:
5338                ath10k_dbg(ar, ATH10K_DBG_WMI,
5339                           "received event id %d not implemented\n", id);
5340                break;
5341        default:
5342                ath10k_warn(ar, "Unknown eventid: %d\n", id);
5343                break;
5344        }
5345
5346out:
5347        dev_kfree_skb(skb);
5348}
5349
5350static void ath10k_wmi_10_4_op_rx(struct ath10k *ar, struct sk_buff *skb)
5351{
5352        struct wmi_cmd_hdr *cmd_hdr;
5353        enum wmi_10_4_event_id id;
5354        bool consumed;
5355
5356        cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5357        id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5358
5359        if (!skb_pull(skb, sizeof(struct wmi_cmd_hdr)))
5360                goto out;
5361
5362        trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5363
5364        consumed = ath10k_tm_event_wmi(ar, id, skb);
5365
5366        /* Ready event must be handled normally also in UTF mode so that we
5367         * know the UTF firmware has booted, others we are just bypass WMI
5368         * events to testmode.
5369         */
5370        if (consumed && id != WMI_10_4_READY_EVENTID) {
5371                ath10k_dbg(ar, ATH10K_DBG_WMI,
5372                           "wmi testmode consumed 0x%x\n", id);
5373                goto out;
5374        }
5375
5376        switch (id) {
5377        case WMI_10_4_MGMT_RX_EVENTID:
5378                ath10k_wmi_event_mgmt_rx(ar, skb);
5379                /* mgmt_rx() owns the skb now! */
5380                return;
5381        case WMI_10_4_ECHO_EVENTID:
5382                ath10k_wmi_event_echo(ar, skb);
5383                break;
5384        case WMI_10_4_DEBUG_MESG_EVENTID:
5385                ath10k_wmi_event_debug_mesg(ar, skb);
5386                ath10k_wmi_queue_set_coverage_class_work(ar);
5387                break;
5388        case WMI_10_4_SERVICE_READY_EVENTID:
5389                ath10k_wmi_event_service_ready(ar, skb);
5390                return;
5391        case WMI_10_4_SCAN_EVENTID:
5392                ath10k_wmi_event_scan(ar, skb);
5393                ath10k_wmi_queue_set_coverage_class_work(ar);
5394                break;
5395        case WMI_10_4_CHAN_INFO_EVENTID:
5396                ath10k_wmi_event_chan_info(ar, skb);
5397                break;
5398        case WMI_10_4_PHYERR_EVENTID:
5399                ath10k_wmi_event_phyerr(ar, skb);
5400                break;
5401        case WMI_10_4_READY_EVENTID:
5402                ath10k_wmi_event_ready(ar, skb);
5403                ath10k_wmi_queue_set_coverage_class_work(ar);
5404                break;
5405        case WMI_10_4_PEER_STA_KICKOUT_EVENTID:
5406                ath10k_wmi_event_peer_sta_kickout(ar, skb);
5407                break;
5408        case WMI_10_4_ROAM_EVENTID:
5409                ath10k_wmi_event_roam(ar, skb);
5410                ath10k_wmi_queue_set_coverage_class_work(ar);
5411                break;
5412        case WMI_10_4_HOST_SWBA_EVENTID:
5413                ath10k_wmi_event_host_swba(ar, skb);
5414                break;
5415        case WMI_10_4_TBTTOFFSET_UPDATE_EVENTID:
5416                ath10k_wmi_event_tbttoffset_update(ar, skb);
5417                break;
5418        case WMI_10_4_DEBUG_PRINT_EVENTID:
5419                ath10k_wmi_event_debug_print(ar, skb);
5420                ath10k_wmi_queue_set_coverage_class_work(ar);
5421                break;
5422        case WMI_10_4_VDEV_START_RESP_EVENTID:
5423                ath10k_wmi_event_vdev_start_resp(ar, skb);
5424                ath10k_wmi_queue_set_coverage_class_work(ar);
5425                break;
5426        case WMI_10_4_VDEV_STOPPED_EVENTID:
5427                ath10k_wmi_event_vdev_stopped(ar, skb);
5428                ath10k_wmi_queue_set_coverage_class_work(ar);
5429                break;
5430        case WMI_10_4_WOW_WAKEUP_HOST_EVENTID:
5431        case WMI_10_4_PEER_RATECODE_LIST_EVENTID:
5432        case WMI_10_4_WDS_PEER_EVENTID:
5433                ath10k_dbg(ar, ATH10K_DBG_WMI,
5434                           "received event id %d not implemented\n", id);
5435                break;
5436        case WMI_10_4_UPDATE_STATS_EVENTID:
5437                ath10k_wmi_event_update_stats(ar, skb);
5438                break;
5439        case WMI_10_4_PDEV_TEMPERATURE_EVENTID:
5440                ath10k_wmi_event_temperature(ar, skb);
5441                break;
5442        case WMI_10_4_PDEV_BSS_CHAN_INFO_EVENTID:
5443                ath10k_wmi_event_pdev_bss_chan_info(ar, skb);
5444                break;
5445        case WMI_10_4_PDEV_TPC_CONFIG_EVENTID:
5446                ath10k_wmi_event_pdev_tpc_config(ar, skb);
5447                break;
5448        default:
5449                ath10k_warn(ar, "Unknown eventid: %d\n", id);
5450                break;
5451        }
5452
5453out:
5454        dev_kfree_skb(skb);
5455}
5456
5457static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
5458{
5459        int ret;
5460
5461        ret = ath10k_wmi_rx(ar, skb);
5462        if (ret)
5463                ath10k_warn(ar, "failed to process wmi rx: %d\n", ret);
5464}
5465
5466int ath10k_wmi_connect(struct ath10k *ar)
5467{
5468        int status;
5469        struct ath10k_htc_svc_conn_req conn_req;
5470        struct ath10k_htc_svc_conn_resp conn_resp;
5471
5472        memset(&conn_req, 0, sizeof(conn_req));
5473        memset(&conn_resp, 0, sizeof(conn_resp));
5474
5475        /* these fields are the same for all service endpoints */
5476        conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
5477        conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
5478        conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
5479
5480        /* connect to control service */
5481        conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
5482
5483        status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
5484        if (status) {
5485                ath10k_warn(ar, "failed to connect to WMI CONTROL service status: %d\n",
5486                            status);
5487                return status;
5488        }
5489
5490        ar->wmi.eid = conn_resp.eid;
5491        return 0;
5492}
5493
5494static struct sk_buff *
5495ath10k_wmi_op_gen_pdev_set_rd(struct ath10k *ar, u16 rd, u16 rd2g, u16 rd5g,
5496                              u16 ctl2g, u16 ctl5g,
5497                              enum wmi_dfs_region dfs_reg)
5498{
5499        struct wmi_pdev_set_regdomain_cmd *cmd;
5500        struct sk_buff *skb;
5501
5502        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5503        if (!skb)
5504                return ERR_PTR(-ENOMEM);
5505
5506        cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
5507        cmd->reg_domain = __cpu_to_le32(rd);
5508        cmd->reg_domain_2G = __cpu_to_le32(rd2g);
5509        cmd->reg_domain_5G = __cpu_to_le32(rd5g);
5510        cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
5511        cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
5512
5513        ath10k_dbg(ar, ATH10K_DBG_WMI,
5514                   "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
5515                   rd, rd2g, rd5g, ctl2g, ctl5g);
5516        return skb;
5517}
5518
5519static struct sk_buff *
5520ath10k_wmi_10x_op_gen_pdev_set_rd(struct ath10k *ar, u16 rd, u16 rd2g, u16
5521                                  rd5g, u16 ctl2g, u16 ctl5g,
5522                                  enum wmi_dfs_region dfs_reg)
5523{
5524        struct wmi_pdev_set_regdomain_cmd_10x *cmd;
5525        struct sk_buff *skb;
5526
5527        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5528        if (!skb)
5529                return ERR_PTR(-ENOMEM);
5530
5531        cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
5532        cmd->reg_domain = __cpu_to_le32(rd);
5533        cmd->reg_domain_2G = __cpu_to_le32(rd2g);
5534        cmd->reg_domain_5G = __cpu_to_le32(rd5g);
5535        cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
5536        cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
5537        cmd->dfs_domain = __cpu_to_le32(dfs_reg);
5538
5539        ath10k_dbg(ar, ATH10K_DBG_WMI,
5540                   "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
5541                   rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
5542        return skb;
5543}
5544
5545static struct sk_buff *
5546ath10k_wmi_op_gen_pdev_suspend(struct ath10k *ar, u32 suspend_opt)
5547{
5548        struct wmi_pdev_suspend_cmd *cmd;
5549        struct sk_buff *skb;
5550
5551        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5552        if (!skb)
5553                return ERR_PTR(-ENOMEM);
5554
5555        cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
5556        cmd->suspend_opt = __cpu_to_le32(suspend_opt);
5557
5558        return skb;
5559}
5560
5561static struct sk_buff *
5562ath10k_wmi_op_gen_pdev_resume(struct ath10k *ar)
5563{
5564        struct sk_buff *skb;
5565
5566        skb = ath10k_wmi_alloc_skb(ar, 0);
5567        if (!skb)
5568                return ERR_PTR(-ENOMEM);
5569
5570        return skb;
5571}
5572
5573static struct sk_buff *
5574ath10k_wmi_op_gen_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
5575{
5576        struct wmi_pdev_set_param_cmd *cmd;
5577        struct sk_buff *skb;
5578
5579        if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
5580                ath10k_warn(ar, "pdev param %d not supported by firmware\n",
5581                            id);
5582                return ERR_PTR(-EOPNOTSUPP);
5583        }
5584
5585        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5586        if (!skb)
5587                return ERR_PTR(-ENOMEM);
5588
5589        cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
5590        cmd->param_id    = __cpu_to_le32(id);
5591        cmd->param_value = __cpu_to_le32(value);
5592
5593        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
5594                   id, value);
5595        return skb;
5596}
5597
5598void ath10k_wmi_put_host_mem_chunks(struct ath10k *ar,
5599                                    struct wmi_host_mem_chunks *chunks)
5600{
5601        struct host_memory_chunk *chunk;
5602        int i;
5603
5604        chunks->count = __cpu_to_le32(ar->wmi.num_mem_chunks);
5605
5606        for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
5607                chunk = &chunks->items[i];
5608                chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
5609                chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
5610                chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
5611
5612                ath10k_dbg(ar, ATH10K_DBG_WMI,
5613                           "wmi chunk %d len %d requested, addr 0x%llx\n",
5614                           i,
5615                           ar->wmi.mem_chunks[i].len,
5616                           (unsigned long long)ar->wmi.mem_chunks[i].paddr);
5617        }
5618}
5619
5620static struct sk_buff *ath10k_wmi_op_gen_init(struct ath10k *ar)
5621{
5622        struct wmi_init_cmd *cmd;
5623        struct sk_buff *buf;
5624        struct wmi_resource_config config = {};
5625        u32 len, val;
5626
5627        config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
5628        config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS);
5629        config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
5630
5631        config.num_offload_reorder_bufs =
5632                __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
5633
5634        config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
5635        config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
5636        config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
5637        config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
5638        config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
5639        config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
5640        config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
5641        config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
5642        config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
5643        config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
5644        config.scan_max_pending_reqs =
5645                __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
5646
5647        config.bmiss_offload_max_vdev =
5648                __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
5649
5650        config.roam_offload_max_vdev =
5651                __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
5652
5653        config.roam_offload_max_ap_profiles =
5654                __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
5655
5656        config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
5657        config.num_mcast_table_elems =
5658                __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
5659
5660        config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
5661        config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
5662        config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
5663        config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
5664        config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
5665
5666        val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
5667        config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
5668
5669        config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
5670
5671        config.gtk_offload_max_vdev =
5672                __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
5673
5674        config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
5675        config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
5676
5677        len = sizeof(*cmd) +
5678              (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5679
5680        buf = ath10k_wmi_alloc_skb(ar, len);
5681        if (!buf)
5682                return ERR_PTR(-ENOMEM);
5683
5684        cmd = (struct wmi_init_cmd *)buf->data;
5685
5686        memcpy(&cmd->resource_config, &config, sizeof(config));
5687        ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5688
5689        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n");
5690        return buf;
5691}
5692
5693static struct sk_buff *ath10k_wmi_10_1_op_gen_init(struct ath10k *ar)
5694{
5695        struct wmi_init_cmd_10x *cmd;
5696        struct sk_buff *buf;
5697        struct wmi_resource_config_10x config = {};
5698        u32 len, val;
5699
5700        config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
5701        config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
5702        config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
5703        config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
5704        config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
5705        config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
5706        config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
5707        config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5708        config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5709        config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5710        config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
5711        config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
5712        config.scan_max_pending_reqs =
5713                __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
5714
5715        config.bmiss_offload_max_vdev =
5716                __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
5717
5718        config.roam_offload_max_vdev =
5719                __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
5720
5721        config.roam_offload_max_ap_profiles =
5722                __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
5723
5724        config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
5725        config.num_mcast_table_elems =
5726                __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
5727
5728        config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
5729        config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
5730        config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
5731        config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
5732        config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
5733
5734        val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
5735        config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
5736
5737        config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
5738
5739        config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
5740        config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
5741
5742        len = sizeof(*cmd) +
5743              (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5744
5745        buf = ath10k_wmi_alloc_skb(ar, len);
5746        if (!buf)
5747                return ERR_PTR(-ENOMEM);
5748
5749        cmd = (struct wmi_init_cmd_10x *)buf->data;
5750
5751        memcpy(&cmd->resource_config, &config, sizeof(config));
5752        ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5753
5754        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n");
5755        return buf;
5756}
5757
5758static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar)
5759{
5760        struct wmi_init_cmd_10_2 *cmd;
5761        struct sk_buff *buf;
5762        struct wmi_resource_config_10x config = {};
5763        u32 len, val, features;
5764
5765        config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
5766        config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
5767
5768        if (ath10k_peer_stats_enabled(ar)) {
5769                config.num_peers = __cpu_to_le32(TARGET_10X_TX_STATS_NUM_PEERS);
5770                config.num_tids = __cpu_to_le32(TARGET_10X_TX_STATS_NUM_TIDS);
5771        } else {
5772                config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
5773                config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
5774        }
5775
5776        config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
5777        config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
5778        config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
5779        config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5780        config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5781        config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5782        config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
5783        config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
5784
5785        config.scan_max_pending_reqs =
5786                __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
5787
5788        config.bmiss_offload_max_vdev =
5789                __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
5790
5791        config.roam_offload_max_vdev =
5792                __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
5793
5794        config.roam_offload_max_ap_profiles =
5795                __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
5796
5797        config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
5798        config.num_mcast_table_elems =
5799                __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
5800
5801        config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
5802        config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
5803        config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
5804        config.dma_burst_size = __cpu_to_le32(TARGET_10_2_DMA_BURST_SIZE);
5805        config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
5806
5807        val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
5808        config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
5809
5810        config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
5811
5812        config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
5813        config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
5814
5815        len = sizeof(*cmd) +
5816              (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5817
5818        buf = ath10k_wmi_alloc_skb(ar, len);
5819        if (!buf)
5820                return ERR_PTR(-ENOMEM);
5821
5822        cmd = (struct wmi_init_cmd_10_2 *)buf->data;
5823
5824        features = WMI_10_2_RX_BATCH_MODE;
5825
5826        if (test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) &&
5827            test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
5828                features |= WMI_10_2_COEX_GPIO;
5829
5830        if (ath10k_peer_stats_enabled(ar))
5831                features |= WMI_10_2_PEER_STATS;
5832
5833        if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
5834                features |= WMI_10_2_BSS_CHAN_INFO;
5835
5836        cmd->resource_config.feature_mask = __cpu_to_le32(features);
5837
5838        memcpy(&cmd->resource_config.common, &config, sizeof(config));
5839        ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5840
5841        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n");
5842        return buf;
5843}
5844
5845static struct sk_buff *ath10k_wmi_10_4_op_gen_init(struct ath10k *ar)
5846{
5847        struct wmi_init_cmd_10_4 *cmd;
5848        struct sk_buff *buf;
5849        struct wmi_resource_config_10_4 config = {};
5850        u32 len;
5851
5852        config.num_vdevs = __cpu_to_le32(ar->max_num_vdevs);
5853        config.num_peers = __cpu_to_le32(ar->max_num_peers);
5854        config.num_active_peers = __cpu_to_le32(ar->num_active_peers);
5855        config.num_tids = __cpu_to_le32(ar->num_tids);
5856
5857        config.num_offload_peers = __cpu_to_le32(TARGET_10_4_NUM_OFFLOAD_PEERS);
5858        config.num_offload_reorder_buffs =
5859                        __cpu_to_le32(TARGET_10_4_NUM_OFFLOAD_REORDER_BUFFS);
5860        config.num_peer_keys  = __cpu_to_le32(TARGET_10_4_NUM_PEER_KEYS);
5861        config.ast_skid_limit = __cpu_to_le32(TARGET_10_4_AST_SKID_LIMIT);
5862        config.tx_chain_mask  = __cpu_to_le32(ar->hw_params.tx_chain_mask);
5863        config.rx_chain_mask  = __cpu_to_le32(ar->hw_params.rx_chain_mask);
5864
5865        config.rx_timeout_pri[0] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
5866        config.rx_timeout_pri[1] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
5867        config.rx_timeout_pri[2] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
5868        config.rx_timeout_pri[3] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_HI_PRI);
5869
5870        config.rx_decap_mode        = __cpu_to_le32(ar->wmi.rx_decap_mode);
5871        config.scan_max_pending_req = __cpu_to_le32(TARGET_10_4_SCAN_MAX_REQS);
5872        config.bmiss_offload_max_vdev =
5873                        __cpu_to_le32(TARGET_10_4_BMISS_OFFLOAD_MAX_VDEV);
5874        config.roam_offload_max_vdev  =
5875                        __cpu_to_le32(TARGET_10_4_ROAM_OFFLOAD_MAX_VDEV);
5876        config.roam_offload_max_ap_profiles =
5877                        __cpu_to_le32(TARGET_10_4_ROAM_OFFLOAD_MAX_PROFILES);
5878        config.num_mcast_groups = __cpu_to_le32(TARGET_10_4_NUM_MCAST_GROUPS);
5879        config.num_mcast_table_elems =
5880                        __cpu_to_le32(TARGET_10_4_NUM_MCAST_TABLE_ELEMS);
5881
5882        config.mcast2ucast_mode = __cpu_to_le32(TARGET_10_4_MCAST2UCAST_MODE);
5883        config.tx_dbg_log_size  = __cpu_to_le32(TARGET_10_4_TX_DBG_LOG_SIZE);
5884        config.num_wds_entries  = __cpu_to_le32(TARGET_10_4_NUM_WDS_ENTRIES);
5885        config.dma_burst_size   = __cpu_to_le32(TARGET_10_4_DMA_BURST_SIZE);
5886        config.mac_aggr_delim   = __cpu_to_le32(TARGET_10_4_MAC_AGGR_DELIM);
5887
5888        config.rx_skip_defrag_timeout_dup_detection_check =
5889          __cpu_to_le32(TARGET_10_4_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK);
5890
5891        config.vow_config = __cpu_to_le32(TARGET_10_4_VOW_CONFIG);
5892        config.gtk_offload_max_vdev =
5893                        __cpu_to_le32(TARGET_10_4_GTK_OFFLOAD_MAX_VDEV);
5894        config.num_msdu_desc = __cpu_to_le32(ar->htt.max_num_pending_tx);
5895        config.max_frag_entries = __cpu_to_le32(TARGET_10_4_11AC_TX_MAX_FRAGS);
5896        config.max_peer_ext_stats =
5897                        __cpu_to_le32(TARGET_10_4_MAX_PEER_EXT_STATS);
5898        config.smart_ant_cap = __cpu_to_le32(TARGET_10_4_SMART_ANT_CAP);
5899
5900        config.bk_minfree = __cpu_to_le32(TARGET_10_4_BK_MIN_FREE);
5901        config.be_minfree = __cpu_to_le32(TARGET_10_4_BE_MIN_FREE);
5902        config.vi_minfree = __cpu_to_le32(TARGET_10_4_VI_MIN_FREE);
5903        config.vo_minfree = __cpu_to_le32(TARGET_10_4_VO_MIN_FREE);
5904
5905        config.rx_batchmode = __cpu_to_le32(TARGET_10_4_RX_BATCH_MODE);
5906        config.tt_support =
5907                        __cpu_to_le32(TARGET_10_4_THERMAL_THROTTLING_CONFIG);
5908        config.atf_config = __cpu_to_le32(TARGET_10_4_ATF_CONFIG);
5909        config.iphdr_pad_config = __cpu_to_le32(TARGET_10_4_IPHDR_PAD_CONFIG);
5910        config.qwrap_config = __cpu_to_le32(TARGET_10_4_QWRAP_CONFIG);
5911
5912        len = sizeof(*cmd) +
5913              (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5914
5915        buf = ath10k_wmi_alloc_skb(ar, len);
5916        if (!buf)
5917                return ERR_PTR(-ENOMEM);
5918
5919        cmd = (struct wmi_init_cmd_10_4 *)buf->data;
5920        memcpy(&cmd->resource_config, &config, sizeof(config));
5921        ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5922
5923        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.4\n");
5924        return buf;
5925}
5926
5927int ath10k_wmi_start_scan_verify(const struct wmi_start_scan_arg *arg)
5928{
5929        if (arg->ie_len && !arg->ie)
5930                return -EINVAL;
5931        if (arg->n_channels && !arg->channels)
5932                return -EINVAL;
5933        if (arg->n_ssids && !arg->ssids)
5934                return -EINVAL;
5935        if (arg->n_bssids && !arg->bssids)
5936                return -EINVAL;
5937
5938        if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
5939                return -EINVAL;
5940        if (arg->n_channels > ARRAY_SIZE(arg->channels))
5941                return -EINVAL;
5942        if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
5943                return -EINVAL;
5944        if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
5945                return -EINVAL;
5946
5947        return 0;
5948}
5949
5950static size_t
5951ath10k_wmi_start_scan_tlvs_len(const struct wmi_start_scan_arg *arg)
5952{
5953        int len = 0;
5954
5955        if (arg->ie_len) {
5956                len += sizeof(struct wmi_ie_data);
5957                len += roundup(arg->ie_len, 4);
5958        }
5959
5960        if (arg->n_channels) {
5961                len += sizeof(struct wmi_chan_list);
5962                len += sizeof(__le32) * arg->n_channels;
5963        }
5964
5965        if (arg->n_ssids) {
5966                len += sizeof(struct wmi_ssid_list);
5967                len += sizeof(struct wmi_ssid) * arg->n_ssids;
5968        }
5969
5970        if (arg->n_bssids) {
5971                len += sizeof(struct wmi_bssid_list);
5972                len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
5973        }
5974
5975        return len;
5976}
5977
5978void ath10k_wmi_put_start_scan_common(struct wmi_start_scan_common *cmn,
5979                                      const struct wmi_start_scan_arg *arg)
5980{
5981        u32 scan_id;
5982        u32 scan_req_id;
5983
5984        scan_id  = WMI_HOST_SCAN_REQ_ID_PREFIX;
5985        scan_id |= arg->scan_id;
5986
5987        scan_req_id  = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
5988        scan_req_id |= arg->scan_req_id;
5989
5990        cmn->scan_id            = __cpu_to_le32(scan_id);
5991        cmn->scan_req_id        = __cpu_to_le32(scan_req_id);
5992        cmn->vdev_id            = __cpu_to_le32(arg->vdev_id);
5993        cmn->scan_priority      = __cpu_to_le32(arg->scan_priority);
5994        cmn->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
5995        cmn->dwell_time_active  = __cpu_to_le32(arg->dwell_time_active);
5996        cmn->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
5997        cmn->min_rest_time      = __cpu_to_le32(arg->min_rest_time);
5998        cmn->max_rest_time      = __cpu_to_le32(arg->max_rest_time);
5999        cmn->repeat_probe_time  = __cpu_to_le32(arg->repeat_probe_time);
6000        cmn->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
6001        cmn->idle_time          = __cpu_to_le32(arg->idle_time);
6002        cmn->max_scan_time      = __cpu_to_le32(arg->max_scan_time);
6003        cmn->probe_delay        = __cpu_to_le32(arg->probe_delay);
6004        cmn->scan_ctrl_flags    = __cpu_to_le32(arg->scan_ctrl_flags);
6005}
6006
6007static void
6008ath10k_wmi_put_start_scan_tlvs(struct wmi_start_scan_tlvs *tlvs,
6009                               const struct wmi_start_scan_arg *arg)
6010{
6011        struct wmi_ie_data *ie;
6012        struct wmi_chan_list *channels;
6013        struct wmi_ssid_list *ssids;
6014        struct wmi_bssid_list *bssids;
6015        void *ptr = tlvs->tlvs;
6016        int i;
6017
6018        if (arg->n_channels) {
6019                channels = ptr;
6020                channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
6021                channels->num_chan = __cpu_to_le32(arg->n_channels);
6022
6023                for (i = 0; i < arg->n_channels; i++)
6024                        channels->channel_list[i].freq =
6025                                __cpu_to_le16(arg->channels[i]);
6026
6027                ptr += sizeof(*channels);
6028                ptr += sizeof(__le32) * arg->n_channels;
6029        }
6030
6031        if (arg->n_ssids) {
6032                ssids = ptr;
6033                ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
6034                ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
6035
6036                for (i = 0; i < arg->n_ssids; i++) {
6037                        ssids->ssids[i].ssid_len =
6038                                __cpu_to_le32(arg->ssids[i].len);
6039                        memcpy(&ssids->ssids[i].ssid,
6040                               arg->ssids[i].ssid,
6041                               arg->ssids[i].len);
6042                }
6043
6044                ptr += sizeof(*ssids);
6045                ptr += sizeof(struct wmi_ssid) * arg->n_ssids;
6046        }
6047
6048        if (arg->n_bssids) {
6049                bssids = ptr;
6050                bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
6051                bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
6052
6053                for (i = 0; i < arg->n_bssids; i++)
6054                        ether_addr_copy(bssids->bssid_list[i].addr,
6055                                        arg->bssids[i].bssid);
6056
6057                ptr += sizeof(*bssids);
6058                ptr += sizeof(struct wmi_mac_addr) * arg->n_bssids;
6059        }
6060
6061        if (arg->ie_len) {
6062                ie = ptr;
6063                ie->tag = __cpu_to_le32(WMI_IE_TAG);
6064                ie->ie_len = __cpu_to_le32(arg->ie_len);
6065                memcpy(ie->ie_data, arg->ie, arg->ie_len);
6066
6067                ptr += sizeof(*ie);
6068                ptr += roundup(arg->ie_len, 4);
6069        }
6070}
6071
6072static struct sk_buff *
6073ath10k_wmi_op_gen_start_scan(struct ath10k *ar,
6074                             const struct wmi_start_scan_arg *arg)
6075{
6076        struct wmi_start_scan_cmd *cmd;
6077        struct sk_buff *skb;
6078        size_t len;
6079        int ret;
6080
6081        ret = ath10k_wmi_start_scan_verify(arg);
6082        if (ret)
6083                return ERR_PTR(ret);
6084
6085        len = sizeof(*cmd) + ath10k_wmi_start_scan_tlvs_len(arg);
6086        skb = ath10k_wmi_alloc_skb(ar, len);
6087        if (!skb)
6088                return ERR_PTR(-ENOMEM);
6089
6090        cmd = (struct wmi_start_scan_cmd *)skb->data;
6091
6092        ath10k_wmi_put_start_scan_common(&cmd->common, arg);
6093        ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
6094
6095        cmd->burst_duration_ms = __cpu_to_le32(0);
6096
6097        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n");
6098        return skb;
6099}
6100
6101static struct sk_buff *
6102ath10k_wmi_10x_op_gen_start_scan(struct ath10k *ar,
6103                                 const struct wmi_start_scan_arg *arg)
6104{
6105        struct wmi_10x_start_scan_cmd *cmd;
6106        struct sk_buff *skb;
6107        size_t len;
6108        int ret;
6109
6110        ret = ath10k_wmi_start_scan_verify(arg);
6111        if (ret)
6112                return ERR_PTR(ret);
6113
6114        len = sizeof(*cmd) + ath10k_wmi_start_scan_tlvs_len(arg);
6115        skb = ath10k_wmi_alloc_skb(ar, len);
6116        if (!skb)
6117                return ERR_PTR(-ENOMEM);
6118
6119        cmd = (struct wmi_10x_start_scan_cmd *)skb->data;
6120
6121        ath10k_wmi_put_start_scan_common(&cmd->common, arg);
6122        ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
6123
6124        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi 10x start scan\n");
6125        return skb;
6126}
6127
6128void ath10k_wmi_start_scan_init(struct ath10k *ar,
6129                                struct wmi_start_scan_arg *arg)
6130{
6131        /* setup commonly used values */
6132        arg->scan_req_id = 1;
6133        arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
6134        arg->dwell_time_active = 50;
6135        arg->dwell_time_passive = 150;
6136        arg->min_rest_time = 50;
6137        arg->max_rest_time = 500;
6138        arg->repeat_probe_time = 0;
6139        arg->probe_spacing_time = 0;
6140        arg->idle_time = 0;
6141        arg->max_scan_time = 20000;
6142        arg->probe_delay = 5;
6143        arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
6144                | WMI_SCAN_EVENT_COMPLETED
6145                | WMI_SCAN_EVENT_BSS_CHANNEL
6146                | WMI_SCAN_EVENT_FOREIGN_CHANNEL
6147                | WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT
6148                | WMI_SCAN_EVENT_DEQUEUED;
6149        arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
6150        arg->n_bssids = 1;
6151        arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
6152}
6153
6154static struct sk_buff *
6155ath10k_wmi_op_gen_stop_scan(struct ath10k *ar,
6156                            const struct wmi_stop_scan_arg *arg)
6157{
6158        struct wmi_stop_scan_cmd *cmd;
6159        struct sk_buff *skb;
6160        u32 scan_id;
6161        u32 req_id;
6162
6163        if (arg->req_id > 0xFFF)
6164                return ERR_PTR(-EINVAL);
6165        if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
6166                return ERR_PTR(-EINVAL);
6167
6168        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6169        if (!skb)
6170                return ERR_PTR(-ENOMEM);
6171
6172        scan_id = arg->u.scan_id;
6173        scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
6174
6175        req_id = arg->req_id;
6176        req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
6177
6178        cmd = (struct wmi_stop_scan_cmd *)skb->data;
6179        cmd->req_type    = __cpu_to_le32(arg->req_type);
6180        cmd->vdev_id     = __cpu_to_le32(arg->u.vdev_id);
6181        cmd->scan_id     = __cpu_to_le32(scan_id);
6182        cmd->scan_req_id = __cpu_to_le32(req_id);
6183
6184        ath10k_dbg(ar, ATH10K_DBG_WMI,
6185                   "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
6186                   arg->req_id, arg->req_type, arg->u.scan_id);
6187        return skb;
6188}
6189
6190static struct sk_buff *
6191ath10k_wmi_op_gen_vdev_create(struct ath10k *ar, u32 vdev_id,
6192                              enum wmi_vdev_type type,
6193                              enum wmi_vdev_subtype subtype,
6194                              const u8 macaddr[ETH_ALEN])
6195{
6196        struct wmi_vdev_create_cmd *cmd;
6197        struct sk_buff *skb;
6198
6199        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6200        if (!skb)
6201                return ERR_PTR(-ENOMEM);
6202
6203        cmd = (struct wmi_vdev_create_cmd *)skb->data;
6204        cmd->vdev_id      = __cpu_to_le32(vdev_id);
6205        cmd->vdev_type    = __cpu_to_le32(type);
6206        cmd->vdev_subtype = __cpu_to_le32(subtype);
6207        ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
6208
6209        ath10k_dbg(ar, ATH10K_DBG_WMI,
6210                   "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
6211                   vdev_id, type, subtype, macaddr);
6212        return skb;
6213}
6214
6215static struct sk_buff *
6216ath10k_wmi_op_gen_vdev_delete(struct ath10k *ar, u32 vdev_id)
6217{
6218        struct wmi_vdev_delete_cmd *cmd;
6219        struct sk_buff *skb;
6220
6221        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6222        if (!skb)
6223                return ERR_PTR(-ENOMEM);
6224
6225        cmd = (struct wmi_vdev_delete_cmd *)skb->data;
6226        cmd->vdev_id = __cpu_to_le32(vdev_id);
6227
6228        ath10k_dbg(ar, ATH10K_DBG_WMI,
6229                   "WMI vdev delete id %d\n", vdev_id);
6230        return skb;
6231}
6232
6233static struct sk_buff *
6234ath10k_wmi_op_gen_vdev_start(struct ath10k *ar,
6235                             const struct wmi_vdev_start_request_arg *arg,
6236                             bool restart)
6237{
6238        struct wmi_vdev_start_request_cmd *cmd;
6239        struct sk_buff *skb;
6240        const char *cmdname;
6241        u32 flags = 0;
6242
6243        if (WARN_ON(arg->hidden_ssid && !arg->ssid))
6244                return ERR_PTR(-EINVAL);
6245        if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
6246                return ERR_PTR(-EINVAL);
6247
6248        if (restart)
6249                cmdname = "restart";
6250        else
6251                cmdname = "start";
6252
6253        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6254        if (!skb)
6255                return ERR_PTR(-ENOMEM);
6256
6257        if (arg->hidden_ssid)
6258                flags |= WMI_VDEV_START_HIDDEN_SSID;
6259        if (arg->pmf_enabled)
6260                flags |= WMI_VDEV_START_PMF_ENABLED;
6261
6262        cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
6263        cmd->vdev_id         = __cpu_to_le32(arg->vdev_id);
6264        cmd->disable_hw_ack  = __cpu_to_le32(arg->disable_hw_ack);
6265        cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
6266        cmd->dtim_period     = __cpu_to_le32(arg->dtim_period);
6267        cmd->flags           = __cpu_to_le32(flags);
6268        cmd->bcn_tx_rate     = __cpu_to_le32(arg->bcn_tx_rate);
6269        cmd->bcn_tx_power    = __cpu_to_le32(arg->bcn_tx_power);
6270
6271        if (arg->ssid) {
6272                cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
6273                memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
6274        }
6275
6276        ath10k_wmi_put_wmi_channel(&cmd->chan, &arg->channel);
6277
6278        ath10k_dbg(ar, ATH10K_DBG_WMI,
6279                   "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n",
6280                   cmdname, arg->vdev_id,
6281                   flags, arg->channel.freq, arg->channel.mode,
6282                   cmd->chan.flags, arg->channel.max_power);
6283
6284        return skb;
6285}
6286
6287static struct sk_buff *
6288ath10k_wmi_op_gen_vdev_stop(struct ath10k *ar, u32 vdev_id)
6289{
6290        struct wmi_vdev_stop_cmd *cmd;
6291        struct sk_buff *skb;
6292
6293        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6294        if (!skb)
6295                return ERR_PTR(-ENOMEM);
6296
6297        cmd = (struct wmi_vdev_stop_cmd *)skb->data;
6298        cmd->vdev_id = __cpu_to_le32(vdev_id);
6299
6300        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
6301        return skb;
6302}
6303
6304static struct sk_buff *
6305ath10k_wmi_op_gen_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid,
6306                          const u8 *bssid)
6307{
6308        struct wmi_vdev_up_cmd *cmd;
6309        struct sk_buff *skb;
6310
6311        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6312        if (!skb)
6313                return ERR_PTR(-ENOMEM);
6314
6315        cmd = (struct wmi_vdev_up_cmd *)skb->data;
6316        cmd->vdev_id       = __cpu_to_le32(vdev_id);
6317        cmd->vdev_assoc_id = __cpu_to_le32(aid);
6318        ether_addr_copy(cmd->vdev_bssid.addr, bssid);
6319
6320        ath10k_dbg(ar, ATH10K_DBG_WMI,
6321                   "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
6322                   vdev_id, aid, bssid);
6323        return skb;
6324}
6325
6326static struct sk_buff *
6327ath10k_wmi_op_gen_vdev_down(struct ath10k *ar, u32 vdev_id)
6328{
6329        struct wmi_vdev_down_cmd *cmd;
6330        struct sk_buff *skb;
6331
6332        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6333        if (!skb)
6334                return ERR_PTR(-ENOMEM);
6335
6336        cmd = (struct wmi_vdev_down_cmd *)skb->data;
6337        cmd->vdev_id = __cpu_to_le32(vdev_id);
6338
6339        ath10k_dbg(ar, ATH10K_DBG_WMI,
6340                   "wmi mgmt vdev down id 0x%x\n", vdev_id);
6341        return skb;
6342}
6343
6344static struct sk_buff *
6345ath10k_wmi_op_gen_vdev_set_param(struct ath10k *ar, u32 vdev_id,
6346                                 u32 param_id, u32 param_value)
6347{
6348        struct wmi_vdev_set_param_cmd *cmd;
6349        struct sk_buff *skb;
6350
6351        if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
6352                ath10k_dbg(ar, ATH10K_DBG_WMI,
6353                           "vdev param %d not supported by firmware\n",
6354                            param_id);
6355                return ERR_PTR(-EOPNOTSUPP);
6356        }
6357
6358        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6359        if (!skb)
6360                return ERR_PTR(-ENOMEM);
6361
6362        cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
6363        cmd->vdev_id     = __cpu_to_le32(vdev_id);
6364        cmd->param_id    = __cpu_to_le32(param_id);
6365        cmd->param_value = __cpu_to_le32(param_value);
6366
6367        ath10k_dbg(ar, ATH10K_DBG_WMI,
6368                   "wmi vdev id 0x%x set param %d value %d\n",
6369                   vdev_id, param_id, param_value);
6370        return skb;
6371}
6372
6373static struct sk_buff *
6374ath10k_wmi_op_gen_vdev_install_key(struct ath10k *ar,
6375                                   const struct wmi_vdev_install_key_arg *arg)
6376{
6377        struct wmi_vdev_install_key_cmd *cmd;
6378        struct sk_buff *skb;
6379
6380        if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
6381                return ERR_PTR(-EINVAL);
6382        if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
6383                return ERR_PTR(-EINVAL);
6384
6385        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + arg->key_len);
6386        if (!skb)
6387                return ERR_PTR(-ENOMEM);
6388
6389        cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
6390        cmd->vdev_id       = __cpu_to_le32(arg->vdev_id);
6391        cmd->key_idx       = __cpu_to_le32(arg->key_idx);
6392        cmd->key_flags     = __cpu_to_le32(arg->key_flags);
6393        cmd->key_cipher    = __cpu_to_le32(arg->key_cipher);
6394        cmd->key_len       = __cpu_to_le32(arg->key_len);
6395        cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
6396        cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
6397
6398        if (arg->macaddr)
6399                ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
6400        if (arg->key_data)
6401                memcpy(cmd->key_data, arg->key_data, arg->key_len);
6402
6403        ath10k_dbg(ar, ATH10K_DBG_WMI,
6404                   "wmi vdev install key idx %d cipher %d len %d\n",
6405                   arg->key_idx, arg->key_cipher, arg->key_len);
6406        return skb;
6407}
6408
6409static struct sk_buff *
6410ath10k_wmi_op_gen_vdev_spectral_conf(struct ath10k *ar,
6411                                     const struct wmi_vdev_spectral_conf_arg *arg)
6412{
6413        struct wmi_vdev_spectral_conf_cmd *cmd;
6414        struct sk_buff *skb;
6415
6416        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6417        if (!skb)
6418                return ERR_PTR(-ENOMEM);
6419
6420        cmd = (struct wmi_vdev_spectral_conf_cmd *)skb->data;
6421        cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
6422        cmd->scan_count = __cpu_to_le32(arg->scan_count);
6423        cmd->scan_period = __cpu_to_le32(arg->scan_period);
6424        cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
6425        cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
6426        cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
6427        cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
6428        cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
6429        cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
6430        cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
6431        cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
6432        cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
6433        cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
6434        cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
6435        cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
6436        cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
6437        cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
6438        cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
6439        cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
6440
6441        return skb;
6442}
6443
6444static struct sk_buff *
6445ath10k_wmi_op_gen_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id,
6446                                       u32 trigger, u32 enable)
6447{
6448        struct wmi_vdev_spectral_enable_cmd *cmd;
6449        struct sk_buff *skb;
6450
6451        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6452        if (!skb)
6453                return ERR_PTR(-ENOMEM);
6454
6455        cmd = (struct wmi_vdev_spectral_enable_cmd *)skb->data;
6456        cmd->vdev_id = __cpu_to_le32(vdev_id);
6457        cmd->trigger_cmd = __cpu_to_le32(trigger);
6458        cmd->enable_cmd = __cpu_to_le32(enable);
6459
6460        return skb;
6461}
6462
6463static struct sk_buff *
6464ath10k_wmi_op_gen_peer_create(struct ath10k *ar, u32 vdev_id,
6465                              const u8 peer_addr[ETH_ALEN],
6466                              enum wmi_peer_type peer_type)
6467{
6468        struct wmi_peer_create_cmd *cmd;
6469        struct sk_buff *skb;
6470
6471        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6472        if (!skb)
6473                return ERR_PTR(-ENOMEM);
6474
6475        cmd = (struct wmi_peer_create_cmd *)skb->data;
6476        cmd->vdev_id = __cpu_to_le32(vdev_id);
6477        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6478
6479        ath10k_dbg(ar, ATH10K_DBG_WMI,
6480                   "wmi peer create vdev_id %d peer_addr %pM\n",
6481                   vdev_id, peer_addr);
6482        return skb;
6483}
6484
6485static struct sk_buff *
6486ath10k_wmi_op_gen_peer_delete(struct ath10k *ar, u32 vdev_id,
6487                              const u8 peer_addr[ETH_ALEN])
6488{
6489        struct wmi_peer_delete_cmd *cmd;
6490        struct sk_buff *skb;
6491
6492        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6493        if (!skb)
6494                return ERR_PTR(-ENOMEM);
6495
6496        cmd = (struct wmi_peer_delete_cmd *)skb->data;
6497        cmd->vdev_id = __cpu_to_le32(vdev_id);
6498        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6499
6500        ath10k_dbg(ar, ATH10K_DBG_WMI,
6501                   "wmi peer delete vdev_id %d peer_addr %pM\n",
6502                   vdev_id, peer_addr);
6503        return skb;
6504}
6505
6506static struct sk_buff *
6507ath10k_wmi_op_gen_peer_flush(struct ath10k *ar, u32 vdev_id,
6508                             const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
6509{
6510        struct wmi_peer_flush_tids_cmd *cmd;
6511        struct sk_buff *skb;
6512
6513        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6514        if (!skb)
6515                return ERR_PTR(-ENOMEM);
6516
6517        cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
6518        cmd->vdev_id         = __cpu_to_le32(vdev_id);
6519        cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
6520        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6521
6522        ath10k_dbg(ar, ATH10K_DBG_WMI,
6523                   "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
6524                   vdev_id, peer_addr, tid_bitmap);
6525        return skb;
6526}
6527
6528static struct sk_buff *
6529ath10k_wmi_op_gen_peer_set_param(struct ath10k *ar, u32 vdev_id,
6530                                 const u8 *peer_addr,
6531                                 enum wmi_peer_param param_id,
6532                                 u32 param_value)
6533{
6534        struct wmi_peer_set_param_cmd *cmd;
6535        struct sk_buff *skb;
6536
6537        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6538        if (!skb)
6539                return ERR_PTR(-ENOMEM);
6540
6541        cmd = (struct wmi_peer_set_param_cmd *)skb->data;
6542        cmd->vdev_id     = __cpu_to_le32(vdev_id);
6543        cmd->param_id    = __cpu_to_le32(param_id);
6544        cmd->param_value = __cpu_to_le32(param_value);
6545        ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6546
6547        ath10k_dbg(ar, ATH10K_DBG_WMI,
6548                   "wmi vdev %d peer 0x%pM set param %d value %d\n",
6549                   vdev_id, peer_addr, param_id, param_value);
6550        return skb;
6551}
6552
6553static struct sk_buff *
6554ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
6555                             enum wmi_sta_ps_mode psmode)
6556{
6557        struct wmi_sta_powersave_mode_cmd *cmd;
6558        struct sk_buff *skb;
6559
6560        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6561        if (!skb)
6562                return ERR_PTR(-ENOMEM);
6563
6564        cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
6565        cmd->vdev_id     = __cpu_to_le32(vdev_id);
6566        cmd->sta_ps_mode = __cpu_to_le32(psmode);
6567
6568        ath10k_dbg(ar, ATH10K_DBG_WMI,
6569                   "wmi set powersave id 0x%x mode %d\n",
6570                   vdev_id, psmode);
6571        return skb;
6572}
6573
6574static struct sk_buff *
6575ath10k_wmi_op_gen_set_sta_ps(struct ath10k *ar, u32 vdev_id,
6576                             enum wmi_sta_powersave_param param_id,
6577                             u32 value)
6578{
6579        struct wmi_sta_powersave_param_cmd *cmd;
6580        struct sk_buff *skb;
6581
6582        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6583        if (!skb)
6584                return ERR_PTR(-ENOMEM);
6585
6586        cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
6587        cmd->vdev_id     = __cpu_to_le32(vdev_id);
6588        cmd->param_id    = __cpu_to_le32(param_id);
6589        cmd->param_value = __cpu_to_le32(value);
6590
6591        ath10k_dbg(ar, ATH10K_DBG_WMI,
6592                   "wmi sta ps param vdev_id 0x%x param %d value %d\n",
6593                   vdev_id, param_id, value);
6594        return skb;
6595}
6596
6597static struct sk_buff *
6598ath10k_wmi_op_gen_set_ap_ps(struct ath10k *ar, u32 vdev_id, const u8 *mac,
6599                            enum wmi_ap_ps_peer_param param_id, u32 value)
6600{
6601        struct wmi_ap_ps_peer_cmd *cmd;
6602        struct sk_buff *skb;
6603
6604        if (!mac)
6605                return ERR_PTR(-EINVAL);
6606
6607        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6608        if (!skb)
6609                return ERR_PTR(-ENOMEM);
6610
6611        cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
6612        cmd->vdev_id = __cpu_to_le32(vdev_id);
6613        cmd->param_id = __cpu_to_le32(param_id);
6614        cmd->param_value = __cpu_to_le32(value);
6615        ether_addr_copy(cmd->peer_macaddr.addr, mac);
6616
6617        ath10k_dbg(ar, ATH10K_DBG_WMI,
6618                   "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
6619                   vdev_id, param_id, value, mac);
6620        return skb;
6621}
6622
6623static struct sk_buff *
6624ath10k_wmi_op_gen_scan_chan_list(struct ath10k *ar,
6625                                 const struct wmi_scan_chan_list_arg *arg)
6626{
6627        struct wmi_scan_chan_list_cmd *cmd;
6628        struct sk_buff *skb;
6629        struct wmi_channel_arg *ch;
6630        struct wmi_channel *ci;
6631        int len;
6632        int i;
6633
6634        len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
6635
6636        skb = ath10k_wmi_alloc_skb(ar, len);
6637        if (!skb)
6638                return ERR_PTR(-EINVAL);
6639
6640        cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
6641        cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
6642
6643        for (i = 0; i < arg->n_channels; i++) {
6644                ch = &arg->channels[i];
6645                ci = &cmd->chan_info[i];
6646
6647                ath10k_wmi_put_wmi_channel(ci, ch);
6648        }
6649
6650        return skb;
6651}
6652
6653static void
6654ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
6655                           const struct wmi_peer_assoc_complete_arg *arg)
6656{
6657        struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
6658
6659        cmd->vdev_id            = __cpu_to_le32(arg->vdev_id);
6660        cmd->peer_new_assoc     = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
6661        cmd->peer_associd       = __cpu_to_le32(arg->peer_aid);
6662        cmd->peer_flags         = __cpu_to_le32(arg->peer_flags);
6663        cmd->peer_caps          = __cpu_to_le32(arg->peer_caps);
6664        cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
6665        cmd->peer_ht_caps       = __cpu_to_le32(arg->peer_ht_caps);
6666        cmd->peer_max_mpdu      = __cpu_to_le32(arg->peer_max_mpdu);
6667        cmd->peer_mpdu_density  = __cpu_to_le32(arg->peer_mpdu_density);
6668        cmd->peer_rate_caps     = __cpu_to_le32(arg->peer_rate_caps);
6669        cmd->peer_nss           = __cpu_to_le32(arg->peer_num_spatial_streams);
6670        cmd->peer_vht_caps      = __cpu_to_le32(arg->peer_vht_caps);
6671        cmd->peer_phymode       = __cpu_to_le32(arg->peer_phymode);
6672
6673        ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
6674
6675        cmd->peer_legacy_rates.num_rates =
6676                __cpu_to_le32(arg->peer_legacy_rates.num_rates);
6677        memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
6678               arg->peer_legacy_rates.num_rates);
6679
6680        cmd->peer_ht_rates.num_rates =
6681                __cpu_to_le32(arg->peer_ht_rates.num_rates);
6682        memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
6683               arg->peer_ht_rates.num_rates);
6684
6685        cmd->peer_vht_rates.rx_max_rate =
6686                __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
6687        cmd->peer_vht_rates.rx_mcs_set =
6688                __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
6689        cmd->peer_vht_rates.tx_max_rate =
6690                __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
6691        cmd->peer_vht_rates.tx_mcs_set =
6692                __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
6693}
6694
6695static void
6696ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
6697                                const struct wmi_peer_assoc_complete_arg *arg)
6698{
6699        struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
6700
6701        ath10k_wmi_peer_assoc_fill(ar, buf, arg);
6702        memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
6703}
6704
6705static void
6706ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
6707                                const struct wmi_peer_assoc_complete_arg *arg)
6708{
6709        ath10k_wmi_peer_assoc_fill(ar, buf, arg);
6710}
6711
6712static void
6713ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
6714                                const struct wmi_peer_assoc_complete_arg *arg)
6715{
6716        struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
6717        int max_mcs, max_nss;
6718        u32 info0;
6719
6720        /* TODO: Is using max values okay with firmware? */
6721        max_mcs = 0xf;
6722        max_nss = 0xf;
6723
6724        info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
6725                SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
6726
6727        ath10k_wmi_peer_assoc_fill(ar, buf, arg);
6728        cmd->info0 = __cpu_to_le32(info0);
6729}
6730
6731static void
6732ath10k_wmi_peer_assoc_fill_10_4(struct ath10k *ar, void *buf,
6733                                const struct wmi_peer_assoc_complete_arg *arg)
6734{
6735        struct wmi_10_4_peer_assoc_complete_cmd *cmd = buf;
6736
6737        ath10k_wmi_peer_assoc_fill_10_2(ar, buf, arg);
6738        cmd->peer_bw_rxnss_override = 0;
6739}
6740
6741static int
6742ath10k_wmi_peer_assoc_check_arg(const struct wmi_peer_assoc_complete_arg *arg)
6743{
6744        if (arg->peer_mpdu_density > 16)
6745                return -EINVAL;
6746        if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
6747                return -EINVAL;
6748        if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
6749                return -EINVAL;
6750
6751        return 0;
6752}
6753
6754static struct sk_buff *
6755ath10k_wmi_op_gen_peer_assoc(struct ath10k *ar,
6756                             const struct wmi_peer_assoc_complete_arg *arg)
6757{
6758        size_t len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
6759        struct sk_buff *skb;
6760        int ret;
6761
6762        ret = ath10k_wmi_peer_assoc_check_arg(arg);
6763        if (ret)
6764                return ERR_PTR(ret);
6765
6766        skb = ath10k_wmi_alloc_skb(ar, len);
6767        if (!skb)
6768                return ERR_PTR(-ENOMEM);
6769
6770        ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
6771
6772        ath10k_dbg(ar, ATH10K_DBG_WMI,
6773                   "wmi peer assoc vdev %d addr %pM (%s)\n",
6774                   arg->vdev_id, arg->addr,
6775                   arg->peer_reassoc ? "reassociate" : "new");
6776        return skb;
6777}
6778
6779static struct sk_buff *
6780ath10k_wmi_10_1_op_gen_peer_assoc(struct ath10k *ar,
6781                                  const struct wmi_peer_assoc_complete_arg *arg)
6782{
6783        size_t len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
6784        struct sk_buff *skb;
6785        int ret;
6786
6787        ret = ath10k_wmi_peer_assoc_check_arg(arg);
6788        if (ret)
6789                return ERR_PTR(ret);
6790
6791        skb = ath10k_wmi_alloc_skb(ar, len);
6792        if (!skb)
6793                return ERR_PTR(-ENOMEM);
6794
6795        ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
6796
6797        ath10k_dbg(ar, ATH10K_DBG_WMI,
6798                   "wmi peer assoc vdev %d addr %pM (%s)\n",
6799                   arg->vdev_id, arg->addr,
6800                   arg->peer_reassoc ? "reassociate" : "new");
6801        return skb;
6802}
6803
6804static struct sk_buff *
6805ath10k_wmi_10_2_op_gen_peer_assoc(struct ath10k *ar,
6806                                  const struct wmi_peer_assoc_complete_arg *arg)
6807{
6808        size_t len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
6809        struct sk_buff *skb;
6810        int ret;
6811
6812        ret = ath10k_wmi_peer_assoc_check_arg(arg);
6813        if (ret)
6814                return ERR_PTR(ret);
6815
6816        skb = ath10k_wmi_alloc_skb(ar, len);
6817        if (!skb)
6818                return ERR_PTR(-ENOMEM);
6819
6820        ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
6821
6822        ath10k_dbg(ar, ATH10K_DBG_WMI,
6823                   "wmi peer assoc vdev %d addr %pM (%s)\n",
6824                   arg->vdev_id, arg->addr,
6825                   arg->peer_reassoc ? "reassociate" : "new");
6826        return skb;
6827}
6828
6829static struct sk_buff *
6830ath10k_wmi_10_4_op_gen_peer_assoc(struct ath10k *ar,
6831                                  const struct wmi_peer_assoc_complete_arg *arg)
6832{
6833        size_t len = sizeof(struct wmi_10_4_peer_assoc_complete_cmd);
6834        struct sk_buff *skb;
6835        int ret;
6836
6837        ret = ath10k_wmi_peer_assoc_check_arg(arg);
6838        if (ret)
6839                return ERR_PTR(ret);
6840
6841        skb = ath10k_wmi_alloc_skb(ar, len);
6842        if (!skb)
6843                return ERR_PTR(-ENOMEM);
6844
6845        ath10k_wmi_peer_assoc_fill_10_4(ar, skb->data, arg);
6846
6847        ath10k_dbg(ar, ATH10K_DBG_WMI,
6848                   "wmi peer assoc vdev %d addr %pM (%s)\n",
6849                   arg->vdev_id, arg->addr,
6850                   arg->peer_reassoc ? "reassociate" : "new");
6851        return skb;
6852}
6853
6854static struct sk_buff *
6855ath10k_wmi_10_2_op_gen_pdev_get_temperature(struct ath10k *ar)
6856{
6857        struct sk_buff *skb;
6858
6859        skb = ath10k_wmi_alloc_skb(ar, 0);
6860        if (!skb)
6861                return ERR_PTR(-ENOMEM);
6862
6863        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev get temperature\n");
6864        return skb;
6865}
6866
6867static struct sk_buff *
6868ath10k_wmi_10_2_op_gen_pdev_bss_chan_info(struct ath10k *ar,
6869                                          enum wmi_bss_survey_req_type type)
6870{
6871        struct wmi_pdev_chan_info_req_cmd *cmd;
6872        struct sk_buff *skb;
6873
6874        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6875        if (!skb)
6876                return ERR_PTR(-ENOMEM);
6877
6878        cmd = (struct wmi_pdev_chan_info_req_cmd *)skb->data;
6879        cmd->type = __cpu_to_le32(type);
6880
6881        ath10k_dbg(ar, ATH10K_DBG_WMI,
6882                   "wmi pdev bss info request type %d\n", type);
6883
6884        return skb;
6885}
6886
6887/* This function assumes the beacon is already DMA mapped */
6888static struct sk_buff *
6889ath10k_wmi_op_gen_beacon_dma(struct ath10k *ar, u32 vdev_id, const void *bcn,
6890                             size_t bcn_len, u32 bcn_paddr, bool dtim_zero,
6891                             bool deliver_cab)
6892{
6893        struct wmi_bcn_tx_ref_cmd *cmd;
6894        struct sk_buff *skb;
6895        struct ieee80211_hdr *hdr;
6896        u16 fc;
6897
6898        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6899        if (!skb)
6900                return ERR_PTR(-ENOMEM);
6901
6902        hdr = (struct ieee80211_hdr *)bcn;
6903        fc = le16_to_cpu(hdr->frame_control);
6904
6905        cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
6906        cmd->vdev_id = __cpu_to_le32(vdev_id);
6907        cmd->data_len = __cpu_to_le32(bcn_len);
6908        cmd->data_ptr = __cpu_to_le32(bcn_paddr);
6909        cmd->msdu_id = 0;
6910        cmd->frame_control = __cpu_to_le32(fc);
6911        cmd->flags = 0;
6912        cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
6913
6914        if (dtim_zero)
6915                cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
6916
6917        if (deliver_cab)
6918                cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
6919
6920        return skb;
6921}
6922
6923void ath10k_wmi_set_wmm_param(struct wmi_wmm_params *params,
6924                              const struct wmi_wmm_params_arg *arg)
6925{
6926        params->cwmin  = __cpu_to_le32(arg->cwmin);
6927        params->cwmax  = __cpu_to_le32(arg->cwmax);
6928        params->aifs   = __cpu_to_le32(arg->aifs);
6929        params->txop   = __cpu_to_le32(arg->txop);
6930        params->acm    = __cpu_to_le32(arg->acm);
6931        params->no_ack = __cpu_to_le32(arg->no_ack);
6932}
6933
6934static struct sk_buff *
6935ath10k_wmi_op_gen_pdev_set_wmm(struct ath10k *ar,
6936                               const struct wmi_wmm_params_all_arg *arg)
6937{
6938        struct wmi_pdev_set_wmm_params *cmd;
6939        struct sk_buff *skb;
6940
6941        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6942        if (!skb)
6943                return ERR_PTR(-ENOMEM);
6944
6945        cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
6946        ath10k_wmi_set_wmm_param(&cmd->ac_be, &arg->ac_be);
6947        ath10k_wmi_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
6948        ath10k_wmi_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
6949        ath10k_wmi_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
6950
6951        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
6952        return skb;
6953}
6954
6955static struct sk_buff *
6956ath10k_wmi_op_gen_request_stats(struct ath10k *ar, u32 stats_mask)
6957{
6958        struct wmi_request_stats_cmd *cmd;
6959        struct sk_buff *skb;
6960
6961        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6962        if (!skb)
6963                return ERR_PTR(-ENOMEM);
6964
6965        cmd = (struct wmi_request_stats_cmd *)skb->data;
6966        cmd->stats_id = __cpu_to_le32(stats_mask);
6967
6968        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi request stats 0x%08x\n",
6969                   stats_mask);
6970        return skb;
6971}
6972
6973static struct sk_buff *
6974ath10k_wmi_op_gen_force_fw_hang(struct ath10k *ar,
6975                                enum wmi_force_fw_hang_type type, u32 delay_ms)
6976{
6977        struct wmi_force_fw_hang_cmd *cmd;
6978        struct sk_buff *skb;
6979
6980        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6981        if (!skb)
6982                return ERR_PTR(-ENOMEM);
6983
6984        cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
6985        cmd->type = __cpu_to_le32(type);
6986        cmd->delay_ms = __cpu_to_le32(delay_ms);
6987
6988        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
6989                   type, delay_ms);
6990        return skb;
6991}
6992
6993static struct sk_buff *
6994ath10k_wmi_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
6995                             u32 log_level)
6996{
6997        struct wmi_dbglog_cfg_cmd *cmd;
6998        struct sk_buff *skb;
6999        u32 cfg;
7000
7001        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7002        if (!skb)
7003                return ERR_PTR(-ENOMEM);
7004
7005        cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
7006
7007        if (module_enable) {
7008                cfg = SM(log_level,
7009                         ATH10K_DBGLOG_CFG_LOG_LVL);
7010        } else {
7011                /* set back defaults, all modules with WARN level */
7012                cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
7013                         ATH10K_DBGLOG_CFG_LOG_LVL);
7014                module_enable = ~0;
7015        }
7016
7017        cmd->module_enable = __cpu_to_le32(module_enable);
7018        cmd->module_valid = __cpu_to_le32(~0);
7019        cmd->config_enable = __cpu_to_le32(cfg);
7020        cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
7021
7022        ath10k_dbg(ar, ATH10K_DBG_WMI,
7023                   "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
7024                   __le32_to_cpu(cmd->module_enable),
7025                   __le32_to_cpu(cmd->module_valid),
7026                   __le32_to_cpu(cmd->config_enable),
7027                   __le32_to_cpu(cmd->config_valid));
7028        return skb;
7029}
7030
7031static struct sk_buff *
7032ath10k_wmi_10_4_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
7033                                  u32 log_level)
7034{
7035        struct wmi_10_4_dbglog_cfg_cmd *cmd;
7036        struct sk_buff *skb;
7037        u32 cfg;
7038
7039        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7040        if (!skb)
7041                return ERR_PTR(-ENOMEM);
7042
7043        cmd = (struct wmi_10_4_dbglog_cfg_cmd *)skb->data;
7044
7045        if (module_enable) {
7046                cfg = SM(log_level,
7047                         ATH10K_DBGLOG_CFG_LOG_LVL);
7048        } else {
7049                /* set back defaults, all modules with WARN level */
7050                cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
7051                         ATH10K_DBGLOG_CFG_LOG_LVL);
7052                module_enable = ~0;
7053        }
7054
7055        cmd->module_enable = __cpu_to_le64(module_enable);
7056        cmd->module_valid = __cpu_to_le64(~0);
7057        cmd->config_enable = __cpu_to_le32(cfg);
7058        cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
7059
7060        ath10k_dbg(ar, ATH10K_DBG_WMI,
7061                   "wmi dbglog cfg modules 0x%016llx 0x%016llx config %08x %08x\n",
7062                   __le64_to_cpu(cmd->module_enable),
7063                   __le64_to_cpu(cmd->module_valid),
7064                   __le32_to_cpu(cmd->config_enable),
7065                   __le32_to_cpu(cmd->config_valid));
7066        return skb;
7067}
7068
7069static struct sk_buff *
7070ath10k_wmi_op_gen_pktlog_enable(struct ath10k *ar, u32 ev_bitmap)
7071{
7072        struct wmi_pdev_pktlog_enable_cmd *cmd;
7073        struct sk_buff *skb;
7074
7075        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7076        if (!skb)
7077                return ERR_PTR(-ENOMEM);
7078
7079        ev_bitmap &= ATH10K_PKTLOG_ANY;
7080
7081        cmd = (struct wmi_pdev_pktlog_enable_cmd *)skb->data;
7082        cmd->ev_bitmap = __cpu_to_le32(ev_bitmap);
7083
7084        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi enable pktlog filter 0x%08x\n",
7085                   ev_bitmap);
7086        return skb;
7087}
7088
7089static struct sk_buff *
7090ath10k_wmi_op_gen_pktlog_disable(struct ath10k *ar)
7091{
7092        struct sk_buff *skb;
7093
7094        skb = ath10k_wmi_alloc_skb(ar, 0);
7095        if (!skb)
7096                return ERR_PTR(-ENOMEM);
7097
7098        ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi disable pktlog\n");
7099        return skb;
7100}
7101
7102static struct sk_buff *
7103ath10k_wmi_op_gen_pdev_set_quiet_mode(struct ath10k *ar, u32 period,
7104                                      u32 duration, u32 next_offset,
7105                                      u32 enabled)
7106{
7107        struct wmi_pdev_set_quiet_cmd *cmd;
7108        struct sk_buff *skb;
7109
7110        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7111        if (!skb)
7112                return ERR_PTR(-ENOMEM);
7113
7114        cmd = (struct wmi_pdev_set_quiet_cmd *)skb->data;
7115        cmd->period = __cpu_to_le32(period);
7116        cmd->duration = __cpu_to_le32(duration);
7117        cmd->next_start = __cpu_to_le32(next_offset);
7118        cmd->enabled = __cpu_to_le32(enabled);
7119
7120        ath10k_dbg(ar, ATH10K_DBG_WMI,
7121                   "wmi quiet param: period %u duration %u enabled %d\n",
7122                   period, duration, enabled);
7123        return skb;
7124}
7125
7126static struct sk_buff *
7127ath10k_wmi_op_gen_addba_clear_resp(struct ath10k *ar, u32 vdev_id,
7128                                   const u8 *mac)
7129{
7130        struct wmi_addba_clear_resp_cmd *cmd;
7131        struct sk_buff *skb;
7132
7133        if (!mac)
7134                return ERR_PTR(-EINVAL);
7135
7136        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7137        if (!skb)
7138                return ERR_PTR(-ENOMEM);
7139
7140        cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
7141        cmd->vdev_id = __cpu_to_le32(vdev_id);
7142        ether_addr_copy(cmd->peer_macaddr.addr, mac);
7143
7144        ath10k_dbg(ar, ATH10K_DBG_WMI,
7145                   "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
7146                   vdev_id, mac);
7147        return skb;
7148}
7149
7150static struct sk_buff *
7151ath10k_wmi_op_gen_addba_send(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7152                             u32 tid, u32 buf_size)
7153{
7154        struct wmi_addba_send_cmd *cmd;
7155        struct sk_buff *skb;
7156
7157        if (!mac)
7158                return ERR_PTR(-EINVAL);
7159
7160        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7161        if (!skb)
7162                return ERR_PTR(-ENOMEM);
7163
7164        cmd = (struct wmi_addba_send_cmd *)skb->data;
7165        cmd->vdev_id = __cpu_to_le32(vdev_id);
7166        ether_addr_copy(cmd->peer_macaddr.addr, mac);
7167        cmd->tid = __cpu_to_le32(tid);
7168        cmd->buffersize = __cpu_to_le32(buf_size);
7169
7170        ath10k_dbg(ar, ATH10K_DBG_WMI,
7171                   "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
7172                   vdev_id, mac, tid, buf_size);
7173        return skb;
7174}
7175
7176static struct sk_buff *
7177ath10k_wmi_op_gen_addba_set_resp(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7178                                 u32 tid, u32 status)
7179{
7180        struct wmi_addba_setresponse_cmd *cmd;
7181        struct sk_buff *skb;
7182
7183        if (!mac)
7184                return ERR_PTR(-EINVAL);
7185
7186        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7187        if (!skb)
7188                return ERR_PTR(-ENOMEM);
7189
7190        cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
7191        cmd->vdev_id = __cpu_to_le32(vdev_id);
7192        ether_addr_copy(cmd->peer_macaddr.addr, mac);
7193        cmd->tid = __cpu_to_le32(tid);
7194        cmd->statuscode = __cpu_to_le32(status);
7195
7196        ath10k_dbg(ar, ATH10K_DBG_WMI,
7197                   "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
7198                   vdev_id, mac, tid, status);
7199        return skb;
7200}
7201
7202static struct sk_buff *
7203ath10k_wmi_op_gen_delba_send(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7204                             u32 tid, u32 initiator, u32 reason)
7205{
7206        struct wmi_delba_send_cmd *cmd;
7207        struct sk_buff *skb;
7208
7209        if (!mac)
7210                return ERR_PTR(-EINVAL);
7211
7212        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7213        if (!skb)
7214                return ERR_PTR(-ENOMEM);
7215
7216        cmd = (struct wmi_delba_send_cmd *)skb->data;
7217        cmd->vdev_id = __cpu_to_le32(vdev_id);
7218        ether_addr_copy(cmd->peer_macaddr.addr, mac);
7219        cmd->tid = __cpu_to_le32(tid);
7220        cmd->initiator = __cpu_to_le32(initiator);
7221        cmd->reasoncode = __cpu_to_le32(reason);
7222
7223        ath10k_dbg(ar, ATH10K_DBG_WMI,
7224                   "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
7225                   vdev_id, mac, tid, initiator, reason);
7226        return skb;
7227}
7228
7229static struct sk_buff *
7230ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config(struct ath10k *ar, u32 param)
7231{
7232        struct wmi_pdev_get_tpc_config_cmd *cmd;
7233        struct sk_buff *skb;
7234
7235        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7236        if (!skb)
7237                return ERR_PTR(-ENOMEM);
7238
7239        cmd = (struct wmi_pdev_get_tpc_config_cmd *)skb->data;
7240        cmd->param = __cpu_to_le32(param);
7241
7242        ath10k_dbg(ar, ATH10K_DBG_WMI,
7243                   "wmi pdev get tcp config param:%d\n", param);
7244        return skb;
7245}
7246
7247size_t ath10k_wmi_fw_stats_num_peers(struct list_head *head)
7248{
7249        struct ath10k_fw_stats_peer *i;
7250        size_t num = 0;
7251
7252        list_for_each_entry(i, head, list)
7253                ++num;
7254
7255        return num;
7256}
7257
7258size_t ath10k_wmi_fw_stats_num_vdevs(struct list_head *head)
7259{
7260        struct ath10k_fw_stats_vdev *i;
7261        size_t num = 0;
7262
7263        list_for_each_entry(i, head, list)
7264                ++num;
7265
7266        return num;
7267}
7268
7269static void
7270ath10k_wmi_fw_pdev_base_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7271                                   char *buf, u32 *length)
7272{
7273        u32 len = *length;
7274        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7275
7276        len += scnprintf(buf + len, buf_len - len, "\n");
7277        len += scnprintf(buf + len, buf_len - len, "%30s\n",
7278                        "ath10k PDEV stats");
7279        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7280                        "=================");
7281
7282        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7283                        "Channel noise floor", pdev->ch_noise_floor);
7284        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7285                        "Channel TX power", pdev->chan_tx_power);
7286        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7287                        "TX frame count", pdev->tx_frame_count);
7288        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7289                        "RX frame count", pdev->rx_frame_count);
7290        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7291                        "RX clear count", pdev->rx_clear_count);
7292        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7293                        "Cycle count", pdev->cycle_count);
7294        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7295                        "PHY error count", pdev->phy_err_count);
7296
7297        *length = len;
7298}
7299
7300static void
7301ath10k_wmi_fw_pdev_extra_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7302                                    char *buf, u32 *length)
7303{
7304        u32 len = *length;
7305        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7306
7307        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7308                        "RTS bad count", pdev->rts_bad);
7309        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7310                        "RTS good count", pdev->rts_good);
7311        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7312                        "FCS bad count", pdev->fcs_bad);
7313        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7314                        "No beacon count", pdev->no_beacons);
7315        len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7316                        "MIB int count", pdev->mib_int_count);
7317
7318        len += scnprintf(buf + len, buf_len - len, "\n");
7319        *length = len;
7320}
7321
7322static void
7323ath10k_wmi_fw_pdev_tx_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7324                                 char *buf, u32 *length)
7325{
7326        u32 len = *length;
7327        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7328
7329        len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
7330                         "ath10k PDEV TX stats");
7331        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7332                                 "=================");
7333
7334        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7335                         "HTT cookies queued", pdev->comp_queued);
7336        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7337                         "HTT cookies disp.", pdev->comp_delivered);
7338        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7339                         "MSDU queued", pdev->msdu_enqued);
7340        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7341                         "MPDU queued", pdev->mpdu_enqued);
7342        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7343                         "MSDUs dropped", pdev->wmm_drop);
7344        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7345                         "Local enqued", pdev->local_enqued);
7346        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7347                         "Local freed", pdev->local_freed);
7348        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7349                         "HW queued", pdev->hw_queued);
7350        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7351                         "PPDUs reaped", pdev->hw_reaped);
7352        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7353                         "Num underruns", pdev->underrun);
7354        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7355                         "PPDUs cleaned", pdev->tx_abort);
7356        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7357                         "MPDUs requed", pdev->mpdus_requed);
7358        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7359                         "Excessive retries", pdev->tx_ko);
7360        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7361                         "HW rate", pdev->data_rc);
7362        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7363                         "Sched self tiggers", pdev->self_triggers);
7364        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7365                         "Dropped due to SW retries",
7366                         pdev->sw_retry_failure);
7367        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7368                         "Illegal rate phy errors",
7369                         pdev->illgl_rate_phy_err);
7370        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7371                         "Pdev continuous xretry", pdev->pdev_cont_xretry);
7372        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7373                         "TX timeout", pdev->pdev_tx_timeout);
7374        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7375                         "PDEV resets", pdev->pdev_resets);
7376        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7377                         "PHY underrun", pdev->phy_underrun);
7378        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7379                         "MPDU is more than txop limit", pdev->txop_ovf);
7380        *length = len;
7381}
7382
7383static void
7384ath10k_wmi_fw_pdev_rx_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7385                                 char *buf, u32 *length)
7386{
7387        u32 len = *length;
7388        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7389
7390        len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
7391                         "ath10k PDEV RX stats");
7392        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7393                                 "=================");
7394
7395        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7396                         "Mid PPDU route change",
7397                         pdev->mid_ppdu_route_change);
7398        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7399                         "Tot. number of statuses", pdev->status_rcvd);
7400        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7401                         "Extra frags on rings 0", pdev->r0_frags);
7402        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7403                         "Extra frags on rings 1", pdev->r1_frags);
7404        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7405                         "Extra frags on rings 2", pdev->r2_frags);
7406        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7407                         "Extra frags on rings 3", pdev->r3_frags);
7408        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7409                         "MSDUs delivered to HTT", pdev->htt_msdus);
7410        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7411                         "MPDUs delivered to HTT", pdev->htt_mpdus);
7412        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7413                         "MSDUs delivered to stack", pdev->loc_msdus);
7414        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7415                         "MPDUs delivered to stack", pdev->loc_mpdus);
7416        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7417                         "Oversized AMSUs", pdev->oversize_amsdu);
7418        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7419                         "PHY errors", pdev->phy_errs);
7420        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7421                         "PHY errors drops", pdev->phy_err_drop);
7422        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7423                         "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
7424        *length = len;
7425}
7426
7427static void
7428ath10k_wmi_fw_vdev_stats_fill(const struct ath10k_fw_stats_vdev *vdev,
7429                              char *buf, u32 *length)
7430{
7431        u32 len = *length;
7432        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7433        int i;
7434
7435        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7436                        "vdev id", vdev->vdev_id);
7437        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7438                        "beacon snr", vdev->beacon_snr);
7439        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7440                        "data snr", vdev->data_snr);
7441        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7442                        "num rx frames", vdev->num_rx_frames);
7443        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7444                        "num rts fail", vdev->num_rts_fail);
7445        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7446                        "num rts success", vdev->num_rts_success);
7447        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7448                        "num rx err", vdev->num_rx_err);
7449        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7450                        "num rx discard", vdev->num_rx_discard);
7451        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7452                        "num tx not acked", vdev->num_tx_not_acked);
7453
7454        for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
7455                len += scnprintf(buf + len, buf_len - len,
7456                                "%25s [%02d] %u\n",
7457                                "num tx frames", i,
7458                                vdev->num_tx_frames[i]);
7459
7460        for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
7461                len += scnprintf(buf + len, buf_len - len,
7462                                "%25s [%02d] %u\n",
7463                                "num tx frames retries", i,
7464                                vdev->num_tx_frames_retries[i]);
7465
7466        for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
7467                len += scnprintf(buf + len, buf_len - len,
7468                                "%25s [%02d] %u\n",
7469                                "num tx frames failures", i,
7470                                vdev->num_tx_frames_failures[i]);
7471
7472        for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
7473                len += scnprintf(buf + len, buf_len - len,
7474                                "%25s [%02d] 0x%08x\n",
7475                                "tx rate history", i,
7476                                vdev->tx_rate_history[i]);
7477
7478        for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
7479                len += scnprintf(buf + len, buf_len - len,
7480                                "%25s [%02d] %u\n",
7481                                "beacon rssi history", i,
7482                                vdev->beacon_rssi_history[i]);
7483
7484        len += scnprintf(buf + len, buf_len - len, "\n");
7485        *length = len;
7486}
7487
7488static void
7489ath10k_wmi_fw_peer_stats_fill(const struct ath10k_fw_stats_peer *peer,
7490                              char *buf, u32 *length)
7491{
7492        u32 len = *length;
7493        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7494
7495        len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
7496                        "Peer MAC address", peer->peer_macaddr);
7497        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7498                        "Peer RSSI", peer->peer_rssi);
7499        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7500                        "Peer TX rate", peer->peer_tx_rate);
7501        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7502                        "Peer RX rate", peer->peer_rx_rate);
7503        len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7504                        "Peer RX duration", peer->rx_duration);
7505
7506        len += scnprintf(buf + len, buf_len - len, "\n");
7507        *length = len;
7508}
7509
7510void ath10k_wmi_main_op_fw_stats_fill(struct ath10k *ar,
7511                                      struct ath10k_fw_stats *fw_stats,
7512                                      char *buf)
7513{
7514        u32 len = 0;
7515        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7516        const struct ath10k_fw_stats_pdev *pdev;
7517        const struct ath10k_fw_stats_vdev *vdev;
7518        const struct ath10k_fw_stats_peer *peer;
7519        size_t num_peers;
7520        size_t num_vdevs;
7521
7522        spin_lock_bh(&ar->data_lock);
7523
7524        pdev = list_first_entry_or_null(&fw_stats->pdevs,
7525                                        struct ath10k_fw_stats_pdev, list);
7526        if (!pdev) {
7527                ath10k_warn(ar, "failed to get pdev stats\n");
7528                goto unlock;
7529        }
7530
7531        num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
7532        num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
7533
7534        ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
7535        ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
7536        ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
7537
7538        len += scnprintf(buf + len, buf_len - len, "\n");
7539        len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7540                         "ath10k VDEV stats", num_vdevs);
7541        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7542                                 "=================");
7543
7544        list_for_each_entry(vdev, &fw_stats->vdevs, list) {
7545                ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
7546        }
7547
7548        len += scnprintf(buf + len, buf_len - len, "\n");
7549        len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7550                         "ath10k PEER stats", num_peers);
7551        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7552                                 "=================");
7553
7554        list_for_each_entry(peer, &fw_stats->peers, list) {
7555                ath10k_wmi_fw_peer_stats_fill(peer, buf, &len);
7556        }
7557
7558unlock:
7559        spin_unlock_bh(&ar->data_lock);
7560
7561        if (len >= buf_len)
7562                buf[len - 1] = 0;
7563        else
7564                buf[len] = 0;
7565}
7566
7567void ath10k_wmi_10x_op_fw_stats_fill(struct ath10k *ar,
7568                                     struct ath10k_fw_stats *fw_stats,
7569                                     char *buf)
7570{
7571        unsigned int len = 0;
7572        unsigned int buf_len = ATH10K_FW_STATS_BUF_SIZE;
7573        const struct ath10k_fw_stats_pdev *pdev;
7574        const struct ath10k_fw_stats_vdev *vdev;
7575        const struct ath10k_fw_stats_peer *peer;
7576        size_t num_peers;
7577        size_t num_vdevs;
7578
7579        spin_lock_bh(&ar->data_lock);
7580
7581        pdev = list_first_entry_or_null(&fw_stats->pdevs,
7582                                        struct ath10k_fw_stats_pdev, list);
7583        if (!pdev) {
7584                ath10k_warn(ar, "failed to get pdev stats\n");
7585                goto unlock;
7586        }
7587
7588        num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
7589        num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
7590
7591        ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
7592        ath10k_wmi_fw_pdev_extra_stats_fill(pdev, buf, &len);
7593        ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
7594        ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
7595
7596        len += scnprintf(buf + len, buf_len - len, "\n");
7597        len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7598                         "ath10k VDEV stats", num_vdevs);
7599        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7600                                 "=================");
7601
7602        list_for_each_entry(vdev, &fw_stats->vdevs, list) {
7603                ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
7604        }
7605
7606        len += scnprintf(buf + len, buf_len - len, "\n");
7607        len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7608                         "ath10k PEER stats", num_peers);
7609        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7610                                 "=================");
7611
7612        list_for_each_entry(peer, &fw_stats->peers, list) {
7613                ath10k_wmi_fw_peer_stats_fill(peer, buf, &len);
7614        }
7615
7616unlock:
7617        spin_unlock_bh(&ar->data_lock);
7618
7619        if (len >= buf_len)
7620                buf[len - 1] = 0;
7621        else
7622                buf[len] = 0;
7623}
7624
7625static struct sk_buff *
7626ath10k_wmi_op_gen_pdev_enable_adaptive_cca(struct ath10k *ar, u8 enable,
7627                                           u32 detect_level, u32 detect_margin)
7628{
7629        struct wmi_pdev_set_adaptive_cca_params *cmd;
7630        struct sk_buff *skb;
7631
7632        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7633        if (!skb)
7634                return ERR_PTR(-ENOMEM);
7635
7636        cmd = (struct wmi_pdev_set_adaptive_cca_params *)skb->data;
7637        cmd->enable = __cpu_to_le32(enable);
7638        cmd->cca_detect_level = __cpu_to_le32(detect_level);
7639        cmd->cca_detect_margin = __cpu_to_le32(detect_margin);
7640
7641        ath10k_dbg(ar, ATH10K_DBG_WMI,
7642                   "wmi pdev set adaptive cca params enable:%d detection level:%d detection margin:%d\n",
7643                   enable, detect_level, detect_margin);
7644        return skb;
7645}
7646
7647void ath10k_wmi_10_4_op_fw_stats_fill(struct ath10k *ar,
7648                                      struct ath10k_fw_stats *fw_stats,
7649                                      char *buf)
7650{
7651        u32 len = 0;
7652        u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7653        const struct ath10k_fw_stats_pdev *pdev;
7654        const struct ath10k_fw_stats_vdev *vdev;
7655        const struct ath10k_fw_stats_peer *peer;
7656        size_t num_peers;
7657        size_t num_vdevs;
7658
7659        spin_lock_bh(&ar->data_lock);
7660
7661        pdev = list_first_entry_or_null(&fw_stats->pdevs,
7662                                        struct ath10k_fw_stats_pdev, list);
7663        if (!pdev) {
7664                ath10k_warn(ar, "failed to get pdev stats\n");
7665                goto unlock;
7666        }
7667
7668        num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
7669        num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
7670
7671        ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
7672        ath10k_wmi_fw_pdev_extra_stats_fill(pdev, buf, &len);
7673        ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
7674
7675        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7676                        "HW paused", pdev->hw_paused);
7677        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7678                        "Seqs posted", pdev->seq_posted);
7679        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7680                        "Seqs failed queueing", pdev->seq_failed_queueing);
7681        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7682                        "Seqs completed", pdev->seq_completed);
7683        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7684                        "Seqs restarted", pdev->seq_restarted);
7685        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7686                        "MU Seqs posted", pdev->mu_seq_posted);
7687        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7688                        "MPDUs SW flushed", pdev->mpdus_sw_flush);
7689        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7690                        "MPDUs HW filtered", pdev->mpdus_hw_filter);
7691        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7692                        "MPDUs truncated", pdev->mpdus_truncated);
7693        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7694                        "MPDUs receive no ACK", pdev->mpdus_ack_failed);
7695        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7696                        "MPDUs expired", pdev->mpdus_expired);
7697
7698        ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
7699        len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7700                        "Num Rx Overflow errors", pdev->rx_ovfl_errs);
7701
7702        len += scnprintf(buf + len, buf_len - len, "\n");
7703        len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7704                        "ath10k VDEV stats", num_vdevs);
7705        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7706                                "=================");
7707
7708        list_for_each_entry(vdev, &fw_stats->vdevs, list) {
7709                ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
7710        }
7711
7712        len += scnprintf(buf + len, buf_len - len, "\n");
7713        len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7714                        "ath10k PEER stats", num_peers);
7715        len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7716                                "=================");
7717
7718        list_for_each_entry(peer, &fw_stats->peers, list) {
7719                ath10k_wmi_fw_peer_stats_fill(peer, buf, &len);
7720        }
7721
7722unlock:
7723        spin_unlock_bh(&ar->data_lock);
7724
7725        if (len >= buf_len)
7726                buf[len - 1] = 0;
7727        else
7728                buf[len] = 0;
7729}
7730
7731int ath10k_wmi_op_get_vdev_subtype(struct ath10k *ar,
7732                                   enum wmi_vdev_subtype subtype)
7733{
7734        switch (subtype) {
7735        case WMI_VDEV_SUBTYPE_NONE:
7736                return WMI_VDEV_SUBTYPE_LEGACY_NONE;
7737        case WMI_VDEV_SUBTYPE_P2P_DEVICE:
7738                return WMI_VDEV_SUBTYPE_LEGACY_P2P_DEV;
7739        case WMI_VDEV_SUBTYPE_P2P_CLIENT:
7740                return WMI_VDEV_SUBTYPE_LEGACY_P2P_CLI;
7741        case WMI_VDEV_SUBTYPE_P2P_GO:
7742                return WMI_VDEV_SUBTYPE_LEGACY_P2P_GO;
7743        case WMI_VDEV_SUBTYPE_PROXY_STA:
7744                return WMI_VDEV_SUBTYPE_LEGACY_PROXY_STA;
7745        case WMI_VDEV_SUBTYPE_MESH_11S:
7746        case WMI_VDEV_SUBTYPE_MESH_NON_11S:
7747                return -ENOTSUPP;
7748        }
7749        return -ENOTSUPP;
7750}
7751
7752static int ath10k_wmi_10_2_4_op_get_vdev_subtype(struct ath10k *ar,
7753                                                 enum wmi_vdev_subtype subtype)
7754{
7755        switch (subtype) {
7756        case WMI_VDEV_SUBTYPE_NONE:
7757                return WMI_VDEV_SUBTYPE_10_2_4_NONE;
7758        case WMI_VDEV_SUBTYPE_P2P_DEVICE:
7759                return WMI_VDEV_SUBTYPE_10_2_4_P2P_DEV;
7760        case WMI_VDEV_SUBTYPE_P2P_CLIENT:
7761                return WMI_VDEV_SUBTYPE_10_2_4_P2P_CLI;
7762        case WMI_VDEV_SUBTYPE_P2P_GO:
7763                return WMI_VDEV_SUBTYPE_10_2_4_P2P_GO;
7764        case WMI_VDEV_SUBTYPE_PROXY_STA:
7765                return WMI_VDEV_SUBTYPE_10_2_4_PROXY_STA;
7766        case WMI_VDEV_SUBTYPE_MESH_11S:
7767                return WMI_VDEV_SUBTYPE_10_2_4_MESH_11S;
7768        case WMI_VDEV_SUBTYPE_MESH_NON_11S:
7769                return -ENOTSUPP;
7770        }
7771        return -ENOTSUPP;
7772}
7773
7774static int ath10k_wmi_10_4_op_get_vdev_subtype(struct ath10k *ar,
7775                                               enum wmi_vdev_subtype subtype)
7776{
7777        switch (subtype) {
7778        case WMI_VDEV_SUBTYPE_NONE:
7779                return WMI_VDEV_SUBTYPE_10_4_NONE;
7780        case WMI_VDEV_SUBTYPE_P2P_DEVICE:
7781                return WMI_VDEV_SUBTYPE_10_4_P2P_DEV;
7782        case WMI_VDEV_SUBTYPE_P2P_CLIENT:
7783                return WMI_VDEV_SUBTYPE_10_4_P2P_CLI;
7784        case WMI_VDEV_SUBTYPE_P2P_GO:
7785                return WMI_VDEV_SUBTYPE_10_4_P2P_GO;
7786        case WMI_VDEV_SUBTYPE_PROXY_STA:
7787                return WMI_VDEV_SUBTYPE_10_4_PROXY_STA;
7788        case WMI_VDEV_SUBTYPE_MESH_11S:
7789                return WMI_VDEV_SUBTYPE_10_4_MESH_11S;
7790        case WMI_VDEV_SUBTYPE_MESH_NON_11S:
7791                return WMI_VDEV_SUBTYPE_10_4_MESH_NON_11S;
7792        }
7793        return -ENOTSUPP;
7794}
7795
7796static struct sk_buff *
7797ath10k_wmi_10_4_ext_resource_config(struct ath10k *ar,
7798                                    enum wmi_host_platform_type type,
7799                                    u32 fw_feature_bitmap)
7800{
7801        struct wmi_ext_resource_config_10_4_cmd *cmd;
7802        struct sk_buff *skb;
7803
7804        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7805        if (!skb)
7806                return ERR_PTR(-ENOMEM);
7807
7808        cmd = (struct wmi_ext_resource_config_10_4_cmd *)skb->data;
7809        cmd->host_platform_config = __cpu_to_le32(type);
7810        cmd->fw_feature_bitmap = __cpu_to_le32(fw_feature_bitmap);
7811
7812        ath10k_dbg(ar, ATH10K_DBG_WMI,
7813                   "wmi ext resource config host type %d firmware feature bitmap %08x\n",
7814                   type, fw_feature_bitmap);
7815        return skb;
7816}
7817
7818static struct sk_buff *
7819ath10k_wmi_op_gen_echo(struct ath10k *ar, u32 value)
7820{
7821        struct wmi_echo_cmd *cmd;
7822        struct sk_buff *skb;
7823
7824        skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7825        if (!skb)
7826                return ERR_PTR(-ENOMEM);
7827
7828        cmd = (struct wmi_echo_cmd *)skb->data;
7829        cmd->value = cpu_to_le32(value);
7830
7831        ath10k_dbg(ar, ATH10K_DBG_WMI,
7832                   "wmi echo value 0x%08x\n", value);
7833        return skb;
7834}
7835
7836int
7837ath10k_wmi_barrier(struct ath10k *ar)
7838{
7839        int ret;
7840        int time_left;
7841
7842        spin_lock_bh(&ar->data_lock);
7843        reinit_completion(&ar->wmi.barrier);
7844        spin_unlock_bh(&ar->data_lock);
7845
7846        ret = ath10k_wmi_echo(ar, ATH10K_WMI_BARRIER_ECHO_ID);
7847        if (ret) {
7848                ath10k_warn(ar, "failed to submit wmi echo: %d\n", ret);
7849                return ret;
7850        }
7851
7852        time_left = wait_for_completion_timeout(&ar->wmi.barrier,
7853                                                ATH10K_WMI_BARRIER_TIMEOUT_HZ);
7854        if (!time_left)
7855                return -ETIMEDOUT;
7856
7857        return 0;
7858}
7859
7860static const struct wmi_ops wmi_ops = {
7861        .rx = ath10k_wmi_op_rx,
7862        .map_svc = wmi_main_svc_map,
7863
7864        .pull_scan = ath10k_wmi_op_pull_scan_ev,
7865        .pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
7866        .pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
7867        .pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
7868        .pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
7869        .pull_swba = ath10k_wmi_op_pull_swba_ev,
7870        .pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
7871        .pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
7872        .pull_svc_rdy = ath10k_wmi_main_op_pull_svc_rdy_ev,
7873        .pull_rdy = ath10k_wmi_op_pull_rdy_ev,
7874        .pull_fw_stats = ath10k_wmi_main_op_pull_fw_stats,
7875        .pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
7876        .pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
7877
7878        .gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
7879        .gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
7880        .gen_pdev_set_rd = ath10k_wmi_op_gen_pdev_set_rd,
7881        .gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
7882        .gen_init = ath10k_wmi_op_gen_init,
7883        .gen_start_scan = ath10k_wmi_op_gen_start_scan,
7884        .gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
7885        .gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
7886        .gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
7887        .gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
7888        .gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
7889        .gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
7890        .gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
7891        .gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
7892        .gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
7893        .gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
7894        .gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
7895        /* .gen_vdev_wmm_conf not implemented */
7896        .gen_peer_create = ath10k_wmi_op_gen_peer_create,
7897        .gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
7898        .gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
7899        .gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
7900        .gen_peer_assoc = ath10k_wmi_op_gen_peer_assoc,
7901        .gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
7902        .gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
7903        .gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
7904        .gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
7905        .gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
7906        .gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
7907        .gen_request_stats = ath10k_wmi_op_gen_request_stats,
7908        .gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
7909        .gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
7910        .gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
7911        .gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
7912        .gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
7913        .gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
7914        /* .gen_pdev_get_temperature not implemented */
7915        .gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
7916        .gen_addba_send = ath10k_wmi_op_gen_addba_send,
7917        .gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
7918        .gen_delba_send = ath10k_wmi_op_gen_delba_send,
7919        .fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
7920        .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
7921        .gen_echo = ath10k_wmi_op_gen_echo,
7922        /* .gen_bcn_tmpl not implemented */
7923        /* .gen_prb_tmpl not implemented */
7924        /* .gen_p2p_go_bcn_ie not implemented */
7925        /* .gen_adaptive_qcs not implemented */
7926        /* .gen_pdev_enable_adaptive_cca not implemented */
7927};
7928
7929static const struct wmi_ops wmi_10_1_ops = {
7930        .rx = ath10k_wmi_10_1_op_rx,
7931        .map_svc = wmi_10x_svc_map,
7932        .pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
7933        .pull_fw_stats = ath10k_wmi_10x_op_pull_fw_stats,
7934        .gen_init = ath10k_wmi_10_1_op_gen_init,
7935        .gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
7936        .gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
7937        .gen_peer_assoc = ath10k_wmi_10_1_op_gen_peer_assoc,
7938        /* .gen_pdev_get_temperature not implemented */
7939
7940        /* shared with main branch */
7941        .pull_scan = ath10k_wmi_op_pull_scan_ev,
7942        .pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
7943        .pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
7944        .pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
7945        .pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
7946        .pull_swba = ath10k_wmi_op_pull_swba_ev,
7947        .pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
7948        .pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
7949        .pull_rdy = ath10k_wmi_op_pull_rdy_ev,
7950        .pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
7951        .pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
7952
7953        .gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
7954        .gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
7955        .gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
7956        .gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
7957        .gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
7958        .gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
7959        .gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
7960        .gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
7961        .gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
7962        .gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
7963        .gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
7964        .gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
7965        .gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
7966        .gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
7967        /* .gen_vdev_wmm_conf not implemented */
7968        .gen_peer_create = ath10k_wmi_op_gen_peer_create,
7969        .gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
7970        .gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
7971        .gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
7972        .gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
7973        .gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
7974        .gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
7975        .gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
7976        .gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
7977        .gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
7978        .gen_request_stats = ath10k_wmi_op_gen_request_stats,
7979        .gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
7980        .gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
7981        .gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
7982        .gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
7983        .gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
7984        .gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
7985        .gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
7986        .gen_addba_send = ath10k_wmi_op_gen_addba_send,
7987        .gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
7988        .gen_delba_send = ath10k_wmi_op_gen_delba_send,
7989        .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
7990        .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
7991        .gen_echo = ath10k_wmi_op_gen_echo,
7992        /* .gen_bcn_tmpl not implemented */
7993        /* .gen_prb_tmpl not implemented */
7994        /* .gen_p2p_go_bcn_ie not implemented */
7995        /* .gen_adaptive_qcs not implemented */
7996        /* .gen_pdev_enable_adaptive_cca not implemented */
7997};
7998
7999static const struct wmi_ops wmi_10_2_ops = {
8000        .rx = ath10k_wmi_10_2_op_rx,
8001        .pull_fw_stats = ath10k_wmi_10_2_op_pull_fw_stats,
8002        .gen_init = ath10k_wmi_10_2_op_gen_init,
8003        .gen_peer_assoc = ath10k_wmi_10_2_op_gen_peer_assoc,
8004        /* .gen_pdev_get_temperature not implemented */
8005
8006        /* shared with 10.1 */
8007        .map_svc = wmi_10x_svc_map,
8008        .pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
8009        .gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
8010        .gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
8011        .gen_echo = ath10k_wmi_op_gen_echo,
8012
8013        .pull_scan = ath10k_wmi_op_pull_scan_ev,
8014        .pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
8015        .pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
8016        .pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
8017        .pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
8018        .pull_swba = ath10k_wmi_op_pull_swba_ev,
8019        .pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
8020        .pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
8021        .pull_rdy = ath10k_wmi_op_pull_rdy_ev,
8022        .pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
8023        .pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
8024
8025        .gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
8026        .gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
8027        .gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
8028        .gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
8029        .gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
8030        .gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
8031        .gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
8032        .gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
8033        .gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
8034        .gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
8035        .gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
8036        .gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
8037        .gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
8038        .gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
8039        /* .gen_vdev_wmm_conf not implemented */
8040        .gen_peer_create = ath10k_wmi_op_gen_peer_create,
8041        .gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
8042        .gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
8043        .gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
8044        .gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
8045        .gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
8046        .gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
8047        .gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
8048        .gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
8049        .gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
8050        .gen_request_stats = ath10k_wmi_op_gen_request_stats,
8051        .gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
8052        .gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
8053        .gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
8054        .gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
8055        .gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
8056        .gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
8057        .gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
8058        .gen_addba_send = ath10k_wmi_op_gen_addba_send,
8059        .gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
8060        .gen_delba_send = ath10k_wmi_op_gen_delba_send,
8061        .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
8062        .get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
8063        /* .gen_pdev_enable_adaptive_cca not implemented */
8064};
8065
8066static const struct wmi_ops wmi_10_2_4_ops = {
8067        .rx = ath10k_wmi_10_2_op_rx,
8068        .pull_fw_stats = ath10k_wmi_10_2_4_op_pull_fw_stats,
8069        .gen_init = ath10k_wmi_10_2_op_gen_init,
8070        .gen_peer_assoc = ath10k_wmi_10_2_op_gen_peer_assoc,
8071        .gen_pdev_get_temperature = ath10k_wmi_10_2_op_gen_pdev_get_temperature,
8072        .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
8073
8074        /* shared with 10.1 */
8075        .map_svc = wmi_10x_svc_map,
8076        .pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
8077        .gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
8078        .gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
8079        .gen_echo = ath10k_wmi_op_gen_echo,
8080
8081        .pull_scan = ath10k_wmi_op_pull_scan_ev,
8082        .pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
8083        .pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
8084        .pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
8085        .pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
8086        .pull_swba = ath10k_wmi_10_2_4_op_pull_swba_ev,
8087        .pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
8088        .pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
8089        .pull_rdy = ath10k_wmi_op_pull_rdy_ev,
8090        .pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
8091        .pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
8092
8093        .gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
8094        .gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
8095        .gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
8096        .gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
8097        .gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
8098        .gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
8099        .gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
8100        .gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
8101        .gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
8102        .gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
8103        .gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
8104        .gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
8105        .gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
8106        .gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
8107        .gen_peer_create = ath10k_wmi_op_gen_peer_create,
8108        .gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
8109        .gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
8110        .gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
8111        .gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
8112        .gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
8113        .gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
8114        .gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
8115        .gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
8116        .gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
8117        .gen_request_stats = ath10k_wmi_op_gen_request_stats,
8118        .gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
8119        .gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
8120        .gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
8121        .gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
8122        .gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
8123        .gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
8124        .gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
8125        .gen_addba_send = ath10k_wmi_op_gen_addba_send,
8126        .gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
8127        .gen_delba_send = ath10k_wmi_op_gen_delba_send,
8128        .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
8129        .fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
8130        .gen_pdev_enable_adaptive_cca =
8131                ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
8132        .get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
8133        /* .gen_bcn_tmpl not implemented */
8134        /* .gen_prb_tmpl not implemented */
8135        /* .gen_p2p_go_bcn_ie not implemented */
8136        /* .gen_adaptive_qcs not implemented */
8137};
8138
8139static const struct wmi_ops wmi_10_4_ops = {
8140        .rx = ath10k_wmi_10_4_op_rx,
8141        .map_svc = wmi_10_4_svc_map,
8142
8143        .pull_fw_stats = ath10k_wmi_10_4_op_pull_fw_stats,
8144        .pull_scan = ath10k_wmi_op_pull_scan_ev,
8145        .pull_mgmt_rx = ath10k_wmi_10_4_op_pull_mgmt_rx_ev,
8146        .pull_ch_info = ath10k_wmi_10_4_op_pull_ch_info_ev,
8147        .pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
8148        .pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
8149        .pull_swba = ath10k_wmi_10_4_op_pull_swba_ev,
8150        .pull_phyerr_hdr = ath10k_wmi_10_4_op_pull_phyerr_ev_hdr,
8151        .pull_phyerr = ath10k_wmi_10_4_op_pull_phyerr_ev,
8152        .pull_svc_rdy = ath10k_wmi_main_op_pull_svc_rdy_ev,
8153        .pull_rdy = ath10k_wmi_op_pull_rdy_ev,
8154        .pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
8155        .get_txbf_conf_scheme = ath10k_wmi_10_4_txbf_conf_scheme,
8156
8157        .gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
8158        .gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
8159        .gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
8160        .gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
8161        .gen_init = ath10k_wmi_10_4_op_gen_init,
8162        .gen_start_scan = ath10k_wmi_op_gen_start_scan,
8163        .gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
8164        .gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
8165        .gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
8166        .gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
8167        .gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
8168        .gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
8169        .gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
8170        .gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
8171        .gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
8172        .gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
8173        .gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
8174        .gen_peer_create = ath10k_wmi_op_gen_peer_create,
8175        .gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
8176        .gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
8177        .gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
8178        .gen_peer_assoc = ath10k_wmi_10_4_op_gen_peer_assoc,
8179        .gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
8180        .gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
8181        .gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
8182        .gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
8183        .gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
8184        .gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
8185        .gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
8186        .gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
8187        .gen_dbglog_cfg = ath10k_wmi_10_4_op_gen_dbglog_cfg,
8188        .gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
8189        .gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
8190        .gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
8191        .gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
8192        .gen_addba_send = ath10k_wmi_op_gen_addba_send,
8193        .gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
8194        .gen_delba_send = ath10k_wmi_op_gen_delba_send,
8195        .fw_stats_fill = ath10k_wmi_10_4_op_fw_stats_fill,
8196        .ext_resource_config = ath10k_wmi_10_4_ext_resource_config,
8197
8198        /* shared with 10.2 */
8199        .pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
8200        .gen_request_stats = ath10k_wmi_op_gen_request_stats,
8201        .gen_pdev_get_temperature = ath10k_wmi_10_2_op_gen_pdev_get_temperature,
8202        .get_vdev_subtype = ath10k_wmi_10_4_op_get_vdev_subtype,
8203        .gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
8204        .gen_echo = ath10k_wmi_op_gen_echo,
8205        .gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
8206};
8207
8208int ath10k_wmi_attach(struct ath10k *ar)
8209{
8210        switch (ar->running_fw->fw_file.wmi_op_version) {
8211        case ATH10K_FW_WMI_OP_VERSION_10_4:
8212                ar->wmi.ops = &wmi_10_4_ops;
8213                ar->wmi.cmd = &wmi_10_4_cmd_map;
8214                ar->wmi.vdev_param = &wmi_10_4_vdev_param_map;
8215                ar->wmi.pdev_param = &wmi_10_4_pdev_param_map;
8216                ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
8217                break;
8218        case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8219                ar->wmi.cmd = &wmi_10_2_4_cmd_map;
8220                ar->wmi.ops = &wmi_10_2_4_ops;
8221                ar->wmi.vdev_param = &wmi_10_2_4_vdev_param_map;
8222                ar->wmi.pdev_param = &wmi_10_2_4_pdev_param_map;
8223                ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
8224                break;
8225        case ATH10K_FW_WMI_OP_VERSION_10_2:
8226                ar->wmi.cmd = &wmi_10_2_cmd_map;
8227                ar->wmi.ops = &wmi_10_2_ops;
8228                ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
8229                ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
8230                ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
8231                break;
8232        case ATH10K_FW_WMI_OP_VERSION_10_1:
8233                ar->wmi.cmd = &wmi_10x_cmd_map;
8234                ar->wmi.ops = &wmi_10_1_ops;
8235                ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
8236                ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
8237                ar->wmi.peer_flags = &wmi_10x_peer_flags_map;
8238                break;
8239        case ATH10K_FW_WMI_OP_VERSION_MAIN:
8240                ar->wmi.cmd = &wmi_cmd_map;
8241                ar->wmi.ops = &wmi_ops;
8242                ar->wmi.vdev_param = &wmi_vdev_param_map;
8243                ar->wmi.pdev_param = &wmi_pdev_param_map;
8244                ar->wmi.peer_flags = &wmi_peer_flags_map;
8245                break;
8246        case ATH10K_FW_WMI_OP_VERSION_TLV:
8247                ath10k_wmi_tlv_attach(ar);
8248                break;
8249        case ATH10K_FW_WMI_OP_VERSION_UNSET:
8250        case ATH10K_FW_WMI_OP_VERSION_MAX:
8251                ath10k_err(ar, "unsupported WMI op version: %d\n",
8252                           ar->running_fw->fw_file.wmi_op_version);
8253                return -EINVAL;
8254        }
8255
8256        init_completion(&ar->wmi.service_ready);
8257        init_completion(&ar->wmi.unified_ready);
8258        init_completion(&ar->wmi.barrier);
8259
8260        INIT_WORK(&ar->svc_rdy_work, ath10k_wmi_event_service_ready_work);
8261
8262        return 0;
8263}
8264
8265void ath10k_wmi_free_host_mem(struct ath10k *ar)
8266{
8267        int i;
8268
8269        /* free the host memory chunks requested by firmware */
8270        for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
8271                dma_unmap_single(ar->dev,
8272                                 ar->wmi.mem_chunks[i].paddr,
8273                                 ar->wmi.mem_chunks[i].len,
8274                                 DMA_BIDIRECTIONAL);
8275                kfree(ar->wmi.mem_chunks[i].vaddr);
8276        }
8277
8278        ar->wmi.num_mem_chunks = 0;
8279}
8280
8281void ath10k_wmi_detach(struct ath10k *ar)
8282{
8283        cancel_work_sync(&ar->svc_rdy_work);
8284
8285        if (ar->svc_rdy_skb)
8286                dev_kfree_skb(ar->svc_rdy_skb);
8287}
8288