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