xref: /openbmc/linux/drivers/net/wireless/ath/ath10k/wmi.c (revision 7b73a9c8)
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 
1930 	hdr = (struct ieee80211_hdr *)msdu->data;
1931 	fc = le16_to_cpu(hdr->frame_control);
1932 
1933 	if (cb->vif) {
1934 		arvif = (void *)cb->vif->drv_priv;
1935 		vdev_id = arvif->vdev_id;
1936 	} else {
1937 		vdev_id = 0;
1938 	}
1939 
1940 	if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
1941 		return ERR_PTR(-EINVAL);
1942 
1943 	len = sizeof(cmd->hdr) + msdu->len;
1944 
1945 	if ((ieee80211_is_action(hdr->frame_control) ||
1946 	     ieee80211_is_deauth(hdr->frame_control) ||
1947 	     ieee80211_is_disassoc(hdr->frame_control)) &&
1948 	     ieee80211_has_protected(hdr->frame_control)) {
1949 		len += IEEE80211_CCMP_MIC_LEN;
1950 		buf_len += IEEE80211_CCMP_MIC_LEN;
1951 	}
1952 
1953 	len = round_up(len, 4);
1954 
1955 	skb = ath10k_wmi_alloc_skb(ar, len);
1956 	if (!skb)
1957 		return ERR_PTR(-ENOMEM);
1958 
1959 	cmd = (struct wmi_mgmt_tx_cmd *)skb->data;
1960 
1961 	cmd->hdr.vdev_id = __cpu_to_le32(vdev_id);
1962 	cmd->hdr.tx_rate = 0;
1963 	cmd->hdr.tx_power = 0;
1964 	cmd->hdr.buf_len = __cpu_to_le32(buf_len);
1965 
1966 	ether_addr_copy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr));
1967 	memcpy(cmd->buf, msdu->data, msdu->len);
1968 
1969 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx skb %pK len %d ftype %02x stype %02x\n",
1970 		   msdu, skb->len, fc & IEEE80211_FCTL_FTYPE,
1971 		   fc & IEEE80211_FCTL_STYPE);
1972 	trace_ath10k_tx_hdr(ar, skb->data, skb->len);
1973 	trace_ath10k_tx_payload(ar, skb->data, skb->len);
1974 
1975 	return skb;
1976 }
1977 
1978 static void ath10k_wmi_event_scan_started(struct ath10k *ar)
1979 {
1980 	lockdep_assert_held(&ar->data_lock);
1981 
1982 	switch (ar->scan.state) {
1983 	case ATH10K_SCAN_IDLE:
1984 	case ATH10K_SCAN_RUNNING:
1985 	case ATH10K_SCAN_ABORTING:
1986 		ath10k_warn(ar, "received scan started event in an invalid scan state: %s (%d)\n",
1987 			    ath10k_scan_state_str(ar->scan.state),
1988 			    ar->scan.state);
1989 		break;
1990 	case ATH10K_SCAN_STARTING:
1991 		ar->scan.state = ATH10K_SCAN_RUNNING;
1992 
1993 		if (ar->scan.is_roc)
1994 			ieee80211_ready_on_channel(ar->hw);
1995 
1996 		complete(&ar->scan.started);
1997 		break;
1998 	}
1999 }
2000 
2001 static void ath10k_wmi_event_scan_start_failed(struct ath10k *ar)
2002 {
2003 	lockdep_assert_held(&ar->data_lock);
2004 
2005 	switch (ar->scan.state) {
2006 	case ATH10K_SCAN_IDLE:
2007 	case ATH10K_SCAN_RUNNING:
2008 	case ATH10K_SCAN_ABORTING:
2009 		ath10k_warn(ar, "received scan start failed event in an invalid scan state: %s (%d)\n",
2010 			    ath10k_scan_state_str(ar->scan.state),
2011 			    ar->scan.state);
2012 		break;
2013 	case ATH10K_SCAN_STARTING:
2014 		complete(&ar->scan.started);
2015 		__ath10k_scan_finish(ar);
2016 		break;
2017 	}
2018 }
2019 
2020 static void ath10k_wmi_event_scan_completed(struct ath10k *ar)
2021 {
2022 	lockdep_assert_held(&ar->data_lock);
2023 
2024 	switch (ar->scan.state) {
2025 	case ATH10K_SCAN_IDLE:
2026 	case ATH10K_SCAN_STARTING:
2027 		/* One suspected reason scan can be completed while starting is
2028 		 * if firmware fails to deliver all scan events to the host,
2029 		 * e.g. when transport pipe is full. This has been observed
2030 		 * with spectral scan phyerr events starving wmi transport
2031 		 * pipe. In such case the "scan completed" event should be (and
2032 		 * is) ignored by the host as it may be just firmware's scan
2033 		 * state machine recovering.
2034 		 */
2035 		ath10k_warn(ar, "received scan completed event in an invalid scan state: %s (%d)\n",
2036 			    ath10k_scan_state_str(ar->scan.state),
2037 			    ar->scan.state);
2038 		break;
2039 	case ATH10K_SCAN_RUNNING:
2040 	case ATH10K_SCAN_ABORTING:
2041 		__ath10k_scan_finish(ar);
2042 		break;
2043 	}
2044 }
2045 
2046 static void ath10k_wmi_event_scan_bss_chan(struct ath10k *ar)
2047 {
2048 	lockdep_assert_held(&ar->data_lock);
2049 
2050 	switch (ar->scan.state) {
2051 	case ATH10K_SCAN_IDLE:
2052 	case ATH10K_SCAN_STARTING:
2053 		ath10k_warn(ar, "received scan bss chan event in an invalid scan state: %s (%d)\n",
2054 			    ath10k_scan_state_str(ar->scan.state),
2055 			    ar->scan.state);
2056 		break;
2057 	case ATH10K_SCAN_RUNNING:
2058 	case ATH10K_SCAN_ABORTING:
2059 		ar->scan_channel = NULL;
2060 		break;
2061 	}
2062 }
2063 
2064 static void ath10k_wmi_event_scan_foreign_chan(struct ath10k *ar, u32 freq)
2065 {
2066 	lockdep_assert_held(&ar->data_lock);
2067 
2068 	switch (ar->scan.state) {
2069 	case ATH10K_SCAN_IDLE:
2070 	case ATH10K_SCAN_STARTING:
2071 		ath10k_warn(ar, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
2072 			    ath10k_scan_state_str(ar->scan.state),
2073 			    ar->scan.state);
2074 		break;
2075 	case ATH10K_SCAN_RUNNING:
2076 	case ATH10K_SCAN_ABORTING:
2077 		ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
2078 
2079 		if (ar->scan.is_roc && ar->scan.roc_freq == freq)
2080 			complete(&ar->scan.on_channel);
2081 		break;
2082 	}
2083 }
2084 
2085 static const char *
2086 ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
2087 			       enum wmi_scan_completion_reason reason)
2088 {
2089 	switch (type) {
2090 	case WMI_SCAN_EVENT_STARTED:
2091 		return "started";
2092 	case WMI_SCAN_EVENT_COMPLETED:
2093 		switch (reason) {
2094 		case WMI_SCAN_REASON_COMPLETED:
2095 			return "completed";
2096 		case WMI_SCAN_REASON_CANCELLED:
2097 			return "completed [cancelled]";
2098 		case WMI_SCAN_REASON_PREEMPTED:
2099 			return "completed [preempted]";
2100 		case WMI_SCAN_REASON_TIMEDOUT:
2101 			return "completed [timedout]";
2102 		case WMI_SCAN_REASON_INTERNAL_FAILURE:
2103 			return "completed [internal err]";
2104 		case WMI_SCAN_REASON_MAX:
2105 			break;
2106 		}
2107 		return "completed [unknown]";
2108 	case WMI_SCAN_EVENT_BSS_CHANNEL:
2109 		return "bss channel";
2110 	case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
2111 		return "foreign channel";
2112 	case WMI_SCAN_EVENT_DEQUEUED:
2113 		return "dequeued";
2114 	case WMI_SCAN_EVENT_PREEMPTED:
2115 		return "preempted";
2116 	case WMI_SCAN_EVENT_START_FAILED:
2117 		return "start failed";
2118 	case WMI_SCAN_EVENT_RESTARTED:
2119 		return "restarted";
2120 	case WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT:
2121 		return "foreign channel exit";
2122 	default:
2123 		return "unknown";
2124 	}
2125 }
2126 
2127 static int ath10k_wmi_op_pull_scan_ev(struct ath10k *ar, struct sk_buff *skb,
2128 				      struct wmi_scan_ev_arg *arg)
2129 {
2130 	struct wmi_scan_event *ev = (void *)skb->data;
2131 
2132 	if (skb->len < sizeof(*ev))
2133 		return -EPROTO;
2134 
2135 	skb_pull(skb, sizeof(*ev));
2136 	arg->event_type = ev->event_type;
2137 	arg->reason = ev->reason;
2138 	arg->channel_freq = ev->channel_freq;
2139 	arg->scan_req_id = ev->scan_req_id;
2140 	arg->scan_id = ev->scan_id;
2141 	arg->vdev_id = ev->vdev_id;
2142 
2143 	return 0;
2144 }
2145 
2146 int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
2147 {
2148 	struct wmi_scan_ev_arg arg = {};
2149 	enum wmi_scan_event_type event_type;
2150 	enum wmi_scan_completion_reason reason;
2151 	u32 freq;
2152 	u32 req_id;
2153 	u32 scan_id;
2154 	u32 vdev_id;
2155 	int ret;
2156 
2157 	ret = ath10k_wmi_pull_scan(ar, skb, &arg);
2158 	if (ret) {
2159 		ath10k_warn(ar, "failed to parse scan event: %d\n", ret);
2160 		return ret;
2161 	}
2162 
2163 	event_type = __le32_to_cpu(arg.event_type);
2164 	reason = __le32_to_cpu(arg.reason);
2165 	freq = __le32_to_cpu(arg.channel_freq);
2166 	req_id = __le32_to_cpu(arg.scan_req_id);
2167 	scan_id = __le32_to_cpu(arg.scan_id);
2168 	vdev_id = __le32_to_cpu(arg.vdev_id);
2169 
2170 	spin_lock_bh(&ar->data_lock);
2171 
2172 	ath10k_dbg(ar, ATH10K_DBG_WMI,
2173 		   "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
2174 		   ath10k_wmi_event_scan_type_str(event_type, reason),
2175 		   event_type, reason, freq, req_id, scan_id, vdev_id,
2176 		   ath10k_scan_state_str(ar->scan.state), ar->scan.state);
2177 
2178 	switch (event_type) {
2179 	case WMI_SCAN_EVENT_STARTED:
2180 		ath10k_wmi_event_scan_started(ar);
2181 		break;
2182 	case WMI_SCAN_EVENT_COMPLETED:
2183 		ath10k_wmi_event_scan_completed(ar);
2184 		break;
2185 	case WMI_SCAN_EVENT_BSS_CHANNEL:
2186 		ath10k_wmi_event_scan_bss_chan(ar);
2187 		break;
2188 	case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
2189 		ath10k_wmi_event_scan_foreign_chan(ar, freq);
2190 		break;
2191 	case WMI_SCAN_EVENT_START_FAILED:
2192 		ath10k_warn(ar, "received scan start failure event\n");
2193 		ath10k_wmi_event_scan_start_failed(ar);
2194 		break;
2195 	case WMI_SCAN_EVENT_DEQUEUED:
2196 	case WMI_SCAN_EVENT_PREEMPTED:
2197 	case WMI_SCAN_EVENT_RESTARTED:
2198 	case WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT:
2199 	default:
2200 		break;
2201 	}
2202 
2203 	spin_unlock_bh(&ar->data_lock);
2204 	return 0;
2205 }
2206 
2207 /* If keys are configured, HW decrypts all frames
2208  * with protected bit set. Mark such frames as decrypted.
2209  */
2210 static void ath10k_wmi_handle_wep_reauth(struct ath10k *ar,
2211 					 struct sk_buff *skb,
2212 					 struct ieee80211_rx_status *status)
2213 {
2214 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2215 	unsigned int hdrlen;
2216 	bool peer_key;
2217 	u8 *addr, keyidx;
2218 
2219 	if (!ieee80211_is_auth(hdr->frame_control) ||
2220 	    !ieee80211_has_protected(hdr->frame_control))
2221 		return;
2222 
2223 	hdrlen = ieee80211_hdrlen(hdr->frame_control);
2224 	if (skb->len < (hdrlen + IEEE80211_WEP_IV_LEN))
2225 		return;
2226 
2227 	keyidx = skb->data[hdrlen + (IEEE80211_WEP_IV_LEN - 1)] >> WEP_KEYID_SHIFT;
2228 	addr = ieee80211_get_SA(hdr);
2229 
2230 	spin_lock_bh(&ar->data_lock);
2231 	peer_key = ath10k_mac_is_peer_wep_key_set(ar, addr, keyidx);
2232 	spin_unlock_bh(&ar->data_lock);
2233 
2234 	if (peer_key) {
2235 		ath10k_dbg(ar, ATH10K_DBG_MAC,
2236 			   "mac wep key present for peer %pM\n", addr);
2237 		status->flag |= RX_FLAG_DECRYPTED;
2238 	}
2239 }
2240 
2241 static int ath10k_wmi_op_pull_mgmt_rx_ev(struct ath10k *ar, struct sk_buff *skb,
2242 					 struct wmi_mgmt_rx_ev_arg *arg)
2243 {
2244 	struct wmi_mgmt_rx_event_v1 *ev_v1;
2245 	struct wmi_mgmt_rx_event_v2 *ev_v2;
2246 	struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
2247 	struct wmi_mgmt_rx_ext_info *ext_info;
2248 	size_t pull_len;
2249 	u32 msdu_len;
2250 	u32 len;
2251 
2252 	if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX,
2253 		     ar->running_fw->fw_file.fw_features)) {
2254 		ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
2255 		ev_hdr = &ev_v2->hdr.v1;
2256 		pull_len = sizeof(*ev_v2);
2257 	} else {
2258 		ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
2259 		ev_hdr = &ev_v1->hdr;
2260 		pull_len = sizeof(*ev_v1);
2261 	}
2262 
2263 	if (skb->len < pull_len)
2264 		return -EPROTO;
2265 
2266 	skb_pull(skb, pull_len);
2267 	arg->channel = ev_hdr->channel;
2268 	arg->buf_len = ev_hdr->buf_len;
2269 	arg->status = ev_hdr->status;
2270 	arg->snr = ev_hdr->snr;
2271 	arg->phy_mode = ev_hdr->phy_mode;
2272 	arg->rate = ev_hdr->rate;
2273 
2274 	msdu_len = __le32_to_cpu(arg->buf_len);
2275 	if (skb->len < msdu_len)
2276 		return -EPROTO;
2277 
2278 	if (le32_to_cpu(arg->status) & WMI_RX_STATUS_EXT_INFO) {
2279 		len = ALIGN(le32_to_cpu(arg->buf_len), 4);
2280 		ext_info = (struct wmi_mgmt_rx_ext_info *)(skb->data + len);
2281 		memcpy(&arg->ext_info, ext_info,
2282 		       sizeof(struct wmi_mgmt_rx_ext_info));
2283 	}
2284 	/* the WMI buffer might've ended up being padded to 4 bytes due to HTC
2285 	 * trailer with credit update. Trim the excess garbage.
2286 	 */
2287 	skb_trim(skb, msdu_len);
2288 
2289 	return 0;
2290 }
2291 
2292 static int ath10k_wmi_10_4_op_pull_mgmt_rx_ev(struct ath10k *ar,
2293 					      struct sk_buff *skb,
2294 					      struct wmi_mgmt_rx_ev_arg *arg)
2295 {
2296 	struct wmi_10_4_mgmt_rx_event *ev;
2297 	struct wmi_10_4_mgmt_rx_hdr *ev_hdr;
2298 	size_t pull_len;
2299 	u32 msdu_len;
2300 	struct wmi_mgmt_rx_ext_info *ext_info;
2301 	u32 len;
2302 
2303 	ev = (struct wmi_10_4_mgmt_rx_event *)skb->data;
2304 	ev_hdr = &ev->hdr;
2305 	pull_len = sizeof(*ev);
2306 
2307 	if (skb->len < pull_len)
2308 		return -EPROTO;
2309 
2310 	skb_pull(skb, pull_len);
2311 	arg->channel = ev_hdr->channel;
2312 	arg->buf_len = ev_hdr->buf_len;
2313 	arg->status = ev_hdr->status;
2314 	arg->snr = ev_hdr->snr;
2315 	arg->phy_mode = ev_hdr->phy_mode;
2316 	arg->rate = ev_hdr->rate;
2317 
2318 	msdu_len = __le32_to_cpu(arg->buf_len);
2319 	if (skb->len < msdu_len)
2320 		return -EPROTO;
2321 
2322 	if (le32_to_cpu(arg->status) & WMI_RX_STATUS_EXT_INFO) {
2323 		len = ALIGN(le32_to_cpu(arg->buf_len), 4);
2324 		ext_info = (struct wmi_mgmt_rx_ext_info *)(skb->data + len);
2325 		memcpy(&arg->ext_info, ext_info,
2326 		       sizeof(struct wmi_mgmt_rx_ext_info));
2327 	}
2328 
2329 	/* Make sure bytes added for padding are removed. */
2330 	skb_trim(skb, msdu_len);
2331 
2332 	return 0;
2333 }
2334 
2335 static bool ath10k_wmi_rx_is_decrypted(struct ath10k *ar,
2336 				       struct ieee80211_hdr *hdr)
2337 {
2338 	if (!ieee80211_has_protected(hdr->frame_control))
2339 		return false;
2340 
2341 	/* FW delivers WEP Shared Auth frame with Protected Bit set and
2342 	 * encrypted payload. However in case of PMF it delivers decrypted
2343 	 * frames with Protected Bit set.
2344 	 */
2345 	if (ieee80211_is_auth(hdr->frame_control))
2346 		return false;
2347 
2348 	/* qca99x0 based FW delivers broadcast or multicast management frames
2349 	 * (ex: group privacy action frames in mesh) as encrypted payload.
2350 	 */
2351 	if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) &&
2352 	    ar->hw_params.sw_decrypt_mcast_mgmt)
2353 		return false;
2354 
2355 	return true;
2356 }
2357 
2358 static int
2359 wmi_process_mgmt_tx_comp(struct ath10k *ar, struct mgmt_tx_compl_params *param)
2360 {
2361 	struct ath10k_mgmt_tx_pkt_addr *pkt_addr;
2362 	struct ath10k_wmi *wmi = &ar->wmi;
2363 	struct ieee80211_tx_info *info;
2364 	struct sk_buff *msdu;
2365 	int ret;
2366 
2367 	spin_lock_bh(&ar->data_lock);
2368 
2369 	pkt_addr = idr_find(&wmi->mgmt_pending_tx, param->desc_id);
2370 	if (!pkt_addr) {
2371 		ath10k_warn(ar, "received mgmt tx completion for invalid msdu_id: %d\n",
2372 			    param->desc_id);
2373 		ret = -ENOENT;
2374 		goto out;
2375 	}
2376 
2377 	msdu = pkt_addr->vaddr;
2378 	dma_unmap_single(ar->dev, pkt_addr->paddr,
2379 			 msdu->len, DMA_TO_DEVICE);
2380 	info = IEEE80211_SKB_CB(msdu);
2381 
2382 	if (param->status) {
2383 		info->flags &= ~IEEE80211_TX_STAT_ACK;
2384 	} else {
2385 		info->flags |= IEEE80211_TX_STAT_ACK;
2386 		info->status.ack_signal = ATH10K_DEFAULT_NOISE_FLOOR +
2387 					  param->ack_rssi;
2388 		info->status.is_valid_ack_signal = true;
2389 	}
2390 
2391 	ieee80211_tx_status_irqsafe(ar->hw, msdu);
2392 
2393 	ret = 0;
2394 
2395 out:
2396 	idr_remove(&wmi->mgmt_pending_tx, param->desc_id);
2397 	spin_unlock_bh(&ar->data_lock);
2398 	return ret;
2399 }
2400 
2401 int ath10k_wmi_event_mgmt_tx_compl(struct ath10k *ar, struct sk_buff *skb)
2402 {
2403 	struct wmi_tlv_mgmt_tx_compl_ev_arg arg;
2404 	struct mgmt_tx_compl_params param;
2405 	int ret;
2406 
2407 	ret = ath10k_wmi_pull_mgmt_tx_compl(ar, skb, &arg);
2408 	if (ret) {
2409 		ath10k_warn(ar, "failed to parse mgmt comp event: %d\n", ret);
2410 		return ret;
2411 	}
2412 
2413 	memset(&param, 0, sizeof(struct mgmt_tx_compl_params));
2414 	param.desc_id = __le32_to_cpu(arg.desc_id);
2415 	param.status = __le32_to_cpu(arg.status);
2416 
2417 	if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
2418 		param.ack_rssi = __le32_to_cpu(arg.ack_rssi);
2419 
2420 	wmi_process_mgmt_tx_comp(ar, &param);
2421 
2422 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv evnt mgmt tx completion\n");
2423 
2424 	return 0;
2425 }
2426 
2427 int ath10k_wmi_event_mgmt_tx_bundle_compl(struct ath10k *ar, struct sk_buff *skb)
2428 {
2429 	struct wmi_tlv_mgmt_tx_bundle_compl_ev_arg arg;
2430 	struct mgmt_tx_compl_params param;
2431 	u32 num_reports;
2432 	int i, ret;
2433 
2434 	ret = ath10k_wmi_pull_mgmt_tx_bundle_compl(ar, skb, &arg);
2435 	if (ret) {
2436 		ath10k_warn(ar, "failed to parse bundle mgmt compl event: %d\n", ret);
2437 		return ret;
2438 	}
2439 
2440 	num_reports = __le32_to_cpu(arg.num_reports);
2441 
2442 	for (i = 0; i < num_reports; i++) {
2443 		memset(&param, 0, sizeof(struct mgmt_tx_compl_params));
2444 		param.desc_id = __le32_to_cpu(arg.desc_ids[i]);
2445 		param.status = __le32_to_cpu(arg.desc_ids[i]);
2446 
2447 		if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map))
2448 			param.ack_rssi = __le32_to_cpu(arg.ack_rssi[i]);
2449 		wmi_process_mgmt_tx_comp(ar, &param);
2450 	}
2451 
2452 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi tlv event bundle mgmt tx completion\n");
2453 
2454 	return 0;
2455 }
2456 
2457 int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
2458 {
2459 	struct wmi_mgmt_rx_ev_arg arg = {};
2460 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2461 	struct ieee80211_hdr *hdr;
2462 	struct ieee80211_supported_band *sband;
2463 	u32 rx_status;
2464 	u32 channel;
2465 	u32 phy_mode;
2466 	u32 snr;
2467 	u32 rate;
2468 	u16 fc;
2469 	int ret;
2470 
2471 	ret = ath10k_wmi_pull_mgmt_rx(ar, skb, &arg);
2472 	if (ret) {
2473 		ath10k_warn(ar, "failed to parse mgmt rx event: %d\n", ret);
2474 		dev_kfree_skb(skb);
2475 		return ret;
2476 	}
2477 
2478 	channel = __le32_to_cpu(arg.channel);
2479 	rx_status = __le32_to_cpu(arg.status);
2480 	snr = __le32_to_cpu(arg.snr);
2481 	phy_mode = __le32_to_cpu(arg.phy_mode);
2482 	rate = __le32_to_cpu(arg.rate);
2483 
2484 	memset(status, 0, sizeof(*status));
2485 
2486 	ath10k_dbg(ar, ATH10K_DBG_MGMT,
2487 		   "event mgmt rx status %08x\n", rx_status);
2488 
2489 	if ((test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) ||
2490 	    (rx_status & (WMI_RX_STATUS_ERR_DECRYPT |
2491 	    WMI_RX_STATUS_ERR_KEY_CACHE_MISS | WMI_RX_STATUS_ERR_CRC))) {
2492 		dev_kfree_skb(skb);
2493 		return 0;
2494 	}
2495 
2496 	if (rx_status & WMI_RX_STATUS_ERR_MIC)
2497 		status->flag |= RX_FLAG_MMIC_ERROR;
2498 
2499 	if (rx_status & WMI_RX_STATUS_EXT_INFO) {
2500 		status->mactime =
2501 			__le64_to_cpu(arg.ext_info.rx_mac_timestamp);
2502 		status->flag |= RX_FLAG_MACTIME_END;
2503 	}
2504 	/* Hardware can Rx CCK rates on 5GHz. In that case phy_mode is set to
2505 	 * MODE_11B. This means phy_mode is not a reliable source for the band
2506 	 * of mgmt rx.
2507 	 */
2508 	if (channel >= 1 && channel <= 14) {
2509 		status->band = NL80211_BAND_2GHZ;
2510 	} else if (channel >= 36 && channel <= ATH10K_MAX_5G_CHAN) {
2511 		status->band = NL80211_BAND_5GHZ;
2512 	} else {
2513 		/* Shouldn't happen unless list of advertised channels to
2514 		 * mac80211 has been changed.
2515 		 */
2516 		WARN_ON_ONCE(1);
2517 		dev_kfree_skb(skb);
2518 		return 0;
2519 	}
2520 
2521 	if (phy_mode == MODE_11B && status->band == NL80211_BAND_5GHZ)
2522 		ath10k_dbg(ar, ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
2523 
2524 	sband = &ar->mac.sbands[status->band];
2525 
2526 	status->freq = ieee80211_channel_to_frequency(channel, status->band);
2527 	status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
2528 	status->rate_idx = ath10k_mac_bitrate_to_idx(sband, rate / 100);
2529 
2530 	hdr = (struct ieee80211_hdr *)skb->data;
2531 	fc = le16_to_cpu(hdr->frame_control);
2532 
2533 	/* Firmware is guaranteed to report all essential management frames via
2534 	 * WMI while it can deliver some extra via HTT. Since there can be
2535 	 * duplicates split the reporting wrt monitor/sniffing.
2536 	 */
2537 	status->flag |= RX_FLAG_SKIP_MONITOR;
2538 
2539 	ath10k_wmi_handle_wep_reauth(ar, skb, status);
2540 
2541 	if (ath10k_wmi_rx_is_decrypted(ar, hdr)) {
2542 		status->flag |= RX_FLAG_DECRYPTED;
2543 
2544 		if (!ieee80211_is_action(hdr->frame_control) &&
2545 		    !ieee80211_is_deauth(hdr->frame_control) &&
2546 		    !ieee80211_is_disassoc(hdr->frame_control)) {
2547 			status->flag |= RX_FLAG_IV_STRIPPED |
2548 					RX_FLAG_MMIC_STRIPPED;
2549 			hdr->frame_control = __cpu_to_le16(fc &
2550 					~IEEE80211_FCTL_PROTECTED);
2551 		}
2552 	}
2553 
2554 	if (ieee80211_is_beacon(hdr->frame_control))
2555 		ath10k_mac_handle_beacon(ar, skb);
2556 
2557 	ath10k_dbg(ar, ATH10K_DBG_MGMT,
2558 		   "event mgmt rx skb %pK len %d ftype %02x stype %02x\n",
2559 		   skb, skb->len,
2560 		   fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
2561 
2562 	ath10k_dbg(ar, ATH10K_DBG_MGMT,
2563 		   "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
2564 		   status->freq, status->band, status->signal,
2565 		   status->rate_idx);
2566 
2567 	ieee80211_rx_ni(ar->hw, skb);
2568 
2569 	return 0;
2570 }
2571 
2572 static int freq_to_idx(struct ath10k *ar, int freq)
2573 {
2574 	struct ieee80211_supported_band *sband;
2575 	int band, ch, idx = 0;
2576 
2577 	for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
2578 		sband = ar->hw->wiphy->bands[band];
2579 		if (!sband)
2580 			continue;
2581 
2582 		for (ch = 0; ch < sband->n_channels; ch++, idx++)
2583 			if (sband->channels[ch].center_freq == freq)
2584 				goto exit;
2585 	}
2586 
2587 exit:
2588 	return idx;
2589 }
2590 
2591 static int ath10k_wmi_op_pull_ch_info_ev(struct ath10k *ar, struct sk_buff *skb,
2592 					 struct wmi_ch_info_ev_arg *arg)
2593 {
2594 	struct wmi_chan_info_event *ev = (void *)skb->data;
2595 
2596 	if (skb->len < sizeof(*ev))
2597 		return -EPROTO;
2598 
2599 	skb_pull(skb, sizeof(*ev));
2600 	arg->err_code = ev->err_code;
2601 	arg->freq = ev->freq;
2602 	arg->cmd_flags = ev->cmd_flags;
2603 	arg->noise_floor = ev->noise_floor;
2604 	arg->rx_clear_count = ev->rx_clear_count;
2605 	arg->cycle_count = ev->cycle_count;
2606 
2607 	return 0;
2608 }
2609 
2610 static int ath10k_wmi_10_4_op_pull_ch_info_ev(struct ath10k *ar,
2611 					      struct sk_buff *skb,
2612 					      struct wmi_ch_info_ev_arg *arg)
2613 {
2614 	struct wmi_10_4_chan_info_event *ev = (void *)skb->data;
2615 
2616 	if (skb->len < sizeof(*ev))
2617 		return -EPROTO;
2618 
2619 	skb_pull(skb, sizeof(*ev));
2620 	arg->err_code = ev->err_code;
2621 	arg->freq = ev->freq;
2622 	arg->cmd_flags = ev->cmd_flags;
2623 	arg->noise_floor = ev->noise_floor;
2624 	arg->rx_clear_count = ev->rx_clear_count;
2625 	arg->cycle_count = ev->cycle_count;
2626 	arg->chan_tx_pwr_range = ev->chan_tx_pwr_range;
2627 	arg->chan_tx_pwr_tp = ev->chan_tx_pwr_tp;
2628 	arg->rx_frame_count = ev->rx_frame_count;
2629 
2630 	return 0;
2631 }
2632 
2633 /*
2634  * Handle the channel info event for firmware which only sends one
2635  * chan_info event per scanned channel.
2636  */
2637 static void ath10k_wmi_event_chan_info_unpaired(struct ath10k *ar,
2638 						struct chan_info_params *params)
2639 {
2640 	struct survey_info *survey;
2641 	int idx;
2642 
2643 	if (params->cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
2644 		ath10k_dbg(ar, ATH10K_DBG_WMI, "chan info report completed\n");
2645 		return;
2646 	}
2647 
2648 	idx = freq_to_idx(ar, params->freq);
2649 	if (idx >= ARRAY_SIZE(ar->survey)) {
2650 		ath10k_warn(ar, "chan info: invalid frequency %d (idx %d out of bounds)\n",
2651 			    params->freq, idx);
2652 		return;
2653 	}
2654 
2655 	survey = &ar->survey[idx];
2656 
2657 	if (!params->mac_clk_mhz)
2658 		return;
2659 
2660 	memset(survey, 0, sizeof(*survey));
2661 
2662 	survey->noise = params->noise_floor;
2663 	survey->time = (params->cycle_count / params->mac_clk_mhz) / 1000;
2664 	survey->time_busy = (params->rx_clear_count / params->mac_clk_mhz) / 1000;
2665 	survey->filled |= SURVEY_INFO_NOISE_DBM | SURVEY_INFO_TIME |
2666 			  SURVEY_INFO_TIME_BUSY;
2667 }
2668 
2669 /*
2670  * Handle the channel info event for firmware which sends chan_info
2671  * event in pairs(start and stop events) for every scanned channel.
2672  */
2673 static void ath10k_wmi_event_chan_info_paired(struct ath10k *ar,
2674 					      struct chan_info_params *params)
2675 {
2676 	struct survey_info *survey;
2677 	int idx;
2678 
2679 	idx = freq_to_idx(ar, params->freq);
2680 	if (idx >= ARRAY_SIZE(ar->survey)) {
2681 		ath10k_warn(ar, "chan info: invalid frequency %d (idx %d out of bounds)\n",
2682 			    params->freq, idx);
2683 		return;
2684 	}
2685 
2686 	if (params->cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
2687 		if (ar->ch_info_can_report_survey) {
2688 			survey = &ar->survey[idx];
2689 			survey->noise = params->noise_floor;
2690 			survey->filled = SURVEY_INFO_NOISE_DBM;
2691 
2692 			ath10k_hw_fill_survey_time(ar,
2693 						   survey,
2694 						   params->cycle_count,
2695 						   params->rx_clear_count,
2696 						   ar->survey_last_cycle_count,
2697 						   ar->survey_last_rx_clear_count);
2698 		}
2699 
2700 		ar->ch_info_can_report_survey = false;
2701 	} else {
2702 		ar->ch_info_can_report_survey = true;
2703 	}
2704 
2705 	if (!(params->cmd_flags & WMI_CHAN_INFO_FLAG_PRE_COMPLETE)) {
2706 		ar->survey_last_rx_clear_count = params->rx_clear_count;
2707 		ar->survey_last_cycle_count = params->cycle_count;
2708 	}
2709 }
2710 
2711 void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
2712 {
2713 	struct chan_info_params ch_info_param;
2714 	struct wmi_ch_info_ev_arg arg = {};
2715 	int ret;
2716 
2717 	ret = ath10k_wmi_pull_ch_info(ar, skb, &arg);
2718 	if (ret) {
2719 		ath10k_warn(ar, "failed to parse chan info event: %d\n", ret);
2720 		return;
2721 	}
2722 
2723 	ch_info_param.err_code = __le32_to_cpu(arg.err_code);
2724 	ch_info_param.freq = __le32_to_cpu(arg.freq);
2725 	ch_info_param.cmd_flags = __le32_to_cpu(arg.cmd_flags);
2726 	ch_info_param.noise_floor = __le32_to_cpu(arg.noise_floor);
2727 	ch_info_param.rx_clear_count = __le32_to_cpu(arg.rx_clear_count);
2728 	ch_info_param.cycle_count = __le32_to_cpu(arg.cycle_count);
2729 	ch_info_param.mac_clk_mhz = __le32_to_cpu(arg.mac_clk_mhz);
2730 
2731 	ath10k_dbg(ar, ATH10K_DBG_WMI,
2732 		   "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
2733 		   ch_info_param.err_code, ch_info_param.freq, ch_info_param.cmd_flags,
2734 		   ch_info_param.noise_floor, ch_info_param.rx_clear_count,
2735 		   ch_info_param.cycle_count);
2736 
2737 	spin_lock_bh(&ar->data_lock);
2738 
2739 	switch (ar->scan.state) {
2740 	case ATH10K_SCAN_IDLE:
2741 	case ATH10K_SCAN_STARTING:
2742 		ath10k_warn(ar, "received chan info event without a scan request, ignoring\n");
2743 		goto exit;
2744 	case ATH10K_SCAN_RUNNING:
2745 	case ATH10K_SCAN_ABORTING:
2746 		break;
2747 	}
2748 
2749 	if (test_bit(ATH10K_FW_FEATURE_SINGLE_CHAN_INFO_PER_CHANNEL,
2750 		     ar->running_fw->fw_file.fw_features))
2751 		ath10k_wmi_event_chan_info_unpaired(ar, &ch_info_param);
2752 	else
2753 		ath10k_wmi_event_chan_info_paired(ar, &ch_info_param);
2754 
2755 exit:
2756 	spin_unlock_bh(&ar->data_lock);
2757 }
2758 
2759 void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
2760 {
2761 	struct wmi_echo_ev_arg arg = {};
2762 	int ret;
2763 
2764 	ret = ath10k_wmi_pull_echo_ev(ar, skb, &arg);
2765 	if (ret) {
2766 		ath10k_warn(ar, "failed to parse echo: %d\n", ret);
2767 		return;
2768 	}
2769 
2770 	ath10k_dbg(ar, ATH10K_DBG_WMI,
2771 		   "wmi event echo value 0x%08x\n",
2772 		   le32_to_cpu(arg.value));
2773 
2774 	if (le32_to_cpu(arg.value) == ATH10K_WMI_BARRIER_ECHO_ID)
2775 		complete(&ar->wmi.barrier);
2776 }
2777 
2778 int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
2779 {
2780 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
2781 		   skb->len);
2782 
2783 	trace_ath10k_wmi_dbglog(ar, skb->data, skb->len);
2784 
2785 	return 0;
2786 }
2787 
2788 void ath10k_wmi_pull_pdev_stats_base(const struct wmi_pdev_stats_base *src,
2789 				     struct ath10k_fw_stats_pdev *dst)
2790 {
2791 	dst->ch_noise_floor = __le32_to_cpu(src->chan_nf);
2792 	dst->tx_frame_count = __le32_to_cpu(src->tx_frame_count);
2793 	dst->rx_frame_count = __le32_to_cpu(src->rx_frame_count);
2794 	dst->rx_clear_count = __le32_to_cpu(src->rx_clear_count);
2795 	dst->cycle_count = __le32_to_cpu(src->cycle_count);
2796 	dst->phy_err_count = __le32_to_cpu(src->phy_err_count);
2797 	dst->chan_tx_power = __le32_to_cpu(src->chan_tx_pwr);
2798 }
2799 
2800 void ath10k_wmi_pull_pdev_stats_tx(const struct wmi_pdev_stats_tx *src,
2801 				   struct ath10k_fw_stats_pdev *dst)
2802 {
2803 	dst->comp_queued = __le32_to_cpu(src->comp_queued);
2804 	dst->comp_delivered = __le32_to_cpu(src->comp_delivered);
2805 	dst->msdu_enqued = __le32_to_cpu(src->msdu_enqued);
2806 	dst->mpdu_enqued = __le32_to_cpu(src->mpdu_enqued);
2807 	dst->wmm_drop = __le32_to_cpu(src->wmm_drop);
2808 	dst->local_enqued = __le32_to_cpu(src->local_enqued);
2809 	dst->local_freed = __le32_to_cpu(src->local_freed);
2810 	dst->hw_queued = __le32_to_cpu(src->hw_queued);
2811 	dst->hw_reaped = __le32_to_cpu(src->hw_reaped);
2812 	dst->underrun = __le32_to_cpu(src->underrun);
2813 	dst->tx_abort = __le32_to_cpu(src->tx_abort);
2814 	dst->mpdus_requed = __le32_to_cpu(src->mpdus_requed);
2815 	dst->tx_ko = __le32_to_cpu(src->tx_ko);
2816 	dst->data_rc = __le32_to_cpu(src->data_rc);
2817 	dst->self_triggers = __le32_to_cpu(src->self_triggers);
2818 	dst->sw_retry_failure = __le32_to_cpu(src->sw_retry_failure);
2819 	dst->illgl_rate_phy_err = __le32_to_cpu(src->illgl_rate_phy_err);
2820 	dst->pdev_cont_xretry = __le32_to_cpu(src->pdev_cont_xretry);
2821 	dst->pdev_tx_timeout = __le32_to_cpu(src->pdev_tx_timeout);
2822 	dst->pdev_resets = __le32_to_cpu(src->pdev_resets);
2823 	dst->phy_underrun = __le32_to_cpu(src->phy_underrun);
2824 	dst->txop_ovf = __le32_to_cpu(src->txop_ovf);
2825 }
2826 
2827 static void
2828 ath10k_wmi_10_4_pull_pdev_stats_tx(const struct wmi_10_4_pdev_stats_tx *src,
2829 				   struct ath10k_fw_stats_pdev *dst)
2830 {
2831 	dst->comp_queued = __le32_to_cpu(src->comp_queued);
2832 	dst->comp_delivered = __le32_to_cpu(src->comp_delivered);
2833 	dst->msdu_enqued = __le32_to_cpu(src->msdu_enqued);
2834 	dst->mpdu_enqued = __le32_to_cpu(src->mpdu_enqued);
2835 	dst->wmm_drop = __le32_to_cpu(src->wmm_drop);
2836 	dst->local_enqued = __le32_to_cpu(src->local_enqued);
2837 	dst->local_freed = __le32_to_cpu(src->local_freed);
2838 	dst->hw_queued = __le32_to_cpu(src->hw_queued);
2839 	dst->hw_reaped = __le32_to_cpu(src->hw_reaped);
2840 	dst->underrun = __le32_to_cpu(src->underrun);
2841 	dst->tx_abort = __le32_to_cpu(src->tx_abort);
2842 	dst->mpdus_requed = __le32_to_cpu(src->mpdus_requed);
2843 	dst->tx_ko = __le32_to_cpu(src->tx_ko);
2844 	dst->data_rc = __le32_to_cpu(src->data_rc);
2845 	dst->self_triggers = __le32_to_cpu(src->self_triggers);
2846 	dst->sw_retry_failure = __le32_to_cpu(src->sw_retry_failure);
2847 	dst->illgl_rate_phy_err = __le32_to_cpu(src->illgl_rate_phy_err);
2848 	dst->pdev_cont_xretry = __le32_to_cpu(src->pdev_cont_xretry);
2849 	dst->pdev_tx_timeout = __le32_to_cpu(src->pdev_tx_timeout);
2850 	dst->pdev_resets = __le32_to_cpu(src->pdev_resets);
2851 	dst->phy_underrun = __le32_to_cpu(src->phy_underrun);
2852 	dst->txop_ovf = __le32_to_cpu(src->txop_ovf);
2853 	dst->hw_paused = __le32_to_cpu(src->hw_paused);
2854 	dst->seq_posted = __le32_to_cpu(src->seq_posted);
2855 	dst->seq_failed_queueing =
2856 		__le32_to_cpu(src->seq_failed_queueing);
2857 	dst->seq_completed = __le32_to_cpu(src->seq_completed);
2858 	dst->seq_restarted = __le32_to_cpu(src->seq_restarted);
2859 	dst->mu_seq_posted = __le32_to_cpu(src->mu_seq_posted);
2860 	dst->mpdus_sw_flush = __le32_to_cpu(src->mpdus_sw_flush);
2861 	dst->mpdus_hw_filter = __le32_to_cpu(src->mpdus_hw_filter);
2862 	dst->mpdus_truncated = __le32_to_cpu(src->mpdus_truncated);
2863 	dst->mpdus_ack_failed = __le32_to_cpu(src->mpdus_ack_failed);
2864 	dst->mpdus_hw_filter = __le32_to_cpu(src->mpdus_hw_filter);
2865 	dst->mpdus_expired = __le32_to_cpu(src->mpdus_expired);
2866 }
2867 
2868 void ath10k_wmi_pull_pdev_stats_rx(const struct wmi_pdev_stats_rx *src,
2869 				   struct ath10k_fw_stats_pdev *dst)
2870 {
2871 	dst->mid_ppdu_route_change = __le32_to_cpu(src->mid_ppdu_route_change);
2872 	dst->status_rcvd = __le32_to_cpu(src->status_rcvd);
2873 	dst->r0_frags = __le32_to_cpu(src->r0_frags);
2874 	dst->r1_frags = __le32_to_cpu(src->r1_frags);
2875 	dst->r2_frags = __le32_to_cpu(src->r2_frags);
2876 	dst->r3_frags = __le32_to_cpu(src->r3_frags);
2877 	dst->htt_msdus = __le32_to_cpu(src->htt_msdus);
2878 	dst->htt_mpdus = __le32_to_cpu(src->htt_mpdus);
2879 	dst->loc_msdus = __le32_to_cpu(src->loc_msdus);
2880 	dst->loc_mpdus = __le32_to_cpu(src->loc_mpdus);
2881 	dst->oversize_amsdu = __le32_to_cpu(src->oversize_amsdu);
2882 	dst->phy_errs = __le32_to_cpu(src->phy_errs);
2883 	dst->phy_err_drop = __le32_to_cpu(src->phy_err_drop);
2884 	dst->mpdu_errs = __le32_to_cpu(src->mpdu_errs);
2885 }
2886 
2887 void ath10k_wmi_pull_pdev_stats_extra(const struct wmi_pdev_stats_extra *src,
2888 				      struct ath10k_fw_stats_pdev *dst)
2889 {
2890 	dst->ack_rx_bad = __le32_to_cpu(src->ack_rx_bad);
2891 	dst->rts_bad = __le32_to_cpu(src->rts_bad);
2892 	dst->rts_good = __le32_to_cpu(src->rts_good);
2893 	dst->fcs_bad = __le32_to_cpu(src->fcs_bad);
2894 	dst->no_beacons = __le32_to_cpu(src->no_beacons);
2895 	dst->mib_int_count = __le32_to_cpu(src->mib_int_count);
2896 }
2897 
2898 void ath10k_wmi_pull_peer_stats(const struct wmi_peer_stats *src,
2899 				struct ath10k_fw_stats_peer *dst)
2900 {
2901 	ether_addr_copy(dst->peer_macaddr, src->peer_macaddr.addr);
2902 	dst->peer_rssi = __le32_to_cpu(src->peer_rssi);
2903 	dst->peer_tx_rate = __le32_to_cpu(src->peer_tx_rate);
2904 }
2905 
2906 static void
2907 ath10k_wmi_10_4_pull_peer_stats(const struct wmi_10_4_peer_stats *src,
2908 				struct ath10k_fw_stats_peer *dst)
2909 {
2910 	ether_addr_copy(dst->peer_macaddr, src->peer_macaddr.addr);
2911 	dst->peer_rssi = __le32_to_cpu(src->peer_rssi);
2912 	dst->peer_tx_rate = __le32_to_cpu(src->peer_tx_rate);
2913 	dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
2914 }
2915 
2916 static void
2917 ath10k_wmi_10_4_pull_vdev_stats(const struct wmi_vdev_stats_extd *src,
2918 				struct ath10k_fw_stats_vdev_extd *dst)
2919 {
2920 	dst->vdev_id = __le32_to_cpu(src->vdev_id);
2921 	dst->ppdu_aggr_cnt = __le32_to_cpu(src->ppdu_aggr_cnt);
2922 	dst->ppdu_noack = __le32_to_cpu(src->ppdu_noack);
2923 	dst->mpdu_queued = __le32_to_cpu(src->mpdu_queued);
2924 	dst->ppdu_nonaggr_cnt = __le32_to_cpu(src->ppdu_nonaggr_cnt);
2925 	dst->mpdu_sw_requeued = __le32_to_cpu(src->mpdu_sw_requeued);
2926 	dst->mpdu_suc_retry = __le32_to_cpu(src->mpdu_suc_retry);
2927 	dst->mpdu_suc_multitry = __le32_to_cpu(src->mpdu_suc_multitry);
2928 	dst->mpdu_fail_retry = __le32_to_cpu(src->mpdu_fail_retry);
2929 	dst->tx_ftm_suc = __le32_to_cpu(src->tx_ftm_suc);
2930 	dst->tx_ftm_suc_retry = __le32_to_cpu(src->tx_ftm_suc_retry);
2931 	dst->tx_ftm_fail = __le32_to_cpu(src->tx_ftm_fail);
2932 	dst->rx_ftmr_cnt = __le32_to_cpu(src->rx_ftmr_cnt);
2933 	dst->rx_ftmr_dup_cnt = __le32_to_cpu(src->rx_ftmr_dup_cnt);
2934 	dst->rx_iftmr_cnt = __le32_to_cpu(src->rx_iftmr_cnt);
2935 	dst->rx_iftmr_dup_cnt = __le32_to_cpu(src->rx_iftmr_dup_cnt);
2936 }
2937 
2938 static int ath10k_wmi_main_op_pull_fw_stats(struct ath10k *ar,
2939 					    struct sk_buff *skb,
2940 					    struct ath10k_fw_stats *stats)
2941 {
2942 	const struct wmi_stats_event *ev = (void *)skb->data;
2943 	u32 num_pdev_stats, num_peer_stats;
2944 	int i;
2945 
2946 	if (!skb_pull(skb, sizeof(*ev)))
2947 		return -EPROTO;
2948 
2949 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
2950 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
2951 
2952 	for (i = 0; i < num_pdev_stats; i++) {
2953 		const struct wmi_pdev_stats *src;
2954 		struct ath10k_fw_stats_pdev *dst;
2955 
2956 		src = (void *)skb->data;
2957 		if (!skb_pull(skb, sizeof(*src)))
2958 			return -EPROTO;
2959 
2960 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2961 		if (!dst)
2962 			continue;
2963 
2964 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
2965 		ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
2966 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
2967 
2968 		list_add_tail(&dst->list, &stats->pdevs);
2969 	}
2970 
2971 	/* fw doesn't implement vdev stats */
2972 
2973 	for (i = 0; i < num_peer_stats; i++) {
2974 		const struct wmi_peer_stats *src;
2975 		struct ath10k_fw_stats_peer *dst;
2976 
2977 		src = (void *)skb->data;
2978 		if (!skb_pull(skb, sizeof(*src)))
2979 			return -EPROTO;
2980 
2981 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
2982 		if (!dst)
2983 			continue;
2984 
2985 		ath10k_wmi_pull_peer_stats(src, dst);
2986 		list_add_tail(&dst->list, &stats->peers);
2987 	}
2988 
2989 	return 0;
2990 }
2991 
2992 static int ath10k_wmi_10x_op_pull_fw_stats(struct ath10k *ar,
2993 					   struct sk_buff *skb,
2994 					   struct ath10k_fw_stats *stats)
2995 {
2996 	const struct wmi_stats_event *ev = (void *)skb->data;
2997 	u32 num_pdev_stats, num_peer_stats;
2998 	int i;
2999 
3000 	if (!skb_pull(skb, sizeof(*ev)))
3001 		return -EPROTO;
3002 
3003 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
3004 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
3005 
3006 	for (i = 0; i < num_pdev_stats; i++) {
3007 		const struct wmi_10x_pdev_stats *src;
3008 		struct ath10k_fw_stats_pdev *dst;
3009 
3010 		src = (void *)skb->data;
3011 		if (!skb_pull(skb, sizeof(*src)))
3012 			return -EPROTO;
3013 
3014 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3015 		if (!dst)
3016 			continue;
3017 
3018 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
3019 		ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
3020 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
3021 		ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
3022 
3023 		list_add_tail(&dst->list, &stats->pdevs);
3024 	}
3025 
3026 	/* fw doesn't implement vdev stats */
3027 
3028 	for (i = 0; i < num_peer_stats; i++) {
3029 		const struct wmi_10x_peer_stats *src;
3030 		struct ath10k_fw_stats_peer *dst;
3031 
3032 		src = (void *)skb->data;
3033 		if (!skb_pull(skb, sizeof(*src)))
3034 			return -EPROTO;
3035 
3036 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3037 		if (!dst)
3038 			continue;
3039 
3040 		ath10k_wmi_pull_peer_stats(&src->old, dst);
3041 
3042 		dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
3043 
3044 		list_add_tail(&dst->list, &stats->peers);
3045 	}
3046 
3047 	return 0;
3048 }
3049 
3050 static int ath10k_wmi_10_2_op_pull_fw_stats(struct ath10k *ar,
3051 					    struct sk_buff *skb,
3052 					    struct ath10k_fw_stats *stats)
3053 {
3054 	const struct wmi_10_2_stats_event *ev = (void *)skb->data;
3055 	u32 num_pdev_stats;
3056 	u32 num_pdev_ext_stats;
3057 	u32 num_peer_stats;
3058 	int i;
3059 
3060 	if (!skb_pull(skb, sizeof(*ev)))
3061 		return -EPROTO;
3062 
3063 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
3064 	num_pdev_ext_stats = __le32_to_cpu(ev->num_pdev_ext_stats);
3065 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
3066 
3067 	for (i = 0; i < num_pdev_stats; i++) {
3068 		const struct wmi_10_2_pdev_stats *src;
3069 		struct ath10k_fw_stats_pdev *dst;
3070 
3071 		src = (void *)skb->data;
3072 		if (!skb_pull(skb, sizeof(*src)))
3073 			return -EPROTO;
3074 
3075 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3076 		if (!dst)
3077 			continue;
3078 
3079 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
3080 		ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
3081 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
3082 		ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
3083 		/* FIXME: expose 10.2 specific values */
3084 
3085 		list_add_tail(&dst->list, &stats->pdevs);
3086 	}
3087 
3088 	for (i = 0; i < num_pdev_ext_stats; i++) {
3089 		const struct wmi_10_2_pdev_ext_stats *src;
3090 
3091 		src = (void *)skb->data;
3092 		if (!skb_pull(skb, sizeof(*src)))
3093 			return -EPROTO;
3094 
3095 		/* FIXME: expose values to userspace
3096 		 *
3097 		 * Note: Even though this loop seems to do nothing it is
3098 		 * required to parse following sub-structures properly.
3099 		 */
3100 	}
3101 
3102 	/* fw doesn't implement vdev stats */
3103 
3104 	for (i = 0; i < num_peer_stats; i++) {
3105 		const struct wmi_10_2_peer_stats *src;
3106 		struct ath10k_fw_stats_peer *dst;
3107 
3108 		src = (void *)skb->data;
3109 		if (!skb_pull(skb, sizeof(*src)))
3110 			return -EPROTO;
3111 
3112 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3113 		if (!dst)
3114 			continue;
3115 
3116 		ath10k_wmi_pull_peer_stats(&src->old, dst);
3117 
3118 		dst->peer_rx_rate = __le32_to_cpu(src->peer_rx_rate);
3119 		/* FIXME: expose 10.2 specific values */
3120 
3121 		list_add_tail(&dst->list, &stats->peers);
3122 	}
3123 
3124 	return 0;
3125 }
3126 
3127 static int ath10k_wmi_10_2_4_op_pull_fw_stats(struct ath10k *ar,
3128 					      struct sk_buff *skb,
3129 					      struct ath10k_fw_stats *stats)
3130 {
3131 	const struct wmi_10_2_stats_event *ev = (void *)skb->data;
3132 	u32 num_pdev_stats;
3133 	u32 num_pdev_ext_stats;
3134 	u32 num_peer_stats;
3135 	int i;
3136 
3137 	if (!skb_pull(skb, sizeof(*ev)))
3138 		return -EPROTO;
3139 
3140 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
3141 	num_pdev_ext_stats = __le32_to_cpu(ev->num_pdev_ext_stats);
3142 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
3143 
3144 	for (i = 0; i < num_pdev_stats; i++) {
3145 		const struct wmi_10_2_pdev_stats *src;
3146 		struct ath10k_fw_stats_pdev *dst;
3147 
3148 		src = (void *)skb->data;
3149 		if (!skb_pull(skb, sizeof(*src)))
3150 			return -EPROTO;
3151 
3152 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3153 		if (!dst)
3154 			continue;
3155 
3156 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
3157 		ath10k_wmi_pull_pdev_stats_tx(&src->tx, dst);
3158 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
3159 		ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
3160 		/* FIXME: expose 10.2 specific values */
3161 
3162 		list_add_tail(&dst->list, &stats->pdevs);
3163 	}
3164 
3165 	for (i = 0; i < num_pdev_ext_stats; i++) {
3166 		const struct wmi_10_2_pdev_ext_stats *src;
3167 
3168 		src = (void *)skb->data;
3169 		if (!skb_pull(skb, sizeof(*src)))
3170 			return -EPROTO;
3171 
3172 		/* FIXME: expose values to userspace
3173 		 *
3174 		 * Note: Even though this loop seems to do nothing it is
3175 		 * required to parse following sub-structures properly.
3176 		 */
3177 	}
3178 
3179 	/* fw doesn't implement vdev stats */
3180 
3181 	for (i = 0; i < num_peer_stats; i++) {
3182 		const struct wmi_10_2_4_ext_peer_stats *src;
3183 		struct ath10k_fw_stats_peer *dst;
3184 		int stats_len;
3185 
3186 		if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
3187 			stats_len = sizeof(struct wmi_10_2_4_ext_peer_stats);
3188 		else
3189 			stats_len = sizeof(struct wmi_10_2_4_peer_stats);
3190 
3191 		src = (void *)skb->data;
3192 		if (!skb_pull(skb, stats_len))
3193 			return -EPROTO;
3194 
3195 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3196 		if (!dst)
3197 			continue;
3198 
3199 		ath10k_wmi_pull_peer_stats(&src->common.old, dst);
3200 
3201 		dst->peer_rx_rate = __le32_to_cpu(src->common.peer_rx_rate);
3202 
3203 		if (ath10k_peer_stats_enabled(ar))
3204 			dst->rx_duration = __le32_to_cpu(src->rx_duration);
3205 		/* FIXME: expose 10.2 specific values */
3206 
3207 		list_add_tail(&dst->list, &stats->peers);
3208 	}
3209 
3210 	return 0;
3211 }
3212 
3213 static int ath10k_wmi_10_4_op_pull_fw_stats(struct ath10k *ar,
3214 					    struct sk_buff *skb,
3215 					    struct ath10k_fw_stats *stats)
3216 {
3217 	const struct wmi_10_2_stats_event *ev = (void *)skb->data;
3218 	u32 num_pdev_stats;
3219 	u32 num_pdev_ext_stats;
3220 	u32 num_vdev_stats;
3221 	u32 num_peer_stats;
3222 	u32 num_bcnflt_stats;
3223 	u32 stats_id;
3224 	int i;
3225 
3226 	if (!skb_pull(skb, sizeof(*ev)))
3227 		return -EPROTO;
3228 
3229 	num_pdev_stats = __le32_to_cpu(ev->num_pdev_stats);
3230 	num_pdev_ext_stats = __le32_to_cpu(ev->num_pdev_ext_stats);
3231 	num_vdev_stats = __le32_to_cpu(ev->num_vdev_stats);
3232 	num_peer_stats = __le32_to_cpu(ev->num_peer_stats);
3233 	num_bcnflt_stats = __le32_to_cpu(ev->num_bcnflt_stats);
3234 	stats_id = __le32_to_cpu(ev->stats_id);
3235 
3236 	for (i = 0; i < num_pdev_stats; i++) {
3237 		const struct wmi_10_4_pdev_stats *src;
3238 		struct ath10k_fw_stats_pdev *dst;
3239 
3240 		src = (void *)skb->data;
3241 		if (!skb_pull(skb, sizeof(*src)))
3242 			return -EPROTO;
3243 
3244 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3245 		if (!dst)
3246 			continue;
3247 
3248 		ath10k_wmi_pull_pdev_stats_base(&src->base, dst);
3249 		ath10k_wmi_10_4_pull_pdev_stats_tx(&src->tx, dst);
3250 		ath10k_wmi_pull_pdev_stats_rx(&src->rx, dst);
3251 		dst->rx_ovfl_errs = __le32_to_cpu(src->rx_ovfl_errs);
3252 		ath10k_wmi_pull_pdev_stats_extra(&src->extra, dst);
3253 
3254 		list_add_tail(&dst->list, &stats->pdevs);
3255 	}
3256 
3257 	for (i = 0; i < num_pdev_ext_stats; i++) {
3258 		const struct wmi_10_2_pdev_ext_stats *src;
3259 
3260 		src = (void *)skb->data;
3261 		if (!skb_pull(skb, sizeof(*src)))
3262 			return -EPROTO;
3263 
3264 		/* FIXME: expose values to userspace
3265 		 *
3266 		 * Note: Even though this loop seems to do nothing it is
3267 		 * required to parse following sub-structures properly.
3268 		 */
3269 	}
3270 
3271 	for (i = 0; i < num_vdev_stats; i++) {
3272 		const struct wmi_vdev_stats *src;
3273 
3274 		/* Ignore vdev stats here as it has only vdev id. Actual vdev
3275 		 * stats will be retrieved from vdev extended stats.
3276 		 */
3277 		src = (void *)skb->data;
3278 		if (!skb_pull(skb, sizeof(*src)))
3279 			return -EPROTO;
3280 	}
3281 
3282 	for (i = 0; i < num_peer_stats; i++) {
3283 		const struct wmi_10_4_peer_stats *src;
3284 		struct ath10k_fw_stats_peer *dst;
3285 
3286 		src = (void *)skb->data;
3287 		if (!skb_pull(skb, sizeof(*src)))
3288 			return -EPROTO;
3289 
3290 		dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3291 		if (!dst)
3292 			continue;
3293 
3294 		ath10k_wmi_10_4_pull_peer_stats(src, dst);
3295 		list_add_tail(&dst->list, &stats->peers);
3296 	}
3297 
3298 	for (i = 0; i < num_bcnflt_stats; i++) {
3299 		const struct wmi_10_4_bss_bcn_filter_stats *src;
3300 
3301 		src = (void *)skb->data;
3302 		if (!skb_pull(skb, sizeof(*src)))
3303 			return -EPROTO;
3304 
3305 		/* FIXME: expose values to userspace
3306 		 *
3307 		 * Note: Even though this loop seems to do nothing it is
3308 		 * required to parse following sub-structures properly.
3309 		 */
3310 	}
3311 
3312 	if (stats_id & WMI_10_4_STAT_PEER_EXTD) {
3313 		stats->extended = true;
3314 
3315 		for (i = 0; i < num_peer_stats; i++) {
3316 			const struct wmi_10_4_peer_extd_stats *src;
3317 			struct ath10k_fw_extd_stats_peer *dst;
3318 
3319 			src = (void *)skb->data;
3320 			if (!skb_pull(skb, sizeof(*src)))
3321 				return -EPROTO;
3322 
3323 			dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3324 			if (!dst)
3325 				continue;
3326 
3327 			ether_addr_copy(dst->peer_macaddr,
3328 					src->peer_macaddr.addr);
3329 			dst->rx_duration = __le32_to_cpu(src->rx_duration);
3330 			list_add_tail(&dst->list, &stats->peers_extd);
3331 		}
3332 	}
3333 
3334 	if (stats_id & WMI_10_4_STAT_VDEV_EXTD) {
3335 		for (i = 0; i < num_vdev_stats; i++) {
3336 			const struct wmi_vdev_stats_extd *src;
3337 			struct ath10k_fw_stats_vdev_extd *dst;
3338 
3339 			src = (void *)skb->data;
3340 			if (!skb_pull(skb, sizeof(*src)))
3341 				return -EPROTO;
3342 
3343 			dst = kzalloc(sizeof(*dst), GFP_ATOMIC);
3344 			if (!dst)
3345 				continue;
3346 			ath10k_wmi_10_4_pull_vdev_stats(src, dst);
3347 			list_add_tail(&dst->list, &stats->vdevs);
3348 		}
3349 	}
3350 
3351 	return 0;
3352 }
3353 
3354 void ath10k_wmi_event_update_stats(struct ath10k *ar, struct sk_buff *skb)
3355 {
3356 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
3357 	ath10k_debug_fw_stats_process(ar, skb);
3358 }
3359 
3360 static int
3361 ath10k_wmi_op_pull_vdev_start_ev(struct ath10k *ar, struct sk_buff *skb,
3362 				 struct wmi_vdev_start_ev_arg *arg)
3363 {
3364 	struct wmi_vdev_start_response_event *ev = (void *)skb->data;
3365 
3366 	if (skb->len < sizeof(*ev))
3367 		return -EPROTO;
3368 
3369 	skb_pull(skb, sizeof(*ev));
3370 	arg->vdev_id = ev->vdev_id;
3371 	arg->req_id = ev->req_id;
3372 	arg->resp_type = ev->resp_type;
3373 	arg->status = ev->status;
3374 
3375 	return 0;
3376 }
3377 
3378 void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar, struct sk_buff *skb)
3379 {
3380 	struct wmi_vdev_start_ev_arg arg = {};
3381 	int ret;
3382 	u32 status;
3383 
3384 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
3385 
3386 	ar->last_wmi_vdev_start_status = 0;
3387 
3388 	ret = ath10k_wmi_pull_vdev_start(ar, skb, &arg);
3389 	if (ret) {
3390 		ath10k_warn(ar, "failed to parse vdev start event: %d\n", ret);
3391 		ar->last_wmi_vdev_start_status = ret;
3392 		goto out;
3393 	}
3394 
3395 	status = __le32_to_cpu(arg.status);
3396 	if (WARN_ON_ONCE(status)) {
3397 		ath10k_warn(ar, "vdev-start-response reports status error: %d (%s)\n",
3398 			    status, (status == WMI_VDEV_START_CHAN_INVALID) ?
3399 			    "chan-invalid" : "unknown");
3400 		/* Setup is done one way or another though, so we should still
3401 		 * do the completion, so don't return here.
3402 		 */
3403 		ar->last_wmi_vdev_start_status = -EINVAL;
3404 	}
3405 
3406 out:
3407 	complete(&ar->vdev_setup_done);
3408 }
3409 
3410 void ath10k_wmi_event_vdev_stopped(struct ath10k *ar, struct sk_buff *skb)
3411 {
3412 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
3413 	complete(&ar->vdev_setup_done);
3414 }
3415 
3416 static int
3417 ath10k_wmi_op_pull_peer_kick_ev(struct ath10k *ar, struct sk_buff *skb,
3418 				struct wmi_peer_kick_ev_arg *arg)
3419 {
3420 	struct wmi_peer_sta_kickout_event *ev = (void *)skb->data;
3421 
3422 	if (skb->len < sizeof(*ev))
3423 		return -EPROTO;
3424 
3425 	skb_pull(skb, sizeof(*ev));
3426 	arg->mac_addr = ev->peer_macaddr.addr;
3427 
3428 	return 0;
3429 }
3430 
3431 void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar, struct sk_buff *skb)
3432 {
3433 	struct wmi_peer_kick_ev_arg arg = {};
3434 	struct ieee80211_sta *sta;
3435 	int ret;
3436 
3437 	ret = ath10k_wmi_pull_peer_kick(ar, skb, &arg);
3438 	if (ret) {
3439 		ath10k_warn(ar, "failed to parse peer kickout event: %d\n",
3440 			    ret);
3441 		return;
3442 	}
3443 
3444 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
3445 		   arg.mac_addr);
3446 
3447 	rcu_read_lock();
3448 
3449 	sta = ieee80211_find_sta_by_ifaddr(ar->hw, arg.mac_addr, NULL);
3450 	if (!sta) {
3451 		ath10k_warn(ar, "Spurious quick kickout for STA %pM\n",
3452 			    arg.mac_addr);
3453 		goto exit;
3454 	}
3455 
3456 	ieee80211_report_low_ack(sta, 10);
3457 
3458 exit:
3459 	rcu_read_unlock();
3460 }
3461 
3462 /*
3463  * FIXME
3464  *
3465  * We don't report to mac80211 sleep state of connected
3466  * stations. Due to this mac80211 can't fill in TIM IE
3467  * correctly.
3468  *
3469  * I know of no way of getting nullfunc frames that contain
3470  * sleep transition from connected stations - these do not
3471  * seem to be sent from the target to the host. There also
3472  * doesn't seem to be a dedicated event for that. So the
3473  * only way left to do this would be to read tim_bitmap
3474  * during SWBA.
3475  *
3476  * We could probably try using tim_bitmap from SWBA to tell
3477  * mac80211 which stations are asleep and which are not. The
3478  * problem here is calling mac80211 functions so many times
3479  * could take too long and make us miss the time to submit
3480  * the beacon to the target.
3481  *
3482  * So as a workaround we try to extend the TIM IE if there
3483  * is unicast buffered for stations with aid > 7 and fill it
3484  * in ourselves.
3485  */
3486 static void ath10k_wmi_update_tim(struct ath10k *ar,
3487 				  struct ath10k_vif *arvif,
3488 				  struct sk_buff *bcn,
3489 				  const struct wmi_tim_info_arg *tim_info)
3490 {
3491 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
3492 	struct ieee80211_tim_ie *tim;
3493 	u8 *ies, *ie;
3494 	u8 ie_len, pvm_len;
3495 	__le32 t;
3496 	u32 v, tim_len;
3497 
3498 	/* When FW reports 0 in tim_len, ensure atleast first byte
3499 	 * in tim_bitmap is considered for pvm calculation.
3500 	 */
3501 	tim_len = tim_info->tim_len ? __le32_to_cpu(tim_info->tim_len) : 1;
3502 
3503 	/* if next SWBA has no tim_changed the tim_bitmap is garbage.
3504 	 * we must copy the bitmap upon change and reuse it later
3505 	 */
3506 	if (__le32_to_cpu(tim_info->tim_changed)) {
3507 		int i;
3508 
3509 		if (sizeof(arvif->u.ap.tim_bitmap) < tim_len) {
3510 			ath10k_warn(ar, "SWBA TIM field is too big (%u), truncated it to %zu",
3511 				    tim_len, sizeof(arvif->u.ap.tim_bitmap));
3512 			tim_len = sizeof(arvif->u.ap.tim_bitmap);
3513 		}
3514 
3515 		for (i = 0; i < tim_len; i++) {
3516 			t = tim_info->tim_bitmap[i / 4];
3517 			v = __le32_to_cpu(t);
3518 			arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
3519 		}
3520 
3521 		/* FW reports either length 0 or length based on max supported
3522 		 * station. so we calculate this on our own
3523 		 */
3524 		arvif->u.ap.tim_len = 0;
3525 		for (i = 0; i < tim_len; i++)
3526 			if (arvif->u.ap.tim_bitmap[i])
3527 				arvif->u.ap.tim_len = i;
3528 
3529 		arvif->u.ap.tim_len++;
3530 	}
3531 
3532 	ies = bcn->data;
3533 	ies += ieee80211_hdrlen(hdr->frame_control);
3534 	ies += 12; /* fixed parameters */
3535 
3536 	ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
3537 				    (u8 *)skb_tail_pointer(bcn) - ies);
3538 	if (!ie) {
3539 		if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3540 			ath10k_warn(ar, "no tim ie found;\n");
3541 		return;
3542 	}
3543 
3544 	tim = (void *)ie + 2;
3545 	ie_len = ie[1];
3546 	pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
3547 
3548 	if (pvm_len < arvif->u.ap.tim_len) {
3549 		int expand_size = tim_len - pvm_len;
3550 		int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
3551 		void *next_ie = ie + 2 + ie_len;
3552 
3553 		if (skb_put(bcn, expand_size)) {
3554 			memmove(next_ie + expand_size, next_ie, move_size);
3555 
3556 			ie[1] += expand_size;
3557 			ie_len += expand_size;
3558 			pvm_len += expand_size;
3559 		} else {
3560 			ath10k_warn(ar, "tim expansion failed\n");
3561 		}
3562 	}
3563 
3564 	if (pvm_len > tim_len) {
3565 		ath10k_warn(ar, "tim pvm length is too great (%d)\n", pvm_len);
3566 		return;
3567 	}
3568 
3569 	tim->bitmap_ctrl = !!__le32_to_cpu(tim_info->tim_mcast);
3570 	memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
3571 
3572 	if (tim->dtim_count == 0) {
3573 		ATH10K_SKB_CB(bcn)->flags |= ATH10K_SKB_F_DTIM_ZERO;
3574 
3575 		if (__le32_to_cpu(tim_info->tim_mcast) == 1)
3576 			ATH10K_SKB_CB(bcn)->flags |= ATH10K_SKB_F_DELIVER_CAB;
3577 	}
3578 
3579 	ath10k_dbg(ar, ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
3580 		   tim->dtim_count, tim->dtim_period,
3581 		   tim->bitmap_ctrl, pvm_len);
3582 }
3583 
3584 static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
3585 				  struct sk_buff *bcn,
3586 				  const struct wmi_p2p_noa_info *noa)
3587 {
3588 	if (!arvif->vif->p2p)
3589 		return;
3590 
3591 	ath10k_dbg(ar, ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
3592 
3593 	if (noa->changed & WMI_P2P_NOA_CHANGED_BIT)
3594 		ath10k_p2p_noa_update(arvif, noa);
3595 
3596 	if (arvif->u.ap.noa_data)
3597 		if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
3598 			skb_put_data(bcn, arvif->u.ap.noa_data,
3599 				     arvif->u.ap.noa_len);
3600 }
3601 
3602 static int ath10k_wmi_op_pull_swba_ev(struct ath10k *ar, struct sk_buff *skb,
3603 				      struct wmi_swba_ev_arg *arg)
3604 {
3605 	struct wmi_host_swba_event *ev = (void *)skb->data;
3606 	u32 map;
3607 	size_t i;
3608 
3609 	if (skb->len < sizeof(*ev))
3610 		return -EPROTO;
3611 
3612 	skb_pull(skb, sizeof(*ev));
3613 	arg->vdev_map = ev->vdev_map;
3614 
3615 	for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3616 		if (!(map & BIT(0)))
3617 			continue;
3618 
3619 		/* If this happens there were some changes in firmware and
3620 		 * ath10k should update the max size of tim_info array.
3621 		 */
3622 		if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3623 			break;
3624 
3625 		if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3626 		     sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3627 			ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3628 			return -EPROTO;
3629 		}
3630 
3631 		arg->tim_info[i].tim_len = ev->bcn_info[i].tim_info.tim_len;
3632 		arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3633 		arg->tim_info[i].tim_bitmap =
3634 				ev->bcn_info[i].tim_info.tim_bitmap;
3635 		arg->tim_info[i].tim_changed =
3636 				ev->bcn_info[i].tim_info.tim_changed;
3637 		arg->tim_info[i].tim_num_ps_pending =
3638 				ev->bcn_info[i].tim_info.tim_num_ps_pending;
3639 
3640 		arg->noa_info[i] = &ev->bcn_info[i].p2p_noa_info;
3641 		i++;
3642 	}
3643 
3644 	return 0;
3645 }
3646 
3647 static int ath10k_wmi_10_2_4_op_pull_swba_ev(struct ath10k *ar,
3648 					     struct sk_buff *skb,
3649 					     struct wmi_swba_ev_arg *arg)
3650 {
3651 	struct wmi_10_2_4_host_swba_event *ev = (void *)skb->data;
3652 	u32 map;
3653 	size_t i;
3654 
3655 	if (skb->len < sizeof(*ev))
3656 		return -EPROTO;
3657 
3658 	skb_pull(skb, sizeof(*ev));
3659 	arg->vdev_map = ev->vdev_map;
3660 
3661 	for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3662 		if (!(map & BIT(0)))
3663 			continue;
3664 
3665 		/* If this happens there were some changes in firmware and
3666 		 * ath10k should update the max size of tim_info array.
3667 		 */
3668 		if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3669 			break;
3670 
3671 		if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3672 		     sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3673 			ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3674 			return -EPROTO;
3675 		}
3676 
3677 		arg->tim_info[i].tim_len = ev->bcn_info[i].tim_info.tim_len;
3678 		arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3679 		arg->tim_info[i].tim_bitmap =
3680 				ev->bcn_info[i].tim_info.tim_bitmap;
3681 		arg->tim_info[i].tim_changed =
3682 				ev->bcn_info[i].tim_info.tim_changed;
3683 		arg->tim_info[i].tim_num_ps_pending =
3684 				ev->bcn_info[i].tim_info.tim_num_ps_pending;
3685 		i++;
3686 	}
3687 
3688 	return 0;
3689 }
3690 
3691 static int ath10k_wmi_10_4_op_pull_swba_ev(struct ath10k *ar,
3692 					   struct sk_buff *skb,
3693 					   struct wmi_swba_ev_arg *arg)
3694 {
3695 	struct wmi_10_4_host_swba_event *ev = (void *)skb->data;
3696 	u32 map, tim_len;
3697 	size_t i;
3698 
3699 	if (skb->len < sizeof(*ev))
3700 		return -EPROTO;
3701 
3702 	skb_pull(skb, sizeof(*ev));
3703 	arg->vdev_map = ev->vdev_map;
3704 
3705 	for (i = 0, map = __le32_to_cpu(ev->vdev_map); map; map >>= 1) {
3706 		if (!(map & BIT(0)))
3707 			continue;
3708 
3709 		/* If this happens there were some changes in firmware and
3710 		 * ath10k should update the max size of tim_info array.
3711 		 */
3712 		if (WARN_ON_ONCE(i == ARRAY_SIZE(arg->tim_info)))
3713 			break;
3714 
3715 		if (__le32_to_cpu(ev->bcn_info[i].tim_info.tim_len) >
3716 		      sizeof(ev->bcn_info[i].tim_info.tim_bitmap)) {
3717 			ath10k_warn(ar, "refusing to parse invalid swba structure\n");
3718 			return -EPROTO;
3719 		}
3720 
3721 		tim_len = __le32_to_cpu(ev->bcn_info[i].tim_info.tim_len);
3722 		if (tim_len) {
3723 			/* Exclude 4 byte guard length */
3724 			tim_len -= 4;
3725 			arg->tim_info[i].tim_len = __cpu_to_le32(tim_len);
3726 		} else {
3727 			arg->tim_info[i].tim_len = 0;
3728 		}
3729 
3730 		arg->tim_info[i].tim_mcast = ev->bcn_info[i].tim_info.tim_mcast;
3731 		arg->tim_info[i].tim_bitmap =
3732 				ev->bcn_info[i].tim_info.tim_bitmap;
3733 		arg->tim_info[i].tim_changed =
3734 				ev->bcn_info[i].tim_info.tim_changed;
3735 		arg->tim_info[i].tim_num_ps_pending =
3736 				ev->bcn_info[i].tim_info.tim_num_ps_pending;
3737 
3738 		/* 10.4 firmware doesn't have p2p support. notice of absence
3739 		 * info can be ignored for now.
3740 		 */
3741 
3742 		i++;
3743 	}
3744 
3745 	return 0;
3746 }
3747 
3748 static enum wmi_txbf_conf ath10k_wmi_10_4_txbf_conf_scheme(struct ath10k *ar)
3749 {
3750 	return WMI_TXBF_CONF_BEFORE_ASSOC;
3751 }
3752 
3753 void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
3754 {
3755 	struct wmi_swba_ev_arg arg = {};
3756 	u32 map;
3757 	int i = -1;
3758 	const struct wmi_tim_info_arg *tim_info;
3759 	const struct wmi_p2p_noa_info *noa_info;
3760 	struct ath10k_vif *arvif;
3761 	struct sk_buff *bcn;
3762 	dma_addr_t paddr;
3763 	int ret, vdev_id = 0;
3764 
3765 	ret = ath10k_wmi_pull_swba(ar, skb, &arg);
3766 	if (ret) {
3767 		ath10k_warn(ar, "failed to parse swba event: %d\n", ret);
3768 		return;
3769 	}
3770 
3771 	map = __le32_to_cpu(arg.vdev_map);
3772 
3773 	ath10k_dbg(ar, ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
3774 		   map);
3775 
3776 	for (; map; map >>= 1, vdev_id++) {
3777 		if (!(map & 0x1))
3778 			continue;
3779 
3780 		i++;
3781 
3782 		if (i >= WMI_MAX_AP_VDEV) {
3783 			ath10k_warn(ar, "swba has corrupted vdev map\n");
3784 			break;
3785 		}
3786 
3787 		tim_info = &arg.tim_info[i];
3788 		noa_info = arg.noa_info[i];
3789 
3790 		ath10k_dbg(ar, ATH10K_DBG_MGMT,
3791 			   "mgmt event bcn_info %d tim_len %d mcast %d changed %d num_ps_pending %d bitmap 0x%08x%08x%08x%08x\n",
3792 			   i,
3793 			   __le32_to_cpu(tim_info->tim_len),
3794 			   __le32_to_cpu(tim_info->tim_mcast),
3795 			   __le32_to_cpu(tim_info->tim_changed),
3796 			   __le32_to_cpu(tim_info->tim_num_ps_pending),
3797 			   __le32_to_cpu(tim_info->tim_bitmap[3]),
3798 			   __le32_to_cpu(tim_info->tim_bitmap[2]),
3799 			   __le32_to_cpu(tim_info->tim_bitmap[1]),
3800 			   __le32_to_cpu(tim_info->tim_bitmap[0]));
3801 
3802 		/* TODO: Only first 4 word from tim_bitmap is dumped.
3803 		 * Extend debug code to dump full tim_bitmap.
3804 		 */
3805 
3806 		arvif = ath10k_get_arvif(ar, vdev_id);
3807 		if (arvif == NULL) {
3808 			ath10k_warn(ar, "no vif for vdev_id %d found\n",
3809 				    vdev_id);
3810 			continue;
3811 		}
3812 
3813 		/* mac80211 would have already asked us to stop beaconing and
3814 		 * bring the vdev down, so continue in that case
3815 		 */
3816 		if (!arvif->is_up)
3817 			continue;
3818 
3819 		/* There are no completions for beacons so wait for next SWBA
3820 		 * before telling mac80211 to decrement CSA counter
3821 		 *
3822 		 * Once CSA counter is completed stop sending beacons until
3823 		 * actual channel switch is done
3824 		 */
3825 		if (arvif->vif->csa_active &&
3826 		    ieee80211_csa_is_complete(arvif->vif)) {
3827 			ieee80211_csa_finish(arvif->vif);
3828 			continue;
3829 		}
3830 
3831 		bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
3832 		if (!bcn) {
3833 			ath10k_warn(ar, "could not get mac80211 beacon\n");
3834 			continue;
3835 		}
3836 
3837 		ath10k_tx_h_seq_no(arvif->vif, bcn);
3838 		ath10k_wmi_update_tim(ar, arvif, bcn, tim_info);
3839 		ath10k_wmi_update_noa(ar, arvif, bcn, noa_info);
3840 
3841 		spin_lock_bh(&ar->data_lock);
3842 
3843 		if (arvif->beacon) {
3844 			switch (arvif->beacon_state) {
3845 			case ATH10K_BEACON_SENT:
3846 				break;
3847 			case ATH10K_BEACON_SCHEDULED:
3848 				ath10k_warn(ar, "SWBA overrun on vdev %d, skipped old beacon\n",
3849 					    arvif->vdev_id);
3850 				break;
3851 			case ATH10K_BEACON_SENDING:
3852 				ath10k_warn(ar, "SWBA overrun on vdev %d, skipped new beacon\n",
3853 					    arvif->vdev_id);
3854 				dev_kfree_skb(bcn);
3855 				goto skip;
3856 			}
3857 
3858 			ath10k_mac_vif_beacon_free(arvif);
3859 		}
3860 
3861 		if (!arvif->beacon_buf) {
3862 			paddr = dma_map_single(arvif->ar->dev, bcn->data,
3863 					       bcn->len, DMA_TO_DEVICE);
3864 			ret = dma_mapping_error(arvif->ar->dev, paddr);
3865 			if (ret) {
3866 				ath10k_warn(ar, "failed to map beacon: %d\n",
3867 					    ret);
3868 				dev_kfree_skb_any(bcn);
3869 				goto skip;
3870 			}
3871 
3872 			ATH10K_SKB_CB(bcn)->paddr = paddr;
3873 		} else {
3874 			if (bcn->len > IEEE80211_MAX_FRAME_LEN) {
3875 				ath10k_warn(ar, "trimming beacon %d -> %d bytes!\n",
3876 					    bcn->len, IEEE80211_MAX_FRAME_LEN);
3877 				skb_trim(bcn, IEEE80211_MAX_FRAME_LEN);
3878 			}
3879 			memcpy(arvif->beacon_buf, bcn->data, bcn->len);
3880 			ATH10K_SKB_CB(bcn)->paddr = arvif->beacon_paddr;
3881 		}
3882 
3883 		arvif->beacon = bcn;
3884 		arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
3885 
3886 		trace_ath10k_tx_hdr(ar, bcn->data, bcn->len);
3887 		trace_ath10k_tx_payload(ar, bcn->data, bcn->len);
3888 
3889 skip:
3890 		spin_unlock_bh(&ar->data_lock);
3891 	}
3892 
3893 	ath10k_wmi_tx_beacons_nowait(ar);
3894 }
3895 
3896 void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar, struct sk_buff *skb)
3897 {
3898 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
3899 }
3900 
3901 static void ath10k_radar_detected(struct ath10k *ar)
3902 {
3903 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs radar detected\n");
3904 	ATH10K_DFS_STAT_INC(ar, radar_detected);
3905 
3906 	/* Control radar events reporting in debugfs file
3907 	 * dfs_block_radar_events
3908 	 */
3909 	if (ar->dfs_block_radar_events)
3910 		ath10k_info(ar, "DFS Radar detected, but ignored as requested\n");
3911 	else
3912 		ieee80211_radar_detected(ar->hw);
3913 }
3914 
3915 static void ath10k_radar_confirmation_work(struct work_struct *work)
3916 {
3917 	struct ath10k *ar = container_of(work, struct ath10k,
3918 					 radar_confirmation_work);
3919 	struct ath10k_radar_found_info radar_info;
3920 	int ret, time_left;
3921 
3922 	reinit_completion(&ar->wmi.radar_confirm);
3923 
3924 	spin_lock_bh(&ar->data_lock);
3925 	memcpy(&radar_info, &ar->last_radar_info, sizeof(radar_info));
3926 	spin_unlock_bh(&ar->data_lock);
3927 
3928 	ret = ath10k_wmi_report_radar_found(ar, &radar_info);
3929 	if (ret) {
3930 		ath10k_warn(ar, "failed to send radar found %d\n", ret);
3931 		goto wait_complete;
3932 	}
3933 
3934 	time_left = wait_for_completion_timeout(&ar->wmi.radar_confirm,
3935 						ATH10K_WMI_DFS_CONF_TIMEOUT_HZ);
3936 	if (time_left) {
3937 		/* DFS Confirmation status event received and
3938 		 * necessary action completed.
3939 		 */
3940 		goto wait_complete;
3941 	} else {
3942 		/* DFS Confirmation event not received from FW.Considering this
3943 		 * as real radar.
3944 		 */
3945 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3946 			   "dfs confirmation not received from fw, considering as radar\n");
3947 		goto radar_detected;
3948 	}
3949 
3950 radar_detected:
3951 	ath10k_radar_detected(ar);
3952 
3953 	/* Reset state to allow sending confirmation on consecutive radar
3954 	 * detections, unless radar confirmation is disabled/stopped.
3955 	 */
3956 wait_complete:
3957 	spin_lock_bh(&ar->data_lock);
3958 	if (ar->radar_conf_state != ATH10K_RADAR_CONFIRMATION_STOPPED)
3959 		ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
3960 	spin_unlock_bh(&ar->data_lock);
3961 }
3962 
3963 static void ath10k_dfs_radar_report(struct ath10k *ar,
3964 				    struct wmi_phyerr_ev_arg *phyerr,
3965 				    const struct phyerr_radar_report *rr,
3966 				    u64 tsf)
3967 {
3968 	u32 reg0, reg1, tsf32l;
3969 	struct ieee80211_channel *ch;
3970 	struct pulse_event pe;
3971 	struct radar_detector_specs rs;
3972 	u64 tsf64;
3973 	u8 rssi, width;
3974 	struct ath10k_radar_found_info *radar_info;
3975 
3976 	reg0 = __le32_to_cpu(rr->reg0);
3977 	reg1 = __le32_to_cpu(rr->reg1);
3978 
3979 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3980 		   "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
3981 		   MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
3982 		   MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
3983 		   MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
3984 		   MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
3985 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3986 		   "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
3987 		   MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
3988 		   MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
3989 		   MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
3990 		   MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
3991 		   MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
3992 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
3993 		   "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
3994 		   MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
3995 		   MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
3996 
3997 	if (!ar->dfs_detector)
3998 		return;
3999 
4000 	spin_lock_bh(&ar->data_lock);
4001 	ch = ar->rx_channel;
4002 
4003 	/* fetch target operating channel during channel change */
4004 	if (!ch)
4005 		ch = ar->tgt_oper_chan;
4006 
4007 	spin_unlock_bh(&ar->data_lock);
4008 
4009 	if (!ch) {
4010 		ath10k_warn(ar, "failed to derive channel for radar pulse, treating as radar\n");
4011 		goto radar_detected;
4012 	}
4013 
4014 	/* report event to DFS pattern detector */
4015 	tsf32l = phyerr->tsf_timestamp;
4016 	tsf64 = tsf & (~0xFFFFFFFFULL);
4017 	tsf64 |= tsf32l;
4018 
4019 	width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
4020 	rssi = phyerr->rssi_combined;
4021 
4022 	/* hardware store this as 8 bit signed value,
4023 	 * set to zero if negative number
4024 	 */
4025 	if (rssi & 0x80)
4026 		rssi = 0;
4027 
4028 	pe.ts = tsf64;
4029 	pe.freq = ch->center_freq;
4030 	pe.width = width;
4031 	pe.rssi = rssi;
4032 	pe.chirp = (MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP) != 0);
4033 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4034 		   "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
4035 		   pe.freq, pe.width, pe.rssi, pe.ts);
4036 
4037 	ATH10K_DFS_STAT_INC(ar, pulses_detected);
4038 
4039 	if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe, &rs)) {
4040 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4041 			   "dfs no pulse pattern detected, yet\n");
4042 		return;
4043 	}
4044 
4045 	if ((test_bit(WMI_SERVICE_HOST_DFS_CHECK_SUPPORT, ar->wmi.svc_map)) &&
4046 	    ar->dfs_detector->region == NL80211_DFS_FCC) {
4047 		/* Consecutive radar indications need not be
4048 		 * sent to the firmware until we get confirmation
4049 		 * for the previous detected radar.
4050 		 */
4051 		spin_lock_bh(&ar->data_lock);
4052 		if (ar->radar_conf_state != ATH10K_RADAR_CONFIRMATION_IDLE) {
4053 			spin_unlock_bh(&ar->data_lock);
4054 			return;
4055 		}
4056 		ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_INPROGRESS;
4057 		radar_info = &ar->last_radar_info;
4058 
4059 		radar_info->pri_min = rs.pri_min;
4060 		radar_info->pri_max = rs.pri_max;
4061 		radar_info->width_min = rs.width_min;
4062 		radar_info->width_max = rs.width_max;
4063 		/*TODO Find sidx_min and sidx_max */
4064 		radar_info->sidx_min = MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX);
4065 		radar_info->sidx_max = MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX);
4066 
4067 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4068 			   "sending wmi radar found cmd pri_min %d pri_max %d width_min %d width_max %d sidx_min %d sidx_max %d\n",
4069 			   radar_info->pri_min, radar_info->pri_max,
4070 			   radar_info->width_min, radar_info->width_max,
4071 			   radar_info->sidx_min, radar_info->sidx_max);
4072 		ieee80211_queue_work(ar->hw, &ar->radar_confirmation_work);
4073 		spin_unlock_bh(&ar->data_lock);
4074 		return;
4075 	}
4076 
4077 radar_detected:
4078 	ath10k_radar_detected(ar);
4079 }
4080 
4081 static int ath10k_dfs_fft_report(struct ath10k *ar,
4082 				 struct wmi_phyerr_ev_arg *phyerr,
4083 				 const struct phyerr_fft_report *fftr,
4084 				 u64 tsf)
4085 {
4086 	u32 reg0, reg1;
4087 	u8 rssi, peak_mag;
4088 
4089 	reg0 = __le32_to_cpu(fftr->reg0);
4090 	reg1 = __le32_to_cpu(fftr->reg1);
4091 	rssi = phyerr->rssi_combined;
4092 
4093 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4094 		   "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
4095 		   MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
4096 		   MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
4097 		   MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
4098 		   MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
4099 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4100 		   "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
4101 		   MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
4102 		   MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
4103 		   MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
4104 		   MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
4105 
4106 	peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
4107 
4108 	/* false event detection */
4109 	if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
4110 	    peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
4111 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
4112 		ATH10K_DFS_STAT_INC(ar, pulses_discarded);
4113 		return -EINVAL;
4114 	}
4115 
4116 	return 0;
4117 }
4118 
4119 void ath10k_wmi_event_dfs(struct ath10k *ar,
4120 			  struct wmi_phyerr_ev_arg *phyerr,
4121 			  u64 tsf)
4122 {
4123 	int buf_len, tlv_len, res, i = 0;
4124 	const struct phyerr_tlv *tlv;
4125 	const struct phyerr_radar_report *rr;
4126 	const struct phyerr_fft_report *fftr;
4127 	const u8 *tlv_buf;
4128 
4129 	buf_len = phyerr->buf_len;
4130 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4131 		   "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
4132 		   phyerr->phy_err_code, phyerr->rssi_combined,
4133 		   phyerr->tsf_timestamp, tsf, buf_len);
4134 
4135 	/* Skip event if DFS disabled */
4136 	if (!IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED))
4137 		return;
4138 
4139 	ATH10K_DFS_STAT_INC(ar, pulses_total);
4140 
4141 	while (i < buf_len) {
4142 		if (i + sizeof(*tlv) > buf_len) {
4143 			ath10k_warn(ar, "too short buf for tlv header (%d)\n",
4144 				    i);
4145 			return;
4146 		}
4147 
4148 		tlv = (struct phyerr_tlv *)&phyerr->buf[i];
4149 		tlv_len = __le16_to_cpu(tlv->len);
4150 		tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
4151 		ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4152 			   "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
4153 			   tlv_len, tlv->tag, tlv->sig);
4154 
4155 		switch (tlv->tag) {
4156 		case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
4157 			if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
4158 				ath10k_warn(ar, "too short radar pulse summary (%d)\n",
4159 					    i);
4160 				return;
4161 			}
4162 
4163 			rr = (struct phyerr_radar_report *)tlv_buf;
4164 			ath10k_dfs_radar_report(ar, phyerr, rr, tsf);
4165 			break;
4166 		case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
4167 			if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
4168 				ath10k_warn(ar, "too short fft report (%d)\n",
4169 					    i);
4170 				return;
4171 			}
4172 
4173 			fftr = (struct phyerr_fft_report *)tlv_buf;
4174 			res = ath10k_dfs_fft_report(ar, phyerr, fftr, tsf);
4175 			if (res)
4176 				return;
4177 			break;
4178 		}
4179 
4180 		i += sizeof(*tlv) + tlv_len;
4181 	}
4182 }
4183 
4184 void ath10k_wmi_event_spectral_scan(struct ath10k *ar,
4185 				    struct wmi_phyerr_ev_arg *phyerr,
4186 				    u64 tsf)
4187 {
4188 	int buf_len, tlv_len, res, i = 0;
4189 	struct phyerr_tlv *tlv;
4190 	const void *tlv_buf;
4191 	const struct phyerr_fft_report *fftr;
4192 	size_t fftr_len;
4193 
4194 	buf_len = phyerr->buf_len;
4195 
4196 	while (i < buf_len) {
4197 		if (i + sizeof(*tlv) > buf_len) {
4198 			ath10k_warn(ar, "failed to parse phyerr tlv header at byte %d\n",
4199 				    i);
4200 			return;
4201 		}
4202 
4203 		tlv = (struct phyerr_tlv *)&phyerr->buf[i];
4204 		tlv_len = __le16_to_cpu(tlv->len);
4205 		tlv_buf = &phyerr->buf[i + sizeof(*tlv)];
4206 
4207 		if (i + sizeof(*tlv) + tlv_len > buf_len) {
4208 			ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n",
4209 				    i);
4210 			return;
4211 		}
4212 
4213 		switch (tlv->tag) {
4214 		case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
4215 			if (sizeof(*fftr) > tlv_len) {
4216 				ath10k_warn(ar, "failed to parse fft report at byte %d\n",
4217 					    i);
4218 				return;
4219 			}
4220 
4221 			fftr_len = tlv_len - sizeof(*fftr);
4222 			fftr = tlv_buf;
4223 			res = ath10k_spectral_process_fft(ar, phyerr,
4224 							  fftr, fftr_len,
4225 							  tsf);
4226 			if (res < 0) {
4227 				ath10k_dbg(ar, ATH10K_DBG_WMI, "failed to process fft report: %d\n",
4228 					   res);
4229 				return;
4230 			}
4231 			break;
4232 		}
4233 
4234 		i += sizeof(*tlv) + tlv_len;
4235 	}
4236 }
4237 
4238 static int ath10k_wmi_op_pull_phyerr_ev_hdr(struct ath10k *ar,
4239 					    struct sk_buff *skb,
4240 					    struct wmi_phyerr_hdr_arg *arg)
4241 {
4242 	struct wmi_phyerr_event *ev = (void *)skb->data;
4243 
4244 	if (skb->len < sizeof(*ev))
4245 		return -EPROTO;
4246 
4247 	arg->num_phyerrs = __le32_to_cpu(ev->num_phyerrs);
4248 	arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
4249 	arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
4250 	arg->buf_len = skb->len - sizeof(*ev);
4251 	arg->phyerrs = ev->phyerrs;
4252 
4253 	return 0;
4254 }
4255 
4256 static int ath10k_wmi_10_4_op_pull_phyerr_ev_hdr(struct ath10k *ar,
4257 						 struct sk_buff *skb,
4258 						 struct wmi_phyerr_hdr_arg *arg)
4259 {
4260 	struct wmi_10_4_phyerr_event *ev = (void *)skb->data;
4261 
4262 	if (skb->len < sizeof(*ev))
4263 		return -EPROTO;
4264 
4265 	/* 10.4 firmware always reports only one phyerr */
4266 	arg->num_phyerrs = 1;
4267 
4268 	arg->tsf_l32 = __le32_to_cpu(ev->tsf_l32);
4269 	arg->tsf_u32 = __le32_to_cpu(ev->tsf_u32);
4270 	arg->buf_len = skb->len;
4271 	arg->phyerrs = skb->data;
4272 
4273 	return 0;
4274 }
4275 
4276 int ath10k_wmi_op_pull_phyerr_ev(struct ath10k *ar,
4277 				 const void *phyerr_buf,
4278 				 int left_len,
4279 				 struct wmi_phyerr_ev_arg *arg)
4280 {
4281 	const struct wmi_phyerr *phyerr = phyerr_buf;
4282 	int i;
4283 
4284 	if (left_len < sizeof(*phyerr)) {
4285 		ath10k_warn(ar, "wrong phyerr event head len %d (need: >=%zd)\n",
4286 			    left_len, sizeof(*phyerr));
4287 		return -EINVAL;
4288 	}
4289 
4290 	arg->tsf_timestamp = __le32_to_cpu(phyerr->tsf_timestamp);
4291 	arg->freq1 = __le16_to_cpu(phyerr->freq1);
4292 	arg->freq2 = __le16_to_cpu(phyerr->freq2);
4293 	arg->rssi_combined = phyerr->rssi_combined;
4294 	arg->chan_width_mhz = phyerr->chan_width_mhz;
4295 	arg->buf_len = __le32_to_cpu(phyerr->buf_len);
4296 	arg->buf = phyerr->buf;
4297 	arg->hdr_len = sizeof(*phyerr);
4298 
4299 	for (i = 0; i < 4; i++)
4300 		arg->nf_chains[i] = __le16_to_cpu(phyerr->nf_chains[i]);
4301 
4302 	switch (phyerr->phy_err_code) {
4303 	case PHY_ERROR_GEN_SPECTRAL_SCAN:
4304 		arg->phy_err_code = PHY_ERROR_SPECTRAL_SCAN;
4305 		break;
4306 	case PHY_ERROR_GEN_FALSE_RADAR_EXT:
4307 		arg->phy_err_code = PHY_ERROR_FALSE_RADAR_EXT;
4308 		break;
4309 	case PHY_ERROR_GEN_RADAR:
4310 		arg->phy_err_code = PHY_ERROR_RADAR;
4311 		break;
4312 	default:
4313 		arg->phy_err_code = PHY_ERROR_UNKNOWN;
4314 		break;
4315 	}
4316 
4317 	return 0;
4318 }
4319 
4320 static int ath10k_wmi_10_4_op_pull_phyerr_ev(struct ath10k *ar,
4321 					     const void *phyerr_buf,
4322 					     int left_len,
4323 					     struct wmi_phyerr_ev_arg *arg)
4324 {
4325 	const struct wmi_10_4_phyerr_event *phyerr = phyerr_buf;
4326 	u32 phy_err_mask;
4327 	int i;
4328 
4329 	if (left_len < sizeof(*phyerr)) {
4330 		ath10k_warn(ar, "wrong phyerr event head len %d (need: >=%zd)\n",
4331 			    left_len, sizeof(*phyerr));
4332 		return -EINVAL;
4333 	}
4334 
4335 	arg->tsf_timestamp = __le32_to_cpu(phyerr->tsf_timestamp);
4336 	arg->freq1 = __le16_to_cpu(phyerr->freq1);
4337 	arg->freq2 = __le16_to_cpu(phyerr->freq2);
4338 	arg->rssi_combined = phyerr->rssi_combined;
4339 	arg->chan_width_mhz = phyerr->chan_width_mhz;
4340 	arg->buf_len = __le32_to_cpu(phyerr->buf_len);
4341 	arg->buf = phyerr->buf;
4342 	arg->hdr_len = sizeof(*phyerr);
4343 
4344 	for (i = 0; i < 4; i++)
4345 		arg->nf_chains[i] = __le16_to_cpu(phyerr->nf_chains[i]);
4346 
4347 	phy_err_mask = __le32_to_cpu(phyerr->phy_err_mask[0]);
4348 
4349 	if (phy_err_mask & PHY_ERROR_10_4_SPECTRAL_SCAN_MASK)
4350 		arg->phy_err_code = PHY_ERROR_SPECTRAL_SCAN;
4351 	else if (phy_err_mask & PHY_ERROR_10_4_RADAR_MASK)
4352 		arg->phy_err_code = PHY_ERROR_RADAR;
4353 	else
4354 		arg->phy_err_code = PHY_ERROR_UNKNOWN;
4355 
4356 	return 0;
4357 }
4358 
4359 void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
4360 {
4361 	struct wmi_phyerr_hdr_arg hdr_arg = {};
4362 	struct wmi_phyerr_ev_arg phyerr_arg = {};
4363 	const void *phyerr;
4364 	u32 count, i, buf_len, phy_err_code;
4365 	u64 tsf;
4366 	int left_len, ret;
4367 
4368 	ATH10K_DFS_STAT_INC(ar, phy_errors);
4369 
4370 	ret = ath10k_wmi_pull_phyerr_hdr(ar, skb, &hdr_arg);
4371 	if (ret) {
4372 		ath10k_warn(ar, "failed to parse phyerr event hdr: %d\n", ret);
4373 		return;
4374 	}
4375 
4376 	/* Check number of included events */
4377 	count = hdr_arg.num_phyerrs;
4378 
4379 	left_len = hdr_arg.buf_len;
4380 
4381 	tsf = hdr_arg.tsf_u32;
4382 	tsf <<= 32;
4383 	tsf |= hdr_arg.tsf_l32;
4384 
4385 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4386 		   "wmi event phyerr count %d tsf64 0x%llX\n",
4387 		   count, tsf);
4388 
4389 	phyerr = hdr_arg.phyerrs;
4390 	for (i = 0; i < count; i++) {
4391 		ret = ath10k_wmi_pull_phyerr(ar, phyerr, left_len, &phyerr_arg);
4392 		if (ret) {
4393 			ath10k_warn(ar, "failed to parse phyerr event (%d)\n",
4394 				    i);
4395 			return;
4396 		}
4397 
4398 		left_len -= phyerr_arg.hdr_len;
4399 		buf_len = phyerr_arg.buf_len;
4400 		phy_err_code = phyerr_arg.phy_err_code;
4401 
4402 		if (left_len < buf_len) {
4403 			ath10k_warn(ar, "single event (%d) wrong buf len\n", i);
4404 			return;
4405 		}
4406 
4407 		left_len -= buf_len;
4408 
4409 		switch (phy_err_code) {
4410 		case PHY_ERROR_RADAR:
4411 			ath10k_wmi_event_dfs(ar, &phyerr_arg, tsf);
4412 			break;
4413 		case PHY_ERROR_SPECTRAL_SCAN:
4414 			ath10k_wmi_event_spectral_scan(ar, &phyerr_arg, tsf);
4415 			break;
4416 		case PHY_ERROR_FALSE_RADAR_EXT:
4417 			ath10k_wmi_event_dfs(ar, &phyerr_arg, tsf);
4418 			ath10k_wmi_event_spectral_scan(ar, &phyerr_arg, tsf);
4419 			break;
4420 		default:
4421 			break;
4422 		}
4423 
4424 		phyerr = phyerr + phyerr_arg.hdr_len + buf_len;
4425 	}
4426 }
4427 
4428 static int
4429 ath10k_wmi_10_4_op_pull_dfs_status_ev(struct ath10k *ar, struct sk_buff *skb,
4430 				      struct wmi_dfs_status_ev_arg *arg)
4431 {
4432 	struct wmi_dfs_status_ev_arg *ev = (void *)skb->data;
4433 
4434 	if (skb->len < sizeof(*ev))
4435 		return -EPROTO;
4436 
4437 	arg->status = ev->status;
4438 
4439 	return 0;
4440 }
4441 
4442 static void
4443 ath10k_wmi_event_dfs_status_check(struct ath10k *ar, struct sk_buff *skb)
4444 {
4445 	struct wmi_dfs_status_ev_arg status_arg = {};
4446 	int ret;
4447 
4448 	ret = ath10k_wmi_pull_dfs_status(ar, skb, &status_arg);
4449 
4450 	if (ret) {
4451 		ath10k_warn(ar, "failed to parse dfs status event: %d\n", ret);
4452 		return;
4453 	}
4454 
4455 	ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
4456 		   "dfs status event received from fw: %d\n",
4457 		   status_arg.status);
4458 
4459 	/* Even in case of radar detection failure we follow the same
4460 	 * behaviour as if radar is detected i.e to switch to a different
4461 	 * channel.
4462 	 */
4463 	if (status_arg.status == WMI_HW_RADAR_DETECTED ||
4464 	    status_arg.status == WMI_RADAR_DETECTION_FAIL)
4465 		ath10k_radar_detected(ar);
4466 	complete(&ar->wmi.radar_confirm);
4467 }
4468 
4469 void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
4470 {
4471 	struct wmi_roam_ev_arg arg = {};
4472 	int ret;
4473 	u32 vdev_id;
4474 	u32 reason;
4475 	s32 rssi;
4476 
4477 	ret = ath10k_wmi_pull_roam_ev(ar, skb, &arg);
4478 	if (ret) {
4479 		ath10k_warn(ar, "failed to parse roam event: %d\n", ret);
4480 		return;
4481 	}
4482 
4483 	vdev_id = __le32_to_cpu(arg.vdev_id);
4484 	reason = __le32_to_cpu(arg.reason);
4485 	rssi = __le32_to_cpu(arg.rssi);
4486 	rssi += WMI_SPECTRAL_NOISE_FLOOR_REF_DEFAULT;
4487 
4488 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4489 		   "wmi roam event vdev %u reason 0x%08x rssi %d\n",
4490 		   vdev_id, reason, rssi);
4491 
4492 	if (reason >= WMI_ROAM_REASON_MAX)
4493 		ath10k_warn(ar, "ignoring unknown roam event reason %d on vdev %i\n",
4494 			    reason, vdev_id);
4495 
4496 	switch (reason) {
4497 	case WMI_ROAM_REASON_BEACON_MISS:
4498 		ath10k_mac_handle_beacon_miss(ar, vdev_id);
4499 		break;
4500 	case WMI_ROAM_REASON_BETTER_AP:
4501 	case WMI_ROAM_REASON_LOW_RSSI:
4502 	case WMI_ROAM_REASON_SUITABLE_AP_FOUND:
4503 	case WMI_ROAM_REASON_HO_FAILED:
4504 		ath10k_warn(ar, "ignoring not implemented roam event reason %d on vdev %i\n",
4505 			    reason, vdev_id);
4506 		break;
4507 	}
4508 }
4509 
4510 void ath10k_wmi_event_profile_match(struct ath10k *ar, struct sk_buff *skb)
4511 {
4512 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
4513 }
4514 
4515 void ath10k_wmi_event_debug_print(struct ath10k *ar, struct sk_buff *skb)
4516 {
4517 	char buf[101], c;
4518 	int i;
4519 
4520 	for (i = 0; i < sizeof(buf) - 1; i++) {
4521 		if (i >= skb->len)
4522 			break;
4523 
4524 		c = skb->data[i];
4525 
4526 		if (c == '\0')
4527 			break;
4528 
4529 		if (isascii(c) && isprint(c))
4530 			buf[i] = c;
4531 		else
4532 			buf[i] = '.';
4533 	}
4534 
4535 	if (i == sizeof(buf) - 1)
4536 		ath10k_warn(ar, "wmi debug print truncated: %d\n", skb->len);
4537 
4538 	/* for some reason the debug prints end with \n, remove that */
4539 	if (skb->data[i - 1] == '\n')
4540 		i--;
4541 
4542 	/* the last byte is always reserved for the null character */
4543 	buf[i] = '\0';
4544 
4545 	ath10k_dbg(ar, ATH10K_DBG_WMI_PRINT, "wmi print '%s'\n", buf);
4546 }
4547 
4548 void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
4549 {
4550 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
4551 }
4552 
4553 void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar, struct sk_buff *skb)
4554 {
4555 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
4556 }
4557 
4558 void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
4559 					     struct sk_buff *skb)
4560 {
4561 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
4562 }
4563 
4564 void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
4565 					     struct sk_buff *skb)
4566 {
4567 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
4568 }
4569 
4570 void ath10k_wmi_event_rtt_error_report(struct ath10k *ar, struct sk_buff *skb)
4571 {
4572 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
4573 }
4574 
4575 void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar, struct sk_buff *skb)
4576 {
4577 	struct wmi_wow_ev_arg ev = {};
4578 	int ret;
4579 
4580 	complete(&ar->wow.wakeup_completed);
4581 
4582 	ret = ath10k_wmi_pull_wow_event(ar, skb, &ev);
4583 	if (ret) {
4584 		ath10k_warn(ar, "failed to parse wow wakeup event: %d\n", ret);
4585 		return;
4586 	}
4587 
4588 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wow wakeup host reason %s\n",
4589 		   wow_reason(ev.wake_reason));
4590 }
4591 
4592 void ath10k_wmi_event_dcs_interference(struct ath10k *ar, struct sk_buff *skb)
4593 {
4594 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
4595 }
4596 
4597 static u8 ath10k_tpc_config_get_rate(struct ath10k *ar,
4598 				     struct wmi_pdev_tpc_config_event *ev,
4599 				     u32 rate_idx, u32 num_chains,
4600 				     u32 rate_code, u8 type)
4601 {
4602 	u8 tpc, num_streams, preamble, ch, stm_idx;
4603 
4604 	num_streams = ATH10K_HW_NSS(rate_code);
4605 	preamble = ATH10K_HW_PREAMBLE(rate_code);
4606 	ch = num_chains - 1;
4607 
4608 	tpc = min_t(u8, ev->rates_array[rate_idx], ev->max_reg_allow_pow[ch]);
4609 
4610 	if (__le32_to_cpu(ev->num_tx_chain) <= 1)
4611 		goto out;
4612 
4613 	if (preamble == WMI_RATE_PREAMBLE_CCK)
4614 		goto out;
4615 
4616 	stm_idx = num_streams - 1;
4617 	if (num_chains <= num_streams)
4618 		goto out;
4619 
4620 	switch (type) {
4621 	case WMI_TPC_TABLE_TYPE_STBC:
4622 		tpc = min_t(u8, tpc,
4623 			    ev->max_reg_allow_pow_agstbc[ch - 1][stm_idx]);
4624 		break;
4625 	case WMI_TPC_TABLE_TYPE_TXBF:
4626 		tpc = min_t(u8, tpc,
4627 			    ev->max_reg_allow_pow_agtxbf[ch - 1][stm_idx]);
4628 		break;
4629 	case WMI_TPC_TABLE_TYPE_CDD:
4630 		tpc = min_t(u8, tpc,
4631 			    ev->max_reg_allow_pow_agcdd[ch - 1][stm_idx]);
4632 		break;
4633 	default:
4634 		ath10k_warn(ar, "unknown wmi tpc table type: %d\n", type);
4635 		tpc = 0;
4636 		break;
4637 	}
4638 
4639 out:
4640 	return tpc;
4641 }
4642 
4643 static void ath10k_tpc_config_disp_tables(struct ath10k *ar,
4644 					  struct wmi_pdev_tpc_config_event *ev,
4645 					  struct ath10k_tpc_stats *tpc_stats,
4646 					  u8 *rate_code, u16 *pream_table, u8 type)
4647 {
4648 	u32 i, j, pream_idx, flags;
4649 	u8 tpc[WMI_TPC_TX_N_CHAIN];
4650 	char tpc_value[WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
4651 	char buff[WMI_TPC_BUF_SIZE];
4652 
4653 	flags = __le32_to_cpu(ev->flags);
4654 
4655 	switch (type) {
4656 	case WMI_TPC_TABLE_TYPE_CDD:
4657 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_CDD)) {
4658 			ath10k_dbg(ar, ATH10K_DBG_WMI, "CDD not supported\n");
4659 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4660 			return;
4661 		}
4662 		break;
4663 	case WMI_TPC_TABLE_TYPE_STBC:
4664 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_STBC)) {
4665 			ath10k_dbg(ar, ATH10K_DBG_WMI, "STBC not supported\n");
4666 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4667 			return;
4668 		}
4669 		break;
4670 	case WMI_TPC_TABLE_TYPE_TXBF:
4671 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_TXBF)) {
4672 			ath10k_dbg(ar, ATH10K_DBG_WMI, "TXBF not supported\n");
4673 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
4674 			return;
4675 		}
4676 		break;
4677 	default:
4678 		ath10k_dbg(ar, ATH10K_DBG_WMI,
4679 			   "invalid table type in wmi tpc event: %d\n", type);
4680 		return;
4681 	}
4682 
4683 	pream_idx = 0;
4684 	for (i = 0; i < tpc_stats->rate_max; i++) {
4685 		memset(tpc_value, 0, sizeof(tpc_value));
4686 		memset(buff, 0, sizeof(buff));
4687 		if (i == pream_table[pream_idx])
4688 			pream_idx++;
4689 
4690 		for (j = 0; j < tpc_stats->num_tx_chain; j++) {
4691 			tpc[j] = ath10k_tpc_config_get_rate(ar, ev, i, j + 1,
4692 							    rate_code[i],
4693 							    type);
4694 			snprintf(buff, sizeof(buff), "%8d ", tpc[j]);
4695 			strlcat(tpc_value, buff, sizeof(tpc_value));
4696 		}
4697 		tpc_stats->tpc_table[type].pream_idx[i] = pream_idx;
4698 		tpc_stats->tpc_table[type].rate_code[i] = rate_code[i];
4699 		memcpy(tpc_stats->tpc_table[type].tpc_value[i],
4700 		       tpc_value, sizeof(tpc_value));
4701 	}
4702 }
4703 
4704 void ath10k_wmi_tpc_config_get_rate_code(u8 *rate_code, u16 *pream_table,
4705 					 u32 num_tx_chain)
4706 {
4707 	u32 i, j, pream_idx;
4708 	u8 rate_idx;
4709 
4710 	/* Create the rate code table based on the chains supported */
4711 	rate_idx = 0;
4712 	pream_idx = 0;
4713 
4714 	/* Fill CCK rate code */
4715 	for (i = 0; i < 4; i++) {
4716 		rate_code[rate_idx] =
4717 			ATH10K_HW_RATECODE(i, 0, WMI_RATE_PREAMBLE_CCK);
4718 		rate_idx++;
4719 	}
4720 	pream_table[pream_idx] = rate_idx;
4721 	pream_idx++;
4722 
4723 	/* Fill OFDM rate code */
4724 	for (i = 0; i < 8; i++) {
4725 		rate_code[rate_idx] =
4726 			ATH10K_HW_RATECODE(i, 0, WMI_RATE_PREAMBLE_OFDM);
4727 		rate_idx++;
4728 	}
4729 	pream_table[pream_idx] = rate_idx;
4730 	pream_idx++;
4731 
4732 	/* Fill HT20 rate code */
4733 	for (i = 0; i < num_tx_chain; i++) {
4734 		for (j = 0; j < 8; j++) {
4735 			rate_code[rate_idx] =
4736 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_HT);
4737 			rate_idx++;
4738 		}
4739 	}
4740 	pream_table[pream_idx] = rate_idx;
4741 	pream_idx++;
4742 
4743 	/* Fill HT40 rate code */
4744 	for (i = 0; i < num_tx_chain; i++) {
4745 		for (j = 0; j < 8; j++) {
4746 			rate_code[rate_idx] =
4747 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_HT);
4748 			rate_idx++;
4749 		}
4750 	}
4751 	pream_table[pream_idx] = rate_idx;
4752 	pream_idx++;
4753 
4754 	/* Fill VHT20 rate code */
4755 	for (i = 0; i < num_tx_chain; i++) {
4756 		for (j = 0; j < 10; j++) {
4757 			rate_code[rate_idx] =
4758 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4759 			rate_idx++;
4760 		}
4761 	}
4762 	pream_table[pream_idx] = rate_idx;
4763 	pream_idx++;
4764 
4765 	/* Fill VHT40 rate code */
4766 	for (i = 0; i < num_tx_chain; i++) {
4767 		for (j = 0; j < 10; j++) {
4768 			rate_code[rate_idx] =
4769 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4770 			rate_idx++;
4771 		}
4772 	}
4773 	pream_table[pream_idx] = rate_idx;
4774 	pream_idx++;
4775 
4776 	/* Fill VHT80 rate code */
4777 	for (i = 0; i < num_tx_chain; i++) {
4778 		for (j = 0; j < 10; j++) {
4779 			rate_code[rate_idx] =
4780 			ATH10K_HW_RATECODE(j, i, WMI_RATE_PREAMBLE_VHT);
4781 			rate_idx++;
4782 		}
4783 	}
4784 	pream_table[pream_idx] = rate_idx;
4785 	pream_idx++;
4786 
4787 	rate_code[rate_idx++] =
4788 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_CCK);
4789 	rate_code[rate_idx++] =
4790 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4791 	rate_code[rate_idx++] =
4792 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_CCK);
4793 	rate_code[rate_idx++] =
4794 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4795 	rate_code[rate_idx++] =
4796 		ATH10K_HW_RATECODE(0, 0, WMI_RATE_PREAMBLE_OFDM);
4797 
4798 	pream_table[pream_idx] = ATH10K_TPC_PREAM_TABLE_END;
4799 }
4800 
4801 void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar, struct sk_buff *skb)
4802 {
4803 	u32 num_tx_chain, rate_max;
4804 	u8 rate_code[WMI_TPC_RATE_MAX];
4805 	u16 pream_table[WMI_TPC_PREAM_TABLE_MAX];
4806 	struct wmi_pdev_tpc_config_event *ev;
4807 	struct ath10k_tpc_stats *tpc_stats;
4808 
4809 	ev = (struct wmi_pdev_tpc_config_event *)skb->data;
4810 
4811 	num_tx_chain = __le32_to_cpu(ev->num_tx_chain);
4812 
4813 	if (num_tx_chain > WMI_TPC_TX_N_CHAIN) {
4814 		ath10k_warn(ar, "number of tx chain is %d greater than TPC configured tx chain %d\n",
4815 			    num_tx_chain, WMI_TPC_TX_N_CHAIN);
4816 		return;
4817 	}
4818 
4819 	rate_max = __le32_to_cpu(ev->rate_max);
4820 	if (rate_max > WMI_TPC_RATE_MAX) {
4821 		ath10k_warn(ar, "number of rate is %d greater than TPC configured rate %d\n",
4822 			    rate_max, WMI_TPC_RATE_MAX);
4823 		rate_max = WMI_TPC_RATE_MAX;
4824 	}
4825 
4826 	tpc_stats = kzalloc(sizeof(*tpc_stats), GFP_ATOMIC);
4827 	if (!tpc_stats)
4828 		return;
4829 
4830 	ath10k_wmi_tpc_config_get_rate_code(rate_code, pream_table,
4831 					    num_tx_chain);
4832 
4833 	tpc_stats->chan_freq = __le32_to_cpu(ev->chan_freq);
4834 	tpc_stats->phy_mode = __le32_to_cpu(ev->phy_mode);
4835 	tpc_stats->ctl = __le32_to_cpu(ev->ctl);
4836 	tpc_stats->reg_domain = __le32_to_cpu(ev->reg_domain);
4837 	tpc_stats->twice_antenna_gain = a_sle32_to_cpu(ev->twice_antenna_gain);
4838 	tpc_stats->twice_antenna_reduction =
4839 		__le32_to_cpu(ev->twice_antenna_reduction);
4840 	tpc_stats->power_limit = __le32_to_cpu(ev->power_limit);
4841 	tpc_stats->twice_max_rd_power = __le32_to_cpu(ev->twice_max_rd_power);
4842 	tpc_stats->num_tx_chain = num_tx_chain;
4843 	tpc_stats->rate_max = rate_max;
4844 
4845 	ath10k_tpc_config_disp_tables(ar, ev, tpc_stats,
4846 				      rate_code, pream_table,
4847 				      WMI_TPC_TABLE_TYPE_CDD);
4848 	ath10k_tpc_config_disp_tables(ar, ev,  tpc_stats,
4849 				      rate_code, pream_table,
4850 				      WMI_TPC_TABLE_TYPE_STBC);
4851 	ath10k_tpc_config_disp_tables(ar, ev, tpc_stats,
4852 				      rate_code, pream_table,
4853 				      WMI_TPC_TABLE_TYPE_TXBF);
4854 
4855 	ath10k_debug_tpc_stats_process(ar, tpc_stats);
4856 
4857 	ath10k_dbg(ar, ATH10K_DBG_WMI,
4858 		   "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",
4859 		   __le32_to_cpu(ev->chan_freq),
4860 		   __le32_to_cpu(ev->phy_mode),
4861 		   __le32_to_cpu(ev->ctl),
4862 		   __le32_to_cpu(ev->reg_domain),
4863 		   a_sle32_to_cpu(ev->twice_antenna_gain),
4864 		   __le32_to_cpu(ev->twice_antenna_reduction),
4865 		   __le32_to_cpu(ev->power_limit),
4866 		   __le32_to_cpu(ev->twice_max_rd_power) / 2,
4867 		   __le32_to_cpu(ev->num_tx_chain),
4868 		   __le32_to_cpu(ev->rate_max));
4869 }
4870 
4871 static u8
4872 ath10k_wmi_tpc_final_get_rate(struct ath10k *ar,
4873 			      struct wmi_pdev_tpc_final_table_event *ev,
4874 			      u32 rate_idx, u32 num_chains,
4875 			      u32 rate_code, u8 type, u32 pream_idx)
4876 {
4877 	u8 tpc, num_streams, preamble, ch, stm_idx;
4878 	s8 pow_agcdd, pow_agstbc, pow_agtxbf;
4879 	int pream;
4880 
4881 	num_streams = ATH10K_HW_NSS(rate_code);
4882 	preamble = ATH10K_HW_PREAMBLE(rate_code);
4883 	ch = num_chains - 1;
4884 	stm_idx = num_streams - 1;
4885 	pream = -1;
4886 
4887 	if (__le32_to_cpu(ev->chan_freq) <= 2483) {
4888 		switch (pream_idx) {
4889 		case WMI_TPC_PREAM_2GHZ_CCK:
4890 			pream = 0;
4891 			break;
4892 		case WMI_TPC_PREAM_2GHZ_OFDM:
4893 			pream = 1;
4894 			break;
4895 		case WMI_TPC_PREAM_2GHZ_HT20:
4896 		case WMI_TPC_PREAM_2GHZ_VHT20:
4897 			pream = 2;
4898 			break;
4899 		case WMI_TPC_PREAM_2GHZ_HT40:
4900 		case WMI_TPC_PREAM_2GHZ_VHT40:
4901 			pream = 3;
4902 			break;
4903 		case WMI_TPC_PREAM_2GHZ_VHT80:
4904 			pream = 4;
4905 			break;
4906 		default:
4907 			pream = -1;
4908 			break;
4909 		}
4910 	}
4911 
4912 	if (__le32_to_cpu(ev->chan_freq) >= 5180) {
4913 		switch (pream_idx) {
4914 		case WMI_TPC_PREAM_5GHZ_OFDM:
4915 			pream = 0;
4916 			break;
4917 		case WMI_TPC_PREAM_5GHZ_HT20:
4918 		case WMI_TPC_PREAM_5GHZ_VHT20:
4919 			pream = 1;
4920 			break;
4921 		case WMI_TPC_PREAM_5GHZ_HT40:
4922 		case WMI_TPC_PREAM_5GHZ_VHT40:
4923 			pream = 2;
4924 			break;
4925 		case WMI_TPC_PREAM_5GHZ_VHT80:
4926 			pream = 3;
4927 			break;
4928 		case WMI_TPC_PREAM_5GHZ_HTCUP:
4929 			pream = 4;
4930 			break;
4931 		default:
4932 			pream = -1;
4933 			break;
4934 		}
4935 	}
4936 
4937 	if (pream == -1) {
4938 		ath10k_warn(ar, "unknown wmi tpc final index and frequency: %u, %u\n",
4939 			    pream_idx, __le32_to_cpu(ev->chan_freq));
4940 		tpc = 0;
4941 		goto out;
4942 	}
4943 
4944 	if (pream == 4)
4945 		tpc = min_t(u8, ev->rates_array[rate_idx],
4946 			    ev->max_reg_allow_pow[ch]);
4947 	else
4948 		tpc = min_t(u8, min_t(u8, ev->rates_array[rate_idx],
4949 				      ev->max_reg_allow_pow[ch]),
4950 			    ev->ctl_power_table[0][pream][stm_idx]);
4951 
4952 	if (__le32_to_cpu(ev->num_tx_chain) <= 1)
4953 		goto out;
4954 
4955 	if (preamble == WMI_RATE_PREAMBLE_CCK)
4956 		goto out;
4957 
4958 	if (num_chains <= num_streams)
4959 		goto out;
4960 
4961 	switch (type) {
4962 	case WMI_TPC_TABLE_TYPE_STBC:
4963 		pow_agstbc = ev->max_reg_allow_pow_agstbc[ch - 1][stm_idx];
4964 		if (pream == 4)
4965 			tpc = min_t(u8, tpc, pow_agstbc);
4966 		else
4967 			tpc = min_t(u8, min_t(u8, tpc, pow_agstbc),
4968 				    ev->ctl_power_table[0][pream][stm_idx]);
4969 		break;
4970 	case WMI_TPC_TABLE_TYPE_TXBF:
4971 		pow_agtxbf = ev->max_reg_allow_pow_agtxbf[ch - 1][stm_idx];
4972 		if (pream == 4)
4973 			tpc = min_t(u8, tpc, pow_agtxbf);
4974 		else
4975 			tpc = min_t(u8, min_t(u8, tpc, pow_agtxbf),
4976 				    ev->ctl_power_table[1][pream][stm_idx]);
4977 		break;
4978 	case WMI_TPC_TABLE_TYPE_CDD:
4979 		pow_agcdd = ev->max_reg_allow_pow_agcdd[ch - 1][stm_idx];
4980 		if (pream == 4)
4981 			tpc = min_t(u8, tpc, pow_agcdd);
4982 		else
4983 			tpc = min_t(u8, min_t(u8, tpc, pow_agcdd),
4984 				    ev->ctl_power_table[0][pream][stm_idx]);
4985 		break;
4986 	default:
4987 		ath10k_warn(ar, "unknown wmi tpc final table type: %d\n", type);
4988 		tpc = 0;
4989 		break;
4990 	}
4991 
4992 out:
4993 	return tpc;
4994 }
4995 
4996 static void
4997 ath10k_wmi_tpc_stats_final_disp_tables(struct ath10k *ar,
4998 				       struct wmi_pdev_tpc_final_table_event *ev,
4999 				       struct ath10k_tpc_stats_final *tpc_stats,
5000 				       u8 *rate_code, u16 *pream_table, u8 type)
5001 {
5002 	u32 i, j, pream_idx, flags;
5003 	u8 tpc[WMI_TPC_TX_N_CHAIN];
5004 	char tpc_value[WMI_TPC_TX_N_CHAIN * WMI_TPC_BUF_SIZE];
5005 	char buff[WMI_TPC_BUF_SIZE];
5006 
5007 	flags = __le32_to_cpu(ev->flags);
5008 
5009 	switch (type) {
5010 	case WMI_TPC_TABLE_TYPE_CDD:
5011 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_CDD)) {
5012 			ath10k_dbg(ar, ATH10K_DBG_WMI, "CDD not supported\n");
5013 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
5014 			return;
5015 		}
5016 		break;
5017 	case WMI_TPC_TABLE_TYPE_STBC:
5018 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_STBC)) {
5019 			ath10k_dbg(ar, ATH10K_DBG_WMI, "STBC not supported\n");
5020 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
5021 			return;
5022 		}
5023 		break;
5024 	case WMI_TPC_TABLE_TYPE_TXBF:
5025 		if (!(flags & WMI_TPC_CONFIG_EVENT_FLAG_TABLE_TXBF)) {
5026 			ath10k_dbg(ar, ATH10K_DBG_WMI, "TXBF not supported\n");
5027 			tpc_stats->flag[type] = ATH10K_TPC_TABLE_TYPE_FLAG;
5028 			return;
5029 		}
5030 		break;
5031 	default:
5032 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5033 			   "invalid table type in wmi tpc event: %d\n", type);
5034 		return;
5035 	}
5036 
5037 	pream_idx = 0;
5038 	for (i = 0; i < tpc_stats->rate_max; i++) {
5039 		memset(tpc_value, 0, sizeof(tpc_value));
5040 		memset(buff, 0, sizeof(buff));
5041 		if (i == pream_table[pream_idx])
5042 			pream_idx++;
5043 
5044 		for (j = 0; j < tpc_stats->num_tx_chain; j++) {
5045 			tpc[j] = ath10k_wmi_tpc_final_get_rate(ar, ev, i, j + 1,
5046 							       rate_code[i],
5047 							       type, pream_idx);
5048 			snprintf(buff, sizeof(buff), "%8d ", tpc[j]);
5049 			strlcat(tpc_value, buff, sizeof(tpc_value));
5050 		}
5051 		tpc_stats->tpc_table_final[type].pream_idx[i] = pream_idx;
5052 		tpc_stats->tpc_table_final[type].rate_code[i] = rate_code[i];
5053 		memcpy(tpc_stats->tpc_table_final[type].tpc_value[i],
5054 		       tpc_value, sizeof(tpc_value));
5055 	}
5056 }
5057 
5058 void ath10k_wmi_event_tpc_final_table(struct ath10k *ar, struct sk_buff *skb)
5059 {
5060 	u32 num_tx_chain, rate_max;
5061 	u8 rate_code[WMI_TPC_FINAL_RATE_MAX];
5062 	u16 pream_table[WMI_TPC_PREAM_TABLE_MAX];
5063 	struct wmi_pdev_tpc_final_table_event *ev;
5064 	struct ath10k_tpc_stats_final *tpc_stats;
5065 
5066 	ev = (struct wmi_pdev_tpc_final_table_event *)skb->data;
5067 
5068 	num_tx_chain = __le32_to_cpu(ev->num_tx_chain);
5069 	if (num_tx_chain > WMI_TPC_TX_N_CHAIN) {
5070 		ath10k_warn(ar, "number of tx chain is %d greater than TPC final configured tx chain %d\n",
5071 			    num_tx_chain, WMI_TPC_TX_N_CHAIN);
5072 		return;
5073 	}
5074 
5075 	rate_max = __le32_to_cpu(ev->rate_max);
5076 	if (rate_max > WMI_TPC_FINAL_RATE_MAX) {
5077 		ath10k_warn(ar, "number of rate is %d greater than TPC final configured rate %d\n",
5078 			    rate_max, WMI_TPC_FINAL_RATE_MAX);
5079 		rate_max = WMI_TPC_FINAL_RATE_MAX;
5080 	}
5081 
5082 	tpc_stats = kzalloc(sizeof(*tpc_stats), GFP_ATOMIC);
5083 	if (!tpc_stats)
5084 		return;
5085 
5086 	ath10k_wmi_tpc_config_get_rate_code(rate_code, pream_table,
5087 					    num_tx_chain);
5088 
5089 	tpc_stats->chan_freq = __le32_to_cpu(ev->chan_freq);
5090 	tpc_stats->phy_mode = __le32_to_cpu(ev->phy_mode);
5091 	tpc_stats->ctl = __le32_to_cpu(ev->ctl);
5092 	tpc_stats->reg_domain = __le32_to_cpu(ev->reg_domain);
5093 	tpc_stats->twice_antenna_gain = a_sle32_to_cpu(ev->twice_antenna_gain);
5094 	tpc_stats->twice_antenna_reduction =
5095 		__le32_to_cpu(ev->twice_antenna_reduction);
5096 	tpc_stats->power_limit = __le32_to_cpu(ev->power_limit);
5097 	tpc_stats->twice_max_rd_power = __le32_to_cpu(ev->twice_max_rd_power);
5098 	tpc_stats->num_tx_chain = num_tx_chain;
5099 	tpc_stats->rate_max = rate_max;
5100 
5101 	ath10k_wmi_tpc_stats_final_disp_tables(ar, ev, tpc_stats,
5102 					       rate_code, pream_table,
5103 					       WMI_TPC_TABLE_TYPE_CDD);
5104 	ath10k_wmi_tpc_stats_final_disp_tables(ar, ev,  tpc_stats,
5105 					       rate_code, pream_table,
5106 					       WMI_TPC_TABLE_TYPE_STBC);
5107 	ath10k_wmi_tpc_stats_final_disp_tables(ar, ev, tpc_stats,
5108 					       rate_code, pream_table,
5109 					       WMI_TPC_TABLE_TYPE_TXBF);
5110 
5111 	ath10k_debug_tpc_stats_final_process(ar, tpc_stats);
5112 
5113 	ath10k_dbg(ar, ATH10K_DBG_WMI,
5114 		   "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",
5115 		   __le32_to_cpu(ev->chan_freq),
5116 		   __le32_to_cpu(ev->phy_mode),
5117 		   __le32_to_cpu(ev->ctl),
5118 		   __le32_to_cpu(ev->reg_domain),
5119 		   a_sle32_to_cpu(ev->twice_antenna_gain),
5120 		   __le32_to_cpu(ev->twice_antenna_reduction),
5121 		   __le32_to_cpu(ev->power_limit),
5122 		   __le32_to_cpu(ev->twice_max_rd_power) / 2,
5123 		   __le32_to_cpu(ev->num_tx_chain),
5124 		   __le32_to_cpu(ev->rate_max));
5125 }
5126 
5127 static void
5128 ath10k_wmi_handle_tdls_peer_event(struct ath10k *ar, struct sk_buff *skb)
5129 {
5130 	struct wmi_tdls_peer_event *ev;
5131 	struct ath10k_peer *peer;
5132 	struct ath10k_vif *arvif;
5133 	int vdev_id;
5134 	int peer_status;
5135 	int peer_reason;
5136 	u8 reason;
5137 
5138 	if (skb->len < sizeof(*ev)) {
5139 		ath10k_err(ar, "received tdls peer event with invalid size (%d bytes)\n",
5140 			   skb->len);
5141 		return;
5142 	}
5143 
5144 	ev = (struct wmi_tdls_peer_event *)skb->data;
5145 	vdev_id = __le32_to_cpu(ev->vdev_id);
5146 	peer_status = __le32_to_cpu(ev->peer_status);
5147 	peer_reason = __le32_to_cpu(ev->peer_reason);
5148 
5149 	spin_lock_bh(&ar->data_lock);
5150 	peer = ath10k_peer_find(ar, vdev_id, ev->peer_macaddr.addr);
5151 	spin_unlock_bh(&ar->data_lock);
5152 
5153 	if (!peer) {
5154 		ath10k_warn(ar, "failed to find peer entry for %pM\n",
5155 			    ev->peer_macaddr.addr);
5156 		return;
5157 	}
5158 
5159 	switch (peer_status) {
5160 	case WMI_TDLS_SHOULD_TEARDOWN:
5161 		switch (peer_reason) {
5162 		case WMI_TDLS_TEARDOWN_REASON_PTR_TIMEOUT:
5163 		case WMI_TDLS_TEARDOWN_REASON_NO_RESPONSE:
5164 		case WMI_TDLS_TEARDOWN_REASON_RSSI:
5165 			reason = WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE;
5166 			break;
5167 		default:
5168 			reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
5169 			break;
5170 		}
5171 
5172 		arvif = ath10k_get_arvif(ar, vdev_id);
5173 		if (!arvif) {
5174 			ath10k_warn(ar, "received tdls peer event for invalid vdev id %u\n",
5175 				    vdev_id);
5176 			return;
5177 		}
5178 
5179 		ieee80211_tdls_oper_request(arvif->vif, ev->peer_macaddr.addr,
5180 					    NL80211_TDLS_TEARDOWN, reason,
5181 					    GFP_ATOMIC);
5182 
5183 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5184 			   "received tdls teardown event for peer %pM reason %u\n",
5185 			   ev->peer_macaddr.addr, peer_reason);
5186 		break;
5187 	default:
5188 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5189 			   "received unknown tdls peer event %u\n",
5190 			   peer_status);
5191 		break;
5192 	}
5193 }
5194 
5195 static void
5196 ath10k_wmi_event_peer_sta_ps_state_chg(struct ath10k *ar, struct sk_buff *skb)
5197 {
5198 	struct wmi_peer_sta_ps_state_chg_event *ev;
5199 	struct ieee80211_sta *sta;
5200 	struct ath10k_sta *arsta;
5201 	u8 peer_addr[ETH_ALEN];
5202 
5203 	lockdep_assert_held(&ar->data_lock);
5204 
5205 	ev = (struct wmi_peer_sta_ps_state_chg_event *)skb->data;
5206 	ether_addr_copy(peer_addr, ev->peer_macaddr.addr);
5207 
5208 	rcu_read_lock();
5209 
5210 	sta = ieee80211_find_sta_by_ifaddr(ar->hw, peer_addr, NULL);
5211 
5212 	if (!sta) {
5213 		ath10k_warn(ar, "failed to find station entry %pM\n",
5214 			    peer_addr);
5215 		goto exit;
5216 	}
5217 
5218 	arsta = (struct ath10k_sta *)sta->drv_priv;
5219 	arsta->peer_ps_state = __le32_to_cpu(ev->peer_ps_state);
5220 
5221 exit:
5222 	rcu_read_unlock();
5223 }
5224 
5225 void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar, struct sk_buff *skb)
5226 {
5227 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
5228 }
5229 
5230 void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar, struct sk_buff *skb)
5231 {
5232 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
5233 }
5234 
5235 void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar, struct sk_buff *skb)
5236 {
5237 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
5238 }
5239 
5240 void ath10k_wmi_event_delba_complete(struct ath10k *ar, struct sk_buff *skb)
5241 {
5242 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
5243 }
5244 
5245 void ath10k_wmi_event_addba_complete(struct ath10k *ar, struct sk_buff *skb)
5246 {
5247 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
5248 }
5249 
5250 void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
5251 						struct sk_buff *skb)
5252 {
5253 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
5254 }
5255 
5256 void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar, struct sk_buff *skb)
5257 {
5258 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
5259 }
5260 
5261 void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar, struct sk_buff *skb)
5262 {
5263 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
5264 }
5265 
5266 void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar, struct sk_buff *skb)
5267 {
5268 	ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
5269 }
5270 
5271 static int ath10k_wmi_alloc_chunk(struct ath10k *ar, u32 req_id,
5272 				  u32 num_units, u32 unit_len)
5273 {
5274 	dma_addr_t paddr;
5275 	u32 pool_size;
5276 	int idx = ar->wmi.num_mem_chunks;
5277 	void *vaddr;
5278 
5279 	pool_size = num_units * round_up(unit_len, 4);
5280 	vaddr = dma_alloc_coherent(ar->dev, pool_size, &paddr, GFP_KERNEL);
5281 
5282 	if (!vaddr)
5283 		return -ENOMEM;
5284 
5285 	ar->wmi.mem_chunks[idx].vaddr = vaddr;
5286 	ar->wmi.mem_chunks[idx].paddr = paddr;
5287 	ar->wmi.mem_chunks[idx].len = pool_size;
5288 	ar->wmi.mem_chunks[idx].req_id = req_id;
5289 	ar->wmi.num_mem_chunks++;
5290 
5291 	return num_units;
5292 }
5293 
5294 static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
5295 				     u32 num_units, u32 unit_len)
5296 {
5297 	int ret;
5298 
5299 	while (num_units) {
5300 		ret = ath10k_wmi_alloc_chunk(ar, req_id, num_units, unit_len);
5301 		if (ret < 0)
5302 			return ret;
5303 
5304 		num_units -= ret;
5305 	}
5306 
5307 	return 0;
5308 }
5309 
5310 static bool
5311 ath10k_wmi_is_host_mem_allocated(struct ath10k *ar,
5312 				 const struct wlan_host_mem_req **mem_reqs,
5313 				 u32 num_mem_reqs)
5314 {
5315 	u32 req_id, num_units, unit_size, num_unit_info;
5316 	u32 pool_size;
5317 	int i, j;
5318 	bool found;
5319 
5320 	if (ar->wmi.num_mem_chunks != num_mem_reqs)
5321 		return false;
5322 
5323 	for (i = 0; i < num_mem_reqs; ++i) {
5324 		req_id = __le32_to_cpu(mem_reqs[i]->req_id);
5325 		num_units = __le32_to_cpu(mem_reqs[i]->num_units);
5326 		unit_size = __le32_to_cpu(mem_reqs[i]->unit_size);
5327 		num_unit_info = __le32_to_cpu(mem_reqs[i]->num_unit_info);
5328 
5329 		if (num_unit_info & NUM_UNITS_IS_NUM_ACTIVE_PEERS) {
5330 			if (ar->num_active_peers)
5331 				num_units = ar->num_active_peers + 1;
5332 			else
5333 				num_units = ar->max_num_peers + 1;
5334 		} else if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) {
5335 			num_units = ar->max_num_peers + 1;
5336 		} else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS) {
5337 			num_units = ar->max_num_vdevs + 1;
5338 		}
5339 
5340 		found = false;
5341 		for (j = 0; j < ar->wmi.num_mem_chunks; j++) {
5342 			if (ar->wmi.mem_chunks[j].req_id == req_id) {
5343 				pool_size = num_units * round_up(unit_size, 4);
5344 				if (ar->wmi.mem_chunks[j].len == pool_size) {
5345 					found = true;
5346 					break;
5347 				}
5348 			}
5349 		}
5350 		if (!found)
5351 			return false;
5352 	}
5353 
5354 	return true;
5355 }
5356 
5357 static int
5358 ath10k_wmi_main_op_pull_svc_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
5359 				   struct wmi_svc_rdy_ev_arg *arg)
5360 {
5361 	struct wmi_service_ready_event *ev;
5362 	size_t i, n;
5363 
5364 	if (skb->len < sizeof(*ev))
5365 		return -EPROTO;
5366 
5367 	ev = (void *)skb->data;
5368 	skb_pull(skb, sizeof(*ev));
5369 	arg->min_tx_power = ev->hw_min_tx_power;
5370 	arg->max_tx_power = ev->hw_max_tx_power;
5371 	arg->ht_cap = ev->ht_cap_info;
5372 	arg->vht_cap = ev->vht_cap_info;
5373 	arg->vht_supp_mcs = ev->vht_supp_mcs;
5374 	arg->sw_ver0 = ev->sw_version;
5375 	arg->sw_ver1 = ev->sw_version_1;
5376 	arg->phy_capab = ev->phy_capability;
5377 	arg->num_rf_chains = ev->num_rf_chains;
5378 	arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
5379 	arg->low_2ghz_chan = ev->hal_reg_capabilities.low_2ghz_chan;
5380 	arg->high_2ghz_chan = ev->hal_reg_capabilities.high_2ghz_chan;
5381 	arg->low_5ghz_chan = ev->hal_reg_capabilities.low_5ghz_chan;
5382 	arg->high_5ghz_chan = ev->hal_reg_capabilities.high_5ghz_chan;
5383 	arg->num_mem_reqs = ev->num_mem_reqs;
5384 	arg->service_map = ev->wmi_service_bitmap;
5385 	arg->service_map_len = sizeof(ev->wmi_service_bitmap);
5386 
5387 	n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
5388 		  ARRAY_SIZE(arg->mem_reqs));
5389 	for (i = 0; i < n; i++)
5390 		arg->mem_reqs[i] = &ev->mem_reqs[i];
5391 
5392 	if (skb->len <
5393 	    __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
5394 		return -EPROTO;
5395 
5396 	return 0;
5397 }
5398 
5399 static int
5400 ath10k_wmi_10x_op_pull_svc_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
5401 				  struct wmi_svc_rdy_ev_arg *arg)
5402 {
5403 	struct wmi_10x_service_ready_event *ev;
5404 	int i, n;
5405 
5406 	if (skb->len < sizeof(*ev))
5407 		return -EPROTO;
5408 
5409 	ev = (void *)skb->data;
5410 	skb_pull(skb, sizeof(*ev));
5411 	arg->min_tx_power = ev->hw_min_tx_power;
5412 	arg->max_tx_power = ev->hw_max_tx_power;
5413 	arg->ht_cap = ev->ht_cap_info;
5414 	arg->vht_cap = ev->vht_cap_info;
5415 	arg->vht_supp_mcs = ev->vht_supp_mcs;
5416 	arg->sw_ver0 = ev->sw_version;
5417 	arg->phy_capab = ev->phy_capability;
5418 	arg->num_rf_chains = ev->num_rf_chains;
5419 	arg->eeprom_rd = ev->hal_reg_capabilities.eeprom_rd;
5420 	arg->low_2ghz_chan = ev->hal_reg_capabilities.low_2ghz_chan;
5421 	arg->high_2ghz_chan = ev->hal_reg_capabilities.high_2ghz_chan;
5422 	arg->low_5ghz_chan = ev->hal_reg_capabilities.low_5ghz_chan;
5423 	arg->high_5ghz_chan = ev->hal_reg_capabilities.high_5ghz_chan;
5424 	arg->num_mem_reqs = ev->num_mem_reqs;
5425 	arg->service_map = ev->wmi_service_bitmap;
5426 	arg->service_map_len = sizeof(ev->wmi_service_bitmap);
5427 
5428 	/* Deliberately skipping ev->sys_cap_info as WMI and WMI-TLV have
5429 	 * different values. We would need a translation to handle that,
5430 	 * but as we don't currently need anything from sys_cap_info from
5431 	 * WMI interface (only from WMI-TLV) safest it to skip it.
5432 	 */
5433 
5434 	n = min_t(size_t, __le32_to_cpu(arg->num_mem_reqs),
5435 		  ARRAY_SIZE(arg->mem_reqs));
5436 	for (i = 0; i < n; i++)
5437 		arg->mem_reqs[i] = &ev->mem_reqs[i];
5438 
5439 	if (skb->len <
5440 	    __le32_to_cpu(arg->num_mem_reqs) * sizeof(arg->mem_reqs[0]))
5441 		return -EPROTO;
5442 
5443 	return 0;
5444 }
5445 
5446 static void ath10k_wmi_event_service_ready_work(struct work_struct *work)
5447 {
5448 	struct ath10k *ar = container_of(work, struct ath10k, svc_rdy_work);
5449 	struct sk_buff *skb = ar->svc_rdy_skb;
5450 	struct wmi_svc_rdy_ev_arg arg = {};
5451 	u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
5452 	int ret;
5453 	bool allocated;
5454 
5455 	if (!skb) {
5456 		ath10k_warn(ar, "invalid service ready event skb\n");
5457 		return;
5458 	}
5459 
5460 	ret = ath10k_wmi_pull_svc_rdy(ar, skb, &arg);
5461 	if (ret) {
5462 		ath10k_warn(ar, "failed to parse service ready: %d\n", ret);
5463 		return;
5464 	}
5465 
5466 	ath10k_wmi_map_svc(ar, arg.service_map, ar->wmi.svc_map,
5467 			   arg.service_map_len);
5468 
5469 	ar->hw_min_tx_power = __le32_to_cpu(arg.min_tx_power);
5470 	ar->hw_max_tx_power = __le32_to_cpu(arg.max_tx_power);
5471 	ar->ht_cap_info = __le32_to_cpu(arg.ht_cap);
5472 	ar->vht_cap_info = __le32_to_cpu(arg.vht_cap);
5473 	ar->vht_supp_mcs = __le32_to_cpu(arg.vht_supp_mcs);
5474 	ar->fw_version_major =
5475 		(__le32_to_cpu(arg.sw_ver0) & 0xff000000) >> 24;
5476 	ar->fw_version_minor = (__le32_to_cpu(arg.sw_ver0) & 0x00ffffff);
5477 	ar->fw_version_release =
5478 		(__le32_to_cpu(arg.sw_ver1) & 0xffff0000) >> 16;
5479 	ar->fw_version_build = (__le32_to_cpu(arg.sw_ver1) & 0x0000ffff);
5480 	ar->phy_capability = __le32_to_cpu(arg.phy_capab);
5481 	ar->num_rf_chains = __le32_to_cpu(arg.num_rf_chains);
5482 	ar->hw_eeprom_rd = __le32_to_cpu(arg.eeprom_rd);
5483 	ar->low_2ghz_chan = __le32_to_cpu(arg.low_2ghz_chan);
5484 	ar->high_2ghz_chan = __le32_to_cpu(arg.high_2ghz_chan);
5485 	ar->low_5ghz_chan = __le32_to_cpu(arg.low_5ghz_chan);
5486 	ar->high_5ghz_chan = __le32_to_cpu(arg.high_5ghz_chan);
5487 	ar->sys_cap_info = __le32_to_cpu(arg.sys_cap_info);
5488 
5489 	ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
5490 			arg.service_map, arg.service_map_len);
5491 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sys_cap_info 0x%x\n",
5492 		   ar->sys_cap_info);
5493 
5494 	if (ar->num_rf_chains > ar->max_spatial_stream) {
5495 		ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
5496 			    ar->num_rf_chains, ar->max_spatial_stream);
5497 		ar->num_rf_chains = ar->max_spatial_stream;
5498 	}
5499 
5500 	if (!ar->cfg_tx_chainmask) {
5501 		ar->cfg_tx_chainmask = (1 << ar->num_rf_chains) - 1;
5502 		ar->cfg_rx_chainmask = (1 << ar->num_rf_chains) - 1;
5503 	}
5504 
5505 	if (strlen(ar->hw->wiphy->fw_version) == 0) {
5506 		snprintf(ar->hw->wiphy->fw_version,
5507 			 sizeof(ar->hw->wiphy->fw_version),
5508 			 "%u.%u.%u.%u",
5509 			 ar->fw_version_major,
5510 			 ar->fw_version_minor,
5511 			 ar->fw_version_release,
5512 			 ar->fw_version_build);
5513 	}
5514 
5515 	num_mem_reqs = __le32_to_cpu(arg.num_mem_reqs);
5516 	if (num_mem_reqs > WMI_MAX_MEM_REQS) {
5517 		ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n",
5518 			    num_mem_reqs);
5519 		return;
5520 	}
5521 
5522 	if (test_bit(WMI_SERVICE_PEER_CACHING, ar->wmi.svc_map)) {
5523 		if (test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
5524 			     ar->running_fw->fw_file.fw_features))
5525 			ar->num_active_peers = TARGET_10_4_QCACHE_ACTIVE_PEERS_PFC +
5526 					       ar->max_num_vdevs;
5527 		else
5528 			ar->num_active_peers = TARGET_10_4_QCACHE_ACTIVE_PEERS +
5529 					       ar->max_num_vdevs;
5530 
5531 		ar->max_num_peers = TARGET_10_4_NUM_QCACHE_PEERS_MAX +
5532 				    ar->max_num_vdevs;
5533 		ar->num_tids = ar->num_active_peers * 2;
5534 		ar->max_num_stations = TARGET_10_4_NUM_QCACHE_PEERS_MAX;
5535 	}
5536 
5537 	/* TODO: Adjust max peer count for cases like WMI_SERVICE_RATECTRL_CACHE
5538 	 * and WMI_SERVICE_IRAM_TIDS, etc.
5539 	 */
5540 
5541 	allocated = ath10k_wmi_is_host_mem_allocated(ar, arg.mem_reqs,
5542 						     num_mem_reqs);
5543 	if (allocated)
5544 		goto skip_mem_alloc;
5545 
5546 	/* Either this event is received during boot time or there is a change
5547 	 * in memory requirement from firmware when compared to last request.
5548 	 * Free any old memory and do a fresh allocation based on the current
5549 	 * memory requirement.
5550 	 */
5551 	ath10k_wmi_free_host_mem(ar);
5552 
5553 	for (i = 0; i < num_mem_reqs; ++i) {
5554 		req_id = __le32_to_cpu(arg.mem_reqs[i]->req_id);
5555 		num_units = __le32_to_cpu(arg.mem_reqs[i]->num_units);
5556 		unit_size = __le32_to_cpu(arg.mem_reqs[i]->unit_size);
5557 		num_unit_info = __le32_to_cpu(arg.mem_reqs[i]->num_unit_info);
5558 
5559 		if (num_unit_info & NUM_UNITS_IS_NUM_ACTIVE_PEERS) {
5560 			if (ar->num_active_peers)
5561 				num_units = ar->num_active_peers + 1;
5562 			else
5563 				num_units = ar->max_num_peers + 1;
5564 		} else if (num_unit_info & NUM_UNITS_IS_NUM_PEERS) {
5565 			/* number of units to allocate is number of
5566 			 * peers, 1 extra for self peer on target
5567 			 * this needs to be tied, host and target
5568 			 * can get out of sync
5569 			 */
5570 			num_units = ar->max_num_peers + 1;
5571 		} else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS) {
5572 			num_units = ar->max_num_vdevs + 1;
5573 		}
5574 
5575 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5576 			   "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
5577 			   req_id,
5578 			   __le32_to_cpu(arg.mem_reqs[i]->num_units),
5579 			   num_unit_info,
5580 			   unit_size,
5581 			   num_units);
5582 
5583 		ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
5584 						unit_size);
5585 		if (ret)
5586 			return;
5587 	}
5588 
5589 skip_mem_alloc:
5590 	ath10k_dbg(ar, ATH10K_DBG_WMI,
5591 		   "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",
5592 		   __le32_to_cpu(arg.min_tx_power),
5593 		   __le32_to_cpu(arg.max_tx_power),
5594 		   __le32_to_cpu(arg.ht_cap),
5595 		   __le32_to_cpu(arg.vht_cap),
5596 		   __le32_to_cpu(arg.vht_supp_mcs),
5597 		   __le32_to_cpu(arg.sw_ver0),
5598 		   __le32_to_cpu(arg.sw_ver1),
5599 		   __le32_to_cpu(arg.fw_build),
5600 		   __le32_to_cpu(arg.phy_capab),
5601 		   __le32_to_cpu(arg.num_rf_chains),
5602 		   __le32_to_cpu(arg.eeprom_rd),
5603 		   __le32_to_cpu(arg.low_2ghz_chan),
5604 		   __le32_to_cpu(arg.high_2ghz_chan),
5605 		   __le32_to_cpu(arg.low_5ghz_chan),
5606 		   __le32_to_cpu(arg.high_5ghz_chan),
5607 		   __le32_to_cpu(arg.num_mem_reqs));
5608 
5609 	dev_kfree_skb(skb);
5610 	ar->svc_rdy_skb = NULL;
5611 	complete(&ar->wmi.service_ready);
5612 }
5613 
5614 void ath10k_wmi_event_service_ready(struct ath10k *ar, struct sk_buff *skb)
5615 {
5616 	ar->svc_rdy_skb = skb;
5617 	queue_work(ar->workqueue_aux, &ar->svc_rdy_work);
5618 }
5619 
5620 static int ath10k_wmi_op_pull_rdy_ev(struct ath10k *ar, struct sk_buff *skb,
5621 				     struct wmi_rdy_ev_arg *arg)
5622 {
5623 	struct wmi_ready_event *ev = (void *)skb->data;
5624 
5625 	if (skb->len < sizeof(*ev))
5626 		return -EPROTO;
5627 
5628 	skb_pull(skb, sizeof(*ev));
5629 	arg->sw_version = ev->sw_version;
5630 	arg->abi_version = ev->abi_version;
5631 	arg->status = ev->status;
5632 	arg->mac_addr = ev->mac_addr.addr;
5633 
5634 	return 0;
5635 }
5636 
5637 static int ath10k_wmi_op_pull_roam_ev(struct ath10k *ar, struct sk_buff *skb,
5638 				      struct wmi_roam_ev_arg *arg)
5639 {
5640 	struct wmi_roam_ev *ev = (void *)skb->data;
5641 
5642 	if (skb->len < sizeof(*ev))
5643 		return -EPROTO;
5644 
5645 	skb_pull(skb, sizeof(*ev));
5646 	arg->vdev_id = ev->vdev_id;
5647 	arg->reason = ev->reason;
5648 
5649 	return 0;
5650 }
5651 
5652 static int ath10k_wmi_op_pull_echo_ev(struct ath10k *ar,
5653 				      struct sk_buff *skb,
5654 				      struct wmi_echo_ev_arg *arg)
5655 {
5656 	struct wmi_echo_event *ev = (void *)skb->data;
5657 
5658 	arg->value = ev->value;
5659 
5660 	return 0;
5661 }
5662 
5663 int ath10k_wmi_event_ready(struct ath10k *ar, struct sk_buff *skb)
5664 {
5665 	struct wmi_rdy_ev_arg arg = {};
5666 	int ret;
5667 
5668 	ret = ath10k_wmi_pull_rdy(ar, skb, &arg);
5669 	if (ret) {
5670 		ath10k_warn(ar, "failed to parse ready event: %d\n", ret);
5671 		return ret;
5672 	}
5673 
5674 	ath10k_dbg(ar, ATH10K_DBG_WMI,
5675 		   "wmi event ready sw_version 0x%08x abi_version %u mac_addr %pM status %d\n",
5676 		   __le32_to_cpu(arg.sw_version),
5677 		   __le32_to_cpu(arg.abi_version),
5678 		   arg.mac_addr,
5679 		   __le32_to_cpu(arg.status));
5680 
5681 	if (is_zero_ether_addr(ar->mac_addr))
5682 		ether_addr_copy(ar->mac_addr, arg.mac_addr);
5683 	complete(&ar->wmi.unified_ready);
5684 	return 0;
5685 }
5686 
5687 void ath10k_wmi_event_service_available(struct ath10k *ar, struct sk_buff *skb)
5688 {
5689 	int ret;
5690 	struct wmi_svc_avail_ev_arg arg = {};
5691 
5692 	ret = ath10k_wmi_pull_svc_avail(ar, skb, &arg);
5693 	if (ret) {
5694 		ath10k_warn(ar, "failed to parse service available event: %d\n",
5695 			    ret);
5696 	}
5697 
5698 	ath10k_wmi_map_svc_ext(ar, arg.service_map_ext, ar->wmi.svc_map,
5699 			       __le32_to_cpu(arg.service_map_ext_len));
5700 }
5701 
5702 static int ath10k_wmi_event_temperature(struct ath10k *ar, struct sk_buff *skb)
5703 {
5704 	const struct wmi_pdev_temperature_event *ev;
5705 
5706 	ev = (struct wmi_pdev_temperature_event *)skb->data;
5707 	if (WARN_ON(skb->len < sizeof(*ev)))
5708 		return -EPROTO;
5709 
5710 	ath10k_thermal_event_temperature(ar, __le32_to_cpu(ev->temperature));
5711 	return 0;
5712 }
5713 
5714 static int ath10k_wmi_event_pdev_bss_chan_info(struct ath10k *ar,
5715 					       struct sk_buff *skb)
5716 {
5717 	struct wmi_pdev_bss_chan_info_event *ev;
5718 	struct survey_info *survey;
5719 	u64 busy, total, tx, rx, rx_bss;
5720 	u32 freq, noise_floor;
5721 	u32 cc_freq_hz = ar->hw_params.channel_counters_freq_hz;
5722 	int idx;
5723 
5724 	ev = (struct wmi_pdev_bss_chan_info_event *)skb->data;
5725 	if (WARN_ON(skb->len < sizeof(*ev)))
5726 		return -EPROTO;
5727 
5728 	freq        = __le32_to_cpu(ev->freq);
5729 	noise_floor = __le32_to_cpu(ev->noise_floor);
5730 	busy        = __le64_to_cpu(ev->cycle_busy);
5731 	total       = __le64_to_cpu(ev->cycle_total);
5732 	tx          = __le64_to_cpu(ev->cycle_tx);
5733 	rx          = __le64_to_cpu(ev->cycle_rx);
5734 	rx_bss      = __le64_to_cpu(ev->cycle_rx_bss);
5735 
5736 	ath10k_dbg(ar, ATH10K_DBG_WMI,
5737 		   "wmi event pdev bss chan info:\n freq: %d noise: %d cycle: busy %llu total %llu tx %llu rx %llu rx_bss %llu\n",
5738 		   freq, noise_floor, busy, total, tx, rx, rx_bss);
5739 
5740 	spin_lock_bh(&ar->data_lock);
5741 	idx = freq_to_idx(ar, freq);
5742 	if (idx >= ARRAY_SIZE(ar->survey)) {
5743 		ath10k_warn(ar, "bss chan info: invalid frequency %d (idx %d out of bounds)\n",
5744 			    freq, idx);
5745 		goto exit;
5746 	}
5747 
5748 	survey = &ar->survey[idx];
5749 
5750 	survey->noise     = noise_floor;
5751 	survey->time      = div_u64(total, cc_freq_hz);
5752 	survey->time_busy = div_u64(busy, cc_freq_hz);
5753 	survey->time_rx   = div_u64(rx_bss, cc_freq_hz);
5754 	survey->time_tx   = div_u64(tx, cc_freq_hz);
5755 	survey->filled   |= (SURVEY_INFO_NOISE_DBM |
5756 			     SURVEY_INFO_TIME |
5757 			     SURVEY_INFO_TIME_BUSY |
5758 			     SURVEY_INFO_TIME_RX |
5759 			     SURVEY_INFO_TIME_TX);
5760 exit:
5761 	spin_unlock_bh(&ar->data_lock);
5762 	complete(&ar->bss_survey_done);
5763 	return 0;
5764 }
5765 
5766 static inline void ath10k_wmi_queue_set_coverage_class_work(struct ath10k *ar)
5767 {
5768 	if (ar->hw_params.hw_ops->set_coverage_class) {
5769 		spin_lock_bh(&ar->data_lock);
5770 
5771 		/* This call only ensures that the modified coverage class
5772 		 * persists in case the firmware sets the registers back to
5773 		 * their default value. So calling it is only necessary if the
5774 		 * coverage class has a non-zero value.
5775 		 */
5776 		if (ar->fw_coverage.coverage_class)
5777 			queue_work(ar->workqueue, &ar->set_coverage_class_work);
5778 
5779 		spin_unlock_bh(&ar->data_lock);
5780 	}
5781 }
5782 
5783 static void ath10k_wmi_op_rx(struct ath10k *ar, struct sk_buff *skb)
5784 {
5785 	struct wmi_cmd_hdr *cmd_hdr;
5786 	enum wmi_event_id id;
5787 
5788 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5789 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5790 
5791 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5792 		goto out;
5793 
5794 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5795 
5796 	switch (id) {
5797 	case WMI_MGMT_RX_EVENTID:
5798 		ath10k_wmi_event_mgmt_rx(ar, skb);
5799 		/* mgmt_rx() owns the skb now! */
5800 		return;
5801 	case WMI_SCAN_EVENTID:
5802 		ath10k_wmi_event_scan(ar, skb);
5803 		ath10k_wmi_queue_set_coverage_class_work(ar);
5804 		break;
5805 	case WMI_CHAN_INFO_EVENTID:
5806 		ath10k_wmi_event_chan_info(ar, skb);
5807 		break;
5808 	case WMI_ECHO_EVENTID:
5809 		ath10k_wmi_event_echo(ar, skb);
5810 		break;
5811 	case WMI_DEBUG_MESG_EVENTID:
5812 		ath10k_wmi_event_debug_mesg(ar, skb);
5813 		ath10k_wmi_queue_set_coverage_class_work(ar);
5814 		break;
5815 	case WMI_UPDATE_STATS_EVENTID:
5816 		ath10k_wmi_event_update_stats(ar, skb);
5817 		break;
5818 	case WMI_VDEV_START_RESP_EVENTID:
5819 		ath10k_wmi_event_vdev_start_resp(ar, skb);
5820 		ath10k_wmi_queue_set_coverage_class_work(ar);
5821 		break;
5822 	case WMI_VDEV_STOPPED_EVENTID:
5823 		ath10k_wmi_event_vdev_stopped(ar, skb);
5824 		ath10k_wmi_queue_set_coverage_class_work(ar);
5825 		break;
5826 	case WMI_PEER_STA_KICKOUT_EVENTID:
5827 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
5828 		break;
5829 	case WMI_HOST_SWBA_EVENTID:
5830 		ath10k_wmi_event_host_swba(ar, skb);
5831 		break;
5832 	case WMI_TBTTOFFSET_UPDATE_EVENTID:
5833 		ath10k_wmi_event_tbttoffset_update(ar, skb);
5834 		break;
5835 	case WMI_PHYERR_EVENTID:
5836 		ath10k_wmi_event_phyerr(ar, skb);
5837 		break;
5838 	case WMI_ROAM_EVENTID:
5839 		ath10k_wmi_event_roam(ar, skb);
5840 		ath10k_wmi_queue_set_coverage_class_work(ar);
5841 		break;
5842 	case WMI_PROFILE_MATCH:
5843 		ath10k_wmi_event_profile_match(ar, skb);
5844 		break;
5845 	case WMI_DEBUG_PRINT_EVENTID:
5846 		ath10k_wmi_event_debug_print(ar, skb);
5847 		ath10k_wmi_queue_set_coverage_class_work(ar);
5848 		break;
5849 	case WMI_PDEV_QVIT_EVENTID:
5850 		ath10k_wmi_event_pdev_qvit(ar, skb);
5851 		break;
5852 	case WMI_WLAN_PROFILE_DATA_EVENTID:
5853 		ath10k_wmi_event_wlan_profile_data(ar, skb);
5854 		break;
5855 	case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
5856 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
5857 		break;
5858 	case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
5859 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
5860 		break;
5861 	case WMI_RTT_ERROR_REPORT_EVENTID:
5862 		ath10k_wmi_event_rtt_error_report(ar, skb);
5863 		break;
5864 	case WMI_WOW_WAKEUP_HOST_EVENTID:
5865 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
5866 		break;
5867 	case WMI_DCS_INTERFERENCE_EVENTID:
5868 		ath10k_wmi_event_dcs_interference(ar, skb);
5869 		break;
5870 	case WMI_PDEV_TPC_CONFIG_EVENTID:
5871 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
5872 		break;
5873 	case WMI_PDEV_FTM_INTG_EVENTID:
5874 		ath10k_wmi_event_pdev_ftm_intg(ar, skb);
5875 		break;
5876 	case WMI_GTK_OFFLOAD_STATUS_EVENTID:
5877 		ath10k_wmi_event_gtk_offload_status(ar, skb);
5878 		break;
5879 	case WMI_GTK_REKEY_FAIL_EVENTID:
5880 		ath10k_wmi_event_gtk_rekey_fail(ar, skb);
5881 		break;
5882 	case WMI_TX_DELBA_COMPLETE_EVENTID:
5883 		ath10k_wmi_event_delba_complete(ar, skb);
5884 		break;
5885 	case WMI_TX_ADDBA_COMPLETE_EVENTID:
5886 		ath10k_wmi_event_addba_complete(ar, skb);
5887 		break;
5888 	case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
5889 		ath10k_wmi_event_vdev_install_key_complete(ar, skb);
5890 		break;
5891 	case WMI_SERVICE_READY_EVENTID:
5892 		ath10k_wmi_event_service_ready(ar, skb);
5893 		return;
5894 	case WMI_READY_EVENTID:
5895 		ath10k_wmi_event_ready(ar, skb);
5896 		ath10k_wmi_queue_set_coverage_class_work(ar);
5897 		break;
5898 	case WMI_SERVICE_AVAILABLE_EVENTID:
5899 		ath10k_wmi_event_service_available(ar, skb);
5900 		break;
5901 	default:
5902 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
5903 		break;
5904 	}
5905 
5906 out:
5907 	dev_kfree_skb(skb);
5908 }
5909 
5910 static void ath10k_wmi_10_1_op_rx(struct ath10k *ar, struct sk_buff *skb)
5911 {
5912 	struct wmi_cmd_hdr *cmd_hdr;
5913 	enum wmi_10x_event_id id;
5914 	bool consumed;
5915 
5916 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
5917 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
5918 
5919 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
5920 		goto out;
5921 
5922 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
5923 
5924 	consumed = ath10k_tm_event_wmi(ar, id, skb);
5925 
5926 	/* Ready event must be handled normally also in UTF mode so that we
5927 	 * know the UTF firmware has booted, others we are just bypass WMI
5928 	 * events to testmode.
5929 	 */
5930 	if (consumed && id != WMI_10X_READY_EVENTID) {
5931 		ath10k_dbg(ar, ATH10K_DBG_WMI,
5932 			   "wmi testmode consumed 0x%x\n", id);
5933 		goto out;
5934 	}
5935 
5936 	switch (id) {
5937 	case WMI_10X_MGMT_RX_EVENTID:
5938 		ath10k_wmi_event_mgmt_rx(ar, skb);
5939 		/* mgmt_rx() owns the skb now! */
5940 		return;
5941 	case WMI_10X_SCAN_EVENTID:
5942 		ath10k_wmi_event_scan(ar, skb);
5943 		ath10k_wmi_queue_set_coverage_class_work(ar);
5944 		break;
5945 	case WMI_10X_CHAN_INFO_EVENTID:
5946 		ath10k_wmi_event_chan_info(ar, skb);
5947 		break;
5948 	case WMI_10X_ECHO_EVENTID:
5949 		ath10k_wmi_event_echo(ar, skb);
5950 		break;
5951 	case WMI_10X_DEBUG_MESG_EVENTID:
5952 		ath10k_wmi_event_debug_mesg(ar, skb);
5953 		ath10k_wmi_queue_set_coverage_class_work(ar);
5954 		break;
5955 	case WMI_10X_UPDATE_STATS_EVENTID:
5956 		ath10k_wmi_event_update_stats(ar, skb);
5957 		break;
5958 	case WMI_10X_VDEV_START_RESP_EVENTID:
5959 		ath10k_wmi_event_vdev_start_resp(ar, skb);
5960 		ath10k_wmi_queue_set_coverage_class_work(ar);
5961 		break;
5962 	case WMI_10X_VDEV_STOPPED_EVENTID:
5963 		ath10k_wmi_event_vdev_stopped(ar, skb);
5964 		ath10k_wmi_queue_set_coverage_class_work(ar);
5965 		break;
5966 	case WMI_10X_PEER_STA_KICKOUT_EVENTID:
5967 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
5968 		break;
5969 	case WMI_10X_HOST_SWBA_EVENTID:
5970 		ath10k_wmi_event_host_swba(ar, skb);
5971 		break;
5972 	case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
5973 		ath10k_wmi_event_tbttoffset_update(ar, skb);
5974 		break;
5975 	case WMI_10X_PHYERR_EVENTID:
5976 		ath10k_wmi_event_phyerr(ar, skb);
5977 		break;
5978 	case WMI_10X_ROAM_EVENTID:
5979 		ath10k_wmi_event_roam(ar, skb);
5980 		ath10k_wmi_queue_set_coverage_class_work(ar);
5981 		break;
5982 	case WMI_10X_PROFILE_MATCH:
5983 		ath10k_wmi_event_profile_match(ar, skb);
5984 		break;
5985 	case WMI_10X_DEBUG_PRINT_EVENTID:
5986 		ath10k_wmi_event_debug_print(ar, skb);
5987 		ath10k_wmi_queue_set_coverage_class_work(ar);
5988 		break;
5989 	case WMI_10X_PDEV_QVIT_EVENTID:
5990 		ath10k_wmi_event_pdev_qvit(ar, skb);
5991 		break;
5992 	case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
5993 		ath10k_wmi_event_wlan_profile_data(ar, skb);
5994 		break;
5995 	case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
5996 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
5997 		break;
5998 	case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
5999 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
6000 		break;
6001 	case WMI_10X_RTT_ERROR_REPORT_EVENTID:
6002 		ath10k_wmi_event_rtt_error_report(ar, skb);
6003 		break;
6004 	case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
6005 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
6006 		break;
6007 	case WMI_10X_DCS_INTERFERENCE_EVENTID:
6008 		ath10k_wmi_event_dcs_interference(ar, skb);
6009 		break;
6010 	case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
6011 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
6012 		break;
6013 	case WMI_10X_INST_RSSI_STATS_EVENTID:
6014 		ath10k_wmi_event_inst_rssi_stats(ar, skb);
6015 		break;
6016 	case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
6017 		ath10k_wmi_event_vdev_standby_req(ar, skb);
6018 		break;
6019 	case WMI_10X_VDEV_RESUME_REQ_EVENTID:
6020 		ath10k_wmi_event_vdev_resume_req(ar, skb);
6021 		break;
6022 	case WMI_10X_SERVICE_READY_EVENTID:
6023 		ath10k_wmi_event_service_ready(ar, skb);
6024 		return;
6025 	case WMI_10X_READY_EVENTID:
6026 		ath10k_wmi_event_ready(ar, skb);
6027 		ath10k_wmi_queue_set_coverage_class_work(ar);
6028 		break;
6029 	case WMI_10X_PDEV_UTF_EVENTID:
6030 		/* ignore utf events */
6031 		break;
6032 	default:
6033 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
6034 		break;
6035 	}
6036 
6037 out:
6038 	dev_kfree_skb(skb);
6039 }
6040 
6041 static void ath10k_wmi_10_2_op_rx(struct ath10k *ar, struct sk_buff *skb)
6042 {
6043 	struct wmi_cmd_hdr *cmd_hdr;
6044 	enum wmi_10_2_event_id id;
6045 	bool consumed;
6046 
6047 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
6048 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
6049 
6050 	if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
6051 		goto out;
6052 
6053 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
6054 
6055 	consumed = ath10k_tm_event_wmi(ar, id, skb);
6056 
6057 	/* Ready event must be handled normally also in UTF mode so that we
6058 	 * know the UTF firmware has booted, others we are just bypass WMI
6059 	 * events to testmode.
6060 	 */
6061 	if (consumed && id != WMI_10_2_READY_EVENTID) {
6062 		ath10k_dbg(ar, ATH10K_DBG_WMI,
6063 			   "wmi testmode consumed 0x%x\n", id);
6064 		goto out;
6065 	}
6066 
6067 	switch (id) {
6068 	case WMI_10_2_MGMT_RX_EVENTID:
6069 		ath10k_wmi_event_mgmt_rx(ar, skb);
6070 		/* mgmt_rx() owns the skb now! */
6071 		return;
6072 	case WMI_10_2_SCAN_EVENTID:
6073 		ath10k_wmi_event_scan(ar, skb);
6074 		ath10k_wmi_queue_set_coverage_class_work(ar);
6075 		break;
6076 	case WMI_10_2_CHAN_INFO_EVENTID:
6077 		ath10k_wmi_event_chan_info(ar, skb);
6078 		break;
6079 	case WMI_10_2_ECHO_EVENTID:
6080 		ath10k_wmi_event_echo(ar, skb);
6081 		break;
6082 	case WMI_10_2_DEBUG_MESG_EVENTID:
6083 		ath10k_wmi_event_debug_mesg(ar, skb);
6084 		ath10k_wmi_queue_set_coverage_class_work(ar);
6085 		break;
6086 	case WMI_10_2_UPDATE_STATS_EVENTID:
6087 		ath10k_wmi_event_update_stats(ar, skb);
6088 		break;
6089 	case WMI_10_2_VDEV_START_RESP_EVENTID:
6090 		ath10k_wmi_event_vdev_start_resp(ar, skb);
6091 		ath10k_wmi_queue_set_coverage_class_work(ar);
6092 		break;
6093 	case WMI_10_2_VDEV_STOPPED_EVENTID:
6094 		ath10k_wmi_event_vdev_stopped(ar, skb);
6095 		ath10k_wmi_queue_set_coverage_class_work(ar);
6096 		break;
6097 	case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
6098 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
6099 		break;
6100 	case WMI_10_2_HOST_SWBA_EVENTID:
6101 		ath10k_wmi_event_host_swba(ar, skb);
6102 		break;
6103 	case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
6104 		ath10k_wmi_event_tbttoffset_update(ar, skb);
6105 		break;
6106 	case WMI_10_2_PHYERR_EVENTID:
6107 		ath10k_wmi_event_phyerr(ar, skb);
6108 		break;
6109 	case WMI_10_2_ROAM_EVENTID:
6110 		ath10k_wmi_event_roam(ar, skb);
6111 		ath10k_wmi_queue_set_coverage_class_work(ar);
6112 		break;
6113 	case WMI_10_2_PROFILE_MATCH:
6114 		ath10k_wmi_event_profile_match(ar, skb);
6115 		break;
6116 	case WMI_10_2_DEBUG_PRINT_EVENTID:
6117 		ath10k_wmi_event_debug_print(ar, skb);
6118 		ath10k_wmi_queue_set_coverage_class_work(ar);
6119 		break;
6120 	case WMI_10_2_PDEV_QVIT_EVENTID:
6121 		ath10k_wmi_event_pdev_qvit(ar, skb);
6122 		break;
6123 	case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
6124 		ath10k_wmi_event_wlan_profile_data(ar, skb);
6125 		break;
6126 	case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
6127 		ath10k_wmi_event_rtt_measurement_report(ar, skb);
6128 		break;
6129 	case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
6130 		ath10k_wmi_event_tsf_measurement_report(ar, skb);
6131 		break;
6132 	case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
6133 		ath10k_wmi_event_rtt_error_report(ar, skb);
6134 		break;
6135 	case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
6136 		ath10k_wmi_event_wow_wakeup_host(ar, skb);
6137 		break;
6138 	case WMI_10_2_DCS_INTERFERENCE_EVENTID:
6139 		ath10k_wmi_event_dcs_interference(ar, skb);
6140 		break;
6141 	case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
6142 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
6143 		break;
6144 	case WMI_10_2_INST_RSSI_STATS_EVENTID:
6145 		ath10k_wmi_event_inst_rssi_stats(ar, skb);
6146 		break;
6147 	case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
6148 		ath10k_wmi_event_vdev_standby_req(ar, skb);
6149 		ath10k_wmi_queue_set_coverage_class_work(ar);
6150 		break;
6151 	case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
6152 		ath10k_wmi_event_vdev_resume_req(ar, skb);
6153 		ath10k_wmi_queue_set_coverage_class_work(ar);
6154 		break;
6155 	case WMI_10_2_SERVICE_READY_EVENTID:
6156 		ath10k_wmi_event_service_ready(ar, skb);
6157 		return;
6158 	case WMI_10_2_READY_EVENTID:
6159 		ath10k_wmi_event_ready(ar, skb);
6160 		ath10k_wmi_queue_set_coverage_class_work(ar);
6161 		break;
6162 	case WMI_10_2_PDEV_TEMPERATURE_EVENTID:
6163 		ath10k_wmi_event_temperature(ar, skb);
6164 		break;
6165 	case WMI_10_2_PDEV_BSS_CHAN_INFO_EVENTID:
6166 		ath10k_wmi_event_pdev_bss_chan_info(ar, skb);
6167 		break;
6168 	case WMI_10_2_RTT_KEEPALIVE_EVENTID:
6169 	case WMI_10_2_GPIO_INPUT_EVENTID:
6170 	case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
6171 	case WMI_10_2_GENERIC_BUFFER_EVENTID:
6172 	case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
6173 	case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
6174 	case WMI_10_2_WDS_PEER_EVENTID:
6175 		ath10k_dbg(ar, ATH10K_DBG_WMI,
6176 			   "received event id %d not implemented\n", id);
6177 		break;
6178 	case WMI_10_2_PEER_STA_PS_STATECHG_EVENTID:
6179 		ath10k_wmi_event_peer_sta_ps_state_chg(ar, skb);
6180 		break;
6181 	default:
6182 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
6183 		break;
6184 	}
6185 
6186 out:
6187 	dev_kfree_skb(skb);
6188 }
6189 
6190 static void ath10k_wmi_10_4_op_rx(struct ath10k *ar, struct sk_buff *skb)
6191 {
6192 	struct wmi_cmd_hdr *cmd_hdr;
6193 	enum wmi_10_4_event_id id;
6194 	bool consumed;
6195 
6196 	cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
6197 	id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
6198 
6199 	if (!skb_pull(skb, sizeof(struct wmi_cmd_hdr)))
6200 		goto out;
6201 
6202 	trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
6203 
6204 	consumed = ath10k_tm_event_wmi(ar, id, skb);
6205 
6206 	/* Ready event must be handled normally also in UTF mode so that we
6207 	 * know the UTF firmware has booted, others we are just bypass WMI
6208 	 * events to testmode.
6209 	 */
6210 	if (consumed && id != WMI_10_4_READY_EVENTID) {
6211 		ath10k_dbg(ar, ATH10K_DBG_WMI,
6212 			   "wmi testmode consumed 0x%x\n", id);
6213 		goto out;
6214 	}
6215 
6216 	switch (id) {
6217 	case WMI_10_4_MGMT_RX_EVENTID:
6218 		ath10k_wmi_event_mgmt_rx(ar, skb);
6219 		/* mgmt_rx() owns the skb now! */
6220 		return;
6221 	case WMI_10_4_ECHO_EVENTID:
6222 		ath10k_wmi_event_echo(ar, skb);
6223 		break;
6224 	case WMI_10_4_DEBUG_MESG_EVENTID:
6225 		ath10k_wmi_event_debug_mesg(ar, skb);
6226 		ath10k_wmi_queue_set_coverage_class_work(ar);
6227 		break;
6228 	case WMI_10_4_SERVICE_READY_EVENTID:
6229 		ath10k_wmi_event_service_ready(ar, skb);
6230 		return;
6231 	case WMI_10_4_SCAN_EVENTID:
6232 		ath10k_wmi_event_scan(ar, skb);
6233 		ath10k_wmi_queue_set_coverage_class_work(ar);
6234 		break;
6235 	case WMI_10_4_CHAN_INFO_EVENTID:
6236 		ath10k_wmi_event_chan_info(ar, skb);
6237 		break;
6238 	case WMI_10_4_PHYERR_EVENTID:
6239 		ath10k_wmi_event_phyerr(ar, skb);
6240 		break;
6241 	case WMI_10_4_READY_EVENTID:
6242 		ath10k_wmi_event_ready(ar, skb);
6243 		ath10k_wmi_queue_set_coverage_class_work(ar);
6244 		break;
6245 	case WMI_10_4_PEER_STA_KICKOUT_EVENTID:
6246 		ath10k_wmi_event_peer_sta_kickout(ar, skb);
6247 		break;
6248 	case WMI_10_4_ROAM_EVENTID:
6249 		ath10k_wmi_event_roam(ar, skb);
6250 		ath10k_wmi_queue_set_coverage_class_work(ar);
6251 		break;
6252 	case WMI_10_4_HOST_SWBA_EVENTID:
6253 		ath10k_wmi_event_host_swba(ar, skb);
6254 		break;
6255 	case WMI_10_4_TBTTOFFSET_UPDATE_EVENTID:
6256 		ath10k_wmi_event_tbttoffset_update(ar, skb);
6257 		break;
6258 	case WMI_10_4_DEBUG_PRINT_EVENTID:
6259 		ath10k_wmi_event_debug_print(ar, skb);
6260 		ath10k_wmi_queue_set_coverage_class_work(ar);
6261 		break;
6262 	case WMI_10_4_VDEV_START_RESP_EVENTID:
6263 		ath10k_wmi_event_vdev_start_resp(ar, skb);
6264 		ath10k_wmi_queue_set_coverage_class_work(ar);
6265 		break;
6266 	case WMI_10_4_VDEV_STOPPED_EVENTID:
6267 		ath10k_wmi_event_vdev_stopped(ar, skb);
6268 		ath10k_wmi_queue_set_coverage_class_work(ar);
6269 		break;
6270 	case WMI_10_4_WOW_WAKEUP_HOST_EVENTID:
6271 	case WMI_10_4_PEER_RATECODE_LIST_EVENTID:
6272 	case WMI_10_4_WDS_PEER_EVENTID:
6273 	case WMI_10_4_DEBUG_FATAL_CONDITION_EVENTID:
6274 		ath10k_dbg(ar, ATH10K_DBG_WMI,
6275 			   "received event id %d not implemented\n", id);
6276 		break;
6277 	case WMI_10_4_UPDATE_STATS_EVENTID:
6278 		ath10k_wmi_event_update_stats(ar, skb);
6279 		break;
6280 	case WMI_10_4_PDEV_TEMPERATURE_EVENTID:
6281 		ath10k_wmi_event_temperature(ar, skb);
6282 		break;
6283 	case WMI_10_4_PDEV_BSS_CHAN_INFO_EVENTID:
6284 		ath10k_wmi_event_pdev_bss_chan_info(ar, skb);
6285 		break;
6286 	case WMI_10_4_PDEV_TPC_CONFIG_EVENTID:
6287 		ath10k_wmi_event_pdev_tpc_config(ar, skb);
6288 		break;
6289 	case WMI_10_4_TDLS_PEER_EVENTID:
6290 		ath10k_wmi_handle_tdls_peer_event(ar, skb);
6291 		break;
6292 	case WMI_10_4_PDEV_TPC_TABLE_EVENTID:
6293 		ath10k_wmi_event_tpc_final_table(ar, skb);
6294 		break;
6295 	case WMI_10_4_DFS_STATUS_CHECK_EVENTID:
6296 		ath10k_wmi_event_dfs_status_check(ar, skb);
6297 		break;
6298 	case WMI_10_4_PEER_STA_PS_STATECHG_EVENTID:
6299 		ath10k_wmi_event_peer_sta_ps_state_chg(ar, skb);
6300 		break;
6301 	default:
6302 		ath10k_warn(ar, "Unknown eventid: %d\n", id);
6303 		break;
6304 	}
6305 
6306 out:
6307 	dev_kfree_skb(skb);
6308 }
6309 
6310 static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
6311 {
6312 	int ret;
6313 
6314 	ret = ath10k_wmi_rx(ar, skb);
6315 	if (ret)
6316 		ath10k_warn(ar, "failed to process wmi rx: %d\n", ret);
6317 }
6318 
6319 int ath10k_wmi_connect(struct ath10k *ar)
6320 {
6321 	int status;
6322 	struct ath10k_htc_svc_conn_req conn_req;
6323 	struct ath10k_htc_svc_conn_resp conn_resp;
6324 
6325 	memset(&ar->wmi.svc_map, 0, sizeof(ar->wmi.svc_map));
6326 
6327 	memset(&conn_req, 0, sizeof(conn_req));
6328 	memset(&conn_resp, 0, sizeof(conn_resp));
6329 
6330 	/* these fields are the same for all service endpoints */
6331 	conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
6332 	conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
6333 	conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
6334 
6335 	/* connect to control service */
6336 	conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
6337 
6338 	status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
6339 	if (status) {
6340 		ath10k_warn(ar, "failed to connect to WMI CONTROL service status: %d\n",
6341 			    status);
6342 		return status;
6343 	}
6344 
6345 	ar->wmi.eid = conn_resp.eid;
6346 	return 0;
6347 }
6348 
6349 static struct sk_buff *
6350 ath10k_wmi_op_gen_pdev_set_base_macaddr(struct ath10k *ar,
6351 					const u8 macaddr[ETH_ALEN])
6352 {
6353 	struct wmi_pdev_set_base_macaddr_cmd *cmd;
6354 	struct sk_buff *skb;
6355 
6356 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6357 	if (!skb)
6358 		return ERR_PTR(-ENOMEM);
6359 
6360 	cmd = (struct wmi_pdev_set_base_macaddr_cmd *)skb->data;
6361 	ether_addr_copy(cmd->mac_addr.addr, macaddr);
6362 
6363 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6364 		   "wmi pdev basemac %pM\n", macaddr);
6365 	return skb;
6366 }
6367 
6368 static struct sk_buff *
6369 ath10k_wmi_op_gen_pdev_set_rd(struct ath10k *ar, u16 rd, u16 rd2g, u16 rd5g,
6370 			      u16 ctl2g, u16 ctl5g,
6371 			      enum wmi_dfs_region dfs_reg)
6372 {
6373 	struct wmi_pdev_set_regdomain_cmd *cmd;
6374 	struct sk_buff *skb;
6375 
6376 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6377 	if (!skb)
6378 		return ERR_PTR(-ENOMEM);
6379 
6380 	cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
6381 	cmd->reg_domain = __cpu_to_le32(rd);
6382 	cmd->reg_domain_2G = __cpu_to_le32(rd2g);
6383 	cmd->reg_domain_5G = __cpu_to_le32(rd5g);
6384 	cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
6385 	cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
6386 
6387 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6388 		   "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
6389 		   rd, rd2g, rd5g, ctl2g, ctl5g);
6390 	return skb;
6391 }
6392 
6393 static struct sk_buff *
6394 ath10k_wmi_10x_op_gen_pdev_set_rd(struct ath10k *ar, u16 rd, u16 rd2g, u16
6395 				  rd5g, u16 ctl2g, u16 ctl5g,
6396 				  enum wmi_dfs_region dfs_reg)
6397 {
6398 	struct wmi_pdev_set_regdomain_cmd_10x *cmd;
6399 	struct sk_buff *skb;
6400 
6401 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6402 	if (!skb)
6403 		return ERR_PTR(-ENOMEM);
6404 
6405 	cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
6406 	cmd->reg_domain = __cpu_to_le32(rd);
6407 	cmd->reg_domain_2G = __cpu_to_le32(rd2g);
6408 	cmd->reg_domain_5G = __cpu_to_le32(rd5g);
6409 	cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
6410 	cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
6411 	cmd->dfs_domain = __cpu_to_le32(dfs_reg);
6412 
6413 	ath10k_dbg(ar, ATH10K_DBG_WMI,
6414 		   "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
6415 		   rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
6416 	return skb;
6417 }
6418 
6419 static struct sk_buff *
6420 ath10k_wmi_op_gen_pdev_suspend(struct ath10k *ar, u32 suspend_opt)
6421 {
6422 	struct wmi_pdev_suspend_cmd *cmd;
6423 	struct sk_buff *skb;
6424 
6425 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6426 	if (!skb)
6427 		return ERR_PTR(-ENOMEM);
6428 
6429 	cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
6430 	cmd->suspend_opt = __cpu_to_le32(suspend_opt);
6431 
6432 	return skb;
6433 }
6434 
6435 static struct sk_buff *
6436 ath10k_wmi_op_gen_pdev_resume(struct ath10k *ar)
6437 {
6438 	struct sk_buff *skb;
6439 
6440 	skb = ath10k_wmi_alloc_skb(ar, 0);
6441 	if (!skb)
6442 		return ERR_PTR(-ENOMEM);
6443 
6444 	return skb;
6445 }
6446 
6447 static struct sk_buff *
6448 ath10k_wmi_op_gen_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
6449 {
6450 	struct wmi_pdev_set_param_cmd *cmd;
6451 	struct sk_buff *skb;
6452 
6453 	if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
6454 		ath10k_warn(ar, "pdev param %d not supported by firmware\n",
6455 			    id);
6456 		return ERR_PTR(-EOPNOTSUPP);
6457 	}
6458 
6459 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
6460 	if (!skb)
6461 		return ERR_PTR(-ENOMEM);
6462 
6463 	cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
6464 	cmd->param_id    = __cpu_to_le32(id);
6465 	cmd->param_value = __cpu_to_le32(value);
6466 
6467 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
6468 		   id, value);
6469 	return skb;
6470 }
6471 
6472 void ath10k_wmi_put_host_mem_chunks(struct ath10k *ar,
6473 				    struct wmi_host_mem_chunks *chunks)
6474 {
6475 	struct host_memory_chunk *chunk;
6476 	int i;
6477 
6478 	chunks->count = __cpu_to_le32(ar->wmi.num_mem_chunks);
6479 
6480 	for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
6481 		chunk = &chunks->items[i];
6482 		chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
6483 		chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
6484 		chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
6485 
6486 		ath10k_dbg(ar, ATH10K_DBG_WMI,
6487 			   "wmi chunk %d len %d requested, addr 0x%llx\n",
6488 			   i,
6489 			   ar->wmi.mem_chunks[i].len,
6490 			   (unsigned long long)ar->wmi.mem_chunks[i].paddr);
6491 	}
6492 }
6493 
6494 static struct sk_buff *ath10k_wmi_op_gen_init(struct ath10k *ar)
6495 {
6496 	struct wmi_init_cmd *cmd;
6497 	struct sk_buff *buf;
6498 	struct wmi_resource_config config = {};
6499 	u32 len, val;
6500 
6501 	config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
6502 	config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS);
6503 	config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
6504 
6505 	config.num_offload_reorder_bufs =
6506 		__cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
6507 
6508 	config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
6509 	config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
6510 	config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
6511 	config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
6512 	config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
6513 	config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
6514 	config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
6515 	config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
6516 	config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
6517 	config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
6518 	config.scan_max_pending_reqs =
6519 		__cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
6520 
6521 	config.bmiss_offload_max_vdev =
6522 		__cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
6523 
6524 	config.roam_offload_max_vdev =
6525 		__cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
6526 
6527 	config.roam_offload_max_ap_profiles =
6528 		__cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
6529 
6530 	config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
6531 	config.num_mcast_table_elems =
6532 		__cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
6533 
6534 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
6535 	config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
6536 	config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
6537 	config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
6538 	config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
6539 
6540 	val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
6541 	config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
6542 
6543 	config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
6544 
6545 	config.gtk_offload_max_vdev =
6546 		__cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
6547 
6548 	config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
6549 	config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
6550 
6551 	len = sizeof(*cmd) +
6552 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
6553 
6554 	buf = ath10k_wmi_alloc_skb(ar, len);
6555 	if (!buf)
6556 		return ERR_PTR(-ENOMEM);
6557 
6558 	cmd = (struct wmi_init_cmd *)buf->data;
6559 
6560 	memcpy(&cmd->resource_config, &config, sizeof(config));
6561 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
6562 
6563 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n");
6564 	return buf;
6565 }
6566 
6567 static struct sk_buff *ath10k_wmi_10_1_op_gen_init(struct ath10k *ar)
6568 {
6569 	struct wmi_init_cmd_10x *cmd;
6570 	struct sk_buff *buf;
6571 	struct wmi_resource_config_10x config = {};
6572 	u32 len, val;
6573 
6574 	config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
6575 	config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
6576 	config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
6577 	config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
6578 	config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
6579 	config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
6580 	config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
6581 	config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
6582 	config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
6583 	config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
6584 	config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
6585 	config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
6586 	config.scan_max_pending_reqs =
6587 		__cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
6588 
6589 	config.bmiss_offload_max_vdev =
6590 		__cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
6591 
6592 	config.roam_offload_max_vdev =
6593 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
6594 
6595 	config.roam_offload_max_ap_profiles =
6596 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
6597 
6598 	config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
6599 	config.num_mcast_table_elems =
6600 		__cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
6601 
6602 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
6603 	config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
6604 	config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
6605 	config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
6606 	config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
6607 
6608 	val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
6609 	config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
6610 
6611 	config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
6612 
6613 	config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
6614 	config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
6615 
6616 	len = sizeof(*cmd) +
6617 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
6618 
6619 	buf = ath10k_wmi_alloc_skb(ar, len);
6620 	if (!buf)
6621 		return ERR_PTR(-ENOMEM);
6622 
6623 	cmd = (struct wmi_init_cmd_10x *)buf->data;
6624 
6625 	memcpy(&cmd->resource_config, &config, sizeof(config));
6626 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
6627 
6628 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n");
6629 	return buf;
6630 }
6631 
6632 static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar)
6633 {
6634 	struct wmi_init_cmd_10_2 *cmd;
6635 	struct sk_buff *buf;
6636 	struct wmi_resource_config_10x config = {};
6637 	u32 len, val, features;
6638 
6639 	config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
6640 	config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
6641 
6642 	if (ath10k_peer_stats_enabled(ar)) {
6643 		config.num_peers = __cpu_to_le32(TARGET_10X_TX_STATS_NUM_PEERS);
6644 		config.num_tids = __cpu_to_le32(TARGET_10X_TX_STATS_NUM_TIDS);
6645 	} else {
6646 		config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
6647 		config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
6648 	}
6649 
6650 	config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
6651 	config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
6652 	config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
6653 	config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
6654 	config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
6655 	config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
6656 	config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
6657 	config.rx_decap_mode = __cpu_to_le32(ar->wmi.rx_decap_mode);
6658 
6659 	config.scan_max_pending_reqs =
6660 		__cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
6661 
6662 	config.bmiss_offload_max_vdev =
6663 		__cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
6664 
6665 	config.roam_offload_max_vdev =
6666 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
6667 
6668 	config.roam_offload_max_ap_profiles =
6669 		__cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
6670 
6671 	config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
6672 	config.num_mcast_table_elems =
6673 		__cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
6674 
6675 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
6676 	config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
6677 	config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
6678 	config.dma_burst_size = __cpu_to_le32(TARGET_10_2_DMA_BURST_SIZE);
6679 	config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
6680 
6681 	val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
6682 	config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
6683 
6684 	config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
6685 
6686 	config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
6687 	config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
6688 
6689 	len = sizeof(*cmd) +
6690 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
6691 
6692 	buf = ath10k_wmi_alloc_skb(ar, len);
6693 	if (!buf)
6694 		return ERR_PTR(-ENOMEM);
6695 
6696 	cmd = (struct wmi_init_cmd_10_2 *)buf->data;
6697 
6698 	features = WMI_10_2_RX_BATCH_MODE;
6699 
6700 	if (test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) &&
6701 	    test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
6702 		features |= WMI_10_2_COEX_GPIO;
6703 
6704 	if (ath10k_peer_stats_enabled(ar))
6705 		features |= WMI_10_2_PEER_STATS;
6706 
6707 	if (test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map))
6708 		features |= WMI_10_2_BSS_CHAN_INFO;
6709 
6710 	cmd->resource_config.feature_mask = __cpu_to_le32(features);
6711 
6712 	memcpy(&cmd->resource_config.common, &config, sizeof(config));
6713 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
6714 
6715 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n");
6716 	return buf;
6717 }
6718 
6719 static struct sk_buff *ath10k_wmi_10_4_op_gen_init(struct ath10k *ar)
6720 {
6721 	struct wmi_init_cmd_10_4 *cmd;
6722 	struct sk_buff *buf;
6723 	struct wmi_resource_config_10_4 config = {};
6724 	u32 len;
6725 
6726 	config.num_vdevs = __cpu_to_le32(ar->max_num_vdevs);
6727 	config.num_peers = __cpu_to_le32(ar->max_num_peers);
6728 	config.num_active_peers = __cpu_to_le32(ar->num_active_peers);
6729 	config.num_tids = __cpu_to_le32(ar->num_tids);
6730 
6731 	config.num_offload_peers = __cpu_to_le32(TARGET_10_4_NUM_OFFLOAD_PEERS);
6732 	config.num_offload_reorder_buffs =
6733 			__cpu_to_le32(TARGET_10_4_NUM_OFFLOAD_REORDER_BUFFS);
6734 	config.num_peer_keys  = __cpu_to_le32(TARGET_10_4_NUM_PEER_KEYS);
6735 	config.ast_skid_limit = __cpu_to_le32(TARGET_10_4_AST_SKID_LIMIT);
6736 	config.tx_chain_mask  = __cpu_to_le32(ar->hw_params.tx_chain_mask);
6737 	config.rx_chain_mask  = __cpu_to_le32(ar->hw_params.rx_chain_mask);
6738 
6739 	config.rx_timeout_pri[0] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
6740 	config.rx_timeout_pri[1] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
6741 	config.rx_timeout_pri[2] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_LO_PRI);
6742 	config.rx_timeout_pri[3] = __cpu_to_le32(TARGET_10_4_RX_TIMEOUT_HI_PRI);
6743 
6744 	config.rx_decap_mode	    = __cpu_to_le32(ar->wmi.rx_decap_mode);
6745 	config.scan_max_pending_req = __cpu_to_le32(TARGET_10_4_SCAN_MAX_REQS);
6746 	config.bmiss_offload_max_vdev =
6747 			__cpu_to_le32(TARGET_10_4_BMISS_OFFLOAD_MAX_VDEV);
6748 	config.roam_offload_max_vdev  =
6749 			__cpu_to_le32(TARGET_10_4_ROAM_OFFLOAD_MAX_VDEV);
6750 	config.roam_offload_max_ap_profiles =
6751 			__cpu_to_le32(TARGET_10_4_ROAM_OFFLOAD_MAX_PROFILES);
6752 	config.num_mcast_groups = __cpu_to_le32(TARGET_10_4_NUM_MCAST_GROUPS);
6753 	config.num_mcast_table_elems =
6754 			__cpu_to_le32(TARGET_10_4_NUM_MCAST_TABLE_ELEMS);
6755 
6756 	config.mcast2ucast_mode = __cpu_to_le32(TARGET_10_4_MCAST2UCAST_MODE);
6757 	config.tx_dbg_log_size  = __cpu_to_le32(TARGET_10_4_TX_DBG_LOG_SIZE);
6758 	config.num_wds_entries  = __cpu_to_le32(TARGET_10_4_NUM_WDS_ENTRIES);
6759 	config.dma_burst_size   = __cpu_to_le32(TARGET_10_4_DMA_BURST_SIZE);
6760 	config.mac_aggr_delim   = __cpu_to_le32(TARGET_10_4_MAC_AGGR_DELIM);
6761 
6762 	config.rx_skip_defrag_timeout_dup_detection_check =
6763 	  __cpu_to_le32(TARGET_10_4_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK);
6764 
6765 	config.vow_config = __cpu_to_le32(TARGET_10_4_VOW_CONFIG);
6766 	config.gtk_offload_max_vdev =
6767 			__cpu_to_le32(TARGET_10_4_GTK_OFFLOAD_MAX_VDEV);
6768 	config.num_msdu_desc = __cpu_to_le32(ar->htt.max_num_pending_tx);
6769 	config.max_frag_entries = __cpu_to_le32(TARGET_10_4_11AC_TX_MAX_FRAGS);
6770 	config.max_peer_ext_stats =
6771 			__cpu_to_le32(TARGET_10_4_MAX_PEER_EXT_STATS);
6772 	config.smart_ant_cap = __cpu_to_le32(TARGET_10_4_SMART_ANT_CAP);
6773 
6774 	config.bk_minfree = __cpu_to_le32(TARGET_10_4_BK_MIN_FREE);
6775 	config.be_minfree = __cpu_to_le32(TARGET_10_4_BE_MIN_FREE);
6776 	config.vi_minfree = __cpu_to_le32(TARGET_10_4_VI_MIN_FREE);
6777 	config.vo_minfree = __cpu_to_le32(TARGET_10_4_VO_MIN_FREE);
6778 
6779 	config.rx_batchmode = __cpu_to_le32(TARGET_10_4_RX_BATCH_MODE);
6780 	config.tt_support =
6781 			__cpu_to_le32(TARGET_10_4_THERMAL_THROTTLING_CONFIG);
6782 	config.atf_config = __cpu_to_le32(TARGET_10_4_ATF_CONFIG);
6783 	config.iphdr_pad_config = __cpu_to_le32(TARGET_10_4_IPHDR_PAD_CONFIG);
6784 	config.qwrap_config = __cpu_to_le32(TARGET_10_4_QWRAP_CONFIG);
6785 
6786 	len = sizeof(*cmd) +
6787 	      (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
6788 
6789 	buf = ath10k_wmi_alloc_skb(ar, len);
6790 	if (!buf)
6791 		return ERR_PTR(-ENOMEM);
6792 
6793 	cmd = (struct wmi_init_cmd_10_4 *)buf->data;
6794 	memcpy(&cmd->resource_config, &config, sizeof(config));
6795 	ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
6796 
6797 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.4\n");
6798 	return buf;
6799 }
6800 
6801 int ath10k_wmi_start_scan_verify(const struct wmi_start_scan_arg *arg)
6802 {
6803 	if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
6804 		return -EINVAL;
6805 	if (arg->n_channels > ARRAY_SIZE(arg->channels))
6806 		return -EINVAL;
6807 	if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
6808 		return -EINVAL;
6809 	if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
6810 		return -EINVAL;
6811 
6812 	return 0;
6813 }
6814 
6815 static size_t
6816 ath10k_wmi_start_scan_tlvs_len(const struct wmi_start_scan_arg *arg)
6817 {
6818 	int len = 0;
6819 
6820 	if (arg->ie_len) {
6821 		len += sizeof(struct wmi_ie_data);
6822 		len += roundup(arg->ie_len, 4);
6823 	}
6824 
6825 	if (arg->n_channels) {
6826 		len += sizeof(struct wmi_chan_list);
6827 		len += sizeof(__le32) * arg->n_channels;
6828 	}
6829 
6830 	if (arg->n_ssids) {
6831 		len += sizeof(struct wmi_ssid_list);
6832 		len += sizeof(struct wmi_ssid) * arg->n_ssids;
6833 	}
6834 
6835 	if (arg->n_bssids) {
6836 		len += sizeof(struct wmi_bssid_list);
6837 		len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
6838 	}
6839 
6840 	return len;
6841 }
6842 
6843 void ath10k_wmi_put_start_scan_common(struct wmi_start_scan_common *cmn,
6844 				      const struct wmi_start_scan_arg *arg)
6845 {
6846 	u32 scan_id;
6847 	u32 scan_req_id;
6848 
6849 	scan_id  = WMI_HOST_SCAN_REQ_ID_PREFIX;
6850 	scan_id |= arg->scan_id;
6851 
6852 	scan_req_id  = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
6853 	scan_req_id |= arg->scan_req_id;
6854 
6855 	cmn->scan_id            = __cpu_to_le32(scan_id);
6856 	cmn->scan_req_id        = __cpu_to_le32(scan_req_id);
6857 	cmn->vdev_id            = __cpu_to_le32(arg->vdev_id);
6858 	cmn->scan_priority      = __cpu_to_le32(arg->scan_priority);
6859 	cmn->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
6860 	cmn->dwell_time_active  = __cpu_to_le32(arg->dwell_time_active);
6861 	cmn->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
6862 	cmn->min_rest_time      = __cpu_to_le32(arg->min_rest_time);
6863 	cmn->max_rest_time      = __cpu_to_le32(arg->max_rest_time);
6864 	cmn->repeat_probe_time  = __cpu_to_le32(arg->repeat_probe_time);
6865 	cmn->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
6866 	cmn->idle_time          = __cpu_to_le32(arg->idle_time);
6867 	cmn->max_scan_time      = __cpu_to_le32(arg->max_scan_time);
6868 	cmn->probe_delay        = __cpu_to_le32(arg->probe_delay);
6869 	cmn->scan_ctrl_flags    = __cpu_to_le32(arg->scan_ctrl_flags);
6870 }
6871 
6872 static void
6873 ath10k_wmi_put_start_scan_tlvs(struct wmi_start_scan_tlvs *tlvs,
6874 			       const struct wmi_start_scan_arg *arg)
6875 {
6876 	struct wmi_ie_data *ie;
6877 	struct wmi_chan_list *channels;
6878 	struct wmi_ssid_list *ssids;
6879 	struct wmi_bssid_list *bssids;
6880 	void *ptr = tlvs->tlvs;
6881 	int i;
6882 
6883 	if (arg->n_channels) {
6884 		channels = ptr;
6885 		channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
6886 		channels->num_chan = __cpu_to_le32(arg->n_channels);
6887 
6888 		for (i = 0; i < arg->n_channels; i++)
6889 			channels->channel_list[i].freq =
6890 				__cpu_to_le16(arg->channels[i]);
6891 
6892 		ptr += sizeof(*channels);
6893 		ptr += sizeof(__le32) * arg->n_channels;
6894 	}
6895 
6896 	if (arg->n_ssids) {
6897 		ssids = ptr;
6898 		ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
6899 		ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
6900 
6901 		for (i = 0; i < arg->n_ssids; i++) {
6902 			ssids->ssids[i].ssid_len =
6903 				__cpu_to_le32(arg->ssids[i].len);
6904 			memcpy(&ssids->ssids[i].ssid,
6905 			       arg->ssids[i].ssid,
6906 			       arg->ssids[i].len);
6907 		}
6908 
6909 		ptr += sizeof(*ssids);
6910 		ptr += sizeof(struct wmi_ssid) * arg->n_ssids;
6911 	}
6912 
6913 	if (arg->n_bssids) {
6914 		bssids = ptr;
6915 		bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
6916 		bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
6917 
6918 		for (i = 0; i < arg->n_bssids; i++)
6919 			ether_addr_copy(bssids->bssid_list[i].addr,
6920 					arg->bssids[i].bssid);
6921 
6922 		ptr += sizeof(*bssids);
6923 		ptr += sizeof(struct wmi_mac_addr) * arg->n_bssids;
6924 	}
6925 
6926 	if (arg->ie_len) {
6927 		ie = ptr;
6928 		ie->tag = __cpu_to_le32(WMI_IE_TAG);
6929 		ie->ie_len = __cpu_to_le32(arg->ie_len);
6930 		memcpy(ie->ie_data, arg->ie, arg->ie_len);
6931 
6932 		ptr += sizeof(*ie);
6933 		ptr += roundup(arg->ie_len, 4);
6934 	}
6935 }
6936 
6937 static struct sk_buff *
6938 ath10k_wmi_op_gen_start_scan(struct ath10k *ar,
6939 			     const struct wmi_start_scan_arg *arg)
6940 {
6941 	struct wmi_start_scan_cmd *cmd;
6942 	struct sk_buff *skb;
6943 	size_t len;
6944 	int ret;
6945 
6946 	ret = ath10k_wmi_start_scan_verify(arg);
6947 	if (ret)
6948 		return ERR_PTR(ret);
6949 
6950 	len = sizeof(*cmd) + ath10k_wmi_start_scan_tlvs_len(arg);
6951 	skb = ath10k_wmi_alloc_skb(ar, len);
6952 	if (!skb)
6953 		return ERR_PTR(-ENOMEM);
6954 
6955 	cmd = (struct wmi_start_scan_cmd *)skb->data;
6956 
6957 	ath10k_wmi_put_start_scan_common(&cmd->common, arg);
6958 	ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
6959 
6960 	cmd->burst_duration_ms = __cpu_to_le32(0);
6961 
6962 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n");
6963 	return skb;
6964 }
6965 
6966 static struct sk_buff *
6967 ath10k_wmi_10x_op_gen_start_scan(struct ath10k *ar,
6968 				 const struct wmi_start_scan_arg *arg)
6969 {
6970 	struct wmi_10x_start_scan_cmd *cmd;
6971 	struct sk_buff *skb;
6972 	size_t len;
6973 	int ret;
6974 
6975 	ret = ath10k_wmi_start_scan_verify(arg);
6976 	if (ret)
6977 		return ERR_PTR(ret);
6978 
6979 	len = sizeof(*cmd) + ath10k_wmi_start_scan_tlvs_len(arg);
6980 	skb = ath10k_wmi_alloc_skb(ar, len);
6981 	if (!skb)
6982 		return ERR_PTR(-ENOMEM);
6983 
6984 	cmd = (struct wmi_10x_start_scan_cmd *)skb->data;
6985 
6986 	ath10k_wmi_put_start_scan_common(&cmd->common, arg);
6987 	ath10k_wmi_put_start_scan_tlvs(&cmd->tlvs, arg);
6988 
6989 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi 10x start scan\n");
6990 	return skb;
6991 }
6992 
6993 void ath10k_wmi_start_scan_init(struct ath10k *ar,
6994 				struct wmi_start_scan_arg *arg)
6995 {
6996 	/* setup commonly used values */
6997 	arg->scan_req_id = 1;
6998 	arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
6999 	arg->dwell_time_active = 50;
7000 	arg->dwell_time_passive = 150;
7001 	arg->min_rest_time = 50;
7002 	arg->max_rest_time = 500;
7003 	arg->repeat_probe_time = 0;
7004 	arg->probe_spacing_time = 0;
7005 	arg->idle_time = 0;
7006 	arg->max_scan_time = 20000;
7007 	arg->probe_delay = 5;
7008 	arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
7009 		| WMI_SCAN_EVENT_COMPLETED
7010 		| WMI_SCAN_EVENT_BSS_CHANNEL
7011 		| WMI_SCAN_EVENT_FOREIGN_CHANNEL
7012 		| WMI_SCAN_EVENT_FOREIGN_CHANNEL_EXIT
7013 		| WMI_SCAN_EVENT_DEQUEUED;
7014 	arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
7015 	arg->n_bssids = 1;
7016 	arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
7017 }
7018 
7019 static struct sk_buff *
7020 ath10k_wmi_op_gen_stop_scan(struct ath10k *ar,
7021 			    const struct wmi_stop_scan_arg *arg)
7022 {
7023 	struct wmi_stop_scan_cmd *cmd;
7024 	struct sk_buff *skb;
7025 	u32 scan_id;
7026 	u32 req_id;
7027 
7028 	if (arg->req_id > 0xFFF)
7029 		return ERR_PTR(-EINVAL);
7030 	if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
7031 		return ERR_PTR(-EINVAL);
7032 
7033 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7034 	if (!skb)
7035 		return ERR_PTR(-ENOMEM);
7036 
7037 	scan_id = arg->u.scan_id;
7038 	scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
7039 
7040 	req_id = arg->req_id;
7041 	req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
7042 
7043 	cmd = (struct wmi_stop_scan_cmd *)skb->data;
7044 	cmd->req_type    = __cpu_to_le32(arg->req_type);
7045 	cmd->vdev_id     = __cpu_to_le32(arg->u.vdev_id);
7046 	cmd->scan_id     = __cpu_to_le32(scan_id);
7047 	cmd->scan_req_id = __cpu_to_le32(req_id);
7048 
7049 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7050 		   "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
7051 		   arg->req_id, arg->req_type, arg->u.scan_id);
7052 	return skb;
7053 }
7054 
7055 static struct sk_buff *
7056 ath10k_wmi_op_gen_vdev_create(struct ath10k *ar, u32 vdev_id,
7057 			      enum wmi_vdev_type type,
7058 			      enum wmi_vdev_subtype subtype,
7059 			      const u8 macaddr[ETH_ALEN])
7060 {
7061 	struct wmi_vdev_create_cmd *cmd;
7062 	struct sk_buff *skb;
7063 
7064 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7065 	if (!skb)
7066 		return ERR_PTR(-ENOMEM);
7067 
7068 	cmd = (struct wmi_vdev_create_cmd *)skb->data;
7069 	cmd->vdev_id      = __cpu_to_le32(vdev_id);
7070 	cmd->vdev_type    = __cpu_to_le32(type);
7071 	cmd->vdev_subtype = __cpu_to_le32(subtype);
7072 	ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
7073 
7074 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7075 		   "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
7076 		   vdev_id, type, subtype, macaddr);
7077 	return skb;
7078 }
7079 
7080 static struct sk_buff *
7081 ath10k_wmi_op_gen_vdev_delete(struct ath10k *ar, u32 vdev_id)
7082 {
7083 	struct wmi_vdev_delete_cmd *cmd;
7084 	struct sk_buff *skb;
7085 
7086 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7087 	if (!skb)
7088 		return ERR_PTR(-ENOMEM);
7089 
7090 	cmd = (struct wmi_vdev_delete_cmd *)skb->data;
7091 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7092 
7093 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7094 		   "WMI vdev delete id %d\n", vdev_id);
7095 	return skb;
7096 }
7097 
7098 static struct sk_buff *
7099 ath10k_wmi_op_gen_vdev_start(struct ath10k *ar,
7100 			     const struct wmi_vdev_start_request_arg *arg,
7101 			     bool restart)
7102 {
7103 	struct wmi_vdev_start_request_cmd *cmd;
7104 	struct sk_buff *skb;
7105 	const char *cmdname;
7106 	u32 flags = 0;
7107 
7108 	if (WARN_ON(arg->hidden_ssid && !arg->ssid))
7109 		return ERR_PTR(-EINVAL);
7110 	if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
7111 		return ERR_PTR(-EINVAL);
7112 
7113 	if (restart)
7114 		cmdname = "restart";
7115 	else
7116 		cmdname = "start";
7117 
7118 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7119 	if (!skb)
7120 		return ERR_PTR(-ENOMEM);
7121 
7122 	if (arg->hidden_ssid)
7123 		flags |= WMI_VDEV_START_HIDDEN_SSID;
7124 	if (arg->pmf_enabled)
7125 		flags |= WMI_VDEV_START_PMF_ENABLED;
7126 
7127 	cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
7128 	cmd->vdev_id         = __cpu_to_le32(arg->vdev_id);
7129 	cmd->disable_hw_ack  = __cpu_to_le32(arg->disable_hw_ack);
7130 	cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
7131 	cmd->dtim_period     = __cpu_to_le32(arg->dtim_period);
7132 	cmd->flags           = __cpu_to_le32(flags);
7133 	cmd->bcn_tx_rate     = __cpu_to_le32(arg->bcn_tx_rate);
7134 	cmd->bcn_tx_power    = __cpu_to_le32(arg->bcn_tx_power);
7135 
7136 	if (arg->ssid) {
7137 		cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
7138 		memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
7139 	}
7140 
7141 	ath10k_wmi_put_wmi_channel(&cmd->chan, &arg->channel);
7142 
7143 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7144 		   "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n",
7145 		   cmdname, arg->vdev_id,
7146 		   flags, arg->channel.freq, arg->channel.mode,
7147 		   cmd->chan.flags, arg->channel.max_power);
7148 
7149 	return skb;
7150 }
7151 
7152 static struct sk_buff *
7153 ath10k_wmi_op_gen_vdev_stop(struct ath10k *ar, u32 vdev_id)
7154 {
7155 	struct wmi_vdev_stop_cmd *cmd;
7156 	struct sk_buff *skb;
7157 
7158 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7159 	if (!skb)
7160 		return ERR_PTR(-ENOMEM);
7161 
7162 	cmd = (struct wmi_vdev_stop_cmd *)skb->data;
7163 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7164 
7165 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
7166 	return skb;
7167 }
7168 
7169 static struct sk_buff *
7170 ath10k_wmi_op_gen_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid,
7171 			  const u8 *bssid)
7172 {
7173 	struct wmi_vdev_up_cmd *cmd;
7174 	struct sk_buff *skb;
7175 
7176 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7177 	if (!skb)
7178 		return ERR_PTR(-ENOMEM);
7179 
7180 	cmd = (struct wmi_vdev_up_cmd *)skb->data;
7181 	cmd->vdev_id       = __cpu_to_le32(vdev_id);
7182 	cmd->vdev_assoc_id = __cpu_to_le32(aid);
7183 	ether_addr_copy(cmd->vdev_bssid.addr, bssid);
7184 
7185 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7186 		   "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
7187 		   vdev_id, aid, bssid);
7188 	return skb;
7189 }
7190 
7191 static struct sk_buff *
7192 ath10k_wmi_op_gen_vdev_down(struct ath10k *ar, u32 vdev_id)
7193 {
7194 	struct wmi_vdev_down_cmd *cmd;
7195 	struct sk_buff *skb;
7196 
7197 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7198 	if (!skb)
7199 		return ERR_PTR(-ENOMEM);
7200 
7201 	cmd = (struct wmi_vdev_down_cmd *)skb->data;
7202 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7203 
7204 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7205 		   "wmi mgmt vdev down id 0x%x\n", vdev_id);
7206 	return skb;
7207 }
7208 
7209 static struct sk_buff *
7210 ath10k_wmi_op_gen_vdev_set_param(struct ath10k *ar, u32 vdev_id,
7211 				 u32 param_id, u32 param_value)
7212 {
7213 	struct wmi_vdev_set_param_cmd *cmd;
7214 	struct sk_buff *skb;
7215 
7216 	if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
7217 		ath10k_dbg(ar, ATH10K_DBG_WMI,
7218 			   "vdev param %d not supported by firmware\n",
7219 			    param_id);
7220 		return ERR_PTR(-EOPNOTSUPP);
7221 	}
7222 
7223 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7224 	if (!skb)
7225 		return ERR_PTR(-ENOMEM);
7226 
7227 	cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
7228 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
7229 	cmd->param_id    = __cpu_to_le32(param_id);
7230 	cmd->param_value = __cpu_to_le32(param_value);
7231 
7232 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7233 		   "wmi vdev id 0x%x set param %d value %d\n",
7234 		   vdev_id, param_id, param_value);
7235 	return skb;
7236 }
7237 
7238 static struct sk_buff *
7239 ath10k_wmi_op_gen_vdev_install_key(struct ath10k *ar,
7240 				   const struct wmi_vdev_install_key_arg *arg)
7241 {
7242 	struct wmi_vdev_install_key_cmd *cmd;
7243 	struct sk_buff *skb;
7244 
7245 	if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
7246 		return ERR_PTR(-EINVAL);
7247 	if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
7248 		return ERR_PTR(-EINVAL);
7249 
7250 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + arg->key_len);
7251 	if (!skb)
7252 		return ERR_PTR(-ENOMEM);
7253 
7254 	cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
7255 	cmd->vdev_id       = __cpu_to_le32(arg->vdev_id);
7256 	cmd->key_idx       = __cpu_to_le32(arg->key_idx);
7257 	cmd->key_flags     = __cpu_to_le32(arg->key_flags);
7258 	cmd->key_cipher    = __cpu_to_le32(arg->key_cipher);
7259 	cmd->key_len       = __cpu_to_le32(arg->key_len);
7260 	cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
7261 	cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
7262 
7263 	if (arg->macaddr)
7264 		ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
7265 	if (arg->key_data)
7266 		memcpy(cmd->key_data, arg->key_data, arg->key_len);
7267 
7268 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7269 		   "wmi vdev install key idx %d cipher %d len %d\n",
7270 		   arg->key_idx, arg->key_cipher, arg->key_len);
7271 	return skb;
7272 }
7273 
7274 static struct sk_buff *
7275 ath10k_wmi_op_gen_vdev_spectral_conf(struct ath10k *ar,
7276 				     const struct wmi_vdev_spectral_conf_arg *arg)
7277 {
7278 	struct wmi_vdev_spectral_conf_cmd *cmd;
7279 	struct sk_buff *skb;
7280 
7281 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7282 	if (!skb)
7283 		return ERR_PTR(-ENOMEM);
7284 
7285 	cmd = (struct wmi_vdev_spectral_conf_cmd *)skb->data;
7286 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
7287 	cmd->scan_count = __cpu_to_le32(arg->scan_count);
7288 	cmd->scan_period = __cpu_to_le32(arg->scan_period);
7289 	cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
7290 	cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
7291 	cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
7292 	cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
7293 	cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
7294 	cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
7295 	cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
7296 	cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
7297 	cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
7298 	cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
7299 	cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
7300 	cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
7301 	cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
7302 	cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
7303 	cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
7304 	cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
7305 
7306 	return skb;
7307 }
7308 
7309 static struct sk_buff *
7310 ath10k_wmi_op_gen_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id,
7311 				       u32 trigger, u32 enable)
7312 {
7313 	struct wmi_vdev_spectral_enable_cmd *cmd;
7314 	struct sk_buff *skb;
7315 
7316 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7317 	if (!skb)
7318 		return ERR_PTR(-ENOMEM);
7319 
7320 	cmd = (struct wmi_vdev_spectral_enable_cmd *)skb->data;
7321 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7322 	cmd->trigger_cmd = __cpu_to_le32(trigger);
7323 	cmd->enable_cmd = __cpu_to_le32(enable);
7324 
7325 	return skb;
7326 }
7327 
7328 static struct sk_buff *
7329 ath10k_wmi_op_gen_peer_create(struct ath10k *ar, u32 vdev_id,
7330 			      const u8 peer_addr[ETH_ALEN],
7331 			      enum wmi_peer_type peer_type)
7332 {
7333 	struct wmi_peer_create_cmd *cmd;
7334 	struct sk_buff *skb;
7335 
7336 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7337 	if (!skb)
7338 		return ERR_PTR(-ENOMEM);
7339 
7340 	cmd = (struct wmi_peer_create_cmd *)skb->data;
7341 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7342 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
7343 	cmd->peer_type = __cpu_to_le32(peer_type);
7344 
7345 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7346 		   "wmi peer create vdev_id %d peer_addr %pM\n",
7347 		   vdev_id, peer_addr);
7348 	return skb;
7349 }
7350 
7351 static struct sk_buff *
7352 ath10k_wmi_op_gen_peer_delete(struct ath10k *ar, u32 vdev_id,
7353 			      const u8 peer_addr[ETH_ALEN])
7354 {
7355 	struct wmi_peer_delete_cmd *cmd;
7356 	struct sk_buff *skb;
7357 
7358 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7359 	if (!skb)
7360 		return ERR_PTR(-ENOMEM);
7361 
7362 	cmd = (struct wmi_peer_delete_cmd *)skb->data;
7363 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7364 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
7365 
7366 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7367 		   "wmi peer delete vdev_id %d peer_addr %pM\n",
7368 		   vdev_id, peer_addr);
7369 	return skb;
7370 }
7371 
7372 static struct sk_buff *
7373 ath10k_wmi_op_gen_peer_flush(struct ath10k *ar, u32 vdev_id,
7374 			     const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
7375 {
7376 	struct wmi_peer_flush_tids_cmd *cmd;
7377 	struct sk_buff *skb;
7378 
7379 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7380 	if (!skb)
7381 		return ERR_PTR(-ENOMEM);
7382 
7383 	cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
7384 	cmd->vdev_id         = __cpu_to_le32(vdev_id);
7385 	cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
7386 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
7387 
7388 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7389 		   "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
7390 		   vdev_id, peer_addr, tid_bitmap);
7391 	return skb;
7392 }
7393 
7394 static struct sk_buff *
7395 ath10k_wmi_op_gen_peer_set_param(struct ath10k *ar, u32 vdev_id,
7396 				 const u8 *peer_addr,
7397 				 enum wmi_peer_param param_id,
7398 				 u32 param_value)
7399 {
7400 	struct wmi_peer_set_param_cmd *cmd;
7401 	struct sk_buff *skb;
7402 
7403 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7404 	if (!skb)
7405 		return ERR_PTR(-ENOMEM);
7406 
7407 	cmd = (struct wmi_peer_set_param_cmd *)skb->data;
7408 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
7409 	cmd->param_id    = __cpu_to_le32(param_id);
7410 	cmd->param_value = __cpu_to_le32(param_value);
7411 	ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
7412 
7413 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7414 		   "wmi vdev %d peer 0x%pM set param %d value %d\n",
7415 		   vdev_id, peer_addr, param_id, param_value);
7416 	return skb;
7417 }
7418 
7419 static struct sk_buff *
7420 ath10k_wmi_op_gen_set_psmode(struct ath10k *ar, u32 vdev_id,
7421 			     enum wmi_sta_ps_mode psmode)
7422 {
7423 	struct wmi_sta_powersave_mode_cmd *cmd;
7424 	struct sk_buff *skb;
7425 
7426 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7427 	if (!skb)
7428 		return ERR_PTR(-ENOMEM);
7429 
7430 	cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
7431 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
7432 	cmd->sta_ps_mode = __cpu_to_le32(psmode);
7433 
7434 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7435 		   "wmi set powersave id 0x%x mode %d\n",
7436 		   vdev_id, psmode);
7437 	return skb;
7438 }
7439 
7440 static struct sk_buff *
7441 ath10k_wmi_op_gen_set_sta_ps(struct ath10k *ar, u32 vdev_id,
7442 			     enum wmi_sta_powersave_param param_id,
7443 			     u32 value)
7444 {
7445 	struct wmi_sta_powersave_param_cmd *cmd;
7446 	struct sk_buff *skb;
7447 
7448 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7449 	if (!skb)
7450 		return ERR_PTR(-ENOMEM);
7451 
7452 	cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
7453 	cmd->vdev_id     = __cpu_to_le32(vdev_id);
7454 	cmd->param_id    = __cpu_to_le32(param_id);
7455 	cmd->param_value = __cpu_to_le32(value);
7456 
7457 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7458 		   "wmi sta ps param vdev_id 0x%x param %d value %d\n",
7459 		   vdev_id, param_id, value);
7460 	return skb;
7461 }
7462 
7463 static struct sk_buff *
7464 ath10k_wmi_op_gen_set_ap_ps(struct ath10k *ar, u32 vdev_id, const u8 *mac,
7465 			    enum wmi_ap_ps_peer_param param_id, u32 value)
7466 {
7467 	struct wmi_ap_ps_peer_cmd *cmd;
7468 	struct sk_buff *skb;
7469 
7470 	if (!mac)
7471 		return ERR_PTR(-EINVAL);
7472 
7473 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7474 	if (!skb)
7475 		return ERR_PTR(-ENOMEM);
7476 
7477 	cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
7478 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7479 	cmd->param_id = __cpu_to_le32(param_id);
7480 	cmd->param_value = __cpu_to_le32(value);
7481 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
7482 
7483 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7484 		   "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
7485 		   vdev_id, param_id, value, mac);
7486 	return skb;
7487 }
7488 
7489 static struct sk_buff *
7490 ath10k_wmi_op_gen_scan_chan_list(struct ath10k *ar,
7491 				 const struct wmi_scan_chan_list_arg *arg)
7492 {
7493 	struct wmi_scan_chan_list_cmd *cmd;
7494 	struct sk_buff *skb;
7495 	struct wmi_channel_arg *ch;
7496 	struct wmi_channel *ci;
7497 	int len;
7498 	int i;
7499 
7500 	len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
7501 
7502 	skb = ath10k_wmi_alloc_skb(ar, len);
7503 	if (!skb)
7504 		return ERR_PTR(-EINVAL);
7505 
7506 	cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
7507 	cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
7508 
7509 	for (i = 0; i < arg->n_channels; i++) {
7510 		ch = &arg->channels[i];
7511 		ci = &cmd->chan_info[i];
7512 
7513 		ath10k_wmi_put_wmi_channel(ci, ch);
7514 	}
7515 
7516 	return skb;
7517 }
7518 
7519 static void
7520 ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
7521 			   const struct wmi_peer_assoc_complete_arg *arg)
7522 {
7523 	struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
7524 
7525 	cmd->vdev_id            = __cpu_to_le32(arg->vdev_id);
7526 	cmd->peer_new_assoc     = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
7527 	cmd->peer_associd       = __cpu_to_le32(arg->peer_aid);
7528 	cmd->peer_flags         = __cpu_to_le32(arg->peer_flags);
7529 	cmd->peer_caps          = __cpu_to_le32(arg->peer_caps);
7530 	cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
7531 	cmd->peer_ht_caps       = __cpu_to_le32(arg->peer_ht_caps);
7532 	cmd->peer_max_mpdu      = __cpu_to_le32(arg->peer_max_mpdu);
7533 	cmd->peer_mpdu_density  = __cpu_to_le32(arg->peer_mpdu_density);
7534 	cmd->peer_rate_caps     = __cpu_to_le32(arg->peer_rate_caps);
7535 	cmd->peer_nss           = __cpu_to_le32(arg->peer_num_spatial_streams);
7536 	cmd->peer_vht_caps      = __cpu_to_le32(arg->peer_vht_caps);
7537 	cmd->peer_phymode       = __cpu_to_le32(arg->peer_phymode);
7538 
7539 	ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
7540 
7541 	cmd->peer_legacy_rates.num_rates =
7542 		__cpu_to_le32(arg->peer_legacy_rates.num_rates);
7543 	memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
7544 	       arg->peer_legacy_rates.num_rates);
7545 
7546 	cmd->peer_ht_rates.num_rates =
7547 		__cpu_to_le32(arg->peer_ht_rates.num_rates);
7548 	memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
7549 	       arg->peer_ht_rates.num_rates);
7550 
7551 	cmd->peer_vht_rates.rx_max_rate =
7552 		__cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
7553 	cmd->peer_vht_rates.rx_mcs_set =
7554 		__cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
7555 	cmd->peer_vht_rates.tx_max_rate =
7556 		__cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
7557 	cmd->peer_vht_rates.tx_mcs_set =
7558 		__cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
7559 }
7560 
7561 static void
7562 ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
7563 				const struct wmi_peer_assoc_complete_arg *arg)
7564 {
7565 	struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
7566 
7567 	ath10k_wmi_peer_assoc_fill(ar, buf, arg);
7568 	memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
7569 }
7570 
7571 static void
7572 ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
7573 				const struct wmi_peer_assoc_complete_arg *arg)
7574 {
7575 	ath10k_wmi_peer_assoc_fill(ar, buf, arg);
7576 }
7577 
7578 static void
7579 ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
7580 				const struct wmi_peer_assoc_complete_arg *arg)
7581 {
7582 	struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
7583 	int max_mcs, max_nss;
7584 	u32 info0;
7585 
7586 	/* TODO: Is using max values okay with firmware? */
7587 	max_mcs = 0xf;
7588 	max_nss = 0xf;
7589 
7590 	info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
7591 		SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
7592 
7593 	ath10k_wmi_peer_assoc_fill(ar, buf, arg);
7594 	cmd->info0 = __cpu_to_le32(info0);
7595 }
7596 
7597 static void
7598 ath10k_wmi_peer_assoc_fill_10_4(struct ath10k *ar, void *buf,
7599 				const struct wmi_peer_assoc_complete_arg *arg)
7600 {
7601 	struct wmi_10_4_peer_assoc_complete_cmd *cmd = buf;
7602 
7603 	ath10k_wmi_peer_assoc_fill_10_2(ar, buf, arg);
7604 	if (arg->peer_bw_rxnss_override)
7605 		cmd->peer_bw_rxnss_override =
7606 			__cpu_to_le32((arg->peer_bw_rxnss_override - 1) |
7607 				      BIT(PEER_BW_RXNSS_OVERRIDE_OFFSET));
7608 	else
7609 		cmd->peer_bw_rxnss_override = 0;
7610 }
7611 
7612 static int
7613 ath10k_wmi_peer_assoc_check_arg(const struct wmi_peer_assoc_complete_arg *arg)
7614 {
7615 	if (arg->peer_mpdu_density > 16)
7616 		return -EINVAL;
7617 	if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
7618 		return -EINVAL;
7619 	if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
7620 		return -EINVAL;
7621 
7622 	return 0;
7623 }
7624 
7625 static struct sk_buff *
7626 ath10k_wmi_op_gen_peer_assoc(struct ath10k *ar,
7627 			     const struct wmi_peer_assoc_complete_arg *arg)
7628 {
7629 	size_t len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
7630 	struct sk_buff *skb;
7631 	int ret;
7632 
7633 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
7634 	if (ret)
7635 		return ERR_PTR(ret);
7636 
7637 	skb = ath10k_wmi_alloc_skb(ar, len);
7638 	if (!skb)
7639 		return ERR_PTR(-ENOMEM);
7640 
7641 	ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
7642 
7643 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7644 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
7645 		   arg->vdev_id, arg->addr,
7646 		   arg->peer_reassoc ? "reassociate" : "new");
7647 	return skb;
7648 }
7649 
7650 static struct sk_buff *
7651 ath10k_wmi_10_1_op_gen_peer_assoc(struct ath10k *ar,
7652 				  const struct wmi_peer_assoc_complete_arg *arg)
7653 {
7654 	size_t len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
7655 	struct sk_buff *skb;
7656 	int ret;
7657 
7658 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
7659 	if (ret)
7660 		return ERR_PTR(ret);
7661 
7662 	skb = ath10k_wmi_alloc_skb(ar, len);
7663 	if (!skb)
7664 		return ERR_PTR(-ENOMEM);
7665 
7666 	ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
7667 
7668 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7669 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
7670 		   arg->vdev_id, arg->addr,
7671 		   arg->peer_reassoc ? "reassociate" : "new");
7672 	return skb;
7673 }
7674 
7675 static struct sk_buff *
7676 ath10k_wmi_10_2_op_gen_peer_assoc(struct ath10k *ar,
7677 				  const struct wmi_peer_assoc_complete_arg *arg)
7678 {
7679 	size_t len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
7680 	struct sk_buff *skb;
7681 	int ret;
7682 
7683 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
7684 	if (ret)
7685 		return ERR_PTR(ret);
7686 
7687 	skb = ath10k_wmi_alloc_skb(ar, len);
7688 	if (!skb)
7689 		return ERR_PTR(-ENOMEM);
7690 
7691 	ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
7692 
7693 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7694 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
7695 		   arg->vdev_id, arg->addr,
7696 		   arg->peer_reassoc ? "reassociate" : "new");
7697 	return skb;
7698 }
7699 
7700 static struct sk_buff *
7701 ath10k_wmi_10_4_op_gen_peer_assoc(struct ath10k *ar,
7702 				  const struct wmi_peer_assoc_complete_arg *arg)
7703 {
7704 	size_t len = sizeof(struct wmi_10_4_peer_assoc_complete_cmd);
7705 	struct sk_buff *skb;
7706 	int ret;
7707 
7708 	ret = ath10k_wmi_peer_assoc_check_arg(arg);
7709 	if (ret)
7710 		return ERR_PTR(ret);
7711 
7712 	skb = ath10k_wmi_alloc_skb(ar, len);
7713 	if (!skb)
7714 		return ERR_PTR(-ENOMEM);
7715 
7716 	ath10k_wmi_peer_assoc_fill_10_4(ar, skb->data, arg);
7717 
7718 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7719 		   "wmi peer assoc vdev %d addr %pM (%s)\n",
7720 		   arg->vdev_id, arg->addr,
7721 		   arg->peer_reassoc ? "reassociate" : "new");
7722 	return skb;
7723 }
7724 
7725 static struct sk_buff *
7726 ath10k_wmi_10_2_op_gen_pdev_get_temperature(struct ath10k *ar)
7727 {
7728 	struct sk_buff *skb;
7729 
7730 	skb = ath10k_wmi_alloc_skb(ar, 0);
7731 	if (!skb)
7732 		return ERR_PTR(-ENOMEM);
7733 
7734 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev get temperature\n");
7735 	return skb;
7736 }
7737 
7738 static struct sk_buff *
7739 ath10k_wmi_10_2_op_gen_pdev_bss_chan_info(struct ath10k *ar,
7740 					  enum wmi_bss_survey_req_type type)
7741 {
7742 	struct wmi_pdev_chan_info_req_cmd *cmd;
7743 	struct sk_buff *skb;
7744 
7745 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7746 	if (!skb)
7747 		return ERR_PTR(-ENOMEM);
7748 
7749 	cmd = (struct wmi_pdev_chan_info_req_cmd *)skb->data;
7750 	cmd->type = __cpu_to_le32(type);
7751 
7752 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7753 		   "wmi pdev bss info request type %d\n", type);
7754 
7755 	return skb;
7756 }
7757 
7758 /* This function assumes the beacon is already DMA mapped */
7759 static struct sk_buff *
7760 ath10k_wmi_op_gen_beacon_dma(struct ath10k *ar, u32 vdev_id, const void *bcn,
7761 			     size_t bcn_len, u32 bcn_paddr, bool dtim_zero,
7762 			     bool deliver_cab)
7763 {
7764 	struct wmi_bcn_tx_ref_cmd *cmd;
7765 	struct sk_buff *skb;
7766 	struct ieee80211_hdr *hdr;
7767 	u16 fc;
7768 
7769 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7770 	if (!skb)
7771 		return ERR_PTR(-ENOMEM);
7772 
7773 	hdr = (struct ieee80211_hdr *)bcn;
7774 	fc = le16_to_cpu(hdr->frame_control);
7775 
7776 	cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
7777 	cmd->vdev_id = __cpu_to_le32(vdev_id);
7778 	cmd->data_len = __cpu_to_le32(bcn_len);
7779 	cmd->data_ptr = __cpu_to_le32(bcn_paddr);
7780 	cmd->msdu_id = 0;
7781 	cmd->frame_control = __cpu_to_le32(fc);
7782 	cmd->flags = 0;
7783 	cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
7784 
7785 	if (dtim_zero)
7786 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
7787 
7788 	if (deliver_cab)
7789 		cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
7790 
7791 	return skb;
7792 }
7793 
7794 void ath10k_wmi_set_wmm_param(struct wmi_wmm_params *params,
7795 			      const struct wmi_wmm_params_arg *arg)
7796 {
7797 	params->cwmin  = __cpu_to_le32(arg->cwmin);
7798 	params->cwmax  = __cpu_to_le32(arg->cwmax);
7799 	params->aifs   = __cpu_to_le32(arg->aifs);
7800 	params->txop   = __cpu_to_le32(arg->txop);
7801 	params->acm    = __cpu_to_le32(arg->acm);
7802 	params->no_ack = __cpu_to_le32(arg->no_ack);
7803 }
7804 
7805 static struct sk_buff *
7806 ath10k_wmi_op_gen_pdev_set_wmm(struct ath10k *ar,
7807 			       const struct wmi_wmm_params_all_arg *arg)
7808 {
7809 	struct wmi_pdev_set_wmm_params *cmd;
7810 	struct sk_buff *skb;
7811 
7812 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7813 	if (!skb)
7814 		return ERR_PTR(-ENOMEM);
7815 
7816 	cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
7817 	ath10k_wmi_set_wmm_param(&cmd->ac_be, &arg->ac_be);
7818 	ath10k_wmi_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
7819 	ath10k_wmi_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
7820 	ath10k_wmi_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
7821 
7822 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
7823 	return skb;
7824 }
7825 
7826 static struct sk_buff *
7827 ath10k_wmi_op_gen_request_stats(struct ath10k *ar, u32 stats_mask)
7828 {
7829 	struct wmi_request_stats_cmd *cmd;
7830 	struct sk_buff *skb;
7831 
7832 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7833 	if (!skb)
7834 		return ERR_PTR(-ENOMEM);
7835 
7836 	cmd = (struct wmi_request_stats_cmd *)skb->data;
7837 	cmd->stats_id = __cpu_to_le32(stats_mask);
7838 
7839 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi request stats 0x%08x\n",
7840 		   stats_mask);
7841 	return skb;
7842 }
7843 
7844 static struct sk_buff *
7845 ath10k_wmi_op_gen_force_fw_hang(struct ath10k *ar,
7846 				enum wmi_force_fw_hang_type type, u32 delay_ms)
7847 {
7848 	struct wmi_force_fw_hang_cmd *cmd;
7849 	struct sk_buff *skb;
7850 
7851 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7852 	if (!skb)
7853 		return ERR_PTR(-ENOMEM);
7854 
7855 	cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
7856 	cmd->type = __cpu_to_le32(type);
7857 	cmd->delay_ms = __cpu_to_le32(delay_ms);
7858 
7859 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
7860 		   type, delay_ms);
7861 	return skb;
7862 }
7863 
7864 static struct sk_buff *
7865 ath10k_wmi_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
7866 			     u32 log_level)
7867 {
7868 	struct wmi_dbglog_cfg_cmd *cmd;
7869 	struct sk_buff *skb;
7870 	u32 cfg;
7871 
7872 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7873 	if (!skb)
7874 		return ERR_PTR(-ENOMEM);
7875 
7876 	cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
7877 
7878 	if (module_enable) {
7879 		cfg = SM(log_level,
7880 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7881 	} else {
7882 		/* set back defaults, all modules with WARN level */
7883 		cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
7884 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7885 		module_enable = ~0;
7886 	}
7887 
7888 	cmd->module_enable = __cpu_to_le32(module_enable);
7889 	cmd->module_valid = __cpu_to_le32(~0);
7890 	cmd->config_enable = __cpu_to_le32(cfg);
7891 	cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
7892 
7893 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7894 		   "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
7895 		   __le32_to_cpu(cmd->module_enable),
7896 		   __le32_to_cpu(cmd->module_valid),
7897 		   __le32_to_cpu(cmd->config_enable),
7898 		   __le32_to_cpu(cmd->config_valid));
7899 	return skb;
7900 }
7901 
7902 static struct sk_buff *
7903 ath10k_wmi_10_4_op_gen_dbglog_cfg(struct ath10k *ar, u64 module_enable,
7904 				  u32 log_level)
7905 {
7906 	struct wmi_10_4_dbglog_cfg_cmd *cmd;
7907 	struct sk_buff *skb;
7908 	u32 cfg;
7909 
7910 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7911 	if (!skb)
7912 		return ERR_PTR(-ENOMEM);
7913 
7914 	cmd = (struct wmi_10_4_dbglog_cfg_cmd *)skb->data;
7915 
7916 	if (module_enable) {
7917 		cfg = SM(log_level,
7918 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7919 	} else {
7920 		/* set back defaults, all modules with WARN level */
7921 		cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
7922 			 ATH10K_DBGLOG_CFG_LOG_LVL);
7923 		module_enable = ~0;
7924 	}
7925 
7926 	cmd->module_enable = __cpu_to_le64(module_enable);
7927 	cmd->module_valid = __cpu_to_le64(~0);
7928 	cmd->config_enable = __cpu_to_le32(cfg);
7929 	cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
7930 
7931 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7932 		   "wmi dbglog cfg modules 0x%016llx 0x%016llx config %08x %08x\n",
7933 		   __le64_to_cpu(cmd->module_enable),
7934 		   __le64_to_cpu(cmd->module_valid),
7935 		   __le32_to_cpu(cmd->config_enable),
7936 		   __le32_to_cpu(cmd->config_valid));
7937 	return skb;
7938 }
7939 
7940 static struct sk_buff *
7941 ath10k_wmi_op_gen_pktlog_enable(struct ath10k *ar, u32 ev_bitmap)
7942 {
7943 	struct wmi_pdev_pktlog_enable_cmd *cmd;
7944 	struct sk_buff *skb;
7945 
7946 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7947 	if (!skb)
7948 		return ERR_PTR(-ENOMEM);
7949 
7950 	ev_bitmap &= ATH10K_PKTLOG_ANY;
7951 
7952 	cmd = (struct wmi_pdev_pktlog_enable_cmd *)skb->data;
7953 	cmd->ev_bitmap = __cpu_to_le32(ev_bitmap);
7954 
7955 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi enable pktlog filter 0x%08x\n",
7956 		   ev_bitmap);
7957 	return skb;
7958 }
7959 
7960 static struct sk_buff *
7961 ath10k_wmi_op_gen_pktlog_disable(struct ath10k *ar)
7962 {
7963 	struct sk_buff *skb;
7964 
7965 	skb = ath10k_wmi_alloc_skb(ar, 0);
7966 	if (!skb)
7967 		return ERR_PTR(-ENOMEM);
7968 
7969 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi disable pktlog\n");
7970 	return skb;
7971 }
7972 
7973 static struct sk_buff *
7974 ath10k_wmi_op_gen_pdev_set_quiet_mode(struct ath10k *ar, u32 period,
7975 				      u32 duration, u32 next_offset,
7976 				      u32 enabled)
7977 {
7978 	struct wmi_pdev_set_quiet_cmd *cmd;
7979 	struct sk_buff *skb;
7980 
7981 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
7982 	if (!skb)
7983 		return ERR_PTR(-ENOMEM);
7984 
7985 	cmd = (struct wmi_pdev_set_quiet_cmd *)skb->data;
7986 	cmd->period = __cpu_to_le32(period);
7987 	cmd->duration = __cpu_to_le32(duration);
7988 	cmd->next_start = __cpu_to_le32(next_offset);
7989 	cmd->enabled = __cpu_to_le32(enabled);
7990 
7991 	ath10k_dbg(ar, ATH10K_DBG_WMI,
7992 		   "wmi quiet param: period %u duration %u enabled %d\n",
7993 		   period, duration, enabled);
7994 	return skb;
7995 }
7996 
7997 static struct sk_buff *
7998 ath10k_wmi_op_gen_addba_clear_resp(struct ath10k *ar, u32 vdev_id,
7999 				   const u8 *mac)
8000 {
8001 	struct wmi_addba_clear_resp_cmd *cmd;
8002 	struct sk_buff *skb;
8003 
8004 	if (!mac)
8005 		return ERR_PTR(-EINVAL);
8006 
8007 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8008 	if (!skb)
8009 		return ERR_PTR(-ENOMEM);
8010 
8011 	cmd = (struct wmi_addba_clear_resp_cmd *)skb->data;
8012 	cmd->vdev_id = __cpu_to_le32(vdev_id);
8013 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
8014 
8015 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8016 		   "wmi addba clear resp vdev_id 0x%X mac_addr %pM\n",
8017 		   vdev_id, mac);
8018 	return skb;
8019 }
8020 
8021 static struct sk_buff *
8022 ath10k_wmi_op_gen_addba_send(struct ath10k *ar, u32 vdev_id, const u8 *mac,
8023 			     u32 tid, u32 buf_size)
8024 {
8025 	struct wmi_addba_send_cmd *cmd;
8026 	struct sk_buff *skb;
8027 
8028 	if (!mac)
8029 		return ERR_PTR(-EINVAL);
8030 
8031 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8032 	if (!skb)
8033 		return ERR_PTR(-ENOMEM);
8034 
8035 	cmd = (struct wmi_addba_send_cmd *)skb->data;
8036 	cmd->vdev_id = __cpu_to_le32(vdev_id);
8037 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
8038 	cmd->tid = __cpu_to_le32(tid);
8039 	cmd->buffersize = __cpu_to_le32(buf_size);
8040 
8041 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8042 		   "wmi addba send vdev_id 0x%X mac_addr %pM tid %u bufsize %u\n",
8043 		   vdev_id, mac, tid, buf_size);
8044 	return skb;
8045 }
8046 
8047 static struct sk_buff *
8048 ath10k_wmi_op_gen_addba_set_resp(struct ath10k *ar, u32 vdev_id, const u8 *mac,
8049 				 u32 tid, u32 status)
8050 {
8051 	struct wmi_addba_setresponse_cmd *cmd;
8052 	struct sk_buff *skb;
8053 
8054 	if (!mac)
8055 		return ERR_PTR(-EINVAL);
8056 
8057 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8058 	if (!skb)
8059 		return ERR_PTR(-ENOMEM);
8060 
8061 	cmd = (struct wmi_addba_setresponse_cmd *)skb->data;
8062 	cmd->vdev_id = __cpu_to_le32(vdev_id);
8063 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
8064 	cmd->tid = __cpu_to_le32(tid);
8065 	cmd->statuscode = __cpu_to_le32(status);
8066 
8067 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8068 		   "wmi addba set resp vdev_id 0x%X mac_addr %pM tid %u status %u\n",
8069 		   vdev_id, mac, tid, status);
8070 	return skb;
8071 }
8072 
8073 static struct sk_buff *
8074 ath10k_wmi_op_gen_delba_send(struct ath10k *ar, u32 vdev_id, const u8 *mac,
8075 			     u32 tid, u32 initiator, u32 reason)
8076 {
8077 	struct wmi_delba_send_cmd *cmd;
8078 	struct sk_buff *skb;
8079 
8080 	if (!mac)
8081 		return ERR_PTR(-EINVAL);
8082 
8083 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8084 	if (!skb)
8085 		return ERR_PTR(-ENOMEM);
8086 
8087 	cmd = (struct wmi_delba_send_cmd *)skb->data;
8088 	cmd->vdev_id = __cpu_to_le32(vdev_id);
8089 	ether_addr_copy(cmd->peer_macaddr.addr, mac);
8090 	cmd->tid = __cpu_to_le32(tid);
8091 	cmd->initiator = __cpu_to_le32(initiator);
8092 	cmd->reasoncode = __cpu_to_le32(reason);
8093 
8094 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8095 		   "wmi delba send vdev_id 0x%X mac_addr %pM tid %u initiator %u reason %u\n",
8096 		   vdev_id, mac, tid, initiator, reason);
8097 	return skb;
8098 }
8099 
8100 static struct sk_buff *
8101 ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config(struct ath10k *ar, u32 param)
8102 {
8103 	struct wmi_pdev_get_tpc_config_cmd *cmd;
8104 	struct sk_buff *skb;
8105 
8106 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8107 	if (!skb)
8108 		return ERR_PTR(-ENOMEM);
8109 
8110 	cmd = (struct wmi_pdev_get_tpc_config_cmd *)skb->data;
8111 	cmd->param = __cpu_to_le32(param);
8112 
8113 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8114 		   "wmi pdev get tpc config param %d\n", param);
8115 	return skb;
8116 }
8117 
8118 size_t ath10k_wmi_fw_stats_num_peers(struct list_head *head)
8119 {
8120 	struct ath10k_fw_stats_peer *i;
8121 	size_t num = 0;
8122 
8123 	list_for_each_entry(i, head, list)
8124 		++num;
8125 
8126 	return num;
8127 }
8128 
8129 size_t ath10k_wmi_fw_stats_num_vdevs(struct list_head *head)
8130 {
8131 	struct ath10k_fw_stats_vdev *i;
8132 	size_t num = 0;
8133 
8134 	list_for_each_entry(i, head, list)
8135 		++num;
8136 
8137 	return num;
8138 }
8139 
8140 static void
8141 ath10k_wmi_fw_pdev_base_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
8142 				   char *buf, u32 *length)
8143 {
8144 	u32 len = *length;
8145 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8146 
8147 	len += scnprintf(buf + len, buf_len - len, "\n");
8148 	len += scnprintf(buf + len, buf_len - len, "%30s\n",
8149 			"ath10k PDEV stats");
8150 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8151 			"=================");
8152 
8153 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8154 			"Channel noise floor", pdev->ch_noise_floor);
8155 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8156 			"Channel TX power", pdev->chan_tx_power);
8157 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8158 			"TX frame count", pdev->tx_frame_count);
8159 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8160 			"RX frame count", pdev->rx_frame_count);
8161 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8162 			"RX clear count", pdev->rx_clear_count);
8163 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8164 			"Cycle count", pdev->cycle_count);
8165 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8166 			"PHY error count", pdev->phy_err_count);
8167 
8168 	*length = len;
8169 }
8170 
8171 static void
8172 ath10k_wmi_fw_pdev_extra_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
8173 				    char *buf, u32 *length)
8174 {
8175 	u32 len = *length;
8176 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8177 
8178 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8179 			"RTS bad count", pdev->rts_bad);
8180 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8181 			"RTS good count", pdev->rts_good);
8182 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8183 			"FCS bad count", pdev->fcs_bad);
8184 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8185 			"No beacon count", pdev->no_beacons);
8186 	len += scnprintf(buf + len, buf_len - len, "%30s %10u\n",
8187 			"MIB int count", pdev->mib_int_count);
8188 
8189 	len += scnprintf(buf + len, buf_len - len, "\n");
8190 	*length = len;
8191 }
8192 
8193 static void
8194 ath10k_wmi_fw_pdev_tx_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
8195 				 char *buf, u32 *length)
8196 {
8197 	u32 len = *length;
8198 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8199 
8200 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
8201 			 "ath10k PDEV TX stats");
8202 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8203 				 "=================");
8204 
8205 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8206 			 "HTT cookies queued", pdev->comp_queued);
8207 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8208 			 "HTT cookies disp.", pdev->comp_delivered);
8209 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8210 			 "MSDU queued", pdev->msdu_enqued);
8211 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8212 			 "MPDU queued", pdev->mpdu_enqued);
8213 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8214 			 "MSDUs dropped", pdev->wmm_drop);
8215 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8216 			 "Local enqued", pdev->local_enqued);
8217 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8218 			 "Local freed", pdev->local_freed);
8219 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8220 			 "HW queued", pdev->hw_queued);
8221 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8222 			 "PPDUs reaped", pdev->hw_reaped);
8223 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8224 			 "Num underruns", pdev->underrun);
8225 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8226 			 "PPDUs cleaned", pdev->tx_abort);
8227 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8228 			 "MPDUs requed", pdev->mpdus_requed);
8229 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8230 			 "Excessive retries", pdev->tx_ko);
8231 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8232 			 "HW rate", pdev->data_rc);
8233 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8234 			 "Sched self triggers", pdev->self_triggers);
8235 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8236 			 "Dropped due to SW retries",
8237 			 pdev->sw_retry_failure);
8238 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8239 			 "Illegal rate phy errors",
8240 			 pdev->illgl_rate_phy_err);
8241 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8242 			 "Pdev continuous xretry", pdev->pdev_cont_xretry);
8243 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8244 			 "TX timeout", pdev->pdev_tx_timeout);
8245 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8246 			 "PDEV resets", pdev->pdev_resets);
8247 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8248 			 "PHY underrun", pdev->phy_underrun);
8249 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8250 			 "MPDU is more than txop limit", pdev->txop_ovf);
8251 	*length = len;
8252 }
8253 
8254 static void
8255 ath10k_wmi_fw_pdev_rx_stats_fill(const struct ath10k_fw_stats_pdev *pdev,
8256 				 char *buf, u32 *length)
8257 {
8258 	u32 len = *length;
8259 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8260 
8261 	len += scnprintf(buf + len, buf_len - len, "\n%30s\n",
8262 			 "ath10k PDEV RX stats");
8263 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8264 				 "=================");
8265 
8266 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8267 			 "Mid PPDU route change",
8268 			 pdev->mid_ppdu_route_change);
8269 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8270 			 "Tot. number of statuses", pdev->status_rcvd);
8271 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8272 			 "Extra frags on rings 0", pdev->r0_frags);
8273 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8274 			 "Extra frags on rings 1", pdev->r1_frags);
8275 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8276 			 "Extra frags on rings 2", pdev->r2_frags);
8277 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8278 			 "Extra frags on rings 3", pdev->r3_frags);
8279 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8280 			 "MSDUs delivered to HTT", pdev->htt_msdus);
8281 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8282 			 "MPDUs delivered to HTT", pdev->htt_mpdus);
8283 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8284 			 "MSDUs delivered to stack", pdev->loc_msdus);
8285 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8286 			 "MPDUs delivered to stack", pdev->loc_mpdus);
8287 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8288 			 "Oversized AMSUs", pdev->oversize_amsdu);
8289 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8290 			 "PHY errors", pdev->phy_errs);
8291 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8292 			 "PHY errors drops", pdev->phy_err_drop);
8293 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8294 			 "MPDU errors (FCS, MIC, ENC)", pdev->mpdu_errs);
8295 	*length = len;
8296 }
8297 
8298 static void
8299 ath10k_wmi_fw_vdev_stats_fill(const struct ath10k_fw_stats_vdev *vdev,
8300 			      char *buf, u32 *length)
8301 {
8302 	u32 len = *length;
8303 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8304 	int i;
8305 
8306 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8307 			"vdev id", vdev->vdev_id);
8308 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8309 			"beacon snr", vdev->beacon_snr);
8310 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8311 			"data snr", vdev->data_snr);
8312 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8313 			"num rx frames", vdev->num_rx_frames);
8314 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8315 			"num rts fail", vdev->num_rts_fail);
8316 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8317 			"num rts success", vdev->num_rts_success);
8318 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8319 			"num rx err", vdev->num_rx_err);
8320 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8321 			"num rx discard", vdev->num_rx_discard);
8322 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8323 			"num tx not acked", vdev->num_tx_not_acked);
8324 
8325 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames); i++)
8326 		len += scnprintf(buf + len, buf_len - len,
8327 				"%25s [%02d] %u\n",
8328 				"num tx frames", i,
8329 				vdev->num_tx_frames[i]);
8330 
8331 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_retries); i++)
8332 		len += scnprintf(buf + len, buf_len - len,
8333 				"%25s [%02d] %u\n",
8334 				"num tx frames retries", i,
8335 				vdev->num_tx_frames_retries[i]);
8336 
8337 	for (i = 0 ; i < ARRAY_SIZE(vdev->num_tx_frames_failures); i++)
8338 		len += scnprintf(buf + len, buf_len - len,
8339 				"%25s [%02d] %u\n",
8340 				"num tx frames failures", i,
8341 				vdev->num_tx_frames_failures[i]);
8342 
8343 	for (i = 0 ; i < ARRAY_SIZE(vdev->tx_rate_history); i++)
8344 		len += scnprintf(buf + len, buf_len - len,
8345 				"%25s [%02d] 0x%08x\n",
8346 				"tx rate history", i,
8347 				vdev->tx_rate_history[i]);
8348 
8349 	for (i = 0 ; i < ARRAY_SIZE(vdev->beacon_rssi_history); i++)
8350 		len += scnprintf(buf + len, buf_len - len,
8351 				"%25s [%02d] %u\n",
8352 				"beacon rssi history", i,
8353 				vdev->beacon_rssi_history[i]);
8354 
8355 	len += scnprintf(buf + len, buf_len - len, "\n");
8356 	*length = len;
8357 }
8358 
8359 static void
8360 ath10k_wmi_fw_peer_stats_fill(const struct ath10k_fw_stats_peer *peer,
8361 			      char *buf, u32 *length, bool extended_peer)
8362 {
8363 	u32 len = *length;
8364 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8365 
8366 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
8367 			"Peer MAC address", peer->peer_macaddr);
8368 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8369 			"Peer RSSI", peer->peer_rssi);
8370 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8371 			"Peer TX rate", peer->peer_tx_rate);
8372 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8373 			"Peer RX rate", peer->peer_rx_rate);
8374 	if (!extended_peer)
8375 		len += scnprintf(buf + len, buf_len - len, "%30s %llu\n",
8376 				"Peer RX duration", peer->rx_duration);
8377 
8378 	len += scnprintf(buf + len, buf_len - len, "\n");
8379 	*length = len;
8380 }
8381 
8382 static void
8383 ath10k_wmi_fw_extd_peer_stats_fill(const struct ath10k_fw_extd_stats_peer *peer,
8384 				   char *buf, u32 *length)
8385 {
8386 	u32 len = *length;
8387 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8388 
8389 	len += scnprintf(buf + len, buf_len - len, "%30s %pM\n",
8390 			"Peer MAC address", peer->peer_macaddr);
8391 	len += scnprintf(buf + len, buf_len - len, "%30s %llu\n",
8392 			"Peer RX duration", peer->rx_duration);
8393 }
8394 
8395 void ath10k_wmi_main_op_fw_stats_fill(struct ath10k *ar,
8396 				      struct ath10k_fw_stats *fw_stats,
8397 				      char *buf)
8398 {
8399 	u32 len = 0;
8400 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8401 	const struct ath10k_fw_stats_pdev *pdev;
8402 	const struct ath10k_fw_stats_vdev *vdev;
8403 	const struct ath10k_fw_stats_peer *peer;
8404 	size_t num_peers;
8405 	size_t num_vdevs;
8406 
8407 	spin_lock_bh(&ar->data_lock);
8408 
8409 	pdev = list_first_entry_or_null(&fw_stats->pdevs,
8410 					struct ath10k_fw_stats_pdev, list);
8411 	if (!pdev) {
8412 		ath10k_warn(ar, "failed to get pdev stats\n");
8413 		goto unlock;
8414 	}
8415 
8416 	num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
8417 	num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
8418 
8419 	ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
8420 	ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
8421 	ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
8422 
8423 	len += scnprintf(buf + len, buf_len - len, "\n");
8424 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
8425 			 "ath10k VDEV stats", num_vdevs);
8426 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8427 				 "=================");
8428 
8429 	list_for_each_entry(vdev, &fw_stats->vdevs, list) {
8430 		ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
8431 	}
8432 
8433 	len += scnprintf(buf + len, buf_len - len, "\n");
8434 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
8435 			 "ath10k PEER stats", num_peers);
8436 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8437 				 "=================");
8438 
8439 	list_for_each_entry(peer, &fw_stats->peers, list) {
8440 		ath10k_wmi_fw_peer_stats_fill(peer, buf, &len,
8441 					      fw_stats->extended);
8442 	}
8443 
8444 unlock:
8445 	spin_unlock_bh(&ar->data_lock);
8446 
8447 	if (len >= buf_len)
8448 		buf[len - 1] = 0;
8449 	else
8450 		buf[len] = 0;
8451 }
8452 
8453 void ath10k_wmi_10x_op_fw_stats_fill(struct ath10k *ar,
8454 				     struct ath10k_fw_stats *fw_stats,
8455 				     char *buf)
8456 {
8457 	unsigned int len = 0;
8458 	unsigned int buf_len = ATH10K_FW_STATS_BUF_SIZE;
8459 	const struct ath10k_fw_stats_pdev *pdev;
8460 	const struct ath10k_fw_stats_vdev *vdev;
8461 	const struct ath10k_fw_stats_peer *peer;
8462 	size_t num_peers;
8463 	size_t num_vdevs;
8464 
8465 	spin_lock_bh(&ar->data_lock);
8466 
8467 	pdev = list_first_entry_or_null(&fw_stats->pdevs,
8468 					struct ath10k_fw_stats_pdev, list);
8469 	if (!pdev) {
8470 		ath10k_warn(ar, "failed to get pdev stats\n");
8471 		goto unlock;
8472 	}
8473 
8474 	num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
8475 	num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
8476 
8477 	ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
8478 	ath10k_wmi_fw_pdev_extra_stats_fill(pdev, buf, &len);
8479 	ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
8480 	ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
8481 
8482 	len += scnprintf(buf + len, buf_len - len, "\n");
8483 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
8484 			 "ath10k VDEV stats", num_vdevs);
8485 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8486 				 "=================");
8487 
8488 	list_for_each_entry(vdev, &fw_stats->vdevs, list) {
8489 		ath10k_wmi_fw_vdev_stats_fill(vdev, buf, &len);
8490 	}
8491 
8492 	len += scnprintf(buf + len, buf_len - len, "\n");
8493 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
8494 			 "ath10k PEER stats", num_peers);
8495 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8496 				 "=================");
8497 
8498 	list_for_each_entry(peer, &fw_stats->peers, list) {
8499 		ath10k_wmi_fw_peer_stats_fill(peer, buf, &len,
8500 					      fw_stats->extended);
8501 	}
8502 
8503 unlock:
8504 	spin_unlock_bh(&ar->data_lock);
8505 
8506 	if (len >= buf_len)
8507 		buf[len - 1] = 0;
8508 	else
8509 		buf[len] = 0;
8510 }
8511 
8512 static struct sk_buff *
8513 ath10k_wmi_op_gen_pdev_enable_adaptive_cca(struct ath10k *ar, u8 enable,
8514 					   u32 detect_level, u32 detect_margin)
8515 {
8516 	struct wmi_pdev_set_adaptive_cca_params *cmd;
8517 	struct sk_buff *skb;
8518 
8519 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8520 	if (!skb)
8521 		return ERR_PTR(-ENOMEM);
8522 
8523 	cmd = (struct wmi_pdev_set_adaptive_cca_params *)skb->data;
8524 	cmd->enable = __cpu_to_le32(enable);
8525 	cmd->cca_detect_level = __cpu_to_le32(detect_level);
8526 	cmd->cca_detect_margin = __cpu_to_le32(detect_margin);
8527 
8528 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8529 		   "wmi pdev set adaptive cca params enable:%d detection level:%d detection margin:%d\n",
8530 		   enable, detect_level, detect_margin);
8531 	return skb;
8532 }
8533 
8534 static void
8535 ath10k_wmi_fw_vdev_stats_extd_fill(const struct ath10k_fw_stats_vdev_extd *vdev,
8536 				   char *buf, u32 *length)
8537 {
8538 	u32 len = *length;
8539 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8540 	u32 val;
8541 
8542 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8543 			 "vdev id", vdev->vdev_id);
8544 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8545 			 "ppdu aggr count", vdev->ppdu_aggr_cnt);
8546 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8547 			 "ppdu noack", vdev->ppdu_noack);
8548 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8549 			 "mpdu queued", vdev->mpdu_queued);
8550 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8551 			 "ppdu nonaggr count", vdev->ppdu_nonaggr_cnt);
8552 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8553 			 "mpdu sw requeued", vdev->mpdu_sw_requeued);
8554 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8555 			 "mpdu success retry", vdev->mpdu_suc_retry);
8556 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8557 			 "mpdu success multitry", vdev->mpdu_suc_multitry);
8558 	len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8559 			 "mpdu fail retry", vdev->mpdu_fail_retry);
8560 	val = vdev->tx_ftm_suc;
8561 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8562 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8563 				 "tx ftm success",
8564 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8565 	val = vdev->tx_ftm_suc_retry;
8566 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8567 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8568 				 "tx ftm success retry",
8569 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8570 	val = vdev->tx_ftm_fail;
8571 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8572 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8573 				 "tx ftm fail",
8574 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8575 	val = vdev->rx_ftmr_cnt;
8576 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8577 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8578 				 "rx ftm request count",
8579 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8580 	val = vdev->rx_ftmr_dup_cnt;
8581 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8582 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8583 				 "rx ftm request dup count",
8584 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8585 	val = vdev->rx_iftmr_cnt;
8586 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8587 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8588 				 "rx initial ftm req count",
8589 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8590 	val = vdev->rx_iftmr_dup_cnt;
8591 	if (val & WMI_VDEV_STATS_FTM_COUNT_VALID)
8592 		len += scnprintf(buf + len, buf_len - len, "%30s %u\n",
8593 				 "rx initial ftm req dup cnt",
8594 				 MS(val, WMI_VDEV_STATS_FTM_COUNT));
8595 	len += scnprintf(buf + len, buf_len - len, "\n");
8596 
8597 	*length = len;
8598 }
8599 
8600 void ath10k_wmi_10_4_op_fw_stats_fill(struct ath10k *ar,
8601 				      struct ath10k_fw_stats *fw_stats,
8602 				      char *buf)
8603 {
8604 	u32 len = 0;
8605 	u32 buf_len = ATH10K_FW_STATS_BUF_SIZE;
8606 	const struct ath10k_fw_stats_pdev *pdev;
8607 	const struct ath10k_fw_stats_vdev_extd *vdev;
8608 	const struct ath10k_fw_stats_peer *peer;
8609 	const struct ath10k_fw_extd_stats_peer *extd_peer;
8610 	size_t num_peers;
8611 	size_t num_vdevs;
8612 
8613 	spin_lock_bh(&ar->data_lock);
8614 
8615 	pdev = list_first_entry_or_null(&fw_stats->pdevs,
8616 					struct ath10k_fw_stats_pdev, list);
8617 	if (!pdev) {
8618 		ath10k_warn(ar, "failed to get pdev stats\n");
8619 		goto unlock;
8620 	}
8621 
8622 	num_peers = ath10k_wmi_fw_stats_num_peers(&fw_stats->peers);
8623 	num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&fw_stats->vdevs);
8624 
8625 	ath10k_wmi_fw_pdev_base_stats_fill(pdev, buf, &len);
8626 	ath10k_wmi_fw_pdev_extra_stats_fill(pdev, buf, &len);
8627 	ath10k_wmi_fw_pdev_tx_stats_fill(pdev, buf, &len);
8628 
8629 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8630 			"HW paused", pdev->hw_paused);
8631 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8632 			"Seqs posted", pdev->seq_posted);
8633 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8634 			"Seqs failed queueing", pdev->seq_failed_queueing);
8635 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8636 			"Seqs completed", pdev->seq_completed);
8637 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8638 			"Seqs restarted", pdev->seq_restarted);
8639 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8640 			"MU Seqs posted", pdev->mu_seq_posted);
8641 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8642 			"MPDUs SW flushed", pdev->mpdus_sw_flush);
8643 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8644 			"MPDUs HW filtered", pdev->mpdus_hw_filter);
8645 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8646 			"MPDUs truncated", pdev->mpdus_truncated);
8647 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8648 			"MPDUs receive no ACK", pdev->mpdus_ack_failed);
8649 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8650 			"MPDUs expired", pdev->mpdus_expired);
8651 
8652 	ath10k_wmi_fw_pdev_rx_stats_fill(pdev, buf, &len);
8653 	len += scnprintf(buf + len, buf_len - len, "%30s %10d\n",
8654 			"Num Rx Overflow errors", pdev->rx_ovfl_errs);
8655 
8656 	len += scnprintf(buf + len, buf_len - len, "\n");
8657 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
8658 			"ath10k VDEV stats", num_vdevs);
8659 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8660 				"=================");
8661 	list_for_each_entry(vdev, &fw_stats->vdevs, list) {
8662 		ath10k_wmi_fw_vdev_stats_extd_fill(vdev, buf, &len);
8663 	}
8664 
8665 	len += scnprintf(buf + len, buf_len - len, "\n");
8666 	len += scnprintf(buf + len, buf_len - len, "%30s (%zu)\n",
8667 			"ath10k PEER stats", num_peers);
8668 	len += scnprintf(buf + len, buf_len - len, "%30s\n\n",
8669 				"=================");
8670 
8671 	list_for_each_entry(peer, &fw_stats->peers, list) {
8672 		ath10k_wmi_fw_peer_stats_fill(peer, buf, &len,
8673 					      fw_stats->extended);
8674 	}
8675 
8676 	if (fw_stats->extended) {
8677 		list_for_each_entry(extd_peer, &fw_stats->peers_extd, list) {
8678 			ath10k_wmi_fw_extd_peer_stats_fill(extd_peer, buf,
8679 							   &len);
8680 		}
8681 	}
8682 
8683 unlock:
8684 	spin_unlock_bh(&ar->data_lock);
8685 
8686 	if (len >= buf_len)
8687 		buf[len - 1] = 0;
8688 	else
8689 		buf[len] = 0;
8690 }
8691 
8692 int ath10k_wmi_op_get_vdev_subtype(struct ath10k *ar,
8693 				   enum wmi_vdev_subtype subtype)
8694 {
8695 	switch (subtype) {
8696 	case WMI_VDEV_SUBTYPE_NONE:
8697 		return WMI_VDEV_SUBTYPE_LEGACY_NONE;
8698 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
8699 		return WMI_VDEV_SUBTYPE_LEGACY_P2P_DEV;
8700 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
8701 		return WMI_VDEV_SUBTYPE_LEGACY_P2P_CLI;
8702 	case WMI_VDEV_SUBTYPE_P2P_GO:
8703 		return WMI_VDEV_SUBTYPE_LEGACY_P2P_GO;
8704 	case WMI_VDEV_SUBTYPE_PROXY_STA:
8705 		return WMI_VDEV_SUBTYPE_LEGACY_PROXY_STA;
8706 	case WMI_VDEV_SUBTYPE_MESH_11S:
8707 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
8708 		return -ENOTSUPP;
8709 	}
8710 	return -ENOTSUPP;
8711 }
8712 
8713 static int ath10k_wmi_10_2_4_op_get_vdev_subtype(struct ath10k *ar,
8714 						 enum wmi_vdev_subtype subtype)
8715 {
8716 	switch (subtype) {
8717 	case WMI_VDEV_SUBTYPE_NONE:
8718 		return WMI_VDEV_SUBTYPE_10_2_4_NONE;
8719 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
8720 		return WMI_VDEV_SUBTYPE_10_2_4_P2P_DEV;
8721 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
8722 		return WMI_VDEV_SUBTYPE_10_2_4_P2P_CLI;
8723 	case WMI_VDEV_SUBTYPE_P2P_GO:
8724 		return WMI_VDEV_SUBTYPE_10_2_4_P2P_GO;
8725 	case WMI_VDEV_SUBTYPE_PROXY_STA:
8726 		return WMI_VDEV_SUBTYPE_10_2_4_PROXY_STA;
8727 	case WMI_VDEV_SUBTYPE_MESH_11S:
8728 		return WMI_VDEV_SUBTYPE_10_2_4_MESH_11S;
8729 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
8730 		return -ENOTSUPP;
8731 	}
8732 	return -ENOTSUPP;
8733 }
8734 
8735 static int ath10k_wmi_10_4_op_get_vdev_subtype(struct ath10k *ar,
8736 					       enum wmi_vdev_subtype subtype)
8737 {
8738 	switch (subtype) {
8739 	case WMI_VDEV_SUBTYPE_NONE:
8740 		return WMI_VDEV_SUBTYPE_10_4_NONE;
8741 	case WMI_VDEV_SUBTYPE_P2P_DEVICE:
8742 		return WMI_VDEV_SUBTYPE_10_4_P2P_DEV;
8743 	case WMI_VDEV_SUBTYPE_P2P_CLIENT:
8744 		return WMI_VDEV_SUBTYPE_10_4_P2P_CLI;
8745 	case WMI_VDEV_SUBTYPE_P2P_GO:
8746 		return WMI_VDEV_SUBTYPE_10_4_P2P_GO;
8747 	case WMI_VDEV_SUBTYPE_PROXY_STA:
8748 		return WMI_VDEV_SUBTYPE_10_4_PROXY_STA;
8749 	case WMI_VDEV_SUBTYPE_MESH_11S:
8750 		return WMI_VDEV_SUBTYPE_10_4_MESH_11S;
8751 	case WMI_VDEV_SUBTYPE_MESH_NON_11S:
8752 		return WMI_VDEV_SUBTYPE_10_4_MESH_NON_11S;
8753 	}
8754 	return -ENOTSUPP;
8755 }
8756 
8757 static struct sk_buff *
8758 ath10k_wmi_10_4_ext_resource_config(struct ath10k *ar,
8759 				    enum wmi_host_platform_type type,
8760 				    u32 fw_feature_bitmap)
8761 {
8762 	struct wmi_ext_resource_config_10_4_cmd *cmd;
8763 	struct sk_buff *skb;
8764 	u32 num_tdls_sleep_sta = 0;
8765 
8766 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8767 	if (!skb)
8768 		return ERR_PTR(-ENOMEM);
8769 
8770 	if (test_bit(WMI_SERVICE_TDLS_UAPSD_SLEEP_STA, ar->wmi.svc_map))
8771 		num_tdls_sleep_sta = TARGET_10_4_NUM_TDLS_SLEEP_STA;
8772 
8773 	cmd = (struct wmi_ext_resource_config_10_4_cmd *)skb->data;
8774 	cmd->host_platform_config = __cpu_to_le32(type);
8775 	cmd->fw_feature_bitmap = __cpu_to_le32(fw_feature_bitmap);
8776 	cmd->wlan_gpio_priority = __cpu_to_le32(-1);
8777 	cmd->coex_version = __cpu_to_le32(WMI_NO_COEX_VERSION_SUPPORT);
8778 	cmd->coex_gpio_pin1 = __cpu_to_le32(-1);
8779 	cmd->coex_gpio_pin2 = __cpu_to_le32(-1);
8780 	cmd->coex_gpio_pin3 = __cpu_to_le32(-1);
8781 	cmd->num_tdls_vdevs = __cpu_to_le32(TARGET_10_4_NUM_TDLS_VDEVS);
8782 	cmd->num_tdls_conn_table_entries = __cpu_to_le32(20);
8783 	cmd->max_tdls_concurrent_sleep_sta = __cpu_to_le32(num_tdls_sleep_sta);
8784 	cmd->max_tdls_concurrent_buffer_sta =
8785 			__cpu_to_le32(TARGET_10_4_NUM_TDLS_BUFFER_STA);
8786 
8787 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8788 		   "wmi ext resource config host type %d firmware feature bitmap %08x\n",
8789 		   type, fw_feature_bitmap);
8790 	return skb;
8791 }
8792 
8793 static struct sk_buff *
8794 ath10k_wmi_10_4_gen_update_fw_tdls_state(struct ath10k *ar, u32 vdev_id,
8795 					 enum wmi_tdls_state state)
8796 {
8797 	struct wmi_10_4_tdls_set_state_cmd *cmd;
8798 	struct sk_buff *skb;
8799 	u32 options = 0;
8800 
8801 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8802 	if (!skb)
8803 		return ERR_PTR(-ENOMEM);
8804 
8805 	if (test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map) &&
8806 	    state == WMI_TDLS_ENABLE_ACTIVE)
8807 		state = WMI_TDLS_ENABLE_PASSIVE;
8808 
8809 	if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8810 		options |= WMI_TDLS_BUFFER_STA_EN;
8811 
8812 	cmd = (struct wmi_10_4_tdls_set_state_cmd *)skb->data;
8813 	cmd->vdev_id = __cpu_to_le32(vdev_id);
8814 	cmd->state = __cpu_to_le32(state);
8815 	cmd->notification_interval_ms = __cpu_to_le32(5000);
8816 	cmd->tx_discovery_threshold = __cpu_to_le32(100);
8817 	cmd->tx_teardown_threshold = __cpu_to_le32(5);
8818 	cmd->rssi_teardown_threshold = __cpu_to_le32(-75);
8819 	cmd->rssi_delta = __cpu_to_le32(-20);
8820 	cmd->tdls_options = __cpu_to_le32(options);
8821 	cmd->tdls_peer_traffic_ind_window = __cpu_to_le32(2);
8822 	cmd->tdls_peer_traffic_response_timeout_ms = __cpu_to_le32(5000);
8823 	cmd->tdls_puapsd_mask = __cpu_to_le32(0xf);
8824 	cmd->tdls_puapsd_inactivity_time_ms = __cpu_to_le32(0);
8825 	cmd->tdls_puapsd_rx_frame_threshold = __cpu_to_le32(10);
8826 	cmd->teardown_notification_ms = __cpu_to_le32(10);
8827 	cmd->tdls_peer_kickout_threshold = __cpu_to_le32(96);
8828 
8829 	ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi update fw tdls state %d for vdev %i\n",
8830 		   state, vdev_id);
8831 	return skb;
8832 }
8833 
8834 static u32 ath10k_wmi_prepare_peer_qos(u8 uapsd_queues, u8 sp)
8835 {
8836 	u32 peer_qos = 0;
8837 
8838 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
8839 		peer_qos |= WMI_TDLS_PEER_QOS_AC_VO;
8840 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
8841 		peer_qos |= WMI_TDLS_PEER_QOS_AC_VI;
8842 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
8843 		peer_qos |= WMI_TDLS_PEER_QOS_AC_BK;
8844 	if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
8845 		peer_qos |= WMI_TDLS_PEER_QOS_AC_BE;
8846 
8847 	peer_qos |= SM(sp, WMI_TDLS_PEER_SP);
8848 
8849 	return peer_qos;
8850 }
8851 
8852 static struct sk_buff *
8853 ath10k_wmi_10_4_op_gen_pdev_get_tpc_table_cmdid(struct ath10k *ar, u32 param)
8854 {
8855 	struct wmi_pdev_get_tpc_table_cmd *cmd;
8856 	struct sk_buff *skb;
8857 
8858 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8859 	if (!skb)
8860 		return ERR_PTR(-ENOMEM);
8861 
8862 	cmd = (struct wmi_pdev_get_tpc_table_cmd *)skb->data;
8863 	cmd->param = __cpu_to_le32(param);
8864 
8865 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8866 		   "wmi pdev get tpc table param:%d\n", param);
8867 	return skb;
8868 }
8869 
8870 static struct sk_buff *
8871 ath10k_wmi_10_4_gen_tdls_peer_update(struct ath10k *ar,
8872 				     const struct wmi_tdls_peer_update_cmd_arg *arg,
8873 				     const struct wmi_tdls_peer_capab_arg *cap,
8874 				     const struct wmi_channel_arg *chan_arg)
8875 {
8876 	struct wmi_10_4_tdls_peer_update_cmd *cmd;
8877 	struct wmi_tdls_peer_capabilities *peer_cap;
8878 	struct wmi_channel *chan;
8879 	struct sk_buff *skb;
8880 	u32 peer_qos;
8881 	int len, chan_len;
8882 	int i;
8883 
8884 	/* tdls peer update cmd has place holder for one channel*/
8885 	chan_len = cap->peer_chan_len ? (cap->peer_chan_len - 1) : 0;
8886 
8887 	len = sizeof(*cmd) + chan_len * sizeof(*chan);
8888 
8889 	skb = ath10k_wmi_alloc_skb(ar, len);
8890 	if (!skb)
8891 		return ERR_PTR(-ENOMEM);
8892 
8893 	memset(skb->data, 0, sizeof(*cmd));
8894 
8895 	cmd = (struct wmi_10_4_tdls_peer_update_cmd *)skb->data;
8896 	cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
8897 	ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
8898 	cmd->peer_state = __cpu_to_le32(arg->peer_state);
8899 
8900 	peer_qos = ath10k_wmi_prepare_peer_qos(cap->peer_uapsd_queues,
8901 					       cap->peer_max_sp);
8902 
8903 	peer_cap = &cmd->peer_capab;
8904 	peer_cap->peer_qos = __cpu_to_le32(peer_qos);
8905 	peer_cap->buff_sta_support = __cpu_to_le32(cap->buff_sta_support);
8906 	peer_cap->off_chan_support = __cpu_to_le32(cap->off_chan_support);
8907 	peer_cap->peer_curr_operclass = __cpu_to_le32(cap->peer_curr_operclass);
8908 	peer_cap->self_curr_operclass = __cpu_to_le32(cap->self_curr_operclass);
8909 	peer_cap->peer_chan_len = __cpu_to_le32(cap->peer_chan_len);
8910 	peer_cap->peer_operclass_len = __cpu_to_le32(cap->peer_operclass_len);
8911 
8912 	for (i = 0; i < WMI_TDLS_MAX_SUPP_OPER_CLASSES; i++)
8913 		peer_cap->peer_operclass[i] = cap->peer_operclass[i];
8914 
8915 	peer_cap->is_peer_responder = __cpu_to_le32(cap->is_peer_responder);
8916 	peer_cap->pref_offchan_num = __cpu_to_le32(cap->pref_offchan_num);
8917 	peer_cap->pref_offchan_bw = __cpu_to_le32(cap->pref_offchan_bw);
8918 
8919 	for (i = 0; i < cap->peer_chan_len; i++) {
8920 		chan = (struct wmi_channel *)&peer_cap->peer_chan_list[i];
8921 		ath10k_wmi_put_wmi_channel(chan, &chan_arg[i]);
8922 	}
8923 
8924 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8925 		   "wmi tdls peer update vdev %i state %d n_chans %u\n",
8926 		   arg->vdev_id, arg->peer_state, cap->peer_chan_len);
8927 	return skb;
8928 }
8929 
8930 static struct sk_buff *
8931 ath10k_wmi_10_4_gen_radar_found(struct ath10k *ar,
8932 				const struct ath10k_radar_found_info *arg)
8933 {
8934 	struct wmi_radar_found_info *cmd;
8935 	struct sk_buff *skb;
8936 
8937 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8938 	if (!skb)
8939 		return ERR_PTR(-ENOMEM);
8940 
8941 	cmd = (struct wmi_radar_found_info *)skb->data;
8942 	cmd->pri_min   = __cpu_to_le32(arg->pri_min);
8943 	cmd->pri_max   = __cpu_to_le32(arg->pri_max);
8944 	cmd->width_min = __cpu_to_le32(arg->width_min);
8945 	cmd->width_max = __cpu_to_le32(arg->width_max);
8946 	cmd->sidx_min  = __cpu_to_le32(arg->sidx_min);
8947 	cmd->sidx_max  = __cpu_to_le32(arg->sidx_max);
8948 
8949 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8950 		   "wmi radar found pri_min %d pri_max %d width_min %d width_max %d sidx_min %d sidx_max %d\n",
8951 		   arg->pri_min, arg->pri_max, arg->width_min,
8952 		   arg->width_max, arg->sidx_min, arg->sidx_max);
8953 	return skb;
8954 }
8955 
8956 static struct sk_buff *
8957 ath10k_wmi_op_gen_echo(struct ath10k *ar, u32 value)
8958 {
8959 	struct wmi_echo_cmd *cmd;
8960 	struct sk_buff *skb;
8961 
8962 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
8963 	if (!skb)
8964 		return ERR_PTR(-ENOMEM);
8965 
8966 	cmd = (struct wmi_echo_cmd *)skb->data;
8967 	cmd->value = cpu_to_le32(value);
8968 
8969 	ath10k_dbg(ar, ATH10K_DBG_WMI,
8970 		   "wmi echo value 0x%08x\n", value);
8971 	return skb;
8972 }
8973 
8974 int
8975 ath10k_wmi_barrier(struct ath10k *ar)
8976 {
8977 	int ret;
8978 	int time_left;
8979 
8980 	spin_lock_bh(&ar->data_lock);
8981 	reinit_completion(&ar->wmi.barrier);
8982 	spin_unlock_bh(&ar->data_lock);
8983 
8984 	ret = ath10k_wmi_echo(ar, ATH10K_WMI_BARRIER_ECHO_ID);
8985 	if (ret) {
8986 		ath10k_warn(ar, "failed to submit wmi echo: %d\n", ret);
8987 		return ret;
8988 	}
8989 
8990 	time_left = wait_for_completion_timeout(&ar->wmi.barrier,
8991 						ATH10K_WMI_BARRIER_TIMEOUT_HZ);
8992 	if (!time_left)
8993 		return -ETIMEDOUT;
8994 
8995 	return 0;
8996 }
8997 
8998 static struct sk_buff *
8999 ath10k_wmi_10_2_4_op_gen_bb_timing(struct ath10k *ar,
9000 				   const struct wmi_bb_timing_cfg_arg *arg)
9001 {
9002 	struct wmi_pdev_bb_timing_cfg_cmd *cmd;
9003 	struct sk_buff *skb;
9004 
9005 	skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
9006 	if (!skb)
9007 		return ERR_PTR(-ENOMEM);
9008 
9009 	cmd = (struct wmi_pdev_bb_timing_cfg_cmd *)skb->data;
9010 	cmd->bb_tx_timing = __cpu_to_le32(arg->bb_tx_timing);
9011 	cmd->bb_xpa_timing = __cpu_to_le32(arg->bb_xpa_timing);
9012 
9013 	ath10k_dbg(ar, ATH10K_DBG_WMI,
9014 		   "wmi pdev bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
9015 		   arg->bb_tx_timing, arg->bb_xpa_timing);
9016 	return skb;
9017 }
9018 
9019 static const struct wmi_ops wmi_ops = {
9020 	.rx = ath10k_wmi_op_rx,
9021 	.map_svc = wmi_main_svc_map,
9022 
9023 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
9024 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
9025 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
9026 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
9027 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
9028 	.pull_swba = ath10k_wmi_op_pull_swba_ev,
9029 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
9030 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
9031 	.pull_svc_rdy = ath10k_wmi_main_op_pull_svc_rdy_ev,
9032 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
9033 	.pull_fw_stats = ath10k_wmi_main_op_pull_fw_stats,
9034 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
9035 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
9036 
9037 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
9038 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
9039 	.gen_pdev_set_rd = ath10k_wmi_op_gen_pdev_set_rd,
9040 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
9041 	.gen_init = ath10k_wmi_op_gen_init,
9042 	.gen_start_scan = ath10k_wmi_op_gen_start_scan,
9043 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
9044 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
9045 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
9046 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
9047 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
9048 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
9049 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
9050 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
9051 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
9052 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
9053 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
9054 	/* .gen_vdev_wmm_conf not implemented */
9055 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
9056 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
9057 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
9058 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
9059 	.gen_peer_assoc = ath10k_wmi_op_gen_peer_assoc,
9060 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
9061 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
9062 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
9063 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
9064 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
9065 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
9066 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
9067 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
9068 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
9069 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
9070 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
9071 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
9072 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
9073 	/* .gen_pdev_get_temperature not implemented */
9074 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
9075 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
9076 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
9077 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
9078 	.fw_stats_fill = ath10k_wmi_main_op_fw_stats_fill,
9079 	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
9080 	.gen_echo = ath10k_wmi_op_gen_echo,
9081 	/* .gen_bcn_tmpl not implemented */
9082 	/* .gen_prb_tmpl not implemented */
9083 	/* .gen_p2p_go_bcn_ie not implemented */
9084 	/* .gen_adaptive_qcs not implemented */
9085 	/* .gen_pdev_enable_adaptive_cca not implemented */
9086 };
9087 
9088 static const struct wmi_ops wmi_10_1_ops = {
9089 	.rx = ath10k_wmi_10_1_op_rx,
9090 	.map_svc = wmi_10x_svc_map,
9091 	.pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
9092 	.pull_fw_stats = ath10k_wmi_10x_op_pull_fw_stats,
9093 	.gen_init = ath10k_wmi_10_1_op_gen_init,
9094 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
9095 	.gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
9096 	.gen_peer_assoc = ath10k_wmi_10_1_op_gen_peer_assoc,
9097 	/* .gen_pdev_get_temperature not implemented */
9098 
9099 	/* shared with main branch */
9100 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
9101 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
9102 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
9103 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
9104 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
9105 	.pull_swba = ath10k_wmi_op_pull_swba_ev,
9106 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
9107 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
9108 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
9109 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
9110 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
9111 
9112 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
9113 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
9114 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
9115 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
9116 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
9117 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
9118 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
9119 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
9120 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
9121 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
9122 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
9123 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
9124 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
9125 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
9126 	/* .gen_vdev_wmm_conf not implemented */
9127 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
9128 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
9129 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
9130 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
9131 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
9132 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
9133 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
9134 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
9135 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
9136 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
9137 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
9138 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
9139 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
9140 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
9141 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
9142 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
9143 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
9144 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
9145 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
9146 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
9147 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
9148 	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
9149 	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
9150 	.gen_echo = ath10k_wmi_op_gen_echo,
9151 	/* .gen_bcn_tmpl not implemented */
9152 	/* .gen_prb_tmpl not implemented */
9153 	/* .gen_p2p_go_bcn_ie not implemented */
9154 	/* .gen_adaptive_qcs not implemented */
9155 	/* .gen_pdev_enable_adaptive_cca not implemented */
9156 };
9157 
9158 static const struct wmi_ops wmi_10_2_ops = {
9159 	.rx = ath10k_wmi_10_2_op_rx,
9160 	.pull_fw_stats = ath10k_wmi_10_2_op_pull_fw_stats,
9161 	.gen_init = ath10k_wmi_10_2_op_gen_init,
9162 	.gen_peer_assoc = ath10k_wmi_10_2_op_gen_peer_assoc,
9163 	/* .gen_pdev_get_temperature not implemented */
9164 
9165 	/* shared with 10.1 */
9166 	.map_svc = wmi_10x_svc_map,
9167 	.pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
9168 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
9169 	.gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
9170 	.gen_echo = ath10k_wmi_op_gen_echo,
9171 
9172 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
9173 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
9174 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
9175 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
9176 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
9177 	.pull_swba = ath10k_wmi_op_pull_swba_ev,
9178 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
9179 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
9180 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
9181 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
9182 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
9183 
9184 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
9185 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
9186 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
9187 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
9188 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
9189 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
9190 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
9191 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
9192 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
9193 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
9194 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
9195 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
9196 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
9197 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
9198 	/* .gen_vdev_wmm_conf not implemented */
9199 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
9200 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
9201 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
9202 	.gen_pdev_set_base_macaddr = ath10k_wmi_op_gen_pdev_set_base_macaddr,
9203 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
9204 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
9205 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
9206 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
9207 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
9208 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
9209 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
9210 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
9211 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
9212 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
9213 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
9214 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
9215 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
9216 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
9217 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
9218 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
9219 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
9220 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
9221 	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
9222 	.get_vdev_subtype = ath10k_wmi_op_get_vdev_subtype,
9223 	/* .gen_pdev_enable_adaptive_cca not implemented */
9224 };
9225 
9226 static const struct wmi_ops wmi_10_2_4_ops = {
9227 	.rx = ath10k_wmi_10_2_op_rx,
9228 	.pull_fw_stats = ath10k_wmi_10_2_4_op_pull_fw_stats,
9229 	.gen_init = ath10k_wmi_10_2_op_gen_init,
9230 	.gen_peer_assoc = ath10k_wmi_10_2_op_gen_peer_assoc,
9231 	.gen_pdev_get_temperature = ath10k_wmi_10_2_op_gen_pdev_get_temperature,
9232 	.gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
9233 
9234 	/* shared with 10.1 */
9235 	.map_svc = wmi_10x_svc_map,
9236 	.pull_svc_rdy = ath10k_wmi_10x_op_pull_svc_rdy_ev,
9237 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
9238 	.gen_start_scan = ath10k_wmi_10x_op_gen_start_scan,
9239 	.gen_echo = ath10k_wmi_op_gen_echo,
9240 
9241 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
9242 	.pull_mgmt_rx = ath10k_wmi_op_pull_mgmt_rx_ev,
9243 	.pull_ch_info = ath10k_wmi_op_pull_ch_info_ev,
9244 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
9245 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
9246 	.pull_swba = ath10k_wmi_10_2_4_op_pull_swba_ev,
9247 	.pull_phyerr_hdr = ath10k_wmi_op_pull_phyerr_ev_hdr,
9248 	.pull_phyerr = ath10k_wmi_op_pull_phyerr_ev,
9249 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
9250 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
9251 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
9252 
9253 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
9254 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
9255 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
9256 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
9257 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
9258 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
9259 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
9260 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
9261 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
9262 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
9263 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
9264 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
9265 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
9266 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
9267 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
9268 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
9269 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
9270 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
9271 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
9272 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
9273 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
9274 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
9275 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
9276 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
9277 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
9278 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
9279 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
9280 	.gen_dbglog_cfg = ath10k_wmi_op_gen_dbglog_cfg,
9281 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
9282 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
9283 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
9284 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
9285 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
9286 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
9287 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
9288 	.gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
9289 	.fw_stats_fill = ath10k_wmi_10x_op_fw_stats_fill,
9290 	.gen_pdev_enable_adaptive_cca =
9291 		ath10k_wmi_op_gen_pdev_enable_adaptive_cca,
9292 	.get_vdev_subtype = ath10k_wmi_10_2_4_op_get_vdev_subtype,
9293 	.gen_bb_timing = ath10k_wmi_10_2_4_op_gen_bb_timing,
9294 	/* .gen_bcn_tmpl not implemented */
9295 	/* .gen_prb_tmpl not implemented */
9296 	/* .gen_p2p_go_bcn_ie not implemented */
9297 	/* .gen_adaptive_qcs not implemented */
9298 };
9299 
9300 static const struct wmi_ops wmi_10_4_ops = {
9301 	.rx = ath10k_wmi_10_4_op_rx,
9302 	.map_svc = wmi_10_4_svc_map,
9303 
9304 	.pull_fw_stats = ath10k_wmi_10_4_op_pull_fw_stats,
9305 	.pull_scan = ath10k_wmi_op_pull_scan_ev,
9306 	.pull_mgmt_rx = ath10k_wmi_10_4_op_pull_mgmt_rx_ev,
9307 	.pull_ch_info = ath10k_wmi_10_4_op_pull_ch_info_ev,
9308 	.pull_vdev_start = ath10k_wmi_op_pull_vdev_start_ev,
9309 	.pull_peer_kick = ath10k_wmi_op_pull_peer_kick_ev,
9310 	.pull_swba = ath10k_wmi_10_4_op_pull_swba_ev,
9311 	.pull_phyerr_hdr = ath10k_wmi_10_4_op_pull_phyerr_ev_hdr,
9312 	.pull_phyerr = ath10k_wmi_10_4_op_pull_phyerr_ev,
9313 	.pull_svc_rdy = ath10k_wmi_main_op_pull_svc_rdy_ev,
9314 	.pull_rdy = ath10k_wmi_op_pull_rdy_ev,
9315 	.pull_roam_ev = ath10k_wmi_op_pull_roam_ev,
9316 	.pull_dfs_status_ev = ath10k_wmi_10_4_op_pull_dfs_status_ev,
9317 	.get_txbf_conf_scheme = ath10k_wmi_10_4_txbf_conf_scheme,
9318 
9319 	.gen_pdev_suspend = ath10k_wmi_op_gen_pdev_suspend,
9320 	.gen_pdev_resume = ath10k_wmi_op_gen_pdev_resume,
9321 	.gen_pdev_set_base_macaddr = ath10k_wmi_op_gen_pdev_set_base_macaddr,
9322 	.gen_pdev_set_rd = ath10k_wmi_10x_op_gen_pdev_set_rd,
9323 	.gen_pdev_set_param = ath10k_wmi_op_gen_pdev_set_param,
9324 	.gen_init = ath10k_wmi_10_4_op_gen_init,
9325 	.gen_start_scan = ath10k_wmi_op_gen_start_scan,
9326 	.gen_stop_scan = ath10k_wmi_op_gen_stop_scan,
9327 	.gen_vdev_create = ath10k_wmi_op_gen_vdev_create,
9328 	.gen_vdev_delete = ath10k_wmi_op_gen_vdev_delete,
9329 	.gen_vdev_start = ath10k_wmi_op_gen_vdev_start,
9330 	.gen_vdev_stop = ath10k_wmi_op_gen_vdev_stop,
9331 	.gen_vdev_up = ath10k_wmi_op_gen_vdev_up,
9332 	.gen_vdev_down = ath10k_wmi_op_gen_vdev_down,
9333 	.gen_vdev_set_param = ath10k_wmi_op_gen_vdev_set_param,
9334 	.gen_vdev_install_key = ath10k_wmi_op_gen_vdev_install_key,
9335 	.gen_vdev_spectral_conf = ath10k_wmi_op_gen_vdev_spectral_conf,
9336 	.gen_vdev_spectral_enable = ath10k_wmi_op_gen_vdev_spectral_enable,
9337 	.gen_peer_create = ath10k_wmi_op_gen_peer_create,
9338 	.gen_peer_delete = ath10k_wmi_op_gen_peer_delete,
9339 	.gen_peer_flush = ath10k_wmi_op_gen_peer_flush,
9340 	.gen_peer_set_param = ath10k_wmi_op_gen_peer_set_param,
9341 	.gen_peer_assoc = ath10k_wmi_10_4_op_gen_peer_assoc,
9342 	.gen_set_psmode = ath10k_wmi_op_gen_set_psmode,
9343 	.gen_set_sta_ps = ath10k_wmi_op_gen_set_sta_ps,
9344 	.gen_set_ap_ps = ath10k_wmi_op_gen_set_ap_ps,
9345 	.gen_scan_chan_list = ath10k_wmi_op_gen_scan_chan_list,
9346 	.gen_beacon_dma = ath10k_wmi_op_gen_beacon_dma,
9347 	.gen_pdev_set_wmm = ath10k_wmi_op_gen_pdev_set_wmm,
9348 	.gen_force_fw_hang = ath10k_wmi_op_gen_force_fw_hang,
9349 	.gen_mgmt_tx = ath10k_wmi_op_gen_mgmt_tx,
9350 	.gen_dbglog_cfg = ath10k_wmi_10_4_op_gen_dbglog_cfg,
9351 	.gen_pktlog_enable = ath10k_wmi_op_gen_pktlog_enable,
9352 	.gen_pktlog_disable = ath10k_wmi_op_gen_pktlog_disable,
9353 	.gen_pdev_set_quiet_mode = ath10k_wmi_op_gen_pdev_set_quiet_mode,
9354 	.gen_addba_clear_resp = ath10k_wmi_op_gen_addba_clear_resp,
9355 	.gen_addba_send = ath10k_wmi_op_gen_addba_send,
9356 	.gen_addba_set_resp = ath10k_wmi_op_gen_addba_set_resp,
9357 	.gen_delba_send = ath10k_wmi_op_gen_delba_send,
9358 	.fw_stats_fill = ath10k_wmi_10_4_op_fw_stats_fill,
9359 	.ext_resource_config = ath10k_wmi_10_4_ext_resource_config,
9360 	.gen_update_fw_tdls_state = ath10k_wmi_10_4_gen_update_fw_tdls_state,
9361 	.gen_tdls_peer_update = ath10k_wmi_10_4_gen_tdls_peer_update,
9362 	.gen_pdev_get_tpc_table_cmdid =
9363 			ath10k_wmi_10_4_op_gen_pdev_get_tpc_table_cmdid,
9364 	.gen_radar_found = ath10k_wmi_10_4_gen_radar_found,
9365 
9366 	/* shared with 10.2 */
9367 	.pull_echo_ev = ath10k_wmi_op_pull_echo_ev,
9368 	.gen_request_stats = ath10k_wmi_op_gen_request_stats,
9369 	.gen_pdev_get_temperature = ath10k_wmi_10_2_op_gen_pdev_get_temperature,
9370 	.get_vdev_subtype = ath10k_wmi_10_4_op_get_vdev_subtype,
9371 	.gen_pdev_bss_chan_info_req = ath10k_wmi_10_2_op_gen_pdev_bss_chan_info,
9372 	.gen_echo = ath10k_wmi_op_gen_echo,
9373 	.gen_pdev_get_tpc_config = ath10k_wmi_10_2_4_op_gen_pdev_get_tpc_config,
9374 };
9375 
9376 int ath10k_wmi_attach(struct ath10k *ar)
9377 {
9378 	switch (ar->running_fw->fw_file.wmi_op_version) {
9379 	case ATH10K_FW_WMI_OP_VERSION_10_4:
9380 		ar->wmi.ops = &wmi_10_4_ops;
9381 		ar->wmi.cmd = &wmi_10_4_cmd_map;
9382 		ar->wmi.vdev_param = &wmi_10_4_vdev_param_map;
9383 		ar->wmi.pdev_param = &wmi_10_4_pdev_param_map;
9384 		ar->wmi.peer_param = &wmi_peer_param_map;
9385 		ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
9386 		ar->wmi_key_cipher = wmi_key_cipher_suites;
9387 		break;
9388 	case ATH10K_FW_WMI_OP_VERSION_10_2_4:
9389 		ar->wmi.cmd = &wmi_10_2_4_cmd_map;
9390 		ar->wmi.ops = &wmi_10_2_4_ops;
9391 		ar->wmi.vdev_param = &wmi_10_2_4_vdev_param_map;
9392 		ar->wmi.pdev_param = &wmi_10_2_4_pdev_param_map;
9393 		ar->wmi.peer_param = &wmi_peer_param_map;
9394 		ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
9395 		ar->wmi_key_cipher = wmi_key_cipher_suites;
9396 		break;
9397 	case ATH10K_FW_WMI_OP_VERSION_10_2:
9398 		ar->wmi.cmd = &wmi_10_2_cmd_map;
9399 		ar->wmi.ops = &wmi_10_2_ops;
9400 		ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
9401 		ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
9402 		ar->wmi.peer_param = &wmi_peer_param_map;
9403 		ar->wmi.peer_flags = &wmi_10_2_peer_flags_map;
9404 		ar->wmi_key_cipher = wmi_key_cipher_suites;
9405 		break;
9406 	case ATH10K_FW_WMI_OP_VERSION_10_1:
9407 		ar->wmi.cmd = &wmi_10x_cmd_map;
9408 		ar->wmi.ops = &wmi_10_1_ops;
9409 		ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
9410 		ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
9411 		ar->wmi.peer_param = &wmi_peer_param_map;
9412 		ar->wmi.peer_flags = &wmi_10x_peer_flags_map;
9413 		ar->wmi_key_cipher = wmi_key_cipher_suites;
9414 		break;
9415 	case ATH10K_FW_WMI_OP_VERSION_MAIN:
9416 		ar->wmi.cmd = &wmi_cmd_map;
9417 		ar->wmi.ops = &wmi_ops;
9418 		ar->wmi.vdev_param = &wmi_vdev_param_map;
9419 		ar->wmi.pdev_param = &wmi_pdev_param_map;
9420 		ar->wmi.peer_param = &wmi_peer_param_map;
9421 		ar->wmi.peer_flags = &wmi_peer_flags_map;
9422 		ar->wmi_key_cipher = wmi_key_cipher_suites;
9423 		break;
9424 	case ATH10K_FW_WMI_OP_VERSION_TLV:
9425 		ath10k_wmi_tlv_attach(ar);
9426 		ar->wmi_key_cipher = wmi_tlv_key_cipher_suites;
9427 		break;
9428 	case ATH10K_FW_WMI_OP_VERSION_UNSET:
9429 	case ATH10K_FW_WMI_OP_VERSION_MAX:
9430 		ath10k_err(ar, "unsupported WMI op version: %d\n",
9431 			   ar->running_fw->fw_file.wmi_op_version);
9432 		return -EINVAL;
9433 	}
9434 
9435 	init_completion(&ar->wmi.service_ready);
9436 	init_completion(&ar->wmi.unified_ready);
9437 	init_completion(&ar->wmi.barrier);
9438 	init_completion(&ar->wmi.radar_confirm);
9439 
9440 	INIT_WORK(&ar->svc_rdy_work, ath10k_wmi_event_service_ready_work);
9441 	INIT_WORK(&ar->radar_confirmation_work,
9442 		  ath10k_radar_confirmation_work);
9443 
9444 	if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
9445 		     ar->running_fw->fw_file.fw_features)) {
9446 		idr_init(&ar->wmi.mgmt_pending_tx);
9447 	}
9448 
9449 	return 0;
9450 }
9451 
9452 void ath10k_wmi_free_host_mem(struct ath10k *ar)
9453 {
9454 	int i;
9455 
9456 	/* free the host memory chunks requested by firmware */
9457 	for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
9458 		dma_free_coherent(ar->dev,
9459 				  ar->wmi.mem_chunks[i].len,
9460 				  ar->wmi.mem_chunks[i].vaddr,
9461 				  ar->wmi.mem_chunks[i].paddr);
9462 	}
9463 
9464 	ar->wmi.num_mem_chunks = 0;
9465 }
9466 
9467 static int ath10k_wmi_mgmt_tx_clean_up_pending(int msdu_id, void *ptr,
9468 					       void *ctx)
9469 {
9470 	struct ath10k_mgmt_tx_pkt_addr *pkt_addr = ptr;
9471 	struct ath10k *ar = ctx;
9472 	struct sk_buff *msdu;
9473 
9474 	ath10k_dbg(ar, ATH10K_DBG_WMI,
9475 		   "force cleanup mgmt msdu_id %hu\n", msdu_id);
9476 
9477 	msdu = pkt_addr->vaddr;
9478 	dma_unmap_single(ar->dev, pkt_addr->paddr,
9479 			 msdu->len, DMA_FROM_DEVICE);
9480 	ieee80211_free_txskb(ar->hw, msdu);
9481 
9482 	return 0;
9483 }
9484 
9485 void ath10k_wmi_detach(struct ath10k *ar)
9486 {
9487 	if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
9488 		     ar->running_fw->fw_file.fw_features)) {
9489 		spin_lock_bh(&ar->data_lock);
9490 		idr_for_each(&ar->wmi.mgmt_pending_tx,
9491 			     ath10k_wmi_mgmt_tx_clean_up_pending, ar);
9492 		idr_destroy(&ar->wmi.mgmt_pending_tx);
9493 		spin_unlock_bh(&ar->data_lock);
9494 	}
9495 
9496 	cancel_work_sync(&ar->svc_rdy_work);
9497 	dev_kfree_skb(ar->svc_rdy_skb);
9498 }
9499