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