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