blob: c834978b6c15498cb8706bf52ad71a3299f86b36 [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
2 * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*
29 * Host WMI unified implementation
30 */
31#include "athdefs.h"
32#include "osapi_linux.h"
33#include "a_types.h"
34#include "a_debug.h"
35#include "ol_if_athvar.h"
36#include "ol_defines.h"
Govind Singh6b411b52016-03-06 19:55:02 +053037#include "htc_api.h"
38#include "htc_api.h"
39#include "dbglog_host.h"
Govind Singh6b411b52016-03-06 19:55:02 +053040#include "wmi_unified_priv.h"
Govind Singh5eb51532016-03-09 11:34:12 +053041#include "wmi_unified_param.h"
Govind Singh6b411b52016-03-06 19:55:02 +053042
Govind Singhecf03cd2016-05-12 12:45:51 +053043#include <linux/debugfs.h>
44
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053045/* This check for CONFIG_WIN temporary added due to redeclaration compilation
46error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
47which gets included here through ol_if_athvar.h. Eventually it is expected that
48wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
49WMI_CMD_HDR to be defined here. */
50#ifdef CONFIG_WIN
51/* Copied from wmi.h */
52#undef MS
53#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
54#undef SM
55#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
56#undef WO
57#define WO(_f) ((_f##_OFFSET) >> 2)
58
59#undef GET_FIELD
60#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
61#undef SET_FIELD
62#define SET_FIELD(_addr, _f, _val) \
63 (*((A_UINT32 *)(_addr) + WO(_f)) = \
64 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
65
66#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
67 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
68
69#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
70 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
71
72#define WMI_EP_APASS 0x0
73#define WMI_EP_LPASS 0x1
74#define WMI_EP_SENSOR 0x2
75
76/*
77 * * Control Path
78 * */
79typedef PREPACK struct {
80 A_UINT32 commandId:24,
81 reserved:2, /* used for WMI endpoint ID */
82 plt_priv:6; /* platform private */
83} POSTPACK WMI_CMD_HDR; /* used for commands and events */
84
85#define WMI_CMD_HDR_COMMANDID_LSB 0
86#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
87#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
88#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
89#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
90#define WMI_CMD_HDR_PLT_PRIV_LSB 24
91#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
92#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
93/* end of copy wmi.h */
94#endif /* CONFIG_WIN */
95
Manikandan Mohan5826ae92016-06-08 16:29:39 -070096#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
97/* TODO Cleanup this backported function */
98int qcacld_bp_seq_printf(struct seq_file *m, const char *f, ...)
99{
100 va_list args;
101
102 va_start(args, f);
103 seq_printf(m, f, args);
104 va_end(args);
105
106 return m->count;
107}
108
109#define seq_printf(m, fmt, ...) qcacld_bp_seq_printf((m), fmt, ##__VA_ARGS__)
110#endif
111
Govind Singh6b411b52016-03-06 19:55:02 +0530112#define WMI_MIN_HEAD_ROOM 64
113
114#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +0530115#ifndef MAX_WMI_INSTANCES
116#ifdef CONFIG_MCL
117#define MAX_WMI_INSTANCES 1
118#else
119#define MAX_WMI_INSTANCES 3
120#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530121#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530122#endif
123
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530124#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530125/* WMI commands */
126uint32_t g_wmi_command_buf_idx = 0;
127struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
128
129/* WMI commands TX completed */
130uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
131struct wmi_command_debug
132 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
133
134/* WMI events when processed */
135uint32_t g_wmi_event_buf_idx = 0;
136struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
137
138/* WMI events when queued */
139uint32_t g_wmi_rx_event_buf_idx = 0;
140struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530141#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530142
Govind Singhecf03cd2016-05-12 12:45:51 +0530143#define WMI_COMMAND_RECORD(h, a, b) { \
144 if (wmi_log_max_entry <= \
145 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
146 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
147 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
148 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
149 .command = a; \
150 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
151 wmi_command_log_buf_info.buf) \
152 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
153 b, wmi_record_max_length); \
154 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
155 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
156 time = qdf_get_log_timestamp(); \
157 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
158 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530159}
160
Govind Singhecf03cd2016-05-12 12:45:51 +0530161#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
162 if (wmi_log_max_entry <= \
163 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530164 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
165 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530166 ((struct wmi_command_debug *)h->log_info. \
167 wmi_command_tx_cmp_log_buf_info.buf) \
168 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
169 p_buf_tail_idx)]. \
170 command = a; \
171 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
172 wmi_command_tx_cmp_log_buf_info.buf) \
173 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
174 p_buf_tail_idx)]. \
175 data, b, wmi_record_max_length); \
176 ((struct wmi_command_debug *)h->log_info. \
177 wmi_command_tx_cmp_log_buf_info.buf) \
178 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
179 p_buf_tail_idx)]. \
180 time = qdf_get_log_timestamp(); \
181 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
182 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530183}
184
Govind Singhecf03cd2016-05-12 12:45:51 +0530185#define WMI_EVENT_RECORD(h, a, b) { \
186 if (wmi_log_max_entry <= \
187 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
188 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
189 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
190 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
191 event = a; \
192 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
193 wmi_event_log_buf_info.buf) \
194 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
195 wmi_record_max_length); \
196 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
197 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530198 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530199 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
200 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530201}
202
Govind Singhecf03cd2016-05-12 12:45:51 +0530203#define WMI_RX_EVENT_RECORD(h, a, b) { \
204 if (wmi_log_max_entry <= \
205 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
206 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
207 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
208 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
209 event = a; \
210 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
211 wmi_rx_event_log_buf_info.buf) \
212 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
213 data, b, wmi_record_max_length); \
214 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
215 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
216 time = qdf_get_log_timestamp(); \
217 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
218 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530219}
Govind Singh6b411b52016-03-06 19:55:02 +0530220
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530221#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530222uint32_t g_wmi_mgmt_command_buf_idx = 0;
223struct
224wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
225
226/* wmi_mgmt commands TX completed */
227uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
228struct wmi_command_debug
229wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
230
231/* wmi_mgmt events when processed */
232uint32_t g_wmi_mgmt_event_buf_idx = 0;
233struct wmi_event_debug
234wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530235#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530236
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530237#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
238 if (wmi_mgmt_log_max_entry <= \
239 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
240 *(h->log_info.wmi_mgmt_command_log_buf_info. \
241 p_buf_tail_idx) = 0; \
242 ((struct wmi_command_debug *)h->log_info. \
243 wmi_mgmt_command_log_buf_info.buf) \
244 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
245 command = a; \
246 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
247 wmi_mgmt_command_log_buf_info.buf) \
248 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
249 data, b, \
250 wmi_record_max_length); \
251 ((struct wmi_command_debug *)h->log_info. \
252 wmi_mgmt_command_log_buf_info.buf) \
253 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
254 time = qdf_get_log_timestamp(); \
255 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
256 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530257}
258
Govind Singhecf03cd2016-05-12 12:45:51 +0530259#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
260 if (wmi_mgmt_log_max_entry <= \
261 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
262 p_buf_tail_idx)) \
263 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
264 p_buf_tail_idx) = 0; \
265 ((struct wmi_command_debug *)h->log_info. \
266 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
267 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
268 p_buf_tail_idx)].command = a; \
269 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
270 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
271 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
272 p_buf_tail_idx)].data, b, \
273 wmi_record_max_length); \
274 ((struct wmi_command_debug *)h->log_info. \
275 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
276 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
277 p_buf_tail_idx)].time = \
278 qdf_get_log_timestamp(); \
279 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
280 p_buf_tail_idx))++; \
281 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530282}
283
Govind Singhecf03cd2016-05-12 12:45:51 +0530284#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
285 if (wmi_mgmt_log_max_entry <= \
286 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
287 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
288 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
289 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
290 .event = a; \
291 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
292 wmi_mgmt_event_log_buf_info.buf) \
293 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
294 data, b, wmi_record_max_length); \
295 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
296 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
297 time = qdf_get_log_timestamp(); \
298 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
299 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530300}
301
Govind Singhecf03cd2016-05-12 12:45:51 +0530302/* These are defined to made it as module param, which can be configured */
303uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
304uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
305uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
306uint32_t wmi_display_size = 100;
307
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530308static uint8_t *wmi_id_to_name(uint32_t wmi_command);
Govind Singhecf03cd2016-05-12 12:45:51 +0530309
310/**
311 * wmi_log_init() - Initialize WMI event logging
312 * @wmi_handle: WMI handle.
313 *
314 * Return: Initialization status
315 */
316#ifdef CONFIG_MCL
317static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
318{
319 struct wmi_log_buf_t *cmd_log_buf =
320 &wmi_handle->log_info.wmi_command_log_buf_info;
321 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
322 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
323
324 struct wmi_log_buf_t *event_log_buf =
325 &wmi_handle->log_info.wmi_event_log_buf_info;
326 struct wmi_log_buf_t *rx_event_log_buf =
327 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
328
329 struct wmi_log_buf_t *mgmt_cmd_log_buf =
330 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
331 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
332 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
333 struct wmi_log_buf_t *mgmt_event_log_buf =
334 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
335
336 /* WMI commands */
337 cmd_log_buf->length = 0;
338 cmd_log_buf->buf_tail_idx = 0;
339 cmd_log_buf->buf = wmi_command_log_buffer;
340 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
341
342 /* WMI commands TX completed */
343 cmd_tx_cmpl_log_buf->length = 0;
344 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
345 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
346 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
347
348 /* WMI events when processed */
349 event_log_buf->length = 0;
350 event_log_buf->buf_tail_idx = 0;
351 event_log_buf->buf = wmi_event_log_buffer;
352 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
353
354 /* WMI events when queued */
355 rx_event_log_buf->length = 0;
356 rx_event_log_buf->buf_tail_idx = 0;
357 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
358 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
359
360 /* WMI Management commands */
361 mgmt_cmd_log_buf->length = 0;
362 mgmt_cmd_log_buf->buf_tail_idx = 0;
363 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
364 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
365
366 /* WMI Management commands Tx completed*/
367 mgmt_cmd_tx_cmp_log_buf->length = 0;
368 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
369 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
370 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
371 &g_wmi_mgmt_command_tx_cmp_buf_idx;
372
373 /* WMI Management events when processed*/
374 mgmt_event_log_buf->length = 0;
375 mgmt_event_log_buf->buf_tail_idx = 0;
376 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
377 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
378
379 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
380 wmi_handle->log_info.wmi_logging_enable = 1;
381
382 return QDF_STATUS_SUCCESS;
383}
384#else
385static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
386{
387 struct wmi_log_buf_t *cmd_log_buf =
388 &wmi_handle->log_info.wmi_command_log_buf_info;
389 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
390 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
391
392 struct wmi_log_buf_t *event_log_buf =
393 &wmi_handle->log_info.wmi_event_log_buf_info;
394 struct wmi_log_buf_t *rx_event_log_buf =
395 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
396
397 struct wmi_log_buf_t *mgmt_cmd_log_buf =
398 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
399 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
400 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
401 struct wmi_log_buf_t *mgmt_event_log_buf =
402 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
403
404 wmi_handle->log_info.wmi_logging_enable = 0;
405
406 /* WMI commands */
407 cmd_log_buf->length = 0;
408 cmd_log_buf->buf_tail_idx = 0;
409 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
410 wmi_log_max_entry * sizeof(struct wmi_command_debug));
411
412 if (!cmd_log_buf->buf) {
413 qdf_print("no memory for WMI command log buffer..\n");
414 return QDF_STATUS_E_NOMEM;
415 }
416 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
417
418 /* WMI commands TX completed */
419 cmd_tx_cmpl_log_buf->length = 0;
420 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
421 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
422 wmi_log_max_entry * sizeof(struct wmi_command_debug));
423
424 if (!cmd_tx_cmpl_log_buf->buf) {
425 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
426 return QDF_STATUS_E_NOMEM;
427 }
428 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
429 &cmd_tx_cmpl_log_buf->buf_tail_idx;
430
431 /* WMI events when processed */
432 event_log_buf->length = 0;
433 event_log_buf->buf_tail_idx = 0;
434 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
435 wmi_log_max_entry * sizeof(struct wmi_event_debug));
436
437 if (!event_log_buf->buf) {
438 qdf_print("no memory for WMI Event log buffer..\n");
439 return QDF_STATUS_E_NOMEM;
440 }
441 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
442
443 /* WMI events when queued */
444 rx_event_log_buf->length = 0;
445 rx_event_log_buf->buf_tail_idx = 0;
446 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
447 wmi_log_max_entry * sizeof(struct wmi_event_debug));
448
449 if (!rx_event_log_buf->buf) {
450 qdf_print("no memory for WMI Event Rx log buffer..\n");
451 return QDF_STATUS_E_NOMEM;
452 }
453 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
454
455 /* WMI Management commands */
456 mgmt_cmd_log_buf->length = 0;
457 mgmt_cmd_log_buf->buf_tail_idx = 0;
458 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
459 wmi_mgmt_log_max_entry *
460 sizeof(struct wmi_command_debug));
461
462 if (!mgmt_cmd_log_buf->buf) {
463 qdf_print("no memory for WMI Management Command log buffer..\n");
464 return QDF_STATUS_E_NOMEM;
465 }
466 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
467
468 /* WMI Management commands Tx completed*/
469 mgmt_cmd_tx_cmp_log_buf->length = 0;
470 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
471 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
472 qdf_mem_malloc(
473 wmi_mgmt_log_max_entry *
474 sizeof(struct wmi_command_debug));
475
476 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
477 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
478 return QDF_STATUS_E_NOMEM;
479 }
480 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
481 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
482
483 /* WMI Management events when processed*/
484 mgmt_event_log_buf->length = 0;
485 mgmt_event_log_buf->buf_tail_idx = 0;
486
487 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
488 wmi_mgmt_log_max_entry *
489 sizeof(struct wmi_event_debug));
490
491 if (!mgmt_event_log_buf->buf) {
492 qdf_print("no memory for WMI Management Event log buffer..\n");
493 return QDF_STATUS_E_NOMEM;
494 }
495 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
496
497 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
498 wmi_handle->log_info.wmi_logging_enable = 1;
499
500 return QDF_STATUS_SUCCESS;
501}
502#endif
503
504/**
505 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
506 * event logging
507 * @wmi_handle: WMI handle.
508 *
509 * Return: None
510 */
511#ifndef CONFIG_MCL
512static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
513{
514 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
515 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
516 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
517 qdf_mem_free(
518 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
519 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
520 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
521 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
522 qdf_mem_free(
523 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
524 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
525 qdf_mem_free(
526 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
527 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
528 qdf_mem_free(
529 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
530 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
531 qdf_mem_free(
532 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
533 wmi_handle->log_info.wmi_logging_enable = 0;
534 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
535}
536#else
537static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
538{
539 /* Do Nothing */
540}
541#endif
542
543#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530544const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530545#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530546const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530547#endif
548
549/* debugfs routines*/
550
551/**
552 * debug_wmi_##func_base##_show() - debugfs functions to display content of
553 * command and event buffers. Macro uses max buffer length to display
554 * buffer when it is wraparound.
555 *
556 * @m: debugfs handler to access wmi_handle
557 * @v: Variable arguments (not used)
558 *
559 * Return: Length of characters printed
560 */
561#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
562 static int debug_wmi_##func_base##_show(struct seq_file *m, \
563 void *v) \
564 { \
565 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
566 struct wmi_log_buf_t *wmi_log = \
567 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
568 int pos, nread, outlen; \
569 int i; \
570 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530571 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
572 if (!wmi_log->length) { \
573 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Govind Singhecf03cd2016-05-12 12:45:51 +0530574 return seq_printf(m, \
575 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530576 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530577 \
578 if (wmi_log->length <= wmi_ring_size) \
579 nread = wmi_log->length; \
580 else \
581 nread = wmi_ring_size; \
582 \
583 if (*(wmi_log->p_buf_tail_idx) == 0) \
584 /* tail can be 0 after wrap-around */ \
585 pos = wmi_ring_size - 1; \
586 else \
587 pos = *(wmi_log->p_buf_tail_idx) - 1; \
588 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530589 outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
590 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530591 while (nread--) { \
592 struct wmi_command_debug *wmi_record; \
593 \
594 wmi_record = (struct wmi_command_debug *) \
595 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
596 outlen += seq_printf(m, "CMD ID = %x\n", \
597 (wmi_record->command)); \
598 outlen += seq_printf(m, "CMD = "); \
599 for (i = 0; i < (wmi_record_max_length/ \
600 sizeof(uint32_t)); i++) \
601 outlen += seq_printf(m, "%x ", \
602 wmi_record->data[i]); \
603 outlen += seq_printf(m, "\n"); \
604 \
605 if (pos == 0) \
606 pos = wmi_ring_size - 1; \
607 else \
608 pos--; \
609 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530610 \
611 return outlen; \
612 } \
613
614#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
615 static int debug_wmi_##func_base##_show(struct seq_file *m, \
616 void *v) \
617 { \
618 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
619 struct wmi_log_buf_t *wmi_log = \
620 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
621 int pos, nread, outlen; \
622 int i; \
623 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530624 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
625 if (!wmi_log->length) { \
626 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Govind Singhecf03cd2016-05-12 12:45:51 +0530627 return seq_printf(m, \
628 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530629 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530630 \
631 if (wmi_log->length <= wmi_ring_size) \
632 nread = wmi_log->length; \
633 else \
634 nread = wmi_ring_size; \
635 \
636 if (*(wmi_log->p_buf_tail_idx) == 0) \
637 /* tail can be 0 after wrap-around */ \
638 pos = wmi_ring_size - 1; \
639 else \
640 pos = *(wmi_log->p_buf_tail_idx) - 1; \
641 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530642 outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
643 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530644 while (nread--) { \
645 struct wmi_event_debug *wmi_record; \
646 \
647 wmi_record = (struct wmi_event_debug *) \
648 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
649 outlen += seq_printf(m, "Event ID = %x\n", \
650 (wmi_record->event)); \
651 outlen += seq_printf(m, "CMD = "); \
652 for (i = 0; i < (wmi_record_max_length/ \
653 sizeof(uint32_t)); i++) \
654 outlen += seq_printf(m, "%x ", \
655 wmi_record->data[i]); \
656 outlen += seq_printf(m, "\n"); \
657 \
658 if (pos == 0) \
659 pos = wmi_ring_size - 1; \
660 else \
661 pos--; \
662 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530663 \
664 return outlen; \
665 }
666
667GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
668GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
669GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
670GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
671GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
672GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
673 wmi_display_size);
674GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
675
676/**
677 * debug_wmi_enable_show() - debugfs functions to display enable state of
678 * wmi logging feature.
679 *
680 * @m: debugfs handler to access wmi_handle
681 * @v: Variable arguments (not used)
682 *
683 * Return: always 1
684 */
685static int debug_wmi_enable_show(struct seq_file *m, void *v)
686{
687 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
688
689 return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
690
691}
692
693/**
694 * debug_wmi_log_size_show() - debugfs functions to display configured size of
695 * wmi logging command/event buffer and management command/event buffer.
696 *
697 * @m: debugfs handler to access wmi_handle
698 * @v: Variable arguments (not used)
699 *
700 * Return: Length of characters printed
701 */
702static int debug_wmi_log_size_show(struct seq_file *m, void *v)
703{
704
705 seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
706 return seq_printf(m, "WMI management command/events log max size:%d\n",
707 wmi_mgmt_log_max_entry);
708}
709
710/**
711 * debug_wmi_##func_base##_write() - debugfs functions to clear
712 * wmi logging command/event buffer and management command/event buffer.
713 *
714 * @file: file handler to access wmi_handle
715 * @buf: received data buffer
716 * @count: length of received buffer
717 * @ppos: Not used
718 *
719 * Return: count
720 */
721#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
722 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
723 const char __user *buf, \
724 size_t count, loff_t *ppos) \
725 { \
726 int k, ret; \
727 wmi_unified_t wmi_handle = file->private_data; \
728 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
729 wmi_##func_base##_buf_info; \
730 \
731 ret = sscanf(buf, "%d", &k); \
732 if ((ret != 1) || (k != 0)) { \
733 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
734 return -EINVAL; \
735 } \
736 \
737 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
738 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
739 sizeof(struct wmi_record_type)); \
740 wmi_log->length = 0; \
741 *(wmi_log->p_buf_tail_idx) = 0; \
742 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
743 \
744 return count; \
745 }
746
747GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
748 wmi_command_debug);
749GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
750 wmi_command_debug);
751GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
752 wmi_event_debug);
753GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
754 wmi_event_debug);
755GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
756 wmi_command_debug);
757GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
758 wmi_mgmt_log_max_entry, wmi_command_debug);
759GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
760 wmi_event_debug);
761
762/**
763 * debug_wmi_enable_write() - debugfs functions to enable/disable
764 * wmi logging feature.
765 *
766 * @file: file handler to access wmi_handle
767 * @buf: received data buffer
768 * @count: length of received buffer
769 * @ppos: Not used
770 *
771 * Return: count
772 */
773static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
774 size_t count, loff_t *ppos)
775{
776 wmi_unified_t wmi_handle = file->private_data;
777 int k, ret;
778
779 ret = sscanf(buf, "%d", &k);
780 if ((ret != 1) || ((k != 0) && (k != 1)))
781 return -EINVAL;
782
783 wmi_handle->log_info.wmi_logging_enable = k;
784 return count;
785}
786
787/**
788 * debug_wmi_log_size_write() - reserved.
789 *
790 * @file: file handler to access wmi_handle
791 * @buf: received data buffer
792 * @count: length of received buffer
793 * @ppos: Not used
794 *
795 * Return: count
796 */
797static ssize_t debug_wmi_log_size_write(struct file *file,
798 const char __user *buf, size_t count, loff_t *ppos)
799{
800 return -EINVAL;
801}
802
803/* Structure to maintain debug information */
804struct wmi_debugfs_info {
805 const char *name;
806 struct dentry *de[MAX_WMI_INSTANCES];
807 const struct file_operations *ops;
808};
809
810#define DEBUG_FOO(func_base) { .name = #func_base, \
811 .ops = &debug_##func_base##_ops }
812
813/**
814 * debug_##func_base##_open() - Open debugfs entry for respective command
815 * and event buffer.
816 *
817 * @inode: node for debug dir entry
818 * @file: file handler
819 *
820 * Return: open status
821 */
822#define GENERATE_DEBUG_STRUCTS(func_base) \
823 static int debug_##func_base##_open(struct inode *inode, \
824 struct file *file) \
825 { \
826 return single_open(file, debug_##func_base##_show, \
827 inode->i_private); \
828 } \
829 \
830 \
831 static struct file_operations debug_##func_base##_ops = { \
832 .open = debug_##func_base##_open, \
833 .read = seq_read, \
834 .llseek = seq_lseek, \
835 .write = debug_##func_base##_write, \
836 .release = single_release, \
837 };
838
839GENERATE_DEBUG_STRUCTS(wmi_command_log);
840GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
841GENERATE_DEBUG_STRUCTS(wmi_event_log);
842GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
843GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
844GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
845GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
846GENERATE_DEBUG_STRUCTS(wmi_enable);
847GENERATE_DEBUG_STRUCTS(wmi_log_size);
848
849struct wmi_debugfs_info wmi_debugfs_infos[] = {
850 DEBUG_FOO(wmi_command_log),
851 DEBUG_FOO(wmi_command_tx_cmp_log),
852 DEBUG_FOO(wmi_event_log),
853 DEBUG_FOO(wmi_rx_event_log),
854 DEBUG_FOO(wmi_mgmt_command_log),
855 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
856 DEBUG_FOO(wmi_mgmt_event_log),
857 DEBUG_FOO(wmi_enable),
858 DEBUG_FOO(wmi_log_size),
859};
860
861#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
862 sizeof(wmi_debugfs_infos[0]))
863
864/**
865 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
866 *
867 * @wmi_handle: wmi handle
868 * @par_entry: debug directory entry
869 * @id: Index to debug info data array
870 *
871 * Return: none
872 */
873static void wmi_debugfs_create(wmi_unified_t wmi_handle,
874 struct dentry *par_entry, int id)
875{
876 int i;
877
878 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
879 goto out;
880
881 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
882
883 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
884 wmi_debugfs_infos[i].name, 0644, par_entry,
885 wmi_handle, wmi_debugfs_infos[i].ops);
886
887 if (wmi_debugfs_infos[i].de[id] == NULL) {
888 qdf_print("%s: debug Entry creation failed!\n",
889 __func__);
890 goto out;
891 }
892 }
893
894 return;
895
896out:
897 qdf_print("%s: debug Entry creation failed!\n", __func__);
898 wmi_log_buffer_free(wmi_handle);
899 return;
900}
901
902/**
903 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +0530904 * @wmi_handle: wmi handle
905 * @dentry: debugfs directory entry
906 * @id: Index to debug info data array
907 *
908 * Return: none
909 */
Govind Singh06c18392016-06-10 10:33:19 +0530910static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +0530911{
912 int i;
Govind Singh06c18392016-06-10 10:33:19 +0530913 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
914 int id = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +0530915
916 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
917 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
918 if (wmi_debugfs_infos[i].de[id])
919 wmi_debugfs_infos[i].de[id] = NULL;
920 }
921 }
922
923 if (dentry)
924 debugfs_remove_recursive(dentry);
925}
926
927/**
928 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
929 * create debugfs enteries.
930 *
931 * @h: wmi handler
932 *
933 * Return: init status
934 */
935static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
936{
937 static int wmi_index;
938
939 if (wmi_index < MAX_WMI_INSTANCES)
940 wmi_handle->log_info.wmi_log_debugfs_dir =
941 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
942
943 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
944 qdf_print("error while creating debugfs dir for %s\n",
945 debugfs_dir[wmi_index]);
946 return QDF_STATUS_E_FAILURE;
947 }
948
949 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
950 wmi_index);
951 wmi_handle->log_info.wmi_instance_id = wmi_index++;
952
953 return QDF_STATUS_SUCCESS;
954}
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700955
956/**
957 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
958 *
959 * @wmi_handle: wmi handle
960 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700961 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700962 * @vdev_id: vdev id
963 * @chanfreq: channel frequency
964 *
965 * Return: none
966 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530967void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700968 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700969{
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530970
971 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
972
973 data[0] = ((struct wmi_command_header *)header)->type;
974 data[1] = ((struct wmi_command_header *)header)->sub_type;
975 data[2] = vdev_id;
976 data[3] = chanfreq;
977
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700978 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
979
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530980 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -0700981
982 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
983}
Rajeev Kumarae91c402016-05-25 16:07:23 -0700984#else
985/**
986 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
987 * @wmi_handle: wmi handle
988 * @dentry: debugfs directory entry
989 * @id: Index to debug info data array
990 *
991 * Return: none
992 */
Govind Singh06c18392016-06-10 10:33:19 +0530993static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530994void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -0700995 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Govind Singh6b411b52016-03-06 19:55:02 +0530996#endif /*WMI_INTERFACE_EVENT_LOGGING */
997
Govind Singh6b411b52016-03-06 19:55:02 +0530998int wmi_get_host_credits(wmi_unified_t wmi_handle);
999/* WMI buffer APIs */
1000
1001#ifdef MEMORY_DEBUG
1002wmi_buf_t
1003wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301004 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301005{
1006 wmi_buf_t wmi_buf;
1007
1008 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301009 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301010 return NULL;
1011 }
1012
Govind Singhb53420c2016-03-09 14:32:57 +05301013 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301014 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1015 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1016 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301017
1018 if (!wmi_buf)
1019 return NULL;
1020
1021 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301022 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301023
1024 /*
1025 * Set the length of the buffer to match the allocation size.
1026 */
Govind Singhb53420c2016-03-09 14:32:57 +05301027 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301028
1029 return wmi_buf;
1030}
1031
1032void wmi_buf_free(wmi_buf_t net_buf)
1033{
Govind Singhb53420c2016-03-09 14:32:57 +05301034 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301035}
1036#else
1037wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1038{
1039 wmi_buf_t wmi_buf;
1040
1041 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301042 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301043 return NULL;
1044 }
1045
Govind Singhb53420c2016-03-09 14:32:57 +05301046 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301047 WMI_MIN_HEAD_ROOM, 4, false);
1048 if (!wmi_buf)
1049 return NULL;
1050
1051 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301052 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301053
1054 /*
1055 * Set the length of the buffer to match the allocation size.
1056 */
Govind Singhb53420c2016-03-09 14:32:57 +05301057 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301058 return wmi_buf;
1059}
1060
1061void wmi_buf_free(wmi_buf_t net_buf)
1062{
Govind Singhb53420c2016-03-09 14:32:57 +05301063 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301064}
1065#endif
1066
1067/**
1068 * wmi_get_max_msg_len() - get maximum WMI message length
1069 * @wmi_handle: WMI handle.
1070 *
1071 * This function returns the maximum WMI message length
1072 *
1073 * Return: maximum WMI message length
1074 */
1075uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1076{
1077 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1078}
1079
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301080#ifdef CONFIG_MCL
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301081static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +05301082{
1083 switch (wmi_command) {
1084 /* initialize the wlan sub system */
1085 CASE_RETURN_STRING(WMI_INIT_CMDID);
1086
1087 /* Scan specific commands */
1088
1089 /* start scan request to FW */
1090 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1091 /* stop scan request to FW */
1092 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1093 /* full list of channels as defined by the regulatory
1094 * that will be used by scanner */
1095 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1096 /* overwrite default priority table in scan scheduler */
1097 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1098 /* This command to adjust the priority and min.max_rest_time
1099 * of an on ongoing scan request.
1100 */
1101 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1102
1103 /* PDEV(physical device) specific commands */
1104 /* set regulatorty ctl id used by FW to determine the exact
1105 * ctl power limits */
1106 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1107 /* set channel. mainly used for supporting monitor mode */
1108 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1109 /* set pdev specific parameters */
1110 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1111 /* enable packet log */
1112 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1113 /* disable packet log*/
1114 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1115 /* set wmm parameters */
1116 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1117 /* set HT cap ie that needs to be carried probe requests
1118 * HT/VHT channels */
1119 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1120 /* set VHT cap ie that needs to be carried on probe
1121 * requests on VHT channels */
1122 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1123
1124 /* Command to send the DSCP-to-TID map to the target */
1125 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1126 /* set quiet ie parameters. primarily used in AP mode */
1127 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1128 /* Enable/Disable Green AP Power Save */
1129 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1130 /* get TPC config for the current operating channel */
1131 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1132
1133 /* set the base MAC address for the physical device before
1134 * a VDEV is created. For firmware that does not support
1135 * this feature and this command, the pdev MAC address will
1136 * not be changed. */
1137 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1138
1139 /* eeprom content dump , the same to bdboard data */
1140 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1141
1142 /* VDEV(virtual device) specific commands */
1143 /* vdev create */
1144 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1145 /* vdev delete */
1146 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1147 /* vdev start request */
1148 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1149 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1150 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1151 /* vdev up request */
1152 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1153 /* vdev stop request */
1154 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1155 /* vdev down request */
1156 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1157 /* set a vdev param */
1158 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1159 /* set a key (used for setting per peer unicast
1160 * and per vdev multicast) */
1161 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1162
1163 /* wnm sleep mode command */
1164 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1165 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1166 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1167 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1168 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1169 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1170
1171 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1172 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1173 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1174 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1175
1176 /* peer specific commands */
1177
1178 /** create a peer */
1179 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1180 /** delete a peer */
1181 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1182 /** flush specific tid queues of a peer */
1183 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1184 /** set a parameter of a peer */
1185 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1186 /* set peer to associated state. will cary all parameters
1187 * determined during assocication time */
1188 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1189 /* add a wds (4 address ) entry. used only for testing
1190 * WDS feature on AP products */
1191 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1192 /* remove wds (4 address ) entry. used only for testing WDS
1193 * feature on AP products */
1194 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1195 /* set up mcast info for multicast to unicast conversion */
1196 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1197 /* request peer info from FW to get PEER_INFO_EVENTID */
1198 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1199
1200 /* beacon/management specific commands */
1201
1202 /* transmit beacon by reference. used for transmitting beacon
1203 * on low latency interface like pcie */
1204 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1205 /* transmit beacon by value */
1206 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1207 /* set the beacon template. used in beacon offload mode to setup
1208 * the common beacon template with the FW to be used by FW to
1209 * generate beacons */
1210 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1211 /* set beacon filter with FW */
1212 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1213 /* enable/disable filtering of probe requests in the firmware */
1214 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1215 /* transmit management frame by value. will be deprecated */
1216 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1217 /* set the probe response template. used in beacon offload mode
1218 * to setup the common probe response template with the FW to
1219 * be used by FW to generate probe responses */
1220 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1221
1222 /* commands to directly control ba negotiation directly from
1223 * host. only used in test mode */
1224
1225 /* turn off FW Auto addba mode and let host control addba */
1226 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1227 /* send add ba request */
1228 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1229 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1230 /* send del ba */
1231 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1232 /* set add ba response will be used by FW to generate
1233 * addba response*/
1234 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1235 /* send single VHT MPDU with AMSDU */
1236 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1237
1238 /* Station power save specific config */
1239 /* enable/disable station powersave */
1240 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1241 /* set station power save specific parameter */
1242 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1243 /* set station mimo powersave mode */
1244 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1245
1246 /* DFS-specific commands */
1247 /* enable DFS (radar detection)*/
1248 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1249 /* disable DFS (radar detection)*/
1250 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1251 /* enable DFS phyerr/parse filter offload */
1252 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1253 /* enable DFS phyerr/parse filter offload */
1254 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1255
1256 /* Roaming specific commands */
1257 /* set roam scan mode */
1258 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1259 /* set roam scan rssi threshold below which roam
1260 * scan is enabled */
1261 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1262 /* set roam scan period for periodic roam scan mode */
1263 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1264 /* set roam scan trigger rssi change threshold */
1265 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1266 /* set roam AP profile */
1267 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1268 /* set channel list for roam scans */
1269 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1270 /* offload scan specific commands */
1271 /* set offload scan AP profile */
1272 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1273 /* remove offload scan AP profile */
1274 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1275 /* set offload scan period */
1276 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1277
1278 /* P2P specific commands */
1279 /* set P2P device info. FW will used by FW to create P2P IE
1280 * to be carried in probe response generated during p2p listen
1281 * and for p2p discoverability */
1282 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1283 /* enable/disable p2p discoverability on STA/AP VDEVs */
1284 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1285 /* set p2p ie to be carried in beacons generated by FW for GO */
1286 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1287 /* set p2p ie to be carried in probe response frames generated
1288 * by FW for GO */
1289 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1290 /* set the vendor specific p2p ie data.
1291 * FW will use this to parse the P2P NoA
1292 * attribute in the beacons/probe responses received.
1293 */
1294 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1295 /* set the configure of p2p find offload */
1296 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1297 /* set the vendor specific p2p ie data for p2p find offload */
1298 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1299 /* set the BSSID/device name pattern of p2p find offload */
1300 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1301 /* set OppPS related parameters **/
1302 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1303
1304 /* AP power save specific config
1305 * set AP power save specific param */
1306 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1307 /* set AP UAPSD coex pecific param */
1308 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1309
1310 /* Rate-control specific commands */
1311 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1312
1313 /* WLAN Profiling commands. */
1314 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1315 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1316 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1317 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1318 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1319
1320 /* Suspend resume command Ids */
1321 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1322 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1323
1324 /* Beacon filter commands */
1325 /* add a beacon filter */
1326 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1327 /* remove a beacon filter */
1328 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1329
1330 /* WOW Specific WMI commands */
1331 /* add pattern for awake */
1332 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1333 /* deleta a wake pattern */
1334 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1335 /* enable/deisable wake event */
1336 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1337 /* enable WOW */
1338 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1339 /* host woke up from sleep event to FW. Generated in response
1340 * to WOW Hardware event */
1341 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1342
1343 /* RTT measurement related cmd */
1344 /* reques to make an RTT measurement */
1345 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1346 /* reques to report a tsf measurement */
1347 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1348
1349 /* spectral scan command */
1350 /* configure spectral scan */
1351 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1352 /* enable/disable spectral scan and trigger */
1353 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1354
1355 /* F/W stats */
1356 /* one time request for stats */
1357 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1358 /* Push MCC Adaptive Scheduler Stats to Firmware */
1359 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1360
1361 /* ARP OFFLOAD REQUEST*/
1362 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1363
1364 /* Proactive ARP Response Add Pattern Command*/
1365 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1366
1367 /* Proactive ARP Response Del Pattern Command*/
1368 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1369
1370 /* NS offload confid*/
1371 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1372
1373 /* GTK offload Specific WMI commands */
1374 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1375
1376 /* CSA offload Specific WMI commands */
1377 /* csa offload enable */
1378 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1379 /* chan switch command */
1380 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1381
1382 /* Chatter commands */
1383 /* Change chatter mode of operation */
1384 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1385 /* chatter add coalescing filter command */
1386 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1387 /* chatter delete coalescing filter command */
1388 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1389 /* chatter coalecing query command */
1390 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1391
1392 /* addba specific commands */
1393 /* start the aggregation on this TID */
1394 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1395 /* stop the aggregation on this TID */
1396 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1397
1398 /* set station mimo powersave method */
1399 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1400 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1401 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1402 /* Configure the Keep Alive Parameters */
1403 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1404
1405 /* Request ssn from target for a sta/tid pair */
1406 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1407 /* misc command group */
1408 /* echo command mainly used for testing */
1409 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1410
1411 /* !!IMPORTANT!!
1412 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1413 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1414 * as we MUST have a fixed value here to maintain compatibility between
1415 * UTF and the ART2 driver
1416 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301417 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301418 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1419
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301420 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301421 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1422 /* QVIT specific command id */
1423 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1424 /* Factory Testing Mode request command
1425 * used for integrated chipsets */
1426 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1427 /* set and get keepalive parameters command */
1428 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1429 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1430 /* For fw recovery test command */
1431 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1432 /* Set Mcast/Bdcast filter */
1433 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1434 /* set thermal management params */
1435 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1436 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1437 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1438 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301439 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301440 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301441 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301442 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301443 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1444 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1445 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1446 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1447 /* GPIO Configuration */
1448 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1449 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1450
1451 /* Txbf configuration command */
1452 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1453
1454 /* FWTEST Commands */
1455 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1456 /* set NoA descs */
1457 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1458
1459 /* TDLS Configuration */
1460 /* enable/disable TDLS */
1461 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1462 /* set tdls peer state */
1463 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1464
1465 /* Resmgr Configuration */
1466 /* Adaptive OCS is enabled by default in the FW.
1467 * This command is used to disable FW based adaptive OCS.
1468 */
1469 CASE_RETURN_STRING
1470 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1471 /* set the requested channel time quota for the home channels */
1472 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1473 /* set the requested latency for the home channels */
1474 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1475
1476 /* STA SMPS Configuration */
1477 /* force SMPS mode */
1478 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1479 /* set SMPS parameters */
1480 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1481
1482 /* Wlan HB commands */
1483 /* enalbe/disable wlan HB */
1484 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1485 /* set tcp parameters for wlan HB */
1486 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1487 /* set tcp pkt filter for wlan HB */
1488 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1489 /* set udp parameters for wlan HB */
1490 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1491 /* set udp pkt filter for wlan HB */
1492 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1493
1494 /* Wlan RMC commands*/
1495 /* enable/disable RMC */
1496 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1497 /* configure action frame period */
1498 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1499 /* For debug/future enhancement purposes only,
1500 * configures/finetunes RMC algorithms */
1501 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1502
1503 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301504 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301505 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1506 /* Plumb routing table for MHF offload */
1507 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1508
1509 /* location scan commands */
1510 /* start batch scan */
1511 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1512 /* stop batch scan */
1513 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1514 /* get batch scan result */
1515 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1516 /* OEM related cmd */
1517 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1518 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1519 /* NAN request cmd */
1520 CASE_RETURN_STRING(WMI_NAN_CMDID);
1521 /* Modem power state cmd */
1522 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1523 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1524 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1525 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1526 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1527 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1528 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1529 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1530 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301531 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301532 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1533 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1534 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1535 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1536 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1537 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1538 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1539 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1540 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1541 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1542 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1543 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1544 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1545 CASE_RETURN_STRING
1546 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1547 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1548 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1549 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1550 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1551 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1552 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1553 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1554 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1555 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1556 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1557 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1558 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1559 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1560 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1561 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1562 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1563 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1564 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1565 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1566 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1567 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1568 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1569 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1570 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1571 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1572 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1573 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1574 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1575 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1576 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1577 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1578 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1579 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1580 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1581 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1582 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1583 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1584 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1585 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1586 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1587 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1588 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1589 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1590 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1591 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1592 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1593 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1594 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1595 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1596 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1597 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1598 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1599 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1600 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1601 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1602 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1603 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1604 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1605 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1606 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301607 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1608 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1609 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1610 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1611 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1612 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1613 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1614 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1615 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1616 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1617 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1618 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1619 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1620 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1621 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1622 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1623 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1624 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1625 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1626 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1627 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1628 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1629 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1630 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1631 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1632 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1633 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1634 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1635 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1636 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1637 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1638 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1639 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001640 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301641 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301642 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301643 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301644 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Himanshu Agarwaldc8d1ae2016-05-13 21:04:17 +05301645 CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
Himanshu Agarwalfc302f92016-05-30 21:06:16 +05301646 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
1647 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
Pradeep Reddy POTTETI18f8fbb2016-06-13 17:59:38 +05301648 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1649 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
Pradeep Reddy POTTETI4b997fd2016-06-20 13:25:31 +05301650 CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
Pradeep Reddy POTTETI10ca69d2016-06-20 14:50:42 +05301651 CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
Nitesh Shah70e11042016-06-29 20:16:16 +05301652 CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
1653 CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
Nitesh Shahc0482652016-07-08 11:45:33 +05301654 CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
Nitesh Shah33b95402016-07-21 17:25:55 +05301655 CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
1656 CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
Anurag Chouhan40865b42016-08-01 14:01:54 +05301657 CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
Anurag Chouhan7f6f1d52016-08-04 18:46:29 +05301658 CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
Manjeet Singhc026bde2016-09-01 16:42:29 +05301659 CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
Manjeet Singhbea16712016-08-18 15:50:30 +05301660 CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
1661 CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
Himanshu Agarwal91c9d672016-09-14 20:43:24 +05301662 CASE_RETURN_STRING(WMI_VDEV_ENCRYPT_DECRYPT_DATA_REQ_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301663 }
1664
1665 return "Invalid WMI cmd";
1666}
1667
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301668static inline void wma_log_cmd_id(uint32_t cmd_id, uint32_t tag)
Govind Singh6b411b52016-03-06 19:55:02 +05301669{
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301670 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1671 wmi_id_to_name(cmd_id), cmd_id, tag);
Govind Singh6b411b52016-03-06 19:55:02 +05301672}
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001673#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301674static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301675{
1676 return "Invalid WMI cmd";
1677}
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301678#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301679
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001680
Govind Singh6b411b52016-03-06 19:55:02 +05301681/**
Govind Singhd52faac2016-03-09 12:03:29 +05301682 * wmi_is_runtime_pm_cmd() - check if a cmd is from suspend resume sequence
Govind Singh6b411b52016-03-06 19:55:02 +05301683 * @cmd: command to check
1684 *
1685 * Return: true if the command is part of the suspend resume sequence.
1686 */
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301687#ifdef CONFIG_MCL
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301688static bool wmi_is_runtime_pm_cmd(uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301689{
1690 switch (cmd_id) {
1691 case WMI_WOW_ENABLE_CMDID:
1692 case WMI_PDEV_SUSPEND_CMDID:
1693 case WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID:
1694 case WMI_WOW_ADD_WAKE_PATTERN_CMDID:
1695 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1696 case WMI_PDEV_RESUME_CMDID:
1697 case WMI_WOW_DEL_WAKE_PATTERN_CMDID:
1698 case WMI_D0_WOW_ENABLE_DISABLE_CMDID:
1699 return true;
1700
1701 default:
1702 return false;
1703 }
1704}
1705
1706/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301707 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1708 * @cmd_id: command to check
1709 *
1710 * Return: true if the command is part of the resume sequence.
1711 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301712static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301713{
1714 switch (cmd_id) {
1715 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1716 case WMI_PDEV_RESUME_CMDID:
1717 return true;
1718
1719 default:
1720 return false;
1721 }
1722}
1723#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301724static bool wmi_is_runtime_pm_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301725{
1726 return false;
1727}
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301728static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301729{
1730 return false;
1731}
1732#endif
1733
1734/**
Govind Singh6b411b52016-03-06 19:55:02 +05301735 * wmi_unified_cmd_send() - WMI command API
1736 * @wmi_handle: handle to wmi
1737 * @buf: wmi buf
1738 * @len: wmi buffer length
1739 * @cmd_id: wmi command id
1740 *
1741 * Return: 0 on success
1742 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001743QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1744 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301745{
1746 HTC_PACKET *pkt;
1747 A_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301748 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301749
1750 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
1751 if (wmi_is_runtime_pm_cmd(cmd_id))
1752 htc_tag = HTC_TX_PACKET_TAG_AUTO_PM;
Govind Singhb53420c2016-03-09 14:32:57 +05301753 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301754 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301755 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301756 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301757 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301758 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301759 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301760 if (wmi_handle->wmi_stopinprogress) {
1761 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1762 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001763 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301764 }
Govind Singh6b411b52016-03-06 19:55:02 +05301765
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301766#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301767 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301768 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301769 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301770
1771 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301772 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301773 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301774 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301775 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301776 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301777 }
1778 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301779#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301780
Govind Singhb53420c2016-03-09 14:32:57 +05301781 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1782 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301783 "%s, Failed to send cmd %x, no memory",
1784 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301785 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301786 }
1787
Govind Singhb53420c2016-03-09 14:32:57 +05301788 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301789
Govind Singhb53420c2016-03-09 14:32:57 +05301790 qdf_atomic_inc(&wmi_handle->pending_cmds);
1791 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1792 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301793 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301794 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301795 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301796 qdf_atomic_dec(&wmi_handle->pending_cmds);
1797 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301798 "%s: MAX %d WMI Pending cmds reached.", __func__,
1799 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301800 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301801 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301802 }
1803
Govind Singhb53420c2016-03-09 14:32:57 +05301804 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301805 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301806 qdf_atomic_dec(&wmi_handle->pending_cmds);
1807 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301808 "%s, Failed to alloc htc packet %x, no memory",
1809 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301810 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301811 }
1812
1813 SET_HTC_PACKET_INFO_TX(pkt,
1814 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301815 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301816 wmi_handle->wmi_endpoint_id, htc_tag);
1817
1818 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301819#ifdef CONFIG_MCL
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301820 wma_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301821#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301822
1823#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301824 if (wmi_handle->log_info.wmi_logging_enable) {
1825 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301826 /*Record 16 bytes of WMI cmd data -
1827 * * exclude TLV and WMI headers */
1828 if (wmi_handle->log_info.is_management_record(cmd_id)) {
1829 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
1830 ((uint32_t *) qdf_nbuf_data(buf) +
1831 wmi_handle->log_info.buf_offset_command));
1832 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05301833 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
1834 ((uint32_t *) qdf_nbuf_data(buf) +
1835 wmi_handle->log_info.buf_offset_command));
1836 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301837 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1838 }
Govind Singh6b411b52016-03-06 19:55:02 +05301839#endif
1840
1841 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1842
1843 if (A_OK != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301844 qdf_atomic_dec(&wmi_handle->pending_cmds);
1845 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301846 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07001847 qdf_mem_free(pkt);
1848
Govind Singh6b411b52016-03-06 19:55:02 +05301849 }
1850 if (status)
Govind Singhb53420c2016-03-09 14:32:57 +05301851 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301852
Govind Singhb53420c2016-03-09 14:32:57 +05301853 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301854}
1855
1856/**
1857 * wmi_unified_get_event_handler_ix() - gives event handler's index
1858 * @wmi_handle: handle to wmi
1859 * @event_id: wmi event id
1860 *
1861 * Return: event handler's index
1862 */
1863int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301864 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301865{
1866 uint32_t idx = 0;
1867 int32_t invalid_idx = -1;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301868
Govind Singh6b411b52016-03-06 19:55:02 +05301869 for (idx = 0; (idx < wmi_handle->max_event_idx &&
1870 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1871 if (wmi_handle->event_id[idx] == event_id &&
1872 wmi_handle->event_handler[idx] != NULL) {
1873 return idx;
1874 }
1875 }
1876
1877 return invalid_idx;
1878}
1879
1880/**
1881 * wmi_unified_register_event_handler() - register wmi event handler
1882 * @wmi_handle: handle to wmi
1883 * @event_id: wmi event id
1884 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301885 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301886 *
1887 * Return: 0 on success
1888 */
1889int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301890 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301891 wmi_unified_event_handler handler_func,
1892 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301893{
1894 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301895 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301896
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301897#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301898 if (event_id >= wmi_events_max ||
1899 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1900 qdf_print("%s: Event id %d is unavailable\n",
1901 __func__, event_id);
1902 return QDF_STATUS_E_FAILURE;
1903 }
1904 evt_id = wmi_handle->wmi_events[event_id];
1905#else
1906 evt_id = event_id;
1907#endif
1908 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1909 qdf_print("%s : event handler already registered 0x%x\n",
1910 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301911 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301912 }
1913 if (wmi_handle->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301914 qdf_print("%s : no more event handlers 0x%x\n",
1915 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301916 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301917 }
1918 idx = wmi_handle->max_event_idx;
1919 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301920 wmi_handle->event_id[idx] = evt_id;
Govind Singh813fdac2016-03-12 09:26:52 +05301921 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301922 wmi_handle->ctx[idx] = rx_ctx;
Govind Singh813fdac2016-03-12 09:26:52 +05301923 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301924 wmi_handle->max_event_idx++;
1925
1926 return 0;
1927}
1928
1929/**
1930 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1931 * @wmi_handle: handle to wmi
1932 * @event_id: wmi event id
1933 *
1934 * Return: 0 on success
1935 */
1936int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301937 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301938{
1939 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301940 uint32_t evt_id;
Govind Singh6b411b52016-03-06 19:55:02 +05301941
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301942#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301943 if (event_id >= wmi_events_max ||
1944 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1945 qdf_print("%s: Event id %d is unavailable\n",
1946 __func__, event_id);
1947 return QDF_STATUS_E_FAILURE;
1948 }
1949 evt_id = wmi_handle->wmi_events[event_id];
1950#else
1951 evt_id = event_id;
1952#endif
1953
1954 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301955 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301956 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1957 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301958 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301959 }
1960 wmi_handle->event_handler[idx] = NULL;
1961 wmi_handle->event_id[idx] = 0;
1962 --wmi_handle->max_event_idx;
1963 wmi_handle->event_handler[idx] =
1964 wmi_handle->event_handler[wmi_handle->max_event_idx];
1965 wmi_handle->event_id[idx] =
1966 wmi_handle->event_id[wmi_handle->max_event_idx];
1967
1968 return 0;
1969}
1970
1971/**
Govind Singhd52faac2016-03-09 12:03:29 +05301972 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301973 * @wmi_handle: handle to wmi
1974 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301975 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301976 *
Govind Singhd52faac2016-03-09 12:03:29 +05301977 * Event process by below function will be in default caller context.
1978 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301979 *
1980 * Return: none
1981 */
Govind Singhd52faac2016-03-09 12:03:29 +05301982static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1983 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301984{
1985 wmi_buf_t evt_buf;
1986 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1987
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301988#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301989 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1990 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1991#else
Govind Singh5eb51532016-03-09 11:34:12 +05301992 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301993 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301994#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301995
Govind Singh6b411b52016-03-06 19:55:02 +05301996 return;
1997}
1998
1999/**
2000 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
2001 * @wmi_handle: handle to wmi
2002 * @htc_packet: pointer to htc packet
2003 *
2004 * Event process by below function will be in worker thread context.
2005 * Use this method for events which are not critical and not
2006 * handled in protocol stack.
2007 *
2008 * Return: none
2009 */
2010static void wmi_process_fw_event_worker_thread_ctx
2011 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
2012{
2013 wmi_buf_t evt_buf;
2014 uint32_t id;
2015 uint8_t *data;
2016
2017 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302018 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
2019 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302020
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302021#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302022 if (wmi_handle->log_info.wmi_logging_enable) {
2023 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2024 /* Exclude 4 bytes of TLV header */
2025 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2026 wmi_handle->log_info.buf_offset_event));
2027 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2028 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302029#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302030 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2031 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
2032 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302033 schedule_work(&wmi_handle->rx_event_work);
2034 return;
2035}
2036
2037/**
Govind Singhd52faac2016-03-09 12:03:29 +05302038 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302039 * @ctx: handle to wmi
2040 * @htc_packet: pointer to htc packet
2041 *
Govind Singh6b411b52016-03-06 19:55:02 +05302042 * Return: none
2043 */
2044void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
2045{
2046 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
2047 wmi_buf_t evt_buf;
2048 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302049 uint32_t idx = 0;
2050 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302051
2052 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302053 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302054 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302055 if (qdf_unlikely(idx == A_ERROR)) {
2056 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05302057 ("%s :event handler is not registered: event id 0x%x\n",
2058 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302059 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302060 return;
2061 }
Govind Singh813fdac2016-03-12 09:26:52 +05302062 qdf_spin_lock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302063 exec_ctx = wmi_handle->ctx[idx];
Govind Singh813fdac2016-03-12 09:26:52 +05302064 qdf_spin_unlock_bh(&wmi_handle->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302065
2066 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302067 wmi_process_fw_event_worker_thread_ctx
2068 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302069 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2070 wmi_process_fw_event_default_ctx
2071 (wmi_handle, htc_packet, exec_ctx);
2072 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05302073 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
2074 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302075 }
Govind Singhd52faac2016-03-09 12:03:29 +05302076
Govind Singh6b411b52016-03-06 19:55:02 +05302077}
2078
2079/**
2080 * wmi_process_fw_event() - process any fw event
2081 * @wmi_handle: wmi handle
2082 * @evt_buf: fw event buffer
2083 *
Govind Singhd52faac2016-03-09 12:03:29 +05302084 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302085 *
2086 * Return: none
2087 */
2088void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2089{
2090 __wmi_control_rx(wmi_handle, evt_buf);
2091}
2092
2093/**
2094 * __wmi_control_rx() - process serialize wmi event callback
2095 * @wmi_handle: wmi handle
2096 * @evt_buf: fw event buffer
2097 *
2098 * Return: none
2099 */
2100void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2101{
2102 uint32_t id;
2103 uint8_t *data;
2104 uint32_t len;
2105 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302106#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302107 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302108#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302109 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302110
Govind Singhb53420c2016-03-09 14:32:57 +05302111 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302112
Govind Singhb53420c2016-03-09 14:32:57 +05302113 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302114 goto end;
2115
Govind Singhb53420c2016-03-09 14:32:57 +05302116 data = qdf_nbuf_data(evt_buf);
2117 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302118
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302119#ifndef WMI_NON_TLV_SUPPORT
2120 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2121 /* Validate and pad(if necessary) the TLVs */
2122 tlv_ok_status =
2123 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302124 data, len, id,
2125 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302126 if (tlv_ok_status != 0) {
2127 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2128 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2129 __func__, id, tlv_ok_status);
2130 goto end;
2131 }
Govind Singh6b411b52016-03-06 19:55:02 +05302132 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302133#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302134
Govind Singhd52faac2016-03-09 12:03:29 +05302135 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2136 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302137 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302138 "%s : event handler is not registered: event id 0x%x\n",
2139 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302140 goto end;
2141 }
Govind Singhd52faac2016-03-09 12:03:29 +05302142#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302143 if (wmi_handle->log_info.wmi_logging_enable) {
2144 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2145 /* Exclude 4 bytes of TLV header */
2146 if (wmi_handle->log_info.is_management_record(id)) {
2147 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2148 + wmi_handle->log_info.buf_offset_event));
2149 } else {
2150 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2151 wmi_handle->log_info.buf_offset_event));
2152 }
2153 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302154 }
Govind Singhd52faac2016-03-09 12:03:29 +05302155#endif
2156 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302157 if (wmi_handle->target_type == WMI_TLV_TARGET)
2158 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2159 wmi_cmd_struct_ptr, len);
2160 else
2161 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2162 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302163
Govind Singh6b411b52016-03-06 19:55:02 +05302164end:
Govind Singhd52faac2016-03-09 12:03:29 +05302165 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302166#ifndef WMI_NON_TLV_SUPPORT
2167 if (wmi_handle->target_type == WMI_TLV_TARGET)
2168 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2169#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302170
Govind Singhb53420c2016-03-09 14:32:57 +05302171 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302172
Govind Singh6b411b52016-03-06 19:55:02 +05302173}
2174
2175/**
2176 * wmi_rx_event_work() - process rx event in rx work queue context
2177 * @work: rx work queue struct
2178 *
2179 * This function process any fw event to serialize it through rx worker thread.
2180 *
2181 * Return: none
2182 */
2183void wmi_rx_event_work(struct work_struct *work)
2184{
2185 struct wmi_unified *wmi = container_of(work, struct wmi_unified,
Govind Singhecf03cd2016-05-12 12:45:51 +05302186 rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302187 wmi_buf_t buf;
2188
Govind Singhb53420c2016-03-09 14:32:57 +05302189 qdf_spin_lock_bh(&wmi->eventq_lock);
2190 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2191 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302192 while (buf) {
2193 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302194 qdf_spin_lock_bh(&wmi->eventq_lock);
2195 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2196 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302197 }
2198}
2199
Govind Singh6b411b52016-03-06 19:55:02 +05302200#ifdef FEATURE_RUNTIME_PM
2201/**
2202 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2203 * @wmi_handle: wmi context
2204 */
Govind Singhd52faac2016-03-09 12:03:29 +05302205static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302206{
Govind Singhb53420c2016-03-09 14:32:57 +05302207 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302208}
Govind Singhd52faac2016-03-09 12:03:29 +05302209
2210/**
2211 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2212 * @wmi_handle: wmi context
2213 * @val: runtime pm progress flag
2214 */
2215void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2216{
Govind Singhb53420c2016-03-09 14:32:57 +05302217 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302218}
2219
2220/**
2221 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2222 * @wmi_handle: wmi context
2223 */
2224inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2225{
Govind Singhb53420c2016-03-09 14:32:57 +05302226 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302227}
Govind Singh6b411b52016-03-06 19:55:02 +05302228#else
Govind Singhd52faac2016-03-09 12:03:29 +05302229static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302230{
2231}
2232#endif
2233
2234/**
2235 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302236 * @scn_handle: handle to SCN
2237 * @osdev: OS device context
2238 * @target_type: TLV or not-TLV based target
2239 * @use_cookie: cookie based allocation enabled/disabled
2240 * @ops: umac rx callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302241 *
2242 * @Return: wmi handle.
2243 */
Govind Singhc458f382016-02-04 18:42:30 +05302244void *wmi_unified_attach(void *scn_handle,
2245 osdev_t osdev, enum wmi_target_type target_type,
Govind Singh5eb51532016-03-09 11:34:12 +05302246 bool use_cookie, struct wmi_rx_ops *rx_ops)
Govind Singh6b411b52016-03-06 19:55:02 +05302247{
2248 struct wmi_unified *wmi_handle;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302249
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302250#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05302251 wmi_handle =
2252 (struct wmi_unified *)os_malloc(NULL,
2253 sizeof(struct wmi_unified),
2254 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302255#else
2256 wmi_handle =
2257 (struct wmi_unified *) qdf_mem_malloc(
2258 sizeof(struct wmi_unified));
2259#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302260 if (wmi_handle == NULL) {
Govind Singhb53420c2016-03-09 14:32:57 +05302261 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302262 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302263 return NULL;
2264 }
2265 OS_MEMZERO(wmi_handle, sizeof(struct wmi_unified));
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302266 wmi_handle->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302267 qdf_atomic_init(&wmi_handle->pending_cmds);
2268 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302269 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302270 qdf_spinlock_create(&wmi_handle->eventq_lock);
2271 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302272 INIT_WORK(&wmi_handle->rx_event_work, wmi_rx_event_work);
Govind Singh6b411b52016-03-06 19:55:02 +05302273#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302274 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2275 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2276 wmi_debugfs_init(wmi_handle);
2277 }
Govind Singh6b411b52016-03-06 19:55:02 +05302278#endif
Govind Singhc458f382016-02-04 18:42:30 +05302279 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302280 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2281 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302282 wmi_handle->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302283 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302284 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302285 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302286 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302287 /* Assign target cookie capablity */
2288 wmi_handle->use_cookie = use_cookie;
2289 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302290 wmi_handle->wmi_stopinprogress = 0;
Govind Singh813fdac2016-03-12 09:26:52 +05302291 qdf_spinlock_create(&wmi_handle->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302292
2293 return wmi_handle;
2294}
2295
2296/**
2297 * wmi_unified_detach() - detach for unified WMI
2298 *
2299 * @wmi_handle : handle to wmi.
2300 *
2301 * @Return: none.
2302 */
2303void wmi_unified_detach(struct wmi_unified *wmi_handle)
2304{
2305 wmi_buf_t buf;
2306
Govind Singhb53420c2016-03-09 14:32:57 +05302307 cancel_work_sync(&wmi_handle->rx_event_work);
Rajeev Kumarae91c402016-05-25 16:07:23 -07002308
Govind Singh06c18392016-06-10 10:33:19 +05302309 wmi_debugfs_remove(wmi_handle);
Rajeev Kumarae91c402016-05-25 16:07:23 -07002310
Govind Singhb53420c2016-03-09 14:32:57 +05302311 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302312 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302313 qdf_nbuf_free(buf);
2314 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302315 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302316
2317#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302318 wmi_log_buffer_free(wmi_handle);
2319#endif
2320
Govind Singh20e7a062016-05-26 18:15:36 +05302321 qdf_spinlock_destroy(&wmi_handle->eventq_lock);
Govind Singh813fdac2016-03-12 09:26:52 +05302322 qdf_spinlock_destroy(&wmi_handle->ctx_lock);
Rajeev Kumarfec04012016-06-10 14:27:46 -07002323 OS_FREE(wmi_handle);
2324 wmi_handle = NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302325}
2326
2327/**
2328 * wmi_unified_remove_work() - detach for WMI work
2329 * @wmi_handle: handle to WMI
2330 *
2331 * A function that does not fully detach WMI, but just remove work
2332 * queue items associated with it. This is used to make sure that
2333 * before any other processing code that may destroy related contexts
2334 * (HTC, etc), work queue processing on WMI has already been stopped.
2335 *
2336 * Return: None
2337 */
2338void
2339wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2340{
2341 wmi_buf_t buf;
2342
Govind Singhb53420c2016-03-09 14:32:57 +05302343 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302344 "Enter: %s", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05302345 cancel_work_sync(&wmi_handle->rx_event_work);
2346 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2347 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302348 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302349 qdf_nbuf_free(buf);
2350 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302351 }
Govind Singhb53420c2016-03-09 14:32:57 +05302352 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2353 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302354 "Done: %s", __func__);
2355}
2356
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302357/**
2358 * wmi_htc_tx_complete() - Process htc tx completion
2359 *
2360 * @ctx: handle to wmi
2361 * @htc_packet: pointer to htc packet
2362 *
2363 * @Return: none.
2364 */
Govind Singh6b411b52016-03-06 19:55:02 +05302365void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
2366{
2367 struct wmi_unified *wmi_handle = (struct wmi_unified *)ctx;
2368 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302369 u_int8_t *buf_ptr;
2370 u_int32_t len;
Govind Singh6b411b52016-03-06 19:55:02 +05302371#ifdef WMI_INTERFACE_EVENT_LOGGING
2372 uint32_t cmd_id;
2373#endif
2374
2375 ASSERT(wmi_cmd_buf);
2376#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302377 if (wmi_handle->log_info.wmi_logging_enable) {
2378 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2379 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302380
Govind Singhecf03cd2016-05-12 12:45:51 +05302381 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302382 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302383 - exclude TLV and WMI headers */
2384 if (wmi_handle->log_info.is_management_record(cmd_id)) {
2385 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2386 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2387 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302388 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302389 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2390 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2391 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302392 }
2393
Govind Singhecf03cd2016-05-12 12:45:51 +05302394 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2395 }
Govind Singh6b411b52016-03-06 19:55:02 +05302396#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302397 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2398 len = qdf_nbuf_len(wmi_cmd_buf);
2399 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302400 qdf_nbuf_free(wmi_cmd_buf);
2401 qdf_mem_free(htc_pkt);
2402 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302403}
2404
2405/**
2406 * wmi_get_host_credits() - WMI API to get updated host_credits
2407 *
2408 * @wmi_handle: handle to WMI.
2409 *
2410 * @Return: updated host_credits.
2411 */
2412int
2413wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2414 void *htc_handle)
2415{
2416
2417 int status;
2418 HTC_SERVICE_CONNECT_RESP response;
2419 HTC_SERVICE_CONNECT_REQ connect;
2420
2421 OS_MEMZERO(&connect, sizeof(connect));
2422 OS_MEMZERO(&response, sizeof(response));
2423
2424 /* meta data is unused for now */
2425 connect.pMetaData = NULL;
2426 connect.MetaDataLength = 0;
2427 /* these fields are the same for all service endpoints */
2428 connect.EpCallbacks.pContext = wmi_handle;
2429 connect.EpCallbacks.EpTxCompleteMultiple =
2430 NULL /* Control path completion ar6000_tx_complete */;
2431 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2432 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2433 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2434 connect.EpCallbacks.EpTxComplete =
2435 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2436
2437 /* connect to control service */
2438 connect.service_id = WMI_CONTROL_SVC;
2439 status = htc_connect_service(htc_handle, &connect,
2440 &response);
2441
2442 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302443 qdf_print
Govind Singh6b411b52016-03-06 19:55:02 +05302444 ("Failed to connect to WMI CONTROL service status:%d \n",
2445 status);
2446 return status;
2447 }
2448 wmi_handle->wmi_endpoint_id = response.Endpoint;
2449 wmi_handle->htc_handle = htc_handle;
2450 wmi_handle->max_msg_len = response.MaxMsgLength;
2451
2452 return EOK;
2453}
2454
2455/**
2456 * wmi_get_host_credits() - WMI API to get updated host_credits
2457 *
2458 * @wmi_handle: handle to WMI.
2459 *
2460 * @Return: updated host_credits.
2461 */
2462int wmi_get_host_credits(wmi_unified_t wmi_handle)
2463{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302464 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302465
2466 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2467 &host_credits);
2468 return host_credits;
2469}
2470
2471/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302472 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2473 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302474 *
2475 * @wmi_handle: handle to WMI.
2476 *
2477 * @Return: Pending Commands in the HTC queue.
2478 */
2479int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2480{
Govind Singhb53420c2016-03-09 14:32:57 +05302481 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302482}
2483
2484/**
2485 * wmi_set_target_suspend() - WMI API to set target suspend state
2486 *
2487 * @wmi_handle: handle to WMI.
2488 * @val: suspend state boolean.
2489 *
2490 * @Return: none.
2491 */
2492void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2493{
Govind Singhb53420c2016-03-09 14:32:57 +05302494 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302495}
2496
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302497#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302498/**
2499 * API to flush all the previous packets associated with the wmi endpoint
2500 *
2501 * @param wmi_handle : handle to WMI.
2502 */
2503void
2504wmi_flush_endpoint(wmi_unified_t wmi_handle)
2505{
2506 htc_flush_endpoint(wmi_handle->htc_handle,
2507 wmi_handle->wmi_endpoint_id, 0);
2508}
2509
2510/**
2511 * generic function to block unified WMI command
2512 * @param wmi_handle : handle to WMI.
2513 * @return 0 on success and -ve on failure.
2514 */
2515int
2516wmi_stop(wmi_unified_t wmi_handle)
2517{
2518 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2519 "WMI Stop\n");
2520 wmi_handle->wmi_stopinprogress = 1;
2521 return 0;
2522}
2523#endif