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