blob: d16b66578d4d6fee2ca88d3cf7358c219b20ffde [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
Paul Zhangd19abd82017-01-04 16:45:42 +08002 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
Govind Singh6b411b52016-03-06 19:55:02 +05303 *
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"
Govind Singh6b411b52016-03-06 19:55:02 +053036#include "htc_api.h"
37#include "htc_api.h"
38#include "dbglog_host.h"
Govind Singh6b411b52016-03-06 19:55:02 +053039#include "wmi_unified_priv.h"
Govind Singh5eb51532016-03-09 11:34:12 +053040#include "wmi_unified_param.h"
Govind Singh6b411b52016-03-06 19:55:02 +053041
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053042#ifndef WMI_NON_TLV_SUPPORT
43#include "wmi_tlv_helper.h"
44#endif
45
Govind Singhecf03cd2016-05-12 12:45:51 +053046#include <linux/debugfs.h>
47
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053048/* This check for CONFIG_WIN temporary added due to redeclaration compilation
49error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
50which gets included here through ol_if_athvar.h. Eventually it is expected that
51wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
52WMI_CMD_HDR to be defined here. */
53#ifdef CONFIG_WIN
54/* Copied from wmi.h */
55#undef MS
56#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
57#undef SM
58#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
59#undef WO
60#define WO(_f) ((_f##_OFFSET) >> 2)
61
62#undef GET_FIELD
63#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
64#undef SET_FIELD
65#define SET_FIELD(_addr, _f, _val) \
66 (*((A_UINT32 *)(_addr) + WO(_f)) = \
67 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
68
69#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
70 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
71
72#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
73 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
74
75#define WMI_EP_APASS 0x0
76#define WMI_EP_LPASS 0x1
77#define WMI_EP_SENSOR 0x2
78
79/*
80 * * Control Path
81 * */
82typedef PREPACK struct {
83 A_UINT32 commandId:24,
84 reserved:2, /* used for WMI endpoint ID */
85 plt_priv:6; /* platform private */
86} POSTPACK WMI_CMD_HDR; /* used for commands and events */
87
88#define WMI_CMD_HDR_COMMANDID_LSB 0
89#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
90#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
91#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
92#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
93#define WMI_CMD_HDR_PLT_PRIV_LSB 24
94#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
95#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
96/* end of copy wmi.h */
97#endif /* CONFIG_WIN */
98
Manikandan Mohan5826ae92016-06-08 16:29:39 -070099#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
100/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +0530101static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700102{
103 va_list args;
104
105 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +0530106 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700107 va_end(args);
108
Pratik Gandhi795ab912017-05-03 20:15:50 +0530109 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700110}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530111#else
112#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700113#endif
114
Govind Singh6b411b52016-03-06 19:55:02 +0530115#define WMI_MIN_HEAD_ROOM 64
116
117#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +0530118#ifndef MAX_WMI_INSTANCES
119#ifdef CONFIG_MCL
120#define MAX_WMI_INSTANCES 1
121#else
122#define MAX_WMI_INSTANCES 3
123#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530124#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530125#endif
126
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530127#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530128/* WMI commands */
129uint32_t g_wmi_command_buf_idx = 0;
130struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
131
132/* WMI commands TX completed */
133uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
134struct wmi_command_debug
135 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
136
137/* WMI events when processed */
138uint32_t g_wmi_event_buf_idx = 0;
139struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
140
141/* WMI events when queued */
142uint32_t g_wmi_rx_event_buf_idx = 0;
143struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530144#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530145
Govind Singhecf03cd2016-05-12 12:45:51 +0530146#define WMI_COMMAND_RECORD(h, a, b) { \
147 if (wmi_log_max_entry <= \
148 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
149 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
150 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
151 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
152 .command = a; \
153 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
154 wmi_command_log_buf_info.buf) \
155 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
156 b, wmi_record_max_length); \
157 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
158 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
159 time = qdf_get_log_timestamp(); \
160 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
161 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530162}
163
Govind Singhecf03cd2016-05-12 12:45:51 +0530164#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
165 if (wmi_log_max_entry <= \
166 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530167 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
168 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530169 ((struct wmi_command_debug *)h->log_info. \
170 wmi_command_tx_cmp_log_buf_info.buf) \
171 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
172 p_buf_tail_idx)]. \
173 command = a; \
174 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
175 wmi_command_tx_cmp_log_buf_info.buf) \
176 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
177 p_buf_tail_idx)]. \
178 data, b, wmi_record_max_length); \
179 ((struct wmi_command_debug *)h->log_info. \
180 wmi_command_tx_cmp_log_buf_info.buf) \
181 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
182 p_buf_tail_idx)]. \
183 time = qdf_get_log_timestamp(); \
184 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
185 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530186}
187
Govind Singhecf03cd2016-05-12 12:45:51 +0530188#define WMI_EVENT_RECORD(h, a, b) { \
189 if (wmi_log_max_entry <= \
190 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
191 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
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)]. \
194 event = a; \
195 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
196 wmi_event_log_buf_info.buf) \
197 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
198 wmi_record_max_length); \
199 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
200 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530201 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530202 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
203 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530204}
205
Govind Singhecf03cd2016-05-12 12:45:51 +0530206#define WMI_RX_EVENT_RECORD(h, a, b) { \
207 if (wmi_log_max_entry <= \
208 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
209 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
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 event = a; \
213 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
214 wmi_rx_event_log_buf_info.buf) \
215 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
216 data, b, wmi_record_max_length); \
217 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
218 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
219 time = qdf_get_log_timestamp(); \
220 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
221 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530222}
Govind Singh6b411b52016-03-06 19:55:02 +0530223
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530224#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530225uint32_t g_wmi_mgmt_command_buf_idx = 0;
226struct
227wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
228
229/* wmi_mgmt commands TX completed */
230uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
231struct wmi_command_debug
232wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
233
234/* wmi_mgmt events when processed */
235uint32_t g_wmi_mgmt_event_buf_idx = 0;
236struct wmi_event_debug
237wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530238#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530239
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530240#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
241 if (wmi_mgmt_log_max_entry <= \
242 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
243 *(h->log_info.wmi_mgmt_command_log_buf_info. \
244 p_buf_tail_idx) = 0; \
245 ((struct wmi_command_debug *)h->log_info. \
246 wmi_mgmt_command_log_buf_info.buf) \
247 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
248 command = a; \
249 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
250 wmi_mgmt_command_log_buf_info.buf) \
251 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
252 data, b, \
253 wmi_record_max_length); \
254 ((struct wmi_command_debug *)h->log_info. \
255 wmi_mgmt_command_log_buf_info.buf) \
256 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
257 time = qdf_get_log_timestamp(); \
258 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
259 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530260}
261
Govind Singhecf03cd2016-05-12 12:45:51 +0530262#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
263 if (wmi_mgmt_log_max_entry <= \
264 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
265 p_buf_tail_idx)) \
266 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
267 p_buf_tail_idx) = 0; \
268 ((struct wmi_command_debug *)h->log_info. \
269 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
270 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
271 p_buf_tail_idx)].command = a; \
272 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
273 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
274 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
275 p_buf_tail_idx)].data, b, \
276 wmi_record_max_length); \
277 ((struct wmi_command_debug *)h->log_info. \
278 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
279 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
280 p_buf_tail_idx)].time = \
281 qdf_get_log_timestamp(); \
282 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
283 p_buf_tail_idx))++; \
284 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530285}
286
Govind Singhecf03cd2016-05-12 12:45:51 +0530287#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
288 if (wmi_mgmt_log_max_entry <= \
289 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
290 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
291 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
292 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
293 .event = a; \
294 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
295 wmi_mgmt_event_log_buf_info.buf) \
296 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
297 data, b, wmi_record_max_length); \
298 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
299 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
300 time = qdf_get_log_timestamp(); \
301 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
302 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530303}
304
Govind Singhecf03cd2016-05-12 12:45:51 +0530305/* These are defined to made it as module param, which can be configured */
306uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
307uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
308uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
309uint32_t wmi_display_size = 100;
310
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530311static uint8_t *wmi_id_to_name(uint32_t wmi_command);
Govind Singhecf03cd2016-05-12 12:45:51 +0530312
313/**
314 * wmi_log_init() - Initialize WMI event logging
315 * @wmi_handle: WMI handle.
316 *
317 * Return: Initialization status
318 */
319#ifdef CONFIG_MCL
320static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
321{
322 struct wmi_log_buf_t *cmd_log_buf =
323 &wmi_handle->log_info.wmi_command_log_buf_info;
324 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
325 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
326
327 struct wmi_log_buf_t *event_log_buf =
328 &wmi_handle->log_info.wmi_event_log_buf_info;
329 struct wmi_log_buf_t *rx_event_log_buf =
330 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
331
332 struct wmi_log_buf_t *mgmt_cmd_log_buf =
333 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
334 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
335 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
336 struct wmi_log_buf_t *mgmt_event_log_buf =
337 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
338
339 /* WMI commands */
340 cmd_log_buf->length = 0;
341 cmd_log_buf->buf_tail_idx = 0;
342 cmd_log_buf->buf = wmi_command_log_buffer;
343 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700344 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530345
346 /* WMI commands TX completed */
347 cmd_tx_cmpl_log_buf->length = 0;
348 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
349 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
350 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700351 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530352
353 /* WMI events when processed */
354 event_log_buf->length = 0;
355 event_log_buf->buf_tail_idx = 0;
356 event_log_buf->buf = wmi_event_log_buffer;
357 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700358 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530359
360 /* WMI events when queued */
361 rx_event_log_buf->length = 0;
362 rx_event_log_buf->buf_tail_idx = 0;
363 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
364 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700365 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530366
367 /* WMI Management commands */
368 mgmt_cmd_log_buf->length = 0;
369 mgmt_cmd_log_buf->buf_tail_idx = 0;
370 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
371 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700372 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530373
374 /* WMI Management commands Tx completed*/
375 mgmt_cmd_tx_cmp_log_buf->length = 0;
376 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
377 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
378 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
379 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700380 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530381
382 /* WMI Management events when processed*/
383 mgmt_event_log_buf->length = 0;
384 mgmt_event_log_buf->buf_tail_idx = 0;
385 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
386 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700387 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530388
389 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
390 wmi_handle->log_info.wmi_logging_enable = 1;
391
392 return QDF_STATUS_SUCCESS;
393}
394#else
395static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
396{
397 struct wmi_log_buf_t *cmd_log_buf =
398 &wmi_handle->log_info.wmi_command_log_buf_info;
399 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
400 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
401
402 struct wmi_log_buf_t *event_log_buf =
403 &wmi_handle->log_info.wmi_event_log_buf_info;
404 struct wmi_log_buf_t *rx_event_log_buf =
405 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
406
407 struct wmi_log_buf_t *mgmt_cmd_log_buf =
408 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
409 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
410 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
411 struct wmi_log_buf_t *mgmt_event_log_buf =
412 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
413
414 wmi_handle->log_info.wmi_logging_enable = 0;
415
416 /* WMI commands */
417 cmd_log_buf->length = 0;
418 cmd_log_buf->buf_tail_idx = 0;
419 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
420 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700421 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530422
423 if (!cmd_log_buf->buf) {
424 qdf_print("no memory for WMI command log buffer..\n");
425 return QDF_STATUS_E_NOMEM;
426 }
427 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
428
429 /* WMI commands TX completed */
430 cmd_tx_cmpl_log_buf->length = 0;
431 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
432 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
433 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700434 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530435
436 if (!cmd_tx_cmpl_log_buf->buf) {
437 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
438 return QDF_STATUS_E_NOMEM;
439 }
440 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
441 &cmd_tx_cmpl_log_buf->buf_tail_idx;
442
443 /* WMI events when processed */
444 event_log_buf->length = 0;
445 event_log_buf->buf_tail_idx = 0;
446 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
447 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700448 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530449
450 if (!event_log_buf->buf) {
451 qdf_print("no memory for WMI Event log buffer..\n");
452 return QDF_STATUS_E_NOMEM;
453 }
454 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
455
456 /* WMI events when queued */
457 rx_event_log_buf->length = 0;
458 rx_event_log_buf->buf_tail_idx = 0;
459 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
460 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700461 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530462
463 if (!rx_event_log_buf->buf) {
464 qdf_print("no memory for WMI Event Rx log buffer..\n");
465 return QDF_STATUS_E_NOMEM;
466 }
467 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
468
469 /* WMI Management commands */
470 mgmt_cmd_log_buf->length = 0;
471 mgmt_cmd_log_buf->buf_tail_idx = 0;
472 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700473 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
474 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530475
476 if (!mgmt_cmd_log_buf->buf) {
477 qdf_print("no memory for WMI Management Command log buffer..\n");
478 return QDF_STATUS_E_NOMEM;
479 }
480 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
481
482 /* WMI Management commands Tx completed*/
483 mgmt_cmd_tx_cmp_log_buf->length = 0;
484 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
485 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
486 qdf_mem_malloc(
487 wmi_mgmt_log_max_entry *
488 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700489 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530490
491 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
492 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
493 return QDF_STATUS_E_NOMEM;
494 }
495 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
496 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
497
498 /* WMI Management events when processed*/
499 mgmt_event_log_buf->length = 0;
500 mgmt_event_log_buf->buf_tail_idx = 0;
501
502 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
503 wmi_mgmt_log_max_entry *
504 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700505 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530506
507 if (!mgmt_event_log_buf->buf) {
508 qdf_print("no memory for WMI Management Event log buffer..\n");
509 return QDF_STATUS_E_NOMEM;
510 }
511 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
512
513 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
514 wmi_handle->log_info.wmi_logging_enable = 1;
515
516 return QDF_STATUS_SUCCESS;
517}
518#endif
519
520/**
521 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
522 * event logging
523 * @wmi_handle: WMI handle.
524 *
525 * Return: None
526 */
527#ifndef CONFIG_MCL
528static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
529{
530 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
531 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
532 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
533 qdf_mem_free(
534 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
535 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
536 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
537 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
538 qdf_mem_free(
539 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
540 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
541 qdf_mem_free(
542 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
543 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
544 qdf_mem_free(
545 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
546 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
547 qdf_mem_free(
548 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
549 wmi_handle->log_info.wmi_logging_enable = 0;
550 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
551}
552#else
553static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
554{
555 /* Do Nothing */
556}
557#endif
558
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700559/**
560 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
561 * @log_buffer: the command log buffer metadata of the buffer to print
562 * @count: the maximum number of entries to print
563 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
564 * @print_priv: any data required by the print method, e.g. a file handle
565 *
566 * Return: None
567 */
568static void
569wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
570 qdf_abstract_print *print, void *print_priv)
571{
572 static const int data_len =
573 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
574 char str[128];
575 uint32_t idx;
576
577 if (count > log_buffer->size)
578 count = log_buffer->size;
579 if (count > log_buffer->length)
580 count = log_buffer->length;
581
582 /* subtract count from index, and wrap if necessary */
583 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
584 idx %= log_buffer->size;
585
586 print(print_priv, "Time (seconds) Cmd Id Payload");
587 while (count) {
588 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
589 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700590 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700591 int len = 0;
592 int i;
593
Dustin Brown8ea39122017-04-10 13:26:56 -0700594 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700595 len += scnprintf(str + len, sizeof(str) - len,
596 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700597 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700598 cmd_log->command, cmd_log->command);
599 for (i = 0; i < data_len; ++i) {
600 len += scnprintf(str + len, sizeof(str) - len,
601 "0x%08x ", cmd_log->data[i]);
602 }
603
604 print(print_priv, str);
605
606 --count;
607 ++idx;
608 if (idx >= log_buffer->size)
609 idx = 0;
610 }
611}
612
613/**
614 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
615 * @log_buffer: the event log buffer metadata of the buffer to print
616 * @count: the maximum number of entries to print
617 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
618 * @print_priv: any data required by the print method, e.g. a file handle
619 *
620 * Return: None
621 */
622static void
623wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
624 qdf_abstract_print *print, void *print_priv)
625{
626 static const int data_len =
627 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
628 char str[128];
629 uint32_t idx;
630
631 if (count > log_buffer->size)
632 count = log_buffer->size;
633 if (count > log_buffer->length)
634 count = log_buffer->length;
635
636 /* subtract count from index, and wrap if necessary */
637 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
638 idx %= log_buffer->size;
639
640 print(print_priv, "Time (seconds) Event Id Payload");
641 while (count) {
642 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
643 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700644 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700645 int len = 0;
646 int i;
647
Dustin Brown8ea39122017-04-10 13:26:56 -0700648 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700649 len += scnprintf(str + len, sizeof(str) - len,
650 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700651 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700652 event_log->event, event_log->event);
653 for (i = 0; i < data_len; ++i) {
654 len += scnprintf(str + len, sizeof(str) - len,
655 "0x%08x ", event_log->data[i]);
656 }
657
658 print(print_priv, str);
659
660 --count;
661 ++idx;
662 if (idx >= log_buffer->size)
663 idx = 0;
664 }
665}
666
667inline void
668wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
669 qdf_abstract_print *print, void *print_priv)
670{
671 wmi_print_cmd_log_buffer(
672 &wmi->log_info.wmi_command_log_buf_info,
673 count, print, print_priv);
674}
675
676inline void
677wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
678 qdf_abstract_print *print, void *print_priv)
679{
680 wmi_print_cmd_log_buffer(
681 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
682 count, print, print_priv);
683}
684
685inline void
686wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
687 qdf_abstract_print *print, void *print_priv)
688{
689 wmi_print_cmd_log_buffer(
690 &wmi->log_info.wmi_mgmt_command_log_buf_info,
691 count, print, print_priv);
692}
693
694inline void
695wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
696 qdf_abstract_print *print, void *print_priv)
697{
698 wmi_print_cmd_log_buffer(
699 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
700 count, print, print_priv);
701}
702
703inline void
704wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
705 qdf_abstract_print *print, void *print_priv)
706{
707 wmi_print_event_log_buffer(
708 &wmi->log_info.wmi_event_log_buf_info,
709 count, print, print_priv);
710}
711
712inline void
713wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
714 qdf_abstract_print *print, void *print_priv)
715{
716 wmi_print_event_log_buffer(
717 &wmi->log_info.wmi_rx_event_log_buf_info,
718 count, print, print_priv);
719}
720
721inline void
722wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
723 qdf_abstract_print *print, void *print_priv)
724{
725 wmi_print_event_log_buffer(
726 &wmi->log_info.wmi_mgmt_event_log_buf_info,
727 count, print, print_priv);
728}
729
Govind Singhecf03cd2016-05-12 12:45:51 +0530730#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530731const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530732#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530733const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530734#endif
735
736/* debugfs routines*/
737
738/**
739 * debug_wmi_##func_base##_show() - debugfs functions to display content of
740 * command and event buffers. Macro uses max buffer length to display
741 * buffer when it is wraparound.
742 *
743 * @m: debugfs handler to access wmi_handle
744 * @v: Variable arguments (not used)
745 *
746 * Return: Length of characters printed
747 */
748#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
749 static int debug_wmi_##func_base##_show(struct seq_file *m, \
750 void *v) \
751 { \
752 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
753 struct wmi_log_buf_t *wmi_log = \
754 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
755 int pos, nread, outlen; \
756 int i; \
757 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530758 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
759 if (!wmi_log->length) { \
760 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530761 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530762 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530763 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530764 \
765 if (wmi_log->length <= wmi_ring_size) \
766 nread = wmi_log->length; \
767 else \
768 nread = wmi_ring_size; \
769 \
770 if (*(wmi_log->p_buf_tail_idx) == 0) \
771 /* tail can be 0 after wrap-around */ \
772 pos = wmi_ring_size - 1; \
773 else \
774 pos = *(wmi_log->p_buf_tail_idx) - 1; \
775 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530776 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530777 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530778 while (nread--) { \
779 struct wmi_command_debug *wmi_record; \
780 \
781 wmi_record = (struct wmi_command_debug *) \
782 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530783 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530784 (wmi_record->command)); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530785 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530786 for (i = 0; i < (wmi_record_max_length/ \
787 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530788 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530789 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530790 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530791 \
792 if (pos == 0) \
793 pos = wmi_ring_size - 1; \
794 else \
795 pos--; \
796 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530797 return outlen; \
798 } \
799
800#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
801 static int debug_wmi_##func_base##_show(struct seq_file *m, \
802 void *v) \
803 { \
804 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
805 struct wmi_log_buf_t *wmi_log = \
806 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
807 int pos, nread, outlen; \
808 int i; \
809 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530810 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
811 if (!wmi_log->length) { \
812 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530813 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530814 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530815 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530816 \
817 if (wmi_log->length <= wmi_ring_size) \
818 nread = wmi_log->length; \
819 else \
820 nread = wmi_ring_size; \
821 \
822 if (*(wmi_log->p_buf_tail_idx) == 0) \
823 /* tail can be 0 after wrap-around */ \
824 pos = wmi_ring_size - 1; \
825 else \
826 pos = *(wmi_log->p_buf_tail_idx) - 1; \
827 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530828 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530829 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530830 while (nread--) { \
831 struct wmi_event_debug *wmi_record; \
832 \
833 wmi_record = (struct wmi_event_debug *) \
834 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530835 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +0530836 (wmi_record->event)); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530837 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530838 for (i = 0; i < (wmi_record_max_length/ \
839 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530840 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530841 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530842 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530843 \
844 if (pos == 0) \
845 pos = wmi_ring_size - 1; \
846 else \
847 pos--; \
848 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530849 return outlen; \
850 }
851
852GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
853GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
854GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
855GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
856GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
857GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
858 wmi_display_size);
859GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
860
861/**
862 * debug_wmi_enable_show() - debugfs functions to display enable state of
863 * wmi logging feature.
864 *
865 * @m: debugfs handler to access wmi_handle
866 * @v: Variable arguments (not used)
867 *
868 * Return: always 1
869 */
870static int debug_wmi_enable_show(struct seq_file *m, void *v)
871{
872 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
873
Pratik Gandhi795ab912017-05-03 20:15:50 +0530874 return wmi_bp_seq_printf(m, "%d\n",
875 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530876}
877
878/**
879 * debug_wmi_log_size_show() - debugfs functions to display configured size of
880 * wmi logging command/event buffer and management command/event buffer.
881 *
882 * @m: debugfs handler to access wmi_handle
883 * @v: Variable arguments (not used)
884 *
885 * Return: Length of characters printed
886 */
887static int debug_wmi_log_size_show(struct seq_file *m, void *v)
888{
889
Pratik Gandhi795ab912017-05-03 20:15:50 +0530890 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
891 wmi_log_max_entry);
892 return wmi_bp_seq_printf(m,
893 "WMI management command/events log max size:%d\n",
894 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530895}
896
897/**
898 * debug_wmi_##func_base##_write() - debugfs functions to clear
899 * wmi logging command/event buffer and management command/event buffer.
900 *
901 * @file: file handler to access wmi_handle
902 * @buf: received data buffer
903 * @count: length of received buffer
904 * @ppos: Not used
905 *
906 * Return: count
907 */
908#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
909 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
910 const char __user *buf, \
911 size_t count, loff_t *ppos) \
912 { \
913 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530914 wmi_unified_t wmi_handle = \
915 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530916 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
917 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530918 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530919 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530920 if ((!buf) || (count > 50)) \
921 return -EFAULT; \
922 \
923 if (copy_from_user(locbuf, buf, count)) \
924 return -EFAULT; \
925 \
926 ret = sscanf(locbuf, "%d", &k); \
927 if ((ret != 1) || (k != 0)) { \
Govind Singhecf03cd2016-05-12 12:45:51 +0530928 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
929 return -EINVAL; \
930 } \
931 \
932 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
933 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
934 sizeof(struct wmi_record_type)); \
935 wmi_log->length = 0; \
936 *(wmi_log->p_buf_tail_idx) = 0; \
937 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
938 \
939 return count; \
940 }
941
942GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
943 wmi_command_debug);
944GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
945 wmi_command_debug);
946GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
947 wmi_event_debug);
948GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
949 wmi_event_debug);
950GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
951 wmi_command_debug);
952GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
953 wmi_mgmt_log_max_entry, wmi_command_debug);
954GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
955 wmi_event_debug);
956
957/**
958 * debug_wmi_enable_write() - debugfs functions to enable/disable
959 * wmi logging feature.
960 *
961 * @file: file handler to access wmi_handle
962 * @buf: received data buffer
963 * @count: length of received buffer
964 * @ppos: Not used
965 *
966 * Return: count
967 */
968static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
969 size_t count, loff_t *ppos)
970{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530971 wmi_unified_t wmi_handle =
972 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530973 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530974 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530975
Pratik Gandhi795ab912017-05-03 20:15:50 +0530976 if ((!buf) || (count > 50))
977 return -EFAULT;
978
979 if (copy_from_user(locbuf, buf, count))
980 return -EFAULT;
981
982 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530983 if ((ret != 1) || ((k != 0) && (k != 1)))
984 return -EINVAL;
985
986 wmi_handle->log_info.wmi_logging_enable = k;
987 return count;
988}
989
990/**
991 * debug_wmi_log_size_write() - reserved.
992 *
993 * @file: file handler to access wmi_handle
994 * @buf: received data buffer
995 * @count: length of received buffer
996 * @ppos: Not used
997 *
998 * Return: count
999 */
1000static ssize_t debug_wmi_log_size_write(struct file *file,
1001 const char __user *buf, size_t count, loff_t *ppos)
1002{
1003 return -EINVAL;
1004}
1005
1006/* Structure to maintain debug information */
1007struct wmi_debugfs_info {
1008 const char *name;
1009 struct dentry *de[MAX_WMI_INSTANCES];
1010 const struct file_operations *ops;
1011};
1012
1013#define DEBUG_FOO(func_base) { .name = #func_base, \
1014 .ops = &debug_##func_base##_ops }
1015
1016/**
1017 * debug_##func_base##_open() - Open debugfs entry for respective command
1018 * and event buffer.
1019 *
1020 * @inode: node for debug dir entry
1021 * @file: file handler
1022 *
1023 * Return: open status
1024 */
1025#define GENERATE_DEBUG_STRUCTS(func_base) \
1026 static int debug_##func_base##_open(struct inode *inode, \
1027 struct file *file) \
1028 { \
1029 return single_open(file, debug_##func_base##_show, \
1030 inode->i_private); \
1031 } \
1032 \
1033 \
1034 static struct file_operations debug_##func_base##_ops = { \
1035 .open = debug_##func_base##_open, \
1036 .read = seq_read, \
1037 .llseek = seq_lseek, \
1038 .write = debug_##func_base##_write, \
1039 .release = single_release, \
1040 };
1041
1042GENERATE_DEBUG_STRUCTS(wmi_command_log);
1043GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1044GENERATE_DEBUG_STRUCTS(wmi_event_log);
1045GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1046GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1047GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1048GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1049GENERATE_DEBUG_STRUCTS(wmi_enable);
1050GENERATE_DEBUG_STRUCTS(wmi_log_size);
1051
1052struct wmi_debugfs_info wmi_debugfs_infos[] = {
1053 DEBUG_FOO(wmi_command_log),
1054 DEBUG_FOO(wmi_command_tx_cmp_log),
1055 DEBUG_FOO(wmi_event_log),
1056 DEBUG_FOO(wmi_rx_event_log),
1057 DEBUG_FOO(wmi_mgmt_command_log),
1058 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1059 DEBUG_FOO(wmi_mgmt_event_log),
1060 DEBUG_FOO(wmi_enable),
1061 DEBUG_FOO(wmi_log_size),
1062};
1063
1064#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1065 sizeof(wmi_debugfs_infos[0]))
1066
1067/**
1068 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1069 *
1070 * @wmi_handle: wmi handle
1071 * @par_entry: debug directory entry
1072 * @id: Index to debug info data array
1073 *
1074 * Return: none
1075 */
1076static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1077 struct dentry *par_entry, int id)
1078{
1079 int i;
1080
1081 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1082 goto out;
1083
1084 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1085
1086 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1087 wmi_debugfs_infos[i].name, 0644, par_entry,
1088 wmi_handle, wmi_debugfs_infos[i].ops);
1089
1090 if (wmi_debugfs_infos[i].de[id] == NULL) {
1091 qdf_print("%s: debug Entry creation failed!\n",
1092 __func__);
1093 goto out;
1094 }
1095 }
1096
1097 return;
1098
1099out:
1100 qdf_print("%s: debug Entry creation failed!\n", __func__);
1101 wmi_log_buffer_free(wmi_handle);
1102 return;
1103}
1104
1105/**
1106 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301107 * @wmi_handle: wmi handle
1108 * @dentry: debugfs directory entry
1109 * @id: Index to debug info data array
1110 *
1111 * Return: none
1112 */
Govind Singh06c18392016-06-10 10:33:19 +05301113static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301114{
1115 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301116 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
1117 int id = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301118
1119 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1120 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1121 if (wmi_debugfs_infos[i].de[id])
1122 wmi_debugfs_infos[i].de[id] = NULL;
1123 }
1124 }
1125
1126 if (dentry)
1127 debugfs_remove_recursive(dentry);
1128}
1129
1130/**
1131 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1132 * create debugfs enteries.
1133 *
1134 * @h: wmi handler
1135 *
1136 * Return: init status
1137 */
1138static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1139{
1140 static int wmi_index;
1141
1142 if (wmi_index < MAX_WMI_INSTANCES)
1143 wmi_handle->log_info.wmi_log_debugfs_dir =
1144 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1145
1146 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
1147 qdf_print("error while creating debugfs dir for %s\n",
1148 debugfs_dir[wmi_index]);
1149 return QDF_STATUS_E_FAILURE;
1150 }
1151
1152 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
1153 wmi_index);
1154 wmi_handle->log_info.wmi_instance_id = wmi_index++;
1155
1156 return QDF_STATUS_SUCCESS;
1157}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001158
1159/**
1160 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1161 *
1162 * @wmi_handle: wmi handle
1163 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001164 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001165 * @vdev_id: vdev id
1166 * @chanfreq: channel frequency
1167 *
1168 * Return: none
1169 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301170void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001171 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001172{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301173
1174 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1175
1176 data[0] = ((struct wmi_command_header *)header)->type;
1177 data[1] = ((struct wmi_command_header *)header)->sub_type;
1178 data[2] = vdev_id;
1179 data[3] = chanfreq;
1180
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001181 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1182
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301183 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001184
1185 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1186}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001187#else
1188/**
1189 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1190 * @wmi_handle: wmi handle
1191 * @dentry: debugfs directory entry
1192 * @id: Index to debug info data array
1193 *
1194 * Return: none
1195 */
Govind Singh06c18392016-06-10 10:33:19 +05301196static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301197void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001198 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301199static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301200#endif /*WMI_INTERFACE_EVENT_LOGGING */
1201
Govind Singh6b411b52016-03-06 19:55:02 +05301202int wmi_get_host_credits(wmi_unified_t wmi_handle);
1203/* WMI buffer APIs */
1204
1205#ifdef MEMORY_DEBUG
1206wmi_buf_t
1207wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301208 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301209{
1210 wmi_buf_t wmi_buf;
1211
1212 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301213 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301214 return NULL;
1215 }
1216
Govind Singhb53420c2016-03-09 14:32:57 +05301217 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301218 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1219 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1220 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301221
1222 if (!wmi_buf)
1223 return NULL;
1224
1225 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301226 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301227
1228 /*
1229 * Set the length of the buffer to match the allocation size.
1230 */
Govind Singhb53420c2016-03-09 14:32:57 +05301231 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301232
1233 return wmi_buf;
1234}
1235
1236void wmi_buf_free(wmi_buf_t net_buf)
1237{
Govind Singhb53420c2016-03-09 14:32:57 +05301238 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301239}
1240#else
1241wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1242{
1243 wmi_buf_t wmi_buf;
1244
1245 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301246 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301247 return NULL;
1248 }
1249
Govind Singhb53420c2016-03-09 14:32:57 +05301250 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301251 WMI_MIN_HEAD_ROOM, 4, false);
1252 if (!wmi_buf)
1253 return NULL;
1254
1255 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301256 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301257
1258 /*
1259 * Set the length of the buffer to match the allocation size.
1260 */
Govind Singhb53420c2016-03-09 14:32:57 +05301261 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301262 return wmi_buf;
1263}
1264
1265void wmi_buf_free(wmi_buf_t net_buf)
1266{
Govind Singhb53420c2016-03-09 14:32:57 +05301267 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301268}
1269#endif
1270
1271/**
1272 * wmi_get_max_msg_len() - get maximum WMI message length
1273 * @wmi_handle: WMI handle.
1274 *
1275 * This function returns the maximum WMI message length
1276 *
1277 * Return: maximum WMI message length
1278 */
1279uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1280{
1281 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1282}
1283
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301284#ifdef CONFIG_MCL
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301285static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +05301286{
1287 switch (wmi_command) {
1288 /* initialize the wlan sub system */
1289 CASE_RETURN_STRING(WMI_INIT_CMDID);
1290
1291 /* Scan specific commands */
1292
1293 /* start scan request to FW */
1294 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1295 /* stop scan request to FW */
1296 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1297 /* full list of channels as defined by the regulatory
1298 * that will be used by scanner */
1299 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1300 /* overwrite default priority table in scan scheduler */
1301 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1302 /* This command to adjust the priority and min.max_rest_time
1303 * of an on ongoing scan request.
1304 */
1305 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1306
1307 /* PDEV(physical device) specific commands */
1308 /* set regulatorty ctl id used by FW to determine the exact
1309 * ctl power limits */
1310 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1311 /* set channel. mainly used for supporting monitor mode */
1312 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1313 /* set pdev specific parameters */
1314 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1315 /* enable packet log */
1316 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1317 /* disable packet log*/
1318 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1319 /* set wmm parameters */
1320 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1321 /* set HT cap ie that needs to be carried probe requests
1322 * HT/VHT channels */
1323 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1324 /* set VHT cap ie that needs to be carried on probe
1325 * requests on VHT channels */
1326 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1327
1328 /* Command to send the DSCP-to-TID map to the target */
1329 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1330 /* set quiet ie parameters. primarily used in AP mode */
1331 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1332 /* Enable/Disable Green AP Power Save */
1333 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1334 /* get TPC config for the current operating channel */
1335 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1336
1337 /* set the base MAC address for the physical device before
1338 * a VDEV is created. For firmware that does not support
1339 * this feature and this command, the pdev MAC address will
1340 * not be changed. */
1341 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1342
1343 /* eeprom content dump , the same to bdboard data */
1344 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1345
1346 /* VDEV(virtual device) specific commands */
1347 /* vdev create */
1348 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1349 /* vdev delete */
1350 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1351 /* vdev start request */
1352 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1353 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1354 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1355 /* vdev up request */
1356 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1357 /* vdev stop request */
1358 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1359 /* vdev down request */
1360 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1361 /* set a vdev param */
1362 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1363 /* set a key (used for setting per peer unicast
1364 * and per vdev multicast) */
1365 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1366
1367 /* wnm sleep mode command */
1368 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1369 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1370 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1371 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1372 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1373 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1374
1375 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1376 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1377 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1378 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1379
1380 /* peer specific commands */
1381
1382 /** create a peer */
1383 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1384 /** delete a peer */
1385 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1386 /** flush specific tid queues of a peer */
1387 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1388 /** set a parameter of a peer */
1389 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1390 /* set peer to associated state. will cary all parameters
1391 * determined during assocication time */
1392 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1393 /* add a wds (4 address ) entry. used only for testing
1394 * WDS feature on AP products */
1395 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1396 /* remove wds (4 address ) entry. used only for testing WDS
1397 * feature on AP products */
1398 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1399 /* set up mcast info for multicast to unicast conversion */
1400 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1401 /* request peer info from FW to get PEER_INFO_EVENTID */
1402 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1403
1404 /* beacon/management specific commands */
1405
1406 /* transmit beacon by reference. used for transmitting beacon
1407 * on low latency interface like pcie */
1408 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1409 /* transmit beacon by value */
1410 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1411 /* set the beacon template. used in beacon offload mode to setup
1412 * the common beacon template with the FW to be used by FW to
1413 * generate beacons */
1414 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1415 /* set beacon filter with FW */
1416 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1417 /* enable/disable filtering of probe requests in the firmware */
1418 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1419 /* transmit management frame by value. will be deprecated */
1420 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1421 /* set the probe response template. used in beacon offload mode
1422 * to setup the common probe response template with the FW to
1423 * be used by FW to generate probe responses */
1424 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1425
1426 /* commands to directly control ba negotiation directly from
1427 * host. only used in test mode */
1428
1429 /* turn off FW Auto addba mode and let host control addba */
1430 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1431 /* send add ba request */
1432 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1433 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1434 /* send del ba */
1435 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1436 /* set add ba response will be used by FW to generate
1437 * addba response*/
1438 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1439 /* send single VHT MPDU with AMSDU */
1440 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1441
1442 /* Station power save specific config */
1443 /* enable/disable station powersave */
1444 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1445 /* set station power save specific parameter */
1446 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1447 /* set station mimo powersave mode */
1448 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1449
1450 /* DFS-specific commands */
1451 /* enable DFS (radar detection)*/
1452 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1453 /* disable DFS (radar detection)*/
1454 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1455 /* enable DFS phyerr/parse filter offload */
1456 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1457 /* enable DFS phyerr/parse filter offload */
1458 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1459
1460 /* Roaming specific commands */
1461 /* set roam scan mode */
1462 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1463 /* set roam scan rssi threshold below which roam
1464 * scan is enabled */
1465 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1466 /* set roam scan period for periodic roam scan mode */
1467 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1468 /* set roam scan trigger rssi change threshold */
1469 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1470 /* set roam AP profile */
1471 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1472 /* set channel list for roam scans */
1473 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1474 /* offload scan specific commands */
1475 /* set offload scan AP profile */
1476 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1477 /* remove offload scan AP profile */
1478 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1479 /* set offload scan period */
1480 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1481
1482 /* P2P specific commands */
1483 /* set P2P device info. FW will used by FW to create P2P IE
1484 * to be carried in probe response generated during p2p listen
1485 * and for p2p discoverability */
1486 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1487 /* enable/disable p2p discoverability on STA/AP VDEVs */
1488 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1489 /* set p2p ie to be carried in beacons generated by FW for GO */
1490 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1491 /* set p2p ie to be carried in probe response frames generated
1492 * by FW for GO */
1493 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1494 /* set the vendor specific p2p ie data.
1495 * FW will use this to parse the P2P NoA
1496 * attribute in the beacons/probe responses received.
1497 */
1498 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1499 /* set the configure of p2p find offload */
1500 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1501 /* set the vendor specific p2p ie data for p2p find offload */
1502 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1503 /* set the BSSID/device name pattern of p2p find offload */
1504 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1505 /* set OppPS related parameters **/
1506 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1507
1508 /* AP power save specific config
1509 * set AP power save specific param */
1510 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1511 /* set AP UAPSD coex pecific param */
1512 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1513
1514 /* Rate-control specific commands */
1515 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1516
1517 /* WLAN Profiling commands. */
1518 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1519 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1520 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1521 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1522 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1523
1524 /* Suspend resume command Ids */
1525 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1526 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1527
1528 /* Beacon filter commands */
1529 /* add a beacon filter */
1530 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1531 /* remove a beacon filter */
1532 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1533
1534 /* WOW Specific WMI commands */
1535 /* add pattern for awake */
1536 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1537 /* deleta a wake pattern */
1538 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1539 /* enable/deisable wake event */
1540 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1541 /* enable WOW */
1542 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1543 /* host woke up from sleep event to FW. Generated in response
1544 * to WOW Hardware event */
1545 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1546
1547 /* RTT measurement related cmd */
1548 /* reques to make an RTT measurement */
1549 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1550 /* reques to report a tsf measurement */
1551 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1552
1553 /* spectral scan command */
1554 /* configure spectral scan */
1555 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1556 /* enable/disable spectral scan and trigger */
1557 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1558
1559 /* F/W stats */
1560 /* one time request for stats */
1561 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1562 /* Push MCC Adaptive Scheduler Stats to Firmware */
1563 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1564
1565 /* ARP OFFLOAD REQUEST*/
1566 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1567
1568 /* Proactive ARP Response Add Pattern Command*/
1569 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1570
1571 /* Proactive ARP Response Del Pattern Command*/
1572 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1573
1574 /* NS offload confid*/
1575 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1576
1577 /* GTK offload Specific WMI commands */
1578 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1579
1580 /* CSA offload Specific WMI commands */
1581 /* csa offload enable */
1582 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1583 /* chan switch command */
1584 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1585
1586 /* Chatter commands */
1587 /* Change chatter mode of operation */
1588 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1589 /* chatter add coalescing filter command */
1590 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1591 /* chatter delete coalescing filter command */
1592 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1593 /* chatter coalecing query command */
1594 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1595
1596 /* addba specific commands */
1597 /* start the aggregation on this TID */
1598 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1599 /* stop the aggregation on this TID */
1600 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1601
1602 /* set station mimo powersave method */
1603 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1604 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1605 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1606 /* Configure the Keep Alive Parameters */
1607 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1608
1609 /* Request ssn from target for a sta/tid pair */
1610 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1611 /* misc command group */
1612 /* echo command mainly used for testing */
1613 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1614
1615 /* !!IMPORTANT!!
1616 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1617 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1618 * as we MUST have a fixed value here to maintain compatibility between
1619 * UTF and the ART2 driver
1620 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301621 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301622 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1623
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301624 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301625 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1626 /* QVIT specific command id */
1627 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1628 /* Factory Testing Mode request command
1629 * used for integrated chipsets */
1630 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1631 /* set and get keepalive parameters command */
1632 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1633 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1634 /* For fw recovery test command */
1635 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1636 /* Set Mcast/Bdcast filter */
1637 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1638 /* set thermal management params */
1639 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1640 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1641 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1642 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301643 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301644 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301645 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301646 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301647 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1648 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1649 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1650 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1651 /* GPIO Configuration */
1652 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1653 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1654
1655 /* Txbf configuration command */
1656 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1657
1658 /* FWTEST Commands */
1659 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1660 /* set NoA descs */
1661 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1662
1663 /* TDLS Configuration */
1664 /* enable/disable TDLS */
1665 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1666 /* set tdls peer state */
1667 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1668
1669 /* Resmgr Configuration */
1670 /* Adaptive OCS is enabled by default in the FW.
1671 * This command is used to disable FW based adaptive OCS.
1672 */
1673 CASE_RETURN_STRING
1674 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1675 /* set the requested channel time quota for the home channels */
1676 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1677 /* set the requested latency for the home channels */
1678 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1679
1680 /* STA SMPS Configuration */
1681 /* force SMPS mode */
1682 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1683 /* set SMPS parameters */
1684 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1685
1686 /* Wlan HB commands */
1687 /* enalbe/disable wlan HB */
1688 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1689 /* set tcp parameters for wlan HB */
1690 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1691 /* set tcp pkt filter for wlan HB */
1692 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1693 /* set udp parameters for wlan HB */
1694 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1695 /* set udp pkt filter for wlan HB */
1696 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1697
1698 /* Wlan RMC commands*/
1699 /* enable/disable RMC */
1700 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1701 /* configure action frame period */
1702 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1703 /* For debug/future enhancement purposes only,
1704 * configures/finetunes RMC algorithms */
1705 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1706
1707 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301708 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301709 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1710 /* Plumb routing table for MHF offload */
1711 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1712
1713 /* location scan commands */
1714 /* start batch scan */
1715 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1716 /* stop batch scan */
1717 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1718 /* get batch scan result */
1719 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1720 /* OEM related cmd */
1721 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1722 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1723 /* NAN request cmd */
1724 CASE_RETURN_STRING(WMI_NAN_CMDID);
1725 /* Modem power state cmd */
1726 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1727 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1728 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1729 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1730 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1731 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1732 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1733 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1734 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301735 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301736 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1737 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1738 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1739 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1740 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1741 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1742 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1743 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1744 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1745 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1746 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1747 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1748 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1749 CASE_RETURN_STRING
1750 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1751 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1752 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1753 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1754 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1755 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1756 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1757 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1758 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1759 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1760 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1761 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1762 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1763 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1764 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1765 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1766 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1767 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1768 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1769 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1770 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1771 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1772 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1773 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1774 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1775 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1776 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1777 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1778 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1779 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1780 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1781 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1782 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1783 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1784 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1785 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1786 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1787 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1788 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1789 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1790 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1791 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1792 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1793 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1794 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1795 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1796 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1797 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1798 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1799 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1800 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1801 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1802 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1803 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1804 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1805 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1806 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1807 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1808 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1809 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1810 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301811 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1812 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1813 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1814 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1815 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1816 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1817 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1818 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1819 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1820 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1821 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1822 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1823 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1824 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1825 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1826 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1827 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1828 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1829 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1830 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1831 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1832 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1833 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1834 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1835 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1836 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1837 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1838 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1839 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1840 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1841 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1842 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1843 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001844 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301845 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301846 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301847 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301848 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Himanshu Agarwaldc8d1ae2016-05-13 21:04:17 +05301849 CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
Himanshu Agarwalfc302f92016-05-30 21:06:16 +05301850 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
1851 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
Pradeep Reddy POTTETI18f8fbb2016-06-13 17:59:38 +05301852 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1853 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
Pradeep Reddy POTTETI4b997fd2016-06-20 13:25:31 +05301854 CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
Pradeep Reddy POTTETI10ca69d2016-06-20 14:50:42 +05301855 CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
Nitesh Shah70e11042016-06-29 20:16:16 +05301856 CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
1857 CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
Nitesh Shahc0482652016-07-08 11:45:33 +05301858 CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
Nitesh Shah33b95402016-07-21 17:25:55 +05301859 CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
1860 CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
Anurag Chouhan40865b42016-08-01 14:01:54 +05301861 CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
Anurag Chouhan7f6f1d52016-08-04 18:46:29 +05301862 CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
Manjeet Singhc026bde2016-09-01 16:42:29 +05301863 CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
Manjeet Singhbea16712016-08-18 15:50:30 +05301864 CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
1865 CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
Himanshu Agarwal91c9d672016-09-14 20:43:24 +05301866 CASE_RETURN_STRING(WMI_VDEV_ENCRYPT_DECRYPT_DATA_REQ_CMDID);
Sandeep Puligillaabcd0f52016-11-03 12:38:45 -07001867 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
1868 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_DISABLE_CMDID);
1869 CASE_RETURN_STRING(WMI_VDEV_ADFS_CH_CFG_CMDID);
1870 CASE_RETURN_STRING(WMI_VDEV_ADFS_OCAC_ABORT_CMDID);
Nishank Aggarwale6994d22016-11-08 13:34:12 +05301871 CASE_RETURN_STRING(WMI_SAR_LIMITS_CMDID);
Kiran Kumar Lokeredaf91e32017-04-24 00:56:03 -07001872 CASE_RETURN_STRING(WMI_SET_CURRENT_COUNTRY_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301873 }
1874
1875 return "Invalid WMI cmd";
1876}
1877
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301878static inline void wma_log_cmd_id(uint32_t cmd_id, uint32_t tag)
Govind Singh6b411b52016-03-06 19:55:02 +05301879{
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301880 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1881 wmi_id_to_name(cmd_id), cmd_id, tag);
Govind Singh6b411b52016-03-06 19:55:02 +05301882}
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001883#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301884static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301885{
1886 return "Invalid WMI cmd";
1887}
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301888#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301889
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301890#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05301891/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301892 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1893 * @cmd_id: command to check
1894 *
1895 * Return: true if the command is part of the resume sequence.
1896 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301897static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301898{
1899 switch (cmd_id) {
1900 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1901 case WMI_PDEV_RESUME_CMDID:
1902 return true;
1903
1904 default:
1905 return false;
1906 }
1907}
1908#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301909static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301910{
1911 return false;
1912}
1913#endif
1914
1915/**
Govind Singh6b411b52016-03-06 19:55:02 +05301916 * wmi_unified_cmd_send() - WMI command API
1917 * @wmi_handle: handle to wmi
1918 * @buf: wmi buf
1919 * @len: wmi buffer length
1920 * @cmd_id: wmi command id
1921 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001922 * Note, it is NOT safe to access buf after calling this function!
1923 *
Govind Singh6b411b52016-03-06 19:55:02 +05301924 * Return: 0 on success
1925 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001926QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1927 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301928{
1929 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301930 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301931 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301932
1933 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301934 htc_tag =
1935 (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
1936 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301937 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301938 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301939 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301940 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301941 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301942 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301943 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301944 if (wmi_handle->wmi_stopinprogress) {
1945 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1946 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001947 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301948 }
Govind Singh6b411b52016-03-06 19:55:02 +05301949
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301950#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301951 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301952 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301953 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301954
1955 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301956 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301957 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301958 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301959 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301960 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301961 }
1962 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301963#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301964
Govind Singhb53420c2016-03-09 14:32:57 +05301965 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1966 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301967 "%s, Failed to send cmd %x, no memory",
1968 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301969 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301970 }
1971
Govind Singhb53420c2016-03-09 14:32:57 +05301972 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301973
Govind Singhb53420c2016-03-09 14:32:57 +05301974 qdf_atomic_inc(&wmi_handle->pending_cmds);
1975 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1976 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301977 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301978 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301979 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301980 qdf_atomic_dec(&wmi_handle->pending_cmds);
1981 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301982 "%s: MAX %d WMI Pending cmds reached.", __func__,
1983 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301984 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301985 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301986 }
1987
Govind Singhb53420c2016-03-09 14:32:57 +05301988 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301989 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301990 qdf_atomic_dec(&wmi_handle->pending_cmds);
1991 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301992 "%s, Failed to alloc htc packet %x, no memory",
1993 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301994 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301995 }
1996
1997 SET_HTC_PACKET_INFO_TX(pkt,
1998 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301999 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05302000 wmi_handle->wmi_endpoint_id, htc_tag);
2001
2002 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302003#ifdef CONFIG_MCL
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05302004 wma_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302005#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302006
2007#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302008 if (wmi_handle->log_info.wmi_logging_enable) {
2009 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05302010 /*Record 16 bytes of WMI cmd data -
2011 * * exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302012 if (wmi_handle->ops->is_management_record(cmd_id)) {
Pratik Gandhi29e33f02016-09-16 01:32:51 +05302013 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
2014 ((uint32_t *) qdf_nbuf_data(buf) +
2015 wmi_handle->log_info.buf_offset_command));
2016 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302017 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
2018 ((uint32_t *) qdf_nbuf_data(buf) +
2019 wmi_handle->log_info.buf_offset_command));
2020 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302021 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2022 }
Govind Singh6b411b52016-03-06 19:55:02 +05302023#endif
2024
2025 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
2026
Rakesh Pillai943a6c12017-06-22 12:52:31 +05302027 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05302028 qdf_atomic_dec(&wmi_handle->pending_cmds);
2029 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302030 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07002031 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05302032 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05302033 }
Govind Singh6b411b52016-03-06 19:55:02 +05302034
Govind Singhb53420c2016-03-09 14:32:57 +05302035 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302036}
2037
2038/**
2039 * wmi_unified_get_event_handler_ix() - gives event handler's index
2040 * @wmi_handle: handle to wmi
2041 * @event_id: wmi event id
2042 *
2043 * Return: event handler's index
2044 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002045static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
2046 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302047{
2048 uint32_t idx = 0;
2049 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302050 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302051
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302052 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05302053 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
2054 if (wmi_handle->event_id[idx] == event_id &&
2055 wmi_handle->event_handler[idx] != NULL) {
2056 return idx;
2057 }
2058 }
2059
2060 return invalid_idx;
2061}
2062
2063/**
Soumya Bhat488092d2017-03-22 14:41:01 +05302064 * wmi_unified_register_event() - register wmi event handler
2065 * @wmi_handle: handle to wmi
2066 * @event_id: wmi event id
2067 * @handler_func: wmi event handler function
2068 *
2069 * Return: 0 on success
2070 */
2071int wmi_unified_register_event(wmi_unified_t wmi_handle,
2072 uint32_t event_id,
2073 wmi_unified_event_handler handler_func)
2074{
2075 uint32_t idx = 0;
2076 uint32_t evt_id;
2077 struct wmi_soc *soc = wmi_handle->soc;
2078
2079 if (event_id >= wmi_events_max ||
2080 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2081 qdf_print("%s: Event id %d is unavailable\n",
2082 __func__, event_id);
2083 return QDF_STATUS_E_FAILURE;
2084 }
2085 evt_id = wmi_handle->wmi_events[event_id];
2086 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2087 qdf_print("%s : event handler already registered 0x%x\n",
2088 __func__, evt_id);
2089 return QDF_STATUS_E_FAILURE;
2090 }
2091 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
2092 qdf_print("%s : no more event handlers 0x%x\n",
2093 __func__, evt_id);
2094 return QDF_STATUS_E_FAILURE;
2095 }
2096 idx = soc->max_event_idx;
2097 wmi_handle->event_handler[idx] = handler_func;
2098 wmi_handle->event_id[idx] = evt_id;
2099 qdf_spin_lock_bh(&soc->ctx_lock);
2100 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
2101 qdf_spin_unlock_bh(&soc->ctx_lock);
2102 soc->max_event_idx++;
2103
2104 return 0;
2105}
2106
2107/**
Govind Singh6b411b52016-03-06 19:55:02 +05302108 * wmi_unified_register_event_handler() - register wmi event handler
2109 * @wmi_handle: handle to wmi
2110 * @event_id: wmi event id
2111 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05302112 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05302113 *
Soumya Bhat488092d2017-03-22 14:41:01 +05302114 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05302115 * Return: 0 on success
2116 */
2117int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302118 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05302119 wmi_unified_event_handler handler_func,
2120 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302121{
2122 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302123 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302124 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302125
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302126#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302127 if (event_id >= wmi_events_max ||
2128 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2129 qdf_print("%s: Event id %d is unavailable\n",
2130 __func__, event_id);
2131 return QDF_STATUS_E_FAILURE;
2132 }
2133 evt_id = wmi_handle->wmi_events[event_id];
2134#else
2135 evt_id = event_id;
2136#endif
2137 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2138 qdf_print("%s : event handler already registered 0x%x\n",
2139 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302140 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302141 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302142 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302143 qdf_print("%s : no more event handlers 0x%x\n",
2144 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302145 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302146 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07002147 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
2148 "Registered event handler for event 0x%8x\n", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302149 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302150 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302151 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302152 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302153 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302154 qdf_spin_unlock_bh(&soc->ctx_lock);
2155 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05302156
2157 return 0;
2158}
2159
2160/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05302161 * wmi_unified_unregister_event() - unregister wmi event handler
2162 * @wmi_handle: handle to wmi
2163 * @event_id: wmi event id
2164 *
2165 * Return: 0 on success
2166 */
2167int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
2168 uint32_t event_id)
2169{
2170 uint32_t idx = 0;
2171 uint32_t evt_id;
2172 struct wmi_soc *soc = wmi_handle->soc;
2173
2174 if (event_id >= wmi_events_max ||
2175 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2176 qdf_print("%s: Event id %d is unavailable\n",
2177 __func__, event_id);
2178 return QDF_STATUS_E_FAILURE;
2179 }
2180 evt_id = wmi_handle->wmi_events[event_id];
2181
2182 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
2183 if (idx == -1) {
2184 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2185 __func__, evt_id);
2186 return QDF_STATUS_E_FAILURE;
2187 }
2188 wmi_handle->event_handler[idx] = NULL;
2189 wmi_handle->event_id[idx] = 0;
2190 --soc->max_event_idx;
2191 wmi_handle->event_handler[idx] =
2192 wmi_handle->event_handler[soc->max_event_idx];
2193 wmi_handle->event_id[idx] =
2194 wmi_handle->event_id[soc->max_event_idx];
2195
2196 return 0;
2197}
2198
2199/**
Govind Singh6b411b52016-03-06 19:55:02 +05302200 * wmi_unified_unregister_event_handler() - unregister wmi event handler
2201 * @wmi_handle: handle to wmi
2202 * @event_id: wmi event id
2203 *
2204 * Return: 0 on success
2205 */
2206int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302207 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302208{
2209 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302210 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302211 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302212
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302213#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302214 if (event_id >= wmi_events_max ||
2215 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2216 qdf_print("%s: Event id %d is unavailable\n",
2217 __func__, event_id);
2218 return QDF_STATUS_E_FAILURE;
2219 }
2220 evt_id = wmi_handle->wmi_events[event_id];
2221#else
2222 evt_id = event_id;
2223#endif
2224
2225 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302226 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302227 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2228 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302229 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302230 }
2231 wmi_handle->event_handler[idx] = NULL;
2232 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302233 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302234 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302235 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302236 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302237 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302238
2239 return 0;
2240}
2241
2242/**
Govind Singhd52faac2016-03-09 12:03:29 +05302243 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302244 * @wmi_handle: handle to wmi
2245 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302246 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05302247 *
Govind Singhd52faac2016-03-09 12:03:29 +05302248 * Event process by below function will be in default caller context.
2249 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05302250 *
2251 * Return: none
2252 */
Govind Singhd52faac2016-03-09 12:03:29 +05302253static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
2254 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302255{
2256 wmi_buf_t evt_buf;
2257 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
2258
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302259#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302260 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
2261 (wmi_handle->scn_handle, evt_buf, exec_ctx);
2262#else
Govind Singh5eb51532016-03-09 11:34:12 +05302263 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05302264 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302265#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302266
Govind Singh6b411b52016-03-06 19:55:02 +05302267 return;
2268}
2269
2270/**
2271 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
2272 * @wmi_handle: handle to wmi
2273 * @htc_packet: pointer to htc packet
2274 *
2275 * Event process by below function will be in worker thread context.
2276 * Use this method for events which are not critical and not
2277 * handled in protocol stack.
2278 *
2279 * Return: none
2280 */
2281static void wmi_process_fw_event_worker_thread_ctx
2282 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
2283{
2284 wmi_buf_t evt_buf;
2285 uint32_t id;
2286 uint8_t *data;
2287
2288 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302289 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
2290 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302291
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302292#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302293 if (wmi_handle->log_info.wmi_logging_enable) {
2294 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2295 /* Exclude 4 bytes of TLV header */
2296 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2297 wmi_handle->log_info.buf_offset_event));
2298 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2299 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302300#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302301 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2302 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
2303 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002304 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
2305 &wmi_handle->rx_event_work);
2306
Govind Singh6b411b52016-03-06 19:55:02 +05302307 return;
2308}
2309
2310/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302311 * wmi_get_pdev_ep: Get wmi handle based on endpoint
2312 * @soc: handle to wmi soc
2313 * @ep: endpoint id
2314 *
2315 * Return: none
2316 */
2317static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
2318 HTC_ENDPOINT_ID ep)
2319{
2320 uint32_t i;
2321
2322 for (i = 0; i < WMI_MAX_RADIOS; i++)
2323 if (soc->wmi_endpoint_id[i] == ep)
2324 break;
2325
2326 if (i == WMI_MAX_RADIOS)
2327 return NULL;
2328
2329 return soc->wmi_pdev[i];
2330}
2331
2332/**
Govind Singhd52faac2016-03-09 12:03:29 +05302333 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302334 * @ctx: handle to wmi
2335 * @htc_packet: pointer to htc packet
2336 *
Govind Singh6b411b52016-03-06 19:55:02 +05302337 * Return: none
2338 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002339static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05302340{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302341 struct wmi_soc *soc = (struct wmi_soc *) ctx;
2342 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302343 wmi_buf_t evt_buf;
2344 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302345 uint32_t idx = 0;
2346 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302347
2348 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302349
2350 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
2351 if (wmi_handle == NULL) {
2352 qdf_print
2353 ("%s :unable to get wmi_handle to Endpoint %d\n",
2354 __func__, htc_packet->Endpoint);
2355 qdf_nbuf_free(evt_buf);
2356 return;
2357 }
2358
Govind Singhb53420c2016-03-09 14:32:57 +05302359 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302360 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302361 if (qdf_unlikely(idx == A_ERROR)) {
2362 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05302363 ("%s :event handler is not registered: event id 0x%x\n",
2364 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302365 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302366 return;
2367 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302368 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302369 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302370 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302371
2372 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302373 wmi_process_fw_event_worker_thread_ctx
2374 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302375 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2376 wmi_process_fw_event_default_ctx
2377 (wmi_handle, htc_packet, exec_ctx);
2378 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05302379 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
2380 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302381 }
Govind Singhd52faac2016-03-09 12:03:29 +05302382
Govind Singh6b411b52016-03-06 19:55:02 +05302383}
2384
2385/**
2386 * wmi_process_fw_event() - process any fw event
2387 * @wmi_handle: wmi handle
2388 * @evt_buf: fw event buffer
2389 *
Govind Singhd52faac2016-03-09 12:03:29 +05302390 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302391 *
2392 * Return: none
2393 */
2394void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2395{
2396 __wmi_control_rx(wmi_handle, evt_buf);
2397}
2398
2399/**
2400 * __wmi_control_rx() - process serialize wmi event callback
2401 * @wmi_handle: wmi handle
2402 * @evt_buf: fw event buffer
2403 *
2404 * Return: none
2405 */
2406void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2407{
2408 uint32_t id;
2409 uint8_t *data;
2410 uint32_t len;
2411 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302412#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302413 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302414#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302415 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302416
Govind Singhb53420c2016-03-09 14:32:57 +05302417 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302418
Govind Singhb53420c2016-03-09 14:32:57 +05302419 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302420 goto end;
2421
Govind Singhb53420c2016-03-09 14:32:57 +05302422 data = qdf_nbuf_data(evt_buf);
2423 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302424
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302425#ifndef WMI_NON_TLV_SUPPORT
2426 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2427 /* Validate and pad(if necessary) the TLVs */
2428 tlv_ok_status =
2429 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302430 data, len, id,
2431 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302432 if (tlv_ok_status != 0) {
2433 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2434 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2435 __func__, id, tlv_ok_status);
2436 goto end;
2437 }
Govind Singh6b411b52016-03-06 19:55:02 +05302438 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302439#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302440
Govind Singhd52faac2016-03-09 12:03:29 +05302441 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2442 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302443 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302444 "%s : event handler is not registered: event id 0x%x\n",
2445 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302446 goto end;
2447 }
Govind Singhd52faac2016-03-09 12:03:29 +05302448#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302449 if (wmi_handle->log_info.wmi_logging_enable) {
2450 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2451 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302452 if (wmi_handle->ops->is_management_record(id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302453 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2454 + wmi_handle->log_info.buf_offset_event));
2455 } else {
2456 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2457 wmi_handle->log_info.buf_offset_event));
2458 }
2459 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302460 }
Govind Singhd52faac2016-03-09 12:03:29 +05302461#endif
2462 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302463 if (wmi_handle->target_type == WMI_TLV_TARGET)
2464 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2465 wmi_cmd_struct_ptr, len);
2466 else
2467 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2468 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302469
Govind Singh6b411b52016-03-06 19:55:02 +05302470end:
Govind Singhd52faac2016-03-09 12:03:29 +05302471 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302472#ifndef WMI_NON_TLV_SUPPORT
2473 if (wmi_handle->target_type == WMI_TLV_TARGET)
2474 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2475#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302476
Govind Singhb53420c2016-03-09 14:32:57 +05302477 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302478
Govind Singh6b411b52016-03-06 19:55:02 +05302479}
2480
2481/**
2482 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002483 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05302484 *
2485 * This function process any fw event to serialize it through rx worker thread.
2486 *
2487 * Return: none
2488 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002489static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05302490{
Govind Singh6b411b52016-03-06 19:55:02 +05302491 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002492 struct wmi_unified *wmi = arg;
Govind Singh6b411b52016-03-06 19:55:02 +05302493
Govind Singhb53420c2016-03-09 14:32:57 +05302494 qdf_spin_lock_bh(&wmi->eventq_lock);
2495 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2496 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302497 while (buf) {
2498 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302499 qdf_spin_lock_bh(&wmi->eventq_lock);
2500 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2501 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302502 }
2503}
2504
Govind Singh6b411b52016-03-06 19:55:02 +05302505#ifdef FEATURE_RUNTIME_PM
2506/**
2507 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2508 * @wmi_handle: wmi context
2509 */
Govind Singhd52faac2016-03-09 12:03:29 +05302510static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302511{
Govind Singhb53420c2016-03-09 14:32:57 +05302512 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302513}
Govind Singhd52faac2016-03-09 12:03:29 +05302514
2515/**
2516 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2517 * @wmi_handle: wmi context
2518 * @val: runtime pm progress flag
2519 */
2520void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2521{
Govind Singhb53420c2016-03-09 14:32:57 +05302522 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302523}
2524
2525/**
2526 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2527 * @wmi_handle: wmi context
2528 */
2529inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2530{
Govind Singhb53420c2016-03-09 14:32:57 +05302531 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302532}
Govind Singh6b411b52016-03-06 19:55:02 +05302533#else
Govind Singhd52faac2016-03-09 12:03:29 +05302534static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302535{
2536}
2537#endif
2538
2539/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302540 * wmi_unified_get_soc_handle: Get WMI SoC handle
2541 * @param wmi_handle: WMI context got from wmi_attach
2542 *
2543 * return: Pointer to Soc handle
2544 */
2545void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2546{
2547 return wmi_handle->soc;
2548}
2549
2550/**
2551 * wmi_interface_logging_init: Interface looging init
2552 * @param wmi_handle: Pointer to wmi handle object
2553 *
2554 * return: None
2555 */
2556#ifdef WMI_INTERFACE_EVENT_LOGGING
2557static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2558{
2559 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2560 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2561 wmi_debugfs_init(wmi_handle);
2562 }
2563}
2564#else
2565void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2566{
2567}
2568#endif
2569
2570/**
2571 * wmi_target_params_init: Target specific params init
2572 * @param wmi_soc: Pointer to wmi soc object
2573 * @param wmi_handle: Pointer to wmi handle object
2574 *
2575 * return: None
2576 */
2577#ifndef CONFIG_MCL
2578static inline void wmi_target_params_init(struct wmi_soc *soc,
2579 struct wmi_unified *wmi_handle)
2580{
2581 /* WMI service bitmap recieved from target */
2582 wmi_handle->wmi_service_bitmap = soc->wmi_service_bitmap;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302583 wmi_handle->pdev_param = soc->pdev_param;
2584 wmi_handle->vdev_param = soc->vdev_param;
2585 wmi_handle->services = soc->services;
2586}
2587#else
2588static inline void wmi_target_params_init(struct wmi_soc *soc,
2589 struct wmi_unified *wmi_handle)
2590{
2591}
2592#endif
2593
2594/**
2595 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2596 * @param wmi_soc: Pointer to wmi soc object
2597 * @param pdev_idx: pdev index
2598 *
2599 * return: Pointer to wmi handle or NULL on failure
2600 */
2601void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2602{
2603 struct wmi_unified *wmi_handle;
2604
2605 if (pdev_idx >= WMI_MAX_RADIOS)
2606 return NULL;
2607
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302608 if (soc->wmi_pdev[pdev_idx] == NULL) {
2609 wmi_handle =
2610 (struct wmi_unified *) qdf_mem_malloc(
2611 sizeof(struct wmi_unified));
2612 if (wmi_handle == NULL) {
2613 qdf_print("allocation of wmi handle failed %zu\n",
2614 sizeof(struct wmi_unified));
2615 return NULL;
2616 }
2617 wmi_handle->scn_handle = soc->scn_handle;
2618 wmi_handle->event_id = soc->event_id;
2619 wmi_handle->event_handler = soc->event_handler;
2620 wmi_handle->ctx = soc->ctx;
2621 wmi_handle->ops = soc->ops;
2622 qdf_spinlock_create(&wmi_handle->eventq_lock);
2623 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302624
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302625 qdf_create_work(0, &wmi_handle->rx_event_work,
2626 wmi_rx_event_work, wmi_handle);
2627 wmi_handle->wmi_rx_work_queue =
2628 qdf_create_workqueue("wmi_rx_event_work_queue");
2629 if (NULL == wmi_handle->wmi_rx_work_queue) {
2630 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2631 goto error;
2632 }
2633 wmi_handle->wmi_events = soc->wmi_events;
2634 wmi_target_params_init(soc, wmi_handle);
2635 wmi_interface_logging_init(wmi_handle);
2636 qdf_atomic_init(&wmi_handle->pending_cmds);
2637 qdf_atomic_init(&wmi_handle->is_target_suspended);
2638 wmi_handle->target_type = soc->target_type;
2639 wmi_handle->soc = soc;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002640
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302641 soc->wmi_pdev[pdev_idx] = wmi_handle;
2642 } else
2643 wmi_handle = soc->wmi_pdev[pdev_idx];
2644
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302645 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302646 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2647 wmi_handle->htc_handle = soc->htc_handle;
2648 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302649
2650 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002651
2652error:
2653 qdf_mem_free(wmi_handle);
2654
2655 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302656}
2657
2658/**
Govind Singh6b411b52016-03-06 19:55:02 +05302659 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302660 * @scn_handle: handle to SCN
2661 * @osdev: OS device context
2662 * @target_type: TLV or not-TLV based target
2663 * @use_cookie: cookie based allocation enabled/disabled
2664 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302665 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302666 *
2667 * @Return: wmi handle.
2668 */
Govind Singhc458f382016-02-04 18:42:30 +05302669void *wmi_unified_attach(void *scn_handle,
2670 osdev_t osdev, enum wmi_target_type target_type,
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302671 bool use_cookie, struct wmi_rx_ops *rx_ops,
2672 struct wlan_objmgr_psoc *psoc)
Govind Singh6b411b52016-03-06 19:55:02 +05302673{
2674 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302675 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302676
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302677 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2678 if (soc == NULL) {
2679 qdf_print("Allocation of wmi_soc failed %zu\n",
2680 sizeof(struct wmi_soc));
2681 return NULL;
2682 }
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302683#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05302684 wmi_handle =
2685 (struct wmi_unified *)os_malloc(NULL,
2686 sizeof(struct wmi_unified),
2687 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302688#else
2689 wmi_handle =
2690 (struct wmi_unified *) qdf_mem_malloc(
2691 sizeof(struct wmi_unified));
2692#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302693 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302694 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302695 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302696 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302697 return NULL;
2698 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302699 wmi_handle->soc = soc;
2700 wmi_handle->event_id = soc->event_id;
2701 wmi_handle->event_handler = soc->event_handler;
2702 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302703 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302704 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302705 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302706 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302707 qdf_atomic_init(&wmi_handle->pending_cmds);
2708 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302709 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302710 qdf_spinlock_create(&wmi_handle->eventq_lock);
2711 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002712 qdf_create_work(0, &wmi_handle->rx_event_work,
2713 wmi_rx_event_work, wmi_handle);
2714 wmi_handle->wmi_rx_work_queue =
2715 qdf_create_workqueue("wmi_rx_event_work_queue");
2716 if (NULL == wmi_handle->wmi_rx_work_queue) {
2717 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2718 goto error;
2719 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302720 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302721 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302722 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2723 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302724 wmi_handle->target_type = target_type;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302725 soc->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302726 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302727 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302728 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302729 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302730 /* Assign target cookie capablity */
2731 wmi_handle->use_cookie = use_cookie;
2732 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302733 wmi_handle->wmi_stopinprogress = 0;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302734 /* Increase the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302735 soc->wmi_psoc = psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302736 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302737
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302738 soc->ops = wmi_handle->ops;
2739 soc->wmi_pdev[0] = wmi_handle;
2740
Govind Singh6b411b52016-03-06 19:55:02 +05302741 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002742
2743error:
2744 qdf_mem_free(soc);
2745 qdf_mem_free(wmi_handle);
2746
2747 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302748}
2749
2750/**
2751 * wmi_unified_detach() - detach for unified WMI
2752 *
2753 * @wmi_handle : handle to wmi.
2754 *
2755 * @Return: none.
2756 */
2757void wmi_unified_detach(struct wmi_unified *wmi_handle)
2758{
2759 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302760 struct wmi_soc *soc;
2761 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302762
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302763 soc = wmi_handle->soc;
2764 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2765 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002766 qdf_flush_workqueue(0,
2767 soc->wmi_pdev[i]->wmi_rx_work_queue);
2768 qdf_destroy_workqueue(0,
2769 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302770 wmi_debugfs_remove(soc->wmi_pdev[i]);
2771 buf = qdf_nbuf_queue_remove(
2772 &soc->wmi_pdev[i]->event_queue);
2773 while (buf) {
2774 qdf_nbuf_free(buf);
2775 buf = qdf_nbuf_queue_remove(
2776 &soc->wmi_pdev[i]->event_queue);
2777 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002778
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302779 wmi_log_buffer_free(soc->wmi_pdev[i]);
2780 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302781 qdf_mem_free(soc->wmi_pdev[i]);
2782 }
Govind Singh6b411b52016-03-06 19:55:02 +05302783 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302784 qdf_spinlock_destroy(&soc->ctx_lock);
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302785 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302786 soc->wmi_psoc = NULL;
2787 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302788}
2789
2790/**
2791 * wmi_unified_remove_work() - detach for WMI work
2792 * @wmi_handle: handle to WMI
2793 *
2794 * A function that does not fully detach WMI, but just remove work
2795 * queue items associated with it. This is used to make sure that
2796 * before any other processing code that may destroy related contexts
2797 * (HTC, etc), work queue processing on WMI has already been stopped.
2798 *
2799 * Return: None
2800 */
2801void
2802wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2803{
2804 wmi_buf_t buf;
2805
Govind Singhb53420c2016-03-09 14:32:57 +05302806 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302807 "Enter: %s", __func__);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002808 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302809 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2810 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302811 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302812 qdf_nbuf_free(buf);
2813 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302814 }
Govind Singhb53420c2016-03-09 14:32:57 +05302815 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2816 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302817 "Done: %s", __func__);
2818}
2819
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302820/**
2821 * wmi_htc_tx_complete() - Process htc tx completion
2822 *
2823 * @ctx: handle to wmi
2824 * @htc_packet: pointer to htc packet
2825 *
2826 * @Return: none.
2827 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002828static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302829{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302830 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302831 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302832 u_int8_t *buf_ptr;
2833 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302834 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302835#ifdef WMI_INTERFACE_EVENT_LOGGING
2836 uint32_t cmd_id;
2837#endif
2838
2839 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302840 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2841 if (wmi_handle == NULL) {
2842 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2843 QDF_ASSERT(0);
2844 return;
2845 }
Govind Singh6b411b52016-03-06 19:55:02 +05302846#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302847 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302848 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2849 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302850
Govind Singhecf03cd2016-05-12 12:45:51 +05302851 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302852 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302853 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302854 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302855 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2856 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2857 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302858 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302859 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2860 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2861 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302862 }
2863
Govind Singhecf03cd2016-05-12 12:45:51 +05302864 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2865 }
Govind Singh6b411b52016-03-06 19:55:02 +05302866#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302867 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2868 len = qdf_nbuf_len(wmi_cmd_buf);
2869 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302870 qdf_nbuf_free(wmi_cmd_buf);
2871 qdf_mem_free(htc_pkt);
2872 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302873}
2874
2875/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302876 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302877 *
2878 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302879 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302880 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302881 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302882 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302883static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2884 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302885{
Govind Singh6b411b52016-03-06 19:55:02 +05302886 int status;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302887 uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
2888 WMI_CONTROL_SVC_WMAC2};
Manikandan Mohanf940db82017-04-13 20:19:26 -07002889 struct htc_service_connect_resp response;
2890 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302891
2892 OS_MEMZERO(&connect, sizeof(connect));
2893 OS_MEMZERO(&response, sizeof(response));
2894
2895 /* meta data is unused for now */
2896 connect.pMetaData = NULL;
2897 connect.MetaDataLength = 0;
2898 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302899 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302900 connect.EpCallbacks.EpTxCompleteMultiple =
2901 NULL /* Control path completion ar6000_tx_complete */;
2902 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2903 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2904 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2905 connect.EpCallbacks.EpTxComplete =
2906 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2907
2908 /* connect to control service */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302909 connect.service_id = svc_id[pdev_idx];
2910 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302911 &response);
2912
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302913
Govind Singh6b411b52016-03-06 19:55:02 +05302914 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302915 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302916 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302917 status);
2918 return status;
2919 }
Govind Singh6b411b52016-03-06 19:55:02 +05302920
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302921 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2922 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2923
2924 return 0;
2925}
2926
2927/**
2928 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2929 *
2930 * @wmi_handle: handle to WMI.
2931 *
2932 * @Return: status.
2933 */
2934QDF_STATUS
2935wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2936 void *htc_handle)
2937{
2938 uint32_t i;
2939 uint8_t wmi_ep_count;
2940
2941 wmi_handle->soc->htc_handle = htc_handle;
2942
2943 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2944 if (wmi_ep_count > WMI_MAX_RADIOS)
2945 return QDF_STATUS_E_FAULT;
2946
2947 for (i = 0; i < wmi_ep_count; i++)
2948 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2949
2950 wmi_handle->htc_handle = htc_handle;
2951 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2952 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2953
2954 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302955}
2956
2957/**
2958 * wmi_get_host_credits() - WMI API to get updated host_credits
2959 *
2960 * @wmi_handle: handle to WMI.
2961 *
2962 * @Return: updated host_credits.
2963 */
2964int wmi_get_host_credits(wmi_unified_t wmi_handle)
2965{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302966 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302967
2968 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2969 &host_credits);
2970 return host_credits;
2971}
2972
2973/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302974 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2975 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302976 *
2977 * @wmi_handle: handle to WMI.
2978 *
2979 * @Return: Pending Commands in the HTC queue.
2980 */
2981int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2982{
Govind Singhb53420c2016-03-09 14:32:57 +05302983 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302984}
2985
2986/**
2987 * wmi_set_target_suspend() - WMI API to set target suspend state
2988 *
2989 * @wmi_handle: handle to WMI.
2990 * @val: suspend state boolean.
2991 *
2992 * @Return: none.
2993 */
2994void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2995{
Govind Singhb53420c2016-03-09 14:32:57 +05302996 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302997}
2998
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302999/**
3000 * WMI API to set crash injection state
3001 * @param wmi_handle: handle to WMI.
3002 * @param val: crash injection state boolean.
3003 */
3004void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
3005{
3006 wmi_handle->tag_crash_inject = flag;
3007}
3008
3009/**
3010 * WMI API to set bus suspend state
3011 * @param wmi_handle: handle to WMI.
3012 * @param val: suspend state boolean.
3013 */
3014void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
3015{
3016 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
3017}
3018
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05303019#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05303020/**
3021 * API to flush all the previous packets associated with the wmi endpoint
3022 *
3023 * @param wmi_handle : handle to WMI.
3024 */
3025void
3026wmi_flush_endpoint(wmi_unified_t wmi_handle)
3027{
3028 htc_flush_endpoint(wmi_handle->htc_handle,
3029 wmi_handle->wmi_endpoint_id, 0);
3030}
3031
3032/**
3033 * generic function to block unified WMI command
3034 * @param wmi_handle : handle to WMI.
3035 * @return 0 on success and -ve on failure.
3036 */
3037int
3038wmi_stop(wmi_unified_t wmi_handle)
3039{
3040 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
3041 "WMI Stop\n");
3042 wmi_handle->wmi_stopinprogress = 1;
3043 return 0;
3044}
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05303045
3046/**
3047 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
3048 * By default pdev_id conversion is not done in WMI.
3049 * This API can be used enable conversion in WMI.
3050 * @param wmi_handle : handle to WMI
3051 * Return none
3052 */
3053void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
3054{
3055 if (wmi_handle->target_type == WMI_TLV_TARGET)
3056 wmi_tlv_pdev_id_conversion_enable(wmi_handle);
3057}
3058
Govind Singhe7d9f3e2016-04-15 13:58:27 +05303059#endif