blob: cec0c2839e5b643c197be34f478a435b1831f940 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
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>
Kalle Valo2fe52882014-01-03 12:59:20 +020019#include <linux/ctype.h>
Kalle Valo5e3dd152013-06-12 20:52:10 +030020
21#include "core.h"
22#include "htc.h"
23#include "debug.h"
24#include "wmi.h"
25#include "mac.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030026#include "testmode.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030027
Bartosz Markowskice428702013-09-26 17:47:05 +020028/* MAIN WMI cmd track */
29static 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
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200148/* 10.X WMI cmd track */
149static 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,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200154 .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200155 .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,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200187 .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200188 .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,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200191 .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200192 .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,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200216 .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
Janusz Dziedzic542fb172014-01-17 14:08:08 +0100217 .ap_ps_peer_param_cmdid = WMI_10X_AP_PS_PEER_PARAM_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200218 .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200219 .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,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200247 .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,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200258 .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,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200262 .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,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200266 .gpio_config_cmdid = WMI_10X_GPIO_CONFIG_CMDID,
267 .gpio_output_cmdid = WMI_10X_GPIO_OUTPUT_CMDID,
268};
Bartosz Markowskice428702013-09-26 17:47:05 +0200269
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200270/* MAIN WMI VDEV param map */
271static 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 */
330static 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
Bartosz Markowski226a3392013-09-26 17:47:16 +0200388static 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,
Bartosz Markowski226a3392013-09-26 17:47:16 +0200424 .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
439static 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,
Marek Puzyniakab6258e2014-01-29 15:03:31 +0200475 .arp_ac_override = WMI_10X_PDEV_PARAM_ARPDHCP_AC_OVERRIDE,
Bartosz Markowski226a3392013-09-26 17:47:16 +0200476 .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
Michal Kazior24c88f72014-07-25 13:32:17 +0200491/* firmware 10.2 specific mappings */
492static 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
Michal Kazior2d667212014-09-18 15:21:21 +0200612static void
613ath10k_wmi_put_wmi_channel(struct wmi_channel *ch,
614 const struct wmi_channel_arg *arg)
615{
616 u32 flags = 0;
617
618 memset(ch, 0, sizeof(*ch));
619
620 if (arg->passive)
621 flags |= WMI_CHAN_FLAG_PASSIVE;
622 if (arg->allow_ibss)
623 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
624 if (arg->allow_ht)
625 flags |= WMI_CHAN_FLAG_ALLOW_HT;
626 if (arg->allow_vht)
627 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
628 if (arg->ht40plus)
629 flags |= WMI_CHAN_FLAG_HT40_PLUS;
630 if (arg->chan_radar)
631 flags |= WMI_CHAN_FLAG_DFS;
632
633 ch->mhz = __cpu_to_le32(arg->freq);
634 ch->band_center_freq1 = __cpu_to_le32(arg->band_center_freq1);
635 ch->band_center_freq2 = 0;
636 ch->min_power = arg->min_power;
637 ch->max_power = arg->max_power;
638 ch->reg_power = arg->max_reg_power;
639 ch->antenna_max = arg->max_antenna_gain;
640
641 /* mode & flags share storage */
642 ch->mode = arg->mode;
643 ch->flags |= __cpu_to_le32(flags);
644}
645
Kalle Valo5e3dd152013-06-12 20:52:10 +0300646int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
647{
648 int ret;
Kalle Valoaf762c02014-09-14 12:50:17 +0300649
Kalle Valo5e3dd152013-06-12 20:52:10 +0300650 ret = wait_for_completion_timeout(&ar->wmi.service_ready,
651 WMI_SERVICE_READY_TIMEOUT_HZ);
652 return ret;
653}
654
655int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
656{
657 int ret;
Kalle Valoaf762c02014-09-14 12:50:17 +0300658
Kalle Valo5e3dd152013-06-12 20:52:10 +0300659 ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
660 WMI_UNIFIED_READY_TIMEOUT_HZ);
661 return ret;
662}
663
Kalle Valo666a73f32014-09-10 18:23:23 +0300664struct sk_buff *ath10k_wmi_alloc_skb(struct ath10k *ar, u32 len)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300665{
666 struct sk_buff *skb;
667 u32 round_len = roundup(len, 4);
668
Michal Kazior7aa7a722014-08-25 12:09:38 +0200669 skb = ath10k_htc_alloc_skb(ar, WMI_SKB_HEADROOM + round_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670 if (!skb)
671 return NULL;
672
673 skb_reserve(skb, WMI_SKB_HEADROOM);
674 if (!IS_ALIGNED((unsigned long)skb->data, 4))
Michal Kazior7aa7a722014-08-25 12:09:38 +0200675 ath10k_warn(ar, "Unaligned WMI skb\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300676
677 skb_put(skb, round_len);
678 memset(skb->data, 0, round_len);
679
680 return skb;
681}
682
683static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
684{
685 dev_kfree_skb(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300686}
687
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200688static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
Bartosz Markowskice428702013-09-26 17:47:05 +0200689 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300690{
691 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
692 struct wmi_cmd_hdr *cmd_hdr;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200693 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300694 u32 cmd = 0;
695
696 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
697 return -ENOMEM;
698
699 cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
700
701 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
702 cmd_hdr->cmd_id = __cpu_to_le32(cmd);
703
Kalle Valo5e3dd152013-06-12 20:52:10 +0300704 memset(skb_cb, 0, sizeof(*skb_cb));
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200705 ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
Michal Kaziord35a6c12014-09-02 11:00:21 +0300706 trace_ath10k_wmi_cmd(ar, cmd_id, skb->data, skb->len, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200708 if (ret)
709 goto err_pull;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300710
711 return 0;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200712
713err_pull:
714 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
715 return ret;
716}
717
Michal Kaziored543882013-09-13 14:16:56 +0200718static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
719{
Michal Kaziored543882013-09-13 14:16:56 +0200720 int ret;
721
722 lockdep_assert_held(&arvif->ar->data_lock);
723
724 if (arvif->beacon == NULL)
725 return;
726
Michal Kazior748afc42014-01-23 12:48:21 +0100727 if (arvif->beacon_sent)
728 return;
Michal Kaziored543882013-09-13 14:16:56 +0200729
Michal Kazior748afc42014-01-23 12:48:21 +0100730 ret = ath10k_wmi_beacon_send_ref_nowait(arvif);
Michal Kaziored543882013-09-13 14:16:56 +0200731 if (ret)
732 return;
733
Michal Kazior748afc42014-01-23 12:48:21 +0100734 /* We need to retain the arvif->beacon reference for DMA unmapping and
735 * freeing the skbuff later. */
736 arvif->beacon_sent = true;
Michal Kaziored543882013-09-13 14:16:56 +0200737}
738
739static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
740 struct ieee80211_vif *vif)
741{
742 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
743
744 ath10k_wmi_tx_beacon_nowait(arvif);
745}
746
747static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
748{
749 spin_lock_bh(&ar->data_lock);
750 ieee80211_iterate_active_interfaces_atomic(ar->hw,
751 IEEE80211_IFACE_ITER_NORMAL,
752 ath10k_wmi_tx_beacons_iter,
753 NULL);
754 spin_unlock_bh(&ar->data_lock);
755}
756
Michal Kazior12acbc42013-09-13 14:16:55 +0200757static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200758{
Michal Kaziored543882013-09-13 14:16:56 +0200759 /* try to send pending beacons first. they take priority */
760 ath10k_wmi_tx_beacons_nowait(ar);
761
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200762 wake_up(&ar->wmi.tx_credits_wq);
763}
764
Kalle Valo666a73f32014-09-10 18:23:23 +0300765int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb, u32 cmd_id)
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200766{
Bartosz Markowski34957b22013-10-15 09:55:31 +0200767 int ret = -EOPNOTSUPP;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200768
Kalle Valo56b84282013-10-16 15:44:47 +0300769 might_sleep();
770
Bartosz Markowski34957b22013-10-15 09:55:31 +0200771 if (cmd_id == WMI_CMD_UNSUPPORTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200772 ath10k_warn(ar, "wmi command %d is not supported by firmware\n",
Bartosz Markowski55321552013-09-26 17:47:07 +0200773 cmd_id);
774 return ret;
775 }
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200776
777 wait_event_timeout(ar->wmi.tx_credits_wq, ({
Michal Kaziored543882013-09-13 14:16:56 +0200778 /* try to send pending beacons first. they take priority */
779 ath10k_wmi_tx_beacons_nowait(ar);
780
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200781 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
782 (ret != -EAGAIN);
783 }), 3*HZ);
784
785 if (ret)
786 dev_kfree_skb_any(skb);
787
788 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300789}
790
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200791int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
792{
793 int ret = 0;
794 struct wmi_mgmt_tx_cmd *cmd;
795 struct ieee80211_hdr *hdr;
796 struct sk_buff *wmi_skb;
797 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
798 int len;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +0300799 u32 buf_len = skb->len;
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200800 u16 fc;
801
802 hdr = (struct ieee80211_hdr *)skb->data;
803 fc = le16_to_cpu(hdr->frame_control);
804
805 if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
806 return -EINVAL;
807
808 len = sizeof(cmd->hdr) + skb->len;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +0300809
810 if ((ieee80211_is_action(hdr->frame_control) ||
811 ieee80211_is_deauth(hdr->frame_control) ||
812 ieee80211_is_disassoc(hdr->frame_control)) &&
813 ieee80211_has_protected(hdr->frame_control)) {
814 len += IEEE80211_CCMP_MIC_LEN;
815 buf_len += IEEE80211_CCMP_MIC_LEN;
816 }
817
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200818 len = round_up(len, 4);
819
Michal Kazior7aa7a722014-08-25 12:09:38 +0200820 wmi_skb = ath10k_wmi_alloc_skb(ar, len);
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200821 if (!wmi_skb)
822 return -ENOMEM;
823
824 cmd = (struct wmi_mgmt_tx_cmd *)wmi_skb->data;
825
826 cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id);
827 cmd->hdr.tx_rate = 0;
828 cmd->hdr.tx_power = 0;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +0300829 cmd->hdr.buf_len = __cpu_to_le32(buf_len);
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200830
Kalle Valob25f32c2014-09-14 12:50:49 +0300831 ether_addr_copy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr));
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200832 memcpy(cmd->buf, skb->data, skb->len);
833
Michal Kazior7aa7a722014-08-25 12:09:38 +0200834 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n",
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200835 wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE,
836 fc & IEEE80211_FCTL_STYPE);
837
838 /* Send the management frame buffer to the target */
839 ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid);
Michal Kazior5fb5e412013-10-28 07:18:13 +0100840 if (ret)
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200841 return ret;
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200842
843 /* TODO: report tx status to mac80211 - temporary just ACK */
844 info->flags |= IEEE80211_TX_STAT_ACK;
845 ieee80211_tx_status_irqsafe(ar->hw, skb);
846
847 return ret;
848}
849
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200850static void ath10k_wmi_event_scan_started(struct ath10k *ar)
851{
852 lockdep_assert_held(&ar->data_lock);
853
854 switch (ar->scan.state) {
855 case ATH10K_SCAN_IDLE:
856 case ATH10K_SCAN_RUNNING:
857 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200858 ath10k_warn(ar, "received scan started event in an invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200859 ath10k_scan_state_str(ar->scan.state),
860 ar->scan.state);
861 break;
862 case ATH10K_SCAN_STARTING:
863 ar->scan.state = ATH10K_SCAN_RUNNING;
864
865 if (ar->scan.is_roc)
866 ieee80211_ready_on_channel(ar->hw);
867
868 complete(&ar->scan.started);
869 break;
870 }
871}
872
873static void ath10k_wmi_event_scan_completed(struct ath10k *ar)
874{
875 lockdep_assert_held(&ar->data_lock);
876
877 switch (ar->scan.state) {
878 case ATH10K_SCAN_IDLE:
879 case ATH10K_SCAN_STARTING:
880 /* One suspected reason scan can be completed while starting is
881 * if firmware fails to deliver all scan events to the host,
882 * e.g. when transport pipe is full. This has been observed
883 * with spectral scan phyerr events starving wmi transport
884 * pipe. In such case the "scan completed" event should be (and
885 * is) ignored by the host as it may be just firmware's scan
886 * state machine recovering.
887 */
Michal Kazior7aa7a722014-08-25 12:09:38 +0200888 ath10k_warn(ar, "received scan completed event in an invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200889 ath10k_scan_state_str(ar->scan.state),
890 ar->scan.state);
891 break;
892 case ATH10K_SCAN_RUNNING:
893 case ATH10K_SCAN_ABORTING:
894 __ath10k_scan_finish(ar);
895 break;
896 }
897}
898
899static void ath10k_wmi_event_scan_bss_chan(struct ath10k *ar)
900{
901 lockdep_assert_held(&ar->data_lock);
902
903 switch (ar->scan.state) {
904 case ATH10K_SCAN_IDLE:
905 case ATH10K_SCAN_STARTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200906 ath10k_warn(ar, "received scan bss chan event in an invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200907 ath10k_scan_state_str(ar->scan.state),
908 ar->scan.state);
909 break;
910 case ATH10K_SCAN_RUNNING:
911 case ATH10K_SCAN_ABORTING:
912 ar->scan_channel = NULL;
913 break;
914 }
915}
916
917static void ath10k_wmi_event_scan_foreign_chan(struct ath10k *ar, u32 freq)
918{
919 lockdep_assert_held(&ar->data_lock);
920
921 switch (ar->scan.state) {
922 case ATH10K_SCAN_IDLE:
923 case ATH10K_SCAN_STARTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200924 ath10k_warn(ar, "received scan foreign chan event in an invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200925 ath10k_scan_state_str(ar->scan.state),
926 ar->scan.state);
927 break;
928 case ATH10K_SCAN_RUNNING:
929 case ATH10K_SCAN_ABORTING:
930 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
931
932 if (ar->scan.is_roc && ar->scan.roc_freq == freq)
933 complete(&ar->scan.on_channel);
934 break;
935 }
936}
937
Michal Kazior9ff8b722014-08-05 14:54:43 +0200938static const char *
939ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
940 enum wmi_scan_completion_reason reason)
941{
942 switch (type) {
943 case WMI_SCAN_EVENT_STARTED:
944 return "started";
945 case WMI_SCAN_EVENT_COMPLETED:
946 switch (reason) {
947 case WMI_SCAN_REASON_COMPLETED:
948 return "completed";
949 case WMI_SCAN_REASON_CANCELLED:
950 return "completed [cancelled]";
951 case WMI_SCAN_REASON_PREEMPTED:
952 return "completed [preempted]";
953 case WMI_SCAN_REASON_TIMEDOUT:
954 return "completed [timedout]";
955 case WMI_SCAN_REASON_MAX:
956 break;
957 }
958 return "completed [unknown]";
959 case WMI_SCAN_EVENT_BSS_CHANNEL:
960 return "bss channel";
961 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
962 return "foreign channel";
963 case WMI_SCAN_EVENT_DEQUEUED:
964 return "dequeued";
965 case WMI_SCAN_EVENT_PREEMPTED:
966 return "preempted";
967 case WMI_SCAN_EVENT_START_FAILED:
968 return "start failed";
969 default:
970 return "unknown";
971 }
972}
973
Kalle Valo5e3dd152013-06-12 20:52:10 +0300974static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
975{
976 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
977 enum wmi_scan_event_type event_type;
978 enum wmi_scan_completion_reason reason;
979 u32 freq;
980 u32 req_id;
981 u32 scan_id;
982 u32 vdev_id;
983
984 event_type = __le32_to_cpu(event->event_type);
985 reason = __le32_to_cpu(event->reason);
986 freq = __le32_to_cpu(event->channel_freq);
987 req_id = __le32_to_cpu(event->scan_req_id);
988 scan_id = __le32_to_cpu(event->scan_id);
989 vdev_id = __le32_to_cpu(event->vdev_id);
990
Kalle Valo5e3dd152013-06-12 20:52:10 +0300991 spin_lock_bh(&ar->data_lock);
992
Michal Kazior7aa7a722014-08-25 12:09:38 +0200993 ath10k_dbg(ar, ATH10K_DBG_WMI,
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200994 "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
995 ath10k_wmi_event_scan_type_str(event_type, reason),
996 event_type, reason, freq, req_id, scan_id, vdev_id,
997 ath10k_scan_state_str(ar->scan.state), ar->scan.state);
998
Kalle Valo5e3dd152013-06-12 20:52:10 +0300999 switch (event_type) {
1000 case WMI_SCAN_EVENT_STARTED:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001001 ath10k_wmi_event_scan_started(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001002 break;
1003 case WMI_SCAN_EVENT_COMPLETED:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001004 ath10k_wmi_event_scan_completed(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001005 break;
1006 case WMI_SCAN_EVENT_BSS_CHANNEL:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001007 ath10k_wmi_event_scan_bss_chan(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001008 break;
1009 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001010 ath10k_wmi_event_scan_foreign_chan(ar, freq);
1011 break;
1012 case WMI_SCAN_EVENT_START_FAILED:
Michal Kazior7aa7a722014-08-25 12:09:38 +02001013 ath10k_warn(ar, "received scan start failure event\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001014 break;
1015 case WMI_SCAN_EVENT_DEQUEUED:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001016 case WMI_SCAN_EVENT_PREEMPTED:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001017 default:
1018 break;
1019 }
1020
1021 spin_unlock_bh(&ar->data_lock);
1022 return 0;
1023}
1024
1025static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
1026{
1027 enum ieee80211_band band;
1028
1029 switch (phy_mode) {
1030 case MODE_11A:
1031 case MODE_11NA_HT20:
1032 case MODE_11NA_HT40:
1033 case MODE_11AC_VHT20:
1034 case MODE_11AC_VHT40:
1035 case MODE_11AC_VHT80:
1036 band = IEEE80211_BAND_5GHZ;
1037 break;
1038 case MODE_11G:
1039 case MODE_11B:
1040 case MODE_11GONLY:
1041 case MODE_11NG_HT20:
1042 case MODE_11NG_HT40:
1043 case MODE_11AC_VHT20_2G:
1044 case MODE_11AC_VHT40_2G:
1045 case MODE_11AC_VHT80_2G:
1046 default:
1047 band = IEEE80211_BAND_2GHZ;
1048 }
1049
1050 return band;
1051}
1052
1053static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
1054{
1055 u8 rate_idx = 0;
1056
1057 /* rate in Kbps */
1058 switch (rate) {
1059 case 1000:
1060 rate_idx = 0;
1061 break;
1062 case 2000:
1063 rate_idx = 1;
1064 break;
1065 case 5500:
1066 rate_idx = 2;
1067 break;
1068 case 11000:
1069 rate_idx = 3;
1070 break;
1071 case 6000:
1072 rate_idx = 4;
1073 break;
1074 case 9000:
1075 rate_idx = 5;
1076 break;
1077 case 12000:
1078 rate_idx = 6;
1079 break;
1080 case 18000:
1081 rate_idx = 7;
1082 break;
1083 case 24000:
1084 rate_idx = 8;
1085 break;
1086 case 36000:
1087 rate_idx = 9;
1088 break;
1089 case 48000:
1090 rate_idx = 10;
1091 break;
1092 case 54000:
1093 rate_idx = 11;
1094 break;
1095 default:
1096 break;
1097 }
1098
1099 if (band == IEEE80211_BAND_5GHZ) {
1100 if (rate_idx > 3)
1101 /* Omit CCK rates */
1102 rate_idx -= 4;
1103 else
1104 rate_idx = 0;
1105 }
1106
1107 return rate_idx;
1108}
1109
1110static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
1111{
Michal Kazior0d9b0432013-08-09 10:13:33 +02001112 struct wmi_mgmt_rx_event_v1 *ev_v1;
1113 struct wmi_mgmt_rx_event_v2 *ev_v2;
1114 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001115 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Michal Kazior453cdb62013-12-13 10:44:43 +01001116 struct ieee80211_channel *ch;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001117 struct ieee80211_hdr *hdr;
1118 u32 rx_status;
1119 u32 channel;
1120 u32 phy_mode;
1121 u32 snr;
1122 u32 rate;
1123 u32 buf_len;
1124 u16 fc;
Michal Kazior0d9b0432013-08-09 10:13:33 +02001125 int pull_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001126
Michal Kazior0d9b0432013-08-09 10:13:33 +02001127 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
1128 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
1129 ev_hdr = &ev_v2->hdr.v1;
1130 pull_len = sizeof(*ev_v2);
1131 } else {
1132 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
1133 ev_hdr = &ev_v1->hdr;
1134 pull_len = sizeof(*ev_v1);
1135 }
1136
1137 channel = __le32_to_cpu(ev_hdr->channel);
1138 buf_len = __le32_to_cpu(ev_hdr->buf_len);
1139 rx_status = __le32_to_cpu(ev_hdr->status);
1140 snr = __le32_to_cpu(ev_hdr->snr);
1141 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
1142 rate = __le32_to_cpu(ev_hdr->rate);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001143
1144 memset(status, 0, sizeof(*status));
1145
Michal Kazior7aa7a722014-08-25 12:09:38 +02001146 ath10k_dbg(ar, ATH10K_DBG_MGMT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001147 "event mgmt rx status %08x\n", rx_status);
1148
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001149 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
1150 dev_kfree_skb(skb);
1151 return 0;
1152 }
1153
Kalle Valo5e3dd152013-06-12 20:52:10 +03001154 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
1155 dev_kfree_skb(skb);
1156 return 0;
1157 }
1158
1159 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
1160 dev_kfree_skb(skb);
1161 return 0;
1162 }
1163
1164 if (rx_status & WMI_RX_STATUS_ERR_CRC)
1165 status->flag |= RX_FLAG_FAILED_FCS_CRC;
1166 if (rx_status & WMI_RX_STATUS_ERR_MIC)
1167 status->flag |= RX_FLAG_MMIC_ERROR;
1168
Michal Kazior453cdb62013-12-13 10:44:43 +01001169 /* HW can Rx CCK rates on 5GHz. In that case phy_mode is set to
1170 * MODE_11B. This means phy_mode is not a reliable source for the band
1171 * of mgmt rx. */
1172
1173 ch = ar->scan_channel;
1174 if (!ch)
1175 ch = ar->rx_channel;
1176
1177 if (ch) {
1178 status->band = ch->band;
1179
1180 if (phy_mode == MODE_11B &&
1181 status->band == IEEE80211_BAND_5GHZ)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001182 ath10k_dbg(ar, ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
Michal Kazior453cdb62013-12-13 10:44:43 +01001183 } else {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001184 ath10k_warn(ar, "using (unreliable) phy_mode to extract band for mgmt rx\n");
Michal Kazior453cdb62013-12-13 10:44:43 +01001185 status->band = phy_mode_to_band(phy_mode);
1186 }
1187
Kalle Valo5e3dd152013-06-12 20:52:10 +03001188 status->freq = ieee80211_channel_to_frequency(channel, status->band);
1189 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
1190 status->rate_idx = get_rate_idx(rate, status->band);
1191
Michal Kazior0d9b0432013-08-09 10:13:33 +02001192 skb_pull(skb, pull_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001193
1194 hdr = (struct ieee80211_hdr *)skb->data;
1195 fc = le16_to_cpu(hdr->frame_control);
1196
Michal Kazior2b6a6a92013-12-05 06:53:41 +01001197 /* FW delivers WEP Shared Auth frame with Protected Bit set and
1198 * encrypted payload. However in case of PMF it delivers decrypted
1199 * frames with Protected Bit set. */
1200 if (ieee80211_has_protected(hdr->frame_control) &&
1201 !ieee80211_is_auth(hdr->frame_control)) {
Marek Kwaczynskieeab2662014-05-14 16:56:17 +03001202 status->flag |= RX_FLAG_DECRYPTED;
1203
1204 if (!ieee80211_is_action(hdr->frame_control) &&
1205 !ieee80211_is_deauth(hdr->frame_control) &&
1206 !ieee80211_is_disassoc(hdr->frame_control)) {
1207 status->flag |= RX_FLAG_IV_STRIPPED |
1208 RX_FLAG_MMIC_STRIPPED;
1209 hdr->frame_control = __cpu_to_le16(fc &
Kalle Valo5e3dd152013-06-12 20:52:10 +03001210 ~IEEE80211_FCTL_PROTECTED);
Marek Kwaczynskieeab2662014-05-14 16:56:17 +03001211 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001212 }
1213
Michal Kazior7aa7a722014-08-25 12:09:38 +02001214 ath10k_dbg(ar, ATH10K_DBG_MGMT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001215 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
1216 skb, skb->len,
1217 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
1218
Michal Kazior7aa7a722014-08-25 12:09:38 +02001219 ath10k_dbg(ar, ATH10K_DBG_MGMT,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001220 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
1221 status->freq, status->band, status->signal,
1222 status->rate_idx);
1223
1224 /*
1225 * packets from HTC come aligned to 4byte boundaries
1226 * because they can originally come in along with a trailer
1227 */
1228 skb_trim(skb, buf_len);
1229
1230 ieee80211_rx(ar->hw, skb);
1231 return 0;
1232}
1233
Michal Kazior2e1dea42013-07-31 10:32:40 +02001234static int freq_to_idx(struct ath10k *ar, int freq)
1235{
1236 struct ieee80211_supported_band *sband;
1237 int band, ch, idx = 0;
1238
1239 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
1240 sband = ar->hw->wiphy->bands[band];
1241 if (!sband)
1242 continue;
1243
1244 for (ch = 0; ch < sband->n_channels; ch++, idx++)
1245 if (sband->channels[ch].center_freq == freq)
1246 goto exit;
1247 }
1248
1249exit:
1250 return idx;
1251}
1252
Kalle Valo5e3dd152013-06-12 20:52:10 +03001253static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
1254{
Michal Kazior2e1dea42013-07-31 10:32:40 +02001255 struct wmi_chan_info_event *ev;
1256 struct survey_info *survey;
1257 u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
1258 int idx;
1259
1260 ev = (struct wmi_chan_info_event *)skb->data;
1261
1262 err_code = __le32_to_cpu(ev->err_code);
1263 freq = __le32_to_cpu(ev->freq);
1264 cmd_flags = __le32_to_cpu(ev->cmd_flags);
1265 noise_floor = __le32_to_cpu(ev->noise_floor);
1266 rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
1267 cycle_count = __le32_to_cpu(ev->cycle_count);
1268
Michal Kazior7aa7a722014-08-25 12:09:38 +02001269 ath10k_dbg(ar, ATH10K_DBG_WMI,
Michal Kazior2e1dea42013-07-31 10:32:40 +02001270 "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
1271 err_code, freq, cmd_flags, noise_floor, rx_clear_count,
1272 cycle_count);
1273
1274 spin_lock_bh(&ar->data_lock);
1275
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001276 switch (ar->scan.state) {
1277 case ATH10K_SCAN_IDLE:
1278 case ATH10K_SCAN_STARTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02001279 ath10k_warn(ar, "received chan info event without a scan request, ignoring\n");
Michal Kazior2e1dea42013-07-31 10:32:40 +02001280 goto exit;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001281 case ATH10K_SCAN_RUNNING:
1282 case ATH10K_SCAN_ABORTING:
1283 break;
Michal Kazior2e1dea42013-07-31 10:32:40 +02001284 }
1285
1286 idx = freq_to_idx(ar, freq);
1287 if (idx >= ARRAY_SIZE(ar->survey)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001288 ath10k_warn(ar, "chan info: invalid frequency %d (idx %d out of bounds)\n",
Michal Kazior2e1dea42013-07-31 10:32:40 +02001289 freq, idx);
1290 goto exit;
1291 }
1292
1293 if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
1294 /* During scanning chan info is reported twice for each
1295 * visited channel. The reported cycle count is global
1296 * and per-channel cycle count must be calculated */
1297
1298 cycle_count -= ar->survey_last_cycle_count;
1299 rx_clear_count -= ar->survey_last_rx_clear_count;
1300
1301 survey = &ar->survey[idx];
1302 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
1303 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
1304 survey->noise = noise_floor;
1305 survey->filled = SURVEY_INFO_CHANNEL_TIME |
1306 SURVEY_INFO_CHANNEL_TIME_RX |
1307 SURVEY_INFO_NOISE_DBM;
1308 }
1309
1310 ar->survey_last_rx_clear_count = rx_clear_count;
1311 ar->survey_last_cycle_count = cycle_count;
1312
1313exit:
1314 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001315}
1316
1317static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
1318{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001319 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001320}
1321
Kalle Valo869526b2014-01-03 12:59:26 +02001322static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001323{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001324 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
Kalle Valo869526b2014-01-03 12:59:26 +02001325 skb->len);
1326
Michal Kaziord35a6c12014-09-02 11:00:21 +03001327 trace_ath10k_wmi_dbglog(ar, skb->data, skb->len);
Kalle Valo869526b2014-01-03 12:59:26 +02001328
1329 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001330}
1331
1332static void ath10k_wmi_event_update_stats(struct ath10k *ar,
1333 struct sk_buff *skb)
1334{
1335 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
1336
Michal Kazior7aa7a722014-08-25 12:09:38 +02001337 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001338
1339 ath10k_debug_read_target_stats(ar, ev);
1340}
1341
1342static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
1343 struct sk_buff *skb)
1344{
1345 struct wmi_vdev_start_response_event *ev;
1346
Michal Kazior7aa7a722014-08-25 12:09:38 +02001347 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001348
1349 ev = (struct wmi_vdev_start_response_event *)skb->data;
1350
1351 if (WARN_ON(__le32_to_cpu(ev->status)))
1352 return;
1353
1354 complete(&ar->vdev_setup_done);
1355}
1356
1357static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
1358 struct sk_buff *skb)
1359{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001360 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001361 complete(&ar->vdev_setup_done);
1362}
1363
1364static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
1365 struct sk_buff *skb)
1366{
Kalle Valo5a13e762014-01-20 11:01:46 +02001367 struct wmi_peer_sta_kickout_event *ev;
1368 struct ieee80211_sta *sta;
1369
1370 ev = (struct wmi_peer_sta_kickout_event *)skb->data;
1371
Michal Kazior7aa7a722014-08-25 12:09:38 +02001372 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
Kalle Valo5a13e762014-01-20 11:01:46 +02001373 ev->peer_macaddr.addr);
1374
1375 rcu_read_lock();
1376
1377 sta = ieee80211_find_sta_by_ifaddr(ar->hw, ev->peer_macaddr.addr, NULL);
1378 if (!sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001379 ath10k_warn(ar, "Spurious quick kickout for STA %pM\n",
Kalle Valo5a13e762014-01-20 11:01:46 +02001380 ev->peer_macaddr.addr);
1381 goto exit;
1382 }
1383
1384 ieee80211_report_low_ack(sta, 10);
1385
1386exit:
1387 rcu_read_unlock();
Kalle Valo5e3dd152013-06-12 20:52:10 +03001388}
1389
1390/*
1391 * FIXME
1392 *
1393 * We don't report to mac80211 sleep state of connected
1394 * stations. Due to this mac80211 can't fill in TIM IE
1395 * correctly.
1396 *
1397 * I know of no way of getting nullfunc frames that contain
1398 * sleep transition from connected stations - these do not
1399 * seem to be sent from the target to the host. There also
1400 * doesn't seem to be a dedicated event for that. So the
1401 * only way left to do this would be to read tim_bitmap
1402 * during SWBA.
1403 *
1404 * We could probably try using tim_bitmap from SWBA to tell
1405 * mac80211 which stations are asleep and which are not. The
1406 * problem here is calling mac80211 functions so many times
1407 * could take too long and make us miss the time to submit
1408 * the beacon to the target.
1409 *
1410 * So as a workaround we try to extend the TIM IE if there
1411 * is unicast buffered for stations with aid > 7 and fill it
1412 * in ourselves.
1413 */
1414static void ath10k_wmi_update_tim(struct ath10k *ar,
1415 struct ath10k_vif *arvif,
1416 struct sk_buff *bcn,
1417 struct wmi_bcn_info *bcn_info)
1418{
1419 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
1420 struct ieee80211_tim_ie *tim;
1421 u8 *ies, *ie;
1422 u8 ie_len, pvm_len;
Kalle Valoaf762c02014-09-14 12:50:17 +03001423 __le32 t;
1424 u32 v;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001425
1426 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
1427 * we must copy the bitmap upon change and reuse it later */
1428 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
1429 int i;
1430
1431 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
1432 sizeof(bcn_info->tim_info.tim_bitmap));
1433
1434 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
Kalle Valoaf762c02014-09-14 12:50:17 +03001435 t = bcn_info->tim_info.tim_bitmap[i / 4];
1436 v = __le32_to_cpu(t);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001437 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
1438 }
1439
1440 /* FW reports either length 0 or 16
1441 * so we calculate this on our own */
1442 arvif->u.ap.tim_len = 0;
1443 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
1444 if (arvif->u.ap.tim_bitmap[i])
1445 arvif->u.ap.tim_len = i;
1446
1447 arvif->u.ap.tim_len++;
1448 }
1449
1450 ies = bcn->data;
1451 ies += ieee80211_hdrlen(hdr->frame_control);
1452 ies += 12; /* fixed parameters */
1453
1454 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
1455 (u8 *)skb_tail_pointer(bcn) - ies);
1456 if (!ie) {
Michal Kazior09af8f82013-07-05 16:15:08 +03001457 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001458 ath10k_warn(ar, "no tim ie found;\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001459 return;
1460 }
1461
1462 tim = (void *)ie + 2;
1463 ie_len = ie[1];
1464 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
1465
1466 if (pvm_len < arvif->u.ap.tim_len) {
1467 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
1468 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
1469 void *next_ie = ie + 2 + ie_len;
1470
1471 if (skb_put(bcn, expand_size)) {
1472 memmove(next_ie + expand_size, next_ie, move_size);
1473
1474 ie[1] += expand_size;
1475 ie_len += expand_size;
1476 pvm_len += expand_size;
1477 } else {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001478 ath10k_warn(ar, "tim expansion failed\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001479 }
1480 }
1481
1482 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001483 ath10k_warn(ar, "tim pvm length is too great (%d)\n", pvm_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001484 return;
1485 }
1486
1487 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
1488 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
1489
Michal Kazior748afc42014-01-23 12:48:21 +01001490 if (tim->dtim_count == 0) {
1491 ATH10K_SKB_CB(bcn)->bcn.dtim_zero = true;
1492
1493 if (__le32_to_cpu(bcn_info->tim_info.tim_mcast) == 1)
1494 ATH10K_SKB_CB(bcn)->bcn.deliver_cab = true;
1495 }
1496
Michal Kazior7aa7a722014-08-25 12:09:38 +02001497 ath10k_dbg(ar, ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498 tim->dtim_count, tim->dtim_period,
1499 tim->bitmap_ctrl, pvm_len);
1500}
1501
1502static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
1503 struct wmi_p2p_noa_info *noa)
1504{
1505 struct ieee80211_p2p_noa_attr *noa_attr;
1506 u8 ctwindow_oppps = noa->ctwindow_oppps;
1507 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
1508 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
1509 __le16 *noa_attr_len;
1510 u16 attr_len;
1511 u8 noa_descriptors = noa->num_descriptors;
1512 int i;
1513
1514 /* P2P IE */
1515 data[0] = WLAN_EID_VENDOR_SPECIFIC;
1516 data[1] = len - 2;
1517 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1518 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1519 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1520 data[5] = WLAN_OUI_TYPE_WFA_P2P;
1521
1522 /* NOA ATTR */
1523 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
1524 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
1525 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
1526
1527 noa_attr->index = noa->index;
1528 noa_attr->oppps_ctwindow = ctwindow;
1529 if (oppps)
1530 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
1531
1532 for (i = 0; i < noa_descriptors; i++) {
1533 noa_attr->desc[i].count =
1534 __le32_to_cpu(noa->descriptors[i].type_count);
1535 noa_attr->desc[i].duration = noa->descriptors[i].duration;
1536 noa_attr->desc[i].interval = noa->descriptors[i].interval;
1537 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
1538 }
1539
1540 attr_len = 2; /* index + oppps_ctwindow */
1541 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1542 *noa_attr_len = __cpu_to_le16(attr_len);
1543}
1544
1545static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
1546{
1547 u32 len = 0;
1548 u8 noa_descriptors = noa->num_descriptors;
1549 u8 opp_ps_info = noa->ctwindow_oppps;
1550 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
1551
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552 if (!noa_descriptors && !opps_enabled)
1553 return len;
1554
1555 len += 1 + 1 + 4; /* EID + len + OUI */
1556 len += 1 + 2; /* noa attr + attr len */
1557 len += 1 + 1; /* index + oppps_ctwindow */
1558 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1559
1560 return len;
1561}
1562
1563static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
1564 struct sk_buff *bcn,
1565 struct wmi_bcn_info *bcn_info)
1566{
1567 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
1568 u8 *new_data, *old_data = arvif->u.ap.noa_data;
1569 u32 new_len;
1570
1571 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1572 return;
1573
Michal Kazior7aa7a722014-08-25 12:09:38 +02001574 ath10k_dbg(ar, ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
1576 new_len = ath10k_p2p_calc_noa_ie_len(noa);
1577 if (!new_len)
1578 goto cleanup;
1579
1580 new_data = kmalloc(new_len, GFP_ATOMIC);
1581 if (!new_data)
1582 goto cleanup;
1583
1584 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
1585
1586 spin_lock_bh(&ar->data_lock);
1587 arvif->u.ap.noa_data = new_data;
1588 arvif->u.ap.noa_len = new_len;
1589 spin_unlock_bh(&ar->data_lock);
1590 kfree(old_data);
1591 }
1592
1593 if (arvif->u.ap.noa_data)
1594 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
1595 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
1596 arvif->u.ap.noa_data,
1597 arvif->u.ap.noa_len);
1598 return;
1599
1600cleanup:
1601 spin_lock_bh(&ar->data_lock);
1602 arvif->u.ap.noa_data = NULL;
1603 arvif->u.ap.noa_len = 0;
1604 spin_unlock_bh(&ar->data_lock);
1605 kfree(old_data);
1606}
1607
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1609{
1610 struct wmi_host_swba_event *ev;
1611 u32 map;
1612 int i = -1;
1613 struct wmi_bcn_info *bcn_info;
1614 struct ath10k_vif *arvif;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 struct sk_buff *bcn;
Michal Kazior64badcb2014-09-18 11:18:02 +03001616 dma_addr_t paddr;
Michal Kazior767d34f2014-02-27 18:50:03 +02001617 int ret, vdev_id = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618
Kalle Valo5e3dd152013-06-12 20:52:10 +03001619 ev = (struct wmi_host_swba_event *)skb->data;
1620 map = __le32_to_cpu(ev->vdev_map);
1621
Michal Kazior7aa7a722014-08-25 12:09:38 +02001622 ath10k_dbg(ar, ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001623 ev->vdev_map);
1624
1625 for (; map; map >>= 1, vdev_id++) {
1626 if (!(map & 0x1))
1627 continue;
1628
1629 i++;
1630
1631 if (i >= WMI_MAX_AP_VDEV) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001632 ath10k_warn(ar, "swba has corrupted vdev map\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 break;
1634 }
1635
1636 bcn_info = &ev->bcn_info[i];
1637
Michal Kazior7aa7a722014-08-25 12:09:38 +02001638 ath10k_dbg(ar, ATH10K_DBG_MGMT,
Kalle Valo7a8a3962014-03-28 14:35:16 +02001639 "mgmt event bcn_info %d tim_len %d mcast %d changed %d num_ps_pending %d bitmap 0x%08x%08x%08x%08x\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001640 i,
1641 __le32_to_cpu(bcn_info->tim_info.tim_len),
1642 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
1643 __le32_to_cpu(bcn_info->tim_info.tim_changed),
1644 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
1645 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
1646 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
1647 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
1648 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
1649
1650 arvif = ath10k_get_arvif(ar, vdev_id);
1651 if (arvif == NULL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001652 ath10k_warn(ar, "no vif for vdev_id %d found\n",
1653 vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001654 continue;
1655 }
1656
Michal Kaziorc2df44b2014-01-23 11:38:26 +01001657 /* There are no completions for beacons so wait for next SWBA
1658 * before telling mac80211 to decrement CSA counter
1659 *
1660 * Once CSA counter is completed stop sending beacons until
1661 * actual channel switch is done */
1662 if (arvif->vif->csa_active &&
1663 ieee80211_csa_is_complete(arvif->vif)) {
1664 ieee80211_csa_finish(arvif->vif);
1665 continue;
1666 }
1667
Kalle Valo5e3dd152013-06-12 20:52:10 +03001668 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
1669 if (!bcn) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001670 ath10k_warn(ar, "could not get mac80211 beacon\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671 continue;
1672 }
1673
Michal Kazior4b604552014-07-21 21:03:09 +03001674 ath10k_tx_h_seq_no(arvif->vif, bcn);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001675 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
1676 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
1677
Michal Kaziored543882013-09-13 14:16:56 +02001678 spin_lock_bh(&ar->data_lock);
Michal Kazior748afc42014-01-23 12:48:21 +01001679
Michal Kaziored543882013-09-13 14:16:56 +02001680 if (arvif->beacon) {
Michal Kazior748afc42014-01-23 12:48:21 +01001681 if (!arvif->beacon_sent)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001682 ath10k_warn(ar, "SWBA overrun on vdev %d\n",
Michal Kazior748afc42014-01-23 12:48:21 +01001683 arvif->vdev_id);
1684
Michal Kazior64badcb2014-09-18 11:18:02 +03001685 ath10k_mac_vif_beacon_free(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02001686 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001687
Michal Kazior64badcb2014-09-18 11:18:02 +03001688 if (!arvif->beacon_buf) {
1689 paddr = dma_map_single(arvif->ar->dev, bcn->data,
1690 bcn->len, DMA_TO_DEVICE);
1691 ret = dma_mapping_error(arvif->ar->dev, paddr);
1692 if (ret) {
1693 ath10k_warn(ar, "failed to map beacon: %d\n",
1694 ret);
1695 dev_kfree_skb_any(bcn);
1696 goto skip;
1697 }
1698
1699 ATH10K_SKB_CB(bcn)->paddr = paddr;
1700 } else {
1701 if (bcn->len > IEEE80211_MAX_FRAME_LEN) {
1702 ath10k_warn(ar, "trimming beacon %d -> %d bytes!\n",
1703 bcn->len, IEEE80211_MAX_FRAME_LEN);
1704 skb_trim(bcn, IEEE80211_MAX_FRAME_LEN);
1705 }
1706 memcpy(arvif->beacon_buf, bcn->data, bcn->len);
1707 ATH10K_SKB_CB(bcn)->paddr = arvif->beacon_paddr;
Michal Kazior767d34f2014-02-27 18:50:03 +02001708 }
Michal Kazior748afc42014-01-23 12:48:21 +01001709
Michal Kaziored543882013-09-13 14:16:56 +02001710 arvif->beacon = bcn;
Michal Kazior748afc42014-01-23 12:48:21 +01001711 arvif->beacon_sent = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001712
Michal Kaziored543882013-09-13 14:16:56 +02001713 ath10k_wmi_tx_beacon_nowait(arvif);
Michal Kazior767d34f2014-02-27 18:50:03 +02001714skip:
Michal Kaziored543882013-09-13 14:16:56 +02001715 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716 }
1717}
1718
1719static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
1720 struct sk_buff *skb)
1721{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001722 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001723}
1724
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001725static void ath10k_dfs_radar_report(struct ath10k *ar,
1726 struct wmi_single_phyerr_rx_event *event,
1727 struct phyerr_radar_report *rr,
1728 u64 tsf)
1729{
1730 u32 reg0, reg1, tsf32l;
1731 struct pulse_event pe;
1732 u64 tsf64;
1733 u8 rssi, width;
1734
1735 reg0 = __le32_to_cpu(rr->reg0);
1736 reg1 = __le32_to_cpu(rr->reg1);
1737
Michal Kazior7aa7a722014-08-25 12:09:38 +02001738 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001739 "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
1740 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
1741 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
1742 MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
1743 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
Michal Kazior7aa7a722014-08-25 12:09:38 +02001744 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001745 "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
1746 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
1747 MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
1748 MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
1749 MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
1750 MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
Michal Kazior7aa7a722014-08-25 12:09:38 +02001751 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001752 "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
1753 MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
1754 MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
1755
1756 if (!ar->dfs_detector)
1757 return;
1758
1759 /* report event to DFS pattern detector */
1760 tsf32l = __le32_to_cpu(event->hdr.tsf_timestamp);
1761 tsf64 = tsf & (~0xFFFFFFFFULL);
1762 tsf64 |= tsf32l;
1763
1764 width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
1765 rssi = event->hdr.rssi_combined;
1766
1767 /* hardware store this as 8 bit signed value,
1768 * set to zero if negative number
1769 */
1770 if (rssi & 0x80)
1771 rssi = 0;
1772
1773 pe.ts = tsf64;
1774 pe.freq = ar->hw->conf.chandef.chan->center_freq;
1775 pe.width = width;
1776 pe.rssi = rssi;
1777
Michal Kazior7aa7a722014-08-25 12:09:38 +02001778 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001779 "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
1780 pe.freq, pe.width, pe.rssi, pe.ts);
1781
1782 ATH10K_DFS_STAT_INC(ar, pulses_detected);
1783
1784 if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001785 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001786 "dfs no pulse pattern detected, yet\n");
1787 return;
1788 }
1789
Michal Kazior7aa7a722014-08-25 12:09:38 +02001790 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs radar detected\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001791 ATH10K_DFS_STAT_INC(ar, radar_detected);
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001792
1793 /* Control radar events reporting in debugfs file
1794 dfs_block_radar_events */
1795 if (ar->dfs_block_radar_events) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001796 ath10k_info(ar, "DFS Radar detected, but ignored as requested\n");
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001797 return;
1798 }
1799
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001800 ieee80211_radar_detected(ar->hw);
1801}
1802
1803static int ath10k_dfs_fft_report(struct ath10k *ar,
1804 struct wmi_single_phyerr_rx_event *event,
1805 struct phyerr_fft_report *fftr,
1806 u64 tsf)
1807{
1808 u32 reg0, reg1;
1809 u8 rssi, peak_mag;
1810
1811 reg0 = __le32_to_cpu(fftr->reg0);
1812 reg1 = __le32_to_cpu(fftr->reg1);
1813 rssi = event->hdr.rssi_combined;
1814
Michal Kazior7aa7a722014-08-25 12:09:38 +02001815 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001816 "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
1817 MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
1818 MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
1819 MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
1820 MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
Michal Kazior7aa7a722014-08-25 12:09:38 +02001821 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001822 "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
1823 MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
1824 MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
1825 MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
1826 MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
1827
1828 peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
1829
1830 /* false event detection */
1831 if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
1832 peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001833 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001834 ATH10K_DFS_STAT_INC(ar, pulses_discarded);
1835 return -EINVAL;
1836 }
1837
1838 return 0;
1839}
1840
1841static void ath10k_wmi_event_dfs(struct ath10k *ar,
1842 struct wmi_single_phyerr_rx_event *event,
1843 u64 tsf)
1844{
1845 int buf_len, tlv_len, res, i = 0;
1846 struct phyerr_tlv *tlv;
1847 struct phyerr_radar_report *rr;
1848 struct phyerr_fft_report *fftr;
1849 u8 *tlv_buf;
1850
1851 buf_len = __le32_to_cpu(event->hdr.buf_len);
Michal Kazior7aa7a722014-08-25 12:09:38 +02001852 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001853 "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
1854 event->hdr.phy_err_code, event->hdr.rssi_combined,
1855 __le32_to_cpu(event->hdr.tsf_timestamp), tsf, buf_len);
1856
1857 /* Skip event if DFS disabled */
1858 if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED))
1859 return;
1860
1861 ATH10K_DFS_STAT_INC(ar, pulses_total);
1862
1863 while (i < buf_len) {
1864 if (i + sizeof(*tlv) > buf_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001865 ath10k_warn(ar, "too short buf for tlv header (%d)\n",
1866 i);
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001867 return;
1868 }
1869
1870 tlv = (struct phyerr_tlv *)&event->bufp[i];
1871 tlv_len = __le16_to_cpu(tlv->len);
1872 tlv_buf = &event->bufp[i + sizeof(*tlv)];
Michal Kazior7aa7a722014-08-25 12:09:38 +02001873 ath10k_dbg(ar, ATH10K_DBG_REGULATORY,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001874 "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
1875 tlv_len, tlv->tag, tlv->sig);
1876
1877 switch (tlv->tag) {
1878 case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
1879 if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001880 ath10k_warn(ar, "too short radar pulse summary (%d)\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001881 i);
1882 return;
1883 }
1884
1885 rr = (struct phyerr_radar_report *)tlv_buf;
1886 ath10k_dfs_radar_report(ar, event, rr, tsf);
1887 break;
1888 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1889 if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001890 ath10k_warn(ar, "too short fft report (%d)\n",
1891 i);
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001892 return;
1893 }
1894
1895 fftr = (struct phyerr_fft_report *)tlv_buf;
1896 res = ath10k_dfs_fft_report(ar, event, fftr, tsf);
1897 if (res)
1898 return;
1899 break;
1900 }
1901
1902 i += sizeof(*tlv) + tlv_len;
1903 }
1904}
1905
Kalle Valo5b07e072014-09-14 12:50:06 +03001906static void
1907ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1908 struct wmi_single_phyerr_rx_event *event,
1909 u64 tsf)
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001910{
Simon Wunderlich855aed12014-08-02 09:12:54 +03001911 int buf_len, tlv_len, res, i = 0;
1912 struct phyerr_tlv *tlv;
1913 u8 *tlv_buf;
1914 struct phyerr_fft_report *fftr;
1915 size_t fftr_len;
1916
1917 buf_len = __le32_to_cpu(event->hdr.buf_len);
1918
1919 while (i < buf_len) {
1920 if (i + sizeof(*tlv) > buf_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001921 ath10k_warn(ar, "failed to parse phyerr tlv header at byte %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03001922 i);
1923 return;
1924 }
1925
1926 tlv = (struct phyerr_tlv *)&event->bufp[i];
1927 tlv_len = __le16_to_cpu(tlv->len);
1928 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1929
1930 if (i + sizeof(*tlv) + tlv_len > buf_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001931 ath10k_warn(ar, "failed to parse phyerr tlv payload at byte %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03001932 i);
1933 return;
1934 }
1935
1936 switch (tlv->tag) {
1937 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1938 if (sizeof(*fftr) > tlv_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001939 ath10k_warn(ar, "failed to parse fft report at byte %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03001940 i);
1941 return;
1942 }
1943
1944 fftr_len = tlv_len - sizeof(*fftr);
1945 fftr = (struct phyerr_fft_report *)tlv_buf;
1946 res = ath10k_spectral_process_fft(ar, event,
1947 fftr, fftr_len,
1948 tsf);
1949 if (res < 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001950 ath10k_warn(ar, "failed to process fft report: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03001951 res);
1952 return;
1953 }
1954 break;
1955 }
1956
1957 i += sizeof(*tlv) + tlv_len;
1958 }
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001959}
1960
Kalle Valo5e3dd152013-06-12 20:52:10 +03001961static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1962{
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001963 struct wmi_comb_phyerr_rx_event *comb_event;
1964 struct wmi_single_phyerr_rx_event *event;
1965 u32 count, i, buf_len, phy_err_code;
1966 u64 tsf;
1967 int left_len = skb->len;
1968
1969 ATH10K_DFS_STAT_INC(ar, phy_errors);
1970
1971 /* Check if combined event available */
1972 if (left_len < sizeof(*comb_event)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001973 ath10k_warn(ar, "wmi phyerr combined event wrong len\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001974 return;
1975 }
1976
1977 left_len -= sizeof(*comb_event);
1978
1979 /* Check number of included events */
1980 comb_event = (struct wmi_comb_phyerr_rx_event *)skb->data;
1981 count = __le32_to_cpu(comb_event->hdr.num_phyerr_events);
1982
1983 tsf = __le32_to_cpu(comb_event->hdr.tsf_u32);
1984 tsf <<= 32;
1985 tsf |= __le32_to_cpu(comb_event->hdr.tsf_l32);
1986
Michal Kazior7aa7a722014-08-25 12:09:38 +02001987 ath10k_dbg(ar, ATH10K_DBG_WMI,
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001988 "wmi event phyerr count %d tsf64 0x%llX\n",
1989 count, tsf);
1990
1991 event = (struct wmi_single_phyerr_rx_event *)comb_event->bufp;
1992 for (i = 0; i < count; i++) {
1993 /* Check if we can read event header */
1994 if (left_len < sizeof(*event)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001995 ath10k_warn(ar, "single event (%d) wrong head len\n",
1996 i);
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001997 return;
1998 }
1999
2000 left_len -= sizeof(*event);
2001
2002 buf_len = __le32_to_cpu(event->hdr.buf_len);
2003 phy_err_code = event->hdr.phy_err_code;
2004
2005 if (left_len < buf_len) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002006 ath10k_warn(ar, "single event (%d) wrong buf len\n", i);
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002007 return;
2008 }
2009
2010 left_len -= buf_len;
2011
2012 switch (phy_err_code) {
2013 case PHY_ERROR_RADAR:
2014 ath10k_wmi_event_dfs(ar, event, tsf);
2015 break;
2016 case PHY_ERROR_SPECTRAL_SCAN:
2017 ath10k_wmi_event_spectral_scan(ar, event, tsf);
2018 break;
2019 case PHY_ERROR_FALSE_RADAR_EXT:
2020 ath10k_wmi_event_dfs(ar, event, tsf);
2021 ath10k_wmi_event_spectral_scan(ar, event, tsf);
2022 break;
2023 default:
2024 break;
2025 }
2026
2027 event += sizeof(*event) + buf_len;
2028 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002029}
2030
2031static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
2032{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002033 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002034}
2035
2036static void ath10k_wmi_event_profile_match(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03002037 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002039 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002040}
2041
2042static void ath10k_wmi_event_debug_print(struct ath10k *ar,
Kalle Valo2fe52882014-01-03 12:59:20 +02002043 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002044{
Kalle Valo2fe52882014-01-03 12:59:20 +02002045 char buf[101], c;
2046 int i;
2047
2048 for (i = 0; i < sizeof(buf) - 1; i++) {
2049 if (i >= skb->len)
2050 break;
2051
2052 c = skb->data[i];
2053
2054 if (c == '\0')
2055 break;
2056
2057 if (isascii(c) && isprint(c))
2058 buf[i] = c;
2059 else
2060 buf[i] = '.';
2061 }
2062
2063 if (i == sizeof(buf) - 1)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002064 ath10k_warn(ar, "wmi debug print truncated: %d\n", skb->len);
Kalle Valo2fe52882014-01-03 12:59:20 +02002065
2066 /* for some reason the debug prints end with \n, remove that */
2067 if (skb->data[i - 1] == '\n')
2068 i--;
2069
2070 /* the last byte is always reserved for the null character */
2071 buf[i] = '\0';
2072
Michal Kazior7aa7a722014-08-25 12:09:38 +02002073 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi event debug print '%s'\n", buf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074}
2075
2076static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
2077{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002078 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079}
2080
2081static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
2082 struct sk_buff *skb)
2083{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002084 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085}
2086
2087static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03002088 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002090 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091}
2092
2093static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03002094 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002096 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002097}
2098
2099static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
2100 struct sk_buff *skb)
2101{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002102 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002103}
2104
2105static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
2106 struct sk_buff *skb)
2107{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002108 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002109}
2110
2111static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
2112 struct sk_buff *skb)
2113{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002114 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002115}
2116
2117static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
2118 struct sk_buff *skb)
2119{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002120 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002121}
2122
2123static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
2124 struct sk_buff *skb)
2125{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002126 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002127}
2128
2129static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03002130 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002131{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002132 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133}
2134
2135static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
2136 struct sk_buff *skb)
2137{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002138 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002139}
2140
2141static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
2142 struct sk_buff *skb)
2143{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002144 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002145}
2146
2147static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
2148 struct sk_buff *skb)
2149{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002150 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002151}
2152
2153static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03002154 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002155{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002156 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157}
2158
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002159static void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar,
2160 struct sk_buff *skb)
2161{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002162 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002163}
2164
2165static void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar,
2166 struct sk_buff *skb)
2167{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002168 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002169}
2170
2171static void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar,
2172 struct sk_buff *skb)
2173{
Michal Kazior7aa7a722014-08-25 12:09:38 +02002174 ath10k_dbg(ar, ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002175}
2176
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002177static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
Kalle Valo5b07e072014-09-14 12:50:06 +03002178 u32 num_units, u32 unit_len)
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002179{
2180 dma_addr_t paddr;
2181 u32 pool_size;
2182 int idx = ar->wmi.num_mem_chunks;
2183
2184 pool_size = num_units * round_up(unit_len, 4);
2185
2186 if (!pool_size)
2187 return -EINVAL;
2188
2189 ar->wmi.mem_chunks[idx].vaddr = dma_alloc_coherent(ar->dev,
2190 pool_size,
2191 &paddr,
2192 GFP_ATOMIC);
2193 if (!ar->wmi.mem_chunks[idx].vaddr) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002194 ath10k_warn(ar, "failed to allocate memory chunk\n");
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002195 return -ENOMEM;
2196 }
2197
2198 memset(ar->wmi.mem_chunks[idx].vaddr, 0, pool_size);
2199
2200 ar->wmi.mem_chunks[idx].paddr = paddr;
2201 ar->wmi.mem_chunks[idx].len = pool_size;
2202 ar->wmi.mem_chunks[idx].req_id = req_id;
2203 ar->wmi.num_mem_chunks++;
2204
2205 return 0;
2206}
2207
Kalle Valo5e3dd152013-06-12 20:52:10 +03002208static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
2209 struct sk_buff *skb)
2210{
2211 struct wmi_service_ready_event *ev = (void *)skb->data;
Michal Kaziorc4f8c832014-09-04 10:18:32 +02002212 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002213
2214 if (skb->len < sizeof(*ev)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002215 ath10k_warn(ar, "Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002216 skb->len, sizeof(*ev));
2217 return;
2218 }
2219
2220 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2221 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2222 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2223 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2224 ar->fw_version_major =
2225 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2226 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2227 ar->fw_version_release =
2228 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
2229 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
2230 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
Michal Kazior8865bee42013-07-24 12:36:46 +02002231 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2232
Kalle Valo1a222432013-09-27 19:55:07 +03002233 /* only manually set fw features when not using FW IE format */
2234 if (ar->fw_api == 1 && ar->fw_version_build > 636)
Michal Kazior0d9b0432013-08-09 10:13:33 +02002235 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
2236
Michal Kazior8865bee42013-07-24 12:36:46 +02002237 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002238 ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
Michal Kazior8865bee42013-07-24 12:36:46 +02002239 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2240 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2241 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002242
Michal Kaziorfdb959c2014-09-18 15:21:19 +02002243 ar->supp_tx_chainmask = (1 << ar->num_rf_chains) - 1;
2244 ar->supp_rx_chainmask = (1 << ar->num_rf_chains) - 1;
2245
Kalle Valo5e3dd152013-06-12 20:52:10 +03002246 ar->ath_common.regulatory.current_rd =
2247 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2248
Michal Kazior7a7b3732014-08-19 13:22:32 +02002249 wmi_main_svc_map(ev->wmi_service_bitmap, svc_bmap);
Michal Kaziorcff990c2014-08-04 09:18:33 +03002250 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
Michal Kazior7aa7a722014-08-25 12:09:38 +02002251 ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
Michal Kaziorcff990c2014-08-04 09:18:33 +03002252 ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002253
2254 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2255 snprintf(ar->hw->wiphy->fw_version,
2256 sizeof(ar->hw->wiphy->fw_version),
2257 "%u.%u.%u.%u",
2258 ar->fw_version_major,
2259 ar->fw_version_minor,
2260 ar->fw_version_release,
2261 ar->fw_version_build);
2262 }
2263
2264 /* FIXME: it probably should be better to support this */
2265 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002266 ath10k_warn(ar, "target requested %d memory chunks; ignoring\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002267 __le32_to_cpu(ev->num_mem_reqs));
2268 }
2269
Michal Kazior7aa7a722014-08-25 12:09:38 +02002270 ath10k_dbg(ar, ATH10K_DBG_WMI,
Michal Kazior8865bee42013-07-24 12:36:46 +02002271 "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",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002272 __le32_to_cpu(ev->sw_version),
2273 __le32_to_cpu(ev->sw_version_1),
2274 __le32_to_cpu(ev->abi_version),
2275 __le32_to_cpu(ev->phy_capability),
2276 __le32_to_cpu(ev->ht_cap_info),
2277 __le32_to_cpu(ev->vht_cap_info),
2278 __le32_to_cpu(ev->vht_supp_mcs),
2279 __le32_to_cpu(ev->sys_cap_info),
Michal Kazior8865bee42013-07-24 12:36:46 +02002280 __le32_to_cpu(ev->num_mem_reqs),
2281 __le32_to_cpu(ev->num_rf_chains));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002282
2283 complete(&ar->wmi.service_ready);
2284}
2285
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002286static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2287 struct sk_buff *skb)
2288{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002289 u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
2290 int ret;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002291 struct wmi_service_ready_event_10x *ev = (void *)skb->data;
Michal Kaziorc4f8c832014-09-04 10:18:32 +02002292 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_MAX) = {};
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002293
2294 if (skb->len < sizeof(*ev)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002295 ath10k_warn(ar, "Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002296 skb->len, sizeof(*ev));
2297 return;
2298 }
2299
2300 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2301 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2302 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2303 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2304 ar->fw_version_major =
2305 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2306 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2307 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
2308 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2309
2310 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002311 ath10k_warn(ar, "hardware advertises support for more spatial streams than it should (%d > %d)\n",
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002312 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2313 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2314 }
2315
Michal Kaziorfdb959c2014-09-18 15:21:19 +02002316 ar->supp_tx_chainmask = (1 << ar->num_rf_chains) - 1;
2317 ar->supp_rx_chainmask = (1 << ar->num_rf_chains) - 1;
2318
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002319 ar->ath_common.regulatory.current_rd =
2320 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2321
Michal Kazior7a7b3732014-08-19 13:22:32 +02002322 wmi_10x_svc_map(ev->wmi_service_bitmap, svc_bmap);
Michal Kaziorcff990c2014-08-04 09:18:33 +03002323 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
Michal Kazior7aa7a722014-08-25 12:09:38 +02002324 ath10k_dbg_dump(ar, ATH10K_DBG_WMI, NULL, "wmi svc: ",
Michal Kaziorcff990c2014-08-04 09:18:33 +03002325 ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002326
2327 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2328 snprintf(ar->hw->wiphy->fw_version,
2329 sizeof(ar->hw->wiphy->fw_version),
2330 "%u.%u",
2331 ar->fw_version_major,
2332 ar->fw_version_minor);
2333 }
2334
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002335 num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
2336
2337 if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002338 ath10k_warn(ar, "requested memory chunks number (%d) exceeds the limit\n",
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002339 num_mem_reqs);
2340 return;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002341 }
2342
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002343 if (!num_mem_reqs)
2344 goto exit;
2345
Michal Kazior7aa7a722014-08-25 12:09:38 +02002346 ath10k_dbg(ar, ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002347 num_mem_reqs);
2348
2349 for (i = 0; i < num_mem_reqs; ++i) {
2350 req_id = __le32_to_cpu(ev->mem_reqs[i].req_id);
2351 num_units = __le32_to_cpu(ev->mem_reqs[i].num_units);
2352 unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size);
2353 num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info);
2354
2355 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
2356 /* number of units to allocate is number of
2357 * peers, 1 extra for self peer on target */
2358 /* this needs to be tied, host and target
2359 * can get out of sync */
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002360 num_units = TARGET_10X_NUM_PEERS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002361 else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS)
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002362 num_units = TARGET_10X_NUM_VDEVS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002363
Michal Kazior7aa7a722014-08-25 12:09:38 +02002364 ath10k_dbg(ar, ATH10K_DBG_WMI,
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002365 "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
2366 req_id,
2367 __le32_to_cpu(ev->mem_reqs[i].num_units),
2368 num_unit_info,
2369 unit_size,
2370 num_units);
2371
2372 ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
2373 unit_size);
2374 if (ret)
2375 return;
2376 }
2377
2378exit:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002379 ath10k_dbg(ar, ATH10K_DBG_WMI,
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002380 "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",
2381 __le32_to_cpu(ev->sw_version),
2382 __le32_to_cpu(ev->abi_version),
2383 __le32_to_cpu(ev->phy_capability),
2384 __le32_to_cpu(ev->ht_cap_info),
2385 __le32_to_cpu(ev->vht_cap_info),
2386 __le32_to_cpu(ev->vht_supp_mcs),
2387 __le32_to_cpu(ev->sys_cap_info),
2388 __le32_to_cpu(ev->num_mem_reqs),
2389 __le32_to_cpu(ev->num_rf_chains));
2390
2391 complete(&ar->wmi.service_ready);
2392}
2393
Kalle Valo5e3dd152013-06-12 20:52:10 +03002394static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
2395{
2396 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
2397
2398 if (WARN_ON(skb->len < sizeof(*ev)))
2399 return -EINVAL;
2400
Kalle Valob25f32c2014-09-14 12:50:49 +03002401 ether_addr_copy(ar->mac_addr, ev->mac_addr.addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002402
Michal Kazior7aa7a722014-08-25 12:09:38 +02002403 ath10k_dbg(ar, ATH10K_DBG_WMI,
Ben Greear2c347522014-02-05 13:58:32 -08002404 "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d skb->len %i ev-sz %zu\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002405 __le32_to_cpu(ev->sw_version),
2406 __le32_to_cpu(ev->abi_version),
2407 ev->mac_addr.addr,
Ben Greear2c347522014-02-05 13:58:32 -08002408 __le32_to_cpu(ev->status), skb->len, sizeof(*ev));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002409
2410 complete(&ar->wmi.unified_ready);
2411 return 0;
2412}
2413
Bartosz Markowskice428702013-09-26 17:47:05 +02002414static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002415{
2416 struct wmi_cmd_hdr *cmd_hdr;
2417 enum wmi_event_id id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418
2419 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2420 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2421
2422 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2423 return;
2424
Michal Kaziord35a6c12014-09-02 11:00:21 +03002425 trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002426
2427 switch (id) {
2428 case WMI_MGMT_RX_EVENTID:
2429 ath10k_wmi_event_mgmt_rx(ar, skb);
2430 /* mgmt_rx() owns the skb now! */
2431 return;
2432 case WMI_SCAN_EVENTID:
2433 ath10k_wmi_event_scan(ar, skb);
2434 break;
2435 case WMI_CHAN_INFO_EVENTID:
2436 ath10k_wmi_event_chan_info(ar, skb);
2437 break;
2438 case WMI_ECHO_EVENTID:
2439 ath10k_wmi_event_echo(ar, skb);
2440 break;
2441 case WMI_DEBUG_MESG_EVENTID:
2442 ath10k_wmi_event_debug_mesg(ar, skb);
2443 break;
2444 case WMI_UPDATE_STATS_EVENTID:
2445 ath10k_wmi_event_update_stats(ar, skb);
2446 break;
2447 case WMI_VDEV_START_RESP_EVENTID:
2448 ath10k_wmi_event_vdev_start_resp(ar, skb);
2449 break;
2450 case WMI_VDEV_STOPPED_EVENTID:
2451 ath10k_wmi_event_vdev_stopped(ar, skb);
2452 break;
2453 case WMI_PEER_STA_KICKOUT_EVENTID:
2454 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2455 break;
2456 case WMI_HOST_SWBA_EVENTID:
2457 ath10k_wmi_event_host_swba(ar, skb);
2458 break;
2459 case WMI_TBTTOFFSET_UPDATE_EVENTID:
2460 ath10k_wmi_event_tbttoffset_update(ar, skb);
2461 break;
2462 case WMI_PHYERR_EVENTID:
2463 ath10k_wmi_event_phyerr(ar, skb);
2464 break;
2465 case WMI_ROAM_EVENTID:
2466 ath10k_wmi_event_roam(ar, skb);
2467 break;
2468 case WMI_PROFILE_MATCH:
2469 ath10k_wmi_event_profile_match(ar, skb);
2470 break;
2471 case WMI_DEBUG_PRINT_EVENTID:
2472 ath10k_wmi_event_debug_print(ar, skb);
2473 break;
2474 case WMI_PDEV_QVIT_EVENTID:
2475 ath10k_wmi_event_pdev_qvit(ar, skb);
2476 break;
2477 case WMI_WLAN_PROFILE_DATA_EVENTID:
2478 ath10k_wmi_event_wlan_profile_data(ar, skb);
2479 break;
2480 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
2481 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2482 break;
2483 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
2484 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2485 break;
2486 case WMI_RTT_ERROR_REPORT_EVENTID:
2487 ath10k_wmi_event_rtt_error_report(ar, skb);
2488 break;
2489 case WMI_WOW_WAKEUP_HOST_EVENTID:
2490 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2491 break;
2492 case WMI_DCS_INTERFERENCE_EVENTID:
2493 ath10k_wmi_event_dcs_interference(ar, skb);
2494 break;
2495 case WMI_PDEV_TPC_CONFIG_EVENTID:
2496 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2497 break;
2498 case WMI_PDEV_FTM_INTG_EVENTID:
2499 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
2500 break;
2501 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
2502 ath10k_wmi_event_gtk_offload_status(ar, skb);
2503 break;
2504 case WMI_GTK_REKEY_FAIL_EVENTID:
2505 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
2506 break;
2507 case WMI_TX_DELBA_COMPLETE_EVENTID:
2508 ath10k_wmi_event_delba_complete(ar, skb);
2509 break;
2510 case WMI_TX_ADDBA_COMPLETE_EVENTID:
2511 ath10k_wmi_event_addba_complete(ar, skb);
2512 break;
2513 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
2514 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
2515 break;
2516 case WMI_SERVICE_READY_EVENTID:
2517 ath10k_wmi_service_ready_event_rx(ar, skb);
2518 break;
2519 case WMI_READY_EVENTID:
2520 ath10k_wmi_ready_event_rx(ar, skb);
2521 break;
2522 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002523 ath10k_warn(ar, "Unknown eventid: %d\n", id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002524 break;
2525 }
2526
2527 dev_kfree_skb(skb);
2528}
2529
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002530static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
2531{
2532 struct wmi_cmd_hdr *cmd_hdr;
2533 enum wmi_10x_event_id id;
Kalle Valo43d2a302014-09-10 18:23:30 +03002534 bool consumed;
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002535
2536 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2537 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2538
2539 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2540 return;
2541
Michal Kaziord35a6c12014-09-02 11:00:21 +03002542 trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002543
Kalle Valo43d2a302014-09-10 18:23:30 +03002544 consumed = ath10k_tm_event_wmi(ar, id, skb);
2545
2546 /* Ready event must be handled normally also in UTF mode so that we
2547 * know the UTF firmware has booted, others we are just bypass WMI
2548 * events to testmode.
2549 */
2550 if (consumed && id != WMI_10X_READY_EVENTID) {
2551 ath10k_dbg(ar, ATH10K_DBG_WMI,
2552 "wmi testmode consumed 0x%x\n", id);
2553 goto out;
2554 }
2555
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002556 switch (id) {
2557 case WMI_10X_MGMT_RX_EVENTID:
2558 ath10k_wmi_event_mgmt_rx(ar, skb);
2559 /* mgmt_rx() owns the skb now! */
2560 return;
2561 case WMI_10X_SCAN_EVENTID:
2562 ath10k_wmi_event_scan(ar, skb);
2563 break;
2564 case WMI_10X_CHAN_INFO_EVENTID:
2565 ath10k_wmi_event_chan_info(ar, skb);
2566 break;
2567 case WMI_10X_ECHO_EVENTID:
2568 ath10k_wmi_event_echo(ar, skb);
2569 break;
2570 case WMI_10X_DEBUG_MESG_EVENTID:
2571 ath10k_wmi_event_debug_mesg(ar, skb);
2572 break;
2573 case WMI_10X_UPDATE_STATS_EVENTID:
2574 ath10k_wmi_event_update_stats(ar, skb);
2575 break;
2576 case WMI_10X_VDEV_START_RESP_EVENTID:
2577 ath10k_wmi_event_vdev_start_resp(ar, skb);
2578 break;
2579 case WMI_10X_VDEV_STOPPED_EVENTID:
2580 ath10k_wmi_event_vdev_stopped(ar, skb);
2581 break;
2582 case WMI_10X_PEER_STA_KICKOUT_EVENTID:
2583 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2584 break;
2585 case WMI_10X_HOST_SWBA_EVENTID:
2586 ath10k_wmi_event_host_swba(ar, skb);
2587 break;
2588 case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
2589 ath10k_wmi_event_tbttoffset_update(ar, skb);
2590 break;
2591 case WMI_10X_PHYERR_EVENTID:
2592 ath10k_wmi_event_phyerr(ar, skb);
2593 break;
2594 case WMI_10X_ROAM_EVENTID:
2595 ath10k_wmi_event_roam(ar, skb);
2596 break;
2597 case WMI_10X_PROFILE_MATCH:
2598 ath10k_wmi_event_profile_match(ar, skb);
2599 break;
2600 case WMI_10X_DEBUG_PRINT_EVENTID:
2601 ath10k_wmi_event_debug_print(ar, skb);
2602 break;
2603 case WMI_10X_PDEV_QVIT_EVENTID:
2604 ath10k_wmi_event_pdev_qvit(ar, skb);
2605 break;
2606 case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
2607 ath10k_wmi_event_wlan_profile_data(ar, skb);
2608 break;
2609 case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
2610 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2611 break;
2612 case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
2613 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2614 break;
2615 case WMI_10X_RTT_ERROR_REPORT_EVENTID:
2616 ath10k_wmi_event_rtt_error_report(ar, skb);
2617 break;
2618 case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
2619 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2620 break;
2621 case WMI_10X_DCS_INTERFERENCE_EVENTID:
2622 ath10k_wmi_event_dcs_interference(ar, skb);
2623 break;
2624 case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
2625 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2626 break;
2627 case WMI_10X_INST_RSSI_STATS_EVENTID:
2628 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2629 break;
2630 case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
2631 ath10k_wmi_event_vdev_standby_req(ar, skb);
2632 break;
2633 case WMI_10X_VDEV_RESUME_REQ_EVENTID:
2634 ath10k_wmi_event_vdev_resume_req(ar, skb);
2635 break;
2636 case WMI_10X_SERVICE_READY_EVENTID:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002637 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002638 break;
2639 case WMI_10X_READY_EVENTID:
2640 ath10k_wmi_ready_event_rx(ar, skb);
2641 break;
Kalle Valo43d2a302014-09-10 18:23:30 +03002642 case WMI_10X_PDEV_UTF_EVENTID:
2643 /* ignore utf events */
2644 break;
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002645 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002646 ath10k_warn(ar, "Unknown eventid: %d\n", id);
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002647 break;
2648 }
2649
Kalle Valo43d2a302014-09-10 18:23:30 +03002650out:
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002651 dev_kfree_skb(skb);
2652}
2653
Michal Kazior24c88f72014-07-25 13:32:17 +02002654static void ath10k_wmi_10_2_process_rx(struct ath10k *ar, struct sk_buff *skb)
2655{
2656 struct wmi_cmd_hdr *cmd_hdr;
2657 enum wmi_10_2_event_id id;
2658
2659 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2660 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2661
2662 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2663 return;
2664
Michal Kaziord35a6c12014-09-02 11:00:21 +03002665 trace_ath10k_wmi_event(ar, id, skb->data, skb->len);
Michal Kazior24c88f72014-07-25 13:32:17 +02002666
2667 switch (id) {
2668 case WMI_10_2_MGMT_RX_EVENTID:
2669 ath10k_wmi_event_mgmt_rx(ar, skb);
2670 /* mgmt_rx() owns the skb now! */
2671 return;
2672 case WMI_10_2_SCAN_EVENTID:
2673 ath10k_wmi_event_scan(ar, skb);
2674 break;
2675 case WMI_10_2_CHAN_INFO_EVENTID:
2676 ath10k_wmi_event_chan_info(ar, skb);
2677 break;
2678 case WMI_10_2_ECHO_EVENTID:
2679 ath10k_wmi_event_echo(ar, skb);
2680 break;
2681 case WMI_10_2_DEBUG_MESG_EVENTID:
2682 ath10k_wmi_event_debug_mesg(ar, skb);
2683 break;
2684 case WMI_10_2_UPDATE_STATS_EVENTID:
2685 ath10k_wmi_event_update_stats(ar, skb);
2686 break;
2687 case WMI_10_2_VDEV_START_RESP_EVENTID:
2688 ath10k_wmi_event_vdev_start_resp(ar, skb);
2689 break;
2690 case WMI_10_2_VDEV_STOPPED_EVENTID:
2691 ath10k_wmi_event_vdev_stopped(ar, skb);
2692 break;
2693 case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
2694 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2695 break;
2696 case WMI_10_2_HOST_SWBA_EVENTID:
2697 ath10k_wmi_event_host_swba(ar, skb);
2698 break;
2699 case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
2700 ath10k_wmi_event_tbttoffset_update(ar, skb);
2701 break;
2702 case WMI_10_2_PHYERR_EVENTID:
2703 ath10k_wmi_event_phyerr(ar, skb);
2704 break;
2705 case WMI_10_2_ROAM_EVENTID:
2706 ath10k_wmi_event_roam(ar, skb);
2707 break;
2708 case WMI_10_2_PROFILE_MATCH:
2709 ath10k_wmi_event_profile_match(ar, skb);
2710 break;
2711 case WMI_10_2_DEBUG_PRINT_EVENTID:
2712 ath10k_wmi_event_debug_print(ar, skb);
2713 break;
2714 case WMI_10_2_PDEV_QVIT_EVENTID:
2715 ath10k_wmi_event_pdev_qvit(ar, skb);
2716 break;
2717 case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
2718 ath10k_wmi_event_wlan_profile_data(ar, skb);
2719 break;
2720 case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
2721 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2722 break;
2723 case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
2724 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2725 break;
2726 case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
2727 ath10k_wmi_event_rtt_error_report(ar, skb);
2728 break;
2729 case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
2730 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2731 break;
2732 case WMI_10_2_DCS_INTERFERENCE_EVENTID:
2733 ath10k_wmi_event_dcs_interference(ar, skb);
2734 break;
2735 case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
2736 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2737 break;
2738 case WMI_10_2_INST_RSSI_STATS_EVENTID:
2739 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2740 break;
2741 case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
2742 ath10k_wmi_event_vdev_standby_req(ar, skb);
2743 break;
2744 case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
2745 ath10k_wmi_event_vdev_resume_req(ar, skb);
2746 break;
2747 case WMI_10_2_SERVICE_READY_EVENTID:
2748 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
2749 break;
2750 case WMI_10_2_READY_EVENTID:
2751 ath10k_wmi_ready_event_rx(ar, skb);
2752 break;
2753 case WMI_10_2_RTT_KEEPALIVE_EVENTID:
2754 case WMI_10_2_GPIO_INPUT_EVENTID:
2755 case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
2756 case WMI_10_2_GENERIC_BUFFER_EVENTID:
2757 case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
2758 case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
2759 case WMI_10_2_WDS_PEER_EVENTID:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002760 ath10k_dbg(ar, ATH10K_DBG_WMI,
Michal Kazior24c88f72014-07-25 13:32:17 +02002761 "received event id %d not implemented\n", id);
2762 break;
2763 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +02002764 ath10k_warn(ar, "Unknown eventid: %d\n", id);
Michal Kazior24c88f72014-07-25 13:32:17 +02002765 break;
2766 }
2767
2768 dev_kfree_skb(skb);
2769}
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002770
Bartosz Markowskice428702013-09-26 17:47:05 +02002771static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
2772{
Michal Kazior24c88f72014-07-25 13:32:17 +02002773 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2774 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2775 ath10k_wmi_10_2_process_rx(ar, skb);
2776 else
2777 ath10k_wmi_10x_process_rx(ar, skb);
2778 } else {
Bartosz Markowskice428702013-09-26 17:47:05 +02002779 ath10k_wmi_main_process_rx(ar, skb);
Michal Kazior24c88f72014-07-25 13:32:17 +02002780 }
Bartosz Markowskice428702013-09-26 17:47:05 +02002781}
2782
Michal Kazior95bf21f2014-05-16 17:15:39 +03002783int ath10k_wmi_connect(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002784{
2785 int status;
2786 struct ath10k_htc_svc_conn_req conn_req;
2787 struct ath10k_htc_svc_conn_resp conn_resp;
2788
2789 memset(&conn_req, 0, sizeof(conn_req));
2790 memset(&conn_resp, 0, sizeof(conn_resp));
2791
2792 /* these fields are the same for all service endpoints */
2793 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
2794 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002795 conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002796
2797 /* connect to control service */
2798 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
2799
Michal Kaziorcd003fa2013-07-05 16:15:13 +03002800 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801 if (status) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002802 ath10k_warn(ar, "failed to connect to WMI CONTROL service status: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002803 status);
2804 return status;
2805 }
2806
2807 ar->wmi.eid = conn_resp.eid;
2808 return 0;
2809}
2810
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002811static int ath10k_wmi_main_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2812 u16 rd2g, u16 rd5g, u16 ctl2g,
2813 u16 ctl5g)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002814{
2815 struct wmi_pdev_set_regdomain_cmd *cmd;
2816 struct sk_buff *skb;
2817
Michal Kazior7aa7a722014-08-25 12:09:38 +02002818 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002819 if (!skb)
2820 return -ENOMEM;
2821
2822 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
2823 cmd->reg_domain = __cpu_to_le32(rd);
2824 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2825 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2826 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2827 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2828
Michal Kazior7aa7a722014-08-25 12:09:38 +02002829 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002830 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
2831 rd, rd2g, rd5g, ctl2g, ctl5g);
2832
Bartosz Markowskice428702013-09-26 17:47:05 +02002833 return ath10k_wmi_cmd_send(ar, skb,
2834 ar->wmi.cmd->pdev_set_regdomain_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002835}
2836
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002837static int ath10k_wmi_10x_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2838 u16 rd2g, u16 rd5g,
2839 u16 ctl2g, u16 ctl5g,
2840 enum wmi_dfs_region dfs_reg)
2841{
2842 struct wmi_pdev_set_regdomain_cmd_10x *cmd;
2843 struct sk_buff *skb;
2844
Michal Kazior7aa7a722014-08-25 12:09:38 +02002845 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002846 if (!skb)
2847 return -ENOMEM;
2848
2849 cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
2850 cmd->reg_domain = __cpu_to_le32(rd);
2851 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2852 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2853 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2854 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2855 cmd->dfs_domain = __cpu_to_le32(dfs_reg);
2856
Michal Kazior7aa7a722014-08-25 12:09:38 +02002857 ath10k_dbg(ar, ATH10K_DBG_WMI,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002858 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
2859 rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
2860
2861 return ath10k_wmi_cmd_send(ar, skb,
2862 ar->wmi.cmd->pdev_set_regdomain_cmdid);
2863}
2864
2865int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
2866 u16 rd5g, u16 ctl2g, u16 ctl5g,
2867 enum wmi_dfs_region dfs_reg)
2868{
2869 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2870 return ath10k_wmi_10x_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2871 ctl2g, ctl5g, dfs_reg);
2872 else
2873 return ath10k_wmi_main_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2874 ctl2g, ctl5g);
2875}
2876
Marek Puzyniak00f54822014-02-10 17:14:24 +01002877int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002878{
2879 struct wmi_pdev_suspend_cmd *cmd;
2880 struct sk_buff *skb;
2881
Michal Kazior7aa7a722014-08-25 12:09:38 +02002882 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002883 if (!skb)
2884 return -ENOMEM;
2885
2886 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
Marek Puzyniak00f54822014-02-10 17:14:24 +01002887 cmd->suspend_opt = __cpu_to_le32(suspend_opt);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002888
Bartosz Markowskice428702013-09-26 17:47:05 +02002889 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_suspend_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002890}
2891
2892int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
2893{
2894 struct sk_buff *skb;
2895
Michal Kazior7aa7a722014-08-25 12:09:38 +02002896 skb = ath10k_wmi_alloc_skb(ar, 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002897 if (skb == NULL)
2898 return -ENOMEM;
2899
Bartosz Markowskice428702013-09-26 17:47:05 +02002900 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_resume_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002901}
2902
Bartosz Markowski226a3392013-09-26 17:47:16 +02002903int ath10k_wmi_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904{
2905 struct wmi_pdev_set_param_cmd *cmd;
2906 struct sk_buff *skb;
2907
Bartosz Markowski226a3392013-09-26 17:47:16 +02002908 if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002909 ath10k_warn(ar, "pdev param %d not supported by firmware\n",
2910 id);
Bartosz Markowskid5449432013-10-15 09:55:32 +02002911 return -EOPNOTSUPP;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002912 }
2913
Michal Kazior7aa7a722014-08-25 12:09:38 +02002914 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002915 if (!skb)
2916 return -ENOMEM;
2917
2918 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
2919 cmd->param_id = __cpu_to_le32(id);
2920 cmd->param_value = __cpu_to_le32(value);
2921
Michal Kazior7aa7a722014-08-25 12:09:38 +02002922 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002923 id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02002924 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925}
2926
Michal Kaziorcf9fca82014-09-18 15:21:22 +02002927static void ath10k_wmi_put_host_mem_chunks(struct ath10k *ar,
2928 struct wmi_host_mem_chunks *chunks)
2929{
2930 struct host_memory_chunk *chunk;
2931 int i;
2932
2933 chunks->count = __cpu_to_le32(ar->wmi.num_mem_chunks);
2934
2935 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2936 chunk = &chunks->items[i];
2937 chunk->ptr = __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
2938 chunk->size = __cpu_to_le32(ar->wmi.mem_chunks[i].len);
2939 chunk->req_id = __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
2940
2941 ath10k_dbg(ar, ATH10K_DBG_WMI,
2942 "wmi chunk %d len %d requested, addr 0x%llx\n",
2943 i,
2944 ar->wmi.mem_chunks[i].len,
2945 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
2946 }
2947}
2948
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002949static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002950{
2951 struct wmi_init_cmd *cmd;
2952 struct sk_buff *buf;
2953 struct wmi_resource_config config = {};
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002954 u32 len, val;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002955
2956 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
2957 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
2958 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
2959
2960 config.num_offload_reorder_bufs =
2961 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
2962
2963 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
2964 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
2965 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
2966 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
2967 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
2968 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2969 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2970 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2971 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
2972 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
2973
2974 config.scan_max_pending_reqs =
2975 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
2976
2977 config.bmiss_offload_max_vdev =
2978 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
2979
2980 config.roam_offload_max_vdev =
2981 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
2982
2983 config.roam_offload_max_ap_profiles =
2984 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
2985
2986 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
2987 config.num_mcast_table_elems =
2988 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
2989
2990 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
2991 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
2992 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
2993 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
2994 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
2995
2996 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
2997 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
2998
2999 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
3000
3001 config.gtk_offload_max_vdev =
3002 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
3003
3004 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
3005 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
3006
Bartosz Markowskib3effe62013-09-26 17:47:11 +02003007 len = sizeof(*cmd) +
3008 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3009
Michal Kazior7aa7a722014-08-25 12:09:38 +02003010 buf = ath10k_wmi_alloc_skb(ar, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003011 if (!buf)
3012 return -ENOMEM;
3013
3014 cmd = (struct wmi_init_cmd *)buf->data;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02003015
Kalle Valo5e3dd152013-06-12 20:52:10 +03003016 memcpy(&cmd->resource_config, &config, sizeof(config));
Michal Kaziorcf9fca82014-09-18 15:21:22 +02003017 ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003018
Michal Kazior7aa7a722014-08-25 12:09:38 +02003019 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003020 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003021}
3022
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003023static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
3024{
3025 struct wmi_init_cmd_10x *cmd;
3026 struct sk_buff *buf;
3027 struct wmi_resource_config_10x config = {};
3028 u32 len, val;
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003029
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003030 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3031 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
3032 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
3033 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
3034 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
3035 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3036 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3037 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3038 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3039 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3040 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3041 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003042
3043 config.scan_max_pending_reqs =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003044 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003045
3046 config.bmiss_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003047 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003048
3049 config.roam_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003050 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003051
3052 config.roam_offload_max_ap_profiles =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003053 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003054
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003055 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003056 config.num_mcast_table_elems =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003057 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003058
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003059 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3060 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3061 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3062 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3063 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003064
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003065 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003066 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3067
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003068 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003069
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003070 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3071 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003072
3073 len = sizeof(*cmd) +
3074 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3075
Michal Kazior7aa7a722014-08-25 12:09:38 +02003076 buf = ath10k_wmi_alloc_skb(ar, len);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003077 if (!buf)
3078 return -ENOMEM;
3079
3080 cmd = (struct wmi_init_cmd_10x *)buf->data;
3081
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003082 memcpy(&cmd->resource_config, &config, sizeof(config));
Michal Kaziorcf9fca82014-09-18 15:21:22 +02003083 ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003084
Michal Kazior7aa7a722014-08-25 12:09:38 +02003085 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10x\n");
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003086 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3087}
3088
Michal Kazior24c88f72014-07-25 13:32:17 +02003089static int ath10k_wmi_10_2_cmd_init(struct ath10k *ar)
3090{
3091 struct wmi_init_cmd_10_2 *cmd;
3092 struct sk_buff *buf;
3093 struct wmi_resource_config_10x config = {};
3094 u32 len, val;
Michal Kazior24c88f72014-07-25 13:32:17 +02003095
3096 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3097 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
3098 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
3099 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
3100 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
3101 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3102 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3103 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3104 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3105 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3106 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3107 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
3108
3109 config.scan_max_pending_reqs =
3110 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
3111
3112 config.bmiss_offload_max_vdev =
3113 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
3114
3115 config.roam_offload_max_vdev =
3116 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
3117
3118 config.roam_offload_max_ap_profiles =
3119 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
3120
3121 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
3122 config.num_mcast_table_elems =
3123 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
3124
3125 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3126 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3127 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3128 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3129 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
3130
3131 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
3132 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3133
3134 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
3135
3136 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3137 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
3138
3139 len = sizeof(*cmd) +
3140 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3141
Michal Kazior7aa7a722014-08-25 12:09:38 +02003142 buf = ath10k_wmi_alloc_skb(ar, len);
Michal Kazior24c88f72014-07-25 13:32:17 +02003143 if (!buf)
3144 return -ENOMEM;
3145
3146 cmd = (struct wmi_init_cmd_10_2 *)buf->data;
3147
Michal Kazior24c88f72014-07-25 13:32:17 +02003148 memcpy(&cmd->resource_config.common, &config, sizeof(config));
Michal Kaziorcf9fca82014-09-18 15:21:22 +02003149 ath10k_wmi_put_host_mem_chunks(ar, &cmd->mem_chunks);
Michal Kazior24c88f72014-07-25 13:32:17 +02003150
Michal Kazior7aa7a722014-08-25 12:09:38 +02003151 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi init 10.2\n");
Michal Kazior24c88f72014-07-25 13:32:17 +02003152 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3153}
3154
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003155int ath10k_wmi_cmd_init(struct ath10k *ar)
3156{
3157 int ret;
3158
Michal Kazior24c88f72014-07-25 13:32:17 +02003159 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3160 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3161 ret = ath10k_wmi_10_2_cmd_init(ar);
3162 else
3163 ret = ath10k_wmi_10x_cmd_init(ar);
3164 } else {
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003165 ret = ath10k_wmi_main_cmd_init(ar);
Michal Kazior24c88f72014-07-25 13:32:17 +02003166 }
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003167
3168 return ret;
3169}
3170
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003171static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar,
3172 const struct wmi_start_scan_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003173{
3174 int len;
3175
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003176 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3177 len = sizeof(struct wmi_start_scan_cmd_10x);
3178 else
3179 len = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003180
3181 if (arg->ie_len) {
3182 if (!arg->ie)
3183 return -EINVAL;
3184 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
3185 return -EINVAL;
3186
3187 len += sizeof(struct wmi_ie_data);
3188 len += roundup(arg->ie_len, 4);
3189 }
3190
3191 if (arg->n_channels) {
3192 if (!arg->channels)
3193 return -EINVAL;
3194 if (arg->n_channels > ARRAY_SIZE(arg->channels))
3195 return -EINVAL;
3196
3197 len += sizeof(struct wmi_chan_list);
3198 len += sizeof(__le32) * arg->n_channels;
3199 }
3200
3201 if (arg->n_ssids) {
3202 if (!arg->ssids)
3203 return -EINVAL;
3204 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
3205 return -EINVAL;
3206
3207 len += sizeof(struct wmi_ssid_list);
3208 len += sizeof(struct wmi_ssid) * arg->n_ssids;
3209 }
3210
3211 if (arg->n_bssids) {
3212 if (!arg->bssids)
3213 return -EINVAL;
3214 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
3215 return -EINVAL;
3216
3217 len += sizeof(struct wmi_bssid_list);
3218 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3219 }
3220
3221 return len;
3222}
3223
3224int ath10k_wmi_start_scan(struct ath10k *ar,
3225 const struct wmi_start_scan_arg *arg)
3226{
3227 struct wmi_start_scan_cmd *cmd;
3228 struct sk_buff *skb;
3229 struct wmi_ie_data *ie;
3230 struct wmi_chan_list *channels;
3231 struct wmi_ssid_list *ssids;
3232 struct wmi_bssid_list *bssids;
3233 u32 scan_id;
3234 u32 scan_req_id;
3235 int off;
3236 int len = 0;
3237 int i;
3238
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003239 len = ath10k_wmi_start_scan_calc_len(ar, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240 if (len < 0)
3241 return len; /* len contains error code here */
3242
Michal Kazior7aa7a722014-08-25 12:09:38 +02003243 skb = ath10k_wmi_alloc_skb(ar, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003244 if (!skb)
3245 return -ENOMEM;
3246
3247 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
3248 scan_id |= arg->scan_id;
3249
3250 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3251 scan_req_id |= arg->scan_req_id;
3252
3253 cmd = (struct wmi_start_scan_cmd *)skb->data;
3254 cmd->scan_id = __cpu_to_le32(scan_id);
3255 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
3256 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3257 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
3258 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
3259 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
3260 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
3261 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
3262 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
3263 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
3264 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
3265 cmd->idle_time = __cpu_to_le32(arg->idle_time);
3266 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
3267 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
3268 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
3269
3270 /* TLV list starts after fields included in the struct */
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003271 /* There's just one filed that differes the two start_scan
3272 * structures - burst_duration, which we are not using btw,
3273 no point to make the split here, just shift the buffer to fit with
3274 given FW */
3275 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3276 off = sizeof(struct wmi_start_scan_cmd_10x);
3277 else
3278 off = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003279
3280 if (arg->n_channels) {
3281 channels = (void *)skb->data + off;
3282 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
3283 channels->num_chan = __cpu_to_le32(arg->n_channels);
3284
3285 for (i = 0; i < arg->n_channels; i++)
Michal Kazior24c88f72014-07-25 13:32:17 +02003286 channels->channel_list[i].freq =
3287 __cpu_to_le16(arg->channels[i]);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003288
3289 off += sizeof(*channels);
3290 off += sizeof(__le32) * arg->n_channels;
3291 }
3292
3293 if (arg->n_ssids) {
3294 ssids = (void *)skb->data + off;
3295 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
3296 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
3297
3298 for (i = 0; i < arg->n_ssids; i++) {
3299 ssids->ssids[i].ssid_len =
3300 __cpu_to_le32(arg->ssids[i].len);
3301 memcpy(&ssids->ssids[i].ssid,
3302 arg->ssids[i].ssid,
3303 arg->ssids[i].len);
3304 }
3305
3306 off += sizeof(*ssids);
3307 off += sizeof(struct wmi_ssid) * arg->n_ssids;
3308 }
3309
3310 if (arg->n_bssids) {
3311 bssids = (void *)skb->data + off;
3312 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
3313 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
3314
3315 for (i = 0; i < arg->n_bssids; i++)
3316 memcpy(&bssids->bssid_list[i],
3317 arg->bssids[i].bssid,
3318 ETH_ALEN);
3319
3320 off += sizeof(*bssids);
3321 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3322 }
3323
3324 if (arg->ie_len) {
3325 ie = (void *)skb->data + off;
3326 ie->tag = __cpu_to_le32(WMI_IE_TAG);
3327 ie->ie_len = __cpu_to_le32(arg->ie_len);
3328 memcpy(ie->ie_data, arg->ie, arg->ie_len);
3329
3330 off += sizeof(*ie);
3331 off += roundup(arg->ie_len, 4);
3332 }
3333
3334 if (off != skb->len) {
3335 dev_kfree_skb(skb);
3336 return -EINVAL;
3337 }
3338
Michal Kazior7aa7a722014-08-25 12:09:38 +02003339 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi start scan\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003340 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->start_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003341}
3342
3343void ath10k_wmi_start_scan_init(struct ath10k *ar,
3344 struct wmi_start_scan_arg *arg)
3345{
3346 /* setup commonly used values */
3347 arg->scan_req_id = 1;
3348 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
3349 arg->dwell_time_active = 50;
3350 arg->dwell_time_passive = 150;
3351 arg->min_rest_time = 50;
3352 arg->max_rest_time = 500;
3353 arg->repeat_probe_time = 0;
3354 arg->probe_spacing_time = 0;
3355 arg->idle_time = 0;
Bartosz Markowskic3228922013-10-02 08:48:52 +02003356 arg->max_scan_time = 20000;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003357 arg->probe_delay = 5;
3358 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
3359 | WMI_SCAN_EVENT_COMPLETED
3360 | WMI_SCAN_EVENT_BSS_CHANNEL
3361 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
3362 | WMI_SCAN_EVENT_DEQUEUED;
3363 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
3364 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
3365 arg->n_bssids = 1;
3366 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
3367}
3368
3369int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
3370{
3371 struct wmi_stop_scan_cmd *cmd;
3372 struct sk_buff *skb;
3373 u32 scan_id;
3374 u32 req_id;
3375
3376 if (arg->req_id > 0xFFF)
3377 return -EINVAL;
3378 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
3379 return -EINVAL;
3380
Michal Kazior7aa7a722014-08-25 12:09:38 +02003381 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003382 if (!skb)
3383 return -ENOMEM;
3384
3385 scan_id = arg->u.scan_id;
3386 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
3387
3388 req_id = arg->req_id;
3389 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3390
3391 cmd = (struct wmi_stop_scan_cmd *)skb->data;
3392 cmd->req_type = __cpu_to_le32(arg->req_type);
3393 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
3394 cmd->scan_id = __cpu_to_le32(scan_id);
3395 cmd->scan_req_id = __cpu_to_le32(req_id);
3396
Michal Kazior7aa7a722014-08-25 12:09:38 +02003397 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
3399 arg->req_id, arg->req_type, arg->u.scan_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02003400 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->stop_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003401}
3402
3403int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
3404 enum wmi_vdev_type type,
3405 enum wmi_vdev_subtype subtype,
3406 const u8 macaddr[ETH_ALEN])
3407{
3408 struct wmi_vdev_create_cmd *cmd;
3409 struct sk_buff *skb;
3410
Michal Kazior7aa7a722014-08-25 12:09:38 +02003411 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003412 if (!skb)
3413 return -ENOMEM;
3414
3415 cmd = (struct wmi_vdev_create_cmd *)skb->data;
3416 cmd->vdev_id = __cpu_to_le32(vdev_id);
3417 cmd->vdev_type = __cpu_to_le32(type);
3418 cmd->vdev_subtype = __cpu_to_le32(subtype);
Kalle Valob25f32c2014-09-14 12:50:49 +03003419 ether_addr_copy(cmd->vdev_macaddr.addr, macaddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003420
Michal Kazior7aa7a722014-08-25 12:09:38 +02003421 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003422 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
3423 vdev_id, type, subtype, macaddr);
3424
Bartosz Markowskice428702013-09-26 17:47:05 +02003425 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003426}
3427
3428int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
3429{
3430 struct wmi_vdev_delete_cmd *cmd;
3431 struct sk_buff *skb;
3432
Michal Kazior7aa7a722014-08-25 12:09:38 +02003433 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003434 if (!skb)
3435 return -ENOMEM;
3436
3437 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
3438 cmd->vdev_id = __cpu_to_le32(vdev_id);
3439
Michal Kazior7aa7a722014-08-25 12:09:38 +02003440 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003441 "WMI vdev delete id %d\n", vdev_id);
3442
Bartosz Markowskice428702013-09-26 17:47:05 +02003443 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003444}
3445
Kalle Valo5b07e072014-09-14 12:50:06 +03003446static int
3447ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3448 const struct wmi_vdev_start_request_arg *arg,
3449 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003450{
3451 struct wmi_vdev_start_request_cmd *cmd;
3452 struct sk_buff *skb;
3453 const char *cmdname;
3454 u32 flags = 0;
3455
Bartosz Markowskice428702013-09-26 17:47:05 +02003456 if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
3457 cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003458 return -EINVAL;
3459 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
3460 return -EINVAL;
3461 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
3462 return -EINVAL;
3463 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
3464 return -EINVAL;
3465
Bartosz Markowskice428702013-09-26 17:47:05 +02003466 if (cmd_id == ar->wmi.cmd->vdev_start_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003467 cmdname = "start";
Bartosz Markowskice428702013-09-26 17:47:05 +02003468 else if (cmd_id == ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003469 cmdname = "restart";
3470 else
3471 return -EINVAL; /* should not happen, we already check cmd_id */
3472
Michal Kazior7aa7a722014-08-25 12:09:38 +02003473 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003474 if (!skb)
3475 return -ENOMEM;
3476
3477 if (arg->hidden_ssid)
3478 flags |= WMI_VDEV_START_HIDDEN_SSID;
3479 if (arg->pmf_enabled)
3480 flags |= WMI_VDEV_START_PMF_ENABLED;
3481
3482 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
3483 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3484 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
3485 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
3486 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
3487 cmd->flags = __cpu_to_le32(flags);
3488 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
3489 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
3490
3491 if (arg->ssid) {
3492 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
3493 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
3494 }
3495
Michal Kazior2d667212014-09-18 15:21:21 +02003496 ath10k_wmi_put_wmi_channel(&cmd->chan, &arg->channel);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003497
Michal Kazior7aa7a722014-08-25 12:09:38 +02003498 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo8cc7f262014-09-14 12:50:39 +03003499 "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, ch_flags: 0x%0X, max_power: %d\n",
3500 cmdname, arg->vdev_id,
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003501 flags, arg->channel.freq, arg->channel.mode,
3502 cmd->chan.flags, arg->channel.max_power);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503
3504 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
3505}
3506
3507int ath10k_wmi_vdev_start(struct ath10k *ar,
3508 const struct wmi_vdev_start_request_arg *arg)
3509{
Bartosz Markowskice428702013-09-26 17:47:05 +02003510 u32 cmd_id = ar->wmi.cmd->vdev_start_request_cmdid;
3511
3512 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513}
3514
3515int ath10k_wmi_vdev_restart(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03003516 const struct wmi_vdev_start_request_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517{
Bartosz Markowskice428702013-09-26 17:47:05 +02003518 u32 cmd_id = ar->wmi.cmd->vdev_restart_request_cmdid;
3519
3520 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003521}
3522
3523int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
3524{
3525 struct wmi_vdev_stop_cmd *cmd;
3526 struct sk_buff *skb;
3527
Michal Kazior7aa7a722014-08-25 12:09:38 +02003528 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003529 if (!skb)
3530 return -ENOMEM;
3531
3532 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
3533 cmd->vdev_id = __cpu_to_le32(vdev_id);
3534
Michal Kazior7aa7a722014-08-25 12:09:38 +02003535 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003536
Bartosz Markowskice428702013-09-26 17:47:05 +02003537 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_stop_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538}
3539
3540int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
3541{
3542 struct wmi_vdev_up_cmd *cmd;
3543 struct sk_buff *skb;
3544
Michal Kazior7aa7a722014-08-25 12:09:38 +02003545 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003546 if (!skb)
3547 return -ENOMEM;
3548
3549 cmd = (struct wmi_vdev_up_cmd *)skb->data;
3550 cmd->vdev_id = __cpu_to_le32(vdev_id);
3551 cmd->vdev_assoc_id = __cpu_to_le32(aid);
Kalle Valob25f32c2014-09-14 12:50:49 +03003552 ether_addr_copy(cmd->vdev_bssid.addr, bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003553
Michal Kazior7aa7a722014-08-25 12:09:38 +02003554 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003555 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
3556 vdev_id, aid, bssid);
3557
Bartosz Markowskice428702013-09-26 17:47:05 +02003558 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_up_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003559}
3560
3561int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
3562{
3563 struct wmi_vdev_down_cmd *cmd;
3564 struct sk_buff *skb;
3565
Michal Kazior7aa7a722014-08-25 12:09:38 +02003566 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567 if (!skb)
3568 return -ENOMEM;
3569
3570 cmd = (struct wmi_vdev_down_cmd *)skb->data;
3571 cmd->vdev_id = __cpu_to_le32(vdev_id);
3572
Michal Kazior7aa7a722014-08-25 12:09:38 +02003573 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003574 "wmi mgmt vdev down id 0x%x\n", vdev_id);
3575
Bartosz Markowskice428702013-09-26 17:47:05 +02003576 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_down_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577}
3578
3579int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003580 u32 param_id, u32 param_value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003581{
3582 struct wmi_vdev_set_param_cmd *cmd;
3583 struct sk_buff *skb;
3584
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003585 if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003586 ath10k_dbg(ar, ATH10K_DBG_WMI,
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003587 "vdev param %d not supported by firmware\n",
3588 param_id);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003589 return -EOPNOTSUPP;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003590 }
3591
Michal Kazior7aa7a722014-08-25 12:09:38 +02003592 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003593 if (!skb)
3594 return -ENOMEM;
3595
3596 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
3597 cmd->vdev_id = __cpu_to_le32(vdev_id);
3598 cmd->param_id = __cpu_to_le32(param_id);
3599 cmd->param_value = __cpu_to_le32(param_value);
3600
Michal Kazior7aa7a722014-08-25 12:09:38 +02003601 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003602 "wmi vdev id 0x%x set param %d value %d\n",
3603 vdev_id, param_id, param_value);
3604
Bartosz Markowskice428702013-09-26 17:47:05 +02003605 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003606}
3607
3608int ath10k_wmi_vdev_install_key(struct ath10k *ar,
3609 const struct wmi_vdev_install_key_arg *arg)
3610{
3611 struct wmi_vdev_install_key_cmd *cmd;
3612 struct sk_buff *skb;
3613
3614 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
3615 return -EINVAL;
3616 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
3617 return -EINVAL;
3618
Michal Kazior7aa7a722014-08-25 12:09:38 +02003619 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + arg->key_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620 if (!skb)
3621 return -ENOMEM;
3622
3623 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
3624 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3625 cmd->key_idx = __cpu_to_le32(arg->key_idx);
3626 cmd->key_flags = __cpu_to_le32(arg->key_flags);
3627 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
3628 cmd->key_len = __cpu_to_le32(arg->key_len);
3629 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
3630 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
3631
3632 if (arg->macaddr)
Kalle Valob25f32c2014-09-14 12:50:49 +03003633 ether_addr_copy(cmd->peer_macaddr.addr, arg->macaddr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003634 if (arg->key_data)
3635 memcpy(cmd->key_data, arg->key_data, arg->key_len);
3636
Michal Kazior7aa7a722014-08-25 12:09:38 +02003637 ath10k_dbg(ar, ATH10K_DBG_WMI,
Michal Kaziore0c508a2013-07-05 16:15:17 +03003638 "wmi vdev install key idx %d cipher %d len %d\n",
3639 arg->key_idx, arg->key_cipher, arg->key_len);
Bartosz Markowskice428702013-09-26 17:47:05 +02003640 return ath10k_wmi_cmd_send(ar, skb,
3641 ar->wmi.cmd->vdev_install_key_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003642}
3643
Simon Wunderlich855aed12014-08-02 09:12:54 +03003644int ath10k_wmi_vdev_spectral_conf(struct ath10k *ar,
3645 const struct wmi_vdev_spectral_conf_arg *arg)
3646{
3647 struct wmi_vdev_spectral_conf_cmd *cmd;
3648 struct sk_buff *skb;
3649 u32 cmdid;
3650
Michal Kazior7aa7a722014-08-25 12:09:38 +02003651 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Simon Wunderlich855aed12014-08-02 09:12:54 +03003652 if (!skb)
3653 return -ENOMEM;
3654
3655 cmd = (struct wmi_vdev_spectral_conf_cmd *)skb->data;
3656 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3657 cmd->scan_count = __cpu_to_le32(arg->scan_count);
3658 cmd->scan_period = __cpu_to_le32(arg->scan_period);
3659 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
3660 cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
3661 cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
3662 cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
3663 cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
3664 cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
3665 cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
3666 cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
3667 cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
3668 cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
3669 cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
3670 cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
3671 cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
3672 cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
3673 cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
3674 cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
3675
3676 cmdid = ar->wmi.cmd->vdev_spectral_scan_configure_cmdid;
3677 return ath10k_wmi_cmd_send(ar, skb, cmdid);
3678}
3679
3680int ath10k_wmi_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id, u32 trigger,
3681 u32 enable)
3682{
3683 struct wmi_vdev_spectral_enable_cmd *cmd;
3684 struct sk_buff *skb;
3685 u32 cmdid;
3686
Michal Kazior7aa7a722014-08-25 12:09:38 +02003687 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Simon Wunderlich855aed12014-08-02 09:12:54 +03003688 if (!skb)
3689 return -ENOMEM;
3690
3691 cmd = (struct wmi_vdev_spectral_enable_cmd *)skb->data;
3692 cmd->vdev_id = __cpu_to_le32(vdev_id);
3693 cmd->trigger_cmd = __cpu_to_le32(trigger);
3694 cmd->enable_cmd = __cpu_to_le32(enable);
3695
3696 cmdid = ar->wmi.cmd->vdev_spectral_scan_enable_cmdid;
3697 return ath10k_wmi_cmd_send(ar, skb, cmdid);
3698}
3699
Kalle Valo5e3dd152013-06-12 20:52:10 +03003700int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
3701 const u8 peer_addr[ETH_ALEN])
3702{
3703 struct wmi_peer_create_cmd *cmd;
3704 struct sk_buff *skb;
3705
Michal Kazior7aa7a722014-08-25 12:09:38 +02003706 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003707 if (!skb)
3708 return -ENOMEM;
3709
3710 cmd = (struct wmi_peer_create_cmd *)skb->data;
3711 cmd->vdev_id = __cpu_to_le32(vdev_id);
Kalle Valob25f32c2014-09-14 12:50:49 +03003712 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003713
Michal Kazior7aa7a722014-08-25 12:09:38 +02003714 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003715 "wmi peer create vdev_id %d peer_addr %pM\n",
3716 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003717 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003718}
3719
3720int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
3721 const u8 peer_addr[ETH_ALEN])
3722{
3723 struct wmi_peer_delete_cmd *cmd;
3724 struct sk_buff *skb;
3725
Michal Kazior7aa7a722014-08-25 12:09:38 +02003726 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003727 if (!skb)
3728 return -ENOMEM;
3729
3730 cmd = (struct wmi_peer_delete_cmd *)skb->data;
3731 cmd->vdev_id = __cpu_to_le32(vdev_id);
Kalle Valob25f32c2014-09-14 12:50:49 +03003732 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003733
Michal Kazior7aa7a722014-08-25 12:09:38 +02003734 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003735 "wmi peer delete vdev_id %d peer_addr %pM\n",
3736 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003737 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003738}
3739
3740int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
3741 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
3742{
3743 struct wmi_peer_flush_tids_cmd *cmd;
3744 struct sk_buff *skb;
3745
Michal Kazior7aa7a722014-08-25 12:09:38 +02003746 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003747 if (!skb)
3748 return -ENOMEM;
3749
3750 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
3751 cmd->vdev_id = __cpu_to_le32(vdev_id);
3752 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
Kalle Valob25f32c2014-09-14 12:50:49 +03003753 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003754
Michal Kazior7aa7a722014-08-25 12:09:38 +02003755 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003756 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
3757 vdev_id, peer_addr, tid_bitmap);
Bartosz Markowskice428702013-09-26 17:47:05 +02003758 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_flush_tids_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003759}
3760
3761int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
3762 const u8 *peer_addr, enum wmi_peer_param param_id,
3763 u32 param_value)
3764{
3765 struct wmi_peer_set_param_cmd *cmd;
3766 struct sk_buff *skb;
3767
Michal Kazior7aa7a722014-08-25 12:09:38 +02003768 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003769 if (!skb)
3770 return -ENOMEM;
3771
3772 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
3773 cmd->vdev_id = __cpu_to_le32(vdev_id);
3774 cmd->param_id = __cpu_to_le32(param_id);
3775 cmd->param_value = __cpu_to_le32(param_value);
Kalle Valob25f32c2014-09-14 12:50:49 +03003776 ether_addr_copy(cmd->peer_macaddr.addr, peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003777
Michal Kazior7aa7a722014-08-25 12:09:38 +02003778 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003779 "wmi vdev %d peer 0x%pM set param %d value %d\n",
3780 vdev_id, peer_addr, param_id, param_value);
3781
Bartosz Markowskice428702013-09-26 17:47:05 +02003782 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003783}
3784
3785int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
3786 enum wmi_sta_ps_mode psmode)
3787{
3788 struct wmi_sta_powersave_mode_cmd *cmd;
3789 struct sk_buff *skb;
3790
Michal Kazior7aa7a722014-08-25 12:09:38 +02003791 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003792 if (!skb)
3793 return -ENOMEM;
3794
3795 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
3796 cmd->vdev_id = __cpu_to_le32(vdev_id);
3797 cmd->sta_ps_mode = __cpu_to_le32(psmode);
3798
Michal Kazior7aa7a722014-08-25 12:09:38 +02003799 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003800 "wmi set powersave id 0x%x mode %d\n",
3801 vdev_id, psmode);
3802
Bartosz Markowskice428702013-09-26 17:47:05 +02003803 return ath10k_wmi_cmd_send(ar, skb,
3804 ar->wmi.cmd->sta_powersave_mode_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805}
3806
3807int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
3808 enum wmi_sta_powersave_param param_id,
3809 u32 value)
3810{
3811 struct wmi_sta_powersave_param_cmd *cmd;
3812 struct sk_buff *skb;
3813
Michal Kazior7aa7a722014-08-25 12:09:38 +02003814 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815 if (!skb)
3816 return -ENOMEM;
3817
3818 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
3819 cmd->vdev_id = __cpu_to_le32(vdev_id);
3820 cmd->param_id = __cpu_to_le32(param_id);
3821 cmd->param_value = __cpu_to_le32(value);
3822
Michal Kazior7aa7a722014-08-25 12:09:38 +02003823 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003824 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
3825 vdev_id, param_id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02003826 return ath10k_wmi_cmd_send(ar, skb,
3827 ar->wmi.cmd->sta_powersave_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003828}
3829
3830int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
3831 enum wmi_ap_ps_peer_param param_id, u32 value)
3832{
3833 struct wmi_ap_ps_peer_cmd *cmd;
3834 struct sk_buff *skb;
3835
3836 if (!mac)
3837 return -EINVAL;
3838
Michal Kazior7aa7a722014-08-25 12:09:38 +02003839 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003840 if (!skb)
3841 return -ENOMEM;
3842
3843 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
3844 cmd->vdev_id = __cpu_to_le32(vdev_id);
3845 cmd->param_id = __cpu_to_le32(param_id);
3846 cmd->param_value = __cpu_to_le32(value);
Kalle Valob25f32c2014-09-14 12:50:49 +03003847 ether_addr_copy(cmd->peer_macaddr.addr, mac);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003848
Michal Kazior7aa7a722014-08-25 12:09:38 +02003849 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003850 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
3851 vdev_id, param_id, value, mac);
3852
Bartosz Markowskice428702013-09-26 17:47:05 +02003853 return ath10k_wmi_cmd_send(ar, skb,
3854 ar->wmi.cmd->ap_ps_peer_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003855}
3856
3857int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3858 const struct wmi_scan_chan_list_arg *arg)
3859{
3860 struct wmi_scan_chan_list_cmd *cmd;
3861 struct sk_buff *skb;
3862 struct wmi_channel_arg *ch;
3863 struct wmi_channel *ci;
3864 int len;
3865 int i;
3866
3867 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
3868
Michal Kazior7aa7a722014-08-25 12:09:38 +02003869 skb = ath10k_wmi_alloc_skb(ar, len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003870 if (!skb)
3871 return -EINVAL;
3872
3873 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
3874 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3875
3876 for (i = 0; i < arg->n_channels; i++) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003877 ch = &arg->channels[i];
3878 ci = &cmd->chan_info[i];
3879
Michal Kazior2d667212014-09-18 15:21:21 +02003880 ath10k_wmi_put_wmi_channel(ci, ch);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003881 }
3882
Bartosz Markowskice428702013-09-26 17:47:05 +02003883 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003884}
3885
Michal Kazior24c88f72014-07-25 13:32:17 +02003886static void
3887ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
3888 const struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003889{
Michal Kazior24c88f72014-07-25 13:32:17 +02003890 struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003891
Kalle Valo5e3dd152013-06-12 20:52:10 +03003892 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3893 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
3894 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
3895 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
3896 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
3897 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
3898 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
3899 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
3900 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
3901 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
3902 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
3903 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
3904 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
3905
Kalle Valob25f32c2014-09-14 12:50:49 +03003906 ether_addr_copy(cmd->peer_macaddr.addr, arg->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003907
3908 cmd->peer_legacy_rates.num_rates =
3909 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
3910 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
3911 arg->peer_legacy_rates.num_rates);
3912
3913 cmd->peer_ht_rates.num_rates =
3914 __cpu_to_le32(arg->peer_ht_rates.num_rates);
3915 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
3916 arg->peer_ht_rates.num_rates);
3917
3918 cmd->peer_vht_rates.rx_max_rate =
3919 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
3920 cmd->peer_vht_rates.rx_mcs_set =
3921 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
3922 cmd->peer_vht_rates.tx_max_rate =
3923 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
3924 cmd->peer_vht_rates.tx_mcs_set =
3925 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
Michal Kazior24c88f72014-07-25 13:32:17 +02003926}
3927
3928static void
3929ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
3930 const struct wmi_peer_assoc_complete_arg *arg)
3931{
3932 struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
3933
3934 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
3935 memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
3936}
3937
3938static void
3939ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
3940 const struct wmi_peer_assoc_complete_arg *arg)
3941{
3942 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
3943}
3944
3945static void
3946ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
3947 const struct wmi_peer_assoc_complete_arg *arg)
3948{
3949 struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
3950 int max_mcs, max_nss;
3951 u32 info0;
3952
3953 /* TODO: Is using max values okay with firmware? */
3954 max_mcs = 0xf;
3955 max_nss = 0xf;
3956
3957 info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
3958 SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
3959
3960 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
3961 cmd->info0 = __cpu_to_le32(info0);
3962}
3963
3964int ath10k_wmi_peer_assoc(struct ath10k *ar,
3965 const struct wmi_peer_assoc_complete_arg *arg)
3966{
3967 struct sk_buff *skb;
3968 int len;
3969
3970 if (arg->peer_mpdu_density > 16)
3971 return -EINVAL;
3972 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
3973 return -EINVAL;
3974 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
3975 return -EINVAL;
3976
3977 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3978 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3979 len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
3980 else
3981 len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
3982 } else {
3983 len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
3984 }
3985
Michal Kazior7aa7a722014-08-25 12:09:38 +02003986 skb = ath10k_wmi_alloc_skb(ar, len);
Michal Kazior24c88f72014-07-25 13:32:17 +02003987 if (!skb)
3988 return -ENOMEM;
3989
3990 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3991 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3992 ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
3993 else
3994 ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
3995 } else {
3996 ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
3997 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003998
Michal Kazior7aa7a722014-08-25 12:09:38 +02003999 ath10k_dbg(ar, ATH10K_DBG_WMI,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004000 "wmi peer assoc vdev %d addr %pM (%s)\n",
4001 arg->vdev_id, arg->addr,
4002 arg->peer_reassoc ? "reassociate" : "new");
Bartosz Markowskice428702013-09-26 17:47:05 +02004003 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_assoc_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004004}
4005
Michal Kazior748afc42014-01-23 12:48:21 +01004006/* This function assumes the beacon is already DMA mapped */
4007int ath10k_wmi_beacon_send_ref_nowait(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004008{
Michal Kazior748afc42014-01-23 12:48:21 +01004009 struct wmi_bcn_tx_ref_cmd *cmd;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010 struct sk_buff *skb;
Michal Kazior748afc42014-01-23 12:48:21 +01004011 struct sk_buff *beacon = arvif->beacon;
4012 struct ath10k *ar = arvif->ar;
4013 struct ieee80211_hdr *hdr;
Michal Kaziore2045482013-10-28 07:18:14 +01004014 int ret;
Michal Kazior748afc42014-01-23 12:48:21 +01004015 u16 fc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004016
Michal Kazior7aa7a722014-08-25 12:09:38 +02004017 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03004018 if (!skb)
4019 return -ENOMEM;
4020
Michal Kazior748afc42014-01-23 12:48:21 +01004021 hdr = (struct ieee80211_hdr *)beacon->data;
4022 fc = le16_to_cpu(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004023
Michal Kazior748afc42014-01-23 12:48:21 +01004024 cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
4025 cmd->vdev_id = __cpu_to_le32(arvif->vdev_id);
4026 cmd->data_len = __cpu_to_le32(beacon->len);
4027 cmd->data_ptr = __cpu_to_le32(ATH10K_SKB_CB(beacon)->paddr);
4028 cmd->msdu_id = 0;
4029 cmd->frame_control = __cpu_to_le32(fc);
4030 cmd->flags = 0;
Michal Kazior24c88f72014-07-25 13:32:17 +02004031 cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
Michal Kazior748afc42014-01-23 12:48:21 +01004032
4033 if (ATH10K_SKB_CB(beacon)->bcn.dtim_zero)
4034 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
4035
4036 if (ATH10K_SKB_CB(beacon)->bcn.deliver_cab)
4037 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
4038
4039 ret = ath10k_wmi_cmd_send_nowait(ar, skb,
4040 ar->wmi.cmd->pdev_send_bcn_cmdid);
4041
Michal Kaziore2045482013-10-28 07:18:14 +01004042 if (ret)
4043 dev_kfree_skb(skb);
4044
4045 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004046}
4047
4048static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
4049 const struct wmi_wmm_params_arg *arg)
4050{
4051 params->cwmin = __cpu_to_le32(arg->cwmin);
4052 params->cwmax = __cpu_to_le32(arg->cwmax);
4053 params->aifs = __cpu_to_le32(arg->aifs);
4054 params->txop = __cpu_to_le32(arg->txop);
4055 params->acm = __cpu_to_le32(arg->acm);
4056 params->no_ack = __cpu_to_le32(arg->no_ack);
4057}
4058
4059int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
Kalle Valo5b07e072014-09-14 12:50:06 +03004060 const struct wmi_pdev_set_wmm_params_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004061{
4062 struct wmi_pdev_set_wmm_params *cmd;
4063 struct sk_buff *skb;
4064
Michal Kazior7aa7a722014-08-25 12:09:38 +02004065 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03004066 if (!skb)
4067 return -ENOMEM;
4068
4069 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
4070 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
4071 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
4072 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
4073 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
4074
Michal Kazior7aa7a722014-08-25 12:09:38 +02004075 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02004076 return ath10k_wmi_cmd_send(ar, skb,
4077 ar->wmi.cmd->pdev_set_wmm_params_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004078}
4079
4080int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
4081{
4082 struct wmi_request_stats_cmd *cmd;
4083 struct sk_buff *skb;
4084
Michal Kazior7aa7a722014-08-25 12:09:38 +02004085 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03004086 if (!skb)
4087 return -ENOMEM;
4088
4089 cmd = (struct wmi_request_stats_cmd *)skb->data;
4090 cmd->stats_id = __cpu_to_le32(stats_id);
4091
Michal Kazior7aa7a722014-08-25 12:09:38 +02004092 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02004093 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->request_stats_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004094}
Michal Kazior9cfbce72013-07-16 09:54:36 +02004095
4096int ath10k_wmi_force_fw_hang(struct ath10k *ar,
4097 enum wmi_force_fw_hang_type type, u32 delay_ms)
4098{
4099 struct wmi_force_fw_hang_cmd *cmd;
4100 struct sk_buff *skb;
4101
Michal Kazior7aa7a722014-08-25 12:09:38 +02004102 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Michal Kazior9cfbce72013-07-16 09:54:36 +02004103 if (!skb)
4104 return -ENOMEM;
4105
4106 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
4107 cmd->type = __cpu_to_le32(type);
4108 cmd->delay_ms = __cpu_to_le32(delay_ms);
4109
Michal Kazior7aa7a722014-08-25 12:09:38 +02004110 ath10k_dbg(ar, ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
Michal Kazior9cfbce72013-07-16 09:54:36 +02004111 type, delay_ms);
Bartosz Markowskice428702013-09-26 17:47:05 +02004112 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
Michal Kazior9cfbce72013-07-16 09:54:36 +02004113}
Kalle Valof118a3e2014-01-03 12:59:31 +02004114
4115int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable)
4116{
4117 struct wmi_dbglog_cfg_cmd *cmd;
4118 struct sk_buff *skb;
4119 u32 cfg;
4120
Michal Kazior7aa7a722014-08-25 12:09:38 +02004121 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd));
Kalle Valof118a3e2014-01-03 12:59:31 +02004122 if (!skb)
4123 return -ENOMEM;
4124
4125 cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
4126
4127 if (module_enable) {
4128 cfg = SM(ATH10K_DBGLOG_LEVEL_VERBOSE,
4129 ATH10K_DBGLOG_CFG_LOG_LVL);
4130 } else {
4131 /* set back defaults, all modules with WARN level */
4132 cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
4133 ATH10K_DBGLOG_CFG_LOG_LVL);
4134 module_enable = ~0;
4135 }
4136
4137 cmd->module_enable = __cpu_to_le32(module_enable);
4138 cmd->module_valid = __cpu_to_le32(~0);
4139 cmd->config_enable = __cpu_to_le32(cfg);
4140 cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
4141
Michal Kazior7aa7a722014-08-25 12:09:38 +02004142 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valof118a3e2014-01-03 12:59:31 +02004143 "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
4144 __le32_to_cpu(cmd->module_enable),
4145 __le32_to_cpu(cmd->module_valid),
4146 __le32_to_cpu(cmd->config_enable),
4147 __le32_to_cpu(cmd->config_valid));
4148
4149 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid);
4150}
Michal Kaziorb79b9ba2014-09-18 15:21:23 +02004151
4152int ath10k_wmi_attach(struct ath10k *ar)
4153{
4154 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4155 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4156 ar->wmi.cmd = &wmi_10_2_cmd_map;
4157 else
4158 ar->wmi.cmd = &wmi_10x_cmd_map;
4159
4160 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
4161 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
4162 } else {
4163 ar->wmi.cmd = &wmi_cmd_map;
4164 ar->wmi.vdev_param = &wmi_vdev_param_map;
4165 ar->wmi.pdev_param = &wmi_pdev_param_map;
4166 }
4167
4168 init_completion(&ar->wmi.service_ready);
4169 init_completion(&ar->wmi.unified_ready);
4170 init_waitqueue_head(&ar->wmi.tx_credits_wq);
4171
4172 return 0;
4173}
4174
4175void ath10k_wmi_detach(struct ath10k *ar)
4176{
4177 int i;
4178
4179 /* free the host memory chunks requested by firmware */
4180 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
4181 dma_free_coherent(ar->dev,
4182 ar->wmi.mem_chunks[i].len,
4183 ar->wmi.mem_chunks[i].vaddr,
4184 ar->wmi.mem_chunks[i].paddr);
4185 }
4186
4187 ar->wmi.num_mem_chunks = 0;
4188}