ath10k: fix tx/rx chainmask init
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / ath / ath10k / wmi.c
1 /*
2  * Copyright (c) 2005-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 #include <linux/skbuff.h>
19 #include <linux/ctype.h>
20
21 #include "core.h"
22 #include "htc.h"
23 #include "debug.h"
24 #include "wmi.h"
25 #include "mac.h"
26 #include "testmode.h"
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         .pdev_set_regdomain_cmdid = WMI_PDEV_SET_REGDOMAIN_CMDID,
36         .pdev_set_channel_cmdid = WMI_PDEV_SET_CHANNEL_CMDID,
37         .pdev_set_param_cmdid = WMI_PDEV_SET_PARAM_CMDID,
38         .pdev_pktlog_enable_cmdid = WMI_PDEV_PKTLOG_ENABLE_CMDID,
39         .pdev_pktlog_disable_cmdid = WMI_PDEV_PKTLOG_DISABLE_CMDID,
40         .pdev_set_wmm_params_cmdid = WMI_PDEV_SET_WMM_PARAMS_CMDID,
41         .pdev_set_ht_cap_ie_cmdid = WMI_PDEV_SET_HT_CAP_IE_CMDID,
42         .pdev_set_vht_cap_ie_cmdid = WMI_PDEV_SET_VHT_CAP_IE_CMDID,
43         .pdev_set_dscp_tid_map_cmdid = WMI_PDEV_SET_DSCP_TID_MAP_CMDID,
44         .pdev_set_quiet_mode_cmdid = WMI_PDEV_SET_QUIET_MODE_CMDID,
45         .pdev_green_ap_ps_enable_cmdid = WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID,
46         .pdev_get_tpc_config_cmdid = WMI_PDEV_GET_TPC_CONFIG_CMDID,
47         .pdev_set_base_macaddr_cmdid = WMI_PDEV_SET_BASE_MACADDR_CMDID,
48         .vdev_create_cmdid = WMI_VDEV_CREATE_CMDID,
49         .vdev_delete_cmdid = WMI_VDEV_DELETE_CMDID,
50         .vdev_start_request_cmdid = WMI_VDEV_START_REQUEST_CMDID,
51         .vdev_restart_request_cmdid = WMI_VDEV_RESTART_REQUEST_CMDID,
52         .vdev_up_cmdid = WMI_VDEV_UP_CMDID,
53         .vdev_stop_cmdid = WMI_VDEV_STOP_CMDID,
54         .vdev_down_cmdid = WMI_VDEV_DOWN_CMDID,
55         .vdev_set_param_cmdid = WMI_VDEV_SET_PARAM_CMDID,
56         .vdev_install_key_cmdid = WMI_VDEV_INSTALL_KEY_CMDID,
57         .peer_create_cmdid = WMI_PEER_CREATE_CMDID,
58         .peer_delete_cmdid = WMI_PEER_DELETE_CMDID,
59         .peer_flush_tids_cmdid = WMI_PEER_FLUSH_TIDS_CMDID,
60         .peer_set_param_cmdid = WMI_PEER_SET_PARAM_CMDID,
61         .peer_assoc_cmdid = WMI_PEER_ASSOC_CMDID,
62         .peer_add_wds_entry_cmdid = WMI_PEER_ADD_WDS_ENTRY_CMDID,
63         .peer_remove_wds_entry_cmdid = WMI_PEER_REMOVE_WDS_ENTRY_CMDID,
64         .peer_mcast_group_cmdid = WMI_PEER_MCAST_GROUP_CMDID,
65         .bcn_tx_cmdid = WMI_BCN_TX_CMDID,
66         .pdev_send_bcn_cmdid = WMI_PDEV_SEND_BCN_CMDID,
67         .bcn_tmpl_cmdid = WMI_BCN_TMPL_CMDID,
68         .bcn_filter_rx_cmdid = WMI_BCN_FILTER_RX_CMDID,
69         .prb_req_filter_rx_cmdid = WMI_PRB_REQ_FILTER_RX_CMDID,
70         .mgmt_tx_cmdid = WMI_MGMT_TX_CMDID,
71         .prb_tmpl_cmdid = WMI_PRB_TMPL_CMDID,
72         .addba_clear_resp_cmdid = WMI_ADDBA_CLEAR_RESP_CMDID,
73         .addba_send_cmdid = WMI_ADDBA_SEND_CMDID,
74         .addba_status_cmdid = WMI_ADDBA_STATUS_CMDID,
75         .delba_send_cmdid = WMI_DELBA_SEND_CMDID,
76         .addba_set_resp_cmdid = WMI_ADDBA_SET_RESP_CMDID,
77         .send_singleamsdu_cmdid = WMI_SEND_SINGLEAMSDU_CMDID,
78         .sta_powersave_mode_cmdid = WMI_STA_POWERSAVE_MODE_CMDID,
79         .sta_powersave_param_cmdid = WMI_STA_POWERSAVE_PARAM_CMDID,
80         .sta_mimo_ps_mode_cmdid = WMI_STA_MIMO_PS_MODE_CMDID,
81         .pdev_dfs_enable_cmdid = WMI_PDEV_DFS_ENABLE_CMDID,
82         .pdev_dfs_disable_cmdid = WMI_PDEV_DFS_DISABLE_CMDID,
83         .roam_scan_mode = WMI_ROAM_SCAN_MODE,
84         .roam_scan_rssi_threshold = WMI_ROAM_SCAN_RSSI_THRESHOLD,
85         .roam_scan_period = WMI_ROAM_SCAN_PERIOD,
86         .roam_scan_rssi_change_threshold = WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
87         .roam_ap_profile = WMI_ROAM_AP_PROFILE,
88         .ofl_scan_add_ap_profile = WMI_ROAM_AP_PROFILE,
89         .ofl_scan_remove_ap_profile = WMI_OFL_SCAN_REMOVE_AP_PROFILE,
90         .ofl_scan_period = WMI_OFL_SCAN_PERIOD,
91         .p2p_dev_set_device_info = WMI_P2P_DEV_SET_DEVICE_INFO,
92         .p2p_dev_set_discoverability = WMI_P2P_DEV_SET_DISCOVERABILITY,
93         .p2p_go_set_beacon_ie = WMI_P2P_GO_SET_BEACON_IE,
94         .p2p_go_set_probe_resp_ie = WMI_P2P_GO_SET_PROBE_RESP_IE,
95         .p2p_set_vendor_ie_data_cmdid = WMI_P2P_SET_VENDOR_IE_DATA_CMDID,
96         .ap_ps_peer_param_cmdid = WMI_AP_PS_PEER_PARAM_CMDID,
97         .ap_ps_peer_uapsd_coex_cmdid = WMI_AP_PS_PEER_UAPSD_COEX_CMDID,
98         .peer_rate_retry_sched_cmdid = WMI_PEER_RATE_RETRY_SCHED_CMDID,
99         .wlan_profile_trigger_cmdid = WMI_WLAN_PROFILE_TRIGGER_CMDID,
100         .wlan_profile_set_hist_intvl_cmdid =
101                                 WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
102         .wlan_profile_get_profile_data_cmdid =
103                                 WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
104         .wlan_profile_enable_profile_id_cmdid =
105                                 WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
106         .wlan_profile_list_profile_id_cmdid =
107                                 WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
108         .pdev_suspend_cmdid = WMI_PDEV_SUSPEND_CMDID,
109         .pdev_resume_cmdid = WMI_PDEV_RESUME_CMDID,
110         .add_bcn_filter_cmdid = WMI_ADD_BCN_FILTER_CMDID,
111         .rmv_bcn_filter_cmdid = WMI_RMV_BCN_FILTER_CMDID,
112         .wow_add_wake_pattern_cmdid = WMI_WOW_ADD_WAKE_PATTERN_CMDID,
113         .wow_del_wake_pattern_cmdid = WMI_WOW_DEL_WAKE_PATTERN_CMDID,
114         .wow_enable_disable_wake_event_cmdid =
115                                 WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
116         .wow_enable_cmdid = WMI_WOW_ENABLE_CMDID,
117         .wow_hostwakeup_from_sleep_cmdid = WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
118         .rtt_measreq_cmdid = WMI_RTT_MEASREQ_CMDID,
119         .rtt_tsf_cmdid = WMI_RTT_TSF_CMDID,
120         .vdev_spectral_scan_configure_cmdid =
121                                 WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
122         .vdev_spectral_scan_enable_cmdid = WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
123         .request_stats_cmdid = WMI_REQUEST_STATS_CMDID,
124         .set_arp_ns_offload_cmdid = WMI_SET_ARP_NS_OFFLOAD_CMDID,
125         .network_list_offload_config_cmdid =
126                                 WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
127         .gtk_offload_cmdid = WMI_GTK_OFFLOAD_CMDID,
128         .csa_offload_enable_cmdid = WMI_CSA_OFFLOAD_ENABLE_CMDID,
129         .csa_offload_chanswitch_cmdid = WMI_CSA_OFFLOAD_CHANSWITCH_CMDID,
130         .chatter_set_mode_cmdid = WMI_CHATTER_SET_MODE_CMDID,
131         .peer_tid_addba_cmdid = WMI_PEER_TID_ADDBA_CMDID,
132         .peer_tid_delba_cmdid = WMI_PEER_TID_DELBA_CMDID,
133         .sta_dtim_ps_method_cmdid = WMI_STA_DTIM_PS_METHOD_CMDID,
134         .sta_uapsd_auto_trig_cmdid = WMI_STA_UAPSD_AUTO_TRIG_CMDID,
135         .sta_keepalive_cmd = WMI_STA_KEEPALIVE_CMD,
136         .echo_cmdid = WMI_ECHO_CMDID,
137         .pdev_utf_cmdid = WMI_PDEV_UTF_CMDID,
138         .dbglog_cfg_cmdid = WMI_DBGLOG_CFG_CMDID,
139         .pdev_qvit_cmdid = WMI_PDEV_QVIT_CMDID,
140         .pdev_ftm_intg_cmdid = WMI_PDEV_FTM_INTG_CMDID,
141         .vdev_set_keepalive_cmdid = WMI_VDEV_SET_KEEPALIVE_CMDID,
142         .vdev_get_keepalive_cmdid = WMI_VDEV_GET_KEEPALIVE_CMDID,
143         .force_fw_hang_cmdid = WMI_FORCE_FW_HANG_CMDID,
144         .gpio_config_cmdid = WMI_GPIO_CONFIG_CMDID,
145         .gpio_output_cmdid = WMI_GPIO_OUTPUT_CMDID,
146 };
147
148 /* 10.X WMI cmd track */
149 static struct wmi_cmd_map wmi_10x_cmd_map = {
150         .init_cmdid = WMI_10X_INIT_CMDID,
151         .start_scan_cmdid = WMI_10X_START_SCAN_CMDID,
152         .stop_scan_cmdid = WMI_10X_STOP_SCAN_CMDID,
153         .scan_chan_list_cmdid = WMI_10X_SCAN_CHAN_LIST_CMDID,
154         .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
155         .pdev_set_regdomain_cmdid = WMI_10X_PDEV_SET_REGDOMAIN_CMDID,
156         .pdev_set_channel_cmdid = WMI_10X_PDEV_SET_CHANNEL_CMDID,
157         .pdev_set_param_cmdid = WMI_10X_PDEV_SET_PARAM_CMDID,
158         .pdev_pktlog_enable_cmdid = WMI_10X_PDEV_PKTLOG_ENABLE_CMDID,
159         .pdev_pktlog_disable_cmdid = WMI_10X_PDEV_PKTLOG_DISABLE_CMDID,
160         .pdev_set_wmm_params_cmdid = WMI_10X_PDEV_SET_WMM_PARAMS_CMDID,
161         .pdev_set_ht_cap_ie_cmdid = WMI_10X_PDEV_SET_HT_CAP_IE_CMDID,
162         .pdev_set_vht_cap_ie_cmdid = WMI_10X_PDEV_SET_VHT_CAP_IE_CMDID,
163         .pdev_set_dscp_tid_map_cmdid = WMI_10X_PDEV_SET_DSCP_TID_MAP_CMDID,
164         .pdev_set_quiet_mode_cmdid = WMI_10X_PDEV_SET_QUIET_MODE_CMDID,
165         .pdev_green_ap_ps_enable_cmdid = WMI_10X_PDEV_GREEN_AP_PS_ENABLE_CMDID,
166         .pdev_get_tpc_config_cmdid = WMI_10X_PDEV_GET_TPC_CONFIG_CMDID,
167         .pdev_set_base_macaddr_cmdid = WMI_10X_PDEV_SET_BASE_MACADDR_CMDID,
168         .vdev_create_cmdid = WMI_10X_VDEV_CREATE_CMDID,
169         .vdev_delete_cmdid = WMI_10X_VDEV_DELETE_CMDID,
170         .vdev_start_request_cmdid = WMI_10X_VDEV_START_REQUEST_CMDID,
171         .vdev_restart_request_cmdid = WMI_10X_VDEV_RESTART_REQUEST_CMDID,
172         .vdev_up_cmdid = WMI_10X_VDEV_UP_CMDID,
173         .vdev_stop_cmdid = WMI_10X_VDEV_STOP_CMDID,
174         .vdev_down_cmdid = WMI_10X_VDEV_DOWN_CMDID,
175         .vdev_set_param_cmdid = WMI_10X_VDEV_SET_PARAM_CMDID,
176         .vdev_install_key_cmdid = WMI_10X_VDEV_INSTALL_KEY_CMDID,
177         .peer_create_cmdid = WMI_10X_PEER_CREATE_CMDID,
178         .peer_delete_cmdid = WMI_10X_PEER_DELETE_CMDID,
179         .peer_flush_tids_cmdid = WMI_10X_PEER_FLUSH_TIDS_CMDID,
180         .peer_set_param_cmdid = WMI_10X_PEER_SET_PARAM_CMDID,
181         .peer_assoc_cmdid = WMI_10X_PEER_ASSOC_CMDID,
182         .peer_add_wds_entry_cmdid = WMI_10X_PEER_ADD_WDS_ENTRY_CMDID,
183         .peer_remove_wds_entry_cmdid = WMI_10X_PEER_REMOVE_WDS_ENTRY_CMDID,
184         .peer_mcast_group_cmdid = WMI_10X_PEER_MCAST_GROUP_CMDID,
185         .bcn_tx_cmdid = WMI_10X_BCN_TX_CMDID,
186         .pdev_send_bcn_cmdid = WMI_10X_PDEV_SEND_BCN_CMDID,
187         .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
188         .bcn_filter_rx_cmdid = WMI_10X_BCN_FILTER_RX_CMDID,
189         .prb_req_filter_rx_cmdid = WMI_10X_PRB_REQ_FILTER_RX_CMDID,
190         .mgmt_tx_cmdid = WMI_10X_MGMT_TX_CMDID,
191         .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
192         .addba_clear_resp_cmdid = WMI_10X_ADDBA_CLEAR_RESP_CMDID,
193         .addba_send_cmdid = WMI_10X_ADDBA_SEND_CMDID,
194         .addba_status_cmdid = WMI_10X_ADDBA_STATUS_CMDID,
195         .delba_send_cmdid = WMI_10X_DELBA_SEND_CMDID,
196         .addba_set_resp_cmdid = WMI_10X_ADDBA_SET_RESP_CMDID,
197         .send_singleamsdu_cmdid = WMI_10X_SEND_SINGLEAMSDU_CMDID,
198         .sta_powersave_mode_cmdid = WMI_10X_STA_POWERSAVE_MODE_CMDID,
199         .sta_powersave_param_cmdid = WMI_10X_STA_POWERSAVE_PARAM_CMDID,
200         .sta_mimo_ps_mode_cmdid = WMI_10X_STA_MIMO_PS_MODE_CMDID,
201         .pdev_dfs_enable_cmdid = WMI_10X_PDEV_DFS_ENABLE_CMDID,
202         .pdev_dfs_disable_cmdid = WMI_10X_PDEV_DFS_DISABLE_CMDID,
203         .roam_scan_mode = WMI_10X_ROAM_SCAN_MODE,
204         .roam_scan_rssi_threshold = WMI_10X_ROAM_SCAN_RSSI_THRESHOLD,
205         .roam_scan_period = WMI_10X_ROAM_SCAN_PERIOD,
206         .roam_scan_rssi_change_threshold =
207                                 WMI_10X_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
208         .roam_ap_profile = WMI_10X_ROAM_AP_PROFILE,
209         .ofl_scan_add_ap_profile = WMI_10X_OFL_SCAN_ADD_AP_PROFILE,
210         .ofl_scan_remove_ap_profile = WMI_10X_OFL_SCAN_REMOVE_AP_PROFILE,
211         .ofl_scan_period = WMI_10X_OFL_SCAN_PERIOD,
212         .p2p_dev_set_device_info = WMI_10X_P2P_DEV_SET_DEVICE_INFO,
213         .p2p_dev_set_discoverability = WMI_10X_P2P_DEV_SET_DISCOVERABILITY,
214         .p2p_go_set_beacon_ie = WMI_10X_P2P_GO_SET_BEACON_IE,
215         .p2p_go_set_probe_resp_ie = WMI_10X_P2P_GO_SET_PROBE_RESP_IE,
216         .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
217         .ap_ps_peer_param_cmdid = WMI_10X_AP_PS_PEER_PARAM_CMDID,
218         .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
219         .peer_rate_retry_sched_cmdid = WMI_10X_PEER_RATE_RETRY_SCHED_CMDID,
220         .wlan_profile_trigger_cmdid = WMI_10X_WLAN_PROFILE_TRIGGER_CMDID,
221         .wlan_profile_set_hist_intvl_cmdid =
222                                 WMI_10X_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
223         .wlan_profile_get_profile_data_cmdid =
224                                 WMI_10X_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
225         .wlan_profile_enable_profile_id_cmdid =
226                                 WMI_10X_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
227         .wlan_profile_list_profile_id_cmdid =
228                                 WMI_10X_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
229         .pdev_suspend_cmdid = WMI_10X_PDEV_SUSPEND_CMDID,
230         .pdev_resume_cmdid = WMI_10X_PDEV_RESUME_CMDID,
231         .add_bcn_filter_cmdid = WMI_10X_ADD_BCN_FILTER_CMDID,
232         .rmv_bcn_filter_cmdid = WMI_10X_RMV_BCN_FILTER_CMDID,
233         .wow_add_wake_pattern_cmdid = WMI_10X_WOW_ADD_WAKE_PATTERN_CMDID,
234         .wow_del_wake_pattern_cmdid = WMI_10X_WOW_DEL_WAKE_PATTERN_CMDID,
235         .wow_enable_disable_wake_event_cmdid =
236                                 WMI_10X_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
237         .wow_enable_cmdid = WMI_10X_WOW_ENABLE_CMDID,
238         .wow_hostwakeup_from_sleep_cmdid =
239                                 WMI_10X_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
240         .rtt_measreq_cmdid = WMI_10X_RTT_MEASREQ_CMDID,
241         .rtt_tsf_cmdid = WMI_10X_RTT_TSF_CMDID,
242         .vdev_spectral_scan_configure_cmdid =
243                                 WMI_10X_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
244         .vdev_spectral_scan_enable_cmdid =
245                                 WMI_10X_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
246         .request_stats_cmdid = WMI_10X_REQUEST_STATS_CMDID,
247         .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
248         .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
249         .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
250         .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
251         .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
252         .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
253         .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
254         .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
255         .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
256         .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
257         .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
258         .echo_cmdid = WMI_10X_ECHO_CMDID,
259         .pdev_utf_cmdid = WMI_10X_PDEV_UTF_CMDID,
260         .dbglog_cfg_cmdid = WMI_10X_DBGLOG_CFG_CMDID,
261         .pdev_qvit_cmdid = WMI_10X_PDEV_QVIT_CMDID,
262         .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
263         .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
264         .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
265         .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
266         .gpio_config_cmdid = WMI_10X_GPIO_CONFIG_CMDID,
267         .gpio_output_cmdid = WMI_10X_GPIO_OUTPUT_CMDID,
268 };
269
270 /* MAIN WMI VDEV param map */
271 static struct wmi_vdev_param_map wmi_vdev_param_map = {
272         .rts_threshold = WMI_VDEV_PARAM_RTS_THRESHOLD,
273         .fragmentation_threshold = WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
274         .beacon_interval = WMI_VDEV_PARAM_BEACON_INTERVAL,
275         .listen_interval = WMI_VDEV_PARAM_LISTEN_INTERVAL,
276         .multicast_rate = WMI_VDEV_PARAM_MULTICAST_RATE,
277         .mgmt_tx_rate = WMI_VDEV_PARAM_MGMT_TX_RATE,
278         .slot_time = WMI_VDEV_PARAM_SLOT_TIME,
279         .preamble = WMI_VDEV_PARAM_PREAMBLE,
280         .swba_time = WMI_VDEV_PARAM_SWBA_TIME,
281         .wmi_vdev_stats_update_period = WMI_VDEV_STATS_UPDATE_PERIOD,
282         .wmi_vdev_pwrsave_ageout_time = WMI_VDEV_PWRSAVE_AGEOUT_TIME,
283         .wmi_vdev_host_swba_interval = WMI_VDEV_HOST_SWBA_INTERVAL,
284         .dtim_period = WMI_VDEV_PARAM_DTIM_PERIOD,
285         .wmi_vdev_oc_scheduler_air_time_limit =
286                                         WMI_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
287         .wds = WMI_VDEV_PARAM_WDS,
288         .atim_window = WMI_VDEV_PARAM_ATIM_WINDOW,
289         .bmiss_count_max = WMI_VDEV_PARAM_BMISS_COUNT_MAX,
290         .bmiss_first_bcnt = WMI_VDEV_PARAM_BMISS_FIRST_BCNT,
291         .bmiss_final_bcnt = WMI_VDEV_PARAM_BMISS_FINAL_BCNT,
292         .feature_wmm = WMI_VDEV_PARAM_FEATURE_WMM,
293         .chwidth = WMI_VDEV_PARAM_CHWIDTH,
294         .chextoffset = WMI_VDEV_PARAM_CHEXTOFFSET,
295         .disable_htprotection = WMI_VDEV_PARAM_DISABLE_HTPROTECTION,
296         .sta_quickkickout = WMI_VDEV_PARAM_STA_QUICKKICKOUT,
297         .mgmt_rate = WMI_VDEV_PARAM_MGMT_RATE,
298         .protection_mode = WMI_VDEV_PARAM_PROTECTION_MODE,
299         .fixed_rate = WMI_VDEV_PARAM_FIXED_RATE,
300         .sgi = WMI_VDEV_PARAM_SGI,
301         .ldpc = WMI_VDEV_PARAM_LDPC,
302         .tx_stbc = WMI_VDEV_PARAM_TX_STBC,
303         .rx_stbc = WMI_VDEV_PARAM_RX_STBC,
304         .intra_bss_fwd = WMI_VDEV_PARAM_INTRA_BSS_FWD,
305         .def_keyid = WMI_VDEV_PARAM_DEF_KEYID,
306         .nss = WMI_VDEV_PARAM_NSS,
307         .bcast_data_rate = WMI_VDEV_PARAM_BCAST_DATA_RATE,
308         .mcast_data_rate = WMI_VDEV_PARAM_MCAST_DATA_RATE,
309         .mcast_indicate = WMI_VDEV_PARAM_MCAST_INDICATE,
310         .dhcp_indicate = WMI_VDEV_PARAM_DHCP_INDICATE,
311         .unknown_dest_indicate = WMI_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
312         .ap_keepalive_min_idle_inactive_time_secs =
313                         WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
314         .ap_keepalive_max_idle_inactive_time_secs =
315                         WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
316         .ap_keepalive_max_unresponsive_time_secs =
317                         WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
318         .ap_enable_nawds = WMI_VDEV_PARAM_AP_ENABLE_NAWDS,
319         .mcast2ucast_set = WMI_VDEV_PARAM_UNSUPPORTED,
320         .enable_rtscts = WMI_VDEV_PARAM_ENABLE_RTSCTS,
321         .txbf = WMI_VDEV_PARAM_TXBF,
322         .packet_powersave = WMI_VDEV_PARAM_PACKET_POWERSAVE,
323         .drop_unencry = WMI_VDEV_PARAM_DROP_UNENCRY,
324         .tx_encap_type = WMI_VDEV_PARAM_TX_ENCAP_TYPE,
325         .ap_detect_out_of_sync_sleeping_sta_time_secs =
326                                         WMI_VDEV_PARAM_UNSUPPORTED,
327 };
328
329 /* 10.X WMI VDEV param map */
330 static struct wmi_vdev_param_map wmi_10x_vdev_param_map = {
331         .rts_threshold = WMI_10X_VDEV_PARAM_RTS_THRESHOLD,
332         .fragmentation_threshold = WMI_10X_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
333         .beacon_interval = WMI_10X_VDEV_PARAM_BEACON_INTERVAL,
334         .listen_interval = WMI_10X_VDEV_PARAM_LISTEN_INTERVAL,
335         .multicast_rate = WMI_10X_VDEV_PARAM_MULTICAST_RATE,
336         .mgmt_tx_rate = WMI_10X_VDEV_PARAM_MGMT_TX_RATE,
337         .slot_time = WMI_10X_VDEV_PARAM_SLOT_TIME,
338         .preamble = WMI_10X_VDEV_PARAM_PREAMBLE,
339         .swba_time = WMI_10X_VDEV_PARAM_SWBA_TIME,
340         .wmi_vdev_stats_update_period = WMI_10X_VDEV_STATS_UPDATE_PERIOD,
341         .wmi_vdev_pwrsave_ageout_time = WMI_10X_VDEV_PWRSAVE_AGEOUT_TIME,
342         .wmi_vdev_host_swba_interval = WMI_10X_VDEV_HOST_SWBA_INTERVAL,
343         .dtim_period = WMI_10X_VDEV_PARAM_DTIM_PERIOD,
344         .wmi_vdev_oc_scheduler_air_time_limit =
345                                 WMI_10X_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
346         .wds = WMI_10X_VDEV_PARAM_WDS,
347         .atim_window = WMI_10X_VDEV_PARAM_ATIM_WINDOW,
348         .bmiss_count_max = WMI_10X_VDEV_PARAM_BMISS_COUNT_MAX,
349         .bmiss_first_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
350         .bmiss_final_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
351         .feature_wmm = WMI_10X_VDEV_PARAM_FEATURE_WMM,
352         .chwidth = WMI_10X_VDEV_PARAM_CHWIDTH,
353         .chextoffset = WMI_10X_VDEV_PARAM_CHEXTOFFSET,
354         .disable_htprotection = WMI_10X_VDEV_PARAM_DISABLE_HTPROTECTION,
355         .sta_quickkickout = WMI_10X_VDEV_PARAM_STA_QUICKKICKOUT,
356         .mgmt_rate = WMI_10X_VDEV_PARAM_MGMT_RATE,
357         .protection_mode = WMI_10X_VDEV_PARAM_PROTECTION_MODE,
358         .fixed_rate = WMI_10X_VDEV_PARAM_FIXED_RATE,
359         .sgi = WMI_10X_VDEV_PARAM_SGI,
360         .ldpc = WMI_10X_VDEV_PARAM_LDPC,
361         .tx_stbc = WMI_10X_VDEV_PARAM_TX_STBC,
362         .rx_stbc = WMI_10X_VDEV_PARAM_RX_STBC,
363         .intra_bss_fwd = WMI_10X_VDEV_PARAM_INTRA_BSS_FWD,
364         .def_keyid = WMI_10X_VDEV_PARAM_DEF_KEYID,
365         .nss = WMI_10X_VDEV_PARAM_NSS,
366         .bcast_data_rate = WMI_10X_VDEV_PARAM_BCAST_DATA_RATE,
367         .mcast_data_rate = WMI_10X_VDEV_PARAM_MCAST_DATA_RATE,
368         .mcast_indicate = WMI_10X_VDEV_PARAM_MCAST_INDICATE,
369         .dhcp_indicate = WMI_10X_VDEV_PARAM_DHCP_INDICATE,
370         .unknown_dest_indicate = WMI_10X_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
371         .ap_keepalive_min_idle_inactive_time_secs =
372                 WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
373         .ap_keepalive_max_idle_inactive_time_secs =
374                 WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
375         .ap_keepalive_max_unresponsive_time_secs =
376                 WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
377         .ap_enable_nawds = WMI_10X_VDEV_PARAM_AP_ENABLE_NAWDS,
378         .mcast2ucast_set = WMI_10X_VDEV_PARAM_MCAST2UCAST_SET,
379         .enable_rtscts = WMI_10X_VDEV_PARAM_ENABLE_RTSCTS,
380         .txbf = WMI_VDEV_PARAM_UNSUPPORTED,
381         .packet_powersave = WMI_VDEV_PARAM_UNSUPPORTED,
382         .drop_unencry = WMI_VDEV_PARAM_UNSUPPORTED,
383         .tx_encap_type = WMI_VDEV_PARAM_UNSUPPORTED,
384         .ap_detect_out_of_sync_sleeping_sta_time_secs =
385                 WMI_10X_VDEV_PARAM_AP_DETECT_OUT_OF_SYNC_SLEEPING_STA_TIME_SECS,
386 };
387
388 static struct wmi_pdev_param_map wmi_pdev_param_map = {
389         .tx_chain_mask = WMI_PDEV_PARAM_TX_CHAIN_MASK,
390         .rx_chain_mask = WMI_PDEV_PARAM_RX_CHAIN_MASK,
391         .txpower_limit2g = WMI_PDEV_PARAM_TXPOWER_LIMIT2G,
392         .txpower_limit5g = WMI_PDEV_PARAM_TXPOWER_LIMIT5G,
393         .txpower_scale = WMI_PDEV_PARAM_TXPOWER_SCALE,
394         .beacon_gen_mode = WMI_PDEV_PARAM_BEACON_GEN_MODE,
395         .beacon_tx_mode = WMI_PDEV_PARAM_BEACON_TX_MODE,
396         .resmgr_offchan_mode = WMI_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
397         .protection_mode = WMI_PDEV_PARAM_PROTECTION_MODE,
398         .dynamic_bw = WMI_PDEV_PARAM_DYNAMIC_BW,
399         .non_agg_sw_retry_th = WMI_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
400         .agg_sw_retry_th = WMI_PDEV_PARAM_AGG_SW_RETRY_TH,
401         .sta_kickout_th = WMI_PDEV_PARAM_STA_KICKOUT_TH,
402         .ac_aggrsize_scaling = WMI_PDEV_PARAM_AC_AGGRSIZE_SCALING,
403         .ltr_enable = WMI_PDEV_PARAM_LTR_ENABLE,
404         .ltr_ac_latency_be = WMI_PDEV_PARAM_LTR_AC_LATENCY_BE,
405         .ltr_ac_latency_bk = WMI_PDEV_PARAM_LTR_AC_LATENCY_BK,
406         .ltr_ac_latency_vi = WMI_PDEV_PARAM_LTR_AC_LATENCY_VI,
407         .ltr_ac_latency_vo = WMI_PDEV_PARAM_LTR_AC_LATENCY_VO,
408         .ltr_ac_latency_timeout = WMI_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
409         .ltr_sleep_override = WMI_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
410         .ltr_rx_override = WMI_PDEV_PARAM_LTR_RX_OVERRIDE,
411         .ltr_tx_activity_timeout = WMI_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
412         .l1ss_enable = WMI_PDEV_PARAM_L1SS_ENABLE,
413         .dsleep_enable = WMI_PDEV_PARAM_DSLEEP_ENABLE,
414         .pcielp_txbuf_flush = WMI_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
415         .pcielp_txbuf_watermark = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
416         .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
417         .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
418         .pdev_stats_update_period = WMI_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
419         .vdev_stats_update_period = WMI_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
420         .peer_stats_update_period = WMI_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
421         .bcnflt_stats_update_period = WMI_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
422         .pmf_qos = WMI_PDEV_PARAM_PMF_QOS,
423         .arp_ac_override = WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
424         .dcs = WMI_PDEV_PARAM_DCS,
425         .ani_enable = WMI_PDEV_PARAM_ANI_ENABLE,
426         .ani_poll_period = WMI_PDEV_PARAM_ANI_POLL_PERIOD,
427         .ani_listen_period = WMI_PDEV_PARAM_ANI_LISTEN_PERIOD,
428         .ani_ofdm_level = WMI_PDEV_PARAM_ANI_OFDM_LEVEL,
429         .ani_cck_level = WMI_PDEV_PARAM_ANI_CCK_LEVEL,
430         .dyntxchain = WMI_PDEV_PARAM_DYNTXCHAIN,
431         .proxy_sta = WMI_PDEV_PARAM_PROXY_STA,
432         .idle_ps_config = WMI_PDEV_PARAM_IDLE_PS_CONFIG,
433         .power_gating_sleep = WMI_PDEV_PARAM_POWER_GATING_SLEEP,
434         .fast_channel_reset = WMI_PDEV_PARAM_UNSUPPORTED,
435         .burst_dur = WMI_PDEV_PARAM_UNSUPPORTED,
436         .burst_enable = WMI_PDEV_PARAM_UNSUPPORTED,
437 };
438
439 static struct wmi_pdev_param_map wmi_10x_pdev_param_map = {
440         .tx_chain_mask = WMI_10X_PDEV_PARAM_TX_CHAIN_MASK,
441         .rx_chain_mask = WMI_10X_PDEV_PARAM_RX_CHAIN_MASK,
442         .txpower_limit2g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT2G,
443         .txpower_limit5g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT5G,
444         .txpower_scale = WMI_10X_PDEV_PARAM_TXPOWER_SCALE,
445         .beacon_gen_mode = WMI_10X_PDEV_PARAM_BEACON_GEN_MODE,
446         .beacon_tx_mode = WMI_10X_PDEV_PARAM_BEACON_TX_MODE,
447         .resmgr_offchan_mode = WMI_10X_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
448         .protection_mode = WMI_10X_PDEV_PARAM_PROTECTION_MODE,
449         .dynamic_bw = WMI_10X_PDEV_PARAM_DYNAMIC_BW,
450         .non_agg_sw_retry_th = WMI_10X_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
451         .agg_sw_retry_th = WMI_10X_PDEV_PARAM_AGG_SW_RETRY_TH,
452         .sta_kickout_th = WMI_10X_PDEV_PARAM_STA_KICKOUT_TH,
453         .ac_aggrsize_scaling = WMI_10X_PDEV_PARAM_AC_AGGRSIZE_SCALING,
454         .ltr_enable = WMI_10X_PDEV_PARAM_LTR_ENABLE,
455         .ltr_ac_latency_be = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BE,
456         .ltr_ac_latency_bk = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BK,
457         .ltr_ac_latency_vi = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VI,
458         .ltr_ac_latency_vo = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VO,
459         .ltr_ac_latency_timeout = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
460         .ltr_sleep_override = WMI_10X_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
461         .ltr_rx_override = WMI_10X_PDEV_PARAM_LTR_RX_OVERRIDE,
462         .ltr_tx_activity_timeout = WMI_10X_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
463         .l1ss_enable = WMI_10X_PDEV_PARAM_L1SS_ENABLE,
464         .dsleep_enable = WMI_10X_PDEV_PARAM_DSLEEP_ENABLE,
465         .pcielp_txbuf_flush = WMI_PDEV_PARAM_UNSUPPORTED,
466         .pcielp_txbuf_watermark = WMI_PDEV_PARAM_UNSUPPORTED,
467         .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_UNSUPPORTED,
468         .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_UNSUPPORTED,
469         .pdev_stats_update_period = WMI_10X_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
470         .vdev_stats_update_period = WMI_10X_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
471         .peer_stats_update_period = WMI_10X_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
472         .bcnflt_stats_update_period =
473                                 WMI_10X_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
474         .pmf_qos = WMI_10X_PDEV_PARAM_PMF_QOS,
475         .arp_ac_override = WMI_10X_PDEV_PARAM_ARPDHCP_AC_OVERRIDE,
476         .dcs = WMI_10X_PDEV_PARAM_DCS,
477         .ani_enable = WMI_10X_PDEV_PARAM_ANI_ENABLE,
478         .ani_poll_period = WMI_10X_PDEV_PARAM_ANI_POLL_PERIOD,
479         .ani_listen_period = WMI_10X_PDEV_PARAM_ANI_LISTEN_PERIOD,
480         .ani_ofdm_level = WMI_10X_PDEV_PARAM_ANI_OFDM_LEVEL,
481         .ani_cck_level = WMI_10X_PDEV_PARAM_ANI_CCK_LEVEL,
482         .dyntxchain = WMI_10X_PDEV_PARAM_DYNTXCHAIN,
483         .proxy_sta = WMI_PDEV_PARAM_UNSUPPORTED,
484         .idle_ps_config = WMI_PDEV_PARAM_UNSUPPORTED,
485         .power_gating_sleep = WMI_PDEV_PARAM_UNSUPPORTED,
486         .fast_channel_reset = WMI_10X_PDEV_PARAM_FAST_CHANNEL_RESET,
487         .burst_dur = WMI_10X_PDEV_PARAM_BURST_DUR,
488         .burst_enable = WMI_10X_PDEV_PARAM_BURST_ENABLE,
489 };
490
491 /* firmware 10.2 specific mappings */
492 static struct wmi_cmd_map wmi_10_2_cmd_map = {
493         .init_cmdid = WMI_10_2_INIT_CMDID,
494         .start_scan_cmdid = WMI_10_2_START_SCAN_CMDID,
495         .stop_scan_cmdid = WMI_10_2_STOP_SCAN_CMDID,
496         .scan_chan_list_cmdid = WMI_10_2_SCAN_CHAN_LIST_CMDID,
497         .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
498         .pdev_set_regdomain_cmdid = WMI_10_2_PDEV_SET_REGDOMAIN_CMDID,
499         .pdev_set_channel_cmdid = WMI_10_2_PDEV_SET_CHANNEL_CMDID,
500         .pdev_set_param_cmdid = WMI_10_2_PDEV_SET_PARAM_CMDID,
501         .pdev_pktlog_enable_cmdid = WMI_10_2_PDEV_PKTLOG_ENABLE_CMDID,
502         .pdev_pktlog_disable_cmdid = WMI_10_2_PDEV_PKTLOG_DISABLE_CMDID,
503         .pdev_set_wmm_params_cmdid = WMI_10_2_PDEV_SET_WMM_PARAMS_CMDID,
504         .pdev_set_ht_cap_ie_cmdid = WMI_10_2_PDEV_SET_HT_CAP_IE_CMDID,
505         .pdev_set_vht_cap_ie_cmdid = WMI_10_2_PDEV_SET_VHT_CAP_IE_CMDID,
506         .pdev_set_quiet_mode_cmdid = WMI_10_2_PDEV_SET_QUIET_MODE_CMDID,
507         .pdev_green_ap_ps_enable_cmdid = WMI_10_2_PDEV_GREEN_AP_PS_ENABLE_CMDID,
508         .pdev_get_tpc_config_cmdid = WMI_10_2_PDEV_GET_TPC_CONFIG_CMDID,
509         .pdev_set_base_macaddr_cmdid = WMI_10_2_PDEV_SET_BASE_MACADDR_CMDID,
510         .vdev_create_cmdid = WMI_10_2_VDEV_CREATE_CMDID,
511         .vdev_delete_cmdid = WMI_10_2_VDEV_DELETE_CMDID,
512         .vdev_start_request_cmdid = WMI_10_2_VDEV_START_REQUEST_CMDID,
513         .vdev_restart_request_cmdid = WMI_10_2_VDEV_RESTART_REQUEST_CMDID,
514         .vdev_up_cmdid = WMI_10_2_VDEV_UP_CMDID,
515         .vdev_stop_cmdid = WMI_10_2_VDEV_STOP_CMDID,
516         .vdev_down_cmdid = WMI_10_2_VDEV_DOWN_CMDID,
517         .vdev_set_param_cmdid = WMI_10_2_VDEV_SET_PARAM_CMDID,
518         .vdev_install_key_cmdid = WMI_10_2_VDEV_INSTALL_KEY_CMDID,
519         .peer_create_cmdid = WMI_10_2_PEER_CREATE_CMDID,
520         .peer_delete_cmdid = WMI_10_2_PEER_DELETE_CMDID,
521         .peer_flush_tids_cmdid = WMI_10_2_PEER_FLUSH_TIDS_CMDID,
522         .peer_set_param_cmdid = WMI_10_2_PEER_SET_PARAM_CMDID,
523         .peer_assoc_cmdid = WMI_10_2_PEER_ASSOC_CMDID,
524         .peer_add_wds_entry_cmdid = WMI_10_2_PEER_ADD_WDS_ENTRY_CMDID,
525         .peer_remove_wds_entry_cmdid = WMI_10_2_PEER_REMOVE_WDS_ENTRY_CMDID,
526         .peer_mcast_group_cmdid = WMI_10_2_PEER_MCAST_GROUP_CMDID,
527         .bcn_tx_cmdid = WMI_10_2_BCN_TX_CMDID,
528         .pdev_send_bcn_cmdid = WMI_10_2_PDEV_SEND_BCN_CMDID,
529         .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
530         .bcn_filter_rx_cmdid = WMI_10_2_BCN_FILTER_RX_CMDID,
531         .prb_req_filter_rx_cmdid = WMI_10_2_PRB_REQ_FILTER_RX_CMDID,
532         .mgmt_tx_cmdid = WMI_10_2_MGMT_TX_CMDID,
533         .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
534         .addba_clear_resp_cmdid = WMI_10_2_ADDBA_CLEAR_RESP_CMDID,
535         .addba_send_cmdid = WMI_10_2_ADDBA_SEND_CMDID,
536         .addba_status_cmdid = WMI_10_2_ADDBA_STATUS_CMDID,
537         .delba_send_cmdid = WMI_10_2_DELBA_SEND_CMDID,
538         .addba_set_resp_cmdid = WMI_10_2_ADDBA_SET_RESP_CMDID,
539         .send_singleamsdu_cmdid = WMI_10_2_SEND_SINGLEAMSDU_CMDID,
540         .sta_powersave_mode_cmdid = WMI_10_2_STA_POWERSAVE_MODE_CMDID,
541         .sta_powersave_param_cmdid = WMI_10_2_STA_POWERSAVE_PARAM_CMDID,
542         .sta_mimo_ps_mode_cmdid = WMI_10_2_STA_MIMO_PS_MODE_CMDID,
543         .pdev_dfs_enable_cmdid = WMI_10_2_PDEV_DFS_ENABLE_CMDID,
544         .pdev_dfs_disable_cmdid = WMI_10_2_PDEV_DFS_DISABLE_CMDID,
545         .roam_scan_mode = WMI_10_2_ROAM_SCAN_MODE,
546         .roam_scan_rssi_threshold = WMI_10_2_ROAM_SCAN_RSSI_THRESHOLD,
547         .roam_scan_period = WMI_10_2_ROAM_SCAN_PERIOD,
548         .roam_scan_rssi_change_threshold =
549                                 WMI_10_2_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
550         .roam_ap_profile = WMI_10_2_ROAM_AP_PROFILE,
551         .ofl_scan_add_ap_profile = WMI_10_2_OFL_SCAN_ADD_AP_PROFILE,
552         .ofl_scan_remove_ap_profile = WMI_10_2_OFL_SCAN_REMOVE_AP_PROFILE,
553         .ofl_scan_period = WMI_10_2_OFL_SCAN_PERIOD,
554         .p2p_dev_set_device_info = WMI_10_2_P2P_DEV_SET_DEVICE_INFO,
555         .p2p_dev_set_discoverability = WMI_10_2_P2P_DEV_SET_DISCOVERABILITY,
556         .p2p_go_set_beacon_ie = WMI_10_2_P2P_GO_SET_BEACON_IE,
557         .p2p_go_set_probe_resp_ie = WMI_10_2_P2P_GO_SET_PROBE_RESP_IE,
558         .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
559         .ap_ps_peer_param_cmdid = WMI_10_2_AP_PS_PEER_PARAM_CMDID,
560         .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
561         .peer_rate_retry_sched_cmdid = WMI_10_2_PEER_RATE_RETRY_SCHED_CMDID,
562         .wlan_profile_trigger_cmdid = WMI_10_2_WLAN_PROFILE_TRIGGER_CMDID,
563         .wlan_profile_set_hist_intvl_cmdid =
564                                 WMI_10_2_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
565         .wlan_profile_get_profile_data_cmdid =
566                                 WMI_10_2_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
567         .wlan_profile_enable_profile_id_cmdid =
568                                 WMI_10_2_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
569         .wlan_profile_list_profile_id_cmdid =
570                                 WMI_10_2_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
571         .pdev_suspend_cmdid = WMI_10_2_PDEV_SUSPEND_CMDID,
572         .pdev_resume_cmdid = WMI_10_2_PDEV_RESUME_CMDID,
573         .add_bcn_filter_cmdid = WMI_10_2_ADD_BCN_FILTER_CMDID,
574         .rmv_bcn_filter_cmdid = WMI_10_2_RMV_BCN_FILTER_CMDID,
575         .wow_add_wake_pattern_cmdid = WMI_10_2_WOW_ADD_WAKE_PATTERN_CMDID,
576         .wow_del_wake_pattern_cmdid = WMI_10_2_WOW_DEL_WAKE_PATTERN_CMDID,
577         .wow_enable_disable_wake_event_cmdid =
578                                 WMI_10_2_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
579         .wow_enable_cmdid = WMI_10_2_WOW_ENABLE_CMDID,
580         .wow_hostwakeup_from_sleep_cmdid =
581                                 WMI_10_2_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
582         .rtt_measreq_cmdid = WMI_10_2_RTT_MEASREQ_CMDID,
583         .rtt_tsf_cmdid = WMI_10_2_RTT_TSF_CMDID,
584         .vdev_spectral_scan_configure_cmdid =
585                                 WMI_10_2_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
586         .vdev_spectral_scan_enable_cmdid =
587                                 WMI_10_2_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
588         .request_stats_cmdid = WMI_10_2_REQUEST_STATS_CMDID,
589         .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
590         .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
591         .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
592         .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
593         .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
594         .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
595         .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
596         .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
597         .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
598         .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
599         .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
600         .echo_cmdid = WMI_10_2_ECHO_CMDID,
601         .pdev_utf_cmdid = WMI_10_2_PDEV_UTF_CMDID,
602         .dbglog_cfg_cmdid = WMI_10_2_DBGLOG_CFG_CMDID,
603         .pdev_qvit_cmdid = WMI_10_2_PDEV_QVIT_CMDID,
604         .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
605         .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
606         .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
607         .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
608         .gpio_config_cmdid = WMI_10_2_GPIO_CONFIG_CMDID,
609         .gpio_output_cmdid = WMI_10_2_GPIO_OUTPUT_CMDID,
610 };
611
612 int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
613 {
614         int ret;
615
616         ret = wait_for_completion_timeout(&ar->wmi.service_ready,
617                                           WMI_SERVICE_READY_TIMEOUT_HZ);
618         return ret;
619 }
620
621 int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
622 {
623         int ret;
624
625         ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
626                                           WMI_UNIFIED_READY_TIMEOUT_HZ);
627         return ret;
628 }
629
630 struct sk_buff *ath10k_wmi_alloc_skb(struct ath10k *ar, u32 len)
631 {
632         struct sk_buff *skb;
633         u32 round_len = roundup(len, 4);
634
635         skb = ath10k_htc_alloc_skb(ar, WMI_SKB_HEADROOM + round_len);
636         if (!skb)
637                 return NULL;
638
639         skb_reserve(skb, WMI_SKB_HEADROOM);
640         if (!IS_ALIGNED((unsigned long)skb->data, 4))
641                 ath10k_warn(ar, "Unaligned WMI skb\n");
642
643         skb_put(skb, round_len);
644         memset(skb->data, 0, round_len);
645
646         return skb;
647 }
648
649 static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
650 {
651         dev_kfree_skb(skb);
652 }
653
654 static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
655                                       u32 cmd_id)
656 {
657         struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
658         struct wmi_cmd_hdr *cmd_hdr;
659         int ret;
660         u32 cmd = 0;
661
662         if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
663                 return -ENOMEM;
664
665         cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
666
667         cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
668         cmd_hdr->cmd_id = __cpu_to_le32(cmd);
669
670         memset(skb_cb, 0, sizeof(*skb_cb));
671         ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
672         trace_ath10k_wmi_cmd(ar, cmd_id, skb->data, skb->len, ret);
673
674         if (ret)
675                 goto err_pull;
676
677         return 0;
678
679 err_pull:
680         skb_pull(skb, sizeof(struct wmi_cmd_hdr));
681         return ret;
682 }
683
684 static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
685 {
686         int ret;
687
688         lockdep_assert_held(&arvif->ar->data_lock);
689
690         if (arvif->beacon == NULL)
691                 return;
692
693         if (arvif->beacon_sent)
694                 return;
695
696         ret = ath10k_wmi_beacon_send_ref_nowait(arvif);
697         if (ret)
698                 return;
699
700         /* We need to retain the arvif->beacon reference for DMA unmapping and
701          * freeing the skbuff later. */
702         arvif->beacon_sent = true;
703 }
704
705 static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
706                                        struct ieee80211_vif *vif)
707 {
708         struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
709
710         ath10k_wmi_tx_beacon_nowait(arvif);
711 }
712
713 static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
714 {
715         spin_lock_bh(&ar->data_lock);
716         ieee80211_iterate_active_interfaces_atomic(ar->hw,
717                                                    IEEE80211_IFACE_ITER_NORMAL,
718                                                    ath10k_wmi_tx_beacons_iter,
719                                                    NULL);
720         spin_unlock_bh(&ar->data_lock);
721 }
722
723 static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
724 {
725         /* try to send pending beacons first. they take priority */
726         ath10k_wmi_tx_beacons_nowait(ar);
727
728         wake_up(&ar->wmi.tx_credits_wq);
729 }
730
731 int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id)
732 {
733         int ret = -EOPNOTSUPP;
734
735         might_sleep();
736
737         if (cmd_id == WMI_CMD_UNSUPPORTED) {
738                 ath10k_warn(ar, "wmi command %d is not supported by firmware\n",
739                             cmd_id);
740                 return ret;
741         }
742
743         wait_event_timeout(ar->wmi.tx_credits_wq, ({
744                 /* try to send pending beacons first. they take priority */
745                 ath10k_wmi_tx_beacons_nowait(ar);
746
747                 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
748                 (ret != -EAGAIN);
749         }), 3*HZ);
750
751         if (ret)
752                 dev_kfree_skb_any(skb);
753
754         return ret;
755 }
756
757 int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
758 {
759         int ret = 0;
760         struct wmi_mgmt_tx_cmd *cmd;
761         struct ieee80211_hdr *hdr;
762         struct sk_buff *wmi_skb;
763         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
764         int len;
765         u32 buf_len = skb->len;
766         u16 fc;
767
768         hdr = (struct ieee80211_hdr *)skb->data;
769         fc = le16_to_cpu(hdr->frame_control);
770
771         if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
772                 return -EINVAL;
773
774         len = sizeof(cmd->hdr) + skb->len;
775
776         if ((ieee80211_is_action(hdr->frame_control) ||
777              ieee80211_is_deauth(hdr->frame_control) ||
778              ieee80211_is_disassoc(hdr->frame_control)) &&
779              ieee80211_has_protected(hdr->frame_control)) {
780                 len += IEEE80211_CCMP_MIC_LEN;
781                 buf_len += IEEE80211_CCMP_MIC_LEN;
782         }
783
784         len = round_up(len, 4);
785
786         wmi_skb = ath10k_wmi_alloc_skb(ar, len);
787         if (!wmi_skb)
788                 return -ENOMEM;
789
790         cmd = (struct wmi_mgmt_tx_cmd *)wmi_skb->data;
791
792         cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id);
793         cmd->hdr.tx_rate = 0;
794         cmd->hdr.tx_power = 0;
795         cmd->hdr.buf_len = __cpu_to_le32(buf_len);
796
797         ether_addr_copy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr));
798         memcpy(cmd->buf, skb->data, skb->len);
799
800         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n",
801                    wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE,
802                    fc & IEEE80211_FCTL_STYPE);
803
804         /* Send the management frame buffer to the target */
805         ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid);
806         if (ret)
807                 return ret;
808
809         /* TODO: report tx status to mac80211 - temporary just ACK */
810         info->flags |= IEEE80211_TX_STAT_ACK;
811         ieee80211_tx_status_irqsafe(ar->hw, skb);
812
813         return ret;
814 }
815
816 static void ath10k_wmi_event_scan_started(struct ath10k *ar)
817 {
818         lockdep_assert_held(&ar->data_lock);
819
820         switch (ar->scan.state) {
821         case ATH10K_SCAN_IDLE:
822         case ATH10K_SCAN_RUNNING:
823         case ATH10K_SCAN_ABORTING:
824                 ath10k_warn(ar, "received scan started event in an invalid scan state: %s (%d)\n",
825                             ath10k_scan_state_str(ar->scan.state),
826                             ar->scan.state);
827                 break;
828         case ATH10K_SCAN_STARTING:
829                 ar->scan.state = ATH10K_SCAN_RUNNING;
830
831                 if (ar->scan.is_roc)
832                         ieee80211_ready_on_channel(ar->hw);
833
834                 complete(&ar->scan.started);
835                 break;
836         }
837 }
838
839 static void ath10k_wmi_event_scan_completed(struct ath10k *ar)
840 {
841         lockdep_assert_held(&ar->data_lock);
842
843         switch (ar->scan.state) {
844         case ATH10K_SCAN_IDLE:
845         case ATH10K_SCAN_STARTING:
846                 /* One suspected reason scan can be completed while starting is
847                  * if firmware fails to deliver all scan events to the host,
848                  * e.g. when transport pipe is full. This has been observed
849                  * with spectral scan phyerr events starving wmi transport
850                  * pipe. In such case the "scan completed" event should be (and
851                  * is) ignored by the host as it may be just firmware's scan
852                  * state machine recovering.
853                  */
854                 ath10k_warn(ar, "received scan completed event in an invalid scan state: %s (%d)\n",
855                             ath10k_scan_state_str(ar->scan.state),
856                             ar->scan.state);
857                 break;
858         case ATH10K_SCAN_RUNNING:
859         case ATH10K_SCAN_ABORTING:
860                 __ath10k_scan_finish(ar);
861                 break;
862         }
863 }
864
865 static void ath10k_wmi_event_scan_bss_chan(struct ath10k *ar)
866 {
867         lockdep_assert_held(&ar->data_lock);
868
869         switch (ar->scan.state) {
870         case ATH10K_SCAN_IDLE:
871         case ATH10K_SCAN_STARTING:
872                 ath10k_warn(ar, "received scan bss chan event in an invalid scan state: %s (%d)\n",
873                             ath10k_scan_state_str(ar->scan.state),
874                             ar->scan.state);
875                 break;
876         case ATH10K_SCAN_RUNNING:
877         case ATH10K_SCAN_ABORTING:
878                 ar->scan_channel = NULL;
879                 break;
880         }
881 }
882
883 static void ath10k_wmi_event_scan_foreign_chan(struct ath10k *ar, u32 freq)
884 {
885         lockdep_assert_held(&ar->data_lock);
886
887         switch (ar->scan.state) {
888         case ATH10K_SCAN_IDLE:
889         case ATH10K_SCAN_STARTING:
890                 ath10k_warn(ar, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
891                             ath10k_scan_state_str(ar->scan.state),
892                             ar->scan.state);
893                 break;
894         case ATH10K_SCAN_RUNNING:
895         case ATH10K_SCAN_ABORTING:
896                 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
897
898                 if (ar->scan.is_roc && ar->scan.roc_freq == freq)
899                         complete(&ar->scan.on_channel);
900                 break;
901         }
902 }
903
904 static const char *
905 ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
906                                enum wmi_scan_completion_reason reason)
907 {
908         switch (type) {
909         case WMI_SCAN_EVENT_STARTED:
910                 return "started";
911         case WMI_SCAN_EVENT_COMPLETED:
912                 switch (reason) {
913                 case WMI_SCAN_REASON_COMPLETED:
914                         return "completed";
915                 case WMI_SCAN_REASON_CANCELLED:
916                         return "completed [cancelled]";
917                 case WMI_SCAN_REASON_PREEMPTED:
918                         return "completed [preempted]";
919                 case WMI_SCAN_REASON_TIMEDOUT:
920                         return "completed [timedout]";
921                 case WMI_SCAN_REASON_MAX:
922                         break;
923                 }
924                 return "completed [unknown]";
925         case WMI_SCAN_EVENT_BSS_CHANNEL:
926                 return "bss channel";
927         case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
928                 return "foreign channel";
929         case WMI_SCAN_EVENT_DEQUEUED:
930                 return "dequeued";
931         case WMI_SCAN_EVENT_PREEMPTED:
932                 return "preempted";
933         case WMI_SCAN_EVENT_START_FAILED:
934                 return "start failed";
935         default:
936                 return "unknown";
937         }
938 }
939
940 static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
941 {
942         struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
943         enum wmi_scan_event_type event_type;
944         enum wmi_scan_completion_reason reason;
945         u32 freq;
946         u32 req_id;
947         u32 scan_id;
948         u32 vdev_id;
949
950         event_type = __le32_to_cpu(event->event_type);
951         reason     = __le32_to_cpu(event->reason);
952         freq       = __le32_to_cpu(event->channel_freq);
953         req_id     = __le32_to_cpu(event->scan_req_id);
954         scan_id    = __le32_to_cpu(event->scan_id);
955         vdev_id    = __le32_to_cpu(event->vdev_id);
956
957         spin_lock_bh(&ar->data_lock);
958
959         ath10k_dbg(ar, ATH10K_DBG_WMI,
960                    "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
961                    ath10k_wmi_event_scan_type_str(event_type, reason),
962                    event_type, reason, freq, req_id, scan_id, vdev_id,
963                    ath10k_scan_state_str(ar->scan.state), ar->scan.state);
964
965         switch (event_type) {
966         case WMI_SCAN_EVENT_STARTED:
967                 ath10k_wmi_event_scan_started(ar);
968                 break;
969         case WMI_SCAN_EVENT_COMPLETED:
970                 ath10k_wmi_event_scan_completed(ar);
971                 break;
972         case WMI_SCAN_EVENT_BSS_CHANNEL:
973                 ath10k_wmi_event_scan_bss_chan(ar);
974                 break;
975         case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
976                 ath10k_wmi_event_scan_foreign_chan(ar, freq);
977                 break;
978         case WMI_SCAN_EVENT_START_FAILED:
979                 ath10k_warn(ar, "received scan start failure event\n");
980                 break;
981         case WMI_SCAN_EVENT_DEQUEUED:
982         case WMI_SCAN_EVENT_PREEMPTED:
983         default:
984                 break;
985         }
986
987         spin_unlock_bh(&ar->data_lock);
988         return 0;
989 }
990
991 static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
992 {
993         enum ieee80211_band band;
994
995         switch (phy_mode) {
996         case MODE_11A:
997         case MODE_11NA_HT20:
998         case MODE_11NA_HT40:
999         case MODE_11AC_VHT20:
1000         case MODE_11AC_VHT40:
1001         case MODE_11AC_VHT80:
1002                 band = IEEE80211_BAND_5GHZ;
1003                 break;
1004         case MODE_11G:
1005         case MODE_11B:
1006         case MODE_11GONLY:
1007         case MODE_11NG_HT20:
1008         case MODE_11NG_HT40:
1009         case MODE_11AC_VHT20_2G:
1010         case MODE_11AC_VHT40_2G:
1011         case MODE_11AC_VHT80_2G:
1012         default:
1013                 band = IEEE80211_BAND_2GHZ;
1014         }
1015
1016         return band;
1017 }
1018
1019 static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
1020 {
1021         u8 rate_idx = 0;
1022
1023         /* rate in Kbps */
1024         switch (rate) {
1025         case 1000:
1026                 rate_idx = 0;
1027                 break;
1028         case 2000:
1029                 rate_idx = 1;
1030                 break;
1031         case 5500:
1032                 rate_idx = 2;
1033                 break;
1034         case 11000:
1035                 rate_idx = 3;
1036                 break;
1037         case 6000:
1038                 rate_idx = 4;
1039                 break;
1040         case 9000:
1041                 rate_idx = 5;
1042                 break;
1043         case 12000:
1044                 rate_idx = 6;
1045                 break;
1046         case 18000:
1047                 rate_idx = 7;
1048                 break;
1049         case 24000:
1050                 rate_idx = 8;
1051                 break;
1052         case 36000:
1053                 rate_idx = 9;
1054                 break;
1055         case 48000:
1056                 rate_idx = 10;
1057                 break;
1058         case 54000:
1059                 rate_idx = 11;
1060                 break;
1061         default:
1062                 break;
1063         }
1064
1065         if (band == IEEE80211_BAND_5GHZ) {
1066                 if (rate_idx > 3)
1067                         /* Omit CCK rates */
1068                         rate_idx -= 4;
1069                 else
1070                         rate_idx = 0;
1071         }
1072
1073         return rate_idx;
1074 }
1075
1076 static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
1077 {
1078         struct wmi_mgmt_rx_event_v1 *ev_v1;
1079         struct wmi_mgmt_rx_event_v2 *ev_v2;
1080         struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
1081         struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1082         struct ieee80211_channel *ch;
1083         struct ieee80211_hdr *hdr;
1084         u32 rx_status;
1085         u32 channel;
1086         u32 phy_mode;
1087         u32 snr;
1088         u32 rate;
1089         u32 buf_len;
1090         u16 fc;
1091         int pull_len;
1092
1093         if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
1094                 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
1095                 ev_hdr = &ev_v2->hdr.v1;
1096                 pull_len = sizeof(*ev_v2);
1097         } else {
1098                 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
1099                 ev_hdr = &ev_v1->hdr;
1100                 pull_len = sizeof(*ev_v1);
1101         }
1102
1103         channel   = __le32_to_cpu(ev_hdr->channel);
1104         buf_len   = __le32_to_cpu(ev_hdr->buf_len);
1105         rx_status = __le32_to_cpu(ev_hdr->status);
1106         snr       = __le32_to_cpu(ev_hdr->snr);
1107         phy_mode  = __le32_to_cpu(ev_hdr->phy_mode);
1108         rate      = __le32_to_cpu(ev_hdr->rate);
1109
1110         memset(status, 0, sizeof(*status));
1111
1112         ath10k_dbg(ar, ATH10K_DBG_MGMT,
1113                    "event mgmt rx status %08x\n", rx_status);
1114
1115         if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
1116                 dev_kfree_skb(skb);
1117                 return 0;
1118         }
1119
1120         if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
1121                 dev_kfree_skb(skb);
1122                 return 0;
1123         }
1124
1125         if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
1126                 dev_kfree_skb(skb);
1127                 return 0;
1128         }
1129
1130         if (rx_status & WMI_RX_STATUS_ERR_CRC)
1131                 status->flag |= RX_FLAG_FAILED_FCS_CRC;
1132         if (rx_status & WMI_RX_STATUS_ERR_MIC)
1133                 status->flag |= RX_FLAG_MMIC_ERROR;
1134
1135         /* HW can Rx CCK rates on 5GHz. In that case phy_mode is set to
1136          * MODE_11B. This means phy_mode is not a reliable source for the band
1137          * of mgmt rx. */
1138
1139         ch = ar->scan_channel;
1140         if (!ch)
1141                 ch = ar->rx_channel;
1142
1143         if (ch) {
1144                 status->band = ch->band;
1145
1146                 if (phy_mode == MODE_11B &&
1147                     status->band == IEEE80211_BAND_5GHZ)
1148                         ath10k_dbg(ar, ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
1149         } else {
1150                 ath10k_warn(ar, "using (unreliable) phy_mode to extract band for mgmt rx\n");
1151                 status->band = phy_mode_to_band(phy_mode);
1152         }
1153
1154         status->freq = ieee80211_channel_to_frequency(channel, status->band);
1155         status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
1156         status->rate_idx = get_rate_idx(rate, status->band);
1157
1158         skb_pull(skb, pull_len);
1159
1160         hdr = (struct ieee80211_hdr *)skb->data;
1161         fc = le16_to_cpu(hdr->frame_control);
1162
1163         /* FW delivers WEP Shared Auth frame with Protected Bit set and
1164          * encrypted payload. However in case of PMF it delivers decrypted
1165          * frames with Protected Bit set. */
1166         if (ieee80211_has_protected(hdr->frame_control) &&
1167             !ieee80211_is_auth(hdr->frame_control)) {
1168                 status->flag |= RX_FLAG_DECRYPTED;
1169
1170                 if (!ieee80211_is_action(hdr->frame_control) &&
1171                     !ieee80211_is_deauth(hdr->frame_control) &&
1172                     !ieee80211_is_disassoc(hdr->frame_control)) {
1173                         status->flag |= RX_FLAG_IV_STRIPPED |
1174                                         RX_FLAG_MMIC_STRIPPED;
1175                         hdr->frame_control = __cpu_to_le16(fc &
1176                                         ~IEEE80211_FCTL_PROTECTED);
1177                 }
1178         }
1179
1180         ath10k_dbg(ar, ATH10K_DBG_MGMT,
1181                    "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
1182                    skb, skb->len,
1183                    fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
1184
1185         ath10k_dbg(ar, ATH10K_DBG_MGMT,
1186                    "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
1187                    status->freq, status->band, status->signal,
1188                    status->rate_idx);
1189
1190         /*
1191          * packets from HTC come aligned to 4byte boundaries
1192          * because they can originally come in along with a trailer
1193          */
1194         skb_trim(skb, buf_len);
1195
1196         ieee80211_rx(ar->hw, skb);
1197         return 0;
1198 }
1199
1200 static int freq_to_idx(struct ath10k *ar, int freq)
1201 {
1202         struct ieee80211_supported_band *sband;
1203         int band, ch, idx = 0;
1204
1205         for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
1206                 sband = ar->hw->wiphy->bands[band];
1207                 if (!sband)
1208                         continue;
1209
1210                 for (ch = 0; ch < sband->n_channels; ch++, idx++)
1211                         if (sband->channels[ch].center_freq == freq)
1212                                 goto exit;
1213         }
1214
1215 exit:
1216         return idx;
1217 }
1218
1219 static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
1220 {
1221         struct wmi_chan_info_event *ev;
1222         struct survey_info *survey;
1223         u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
1224         int idx;
1225
1226         ev = (struct wmi_chan_info_event *)skb->data;
1227
1228         err_code = __le32_to_cpu(ev->err_code);
1229         freq = __le32_to_cpu(ev->freq);
1230         cmd_flags = __le32_to_cpu(ev->cmd_flags);
1231         noise_floor = __le32_to_cpu(ev->noise_floor);
1232         rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
1233         cycle_count = __le32_to_cpu(ev->cycle_count);
1234
1235         ath10k_dbg(ar, ATH10K_DBG_WMI,
1236                    "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
1237                    err_code, freq, cmd_flags, noise_floor, rx_clear_count,
1238                    cycle_count);
1239
1240         spin_lock_bh(&ar->data_lock);
1241
1242         switch (ar->scan.state) {
1243         case ATH10K_SCAN_IDLE:
1244         case ATH10K_SCAN_STARTING:
1245                 ath10k_warn(ar, "received chan info event without a scan request, ignoring\n");
1246                 goto exit;
1247         case ATH10K_SCAN_RUNNING:
1248         case ATH10K_SCAN_ABORTING:
1249                 break;
1250         }
1251
1252         idx = freq_to_idx(ar, freq);
1253         if (idx >= ARRAY_SIZE(ar->survey)) {
1254                 ath10k_warn(ar, "chan info: invalid frequency %d (idx %d out of bounds)\n",
1255                             freq, idx);
1256                 goto exit;
1257         }
1258
1259         if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
1260                 /* During scanning chan info is reported twice for each
1261                  * visited channel. The reported cycle count is global
1262                  * and per-channel cycle count must be calculated */
1263
1264                 cycle_count -= ar->survey_last_cycle_count;
1265                 rx_clear_count -= ar->survey_last_rx_clear_count;
1266
1267                 survey = &ar->survey[idx];
1268                 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
1269                 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
1270                 survey->noise = noise_floor;
1271                 survey->filled = SURVEY_INFO_CHANNEL_TIME |
1272                                  SURVEY_INFO_CHANNEL_TIME_RX |
1273                                  SURVEY_INFO_NOISE_DBM;
1274         }
1275
1276         ar->survey_last_rx_clear_count = rx_clear_count;
1277         ar->survey_last_cycle_count = cycle_count;
1278
1279 exit:
1280         spin_unlock_bh(&ar->data_lock);
1281 }
1282
1283 static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
1284 {
1285         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
1286 }
1287
1288 static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
1289 {
1290         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
1291                    skb->len);
1292
1293         trace_ath10k_wmi_dbglog(ar, skb->data, skb->len);
1294
1295         return 0;
1296 }
1297
1298 static void ath10k_wmi_event_update_stats(struct ath10k *ar,
1299                                           struct sk_buff *skb)
1300 {
1301         struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
1302
1303         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
1304
1305         ath10k_debug_read_target_stats(ar, ev);
1306 }
1307
1308 static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
1309                                              struct sk_buff *skb)
1310 {
1311         struct wmi_vdev_start_response_event *ev;
1312
1313         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
1314
1315         ev = (struct wmi_vdev_start_response_event *)skb->data;
1316
1317         if (WARN_ON(__le32_to_cpu(ev->status)))
1318                 return;
1319
1320         complete(&ar->vdev_setup_done);
1321 }
1322
1323 static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
1324                                           struct sk_buff *skb)
1325 {
1326         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
1327         complete(&ar->vdev_setup_done);
1328 }
1329
1330 static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
1331                                               struct sk_buff *skb)
1332 {
1333         struct wmi_peer_sta_kickout_event *ev;
1334         struct ieee80211_sta *sta;
1335
1336         ev = (struct wmi_peer_sta_kickout_event *)skb->data;
1337
1338         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
1339                    ev->peer_macaddr.addr);
1340
1341         rcu_read_lock();
1342
1343         sta = ieee80211_find_sta_by_ifaddr(ar->hw, ev->peer_macaddr.addr, NULL);
1344         if (!sta) {
1345                 ath10k_warn(ar, "Spurious quick kickout for STA %pM\n",
1346                             ev->peer_macaddr.addr);
1347                 goto exit;
1348         }
1349
1350         ieee80211_report_low_ack(sta, 10);
1351
1352 exit:
1353         rcu_read_unlock();
1354 }
1355
1356 /*
1357  * FIXME
1358  *
1359  * We don't report to mac80211 sleep state of connected
1360  * stations. Due to this mac80211 can't fill in TIM IE
1361  * correctly.
1362  *
1363  * I know of no way of getting nullfunc frames that contain
1364  * sleep transition from connected stations - these do not
1365  * seem to be sent from the target to the host. There also
1366  * doesn't seem to be a dedicated event for that. So the
1367  * only way left to do this would be to read tim_bitmap
1368  * during SWBA.
1369  *
1370  * We could probably try using tim_bitmap from SWBA to tell
1371  * mac80211 which stations are asleep and which are not. The
1372  * problem here is calling mac80211 functions so many times
1373  * could take too long and make us miss the time to submit
1374  * the beacon to the target.
1375  *
1376  * So as a workaround we try to extend the TIM IE if there
1377  * is unicast buffered for stations with aid > 7 and fill it
1378  * in ourselves.
1379  */
1380 static void ath10k_wmi_update_tim(struct ath10k *ar,
1381                                   struct ath10k_vif *arvif,
1382                                   struct sk_buff *bcn,
1383                                   struct wmi_bcn_info *bcn_info)
1384 {
1385         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
1386         struct ieee80211_tim_ie *tim;
1387         u8 *ies, *ie;
1388         u8 ie_len, pvm_len;
1389         __le32 t;
1390         u32 v;
1391
1392         /* if next SWBA has no tim_changed the tim_bitmap is garbage.
1393          * we must copy the bitmap upon change and reuse it later */
1394         if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
1395                 int i;
1396
1397                 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
1398                              sizeof(bcn_info->tim_info.tim_bitmap));
1399
1400                 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
1401                         t = bcn_info->tim_info.tim_bitmap[i / 4];
1402                         v = __le32_to_cpu(t);
1403                         arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
1404                 }
1405
1406                 /* FW reports either length 0 or 16
1407                  * so we calculate this on our own */
1408                 arvif->u.ap.tim_len = 0;
1409                 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
1410                         if (arvif->u.ap.tim_bitmap[i])
1411                                 arvif->u.ap.tim_len = i;
1412
1413                 arvif->u.ap.tim_len++;
1414         }
1415
1416         ies = bcn->data;
1417         ies += ieee80211_hdrlen(hdr->frame_control);
1418         ies += 12; /* fixed parameters */
1419
1420         ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
1421                                     (u8 *)skb_tail_pointer(bcn) - ies);
1422         if (!ie) {
1423                 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1424                         ath10k_warn(ar, "no tim ie found;\n");
1425                 return;
1426         }
1427
1428         tim = (void *)ie + 2;
1429         ie_len = ie[1];
1430         pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
1431
1432         if (pvm_len < arvif->u.ap.tim_len) {
1433                 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
1434                 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
1435                 void *next_ie = ie + 2 + ie_len;
1436
1437                 if (skb_put(bcn, expand_size)) {
1438                         memmove(next_ie + expand_size, next_ie, move_size);
1439
1440                         ie[1] += expand_size;
1441                         ie_len += expand_size;
1442                         pvm_len += expand_size;
1443                 } else {
1444                         ath10k_warn(ar, "tim expansion failed\n");
1445                 }
1446         }
1447
1448         if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
1449                 ath10k_warn(ar, "tim pvm length is too great (%d)\n", pvm_len);
1450                 return;
1451         }
1452
1453         tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
1454         memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
1455
1456         if (tim->dtim_count == 0) {
1457                 ATH10K_SKB_CB(bcn)->bcn.dtim_zero = true;
1458
1459                 if (__le32_to_cpu(bcn_info->tim_info.tim_mcast) == 1)
1460                         ATH10K_SKB_CB(bcn)->bcn.deliver_cab = true;
1461         }
1462
1463         ath10k_dbg(ar, ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
1464                    tim->dtim_count, tim->dtim_period,
1465                    tim->bitmap_ctrl, pvm_len);
1466 }
1467
1468 static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
1469                                    struct wmi_p2p_noa_info *noa)
1470 {
1471         struct ieee80211_p2p_noa_attr *noa_attr;
1472         u8  ctwindow_oppps = noa->ctwindow_oppps;
1473         u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
1474         bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
1475         __le16 *noa_attr_len;
1476         u16 attr_len;
1477         u8 noa_descriptors = noa->num_descriptors;
1478         int i;
1479
1480         /* P2P IE */
1481         data[0] = WLAN_EID_VENDOR_SPECIFIC;
1482         data[1] = len - 2;
1483         data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1484         data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1485         data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1486         data[5] = WLAN_OUI_TYPE_WFA_P2P;
1487
1488         /* NOA ATTR */
1489         data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
1490         noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
1491         noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
1492
1493         noa_attr->index = noa->index;
1494         noa_attr->oppps_ctwindow = ctwindow;
1495         if (oppps)
1496                 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
1497
1498         for (i = 0; i < noa_descriptors; i++) {
1499                 noa_attr->desc[i].count =
1500                         __le32_to_cpu(noa->descriptors[i].type_count);
1501                 noa_attr->desc[i].duration = noa->descriptors[i].duration;
1502                 noa_attr->desc[i].interval = noa->descriptors[i].interval;
1503                 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
1504         }
1505
1506         attr_len = 2; /* index + oppps_ctwindow */
1507         attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1508         *noa_attr_len = __cpu_to_le16(attr_len);
1509 }
1510
1511 static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
1512 {
1513         u32 len = 0;
1514         u8 noa_descriptors = noa->num_descriptors;
1515         u8 opp_ps_info = noa->ctwindow_oppps;
1516         bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
1517
1518         if (!noa_descriptors && !opps_enabled)
1519                 return len;
1520
1521         len += 1 + 1 + 4; /* EID + len + OUI */
1522         len += 1 + 2; /* noa attr  + attr len */
1523         len += 1 + 1; /* index + oppps_ctwindow */
1524         len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1525
1526         return len;
1527 }
1528
1529 static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
1530                                   struct sk_buff *bcn,
1531                                   struct wmi_bcn_info *bcn_info)
1532 {
1533         struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
1534         u8 *new_data, *old_data = arvif->u.ap.noa_data;
1535         u32 new_len;
1536
1537         if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1538                 return;
1539
1540         ath10k_dbg(ar, ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
1541         if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
1542                 new_len = ath10k_p2p_calc_noa_ie_len(noa);
1543                 if (!new_len)
1544                         goto cleanup;
1545
1546                 new_data = kmalloc(new_len, GFP_ATOMIC);
1547                 if (!new_data)
1548                         goto cleanup;
1549
1550                 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
1551
1552                 spin_lock_bh(&ar->data_lock);
1553                 arvif->u.ap.noa_data = new_data;
1554                 arvif->u.ap.noa_len = new_len;
1555                 spin_unlock_bh(&ar->data_lock);
1556                 kfree(old_data);
1557         }
1558
1559         if (arvif->u.ap.noa_data)
1560                 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
1561                         memcpy(skb_put(bcn, arvif->u.ap.noa_len),
1562                                arvif->u.ap.noa_data,
1563                                arvif->u.ap.noa_len);
1564         return;
1565
1566 cleanup:
1567         spin_lock_bh(&ar->data_lock);
1568         arvif->u.ap.noa_data = NULL;
1569         arvif->u.ap.noa_len = 0;
1570         spin_unlock_bh(&ar->data_lock);
1571         kfree(old_data);
1572 }
1573
1574 static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1575 {
1576         struct wmi_host_swba_event *ev;
1577         u32 map;
1578         int i = -1;
1579         struct wmi_bcn_info *bcn_info;
1580         struct ath10k_vif *arvif;
1581         struct sk_buff *bcn;
1582         dma_addr_t paddr;
1583         int ret, vdev_id = 0;
1584
1585         ev = (struct wmi_host_swba_event *)skb->data;
1586         map = __le32_to_cpu(ev->vdev_map);
1587
1588         ath10k_dbg(ar, ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
1589                    ev->vdev_map);
1590
1591         for (; map; map >>= 1, vdev_id++) {
1592                 if (!(map & 0x1))
1593                         continue;
1594
1595                 i++;
1596
1597                 if (i >= WMI_MAX_AP_VDEV) {
1598                         ath10k_warn(ar, "swba has corrupted vdev map\n");
1599                         break;
1600                 }
1601
1602                 bcn_info = &ev->bcn_info[i];
1603
1604                 ath10k_dbg(ar, ATH10K_DBG_MGMT,
1605                            "mgmt event bcn_info %d tim_len %d mcast %d changed %d num_ps_pending %d bitmap 0x%08x%08x%08x%08x\n",
1606                            i,
1607                            __le32_to_cpu(bcn_info->tim_info.tim_len),
1608                            __le32_to_cpu(bcn_info->tim_info.tim_mcast),
1609                            __le32_to_cpu(bcn_info->tim_info.tim_changed),
1610                            __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
1611                            __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
1612                            __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
1613                            __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
1614                            __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
1615
1616                 arvif = ath10k_get_arvif(ar, vdev_id);
1617                 if (arvif == NULL) {
1618                         ath10k_warn(ar, "no vif for vdev_id %d found\n",
1619                                     vdev_id);
1620                         continue;
1621                 }
1622
1623                 /* There are no completions for beacons so wait for next SWBA
1624                  * before telling mac80211 to decrement CSA counter
1625                  *
1626                  * Once CSA counter is completed stop sending beacons until
1627                  * actual channel switch is done */
1628                 if (arvif->vif->csa_active &&
1629                     ieee80211_csa_is_complete(arvif->vif)) {
1630                         ieee80211_csa_finish(arvif->vif);
1631                         continue;
1632                 }
1633
1634                 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
1635                 if (!bcn) {
1636                         ath10k_warn(ar, "could not get mac80211 beacon\n");
1637                         continue;
1638                 }
1639
1640                 ath10k_tx_h_seq_no(arvif->vif, bcn);
1641                 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
1642                 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
1643
1644                 spin_lock_bh(&ar->data_lock);
1645
1646                 if (arvif->beacon) {
1647                         if (!arvif->beacon_sent)
1648                                 ath10k_warn(ar, "SWBA overrun on vdev %d\n",
1649                                             arvif->vdev_id);
1650
1651                         ath10k_mac_vif_beacon_free(arvif);
1652                 }
1653
1654                 if (!arvif->beacon_buf) {
1655                         paddr = dma_map_single(arvif->ar->dev, bcn->data,
1656                                                bcn->len, DMA_TO_DEVICE);
1657                         ret = dma_mapping_error(arvif->ar->dev, paddr);
1658                         if (ret) {
1659                                 ath10k_warn(ar, "failed to map beacon: %d\n",
1660                                             ret);
1661                                 dev_kfree_skb_any(bcn);
1662                                 goto skip;
1663                         }
1664
1665                         ATH10K_SKB_CB(bcn)->paddr = paddr;
1666                 } else {
1667                         if (bcn->len > IEEE80211_MAX_FRAME_LEN) {
1668                                 ath10k_warn(ar, "trimming beacon %d -> %d bytes!\n",
1669                                             bcn->len, IEEE80211_MAX_FRAME_LEN);
1670                                 skb_trim(bcn, IEEE80211_MAX_FRAME_LEN);
1671                         }
1672                         memcpy(arvif->beacon_buf, bcn->data, bcn->len);
1673                         ATH10K_SKB_CB(bcn)->paddr = arvif->beacon_paddr;
1674                 }
1675
1676                 arvif->beacon = bcn;
1677                 arvif->beacon_sent = false;
1678
1679                 ath10k_wmi_tx_beacon_nowait(arvif);
1680 skip:
1681                 spin_unlock_bh(&ar->data_lock);
1682         }
1683 }
1684
1685 static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
1686                                                struct sk_buff *skb)
1687 {
1688         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
1689 }
1690
1691 static void ath10k_dfs_radar_report(struct ath10k *ar,
1692                                     struct wmi_single_phyerr_rx_event *event,
1693                                     struct phyerr_radar_report *rr,
1694                                     u64 tsf)
1695 {
1696         u32 reg0, reg1, tsf32l;
1697         struct pulse_event pe;
1698         u64 tsf64;
1699         u8 rssi, width;
1700
1701         reg0 = __le32_to_cpu(rr->reg0);
1702         reg1 = __le32_to_cpu(rr->reg1);
1703
1704         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1705                    "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
1706                    MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
1707                    MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
1708                    MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
1709                    MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
1710         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1711                    "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
1712                    MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
1713                    MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
1714                    MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
1715                    MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
1716                    MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
1717         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1718                    "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
1719                    MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
1720                    MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
1721
1722         if (!ar->dfs_detector)
1723                 return;
1724
1725         /* report event to DFS pattern detector */
1726         tsf32l = __le32_to_cpu(event->hdr.tsf_timestamp);
1727         tsf64 = tsf & (~0xFFFFFFFFULL);
1728         tsf64 |= tsf32l;
1729
1730         width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
1731         rssi = event->hdr.rssi_combined;
1732
1733         /* hardware store this as 8 bit signed value,
1734          * set to zero if negative number
1735          */
1736         if (rssi & 0x80)
1737                 rssi = 0;
1738
1739         pe.ts = tsf64;
1740         pe.freq = ar->hw->conf.chandef.chan->center_freq;
1741         pe.width = width;
1742         pe.rssi = rssi;
1743
1744         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1745                    "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
1746                    pe.freq, pe.width, pe.rssi, pe.ts);
1747
1748         ATH10K_DFS_STAT_INC(ar, pulses_detected);
1749
1750         if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
1751                 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1752                            "dfs no pulse pattern detected, yet\n");
1753                 return;
1754         }
1755
1756         ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs radar detected\n");
1757         ATH10K_DFS_STAT_INC(ar, radar_detected);
1758
1759         /* Control radar events reporting in debugfs file
1760            dfs_block_radar_events */
1761         if (ar->dfs_block_radar_events) {
1762                 ath10k_info(ar, "DFS Radar detected, but ignored as requested\n");
1763                 return;
1764         }
1765
1766         ieee80211_radar_detected(ar->hw);
1767 }
1768
1769 static int ath10k_dfs_fft_report(struct ath10k *ar,
1770                                  struct wmi_single_phyerr_rx_event *event,
1771                                  struct phyerr_fft_report *fftr,
1772                                  u64 tsf)
1773 {
1774         u32 reg0, reg1;
1775         u8 rssi, peak_mag;
1776
1777         reg0 = __le32_to_cpu(fftr->reg0);
1778         reg1 = __le32_to_cpu(fftr->reg1);
1779         rssi = event->hdr.rssi_combined;
1780
1781         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1782                    "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
1783                    MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
1784                    MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
1785                    MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
1786                    MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
1787         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1788                    "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
1789                    MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
1790                    MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
1791                    MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
1792                    MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
1793
1794         peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
1795
1796         /* false event detection */
1797         if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
1798             peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
1799                 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
1800                 ATH10K_DFS_STAT_INC(ar, pulses_discarded);
1801                 return -EINVAL;
1802         }
1803
1804         return 0;
1805 }
1806
1807 static void ath10k_wmi_event_dfs(struct ath10k *ar,
1808                                  struct wmi_single_phyerr_rx_event *event,
1809                                  u64 tsf)
1810 {
1811         int buf_len, tlv_len, res, i = 0;
1812         struct phyerr_tlv *tlv;
1813         struct phyerr_radar_report *rr;
1814         struct phyerr_fft_report *fftr;
1815         u8 *tlv_buf;
1816
1817         buf_len = __le32_to_cpu(event->hdr.buf_len);
1818         ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1819                    "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
1820                    event->hdr.phy_err_code, event->hdr.rssi_combined,
1821                    __le32_to_cpu(event->hdr.tsf_timestamp), tsf, buf_len);
1822
1823         /* Skip event if DFS disabled */
1824         if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED))
1825                 return;
1826
1827         ATH10K_DFS_STAT_INC(ar, pulses_total);
1828
1829         while (i < buf_len) {
1830                 if (i + sizeof(*tlv) > buf_len) {
1831                         ath10k_warn(ar, "too short buf for tlv header (%d)\n",
1832                                     i);
1833                         return;
1834                 }
1835
1836                 tlv = (struct phyerr_tlv *)&event->bufp[i];
1837                 tlv_len = __le16_to_cpu(tlv->len);
1838                 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1839                 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
1840                            "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
1841                            tlv_len, tlv->tag, tlv->sig);
1842
1843                 switch (tlv->tag) {
1844                 case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
1845                         if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
1846                                 ath10k_warn(ar, "too short radar pulse summary (%d)\n",
1847                                             i);
1848                                 return;
1849                         }
1850
1851                         rr = (struct phyerr_radar_report *)tlv_buf;
1852                         ath10k_dfs_radar_report(ar, event, rr, tsf);
1853                         break;
1854                 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1855                         if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
1856                                 ath10k_warn(ar, "too short fft report (%d)\n",
1857                                             i);
1858                                 return;
1859                         }
1860
1861                         fftr = (struct phyerr_fft_report *)tlv_buf;
1862                         res = ath10k_dfs_fft_report(ar, event, fftr, tsf);
1863                         if (res)
1864                                 return;
1865                         break;
1866                 }
1867
1868                 i += sizeof(*tlv) + tlv_len;
1869         }
1870 }
1871
1872 static void
1873 ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1874                                struct wmi_single_phyerr_rx_event *event,
1875                                u64 tsf)
1876 {
1877         int buf_len, tlv_len, res, i = 0;
1878         struct phyerr_tlv *tlv;
1879         u8 *tlv_buf;
1880         struct phyerr_fft_report *fftr;
1881         size_t fftr_len;
1882
1883         buf_len = __le32_to_cpu(event->hdr.buf_len);
1884
1885         while (i < buf_len) {
1886                 if (i + sizeof(*tlv) > buf_len) {
1887                         ath10k_warn(ar, "failed to parse phyerr tlv header at byte %d\n",
1888                                     i);
1889                         return;
1890                 }
1891
1892                 tlv = (struct phyerr_tlv *)&event->bufp[i];
1893                 tlv_len = __le16_to_cpu(tlv->len);
1894                 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1895
1896                 if (i + sizeof(*tlv) + tlv_len > buf_len) {
1897                         ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n",
1898                                     i);
1899                         return;
1900                 }
1901
1902                 switch (tlv->tag) {
1903                 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1904                         if (sizeof(*fftr) > tlv_len) {
1905                                 ath10k_warn(ar, "failed to parse fft report at byte %d\n",
1906                                             i);
1907                                 return;
1908                         }
1909
1910                         fftr_len = tlv_len - sizeof(*fftr);
1911                         fftr = (struct phyerr_fft_report *)tlv_buf;
1912                         res = ath10k_spectral_process_fft(ar, event,
1913                                                           fftr, fftr_len,
1914                                                           tsf);
1915                         if (res < 0) {
1916                                 ath10k_warn(ar, "failed to process fft report: %d\n",
1917                                             res);
1918                                 return;
1919                         }
1920                         break;
1921                 }
1922
1923                 i += sizeof(*tlv) + tlv_len;
1924         }
1925 }
1926
1927 static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1928 {
1929         struct wmi_comb_phyerr_rx_event *comb_event;
1930         struct wmi_single_phyerr_rx_event *event;
1931         u32 count, i, buf_len, phy_err_code;
1932         u64 tsf;
1933         int left_len = skb->len;
1934
1935         ATH10K_DFS_STAT_INC(ar, phy_errors);
1936
1937         /* Check if combined event available */
1938         if (left_len < sizeof(*comb_event)) {
1939                 ath10k_warn(ar, "wmi phyerr combined event wrong len\n");
1940                 return;
1941         }
1942
1943         left_len -= sizeof(*comb_event);
1944
1945         /* Check number of included events */
1946         comb_event = (struct wmi_comb_phyerr_rx_event *)skb->data;
1947         count = __le32_to_cpu(comb_event->hdr.num_phyerr_events);
1948
1949         tsf = __le32_to_cpu(comb_event->hdr.tsf_u32);
1950         tsf <<= 32;
1951         tsf |= __le32_to_cpu(comb_event->hdr.tsf_l32);
1952
1953         ath10k_dbg(ar, ATH10K_DBG_WMI,
1954                    "wmi event phyerr count %d tsf64 0x%llX\n",
1955                    count, tsf);
1956
1957         event = (struct wmi_single_phyerr_rx_event *)comb_event->bufp;
1958         for (i = 0; i < count; i++) {
1959                 /* Check if we can read event header */
1960                 if (left_len < sizeof(*event)) {
1961                         ath10k_warn(ar, "single event (%d) wrong head len\n",
1962                                     i);
1963                         return;
1964                 }
1965
1966                 left_len -= sizeof(*event);
1967
1968                 buf_len = __le32_to_cpu(event->hdr.buf_len);
1969                 phy_err_code = event->hdr.phy_err_code;
1970
1971                 if (left_len < buf_len) {
1972                         ath10k_warn(ar, "single event (%d) wrong buf len\n", i);
1973                         return;
1974                 }
1975
1976                 left_len -= buf_len;
1977
1978                 switch (phy_err_code) {
1979                 case PHY_ERROR_RADAR:
1980                         ath10k_wmi_event_dfs(ar, event, tsf);
1981                         break;
1982                 case PHY_ERROR_SPECTRAL_SCAN:
1983                         ath10k_wmi_event_spectral_scan(ar, event, tsf);
1984                         break;
1985                 case PHY_ERROR_FALSE_RADAR_EXT:
1986                         ath10k_wmi_event_dfs(ar, event, tsf);
1987                         ath10k_wmi_event_spectral_scan(ar, event, tsf);
1988                         break;
1989                 default:
1990                         break;
1991                 }
1992
1993                 event += sizeof(*event) + buf_len;
1994         }
1995 }
1996
1997 static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
1998 {
1999         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
2000 }
2001
2002 static void ath10k_wmi_event_profile_match(struct ath10k *ar,
2003                                            struct sk_buff *skb)
2004 {
2005         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
2006 }
2007
2008 static void ath10k_wmi_event_debug_print(struct ath10k *ar,
2009                                          struct sk_buff *skb)
2010 {
2011         char buf[101], c;
2012         int i;
2013
2014         for (i = 0; i < sizeof(buf) - 1; i++) {
2015                 if (i >= skb->len)
2016                         break;
2017
2018                 c = skb->data[i];
2019
2020                 if (c == '\0')
2021                         break;
2022
2023                 if (isascii(c) && isprint(c))
2024                         buf[i] = c;
2025                 else
2026                         buf[i] = '.';
2027         }
2028
2029         if (i == sizeof(buf) - 1)
2030                 ath10k_warn(ar, "wmi debug print truncated: %d\n", skb->len);
2031
2032         /* for some reason the debug prints end with \n, remove that */
2033         if (skb->data[i - 1] == '\n')
2034                 i--;
2035
2036         /* the last byte is always reserved for the null character */
2037         buf[i] = '\0';
2038
2039         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event debug print '%s'\n", buf);
2040 }
2041
2042 static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
2043 {
2044         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
2045 }
2046
2047 static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
2048                                                struct sk_buff *skb)
2049 {
2050         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
2051 }
2052
2053 static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
2054                                                     struct sk_buff *skb)
2055 {
2056         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
2057 }
2058
2059 static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
2060                                                     struct sk_buff *skb)
2061 {
2062         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
2063 }
2064
2065 static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
2066                                               struct sk_buff *skb)
2067 {
2068         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
2069 }
2070
2071 static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
2072                                              struct sk_buff *skb)
2073 {
2074         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
2075 }
2076
2077 static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
2078                                               struct sk_buff *skb)
2079 {
2080         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
2081 }
2082
2083 static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
2084                                              struct sk_buff *skb)
2085 {
2086         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
2087 }
2088
2089 static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
2090                                            struct sk_buff *skb)
2091 {
2092         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
2093 }
2094
2095 static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
2096                                                 struct sk_buff *skb)
2097 {
2098         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
2099 }
2100
2101 static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
2102                                             struct sk_buff *skb)
2103 {
2104         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
2105 }
2106
2107 static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
2108                                             struct sk_buff *skb)
2109 {
2110         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
2111 }
2112
2113 static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
2114                                             struct sk_buff *skb)
2115 {
2116         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
2117 }
2118
2119 static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
2120                                                        struct sk_buff *skb)
2121 {
2122         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
2123 }
2124
2125 static void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar,
2126                                              struct sk_buff *skb)
2127 {
2128         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
2129 }
2130
2131 static void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar,
2132                                               struct sk_buff *skb)
2133 {
2134         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
2135 }
2136
2137 static void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar,
2138                                              struct sk_buff *skb)
2139 {
2140         ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
2141 }
2142
2143 static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
2144                                      u32 num_units, u32 unit_len)
2145 {
2146         dma_addr_t paddr;
2147         u32 pool_size;
2148         int idx = ar->wmi.num_mem_chunks;
2149
2150         pool_size = num_units * round_up(unit_len, 4);
2151
2152         if (!pool_size)
2153                 return -EINVAL;
2154
2155         ar->wmi.mem_chunks[idx].vaddr = dma_alloc_coherent(ar->dev,
2156                                                            pool_size,
2157                                                            &paddr,
2158                                                            GFP_ATOMIC);
2159         if (!ar->wmi.mem_chunks[idx].vaddr) {
2160                 ath10k_warn(ar, "failed to allocate memory chunk\n");
2161                 return -ENOMEM;
2162         }
2163
2164         memset(ar->wmi.mem_chunks[idx].vaddr, 0, pool_size);
2165
2166         ar->wmi.mem_chunks[idx].paddr = paddr;
2167         ar->wmi.mem_chunks[idx].len = pool_size;
2168         ar->wmi.mem_chunks[idx].req_id = req_id;
2169         ar->wmi.num_mem_chunks++;
2170
2171         return 0;
2172 }
2173
2174 static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
2175                                               struct sk_buff *skb)
2176 {
2177         struct wmi_service_ready_event *ev = (void *)skb->data;
2178         DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {};
2179
2180         if (skb->len < sizeof(*ev)) {
2181                 ath10k_warn(ar, "Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2182                             skb->len, sizeof(*ev));
2183                 return;
2184         }
2185
2186         ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2187         ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2188         ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2189         ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2190         ar->fw_version_major =
2191                 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2192         ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2193         ar->fw_version_release =
2194                 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
2195         ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
2196         ar->phy_capability = __le32_to_cpu(ev->phy_capability);
2197         ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2198
2199         /* only manually set fw features when not using FW IE format */
2200         if (ar->fw_api == 1 && ar->fw_version_build > 636)
2201                 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
2202
2203         if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2204                 ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
2205                             ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2206                 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2207         }
2208
2209         ar->supp_tx_chainmask = (1 << ar->num_rf_chains) - 1;
2210         ar->supp_rx_chainmask = (1 << ar->num_rf_chains) - 1;
2211
2212         ar->ath_common.regulatory.current_rd =
2213                 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2214
2215         wmi_main_svc_map(ev->wmi_service_bitmap, svc_bmap);
2216         ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2217         ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
2218                         ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
2219
2220         if (strlen(ar->hw->wiphy->fw_version) == 0) {
2221                 snprintf(ar->hw->wiphy->fw_version,
2222                          sizeof(ar->hw->wiphy->fw_version),
2223                          "%u.%u.%u.%u",
2224                          ar->fw_version_major,
2225                          ar->fw_version_minor,
2226                          ar->fw_version_release,
2227                          ar->fw_version_build);
2228         }
2229
2230         /* FIXME: it probably should be better to support this */
2231         if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
2232                 ath10k_warn(ar, "target requested %d memory chunks; ignoring\n",
2233                             __le32_to_cpu(ev->num_mem_reqs));
2234         }
2235
2236         ath10k_dbg(ar, ATH10K_DBG_WMI,
2237                    "wmi event service ready sw_ver 0x%08x sw_ver1 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u num_rf_chains %u\n",
2238                    __le32_to_cpu(ev->sw_version),
2239                    __le32_to_cpu(ev->sw_version_1),
2240                    __le32_to_cpu(ev->abi_version),
2241                    __le32_to_cpu(ev->phy_capability),
2242                    __le32_to_cpu(ev->ht_cap_info),
2243                    __le32_to_cpu(ev->vht_cap_info),
2244                    __le32_to_cpu(ev->vht_supp_mcs),
2245                    __le32_to_cpu(ev->sys_cap_info),
2246                    __le32_to_cpu(ev->num_mem_reqs),
2247                    __le32_to_cpu(ev->num_rf_chains));
2248
2249         complete(&ar->wmi.service_ready);
2250 }
2251
2252 static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2253                                                   struct sk_buff *skb)
2254 {
2255         u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
2256         int ret;
2257         struct wmi_service_ready_event_10x *ev = (void *)skb->data;
2258         DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {};
2259
2260         if (skb->len < sizeof(*ev)) {
2261                 ath10k_warn(ar, "Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2262                             skb->len, sizeof(*ev));
2263                 return;
2264         }
2265
2266         ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2267         ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2268         ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2269         ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2270         ar->fw_version_major =
2271                 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2272         ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2273         ar->phy_capability = __le32_to_cpu(ev->phy_capability);
2274         ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2275
2276         if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2277                 ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
2278                             ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2279                 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2280         }
2281
2282         ar->supp_tx_chainmask = (1 << ar->num_rf_chains) - 1;
2283         ar->supp_rx_chainmask = (1 << ar->num_rf_chains) - 1;
2284
2285         ar->ath_common.regulatory.current_rd =
2286                 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2287
2288         wmi_10x_svc_map(ev->wmi_service_bitmap, svc_bmap);
2289         ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2290         ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
2291                         ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
2292
2293         if (strlen(ar->hw->wiphy->fw_version) == 0) {
2294                 snprintf(ar->hw->wiphy->fw_version,
2295                          sizeof(ar->hw->wiphy->fw_version),
2296                          "%u.%u",
2297                          ar->fw_version_major,
2298                          ar->fw_version_minor);
2299         }
2300
2301         num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
2302
2303         if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
2304                 ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n",
2305                             num_mem_reqs);
2306                 return;
2307         }
2308
2309         if (!num_mem_reqs)
2310                 goto exit;
2311
2312         ath10k_dbg(ar, ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
2313                    num_mem_reqs);
2314
2315         for (i = 0; i < num_mem_reqs; ++i) {
2316                 req_id = __le32_to_cpu(ev->mem_reqs[i].req_id);
2317                 num_units = __le32_to_cpu(ev->mem_reqs[i].num_units);
2318                 unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size);
2319                 num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info);
2320
2321                 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
2322                         /* number of units to allocate is number of
2323                          * peers, 1 extra for self peer on target */
2324                         /* this needs to be tied, host and target
2325                          * can get out of sync */
2326                         num_units = TARGET_10X_NUM_PEERS + 1;
2327                 else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS)
2328                         num_units = TARGET_10X_NUM_VDEVS + 1;
2329
2330                 ath10k_dbg(ar, ATH10K_DBG_WMI,
2331                            "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
2332                            req_id,
2333                            __le32_to_cpu(ev->mem_reqs[i].num_units),
2334                            num_unit_info,
2335                            unit_size,
2336                            num_units);
2337
2338                 ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
2339                                                 unit_size);
2340                 if (ret)
2341                         return;
2342         }
2343
2344 exit:
2345         ath10k_dbg(ar, ATH10K_DBG_WMI,
2346                    "wmi event service ready sw_ver 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u num_rf_chains %u\n",
2347                    __le32_to_cpu(ev->sw_version),
2348                    __le32_to_cpu(ev->abi_version),
2349                    __le32_to_cpu(ev->phy_capability),
2350                    __le32_to_cpu(ev->ht_cap_info),
2351                    __le32_to_cpu(ev->vht_cap_info),
2352                    __le32_to_cpu(ev->vht_supp_mcs),
2353                    __le32_to_cpu(ev->sys_cap_info),
2354                    __le32_to_cpu(ev->num_mem_reqs),
2355                    __le32_to_cpu(ev->num_rf_chains));
2356
2357         complete(&ar->wmi.service_ready);
2358 }
2359
2360 static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
2361 {
2362         struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
2363
2364         if (WARN_ON(skb->len < sizeof(*ev)))
2365                 return -EINVAL;
2366
2367         ether_addr_copy(ar->mac_addr, ev->mac_addr.addr);
2368
2369         ath10k_dbg(ar, ATH10K_DBG_WMI,
2370                    "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d skb->len %i ev-sz %zu\n",
2371                    __le32_to_cpu(ev->sw_version),
2372                    __le32_to_cpu(ev->abi_version),
2373                    ev->mac_addr.addr,
2374                    __le32_to_cpu(ev->status), skb->len, sizeof(*ev));
2375
2376         complete(&ar->wmi.unified_ready);
2377         return 0;
2378 }
2379
2380 static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
2381 {
2382         struct wmi_cmd_hdr *cmd_hdr;
2383         enum wmi_event_id id;
2384
2385         cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2386         id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2387
2388         if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2389                 return;
2390
2391         trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
2392
2393         switch (id) {
2394         case WMI_MGMT_RX_EVENTID:
2395                 ath10k_wmi_event_mgmt_rx(ar, skb);
2396                 /* mgmt_rx() owns the skb now! */
2397                 return;
2398         case WMI_SCAN_EVENTID:
2399                 ath10k_wmi_event_scan(ar, skb);
2400                 break;
2401         case WMI_CHAN_INFO_EVENTID:
2402                 ath10k_wmi_event_chan_info(ar, skb);
2403                 break;
2404         case WMI_ECHO_EVENTID:
2405                 ath10k_wmi_event_echo(ar, skb);
2406                 break;
2407         case WMI_DEBUG_MESG_EVENTID:
2408                 ath10k_wmi_event_debug_mesg(ar, skb);
2409                 break;
2410         case WMI_UPDATE_STATS_EVENTID:
2411                 ath10k_wmi_event_update_stats(ar, skb);
2412                 break;
2413         case WMI_VDEV_START_RESP_EVENTID:
2414                 ath10k_wmi_event_vdev_start_resp(ar, skb);
2415                 break;
2416         case WMI_VDEV_STOPPED_EVENTID:
2417                 ath10k_wmi_event_vdev_stopped(ar, skb);
2418                 break;
2419         case WMI_PEER_STA_KICKOUT_EVENTID:
2420                 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2421                 break;
2422         case WMI_HOST_SWBA_EVENTID:
2423                 ath10k_wmi_event_host_swba(ar, skb);
2424                 break;
2425         case WMI_TBTTOFFSET_UPDATE_EVENTID:
2426                 ath10k_wmi_event_tbttoffset_update(ar, skb);
2427                 break;
2428         case WMI_PHYERR_EVENTID:
2429                 ath10k_wmi_event_phyerr(ar, skb);
2430                 break;
2431         case WMI_ROAM_EVENTID:
2432                 ath10k_wmi_event_roam(ar, skb);
2433                 break;
2434         case WMI_PROFILE_MATCH:
2435                 ath10k_wmi_event_profile_match(ar, skb);
2436                 break;
2437         case WMI_DEBUG_PRINT_EVENTID:
2438                 ath10k_wmi_event_debug_print(ar, skb);
2439                 break;
2440         case WMI_PDEV_QVIT_EVENTID:
2441                 ath10k_wmi_event_pdev_qvit(ar, skb);
2442                 break;
2443         case WMI_WLAN_PROFILE_DATA_EVENTID:
2444                 ath10k_wmi_event_wlan_profile_data(ar, skb);
2445                 break;
2446         case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
2447                 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2448                 break;
2449         case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
2450                 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2451                 break;
2452         case WMI_RTT_ERROR_REPORT_EVENTID:
2453                 ath10k_wmi_event_rtt_error_report(ar, skb);
2454                 break;
2455         case WMI_WOW_WAKEUP_HOST_EVENTID:
2456                 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2457                 break;
2458         case WMI_DCS_INTERFERENCE_EVENTID:
2459                 ath10k_wmi_event_dcs_interference(ar, skb);
2460                 break;
2461         case WMI_PDEV_TPC_CONFIG_EVENTID:
2462                 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2463                 break;
2464         case WMI_PDEV_FTM_INTG_EVENTID:
2465                 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
2466                 break;
2467         case WMI_GTK_OFFLOAD_STATUS_EVENTID:
2468                 ath10k_wmi_event_gtk_offload_status(ar, skb);
2469                 break;
2470         case WMI_GTK_REKEY_FAIL_EVENTID:
2471                 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
2472                 break;
2473         case WMI_TX_DELBA_COMPLETE_EVENTID:
2474                 ath10k_wmi_event_delba_complete(ar, skb);
2475                 break;
2476         case WMI_TX_ADDBA_COMPLETE_EVENTID:
2477                 ath10k_wmi_event_addba_complete(ar, skb);
2478                 break;
2479         case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
2480                 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
2481                 break;
2482         case WMI_SERVICE_READY_EVENTID:
2483                 ath10k_wmi_service_ready_event_rx(ar, skb);
2484                 break;
2485         case WMI_READY_EVENTID:
2486                 ath10k_wmi_ready_event_rx(ar, skb);
2487                 break;
2488         default:
2489                 ath10k_warn(ar, "Unknown eventid: %d\n", id);
2490                 break;
2491         }
2492
2493         dev_kfree_skb(skb);
2494 }
2495
2496 static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
2497 {
2498         struct wmi_cmd_hdr *cmd_hdr;
2499         enum wmi_10x_event_id id;
2500         bool consumed;
2501
2502         cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2503         id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2504
2505         if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2506                 return;
2507
2508         trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
2509
2510         consumed = ath10k_tm_event_wmi(ar, id, skb);
2511
2512         /* Ready event must be handled normally also in UTF mode so that we
2513          * know the UTF firmware has booted, others we are just bypass WMI
2514          * events to testmode.
2515          */
2516         if (consumed && id != WMI_10X_READY_EVENTID) {
2517                 ath10k_dbg(ar, ATH10K_DBG_WMI,
2518                            "wmi testmode consumed 0x%x\n", id);
2519                 goto out;
2520         }
2521
2522         switch (id) {
2523         case WMI_10X_MGMT_RX_EVENTID:
2524                 ath10k_wmi_event_mgmt_rx(ar, skb);
2525                 /* mgmt_rx() owns the skb now! */
2526                 return;
2527         case WMI_10X_SCAN_EVENTID:
2528                 ath10k_wmi_event_scan(ar, skb);
2529                 break;
2530         case WMI_10X_CHAN_INFO_EVENTID:
2531                 ath10k_wmi_event_chan_info(ar, skb);
2532                 break;
2533         case WMI_10X_ECHO_EVENTID:
2534                 ath10k_wmi_event_echo(ar, skb);
2535                 break;
2536         case WMI_10X_DEBUG_MESG_EVENTID:
2537                 ath10k_wmi_event_debug_mesg(ar, skb);
2538                 break;
2539         case WMI_10X_UPDATE_STATS_EVENTID:
2540                 ath10k_wmi_event_update_stats(ar, skb);
2541                 break;
2542         case WMI_10X_VDEV_START_RESP_EVENTID:
2543                 ath10k_wmi_event_vdev_start_resp(ar, skb);
2544                 break;
2545         case WMI_10X_VDEV_STOPPED_EVENTID:
2546                 ath10k_wmi_event_vdev_stopped(ar, skb);
2547                 break;
2548         case WMI_10X_PEER_STA_KICKOUT_EVENTID:
2549                 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2550                 break;
2551         case WMI_10X_HOST_SWBA_EVENTID:
2552                 ath10k_wmi_event_host_swba(ar, skb);
2553                 break;
2554         case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
2555                 ath10k_wmi_event_tbttoffset_update(ar, skb);
2556                 break;
2557         case WMI_10X_PHYERR_EVENTID:
2558                 ath10k_wmi_event_phyerr(ar, skb);
2559                 break;
2560         case WMI_10X_ROAM_EVENTID:
2561                 ath10k_wmi_event_roam(ar, skb);
2562                 break;
2563         case WMI_10X_PROFILE_MATCH:
2564                 ath10k_wmi_event_profile_match(ar, skb);
2565                 break;
2566         case WMI_10X_DEBUG_PRINT_EVENTID:
2567                 ath10k_wmi_event_debug_print(ar, skb);
2568                 break;
2569         case WMI_10X_PDEV_QVIT_EVENTID:
2570                 ath10k_wmi_event_pdev_qvit(ar, skb);
2571                 break;
2572         case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
2573                 ath10k_wmi_event_wlan_profile_data(ar, skb);
2574                 break;
2575         case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
2576                 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2577                 break;
2578         case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
2579                 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2580                 break;
2581         case WMI_10X_RTT_ERROR_REPORT_EVENTID:
2582                 ath10k_wmi_event_rtt_error_report(ar, skb);
2583                 break;
2584         case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
2585                 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2586                 break;
2587         case WMI_10X_DCS_INTERFERENCE_EVENTID:
2588                 ath10k_wmi_event_dcs_interference(ar, skb);
2589                 break;
2590         case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
2591                 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2592                 break;
2593         case WMI_10X_INST_RSSI_STATS_EVENTID:
2594                 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2595                 break;
2596         case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
2597                 ath10k_wmi_event_vdev_standby_req(ar, skb);
2598                 break;
2599         case WMI_10X_VDEV_RESUME_REQ_EVENTID:
2600                 ath10k_wmi_event_vdev_resume_req(ar, skb);
2601                 break;
2602         case WMI_10X_SERVICE_READY_EVENTID:
2603                 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
2604                 break;
2605         case WMI_10X_READY_EVENTID:
2606                 ath10k_wmi_ready_event_rx(ar, skb);
2607                 break;
2608         case WMI_10X_PDEV_UTF_EVENTID:
2609                 /* ignore utf events */
2610                 break;
2611         default:
2612                 ath10k_warn(ar, "Unknown eventid: %d\n", id);
2613                 break;
2614         }
2615
2616 out:
2617         dev_kfree_skb(skb);
2618 }
2619
2620 static void ath10k_wmi_10_2_process_rx(struct ath10k *ar, struct sk_buff *skb)
2621 {
2622         struct wmi_cmd_hdr *cmd_hdr;
2623         enum wmi_10_2_event_id id;
2624
2625         cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2626         id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2627
2628         if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2629                 return;
2630
2631         trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
2632
2633         switch (id) {
2634         case WMI_10_2_MGMT_RX_EVENTID:
2635                 ath10k_wmi_event_mgmt_rx(ar, skb);
2636                 /* mgmt_rx() owns the skb now! */
2637                 return;
2638         case WMI_10_2_SCAN_EVENTID:
2639                 ath10k_wmi_event_scan(ar, skb);
2640                 break;
2641         case WMI_10_2_CHAN_INFO_EVENTID:
2642                 ath10k_wmi_event_chan_info(ar, skb);
2643                 break;
2644         case WMI_10_2_ECHO_EVENTID:
2645                 ath10k_wmi_event_echo(ar, skb);
2646                 break;
2647         case WMI_10_2_DEBUG_MESG_EVENTID:
2648                 ath10k_wmi_event_debug_mesg(ar, skb);
2649                 break;
2650         case WMI_10_2_UPDATE_STATS_EVENTID:
2651                 ath10k_wmi_event_update_stats(ar, skb);
2652                 break;
2653         case WMI_10_2_VDEV_START_RESP_EVENTID:
2654                 ath10k_wmi_event_vdev_start_resp(ar, skb);
2655                 break;
2656         case WMI_10_2_VDEV_STOPPED_EVENTID:
2657                 ath10k_wmi_event_vdev_stopped(ar, skb);
2658                 break;
2659         case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
2660                 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2661                 break;
2662         case WMI_10_2_HOST_SWBA_EVENTID:
2663                 ath10k_wmi_event_host_swba(ar, skb);
2664                 break;
2665         case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
2666                 ath10k_wmi_event_tbttoffset_update(ar, skb);
2667                 break;
2668         case WMI_10_2_PHYERR_EVENTID:
2669                 ath10k_wmi_event_phyerr(ar, skb);
2670                 break;
2671         case WMI_10_2_ROAM_EVENTID:
2672                 ath10k_wmi_event_roam(ar, skb);
2673                 break;
2674         case WMI_10_2_PROFILE_MATCH:
2675                 ath10k_wmi_event_profile_match(ar, skb);
2676                 break;
2677         case WMI_10_2_DEBUG_PRINT_EVENTID:
2678                 ath10k_wmi_event_debug_print(ar, skb);
2679                 break;
2680         case WMI_10_2_PDEV_QVIT_EVENTID:
2681                 ath10k_wmi_event_pdev_qvit(ar, skb);
2682                 break;
2683         case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
2684                 ath10k_wmi_event_wlan_profile_data(ar, skb);
2685                 break;
2686         case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
2687                 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2688                 break;
2689         case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
2690                 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2691                 break;
2692         case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
2693                 ath10k_wmi_event_rtt_error_report(ar, skb);
2694                 break;
2695         case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
2696                 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2697                 break;
2698         case WMI_10_2_DCS_INTERFERENCE_EVENTID:
2699                 ath10k_wmi_event_dcs_interference(ar, skb);
2700                 break;
2701         case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
2702                 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2703                 break;
2704         case WMI_10_2_INST_RSSI_STATS_EVENTID:
2705                 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2706                 break;
2707         case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
2708                 ath10k_wmi_event_vdev_standby_req(ar, skb);
2709                 break;
2710         case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
2711                 ath10k_wmi_event_vdev_resume_req(ar, skb);
2712                 break;
2713         case WMI_10_2_SERVICE_READY_EVENTID:
2714                 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
2715                 break;
2716         case WMI_10_2_READY_EVENTID:
2717                 ath10k_wmi_ready_event_rx(ar, skb);
2718                 break;
2719         case WMI_10_2_RTT_KEEPALIVE_EVENTID:
2720         case WMI_10_2_GPIO_INPUT_EVENTID:
2721         case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
2722         case WMI_10_2_GENERIC_BUFFER_EVENTID:
2723         case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
2724         case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
2725         case WMI_10_2_WDS_PEER_EVENTID:
2726                 ath10k_dbg(ar, ATH10K_DBG_WMI,
2727                            "received event id %d not implemented\n", id);
2728                 break;
2729         default:
2730                 ath10k_warn(ar, "Unknown eventid: %d\n", id);
2731                 break;
2732         }
2733
2734         dev_kfree_skb(skb);
2735 }
2736
2737 static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
2738 {
2739         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2740                 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2741                         ath10k_wmi_10_2_process_rx(ar, skb);
2742                 else
2743                         ath10k_wmi_10x_process_rx(ar, skb);
2744         } else {
2745                 ath10k_wmi_main_process_rx(ar, skb);
2746         }
2747 }
2748
2749 /* WMI Initialization functions */
2750 int ath10k_wmi_attach(struct ath10k *ar)
2751 {
2752         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2753                 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2754                         ar->wmi.cmd = &wmi_10_2_cmd_map;
2755                 else
2756                         ar->wmi.cmd = &wmi_10x_cmd_map;
2757
2758                 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
2759                 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
2760         } else {
2761                 ar->wmi.cmd = &wmi_cmd_map;
2762                 ar->wmi.vdev_param = &wmi_vdev_param_map;
2763                 ar->wmi.pdev_param = &wmi_pdev_param_map;
2764         }
2765
2766         init_completion(&ar->wmi.service_ready);
2767         init_completion(&ar->wmi.unified_ready);
2768         init_waitqueue_head(&ar->wmi.tx_credits_wq);
2769
2770         return 0;
2771 }
2772
2773 void ath10k_wmi_detach(struct ath10k *ar)
2774 {
2775         int i;
2776
2777         /* free the host memory chunks requested by firmware */
2778         for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2779                 dma_free_coherent(ar->dev,
2780                                   ar->wmi.mem_chunks[i].len,
2781                                   ar->wmi.mem_chunks[i].vaddr,
2782                                   ar->wmi.mem_chunks[i].paddr);
2783         }
2784
2785         ar->wmi.num_mem_chunks = 0;
2786 }
2787
2788 int ath10k_wmi_connect(struct ath10k *ar)
2789 {
2790         int status;
2791         struct ath10k_htc_svc_conn_req conn_req;
2792         struct ath10k_htc_svc_conn_resp conn_resp;
2793
2794         memset(&conn_req, 0, sizeof(conn_req));
2795         memset(&conn_resp, 0, sizeof(conn_resp));
2796
2797         /* these fields are the same for all service endpoints */
2798         conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
2799         conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
2800         conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
2801
2802         /* connect to control service */
2803         conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
2804
2805         status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
2806         if (status) {
2807                 ath10k_warn(ar, "failed to connect to WMI CONTROL service status: %d\n",
2808                             status);
2809                 return status;
2810         }
2811
2812         ar->wmi.eid = conn_resp.eid;
2813         return 0;
2814 }
2815
2816 static int ath10k_wmi_main_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2817                                               u16 rd2g, u16 rd5g, u16 ctl2g,
2818                                               u16 ctl5g)
2819 {
2820         struct wmi_pdev_set_regdomain_cmd *cmd;
2821         struct sk_buff *skb;
2822
2823         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
2824         if (!skb)
2825                 return -ENOMEM;
2826
2827         cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
2828         cmd->reg_domain = __cpu_to_le32(rd);
2829         cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2830         cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2831         cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2832         cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2833
2834         ath10k_dbg(ar, ATH10K_DBG_WMI,
2835                    "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
2836                    rd, rd2g, rd5g, ctl2g, ctl5g);
2837
2838         return ath10k_wmi_cmd_send(ar, skb,
2839                                    ar->wmi.cmd->pdev_set_regdomain_cmdid);
2840 }
2841
2842 static int ath10k_wmi_10x_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2843                                              u16 rd2g, u16 rd5g,
2844                                              u16 ctl2g, u16 ctl5g,
2845                                              enum wmi_dfs_region dfs_reg)
2846 {
2847         struct wmi_pdev_set_regdomain_cmd_10x *cmd;
2848         struct sk_buff *skb;
2849
2850         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
2851         if (!skb)
2852                 return -ENOMEM;
2853
2854         cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
2855         cmd->reg_domain = __cpu_to_le32(rd);
2856         cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2857         cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2858         cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2859         cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2860         cmd->dfs_domain = __cpu_to_le32(dfs_reg);
2861
2862         ath10k_dbg(ar, ATH10K_DBG_WMI,
2863                    "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
2864                    rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
2865
2866         return ath10k_wmi_cmd_send(ar, skb,
2867                                    ar->wmi.cmd->pdev_set_regdomain_cmdid);
2868 }
2869
2870 int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
2871                                   u16 rd5g, u16 ctl2g, u16 ctl5g,
2872                                   enum wmi_dfs_region dfs_reg)
2873 {
2874         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2875                 return ath10k_wmi_10x_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2876                                                         ctl2g, ctl5g, dfs_reg);
2877         else
2878                 return ath10k_wmi_main_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2879                                                          ctl2g, ctl5g);
2880 }
2881
2882 int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
2883                                 const struct wmi_channel_arg *arg)
2884 {
2885         struct wmi_set_channel_cmd *cmd;
2886         struct sk_buff *skb;
2887         u32 ch_flags = 0;
2888
2889         if (arg->passive)
2890                 return -EINVAL;
2891
2892         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
2893         if (!skb)
2894                 return -ENOMEM;
2895
2896         if (arg->chan_radar)
2897                 ch_flags |= WMI_CHAN_FLAG_DFS;
2898
2899         cmd = (struct wmi_set_channel_cmd *)skb->data;
2900         cmd->chan.mhz               = __cpu_to_le32(arg->freq);
2901         cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
2902         cmd->chan.mode              = arg->mode;
2903         cmd->chan.flags            |= __cpu_to_le32(ch_flags);
2904         cmd->chan.min_power         = arg->min_power;
2905         cmd->chan.max_power         = arg->max_power;
2906         cmd->chan.reg_power         = arg->max_reg_power;
2907         cmd->chan.reg_classid       = arg->reg_class_id;
2908         cmd->chan.antenna_max       = arg->max_antenna_gain;
2909
2910         ath10k_dbg(ar, ATH10K_DBG_WMI,
2911                    "wmi set channel mode %d freq %d\n",
2912                    arg->mode, arg->freq);
2913
2914         return ath10k_wmi_cmd_send(ar, skb,
2915                                    ar->wmi.cmd->pdev_set_channel_cmdid);
2916 }
2917
2918 int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt)
2919 {
2920         struct wmi_pdev_suspend_cmd *cmd;
2921         struct sk_buff *skb;
2922
2923         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
2924         if (!skb)
2925                 return -ENOMEM;
2926
2927         cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
2928         cmd->suspend_opt = __cpu_to_le32(suspend_opt);
2929
2930         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_suspend_cmdid);
2931 }
2932
2933 int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
2934 {
2935         struct sk_buff *skb;
2936
2937         skb = ath10k_wmi_alloc_skb(ar, 0);
2938         if (skb == NULL)
2939                 return -ENOMEM;
2940
2941         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_resume_cmdid);
2942 }
2943
2944 int ath10k_wmi_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
2945 {
2946         struct wmi_pdev_set_param_cmd *cmd;
2947         struct sk_buff *skb;
2948
2949         if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
2950                 ath10k_warn(ar, "pdev param %d not supported by firmware\n",
2951                             id);
2952                 return -EOPNOTSUPP;
2953         }
2954
2955         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
2956         if (!skb)
2957                 return -ENOMEM;
2958
2959         cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
2960         cmd->param_id    = __cpu_to_le32(id);
2961         cmd->param_value = __cpu_to_le32(value);
2962
2963         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
2964                    id, value);
2965         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
2966 }
2967
2968 static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
2969 {
2970         struct wmi_init_cmd *cmd;
2971         struct sk_buff *buf;
2972         struct wmi_resource_config config = {};
2973         u32 len, val;
2974         int i;
2975
2976         config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
2977         config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
2978         config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
2979
2980         config.num_offload_reorder_bufs =
2981                 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
2982
2983         config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
2984         config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
2985         config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
2986         config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
2987         config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
2988         config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2989         config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2990         config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2991         config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
2992         config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
2993
2994         config.scan_max_pending_reqs =
2995                 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
2996
2997         config.bmiss_offload_max_vdev =
2998                 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
2999
3000         config.roam_offload_max_vdev =
3001                 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
3002
3003         config.roam_offload_max_ap_profiles =
3004                 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
3005
3006         config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
3007         config.num_mcast_table_elems =
3008                 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
3009
3010         config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
3011         config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
3012         config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
3013         config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
3014         config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
3015
3016         val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
3017         config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3018
3019         config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
3020
3021         config.gtk_offload_max_vdev =
3022                 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
3023
3024         config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
3025         config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
3026
3027         len = sizeof(*cmd) +
3028               (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3029
3030         buf = ath10k_wmi_alloc_skb(ar, len);
3031         if (!buf)
3032                 return -ENOMEM;
3033
3034         cmd = (struct wmi_init_cmd *)buf->data;
3035
3036         if (ar->wmi.num_mem_chunks == 0) {
3037                 cmd->num_host_mem_chunks = 0;
3038                 goto out;
3039         }
3040
3041         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3042                    ar->wmi.num_mem_chunks);
3043
3044         cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3045
3046         for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3047                 cmd->host_mem_chunks[i].ptr =
3048                         __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3049                 cmd->host_mem_chunks[i].size =
3050                         __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3051                 cmd->host_mem_chunks[i].req_id =
3052                         __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3053
3054                 ath10k_dbg(ar, ATH10K_DBG_WMI,
3055                            "wmi chunk %d len %d requested, addr 0x%llx\n",
3056                            i,
3057                            ar->wmi.mem_chunks[i].len,
3058                            (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3059         }
3060 out:
3061         memcpy(&cmd->resource_config, &config, sizeof(config));
3062
3063         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n");
3064         return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3065 }
3066
3067 static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
3068 {
3069         struct wmi_init_cmd_10x *cmd;
3070         struct sk_buff *buf;
3071         struct wmi_resource_config_10x config = {};
3072         u32 len, val;
3073         int i;
3074
3075         config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3076         config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
3077         config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
3078         config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
3079         config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
3080         config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3081         config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3082         config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3083         config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3084         config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3085         config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3086         config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
3087
3088         config.scan_max_pending_reqs =
3089                 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
3090
3091         config.bmiss_offload_max_vdev =
3092                 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
3093
3094         config.roam_offload_max_vdev =
3095                 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
3096
3097         config.roam_offload_max_ap_profiles =
3098                 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
3099
3100         config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
3101         config.num_mcast_table_elems =
3102                 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
3103
3104         config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3105         config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3106         config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3107         config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3108         config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
3109
3110         val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
3111         config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3112
3113         config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
3114
3115         config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3116         config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
3117
3118         len = sizeof(*cmd) +
3119               (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3120
3121         buf = ath10k_wmi_alloc_skb(ar, len);
3122         if (!buf)
3123                 return -ENOMEM;
3124
3125         cmd = (struct wmi_init_cmd_10x *)buf->data;
3126
3127         if (ar->wmi.num_mem_chunks == 0) {
3128                 cmd->num_host_mem_chunks = 0;
3129                 goto out;
3130         }
3131
3132         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3133                    ar->wmi.num_mem_chunks);
3134
3135         cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3136
3137         for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3138                 cmd->host_mem_chunks[i].ptr =
3139                         __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3140                 cmd->host_mem_chunks[i].size =
3141                         __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3142                 cmd->host_mem_chunks[i].req_id =
3143                         __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3144
3145                 ath10k_dbg(ar, ATH10K_DBG_WMI,
3146                            "wmi chunk %d len %d requested, addr 0x%llx\n",
3147                            i,
3148                            ar->wmi.mem_chunks[i].len,
3149                            (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3150         }
3151 out:
3152         memcpy(&cmd->resource_config, &config, sizeof(config));
3153
3154         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n");
3155         return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3156 }
3157
3158 static int ath10k_wmi_10_2_cmd_init(struct ath10k *ar)
3159 {
3160         struct wmi_init_cmd_10_2 *cmd;
3161         struct sk_buff *buf;
3162         struct wmi_resource_config_10x config = {};
3163         u32 len, val;
3164         int i;
3165
3166         config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3167         config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
3168         config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
3169         config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
3170         config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
3171         config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3172         config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3173         config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3174         config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3175         config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3176         config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3177         config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
3178
3179         config.scan_max_pending_reqs =
3180                 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
3181
3182         config.bmiss_offload_max_vdev =
3183                 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
3184
3185         config.roam_offload_max_vdev =
3186                 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
3187
3188         config.roam_offload_max_ap_profiles =
3189                 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
3190
3191         config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
3192         config.num_mcast_table_elems =
3193                 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
3194
3195         config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3196         config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3197         config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3198         config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3199         config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
3200
3201         val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
3202         config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3203
3204         config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
3205
3206         config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3207         config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
3208
3209         len = sizeof(*cmd) +
3210               (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3211
3212         buf = ath10k_wmi_alloc_skb(ar, len);
3213         if (!buf)
3214                 return -ENOMEM;
3215
3216         cmd = (struct wmi_init_cmd_10_2 *)buf->data;
3217
3218         if (ar->wmi.num_mem_chunks == 0) {
3219                 cmd->num_host_mem_chunks = 0;
3220                 goto out;
3221         }
3222
3223         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3224                    ar->wmi.num_mem_chunks);
3225
3226         cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3227
3228         for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3229                 cmd->host_mem_chunks[i].ptr =
3230                         __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3231                 cmd->host_mem_chunks[i].size =
3232                         __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3233                 cmd->host_mem_chunks[i].req_id =
3234                         __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3235
3236                 ath10k_dbg(ar, ATH10K_DBG_WMI,
3237                            "wmi chunk %d len %d requested, addr 0x%llx\n",
3238                            i,
3239                            ar->wmi.mem_chunks[i].len,
3240                            (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3241         }
3242 out:
3243         memcpy(&cmd->resource_config.common, &config, sizeof(config));
3244
3245         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n");
3246         return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3247 }
3248
3249 int ath10k_wmi_cmd_init(struct ath10k *ar)
3250 {
3251         int ret;
3252
3253         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3254                 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3255                         ret = ath10k_wmi_10_2_cmd_init(ar);
3256                 else
3257                         ret = ath10k_wmi_10x_cmd_init(ar);
3258         } else {
3259                 ret = ath10k_wmi_main_cmd_init(ar);
3260         }
3261
3262         return ret;
3263 }
3264
3265 static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar,
3266                                           const struct wmi_start_scan_arg *arg)
3267 {
3268         int len;
3269
3270         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3271                 len = sizeof(struct wmi_start_scan_cmd_10x);
3272         else
3273                 len = sizeof(struct wmi_start_scan_cmd);
3274
3275         if (arg->ie_len) {
3276                 if (!arg->ie)
3277                         return -EINVAL;
3278                 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
3279                         return -EINVAL;
3280
3281                 len += sizeof(struct wmi_ie_data);
3282                 len += roundup(arg->ie_len, 4);
3283         }
3284
3285         if (arg->n_channels) {
3286                 if (!arg->channels)
3287                         return -EINVAL;
3288                 if (arg->n_channels > ARRAY_SIZE(arg->channels))
3289                         return -EINVAL;
3290
3291                 len += sizeof(struct wmi_chan_list);
3292                 len += sizeof(__le32) * arg->n_channels;
3293         }
3294
3295         if (arg->n_ssids) {
3296                 if (!arg->ssids)
3297                         return -EINVAL;
3298                 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
3299                         return -EINVAL;
3300
3301                 len += sizeof(struct wmi_ssid_list);
3302                 len += sizeof(struct wmi_ssid) * arg->n_ssids;
3303         }
3304
3305         if (arg->n_bssids) {
3306                 if (!arg->bssids)
3307                         return -EINVAL;
3308                 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
3309                         return -EINVAL;
3310
3311                 len += sizeof(struct wmi_bssid_list);
3312                 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3313         }
3314
3315         return len;
3316 }
3317
3318 int ath10k_wmi_start_scan(struct ath10k *ar,
3319                           const struct wmi_start_scan_arg *arg)
3320 {
3321         struct wmi_start_scan_cmd *cmd;
3322         struct sk_buff *skb;
3323         struct wmi_ie_data *ie;
3324         struct wmi_chan_list *channels;
3325         struct wmi_ssid_list *ssids;
3326         struct wmi_bssid_list *bssids;
3327         u32 scan_id;
3328         u32 scan_req_id;
3329         int off;
3330         int len = 0;
3331         int i;
3332
3333         len = ath10k_wmi_start_scan_calc_len(ar, arg);
3334         if (len < 0)
3335                 return len; /* len contains error code here */
3336
3337         skb = ath10k_wmi_alloc_skb(ar, len);
3338         if (!skb)
3339                 return -ENOMEM;
3340
3341         scan_id  = WMI_HOST_SCAN_REQ_ID_PREFIX;
3342         scan_id |= arg->scan_id;
3343
3344         scan_req_id  = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3345         scan_req_id |= arg->scan_req_id;
3346
3347         cmd = (struct wmi_start_scan_cmd *)skb->data;
3348         cmd->scan_id            = __cpu_to_le32(scan_id);
3349         cmd->scan_req_id        = __cpu_to_le32(scan_req_id);
3350         cmd->vdev_id            = __cpu_to_le32(arg->vdev_id);
3351         cmd->scan_priority      = __cpu_to_le32(arg->scan_priority);
3352         cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
3353         cmd->dwell_time_active  = __cpu_to_le32(arg->dwell_time_active);
3354         cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
3355         cmd->min_rest_time      = __cpu_to_le32(arg->min_rest_time);
3356         cmd->max_rest_time      = __cpu_to_le32(arg->max_rest_time);
3357         cmd->repeat_probe_time  = __cpu_to_le32(arg->repeat_probe_time);
3358         cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
3359         cmd->idle_time          = __cpu_to_le32(arg->idle_time);
3360         cmd->max_scan_time      = __cpu_to_le32(arg->max_scan_time);
3361         cmd->probe_delay        = __cpu_to_le32(arg->probe_delay);
3362         cmd->scan_ctrl_flags    = __cpu_to_le32(arg->scan_ctrl_flags);
3363
3364         /* TLV list starts after fields included in the struct */
3365         /* There's just one filed that differes the two start_scan
3366          * structures - burst_duration, which we are not using btw,
3367            no point to make the split here, just shift the buffer to fit with
3368            given FW */
3369         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3370                 off = sizeof(struct wmi_start_scan_cmd_10x);
3371         else
3372                 off = sizeof(struct wmi_start_scan_cmd);
3373
3374         if (arg->n_channels) {
3375                 channels = (void *)skb->data + off;
3376                 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
3377                 channels->num_chan = __cpu_to_le32(arg->n_channels);
3378
3379                 for (i = 0; i < arg->n_channels; i++)
3380                         channels->channel_list[i].freq =
3381                                 __cpu_to_le16(arg->channels[i]);
3382
3383                 off += sizeof(*channels);
3384                 off += sizeof(__le32) * arg->n_channels;
3385         }
3386
3387         if (arg->n_ssids) {
3388                 ssids = (void *)skb->data + off;
3389                 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
3390                 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
3391
3392                 for (i = 0; i < arg->n_ssids; i++) {
3393                         ssids->ssids[i].ssid_len =
3394                                 __cpu_to_le32(arg->ssids[i].len);
3395                         memcpy(&ssids->ssids[i].ssid,
3396                                arg->ssids[i].ssid,
3397                                arg->ssids[i].len);
3398                 }
3399
3400                 off += sizeof(*ssids);
3401                 off += sizeof(struct wmi_ssid) * arg->n_ssids;
3402         }
3403
3404         if (arg->n_bssids) {
3405                 bssids = (void *)skb->data + off;
3406                 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
3407                 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
3408
3409                 for (i = 0; i < arg->n_bssids; i++)
3410                         memcpy(&bssids->bssid_list[i],
3411                                arg->bssids[i].bssid,
3412                                ETH_ALEN);
3413
3414                 off += sizeof(*bssids);
3415                 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3416         }
3417
3418         if (arg->ie_len) {
3419                 ie = (void *)skb->data + off;
3420                 ie->tag = __cpu_to_le32(WMI_IE_TAG);
3421                 ie->ie_len = __cpu_to_le32(arg->ie_len);
3422                 memcpy(ie->ie_data, arg->ie, arg->ie_len);
3423
3424                 off += sizeof(*ie);
3425                 off += roundup(arg->ie_len, 4);
3426         }
3427
3428         if (off != skb->len) {
3429                 dev_kfree_skb(skb);
3430                 return -EINVAL;
3431         }
3432
3433         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n");
3434         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->start_scan_cmdid);
3435 }
3436
3437 void ath10k_wmi_start_scan_init(struct ath10k *ar,
3438                                 struct wmi_start_scan_arg *arg)
3439 {
3440         /* setup commonly used values */
3441         arg->scan_req_id = 1;
3442         arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
3443         arg->dwell_time_active = 50;
3444         arg->dwell_time_passive = 150;
3445         arg->min_rest_time = 50;
3446         arg->max_rest_time = 500;
3447         arg->repeat_probe_time = 0;
3448         arg->probe_spacing_time = 0;
3449         arg->idle_time = 0;
3450         arg->max_scan_time = 20000;
3451         arg->probe_delay = 5;
3452         arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
3453                 | WMI_SCAN_EVENT_COMPLETED
3454                 | WMI_SCAN_EVENT_BSS_CHANNEL
3455                 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
3456                 | WMI_SCAN_EVENT_DEQUEUED;
3457         arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
3458         arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
3459         arg->n_bssids = 1;
3460         arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
3461 }
3462
3463 int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
3464 {
3465         struct wmi_stop_scan_cmd *cmd;
3466         struct sk_buff *skb;
3467         u32 scan_id;
3468         u32 req_id;
3469
3470         if (arg->req_id > 0xFFF)
3471                 return -EINVAL;
3472         if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
3473                 return -EINVAL;
3474
3475         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3476         if (!skb)
3477                 return -ENOMEM;
3478
3479         scan_id = arg->u.scan_id;
3480         scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
3481
3482         req_id = arg->req_id;
3483         req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3484
3485         cmd = (struct wmi_stop_scan_cmd *)skb->data;
3486         cmd->req_type    = __cpu_to_le32(arg->req_type);
3487         cmd->vdev_id     = __cpu_to_le32(arg->u.vdev_id);
3488         cmd->scan_id     = __cpu_to_le32(scan_id);
3489         cmd->scan_req_id = __cpu_to_le32(req_id);
3490
3491         ath10k_dbg(ar, ATH10K_DBG_WMI,
3492                    "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
3493                    arg->req_id, arg->req_type, arg->u.scan_id);
3494         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->stop_scan_cmdid);
3495 }
3496
3497 int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
3498                            enum wmi_vdev_type type,
3499                            enum wmi_vdev_subtype subtype,
3500                            const u8 macaddr[ETH_ALEN])
3501 {
3502         struct wmi_vdev_create_cmd *cmd;
3503         struct sk_buff *skb;
3504
3505         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3506         if (!skb)
3507                 return -ENOMEM;
3508
3509         cmd = (struct wmi_vdev_create_cmd *)skb->data;
3510         cmd->vdev_id      = __cpu_to_le32(vdev_id);
3511         cmd->vdev_type    = __cpu_to_le32(type);
3512         cmd->vdev_subtype = __cpu_to_le32(subtype);
3513         ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
3514
3515         ath10k_dbg(ar, ATH10K_DBG_WMI,
3516                    "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
3517                    vdev_id, type, subtype, macaddr);
3518
3519         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_create_cmdid);
3520 }
3521
3522 int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
3523 {
3524         struct wmi_vdev_delete_cmd *cmd;
3525         struct sk_buff *skb;
3526
3527         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3528         if (!skb)
3529                 return -ENOMEM;
3530
3531         cmd = (struct wmi_vdev_delete_cmd *)skb->data;
3532         cmd->vdev_id = __cpu_to_le32(vdev_id);
3533
3534         ath10k_dbg(ar, ATH10K_DBG_WMI,
3535                    "WMI vdev delete id %d\n", vdev_id);
3536
3537         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_delete_cmdid);
3538 }
3539
3540 static int
3541 ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3542                               const struct wmi_vdev_start_request_arg *arg,
3543                               u32 cmd_id)
3544 {
3545         struct wmi_vdev_start_request_cmd *cmd;
3546         struct sk_buff *skb;
3547         const char *cmdname;
3548         u32 flags = 0;
3549         u32 ch_flags = 0;
3550
3551         if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
3552             cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
3553                 return -EINVAL;
3554         if (WARN_ON(arg->ssid && arg->ssid_len == 0))
3555                 return -EINVAL;
3556         if (WARN_ON(arg->hidden_ssid && !arg->ssid))
3557                 return -EINVAL;
3558         if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
3559                 return -EINVAL;
3560
3561         if (cmd_id == ar->wmi.cmd->vdev_start_request_cmdid)
3562                 cmdname = "start";
3563         else if (cmd_id == ar->wmi.cmd->vdev_restart_request_cmdid)
3564                 cmdname = "restart";
3565         else
3566                 return -EINVAL; /* should not happen, we already check cmd_id */
3567
3568         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3569         if (!skb)
3570                 return -ENOMEM;
3571
3572         if (arg->hidden_ssid)
3573                 flags |= WMI_VDEV_START_HIDDEN_SSID;
3574         if (arg->pmf_enabled)
3575                 flags |= WMI_VDEV_START_PMF_ENABLED;
3576         if (arg->channel.chan_radar)
3577                 ch_flags |= WMI_CHAN_FLAG_DFS;
3578
3579         cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
3580         cmd->vdev_id         = __cpu_to_le32(arg->vdev_id);
3581         cmd->disable_hw_ack  = __cpu_to_le32(arg->disable_hw_ack);
3582         cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
3583         cmd->dtim_period     = __cpu_to_le32(arg->dtim_period);
3584         cmd->flags           = __cpu_to_le32(flags);
3585         cmd->bcn_tx_rate     = __cpu_to_le32(arg->bcn_tx_rate);
3586         cmd->bcn_tx_power    = __cpu_to_le32(arg->bcn_tx_power);
3587
3588         if (arg->ssid) {
3589                 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
3590                 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
3591         }
3592
3593         cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
3594
3595         cmd->chan.band_center_freq1 =
3596                 __cpu_to_le32(arg->channel.band_center_freq1);
3597
3598         cmd->chan.mode = arg->channel.mode;
3599         cmd->chan.flags |= __cpu_to_le32(ch_flags);
3600         cmd->chan.min_power = arg->channel.min_power;
3601         cmd->chan.max_power = arg->channel.max_power;
3602         cmd->chan.reg_power = arg->channel.max_reg_power;
3603         cmd->chan.reg_classid = arg->channel.reg_class_id;
3604         cmd->chan.antenna_max = arg->channel.max_antenna_gain;
3605
3606         ath10k_dbg(ar, ATH10K_DBG_WMI,
3607                    "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n",
3608                    cmdname, arg->vdev_id,
3609                    flags, arg->channel.freq, arg->channel.mode,
3610                    cmd->chan.flags, arg->channel.max_power);
3611
3612         return ath10k_wmi_cmd_send(ar, skb, cmd_id);
3613 }
3614
3615 int ath10k_wmi_vdev_start(struct ath10k *ar,
3616                           const struct wmi_vdev_start_request_arg *arg)
3617 {
3618         u32 cmd_id = ar->wmi.cmd->vdev_start_request_cmdid;
3619
3620         return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
3621 }
3622
3623 int ath10k_wmi_vdev_restart(struct ath10k *ar,
3624                             const struct wmi_vdev_start_request_arg *arg)
3625 {
3626         u32 cmd_id = ar->wmi.cmd->vdev_restart_request_cmdid;
3627
3628         return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
3629 }
3630
3631 int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
3632 {
3633         struct wmi_vdev_stop_cmd *cmd;
3634         struct sk_buff *skb;
3635
3636         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3637         if (!skb)
3638                 return -ENOMEM;
3639
3640         cmd = (struct wmi_vdev_stop_cmd *)skb->data;
3641         cmd->vdev_id = __cpu_to_le32(vdev_id);
3642
3643         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
3644
3645         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_stop_cmdid);
3646 }
3647
3648 int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
3649 {
3650         struct wmi_vdev_up_cmd *cmd;
3651         struct sk_buff *skb;
3652
3653         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3654         if (!skb)
3655                 return -ENOMEM;
3656
3657         cmd = (struct wmi_vdev_up_cmd *)skb->data;
3658         cmd->vdev_id       = __cpu_to_le32(vdev_id);
3659         cmd->vdev_assoc_id = __cpu_to_le32(aid);
3660         ether_addr_copy(cmd->vdev_bssid.addr, bssid);
3661
3662         ath10k_dbg(ar, ATH10K_DBG_WMI,
3663                    "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
3664                    vdev_id, aid, bssid);
3665
3666         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_up_cmdid);
3667 }
3668
3669 int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
3670 {
3671         struct wmi_vdev_down_cmd *cmd;
3672         struct sk_buff *skb;
3673
3674         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3675         if (!skb)
3676                 return -ENOMEM;
3677
3678         cmd = (struct wmi_vdev_down_cmd *)skb->data;
3679         cmd->vdev_id = __cpu_to_le32(vdev_id);
3680
3681         ath10k_dbg(ar, ATH10K_DBG_WMI,
3682                    "wmi mgmt vdev down id 0x%x\n", vdev_id);
3683
3684         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_down_cmdid);
3685 }
3686
3687 int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
3688                               u32 param_id, u32 param_value)
3689 {
3690         struct wmi_vdev_set_param_cmd *cmd;
3691         struct sk_buff *skb;
3692
3693         if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
3694                 ath10k_dbg(ar, ATH10K_DBG_WMI,
3695                            "vdev param %d not supported by firmware\n",
3696                             param_id);
3697                 return -EOPNOTSUPP;
3698         }
3699
3700         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3701         if (!skb)
3702                 return -ENOMEM;
3703
3704         cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
3705         cmd->vdev_id     = __cpu_to_le32(vdev_id);
3706         cmd->param_id    = __cpu_to_le32(param_id);
3707         cmd->param_value = __cpu_to_le32(param_value);
3708
3709         ath10k_dbg(ar, ATH10K_DBG_WMI,
3710                    "wmi vdev id 0x%x set param %d value %d\n",
3711                    vdev_id, param_id, param_value);
3712
3713         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_set_param_cmdid);
3714 }
3715
3716 int ath10k_wmi_vdev_install_key(struct ath10k *ar,
3717                                 const struct wmi_vdev_install_key_arg *arg)
3718 {
3719         struct wmi_vdev_install_key_cmd *cmd;
3720         struct sk_buff *skb;
3721
3722         if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
3723                 return -EINVAL;
3724         if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
3725                 return -EINVAL;
3726
3727         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + arg->key_len);
3728         if (!skb)
3729                 return -ENOMEM;
3730
3731         cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
3732         cmd->vdev_id       = __cpu_to_le32(arg->vdev_id);
3733         cmd->key_idx       = __cpu_to_le32(arg->key_idx);
3734         cmd->key_flags     = __cpu_to_le32(arg->key_flags);
3735         cmd->key_cipher    = __cpu_to_le32(arg->key_cipher);
3736         cmd->key_len       = __cpu_to_le32(arg->key_len);
3737         cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
3738         cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
3739
3740         if (arg->macaddr)
3741                 ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
3742         if (arg->key_data)
3743                 memcpy(cmd->key_data, arg->key_data, arg->key_len);
3744
3745         ath10k_dbg(ar, ATH10K_DBG_WMI,
3746                    "wmi vdev install key idx %d cipher %d len %d\n",
3747                    arg->key_idx, arg->key_cipher, arg->key_len);
3748         return ath10k_wmi_cmd_send(ar, skb,
3749                                    ar->wmi.cmd->vdev_install_key_cmdid);
3750 }
3751
3752 int ath10k_wmi_vdev_spectral_conf(struct ath10k *ar,
3753                                   const struct wmi_vdev_spectral_conf_arg *arg)
3754 {
3755         struct wmi_vdev_spectral_conf_cmd *cmd;
3756         struct sk_buff *skb;
3757         u32 cmdid;
3758
3759         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3760         if (!skb)
3761                 return -ENOMEM;
3762
3763         cmd = (struct wmi_vdev_spectral_conf_cmd *)skb->data;
3764         cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3765         cmd->scan_count = __cpu_to_le32(arg->scan_count);
3766         cmd->scan_period = __cpu_to_le32(arg->scan_period);
3767         cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
3768         cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
3769         cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
3770         cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
3771         cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
3772         cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
3773         cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
3774         cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
3775         cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
3776         cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
3777         cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
3778         cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
3779         cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
3780         cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
3781         cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
3782         cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
3783
3784         cmdid = ar->wmi.cmd->vdev_spectral_scan_configure_cmdid;
3785         return ath10k_wmi_cmd_send(ar, skb, cmdid);
3786 }
3787
3788 int ath10k_wmi_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id, u32 trigger,
3789                                     u32 enable)
3790 {
3791         struct wmi_vdev_spectral_enable_cmd *cmd;
3792         struct sk_buff *skb;
3793         u32 cmdid;
3794
3795         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3796         if (!skb)
3797                 return -ENOMEM;
3798
3799         cmd = (struct wmi_vdev_spectral_enable_cmd *)skb->data;
3800         cmd->vdev_id = __cpu_to_le32(vdev_id);
3801         cmd->trigger_cmd = __cpu_to_le32(trigger);
3802         cmd->enable_cmd = __cpu_to_le32(enable);
3803
3804         cmdid = ar->wmi.cmd->vdev_spectral_scan_enable_cmdid;
3805         return ath10k_wmi_cmd_send(ar, skb, cmdid);
3806 }
3807
3808 int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
3809                            const u8 peer_addr[ETH_ALEN])
3810 {
3811         struct wmi_peer_create_cmd *cmd;
3812         struct sk_buff *skb;
3813
3814         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3815         if (!skb)
3816                 return -ENOMEM;
3817
3818         cmd = (struct wmi_peer_create_cmd *)skb->data;
3819         cmd->vdev_id = __cpu_to_le32(vdev_id);
3820         ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
3821
3822         ath10k_dbg(ar, ATH10K_DBG_WMI,
3823                    "wmi peer create vdev_id %d peer_addr %pM\n",
3824                    vdev_id, peer_addr);
3825         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_create_cmdid);
3826 }
3827
3828 int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
3829                            const u8 peer_addr[ETH_ALEN])
3830 {
3831         struct wmi_peer_delete_cmd *cmd;
3832         struct sk_buff *skb;
3833
3834         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3835         if (!skb)
3836                 return -ENOMEM;
3837
3838         cmd = (struct wmi_peer_delete_cmd *)skb->data;
3839         cmd->vdev_id = __cpu_to_le32(vdev_id);
3840         ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
3841
3842         ath10k_dbg(ar, ATH10K_DBG_WMI,
3843                    "wmi peer delete vdev_id %d peer_addr %pM\n",
3844                    vdev_id, peer_addr);
3845         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_delete_cmdid);
3846 }
3847
3848 int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
3849                           const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
3850 {
3851         struct wmi_peer_flush_tids_cmd *cmd;
3852         struct sk_buff *skb;
3853
3854         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3855         if (!skb)
3856                 return -ENOMEM;
3857
3858         cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
3859         cmd->vdev_id         = __cpu_to_le32(vdev_id);
3860         cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
3861         ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
3862
3863         ath10k_dbg(ar, ATH10K_DBG_WMI,
3864                    "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
3865                    vdev_id, peer_addr, tid_bitmap);
3866         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_flush_tids_cmdid);
3867 }
3868
3869 int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
3870                               const u8 *peer_addr, enum wmi_peer_param param_id,
3871                               u32 param_value)
3872 {
3873         struct wmi_peer_set_param_cmd *cmd;
3874         struct sk_buff *skb;
3875
3876         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3877         if (!skb)
3878                 return -ENOMEM;
3879
3880         cmd = (struct wmi_peer_set_param_cmd *)skb->data;
3881         cmd->vdev_id     = __cpu_to_le32(vdev_id);
3882         cmd->param_id    = __cpu_to_le32(param_id);
3883         cmd->param_value = __cpu_to_le32(param_value);
3884         ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
3885
3886         ath10k_dbg(ar, ATH10K_DBG_WMI,
3887                    "wmi vdev %d peer 0x%pM set param %d value %d\n",
3888                    vdev_id, peer_addr, param_id, param_value);
3889
3890         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_set_param_cmdid);
3891 }
3892
3893 int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
3894                           enum wmi_sta_ps_mode psmode)
3895 {
3896         struct wmi_sta_powersave_mode_cmd *cmd;
3897         struct sk_buff *skb;
3898
3899         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3900         if (!skb)
3901                 return -ENOMEM;
3902
3903         cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
3904         cmd->vdev_id     = __cpu_to_le32(vdev_id);
3905         cmd->sta_ps_mode = __cpu_to_le32(psmode);
3906
3907         ath10k_dbg(ar, ATH10K_DBG_WMI,
3908                    "wmi set powersave id 0x%x mode %d\n",
3909                    vdev_id, psmode);
3910
3911         return ath10k_wmi_cmd_send(ar, skb,
3912                                    ar->wmi.cmd->sta_powersave_mode_cmdid);
3913 }
3914
3915 int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
3916                                 enum wmi_sta_powersave_param param_id,
3917                                 u32 value)
3918 {
3919         struct wmi_sta_powersave_param_cmd *cmd;
3920         struct sk_buff *skb;
3921
3922         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3923         if (!skb)
3924                 return -ENOMEM;
3925
3926         cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
3927         cmd->vdev_id     = __cpu_to_le32(vdev_id);
3928         cmd->param_id    = __cpu_to_le32(param_id);
3929         cmd->param_value = __cpu_to_le32(value);
3930
3931         ath10k_dbg(ar, ATH10K_DBG_WMI,
3932                    "wmi sta ps param vdev_id 0x%x param %d value %d\n",
3933                    vdev_id, param_id, value);
3934         return ath10k_wmi_cmd_send(ar, skb,
3935                                    ar->wmi.cmd->sta_powersave_param_cmdid);
3936 }
3937
3938 int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
3939                                enum wmi_ap_ps_peer_param param_id, u32 value)
3940 {
3941         struct wmi_ap_ps_peer_cmd *cmd;
3942         struct sk_buff *skb;
3943
3944         if (!mac)
3945                 return -EINVAL;
3946
3947         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
3948         if (!skb)
3949                 return -ENOMEM;
3950
3951         cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
3952         cmd->vdev_id = __cpu_to_le32(vdev_id);
3953         cmd->param_id = __cpu_to_le32(param_id);
3954         cmd->param_value = __cpu_to_le32(value);
3955         ether_addr_copy(cmd->peer_macaddr.addr, mac);
3956
3957         ath10k_dbg(ar, ATH10K_DBG_WMI,
3958                    "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
3959                    vdev_id, param_id, value, mac);
3960
3961         return ath10k_wmi_cmd_send(ar, skb,
3962                                    ar->wmi.cmd->ap_ps_peer_param_cmdid);
3963 }
3964
3965 int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3966                               const struct wmi_scan_chan_list_arg *arg)
3967 {
3968         struct wmi_scan_chan_list_cmd *cmd;
3969         struct sk_buff *skb;
3970         struct wmi_channel_arg *ch;
3971         struct wmi_channel *ci;
3972         int len;
3973         int i;
3974
3975         len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
3976
3977         skb = ath10k_wmi_alloc_skb(ar, len);
3978         if (!skb)
3979                 return -EINVAL;
3980
3981         cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
3982         cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3983
3984         for (i = 0; i < arg->n_channels; i++) {
3985                 u32 flags = 0;
3986
3987                 ch = &arg->channels[i];
3988                 ci = &cmd->chan_info[i];
3989
3990                 if (ch->passive)
3991                         flags |= WMI_CHAN_FLAG_PASSIVE;
3992                 if (ch->allow_ibss)
3993                         flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
3994                 if (ch->allow_ht)
3995                         flags |= WMI_CHAN_FLAG_ALLOW_HT;
3996                 if (ch->allow_vht)
3997                         flags |= WMI_CHAN_FLAG_ALLOW_VHT;
3998                 if (ch->ht40plus)
3999                         flags |= WMI_CHAN_FLAG_HT40_PLUS;
4000                 if (ch->chan_radar)
4001                         flags |= WMI_CHAN_FLAG_DFS;
4002
4003                 ci->mhz               = __cpu_to_le32(ch->freq);
4004                 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
4005                 ci->band_center_freq2 = 0;
4006                 ci->min_power         = ch->min_power;
4007                 ci->max_power         = ch->max_power;
4008                 ci->reg_power         = ch->max_reg_power;
4009                 ci->antenna_max       = ch->max_antenna_gain;
4010
4011                 /* mode & flags share storage */
4012                 ci->mode              = ch->mode;
4013                 ci->flags            |= __cpu_to_le32(flags);
4014         }
4015
4016         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
4017 }
4018
4019 static void
4020 ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
4021                            const struct wmi_peer_assoc_complete_arg *arg)
4022 {
4023         struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
4024
4025         cmd->vdev_id            = __cpu_to_le32(arg->vdev_id);
4026         cmd->peer_new_assoc     = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
4027         cmd->peer_associd       = __cpu_to_le32(arg->peer_aid);
4028         cmd->peer_flags         = __cpu_to_le32(arg->peer_flags);
4029         cmd->peer_caps          = __cpu_to_le32(arg->peer_caps);
4030         cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
4031         cmd->peer_ht_caps       = __cpu_to_le32(arg->peer_ht_caps);
4032         cmd->peer_max_mpdu      = __cpu_to_le32(arg->peer_max_mpdu);
4033         cmd->peer_mpdu_density  = __cpu_to_le32(arg->peer_mpdu_density);
4034         cmd->peer_rate_caps     = __cpu_to_le32(arg->peer_rate_caps);
4035         cmd->peer_nss           = __cpu_to_le32(arg->peer_num_spatial_streams);
4036         cmd->peer_vht_caps      = __cpu_to_le32(arg->peer_vht_caps);
4037         cmd->peer_phymode       = __cpu_to_le32(arg->peer_phymode);
4038
4039         ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
4040
4041         cmd->peer_legacy_rates.num_rates =
4042                 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
4043         memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
4044                arg->peer_legacy_rates.num_rates);
4045
4046         cmd->peer_ht_rates.num_rates =
4047                 __cpu_to_le32(arg->peer_ht_rates.num_rates);
4048         memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
4049                arg->peer_ht_rates.num_rates);
4050
4051         cmd->peer_vht_rates.rx_max_rate =
4052                 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
4053         cmd->peer_vht_rates.rx_mcs_set =
4054                 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
4055         cmd->peer_vht_rates.tx_max_rate =
4056                 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
4057         cmd->peer_vht_rates.tx_mcs_set =
4058                 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
4059 }
4060
4061 static void
4062 ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
4063                                 const struct wmi_peer_assoc_complete_arg *arg)
4064 {
4065         struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
4066
4067         ath10k_wmi_peer_assoc_fill(ar, buf, arg);
4068         memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
4069 }
4070
4071 static void
4072 ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
4073                                 const struct wmi_peer_assoc_complete_arg *arg)
4074 {
4075         ath10k_wmi_peer_assoc_fill(ar, buf, arg);
4076 }
4077
4078 static void
4079 ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
4080                                 const struct wmi_peer_assoc_complete_arg *arg)
4081 {
4082         struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
4083         int max_mcs, max_nss;
4084         u32 info0;
4085
4086         /* TODO: Is using max values okay with firmware? */
4087         max_mcs = 0xf;
4088         max_nss = 0xf;
4089
4090         info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
4091                 SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
4092
4093         ath10k_wmi_peer_assoc_fill(ar, buf, arg);
4094         cmd->info0 = __cpu_to_le32(info0);
4095 }
4096
4097 int ath10k_wmi_peer_assoc(struct ath10k *ar,
4098                           const struct wmi_peer_assoc_complete_arg *arg)
4099 {
4100         struct sk_buff *skb;
4101         int len;
4102
4103         if (arg->peer_mpdu_density > 16)
4104                 return -EINVAL;
4105         if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
4106                 return -EINVAL;
4107         if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
4108                 return -EINVAL;
4109
4110         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4111                 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4112                         len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
4113                 else
4114                         len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
4115         } else {
4116                 len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
4117         }
4118
4119         skb = ath10k_wmi_alloc_skb(ar, len);
4120         if (!skb)
4121                 return -ENOMEM;
4122
4123         if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4124                 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4125                         ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
4126                 else
4127                         ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
4128         } else {
4129                 ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
4130         }
4131
4132         ath10k_dbg(ar, ATH10K_DBG_WMI,
4133                    "wmi peer assoc vdev %d addr %pM (%s)\n",
4134                    arg->vdev_id, arg->addr,
4135                    arg->peer_reassoc ? "reassociate" : "new");
4136         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_assoc_cmdid);
4137 }
4138
4139 /* This function assumes the beacon is already DMA mapped */
4140 int ath10k_wmi_beacon_send_ref_nowait(struct ath10k_vif *arvif)
4141 {
4142         struct wmi_bcn_tx_ref_cmd *cmd;
4143         struct sk_buff *skb;
4144         struct sk_buff *beacon = arvif->beacon;
4145         struct ath10k *ar = arvif->ar;
4146         struct ieee80211_hdr *hdr;
4147         int ret;
4148         u16 fc;
4149
4150         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
4151         if (!skb)
4152                 return -ENOMEM;
4153
4154         hdr = (struct ieee80211_hdr *)beacon->data;
4155         fc = le16_to_cpu(hdr->frame_control);
4156
4157         cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
4158         cmd->vdev_id = __cpu_to_le32(arvif->vdev_id);
4159         cmd->data_len = __cpu_to_le32(beacon->len);
4160         cmd->data_ptr = __cpu_to_le32(ATH10K_SKB_CB(beacon)->paddr);
4161         cmd->msdu_id = 0;
4162         cmd->frame_control = __cpu_to_le32(fc);
4163         cmd->flags = 0;
4164         cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
4165
4166         if (ATH10K_SKB_CB(beacon)->bcn.dtim_zero)
4167                 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
4168
4169         if (ATH10K_SKB_CB(beacon)->bcn.deliver_cab)
4170                 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
4171
4172         ret = ath10k_wmi_cmd_send_nowait(ar, skb,
4173                                          ar->wmi.cmd->pdev_send_bcn_cmdid);
4174
4175         if (ret)
4176                 dev_kfree_skb(skb);
4177
4178         return ret;
4179 }
4180
4181 static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
4182                                           const struct wmi_wmm_params_arg *arg)
4183 {
4184         params->cwmin  = __cpu_to_le32(arg->cwmin);
4185         params->cwmax  = __cpu_to_le32(arg->cwmax);
4186         params->aifs   = __cpu_to_le32(arg->aifs);
4187         params->txop   = __cpu_to_le32(arg->txop);
4188         params->acm    = __cpu_to_le32(arg->acm);
4189         params->no_ack = __cpu_to_le32(arg->no_ack);
4190 }
4191
4192 int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
4193                                    const struct wmi_pdev_set_wmm_params_arg *arg)
4194 {
4195         struct wmi_pdev_set_wmm_params *cmd;
4196         struct sk_buff *skb;
4197
4198         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
4199         if (!skb)
4200                 return -ENOMEM;
4201
4202         cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
4203         ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
4204         ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
4205         ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
4206         ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
4207
4208         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
4209         return ath10k_wmi_cmd_send(ar, skb,
4210                                    ar->wmi.cmd->pdev_set_wmm_params_cmdid);
4211 }
4212
4213 int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
4214 {
4215         struct wmi_request_stats_cmd *cmd;
4216         struct sk_buff *skb;
4217
4218         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
4219         if (!skb)
4220                 return -ENOMEM;
4221
4222         cmd = (struct wmi_request_stats_cmd *)skb->data;
4223         cmd->stats_id = __cpu_to_le32(stats_id);
4224
4225         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
4226         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->request_stats_cmdid);
4227 }
4228
4229 int ath10k_wmi_force_fw_hang(struct ath10k *ar,
4230                              enum wmi_force_fw_hang_type type, u32 delay_ms)
4231 {
4232         struct wmi_force_fw_hang_cmd *cmd;
4233         struct sk_buff *skb;
4234
4235         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
4236         if (!skb)
4237                 return -ENOMEM;
4238
4239         cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
4240         cmd->type = __cpu_to_le32(type);
4241         cmd->delay_ms = __cpu_to_le32(delay_ms);
4242
4243         ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
4244                    type, delay_ms);
4245         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
4246 }
4247
4248 int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable)
4249 {
4250         struct wmi_dbglog_cfg_cmd *cmd;
4251         struct sk_buff *skb;
4252         u32 cfg;
4253
4254         skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
4255         if (!skb)
4256                 return -ENOMEM;
4257
4258         cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
4259
4260         if (module_enable) {
4261                 cfg = SM(ATH10K_DBGLOG_LEVEL_VERBOSE,
4262                          ATH10K_DBGLOG_CFG_LOG_LVL);
4263         } else {
4264                 /* set back defaults, all modules with WARN level */
4265                 cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
4266                          ATH10K_DBGLOG_CFG_LOG_LVL);
4267                 module_enable = ~0;
4268         }
4269
4270         cmd->module_enable = __cpu_to_le32(module_enable);
4271         cmd->module_valid = __cpu_to_le32(~0);
4272         cmd->config_enable = __cpu_to_le32(cfg);
4273         cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
4274
4275         ath10k_dbg(ar, ATH10K_DBG_WMI,
4276                    "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
4277                    __le32_to_cpu(cmd->module_enable),
4278                    __le32_to_cpu(cmd->module_valid),
4279                    __le32_to_cpu(cmd->config_enable),
4280                    __le32_to_cpu(cmd->config_valid));
4281
4282         return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid);
4283 }