xref: /openbmc/linux/drivers/net/wireless/ath/ath10k/wmi.c (revision 7bcae826)
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 	if (__le32_to_cpu(tim_info->tim_changed)) {
3215 		int i;
3216 
3217 		if (sizeof(arvif->u.ap.tim_bitmap) < tim_len) {
3218 			ath10k_warn(ar, "SWBA TIM field is too big (%u), truncated it to %zu",
3219 				    tim_len, sizeof(arvif->u.ap.tim_bitmap));
3220 			tim_len = sizeof(arvif->u.ap.tim_bitmap);
3221 		}
3222 
3223 		for (i = 0; i < tim_len; i++) {
3224 			t = tim_info->tim_bitmap[i / 4];
3225 			v = __le32_to_cpu(t);
3226 			arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
3227 		}
3228 
3229 		/* FW reports either length 0 or length based on max supported
3230 		 * station. so we calculate this on our own
3231 		 */
3232 		arvif->u.ap.tim_len = 0;
3233 		for (i = 0; i < tim_len; i++)
3234 			if (arvif->u.ap.tim_bitmap[i])
3235 				arvif->u.ap.tim_len = i;
3236 
3237 		arvif->u.ap.tim_len++;
3238 	}
3239 
3240 	ies = bcn->data;
3241 	ies += ieee80211_hdrlen(hdr->frame_control);
3242 	ies += 12; /* fixed parameters */
3243 
3244 	ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
3245 				    (u8 *)skb_tail_pointer(bcn) - ies);
3246 	if (!ie) {
3247 		if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3248 			ath10k_warn(ar, "no tim ie found;\n");
3249 		return;
3250 	}
3251 
3252 	tim = (void *)ie + 2;
3253 	ie_len = ie[1];
3254 	pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
3255 
3256 	if (pvm_len < arvif->u.ap.tim_len) {
3257 		int expand_size = tim_len - pvm_len;
3258 		int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
3259 		void *next_ie = ie + 2 + ie_len;
3260 
3261 		if (skb_put(bcn, expand_size)) {
3262 			memmove(next_ie + expand_size, next_ie, move_size);
3263 
3264 			ie[1] += expand_size;
3265 			ie_len += expand_size;
3266 			pvm_len += expand_size;
3267 		} else {
3268 			ath10k_warn(ar, "tim expansion failed\n");
3269 		}
3270 	}
3271 
3272 	if (pvm_len > tim_len) {
3273 		ath10k_warn(ar, "tim pvm length is too great (%d)\n", pvm_len);
3274 		return;
3275 	}
3276 
3277 	tim->bitmap_ctrl = !!__le32_to_cpu(tim_info->tim_mcast);
3278 	memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
3279 
3280 	if (tim->dtim_count == 0) {
3281 		ATH10K_SKB_CB(bcn)->flags |= ATH10K_SKB_F_DTIM_ZERO;
3282 
3283 		if (__le32_to_cpu(tim_info->tim_mcast) == 1)
3284 			ATH10K_SKB_CB(bcn)->flags |= ATH10K_SKB_F_DELIVER_CAB;
3285 	}
3286 
3287 	ath10k_dbg(ar, ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
3288 		   tim->dtim_count, tim->dtim_period,
3289 		   tim->bitmap_ctrl, pvm_len);
3290 }
3291 
3292 static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
3293 				  struct sk_buff *bcn,
3294 				  const struct wmi_p2p_noa_info *noa)
3295 {
3296 	if (!arvif->vif->p2p)
3297 		return;
3298 
3299 	ath10k_dbg(ar, ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
3300 
3301 	if (noa->changed & WMI_P2P_NOA_CHANGED_BIT)
3302 		ath10k_p2p_noa_update(arvif, noa);
3303 
3304 	if (arvif->u.ap.noa_data)
3305 		if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
3306 			memcpy(skb_put(bcn, arvif->u.ap.noa_len),
3307 			       arvif->u.ap.noa_data,
3308 			       arvif->u.ap.noa_len);
3309 }
3310 
3311 static int ath10k_wmi_op_pull_swba_ev(struct ath10k *ar, struct sk_buff *skb,
3312 				      struct wmi_swba_ev_arg *arg)
3313 {
3314 	struct wmi_host_swba_event *ev = (void *)skb->data;
3315 	u32 map;
3316 	size_t i;
3317 
3318 	if (skb->len < sizeof(*ev))
3319 		return -EPROTO;
3320 
3321 	skb_pull(skb, sizeof(*ev));
3322 	arg->vdev_map = ev->vdev_map;
3323 
3324 	for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3325 		if (!(map & BIT(0)))
3326 			continue;
3327 
3328 		/* If this happens there were some changes in firmware and
3329 		 * ath10k should update the max size of tim_info array.
3330 		 */
3331 		if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3332 			break;
3333 
3334 		if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3335 		     sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3336 			ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3337 			return -EPROTO;
3338 		}
3339 
3340 		arg->tim_info[i].tim_len = ev->bcn_info[i].tim_info.tim_len;
3341 		arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3342 		arg->tim_info[i].tim_bitmap =
3343 				ev->bcn_info[i].tim_info.tim_bitmap;
3344 		arg->tim_info[i].tim_changed =
3345 				ev->bcn_info[i].tim_info.tim_changed;
3346 		arg->tim_info[i].tim_num_ps_pending =
3347 				ev->bcn_info[i].tim_info.tim_num_ps_pending;
3348 
3349 		arg->noa_info[i] = &ev->bcn_info[i].p2p_noa_info;
3350 		i++;
3351 	}
3352 
3353 	return 0;
3354 }
3355 
3356 static int ath10k_wmi_10_2_4_op_pull_swba_ev(struct ath10k *ar,
3357 					     struct sk_buff *skb,
3358 					     struct wmi_swba_ev_arg *arg)
3359 {
3360 	struct wmi_10_2_4_host_swba_event *ev = (void *)skb->data;
3361 	u32 map;
3362 	size_t i;
3363 
3364 	if (skb->len < sizeof(*ev))
3365 		return -EPROTO;
3366 
3367 	skb_pull(skb, sizeof(*ev));
3368 	arg->vdev_map = ev->vdev_map;
3369 
3370 	for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3371 		if (!(map & BIT(0)))
3372 			continue;
3373 
3374 		/* If this happens there were some changes in firmware and
3375 		 * ath10k should update the max size of tim_info array.
3376 		 */
3377 		if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3378 			break;
3379 
3380 		if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3381 		     sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3382 			ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3383 			return -EPROTO;
3384 		}
3385 
3386 		arg->tim_info[i].tim_len = ev->bcn_info[i].tim_info.tim_len;
3387 		arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3388 		arg->tim_info[i].tim_bitmap =
3389 				ev->bcn_info[i].tim_info.tim_bitmap;
3390 		arg->tim_info[i].tim_changed =
3391 				ev->bcn_info[i].tim_info.tim_changed;
3392 		arg->tim_info[i].tim_num_ps_pending =
3393 				ev->bcn_info[i].tim_info.tim_num_ps_pending;
3394 		i++;
3395 	}
3396 
3397 	return 0;
3398 }
3399 
3400 static int ath10k_wmi_10_4_op_pull_swba_ev(struct ath10k *ar,
3401 					   struct sk_buff *skb,
3402 					   struct wmi_swba_ev_arg *arg)
3403 {
3404 	struct wmi_10_4_host_swba_event *ev = (void *)skb->data;
3405 	u32 map, tim_len;
3406 	size_t i;
3407 
3408 	if (skb->len < sizeof(*ev))
3409 		return -EPROTO;
3410 
3411 	skb_pull(skb, sizeof(*ev));
3412 	arg->vdev_map = ev->vdev_map;
3413 
3414 	for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3415 		if (!(map & BIT(0)))
3416 			continue;
3417 
3418 		/* If this happens there were some changes in firmware and
3419 		 * ath10k should update the max size of tim_info array.
3420 		 */
3421 		if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3422 			break;
3423 
3424 		if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3425 		      sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3426 			ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3427 			return -EPROTO;
3428 		}
3429 
3430 		tim_len = __le32_to_cpu(ev->bcn_info[i].tim_info.tim_len);
3431 		if (tim_len) {
3432 			/* Exclude 4 byte guard length */
3433 			tim_len -= 4;
3434 			arg->tim_info[i].tim_len = __cpu_to_le32(tim_len);
3435 		} else {
3436 			arg->tim_info[i].tim_len = 0;
3437 		}
3438 
3439 		arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3440 		arg->tim_info[i].tim_bitmap =
3441 				ev->bcn_info[i].tim_info.tim_bitmap;
3442 		arg->tim_info[i].tim_changed =
3443 				ev->bcn_info[i].tim_info.tim_changed;
3444 		arg->tim_info[i].tim_num_ps_pending =
3445 				ev->bcn_info[i].tim_info.tim_num_ps_pending;
3446 
3447 		/* 10.4 firmware doesn't have p2p support. notice of absence
3448 		 * info can be ignored for now.
3449 		 */
3450 
3451 		i++;
3452 	}
3453 
3454 	return 0;
3455 }
3456 
3457 static enum wmi_txbf_conf ath10k_wmi_10_4_txbf_conf_scheme(struct ath10k *ar)
3458 {
3459 	return WMI_TXBF_CONF_BEFORE_ASSOC;
3460 }
3461 
3462 void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
3463 {
3464 	struct wmi_swba_ev_arg arg = {};
3465 	u32 map;
3466 	int i = -1;
3467 	const struct wmi_tim_info_arg *tim_info;
3468 	const struct wmi_p2p_noa_info *noa_info;
3469 	struct ath10k_vif *arvif;
3470 	struct sk_buff *bcn;
3471 	dma_addr_t paddr;
3472 	int ret, vdev_id = 0;
3473 
3474 	ret = ath10k_wmi_pull_swba(ar, skb, &arg);
3475 	if (ret) {
3476 		ath10k_warn(ar, "failed to parse swba event: %d\n", ret);
3477 		return;
3478 	}
3479 
3480 	map = __le32_to_cpu(arg.vdev_map);
3481 
3482 	ath10k_dbg(ar, ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
3483 		   map);
3484 
3485 	for (; map; map >>= 1, vdev_id++) {
3486 		if (!(map & 0x1))
3487 			continue;
3488 
3489 		i++;
3490 
3491 		if (i >= WMI_MAX_AP_VDEV) {
3492 			ath10k_warn(ar, "swba has corrupted vdev map\n");
3493 			break;
3494 		}
3495 
3496 		tim_info = &arg.tim_info[i];
3497 		noa_info = arg.noa_info[i];
3498 
3499 		ath10k_dbg(ar, ATH10K_DBG_MGMT,
3500 			   "mgmt event bcn_info %d tim_len %d mcast %d changed %d num_ps_pending %d bitmap 0x%08x%08x%08x%08x\n",
3501 			   i,
3502 			   __le32_to_cpu(tim_info->tim_len),
3503 			   __le32_to_cpu(tim_info->tim_mcast),
3504 			   __le32_to_cpu(tim_info->tim_changed),
3505 			   __le32_to_cpu(tim_info->tim_num_ps_pending),
3506 			   __le32_to_cpu(tim_info->tim_bitmap[3]),
3507 			   __le32_to_cpu(tim_info->tim_bitmap[2]),
3508 			   __le32_to_cpu(tim_info->tim_bitmap[1]),
3509 			   __le32_to_cpu(tim_info->tim_bitmap[0]));
3510 
3511 		/* TODO: Only first 4 word from tim_bitmap is dumped.
3512 		 * Extend debug code to dump full tim_bitmap.
3513 		 */
3514 
3515 		arvif = ath10k_get_arvif(ar, vdev_id);
3516 		if (arvif == NULL) {
3517 			ath10k_warn(ar, "no vif for vdev_id %d found\n",
3518 				    vdev_id);
3519 			continue;
3520 		}
3521 
3522 		/* mac80211 would have already asked us to stop beaconing and
3523 		 * bring the vdev down, so continue in that case
3524 		 */
3525 		if (!arvif->is_up)
3526 			continue;
3527 
3528 		/* There are no completions for beacons so wait for next SWBA
3529 		 * before telling mac80211 to decrement CSA counter
3530 		 *
3531 		 * Once CSA counter is completed stop sending beacons until
3532 		 * actual channel switch is done */
3533 		if (arvif->vif->csa_active &&
3534 		    ieee80211_csa_is_complete(arvif->vif)) {
3535 			ieee80211_csa_finish(arvif->vif);
3536 			continue;
3537 		}
3538 
3539 		bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
3540 		if (!bcn) {
3541 			ath10k_warn(ar, "could not get mac80211 beacon\n");
3542 			continue;
3543 		}
3544 
3545 		ath10k_tx_h_seq_no(arvif->vif, bcn);
3546 		ath10k_wmi_update_tim(ar, arvif, bcn, tim_info);
3547 		ath10k_wmi_update_noa(ar, arvif, bcn, noa_info);
3548 
3549 		spin_lock_bh(&ar->data_lock);
3550 
3551 		if (arvif->beacon) {
3552 			switch (arvif->beacon_state) {
3553 			case ATH10K_BEACON_SENT:
3554 				break;
3555 			case ATH10K_BEACON_SCHEDULED:
3556 				ath10k_warn(ar, "SWBA overrun on vdev %d, skipped old beacon\n",
3557 					    arvif->vdev_id);
3558 				break;
3559 			case ATH10K_BEACON_SENDING:
3560 				ath10k_warn(ar, "SWBA overrun on vdev %d, skipped new beacon\n",
3561 					    arvif->vdev_id);
3562 				dev_kfree_skb(bcn);
3563 				goto skip;
3564 			}
3565 
3566 			ath10k_mac_vif_beacon_free(arvif);
3567 		}
3568 
3569 		if (!arvif->beacon_buf) {
3570 			paddr = dma_map_single(arvif->ar->dev, bcn->data,
3571 					       bcn->len, DMA_TO_DEVICE);
3572 			ret = dma_mapping_error(arvif->ar->dev, paddr);
3573 			if (ret) {
3574 				ath10k_warn(ar, "failed to map beacon: %d\n",
3575 					    ret);
3576 				dev_kfree_skb_any(bcn);
3577 				goto skip;
3578 			}
3579 
3580 			ATH10K_SKB_CB(bcn)->paddr = paddr;
3581 		} else {
3582 			if (bcn->len > IEEE80211_MAX_FRAME_LEN) {
3583 				ath10k_warn(ar, "trimming beacon %d -> %d bytes!\n",
3584 					    bcn->len, IEEE80211_MAX_FRAME_LEN);
3585 				skb_trim(bcn, IEEE80211_MAX_FRAME_LEN);
3586 			}
3587 			memcpy(arvif->beacon_buf, bcn->data, bcn->len);
3588 			ATH10K_SKB_CB(bcn)->paddr = arvif->beacon_paddr;
3589 		}
3590 
3591 		arvif->beacon = bcn;
3592 		arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
3593 
3594 		trace_ath10k_tx_hdr(ar, bcn->data, bcn->len);
3595 		trace_ath10k_tx_payload(ar, bcn->data, bcn->len);
3596 
3597 skip:
3598 		spin_unlock_bh(&ar->data_lock);
3599 	}
3600 
3601 	ath10k_wmi_tx_beacons_nowait(ar);
3602 }
3603 
3604 void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar, struct sk_buff *skb)
3605 {
3606 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
3607 }
3608 
3609 static void ath10k_dfs_radar_report(struct ath10k *ar,
3610 				    struct wmi_phyerr_ev_arg *phyerr,
3611 				    const struct phyerr_radar_report *rr,
3612 				    u64 tsf)
3613 {
3614 	u32 reg0, reg1, tsf32l;
3615 	struct ieee80211_channel *ch;
3616 	struct pulse_event pe;
3617 	u64 tsf64;
3618 	u8 rssi, width;
3619 
3620 	reg0 = __le32_to_cpu(rr->reg0);
3621 	reg1 = __le32_to_cpu(rr->reg1);
3622 
3623 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3624 		   "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
3625 		   MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
3626 		   MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
3627 		   MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
3628 		   MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
3629 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3630 		   "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
3631 		   MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
3632 		   MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
3633 		   MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
3634 		   MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
3635 		   MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
3636 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3637 		   "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
3638 		   MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
3639 		   MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
3640 
3641 	if (!ar->dfs_detector)
3642 		return;
3643 
3644 	spin_lock_bh(&ar->data_lock);
3645 	ch = ar->rx_channel;
3646 	spin_unlock_bh(&ar->data_lock);
3647 
3648 	if (!ch) {
3649 		ath10k_warn(ar, "failed to derive channel for radar pulse, treating as radar\n");
3650 		goto radar_detected;
3651 	}
3652 
3653 	/* report event to DFS pattern detector */
3654 	tsf32l = phyerr->tsf_timestamp;
3655 	tsf64 = tsf & (~0xFFFFFFFFULL);
3656 	tsf64 |= tsf32l;
3657 
3658 	width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
3659 	rssi = phyerr->rssi_combined;
3660 
3661 	/* hardware store this as 8 bit signed value,
3662 	 * set to zero if negative number
3663 	 */
3664 	if (rssi & 0x80)
3665 		rssi = 0;
3666 
3667 	pe.ts = tsf64;
3668 	pe.freq = ch->center_freq;
3669 	pe.width = width;
3670 	pe.rssi = rssi;
3671 	pe.chirp = (MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP) != 0);
3672 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3673 		   "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
3674 		   pe.freq, pe.width, pe.rssi, pe.ts);
3675 
3676 	ATH10K_DFS_STAT_INC(ar, pulses_detected);
3677 
3678 	if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
3679 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3680 			   "dfs no pulse pattern detected, yet\n");
3681 		return;
3682 	}
3683 
3684 radar_detected:
3685 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs radar detected\n");
3686 	ATH10K_DFS_STAT_INC(ar, radar_detected);
3687 
3688 	/* Control radar events reporting in debugfs file
3689 	   dfs_block_radar_events */
3690 	if (ar->dfs_block_radar_events) {
3691 		ath10k_info(ar, "DFS Radar detected, but ignored as requested\n");
3692 		return;
3693 	}
3694 
3695 	ieee80211_radar_detected(ar->hw);
3696 }
3697 
3698 static int ath10k_dfs_fft_report(struct ath10k *ar,
3699 				 struct wmi_phyerr_ev_arg *phyerr,
3700 				 const struct phyerr_fft_report *fftr,
3701 				 u64 tsf)
3702 {
3703 	u32 reg0, reg1;
3704 	u8 rssi, peak_mag;
3705 
3706 	reg0 = __le32_to_cpu(fftr->reg0);
3707 	reg1 = __le32_to_cpu(fftr->reg1);
3708 	rssi = phyerr->rssi_combined;
3709 
3710 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3711 		   "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
3712 		   MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
3713 		   MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
3714 		   MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
3715 		   MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
3716 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3717 		   "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
3718 		   MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
3719 		   MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
3720 		   MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
3721 		   MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
3722 
3723 	peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
3724 
3725 	/* false event detection */
3726 	if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
3727 	    peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
3728 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
3729 		ATH10K_DFS_STAT_INC(ar, pulses_discarded);
3730 		return -EINVAL;
3731 	}
3732 
3733 	return 0;
3734 }
3735 
3736 void ath10k_wmi_event_dfs(struct ath10k *ar,
3737 			  struct wmi_phyerr_ev_arg *phyerr,
3738 			  u64 tsf)
3739 {
3740 	int buf_len, tlv_len, res, i = 0;
3741 	const struct phyerr_tlv *tlv;
3742 	const struct phyerr_radar_report *rr;
3743 	const struct phyerr_fft_report *fftr;
3744 	const u8 *tlv_buf;
3745 
3746 	buf_len = phyerr->buf_len;
3747 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3748 		   "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
3749 		   phyerr->phy_err_code, phyerr->rssi_combined,
3750 		   phyerr->tsf_timestamp, tsf, buf_len);
3751 
3752 	/* Skip event if DFS disabled */
3753 	if (!IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED))
3754 		return;
3755 
3756 	ATH10K_DFS_STAT_INC(ar, pulses_total);
3757 
3758 	while (i < buf_len) {
3759 		if (i + sizeof(*tlv) > buf_len) {
3760 			ath10k_warn(ar, "too short buf for tlv header (%d)\n",
3761 				    i);
3762 			return;
3763 		}
3764 
3765 		tlv = (struct phyerr_tlv *)&phyerr->buf[i];
3766 		tlv_len = __le16_to_cpu(tlv->len);
3767 		tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
3768 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3769 			   "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
3770 			   tlv_len, tlv->tag, tlv->sig);
3771 
3772 		switch (tlv->tag) {
3773 		case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
3774 			if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
3775 				ath10k_warn(ar, "too short radar pulse summary (%d)\n",
3776 					    i);
3777 				return;
3778 			}
3779 
3780 			rr = (struct phyerr_radar_report *)tlv_buf;
3781 			ath10k_dfs_radar_report(ar, phyerr, rr, tsf);
3782 			break;
3783 		case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
3784 			if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
3785 				ath10k_warn(ar, "too short fft report (%d)\n",
3786 					    i);
3787 				return;
3788 			}
3789 
3790 			fftr = (struct phyerr_fft_report *)tlv_buf;
3791 			res = ath10k_dfs_fft_report(ar, phyerr, fftr, tsf);
3792 			if (res)
3793 				return;
3794 			break;
3795 		}
3796 
3797 		i += sizeof(*tlv) + tlv_len;
3798 	}
3799 }
3800 
3801 void ath10k_wmi_event_spectral_scan(struct ath10k *ar,
3802 				    struct wmi_phyerr_ev_arg *phyerr,
3803 				    u64 tsf)
3804 {
3805 	int buf_len, tlv_len, res, i = 0;
3806 	struct phyerr_tlv *tlv;
3807 	const void *tlv_buf;
3808 	const struct phyerr_fft_report *fftr;
3809 	size_t fftr_len;
3810 
3811 	buf_len = phyerr->buf_len;
3812 
3813 	while (i < buf_len) {
3814 		if (i + sizeof(*tlv) > buf_len) {
3815 			ath10k_warn(ar, "failed to parse phyerr tlv header at byte %d\n",
3816 				    i);
3817 			return;
3818 		}
3819 
3820 		tlv = (struct phyerr_tlv *)&phyerr->buf[i];
3821 		tlv_len = __le16_to_cpu(tlv->len);
3822 		tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
3823 
3824 		if (i + sizeof(*tlv) + tlv_len > buf_len) {
3825 			ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n",
3826 				    i);
3827 			return;
3828 		}
3829 
3830 		switch (tlv->tag) {
3831 		case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
3832 			if (sizeof(*fftr) > tlv_len) {
3833 				ath10k_warn(ar, "failed to parse fft report at byte %d\n",
3834 					    i);
3835 				return;
3836 			}
3837 
3838 			fftr_len = tlv_len - sizeof(*fftr);
3839 			fftr = tlv_buf;
3840 			res = ath10k_spectral_process_fft(ar, phyerr,
3841 							  fftr, fftr_len,
3842 							  tsf);
3843 			if (res < 0) {
3844 				ath10k_dbg(ar, ATH10K_DBG_WMI, "failed to process fft report: %d\n",
3845 					   res);
3846 				return;
3847 			}
3848 			break;
3849 		}
3850 
3851 		i += sizeof(*tlv) + tlv_len;
3852 	}
3853 }
3854 
3855 static int ath10k_wmi_op_pull_phyerr_ev_hdr(struct ath10k *ar,
3856 					    struct sk_buff *skb,
3857 					    struct wmi_phyerr_hdr_arg *arg)
3858 {
3859 	struct wmi_phyerr_event *ev = (void *)skb->data;
3860 
3861 	if (skb->len < sizeof(*ev))
3862 		return -EPROTO;
3863 
3864 	arg->num_phyerrs = __le32_to_cpu(ev->num_phyerrs);
3865 	arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
3866 	arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
3867 	arg->buf_len = skb->len - sizeof(*ev);
3868 	arg->phyerrs = ev->phyerrs;
3869 
3870 	return 0;
3871 }
3872 
3873 static int ath10k_wmi_10_4_op_pull_phyerr_ev_hdr(struct ath10k *ar,
3874 						 struct sk_buff *skb,
3875 						 struct wmi_phyerr_hdr_arg *arg)
3876 {
3877 	struct wmi_10_4_phyerr_event *ev = (void *)skb->data;
3878 
3879 	if (skb->len < sizeof(*ev))
3880 		return -EPROTO;
3881 
3882 	/* 10.4 firmware always reports only one phyerr */
3883 	arg->num_phyerrs = 1;
3884 
3885 	arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
3886 	arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
3887 	arg->buf_len = skb->len;
3888 	arg->phyerrs = skb->data;
3889 
3890 	return 0;
3891 }
3892 
3893 int ath10k_wmi_op_pull_phyerr_ev(struct ath10k *ar,
3894 				 const void *phyerr_buf,
3895 				 int left_len,
3896 				 struct wmi_phyerr_ev_arg *arg)
3897 {
3898 	const struct wmi_phyerr *phyerr = phyerr_buf;
3899 	int i;
3900 
3901 	if (left_len < sizeof(*phyerr)) {
3902 		ath10k_warn(ar, "wrong phyerr event head len %d (need: >=%zd)\n",
3903 			    left_len, sizeof(*phyerr));
3904 		return -EINVAL;
3905 	}
3906 
3907 	arg->tsf_timestamp = __le32_to_cpu(phyerr->tsf_timestamp);
3908 	arg->freq1 = __le16_to_cpu(phyerr->freq1);
3909 	arg->freq2 = __le16_to_cpu(phyerr->freq2);
3910 	arg->rssi_combined = phyerr->rssi_combined;
3911 	arg->chan_width_mhz = phyerr->chan_width_mhz;
3912 	arg->buf_len = __le32_to_cpu(phyerr->buf_len);
3913 	arg->buf = phyerr->buf;
3914 	arg->hdr_len = sizeof(*phyerr);
3915 
3916 	for (i = 0; i < 4; i++)
3917 		arg->nf_chains[i] = __le16_to_cpu(phyerr->nf_chains[i]);
3918 
3919 	switch (phyerr->phy_err_code) {
3920 	case PHY_ERROR_GEN_SPECTRAL_SCAN:
3921 		arg->phy_err_code = PHY_ERROR_SPECTRAL_SCAN;
3922 		break;
3923 	case PHY_ERROR_GEN_FALSE_RADAR_EXT:
3924 		arg->phy_err_code = PHY_ERROR_FALSE_RADAR_EXT;
3925 		break;
3926 	case PHY_ERROR_GEN_RADAR:
3927 		arg->phy_err_code = PHY_ERROR_RADAR;
3928 		break;
3929 	default:
3930 		arg->phy_err_code = PHY_ERROR_UNKNOWN;
3931 		break;
3932 	}
3933 
3934 	return 0;
3935 }
3936 
3937 static int ath10k_wmi_10_4_op_pull_phyerr_ev(struct ath10k *ar,
3938 					     const void *phyerr_buf,
3939 					     int left_len,
3940 					     struct wmi_phyerr_ev_arg *arg)
3941 {
3942 	const struct wmi_10_4_phyerr_event *phyerr = phyerr_buf;
3943 	u32 phy_err_mask;
3944 	int i;
3945 
3946 	if (left_len < sizeof(*phyerr)) {
3947 		ath10k_warn(ar, "wrong phyerr event head len %d (need: >=%zd)\n",
3948 			    left_len, sizeof(*phyerr));
3949 		return -EINVAL;
3950 	}
3951 
3952 	arg->tsf_timestamp = __le32_to_cpu(phyerr->tsf_timestamp);
3953 	arg->freq1 = __le16_to_cpu(phyerr->freq1);
3954 	arg->freq2 = __le16_to_cpu(phyerr->freq2);
3955 	arg->rssi_combined = phyerr->rssi_combined;
3956 	arg->chan_width_mhz = phyerr->chan_width_mhz;
3957 	arg->buf_len = __le32_to_cpu(phyerr->buf_len);
3958 	arg->buf = phyerr->buf;
3959 	arg->hdr_len = sizeof(*phyerr);
3960 
3961 	for (i = 0; i < 4; i++)
3962 		arg->nf_chains[i] = __le16_to_cpu(phyerr->nf_chains[i]);
3963 
3964 	phy_err_mask = __le32_to_cpu(phyerr->phy_err_mask[0]);
3965 
3966 	if (phy_err_mask & PHY_ERROR_10_4_SPECTRAL_SCAN_MASK)
3967 		arg->phy_err_code = PHY_ERROR_SPECTRAL_SCAN;
3968 	else if (phy_err_mask & PHY_ERROR_10_4_RADAR_MASK)
3969 		arg->phy_err_code = PHY_ERROR_RADAR;
3970 	else
3971 		arg->phy_err_code = PHY_ERROR_UNKNOWN;
3972 
3973 	return 0;
3974 }
3975 
3976 void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
3977 {
3978 	struct wmi_phyerr_hdr_arg hdr_arg = {};
3979 	struct wmi_phyerr_ev_arg phyerr_arg = {};
3980 	const void *phyerr;
3981 	u32 count, i, buf_len, phy_err_code;
3982 	u64 tsf;
3983 	int left_len, ret;
3984 
3985 	ATH10K_DFS_STAT_INC(ar, phy_errors);
3986 
3987 	ret = ath10k_wmi_pull_phyerr_hdr(ar, skb, &hdr_arg);
3988 	if (ret) {
3989 		ath10k_warn(ar, "failed to parse phyerr event hdr: %d\n", ret);
3990 		return;
3991 	}
3992 
3993 	/* Check number of included events */
3994 	count = hdr_arg.num_phyerrs;
3995 
3996 	left_len = hdr_arg.buf_len;
3997 
3998 	tsf = hdr_arg.tsf_u32;
3999 	tsf <<= 32;
4000 	tsf |= hdr_arg.tsf_l32;
4001 
4002 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4003 		   "wmi event phyerr count %d tsf64 0x%llX\n",
4004 		   count, tsf);
4005 
4006 	phyerr = hdr_arg.phyerrs;
4007 	for (i = 0; i < count; i++) {
4008 		ret = ath10k_wmi_pull_phyerr(ar, phyerr, left_len, &phyerr_arg);
4009 		if (ret) {
4010 			ath10k_warn(ar, "failed to parse phyerr event (%d)\n",
4011 				    i);
4012 			return;
4013 		}
4014 
4015 		left_len -= phyerr_arg.hdr_len;
4016 		buf_len = phyerr_arg.buf_len;
4017 		phy_err_code = phyerr_arg.phy_err_code;
4018 
4019 		if (left_len < buf_len) {
4020 			ath10k_warn(ar, "single event (%d) wrong buf len\n", i);
4021 			return;
4022 		}
4023 
4024 		left_len -= buf_len;
4025 
4026 		switch (phy_err_code) {
4027 		case PHY_ERROR_RADAR:
4028 			ath10k_wmi_event_dfs(ar, &phyerr_arg, tsf);
4029 			break;
4030 		case PHY_ERROR_SPECTRAL_SCAN:
4031 			ath10k_wmi_event_spectral_scan(ar, &phyerr_arg, tsf);
4032 			break;
4033 		case PHY_ERROR_FALSE_RADAR_EXT:
4034 			ath10k_wmi_event_dfs(ar, &phyerr_arg, tsf);
4035 			ath10k_wmi_event_spectral_scan(ar, &phyerr_arg, tsf);
4036 			break;
4037 		default:
4038 			break;
4039 		}
4040 
4041 		phyerr = phyerr + phyerr_arg.hdr_len + buf_len;
4042 	}
4043 }
4044 
4045 void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
4046 {
4047 	struct wmi_roam_ev_arg arg = {};
4048 	int ret;
4049 	u32 vdev_id;
4050 	u32 reason;
4051 	s32 rssi;
4052 
4053 	ret = ath10k_wmi_pull_roam_ev(ar, skb, &arg);
4054 	if (ret) {
4055 		ath10k_warn(ar, "failed to parse roam event: %d\n", ret);
4056 		return;
4057 	}
4058 
4059 	vdev_id = __le32_to_cpu(arg.vdev_id);
4060 	reason = __le32_to_cpu(arg.reason);
4061 	rssi = __le32_to_cpu(arg.rssi);
4062 	rssi += WMI_SPECTRAL_NOISE_FLOOR_REF_DEFAULT;
4063 
4064 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4065 		   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
4066 		   vdev_id, reason, rssi);
4067 
4068 	if (reason >= WMI_ROAM_REASON_MAX)
4069 		ath10k_warn(ar, "ignoring unknown roam event reason %d on vdev %i\n",
4070 			    reason, vdev_id);
4071 
4072 	switch (reason) {
4073 	case WMI_ROAM_REASON_BEACON_MISS:
4074 		ath10k_mac_handle_beacon_miss(ar, vdev_id);
4075 		break;
4076 	case WMI_ROAM_REASON_BETTER_AP:
4077 	case WMI_ROAM_REASON_LOW_RSSI:
4078 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
4079 	case WMI_ROAM_REASON_HO_FAILED:
4080 		ath10k_warn(ar, "ignoring not implemented roam event reason %d on vdev %i\n",
4081 			    reason, vdev_id);
4082 		break;
4083 	}
4084 }
4085 
4086 void ath10k_wmi_event_profile_match(struct ath10k *ar, struct sk_buff *skb)
4087 {
4088 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
4089 }
4090 
4091 void ath10k_wmi_event_debug_print(struct ath10k *ar, struct sk_buff *skb)
4092 {
4093 	char buf[101], c;
4094 	int i;
4095 
4096 	for (i = 0; i < sizeof(buf) - 1; i++) {
4097 		if (i >= skb->len)
4098 			break;
4099 
4100 		c = skb->data[i];
4101 
4102 		if (c == '\0')
4103 			break;
4104 
4105 		if (isascii(c) && isprint(c))
4106 			buf[i] = c;
4107 		else
4108 			buf[i] = '.';
4109 	}
4110 
4111 	if (i == sizeof(buf) - 1)
4112 		ath10k_warn(ar, "wmi debug print truncated: %d\n", skb->len);
4113 
4114 	/* for some reason the debug prints end with \n, remove that */
4115 	if (skb->data[i - 1] == '\n')
4116 		i--;
4117 
4118 	/* the last byte is always reserved for the null character */
4119 	buf[i] = '\0';
4120 
4121 	ath10k_dbg(ar, ATH10K_DBG_WMI_PRINT, "wmi print '%s'\n", buf);
4122 }
4123 
4124 void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
4125 {
4126 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
4127 }
4128 
4129 void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar, struct sk_buff *skb)
4130 {
4131 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
4132 }
4133 
4134 void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
4135 					     struct sk_buff *skb)
4136 {
4137 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
4138 }
4139 
4140 void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
4141 					     struct sk_buff *skb)
4142 {
4143 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
4144 }
4145 
4146 void ath10k_wmi_event_rtt_error_report(struct ath10k *ar, struct sk_buff *skb)
4147 {
4148 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
4149 }
4150 
4151 void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar, struct sk_buff *skb)
4152 {
4153 	struct wmi_wow_ev_arg ev = {};
4154 	int ret;
4155 
4156 	complete(&ar->wow.wakeup_completed);
4157 
4158 	ret = ath10k_wmi_pull_wow_event(ar, skb, &ev);
4159 	if (ret) {
4160 		ath10k_warn(ar, "failed to parse wow wakeup event: %d\n", ret);
4161 		return;
4162 	}
4163 
4164 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wow wakeup host reason %s\n",
4165 		   wow_reason(ev.wake_reason));
4166 }
4167 
4168 void ath10k_wmi_event_dcs_interference(struct ath10k *ar, struct sk_buff *skb)
4169 {
4170 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
4171 }
4172 
4173 static u8 ath10k_tpc_config_get_rate(struct ath10k *ar,
4174 				     struct wmi_pdev_tpc_config_event *ev,
4175 				     u32 rate_idx, u32 num_chains,
4176 				     u32 rate_code, u8 type)
4177 {
4178 	u8 tpc, num_streams, preamble, ch, stm_idx;
4179 
4180 	num_streams = ATH10K_HW_NSS(rate_code);
4181 	preamble = ATH10K_HW_PREAMBLE(rate_code);
4182 	ch = num_chains - 1;
4183 
4184 	tpc = min_t(u8, ev->rates_array[rate_idx], ev->max_reg_allow_pow[ch]);
4185 
4186 	if (__le32_to_cpu(ev->num_tx_chain) <= 1)
4187 		goto out;
4188 
4189 	if (preamble == WMI_RATE_PREAMBLE_CCK)
4190 		goto out;
4191 
4192 	stm_idx = num_streams - 1;
4193 	if (num_chains <= num_streams)
4194 		goto out;
4195 
4196 	switch (type) {
4197 	case WMI_TPC_TABLE_TYPE_STBC:
4198 		tpc = min_t(u8, tpc,
4199 			    ev->max_reg_allow_pow_agstbc[ch - 1][stm_idx]);
4200 		break;
4201 	case WMI_TPC_TABLE_TYPE_TXBF:
4202 		tpc = min_t(u8, tpc,
4203 			    ev->max_reg_allow_pow_agtxbf[ch - 1][stm_idx]);
4204 		break;
4205 	case WMI_TPC_TABLE_TYPE_CDD:
4206 		tpc = min_t(u8, tpc,
4207 			    ev->max_reg_allow_pow_agcdd[ch - 1][stm_idx]);
4208 		break;
4209 	default:
4210 		ath10k_warn(ar, "unknown wmi tpc table type: %d\n", type);
4211 		tpc = 0;
4212 		break;
4213 	}
4214 
4215 out:
4216 	return tpc;
4217 }
4218 
4219 static void ath10k_tpc_config_disp_tables(struct ath10k *ar,
4220 					  struct wmi_pdev_tpc_config_event *ev,
4221 					  struct ath10k_tpc_stats *tpc_stats,
4222 					  u8 *rate_code, u16 *pream_table, u8 type)
4223 {
4224 	u32 i, j, pream_idx, flags;
4225 	u8 tpc[WMI_TPC_TX_N_CHAIN];
4226 	char tpc_value[WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
4227 	char buff[WMI_TPC_BUF_SIZE];
4228 
4229 	flags = __le32_to_cpu(ev->flags);
4230 
4231 	switch (type) {
4232 	case WMI_TPC_TABLE_TYPE_CDD:
4233 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_CDD)) {
4234 			ath10k_dbg(ar, ATH10K_DBG_WMI, "CDD not supported\n");
4235 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4236 			return;
4237 		}
4238 		break;
4239 	case WMI_TPC_TABLE_TYPE_STBC:
4240 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_STBC)) {
4241 			ath10k_dbg(ar, ATH10K_DBG_WMI, "STBC not supported\n");
4242 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4243 			return;
4244 		}
4245 		break;
4246 	case WMI_TPC_TABLE_TYPE_TXBF:
4247 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_TXBF)) {
4248 			ath10k_dbg(ar, ATH10K_DBG_WMI, "TXBF not supported\n");
4249 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4250 			return;
4251 		}
4252 		break;
4253 	default:
4254 		ath10k_dbg(ar, ATH10K_DBG_WMI,
4255 			   "invalid table type in wmi tpc event: %d\n", type);
4256 		return;
4257 	}
4258 
4259 	pream_idx = 0;
4260 	for (i = 0; i < __le32_to_cpu(ev->rate_max); i++) {
4261 		memset(tpc_value, 0, sizeof(tpc_value));
4262 		memset(buff, 0, sizeof(buff));
4263 		if (i == pream_table[pream_idx])
4264 			pream_idx++;
4265 
4266 		for (j = 0; j < WMI_TPC_TX_N_CHAIN; j++) {
4267 			if (j >= __le32_to_cpu(ev->num_tx_chain))
4268 				break;
4269 
4270 			tpc[j] = ath10k_tpc_config_get_rate(ar, ev, i, j + 1,
4271 							    rate_code[i],
4272 							    type);
4273 			snprintf(buff, sizeof(buff), "%8d ", tpc[j]);
4274 			strncat(tpc_value, buff, strlen(buff));
4275 		}
4276 		tpc_stats->tpc_table[type].pream_idx[i] = pream_idx;
4277 		tpc_stats->tpc_table[type].rate_code[i] = rate_code[i];
4278 		memcpy(tpc_stats->tpc_table[type].tpc_value[i],
4279 		       tpc_value, sizeof(tpc_value));
4280 	}
4281 }
4282 
4283 void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar, struct sk_buff *skb)
4284 {
4285 	u32 i, j, pream_idx, num_tx_chain;
4286 	u8 rate_code[WMI_TPC_RATE_MAX], rate_idx;
4287 	u16 pream_table[WMI_TPC_PREAM_TABLE_MAX];
4288 	struct wmi_pdev_tpc_config_event *ev;
4289 	struct ath10k_tpc_stats *tpc_stats;
4290 
4291 	ev = (struct wmi_pdev_tpc_config_event *)skb->data;
4292 
4293 	tpc_stats = kzalloc(sizeof(*tpc_stats), GFP_ATOMIC);
4294 	if (!tpc_stats)
4295 		return;
4296 
4297 	/* Create the rate code table based on the chains supported */
4298 	rate_idx = 0;
4299 	pream_idx = 0;
4300 
4301 	/* Fill CCK rate code */
4302 	for (i = 0; i < 4; i++) {
4303 		rate_code[rate_idx] =
4304 			ATH10K_HW_RATECODE(i, 0, WMI_RATE_PREAMBLE_CCK);
4305 		rate_idx++;
4306 	}
4307 	pream_table[pream_idx] = rate_idx;
4308 	pream_idx++;
4309 
4310 	/* Fill OFDM rate code */
4311 	for (i = 0; i < 8; i++) {
4312 		rate_code[rate_idx] =
4313 			ATH10K_HW_RATECODE(i, 0, WMI_RATE_PREAMBLE_OFDM);
4314 		rate_idx++;
4315 	}
4316 	pream_table[pream_idx] = rate_idx;
4317 	pream_idx++;
4318 
4319 	num_tx_chain = __le32_to_cpu(ev->num_tx_chain);
4320 
4321 	/* Fill HT20 rate code */
4322 	for (i = 0; i < num_tx_chain; i++) {
4323 		for (j = 0; j < 8; j++) {
4324 			rate_code[rate_idx] =
4325 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_HT);
4326 			rate_idx++;
4327 		}
4328 	}
4329 	pream_table[pream_idx] = rate_idx;
4330 	pream_idx++;
4331 
4332 	/* Fill HT40 rate code */
4333 	for (i = 0; i < num_tx_chain; i++) {
4334 		for (j = 0; j < 8; j++) {
4335 			rate_code[rate_idx] =
4336 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_HT);
4337 			rate_idx++;
4338 		}
4339 	}
4340 	pream_table[pream_idx] = rate_idx;
4341 	pream_idx++;
4342 
4343 	/* Fill VHT20 rate code */
4344 	for (i = 0; i < __le32_to_cpu(ev->num_tx_chain); i++) {
4345 		for (j = 0; j < 10; j++) {
4346 			rate_code[rate_idx] =
4347 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4348 			rate_idx++;
4349 		}
4350 	}
4351 	pream_table[pream_idx] = rate_idx;
4352 	pream_idx++;
4353 
4354 	/* Fill VHT40 rate code */
4355 	for (i = 0; i < num_tx_chain; i++) {
4356 		for (j = 0; j < 10; j++) {
4357 			rate_code[rate_idx] =
4358 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4359 			rate_idx++;
4360 		}
4361 	}
4362 	pream_table[pream_idx] = rate_idx;
4363 	pream_idx++;
4364 
4365 	/* Fill VHT80 rate code */
4366 	for (i = 0; i < num_tx_chain; i++) {
4367 		for (j = 0; j < 10; j++) {
4368 			rate_code[rate_idx] =
4369 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4370 			rate_idx++;
4371 		}
4372 	}
4373 	pream_table[pream_idx] = rate_idx;
4374 	pream_idx++;
4375 
4376 	rate_code[rate_idx++] =
4377 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_CCK);
4378 	rate_code[rate_idx++] =
4379 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4380 	rate_code[rate_idx++] =
4381 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_CCK);
4382 	rate_code[rate_idx++] =
4383 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4384 	rate_code[rate_idx++] =
4385 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4386 
4387 	pream_table[pream_idx] = ATH10K_TPC_PREAM_TABLE_END;
4388 
4389 	tpc_stats->chan_freq = __le32_to_cpu(ev->chan_freq);
4390 	tpc_stats->phy_mode = __le32_to_cpu(ev->phy_mode);
4391 	tpc_stats->ctl = __le32_to_cpu(ev->ctl);
4392 	tpc_stats->reg_domain = __le32_to_cpu(ev->reg_domain);
4393 	tpc_stats->twice_antenna_gain = a_sle32_to_cpu(ev->twice_antenna_gain);
4394 	tpc_stats->twice_antenna_reduction =
4395 		__le32_to_cpu(ev->twice_antenna_reduction);
4396 	tpc_stats->power_limit = __le32_to_cpu(ev->power_limit);
4397 	tpc_stats->twice_max_rd_power = __le32_to_cpu(ev->twice_max_rd_power);
4398 	tpc_stats->num_tx_chain = __le32_to_cpu(ev->num_tx_chain);
4399 	tpc_stats->rate_max = __le32_to_cpu(ev->rate_max);
4400 
4401 	ath10k_tpc_config_disp_tables(ar, ev, tpc_stats,
4402 				      rate_code, pream_table,
4403 				      WMI_TPC_TABLE_TYPE_CDD);
4404 	ath10k_tpc_config_disp_tables(ar, ev,  tpc_stats,
4405 				      rate_code, pream_table,
4406 				      WMI_TPC_TABLE_TYPE_STBC);
4407 	ath10k_tpc_config_disp_tables(ar, ev, tpc_stats,
4408 				      rate_code, pream_table,
4409 				      WMI_TPC_TABLE_TYPE_TXBF);
4410 
4411 	ath10k_debug_tpc_stats_process(ar, tpc_stats);
4412 
4413 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4414 		   "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",
4415 		   __le32_to_cpu(ev->chan_freq),
4416 		   __le32_to_cpu(ev->phy_mode),
4417 		   __le32_to_cpu(ev->ctl),
4418 		   __le32_to_cpu(ev->reg_domain),
4419 		   a_sle32_to_cpu(ev->twice_antenna_gain),
4420 		   __le32_to_cpu(ev->twice_antenna_reduction),
4421 		   __le32_to_cpu(ev->power_limit),
4422 		   __le32_to_cpu(ev->twice_max_rd_power) / 2,
4423 		   __le32_to_cpu(ev->num_tx_chain),
4424 		   __le32_to_cpu(ev->rate_max));
4425 }
4426 
4427 void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar, struct sk_buff *skb)
4428 {
4429 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
4430 }
4431 
4432 void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar, struct sk_buff *skb)
4433 {
4434 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
4435 }
4436 
4437 void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar, struct sk_buff *skb)
4438 {
4439 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
4440 }
4441 
4442 void ath10k_wmi_event_delba_complete(struct ath10k *ar, struct sk_buff *skb)
4443 {
4444 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
4445 }
4446 
4447 void ath10k_wmi_event_addba_complete(struct ath10k *ar, struct sk_buff *skb)
4448 {
4449 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
4450 }
4451 
4452 void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
4453 						struct sk_buff *skb)
4454 {
4455 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
4456 }
4457 
4458 void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar, struct sk_buff *skb)
4459 {
4460 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
4461 }
4462 
4463 void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar, struct sk_buff *skb)
4464 {
4465 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
4466 }
4467 
4468 void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar, struct sk_buff *skb)
4469 {
4470 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
4471 }
4472 
4473 static int ath10k_wmi_alloc_chunk(struct ath10k *ar, u32 req_id,
4474 				  u32 num_units, u32 unit_len)
4475 {
4476 	dma_addr_t paddr;
4477 	u32 pool_size = 0;
4478 	int idx = ar->wmi.num_mem_chunks;
4479 	void *vaddr = NULL;
4480 
4481 	if (ar->wmi.num_mem_chunks == ARRAY_SIZE(ar->wmi.mem_chunks))
4482 		return -ENOMEM;
4483 
4484 	while (!vaddr && num_units) {
4485 		pool_size = num_units * round_up(unit_len, 4);
4486 		if (!pool_size)
4487 			return -EINVAL;
4488 
4489 		vaddr = kzalloc(pool_size, GFP_KERNEL | __GFP_NOWARN);
4490 		if (!vaddr)
4491 			num_units /= 2;
4492 	}
4493 
4494 	if (!num_units)
4495 		return -ENOMEM;
4496 
4497 	paddr = dma_map_single(ar->dev, vaddr, pool_size, DMA_BIDIRECTIONAL);
4498 	if (dma_mapping_error(ar->dev, paddr)) {
4499 		kfree(vaddr);
4500 		return -ENOMEM;
4501 	}
4502 
4503 	ar->wmi.mem_chunks[idx].vaddr = vaddr;
4504 	ar->wmi.mem_chunks[idx].paddr = paddr;
4505 	ar->wmi.mem_chunks[idx].len = pool_size;
4506 	ar->wmi.mem_chunks[idx].req_id = req_id;
4507 	ar->wmi.num_mem_chunks++;
4508 
4509 	return num_units;
4510 }
4511 
4512 static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
4513 				     u32 num_units, u32 unit_len)
4514 {
4515 	int ret;
4516 
4517 	while (num_units) {
4518 		ret = ath10k_wmi_alloc_chunk(ar, req_id, num_units, unit_len);
4519 		if (ret < 0)
4520 			return ret;
4521 
4522 		num_units -= ret;
4523 	}
4524 
4525 	return 0;
4526 }
4527 
4528 static bool
4529 ath10k_wmi_is_host_mem_allocated(struct ath10k *ar,
4530 				 const struct wlan_host_mem_req **mem_reqs,
4531 				 u32 num_mem_reqs)
4532 {
4533 	u32 req_id, num_units, unit_size, num_unit_info;
4534 	u32 pool_size;
4535 	int i, j;
4536 	bool found;
4537 
4538 	if (ar->wmi.num_mem_chunks != num_mem_reqs)
4539 		return false;
4540 
4541 	for (i = 0; i < num_mem_reqs; ++i) {
4542 		req_id = __le32_to_cpu(mem_reqs[i]->req_id);
4543 		num_units = __le32_to_cpu(mem_reqs[i]->num_units);
4544 		unit_size = __le32_to_cpu(mem_reqs[i]->unit_size);
4545 		num_unit_info = __le32_to_cpu(mem_reqs[i]->num_unit_info);
4546 
4547 		if (num_unit_info & NUM_UNITS_IS_NUM_ACTIVE_PEERS) {
4548 			if (ar->num_active_peers)
4549 				num_units = ar->num_active_peers + 1;
4550 			else
4551 				num_units = ar->max_num_peers + 1;
4552 		} else if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) {
4553 			num_units = ar->max_num_peers + 1;
4554 		} else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS) {
4555 			num_units = ar->max_num_vdevs + 1;
4556 		}
4557 
4558 		found = false;
4559 		for (j = 0; j < ar->wmi.num_mem_chunks; j++) {
4560 			if (ar->wmi.mem_chunks[j].req_id == req_id) {
4561 				pool_size = num_units * round_up(unit_size, 4);
4562 				if (ar->wmi.mem_chunks[j].len == pool_size) {
4563 					found = true;
4564 					break;
4565 				}
4566 			}
4567 		}
4568 		if (!found)
4569 			return false;
4570 	}
4571 
4572 	return true;
4573 }
4574 
4575 static int
4576 ath10k_wmi_main_op_pull_svc_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
4577 				   struct wmi_svc_rdy_ev_arg *arg)
4578 {
4579 	struct wmi_service_ready_event *ev;
4580 	size_t i, n;
4581 
4582 	if (skb->len < sizeof(*ev))
4583 		return -EPROTO;
4584 
4585 	ev = (void *)skb->data;
4586 	skb_pull(skb, sizeof(*ev));
4587 	arg->min_tx_power = ev->hw_min_tx_power;
4588 	arg->max_tx_power = ev->hw_max_tx_power;
4589 	arg->ht_cap = ev->ht_cap_info;
4590 	arg->vht_cap = ev->vht_cap_info;
4591 	arg->sw_ver0 = ev->sw_version;
4592 	arg->sw_ver1 = ev->sw_version_1;
4593 	arg->phy_capab = ev->phy_capability;
4594 	arg->num_rf_chains = ev->num_rf_chains;
4595 	arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
4596 	arg->num_mem_reqs = ev->num_mem_reqs;
4597 	arg->service_map = ev->wmi_service_bitmap;
4598 	arg->service_map_len = sizeof(ev->wmi_service_bitmap);
4599 
4600 	n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
4601 		  ARRAY_SIZE(arg->mem_reqs));
4602 	for (i = 0; i < n; i++)
4603 		arg->mem_reqs[i] = &ev->mem_reqs[i];
4604 
4605 	if (skb->len <
4606 	    __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
4607 		return -EPROTO;
4608 
4609 	return 0;
4610 }
4611 
4612 static int
4613 ath10k_wmi_10x_op_pull_svc_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
4614 				  struct wmi_svc_rdy_ev_arg *arg)
4615 {
4616 	struct wmi_10x_service_ready_event *ev;
4617 	int i, n;
4618 
4619 	if (skb->len < sizeof(*ev))
4620 		return -EPROTO;
4621 
4622 	ev = (void *)skb->data;
4623 	skb_pull(skb, sizeof(*ev));
4624 	arg->min_tx_power = ev->hw_min_tx_power;
4625 	arg->max_tx_power = ev->hw_max_tx_power;
4626 	arg->ht_cap = ev->ht_cap_info;
4627 	arg->vht_cap = ev->vht_cap_info;
4628 	arg->sw_ver0 = ev->sw_version;
4629 	arg->phy_capab = ev->phy_capability;
4630 	arg->num_rf_chains = ev->num_rf_chains;
4631 	arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
4632 	arg->num_mem_reqs = ev->num_mem_reqs;
4633 	arg->service_map = ev->wmi_service_bitmap;
4634 	arg->service_map_len = sizeof(ev->wmi_service_bitmap);
4635 
4636 	n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
4637 		  ARRAY_SIZE(arg->mem_reqs));
4638 	for (i = 0; i < n; i++)
4639 		arg->mem_reqs[i] = &ev->mem_reqs[i];
4640 
4641 	if (skb->len <
4642 	    __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
4643 		return -EPROTO;
4644 
4645 	return 0;
4646 }
4647 
4648 static void ath10k_wmi_event_service_ready_work(struct work_struct *work)
4649 {
4650 	struct ath10k *ar = container_of(work, struct ath10k, svc_rdy_work);
4651 	struct sk_buff *skb = ar->svc_rdy_skb;
4652 	struct wmi_svc_rdy_ev_arg arg = {};
4653 	u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
4654 	int ret;
4655 	bool allocated;
4656 
4657 	if (!skb) {
4658 		ath10k_warn(ar, "invalid service ready event skb\n");
4659 		return;
4660 	}
4661 
4662 	ret = ath10k_wmi_pull_svc_rdy(ar, skb, &arg);
4663 	if (ret) {
4664 		ath10k_warn(ar, "failed to parse service ready: %d\n", ret);
4665 		return;
4666 	}
4667 
4668 	memset(&ar->wmi.svc_map, 0, sizeof(ar->wmi.svc_map));
4669 	ath10k_wmi_map_svc(ar, arg.service_map, ar->wmi.svc_map,
4670 			   arg.service_map_len);
4671 
4672 	ar->hw_min_tx_power = __le32_to_cpu(arg.min_tx_power);
4673 	ar->hw_max_tx_power = __le32_to_cpu(arg.max_tx_power);
4674 	ar->ht_cap_info = __le32_to_cpu(arg.ht_cap);
4675 	ar->vht_cap_info = __le32_to_cpu(arg.vht_cap);
4676 	ar->fw_version_major =
4677 		(__le32_to_cpu(arg.sw_ver0) & 0xff000000) >> 24;
4678 	ar->fw_version_minor = (__le32_to_cpu(arg.sw_ver0) & 0x00ffffff);
4679 	ar->fw_version_release =
4680 		(__le32_to_cpu(arg.sw_ver1) & 0xffff0000) >> 16;
4681 	ar->fw_version_build = (__le32_to_cpu(arg.sw_ver1) & 0x0000ffff);
4682 	ar->phy_capability = __le32_to_cpu(arg.phy_capab);
4683 	ar->num_rf_chains = __le32_to_cpu(arg.num_rf_chains);
4684 	ar->hw_eeprom_rd = __le32_to_cpu(arg.eeprom_rd);
4685 
4686 	ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
4687 			arg.service_map, arg.service_map_len);
4688 
4689 	if (ar->num_rf_chains > ar->max_spatial_stream) {
4690 		ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
4691 			    ar->num_rf_chains, ar->max_spatial_stream);
4692 		ar->num_rf_chains = ar->max_spatial_stream;
4693 	}
4694 
4695 	if (!ar->cfg_tx_chainmask) {
4696 		ar->cfg_tx_chainmask = (1 << ar->num_rf_chains) - 1;
4697 		ar->cfg_rx_chainmask = (1 << ar->num_rf_chains) - 1;
4698 	}
4699 
4700 	if (strlen(ar->hw->wiphy->fw_version) == 0) {
4701 		snprintf(ar->hw->wiphy->fw_version,
4702 			 sizeof(ar->hw->wiphy->fw_version),
4703 			 "%u.%u.%u.%u",
4704 			 ar->fw_version_major,
4705 			 ar->fw_version_minor,
4706 			 ar->fw_version_release,
4707 			 ar->fw_version_build);
4708 	}
4709 
4710 	num_mem_reqs = __le32_to_cpu(arg.num_mem_reqs);
4711 	if (num_mem_reqs > WMI_MAX_MEM_REQS) {
4712 		ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n",
4713 			    num_mem_reqs);
4714 		return;
4715 	}
4716 
4717 	if (test_bit(WMI_SERVICE_PEER_CACHING, ar->wmi.svc_map)) {
4718 		if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
4719 			     ar->running_fw->fw_file.fw_features))
4720 			ar->num_active_peers = TARGET_10_4_QCACHE_ACTIVE_PEERS_PFC +
4721 					       ar->max_num_vdevs;
4722 		else
4723 			ar->num_active_peers = TARGET_10_4_QCACHE_ACTIVE_PEERS +
4724 					       ar->max_num_vdevs;
4725 
4726 		ar->max_num_peers = TARGET_10_4_NUM_QCACHE_PEERS_MAX +
4727 				    ar->max_num_vdevs;
4728 		ar->num_tids = ar->num_active_peers * 2;
4729 		ar->max_num_stations = TARGET_10_4_NUM_QCACHE_PEERS_MAX;
4730 	}
4731 
4732 	/* TODO: Adjust max peer count for cases like WMI_SERVICE_RATECTRL_CACHE
4733 	 * and WMI_SERVICE_IRAM_TIDS, etc.
4734 	 */
4735 
4736 	allocated = ath10k_wmi_is_host_mem_allocated(ar, arg.mem_reqs,
4737 						     num_mem_reqs);
4738 	if (allocated)
4739 		goto skip_mem_alloc;
4740 
4741 	/* Either this event is received during boot time or there is a change
4742 	 * in memory requirement from firmware when compared to last request.
4743 	 * Free any old memory and do a fresh allocation based on the current
4744 	 * memory requirement.
4745 	 */
4746 	ath10k_wmi_free_host_mem(ar);
4747 
4748 	for (i = 0; i < num_mem_reqs; ++i) {
4749 		req_id = __le32_to_cpu(arg.mem_reqs[i]->req_id);
4750 		num_units = __le32_to_cpu(arg.mem_reqs[i]->num_units);
4751 		unit_size = __le32_to_cpu(arg.mem_reqs[i]->unit_size);
4752 		num_unit_info = __le32_to_cpu(arg.mem_reqs[i]->num_unit_info);
4753 
4754 		if (num_unit_info & NUM_UNITS_IS_NUM_ACTIVE_PEERS) {
4755 			if (ar->num_active_peers)
4756 				num_units = ar->num_active_peers + 1;
4757 			else
4758 				num_units = ar->max_num_peers + 1;
4759 		} else if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) {
4760 			/* number of units to allocate is number of
4761 			 * peers, 1 extra for self peer on target */
4762 			/* this needs to be tied, host and target
4763 			 * can get out of sync */
4764 			num_units = ar->max_num_peers + 1;
4765 		} else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS) {
4766 			num_units = ar->max_num_vdevs + 1;
4767 		}
4768 
4769 		ath10k_dbg(ar, ATH10K_DBG_WMI,
4770 			   "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
4771 			   req_id,
4772 			   __le32_to_cpu(arg.mem_reqs[i]->num_units),
4773 			   num_unit_info,
4774 			   unit_size,
4775 			   num_units);
4776 
4777 		ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
4778 						unit_size);
4779 		if (ret)
4780 			return;
4781 	}
4782 
4783 skip_mem_alloc:
4784 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4785 		   "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",
4786 		   __le32_to_cpu(arg.min_tx_power),
4787 		   __le32_to_cpu(arg.max_tx_power),
4788 		   __le32_to_cpu(arg.ht_cap),
4789 		   __le32_to_cpu(arg.vht_cap),
4790 		   __le32_to_cpu(arg.sw_ver0),
4791 		   __le32_to_cpu(arg.sw_ver1),
4792 		   __le32_to_cpu(arg.fw_build),
4793 		   __le32_to_cpu(arg.phy_capab),
4794 		   __le32_to_cpu(arg.num_rf_chains),
4795 		   __le32_to_cpu(arg.eeprom_rd),
4796 		   __le32_to_cpu(arg.num_mem_reqs));
4797 
4798 	dev_kfree_skb(skb);
4799 	ar->svc_rdy_skb = NULL;
4800 	complete(&ar->wmi.service_ready);
4801 }
4802 
4803 void ath10k_wmi_event_service_ready(struct ath10k *ar, struct sk_buff *skb)
4804 {
4805 	ar->svc_rdy_skb = skb;
4806 	queue_work(ar->workqueue_aux, &ar->svc_rdy_work);
4807 }
4808 
4809 static int ath10k_wmi_op_pull_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
4810 				     struct wmi_rdy_ev_arg *arg)
4811 {
4812 	struct wmi_ready_event *ev = (void *)skb->data;
4813 
4814 	if (skb->len < sizeof(*ev))
4815 		return -EPROTO;
4816 
4817 	skb_pull(skb, sizeof(*ev));
4818 	arg->sw_version = ev->sw_version;
4819 	arg->abi_version = ev->abi_version;
4820 	arg->status = ev->status;
4821 	arg->mac_addr = ev->mac_addr.addr;
4822 
4823 	return 0;
4824 }
4825 
4826 static int ath10k_wmi_op_pull_roam_ev(struct ath10k *ar, struct sk_buff *skb,
4827 				      struct wmi_roam_ev_arg *arg)
4828 {
4829 	struct wmi_roam_ev *ev = (void *)skb->data;
4830 
4831 	if (skb->len < sizeof(*ev))
4832 		return -EPROTO;
4833 
4834 	skb_pull(skb, sizeof(*ev));
4835 	arg->vdev_id = ev->vdev_id;
4836 	arg->reason = ev->reason;
4837 
4838 	return 0;
4839 }
4840 
4841 static int ath10k_wmi_op_pull_echo_ev(struct ath10k *ar,
4842 				      struct sk_buff *skb,
4843 				      struct wmi_echo_ev_arg *arg)
4844 {
4845 	struct wmi_echo_event *ev = (void *)skb->data;
4846 
4847 	arg->value = ev->value;
4848 
4849 	return 0;
4850 }
4851 
4852 int ath10k_wmi_event_ready(struct ath10k *ar, struct sk_buff *skb)
4853 {
4854 	struct wmi_rdy_ev_arg arg = {};
4855 	int ret;
4856 
4857 	ret = ath10k_wmi_pull_rdy(ar, skb, &arg);
4858 	if (ret) {
4859 		ath10k_warn(ar, "failed to parse ready event: %d\n", ret);
4860 		return ret;
4861 	}
4862 
4863 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4864 		   "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d\n",
4865 		   __le32_to_cpu(arg.sw_version),
4866 		   __le32_to_cpu(arg.abi_version),
4867 		   arg.mac_addr,
4868 		   __le32_to_cpu(arg.status));
4869 
4870 	ether_addr_copy(ar->mac_addr, arg.mac_addr);
4871 	complete(&ar->wmi.unified_ready);
4872 	return 0;
4873 }
4874 
4875 static int ath10k_wmi_event_temperature(struct ath10k *ar, struct sk_buff *skb)
4876 {
4877 	const struct wmi_pdev_temperature_event *ev;
4878 
4879 	ev = (struct wmi_pdev_temperature_event *)skb->data;
4880 	if (WARN_ON(skb->len < sizeof(*ev)))
4881 		return -EPROTO;
4882 
4883 	ath10k_thermal_event_temperature(ar, __le32_to_cpu(ev->temperature));
4884 	return 0;
4885 }
4886 
4887 static int ath10k_wmi_event_pdev_bss_chan_info(struct ath10k *ar,
4888 					       struct sk_buff *skb)
4889 {
4890 	struct wmi_pdev_bss_chan_info_event *ev;
4891 	struct survey_info *survey;
4892 	u64 busy, total, tx, rx, rx_bss;
4893 	u32 freq, noise_floor;
4894 	u32 cc_freq_hz = ar->hw_params.channel_counters_freq_hz;
4895 	int idx;
4896 
4897 	ev = (struct wmi_pdev_bss_chan_info_event *)skb->data;
4898 	if (WARN_ON(skb->len < sizeof(*ev)))
4899 		return -EPROTO;
4900 
4901 	freq        = __le32_to_cpu(ev->freq);
4902 	noise_floor = __le32_to_cpu(ev->noise_floor);
4903 	busy        = __le64_to_cpu(ev->cycle_busy);
4904 	total       = __le64_to_cpu(ev->cycle_total);
4905 	tx          = __le64_to_cpu(ev->cycle_tx);
4906 	rx          = __le64_to_cpu(ev->cycle_rx);
4907 	rx_bss      = __le64_to_cpu(ev->cycle_rx_bss);
4908 
4909 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4910 		   "wmi event pdev bss chan info:\n freq: %d noise: %d cycle: busy %llu total %llu tx %llu rx %llu rx_bss %llu\n",
4911 		   freq, noise_floor, busy, total, tx, rx, rx_bss);
4912 
4913 	spin_lock_bh(&ar->data_lock);
4914 	idx = freq_to_idx(ar, freq);
4915 	if (idx >= ARRAY_SIZE(ar->survey)) {
4916 		ath10k_warn(ar, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
4917 			    freq, idx);
4918 		goto exit;
4919 	}
4920 
4921 	survey = &ar->survey[idx];
4922 
4923 	survey->noise     = noise_floor;
4924 	survey->time      = div_u64(total, cc_freq_hz);
4925 	survey->time_busy = div_u64(busy, cc_freq_hz);
4926 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
4927 	survey->time_tx   = div_u64(tx, cc_freq_hz);
4928 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
4929 			     SURVEY_INFO_TIME |
4930 			     SURVEY_INFO_TIME_BUSY |
4931 			     SURVEY_INFO_TIME_RX |
4932 			     SURVEY_INFO_TIME_TX);
4933 exit:
4934 	spin_unlock_bh(&ar->data_lock);
4935 	complete(&ar->bss_survey_done);
4936 	return 0;
4937 }
4938 
4939 static inline void ath10k_wmi_queue_set_coverage_class_work(struct ath10k *ar)
4940 {
4941 	if (ar->hw_params.hw_ops->set_coverage_class) {
4942 		spin_lock_bh(&ar->data_lock);
4943 
4944 		/* This call only ensures that the modified coverage class
4945 		 * persists in case the firmware sets the registers back to
4946 		 * their default value. So calling it is only necessary if the
4947 		 * coverage class has a non-zero value.
4948 		 */
4949 		if (ar->fw_coverage.coverage_class)
4950 			queue_work(ar->workqueue, &ar->set_coverage_class_work);
4951 
4952 		spin_unlock_bh(&ar->data_lock);
4953 	}
4954 }
4955 
4956 static void ath10k_wmi_op_rx(struct ath10k *ar, struct sk_buff *skb)
4957 {
4958 	struct wmi_cmd_hdr *cmd_hdr;
4959 	enum wmi_event_id id;
4960 
4961 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
4962 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
4963 
4964 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
4965 		goto out;
4966 
4967 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
4968 
4969 	switch (id) {
4970 	case WMI_MGMT_RX_EVENTID:
4971 		ath10k_wmi_event_mgmt_rx(ar, skb);
4972 		/* mgmt_rx() owns the skb now! */
4973 		return;
4974 	case WMI_SCAN_EVENTID:
4975 		ath10k_wmi_event_scan(ar, skb);
4976 		ath10k_wmi_queue_set_coverage_class_work(ar);
4977 		break;
4978 	case WMI_CHAN_INFO_EVENTID:
4979 		ath10k_wmi_event_chan_info(ar, skb);
4980 		break;
4981 	case WMI_ECHO_EVENTID:
4982 		ath10k_wmi_event_echo(ar, skb);
4983 		break;
4984 	case WMI_DEBUG_MESG_EVENTID:
4985 		ath10k_wmi_event_debug_mesg(ar, skb);
4986 		ath10k_wmi_queue_set_coverage_class_work(ar);
4987 		break;
4988 	case WMI_UPDATE_STATS_EVENTID:
4989 		ath10k_wmi_event_update_stats(ar, skb);
4990 		break;
4991 	case WMI_VDEV_START_RESP_EVENTID:
4992 		ath10k_wmi_event_vdev_start_resp(ar, skb);
4993 		ath10k_wmi_queue_set_coverage_class_work(ar);
4994 		break;
4995 	case WMI_VDEV_STOPPED_EVENTID:
4996 		ath10k_wmi_event_vdev_stopped(ar, skb);
4997 		ath10k_wmi_queue_set_coverage_class_work(ar);
4998 		break;
4999 	case WMI_PEER_STA_KICKOUT_EVENTID:
5000 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
5001 		break;
5002 	case WMI_HOST_SWBA_EVENTID:
5003 		ath10k_wmi_event_host_swba(ar, skb);
5004 		break;
5005 	case WMI_TBTTOFFSET_UPDATE_EVENTID:
5006 		ath10k_wmi_event_tbttoffset_update(ar, skb);
5007 		break;
5008 	case WMI_PHYERR_EVENTID:
5009 		ath10k_wmi_event_phyerr(ar, skb);
5010 		break;
5011 	case WMI_ROAM_EVENTID:
5012 		ath10k_wmi_event_roam(ar, skb);
5013 		ath10k_wmi_queue_set_coverage_class_work(ar);
5014 		break;
5015 	case WMI_PROFILE_MATCH:
5016 		ath10k_wmi_event_profile_match(ar, skb);
5017 		break;
5018 	case WMI_DEBUG_PRINT_EVENTID:
5019 		ath10k_wmi_event_debug_print(ar, skb);
5020 		ath10k_wmi_queue_set_coverage_class_work(ar);
5021 		break;
5022 	case WMI_PDEV_QVIT_EVENTID:
5023 		ath10k_wmi_event_pdev_qvit(ar, skb);
5024 		break;
5025 	case WMI_WLAN_PROFILE_DATA_EVENTID:
5026 		ath10k_wmi_event_wlan_profile_data(ar, skb);
5027 		break;
5028 	case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
5029 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
5030 		break;
5031 	case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
5032 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
5033 		break;
5034 	case WMI_RTT_ERROR_REPORT_EVENTID:
5035 		ath10k_wmi_event_rtt_error_report(ar, skb);
5036 		break;
5037 	case WMI_WOW_WAKEUP_HOST_EVENTID:
5038 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
5039 		break;
5040 	case WMI_DCS_INTERFERENCE_EVENTID:
5041 		ath10k_wmi_event_dcs_interference(ar, skb);
5042 		break;
5043 	case WMI_PDEV_TPC_CONFIG_EVENTID:
5044 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
5045 		break;
5046 	case WMI_PDEV_FTM_INTG_EVENTID:
5047 		ath10k_wmi_event_pdev_ftm_intg(ar, skb);
5048 		break;
5049 	case WMI_GTK_OFFLOAD_STATUS_EVENTID:
5050 		ath10k_wmi_event_gtk_offload_status(ar, skb);
5051 		break;
5052 	case WMI_GTK_REKEY_FAIL_EVENTID:
5053 		ath10k_wmi_event_gtk_rekey_fail(ar, skb);
5054 		break;
5055 	case WMI_TX_DELBA_COMPLETE_EVENTID:
5056 		ath10k_wmi_event_delba_complete(ar, skb);
5057 		break;
5058 	case WMI_TX_ADDBA_COMPLETE_EVENTID:
5059 		ath10k_wmi_event_addba_complete(ar, skb);
5060 		break;
5061 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
5062 		ath10k_wmi_event_vdev_install_key_complete(ar, skb);
5063 		break;
5064 	case WMI_SERVICE_READY_EVENTID:
5065 		ath10k_wmi_event_service_ready(ar, skb);
5066 		return;
5067 	case WMI_READY_EVENTID:
5068 		ath10k_wmi_event_ready(ar, skb);
5069 		ath10k_wmi_queue_set_coverage_class_work(ar);
5070 		break;
5071 	default:
5072 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
5073 		break;
5074 	}
5075 
5076 out:
5077 	dev_kfree_skb(skb);
5078 }
5079 
5080 static void ath10k_wmi_10_1_op_rx(struct ath10k *ar, struct sk_buff *skb)
5081 {
5082 	struct wmi_cmd_hdr *cmd_hdr;
5083 	enum wmi_10x_event_id id;
5084 	bool consumed;
5085 
5086 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5087 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5088 
5089 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5090 		goto out;
5091 
5092 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5093 
5094 	consumed = ath10k_tm_event_wmi(ar, id, skb);
5095 
5096 	/* Ready event must be handled normally also in UTF mode so that we
5097 	 * know the UTF firmware has booted, others we are just bypass WMI
5098 	 * events to testmode.
5099 	 */
5100 	if (consumed && id != WMI_10X_READY_EVENTID) {
5101 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5102 			   "wmi testmode consumed 0x%x\n", id);
5103 		goto out;
5104 	}
5105 
5106 	switch (id) {
5107 	case WMI_10X_MGMT_RX_EVENTID:
5108 		ath10k_wmi_event_mgmt_rx(ar, skb);
5109 		/* mgmt_rx() owns the skb now! */
5110 		return;
5111 	case WMI_10X_SCAN_EVENTID:
5112 		ath10k_wmi_event_scan(ar, skb);
5113 		ath10k_wmi_queue_set_coverage_class_work(ar);
5114 		break;
5115 	case WMI_10X_CHAN_INFO_EVENTID:
5116 		ath10k_wmi_event_chan_info(ar, skb);
5117 		break;
5118 	case WMI_10X_ECHO_EVENTID:
5119 		ath10k_wmi_event_echo(ar, skb);
5120 		break;
5121 	case WMI_10X_DEBUG_MESG_EVENTID:
5122 		ath10k_wmi_event_debug_mesg(ar, skb);
5123 		ath10k_wmi_queue_set_coverage_class_work(ar);
5124 		break;
5125 	case WMI_10X_UPDATE_STATS_EVENTID:
5126 		ath10k_wmi_event_update_stats(ar, skb);
5127 		break;
5128 	case WMI_10X_VDEV_START_RESP_EVENTID:
5129 		ath10k_wmi_event_vdev_start_resp(ar, skb);
5130 		ath10k_wmi_queue_set_coverage_class_work(ar);
5131 		break;
5132 	case WMI_10X_VDEV_STOPPED_EVENTID:
5133 		ath10k_wmi_event_vdev_stopped(ar, skb);
5134 		ath10k_wmi_queue_set_coverage_class_work(ar);
5135 		break;
5136 	case WMI_10X_PEER_STA_KICKOUT_EVENTID:
5137 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
5138 		break;
5139 	case WMI_10X_HOST_SWBA_EVENTID:
5140 		ath10k_wmi_event_host_swba(ar, skb);
5141 		break;
5142 	case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
5143 		ath10k_wmi_event_tbttoffset_update(ar, skb);
5144 		break;
5145 	case WMI_10X_PHYERR_EVENTID:
5146 		ath10k_wmi_event_phyerr(ar, skb);
5147 		break;
5148 	case WMI_10X_ROAM_EVENTID:
5149 		ath10k_wmi_event_roam(ar, skb);
5150 		ath10k_wmi_queue_set_coverage_class_work(ar);
5151 		break;
5152 	case WMI_10X_PROFILE_MATCH:
5153 		ath10k_wmi_event_profile_match(ar, skb);
5154 		break;
5155 	case WMI_10X_DEBUG_PRINT_EVENTID:
5156 		ath10k_wmi_event_debug_print(ar, skb);
5157 		ath10k_wmi_queue_set_coverage_class_work(ar);
5158 		break;
5159 	case WMI_10X_PDEV_QVIT_EVENTID:
5160 		ath10k_wmi_event_pdev_qvit(ar, skb);
5161 		break;
5162 	case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
5163 		ath10k_wmi_event_wlan_profile_data(ar, skb);
5164 		break;
5165 	case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
5166 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
5167 		break;
5168 	case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
5169 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
5170 		break;
5171 	case WMI_10X_RTT_ERROR_REPORT_EVENTID:
5172 		ath10k_wmi_event_rtt_error_report(ar, skb);
5173 		break;
5174 	case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
5175 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
5176 		break;
5177 	case WMI_10X_DCS_INTERFERENCE_EVENTID:
5178 		ath10k_wmi_event_dcs_interference(ar, skb);
5179 		break;
5180 	case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
5181 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
5182 		break;
5183 	case WMI_10X_INST_RSSI_STATS_EVENTID:
5184 		ath10k_wmi_event_inst_rssi_stats(ar, skb);
5185 		break;
5186 	case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
5187 		ath10k_wmi_event_vdev_standby_req(ar, skb);
5188 		break;
5189 	case WMI_10X_VDEV_RESUME_REQ_EVENTID:
5190 		ath10k_wmi_event_vdev_resume_req(ar, skb);
5191 		break;
5192 	case WMI_10X_SERVICE_READY_EVENTID:
5193 		ath10k_wmi_event_service_ready(ar, skb);
5194 		return;
5195 	case WMI_10X_READY_EVENTID:
5196 		ath10k_wmi_event_ready(ar, skb);
5197 		ath10k_wmi_queue_set_coverage_class_work(ar);
5198 		break;
5199 	case WMI_10X_PDEV_UTF_EVENTID:
5200 		/* ignore utf events */
5201 		break;
5202 	default:
5203 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
5204 		break;
5205 	}
5206 
5207 out:
5208 	dev_kfree_skb(skb);
5209 }
5210 
5211 static void ath10k_wmi_10_2_op_rx(struct ath10k *ar, struct sk_buff *skb)
5212 {
5213 	struct wmi_cmd_hdr *cmd_hdr;
5214 	enum wmi_10_2_event_id id;
5215 	bool consumed;
5216 
5217 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5218 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5219 
5220 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5221 		goto out;
5222 
5223 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5224 
5225 	consumed = ath10k_tm_event_wmi(ar, id, skb);
5226 
5227 	/* Ready event must be handled normally also in UTF mode so that we
5228 	 * know the UTF firmware has booted, others we are just bypass WMI
5229 	 * events to testmode.
5230 	 */
5231 	if (consumed && id != WMI_10_2_READY_EVENTID) {
5232 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5233 			   "wmi testmode consumed 0x%x\n", id);
5234 		goto out;
5235 	}
5236 
5237 	switch (id) {
5238 	case WMI_10_2_MGMT_RX_EVENTID:
5239 		ath10k_wmi_event_mgmt_rx(ar, skb);
5240 		/* mgmt_rx() owns the skb now! */
5241 		return;
5242 	case WMI_10_2_SCAN_EVENTID:
5243 		ath10k_wmi_event_scan(ar, skb);
5244 		ath10k_wmi_queue_set_coverage_class_work(ar);
5245 		break;
5246 	case WMI_10_2_CHAN_INFO_EVENTID:
5247 		ath10k_wmi_event_chan_info(ar, skb);
5248 		break;
5249 	case WMI_10_2_ECHO_EVENTID:
5250 		ath10k_wmi_event_echo(ar, skb);
5251 		break;
5252 	case WMI_10_2_DEBUG_MESG_EVENTID:
5253 		ath10k_wmi_event_debug_mesg(ar, skb);
5254 		ath10k_wmi_queue_set_coverage_class_work(ar);
5255 		break;
5256 	case WMI_10_2_UPDATE_STATS_EVENTID:
5257 		ath10k_wmi_event_update_stats(ar, skb);
5258 		break;
5259 	case WMI_10_2_VDEV_START_RESP_EVENTID:
5260 		ath10k_wmi_event_vdev_start_resp(ar, skb);
5261 		ath10k_wmi_queue_set_coverage_class_work(ar);
5262 		break;
5263 	case WMI_10_2_VDEV_STOPPED_EVENTID:
5264 		ath10k_wmi_event_vdev_stopped(ar, skb);
5265 		ath10k_wmi_queue_set_coverage_class_work(ar);
5266 		break;
5267 	case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
5268 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
5269 		break;
5270 	case WMI_10_2_HOST_SWBA_EVENTID:
5271 		ath10k_wmi_event_host_swba(ar, skb);
5272 		break;
5273 	case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
5274 		ath10k_wmi_event_tbttoffset_update(ar, skb);
5275 		break;
5276 	case WMI_10_2_PHYERR_EVENTID:
5277 		ath10k_wmi_event_phyerr(ar, skb);
5278 		break;
5279 	case WMI_10_2_ROAM_EVENTID:
5280 		ath10k_wmi_event_roam(ar, skb);
5281 		ath10k_wmi_queue_set_coverage_class_work(ar);
5282 		break;
5283 	case WMI_10_2_PROFILE_MATCH:
5284 		ath10k_wmi_event_profile_match(ar, skb);
5285 		break;
5286 	case WMI_10_2_DEBUG_PRINT_EVENTID:
5287 		ath10k_wmi_event_debug_print(ar, skb);
5288 		ath10k_wmi_queue_set_coverage_class_work(ar);
5289 		break;
5290 	case WMI_10_2_PDEV_QVIT_EVENTID:
5291 		ath10k_wmi_event_pdev_qvit(ar, skb);
5292 		break;
5293 	case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
5294 		ath10k_wmi_event_wlan_profile_data(ar, skb);
5295 		break;
5296 	case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
5297 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
5298 		break;
5299 	case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
5300 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
5301 		break;
5302 	case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
5303 		ath10k_wmi_event_rtt_error_report(ar, skb);
5304 		break;
5305 	case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
5306 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
5307 		break;
5308 	case WMI_10_2_DCS_INTERFERENCE_EVENTID:
5309 		ath10k_wmi_event_dcs_interference(ar, skb);
5310 		break;
5311 	case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
5312 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
5313 		break;
5314 	case WMI_10_2_INST_RSSI_STATS_EVENTID:
5315 		ath10k_wmi_event_inst_rssi_stats(ar, skb);
5316 		break;
5317 	case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
5318 		ath10k_wmi_event_vdev_standby_req(ar, skb);
5319 		ath10k_wmi_queue_set_coverage_class_work(ar);
5320 		break;
5321 	case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
5322 		ath10k_wmi_event_vdev_resume_req(ar, skb);
5323 		ath10k_wmi_queue_set_coverage_class_work(ar);
5324 		break;
5325 	case WMI_10_2_SERVICE_READY_EVENTID:
5326 		ath10k_wmi_event_service_ready(ar, skb);
5327 		return;
5328 	case WMI_10_2_READY_EVENTID:
5329 		ath10k_wmi_event_ready(ar, skb);
5330 		ath10k_wmi_queue_set_coverage_class_work(ar);
5331 		break;
5332 	case WMI_10_2_PDEV_TEMPERATURE_EVENTID:
5333 		ath10k_wmi_event_temperature(ar, skb);
5334 		break;
5335 	case WMI_10_2_PDEV_BSS_CHAN_INFO_EVENTID:
5336 		ath10k_wmi_event_pdev_bss_chan_info(ar, skb);
5337 		break;
5338 	case WMI_10_2_RTT_KEEPALIVE_EVENTID:
5339 	case WMI_10_2_GPIO_INPUT_EVENTID:
5340 	case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
5341 	case WMI_10_2_GENERIC_BUFFER_EVENTID:
5342 	case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
5343 	case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
5344 	case WMI_10_2_WDS_PEER_EVENTID:
5345 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5346 			   "received event id %d not implemented\n", id);
5347 		break;
5348 	default:
5349 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
5350 		break;
5351 	}
5352 
5353 out:
5354 	dev_kfree_skb(skb);
5355 }
5356 
5357 static void ath10k_wmi_10_4_op_rx(struct ath10k *ar, struct sk_buff *skb)
5358 {
5359 	struct wmi_cmd_hdr *cmd_hdr;
5360 	enum wmi_10_4_event_id id;
5361 	bool consumed;
5362 
5363 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5364 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5365 
5366 	if (!skb_pull(skb, sizeof(struct wmi_cmd_hdr)))
5367 		goto out;
5368 
5369 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5370 
5371 	consumed = ath10k_tm_event_wmi(ar, id, skb);
5372 
5373 	/* Ready event must be handled normally also in UTF mode so that we
5374 	 * know the UTF firmware has booted, others we are just bypass WMI
5375 	 * events to testmode.
5376 	 */
5377 	if (consumed && id != WMI_10_4_READY_EVENTID) {
5378 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5379 			   "wmi testmode consumed 0x%x\n", id);
5380 		goto out;
5381 	}
5382 
5383 	switch (id) {
5384 	case WMI_10_4_MGMT_RX_EVENTID:
5385 		ath10k_wmi_event_mgmt_rx(ar, skb);
5386 		/* mgmt_rx() owns the skb now! */
5387 		return;
5388 	case WMI_10_4_ECHO_EVENTID:
5389 		ath10k_wmi_event_echo(ar, skb);
5390 		break;
5391 	case WMI_10_4_DEBUG_MESG_EVENTID:
5392 		ath10k_wmi_event_debug_mesg(ar, skb);
5393 		ath10k_wmi_queue_set_coverage_class_work(ar);
5394 		break;
5395 	case WMI_10_4_SERVICE_READY_EVENTID:
5396 		ath10k_wmi_event_service_ready(ar, skb);
5397 		return;
5398 	case WMI_10_4_SCAN_EVENTID:
5399 		ath10k_wmi_event_scan(ar, skb);
5400 		ath10k_wmi_queue_set_coverage_class_work(ar);
5401 		break;
5402 	case WMI_10_4_CHAN_INFO_EVENTID:
5403 		ath10k_wmi_event_chan_info(ar, skb);
5404 		break;
5405 	case WMI_10_4_PHYERR_EVENTID:
5406 		ath10k_wmi_event_phyerr(ar, skb);
5407 		break;
5408 	case WMI_10_4_READY_EVENTID:
5409 		ath10k_wmi_event_ready(ar, skb);
5410 		ath10k_wmi_queue_set_coverage_class_work(ar);
5411 		break;
5412 	case WMI_10_4_PEER_STA_KICKOUT_EVENTID:
5413 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
5414 		break;
5415 	case WMI_10_4_ROAM_EVENTID:
5416 		ath10k_wmi_event_roam(ar, skb);
5417 		ath10k_wmi_queue_set_coverage_class_work(ar);
5418 		break;
5419 	case WMI_10_4_HOST_SWBA_EVENTID:
5420 		ath10k_wmi_event_host_swba(ar, skb);
5421 		break;
5422 	case WMI_10_4_TBTTOFFSET_UPDATE_EVENTID:
5423 		ath10k_wmi_event_tbttoffset_update(ar, skb);
5424 		break;
5425 	case WMI_10_4_DEBUG_PRINT_EVENTID:
5426 		ath10k_wmi_event_debug_print(ar, skb);
5427 		ath10k_wmi_queue_set_coverage_class_work(ar);
5428 		break;
5429 	case WMI_10_4_VDEV_START_RESP_EVENTID:
5430 		ath10k_wmi_event_vdev_start_resp(ar, skb);
5431 		ath10k_wmi_queue_set_coverage_class_work(ar);
5432 		break;
5433 	case WMI_10_4_VDEV_STOPPED_EVENTID:
5434 		ath10k_wmi_event_vdev_stopped(ar, skb);
5435 		ath10k_wmi_queue_set_coverage_class_work(ar);
5436 		break;
5437 	case WMI_10_4_WOW_WAKEUP_HOST_EVENTID:
5438 	case WMI_10_4_PEER_RATECODE_LIST_EVENTID:
5439 	case WMI_10_4_WDS_PEER_EVENTID:
5440 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5441 			   "received event id %d not implemented\n", id);
5442 		break;
5443 	case WMI_10_4_UPDATE_STATS_EVENTID:
5444 		ath10k_wmi_event_update_stats(ar, skb);
5445 		break;
5446 	case WMI_10_4_PDEV_TEMPERATURE_EVENTID:
5447 		ath10k_wmi_event_temperature(ar, skb);
5448 		break;
5449 	case WMI_10_4_PDEV_BSS_CHAN_INFO_EVENTID:
5450 		ath10k_wmi_event_pdev_bss_chan_info(ar, skb);
5451 		break;
5452 	case WMI_10_4_PDEV_TPC_CONFIG_EVENTID:
5453 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
5454 		break;
5455 	default:
5456 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
5457 		break;
5458 	}
5459 
5460 out:
5461 	dev_kfree_skb(skb);
5462 }
5463 
5464 static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
5465 {
5466 	int ret;
5467 
5468 	ret = ath10k_wmi_rx(ar, skb);
5469 	if (ret)
5470 		ath10k_warn(ar, "failed to process wmi rx: %d\n", ret);
5471 }
5472 
5473 int ath10k_wmi_connect(struct ath10k *ar)
5474 {
5475 	int status;
5476 	struct ath10k_htc_svc_conn_req conn_req;
5477 	struct ath10k_htc_svc_conn_resp conn_resp;
5478 
5479 	memset(&conn_req, 0, sizeof(conn_req));
5480 	memset(&conn_resp, 0, sizeof(conn_resp));
5481 
5482 	/* these fields are the same for all service endpoints */
5483 	conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
5484 	conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
5485 	conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
5486 
5487 	/* connect to control service */
5488 	conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
5489 
5490 	status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
5491 	if (status) {
5492 		ath10k_warn(ar, "failed to connect to WMI CONTROL service status: %d\n",
5493 			    status);
5494 		return status;
5495 	}
5496 
5497 	ar->wmi.eid = conn_resp.eid;
5498 	return 0;
5499 }
5500 
5501 static struct sk_buff *
5502 ath10k_wmi_op_gen_pdev_set_rd(struct ath10k *ar, u16 rd, u16 rd2g, u16 rd5g,
5503 			      u16 ctl2g, u16 ctl5g,
5504 			      enum wmi_dfs_region dfs_reg)
5505 {
5506 	struct wmi_pdev_set_regdomain_cmd *cmd;
5507 	struct sk_buff *skb;
5508 
5509 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5510 	if (!skb)
5511 		return ERR_PTR(-ENOMEM);
5512 
5513 	cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
5514 	cmd->reg_domain = __cpu_to_le32(rd);
5515 	cmd->reg_domain_2G = __cpu_to_le32(rd2g);
5516 	cmd->reg_domain_5G = __cpu_to_le32(rd5g);
5517 	cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
5518 	cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
5519 
5520 	ath10k_dbg(ar, ATH10K_DBG_WMI,
5521 		   "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
5522 		   rd, rd2g, rd5g, ctl2g, ctl5g);
5523 	return skb;
5524 }
5525 
5526 static struct sk_buff *
5527 ath10k_wmi_10x_op_gen_pdev_set_rd(struct ath10k *ar, u16 rd, u16 rd2g, u16
5528 				  rd5g, u16 ctl2g, u16 ctl5g,
5529 				  enum wmi_dfs_region dfs_reg)
5530 {
5531 	struct wmi_pdev_set_regdomain_cmd_10x *cmd;
5532 	struct sk_buff *skb;
5533 
5534 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5535 	if (!skb)
5536 		return ERR_PTR(-ENOMEM);
5537 
5538 	cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
5539 	cmd->reg_domain = __cpu_to_le32(rd);
5540 	cmd->reg_domain_2G = __cpu_to_le32(rd2g);
5541 	cmd->reg_domain_5G = __cpu_to_le32(rd5g);
5542 	cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
5543 	cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
5544 	cmd->dfs_domain = __cpu_to_le32(dfs_reg);
5545 
5546 	ath10k_dbg(ar, ATH10K_DBG_WMI,
5547 		   "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
5548 		   rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
5549 	return skb;
5550 }
5551 
5552 static struct sk_buff *
5553 ath10k_wmi_op_gen_pdev_suspend(struct ath10k *ar, u32 suspend_opt)
5554 {
5555 	struct wmi_pdev_suspend_cmd *cmd;
5556 	struct sk_buff *skb;
5557 
5558 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5559 	if (!skb)
5560 		return ERR_PTR(-ENOMEM);
5561 
5562 	cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
5563 	cmd->suspend_opt = __cpu_to_le32(suspend_opt);
5564 
5565 	return skb;
5566 }
5567 
5568 static struct sk_buff *
5569 ath10k_wmi_op_gen_pdev_resume(struct ath10k *ar)
5570 {
5571 	struct sk_buff *skb;
5572 
5573 	skb = ath10k_wmi_alloc_skb(ar, 0);
5574 	if (!skb)
5575 		return ERR_PTR(-ENOMEM);
5576 
5577 	return skb;
5578 }
5579 
5580 static struct sk_buff *
5581 ath10k_wmi_op_gen_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
5582 {
5583 	struct wmi_pdev_set_param_cmd *cmd;
5584 	struct sk_buff *skb;
5585 
5586 	if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
5587 		ath10k_warn(ar, "pdev param %d not supported by firmware\n",
5588 			    id);
5589 		return ERR_PTR(-EOPNOTSUPP);
5590 	}
5591 
5592 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
5593 	if (!skb)
5594 		return ERR_PTR(-ENOMEM);
5595 
5596 	cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
5597 	cmd->param_id    = __cpu_to_le32(id);
5598 	cmd->param_value = __cpu_to_le32(value);
5599 
5600 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
5601 		   id, value);
5602 	return skb;
5603 }
5604 
5605 void ath10k_wmi_put_host_mem_chunks(struct ath10k *ar,
5606 				    struct wmi_host_mem_chunks *chunks)
5607 {
5608 	struct host_memory_chunk *chunk;
5609 	int i;
5610 
5611 	chunks->count = __cpu_to_le32(ar->wmi.num_mem_chunks);
5612 
5613 	for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
5614 		chunk = &chunks->items[i];
5615 		chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
5616 		chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
5617 		chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
5618 
5619 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5620 			   "wmi chunk %d len %d requested, addr 0x%llx\n",
5621 			   i,
5622 			   ar->wmi.mem_chunks[i].len,
5623 			   (unsigned long long)ar->wmi.mem_chunks[i].paddr);
5624 	}
5625 }
5626 
5627 static struct sk_buff *ath10k_wmi_op_gen_init(struct ath10k *ar)
5628 {
5629 	struct wmi_init_cmd *cmd;
5630 	struct sk_buff *buf;
5631 	struct wmi_resource_config config = {};
5632 	u32 len, val;
5633 
5634 	config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
5635 	config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS);
5636 	config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
5637 
5638 	config.num_offload_reorder_bufs =
5639 		__cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
5640 
5641 	config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
5642 	config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
5643 	config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
5644 	config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
5645 	config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
5646 	config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
5647 	config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
5648 	config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
5649 	config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
5650 	config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
5651 	config.scan_max_pending_reqs =
5652 		__cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
5653 
5654 	config.bmiss_offload_max_vdev =
5655 		__cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
5656 
5657 	config.roam_offload_max_vdev =
5658 		__cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
5659 
5660 	config.roam_offload_max_ap_profiles =
5661 		__cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
5662 
5663 	config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
5664 	config.num_mcast_table_elems =
5665 		__cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
5666 
5667 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
5668 	config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
5669 	config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
5670 	config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
5671 	config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
5672 
5673 	val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
5674 	config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
5675 
5676 	config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
5677 
5678 	config.gtk_offload_max_vdev =
5679 		__cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
5680 
5681 	config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
5682 	config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
5683 
5684 	len = sizeof(*cmd) +
5685 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5686 
5687 	buf = ath10k_wmi_alloc_skb(ar, len);
5688 	if (!buf)
5689 		return ERR_PTR(-ENOMEM);
5690 
5691 	cmd = (struct wmi_init_cmd *)buf->data;
5692 
5693 	memcpy(&cmd->resource_config, &config, sizeof(config));
5694 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5695 
5696 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n");
5697 	return buf;
5698 }
5699 
5700 static struct sk_buff *ath10k_wmi_10_1_op_gen_init(struct ath10k *ar)
5701 {
5702 	struct wmi_init_cmd_10x *cmd;
5703 	struct sk_buff *buf;
5704 	struct wmi_resource_config_10x config = {};
5705 	u32 len, val;
5706 
5707 	config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
5708 	config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
5709 	config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
5710 	config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
5711 	config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
5712 	config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
5713 	config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
5714 	config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5715 	config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5716 	config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5717 	config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
5718 	config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
5719 	config.scan_max_pending_reqs =
5720 		__cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
5721 
5722 	config.bmiss_offload_max_vdev =
5723 		__cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
5724 
5725 	config.roam_offload_max_vdev =
5726 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
5727 
5728 	config.roam_offload_max_ap_profiles =
5729 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
5730 
5731 	config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
5732 	config.num_mcast_table_elems =
5733 		__cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
5734 
5735 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
5736 	config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
5737 	config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
5738 	config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
5739 	config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
5740 
5741 	val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
5742 	config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
5743 
5744 	config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
5745 
5746 	config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
5747 	config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
5748 
5749 	len = sizeof(*cmd) +
5750 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5751 
5752 	buf = ath10k_wmi_alloc_skb(ar, len);
5753 	if (!buf)
5754 		return ERR_PTR(-ENOMEM);
5755 
5756 	cmd = (struct wmi_init_cmd_10x *)buf->data;
5757 
5758 	memcpy(&cmd->resource_config, &config, sizeof(config));
5759 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5760 
5761 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n");
5762 	return buf;
5763 }
5764 
5765 static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar)
5766 {
5767 	struct wmi_init_cmd_10_2 *cmd;
5768 	struct sk_buff *buf;
5769 	struct wmi_resource_config_10x config = {};
5770 	u32 len, val, features;
5771 
5772 	config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
5773 	config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
5774 
5775 	if (ath10k_peer_stats_enabled(ar)) {
5776 		config.num_peers = __cpu_to_le32(TARGET_10X_TX_STATS_NUM_PEERS);
5777 		config.num_tids = __cpu_to_le32(TARGET_10X_TX_STATS_NUM_TIDS);
5778 	} else {
5779 		config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
5780 		config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
5781 	}
5782 
5783 	config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
5784 	config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
5785 	config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
5786 	config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5787 	config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5788 	config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
5789 	config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
5790 	config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
5791 
5792 	config.scan_max_pending_reqs =
5793 		__cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
5794 
5795 	config.bmiss_offload_max_vdev =
5796 		__cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
5797 
5798 	config.roam_offload_max_vdev =
5799 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
5800 
5801 	config.roam_offload_max_ap_profiles =
5802 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
5803 
5804 	config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
5805 	config.num_mcast_table_elems =
5806 		__cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
5807 
5808 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
5809 	config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
5810 	config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
5811 	config.dma_burst_size = __cpu_to_le32(TARGET_10_2_DMA_BURST_SIZE);
5812 	config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
5813 
5814 	val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
5815 	config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
5816 
5817 	config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
5818 
5819 	config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
5820 	config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
5821 
5822 	len = sizeof(*cmd) +
5823 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5824 
5825 	buf = ath10k_wmi_alloc_skb(ar, len);
5826 	if (!buf)
5827 		return ERR_PTR(-ENOMEM);
5828 
5829 	cmd = (struct wmi_init_cmd_10_2 *)buf->data;
5830 
5831 	features = WMI_10_2_RX_BATCH_MODE;
5832 
5833 	if (test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) &&
5834 	    test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
5835 		features |= WMI_10_2_COEX_GPIO;
5836 
5837 	if (ath10k_peer_stats_enabled(ar))
5838 		features |= WMI_10_2_PEER_STATS;
5839 
5840 	if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
5841 		features |= WMI_10_2_BSS_CHAN_INFO;
5842 
5843 	cmd->resource_config.feature_mask = __cpu_to_le32(features);
5844 
5845 	memcpy(&cmd->resource_config.common, &config, sizeof(config));
5846 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5847 
5848 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n");
5849 	return buf;
5850 }
5851 
5852 static struct sk_buff *ath10k_wmi_10_4_op_gen_init(struct ath10k *ar)
5853 {
5854 	struct wmi_init_cmd_10_4 *cmd;
5855 	struct sk_buff *buf;
5856 	struct wmi_resource_config_10_4 config = {};
5857 	u32 len;
5858 
5859 	config.num_vdevs = __cpu_to_le32(ar->max_num_vdevs);
5860 	config.num_peers = __cpu_to_le32(ar->max_num_peers);
5861 	config.num_active_peers = __cpu_to_le32(ar->num_active_peers);
5862 	config.num_tids = __cpu_to_le32(ar->num_tids);
5863 
5864 	config.num_offload_peers = __cpu_to_le32(TARGET_10_4_NUM_OFFLOAD_PEERS);
5865 	config.num_offload_reorder_buffs =
5866 			__cpu_to_le32(TARGET_10_4_NUM_OFFLOAD_REORDER_BUFFS);
5867 	config.num_peer_keys  = __cpu_to_le32(TARGET_10_4_NUM_PEER_KEYS);
5868 	config.ast_skid_limit = __cpu_to_le32(TARGET_10_4_AST_SKID_LIMIT);
5869 	config.tx_chain_mask  = __cpu_to_le32(ar->hw_params.tx_chain_mask);
5870 	config.rx_chain_mask  = __cpu_to_le32(ar->hw_params.rx_chain_mask);
5871 
5872 	config.rx_timeout_pri[0] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
5873 	config.rx_timeout_pri[1] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
5874 	config.rx_timeout_pri[2] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
5875 	config.rx_timeout_pri[3] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_HI_PRI);
5876 
5877 	config.rx_decap_mode	    = __cpu_to_le32(ar->wmi.rx_decap_mode);
5878 	config.scan_max_pending_req = __cpu_to_le32(TARGET_10_4_SCAN_MAX_REQS);
5879 	config.bmiss_offload_max_vdev =
5880 			__cpu_to_le32(TARGET_10_4_BMISS_OFFLOAD_MAX_VDEV);
5881 	config.roam_offload_max_vdev  =
5882 			__cpu_to_le32(TARGET_10_4_ROAM_OFFLOAD_MAX_VDEV);
5883 	config.roam_offload_max_ap_profiles =
5884 			__cpu_to_le32(TARGET_10_4_ROAM_OFFLOAD_MAX_PROFILES);
5885 	config.num_mcast_groups = __cpu_to_le32(TARGET_10_4_NUM_MCAST_GROUPS);
5886 	config.num_mcast_table_elems =
5887 			__cpu_to_le32(TARGET_10_4_NUM_MCAST_TABLE_ELEMS);
5888 
5889 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_10_4_MCAST2UCAST_MODE);
5890 	config.tx_dbg_log_size  = __cpu_to_le32(TARGET_10_4_TX_DBG_LOG_SIZE);
5891 	config.num_wds_entries  = __cpu_to_le32(TARGET_10_4_NUM_WDS_ENTRIES);
5892 	config.dma_burst_size   = __cpu_to_le32(TARGET_10_4_DMA_BURST_SIZE);
5893 	config.mac_aggr_delim   = __cpu_to_le32(TARGET_10_4_MAC_AGGR_DELIM);
5894 
5895 	config.rx_skip_defrag_timeout_dup_detection_check =
5896 	  __cpu_to_le32(TARGET_10_4_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK);
5897 
5898 	config.vow_config = __cpu_to_le32(TARGET_10_4_VOW_CONFIG);
5899 	config.gtk_offload_max_vdev =
5900 			__cpu_to_le32(TARGET_10_4_GTK_OFFLOAD_MAX_VDEV);
5901 	config.num_msdu_desc = __cpu_to_le32(ar->htt.max_num_pending_tx);
5902 	config.max_frag_entries = __cpu_to_le32(TARGET_10_4_11AC_TX_MAX_FRAGS);
5903 	config.max_peer_ext_stats =
5904 			__cpu_to_le32(TARGET_10_4_MAX_PEER_EXT_STATS);
5905 	config.smart_ant_cap = __cpu_to_le32(TARGET_10_4_SMART_ANT_CAP);
5906 
5907 	config.bk_minfree = __cpu_to_le32(TARGET_10_4_BK_MIN_FREE);
5908 	config.be_minfree = __cpu_to_le32(TARGET_10_4_BE_MIN_FREE);
5909 	config.vi_minfree = __cpu_to_le32(TARGET_10_4_VI_MIN_FREE);
5910 	config.vo_minfree = __cpu_to_le32(TARGET_10_4_VO_MIN_FREE);
5911 
5912 	config.rx_batchmode = __cpu_to_le32(TARGET_10_4_RX_BATCH_MODE);
5913 	config.tt_support =
5914 			__cpu_to_le32(TARGET_10_4_THERMAL_THROTTLING_CONFIG);
5915 	config.atf_config = __cpu_to_le32(TARGET_10_4_ATF_CONFIG);
5916 	config.iphdr_pad_config = __cpu_to_le32(TARGET_10_4_IPHDR_PAD_CONFIG);
5917 	config.qwrap_config = __cpu_to_le32(TARGET_10_4_QWRAP_CONFIG);
5918 
5919 	len = sizeof(*cmd) +
5920 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
5921 
5922 	buf = ath10k_wmi_alloc_skb(ar, len);
5923 	if (!buf)
5924 		return ERR_PTR(-ENOMEM);
5925 
5926 	cmd = (struct wmi_init_cmd_10_4 *)buf->data;
5927 	memcpy(&cmd->resource_config, &config, sizeof(config));
5928 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
5929 
5930 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.4\n");
5931 	return buf;
5932 }
5933 
5934 int ath10k_wmi_start_scan_verify(const struct wmi_start_scan_arg *arg)
5935 {
5936 	if (arg->ie_len && !arg->ie)
5937 		return -EINVAL;
5938 	if (arg->n_channels && !arg->channels)
5939 		return -EINVAL;
5940 	if (arg->n_ssids && !arg->ssids)
5941 		return -EINVAL;
5942 	if (arg->n_bssids && !arg->bssids)
5943 		return -EINVAL;
5944 
5945 	if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
5946 		return -EINVAL;
5947 	if (arg->n_channels > ARRAY_SIZE(arg->channels))
5948 		return -EINVAL;
5949 	if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
5950 		return -EINVAL;
5951 	if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
5952 		return -EINVAL;
5953 
5954 	return 0;
5955 }
5956 
5957 static size_t
5958 ath10k_wmi_start_scan_tlvs_len(const struct wmi_start_scan_arg *arg)
5959 {
5960 	int len = 0;
5961 
5962 	if (arg->ie_len) {
5963 		len += sizeof(struct wmi_ie_data);
5964 		len += roundup(arg->ie_len, 4);
5965 	}
5966 
5967 	if (arg->n_channels) {
5968 		len += sizeof(struct wmi_chan_list);
5969 		len += sizeof(__le32) * arg->n_channels;
5970 	}
5971 
5972 	if (arg->n_ssids) {
5973 		len += sizeof(struct wmi_ssid_list);
5974 		len += sizeof(struct wmi_ssid) * arg->n_ssids;
5975 	}
5976 
5977 	if (arg->n_bssids) {
5978 		len += sizeof(struct wmi_bssid_list);
5979 		len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
5980 	}
5981 
5982 	return len;
5983 }
5984 
5985 void ath10k_wmi_put_start_scan_common(struct wmi_start_scan_common *cmn,
5986 				      const struct wmi_start_scan_arg *arg)
5987 {
5988 	u32 scan_id;
5989 	u32 scan_req_id;
5990 
5991 	scan_id  = WMI_HOST_SCAN_REQ_ID_PREFIX;
5992 	scan_id |= arg->scan_id;
5993 
5994 	scan_req_id  = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
5995 	scan_req_id |= arg->scan_req_id;
5996 
5997 	cmn->scan_id            = __cpu_to_le32(scan_id);
5998 	cmn->scan_req_id        = __cpu_to_le32(scan_req_id);
5999 	cmn->vdev_id            = __cpu_to_le32(arg->vdev_id);
6000 	cmn->scan_priority      = __cpu_to_le32(arg->scan_priority);
6001 	cmn->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
6002 	cmn->dwell_time_active  = __cpu_to_le32(arg->dwell_time_active);
6003 	cmn->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
6004 	cmn->min_rest_time      = __cpu_to_le32(arg->min_rest_time);
6005 	cmn->max_rest_time      = __cpu_to_le32(arg->max_rest_time);
6006 	cmn->repeat_probe_time  = __cpu_to_le32(arg->repeat_probe_time);
6007 	cmn->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
6008 	cmn->idle_time          = __cpu_to_le32(arg->idle_time);
6009 	cmn->max_scan_time      = __cpu_to_le32(arg->max_scan_time);
6010 	cmn->probe_delay        = __cpu_to_le32(arg->probe_delay);
6011 	cmn->scan_ctrl_flags    = __cpu_to_le32(arg->scan_ctrl_flags);
6012 }
6013 
6014 static void
6015 ath10k_wmi_put_start_scan_tlvs(struct wmi_start_scan_tlvs *tlvs,
6016 			       const struct wmi_start_scan_arg *arg)
6017 {
6018 	struct wmi_ie_data *ie;
6019 	struct wmi_chan_list *channels;
6020 	struct wmi_ssid_list *ssids;
6021 	struct wmi_bssid_list *bssids;
6022 	void *ptr = tlvs->tlvs;
6023 	int i;
6024 
6025 	if (arg->n_channels) {
6026 		channels = ptr;
6027 		channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
6028 		channels->num_chan = __cpu_to_le32(arg->n_channels);
6029 
6030 		for (i = 0; i < arg->n_channels; i++)
6031 			channels->channel_list[i].freq =
6032 				__cpu_to_le16(arg->channels[i]);
6033 
6034 		ptr += sizeof(*channels);
6035 		ptr += sizeof(__le32) * arg->n_channels;
6036 	}
6037 
6038 	if (arg->n_ssids) {
6039 		ssids = ptr;
6040 		ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
6041 		ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
6042 
6043 		for (i = 0; i < arg->n_ssids; i++) {
6044 			ssids->ssids[i].ssid_len =
6045 				__cpu_to_le32(arg->ssids[i].len);
6046 			memcpy(&ssids->ssids[i].ssid,
6047 			       arg->ssids[i].ssid,
6048 			       arg->ssids[i].len);
6049 		}
6050 
6051 		ptr += sizeof(*ssids);
6052 		ptr += sizeof(struct wmi_ssid) * arg->n_ssids;
6053 	}
6054 
6055 	if (arg->n_bssids) {
6056 		bssids = ptr;
6057 		bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
6058 		bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
6059 
6060 		for (i = 0; i < arg->n_bssids; i++)
6061 			ether_addr_copy(bssids->bssid_list[i].addr,
6062 					arg->bssids[i].bssid);
6063 
6064 		ptr += sizeof(*bssids);
6065 		ptr += sizeof(struct wmi_mac_addr) * arg->n_bssids;
6066 	}
6067 
6068 	if (arg->ie_len) {
6069 		ie = ptr;
6070 		ie->tag = __cpu_to_le32(WMI_IE_TAG);
6071 		ie->ie_len = __cpu_to_le32(arg->ie_len);
6072 		memcpy(ie->ie_data, arg->ie, arg->ie_len);
6073 
6074 		ptr += sizeof(*ie);
6075 		ptr += roundup(arg->ie_len, 4);
6076 	}
6077 }
6078 
6079 static struct sk_buff *
6080 ath10k_wmi_op_gen_start_scan(struct ath10k *ar,
6081 			     const struct wmi_start_scan_arg *arg)
6082 {
6083 	struct wmi_start_scan_cmd *cmd;
6084 	struct sk_buff *skb;
6085 	size_t len;
6086 	int ret;
6087 
6088 	ret = ath10k_wmi_start_scan_verify(arg);
6089 	if (ret)
6090 		return ERR_PTR(ret);
6091 
6092 	len = sizeof(*cmd) + ath10k_wmi_start_scan_tlvs_len(arg);
6093 	skb = ath10k_wmi_alloc_skb(ar, len);
6094 	if (!skb)
6095 		return ERR_PTR(-ENOMEM);
6096 
6097 	cmd = (struct wmi_start_scan_cmd *)skb->data;
6098 
6099 	ath10k_wmi_put_start_scan_common(&cmd->common, arg);
6100 	ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
6101 
6102 	cmd->burst_duration_ms = __cpu_to_le32(0);
6103 
6104 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n");
6105 	return skb;
6106 }
6107 
6108 static struct sk_buff *
6109 ath10k_wmi_10x_op_gen_start_scan(struct ath10k *ar,
6110 				 const struct wmi_start_scan_arg *arg)
6111 {
6112 	struct wmi_10x_start_scan_cmd *cmd;
6113 	struct sk_buff *skb;
6114 	size_t len;
6115 	int ret;
6116 
6117 	ret = ath10k_wmi_start_scan_verify(arg);
6118 	if (ret)
6119 		return ERR_PTR(ret);
6120 
6121 	len = sizeof(*cmd) + ath10k_wmi_start_scan_tlvs_len(arg);
6122 	skb = ath10k_wmi_alloc_skb(ar, len);
6123 	if (!skb)
6124 		return ERR_PTR(-ENOMEM);
6125 
6126 	cmd = (struct wmi_10x_start_scan_cmd *)skb->data;
6127 
6128 	ath10k_wmi_put_start_scan_common(&cmd->common, arg);
6129 	ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
6130 
6131 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi 10x start scan\n");
6132 	return skb;
6133 }
6134 
6135 void ath10k_wmi_start_scan_init(struct ath10k *ar,
6136 				struct wmi_start_scan_arg *arg)
6137 {
6138 	/* setup commonly used values */
6139 	arg->scan_req_id = 1;
6140 	arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
6141 	arg->dwell_time_active = 50;
6142 	arg->dwell_time_passive = 150;
6143 	arg->min_rest_time = 50;
6144 	arg->max_rest_time = 500;
6145 	arg->repeat_probe_time = 0;
6146 	arg->probe_spacing_time = 0;
6147 	arg->idle_time = 0;
6148 	arg->max_scan_time = 20000;
6149 	arg->probe_delay = 5;
6150 	arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
6151 		| WMI_SCAN_EVENT_COMPLETED
6152 		| WMI_SCAN_EVENT_BSS_CHANNEL
6153 		| WMI_SCAN_EVENT_FOREIGN_CHANNEL
6154 		| WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT
6155 		| WMI_SCAN_EVENT_DEQUEUED;
6156 	arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
6157 	arg->n_bssids = 1;
6158 	arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
6159 }
6160 
6161 static struct sk_buff *
6162 ath10k_wmi_op_gen_stop_scan(struct ath10k *ar,
6163 			    const struct wmi_stop_scan_arg *arg)
6164 {
6165 	struct wmi_stop_scan_cmd *cmd;
6166 	struct sk_buff *skb;
6167 	u32 scan_id;
6168 	u32 req_id;
6169 
6170 	if (arg->req_id > 0xFFF)
6171 		return ERR_PTR(-EINVAL);
6172 	if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
6173 		return ERR_PTR(-EINVAL);
6174 
6175 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6176 	if (!skb)
6177 		return ERR_PTR(-ENOMEM);
6178 
6179 	scan_id = arg->u.scan_id;
6180 	scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
6181 
6182 	req_id = arg->req_id;
6183 	req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
6184 
6185 	cmd = (struct wmi_stop_scan_cmd *)skb->data;
6186 	cmd->req_type    = __cpu_to_le32(arg->req_type);
6187 	cmd->vdev_id     = __cpu_to_le32(arg->u.vdev_id);
6188 	cmd->scan_id     = __cpu_to_le32(scan_id);
6189 	cmd->scan_req_id = __cpu_to_le32(req_id);
6190 
6191 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6192 		   "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
6193 		   arg->req_id, arg->req_type, arg->u.scan_id);
6194 	return skb;
6195 }
6196 
6197 static struct sk_buff *
6198 ath10k_wmi_op_gen_vdev_create(struct ath10k *ar, u32 vdev_id,
6199 			      enum wmi_vdev_type type,
6200 			      enum wmi_vdev_subtype subtype,
6201 			      const u8 macaddr[ETH_ALEN])
6202 {
6203 	struct wmi_vdev_create_cmd *cmd;
6204 	struct sk_buff *skb;
6205 
6206 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6207 	if (!skb)
6208 		return ERR_PTR(-ENOMEM);
6209 
6210 	cmd = (struct wmi_vdev_create_cmd *)skb->data;
6211 	cmd->vdev_id      = __cpu_to_le32(vdev_id);
6212 	cmd->vdev_type    = __cpu_to_le32(type);
6213 	cmd->vdev_subtype = __cpu_to_le32(subtype);
6214 	ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
6215 
6216 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6217 		   "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
6218 		   vdev_id, type, subtype, macaddr);
6219 	return skb;
6220 }
6221 
6222 static struct sk_buff *
6223 ath10k_wmi_op_gen_vdev_delete(struct ath10k *ar, u32 vdev_id)
6224 {
6225 	struct wmi_vdev_delete_cmd *cmd;
6226 	struct sk_buff *skb;
6227 
6228 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6229 	if (!skb)
6230 		return ERR_PTR(-ENOMEM);
6231 
6232 	cmd = (struct wmi_vdev_delete_cmd *)skb->data;
6233 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6234 
6235 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6236 		   "WMI vdev delete id %d\n", vdev_id);
6237 	return skb;
6238 }
6239 
6240 static struct sk_buff *
6241 ath10k_wmi_op_gen_vdev_start(struct ath10k *ar,
6242 			     const struct wmi_vdev_start_request_arg *arg,
6243 			     bool restart)
6244 {
6245 	struct wmi_vdev_start_request_cmd *cmd;
6246 	struct sk_buff *skb;
6247 	const char *cmdname;
6248 	u32 flags = 0;
6249 
6250 	if (WARN_ON(arg->hidden_ssid && !arg->ssid))
6251 		return ERR_PTR(-EINVAL);
6252 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
6253 		return ERR_PTR(-EINVAL);
6254 
6255 	if (restart)
6256 		cmdname = "restart";
6257 	else
6258 		cmdname = "start";
6259 
6260 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6261 	if (!skb)
6262 		return ERR_PTR(-ENOMEM);
6263 
6264 	if (arg->hidden_ssid)
6265 		flags |= WMI_VDEV_START_HIDDEN_SSID;
6266 	if (arg->pmf_enabled)
6267 		flags |= WMI_VDEV_START_PMF_ENABLED;
6268 
6269 	cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
6270 	cmd->vdev_id         = __cpu_to_le32(arg->vdev_id);
6271 	cmd->disable_hw_ack  = __cpu_to_le32(arg->disable_hw_ack);
6272 	cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
6273 	cmd->dtim_period     = __cpu_to_le32(arg->dtim_period);
6274 	cmd->flags           = __cpu_to_le32(flags);
6275 	cmd->bcn_tx_rate     = __cpu_to_le32(arg->bcn_tx_rate);
6276 	cmd->bcn_tx_power    = __cpu_to_le32(arg->bcn_tx_power);
6277 
6278 	if (arg->ssid) {
6279 		cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
6280 		memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
6281 	}
6282 
6283 	ath10k_wmi_put_wmi_channel(&cmd->chan, &arg->channel);
6284 
6285 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6286 		   "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n",
6287 		   cmdname, arg->vdev_id,
6288 		   flags, arg->channel.freq, arg->channel.mode,
6289 		   cmd->chan.flags, arg->channel.max_power);
6290 
6291 	return skb;
6292 }
6293 
6294 static struct sk_buff *
6295 ath10k_wmi_op_gen_vdev_stop(struct ath10k *ar, u32 vdev_id)
6296 {
6297 	struct wmi_vdev_stop_cmd *cmd;
6298 	struct sk_buff *skb;
6299 
6300 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6301 	if (!skb)
6302 		return ERR_PTR(-ENOMEM);
6303 
6304 	cmd = (struct wmi_vdev_stop_cmd *)skb->data;
6305 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6306 
6307 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
6308 	return skb;
6309 }
6310 
6311 static struct sk_buff *
6312 ath10k_wmi_op_gen_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid,
6313 			  const u8 *bssid)
6314 {
6315 	struct wmi_vdev_up_cmd *cmd;
6316 	struct sk_buff *skb;
6317 
6318 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6319 	if (!skb)
6320 		return ERR_PTR(-ENOMEM);
6321 
6322 	cmd = (struct wmi_vdev_up_cmd *)skb->data;
6323 	cmd->vdev_id       = __cpu_to_le32(vdev_id);
6324 	cmd->vdev_assoc_id = __cpu_to_le32(aid);
6325 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
6326 
6327 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6328 		   "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
6329 		   vdev_id, aid, bssid);
6330 	return skb;
6331 }
6332 
6333 static struct sk_buff *
6334 ath10k_wmi_op_gen_vdev_down(struct ath10k *ar, u32 vdev_id)
6335 {
6336 	struct wmi_vdev_down_cmd *cmd;
6337 	struct sk_buff *skb;
6338 
6339 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6340 	if (!skb)
6341 		return ERR_PTR(-ENOMEM);
6342 
6343 	cmd = (struct wmi_vdev_down_cmd *)skb->data;
6344 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6345 
6346 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6347 		   "wmi mgmt vdev down id 0x%x\n", vdev_id);
6348 	return skb;
6349 }
6350 
6351 static struct sk_buff *
6352 ath10k_wmi_op_gen_vdev_set_param(struct ath10k *ar, u32 vdev_id,
6353 				 u32 param_id, u32 param_value)
6354 {
6355 	struct wmi_vdev_set_param_cmd *cmd;
6356 	struct sk_buff *skb;
6357 
6358 	if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
6359 		ath10k_dbg(ar, ATH10K_DBG_WMI,
6360 			   "vdev param %d not supported by firmware\n",
6361 			    param_id);
6362 		return ERR_PTR(-EOPNOTSUPP);
6363 	}
6364 
6365 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6366 	if (!skb)
6367 		return ERR_PTR(-ENOMEM);
6368 
6369 	cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
6370 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
6371 	cmd->param_id    = __cpu_to_le32(param_id);
6372 	cmd->param_value = __cpu_to_le32(param_value);
6373 
6374 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6375 		   "wmi vdev id 0x%x set param %d value %d\n",
6376 		   vdev_id, param_id, param_value);
6377 	return skb;
6378 }
6379 
6380 static struct sk_buff *
6381 ath10k_wmi_op_gen_vdev_install_key(struct ath10k *ar,
6382 				   const struct wmi_vdev_install_key_arg *arg)
6383 {
6384 	struct wmi_vdev_install_key_cmd *cmd;
6385 	struct sk_buff *skb;
6386 
6387 	if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
6388 		return ERR_PTR(-EINVAL);
6389 	if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
6390 		return ERR_PTR(-EINVAL);
6391 
6392 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + arg->key_len);
6393 	if (!skb)
6394 		return ERR_PTR(-ENOMEM);
6395 
6396 	cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
6397 	cmd->vdev_id       = __cpu_to_le32(arg->vdev_id);
6398 	cmd->key_idx       = __cpu_to_le32(arg->key_idx);
6399 	cmd->key_flags     = __cpu_to_le32(arg->key_flags);
6400 	cmd->key_cipher    = __cpu_to_le32(arg->key_cipher);
6401 	cmd->key_len       = __cpu_to_le32(arg->key_len);
6402 	cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
6403 	cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
6404 
6405 	if (arg->macaddr)
6406 		ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
6407 	if (arg->key_data)
6408 		memcpy(cmd->key_data, arg->key_data, arg->key_len);
6409 
6410 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6411 		   "wmi vdev install key idx %d cipher %d len %d\n",
6412 		   arg->key_idx, arg->key_cipher, arg->key_len);
6413 	return skb;
6414 }
6415 
6416 static struct sk_buff *
6417 ath10k_wmi_op_gen_vdev_spectral_conf(struct ath10k *ar,
6418 				     const struct wmi_vdev_spectral_conf_arg *arg)
6419 {
6420 	struct wmi_vdev_spectral_conf_cmd *cmd;
6421 	struct sk_buff *skb;
6422 
6423 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6424 	if (!skb)
6425 		return ERR_PTR(-ENOMEM);
6426 
6427 	cmd = (struct wmi_vdev_spectral_conf_cmd *)skb->data;
6428 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
6429 	cmd->scan_count = __cpu_to_le32(arg->scan_count);
6430 	cmd->scan_period = __cpu_to_le32(arg->scan_period);
6431 	cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
6432 	cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
6433 	cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
6434 	cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
6435 	cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
6436 	cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
6437 	cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
6438 	cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
6439 	cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
6440 	cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
6441 	cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
6442 	cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
6443 	cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
6444 	cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
6445 	cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
6446 	cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
6447 
6448 	return skb;
6449 }
6450 
6451 static struct sk_buff *
6452 ath10k_wmi_op_gen_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id,
6453 				       u32 trigger, u32 enable)
6454 {
6455 	struct wmi_vdev_spectral_enable_cmd *cmd;
6456 	struct sk_buff *skb;
6457 
6458 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6459 	if (!skb)
6460 		return ERR_PTR(-ENOMEM);
6461 
6462 	cmd = (struct wmi_vdev_spectral_enable_cmd *)skb->data;
6463 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6464 	cmd->trigger_cmd = __cpu_to_le32(trigger);
6465 	cmd->enable_cmd = __cpu_to_le32(enable);
6466 
6467 	return skb;
6468 }
6469 
6470 static struct sk_buff *
6471 ath10k_wmi_op_gen_peer_create(struct ath10k *ar, u32 vdev_id,
6472 			      const u8 peer_addr[ETH_ALEN],
6473 			      enum wmi_peer_type peer_type)
6474 {
6475 	struct wmi_peer_create_cmd *cmd;
6476 	struct sk_buff *skb;
6477 
6478 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6479 	if (!skb)
6480 		return ERR_PTR(-ENOMEM);
6481 
6482 	cmd = (struct wmi_peer_create_cmd *)skb->data;
6483 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6484 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6485 
6486 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6487 		   "wmi peer create vdev_id %d peer_addr %pM\n",
6488 		   vdev_id, peer_addr);
6489 	return skb;
6490 }
6491 
6492 static struct sk_buff *
6493 ath10k_wmi_op_gen_peer_delete(struct ath10k *ar, u32 vdev_id,
6494 			      const u8 peer_addr[ETH_ALEN])
6495 {
6496 	struct wmi_peer_delete_cmd *cmd;
6497 	struct sk_buff *skb;
6498 
6499 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6500 	if (!skb)
6501 		return ERR_PTR(-ENOMEM);
6502 
6503 	cmd = (struct wmi_peer_delete_cmd *)skb->data;
6504 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6505 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6506 
6507 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6508 		   "wmi peer delete vdev_id %d peer_addr %pM\n",
6509 		   vdev_id, peer_addr);
6510 	return skb;
6511 }
6512 
6513 static struct sk_buff *
6514 ath10k_wmi_op_gen_peer_flush(struct ath10k *ar, u32 vdev_id,
6515 			     const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
6516 {
6517 	struct wmi_peer_flush_tids_cmd *cmd;
6518 	struct sk_buff *skb;
6519 
6520 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6521 	if (!skb)
6522 		return ERR_PTR(-ENOMEM);
6523 
6524 	cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
6525 	cmd->vdev_id         = __cpu_to_le32(vdev_id);
6526 	cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
6527 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6528 
6529 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6530 		   "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
6531 		   vdev_id, peer_addr, tid_bitmap);
6532 	return skb;
6533 }
6534 
6535 static struct sk_buff *
6536 ath10k_wmi_op_gen_peer_set_param(struct ath10k *ar, u32 vdev_id,
6537 				 const u8 *peer_addr,
6538 				 enum wmi_peer_param param_id,
6539 				 u32 param_value)
6540 {
6541 	struct wmi_peer_set_param_cmd *cmd;
6542 	struct sk_buff *skb;
6543 
6544 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6545 	if (!skb)
6546 		return ERR_PTR(-ENOMEM);
6547 
6548 	cmd = (struct wmi_peer_set_param_cmd *)skb->data;
6549 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
6550 	cmd->param_id    = __cpu_to_le32(param_id);
6551 	cmd->param_value = __cpu_to_le32(param_value);
6552 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
6553 
6554 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6555 		   "wmi vdev %d peer 0x%pM set param %d value %d\n",
6556 		   vdev_id, peer_addr, param_id, param_value);
6557 	return skb;
6558 }
6559 
6560 static struct sk_buff *
6561 ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
6562 			     enum wmi_sta_ps_mode psmode)
6563 {
6564 	struct wmi_sta_powersave_mode_cmd *cmd;
6565 	struct sk_buff *skb;
6566 
6567 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6568 	if (!skb)
6569 		return ERR_PTR(-ENOMEM);
6570 
6571 	cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
6572 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
6573 	cmd->sta_ps_mode = __cpu_to_le32(psmode);
6574 
6575 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6576 		   "wmi set powersave id 0x%x mode %d\n",
6577 		   vdev_id, psmode);
6578 	return skb;
6579 }
6580 
6581 static struct sk_buff *
6582 ath10k_wmi_op_gen_set_sta_ps(struct ath10k *ar, u32 vdev_id,
6583 			     enum wmi_sta_powersave_param param_id,
6584 			     u32 value)
6585 {
6586 	struct wmi_sta_powersave_param_cmd *cmd;
6587 	struct sk_buff *skb;
6588 
6589 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6590 	if (!skb)
6591 		return ERR_PTR(-ENOMEM);
6592 
6593 	cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
6594 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
6595 	cmd->param_id    = __cpu_to_le32(param_id);
6596 	cmd->param_value = __cpu_to_le32(value);
6597 
6598 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6599 		   "wmi sta ps param vdev_id 0x%x param %d value %d\n",
6600 		   vdev_id, param_id, value);
6601 	return skb;
6602 }
6603 
6604 static struct sk_buff *
6605 ath10k_wmi_op_gen_set_ap_ps(struct ath10k *ar, u32 vdev_id, const u8 *mac,
6606 			    enum wmi_ap_ps_peer_param param_id, u32 value)
6607 {
6608 	struct wmi_ap_ps_peer_cmd *cmd;
6609 	struct sk_buff *skb;
6610 
6611 	if (!mac)
6612 		return ERR_PTR(-EINVAL);
6613 
6614 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6615 	if (!skb)
6616 		return ERR_PTR(-ENOMEM);
6617 
6618 	cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
6619 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6620 	cmd->param_id = __cpu_to_le32(param_id);
6621 	cmd->param_value = __cpu_to_le32(value);
6622 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
6623 
6624 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6625 		   "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
6626 		   vdev_id, param_id, value, mac);
6627 	return skb;
6628 }
6629 
6630 static struct sk_buff *
6631 ath10k_wmi_op_gen_scan_chan_list(struct ath10k *ar,
6632 				 const struct wmi_scan_chan_list_arg *arg)
6633 {
6634 	struct wmi_scan_chan_list_cmd *cmd;
6635 	struct sk_buff *skb;
6636 	struct wmi_channel_arg *ch;
6637 	struct wmi_channel *ci;
6638 	int len;
6639 	int i;
6640 
6641 	len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
6642 
6643 	skb = ath10k_wmi_alloc_skb(ar, len);
6644 	if (!skb)
6645 		return ERR_PTR(-EINVAL);
6646 
6647 	cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
6648 	cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
6649 
6650 	for (i = 0; i < arg->n_channels; i++) {
6651 		ch = &arg->channels[i];
6652 		ci = &cmd->chan_info[i];
6653 
6654 		ath10k_wmi_put_wmi_channel(ci, ch);
6655 	}
6656 
6657 	return skb;
6658 }
6659 
6660 static void
6661 ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
6662 			   const struct wmi_peer_assoc_complete_arg *arg)
6663 {
6664 	struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
6665 
6666 	cmd->vdev_id            = __cpu_to_le32(arg->vdev_id);
6667 	cmd->peer_new_assoc     = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
6668 	cmd->peer_associd       = __cpu_to_le32(arg->peer_aid);
6669 	cmd->peer_flags         = __cpu_to_le32(arg->peer_flags);
6670 	cmd->peer_caps          = __cpu_to_le32(arg->peer_caps);
6671 	cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
6672 	cmd->peer_ht_caps       = __cpu_to_le32(arg->peer_ht_caps);
6673 	cmd->peer_max_mpdu      = __cpu_to_le32(arg->peer_max_mpdu);
6674 	cmd->peer_mpdu_density  = __cpu_to_le32(arg->peer_mpdu_density);
6675 	cmd->peer_rate_caps     = __cpu_to_le32(arg->peer_rate_caps);
6676 	cmd->peer_nss           = __cpu_to_le32(arg->peer_num_spatial_streams);
6677 	cmd->peer_vht_caps      = __cpu_to_le32(arg->peer_vht_caps);
6678 	cmd->peer_phymode       = __cpu_to_le32(arg->peer_phymode);
6679 
6680 	ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
6681 
6682 	cmd->peer_legacy_rates.num_rates =
6683 		__cpu_to_le32(arg->peer_legacy_rates.num_rates);
6684 	memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
6685 	       arg->peer_legacy_rates.num_rates);
6686 
6687 	cmd->peer_ht_rates.num_rates =
6688 		__cpu_to_le32(arg->peer_ht_rates.num_rates);
6689 	memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
6690 	       arg->peer_ht_rates.num_rates);
6691 
6692 	cmd->peer_vht_rates.rx_max_rate =
6693 		__cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
6694 	cmd->peer_vht_rates.rx_mcs_set =
6695 		__cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
6696 	cmd->peer_vht_rates.tx_max_rate =
6697 		__cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
6698 	cmd->peer_vht_rates.tx_mcs_set =
6699 		__cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
6700 }
6701 
6702 static void
6703 ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
6704 				const struct wmi_peer_assoc_complete_arg *arg)
6705 {
6706 	struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
6707 
6708 	ath10k_wmi_peer_assoc_fill(ar, buf, arg);
6709 	memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
6710 }
6711 
6712 static void
6713 ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
6714 				const struct wmi_peer_assoc_complete_arg *arg)
6715 {
6716 	ath10k_wmi_peer_assoc_fill(ar, buf, arg);
6717 }
6718 
6719 static void
6720 ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
6721 				const struct wmi_peer_assoc_complete_arg *arg)
6722 {
6723 	struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
6724 	int max_mcs, max_nss;
6725 	u32 info0;
6726 
6727 	/* TODO: Is using max values okay with firmware? */
6728 	max_mcs = 0xf;
6729 	max_nss = 0xf;
6730 
6731 	info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
6732 		SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
6733 
6734 	ath10k_wmi_peer_assoc_fill(ar, buf, arg);
6735 	cmd->info0 = __cpu_to_le32(info0);
6736 }
6737 
6738 static void
6739 ath10k_wmi_peer_assoc_fill_10_4(struct ath10k *ar, void *buf,
6740 				const struct wmi_peer_assoc_complete_arg *arg)
6741 {
6742 	struct wmi_10_4_peer_assoc_complete_cmd *cmd = buf;
6743 
6744 	ath10k_wmi_peer_assoc_fill_10_2(ar, buf, arg);
6745 	cmd->peer_bw_rxnss_override = 0;
6746 }
6747 
6748 static int
6749 ath10k_wmi_peer_assoc_check_arg(const struct wmi_peer_assoc_complete_arg *arg)
6750 {
6751 	if (arg->peer_mpdu_density > 16)
6752 		return -EINVAL;
6753 	if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
6754 		return -EINVAL;
6755 	if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
6756 		return -EINVAL;
6757 
6758 	return 0;
6759 }
6760 
6761 static struct sk_buff *
6762 ath10k_wmi_op_gen_peer_assoc(struct ath10k *ar,
6763 			     const struct wmi_peer_assoc_complete_arg *arg)
6764 {
6765 	size_t len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
6766 	struct sk_buff *skb;
6767 	int ret;
6768 
6769 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
6770 	if (ret)
6771 		return ERR_PTR(ret);
6772 
6773 	skb = ath10k_wmi_alloc_skb(ar, len);
6774 	if (!skb)
6775 		return ERR_PTR(-ENOMEM);
6776 
6777 	ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
6778 
6779 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6780 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
6781 		   arg->vdev_id, arg->addr,
6782 		   arg->peer_reassoc ? "reassociate" : "new");
6783 	return skb;
6784 }
6785 
6786 static struct sk_buff *
6787 ath10k_wmi_10_1_op_gen_peer_assoc(struct ath10k *ar,
6788 				  const struct wmi_peer_assoc_complete_arg *arg)
6789 {
6790 	size_t len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
6791 	struct sk_buff *skb;
6792 	int ret;
6793 
6794 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
6795 	if (ret)
6796 		return ERR_PTR(ret);
6797 
6798 	skb = ath10k_wmi_alloc_skb(ar, len);
6799 	if (!skb)
6800 		return ERR_PTR(-ENOMEM);
6801 
6802 	ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
6803 
6804 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6805 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
6806 		   arg->vdev_id, arg->addr,
6807 		   arg->peer_reassoc ? "reassociate" : "new");
6808 	return skb;
6809 }
6810 
6811 static struct sk_buff *
6812 ath10k_wmi_10_2_op_gen_peer_assoc(struct ath10k *ar,
6813 				  const struct wmi_peer_assoc_complete_arg *arg)
6814 {
6815 	size_t len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
6816 	struct sk_buff *skb;
6817 	int ret;
6818 
6819 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
6820 	if (ret)
6821 		return ERR_PTR(ret);
6822 
6823 	skb = ath10k_wmi_alloc_skb(ar, len);
6824 	if (!skb)
6825 		return ERR_PTR(-ENOMEM);
6826 
6827 	ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
6828 
6829 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6830 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
6831 		   arg->vdev_id, arg->addr,
6832 		   arg->peer_reassoc ? "reassociate" : "new");
6833 	return skb;
6834 }
6835 
6836 static struct sk_buff *
6837 ath10k_wmi_10_4_op_gen_peer_assoc(struct ath10k *ar,
6838 				  const struct wmi_peer_assoc_complete_arg *arg)
6839 {
6840 	size_t len = sizeof(struct wmi_10_4_peer_assoc_complete_cmd);
6841 	struct sk_buff *skb;
6842 	int ret;
6843 
6844 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
6845 	if (ret)
6846 		return ERR_PTR(ret);
6847 
6848 	skb = ath10k_wmi_alloc_skb(ar, len);
6849 	if (!skb)
6850 		return ERR_PTR(-ENOMEM);
6851 
6852 	ath10k_wmi_peer_assoc_fill_10_4(ar, skb->data, arg);
6853 
6854 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6855 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
6856 		   arg->vdev_id, arg->addr,
6857 		   arg->peer_reassoc ? "reassociate" : "new");
6858 	return skb;
6859 }
6860 
6861 static struct sk_buff *
6862 ath10k_wmi_10_2_op_gen_pdev_get_temperature(struct ath10k *ar)
6863 {
6864 	struct sk_buff *skb;
6865 
6866 	skb = ath10k_wmi_alloc_skb(ar, 0);
6867 	if (!skb)
6868 		return ERR_PTR(-ENOMEM);
6869 
6870 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev get temperature\n");
6871 	return skb;
6872 }
6873 
6874 static struct sk_buff *
6875 ath10k_wmi_10_2_op_gen_pdev_bss_chan_info(struct ath10k *ar,
6876 					  enum wmi_bss_survey_req_type type)
6877 {
6878 	struct wmi_pdev_chan_info_req_cmd *cmd;
6879 	struct sk_buff *skb;
6880 
6881 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6882 	if (!skb)
6883 		return ERR_PTR(-ENOMEM);
6884 
6885 	cmd = (struct wmi_pdev_chan_info_req_cmd *)skb->data;
6886 	cmd->type = __cpu_to_le32(type);
6887 
6888 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6889 		   "wmi pdev bss info request type %d\n", type);
6890 
6891 	return skb;
6892 }
6893 
6894 /* This function assumes the beacon is already DMA mapped */
6895 static struct sk_buff *
6896 ath10k_wmi_op_gen_beacon_dma(struct ath10k *ar, u32 vdev_id, const void *bcn,
6897 			     size_t bcn_len, u32 bcn_paddr, bool dtim_zero,
6898 			     bool deliver_cab)
6899 {
6900 	struct wmi_bcn_tx_ref_cmd *cmd;
6901 	struct sk_buff *skb;
6902 	struct ieee80211_hdr *hdr;
6903 	u16 fc;
6904 
6905 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6906 	if (!skb)
6907 		return ERR_PTR(-ENOMEM);
6908 
6909 	hdr = (struct ieee80211_hdr *)bcn;
6910 	fc = le16_to_cpu(hdr->frame_control);
6911 
6912 	cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
6913 	cmd->vdev_id = __cpu_to_le32(vdev_id);
6914 	cmd->data_len = __cpu_to_le32(bcn_len);
6915 	cmd->data_ptr = __cpu_to_le32(bcn_paddr);
6916 	cmd->msdu_id = 0;
6917 	cmd->frame_control = __cpu_to_le32(fc);
6918 	cmd->flags = 0;
6919 	cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
6920 
6921 	if (dtim_zero)
6922 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
6923 
6924 	if (deliver_cab)
6925 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
6926 
6927 	return skb;
6928 }
6929 
6930 void ath10k_wmi_set_wmm_param(struct wmi_wmm_params *params,
6931 			      const struct wmi_wmm_params_arg *arg)
6932 {
6933 	params->cwmin  = __cpu_to_le32(arg->cwmin);
6934 	params->cwmax  = __cpu_to_le32(arg->cwmax);
6935 	params->aifs   = __cpu_to_le32(arg->aifs);
6936 	params->txop   = __cpu_to_le32(arg->txop);
6937 	params->acm    = __cpu_to_le32(arg->acm);
6938 	params->no_ack = __cpu_to_le32(arg->no_ack);
6939 }
6940 
6941 static struct sk_buff *
6942 ath10k_wmi_op_gen_pdev_set_wmm(struct ath10k *ar,
6943 			       const struct wmi_wmm_params_all_arg *arg)
6944 {
6945 	struct wmi_pdev_set_wmm_params *cmd;
6946 	struct sk_buff *skb;
6947 
6948 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6949 	if (!skb)
6950 		return ERR_PTR(-ENOMEM);
6951 
6952 	cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
6953 	ath10k_wmi_set_wmm_param(&cmd->ac_be, &arg->ac_be);
6954 	ath10k_wmi_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
6955 	ath10k_wmi_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
6956 	ath10k_wmi_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
6957 
6958 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
6959 	return skb;
6960 }
6961 
6962 static struct sk_buff *
6963 ath10k_wmi_op_gen_request_stats(struct ath10k *ar, u32 stats_mask)
6964 {
6965 	struct wmi_request_stats_cmd *cmd;
6966 	struct sk_buff *skb;
6967 
6968 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6969 	if (!skb)
6970 		return ERR_PTR(-ENOMEM);
6971 
6972 	cmd = (struct wmi_request_stats_cmd *)skb->data;
6973 	cmd->stats_id = __cpu_to_le32(stats_mask);
6974 
6975 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi request stats 0x%08x\n",
6976 		   stats_mask);
6977 	return skb;
6978 }
6979 
6980 static struct sk_buff *
6981 ath10k_wmi_op_gen_force_fw_hang(struct ath10k *ar,
6982 				enum wmi_force_fw_hang_type type, u32 delay_ms)
6983 {
6984 	struct wmi_force_fw_hang_cmd *cmd;
6985 	struct sk_buff *skb;
6986 
6987 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6988 	if (!skb)
6989 		return ERR_PTR(-ENOMEM);
6990 
6991 	cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
6992 	cmd->type = __cpu_to_le32(type);
6993 	cmd->delay_ms = __cpu_to_le32(delay_ms);
6994 
6995 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
6996 		   type, delay_ms);
6997 	return skb;
6998 }
6999 
7000 static struct sk_buff *
7001 ath10k_wmi_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
7002 			     u32 log_level)
7003 {
7004 	struct wmi_dbglog_cfg_cmd *cmd;
7005 	struct sk_buff *skb;
7006 	u32 cfg;
7007 
7008 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7009 	if (!skb)
7010 		return ERR_PTR(-ENOMEM);
7011 
7012 	cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
7013 
7014 	if (module_enable) {
7015 		cfg = SM(log_level,
7016 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7017 	} else {
7018 		/* set back defaults, all modules with WARN level */
7019 		cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
7020 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7021 		module_enable = ~0;
7022 	}
7023 
7024 	cmd->module_enable = __cpu_to_le32(module_enable);
7025 	cmd->module_valid = __cpu_to_le32(~0);
7026 	cmd->config_enable = __cpu_to_le32(cfg);
7027 	cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
7028 
7029 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7030 		   "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
7031 		   __le32_to_cpu(cmd->module_enable),
7032 		   __le32_to_cpu(cmd->module_valid),
7033 		   __le32_to_cpu(cmd->config_enable),
7034 		   __le32_to_cpu(cmd->config_valid));
7035 	return skb;
7036 }
7037 
7038 static struct sk_buff *
7039 ath10k_wmi_10_4_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
7040 				  u32 log_level)
7041 {
7042 	struct wmi_10_4_dbglog_cfg_cmd *cmd;
7043 	struct sk_buff *skb;
7044 	u32 cfg;
7045 
7046 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7047 	if (!skb)
7048 		return ERR_PTR(-ENOMEM);
7049 
7050 	cmd = (struct wmi_10_4_dbglog_cfg_cmd *)skb->data;
7051 
7052 	if (module_enable) {
7053 		cfg = SM(log_level,
7054 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7055 	} else {
7056 		/* set back defaults, all modules with WARN level */
7057 		cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
7058 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7059 		module_enable = ~0;
7060 	}
7061 
7062 	cmd->module_enable = __cpu_to_le64(module_enable);
7063 	cmd->module_valid = __cpu_to_le64(~0);
7064 	cmd->config_enable = __cpu_to_le32(cfg);
7065 	cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
7066 
7067 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7068 		   "wmi dbglog cfg modules 0x%016llx 0x%016llx config %08x %08x\n",
7069 		   __le64_to_cpu(cmd->module_enable),
7070 		   __le64_to_cpu(cmd->module_valid),
7071 		   __le32_to_cpu(cmd->config_enable),
7072 		   __le32_to_cpu(cmd->config_valid));
7073 	return skb;
7074 }
7075 
7076 static struct sk_buff *
7077 ath10k_wmi_op_gen_pktlog_enable(struct ath10k *ar, u32 ev_bitmap)
7078 {
7079 	struct wmi_pdev_pktlog_enable_cmd *cmd;
7080 	struct sk_buff *skb;
7081 
7082 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7083 	if (!skb)
7084 		return ERR_PTR(-ENOMEM);
7085 
7086 	ev_bitmap &= ATH10K_PKTLOG_ANY;
7087 
7088 	cmd = (struct wmi_pdev_pktlog_enable_cmd *)skb->data;
7089 	cmd->ev_bitmap = __cpu_to_le32(ev_bitmap);
7090 
7091 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi enable pktlog filter 0x%08x\n",
7092 		   ev_bitmap);
7093 	return skb;
7094 }
7095 
7096 static struct sk_buff *
7097 ath10k_wmi_op_gen_pktlog_disable(struct ath10k *ar)
7098 {
7099 	struct sk_buff *skb;
7100 
7101 	skb = ath10k_wmi_alloc_skb(ar, 0);
7102 	if (!skb)
7103 		return ERR_PTR(-ENOMEM);
7104 
7105 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi disable pktlog\n");
7106 	return skb;
7107 }
7108 
7109 static struct sk_buff *
7110 ath10k_wmi_op_gen_pdev_set_quiet_mode(struct ath10k *ar, u32 period,
7111 				      u32 duration, u32 next_offset,
7112 				      u32 enabled)
7113 {
7114 	struct wmi_pdev_set_quiet_cmd *cmd;
7115 	struct sk_buff *skb;
7116 
7117 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7118 	if (!skb)
7119 		return ERR_PTR(-ENOMEM);
7120 
7121 	cmd = (struct wmi_pdev_set_quiet_cmd *)skb->data;
7122 	cmd->period = __cpu_to_le32(period);
7123 	cmd->duration = __cpu_to_le32(duration);
7124 	cmd->next_start = __cpu_to_le32(next_offset);
7125 	cmd->enabled = __cpu_to_le32(enabled);
7126 
7127 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7128 		   "wmi quiet param: period %u duration %u enabled %d\n",
7129 		   period, duration, enabled);
7130 	return skb;
7131 }
7132 
7133 static struct sk_buff *
7134 ath10k_wmi_op_gen_addba_clear_resp(struct ath10k *ar, u32 vdev_id,
7135 				   const u8 *mac)
7136 {
7137 	struct wmi_addba_clear_resp_cmd *cmd;
7138 	struct sk_buff *skb;
7139 
7140 	if (!mac)
7141 		return ERR_PTR(-EINVAL);
7142 
7143 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7144 	if (!skb)
7145 		return ERR_PTR(-ENOMEM);
7146 
7147 	cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
7148 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7149 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
7150 
7151 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7152 		   "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
7153 		   vdev_id, mac);
7154 	return skb;
7155 }
7156 
7157 static struct sk_buff *
7158 ath10k_wmi_op_gen_addba_send(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7159 			     u32 tid, u32 buf_size)
7160 {
7161 	struct wmi_addba_send_cmd *cmd;
7162 	struct sk_buff *skb;
7163 
7164 	if (!mac)
7165 		return ERR_PTR(-EINVAL);
7166 
7167 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7168 	if (!skb)
7169 		return ERR_PTR(-ENOMEM);
7170 
7171 	cmd = (struct wmi_addba_send_cmd *)skb->data;
7172 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7173 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
7174 	cmd->tid = __cpu_to_le32(tid);
7175 	cmd->buffersize = __cpu_to_le32(buf_size);
7176 
7177 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7178 		   "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
7179 		   vdev_id, mac, tid, buf_size);
7180 	return skb;
7181 }
7182 
7183 static struct sk_buff *
7184 ath10k_wmi_op_gen_addba_set_resp(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7185 				 u32 tid, u32 status)
7186 {
7187 	struct wmi_addba_setresponse_cmd *cmd;
7188 	struct sk_buff *skb;
7189 
7190 	if (!mac)
7191 		return ERR_PTR(-EINVAL);
7192 
7193 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7194 	if (!skb)
7195 		return ERR_PTR(-ENOMEM);
7196 
7197 	cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
7198 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7199 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
7200 	cmd->tid = __cpu_to_le32(tid);
7201 	cmd->statuscode = __cpu_to_le32(status);
7202 
7203 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7204 		   "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
7205 		   vdev_id, mac, tid, status);
7206 	return skb;
7207 }
7208 
7209 static struct sk_buff *
7210 ath10k_wmi_op_gen_delba_send(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7211 			     u32 tid, u32 initiator, u32 reason)
7212 {
7213 	struct wmi_delba_send_cmd *cmd;
7214 	struct sk_buff *skb;
7215 
7216 	if (!mac)
7217 		return ERR_PTR(-EINVAL);
7218 
7219 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7220 	if (!skb)
7221 		return ERR_PTR(-ENOMEM);
7222 
7223 	cmd = (struct wmi_delba_send_cmd *)skb->data;
7224 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7225 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
7226 	cmd->tid = __cpu_to_le32(tid);
7227 	cmd->initiator = __cpu_to_le32(initiator);
7228 	cmd->reasoncode = __cpu_to_le32(reason);
7229 
7230 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7231 		   "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
7232 		   vdev_id, mac, tid, initiator, reason);
7233 	return skb;
7234 }
7235 
7236 static struct sk_buff *
7237 ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config(struct ath10k *ar, u32 param)
7238 {
7239 	struct wmi_pdev_get_tpc_config_cmd *cmd;
7240 	struct sk_buff *skb;
7241 
7242 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7243 	if (!skb)
7244 		return ERR_PTR(-ENOMEM);
7245 
7246 	cmd = (struct wmi_pdev_get_tpc_config_cmd *)skb->data;
7247 	cmd->param = __cpu_to_le32(param);
7248 
7249 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7250 		   "wmi pdev get tcp config param:%d\n", param);
7251 	return skb;
7252 }
7253 
7254 size_t ath10k_wmi_fw_stats_num_peers(struct list_head *head)
7255 {
7256 	struct ath10k_fw_stats_peer *i;
7257 	size_t num = 0;
7258 
7259 	list_for_each_entry(i, head, list)
7260 		++num;
7261 
7262 	return num;
7263 }
7264 
7265 size_t ath10k_wmi_fw_stats_num_vdevs(struct list_head *head)
7266 {
7267 	struct ath10k_fw_stats_vdev *i;
7268 	size_t num = 0;
7269 
7270 	list_for_each_entry(i, head, list)
7271 		++num;
7272 
7273 	return num;
7274 }
7275 
7276 static void
7277 ath10k_wmi_fw_pdev_base_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7278 				   char *buf, u32 *length)
7279 {
7280 	u32 len = *length;
7281 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7282 
7283 	len += scnprintf(buf + len, buf_len - len, "\n");
7284 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
7285 			"ath10k PDEV stats");
7286 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7287 			"=================");
7288 
7289 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7290 			"Channel noise floor", pdev->ch_noise_floor);
7291 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7292 			"Channel TX power", pdev->chan_tx_power);
7293 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7294 			"TX frame count", pdev->tx_frame_count);
7295 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7296 			"RX frame count", pdev->rx_frame_count);
7297 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7298 			"RX clear count", pdev->rx_clear_count);
7299 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7300 			"Cycle count", pdev->cycle_count);
7301 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7302 			"PHY error count", pdev->phy_err_count);
7303 
7304 	*length = len;
7305 }
7306 
7307 static void
7308 ath10k_wmi_fw_pdev_extra_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7309 				    char *buf, u32 *length)
7310 {
7311 	u32 len = *length;
7312 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7313 
7314 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7315 			"RTS bad count", pdev->rts_bad);
7316 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7317 			"RTS good count", pdev->rts_good);
7318 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7319 			"FCS bad count", pdev->fcs_bad);
7320 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7321 			"No beacon count", pdev->no_beacons);
7322 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
7323 			"MIB int count", pdev->mib_int_count);
7324 
7325 	len += scnprintf(buf + len, buf_len - len, "\n");
7326 	*length = len;
7327 }
7328 
7329 static void
7330 ath10k_wmi_fw_pdev_tx_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7331 				 char *buf, u32 *length)
7332 {
7333 	u32 len = *length;
7334 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7335 
7336 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
7337 			 "ath10k PDEV TX stats");
7338 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7339 				 "=================");
7340 
7341 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7342 			 "HTT cookies queued", pdev->comp_queued);
7343 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7344 			 "HTT cookies disp.", pdev->comp_delivered);
7345 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7346 			 "MSDU queued", pdev->msdu_enqued);
7347 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7348 			 "MPDU queued", pdev->mpdu_enqued);
7349 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7350 			 "MSDUs dropped", pdev->wmm_drop);
7351 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7352 			 "Local enqued", pdev->local_enqued);
7353 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7354 			 "Local freed", pdev->local_freed);
7355 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7356 			 "HW queued", pdev->hw_queued);
7357 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7358 			 "PPDUs reaped", pdev->hw_reaped);
7359 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7360 			 "Num underruns", pdev->underrun);
7361 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7362 			 "PPDUs cleaned", pdev->tx_abort);
7363 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7364 			 "MPDUs requed", pdev->mpdus_requed);
7365 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7366 			 "Excessive retries", pdev->tx_ko);
7367 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7368 			 "HW rate", pdev->data_rc);
7369 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7370 			 "Sched self tiggers", pdev->self_triggers);
7371 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7372 			 "Dropped due to SW retries",
7373 			 pdev->sw_retry_failure);
7374 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7375 			 "Illegal rate phy errors",
7376 			 pdev->illgl_rate_phy_err);
7377 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7378 			 "Pdev continuous xretry", pdev->pdev_cont_xretry);
7379 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7380 			 "TX timeout", pdev->pdev_tx_timeout);
7381 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7382 			 "PDEV resets", pdev->pdev_resets);
7383 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7384 			 "PHY underrun", pdev->phy_underrun);
7385 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7386 			 "MPDU is more than txop limit", pdev->txop_ovf);
7387 	*length = len;
7388 }
7389 
7390 static void
7391 ath10k_wmi_fw_pdev_rx_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
7392 				 char *buf, u32 *length)
7393 {
7394 	u32 len = *length;
7395 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7396 
7397 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
7398 			 "ath10k PDEV RX stats");
7399 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7400 				 "=================");
7401 
7402 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7403 			 "Mid PPDU route change",
7404 			 pdev->mid_ppdu_route_change);
7405 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7406 			 "Tot. number of statuses", pdev->status_rcvd);
7407 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7408 			 "Extra frags on rings 0", pdev->r0_frags);
7409 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7410 			 "Extra frags on rings 1", pdev->r1_frags);
7411 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7412 			 "Extra frags on rings 2", pdev->r2_frags);
7413 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7414 			 "Extra frags on rings 3", pdev->r3_frags);
7415 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7416 			 "MSDUs delivered to HTT", pdev->htt_msdus);
7417 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7418 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
7419 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7420 			 "MSDUs delivered to stack", pdev->loc_msdus);
7421 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7422 			 "MPDUs delivered to stack", pdev->loc_mpdus);
7423 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7424 			 "Oversized AMSUs", pdev->oversize_amsdu);
7425 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7426 			 "PHY errors", pdev->phy_errs);
7427 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7428 			 "PHY errors drops", pdev->phy_err_drop);
7429 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7430 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
7431 	*length = len;
7432 }
7433 
7434 static void
7435 ath10k_wmi_fw_vdev_stats_fill(const struct ath10k_fw_stats_vdev *vdev,
7436 			      char *buf, u32 *length)
7437 {
7438 	u32 len = *length;
7439 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7440 	int i;
7441 
7442 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7443 			"vdev id", vdev->vdev_id);
7444 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7445 			"beacon snr", vdev->beacon_snr);
7446 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7447 			"data snr", vdev->data_snr);
7448 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7449 			"num rx frames", vdev->num_rx_frames);
7450 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7451 			"num rts fail", vdev->num_rts_fail);
7452 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7453 			"num rts success", vdev->num_rts_success);
7454 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7455 			"num rx err", vdev->num_rx_err);
7456 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7457 			"num rx discard", vdev->num_rx_discard);
7458 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7459 			"num tx not acked", vdev->num_tx_not_acked);
7460 
7461 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
7462 		len += scnprintf(buf + len, buf_len - len,
7463 				"%25s [%02d] %u\n",
7464 				"num tx frames", i,
7465 				vdev->num_tx_frames[i]);
7466 
7467 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
7468 		len += scnprintf(buf + len, buf_len - len,
7469 				"%25s [%02d] %u\n",
7470 				"num tx frames retries", i,
7471 				vdev->num_tx_frames_retries[i]);
7472 
7473 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
7474 		len += scnprintf(buf + len, buf_len - len,
7475 				"%25s [%02d] %u\n",
7476 				"num tx frames failures", i,
7477 				vdev->num_tx_frames_failures[i]);
7478 
7479 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
7480 		len += scnprintf(buf + len, buf_len - len,
7481 				"%25s [%02d] 0x%08x\n",
7482 				"tx rate history", i,
7483 				vdev->tx_rate_history[i]);
7484 
7485 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
7486 		len += scnprintf(buf + len, buf_len - len,
7487 				"%25s [%02d] %u\n",
7488 				"beacon rssi history", i,
7489 				vdev->beacon_rssi_history[i]);
7490 
7491 	len += scnprintf(buf + len, buf_len - len, "\n");
7492 	*length = len;
7493 }
7494 
7495 static void
7496 ath10k_wmi_fw_peer_stats_fill(const struct ath10k_fw_stats_peer *peer,
7497 			      char *buf, u32 *length)
7498 {
7499 	u32 len = *length;
7500 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7501 
7502 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
7503 			"Peer MAC address", peer->peer_macaddr);
7504 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7505 			"Peer RSSI", peer->peer_rssi);
7506 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7507 			"Peer TX rate", peer->peer_tx_rate);
7508 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7509 			"Peer RX rate", peer->peer_rx_rate);
7510 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
7511 			"Peer RX duration", peer->rx_duration);
7512 
7513 	len += scnprintf(buf + len, buf_len - len, "\n");
7514 	*length = len;
7515 }
7516 
7517 void ath10k_wmi_main_op_fw_stats_fill(struct ath10k *ar,
7518 				      struct ath10k_fw_stats *fw_stats,
7519 				      char *buf)
7520 {
7521 	u32 len = 0;
7522 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7523 	const struct ath10k_fw_stats_pdev *pdev;
7524 	const struct ath10k_fw_stats_vdev *vdev;
7525 	const struct ath10k_fw_stats_peer *peer;
7526 	size_t num_peers;
7527 	size_t num_vdevs;
7528 
7529 	spin_lock_bh(&ar->data_lock);
7530 
7531 	pdev = list_first_entry_or_null(&fw_stats->pdevs,
7532 					struct ath10k_fw_stats_pdev, list);
7533 	if (!pdev) {
7534 		ath10k_warn(ar, "failed to get pdev stats\n");
7535 		goto unlock;
7536 	}
7537 
7538 	num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
7539 	num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
7540 
7541 	ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
7542 	ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
7543 	ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
7544 
7545 	len += scnprintf(buf + len, buf_len - len, "\n");
7546 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7547 			 "ath10k VDEV stats", num_vdevs);
7548 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7549 				 "=================");
7550 
7551 	list_for_each_entry(vdev, &fw_stats->vdevs, list) {
7552 		ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
7553 	}
7554 
7555 	len += scnprintf(buf + len, buf_len - len, "\n");
7556 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7557 			 "ath10k PEER stats", num_peers);
7558 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7559 				 "=================");
7560 
7561 	list_for_each_entry(peer, &fw_stats->peers, list) {
7562 		ath10k_wmi_fw_peer_stats_fill(peer, buf, &len);
7563 	}
7564 
7565 unlock:
7566 	spin_unlock_bh(&ar->data_lock);
7567 
7568 	if (len >= buf_len)
7569 		buf[len - 1] = 0;
7570 	else
7571 		buf[len] = 0;
7572 }
7573 
7574 void ath10k_wmi_10x_op_fw_stats_fill(struct ath10k *ar,
7575 				     struct ath10k_fw_stats *fw_stats,
7576 				     char *buf)
7577 {
7578 	unsigned int len = 0;
7579 	unsigned int buf_len = ATH10K_FW_STATS_BUF_SIZE;
7580 	const struct ath10k_fw_stats_pdev *pdev;
7581 	const struct ath10k_fw_stats_vdev *vdev;
7582 	const struct ath10k_fw_stats_peer *peer;
7583 	size_t num_peers;
7584 	size_t num_vdevs;
7585 
7586 	spin_lock_bh(&ar->data_lock);
7587 
7588 	pdev = list_first_entry_or_null(&fw_stats->pdevs,
7589 					struct ath10k_fw_stats_pdev, list);
7590 	if (!pdev) {
7591 		ath10k_warn(ar, "failed to get pdev stats\n");
7592 		goto unlock;
7593 	}
7594 
7595 	num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
7596 	num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
7597 
7598 	ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
7599 	ath10k_wmi_fw_pdev_extra_stats_fill(pdev, buf, &len);
7600 	ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
7601 	ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
7602 
7603 	len += scnprintf(buf + len, buf_len - len, "\n");
7604 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7605 			 "ath10k VDEV stats", num_vdevs);
7606 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7607 				 "=================");
7608 
7609 	list_for_each_entry(vdev, &fw_stats->vdevs, list) {
7610 		ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
7611 	}
7612 
7613 	len += scnprintf(buf + len, buf_len - len, "\n");
7614 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7615 			 "ath10k PEER stats", num_peers);
7616 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7617 				 "=================");
7618 
7619 	list_for_each_entry(peer, &fw_stats->peers, list) {
7620 		ath10k_wmi_fw_peer_stats_fill(peer, buf, &len);
7621 	}
7622 
7623 unlock:
7624 	spin_unlock_bh(&ar->data_lock);
7625 
7626 	if (len >= buf_len)
7627 		buf[len - 1] = 0;
7628 	else
7629 		buf[len] = 0;
7630 }
7631 
7632 static struct sk_buff *
7633 ath10k_wmi_op_gen_pdev_enable_adaptive_cca(struct ath10k *ar, u8 enable,
7634 					   u32 detect_level, u32 detect_margin)
7635 {
7636 	struct wmi_pdev_set_adaptive_cca_params *cmd;
7637 	struct sk_buff *skb;
7638 
7639 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7640 	if (!skb)
7641 		return ERR_PTR(-ENOMEM);
7642 
7643 	cmd = (struct wmi_pdev_set_adaptive_cca_params *)skb->data;
7644 	cmd->enable = __cpu_to_le32(enable);
7645 	cmd->cca_detect_level = __cpu_to_le32(detect_level);
7646 	cmd->cca_detect_margin = __cpu_to_le32(detect_margin);
7647 
7648 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7649 		   "wmi pdev set adaptive cca params enable:%d detection level:%d detection margin:%d\n",
7650 		   enable, detect_level, detect_margin);
7651 	return skb;
7652 }
7653 
7654 void ath10k_wmi_10_4_op_fw_stats_fill(struct ath10k *ar,
7655 				      struct ath10k_fw_stats *fw_stats,
7656 				      char *buf)
7657 {
7658 	u32 len = 0;
7659 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
7660 	const struct ath10k_fw_stats_pdev *pdev;
7661 	const struct ath10k_fw_stats_vdev *vdev;
7662 	const struct ath10k_fw_stats_peer *peer;
7663 	size_t num_peers;
7664 	size_t num_vdevs;
7665 
7666 	spin_lock_bh(&ar->data_lock);
7667 
7668 	pdev = list_first_entry_or_null(&fw_stats->pdevs,
7669 					struct ath10k_fw_stats_pdev, list);
7670 	if (!pdev) {
7671 		ath10k_warn(ar, "failed to get pdev stats\n");
7672 		goto unlock;
7673 	}
7674 
7675 	num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
7676 	num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
7677 
7678 	ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
7679 	ath10k_wmi_fw_pdev_extra_stats_fill(pdev, buf, &len);
7680 	ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
7681 
7682 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7683 			"HW paused", pdev->hw_paused);
7684 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7685 			"Seqs posted", pdev->seq_posted);
7686 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7687 			"Seqs failed queueing", pdev->seq_failed_queueing);
7688 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7689 			"Seqs completed", pdev->seq_completed);
7690 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7691 			"Seqs restarted", pdev->seq_restarted);
7692 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7693 			"MU Seqs posted", pdev->mu_seq_posted);
7694 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7695 			"MPDUs SW flushed", pdev->mpdus_sw_flush);
7696 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7697 			"MPDUs HW filtered", pdev->mpdus_hw_filter);
7698 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7699 			"MPDUs truncated", pdev->mpdus_truncated);
7700 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7701 			"MPDUs receive no ACK", pdev->mpdus_ack_failed);
7702 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7703 			"MPDUs expired", pdev->mpdus_expired);
7704 
7705 	ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
7706 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
7707 			"Num Rx Overflow errors", pdev->rx_ovfl_errs);
7708 
7709 	len += scnprintf(buf + len, buf_len - len, "\n");
7710 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7711 			"ath10k VDEV stats", num_vdevs);
7712 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7713 				"=================");
7714 
7715 	list_for_each_entry(vdev, &fw_stats->vdevs, list) {
7716 		ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
7717 	}
7718 
7719 	len += scnprintf(buf + len, buf_len - len, "\n");
7720 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
7721 			"ath10k PEER stats", num_peers);
7722 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
7723 				"=================");
7724 
7725 	list_for_each_entry(peer, &fw_stats->peers, list) {
7726 		ath10k_wmi_fw_peer_stats_fill(peer, buf, &len);
7727 	}
7728 
7729 unlock:
7730 	spin_unlock_bh(&ar->data_lock);
7731 
7732 	if (len >= buf_len)
7733 		buf[len - 1] = 0;
7734 	else
7735 		buf[len] = 0;
7736 }
7737 
7738 int ath10k_wmi_op_get_vdev_subtype(struct ath10k *ar,
7739 				   enum wmi_vdev_subtype subtype)
7740 {
7741 	switch (subtype) {
7742 	case WMI_VDEV_SUBTYPE_NONE:
7743 		return WMI_VDEV_SUBTYPE_LEGACY_NONE;
7744 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
7745 		return WMI_VDEV_SUBTYPE_LEGACY_P2P_DEV;
7746 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
7747 		return WMI_VDEV_SUBTYPE_LEGACY_P2P_CLI;
7748 	case WMI_VDEV_SUBTYPE_P2P_GO:
7749 		return WMI_VDEV_SUBTYPE_LEGACY_P2P_GO;
7750 	case WMI_VDEV_SUBTYPE_PROXY_STA:
7751 		return WMI_VDEV_SUBTYPE_LEGACY_PROXY_STA;
7752 	case WMI_VDEV_SUBTYPE_MESH_11S:
7753 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
7754 		return -ENOTSUPP;
7755 	}
7756 	return -ENOTSUPP;
7757 }
7758 
7759 static int ath10k_wmi_10_2_4_op_get_vdev_subtype(struct ath10k *ar,
7760 						 enum wmi_vdev_subtype subtype)
7761 {
7762 	switch (subtype) {
7763 	case WMI_VDEV_SUBTYPE_NONE:
7764 		return WMI_VDEV_SUBTYPE_10_2_4_NONE;
7765 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
7766 		return WMI_VDEV_SUBTYPE_10_2_4_P2P_DEV;
7767 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
7768 		return WMI_VDEV_SUBTYPE_10_2_4_P2P_CLI;
7769 	case WMI_VDEV_SUBTYPE_P2P_GO:
7770 		return WMI_VDEV_SUBTYPE_10_2_4_P2P_GO;
7771 	case WMI_VDEV_SUBTYPE_PROXY_STA:
7772 		return WMI_VDEV_SUBTYPE_10_2_4_PROXY_STA;
7773 	case WMI_VDEV_SUBTYPE_MESH_11S:
7774 		return WMI_VDEV_SUBTYPE_10_2_4_MESH_11S;
7775 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
7776 		return -ENOTSUPP;
7777 	}
7778 	return -ENOTSUPP;
7779 }
7780 
7781 static int ath10k_wmi_10_4_op_get_vdev_subtype(struct ath10k *ar,
7782 					       enum wmi_vdev_subtype subtype)
7783 {
7784 	switch (subtype) {
7785 	case WMI_VDEV_SUBTYPE_NONE:
7786 		return WMI_VDEV_SUBTYPE_10_4_NONE;
7787 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
7788 		return WMI_VDEV_SUBTYPE_10_4_P2P_DEV;
7789 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
7790 		return WMI_VDEV_SUBTYPE_10_4_P2P_CLI;
7791 	case WMI_VDEV_SUBTYPE_P2P_GO:
7792 		return WMI_VDEV_SUBTYPE_10_4_P2P_GO;
7793 	case WMI_VDEV_SUBTYPE_PROXY_STA:
7794 		return WMI_VDEV_SUBTYPE_10_4_PROXY_STA;
7795 	case WMI_VDEV_SUBTYPE_MESH_11S:
7796 		return WMI_VDEV_SUBTYPE_10_4_MESH_11S;
7797 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
7798 		return WMI_VDEV_SUBTYPE_10_4_MESH_NON_11S;
7799 	}
7800 	return -ENOTSUPP;
7801 }
7802 
7803 static struct sk_buff *
7804 ath10k_wmi_10_4_ext_resource_config(struct ath10k *ar,
7805 				    enum wmi_host_platform_type type,
7806 				    u32 fw_feature_bitmap)
7807 {
7808 	struct wmi_ext_resource_config_10_4_cmd *cmd;
7809 	struct sk_buff *skb;
7810 
7811 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7812 	if (!skb)
7813 		return ERR_PTR(-ENOMEM);
7814 
7815 	cmd = (struct wmi_ext_resource_config_10_4_cmd *)skb->data;
7816 	cmd->host_platform_config = __cpu_to_le32(type);
7817 	cmd->fw_feature_bitmap = __cpu_to_le32(fw_feature_bitmap);
7818 
7819 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7820 		   "wmi ext resource config host type %d firmware feature bitmap %08x\n",
7821 		   type, fw_feature_bitmap);
7822 	return skb;
7823 }
7824 
7825 static struct sk_buff *
7826 ath10k_wmi_op_gen_echo(struct ath10k *ar, u32 value)
7827 {
7828 	struct wmi_echo_cmd *cmd;
7829 	struct sk_buff *skb;
7830 
7831 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7832 	if (!skb)
7833 		return ERR_PTR(-ENOMEM);
7834 
7835 	cmd = (struct wmi_echo_cmd *)skb->data;
7836 	cmd->value = cpu_to_le32(value);
7837 
7838 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7839 		   "wmi echo value 0x%08x\n", value);
7840 	return skb;
7841 }
7842 
7843 int
7844 ath10k_wmi_barrier(struct ath10k *ar)
7845 {
7846 	int ret;
7847 	int time_left;
7848 
7849 	spin_lock_bh(&ar->data_lock);
7850 	reinit_completion(&ar->wmi.barrier);
7851 	spin_unlock_bh(&ar->data_lock);
7852 
7853 	ret = ath10k_wmi_echo(ar, ATH10K_WMI_BARRIER_ECHO_ID);
7854 	if (ret) {
7855 		ath10k_warn(ar, "failed to submit wmi echo: %d\n", ret);
7856 		return ret;
7857 	}
7858 
7859 	time_left = wait_for_completion_timeout(&ar->wmi.barrier,
7860 						ATH10K_WMI_BARRIER_TIMEOUT_HZ);
7861 	if (!time_left)
7862 		return -ETIMEDOUT;
7863 
7864 	return 0;
7865 }
7866 
7867 static const struct wmi_ops wmi_ops = {
7868 	.rx = ath10k_wmi_op_rx,
7869 	.map_svc = wmi_main_svc_map,
7870 
7871 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
7872 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
7873 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
7874 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
7875 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
7876 	.pull_swba = ath10k_wmi_op_pull_swba_ev,
7877 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
7878 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
7879 	.pull_svc_rdy = ath10k_wmi_main_op_pull_svc_rdy_ev,
7880 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
7881 	.pull_fw_stats = ath10k_wmi_main_op_pull_fw_stats,
7882 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
7883 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
7884 
7885 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
7886 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
7887 	.gen_pdev_set_rd = ath10k_wmi_op_gen_pdev_set_rd,
7888 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
7889 	.gen_init = ath10k_wmi_op_gen_init,
7890 	.gen_start_scan = ath10k_wmi_op_gen_start_scan,
7891 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
7892 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
7893 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
7894 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
7895 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
7896 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
7897 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
7898 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
7899 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
7900 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
7901 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
7902 	/* .gen_vdev_wmm_conf not implemented */
7903 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
7904 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
7905 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
7906 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
7907 	.gen_peer_assoc = ath10k_wmi_op_gen_peer_assoc,
7908 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
7909 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
7910 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
7911 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
7912 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
7913 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
7914 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
7915 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
7916 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
7917 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
7918 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
7919 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
7920 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
7921 	/* .gen_pdev_get_temperature not implemented */
7922 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
7923 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
7924 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
7925 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
7926 	.fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
7927 	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
7928 	.gen_echo = ath10k_wmi_op_gen_echo,
7929 	/* .gen_bcn_tmpl not implemented */
7930 	/* .gen_prb_tmpl not implemented */
7931 	/* .gen_p2p_go_bcn_ie not implemented */
7932 	/* .gen_adaptive_qcs not implemented */
7933 	/* .gen_pdev_enable_adaptive_cca not implemented */
7934 };
7935 
7936 static const struct wmi_ops wmi_10_1_ops = {
7937 	.rx = ath10k_wmi_10_1_op_rx,
7938 	.map_svc = wmi_10x_svc_map,
7939 	.pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
7940 	.pull_fw_stats = ath10k_wmi_10x_op_pull_fw_stats,
7941 	.gen_init = ath10k_wmi_10_1_op_gen_init,
7942 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
7943 	.gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
7944 	.gen_peer_assoc = ath10k_wmi_10_1_op_gen_peer_assoc,
7945 	/* .gen_pdev_get_temperature not implemented */
7946 
7947 	/* shared with main branch */
7948 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
7949 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
7950 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
7951 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
7952 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
7953 	.pull_swba = ath10k_wmi_op_pull_swba_ev,
7954 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
7955 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
7956 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
7957 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
7958 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
7959 
7960 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
7961 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
7962 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
7963 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
7964 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
7965 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
7966 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
7967 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
7968 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
7969 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
7970 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
7971 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
7972 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
7973 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
7974 	/* .gen_vdev_wmm_conf not implemented */
7975 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
7976 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
7977 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
7978 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
7979 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
7980 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
7981 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
7982 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
7983 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
7984 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
7985 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
7986 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
7987 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
7988 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
7989 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
7990 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
7991 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
7992 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
7993 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
7994 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
7995 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
7996 	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
7997 	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
7998 	.gen_echo = ath10k_wmi_op_gen_echo,
7999 	/* .gen_bcn_tmpl not implemented */
8000 	/* .gen_prb_tmpl not implemented */
8001 	/* .gen_p2p_go_bcn_ie not implemented */
8002 	/* .gen_adaptive_qcs not implemented */
8003 	/* .gen_pdev_enable_adaptive_cca not implemented */
8004 };
8005 
8006 static const struct wmi_ops wmi_10_2_ops = {
8007 	.rx = ath10k_wmi_10_2_op_rx,
8008 	.pull_fw_stats = ath10k_wmi_10_2_op_pull_fw_stats,
8009 	.gen_init = ath10k_wmi_10_2_op_gen_init,
8010 	.gen_peer_assoc = ath10k_wmi_10_2_op_gen_peer_assoc,
8011 	/* .gen_pdev_get_temperature not implemented */
8012 
8013 	/* shared with 10.1 */
8014 	.map_svc = wmi_10x_svc_map,
8015 	.pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
8016 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
8017 	.gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
8018 	.gen_echo = ath10k_wmi_op_gen_echo,
8019 
8020 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
8021 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
8022 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
8023 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
8024 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
8025 	.pull_swba = ath10k_wmi_op_pull_swba_ev,
8026 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
8027 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
8028 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
8029 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
8030 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
8031 
8032 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
8033 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
8034 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
8035 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
8036 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
8037 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
8038 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
8039 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
8040 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
8041 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
8042 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
8043 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
8044 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
8045 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
8046 	/* .gen_vdev_wmm_conf not implemented */
8047 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
8048 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
8049 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
8050 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
8051 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
8052 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
8053 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
8054 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
8055 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
8056 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
8057 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
8058 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
8059 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
8060 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
8061 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
8062 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
8063 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
8064 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
8065 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
8066 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
8067 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
8068 	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
8069 	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
8070 	/* .gen_pdev_enable_adaptive_cca not implemented */
8071 };
8072 
8073 static const struct wmi_ops wmi_10_2_4_ops = {
8074 	.rx = ath10k_wmi_10_2_op_rx,
8075 	.pull_fw_stats = ath10k_wmi_10_2_4_op_pull_fw_stats,
8076 	.gen_init = ath10k_wmi_10_2_op_gen_init,
8077 	.gen_peer_assoc = ath10k_wmi_10_2_op_gen_peer_assoc,
8078 	.gen_pdev_get_temperature = ath10k_wmi_10_2_op_gen_pdev_get_temperature,
8079 	.gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
8080 
8081 	/* shared with 10.1 */
8082 	.map_svc = wmi_10x_svc_map,
8083 	.pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
8084 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
8085 	.gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
8086 	.gen_echo = ath10k_wmi_op_gen_echo,
8087 
8088 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
8089 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
8090 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
8091 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
8092 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
8093 	.pull_swba = ath10k_wmi_10_2_4_op_pull_swba_ev,
8094 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
8095 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
8096 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
8097 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
8098 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
8099 
8100 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
8101 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
8102 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
8103 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
8104 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
8105 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
8106 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
8107 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
8108 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
8109 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
8110 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
8111 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
8112 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
8113 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
8114 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
8115 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
8116 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
8117 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
8118 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
8119 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
8120 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
8121 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
8122 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
8123 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
8124 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
8125 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
8126 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
8127 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
8128 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
8129 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
8130 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
8131 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
8132 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
8133 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
8134 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
8135 	.gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
8136 	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
8137 	.gen_pdev_enable_adaptive_cca =
8138 		ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
8139 	.get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
8140 	/* .gen_bcn_tmpl not implemented */
8141 	/* .gen_prb_tmpl not implemented */
8142 	/* .gen_p2p_go_bcn_ie not implemented */
8143 	/* .gen_adaptive_qcs not implemented */
8144 };
8145 
8146 static const struct wmi_ops wmi_10_4_ops = {
8147 	.rx = ath10k_wmi_10_4_op_rx,
8148 	.map_svc = wmi_10_4_svc_map,
8149 
8150 	.pull_fw_stats = ath10k_wmi_10_4_op_pull_fw_stats,
8151 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
8152 	.pull_mgmt_rx = ath10k_wmi_10_4_op_pull_mgmt_rx_ev,
8153 	.pull_ch_info = ath10k_wmi_10_4_op_pull_ch_info_ev,
8154 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
8155 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
8156 	.pull_swba = ath10k_wmi_10_4_op_pull_swba_ev,
8157 	.pull_phyerr_hdr = ath10k_wmi_10_4_op_pull_phyerr_ev_hdr,
8158 	.pull_phyerr = ath10k_wmi_10_4_op_pull_phyerr_ev,
8159 	.pull_svc_rdy = ath10k_wmi_main_op_pull_svc_rdy_ev,
8160 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
8161 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
8162 	.get_txbf_conf_scheme = ath10k_wmi_10_4_txbf_conf_scheme,
8163 
8164 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
8165 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
8166 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
8167 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
8168 	.gen_init = ath10k_wmi_10_4_op_gen_init,
8169 	.gen_start_scan = ath10k_wmi_op_gen_start_scan,
8170 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
8171 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
8172 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
8173 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
8174 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
8175 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
8176 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
8177 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
8178 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
8179 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
8180 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
8181 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
8182 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
8183 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
8184 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
8185 	.gen_peer_assoc = ath10k_wmi_10_4_op_gen_peer_assoc,
8186 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
8187 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
8188 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
8189 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
8190 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
8191 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
8192 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
8193 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
8194 	.gen_dbglog_cfg = ath10k_wmi_10_4_op_gen_dbglog_cfg,
8195 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
8196 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
8197 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
8198 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
8199 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
8200 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
8201 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
8202 	.fw_stats_fill = ath10k_wmi_10_4_op_fw_stats_fill,
8203 	.ext_resource_config = ath10k_wmi_10_4_ext_resource_config,
8204 
8205 	/* shared with 10.2 */
8206 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
8207 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
8208 	.gen_pdev_get_temperature = ath10k_wmi_10_2_op_gen_pdev_get_temperature,
8209 	.get_vdev_subtype = ath10k_wmi_10_4_op_get_vdev_subtype,
8210 	.gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
8211 	.gen_echo = ath10k_wmi_op_gen_echo,
8212 	.gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
8213 };
8214 
8215 int ath10k_wmi_attach(struct ath10k *ar)
8216 {
8217 	switch (ar->running_fw->fw_file.wmi_op_version) {
8218 	case ATH10K_FW_WMI_OP_VERSION_10_4:
8219 		ar->wmi.ops = &wmi_10_4_ops;
8220 		ar->wmi.cmd = &wmi_10_4_cmd_map;
8221 		ar->wmi.vdev_param = &wmi_10_4_vdev_param_map;
8222 		ar->wmi.pdev_param = &wmi_10_4_pdev_param_map;
8223 		ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
8224 		break;
8225 	case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8226 		ar->wmi.cmd = &wmi_10_2_4_cmd_map;
8227 		ar->wmi.ops = &wmi_10_2_4_ops;
8228 		ar->wmi.vdev_param = &wmi_10_2_4_vdev_param_map;
8229 		ar->wmi.pdev_param = &wmi_10_2_4_pdev_param_map;
8230 		ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
8231 		break;
8232 	case ATH10K_FW_WMI_OP_VERSION_10_2:
8233 		ar->wmi.cmd = &wmi_10_2_cmd_map;
8234 		ar->wmi.ops = &wmi_10_2_ops;
8235 		ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
8236 		ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
8237 		ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
8238 		break;
8239 	case ATH10K_FW_WMI_OP_VERSION_10_1:
8240 		ar->wmi.cmd = &wmi_10x_cmd_map;
8241 		ar->wmi.ops = &wmi_10_1_ops;
8242 		ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
8243 		ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
8244 		ar->wmi.peer_flags = &wmi_10x_peer_flags_map;
8245 		break;
8246 	case ATH10K_FW_WMI_OP_VERSION_MAIN:
8247 		ar->wmi.cmd = &wmi_cmd_map;
8248 		ar->wmi.ops = &wmi_ops;
8249 		ar->wmi.vdev_param = &wmi_vdev_param_map;
8250 		ar->wmi.pdev_param = &wmi_pdev_param_map;
8251 		ar->wmi.peer_flags = &wmi_peer_flags_map;
8252 		break;
8253 	case ATH10K_FW_WMI_OP_VERSION_TLV:
8254 		ath10k_wmi_tlv_attach(ar);
8255 		break;
8256 	case ATH10K_FW_WMI_OP_VERSION_UNSET:
8257 	case ATH10K_FW_WMI_OP_VERSION_MAX:
8258 		ath10k_err(ar, "unsupported WMI op version: %d\n",
8259 			   ar->running_fw->fw_file.wmi_op_version);
8260 		return -EINVAL;
8261 	}
8262 
8263 	init_completion(&ar->wmi.service_ready);
8264 	init_completion(&ar->wmi.unified_ready);
8265 	init_completion(&ar->wmi.barrier);
8266 
8267 	INIT_WORK(&ar->svc_rdy_work, ath10k_wmi_event_service_ready_work);
8268 
8269 	return 0;
8270 }
8271 
8272 void ath10k_wmi_free_host_mem(struct ath10k *ar)
8273 {
8274 	int i;
8275 
8276 	/* free the host memory chunks requested by firmware */
8277 	for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
8278 		dma_unmap_single(ar->dev,
8279 				 ar->wmi.mem_chunks[i].paddr,
8280 				 ar->wmi.mem_chunks[i].len,
8281 				 DMA_BIDIRECTIONAL);
8282 		kfree(ar->wmi.mem_chunks[i].vaddr);
8283 	}
8284 
8285 	ar->wmi.num_mem_chunks = 0;
8286 }
8287 
8288 void ath10k_wmi_detach(struct ath10k *ar)
8289 {
8290 	cancel_work_sync(&ar->svc_rdy_work);
8291 
8292 	if (ar->svc_rdy_skb)
8293 		dev_kfree_skb(ar->svc_rdy_skb);
8294 }
8295