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