blob: 58c157d9ea0c153946967819f020a373335f2c06 [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
2 * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*
29 * Host WMI unified implementation
30 */
31#include "athdefs.h"
32#include "osapi_linux.h"
33#include "a_types.h"
34#include "a_debug.h"
35#include "ol_if_athvar.h"
36#include "ol_defines.h"
37#include "ol_fw.h"
38#include "htc_api.h"
39#include "htc_api.h"
40#include "dbglog_host.h"
41#include "wmi.h"
42#include "wmi_unified_priv.h"
43#include "wma_api.h"
44#include "wma.h"
45#include "mac_trace.h"
46
47#define WMI_MIN_HEAD_ROOM 64
48
49#ifdef WMI_INTERFACE_EVENT_LOGGING
50/* WMI commands */
51uint32_t g_wmi_command_buf_idx = 0;
52struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
53
54/* WMI commands TX completed */
55uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
56struct wmi_command_debug
57 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
58
59/* WMI events when processed */
60uint32_t g_wmi_event_buf_idx = 0;
61struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
62
63/* WMI events when queued */
64uint32_t g_wmi_rx_event_buf_idx = 0;
65struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
66
67#define WMI_COMMAND_RECORD(a, b) { \
68 if (WMI_EVENT_DEBUG_MAX_ENTRY <= g_wmi_command_buf_idx) \
69 g_wmi_command_buf_idx = 0; \
70 wmi_command_log_buffer[g_wmi_command_buf_idx].command = a; \
71 cdf_mem_copy(wmi_command_log_buffer[g_wmi_command_buf_idx].data, b, 16); \
72 wmi_command_log_buffer[g_wmi_command_buf_idx].time = \
73 cdf_get_log_timestamp(); \
74 g_wmi_command_buf_idx++; \
75}
76
77#define WMI_COMMAND_TX_CMP_RECORD(a, b) { \
78 if (WMI_EVENT_DEBUG_MAX_ENTRY <= g_wmi_command_tx_cmp_buf_idx) \
79 g_wmi_command_tx_cmp_buf_idx = 0; \
80 wmi_command_tx_cmp_log_buffer[g_wmi_command_tx_cmp_buf_idx].command = a; \
81 cdf_mem_copy(wmi_command_tx_cmp_log_buffer \
82 [g_wmi_command_tx_cmp_buf_idx].data, b, 16); \
83 wmi_command_tx_cmp_log_buffer[g_wmi_command_tx_cmp_buf_idx].time = \
84 cdf_get_log_timestamp(); \
85 g_wmi_command_tx_cmp_buf_idx++; \
86}
87
88#define WMI_EVENT_RECORD(a, b) { \
89 if (WMI_EVENT_DEBUG_MAX_ENTRY <= g_wmi_event_buf_idx) \
90 g_wmi_event_buf_idx = 0; \
91 wmi_event_log_buffer[g_wmi_event_buf_idx].event = a; \
92 cdf_mem_copy(wmi_event_log_buffer[g_wmi_event_buf_idx].data, b, 16); \
93 wmi_event_log_buffer[g_wmi_event_buf_idx].time = \
94 cdf_get_log_timestamp(); \
95 g_wmi_event_buf_idx++; \
96}
97
98#define WMI_RX_EVENT_RECORD(a, b) { \
99 if (WMI_EVENT_DEBUG_MAX_ENTRY <= g_wmi_rx_event_buf_idx) \
100 g_wmi_rx_event_buf_idx = 0; \
101 wmi_rx_event_log_buffer[g_wmi_rx_event_buf_idx].event = a; \
102 cdf_mem_copy(wmi_rx_event_log_buffer[g_wmi_rx_event_buf_idx].data, b, 16); \
103 wmi_rx_event_log_buffer[g_wmi_rx_event_buf_idx].time = \
104 cdf_get_log_timestamp(); \
105 g_wmi_rx_event_buf_idx++; \
106}
107/* wmi_mgmt commands */
108#define WMI_MGMT_EVENT_DEBUG_MAX_ENTRY (256)
109
110uint32_t g_wmi_mgmt_command_buf_idx = 0;
111struct
112wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
113
114/* wmi_mgmt commands TX completed */
115uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
116struct wmi_command_debug
117wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
118
119/* wmi_mgmt events when processed */
120uint32_t g_wmi_mgmt_event_buf_idx = 0;
121struct wmi_event_debug
122wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
123
124#define WMI_MGMT_COMMAND_RECORD(a, b) { \
125 if (WMI_MGMT_EVENT_DEBUG_MAX_ENTRY <= \
126 g_wmi_mgmt_command_buf_idx) \
127 g_wmi_mgmt_command_buf_idx = 0; \
128 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].command = a; \
129 cdf_mem_copy( \
130 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].data,\
131 b, 16); \
132 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].time = \
133 cdf_get_log_timestamp(); \
134 g_wmi_mgmt_command_buf_idx++; \
135}
136
137#define WMI_MGMT_COMMAND_TX_CMP_RECORD(a, b) { \
138 if (WMI_MGMT_EVENT_DEBUG_MAX_ENTRY <= \
139 g_wmi_mgmt_command_tx_cmp_buf_idx) \
140 g_wmi_mgmt_command_tx_cmp_buf_idx = 0; \
141 wmi_mgmt_command_tx_cmp_log_buffer[g_wmi_mgmt_command_tx_cmp_buf_idx].\
142 command = a; \
143 cdf_mem_copy(wmi_mgmt_command_tx_cmp_log_buffer \
144 [g_wmi_mgmt_command_tx_cmp_buf_idx].data, b, 16); \
145 wmi_mgmt_command_tx_cmp_log_buffer[g_wmi_mgmt_command_tx_cmp_buf_idx].\
146 time =\
147 cdf_get_log_timestamp(); \
148 g_wmi_mgmt_command_tx_cmp_buf_idx++; \
149}
150
151#define WMI_MGMT_EVENT_RECORD(a, b) { \
152 if (WMI_MGMT_EVENT_DEBUG_MAX_ENTRY <= g_wmi_mgmt_event_buf_idx) \
153 g_wmi_mgmt_event_buf_idx = 0; \
154 wmi_mgmt_event_log_buffer[g_wmi_mgmt_event_buf_idx].event = a; \
155 cdf_mem_copy(wmi_mgmt_event_log_buffer[g_wmi_mgmt_event_buf_idx].data,\
156 b, 16); \
157 wmi_mgmt_event_log_buffer[g_wmi_mgmt_event_buf_idx].time = \
158 cdf_get_log_timestamp(); \
159 g_wmi_mgmt_event_buf_idx++; \
160}
161
162#endif /*WMI_INTERFACE_EVENT_LOGGING */
163
164static void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf);
165int wmi_get_host_credits(wmi_unified_t wmi_handle);
166/* WMI buffer APIs */
167
168#ifdef MEMORY_DEBUG
169wmi_buf_t
170wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
171 uint32_t line_num)
172{
173 wmi_buf_t wmi_buf;
174
175 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
176 CDF_ASSERT(0);
177 return NULL;
178 }
179
180 wmi_buf = cdf_nbuf_alloc_debug(NULL,
181 roundup(len + WMI_MIN_HEAD_ROOM, 4),
182 WMI_MIN_HEAD_ROOM, 4, false, file_name,
183 line_num);
184
185 if (!wmi_buf)
186 return NULL;
187
188 /* Clear the wmi buffer */
189 OS_MEMZERO(cdf_nbuf_data(wmi_buf), len);
190
191 /*
192 * Set the length of the buffer to match the allocation size.
193 */
194 cdf_nbuf_set_pktlen(wmi_buf, len);
195
196 return wmi_buf;
197}
198
199void wmi_buf_free(wmi_buf_t net_buf)
200{
201 cdf_nbuf_free(net_buf);
202}
203#else
204wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
205{
206 wmi_buf_t wmi_buf;
207
208 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
209 CDF_ASSERT(0);
210 return NULL;
211 }
212
213 wmi_buf = cdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
214 WMI_MIN_HEAD_ROOM, 4, false);
215 if (!wmi_buf)
216 return NULL;
217
218 /* Clear the wmi buffer */
219 OS_MEMZERO(cdf_nbuf_data(wmi_buf), len);
220
221 /*
222 * Set the length of the buffer to match the allocation size.
223 */
224 cdf_nbuf_set_pktlen(wmi_buf, len);
225 return wmi_buf;
226}
227
228void wmi_buf_free(wmi_buf_t net_buf)
229{
230 cdf_nbuf_free(net_buf);
231}
232#endif
233
234/**
235 * wmi_get_max_msg_len() - get maximum WMI message length
236 * @wmi_handle: WMI handle.
237 *
238 * This function returns the maximum WMI message length
239 *
240 * Return: maximum WMI message length
241 */
242uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
243{
244 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
245}
246
247static uint8_t *get_wmi_cmd_string(WMI_CMD_ID wmi_command)
248{
249 switch (wmi_command) {
250 /* initialize the wlan sub system */
251 CASE_RETURN_STRING(WMI_INIT_CMDID);
252
253 /* Scan specific commands */
254
255 /* start scan request to FW */
256 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
257 /* stop scan request to FW */
258 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
259 /* full list of channels as defined by the regulatory
260 * that will be used by scanner */
261 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
262 /* overwrite default priority table in scan scheduler */
263 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
264 /* This command to adjust the priority and min.max_rest_time
265 * of an on ongoing scan request.
266 */
267 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
268
269 /* PDEV(physical device) specific commands */
270 /* set regulatorty ctl id used by FW to determine the exact
271 * ctl power limits */
272 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
273 /* set channel. mainly used for supporting monitor mode */
274 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
275 /* set pdev specific parameters */
276 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
277 /* enable packet log */
278 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
279 /* disable packet log*/
280 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
281 /* set wmm parameters */
282 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
283 /* set HT cap ie that needs to be carried probe requests
284 * HT/VHT channels */
285 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
286 /* set VHT cap ie that needs to be carried on probe
287 * requests on VHT channels */
288 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
289
290 /* Command to send the DSCP-to-TID map to the target */
291 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
292 /* set quiet ie parameters. primarily used in AP mode */
293 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
294 /* Enable/Disable Green AP Power Save */
295 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
296 /* get TPC config for the current operating channel */
297 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
298
299 /* set the base MAC address for the physical device before
300 * a VDEV is created. For firmware that does not support
301 * this feature and this command, the pdev MAC address will
302 * not be changed. */
303 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
304
305 /* eeprom content dump , the same to bdboard data */
306 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
307
308 /* VDEV(virtual device) specific commands */
309 /* vdev create */
310 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
311 /* vdev delete */
312 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
313 /* vdev start request */
314 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
315 /* vdev restart request (RX only, NO TX, used for CAC period)*/
316 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
317 /* vdev up request */
318 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
319 /* vdev stop request */
320 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
321 /* vdev down request */
322 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
323 /* set a vdev param */
324 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
325 /* set a key (used for setting per peer unicast
326 * and per vdev multicast) */
327 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
328
329 /* wnm sleep mode command */
330 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
331 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
332 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
333 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
334 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
335 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
336
337 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
338 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
339 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
340 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
341
342 /* peer specific commands */
343
344 /** create a peer */
345 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
346 /** delete a peer */
347 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
348 /** flush specific tid queues of a peer */
349 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
350 /** set a parameter of a peer */
351 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
352 /* set peer to associated state. will cary all parameters
353 * determined during assocication time */
354 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
355 /* add a wds (4 address ) entry. used only for testing
356 * WDS feature on AP products */
357 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
358 /* remove wds (4 address ) entry. used only for testing WDS
359 * feature on AP products */
360 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
361 /* set up mcast info for multicast to unicast conversion */
362 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
363 /* request peer info from FW to get PEER_INFO_EVENTID */
364 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
365
366 /* beacon/management specific commands */
367
368 /* transmit beacon by reference. used for transmitting beacon
369 * on low latency interface like pcie */
370 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
371 /* transmit beacon by value */
372 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
373 /* set the beacon template. used in beacon offload mode to setup
374 * the common beacon template with the FW to be used by FW to
375 * generate beacons */
376 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
377 /* set beacon filter with FW */
378 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
379 /* enable/disable filtering of probe requests in the firmware */
380 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
381 /* transmit management frame by value. will be deprecated */
382 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
383 /* set the probe response template. used in beacon offload mode
384 * to setup the common probe response template with the FW to
385 * be used by FW to generate probe responses */
386 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
387
388 /* commands to directly control ba negotiation directly from
389 * host. only used in test mode */
390
391 /* turn off FW Auto addba mode and let host control addba */
392 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
393 /* send add ba request */
394 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
395 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
396 /* send del ba */
397 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
398 /* set add ba response will be used by FW to generate
399 * addba response*/
400 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
401 /* send single VHT MPDU with AMSDU */
402 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
403
404 /* Station power save specific config */
405 /* enable/disable station powersave */
406 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
407 /* set station power save specific parameter */
408 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
409 /* set station mimo powersave mode */
410 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
411
412 /* DFS-specific commands */
413 /* enable DFS (radar detection)*/
414 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
415 /* disable DFS (radar detection)*/
416 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
417 /* enable DFS phyerr/parse filter offload */
418 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
419 /* enable DFS phyerr/parse filter offload */
420 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
421
422 /* Roaming specific commands */
423 /* set roam scan mode */
424 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
425 /* set roam scan rssi threshold below which roam
426 * scan is enabled */
427 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
428 /* set roam scan period for periodic roam scan mode */
429 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
430 /* set roam scan trigger rssi change threshold */
431 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
432 /* set roam AP profile */
433 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
434 /* set channel list for roam scans */
435 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
436 /* offload scan specific commands */
437 /* set offload scan AP profile */
438 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
439 /* remove offload scan AP profile */
440 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
441 /* set offload scan period */
442 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
443
444 /* P2P specific commands */
445 /* set P2P device info. FW will used by FW to create P2P IE
446 * to be carried in probe response generated during p2p listen
447 * and for p2p discoverability */
448 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
449 /* enable/disable p2p discoverability on STA/AP VDEVs */
450 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
451 /* set p2p ie to be carried in beacons generated by FW for GO */
452 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
453 /* set p2p ie to be carried in probe response frames generated
454 * by FW for GO */
455 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
456 /* set the vendor specific p2p ie data.
457 * FW will use this to parse the P2P NoA
458 * attribute in the beacons/probe responses received.
459 */
460 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
461 /* set the configure of p2p find offload */
462 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
463 /* set the vendor specific p2p ie data for p2p find offload */
464 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
465 /* set the BSSID/device name pattern of p2p find offload */
466 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
467 /* set OppPS related parameters **/
468 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
469
470 /* AP power save specific config
471 * set AP power save specific param */
472 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
473 /* set AP UAPSD coex pecific param */
474 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
475
476 /* Rate-control specific commands */
477 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
478
479 /* WLAN Profiling commands. */
480 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
481 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
482 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
483 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
484 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
485
486 /* Suspend resume command Ids */
487 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
488 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
489
490 /* Beacon filter commands */
491 /* add a beacon filter */
492 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
493 /* remove a beacon filter */
494 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
495
496 /* WOW Specific WMI commands */
497 /* add pattern for awake */
498 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
499 /* deleta a wake pattern */
500 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
501 /* enable/deisable wake event */
502 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
503 /* enable WOW */
504 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
505 /* host woke up from sleep event to FW. Generated in response
506 * to WOW Hardware event */
507 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
508
509 /* RTT measurement related cmd */
510 /* reques to make an RTT measurement */
511 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
512 /* reques to report a tsf measurement */
513 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
514
515 /* spectral scan command */
516 /* configure spectral scan */
517 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
518 /* enable/disable spectral scan and trigger */
519 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
520
521 /* F/W stats */
522 /* one time request for stats */
523 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
524 /* Push MCC Adaptive Scheduler Stats to Firmware */
525 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
526
527 /* ARP OFFLOAD REQUEST*/
528 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
529
530 /* Proactive ARP Response Add Pattern Command*/
531 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
532
533 /* Proactive ARP Response Del Pattern Command*/
534 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
535
536 /* NS offload confid*/
537 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
538
539 /* GTK offload Specific WMI commands */
540 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
541
542 /* CSA offload Specific WMI commands */
543 /* csa offload enable */
544 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
545 /* chan switch command */
546 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
547
548 /* Chatter commands */
549 /* Change chatter mode of operation */
550 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
551 /* chatter add coalescing filter command */
552 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
553 /* chatter delete coalescing filter command */
554 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
555 /* chatter coalecing query command */
556 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
557
558 /* addba specific commands */
559 /* start the aggregation on this TID */
560 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
561 /* stop the aggregation on this TID */
562 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
563
564 /* set station mimo powersave method */
565 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
566 /* Configure the Station UAPSD AC Auto Trigger Parameters */
567 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
568 /* Configure the Keep Alive Parameters */
569 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
570
571 /* Request ssn from target for a sta/tid pair */
572 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
573 /* misc command group */
574 /* echo command mainly used for testing */
575 CASE_RETURN_STRING(WMI_ECHO_CMDID);
576
577 /* !!IMPORTANT!!
578 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
579 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
580 * as we MUST have a fixed value here to maintain compatibility between
581 * UTF and the ART2 driver
582 */
583 /** UTF WMI commands */
584 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
585
586 /** set debug log config */
587 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
588 /* QVIT specific command id */
589 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
590 /* Factory Testing Mode request command
591 * used for integrated chipsets */
592 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
593 /* set and get keepalive parameters command */
594 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
595 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
596 /* For fw recovery test command */
597 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
598 /* Set Mcast/Bdcast filter */
599 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
600 /* set thermal management params */
601 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
602 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
603 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
604 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
605 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
606 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
607 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
608 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
609 /* GPIO Configuration */
610 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
611 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
612
613 /* Txbf configuration command */
614 CASE_RETURN_STRING(WMI_TXBF_CMDID);
615
616 /* FWTEST Commands */
617 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
618 /* set NoA descs */
619 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
620
621 /* TDLS Configuration */
622 /* enable/disable TDLS */
623 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
624 /* set tdls peer state */
625 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
626
627 /* Resmgr Configuration */
628 /* Adaptive OCS is enabled by default in the FW.
629 * This command is used to disable FW based adaptive OCS.
630 */
631 CASE_RETURN_STRING
632 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
633 /* set the requested channel time quota for the home channels */
634 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
635 /* set the requested latency for the home channels */
636 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
637
638 /* STA SMPS Configuration */
639 /* force SMPS mode */
640 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
641 /* set SMPS parameters */
642 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
643
644 /* Wlan HB commands */
645 /* enalbe/disable wlan HB */
646 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
647 /* set tcp parameters for wlan HB */
648 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
649 /* set tcp pkt filter for wlan HB */
650 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
651 /* set udp parameters for wlan HB */
652 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
653 /* set udp pkt filter for wlan HB */
654 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
655
656 /* Wlan RMC commands*/
657 /* enable/disable RMC */
658 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
659 /* configure action frame period */
660 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
661 /* For debug/future enhancement purposes only,
662 * configures/finetunes RMC algorithms */
663 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
664
665 /* WLAN MHF offload commands */
666 /** enable/disable MHF offload */
667 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
668 /* Plumb routing table for MHF offload */
669 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
670
671 /* location scan commands */
672 /* start batch scan */
673 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
674 /* stop batch scan */
675 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
676 /* get batch scan result */
677 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
678 /* OEM related cmd */
679 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
680 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
681 /* NAN request cmd */
682 CASE_RETURN_STRING(WMI_NAN_CMDID);
683 /* Modem power state cmd */
684 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
685 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
686 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
687 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
688 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
689 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
690 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
691 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
692 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
693 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
694 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
695 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
696 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
697 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
698 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
699 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
700 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
701 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
702 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
703 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
704 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
705 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
706 CASE_RETURN_STRING
707 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
708 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
709 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
710 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
711 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
712 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
713 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
714 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
715 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
716 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
717 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
718 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
719 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
720 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
721 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
722 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
723 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
724 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
725 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
726 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
727 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
728 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
729 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
730 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
731 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
732 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
733 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
734 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
735 CASE_RETURN_STRING(WMI_APFIND_CMDID);
736 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
737 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
738 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
739 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
740 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
741 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
742 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
743 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
744 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
745 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
746 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
747 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
748 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
749 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
750 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
751 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
752 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
753 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
754 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
755 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
756 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
757 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
758 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
759 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
760 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
761 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
762 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
763 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
764 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
765 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
766 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
767 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
768
769 }
770
771 return "Invalid WMI cmd";
772}
773
774#ifdef QCA_WIFI_3_0_EMU
775static inline void wma_log_cmd_id(WMI_CMD_ID cmd_id)
776{
777 WMA_LOGE("Send WMI command:%s command_id:%d",
778 get_wmi_cmd_string(cmd_id), cmd_id);
779}
780#else
781static inline void wma_log_cmd_id(WMI_CMD_ID cmd_id)
782{
783 WMA_LOGD("Send WMI command:%s command_id:%d",
784 get_wmi_cmd_string(cmd_id), cmd_id);
785}
786#endif
787
788/**
789 * wmi_is_runtime_pm_cmd() - check if a cmd is part of the suspend resume sequence
790 * @cmd: command to check
791 *
792 * Return: true if the command is part of the suspend resume sequence.
793 */
794bool wmi_is_runtime_pm_cmd(WMI_CMD_ID cmd_id)
795{
796 switch (cmd_id) {
797 case WMI_WOW_ENABLE_CMDID:
798 case WMI_PDEV_SUSPEND_CMDID:
799 case WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID:
800 case WMI_WOW_ADD_WAKE_PATTERN_CMDID:
801 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
802 case WMI_PDEV_RESUME_CMDID:
803 case WMI_WOW_DEL_WAKE_PATTERN_CMDID:
804 case WMI_D0_WOW_ENABLE_DISABLE_CMDID:
805 return true;
806
807 default:
808 return false;
809 }
810}
811
812/**
813 * wmi_unified_cmd_send() - WMI command API
814 * @wmi_handle: handle to wmi
815 * @buf: wmi buf
816 * @len: wmi buffer length
817 * @cmd_id: wmi command id
818 *
819 * Return: 0 on success
820 */
821int wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf, int len,
822 WMI_CMD_ID cmd_id)
823{
824 HTC_PACKET *pkt;
825 A_STATUS status;
826
827 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
828 if (wmi_is_runtime_pm_cmd(cmd_id))
829 htc_tag = HTC_TX_PACKET_TAG_AUTO_PM;
830 } else if (cdf_atomic_read(&wmi_handle->is_target_suspended) &&
831 ((WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID != cmd_id) &&
832 (WMI_PDEV_RESUME_CMDID != cmd_id))) {
833 cdf_print("%s: Target is suspended could not send WMI command \n",
834 __func__);
835 CDF_ASSERT(0);
836 return -EBUSY;
837 }
838
839 /* Do sanity check on the TLV parameter structure */
840 {
841 void *buf_ptr = (void *)cdf_nbuf_data(buf);
842
843 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
844 != 0) {
845 cdf_print
846 ("\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d\n",
847 __func__, cmd_id);
848 return -EINVAL;
849 }
850 }
851
852 if (cdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
853 pr_err("%s, Failed to send cmd %x, no memory\n",
854 __func__, cmd_id);
855 return -ENOMEM;
856 }
857
858 WMI_SET_FIELD(cdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
859
860 cdf_atomic_inc(&wmi_handle->pending_cmds);
861 if (cdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
862 pr_err("\n%s: hostcredits = %d\n", __func__,
863 wmi_get_host_credits(wmi_handle));
864 htc_dump_counter_info(wmi_handle->htc_handle);
865 cdf_atomic_dec(&wmi_handle->pending_cmds);
866 pr_err("%s: MAX 1024 WMI Pending cmds reached.\n", __func__);
867 CDF_BUG(0);
868 return -EBUSY;
869 }
870
871 pkt = cdf_mem_malloc(sizeof(*pkt));
872 if (!pkt) {
873 cdf_atomic_dec(&wmi_handle->pending_cmds);
874 pr_err("%s, Failed to alloc htc packet %x, no memory\n",
875 __func__, cmd_id);
876 return -ENOMEM;
877 }
878
879 SET_HTC_PACKET_INFO_TX(pkt,
880 NULL,
881 cdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
882 wmi_handle->wmi_endpoint_id, htc_tag);
883
884 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
885
886 wma_log_cmd_id(cmd_id);
887
888#ifdef WMI_INTERFACE_EVENT_LOGGING
889 cdf_spin_lock_bh(&wmi_handle->wmi_record_lock);
890 /*Record 16 bytes of WMI cmd data - exclude TLV and WMI headers */
891 if (cmd_id == WMI_MGMT_TX_SEND_CMDID) {
892 WMI_MGMT_COMMAND_RECORD(cmd_id,
893 ((uint32_t *)cdf_nbuf_data(buf) + 2));
894 } else {
895 WMI_COMMAND_RECORD(cmd_id, ((uint32_t *) cdf_nbuf_data(buf) +
896 2));
897 }
898
899 cdf_spin_unlock_bh(&wmi_handle->wmi_record_lock);
900#endif
901
902 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
903
904 if (A_OK != status) {
905 cdf_atomic_dec(&wmi_handle->pending_cmds);
906 pr_err("%s %d, htc_send_pkt failed\n", __func__, __LINE__);
907 }
908 if (status)
909 return CDF_STATUS_E_FAILURE;
910
911 return CDF_STATUS_SUCCESS;
912}
913
914/**
915 * wmi_unified_get_event_handler_ix() - gives event handler's index
916 * @wmi_handle: handle to wmi
917 * @event_id: wmi event id
918 *
919 * Return: event handler's index
920 */
921int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
922 WMI_EVT_ID event_id)
923{
924 uint32_t idx = 0;
925 int32_t invalid_idx = -1;
926 for (idx = 0; (idx < wmi_handle->max_event_idx &&
927 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
928 if (wmi_handle->event_id[idx] == event_id &&
929 wmi_handle->event_handler[idx] != NULL) {
930 return idx;
931 }
932 }
933
934 return invalid_idx;
935}
936
937/**
938 * wmi_unified_register_event_handler() - register wmi event handler
939 * @wmi_handle: handle to wmi
940 * @event_id: wmi event id
941 * @handler_func: wmi event handler function
942 *
943 * Return: 0 on success
944 */
945int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
946 WMI_EVT_ID event_id,
947 wmi_unified_event_handler handler_func)
948{
949 uint32_t idx = 0;
950
951 if (wmi_unified_get_event_handler_ix(wmi_handle, event_id) != -1) {
952 cdf_print("%s : event handler already registered 0x%x \n",
953 __func__, event_id);
954 return CDF_STATUS_E_FAILURE;
955 }
956 if (wmi_handle->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
957 cdf_print("%s : no more event handlers 0x%x \n",
958 __func__, event_id);
959 return CDF_STATUS_E_FAILURE;
960 }
961 idx = wmi_handle->max_event_idx;
962 wmi_handle->event_handler[idx] = handler_func;
963 wmi_handle->event_id[idx] = event_id;
964 wmi_handle->max_event_idx++;
965
966 return 0;
967}
968
969/**
970 * wmi_unified_unregister_event_handler() - unregister wmi event handler
971 * @wmi_handle: handle to wmi
972 * @event_id: wmi event id
973 *
974 * Return: 0 on success
975 */
976int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
977 WMI_EVT_ID event_id)
978{
979 uint32_t idx = 0;
980
981 idx = wmi_unified_get_event_handler_ix(wmi_handle, event_id);
982 if (idx == -1) {
983 cdf_print("%s : event handler is not registered: event id 0x%x \n",
984 __func__, event_id);
985 return CDF_STATUS_E_FAILURE;
986 }
987 wmi_handle->event_handler[idx] = NULL;
988 wmi_handle->event_id[idx] = 0;
989 --wmi_handle->max_event_idx;
990 wmi_handle->event_handler[idx] =
991 wmi_handle->event_handler[wmi_handle->max_event_idx];
992 wmi_handle->event_id[idx] =
993 wmi_handle->event_id[wmi_handle->max_event_idx];
994
995 return 0;
996}
997
998/**
999 * wmi_process_fw_event_tasklet_ctx() - process in tasklet context
1000 * @wmi_handle: handle to wmi
1001 * @htc_packet: pointer to htc packet
1002 *
1003 * Event process by below function will be in tasket context,
1004 * need to use this method only for time sensitive functions.
1005 *
1006 * Return: none
1007 */
1008static void wmi_process_fw_event_tasklet_ctx(struct wmi_unified *wmi_handle,
1009 HTC_PACKET *htc_packet)
1010{
1011
1012 wmi_buf_t evt_buf;
1013 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1014
1015 __wmi_control_rx(wmi_handle, evt_buf);
1016 return;
1017}
1018
1019/**
1020 * wmi_process_fw_event_mc_thread_ctx() - process in mc thread context
1021 * @wmi_handle: handle to wmi
1022 * @htc_packet: pointer to htc packet
1023 *
1024 * Event process by below function will be in mc_thread context.
1025 * By default all event will be executed in mc_thread context.
1026 * Use this method for all events which are processed by protocol stack.
1027 * This method will reduce context switching and race conditions.
1028 *
1029 * Return: none
1030 */
1031static void wmi_process_fw_event_mc_thread_ctx(struct wmi_unified *wmi_handle,
1032 HTC_PACKET *htc_packet)
1033{
1034 wmi_buf_t evt_buf;
1035 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1036
1037 wmi_handle->wma_process_fw_event_handler_cbk(wmi_handle, evt_buf);
1038 return;
1039}
1040
1041/**
1042 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1043 * @wmi_handle: handle to wmi
1044 * @htc_packet: pointer to htc packet
1045 *
1046 * Event process by below function will be in worker thread context.
1047 * Use this method for events which are not critical and not
1048 * handled in protocol stack.
1049 *
1050 * Return: none
1051 */
1052static void wmi_process_fw_event_worker_thread_ctx
1053 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1054{
1055 wmi_buf_t evt_buf;
1056 uint32_t id;
1057 uint8_t *data;
1058
1059 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1060 id = WMI_GET_FIELD(cdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
1061 data = cdf_nbuf_data(evt_buf);
1062
1063 cdf_spin_lock_bh(&wmi_handle->wmi_record_lock);
1064 /* Exclude 4 bytes of TLV header */
1065 WMI_RX_EVENT_RECORD(id, ((uint8_t *) data + 4));
1066 cdf_spin_unlock_bh(&wmi_handle->wmi_record_lock);
1067 cdf_spin_lock_bh(&wmi_handle->eventq_lock);
1068 cdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1069 cdf_spin_unlock_bh(&wmi_handle->eventq_lock);
1070 schedule_work(&wmi_handle->rx_event_work);
1071 return;
1072}
1073
1074/**
1075 * wmi_control_rx() - process in worker thread context
1076 * @ctx: handle to wmi
1077 * @htc_packet: pointer to htc packet
1078 *
1079 * Temporarily added to support older WMI events.
1080 * We should move all events to unified
1081 * when the target is ready to support it.
1082 *
1083 * Return: none
1084 */
1085void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
1086{
1087 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
1088 wmi_buf_t evt_buf;
1089 uint32_t id;
1090
1091 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1092 id = WMI_GET_FIELD(cdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
1093 switch (id) {
1094 /*Event will be handled in tasklet ctx*/
1095 case WMI_TX_PAUSE_EVENTID:
1096 case WMI_WOW_WAKEUP_HOST_EVENTID:
1097 case WMI_PDEV_RESUME_EVENTID:
1098 case WMI_D0_WOW_DISABLE_ACK_EVENTID:
1099 wmi_process_fw_event_tasklet_ctx
1100 (wmi_handle, htc_packet);
1101 break;
1102 /*Event will be handled in worker thread ctx*/
1103 case WMI_DEBUG_MESG_EVENTID:
1104 case WMI_DFS_RADAR_EVENTID:
1105 case WMI_PHYERR_EVENTID:
1106 case WMI_PEER_STATE_EVENTID:
1107 case WMI_MGMT_RX_EVENTID:
1108 case WMI_ROAM_EVENTID:
1109 wmi_process_fw_event_worker_thread_ctx
1110 (wmi_handle, htc_packet);
1111 break;
1112 /*Event will be handled in mc_thread ctx*/
1113 default:
1114 wmi_process_fw_event_mc_thread_ctx
1115 (wmi_handle, htc_packet);
1116 break;
1117 }
1118}
1119
1120/**
1121 * wmi_process_fw_event() - process any fw event
1122 * @wmi_handle: wmi handle
1123 * @evt_buf: fw event buffer
1124 *
1125 * This function process any fw event to serialize it through mc thread.
1126 *
1127 * Return: none
1128 */
1129void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1130{
1131 __wmi_control_rx(wmi_handle, evt_buf);
1132}
1133
1134/**
1135 * __wmi_control_rx() - process serialize wmi event callback
1136 * @wmi_handle: wmi handle
1137 * @evt_buf: fw event buffer
1138 *
1139 * Return: none
1140 */
1141void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1142{
1143 uint32_t id;
1144 uint8_t *data;
1145 uint32_t len;
1146 void *wmi_cmd_struct_ptr = NULL;
1147 int tlv_ok_status = 0;
1148
1149 id = WMI_GET_FIELD(cdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
1150
1151 if (cdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
1152 goto end;
1153
1154 data = cdf_nbuf_data(evt_buf);
1155 len = cdf_nbuf_len(evt_buf);
1156
1157 /* Validate and pad(if necessary) the TLVs */
1158 tlv_ok_status = wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
1159 data, len, id,
1160 &wmi_cmd_struct_ptr);
1161 if (tlv_ok_status != 0) {
1162 pr_err("%s: Error: id=0x%d, wmitlv_check_and_pad_tlvs ret=%d\n",
1163 __func__, id, tlv_ok_status);
1164 goto end;
1165 }
1166
1167 if ((id >= WMI_EVT_GRP_START_ID(WMI_GRP_START)) &&
1168 /* WMI_SERVICE_READY_EXT_EVENTID is supposed to be part of the
1169 * WMI_GRP_START group. Since the group is out of space, FW
1170 * has accomodated this in WMI_GRP_VDEV.
1171 * WMI_SERVICE_READY_EXT_EVENTID does not have any specific
1172 * event handler registered. So, we do not want to go through
1173 * the WMI registered event handler path for this event.
1174 */
1175 (id != WMI_SERVICE_READY_EXT_EVENTID)) {
1176 uint32_t idx = 0;
1177
1178 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
1179 if (idx == -1) {
1180 cdf_print
1181 ("%s : event handler is not registered: event id 0x%x\n",
1182 __func__, id);
1183 goto end;
1184 }
1185#ifdef WMI_INTERFACE_EVENT_LOGGING
1186 cdf_spin_lock_bh(&wmi_handle->wmi_record_lock);
1187 /* Exclude 4 bytes of TLV header */
1188 if (id == WMI_MGMT_TX_COMPLETION_EVENTID) {
1189 WMI_MGMT_EVENT_RECORD(id, ((uint8_t *) data + 4));
1190 } else {
1191 WMI_EVENT_RECORD(id, ((uint8_t *) data + 4));
1192 }
1193 cdf_spin_unlock_bh(&wmi_handle->wmi_record_lock);
1194#endif
1195 /* Call the WMI registered event handler */
1196 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1197 wmi_cmd_struct_ptr, len);
1198 goto end;
1199 }
1200
1201 switch (id) {
1202 default:
1203 cdf_print("%s: Unhandled WMI event %d\n", __func__, id);
1204 break;
1205 case WMI_SERVICE_READY_EVENTID:
1206 cdf_print("%s: WMI UNIFIED SERVICE READY event\n", __func__);
1207 wma_rx_service_ready_event(wmi_handle->scn_handle,
1208 wmi_cmd_struct_ptr);
1209 break;
1210 case WMI_SERVICE_READY_EXT_EVENTID:
1211 WMA_LOGA("%s: WMI UNIFIED SERVICE READY Extended event",
1212 __func__);
1213 wma_rx_service_ready_ext_event(wmi_handle->scn_handle,
1214 wmi_cmd_struct_ptr);
1215 break;
1216 case WMI_READY_EVENTID:
1217 cdf_print("%s: WMI UNIFIED READY event\n", __func__);
1218 wma_rx_ready_event(wmi_handle->scn_handle, wmi_cmd_struct_ptr);
1219 break;
1220 }
1221end:
1222 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
1223 cdf_nbuf_free(evt_buf);
1224}
1225
1226/**
1227 * wmi_rx_event_work() - process rx event in rx work queue context
1228 * @work: rx work queue struct
1229 *
1230 * This function process any fw event to serialize it through rx worker thread.
1231 *
1232 * Return: none
1233 */
1234void wmi_rx_event_work(struct work_struct *work)
1235{
1236 struct wmi_unified *wmi = container_of(work, struct wmi_unified,
1237 rx_event_work);
1238 wmi_buf_t buf;
1239
1240 cdf_spin_lock_bh(&wmi->eventq_lock);
1241 buf = cdf_nbuf_queue_remove(&wmi->event_queue);
1242 cdf_spin_unlock_bh(&wmi->eventq_lock);
1243 while (buf) {
1244 __wmi_control_rx(wmi, buf);
1245 cdf_spin_lock_bh(&wmi->eventq_lock);
1246 buf = cdf_nbuf_queue_remove(&wmi->event_queue);
1247 cdf_spin_unlock_bh(&wmi->eventq_lock);
1248 }
1249}
1250
1251/* WMI Initialization functions */
1252
1253#ifdef FEATURE_RUNTIME_PM
1254/**
1255 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
1256 * @wmi_handle: wmi context
1257 */
1258void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
1259{
1260 cdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
1261}
1262#else
1263void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
1264{
1265}
1266#endif
1267
1268/**
1269 * wmi_unified_attach() - attach for unified WMI
1270 *
1271 * @param scn_handle : handle to SCN.
1272 * @wma_process_fw_event_handler_cbk: rx callbacks
1273 *
1274 * @Return: wmi handle.
1275 */
1276void *wmi_unified_attach(ol_scn_t scn_handle,
1277 wma_process_fw_event_handler_cbk func)
1278{
1279 struct wmi_unified *wmi_handle;
1280
1281 wmi_handle =
1282 (struct wmi_unified *)os_malloc(NULL,
1283 sizeof(struct wmi_unified),
1284 GFP_ATOMIC);
1285 if (wmi_handle == NULL) {
1286 cdf_print("allocation of wmi handle failed %zu \n",
1287 sizeof(struct wmi_unified));
1288 return NULL;
1289 }
1290 OS_MEMZERO(wmi_handle, sizeof(struct wmi_unified));
1291 wmi_handle->scn_handle = scn_handle;
1292 cdf_atomic_init(&wmi_handle->pending_cmds);
1293 cdf_atomic_init(&wmi_handle->is_target_suspended);
1294 wmi_runtime_pm_init(wmi_handle);
1295 cdf_spinlock_init(&wmi_handle->eventq_lock);
1296 cdf_nbuf_queue_init(&wmi_handle->event_queue);
1297#ifdef CONFIG_CNSS
1298 cnss_init_work(&wmi_handle->rx_event_work, wmi_rx_event_work);
1299#else
1300 INIT_WORK(&wmi_handle->rx_event_work, wmi_rx_event_work);
1301#endif
1302#ifdef WMI_INTERFACE_EVENT_LOGGING
1303 cdf_spinlock_init(&wmi_handle->wmi_record_lock);
1304#endif
1305 wmi_handle->wma_process_fw_event_handler_cbk = func;
1306
1307 return wmi_handle;
1308}
1309
1310/**
1311 * wmi_unified_detach() - detach for unified WMI
1312 *
1313 * @wmi_handle : handle to wmi.
1314 *
1315 * @Return: none.
1316 */
1317void wmi_unified_detach(struct wmi_unified *wmi_handle)
1318{
1319 wmi_buf_t buf;
1320
1321 cds_flush_work(&wmi_handle->rx_event_work);
1322 cdf_spin_lock_bh(&wmi_handle->eventq_lock);
1323 buf = cdf_nbuf_queue_remove(&wmi_handle->event_queue);
1324 while (buf) {
1325 cdf_nbuf_free(buf);
1326 buf = cdf_nbuf_queue_remove(&wmi_handle->event_queue);
1327 }
1328 cdf_spin_unlock_bh(&wmi_handle->eventq_lock);
1329 if (wmi_handle != NULL) {
1330 OS_FREE(wmi_handle);
1331 wmi_handle = NULL;
1332 }
1333}
1334
1335/**
1336 * wmi_unified_remove_work() - detach for WMI work
1337 * @wmi_handle: handle to WMI
1338 *
1339 * A function that does not fully detach WMI, but just remove work
1340 * queue items associated with it. This is used to make sure that
1341 * before any other processing code that may destroy related contexts
1342 * (HTC, etc), work queue processing on WMI has already been stopped.
1343 *
1344 * Return: None
1345 */
1346void
1347wmi_unified_remove_work(struct wmi_unified *wmi_handle)
1348{
1349 wmi_buf_t buf;
1350
1351 CDF_TRACE(CDF_MODULE_ID_WMI, CDF_TRACE_LEVEL_INFO,
1352 "Enter: %s", __func__);
1353 cds_flush_work(&wmi_handle->rx_event_work);
1354 cdf_spin_lock_bh(&wmi_handle->eventq_lock);
1355 buf = cdf_nbuf_queue_remove(&wmi_handle->event_queue);
1356 while (buf) {
1357 cdf_nbuf_free(buf);
1358 buf = cdf_nbuf_queue_remove(&wmi_handle->event_queue);
1359 }
1360 cdf_spin_unlock_bh(&wmi_handle->eventq_lock);
1361 CDF_TRACE(CDF_MODULE_ID_WMA, CDF_TRACE_LEVEL_INFO,
1362 "Done: %s", __func__);
1363}
1364
1365void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
1366{
1367 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
1368 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
1369#ifdef WMI_INTERFACE_EVENT_LOGGING
1370 uint32_t cmd_id;
1371#endif
1372
1373 ASSERT(wmi_cmd_buf);
1374#ifdef WMI_INTERFACE_EVENT_LOGGING
1375 cmd_id = WMI_GET_FIELD(cdf_nbuf_data(wmi_cmd_buf),
1376 WMI_CMD_HDR, COMMANDID);
1377
1378#ifdef QCA_WIFI_3_0_EMU
1379 cdf_print
1380 ("\nSent WMI command:%s command_id:0x%x over dma and recieved tx complete interupt\n",
1381 get_wmi_cmd_string(cmd_id), cmd_id);
1382#endif
1383
1384 cdf_spin_lock_bh(&wmi_handle->wmi_record_lock);
1385 /* Record 16 bytes of WMI cmd tx complete data
1386 - exclude TLV and WMI headers */
1387 if (cmd_id == WMI_MGMT_TX_SEND_CMDID) {
1388 WMI_MGMT_COMMAND_TX_CMP_RECORD(cmd_id,
1389 ((uint32_t *) cdf_nbuf_data(wmi_cmd_buf) + 2));
1390 } else {
1391 WMI_COMMAND_TX_CMP_RECORD(cmd_id,
1392 ((uint32_t *) cdf_nbuf_data(wmi_cmd_buf) + 2));
1393 }
1394
1395 cdf_spin_unlock_bh(&wmi_handle->wmi_record_lock);
1396#endif
1397 cdf_nbuf_free(wmi_cmd_buf);
1398 cdf_mem_free(htc_pkt);
1399 cdf_atomic_dec(&wmi_handle->pending_cmds);
1400}
1401
1402/**
1403 * wmi_get_host_credits() - WMI API to get updated host_credits
1404 *
1405 * @wmi_handle: handle to WMI.
1406 *
1407 * @Return: updated host_credits.
1408 */
1409int
1410wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
1411 void *htc_handle)
1412{
1413
1414 int status;
1415 HTC_SERVICE_CONNECT_RESP response;
1416 HTC_SERVICE_CONNECT_REQ connect;
1417
1418 OS_MEMZERO(&connect, sizeof(connect));
1419 OS_MEMZERO(&response, sizeof(response));
1420
1421 /* meta data is unused for now */
1422 connect.pMetaData = NULL;
1423 connect.MetaDataLength = 0;
1424 /* these fields are the same for all service endpoints */
1425 connect.EpCallbacks.pContext = wmi_handle;
1426 connect.EpCallbacks.EpTxCompleteMultiple =
1427 NULL /* Control path completion ar6000_tx_complete */;
1428 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
1429 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
1430 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
1431 connect.EpCallbacks.EpTxComplete =
1432 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
1433
1434 /* connect to control service */
1435 connect.service_id = WMI_CONTROL_SVC;
1436 status = htc_connect_service(htc_handle, &connect,
1437 &response);
1438
1439 if (status != EOK) {
1440 cdf_print
1441 ("Failed to connect to WMI CONTROL service status:%d \n",
1442 status);
1443 return status;
1444 }
1445 wmi_handle->wmi_endpoint_id = response.Endpoint;
1446 wmi_handle->htc_handle = htc_handle;
1447 wmi_handle->max_msg_len = response.MaxMsgLength;
1448
1449 return EOK;
1450}
1451
1452/**
1453 * wmi_get_host_credits() - WMI API to get updated host_credits
1454 *
1455 * @wmi_handle: handle to WMI.
1456 *
1457 * @Return: updated host_credits.
1458 */
1459int wmi_get_host_credits(wmi_unified_t wmi_handle)
1460{
1461 int host_credits;
1462
1463 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
1464 &host_credits);
1465 return host_credits;
1466}
1467
1468/**
1469 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC queue
1470 *
1471 * @wmi_handle: handle to WMI.
1472 *
1473 * @Return: Pending Commands in the HTC queue.
1474 */
1475int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
1476{
1477 return cdf_atomic_read(&wmi_handle->pending_cmds);
1478}
1479
1480/**
1481 * wmi_set_target_suspend() - WMI API to set target suspend state
1482 *
1483 * @wmi_handle: handle to WMI.
1484 * @val: suspend state boolean.
1485 *
1486 * @Return: none.
1487 */
1488void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
1489{
1490 cdf_atomic_set(&wmi_handle->is_target_suspended, val);
1491}
1492
1493#ifdef FEATURE_RUNTIME_PM
1494void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
1495{
1496 cdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
1497}
1498
1499inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
1500{
1501 return cdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
1502}
1503#endif