blob: d4b48ef0ec2ede7d55ea918e30786067473ac09f [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"
26
Bartosz Markowskice428702013-09-26 17:47:05 +020027/* MAIN WMI cmd track */
28static struct wmi_cmd_map wmi_cmd_map = {
29 .init_cmdid = WMI_INIT_CMDID,
30 .start_scan_cmdid = WMI_START_SCAN_CMDID,
31 .stop_scan_cmdid = WMI_STOP_SCAN_CMDID,
32 .scan_chan_list_cmdid = WMI_SCAN_CHAN_LIST_CMDID,
33 .scan_sch_prio_tbl_cmdid = WMI_SCAN_SCH_PRIO_TBL_CMDID,
34 .pdev_set_regdomain_cmdid = WMI_PDEV_SET_REGDOMAIN_CMDID,
35 .pdev_set_channel_cmdid = WMI_PDEV_SET_CHANNEL_CMDID,
36 .pdev_set_param_cmdid = WMI_PDEV_SET_PARAM_CMDID,
37 .pdev_pktlog_enable_cmdid = WMI_PDEV_PKTLOG_ENABLE_CMDID,
38 .pdev_pktlog_disable_cmdid = WMI_PDEV_PKTLOG_DISABLE_CMDID,
39 .pdev_set_wmm_params_cmdid = WMI_PDEV_SET_WMM_PARAMS_CMDID,
40 .pdev_set_ht_cap_ie_cmdid = WMI_PDEV_SET_HT_CAP_IE_CMDID,
41 .pdev_set_vht_cap_ie_cmdid = WMI_PDEV_SET_VHT_CAP_IE_CMDID,
42 .pdev_set_dscp_tid_map_cmdid = WMI_PDEV_SET_DSCP_TID_MAP_CMDID,
43 .pdev_set_quiet_mode_cmdid = WMI_PDEV_SET_QUIET_MODE_CMDID,
44 .pdev_green_ap_ps_enable_cmdid = WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID,
45 .pdev_get_tpc_config_cmdid = WMI_PDEV_GET_TPC_CONFIG_CMDID,
46 .pdev_set_base_macaddr_cmdid = WMI_PDEV_SET_BASE_MACADDR_CMDID,
47 .vdev_create_cmdid = WMI_VDEV_CREATE_CMDID,
48 .vdev_delete_cmdid = WMI_VDEV_DELETE_CMDID,
49 .vdev_start_request_cmdid = WMI_VDEV_START_REQUEST_CMDID,
50 .vdev_restart_request_cmdid = WMI_VDEV_RESTART_REQUEST_CMDID,
51 .vdev_up_cmdid = WMI_VDEV_UP_CMDID,
52 .vdev_stop_cmdid = WMI_VDEV_STOP_CMDID,
53 .vdev_down_cmdid = WMI_VDEV_DOWN_CMDID,
54 .vdev_set_param_cmdid = WMI_VDEV_SET_PARAM_CMDID,
55 .vdev_install_key_cmdid = WMI_VDEV_INSTALL_KEY_CMDID,
56 .peer_create_cmdid = WMI_PEER_CREATE_CMDID,
57 .peer_delete_cmdid = WMI_PEER_DELETE_CMDID,
58 .peer_flush_tids_cmdid = WMI_PEER_FLUSH_TIDS_CMDID,
59 .peer_set_param_cmdid = WMI_PEER_SET_PARAM_CMDID,
60 .peer_assoc_cmdid = WMI_PEER_ASSOC_CMDID,
61 .peer_add_wds_entry_cmdid = WMI_PEER_ADD_WDS_ENTRY_CMDID,
62 .peer_remove_wds_entry_cmdid = WMI_PEER_REMOVE_WDS_ENTRY_CMDID,
63 .peer_mcast_group_cmdid = WMI_PEER_MCAST_GROUP_CMDID,
64 .bcn_tx_cmdid = WMI_BCN_TX_CMDID,
65 .pdev_send_bcn_cmdid = WMI_PDEV_SEND_BCN_CMDID,
66 .bcn_tmpl_cmdid = WMI_BCN_TMPL_CMDID,
67 .bcn_filter_rx_cmdid = WMI_BCN_FILTER_RX_CMDID,
68 .prb_req_filter_rx_cmdid = WMI_PRB_REQ_FILTER_RX_CMDID,
69 .mgmt_tx_cmdid = WMI_MGMT_TX_CMDID,
70 .prb_tmpl_cmdid = WMI_PRB_TMPL_CMDID,
71 .addba_clear_resp_cmdid = WMI_ADDBA_CLEAR_RESP_CMDID,
72 .addba_send_cmdid = WMI_ADDBA_SEND_CMDID,
73 .addba_status_cmdid = WMI_ADDBA_STATUS_CMDID,
74 .delba_send_cmdid = WMI_DELBA_SEND_CMDID,
75 .addba_set_resp_cmdid = WMI_ADDBA_SET_RESP_CMDID,
76 .send_singleamsdu_cmdid = WMI_SEND_SINGLEAMSDU_CMDID,
77 .sta_powersave_mode_cmdid = WMI_STA_POWERSAVE_MODE_CMDID,
78 .sta_powersave_param_cmdid = WMI_STA_POWERSAVE_PARAM_CMDID,
79 .sta_mimo_ps_mode_cmdid = WMI_STA_MIMO_PS_MODE_CMDID,
80 .pdev_dfs_enable_cmdid = WMI_PDEV_DFS_ENABLE_CMDID,
81 .pdev_dfs_disable_cmdid = WMI_PDEV_DFS_DISABLE_CMDID,
82 .roam_scan_mode = WMI_ROAM_SCAN_MODE,
83 .roam_scan_rssi_threshold = WMI_ROAM_SCAN_RSSI_THRESHOLD,
84 .roam_scan_period = WMI_ROAM_SCAN_PERIOD,
85 .roam_scan_rssi_change_threshold = WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
86 .roam_ap_profile = WMI_ROAM_AP_PROFILE,
87 .ofl_scan_add_ap_profile = WMI_ROAM_AP_PROFILE,
88 .ofl_scan_remove_ap_profile = WMI_OFL_SCAN_REMOVE_AP_PROFILE,
89 .ofl_scan_period = WMI_OFL_SCAN_PERIOD,
90 .p2p_dev_set_device_info = WMI_P2P_DEV_SET_DEVICE_INFO,
91 .p2p_dev_set_discoverability = WMI_P2P_DEV_SET_DISCOVERABILITY,
92 .p2p_go_set_beacon_ie = WMI_P2P_GO_SET_BEACON_IE,
93 .p2p_go_set_probe_resp_ie = WMI_P2P_GO_SET_PROBE_RESP_IE,
94 .p2p_set_vendor_ie_data_cmdid = WMI_P2P_SET_VENDOR_IE_DATA_CMDID,
95 .ap_ps_peer_param_cmdid = WMI_AP_PS_PEER_PARAM_CMDID,
96 .ap_ps_peer_uapsd_coex_cmdid = WMI_AP_PS_PEER_UAPSD_COEX_CMDID,
97 .peer_rate_retry_sched_cmdid = WMI_PEER_RATE_RETRY_SCHED_CMDID,
98 .wlan_profile_trigger_cmdid = WMI_WLAN_PROFILE_TRIGGER_CMDID,
99 .wlan_profile_set_hist_intvl_cmdid =
100 WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
101 .wlan_profile_get_profile_data_cmdid =
102 WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
103 .wlan_profile_enable_profile_id_cmdid =
104 WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
105 .wlan_profile_list_profile_id_cmdid =
106 WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
107 .pdev_suspend_cmdid = WMI_PDEV_SUSPEND_CMDID,
108 .pdev_resume_cmdid = WMI_PDEV_RESUME_CMDID,
109 .add_bcn_filter_cmdid = WMI_ADD_BCN_FILTER_CMDID,
110 .rmv_bcn_filter_cmdid = WMI_RMV_BCN_FILTER_CMDID,
111 .wow_add_wake_pattern_cmdid = WMI_WOW_ADD_WAKE_PATTERN_CMDID,
112 .wow_del_wake_pattern_cmdid = WMI_WOW_DEL_WAKE_PATTERN_CMDID,
113 .wow_enable_disable_wake_event_cmdid =
114 WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
115 .wow_enable_cmdid = WMI_WOW_ENABLE_CMDID,
116 .wow_hostwakeup_from_sleep_cmdid = WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
117 .rtt_measreq_cmdid = WMI_RTT_MEASREQ_CMDID,
118 .rtt_tsf_cmdid = WMI_RTT_TSF_CMDID,
119 .vdev_spectral_scan_configure_cmdid =
120 WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
121 .vdev_spectral_scan_enable_cmdid = WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
122 .request_stats_cmdid = WMI_REQUEST_STATS_CMDID,
123 .set_arp_ns_offload_cmdid = WMI_SET_ARP_NS_OFFLOAD_CMDID,
124 .network_list_offload_config_cmdid =
125 WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID,
126 .gtk_offload_cmdid = WMI_GTK_OFFLOAD_CMDID,
127 .csa_offload_enable_cmdid = WMI_CSA_OFFLOAD_ENABLE_CMDID,
128 .csa_offload_chanswitch_cmdid = WMI_CSA_OFFLOAD_CHANSWITCH_CMDID,
129 .chatter_set_mode_cmdid = WMI_CHATTER_SET_MODE_CMDID,
130 .peer_tid_addba_cmdid = WMI_PEER_TID_ADDBA_CMDID,
131 .peer_tid_delba_cmdid = WMI_PEER_TID_DELBA_CMDID,
132 .sta_dtim_ps_method_cmdid = WMI_STA_DTIM_PS_METHOD_CMDID,
133 .sta_uapsd_auto_trig_cmdid = WMI_STA_UAPSD_AUTO_TRIG_CMDID,
134 .sta_keepalive_cmd = WMI_STA_KEEPALIVE_CMD,
135 .echo_cmdid = WMI_ECHO_CMDID,
136 .pdev_utf_cmdid = WMI_PDEV_UTF_CMDID,
137 .dbglog_cfg_cmdid = WMI_DBGLOG_CFG_CMDID,
138 .pdev_qvit_cmdid = WMI_PDEV_QVIT_CMDID,
139 .pdev_ftm_intg_cmdid = WMI_PDEV_FTM_INTG_CMDID,
140 .vdev_set_keepalive_cmdid = WMI_VDEV_SET_KEEPALIVE_CMDID,
141 .vdev_get_keepalive_cmdid = WMI_VDEV_GET_KEEPALIVE_CMDID,
142 .force_fw_hang_cmdid = WMI_FORCE_FW_HANG_CMDID,
143 .gpio_config_cmdid = WMI_GPIO_CONFIG_CMDID,
144 .gpio_output_cmdid = WMI_GPIO_OUTPUT_CMDID,
145};
146
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200147/* 10.X WMI cmd track */
148static struct wmi_cmd_map wmi_10x_cmd_map = {
149 .init_cmdid = WMI_10X_INIT_CMDID,
150 .start_scan_cmdid = WMI_10X_START_SCAN_CMDID,
151 .stop_scan_cmdid = WMI_10X_STOP_SCAN_CMDID,
152 .scan_chan_list_cmdid = WMI_10X_SCAN_CHAN_LIST_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200153 .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200154 .pdev_set_regdomain_cmdid = WMI_10X_PDEV_SET_REGDOMAIN_CMDID,
155 .pdev_set_channel_cmdid = WMI_10X_PDEV_SET_CHANNEL_CMDID,
156 .pdev_set_param_cmdid = WMI_10X_PDEV_SET_PARAM_CMDID,
157 .pdev_pktlog_enable_cmdid = WMI_10X_PDEV_PKTLOG_ENABLE_CMDID,
158 .pdev_pktlog_disable_cmdid = WMI_10X_PDEV_PKTLOG_DISABLE_CMDID,
159 .pdev_set_wmm_params_cmdid = WMI_10X_PDEV_SET_WMM_PARAMS_CMDID,
160 .pdev_set_ht_cap_ie_cmdid = WMI_10X_PDEV_SET_HT_CAP_IE_CMDID,
161 .pdev_set_vht_cap_ie_cmdid = WMI_10X_PDEV_SET_VHT_CAP_IE_CMDID,
162 .pdev_set_dscp_tid_map_cmdid = WMI_10X_PDEV_SET_DSCP_TID_MAP_CMDID,
163 .pdev_set_quiet_mode_cmdid = WMI_10X_PDEV_SET_QUIET_MODE_CMDID,
164 .pdev_green_ap_ps_enable_cmdid = WMI_10X_PDEV_GREEN_AP_PS_ENABLE_CMDID,
165 .pdev_get_tpc_config_cmdid = WMI_10X_PDEV_GET_TPC_CONFIG_CMDID,
166 .pdev_set_base_macaddr_cmdid = WMI_10X_PDEV_SET_BASE_MACADDR_CMDID,
167 .vdev_create_cmdid = WMI_10X_VDEV_CREATE_CMDID,
168 .vdev_delete_cmdid = WMI_10X_VDEV_DELETE_CMDID,
169 .vdev_start_request_cmdid = WMI_10X_VDEV_START_REQUEST_CMDID,
170 .vdev_restart_request_cmdid = WMI_10X_VDEV_RESTART_REQUEST_CMDID,
171 .vdev_up_cmdid = WMI_10X_VDEV_UP_CMDID,
172 .vdev_stop_cmdid = WMI_10X_VDEV_STOP_CMDID,
173 .vdev_down_cmdid = WMI_10X_VDEV_DOWN_CMDID,
174 .vdev_set_param_cmdid = WMI_10X_VDEV_SET_PARAM_CMDID,
175 .vdev_install_key_cmdid = WMI_10X_VDEV_INSTALL_KEY_CMDID,
176 .peer_create_cmdid = WMI_10X_PEER_CREATE_CMDID,
177 .peer_delete_cmdid = WMI_10X_PEER_DELETE_CMDID,
178 .peer_flush_tids_cmdid = WMI_10X_PEER_FLUSH_TIDS_CMDID,
179 .peer_set_param_cmdid = WMI_10X_PEER_SET_PARAM_CMDID,
180 .peer_assoc_cmdid = WMI_10X_PEER_ASSOC_CMDID,
181 .peer_add_wds_entry_cmdid = WMI_10X_PEER_ADD_WDS_ENTRY_CMDID,
182 .peer_remove_wds_entry_cmdid = WMI_10X_PEER_REMOVE_WDS_ENTRY_CMDID,
183 .peer_mcast_group_cmdid = WMI_10X_PEER_MCAST_GROUP_CMDID,
184 .bcn_tx_cmdid = WMI_10X_BCN_TX_CMDID,
185 .pdev_send_bcn_cmdid = WMI_10X_PDEV_SEND_BCN_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200186 .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200187 .bcn_filter_rx_cmdid = WMI_10X_BCN_FILTER_RX_CMDID,
188 .prb_req_filter_rx_cmdid = WMI_10X_PRB_REQ_FILTER_RX_CMDID,
189 .mgmt_tx_cmdid = WMI_10X_MGMT_TX_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200190 .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200191 .addba_clear_resp_cmdid = WMI_10X_ADDBA_CLEAR_RESP_CMDID,
192 .addba_send_cmdid = WMI_10X_ADDBA_SEND_CMDID,
193 .addba_status_cmdid = WMI_10X_ADDBA_STATUS_CMDID,
194 .delba_send_cmdid = WMI_10X_DELBA_SEND_CMDID,
195 .addba_set_resp_cmdid = WMI_10X_ADDBA_SET_RESP_CMDID,
196 .send_singleamsdu_cmdid = WMI_10X_SEND_SINGLEAMSDU_CMDID,
197 .sta_powersave_mode_cmdid = WMI_10X_STA_POWERSAVE_MODE_CMDID,
198 .sta_powersave_param_cmdid = WMI_10X_STA_POWERSAVE_PARAM_CMDID,
199 .sta_mimo_ps_mode_cmdid = WMI_10X_STA_MIMO_PS_MODE_CMDID,
200 .pdev_dfs_enable_cmdid = WMI_10X_PDEV_DFS_ENABLE_CMDID,
201 .pdev_dfs_disable_cmdid = WMI_10X_PDEV_DFS_DISABLE_CMDID,
202 .roam_scan_mode = WMI_10X_ROAM_SCAN_MODE,
203 .roam_scan_rssi_threshold = WMI_10X_ROAM_SCAN_RSSI_THRESHOLD,
204 .roam_scan_period = WMI_10X_ROAM_SCAN_PERIOD,
205 .roam_scan_rssi_change_threshold =
206 WMI_10X_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
207 .roam_ap_profile = WMI_10X_ROAM_AP_PROFILE,
208 .ofl_scan_add_ap_profile = WMI_10X_OFL_SCAN_ADD_AP_PROFILE,
209 .ofl_scan_remove_ap_profile = WMI_10X_OFL_SCAN_REMOVE_AP_PROFILE,
210 .ofl_scan_period = WMI_10X_OFL_SCAN_PERIOD,
211 .p2p_dev_set_device_info = WMI_10X_P2P_DEV_SET_DEVICE_INFO,
212 .p2p_dev_set_discoverability = WMI_10X_P2P_DEV_SET_DISCOVERABILITY,
213 .p2p_go_set_beacon_ie = WMI_10X_P2P_GO_SET_BEACON_IE,
214 .p2p_go_set_probe_resp_ie = WMI_10X_P2P_GO_SET_PROBE_RESP_IE,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200215 .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
Janusz Dziedzic542fb172014-01-17 14:08:08 +0100216 .ap_ps_peer_param_cmdid = WMI_10X_AP_PS_PEER_PARAM_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200217 .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200218 .peer_rate_retry_sched_cmdid = WMI_10X_PEER_RATE_RETRY_SCHED_CMDID,
219 .wlan_profile_trigger_cmdid = WMI_10X_WLAN_PROFILE_TRIGGER_CMDID,
220 .wlan_profile_set_hist_intvl_cmdid =
221 WMI_10X_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
222 .wlan_profile_get_profile_data_cmdid =
223 WMI_10X_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
224 .wlan_profile_enable_profile_id_cmdid =
225 WMI_10X_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
226 .wlan_profile_list_profile_id_cmdid =
227 WMI_10X_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
228 .pdev_suspend_cmdid = WMI_10X_PDEV_SUSPEND_CMDID,
229 .pdev_resume_cmdid = WMI_10X_PDEV_RESUME_CMDID,
230 .add_bcn_filter_cmdid = WMI_10X_ADD_BCN_FILTER_CMDID,
231 .rmv_bcn_filter_cmdid = WMI_10X_RMV_BCN_FILTER_CMDID,
232 .wow_add_wake_pattern_cmdid = WMI_10X_WOW_ADD_WAKE_PATTERN_CMDID,
233 .wow_del_wake_pattern_cmdid = WMI_10X_WOW_DEL_WAKE_PATTERN_CMDID,
234 .wow_enable_disable_wake_event_cmdid =
235 WMI_10X_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
236 .wow_enable_cmdid = WMI_10X_WOW_ENABLE_CMDID,
237 .wow_hostwakeup_from_sleep_cmdid =
238 WMI_10X_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
239 .rtt_measreq_cmdid = WMI_10X_RTT_MEASREQ_CMDID,
240 .rtt_tsf_cmdid = WMI_10X_RTT_TSF_CMDID,
241 .vdev_spectral_scan_configure_cmdid =
242 WMI_10X_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
243 .vdev_spectral_scan_enable_cmdid =
244 WMI_10X_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
245 .request_stats_cmdid = WMI_10X_REQUEST_STATS_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200246 .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
247 .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
248 .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
249 .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
250 .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
251 .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
252 .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
253 .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
254 .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
255 .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
256 .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200257 .echo_cmdid = WMI_10X_ECHO_CMDID,
258 .pdev_utf_cmdid = WMI_10X_PDEV_UTF_CMDID,
259 .dbglog_cfg_cmdid = WMI_10X_DBGLOG_CFG_CMDID,
260 .pdev_qvit_cmdid = WMI_10X_PDEV_QVIT_CMDID,
Bartosz Markowski34957b22013-10-15 09:55:31 +0200261 .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
262 .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
263 .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
264 .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +0200265 .gpio_config_cmdid = WMI_10X_GPIO_CONFIG_CMDID,
266 .gpio_output_cmdid = WMI_10X_GPIO_OUTPUT_CMDID,
267};
Bartosz Markowskice428702013-09-26 17:47:05 +0200268
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200269/* MAIN WMI VDEV param map */
270static struct wmi_vdev_param_map wmi_vdev_param_map = {
271 .rts_threshold = WMI_VDEV_PARAM_RTS_THRESHOLD,
272 .fragmentation_threshold = WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
273 .beacon_interval = WMI_VDEV_PARAM_BEACON_INTERVAL,
274 .listen_interval = WMI_VDEV_PARAM_LISTEN_INTERVAL,
275 .multicast_rate = WMI_VDEV_PARAM_MULTICAST_RATE,
276 .mgmt_tx_rate = WMI_VDEV_PARAM_MGMT_TX_RATE,
277 .slot_time = WMI_VDEV_PARAM_SLOT_TIME,
278 .preamble = WMI_VDEV_PARAM_PREAMBLE,
279 .swba_time = WMI_VDEV_PARAM_SWBA_TIME,
280 .wmi_vdev_stats_update_period = WMI_VDEV_STATS_UPDATE_PERIOD,
281 .wmi_vdev_pwrsave_ageout_time = WMI_VDEV_PWRSAVE_AGEOUT_TIME,
282 .wmi_vdev_host_swba_interval = WMI_VDEV_HOST_SWBA_INTERVAL,
283 .dtim_period = WMI_VDEV_PARAM_DTIM_PERIOD,
284 .wmi_vdev_oc_scheduler_air_time_limit =
285 WMI_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
286 .wds = WMI_VDEV_PARAM_WDS,
287 .atim_window = WMI_VDEV_PARAM_ATIM_WINDOW,
288 .bmiss_count_max = WMI_VDEV_PARAM_BMISS_COUNT_MAX,
289 .bmiss_first_bcnt = WMI_VDEV_PARAM_BMISS_FIRST_BCNT,
290 .bmiss_final_bcnt = WMI_VDEV_PARAM_BMISS_FINAL_BCNT,
291 .feature_wmm = WMI_VDEV_PARAM_FEATURE_WMM,
292 .chwidth = WMI_VDEV_PARAM_CHWIDTH,
293 .chextoffset = WMI_VDEV_PARAM_CHEXTOFFSET,
294 .disable_htprotection = WMI_VDEV_PARAM_DISABLE_HTPROTECTION,
295 .sta_quickkickout = WMI_VDEV_PARAM_STA_QUICKKICKOUT,
296 .mgmt_rate = WMI_VDEV_PARAM_MGMT_RATE,
297 .protection_mode = WMI_VDEV_PARAM_PROTECTION_MODE,
298 .fixed_rate = WMI_VDEV_PARAM_FIXED_RATE,
299 .sgi = WMI_VDEV_PARAM_SGI,
300 .ldpc = WMI_VDEV_PARAM_LDPC,
301 .tx_stbc = WMI_VDEV_PARAM_TX_STBC,
302 .rx_stbc = WMI_VDEV_PARAM_RX_STBC,
303 .intra_bss_fwd = WMI_VDEV_PARAM_INTRA_BSS_FWD,
304 .def_keyid = WMI_VDEV_PARAM_DEF_KEYID,
305 .nss = WMI_VDEV_PARAM_NSS,
306 .bcast_data_rate = WMI_VDEV_PARAM_BCAST_DATA_RATE,
307 .mcast_data_rate = WMI_VDEV_PARAM_MCAST_DATA_RATE,
308 .mcast_indicate = WMI_VDEV_PARAM_MCAST_INDICATE,
309 .dhcp_indicate = WMI_VDEV_PARAM_DHCP_INDICATE,
310 .unknown_dest_indicate = WMI_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
311 .ap_keepalive_min_idle_inactive_time_secs =
312 WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
313 .ap_keepalive_max_idle_inactive_time_secs =
314 WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
315 .ap_keepalive_max_unresponsive_time_secs =
316 WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
317 .ap_enable_nawds = WMI_VDEV_PARAM_AP_ENABLE_NAWDS,
318 .mcast2ucast_set = WMI_VDEV_PARAM_UNSUPPORTED,
319 .enable_rtscts = WMI_VDEV_PARAM_ENABLE_RTSCTS,
320 .txbf = WMI_VDEV_PARAM_TXBF,
321 .packet_powersave = WMI_VDEV_PARAM_PACKET_POWERSAVE,
322 .drop_unencry = WMI_VDEV_PARAM_DROP_UNENCRY,
323 .tx_encap_type = WMI_VDEV_PARAM_TX_ENCAP_TYPE,
324 .ap_detect_out_of_sync_sleeping_sta_time_secs =
325 WMI_VDEV_PARAM_UNSUPPORTED,
326};
327
328/* 10.X WMI VDEV param map */
329static struct wmi_vdev_param_map wmi_10x_vdev_param_map = {
330 .rts_threshold = WMI_10X_VDEV_PARAM_RTS_THRESHOLD,
331 .fragmentation_threshold = WMI_10X_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
332 .beacon_interval = WMI_10X_VDEV_PARAM_BEACON_INTERVAL,
333 .listen_interval = WMI_10X_VDEV_PARAM_LISTEN_INTERVAL,
334 .multicast_rate = WMI_10X_VDEV_PARAM_MULTICAST_RATE,
335 .mgmt_tx_rate = WMI_10X_VDEV_PARAM_MGMT_TX_RATE,
336 .slot_time = WMI_10X_VDEV_PARAM_SLOT_TIME,
337 .preamble = WMI_10X_VDEV_PARAM_PREAMBLE,
338 .swba_time = WMI_10X_VDEV_PARAM_SWBA_TIME,
339 .wmi_vdev_stats_update_period = WMI_10X_VDEV_STATS_UPDATE_PERIOD,
340 .wmi_vdev_pwrsave_ageout_time = WMI_10X_VDEV_PWRSAVE_AGEOUT_TIME,
341 .wmi_vdev_host_swba_interval = WMI_10X_VDEV_HOST_SWBA_INTERVAL,
342 .dtim_period = WMI_10X_VDEV_PARAM_DTIM_PERIOD,
343 .wmi_vdev_oc_scheduler_air_time_limit =
344 WMI_10X_VDEV_OC_SCHEDULER_AIR_TIME_LIMIT,
345 .wds = WMI_10X_VDEV_PARAM_WDS,
346 .atim_window = WMI_10X_VDEV_PARAM_ATIM_WINDOW,
347 .bmiss_count_max = WMI_10X_VDEV_PARAM_BMISS_COUNT_MAX,
348 .bmiss_first_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
349 .bmiss_final_bcnt = WMI_VDEV_PARAM_UNSUPPORTED,
350 .feature_wmm = WMI_10X_VDEV_PARAM_FEATURE_WMM,
351 .chwidth = WMI_10X_VDEV_PARAM_CHWIDTH,
352 .chextoffset = WMI_10X_VDEV_PARAM_CHEXTOFFSET,
353 .disable_htprotection = WMI_10X_VDEV_PARAM_DISABLE_HTPROTECTION,
354 .sta_quickkickout = WMI_10X_VDEV_PARAM_STA_QUICKKICKOUT,
355 .mgmt_rate = WMI_10X_VDEV_PARAM_MGMT_RATE,
356 .protection_mode = WMI_10X_VDEV_PARAM_PROTECTION_MODE,
357 .fixed_rate = WMI_10X_VDEV_PARAM_FIXED_RATE,
358 .sgi = WMI_10X_VDEV_PARAM_SGI,
359 .ldpc = WMI_10X_VDEV_PARAM_LDPC,
360 .tx_stbc = WMI_10X_VDEV_PARAM_TX_STBC,
361 .rx_stbc = WMI_10X_VDEV_PARAM_RX_STBC,
362 .intra_bss_fwd = WMI_10X_VDEV_PARAM_INTRA_BSS_FWD,
363 .def_keyid = WMI_10X_VDEV_PARAM_DEF_KEYID,
364 .nss = WMI_10X_VDEV_PARAM_NSS,
365 .bcast_data_rate = WMI_10X_VDEV_PARAM_BCAST_DATA_RATE,
366 .mcast_data_rate = WMI_10X_VDEV_PARAM_MCAST_DATA_RATE,
367 .mcast_indicate = WMI_10X_VDEV_PARAM_MCAST_INDICATE,
368 .dhcp_indicate = WMI_10X_VDEV_PARAM_DHCP_INDICATE,
369 .unknown_dest_indicate = WMI_10X_VDEV_PARAM_UNKNOWN_DEST_INDICATE,
370 .ap_keepalive_min_idle_inactive_time_secs =
371 WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS,
372 .ap_keepalive_max_idle_inactive_time_secs =
373 WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS,
374 .ap_keepalive_max_unresponsive_time_secs =
375 WMI_10X_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS,
376 .ap_enable_nawds = WMI_10X_VDEV_PARAM_AP_ENABLE_NAWDS,
377 .mcast2ucast_set = WMI_10X_VDEV_PARAM_MCAST2UCAST_SET,
378 .enable_rtscts = WMI_10X_VDEV_PARAM_ENABLE_RTSCTS,
379 .txbf = WMI_VDEV_PARAM_UNSUPPORTED,
380 .packet_powersave = WMI_VDEV_PARAM_UNSUPPORTED,
381 .drop_unencry = WMI_VDEV_PARAM_UNSUPPORTED,
382 .tx_encap_type = WMI_VDEV_PARAM_UNSUPPORTED,
383 .ap_detect_out_of_sync_sleeping_sta_time_secs =
384 WMI_10X_VDEV_PARAM_AP_DETECT_OUT_OF_SYNC_SLEEPING_STA_TIME_SECS,
385};
386
Bartosz Markowski226a3392013-09-26 17:47:16 +0200387static struct wmi_pdev_param_map wmi_pdev_param_map = {
388 .tx_chain_mask = WMI_PDEV_PARAM_TX_CHAIN_MASK,
389 .rx_chain_mask = WMI_PDEV_PARAM_RX_CHAIN_MASK,
390 .txpower_limit2g = WMI_PDEV_PARAM_TXPOWER_LIMIT2G,
391 .txpower_limit5g = WMI_PDEV_PARAM_TXPOWER_LIMIT5G,
392 .txpower_scale = WMI_PDEV_PARAM_TXPOWER_SCALE,
393 .beacon_gen_mode = WMI_PDEV_PARAM_BEACON_GEN_MODE,
394 .beacon_tx_mode = WMI_PDEV_PARAM_BEACON_TX_MODE,
395 .resmgr_offchan_mode = WMI_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
396 .protection_mode = WMI_PDEV_PARAM_PROTECTION_MODE,
397 .dynamic_bw = WMI_PDEV_PARAM_DYNAMIC_BW,
398 .non_agg_sw_retry_th = WMI_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
399 .agg_sw_retry_th = WMI_PDEV_PARAM_AGG_SW_RETRY_TH,
400 .sta_kickout_th = WMI_PDEV_PARAM_STA_KICKOUT_TH,
401 .ac_aggrsize_scaling = WMI_PDEV_PARAM_AC_AGGRSIZE_SCALING,
402 .ltr_enable = WMI_PDEV_PARAM_LTR_ENABLE,
403 .ltr_ac_latency_be = WMI_PDEV_PARAM_LTR_AC_LATENCY_BE,
404 .ltr_ac_latency_bk = WMI_PDEV_PARAM_LTR_AC_LATENCY_BK,
405 .ltr_ac_latency_vi = WMI_PDEV_PARAM_LTR_AC_LATENCY_VI,
406 .ltr_ac_latency_vo = WMI_PDEV_PARAM_LTR_AC_LATENCY_VO,
407 .ltr_ac_latency_timeout = WMI_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
408 .ltr_sleep_override = WMI_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
409 .ltr_rx_override = WMI_PDEV_PARAM_LTR_RX_OVERRIDE,
410 .ltr_tx_activity_timeout = WMI_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
411 .l1ss_enable = WMI_PDEV_PARAM_L1SS_ENABLE,
412 .dsleep_enable = WMI_PDEV_PARAM_DSLEEP_ENABLE,
413 .pcielp_txbuf_flush = WMI_PDEV_PARAM_PCIELP_TXBUF_FLUSH,
414 .pcielp_txbuf_watermark = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
415 .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_EN,
416 .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_PCIELP_TXBUF_TMO_VALUE,
417 .pdev_stats_update_period = WMI_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
418 .vdev_stats_update_period = WMI_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
419 .peer_stats_update_period = WMI_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
420 .bcnflt_stats_update_period = WMI_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
421 .pmf_qos = WMI_PDEV_PARAM_PMF_QOS,
422 .arp_ac_override = WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Bartosz Markowski226a3392013-09-26 17:47:16 +0200423 .dcs = WMI_PDEV_PARAM_DCS,
424 .ani_enable = WMI_PDEV_PARAM_ANI_ENABLE,
425 .ani_poll_period = WMI_PDEV_PARAM_ANI_POLL_PERIOD,
426 .ani_listen_period = WMI_PDEV_PARAM_ANI_LISTEN_PERIOD,
427 .ani_ofdm_level = WMI_PDEV_PARAM_ANI_OFDM_LEVEL,
428 .ani_cck_level = WMI_PDEV_PARAM_ANI_CCK_LEVEL,
429 .dyntxchain = WMI_PDEV_PARAM_DYNTXCHAIN,
430 .proxy_sta = WMI_PDEV_PARAM_PROXY_STA,
431 .idle_ps_config = WMI_PDEV_PARAM_IDLE_PS_CONFIG,
432 .power_gating_sleep = WMI_PDEV_PARAM_POWER_GATING_SLEEP,
433 .fast_channel_reset = WMI_PDEV_PARAM_UNSUPPORTED,
434 .burst_dur = WMI_PDEV_PARAM_UNSUPPORTED,
435 .burst_enable = WMI_PDEV_PARAM_UNSUPPORTED,
436};
437
438static struct wmi_pdev_param_map wmi_10x_pdev_param_map = {
439 .tx_chain_mask = WMI_10X_PDEV_PARAM_TX_CHAIN_MASK,
440 .rx_chain_mask = WMI_10X_PDEV_PARAM_RX_CHAIN_MASK,
441 .txpower_limit2g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT2G,
442 .txpower_limit5g = WMI_10X_PDEV_PARAM_TXPOWER_LIMIT5G,
443 .txpower_scale = WMI_10X_PDEV_PARAM_TXPOWER_SCALE,
444 .beacon_gen_mode = WMI_10X_PDEV_PARAM_BEACON_GEN_MODE,
445 .beacon_tx_mode = WMI_10X_PDEV_PARAM_BEACON_TX_MODE,
446 .resmgr_offchan_mode = WMI_10X_PDEV_PARAM_RESMGR_OFFCHAN_MODE,
447 .protection_mode = WMI_10X_PDEV_PARAM_PROTECTION_MODE,
448 .dynamic_bw = WMI_10X_PDEV_PARAM_DYNAMIC_BW,
449 .non_agg_sw_retry_th = WMI_10X_PDEV_PARAM_NON_AGG_SW_RETRY_TH,
450 .agg_sw_retry_th = WMI_10X_PDEV_PARAM_AGG_SW_RETRY_TH,
451 .sta_kickout_th = WMI_10X_PDEV_PARAM_STA_KICKOUT_TH,
452 .ac_aggrsize_scaling = WMI_10X_PDEV_PARAM_AC_AGGRSIZE_SCALING,
453 .ltr_enable = WMI_10X_PDEV_PARAM_LTR_ENABLE,
454 .ltr_ac_latency_be = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BE,
455 .ltr_ac_latency_bk = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_BK,
456 .ltr_ac_latency_vi = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VI,
457 .ltr_ac_latency_vo = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_VO,
458 .ltr_ac_latency_timeout = WMI_10X_PDEV_PARAM_LTR_AC_LATENCY_TIMEOUT,
459 .ltr_sleep_override = WMI_10X_PDEV_PARAM_LTR_SLEEP_OVERRIDE,
460 .ltr_rx_override = WMI_10X_PDEV_PARAM_LTR_RX_OVERRIDE,
461 .ltr_tx_activity_timeout = WMI_10X_PDEV_PARAM_LTR_TX_ACTIVITY_TIMEOUT,
462 .l1ss_enable = WMI_10X_PDEV_PARAM_L1SS_ENABLE,
463 .dsleep_enable = WMI_10X_PDEV_PARAM_DSLEEP_ENABLE,
464 .pcielp_txbuf_flush = WMI_PDEV_PARAM_UNSUPPORTED,
465 .pcielp_txbuf_watermark = WMI_PDEV_PARAM_UNSUPPORTED,
466 .pcielp_txbuf_tmo_en = WMI_PDEV_PARAM_UNSUPPORTED,
467 .pcielp_txbuf_tmo_value = WMI_PDEV_PARAM_UNSUPPORTED,
468 .pdev_stats_update_period = WMI_10X_PDEV_PARAM_PDEV_STATS_UPDATE_PERIOD,
469 .vdev_stats_update_period = WMI_10X_PDEV_PARAM_VDEV_STATS_UPDATE_PERIOD,
470 .peer_stats_update_period = WMI_10X_PDEV_PARAM_PEER_STATS_UPDATE_PERIOD,
471 .bcnflt_stats_update_period =
472 WMI_10X_PDEV_PARAM_BCNFLT_STATS_UPDATE_PERIOD,
473 .pmf_qos = WMI_10X_PDEV_PARAM_PMF_QOS,
Marek Puzyniakab6258e2014-01-29 15:03:31 +0200474 .arp_ac_override = WMI_10X_PDEV_PARAM_ARPDHCP_AC_OVERRIDE,
Bartosz Markowski226a3392013-09-26 17:47:16 +0200475 .dcs = WMI_10X_PDEV_PARAM_DCS,
476 .ani_enable = WMI_10X_PDEV_PARAM_ANI_ENABLE,
477 .ani_poll_period = WMI_10X_PDEV_PARAM_ANI_POLL_PERIOD,
478 .ani_listen_period = WMI_10X_PDEV_PARAM_ANI_LISTEN_PERIOD,
479 .ani_ofdm_level = WMI_10X_PDEV_PARAM_ANI_OFDM_LEVEL,
480 .ani_cck_level = WMI_10X_PDEV_PARAM_ANI_CCK_LEVEL,
481 .dyntxchain = WMI_10X_PDEV_PARAM_DYNTXCHAIN,
482 .proxy_sta = WMI_PDEV_PARAM_UNSUPPORTED,
483 .idle_ps_config = WMI_PDEV_PARAM_UNSUPPORTED,
484 .power_gating_sleep = WMI_PDEV_PARAM_UNSUPPORTED,
485 .fast_channel_reset = WMI_10X_PDEV_PARAM_FAST_CHANNEL_RESET,
486 .burst_dur = WMI_10X_PDEV_PARAM_BURST_DUR,
487 .burst_enable = WMI_10X_PDEV_PARAM_BURST_ENABLE,
488};
489
Kalle Valo5e3dd152013-06-12 20:52:10 +0300490int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
491{
492 int ret;
493 ret = wait_for_completion_timeout(&ar->wmi.service_ready,
494 WMI_SERVICE_READY_TIMEOUT_HZ);
495 return ret;
496}
497
498int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
499{
500 int ret;
501 ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
502 WMI_UNIFIED_READY_TIMEOUT_HZ);
503 return ret;
504}
505
506static struct sk_buff *ath10k_wmi_alloc_skb(u32 len)
507{
508 struct sk_buff *skb;
509 u32 round_len = roundup(len, 4);
510
511 skb = ath10k_htc_alloc_skb(WMI_SKB_HEADROOM + round_len);
512 if (!skb)
513 return NULL;
514
515 skb_reserve(skb, WMI_SKB_HEADROOM);
516 if (!IS_ALIGNED((unsigned long)skb->data, 4))
517 ath10k_warn("Unaligned WMI skb\n");
518
519 skb_put(skb, round_len);
520 memset(skb->data, 0, round_len);
521
522 return skb;
523}
524
525static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
526{
527 dev_kfree_skb(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300528}
529
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200530static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
Bartosz Markowskice428702013-09-26 17:47:05 +0200531 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300532{
533 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
534 struct wmi_cmd_hdr *cmd_hdr;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200535 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300536 u32 cmd = 0;
537
538 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
539 return -ENOMEM;
540
541 cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
542
543 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
544 cmd_hdr->cmd_id = __cpu_to_le32(cmd);
545
Kalle Valo5e3dd152013-06-12 20:52:10 +0300546 memset(skb_cb, 0, sizeof(*skb_cb));
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200547 ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
548 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300549
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200550 if (ret)
551 goto err_pull;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300552
553 return 0;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200554
555err_pull:
556 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
557 return ret;
558}
559
Michal Kaziored543882013-09-13 14:16:56 +0200560static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
561{
Michal Kaziored543882013-09-13 14:16:56 +0200562 int ret;
563
564 lockdep_assert_held(&arvif->ar->data_lock);
565
566 if (arvif->beacon == NULL)
567 return;
568
Michal Kazior748afc42014-01-23 12:48:21 +0100569 if (arvif->beacon_sent)
570 return;
Michal Kaziored543882013-09-13 14:16:56 +0200571
Michal Kazior748afc42014-01-23 12:48:21 +0100572 ret = ath10k_wmi_beacon_send_ref_nowait(arvif);
Michal Kaziored543882013-09-13 14:16:56 +0200573 if (ret)
574 return;
575
Michal Kazior748afc42014-01-23 12:48:21 +0100576 /* We need to retain the arvif->beacon reference for DMA unmapping and
577 * freeing the skbuff later. */
578 arvif->beacon_sent = true;
Michal Kaziored543882013-09-13 14:16:56 +0200579}
580
581static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
582 struct ieee80211_vif *vif)
583{
584 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
585
586 ath10k_wmi_tx_beacon_nowait(arvif);
587}
588
589static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
590{
591 spin_lock_bh(&ar->data_lock);
592 ieee80211_iterate_active_interfaces_atomic(ar->hw,
593 IEEE80211_IFACE_ITER_NORMAL,
594 ath10k_wmi_tx_beacons_iter,
595 NULL);
596 spin_unlock_bh(&ar->data_lock);
597}
598
Michal Kazior12acbc42013-09-13 14:16:55 +0200599static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200600{
Michal Kaziored543882013-09-13 14:16:56 +0200601 /* try to send pending beacons first. they take priority */
602 ath10k_wmi_tx_beacons_nowait(ar);
603
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200604 wake_up(&ar->wmi.tx_credits_wq);
605}
606
607static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
Bartosz Markowskice428702013-09-26 17:47:05 +0200608 u32 cmd_id)
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200609{
Bartosz Markowski34957b22013-10-15 09:55:31 +0200610 int ret = -EOPNOTSUPP;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200611
Kalle Valo56b84282013-10-16 15:44:47 +0300612 might_sleep();
613
Bartosz Markowski34957b22013-10-15 09:55:31 +0200614 if (cmd_id == WMI_CMD_UNSUPPORTED) {
Bartosz Markowski55321552013-09-26 17:47:07 +0200615 ath10k_warn("wmi command %d is not supported by firmware\n",
616 cmd_id);
617 return ret;
618 }
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200619
620 wait_event_timeout(ar->wmi.tx_credits_wq, ({
Michal Kaziored543882013-09-13 14:16:56 +0200621 /* try to send pending beacons first. they take priority */
622 ath10k_wmi_tx_beacons_nowait(ar);
623
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200624 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
625 (ret != -EAGAIN);
626 }), 3*HZ);
627
628 if (ret)
629 dev_kfree_skb_any(skb);
630
631 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300632}
633
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200634int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
635{
636 int ret = 0;
637 struct wmi_mgmt_tx_cmd *cmd;
638 struct ieee80211_hdr *hdr;
639 struct sk_buff *wmi_skb;
640 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
641 int len;
642 u16 fc;
643
644 hdr = (struct ieee80211_hdr *)skb->data;
645 fc = le16_to_cpu(hdr->frame_control);
646
647 if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
648 return -EINVAL;
649
650 len = sizeof(cmd->hdr) + skb->len;
651 len = round_up(len, 4);
652
653 wmi_skb = ath10k_wmi_alloc_skb(len);
654 if (!wmi_skb)
655 return -ENOMEM;
656
657 cmd = (struct wmi_mgmt_tx_cmd *)wmi_skb->data;
658
659 cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id);
660 cmd->hdr.tx_rate = 0;
661 cmd->hdr.tx_power = 0;
662 cmd->hdr.buf_len = __cpu_to_le32((u32)(skb->len));
663
664 memcpy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr), ETH_ALEN);
665 memcpy(cmd->buf, skb->data, skb->len);
666
667 ath10k_dbg(ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n",
668 wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE,
669 fc & IEEE80211_FCTL_STYPE);
670
671 /* Send the management frame buffer to the target */
672 ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid);
Michal Kazior5fb5e412013-10-28 07:18:13 +0100673 if (ret)
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200674 return ret;
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200675
676 /* TODO: report tx status to mac80211 - temporary just ACK */
677 info->flags |= IEEE80211_TX_STAT_ACK;
678 ieee80211_tx_status_irqsafe(ar->hw, skb);
679
680 return ret;
681}
682
Kalle Valo5e3dd152013-06-12 20:52:10 +0300683static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
684{
685 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
686 enum wmi_scan_event_type event_type;
687 enum wmi_scan_completion_reason reason;
688 u32 freq;
689 u32 req_id;
690 u32 scan_id;
691 u32 vdev_id;
692
693 event_type = __le32_to_cpu(event->event_type);
694 reason = __le32_to_cpu(event->reason);
695 freq = __le32_to_cpu(event->channel_freq);
696 req_id = __le32_to_cpu(event->scan_req_id);
697 scan_id = __le32_to_cpu(event->scan_id);
698 vdev_id = __le32_to_cpu(event->vdev_id);
699
700 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENTID\n");
701 ath10k_dbg(ATH10K_DBG_WMI,
702 "scan event type %d reason %d freq %d req_id %d "
703 "scan_id %d vdev_id %d\n",
704 event_type, reason, freq, req_id, scan_id, vdev_id);
705
706 spin_lock_bh(&ar->data_lock);
707
708 switch (event_type) {
709 case WMI_SCAN_EVENT_STARTED:
710 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_STARTED\n");
711 if (ar->scan.in_progress && ar->scan.is_roc)
712 ieee80211_ready_on_channel(ar->hw);
713
714 complete(&ar->scan.started);
715 break;
716 case WMI_SCAN_EVENT_COMPLETED:
717 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_COMPLETED\n");
718 switch (reason) {
719 case WMI_SCAN_REASON_COMPLETED:
720 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_COMPLETED\n");
721 break;
722 case WMI_SCAN_REASON_CANCELLED:
723 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_CANCELED\n");
724 break;
725 case WMI_SCAN_REASON_PREEMPTED:
726 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_PREEMPTED\n");
727 break;
728 case WMI_SCAN_REASON_TIMEDOUT:
729 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_TIMEDOUT\n");
730 break;
731 default:
732 break;
733 }
734
735 ar->scan_channel = NULL;
736 if (!ar->scan.in_progress) {
737 ath10k_warn("no scan requested, ignoring\n");
738 break;
739 }
740
741 if (ar->scan.is_roc) {
742 ath10k_offchan_tx_purge(ar);
743
744 if (!ar->scan.aborting)
745 ieee80211_remain_on_channel_expired(ar->hw);
746 } else {
747 ieee80211_scan_completed(ar->hw, ar->scan.aborting);
748 }
749
750 del_timer(&ar->scan.timeout);
751 complete_all(&ar->scan.completed);
752 ar->scan.in_progress = false;
753 break;
754 case WMI_SCAN_EVENT_BSS_CHANNEL:
755 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_BSS_CHANNEL\n");
756 ar->scan_channel = NULL;
757 break;
758 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
759 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_FOREIGN_CHANNEL\n");
760 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
761 if (ar->scan.in_progress && ar->scan.is_roc &&
762 ar->scan.roc_freq == freq) {
763 complete(&ar->scan.on_channel);
764 }
765 break;
766 case WMI_SCAN_EVENT_DEQUEUED:
767 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_DEQUEUED\n");
768 break;
769 case WMI_SCAN_EVENT_PREEMPTED:
770 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_PREEMPTED\n");
771 break;
772 case WMI_SCAN_EVENT_START_FAILED:
773 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_START_FAILED\n");
774 break;
775 default:
776 break;
777 }
778
779 spin_unlock_bh(&ar->data_lock);
780 return 0;
781}
782
783static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
784{
785 enum ieee80211_band band;
786
787 switch (phy_mode) {
788 case MODE_11A:
789 case MODE_11NA_HT20:
790 case MODE_11NA_HT40:
791 case MODE_11AC_VHT20:
792 case MODE_11AC_VHT40:
793 case MODE_11AC_VHT80:
794 band = IEEE80211_BAND_5GHZ;
795 break;
796 case MODE_11G:
797 case MODE_11B:
798 case MODE_11GONLY:
799 case MODE_11NG_HT20:
800 case MODE_11NG_HT40:
801 case MODE_11AC_VHT20_2G:
802 case MODE_11AC_VHT40_2G:
803 case MODE_11AC_VHT80_2G:
804 default:
805 band = IEEE80211_BAND_2GHZ;
806 }
807
808 return band;
809}
810
811static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
812{
813 u8 rate_idx = 0;
814
815 /* rate in Kbps */
816 switch (rate) {
817 case 1000:
818 rate_idx = 0;
819 break;
820 case 2000:
821 rate_idx = 1;
822 break;
823 case 5500:
824 rate_idx = 2;
825 break;
826 case 11000:
827 rate_idx = 3;
828 break;
829 case 6000:
830 rate_idx = 4;
831 break;
832 case 9000:
833 rate_idx = 5;
834 break;
835 case 12000:
836 rate_idx = 6;
837 break;
838 case 18000:
839 rate_idx = 7;
840 break;
841 case 24000:
842 rate_idx = 8;
843 break;
844 case 36000:
845 rate_idx = 9;
846 break;
847 case 48000:
848 rate_idx = 10;
849 break;
850 case 54000:
851 rate_idx = 11;
852 break;
853 default:
854 break;
855 }
856
857 if (band == IEEE80211_BAND_5GHZ) {
858 if (rate_idx > 3)
859 /* Omit CCK rates */
860 rate_idx -= 4;
861 else
862 rate_idx = 0;
863 }
864
865 return rate_idx;
866}
867
868static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
869{
Michal Kazior0d9b0432013-08-09 10:13:33 +0200870 struct wmi_mgmt_rx_event_v1 *ev_v1;
871 struct wmi_mgmt_rx_event_v2 *ev_v2;
872 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300873 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Michal Kazior453cdb62013-12-13 10:44:43 +0100874 struct ieee80211_channel *ch;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300875 struct ieee80211_hdr *hdr;
876 u32 rx_status;
877 u32 channel;
878 u32 phy_mode;
879 u32 snr;
880 u32 rate;
881 u32 buf_len;
882 u16 fc;
Michal Kazior0d9b0432013-08-09 10:13:33 +0200883 int pull_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300884
Michal Kazior0d9b0432013-08-09 10:13:33 +0200885 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
886 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
887 ev_hdr = &ev_v2->hdr.v1;
888 pull_len = sizeof(*ev_v2);
889 } else {
890 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
891 ev_hdr = &ev_v1->hdr;
892 pull_len = sizeof(*ev_v1);
893 }
894
895 channel = __le32_to_cpu(ev_hdr->channel);
896 buf_len = __le32_to_cpu(ev_hdr->buf_len);
897 rx_status = __le32_to_cpu(ev_hdr->status);
898 snr = __le32_to_cpu(ev_hdr->snr);
899 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
900 rate = __le32_to_cpu(ev_hdr->rate);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300901
902 memset(status, 0, sizeof(*status));
903
904 ath10k_dbg(ATH10K_DBG_MGMT,
905 "event mgmt rx status %08x\n", rx_status);
906
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200907 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
908 dev_kfree_skb(skb);
909 return 0;
910 }
911
Kalle Valo5e3dd152013-06-12 20:52:10 +0300912 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
913 dev_kfree_skb(skb);
914 return 0;
915 }
916
917 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
918 dev_kfree_skb(skb);
919 return 0;
920 }
921
922 if (rx_status & WMI_RX_STATUS_ERR_CRC)
923 status->flag |= RX_FLAG_FAILED_FCS_CRC;
924 if (rx_status & WMI_RX_STATUS_ERR_MIC)
925 status->flag |= RX_FLAG_MMIC_ERROR;
926
Michal Kazior453cdb62013-12-13 10:44:43 +0100927 /* HW can Rx CCK rates on 5GHz. In that case phy_mode is set to
928 * MODE_11B. This means phy_mode is not a reliable source for the band
929 * of mgmt rx. */
930
931 ch = ar->scan_channel;
932 if (!ch)
933 ch = ar->rx_channel;
934
935 if (ch) {
936 status->band = ch->band;
937
938 if (phy_mode == MODE_11B &&
939 status->band == IEEE80211_BAND_5GHZ)
940 ath10k_dbg(ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
941 } else {
942 ath10k_warn("using (unreliable) phy_mode to extract band for mgmt rx\n");
943 status->band = phy_mode_to_band(phy_mode);
944 }
945
Kalle Valo5e3dd152013-06-12 20:52:10 +0300946 status->freq = ieee80211_channel_to_frequency(channel, status->band);
947 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
948 status->rate_idx = get_rate_idx(rate, status->band);
949
Michal Kazior0d9b0432013-08-09 10:13:33 +0200950 skb_pull(skb, pull_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300951
952 hdr = (struct ieee80211_hdr *)skb->data;
953 fc = le16_to_cpu(hdr->frame_control);
954
Michal Kazior2b6a6a92013-12-05 06:53:41 +0100955 /* FW delivers WEP Shared Auth frame with Protected Bit set and
956 * encrypted payload. However in case of PMF it delivers decrypted
957 * frames with Protected Bit set. */
958 if (ieee80211_has_protected(hdr->frame_control) &&
959 !ieee80211_is_auth(hdr->frame_control)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300960 status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED |
961 RX_FLAG_MMIC_STRIPPED;
962 hdr->frame_control = __cpu_to_le16(fc &
963 ~IEEE80211_FCTL_PROTECTED);
964 }
965
966 ath10k_dbg(ATH10K_DBG_MGMT,
967 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
968 skb, skb->len,
969 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
970
971 ath10k_dbg(ATH10K_DBG_MGMT,
972 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
973 status->freq, status->band, status->signal,
974 status->rate_idx);
975
976 /*
977 * packets from HTC come aligned to 4byte boundaries
978 * because they can originally come in along with a trailer
979 */
980 skb_trim(skb, buf_len);
981
982 ieee80211_rx(ar->hw, skb);
983 return 0;
984}
985
Michal Kazior2e1dea42013-07-31 10:32:40 +0200986static int freq_to_idx(struct ath10k *ar, int freq)
987{
988 struct ieee80211_supported_band *sband;
989 int band, ch, idx = 0;
990
991 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
992 sband = ar->hw->wiphy->bands[band];
993 if (!sband)
994 continue;
995
996 for (ch = 0; ch < sband->n_channels; ch++, idx++)
997 if (sband->channels[ch].center_freq == freq)
998 goto exit;
999 }
1000
1001exit:
1002 return idx;
1003}
1004
Kalle Valo5e3dd152013-06-12 20:52:10 +03001005static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
1006{
Michal Kazior2e1dea42013-07-31 10:32:40 +02001007 struct wmi_chan_info_event *ev;
1008 struct survey_info *survey;
1009 u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
1010 int idx;
1011
1012 ev = (struct wmi_chan_info_event *)skb->data;
1013
1014 err_code = __le32_to_cpu(ev->err_code);
1015 freq = __le32_to_cpu(ev->freq);
1016 cmd_flags = __le32_to_cpu(ev->cmd_flags);
1017 noise_floor = __le32_to_cpu(ev->noise_floor);
1018 rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
1019 cycle_count = __le32_to_cpu(ev->cycle_count);
1020
1021 ath10k_dbg(ATH10K_DBG_WMI,
1022 "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
1023 err_code, freq, cmd_flags, noise_floor, rx_clear_count,
1024 cycle_count);
1025
1026 spin_lock_bh(&ar->data_lock);
1027
1028 if (!ar->scan.in_progress) {
1029 ath10k_warn("chan info event without a scan request?\n");
1030 goto exit;
1031 }
1032
1033 idx = freq_to_idx(ar, freq);
1034 if (idx >= ARRAY_SIZE(ar->survey)) {
1035 ath10k_warn("chan info: invalid frequency %d (idx %d out of bounds)\n",
1036 freq, idx);
1037 goto exit;
1038 }
1039
1040 if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
1041 /* During scanning chan info is reported twice for each
1042 * visited channel. The reported cycle count is global
1043 * and per-channel cycle count must be calculated */
1044
1045 cycle_count -= ar->survey_last_cycle_count;
1046 rx_clear_count -= ar->survey_last_rx_clear_count;
1047
1048 survey = &ar->survey[idx];
1049 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
1050 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
1051 survey->noise = noise_floor;
1052 survey->filled = SURVEY_INFO_CHANNEL_TIME |
1053 SURVEY_INFO_CHANNEL_TIME_RX |
1054 SURVEY_INFO_NOISE_DBM;
1055 }
1056
1057 ar->survey_last_rx_clear_count = rx_clear_count;
1058 ar->survey_last_cycle_count = cycle_count;
1059
1060exit:
1061 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001062}
1063
1064static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
1065{
1066 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
1067}
1068
Kalle Valo869526b2014-01-03 12:59:26 +02001069static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001070{
Kalle Valo869526b2014-01-03 12:59:26 +02001071 ath10k_dbg(ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
1072 skb->len);
1073
1074 trace_ath10k_wmi_dbglog(skb->data, skb->len);
1075
1076 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001077}
1078
1079static void ath10k_wmi_event_update_stats(struct ath10k *ar,
1080 struct sk_buff *skb)
1081{
1082 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
1083
1084 ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
1085
1086 ath10k_debug_read_target_stats(ar, ev);
1087}
1088
1089static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
1090 struct sk_buff *skb)
1091{
1092 struct wmi_vdev_start_response_event *ev;
1093
1094 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
1095
1096 ev = (struct wmi_vdev_start_response_event *)skb->data;
1097
1098 if (WARN_ON(__le32_to_cpu(ev->status)))
1099 return;
1100
1101 complete(&ar->vdev_setup_done);
1102}
1103
1104static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
1105 struct sk_buff *skb)
1106{
1107 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
1108 complete(&ar->vdev_setup_done);
1109}
1110
1111static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
1112 struct sk_buff *skb)
1113{
Kalle Valo5a13e762014-01-20 11:01:46 +02001114 struct wmi_peer_sta_kickout_event *ev;
1115 struct ieee80211_sta *sta;
1116
1117 ev = (struct wmi_peer_sta_kickout_event *)skb->data;
1118
1119 ath10k_dbg(ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
1120 ev->peer_macaddr.addr);
1121
1122 rcu_read_lock();
1123
1124 sta = ieee80211_find_sta_by_ifaddr(ar->hw, ev->peer_macaddr.addr, NULL);
1125 if (!sta) {
1126 ath10k_warn("Spurious quick kickout for STA %pM\n",
1127 ev->peer_macaddr.addr);
1128 goto exit;
1129 }
1130
1131 ieee80211_report_low_ack(sta, 10);
1132
1133exit:
1134 rcu_read_unlock();
Kalle Valo5e3dd152013-06-12 20:52:10 +03001135}
1136
1137/*
1138 * FIXME
1139 *
1140 * We don't report to mac80211 sleep state of connected
1141 * stations. Due to this mac80211 can't fill in TIM IE
1142 * correctly.
1143 *
1144 * I know of no way of getting nullfunc frames that contain
1145 * sleep transition from connected stations - these do not
1146 * seem to be sent from the target to the host. There also
1147 * doesn't seem to be a dedicated event for that. So the
1148 * only way left to do this would be to read tim_bitmap
1149 * during SWBA.
1150 *
1151 * We could probably try using tim_bitmap from SWBA to tell
1152 * mac80211 which stations are asleep and which are not. The
1153 * problem here is calling mac80211 functions so many times
1154 * could take too long and make us miss the time to submit
1155 * the beacon to the target.
1156 *
1157 * So as a workaround we try to extend the TIM IE if there
1158 * is unicast buffered for stations with aid > 7 and fill it
1159 * in ourselves.
1160 */
1161static void ath10k_wmi_update_tim(struct ath10k *ar,
1162 struct ath10k_vif *arvif,
1163 struct sk_buff *bcn,
1164 struct wmi_bcn_info *bcn_info)
1165{
1166 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
1167 struct ieee80211_tim_ie *tim;
1168 u8 *ies, *ie;
1169 u8 ie_len, pvm_len;
1170
1171 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
1172 * we must copy the bitmap upon change and reuse it later */
1173 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
1174 int i;
1175
1176 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
1177 sizeof(bcn_info->tim_info.tim_bitmap));
1178
1179 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
1180 __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
1181 u32 v = __le32_to_cpu(t);
1182 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
1183 }
1184
1185 /* FW reports either length 0 or 16
1186 * so we calculate this on our own */
1187 arvif->u.ap.tim_len = 0;
1188 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
1189 if (arvif->u.ap.tim_bitmap[i])
1190 arvif->u.ap.tim_len = i;
1191
1192 arvif->u.ap.tim_len++;
1193 }
1194
1195 ies = bcn->data;
1196 ies += ieee80211_hdrlen(hdr->frame_control);
1197 ies += 12; /* fixed parameters */
1198
1199 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
1200 (u8 *)skb_tail_pointer(bcn) - ies);
1201 if (!ie) {
Michal Kazior09af8f82013-07-05 16:15:08 +03001202 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1203 ath10k_warn("no tim ie found;\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001204 return;
1205 }
1206
1207 tim = (void *)ie + 2;
1208 ie_len = ie[1];
1209 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
1210
1211 if (pvm_len < arvif->u.ap.tim_len) {
1212 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
1213 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
1214 void *next_ie = ie + 2 + ie_len;
1215
1216 if (skb_put(bcn, expand_size)) {
1217 memmove(next_ie + expand_size, next_ie, move_size);
1218
1219 ie[1] += expand_size;
1220 ie_len += expand_size;
1221 pvm_len += expand_size;
1222 } else {
1223 ath10k_warn("tim expansion failed\n");
1224 }
1225 }
1226
1227 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
1228 ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
1229 return;
1230 }
1231
1232 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
1233 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
1234
Michal Kazior748afc42014-01-23 12:48:21 +01001235 if (tim->dtim_count == 0) {
1236 ATH10K_SKB_CB(bcn)->bcn.dtim_zero = true;
1237
1238 if (__le32_to_cpu(bcn_info->tim_info.tim_mcast) == 1)
1239 ATH10K_SKB_CB(bcn)->bcn.deliver_cab = true;
1240 }
1241
Kalle Valo5e3dd152013-06-12 20:52:10 +03001242 ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
1243 tim->dtim_count, tim->dtim_period,
1244 tim->bitmap_ctrl, pvm_len);
1245}
1246
1247static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
1248 struct wmi_p2p_noa_info *noa)
1249{
1250 struct ieee80211_p2p_noa_attr *noa_attr;
1251 u8 ctwindow_oppps = noa->ctwindow_oppps;
1252 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
1253 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
1254 __le16 *noa_attr_len;
1255 u16 attr_len;
1256 u8 noa_descriptors = noa->num_descriptors;
1257 int i;
1258
1259 /* P2P IE */
1260 data[0] = WLAN_EID_VENDOR_SPECIFIC;
1261 data[1] = len - 2;
1262 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1263 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1264 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1265 data[5] = WLAN_OUI_TYPE_WFA_P2P;
1266
1267 /* NOA ATTR */
1268 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
1269 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
1270 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
1271
1272 noa_attr->index = noa->index;
1273 noa_attr->oppps_ctwindow = ctwindow;
1274 if (oppps)
1275 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
1276
1277 for (i = 0; i < noa_descriptors; i++) {
1278 noa_attr->desc[i].count =
1279 __le32_to_cpu(noa->descriptors[i].type_count);
1280 noa_attr->desc[i].duration = noa->descriptors[i].duration;
1281 noa_attr->desc[i].interval = noa->descriptors[i].interval;
1282 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
1283 }
1284
1285 attr_len = 2; /* index + oppps_ctwindow */
1286 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1287 *noa_attr_len = __cpu_to_le16(attr_len);
1288}
1289
1290static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
1291{
1292 u32 len = 0;
1293 u8 noa_descriptors = noa->num_descriptors;
1294 u8 opp_ps_info = noa->ctwindow_oppps;
1295 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
1296
1297
1298 if (!noa_descriptors && !opps_enabled)
1299 return len;
1300
1301 len += 1 + 1 + 4; /* EID + len + OUI */
1302 len += 1 + 2; /* noa attr + attr len */
1303 len += 1 + 1; /* index + oppps_ctwindow */
1304 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1305
1306 return len;
1307}
1308
1309static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
1310 struct sk_buff *bcn,
1311 struct wmi_bcn_info *bcn_info)
1312{
1313 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
1314 u8 *new_data, *old_data = arvif->u.ap.noa_data;
1315 u32 new_len;
1316
1317 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1318 return;
1319
1320 ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
1321 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
1322 new_len = ath10k_p2p_calc_noa_ie_len(noa);
1323 if (!new_len)
1324 goto cleanup;
1325
1326 new_data = kmalloc(new_len, GFP_ATOMIC);
1327 if (!new_data)
1328 goto cleanup;
1329
1330 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
1331
1332 spin_lock_bh(&ar->data_lock);
1333 arvif->u.ap.noa_data = new_data;
1334 arvif->u.ap.noa_len = new_len;
1335 spin_unlock_bh(&ar->data_lock);
1336 kfree(old_data);
1337 }
1338
1339 if (arvif->u.ap.noa_data)
1340 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
1341 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
1342 arvif->u.ap.noa_data,
1343 arvif->u.ap.noa_len);
1344 return;
1345
1346cleanup:
1347 spin_lock_bh(&ar->data_lock);
1348 arvif->u.ap.noa_data = NULL;
1349 arvif->u.ap.noa_len = 0;
1350 spin_unlock_bh(&ar->data_lock);
1351 kfree(old_data);
1352}
1353
1354
1355static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1356{
1357 struct wmi_host_swba_event *ev;
1358 u32 map;
1359 int i = -1;
1360 struct wmi_bcn_info *bcn_info;
1361 struct ath10k_vif *arvif;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001362 struct sk_buff *bcn;
Michal Kazior767d34f2014-02-27 18:50:03 +02001363 int ret, vdev_id = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001364
1365 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
1366
1367 ev = (struct wmi_host_swba_event *)skb->data;
1368 map = __le32_to_cpu(ev->vdev_map);
1369
1370 ath10k_dbg(ATH10K_DBG_MGMT, "host swba:\n"
1371 "-vdev map 0x%x\n",
1372 ev->vdev_map);
1373
1374 for (; map; map >>= 1, vdev_id++) {
1375 if (!(map & 0x1))
1376 continue;
1377
1378 i++;
1379
1380 if (i >= WMI_MAX_AP_VDEV) {
1381 ath10k_warn("swba has corrupted vdev map\n");
1382 break;
1383 }
1384
1385 bcn_info = &ev->bcn_info[i];
1386
1387 ath10k_dbg(ATH10K_DBG_MGMT,
1388 "-bcn_info[%d]:\n"
1389 "--tim_len %d\n"
1390 "--tim_mcast %d\n"
1391 "--tim_changed %d\n"
1392 "--tim_num_ps_pending %d\n"
1393 "--tim_bitmap 0x%08x%08x%08x%08x\n",
1394 i,
1395 __le32_to_cpu(bcn_info->tim_info.tim_len),
1396 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
1397 __le32_to_cpu(bcn_info->tim_info.tim_changed),
1398 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
1399 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
1400 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
1401 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
1402 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
1403
1404 arvif = ath10k_get_arvif(ar, vdev_id);
1405 if (arvif == NULL) {
1406 ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
1407 continue;
1408 }
1409
Michal Kaziorc2df44b2014-01-23 11:38:26 +01001410 /* There are no completions for beacons so wait for next SWBA
1411 * before telling mac80211 to decrement CSA counter
1412 *
1413 * Once CSA counter is completed stop sending beacons until
1414 * actual channel switch is done */
1415 if (arvif->vif->csa_active &&
1416 ieee80211_csa_is_complete(arvif->vif)) {
1417 ieee80211_csa_finish(arvif->vif);
1418 continue;
1419 }
1420
Kalle Valo5e3dd152013-06-12 20:52:10 +03001421 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
1422 if (!bcn) {
1423 ath10k_warn("could not get mac80211 beacon\n");
1424 continue;
1425 }
1426
1427 ath10k_tx_h_seq_no(bcn);
1428 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
1429 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
1430
Michal Kaziored543882013-09-13 14:16:56 +02001431 spin_lock_bh(&ar->data_lock);
Michal Kazior748afc42014-01-23 12:48:21 +01001432
Michal Kaziored543882013-09-13 14:16:56 +02001433 if (arvif->beacon) {
Michal Kazior748afc42014-01-23 12:48:21 +01001434 if (!arvif->beacon_sent)
1435 ath10k_warn("SWBA overrun on vdev %d\n",
1436 arvif->vdev_id);
1437
Michal Kazior767d34f2014-02-27 18:50:03 +02001438 dma_unmap_single(arvif->ar->dev,
1439 ATH10K_SKB_CB(arvif->beacon)->paddr,
1440 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02001441 dev_kfree_skb_any(arvif->beacon);
1442 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001443
Michal Kazior767d34f2014-02-27 18:50:03 +02001444 ATH10K_SKB_CB(bcn)->paddr = dma_map_single(arvif->ar->dev,
1445 bcn->data, bcn->len,
1446 DMA_TO_DEVICE);
1447 ret = dma_mapping_error(arvif->ar->dev,
1448 ATH10K_SKB_CB(bcn)->paddr);
1449 if (ret) {
1450 ath10k_warn("failed to map beacon: %d\n", ret);
1451 goto skip;
1452 }
Michal Kazior748afc42014-01-23 12:48:21 +01001453
Michal Kaziored543882013-09-13 14:16:56 +02001454 arvif->beacon = bcn;
Michal Kazior748afc42014-01-23 12:48:21 +01001455 arvif->beacon_sent = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001456
Michal Kaziored543882013-09-13 14:16:56 +02001457 ath10k_wmi_tx_beacon_nowait(arvif);
Michal Kazior767d34f2014-02-27 18:50:03 +02001458skip:
Michal Kaziored543882013-09-13 14:16:56 +02001459 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001460 }
1461}
1462
1463static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
1464 struct sk_buff *skb)
1465{
1466 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
1467}
1468
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001469static void ath10k_dfs_radar_report(struct ath10k *ar,
1470 struct wmi_single_phyerr_rx_event *event,
1471 struct phyerr_radar_report *rr,
1472 u64 tsf)
1473{
1474 u32 reg0, reg1, tsf32l;
1475 struct pulse_event pe;
1476 u64 tsf64;
1477 u8 rssi, width;
1478
1479 reg0 = __le32_to_cpu(rr->reg0);
1480 reg1 = __le32_to_cpu(rr->reg1);
1481
1482 ath10k_dbg(ATH10K_DBG_REGULATORY,
1483 "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
1484 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
1485 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
1486 MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
1487 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
1488 ath10k_dbg(ATH10K_DBG_REGULATORY,
1489 "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
1490 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
1491 MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
1492 MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
1493 MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
1494 MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
1495 ath10k_dbg(ATH10K_DBG_REGULATORY,
1496 "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
1497 MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
1498 MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
1499
1500 if (!ar->dfs_detector)
1501 return;
1502
1503 /* report event to DFS pattern detector */
1504 tsf32l = __le32_to_cpu(event->hdr.tsf_timestamp);
1505 tsf64 = tsf & (~0xFFFFFFFFULL);
1506 tsf64 |= tsf32l;
1507
1508 width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
1509 rssi = event->hdr.rssi_combined;
1510
1511 /* hardware store this as 8 bit signed value,
1512 * set to zero if negative number
1513 */
1514 if (rssi & 0x80)
1515 rssi = 0;
1516
1517 pe.ts = tsf64;
1518 pe.freq = ar->hw->conf.chandef.chan->center_freq;
1519 pe.width = width;
1520 pe.rssi = rssi;
1521
1522 ath10k_dbg(ATH10K_DBG_REGULATORY,
1523 "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
1524 pe.freq, pe.width, pe.rssi, pe.ts);
1525
1526 ATH10K_DFS_STAT_INC(ar, pulses_detected);
1527
1528 if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
1529 ath10k_dbg(ATH10K_DBG_REGULATORY,
1530 "dfs no pulse pattern detected, yet\n");
1531 return;
1532 }
1533
1534 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs radar detected\n");
1535 ATH10K_DFS_STAT_INC(ar, radar_detected);
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001536
1537 /* Control radar events reporting in debugfs file
1538 dfs_block_radar_events */
1539 if (ar->dfs_block_radar_events) {
1540 ath10k_info("DFS Radar detected, but ignored as requested\n");
1541 return;
1542 }
1543
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001544 ieee80211_radar_detected(ar->hw);
1545}
1546
1547static int ath10k_dfs_fft_report(struct ath10k *ar,
1548 struct wmi_single_phyerr_rx_event *event,
1549 struct phyerr_fft_report *fftr,
1550 u64 tsf)
1551{
1552 u32 reg0, reg1;
1553 u8 rssi, peak_mag;
1554
1555 reg0 = __le32_to_cpu(fftr->reg0);
1556 reg1 = __le32_to_cpu(fftr->reg1);
1557 rssi = event->hdr.rssi_combined;
1558
1559 ath10k_dbg(ATH10K_DBG_REGULATORY,
1560 "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
1561 MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
1562 MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
1563 MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
1564 MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
1565 ath10k_dbg(ATH10K_DBG_REGULATORY,
1566 "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
1567 MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
1568 MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
1569 MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
1570 MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
1571
1572 peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
1573
1574 /* false event detection */
1575 if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
1576 peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
1577 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
1578 ATH10K_DFS_STAT_INC(ar, pulses_discarded);
1579 return -EINVAL;
1580 }
1581
1582 return 0;
1583}
1584
1585static void ath10k_wmi_event_dfs(struct ath10k *ar,
1586 struct wmi_single_phyerr_rx_event *event,
1587 u64 tsf)
1588{
1589 int buf_len, tlv_len, res, i = 0;
1590 struct phyerr_tlv *tlv;
1591 struct phyerr_radar_report *rr;
1592 struct phyerr_fft_report *fftr;
1593 u8 *tlv_buf;
1594
1595 buf_len = __le32_to_cpu(event->hdr.buf_len);
1596 ath10k_dbg(ATH10K_DBG_REGULATORY,
1597 "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
1598 event->hdr.phy_err_code, event->hdr.rssi_combined,
1599 __le32_to_cpu(event->hdr.tsf_timestamp), tsf, buf_len);
1600
1601 /* Skip event if DFS disabled */
1602 if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED))
1603 return;
1604
1605 ATH10K_DFS_STAT_INC(ar, pulses_total);
1606
1607 while (i < buf_len) {
1608 if (i + sizeof(*tlv) > buf_len) {
1609 ath10k_warn("too short buf for tlv header (%d)\n", i);
1610 return;
1611 }
1612
1613 tlv = (struct phyerr_tlv *)&event->bufp[i];
1614 tlv_len = __le16_to_cpu(tlv->len);
1615 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1616 ath10k_dbg(ATH10K_DBG_REGULATORY,
1617 "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
1618 tlv_len, tlv->tag, tlv->sig);
1619
1620 switch (tlv->tag) {
1621 case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
1622 if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
1623 ath10k_warn("too short radar pulse summary (%d)\n",
1624 i);
1625 return;
1626 }
1627
1628 rr = (struct phyerr_radar_report *)tlv_buf;
1629 ath10k_dfs_radar_report(ar, event, rr, tsf);
1630 break;
1631 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1632 if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
1633 ath10k_warn("too short fft report (%d)\n", i);
1634 return;
1635 }
1636
1637 fftr = (struct phyerr_fft_report *)tlv_buf;
1638 res = ath10k_dfs_fft_report(ar, event, fftr, tsf);
1639 if (res)
1640 return;
1641 break;
1642 }
1643
1644 i += sizeof(*tlv) + tlv_len;
1645 }
1646}
1647
1648static void ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1649 struct wmi_single_phyerr_rx_event *event,
1650 u64 tsf)
1651{
1652 ath10k_dbg(ATH10K_DBG_WMI, "wmi event spectral scan\n");
1653}
1654
Kalle Valo5e3dd152013-06-12 20:52:10 +03001655static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1656{
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001657 struct wmi_comb_phyerr_rx_event *comb_event;
1658 struct wmi_single_phyerr_rx_event *event;
1659 u32 count, i, buf_len, phy_err_code;
1660 u64 tsf;
1661 int left_len = skb->len;
1662
1663 ATH10K_DFS_STAT_INC(ar, phy_errors);
1664
1665 /* Check if combined event available */
1666 if (left_len < sizeof(*comb_event)) {
1667 ath10k_warn("wmi phyerr combined event wrong len\n");
1668 return;
1669 }
1670
1671 left_len -= sizeof(*comb_event);
1672
1673 /* Check number of included events */
1674 comb_event = (struct wmi_comb_phyerr_rx_event *)skb->data;
1675 count = __le32_to_cpu(comb_event->hdr.num_phyerr_events);
1676
1677 tsf = __le32_to_cpu(comb_event->hdr.tsf_u32);
1678 tsf <<= 32;
1679 tsf |= __le32_to_cpu(comb_event->hdr.tsf_l32);
1680
1681 ath10k_dbg(ATH10K_DBG_WMI,
1682 "wmi event phyerr count %d tsf64 0x%llX\n",
1683 count, tsf);
1684
1685 event = (struct wmi_single_phyerr_rx_event *)comb_event->bufp;
1686 for (i = 0; i < count; i++) {
1687 /* Check if we can read event header */
1688 if (left_len < sizeof(*event)) {
1689 ath10k_warn("single event (%d) wrong head len\n", i);
1690 return;
1691 }
1692
1693 left_len -= sizeof(*event);
1694
1695 buf_len = __le32_to_cpu(event->hdr.buf_len);
1696 phy_err_code = event->hdr.phy_err_code;
1697
1698 if (left_len < buf_len) {
1699 ath10k_warn("single event (%d) wrong buf len\n", i);
1700 return;
1701 }
1702
1703 left_len -= buf_len;
1704
1705 switch (phy_err_code) {
1706 case PHY_ERROR_RADAR:
1707 ath10k_wmi_event_dfs(ar, event, tsf);
1708 break;
1709 case PHY_ERROR_SPECTRAL_SCAN:
1710 ath10k_wmi_event_spectral_scan(ar, event, tsf);
1711 break;
1712 case PHY_ERROR_FALSE_RADAR_EXT:
1713 ath10k_wmi_event_dfs(ar, event, tsf);
1714 ath10k_wmi_event_spectral_scan(ar, event, tsf);
1715 break;
1716 default:
1717 break;
1718 }
1719
1720 event += sizeof(*event) + buf_len;
1721 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722}
1723
1724static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
1725{
1726 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
1727}
1728
1729static void ath10k_wmi_event_profile_match(struct ath10k *ar,
1730 struct sk_buff *skb)
1731{
1732 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
1733}
1734
1735static void ath10k_wmi_event_debug_print(struct ath10k *ar,
Kalle Valo2fe52882014-01-03 12:59:20 +02001736 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001737{
Kalle Valo2fe52882014-01-03 12:59:20 +02001738 char buf[101], c;
1739 int i;
1740
1741 for (i = 0; i < sizeof(buf) - 1; i++) {
1742 if (i >= skb->len)
1743 break;
1744
1745 c = skb->data[i];
1746
1747 if (c == '\0')
1748 break;
1749
1750 if (isascii(c) && isprint(c))
1751 buf[i] = c;
1752 else
1753 buf[i] = '.';
1754 }
1755
1756 if (i == sizeof(buf) - 1)
1757 ath10k_warn("wmi debug print truncated: %d\n", skb->len);
1758
1759 /* for some reason the debug prints end with \n, remove that */
1760 if (skb->data[i - 1] == '\n')
1761 i--;
1762
1763 /* the last byte is always reserved for the null character */
1764 buf[i] = '\0';
1765
1766 ath10k_dbg(ATH10K_DBG_WMI, "wmi event debug print '%s'\n", buf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001767}
1768
1769static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
1770{
1771 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
1772}
1773
1774static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
1775 struct sk_buff *skb)
1776{
1777 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
1778}
1779
1780static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
1781 struct sk_buff *skb)
1782{
1783 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
1784}
1785
1786static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
1787 struct sk_buff *skb)
1788{
1789 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
1790}
1791
1792static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
1793 struct sk_buff *skb)
1794{
1795 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
1796}
1797
1798static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
1799 struct sk_buff *skb)
1800{
1801 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
1802}
1803
1804static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
1805 struct sk_buff *skb)
1806{
1807 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
1808}
1809
1810static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
1811 struct sk_buff *skb)
1812{
1813 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
1814}
1815
1816static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
1817 struct sk_buff *skb)
1818{
1819 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
1820}
1821
1822static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
1823 struct sk_buff *skb)
1824{
1825 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
1826}
1827
1828static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
1829 struct sk_buff *skb)
1830{
1831 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
1832}
1833
1834static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
1835 struct sk_buff *skb)
1836{
1837 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
1838}
1839
1840static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
1841 struct sk_buff *skb)
1842{
1843 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
1844}
1845
1846static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
1847 struct sk_buff *skb)
1848{
1849 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
1850}
1851
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02001852static void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar,
1853 struct sk_buff *skb)
1854{
1855 ath10k_dbg(ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
1856}
1857
1858static void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar,
1859 struct sk_buff *skb)
1860{
1861 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
1862}
1863
1864static void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar,
1865 struct sk_buff *skb)
1866{
1867 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
1868}
1869
Bartosz Markowskib3effe62013-09-26 17:47:11 +02001870static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
1871 u32 num_units, u32 unit_len)
1872{
1873 dma_addr_t paddr;
1874 u32 pool_size;
1875 int idx = ar->wmi.num_mem_chunks;
1876
1877 pool_size = num_units * round_up(unit_len, 4);
1878
1879 if (!pool_size)
1880 return -EINVAL;
1881
1882 ar->wmi.mem_chunks[idx].vaddr = dma_alloc_coherent(ar->dev,
1883 pool_size,
1884 &paddr,
1885 GFP_ATOMIC);
1886 if (!ar->wmi.mem_chunks[idx].vaddr) {
1887 ath10k_warn("failed to allocate memory chunk\n");
1888 return -ENOMEM;
1889 }
1890
1891 memset(ar->wmi.mem_chunks[idx].vaddr, 0, pool_size);
1892
1893 ar->wmi.mem_chunks[idx].paddr = paddr;
1894 ar->wmi.mem_chunks[idx].len = pool_size;
1895 ar->wmi.mem_chunks[idx].req_id = req_id;
1896 ar->wmi.num_mem_chunks++;
1897
1898 return 0;
1899}
1900
Kalle Valo5e3dd152013-06-12 20:52:10 +03001901static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
1902 struct sk_buff *skb)
1903{
1904 struct wmi_service_ready_event *ev = (void *)skb->data;
1905
1906 if (skb->len < sizeof(*ev)) {
1907 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
1908 skb->len, sizeof(*ev));
1909 return;
1910 }
1911
1912 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
1913 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
1914 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
1915 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
1916 ar->fw_version_major =
1917 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
1918 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
1919 ar->fw_version_release =
1920 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
1921 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
1922 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
Michal Kazior8865bee42013-07-24 12:36:46 +02001923 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
1924
Kalle Valo1a222432013-09-27 19:55:07 +03001925 /* only manually set fw features when not using FW IE format */
1926 if (ar->fw_api == 1 && ar->fw_version_build > 636)
Michal Kazior0d9b0432013-08-09 10:13:33 +02001927 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
1928
Michal Kazior8865bee42013-07-24 12:36:46 +02001929 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
1930 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
1931 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
1932 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
1933 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001934
1935 ar->ath_common.regulatory.current_rd =
1936 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
1937
1938 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
1939 sizeof(ev->wmi_service_bitmap));
1940
1941 if (strlen(ar->hw->wiphy->fw_version) == 0) {
1942 snprintf(ar->hw->wiphy->fw_version,
1943 sizeof(ar->hw->wiphy->fw_version),
1944 "%u.%u.%u.%u",
1945 ar->fw_version_major,
1946 ar->fw_version_minor,
1947 ar->fw_version_release,
1948 ar->fw_version_build);
1949 }
1950
1951 /* FIXME: it probably should be better to support this */
1952 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
1953 ath10k_warn("target requested %d memory chunks; ignoring\n",
1954 __le32_to_cpu(ev->num_mem_reqs));
1955 }
1956
1957 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior8865bee42013-07-24 12:36:46 +02001958 "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 +03001959 __le32_to_cpu(ev->sw_version),
1960 __le32_to_cpu(ev->sw_version_1),
1961 __le32_to_cpu(ev->abi_version),
1962 __le32_to_cpu(ev->phy_capability),
1963 __le32_to_cpu(ev->ht_cap_info),
1964 __le32_to_cpu(ev->vht_cap_info),
1965 __le32_to_cpu(ev->vht_supp_mcs),
1966 __le32_to_cpu(ev->sys_cap_info),
Michal Kazior8865bee42013-07-24 12:36:46 +02001967 __le32_to_cpu(ev->num_mem_reqs),
1968 __le32_to_cpu(ev->num_rf_chains));
Kalle Valo5e3dd152013-06-12 20:52:10 +03001969
1970 complete(&ar->wmi.service_ready);
1971}
1972
Bartosz Markowski6f97d252013-09-26 17:47:09 +02001973static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
1974 struct sk_buff *skb)
1975{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02001976 u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
1977 int ret;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02001978 struct wmi_service_ready_event_10x *ev = (void *)skb->data;
1979
1980 if (skb->len < sizeof(*ev)) {
1981 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
1982 skb->len, sizeof(*ev));
1983 return;
1984 }
1985
1986 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
1987 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
1988 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
1989 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
1990 ar->fw_version_major =
1991 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
1992 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
1993 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
1994 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
1995
1996 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
1997 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
1998 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
1999 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2000 }
2001
2002 ar->ath_common.regulatory.current_rd =
2003 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2004
2005 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
2006 sizeof(ev->wmi_service_bitmap));
2007
2008 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2009 snprintf(ar->hw->wiphy->fw_version,
2010 sizeof(ar->hw->wiphy->fw_version),
2011 "%u.%u",
2012 ar->fw_version_major,
2013 ar->fw_version_minor);
2014 }
2015
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002016 num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
2017
2018 if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
2019 ath10k_warn("requested memory chunks number (%d) exceeds the limit\n",
2020 num_mem_reqs);
2021 return;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002022 }
2023
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002024 if (!num_mem_reqs)
2025 goto exit;
2026
2027 ath10k_dbg(ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
2028 num_mem_reqs);
2029
2030 for (i = 0; i < num_mem_reqs; ++i) {
2031 req_id = __le32_to_cpu(ev->mem_reqs[i].req_id);
2032 num_units = __le32_to_cpu(ev->mem_reqs[i].num_units);
2033 unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size);
2034 num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info);
2035
2036 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
2037 /* number of units to allocate is number of
2038 * peers, 1 extra for self peer on target */
2039 /* this needs to be tied, host and target
2040 * can get out of sync */
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002041 num_units = TARGET_10X_NUM_PEERS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002042 else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS)
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002043 num_units = TARGET_10X_NUM_VDEVS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002044
2045 ath10k_dbg(ATH10K_DBG_WMI,
2046 "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
2047 req_id,
2048 __le32_to_cpu(ev->mem_reqs[i].num_units),
2049 num_unit_info,
2050 unit_size,
2051 num_units);
2052
2053 ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
2054 unit_size);
2055 if (ret)
2056 return;
2057 }
2058
2059exit:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002060 ath10k_dbg(ATH10K_DBG_WMI,
2061 "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",
2062 __le32_to_cpu(ev->sw_version),
2063 __le32_to_cpu(ev->abi_version),
2064 __le32_to_cpu(ev->phy_capability),
2065 __le32_to_cpu(ev->ht_cap_info),
2066 __le32_to_cpu(ev->vht_cap_info),
2067 __le32_to_cpu(ev->vht_supp_mcs),
2068 __le32_to_cpu(ev->sys_cap_info),
2069 __le32_to_cpu(ev->num_mem_reqs),
2070 __le32_to_cpu(ev->num_rf_chains));
2071
2072 complete(&ar->wmi.service_ready);
2073}
2074
Kalle Valo5e3dd152013-06-12 20:52:10 +03002075static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
2076{
2077 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
2078
2079 if (WARN_ON(skb->len < sizeof(*ev)))
2080 return -EINVAL;
2081
2082 memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
2083
2084 ath10k_dbg(ATH10K_DBG_WMI,
Ben Greear2c347522014-02-05 13:58:32 -08002085 "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 +03002086 __le32_to_cpu(ev->sw_version),
2087 __le32_to_cpu(ev->abi_version),
2088 ev->mac_addr.addr,
Ben Greear2c347522014-02-05 13:58:32 -08002089 __le32_to_cpu(ev->status), skb->len, sizeof(*ev));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090
2091 complete(&ar->wmi.unified_ready);
2092 return 0;
2093}
2094
Bartosz Markowskice428702013-09-26 17:47:05 +02002095static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096{
2097 struct wmi_cmd_hdr *cmd_hdr;
2098 enum wmi_event_id id;
2099 u16 len;
2100
2101 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2102 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2103
2104 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2105 return;
2106
2107 len = skb->len;
2108
2109 trace_ath10k_wmi_event(id, skb->data, skb->len);
2110
2111 switch (id) {
2112 case WMI_MGMT_RX_EVENTID:
2113 ath10k_wmi_event_mgmt_rx(ar, skb);
2114 /* mgmt_rx() owns the skb now! */
2115 return;
2116 case WMI_SCAN_EVENTID:
2117 ath10k_wmi_event_scan(ar, skb);
2118 break;
2119 case WMI_CHAN_INFO_EVENTID:
2120 ath10k_wmi_event_chan_info(ar, skb);
2121 break;
2122 case WMI_ECHO_EVENTID:
2123 ath10k_wmi_event_echo(ar, skb);
2124 break;
2125 case WMI_DEBUG_MESG_EVENTID:
2126 ath10k_wmi_event_debug_mesg(ar, skb);
2127 break;
2128 case WMI_UPDATE_STATS_EVENTID:
2129 ath10k_wmi_event_update_stats(ar, skb);
2130 break;
2131 case WMI_VDEV_START_RESP_EVENTID:
2132 ath10k_wmi_event_vdev_start_resp(ar, skb);
2133 break;
2134 case WMI_VDEV_STOPPED_EVENTID:
2135 ath10k_wmi_event_vdev_stopped(ar, skb);
2136 break;
2137 case WMI_PEER_STA_KICKOUT_EVENTID:
2138 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2139 break;
2140 case WMI_HOST_SWBA_EVENTID:
2141 ath10k_wmi_event_host_swba(ar, skb);
2142 break;
2143 case WMI_TBTTOFFSET_UPDATE_EVENTID:
2144 ath10k_wmi_event_tbttoffset_update(ar, skb);
2145 break;
2146 case WMI_PHYERR_EVENTID:
2147 ath10k_wmi_event_phyerr(ar, skb);
2148 break;
2149 case WMI_ROAM_EVENTID:
2150 ath10k_wmi_event_roam(ar, skb);
2151 break;
2152 case WMI_PROFILE_MATCH:
2153 ath10k_wmi_event_profile_match(ar, skb);
2154 break;
2155 case WMI_DEBUG_PRINT_EVENTID:
2156 ath10k_wmi_event_debug_print(ar, skb);
2157 break;
2158 case WMI_PDEV_QVIT_EVENTID:
2159 ath10k_wmi_event_pdev_qvit(ar, skb);
2160 break;
2161 case WMI_WLAN_PROFILE_DATA_EVENTID:
2162 ath10k_wmi_event_wlan_profile_data(ar, skb);
2163 break;
2164 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
2165 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2166 break;
2167 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
2168 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2169 break;
2170 case WMI_RTT_ERROR_REPORT_EVENTID:
2171 ath10k_wmi_event_rtt_error_report(ar, skb);
2172 break;
2173 case WMI_WOW_WAKEUP_HOST_EVENTID:
2174 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2175 break;
2176 case WMI_DCS_INTERFERENCE_EVENTID:
2177 ath10k_wmi_event_dcs_interference(ar, skb);
2178 break;
2179 case WMI_PDEV_TPC_CONFIG_EVENTID:
2180 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2181 break;
2182 case WMI_PDEV_FTM_INTG_EVENTID:
2183 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
2184 break;
2185 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
2186 ath10k_wmi_event_gtk_offload_status(ar, skb);
2187 break;
2188 case WMI_GTK_REKEY_FAIL_EVENTID:
2189 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
2190 break;
2191 case WMI_TX_DELBA_COMPLETE_EVENTID:
2192 ath10k_wmi_event_delba_complete(ar, skb);
2193 break;
2194 case WMI_TX_ADDBA_COMPLETE_EVENTID:
2195 ath10k_wmi_event_addba_complete(ar, skb);
2196 break;
2197 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
2198 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
2199 break;
2200 case WMI_SERVICE_READY_EVENTID:
2201 ath10k_wmi_service_ready_event_rx(ar, skb);
2202 break;
2203 case WMI_READY_EVENTID:
2204 ath10k_wmi_ready_event_rx(ar, skb);
2205 break;
2206 default:
2207 ath10k_warn("Unknown eventid: %d\n", id);
2208 break;
2209 }
2210
2211 dev_kfree_skb(skb);
2212}
2213
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002214static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
2215{
2216 struct wmi_cmd_hdr *cmd_hdr;
2217 enum wmi_10x_event_id id;
2218 u16 len;
2219
2220 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2221 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2222
2223 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2224 return;
2225
2226 len = skb->len;
2227
2228 trace_ath10k_wmi_event(id, skb->data, skb->len);
2229
2230 switch (id) {
2231 case WMI_10X_MGMT_RX_EVENTID:
2232 ath10k_wmi_event_mgmt_rx(ar, skb);
2233 /* mgmt_rx() owns the skb now! */
2234 return;
2235 case WMI_10X_SCAN_EVENTID:
2236 ath10k_wmi_event_scan(ar, skb);
2237 break;
2238 case WMI_10X_CHAN_INFO_EVENTID:
2239 ath10k_wmi_event_chan_info(ar, skb);
2240 break;
2241 case WMI_10X_ECHO_EVENTID:
2242 ath10k_wmi_event_echo(ar, skb);
2243 break;
2244 case WMI_10X_DEBUG_MESG_EVENTID:
2245 ath10k_wmi_event_debug_mesg(ar, skb);
2246 break;
2247 case WMI_10X_UPDATE_STATS_EVENTID:
2248 ath10k_wmi_event_update_stats(ar, skb);
2249 break;
2250 case WMI_10X_VDEV_START_RESP_EVENTID:
2251 ath10k_wmi_event_vdev_start_resp(ar, skb);
2252 break;
2253 case WMI_10X_VDEV_STOPPED_EVENTID:
2254 ath10k_wmi_event_vdev_stopped(ar, skb);
2255 break;
2256 case WMI_10X_PEER_STA_KICKOUT_EVENTID:
2257 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2258 break;
2259 case WMI_10X_HOST_SWBA_EVENTID:
2260 ath10k_wmi_event_host_swba(ar, skb);
2261 break;
2262 case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
2263 ath10k_wmi_event_tbttoffset_update(ar, skb);
2264 break;
2265 case WMI_10X_PHYERR_EVENTID:
2266 ath10k_wmi_event_phyerr(ar, skb);
2267 break;
2268 case WMI_10X_ROAM_EVENTID:
2269 ath10k_wmi_event_roam(ar, skb);
2270 break;
2271 case WMI_10X_PROFILE_MATCH:
2272 ath10k_wmi_event_profile_match(ar, skb);
2273 break;
2274 case WMI_10X_DEBUG_PRINT_EVENTID:
2275 ath10k_wmi_event_debug_print(ar, skb);
2276 break;
2277 case WMI_10X_PDEV_QVIT_EVENTID:
2278 ath10k_wmi_event_pdev_qvit(ar, skb);
2279 break;
2280 case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
2281 ath10k_wmi_event_wlan_profile_data(ar, skb);
2282 break;
2283 case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
2284 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2285 break;
2286 case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
2287 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2288 break;
2289 case WMI_10X_RTT_ERROR_REPORT_EVENTID:
2290 ath10k_wmi_event_rtt_error_report(ar, skb);
2291 break;
2292 case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
2293 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2294 break;
2295 case WMI_10X_DCS_INTERFERENCE_EVENTID:
2296 ath10k_wmi_event_dcs_interference(ar, skb);
2297 break;
2298 case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
2299 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2300 break;
2301 case WMI_10X_INST_RSSI_STATS_EVENTID:
2302 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2303 break;
2304 case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
2305 ath10k_wmi_event_vdev_standby_req(ar, skb);
2306 break;
2307 case WMI_10X_VDEV_RESUME_REQ_EVENTID:
2308 ath10k_wmi_event_vdev_resume_req(ar, skb);
2309 break;
2310 case WMI_10X_SERVICE_READY_EVENTID:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002311 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002312 break;
2313 case WMI_10X_READY_EVENTID:
2314 ath10k_wmi_ready_event_rx(ar, skb);
2315 break;
2316 default:
2317 ath10k_warn("Unknown eventid: %d\n", id);
2318 break;
2319 }
2320
2321 dev_kfree_skb(skb);
2322}
2323
2324
Bartosz Markowskice428702013-09-26 17:47:05 +02002325static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
2326{
2327 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002328 ath10k_wmi_10x_process_rx(ar, skb);
Bartosz Markowskice428702013-09-26 17:47:05 +02002329 else
2330 ath10k_wmi_main_process_rx(ar, skb);
2331}
2332
Kalle Valo5e3dd152013-06-12 20:52:10 +03002333/* WMI Initialization functions */
2334int ath10k_wmi_attach(struct ath10k *ar)
2335{
Bartosz Markowskice428702013-09-26 17:47:05 +02002336 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
Bartosz Markowskib7e3adf2013-09-26 17:47:06 +02002337 ar->wmi.cmd = &wmi_10x_cmd_map;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002338 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002339 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
Bartosz Markowskice428702013-09-26 17:47:05 +02002340 } else {
2341 ar->wmi.cmd = &wmi_cmd_map;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002342 ar->wmi.vdev_param = &wmi_vdev_param_map;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002343 ar->wmi.pdev_param = &wmi_pdev_param_map;
Bartosz Markowskice428702013-09-26 17:47:05 +02002344 }
2345
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 init_completion(&ar->wmi.service_ready);
2347 init_completion(&ar->wmi.unified_ready);
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002348 init_waitqueue_head(&ar->wmi.tx_credits_wq);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002349
2350 return 0;
2351}
2352
2353void ath10k_wmi_detach(struct ath10k *ar)
2354{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002355 int i;
2356
2357 /* free the host memory chunks requested by firmware */
2358 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2359 dma_free_coherent(ar->dev,
2360 ar->wmi.mem_chunks[i].len,
2361 ar->wmi.mem_chunks[i].vaddr,
2362 ar->wmi.mem_chunks[i].paddr);
2363 }
2364
2365 ar->wmi.num_mem_chunks = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366}
2367
2368int ath10k_wmi_connect_htc_service(struct ath10k *ar)
2369{
2370 int status;
2371 struct ath10k_htc_svc_conn_req conn_req;
2372 struct ath10k_htc_svc_conn_resp conn_resp;
2373
2374 memset(&conn_req, 0, sizeof(conn_req));
2375 memset(&conn_resp, 0, sizeof(conn_resp));
2376
2377 /* these fields are the same for all service endpoints */
2378 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
2379 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002380 conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002381
2382 /* connect to control service */
2383 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
2384
Michal Kaziorcd003fa2013-07-05 16:15:13 +03002385 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002386 if (status) {
2387 ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
2388 status);
2389 return status;
2390 }
2391
2392 ar->wmi.eid = conn_resp.eid;
2393 return 0;
2394}
2395
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002396static int ath10k_wmi_main_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2397 u16 rd2g, u16 rd5g, u16 ctl2g,
2398 u16 ctl5g)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002399{
2400 struct wmi_pdev_set_regdomain_cmd *cmd;
2401 struct sk_buff *skb;
2402
2403 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2404 if (!skb)
2405 return -ENOMEM;
2406
2407 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
2408 cmd->reg_domain = __cpu_to_le32(rd);
2409 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2410 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2411 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2412 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2413
2414 ath10k_dbg(ATH10K_DBG_WMI,
2415 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
2416 rd, rd2g, rd5g, ctl2g, ctl5g);
2417
Bartosz Markowskice428702013-09-26 17:47:05 +02002418 return ath10k_wmi_cmd_send(ar, skb,
2419 ar->wmi.cmd->pdev_set_regdomain_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002420}
2421
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002422static int ath10k_wmi_10x_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2423 u16 rd2g, u16 rd5g,
2424 u16 ctl2g, u16 ctl5g,
2425 enum wmi_dfs_region dfs_reg)
2426{
2427 struct wmi_pdev_set_regdomain_cmd_10x *cmd;
2428 struct sk_buff *skb;
2429
2430 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2431 if (!skb)
2432 return -ENOMEM;
2433
2434 cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
2435 cmd->reg_domain = __cpu_to_le32(rd);
2436 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2437 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2438 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2439 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2440 cmd->dfs_domain = __cpu_to_le32(dfs_reg);
2441
2442 ath10k_dbg(ATH10K_DBG_WMI,
2443 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
2444 rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
2445
2446 return ath10k_wmi_cmd_send(ar, skb,
2447 ar->wmi.cmd->pdev_set_regdomain_cmdid);
2448}
2449
2450int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
2451 u16 rd5g, u16 ctl2g, u16 ctl5g,
2452 enum wmi_dfs_region dfs_reg)
2453{
2454 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2455 return ath10k_wmi_10x_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2456 ctl2g, ctl5g, dfs_reg);
2457 else
2458 return ath10k_wmi_main_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2459 ctl2g, ctl5g);
2460}
2461
Kalle Valo5e3dd152013-06-12 20:52:10 +03002462int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
2463 const struct wmi_channel_arg *arg)
2464{
2465 struct wmi_set_channel_cmd *cmd;
2466 struct sk_buff *skb;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002467 u32 ch_flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468
2469 if (arg->passive)
2470 return -EINVAL;
2471
2472 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2473 if (!skb)
2474 return -ENOMEM;
2475
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002476 if (arg->chan_radar)
2477 ch_flags |= WMI_CHAN_FLAG_DFS;
2478
Kalle Valo5e3dd152013-06-12 20:52:10 +03002479 cmd = (struct wmi_set_channel_cmd *)skb->data;
2480 cmd->chan.mhz = __cpu_to_le32(arg->freq);
2481 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
2482 cmd->chan.mode = arg->mode;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002483 cmd->chan.flags |= __cpu_to_le32(ch_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484 cmd->chan.min_power = arg->min_power;
2485 cmd->chan.max_power = arg->max_power;
2486 cmd->chan.reg_power = arg->max_reg_power;
2487 cmd->chan.reg_classid = arg->reg_class_id;
2488 cmd->chan.antenna_max = arg->max_antenna_gain;
2489
2490 ath10k_dbg(ATH10K_DBG_WMI,
2491 "wmi set channel mode %d freq %d\n",
2492 arg->mode, arg->freq);
2493
Bartosz Markowskice428702013-09-26 17:47:05 +02002494 return ath10k_wmi_cmd_send(ar, skb,
2495 ar->wmi.cmd->pdev_set_channel_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002496}
2497
Marek Puzyniak00f54822014-02-10 17:14:24 +01002498int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002499{
2500 struct wmi_pdev_suspend_cmd *cmd;
2501 struct sk_buff *skb;
2502
2503 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2504 if (!skb)
2505 return -ENOMEM;
2506
2507 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
Marek Puzyniak00f54822014-02-10 17:14:24 +01002508 cmd->suspend_opt = __cpu_to_le32(suspend_opt);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002509
Bartosz Markowskice428702013-09-26 17:47:05 +02002510 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_suspend_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002511}
2512
2513int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
2514{
2515 struct sk_buff *skb;
2516
2517 skb = ath10k_wmi_alloc_skb(0);
2518 if (skb == NULL)
2519 return -ENOMEM;
2520
Bartosz Markowskice428702013-09-26 17:47:05 +02002521 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_resume_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002522}
2523
Bartosz Markowski226a3392013-09-26 17:47:16 +02002524int ath10k_wmi_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002525{
2526 struct wmi_pdev_set_param_cmd *cmd;
2527 struct sk_buff *skb;
2528
Bartosz Markowski226a3392013-09-26 17:47:16 +02002529 if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
2530 ath10k_warn("pdev param %d not supported by firmware\n", id);
Bartosz Markowskid5449432013-10-15 09:55:32 +02002531 return -EOPNOTSUPP;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002532 }
2533
Kalle Valo5e3dd152013-06-12 20:52:10 +03002534 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2535 if (!skb)
2536 return -ENOMEM;
2537
2538 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
2539 cmd->param_id = __cpu_to_le32(id);
2540 cmd->param_value = __cpu_to_le32(value);
2541
2542 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
2543 id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02002544 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545}
2546
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002547static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002548{
2549 struct wmi_init_cmd *cmd;
2550 struct sk_buff *buf;
2551 struct wmi_resource_config config = {};
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002552 u32 len, val;
2553 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002554
2555 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
2556 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
2557 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
2558
2559 config.num_offload_reorder_bufs =
2560 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
2561
2562 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
2563 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
2564 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
2565 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
2566 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
2567 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2568 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2569 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2570 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
2571 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
2572
2573 config.scan_max_pending_reqs =
2574 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
2575
2576 config.bmiss_offload_max_vdev =
2577 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
2578
2579 config.roam_offload_max_vdev =
2580 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
2581
2582 config.roam_offload_max_ap_profiles =
2583 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
2584
2585 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
2586 config.num_mcast_table_elems =
2587 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
2588
2589 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
2590 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
2591 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
2592 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
2593 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
2594
2595 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
2596 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
2597
2598 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
2599
2600 config.gtk_offload_max_vdev =
2601 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
2602
2603 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
2604 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
2605
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002606 len = sizeof(*cmd) +
2607 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
2608
2609 buf = ath10k_wmi_alloc_skb(len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002610 if (!buf)
2611 return -ENOMEM;
2612
2613 cmd = (struct wmi_init_cmd *)buf->data;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002614
2615 if (ar->wmi.num_mem_chunks == 0) {
2616 cmd->num_host_mem_chunks = 0;
2617 goto out;
2618 }
2619
2620 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002621 ar->wmi.num_mem_chunks);
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002622
2623 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
2624
2625 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2626 cmd->host_mem_chunks[i].ptr =
2627 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
2628 cmd->host_mem_chunks[i].size =
2629 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
2630 cmd->host_mem_chunks[i].req_id =
2631 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
2632
2633 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002634 "wmi chunk %d len %d requested, addr 0x%llx\n",
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002635 i,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002636 ar->wmi.mem_chunks[i].len,
2637 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002638 }
2639out:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002640 memcpy(&cmd->resource_config, &config, sizeof(config));
2641
2642 ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02002643 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644}
2645
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002646static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
2647{
2648 struct wmi_init_cmd_10x *cmd;
2649 struct sk_buff *buf;
2650 struct wmi_resource_config_10x config = {};
2651 u32 len, val;
2652 int i;
2653
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002654 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
2655 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
2656 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
2657 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
2658 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
2659 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
2660 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
2661 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
2662 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
2663 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
2664 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
2665 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002666
2667 config.scan_max_pending_reqs =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002668 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002669
2670 config.bmiss_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002671 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002672
2673 config.roam_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002674 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002675
2676 config.roam_offload_max_ap_profiles =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002677 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002678
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002679 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002680 config.num_mcast_table_elems =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002681 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002682
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002683 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
2684 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
2685 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
2686 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
2687 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002688
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002689 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002690 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
2691
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002692 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002693
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002694 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
2695 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002696
2697 len = sizeof(*cmd) +
2698 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
2699
2700 buf = ath10k_wmi_alloc_skb(len);
2701 if (!buf)
2702 return -ENOMEM;
2703
2704 cmd = (struct wmi_init_cmd_10x *)buf->data;
2705
2706 if (ar->wmi.num_mem_chunks == 0) {
2707 cmd->num_host_mem_chunks = 0;
2708 goto out;
2709 }
2710
2711 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002712 ar->wmi.num_mem_chunks);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002713
2714 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
2715
2716 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2717 cmd->host_mem_chunks[i].ptr =
2718 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
2719 cmd->host_mem_chunks[i].size =
2720 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
2721 cmd->host_mem_chunks[i].req_id =
2722 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
2723
2724 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002725 "wmi chunk %d len %d requested, addr 0x%llx\n",
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002726 i,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002727 ar->wmi.mem_chunks[i].len,
2728 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002729 }
2730out:
2731 memcpy(&cmd->resource_config, &config, sizeof(config));
2732
2733 ath10k_dbg(ATH10K_DBG_WMI, "wmi init 10x\n");
2734 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
2735}
2736
2737int ath10k_wmi_cmd_init(struct ath10k *ar)
2738{
2739 int ret;
2740
2741 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2742 ret = ath10k_wmi_10x_cmd_init(ar);
2743 else
2744 ret = ath10k_wmi_main_cmd_init(ar);
2745
2746 return ret;
2747}
2748
Bartosz Markowski89b7e762013-09-26 17:47:17 +02002749static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar,
2750 const struct wmi_start_scan_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751{
2752 int len;
2753
Bartosz Markowski89b7e762013-09-26 17:47:17 +02002754 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2755 len = sizeof(struct wmi_start_scan_cmd_10x);
2756 else
2757 len = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758
2759 if (arg->ie_len) {
2760 if (!arg->ie)
2761 return -EINVAL;
2762 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
2763 return -EINVAL;
2764
2765 len += sizeof(struct wmi_ie_data);
2766 len += roundup(arg->ie_len, 4);
2767 }
2768
2769 if (arg->n_channels) {
2770 if (!arg->channels)
2771 return -EINVAL;
2772 if (arg->n_channels > ARRAY_SIZE(arg->channels))
2773 return -EINVAL;
2774
2775 len += sizeof(struct wmi_chan_list);
2776 len += sizeof(__le32) * arg->n_channels;
2777 }
2778
2779 if (arg->n_ssids) {
2780 if (!arg->ssids)
2781 return -EINVAL;
2782 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
2783 return -EINVAL;
2784
2785 len += sizeof(struct wmi_ssid_list);
2786 len += sizeof(struct wmi_ssid) * arg->n_ssids;
2787 }
2788
2789 if (arg->n_bssids) {
2790 if (!arg->bssids)
2791 return -EINVAL;
2792 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
2793 return -EINVAL;
2794
2795 len += sizeof(struct wmi_bssid_list);
2796 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
2797 }
2798
2799 return len;
2800}
2801
2802int ath10k_wmi_start_scan(struct ath10k *ar,
2803 const struct wmi_start_scan_arg *arg)
2804{
2805 struct wmi_start_scan_cmd *cmd;
2806 struct sk_buff *skb;
2807 struct wmi_ie_data *ie;
2808 struct wmi_chan_list *channels;
2809 struct wmi_ssid_list *ssids;
2810 struct wmi_bssid_list *bssids;
2811 u32 scan_id;
2812 u32 scan_req_id;
2813 int off;
2814 int len = 0;
2815 int i;
2816
Bartosz Markowski89b7e762013-09-26 17:47:17 +02002817 len = ath10k_wmi_start_scan_calc_len(ar, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002818 if (len < 0)
2819 return len; /* len contains error code here */
2820
2821 skb = ath10k_wmi_alloc_skb(len);
2822 if (!skb)
2823 return -ENOMEM;
2824
2825 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
2826 scan_id |= arg->scan_id;
2827
2828 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
2829 scan_req_id |= arg->scan_req_id;
2830
2831 cmd = (struct wmi_start_scan_cmd *)skb->data;
2832 cmd->scan_id = __cpu_to_le32(scan_id);
2833 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
2834 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2835 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
2836 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
2837 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
2838 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
2839 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
2840 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
2841 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
2842 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
2843 cmd->idle_time = __cpu_to_le32(arg->idle_time);
2844 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
2845 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
2846 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
2847
2848 /* TLV list starts after fields included in the struct */
Bartosz Markowski89b7e762013-09-26 17:47:17 +02002849 /* There's just one filed that differes the two start_scan
2850 * structures - burst_duration, which we are not using btw,
2851 no point to make the split here, just shift the buffer to fit with
2852 given FW */
2853 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2854 off = sizeof(struct wmi_start_scan_cmd_10x);
2855 else
2856 off = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002857
2858 if (arg->n_channels) {
2859 channels = (void *)skb->data + off;
2860 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
2861 channels->num_chan = __cpu_to_le32(arg->n_channels);
2862
2863 for (i = 0; i < arg->n_channels; i++)
2864 channels->channel_list[i] =
2865 __cpu_to_le32(arg->channels[i]);
2866
2867 off += sizeof(*channels);
2868 off += sizeof(__le32) * arg->n_channels;
2869 }
2870
2871 if (arg->n_ssids) {
2872 ssids = (void *)skb->data + off;
2873 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
2874 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
2875
2876 for (i = 0; i < arg->n_ssids; i++) {
2877 ssids->ssids[i].ssid_len =
2878 __cpu_to_le32(arg->ssids[i].len);
2879 memcpy(&ssids->ssids[i].ssid,
2880 arg->ssids[i].ssid,
2881 arg->ssids[i].len);
2882 }
2883
2884 off += sizeof(*ssids);
2885 off += sizeof(struct wmi_ssid) * arg->n_ssids;
2886 }
2887
2888 if (arg->n_bssids) {
2889 bssids = (void *)skb->data + off;
2890 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
2891 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
2892
2893 for (i = 0; i < arg->n_bssids; i++)
2894 memcpy(&bssids->bssid_list[i],
2895 arg->bssids[i].bssid,
2896 ETH_ALEN);
2897
2898 off += sizeof(*bssids);
2899 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
2900 }
2901
2902 if (arg->ie_len) {
2903 ie = (void *)skb->data + off;
2904 ie->tag = __cpu_to_le32(WMI_IE_TAG);
2905 ie->ie_len = __cpu_to_le32(arg->ie_len);
2906 memcpy(ie->ie_data, arg->ie, arg->ie_len);
2907
2908 off += sizeof(*ie);
2909 off += roundup(arg->ie_len, 4);
2910 }
2911
2912 if (off != skb->len) {
2913 dev_kfree_skb(skb);
2914 return -EINVAL;
2915 }
2916
2917 ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02002918 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->start_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002919}
2920
2921void ath10k_wmi_start_scan_init(struct ath10k *ar,
2922 struct wmi_start_scan_arg *arg)
2923{
2924 /* setup commonly used values */
2925 arg->scan_req_id = 1;
2926 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
2927 arg->dwell_time_active = 50;
2928 arg->dwell_time_passive = 150;
2929 arg->min_rest_time = 50;
2930 arg->max_rest_time = 500;
2931 arg->repeat_probe_time = 0;
2932 arg->probe_spacing_time = 0;
2933 arg->idle_time = 0;
Bartosz Markowskic3228922013-10-02 08:48:52 +02002934 arg->max_scan_time = 20000;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002935 arg->probe_delay = 5;
2936 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
2937 | WMI_SCAN_EVENT_COMPLETED
2938 | WMI_SCAN_EVENT_BSS_CHANNEL
2939 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
2940 | WMI_SCAN_EVENT_DEQUEUED;
2941 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
2942 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
2943 arg->n_bssids = 1;
2944 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
2945}
2946
2947int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
2948{
2949 struct wmi_stop_scan_cmd *cmd;
2950 struct sk_buff *skb;
2951 u32 scan_id;
2952 u32 req_id;
2953
2954 if (arg->req_id > 0xFFF)
2955 return -EINVAL;
2956 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
2957 return -EINVAL;
2958
2959 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2960 if (!skb)
2961 return -ENOMEM;
2962
2963 scan_id = arg->u.scan_id;
2964 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
2965
2966 req_id = arg->req_id;
2967 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
2968
2969 cmd = (struct wmi_stop_scan_cmd *)skb->data;
2970 cmd->req_type = __cpu_to_le32(arg->req_type);
2971 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
2972 cmd->scan_id = __cpu_to_le32(scan_id);
2973 cmd->scan_req_id = __cpu_to_le32(req_id);
2974
2975 ath10k_dbg(ATH10K_DBG_WMI,
2976 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
2977 arg->req_id, arg->req_type, arg->u.scan_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02002978 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->stop_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002979}
2980
2981int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
2982 enum wmi_vdev_type type,
2983 enum wmi_vdev_subtype subtype,
2984 const u8 macaddr[ETH_ALEN])
2985{
2986 struct wmi_vdev_create_cmd *cmd;
2987 struct sk_buff *skb;
2988
2989 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2990 if (!skb)
2991 return -ENOMEM;
2992
2993 cmd = (struct wmi_vdev_create_cmd *)skb->data;
2994 cmd->vdev_id = __cpu_to_le32(vdev_id);
2995 cmd->vdev_type = __cpu_to_le32(type);
2996 cmd->vdev_subtype = __cpu_to_le32(subtype);
2997 memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
2998
2999 ath10k_dbg(ATH10K_DBG_WMI,
3000 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
3001 vdev_id, type, subtype, macaddr);
3002
Bartosz Markowskice428702013-09-26 17:47:05 +02003003 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003004}
3005
3006int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
3007{
3008 struct wmi_vdev_delete_cmd *cmd;
3009 struct sk_buff *skb;
3010
3011 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3012 if (!skb)
3013 return -ENOMEM;
3014
3015 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
3016 cmd->vdev_id = __cpu_to_le32(vdev_id);
3017
3018 ath10k_dbg(ATH10K_DBG_WMI,
3019 "WMI vdev delete id %d\n", vdev_id);
3020
Bartosz Markowskice428702013-09-26 17:47:05 +02003021 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003022}
3023
3024static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3025 const struct wmi_vdev_start_request_arg *arg,
Bartosz Markowskice428702013-09-26 17:47:05 +02003026 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003027{
3028 struct wmi_vdev_start_request_cmd *cmd;
3029 struct sk_buff *skb;
3030 const char *cmdname;
3031 u32 flags = 0;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003032 u32 ch_flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003033
Bartosz Markowskice428702013-09-26 17:47:05 +02003034 if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
3035 cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003036 return -EINVAL;
3037 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
3038 return -EINVAL;
3039 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
3040 return -EINVAL;
3041 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
3042 return -EINVAL;
3043
Bartosz Markowskice428702013-09-26 17:47:05 +02003044 if (cmd_id == ar->wmi.cmd->vdev_start_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003045 cmdname = "start";
Bartosz Markowskice428702013-09-26 17:47:05 +02003046 else if (cmd_id == ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003047 cmdname = "restart";
3048 else
3049 return -EINVAL; /* should not happen, we already check cmd_id */
3050
3051 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3052 if (!skb)
3053 return -ENOMEM;
3054
3055 if (arg->hidden_ssid)
3056 flags |= WMI_VDEV_START_HIDDEN_SSID;
3057 if (arg->pmf_enabled)
3058 flags |= WMI_VDEV_START_PMF_ENABLED;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003059 if (arg->channel.chan_radar)
3060 ch_flags |= WMI_CHAN_FLAG_DFS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003061
3062 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
3063 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3064 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
3065 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
3066 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
3067 cmd->flags = __cpu_to_le32(flags);
3068 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
3069 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
3070
3071 if (arg->ssid) {
3072 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
3073 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
3074 }
3075
3076 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
3077
3078 cmd->chan.band_center_freq1 =
3079 __cpu_to_le32(arg->channel.band_center_freq1);
3080
3081 cmd->chan.mode = arg->channel.mode;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003082 cmd->chan.flags |= __cpu_to_le32(ch_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003083 cmd->chan.min_power = arg->channel.min_power;
3084 cmd->chan.max_power = arg->channel.max_power;
3085 cmd->chan.reg_power = arg->channel.max_reg_power;
3086 cmd->chan.reg_classid = arg->channel.reg_class_id;
3087 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
3088
3089 ath10k_dbg(ATH10K_DBG_WMI,
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003090 "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, "
3091 "ch_flags: 0x%0X, max_power: %d\n", cmdname, arg->vdev_id,
3092 flags, arg->channel.freq, arg->channel.mode,
3093 cmd->chan.flags, arg->channel.max_power);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094
3095 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
3096}
3097
3098int ath10k_wmi_vdev_start(struct ath10k *ar,
3099 const struct wmi_vdev_start_request_arg *arg)
3100{
Bartosz Markowskice428702013-09-26 17:47:05 +02003101 u32 cmd_id = ar->wmi.cmd->vdev_start_request_cmdid;
3102
3103 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003104}
3105
3106int ath10k_wmi_vdev_restart(struct ath10k *ar,
3107 const struct wmi_vdev_start_request_arg *arg)
3108{
Bartosz Markowskice428702013-09-26 17:47:05 +02003109 u32 cmd_id = ar->wmi.cmd->vdev_restart_request_cmdid;
3110
3111 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003112}
3113
3114int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
3115{
3116 struct wmi_vdev_stop_cmd *cmd;
3117 struct sk_buff *skb;
3118
3119 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3120 if (!skb)
3121 return -ENOMEM;
3122
3123 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
3124 cmd->vdev_id = __cpu_to_le32(vdev_id);
3125
3126 ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
3127
Bartosz Markowskice428702013-09-26 17:47:05 +02003128 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_stop_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003129}
3130
3131int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
3132{
3133 struct wmi_vdev_up_cmd *cmd;
3134 struct sk_buff *skb;
3135
3136 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3137 if (!skb)
3138 return -ENOMEM;
3139
3140 cmd = (struct wmi_vdev_up_cmd *)skb->data;
3141 cmd->vdev_id = __cpu_to_le32(vdev_id);
3142 cmd->vdev_assoc_id = __cpu_to_le32(aid);
Joe Perches7b4371e2013-10-02 20:39:11 -07003143 memcpy(&cmd->vdev_bssid.addr, bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003144
3145 ath10k_dbg(ATH10K_DBG_WMI,
3146 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
3147 vdev_id, aid, bssid);
3148
Bartosz Markowskice428702013-09-26 17:47:05 +02003149 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_up_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150}
3151
3152int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
3153{
3154 struct wmi_vdev_down_cmd *cmd;
3155 struct sk_buff *skb;
3156
3157 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3158 if (!skb)
3159 return -ENOMEM;
3160
3161 cmd = (struct wmi_vdev_down_cmd *)skb->data;
3162 cmd->vdev_id = __cpu_to_le32(vdev_id);
3163
3164 ath10k_dbg(ATH10K_DBG_WMI,
3165 "wmi mgmt vdev down id 0x%x\n", vdev_id);
3166
Bartosz Markowskice428702013-09-26 17:47:05 +02003167 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_down_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003168}
3169
3170int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003171 u32 param_id, u32 param_value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003172{
3173 struct wmi_vdev_set_param_cmd *cmd;
3174 struct sk_buff *skb;
3175
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003176 if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
3177 ath10k_dbg(ATH10K_DBG_WMI,
3178 "vdev param %d not supported by firmware\n",
3179 param_id);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003180 return -EOPNOTSUPP;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003181 }
3182
Kalle Valo5e3dd152013-06-12 20:52:10 +03003183 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3184 if (!skb)
3185 return -ENOMEM;
3186
3187 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
3188 cmd->vdev_id = __cpu_to_le32(vdev_id);
3189 cmd->param_id = __cpu_to_le32(param_id);
3190 cmd->param_value = __cpu_to_le32(param_value);
3191
3192 ath10k_dbg(ATH10K_DBG_WMI,
3193 "wmi vdev id 0x%x set param %d value %d\n",
3194 vdev_id, param_id, param_value);
3195
Bartosz Markowskice428702013-09-26 17:47:05 +02003196 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197}
3198
3199int ath10k_wmi_vdev_install_key(struct ath10k *ar,
3200 const struct wmi_vdev_install_key_arg *arg)
3201{
3202 struct wmi_vdev_install_key_cmd *cmd;
3203 struct sk_buff *skb;
3204
3205 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
3206 return -EINVAL;
3207 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
3208 return -EINVAL;
3209
3210 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
3211 if (!skb)
3212 return -ENOMEM;
3213
3214 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
3215 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3216 cmd->key_idx = __cpu_to_le32(arg->key_idx);
3217 cmd->key_flags = __cpu_to_le32(arg->key_flags);
3218 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
3219 cmd->key_len = __cpu_to_le32(arg->key_len);
3220 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
3221 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
3222
3223 if (arg->macaddr)
3224 memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
3225 if (arg->key_data)
3226 memcpy(cmd->key_data, arg->key_data, arg->key_len);
3227
Michal Kaziore0c508a2013-07-05 16:15:17 +03003228 ath10k_dbg(ATH10K_DBG_WMI,
3229 "wmi vdev install key idx %d cipher %d len %d\n",
3230 arg->key_idx, arg->key_cipher, arg->key_len);
Bartosz Markowskice428702013-09-26 17:47:05 +02003231 return ath10k_wmi_cmd_send(ar, skb,
3232 ar->wmi.cmd->vdev_install_key_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233}
3234
3235int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
3236 const u8 peer_addr[ETH_ALEN])
3237{
3238 struct wmi_peer_create_cmd *cmd;
3239 struct sk_buff *skb;
3240
3241 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3242 if (!skb)
3243 return -ENOMEM;
3244
3245 cmd = (struct wmi_peer_create_cmd *)skb->data;
3246 cmd->vdev_id = __cpu_to_le32(vdev_id);
3247 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3248
3249 ath10k_dbg(ATH10K_DBG_WMI,
3250 "wmi peer create vdev_id %d peer_addr %pM\n",
3251 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003252 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003253}
3254
3255int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
3256 const u8 peer_addr[ETH_ALEN])
3257{
3258 struct wmi_peer_delete_cmd *cmd;
3259 struct sk_buff *skb;
3260
3261 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3262 if (!skb)
3263 return -ENOMEM;
3264
3265 cmd = (struct wmi_peer_delete_cmd *)skb->data;
3266 cmd->vdev_id = __cpu_to_le32(vdev_id);
3267 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3268
3269 ath10k_dbg(ATH10K_DBG_WMI,
3270 "wmi peer delete vdev_id %d peer_addr %pM\n",
3271 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003272 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003273}
3274
3275int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
3276 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
3277{
3278 struct wmi_peer_flush_tids_cmd *cmd;
3279 struct sk_buff *skb;
3280
3281 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3282 if (!skb)
3283 return -ENOMEM;
3284
3285 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
3286 cmd->vdev_id = __cpu_to_le32(vdev_id);
3287 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
3288 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3289
3290 ath10k_dbg(ATH10K_DBG_WMI,
3291 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
3292 vdev_id, peer_addr, tid_bitmap);
Bartosz Markowskice428702013-09-26 17:47:05 +02003293 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_flush_tids_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294}
3295
3296int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
3297 const u8 *peer_addr, enum wmi_peer_param param_id,
3298 u32 param_value)
3299{
3300 struct wmi_peer_set_param_cmd *cmd;
3301 struct sk_buff *skb;
3302
3303 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3304 if (!skb)
3305 return -ENOMEM;
3306
3307 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
3308 cmd->vdev_id = __cpu_to_le32(vdev_id);
3309 cmd->param_id = __cpu_to_le32(param_id);
3310 cmd->param_value = __cpu_to_le32(param_value);
Joe Perchesd458cdf2013-10-01 19:04:40 -07003311 memcpy(&cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003312
3313 ath10k_dbg(ATH10K_DBG_WMI,
3314 "wmi vdev %d peer 0x%pM set param %d value %d\n",
3315 vdev_id, peer_addr, param_id, param_value);
3316
Bartosz Markowskice428702013-09-26 17:47:05 +02003317 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003318}
3319
3320int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
3321 enum wmi_sta_ps_mode psmode)
3322{
3323 struct wmi_sta_powersave_mode_cmd *cmd;
3324 struct sk_buff *skb;
3325
3326 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3327 if (!skb)
3328 return -ENOMEM;
3329
3330 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
3331 cmd->vdev_id = __cpu_to_le32(vdev_id);
3332 cmd->sta_ps_mode = __cpu_to_le32(psmode);
3333
3334 ath10k_dbg(ATH10K_DBG_WMI,
3335 "wmi set powersave id 0x%x mode %d\n",
3336 vdev_id, psmode);
3337
Bartosz Markowskice428702013-09-26 17:47:05 +02003338 return ath10k_wmi_cmd_send(ar, skb,
3339 ar->wmi.cmd->sta_powersave_mode_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003340}
3341
3342int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
3343 enum wmi_sta_powersave_param param_id,
3344 u32 value)
3345{
3346 struct wmi_sta_powersave_param_cmd *cmd;
3347 struct sk_buff *skb;
3348
3349 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3350 if (!skb)
3351 return -ENOMEM;
3352
3353 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
3354 cmd->vdev_id = __cpu_to_le32(vdev_id);
3355 cmd->param_id = __cpu_to_le32(param_id);
3356 cmd->param_value = __cpu_to_le32(value);
3357
3358 ath10k_dbg(ATH10K_DBG_WMI,
3359 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
3360 vdev_id, param_id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02003361 return ath10k_wmi_cmd_send(ar, skb,
3362 ar->wmi.cmd->sta_powersave_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003363}
3364
3365int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
3366 enum wmi_ap_ps_peer_param param_id, u32 value)
3367{
3368 struct wmi_ap_ps_peer_cmd *cmd;
3369 struct sk_buff *skb;
3370
3371 if (!mac)
3372 return -EINVAL;
3373
3374 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3375 if (!skb)
3376 return -ENOMEM;
3377
3378 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
3379 cmd->vdev_id = __cpu_to_le32(vdev_id);
3380 cmd->param_id = __cpu_to_le32(param_id);
3381 cmd->param_value = __cpu_to_le32(value);
3382 memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
3383
3384 ath10k_dbg(ATH10K_DBG_WMI,
3385 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
3386 vdev_id, param_id, value, mac);
3387
Bartosz Markowskice428702013-09-26 17:47:05 +02003388 return ath10k_wmi_cmd_send(ar, skb,
3389 ar->wmi.cmd->ap_ps_peer_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003390}
3391
3392int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3393 const struct wmi_scan_chan_list_arg *arg)
3394{
3395 struct wmi_scan_chan_list_cmd *cmd;
3396 struct sk_buff *skb;
3397 struct wmi_channel_arg *ch;
3398 struct wmi_channel *ci;
3399 int len;
3400 int i;
3401
3402 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
3403
3404 skb = ath10k_wmi_alloc_skb(len);
3405 if (!skb)
3406 return -EINVAL;
3407
3408 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
3409 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3410
3411 for (i = 0; i < arg->n_channels; i++) {
3412 u32 flags = 0;
3413
3414 ch = &arg->channels[i];
3415 ci = &cmd->chan_info[i];
3416
3417 if (ch->passive)
3418 flags |= WMI_CHAN_FLAG_PASSIVE;
3419 if (ch->allow_ibss)
3420 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
3421 if (ch->allow_ht)
3422 flags |= WMI_CHAN_FLAG_ALLOW_HT;
3423 if (ch->allow_vht)
3424 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
3425 if (ch->ht40plus)
3426 flags |= WMI_CHAN_FLAG_HT40_PLUS;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003427 if (ch->chan_radar)
3428 flags |= WMI_CHAN_FLAG_DFS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003429
3430 ci->mhz = __cpu_to_le32(ch->freq);
3431 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
3432 ci->band_center_freq2 = 0;
3433 ci->min_power = ch->min_power;
3434 ci->max_power = ch->max_power;
3435 ci->reg_power = ch->max_reg_power;
3436 ci->antenna_max = ch->max_antenna_gain;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003437
3438 /* mode & flags share storage */
3439 ci->mode = ch->mode;
3440 ci->flags |= __cpu_to_le32(flags);
3441 }
3442
Bartosz Markowskice428702013-09-26 17:47:05 +02003443 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003444}
3445
3446int ath10k_wmi_peer_assoc(struct ath10k *ar,
3447 const struct wmi_peer_assoc_complete_arg *arg)
3448{
3449 struct wmi_peer_assoc_complete_cmd *cmd;
3450 struct sk_buff *skb;
3451
3452 if (arg->peer_mpdu_density > 16)
3453 return -EINVAL;
3454 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
3455 return -EINVAL;
3456 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
3457 return -EINVAL;
3458
3459 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3460 if (!skb)
3461 return -ENOMEM;
3462
3463 cmd = (struct wmi_peer_assoc_complete_cmd *)skb->data;
3464 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3465 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
3466 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
3467 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
3468 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
3469 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
3470 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
3471 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
3472 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
3473 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
3474 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
3475 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
3476 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
3477
3478 memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
3479
3480 cmd->peer_legacy_rates.num_rates =
3481 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
3482 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
3483 arg->peer_legacy_rates.num_rates);
3484
3485 cmd->peer_ht_rates.num_rates =
3486 __cpu_to_le32(arg->peer_ht_rates.num_rates);
3487 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
3488 arg->peer_ht_rates.num_rates);
3489
3490 cmd->peer_vht_rates.rx_max_rate =
3491 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
3492 cmd->peer_vht_rates.rx_mcs_set =
3493 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
3494 cmd->peer_vht_rates.tx_max_rate =
3495 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
3496 cmd->peer_vht_rates.tx_mcs_set =
3497 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
3498
Michal Kaziore0c508a2013-07-05 16:15:17 +03003499 ath10k_dbg(ATH10K_DBG_WMI,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003500 "wmi peer assoc vdev %d addr %pM (%s)\n",
3501 arg->vdev_id, arg->addr,
3502 arg->peer_reassoc ? "reassociate" : "new");
Bartosz Markowskice428702013-09-26 17:47:05 +02003503 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_assoc_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003504}
3505
Michal Kazior748afc42014-01-23 12:48:21 +01003506/* This function assumes the beacon is already DMA mapped */
3507int ath10k_wmi_beacon_send_ref_nowait(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003508{
Michal Kazior748afc42014-01-23 12:48:21 +01003509 struct wmi_bcn_tx_ref_cmd *cmd;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003510 struct sk_buff *skb;
Michal Kazior748afc42014-01-23 12:48:21 +01003511 struct sk_buff *beacon = arvif->beacon;
3512 struct ath10k *ar = arvif->ar;
3513 struct ieee80211_hdr *hdr;
Michal Kaziore2045482013-10-28 07:18:14 +01003514 int ret;
Michal Kazior748afc42014-01-23 12:48:21 +01003515 u16 fc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003516
Michal Kazior748afc42014-01-23 12:48:21 +01003517 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518 if (!skb)
3519 return -ENOMEM;
3520
Michal Kazior748afc42014-01-23 12:48:21 +01003521 hdr = (struct ieee80211_hdr *)beacon->data;
3522 fc = le16_to_cpu(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003523
Michal Kazior748afc42014-01-23 12:48:21 +01003524 cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
3525 cmd->vdev_id = __cpu_to_le32(arvif->vdev_id);
3526 cmd->data_len = __cpu_to_le32(beacon->len);
3527 cmd->data_ptr = __cpu_to_le32(ATH10K_SKB_CB(beacon)->paddr);
3528 cmd->msdu_id = 0;
3529 cmd->frame_control = __cpu_to_le32(fc);
3530 cmd->flags = 0;
3531
3532 if (ATH10K_SKB_CB(beacon)->bcn.dtim_zero)
3533 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
3534
3535 if (ATH10K_SKB_CB(beacon)->bcn.deliver_cab)
3536 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
3537
3538 ret = ath10k_wmi_cmd_send_nowait(ar, skb,
3539 ar->wmi.cmd->pdev_send_bcn_cmdid);
3540
Michal Kaziore2045482013-10-28 07:18:14 +01003541 if (ret)
3542 dev_kfree_skb(skb);
3543
3544 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003545}
3546
3547static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
3548 const struct wmi_wmm_params_arg *arg)
3549{
3550 params->cwmin = __cpu_to_le32(arg->cwmin);
3551 params->cwmax = __cpu_to_le32(arg->cwmax);
3552 params->aifs = __cpu_to_le32(arg->aifs);
3553 params->txop = __cpu_to_le32(arg->txop);
3554 params->acm = __cpu_to_le32(arg->acm);
3555 params->no_ack = __cpu_to_le32(arg->no_ack);
3556}
3557
3558int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
3559 const struct wmi_pdev_set_wmm_params_arg *arg)
3560{
3561 struct wmi_pdev_set_wmm_params *cmd;
3562 struct sk_buff *skb;
3563
3564 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3565 if (!skb)
3566 return -ENOMEM;
3567
3568 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
3569 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
3570 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
3571 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
3572 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
3573
3574 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003575 return ath10k_wmi_cmd_send(ar, skb,
3576 ar->wmi.cmd->pdev_set_wmm_params_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577}
3578
3579int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
3580{
3581 struct wmi_request_stats_cmd *cmd;
3582 struct sk_buff *skb;
3583
3584 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3585 if (!skb)
3586 return -ENOMEM;
3587
3588 cmd = (struct wmi_request_stats_cmd *)skb->data;
3589 cmd->stats_id = __cpu_to_le32(stats_id);
3590
3591 ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02003592 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->request_stats_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003593}
Michal Kazior9cfbce72013-07-16 09:54:36 +02003594
3595int ath10k_wmi_force_fw_hang(struct ath10k *ar,
3596 enum wmi_force_fw_hang_type type, u32 delay_ms)
3597{
3598 struct wmi_force_fw_hang_cmd *cmd;
3599 struct sk_buff *skb;
3600
3601 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3602 if (!skb)
3603 return -ENOMEM;
3604
3605 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
3606 cmd->type = __cpu_to_le32(type);
3607 cmd->delay_ms = __cpu_to_le32(delay_ms);
3608
3609 ath10k_dbg(ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
3610 type, delay_ms);
Bartosz Markowskice428702013-09-26 17:47:05 +02003611 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
Michal Kazior9cfbce72013-07-16 09:54:36 +02003612}
Kalle Valof118a3e2014-01-03 12:59:31 +02003613
3614int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable)
3615{
3616 struct wmi_dbglog_cfg_cmd *cmd;
3617 struct sk_buff *skb;
3618 u32 cfg;
3619
3620 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3621 if (!skb)
3622 return -ENOMEM;
3623
3624 cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
3625
3626 if (module_enable) {
3627 cfg = SM(ATH10K_DBGLOG_LEVEL_VERBOSE,
3628 ATH10K_DBGLOG_CFG_LOG_LVL);
3629 } else {
3630 /* set back defaults, all modules with WARN level */
3631 cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
3632 ATH10K_DBGLOG_CFG_LOG_LVL);
3633 module_enable = ~0;
3634 }
3635
3636 cmd->module_enable = __cpu_to_le32(module_enable);
3637 cmd->module_valid = __cpu_to_le32(~0);
3638 cmd->config_enable = __cpu_to_le32(cfg);
3639 cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
3640
3641 ath10k_dbg(ATH10K_DBG_WMI,
3642 "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
3643 __le32_to_cpu(cmd->module_enable),
3644 __le32_to_cpu(cmd->module_valid),
3645 __le32_to_cpu(cmd->config_enable),
3646 __le32_to_cpu(cmd->config_valid));
3647
3648 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid);
3649}