Linux Audio

Check our new training course

Linux BSP development engineering services

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