blob: 93f81ccf02fda06e6ecf412d1403d16dd1983ac2 [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"
40#include "wmi.h"
41#include "wmi_unified_priv.h"
Govind Singh5eb51532016-03-09 11:34:12 +053042#include "wmi_unified_param.h"
Govind Singh6b411b52016-03-06 19:55:02 +053043
Govind Singhecf03cd2016-05-12 12:45:51 +053044#include <linux/debugfs.h>
45
Manikandan Mohan5826ae92016-06-08 16:29:39 -070046#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
47/* TODO Cleanup this backported function */
48int qcacld_bp_seq_printf(struct seq_file *m, const char *f, ...)
49{
50 va_list args;
51
52 va_start(args, f);
53 seq_printf(m, f, args);
54 va_end(args);
55
56 return m->count;
57}
58
59#define seq_printf(m, fmt, ...) qcacld_bp_seq_printf((m), fmt, ##__VA_ARGS__)
60#endif
61
Govind Singh6b411b52016-03-06 19:55:02 +053062#define WMI_MIN_HEAD_ROOM 64
63
64#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +053065#ifndef MAX_WMI_INSTANCES
66#ifdef CONFIG_MCL
67#define MAX_WMI_INSTANCES 1
68#else
69#define MAX_WMI_INSTANCES 3
70#endif
71#endif
72
Govind Singh6b411b52016-03-06 19:55:02 +053073/* WMI commands */
74uint32_t g_wmi_command_buf_idx = 0;
75struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
76
77/* WMI commands TX completed */
78uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
79struct wmi_command_debug
80 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
81
82/* WMI events when processed */
83uint32_t g_wmi_event_buf_idx = 0;
84struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
85
86/* WMI events when queued */
87uint32_t g_wmi_rx_event_buf_idx = 0;
88struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
89
Govind Singhecf03cd2016-05-12 12:45:51 +053090#define WMI_COMMAND_RECORD(h, a, b) { \
91 if (wmi_log_max_entry <= \
92 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
93 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
94 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
95 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
96 .command = a; \
97 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
98 wmi_command_log_buf_info.buf) \
99 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
100 b, wmi_record_max_length); \
101 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
102 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
103 time = qdf_get_log_timestamp(); \
104 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
105 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530106}
107
Govind Singhecf03cd2016-05-12 12:45:51 +0530108#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
109 if (wmi_log_max_entry <= \
110 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
111 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx) = 0;\
112 ((struct wmi_command_debug *)h->log_info. \
113 wmi_command_tx_cmp_log_buf_info.buf) \
114 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
115 p_buf_tail_idx)]. \
116 command = a; \
117 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
118 wmi_command_tx_cmp_log_buf_info.buf) \
119 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
120 p_buf_tail_idx)]. \
121 data, b, wmi_record_max_length); \
122 ((struct wmi_command_debug *)h->log_info. \
123 wmi_command_tx_cmp_log_buf_info.buf) \
124 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
125 p_buf_tail_idx)]. \
126 time = qdf_get_log_timestamp(); \
127 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
128 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530129}
130
Govind Singhecf03cd2016-05-12 12:45:51 +0530131#define WMI_EVENT_RECORD(h, a, b) { \
132 if (wmi_log_max_entry <= \
133 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
134 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
135 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
136 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
137 event = a; \
138 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
139 wmi_event_log_buf_info.buf) \
140 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
141 wmi_record_max_length); \
142 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
143 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530144 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530145 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
146 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530147}
148
Govind Singhecf03cd2016-05-12 12:45:51 +0530149#define WMI_RX_EVENT_RECORD(h, a, b) { \
150 if (wmi_log_max_entry <= \
151 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
152 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
153 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
154 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
155 event = a; \
156 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
157 wmi_rx_event_log_buf_info.buf) \
158 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
159 data, b, wmi_record_max_length); \
160 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
161 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
162 time = qdf_get_log_timestamp(); \
163 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
164 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530165}
Govind Singh6b411b52016-03-06 19:55:02 +0530166
167uint32_t g_wmi_mgmt_command_buf_idx = 0;
168struct
169wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
170
171/* wmi_mgmt commands TX completed */
172uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
173struct wmi_command_debug
174wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
175
176/* wmi_mgmt events when processed */
177uint32_t g_wmi_mgmt_event_buf_idx = 0;
178struct wmi_event_debug
179wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
180
Govind Singhecf03cd2016-05-12 12:45:51 +0530181#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
182 if (wmi_mgmt_log_max_entry <= \
183 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
184 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx) = 0;\
185 ((struct wmi_command_debug *)h->log_info. \
186 wmi_mgmt_command_log_buf_info.buf) \
187 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
188 command = a; \
189 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
190 wmi_mgmt_command_log_buf_info.buf) \
191 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
192 data, b, \
193 wmi_record_max_length); \
194 ((struct wmi_command_debug *)h->log_info. \
195 wmi_mgmt_command_log_buf_info.buf) \
196 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
197 time = qdf_get_log_timestamp(); \
198 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
199 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530200}
201
Govind Singhecf03cd2016-05-12 12:45:51 +0530202#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
203 if (wmi_mgmt_log_max_entry <= \
204 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
205 p_buf_tail_idx)) \
206 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
207 p_buf_tail_idx) = 0; \
208 ((struct wmi_command_debug *)h->log_info. \
209 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
210 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
211 p_buf_tail_idx)].command = a; \
212 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
213 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
214 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
215 p_buf_tail_idx)].data, b, \
216 wmi_record_max_length); \
217 ((struct wmi_command_debug *)h->log_info. \
218 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
219 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
220 p_buf_tail_idx)].time = \
221 qdf_get_log_timestamp(); \
222 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
223 p_buf_tail_idx))++; \
224 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530225}
226
Govind Singhecf03cd2016-05-12 12:45:51 +0530227#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
228 if (wmi_mgmt_log_max_entry <= \
229 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
230 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
231 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
232 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
233 .event = a; \
234 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
235 wmi_mgmt_event_log_buf_info.buf) \
236 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
237 data, b, wmi_record_max_length); \
238 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
239 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
240 time = qdf_get_log_timestamp(); \
241 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
242 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530243}
244
Govind Singhecf03cd2016-05-12 12:45:51 +0530245/* These are defined to made it as module param, which can be configured */
246uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
247uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
248uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
249uint32_t wmi_display_size = 100;
250
251static uint8_t *wmi_id_to_name(WMI_CMD_ID wmi_command);
252
253/**
254 * wmi_log_init() - Initialize WMI event logging
255 * @wmi_handle: WMI handle.
256 *
257 * Return: Initialization status
258 */
259#ifdef CONFIG_MCL
260static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
261{
262 struct wmi_log_buf_t *cmd_log_buf =
263 &wmi_handle->log_info.wmi_command_log_buf_info;
264 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
265 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
266
267 struct wmi_log_buf_t *event_log_buf =
268 &wmi_handle->log_info.wmi_event_log_buf_info;
269 struct wmi_log_buf_t *rx_event_log_buf =
270 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
271
272 struct wmi_log_buf_t *mgmt_cmd_log_buf =
273 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
274 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
275 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
276 struct wmi_log_buf_t *mgmt_event_log_buf =
277 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
278
279 /* WMI commands */
280 cmd_log_buf->length = 0;
281 cmd_log_buf->buf_tail_idx = 0;
282 cmd_log_buf->buf = wmi_command_log_buffer;
283 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
284
285 /* WMI commands TX completed */
286 cmd_tx_cmpl_log_buf->length = 0;
287 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
288 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
289 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
290
291 /* WMI events when processed */
292 event_log_buf->length = 0;
293 event_log_buf->buf_tail_idx = 0;
294 event_log_buf->buf = wmi_event_log_buffer;
295 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
296
297 /* WMI events when queued */
298 rx_event_log_buf->length = 0;
299 rx_event_log_buf->buf_tail_idx = 0;
300 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
301 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
302
303 /* WMI Management commands */
304 mgmt_cmd_log_buf->length = 0;
305 mgmt_cmd_log_buf->buf_tail_idx = 0;
306 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
307 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
308
309 /* WMI Management commands Tx completed*/
310 mgmt_cmd_tx_cmp_log_buf->length = 0;
311 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
312 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
313 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
314 &g_wmi_mgmt_command_tx_cmp_buf_idx;
315
316 /* WMI Management events when processed*/
317 mgmt_event_log_buf->length = 0;
318 mgmt_event_log_buf->buf_tail_idx = 0;
319 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
320 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
321
322 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
323 wmi_handle->log_info.wmi_logging_enable = 1;
324
325 return QDF_STATUS_SUCCESS;
326}
327#else
328static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
329{
330 struct wmi_log_buf_t *cmd_log_buf =
331 &wmi_handle->log_info.wmi_command_log_buf_info;
332 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
333 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
334
335 struct wmi_log_buf_t *event_log_buf =
336 &wmi_handle->log_info.wmi_event_log_buf_info;
337 struct wmi_log_buf_t *rx_event_log_buf =
338 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
339
340 struct wmi_log_buf_t *mgmt_cmd_log_buf =
341 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
342 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
343 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
344 struct wmi_log_buf_t *mgmt_event_log_buf =
345 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
346
347 wmi_handle->log_info.wmi_logging_enable = 0;
348
349 /* WMI commands */
350 cmd_log_buf->length = 0;
351 cmd_log_buf->buf_tail_idx = 0;
352 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
353 wmi_log_max_entry * sizeof(struct wmi_command_debug));
354
355 if (!cmd_log_buf->buf) {
356 qdf_print("no memory for WMI command log buffer..\n");
357 return QDF_STATUS_E_NOMEM;
358 }
359 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
360
361 /* WMI commands TX completed */
362 cmd_tx_cmpl_log_buf->length = 0;
363 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
364 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
365 wmi_log_max_entry * sizeof(struct wmi_command_debug));
366
367 if (!cmd_tx_cmpl_log_buf->buf) {
368 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
369 return QDF_STATUS_E_NOMEM;
370 }
371 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
372 &cmd_tx_cmpl_log_buf->buf_tail_idx;
373
374 /* WMI events when processed */
375 event_log_buf->length = 0;
376 event_log_buf->buf_tail_idx = 0;
377 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
378 wmi_log_max_entry * sizeof(struct wmi_event_debug));
379
380 if (!event_log_buf->buf) {
381 qdf_print("no memory for WMI Event log buffer..\n");
382 return QDF_STATUS_E_NOMEM;
383 }
384 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
385
386 /* WMI events when queued */
387 rx_event_log_buf->length = 0;
388 rx_event_log_buf->buf_tail_idx = 0;
389 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
390 wmi_log_max_entry * sizeof(struct wmi_event_debug));
391
392 if (!rx_event_log_buf->buf) {
393 qdf_print("no memory for WMI Event Rx log buffer..\n");
394 return QDF_STATUS_E_NOMEM;
395 }
396 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
397
398 /* WMI Management commands */
399 mgmt_cmd_log_buf->length = 0;
400 mgmt_cmd_log_buf->buf_tail_idx = 0;
401 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
402 wmi_mgmt_log_max_entry *
403 sizeof(struct wmi_command_debug));
404
405 if (!mgmt_cmd_log_buf->buf) {
406 qdf_print("no memory for WMI Management Command log buffer..\n");
407 return QDF_STATUS_E_NOMEM;
408 }
409 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
410
411 /* WMI Management commands Tx completed*/
412 mgmt_cmd_tx_cmp_log_buf->length = 0;
413 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
414 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
415 qdf_mem_malloc(
416 wmi_mgmt_log_max_entry *
417 sizeof(struct wmi_command_debug));
418
419 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
420 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
421 return QDF_STATUS_E_NOMEM;
422 }
423 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
424 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
425
426 /* WMI Management events when processed*/
427 mgmt_event_log_buf->length = 0;
428 mgmt_event_log_buf->buf_tail_idx = 0;
429
430 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
431 wmi_mgmt_log_max_entry *
432 sizeof(struct wmi_event_debug));
433
434 if (!mgmt_event_log_buf->buf) {
435 qdf_print("no memory for WMI Management Event log buffer..\n");
436 return QDF_STATUS_E_NOMEM;
437 }
438 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
439
440 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
441 wmi_handle->log_info.wmi_logging_enable = 1;
442
443 return QDF_STATUS_SUCCESS;
444}
445#endif
446
447/**
448 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
449 * event logging
450 * @wmi_handle: WMI handle.
451 *
452 * Return: None
453 */
454#ifndef CONFIG_MCL
455static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
456{
457 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
458 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
459 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
460 qdf_mem_free(
461 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
462 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
463 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
464 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
465 qdf_mem_free(
466 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
467 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
468 qdf_mem_free(
469 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
470 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
471 qdf_mem_free(
472 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
473 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
474 qdf_mem_free(
475 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
476 wmi_handle->log_info.wmi_logging_enable = 0;
477 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
478}
479#else
480static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
481{
482 /* Do Nothing */
483}
484#endif
485
486#ifdef CONFIG_MCL
487const int8_t * const debugfs_dir[] = {"WMI0", "WMI1", "WMI2"};
488#else
489const int8_t * const debugfs_dir[] = {"WMI0"};
490#endif
491
492/* debugfs routines*/
493
494/**
495 * debug_wmi_##func_base##_show() - debugfs functions to display content of
496 * command and event buffers. Macro uses max buffer length to display
497 * buffer when it is wraparound.
498 *
499 * @m: debugfs handler to access wmi_handle
500 * @v: Variable arguments (not used)
501 *
502 * Return: Length of characters printed
503 */
504#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
505 static int debug_wmi_##func_base##_show(struct seq_file *m, \
506 void *v) \
507 { \
508 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
509 struct wmi_log_buf_t *wmi_log = \
510 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
511 int pos, nread, outlen; \
512 int i; \
513 \
514 if (!wmi_log->length) \
515 return seq_printf(m, \
516 "no elements to read from ring buffer!\n"); \
517 \
518 if (wmi_log->length <= wmi_ring_size) \
519 nread = wmi_log->length; \
520 else \
521 nread = wmi_ring_size; \
522 \
523 if (*(wmi_log->p_buf_tail_idx) == 0) \
524 /* tail can be 0 after wrap-around */ \
525 pos = wmi_ring_size - 1; \
526 else \
527 pos = *(wmi_log->p_buf_tail_idx) - 1; \
528 \
529 outlen = 0; \
530 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
531 while (nread--) { \
532 struct wmi_command_debug *wmi_record; \
533 \
534 wmi_record = (struct wmi_command_debug *) \
535 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
536 outlen += seq_printf(m, "CMD ID = %x\n", \
537 (wmi_record->command)); \
538 outlen += seq_printf(m, "CMD = "); \
539 for (i = 0; i < (wmi_record_max_length/ \
540 sizeof(uint32_t)); i++) \
541 outlen += seq_printf(m, "%x ", \
542 wmi_record->data[i]); \
543 outlen += seq_printf(m, "\n"); \
544 \
545 if (pos == 0) \
546 pos = wmi_ring_size - 1; \
547 else \
548 pos--; \
549 } \
550 outlen += seq_printf(m, "Length = %d\n", wmi_log->length);\
551 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
552 \
553 return outlen; \
554 } \
555
556#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
557 static int debug_wmi_##func_base##_show(struct seq_file *m, \
558 void *v) \
559 { \
560 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
561 struct wmi_log_buf_t *wmi_log = \
562 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
563 int pos, nread, outlen; \
564 int i; \
565 \
566 if (!wmi_log->length) \
567 return seq_printf(m, \
568 "no elements to read from ring buffer!\n"); \
569 \
570 if (wmi_log->length <= wmi_ring_size) \
571 nread = wmi_log->length; \
572 else \
573 nread = wmi_ring_size; \
574 \
575 if (*(wmi_log->p_buf_tail_idx) == 0) \
576 /* tail can be 0 after wrap-around */ \
577 pos = wmi_ring_size - 1; \
578 else \
579 pos = *(wmi_log->p_buf_tail_idx) - 1; \
580 \
581 outlen = 0; \
582 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
583 while (nread--) { \
584 struct wmi_event_debug *wmi_record; \
585 \
586 wmi_record = (struct wmi_event_debug *) \
587 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
588 outlen += seq_printf(m, "Event ID = %x\n", \
589 (wmi_record->event)); \
590 outlen += seq_printf(m, "CMD = "); \
591 for (i = 0; i < (wmi_record_max_length/ \
592 sizeof(uint32_t)); i++) \
593 outlen += seq_printf(m, "%x ", \
594 wmi_record->data[i]); \
595 outlen += seq_printf(m, "\n"); \
596 \
597 if (pos == 0) \
598 pos = wmi_ring_size - 1; \
599 else \
600 pos--; \
601 } \
602 outlen += seq_printf(m, "Length = %d\n", wmi_log->length);\
603 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
604 \
605 return outlen; \
606 }
607
608GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
609GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
610GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
611GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
612GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
613GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
614 wmi_display_size);
615GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
616
617/**
618 * debug_wmi_enable_show() - debugfs functions to display enable state of
619 * wmi logging feature.
620 *
621 * @m: debugfs handler to access wmi_handle
622 * @v: Variable arguments (not used)
623 *
624 * Return: always 1
625 */
626static int debug_wmi_enable_show(struct seq_file *m, void *v)
627{
628 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
629
630 return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
631
632}
633
634/**
635 * debug_wmi_log_size_show() - debugfs functions to display configured size of
636 * wmi logging command/event buffer and management command/event buffer.
637 *
638 * @m: debugfs handler to access wmi_handle
639 * @v: Variable arguments (not used)
640 *
641 * Return: Length of characters printed
642 */
643static int debug_wmi_log_size_show(struct seq_file *m, void *v)
644{
645
646 seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
647 return seq_printf(m, "WMI management command/events log max size:%d\n",
648 wmi_mgmt_log_max_entry);
649}
650
651/**
652 * debug_wmi_##func_base##_write() - debugfs functions to clear
653 * wmi logging command/event buffer and management command/event buffer.
654 *
655 * @file: file handler to access wmi_handle
656 * @buf: received data buffer
657 * @count: length of received buffer
658 * @ppos: Not used
659 *
660 * Return: count
661 */
662#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
663 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
664 const char __user *buf, \
665 size_t count, loff_t *ppos) \
666 { \
667 int k, ret; \
668 wmi_unified_t wmi_handle = file->private_data; \
669 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
670 wmi_##func_base##_buf_info; \
671 \
672 ret = sscanf(buf, "%d", &k); \
673 if ((ret != 1) || (k != 0)) { \
674 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
675 return -EINVAL; \
676 } \
677 \
678 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
679 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
680 sizeof(struct wmi_record_type)); \
681 wmi_log->length = 0; \
682 *(wmi_log->p_buf_tail_idx) = 0; \
683 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
684 \
685 return count; \
686 }
687
688GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
689 wmi_command_debug);
690GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
691 wmi_command_debug);
692GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
693 wmi_event_debug);
694GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
695 wmi_event_debug);
696GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
697 wmi_command_debug);
698GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
699 wmi_mgmt_log_max_entry, wmi_command_debug);
700GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
701 wmi_event_debug);
702
703/**
704 * debug_wmi_enable_write() - debugfs functions to enable/disable
705 * wmi logging feature.
706 *
707 * @file: file handler to access wmi_handle
708 * @buf: received data buffer
709 * @count: length of received buffer
710 * @ppos: Not used
711 *
712 * Return: count
713 */
714static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
715 size_t count, loff_t *ppos)
716{
717 wmi_unified_t wmi_handle = file->private_data;
718 int k, ret;
719
720 ret = sscanf(buf, "%d", &k);
721 if ((ret != 1) || ((k != 0) && (k != 1)))
722 return -EINVAL;
723
724 wmi_handle->log_info.wmi_logging_enable = k;
725 return count;
726}
727
728/**
729 * debug_wmi_log_size_write() - reserved.
730 *
731 * @file: file handler to access wmi_handle
732 * @buf: received data buffer
733 * @count: length of received buffer
734 * @ppos: Not used
735 *
736 * Return: count
737 */
738static ssize_t debug_wmi_log_size_write(struct file *file,
739 const char __user *buf, size_t count, loff_t *ppos)
740{
741 return -EINVAL;
742}
743
744/* Structure to maintain debug information */
745struct wmi_debugfs_info {
746 const char *name;
747 struct dentry *de[MAX_WMI_INSTANCES];
748 const struct file_operations *ops;
749};
750
751#define DEBUG_FOO(func_base) { .name = #func_base, \
752 .ops = &debug_##func_base##_ops }
753
754/**
755 * debug_##func_base##_open() - Open debugfs entry for respective command
756 * and event buffer.
757 *
758 * @inode: node for debug dir entry
759 * @file: file handler
760 *
761 * Return: open status
762 */
763#define GENERATE_DEBUG_STRUCTS(func_base) \
764 static int debug_##func_base##_open(struct inode *inode, \
765 struct file *file) \
766 { \
767 return single_open(file, debug_##func_base##_show, \
768 inode->i_private); \
769 } \
770 \
771 \
772 static struct file_operations debug_##func_base##_ops = { \
773 .open = debug_##func_base##_open, \
774 .read = seq_read, \
775 .llseek = seq_lseek, \
776 .write = debug_##func_base##_write, \
777 .release = single_release, \
778 };
779
780GENERATE_DEBUG_STRUCTS(wmi_command_log);
781GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
782GENERATE_DEBUG_STRUCTS(wmi_event_log);
783GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
784GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
785GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
786GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
787GENERATE_DEBUG_STRUCTS(wmi_enable);
788GENERATE_DEBUG_STRUCTS(wmi_log_size);
789
790struct wmi_debugfs_info wmi_debugfs_infos[] = {
791 DEBUG_FOO(wmi_command_log),
792 DEBUG_FOO(wmi_command_tx_cmp_log),
793 DEBUG_FOO(wmi_event_log),
794 DEBUG_FOO(wmi_rx_event_log),
795 DEBUG_FOO(wmi_mgmt_command_log),
796 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
797 DEBUG_FOO(wmi_mgmt_event_log),
798 DEBUG_FOO(wmi_enable),
799 DEBUG_FOO(wmi_log_size),
800};
801
802#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
803 sizeof(wmi_debugfs_infos[0]))
804
805/**
806 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
807 *
808 * @wmi_handle: wmi handle
809 * @par_entry: debug directory entry
810 * @id: Index to debug info data array
811 *
812 * Return: none
813 */
814static void wmi_debugfs_create(wmi_unified_t wmi_handle,
815 struct dentry *par_entry, int id)
816{
817 int i;
818
819 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
820 goto out;
821
822 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
823
824 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
825 wmi_debugfs_infos[i].name, 0644, par_entry,
826 wmi_handle, wmi_debugfs_infos[i].ops);
827
828 if (wmi_debugfs_infos[i].de[id] == NULL) {
829 qdf_print("%s: debug Entry creation failed!\n",
830 __func__);
831 goto out;
832 }
833 }
834
835 return;
836
837out:
838 qdf_print("%s: debug Entry creation failed!\n", __func__);
839 wmi_log_buffer_free(wmi_handle);
840 return;
841}
842
843/**
844 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +0530845 * @wmi_handle: wmi handle
846 * @dentry: debugfs directory entry
847 * @id: Index to debug info data array
848 *
849 * Return: none
850 */
851static void wmi_debugfs_remove(wmi_unified_t wmi_handle, struct dentry *dentry
852 , int id)
853{
854 int i;
855
856 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
857 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
858 if (wmi_debugfs_infos[i].de[id])
859 wmi_debugfs_infos[i].de[id] = NULL;
860 }
861 }
862
863 if (dentry)
864 debugfs_remove_recursive(dentry);
865}
866
867/**
868 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
869 * create debugfs enteries.
870 *
871 * @h: wmi handler
872 *
873 * Return: init status
874 */
875static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
876{
877 static int wmi_index;
878
879 if (wmi_index < MAX_WMI_INSTANCES)
880 wmi_handle->log_info.wmi_log_debugfs_dir =
881 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
882
883 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
884 qdf_print("error while creating debugfs dir for %s\n",
885 debugfs_dir[wmi_index]);
886 return QDF_STATUS_E_FAILURE;
887 }
888
889 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
890 wmi_index);
891 wmi_handle->log_info.wmi_instance_id = wmi_index++;
892
893 return QDF_STATUS_SUCCESS;
894}
Rajeev Kumarae91c402016-05-25 16:07:23 -0700895#else
896/**
897 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
898 * @wmi_handle: wmi handle
899 * @dentry: debugfs directory entry
900 * @id: Index to debug info data array
901 *
902 * Return: none
903 */
904static void wmi_debugfs_remove(wmi_unified_t wmi_handle, struct dentry *dentry
905 , int id) { }
Govind Singh6b411b52016-03-06 19:55:02 +0530906#endif /*WMI_INTERFACE_EVENT_LOGGING */
907
Govind Singh6b411b52016-03-06 19:55:02 +0530908int wmi_get_host_credits(wmi_unified_t wmi_handle);
909/* WMI buffer APIs */
910
911#ifdef MEMORY_DEBUG
912wmi_buf_t
913wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +0530914 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +0530915{
916 wmi_buf_t wmi_buf;
917
918 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +0530919 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +0530920 return NULL;
921 }
922
Govind Singhb53420c2016-03-09 14:32:57 +0530923 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +0530924 roundup(len + WMI_MIN_HEAD_ROOM, 4),
925 WMI_MIN_HEAD_ROOM, 4, false, file_name,
926 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +0530927
928 if (!wmi_buf)
929 return NULL;
930
931 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +0530932 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +0530933
934 /*
935 * Set the length of the buffer to match the allocation size.
936 */
Govind Singhb53420c2016-03-09 14:32:57 +0530937 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +0530938
939 return wmi_buf;
940}
941
942void wmi_buf_free(wmi_buf_t net_buf)
943{
Govind Singhb53420c2016-03-09 14:32:57 +0530944 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +0530945}
946#else
947wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
948{
949 wmi_buf_t wmi_buf;
950
951 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +0530952 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +0530953 return NULL;
954 }
955
Govind Singhb53420c2016-03-09 14:32:57 +0530956 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +0530957 WMI_MIN_HEAD_ROOM, 4, false);
958 if (!wmi_buf)
959 return NULL;
960
961 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +0530962 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +0530963
964 /*
965 * Set the length of the buffer to match the allocation size.
966 */
Govind Singhb53420c2016-03-09 14:32:57 +0530967 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +0530968 return wmi_buf;
969}
970
971void wmi_buf_free(wmi_buf_t net_buf)
972{
Govind Singhb53420c2016-03-09 14:32:57 +0530973 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +0530974}
975#endif
976
977/**
978 * wmi_get_max_msg_len() - get maximum WMI message length
979 * @wmi_handle: WMI handle.
980 *
981 * This function returns the maximum WMI message length
982 *
983 * Return: maximum WMI message length
984 */
985uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
986{
987 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
988}
989
Govind Singhe7d9f3e2016-04-15 13:58:27 +0530990#ifndef WMI_NON_TLV_SUPPORT
Govind Singhecf03cd2016-05-12 12:45:51 +0530991static uint8_t *wmi_id_to_name(WMI_CMD_ID wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +0530992{
993 switch (wmi_command) {
994 /* initialize the wlan sub system */
995 CASE_RETURN_STRING(WMI_INIT_CMDID);
996
997 /* Scan specific commands */
998
999 /* start scan request to FW */
1000 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1001 /* stop scan request to FW */
1002 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1003 /* full list of channels as defined by the regulatory
1004 * that will be used by scanner */
1005 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1006 /* overwrite default priority table in scan scheduler */
1007 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1008 /* This command to adjust the priority and min.max_rest_time
1009 * of an on ongoing scan request.
1010 */
1011 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1012
1013 /* PDEV(physical device) specific commands */
1014 /* set regulatorty ctl id used by FW to determine the exact
1015 * ctl power limits */
1016 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1017 /* set channel. mainly used for supporting monitor mode */
1018 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1019 /* set pdev specific parameters */
1020 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1021 /* enable packet log */
1022 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1023 /* disable packet log*/
1024 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1025 /* set wmm parameters */
1026 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1027 /* set HT cap ie that needs to be carried probe requests
1028 * HT/VHT channels */
1029 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1030 /* set VHT cap ie that needs to be carried on probe
1031 * requests on VHT channels */
1032 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1033
1034 /* Command to send the DSCP-to-TID map to the target */
1035 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1036 /* set quiet ie parameters. primarily used in AP mode */
1037 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1038 /* Enable/Disable Green AP Power Save */
1039 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1040 /* get TPC config for the current operating channel */
1041 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1042
1043 /* set the base MAC address for the physical device before
1044 * a VDEV is created. For firmware that does not support
1045 * this feature and this command, the pdev MAC address will
1046 * not be changed. */
1047 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1048
1049 /* eeprom content dump , the same to bdboard data */
1050 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1051
1052 /* VDEV(virtual device) specific commands */
1053 /* vdev create */
1054 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1055 /* vdev delete */
1056 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1057 /* vdev start request */
1058 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1059 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1060 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1061 /* vdev up request */
1062 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1063 /* vdev stop request */
1064 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1065 /* vdev down request */
1066 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1067 /* set a vdev param */
1068 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1069 /* set a key (used for setting per peer unicast
1070 * and per vdev multicast) */
1071 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1072
1073 /* wnm sleep mode command */
1074 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1075 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1076 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1077 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1078 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1079 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1080
1081 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1082 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1083 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1084 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1085
1086 /* peer specific commands */
1087
1088 /** create a peer */
1089 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1090 /** delete a peer */
1091 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1092 /** flush specific tid queues of a peer */
1093 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1094 /** set a parameter of a peer */
1095 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1096 /* set peer to associated state. will cary all parameters
1097 * determined during assocication time */
1098 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1099 /* add a wds (4 address ) entry. used only for testing
1100 * WDS feature on AP products */
1101 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1102 /* remove wds (4 address ) entry. used only for testing WDS
1103 * feature on AP products */
1104 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1105 /* set up mcast info for multicast to unicast conversion */
1106 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1107 /* request peer info from FW to get PEER_INFO_EVENTID */
1108 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1109
1110 /* beacon/management specific commands */
1111
1112 /* transmit beacon by reference. used for transmitting beacon
1113 * on low latency interface like pcie */
1114 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1115 /* transmit beacon by value */
1116 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1117 /* set the beacon template. used in beacon offload mode to setup
1118 * the common beacon template with the FW to be used by FW to
1119 * generate beacons */
1120 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1121 /* set beacon filter with FW */
1122 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1123 /* enable/disable filtering of probe requests in the firmware */
1124 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1125 /* transmit management frame by value. will be deprecated */
1126 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1127 /* set the probe response template. used in beacon offload mode
1128 * to setup the common probe response template with the FW to
1129 * be used by FW to generate probe responses */
1130 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1131
1132 /* commands to directly control ba negotiation directly from
1133 * host. only used in test mode */
1134
1135 /* turn off FW Auto addba mode and let host control addba */
1136 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1137 /* send add ba request */
1138 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1139 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1140 /* send del ba */
1141 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1142 /* set add ba response will be used by FW to generate
1143 * addba response*/
1144 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1145 /* send single VHT MPDU with AMSDU */
1146 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1147
1148 /* Station power save specific config */
1149 /* enable/disable station powersave */
1150 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1151 /* set station power save specific parameter */
1152 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1153 /* set station mimo powersave mode */
1154 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1155
1156 /* DFS-specific commands */
1157 /* enable DFS (radar detection)*/
1158 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1159 /* disable DFS (radar detection)*/
1160 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1161 /* enable DFS phyerr/parse filter offload */
1162 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1163 /* enable DFS phyerr/parse filter offload */
1164 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1165
1166 /* Roaming specific commands */
1167 /* set roam scan mode */
1168 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1169 /* set roam scan rssi threshold below which roam
1170 * scan is enabled */
1171 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1172 /* set roam scan period for periodic roam scan mode */
1173 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1174 /* set roam scan trigger rssi change threshold */
1175 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1176 /* set roam AP profile */
1177 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1178 /* set channel list for roam scans */
1179 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1180 /* offload scan specific commands */
1181 /* set offload scan AP profile */
1182 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1183 /* remove offload scan AP profile */
1184 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1185 /* set offload scan period */
1186 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1187
1188 /* P2P specific commands */
1189 /* set P2P device info. FW will used by FW to create P2P IE
1190 * to be carried in probe response generated during p2p listen
1191 * and for p2p discoverability */
1192 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1193 /* enable/disable p2p discoverability on STA/AP VDEVs */
1194 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1195 /* set p2p ie to be carried in beacons generated by FW for GO */
1196 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1197 /* set p2p ie to be carried in probe response frames generated
1198 * by FW for GO */
1199 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1200 /* set the vendor specific p2p ie data.
1201 * FW will use this to parse the P2P NoA
1202 * attribute in the beacons/probe responses received.
1203 */
1204 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1205 /* set the configure of p2p find offload */
1206 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1207 /* set the vendor specific p2p ie data for p2p find offload */
1208 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1209 /* set the BSSID/device name pattern of p2p find offload */
1210 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1211 /* set OppPS related parameters **/
1212 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1213
1214 /* AP power save specific config
1215 * set AP power save specific param */
1216 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1217 /* set AP UAPSD coex pecific param */
1218 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1219
1220 /* Rate-control specific commands */
1221 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1222
1223 /* WLAN Profiling commands. */
1224 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1225 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1226 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1227 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1228 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1229
1230 /* Suspend resume command Ids */
1231 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1232 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1233
1234 /* Beacon filter commands */
1235 /* add a beacon filter */
1236 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1237 /* remove a beacon filter */
1238 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1239
1240 /* WOW Specific WMI commands */
1241 /* add pattern for awake */
1242 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1243 /* deleta a wake pattern */
1244 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1245 /* enable/deisable wake event */
1246 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1247 /* enable WOW */
1248 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1249 /* host woke up from sleep event to FW. Generated in response
1250 * to WOW Hardware event */
1251 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1252
1253 /* RTT measurement related cmd */
1254 /* reques to make an RTT measurement */
1255 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1256 /* reques to report a tsf measurement */
1257 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1258
1259 /* spectral scan command */
1260 /* configure spectral scan */
1261 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1262 /* enable/disable spectral scan and trigger */
1263 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1264
1265 /* F/W stats */
1266 /* one time request for stats */
1267 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1268 /* Push MCC Adaptive Scheduler Stats to Firmware */
1269 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1270
1271 /* ARP OFFLOAD REQUEST*/
1272 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1273
1274 /* Proactive ARP Response Add Pattern Command*/
1275 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1276
1277 /* Proactive ARP Response Del Pattern Command*/
1278 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1279
1280 /* NS offload confid*/
1281 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1282
1283 /* GTK offload Specific WMI commands */
1284 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1285
1286 /* CSA offload Specific WMI commands */
1287 /* csa offload enable */
1288 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1289 /* chan switch command */
1290 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1291
1292 /* Chatter commands */
1293 /* Change chatter mode of operation */
1294 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1295 /* chatter add coalescing filter command */
1296 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1297 /* chatter delete coalescing filter command */
1298 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1299 /* chatter coalecing query command */
1300 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1301
1302 /* addba specific commands */
1303 /* start the aggregation on this TID */
1304 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1305 /* stop the aggregation on this TID */
1306 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1307
1308 /* set station mimo powersave method */
1309 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1310 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1311 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1312 /* Configure the Keep Alive Parameters */
1313 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1314
1315 /* Request ssn from target for a sta/tid pair */
1316 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1317 /* misc command group */
1318 /* echo command mainly used for testing */
1319 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1320
1321 /* !!IMPORTANT!!
1322 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1323 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1324 * as we MUST have a fixed value here to maintain compatibility between
1325 * UTF and the ART2 driver
1326 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301327 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301328 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1329
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301330 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301331 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1332 /* QVIT specific command id */
1333 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1334 /* Factory Testing Mode request command
1335 * used for integrated chipsets */
1336 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1337 /* set and get keepalive parameters command */
1338 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1339 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1340 /* For fw recovery test command */
1341 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1342 /* Set Mcast/Bdcast filter */
1343 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1344 /* set thermal management params */
1345 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1346 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1347 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1348 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301349 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301350 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301351 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301352 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301353 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1354 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1355 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1356 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1357 /* GPIO Configuration */
1358 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1359 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1360
1361 /* Txbf configuration command */
1362 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1363
1364 /* FWTEST Commands */
1365 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1366 /* set NoA descs */
1367 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1368
1369 /* TDLS Configuration */
1370 /* enable/disable TDLS */
1371 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1372 /* set tdls peer state */
1373 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1374
1375 /* Resmgr Configuration */
1376 /* Adaptive OCS is enabled by default in the FW.
1377 * This command is used to disable FW based adaptive OCS.
1378 */
1379 CASE_RETURN_STRING
1380 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1381 /* set the requested channel time quota for the home channels */
1382 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1383 /* set the requested latency for the home channels */
1384 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1385
1386 /* STA SMPS Configuration */
1387 /* force SMPS mode */
1388 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1389 /* set SMPS parameters */
1390 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1391
1392 /* Wlan HB commands */
1393 /* enalbe/disable wlan HB */
1394 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1395 /* set tcp parameters for wlan HB */
1396 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1397 /* set tcp pkt filter for wlan HB */
1398 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1399 /* set udp parameters for wlan HB */
1400 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1401 /* set udp pkt filter for wlan HB */
1402 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1403
1404 /* Wlan RMC commands*/
1405 /* enable/disable RMC */
1406 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1407 /* configure action frame period */
1408 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1409 /* For debug/future enhancement purposes only,
1410 * configures/finetunes RMC algorithms */
1411 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1412
1413 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301414 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301415 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1416 /* Plumb routing table for MHF offload */
1417 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1418
1419 /* location scan commands */
1420 /* start batch scan */
1421 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1422 /* stop batch scan */
1423 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1424 /* get batch scan result */
1425 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1426 /* OEM related cmd */
1427 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1428 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1429 /* NAN request cmd */
1430 CASE_RETURN_STRING(WMI_NAN_CMDID);
1431 /* Modem power state cmd */
1432 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1433 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1434 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1435 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1436 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1437 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1438 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1439 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1440 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301441 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301442 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1443 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1444 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1445 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1446 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1447 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1448 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1449 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1450 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1451 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1452 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1453 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1454 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1455 CASE_RETURN_STRING
1456 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1457 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1458 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1459 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1460 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1461 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1462 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1463 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1464 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1465 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1466 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1467 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1468 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1469 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1470 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1471 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1472 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1473 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1474 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1475 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1476 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1477 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1478 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1479 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1480 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1481 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1482 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1483 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1484 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1485 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1486 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1487 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1488 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1489 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1490 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1491 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1492 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1493 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1494 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1495 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1496 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1497 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1498 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1499 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1500 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1501 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1502 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1503 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1504 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1505 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1506 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1507 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1508 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1509 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1510 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1511 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1512 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1513 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1514 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1515 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1516 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301517 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1518 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1519 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1520 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1521 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1522 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1523 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1524 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1525 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1526 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1527 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1528 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1529 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1530 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1531 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1532 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1533 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1534 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1535 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1536 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1537 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1538 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1539 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1540 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1541 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1542 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1543 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1544 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1545 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1546 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1547 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1548 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1549 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001550 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301551 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301552 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301553 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301554 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301555 }
1556
1557 return "Invalid WMI cmd";
1558}
1559
1560#ifdef QCA_WIFI_3_0_EMU
1561static inline void wma_log_cmd_id(WMI_CMD_ID cmd_id)
1562{
Govind Singhb53420c2016-03-09 14:32:57 +05301563 WMI_LOGE("Send WMI command:%s command_id:%d",
Govind Singhecf03cd2016-05-12 12:45:51 +05301564 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301565}
1566#else
1567static inline void wma_log_cmd_id(WMI_CMD_ID cmd_id)
1568{
Govind Singhb53420c2016-03-09 14:32:57 +05301569 WMI_LOGD("Send WMI command:%s command_id:%d",
Govind Singhecf03cd2016-05-12 12:45:51 +05301570 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301571}
1572#endif
Govind Singhecf03cd2016-05-12 12:45:51 +05301573#else /* WMI_NON_TLV_SUPPORT */
1574static uint8_t *wmi_id_to_name(WMI_CMD_ID wmi_command)
1575{
1576 return "Invalid WMI cmd";
1577}
1578
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301579#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301580
1581/**
Govind Singhd52faac2016-03-09 12:03:29 +05301582 * wmi_is_runtime_pm_cmd() - check if a cmd is from suspend resume sequence
Govind Singh6b411b52016-03-06 19:55:02 +05301583 * @cmd: command to check
1584 *
1585 * Return: true if the command is part of the suspend resume sequence.
1586 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301587#ifndef WMI_NON_TLV_SUPPORT
Govind Singhd52faac2016-03-09 12:03:29 +05301588static bool wmi_is_runtime_pm_cmd(WMI_CMD_ID cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301589{
1590 switch (cmd_id) {
1591 case WMI_WOW_ENABLE_CMDID:
1592 case WMI_PDEV_SUSPEND_CMDID:
1593 case WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID:
1594 case WMI_WOW_ADD_WAKE_PATTERN_CMDID:
1595 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1596 case WMI_PDEV_RESUME_CMDID:
1597 case WMI_WOW_DEL_WAKE_PATTERN_CMDID:
1598 case WMI_D0_WOW_ENABLE_DISABLE_CMDID:
1599 return true;
1600
1601 default:
1602 return false;
1603 }
1604}
1605
1606/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301607 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1608 * @cmd_id: command to check
1609 *
1610 * Return: true if the command is part of the resume sequence.
1611 */
1612static bool wmi_is_pm_resume_cmd(WMI_CMD_ID cmd_id)
1613{
1614 switch (cmd_id) {
1615 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1616 case WMI_PDEV_RESUME_CMDID:
1617 return true;
1618
1619 default:
1620 return false;
1621 }
1622}
1623#else
1624static bool wmi_is_runtime_pm_cmd(WMI_CMD_ID cmd_id)
1625{
1626 return false;
1627}
1628static bool wmi_is_pm_resume_cmd(WMI_CMD_ID cmd_id)
1629{
1630 return false;
1631}
1632#endif
1633
1634/**
Govind Singh6b411b52016-03-06 19:55:02 +05301635 * wmi_unified_cmd_send() - WMI command API
1636 * @wmi_handle: handle to wmi
1637 * @buf: wmi buf
1638 * @len: wmi buffer length
1639 * @cmd_id: wmi command id
1640 *
1641 * Return: 0 on success
1642 */
Govind Singhc458f382016-02-04 18:42:30 +05301643int wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf, uint32_t len,
Govind Singh6b411b52016-03-06 19:55:02 +05301644 WMI_CMD_ID cmd_id)
1645{
1646 HTC_PACKET *pkt;
1647 A_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301648 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301649
1650 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
1651 if (wmi_is_runtime_pm_cmd(cmd_id))
1652 htc_tag = HTC_TX_PACKET_TAG_AUTO_PM;
Govind Singhb53420c2016-03-09 14:32:57 +05301653 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301654 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301655 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301656 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301657 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301658 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301659 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301660 if (wmi_handle->wmi_stopinprogress) {
1661 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1662 "WMI stop in progress\n");
1663 return -EINVAL;
1664 }
Govind Singh6b411b52016-03-06 19:55:02 +05301665
1666 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301667#ifndef WMI_NON_TLV_SUPPORT
1668 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301669 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301670
1671 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301672 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301673 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301674 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301675 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301676 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301677 }
1678 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301679#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301680
Govind Singhb53420c2016-03-09 14:32:57 +05301681 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1682 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301683 "%s, Failed to send cmd %x, no memory",
1684 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301685 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301686 }
1687
Govind Singhb53420c2016-03-09 14:32:57 +05301688 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301689
Govind Singhb53420c2016-03-09 14:32:57 +05301690 qdf_atomic_inc(&wmi_handle->pending_cmds);
1691 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1692 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301693 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301694 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301695 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301696 qdf_atomic_dec(&wmi_handle->pending_cmds);
1697 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301698 "%s: MAX 1024 WMI Pending cmds reached.", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301699 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301700 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301701 }
1702
Govind Singhb53420c2016-03-09 14:32:57 +05301703 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301704 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301705 qdf_atomic_dec(&wmi_handle->pending_cmds);
1706 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301707 "%s, Failed to alloc htc packet %x, no memory",
1708 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301709 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301710 }
1711
1712 SET_HTC_PACKET_INFO_TX(pkt,
1713 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301714 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301715 wmi_handle->wmi_endpoint_id, htc_tag);
1716
1717 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301718#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301719 wma_log_cmd_id(cmd_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301720#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301721
1722#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301723 if (wmi_handle->log_info.wmi_logging_enable) {
1724 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1725 /*Record 16 bytes of WMI cmd data -
1726 * exclude TLV and WMI headers */
1727 if (wmi_handle->log_info.is_management_record(cmd_id)) {
1728 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
1729 ((uint32_t *) qdf_nbuf_data(buf) +
1730 wmi_handle->log_info.buf_offset_command));
1731 } else {
1732 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
1733 ((uint32_t *) qdf_nbuf_data(buf) +
1734 wmi_handle->log_info.buf_offset_command));
1735 }
Govind Singh6b411b52016-03-06 19:55:02 +05301736
Govind Singhecf03cd2016-05-12 12:45:51 +05301737 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1738 }
Govind Singh6b411b52016-03-06 19:55:02 +05301739#endif
1740
1741 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1742
1743 if (A_OK != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301744 qdf_atomic_dec(&wmi_handle->pending_cmds);
1745 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301746 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Govind Singh6b411b52016-03-06 19:55:02 +05301747 }
1748 if (status)
Govind Singhb53420c2016-03-09 14:32:57 +05301749 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301750
Govind Singhb53420c2016-03-09 14:32:57 +05301751 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301752}
1753
1754/**
1755 * wmi_unified_get_event_handler_ix() - gives event handler's index
1756 * @wmi_handle: handle to wmi
1757 * @event_id: wmi event id
1758 *
1759 * Return: event handler's index
1760 */
1761int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301762 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301763{
1764 uint32_t idx = 0;
1765 int32_t invalid_idx = -1;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301766
Govind Singh6b411b52016-03-06 19:55:02 +05301767 for (idx = 0; (idx < wmi_handle->max_event_idx &&
1768 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1769 if (wmi_handle->event_id[idx] == event_id &&
1770 wmi_handle->event_handler[idx] != NULL) {
1771 return idx;
1772 }
1773 }
1774
1775 return invalid_idx;
1776}
1777
1778/**
1779 * wmi_unified_register_event_handler() - register wmi event handler
1780 * @wmi_handle: handle to wmi
1781 * @event_id: wmi event id
1782 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301783 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301784 *
1785 * Return: 0 on success
1786 */
1787int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301788 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301789 wmi_unified_event_handler handler_func,
1790 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301791{
1792 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301793 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301794
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301795#ifdef WMI_TLV_AND_NON_TLV_SUPPORT
1796 if (event_id >= wmi_events_max ||
1797 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1798 qdf_print("%s: Event id %d is unavailable\n",
1799 __func__, event_id);
1800 return QDF_STATUS_E_FAILURE;
1801 }
1802 evt_id = wmi_handle->wmi_events[event_id];
1803#else
1804 evt_id = event_id;
1805#endif
1806 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1807 qdf_print("%s : event handler already registered 0x%x\n",
1808 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301809 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301810 }
1811 if (wmi_handle->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301812 qdf_print("%s : no more event handlers 0x%x\n",
1813 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301814 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301815 }
1816 idx = wmi_handle->max_event_idx;
1817 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301818 wmi_handle->event_id[idx] = evt_id;
Govind Singh813fdac2016-03-12 09:26:52 +05301819 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301820 wmi_handle->ctx[idx] = rx_ctx;
Govind Singh813fdac2016-03-12 09:26:52 +05301821 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301822 wmi_handle->max_event_idx++;
1823
1824 return 0;
1825}
1826
1827/**
1828 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1829 * @wmi_handle: handle to wmi
1830 * @event_id: wmi event id
1831 *
1832 * Return: 0 on success
1833 */
1834int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301835 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301836{
1837 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301838 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301839
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301840#ifdef WMI_TLV_AND_NON_TLV_SUPPORT
1841 if (event_id >= wmi_events_max ||
1842 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1843 qdf_print("%s: Event id %d is unavailable\n",
1844 __func__, event_id);
1845 return QDF_STATUS_E_FAILURE;
1846 }
1847 evt_id = wmi_handle->wmi_events[event_id];
1848#else
1849 evt_id = event_id;
1850#endif
1851
1852 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301853 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301854 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1855 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301856 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301857 }
1858 wmi_handle->event_handler[idx] = NULL;
1859 wmi_handle->event_id[idx] = 0;
1860 --wmi_handle->max_event_idx;
1861 wmi_handle->event_handler[idx] =
1862 wmi_handle->event_handler[wmi_handle->max_event_idx];
1863 wmi_handle->event_id[idx] =
1864 wmi_handle->event_id[wmi_handle->max_event_idx];
1865
1866 return 0;
1867}
1868
1869/**
Govind Singhd52faac2016-03-09 12:03:29 +05301870 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301871 * @wmi_handle: handle to wmi
1872 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301873 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301874 *
Govind Singhd52faac2016-03-09 12:03:29 +05301875 * Event process by below function will be in default caller context.
1876 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301877 *
1878 * Return: none
1879 */
Govind Singhd52faac2016-03-09 12:03:29 +05301880static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1881 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301882{
1883 wmi_buf_t evt_buf;
1884 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1885
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301886#ifdef WMI_NON_TLV_SUPPORT
1887 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1888 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1889#else
Govind Singh5eb51532016-03-09 11:34:12 +05301890 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301891 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301892#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301893
Govind Singh6b411b52016-03-06 19:55:02 +05301894 return;
1895}
1896
1897/**
1898 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1899 * @wmi_handle: handle to wmi
1900 * @htc_packet: pointer to htc packet
1901 *
1902 * Event process by below function will be in worker thread context.
1903 * Use this method for events which are not critical and not
1904 * handled in protocol stack.
1905 *
1906 * Return: none
1907 */
1908static void wmi_process_fw_event_worker_thread_ctx
1909 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1910{
1911 wmi_buf_t evt_buf;
1912 uint32_t id;
1913 uint8_t *data;
1914
1915 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05301916 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
1917 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301918
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301919#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301920 if (wmi_handle->log_info.wmi_logging_enable) {
1921 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1922 /* Exclude 4 bytes of TLV header */
1923 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
1924 wmi_handle->log_info.buf_offset_event));
1925 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1926 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301927#endif
Govind Singhb53420c2016-03-09 14:32:57 +05301928 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1929 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1930 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301931 schedule_work(&wmi_handle->rx_event_work);
1932 return;
1933}
1934
1935/**
Govind Singhd52faac2016-03-09 12:03:29 +05301936 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301937 * @ctx: handle to wmi
1938 * @htc_packet: pointer to htc packet
1939 *
Govind Singh6b411b52016-03-06 19:55:02 +05301940 * Return: none
1941 */
1942void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
1943{
1944 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
1945 wmi_buf_t evt_buf;
1946 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301947 uint32_t idx = 0;
1948 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301949
1950 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05301951 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301952 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301953 if (qdf_unlikely(idx == A_ERROR)) {
1954 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05301955 ("%s :event handler is not registered: event id 0x%x\n",
1956 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301957 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301958 return;
1959 }
Govind Singh813fdac2016-03-12 09:26:52 +05301960 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301961 exec_ctx = wmi_handle->ctx[idx];
Govind Singh813fdac2016-03-12 09:26:52 +05301962 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301963
1964 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301965 wmi_process_fw_event_worker_thread_ctx
1966 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301967 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1968 wmi_process_fw_event_default_ctx
1969 (wmi_handle, htc_packet, exec_ctx);
1970 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05301971 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
1972 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301973 }
Govind Singhd52faac2016-03-09 12:03:29 +05301974
Govind Singh6b411b52016-03-06 19:55:02 +05301975}
1976
1977/**
1978 * wmi_process_fw_event() - process any fw event
1979 * @wmi_handle: wmi handle
1980 * @evt_buf: fw event buffer
1981 *
Govind Singhd52faac2016-03-09 12:03:29 +05301982 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301983 *
1984 * Return: none
1985 */
1986void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1987{
1988 __wmi_control_rx(wmi_handle, evt_buf);
1989}
1990
1991/**
1992 * __wmi_control_rx() - process serialize wmi event callback
1993 * @wmi_handle: wmi handle
1994 * @evt_buf: fw event buffer
1995 *
1996 * Return: none
1997 */
1998void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1999{
2000 uint32_t id;
2001 uint8_t *data;
2002 uint32_t len;
2003 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302004#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302005 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302006#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302007 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302008
Govind Singhb53420c2016-03-09 14:32:57 +05302009 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302010
Govind Singhb53420c2016-03-09 14:32:57 +05302011 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302012 goto end;
2013
Govind Singhb53420c2016-03-09 14:32:57 +05302014 data = qdf_nbuf_data(evt_buf);
2015 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302016
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302017#ifndef WMI_NON_TLV_SUPPORT
2018 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2019 /* Validate and pad(if necessary) the TLVs */
2020 tlv_ok_status =
2021 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302022 data, len, id,
2023 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302024 if (tlv_ok_status != 0) {
2025 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2026 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2027 __func__, id, tlv_ok_status);
2028 goto end;
2029 }
Govind Singh6b411b52016-03-06 19:55:02 +05302030 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302031#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302032
Govind Singhd52faac2016-03-09 12:03:29 +05302033 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2034 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302035 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302036 "%s : event handler is not registered: event id 0x%x\n",
2037 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302038 goto end;
2039 }
Govind Singhd52faac2016-03-09 12:03:29 +05302040#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302041 if (wmi_handle->log_info.wmi_logging_enable) {
2042 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2043 /* Exclude 4 bytes of TLV header */
2044 if (wmi_handle->log_info.is_management_record(id)) {
2045 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2046 + wmi_handle->log_info.buf_offset_event));
2047 } else {
2048 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2049 wmi_handle->log_info.buf_offset_event));
2050 }
2051 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302052 }
Govind Singhd52faac2016-03-09 12:03:29 +05302053#endif
2054 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302055 if (wmi_handle->target_type == WMI_TLV_TARGET)
2056 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2057 wmi_cmd_struct_ptr, len);
2058 else
2059 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2060 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302061
Govind Singh6b411b52016-03-06 19:55:02 +05302062end:
Govind Singhd52faac2016-03-09 12:03:29 +05302063 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302064#ifndef WMI_NON_TLV_SUPPORT
2065 if (wmi_handle->target_type == WMI_TLV_TARGET)
2066 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2067#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302068 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302069
Govind Singh6b411b52016-03-06 19:55:02 +05302070}
2071
2072/**
2073 * wmi_rx_event_work() - process rx event in rx work queue context
2074 * @work: rx work queue struct
2075 *
2076 * This function process any fw event to serialize it through rx worker thread.
2077 *
2078 * Return: none
2079 */
2080void wmi_rx_event_work(struct work_struct *work)
2081{
2082 struct wmi_unified *wmi = container_of(work, struct wmi_unified,
Govind Singhecf03cd2016-05-12 12:45:51 +05302083 rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302084 wmi_buf_t buf;
2085
Govind Singhb53420c2016-03-09 14:32:57 +05302086 qdf_spin_lock_bh(&wmi->eventq_lock);
2087 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2088 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302089 while (buf) {
2090 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302091 qdf_spin_lock_bh(&wmi->eventq_lock);
2092 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2093 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302094 }
2095}
2096
Govind Singh6b411b52016-03-06 19:55:02 +05302097#ifdef FEATURE_RUNTIME_PM
2098/**
2099 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2100 * @wmi_handle: wmi context
2101 */
Govind Singhd52faac2016-03-09 12:03:29 +05302102static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302103{
Govind Singhb53420c2016-03-09 14:32:57 +05302104 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302105}
Govind Singhd52faac2016-03-09 12:03:29 +05302106
2107/**
2108 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2109 * @wmi_handle: wmi context
2110 * @val: runtime pm progress flag
2111 */
2112void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2113{
Govind Singhb53420c2016-03-09 14:32:57 +05302114 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302115}
2116
2117/**
2118 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2119 * @wmi_handle: wmi context
2120 */
2121inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2122{
Govind Singhb53420c2016-03-09 14:32:57 +05302123 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302124}
Govind Singh6b411b52016-03-06 19:55:02 +05302125#else
Govind Singhd52faac2016-03-09 12:03:29 +05302126static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302127{
2128}
2129#endif
2130
2131/**
2132 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302133 * @scn_handle: handle to SCN
2134 * @osdev: OS device context
2135 * @target_type: TLV or not-TLV based target
2136 * @use_cookie: cookie based allocation enabled/disabled
2137 * @ops: umac rx callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302138 *
2139 * @Return: wmi handle.
2140 */
Govind Singhc458f382016-02-04 18:42:30 +05302141void *wmi_unified_attach(void *scn_handle,
2142 osdev_t osdev, enum wmi_target_type target_type,
Govind Singh5eb51532016-03-09 11:34:12 +05302143 bool use_cookie, struct wmi_rx_ops *rx_ops)
Govind Singh6b411b52016-03-06 19:55:02 +05302144{
2145 struct wmi_unified *wmi_handle;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302146
2147#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302148 wmi_handle =
2149 (struct wmi_unified *)os_malloc(NULL,
2150 sizeof(struct wmi_unified),
2151 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302152#else
2153 wmi_handle =
2154 (struct wmi_unified *) qdf_mem_malloc(
2155 sizeof(struct wmi_unified));
2156#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302157 if (wmi_handle == NULL) {
Govind Singhb53420c2016-03-09 14:32:57 +05302158 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302159 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302160 return NULL;
2161 }
2162 OS_MEMZERO(wmi_handle, sizeof(struct wmi_unified));
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302163 wmi_handle->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302164 qdf_atomic_init(&wmi_handle->pending_cmds);
2165 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302166 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302167 qdf_spinlock_create(&wmi_handle->eventq_lock);
2168 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302169 INIT_WORK(&wmi_handle->rx_event_work, wmi_rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302170#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302171 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2172 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2173 wmi_debugfs_init(wmi_handle);
2174 }
Govind Singh6b411b52016-03-06 19:55:02 +05302175#endif
Govind Singhc458f382016-02-04 18:42:30 +05302176 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302177 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2178 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302179 wmi_handle->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302180 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302181 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302182 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302183 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302184 /* Assign target cookie capablity */
2185 wmi_handle->use_cookie = use_cookie;
2186 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302187 wmi_handle->wmi_stopinprogress = 0;
Govind Singh813fdac2016-03-12 09:26:52 +05302188 qdf_spinlock_create(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302189
2190 return wmi_handle;
2191}
2192
2193/**
2194 * wmi_unified_detach() - detach for unified WMI
2195 *
2196 * @wmi_handle : handle to wmi.
2197 *
2198 * @Return: none.
2199 */
2200void wmi_unified_detach(struct wmi_unified *wmi_handle)
2201{
2202 wmi_buf_t buf;
2203
Govind Singhb53420c2016-03-09 14:32:57 +05302204 cancel_work_sync(&wmi_handle->rx_event_work);
Rajeev Kumarae91c402016-05-25 16:07:23 -07002205
2206 wmi_debugfs_remove(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
2207 wmi_handle->log_info.wmi_instance_id);
2208
Govind Singhb53420c2016-03-09 14:32:57 +05302209 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2210 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302211 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302212 qdf_nbuf_free(buf);
2213 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302214 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302215
2216#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302217 wmi_log_buffer_free(wmi_handle);
2218#endif
2219
Govind Singhb53420c2016-03-09 14:32:57 +05302220 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh20e7a062016-05-26 18:15:36 +05302221 qdf_spinlock_destroy(&wmi_handle->eventq_lock);
Govind Singh813fdac2016-03-12 09:26:52 +05302222 qdf_spinlock_destroy(&wmi_handle->ctx_lock);
Rajeev Kumarfec04012016-06-10 14:27:46 -07002223 OS_FREE(wmi_handle);
2224 wmi_handle = NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302225}
2226
2227/**
2228 * wmi_unified_remove_work() - detach for WMI work
2229 * @wmi_handle: handle to WMI
2230 *
2231 * A function that does not fully detach WMI, but just remove work
2232 * queue items associated with it. This is used to make sure that
2233 * before any other processing code that may destroy related contexts
2234 * (HTC, etc), work queue processing on WMI has already been stopped.
2235 *
2236 * Return: None
2237 */
2238void
2239wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2240{
2241 wmi_buf_t buf;
2242
Govind Singhb53420c2016-03-09 14:32:57 +05302243 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302244 "Enter: %s", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05302245 cancel_work_sync(&wmi_handle->rx_event_work);
2246 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2247 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302248 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302249 qdf_nbuf_free(buf);
2250 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302251 }
Govind Singhb53420c2016-03-09 14:32:57 +05302252 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2253 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302254 "Done: %s", __func__);
2255}
2256
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302257/**
2258 * wmi_htc_tx_complete() - Process htc tx completion
2259 *
2260 * @ctx: handle to wmi
2261 * @htc_packet: pointer to htc packet
2262 *
2263 * @Return: none.
2264 */
Govind Singh6b411b52016-03-06 19:55:02 +05302265void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
2266{
2267 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
2268 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302269
Govind Singh6b411b52016-03-06 19:55:02 +05302270#ifdef WMI_INTERFACE_EVENT_LOGGING
2271 uint32_t cmd_id;
2272#endif
2273
2274 ASSERT(wmi_cmd_buf);
2275#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302276 if (wmi_handle->log_info.wmi_logging_enable) {
2277 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2278 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302279
2280#ifdef QCA_WIFI_3_0_EMU
Govind Singhb53420c2016-03-09 14:32:57 +05302281 qdf_print
Govind Singh6b411b52016-03-06 19:55:02 +05302282 ("\nSent WMI command:%s command_id:0x%x over dma and recieved tx complete interupt\n",
Govind Singhecf03cd2016-05-12 12:45:51 +05302283 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302284#endif
2285
Govind Singhecf03cd2016-05-12 12:45:51 +05302286 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302287 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302288 - exclude TLV and WMI headers */
2289 if (wmi_handle->log_info.is_management_record(cmd_id)) {
2290 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2291 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2292 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302293 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302294 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2295 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2296 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302297 }
2298
Govind Singhecf03cd2016-05-12 12:45:51 +05302299 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2300 }
Govind Singh6b411b52016-03-06 19:55:02 +05302301#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302302 qdf_nbuf_free(wmi_cmd_buf);
2303 qdf_mem_free(htc_pkt);
2304 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302305}
2306
2307/**
2308 * wmi_get_host_credits() - WMI API to get updated host_credits
2309 *
2310 * @wmi_handle: handle to WMI.
2311 *
2312 * @Return: updated host_credits.
2313 */
2314int
2315wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2316 void *htc_handle)
2317{
2318
2319 int status;
2320 HTC_SERVICE_CONNECT_RESP response;
2321 HTC_SERVICE_CONNECT_REQ connect;
2322
2323 OS_MEMZERO(&connect, sizeof(connect));
2324 OS_MEMZERO(&response, sizeof(response));
2325
2326 /* meta data is unused for now */
2327 connect.pMetaData = NULL;
2328 connect.MetaDataLength = 0;
2329 /* these fields are the same for all service endpoints */
2330 connect.EpCallbacks.pContext = wmi_handle;
2331 connect.EpCallbacks.EpTxCompleteMultiple =
2332 NULL /* Control path completion ar6000_tx_complete */;
2333 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2334 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2335 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2336 connect.EpCallbacks.EpTxComplete =
2337 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2338
2339 /* connect to control service */
2340 connect.service_id = WMI_CONTROL_SVC;
2341 status = htc_connect_service(htc_handle, &connect,
2342 &response);
2343
2344 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302345 qdf_print
Govind Singh6b411b52016-03-06 19:55:02 +05302346 ("Failed to connect to WMI CONTROL service status:%d \n",
2347 status);
2348 return status;
2349 }
2350 wmi_handle->wmi_endpoint_id = response.Endpoint;
2351 wmi_handle->htc_handle = htc_handle;
2352 wmi_handle->max_msg_len = response.MaxMsgLength;
2353
2354 return EOK;
2355}
2356
2357/**
2358 * wmi_get_host_credits() - WMI API to get updated host_credits
2359 *
2360 * @wmi_handle: handle to WMI.
2361 *
2362 * @Return: updated host_credits.
2363 */
2364int wmi_get_host_credits(wmi_unified_t wmi_handle)
2365{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302366 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302367
2368 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2369 &host_credits);
2370 return host_credits;
2371}
2372
2373/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302374 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2375 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302376 *
2377 * @wmi_handle: handle to WMI.
2378 *
2379 * @Return: Pending Commands in the HTC queue.
2380 */
2381int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2382{
Govind Singhb53420c2016-03-09 14:32:57 +05302383 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302384}
2385
2386/**
2387 * wmi_set_target_suspend() - WMI API to set target suspend state
2388 *
2389 * @wmi_handle: handle to WMI.
2390 * @val: suspend state boolean.
2391 *
2392 * @Return: none.
2393 */
2394void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2395{
Govind Singhb53420c2016-03-09 14:32:57 +05302396 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302397}
2398
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302399#ifdef WMI_NON_TLV_SUPPORT
2400/**
2401 * API to flush all the previous packets associated with the wmi endpoint
2402 *
2403 * @param wmi_handle : handle to WMI.
2404 */
2405void
2406wmi_flush_endpoint(wmi_unified_t wmi_handle)
2407{
2408 htc_flush_endpoint(wmi_handle->htc_handle,
2409 wmi_handle->wmi_endpoint_id, 0);
2410}
2411
2412/**
2413 * generic function to block unified WMI command
2414 * @param wmi_handle : handle to WMI.
2415 * @return 0 on success and -ve on failure.
2416 */
2417int
2418wmi_stop(wmi_unified_t wmi_handle)
2419{
2420 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2421 "WMI Stop\n");
2422 wmi_handle->wmi_stopinprogress = 1;
2423 return 0;
2424}
2425#endif