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