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