blob: b03dadec4b91ba6aaec45de3d1a12c8272b9234f [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"
Govind Singh6b411b52016-03-06 19:55:02 +053037#include "htc_api.h"
38#include "htc_api.h"
39#include "dbglog_host.h"
Govind Singh6b411b52016-03-06 19:55:02 +053040#include "wmi_unified_priv.h"
Govind Singh5eb51532016-03-09 11:34:12 +053041#include "wmi_unified_param.h"
Govind Singh6b411b52016-03-06 19:55:02 +053042
Govind Singhecf03cd2016-05-12 12:45:51 +053043#include <linux/debugfs.h>
44
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053045/* This check for CONFIG_WIN temporary added due to redeclaration compilation
46error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
47which gets included here through ol_if_athvar.h. Eventually it is expected that
48wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
49WMI_CMD_HDR to be defined here. */
50#ifdef CONFIG_WIN
51/* Copied from wmi.h */
52#undef MS
53#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
54#undef SM
55#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
56#undef WO
57#define WO(_f) ((_f##_OFFSET) >> 2)
58
59#undef GET_FIELD
60#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
61#undef SET_FIELD
62#define SET_FIELD(_addr, _f, _val) \
63 (*((A_UINT32 *)(_addr) + WO(_f)) = \
64 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
65
66#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
67 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
68
69#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
70 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
71
72#define WMI_EP_APASS 0x0
73#define WMI_EP_LPASS 0x1
74#define WMI_EP_SENSOR 0x2
75
76/*
77 * * Control Path
78 * */
79typedef PREPACK struct {
80 A_UINT32 commandId:24,
81 reserved:2, /* used for WMI endpoint ID */
82 plt_priv:6; /* platform private */
83} POSTPACK WMI_CMD_HDR; /* used for commands and events */
84
85#define WMI_CMD_HDR_COMMANDID_LSB 0
86#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
87#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
88#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
89#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
90#define WMI_CMD_HDR_PLT_PRIV_LSB 24
91#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
92#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
93/* end of copy wmi.h */
94#endif /* CONFIG_WIN */
95
Manikandan Mohan5826ae92016-06-08 16:29:39 -070096#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
97/* TODO Cleanup this backported function */
98int qcacld_bp_seq_printf(struct seq_file *m, const char *f, ...)
99{
100 va_list args;
101
102 va_start(args, f);
103 seq_printf(m, f, args);
104 va_end(args);
105
106 return m->count;
107}
108
109#define seq_printf(m, fmt, ...) qcacld_bp_seq_printf((m), fmt, ##__VA_ARGS__)
110#endif
111
Govind Singh6b411b52016-03-06 19:55:02 +0530112#define WMI_MIN_HEAD_ROOM 64
113
114#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +0530115#ifndef MAX_WMI_INSTANCES
116#ifdef CONFIG_MCL
117#define MAX_WMI_INSTANCES 1
118#else
119#define MAX_WMI_INSTANCES 3
120#endif
121#endif
122
Govind Singh6b411b52016-03-06 19:55:02 +0530123/* WMI commands */
124uint32_t g_wmi_command_buf_idx = 0;
125struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
126
127/* WMI commands TX completed */
128uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
129struct wmi_command_debug
130 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
131
132/* WMI events when processed */
133uint32_t g_wmi_event_buf_idx = 0;
134struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
135
136/* WMI events when queued */
137uint32_t g_wmi_rx_event_buf_idx = 0;
138struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
139
Govind Singhecf03cd2016-05-12 12:45:51 +0530140#define WMI_COMMAND_RECORD(h, a, b) { \
141 if (wmi_log_max_entry <= \
142 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
143 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
144 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
145 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
146 .command = a; \
147 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
148 wmi_command_log_buf_info.buf) \
149 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
150 b, wmi_record_max_length); \
151 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
152 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
153 time = qdf_get_log_timestamp(); \
154 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
155 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530156}
157
Govind Singhecf03cd2016-05-12 12:45:51 +0530158#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
159 if (wmi_log_max_entry <= \
160 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
161 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx) = 0;\
162 ((struct wmi_command_debug *)h->log_info. \
163 wmi_command_tx_cmp_log_buf_info.buf) \
164 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
165 p_buf_tail_idx)]. \
166 command = a; \
167 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
168 wmi_command_tx_cmp_log_buf_info.buf) \
169 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
170 p_buf_tail_idx)]. \
171 data, b, wmi_record_max_length); \
172 ((struct wmi_command_debug *)h->log_info. \
173 wmi_command_tx_cmp_log_buf_info.buf) \
174 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
175 p_buf_tail_idx)]. \
176 time = qdf_get_log_timestamp(); \
177 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
178 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530179}
180
Govind Singhecf03cd2016-05-12 12:45:51 +0530181#define WMI_EVENT_RECORD(h, a, b) { \
182 if (wmi_log_max_entry <= \
183 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
184 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
185 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
186 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
187 event = a; \
188 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
189 wmi_event_log_buf_info.buf) \
190 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
191 wmi_record_max_length); \
192 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
193 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530194 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530195 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
196 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530197}
198
Govind Singhecf03cd2016-05-12 12:45:51 +0530199#define WMI_RX_EVENT_RECORD(h, a, b) { \
200 if (wmi_log_max_entry <= \
201 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
202 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
203 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
204 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
205 event = a; \
206 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
207 wmi_rx_event_log_buf_info.buf) \
208 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
209 data, b, wmi_record_max_length); \
210 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
211 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
212 time = qdf_get_log_timestamp(); \
213 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
214 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530215}
Govind Singh6b411b52016-03-06 19:55:02 +0530216
217uint32_t g_wmi_mgmt_command_buf_idx = 0;
218struct
219wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
220
221/* wmi_mgmt commands TX completed */
222uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
223struct wmi_command_debug
224wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
225
226/* wmi_mgmt events when processed */
227uint32_t g_wmi_mgmt_event_buf_idx = 0;
228struct wmi_event_debug
229wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
230
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700231#define WMI_MGMT_COMMAND_RECORD(a, b, c, d, e) { \
232 if (WMI_MGMT_EVENT_DEBUG_MAX_ENTRY <= \
233 g_wmi_mgmt_command_buf_idx) \
234 g_wmi_mgmt_command_buf_idx = 0; \
235 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].command = a; \
236 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].data[0] = b; \
237 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].data[1] = c; \
238 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].data[2] = d; \
239 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].data[3] = e; \
240 wmi_mgmt_command_log_buffer[g_wmi_mgmt_command_buf_idx].time = \
241 qdf_get_log_timestamp(); \
242 g_wmi_mgmt_command_buf_idx++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530243}
244
Govind Singhecf03cd2016-05-12 12:45:51 +0530245#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
246 if (wmi_mgmt_log_max_entry <= \
247 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
248 p_buf_tail_idx)) \
249 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
250 p_buf_tail_idx) = 0; \
251 ((struct wmi_command_debug *)h->log_info. \
252 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
253 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
254 p_buf_tail_idx)].command = a; \
255 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
256 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
257 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
258 p_buf_tail_idx)].data, b, \
259 wmi_record_max_length); \
260 ((struct wmi_command_debug *)h->log_info. \
261 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
262 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
263 p_buf_tail_idx)].time = \
264 qdf_get_log_timestamp(); \
265 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
266 p_buf_tail_idx))++; \
267 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530268}
269
Govind Singhecf03cd2016-05-12 12:45:51 +0530270#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
271 if (wmi_mgmt_log_max_entry <= \
272 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
273 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
274 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
275 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
276 .event = a; \
277 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
278 wmi_mgmt_event_log_buf_info.buf) \
279 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
280 data, b, wmi_record_max_length); \
281 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
282 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
283 time = qdf_get_log_timestamp(); \
284 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
285 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530286}
287
Govind Singhecf03cd2016-05-12 12:45:51 +0530288/* These are defined to made it as module param, which can be configured */
289uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
290uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
291uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
292uint32_t wmi_display_size = 100;
293
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530294static uint8_t *wmi_id_to_name(uint32_t wmi_command);
Govind Singhecf03cd2016-05-12 12:45:51 +0530295
296/**
297 * wmi_log_init() - Initialize WMI event logging
298 * @wmi_handle: WMI handle.
299 *
300 * Return: Initialization status
301 */
302#ifdef CONFIG_MCL
303static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
304{
305 struct wmi_log_buf_t *cmd_log_buf =
306 &wmi_handle->log_info.wmi_command_log_buf_info;
307 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
308 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
309
310 struct wmi_log_buf_t *event_log_buf =
311 &wmi_handle->log_info.wmi_event_log_buf_info;
312 struct wmi_log_buf_t *rx_event_log_buf =
313 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
314
315 struct wmi_log_buf_t *mgmt_cmd_log_buf =
316 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
317 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
318 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
319 struct wmi_log_buf_t *mgmt_event_log_buf =
320 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
321
322 /* WMI commands */
323 cmd_log_buf->length = 0;
324 cmd_log_buf->buf_tail_idx = 0;
325 cmd_log_buf->buf = wmi_command_log_buffer;
326 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
327
328 /* WMI commands TX completed */
329 cmd_tx_cmpl_log_buf->length = 0;
330 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
331 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
332 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
333
334 /* WMI events when processed */
335 event_log_buf->length = 0;
336 event_log_buf->buf_tail_idx = 0;
337 event_log_buf->buf = wmi_event_log_buffer;
338 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
339
340 /* WMI events when queued */
341 rx_event_log_buf->length = 0;
342 rx_event_log_buf->buf_tail_idx = 0;
343 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
344 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
345
346 /* WMI Management commands */
347 mgmt_cmd_log_buf->length = 0;
348 mgmt_cmd_log_buf->buf_tail_idx = 0;
349 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
350 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
351
352 /* WMI Management commands Tx completed*/
353 mgmt_cmd_tx_cmp_log_buf->length = 0;
354 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
355 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
356 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
357 &g_wmi_mgmt_command_tx_cmp_buf_idx;
358
359 /* WMI Management events when processed*/
360 mgmt_event_log_buf->length = 0;
361 mgmt_event_log_buf->buf_tail_idx = 0;
362 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
363 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
364
365 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
366 wmi_handle->log_info.wmi_logging_enable = 1;
367
368 return QDF_STATUS_SUCCESS;
369}
370#else
371static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
372{
373 struct wmi_log_buf_t *cmd_log_buf =
374 &wmi_handle->log_info.wmi_command_log_buf_info;
375 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
376 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
377
378 struct wmi_log_buf_t *event_log_buf =
379 &wmi_handle->log_info.wmi_event_log_buf_info;
380 struct wmi_log_buf_t *rx_event_log_buf =
381 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
382
383 struct wmi_log_buf_t *mgmt_cmd_log_buf =
384 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
385 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
386 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
387 struct wmi_log_buf_t *mgmt_event_log_buf =
388 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
389
390 wmi_handle->log_info.wmi_logging_enable = 0;
391
392 /* WMI commands */
393 cmd_log_buf->length = 0;
394 cmd_log_buf->buf_tail_idx = 0;
395 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
396 wmi_log_max_entry * sizeof(struct wmi_command_debug));
397
398 if (!cmd_log_buf->buf) {
399 qdf_print("no memory for WMI command log buffer..\n");
400 return QDF_STATUS_E_NOMEM;
401 }
402 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
403
404 /* WMI commands TX completed */
405 cmd_tx_cmpl_log_buf->length = 0;
406 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
407 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
408 wmi_log_max_entry * sizeof(struct wmi_command_debug));
409
410 if (!cmd_tx_cmpl_log_buf->buf) {
411 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
412 return QDF_STATUS_E_NOMEM;
413 }
414 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
415 &cmd_tx_cmpl_log_buf->buf_tail_idx;
416
417 /* WMI events when processed */
418 event_log_buf->length = 0;
419 event_log_buf->buf_tail_idx = 0;
420 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
421 wmi_log_max_entry * sizeof(struct wmi_event_debug));
422
423 if (!event_log_buf->buf) {
424 qdf_print("no memory for WMI Event log buffer..\n");
425 return QDF_STATUS_E_NOMEM;
426 }
427 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
428
429 /* WMI events when queued */
430 rx_event_log_buf->length = 0;
431 rx_event_log_buf->buf_tail_idx = 0;
432 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
433 wmi_log_max_entry * sizeof(struct wmi_event_debug));
434
435 if (!rx_event_log_buf->buf) {
436 qdf_print("no memory for WMI Event Rx log buffer..\n");
437 return QDF_STATUS_E_NOMEM;
438 }
439 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
440
441 /* WMI Management commands */
442 mgmt_cmd_log_buf->length = 0;
443 mgmt_cmd_log_buf->buf_tail_idx = 0;
444 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
445 wmi_mgmt_log_max_entry *
446 sizeof(struct wmi_command_debug));
447
448 if (!mgmt_cmd_log_buf->buf) {
449 qdf_print("no memory for WMI Management Command log buffer..\n");
450 return QDF_STATUS_E_NOMEM;
451 }
452 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
453
454 /* WMI Management commands Tx completed*/
455 mgmt_cmd_tx_cmp_log_buf->length = 0;
456 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
457 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
458 qdf_mem_malloc(
459 wmi_mgmt_log_max_entry *
460 sizeof(struct wmi_command_debug));
461
462 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
463 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
464 return QDF_STATUS_E_NOMEM;
465 }
466 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
467 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
468
469 /* WMI Management events when processed*/
470 mgmt_event_log_buf->length = 0;
471 mgmt_event_log_buf->buf_tail_idx = 0;
472
473 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
474 wmi_mgmt_log_max_entry *
475 sizeof(struct wmi_event_debug));
476
477 if (!mgmt_event_log_buf->buf) {
478 qdf_print("no memory for WMI Management Event log buffer..\n");
479 return QDF_STATUS_E_NOMEM;
480 }
481 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
482
483 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
484 wmi_handle->log_info.wmi_logging_enable = 1;
485
486 return QDF_STATUS_SUCCESS;
487}
488#endif
489
490/**
491 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
492 * event logging
493 * @wmi_handle: WMI handle.
494 *
495 * Return: None
496 */
497#ifndef CONFIG_MCL
498static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
499{
500 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
501 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
502 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
503 qdf_mem_free(
504 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
505 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
506 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
507 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
508 qdf_mem_free(
509 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
510 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
511 qdf_mem_free(
512 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
513 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
514 qdf_mem_free(
515 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
516 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
517 qdf_mem_free(
518 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
519 wmi_handle->log_info.wmi_logging_enable = 0;
520 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
521}
522#else
523static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
524{
525 /* Do Nothing */
526}
527#endif
528
529#ifdef CONFIG_MCL
530const int8_t * const debugfs_dir[] = {"WMI0", "WMI1", "WMI2"};
531#else
532const int8_t * const debugfs_dir[] = {"WMI0"};
533#endif
534
535/* debugfs routines*/
536
537/**
538 * debug_wmi_##func_base##_show() - debugfs functions to display content of
539 * command and event buffers. Macro uses max buffer length to display
540 * buffer when it is wraparound.
541 *
542 * @m: debugfs handler to access wmi_handle
543 * @v: Variable arguments (not used)
544 *
545 * Return: Length of characters printed
546 */
547#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
548 static int debug_wmi_##func_base##_show(struct seq_file *m, \
549 void *v) \
550 { \
551 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
552 struct wmi_log_buf_t *wmi_log = \
553 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
554 int pos, nread, outlen; \
555 int i; \
556 \
557 if (!wmi_log->length) \
558 return seq_printf(m, \
559 "no elements to read from ring buffer!\n"); \
560 \
561 if (wmi_log->length <= wmi_ring_size) \
562 nread = wmi_log->length; \
563 else \
564 nread = wmi_ring_size; \
565 \
566 if (*(wmi_log->p_buf_tail_idx) == 0) \
567 /* tail can be 0 after wrap-around */ \
568 pos = wmi_ring_size - 1; \
569 else \
570 pos = *(wmi_log->p_buf_tail_idx) - 1; \
571 \
572 outlen = 0; \
573 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
574 while (nread--) { \
575 struct wmi_command_debug *wmi_record; \
576 \
577 wmi_record = (struct wmi_command_debug *) \
578 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
579 outlen += seq_printf(m, "CMD ID = %x\n", \
580 (wmi_record->command)); \
581 outlen += seq_printf(m, "CMD = "); \
582 for (i = 0; i < (wmi_record_max_length/ \
583 sizeof(uint32_t)); i++) \
584 outlen += seq_printf(m, "%x ", \
585 wmi_record->data[i]); \
586 outlen += seq_printf(m, "\n"); \
587 \
588 if (pos == 0) \
589 pos = wmi_ring_size - 1; \
590 else \
591 pos--; \
592 } \
593 outlen += seq_printf(m, "Length = %d\n", wmi_log->length);\
594 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
595 \
596 return outlen; \
597 } \
598
599#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
600 static int debug_wmi_##func_base##_show(struct seq_file *m, \
601 void *v) \
602 { \
603 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
604 struct wmi_log_buf_t *wmi_log = \
605 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
606 int pos, nread, outlen; \
607 int i; \
608 \
609 if (!wmi_log->length) \
610 return seq_printf(m, \
611 "no elements to read from ring buffer!\n"); \
612 \
613 if (wmi_log->length <= wmi_ring_size) \
614 nread = wmi_log->length; \
615 else \
616 nread = wmi_ring_size; \
617 \
618 if (*(wmi_log->p_buf_tail_idx) == 0) \
619 /* tail can be 0 after wrap-around */ \
620 pos = wmi_ring_size - 1; \
621 else \
622 pos = *(wmi_log->p_buf_tail_idx) - 1; \
623 \
624 outlen = 0; \
625 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
626 while (nread--) { \
627 struct wmi_event_debug *wmi_record; \
628 \
629 wmi_record = (struct wmi_event_debug *) \
630 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
631 outlen += seq_printf(m, "Event ID = %x\n", \
632 (wmi_record->event)); \
633 outlen += seq_printf(m, "CMD = "); \
634 for (i = 0; i < (wmi_record_max_length/ \
635 sizeof(uint32_t)); i++) \
636 outlen += seq_printf(m, "%x ", \
637 wmi_record->data[i]); \
638 outlen += seq_printf(m, "\n"); \
639 \
640 if (pos == 0) \
641 pos = wmi_ring_size - 1; \
642 else \
643 pos--; \
644 } \
645 outlen += seq_printf(m, "Length = %d\n", wmi_log->length);\
646 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
647 \
648 return outlen; \
649 }
650
651GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
652GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
653GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
654GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
655GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
656GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
657 wmi_display_size);
658GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
659
660/**
661 * debug_wmi_enable_show() - debugfs functions to display enable state of
662 * wmi logging feature.
663 *
664 * @m: debugfs handler to access wmi_handle
665 * @v: Variable arguments (not used)
666 *
667 * Return: always 1
668 */
669static int debug_wmi_enable_show(struct seq_file *m, void *v)
670{
671 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
672
673 return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
674
675}
676
677/**
678 * debug_wmi_log_size_show() - debugfs functions to display configured size of
679 * wmi logging command/event buffer and management command/event buffer.
680 *
681 * @m: debugfs handler to access wmi_handle
682 * @v: Variable arguments (not used)
683 *
684 * Return: Length of characters printed
685 */
686static int debug_wmi_log_size_show(struct seq_file *m, void *v)
687{
688
689 seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
690 return seq_printf(m, "WMI management command/events log max size:%d\n",
691 wmi_mgmt_log_max_entry);
692}
693
694/**
695 * debug_wmi_##func_base##_write() - debugfs functions to clear
696 * wmi logging command/event buffer and management command/event buffer.
697 *
698 * @file: file handler to access wmi_handle
699 * @buf: received data buffer
700 * @count: length of received buffer
701 * @ppos: Not used
702 *
703 * Return: count
704 */
705#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
706 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
707 const char __user *buf, \
708 size_t count, loff_t *ppos) \
709 { \
710 int k, ret; \
711 wmi_unified_t wmi_handle = file->private_data; \
712 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
713 wmi_##func_base##_buf_info; \
714 \
715 ret = sscanf(buf, "%d", &k); \
716 if ((ret != 1) || (k != 0)) { \
717 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
718 return -EINVAL; \
719 } \
720 \
721 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
722 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
723 sizeof(struct wmi_record_type)); \
724 wmi_log->length = 0; \
725 *(wmi_log->p_buf_tail_idx) = 0; \
726 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
727 \
728 return count; \
729 }
730
731GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
732 wmi_command_debug);
733GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
734 wmi_command_debug);
735GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
736 wmi_event_debug);
737GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
738 wmi_event_debug);
739GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
740 wmi_command_debug);
741GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
742 wmi_mgmt_log_max_entry, wmi_command_debug);
743GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
744 wmi_event_debug);
745
746/**
747 * debug_wmi_enable_write() - debugfs functions to enable/disable
748 * wmi logging feature.
749 *
750 * @file: file handler to access wmi_handle
751 * @buf: received data buffer
752 * @count: length of received buffer
753 * @ppos: Not used
754 *
755 * Return: count
756 */
757static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
758 size_t count, loff_t *ppos)
759{
760 wmi_unified_t wmi_handle = file->private_data;
761 int k, ret;
762
763 ret = sscanf(buf, "%d", &k);
764 if ((ret != 1) || ((k != 0) && (k != 1)))
765 return -EINVAL;
766
767 wmi_handle->log_info.wmi_logging_enable = k;
768 return count;
769}
770
771/**
772 * debug_wmi_log_size_write() - reserved.
773 *
774 * @file: file handler to access wmi_handle
775 * @buf: received data buffer
776 * @count: length of received buffer
777 * @ppos: Not used
778 *
779 * Return: count
780 */
781static ssize_t debug_wmi_log_size_write(struct file *file,
782 const char __user *buf, size_t count, loff_t *ppos)
783{
784 return -EINVAL;
785}
786
787/* Structure to maintain debug information */
788struct wmi_debugfs_info {
789 const char *name;
790 struct dentry *de[MAX_WMI_INSTANCES];
791 const struct file_operations *ops;
792};
793
794#define DEBUG_FOO(func_base) { .name = #func_base, \
795 .ops = &debug_##func_base##_ops }
796
797/**
798 * debug_##func_base##_open() - Open debugfs entry for respective command
799 * and event buffer.
800 *
801 * @inode: node for debug dir entry
802 * @file: file handler
803 *
804 * Return: open status
805 */
806#define GENERATE_DEBUG_STRUCTS(func_base) \
807 static int debug_##func_base##_open(struct inode *inode, \
808 struct file *file) \
809 { \
810 return single_open(file, debug_##func_base##_show, \
811 inode->i_private); \
812 } \
813 \
814 \
815 static struct file_operations debug_##func_base##_ops = { \
816 .open = debug_##func_base##_open, \
817 .read = seq_read, \
818 .llseek = seq_lseek, \
819 .write = debug_##func_base##_write, \
820 .release = single_release, \
821 };
822
823GENERATE_DEBUG_STRUCTS(wmi_command_log);
824GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
825GENERATE_DEBUG_STRUCTS(wmi_event_log);
826GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
827GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
828GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
829GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
830GENERATE_DEBUG_STRUCTS(wmi_enable);
831GENERATE_DEBUG_STRUCTS(wmi_log_size);
832
833struct wmi_debugfs_info wmi_debugfs_infos[] = {
834 DEBUG_FOO(wmi_command_log),
835 DEBUG_FOO(wmi_command_tx_cmp_log),
836 DEBUG_FOO(wmi_event_log),
837 DEBUG_FOO(wmi_rx_event_log),
838 DEBUG_FOO(wmi_mgmt_command_log),
839 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
840 DEBUG_FOO(wmi_mgmt_event_log),
841 DEBUG_FOO(wmi_enable),
842 DEBUG_FOO(wmi_log_size),
843};
844
845#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
846 sizeof(wmi_debugfs_infos[0]))
847
848/**
849 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
850 *
851 * @wmi_handle: wmi handle
852 * @par_entry: debug directory entry
853 * @id: Index to debug info data array
854 *
855 * Return: none
856 */
857static void wmi_debugfs_create(wmi_unified_t wmi_handle,
858 struct dentry *par_entry, int id)
859{
860 int i;
861
862 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
863 goto out;
864
865 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
866
867 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
868 wmi_debugfs_infos[i].name, 0644, par_entry,
869 wmi_handle, wmi_debugfs_infos[i].ops);
870
871 if (wmi_debugfs_infos[i].de[id] == NULL) {
872 qdf_print("%s: debug Entry creation failed!\n",
873 __func__);
874 goto out;
875 }
876 }
877
878 return;
879
880out:
881 qdf_print("%s: debug Entry creation failed!\n", __func__);
882 wmi_log_buffer_free(wmi_handle);
883 return;
884}
885
886/**
887 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +0530888 * @wmi_handle: wmi handle
889 * @dentry: debugfs directory entry
890 * @id: Index to debug info data array
891 *
892 * Return: none
893 */
Govind Singh06c18392016-06-10 10:33:19 +0530894static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +0530895{
896 int i;
Govind Singh06c18392016-06-10 10:33:19 +0530897 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
898 int id = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +0530899
900 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
901 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
902 if (wmi_debugfs_infos[i].de[id])
903 wmi_debugfs_infos[i].de[id] = NULL;
904 }
905 }
906
907 if (dentry)
908 debugfs_remove_recursive(dentry);
909}
910
911/**
912 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
913 * create debugfs enteries.
914 *
915 * @h: wmi handler
916 *
917 * Return: init status
918 */
919static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
920{
921 static int wmi_index;
922
923 if (wmi_index < MAX_WMI_INSTANCES)
924 wmi_handle->log_info.wmi_log_debugfs_dir =
925 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
926
927 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
928 qdf_print("error while creating debugfs dir for %s\n",
929 debugfs_dir[wmi_index]);
930 return QDF_STATUS_E_FAILURE;
931 }
932
933 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
934 wmi_index);
935 wmi_handle->log_info.wmi_instance_id = wmi_index++;
936
937 return QDF_STATUS_SUCCESS;
938}
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700939
940/**
941 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
942 *
943 * @wmi_handle: wmi handle
944 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700945 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700946 * @vdev_id: vdev id
947 * @chanfreq: channel frequency
948 *
949 * Return: none
950 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530951void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700952 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700953{
954 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
955
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700956 WMI_MGMT_COMMAND_RECORD(cmd,
957 ((struct wmi_command_header *)header)->type,
958 ((struct wmi_command_header *)header)->sub_type,
959 vdev_id, chanfreq);
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700960
961 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
962}
Rajeev Kumarae91c402016-05-25 16:07:23 -0700963#else
964/**
965 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
966 * @wmi_handle: wmi handle
967 * @dentry: debugfs directory entry
968 * @id: Index to debug info data array
969 *
970 * Return: none
971 */
Govind Singh06c18392016-06-10 10:33:19 +0530972static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530973void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700974 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Govind Singh6b411b52016-03-06 19:55:02 +0530975#endif /*WMI_INTERFACE_EVENT_LOGGING */
976
Govind Singh6b411b52016-03-06 19:55:02 +0530977int wmi_get_host_credits(wmi_unified_t wmi_handle);
978/* WMI buffer APIs */
979
980#ifdef MEMORY_DEBUG
981wmi_buf_t
982wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +0530983 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +0530984{
985 wmi_buf_t wmi_buf;
986
987 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +0530988 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +0530989 return NULL;
990 }
991
Govind Singhb53420c2016-03-09 14:32:57 +0530992 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +0530993 roundup(len + WMI_MIN_HEAD_ROOM, 4),
994 WMI_MIN_HEAD_ROOM, 4, false, file_name,
995 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +0530996
997 if (!wmi_buf)
998 return NULL;
999
1000 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301001 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301002
1003 /*
1004 * Set the length of the buffer to match the allocation size.
1005 */
Govind Singhb53420c2016-03-09 14:32:57 +05301006 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301007
1008 return wmi_buf;
1009}
1010
1011void wmi_buf_free(wmi_buf_t net_buf)
1012{
Govind Singhb53420c2016-03-09 14:32:57 +05301013 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301014}
1015#else
1016wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1017{
1018 wmi_buf_t wmi_buf;
1019
1020 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301021 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301022 return NULL;
1023 }
1024
Govind Singhb53420c2016-03-09 14:32:57 +05301025 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301026 WMI_MIN_HEAD_ROOM, 4, false);
1027 if (!wmi_buf)
1028 return NULL;
1029
1030 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301031 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301032
1033 /*
1034 * Set the length of the buffer to match the allocation size.
1035 */
Govind Singhb53420c2016-03-09 14:32:57 +05301036 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301037 return wmi_buf;
1038}
1039
1040void wmi_buf_free(wmi_buf_t net_buf)
1041{
Govind Singhb53420c2016-03-09 14:32:57 +05301042 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301043}
1044#endif
1045
1046/**
1047 * wmi_get_max_msg_len() - get maximum WMI message length
1048 * @wmi_handle: WMI handle.
1049 *
1050 * This function returns the maximum WMI message length
1051 *
1052 * Return: maximum WMI message length
1053 */
1054uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1055{
1056 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1057}
1058
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301059#ifndef WMI_NON_TLV_SUPPORT
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301060static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +05301061{
1062 switch (wmi_command) {
1063 /* initialize the wlan sub system */
1064 CASE_RETURN_STRING(WMI_INIT_CMDID);
1065
1066 /* Scan specific commands */
1067
1068 /* start scan request to FW */
1069 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1070 /* stop scan request to FW */
1071 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1072 /* full list of channels as defined by the regulatory
1073 * that will be used by scanner */
1074 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1075 /* overwrite default priority table in scan scheduler */
1076 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1077 /* This command to adjust the priority and min.max_rest_time
1078 * of an on ongoing scan request.
1079 */
1080 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1081
1082 /* PDEV(physical device) specific commands */
1083 /* set regulatorty ctl id used by FW to determine the exact
1084 * ctl power limits */
1085 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1086 /* set channel. mainly used for supporting monitor mode */
1087 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1088 /* set pdev specific parameters */
1089 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1090 /* enable packet log */
1091 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1092 /* disable packet log*/
1093 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1094 /* set wmm parameters */
1095 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1096 /* set HT cap ie that needs to be carried probe requests
1097 * HT/VHT channels */
1098 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1099 /* set VHT cap ie that needs to be carried on probe
1100 * requests on VHT channels */
1101 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1102
1103 /* Command to send the DSCP-to-TID map to the target */
1104 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1105 /* set quiet ie parameters. primarily used in AP mode */
1106 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1107 /* Enable/Disable Green AP Power Save */
1108 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1109 /* get TPC config for the current operating channel */
1110 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1111
1112 /* set the base MAC address for the physical device before
1113 * a VDEV is created. For firmware that does not support
1114 * this feature and this command, the pdev MAC address will
1115 * not be changed. */
1116 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1117
1118 /* eeprom content dump , the same to bdboard data */
1119 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1120
1121 /* VDEV(virtual device) specific commands */
1122 /* vdev create */
1123 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1124 /* vdev delete */
1125 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1126 /* vdev start request */
1127 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1128 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1129 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1130 /* vdev up request */
1131 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1132 /* vdev stop request */
1133 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1134 /* vdev down request */
1135 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1136 /* set a vdev param */
1137 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1138 /* set a key (used for setting per peer unicast
1139 * and per vdev multicast) */
1140 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1141
1142 /* wnm sleep mode command */
1143 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1144 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1145 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1146 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1147 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1148 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1149
1150 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1151 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1152 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1153 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1154
1155 /* peer specific commands */
1156
1157 /** create a peer */
1158 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1159 /** delete a peer */
1160 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1161 /** flush specific tid queues of a peer */
1162 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1163 /** set a parameter of a peer */
1164 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1165 /* set peer to associated state. will cary all parameters
1166 * determined during assocication time */
1167 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1168 /* add a wds (4 address ) entry. used only for testing
1169 * WDS feature on AP products */
1170 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1171 /* remove wds (4 address ) entry. used only for testing WDS
1172 * feature on AP products */
1173 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1174 /* set up mcast info for multicast to unicast conversion */
1175 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1176 /* request peer info from FW to get PEER_INFO_EVENTID */
1177 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1178
1179 /* beacon/management specific commands */
1180
1181 /* transmit beacon by reference. used for transmitting beacon
1182 * on low latency interface like pcie */
1183 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1184 /* transmit beacon by value */
1185 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1186 /* set the beacon template. used in beacon offload mode to setup
1187 * the common beacon template with the FW to be used by FW to
1188 * generate beacons */
1189 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1190 /* set beacon filter with FW */
1191 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1192 /* enable/disable filtering of probe requests in the firmware */
1193 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1194 /* transmit management frame by value. will be deprecated */
1195 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1196 /* set the probe response template. used in beacon offload mode
1197 * to setup the common probe response template with the FW to
1198 * be used by FW to generate probe responses */
1199 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1200
1201 /* commands to directly control ba negotiation directly from
1202 * host. only used in test mode */
1203
1204 /* turn off FW Auto addba mode and let host control addba */
1205 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1206 /* send add ba request */
1207 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1208 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1209 /* send del ba */
1210 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1211 /* set add ba response will be used by FW to generate
1212 * addba response*/
1213 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1214 /* send single VHT MPDU with AMSDU */
1215 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1216
1217 /* Station power save specific config */
1218 /* enable/disable station powersave */
1219 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1220 /* set station power save specific parameter */
1221 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1222 /* set station mimo powersave mode */
1223 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1224
1225 /* DFS-specific commands */
1226 /* enable DFS (radar detection)*/
1227 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1228 /* disable DFS (radar detection)*/
1229 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1230 /* enable DFS phyerr/parse filter offload */
1231 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1232 /* enable DFS phyerr/parse filter offload */
1233 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1234
1235 /* Roaming specific commands */
1236 /* set roam scan mode */
1237 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1238 /* set roam scan rssi threshold below which roam
1239 * scan is enabled */
1240 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1241 /* set roam scan period for periodic roam scan mode */
1242 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1243 /* set roam scan trigger rssi change threshold */
1244 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1245 /* set roam AP profile */
1246 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1247 /* set channel list for roam scans */
1248 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1249 /* offload scan specific commands */
1250 /* set offload scan AP profile */
1251 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1252 /* remove offload scan AP profile */
1253 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1254 /* set offload scan period */
1255 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1256
1257 /* P2P specific commands */
1258 /* set P2P device info. FW will used by FW to create P2P IE
1259 * to be carried in probe response generated during p2p listen
1260 * and for p2p discoverability */
1261 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1262 /* enable/disable p2p discoverability on STA/AP VDEVs */
1263 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1264 /* set p2p ie to be carried in beacons generated by FW for GO */
1265 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1266 /* set p2p ie to be carried in probe response frames generated
1267 * by FW for GO */
1268 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1269 /* set the vendor specific p2p ie data.
1270 * FW will use this to parse the P2P NoA
1271 * attribute in the beacons/probe responses received.
1272 */
1273 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1274 /* set the configure of p2p find offload */
1275 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1276 /* set the vendor specific p2p ie data for p2p find offload */
1277 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1278 /* set the BSSID/device name pattern of p2p find offload */
1279 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1280 /* set OppPS related parameters **/
1281 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1282
1283 /* AP power save specific config
1284 * set AP power save specific param */
1285 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1286 /* set AP UAPSD coex pecific param */
1287 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1288
1289 /* Rate-control specific commands */
1290 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1291
1292 /* WLAN Profiling commands. */
1293 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1294 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1295 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1296 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1297 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1298
1299 /* Suspend resume command Ids */
1300 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1301 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1302
1303 /* Beacon filter commands */
1304 /* add a beacon filter */
1305 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1306 /* remove a beacon filter */
1307 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1308
1309 /* WOW Specific WMI commands */
1310 /* add pattern for awake */
1311 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1312 /* deleta a wake pattern */
1313 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1314 /* enable/deisable wake event */
1315 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1316 /* enable WOW */
1317 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1318 /* host woke up from sleep event to FW. Generated in response
1319 * to WOW Hardware event */
1320 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1321
1322 /* RTT measurement related cmd */
1323 /* reques to make an RTT measurement */
1324 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1325 /* reques to report a tsf measurement */
1326 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1327
1328 /* spectral scan command */
1329 /* configure spectral scan */
1330 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1331 /* enable/disable spectral scan and trigger */
1332 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1333
1334 /* F/W stats */
1335 /* one time request for stats */
1336 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1337 /* Push MCC Adaptive Scheduler Stats to Firmware */
1338 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1339
1340 /* ARP OFFLOAD REQUEST*/
1341 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1342
1343 /* Proactive ARP Response Add Pattern Command*/
1344 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1345
1346 /* Proactive ARP Response Del Pattern Command*/
1347 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1348
1349 /* NS offload confid*/
1350 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1351
1352 /* GTK offload Specific WMI commands */
1353 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1354
1355 /* CSA offload Specific WMI commands */
1356 /* csa offload enable */
1357 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1358 /* chan switch command */
1359 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1360
1361 /* Chatter commands */
1362 /* Change chatter mode of operation */
1363 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1364 /* chatter add coalescing filter command */
1365 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1366 /* chatter delete coalescing filter command */
1367 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1368 /* chatter coalecing query command */
1369 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1370
1371 /* addba specific commands */
1372 /* start the aggregation on this TID */
1373 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1374 /* stop the aggregation on this TID */
1375 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1376
1377 /* set station mimo powersave method */
1378 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1379 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1380 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1381 /* Configure the Keep Alive Parameters */
1382 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1383
1384 /* Request ssn from target for a sta/tid pair */
1385 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1386 /* misc command group */
1387 /* echo command mainly used for testing */
1388 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1389
1390 /* !!IMPORTANT!!
1391 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1392 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1393 * as we MUST have a fixed value here to maintain compatibility between
1394 * UTF and the ART2 driver
1395 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301396 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301397 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1398
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301399 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301400 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1401 /* QVIT specific command id */
1402 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1403 /* Factory Testing Mode request command
1404 * used for integrated chipsets */
1405 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1406 /* set and get keepalive parameters command */
1407 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1408 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1409 /* For fw recovery test command */
1410 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1411 /* Set Mcast/Bdcast filter */
1412 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1413 /* set thermal management params */
1414 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1415 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1416 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1417 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301418 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301419 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301420 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301421 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301422 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1423 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1424 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1425 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1426 /* GPIO Configuration */
1427 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1428 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1429
1430 /* Txbf configuration command */
1431 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1432
1433 /* FWTEST Commands */
1434 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1435 /* set NoA descs */
1436 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1437
1438 /* TDLS Configuration */
1439 /* enable/disable TDLS */
1440 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1441 /* set tdls peer state */
1442 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1443
1444 /* Resmgr Configuration */
1445 /* Adaptive OCS is enabled by default in the FW.
1446 * This command is used to disable FW based adaptive OCS.
1447 */
1448 CASE_RETURN_STRING
1449 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1450 /* set the requested channel time quota for the home channels */
1451 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1452 /* set the requested latency for the home channels */
1453 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1454
1455 /* STA SMPS Configuration */
1456 /* force SMPS mode */
1457 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1458 /* set SMPS parameters */
1459 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1460
1461 /* Wlan HB commands */
1462 /* enalbe/disable wlan HB */
1463 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1464 /* set tcp parameters for wlan HB */
1465 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1466 /* set tcp pkt filter for wlan HB */
1467 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1468 /* set udp parameters for wlan HB */
1469 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1470 /* set udp pkt filter for wlan HB */
1471 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1472
1473 /* Wlan RMC commands*/
1474 /* enable/disable RMC */
1475 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1476 /* configure action frame period */
1477 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1478 /* For debug/future enhancement purposes only,
1479 * configures/finetunes RMC algorithms */
1480 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1481
1482 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301483 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301484 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1485 /* Plumb routing table for MHF offload */
1486 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1487
1488 /* location scan commands */
1489 /* start batch scan */
1490 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1491 /* stop batch scan */
1492 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1493 /* get batch scan result */
1494 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1495 /* OEM related cmd */
1496 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1497 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1498 /* NAN request cmd */
1499 CASE_RETURN_STRING(WMI_NAN_CMDID);
1500 /* Modem power state cmd */
1501 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1502 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1503 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1504 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1505 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1506 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1507 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1508 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1509 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301510 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301511 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1512 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1513 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1514 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1515 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1516 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1517 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1518 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1519 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1520 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1521 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1522 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1523 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1524 CASE_RETURN_STRING
1525 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1526 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1527 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1528 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1529 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1530 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1531 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1532 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1533 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1534 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1535 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1536 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1537 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1538 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1539 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1540 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1541 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1542 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1543 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1544 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1545 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1546 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1547 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1548 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1549 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1550 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1551 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1552 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1553 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1554 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1555 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1556 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1557 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1558 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1559 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1560 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1561 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1562 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1563 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1564 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1565 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1566 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1567 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1568 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1569 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1570 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1571 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1572 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1573 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1574 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1575 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1576 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1577 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1578 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1579 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1580 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1581 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1582 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1583 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1584 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1585 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301586 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1587 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1588 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1589 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1590 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1591 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1592 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1593 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1594 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1595 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1596 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1597 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1598 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1599 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1600 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1601 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1602 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1603 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1604 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1605 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1606 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1607 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1608 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1609 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1610 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1611 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1612 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1613 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1614 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1615 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1616 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1617 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1618 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001619 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301620 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301621 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301622 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301623 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Himanshu Agarwaldc8d1ae2016-05-13 21:04:17 +05301624 CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
Himanshu Agarwalfc302f92016-05-30 21:06:16 +05301625 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
1626 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
Pradeep Reddy POTTETI18f8fbb2016-06-13 17:59:38 +05301627 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1628 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
Pradeep Reddy POTTETI4b997fd2016-06-20 13:25:31 +05301629 CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
Pradeep Reddy POTTETI10ca69d2016-06-20 14:50:42 +05301630 CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
Nitesh Shah70e11042016-06-29 20:16:16 +05301631 CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
1632 CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
Nitesh Shahc0482652016-07-08 11:45:33 +05301633 CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
Nitesh Shah33b95402016-07-21 17:25:55 +05301634 CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
1635 CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
Anurag Chouhan40865b42016-08-01 14:01:54 +05301636 CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
Anurag Chouhan7f6f1d52016-08-04 18:46:29 +05301637 CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
Manjeet Singhc026bde2016-09-01 16:42:29 +05301638 CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
Manjeet Singhbea16712016-08-18 15:50:30 +05301639 CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
1640 CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301641 }
1642
1643 return "Invalid WMI cmd";
1644}
1645
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301646static inline void wma_log_cmd_id(uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301647{
Govind Singhb53420c2016-03-09 14:32:57 +05301648 WMI_LOGD("Send WMI command:%s command_id:%d",
Govind Singhecf03cd2016-05-12 12:45:51 +05301649 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301650}
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001651#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301652static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301653{
1654 return "Invalid WMI cmd";
1655}
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301656#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301657
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001658
Govind Singh6b411b52016-03-06 19:55:02 +05301659/**
Govind Singhd52faac2016-03-09 12:03:29 +05301660 * wmi_is_runtime_pm_cmd() - check if a cmd is from suspend resume sequence
Govind Singh6b411b52016-03-06 19:55:02 +05301661 * @cmd: command to check
1662 *
1663 * Return: true if the command is part of the suspend resume sequence.
1664 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301665#ifndef WMI_NON_TLV_SUPPORT
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301666static bool wmi_is_runtime_pm_cmd(uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301667{
1668 switch (cmd_id) {
1669 case WMI_WOW_ENABLE_CMDID:
1670 case WMI_PDEV_SUSPEND_CMDID:
1671 case WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID:
1672 case WMI_WOW_ADD_WAKE_PATTERN_CMDID:
1673 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1674 case WMI_PDEV_RESUME_CMDID:
1675 case WMI_WOW_DEL_WAKE_PATTERN_CMDID:
1676 case WMI_D0_WOW_ENABLE_DISABLE_CMDID:
1677 return true;
1678
1679 default:
1680 return false;
1681 }
1682}
1683
1684/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301685 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1686 * @cmd_id: command to check
1687 *
1688 * Return: true if the command is part of the resume sequence.
1689 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301690static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301691{
1692 switch (cmd_id) {
1693 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1694 case WMI_PDEV_RESUME_CMDID:
1695 return true;
1696
1697 default:
1698 return false;
1699 }
1700}
1701#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301702static bool wmi_is_runtime_pm_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301703{
1704 return false;
1705}
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301706static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301707{
1708 return false;
1709}
1710#endif
1711
1712/**
Govind Singh6b411b52016-03-06 19:55:02 +05301713 * wmi_unified_cmd_send() - WMI command API
1714 * @wmi_handle: handle to wmi
1715 * @buf: wmi buf
1716 * @len: wmi buffer length
1717 * @cmd_id: wmi command id
1718 *
1719 * Return: 0 on success
1720 */
Govind Singhc458f382016-02-04 18:42:30 +05301721int wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf, uint32_t len,
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301722 uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301723{
1724 HTC_PACKET *pkt;
1725 A_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301726 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301727
1728 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
1729 if (wmi_is_runtime_pm_cmd(cmd_id))
1730 htc_tag = HTC_TX_PACKET_TAG_AUTO_PM;
Govind Singhb53420c2016-03-09 14:32:57 +05301731 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301732 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301733 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301734 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301735 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301736 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301737 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301738 if (wmi_handle->wmi_stopinprogress) {
1739 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1740 "WMI stop in progress\n");
1741 return -EINVAL;
1742 }
Govind Singh6b411b52016-03-06 19:55:02 +05301743
1744 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301745#ifndef WMI_NON_TLV_SUPPORT
1746 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301747 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301748
1749 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301750 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301751 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301752 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301753 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301754 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301755 }
1756 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301757#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301758
Govind Singhb53420c2016-03-09 14:32:57 +05301759 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1760 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301761 "%s, Failed to send cmd %x, no memory",
1762 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301763 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301764 }
1765
Govind Singhb53420c2016-03-09 14:32:57 +05301766 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301767
Govind Singhb53420c2016-03-09 14:32:57 +05301768 qdf_atomic_inc(&wmi_handle->pending_cmds);
1769 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1770 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301771 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301772 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301773 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301774 qdf_atomic_dec(&wmi_handle->pending_cmds);
1775 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301776 "%s: MAX 1024 WMI Pending cmds reached.", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301777 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301778 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301779 }
1780
Govind Singhb53420c2016-03-09 14:32:57 +05301781 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301782 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301783 qdf_atomic_dec(&wmi_handle->pending_cmds);
1784 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301785 "%s, Failed to alloc htc packet %x, no memory",
1786 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301787 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301788 }
1789
1790 SET_HTC_PACKET_INFO_TX(pkt,
1791 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301792 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301793 wmi_handle->wmi_endpoint_id, htc_tag);
1794
1795 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301796#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301797 wma_log_cmd_id(cmd_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301798#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301799
1800#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301801 if (wmi_handle->log_info.wmi_logging_enable) {
1802 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001803 if (!wmi_handle->log_info.is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301804 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
1805 ((uint32_t *) qdf_nbuf_data(buf) +
1806 wmi_handle->log_info.buf_offset_command));
1807 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301808 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1809 }
Govind Singh6b411b52016-03-06 19:55:02 +05301810#endif
1811
1812 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1813
1814 if (A_OK != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301815 qdf_atomic_dec(&wmi_handle->pending_cmds);
1816 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301817 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Govind Singh6b411b52016-03-06 19:55:02 +05301818 }
1819 if (status)
Govind Singhb53420c2016-03-09 14:32:57 +05301820 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301821
Govind Singhb53420c2016-03-09 14:32:57 +05301822 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301823}
1824
1825/**
1826 * wmi_unified_get_event_handler_ix() - gives event handler's index
1827 * @wmi_handle: handle to wmi
1828 * @event_id: wmi event id
1829 *
1830 * Return: event handler's index
1831 */
1832int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301833 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301834{
1835 uint32_t idx = 0;
1836 int32_t invalid_idx = -1;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301837
Govind Singh6b411b52016-03-06 19:55:02 +05301838 for (idx = 0; (idx < wmi_handle->max_event_idx &&
1839 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1840 if (wmi_handle->event_id[idx] == event_id &&
1841 wmi_handle->event_handler[idx] != NULL) {
1842 return idx;
1843 }
1844 }
1845
1846 return invalid_idx;
1847}
1848
1849/**
1850 * wmi_unified_register_event_handler() - register wmi event handler
1851 * @wmi_handle: handle to wmi
1852 * @event_id: wmi event id
1853 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301854 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301855 *
1856 * Return: 0 on success
1857 */
1858int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301859 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301860 wmi_unified_event_handler handler_func,
1861 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301862{
1863 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301864 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301865
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301866#ifdef WMI_TLV_AND_NON_TLV_SUPPORT
1867 if (event_id >= wmi_events_max ||
1868 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1869 qdf_print("%s: Event id %d is unavailable\n",
1870 __func__, event_id);
1871 return QDF_STATUS_E_FAILURE;
1872 }
1873 evt_id = wmi_handle->wmi_events[event_id];
1874#else
1875 evt_id = event_id;
1876#endif
1877 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1878 qdf_print("%s : event handler already registered 0x%x\n",
1879 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301880 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301881 }
1882 if (wmi_handle->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301883 qdf_print("%s : no more event handlers 0x%x\n",
1884 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301885 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301886 }
1887 idx = wmi_handle->max_event_idx;
1888 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301889 wmi_handle->event_id[idx] = evt_id;
Govind Singh813fdac2016-03-12 09:26:52 +05301890 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301891 wmi_handle->ctx[idx] = rx_ctx;
Govind Singh813fdac2016-03-12 09:26:52 +05301892 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301893 wmi_handle->max_event_idx++;
1894
1895 return 0;
1896}
1897
1898/**
1899 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1900 * @wmi_handle: handle to wmi
1901 * @event_id: wmi event id
1902 *
1903 * Return: 0 on success
1904 */
1905int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301906 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301907{
1908 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301909 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301910
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301911#ifdef WMI_TLV_AND_NON_TLV_SUPPORT
1912 if (event_id >= wmi_events_max ||
1913 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1914 qdf_print("%s: Event id %d is unavailable\n",
1915 __func__, event_id);
1916 return QDF_STATUS_E_FAILURE;
1917 }
1918 evt_id = wmi_handle->wmi_events[event_id];
1919#else
1920 evt_id = event_id;
1921#endif
1922
1923 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301924 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301925 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1926 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301927 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301928 }
1929 wmi_handle->event_handler[idx] = NULL;
1930 wmi_handle->event_id[idx] = 0;
1931 --wmi_handle->max_event_idx;
1932 wmi_handle->event_handler[idx] =
1933 wmi_handle->event_handler[wmi_handle->max_event_idx];
1934 wmi_handle->event_id[idx] =
1935 wmi_handle->event_id[wmi_handle->max_event_idx];
1936
1937 return 0;
1938}
1939
1940/**
Govind Singhd52faac2016-03-09 12:03:29 +05301941 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301942 * @wmi_handle: handle to wmi
1943 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301944 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301945 *
Govind Singhd52faac2016-03-09 12:03:29 +05301946 * Event process by below function will be in default caller context.
1947 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301948 *
1949 * Return: none
1950 */
Govind Singhd52faac2016-03-09 12:03:29 +05301951static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1952 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301953{
1954 wmi_buf_t evt_buf;
1955 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1956
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301957#ifdef WMI_NON_TLV_SUPPORT
1958 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1959 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1960#else
Govind Singh5eb51532016-03-09 11:34:12 +05301961 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301962 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301963#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301964
Govind Singh6b411b52016-03-06 19:55:02 +05301965 return;
1966}
1967
1968/**
1969 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1970 * @wmi_handle: handle to wmi
1971 * @htc_packet: pointer to htc packet
1972 *
1973 * Event process by below function will be in worker thread context.
1974 * Use this method for events which are not critical and not
1975 * handled in protocol stack.
1976 *
1977 * Return: none
1978 */
1979static void wmi_process_fw_event_worker_thread_ctx
1980 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1981{
1982 wmi_buf_t evt_buf;
1983 uint32_t id;
1984 uint8_t *data;
1985
1986 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05301987 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
1988 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301989
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301990#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301991 if (wmi_handle->log_info.wmi_logging_enable) {
1992 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1993 /* Exclude 4 bytes of TLV header */
1994 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
1995 wmi_handle->log_info.buf_offset_event));
1996 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1997 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301998#endif
Govind Singhb53420c2016-03-09 14:32:57 +05301999 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2000 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
2001 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302002 schedule_work(&wmi_handle->rx_event_work);
2003 return;
2004}
2005
2006/**
Govind Singhd52faac2016-03-09 12:03:29 +05302007 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302008 * @ctx: handle to wmi
2009 * @htc_packet: pointer to htc packet
2010 *
Govind Singh6b411b52016-03-06 19:55:02 +05302011 * Return: none
2012 */
2013void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
2014{
2015 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
2016 wmi_buf_t evt_buf;
2017 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302018 uint32_t idx = 0;
2019 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302020
2021 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302022 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302023 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302024 if (qdf_unlikely(idx == A_ERROR)) {
2025 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05302026 ("%s :event handler is not registered: event id 0x%x\n",
2027 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302028 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302029 return;
2030 }
Govind Singh813fdac2016-03-12 09:26:52 +05302031 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302032 exec_ctx = wmi_handle->ctx[idx];
Govind Singh813fdac2016-03-12 09:26:52 +05302033 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302034
2035 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302036 wmi_process_fw_event_worker_thread_ctx
2037 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302038 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2039 wmi_process_fw_event_default_ctx
2040 (wmi_handle, htc_packet, exec_ctx);
2041 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05302042 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
2043 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302044 }
Govind Singhd52faac2016-03-09 12:03:29 +05302045
Govind Singh6b411b52016-03-06 19:55:02 +05302046}
2047
2048/**
2049 * wmi_process_fw_event() - process any fw event
2050 * @wmi_handle: wmi handle
2051 * @evt_buf: fw event buffer
2052 *
Govind Singhd52faac2016-03-09 12:03:29 +05302053 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302054 *
2055 * Return: none
2056 */
2057void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2058{
2059 __wmi_control_rx(wmi_handle, evt_buf);
2060}
2061
2062/**
2063 * __wmi_control_rx() - process serialize wmi event callback
2064 * @wmi_handle: wmi handle
2065 * @evt_buf: fw event buffer
2066 *
2067 * Return: none
2068 */
2069void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2070{
2071 uint32_t id;
2072 uint8_t *data;
2073 uint32_t len;
2074 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302075#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302076 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302077#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302078 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302079
Govind Singhb53420c2016-03-09 14:32:57 +05302080 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302081
Govind Singhb53420c2016-03-09 14:32:57 +05302082 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302083 goto end;
2084
Govind Singhb53420c2016-03-09 14:32:57 +05302085 data = qdf_nbuf_data(evt_buf);
2086 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302087
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302088#ifndef WMI_NON_TLV_SUPPORT
2089 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2090 /* Validate and pad(if necessary) the TLVs */
2091 tlv_ok_status =
2092 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302093 data, len, id,
2094 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302095 if (tlv_ok_status != 0) {
2096 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2097 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2098 __func__, id, tlv_ok_status);
2099 goto end;
2100 }
Govind Singh6b411b52016-03-06 19:55:02 +05302101 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302102#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302103
Govind Singhd52faac2016-03-09 12:03:29 +05302104 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2105 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302106 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302107 "%s : event handler is not registered: event id 0x%x\n",
2108 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302109 goto end;
2110 }
Govind Singhd52faac2016-03-09 12:03:29 +05302111#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302112 if (wmi_handle->log_info.wmi_logging_enable) {
2113 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2114 /* Exclude 4 bytes of TLV header */
2115 if (wmi_handle->log_info.is_management_record(id)) {
2116 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2117 + wmi_handle->log_info.buf_offset_event));
2118 } else {
2119 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2120 wmi_handle->log_info.buf_offset_event));
2121 }
2122 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302123 }
Govind Singhd52faac2016-03-09 12:03:29 +05302124#endif
2125 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302126 if (wmi_handle->target_type == WMI_TLV_TARGET)
2127 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2128 wmi_cmd_struct_ptr, len);
2129 else
2130 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2131 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302132
Govind Singh6b411b52016-03-06 19:55:02 +05302133end:
Govind Singhd52faac2016-03-09 12:03:29 +05302134 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302135#ifndef WMI_NON_TLV_SUPPORT
2136 if (wmi_handle->target_type == WMI_TLV_TARGET)
2137 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2138#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302139 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302140
Govind Singh6b411b52016-03-06 19:55:02 +05302141}
2142
2143/**
2144 * wmi_rx_event_work() - process rx event in rx work queue context
2145 * @work: rx work queue struct
2146 *
2147 * This function process any fw event to serialize it through rx worker thread.
2148 *
2149 * Return: none
2150 */
2151void wmi_rx_event_work(struct work_struct *work)
2152{
2153 struct wmi_unified *wmi = container_of(work, struct wmi_unified,
Govind Singhecf03cd2016-05-12 12:45:51 +05302154 rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302155 wmi_buf_t buf;
2156
Govind Singhb53420c2016-03-09 14:32:57 +05302157 qdf_spin_lock_bh(&wmi->eventq_lock);
2158 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2159 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302160 while (buf) {
2161 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302162 qdf_spin_lock_bh(&wmi->eventq_lock);
2163 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2164 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302165 }
2166}
2167
Govind Singh6b411b52016-03-06 19:55:02 +05302168#ifdef FEATURE_RUNTIME_PM
2169/**
2170 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2171 * @wmi_handle: wmi context
2172 */
Govind Singhd52faac2016-03-09 12:03:29 +05302173static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302174{
Govind Singhb53420c2016-03-09 14:32:57 +05302175 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302176}
Govind Singhd52faac2016-03-09 12:03:29 +05302177
2178/**
2179 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2180 * @wmi_handle: wmi context
2181 * @val: runtime pm progress flag
2182 */
2183void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2184{
Govind Singhb53420c2016-03-09 14:32:57 +05302185 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302186}
2187
2188/**
2189 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2190 * @wmi_handle: wmi context
2191 */
2192inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2193{
Govind Singhb53420c2016-03-09 14:32:57 +05302194 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302195}
Govind Singh6b411b52016-03-06 19:55:02 +05302196#else
Govind Singhd52faac2016-03-09 12:03:29 +05302197static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302198{
2199}
2200#endif
2201
2202/**
2203 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302204 * @scn_handle: handle to SCN
2205 * @osdev: OS device context
2206 * @target_type: TLV or not-TLV based target
2207 * @use_cookie: cookie based allocation enabled/disabled
2208 * @ops: umac rx callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302209 *
2210 * @Return: wmi handle.
2211 */
Govind Singhc458f382016-02-04 18:42:30 +05302212void *wmi_unified_attach(void *scn_handle,
2213 osdev_t osdev, enum wmi_target_type target_type,
Govind Singh5eb51532016-03-09 11:34:12 +05302214 bool use_cookie, struct wmi_rx_ops *rx_ops)
Govind Singh6b411b52016-03-06 19:55:02 +05302215{
2216 struct wmi_unified *wmi_handle;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302217
2218#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302219 wmi_handle =
2220 (struct wmi_unified *)os_malloc(NULL,
2221 sizeof(struct wmi_unified),
2222 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302223#else
2224 wmi_handle =
2225 (struct wmi_unified *) qdf_mem_malloc(
2226 sizeof(struct wmi_unified));
2227#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302228 if (wmi_handle == NULL) {
Govind Singhb53420c2016-03-09 14:32:57 +05302229 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302230 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302231 return NULL;
2232 }
2233 OS_MEMZERO(wmi_handle, sizeof(struct wmi_unified));
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302234 wmi_handle->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302235 qdf_atomic_init(&wmi_handle->pending_cmds);
2236 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302237 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302238 qdf_spinlock_create(&wmi_handle->eventq_lock);
2239 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302240 INIT_WORK(&wmi_handle->rx_event_work, wmi_rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302241#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302242 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2243 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2244 wmi_debugfs_init(wmi_handle);
2245 }
Govind Singh6b411b52016-03-06 19:55:02 +05302246#endif
Govind Singhc458f382016-02-04 18:42:30 +05302247 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302248 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2249 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302250 wmi_handle->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302251 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302252 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302253 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302254 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302255 /* Assign target cookie capablity */
2256 wmi_handle->use_cookie = use_cookie;
2257 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302258 wmi_handle->wmi_stopinprogress = 0;
Govind Singh813fdac2016-03-12 09:26:52 +05302259 qdf_spinlock_create(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302260
2261 return wmi_handle;
2262}
2263
2264/**
2265 * wmi_unified_detach() - detach for unified WMI
2266 *
2267 * @wmi_handle : handle to wmi.
2268 *
2269 * @Return: none.
2270 */
2271void wmi_unified_detach(struct wmi_unified *wmi_handle)
2272{
2273 wmi_buf_t buf;
2274
Govind Singhb53420c2016-03-09 14:32:57 +05302275 cancel_work_sync(&wmi_handle->rx_event_work);
Rajeev Kumarae91c402016-05-25 16:07:23 -07002276
Govind Singh06c18392016-06-10 10:33:19 +05302277 wmi_debugfs_remove(wmi_handle);
Rajeev Kumarae91c402016-05-25 16:07:23 -07002278
Govind Singhb53420c2016-03-09 14:32:57 +05302279 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302280 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302281 qdf_nbuf_free(buf);
2282 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302283 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302284
2285#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302286 wmi_log_buffer_free(wmi_handle);
2287#endif
2288
Govind Singh20e7a062016-05-26 18:15:36 +05302289 qdf_spinlock_destroy(&wmi_handle->eventq_lock);
Govind Singh813fdac2016-03-12 09:26:52 +05302290 qdf_spinlock_destroy(&wmi_handle->ctx_lock);
Rajeev Kumarfec04012016-06-10 14:27:46 -07002291 OS_FREE(wmi_handle);
2292 wmi_handle = NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302293}
2294
2295/**
2296 * wmi_unified_remove_work() - detach for WMI work
2297 * @wmi_handle: handle to WMI
2298 *
2299 * A function that does not fully detach WMI, but just remove work
2300 * queue items associated with it. This is used to make sure that
2301 * before any other processing code that may destroy related contexts
2302 * (HTC, etc), work queue processing on WMI has already been stopped.
2303 *
2304 * Return: None
2305 */
2306void
2307wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2308{
2309 wmi_buf_t buf;
2310
Govind Singhb53420c2016-03-09 14:32:57 +05302311 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302312 "Enter: %s", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05302313 cancel_work_sync(&wmi_handle->rx_event_work);
2314 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2315 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302316 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302317 qdf_nbuf_free(buf);
2318 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302319 }
Govind Singhb53420c2016-03-09 14:32:57 +05302320 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2321 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302322 "Done: %s", __func__);
2323}
2324
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302325/**
2326 * wmi_htc_tx_complete() - Process htc tx completion
2327 *
2328 * @ctx: handle to wmi
2329 * @htc_packet: pointer to htc packet
2330 *
2331 * @Return: none.
2332 */
Govind Singh6b411b52016-03-06 19:55:02 +05302333void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
2334{
2335 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
2336 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302337
Govind Singh6b411b52016-03-06 19:55:02 +05302338#ifdef WMI_INTERFACE_EVENT_LOGGING
2339 uint32_t cmd_id;
2340#endif
2341
2342 ASSERT(wmi_cmd_buf);
2343#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302344 if (wmi_handle->log_info.wmi_logging_enable) {
2345 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2346 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302347
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07002348 WMI_LOGD("Sent WMI command:%s command_id:0x%x over dma and recieved tx complete interupt",
2349 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302350
Govind Singhecf03cd2016-05-12 12:45:51 +05302351 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302352 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302353 - exclude TLV and WMI headers */
2354 if (wmi_handle->log_info.is_management_record(cmd_id)) {
2355 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2356 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2357 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302358 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302359 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2360 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2361 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302362 }
2363
Govind Singhecf03cd2016-05-12 12:45:51 +05302364 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2365 }
Govind Singh6b411b52016-03-06 19:55:02 +05302366#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302367 qdf_nbuf_free(wmi_cmd_buf);
2368 qdf_mem_free(htc_pkt);
2369 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302370}
2371
2372/**
2373 * wmi_get_host_credits() - WMI API to get updated host_credits
2374 *
2375 * @wmi_handle: handle to WMI.
2376 *
2377 * @Return: updated host_credits.
2378 */
2379int
2380wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2381 void *htc_handle)
2382{
2383
2384 int status;
2385 HTC_SERVICE_CONNECT_RESP response;
2386 HTC_SERVICE_CONNECT_REQ connect;
2387
2388 OS_MEMZERO(&connect, sizeof(connect));
2389 OS_MEMZERO(&response, sizeof(response));
2390
2391 /* meta data is unused for now */
2392 connect.pMetaData = NULL;
2393 connect.MetaDataLength = 0;
2394 /* these fields are the same for all service endpoints */
2395 connect.EpCallbacks.pContext = wmi_handle;
2396 connect.EpCallbacks.EpTxCompleteMultiple =
2397 NULL /* Control path completion ar6000_tx_complete */;
2398 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2399 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2400 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2401 connect.EpCallbacks.EpTxComplete =
2402 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2403
2404 /* connect to control service */
2405 connect.service_id = WMI_CONTROL_SVC;
2406 status = htc_connect_service(htc_handle, &connect,
2407 &response);
2408
2409 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302410 qdf_print
Govind Singh6b411b52016-03-06 19:55:02 +05302411 ("Failed to connect to WMI CONTROL service status:%d \n",
2412 status);
2413 return status;
2414 }
2415 wmi_handle->wmi_endpoint_id = response.Endpoint;
2416 wmi_handle->htc_handle = htc_handle;
2417 wmi_handle->max_msg_len = response.MaxMsgLength;
2418
2419 return EOK;
2420}
2421
2422/**
2423 * wmi_get_host_credits() - WMI API to get updated host_credits
2424 *
2425 * @wmi_handle: handle to WMI.
2426 *
2427 * @Return: updated host_credits.
2428 */
2429int wmi_get_host_credits(wmi_unified_t wmi_handle)
2430{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302431 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302432
2433 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2434 &host_credits);
2435 return host_credits;
2436}
2437
2438/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302439 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2440 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302441 *
2442 * @wmi_handle: handle to WMI.
2443 *
2444 * @Return: Pending Commands in the HTC queue.
2445 */
2446int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2447{
Govind Singhb53420c2016-03-09 14:32:57 +05302448 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302449}
2450
2451/**
2452 * wmi_set_target_suspend() - WMI API to set target suspend state
2453 *
2454 * @wmi_handle: handle to WMI.
2455 * @val: suspend state boolean.
2456 *
2457 * @Return: none.
2458 */
2459void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2460{
Govind Singhb53420c2016-03-09 14:32:57 +05302461 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302462}
2463
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302464#ifdef WMI_NON_TLV_SUPPORT
2465/**
2466 * API to flush all the previous packets associated with the wmi endpoint
2467 *
2468 * @param wmi_handle : handle to WMI.
2469 */
2470void
2471wmi_flush_endpoint(wmi_unified_t wmi_handle)
2472{
2473 htc_flush_endpoint(wmi_handle->htc_handle,
2474 wmi_handle->wmi_endpoint_id, 0);
2475}
2476
2477/**
2478 * generic function to block unified WMI command
2479 * @param wmi_handle : handle to WMI.
2480 * @return 0 on success and -ve on failure.
2481 */
2482int
2483wmi_stop(wmi_unified_t wmi_handle)
2484{
2485 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2486 "WMI Stop\n");
2487 wmi_handle->wmi_stopinprogress = 1;
2488 return 0;
2489}
2490#endif