blob: b273625d51507e2dfb05391e2b5fd656c2215b2b [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/**
Govind Singhd52faac2016-03-09 12:03:29 +05301970 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301971 * @ctx: handle to wmi
1972 * @htc_packet: pointer to htc packet
1973 *
Govind Singh6b411b52016-03-06 19:55:02 +05301974 * Return: none
1975 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001976static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301977{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301978 struct wmi_soc *soc = (struct wmi_soc *) ctx;
1979 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05301980 wmi_buf_t evt_buf;
1981 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301982 uint32_t idx = 0;
1983 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301984
1985 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301986
1987 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
1988 if (wmi_handle == NULL) {
1989 qdf_print
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301990 ("unable to get wmi_handle to Endpoint %d\n",
1991 htc_packet->Endpoint);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301992 qdf_nbuf_free(evt_buf);
1993 return;
1994 }
1995
Govind Singhb53420c2016-03-09 14:32:57 +05301996 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301997 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301998 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05301999 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
2000 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302001 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302002 return;
2003 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302004 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302005 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302006 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302007
Houston Hoffmanc85276b2017-10-11 14:50:30 -07002008#ifdef WMI_INTERFACE_EVENT_LOGGING
2009 if (wmi_handle->log_info.wmi_logging_enable) {
2010 uint8_t *data;
2011 data = qdf_nbuf_data(evt_buf);
2012
2013 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2014 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05302015 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
2016 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07002017 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2018 }
2019#endif
2020
Govind Singhd52faac2016-03-09 12:03:29 +05302021 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302022 wmi_process_fw_event_worker_thread_ctx
2023 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302024 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2025 wmi_process_fw_event_default_ctx
2026 (wmi_handle, htc_packet, exec_ctx);
2027 } else {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302028 qdf_print("Invalid event context %d", exec_ctx);
Govind Singhb53420c2016-03-09 14:32:57 +05302029 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302030 }
Govind Singhd52faac2016-03-09 12:03:29 +05302031
Govind Singh6b411b52016-03-06 19:55:02 +05302032}
2033
2034/**
2035 * wmi_process_fw_event() - process any fw event
2036 * @wmi_handle: wmi handle
2037 * @evt_buf: fw event buffer
2038 *
Govind Singhd52faac2016-03-09 12:03:29 +05302039 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302040 *
2041 * Return: none
2042 */
2043void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2044{
2045 __wmi_control_rx(wmi_handle, evt_buf);
2046}
2047
2048/**
2049 * __wmi_control_rx() - process serialize wmi event callback
2050 * @wmi_handle: wmi handle
2051 * @evt_buf: fw event buffer
2052 *
2053 * Return: none
2054 */
2055void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2056{
2057 uint32_t id;
2058 uint8_t *data;
2059 uint32_t len;
2060 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302061#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302062 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302063#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302064 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302065
Govind Singhb53420c2016-03-09 14:32:57 +05302066 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302067
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05302068 wmi_ext_dbg_msg_event_record(wmi_handle, qdf_nbuf_data(evt_buf),
2069 qdf_nbuf_len(evt_buf));
2070
Govind Singhb53420c2016-03-09 14:32:57 +05302071 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302072 goto end;
2073
Govind Singhb53420c2016-03-09 14:32:57 +05302074 data = qdf_nbuf_data(evt_buf);
2075 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302076
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302077#ifndef WMI_NON_TLV_SUPPORT
2078 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2079 /* Validate and pad(if necessary) the TLVs */
2080 tlv_ok_status =
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302081 wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302082 data, len, id,
2083 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302084 if (tlv_ok_status != 0) {
2085 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302086 "%s: Error: id=0x%x, wmitlv check status=%d",
2087 __func__, id, tlv_ok_status);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302088 goto end;
2089 }
Govind Singh6b411b52016-03-06 19:55:02 +05302090 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302091#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302092
Govind Singhd52faac2016-03-09 12:03:29 +05302093 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2094 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302095 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302096 "%s : event handler is not registered: event id 0x%x",
Govind Singhd52faac2016-03-09 12:03:29 +05302097 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302098 goto end;
2099 }
Govind Singhd52faac2016-03-09 12:03:29 +05302100#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302101 if (wmi_handle->log_info.wmi_logging_enable) {
2102 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2103 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302104 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05302105 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
2106 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05302107 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05302108 WMI_EVENT_RECORD(wmi_handle, id, data +
2109 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05302110 }
2111 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302112 }
Govind Singhd52faac2016-03-09 12:03:29 +05302113#endif
2114 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302115 if (wmi_handle->target_type == WMI_TLV_TARGET)
2116 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2117 wmi_cmd_struct_ptr, len);
2118 else
2119 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2120 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302121
Govind Singh6b411b52016-03-06 19:55:02 +05302122end:
Govind Singhd52faac2016-03-09 12:03:29 +05302123 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302124#ifndef WMI_NON_TLV_SUPPORT
2125 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302126 wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302127#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302128
Govind Singhb53420c2016-03-09 14:32:57 +05302129 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302130
Govind Singh6b411b52016-03-06 19:55:02 +05302131}
2132
Arunk Khandavallib6ba21f2017-12-06 15:47:10 +05302133#define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
Govind Singh97b8e7c2017-09-07 18:23:39 +05302134
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05302135static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05302136{
2137 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Kabilan Kannanf1311ec2018-03-08 14:34:28 -08002138 "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
Govind Singh97b8e7c2017-09-07 18:23:39 +05302139 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
2140}
2141
2142#ifdef CONFIG_SLUB_DEBUG_ON
2143static void wmi_workqueue_watchdog_bite(void *arg)
2144{
Govind Singhc646e102017-11-21 10:53:40 +05302145 struct wmi_wq_dbg_info *info = arg;
2146
2147 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
2148 qdf_print_thread_trace(info->task);
2149
Govind Singh97b8e7c2017-09-07 18:23:39 +05302150 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
2151 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
2152 QDF_BUG(0);
2153}
2154#else
2155static inline void wmi_workqueue_watchdog_bite(void *arg)
2156{
Govind Singhc646e102017-11-21 10:53:40 +05302157 struct wmi_wq_dbg_info *info = arg;
2158
2159 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05302160}
2161#endif
2162
Govind Singh6b411b52016-03-06 19:55:02 +05302163/**
2164 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002165 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05302166 *
2167 * This function process any fw event to serialize it through rx worker thread.
2168 *
2169 * Return: none
2170 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002171static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05302172{
Govind Singh6b411b52016-03-06 19:55:02 +05302173 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002174 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05302175 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05302176 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05302177
Govind Singh97b8e7c2017-09-07 18:23:39 +05302178 /* initialize WMI workqueue watchdog timer */
2179 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05302180 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05302181 qdf_spin_lock_bh(&wmi->eventq_lock);
2182 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2183 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302184 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05302185 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05302186 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05302187 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05302188 info.wmi_wq = wmi->wmi_rx_work_queue;
2189 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05302190 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05302191 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05302192 qdf_spin_lock_bh(&wmi->eventq_lock);
2193 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2194 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302195 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05302196 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05302197}
2198
Govind Singh6b411b52016-03-06 19:55:02 +05302199#ifdef FEATURE_RUNTIME_PM
2200/**
2201 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2202 * @wmi_handle: wmi context
2203 */
Govind Singhd52faac2016-03-09 12:03:29 +05302204static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302205{
Govind Singhb53420c2016-03-09 14:32:57 +05302206 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302207}
Govind Singhd52faac2016-03-09 12:03:29 +05302208
2209/**
2210 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2211 * @wmi_handle: wmi context
2212 * @val: runtime pm progress flag
2213 */
2214void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2215{
Govind Singhb53420c2016-03-09 14:32:57 +05302216 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302217}
2218
2219/**
2220 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2221 * @wmi_handle: wmi context
2222 */
2223inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2224{
Govind Singhb53420c2016-03-09 14:32:57 +05302225 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302226}
Govind Singh6b411b52016-03-06 19:55:02 +05302227#else
Govind Singhd52faac2016-03-09 12:03:29 +05302228static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302229{
2230}
2231#endif
2232
2233/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302234 * wmi_unified_get_soc_handle: Get WMI SoC handle
2235 * @param wmi_handle: WMI context got from wmi_attach
2236 *
2237 * return: Pointer to Soc handle
2238 */
2239void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2240{
2241 return wmi_handle->soc;
2242}
2243
2244/**
2245 * wmi_interface_logging_init: Interface looging init
2246 * @param wmi_handle: Pointer to wmi handle object
2247 *
2248 * return: None
2249 */
2250#ifdef WMI_INTERFACE_EVENT_LOGGING
c_priysb5f94a82018-06-12 16:53:51 +05302251static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
2252 uint32_t pdev_idx)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302253{
2254 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2255 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
c_priysb5f94a82018-06-12 16:53:51 +05302256 wmi_debugfs_init(wmi_handle, pdev_idx);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302257 }
2258}
2259#else
c_priysb5f94a82018-06-12 16:53:51 +05302260static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
2261 uint32_t pdev_idx)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302262{
2263}
2264#endif
2265
2266/**
2267 * wmi_target_params_init: Target specific params init
2268 * @param wmi_soc: Pointer to wmi soc object
2269 * @param wmi_handle: Pointer to wmi handle object
2270 *
2271 * return: None
2272 */
2273#ifndef CONFIG_MCL
2274static inline void wmi_target_params_init(struct wmi_soc *soc,
2275 struct wmi_unified *wmi_handle)
2276{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302277 wmi_handle->pdev_param = soc->pdev_param;
2278 wmi_handle->vdev_param = soc->vdev_param;
Kris Muthusamy76e22412018-01-26 16:18:37 -08002279 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302280}
2281#else
2282static inline void wmi_target_params_init(struct wmi_soc *soc,
2283 struct wmi_unified *wmi_handle)
2284{
Kris Muthusamy76e22412018-01-26 16:18:37 -08002285 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302286}
2287#endif
2288
2289/**
2290 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2291 * @param wmi_soc: Pointer to wmi soc object
2292 * @param pdev_idx: pdev index
2293 *
2294 * return: Pointer to wmi handle or NULL on failure
2295 */
2296void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2297{
2298 struct wmi_unified *wmi_handle;
2299
2300 if (pdev_idx >= WMI_MAX_RADIOS)
2301 return NULL;
2302
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302303 if (soc->wmi_pdev[pdev_idx] == NULL) {
2304 wmi_handle =
2305 (struct wmi_unified *) qdf_mem_malloc(
2306 sizeof(struct wmi_unified));
2307 if (wmi_handle == NULL) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302308 qdf_print("allocation of wmi handle failed %zu",
2309 sizeof(struct wmi_unified));
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302310 return NULL;
2311 }
2312 wmi_handle->scn_handle = soc->scn_handle;
2313 wmi_handle->event_id = soc->event_id;
2314 wmi_handle->event_handler = soc->event_handler;
2315 wmi_handle->ctx = soc->ctx;
2316 wmi_handle->ops = soc->ops;
2317 qdf_spinlock_create(&wmi_handle->eventq_lock);
2318 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302319
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302320 qdf_create_work(0, &wmi_handle->rx_event_work,
2321 wmi_rx_event_work, wmi_handle);
2322 wmi_handle->wmi_rx_work_queue =
2323 qdf_create_workqueue("wmi_rx_event_work_queue");
2324 if (NULL == wmi_handle->wmi_rx_work_queue) {
2325 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2326 goto error;
2327 }
2328 wmi_handle->wmi_events = soc->wmi_events;
2329 wmi_target_params_init(soc, wmi_handle);
c_priysb5f94a82018-06-12 16:53:51 +05302330 wmi_handle->soc = soc;
2331 wmi_interface_logging_init(wmi_handle, pdev_idx);
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302332 qdf_atomic_init(&wmi_handle->pending_cmds);
2333 qdf_atomic_init(&wmi_handle->is_target_suspended);
2334 wmi_handle->target_type = soc->target_type;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302335 wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002336
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302337 soc->wmi_pdev[pdev_idx] = wmi_handle;
2338 } else
2339 wmi_handle = soc->wmi_pdev[pdev_idx];
2340
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302341 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302342 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2343 wmi_handle->htc_handle = soc->htc_handle;
2344 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302345
2346 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002347
2348error:
2349 qdf_mem_free(wmi_handle);
2350
2351 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302352}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302353qdf_export_symbol(wmi_unified_get_pdev_handle);
2354
2355static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
2356
2357void wmi_unified_register_module(enum wmi_target_type target_type,
2358 void (*wmi_attach)(wmi_unified_t wmi_handle))
2359{
2360 if (target_type < WMI_MAX_TARGET_TYPE)
2361 wmi_attach_register[target_type] = wmi_attach;
2362
2363 return;
2364}
2365qdf_export_symbol(wmi_unified_register_module);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302366
2367/**
Govind Singh6b411b52016-03-06 19:55:02 +05302368 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302369 * @scn_handle: handle to SCN
2370 * @osdev: OS device context
2371 * @target_type: TLV or not-TLV based target
2372 * @use_cookie: cookie based allocation enabled/disabled
2373 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302374 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302375 *
2376 * @Return: wmi handle.
2377 */
Govind Singhc458f382016-02-04 18:42:30 +05302378void *wmi_unified_attach(void *scn_handle,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302379 struct wmi_unified_attach_params *param)
Govind Singh6b411b52016-03-06 19:55:02 +05302380{
2381 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302382 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302383
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302384 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2385 if (soc == NULL) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302386 qdf_print("Allocation of wmi_soc failed %zu",
2387 sizeof(struct wmi_soc));
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302388 return NULL;
2389 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302390
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302391 wmi_handle =
2392 (struct wmi_unified *) qdf_mem_malloc(
2393 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302394 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302395 qdf_mem_free(soc);
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302396 qdf_print("allocation of wmi handle failed %zu",
2397 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302398 return NULL;
2399 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302400 wmi_handle->soc = soc;
c_priysb5f94a82018-06-12 16:53:51 +05302401 wmi_handle->soc->soc_idx = param->soc_id;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302402 wmi_handle->event_id = soc->event_id;
2403 wmi_handle->event_handler = soc->event_handler;
2404 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302405 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302406 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302407 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302408 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302409 qdf_atomic_init(&wmi_handle->pending_cmds);
2410 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302411 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302412 qdf_spinlock_create(&wmi_handle->eventq_lock);
2413 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002414 qdf_create_work(0, &wmi_handle->rx_event_work,
2415 wmi_rx_event_work, wmi_handle);
2416 wmi_handle->wmi_rx_work_queue =
2417 qdf_create_workqueue("wmi_rx_event_work_queue");
2418 if (NULL == wmi_handle->wmi_rx_work_queue) {
2419 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2420 goto error;
2421 }
c_priysb5f94a82018-06-12 16:53:51 +05302422 wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
Govind Singhc458f382016-02-04 18:42:30 +05302423 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302424 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302425 param->rx_ops->wma_process_fw_event_handler_cbk;
2426 wmi_handle->target_type = param->target_type;
2427 soc->target_type = param->target_type;
Abhiram Jogadenu429ab532018-05-14 17:13:28 +05302428
2429 if (param->target_type >= WMI_MAX_TARGET_TYPE)
2430 goto error;
2431
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302432 if (wmi_attach_register[param->target_type]) {
2433 wmi_attach_register[param->target_type](wmi_handle);
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302434 } else {
2435 WMI_LOGE("wmi attach is not registered");
2436 goto error;
2437 }
Govind Singhc458f382016-02-04 18:42:30 +05302438 /* Assign target cookie capablity */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302439 wmi_handle->use_cookie = param->use_cookie;
2440 wmi_handle->osdev = param->osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302441 wmi_handle->wmi_stopinprogress = 0;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302442 wmi_handle->wmi_max_cmds = param->max_commands;
2443 soc->wmi_max_cmds = param->max_commands;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302444 /* Increase the ref count once refcount infra is present */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302445 soc->wmi_psoc = param->psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302446 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302447
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302448 soc->ops = wmi_handle->ops;
2449 soc->wmi_pdev[0] = wmi_handle;
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05302450 if (wmi_ext_dbgfs_init(wmi_handle) != QDF_STATUS_SUCCESS)
2451 qdf_print("failed to initialize wmi extended debugfs");
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302452
Govind Singh6b411b52016-03-06 19:55:02 +05302453 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002454
2455error:
2456 qdf_mem_free(soc);
2457 qdf_mem_free(wmi_handle);
2458
2459 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302460}
2461
2462/**
2463 * wmi_unified_detach() - detach for unified WMI
2464 *
2465 * @wmi_handle : handle to wmi.
2466 *
2467 * @Return: none.
2468 */
2469void wmi_unified_detach(struct wmi_unified *wmi_handle)
2470{
2471 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302472 struct wmi_soc *soc;
2473 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302474
Venkat Karthik Kantamnenibc8d3292018-05-21 19:13:02 +05302475 wmi_ext_dbgfs_deinit(wmi_handle);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302476 soc = wmi_handle->soc;
2477 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2478 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002479 qdf_flush_workqueue(0,
2480 soc->wmi_pdev[i]->wmi_rx_work_queue);
2481 qdf_destroy_workqueue(0,
2482 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302483 wmi_debugfs_remove(soc->wmi_pdev[i]);
2484 buf = qdf_nbuf_queue_remove(
2485 &soc->wmi_pdev[i]->event_queue);
2486 while (buf) {
2487 qdf_nbuf_free(buf);
2488 buf = qdf_nbuf_queue_remove(
2489 &soc->wmi_pdev[i]->event_queue);
2490 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002491
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302492 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002493
2494 /* Free events logs list */
2495 if (soc->wmi_pdev[i]->events_logs_list)
2496 qdf_mem_free(
2497 soc->wmi_pdev[i]->events_logs_list);
2498
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302499 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302500 qdf_mem_free(soc->wmi_pdev[i]);
2501 }
Govind Singh6b411b52016-03-06 19:55:02 +05302502 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302503 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302504
2505 if (soc->wmi_service_bitmap) {
2506 qdf_mem_free(soc->wmi_service_bitmap);
2507 soc->wmi_service_bitmap = NULL;
2508 }
2509
2510 if (soc->wmi_ext_service_bitmap) {
2511 qdf_mem_free(soc->wmi_ext_service_bitmap);
2512 soc->wmi_ext_service_bitmap = NULL;
2513 }
2514
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302515 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302516 soc->wmi_psoc = NULL;
2517 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302518}
2519
2520/**
2521 * wmi_unified_remove_work() - detach for WMI work
2522 * @wmi_handle: handle to WMI
2523 *
2524 * A function that does not fully detach WMI, but just remove work
2525 * queue items associated with it. This is used to make sure that
2526 * before any other processing code that may destroy related contexts
2527 * (HTC, etc), work queue processing on WMI has already been stopped.
2528 *
2529 * Return: None
2530 */
2531void
2532wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2533{
2534 wmi_buf_t buf;
2535
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002536 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302537 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2538 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302539 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302540 qdf_nbuf_free(buf);
2541 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302542 }
Govind Singhb53420c2016-03-09 14:32:57 +05302543 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302544}
2545
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302546/**
2547 * wmi_htc_tx_complete() - Process htc tx completion
2548 *
2549 * @ctx: handle to wmi
2550 * @htc_packet: pointer to htc packet
2551 *
2552 * @Return: none.
2553 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002554static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302555{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302556 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302557 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302558 u_int8_t *buf_ptr;
2559 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302560 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302561#ifdef WMI_INTERFACE_EVENT_LOGGING
2562 uint32_t cmd_id;
2563#endif
2564
2565 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302566 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2567 if (wmi_handle == NULL) {
2568 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2569 QDF_ASSERT(0);
2570 return;
2571 }
Govind Singh6b411b52016-03-06 19:55:02 +05302572#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302573 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302574 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2575 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302576
Govind Singhecf03cd2016-05-12 12:45:51 +05302577 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302578 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302579 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302580 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302581 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302582 qdf_nbuf_data(wmi_cmd_buf) +
2583 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302584 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302585 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302586 qdf_nbuf_data(wmi_cmd_buf) +
2587 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302588 }
2589
Govind Singhecf03cd2016-05-12 12:45:51 +05302590 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2591 }
Govind Singh6b411b52016-03-06 19:55:02 +05302592#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302593 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2594 len = qdf_nbuf_len(wmi_cmd_buf);
2595 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302596 qdf_nbuf_free(wmi_cmd_buf);
2597 qdf_mem_free(htc_pkt);
2598 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302599}
2600
2601/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302602 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302603 *
2604 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302605 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302606 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302607 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302608 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302609static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2610 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302611{
Govind Singh6b411b52016-03-06 19:55:02 +05302612 int status;
Manikandan Mohanf940db82017-04-13 20:19:26 -07002613 struct htc_service_connect_resp response;
2614 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302615
2616 OS_MEMZERO(&connect, sizeof(connect));
2617 OS_MEMZERO(&response, sizeof(response));
2618
2619 /* meta data is unused for now */
2620 connect.pMetaData = NULL;
2621 connect.MetaDataLength = 0;
2622 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302623 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302624 connect.EpCallbacks.EpTxCompleteMultiple =
2625 NULL /* Control path completion ar6000_tx_complete */;
2626 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2627 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2628 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2629 connect.EpCallbacks.EpTxComplete =
2630 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2631
2632 /* connect to control service */
Pratik Gandhicf3b8b92018-02-05 17:22:41 +05302633 connect.service_id = soc->svc_ids[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302634 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302635 &response);
2636
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302637
Govind Singh6b411b52016-03-06 19:55:02 +05302638 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302639 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302640 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302641 status);
2642 return status;
2643 }
Govind Singh6b411b52016-03-06 19:55:02 +05302644
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302645 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2646 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2647
2648 return 0;
2649}
2650
2651/**
2652 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2653 *
2654 * @wmi_handle: handle to WMI.
2655 *
2656 * @Return: status.
2657 */
2658QDF_STATUS
2659wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2660 void *htc_handle)
2661{
2662 uint32_t i;
2663 uint8_t wmi_ep_count;
2664
2665 wmi_handle->soc->htc_handle = htc_handle;
2666
2667 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2668 if (wmi_ep_count > WMI_MAX_RADIOS)
2669 return QDF_STATUS_E_FAULT;
2670
2671 for (i = 0; i < wmi_ep_count; i++)
2672 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2673
2674 wmi_handle->htc_handle = htc_handle;
2675 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2676 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2677
2678 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302679}
2680
2681/**
2682 * wmi_get_host_credits() - WMI API to get updated host_credits
2683 *
2684 * @wmi_handle: handle to WMI.
2685 *
2686 * @Return: updated host_credits.
2687 */
2688int wmi_get_host_credits(wmi_unified_t wmi_handle)
2689{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302690 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302691
2692 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2693 &host_credits);
2694 return host_credits;
2695}
2696
2697/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302698 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2699 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302700 *
2701 * @wmi_handle: handle to WMI.
2702 *
2703 * @Return: Pending Commands in the HTC queue.
2704 */
2705int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2706{
Govind Singhb53420c2016-03-09 14:32:57 +05302707 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302708}
2709
2710/**
2711 * wmi_set_target_suspend() - WMI API to set target suspend state
2712 *
2713 * @wmi_handle: handle to WMI.
2714 * @val: suspend state boolean.
2715 *
2716 * @Return: none.
2717 */
2718void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2719{
Govind Singhb53420c2016-03-09 14:32:57 +05302720 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302721}
2722
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302723/**
2724 * WMI API to set crash injection state
2725 * @param wmi_handle: handle to WMI.
2726 * @param val: crash injection state boolean.
2727 */
2728void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2729{
2730 wmi_handle->tag_crash_inject = flag;
2731}
2732
2733/**
2734 * WMI API to set bus suspend state
2735 * @param wmi_handle: handle to WMI.
2736 * @param val: suspend state boolean.
2737 */
2738void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2739{
2740 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2741}
2742
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302743void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2744{
2745 wmi_handle->tgt_force_assert_enable = val;
2746}
2747
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002748/**
2749 * wmi_stop() - generic function to block unified WMI command
2750 * @wmi_handle: handle to WMI.
2751 *
2752 * @Return: success always.
2753 */
2754int
2755wmi_stop(wmi_unified_t wmi_handle)
2756{
2757 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302758 "WMI Stop");
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002759 wmi_handle->wmi_stopinprogress = 1;
2760 return 0;
2761}
2762
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302763#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302764/**
2765 * API to flush all the previous packets associated with the wmi endpoint
2766 *
2767 * @param wmi_handle : handle to WMI.
2768 */
2769void
2770wmi_flush_endpoint(wmi_unified_t wmi_handle)
2771{
2772 htc_flush_endpoint(wmi_handle->htc_handle,
2773 wmi_handle->wmi_endpoint_id, 0);
2774}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302775qdf_export_symbol(wmi_flush_endpoint);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302776
2777/**
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302778 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2779 * By default pdev_id conversion is not done in WMI.
2780 * This API can be used enable conversion in WMI.
2781 * @param wmi_handle : handle to WMI
2782 * Return none
2783 */
2784void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2785{
2786 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302787 wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302788}
2789
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302790#endif