blob: f886fb209e4fcc71f01ba293311478e55a1f0524 [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 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -0700101static int qcacld_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);
106 seq_printf(m, f, args);
107 va_end(args);
108
109 return m->count;
110}
111
112#define seq_printf(m, fmt, ...) qcacld_bp_seq_printf((m), fmt, ##__VA_ARGS__)
113#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);\
Govind Singhecf03cd2016-05-12 12:45:51 +0530761 return seq_printf(m, \
762 "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 Gandhi29e33f02016-09-16 01:32:51 +0530776 outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
777 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]);\
783 outlen += seq_printf(m, "CMD ID = %x\n", \
784 (wmi_record->command)); \
785 outlen += seq_printf(m, "CMD = "); \
786 for (i = 0; i < (wmi_record_max_length/ \
787 sizeof(uint32_t)); i++) \
788 outlen += seq_printf(m, "%x ", \
789 wmi_record->data[i]); \
790 outlen += seq_printf(m, "\n"); \
791 \
792 if (pos == 0) \
793 pos = wmi_ring_size - 1; \
794 else \
795 pos--; \
796 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530797 \
798 return outlen; \
799 } \
800
801#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
802 static int debug_wmi_##func_base##_show(struct seq_file *m, \
803 void *v) \
804 { \
805 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
806 struct wmi_log_buf_t *wmi_log = \
807 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
808 int pos, nread, outlen; \
809 int i; \
810 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530811 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
812 if (!wmi_log->length) { \
813 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Govind Singhecf03cd2016-05-12 12:45:51 +0530814 return seq_printf(m, \
815 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530816 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530817 \
818 if (wmi_log->length <= wmi_ring_size) \
819 nread = wmi_log->length; \
820 else \
821 nread = wmi_ring_size; \
822 \
823 if (*(wmi_log->p_buf_tail_idx) == 0) \
824 /* tail can be 0 after wrap-around */ \
825 pos = wmi_ring_size - 1; \
826 else \
827 pos = *(wmi_log->p_buf_tail_idx) - 1; \
828 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530829 outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
830 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530831 while (nread--) { \
832 struct wmi_event_debug *wmi_record; \
833 \
834 wmi_record = (struct wmi_event_debug *) \
835 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
836 outlen += seq_printf(m, "Event ID = %x\n", \
837 (wmi_record->event)); \
838 outlen += seq_printf(m, "CMD = "); \
839 for (i = 0; i < (wmi_record_max_length/ \
840 sizeof(uint32_t)); i++) \
841 outlen += seq_printf(m, "%x ", \
842 wmi_record->data[i]); \
843 outlen += seq_printf(m, "\n"); \
844 \
845 if (pos == 0) \
846 pos = wmi_ring_size - 1; \
847 else \
848 pos--; \
849 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530850 \
851 return outlen; \
852 }
853
854GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
855GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
856GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
857GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
858GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
859GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
860 wmi_display_size);
861GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
862
863/**
864 * debug_wmi_enable_show() - debugfs functions to display enable state of
865 * wmi logging feature.
866 *
867 * @m: debugfs handler to access wmi_handle
868 * @v: Variable arguments (not used)
869 *
870 * Return: always 1
871 */
872static int debug_wmi_enable_show(struct seq_file *m, void *v)
873{
874 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
875
876 return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
877
878}
879
880/**
881 * debug_wmi_log_size_show() - debugfs functions to display configured size of
882 * wmi logging command/event buffer and management command/event buffer.
883 *
884 * @m: debugfs handler to access wmi_handle
885 * @v: Variable arguments (not used)
886 *
887 * Return: Length of characters printed
888 */
889static int debug_wmi_log_size_show(struct seq_file *m, void *v)
890{
891
892 seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
893 return seq_printf(m, "WMI management command/events log max size:%d\n",
894 wmi_mgmt_log_max_entry);
895}
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; \
918 \
919 ret = sscanf(buf, "%d", &k); \
920 if ((ret != 1) || (k != 0)) { \
921 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
922 return -EINVAL; \
923 } \
924 \
925 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
926 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
927 sizeof(struct wmi_record_type)); \
928 wmi_log->length = 0; \
929 *(wmi_log->p_buf_tail_idx) = 0; \
930 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
931 \
932 return count; \
933 }
934
935GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
936 wmi_command_debug);
937GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
938 wmi_command_debug);
939GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
940 wmi_event_debug);
941GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
942 wmi_event_debug);
943GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
944 wmi_command_debug);
945GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
946 wmi_mgmt_log_max_entry, wmi_command_debug);
947GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
948 wmi_event_debug);
949
950/**
951 * debug_wmi_enable_write() - debugfs functions to enable/disable
952 * wmi logging feature.
953 *
954 * @file: file handler to access wmi_handle
955 * @buf: received data buffer
956 * @count: length of received buffer
957 * @ppos: Not used
958 *
959 * Return: count
960 */
961static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
962 size_t count, loff_t *ppos)
963{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530964 wmi_unified_t wmi_handle =
965 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530966 int k, ret;
967
968 ret = sscanf(buf, "%d", &k);
969 if ((ret != 1) || ((k != 0) && (k != 1)))
970 return -EINVAL;
971
972 wmi_handle->log_info.wmi_logging_enable = k;
973 return count;
974}
975
976/**
977 * debug_wmi_log_size_write() - reserved.
978 *
979 * @file: file handler to access wmi_handle
980 * @buf: received data buffer
981 * @count: length of received buffer
982 * @ppos: Not used
983 *
984 * Return: count
985 */
986static ssize_t debug_wmi_log_size_write(struct file *file,
987 const char __user *buf, size_t count, loff_t *ppos)
988{
989 return -EINVAL;
990}
991
992/* Structure to maintain debug information */
993struct wmi_debugfs_info {
994 const char *name;
995 struct dentry *de[MAX_WMI_INSTANCES];
996 const struct file_operations *ops;
997};
998
999#define DEBUG_FOO(func_base) { .name = #func_base, \
1000 .ops = &debug_##func_base##_ops }
1001
1002/**
1003 * debug_##func_base##_open() - Open debugfs entry for respective command
1004 * and event buffer.
1005 *
1006 * @inode: node for debug dir entry
1007 * @file: file handler
1008 *
1009 * Return: open status
1010 */
1011#define GENERATE_DEBUG_STRUCTS(func_base) \
1012 static int debug_##func_base##_open(struct inode *inode, \
1013 struct file *file) \
1014 { \
1015 return single_open(file, debug_##func_base##_show, \
1016 inode->i_private); \
1017 } \
1018 \
1019 \
1020 static struct file_operations debug_##func_base##_ops = { \
1021 .open = debug_##func_base##_open, \
1022 .read = seq_read, \
1023 .llseek = seq_lseek, \
1024 .write = debug_##func_base##_write, \
1025 .release = single_release, \
1026 };
1027
1028GENERATE_DEBUG_STRUCTS(wmi_command_log);
1029GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1030GENERATE_DEBUG_STRUCTS(wmi_event_log);
1031GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1032GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1033GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1034GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1035GENERATE_DEBUG_STRUCTS(wmi_enable);
1036GENERATE_DEBUG_STRUCTS(wmi_log_size);
1037
1038struct wmi_debugfs_info wmi_debugfs_infos[] = {
1039 DEBUG_FOO(wmi_command_log),
1040 DEBUG_FOO(wmi_command_tx_cmp_log),
1041 DEBUG_FOO(wmi_event_log),
1042 DEBUG_FOO(wmi_rx_event_log),
1043 DEBUG_FOO(wmi_mgmt_command_log),
1044 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1045 DEBUG_FOO(wmi_mgmt_event_log),
1046 DEBUG_FOO(wmi_enable),
1047 DEBUG_FOO(wmi_log_size),
1048};
1049
1050#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1051 sizeof(wmi_debugfs_infos[0]))
1052
1053/**
1054 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1055 *
1056 * @wmi_handle: wmi handle
1057 * @par_entry: debug directory entry
1058 * @id: Index to debug info data array
1059 *
1060 * Return: none
1061 */
1062static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1063 struct dentry *par_entry, int id)
1064{
1065 int i;
1066
1067 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1068 goto out;
1069
1070 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1071
1072 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1073 wmi_debugfs_infos[i].name, 0644, par_entry,
1074 wmi_handle, wmi_debugfs_infos[i].ops);
1075
1076 if (wmi_debugfs_infos[i].de[id] == NULL) {
1077 qdf_print("%s: debug Entry creation failed!\n",
1078 __func__);
1079 goto out;
1080 }
1081 }
1082
1083 return;
1084
1085out:
1086 qdf_print("%s: debug Entry creation failed!\n", __func__);
1087 wmi_log_buffer_free(wmi_handle);
1088 return;
1089}
1090
1091/**
1092 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301093 * @wmi_handle: wmi handle
1094 * @dentry: debugfs directory entry
1095 * @id: Index to debug info data array
1096 *
1097 * Return: none
1098 */
Govind Singh06c18392016-06-10 10:33:19 +05301099static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301100{
1101 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301102 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
1103 int id = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301104
1105 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1106 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1107 if (wmi_debugfs_infos[i].de[id])
1108 wmi_debugfs_infos[i].de[id] = NULL;
1109 }
1110 }
1111
1112 if (dentry)
1113 debugfs_remove_recursive(dentry);
1114}
1115
1116/**
1117 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1118 * create debugfs enteries.
1119 *
1120 * @h: wmi handler
1121 *
1122 * Return: init status
1123 */
1124static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1125{
1126 static int wmi_index;
1127
1128 if (wmi_index < MAX_WMI_INSTANCES)
1129 wmi_handle->log_info.wmi_log_debugfs_dir =
1130 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1131
1132 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
1133 qdf_print("error while creating debugfs dir for %s\n",
1134 debugfs_dir[wmi_index]);
1135 return QDF_STATUS_E_FAILURE;
1136 }
1137
1138 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
1139 wmi_index);
1140 wmi_handle->log_info.wmi_instance_id = wmi_index++;
1141
1142 return QDF_STATUS_SUCCESS;
1143}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001144
1145/**
1146 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1147 *
1148 * @wmi_handle: wmi handle
1149 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001150 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001151 * @vdev_id: vdev id
1152 * @chanfreq: channel frequency
1153 *
1154 * Return: none
1155 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301156void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001157 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001158{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301159
1160 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1161
1162 data[0] = ((struct wmi_command_header *)header)->type;
1163 data[1] = ((struct wmi_command_header *)header)->sub_type;
1164 data[2] = vdev_id;
1165 data[3] = chanfreq;
1166
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001167 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1168
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301169 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001170
1171 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1172}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001173#else
1174/**
1175 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1176 * @wmi_handle: wmi handle
1177 * @dentry: debugfs directory entry
1178 * @id: Index to debug info data array
1179 *
1180 * Return: none
1181 */
Govind Singh06c18392016-06-10 10:33:19 +05301182static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301183void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001184 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301185static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301186#endif /*WMI_INTERFACE_EVENT_LOGGING */
1187
Govind Singh6b411b52016-03-06 19:55:02 +05301188int wmi_get_host_credits(wmi_unified_t wmi_handle);
1189/* WMI buffer APIs */
1190
1191#ifdef MEMORY_DEBUG
1192wmi_buf_t
1193wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301194 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301195{
1196 wmi_buf_t wmi_buf;
1197
1198 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301199 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301200 return NULL;
1201 }
1202
Govind Singhb53420c2016-03-09 14:32:57 +05301203 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301204 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1205 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1206 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301207
1208 if (!wmi_buf)
1209 return NULL;
1210
1211 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301212 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301213
1214 /*
1215 * Set the length of the buffer to match the allocation size.
1216 */
Govind Singhb53420c2016-03-09 14:32:57 +05301217 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301218
1219 return wmi_buf;
1220}
1221
1222void wmi_buf_free(wmi_buf_t net_buf)
1223{
Govind Singhb53420c2016-03-09 14:32:57 +05301224 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301225}
1226#else
1227wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1228{
1229 wmi_buf_t wmi_buf;
1230
1231 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301232 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301233 return NULL;
1234 }
1235
Govind Singhb53420c2016-03-09 14:32:57 +05301236 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301237 WMI_MIN_HEAD_ROOM, 4, false);
1238 if (!wmi_buf)
1239 return NULL;
1240
1241 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301242 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301243
1244 /*
1245 * Set the length of the buffer to match the allocation size.
1246 */
Govind Singhb53420c2016-03-09 14:32:57 +05301247 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301248 return wmi_buf;
1249}
1250
1251void wmi_buf_free(wmi_buf_t net_buf)
1252{
Govind Singhb53420c2016-03-09 14:32:57 +05301253 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301254}
1255#endif
1256
1257/**
1258 * wmi_get_max_msg_len() - get maximum WMI message length
1259 * @wmi_handle: WMI handle.
1260 *
1261 * This function returns the maximum WMI message length
1262 *
1263 * Return: maximum WMI message length
1264 */
1265uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1266{
1267 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1268}
1269
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301270#ifdef CONFIG_MCL
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301271static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +05301272{
1273 switch (wmi_command) {
1274 /* initialize the wlan sub system */
1275 CASE_RETURN_STRING(WMI_INIT_CMDID);
1276
1277 /* Scan specific commands */
1278
1279 /* start scan request to FW */
1280 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1281 /* stop scan request to FW */
1282 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1283 /* full list of channels as defined by the regulatory
1284 * that will be used by scanner */
1285 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1286 /* overwrite default priority table in scan scheduler */
1287 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1288 /* This command to adjust the priority and min.max_rest_time
1289 * of an on ongoing scan request.
1290 */
1291 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1292
1293 /* PDEV(physical device) specific commands */
1294 /* set regulatorty ctl id used by FW to determine the exact
1295 * ctl power limits */
1296 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1297 /* set channel. mainly used for supporting monitor mode */
1298 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1299 /* set pdev specific parameters */
1300 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1301 /* enable packet log */
1302 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1303 /* disable packet log*/
1304 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1305 /* set wmm parameters */
1306 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1307 /* set HT cap ie that needs to be carried probe requests
1308 * HT/VHT channels */
1309 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1310 /* set VHT cap ie that needs to be carried on probe
1311 * requests on VHT channels */
1312 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1313
1314 /* Command to send the DSCP-to-TID map to the target */
1315 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1316 /* set quiet ie parameters. primarily used in AP mode */
1317 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1318 /* Enable/Disable Green AP Power Save */
1319 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1320 /* get TPC config for the current operating channel */
1321 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1322
1323 /* set the base MAC address for the physical device before
1324 * a VDEV is created. For firmware that does not support
1325 * this feature and this command, the pdev MAC address will
1326 * not be changed. */
1327 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1328
1329 /* eeprom content dump , the same to bdboard data */
1330 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1331
1332 /* VDEV(virtual device) specific commands */
1333 /* vdev create */
1334 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1335 /* vdev delete */
1336 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1337 /* vdev start request */
1338 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1339 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1340 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1341 /* vdev up request */
1342 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1343 /* vdev stop request */
1344 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1345 /* vdev down request */
1346 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1347 /* set a vdev param */
1348 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1349 /* set a key (used for setting per peer unicast
1350 * and per vdev multicast) */
1351 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1352
1353 /* wnm sleep mode command */
1354 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1355 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1356 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1357 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1358 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1359 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1360
1361 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1362 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1363 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1364 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1365
1366 /* peer specific commands */
1367
1368 /** create a peer */
1369 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1370 /** delete a peer */
1371 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1372 /** flush specific tid queues of a peer */
1373 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1374 /** set a parameter of a peer */
1375 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1376 /* set peer to associated state. will cary all parameters
1377 * determined during assocication time */
1378 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1379 /* add a wds (4 address ) entry. used only for testing
1380 * WDS feature on AP products */
1381 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1382 /* remove wds (4 address ) entry. used only for testing WDS
1383 * feature on AP products */
1384 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1385 /* set up mcast info for multicast to unicast conversion */
1386 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1387 /* request peer info from FW to get PEER_INFO_EVENTID */
1388 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1389
1390 /* beacon/management specific commands */
1391
1392 /* transmit beacon by reference. used for transmitting beacon
1393 * on low latency interface like pcie */
1394 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1395 /* transmit beacon by value */
1396 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1397 /* set the beacon template. used in beacon offload mode to setup
1398 * the common beacon template with the FW to be used by FW to
1399 * generate beacons */
1400 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1401 /* set beacon filter with FW */
1402 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1403 /* enable/disable filtering of probe requests in the firmware */
1404 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1405 /* transmit management frame by value. will be deprecated */
1406 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1407 /* set the probe response template. used in beacon offload mode
1408 * to setup the common probe response template with the FW to
1409 * be used by FW to generate probe responses */
1410 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1411
1412 /* commands to directly control ba negotiation directly from
1413 * host. only used in test mode */
1414
1415 /* turn off FW Auto addba mode and let host control addba */
1416 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1417 /* send add ba request */
1418 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1419 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1420 /* send del ba */
1421 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1422 /* set add ba response will be used by FW to generate
1423 * addba response*/
1424 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1425 /* send single VHT MPDU with AMSDU */
1426 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1427
1428 /* Station power save specific config */
1429 /* enable/disable station powersave */
1430 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1431 /* set station power save specific parameter */
1432 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1433 /* set station mimo powersave mode */
1434 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1435
1436 /* DFS-specific commands */
1437 /* enable DFS (radar detection)*/
1438 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1439 /* disable DFS (radar detection)*/
1440 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1441 /* enable DFS phyerr/parse filter offload */
1442 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1443 /* enable DFS phyerr/parse filter offload */
1444 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1445
1446 /* Roaming specific commands */
1447 /* set roam scan mode */
1448 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1449 /* set roam scan rssi threshold below which roam
1450 * scan is enabled */
1451 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1452 /* set roam scan period for periodic roam scan mode */
1453 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1454 /* set roam scan trigger rssi change threshold */
1455 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1456 /* set roam AP profile */
1457 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1458 /* set channel list for roam scans */
1459 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1460 /* offload scan specific commands */
1461 /* set offload scan AP profile */
1462 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1463 /* remove offload scan AP profile */
1464 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1465 /* set offload scan period */
1466 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1467
1468 /* P2P specific commands */
1469 /* set P2P device info. FW will used by FW to create P2P IE
1470 * to be carried in probe response generated during p2p listen
1471 * and for p2p discoverability */
1472 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1473 /* enable/disable p2p discoverability on STA/AP VDEVs */
1474 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1475 /* set p2p ie to be carried in beacons generated by FW for GO */
1476 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1477 /* set p2p ie to be carried in probe response frames generated
1478 * by FW for GO */
1479 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1480 /* set the vendor specific p2p ie data.
1481 * FW will use this to parse the P2P NoA
1482 * attribute in the beacons/probe responses received.
1483 */
1484 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1485 /* set the configure of p2p find offload */
1486 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1487 /* set the vendor specific p2p ie data for p2p find offload */
1488 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1489 /* set the BSSID/device name pattern of p2p find offload */
1490 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1491 /* set OppPS related parameters **/
1492 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1493
1494 /* AP power save specific config
1495 * set AP power save specific param */
1496 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1497 /* set AP UAPSD coex pecific param */
1498 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1499
1500 /* Rate-control specific commands */
1501 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1502
1503 /* WLAN Profiling commands. */
1504 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1505 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1506 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1507 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1508 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1509
1510 /* Suspend resume command Ids */
1511 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1512 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1513
1514 /* Beacon filter commands */
1515 /* add a beacon filter */
1516 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1517 /* remove a beacon filter */
1518 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1519
1520 /* WOW Specific WMI commands */
1521 /* add pattern for awake */
1522 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1523 /* deleta a wake pattern */
1524 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1525 /* enable/deisable wake event */
1526 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1527 /* enable WOW */
1528 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1529 /* host woke up from sleep event to FW. Generated in response
1530 * to WOW Hardware event */
1531 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1532
1533 /* RTT measurement related cmd */
1534 /* reques to make an RTT measurement */
1535 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1536 /* reques to report a tsf measurement */
1537 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1538
1539 /* spectral scan command */
1540 /* configure spectral scan */
1541 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1542 /* enable/disable spectral scan and trigger */
1543 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1544
1545 /* F/W stats */
1546 /* one time request for stats */
1547 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1548 /* Push MCC Adaptive Scheduler Stats to Firmware */
1549 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1550
1551 /* ARP OFFLOAD REQUEST*/
1552 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1553
1554 /* Proactive ARP Response Add Pattern Command*/
1555 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1556
1557 /* Proactive ARP Response Del Pattern Command*/
1558 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1559
1560 /* NS offload confid*/
1561 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1562
1563 /* GTK offload Specific WMI commands */
1564 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1565
1566 /* CSA offload Specific WMI commands */
1567 /* csa offload enable */
1568 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1569 /* chan switch command */
1570 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1571
1572 /* Chatter commands */
1573 /* Change chatter mode of operation */
1574 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1575 /* chatter add coalescing filter command */
1576 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1577 /* chatter delete coalescing filter command */
1578 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1579 /* chatter coalecing query command */
1580 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1581
1582 /* addba specific commands */
1583 /* start the aggregation on this TID */
1584 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1585 /* stop the aggregation on this TID */
1586 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1587
1588 /* set station mimo powersave method */
1589 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1590 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1591 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1592 /* Configure the Keep Alive Parameters */
1593 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1594
1595 /* Request ssn from target for a sta/tid pair */
1596 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1597 /* misc command group */
1598 /* echo command mainly used for testing */
1599 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1600
1601 /* !!IMPORTANT!!
1602 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1603 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1604 * as we MUST have a fixed value here to maintain compatibility between
1605 * UTF and the ART2 driver
1606 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301607 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301608 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1609
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301610 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301611 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1612 /* QVIT specific command id */
1613 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1614 /* Factory Testing Mode request command
1615 * used for integrated chipsets */
1616 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1617 /* set and get keepalive parameters command */
1618 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1619 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1620 /* For fw recovery test command */
1621 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1622 /* Set Mcast/Bdcast filter */
1623 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1624 /* set thermal management params */
1625 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1626 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1627 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1628 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301629 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301630 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301631 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301632 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301633 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1634 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1635 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1636 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1637 /* GPIO Configuration */
1638 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1639 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1640
1641 /* Txbf configuration command */
1642 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1643
1644 /* FWTEST Commands */
1645 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1646 /* set NoA descs */
1647 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1648
1649 /* TDLS Configuration */
1650 /* enable/disable TDLS */
1651 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1652 /* set tdls peer state */
1653 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1654
1655 /* Resmgr Configuration */
1656 /* Adaptive OCS is enabled by default in the FW.
1657 * This command is used to disable FW based adaptive OCS.
1658 */
1659 CASE_RETURN_STRING
1660 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1661 /* set the requested channel time quota for the home channels */
1662 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1663 /* set the requested latency for the home channels */
1664 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1665
1666 /* STA SMPS Configuration */
1667 /* force SMPS mode */
1668 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1669 /* set SMPS parameters */
1670 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1671
1672 /* Wlan HB commands */
1673 /* enalbe/disable wlan HB */
1674 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1675 /* set tcp parameters for wlan HB */
1676 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1677 /* set tcp pkt filter for wlan HB */
1678 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1679 /* set udp parameters for wlan HB */
1680 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1681 /* set udp pkt filter for wlan HB */
1682 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1683
1684 /* Wlan RMC commands*/
1685 /* enable/disable RMC */
1686 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1687 /* configure action frame period */
1688 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1689 /* For debug/future enhancement purposes only,
1690 * configures/finetunes RMC algorithms */
1691 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1692
1693 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301694 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301695 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1696 /* Plumb routing table for MHF offload */
1697 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1698
1699 /* location scan commands */
1700 /* start batch scan */
1701 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1702 /* stop batch scan */
1703 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1704 /* get batch scan result */
1705 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1706 /* OEM related cmd */
1707 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1708 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1709 /* NAN request cmd */
1710 CASE_RETURN_STRING(WMI_NAN_CMDID);
1711 /* Modem power state cmd */
1712 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1713 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1714 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1715 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1716 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1717 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1718 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1719 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1720 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301721 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301722 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1723 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1724 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1725 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1726 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1727 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1728 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1729 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1730 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1731 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1732 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1733 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1734 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1735 CASE_RETURN_STRING
1736 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1737 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1738 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1739 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1740 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1741 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1742 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1743 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1744 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1745 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1746 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1747 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1748 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1749 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1750 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1751 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1752 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1753 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1754 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1755 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1756 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1757 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1758 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1759 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1760 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1761 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1762 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1763 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1764 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1765 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1766 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1767 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1768 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1769 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1770 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1771 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1772 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1773 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1774 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1775 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1776 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1777 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1778 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1779 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1780 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1781 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1782 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1783 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1784 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1785 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1786 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1787 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1788 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1789 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1790 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1791 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1792 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1793 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1794 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1795 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1796 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301797 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1798 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1799 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1800 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1801 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1802 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1803 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1804 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1805 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1806 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1807 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1808 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1809 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1810 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1811 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1812 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1813 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1814 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1815 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1816 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1817 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1818 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1819 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1820 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1821 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1822 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1823 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1824 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1825 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1826 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1827 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1828 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1829 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001830 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301831 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301832 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301833 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301834 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Himanshu Agarwaldc8d1ae2016-05-13 21:04:17 +05301835 CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
Himanshu Agarwalfc302f92016-05-30 21:06:16 +05301836 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
1837 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
Pradeep Reddy POTTETI18f8fbb2016-06-13 17:59:38 +05301838 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1839 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
Pradeep Reddy POTTETI4b997fd2016-06-20 13:25:31 +05301840 CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
Pradeep Reddy POTTETI10ca69d2016-06-20 14:50:42 +05301841 CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
Nitesh Shah70e11042016-06-29 20:16:16 +05301842 CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
1843 CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
Nitesh Shahc0482652016-07-08 11:45:33 +05301844 CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
Nitesh Shah33b95402016-07-21 17:25:55 +05301845 CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
1846 CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
Anurag Chouhan40865b42016-08-01 14:01:54 +05301847 CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
Anurag Chouhan7f6f1d52016-08-04 18:46:29 +05301848 CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
Manjeet Singhc026bde2016-09-01 16:42:29 +05301849 CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
Manjeet Singhbea16712016-08-18 15:50:30 +05301850 CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
1851 CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
Himanshu Agarwal91c9d672016-09-14 20:43:24 +05301852 CASE_RETURN_STRING(WMI_VDEV_ENCRYPT_DECRYPT_DATA_REQ_CMDID);
Sandeep Puligillaabcd0f52016-11-03 12:38:45 -07001853 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
1854 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_DISABLE_CMDID);
1855 CASE_RETURN_STRING(WMI_VDEV_ADFS_CH_CFG_CMDID);
1856 CASE_RETURN_STRING(WMI_VDEV_ADFS_OCAC_ABORT_CMDID);
Nishank Aggarwale6994d22016-11-08 13:34:12 +05301857 CASE_RETURN_STRING(WMI_SAR_LIMITS_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301858 }
1859
1860 return "Invalid WMI cmd";
1861}
1862
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301863static inline void wma_log_cmd_id(uint32_t cmd_id, uint32_t tag)
Govind Singh6b411b52016-03-06 19:55:02 +05301864{
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301865 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1866 wmi_id_to_name(cmd_id), cmd_id, tag);
Govind Singh6b411b52016-03-06 19:55:02 +05301867}
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001868#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301869static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301870{
1871 return "Invalid WMI cmd";
1872}
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301873#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301874
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301875#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05301876/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301877 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1878 * @cmd_id: command to check
1879 *
1880 * Return: true if the command is part of the resume sequence.
1881 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301882static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301883{
1884 switch (cmd_id) {
1885 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1886 case WMI_PDEV_RESUME_CMDID:
1887 return true;
1888
1889 default:
1890 return false;
1891 }
1892}
1893#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301894static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301895{
1896 return false;
1897}
1898#endif
1899
1900/**
Govind Singh6b411b52016-03-06 19:55:02 +05301901 * wmi_unified_cmd_send() - WMI command API
1902 * @wmi_handle: handle to wmi
1903 * @buf: wmi buf
1904 * @len: wmi buffer length
1905 * @cmd_id: wmi command id
1906 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001907 * Note, it is NOT safe to access buf after calling this function!
1908 *
Govind Singh6b411b52016-03-06 19:55:02 +05301909 * Return: 0 on success
1910 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001911QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1912 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301913{
1914 HTC_PACKET *pkt;
1915 A_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301916 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301917
1918 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301919 htc_tag =
1920 (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
1921 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301922 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301923 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301924 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301925 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301926 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301927 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301928 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301929 if (wmi_handle->wmi_stopinprogress) {
1930 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1931 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001932 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301933 }
Govind Singh6b411b52016-03-06 19:55:02 +05301934
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301935#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301936 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301937 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301938 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301939
1940 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301941 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301942 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301943 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301944 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301945 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301946 }
1947 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301948#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301949
Govind Singhb53420c2016-03-09 14:32:57 +05301950 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1951 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301952 "%s, Failed to send cmd %x, no memory",
1953 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301954 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301955 }
1956
Govind Singhb53420c2016-03-09 14:32:57 +05301957 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301958
Govind Singhb53420c2016-03-09 14:32:57 +05301959 qdf_atomic_inc(&wmi_handle->pending_cmds);
1960 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1961 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301962 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301963 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301964 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301965 qdf_atomic_dec(&wmi_handle->pending_cmds);
1966 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301967 "%s: MAX %d WMI Pending cmds reached.", __func__,
1968 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301969 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301970 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301971 }
1972
Govind Singhb53420c2016-03-09 14:32:57 +05301973 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301974 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301975 qdf_atomic_dec(&wmi_handle->pending_cmds);
1976 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301977 "%s, Failed to alloc htc packet %x, no memory",
1978 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301979 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301980 }
1981
1982 SET_HTC_PACKET_INFO_TX(pkt,
1983 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301984 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301985 wmi_handle->wmi_endpoint_id, htc_tag);
1986
1987 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301988#ifdef CONFIG_MCL
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301989 wma_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301990#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301991
1992#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301993 if (wmi_handle->log_info.wmi_logging_enable) {
1994 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301995 /*Record 16 bytes of WMI cmd data -
1996 * * exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301997 if (wmi_handle->ops->is_management_record(cmd_id)) {
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301998 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
1999 ((uint32_t *) qdf_nbuf_data(buf) +
2000 wmi_handle->log_info.buf_offset_command));
2001 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302002 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
2003 ((uint32_t *) qdf_nbuf_data(buf) +
2004 wmi_handle->log_info.buf_offset_command));
2005 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302006 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2007 }
Govind Singh6b411b52016-03-06 19:55:02 +05302008#endif
2009
2010 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
2011
2012 if (A_OK != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05302013 qdf_atomic_dec(&wmi_handle->pending_cmds);
2014 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302015 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07002016 qdf_mem_free(pkt);
2017
Govind Singh6b411b52016-03-06 19:55:02 +05302018 }
2019 if (status)
Govind Singhb53420c2016-03-09 14:32:57 +05302020 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302021
Govind Singhb53420c2016-03-09 14:32:57 +05302022 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302023}
2024
2025/**
2026 * wmi_unified_get_event_handler_ix() - gives event handler's index
2027 * @wmi_handle: handle to wmi
2028 * @event_id: wmi event id
2029 *
2030 * Return: event handler's index
2031 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002032static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
2033 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302034{
2035 uint32_t idx = 0;
2036 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302037 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302038
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302039 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05302040 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
2041 if (wmi_handle->event_id[idx] == event_id &&
2042 wmi_handle->event_handler[idx] != NULL) {
2043 return idx;
2044 }
2045 }
2046
2047 return invalid_idx;
2048}
2049
2050/**
Soumya Bhat488092d2017-03-22 14:41:01 +05302051 * wmi_unified_register_event() - register wmi event handler
2052 * @wmi_handle: handle to wmi
2053 * @event_id: wmi event id
2054 * @handler_func: wmi event handler function
2055 *
2056 * Return: 0 on success
2057 */
2058int wmi_unified_register_event(wmi_unified_t wmi_handle,
2059 uint32_t event_id,
2060 wmi_unified_event_handler handler_func)
2061{
2062 uint32_t idx = 0;
2063 uint32_t evt_id;
2064 struct wmi_soc *soc = wmi_handle->soc;
2065
2066 if (event_id >= wmi_events_max ||
2067 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2068 qdf_print("%s: Event id %d is unavailable\n",
2069 __func__, event_id);
2070 return QDF_STATUS_E_FAILURE;
2071 }
2072 evt_id = wmi_handle->wmi_events[event_id];
2073 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2074 qdf_print("%s : event handler already registered 0x%x\n",
2075 __func__, evt_id);
2076 return QDF_STATUS_E_FAILURE;
2077 }
2078 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
2079 qdf_print("%s : no more event handlers 0x%x\n",
2080 __func__, evt_id);
2081 return QDF_STATUS_E_FAILURE;
2082 }
2083 idx = soc->max_event_idx;
2084 wmi_handle->event_handler[idx] = handler_func;
2085 wmi_handle->event_id[idx] = evt_id;
2086 qdf_spin_lock_bh(&soc->ctx_lock);
2087 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
2088 qdf_spin_unlock_bh(&soc->ctx_lock);
2089 soc->max_event_idx++;
2090
2091 return 0;
2092}
2093
2094/**
Govind Singh6b411b52016-03-06 19:55:02 +05302095 * wmi_unified_register_event_handler() - register wmi event handler
2096 * @wmi_handle: handle to wmi
2097 * @event_id: wmi event id
2098 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05302099 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05302100 *
Soumya Bhat488092d2017-03-22 14:41:01 +05302101 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05302102 * Return: 0 on success
2103 */
2104int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302105 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05302106 wmi_unified_event_handler handler_func,
2107 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302108{
2109 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302110 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302111 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302112
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302113#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302114 if (event_id >= wmi_events_max ||
2115 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2116 qdf_print("%s: Event id %d is unavailable\n",
2117 __func__, event_id);
2118 return QDF_STATUS_E_FAILURE;
2119 }
2120 evt_id = wmi_handle->wmi_events[event_id];
2121#else
2122 evt_id = event_id;
2123#endif
2124 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2125 qdf_print("%s : event handler already registered 0x%x\n",
2126 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302127 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302128 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302129 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302130 qdf_print("%s : no more event handlers 0x%x\n",
2131 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302132 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302133 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302134 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302135 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302136 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302137 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302138 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302139 qdf_spin_unlock_bh(&soc->ctx_lock);
2140 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05302141
2142 return 0;
2143}
2144
2145/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05302146 * wmi_unified_unregister_event() - unregister wmi event handler
2147 * @wmi_handle: handle to wmi
2148 * @event_id: wmi event id
2149 *
2150 * Return: 0 on success
2151 */
2152int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
2153 uint32_t event_id)
2154{
2155 uint32_t idx = 0;
2156 uint32_t evt_id;
2157 struct wmi_soc *soc = wmi_handle->soc;
2158
2159 if (event_id >= wmi_events_max ||
2160 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2161 qdf_print("%s: Event id %d is unavailable\n",
2162 __func__, event_id);
2163 return QDF_STATUS_E_FAILURE;
2164 }
2165 evt_id = wmi_handle->wmi_events[event_id];
2166
2167 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
2168 if (idx == -1) {
2169 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2170 __func__, evt_id);
2171 return QDF_STATUS_E_FAILURE;
2172 }
2173 wmi_handle->event_handler[idx] = NULL;
2174 wmi_handle->event_id[idx] = 0;
2175 --soc->max_event_idx;
2176 wmi_handle->event_handler[idx] =
2177 wmi_handle->event_handler[soc->max_event_idx];
2178 wmi_handle->event_id[idx] =
2179 wmi_handle->event_id[soc->max_event_idx];
2180
2181 return 0;
2182}
2183
2184/**
Govind Singh6b411b52016-03-06 19:55:02 +05302185 * wmi_unified_unregister_event_handler() - unregister wmi event handler
2186 * @wmi_handle: handle to wmi
2187 * @event_id: wmi event id
2188 *
2189 * Return: 0 on success
2190 */
2191int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302192 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302193{
2194 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302195 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302196 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302197
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302198#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302199 if (event_id >= wmi_events_max ||
2200 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2201 qdf_print("%s: Event id %d is unavailable\n",
2202 __func__, event_id);
2203 return QDF_STATUS_E_FAILURE;
2204 }
2205 evt_id = wmi_handle->wmi_events[event_id];
2206#else
2207 evt_id = event_id;
2208#endif
2209
2210 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302211 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302212 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2213 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302214 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302215 }
2216 wmi_handle->event_handler[idx] = NULL;
2217 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302218 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302219 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302220 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302221 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302222 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302223
2224 return 0;
2225}
2226
2227/**
Govind Singhd52faac2016-03-09 12:03:29 +05302228 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302229 * @wmi_handle: handle to wmi
2230 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302231 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05302232 *
Govind Singhd52faac2016-03-09 12:03:29 +05302233 * Event process by below function will be in default caller context.
2234 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05302235 *
2236 * Return: none
2237 */
Govind Singhd52faac2016-03-09 12:03:29 +05302238static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
2239 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302240{
2241 wmi_buf_t evt_buf;
2242 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
2243
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302244#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302245 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
2246 (wmi_handle->scn_handle, evt_buf, exec_ctx);
2247#else
Govind Singh5eb51532016-03-09 11:34:12 +05302248 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05302249 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302250#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302251
Govind Singh6b411b52016-03-06 19:55:02 +05302252 return;
2253}
2254
2255/**
2256 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
2257 * @wmi_handle: handle to wmi
2258 * @htc_packet: pointer to htc packet
2259 *
2260 * Event process by below function will be in worker thread context.
2261 * Use this method for events which are not critical and not
2262 * handled in protocol stack.
2263 *
2264 * Return: none
2265 */
2266static void wmi_process_fw_event_worker_thread_ctx
2267 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
2268{
2269 wmi_buf_t evt_buf;
2270 uint32_t id;
2271 uint8_t *data;
2272
2273 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302274 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
2275 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302276
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302277#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302278 if (wmi_handle->log_info.wmi_logging_enable) {
2279 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2280 /* Exclude 4 bytes of TLV header */
2281 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2282 wmi_handle->log_info.buf_offset_event));
2283 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2284 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302285#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302286 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2287 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
2288 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002289 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
2290 &wmi_handle->rx_event_work);
2291
Govind Singh6b411b52016-03-06 19:55:02 +05302292 return;
2293}
2294
2295/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302296 * wmi_get_pdev_ep: Get wmi handle based on endpoint
2297 * @soc: handle to wmi soc
2298 * @ep: endpoint id
2299 *
2300 * Return: none
2301 */
2302static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
2303 HTC_ENDPOINT_ID ep)
2304{
2305 uint32_t i;
2306
2307 for (i = 0; i < WMI_MAX_RADIOS; i++)
2308 if (soc->wmi_endpoint_id[i] == ep)
2309 break;
2310
2311 if (i == WMI_MAX_RADIOS)
2312 return NULL;
2313
2314 return soc->wmi_pdev[i];
2315}
2316
2317/**
Govind Singhd52faac2016-03-09 12:03:29 +05302318 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302319 * @ctx: handle to wmi
2320 * @htc_packet: pointer to htc packet
2321 *
Govind Singh6b411b52016-03-06 19:55:02 +05302322 * Return: none
2323 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002324static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05302325{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302326 struct wmi_soc *soc = (struct wmi_soc *) ctx;
2327 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302328 wmi_buf_t evt_buf;
2329 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302330 uint32_t idx = 0;
2331 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302332
2333 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302334
2335 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
2336 if (wmi_handle == NULL) {
2337 qdf_print
2338 ("%s :unable to get wmi_handle to Endpoint %d\n",
2339 __func__, htc_packet->Endpoint);
2340 qdf_nbuf_free(evt_buf);
2341 return;
2342 }
2343
Govind Singhb53420c2016-03-09 14:32:57 +05302344 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302345 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302346 if (qdf_unlikely(idx == A_ERROR)) {
2347 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05302348 ("%s :event handler is not registered: event id 0x%x\n",
2349 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302350 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302351 return;
2352 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302353 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302354 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302355 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302356
2357 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302358 wmi_process_fw_event_worker_thread_ctx
2359 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302360 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2361 wmi_process_fw_event_default_ctx
2362 (wmi_handle, htc_packet, exec_ctx);
2363 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05302364 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
2365 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302366 }
Govind Singhd52faac2016-03-09 12:03:29 +05302367
Govind Singh6b411b52016-03-06 19:55:02 +05302368}
2369
2370/**
2371 * wmi_process_fw_event() - process any fw event
2372 * @wmi_handle: wmi handle
2373 * @evt_buf: fw event buffer
2374 *
Govind Singhd52faac2016-03-09 12:03:29 +05302375 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302376 *
2377 * Return: none
2378 */
2379void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2380{
2381 __wmi_control_rx(wmi_handle, evt_buf);
2382}
2383
2384/**
2385 * __wmi_control_rx() - process serialize wmi event callback
2386 * @wmi_handle: wmi handle
2387 * @evt_buf: fw event buffer
2388 *
2389 * Return: none
2390 */
2391void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2392{
2393 uint32_t id;
2394 uint8_t *data;
2395 uint32_t len;
2396 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302397#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302398 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302399#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302400 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302401
Govind Singhb53420c2016-03-09 14:32:57 +05302402 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302403
Govind Singhb53420c2016-03-09 14:32:57 +05302404 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302405 goto end;
2406
Govind Singhb53420c2016-03-09 14:32:57 +05302407 data = qdf_nbuf_data(evt_buf);
2408 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302409
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302410#ifndef WMI_NON_TLV_SUPPORT
2411 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2412 /* Validate and pad(if necessary) the TLVs */
2413 tlv_ok_status =
2414 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302415 data, len, id,
2416 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302417 if (tlv_ok_status != 0) {
2418 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2419 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2420 __func__, id, tlv_ok_status);
2421 goto end;
2422 }
Govind Singh6b411b52016-03-06 19:55:02 +05302423 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302424#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302425
Govind Singhd52faac2016-03-09 12:03:29 +05302426 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2427 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302428 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302429 "%s : event handler is not registered: event id 0x%x\n",
2430 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302431 goto end;
2432 }
Govind Singhd52faac2016-03-09 12:03:29 +05302433#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302434 if (wmi_handle->log_info.wmi_logging_enable) {
2435 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2436 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302437 if (wmi_handle->ops->is_management_record(id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302438 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2439 + wmi_handle->log_info.buf_offset_event));
2440 } else {
2441 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2442 wmi_handle->log_info.buf_offset_event));
2443 }
2444 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302445 }
Govind Singhd52faac2016-03-09 12:03:29 +05302446#endif
2447 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302448 if (wmi_handle->target_type == WMI_TLV_TARGET)
2449 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2450 wmi_cmd_struct_ptr, len);
2451 else
2452 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2453 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302454
Govind Singh6b411b52016-03-06 19:55:02 +05302455end:
Govind Singhd52faac2016-03-09 12:03:29 +05302456 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302457#ifndef WMI_NON_TLV_SUPPORT
2458 if (wmi_handle->target_type == WMI_TLV_TARGET)
2459 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2460#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302461
Govind Singhb53420c2016-03-09 14:32:57 +05302462 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302463
Govind Singh6b411b52016-03-06 19:55:02 +05302464}
2465
2466/**
2467 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002468 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05302469 *
2470 * This function process any fw event to serialize it through rx worker thread.
2471 *
2472 * Return: none
2473 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002474static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05302475{
Govind Singh6b411b52016-03-06 19:55:02 +05302476 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002477 struct wmi_unified *wmi = arg;
Govind Singh6b411b52016-03-06 19:55:02 +05302478
Govind Singhb53420c2016-03-09 14:32:57 +05302479 qdf_spin_lock_bh(&wmi->eventq_lock);
2480 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2481 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302482 while (buf) {
2483 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302484 qdf_spin_lock_bh(&wmi->eventq_lock);
2485 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2486 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302487 }
2488}
2489
Govind Singh6b411b52016-03-06 19:55:02 +05302490#ifdef FEATURE_RUNTIME_PM
2491/**
2492 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2493 * @wmi_handle: wmi context
2494 */
Govind Singhd52faac2016-03-09 12:03:29 +05302495static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302496{
Govind Singhb53420c2016-03-09 14:32:57 +05302497 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302498}
Govind Singhd52faac2016-03-09 12:03:29 +05302499
2500/**
2501 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2502 * @wmi_handle: wmi context
2503 * @val: runtime pm progress flag
2504 */
2505void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2506{
Govind Singhb53420c2016-03-09 14:32:57 +05302507 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302508}
2509
2510/**
2511 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2512 * @wmi_handle: wmi context
2513 */
2514inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2515{
Govind Singhb53420c2016-03-09 14:32:57 +05302516 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302517}
Govind Singh6b411b52016-03-06 19:55:02 +05302518#else
Govind Singhd52faac2016-03-09 12:03:29 +05302519static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302520{
2521}
2522#endif
2523
2524/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302525 * wmi_unified_get_soc_handle: Get WMI SoC handle
2526 * @param wmi_handle: WMI context got from wmi_attach
2527 *
2528 * return: Pointer to Soc handle
2529 */
2530void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2531{
2532 return wmi_handle->soc;
2533}
2534
2535/**
2536 * wmi_interface_logging_init: Interface looging init
2537 * @param wmi_handle: Pointer to wmi handle object
2538 *
2539 * return: None
2540 */
2541#ifdef WMI_INTERFACE_EVENT_LOGGING
2542static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2543{
2544 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2545 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2546 wmi_debugfs_init(wmi_handle);
2547 }
2548}
2549#else
2550void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2551{
2552}
2553#endif
2554
2555/**
2556 * wmi_target_params_init: Target specific params init
2557 * @param wmi_soc: Pointer to wmi soc object
2558 * @param wmi_handle: Pointer to wmi handle object
2559 *
2560 * return: None
2561 */
2562#ifndef CONFIG_MCL
2563static inline void wmi_target_params_init(struct wmi_soc *soc,
2564 struct wmi_unified *wmi_handle)
2565{
2566 /* WMI service bitmap recieved from target */
2567 wmi_handle->wmi_service_bitmap = soc->wmi_service_bitmap;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302568 wmi_handle->pdev_param = soc->pdev_param;
2569 wmi_handle->vdev_param = soc->vdev_param;
2570 wmi_handle->services = soc->services;
2571}
2572#else
2573static inline void wmi_target_params_init(struct wmi_soc *soc,
2574 struct wmi_unified *wmi_handle)
2575{
2576}
2577#endif
2578
2579/**
2580 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2581 * @param wmi_soc: Pointer to wmi soc object
2582 * @param pdev_idx: pdev index
2583 *
2584 * return: Pointer to wmi handle or NULL on failure
2585 */
2586void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2587{
2588 struct wmi_unified *wmi_handle;
2589
2590 if (pdev_idx >= WMI_MAX_RADIOS)
2591 return NULL;
2592
2593 /* If wmi pdev is already allocated, just return the handle */
2594 if (soc->wmi_pdev[pdev_idx] != NULL)
2595 return soc->wmi_pdev[pdev_idx];
2596
2597 wmi_handle =
2598 (struct wmi_unified *) qdf_mem_malloc(
2599 sizeof(struct wmi_unified));
2600 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302601 qdf_print("allocation of wmi handle failed %zu\n",
2602 sizeof(struct wmi_unified));
2603 return NULL;
2604 }
2605 wmi_handle->scn_handle = soc->scn_handle;
2606 wmi_handle->event_id = soc->event_id;
2607 wmi_handle->event_handler = soc->event_handler;
2608 wmi_handle->ctx = soc->ctx;
2609 wmi_handle->ops = soc->ops;
2610 qdf_spinlock_create(&wmi_handle->eventq_lock);
2611 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002612
2613 qdf_create_work(0, &wmi_handle->rx_event_work,
2614 wmi_rx_event_work, wmi_handle);
2615 wmi_handle->wmi_rx_work_queue =
2616 qdf_create_workqueue("wmi_rx_event_work_queue");
2617 if (NULL == wmi_handle->wmi_rx_work_queue) {
2618 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2619 goto error;
2620 }
Soumya Bhat488092d2017-03-22 14:41:01 +05302621 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302622 wmi_target_params_init(soc, wmi_handle);
2623 wmi_interface_logging_init(wmi_handle);
2624 qdf_atomic_init(&wmi_handle->pending_cmds);
2625 qdf_atomic_init(&wmi_handle->is_target_suspended);
2626 wmi_handle->target_type = soc->target_type;
2627 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302628 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2629 wmi_handle->htc_handle = soc->htc_handle;
2630 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302631 wmi_handle->soc = soc;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302632
2633 soc->wmi_pdev[pdev_idx] = wmi_handle;
2634
2635 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002636
2637error:
2638 qdf_mem_free(wmi_handle);
2639
2640 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302641}
2642
2643/**
Govind Singh6b411b52016-03-06 19:55:02 +05302644 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302645 * @scn_handle: handle to SCN
2646 * @osdev: OS device context
2647 * @target_type: TLV or not-TLV based target
2648 * @use_cookie: cookie based allocation enabled/disabled
2649 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302650 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302651 *
2652 * @Return: wmi handle.
2653 */
Govind Singhc458f382016-02-04 18:42:30 +05302654void *wmi_unified_attach(void *scn_handle,
2655 osdev_t osdev, enum wmi_target_type target_type,
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302656 bool use_cookie, struct wmi_rx_ops *rx_ops,
2657 struct wlan_objmgr_psoc *psoc)
Govind Singh6b411b52016-03-06 19:55:02 +05302658{
2659 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302660 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302661
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302662 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2663 if (soc == NULL) {
2664 qdf_print("Allocation of wmi_soc failed %zu\n",
2665 sizeof(struct wmi_soc));
2666 return NULL;
2667 }
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302668#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05302669 wmi_handle =
2670 (struct wmi_unified *)os_malloc(NULL,
2671 sizeof(struct wmi_unified),
2672 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302673#else
2674 wmi_handle =
2675 (struct wmi_unified *) qdf_mem_malloc(
2676 sizeof(struct wmi_unified));
2677#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302678 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302679 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302680 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302681 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302682 return NULL;
2683 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302684 wmi_handle->soc = soc;
2685 wmi_handle->event_id = soc->event_id;
2686 wmi_handle->event_handler = soc->event_handler;
2687 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302688 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302689 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302690 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302691 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302692 qdf_atomic_init(&wmi_handle->pending_cmds);
2693 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302694 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302695 qdf_spinlock_create(&wmi_handle->eventq_lock);
2696 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002697 qdf_create_work(0, &wmi_handle->rx_event_work,
2698 wmi_rx_event_work, wmi_handle);
2699 wmi_handle->wmi_rx_work_queue =
2700 qdf_create_workqueue("wmi_rx_event_work_queue");
2701 if (NULL == wmi_handle->wmi_rx_work_queue) {
2702 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2703 goto error;
2704 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302705 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302706 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302707 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2708 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302709 wmi_handle->target_type = target_type;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302710 soc->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302711 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302712 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302713 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302714 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302715 /* Assign target cookie capablity */
2716 wmi_handle->use_cookie = use_cookie;
2717 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302718 wmi_handle->wmi_stopinprogress = 0;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302719 /* Increase the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302720 soc->wmi_psoc = psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302721 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302722
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302723 soc->ops = wmi_handle->ops;
2724 soc->wmi_pdev[0] = wmi_handle;
2725
Govind Singh6b411b52016-03-06 19:55:02 +05302726 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002727
2728error:
2729 qdf_mem_free(soc);
2730 qdf_mem_free(wmi_handle);
2731
2732 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302733}
2734
2735/**
2736 * wmi_unified_detach() - detach for unified WMI
2737 *
2738 * @wmi_handle : handle to wmi.
2739 *
2740 * @Return: none.
2741 */
2742void wmi_unified_detach(struct wmi_unified *wmi_handle)
2743{
2744 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302745 struct wmi_soc *soc;
2746 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302747
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302748 soc = wmi_handle->soc;
2749 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2750 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002751 qdf_flush_workqueue(0,
2752 soc->wmi_pdev[i]->wmi_rx_work_queue);
2753 qdf_destroy_workqueue(0,
2754 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302755 wmi_debugfs_remove(soc->wmi_pdev[i]);
2756 buf = qdf_nbuf_queue_remove(
2757 &soc->wmi_pdev[i]->event_queue);
2758 while (buf) {
2759 qdf_nbuf_free(buf);
2760 buf = qdf_nbuf_queue_remove(
2761 &soc->wmi_pdev[i]->event_queue);
2762 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002763
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302764 wmi_log_buffer_free(soc->wmi_pdev[i]);
2765 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302766 qdf_mem_free(soc->wmi_pdev[i]);
2767 }
Govind Singh6b411b52016-03-06 19:55:02 +05302768 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302769 qdf_spinlock_destroy(&soc->ctx_lock);
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302770 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302771 soc->wmi_psoc = NULL;
2772 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302773}
2774
2775/**
2776 * wmi_unified_remove_work() - detach for WMI work
2777 * @wmi_handle: handle to WMI
2778 *
2779 * A function that does not fully detach WMI, but just remove work
2780 * queue items associated with it. This is used to make sure that
2781 * before any other processing code that may destroy related contexts
2782 * (HTC, etc), work queue processing on WMI has already been stopped.
2783 *
2784 * Return: None
2785 */
2786void
2787wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2788{
2789 wmi_buf_t buf;
2790
Govind Singhb53420c2016-03-09 14:32:57 +05302791 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302792 "Enter: %s", __func__);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002793 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302794 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2795 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302796 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302797 qdf_nbuf_free(buf);
2798 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302799 }
Govind Singhb53420c2016-03-09 14:32:57 +05302800 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2801 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302802 "Done: %s", __func__);
2803}
2804
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302805/**
2806 * wmi_htc_tx_complete() - Process htc tx completion
2807 *
2808 * @ctx: handle to wmi
2809 * @htc_packet: pointer to htc packet
2810 *
2811 * @Return: none.
2812 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002813static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302814{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302815 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302816 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302817 u_int8_t *buf_ptr;
2818 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302819 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302820#ifdef WMI_INTERFACE_EVENT_LOGGING
2821 uint32_t cmd_id;
2822#endif
2823
2824 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302825 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2826 if (wmi_handle == NULL) {
2827 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2828 QDF_ASSERT(0);
2829 return;
2830 }
Govind Singh6b411b52016-03-06 19:55:02 +05302831#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302832 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302833 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2834 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302835
Govind Singhecf03cd2016-05-12 12:45:51 +05302836 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302837 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302838 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302839 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302840 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2841 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2842 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302843 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302844 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2845 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2846 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302847 }
2848
Govind Singhecf03cd2016-05-12 12:45:51 +05302849 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2850 }
Govind Singh6b411b52016-03-06 19:55:02 +05302851#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302852 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2853 len = qdf_nbuf_len(wmi_cmd_buf);
2854 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302855 qdf_nbuf_free(wmi_cmd_buf);
2856 qdf_mem_free(htc_pkt);
2857 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302858}
2859
2860/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302861 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302862 *
2863 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302864 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302865 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302866 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302867 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302868static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2869 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302870{
Govind Singh6b411b52016-03-06 19:55:02 +05302871 int status;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302872 uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
2873 WMI_CONTROL_SVC_WMAC2};
Manikandan Mohanf940db82017-04-13 20:19:26 -07002874 struct htc_service_connect_resp response;
2875 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302876
2877 OS_MEMZERO(&connect, sizeof(connect));
2878 OS_MEMZERO(&response, sizeof(response));
2879
2880 /* meta data is unused for now */
2881 connect.pMetaData = NULL;
2882 connect.MetaDataLength = 0;
2883 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302884 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302885 connect.EpCallbacks.EpTxCompleteMultiple =
2886 NULL /* Control path completion ar6000_tx_complete */;
2887 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2888 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2889 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2890 connect.EpCallbacks.EpTxComplete =
2891 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2892
2893 /* connect to control service */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302894 connect.service_id = svc_id[pdev_idx];
2895 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302896 &response);
2897
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302898
Govind Singh6b411b52016-03-06 19:55:02 +05302899 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302900 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302901 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302902 status);
2903 return status;
2904 }
Govind Singh6b411b52016-03-06 19:55:02 +05302905
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302906 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2907 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2908
2909 return 0;
2910}
2911
2912/**
2913 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2914 *
2915 * @wmi_handle: handle to WMI.
2916 *
2917 * @Return: status.
2918 */
2919QDF_STATUS
2920wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2921 void *htc_handle)
2922{
2923 uint32_t i;
2924 uint8_t wmi_ep_count;
2925
2926 wmi_handle->soc->htc_handle = htc_handle;
2927
2928 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2929 if (wmi_ep_count > WMI_MAX_RADIOS)
2930 return QDF_STATUS_E_FAULT;
2931
2932 for (i = 0; i < wmi_ep_count; i++)
2933 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2934
2935 wmi_handle->htc_handle = htc_handle;
2936 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2937 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2938
2939 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302940}
2941
2942/**
2943 * wmi_get_host_credits() - WMI API to get updated host_credits
2944 *
2945 * @wmi_handle: handle to WMI.
2946 *
2947 * @Return: updated host_credits.
2948 */
2949int wmi_get_host_credits(wmi_unified_t wmi_handle)
2950{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302951 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302952
2953 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2954 &host_credits);
2955 return host_credits;
2956}
2957
2958/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302959 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2960 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302961 *
2962 * @wmi_handle: handle to WMI.
2963 *
2964 * @Return: Pending Commands in the HTC queue.
2965 */
2966int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2967{
Govind Singhb53420c2016-03-09 14:32:57 +05302968 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302969}
2970
2971/**
2972 * wmi_set_target_suspend() - WMI API to set target suspend state
2973 *
2974 * @wmi_handle: handle to WMI.
2975 * @val: suspend state boolean.
2976 *
2977 * @Return: none.
2978 */
2979void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2980{
Govind Singhb53420c2016-03-09 14:32:57 +05302981 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302982}
2983
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302984/**
2985 * WMI API to set crash injection state
2986 * @param wmi_handle: handle to WMI.
2987 * @param val: crash injection state boolean.
2988 */
2989void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2990{
2991 wmi_handle->tag_crash_inject = flag;
2992}
2993
2994/**
2995 * WMI API to set bus suspend state
2996 * @param wmi_handle: handle to WMI.
2997 * @param val: suspend state boolean.
2998 */
2999void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
3000{
3001 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
3002}
3003
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05303004#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05303005/**
3006 * API to flush all the previous packets associated with the wmi endpoint
3007 *
3008 * @param wmi_handle : handle to WMI.
3009 */
3010void
3011wmi_flush_endpoint(wmi_unified_t wmi_handle)
3012{
3013 htc_flush_endpoint(wmi_handle->htc_handle,
3014 wmi_handle->wmi_endpoint_id, 0);
3015}
3016
3017/**
3018 * generic function to block unified WMI command
3019 * @param wmi_handle : handle to WMI.
3020 * @return 0 on success and -ve on failure.
3021 */
3022int
3023wmi_stop(wmi_unified_t wmi_handle)
3024{
3025 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
3026 "WMI Stop\n");
3027 wmi_handle->wmi_stopinprogress = 1;
3028 return 0;
3029}
3030#endif