blob: f070c17f2ba3408383954f192bb72f22ccc9c8e0 [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
Rakesh Pillai05110462017-12-27 14:08:59 +05302 * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
Govind Singh6b411b52016-03-06 19:55:02 +05303 *
Govind Singh6b411b52016-03-06 19:55:02 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19/*
Govind Singh6b411b52016-03-06 19:55:02 +053020 * Host WMI unified implementation
21 */
Govind Singh6b411b52016-03-06 19:55:02 +053022#include "htc_api.h"
23#include "htc_api.h"
Govind Singh6b411b52016-03-06 19:55:02 +053024#include "wmi_unified_priv.h"
Amar Singhal66d1ed52018-06-26 16:45:54 -070025#include "wmi_unified_api.h"
Pratik Gandhi67da1bb2018-01-30 19:05:41 +053026#include "qdf_module.h"
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +053027#ifdef WMI_EXT_DBG
28#include "qdf_list.h"
29#endif
Govind Singh6b411b52016-03-06 19:55:02 +053030
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053031#ifndef WMI_NON_TLV_SUPPORT
32#include "wmi_tlv_helper.h"
33#endif
34
Govind Singhecf03cd2016-05-12 12:45:51 +053035#include <linux/debugfs.h>
36
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +053037#ifdef WMI_EXT_DBG
38
39/**
40 * wmi_ext_dbg_msg_enqueue() - enqueue wmi message
41 *
42 * @wmi_handle: wmi handler
43 *
44 * Return: size of wmi message queue after enqueue
45 */
46static uint32_t wmi_ext_dbg_msg_enqueue(struct wmi_unified *wmi_handle,
47 struct wmi_ext_dbg_msg *msg)
48{
49 uint32_t list_size;
50
51 qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
52 qdf_list_insert_back_size(&wmi_handle->wmi_ext_dbg_msg_queue,
53 &msg->node, &list_size);
54 qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
55
56 return list_size;
57}
58
59/**
60 * wmi_ext_dbg_msg_dequeue() - dequeue wmi message
61 *
62 * @wmi_handle: wmi handler
63 *
64 * Return: wmi msg on success else NULL
65 */
66static struct wmi_ext_dbg_msg *wmi_ext_dbg_msg_dequeue(struct wmi_unified
67 *wmi_handle)
68{
69 qdf_list_node_t *list_node = NULL;
70
71 qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
72 qdf_list_remove_front(&wmi_handle->wmi_ext_dbg_msg_queue, &list_node);
73 qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
74
75 if (!list_node)
76 return NULL;
77
78 return qdf_container_of(list_node, struct wmi_ext_dbg_msg, node);
79}
80
81/**
82 * wmi_ext_dbg_msg_record() - record wmi messages
83 *
84 * @wmi_handle: wmi handler
85 * @buf: wmi message buffer
86 * @len: wmi message length
87 * @type: wmi message type
88 *
89 * Return: QDF_STATUS_SUCCESS on successful recording else failure.
90 */
91static QDF_STATUS wmi_ext_dbg_msg_record(struct wmi_unified *wmi_handle,
92 uint8_t *buf, uint32_t len,
93 enum WMI_MSG_TYPE type)
94{
95 struct wmi_ext_dbg_msg *msg;
96 uint32_t list_size;
97
98 msg = wmi_ext_dbg_msg_get(len);
99 if (!msg)
100 return QDF_STATUS_E_NOMEM;
101
102 msg->len = len;
103 msg->type = type;
104 qdf_mem_copy(msg->buf, buf, len);
105 msg->ts = qdf_get_log_timestamp();
106 list_size = wmi_ext_dbg_msg_enqueue(wmi_handle, msg);
107
108 if (list_size >= wmi_handle->wmi_ext_dbg_msg_queue_size) {
109 msg = wmi_ext_dbg_msg_dequeue(wmi_handle);
110 wmi_ext_dbg_msg_put(msg);
111 }
112
113 return QDF_STATUS_SUCCESS;
114}
115
116/**
117 * wmi_ext_dbg_msg_cmd_record() - record wmi command messages
118 *
119 * @wmi_handle: wmi handler
120 * @buf: wmi command buffer
121 * @len: wmi command message length
122 *
123 * Return: QDF_STATUS_SUCCESS on successful recording else failure.
124 */
125static QDF_STATUS wmi_ext_dbg_msg_cmd_record(struct wmi_unified *wmi_handle,
126 uint8_t *buf, uint32_t len)
127{
128 return wmi_ext_dbg_msg_record(wmi_handle, buf, len,
129 WMI_MSG_TYPE_CMD);
130}
131
132/**
133 * wmi_ext_dbg_msg_event_record() - record wmi event messages
134 *
135 * @wmi_handle: wmi handler
136 * @buf: wmi event buffer
137 * @len: wmi event message length
138 *
139 * Return: QDF_STATUS_SUCCESS on successful recording else failure.
140 */
141static QDF_STATUS wmi_ext_dbg_msg_event_record(struct wmi_unified *wmi_handle,
142 uint8_t *buf, uint32_t len)
143{
144 uint32_t id;
145
146 id = WMI_GET_FIELD(buf, WMI_CMD_HDR, COMMANDID);
147 if (id != wmi_diag_event_id)
148 return wmi_ext_dbg_msg_record(wmi_handle, buf, len,
149 WMI_MSG_TYPE_EVENT);
150
151 return QDF_STATUS_SUCCESS;
152}
153
154/**
155 * wmi_ext_dbg_msg_queue_init() - create debugfs queue and associated lock
156 *
157 * @wmi_handle: wmi handler
158 *
159 * Return: none
160 */
161static void wmi_ext_dbg_msg_queue_init(struct wmi_unified *wmi_handle)
162{
163 qdf_list_create(&wmi_handle->wmi_ext_dbg_msg_queue,
164 wmi_handle->wmi_ext_dbg_msg_queue_size);
165 qdf_spinlock_create(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
166}
167
168/**
169 * wmi_ext_dbg_msg_queue_deinit() - destroy debugfs queue and associated lock
170 *
171 * @wmi_handle: wmi handler
172 *
173 * Return: none
174 */
175static void wmi_ext_dbg_msg_queue_deinit(struct wmi_unified *wmi_handle)
176{
177 qdf_list_destroy(&wmi_handle->wmi_ext_dbg_msg_queue);
178 qdf_spinlock_destroy(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
179}
180
181/**
182 * wmi_ext_dbg_msg_show() - debugfs function to display whole content of
183 * wmi command/event messages including headers.
184 *
185 * @file: qdf debugfs file handler
186 * @arg: pointer to wmi handler
187 *
188 * Return: QDF_STATUS_SUCCESS if all the messages are shown successfully,
189 * else QDF_STATUS_E_AGAIN if more data to show.
190 */
191static QDF_STATUS wmi_ext_dbg_msg_show(qdf_debugfs_file_t file, void *arg)
192{
193 struct wmi_unified *wmi_handle = (struct wmi_unified *)arg;
194 struct wmi_ext_dbg_msg *msg;
195 uint64_t secs, usecs;
196
197 msg = wmi_ext_dbg_msg_dequeue(wmi_handle);
198 if (!msg)
199 return QDF_STATUS_SUCCESS;
200
201 qdf_debugfs_printf(file, "%s: 0x%x\n",
202 msg->type == WMI_MSG_TYPE_CMD ? "COMMAND" :
203 "EVENT", WMI_GET_FIELD(msg->buf, WMI_CMD_HDR,
204 COMMANDID));
205 qdf_log_timestamp_to_secs(msg->ts, &secs, &usecs);
206 qdf_debugfs_printf(file, "Time: %llu.%llu\n", secs, usecs);
207 qdf_debugfs_printf(file, "Length:%d\n", msg->len);
208 qdf_debugfs_hexdump(file, msg->buf, msg->len,
209 WMI_EXT_DBG_DUMP_ROW_SIZE,
210 WMI_EXT_DBG_DUMP_GROUP_SIZE);
211 qdf_debugfs_printf(file, "\n");
212
213 if (qdf_debugfs_overflow(file)) {
214 qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
215 qdf_list_insert_front(&wmi_handle->wmi_ext_dbg_msg_queue,
216 &msg->node);
217 qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
218
219 } else {
220 wmi_ext_dbg_msg_put(msg);
221 }
222
223 return QDF_STATUS_E_AGAIN;
224}
225
226/**
227 * wmi_ext_dbg_msg_write() - debugfs write not supported
228 *
229 * @priv: private data
230 * @buf: received data buffer
231 * @len: length of received buffer
232 *
233 * Return: QDF_STATUS_E_NOSUPPORT.
234 */
235static QDF_STATUS wmi_ext_dbg_msg_write(void *priv, const char *buf,
236 qdf_size_t len)
237{
238 return QDF_STATUS_E_NOSUPPORT;
239}
240
241static struct qdf_debugfs_fops wmi_ext_dbgfs_ops = {
242 .show = wmi_ext_dbg_msg_show,
243 .write = wmi_ext_dbg_msg_write,
244 .priv = NULL,
245};
246
247/**
248 * wmi_ext_debugfs_init() - init debugfs items for extended wmi dump.
249 *
250 * @wmi_handle: wmi handler
251 *
252 * Return: QDF_STATUS_SUCCESS if debugfs is initialized else
253 * QDF_STATUS_E_FAILURE
254 */
255static QDF_STATUS wmi_ext_dbgfs_init(struct wmi_unified *wmi_handle)
256{
257 qdf_dentry_t dentry;
258
259 dentry = qdf_debugfs_create_dir(WMI_EXT_DBG_DIR, NULL);
260 if (!dentry) {
261 qdf_print("error while creating extended wmi debugfs dir");
262 return QDF_STATUS_E_FAILURE;
263 }
264
265 wmi_ext_dbgfs_ops.priv = wmi_handle;
266 if (!qdf_debugfs_create_file(WMI_EXT_DBG_FILE, WMI_EXT_DBG_FILE_PERM,
267 dentry, &wmi_ext_dbgfs_ops)) {
268 qdf_debugfs_remove_dir(dentry);
269 qdf_print("error while creating extended wmi debugfs file");
270 return QDF_STATUS_E_FAILURE;
271 }
272
273 wmi_handle->wmi_ext_dbg_dentry = dentry;
274 wmi_handle->wmi_ext_dbg_msg_queue_size = WMI_EXT_DBG_QUEUE_SIZE;
275 wmi_ext_dbg_msg_queue_init(wmi_handle);
276
277 return QDF_STATUS_SUCCESS;
278}
279
280/**
281 * wmi_ext_debugfs_deinit() - cleanup/deinit debugfs items of extended wmi dump.
282 *
283 * @wmi_handle: wmi handler
284 *
285 * Return: QDF_STATUS_SUCCESS if cleanup is successful
286 */
287static QDF_STATUS wmi_ext_dbgfs_deinit(struct wmi_unified *wmi_handle)
288{
289 struct wmi_ext_dbg_msg *msg;
290
291 while ((msg = wmi_ext_dbg_msg_dequeue(wmi_handle)))
292 wmi_ext_dbg_msg_put(msg);
293
294 wmi_ext_dbg_msg_queue_deinit(wmi_handle);
295 qdf_debugfs_remove_dir_recursive(wmi_handle->wmi_ext_dbg_dentry);
296
297 return QDF_STATUS_SUCCESS;
298}
299
300#endif /*WMI_EXT_DBG */
301
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530302/* This check for CONFIG_WIN temporary added due to redeclaration compilation
303error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
304which gets included here through ol_if_athvar.h. Eventually it is expected that
305wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
306WMI_CMD_HDR to be defined here. */
307#ifdef CONFIG_WIN
308/* Copied from wmi.h */
309#undef MS
310#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
311#undef SM
312#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
313#undef WO
314#define WO(_f) ((_f##_OFFSET) >> 2)
315
316#undef GET_FIELD
Vivekc5823092018-03-22 23:27:21 +0530317#define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530318#undef SET_FIELD
319#define SET_FIELD(_addr, _f, _val) \
Vivekc5823092018-03-22 23:27:21 +0530320 (*((uint32_t *)(_addr) + WO(_f)) = \
321 (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530322
323#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
324 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
325
326#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
327 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
328
329#define WMI_EP_APASS 0x0
330#define WMI_EP_LPASS 0x1
331#define WMI_EP_SENSOR 0x2
332
333/*
334 * * Control Path
335 * */
336typedef PREPACK struct {
Vivekc5823092018-03-22 23:27:21 +0530337 uint32_t commandId:24,
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530338 reserved:2, /* used for WMI endpoint ID */
339 plt_priv:6; /* platform private */
340} POSTPACK WMI_CMD_HDR; /* used for commands and events */
341
342#define WMI_CMD_HDR_COMMANDID_LSB 0
343#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
344#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
345#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
346#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
347#define WMI_CMD_HDR_PLT_PRIV_LSB 24
348#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
349#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
350/* end of copy wmi.h */
351#endif /* CONFIG_WIN */
352
Rachit Kankane799d2c92018-02-19 11:28:10 +0530353#define WMI_MIN_HEAD_ROOM 64
354
355#ifdef WMI_INTERFACE_EVENT_LOGGING
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700356#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
357/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +0530358static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700359{
360 va_list args;
361
362 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +0530363 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700364 va_end(args);
365
Pratik Gandhi795ab912017-05-03 20:15:50 +0530366 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700367}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530368#else
369#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700370#endif
371
Govind Singhecf03cd2016-05-12 12:45:51 +0530372#ifndef MAX_WMI_INSTANCES
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530373#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530374#endif
375
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530376#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530377/* WMI commands */
378uint32_t g_wmi_command_buf_idx = 0;
379struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
380
381/* WMI commands TX completed */
382uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
383struct wmi_command_debug
384 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
385
386/* WMI events when processed */
387uint32_t g_wmi_event_buf_idx = 0;
388struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
389
390/* WMI events when queued */
391uint32_t g_wmi_rx_event_buf_idx = 0;
392struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530393#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530394
Govind Singhecf03cd2016-05-12 12:45:51 +0530395#define WMI_COMMAND_RECORD(h, a, b) { \
396 if (wmi_log_max_entry <= \
397 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
398 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
399 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
400 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
401 .command = a; \
402 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
403 wmi_command_log_buf_info.buf) \
404 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
405 b, wmi_record_max_length); \
406 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
407 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
408 time = qdf_get_log_timestamp(); \
409 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
410 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530411}
412
Govind Singhecf03cd2016-05-12 12:45:51 +0530413#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
414 if (wmi_log_max_entry <= \
415 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530416 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
417 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530418 ((struct wmi_command_debug *)h->log_info. \
419 wmi_command_tx_cmp_log_buf_info.buf) \
420 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
421 p_buf_tail_idx)]. \
422 command = a; \
423 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
424 wmi_command_tx_cmp_log_buf_info.buf) \
425 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
426 p_buf_tail_idx)]. \
427 data, b, wmi_record_max_length); \
428 ((struct wmi_command_debug *)h->log_info. \
429 wmi_command_tx_cmp_log_buf_info.buf) \
430 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
431 p_buf_tail_idx)]. \
432 time = qdf_get_log_timestamp(); \
433 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
434 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530435}
436
Govind Singhecf03cd2016-05-12 12:45:51 +0530437#define WMI_EVENT_RECORD(h, a, b) { \
438 if (wmi_log_max_entry <= \
439 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
440 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
441 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
442 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
443 event = a; \
444 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
445 wmi_event_log_buf_info.buf) \
446 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
447 wmi_record_max_length); \
448 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
449 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530450 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530451 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
452 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530453}
454
Govind Singhecf03cd2016-05-12 12:45:51 +0530455#define WMI_RX_EVENT_RECORD(h, a, b) { \
456 if (wmi_log_max_entry <= \
457 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
458 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
459 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
460 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
461 event = a; \
462 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
463 wmi_rx_event_log_buf_info.buf) \
464 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
465 data, b, wmi_record_max_length); \
466 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
467 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
468 time = qdf_get_log_timestamp(); \
469 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
470 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530471}
Govind Singh6b411b52016-03-06 19:55:02 +0530472
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530473#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530474uint32_t g_wmi_mgmt_command_buf_idx = 0;
475struct
476wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
477
478/* wmi_mgmt commands TX completed */
479uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
480struct wmi_command_debug
481wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
482
483/* wmi_mgmt events when processed */
484uint32_t g_wmi_mgmt_event_buf_idx = 0;
485struct wmi_event_debug
486wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530487#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530488
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530489#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
490 if (wmi_mgmt_log_max_entry <= \
491 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
492 *(h->log_info.wmi_mgmt_command_log_buf_info. \
493 p_buf_tail_idx) = 0; \
494 ((struct wmi_command_debug *)h->log_info. \
495 wmi_mgmt_command_log_buf_info.buf) \
496 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
497 command = a; \
498 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
499 wmi_mgmt_command_log_buf_info.buf) \
500 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
501 data, b, \
502 wmi_record_max_length); \
503 ((struct wmi_command_debug *)h->log_info. \
504 wmi_mgmt_command_log_buf_info.buf) \
505 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
506 time = qdf_get_log_timestamp(); \
507 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
508 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530509}
510
Govind Singhecf03cd2016-05-12 12:45:51 +0530511#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
512 if (wmi_mgmt_log_max_entry <= \
513 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
514 p_buf_tail_idx)) \
515 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
516 p_buf_tail_idx) = 0; \
517 ((struct wmi_command_debug *)h->log_info. \
518 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
519 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
520 p_buf_tail_idx)].command = a; \
521 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
522 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
523 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
524 p_buf_tail_idx)].data, b, \
525 wmi_record_max_length); \
526 ((struct wmi_command_debug *)h->log_info. \
527 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
528 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
529 p_buf_tail_idx)].time = \
530 qdf_get_log_timestamp(); \
531 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
532 p_buf_tail_idx))++; \
533 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530534}
535
Govind Singhecf03cd2016-05-12 12:45:51 +0530536#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
537 if (wmi_mgmt_log_max_entry <= \
538 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
539 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
540 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
541 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
542 .event = a; \
543 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
544 wmi_mgmt_event_log_buf_info.buf) \
545 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
546 data, b, wmi_record_max_length); \
547 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
548 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
549 time = qdf_get_log_timestamp(); \
550 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
551 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530552}
553
Govind Singhecf03cd2016-05-12 12:45:51 +0530554/* These are defined to made it as module param, which can be configured */
555uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
556uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
557uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
558uint32_t wmi_display_size = 100;
559
Govind Singhecf03cd2016-05-12 12:45:51 +0530560/**
561 * wmi_log_init() - Initialize WMI event logging
562 * @wmi_handle: WMI handle.
563 *
564 * Return: Initialization status
565 */
566#ifdef CONFIG_MCL
567static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
568{
569 struct wmi_log_buf_t *cmd_log_buf =
570 &wmi_handle->log_info.wmi_command_log_buf_info;
571 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
572 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
573
574 struct wmi_log_buf_t *event_log_buf =
575 &wmi_handle->log_info.wmi_event_log_buf_info;
576 struct wmi_log_buf_t *rx_event_log_buf =
577 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
578
579 struct wmi_log_buf_t *mgmt_cmd_log_buf =
580 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
581 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
582 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
583 struct wmi_log_buf_t *mgmt_event_log_buf =
584 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
585
586 /* WMI commands */
587 cmd_log_buf->length = 0;
588 cmd_log_buf->buf_tail_idx = 0;
589 cmd_log_buf->buf = wmi_command_log_buffer;
590 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700591 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530592
593 /* WMI commands TX completed */
594 cmd_tx_cmpl_log_buf->length = 0;
595 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
596 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
597 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700598 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530599
600 /* WMI events when processed */
601 event_log_buf->length = 0;
602 event_log_buf->buf_tail_idx = 0;
603 event_log_buf->buf = wmi_event_log_buffer;
604 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700605 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530606
607 /* WMI events when queued */
608 rx_event_log_buf->length = 0;
609 rx_event_log_buf->buf_tail_idx = 0;
610 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
611 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700612 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530613
614 /* WMI Management commands */
615 mgmt_cmd_log_buf->length = 0;
616 mgmt_cmd_log_buf->buf_tail_idx = 0;
617 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
618 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700619 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530620
621 /* WMI Management commands Tx completed*/
622 mgmt_cmd_tx_cmp_log_buf->length = 0;
623 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
624 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
625 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
626 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700627 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530628
629 /* WMI Management events when processed*/
630 mgmt_event_log_buf->length = 0;
631 mgmt_event_log_buf->buf_tail_idx = 0;
632 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
633 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700634 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530635
636 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
637 wmi_handle->log_info.wmi_logging_enable = 1;
638
639 return QDF_STATUS_SUCCESS;
640}
641#else
642static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
643{
644 struct wmi_log_buf_t *cmd_log_buf =
645 &wmi_handle->log_info.wmi_command_log_buf_info;
646 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
647 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
648
649 struct wmi_log_buf_t *event_log_buf =
650 &wmi_handle->log_info.wmi_event_log_buf_info;
651 struct wmi_log_buf_t *rx_event_log_buf =
652 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
653
654 struct wmi_log_buf_t *mgmt_cmd_log_buf =
655 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
656 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
657 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
658 struct wmi_log_buf_t *mgmt_event_log_buf =
659 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
660
661 wmi_handle->log_info.wmi_logging_enable = 0;
662
663 /* WMI commands */
664 cmd_log_buf->length = 0;
665 cmd_log_buf->buf_tail_idx = 0;
666 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
667 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700668 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530669
670 if (!cmd_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530671 qdf_print("no memory for WMI command log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530672 return QDF_STATUS_E_NOMEM;
673 }
674 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
675
676 /* WMI commands TX completed */
677 cmd_tx_cmpl_log_buf->length = 0;
678 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
679 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
680 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700681 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530682
683 if (!cmd_tx_cmpl_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530684 qdf_print("no memory for WMI Command Tx Complete log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530685 return QDF_STATUS_E_NOMEM;
686 }
687 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
688 &cmd_tx_cmpl_log_buf->buf_tail_idx;
689
690 /* WMI events when processed */
691 event_log_buf->length = 0;
692 event_log_buf->buf_tail_idx = 0;
693 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
694 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700695 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530696
697 if (!event_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530698 qdf_print("no memory for WMI Event log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530699 return QDF_STATUS_E_NOMEM;
700 }
701 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
702
703 /* WMI events when queued */
704 rx_event_log_buf->length = 0;
705 rx_event_log_buf->buf_tail_idx = 0;
706 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
707 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700708 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530709
710 if (!rx_event_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530711 qdf_print("no memory for WMI Event Rx log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530712 return QDF_STATUS_E_NOMEM;
713 }
714 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
715
716 /* WMI Management commands */
717 mgmt_cmd_log_buf->length = 0;
718 mgmt_cmd_log_buf->buf_tail_idx = 0;
719 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700720 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
721 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530722
723 if (!mgmt_cmd_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530724 qdf_print("no memory for WMI Management Command log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530725 return QDF_STATUS_E_NOMEM;
726 }
727 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
728
729 /* WMI Management commands Tx completed*/
730 mgmt_cmd_tx_cmp_log_buf->length = 0;
731 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
732 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
733 qdf_mem_malloc(
734 wmi_mgmt_log_max_entry *
735 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700736 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530737
738 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530739 qdf_print("no memory for WMI Management Command Tx complete log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530740 return QDF_STATUS_E_NOMEM;
741 }
742 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
743 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
744
745 /* WMI Management events when processed*/
746 mgmt_event_log_buf->length = 0;
747 mgmt_event_log_buf->buf_tail_idx = 0;
748
749 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
750 wmi_mgmt_log_max_entry *
751 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700752 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530753
754 if (!mgmt_event_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530755 qdf_print("no memory for WMI Management Event log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530756 return QDF_STATUS_E_NOMEM;
757 }
758 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
759
760 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
761 wmi_handle->log_info.wmi_logging_enable = 1;
762
763 return QDF_STATUS_SUCCESS;
764}
765#endif
766
767/**
768 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
769 * event logging
770 * @wmi_handle: WMI handle.
771 *
772 * Return: None
773 */
774#ifndef CONFIG_MCL
775static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
776{
777 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
778 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
779 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
780 qdf_mem_free(
781 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
782 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
783 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
784 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
785 qdf_mem_free(
786 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
787 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
788 qdf_mem_free(
789 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
790 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
791 qdf_mem_free(
792 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
793 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
794 qdf_mem_free(
795 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
796 wmi_handle->log_info.wmi_logging_enable = 0;
797 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
798}
799#else
800static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
801{
802 /* Do Nothing */
803}
804#endif
805
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700806/**
807 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
808 * @log_buffer: the command log buffer metadata of the buffer to print
809 * @count: the maximum number of entries to print
810 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
811 * @print_priv: any data required by the print method, e.g. a file handle
812 *
813 * Return: None
814 */
815static void
816wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
817 qdf_abstract_print *print, void *print_priv)
818{
819 static const int data_len =
820 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
821 char str[128];
822 uint32_t idx;
823
824 if (count > log_buffer->size)
825 count = log_buffer->size;
826 if (count > log_buffer->length)
827 count = log_buffer->length;
828
829 /* subtract count from index, and wrap if necessary */
830 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
831 idx %= log_buffer->size;
832
833 print(print_priv, "Time (seconds) Cmd Id Payload");
834 while (count) {
835 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
836 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700837 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700838 int len = 0;
839 int i;
840
Dustin Brown8ea39122017-04-10 13:26:56 -0700841 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700842 len += scnprintf(str + len, sizeof(str) - len,
843 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700844 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700845 cmd_log->command, cmd_log->command);
846 for (i = 0; i < data_len; ++i) {
847 len += scnprintf(str + len, sizeof(str) - len,
848 "0x%08x ", cmd_log->data[i]);
849 }
850
851 print(print_priv, str);
852
853 --count;
854 ++idx;
855 if (idx >= log_buffer->size)
856 idx = 0;
857 }
858}
859
860/**
861 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
862 * @log_buffer: the event log buffer metadata of the buffer to print
863 * @count: the maximum number of entries to print
864 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
865 * @print_priv: any data required by the print method, e.g. a file handle
866 *
867 * Return: None
868 */
869static void
870wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
871 qdf_abstract_print *print, void *print_priv)
872{
873 static const int data_len =
874 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
875 char str[128];
876 uint32_t idx;
877
878 if (count > log_buffer->size)
879 count = log_buffer->size;
880 if (count > log_buffer->length)
881 count = log_buffer->length;
882
883 /* subtract count from index, and wrap if necessary */
884 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
885 idx %= log_buffer->size;
886
887 print(print_priv, "Time (seconds) Event Id Payload");
888 while (count) {
889 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
890 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700891 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700892 int len = 0;
893 int i;
894
Dustin Brown8ea39122017-04-10 13:26:56 -0700895 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700896 len += scnprintf(str + len, sizeof(str) - len,
897 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700898 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700899 event_log->event, event_log->event);
900 for (i = 0; i < data_len; ++i) {
901 len += scnprintf(str + len, sizeof(str) - len,
902 "0x%08x ", event_log->data[i]);
903 }
904
905 print(print_priv, str);
906
907 --count;
908 ++idx;
909 if (idx >= log_buffer->size)
910 idx = 0;
911 }
912}
913
914inline void
915wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
916 qdf_abstract_print *print, void *print_priv)
917{
918 wmi_print_cmd_log_buffer(
919 &wmi->log_info.wmi_command_log_buf_info,
920 count, print, print_priv);
921}
922
923inline void
924wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
925 qdf_abstract_print *print, void *print_priv)
926{
927 wmi_print_cmd_log_buffer(
928 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
929 count, print, print_priv);
930}
931
932inline void
933wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
934 qdf_abstract_print *print, void *print_priv)
935{
936 wmi_print_cmd_log_buffer(
937 &wmi->log_info.wmi_mgmt_command_log_buf_info,
938 count, print, print_priv);
939}
940
941inline void
942wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
943 qdf_abstract_print *print, void *print_priv)
944{
945 wmi_print_cmd_log_buffer(
946 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
947 count, print, print_priv);
948}
949
950inline void
951wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
952 qdf_abstract_print *print, void *print_priv)
953{
954 wmi_print_event_log_buffer(
955 &wmi->log_info.wmi_event_log_buf_info,
956 count, print, print_priv);
957}
958
959inline void
960wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
961 qdf_abstract_print *print, void *print_priv)
962{
963 wmi_print_event_log_buffer(
964 &wmi->log_info.wmi_rx_event_log_buf_info,
965 count, print, print_priv);
966}
967
968inline void
969wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
970 qdf_abstract_print *print, void *print_priv)
971{
972 wmi_print_event_log_buffer(
973 &wmi->log_info.wmi_mgmt_event_log_buf_info,
974 count, print, print_priv);
975}
976
Govind Singhecf03cd2016-05-12 12:45:51 +0530977
978/* debugfs routines*/
979
980/**
981 * debug_wmi_##func_base##_show() - debugfs functions to display content of
982 * command and event buffers. Macro uses max buffer length to display
983 * buffer when it is wraparound.
984 *
985 * @m: debugfs handler to access wmi_handle
986 * @v: Variable arguments (not used)
987 *
988 * Return: Length of characters printed
989 */
990#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
991 static int debug_wmi_##func_base##_show(struct seq_file *m, \
992 void *v) \
993 { \
994 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
995 struct wmi_log_buf_t *wmi_log = \
996 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
997 int pos, nread, outlen; \
998 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800999 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +05301000 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301001 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
1002 if (!wmi_log->length) { \
1003 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +05301004 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +05301005 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301006 } \
Govind Singhecf03cd2016-05-12 12:45:51 +05301007 \
1008 if (wmi_log->length <= wmi_ring_size) \
1009 nread = wmi_log->length; \
1010 else \
1011 nread = wmi_ring_size; \
1012 \
1013 if (*(wmi_log->p_buf_tail_idx) == 0) \
1014 /* tail can be 0 after wrap-around */ \
1015 pos = wmi_ring_size - 1; \
1016 else \
1017 pos = *(wmi_log->p_buf_tail_idx) - 1; \
1018 \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301019 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301020 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +05301021 while (nread--) { \
1022 struct wmi_command_debug *wmi_record; \
1023 \
1024 wmi_record = (struct wmi_command_debug *) \
1025 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +05301026 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +05301027 (wmi_record->command)); \
nobelj2a6da6f2017-12-11 23:18:27 -08001028 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
1029 &usecs); \
1030 outlen += \
1031 wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
1032 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301033 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +05301034 for (i = 0; i < (wmi_record_max_length/ \
1035 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301036 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +05301037 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301038 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +05301039 \
1040 if (pos == 0) \
1041 pos = wmi_ring_size - 1; \
1042 else \
1043 pos--; \
1044 } \
Govind Singhecf03cd2016-05-12 12:45:51 +05301045 return outlen; \
1046 } \
1047
1048#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
1049 static int debug_wmi_##func_base##_show(struct seq_file *m, \
1050 void *v) \
1051 { \
1052 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
1053 struct wmi_log_buf_t *wmi_log = \
1054 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
1055 int pos, nread, outlen; \
1056 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -08001057 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +05301058 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301059 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
1060 if (!wmi_log->length) { \
1061 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +05301062 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +05301063 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301064 } \
Govind Singhecf03cd2016-05-12 12:45:51 +05301065 \
1066 if (wmi_log->length <= wmi_ring_size) \
1067 nread = wmi_log->length; \
1068 else \
1069 nread = wmi_ring_size; \
1070 \
1071 if (*(wmi_log->p_buf_tail_idx) == 0) \
1072 /* tail can be 0 after wrap-around */ \
1073 pos = wmi_ring_size - 1; \
1074 else \
1075 pos = *(wmi_log->p_buf_tail_idx) - 1; \
1076 \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301077 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301078 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +05301079 while (nread--) { \
1080 struct wmi_event_debug *wmi_record; \
1081 \
1082 wmi_record = (struct wmi_event_debug *) \
1083 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
nobelj2a6da6f2017-12-11 23:18:27 -08001084 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
1085 &usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301086 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +05301087 (wmi_record->event)); \
nobelj2a6da6f2017-12-11 23:18:27 -08001088 outlen += \
1089 wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
1090 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301091 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +05301092 for (i = 0; i < (wmi_record_max_length/ \
1093 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301094 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +05301095 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301096 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +05301097 \
1098 if (pos == 0) \
1099 pos = wmi_ring_size - 1; \
1100 else \
1101 pos--; \
1102 } \
Govind Singhecf03cd2016-05-12 12:45:51 +05301103 return outlen; \
1104 }
1105
1106GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
1107GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
1108GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
1109GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
1110GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
1111GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
1112 wmi_display_size);
1113GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
1114
1115/**
1116 * debug_wmi_enable_show() - debugfs functions to display enable state of
1117 * wmi logging feature.
1118 *
1119 * @m: debugfs handler to access wmi_handle
1120 * @v: Variable arguments (not used)
1121 *
1122 * Return: always 1
1123 */
1124static int debug_wmi_enable_show(struct seq_file *m, void *v)
1125{
1126 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
1127
Pratik Gandhi795ab912017-05-03 20:15:50 +05301128 return wmi_bp_seq_printf(m, "%d\n",
1129 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +05301130}
1131
1132/**
1133 * debug_wmi_log_size_show() - debugfs functions to display configured size of
1134 * wmi logging command/event buffer and management command/event buffer.
1135 *
1136 * @m: debugfs handler to access wmi_handle
1137 * @v: Variable arguments (not used)
1138 *
1139 * Return: Length of characters printed
1140 */
1141static int debug_wmi_log_size_show(struct seq_file *m, void *v)
1142{
1143
Pratik Gandhi795ab912017-05-03 20:15:50 +05301144 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
1145 wmi_log_max_entry);
1146 return wmi_bp_seq_printf(m,
1147 "WMI management command/events log max size:%d\n",
1148 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +05301149}
1150
1151/**
1152 * debug_wmi_##func_base##_write() - debugfs functions to clear
1153 * wmi logging command/event buffer and management command/event buffer.
1154 *
1155 * @file: file handler to access wmi_handle
1156 * @buf: received data buffer
1157 * @count: length of received buffer
1158 * @ppos: Not used
1159 *
1160 * Return: count
1161 */
1162#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
1163 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
1164 const char __user *buf, \
1165 size_t count, loff_t *ppos) \
1166 { \
1167 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +05301168 wmi_unified_t wmi_handle = \
1169 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +05301170 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
1171 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301172 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +05301173 \
Pratik Gandhi795ab912017-05-03 20:15:50 +05301174 if ((!buf) || (count > 50)) \
1175 return -EFAULT; \
1176 \
1177 if (copy_from_user(locbuf, buf, count)) \
1178 return -EFAULT; \
1179 \
1180 ret = sscanf(locbuf, "%d", &k); \
1181 if ((ret != 1) || (k != 0)) { \
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301182 qdf_print("Wrong input, echo 0 to clear the wmi buffer");\
Govind Singhecf03cd2016-05-12 12:45:51 +05301183 return -EINVAL; \
1184 } \
1185 \
1186 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
1187 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
1188 sizeof(struct wmi_record_type)); \
1189 wmi_log->length = 0; \
1190 *(wmi_log->p_buf_tail_idx) = 0; \
1191 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
1192 \
1193 return count; \
1194 }
1195
1196GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
1197 wmi_command_debug);
1198GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
1199 wmi_command_debug);
1200GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
1201 wmi_event_debug);
1202GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
1203 wmi_event_debug);
1204GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
1205 wmi_command_debug);
1206GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
1207 wmi_mgmt_log_max_entry, wmi_command_debug);
1208GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
1209 wmi_event_debug);
1210
1211/**
1212 * debug_wmi_enable_write() - debugfs functions to enable/disable
1213 * wmi logging feature.
1214 *
1215 * @file: file handler to access wmi_handle
1216 * @buf: received data buffer
1217 * @count: length of received buffer
1218 * @ppos: Not used
1219 *
1220 * Return: count
1221 */
1222static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
1223 size_t count, loff_t *ppos)
1224{
Pratik Gandhidad75ff2017-01-16 12:50:27 +05301225 wmi_unified_t wmi_handle =
1226 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +05301227 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +05301228 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +05301229
Pratik Gandhi795ab912017-05-03 20:15:50 +05301230 if ((!buf) || (count > 50))
1231 return -EFAULT;
1232
1233 if (copy_from_user(locbuf, buf, count))
1234 return -EFAULT;
1235
1236 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +05301237 if ((ret != 1) || ((k != 0) && (k != 1)))
1238 return -EINVAL;
1239
1240 wmi_handle->log_info.wmi_logging_enable = k;
1241 return count;
1242}
1243
1244/**
1245 * debug_wmi_log_size_write() - reserved.
1246 *
1247 * @file: file handler to access wmi_handle
1248 * @buf: received data buffer
1249 * @count: length of received buffer
1250 * @ppos: Not used
1251 *
1252 * Return: count
1253 */
1254static ssize_t debug_wmi_log_size_write(struct file *file,
1255 const char __user *buf, size_t count, loff_t *ppos)
1256{
1257 return -EINVAL;
1258}
1259
1260/* Structure to maintain debug information */
1261struct wmi_debugfs_info {
1262 const char *name;
Govind Singhecf03cd2016-05-12 12:45:51 +05301263 const struct file_operations *ops;
1264};
1265
1266#define DEBUG_FOO(func_base) { .name = #func_base, \
1267 .ops = &debug_##func_base##_ops }
1268
1269/**
1270 * debug_##func_base##_open() - Open debugfs entry for respective command
1271 * and event buffer.
1272 *
1273 * @inode: node for debug dir entry
1274 * @file: file handler
1275 *
1276 * Return: open status
1277 */
1278#define GENERATE_DEBUG_STRUCTS(func_base) \
1279 static int debug_##func_base##_open(struct inode *inode, \
1280 struct file *file) \
1281 { \
1282 return single_open(file, debug_##func_base##_show, \
1283 inode->i_private); \
1284 } \
1285 \
1286 \
1287 static struct file_operations debug_##func_base##_ops = { \
1288 .open = debug_##func_base##_open, \
1289 .read = seq_read, \
1290 .llseek = seq_lseek, \
1291 .write = debug_##func_base##_write, \
1292 .release = single_release, \
1293 };
1294
1295GENERATE_DEBUG_STRUCTS(wmi_command_log);
1296GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1297GENERATE_DEBUG_STRUCTS(wmi_event_log);
1298GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1299GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1300GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1301GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1302GENERATE_DEBUG_STRUCTS(wmi_enable);
1303GENERATE_DEBUG_STRUCTS(wmi_log_size);
1304
c_priysb5f94a82018-06-12 16:53:51 +05301305struct wmi_debugfs_info wmi_debugfs_infos[NUM_DEBUG_INFOS] = {
Govind Singhecf03cd2016-05-12 12:45:51 +05301306 DEBUG_FOO(wmi_command_log),
1307 DEBUG_FOO(wmi_command_tx_cmp_log),
1308 DEBUG_FOO(wmi_event_log),
1309 DEBUG_FOO(wmi_rx_event_log),
1310 DEBUG_FOO(wmi_mgmt_command_log),
1311 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1312 DEBUG_FOO(wmi_mgmt_event_log),
1313 DEBUG_FOO(wmi_enable),
1314 DEBUG_FOO(wmi_log_size),
1315};
1316
Govind Singhecf03cd2016-05-12 12:45:51 +05301317
1318/**
1319 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1320 *
1321 * @wmi_handle: wmi handle
1322 * @par_entry: debug directory entry
1323 * @id: Index to debug info data array
1324 *
1325 * Return: none
1326 */
1327static void wmi_debugfs_create(wmi_unified_t wmi_handle,
c_priysb5f94a82018-06-12 16:53:51 +05301328 struct dentry *par_entry)
Govind Singhecf03cd2016-05-12 12:45:51 +05301329{
1330 int i;
1331
c_priysb5f94a82018-06-12 16:53:51 +05301332 if (!par_entry)
Govind Singhecf03cd2016-05-12 12:45:51 +05301333 goto out;
1334
1335 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
c_priysb5f94a82018-06-12 16:53:51 +05301336 wmi_handle->debugfs_de[i] = debugfs_create_file(
Govind Singhecf03cd2016-05-12 12:45:51 +05301337 wmi_debugfs_infos[i].name, 0644, par_entry,
1338 wmi_handle, wmi_debugfs_infos[i].ops);
1339
c_priysb5f94a82018-06-12 16:53:51 +05301340 if (!wmi_handle->debugfs_de[i]) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301341 qdf_print("debug Entry creation failed!");
Govind Singhecf03cd2016-05-12 12:45:51 +05301342 goto out;
1343 }
1344 }
1345
1346 return;
1347
1348out:
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301349 qdf_print("debug Entry creation failed!");
Govind Singhecf03cd2016-05-12 12:45:51 +05301350 wmi_log_buffer_free(wmi_handle);
1351 return;
1352}
1353
1354/**
1355 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301356 * @wmi_handle: wmi handle
1357 * @dentry: debugfs directory entry
1358 * @id: Index to debug info data array
1359 *
1360 * Return: none
1361 */
Govind Singh06c18392016-06-10 10:33:19 +05301362static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301363{
1364 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301365 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
Govind Singhecf03cd2016-05-12 12:45:51 +05301366
c_priysb5f94a82018-06-12 16:53:51 +05301367 if (dentry) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301368 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
c_priysb5f94a82018-06-12 16:53:51 +05301369 if (wmi_handle->debugfs_de[i])
1370 wmi_handle->debugfs_de[i] = NULL;
Govind Singhecf03cd2016-05-12 12:45:51 +05301371 }
1372 }
1373
1374 if (dentry)
1375 debugfs_remove_recursive(dentry);
1376}
1377
1378/**
1379 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1380 * create debugfs enteries.
1381 *
1382 * @h: wmi handler
1383 *
1384 * Return: init status
1385 */
c_priysb5f94a82018-06-12 16:53:51 +05301386static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle, uint32_t pdev_idx)
Govind Singhecf03cd2016-05-12 12:45:51 +05301387{
c_priysb5f94a82018-06-12 16:53:51 +05301388 char buf[32];
Govind Singhecf03cd2016-05-12 12:45:51 +05301389
c_priysb5f94a82018-06-12 16:53:51 +05301390 snprintf(buf, sizeof(buf), "WMI_SOC%u_PDEV%u",
1391 wmi_handle->soc->soc_idx, pdev_idx);
Govind Singhecf03cd2016-05-12 12:45:51 +05301392
c_priysb5f94a82018-06-12 16:53:51 +05301393 wmi_handle->log_info.wmi_log_debugfs_dir =
1394 debugfs_create_dir(buf, NULL);
Govind Singhecf03cd2016-05-12 12:45:51 +05301395
c_priysb5f94a82018-06-12 16:53:51 +05301396 if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301397 qdf_print("error while creating debugfs dir for %s", buf);
c_priysb5f94a82018-06-12 16:53:51 +05301398 return QDF_STATUS_E_FAILURE;
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301399 }
c_priysb5f94a82018-06-12 16:53:51 +05301400 wmi_debugfs_create(wmi_handle,
1401 wmi_handle->log_info.wmi_log_debugfs_dir);
Govind Singhecf03cd2016-05-12 12:45:51 +05301402
1403 return QDF_STATUS_SUCCESS;
1404}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001405
1406/**
1407 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1408 *
1409 * @wmi_handle: wmi handle
1410 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001411 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001412 * @vdev_id: vdev id
1413 * @chanfreq: channel frequency
1414 *
1415 * Return: none
1416 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301417void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001418 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001419{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301420
1421 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1422
1423 data[0] = ((struct wmi_command_header *)header)->type;
1424 data[1] = ((struct wmi_command_header *)header)->sub_type;
1425 data[2] = vdev_id;
1426 data[3] = chanfreq;
1427
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001428 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1429
Rakesh Pillai05110462017-12-27 14:08:59 +05301430 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001431
1432 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1433}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001434#else
1435/**
1436 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1437 * @wmi_handle: wmi handle
1438 * @dentry: debugfs directory entry
1439 * @id: Index to debug info data array
1440 *
1441 * Return: none
1442 */
Govind Singh06c18392016-06-10 10:33:19 +05301443static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301444void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001445 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301446static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301447#endif /*WMI_INTERFACE_EVENT_LOGGING */
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301448qdf_export_symbol(wmi_mgmt_cmd_record);
Govind Singh6b411b52016-03-06 19:55:02 +05301449
Govind Singh6b411b52016-03-06 19:55:02 +05301450int wmi_get_host_credits(wmi_unified_t wmi_handle);
1451/* WMI buffer APIs */
1452
Shiva Krishna Pittala79293372018-04-02 17:23:42 +05301453#ifdef NBUF_MEMORY_DEBUG
Govind Singh6b411b52016-03-06 19:55:02 +05301454wmi_buf_t
Debasis Daseaf8a8b2018-04-04 17:17:55 +05301455wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len, uint8_t *file_name,
1456 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301457{
1458 wmi_buf_t wmi_buf;
1459
1460 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301461 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301462 return NULL;
1463 }
1464
Govind Singhb53420c2016-03-09 14:32:57 +05301465 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301466 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1467 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1468 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301469
1470 if (!wmi_buf)
1471 return NULL;
1472
1473 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301474 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301475
1476 /*
1477 * Set the length of the buffer to match the allocation size.
1478 */
Govind Singhb53420c2016-03-09 14:32:57 +05301479 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301480
1481 return wmi_buf;
1482}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301483qdf_export_symbol(wmi_buf_alloc_debug);
Govind Singh6b411b52016-03-06 19:55:02 +05301484
1485void wmi_buf_free(wmi_buf_t net_buf)
1486{
Govind Singhb53420c2016-03-09 14:32:57 +05301487 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301488}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301489qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301490#else
Arif Hussain3f6ad3d2018-07-19 14:15:36 -07001491wmi_buf_t wmi_buf_alloc_fl(wmi_unified_t wmi_handle, uint32_t len,
1492 const char *func, uint32_t line)
Govind Singh6b411b52016-03-06 19:55:02 +05301493{
1494 wmi_buf_t wmi_buf;
1495
1496 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Arif Hussain3f6ad3d2018-07-19 14:15:36 -07001497 wmi_nofl_err("%s:%d, Invalid len:%d", func, line, len);
1498 QDF_DEBUG_PANIC();
Govind Singh6b411b52016-03-06 19:55:02 +05301499 return NULL;
1500 }
1501
Arif Hussainf4440382018-07-20 12:58:31 -07001502 wmi_buf = qdf_nbuf_alloc_fl(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
1503 WMI_MIN_HEAD_ROOM, 4, false, func, line);
Govind Singh6b411b52016-03-06 19:55:02 +05301504 if (!wmi_buf)
1505 return NULL;
1506
1507 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301508 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301509
1510 /*
1511 * Set the length of the buffer to match the allocation size.
1512 */
Govind Singhb53420c2016-03-09 14:32:57 +05301513 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301514 return wmi_buf;
1515}
Arif Hussain3f6ad3d2018-07-19 14:15:36 -07001516qdf_export_symbol(wmi_buf_alloc_fl);
Govind Singh6b411b52016-03-06 19:55:02 +05301517
1518void wmi_buf_free(wmi_buf_t net_buf)
1519{
Govind Singhb53420c2016-03-09 14:32:57 +05301520 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301521}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301522qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301523#endif
1524
1525/**
1526 * wmi_get_max_msg_len() - get maximum WMI message length
1527 * @wmi_handle: WMI handle.
1528 *
1529 * This function returns the maximum WMI message length
1530 *
1531 * Return: maximum WMI message length
1532 */
1533uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1534{
1535 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1536}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301537qdf_export_symbol(wmi_get_max_msg_len);
Govind Singh6b411b52016-03-06 19:55:02 +05301538
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301539#ifndef WMI_CMD_STRINGS
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301540static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301541{
1542 return "Invalid WMI cmd";
1543}
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301544
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301545#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301546
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301547#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301548static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1549{
1550 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1551 wmi_id_to_name(cmd_id), cmd_id, tag);
1552}
1553
Govind Singh6b411b52016-03-06 19:55:02 +05301554/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301555 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1556 * @cmd_id: command to check
1557 *
1558 * Return: true if the command is part of the resume sequence.
1559 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301560static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301561{
1562 switch (cmd_id) {
1563 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1564 case WMI_PDEV_RESUME_CMDID:
1565 return true;
1566
1567 default:
1568 return false;
1569 }
1570}
1571#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301572static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301573{
1574 return false;
1575}
1576#endif
1577
Arif Hussain07d902a2018-07-19 15:05:16 -07001578QDF_STATUS wmi_unified_cmd_send_fl(wmi_unified_t wmi_handle, wmi_buf_t buf,
1579 uint32_t len, uint32_t cmd_id,
1580 const char *func, uint32_t line)
Govind Singh6b411b52016-03-06 19:55:02 +05301581{
1582 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301583 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301584 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301585
1586 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301587 htc_tag =
Vivekc5823092018-03-22 23:27:21 +05301588 (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301589 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301590 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301591 (!wmi_is_pm_resume_cmd(cmd_id))) {
Arif Hussain07d902a2018-07-19 15:05:16 -07001592 wmi_nofl_err("%s:%d, Target is suspended", func, line);
1593 QDF_DEBUG_PANIC();
Govind Singh67922e82016-04-01 16:48:57 +05301594 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301595 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301596 if (wmi_handle->wmi_stopinprogress) {
Arif Hussain07d902a2018-07-19 15:05:16 -07001597 wmi_nofl_err("%s:%d, WMI stop in progress", func, line);
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001598 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301599 }
Govind Singh6b411b52016-03-06 19:55:02 +05301600
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301601#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301602 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301603 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301604 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301605
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301606 if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301607 != 0) {
Arif Hussain07d902a2018-07-19 15:05:16 -07001608 wmi_nofl_err("%s:%d, Invalid WMI Param Buffer for Cmd:%d",
1609 func, line, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301610 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301611 }
1612 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301613#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301614
Govind Singhb53420c2016-03-09 14:32:57 +05301615 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
Arif Hussain07d902a2018-07-19 15:05:16 -07001616 wmi_nofl_err("%s:%d, Failed to send cmd %x, no memory",
1617 func, line, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301618 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301619 }
1620
Vignesh Viswanathan737cef72018-06-15 12:42:45 +05301621 qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
Govind Singhb53420c2016-03-09 14:32:57 +05301622 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301623
Govind Singhb53420c2016-03-09 14:32:57 +05301624 qdf_atomic_inc(&wmi_handle->pending_cmds);
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301625 if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
1626 wmi_handle->wmi_max_cmds) {
Arif Hussain07d902a2018-07-19 15:05:16 -07001627 wmi_nofl_err("hostcredits = %d",
1628 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301629 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301630 qdf_atomic_dec(&wmi_handle->pending_cmds);
Arif Hussain07d902a2018-07-19 15:05:16 -07001631 wmi_nofl_err("%s:%d, MAX %d WMI Pending cmds reached",
1632 func, line, wmi_handle->wmi_max_cmds);
Govind Singhb53420c2016-03-09 14:32:57 +05301633 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301634 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301635 }
1636
Arif Hussain07d902a2018-07-19 15:05:16 -07001637 pkt = qdf_mem_malloc_fl(sizeof(*pkt), func, line);
Govind Singh6b411b52016-03-06 19:55:02 +05301638 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301639 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh67922e82016-04-01 16:48:57 +05301640 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301641 }
1642
1643 SET_HTC_PACKET_INFO_TX(pkt,
1644 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301645 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301646 wmi_handle->wmi_endpoint_id, htc_tag);
1647
1648 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301649#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301650 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301651#endif
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05301652 wmi_ext_dbg_msg_cmd_record(wmi_handle,
1653 qdf_nbuf_data(buf), qdf_nbuf_len(buf));
Govind Singh6b411b52016-03-06 19:55:02 +05301654#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301655 if (wmi_handle->log_info.wmi_logging_enable) {
1656 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
jiad36c94d22018-01-22 15:37:03 +08001657 /*
1658 * Record 16 bytes of WMI cmd data -
1659 * exclude TLV and WMI headers
1660 *
1661 * WMI mgmt command already recorded in wmi_mgmt_cmd_record
1662 */
1663 if (wmi_handle->ops->is_management_record(cmd_id) == false) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301664 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301665 qdf_nbuf_data(buf) +
1666 wmi_handle->log_info.buf_offset_command);
Govind Singhecf03cd2016-05-12 12:45:51 +05301667 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301668 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1669 }
Govind Singh6b411b52016-03-06 19:55:02 +05301670#endif
1671
1672 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1673
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301674 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301675 qdf_atomic_dec(&wmi_handle->pending_cmds);
Arif Hussain07d902a2018-07-19 15:05:16 -07001676 wmi_nofl_err("%s:%d, htc_send_pkt failed, status:%d",
1677 func, line, status);
Houston Hoffman40805b82016-10-13 15:30:52 -07001678 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301679 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05301680 }
Govind Singh6b411b52016-03-06 19:55:02 +05301681
Govind Singhb53420c2016-03-09 14:32:57 +05301682 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301683}
Arif Hussain07d902a2018-07-19 15:05:16 -07001684qdf_export_symbol(wmi_unified_cmd_send_fl);
Govind Singh6b411b52016-03-06 19:55:02 +05301685
1686/**
1687 * wmi_unified_get_event_handler_ix() - gives event handler's index
1688 * @wmi_handle: handle to wmi
1689 * @event_id: wmi event id
1690 *
1691 * Return: event handler's index
1692 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001693static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
1694 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301695{
1696 uint32_t idx = 0;
1697 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301698 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301699
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301700 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05301701 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1702 if (wmi_handle->event_id[idx] == event_id &&
1703 wmi_handle->event_handler[idx] != NULL) {
1704 return idx;
1705 }
1706 }
1707
1708 return invalid_idx;
1709}
1710
1711/**
Soumya Bhat488092d2017-03-22 14:41:01 +05301712 * wmi_unified_register_event() - register wmi event handler
1713 * @wmi_handle: handle to wmi
1714 * @event_id: wmi event id
1715 * @handler_func: wmi event handler function
1716 *
1717 * Return: 0 on success
1718 */
1719int wmi_unified_register_event(wmi_unified_t wmi_handle,
1720 uint32_t event_id,
1721 wmi_unified_event_handler handler_func)
1722{
1723 uint32_t idx = 0;
1724 uint32_t evt_id;
1725 struct wmi_soc *soc = wmi_handle->soc;
1726
1727 if (event_id >= wmi_events_max ||
1728 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301729 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1730 "%s: Event id %d is unavailable",
1731 __func__, event_id);
Soumya Bhat488092d2017-03-22 14:41:01 +05301732 return QDF_STATUS_E_FAILURE;
1733 }
1734 evt_id = wmi_handle->wmi_events[event_id];
1735 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301736 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1737 "%s : event handler already registered 0x%x",
1738 __func__, evt_id);
Soumya Bhat488092d2017-03-22 14:41:01 +05301739 return QDF_STATUS_E_FAILURE;
1740 }
1741 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301742 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1743 "%s : no more event handlers 0x%x",
1744 __func__, evt_id);
Soumya Bhat488092d2017-03-22 14:41:01 +05301745 return QDF_STATUS_E_FAILURE;
1746 }
1747 idx = soc->max_event_idx;
1748 wmi_handle->event_handler[idx] = handler_func;
1749 wmi_handle->event_id[idx] = evt_id;
1750 qdf_spin_lock_bh(&soc->ctx_lock);
1751 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
1752 qdf_spin_unlock_bh(&soc->ctx_lock);
1753 soc->max_event_idx++;
1754
1755 return 0;
1756}
1757
1758/**
Govind Singh6b411b52016-03-06 19:55:02 +05301759 * wmi_unified_register_event_handler() - register wmi event handler
1760 * @wmi_handle: handle to wmi
1761 * @event_id: wmi event id
1762 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301763 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301764 *
Soumya Bhat488092d2017-03-22 14:41:01 +05301765 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05301766 * Return: 0 on success
1767 */
1768int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301769 wmi_conv_event_id event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301770 wmi_unified_event_handler handler_func,
1771 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301772{
1773 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301774 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301775 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301776
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301777 if (event_id >= wmi_events_max ||
1778 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301779 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1780 "%s: Event id %d is unavailable",
1781 __func__, event_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301782 return QDF_STATUS_E_FAILURE;
1783 }
1784 evt_id = wmi_handle->wmi_events[event_id];
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301785
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301786 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301787 qdf_print("event handler already registered 0x%x",
1788 evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301789 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301790 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301791 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301792 qdf_print("no more event handlers 0x%x",
1793 evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301794 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301795 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07001796 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301797 "Registered event handler for event 0x%8x", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301798 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301799 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301800 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301801 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301802 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301803 qdf_spin_unlock_bh(&soc->ctx_lock);
1804 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05301805
1806 return 0;
1807}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301808qdf_export_symbol(wmi_unified_register_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301809
1810/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301811 * wmi_unified_unregister_event() - unregister wmi event handler
1812 * @wmi_handle: handle to wmi
1813 * @event_id: wmi event id
1814 *
1815 * Return: 0 on success
1816 */
1817int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
1818 uint32_t event_id)
1819{
1820 uint32_t idx = 0;
1821 uint32_t evt_id;
1822 struct wmi_soc *soc = wmi_handle->soc;
1823
1824 if (event_id >= wmi_events_max ||
1825 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301826 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1827 "%s: Event id %d is unavailable",
1828 __func__, event_id);
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301829 return QDF_STATUS_E_FAILURE;
1830 }
1831 evt_id = wmi_handle->wmi_events[event_id];
1832
1833 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
1834 if (idx == -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301835 qdf_print("event handler is not registered: evt id 0x%x",
1836 evt_id);
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301837 return QDF_STATUS_E_FAILURE;
1838 }
1839 wmi_handle->event_handler[idx] = NULL;
1840 wmi_handle->event_id[idx] = 0;
1841 --soc->max_event_idx;
1842 wmi_handle->event_handler[idx] =
1843 wmi_handle->event_handler[soc->max_event_idx];
1844 wmi_handle->event_id[idx] =
1845 wmi_handle->event_id[soc->max_event_idx];
1846
1847 return 0;
1848}
1849
1850/**
Govind Singh6b411b52016-03-06 19:55:02 +05301851 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1852 * @wmi_handle: handle to wmi
1853 * @event_id: wmi event id
1854 *
1855 * Return: 0 on success
1856 */
1857int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301858 wmi_conv_event_id event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301859{
1860 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301861 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301862 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301863
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301864 if (event_id >= wmi_events_max ||
1865 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301866 qdf_print("Event id %d is unavailable",
1867 event_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301868 return QDF_STATUS_E_FAILURE;
1869 }
1870 evt_id = wmi_handle->wmi_events[event_id];
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301871
1872 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301873 if (idx == -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301874 qdf_print("event handler is not registered: evt id 0x%x",
1875 evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301876 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301877 }
1878 wmi_handle->event_handler[idx] = NULL;
1879 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301880 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301881 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301882 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301883 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301884 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301885
1886 return 0;
1887}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301888qdf_export_symbol(wmi_unified_unregister_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301889
1890/**
Govind Singhd52faac2016-03-09 12:03:29 +05301891 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301892 * @wmi_handle: handle to wmi
1893 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301894 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301895 *
Govind Singhd52faac2016-03-09 12:03:29 +05301896 * Event process by below function will be in default caller context.
1897 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301898 *
1899 * Return: none
1900 */
Govind Singhd52faac2016-03-09 12:03:29 +05301901static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1902 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301903{
1904 wmi_buf_t evt_buf;
1905 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1906
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301907#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301908 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1909 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1910#else
Govind Singh5eb51532016-03-09 11:34:12 +05301911 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Amar Singhal66d1ed52018-06-26 16:45:54 -07001912 htc_packet, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301913#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301914
Govind Singh6b411b52016-03-06 19:55:02 +05301915 return;
1916}
1917
1918/**
1919 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1920 * @wmi_handle: handle to wmi
1921 * @htc_packet: pointer to htc packet
1922 *
1923 * Event process by below function will be in worker thread context.
1924 * Use this method for events which are not critical and not
1925 * handled in protocol stack.
1926 *
1927 * Return: none
1928 */
Amar Singhal66d1ed52018-06-26 16:45:54 -07001929void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
1930 HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301931{
1932 wmi_buf_t evt_buf;
Govind Singh6b411b52016-03-06 19:55:02 +05301933
1934 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singh6b411b52016-03-06 19:55:02 +05301935
Govind Singhb53420c2016-03-09 14:32:57 +05301936 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1937 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1938 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001939 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
1940 &wmi_handle->rx_event_work);
1941
Govind Singh6b411b52016-03-06 19:55:02 +05301942 return;
1943}
1944
Amar Singhal66d1ed52018-06-26 16:45:54 -07001945qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
1946
Govind Singh6b411b52016-03-06 19:55:02 +05301947/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301948 * wmi_get_pdev_ep: Get wmi handle based on endpoint
1949 * @soc: handle to wmi soc
1950 * @ep: endpoint id
1951 *
1952 * Return: none
1953 */
1954static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
1955 HTC_ENDPOINT_ID ep)
1956{
1957 uint32_t i;
1958
1959 for (i = 0; i < WMI_MAX_RADIOS; i++)
1960 if (soc->wmi_endpoint_id[i] == ep)
1961 break;
1962
1963 if (i == WMI_MAX_RADIOS)
1964 return NULL;
1965
1966 return soc->wmi_pdev[i];
1967}
1968
1969/**
gaurank kathpalia496e66e2018-08-03 12:00:12 +05301970 * wmi_mtrace_rx() - Wrappper function for qdf_mtrace api
1971 * @message_id: 32-Bit Wmi message ID
1972 * @vdev_id: Vdev ID
1973 * @data: Actual message contents
1974 *
1975 * This function converts the 32-bit WMI message ID in 15-bit message ID
1976 * format for qdf_mtrace as in qdf_mtrace message there are only 15
1977 * bits reserved for message ID.
1978 * out of these 15-bits, 8-bits (From LSB) specifies the WMI_GRP_ID
1979 * and remaining 7-bits specifies the actual WMI command. With this
1980 * notation there can be maximum 256 groups and each group can have
1981 * max 128 commands can be supported.
1982 *
1983 * Return: None
1984 */
1985static void wmi_mtrace_rx(uint32_t message_id, uint16_t vdev_id, uint32_t data)
1986{
1987 uint16_t mtrace_message_id;
1988
1989 mtrace_message_id = QDF_WMI_MTRACE_CMD_ID(message_id) |
1990 (QDF_WMI_MTRACE_GRP_ID(message_id) <<
1991 QDF_WMI_MTRACE_CMD_NUM_BITS);
1992 qdf_mtrace(QDF_MODULE_ID_WMI, QDF_MODULE_ID_WMA,
1993 mtrace_message_id, vdev_id, data);
1994}
1995
1996/**
Govind Singhd52faac2016-03-09 12:03:29 +05301997 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301998 * @ctx: handle to wmi
1999 * @htc_packet: pointer to htc packet
2000 *
Govind Singh6b411b52016-03-06 19:55:02 +05302001 * Return: none
2002 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002003static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05302004{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302005 struct wmi_soc *soc = (struct wmi_soc *) ctx;
2006 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302007 wmi_buf_t evt_buf;
2008 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302009 uint32_t idx = 0;
2010 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302011
2012 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302013
2014 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
2015 if (wmi_handle == NULL) {
2016 qdf_print
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302017 ("unable to get wmi_handle to Endpoint %d\n",
2018 htc_packet->Endpoint);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302019 qdf_nbuf_free(evt_buf);
2020 return;
2021 }
2022
Govind Singhb53420c2016-03-09 14:32:57 +05302023 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302024 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302025 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05302026 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
2027 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302028 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302029 return;
2030 }
gaurank kathpalia496e66e2018-08-03 12:00:12 +05302031 wmi_mtrace_rx(id, 0xFF, idx);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302032 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302033 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302034 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302035
Houston Hoffmanc85276b2017-10-11 14:50:30 -07002036#ifdef WMI_INTERFACE_EVENT_LOGGING
2037 if (wmi_handle->log_info.wmi_logging_enable) {
2038 uint8_t *data;
2039 data = qdf_nbuf_data(evt_buf);
2040
2041 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2042 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05302043 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
2044 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07002045 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2046 }
2047#endif
2048
Govind Singhd52faac2016-03-09 12:03:29 +05302049 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302050 wmi_process_fw_event_worker_thread_ctx
2051 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302052 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2053 wmi_process_fw_event_default_ctx
2054 (wmi_handle, htc_packet, exec_ctx);
2055 } else {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302056 qdf_print("Invalid event context %d", exec_ctx);
Govind Singhb53420c2016-03-09 14:32:57 +05302057 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302058 }
Govind Singhd52faac2016-03-09 12:03:29 +05302059
Govind Singh6b411b52016-03-06 19:55:02 +05302060}
2061
2062/**
2063 * wmi_process_fw_event() - process any fw event
2064 * @wmi_handle: wmi handle
2065 * @evt_buf: fw event buffer
2066 *
Govind Singhd52faac2016-03-09 12:03:29 +05302067 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302068 *
2069 * Return: none
2070 */
2071void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2072{
2073 __wmi_control_rx(wmi_handle, evt_buf);
2074}
2075
2076/**
2077 * __wmi_control_rx() - process serialize wmi event callback
2078 * @wmi_handle: wmi handle
2079 * @evt_buf: fw event buffer
2080 *
2081 * Return: none
2082 */
2083void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2084{
2085 uint32_t id;
2086 uint8_t *data;
2087 uint32_t len;
2088 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302089#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302090 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302091#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302092 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302093
Govind Singhb53420c2016-03-09 14:32:57 +05302094 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302095
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05302096 wmi_ext_dbg_msg_event_record(wmi_handle, qdf_nbuf_data(evt_buf),
2097 qdf_nbuf_len(evt_buf));
2098
Govind Singhb53420c2016-03-09 14:32:57 +05302099 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302100 goto end;
2101
Govind Singhb53420c2016-03-09 14:32:57 +05302102 data = qdf_nbuf_data(evt_buf);
2103 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302104
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302105#ifndef WMI_NON_TLV_SUPPORT
2106 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2107 /* Validate and pad(if necessary) the TLVs */
2108 tlv_ok_status =
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302109 wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302110 data, len, id,
2111 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302112 if (tlv_ok_status != 0) {
2113 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302114 "%s: Error: id=0x%x, wmitlv check status=%d",
2115 __func__, id, tlv_ok_status);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302116 goto end;
2117 }
Govind Singh6b411b52016-03-06 19:55:02 +05302118 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302119#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302120
Govind Singhd52faac2016-03-09 12:03:29 +05302121 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2122 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302123 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302124 "%s : event handler is not registered: event id 0x%x",
Govind Singhd52faac2016-03-09 12:03:29 +05302125 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302126 goto end;
2127 }
Govind Singhd52faac2016-03-09 12:03:29 +05302128#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302129 if (wmi_handle->log_info.wmi_logging_enable) {
2130 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2131 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302132 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05302133 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
2134 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05302135 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05302136 WMI_EVENT_RECORD(wmi_handle, id, data +
2137 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05302138 }
2139 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302140 }
Govind Singhd52faac2016-03-09 12:03:29 +05302141#endif
2142 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302143 if (wmi_handle->target_type == WMI_TLV_TARGET)
2144 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2145 wmi_cmd_struct_ptr, len);
2146 else
2147 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2148 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302149
Govind Singh6b411b52016-03-06 19:55:02 +05302150end:
Govind Singhd52faac2016-03-09 12:03:29 +05302151 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302152#ifndef WMI_NON_TLV_SUPPORT
2153 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302154 wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302155#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302156
Govind Singhb53420c2016-03-09 14:32:57 +05302157 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302158
Govind Singh6b411b52016-03-06 19:55:02 +05302159}
2160
Arunk Khandavallib6ba21f2017-12-06 15:47:10 +05302161#define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
Govind Singh97b8e7c2017-09-07 18:23:39 +05302162
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05302163static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05302164{
2165 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Kabilan Kannanf1311ec2018-03-08 14:34:28 -08002166 "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
Govind Singh97b8e7c2017-09-07 18:23:39 +05302167 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
2168}
2169
2170#ifdef CONFIG_SLUB_DEBUG_ON
2171static void wmi_workqueue_watchdog_bite(void *arg)
2172{
Govind Singhc646e102017-11-21 10:53:40 +05302173 struct wmi_wq_dbg_info *info = arg;
2174
2175 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
2176 qdf_print_thread_trace(info->task);
2177
Govind Singh97b8e7c2017-09-07 18:23:39 +05302178 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2179 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
2180 QDF_BUG(0);
2181}
2182#else
2183static inline void wmi_workqueue_watchdog_bite(void *arg)
2184{
Govind Singhc646e102017-11-21 10:53:40 +05302185 struct wmi_wq_dbg_info *info = arg;
2186
2187 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05302188}
2189#endif
2190
Govind Singh6b411b52016-03-06 19:55:02 +05302191/**
2192 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002193 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05302194 *
2195 * This function process any fw event to serialize it through rx worker thread.
2196 *
2197 * Return: none
2198 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002199static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05302200{
Govind Singh6b411b52016-03-06 19:55:02 +05302201 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002202 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05302203 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05302204 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05302205
Govind Singh97b8e7c2017-09-07 18:23:39 +05302206 /* initialize WMI workqueue watchdog timer */
2207 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05302208 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05302209 qdf_spin_lock_bh(&wmi->eventq_lock);
2210 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2211 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302212 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05302213 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05302214 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05302215 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05302216 info.wmi_wq = wmi->wmi_rx_work_queue;
2217 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05302218 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05302219 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05302220 qdf_spin_lock_bh(&wmi->eventq_lock);
2221 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2222 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302223 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05302224 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05302225}
2226
Govind Singh6b411b52016-03-06 19:55:02 +05302227#ifdef FEATURE_RUNTIME_PM
2228/**
2229 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2230 * @wmi_handle: wmi context
2231 */
Govind Singhd52faac2016-03-09 12:03:29 +05302232static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302233{
Govind Singhb53420c2016-03-09 14:32:57 +05302234 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302235}
Govind Singhd52faac2016-03-09 12:03:29 +05302236
2237/**
2238 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2239 * @wmi_handle: wmi context
2240 * @val: runtime pm progress flag
2241 */
2242void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2243{
Govind Singhb53420c2016-03-09 14:32:57 +05302244 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302245}
2246
2247/**
2248 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2249 * @wmi_handle: wmi context
2250 */
2251inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2252{
Govind Singhb53420c2016-03-09 14:32:57 +05302253 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302254}
Govind Singh6b411b52016-03-06 19:55:02 +05302255#else
Govind Singhd52faac2016-03-09 12:03:29 +05302256static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302257{
2258}
2259#endif
2260
2261/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302262 * wmi_unified_get_soc_handle: Get WMI SoC handle
2263 * @param wmi_handle: WMI context got from wmi_attach
2264 *
2265 * return: Pointer to Soc handle
2266 */
2267void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2268{
2269 return wmi_handle->soc;
2270}
2271
2272/**
2273 * wmi_interface_logging_init: Interface looging init
2274 * @param wmi_handle: Pointer to wmi handle object
2275 *
2276 * return: None
2277 */
2278#ifdef WMI_INTERFACE_EVENT_LOGGING
c_priysb5f94a82018-06-12 16:53:51 +05302279static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
2280 uint32_t pdev_idx)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302281{
2282 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2283 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
c_priysb5f94a82018-06-12 16:53:51 +05302284 wmi_debugfs_init(wmi_handle, pdev_idx);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302285 }
2286}
2287#else
c_priysb5f94a82018-06-12 16:53:51 +05302288static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
2289 uint32_t pdev_idx)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302290{
2291}
2292#endif
2293
2294/**
2295 * wmi_target_params_init: Target specific params init
2296 * @param wmi_soc: Pointer to wmi soc object
2297 * @param wmi_handle: Pointer to wmi handle object
2298 *
2299 * return: None
2300 */
2301#ifndef CONFIG_MCL
2302static inline void wmi_target_params_init(struct wmi_soc *soc,
2303 struct wmi_unified *wmi_handle)
2304{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302305 wmi_handle->pdev_param = soc->pdev_param;
2306 wmi_handle->vdev_param = soc->vdev_param;
Kris Muthusamy76e22412018-01-26 16:18:37 -08002307 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302308}
2309#else
2310static inline void wmi_target_params_init(struct wmi_soc *soc,
2311 struct wmi_unified *wmi_handle)
2312{
Kris Muthusamy76e22412018-01-26 16:18:37 -08002313 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302314}
2315#endif
2316
2317/**
2318 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2319 * @param wmi_soc: Pointer to wmi soc object
2320 * @param pdev_idx: pdev index
2321 *
2322 * return: Pointer to wmi handle or NULL on failure
2323 */
2324void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2325{
2326 struct wmi_unified *wmi_handle;
2327
2328 if (pdev_idx >= WMI_MAX_RADIOS)
2329 return NULL;
2330
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302331 if (soc->wmi_pdev[pdev_idx] == NULL) {
2332 wmi_handle =
2333 (struct wmi_unified *) qdf_mem_malloc(
2334 sizeof(struct wmi_unified));
2335 if (wmi_handle == NULL) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302336 qdf_print("allocation of wmi handle failed %zu",
2337 sizeof(struct wmi_unified));
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302338 return NULL;
2339 }
2340 wmi_handle->scn_handle = soc->scn_handle;
2341 wmi_handle->event_id = soc->event_id;
2342 wmi_handle->event_handler = soc->event_handler;
2343 wmi_handle->ctx = soc->ctx;
2344 wmi_handle->ops = soc->ops;
2345 qdf_spinlock_create(&wmi_handle->eventq_lock);
2346 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302347
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302348 qdf_create_work(0, &wmi_handle->rx_event_work,
2349 wmi_rx_event_work, wmi_handle);
2350 wmi_handle->wmi_rx_work_queue =
2351 qdf_create_workqueue("wmi_rx_event_work_queue");
2352 if (NULL == wmi_handle->wmi_rx_work_queue) {
2353 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2354 goto error;
2355 }
2356 wmi_handle->wmi_events = soc->wmi_events;
2357 wmi_target_params_init(soc, wmi_handle);
c_priysb5f94a82018-06-12 16:53:51 +05302358 wmi_handle->soc = soc;
2359 wmi_interface_logging_init(wmi_handle, pdev_idx);
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302360 qdf_atomic_init(&wmi_handle->pending_cmds);
2361 qdf_atomic_init(&wmi_handle->is_target_suspended);
2362 wmi_handle->target_type = soc->target_type;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302363 wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002364
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302365 soc->wmi_pdev[pdev_idx] = wmi_handle;
2366 } else
2367 wmi_handle = soc->wmi_pdev[pdev_idx];
2368
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302369 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302370 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2371 wmi_handle->htc_handle = soc->htc_handle;
2372 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302373
2374 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002375
2376error:
2377 qdf_mem_free(wmi_handle);
2378
2379 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302380}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302381qdf_export_symbol(wmi_unified_get_pdev_handle);
2382
2383static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
2384
2385void wmi_unified_register_module(enum wmi_target_type target_type,
2386 void (*wmi_attach)(wmi_unified_t wmi_handle))
2387{
2388 if (target_type < WMI_MAX_TARGET_TYPE)
2389 wmi_attach_register[target_type] = wmi_attach;
2390
2391 return;
2392}
2393qdf_export_symbol(wmi_unified_register_module);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302394
2395/**
Govind Singh6b411b52016-03-06 19:55:02 +05302396 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302397 * @scn_handle: handle to SCN
2398 * @osdev: OS device context
2399 * @target_type: TLV or not-TLV based target
2400 * @use_cookie: cookie based allocation enabled/disabled
2401 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302402 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302403 *
2404 * @Return: wmi handle.
2405 */
Govind Singhc458f382016-02-04 18:42:30 +05302406void *wmi_unified_attach(void *scn_handle,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302407 struct wmi_unified_attach_params *param)
Govind Singh6b411b52016-03-06 19:55:02 +05302408{
2409 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302410 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302411
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302412 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2413 if (soc == NULL) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302414 qdf_print("Allocation of wmi_soc failed %zu",
2415 sizeof(struct wmi_soc));
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302416 return NULL;
2417 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302418
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302419 wmi_handle =
2420 (struct wmi_unified *) qdf_mem_malloc(
2421 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302422 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302423 qdf_mem_free(soc);
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302424 qdf_print("allocation of wmi handle failed %zu",
2425 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302426 return NULL;
2427 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302428 wmi_handle->soc = soc;
c_priysb5f94a82018-06-12 16:53:51 +05302429 wmi_handle->soc->soc_idx = param->soc_id;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302430 wmi_handle->event_id = soc->event_id;
2431 wmi_handle->event_handler = soc->event_handler;
2432 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302433 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302434 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302435 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302436 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302437 qdf_atomic_init(&wmi_handle->pending_cmds);
2438 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302439 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302440 qdf_spinlock_create(&wmi_handle->eventq_lock);
2441 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002442 qdf_create_work(0, &wmi_handle->rx_event_work,
2443 wmi_rx_event_work, wmi_handle);
2444 wmi_handle->wmi_rx_work_queue =
2445 qdf_create_workqueue("wmi_rx_event_work_queue");
2446 if (NULL == wmi_handle->wmi_rx_work_queue) {
2447 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2448 goto error;
2449 }
c_priysb5f94a82018-06-12 16:53:51 +05302450 wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
Govind Singhc458f382016-02-04 18:42:30 +05302451 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302452 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302453 param->rx_ops->wma_process_fw_event_handler_cbk;
2454 wmi_handle->target_type = param->target_type;
2455 soc->target_type = param->target_type;
Abhiram Jogadenu429ab532018-05-14 17:13:28 +05302456
2457 if (param->target_type >= WMI_MAX_TARGET_TYPE)
2458 goto error;
2459
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302460 if (wmi_attach_register[param->target_type]) {
2461 wmi_attach_register[param->target_type](wmi_handle);
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302462 } else {
2463 WMI_LOGE("wmi attach is not registered");
2464 goto error;
2465 }
Govind Singhc458f382016-02-04 18:42:30 +05302466 /* Assign target cookie capablity */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302467 wmi_handle->use_cookie = param->use_cookie;
2468 wmi_handle->osdev = param->osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302469 wmi_handle->wmi_stopinprogress = 0;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302470 wmi_handle->wmi_max_cmds = param->max_commands;
2471 soc->wmi_max_cmds = param->max_commands;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302472 /* Increase the ref count once refcount infra is present */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302473 soc->wmi_psoc = param->psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302474 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302475
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302476 soc->ops = wmi_handle->ops;
2477 soc->wmi_pdev[0] = wmi_handle;
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05302478 if (wmi_ext_dbgfs_init(wmi_handle) != QDF_STATUS_SUCCESS)
2479 qdf_print("failed to initialize wmi extended debugfs");
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302480
Govind Singh6b411b52016-03-06 19:55:02 +05302481 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002482
2483error:
2484 qdf_mem_free(soc);
2485 qdf_mem_free(wmi_handle);
2486
2487 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302488}
2489
2490/**
2491 * wmi_unified_detach() - detach for unified WMI
2492 *
2493 * @wmi_handle : handle to wmi.
2494 *
2495 * @Return: none.
2496 */
2497void wmi_unified_detach(struct wmi_unified *wmi_handle)
2498{
2499 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302500 struct wmi_soc *soc;
2501 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302502
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05302503 wmi_ext_dbgfs_deinit(wmi_handle);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302504 soc = wmi_handle->soc;
2505 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2506 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002507 qdf_flush_workqueue(0,
2508 soc->wmi_pdev[i]->wmi_rx_work_queue);
2509 qdf_destroy_workqueue(0,
2510 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302511 wmi_debugfs_remove(soc->wmi_pdev[i]);
2512 buf = qdf_nbuf_queue_remove(
2513 &soc->wmi_pdev[i]->event_queue);
2514 while (buf) {
2515 qdf_nbuf_free(buf);
2516 buf = qdf_nbuf_queue_remove(
2517 &soc->wmi_pdev[i]->event_queue);
2518 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002519
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302520 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002521
2522 /* Free events logs list */
2523 if (soc->wmi_pdev[i]->events_logs_list)
2524 qdf_mem_free(
2525 soc->wmi_pdev[i]->events_logs_list);
2526
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302527 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302528 qdf_mem_free(soc->wmi_pdev[i]);
2529 }
Govind Singh6b411b52016-03-06 19:55:02 +05302530 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302531 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302532
2533 if (soc->wmi_service_bitmap) {
2534 qdf_mem_free(soc->wmi_service_bitmap);
2535 soc->wmi_service_bitmap = NULL;
2536 }
2537
2538 if (soc->wmi_ext_service_bitmap) {
2539 qdf_mem_free(soc->wmi_ext_service_bitmap);
2540 soc->wmi_ext_service_bitmap = NULL;
2541 }
2542
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302543 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302544 soc->wmi_psoc = NULL;
2545 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302546}
2547
2548/**
2549 * wmi_unified_remove_work() - detach for WMI work
2550 * @wmi_handle: handle to WMI
2551 *
2552 * A function that does not fully detach WMI, but just remove work
2553 * queue items associated with it. This is used to make sure that
2554 * before any other processing code that may destroy related contexts
2555 * (HTC, etc), work queue processing on WMI has already been stopped.
2556 *
2557 * Return: None
2558 */
2559void
2560wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2561{
2562 wmi_buf_t buf;
2563
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002564 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302565 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2566 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302567 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302568 qdf_nbuf_free(buf);
2569 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302570 }
Govind Singhb53420c2016-03-09 14:32:57 +05302571 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302572}
2573
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302574/**
2575 * wmi_htc_tx_complete() - Process htc tx completion
2576 *
2577 * @ctx: handle to wmi
2578 * @htc_packet: pointer to htc packet
2579 *
2580 * @Return: none.
2581 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002582static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302583{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302584 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302585 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302586 u_int8_t *buf_ptr;
2587 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302588 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302589#ifdef WMI_INTERFACE_EVENT_LOGGING
2590 uint32_t cmd_id;
2591#endif
2592
2593 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302594 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2595 if (wmi_handle == NULL) {
2596 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2597 QDF_ASSERT(0);
2598 return;
2599 }
Govind Singh6b411b52016-03-06 19:55:02 +05302600#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302601 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302602 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2603 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302604
Govind Singhecf03cd2016-05-12 12:45:51 +05302605 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302606 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302607 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302608 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302609 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302610 qdf_nbuf_data(wmi_cmd_buf) +
2611 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302612 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302613 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302614 qdf_nbuf_data(wmi_cmd_buf) +
2615 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302616 }
2617
Govind Singhecf03cd2016-05-12 12:45:51 +05302618 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2619 }
Govind Singh6b411b52016-03-06 19:55:02 +05302620#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302621 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2622 len = qdf_nbuf_len(wmi_cmd_buf);
2623 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302624 qdf_nbuf_free(wmi_cmd_buf);
2625 qdf_mem_free(htc_pkt);
2626 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302627}
2628
2629/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302630 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302631 *
2632 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302633 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302634 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302635 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302636 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302637static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2638 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302639{
Govind Singh6b411b52016-03-06 19:55:02 +05302640 int status;
Manikandan Mohanf940db82017-04-13 20:19:26 -07002641 struct htc_service_connect_resp response;
2642 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302643
2644 OS_MEMZERO(&connect, sizeof(connect));
2645 OS_MEMZERO(&response, sizeof(response));
2646
2647 /* meta data is unused for now */
2648 connect.pMetaData = NULL;
2649 connect.MetaDataLength = 0;
2650 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302651 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302652 connect.EpCallbacks.EpTxCompleteMultiple =
2653 NULL /* Control path completion ar6000_tx_complete */;
2654 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2655 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2656 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2657 connect.EpCallbacks.EpTxComplete =
2658 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2659
2660 /* connect to control service */
Pratik Gandhicf3b8b92018-02-05 17:22:41 +05302661 connect.service_id = soc->svc_ids[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302662 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302663 &response);
2664
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302665
Govind Singh6b411b52016-03-06 19:55:02 +05302666 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302667 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302668 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302669 status);
2670 return status;
2671 }
Govind Singh6b411b52016-03-06 19:55:02 +05302672
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302673 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2674 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2675
2676 return 0;
2677}
2678
2679/**
2680 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2681 *
2682 * @wmi_handle: handle to WMI.
2683 *
2684 * @Return: status.
2685 */
2686QDF_STATUS
2687wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2688 void *htc_handle)
2689{
2690 uint32_t i;
2691 uint8_t wmi_ep_count;
2692
2693 wmi_handle->soc->htc_handle = htc_handle;
2694
2695 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2696 if (wmi_ep_count > WMI_MAX_RADIOS)
2697 return QDF_STATUS_E_FAULT;
2698
2699 for (i = 0; i < wmi_ep_count; i++)
2700 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2701
2702 wmi_handle->htc_handle = htc_handle;
2703 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2704 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2705
2706 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302707}
2708
2709/**
2710 * wmi_get_host_credits() - WMI API to get updated host_credits
2711 *
2712 * @wmi_handle: handle to WMI.
2713 *
2714 * @Return: updated host_credits.
2715 */
2716int wmi_get_host_credits(wmi_unified_t wmi_handle)
2717{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302718 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302719
2720 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2721 &host_credits);
2722 return host_credits;
2723}
2724
2725/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302726 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2727 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302728 *
2729 * @wmi_handle: handle to WMI.
2730 *
2731 * @Return: Pending Commands in the HTC queue.
2732 */
2733int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2734{
Govind Singhb53420c2016-03-09 14:32:57 +05302735 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302736}
2737
2738/**
2739 * wmi_set_target_suspend() - WMI API to set target suspend state
2740 *
2741 * @wmi_handle: handle to WMI.
2742 * @val: suspend state boolean.
2743 *
2744 * @Return: none.
2745 */
2746void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2747{
Govind Singhb53420c2016-03-09 14:32:57 +05302748 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302749}
2750
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302751/**
2752 * WMI API to set crash injection state
2753 * @param wmi_handle: handle to WMI.
2754 * @param val: crash injection state boolean.
2755 */
2756void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2757{
2758 wmi_handle->tag_crash_inject = flag;
2759}
2760
2761/**
2762 * WMI API to set bus suspend state
2763 * @param wmi_handle: handle to WMI.
2764 * @param val: suspend state boolean.
2765 */
2766void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2767{
2768 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2769}
2770
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302771void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2772{
2773 wmi_handle->tgt_force_assert_enable = val;
2774}
2775
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002776/**
2777 * wmi_stop() - generic function to block unified WMI command
2778 * @wmi_handle: handle to WMI.
2779 *
2780 * @Return: success always.
2781 */
2782int
2783wmi_stop(wmi_unified_t wmi_handle)
2784{
2785 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302786 "WMI Stop");
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002787 wmi_handle->wmi_stopinprogress = 1;
2788 return 0;
2789}
2790
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302791#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302792/**
2793 * API to flush all the previous packets associated with the wmi endpoint
2794 *
2795 * @param wmi_handle : handle to WMI.
2796 */
2797void
2798wmi_flush_endpoint(wmi_unified_t wmi_handle)
2799{
2800 htc_flush_endpoint(wmi_handle->htc_handle,
2801 wmi_handle->wmi_endpoint_id, 0);
2802}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302803qdf_export_symbol(wmi_flush_endpoint);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302804
2805/**
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302806 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2807 * By default pdev_id conversion is not done in WMI.
2808 * This API can be used enable conversion in WMI.
2809 * @param wmi_handle : handle to WMI
2810 * Return none
2811 */
2812void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2813{
2814 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302815 wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302816}
2817
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302818#endif