blob: 23acbadeb8fa4f17fd98124ce6a0b8b8ea51b7ae [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
Michal Kazior24c88f72014-07-25 13:32:17 +0200490/* firmware 10.2 specific mappings */
491static struct wmi_cmd_map wmi_10_2_cmd_map = {
492 .init_cmdid = WMI_10_2_INIT_CMDID,
493 .start_scan_cmdid = WMI_10_2_START_SCAN_CMDID,
494 .stop_scan_cmdid = WMI_10_2_STOP_SCAN_CMDID,
495 .scan_chan_list_cmdid = WMI_10_2_SCAN_CHAN_LIST_CMDID,
496 .scan_sch_prio_tbl_cmdid = WMI_CMD_UNSUPPORTED,
497 .pdev_set_regdomain_cmdid = WMI_10_2_PDEV_SET_REGDOMAIN_CMDID,
498 .pdev_set_channel_cmdid = WMI_10_2_PDEV_SET_CHANNEL_CMDID,
499 .pdev_set_param_cmdid = WMI_10_2_PDEV_SET_PARAM_CMDID,
500 .pdev_pktlog_enable_cmdid = WMI_10_2_PDEV_PKTLOG_ENABLE_CMDID,
501 .pdev_pktlog_disable_cmdid = WMI_10_2_PDEV_PKTLOG_DISABLE_CMDID,
502 .pdev_set_wmm_params_cmdid = WMI_10_2_PDEV_SET_WMM_PARAMS_CMDID,
503 .pdev_set_ht_cap_ie_cmdid = WMI_10_2_PDEV_SET_HT_CAP_IE_CMDID,
504 .pdev_set_vht_cap_ie_cmdid = WMI_10_2_PDEV_SET_VHT_CAP_IE_CMDID,
505 .pdev_set_quiet_mode_cmdid = WMI_10_2_PDEV_SET_QUIET_MODE_CMDID,
506 .pdev_green_ap_ps_enable_cmdid = WMI_10_2_PDEV_GREEN_AP_PS_ENABLE_CMDID,
507 .pdev_get_tpc_config_cmdid = WMI_10_2_PDEV_GET_TPC_CONFIG_CMDID,
508 .pdev_set_base_macaddr_cmdid = WMI_10_2_PDEV_SET_BASE_MACADDR_CMDID,
509 .vdev_create_cmdid = WMI_10_2_VDEV_CREATE_CMDID,
510 .vdev_delete_cmdid = WMI_10_2_VDEV_DELETE_CMDID,
511 .vdev_start_request_cmdid = WMI_10_2_VDEV_START_REQUEST_CMDID,
512 .vdev_restart_request_cmdid = WMI_10_2_VDEV_RESTART_REQUEST_CMDID,
513 .vdev_up_cmdid = WMI_10_2_VDEV_UP_CMDID,
514 .vdev_stop_cmdid = WMI_10_2_VDEV_STOP_CMDID,
515 .vdev_down_cmdid = WMI_10_2_VDEV_DOWN_CMDID,
516 .vdev_set_param_cmdid = WMI_10_2_VDEV_SET_PARAM_CMDID,
517 .vdev_install_key_cmdid = WMI_10_2_VDEV_INSTALL_KEY_CMDID,
518 .peer_create_cmdid = WMI_10_2_PEER_CREATE_CMDID,
519 .peer_delete_cmdid = WMI_10_2_PEER_DELETE_CMDID,
520 .peer_flush_tids_cmdid = WMI_10_2_PEER_FLUSH_TIDS_CMDID,
521 .peer_set_param_cmdid = WMI_10_2_PEER_SET_PARAM_CMDID,
522 .peer_assoc_cmdid = WMI_10_2_PEER_ASSOC_CMDID,
523 .peer_add_wds_entry_cmdid = WMI_10_2_PEER_ADD_WDS_ENTRY_CMDID,
524 .peer_remove_wds_entry_cmdid = WMI_10_2_PEER_REMOVE_WDS_ENTRY_CMDID,
525 .peer_mcast_group_cmdid = WMI_10_2_PEER_MCAST_GROUP_CMDID,
526 .bcn_tx_cmdid = WMI_10_2_BCN_TX_CMDID,
527 .pdev_send_bcn_cmdid = WMI_10_2_PDEV_SEND_BCN_CMDID,
528 .bcn_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
529 .bcn_filter_rx_cmdid = WMI_10_2_BCN_FILTER_RX_CMDID,
530 .prb_req_filter_rx_cmdid = WMI_10_2_PRB_REQ_FILTER_RX_CMDID,
531 .mgmt_tx_cmdid = WMI_10_2_MGMT_TX_CMDID,
532 .prb_tmpl_cmdid = WMI_CMD_UNSUPPORTED,
533 .addba_clear_resp_cmdid = WMI_10_2_ADDBA_CLEAR_RESP_CMDID,
534 .addba_send_cmdid = WMI_10_2_ADDBA_SEND_CMDID,
535 .addba_status_cmdid = WMI_10_2_ADDBA_STATUS_CMDID,
536 .delba_send_cmdid = WMI_10_2_DELBA_SEND_CMDID,
537 .addba_set_resp_cmdid = WMI_10_2_ADDBA_SET_RESP_CMDID,
538 .send_singleamsdu_cmdid = WMI_10_2_SEND_SINGLEAMSDU_CMDID,
539 .sta_powersave_mode_cmdid = WMI_10_2_STA_POWERSAVE_MODE_CMDID,
540 .sta_powersave_param_cmdid = WMI_10_2_STA_POWERSAVE_PARAM_CMDID,
541 .sta_mimo_ps_mode_cmdid = WMI_10_2_STA_MIMO_PS_MODE_CMDID,
542 .pdev_dfs_enable_cmdid = WMI_10_2_PDEV_DFS_ENABLE_CMDID,
543 .pdev_dfs_disable_cmdid = WMI_10_2_PDEV_DFS_DISABLE_CMDID,
544 .roam_scan_mode = WMI_10_2_ROAM_SCAN_MODE,
545 .roam_scan_rssi_threshold = WMI_10_2_ROAM_SCAN_RSSI_THRESHOLD,
546 .roam_scan_period = WMI_10_2_ROAM_SCAN_PERIOD,
547 .roam_scan_rssi_change_threshold =
548 WMI_10_2_ROAM_SCAN_RSSI_CHANGE_THRESHOLD,
549 .roam_ap_profile = WMI_10_2_ROAM_AP_PROFILE,
550 .ofl_scan_add_ap_profile = WMI_10_2_OFL_SCAN_ADD_AP_PROFILE,
551 .ofl_scan_remove_ap_profile = WMI_10_2_OFL_SCAN_REMOVE_AP_PROFILE,
552 .ofl_scan_period = WMI_10_2_OFL_SCAN_PERIOD,
553 .p2p_dev_set_device_info = WMI_10_2_P2P_DEV_SET_DEVICE_INFO,
554 .p2p_dev_set_discoverability = WMI_10_2_P2P_DEV_SET_DISCOVERABILITY,
555 .p2p_go_set_beacon_ie = WMI_10_2_P2P_GO_SET_BEACON_IE,
556 .p2p_go_set_probe_resp_ie = WMI_10_2_P2P_GO_SET_PROBE_RESP_IE,
557 .p2p_set_vendor_ie_data_cmdid = WMI_CMD_UNSUPPORTED,
558 .ap_ps_peer_param_cmdid = WMI_10_2_AP_PS_PEER_PARAM_CMDID,
559 .ap_ps_peer_uapsd_coex_cmdid = WMI_CMD_UNSUPPORTED,
560 .peer_rate_retry_sched_cmdid = WMI_10_2_PEER_RATE_RETRY_SCHED_CMDID,
561 .wlan_profile_trigger_cmdid = WMI_10_2_WLAN_PROFILE_TRIGGER_CMDID,
562 .wlan_profile_set_hist_intvl_cmdid =
563 WMI_10_2_WLAN_PROFILE_SET_HIST_INTVL_CMDID,
564 .wlan_profile_get_profile_data_cmdid =
565 WMI_10_2_WLAN_PROFILE_GET_PROFILE_DATA_CMDID,
566 .wlan_profile_enable_profile_id_cmdid =
567 WMI_10_2_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID,
568 .wlan_profile_list_profile_id_cmdid =
569 WMI_10_2_WLAN_PROFILE_LIST_PROFILE_ID_CMDID,
570 .pdev_suspend_cmdid = WMI_10_2_PDEV_SUSPEND_CMDID,
571 .pdev_resume_cmdid = WMI_10_2_PDEV_RESUME_CMDID,
572 .add_bcn_filter_cmdid = WMI_10_2_ADD_BCN_FILTER_CMDID,
573 .rmv_bcn_filter_cmdid = WMI_10_2_RMV_BCN_FILTER_CMDID,
574 .wow_add_wake_pattern_cmdid = WMI_10_2_WOW_ADD_WAKE_PATTERN_CMDID,
575 .wow_del_wake_pattern_cmdid = WMI_10_2_WOW_DEL_WAKE_PATTERN_CMDID,
576 .wow_enable_disable_wake_event_cmdid =
577 WMI_10_2_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID,
578 .wow_enable_cmdid = WMI_10_2_WOW_ENABLE_CMDID,
579 .wow_hostwakeup_from_sleep_cmdid =
580 WMI_10_2_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID,
581 .rtt_measreq_cmdid = WMI_10_2_RTT_MEASREQ_CMDID,
582 .rtt_tsf_cmdid = WMI_10_2_RTT_TSF_CMDID,
583 .vdev_spectral_scan_configure_cmdid =
584 WMI_10_2_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID,
585 .vdev_spectral_scan_enable_cmdid =
586 WMI_10_2_VDEV_SPECTRAL_SCAN_ENABLE_CMDID,
587 .request_stats_cmdid = WMI_10_2_REQUEST_STATS_CMDID,
588 .set_arp_ns_offload_cmdid = WMI_CMD_UNSUPPORTED,
589 .network_list_offload_config_cmdid = WMI_CMD_UNSUPPORTED,
590 .gtk_offload_cmdid = WMI_CMD_UNSUPPORTED,
591 .csa_offload_enable_cmdid = WMI_CMD_UNSUPPORTED,
592 .csa_offload_chanswitch_cmdid = WMI_CMD_UNSUPPORTED,
593 .chatter_set_mode_cmdid = WMI_CMD_UNSUPPORTED,
594 .peer_tid_addba_cmdid = WMI_CMD_UNSUPPORTED,
595 .peer_tid_delba_cmdid = WMI_CMD_UNSUPPORTED,
596 .sta_dtim_ps_method_cmdid = WMI_CMD_UNSUPPORTED,
597 .sta_uapsd_auto_trig_cmdid = WMI_CMD_UNSUPPORTED,
598 .sta_keepalive_cmd = WMI_CMD_UNSUPPORTED,
599 .echo_cmdid = WMI_10_2_ECHO_CMDID,
600 .pdev_utf_cmdid = WMI_10_2_PDEV_UTF_CMDID,
601 .dbglog_cfg_cmdid = WMI_10_2_DBGLOG_CFG_CMDID,
602 .pdev_qvit_cmdid = WMI_10_2_PDEV_QVIT_CMDID,
603 .pdev_ftm_intg_cmdid = WMI_CMD_UNSUPPORTED,
604 .vdev_set_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
605 .vdev_get_keepalive_cmdid = WMI_CMD_UNSUPPORTED,
606 .force_fw_hang_cmdid = WMI_CMD_UNSUPPORTED,
607 .gpio_config_cmdid = WMI_10_2_GPIO_CONFIG_CMDID,
608 .gpio_output_cmdid = WMI_10_2_GPIO_OUTPUT_CMDID,
609};
610
Kalle Valo5e3dd152013-06-12 20:52:10 +0300611int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
612{
613 int ret;
614 ret = wait_for_completion_timeout(&ar->wmi.service_ready,
615 WMI_SERVICE_READY_TIMEOUT_HZ);
616 return ret;
617}
618
619int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
620{
621 int ret;
622 ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
623 WMI_UNIFIED_READY_TIMEOUT_HZ);
624 return ret;
625}
626
627static struct sk_buff *ath10k_wmi_alloc_skb(u32 len)
628{
629 struct sk_buff *skb;
630 u32 round_len = roundup(len, 4);
631
632 skb = ath10k_htc_alloc_skb(WMI_SKB_HEADROOM + round_len);
633 if (!skb)
634 return NULL;
635
636 skb_reserve(skb, WMI_SKB_HEADROOM);
637 if (!IS_ALIGNED((unsigned long)skb->data, 4))
638 ath10k_warn("Unaligned WMI skb\n");
639
640 skb_put(skb, round_len);
641 memset(skb->data, 0, round_len);
642
643 return skb;
644}
645
646static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
647{
648 dev_kfree_skb(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649}
650
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200651static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
Bartosz Markowskice428702013-09-26 17:47:05 +0200652 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300653{
654 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
655 struct wmi_cmd_hdr *cmd_hdr;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200656 int ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300657 u32 cmd = 0;
658
659 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
660 return -ENOMEM;
661
662 cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
663
664 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
665 cmd_hdr->cmd_id = __cpu_to_le32(cmd);
666
Kalle Valo5e3dd152013-06-12 20:52:10 +0300667 memset(skb_cb, 0, sizeof(*skb_cb));
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200668 ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
669 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300670
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200671 if (ret)
672 goto err_pull;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300673
674 return 0;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200675
676err_pull:
677 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
678 return ret;
679}
680
Michal Kaziored543882013-09-13 14:16:56 +0200681static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
682{
Michal Kaziored543882013-09-13 14:16:56 +0200683 int ret;
684
685 lockdep_assert_held(&arvif->ar->data_lock);
686
687 if (arvif->beacon == NULL)
688 return;
689
Michal Kazior748afc42014-01-23 12:48:21 +0100690 if (arvif->beacon_sent)
691 return;
Michal Kaziored543882013-09-13 14:16:56 +0200692
Michal Kazior748afc42014-01-23 12:48:21 +0100693 ret = ath10k_wmi_beacon_send_ref_nowait(arvif);
Michal Kaziored543882013-09-13 14:16:56 +0200694 if (ret)
695 return;
696
Michal Kazior748afc42014-01-23 12:48:21 +0100697 /* We need to retain the arvif->beacon reference for DMA unmapping and
698 * freeing the skbuff later. */
699 arvif->beacon_sent = true;
Michal Kaziored543882013-09-13 14:16:56 +0200700}
701
702static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
703 struct ieee80211_vif *vif)
704{
705 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
706
707 ath10k_wmi_tx_beacon_nowait(arvif);
708}
709
710static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
711{
712 spin_lock_bh(&ar->data_lock);
713 ieee80211_iterate_active_interfaces_atomic(ar->hw,
714 IEEE80211_IFACE_ITER_NORMAL,
715 ath10k_wmi_tx_beacons_iter,
716 NULL);
717 spin_unlock_bh(&ar->data_lock);
718}
719
Michal Kazior12acbc42013-09-13 14:16:55 +0200720static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200721{
Michal Kaziored543882013-09-13 14:16:56 +0200722 /* try to send pending beacons first. they take priority */
723 ath10k_wmi_tx_beacons_nowait(ar);
724
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200725 wake_up(&ar->wmi.tx_credits_wq);
726}
727
728static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
Bartosz Markowskice428702013-09-26 17:47:05 +0200729 u32 cmd_id)
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200730{
Bartosz Markowski34957b22013-10-15 09:55:31 +0200731 int ret = -EOPNOTSUPP;
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200732
Kalle Valo56b84282013-10-16 15:44:47 +0300733 might_sleep();
734
Bartosz Markowski34957b22013-10-15 09:55:31 +0200735 if (cmd_id == WMI_CMD_UNSUPPORTED) {
Bartosz Markowski55321552013-09-26 17:47:07 +0200736 ath10k_warn("wmi command %d is not supported by firmware\n",
737 cmd_id);
738 return ret;
739 }
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200740
741 wait_event_timeout(ar->wmi.tx_credits_wq, ({
Michal Kaziored543882013-09-13 14:16:56 +0200742 /* try to send pending beacons first. they take priority */
743 ath10k_wmi_tx_beacons_nowait(ar);
744
Michal Kaziorbe8b3942013-09-13 14:16:54 +0200745 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
746 (ret != -EAGAIN);
747 }), 3*HZ);
748
749 if (ret)
750 dev_kfree_skb_any(skb);
751
752 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300753}
754
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200755int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
756{
757 int ret = 0;
758 struct wmi_mgmt_tx_cmd *cmd;
759 struct ieee80211_hdr *hdr;
760 struct sk_buff *wmi_skb;
761 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
762 int len;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +0300763 u32 buf_len = skb->len;
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200764 u16 fc;
765
766 hdr = (struct ieee80211_hdr *)skb->data;
767 fc = le16_to_cpu(hdr->frame_control);
768
769 if (WARN_ON_ONCE(!ieee80211_is_mgmt(hdr->frame_control)))
770 return -EINVAL;
771
772 len = sizeof(cmd->hdr) + skb->len;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +0300773
774 if ((ieee80211_is_action(hdr->frame_control) ||
775 ieee80211_is_deauth(hdr->frame_control) ||
776 ieee80211_is_disassoc(hdr->frame_control)) &&
777 ieee80211_has_protected(hdr->frame_control)) {
778 len += IEEE80211_CCMP_MIC_LEN;
779 buf_len += IEEE80211_CCMP_MIC_LEN;
780 }
781
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200782 len = round_up(len, 4);
783
784 wmi_skb = ath10k_wmi_alloc_skb(len);
785 if (!wmi_skb)
786 return -ENOMEM;
787
788 cmd = (struct wmi_mgmt_tx_cmd *)wmi_skb->data;
789
790 cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id);
791 cmd->hdr.tx_rate = 0;
792 cmd->hdr.tx_power = 0;
Marek Kwaczynskieeab2662014-05-14 16:56:17 +0300793 cmd->hdr.buf_len = __cpu_to_le32(buf_len);
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200794
795 memcpy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr), ETH_ALEN);
796 memcpy(cmd->buf, skb->data, skb->len);
797
798 ath10k_dbg(ATH10K_DBG_WMI, "wmi mgmt tx skb %p len %d ftype %02x stype %02x\n",
799 wmi_skb, wmi_skb->len, fc & IEEE80211_FCTL_FTYPE,
800 fc & IEEE80211_FCTL_STYPE);
801
802 /* Send the management frame buffer to the target */
803 ret = ath10k_wmi_cmd_send(ar, wmi_skb, ar->wmi.cmd->mgmt_tx_cmdid);
Michal Kazior5fb5e412013-10-28 07:18:13 +0100804 if (ret)
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200805 return ret;
Bartosz Markowski5e00d312013-09-26 17:47:12 +0200806
807 /* TODO: report tx status to mac80211 - temporary just ACK */
808 info->flags |= IEEE80211_TX_STAT_ACK;
809 ieee80211_tx_status_irqsafe(ar->hw, skb);
810
811 return ret;
812}
813
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200814static void ath10k_wmi_event_scan_started(struct ath10k *ar)
815{
816 lockdep_assert_held(&ar->data_lock);
817
818 switch (ar->scan.state) {
819 case ATH10K_SCAN_IDLE:
820 case ATH10K_SCAN_RUNNING:
821 case ATH10K_SCAN_ABORTING:
822 ath10k_warn("received scan started event in an invalid scan state: %s (%d)\n",
823 ath10k_scan_state_str(ar->scan.state),
824 ar->scan.state);
825 break;
826 case ATH10K_SCAN_STARTING:
827 ar->scan.state = ATH10K_SCAN_RUNNING;
828
829 if (ar->scan.is_roc)
830 ieee80211_ready_on_channel(ar->hw);
831
832 complete(&ar->scan.started);
833 break;
834 }
835}
836
837static void ath10k_wmi_event_scan_completed(struct ath10k *ar)
838{
839 lockdep_assert_held(&ar->data_lock);
840
841 switch (ar->scan.state) {
842 case ATH10K_SCAN_IDLE:
843 case ATH10K_SCAN_STARTING:
844 /* One suspected reason scan can be completed while starting is
845 * if firmware fails to deliver all scan events to the host,
846 * e.g. when transport pipe is full. This has been observed
847 * with spectral scan phyerr events starving wmi transport
848 * pipe. In such case the "scan completed" event should be (and
849 * is) ignored by the host as it may be just firmware's scan
850 * state machine recovering.
851 */
852 ath10k_warn("received scan completed event in an invalid scan state: %s (%d)\n",
853 ath10k_scan_state_str(ar->scan.state),
854 ar->scan.state);
855 break;
856 case ATH10K_SCAN_RUNNING:
857 case ATH10K_SCAN_ABORTING:
858 __ath10k_scan_finish(ar);
859 break;
860 }
861}
862
863static void ath10k_wmi_event_scan_bss_chan(struct ath10k *ar)
864{
865 lockdep_assert_held(&ar->data_lock);
866
867 switch (ar->scan.state) {
868 case ATH10K_SCAN_IDLE:
869 case ATH10K_SCAN_STARTING:
870 ath10k_warn("received scan bss chan event in an invalid scan state: %s (%d)\n",
871 ath10k_scan_state_str(ar->scan.state),
872 ar->scan.state);
873 break;
874 case ATH10K_SCAN_RUNNING:
875 case ATH10K_SCAN_ABORTING:
876 ar->scan_channel = NULL;
877 break;
878 }
879}
880
881static void ath10k_wmi_event_scan_foreign_chan(struct ath10k *ar, u32 freq)
882{
883 lockdep_assert_held(&ar->data_lock);
884
885 switch (ar->scan.state) {
886 case ATH10K_SCAN_IDLE:
887 case ATH10K_SCAN_STARTING:
888 ath10k_warn("received scan foreign chan event in an invalid scan state: %s (%d)\n",
889 ath10k_scan_state_str(ar->scan.state),
890 ar->scan.state);
891 break;
892 case ATH10K_SCAN_RUNNING:
893 case ATH10K_SCAN_ABORTING:
894 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
895
896 if (ar->scan.is_roc && ar->scan.roc_freq == freq)
897 complete(&ar->scan.on_channel);
898 break;
899 }
900}
901
Michal Kazior9ff8b722014-08-05 14:54:43 +0200902static const char *
903ath10k_wmi_event_scan_type_str(enum wmi_scan_event_type type,
904 enum wmi_scan_completion_reason reason)
905{
906 switch (type) {
907 case WMI_SCAN_EVENT_STARTED:
908 return "started";
909 case WMI_SCAN_EVENT_COMPLETED:
910 switch (reason) {
911 case WMI_SCAN_REASON_COMPLETED:
912 return "completed";
913 case WMI_SCAN_REASON_CANCELLED:
914 return "completed [cancelled]";
915 case WMI_SCAN_REASON_PREEMPTED:
916 return "completed [preempted]";
917 case WMI_SCAN_REASON_TIMEDOUT:
918 return "completed [timedout]";
919 case WMI_SCAN_REASON_MAX:
920 break;
921 }
922 return "completed [unknown]";
923 case WMI_SCAN_EVENT_BSS_CHANNEL:
924 return "bss channel";
925 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
926 return "foreign channel";
927 case WMI_SCAN_EVENT_DEQUEUED:
928 return "dequeued";
929 case WMI_SCAN_EVENT_PREEMPTED:
930 return "preempted";
931 case WMI_SCAN_EVENT_START_FAILED:
932 return "start failed";
933 default:
934 return "unknown";
935 }
936}
937
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
939{
940 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
941 enum wmi_scan_event_type event_type;
942 enum wmi_scan_completion_reason reason;
943 u32 freq;
944 u32 req_id;
945 u32 scan_id;
946 u32 vdev_id;
947
948 event_type = __le32_to_cpu(event->event_type);
949 reason = __le32_to_cpu(event->reason);
950 freq = __le32_to_cpu(event->channel_freq);
951 req_id = __le32_to_cpu(event->scan_req_id);
952 scan_id = __le32_to_cpu(event->scan_id);
953 vdev_id = __le32_to_cpu(event->vdev_id);
954
Kalle Valo5e3dd152013-06-12 20:52:10 +0300955 spin_lock_bh(&ar->data_lock);
956
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200957 ath10k_dbg(ATH10K_DBG_WMI,
958 "scan event %s type %d reason %d freq %d req_id %d scan_id %d vdev_id %d state %s (%d)\n",
959 ath10k_wmi_event_scan_type_str(event_type, reason),
960 event_type, reason, freq, req_id, scan_id, vdev_id,
961 ath10k_scan_state_str(ar->scan.state), ar->scan.state);
962
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963 switch (event_type) {
964 case WMI_SCAN_EVENT_STARTED:
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200965 ath10k_wmi_event_scan_started(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300966 break;
967 case WMI_SCAN_EVENT_COMPLETED:
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200968 ath10k_wmi_event_scan_completed(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300969 break;
970 case WMI_SCAN_EVENT_BSS_CHANNEL:
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200971 ath10k_wmi_event_scan_bss_chan(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300972 break;
973 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
Michal Kazior5c81c7f2014-08-05 14:54:44 +0200974 ath10k_wmi_event_scan_foreign_chan(ar, freq);
975 break;
976 case WMI_SCAN_EVENT_START_FAILED:
977 ath10k_warn("received scan start failure event\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300978 break;
979 case WMI_SCAN_EVENT_DEQUEUED:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980 case WMI_SCAN_EVENT_PREEMPTED:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300981 default:
982 break;
983 }
984
985 spin_unlock_bh(&ar->data_lock);
986 return 0;
987}
988
989static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
990{
991 enum ieee80211_band band;
992
993 switch (phy_mode) {
994 case MODE_11A:
995 case MODE_11NA_HT20:
996 case MODE_11NA_HT40:
997 case MODE_11AC_VHT20:
998 case MODE_11AC_VHT40:
999 case MODE_11AC_VHT80:
1000 band = IEEE80211_BAND_5GHZ;
1001 break;
1002 case MODE_11G:
1003 case MODE_11B:
1004 case MODE_11GONLY:
1005 case MODE_11NG_HT20:
1006 case MODE_11NG_HT40:
1007 case MODE_11AC_VHT20_2G:
1008 case MODE_11AC_VHT40_2G:
1009 case MODE_11AC_VHT80_2G:
1010 default:
1011 band = IEEE80211_BAND_2GHZ;
1012 }
1013
1014 return band;
1015}
1016
1017static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
1018{
1019 u8 rate_idx = 0;
1020
1021 /* rate in Kbps */
1022 switch (rate) {
1023 case 1000:
1024 rate_idx = 0;
1025 break;
1026 case 2000:
1027 rate_idx = 1;
1028 break;
1029 case 5500:
1030 rate_idx = 2;
1031 break;
1032 case 11000:
1033 rate_idx = 3;
1034 break;
1035 case 6000:
1036 rate_idx = 4;
1037 break;
1038 case 9000:
1039 rate_idx = 5;
1040 break;
1041 case 12000:
1042 rate_idx = 6;
1043 break;
1044 case 18000:
1045 rate_idx = 7;
1046 break;
1047 case 24000:
1048 rate_idx = 8;
1049 break;
1050 case 36000:
1051 rate_idx = 9;
1052 break;
1053 case 48000:
1054 rate_idx = 10;
1055 break;
1056 case 54000:
1057 rate_idx = 11;
1058 break;
1059 default:
1060 break;
1061 }
1062
1063 if (band == IEEE80211_BAND_5GHZ) {
1064 if (rate_idx > 3)
1065 /* Omit CCK rates */
1066 rate_idx -= 4;
1067 else
1068 rate_idx = 0;
1069 }
1070
1071 return rate_idx;
1072}
1073
1074static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
1075{
Michal Kazior0d9b0432013-08-09 10:13:33 +02001076 struct wmi_mgmt_rx_event_v1 *ev_v1;
1077 struct wmi_mgmt_rx_event_v2 *ev_v2;
1078 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001079 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Michal Kazior453cdb62013-12-13 10:44:43 +01001080 struct ieee80211_channel *ch;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001081 struct ieee80211_hdr *hdr;
1082 u32 rx_status;
1083 u32 channel;
1084 u32 phy_mode;
1085 u32 snr;
1086 u32 rate;
1087 u32 buf_len;
1088 u16 fc;
Michal Kazior0d9b0432013-08-09 10:13:33 +02001089 int pull_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001090
Michal Kazior0d9b0432013-08-09 10:13:33 +02001091 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
1092 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
1093 ev_hdr = &ev_v2->hdr.v1;
1094 pull_len = sizeof(*ev_v2);
1095 } else {
1096 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
1097 ev_hdr = &ev_v1->hdr;
1098 pull_len = sizeof(*ev_v1);
1099 }
1100
1101 channel = __le32_to_cpu(ev_hdr->channel);
1102 buf_len = __le32_to_cpu(ev_hdr->buf_len);
1103 rx_status = __le32_to_cpu(ev_hdr->status);
1104 snr = __le32_to_cpu(ev_hdr->snr);
1105 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
1106 rate = __le32_to_cpu(ev_hdr->rate);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001107
1108 memset(status, 0, sizeof(*status));
1109
1110 ath10k_dbg(ATH10K_DBG_MGMT,
1111 "event mgmt rx status %08x\n", rx_status);
1112
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001113 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
1114 dev_kfree_skb(skb);
1115 return 0;
1116 }
1117
Kalle Valo5e3dd152013-06-12 20:52:10 +03001118 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
1119 dev_kfree_skb(skb);
1120 return 0;
1121 }
1122
1123 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
1124 dev_kfree_skb(skb);
1125 return 0;
1126 }
1127
1128 if (rx_status & WMI_RX_STATUS_ERR_CRC)
1129 status->flag |= RX_FLAG_FAILED_FCS_CRC;
1130 if (rx_status & WMI_RX_STATUS_ERR_MIC)
1131 status->flag |= RX_FLAG_MMIC_ERROR;
1132
Michal Kazior453cdb62013-12-13 10:44:43 +01001133 /* HW can Rx CCK rates on 5GHz. In that case phy_mode is set to
1134 * MODE_11B. This means phy_mode is not a reliable source for the band
1135 * of mgmt rx. */
1136
1137 ch = ar->scan_channel;
1138 if (!ch)
1139 ch = ar->rx_channel;
1140
1141 if (ch) {
1142 status->band = ch->band;
1143
1144 if (phy_mode == MODE_11B &&
1145 status->band == IEEE80211_BAND_5GHZ)
1146 ath10k_dbg(ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
1147 } else {
1148 ath10k_warn("using (unreliable) phy_mode to extract band for mgmt rx\n");
1149 status->band = phy_mode_to_band(phy_mode);
1150 }
1151
Kalle Valo5e3dd152013-06-12 20:52:10 +03001152 status->freq = ieee80211_channel_to_frequency(channel, status->band);
1153 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
1154 status->rate_idx = get_rate_idx(rate, status->band);
1155
Michal Kazior0d9b0432013-08-09 10:13:33 +02001156 skb_pull(skb, pull_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001157
1158 hdr = (struct ieee80211_hdr *)skb->data;
1159 fc = le16_to_cpu(hdr->frame_control);
1160
Michal Kazior2b6a6a92013-12-05 06:53:41 +01001161 /* FW delivers WEP Shared Auth frame with Protected Bit set and
1162 * encrypted payload. However in case of PMF it delivers decrypted
1163 * frames with Protected Bit set. */
1164 if (ieee80211_has_protected(hdr->frame_control) &&
1165 !ieee80211_is_auth(hdr->frame_control)) {
Marek Kwaczynskieeab2662014-05-14 16:56:17 +03001166 status->flag |= RX_FLAG_DECRYPTED;
1167
1168 if (!ieee80211_is_action(hdr->frame_control) &&
1169 !ieee80211_is_deauth(hdr->frame_control) &&
1170 !ieee80211_is_disassoc(hdr->frame_control)) {
1171 status->flag |= RX_FLAG_IV_STRIPPED |
1172 RX_FLAG_MMIC_STRIPPED;
1173 hdr->frame_control = __cpu_to_le16(fc &
Kalle Valo5e3dd152013-06-12 20:52:10 +03001174 ~IEEE80211_FCTL_PROTECTED);
Marek Kwaczynskieeab2662014-05-14 16:56:17 +03001175 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001176 }
1177
1178 ath10k_dbg(ATH10K_DBG_MGMT,
1179 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
1180 skb, skb->len,
1181 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
1182
1183 ath10k_dbg(ATH10K_DBG_MGMT,
1184 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
1185 status->freq, status->band, status->signal,
1186 status->rate_idx);
1187
1188 /*
1189 * packets from HTC come aligned to 4byte boundaries
1190 * because they can originally come in along with a trailer
1191 */
1192 skb_trim(skb, buf_len);
1193
1194 ieee80211_rx(ar->hw, skb);
1195 return 0;
1196}
1197
Michal Kazior2e1dea42013-07-31 10:32:40 +02001198static int freq_to_idx(struct ath10k *ar, int freq)
1199{
1200 struct ieee80211_supported_band *sband;
1201 int band, ch, idx = 0;
1202
1203 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
1204 sband = ar->hw->wiphy->bands[band];
1205 if (!sband)
1206 continue;
1207
1208 for (ch = 0; ch < sband->n_channels; ch++, idx++)
1209 if (sband->channels[ch].center_freq == freq)
1210 goto exit;
1211 }
1212
1213exit:
1214 return idx;
1215}
1216
Kalle Valo5e3dd152013-06-12 20:52:10 +03001217static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
1218{
Michal Kazior2e1dea42013-07-31 10:32:40 +02001219 struct wmi_chan_info_event *ev;
1220 struct survey_info *survey;
1221 u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
1222 int idx;
1223
1224 ev = (struct wmi_chan_info_event *)skb->data;
1225
1226 err_code = __le32_to_cpu(ev->err_code);
1227 freq = __le32_to_cpu(ev->freq);
1228 cmd_flags = __le32_to_cpu(ev->cmd_flags);
1229 noise_floor = __le32_to_cpu(ev->noise_floor);
1230 rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
1231 cycle_count = __le32_to_cpu(ev->cycle_count);
1232
1233 ath10k_dbg(ATH10K_DBG_WMI,
1234 "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
1235 err_code, freq, cmd_flags, noise_floor, rx_clear_count,
1236 cycle_count);
1237
1238 spin_lock_bh(&ar->data_lock);
1239
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001240 switch (ar->scan.state) {
1241 case ATH10K_SCAN_IDLE:
1242 case ATH10K_SCAN_STARTING:
1243 ath10k_warn("received chan info event without a scan request, ignoring\n");
Michal Kazior2e1dea42013-07-31 10:32:40 +02001244 goto exit;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02001245 case ATH10K_SCAN_RUNNING:
1246 case ATH10K_SCAN_ABORTING:
1247 break;
Michal Kazior2e1dea42013-07-31 10:32:40 +02001248 }
1249
1250 idx = freq_to_idx(ar, freq);
1251 if (idx >= ARRAY_SIZE(ar->survey)) {
1252 ath10k_warn("chan info: invalid frequency %d (idx %d out of bounds)\n",
1253 freq, idx);
1254 goto exit;
1255 }
1256
1257 if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
1258 /* During scanning chan info is reported twice for each
1259 * visited channel. The reported cycle count is global
1260 * and per-channel cycle count must be calculated */
1261
1262 cycle_count -= ar->survey_last_cycle_count;
1263 rx_clear_count -= ar->survey_last_rx_clear_count;
1264
1265 survey = &ar->survey[idx];
1266 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
1267 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
1268 survey->noise = noise_floor;
1269 survey->filled = SURVEY_INFO_CHANNEL_TIME |
1270 SURVEY_INFO_CHANNEL_TIME_RX |
1271 SURVEY_INFO_NOISE_DBM;
1272 }
1273
1274 ar->survey_last_rx_clear_count = rx_clear_count;
1275 ar->survey_last_cycle_count = cycle_count;
1276
1277exit:
1278 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001279}
1280
1281static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
1282{
1283 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
1284}
1285
Kalle Valo869526b2014-01-03 12:59:26 +02001286static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287{
Kalle Valo869526b2014-01-03 12:59:26 +02001288 ath10k_dbg(ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
1289 skb->len);
1290
1291 trace_ath10k_wmi_dbglog(skb->data, skb->len);
1292
1293 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001294}
1295
1296static void ath10k_wmi_event_update_stats(struct ath10k *ar,
1297 struct sk_buff *skb)
1298{
1299 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
1300
1301 ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
1302
1303 ath10k_debug_read_target_stats(ar, ev);
1304}
1305
1306static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
1307 struct sk_buff *skb)
1308{
1309 struct wmi_vdev_start_response_event *ev;
1310
1311 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
1312
1313 ev = (struct wmi_vdev_start_response_event *)skb->data;
1314
1315 if (WARN_ON(__le32_to_cpu(ev->status)))
1316 return;
1317
1318 complete(&ar->vdev_setup_done);
1319}
1320
1321static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
1322 struct sk_buff *skb)
1323{
1324 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
1325 complete(&ar->vdev_setup_done);
1326}
1327
1328static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
1329 struct sk_buff *skb)
1330{
Kalle Valo5a13e762014-01-20 11:01:46 +02001331 struct wmi_peer_sta_kickout_event *ev;
1332 struct ieee80211_sta *sta;
1333
1334 ev = (struct wmi_peer_sta_kickout_event *)skb->data;
1335
1336 ath10k_dbg(ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
1337 ev->peer_macaddr.addr);
1338
1339 rcu_read_lock();
1340
1341 sta = ieee80211_find_sta_by_ifaddr(ar->hw, ev->peer_macaddr.addr, NULL);
1342 if (!sta) {
1343 ath10k_warn("Spurious quick kickout for STA %pM\n",
1344 ev->peer_macaddr.addr);
1345 goto exit;
1346 }
1347
1348 ieee80211_report_low_ack(sta, 10);
1349
1350exit:
1351 rcu_read_unlock();
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352}
1353
1354/*
1355 * FIXME
1356 *
1357 * We don't report to mac80211 sleep state of connected
1358 * stations. Due to this mac80211 can't fill in TIM IE
1359 * correctly.
1360 *
1361 * I know of no way of getting nullfunc frames that contain
1362 * sleep transition from connected stations - these do not
1363 * seem to be sent from the target to the host. There also
1364 * doesn't seem to be a dedicated event for that. So the
1365 * only way left to do this would be to read tim_bitmap
1366 * during SWBA.
1367 *
1368 * We could probably try using tim_bitmap from SWBA to tell
1369 * mac80211 which stations are asleep and which are not. The
1370 * problem here is calling mac80211 functions so many times
1371 * could take too long and make us miss the time to submit
1372 * the beacon to the target.
1373 *
1374 * So as a workaround we try to extend the TIM IE if there
1375 * is unicast buffered for stations with aid > 7 and fill it
1376 * in ourselves.
1377 */
1378static void ath10k_wmi_update_tim(struct ath10k *ar,
1379 struct ath10k_vif *arvif,
1380 struct sk_buff *bcn,
1381 struct wmi_bcn_info *bcn_info)
1382{
1383 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
1384 struct ieee80211_tim_ie *tim;
1385 u8 *ies, *ie;
1386 u8 ie_len, pvm_len;
1387
1388 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
1389 * we must copy the bitmap upon change and reuse it later */
1390 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
1391 int i;
1392
1393 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
1394 sizeof(bcn_info->tim_info.tim_bitmap));
1395
1396 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
1397 __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
1398 u32 v = __le32_to_cpu(t);
1399 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
1400 }
1401
1402 /* FW reports either length 0 or 16
1403 * so we calculate this on our own */
1404 arvif->u.ap.tim_len = 0;
1405 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
1406 if (arvif->u.ap.tim_bitmap[i])
1407 arvif->u.ap.tim_len = i;
1408
1409 arvif->u.ap.tim_len++;
1410 }
1411
1412 ies = bcn->data;
1413 ies += ieee80211_hdrlen(hdr->frame_control);
1414 ies += 12; /* fixed parameters */
1415
1416 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
1417 (u8 *)skb_tail_pointer(bcn) - ies);
1418 if (!ie) {
Michal Kazior09af8f82013-07-05 16:15:08 +03001419 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1420 ath10k_warn("no tim ie found;\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001421 return;
1422 }
1423
1424 tim = (void *)ie + 2;
1425 ie_len = ie[1];
1426 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
1427
1428 if (pvm_len < arvif->u.ap.tim_len) {
1429 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
1430 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
1431 void *next_ie = ie + 2 + ie_len;
1432
1433 if (skb_put(bcn, expand_size)) {
1434 memmove(next_ie + expand_size, next_ie, move_size);
1435
1436 ie[1] += expand_size;
1437 ie_len += expand_size;
1438 pvm_len += expand_size;
1439 } else {
1440 ath10k_warn("tim expansion failed\n");
1441 }
1442 }
1443
1444 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
1445 ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
1446 return;
1447 }
1448
1449 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
1450 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
1451
Michal Kazior748afc42014-01-23 12:48:21 +01001452 if (tim->dtim_count == 0) {
1453 ATH10K_SKB_CB(bcn)->bcn.dtim_zero = true;
1454
1455 if (__le32_to_cpu(bcn_info->tim_info.tim_mcast) == 1)
1456 ATH10K_SKB_CB(bcn)->bcn.deliver_cab = true;
1457 }
1458
Kalle Valo5e3dd152013-06-12 20:52:10 +03001459 ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
1460 tim->dtim_count, tim->dtim_period,
1461 tim->bitmap_ctrl, pvm_len);
1462}
1463
1464static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
1465 struct wmi_p2p_noa_info *noa)
1466{
1467 struct ieee80211_p2p_noa_attr *noa_attr;
1468 u8 ctwindow_oppps = noa->ctwindow_oppps;
1469 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
1470 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
1471 __le16 *noa_attr_len;
1472 u16 attr_len;
1473 u8 noa_descriptors = noa->num_descriptors;
1474 int i;
1475
1476 /* P2P IE */
1477 data[0] = WLAN_EID_VENDOR_SPECIFIC;
1478 data[1] = len - 2;
1479 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1480 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1481 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1482 data[5] = WLAN_OUI_TYPE_WFA_P2P;
1483
1484 /* NOA ATTR */
1485 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
1486 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
1487 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
1488
1489 noa_attr->index = noa->index;
1490 noa_attr->oppps_ctwindow = ctwindow;
1491 if (oppps)
1492 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
1493
1494 for (i = 0; i < noa_descriptors; i++) {
1495 noa_attr->desc[i].count =
1496 __le32_to_cpu(noa->descriptors[i].type_count);
1497 noa_attr->desc[i].duration = noa->descriptors[i].duration;
1498 noa_attr->desc[i].interval = noa->descriptors[i].interval;
1499 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
1500 }
1501
1502 attr_len = 2; /* index + oppps_ctwindow */
1503 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1504 *noa_attr_len = __cpu_to_le16(attr_len);
1505}
1506
1507static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
1508{
1509 u32 len = 0;
1510 u8 noa_descriptors = noa->num_descriptors;
1511 u8 opp_ps_info = noa->ctwindow_oppps;
1512 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
1513
1514
1515 if (!noa_descriptors && !opps_enabled)
1516 return len;
1517
1518 len += 1 + 1 + 4; /* EID + len + OUI */
1519 len += 1 + 2; /* noa attr + attr len */
1520 len += 1 + 1; /* index + oppps_ctwindow */
1521 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1522
1523 return len;
1524}
1525
1526static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
1527 struct sk_buff *bcn,
1528 struct wmi_bcn_info *bcn_info)
1529{
1530 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
1531 u8 *new_data, *old_data = arvif->u.ap.noa_data;
1532 u32 new_len;
1533
1534 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1535 return;
1536
1537 ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
1538 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
1539 new_len = ath10k_p2p_calc_noa_ie_len(noa);
1540 if (!new_len)
1541 goto cleanup;
1542
1543 new_data = kmalloc(new_len, GFP_ATOMIC);
1544 if (!new_data)
1545 goto cleanup;
1546
1547 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
1548
1549 spin_lock_bh(&ar->data_lock);
1550 arvif->u.ap.noa_data = new_data;
1551 arvif->u.ap.noa_len = new_len;
1552 spin_unlock_bh(&ar->data_lock);
1553 kfree(old_data);
1554 }
1555
1556 if (arvif->u.ap.noa_data)
1557 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
1558 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
1559 arvif->u.ap.noa_data,
1560 arvif->u.ap.noa_len);
1561 return;
1562
1563cleanup:
1564 spin_lock_bh(&ar->data_lock);
1565 arvif->u.ap.noa_data = NULL;
1566 arvif->u.ap.noa_len = 0;
1567 spin_unlock_bh(&ar->data_lock);
1568 kfree(old_data);
1569}
1570
1571
1572static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1573{
1574 struct wmi_host_swba_event *ev;
1575 u32 map;
1576 int i = -1;
1577 struct wmi_bcn_info *bcn_info;
1578 struct ath10k_vif *arvif;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579 struct sk_buff *bcn;
Michal Kazior767d34f2014-02-27 18:50:03 +02001580 int ret, vdev_id = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001581
Kalle Valo5e3dd152013-06-12 20:52:10 +03001582 ev = (struct wmi_host_swba_event *)skb->data;
1583 map = __le32_to_cpu(ev->vdev_map);
1584
Kalle Valo7a8a3962014-03-28 14:35:16 +02001585 ath10k_dbg(ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586 ev->vdev_map);
1587
1588 for (; map; map >>= 1, vdev_id++) {
1589 if (!(map & 0x1))
1590 continue;
1591
1592 i++;
1593
1594 if (i >= WMI_MAX_AP_VDEV) {
1595 ath10k_warn("swba has corrupted vdev map\n");
1596 break;
1597 }
1598
1599 bcn_info = &ev->bcn_info[i];
1600
1601 ath10k_dbg(ATH10K_DBG_MGMT,
Kalle Valo7a8a3962014-03-28 14:35:16 +02001602 "mgmt event bcn_info %d tim_len %d mcast %d changed %d num_ps_pending %d bitmap 0x%08x%08x%08x%08x\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 i,
1604 __le32_to_cpu(bcn_info->tim_info.tim_len),
1605 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
1606 __le32_to_cpu(bcn_info->tim_info.tim_changed),
1607 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
1608 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
1609 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
1610 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
1611 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
1612
1613 arvif = ath10k_get_arvif(ar, vdev_id);
1614 if (arvif == NULL) {
1615 ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
1616 continue;
1617 }
1618
Michal Kaziorc2df44b2014-01-23 11:38:26 +01001619 /* There are no completions for beacons so wait for next SWBA
1620 * before telling mac80211 to decrement CSA counter
1621 *
1622 * Once CSA counter is completed stop sending beacons until
1623 * actual channel switch is done */
1624 if (arvif->vif->csa_active &&
1625 ieee80211_csa_is_complete(arvif->vif)) {
1626 ieee80211_csa_finish(arvif->vif);
1627 continue;
1628 }
1629
Kalle Valo5e3dd152013-06-12 20:52:10 +03001630 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
1631 if (!bcn) {
1632 ath10k_warn("could not get mac80211 beacon\n");
1633 continue;
1634 }
1635
Michal Kazior4b604552014-07-21 21:03:09 +03001636 ath10k_tx_h_seq_no(arvif->vif, bcn);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001637 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
1638 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
1639
Michal Kaziored543882013-09-13 14:16:56 +02001640 spin_lock_bh(&ar->data_lock);
Michal Kazior748afc42014-01-23 12:48:21 +01001641
Michal Kaziored543882013-09-13 14:16:56 +02001642 if (arvif->beacon) {
Michal Kazior748afc42014-01-23 12:48:21 +01001643 if (!arvif->beacon_sent)
1644 ath10k_warn("SWBA overrun on vdev %d\n",
1645 arvif->vdev_id);
1646
Michal Kazior767d34f2014-02-27 18:50:03 +02001647 dma_unmap_single(arvif->ar->dev,
1648 ATH10K_SKB_CB(arvif->beacon)->paddr,
1649 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02001650 dev_kfree_skb_any(arvif->beacon);
Michal Kazior2ab03a62014-04-23 19:30:05 +03001651 arvif->beacon = NULL;
Michal Kaziored543882013-09-13 14:16:56 +02001652 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001653
Michal Kazior767d34f2014-02-27 18:50:03 +02001654 ATH10K_SKB_CB(bcn)->paddr = dma_map_single(arvif->ar->dev,
1655 bcn->data, bcn->len,
1656 DMA_TO_DEVICE);
1657 ret = dma_mapping_error(arvif->ar->dev,
1658 ATH10K_SKB_CB(bcn)->paddr);
1659 if (ret) {
1660 ath10k_warn("failed to map beacon: %d\n", ret);
Michal Kaziorad3d2152014-04-23 19:30:06 +03001661 dev_kfree_skb_any(bcn);
Michal Kazior767d34f2014-02-27 18:50:03 +02001662 goto skip;
1663 }
Michal Kazior748afc42014-01-23 12:48:21 +01001664
Michal Kaziored543882013-09-13 14:16:56 +02001665 arvif->beacon = bcn;
Michal Kazior748afc42014-01-23 12:48:21 +01001666 arvif->beacon_sent = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001667
Michal Kaziored543882013-09-13 14:16:56 +02001668 ath10k_wmi_tx_beacon_nowait(arvif);
Michal Kazior767d34f2014-02-27 18:50:03 +02001669skip:
Michal Kaziored543882013-09-13 14:16:56 +02001670 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001671 }
1672}
1673
1674static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
1675 struct sk_buff *skb)
1676{
1677 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
1678}
1679
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001680static void ath10k_dfs_radar_report(struct ath10k *ar,
1681 struct wmi_single_phyerr_rx_event *event,
1682 struct phyerr_radar_report *rr,
1683 u64 tsf)
1684{
1685 u32 reg0, reg1, tsf32l;
1686 struct pulse_event pe;
1687 u64 tsf64;
1688 u8 rssi, width;
1689
1690 reg0 = __le32_to_cpu(rr->reg0);
1691 reg1 = __le32_to_cpu(rr->reg1);
1692
1693 ath10k_dbg(ATH10K_DBG_REGULATORY,
1694 "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
1695 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
1696 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
1697 MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
1698 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
1699 ath10k_dbg(ATH10K_DBG_REGULATORY,
1700 "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
1701 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
1702 MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
1703 MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
1704 MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
1705 MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
1706 ath10k_dbg(ATH10K_DBG_REGULATORY,
1707 "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
1708 MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
1709 MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
1710
1711 if (!ar->dfs_detector)
1712 return;
1713
1714 /* report event to DFS pattern detector */
1715 tsf32l = __le32_to_cpu(event->hdr.tsf_timestamp);
1716 tsf64 = tsf & (~0xFFFFFFFFULL);
1717 tsf64 |= tsf32l;
1718
1719 width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
1720 rssi = event->hdr.rssi_combined;
1721
1722 /* hardware store this as 8 bit signed value,
1723 * set to zero if negative number
1724 */
1725 if (rssi & 0x80)
1726 rssi = 0;
1727
1728 pe.ts = tsf64;
1729 pe.freq = ar->hw->conf.chandef.chan->center_freq;
1730 pe.width = width;
1731 pe.rssi = rssi;
1732
1733 ath10k_dbg(ATH10K_DBG_REGULATORY,
1734 "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
1735 pe.freq, pe.width, pe.rssi, pe.ts);
1736
1737 ATH10K_DFS_STAT_INC(ar, pulses_detected);
1738
1739 if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
1740 ath10k_dbg(ATH10K_DBG_REGULATORY,
1741 "dfs no pulse pattern detected, yet\n");
1742 return;
1743 }
1744
1745 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs radar detected\n");
1746 ATH10K_DFS_STAT_INC(ar, radar_detected);
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001747
1748 /* Control radar events reporting in debugfs file
1749 dfs_block_radar_events */
1750 if (ar->dfs_block_radar_events) {
1751 ath10k_info("DFS Radar detected, but ignored as requested\n");
1752 return;
1753 }
1754
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001755 ieee80211_radar_detected(ar->hw);
1756}
1757
1758static int ath10k_dfs_fft_report(struct ath10k *ar,
1759 struct wmi_single_phyerr_rx_event *event,
1760 struct phyerr_fft_report *fftr,
1761 u64 tsf)
1762{
1763 u32 reg0, reg1;
1764 u8 rssi, peak_mag;
1765
1766 reg0 = __le32_to_cpu(fftr->reg0);
1767 reg1 = __le32_to_cpu(fftr->reg1);
1768 rssi = event->hdr.rssi_combined;
1769
1770 ath10k_dbg(ATH10K_DBG_REGULATORY,
1771 "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
1772 MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
1773 MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
1774 MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
1775 MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
1776 ath10k_dbg(ATH10K_DBG_REGULATORY,
1777 "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
1778 MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
1779 MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
1780 MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
1781 MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
1782
1783 peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
1784
1785 /* false event detection */
1786 if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
1787 peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
1788 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
1789 ATH10K_DFS_STAT_INC(ar, pulses_discarded);
1790 return -EINVAL;
1791 }
1792
1793 return 0;
1794}
1795
1796static void ath10k_wmi_event_dfs(struct ath10k *ar,
1797 struct wmi_single_phyerr_rx_event *event,
1798 u64 tsf)
1799{
1800 int buf_len, tlv_len, res, i = 0;
1801 struct phyerr_tlv *tlv;
1802 struct phyerr_radar_report *rr;
1803 struct phyerr_fft_report *fftr;
1804 u8 *tlv_buf;
1805
1806 buf_len = __le32_to_cpu(event->hdr.buf_len);
1807 ath10k_dbg(ATH10K_DBG_REGULATORY,
1808 "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
1809 event->hdr.phy_err_code, event->hdr.rssi_combined,
1810 __le32_to_cpu(event->hdr.tsf_timestamp), tsf, buf_len);
1811
1812 /* Skip event if DFS disabled */
1813 if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED))
1814 return;
1815
1816 ATH10K_DFS_STAT_INC(ar, pulses_total);
1817
1818 while (i < buf_len) {
1819 if (i + sizeof(*tlv) > buf_len) {
1820 ath10k_warn("too short buf for tlv header (%d)\n", i);
1821 return;
1822 }
1823
1824 tlv = (struct phyerr_tlv *)&event->bufp[i];
1825 tlv_len = __le16_to_cpu(tlv->len);
1826 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1827 ath10k_dbg(ATH10K_DBG_REGULATORY,
1828 "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
1829 tlv_len, tlv->tag, tlv->sig);
1830
1831 switch (tlv->tag) {
1832 case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
1833 if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
1834 ath10k_warn("too short radar pulse summary (%d)\n",
1835 i);
1836 return;
1837 }
1838
1839 rr = (struct phyerr_radar_report *)tlv_buf;
1840 ath10k_dfs_radar_report(ar, event, rr, tsf);
1841 break;
1842 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1843 if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
1844 ath10k_warn("too short fft report (%d)\n", i);
1845 return;
1846 }
1847
1848 fftr = (struct phyerr_fft_report *)tlv_buf;
1849 res = ath10k_dfs_fft_report(ar, event, fftr, tsf);
1850 if (res)
1851 return;
1852 break;
1853 }
1854
1855 i += sizeof(*tlv) + tlv_len;
1856 }
1857}
1858
1859static void ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1860 struct wmi_single_phyerr_rx_event *event,
1861 u64 tsf)
1862{
Simon Wunderlich855aed12014-08-02 09:12:54 +03001863 int buf_len, tlv_len, res, i = 0;
1864 struct phyerr_tlv *tlv;
1865 u8 *tlv_buf;
1866 struct phyerr_fft_report *fftr;
1867 size_t fftr_len;
1868
1869 buf_len = __le32_to_cpu(event->hdr.buf_len);
1870
1871 while (i < buf_len) {
1872 if (i + sizeof(*tlv) > buf_len) {
1873 ath10k_warn("failed to parse phyerr tlv header at byte %d\n",
1874 i);
1875 return;
1876 }
1877
1878 tlv = (struct phyerr_tlv *)&event->bufp[i];
1879 tlv_len = __le16_to_cpu(tlv->len);
1880 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1881
1882 if (i + sizeof(*tlv) + tlv_len > buf_len) {
1883 ath10k_warn("failed to parse phyerr tlv payload at byte %d\n",
1884 i);
1885 return;
1886 }
1887
1888 switch (tlv->tag) {
1889 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1890 if (sizeof(*fftr) > tlv_len) {
1891 ath10k_warn("failed to parse fft report at byte %d\n",
1892 i);
1893 return;
1894 }
1895
1896 fftr_len = tlv_len - sizeof(*fftr);
1897 fftr = (struct phyerr_fft_report *)tlv_buf;
1898 res = ath10k_spectral_process_fft(ar, event,
1899 fftr, fftr_len,
1900 tsf);
1901 if (res < 0) {
1902 ath10k_warn("failed to process fft report: %d\n",
1903 res);
1904 return;
1905 }
1906 break;
1907 }
1908
1909 i += sizeof(*tlv) + tlv_len;
1910 }
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001911}
1912
Kalle Valo5e3dd152013-06-12 20:52:10 +03001913static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1914{
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001915 struct wmi_comb_phyerr_rx_event *comb_event;
1916 struct wmi_single_phyerr_rx_event *event;
1917 u32 count, i, buf_len, phy_err_code;
1918 u64 tsf;
1919 int left_len = skb->len;
1920
1921 ATH10K_DFS_STAT_INC(ar, phy_errors);
1922
1923 /* Check if combined event available */
1924 if (left_len < sizeof(*comb_event)) {
1925 ath10k_warn("wmi phyerr combined event wrong len\n");
1926 return;
1927 }
1928
1929 left_len -= sizeof(*comb_event);
1930
1931 /* Check number of included events */
1932 comb_event = (struct wmi_comb_phyerr_rx_event *)skb->data;
1933 count = __le32_to_cpu(comb_event->hdr.num_phyerr_events);
1934
1935 tsf = __le32_to_cpu(comb_event->hdr.tsf_u32);
1936 tsf <<= 32;
1937 tsf |= __le32_to_cpu(comb_event->hdr.tsf_l32);
1938
1939 ath10k_dbg(ATH10K_DBG_WMI,
1940 "wmi event phyerr count %d tsf64 0x%llX\n",
1941 count, tsf);
1942
1943 event = (struct wmi_single_phyerr_rx_event *)comb_event->bufp;
1944 for (i = 0; i < count; i++) {
1945 /* Check if we can read event header */
1946 if (left_len < sizeof(*event)) {
1947 ath10k_warn("single event (%d) wrong head len\n", i);
1948 return;
1949 }
1950
1951 left_len -= sizeof(*event);
1952
1953 buf_len = __le32_to_cpu(event->hdr.buf_len);
1954 phy_err_code = event->hdr.phy_err_code;
1955
1956 if (left_len < buf_len) {
1957 ath10k_warn("single event (%d) wrong buf len\n", i);
1958 return;
1959 }
1960
1961 left_len -= buf_len;
1962
1963 switch (phy_err_code) {
1964 case PHY_ERROR_RADAR:
1965 ath10k_wmi_event_dfs(ar, event, tsf);
1966 break;
1967 case PHY_ERROR_SPECTRAL_SCAN:
1968 ath10k_wmi_event_spectral_scan(ar, event, tsf);
1969 break;
1970 case PHY_ERROR_FALSE_RADAR_EXT:
1971 ath10k_wmi_event_dfs(ar, event, tsf);
1972 ath10k_wmi_event_spectral_scan(ar, event, tsf);
1973 break;
1974 default:
1975 break;
1976 }
1977
1978 event += sizeof(*event) + buf_len;
1979 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001980}
1981
1982static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
1983{
1984 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
1985}
1986
1987static void ath10k_wmi_event_profile_match(struct ath10k *ar,
1988 struct sk_buff *skb)
1989{
1990 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
1991}
1992
1993static void ath10k_wmi_event_debug_print(struct ath10k *ar,
Kalle Valo2fe52882014-01-03 12:59:20 +02001994 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995{
Kalle Valo2fe52882014-01-03 12:59:20 +02001996 char buf[101], c;
1997 int i;
1998
1999 for (i = 0; i < sizeof(buf) - 1; i++) {
2000 if (i >= skb->len)
2001 break;
2002
2003 c = skb->data[i];
2004
2005 if (c == '\0')
2006 break;
2007
2008 if (isascii(c) && isprint(c))
2009 buf[i] = c;
2010 else
2011 buf[i] = '.';
2012 }
2013
2014 if (i == sizeof(buf) - 1)
2015 ath10k_warn("wmi debug print truncated: %d\n", skb->len);
2016
2017 /* for some reason the debug prints end with \n, remove that */
2018 if (skb->data[i - 1] == '\n')
2019 i--;
2020
2021 /* the last byte is always reserved for the null character */
2022 buf[i] = '\0';
2023
2024 ath10k_dbg(ATH10K_DBG_WMI, "wmi event debug print '%s'\n", buf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002025}
2026
2027static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
2028{
2029 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
2030}
2031
2032static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
2033 struct sk_buff *skb)
2034{
2035 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
2036}
2037
2038static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
2039 struct sk_buff *skb)
2040{
2041 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
2042}
2043
2044static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
2045 struct sk_buff *skb)
2046{
2047 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
2048}
2049
2050static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
2051 struct sk_buff *skb)
2052{
2053 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
2054}
2055
2056static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
2057 struct sk_buff *skb)
2058{
2059 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
2060}
2061
2062static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
2063 struct sk_buff *skb)
2064{
2065 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
2066}
2067
2068static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
2069 struct sk_buff *skb)
2070{
2071 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
2072}
2073
2074static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
2075 struct sk_buff *skb)
2076{
2077 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
2078}
2079
2080static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
2081 struct sk_buff *skb)
2082{
2083 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
2084}
2085
2086static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
2087 struct sk_buff *skb)
2088{
2089 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
2090}
2091
2092static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
2093 struct sk_buff *skb)
2094{
2095 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
2096}
2097
2098static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
2099 struct sk_buff *skb)
2100{
2101 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
2102}
2103
2104static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
2105 struct sk_buff *skb)
2106{
2107 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
2108}
2109
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002110static void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar,
2111 struct sk_buff *skb)
2112{
2113 ath10k_dbg(ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
2114}
2115
2116static void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar,
2117 struct sk_buff *skb)
2118{
2119 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
2120}
2121
2122static void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar,
2123 struct sk_buff *skb)
2124{
2125 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
2126}
2127
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002128static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
2129 u32 num_units, u32 unit_len)
2130{
2131 dma_addr_t paddr;
2132 u32 pool_size;
2133 int idx = ar->wmi.num_mem_chunks;
2134
2135 pool_size = num_units * round_up(unit_len, 4);
2136
2137 if (!pool_size)
2138 return -EINVAL;
2139
2140 ar->wmi.mem_chunks[idx].vaddr = dma_alloc_coherent(ar->dev,
2141 pool_size,
2142 &paddr,
2143 GFP_ATOMIC);
2144 if (!ar->wmi.mem_chunks[idx].vaddr) {
2145 ath10k_warn("failed to allocate memory chunk\n");
2146 return -ENOMEM;
2147 }
2148
2149 memset(ar->wmi.mem_chunks[idx].vaddr, 0, pool_size);
2150
2151 ar->wmi.mem_chunks[idx].paddr = paddr;
2152 ar->wmi.mem_chunks[idx].len = pool_size;
2153 ar->wmi.mem_chunks[idx].req_id = req_id;
2154 ar->wmi.num_mem_chunks++;
2155
2156 return 0;
2157}
2158
Kalle Valo5e3dd152013-06-12 20:52:10 +03002159static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
2160 struct sk_buff *skb)
2161{
2162 struct wmi_service_ready_event *ev = (void *)skb->data;
Michal Kaziorcff990c2014-08-04 09:18:33 +03002163 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_BM_SIZE) = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002164
2165 if (skb->len < sizeof(*ev)) {
2166 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2167 skb->len, sizeof(*ev));
2168 return;
2169 }
2170
2171 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2172 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2173 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2174 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2175 ar->fw_version_major =
2176 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2177 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2178 ar->fw_version_release =
2179 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
2180 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
2181 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
Michal Kazior8865bee42013-07-24 12:36:46 +02002182 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2183
Kalle Valo1a222432013-09-27 19:55:07 +03002184 /* only manually set fw features when not using FW IE format */
2185 if (ar->fw_api == 1 && ar->fw_version_build > 636)
Michal Kazior0d9b0432013-08-09 10:13:33 +02002186 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
2187
Michal Kazior8865bee42013-07-24 12:36:46 +02002188 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2189 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
2190 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2191 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2192 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193
2194 ar->ath_common.regulatory.current_rd =
2195 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2196
Michal Kaziorcff990c2014-08-04 09:18:33 +03002197 wmi_10x_svc_map(ev->wmi_service_bitmap, svc_bmap);
2198 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2199 ath10k_dbg_dump(ATH10K_DBG_WMI, NULL, "ath10k: wmi svc: ",
2200 ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002201
2202 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2203 snprintf(ar->hw->wiphy->fw_version,
2204 sizeof(ar->hw->wiphy->fw_version),
2205 "%u.%u.%u.%u",
2206 ar->fw_version_major,
2207 ar->fw_version_minor,
2208 ar->fw_version_release,
2209 ar->fw_version_build);
2210 }
2211
2212 /* FIXME: it probably should be better to support this */
2213 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
2214 ath10k_warn("target requested %d memory chunks; ignoring\n",
2215 __le32_to_cpu(ev->num_mem_reqs));
2216 }
2217
2218 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior8865bee42013-07-24 12:36:46 +02002219 "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 +03002220 __le32_to_cpu(ev->sw_version),
2221 __le32_to_cpu(ev->sw_version_1),
2222 __le32_to_cpu(ev->abi_version),
2223 __le32_to_cpu(ev->phy_capability),
2224 __le32_to_cpu(ev->ht_cap_info),
2225 __le32_to_cpu(ev->vht_cap_info),
2226 __le32_to_cpu(ev->vht_supp_mcs),
2227 __le32_to_cpu(ev->sys_cap_info),
Michal Kazior8865bee42013-07-24 12:36:46 +02002228 __le32_to_cpu(ev->num_mem_reqs),
2229 __le32_to_cpu(ev->num_rf_chains));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002230
2231 complete(&ar->wmi.service_ready);
2232}
2233
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002234static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2235 struct sk_buff *skb)
2236{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002237 u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
2238 int ret;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002239 struct wmi_service_ready_event_10x *ev = (void *)skb->data;
Michal Kaziorcff990c2014-08-04 09:18:33 +03002240 DECLARE_BITMAP(svc_bmap, WMI_SERVICE_BM_SIZE) = {};
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002241
2242 if (skb->len < sizeof(*ev)) {
2243 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2244 skb->len, sizeof(*ev));
2245 return;
2246 }
2247
2248 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2249 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2250 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2251 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2252 ar->fw_version_major =
2253 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2254 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2255 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
2256 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2257
2258 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2259 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
2260 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2261 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2262 }
2263
2264 ar->ath_common.regulatory.current_rd =
2265 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2266
Michal Kaziorcff990c2014-08-04 09:18:33 +03002267 wmi_main_svc_map(ev->wmi_service_bitmap, svc_bmap);
2268 ath10k_debug_read_service_map(ar, svc_bmap, sizeof(svc_bmap));
2269 ath10k_dbg_dump(ATH10K_DBG_WMI, NULL, "ath10k: wmi svc: ",
2270 ev->wmi_service_bitmap, sizeof(ev->wmi_service_bitmap));
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002271
2272 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2273 snprintf(ar->hw->wiphy->fw_version,
2274 sizeof(ar->hw->wiphy->fw_version),
2275 "%u.%u",
2276 ar->fw_version_major,
2277 ar->fw_version_minor);
2278 }
2279
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002280 num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
2281
2282 if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
2283 ath10k_warn("requested memory chunks number (%d) exceeds the limit\n",
2284 num_mem_reqs);
2285 return;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002286 }
2287
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002288 if (!num_mem_reqs)
2289 goto exit;
2290
2291 ath10k_dbg(ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
2292 num_mem_reqs);
2293
2294 for (i = 0; i < num_mem_reqs; ++i) {
2295 req_id = __le32_to_cpu(ev->mem_reqs[i].req_id);
2296 num_units = __le32_to_cpu(ev->mem_reqs[i].num_units);
2297 unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size);
2298 num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info);
2299
2300 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
2301 /* number of units to allocate is number of
2302 * peers, 1 extra for self peer on target */
2303 /* this needs to be tied, host and target
2304 * can get out of sync */
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002305 num_units = TARGET_10X_NUM_PEERS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002306 else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS)
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002307 num_units = TARGET_10X_NUM_VDEVS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002308
2309 ath10k_dbg(ATH10K_DBG_WMI,
2310 "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
2311 req_id,
2312 __le32_to_cpu(ev->mem_reqs[i].num_units),
2313 num_unit_info,
2314 unit_size,
2315 num_units);
2316
2317 ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
2318 unit_size);
2319 if (ret)
2320 return;
2321 }
2322
2323exit:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002324 ath10k_dbg(ATH10K_DBG_WMI,
2325 "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",
2326 __le32_to_cpu(ev->sw_version),
2327 __le32_to_cpu(ev->abi_version),
2328 __le32_to_cpu(ev->phy_capability),
2329 __le32_to_cpu(ev->ht_cap_info),
2330 __le32_to_cpu(ev->vht_cap_info),
2331 __le32_to_cpu(ev->vht_supp_mcs),
2332 __le32_to_cpu(ev->sys_cap_info),
2333 __le32_to_cpu(ev->num_mem_reqs),
2334 __le32_to_cpu(ev->num_rf_chains));
2335
2336 complete(&ar->wmi.service_ready);
2337}
2338
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
2340{
2341 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
2342
2343 if (WARN_ON(skb->len < sizeof(*ev)))
2344 return -EINVAL;
2345
2346 memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
2347
2348 ath10k_dbg(ATH10K_DBG_WMI,
Ben Greear2c347522014-02-05 13:58:32 -08002349 "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 +03002350 __le32_to_cpu(ev->sw_version),
2351 __le32_to_cpu(ev->abi_version),
2352 ev->mac_addr.addr,
Ben Greear2c347522014-02-05 13:58:32 -08002353 __le32_to_cpu(ev->status), skb->len, sizeof(*ev));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002354
2355 complete(&ar->wmi.unified_ready);
2356 return 0;
2357}
2358
Bartosz Markowskice428702013-09-26 17:47:05 +02002359static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002360{
2361 struct wmi_cmd_hdr *cmd_hdr;
2362 enum wmi_event_id id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002363
2364 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2365 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2366
2367 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2368 return;
2369
Kalle Valo5e3dd152013-06-12 20:52:10 +03002370 trace_ath10k_wmi_event(id, skb->data, skb->len);
2371
2372 switch (id) {
2373 case WMI_MGMT_RX_EVENTID:
2374 ath10k_wmi_event_mgmt_rx(ar, skb);
2375 /* mgmt_rx() owns the skb now! */
2376 return;
2377 case WMI_SCAN_EVENTID:
2378 ath10k_wmi_event_scan(ar, skb);
2379 break;
2380 case WMI_CHAN_INFO_EVENTID:
2381 ath10k_wmi_event_chan_info(ar, skb);
2382 break;
2383 case WMI_ECHO_EVENTID:
2384 ath10k_wmi_event_echo(ar, skb);
2385 break;
2386 case WMI_DEBUG_MESG_EVENTID:
2387 ath10k_wmi_event_debug_mesg(ar, skb);
2388 break;
2389 case WMI_UPDATE_STATS_EVENTID:
2390 ath10k_wmi_event_update_stats(ar, skb);
2391 break;
2392 case WMI_VDEV_START_RESP_EVENTID:
2393 ath10k_wmi_event_vdev_start_resp(ar, skb);
2394 break;
2395 case WMI_VDEV_STOPPED_EVENTID:
2396 ath10k_wmi_event_vdev_stopped(ar, skb);
2397 break;
2398 case WMI_PEER_STA_KICKOUT_EVENTID:
2399 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2400 break;
2401 case WMI_HOST_SWBA_EVENTID:
2402 ath10k_wmi_event_host_swba(ar, skb);
2403 break;
2404 case WMI_TBTTOFFSET_UPDATE_EVENTID:
2405 ath10k_wmi_event_tbttoffset_update(ar, skb);
2406 break;
2407 case WMI_PHYERR_EVENTID:
2408 ath10k_wmi_event_phyerr(ar, skb);
2409 break;
2410 case WMI_ROAM_EVENTID:
2411 ath10k_wmi_event_roam(ar, skb);
2412 break;
2413 case WMI_PROFILE_MATCH:
2414 ath10k_wmi_event_profile_match(ar, skb);
2415 break;
2416 case WMI_DEBUG_PRINT_EVENTID:
2417 ath10k_wmi_event_debug_print(ar, skb);
2418 break;
2419 case WMI_PDEV_QVIT_EVENTID:
2420 ath10k_wmi_event_pdev_qvit(ar, skb);
2421 break;
2422 case WMI_WLAN_PROFILE_DATA_EVENTID:
2423 ath10k_wmi_event_wlan_profile_data(ar, skb);
2424 break;
2425 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
2426 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2427 break;
2428 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
2429 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2430 break;
2431 case WMI_RTT_ERROR_REPORT_EVENTID:
2432 ath10k_wmi_event_rtt_error_report(ar, skb);
2433 break;
2434 case WMI_WOW_WAKEUP_HOST_EVENTID:
2435 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2436 break;
2437 case WMI_DCS_INTERFERENCE_EVENTID:
2438 ath10k_wmi_event_dcs_interference(ar, skb);
2439 break;
2440 case WMI_PDEV_TPC_CONFIG_EVENTID:
2441 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2442 break;
2443 case WMI_PDEV_FTM_INTG_EVENTID:
2444 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
2445 break;
2446 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
2447 ath10k_wmi_event_gtk_offload_status(ar, skb);
2448 break;
2449 case WMI_GTK_REKEY_FAIL_EVENTID:
2450 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
2451 break;
2452 case WMI_TX_DELBA_COMPLETE_EVENTID:
2453 ath10k_wmi_event_delba_complete(ar, skb);
2454 break;
2455 case WMI_TX_ADDBA_COMPLETE_EVENTID:
2456 ath10k_wmi_event_addba_complete(ar, skb);
2457 break;
2458 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
2459 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
2460 break;
2461 case WMI_SERVICE_READY_EVENTID:
2462 ath10k_wmi_service_ready_event_rx(ar, skb);
2463 break;
2464 case WMI_READY_EVENTID:
2465 ath10k_wmi_ready_event_rx(ar, skb);
2466 break;
2467 default:
2468 ath10k_warn("Unknown eventid: %d\n", id);
2469 break;
2470 }
2471
2472 dev_kfree_skb(skb);
2473}
2474
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002475static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
2476{
2477 struct wmi_cmd_hdr *cmd_hdr;
2478 enum wmi_10x_event_id id;
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002479
2480 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2481 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2482
2483 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2484 return;
2485
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002486 trace_ath10k_wmi_event(id, skb->data, skb->len);
2487
2488 switch (id) {
2489 case WMI_10X_MGMT_RX_EVENTID:
2490 ath10k_wmi_event_mgmt_rx(ar, skb);
2491 /* mgmt_rx() owns the skb now! */
2492 return;
2493 case WMI_10X_SCAN_EVENTID:
2494 ath10k_wmi_event_scan(ar, skb);
2495 break;
2496 case WMI_10X_CHAN_INFO_EVENTID:
2497 ath10k_wmi_event_chan_info(ar, skb);
2498 break;
2499 case WMI_10X_ECHO_EVENTID:
2500 ath10k_wmi_event_echo(ar, skb);
2501 break;
2502 case WMI_10X_DEBUG_MESG_EVENTID:
2503 ath10k_wmi_event_debug_mesg(ar, skb);
2504 break;
2505 case WMI_10X_UPDATE_STATS_EVENTID:
2506 ath10k_wmi_event_update_stats(ar, skb);
2507 break;
2508 case WMI_10X_VDEV_START_RESP_EVENTID:
2509 ath10k_wmi_event_vdev_start_resp(ar, skb);
2510 break;
2511 case WMI_10X_VDEV_STOPPED_EVENTID:
2512 ath10k_wmi_event_vdev_stopped(ar, skb);
2513 break;
2514 case WMI_10X_PEER_STA_KICKOUT_EVENTID:
2515 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2516 break;
2517 case WMI_10X_HOST_SWBA_EVENTID:
2518 ath10k_wmi_event_host_swba(ar, skb);
2519 break;
2520 case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
2521 ath10k_wmi_event_tbttoffset_update(ar, skb);
2522 break;
2523 case WMI_10X_PHYERR_EVENTID:
2524 ath10k_wmi_event_phyerr(ar, skb);
2525 break;
2526 case WMI_10X_ROAM_EVENTID:
2527 ath10k_wmi_event_roam(ar, skb);
2528 break;
2529 case WMI_10X_PROFILE_MATCH:
2530 ath10k_wmi_event_profile_match(ar, skb);
2531 break;
2532 case WMI_10X_DEBUG_PRINT_EVENTID:
2533 ath10k_wmi_event_debug_print(ar, skb);
2534 break;
2535 case WMI_10X_PDEV_QVIT_EVENTID:
2536 ath10k_wmi_event_pdev_qvit(ar, skb);
2537 break;
2538 case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
2539 ath10k_wmi_event_wlan_profile_data(ar, skb);
2540 break;
2541 case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
2542 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2543 break;
2544 case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
2545 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2546 break;
2547 case WMI_10X_RTT_ERROR_REPORT_EVENTID:
2548 ath10k_wmi_event_rtt_error_report(ar, skb);
2549 break;
2550 case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
2551 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2552 break;
2553 case WMI_10X_DCS_INTERFERENCE_EVENTID:
2554 ath10k_wmi_event_dcs_interference(ar, skb);
2555 break;
2556 case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
2557 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2558 break;
2559 case WMI_10X_INST_RSSI_STATS_EVENTID:
2560 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2561 break;
2562 case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
2563 ath10k_wmi_event_vdev_standby_req(ar, skb);
2564 break;
2565 case WMI_10X_VDEV_RESUME_REQ_EVENTID:
2566 ath10k_wmi_event_vdev_resume_req(ar, skb);
2567 break;
2568 case WMI_10X_SERVICE_READY_EVENTID:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002569 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002570 break;
2571 case WMI_10X_READY_EVENTID:
2572 ath10k_wmi_ready_event_rx(ar, skb);
2573 break;
2574 default:
2575 ath10k_warn("Unknown eventid: %d\n", id);
2576 break;
2577 }
2578
2579 dev_kfree_skb(skb);
2580}
2581
Michal Kazior24c88f72014-07-25 13:32:17 +02002582static void ath10k_wmi_10_2_process_rx(struct ath10k *ar, struct sk_buff *skb)
2583{
2584 struct wmi_cmd_hdr *cmd_hdr;
2585 enum wmi_10_2_event_id id;
2586
2587 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2588 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2589
2590 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2591 return;
2592
2593 trace_ath10k_wmi_event(id, skb->data, skb->len);
2594
2595 switch (id) {
2596 case WMI_10_2_MGMT_RX_EVENTID:
2597 ath10k_wmi_event_mgmt_rx(ar, skb);
2598 /* mgmt_rx() owns the skb now! */
2599 return;
2600 case WMI_10_2_SCAN_EVENTID:
2601 ath10k_wmi_event_scan(ar, skb);
2602 break;
2603 case WMI_10_2_CHAN_INFO_EVENTID:
2604 ath10k_wmi_event_chan_info(ar, skb);
2605 break;
2606 case WMI_10_2_ECHO_EVENTID:
2607 ath10k_wmi_event_echo(ar, skb);
2608 break;
2609 case WMI_10_2_DEBUG_MESG_EVENTID:
2610 ath10k_wmi_event_debug_mesg(ar, skb);
2611 break;
2612 case WMI_10_2_UPDATE_STATS_EVENTID:
2613 ath10k_wmi_event_update_stats(ar, skb);
2614 break;
2615 case WMI_10_2_VDEV_START_RESP_EVENTID:
2616 ath10k_wmi_event_vdev_start_resp(ar, skb);
2617 break;
2618 case WMI_10_2_VDEV_STOPPED_EVENTID:
2619 ath10k_wmi_event_vdev_stopped(ar, skb);
2620 break;
2621 case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
2622 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2623 break;
2624 case WMI_10_2_HOST_SWBA_EVENTID:
2625 ath10k_wmi_event_host_swba(ar, skb);
2626 break;
2627 case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
2628 ath10k_wmi_event_tbttoffset_update(ar, skb);
2629 break;
2630 case WMI_10_2_PHYERR_EVENTID:
2631 ath10k_wmi_event_phyerr(ar, skb);
2632 break;
2633 case WMI_10_2_ROAM_EVENTID:
2634 ath10k_wmi_event_roam(ar, skb);
2635 break;
2636 case WMI_10_2_PROFILE_MATCH:
2637 ath10k_wmi_event_profile_match(ar, skb);
2638 break;
2639 case WMI_10_2_DEBUG_PRINT_EVENTID:
2640 ath10k_wmi_event_debug_print(ar, skb);
2641 break;
2642 case WMI_10_2_PDEV_QVIT_EVENTID:
2643 ath10k_wmi_event_pdev_qvit(ar, skb);
2644 break;
2645 case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
2646 ath10k_wmi_event_wlan_profile_data(ar, skb);
2647 break;
2648 case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
2649 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2650 break;
2651 case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
2652 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2653 break;
2654 case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
2655 ath10k_wmi_event_rtt_error_report(ar, skb);
2656 break;
2657 case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
2658 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2659 break;
2660 case WMI_10_2_DCS_INTERFERENCE_EVENTID:
2661 ath10k_wmi_event_dcs_interference(ar, skb);
2662 break;
2663 case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
2664 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2665 break;
2666 case WMI_10_2_INST_RSSI_STATS_EVENTID:
2667 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2668 break;
2669 case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
2670 ath10k_wmi_event_vdev_standby_req(ar, skb);
2671 break;
2672 case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
2673 ath10k_wmi_event_vdev_resume_req(ar, skb);
2674 break;
2675 case WMI_10_2_SERVICE_READY_EVENTID:
2676 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
2677 break;
2678 case WMI_10_2_READY_EVENTID:
2679 ath10k_wmi_ready_event_rx(ar, skb);
2680 break;
2681 case WMI_10_2_RTT_KEEPALIVE_EVENTID:
2682 case WMI_10_2_GPIO_INPUT_EVENTID:
2683 case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
2684 case WMI_10_2_GENERIC_BUFFER_EVENTID:
2685 case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
2686 case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
2687 case WMI_10_2_WDS_PEER_EVENTID:
2688 ath10k_dbg(ATH10K_DBG_WMI,
2689 "received event id %d not implemented\n", id);
2690 break;
2691 default:
2692 ath10k_warn("Unknown eventid: %d\n", id);
2693 break;
2694 }
2695
2696 dev_kfree_skb(skb);
2697}
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002698
Bartosz Markowskice428702013-09-26 17:47:05 +02002699static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
2700{
Michal Kazior24c88f72014-07-25 13:32:17 +02002701 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2702 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2703 ath10k_wmi_10_2_process_rx(ar, skb);
2704 else
2705 ath10k_wmi_10x_process_rx(ar, skb);
2706 } else {
Bartosz Markowskice428702013-09-26 17:47:05 +02002707 ath10k_wmi_main_process_rx(ar, skb);
Michal Kazior24c88f72014-07-25 13:32:17 +02002708 }
Bartosz Markowskice428702013-09-26 17:47:05 +02002709}
2710
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711/* WMI Initialization functions */
2712int ath10k_wmi_attach(struct ath10k *ar)
2713{
Bartosz Markowskice428702013-09-26 17:47:05 +02002714 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
Michal Kazior24c88f72014-07-25 13:32:17 +02002715 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2716 ar->wmi.cmd = &wmi_10_2_cmd_map;
2717 else
2718 ar->wmi.cmd = &wmi_10x_cmd_map;
2719
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002720 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002721 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
Bartosz Markowskice428702013-09-26 17:47:05 +02002722 } else {
2723 ar->wmi.cmd = &wmi_cmd_map;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002724 ar->wmi.vdev_param = &wmi_vdev_param_map;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002725 ar->wmi.pdev_param = &wmi_pdev_param_map;
Bartosz Markowskice428702013-09-26 17:47:05 +02002726 }
2727
Kalle Valo5e3dd152013-06-12 20:52:10 +03002728 init_completion(&ar->wmi.service_ready);
2729 init_completion(&ar->wmi.unified_ready);
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002730 init_waitqueue_head(&ar->wmi.tx_credits_wq);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731
2732 return 0;
2733}
2734
2735void ath10k_wmi_detach(struct ath10k *ar)
2736{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002737 int i;
2738
2739 /* free the host memory chunks requested by firmware */
2740 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2741 dma_free_coherent(ar->dev,
2742 ar->wmi.mem_chunks[i].len,
2743 ar->wmi.mem_chunks[i].vaddr,
2744 ar->wmi.mem_chunks[i].paddr);
2745 }
2746
2747 ar->wmi.num_mem_chunks = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748}
2749
Michal Kazior95bf21f2014-05-16 17:15:39 +03002750int ath10k_wmi_connect(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751{
2752 int status;
2753 struct ath10k_htc_svc_conn_req conn_req;
2754 struct ath10k_htc_svc_conn_resp conn_resp;
2755
2756 memset(&conn_req, 0, sizeof(conn_req));
2757 memset(&conn_resp, 0, sizeof(conn_resp));
2758
2759 /* these fields are the same for all service endpoints */
2760 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
2761 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002762 conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002763
2764 /* connect to control service */
2765 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
2766
Michal Kaziorcd003fa2013-07-05 16:15:13 +03002767 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002768 if (status) {
2769 ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
2770 status);
2771 return status;
2772 }
2773
2774 ar->wmi.eid = conn_resp.eid;
2775 return 0;
2776}
2777
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002778static int ath10k_wmi_main_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2779 u16 rd2g, u16 rd5g, u16 ctl2g,
2780 u16 ctl5g)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002781{
2782 struct wmi_pdev_set_regdomain_cmd *cmd;
2783 struct sk_buff *skb;
2784
2785 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2786 if (!skb)
2787 return -ENOMEM;
2788
2789 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
2790 cmd->reg_domain = __cpu_to_le32(rd);
2791 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2792 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2793 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2794 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2795
2796 ath10k_dbg(ATH10K_DBG_WMI,
2797 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
2798 rd, rd2g, rd5g, ctl2g, ctl5g);
2799
Bartosz Markowskice428702013-09-26 17:47:05 +02002800 return ath10k_wmi_cmd_send(ar, skb,
2801 ar->wmi.cmd->pdev_set_regdomain_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002802}
2803
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002804static int ath10k_wmi_10x_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2805 u16 rd2g, u16 rd5g,
2806 u16 ctl2g, u16 ctl5g,
2807 enum wmi_dfs_region dfs_reg)
2808{
2809 struct wmi_pdev_set_regdomain_cmd_10x *cmd;
2810 struct sk_buff *skb;
2811
2812 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2813 if (!skb)
2814 return -ENOMEM;
2815
2816 cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
2817 cmd->reg_domain = __cpu_to_le32(rd);
2818 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2819 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2820 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2821 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2822 cmd->dfs_domain = __cpu_to_le32(dfs_reg);
2823
2824 ath10k_dbg(ATH10K_DBG_WMI,
2825 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
2826 rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
2827
2828 return ath10k_wmi_cmd_send(ar, skb,
2829 ar->wmi.cmd->pdev_set_regdomain_cmdid);
2830}
2831
2832int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
2833 u16 rd5g, u16 ctl2g, u16 ctl5g,
2834 enum wmi_dfs_region dfs_reg)
2835{
2836 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2837 return ath10k_wmi_10x_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2838 ctl2g, ctl5g, dfs_reg);
2839 else
2840 return ath10k_wmi_main_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2841 ctl2g, ctl5g);
2842}
2843
Kalle Valo5e3dd152013-06-12 20:52:10 +03002844int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
2845 const struct wmi_channel_arg *arg)
2846{
2847 struct wmi_set_channel_cmd *cmd;
2848 struct sk_buff *skb;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002849 u32 ch_flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850
2851 if (arg->passive)
2852 return -EINVAL;
2853
2854 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2855 if (!skb)
2856 return -ENOMEM;
2857
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002858 if (arg->chan_radar)
2859 ch_flags |= WMI_CHAN_FLAG_DFS;
2860
Kalle Valo5e3dd152013-06-12 20:52:10 +03002861 cmd = (struct wmi_set_channel_cmd *)skb->data;
2862 cmd->chan.mhz = __cpu_to_le32(arg->freq);
2863 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
2864 cmd->chan.mode = arg->mode;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002865 cmd->chan.flags |= __cpu_to_le32(ch_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002866 cmd->chan.min_power = arg->min_power;
2867 cmd->chan.max_power = arg->max_power;
2868 cmd->chan.reg_power = arg->max_reg_power;
2869 cmd->chan.reg_classid = arg->reg_class_id;
2870 cmd->chan.antenna_max = arg->max_antenna_gain;
2871
2872 ath10k_dbg(ATH10K_DBG_WMI,
2873 "wmi set channel mode %d freq %d\n",
2874 arg->mode, arg->freq);
2875
Bartosz Markowskice428702013-09-26 17:47:05 +02002876 return ath10k_wmi_cmd_send(ar, skb,
2877 ar->wmi.cmd->pdev_set_channel_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002878}
2879
Marek Puzyniak00f54822014-02-10 17:14:24 +01002880int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002881{
2882 struct wmi_pdev_suspend_cmd *cmd;
2883 struct sk_buff *skb;
2884
2885 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2886 if (!skb)
2887 return -ENOMEM;
2888
2889 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
Marek Puzyniak00f54822014-02-10 17:14:24 +01002890 cmd->suspend_opt = __cpu_to_le32(suspend_opt);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002891
Bartosz Markowskice428702013-09-26 17:47:05 +02002892 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_suspend_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893}
2894
2895int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
2896{
2897 struct sk_buff *skb;
2898
2899 skb = ath10k_wmi_alloc_skb(0);
2900 if (skb == NULL)
2901 return -ENOMEM;
2902
Bartosz Markowskice428702013-09-26 17:47:05 +02002903 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_resume_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904}
2905
Bartosz Markowski226a3392013-09-26 17:47:16 +02002906int ath10k_wmi_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907{
2908 struct wmi_pdev_set_param_cmd *cmd;
2909 struct sk_buff *skb;
2910
Bartosz Markowski226a3392013-09-26 17:47:16 +02002911 if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
2912 ath10k_warn("pdev param %d not supported by firmware\n", id);
Bartosz Markowskid5449432013-10-15 09:55:32 +02002913 return -EOPNOTSUPP;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002914 }
2915
Kalle Valo5e3dd152013-06-12 20:52:10 +03002916 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2917 if (!skb)
2918 return -ENOMEM;
2919
2920 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
2921 cmd->param_id = __cpu_to_le32(id);
2922 cmd->param_value = __cpu_to_le32(value);
2923
2924 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
2925 id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02002926 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002927}
2928
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002929static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002930{
2931 struct wmi_init_cmd *cmd;
2932 struct sk_buff *buf;
2933 struct wmi_resource_config config = {};
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002934 u32 len, val;
2935 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002936
2937 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
2938 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
2939 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
2940
2941 config.num_offload_reorder_bufs =
2942 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
2943
2944 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
2945 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
2946 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
2947 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
2948 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
2949 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2950 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2951 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2952 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
2953 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
2954
2955 config.scan_max_pending_reqs =
2956 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
2957
2958 config.bmiss_offload_max_vdev =
2959 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
2960
2961 config.roam_offload_max_vdev =
2962 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
2963
2964 config.roam_offload_max_ap_profiles =
2965 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
2966
2967 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
2968 config.num_mcast_table_elems =
2969 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
2970
2971 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
2972 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
2973 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
2974 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
2975 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
2976
2977 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
2978 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
2979
2980 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
2981
2982 config.gtk_offload_max_vdev =
2983 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
2984
2985 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
2986 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
2987
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002988 len = sizeof(*cmd) +
2989 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
2990
2991 buf = ath10k_wmi_alloc_skb(len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002992 if (!buf)
2993 return -ENOMEM;
2994
2995 cmd = (struct wmi_init_cmd *)buf->data;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002996
2997 if (ar->wmi.num_mem_chunks == 0) {
2998 cmd->num_host_mem_chunks = 0;
2999 goto out;
3000 }
3001
3002 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
Michal Kazior5c54a7b2013-10-16 16:45:53 +03003003 ar->wmi.num_mem_chunks);
Bartosz Markowskib3effe62013-09-26 17:47:11 +02003004
3005 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3006
3007 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3008 cmd->host_mem_chunks[i].ptr =
3009 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3010 cmd->host_mem_chunks[i].size =
3011 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3012 cmd->host_mem_chunks[i].req_id =
3013 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3014
3015 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03003016 "wmi chunk %d len %d requested, addr 0x%llx\n",
Bartosz Markowskib3effe62013-09-26 17:47:11 +02003017 i,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03003018 ar->wmi.mem_chunks[i].len,
3019 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
Bartosz Markowskib3effe62013-09-26 17:47:11 +02003020 }
3021out:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003022 memcpy(&cmd->resource_config, &config, sizeof(config));
3023
3024 ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003025 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003026}
3027
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003028static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
3029{
3030 struct wmi_init_cmd_10x *cmd;
3031 struct sk_buff *buf;
3032 struct wmi_resource_config_10x config = {};
3033 u32 len, val;
3034 int i;
3035
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003036 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3037 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
3038 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
3039 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
3040 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
3041 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3042 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3043 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3044 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3045 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3046 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3047 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003048
3049 config.scan_max_pending_reqs =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003050 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003051
3052 config.bmiss_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003053 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003054
3055 config.roam_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003056 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003057
3058 config.roam_offload_max_ap_profiles =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003059 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003060
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003061 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003062 config.num_mcast_table_elems =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003063 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003064
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003065 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3066 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3067 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3068 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3069 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003070
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003071 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003072 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3073
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003074 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003075
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02003076 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3077 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003078
3079 len = sizeof(*cmd) +
3080 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3081
3082 buf = ath10k_wmi_alloc_skb(len);
3083 if (!buf)
3084 return -ENOMEM;
3085
3086 cmd = (struct wmi_init_cmd_10x *)buf->data;
3087
3088 if (ar->wmi.num_mem_chunks == 0) {
3089 cmd->num_host_mem_chunks = 0;
3090 goto out;
3091 }
3092
3093 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
Michal Kazior5c54a7b2013-10-16 16:45:53 +03003094 ar->wmi.num_mem_chunks);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003095
3096 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3097
3098 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3099 cmd->host_mem_chunks[i].ptr =
3100 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3101 cmd->host_mem_chunks[i].size =
3102 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3103 cmd->host_mem_chunks[i].req_id =
3104 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3105
3106 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03003107 "wmi chunk %d len %d requested, addr 0x%llx\n",
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003108 i,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03003109 ar->wmi.mem_chunks[i].len,
3110 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003111 }
3112out:
3113 memcpy(&cmd->resource_config, &config, sizeof(config));
3114
3115 ath10k_dbg(ATH10K_DBG_WMI, "wmi init 10x\n");
3116 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3117}
3118
Michal Kazior24c88f72014-07-25 13:32:17 +02003119static int ath10k_wmi_10_2_cmd_init(struct ath10k *ar)
3120{
3121 struct wmi_init_cmd_10_2 *cmd;
3122 struct sk_buff *buf;
3123 struct wmi_resource_config_10x config = {};
3124 u32 len, val;
3125 int i;
3126
3127 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
3128 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
3129 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
3130 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
3131 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
3132 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3133 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3134 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3135 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3136 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3137 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3138 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
3139
3140 config.scan_max_pending_reqs =
3141 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
3142
3143 config.bmiss_offload_max_vdev =
3144 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
3145
3146 config.roam_offload_max_vdev =
3147 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
3148
3149 config.roam_offload_max_ap_profiles =
3150 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
3151
3152 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
3153 config.num_mcast_table_elems =
3154 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
3155
3156 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3157 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3158 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3159 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3160 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
3161
3162 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
3163 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3164
3165 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
3166
3167 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3168 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
3169
3170 len = sizeof(*cmd) +
3171 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3172
3173 buf = ath10k_wmi_alloc_skb(len);
3174 if (!buf)
3175 return -ENOMEM;
3176
3177 cmd = (struct wmi_init_cmd_10_2 *)buf->data;
3178
3179 if (ar->wmi.num_mem_chunks == 0) {
3180 cmd->num_host_mem_chunks = 0;
3181 goto out;
3182 }
3183
3184 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3185 ar->wmi.num_mem_chunks);
3186
3187 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3188
3189 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3190 cmd->host_mem_chunks[i].ptr =
3191 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3192 cmd->host_mem_chunks[i].size =
3193 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3194 cmd->host_mem_chunks[i].req_id =
3195 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3196
3197 ath10k_dbg(ATH10K_DBG_WMI,
3198 "wmi chunk %d len %d requested, addr 0x%llx\n",
3199 i,
3200 ar->wmi.mem_chunks[i].len,
3201 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3202 }
3203out:
3204 memcpy(&cmd->resource_config.common, &config, sizeof(config));
3205
3206 ath10k_dbg(ATH10K_DBG_WMI, "wmi init 10.2\n");
3207 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3208}
3209
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003210int ath10k_wmi_cmd_init(struct ath10k *ar)
3211{
3212 int ret;
3213
Michal Kazior24c88f72014-07-25 13:32:17 +02003214 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3215 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3216 ret = ath10k_wmi_10_2_cmd_init(ar);
3217 else
3218 ret = ath10k_wmi_10x_cmd_init(ar);
3219 } else {
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003220 ret = ath10k_wmi_main_cmd_init(ar);
Michal Kazior24c88f72014-07-25 13:32:17 +02003221 }
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003222
3223 return ret;
3224}
3225
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003226static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar,
3227 const struct wmi_start_scan_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003228{
3229 int len;
3230
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003231 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3232 len = sizeof(struct wmi_start_scan_cmd_10x);
3233 else
3234 len = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003235
3236 if (arg->ie_len) {
3237 if (!arg->ie)
3238 return -EINVAL;
3239 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
3240 return -EINVAL;
3241
3242 len += sizeof(struct wmi_ie_data);
3243 len += roundup(arg->ie_len, 4);
3244 }
3245
3246 if (arg->n_channels) {
3247 if (!arg->channels)
3248 return -EINVAL;
3249 if (arg->n_channels > ARRAY_SIZE(arg->channels))
3250 return -EINVAL;
3251
3252 len += sizeof(struct wmi_chan_list);
3253 len += sizeof(__le32) * arg->n_channels;
3254 }
3255
3256 if (arg->n_ssids) {
3257 if (!arg->ssids)
3258 return -EINVAL;
3259 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
3260 return -EINVAL;
3261
3262 len += sizeof(struct wmi_ssid_list);
3263 len += sizeof(struct wmi_ssid) * arg->n_ssids;
3264 }
3265
3266 if (arg->n_bssids) {
3267 if (!arg->bssids)
3268 return -EINVAL;
3269 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
3270 return -EINVAL;
3271
3272 len += sizeof(struct wmi_bssid_list);
3273 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3274 }
3275
3276 return len;
3277}
3278
3279int ath10k_wmi_start_scan(struct ath10k *ar,
3280 const struct wmi_start_scan_arg *arg)
3281{
3282 struct wmi_start_scan_cmd *cmd;
3283 struct sk_buff *skb;
3284 struct wmi_ie_data *ie;
3285 struct wmi_chan_list *channels;
3286 struct wmi_ssid_list *ssids;
3287 struct wmi_bssid_list *bssids;
3288 u32 scan_id;
3289 u32 scan_req_id;
3290 int off;
3291 int len = 0;
3292 int i;
3293
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003294 len = ath10k_wmi_start_scan_calc_len(ar, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003295 if (len < 0)
3296 return len; /* len contains error code here */
3297
3298 skb = ath10k_wmi_alloc_skb(len);
3299 if (!skb)
3300 return -ENOMEM;
3301
3302 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
3303 scan_id |= arg->scan_id;
3304
3305 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3306 scan_req_id |= arg->scan_req_id;
3307
3308 cmd = (struct wmi_start_scan_cmd *)skb->data;
3309 cmd->scan_id = __cpu_to_le32(scan_id);
3310 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
3311 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3312 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
3313 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
3314 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
3315 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
3316 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
3317 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
3318 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
3319 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
3320 cmd->idle_time = __cpu_to_le32(arg->idle_time);
3321 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
3322 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
3323 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
3324
3325 /* TLV list starts after fields included in the struct */
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003326 /* There's just one filed that differes the two start_scan
3327 * structures - burst_duration, which we are not using btw,
3328 no point to make the split here, just shift the buffer to fit with
3329 given FW */
3330 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3331 off = sizeof(struct wmi_start_scan_cmd_10x);
3332 else
3333 off = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003334
3335 if (arg->n_channels) {
3336 channels = (void *)skb->data + off;
3337 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
3338 channels->num_chan = __cpu_to_le32(arg->n_channels);
3339
3340 for (i = 0; i < arg->n_channels; i++)
Michal Kazior24c88f72014-07-25 13:32:17 +02003341 channels->channel_list[i].freq =
3342 __cpu_to_le16(arg->channels[i]);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003343
3344 off += sizeof(*channels);
3345 off += sizeof(__le32) * arg->n_channels;
3346 }
3347
3348 if (arg->n_ssids) {
3349 ssids = (void *)skb->data + off;
3350 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
3351 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
3352
3353 for (i = 0; i < arg->n_ssids; i++) {
3354 ssids->ssids[i].ssid_len =
3355 __cpu_to_le32(arg->ssids[i].len);
3356 memcpy(&ssids->ssids[i].ssid,
3357 arg->ssids[i].ssid,
3358 arg->ssids[i].len);
3359 }
3360
3361 off += sizeof(*ssids);
3362 off += sizeof(struct wmi_ssid) * arg->n_ssids;
3363 }
3364
3365 if (arg->n_bssids) {
3366 bssids = (void *)skb->data + off;
3367 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
3368 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
3369
3370 for (i = 0; i < arg->n_bssids; i++)
3371 memcpy(&bssids->bssid_list[i],
3372 arg->bssids[i].bssid,
3373 ETH_ALEN);
3374
3375 off += sizeof(*bssids);
3376 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3377 }
3378
3379 if (arg->ie_len) {
3380 ie = (void *)skb->data + off;
3381 ie->tag = __cpu_to_le32(WMI_IE_TAG);
3382 ie->ie_len = __cpu_to_le32(arg->ie_len);
3383 memcpy(ie->ie_data, arg->ie, arg->ie_len);
3384
3385 off += sizeof(*ie);
3386 off += roundup(arg->ie_len, 4);
3387 }
3388
3389 if (off != skb->len) {
3390 dev_kfree_skb(skb);
3391 return -EINVAL;
3392 }
3393
3394 ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003395 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->start_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003396}
3397
3398void ath10k_wmi_start_scan_init(struct ath10k *ar,
3399 struct wmi_start_scan_arg *arg)
3400{
3401 /* setup commonly used values */
3402 arg->scan_req_id = 1;
3403 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
3404 arg->dwell_time_active = 50;
3405 arg->dwell_time_passive = 150;
3406 arg->min_rest_time = 50;
3407 arg->max_rest_time = 500;
3408 arg->repeat_probe_time = 0;
3409 arg->probe_spacing_time = 0;
3410 arg->idle_time = 0;
Bartosz Markowskic3228922013-10-02 08:48:52 +02003411 arg->max_scan_time = 20000;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003412 arg->probe_delay = 5;
3413 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
3414 | WMI_SCAN_EVENT_COMPLETED
3415 | WMI_SCAN_EVENT_BSS_CHANNEL
3416 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
3417 | WMI_SCAN_EVENT_DEQUEUED;
3418 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
3419 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
3420 arg->n_bssids = 1;
3421 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
3422}
3423
3424int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
3425{
3426 struct wmi_stop_scan_cmd *cmd;
3427 struct sk_buff *skb;
3428 u32 scan_id;
3429 u32 req_id;
3430
3431 if (arg->req_id > 0xFFF)
3432 return -EINVAL;
3433 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
3434 return -EINVAL;
3435
3436 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3437 if (!skb)
3438 return -ENOMEM;
3439
3440 scan_id = arg->u.scan_id;
3441 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
3442
3443 req_id = arg->req_id;
3444 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3445
3446 cmd = (struct wmi_stop_scan_cmd *)skb->data;
3447 cmd->req_type = __cpu_to_le32(arg->req_type);
3448 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
3449 cmd->scan_id = __cpu_to_le32(scan_id);
3450 cmd->scan_req_id = __cpu_to_le32(req_id);
3451
3452 ath10k_dbg(ATH10K_DBG_WMI,
3453 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
3454 arg->req_id, arg->req_type, arg->u.scan_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02003455 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->stop_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003456}
3457
3458int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
3459 enum wmi_vdev_type type,
3460 enum wmi_vdev_subtype subtype,
3461 const u8 macaddr[ETH_ALEN])
3462{
3463 struct wmi_vdev_create_cmd *cmd;
3464 struct sk_buff *skb;
3465
3466 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3467 if (!skb)
3468 return -ENOMEM;
3469
3470 cmd = (struct wmi_vdev_create_cmd *)skb->data;
3471 cmd->vdev_id = __cpu_to_le32(vdev_id);
3472 cmd->vdev_type = __cpu_to_le32(type);
3473 cmd->vdev_subtype = __cpu_to_le32(subtype);
3474 memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
3475
3476 ath10k_dbg(ATH10K_DBG_WMI,
3477 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
3478 vdev_id, type, subtype, macaddr);
3479
Bartosz Markowskice428702013-09-26 17:47:05 +02003480 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003481}
3482
3483int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
3484{
3485 struct wmi_vdev_delete_cmd *cmd;
3486 struct sk_buff *skb;
3487
3488 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3489 if (!skb)
3490 return -ENOMEM;
3491
3492 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
3493 cmd->vdev_id = __cpu_to_le32(vdev_id);
3494
3495 ath10k_dbg(ATH10K_DBG_WMI,
3496 "WMI vdev delete id %d\n", vdev_id);
3497
Bartosz Markowskice428702013-09-26 17:47:05 +02003498 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499}
3500
3501static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3502 const struct wmi_vdev_start_request_arg *arg,
Bartosz Markowskice428702013-09-26 17:47:05 +02003503 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003504{
3505 struct wmi_vdev_start_request_cmd *cmd;
3506 struct sk_buff *skb;
3507 const char *cmdname;
3508 u32 flags = 0;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003509 u32 ch_flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003510
Bartosz Markowskice428702013-09-26 17:47:05 +02003511 if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
3512 cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513 return -EINVAL;
3514 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
3515 return -EINVAL;
3516 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
3517 return -EINVAL;
3518 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
3519 return -EINVAL;
3520
Bartosz Markowskice428702013-09-26 17:47:05 +02003521 if (cmd_id == ar->wmi.cmd->vdev_start_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003522 cmdname = "start";
Bartosz Markowskice428702013-09-26 17:47:05 +02003523 else if (cmd_id == ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003524 cmdname = "restart";
3525 else
3526 return -EINVAL; /* should not happen, we already check cmd_id */
3527
3528 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3529 if (!skb)
3530 return -ENOMEM;
3531
3532 if (arg->hidden_ssid)
3533 flags |= WMI_VDEV_START_HIDDEN_SSID;
3534 if (arg->pmf_enabled)
3535 flags |= WMI_VDEV_START_PMF_ENABLED;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003536 if (arg->channel.chan_radar)
3537 ch_flags |= WMI_CHAN_FLAG_DFS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003538
3539 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
3540 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3541 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
3542 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
3543 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
3544 cmd->flags = __cpu_to_le32(flags);
3545 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
3546 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
3547
3548 if (arg->ssid) {
3549 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
3550 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
3551 }
3552
3553 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
3554
3555 cmd->chan.band_center_freq1 =
3556 __cpu_to_le32(arg->channel.band_center_freq1);
3557
3558 cmd->chan.mode = arg->channel.mode;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003559 cmd->chan.flags |= __cpu_to_le32(ch_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003560 cmd->chan.min_power = arg->channel.min_power;
3561 cmd->chan.max_power = arg->channel.max_power;
3562 cmd->chan.reg_power = arg->channel.max_reg_power;
3563 cmd->chan.reg_classid = arg->channel.reg_class_id;
3564 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
3565
3566 ath10k_dbg(ATH10K_DBG_WMI,
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003567 "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, "
3568 "ch_flags: 0x%0X, max_power: %d\n", cmdname, arg->vdev_id,
3569 flags, arg->channel.freq, arg->channel.mode,
3570 cmd->chan.flags, arg->channel.max_power);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003571
3572 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
3573}
3574
3575int ath10k_wmi_vdev_start(struct ath10k *ar,
3576 const struct wmi_vdev_start_request_arg *arg)
3577{
Bartosz Markowskice428702013-09-26 17:47:05 +02003578 u32 cmd_id = ar->wmi.cmd->vdev_start_request_cmdid;
3579
3580 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003581}
3582
3583int ath10k_wmi_vdev_restart(struct ath10k *ar,
3584 const struct wmi_vdev_start_request_arg *arg)
3585{
Bartosz Markowskice428702013-09-26 17:47:05 +02003586 u32 cmd_id = ar->wmi.cmd->vdev_restart_request_cmdid;
3587
3588 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003589}
3590
3591int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
3592{
3593 struct wmi_vdev_stop_cmd *cmd;
3594 struct sk_buff *skb;
3595
3596 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3597 if (!skb)
3598 return -ENOMEM;
3599
3600 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
3601 cmd->vdev_id = __cpu_to_le32(vdev_id);
3602
3603 ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
3604
Bartosz Markowskice428702013-09-26 17:47:05 +02003605 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_stop_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003606}
3607
3608int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
3609{
3610 struct wmi_vdev_up_cmd *cmd;
3611 struct sk_buff *skb;
3612
3613 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3614 if (!skb)
3615 return -ENOMEM;
3616
3617 cmd = (struct wmi_vdev_up_cmd *)skb->data;
3618 cmd->vdev_id = __cpu_to_le32(vdev_id);
3619 cmd->vdev_assoc_id = __cpu_to_le32(aid);
Joe Perches7b4371e2013-10-02 20:39:11 -07003620 memcpy(&cmd->vdev_bssid.addr, bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621
3622 ath10k_dbg(ATH10K_DBG_WMI,
3623 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
3624 vdev_id, aid, bssid);
3625
Bartosz Markowskice428702013-09-26 17:47:05 +02003626 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_up_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003627}
3628
3629int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
3630{
3631 struct wmi_vdev_down_cmd *cmd;
3632 struct sk_buff *skb;
3633
3634 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3635 if (!skb)
3636 return -ENOMEM;
3637
3638 cmd = (struct wmi_vdev_down_cmd *)skb->data;
3639 cmd->vdev_id = __cpu_to_le32(vdev_id);
3640
3641 ath10k_dbg(ATH10K_DBG_WMI,
3642 "wmi mgmt vdev down id 0x%x\n", vdev_id);
3643
Bartosz Markowskice428702013-09-26 17:47:05 +02003644 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_down_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003645}
3646
3647int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003648 u32 param_id, u32 param_value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003649{
3650 struct wmi_vdev_set_param_cmd *cmd;
3651 struct sk_buff *skb;
3652
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003653 if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
3654 ath10k_dbg(ATH10K_DBG_WMI,
3655 "vdev param %d not supported by firmware\n",
3656 param_id);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003657 return -EOPNOTSUPP;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003658 }
3659
Kalle Valo5e3dd152013-06-12 20:52:10 +03003660 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3661 if (!skb)
3662 return -ENOMEM;
3663
3664 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
3665 cmd->vdev_id = __cpu_to_le32(vdev_id);
3666 cmd->param_id = __cpu_to_le32(param_id);
3667 cmd->param_value = __cpu_to_le32(param_value);
3668
3669 ath10k_dbg(ATH10K_DBG_WMI,
3670 "wmi vdev id 0x%x set param %d value %d\n",
3671 vdev_id, param_id, param_value);
3672
Bartosz Markowskice428702013-09-26 17:47:05 +02003673 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003674}
3675
3676int ath10k_wmi_vdev_install_key(struct ath10k *ar,
3677 const struct wmi_vdev_install_key_arg *arg)
3678{
3679 struct wmi_vdev_install_key_cmd *cmd;
3680 struct sk_buff *skb;
3681
3682 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
3683 return -EINVAL;
3684 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
3685 return -EINVAL;
3686
3687 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
3688 if (!skb)
3689 return -ENOMEM;
3690
3691 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
3692 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3693 cmd->key_idx = __cpu_to_le32(arg->key_idx);
3694 cmd->key_flags = __cpu_to_le32(arg->key_flags);
3695 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
3696 cmd->key_len = __cpu_to_le32(arg->key_len);
3697 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
3698 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
3699
3700 if (arg->macaddr)
3701 memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
3702 if (arg->key_data)
3703 memcpy(cmd->key_data, arg->key_data, arg->key_len);
3704
Michal Kaziore0c508a2013-07-05 16:15:17 +03003705 ath10k_dbg(ATH10K_DBG_WMI,
3706 "wmi vdev install key idx %d cipher %d len %d\n",
3707 arg->key_idx, arg->key_cipher, arg->key_len);
Bartosz Markowskice428702013-09-26 17:47:05 +02003708 return ath10k_wmi_cmd_send(ar, skb,
3709 ar->wmi.cmd->vdev_install_key_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003710}
3711
Simon Wunderlich855aed12014-08-02 09:12:54 +03003712int ath10k_wmi_vdev_spectral_conf(struct ath10k *ar,
3713 const struct wmi_vdev_spectral_conf_arg *arg)
3714{
3715 struct wmi_vdev_spectral_conf_cmd *cmd;
3716 struct sk_buff *skb;
3717 u32 cmdid;
3718
3719 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3720 if (!skb)
3721 return -ENOMEM;
3722
3723 cmd = (struct wmi_vdev_spectral_conf_cmd *)skb->data;
3724 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3725 cmd->scan_count = __cpu_to_le32(arg->scan_count);
3726 cmd->scan_period = __cpu_to_le32(arg->scan_period);
3727 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
3728 cmd->scan_fft_size = __cpu_to_le32(arg->scan_fft_size);
3729 cmd->scan_gc_ena = __cpu_to_le32(arg->scan_gc_ena);
3730 cmd->scan_restart_ena = __cpu_to_le32(arg->scan_restart_ena);
3731 cmd->scan_noise_floor_ref = __cpu_to_le32(arg->scan_noise_floor_ref);
3732 cmd->scan_init_delay = __cpu_to_le32(arg->scan_init_delay);
3733 cmd->scan_nb_tone_thr = __cpu_to_le32(arg->scan_nb_tone_thr);
3734 cmd->scan_str_bin_thr = __cpu_to_le32(arg->scan_str_bin_thr);
3735 cmd->scan_wb_rpt_mode = __cpu_to_le32(arg->scan_wb_rpt_mode);
3736 cmd->scan_rssi_rpt_mode = __cpu_to_le32(arg->scan_rssi_rpt_mode);
3737 cmd->scan_rssi_thr = __cpu_to_le32(arg->scan_rssi_thr);
3738 cmd->scan_pwr_format = __cpu_to_le32(arg->scan_pwr_format);
3739 cmd->scan_rpt_mode = __cpu_to_le32(arg->scan_rpt_mode);
3740 cmd->scan_bin_scale = __cpu_to_le32(arg->scan_bin_scale);
3741 cmd->scan_dbm_adj = __cpu_to_le32(arg->scan_dbm_adj);
3742 cmd->scan_chn_mask = __cpu_to_le32(arg->scan_chn_mask);
3743
3744 cmdid = ar->wmi.cmd->vdev_spectral_scan_configure_cmdid;
3745 return ath10k_wmi_cmd_send(ar, skb, cmdid);
3746}
3747
3748int ath10k_wmi_vdev_spectral_enable(struct ath10k *ar, u32 vdev_id, u32 trigger,
3749 u32 enable)
3750{
3751 struct wmi_vdev_spectral_enable_cmd *cmd;
3752 struct sk_buff *skb;
3753 u32 cmdid;
3754
3755 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3756 if (!skb)
3757 return -ENOMEM;
3758
3759 cmd = (struct wmi_vdev_spectral_enable_cmd *)skb->data;
3760 cmd->vdev_id = __cpu_to_le32(vdev_id);
3761 cmd->trigger_cmd = __cpu_to_le32(trigger);
3762 cmd->enable_cmd = __cpu_to_le32(enable);
3763
3764 cmdid = ar->wmi.cmd->vdev_spectral_scan_enable_cmdid;
3765 return ath10k_wmi_cmd_send(ar, skb, cmdid);
3766}
3767
Kalle Valo5e3dd152013-06-12 20:52:10 +03003768int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
3769 const u8 peer_addr[ETH_ALEN])
3770{
3771 struct wmi_peer_create_cmd *cmd;
3772 struct sk_buff *skb;
3773
3774 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3775 if (!skb)
3776 return -ENOMEM;
3777
3778 cmd = (struct wmi_peer_create_cmd *)skb->data;
3779 cmd->vdev_id = __cpu_to_le32(vdev_id);
3780 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3781
3782 ath10k_dbg(ATH10K_DBG_WMI,
3783 "wmi peer create vdev_id %d peer_addr %pM\n",
3784 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003785 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003786}
3787
3788int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
3789 const u8 peer_addr[ETH_ALEN])
3790{
3791 struct wmi_peer_delete_cmd *cmd;
3792 struct sk_buff *skb;
3793
3794 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3795 if (!skb)
3796 return -ENOMEM;
3797
3798 cmd = (struct wmi_peer_delete_cmd *)skb->data;
3799 cmd->vdev_id = __cpu_to_le32(vdev_id);
3800 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3801
3802 ath10k_dbg(ATH10K_DBG_WMI,
3803 "wmi peer delete vdev_id %d peer_addr %pM\n",
3804 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003805 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003806}
3807
3808int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
3809 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
3810{
3811 struct wmi_peer_flush_tids_cmd *cmd;
3812 struct sk_buff *skb;
3813
3814 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3815 if (!skb)
3816 return -ENOMEM;
3817
3818 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
3819 cmd->vdev_id = __cpu_to_le32(vdev_id);
3820 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
3821 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3822
3823 ath10k_dbg(ATH10K_DBG_WMI,
3824 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
3825 vdev_id, peer_addr, tid_bitmap);
Bartosz Markowskice428702013-09-26 17:47:05 +02003826 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_flush_tids_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827}
3828
3829int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
3830 const u8 *peer_addr, enum wmi_peer_param param_id,
3831 u32 param_value)
3832{
3833 struct wmi_peer_set_param_cmd *cmd;
3834 struct sk_buff *skb;
3835
3836 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3837 if (!skb)
3838 return -ENOMEM;
3839
3840 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
3841 cmd->vdev_id = __cpu_to_le32(vdev_id);
3842 cmd->param_id = __cpu_to_le32(param_id);
3843 cmd->param_value = __cpu_to_le32(param_value);
Joe Perchesd458cdf2013-10-01 19:04:40 -07003844 memcpy(&cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003845
3846 ath10k_dbg(ATH10K_DBG_WMI,
3847 "wmi vdev %d peer 0x%pM set param %d value %d\n",
3848 vdev_id, peer_addr, param_id, param_value);
3849
Bartosz Markowskice428702013-09-26 17:47:05 +02003850 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003851}
3852
3853int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
3854 enum wmi_sta_ps_mode psmode)
3855{
3856 struct wmi_sta_powersave_mode_cmd *cmd;
3857 struct sk_buff *skb;
3858
3859 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3860 if (!skb)
3861 return -ENOMEM;
3862
3863 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
3864 cmd->vdev_id = __cpu_to_le32(vdev_id);
3865 cmd->sta_ps_mode = __cpu_to_le32(psmode);
3866
3867 ath10k_dbg(ATH10K_DBG_WMI,
3868 "wmi set powersave id 0x%x mode %d\n",
3869 vdev_id, psmode);
3870
Bartosz Markowskice428702013-09-26 17:47:05 +02003871 return ath10k_wmi_cmd_send(ar, skb,
3872 ar->wmi.cmd->sta_powersave_mode_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003873}
3874
3875int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
3876 enum wmi_sta_powersave_param param_id,
3877 u32 value)
3878{
3879 struct wmi_sta_powersave_param_cmd *cmd;
3880 struct sk_buff *skb;
3881
3882 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3883 if (!skb)
3884 return -ENOMEM;
3885
3886 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
3887 cmd->vdev_id = __cpu_to_le32(vdev_id);
3888 cmd->param_id = __cpu_to_le32(param_id);
3889 cmd->param_value = __cpu_to_le32(value);
3890
3891 ath10k_dbg(ATH10K_DBG_WMI,
3892 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
3893 vdev_id, param_id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02003894 return ath10k_wmi_cmd_send(ar, skb,
3895 ar->wmi.cmd->sta_powersave_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003896}
3897
3898int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
3899 enum wmi_ap_ps_peer_param param_id, u32 value)
3900{
3901 struct wmi_ap_ps_peer_cmd *cmd;
3902 struct sk_buff *skb;
3903
3904 if (!mac)
3905 return -EINVAL;
3906
3907 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3908 if (!skb)
3909 return -ENOMEM;
3910
3911 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
3912 cmd->vdev_id = __cpu_to_le32(vdev_id);
3913 cmd->param_id = __cpu_to_le32(param_id);
3914 cmd->param_value = __cpu_to_le32(value);
3915 memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
3916
3917 ath10k_dbg(ATH10K_DBG_WMI,
3918 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
3919 vdev_id, param_id, value, mac);
3920
Bartosz Markowskice428702013-09-26 17:47:05 +02003921 return ath10k_wmi_cmd_send(ar, skb,
3922 ar->wmi.cmd->ap_ps_peer_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003923}
3924
3925int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3926 const struct wmi_scan_chan_list_arg *arg)
3927{
3928 struct wmi_scan_chan_list_cmd *cmd;
3929 struct sk_buff *skb;
3930 struct wmi_channel_arg *ch;
3931 struct wmi_channel *ci;
3932 int len;
3933 int i;
3934
3935 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
3936
3937 skb = ath10k_wmi_alloc_skb(len);
3938 if (!skb)
3939 return -EINVAL;
3940
3941 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
3942 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3943
3944 for (i = 0; i < arg->n_channels; i++) {
3945 u32 flags = 0;
3946
3947 ch = &arg->channels[i];
3948 ci = &cmd->chan_info[i];
3949
3950 if (ch->passive)
3951 flags |= WMI_CHAN_FLAG_PASSIVE;
3952 if (ch->allow_ibss)
3953 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
3954 if (ch->allow_ht)
3955 flags |= WMI_CHAN_FLAG_ALLOW_HT;
3956 if (ch->allow_vht)
3957 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
3958 if (ch->ht40plus)
3959 flags |= WMI_CHAN_FLAG_HT40_PLUS;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003960 if (ch->chan_radar)
3961 flags |= WMI_CHAN_FLAG_DFS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962
3963 ci->mhz = __cpu_to_le32(ch->freq);
3964 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
3965 ci->band_center_freq2 = 0;
3966 ci->min_power = ch->min_power;
3967 ci->max_power = ch->max_power;
3968 ci->reg_power = ch->max_reg_power;
3969 ci->antenna_max = ch->max_antenna_gain;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003970
3971 /* mode & flags share storage */
3972 ci->mode = ch->mode;
3973 ci->flags |= __cpu_to_le32(flags);
3974 }
3975
Bartosz Markowskice428702013-09-26 17:47:05 +02003976 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003977}
3978
Michal Kazior24c88f72014-07-25 13:32:17 +02003979static void
3980ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
3981 const struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003982{
Michal Kazior24c88f72014-07-25 13:32:17 +02003983 struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003984
Kalle Valo5e3dd152013-06-12 20:52:10 +03003985 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3986 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
3987 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
3988 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
3989 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
3990 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
3991 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
3992 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
3993 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
3994 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
3995 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
3996 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
3997 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
3998
3999 memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
4000
4001 cmd->peer_legacy_rates.num_rates =
4002 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
4003 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
4004 arg->peer_legacy_rates.num_rates);
4005
4006 cmd->peer_ht_rates.num_rates =
4007 __cpu_to_le32(arg->peer_ht_rates.num_rates);
4008 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
4009 arg->peer_ht_rates.num_rates);
4010
4011 cmd->peer_vht_rates.rx_max_rate =
4012 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
4013 cmd->peer_vht_rates.rx_mcs_set =
4014 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
4015 cmd->peer_vht_rates.tx_max_rate =
4016 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
4017 cmd->peer_vht_rates.tx_mcs_set =
4018 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
Michal Kazior24c88f72014-07-25 13:32:17 +02004019}
4020
4021static void
4022ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
4023 const struct wmi_peer_assoc_complete_arg *arg)
4024{
4025 struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
4026
4027 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
4028 memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
4029}
4030
4031static void
4032ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
4033 const struct wmi_peer_assoc_complete_arg *arg)
4034{
4035 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
4036}
4037
4038static void
4039ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
4040 const struct wmi_peer_assoc_complete_arg *arg)
4041{
4042 struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
4043 int max_mcs, max_nss;
4044 u32 info0;
4045
4046 /* TODO: Is using max values okay with firmware? */
4047 max_mcs = 0xf;
4048 max_nss = 0xf;
4049
4050 info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
4051 SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
4052
4053 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
4054 cmd->info0 = __cpu_to_le32(info0);
4055}
4056
4057int ath10k_wmi_peer_assoc(struct ath10k *ar,
4058 const struct wmi_peer_assoc_complete_arg *arg)
4059{
4060 struct sk_buff *skb;
4061 int len;
4062
4063 if (arg->peer_mpdu_density > 16)
4064 return -EINVAL;
4065 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
4066 return -EINVAL;
4067 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
4068 return -EINVAL;
4069
4070 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4071 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4072 len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
4073 else
4074 len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
4075 } else {
4076 len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
4077 }
4078
4079 skb = ath10k_wmi_alloc_skb(len);
4080 if (!skb)
4081 return -ENOMEM;
4082
4083 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4084 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
4085 ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
4086 else
4087 ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
4088 } else {
4089 ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
4090 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004091
Michal Kaziore0c508a2013-07-05 16:15:17 +03004092 ath10k_dbg(ATH10K_DBG_WMI,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004093 "wmi peer assoc vdev %d addr %pM (%s)\n",
4094 arg->vdev_id, arg->addr,
4095 arg->peer_reassoc ? "reassociate" : "new");
Bartosz Markowskice428702013-09-26 17:47:05 +02004096 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_assoc_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004097}
4098
Michal Kazior748afc42014-01-23 12:48:21 +01004099/* This function assumes the beacon is already DMA mapped */
4100int ath10k_wmi_beacon_send_ref_nowait(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004101{
Michal Kazior748afc42014-01-23 12:48:21 +01004102 struct wmi_bcn_tx_ref_cmd *cmd;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004103 struct sk_buff *skb;
Michal Kazior748afc42014-01-23 12:48:21 +01004104 struct sk_buff *beacon = arvif->beacon;
4105 struct ath10k *ar = arvif->ar;
4106 struct ieee80211_hdr *hdr;
Michal Kaziore2045482013-10-28 07:18:14 +01004107 int ret;
Michal Kazior748afc42014-01-23 12:48:21 +01004108 u16 fc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004109
Michal Kazior748afc42014-01-23 12:48:21 +01004110 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03004111 if (!skb)
4112 return -ENOMEM;
4113
Michal Kazior748afc42014-01-23 12:48:21 +01004114 hdr = (struct ieee80211_hdr *)beacon->data;
4115 fc = le16_to_cpu(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004116
Michal Kazior748afc42014-01-23 12:48:21 +01004117 cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
4118 cmd->vdev_id = __cpu_to_le32(arvif->vdev_id);
4119 cmd->data_len = __cpu_to_le32(beacon->len);
4120 cmd->data_ptr = __cpu_to_le32(ATH10K_SKB_CB(beacon)->paddr);
4121 cmd->msdu_id = 0;
4122 cmd->frame_control = __cpu_to_le32(fc);
4123 cmd->flags = 0;
Michal Kazior24c88f72014-07-25 13:32:17 +02004124 cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
Michal Kazior748afc42014-01-23 12:48:21 +01004125
4126 if (ATH10K_SKB_CB(beacon)->bcn.dtim_zero)
4127 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
4128
4129 if (ATH10K_SKB_CB(beacon)->bcn.deliver_cab)
4130 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
4131
4132 ret = ath10k_wmi_cmd_send_nowait(ar, skb,
4133 ar->wmi.cmd->pdev_send_bcn_cmdid);
4134
Michal Kaziore2045482013-10-28 07:18:14 +01004135 if (ret)
4136 dev_kfree_skb(skb);
4137
4138 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004139}
4140
4141static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
4142 const struct wmi_wmm_params_arg *arg)
4143{
4144 params->cwmin = __cpu_to_le32(arg->cwmin);
4145 params->cwmax = __cpu_to_le32(arg->cwmax);
4146 params->aifs = __cpu_to_le32(arg->aifs);
4147 params->txop = __cpu_to_le32(arg->txop);
4148 params->acm = __cpu_to_le32(arg->acm);
4149 params->no_ack = __cpu_to_le32(arg->no_ack);
4150}
4151
4152int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
4153 const struct wmi_pdev_set_wmm_params_arg *arg)
4154{
4155 struct wmi_pdev_set_wmm_params *cmd;
4156 struct sk_buff *skb;
4157
4158 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
4159 if (!skb)
4160 return -ENOMEM;
4161
4162 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
4163 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
4164 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
4165 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
4166 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
4167
4168 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02004169 return ath10k_wmi_cmd_send(ar, skb,
4170 ar->wmi.cmd->pdev_set_wmm_params_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004171}
4172
4173int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
4174{
4175 struct wmi_request_stats_cmd *cmd;
4176 struct sk_buff *skb;
4177
4178 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
4179 if (!skb)
4180 return -ENOMEM;
4181
4182 cmd = (struct wmi_request_stats_cmd *)skb->data;
4183 cmd->stats_id = __cpu_to_le32(stats_id);
4184
4185 ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02004186 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->request_stats_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004187}
Michal Kazior9cfbce72013-07-16 09:54:36 +02004188
4189int ath10k_wmi_force_fw_hang(struct ath10k *ar,
4190 enum wmi_force_fw_hang_type type, u32 delay_ms)
4191{
4192 struct wmi_force_fw_hang_cmd *cmd;
4193 struct sk_buff *skb;
4194
4195 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
4196 if (!skb)
4197 return -ENOMEM;
4198
4199 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
4200 cmd->type = __cpu_to_le32(type);
4201 cmd->delay_ms = __cpu_to_le32(delay_ms);
4202
4203 ath10k_dbg(ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
4204 type, delay_ms);
Bartosz Markowskice428702013-09-26 17:47:05 +02004205 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
Michal Kazior9cfbce72013-07-16 09:54:36 +02004206}
Kalle Valof118a3e2014-01-03 12:59:31 +02004207
4208int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable)
4209{
4210 struct wmi_dbglog_cfg_cmd *cmd;
4211 struct sk_buff *skb;
4212 u32 cfg;
4213
4214 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
4215 if (!skb)
4216 return -ENOMEM;
4217
4218 cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
4219
4220 if (module_enable) {
4221 cfg = SM(ATH10K_DBGLOG_LEVEL_VERBOSE,
4222 ATH10K_DBGLOG_CFG_LOG_LVL);
4223 } else {
4224 /* set back defaults, all modules with WARN level */
4225 cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
4226 ATH10K_DBGLOG_CFG_LOG_LVL);
4227 module_enable = ~0;
4228 }
4229
4230 cmd->module_enable = __cpu_to_le32(module_enable);
4231 cmd->module_valid = __cpu_to_le32(~0);
4232 cmd->config_enable = __cpu_to_le32(cfg);
4233 cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
4234
4235 ath10k_dbg(ATH10K_DBG_WMI,
4236 "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
4237 __le32_to_cpu(cmd->module_enable),
4238 __le32_to_cpu(cmd->module_valid),
4239 __le32_to_cpu(cmd->config_enable),
4240 __le32_to_cpu(cmd->config_valid));
4241
4242 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid);
4243}