blob: b09661db9447a057a795112bb560153cc8d9106b [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
Kalle Valo5e3dd152013-06-12 20:52:10 +0300814static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
815{
816 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
817 enum wmi_scan_event_type event_type;
818 enum wmi_scan_completion_reason reason;
819 u32 freq;
820 u32 req_id;
821 u32 scan_id;
822 u32 vdev_id;
823
824 event_type = __le32_to_cpu(event->event_type);
825 reason = __le32_to_cpu(event->reason);
826 freq = __le32_to_cpu(event->channel_freq);
827 req_id = __le32_to_cpu(event->scan_req_id);
828 scan_id = __le32_to_cpu(event->scan_id);
829 vdev_id = __le32_to_cpu(event->vdev_id);
830
831 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENTID\n");
832 ath10k_dbg(ATH10K_DBG_WMI,
833 "scan event type %d reason %d freq %d req_id %d "
834 "scan_id %d vdev_id %d\n",
835 event_type, reason, freq, req_id, scan_id, vdev_id);
836
837 spin_lock_bh(&ar->data_lock);
838
839 switch (event_type) {
840 case WMI_SCAN_EVENT_STARTED:
841 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_STARTED\n");
842 if (ar->scan.in_progress && ar->scan.is_roc)
843 ieee80211_ready_on_channel(ar->hw);
844
845 complete(&ar->scan.started);
846 break;
847 case WMI_SCAN_EVENT_COMPLETED:
848 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_COMPLETED\n");
849 switch (reason) {
850 case WMI_SCAN_REASON_COMPLETED:
851 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_COMPLETED\n");
852 break;
853 case WMI_SCAN_REASON_CANCELLED:
854 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_CANCELED\n");
855 break;
856 case WMI_SCAN_REASON_PREEMPTED:
857 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_PREEMPTED\n");
858 break;
859 case WMI_SCAN_REASON_TIMEDOUT:
860 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_TIMEDOUT\n");
861 break;
862 default:
863 break;
864 }
865
866 ar->scan_channel = NULL;
867 if (!ar->scan.in_progress) {
868 ath10k_warn("no scan requested, ignoring\n");
869 break;
870 }
871
872 if (ar->scan.is_roc) {
873 ath10k_offchan_tx_purge(ar);
874
875 if (!ar->scan.aborting)
876 ieee80211_remain_on_channel_expired(ar->hw);
877 } else {
878 ieee80211_scan_completed(ar->hw, ar->scan.aborting);
879 }
880
881 del_timer(&ar->scan.timeout);
882 complete_all(&ar->scan.completed);
883 ar->scan.in_progress = false;
884 break;
885 case WMI_SCAN_EVENT_BSS_CHANNEL:
886 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_BSS_CHANNEL\n");
887 ar->scan_channel = NULL;
888 break;
889 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
890 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_FOREIGN_CHANNEL\n");
891 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
892 if (ar->scan.in_progress && ar->scan.is_roc &&
893 ar->scan.roc_freq == freq) {
894 complete(&ar->scan.on_channel);
895 }
896 break;
897 case WMI_SCAN_EVENT_DEQUEUED:
898 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_DEQUEUED\n");
899 break;
900 case WMI_SCAN_EVENT_PREEMPTED:
901 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_PREEMPTED\n");
902 break;
903 case WMI_SCAN_EVENT_START_FAILED:
904 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_START_FAILED\n");
905 break;
906 default:
907 break;
908 }
909
910 spin_unlock_bh(&ar->data_lock);
911 return 0;
912}
913
914static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
915{
916 enum ieee80211_band band;
917
918 switch (phy_mode) {
919 case MODE_11A:
920 case MODE_11NA_HT20:
921 case MODE_11NA_HT40:
922 case MODE_11AC_VHT20:
923 case MODE_11AC_VHT40:
924 case MODE_11AC_VHT80:
925 band = IEEE80211_BAND_5GHZ;
926 break;
927 case MODE_11G:
928 case MODE_11B:
929 case MODE_11GONLY:
930 case MODE_11NG_HT20:
931 case MODE_11NG_HT40:
932 case MODE_11AC_VHT20_2G:
933 case MODE_11AC_VHT40_2G:
934 case MODE_11AC_VHT80_2G:
935 default:
936 band = IEEE80211_BAND_2GHZ;
937 }
938
939 return band;
940}
941
942static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
943{
944 u8 rate_idx = 0;
945
946 /* rate in Kbps */
947 switch (rate) {
948 case 1000:
949 rate_idx = 0;
950 break;
951 case 2000:
952 rate_idx = 1;
953 break;
954 case 5500:
955 rate_idx = 2;
956 break;
957 case 11000:
958 rate_idx = 3;
959 break;
960 case 6000:
961 rate_idx = 4;
962 break;
963 case 9000:
964 rate_idx = 5;
965 break;
966 case 12000:
967 rate_idx = 6;
968 break;
969 case 18000:
970 rate_idx = 7;
971 break;
972 case 24000:
973 rate_idx = 8;
974 break;
975 case 36000:
976 rate_idx = 9;
977 break;
978 case 48000:
979 rate_idx = 10;
980 break;
981 case 54000:
982 rate_idx = 11;
983 break;
984 default:
985 break;
986 }
987
988 if (band == IEEE80211_BAND_5GHZ) {
989 if (rate_idx > 3)
990 /* Omit CCK rates */
991 rate_idx -= 4;
992 else
993 rate_idx = 0;
994 }
995
996 return rate_idx;
997}
998
999static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
1000{
Michal Kazior0d9b0432013-08-09 10:13:33 +02001001 struct wmi_mgmt_rx_event_v1 *ev_v1;
1002 struct wmi_mgmt_rx_event_v2 *ev_v2;
1003 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001004 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
Michal Kazior453cdb62013-12-13 10:44:43 +01001005 struct ieee80211_channel *ch;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001006 struct ieee80211_hdr *hdr;
1007 u32 rx_status;
1008 u32 channel;
1009 u32 phy_mode;
1010 u32 snr;
1011 u32 rate;
1012 u32 buf_len;
1013 u16 fc;
Michal Kazior0d9b0432013-08-09 10:13:33 +02001014 int pull_len;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001015
Michal Kazior0d9b0432013-08-09 10:13:33 +02001016 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
1017 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
1018 ev_hdr = &ev_v2->hdr.v1;
1019 pull_len = sizeof(*ev_v2);
1020 } else {
1021 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
1022 ev_hdr = &ev_v1->hdr;
1023 pull_len = sizeof(*ev_v1);
1024 }
1025
1026 channel = __le32_to_cpu(ev_hdr->channel);
1027 buf_len = __le32_to_cpu(ev_hdr->buf_len);
1028 rx_status = __le32_to_cpu(ev_hdr->status);
1029 snr = __le32_to_cpu(ev_hdr->snr);
1030 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
1031 rate = __le32_to_cpu(ev_hdr->rate);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001032
1033 memset(status, 0, sizeof(*status));
1034
1035 ath10k_dbg(ATH10K_DBG_MGMT,
1036 "event mgmt rx status %08x\n", rx_status);
1037
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001038 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) {
1039 dev_kfree_skb(skb);
1040 return 0;
1041 }
1042
Kalle Valo5e3dd152013-06-12 20:52:10 +03001043 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
1044 dev_kfree_skb(skb);
1045 return 0;
1046 }
1047
1048 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
1049 dev_kfree_skb(skb);
1050 return 0;
1051 }
1052
1053 if (rx_status & WMI_RX_STATUS_ERR_CRC)
1054 status->flag |= RX_FLAG_FAILED_FCS_CRC;
1055 if (rx_status & WMI_RX_STATUS_ERR_MIC)
1056 status->flag |= RX_FLAG_MMIC_ERROR;
1057
Michal Kazior453cdb62013-12-13 10:44:43 +01001058 /* HW can Rx CCK rates on 5GHz. In that case phy_mode is set to
1059 * MODE_11B. This means phy_mode is not a reliable source for the band
1060 * of mgmt rx. */
1061
1062 ch = ar->scan_channel;
1063 if (!ch)
1064 ch = ar->rx_channel;
1065
1066 if (ch) {
1067 status->band = ch->band;
1068
1069 if (phy_mode == MODE_11B &&
1070 status->band == IEEE80211_BAND_5GHZ)
1071 ath10k_dbg(ATH10K_DBG_MGMT, "wmi mgmt rx 11b (CCK) on 5GHz\n");
1072 } else {
1073 ath10k_warn("using (unreliable) phy_mode to extract band for mgmt rx\n");
1074 status->band = phy_mode_to_band(phy_mode);
1075 }
1076
Kalle Valo5e3dd152013-06-12 20:52:10 +03001077 status->freq = ieee80211_channel_to_frequency(channel, status->band);
1078 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
1079 status->rate_idx = get_rate_idx(rate, status->band);
1080
Michal Kazior0d9b0432013-08-09 10:13:33 +02001081 skb_pull(skb, pull_len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001082
1083 hdr = (struct ieee80211_hdr *)skb->data;
1084 fc = le16_to_cpu(hdr->frame_control);
1085
Michal Kazior2b6a6a92013-12-05 06:53:41 +01001086 /* FW delivers WEP Shared Auth frame with Protected Bit set and
1087 * encrypted payload. However in case of PMF it delivers decrypted
1088 * frames with Protected Bit set. */
1089 if (ieee80211_has_protected(hdr->frame_control) &&
1090 !ieee80211_is_auth(hdr->frame_control)) {
Marek Kwaczynskieeab2662014-05-14 16:56:17 +03001091 status->flag |= RX_FLAG_DECRYPTED;
1092
1093 if (!ieee80211_is_action(hdr->frame_control) &&
1094 !ieee80211_is_deauth(hdr->frame_control) &&
1095 !ieee80211_is_disassoc(hdr->frame_control)) {
1096 status->flag |= RX_FLAG_IV_STRIPPED |
1097 RX_FLAG_MMIC_STRIPPED;
1098 hdr->frame_control = __cpu_to_le16(fc &
Kalle Valo5e3dd152013-06-12 20:52:10 +03001099 ~IEEE80211_FCTL_PROTECTED);
Marek Kwaczynskieeab2662014-05-14 16:56:17 +03001100 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001101 }
1102
1103 ath10k_dbg(ATH10K_DBG_MGMT,
1104 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
1105 skb, skb->len,
1106 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
1107
1108 ath10k_dbg(ATH10K_DBG_MGMT,
1109 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
1110 status->freq, status->band, status->signal,
1111 status->rate_idx);
1112
1113 /*
1114 * packets from HTC come aligned to 4byte boundaries
1115 * because they can originally come in along with a trailer
1116 */
1117 skb_trim(skb, buf_len);
1118
1119 ieee80211_rx(ar->hw, skb);
1120 return 0;
1121}
1122
Michal Kazior2e1dea42013-07-31 10:32:40 +02001123static int freq_to_idx(struct ath10k *ar, int freq)
1124{
1125 struct ieee80211_supported_band *sband;
1126 int band, ch, idx = 0;
1127
1128 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
1129 sband = ar->hw->wiphy->bands[band];
1130 if (!sband)
1131 continue;
1132
1133 for (ch = 0; ch < sband->n_channels; ch++, idx++)
1134 if (sband->channels[ch].center_freq == freq)
1135 goto exit;
1136 }
1137
1138exit:
1139 return idx;
1140}
1141
Kalle Valo5e3dd152013-06-12 20:52:10 +03001142static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
1143{
Michal Kazior2e1dea42013-07-31 10:32:40 +02001144 struct wmi_chan_info_event *ev;
1145 struct survey_info *survey;
1146 u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
1147 int idx;
1148
1149 ev = (struct wmi_chan_info_event *)skb->data;
1150
1151 err_code = __le32_to_cpu(ev->err_code);
1152 freq = __le32_to_cpu(ev->freq);
1153 cmd_flags = __le32_to_cpu(ev->cmd_flags);
1154 noise_floor = __le32_to_cpu(ev->noise_floor);
1155 rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
1156 cycle_count = __le32_to_cpu(ev->cycle_count);
1157
1158 ath10k_dbg(ATH10K_DBG_WMI,
1159 "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
1160 err_code, freq, cmd_flags, noise_floor, rx_clear_count,
1161 cycle_count);
1162
1163 spin_lock_bh(&ar->data_lock);
1164
1165 if (!ar->scan.in_progress) {
1166 ath10k_warn("chan info event without a scan request?\n");
1167 goto exit;
1168 }
1169
1170 idx = freq_to_idx(ar, freq);
1171 if (idx >= ARRAY_SIZE(ar->survey)) {
1172 ath10k_warn("chan info: invalid frequency %d (idx %d out of bounds)\n",
1173 freq, idx);
1174 goto exit;
1175 }
1176
1177 if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
1178 /* During scanning chan info is reported twice for each
1179 * visited channel. The reported cycle count is global
1180 * and per-channel cycle count must be calculated */
1181
1182 cycle_count -= ar->survey_last_cycle_count;
1183 rx_clear_count -= ar->survey_last_rx_clear_count;
1184
1185 survey = &ar->survey[idx];
1186 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
1187 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
1188 survey->noise = noise_floor;
1189 survey->filled = SURVEY_INFO_CHANNEL_TIME |
1190 SURVEY_INFO_CHANNEL_TIME_RX |
1191 SURVEY_INFO_NOISE_DBM;
1192 }
1193
1194 ar->survey_last_rx_clear_count = rx_clear_count;
1195 ar->survey_last_cycle_count = cycle_count;
1196
1197exit:
1198 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001199}
1200
1201static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
1202{
1203 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
1204}
1205
Kalle Valo869526b2014-01-03 12:59:26 +02001206static int ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001207{
Kalle Valo869526b2014-01-03 12:59:26 +02001208 ath10k_dbg(ATH10K_DBG_WMI, "wmi event debug mesg len %d\n",
1209 skb->len);
1210
1211 trace_ath10k_wmi_dbglog(skb->data, skb->len);
1212
1213 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001214}
1215
1216static void ath10k_wmi_event_update_stats(struct ath10k *ar,
1217 struct sk_buff *skb)
1218{
1219 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
1220
1221 ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
1222
1223 ath10k_debug_read_target_stats(ar, ev);
1224}
1225
1226static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
1227 struct sk_buff *skb)
1228{
1229 struct wmi_vdev_start_response_event *ev;
1230
1231 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
1232
1233 ev = (struct wmi_vdev_start_response_event *)skb->data;
1234
1235 if (WARN_ON(__le32_to_cpu(ev->status)))
1236 return;
1237
1238 complete(&ar->vdev_setup_done);
1239}
1240
1241static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
1242 struct sk_buff *skb)
1243{
1244 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
1245 complete(&ar->vdev_setup_done);
1246}
1247
1248static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
1249 struct sk_buff *skb)
1250{
Kalle Valo5a13e762014-01-20 11:01:46 +02001251 struct wmi_peer_sta_kickout_event *ev;
1252 struct ieee80211_sta *sta;
1253
1254 ev = (struct wmi_peer_sta_kickout_event *)skb->data;
1255
1256 ath10k_dbg(ATH10K_DBG_WMI, "wmi event peer sta kickout %pM\n",
1257 ev->peer_macaddr.addr);
1258
1259 rcu_read_lock();
1260
1261 sta = ieee80211_find_sta_by_ifaddr(ar->hw, ev->peer_macaddr.addr, NULL);
1262 if (!sta) {
1263 ath10k_warn("Spurious quick kickout for STA %pM\n",
1264 ev->peer_macaddr.addr);
1265 goto exit;
1266 }
1267
1268 ieee80211_report_low_ack(sta, 10);
1269
1270exit:
1271 rcu_read_unlock();
Kalle Valo5e3dd152013-06-12 20:52:10 +03001272}
1273
1274/*
1275 * FIXME
1276 *
1277 * We don't report to mac80211 sleep state of connected
1278 * stations. Due to this mac80211 can't fill in TIM IE
1279 * correctly.
1280 *
1281 * I know of no way of getting nullfunc frames that contain
1282 * sleep transition from connected stations - these do not
1283 * seem to be sent from the target to the host. There also
1284 * doesn't seem to be a dedicated event for that. So the
1285 * only way left to do this would be to read tim_bitmap
1286 * during SWBA.
1287 *
1288 * We could probably try using tim_bitmap from SWBA to tell
1289 * mac80211 which stations are asleep and which are not. The
1290 * problem here is calling mac80211 functions so many times
1291 * could take too long and make us miss the time to submit
1292 * the beacon to the target.
1293 *
1294 * So as a workaround we try to extend the TIM IE if there
1295 * is unicast buffered for stations with aid > 7 and fill it
1296 * in ourselves.
1297 */
1298static void ath10k_wmi_update_tim(struct ath10k *ar,
1299 struct ath10k_vif *arvif,
1300 struct sk_buff *bcn,
1301 struct wmi_bcn_info *bcn_info)
1302{
1303 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
1304 struct ieee80211_tim_ie *tim;
1305 u8 *ies, *ie;
1306 u8 ie_len, pvm_len;
1307
1308 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
1309 * we must copy the bitmap upon change and reuse it later */
1310 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
1311 int i;
1312
1313 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
1314 sizeof(bcn_info->tim_info.tim_bitmap));
1315
1316 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
1317 __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
1318 u32 v = __le32_to_cpu(t);
1319 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
1320 }
1321
1322 /* FW reports either length 0 or 16
1323 * so we calculate this on our own */
1324 arvif->u.ap.tim_len = 0;
1325 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
1326 if (arvif->u.ap.tim_bitmap[i])
1327 arvif->u.ap.tim_len = i;
1328
1329 arvif->u.ap.tim_len++;
1330 }
1331
1332 ies = bcn->data;
1333 ies += ieee80211_hdrlen(hdr->frame_control);
1334 ies += 12; /* fixed parameters */
1335
1336 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
1337 (u8 *)skb_tail_pointer(bcn) - ies);
1338 if (!ie) {
Michal Kazior09af8f82013-07-05 16:15:08 +03001339 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1340 ath10k_warn("no tim ie found;\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03001341 return;
1342 }
1343
1344 tim = (void *)ie + 2;
1345 ie_len = ie[1];
1346 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
1347
1348 if (pvm_len < arvif->u.ap.tim_len) {
1349 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
1350 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
1351 void *next_ie = ie + 2 + ie_len;
1352
1353 if (skb_put(bcn, expand_size)) {
1354 memmove(next_ie + expand_size, next_ie, move_size);
1355
1356 ie[1] += expand_size;
1357 ie_len += expand_size;
1358 pvm_len += expand_size;
1359 } else {
1360 ath10k_warn("tim expansion failed\n");
1361 }
1362 }
1363
1364 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
1365 ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
1366 return;
1367 }
1368
1369 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
1370 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
1371
Michal Kazior748afc42014-01-23 12:48:21 +01001372 if (tim->dtim_count == 0) {
1373 ATH10K_SKB_CB(bcn)->bcn.dtim_zero = true;
1374
1375 if (__le32_to_cpu(bcn_info->tim_info.tim_mcast) == 1)
1376 ATH10K_SKB_CB(bcn)->bcn.deliver_cab = true;
1377 }
1378
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379 ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
1380 tim->dtim_count, tim->dtim_period,
1381 tim->bitmap_ctrl, pvm_len);
1382}
1383
1384static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
1385 struct wmi_p2p_noa_info *noa)
1386{
1387 struct ieee80211_p2p_noa_attr *noa_attr;
1388 u8 ctwindow_oppps = noa->ctwindow_oppps;
1389 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
1390 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
1391 __le16 *noa_attr_len;
1392 u16 attr_len;
1393 u8 noa_descriptors = noa->num_descriptors;
1394 int i;
1395
1396 /* P2P IE */
1397 data[0] = WLAN_EID_VENDOR_SPECIFIC;
1398 data[1] = len - 2;
1399 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1400 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1401 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1402 data[5] = WLAN_OUI_TYPE_WFA_P2P;
1403
1404 /* NOA ATTR */
1405 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
1406 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
1407 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
1408
1409 noa_attr->index = noa->index;
1410 noa_attr->oppps_ctwindow = ctwindow;
1411 if (oppps)
1412 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
1413
1414 for (i = 0; i < noa_descriptors; i++) {
1415 noa_attr->desc[i].count =
1416 __le32_to_cpu(noa->descriptors[i].type_count);
1417 noa_attr->desc[i].duration = noa->descriptors[i].duration;
1418 noa_attr->desc[i].interval = noa->descriptors[i].interval;
1419 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
1420 }
1421
1422 attr_len = 2; /* index + oppps_ctwindow */
1423 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1424 *noa_attr_len = __cpu_to_le16(attr_len);
1425}
1426
1427static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
1428{
1429 u32 len = 0;
1430 u8 noa_descriptors = noa->num_descriptors;
1431 u8 opp_ps_info = noa->ctwindow_oppps;
1432 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
1433
1434
1435 if (!noa_descriptors && !opps_enabled)
1436 return len;
1437
1438 len += 1 + 1 + 4; /* EID + len + OUI */
1439 len += 1 + 2; /* noa attr + attr len */
1440 len += 1 + 1; /* index + oppps_ctwindow */
1441 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
1442
1443 return len;
1444}
1445
1446static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
1447 struct sk_buff *bcn,
1448 struct wmi_bcn_info *bcn_info)
1449{
1450 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
1451 u8 *new_data, *old_data = arvif->u.ap.noa_data;
1452 u32 new_len;
1453
1454 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1455 return;
1456
1457 ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
1458 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
1459 new_len = ath10k_p2p_calc_noa_ie_len(noa);
1460 if (!new_len)
1461 goto cleanup;
1462
1463 new_data = kmalloc(new_len, GFP_ATOMIC);
1464 if (!new_data)
1465 goto cleanup;
1466
1467 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
1468
1469 spin_lock_bh(&ar->data_lock);
1470 arvif->u.ap.noa_data = new_data;
1471 arvif->u.ap.noa_len = new_len;
1472 spin_unlock_bh(&ar->data_lock);
1473 kfree(old_data);
1474 }
1475
1476 if (arvif->u.ap.noa_data)
1477 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
1478 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
1479 arvif->u.ap.noa_data,
1480 arvif->u.ap.noa_len);
1481 return;
1482
1483cleanup:
1484 spin_lock_bh(&ar->data_lock);
1485 arvif->u.ap.noa_data = NULL;
1486 arvif->u.ap.noa_len = 0;
1487 spin_unlock_bh(&ar->data_lock);
1488 kfree(old_data);
1489}
1490
1491
1492static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
1493{
1494 struct wmi_host_swba_event *ev;
1495 u32 map;
1496 int i = -1;
1497 struct wmi_bcn_info *bcn_info;
1498 struct ath10k_vif *arvif;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001499 struct sk_buff *bcn;
Michal Kazior767d34f2014-02-27 18:50:03 +02001500 int ret, vdev_id = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001501
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502 ev = (struct wmi_host_swba_event *)skb->data;
1503 map = __le32_to_cpu(ev->vdev_map);
1504
Kalle Valo7a8a3962014-03-28 14:35:16 +02001505 ath10k_dbg(ATH10K_DBG_MGMT, "mgmt swba vdev_map 0x%x\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001506 ev->vdev_map);
1507
1508 for (; map; map >>= 1, vdev_id++) {
1509 if (!(map & 0x1))
1510 continue;
1511
1512 i++;
1513
1514 if (i >= WMI_MAX_AP_VDEV) {
1515 ath10k_warn("swba has corrupted vdev map\n");
1516 break;
1517 }
1518
1519 bcn_info = &ev->bcn_info[i];
1520
1521 ath10k_dbg(ATH10K_DBG_MGMT,
Kalle Valo7a8a3962014-03-28 14:35:16 +02001522 "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 +03001523 i,
1524 __le32_to_cpu(bcn_info->tim_info.tim_len),
1525 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
1526 __le32_to_cpu(bcn_info->tim_info.tim_changed),
1527 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
1528 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
1529 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
1530 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
1531 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
1532
1533 arvif = ath10k_get_arvif(ar, vdev_id);
1534 if (arvif == NULL) {
1535 ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
1536 continue;
1537 }
1538
Michal Kaziorc2df44b2014-01-23 11:38:26 +01001539 /* There are no completions for beacons so wait for next SWBA
1540 * before telling mac80211 to decrement CSA counter
1541 *
1542 * Once CSA counter is completed stop sending beacons until
1543 * actual channel switch is done */
1544 if (arvif->vif->csa_active &&
1545 ieee80211_csa_is_complete(arvif->vif)) {
1546 ieee80211_csa_finish(arvif->vif);
1547 continue;
1548 }
1549
Kalle Valo5e3dd152013-06-12 20:52:10 +03001550 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
1551 if (!bcn) {
1552 ath10k_warn("could not get mac80211 beacon\n");
1553 continue;
1554 }
1555
Michal Kazior4b604552014-07-21 21:03:09 +03001556 ath10k_tx_h_seq_no(arvif->vif, bcn);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001557 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
1558 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
1559
Michal Kaziored543882013-09-13 14:16:56 +02001560 spin_lock_bh(&ar->data_lock);
Michal Kazior748afc42014-01-23 12:48:21 +01001561
Michal Kaziored543882013-09-13 14:16:56 +02001562 if (arvif->beacon) {
Michal Kazior748afc42014-01-23 12:48:21 +01001563 if (!arvif->beacon_sent)
1564 ath10k_warn("SWBA overrun on vdev %d\n",
1565 arvif->vdev_id);
1566
Michal Kazior767d34f2014-02-27 18:50:03 +02001567 dma_unmap_single(arvif->ar->dev,
1568 ATH10K_SKB_CB(arvif->beacon)->paddr,
1569 arvif->beacon->len, DMA_TO_DEVICE);
Michal Kaziored543882013-09-13 14:16:56 +02001570 dev_kfree_skb_any(arvif->beacon);
Michal Kazior2ab03a62014-04-23 19:30:05 +03001571 arvif->beacon = NULL;
Michal Kaziored543882013-09-13 14:16:56 +02001572 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573
Michal Kazior767d34f2014-02-27 18:50:03 +02001574 ATH10K_SKB_CB(bcn)->paddr = dma_map_single(arvif->ar->dev,
1575 bcn->data, bcn->len,
1576 DMA_TO_DEVICE);
1577 ret = dma_mapping_error(arvif->ar->dev,
1578 ATH10K_SKB_CB(bcn)->paddr);
1579 if (ret) {
1580 ath10k_warn("failed to map beacon: %d\n", ret);
Michal Kaziorad3d2152014-04-23 19:30:06 +03001581 dev_kfree_skb_any(bcn);
Michal Kazior767d34f2014-02-27 18:50:03 +02001582 goto skip;
1583 }
Michal Kazior748afc42014-01-23 12:48:21 +01001584
Michal Kaziored543882013-09-13 14:16:56 +02001585 arvif->beacon = bcn;
Michal Kazior748afc42014-01-23 12:48:21 +01001586 arvif->beacon_sent = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587
Michal Kaziored543882013-09-13 14:16:56 +02001588 ath10k_wmi_tx_beacon_nowait(arvif);
Michal Kazior767d34f2014-02-27 18:50:03 +02001589skip:
Michal Kaziored543882013-09-13 14:16:56 +02001590 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591 }
1592}
1593
1594static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
1595 struct sk_buff *skb)
1596{
1597 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
1598}
1599
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001600static void ath10k_dfs_radar_report(struct ath10k *ar,
1601 struct wmi_single_phyerr_rx_event *event,
1602 struct phyerr_radar_report *rr,
1603 u64 tsf)
1604{
1605 u32 reg0, reg1, tsf32l;
1606 struct pulse_event pe;
1607 u64 tsf64;
1608 u8 rssi, width;
1609
1610 reg0 = __le32_to_cpu(rr->reg0);
1611 reg1 = __le32_to_cpu(rr->reg1);
1612
1613 ath10k_dbg(ATH10K_DBG_REGULATORY,
1614 "wmi phyerr radar report chirp %d max_width %d agc_total_gain %d pulse_delta_diff %d\n",
1615 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_CHIRP),
1616 MS(reg0, RADAR_REPORT_REG0_PULSE_IS_MAX_WIDTH),
1617 MS(reg0, RADAR_REPORT_REG0_AGC_TOTAL_GAIN),
1618 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_DIFF));
1619 ath10k_dbg(ATH10K_DBG_REGULATORY,
1620 "wmi phyerr radar report pulse_delta_pean %d pulse_sidx %d fft_valid %d agc_mb_gain %d subchan_mask %d\n",
1621 MS(reg0, RADAR_REPORT_REG0_PULSE_DELTA_PEAK),
1622 MS(reg0, RADAR_REPORT_REG0_PULSE_SIDX),
1623 MS(reg1, RADAR_REPORT_REG1_PULSE_SRCH_FFT_VALID),
1624 MS(reg1, RADAR_REPORT_REG1_PULSE_AGC_MB_GAIN),
1625 MS(reg1, RADAR_REPORT_REG1_PULSE_SUBCHAN_MASK));
1626 ath10k_dbg(ATH10K_DBG_REGULATORY,
1627 "wmi phyerr radar report pulse_tsf_offset 0x%X pulse_dur: %d\n",
1628 MS(reg1, RADAR_REPORT_REG1_PULSE_TSF_OFFSET),
1629 MS(reg1, RADAR_REPORT_REG1_PULSE_DUR));
1630
1631 if (!ar->dfs_detector)
1632 return;
1633
1634 /* report event to DFS pattern detector */
1635 tsf32l = __le32_to_cpu(event->hdr.tsf_timestamp);
1636 tsf64 = tsf & (~0xFFFFFFFFULL);
1637 tsf64 |= tsf32l;
1638
1639 width = MS(reg1, RADAR_REPORT_REG1_PULSE_DUR);
1640 rssi = event->hdr.rssi_combined;
1641
1642 /* hardware store this as 8 bit signed value,
1643 * set to zero if negative number
1644 */
1645 if (rssi & 0x80)
1646 rssi = 0;
1647
1648 pe.ts = tsf64;
1649 pe.freq = ar->hw->conf.chandef.chan->center_freq;
1650 pe.width = width;
1651 pe.rssi = rssi;
1652
1653 ath10k_dbg(ATH10K_DBG_REGULATORY,
1654 "dfs add pulse freq: %d, width: %d, rssi %d, tsf: %llX\n",
1655 pe.freq, pe.width, pe.rssi, pe.ts);
1656
1657 ATH10K_DFS_STAT_INC(ar, pulses_detected);
1658
1659 if (!ar->dfs_detector->add_pulse(ar->dfs_detector, &pe)) {
1660 ath10k_dbg(ATH10K_DBG_REGULATORY,
1661 "dfs no pulse pattern detected, yet\n");
1662 return;
1663 }
1664
1665 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs radar detected\n");
1666 ATH10K_DFS_STAT_INC(ar, radar_detected);
Marek Puzyniak7d9b40b2013-11-20 10:00:28 +02001667
1668 /* Control radar events reporting in debugfs file
1669 dfs_block_radar_events */
1670 if (ar->dfs_block_radar_events) {
1671 ath10k_info("DFS Radar detected, but ignored as requested\n");
1672 return;
1673 }
1674
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001675 ieee80211_radar_detected(ar->hw);
1676}
1677
1678static int ath10k_dfs_fft_report(struct ath10k *ar,
1679 struct wmi_single_phyerr_rx_event *event,
1680 struct phyerr_fft_report *fftr,
1681 u64 tsf)
1682{
1683 u32 reg0, reg1;
1684 u8 rssi, peak_mag;
1685
1686 reg0 = __le32_to_cpu(fftr->reg0);
1687 reg1 = __le32_to_cpu(fftr->reg1);
1688 rssi = event->hdr.rssi_combined;
1689
1690 ath10k_dbg(ATH10K_DBG_REGULATORY,
1691 "wmi phyerr fft report total_gain_db %d base_pwr_db %d fft_chn_idx %d peak_sidx %d\n",
1692 MS(reg0, SEARCH_FFT_REPORT_REG0_TOTAL_GAIN_DB),
1693 MS(reg0, SEARCH_FFT_REPORT_REG0_BASE_PWR_DB),
1694 MS(reg0, SEARCH_FFT_REPORT_REG0_FFT_CHN_IDX),
1695 MS(reg0, SEARCH_FFT_REPORT_REG0_PEAK_SIDX));
1696 ath10k_dbg(ATH10K_DBG_REGULATORY,
1697 "wmi phyerr fft report rel_pwr_db %d avgpwr_db %d peak_mag %d num_store_bin %d\n",
1698 MS(reg1, SEARCH_FFT_REPORT_REG1_RELPWR_DB),
1699 MS(reg1, SEARCH_FFT_REPORT_REG1_AVGPWR_DB),
1700 MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG),
1701 MS(reg1, SEARCH_FFT_REPORT_REG1_NUM_STR_BINS_IB));
1702
1703 peak_mag = MS(reg1, SEARCH_FFT_REPORT_REG1_PEAK_MAG);
1704
1705 /* false event detection */
1706 if (rssi == DFS_RSSI_POSSIBLY_FALSE &&
1707 peak_mag < 2 * DFS_PEAK_MAG_THOLD_POSSIBLY_FALSE) {
1708 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs false pulse detected\n");
1709 ATH10K_DFS_STAT_INC(ar, pulses_discarded);
1710 return -EINVAL;
1711 }
1712
1713 return 0;
1714}
1715
1716static void ath10k_wmi_event_dfs(struct ath10k *ar,
1717 struct wmi_single_phyerr_rx_event *event,
1718 u64 tsf)
1719{
1720 int buf_len, tlv_len, res, i = 0;
1721 struct phyerr_tlv *tlv;
1722 struct phyerr_radar_report *rr;
1723 struct phyerr_fft_report *fftr;
1724 u8 *tlv_buf;
1725
1726 buf_len = __le32_to_cpu(event->hdr.buf_len);
1727 ath10k_dbg(ATH10K_DBG_REGULATORY,
1728 "wmi event dfs err_code %d rssi %d tsfl 0x%X tsf64 0x%llX len %d\n",
1729 event->hdr.phy_err_code, event->hdr.rssi_combined,
1730 __le32_to_cpu(event->hdr.tsf_timestamp), tsf, buf_len);
1731
1732 /* Skip event if DFS disabled */
1733 if (!config_enabled(CONFIG_ATH10K_DFS_CERTIFIED))
1734 return;
1735
1736 ATH10K_DFS_STAT_INC(ar, pulses_total);
1737
1738 while (i < buf_len) {
1739 if (i + sizeof(*tlv) > buf_len) {
1740 ath10k_warn("too short buf for tlv header (%d)\n", i);
1741 return;
1742 }
1743
1744 tlv = (struct phyerr_tlv *)&event->bufp[i];
1745 tlv_len = __le16_to_cpu(tlv->len);
1746 tlv_buf = &event->bufp[i + sizeof(*tlv)];
1747 ath10k_dbg(ATH10K_DBG_REGULATORY,
1748 "wmi event dfs tlv_len %d tlv_tag 0x%02X tlv_sig 0x%02X\n",
1749 tlv_len, tlv->tag, tlv->sig);
1750
1751 switch (tlv->tag) {
1752 case PHYERR_TLV_TAG_RADAR_PULSE_SUMMARY:
1753 if (i + sizeof(*tlv) + sizeof(*rr) > buf_len) {
1754 ath10k_warn("too short radar pulse summary (%d)\n",
1755 i);
1756 return;
1757 }
1758
1759 rr = (struct phyerr_radar_report *)tlv_buf;
1760 ath10k_dfs_radar_report(ar, event, rr, tsf);
1761 break;
1762 case PHYERR_TLV_TAG_SEARCH_FFT_REPORT:
1763 if (i + sizeof(*tlv) + sizeof(*fftr) > buf_len) {
1764 ath10k_warn("too short fft report (%d)\n", i);
1765 return;
1766 }
1767
1768 fftr = (struct phyerr_fft_report *)tlv_buf;
1769 res = ath10k_dfs_fft_report(ar, event, fftr, tsf);
1770 if (res)
1771 return;
1772 break;
1773 }
1774
1775 i += sizeof(*tlv) + tlv_len;
1776 }
1777}
1778
1779static void ath10k_wmi_event_spectral_scan(struct ath10k *ar,
1780 struct wmi_single_phyerr_rx_event *event,
1781 u64 tsf)
1782{
1783 ath10k_dbg(ATH10K_DBG_WMI, "wmi event spectral scan\n");
1784}
1785
Kalle Valo5e3dd152013-06-12 20:52:10 +03001786static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
1787{
Janusz Dziedzic9702c682013-11-20 09:59:41 +02001788 struct wmi_comb_phyerr_rx_event *comb_event;
1789 struct wmi_single_phyerr_rx_event *event;
1790 u32 count, i, buf_len, phy_err_code;
1791 u64 tsf;
1792 int left_len = skb->len;
1793
1794 ATH10K_DFS_STAT_INC(ar, phy_errors);
1795
1796 /* Check if combined event available */
1797 if (left_len < sizeof(*comb_event)) {
1798 ath10k_warn("wmi phyerr combined event wrong len\n");
1799 return;
1800 }
1801
1802 left_len -= sizeof(*comb_event);
1803
1804 /* Check number of included events */
1805 comb_event = (struct wmi_comb_phyerr_rx_event *)skb->data;
1806 count = __le32_to_cpu(comb_event->hdr.num_phyerr_events);
1807
1808 tsf = __le32_to_cpu(comb_event->hdr.tsf_u32);
1809 tsf <<= 32;
1810 tsf |= __le32_to_cpu(comb_event->hdr.tsf_l32);
1811
1812 ath10k_dbg(ATH10K_DBG_WMI,
1813 "wmi event phyerr count %d tsf64 0x%llX\n",
1814 count, tsf);
1815
1816 event = (struct wmi_single_phyerr_rx_event *)comb_event->bufp;
1817 for (i = 0; i < count; i++) {
1818 /* Check if we can read event header */
1819 if (left_len < sizeof(*event)) {
1820 ath10k_warn("single event (%d) wrong head len\n", i);
1821 return;
1822 }
1823
1824 left_len -= sizeof(*event);
1825
1826 buf_len = __le32_to_cpu(event->hdr.buf_len);
1827 phy_err_code = event->hdr.phy_err_code;
1828
1829 if (left_len < buf_len) {
1830 ath10k_warn("single event (%d) wrong buf len\n", i);
1831 return;
1832 }
1833
1834 left_len -= buf_len;
1835
1836 switch (phy_err_code) {
1837 case PHY_ERROR_RADAR:
1838 ath10k_wmi_event_dfs(ar, event, tsf);
1839 break;
1840 case PHY_ERROR_SPECTRAL_SCAN:
1841 ath10k_wmi_event_spectral_scan(ar, event, tsf);
1842 break;
1843 case PHY_ERROR_FALSE_RADAR_EXT:
1844 ath10k_wmi_event_dfs(ar, event, tsf);
1845 ath10k_wmi_event_spectral_scan(ar, event, tsf);
1846 break;
1847 default:
1848 break;
1849 }
1850
1851 event += sizeof(*event) + buf_len;
1852 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001853}
1854
1855static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
1856{
1857 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
1858}
1859
1860static void ath10k_wmi_event_profile_match(struct ath10k *ar,
1861 struct sk_buff *skb)
1862{
1863 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
1864}
1865
1866static void ath10k_wmi_event_debug_print(struct ath10k *ar,
Kalle Valo2fe52882014-01-03 12:59:20 +02001867 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001868{
Kalle Valo2fe52882014-01-03 12:59:20 +02001869 char buf[101], c;
1870 int i;
1871
1872 for (i = 0; i < sizeof(buf) - 1; i++) {
1873 if (i >= skb->len)
1874 break;
1875
1876 c = skb->data[i];
1877
1878 if (c == '\0')
1879 break;
1880
1881 if (isascii(c) && isprint(c))
1882 buf[i] = c;
1883 else
1884 buf[i] = '.';
1885 }
1886
1887 if (i == sizeof(buf) - 1)
1888 ath10k_warn("wmi debug print truncated: %d\n", skb->len);
1889
1890 /* for some reason the debug prints end with \n, remove that */
1891 if (skb->data[i - 1] == '\n')
1892 i--;
1893
1894 /* the last byte is always reserved for the null character */
1895 buf[i] = '\0';
1896
1897 ath10k_dbg(ATH10K_DBG_WMI, "wmi event debug print '%s'\n", buf);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001898}
1899
1900static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
1901{
1902 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
1903}
1904
1905static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
1906 struct sk_buff *skb)
1907{
1908 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
1909}
1910
1911static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
1912 struct sk_buff *skb)
1913{
1914 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
1915}
1916
1917static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
1918 struct sk_buff *skb)
1919{
1920 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
1921}
1922
1923static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
1924 struct sk_buff *skb)
1925{
1926 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
1927}
1928
1929static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
1930 struct sk_buff *skb)
1931{
1932 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
1933}
1934
1935static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
1936 struct sk_buff *skb)
1937{
1938 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
1939}
1940
1941static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
1942 struct sk_buff *skb)
1943{
1944 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
1945}
1946
1947static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
1948 struct sk_buff *skb)
1949{
1950 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
1951}
1952
1953static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
1954 struct sk_buff *skb)
1955{
1956 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
1957}
1958
1959static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
1960 struct sk_buff *skb)
1961{
1962 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
1963}
1964
1965static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
1966 struct sk_buff *skb)
1967{
1968 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
1969}
1970
1971static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
1972 struct sk_buff *skb)
1973{
1974 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
1975}
1976
1977static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
1978 struct sk_buff *skb)
1979{
1980 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
1981}
1982
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02001983static void ath10k_wmi_event_inst_rssi_stats(struct ath10k *ar,
1984 struct sk_buff *skb)
1985{
1986 ath10k_dbg(ATH10K_DBG_WMI, "WMI_INST_RSSI_STATS_EVENTID\n");
1987}
1988
1989static void ath10k_wmi_event_vdev_standby_req(struct ath10k *ar,
1990 struct sk_buff *skb)
1991{
1992 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STANDBY_REQ_EVENTID\n");
1993}
1994
1995static void ath10k_wmi_event_vdev_resume_req(struct ath10k *ar,
1996 struct sk_buff *skb)
1997{
1998 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_RESUME_REQ_EVENTID\n");
1999}
2000
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002001static int ath10k_wmi_alloc_host_mem(struct ath10k *ar, u32 req_id,
2002 u32 num_units, u32 unit_len)
2003{
2004 dma_addr_t paddr;
2005 u32 pool_size;
2006 int idx = ar->wmi.num_mem_chunks;
2007
2008 pool_size = num_units * round_up(unit_len, 4);
2009
2010 if (!pool_size)
2011 return -EINVAL;
2012
2013 ar->wmi.mem_chunks[idx].vaddr = dma_alloc_coherent(ar->dev,
2014 pool_size,
2015 &paddr,
2016 GFP_ATOMIC);
2017 if (!ar->wmi.mem_chunks[idx].vaddr) {
2018 ath10k_warn("failed to allocate memory chunk\n");
2019 return -ENOMEM;
2020 }
2021
2022 memset(ar->wmi.mem_chunks[idx].vaddr, 0, pool_size);
2023
2024 ar->wmi.mem_chunks[idx].paddr = paddr;
2025 ar->wmi.mem_chunks[idx].len = pool_size;
2026 ar->wmi.mem_chunks[idx].req_id = req_id;
2027 ar->wmi.num_mem_chunks++;
2028
2029 return 0;
2030}
2031
Kalle Valo5e3dd152013-06-12 20:52:10 +03002032static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
2033 struct sk_buff *skb)
2034{
2035 struct wmi_service_ready_event *ev = (void *)skb->data;
2036
2037 if (skb->len < sizeof(*ev)) {
2038 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2039 skb->len, sizeof(*ev));
2040 return;
2041 }
2042
2043 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2044 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2045 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2046 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2047 ar->fw_version_major =
2048 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2049 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2050 ar->fw_version_release =
2051 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
2052 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
2053 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
Michal Kazior8865bee42013-07-24 12:36:46 +02002054 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2055
Kalle Valo1a222432013-09-27 19:55:07 +03002056 /* only manually set fw features when not using FW IE format */
2057 if (ar->fw_api == 1 && ar->fw_version_build > 636)
Michal Kazior0d9b0432013-08-09 10:13:33 +02002058 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
2059
Michal Kazior8865bee42013-07-24 12:36:46 +02002060 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2061 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
2062 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2063 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2064 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002065
2066 ar->ath_common.regulatory.current_rd =
2067 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2068
2069 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
2070 sizeof(ev->wmi_service_bitmap));
2071
2072 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2073 snprintf(ar->hw->wiphy->fw_version,
2074 sizeof(ar->hw->wiphy->fw_version),
2075 "%u.%u.%u.%u",
2076 ar->fw_version_major,
2077 ar->fw_version_minor,
2078 ar->fw_version_release,
2079 ar->fw_version_build);
2080 }
2081
2082 /* FIXME: it probably should be better to support this */
2083 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
2084 ath10k_warn("target requested %d memory chunks; ignoring\n",
2085 __le32_to_cpu(ev->num_mem_reqs));
2086 }
2087
2088 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior8865bee42013-07-24 12:36:46 +02002089 "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 +03002090 __le32_to_cpu(ev->sw_version),
2091 __le32_to_cpu(ev->sw_version_1),
2092 __le32_to_cpu(ev->abi_version),
2093 __le32_to_cpu(ev->phy_capability),
2094 __le32_to_cpu(ev->ht_cap_info),
2095 __le32_to_cpu(ev->vht_cap_info),
2096 __le32_to_cpu(ev->vht_supp_mcs),
2097 __le32_to_cpu(ev->sys_cap_info),
Michal Kazior8865bee42013-07-24 12:36:46 +02002098 __le32_to_cpu(ev->num_mem_reqs),
2099 __le32_to_cpu(ev->num_rf_chains));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002100
2101 complete(&ar->wmi.service_ready);
2102}
2103
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002104static void ath10k_wmi_10x_service_ready_event_rx(struct ath10k *ar,
2105 struct sk_buff *skb)
2106{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002107 u32 num_units, req_id, unit_size, num_mem_reqs, num_unit_info, i;
2108 int ret;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002109 struct wmi_service_ready_event_10x *ev = (void *)skb->data;
2110
2111 if (skb->len < sizeof(*ev)) {
2112 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
2113 skb->len, sizeof(*ev));
2114 return;
2115 }
2116
2117 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
2118 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
2119 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
2120 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
2121 ar->fw_version_major =
2122 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
2123 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
2124 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
2125 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
2126
2127 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
2128 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
2129 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
2130 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
2131 }
2132
2133 ar->ath_common.regulatory.current_rd =
2134 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
2135
2136 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
2137 sizeof(ev->wmi_service_bitmap));
2138
2139 if (strlen(ar->hw->wiphy->fw_version) == 0) {
2140 snprintf(ar->hw->wiphy->fw_version,
2141 sizeof(ar->hw->wiphy->fw_version),
2142 "%u.%u",
2143 ar->fw_version_major,
2144 ar->fw_version_minor);
2145 }
2146
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002147 num_mem_reqs = __le32_to_cpu(ev->num_mem_reqs);
2148
2149 if (num_mem_reqs > ATH10K_MAX_MEM_REQS) {
2150 ath10k_warn("requested memory chunks number (%d) exceeds the limit\n",
2151 num_mem_reqs);
2152 return;
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002153 }
2154
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002155 if (!num_mem_reqs)
2156 goto exit;
2157
2158 ath10k_dbg(ATH10K_DBG_WMI, "firmware has requested %d memory chunks\n",
2159 num_mem_reqs);
2160
2161 for (i = 0; i < num_mem_reqs; ++i) {
2162 req_id = __le32_to_cpu(ev->mem_reqs[i].req_id);
2163 num_units = __le32_to_cpu(ev->mem_reqs[i].num_units);
2164 unit_size = __le32_to_cpu(ev->mem_reqs[i].unit_size);
2165 num_unit_info = __le32_to_cpu(ev->mem_reqs[i].num_unit_info);
2166
2167 if (num_unit_info & NUM_UNITS_IS_NUM_PEERS)
2168 /* number of units to allocate is number of
2169 * peers, 1 extra for self peer on target */
2170 /* this needs to be tied, host and target
2171 * can get out of sync */
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002172 num_units = TARGET_10X_NUM_PEERS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002173 else if (num_unit_info & NUM_UNITS_IS_NUM_VDEVS)
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002174 num_units = TARGET_10X_NUM_VDEVS + 1;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002175
2176 ath10k_dbg(ATH10K_DBG_WMI,
2177 "wmi mem_req_id %d num_units %d num_unit_info %d unit size %d actual units %d\n",
2178 req_id,
2179 __le32_to_cpu(ev->mem_reqs[i].num_units),
2180 num_unit_info,
2181 unit_size,
2182 num_units);
2183
2184 ret = ath10k_wmi_alloc_host_mem(ar, req_id, num_units,
2185 unit_size);
2186 if (ret)
2187 return;
2188 }
2189
2190exit:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002191 ath10k_dbg(ATH10K_DBG_WMI,
2192 "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",
2193 __le32_to_cpu(ev->sw_version),
2194 __le32_to_cpu(ev->abi_version),
2195 __le32_to_cpu(ev->phy_capability),
2196 __le32_to_cpu(ev->ht_cap_info),
2197 __le32_to_cpu(ev->vht_cap_info),
2198 __le32_to_cpu(ev->vht_supp_mcs),
2199 __le32_to_cpu(ev->sys_cap_info),
2200 __le32_to_cpu(ev->num_mem_reqs),
2201 __le32_to_cpu(ev->num_rf_chains));
2202
2203 complete(&ar->wmi.service_ready);
2204}
2205
Kalle Valo5e3dd152013-06-12 20:52:10 +03002206static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
2207{
2208 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
2209
2210 if (WARN_ON(skb->len < sizeof(*ev)))
2211 return -EINVAL;
2212
2213 memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
2214
2215 ath10k_dbg(ATH10K_DBG_WMI,
Ben Greear2c347522014-02-05 13:58:32 -08002216 "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 +03002217 __le32_to_cpu(ev->sw_version),
2218 __le32_to_cpu(ev->abi_version),
2219 ev->mac_addr.addr,
Ben Greear2c347522014-02-05 13:58:32 -08002220 __le32_to_cpu(ev->status), skb->len, sizeof(*ev));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002221
2222 complete(&ar->wmi.unified_ready);
2223 return 0;
2224}
2225
Bartosz Markowskice428702013-09-26 17:47:05 +02002226static void ath10k_wmi_main_process_rx(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002227{
2228 struct wmi_cmd_hdr *cmd_hdr;
2229 enum wmi_event_id id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002230
2231 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2232 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2233
2234 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2235 return;
2236
Kalle Valo5e3dd152013-06-12 20:52:10 +03002237 trace_ath10k_wmi_event(id, skb->data, skb->len);
2238
2239 switch (id) {
2240 case WMI_MGMT_RX_EVENTID:
2241 ath10k_wmi_event_mgmt_rx(ar, skb);
2242 /* mgmt_rx() owns the skb now! */
2243 return;
2244 case WMI_SCAN_EVENTID:
2245 ath10k_wmi_event_scan(ar, skb);
2246 break;
2247 case WMI_CHAN_INFO_EVENTID:
2248 ath10k_wmi_event_chan_info(ar, skb);
2249 break;
2250 case WMI_ECHO_EVENTID:
2251 ath10k_wmi_event_echo(ar, skb);
2252 break;
2253 case WMI_DEBUG_MESG_EVENTID:
2254 ath10k_wmi_event_debug_mesg(ar, skb);
2255 break;
2256 case WMI_UPDATE_STATS_EVENTID:
2257 ath10k_wmi_event_update_stats(ar, skb);
2258 break;
2259 case WMI_VDEV_START_RESP_EVENTID:
2260 ath10k_wmi_event_vdev_start_resp(ar, skb);
2261 break;
2262 case WMI_VDEV_STOPPED_EVENTID:
2263 ath10k_wmi_event_vdev_stopped(ar, skb);
2264 break;
2265 case WMI_PEER_STA_KICKOUT_EVENTID:
2266 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2267 break;
2268 case WMI_HOST_SWBA_EVENTID:
2269 ath10k_wmi_event_host_swba(ar, skb);
2270 break;
2271 case WMI_TBTTOFFSET_UPDATE_EVENTID:
2272 ath10k_wmi_event_tbttoffset_update(ar, skb);
2273 break;
2274 case WMI_PHYERR_EVENTID:
2275 ath10k_wmi_event_phyerr(ar, skb);
2276 break;
2277 case WMI_ROAM_EVENTID:
2278 ath10k_wmi_event_roam(ar, skb);
2279 break;
2280 case WMI_PROFILE_MATCH:
2281 ath10k_wmi_event_profile_match(ar, skb);
2282 break;
2283 case WMI_DEBUG_PRINT_EVENTID:
2284 ath10k_wmi_event_debug_print(ar, skb);
2285 break;
2286 case WMI_PDEV_QVIT_EVENTID:
2287 ath10k_wmi_event_pdev_qvit(ar, skb);
2288 break;
2289 case WMI_WLAN_PROFILE_DATA_EVENTID:
2290 ath10k_wmi_event_wlan_profile_data(ar, skb);
2291 break;
2292 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
2293 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2294 break;
2295 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
2296 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2297 break;
2298 case WMI_RTT_ERROR_REPORT_EVENTID:
2299 ath10k_wmi_event_rtt_error_report(ar, skb);
2300 break;
2301 case WMI_WOW_WAKEUP_HOST_EVENTID:
2302 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2303 break;
2304 case WMI_DCS_INTERFERENCE_EVENTID:
2305 ath10k_wmi_event_dcs_interference(ar, skb);
2306 break;
2307 case WMI_PDEV_TPC_CONFIG_EVENTID:
2308 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2309 break;
2310 case WMI_PDEV_FTM_INTG_EVENTID:
2311 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
2312 break;
2313 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
2314 ath10k_wmi_event_gtk_offload_status(ar, skb);
2315 break;
2316 case WMI_GTK_REKEY_FAIL_EVENTID:
2317 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
2318 break;
2319 case WMI_TX_DELBA_COMPLETE_EVENTID:
2320 ath10k_wmi_event_delba_complete(ar, skb);
2321 break;
2322 case WMI_TX_ADDBA_COMPLETE_EVENTID:
2323 ath10k_wmi_event_addba_complete(ar, skb);
2324 break;
2325 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
2326 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
2327 break;
2328 case WMI_SERVICE_READY_EVENTID:
2329 ath10k_wmi_service_ready_event_rx(ar, skb);
2330 break;
2331 case WMI_READY_EVENTID:
2332 ath10k_wmi_ready_event_rx(ar, skb);
2333 break;
2334 default:
2335 ath10k_warn("Unknown eventid: %d\n", id);
2336 break;
2337 }
2338
2339 dev_kfree_skb(skb);
2340}
2341
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002342static void ath10k_wmi_10x_process_rx(struct ath10k *ar, struct sk_buff *skb)
2343{
2344 struct wmi_cmd_hdr *cmd_hdr;
2345 enum wmi_10x_event_id id;
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002346
2347 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2348 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2349
2350 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2351 return;
2352
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002353 trace_ath10k_wmi_event(id, skb->data, skb->len);
2354
2355 switch (id) {
2356 case WMI_10X_MGMT_RX_EVENTID:
2357 ath10k_wmi_event_mgmt_rx(ar, skb);
2358 /* mgmt_rx() owns the skb now! */
2359 return;
2360 case WMI_10X_SCAN_EVENTID:
2361 ath10k_wmi_event_scan(ar, skb);
2362 break;
2363 case WMI_10X_CHAN_INFO_EVENTID:
2364 ath10k_wmi_event_chan_info(ar, skb);
2365 break;
2366 case WMI_10X_ECHO_EVENTID:
2367 ath10k_wmi_event_echo(ar, skb);
2368 break;
2369 case WMI_10X_DEBUG_MESG_EVENTID:
2370 ath10k_wmi_event_debug_mesg(ar, skb);
2371 break;
2372 case WMI_10X_UPDATE_STATS_EVENTID:
2373 ath10k_wmi_event_update_stats(ar, skb);
2374 break;
2375 case WMI_10X_VDEV_START_RESP_EVENTID:
2376 ath10k_wmi_event_vdev_start_resp(ar, skb);
2377 break;
2378 case WMI_10X_VDEV_STOPPED_EVENTID:
2379 ath10k_wmi_event_vdev_stopped(ar, skb);
2380 break;
2381 case WMI_10X_PEER_STA_KICKOUT_EVENTID:
2382 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2383 break;
2384 case WMI_10X_HOST_SWBA_EVENTID:
2385 ath10k_wmi_event_host_swba(ar, skb);
2386 break;
2387 case WMI_10X_TBTTOFFSET_UPDATE_EVENTID:
2388 ath10k_wmi_event_tbttoffset_update(ar, skb);
2389 break;
2390 case WMI_10X_PHYERR_EVENTID:
2391 ath10k_wmi_event_phyerr(ar, skb);
2392 break;
2393 case WMI_10X_ROAM_EVENTID:
2394 ath10k_wmi_event_roam(ar, skb);
2395 break;
2396 case WMI_10X_PROFILE_MATCH:
2397 ath10k_wmi_event_profile_match(ar, skb);
2398 break;
2399 case WMI_10X_DEBUG_PRINT_EVENTID:
2400 ath10k_wmi_event_debug_print(ar, skb);
2401 break;
2402 case WMI_10X_PDEV_QVIT_EVENTID:
2403 ath10k_wmi_event_pdev_qvit(ar, skb);
2404 break;
2405 case WMI_10X_WLAN_PROFILE_DATA_EVENTID:
2406 ath10k_wmi_event_wlan_profile_data(ar, skb);
2407 break;
2408 case WMI_10X_RTT_MEASUREMENT_REPORT_EVENTID:
2409 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2410 break;
2411 case WMI_10X_TSF_MEASUREMENT_REPORT_EVENTID:
2412 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2413 break;
2414 case WMI_10X_RTT_ERROR_REPORT_EVENTID:
2415 ath10k_wmi_event_rtt_error_report(ar, skb);
2416 break;
2417 case WMI_10X_WOW_WAKEUP_HOST_EVENTID:
2418 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2419 break;
2420 case WMI_10X_DCS_INTERFERENCE_EVENTID:
2421 ath10k_wmi_event_dcs_interference(ar, skb);
2422 break;
2423 case WMI_10X_PDEV_TPC_CONFIG_EVENTID:
2424 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2425 break;
2426 case WMI_10X_INST_RSSI_STATS_EVENTID:
2427 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2428 break;
2429 case WMI_10X_VDEV_STANDBY_REQ_EVENTID:
2430 ath10k_wmi_event_vdev_standby_req(ar, skb);
2431 break;
2432 case WMI_10X_VDEV_RESUME_REQ_EVENTID:
2433 ath10k_wmi_event_vdev_resume_req(ar, skb);
2434 break;
2435 case WMI_10X_SERVICE_READY_EVENTID:
Bartosz Markowski6f97d252013-09-26 17:47:09 +02002436 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002437 break;
2438 case WMI_10X_READY_EVENTID:
2439 ath10k_wmi_ready_event_rx(ar, skb);
2440 break;
2441 default:
2442 ath10k_warn("Unknown eventid: %d\n", id);
2443 break;
2444 }
2445
2446 dev_kfree_skb(skb);
2447}
2448
Michal Kazior24c88f72014-07-25 13:32:17 +02002449static void ath10k_wmi_10_2_process_rx(struct ath10k *ar, struct sk_buff *skb)
2450{
2451 struct wmi_cmd_hdr *cmd_hdr;
2452 enum wmi_10_2_event_id id;
2453
2454 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
2455 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
2456
2457 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
2458 return;
2459
2460 trace_ath10k_wmi_event(id, skb->data, skb->len);
2461
2462 switch (id) {
2463 case WMI_10_2_MGMT_RX_EVENTID:
2464 ath10k_wmi_event_mgmt_rx(ar, skb);
2465 /* mgmt_rx() owns the skb now! */
2466 return;
2467 case WMI_10_2_SCAN_EVENTID:
2468 ath10k_wmi_event_scan(ar, skb);
2469 break;
2470 case WMI_10_2_CHAN_INFO_EVENTID:
2471 ath10k_wmi_event_chan_info(ar, skb);
2472 break;
2473 case WMI_10_2_ECHO_EVENTID:
2474 ath10k_wmi_event_echo(ar, skb);
2475 break;
2476 case WMI_10_2_DEBUG_MESG_EVENTID:
2477 ath10k_wmi_event_debug_mesg(ar, skb);
2478 break;
2479 case WMI_10_2_UPDATE_STATS_EVENTID:
2480 ath10k_wmi_event_update_stats(ar, skb);
2481 break;
2482 case WMI_10_2_VDEV_START_RESP_EVENTID:
2483 ath10k_wmi_event_vdev_start_resp(ar, skb);
2484 break;
2485 case WMI_10_2_VDEV_STOPPED_EVENTID:
2486 ath10k_wmi_event_vdev_stopped(ar, skb);
2487 break;
2488 case WMI_10_2_PEER_STA_KICKOUT_EVENTID:
2489 ath10k_wmi_event_peer_sta_kickout(ar, skb);
2490 break;
2491 case WMI_10_2_HOST_SWBA_EVENTID:
2492 ath10k_wmi_event_host_swba(ar, skb);
2493 break;
2494 case WMI_10_2_TBTTOFFSET_UPDATE_EVENTID:
2495 ath10k_wmi_event_tbttoffset_update(ar, skb);
2496 break;
2497 case WMI_10_2_PHYERR_EVENTID:
2498 ath10k_wmi_event_phyerr(ar, skb);
2499 break;
2500 case WMI_10_2_ROAM_EVENTID:
2501 ath10k_wmi_event_roam(ar, skb);
2502 break;
2503 case WMI_10_2_PROFILE_MATCH:
2504 ath10k_wmi_event_profile_match(ar, skb);
2505 break;
2506 case WMI_10_2_DEBUG_PRINT_EVENTID:
2507 ath10k_wmi_event_debug_print(ar, skb);
2508 break;
2509 case WMI_10_2_PDEV_QVIT_EVENTID:
2510 ath10k_wmi_event_pdev_qvit(ar, skb);
2511 break;
2512 case WMI_10_2_WLAN_PROFILE_DATA_EVENTID:
2513 ath10k_wmi_event_wlan_profile_data(ar, skb);
2514 break;
2515 case WMI_10_2_RTT_MEASUREMENT_REPORT_EVENTID:
2516 ath10k_wmi_event_rtt_measurement_report(ar, skb);
2517 break;
2518 case WMI_10_2_TSF_MEASUREMENT_REPORT_EVENTID:
2519 ath10k_wmi_event_tsf_measurement_report(ar, skb);
2520 break;
2521 case WMI_10_2_RTT_ERROR_REPORT_EVENTID:
2522 ath10k_wmi_event_rtt_error_report(ar, skb);
2523 break;
2524 case WMI_10_2_WOW_WAKEUP_HOST_EVENTID:
2525 ath10k_wmi_event_wow_wakeup_host(ar, skb);
2526 break;
2527 case WMI_10_2_DCS_INTERFERENCE_EVENTID:
2528 ath10k_wmi_event_dcs_interference(ar, skb);
2529 break;
2530 case WMI_10_2_PDEV_TPC_CONFIG_EVENTID:
2531 ath10k_wmi_event_pdev_tpc_config(ar, skb);
2532 break;
2533 case WMI_10_2_INST_RSSI_STATS_EVENTID:
2534 ath10k_wmi_event_inst_rssi_stats(ar, skb);
2535 break;
2536 case WMI_10_2_VDEV_STANDBY_REQ_EVENTID:
2537 ath10k_wmi_event_vdev_standby_req(ar, skb);
2538 break;
2539 case WMI_10_2_VDEV_RESUME_REQ_EVENTID:
2540 ath10k_wmi_event_vdev_resume_req(ar, skb);
2541 break;
2542 case WMI_10_2_SERVICE_READY_EVENTID:
2543 ath10k_wmi_10x_service_ready_event_rx(ar, skb);
2544 break;
2545 case WMI_10_2_READY_EVENTID:
2546 ath10k_wmi_ready_event_rx(ar, skb);
2547 break;
2548 case WMI_10_2_RTT_KEEPALIVE_EVENTID:
2549 case WMI_10_2_GPIO_INPUT_EVENTID:
2550 case WMI_10_2_PEER_RATECODE_LIST_EVENTID:
2551 case WMI_10_2_GENERIC_BUFFER_EVENTID:
2552 case WMI_10_2_MCAST_BUF_RELEASE_EVENTID:
2553 case WMI_10_2_MCAST_LIST_AGEOUT_EVENTID:
2554 case WMI_10_2_WDS_PEER_EVENTID:
2555 ath10k_dbg(ATH10K_DBG_WMI,
2556 "received event id %d not implemented\n", id);
2557 break;
2558 default:
2559 ath10k_warn("Unknown eventid: %d\n", id);
2560 break;
2561 }
2562
2563 dev_kfree_skb(skb);
2564}
Bartosz Markowski8a6618b2013-09-26 17:47:08 +02002565
Bartosz Markowskice428702013-09-26 17:47:05 +02002566static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
2567{
Michal Kazior24c88f72014-07-25 13:32:17 +02002568 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
2569 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2570 ath10k_wmi_10_2_process_rx(ar, skb);
2571 else
2572 ath10k_wmi_10x_process_rx(ar, skb);
2573 } else {
Bartosz Markowskice428702013-09-26 17:47:05 +02002574 ath10k_wmi_main_process_rx(ar, skb);
Michal Kazior24c88f72014-07-25 13:32:17 +02002575 }
Bartosz Markowskice428702013-09-26 17:47:05 +02002576}
2577
Kalle Valo5e3dd152013-06-12 20:52:10 +03002578/* WMI Initialization functions */
2579int ath10k_wmi_attach(struct ath10k *ar)
2580{
Bartosz Markowskice428702013-09-26 17:47:05 +02002581 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
Michal Kazior24c88f72014-07-25 13:32:17 +02002582 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
2583 ar->wmi.cmd = &wmi_10_2_cmd_map;
2584 else
2585 ar->wmi.cmd = &wmi_10x_cmd_map;
2586
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002587 ar->wmi.vdev_param = &wmi_10x_vdev_param_map;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002588 ar->wmi.pdev_param = &wmi_10x_pdev_param_map;
Bartosz Markowskice428702013-09-26 17:47:05 +02002589 } else {
2590 ar->wmi.cmd = &wmi_cmd_map;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02002591 ar->wmi.vdev_param = &wmi_vdev_param_map;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002592 ar->wmi.pdev_param = &wmi_pdev_param_map;
Bartosz Markowskice428702013-09-26 17:47:05 +02002593 }
2594
Kalle Valo5e3dd152013-06-12 20:52:10 +03002595 init_completion(&ar->wmi.service_ready);
2596 init_completion(&ar->wmi.unified_ready);
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002597 init_waitqueue_head(&ar->wmi.tx_credits_wq);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002598
2599 return 0;
2600}
2601
2602void ath10k_wmi_detach(struct ath10k *ar)
2603{
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002604 int i;
2605
2606 /* free the host memory chunks requested by firmware */
2607 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2608 dma_free_coherent(ar->dev,
2609 ar->wmi.mem_chunks[i].len,
2610 ar->wmi.mem_chunks[i].vaddr,
2611 ar->wmi.mem_chunks[i].paddr);
2612 }
2613
2614 ar->wmi.num_mem_chunks = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002615}
2616
Michal Kazior95bf21f2014-05-16 17:15:39 +03002617int ath10k_wmi_connect(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002618{
2619 int status;
2620 struct ath10k_htc_svc_conn_req conn_req;
2621 struct ath10k_htc_svc_conn_resp conn_resp;
2622
2623 memset(&conn_req, 0, sizeof(conn_req));
2624 memset(&conn_resp, 0, sizeof(conn_resp));
2625
2626 /* these fields are the same for all service endpoints */
2627 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
2628 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
Michal Kaziorbe8b3942013-09-13 14:16:54 +02002629 conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002630
2631 /* connect to control service */
2632 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
2633
Michal Kaziorcd003fa2013-07-05 16:15:13 +03002634 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002635 if (status) {
2636 ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
2637 status);
2638 return status;
2639 }
2640
2641 ar->wmi.eid = conn_resp.eid;
2642 return 0;
2643}
2644
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002645static int ath10k_wmi_main_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2646 u16 rd2g, u16 rd5g, u16 ctl2g,
2647 u16 ctl5g)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002648{
2649 struct wmi_pdev_set_regdomain_cmd *cmd;
2650 struct sk_buff *skb;
2651
2652 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2653 if (!skb)
2654 return -ENOMEM;
2655
2656 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
2657 cmd->reg_domain = __cpu_to_le32(rd);
2658 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2659 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2660 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2661 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2662
2663 ath10k_dbg(ATH10K_DBG_WMI,
2664 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
2665 rd, rd2g, rd5g, ctl2g, ctl5g);
2666
Bartosz Markowskice428702013-09-26 17:47:05 +02002667 return ath10k_wmi_cmd_send(ar, skb,
2668 ar->wmi.cmd->pdev_set_regdomain_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669}
2670
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002671static int ath10k_wmi_10x_pdev_set_regdomain(struct ath10k *ar, u16 rd,
2672 u16 rd2g, u16 rd5g,
2673 u16 ctl2g, u16 ctl5g,
2674 enum wmi_dfs_region dfs_reg)
2675{
2676 struct wmi_pdev_set_regdomain_cmd_10x *cmd;
2677 struct sk_buff *skb;
2678
2679 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2680 if (!skb)
2681 return -ENOMEM;
2682
2683 cmd = (struct wmi_pdev_set_regdomain_cmd_10x *)skb->data;
2684 cmd->reg_domain = __cpu_to_le32(rd);
2685 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
2686 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
2687 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
2688 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
2689 cmd->dfs_domain = __cpu_to_le32(dfs_reg);
2690
2691 ath10k_dbg(ATH10K_DBG_WMI,
2692 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x dfs_region %x\n",
2693 rd, rd2g, rd5g, ctl2g, ctl5g, dfs_reg);
2694
2695 return ath10k_wmi_cmd_send(ar, skb,
2696 ar->wmi.cmd->pdev_set_regdomain_cmdid);
2697}
2698
2699int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
2700 u16 rd5g, u16 ctl2g, u16 ctl5g,
2701 enum wmi_dfs_region dfs_reg)
2702{
2703 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
2704 return ath10k_wmi_10x_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2705 ctl2g, ctl5g, dfs_reg);
2706 else
2707 return ath10k_wmi_main_pdev_set_regdomain(ar, rd, rd2g, rd5g,
2708 ctl2g, ctl5g);
2709}
2710
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
2712 const struct wmi_channel_arg *arg)
2713{
2714 struct wmi_set_channel_cmd *cmd;
2715 struct sk_buff *skb;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002716 u32 ch_flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002717
2718 if (arg->passive)
2719 return -EINVAL;
2720
2721 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2722 if (!skb)
2723 return -ENOMEM;
2724
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002725 if (arg->chan_radar)
2726 ch_flags |= WMI_CHAN_FLAG_DFS;
2727
Kalle Valo5e3dd152013-06-12 20:52:10 +03002728 cmd = (struct wmi_set_channel_cmd *)skb->data;
2729 cmd->chan.mhz = __cpu_to_le32(arg->freq);
2730 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
2731 cmd->chan.mode = arg->mode;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002732 cmd->chan.flags |= __cpu_to_le32(ch_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002733 cmd->chan.min_power = arg->min_power;
2734 cmd->chan.max_power = arg->max_power;
2735 cmd->chan.reg_power = arg->max_reg_power;
2736 cmd->chan.reg_classid = arg->reg_class_id;
2737 cmd->chan.antenna_max = arg->max_antenna_gain;
2738
2739 ath10k_dbg(ATH10K_DBG_WMI,
2740 "wmi set channel mode %d freq %d\n",
2741 arg->mode, arg->freq);
2742
Bartosz Markowskice428702013-09-26 17:47:05 +02002743 return ath10k_wmi_cmd_send(ar, skb,
2744 ar->wmi.cmd->pdev_set_channel_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002745}
2746
Marek Puzyniak00f54822014-02-10 17:14:24 +01002747int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748{
2749 struct wmi_pdev_suspend_cmd *cmd;
2750 struct sk_buff *skb;
2751
2752 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2753 if (!skb)
2754 return -ENOMEM;
2755
2756 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
Marek Puzyniak00f54822014-02-10 17:14:24 +01002757 cmd->suspend_opt = __cpu_to_le32(suspend_opt);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758
Bartosz Markowskice428702013-09-26 17:47:05 +02002759 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_suspend_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002760}
2761
2762int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
2763{
2764 struct sk_buff *skb;
2765
2766 skb = ath10k_wmi_alloc_skb(0);
2767 if (skb == NULL)
2768 return -ENOMEM;
2769
Bartosz Markowskice428702013-09-26 17:47:05 +02002770 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_resume_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002771}
2772
Bartosz Markowski226a3392013-09-26 17:47:16 +02002773int ath10k_wmi_pdev_set_param(struct ath10k *ar, u32 id, u32 value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002774{
2775 struct wmi_pdev_set_param_cmd *cmd;
2776 struct sk_buff *skb;
2777
Bartosz Markowski226a3392013-09-26 17:47:16 +02002778 if (id == WMI_PDEV_PARAM_UNSUPPORTED) {
2779 ath10k_warn("pdev param %d not supported by firmware\n", id);
Bartosz Markowskid5449432013-10-15 09:55:32 +02002780 return -EOPNOTSUPP;
Bartosz Markowski226a3392013-09-26 17:47:16 +02002781 }
2782
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2784 if (!skb)
2785 return -ENOMEM;
2786
2787 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
2788 cmd->param_id = __cpu_to_le32(id);
2789 cmd->param_value = __cpu_to_le32(value);
2790
2791 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
2792 id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02002793 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->pdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794}
2795
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002796static int ath10k_wmi_main_cmd_init(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002797{
2798 struct wmi_init_cmd *cmd;
2799 struct sk_buff *buf;
2800 struct wmi_resource_config config = {};
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002801 u32 len, val;
2802 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002803
2804 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
2805 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
2806 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
2807
2808 config.num_offload_reorder_bufs =
2809 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
2810
2811 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
2812 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
2813 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
2814 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
2815 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
2816 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2817 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2818 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
2819 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
2820 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
2821
2822 config.scan_max_pending_reqs =
2823 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
2824
2825 config.bmiss_offload_max_vdev =
2826 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
2827
2828 config.roam_offload_max_vdev =
2829 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
2830
2831 config.roam_offload_max_ap_profiles =
2832 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
2833
2834 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
2835 config.num_mcast_table_elems =
2836 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
2837
2838 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
2839 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
2840 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
2841 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
2842 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
2843
2844 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
2845 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
2846
2847 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
2848
2849 config.gtk_offload_max_vdev =
2850 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
2851
2852 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
2853 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
2854
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002855 len = sizeof(*cmd) +
2856 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
2857
2858 buf = ath10k_wmi_alloc_skb(len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002859 if (!buf)
2860 return -ENOMEM;
2861
2862 cmd = (struct wmi_init_cmd *)buf->data;
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002863
2864 if (ar->wmi.num_mem_chunks == 0) {
2865 cmd->num_host_mem_chunks = 0;
2866 goto out;
2867 }
2868
2869 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002870 ar->wmi.num_mem_chunks);
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002871
2872 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
2873
2874 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2875 cmd->host_mem_chunks[i].ptr =
2876 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
2877 cmd->host_mem_chunks[i].size =
2878 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
2879 cmd->host_mem_chunks[i].req_id =
2880 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
2881
2882 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002883 "wmi chunk %d len %d requested, addr 0x%llx\n",
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002884 i,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002885 ar->wmi.mem_chunks[i].len,
2886 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
Bartosz Markowskib3effe62013-09-26 17:47:11 +02002887 }
2888out:
Kalle Valo5e3dd152013-06-12 20:52:10 +03002889 memcpy(&cmd->resource_config, &config, sizeof(config));
2890
2891 ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02002892 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893}
2894
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002895static int ath10k_wmi_10x_cmd_init(struct ath10k *ar)
2896{
2897 struct wmi_init_cmd_10x *cmd;
2898 struct sk_buff *buf;
2899 struct wmi_resource_config_10x config = {};
2900 u32 len, val;
2901 int i;
2902
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002903 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
2904 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
2905 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
2906 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
2907 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
2908 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
2909 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
2910 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
2911 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
2912 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
2913 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
2914 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002915
2916 config.scan_max_pending_reqs =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002917 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002918
2919 config.bmiss_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002920 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002921
2922 config.roam_offload_max_vdev =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002923 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002924
2925 config.roam_offload_max_ap_profiles =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002926 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002927
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002928 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002929 config.num_mcast_table_elems =
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002930 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002931
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002932 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
2933 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
2934 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
2935 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
2936 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002937
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002938 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002939 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
2940
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002941 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002942
Bartosz Markowskiec6a73f2013-09-26 17:47:14 +02002943 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
2944 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002945
2946 len = sizeof(*cmd) +
2947 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
2948
2949 buf = ath10k_wmi_alloc_skb(len);
2950 if (!buf)
2951 return -ENOMEM;
2952
2953 cmd = (struct wmi_init_cmd_10x *)buf->data;
2954
2955 if (ar->wmi.num_mem_chunks == 0) {
2956 cmd->num_host_mem_chunks = 0;
2957 goto out;
2958 }
2959
2960 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002961 ar->wmi.num_mem_chunks);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002962
2963 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
2964
2965 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
2966 cmd->host_mem_chunks[i].ptr =
2967 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
2968 cmd->host_mem_chunks[i].size =
2969 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
2970 cmd->host_mem_chunks[i].req_id =
2971 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
2972
2973 ath10k_dbg(ATH10K_DBG_WMI,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002974 "wmi chunk %d len %d requested, addr 0x%llx\n",
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002975 i,
Michal Kazior5c54a7b2013-10-16 16:45:53 +03002976 ar->wmi.mem_chunks[i].len,
2977 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02002978 }
2979out:
2980 memcpy(&cmd->resource_config, &config, sizeof(config));
2981
2982 ath10k_dbg(ATH10K_DBG_WMI, "wmi init 10x\n");
2983 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
2984}
2985
Michal Kazior24c88f72014-07-25 13:32:17 +02002986static int ath10k_wmi_10_2_cmd_init(struct ath10k *ar)
2987{
2988 struct wmi_init_cmd_10_2 *cmd;
2989 struct sk_buff *buf;
2990 struct wmi_resource_config_10x config = {};
2991 u32 len, val;
2992 int i;
2993
2994 config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
2995 config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
2996 config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
2997 config.num_tids = __cpu_to_le32(TARGET_10X_NUM_TIDS);
2998 config.ast_skid_limit = __cpu_to_le32(TARGET_10X_AST_SKID_LIMIT);
2999 config.tx_chain_mask = __cpu_to_le32(TARGET_10X_TX_CHAIN_MASK);
3000 config.rx_chain_mask = __cpu_to_le32(TARGET_10X_RX_CHAIN_MASK);
3001 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3002 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3003 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_LO_PRI);
3004 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_10X_RX_TIMEOUT_HI_PRI);
3005 config.rx_decap_mode = __cpu_to_le32(TARGET_10X_RX_DECAP_MODE);
3006
3007 config.scan_max_pending_reqs =
3008 __cpu_to_le32(TARGET_10X_SCAN_MAX_PENDING_REQS);
3009
3010 config.bmiss_offload_max_vdev =
3011 __cpu_to_le32(TARGET_10X_BMISS_OFFLOAD_MAX_VDEV);
3012
3013 config.roam_offload_max_vdev =
3014 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_VDEV);
3015
3016 config.roam_offload_max_ap_profiles =
3017 __cpu_to_le32(TARGET_10X_ROAM_OFFLOAD_MAX_AP_PROFILES);
3018
3019 config.num_mcast_groups = __cpu_to_le32(TARGET_10X_NUM_MCAST_GROUPS);
3020 config.num_mcast_table_elems =
3021 __cpu_to_le32(TARGET_10X_NUM_MCAST_TABLE_ELEMS);
3022
3023 config.mcast2ucast_mode = __cpu_to_le32(TARGET_10X_MCAST2UCAST_MODE);
3024 config.tx_dbg_log_size = __cpu_to_le32(TARGET_10X_TX_DBG_LOG_SIZE);
3025 config.num_wds_entries = __cpu_to_le32(TARGET_10X_NUM_WDS_ENTRIES);
3026 config.dma_burst_size = __cpu_to_le32(TARGET_10X_DMA_BURST_SIZE);
3027 config.mac_aggr_delim = __cpu_to_le32(TARGET_10X_MAC_AGGR_DELIM);
3028
3029 val = TARGET_10X_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
3030 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
3031
3032 config.vow_config = __cpu_to_le32(TARGET_10X_VOW_CONFIG);
3033
3034 config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
3035 config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);
3036
3037 len = sizeof(*cmd) +
3038 (sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);
3039
3040 buf = ath10k_wmi_alloc_skb(len);
3041 if (!buf)
3042 return -ENOMEM;
3043
3044 cmd = (struct wmi_init_cmd_10_2 *)buf->data;
3045
3046 if (ar->wmi.num_mem_chunks == 0) {
3047 cmd->num_host_mem_chunks = 0;
3048 goto out;
3049 }
3050
3051 ath10k_dbg(ATH10K_DBG_WMI, "wmi sending %d memory chunks info.\n",
3052 ar->wmi.num_mem_chunks);
3053
3054 cmd->num_host_mem_chunks = __cpu_to_le32(ar->wmi.num_mem_chunks);
3055
3056 for (i = 0; i < ar->wmi.num_mem_chunks; i++) {
3057 cmd->host_mem_chunks[i].ptr =
3058 __cpu_to_le32(ar->wmi.mem_chunks[i].paddr);
3059 cmd->host_mem_chunks[i].size =
3060 __cpu_to_le32(ar->wmi.mem_chunks[i].len);
3061 cmd->host_mem_chunks[i].req_id =
3062 __cpu_to_le32(ar->wmi.mem_chunks[i].req_id);
3063
3064 ath10k_dbg(ATH10K_DBG_WMI,
3065 "wmi chunk %d len %d requested, addr 0x%llx\n",
3066 i,
3067 ar->wmi.mem_chunks[i].len,
3068 (unsigned long long)ar->wmi.mem_chunks[i].paddr);
3069 }
3070out:
3071 memcpy(&cmd->resource_config.common, &config, sizeof(config));
3072
3073 ath10k_dbg(ATH10K_DBG_WMI, "wmi init 10.2\n");
3074 return ath10k_wmi_cmd_send(ar, buf, ar->wmi.cmd->init_cmdid);
3075}
3076
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003077int ath10k_wmi_cmd_init(struct ath10k *ar)
3078{
3079 int ret;
3080
Michal Kazior24c88f72014-07-25 13:32:17 +02003081 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3082 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3083 ret = ath10k_wmi_10_2_cmd_init(ar);
3084 else
3085 ret = ath10k_wmi_10x_cmd_init(ar);
3086 } else {
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003087 ret = ath10k_wmi_main_cmd_init(ar);
Michal Kazior24c88f72014-07-25 13:32:17 +02003088 }
Bartosz Markowski12b2b9e2013-09-26 17:47:13 +02003089
3090 return ret;
3091}
3092
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003093static int ath10k_wmi_start_scan_calc_len(struct ath10k *ar,
3094 const struct wmi_start_scan_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003095{
3096 int len;
3097
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003098 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3099 len = sizeof(struct wmi_start_scan_cmd_10x);
3100 else
3101 len = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003102
3103 if (arg->ie_len) {
3104 if (!arg->ie)
3105 return -EINVAL;
3106 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
3107 return -EINVAL;
3108
3109 len += sizeof(struct wmi_ie_data);
3110 len += roundup(arg->ie_len, 4);
3111 }
3112
3113 if (arg->n_channels) {
3114 if (!arg->channels)
3115 return -EINVAL;
3116 if (arg->n_channels > ARRAY_SIZE(arg->channels))
3117 return -EINVAL;
3118
3119 len += sizeof(struct wmi_chan_list);
3120 len += sizeof(__le32) * arg->n_channels;
3121 }
3122
3123 if (arg->n_ssids) {
3124 if (!arg->ssids)
3125 return -EINVAL;
3126 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
3127 return -EINVAL;
3128
3129 len += sizeof(struct wmi_ssid_list);
3130 len += sizeof(struct wmi_ssid) * arg->n_ssids;
3131 }
3132
3133 if (arg->n_bssids) {
3134 if (!arg->bssids)
3135 return -EINVAL;
3136 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
3137 return -EINVAL;
3138
3139 len += sizeof(struct wmi_bssid_list);
3140 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3141 }
3142
3143 return len;
3144}
3145
3146int ath10k_wmi_start_scan(struct ath10k *ar,
3147 const struct wmi_start_scan_arg *arg)
3148{
3149 struct wmi_start_scan_cmd *cmd;
3150 struct sk_buff *skb;
3151 struct wmi_ie_data *ie;
3152 struct wmi_chan_list *channels;
3153 struct wmi_ssid_list *ssids;
3154 struct wmi_bssid_list *bssids;
3155 u32 scan_id;
3156 u32 scan_req_id;
3157 int off;
3158 int len = 0;
3159 int i;
3160
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003161 len = ath10k_wmi_start_scan_calc_len(ar, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003162 if (len < 0)
3163 return len; /* len contains error code here */
3164
3165 skb = ath10k_wmi_alloc_skb(len);
3166 if (!skb)
3167 return -ENOMEM;
3168
3169 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
3170 scan_id |= arg->scan_id;
3171
3172 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3173 scan_req_id |= arg->scan_req_id;
3174
3175 cmd = (struct wmi_start_scan_cmd *)skb->data;
3176 cmd->scan_id = __cpu_to_le32(scan_id);
3177 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
3178 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3179 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
3180 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
3181 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
3182 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
3183 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
3184 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
3185 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
3186 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
3187 cmd->idle_time = __cpu_to_le32(arg->idle_time);
3188 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
3189 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
3190 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
3191
3192 /* TLV list starts after fields included in the struct */
Bartosz Markowski89b7e762013-09-26 17:47:17 +02003193 /* There's just one filed that differes the two start_scan
3194 * structures - burst_duration, which we are not using btw,
3195 no point to make the split here, just shift the buffer to fit with
3196 given FW */
3197 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3198 off = sizeof(struct wmi_start_scan_cmd_10x);
3199 else
3200 off = sizeof(struct wmi_start_scan_cmd);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003201
3202 if (arg->n_channels) {
3203 channels = (void *)skb->data + off;
3204 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
3205 channels->num_chan = __cpu_to_le32(arg->n_channels);
3206
3207 for (i = 0; i < arg->n_channels; i++)
Michal Kazior24c88f72014-07-25 13:32:17 +02003208 channels->channel_list[i].freq =
3209 __cpu_to_le16(arg->channels[i]);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003210
3211 off += sizeof(*channels);
3212 off += sizeof(__le32) * arg->n_channels;
3213 }
3214
3215 if (arg->n_ssids) {
3216 ssids = (void *)skb->data + off;
3217 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
3218 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
3219
3220 for (i = 0; i < arg->n_ssids; i++) {
3221 ssids->ssids[i].ssid_len =
3222 __cpu_to_le32(arg->ssids[i].len);
3223 memcpy(&ssids->ssids[i].ssid,
3224 arg->ssids[i].ssid,
3225 arg->ssids[i].len);
3226 }
3227
3228 off += sizeof(*ssids);
3229 off += sizeof(struct wmi_ssid) * arg->n_ssids;
3230 }
3231
3232 if (arg->n_bssids) {
3233 bssids = (void *)skb->data + off;
3234 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
3235 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
3236
3237 for (i = 0; i < arg->n_bssids; i++)
3238 memcpy(&bssids->bssid_list[i],
3239 arg->bssids[i].bssid,
3240 ETH_ALEN);
3241
3242 off += sizeof(*bssids);
3243 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
3244 }
3245
3246 if (arg->ie_len) {
3247 ie = (void *)skb->data + off;
3248 ie->tag = __cpu_to_le32(WMI_IE_TAG);
3249 ie->ie_len = __cpu_to_le32(arg->ie_len);
3250 memcpy(ie->ie_data, arg->ie, arg->ie_len);
3251
3252 off += sizeof(*ie);
3253 off += roundup(arg->ie_len, 4);
3254 }
3255
3256 if (off != skb->len) {
3257 dev_kfree_skb(skb);
3258 return -EINVAL;
3259 }
3260
3261 ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003262 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->start_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003263}
3264
3265void ath10k_wmi_start_scan_init(struct ath10k *ar,
3266 struct wmi_start_scan_arg *arg)
3267{
3268 /* setup commonly used values */
3269 arg->scan_req_id = 1;
3270 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
3271 arg->dwell_time_active = 50;
3272 arg->dwell_time_passive = 150;
3273 arg->min_rest_time = 50;
3274 arg->max_rest_time = 500;
3275 arg->repeat_probe_time = 0;
3276 arg->probe_spacing_time = 0;
3277 arg->idle_time = 0;
Bartosz Markowskic3228922013-10-02 08:48:52 +02003278 arg->max_scan_time = 20000;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003279 arg->probe_delay = 5;
3280 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
3281 | WMI_SCAN_EVENT_COMPLETED
3282 | WMI_SCAN_EVENT_BSS_CHANNEL
3283 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
3284 | WMI_SCAN_EVENT_DEQUEUED;
3285 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
3286 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
3287 arg->n_bssids = 1;
3288 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
3289}
3290
3291int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
3292{
3293 struct wmi_stop_scan_cmd *cmd;
3294 struct sk_buff *skb;
3295 u32 scan_id;
3296 u32 req_id;
3297
3298 if (arg->req_id > 0xFFF)
3299 return -EINVAL;
3300 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
3301 return -EINVAL;
3302
3303 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3304 if (!skb)
3305 return -ENOMEM;
3306
3307 scan_id = arg->u.scan_id;
3308 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
3309
3310 req_id = arg->req_id;
3311 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
3312
3313 cmd = (struct wmi_stop_scan_cmd *)skb->data;
3314 cmd->req_type = __cpu_to_le32(arg->req_type);
3315 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
3316 cmd->scan_id = __cpu_to_le32(scan_id);
3317 cmd->scan_req_id = __cpu_to_le32(req_id);
3318
3319 ath10k_dbg(ATH10K_DBG_WMI,
3320 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
3321 arg->req_id, arg->req_type, arg->u.scan_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02003322 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->stop_scan_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003323}
3324
3325int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
3326 enum wmi_vdev_type type,
3327 enum wmi_vdev_subtype subtype,
3328 const u8 macaddr[ETH_ALEN])
3329{
3330 struct wmi_vdev_create_cmd *cmd;
3331 struct sk_buff *skb;
3332
3333 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3334 if (!skb)
3335 return -ENOMEM;
3336
3337 cmd = (struct wmi_vdev_create_cmd *)skb->data;
3338 cmd->vdev_id = __cpu_to_le32(vdev_id);
3339 cmd->vdev_type = __cpu_to_le32(type);
3340 cmd->vdev_subtype = __cpu_to_le32(subtype);
3341 memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
3342
3343 ath10k_dbg(ATH10K_DBG_WMI,
3344 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
3345 vdev_id, type, subtype, macaddr);
3346
Bartosz Markowskice428702013-09-26 17:47:05 +02003347 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003348}
3349
3350int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
3351{
3352 struct wmi_vdev_delete_cmd *cmd;
3353 struct sk_buff *skb;
3354
3355 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3356 if (!skb)
3357 return -ENOMEM;
3358
3359 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
3360 cmd->vdev_id = __cpu_to_le32(vdev_id);
3361
3362 ath10k_dbg(ATH10K_DBG_WMI,
3363 "WMI vdev delete id %d\n", vdev_id);
3364
Bartosz Markowskice428702013-09-26 17:47:05 +02003365 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003366}
3367
3368static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
3369 const struct wmi_vdev_start_request_arg *arg,
Bartosz Markowskice428702013-09-26 17:47:05 +02003370 u32 cmd_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003371{
3372 struct wmi_vdev_start_request_cmd *cmd;
3373 struct sk_buff *skb;
3374 const char *cmdname;
3375 u32 flags = 0;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003376 u32 ch_flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003377
Bartosz Markowskice428702013-09-26 17:47:05 +02003378 if (cmd_id != ar->wmi.cmd->vdev_start_request_cmdid &&
3379 cmd_id != ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380 return -EINVAL;
3381 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
3382 return -EINVAL;
3383 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
3384 return -EINVAL;
3385 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
3386 return -EINVAL;
3387
Bartosz Markowskice428702013-09-26 17:47:05 +02003388 if (cmd_id == ar->wmi.cmd->vdev_start_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003389 cmdname = "start";
Bartosz Markowskice428702013-09-26 17:47:05 +02003390 else if (cmd_id == ar->wmi.cmd->vdev_restart_request_cmdid)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 cmdname = "restart";
3392 else
3393 return -EINVAL; /* should not happen, we already check cmd_id */
3394
3395 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3396 if (!skb)
3397 return -ENOMEM;
3398
3399 if (arg->hidden_ssid)
3400 flags |= WMI_VDEV_START_HIDDEN_SSID;
3401 if (arg->pmf_enabled)
3402 flags |= WMI_VDEV_START_PMF_ENABLED;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003403 if (arg->channel.chan_radar)
3404 ch_flags |= WMI_CHAN_FLAG_DFS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405
3406 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
3407 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3408 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
3409 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
3410 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
3411 cmd->flags = __cpu_to_le32(flags);
3412 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
3413 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
3414
3415 if (arg->ssid) {
3416 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
3417 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
3418 }
3419
3420 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
3421
3422 cmd->chan.band_center_freq1 =
3423 __cpu_to_le32(arg->channel.band_center_freq1);
3424
3425 cmd->chan.mode = arg->channel.mode;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003426 cmd->chan.flags |= __cpu_to_le32(ch_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003427 cmd->chan.min_power = arg->channel.min_power;
3428 cmd->chan.max_power = arg->channel.max_power;
3429 cmd->chan.reg_power = arg->channel.max_reg_power;
3430 cmd->chan.reg_classid = arg->channel.reg_class_id;
3431 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
3432
3433 ath10k_dbg(ATH10K_DBG_WMI,
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003434 "wmi vdev %s id 0x%x flags: 0x%0X, freq %d, mode %d, "
3435 "ch_flags: 0x%0X, max_power: %d\n", cmdname, arg->vdev_id,
3436 flags, arg->channel.freq, arg->channel.mode,
3437 cmd->chan.flags, arg->channel.max_power);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003438
3439 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
3440}
3441
3442int ath10k_wmi_vdev_start(struct ath10k *ar,
3443 const struct wmi_vdev_start_request_arg *arg)
3444{
Bartosz Markowskice428702013-09-26 17:47:05 +02003445 u32 cmd_id = ar->wmi.cmd->vdev_start_request_cmdid;
3446
3447 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448}
3449
3450int ath10k_wmi_vdev_restart(struct ath10k *ar,
3451 const struct wmi_vdev_start_request_arg *arg)
3452{
Bartosz Markowskice428702013-09-26 17:47:05 +02003453 u32 cmd_id = ar->wmi.cmd->vdev_restart_request_cmdid;
3454
3455 return ath10k_wmi_vdev_start_restart(ar, arg, cmd_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003456}
3457
3458int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
3459{
3460 struct wmi_vdev_stop_cmd *cmd;
3461 struct sk_buff *skb;
3462
3463 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3464 if (!skb)
3465 return -ENOMEM;
3466
3467 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
3468 cmd->vdev_id = __cpu_to_le32(vdev_id);
3469
3470 ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
3471
Bartosz Markowskice428702013-09-26 17:47:05 +02003472 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_stop_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473}
3474
3475int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
3476{
3477 struct wmi_vdev_up_cmd *cmd;
3478 struct sk_buff *skb;
3479
3480 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3481 if (!skb)
3482 return -ENOMEM;
3483
3484 cmd = (struct wmi_vdev_up_cmd *)skb->data;
3485 cmd->vdev_id = __cpu_to_le32(vdev_id);
3486 cmd->vdev_assoc_id = __cpu_to_le32(aid);
Joe Perches7b4371e2013-10-02 20:39:11 -07003487 memcpy(&cmd->vdev_bssid.addr, bssid, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003488
3489 ath10k_dbg(ATH10K_DBG_WMI,
3490 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
3491 vdev_id, aid, bssid);
3492
Bartosz Markowskice428702013-09-26 17:47:05 +02003493 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_up_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003494}
3495
3496int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
3497{
3498 struct wmi_vdev_down_cmd *cmd;
3499 struct sk_buff *skb;
3500
3501 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3502 if (!skb)
3503 return -ENOMEM;
3504
3505 cmd = (struct wmi_vdev_down_cmd *)skb->data;
3506 cmd->vdev_id = __cpu_to_le32(vdev_id);
3507
3508 ath10k_dbg(ATH10K_DBG_WMI,
3509 "wmi mgmt vdev down id 0x%x\n", vdev_id);
3510
Bartosz Markowskice428702013-09-26 17:47:05 +02003511 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_down_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003512}
3513
3514int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003515 u32 param_id, u32 param_value)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003516{
3517 struct wmi_vdev_set_param_cmd *cmd;
3518 struct sk_buff *skb;
3519
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003520 if (param_id == WMI_VDEV_PARAM_UNSUPPORTED) {
3521 ath10k_dbg(ATH10K_DBG_WMI,
3522 "vdev param %d not supported by firmware\n",
3523 param_id);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003524 return -EOPNOTSUPP;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003525 }
3526
Kalle Valo5e3dd152013-06-12 20:52:10 +03003527 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3528 if (!skb)
3529 return -ENOMEM;
3530
3531 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
3532 cmd->vdev_id = __cpu_to_le32(vdev_id);
3533 cmd->param_id = __cpu_to_le32(param_id);
3534 cmd->param_value = __cpu_to_le32(param_value);
3535
3536 ath10k_dbg(ATH10K_DBG_WMI,
3537 "wmi vdev id 0x%x set param %d value %d\n",
3538 vdev_id, param_id, param_value);
3539
Bartosz Markowskice428702013-09-26 17:47:05 +02003540 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->vdev_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003541}
3542
3543int ath10k_wmi_vdev_install_key(struct ath10k *ar,
3544 const struct wmi_vdev_install_key_arg *arg)
3545{
3546 struct wmi_vdev_install_key_cmd *cmd;
3547 struct sk_buff *skb;
3548
3549 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
3550 return -EINVAL;
3551 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
3552 return -EINVAL;
3553
3554 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
3555 if (!skb)
3556 return -ENOMEM;
3557
3558 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
3559 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3560 cmd->key_idx = __cpu_to_le32(arg->key_idx);
3561 cmd->key_flags = __cpu_to_le32(arg->key_flags);
3562 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
3563 cmd->key_len = __cpu_to_le32(arg->key_len);
3564 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
3565 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
3566
3567 if (arg->macaddr)
3568 memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
3569 if (arg->key_data)
3570 memcpy(cmd->key_data, arg->key_data, arg->key_len);
3571
Michal Kaziore0c508a2013-07-05 16:15:17 +03003572 ath10k_dbg(ATH10K_DBG_WMI,
3573 "wmi vdev install key idx %d cipher %d len %d\n",
3574 arg->key_idx, arg->key_cipher, arg->key_len);
Bartosz Markowskice428702013-09-26 17:47:05 +02003575 return ath10k_wmi_cmd_send(ar, skb,
3576 ar->wmi.cmd->vdev_install_key_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003577}
3578
3579int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
3580 const u8 peer_addr[ETH_ALEN])
3581{
3582 struct wmi_peer_create_cmd *cmd;
3583 struct sk_buff *skb;
3584
3585 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3586 if (!skb)
3587 return -ENOMEM;
3588
3589 cmd = (struct wmi_peer_create_cmd *)skb->data;
3590 cmd->vdev_id = __cpu_to_le32(vdev_id);
3591 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3592
3593 ath10k_dbg(ATH10K_DBG_WMI,
3594 "wmi peer create vdev_id %d peer_addr %pM\n",
3595 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003596 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_create_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003597}
3598
3599int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
3600 const u8 peer_addr[ETH_ALEN])
3601{
3602 struct wmi_peer_delete_cmd *cmd;
3603 struct sk_buff *skb;
3604
3605 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3606 if (!skb)
3607 return -ENOMEM;
3608
3609 cmd = (struct wmi_peer_delete_cmd *)skb->data;
3610 cmd->vdev_id = __cpu_to_le32(vdev_id);
3611 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3612
3613 ath10k_dbg(ATH10K_DBG_WMI,
3614 "wmi peer delete vdev_id %d peer_addr %pM\n",
3615 vdev_id, peer_addr);
Bartosz Markowskice428702013-09-26 17:47:05 +02003616 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_delete_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003617}
3618
3619int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
3620 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
3621{
3622 struct wmi_peer_flush_tids_cmd *cmd;
3623 struct sk_buff *skb;
3624
3625 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3626 if (!skb)
3627 return -ENOMEM;
3628
3629 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
3630 cmd->vdev_id = __cpu_to_le32(vdev_id);
3631 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
3632 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
3633
3634 ath10k_dbg(ATH10K_DBG_WMI,
3635 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
3636 vdev_id, peer_addr, tid_bitmap);
Bartosz Markowskice428702013-09-26 17:47:05 +02003637 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_flush_tids_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003638}
3639
3640int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
3641 const u8 *peer_addr, enum wmi_peer_param param_id,
3642 u32 param_value)
3643{
3644 struct wmi_peer_set_param_cmd *cmd;
3645 struct sk_buff *skb;
3646
3647 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3648 if (!skb)
3649 return -ENOMEM;
3650
3651 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
3652 cmd->vdev_id = __cpu_to_le32(vdev_id);
3653 cmd->param_id = __cpu_to_le32(param_id);
3654 cmd->param_value = __cpu_to_le32(param_value);
Joe Perchesd458cdf2013-10-01 19:04:40 -07003655 memcpy(&cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003656
3657 ath10k_dbg(ATH10K_DBG_WMI,
3658 "wmi vdev %d peer 0x%pM set param %d value %d\n",
3659 vdev_id, peer_addr, param_id, param_value);
3660
Bartosz Markowskice428702013-09-26 17:47:05 +02003661 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_set_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003662}
3663
3664int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
3665 enum wmi_sta_ps_mode psmode)
3666{
3667 struct wmi_sta_powersave_mode_cmd *cmd;
3668 struct sk_buff *skb;
3669
3670 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3671 if (!skb)
3672 return -ENOMEM;
3673
3674 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
3675 cmd->vdev_id = __cpu_to_le32(vdev_id);
3676 cmd->sta_ps_mode = __cpu_to_le32(psmode);
3677
3678 ath10k_dbg(ATH10K_DBG_WMI,
3679 "wmi set powersave id 0x%x mode %d\n",
3680 vdev_id, psmode);
3681
Bartosz Markowskice428702013-09-26 17:47:05 +02003682 return ath10k_wmi_cmd_send(ar, skb,
3683 ar->wmi.cmd->sta_powersave_mode_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003684}
3685
3686int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
3687 enum wmi_sta_powersave_param param_id,
3688 u32 value)
3689{
3690 struct wmi_sta_powersave_param_cmd *cmd;
3691 struct sk_buff *skb;
3692
3693 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3694 if (!skb)
3695 return -ENOMEM;
3696
3697 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
3698 cmd->vdev_id = __cpu_to_le32(vdev_id);
3699 cmd->param_id = __cpu_to_le32(param_id);
3700 cmd->param_value = __cpu_to_le32(value);
3701
3702 ath10k_dbg(ATH10K_DBG_WMI,
3703 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
3704 vdev_id, param_id, value);
Bartosz Markowskice428702013-09-26 17:47:05 +02003705 return ath10k_wmi_cmd_send(ar, skb,
3706 ar->wmi.cmd->sta_powersave_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003707}
3708
3709int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
3710 enum wmi_ap_ps_peer_param param_id, u32 value)
3711{
3712 struct wmi_ap_ps_peer_cmd *cmd;
3713 struct sk_buff *skb;
3714
3715 if (!mac)
3716 return -EINVAL;
3717
3718 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3719 if (!skb)
3720 return -ENOMEM;
3721
3722 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
3723 cmd->vdev_id = __cpu_to_le32(vdev_id);
3724 cmd->param_id = __cpu_to_le32(param_id);
3725 cmd->param_value = __cpu_to_le32(value);
3726 memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
3727
3728 ath10k_dbg(ATH10K_DBG_WMI,
3729 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
3730 vdev_id, param_id, value, mac);
3731
Bartosz Markowskice428702013-09-26 17:47:05 +02003732 return ath10k_wmi_cmd_send(ar, skb,
3733 ar->wmi.cmd->ap_ps_peer_param_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003734}
3735
3736int ath10k_wmi_scan_chan_list(struct ath10k *ar,
3737 const struct wmi_scan_chan_list_arg *arg)
3738{
3739 struct wmi_scan_chan_list_cmd *cmd;
3740 struct sk_buff *skb;
3741 struct wmi_channel_arg *ch;
3742 struct wmi_channel *ci;
3743 int len;
3744 int i;
3745
3746 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
3747
3748 skb = ath10k_wmi_alloc_skb(len);
3749 if (!skb)
3750 return -EINVAL;
3751
3752 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
3753 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
3754
3755 for (i = 0; i < arg->n_channels; i++) {
3756 u32 flags = 0;
3757
3758 ch = &arg->channels[i];
3759 ci = &cmd->chan_info[i];
3760
3761 if (ch->passive)
3762 flags |= WMI_CHAN_FLAG_PASSIVE;
3763 if (ch->allow_ibss)
3764 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
3765 if (ch->allow_ht)
3766 flags |= WMI_CHAN_FLAG_ALLOW_HT;
3767 if (ch->allow_vht)
3768 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
3769 if (ch->ht40plus)
3770 flags |= WMI_CHAN_FLAG_HT40_PLUS;
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003771 if (ch->chan_radar)
3772 flags |= WMI_CHAN_FLAG_DFS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003773
3774 ci->mhz = __cpu_to_le32(ch->freq);
3775 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
3776 ci->band_center_freq2 = 0;
3777 ci->min_power = ch->min_power;
3778 ci->max_power = ch->max_power;
3779 ci->reg_power = ch->max_reg_power;
3780 ci->antenna_max = ch->max_antenna_gain;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003781
3782 /* mode & flags share storage */
3783 ci->mode = ch->mode;
3784 ci->flags |= __cpu_to_le32(flags);
3785 }
3786
Bartosz Markowskice428702013-09-26 17:47:05 +02003787 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->scan_chan_list_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003788}
3789
Michal Kazior24c88f72014-07-25 13:32:17 +02003790static void
3791ath10k_wmi_peer_assoc_fill(struct ath10k *ar, void *buf,
3792 const struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003793{
Michal Kazior24c88f72014-07-25 13:32:17 +02003794 struct wmi_common_peer_assoc_complete_cmd *cmd = buf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003795
Kalle Valo5e3dd152013-06-12 20:52:10 +03003796 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
3797 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
3798 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
3799 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
3800 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
3801 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
3802 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
3803 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
3804 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
3805 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
3806 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
3807 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
3808 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
3809
3810 memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
3811
3812 cmd->peer_legacy_rates.num_rates =
3813 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
3814 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
3815 arg->peer_legacy_rates.num_rates);
3816
3817 cmd->peer_ht_rates.num_rates =
3818 __cpu_to_le32(arg->peer_ht_rates.num_rates);
3819 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
3820 arg->peer_ht_rates.num_rates);
3821
3822 cmd->peer_vht_rates.rx_max_rate =
3823 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
3824 cmd->peer_vht_rates.rx_mcs_set =
3825 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
3826 cmd->peer_vht_rates.tx_max_rate =
3827 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
3828 cmd->peer_vht_rates.tx_mcs_set =
3829 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
Michal Kazior24c88f72014-07-25 13:32:17 +02003830}
3831
3832static void
3833ath10k_wmi_peer_assoc_fill_main(struct ath10k *ar, void *buf,
3834 const struct wmi_peer_assoc_complete_arg *arg)
3835{
3836 struct wmi_main_peer_assoc_complete_cmd *cmd = buf;
3837
3838 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
3839 memset(cmd->peer_ht_info, 0, sizeof(cmd->peer_ht_info));
3840}
3841
3842static void
3843ath10k_wmi_peer_assoc_fill_10_1(struct ath10k *ar, void *buf,
3844 const struct wmi_peer_assoc_complete_arg *arg)
3845{
3846 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
3847}
3848
3849static void
3850ath10k_wmi_peer_assoc_fill_10_2(struct ath10k *ar, void *buf,
3851 const struct wmi_peer_assoc_complete_arg *arg)
3852{
3853 struct wmi_10_2_peer_assoc_complete_cmd *cmd = buf;
3854 int max_mcs, max_nss;
3855 u32 info0;
3856
3857 /* TODO: Is using max values okay with firmware? */
3858 max_mcs = 0xf;
3859 max_nss = 0xf;
3860
3861 info0 = SM(max_mcs, WMI_PEER_ASSOC_INFO0_MAX_MCS_IDX) |
3862 SM(max_nss, WMI_PEER_ASSOC_INFO0_MAX_NSS);
3863
3864 ath10k_wmi_peer_assoc_fill(ar, buf, arg);
3865 cmd->info0 = __cpu_to_le32(info0);
3866}
3867
3868int ath10k_wmi_peer_assoc(struct ath10k *ar,
3869 const struct wmi_peer_assoc_complete_arg *arg)
3870{
3871 struct sk_buff *skb;
3872 int len;
3873
3874 if (arg->peer_mpdu_density > 16)
3875 return -EINVAL;
3876 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
3877 return -EINVAL;
3878 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
3879 return -EINVAL;
3880
3881 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3882 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3883 len = sizeof(struct wmi_10_2_peer_assoc_complete_cmd);
3884 else
3885 len = sizeof(struct wmi_10_1_peer_assoc_complete_cmd);
3886 } else {
3887 len = sizeof(struct wmi_main_peer_assoc_complete_cmd);
3888 }
3889
3890 skb = ath10k_wmi_alloc_skb(len);
3891 if (!skb)
3892 return -ENOMEM;
3893
3894 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
3895 if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features))
3896 ath10k_wmi_peer_assoc_fill_10_1(ar, skb->data, arg);
3897 else
3898 ath10k_wmi_peer_assoc_fill_10_2(ar, skb->data, arg);
3899 } else {
3900 ath10k_wmi_peer_assoc_fill_main(ar, skb->data, arg);
3901 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003902
Michal Kaziore0c508a2013-07-05 16:15:17 +03003903 ath10k_dbg(ATH10K_DBG_WMI,
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02003904 "wmi peer assoc vdev %d addr %pM (%s)\n",
3905 arg->vdev_id, arg->addr,
3906 arg->peer_reassoc ? "reassociate" : "new");
Bartosz Markowskice428702013-09-26 17:47:05 +02003907 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->peer_assoc_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003908}
3909
Michal Kazior748afc42014-01-23 12:48:21 +01003910/* This function assumes the beacon is already DMA mapped */
3911int ath10k_wmi_beacon_send_ref_nowait(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003912{
Michal Kazior748afc42014-01-23 12:48:21 +01003913 struct wmi_bcn_tx_ref_cmd *cmd;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003914 struct sk_buff *skb;
Michal Kazior748afc42014-01-23 12:48:21 +01003915 struct sk_buff *beacon = arvif->beacon;
3916 struct ath10k *ar = arvif->ar;
3917 struct ieee80211_hdr *hdr;
Michal Kaziore2045482013-10-28 07:18:14 +01003918 int ret;
Michal Kazior748afc42014-01-23 12:48:21 +01003919 u16 fc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003920
Michal Kazior748afc42014-01-23 12:48:21 +01003921 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003922 if (!skb)
3923 return -ENOMEM;
3924
Michal Kazior748afc42014-01-23 12:48:21 +01003925 hdr = (struct ieee80211_hdr *)beacon->data;
3926 fc = le16_to_cpu(hdr->frame_control);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003927
Michal Kazior748afc42014-01-23 12:48:21 +01003928 cmd = (struct wmi_bcn_tx_ref_cmd *)skb->data;
3929 cmd->vdev_id = __cpu_to_le32(arvif->vdev_id);
3930 cmd->data_len = __cpu_to_le32(beacon->len);
3931 cmd->data_ptr = __cpu_to_le32(ATH10K_SKB_CB(beacon)->paddr);
3932 cmd->msdu_id = 0;
3933 cmd->frame_control = __cpu_to_le32(fc);
3934 cmd->flags = 0;
Michal Kazior24c88f72014-07-25 13:32:17 +02003935 cmd->antenna_mask = __cpu_to_le32(WMI_BCN_TX_REF_DEF_ANTENNA);
Michal Kazior748afc42014-01-23 12:48:21 +01003936
3937 if (ATH10K_SKB_CB(beacon)->bcn.dtim_zero)
3938 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DTIM_ZERO);
3939
3940 if (ATH10K_SKB_CB(beacon)->bcn.deliver_cab)
3941 cmd->flags |= __cpu_to_le32(WMI_BCN_TX_REF_FLAG_DELIVER_CAB);
3942
3943 ret = ath10k_wmi_cmd_send_nowait(ar, skb,
3944 ar->wmi.cmd->pdev_send_bcn_cmdid);
3945
Michal Kaziore2045482013-10-28 07:18:14 +01003946 if (ret)
3947 dev_kfree_skb(skb);
3948
3949 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003950}
3951
3952static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
3953 const struct wmi_wmm_params_arg *arg)
3954{
3955 params->cwmin = __cpu_to_le32(arg->cwmin);
3956 params->cwmax = __cpu_to_le32(arg->cwmax);
3957 params->aifs = __cpu_to_le32(arg->aifs);
3958 params->txop = __cpu_to_le32(arg->txop);
3959 params->acm = __cpu_to_le32(arg->acm);
3960 params->no_ack = __cpu_to_le32(arg->no_ack);
3961}
3962
3963int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
3964 const struct wmi_pdev_set_wmm_params_arg *arg)
3965{
3966 struct wmi_pdev_set_wmm_params *cmd;
3967 struct sk_buff *skb;
3968
3969 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3970 if (!skb)
3971 return -ENOMEM;
3972
3973 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
3974 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
3975 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
3976 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
3977 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
3978
3979 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
Bartosz Markowskice428702013-09-26 17:47:05 +02003980 return ath10k_wmi_cmd_send(ar, skb,
3981 ar->wmi.cmd->pdev_set_wmm_params_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003982}
3983
3984int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
3985{
3986 struct wmi_request_stats_cmd *cmd;
3987 struct sk_buff *skb;
3988
3989 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
3990 if (!skb)
3991 return -ENOMEM;
3992
3993 cmd = (struct wmi_request_stats_cmd *)skb->data;
3994 cmd->stats_id = __cpu_to_le32(stats_id);
3995
3996 ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
Bartosz Markowskice428702013-09-26 17:47:05 +02003997 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->request_stats_cmdid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003998}
Michal Kazior9cfbce72013-07-16 09:54:36 +02003999
4000int ath10k_wmi_force_fw_hang(struct ath10k *ar,
4001 enum wmi_force_fw_hang_type type, u32 delay_ms)
4002{
4003 struct wmi_force_fw_hang_cmd *cmd;
4004 struct sk_buff *skb;
4005
4006 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
4007 if (!skb)
4008 return -ENOMEM;
4009
4010 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
4011 cmd->type = __cpu_to_le32(type);
4012 cmd->delay_ms = __cpu_to_le32(delay_ms);
4013
4014 ath10k_dbg(ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
4015 type, delay_ms);
Bartosz Markowskice428702013-09-26 17:47:05 +02004016 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->force_fw_hang_cmdid);
Michal Kazior9cfbce72013-07-16 09:54:36 +02004017}
Kalle Valof118a3e2014-01-03 12:59:31 +02004018
4019int ath10k_wmi_dbglog_cfg(struct ath10k *ar, u32 module_enable)
4020{
4021 struct wmi_dbglog_cfg_cmd *cmd;
4022 struct sk_buff *skb;
4023 u32 cfg;
4024
4025 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
4026 if (!skb)
4027 return -ENOMEM;
4028
4029 cmd = (struct wmi_dbglog_cfg_cmd *)skb->data;
4030
4031 if (module_enable) {
4032 cfg = SM(ATH10K_DBGLOG_LEVEL_VERBOSE,
4033 ATH10K_DBGLOG_CFG_LOG_LVL);
4034 } else {
4035 /* set back defaults, all modules with WARN level */
4036 cfg = SM(ATH10K_DBGLOG_LEVEL_WARN,
4037 ATH10K_DBGLOG_CFG_LOG_LVL);
4038 module_enable = ~0;
4039 }
4040
4041 cmd->module_enable = __cpu_to_le32(module_enable);
4042 cmd->module_valid = __cpu_to_le32(~0);
4043 cmd->config_enable = __cpu_to_le32(cfg);
4044 cmd->config_valid = __cpu_to_le32(ATH10K_DBGLOG_CFG_LOG_LVL_MASK);
4045
4046 ath10k_dbg(ATH10K_DBG_WMI,
4047 "wmi dbglog cfg modules %08x %08x config %08x %08x\n",
4048 __le32_to_cpu(cmd->module_enable),
4049 __le32_to_cpu(cmd->module_valid),
4050 __le32_to_cpu(cmd->config_enable),
4051 __le32_to_cpu(cmd->config_valid));
4052
4053 return ath10k_wmi_cmd_send(ar, skb, ar->wmi.cmd->dbglog_cfg_cmdid);
4054}