blob: 96dbe5ba4933528cc97906984df6b9faa9f68b2e [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
Govind Singh6b411b52016-03-06 19:55:02 +053046#define WMI_MIN_HEAD_ROOM 64
47
48#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +053049#ifndef MAX_WMI_INSTANCES
50#ifdef CONFIG_MCL
51#define MAX_WMI_INSTANCES 1
52#else
53#define MAX_WMI_INSTANCES 3
54#endif
55#endif
56
Govind Singh6b411b52016-03-06 19:55:02 +053057/* WMI commands */
58uint32_t g_wmi_command_buf_idx = 0;
59struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
60
61/* WMI commands TX completed */
62uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
63struct wmi_command_debug
64 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
65
66/* WMI events when processed */
67uint32_t g_wmi_event_buf_idx = 0;
68struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
69
70/* WMI events when queued */
71uint32_t g_wmi_rx_event_buf_idx = 0;
72struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
73
Govind Singhecf03cd2016-05-12 12:45:51 +053074#define WMI_COMMAND_RECORD(h, a, b) { \
75 if (wmi_log_max_entry <= \
76 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
77 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
78 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
79 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
80 .command = a; \
81 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
82 wmi_command_log_buf_info.buf) \
83 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
84 b, wmi_record_max_length); \
85 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
86 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
87 time = qdf_get_log_timestamp(); \
88 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
89 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +053090}
91
Govind Singhecf03cd2016-05-12 12:45:51 +053092#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
93 if (wmi_log_max_entry <= \
94 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
95 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx) = 0;\
96 ((struct wmi_command_debug *)h->log_info. \
97 wmi_command_tx_cmp_log_buf_info.buf) \
98 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
99 p_buf_tail_idx)]. \
100 command = a; \
101 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
102 wmi_command_tx_cmp_log_buf_info.buf) \
103 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
104 p_buf_tail_idx)]. \
105 data, b, wmi_record_max_length); \
106 ((struct wmi_command_debug *)h->log_info. \
107 wmi_command_tx_cmp_log_buf_info.buf) \
108 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
109 p_buf_tail_idx)]. \
110 time = qdf_get_log_timestamp(); \
111 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
112 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530113}
114
Govind Singhecf03cd2016-05-12 12:45:51 +0530115#define WMI_EVENT_RECORD(h, a, b) { \
116 if (wmi_log_max_entry <= \
117 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
118 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
119 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
120 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
121 event = a; \
122 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
123 wmi_event_log_buf_info.buf) \
124 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
125 wmi_record_max_length); \
126 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
127 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530128 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530129 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
130 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530131}
132
Govind Singhecf03cd2016-05-12 12:45:51 +0530133#define WMI_RX_EVENT_RECORD(h, a, b) { \
134 if (wmi_log_max_entry <= \
135 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
136 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
137 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
138 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
139 event = a; \
140 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
141 wmi_rx_event_log_buf_info.buf) \
142 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
143 data, b, wmi_record_max_length); \
144 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
145 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
146 time = qdf_get_log_timestamp(); \
147 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
148 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530149}
Govind Singh6b411b52016-03-06 19:55:02 +0530150
151uint32_t g_wmi_mgmt_command_buf_idx = 0;
152struct
153wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
154
155/* wmi_mgmt commands TX completed */
156uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
157struct wmi_command_debug
158wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
159
160/* wmi_mgmt events when processed */
161uint32_t g_wmi_mgmt_event_buf_idx = 0;
162struct wmi_event_debug
163wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
164
Govind Singhecf03cd2016-05-12 12:45:51 +0530165#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
166 if (wmi_mgmt_log_max_entry <= \
167 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
168 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx) = 0;\
169 ((struct wmi_command_debug *)h->log_info. \
170 wmi_mgmt_command_log_buf_info.buf) \
171 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
172 command = a; \
173 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
174 wmi_mgmt_command_log_buf_info.buf) \
175 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
176 data, b, \
177 wmi_record_max_length); \
178 ((struct wmi_command_debug *)h->log_info. \
179 wmi_mgmt_command_log_buf_info.buf) \
180 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
181 time = qdf_get_log_timestamp(); \
182 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
183 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530184}
185
Govind Singhecf03cd2016-05-12 12:45:51 +0530186#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
187 if (wmi_mgmt_log_max_entry <= \
188 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
189 p_buf_tail_idx)) \
190 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
191 p_buf_tail_idx) = 0; \
192 ((struct wmi_command_debug *)h->log_info. \
193 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
194 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
195 p_buf_tail_idx)].command = a; \
196 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
197 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
198 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
199 p_buf_tail_idx)].data, b, \
200 wmi_record_max_length); \
201 ((struct wmi_command_debug *)h->log_info. \
202 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
203 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
204 p_buf_tail_idx)].time = \
205 qdf_get_log_timestamp(); \
206 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
207 p_buf_tail_idx))++; \
208 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530209}
210
Govind Singhecf03cd2016-05-12 12:45:51 +0530211#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
212 if (wmi_mgmt_log_max_entry <= \
213 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
214 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
215 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
216 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
217 .event = a; \
218 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
219 wmi_mgmt_event_log_buf_info.buf) \
220 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
221 data, b, wmi_record_max_length); \
222 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
223 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
224 time = qdf_get_log_timestamp(); \
225 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
226 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530227}
228
Govind Singhecf03cd2016-05-12 12:45:51 +0530229/* These are defined to made it as module param, which can be configured */
230uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
231uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
232uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
233uint32_t wmi_display_size = 100;
234
235static uint8_t *wmi_id_to_name(WMI_CMD_ID wmi_command);
236
237/**
238 * wmi_log_init() - Initialize WMI event logging
239 * @wmi_handle: WMI handle.
240 *
241 * Return: Initialization status
242 */
243#ifdef CONFIG_MCL
244static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
245{
246 struct wmi_log_buf_t *cmd_log_buf =
247 &wmi_handle->log_info.wmi_command_log_buf_info;
248 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
249 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
250
251 struct wmi_log_buf_t *event_log_buf =
252 &wmi_handle->log_info.wmi_event_log_buf_info;
253 struct wmi_log_buf_t *rx_event_log_buf =
254 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
255
256 struct wmi_log_buf_t *mgmt_cmd_log_buf =
257 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
258 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
259 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
260 struct wmi_log_buf_t *mgmt_event_log_buf =
261 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
262
263 /* WMI commands */
264 cmd_log_buf->length = 0;
265 cmd_log_buf->buf_tail_idx = 0;
266 cmd_log_buf->buf = wmi_command_log_buffer;
267 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
268
269 /* WMI commands TX completed */
270 cmd_tx_cmpl_log_buf->length = 0;
271 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
272 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
273 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
274
275 /* WMI events when processed */
276 event_log_buf->length = 0;
277 event_log_buf->buf_tail_idx = 0;
278 event_log_buf->buf = wmi_event_log_buffer;
279 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
280
281 /* WMI events when queued */
282 rx_event_log_buf->length = 0;
283 rx_event_log_buf->buf_tail_idx = 0;
284 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
285 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
286
287 /* WMI Management commands */
288 mgmt_cmd_log_buf->length = 0;
289 mgmt_cmd_log_buf->buf_tail_idx = 0;
290 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
291 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
292
293 /* WMI Management commands Tx completed*/
294 mgmt_cmd_tx_cmp_log_buf->length = 0;
295 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
296 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
297 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
298 &g_wmi_mgmt_command_tx_cmp_buf_idx;
299
300 /* WMI Management events when processed*/
301 mgmt_event_log_buf->length = 0;
302 mgmt_event_log_buf->buf_tail_idx = 0;
303 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
304 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
305
306 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
307 wmi_handle->log_info.wmi_logging_enable = 1;
308
309 return QDF_STATUS_SUCCESS;
310}
311#else
312static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
313{
314 struct wmi_log_buf_t *cmd_log_buf =
315 &wmi_handle->log_info.wmi_command_log_buf_info;
316 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
317 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
318
319 struct wmi_log_buf_t *event_log_buf =
320 &wmi_handle->log_info.wmi_event_log_buf_info;
321 struct wmi_log_buf_t *rx_event_log_buf =
322 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
323
324 struct wmi_log_buf_t *mgmt_cmd_log_buf =
325 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
326 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
327 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
328 struct wmi_log_buf_t *mgmt_event_log_buf =
329 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
330
331 wmi_handle->log_info.wmi_logging_enable = 0;
332
333 /* WMI commands */
334 cmd_log_buf->length = 0;
335 cmd_log_buf->buf_tail_idx = 0;
336 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
337 wmi_log_max_entry * sizeof(struct wmi_command_debug));
338
339 if (!cmd_log_buf->buf) {
340 qdf_print("no memory for WMI command log buffer..\n");
341 return QDF_STATUS_E_NOMEM;
342 }
343 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
344
345 /* WMI commands TX completed */
346 cmd_tx_cmpl_log_buf->length = 0;
347 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
348 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
349 wmi_log_max_entry * sizeof(struct wmi_command_debug));
350
351 if (!cmd_tx_cmpl_log_buf->buf) {
352 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
353 return QDF_STATUS_E_NOMEM;
354 }
355 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
356 &cmd_tx_cmpl_log_buf->buf_tail_idx;
357
358 /* WMI events when processed */
359 event_log_buf->length = 0;
360 event_log_buf->buf_tail_idx = 0;
361 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
362 wmi_log_max_entry * sizeof(struct wmi_event_debug));
363
364 if (!event_log_buf->buf) {
365 qdf_print("no memory for WMI Event log buffer..\n");
366 return QDF_STATUS_E_NOMEM;
367 }
368 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
369
370 /* WMI events when queued */
371 rx_event_log_buf->length = 0;
372 rx_event_log_buf->buf_tail_idx = 0;
373 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
374 wmi_log_max_entry * sizeof(struct wmi_event_debug));
375
376 if (!rx_event_log_buf->buf) {
377 qdf_print("no memory for WMI Event Rx log buffer..\n");
378 return QDF_STATUS_E_NOMEM;
379 }
380 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
381
382 /* WMI Management commands */
383 mgmt_cmd_log_buf->length = 0;
384 mgmt_cmd_log_buf->buf_tail_idx = 0;
385 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
386 wmi_mgmt_log_max_entry *
387 sizeof(struct wmi_command_debug));
388
389 if (!mgmt_cmd_log_buf->buf) {
390 qdf_print("no memory for WMI Management Command log buffer..\n");
391 return QDF_STATUS_E_NOMEM;
392 }
393 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
394
395 /* WMI Management commands Tx completed*/
396 mgmt_cmd_tx_cmp_log_buf->length = 0;
397 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
398 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
399 qdf_mem_malloc(
400 wmi_mgmt_log_max_entry *
401 sizeof(struct wmi_command_debug));
402
403 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
404 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
405 return QDF_STATUS_E_NOMEM;
406 }
407 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
408 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
409
410 /* WMI Management events when processed*/
411 mgmt_event_log_buf->length = 0;
412 mgmt_event_log_buf->buf_tail_idx = 0;
413
414 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
415 wmi_mgmt_log_max_entry *
416 sizeof(struct wmi_event_debug));
417
418 if (!mgmt_event_log_buf->buf) {
419 qdf_print("no memory for WMI Management Event log buffer..\n");
420 return QDF_STATUS_E_NOMEM;
421 }
422 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
423
424 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
425 wmi_handle->log_info.wmi_logging_enable = 1;
426
427 return QDF_STATUS_SUCCESS;
428}
429#endif
430
431/**
432 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
433 * event logging
434 * @wmi_handle: WMI handle.
435 *
436 * Return: None
437 */
438#ifndef CONFIG_MCL
439static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
440{
441 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
442 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
443 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
444 qdf_mem_free(
445 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
446 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
447 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
448 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
449 qdf_mem_free(
450 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
451 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
452 qdf_mem_free(
453 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
454 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
455 qdf_mem_free(
456 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
457 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
458 qdf_mem_free(
459 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
460 wmi_handle->log_info.wmi_logging_enable = 0;
461 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
462}
463#else
464static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
465{
466 /* Do Nothing */
467}
468#endif
469
470#ifdef CONFIG_MCL
471const int8_t * const debugfs_dir[] = {"WMI0", "WMI1", "WMI2"};
472#else
473const int8_t * const debugfs_dir[] = {"WMI0"};
474#endif
475
476/* debugfs routines*/
477
478/**
479 * debug_wmi_##func_base##_show() - debugfs functions to display content of
480 * command and event buffers. Macro uses max buffer length to display
481 * buffer when it is wraparound.
482 *
483 * @m: debugfs handler to access wmi_handle
484 * @v: Variable arguments (not used)
485 *
486 * Return: Length of characters printed
487 */
488#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
489 static int debug_wmi_##func_base##_show(struct seq_file *m, \
490 void *v) \
491 { \
492 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
493 struct wmi_log_buf_t *wmi_log = \
494 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
495 int pos, nread, outlen; \
496 int i; \
497 \
498 if (!wmi_log->length) \
499 return seq_printf(m, \
500 "no elements to read from ring buffer!\n"); \
501 \
502 if (wmi_log->length <= wmi_ring_size) \
503 nread = wmi_log->length; \
504 else \
505 nread = wmi_ring_size; \
506 \
507 if (*(wmi_log->p_buf_tail_idx) == 0) \
508 /* tail can be 0 after wrap-around */ \
509 pos = wmi_ring_size - 1; \
510 else \
511 pos = *(wmi_log->p_buf_tail_idx) - 1; \
512 \
513 outlen = 0; \
514 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
515 while (nread--) { \
516 struct wmi_command_debug *wmi_record; \
517 \
518 wmi_record = (struct wmi_command_debug *) \
519 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
520 outlen += seq_printf(m, "CMD ID = %x\n", \
521 (wmi_record->command)); \
522 outlen += seq_printf(m, "CMD = "); \
523 for (i = 0; i < (wmi_record_max_length/ \
524 sizeof(uint32_t)); i++) \
525 outlen += seq_printf(m, "%x ", \
526 wmi_record->data[i]); \
527 outlen += seq_printf(m, "\n"); \
528 \
529 if (pos == 0) \
530 pos = wmi_ring_size - 1; \
531 else \
532 pos--; \
533 } \
534 outlen += seq_printf(m, "Length = %d\n", wmi_log->length);\
535 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
536 \
537 return outlen; \
538 } \
539
540#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
541 static int debug_wmi_##func_base##_show(struct seq_file *m, \
542 void *v) \
543 { \
544 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
545 struct wmi_log_buf_t *wmi_log = \
546 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
547 int pos, nread, outlen; \
548 int i; \
549 \
550 if (!wmi_log->length) \
551 return seq_printf(m, \
552 "no elements to read from ring buffer!\n"); \
553 \
554 if (wmi_log->length <= wmi_ring_size) \
555 nread = wmi_log->length; \
556 else \
557 nread = wmi_ring_size; \
558 \
559 if (*(wmi_log->p_buf_tail_idx) == 0) \
560 /* tail can be 0 after wrap-around */ \
561 pos = wmi_ring_size - 1; \
562 else \
563 pos = *(wmi_log->p_buf_tail_idx) - 1; \
564 \
565 outlen = 0; \
566 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
567 while (nread--) { \
568 struct wmi_event_debug *wmi_record; \
569 \
570 wmi_record = (struct wmi_event_debug *) \
571 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
572 outlen += seq_printf(m, "Event ID = %x\n", \
573 (wmi_record->event)); \
574 outlen += seq_printf(m, "CMD = "); \
575 for (i = 0; i < (wmi_record_max_length/ \
576 sizeof(uint32_t)); i++) \
577 outlen += seq_printf(m, "%x ", \
578 wmi_record->data[i]); \
579 outlen += seq_printf(m, "\n"); \
580 \
581 if (pos == 0) \
582 pos = wmi_ring_size - 1; \
583 else \
584 pos--; \
585 } \
586 outlen += seq_printf(m, "Length = %d\n", wmi_log->length);\
587 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
588 \
589 return outlen; \
590 }
591
592GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
593GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
594GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
595GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
596GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
597GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
598 wmi_display_size);
599GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
600
601/**
602 * debug_wmi_enable_show() - debugfs functions to display enable state of
603 * wmi logging feature.
604 *
605 * @m: debugfs handler to access wmi_handle
606 * @v: Variable arguments (not used)
607 *
608 * Return: always 1
609 */
610static int debug_wmi_enable_show(struct seq_file *m, void *v)
611{
612 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
613
614 return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
615
616}
617
618/**
619 * debug_wmi_log_size_show() - debugfs functions to display configured size of
620 * wmi logging command/event buffer and management command/event buffer.
621 *
622 * @m: debugfs handler to access wmi_handle
623 * @v: Variable arguments (not used)
624 *
625 * Return: Length of characters printed
626 */
627static int debug_wmi_log_size_show(struct seq_file *m, void *v)
628{
629
630 seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
631 return seq_printf(m, "WMI management command/events log max size:%d\n",
632 wmi_mgmt_log_max_entry);
633}
634
635/**
636 * debug_wmi_##func_base##_write() - debugfs functions to clear
637 * wmi logging command/event buffer and management command/event buffer.
638 *
639 * @file: file handler to access wmi_handle
640 * @buf: received data buffer
641 * @count: length of received buffer
642 * @ppos: Not used
643 *
644 * Return: count
645 */
646#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
647 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
648 const char __user *buf, \
649 size_t count, loff_t *ppos) \
650 { \
651 int k, ret; \
652 wmi_unified_t wmi_handle = file->private_data; \
653 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
654 wmi_##func_base##_buf_info; \
655 \
656 ret = sscanf(buf, "%d", &k); \
657 if ((ret != 1) || (k != 0)) { \
658 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
659 return -EINVAL; \
660 } \
661 \
662 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
663 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
664 sizeof(struct wmi_record_type)); \
665 wmi_log->length = 0; \
666 *(wmi_log->p_buf_tail_idx) = 0; \
667 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
668 \
669 return count; \
670 }
671
672GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
673 wmi_command_debug);
674GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
675 wmi_command_debug);
676GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
677 wmi_event_debug);
678GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
679 wmi_event_debug);
680GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
681 wmi_command_debug);
682GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
683 wmi_mgmt_log_max_entry, wmi_command_debug);
684GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
685 wmi_event_debug);
686
687/**
688 * debug_wmi_enable_write() - debugfs functions to enable/disable
689 * wmi logging feature.
690 *
691 * @file: file handler to access wmi_handle
692 * @buf: received data buffer
693 * @count: length of received buffer
694 * @ppos: Not used
695 *
696 * Return: count
697 */
698static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
699 size_t count, loff_t *ppos)
700{
701 wmi_unified_t wmi_handle = file->private_data;
702 int k, ret;
703
704 ret = sscanf(buf, "%d", &k);
705 if ((ret != 1) || ((k != 0) && (k != 1)))
706 return -EINVAL;
707
708 wmi_handle->log_info.wmi_logging_enable = k;
709 return count;
710}
711
712/**
713 * debug_wmi_log_size_write() - reserved.
714 *
715 * @file: file handler to access wmi_handle
716 * @buf: received data buffer
717 * @count: length of received buffer
718 * @ppos: Not used
719 *
720 * Return: count
721 */
722static ssize_t debug_wmi_log_size_write(struct file *file,
723 const char __user *buf, size_t count, loff_t *ppos)
724{
725 return -EINVAL;
726}
727
728/* Structure to maintain debug information */
729struct wmi_debugfs_info {
730 const char *name;
731 struct dentry *de[MAX_WMI_INSTANCES];
732 const struct file_operations *ops;
733};
734
735#define DEBUG_FOO(func_base) { .name = #func_base, \
736 .ops = &debug_##func_base##_ops }
737
738/**
739 * debug_##func_base##_open() - Open debugfs entry for respective command
740 * and event buffer.
741 *
742 * @inode: node for debug dir entry
743 * @file: file handler
744 *
745 * Return: open status
746 */
747#define GENERATE_DEBUG_STRUCTS(func_base) \
748 static int debug_##func_base##_open(struct inode *inode, \
749 struct file *file) \
750 { \
751 return single_open(file, debug_##func_base##_show, \
752 inode->i_private); \
753 } \
754 \
755 \
756 static struct file_operations debug_##func_base##_ops = { \
757 .open = debug_##func_base##_open, \
758 .read = seq_read, \
759 .llseek = seq_lseek, \
760 .write = debug_##func_base##_write, \
761 .release = single_release, \
762 };
763
764GENERATE_DEBUG_STRUCTS(wmi_command_log);
765GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
766GENERATE_DEBUG_STRUCTS(wmi_event_log);
767GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
768GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
769GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
770GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
771GENERATE_DEBUG_STRUCTS(wmi_enable);
772GENERATE_DEBUG_STRUCTS(wmi_log_size);
773
774struct wmi_debugfs_info wmi_debugfs_infos[] = {
775 DEBUG_FOO(wmi_command_log),
776 DEBUG_FOO(wmi_command_tx_cmp_log),
777 DEBUG_FOO(wmi_event_log),
778 DEBUG_FOO(wmi_rx_event_log),
779 DEBUG_FOO(wmi_mgmt_command_log),
780 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
781 DEBUG_FOO(wmi_mgmt_event_log),
782 DEBUG_FOO(wmi_enable),
783 DEBUG_FOO(wmi_log_size),
784};
785
786#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
787 sizeof(wmi_debugfs_infos[0]))
788
789/**
790 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
791 *
792 * @wmi_handle: wmi handle
793 * @par_entry: debug directory entry
794 * @id: Index to debug info data array
795 *
796 * Return: none
797 */
798static void wmi_debugfs_create(wmi_unified_t wmi_handle,
799 struct dentry *par_entry, int id)
800{
801 int i;
802
803 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
804 goto out;
805
806 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
807
808 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
809 wmi_debugfs_infos[i].name, 0644, par_entry,
810 wmi_handle, wmi_debugfs_infos[i].ops);
811
812 if (wmi_debugfs_infos[i].de[id] == NULL) {
813 qdf_print("%s: debug Entry creation failed!\n",
814 __func__);
815 goto out;
816 }
817 }
818
819 return;
820
821out:
822 qdf_print("%s: debug Entry creation failed!\n", __func__);
823 wmi_log_buffer_free(wmi_handle);
824 return;
825}
826
827/**
828 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +0530829 * @wmi_handle: wmi handle
830 * @dentry: debugfs directory entry
831 * @id: Index to debug info data array
832 *
833 * Return: none
834 */
835static void wmi_debugfs_remove(wmi_unified_t wmi_handle, struct dentry *dentry
836 , int id)
837{
838 int i;
839
840 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
841 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
842 if (wmi_debugfs_infos[i].de[id])
843 wmi_debugfs_infos[i].de[id] = NULL;
844 }
845 }
846
847 if (dentry)
848 debugfs_remove_recursive(dentry);
849}
850
851/**
852 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
853 * create debugfs enteries.
854 *
855 * @h: wmi handler
856 *
857 * Return: init status
858 */
859static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
860{
861 static int wmi_index;
862
863 if (wmi_index < MAX_WMI_INSTANCES)
864 wmi_handle->log_info.wmi_log_debugfs_dir =
865 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
866
867 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
868 qdf_print("error while creating debugfs dir for %s\n",
869 debugfs_dir[wmi_index]);
870 return QDF_STATUS_E_FAILURE;
871 }
872
873 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
874 wmi_index);
875 wmi_handle->log_info.wmi_instance_id = wmi_index++;
876
877 return QDF_STATUS_SUCCESS;
878}
Rajeev Kumarae91c402016-05-25 16:07:23 -0700879#else
880/**
881 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
882 * @wmi_handle: wmi handle
883 * @dentry: debugfs directory entry
884 * @id: Index to debug info data array
885 *
886 * Return: none
887 */
888static void wmi_debugfs_remove(wmi_unified_t wmi_handle, struct dentry *dentry
889 , int id) { }
Govind Singh6b411b52016-03-06 19:55:02 +0530890#endif /*WMI_INTERFACE_EVENT_LOGGING */
891
Govind Singh6b411b52016-03-06 19:55:02 +0530892int wmi_get_host_credits(wmi_unified_t wmi_handle);
893/* WMI buffer APIs */
894
895#ifdef MEMORY_DEBUG
896wmi_buf_t
897wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +0530898 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +0530899{
900 wmi_buf_t wmi_buf;
901
902 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +0530903 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +0530904 return NULL;
905 }
906
Govind Singhb53420c2016-03-09 14:32:57 +0530907 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +0530908 roundup(len + WMI_MIN_HEAD_ROOM, 4),
909 WMI_MIN_HEAD_ROOM, 4, false, file_name,
910 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +0530911
912 if (!wmi_buf)
913 return NULL;
914
915 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +0530916 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +0530917
918 /*
919 * Set the length of the buffer to match the allocation size.
920 */
Govind Singhb53420c2016-03-09 14:32:57 +0530921 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +0530922
923 return wmi_buf;
924}
925
926void wmi_buf_free(wmi_buf_t net_buf)
927{
Govind Singhb53420c2016-03-09 14:32:57 +0530928 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +0530929}
930#else
931wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
932{
933 wmi_buf_t wmi_buf;
934
935 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +0530936 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +0530937 return NULL;
938 }
939
Govind Singhb53420c2016-03-09 14:32:57 +0530940 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +0530941 WMI_MIN_HEAD_ROOM, 4, false);
942 if (!wmi_buf)
943 return NULL;
944
945 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +0530946 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +0530947
948 /*
949 * Set the length of the buffer to match the allocation size.
950 */
Govind Singhb53420c2016-03-09 14:32:57 +0530951 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +0530952 return wmi_buf;
953}
954
955void wmi_buf_free(wmi_buf_t net_buf)
956{
Govind Singhb53420c2016-03-09 14:32:57 +0530957 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +0530958}
959#endif
960
961/**
962 * wmi_get_max_msg_len() - get maximum WMI message length
963 * @wmi_handle: WMI handle.
964 *
965 * This function returns the maximum WMI message length
966 *
967 * Return: maximum WMI message length
968 */
969uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
970{
971 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
972}
973
Govind Singhe7d9f3e2016-04-15 13:58:27 +0530974#ifndef WMI_NON_TLV_SUPPORT
Govind Singhecf03cd2016-05-12 12:45:51 +0530975static uint8_t *wmi_id_to_name(WMI_CMD_ID wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +0530976{
977 switch (wmi_command) {
978 /* initialize the wlan sub system */
979 CASE_RETURN_STRING(WMI_INIT_CMDID);
980
981 /* Scan specific commands */
982
983 /* start scan request to FW */
984 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
985 /* stop scan request to FW */
986 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
987 /* full list of channels as defined by the regulatory
988 * that will be used by scanner */
989 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
990 /* overwrite default priority table in scan scheduler */
991 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
992 /* This command to adjust the priority and min.max_rest_time
993 * of an on ongoing scan request.
994 */
995 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
996
997 /* PDEV(physical device) specific commands */
998 /* set regulatorty ctl id used by FW to determine the exact
999 * ctl power limits */
1000 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1001 /* set channel. mainly used for supporting monitor mode */
1002 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1003 /* set pdev specific parameters */
1004 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1005 /* enable packet log */
1006 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1007 /* disable packet log*/
1008 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1009 /* set wmm parameters */
1010 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1011 /* set HT cap ie that needs to be carried probe requests
1012 * HT/VHT channels */
1013 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1014 /* set VHT cap ie that needs to be carried on probe
1015 * requests on VHT channels */
1016 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1017
1018 /* Command to send the DSCP-to-TID map to the target */
1019 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1020 /* set quiet ie parameters. primarily used in AP mode */
1021 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1022 /* Enable/Disable Green AP Power Save */
1023 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1024 /* get TPC config for the current operating channel */
1025 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1026
1027 /* set the base MAC address for the physical device before
1028 * a VDEV is created. For firmware that does not support
1029 * this feature and this command, the pdev MAC address will
1030 * not be changed. */
1031 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1032
1033 /* eeprom content dump , the same to bdboard data */
1034 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1035
1036 /* VDEV(virtual device) specific commands */
1037 /* vdev create */
1038 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1039 /* vdev delete */
1040 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1041 /* vdev start request */
1042 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1043 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1044 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1045 /* vdev up request */
1046 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1047 /* vdev stop request */
1048 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1049 /* vdev down request */
1050 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1051 /* set a vdev param */
1052 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1053 /* set a key (used for setting per peer unicast
1054 * and per vdev multicast) */
1055 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1056
1057 /* wnm sleep mode command */
1058 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1059 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1060 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1061 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1062 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1063 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1064
1065 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1066 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1067 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1068 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1069
1070 /* peer specific commands */
1071
1072 /** create a peer */
1073 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1074 /** delete a peer */
1075 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1076 /** flush specific tid queues of a peer */
1077 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1078 /** set a parameter of a peer */
1079 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1080 /* set peer to associated state. will cary all parameters
1081 * determined during assocication time */
1082 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1083 /* add a wds (4 address ) entry. used only for testing
1084 * WDS feature on AP products */
1085 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1086 /* remove wds (4 address ) entry. used only for testing WDS
1087 * feature on AP products */
1088 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1089 /* set up mcast info for multicast to unicast conversion */
1090 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1091 /* request peer info from FW to get PEER_INFO_EVENTID */
1092 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1093
1094 /* beacon/management specific commands */
1095
1096 /* transmit beacon by reference. used for transmitting beacon
1097 * on low latency interface like pcie */
1098 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1099 /* transmit beacon by value */
1100 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1101 /* set the beacon template. used in beacon offload mode to setup
1102 * the common beacon template with the FW to be used by FW to
1103 * generate beacons */
1104 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1105 /* set beacon filter with FW */
1106 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1107 /* enable/disable filtering of probe requests in the firmware */
1108 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1109 /* transmit management frame by value. will be deprecated */
1110 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1111 /* set the probe response template. used in beacon offload mode
1112 * to setup the common probe response template with the FW to
1113 * be used by FW to generate probe responses */
1114 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1115
1116 /* commands to directly control ba negotiation directly from
1117 * host. only used in test mode */
1118
1119 /* turn off FW Auto addba mode and let host control addba */
1120 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1121 /* send add ba request */
1122 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1123 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1124 /* send del ba */
1125 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1126 /* set add ba response will be used by FW to generate
1127 * addba response*/
1128 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1129 /* send single VHT MPDU with AMSDU */
1130 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1131
1132 /* Station power save specific config */
1133 /* enable/disable station powersave */
1134 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1135 /* set station power save specific parameter */
1136 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1137 /* set station mimo powersave mode */
1138 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1139
1140 /* DFS-specific commands */
1141 /* enable DFS (radar detection)*/
1142 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1143 /* disable DFS (radar detection)*/
1144 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1145 /* enable DFS phyerr/parse filter offload */
1146 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1147 /* enable DFS phyerr/parse filter offload */
1148 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1149
1150 /* Roaming specific commands */
1151 /* set roam scan mode */
1152 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1153 /* set roam scan rssi threshold below which roam
1154 * scan is enabled */
1155 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1156 /* set roam scan period for periodic roam scan mode */
1157 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1158 /* set roam scan trigger rssi change threshold */
1159 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1160 /* set roam AP profile */
1161 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1162 /* set channel list for roam scans */
1163 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1164 /* offload scan specific commands */
1165 /* set offload scan AP profile */
1166 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1167 /* remove offload scan AP profile */
1168 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1169 /* set offload scan period */
1170 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1171
1172 /* P2P specific commands */
1173 /* set P2P device info. FW will used by FW to create P2P IE
1174 * to be carried in probe response generated during p2p listen
1175 * and for p2p discoverability */
1176 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1177 /* enable/disable p2p discoverability on STA/AP VDEVs */
1178 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1179 /* set p2p ie to be carried in beacons generated by FW for GO */
1180 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1181 /* set p2p ie to be carried in probe response frames generated
1182 * by FW for GO */
1183 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1184 /* set the vendor specific p2p ie data.
1185 * FW will use this to parse the P2P NoA
1186 * attribute in the beacons/probe responses received.
1187 */
1188 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1189 /* set the configure of p2p find offload */
1190 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1191 /* set the vendor specific p2p ie data for p2p find offload */
1192 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1193 /* set the BSSID/device name pattern of p2p find offload */
1194 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1195 /* set OppPS related parameters **/
1196 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1197
1198 /* AP power save specific config
1199 * set AP power save specific param */
1200 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1201 /* set AP UAPSD coex pecific param */
1202 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1203
1204 /* Rate-control specific commands */
1205 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1206
1207 /* WLAN Profiling commands. */
1208 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1209 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1210 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1211 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1212 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1213
1214 /* Suspend resume command Ids */
1215 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1216 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1217
1218 /* Beacon filter commands */
1219 /* add a beacon filter */
1220 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1221 /* remove a beacon filter */
1222 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1223
1224 /* WOW Specific WMI commands */
1225 /* add pattern for awake */
1226 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1227 /* deleta a wake pattern */
1228 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1229 /* enable/deisable wake event */
1230 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1231 /* enable WOW */
1232 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1233 /* host woke up from sleep event to FW. Generated in response
1234 * to WOW Hardware event */
1235 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1236
1237 /* RTT measurement related cmd */
1238 /* reques to make an RTT measurement */
1239 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1240 /* reques to report a tsf measurement */
1241 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1242
1243 /* spectral scan command */
1244 /* configure spectral scan */
1245 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1246 /* enable/disable spectral scan and trigger */
1247 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1248
1249 /* F/W stats */
1250 /* one time request for stats */
1251 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1252 /* Push MCC Adaptive Scheduler Stats to Firmware */
1253 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1254
1255 /* ARP OFFLOAD REQUEST*/
1256 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1257
1258 /* Proactive ARP Response Add Pattern Command*/
1259 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1260
1261 /* Proactive ARP Response Del Pattern Command*/
1262 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1263
1264 /* NS offload confid*/
1265 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1266
1267 /* GTK offload Specific WMI commands */
1268 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1269
1270 /* CSA offload Specific WMI commands */
1271 /* csa offload enable */
1272 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1273 /* chan switch command */
1274 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1275
1276 /* Chatter commands */
1277 /* Change chatter mode of operation */
1278 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1279 /* chatter add coalescing filter command */
1280 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1281 /* chatter delete coalescing filter command */
1282 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1283 /* chatter coalecing query command */
1284 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1285
1286 /* addba specific commands */
1287 /* start the aggregation on this TID */
1288 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1289 /* stop the aggregation on this TID */
1290 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1291
1292 /* set station mimo powersave method */
1293 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1294 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1295 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1296 /* Configure the Keep Alive Parameters */
1297 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1298
1299 /* Request ssn from target for a sta/tid pair */
1300 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1301 /* misc command group */
1302 /* echo command mainly used for testing */
1303 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1304
1305 /* !!IMPORTANT!!
1306 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1307 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1308 * as we MUST have a fixed value here to maintain compatibility between
1309 * UTF and the ART2 driver
1310 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301311 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301312 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1313
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301314 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301315 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1316 /* QVIT specific command id */
1317 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1318 /* Factory Testing Mode request command
1319 * used for integrated chipsets */
1320 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1321 /* set and get keepalive parameters command */
1322 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1323 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1324 /* For fw recovery test command */
1325 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1326 /* Set Mcast/Bdcast filter */
1327 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1328 /* set thermal management params */
1329 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1330 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1331 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1332 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301333 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301334 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301335 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301336 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301337 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1338 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1339 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1340 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1341 /* GPIO Configuration */
1342 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1343 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1344
1345 /* Txbf configuration command */
1346 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1347
1348 /* FWTEST Commands */
1349 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1350 /* set NoA descs */
1351 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1352
1353 /* TDLS Configuration */
1354 /* enable/disable TDLS */
1355 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1356 /* set tdls peer state */
1357 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1358
1359 /* Resmgr Configuration */
1360 /* Adaptive OCS is enabled by default in the FW.
1361 * This command is used to disable FW based adaptive OCS.
1362 */
1363 CASE_RETURN_STRING
1364 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1365 /* set the requested channel time quota for the home channels */
1366 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1367 /* set the requested latency for the home channels */
1368 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1369
1370 /* STA SMPS Configuration */
1371 /* force SMPS mode */
1372 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1373 /* set SMPS parameters */
1374 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1375
1376 /* Wlan HB commands */
1377 /* enalbe/disable wlan HB */
1378 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1379 /* set tcp parameters for wlan HB */
1380 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1381 /* set tcp pkt filter for wlan HB */
1382 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1383 /* set udp parameters for wlan HB */
1384 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1385 /* set udp pkt filter for wlan HB */
1386 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1387
1388 /* Wlan RMC commands*/
1389 /* enable/disable RMC */
1390 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1391 /* configure action frame period */
1392 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1393 /* For debug/future enhancement purposes only,
1394 * configures/finetunes RMC algorithms */
1395 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1396
1397 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301398 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301399 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1400 /* Plumb routing table for MHF offload */
1401 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1402
1403 /* location scan commands */
1404 /* start batch scan */
1405 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1406 /* stop batch scan */
1407 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1408 /* get batch scan result */
1409 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1410 /* OEM related cmd */
1411 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1412 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1413 /* NAN request cmd */
1414 CASE_RETURN_STRING(WMI_NAN_CMDID);
1415 /* Modem power state cmd */
1416 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1417 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1418 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1419 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1420 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1421 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1422 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1423 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1424 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301425 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301426 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1427 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1428 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1429 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1430 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1431 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1432 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1433 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1434 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1435 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1436 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1437 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1438 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1439 CASE_RETURN_STRING
1440 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1441 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1442 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1443 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1444 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1445 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1446 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1447 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1448 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1449 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1450 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1451 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1452 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1453 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1454 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1455 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1456 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1457 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1458 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1459 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1460 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1461 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1462 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1463 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1464 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1465 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1466 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1467 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1468 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1469 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1470 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1471 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1472 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1473 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1474 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1475 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1476 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1477 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1478 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1479 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1480 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1481 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1482 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1483 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1484 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1485 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1486 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1487 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1488 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1489 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1490 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1491 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1492 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1493 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1494 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1495 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1496 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1497 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1498 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1499 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1500 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301501 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1502 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1503 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1504 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1505 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1506 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1507 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1508 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1509 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1510 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1511 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1512 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1513 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1514 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1515 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1516 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1517 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1518 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1519 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1520 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1521 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1522 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1523 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1524 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1525 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1526 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1527 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1528 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1529 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1530 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1531 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1532 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1533 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001534 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301535 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301536 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301537 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301538 }
1539
1540 return "Invalid WMI cmd";
1541}
1542
1543#ifdef QCA_WIFI_3_0_EMU
1544static inline void wma_log_cmd_id(WMI_CMD_ID cmd_id)
1545{
Govind Singhb53420c2016-03-09 14:32:57 +05301546 WMI_LOGE("Send WMI command:%s command_id:%d",
Govind Singhecf03cd2016-05-12 12:45:51 +05301547 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301548}
1549#else
1550static inline void wma_log_cmd_id(WMI_CMD_ID cmd_id)
1551{
Govind Singhb53420c2016-03-09 14:32:57 +05301552 WMI_LOGD("Send WMI command:%s command_id:%d",
Govind Singhecf03cd2016-05-12 12:45:51 +05301553 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301554}
1555#endif
Govind Singhecf03cd2016-05-12 12:45:51 +05301556#else /* WMI_NON_TLV_SUPPORT */
1557static uint8_t *wmi_id_to_name(WMI_CMD_ID wmi_command)
1558{
1559 return "Invalid WMI cmd";
1560}
1561
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301562#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301563
1564/**
Govind Singhd52faac2016-03-09 12:03:29 +05301565 * wmi_is_runtime_pm_cmd() - check if a cmd is from suspend resume sequence
Govind Singh6b411b52016-03-06 19:55:02 +05301566 * @cmd: command to check
1567 *
1568 * Return: true if the command is part of the suspend resume sequence.
1569 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301570#ifndef WMI_NON_TLV_SUPPORT
Govind Singhd52faac2016-03-09 12:03:29 +05301571static bool wmi_is_runtime_pm_cmd(WMI_CMD_ID cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301572{
1573 switch (cmd_id) {
1574 case WMI_WOW_ENABLE_CMDID:
1575 case WMI_PDEV_SUSPEND_CMDID:
1576 case WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID:
1577 case WMI_WOW_ADD_WAKE_PATTERN_CMDID:
1578 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1579 case WMI_PDEV_RESUME_CMDID:
1580 case WMI_WOW_DEL_WAKE_PATTERN_CMDID:
1581 case WMI_D0_WOW_ENABLE_DISABLE_CMDID:
1582 return true;
1583
1584 default:
1585 return false;
1586 }
1587}
1588
1589/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301590 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1591 * @cmd_id: command to check
1592 *
1593 * Return: true if the command is part of the resume sequence.
1594 */
1595static bool wmi_is_pm_resume_cmd(WMI_CMD_ID cmd_id)
1596{
1597 switch (cmd_id) {
1598 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1599 case WMI_PDEV_RESUME_CMDID:
1600 return true;
1601
1602 default:
1603 return false;
1604 }
1605}
1606#else
1607static bool wmi_is_runtime_pm_cmd(WMI_CMD_ID cmd_id)
1608{
1609 return false;
1610}
1611static bool wmi_is_pm_resume_cmd(WMI_CMD_ID cmd_id)
1612{
1613 return false;
1614}
1615#endif
1616
1617/**
Govind Singh6b411b52016-03-06 19:55:02 +05301618 * wmi_unified_cmd_send() - WMI command API
1619 * @wmi_handle: handle to wmi
1620 * @buf: wmi buf
1621 * @len: wmi buffer length
1622 * @cmd_id: wmi command id
1623 *
1624 * Return: 0 on success
1625 */
Govind Singhc458f382016-02-04 18:42:30 +05301626int wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf, uint32_t len,
Govind Singh6b411b52016-03-06 19:55:02 +05301627 WMI_CMD_ID cmd_id)
1628{
1629 HTC_PACKET *pkt;
1630 A_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301631 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301632
1633 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
1634 if (wmi_is_runtime_pm_cmd(cmd_id))
1635 htc_tag = HTC_TX_PACKET_TAG_AUTO_PM;
Govind Singhb53420c2016-03-09 14:32:57 +05301636 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301637 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301638 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301639 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301640 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301641 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301642 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301643 if (wmi_handle->wmi_stopinprogress) {
1644 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1645 "WMI stop in progress\n");
1646 return -EINVAL;
1647 }
Govind Singh6b411b52016-03-06 19:55:02 +05301648
1649 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301650#ifndef WMI_NON_TLV_SUPPORT
1651 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301652 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301653
1654 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301655 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301656 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301657 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301658 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301659 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301660 }
1661 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301662#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301663
Govind Singhb53420c2016-03-09 14:32:57 +05301664 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1665 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301666 "%s, Failed to send cmd %x, no memory",
1667 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301668 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301669 }
1670
Govind Singhb53420c2016-03-09 14:32:57 +05301671 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301672
Govind Singhb53420c2016-03-09 14:32:57 +05301673 qdf_atomic_inc(&wmi_handle->pending_cmds);
1674 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1675 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301676 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301677 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301678 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301679 qdf_atomic_dec(&wmi_handle->pending_cmds);
1680 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301681 "%s: MAX 1024 WMI Pending cmds reached.", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301682 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301683 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301684 }
1685
Govind Singhb53420c2016-03-09 14:32:57 +05301686 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301687 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301688 qdf_atomic_dec(&wmi_handle->pending_cmds);
1689 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301690 "%s, Failed to alloc htc packet %x, no memory",
1691 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301692 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301693 }
1694
1695 SET_HTC_PACKET_INFO_TX(pkt,
1696 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301697 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301698 wmi_handle->wmi_endpoint_id, htc_tag);
1699
1700 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301701#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301702 wma_log_cmd_id(cmd_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301703#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301704
1705#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301706 if (wmi_handle->log_info.wmi_logging_enable) {
1707 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1708 /*Record 16 bytes of WMI cmd data -
1709 * exclude TLV and WMI headers */
1710 if (wmi_handle->log_info.is_management_record(cmd_id)) {
1711 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
1712 ((uint32_t *) qdf_nbuf_data(buf) +
1713 wmi_handle->log_info.buf_offset_command));
1714 } else {
1715 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
1716 ((uint32_t *) qdf_nbuf_data(buf) +
1717 wmi_handle->log_info.buf_offset_command));
1718 }
Govind Singh6b411b52016-03-06 19:55:02 +05301719
Govind Singhecf03cd2016-05-12 12:45:51 +05301720 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1721 }
Govind Singh6b411b52016-03-06 19:55:02 +05301722#endif
1723
1724 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1725
1726 if (A_OK != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301727 qdf_atomic_dec(&wmi_handle->pending_cmds);
1728 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301729 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Govind Singh6b411b52016-03-06 19:55:02 +05301730 }
1731 if (status)
Govind Singhb53420c2016-03-09 14:32:57 +05301732 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301733
Govind Singhb53420c2016-03-09 14:32:57 +05301734 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301735}
1736
1737/**
1738 * wmi_unified_get_event_handler_ix() - gives event handler's index
1739 * @wmi_handle: handle to wmi
1740 * @event_id: wmi event id
1741 *
1742 * Return: event handler's index
1743 */
1744int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301745 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301746{
1747 uint32_t idx = 0;
1748 int32_t invalid_idx = -1;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301749
Govind Singh6b411b52016-03-06 19:55:02 +05301750 for (idx = 0; (idx < wmi_handle->max_event_idx &&
1751 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1752 if (wmi_handle->event_id[idx] == event_id &&
1753 wmi_handle->event_handler[idx] != NULL) {
1754 return idx;
1755 }
1756 }
1757
1758 return invalid_idx;
1759}
1760
1761/**
1762 * wmi_unified_register_event_handler() - register wmi event handler
1763 * @wmi_handle: handle to wmi
1764 * @event_id: wmi event id
1765 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301766 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301767 *
1768 * Return: 0 on success
1769 */
1770int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301771 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301772 wmi_unified_event_handler handler_func,
1773 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301774{
1775 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301776 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301777
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301778#ifdef WMI_TLV_AND_NON_TLV_SUPPORT
1779 if (event_id >= wmi_events_max ||
1780 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1781 qdf_print("%s: Event id %d is unavailable\n",
1782 __func__, event_id);
1783 return QDF_STATUS_E_FAILURE;
1784 }
1785 evt_id = wmi_handle->wmi_events[event_id];
1786#else
1787 evt_id = event_id;
1788#endif
1789 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1790 qdf_print("%s : event handler already registered 0x%x\n",
1791 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301792 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301793 }
1794 if (wmi_handle->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301795 qdf_print("%s : no more event handlers 0x%x\n",
1796 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301797 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301798 }
1799 idx = wmi_handle->max_event_idx;
1800 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301801 wmi_handle->event_id[idx] = evt_id;
Govind Singh813fdac2016-03-12 09:26:52 +05301802 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301803 wmi_handle->ctx[idx] = rx_ctx;
Govind Singh813fdac2016-03-12 09:26:52 +05301804 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301805 wmi_handle->max_event_idx++;
1806
1807 return 0;
1808}
1809
1810/**
1811 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1812 * @wmi_handle: handle to wmi
1813 * @event_id: wmi event id
1814 *
1815 * Return: 0 on success
1816 */
1817int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301818 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301819{
1820 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301821 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301822
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301823#ifdef WMI_TLV_AND_NON_TLV_SUPPORT
1824 if (event_id >= wmi_events_max ||
1825 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1826 qdf_print("%s: Event id %d is unavailable\n",
1827 __func__, event_id);
1828 return QDF_STATUS_E_FAILURE;
1829 }
1830 evt_id = wmi_handle->wmi_events[event_id];
1831#else
1832 evt_id = event_id;
1833#endif
1834
1835 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301836 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301837 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1838 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301839 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301840 }
1841 wmi_handle->event_handler[idx] = NULL;
1842 wmi_handle->event_id[idx] = 0;
1843 --wmi_handle->max_event_idx;
1844 wmi_handle->event_handler[idx] =
1845 wmi_handle->event_handler[wmi_handle->max_event_idx];
1846 wmi_handle->event_id[idx] =
1847 wmi_handle->event_id[wmi_handle->max_event_idx];
1848
1849 return 0;
1850}
1851
1852/**
Govind Singhd52faac2016-03-09 12:03:29 +05301853 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301854 * @wmi_handle: handle to wmi
1855 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301856 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301857 *
Govind Singhd52faac2016-03-09 12:03:29 +05301858 * Event process by below function will be in default caller context.
1859 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301860 *
1861 * Return: none
1862 */
Govind Singhd52faac2016-03-09 12:03:29 +05301863static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1864 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301865{
1866 wmi_buf_t evt_buf;
1867 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1868
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301869#ifdef WMI_NON_TLV_SUPPORT
1870 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1871 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1872#else
Govind Singh5eb51532016-03-09 11:34:12 +05301873 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301874 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301875#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301876
Govind Singh6b411b52016-03-06 19:55:02 +05301877 return;
1878}
1879
1880/**
1881 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1882 * @wmi_handle: handle to wmi
1883 * @htc_packet: pointer to htc packet
1884 *
1885 * Event process by below function will be in worker thread context.
1886 * Use this method for events which are not critical and not
1887 * handled in protocol stack.
1888 *
1889 * Return: none
1890 */
1891static void wmi_process_fw_event_worker_thread_ctx
1892 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1893{
1894 wmi_buf_t evt_buf;
1895 uint32_t id;
1896 uint8_t *data;
1897
1898 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05301899 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
1900 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301901
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301902#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301903 if (wmi_handle->log_info.wmi_logging_enable) {
1904 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1905 /* Exclude 4 bytes of TLV header */
1906 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
1907 wmi_handle->log_info.buf_offset_event));
1908 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1909 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301910#endif
Govind Singhb53420c2016-03-09 14:32:57 +05301911 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1912 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1913 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301914 schedule_work(&wmi_handle->rx_event_work);
1915 return;
1916}
1917
1918/**
Govind Singhd52faac2016-03-09 12:03:29 +05301919 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301920 * @ctx: handle to wmi
1921 * @htc_packet: pointer to htc packet
1922 *
Govind Singh6b411b52016-03-06 19:55:02 +05301923 * Return: none
1924 */
1925void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
1926{
1927 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
1928 wmi_buf_t evt_buf;
1929 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301930 uint32_t idx = 0;
1931 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301932
1933 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05301934 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301935 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301936 if (qdf_unlikely(idx == A_ERROR)) {
1937 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05301938 ("%s :event handler is not registered: event id 0x%x\n",
1939 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301940 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301941 return;
1942 }
Govind Singh813fdac2016-03-12 09:26:52 +05301943 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301944 exec_ctx = wmi_handle->ctx[idx];
Govind Singh813fdac2016-03-12 09:26:52 +05301945 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301946
1947 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301948 wmi_process_fw_event_worker_thread_ctx
1949 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301950 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1951 wmi_process_fw_event_default_ctx
1952 (wmi_handle, htc_packet, exec_ctx);
1953 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05301954 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
1955 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301956 }
Govind Singhd52faac2016-03-09 12:03:29 +05301957
Govind Singh6b411b52016-03-06 19:55:02 +05301958}
1959
1960/**
1961 * wmi_process_fw_event() - process any fw event
1962 * @wmi_handle: wmi handle
1963 * @evt_buf: fw event buffer
1964 *
Govind Singhd52faac2016-03-09 12:03:29 +05301965 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301966 *
1967 * Return: none
1968 */
1969void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1970{
1971 __wmi_control_rx(wmi_handle, evt_buf);
1972}
1973
1974/**
1975 * __wmi_control_rx() - process serialize wmi event callback
1976 * @wmi_handle: wmi handle
1977 * @evt_buf: fw event buffer
1978 *
1979 * Return: none
1980 */
1981void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1982{
1983 uint32_t id;
1984 uint8_t *data;
1985 uint32_t len;
1986 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301987#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301988 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301989#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301990 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301991
Govind Singhb53420c2016-03-09 14:32:57 +05301992 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301993
Govind Singhb53420c2016-03-09 14:32:57 +05301994 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05301995 goto end;
1996
Govind Singhb53420c2016-03-09 14:32:57 +05301997 data = qdf_nbuf_data(evt_buf);
1998 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301999
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302000#ifndef WMI_NON_TLV_SUPPORT
2001 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2002 /* Validate and pad(if necessary) the TLVs */
2003 tlv_ok_status =
2004 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302005 data, len, id,
2006 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302007 if (tlv_ok_status != 0) {
2008 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2009 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2010 __func__, id, tlv_ok_status);
2011 goto end;
2012 }
Govind Singh6b411b52016-03-06 19:55:02 +05302013 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302014#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302015
Govind Singhd52faac2016-03-09 12:03:29 +05302016 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2017 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302018 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302019 "%s : event handler is not registered: event id 0x%x\n",
2020 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302021 goto end;
2022 }
Govind Singhd52faac2016-03-09 12:03:29 +05302023#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302024 if (wmi_handle->log_info.wmi_logging_enable) {
2025 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2026 /* Exclude 4 bytes of TLV header */
2027 if (wmi_handle->log_info.is_management_record(id)) {
2028 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2029 + wmi_handle->log_info.buf_offset_event));
2030 } else {
2031 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2032 wmi_handle->log_info.buf_offset_event));
2033 }
2034 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302035 }
Govind Singhd52faac2016-03-09 12:03:29 +05302036#endif
2037 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302038 if (wmi_handle->target_type == WMI_TLV_TARGET)
2039 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2040 wmi_cmd_struct_ptr, len);
2041 else
2042 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2043 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302044
Govind Singh6b411b52016-03-06 19:55:02 +05302045end:
Govind Singhd52faac2016-03-09 12:03:29 +05302046 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302047#ifndef WMI_NON_TLV_SUPPORT
2048 if (wmi_handle->target_type == WMI_TLV_TARGET)
2049 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2050#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302051 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302052
Govind Singh6b411b52016-03-06 19:55:02 +05302053}
2054
2055/**
2056 * wmi_rx_event_work() - process rx event in rx work queue context
2057 * @work: rx work queue struct
2058 *
2059 * This function process any fw event to serialize it through rx worker thread.
2060 *
2061 * Return: none
2062 */
2063void wmi_rx_event_work(struct work_struct *work)
2064{
2065 struct wmi_unified *wmi = container_of(work, struct wmi_unified,
Govind Singhecf03cd2016-05-12 12:45:51 +05302066 rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302067 wmi_buf_t buf;
2068
Govind Singhb53420c2016-03-09 14:32:57 +05302069 qdf_spin_lock_bh(&wmi->eventq_lock);
2070 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2071 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302072 while (buf) {
2073 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302074 qdf_spin_lock_bh(&wmi->eventq_lock);
2075 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2076 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302077 }
2078}
2079
Govind Singh6b411b52016-03-06 19:55:02 +05302080#ifdef FEATURE_RUNTIME_PM
2081/**
2082 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2083 * @wmi_handle: wmi context
2084 */
Govind Singhd52faac2016-03-09 12:03:29 +05302085static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302086{
Govind Singhb53420c2016-03-09 14:32:57 +05302087 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302088}
Govind Singhd52faac2016-03-09 12:03:29 +05302089
2090/**
2091 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2092 * @wmi_handle: wmi context
2093 * @val: runtime pm progress flag
2094 */
2095void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2096{
Govind Singhb53420c2016-03-09 14:32:57 +05302097 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302098}
2099
2100/**
2101 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2102 * @wmi_handle: wmi context
2103 */
2104inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2105{
Govind Singhb53420c2016-03-09 14:32:57 +05302106 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302107}
Govind Singh6b411b52016-03-06 19:55:02 +05302108#else
Govind Singhd52faac2016-03-09 12:03:29 +05302109static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302110{
2111}
2112#endif
2113
2114/**
2115 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302116 * @scn_handle: handle to SCN
2117 * @osdev: OS device context
2118 * @target_type: TLV or not-TLV based target
2119 * @use_cookie: cookie based allocation enabled/disabled
2120 * @ops: umac rx callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302121 *
2122 * @Return: wmi handle.
2123 */
Govind Singhc458f382016-02-04 18:42:30 +05302124void *wmi_unified_attach(void *scn_handle,
2125 osdev_t osdev, enum wmi_target_type target_type,
Govind Singh5eb51532016-03-09 11:34:12 +05302126 bool use_cookie, struct wmi_rx_ops *rx_ops)
Govind Singh6b411b52016-03-06 19:55:02 +05302127{
2128 struct wmi_unified *wmi_handle;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302129
2130#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302131 wmi_handle =
2132 (struct wmi_unified *)os_malloc(NULL,
2133 sizeof(struct wmi_unified),
2134 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302135#else
2136 wmi_handle =
2137 (struct wmi_unified *) qdf_mem_malloc(
2138 sizeof(struct wmi_unified));
2139#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302140 if (wmi_handle == NULL) {
Govind Singhb53420c2016-03-09 14:32:57 +05302141 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302142 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302143 return NULL;
2144 }
2145 OS_MEMZERO(wmi_handle, sizeof(struct wmi_unified));
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302146 wmi_handle->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302147 qdf_atomic_init(&wmi_handle->pending_cmds);
2148 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302149 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302150 qdf_spinlock_create(&wmi_handle->eventq_lock);
2151 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302152 INIT_WORK(&wmi_handle->rx_event_work, wmi_rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302153#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302154 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2155 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2156 wmi_debugfs_init(wmi_handle);
2157 }
Govind Singh6b411b52016-03-06 19:55:02 +05302158#endif
Govind Singhc458f382016-02-04 18:42:30 +05302159 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302160 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2161 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302162 wmi_handle->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302163 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302164 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302165 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302166 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302167 /* Assign target cookie capablity */
2168 wmi_handle->use_cookie = use_cookie;
2169 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302170 wmi_handle->wmi_stopinprogress = 0;
Govind Singh813fdac2016-03-12 09:26:52 +05302171 qdf_spinlock_create(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302172
2173 return wmi_handle;
2174}
2175
2176/**
2177 * wmi_unified_detach() - detach for unified WMI
2178 *
2179 * @wmi_handle : handle to wmi.
2180 *
2181 * @Return: none.
2182 */
2183void wmi_unified_detach(struct wmi_unified *wmi_handle)
2184{
2185 wmi_buf_t buf;
2186
Govind Singhb53420c2016-03-09 14:32:57 +05302187 cancel_work_sync(&wmi_handle->rx_event_work);
Rajeev Kumarae91c402016-05-25 16:07:23 -07002188
2189 wmi_debugfs_remove(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
2190 wmi_handle->log_info.wmi_instance_id);
2191
Govind Singhb53420c2016-03-09 14:32:57 +05302192 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2193 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302194 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302195 qdf_nbuf_free(buf);
2196 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302197 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302198
2199#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302200 wmi_log_buffer_free(wmi_handle);
2201#endif
2202
Govind Singhb53420c2016-03-09 14:32:57 +05302203 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh813fdac2016-03-12 09:26:52 +05302204 qdf_spinlock_destroy(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302205 if (wmi_handle != NULL) {
2206 OS_FREE(wmi_handle);
2207 wmi_handle = NULL;
2208 }
2209}
2210
2211/**
2212 * wmi_unified_remove_work() - detach for WMI work
2213 * @wmi_handle: handle to WMI
2214 *
2215 * A function that does not fully detach WMI, but just remove work
2216 * queue items associated with it. This is used to make sure that
2217 * before any other processing code that may destroy related contexts
2218 * (HTC, etc), work queue processing on WMI has already been stopped.
2219 *
2220 * Return: None
2221 */
2222void
2223wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2224{
2225 wmi_buf_t buf;
2226
Govind Singhb53420c2016-03-09 14:32:57 +05302227 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302228 "Enter: %s", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05302229 cancel_work_sync(&wmi_handle->rx_event_work);
2230 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2231 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302232 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302233 qdf_nbuf_free(buf);
2234 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302235 }
Govind Singhb53420c2016-03-09 14:32:57 +05302236 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2237 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302238 "Done: %s", __func__);
2239}
2240
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302241/**
2242 * wmi_htc_tx_complete() - Process htc tx completion
2243 *
2244 * @ctx: handle to wmi
2245 * @htc_packet: pointer to htc packet
2246 *
2247 * @Return: none.
2248 */
Govind Singh6b411b52016-03-06 19:55:02 +05302249void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
2250{
2251 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
2252 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302253
Govind Singh6b411b52016-03-06 19:55:02 +05302254#ifdef WMI_INTERFACE_EVENT_LOGGING
2255 uint32_t cmd_id;
2256#endif
2257
2258 ASSERT(wmi_cmd_buf);
2259#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302260 if (wmi_handle->log_info.wmi_logging_enable) {
2261 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2262 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302263
2264#ifdef QCA_WIFI_3_0_EMU
Govind Singhb53420c2016-03-09 14:32:57 +05302265 qdf_print
Govind Singh6b411b52016-03-06 19:55:02 +05302266 ("\nSent WMI command:%s command_id:0x%x over dma and recieved tx complete interupt\n",
Govind Singhecf03cd2016-05-12 12:45:51 +05302267 wmi_id_to_name(cmd_id), cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302268#endif
2269
Govind Singhecf03cd2016-05-12 12:45:51 +05302270 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302271 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302272 - exclude TLV and WMI headers */
2273 if (wmi_handle->log_info.is_management_record(cmd_id)) {
2274 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2275 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2276 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302277 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302278 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2279 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2280 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302281 }
2282
Govind Singhecf03cd2016-05-12 12:45:51 +05302283 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2284 }
Govind Singh6b411b52016-03-06 19:55:02 +05302285#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302286 qdf_nbuf_free(wmi_cmd_buf);
2287 qdf_mem_free(htc_pkt);
2288 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302289}
2290
2291/**
2292 * wmi_get_host_credits() - WMI API to get updated host_credits
2293 *
2294 * @wmi_handle: handle to WMI.
2295 *
2296 * @Return: updated host_credits.
2297 */
2298int
2299wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2300 void *htc_handle)
2301{
2302
2303 int status;
2304 HTC_SERVICE_CONNECT_RESP response;
2305 HTC_SERVICE_CONNECT_REQ connect;
2306
2307 OS_MEMZERO(&connect, sizeof(connect));
2308 OS_MEMZERO(&response, sizeof(response));
2309
2310 /* meta data is unused for now */
2311 connect.pMetaData = NULL;
2312 connect.MetaDataLength = 0;
2313 /* these fields are the same for all service endpoints */
2314 connect.EpCallbacks.pContext = wmi_handle;
2315 connect.EpCallbacks.EpTxCompleteMultiple =
2316 NULL /* Control path completion ar6000_tx_complete */;
2317 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2318 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2319 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2320 connect.EpCallbacks.EpTxComplete =
2321 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2322
2323 /* connect to control service */
2324 connect.service_id = WMI_CONTROL_SVC;
2325 status = htc_connect_service(htc_handle, &connect,
2326 &response);
2327
2328 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302329 qdf_print
Govind Singh6b411b52016-03-06 19:55:02 +05302330 ("Failed to connect to WMI CONTROL service status:%d \n",
2331 status);
2332 return status;
2333 }
2334 wmi_handle->wmi_endpoint_id = response.Endpoint;
2335 wmi_handle->htc_handle = htc_handle;
2336 wmi_handle->max_msg_len = response.MaxMsgLength;
2337
2338 return EOK;
2339}
2340
2341/**
2342 * wmi_get_host_credits() - WMI API to get updated host_credits
2343 *
2344 * @wmi_handle: handle to WMI.
2345 *
2346 * @Return: updated host_credits.
2347 */
2348int wmi_get_host_credits(wmi_unified_t wmi_handle)
2349{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302350 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302351
2352 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2353 &host_credits);
2354 return host_credits;
2355}
2356
2357/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302358 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2359 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302360 *
2361 * @wmi_handle: handle to WMI.
2362 *
2363 * @Return: Pending Commands in the HTC queue.
2364 */
2365int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2366{
Govind Singhb53420c2016-03-09 14:32:57 +05302367 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302368}
2369
2370/**
2371 * wmi_set_target_suspend() - WMI API to set target suspend state
2372 *
2373 * @wmi_handle: handle to WMI.
2374 * @val: suspend state boolean.
2375 *
2376 * @Return: none.
2377 */
2378void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2379{
Govind Singhb53420c2016-03-09 14:32:57 +05302380 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302381}
2382
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302383#ifdef WMI_NON_TLV_SUPPORT
2384/**
2385 * API to flush all the previous packets associated with the wmi endpoint
2386 *
2387 * @param wmi_handle : handle to WMI.
2388 */
2389void
2390wmi_flush_endpoint(wmi_unified_t wmi_handle)
2391{
2392 htc_flush_endpoint(wmi_handle->htc_handle,
2393 wmi_handle->wmi_endpoint_id, 0);
2394}
2395
2396/**
2397 * generic function to block unified WMI command
2398 * @param wmi_handle : handle to WMI.
2399 * @return 0 on success and -ve on failure.
2400 */
2401int
2402wmi_stop(wmi_unified_t wmi_handle)
2403{
2404 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2405 "WMI Stop\n");
2406 wmi_handle->wmi_stopinprogress = 1;
2407 return 0;
2408}
2409#endif