blob: 7bc40a42084db68f4508dafd2f512dca4887e9c7 [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"
Govind Singh6b411b52016-03-06 19:55:02 +053027
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053028#ifndef WMI_NON_TLV_SUPPORT
29#include "wmi_tlv_helper.h"
30#endif
31
Govind Singhecf03cd2016-05-12 12:45:51 +053032#include <linux/debugfs.h>
33
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053034/* This check for CONFIG_WIN temporary added due to redeclaration compilation
35error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
36which gets included here through ol_if_athvar.h. Eventually it is expected that
37wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
38WMI_CMD_HDR to be defined here. */
39#ifdef CONFIG_WIN
40/* Copied from wmi.h */
41#undef MS
42#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
43#undef SM
44#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
45#undef WO
46#define WO(_f) ((_f##_OFFSET) >> 2)
47
48#undef GET_FIELD
Vivekc5823092018-03-22 23:27:21 +053049#define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053050#undef SET_FIELD
51#define SET_FIELD(_addr, _f, _val) \
Vivekc5823092018-03-22 23:27:21 +053052 (*((uint32_t *)(_addr) + WO(_f)) = \
53 (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053054
55#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
56 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
57
58#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
59 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
60
61#define WMI_EP_APASS 0x0
62#define WMI_EP_LPASS 0x1
63#define WMI_EP_SENSOR 0x2
64
65/*
66 * * Control Path
67 * */
68typedef PREPACK struct {
Vivekc5823092018-03-22 23:27:21 +053069 uint32_t commandId:24,
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053070 reserved:2, /* used for WMI endpoint ID */
71 plt_priv:6; /* platform private */
72} POSTPACK WMI_CMD_HDR; /* used for commands and events */
73
74#define WMI_CMD_HDR_COMMANDID_LSB 0
75#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
76#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
77#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
78#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
79#define WMI_CMD_HDR_PLT_PRIV_LSB 24
80#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
81#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
82/* end of copy wmi.h */
83#endif /* CONFIG_WIN */
84
Rachit Kankane799d2c92018-02-19 11:28:10 +053085#define WMI_MIN_HEAD_ROOM 64
86
87#ifdef WMI_INTERFACE_EVENT_LOGGING
Manikandan Mohan5826ae92016-06-08 16:29:39 -070088#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
89/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +053090static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -070091{
92 va_list args;
93
94 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +053095 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -070096 va_end(args);
97
Pratik Gandhi795ab912017-05-03 20:15:50 +053098 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -070099}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530100#else
101#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700102#endif
103
Govind Singhecf03cd2016-05-12 12:45:51 +0530104#ifndef MAX_WMI_INSTANCES
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530105#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530106#endif
107
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530108#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530109/* WMI commands */
110uint32_t g_wmi_command_buf_idx = 0;
111struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
112
113/* WMI commands TX completed */
114uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
115struct wmi_command_debug
116 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
117
118/* WMI events when processed */
119uint32_t g_wmi_event_buf_idx = 0;
120struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
121
122/* WMI events when queued */
123uint32_t g_wmi_rx_event_buf_idx = 0;
124struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530125#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530126
Govind Singhecf03cd2016-05-12 12:45:51 +0530127#define WMI_COMMAND_RECORD(h, a, b) { \
128 if (wmi_log_max_entry <= \
129 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
130 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
131 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
132 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
133 .command = a; \
134 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
135 wmi_command_log_buf_info.buf) \
136 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
137 b, wmi_record_max_length); \
138 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
139 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
140 time = qdf_get_log_timestamp(); \
141 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
142 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530143}
144
Govind Singhecf03cd2016-05-12 12:45:51 +0530145#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
146 if (wmi_log_max_entry <= \
147 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530148 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
149 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530150 ((struct wmi_command_debug *)h->log_info. \
151 wmi_command_tx_cmp_log_buf_info.buf) \
152 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
153 p_buf_tail_idx)]. \
154 command = a; \
155 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
156 wmi_command_tx_cmp_log_buf_info.buf) \
157 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
158 p_buf_tail_idx)]. \
159 data, b, wmi_record_max_length); \
160 ((struct wmi_command_debug *)h->log_info. \
161 wmi_command_tx_cmp_log_buf_info.buf) \
162 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
163 p_buf_tail_idx)]. \
164 time = qdf_get_log_timestamp(); \
165 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
166 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530167}
168
Govind Singhecf03cd2016-05-12 12:45:51 +0530169#define WMI_EVENT_RECORD(h, a, b) { \
170 if (wmi_log_max_entry <= \
171 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
172 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
173 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
174 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
175 event = a; \
176 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
177 wmi_event_log_buf_info.buf) \
178 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
179 wmi_record_max_length); \
180 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
181 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530182 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530183 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
184 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530185}
186
Govind Singhecf03cd2016-05-12 12:45:51 +0530187#define WMI_RX_EVENT_RECORD(h, a, b) { \
188 if (wmi_log_max_entry <= \
189 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
190 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
191 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
192 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
193 event = a; \
194 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
195 wmi_rx_event_log_buf_info.buf) \
196 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
197 data, b, wmi_record_max_length); \
198 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
199 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
200 time = qdf_get_log_timestamp(); \
201 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
202 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530203}
Govind Singh6b411b52016-03-06 19:55:02 +0530204
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530205#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530206uint32_t g_wmi_mgmt_command_buf_idx = 0;
207struct
208wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
209
210/* wmi_mgmt commands TX completed */
211uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
212struct wmi_command_debug
213wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
214
215/* wmi_mgmt events when processed */
216uint32_t g_wmi_mgmt_event_buf_idx = 0;
217struct wmi_event_debug
218wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530219#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530220
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530221#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
222 if (wmi_mgmt_log_max_entry <= \
223 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
224 *(h->log_info.wmi_mgmt_command_log_buf_info. \
225 p_buf_tail_idx) = 0; \
226 ((struct wmi_command_debug *)h->log_info. \
227 wmi_mgmt_command_log_buf_info.buf) \
228 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
229 command = a; \
230 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
231 wmi_mgmt_command_log_buf_info.buf) \
232 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
233 data, b, \
234 wmi_record_max_length); \
235 ((struct wmi_command_debug *)h->log_info. \
236 wmi_mgmt_command_log_buf_info.buf) \
237 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
238 time = qdf_get_log_timestamp(); \
239 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
240 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530241}
242
Govind Singhecf03cd2016-05-12 12:45:51 +0530243#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
244 if (wmi_mgmt_log_max_entry <= \
245 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
246 p_buf_tail_idx)) \
247 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
248 p_buf_tail_idx) = 0; \
249 ((struct wmi_command_debug *)h->log_info. \
250 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
251 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
252 p_buf_tail_idx)].command = a; \
253 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
254 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
255 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
256 p_buf_tail_idx)].data, b, \
257 wmi_record_max_length); \
258 ((struct wmi_command_debug *)h->log_info. \
259 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
260 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
261 p_buf_tail_idx)].time = \
262 qdf_get_log_timestamp(); \
263 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
264 p_buf_tail_idx))++; \
265 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530266}
267
Govind Singhecf03cd2016-05-12 12:45:51 +0530268#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
269 if (wmi_mgmt_log_max_entry <= \
270 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
271 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
272 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
273 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
274 .event = a; \
275 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
276 wmi_mgmt_event_log_buf_info.buf) \
277 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
278 data, b, wmi_record_max_length); \
279 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
280 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
281 time = qdf_get_log_timestamp(); \
282 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
283 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530284}
285
Govind Singhecf03cd2016-05-12 12:45:51 +0530286/* These are defined to made it as module param, which can be configured */
287uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
288uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
289uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
290uint32_t wmi_display_size = 100;
291
Govind Singhecf03cd2016-05-12 12:45:51 +0530292/**
293 * wmi_log_init() - Initialize WMI event logging
294 * @wmi_handle: WMI handle.
295 *
296 * Return: Initialization status
297 */
298#ifdef CONFIG_MCL
299static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
300{
301 struct wmi_log_buf_t *cmd_log_buf =
302 &wmi_handle->log_info.wmi_command_log_buf_info;
303 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
304 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
305
306 struct wmi_log_buf_t *event_log_buf =
307 &wmi_handle->log_info.wmi_event_log_buf_info;
308 struct wmi_log_buf_t *rx_event_log_buf =
309 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
310
311 struct wmi_log_buf_t *mgmt_cmd_log_buf =
312 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
313 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
314 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
315 struct wmi_log_buf_t *mgmt_event_log_buf =
316 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
317
318 /* WMI commands */
319 cmd_log_buf->length = 0;
320 cmd_log_buf->buf_tail_idx = 0;
321 cmd_log_buf->buf = wmi_command_log_buffer;
322 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700323 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530324
325 /* WMI commands TX completed */
326 cmd_tx_cmpl_log_buf->length = 0;
327 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
328 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
329 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700330 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530331
332 /* WMI events when processed */
333 event_log_buf->length = 0;
334 event_log_buf->buf_tail_idx = 0;
335 event_log_buf->buf = wmi_event_log_buffer;
336 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700337 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530338
339 /* WMI events when queued */
340 rx_event_log_buf->length = 0;
341 rx_event_log_buf->buf_tail_idx = 0;
342 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
343 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700344 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530345
346 /* WMI Management commands */
347 mgmt_cmd_log_buf->length = 0;
348 mgmt_cmd_log_buf->buf_tail_idx = 0;
349 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
350 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700351 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530352
353 /* WMI Management commands Tx completed*/
354 mgmt_cmd_tx_cmp_log_buf->length = 0;
355 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
356 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
357 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
358 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700359 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530360
361 /* WMI Management events when processed*/
362 mgmt_event_log_buf->length = 0;
363 mgmt_event_log_buf->buf_tail_idx = 0;
364 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
365 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700366 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530367
368 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
369 wmi_handle->log_info.wmi_logging_enable = 1;
370
371 return QDF_STATUS_SUCCESS;
372}
373#else
374static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
375{
376 struct wmi_log_buf_t *cmd_log_buf =
377 &wmi_handle->log_info.wmi_command_log_buf_info;
378 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
379 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
380
381 struct wmi_log_buf_t *event_log_buf =
382 &wmi_handle->log_info.wmi_event_log_buf_info;
383 struct wmi_log_buf_t *rx_event_log_buf =
384 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
385
386 struct wmi_log_buf_t *mgmt_cmd_log_buf =
387 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
388 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
389 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
390 struct wmi_log_buf_t *mgmt_event_log_buf =
391 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
392
393 wmi_handle->log_info.wmi_logging_enable = 0;
394
395 /* WMI commands */
396 cmd_log_buf->length = 0;
397 cmd_log_buf->buf_tail_idx = 0;
398 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
399 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700400 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530401
402 if (!cmd_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530403 qdf_print("no memory for WMI command log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530404 return QDF_STATUS_E_NOMEM;
405 }
406 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
407
408 /* WMI commands TX completed */
409 cmd_tx_cmpl_log_buf->length = 0;
410 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
411 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
412 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700413 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530414
415 if (!cmd_tx_cmpl_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530416 qdf_print("no memory for WMI Command Tx Complete log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530417 return QDF_STATUS_E_NOMEM;
418 }
419 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
420 &cmd_tx_cmpl_log_buf->buf_tail_idx;
421
422 /* WMI events when processed */
423 event_log_buf->length = 0;
424 event_log_buf->buf_tail_idx = 0;
425 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
426 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700427 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530428
429 if (!event_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530430 qdf_print("no memory for WMI Event log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530431 return QDF_STATUS_E_NOMEM;
432 }
433 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
434
435 /* WMI events when queued */
436 rx_event_log_buf->length = 0;
437 rx_event_log_buf->buf_tail_idx = 0;
438 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
439 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700440 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530441
442 if (!rx_event_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530443 qdf_print("no memory for WMI Event Rx log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530444 return QDF_STATUS_E_NOMEM;
445 }
446 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
447
448 /* WMI Management commands */
449 mgmt_cmd_log_buf->length = 0;
450 mgmt_cmd_log_buf->buf_tail_idx = 0;
451 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700452 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
453 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530454
455 if (!mgmt_cmd_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530456 qdf_print("no memory for WMI Management Command log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530457 return QDF_STATUS_E_NOMEM;
458 }
459 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
460
461 /* WMI Management commands Tx completed*/
462 mgmt_cmd_tx_cmp_log_buf->length = 0;
463 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
464 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
465 qdf_mem_malloc(
466 wmi_mgmt_log_max_entry *
467 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700468 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530469
470 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530471 qdf_print("no memory for WMI Management Command Tx complete log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530472 return QDF_STATUS_E_NOMEM;
473 }
474 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
475 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
476
477 /* WMI Management events when processed*/
478 mgmt_event_log_buf->length = 0;
479 mgmt_event_log_buf->buf_tail_idx = 0;
480
481 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
482 wmi_mgmt_log_max_entry *
483 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700484 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530485
486 if (!mgmt_event_log_buf->buf) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530487 qdf_print("no memory for WMI Management Event log buffer..");
Govind Singhecf03cd2016-05-12 12:45:51 +0530488 return QDF_STATUS_E_NOMEM;
489 }
490 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
491
492 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
493 wmi_handle->log_info.wmi_logging_enable = 1;
494
495 return QDF_STATUS_SUCCESS;
496}
497#endif
498
499/**
500 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
501 * event logging
502 * @wmi_handle: WMI handle.
503 *
504 * Return: None
505 */
506#ifndef CONFIG_MCL
507static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
508{
509 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
510 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
511 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
512 qdf_mem_free(
513 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
514 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
515 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
516 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
517 qdf_mem_free(
518 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
519 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
520 qdf_mem_free(
521 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
522 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
523 qdf_mem_free(
524 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
525 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
526 qdf_mem_free(
527 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
528 wmi_handle->log_info.wmi_logging_enable = 0;
529 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
530}
531#else
532static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
533{
534 /* Do Nothing */
535}
536#endif
537
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700538/**
539 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
540 * @log_buffer: the command log buffer metadata of the buffer to print
541 * @count: the maximum number of entries to print
542 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
543 * @print_priv: any data required by the print method, e.g. a file handle
544 *
545 * Return: None
546 */
547static void
548wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
549 qdf_abstract_print *print, void *print_priv)
550{
551 static const int data_len =
552 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
553 char str[128];
554 uint32_t idx;
555
556 if (count > log_buffer->size)
557 count = log_buffer->size;
558 if (count > log_buffer->length)
559 count = log_buffer->length;
560
561 /* subtract count from index, and wrap if necessary */
562 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
563 idx %= log_buffer->size;
564
565 print(print_priv, "Time (seconds) Cmd Id Payload");
566 while (count) {
567 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
568 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700569 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700570 int len = 0;
571 int i;
572
Dustin Brown8ea39122017-04-10 13:26:56 -0700573 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700574 len += scnprintf(str + len, sizeof(str) - len,
575 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700576 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700577 cmd_log->command, cmd_log->command);
578 for (i = 0; i < data_len; ++i) {
579 len += scnprintf(str + len, sizeof(str) - len,
580 "0x%08x ", cmd_log->data[i]);
581 }
582
583 print(print_priv, str);
584
585 --count;
586 ++idx;
587 if (idx >= log_buffer->size)
588 idx = 0;
589 }
590}
591
592/**
593 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
594 * @log_buffer: the event log buffer metadata of the buffer to print
595 * @count: the maximum number of entries to print
596 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
597 * @print_priv: any data required by the print method, e.g. a file handle
598 *
599 * Return: None
600 */
601static void
602wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
603 qdf_abstract_print *print, void *print_priv)
604{
605 static const int data_len =
606 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
607 char str[128];
608 uint32_t idx;
609
610 if (count > log_buffer->size)
611 count = log_buffer->size;
612 if (count > log_buffer->length)
613 count = log_buffer->length;
614
615 /* subtract count from index, and wrap if necessary */
616 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
617 idx %= log_buffer->size;
618
619 print(print_priv, "Time (seconds) Event Id Payload");
620 while (count) {
621 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
622 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700623 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700624 int len = 0;
625 int i;
626
Dustin Brown8ea39122017-04-10 13:26:56 -0700627 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700628 len += scnprintf(str + len, sizeof(str) - len,
629 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700630 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700631 event_log->event, event_log->event);
632 for (i = 0; i < data_len; ++i) {
633 len += scnprintf(str + len, sizeof(str) - len,
634 "0x%08x ", event_log->data[i]);
635 }
636
637 print(print_priv, str);
638
639 --count;
640 ++idx;
641 if (idx >= log_buffer->size)
642 idx = 0;
643 }
644}
645
646inline void
647wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
648 qdf_abstract_print *print, void *print_priv)
649{
650 wmi_print_cmd_log_buffer(
651 &wmi->log_info.wmi_command_log_buf_info,
652 count, print, print_priv);
653}
654
655inline void
656wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
657 qdf_abstract_print *print, void *print_priv)
658{
659 wmi_print_cmd_log_buffer(
660 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
661 count, print, print_priv);
662}
663
664inline void
665wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
666 qdf_abstract_print *print, void *print_priv)
667{
668 wmi_print_cmd_log_buffer(
669 &wmi->log_info.wmi_mgmt_command_log_buf_info,
670 count, print, print_priv);
671}
672
673inline void
674wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
675 qdf_abstract_print *print, void *print_priv)
676{
677 wmi_print_cmd_log_buffer(
678 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
679 count, print, print_priv);
680}
681
682inline void
683wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
684 qdf_abstract_print *print, void *print_priv)
685{
686 wmi_print_event_log_buffer(
687 &wmi->log_info.wmi_event_log_buf_info,
688 count, print, print_priv);
689}
690
691inline void
692wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
693 qdf_abstract_print *print, void *print_priv)
694{
695 wmi_print_event_log_buffer(
696 &wmi->log_info.wmi_rx_event_log_buf_info,
697 count, print, print_priv);
698}
699
700inline void
701wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
702 qdf_abstract_print *print, void *print_priv)
703{
704 wmi_print_event_log_buffer(
705 &wmi->log_info.wmi_mgmt_event_log_buf_info,
706 count, print, print_priv);
707}
708
Govind Singhecf03cd2016-05-12 12:45:51 +0530709
710/* debugfs routines*/
711
712/**
713 * debug_wmi_##func_base##_show() - debugfs functions to display content of
714 * command and event buffers. Macro uses max buffer length to display
715 * buffer when it is wraparound.
716 *
717 * @m: debugfs handler to access wmi_handle
718 * @v: Variable arguments (not used)
719 *
720 * Return: Length of characters printed
721 */
722#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
723 static int debug_wmi_##func_base##_show(struct seq_file *m, \
724 void *v) \
725 { \
726 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
727 struct wmi_log_buf_t *wmi_log = \
728 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
729 int pos, nread, outlen; \
730 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800731 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530732 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530733 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
734 if (!wmi_log->length) { \
735 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530736 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530737 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530738 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530739 \
740 if (wmi_log->length <= wmi_ring_size) \
741 nread = wmi_log->length; \
742 else \
743 nread = wmi_ring_size; \
744 \
745 if (*(wmi_log->p_buf_tail_idx) == 0) \
746 /* tail can be 0 after wrap-around */ \
747 pos = wmi_ring_size - 1; \
748 else \
749 pos = *(wmi_log->p_buf_tail_idx) - 1; \
750 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530751 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530752 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530753 while (nread--) { \
754 struct wmi_command_debug *wmi_record; \
755 \
756 wmi_record = (struct wmi_command_debug *) \
757 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530758 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530759 (wmi_record->command)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800760 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
761 &usecs); \
762 outlen += \
763 wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
764 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530765 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530766 for (i = 0; i < (wmi_record_max_length/ \
767 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530768 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530769 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530770 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530771 \
772 if (pos == 0) \
773 pos = wmi_ring_size - 1; \
774 else \
775 pos--; \
776 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530777 return outlen; \
778 } \
779
780#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
781 static int debug_wmi_##func_base##_show(struct seq_file *m, \
782 void *v) \
783 { \
784 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
785 struct wmi_log_buf_t *wmi_log = \
786 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
787 int pos, nread, outlen; \
788 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800789 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530790 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530791 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
792 if (!wmi_log->length) { \
793 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530794 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530795 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530796 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530797 \
798 if (wmi_log->length <= wmi_ring_size) \
799 nread = wmi_log->length; \
800 else \
801 nread = wmi_ring_size; \
802 \
803 if (*(wmi_log->p_buf_tail_idx) == 0) \
804 /* tail can be 0 after wrap-around */ \
805 pos = wmi_ring_size - 1; \
806 else \
807 pos = *(wmi_log->p_buf_tail_idx) - 1; \
808 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530809 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530810 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530811 while (nread--) { \
812 struct wmi_event_debug *wmi_record; \
813 \
814 wmi_record = (struct wmi_event_debug *) \
815 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
nobelj2a6da6f2017-12-11 23:18:27 -0800816 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
817 &usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530818 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +0530819 (wmi_record->event)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800820 outlen += \
821 wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
822 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530823 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530824 for (i = 0; i < (wmi_record_max_length/ \
825 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530826 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530827 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530828 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530829 \
830 if (pos == 0) \
831 pos = wmi_ring_size - 1; \
832 else \
833 pos--; \
834 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530835 return outlen; \
836 }
837
838GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
839GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
840GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
841GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
842GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
843GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
844 wmi_display_size);
845GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
846
847/**
848 * debug_wmi_enable_show() - debugfs functions to display enable state of
849 * wmi logging feature.
850 *
851 * @m: debugfs handler to access wmi_handle
852 * @v: Variable arguments (not used)
853 *
854 * Return: always 1
855 */
856static int debug_wmi_enable_show(struct seq_file *m, void *v)
857{
858 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
859
Pratik Gandhi795ab912017-05-03 20:15:50 +0530860 return wmi_bp_seq_printf(m, "%d\n",
861 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530862}
863
864/**
865 * debug_wmi_log_size_show() - debugfs functions to display configured size of
866 * wmi logging command/event buffer and management command/event buffer.
867 *
868 * @m: debugfs handler to access wmi_handle
869 * @v: Variable arguments (not used)
870 *
871 * Return: Length of characters printed
872 */
873static int debug_wmi_log_size_show(struct seq_file *m, void *v)
874{
875
Pratik Gandhi795ab912017-05-03 20:15:50 +0530876 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
877 wmi_log_max_entry);
878 return wmi_bp_seq_printf(m,
879 "WMI management command/events log max size:%d\n",
880 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530881}
882
883/**
884 * debug_wmi_##func_base##_write() - debugfs functions to clear
885 * wmi logging command/event buffer and management command/event buffer.
886 *
887 * @file: file handler to access wmi_handle
888 * @buf: received data buffer
889 * @count: length of received buffer
890 * @ppos: Not used
891 *
892 * Return: count
893 */
894#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
895 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
896 const char __user *buf, \
897 size_t count, loff_t *ppos) \
898 { \
899 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530900 wmi_unified_t wmi_handle = \
901 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530902 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
903 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530904 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530905 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530906 if ((!buf) || (count > 50)) \
907 return -EFAULT; \
908 \
909 if (copy_from_user(locbuf, buf, count)) \
910 return -EFAULT; \
911 \
912 ret = sscanf(locbuf, "%d", &k); \
913 if ((ret != 1) || (k != 0)) { \
Aditya Sathish45d7ada2018-07-02 17:31:55 +0530914 qdf_print("Wrong input, echo 0 to clear the wmi buffer");\
Govind Singhecf03cd2016-05-12 12:45:51 +0530915 return -EINVAL; \
916 } \
917 \
918 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
919 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
920 sizeof(struct wmi_record_type)); \
921 wmi_log->length = 0; \
922 *(wmi_log->p_buf_tail_idx) = 0; \
923 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
924 \
925 return count; \
926 }
927
928GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
929 wmi_command_debug);
930GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
931 wmi_command_debug);
932GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
933 wmi_event_debug);
934GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
935 wmi_event_debug);
936GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
937 wmi_command_debug);
938GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
939 wmi_mgmt_log_max_entry, wmi_command_debug);
940GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
941 wmi_event_debug);
942
943/**
944 * debug_wmi_enable_write() - debugfs functions to enable/disable
945 * wmi logging feature.
946 *
947 * @file: file handler to access wmi_handle
948 * @buf: received data buffer
949 * @count: length of received buffer
950 * @ppos: Not used
951 *
952 * Return: count
953 */
954static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
955 size_t count, loff_t *ppos)
956{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530957 wmi_unified_t wmi_handle =
958 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530959 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530960 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530961
Pratik Gandhi795ab912017-05-03 20:15:50 +0530962 if ((!buf) || (count > 50))
963 return -EFAULT;
964
965 if (copy_from_user(locbuf, buf, count))
966 return -EFAULT;
967
968 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530969 if ((ret != 1) || ((k != 0) && (k != 1)))
970 return -EINVAL;
971
972 wmi_handle->log_info.wmi_logging_enable = k;
973 return count;
974}
975
976/**
977 * debug_wmi_log_size_write() - reserved.
978 *
979 * @file: file handler to access wmi_handle
980 * @buf: received data buffer
981 * @count: length of received buffer
982 * @ppos: Not used
983 *
984 * Return: count
985 */
986static ssize_t debug_wmi_log_size_write(struct file *file,
987 const char __user *buf, size_t count, loff_t *ppos)
988{
989 return -EINVAL;
990}
991
992/* Structure to maintain debug information */
993struct wmi_debugfs_info {
994 const char *name;
Govind Singhecf03cd2016-05-12 12:45:51 +0530995 const struct file_operations *ops;
996};
997
998#define DEBUG_FOO(func_base) { .name = #func_base, \
999 .ops = &debug_##func_base##_ops }
1000
1001/**
1002 * debug_##func_base##_open() - Open debugfs entry for respective command
1003 * and event buffer.
1004 *
1005 * @inode: node for debug dir entry
1006 * @file: file handler
1007 *
1008 * Return: open status
1009 */
1010#define GENERATE_DEBUG_STRUCTS(func_base) \
1011 static int debug_##func_base##_open(struct inode *inode, \
1012 struct file *file) \
1013 { \
1014 return single_open(file, debug_##func_base##_show, \
1015 inode->i_private); \
1016 } \
1017 \
1018 \
1019 static struct file_operations debug_##func_base##_ops = { \
1020 .open = debug_##func_base##_open, \
1021 .read = seq_read, \
1022 .llseek = seq_lseek, \
1023 .write = debug_##func_base##_write, \
1024 .release = single_release, \
1025 };
1026
1027GENERATE_DEBUG_STRUCTS(wmi_command_log);
1028GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1029GENERATE_DEBUG_STRUCTS(wmi_event_log);
1030GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1031GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1032GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1033GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1034GENERATE_DEBUG_STRUCTS(wmi_enable);
1035GENERATE_DEBUG_STRUCTS(wmi_log_size);
1036
c_priysb5f94a82018-06-12 16:53:51 +05301037struct wmi_debugfs_info wmi_debugfs_infos[NUM_DEBUG_INFOS] = {
Govind Singhecf03cd2016-05-12 12:45:51 +05301038 DEBUG_FOO(wmi_command_log),
1039 DEBUG_FOO(wmi_command_tx_cmp_log),
1040 DEBUG_FOO(wmi_event_log),
1041 DEBUG_FOO(wmi_rx_event_log),
1042 DEBUG_FOO(wmi_mgmt_command_log),
1043 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1044 DEBUG_FOO(wmi_mgmt_event_log),
1045 DEBUG_FOO(wmi_enable),
1046 DEBUG_FOO(wmi_log_size),
1047};
1048
Govind Singhecf03cd2016-05-12 12:45:51 +05301049
1050/**
1051 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1052 *
1053 * @wmi_handle: wmi handle
1054 * @par_entry: debug directory entry
1055 * @id: Index to debug info data array
1056 *
1057 * Return: none
1058 */
1059static void wmi_debugfs_create(wmi_unified_t wmi_handle,
c_priysb5f94a82018-06-12 16:53:51 +05301060 struct dentry *par_entry)
Govind Singhecf03cd2016-05-12 12:45:51 +05301061{
1062 int i;
1063
c_priysb5f94a82018-06-12 16:53:51 +05301064 if (!par_entry)
Govind Singhecf03cd2016-05-12 12:45:51 +05301065 goto out;
1066
1067 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
c_priysb5f94a82018-06-12 16:53:51 +05301068 wmi_handle->debugfs_de[i] = debugfs_create_file(
Govind Singhecf03cd2016-05-12 12:45:51 +05301069 wmi_debugfs_infos[i].name, 0644, par_entry,
1070 wmi_handle, wmi_debugfs_infos[i].ops);
1071
c_priysb5f94a82018-06-12 16:53:51 +05301072 if (!wmi_handle->debugfs_de[i]) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301073 qdf_print("debug Entry creation failed!");
Govind Singhecf03cd2016-05-12 12:45:51 +05301074 goto out;
1075 }
1076 }
1077
1078 return;
1079
1080out:
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301081 qdf_print("debug Entry creation failed!");
Govind Singhecf03cd2016-05-12 12:45:51 +05301082 wmi_log_buffer_free(wmi_handle);
1083 return;
1084}
1085
1086/**
1087 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301088 * @wmi_handle: wmi handle
1089 * @dentry: debugfs directory entry
1090 * @id: Index to debug info data array
1091 *
1092 * Return: none
1093 */
Govind Singh06c18392016-06-10 10:33:19 +05301094static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301095{
1096 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301097 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
Govind Singhecf03cd2016-05-12 12:45:51 +05301098
c_priysb5f94a82018-06-12 16:53:51 +05301099 if (dentry) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301100 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
c_priysb5f94a82018-06-12 16:53:51 +05301101 if (wmi_handle->debugfs_de[i])
1102 wmi_handle->debugfs_de[i] = NULL;
Govind Singhecf03cd2016-05-12 12:45:51 +05301103 }
1104 }
1105
1106 if (dentry)
1107 debugfs_remove_recursive(dentry);
1108}
1109
1110/**
1111 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1112 * create debugfs enteries.
1113 *
1114 * @h: wmi handler
1115 *
1116 * Return: init status
1117 */
c_priysb5f94a82018-06-12 16:53:51 +05301118static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle, uint32_t pdev_idx)
Govind Singhecf03cd2016-05-12 12:45:51 +05301119{
c_priysb5f94a82018-06-12 16:53:51 +05301120 char buf[32];
Govind Singhecf03cd2016-05-12 12:45:51 +05301121
c_priysb5f94a82018-06-12 16:53:51 +05301122 snprintf(buf, sizeof(buf), "WMI_SOC%u_PDEV%u",
1123 wmi_handle->soc->soc_idx, pdev_idx);
Govind Singhecf03cd2016-05-12 12:45:51 +05301124
c_priysb5f94a82018-06-12 16:53:51 +05301125 wmi_handle->log_info.wmi_log_debugfs_dir =
1126 debugfs_create_dir(buf, NULL);
Govind Singhecf03cd2016-05-12 12:45:51 +05301127
c_priysb5f94a82018-06-12 16:53:51 +05301128 if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301129 qdf_print("error while creating debugfs dir for %s", buf);
c_priysb5f94a82018-06-12 16:53:51 +05301130 return QDF_STATUS_E_FAILURE;
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301131 }
c_priysb5f94a82018-06-12 16:53:51 +05301132 wmi_debugfs_create(wmi_handle,
1133 wmi_handle->log_info.wmi_log_debugfs_dir);
Govind Singhecf03cd2016-05-12 12:45:51 +05301134
1135 return QDF_STATUS_SUCCESS;
1136}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001137
1138/**
1139 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1140 *
1141 * @wmi_handle: wmi handle
1142 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001143 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001144 * @vdev_id: vdev id
1145 * @chanfreq: channel frequency
1146 *
1147 * Return: none
1148 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301149void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001150 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001151{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301152
1153 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1154
1155 data[0] = ((struct wmi_command_header *)header)->type;
1156 data[1] = ((struct wmi_command_header *)header)->sub_type;
1157 data[2] = vdev_id;
1158 data[3] = chanfreq;
1159
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001160 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1161
Rakesh Pillai05110462017-12-27 14:08:59 +05301162 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001163
1164 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1165}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001166#else
1167/**
1168 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1169 * @wmi_handle: wmi handle
1170 * @dentry: debugfs directory entry
1171 * @id: Index to debug info data array
1172 *
1173 * Return: none
1174 */
Govind Singh06c18392016-06-10 10:33:19 +05301175static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301176void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001177 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301178static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301179#endif /*WMI_INTERFACE_EVENT_LOGGING */
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301180qdf_export_symbol(wmi_mgmt_cmd_record);
Govind Singh6b411b52016-03-06 19:55:02 +05301181
Govind Singh6b411b52016-03-06 19:55:02 +05301182int wmi_get_host_credits(wmi_unified_t wmi_handle);
1183/* WMI buffer APIs */
1184
Shiva Krishna Pittala79293372018-04-02 17:23:42 +05301185#ifdef NBUF_MEMORY_DEBUG
Govind Singh6b411b52016-03-06 19:55:02 +05301186wmi_buf_t
Debasis Daseaf8a8b2018-04-04 17:17:55 +05301187wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len, uint8_t *file_name,
1188 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301189{
1190 wmi_buf_t wmi_buf;
1191
1192 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301193 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301194 return NULL;
1195 }
1196
Govind Singhb53420c2016-03-09 14:32:57 +05301197 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301198 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1199 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1200 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301201
1202 if (!wmi_buf)
1203 return NULL;
1204
1205 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301206 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301207
1208 /*
1209 * Set the length of the buffer to match the allocation size.
1210 */
Govind Singhb53420c2016-03-09 14:32:57 +05301211 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301212
1213 return wmi_buf;
1214}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301215qdf_export_symbol(wmi_buf_alloc_debug);
Govind Singh6b411b52016-03-06 19:55:02 +05301216
1217void wmi_buf_free(wmi_buf_t net_buf)
1218{
Govind Singhb53420c2016-03-09 14:32:57 +05301219 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301220}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301221qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301222#else
Arif Hussain3f6ad3d2018-07-19 14:15:36 -07001223wmi_buf_t wmi_buf_alloc_fl(wmi_unified_t wmi_handle, uint32_t len,
1224 const char *func, uint32_t line)
Govind Singh6b411b52016-03-06 19:55:02 +05301225{
1226 wmi_buf_t wmi_buf;
1227
1228 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Arif Hussain3f6ad3d2018-07-19 14:15:36 -07001229 wmi_nofl_err("%s:%d, Invalid len:%d", func, line, len);
1230 QDF_DEBUG_PANIC();
Govind Singh6b411b52016-03-06 19:55:02 +05301231 return NULL;
1232 }
1233
Govind Singhb53420c2016-03-09 14:32:57 +05301234 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301235 WMI_MIN_HEAD_ROOM, 4, false);
1236 if (!wmi_buf)
1237 return NULL;
1238
1239 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301240 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301241
1242 /*
1243 * Set the length of the buffer to match the allocation size.
1244 */
Govind Singhb53420c2016-03-09 14:32:57 +05301245 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301246 return wmi_buf;
1247}
Arif Hussain3f6ad3d2018-07-19 14:15:36 -07001248qdf_export_symbol(wmi_buf_alloc_fl);
Govind Singh6b411b52016-03-06 19:55:02 +05301249
1250void wmi_buf_free(wmi_buf_t net_buf)
1251{
Govind Singhb53420c2016-03-09 14:32:57 +05301252 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301253}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301254qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301255#endif
1256
1257/**
1258 * wmi_get_max_msg_len() - get maximum WMI message length
1259 * @wmi_handle: WMI handle.
1260 *
1261 * This function returns the maximum WMI message length
1262 *
1263 * Return: maximum WMI message length
1264 */
1265uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1266{
1267 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1268}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301269qdf_export_symbol(wmi_get_max_msg_len);
Govind Singh6b411b52016-03-06 19:55:02 +05301270
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301271#ifndef WMI_CMD_STRINGS
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301272static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301273{
1274 return "Invalid WMI cmd";
1275}
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301276
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301277#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301278
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301279#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301280static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1281{
1282 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1283 wmi_id_to_name(cmd_id), cmd_id, tag);
1284}
1285
Govind Singh6b411b52016-03-06 19:55:02 +05301286/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301287 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1288 * @cmd_id: command to check
1289 *
1290 * Return: true if the command is part of the resume sequence.
1291 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301292static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301293{
1294 switch (cmd_id) {
1295 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1296 case WMI_PDEV_RESUME_CMDID:
1297 return true;
1298
1299 default:
1300 return false;
1301 }
1302}
1303#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301304static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301305{
1306 return false;
1307}
1308#endif
1309
1310/**
Govind Singh6b411b52016-03-06 19:55:02 +05301311 * wmi_unified_cmd_send() - WMI command API
1312 * @wmi_handle: handle to wmi
1313 * @buf: wmi buf
1314 * @len: wmi buffer length
1315 * @cmd_id: wmi command id
1316 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001317 * Note, it is NOT safe to access buf after calling this function!
1318 *
Govind Singh6b411b52016-03-06 19:55:02 +05301319 * Return: 0 on success
1320 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001321QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1322 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301323{
1324 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301325 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301326 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301327
1328 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301329 htc_tag =
Vivekc5823092018-03-22 23:27:21 +05301330 (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301331 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301332 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301333 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301334 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301335 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301336 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301337 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301338 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301339 if (wmi_handle->wmi_stopinprogress) {
1340 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301341 "WMI stop in progress");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001342 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301343 }
Govind Singh6b411b52016-03-06 19:55:02 +05301344
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301345#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301346 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301347 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301348 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301349
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301350 if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301351 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301352 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301353 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301354 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301355 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301356 }
1357 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301358#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301359
Govind Singhb53420c2016-03-09 14:32:57 +05301360 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1361 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301362 "%s, Failed to send cmd %x, no memory",
1363 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301364 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301365 }
1366
Vignesh Viswanathan737cef72018-06-15 12:42:45 +05301367 qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
Govind Singhb53420c2016-03-09 14:32:57 +05301368 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301369
Govind Singhb53420c2016-03-09 14:32:57 +05301370 qdf_atomic_inc(&wmi_handle->pending_cmds);
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301371 if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
1372 wmi_handle->wmi_max_cmds) {
Govind Singhb53420c2016-03-09 14:32:57 +05301373 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301374 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301375 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301376 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301377 qdf_atomic_dec(&wmi_handle->pending_cmds);
1378 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301379 "%s: MAX %d WMI Pending cmds reached.", __func__,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301380 wmi_handle->wmi_max_cmds);
Govind Singhb53420c2016-03-09 14:32:57 +05301381 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301382 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301383 }
1384
Govind Singhb53420c2016-03-09 14:32:57 +05301385 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301386 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301387 qdf_atomic_dec(&wmi_handle->pending_cmds);
1388 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301389 "%s, Failed to alloc htc packet %x, no memory",
1390 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301391 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301392 }
1393
1394 SET_HTC_PACKET_INFO_TX(pkt,
1395 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301396 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301397 wmi_handle->wmi_endpoint_id, htc_tag);
1398
1399 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301400#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301401 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301402#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301403
1404#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301405 if (wmi_handle->log_info.wmi_logging_enable) {
1406 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
jiad36c94d22018-01-22 15:37:03 +08001407 /*
1408 * Record 16 bytes of WMI cmd data -
1409 * exclude TLV and WMI headers
1410 *
1411 * WMI mgmt command already recorded in wmi_mgmt_cmd_record
1412 */
1413 if (wmi_handle->ops->is_management_record(cmd_id) == false) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301414 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301415 qdf_nbuf_data(buf) +
1416 wmi_handle->log_info.buf_offset_command);
Govind Singhecf03cd2016-05-12 12:45:51 +05301417 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301418 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1419 }
Govind Singh6b411b52016-03-06 19:55:02 +05301420#endif
1421
1422 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1423
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301424 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301425 qdf_atomic_dec(&wmi_handle->pending_cmds);
1426 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301427 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07001428 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301429 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05301430 }
Govind Singh6b411b52016-03-06 19:55:02 +05301431
Govind Singhb53420c2016-03-09 14:32:57 +05301432 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301433}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301434qdf_export_symbol(wmi_unified_cmd_send);
Govind Singh6b411b52016-03-06 19:55:02 +05301435
1436/**
1437 * wmi_unified_get_event_handler_ix() - gives event handler's index
1438 * @wmi_handle: handle to wmi
1439 * @event_id: wmi event id
1440 *
1441 * Return: event handler's index
1442 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001443static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
1444 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301445{
1446 uint32_t idx = 0;
1447 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301448 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301449
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301450 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05301451 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1452 if (wmi_handle->event_id[idx] == event_id &&
1453 wmi_handle->event_handler[idx] != NULL) {
1454 return idx;
1455 }
1456 }
1457
1458 return invalid_idx;
1459}
1460
1461/**
Soumya Bhat488092d2017-03-22 14:41:01 +05301462 * wmi_unified_register_event() - register wmi event handler
1463 * @wmi_handle: handle to wmi
1464 * @event_id: wmi event id
1465 * @handler_func: wmi event handler function
1466 *
1467 * Return: 0 on success
1468 */
1469int wmi_unified_register_event(wmi_unified_t wmi_handle,
1470 uint32_t event_id,
1471 wmi_unified_event_handler handler_func)
1472{
1473 uint32_t idx = 0;
1474 uint32_t evt_id;
1475 struct wmi_soc *soc = wmi_handle->soc;
1476
1477 if (event_id >= wmi_events_max ||
1478 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301479 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1480 "%s: Event id %d is unavailable",
1481 __func__, event_id);
Soumya Bhat488092d2017-03-22 14:41:01 +05301482 return QDF_STATUS_E_FAILURE;
1483 }
1484 evt_id = wmi_handle->wmi_events[event_id];
1485 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301486 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1487 "%s : event handler already registered 0x%x",
1488 __func__, evt_id);
Soumya Bhat488092d2017-03-22 14:41:01 +05301489 return QDF_STATUS_E_FAILURE;
1490 }
1491 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301492 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1493 "%s : no more event handlers 0x%x",
1494 __func__, evt_id);
Soumya Bhat488092d2017-03-22 14:41:01 +05301495 return QDF_STATUS_E_FAILURE;
1496 }
1497 idx = soc->max_event_idx;
1498 wmi_handle->event_handler[idx] = handler_func;
1499 wmi_handle->event_id[idx] = evt_id;
1500 qdf_spin_lock_bh(&soc->ctx_lock);
1501 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
1502 qdf_spin_unlock_bh(&soc->ctx_lock);
1503 soc->max_event_idx++;
1504
1505 return 0;
1506}
1507
1508/**
Govind Singh6b411b52016-03-06 19:55:02 +05301509 * wmi_unified_register_event_handler() - register wmi event handler
1510 * @wmi_handle: handle to wmi
1511 * @event_id: wmi event id
1512 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301513 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301514 *
Soumya Bhat488092d2017-03-22 14:41:01 +05301515 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05301516 * Return: 0 on success
1517 */
1518int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301519 wmi_conv_event_id event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301520 wmi_unified_event_handler handler_func,
1521 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301522{
1523 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301524 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301525 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301526
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301527 if (event_id >= wmi_events_max ||
1528 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301529 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1530 "%s: Event id %d is unavailable",
1531 __func__, event_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301532 return QDF_STATUS_E_FAILURE;
1533 }
1534 evt_id = wmi_handle->wmi_events[event_id];
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301535
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301536 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301537 qdf_print("event handler already registered 0x%x",
1538 evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301539 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301540 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301541 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301542 qdf_print("no more event handlers 0x%x",
1543 evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301544 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301545 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07001546 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301547 "Registered event handler for event 0x%8x", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301548 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301549 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301550 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301551 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301552 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301553 qdf_spin_unlock_bh(&soc->ctx_lock);
1554 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05301555
1556 return 0;
1557}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301558qdf_export_symbol(wmi_unified_register_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301559
1560/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301561 * wmi_unified_unregister_event() - unregister wmi event handler
1562 * @wmi_handle: handle to wmi
1563 * @event_id: wmi event id
1564 *
1565 * Return: 0 on success
1566 */
1567int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
1568 uint32_t event_id)
1569{
1570 uint32_t idx = 0;
1571 uint32_t evt_id;
1572 struct wmi_soc *soc = wmi_handle->soc;
1573
1574 if (event_id >= wmi_events_max ||
1575 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301576 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1577 "%s: Event id %d is unavailable",
1578 __func__, event_id);
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301579 return QDF_STATUS_E_FAILURE;
1580 }
1581 evt_id = wmi_handle->wmi_events[event_id];
1582
1583 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
1584 if (idx == -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301585 qdf_print("event handler is not registered: evt id 0x%x",
1586 evt_id);
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301587 return QDF_STATUS_E_FAILURE;
1588 }
1589 wmi_handle->event_handler[idx] = NULL;
1590 wmi_handle->event_id[idx] = 0;
1591 --soc->max_event_idx;
1592 wmi_handle->event_handler[idx] =
1593 wmi_handle->event_handler[soc->max_event_idx];
1594 wmi_handle->event_id[idx] =
1595 wmi_handle->event_id[soc->max_event_idx];
1596
1597 return 0;
1598}
1599
1600/**
Govind Singh6b411b52016-03-06 19:55:02 +05301601 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1602 * @wmi_handle: handle to wmi
1603 * @event_id: wmi event id
1604 *
1605 * Return: 0 on success
1606 */
1607int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301608 wmi_conv_event_id event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301609{
1610 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301611 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301612 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301613
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301614 if (event_id >= wmi_events_max ||
1615 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301616 qdf_print("Event id %d is unavailable",
1617 event_id);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301618 return QDF_STATUS_E_FAILURE;
1619 }
1620 evt_id = wmi_handle->wmi_events[event_id];
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301621
1622 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301623 if (idx == -1) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301624 qdf_print("event handler is not registered: evt id 0x%x",
1625 evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301626 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301627 }
1628 wmi_handle->event_handler[idx] = NULL;
1629 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301630 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301631 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301632 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301633 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301634 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301635
1636 return 0;
1637}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301638qdf_export_symbol(wmi_unified_unregister_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301639
1640/**
Govind Singhd52faac2016-03-09 12:03:29 +05301641 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301642 * @wmi_handle: handle to wmi
1643 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301644 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301645 *
Govind Singhd52faac2016-03-09 12:03:29 +05301646 * Event process by below function will be in default caller context.
1647 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301648 *
1649 * Return: none
1650 */
Govind Singhd52faac2016-03-09 12:03:29 +05301651static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1652 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301653{
1654 wmi_buf_t evt_buf;
1655 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1656
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301657#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301658 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1659 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1660#else
Govind Singh5eb51532016-03-09 11:34:12 +05301661 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Amar Singhal66d1ed52018-06-26 16:45:54 -07001662 htc_packet, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301663#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301664
Govind Singh6b411b52016-03-06 19:55:02 +05301665 return;
1666}
1667
1668/**
1669 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1670 * @wmi_handle: handle to wmi
1671 * @htc_packet: pointer to htc packet
1672 *
1673 * Event process by below function will be in worker thread context.
1674 * Use this method for events which are not critical and not
1675 * handled in protocol stack.
1676 *
1677 * Return: none
1678 */
Amar Singhal66d1ed52018-06-26 16:45:54 -07001679void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
1680 HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301681{
1682 wmi_buf_t evt_buf;
Govind Singh6b411b52016-03-06 19:55:02 +05301683
1684 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singh6b411b52016-03-06 19:55:02 +05301685
Govind Singhb53420c2016-03-09 14:32:57 +05301686 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1687 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1688 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001689 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
1690 &wmi_handle->rx_event_work);
1691
Govind Singh6b411b52016-03-06 19:55:02 +05301692 return;
1693}
1694
Amar Singhal66d1ed52018-06-26 16:45:54 -07001695qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
1696
Govind Singh6b411b52016-03-06 19:55:02 +05301697/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301698 * wmi_get_pdev_ep: Get wmi handle based on endpoint
1699 * @soc: handle to wmi soc
1700 * @ep: endpoint id
1701 *
1702 * Return: none
1703 */
1704static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
1705 HTC_ENDPOINT_ID ep)
1706{
1707 uint32_t i;
1708
1709 for (i = 0; i < WMI_MAX_RADIOS; i++)
1710 if (soc->wmi_endpoint_id[i] == ep)
1711 break;
1712
1713 if (i == WMI_MAX_RADIOS)
1714 return NULL;
1715
1716 return soc->wmi_pdev[i];
1717}
1718
1719/**
Govind Singhd52faac2016-03-09 12:03:29 +05301720 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301721 * @ctx: handle to wmi
1722 * @htc_packet: pointer to htc packet
1723 *
Govind Singh6b411b52016-03-06 19:55:02 +05301724 * Return: none
1725 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001726static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301727{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301728 struct wmi_soc *soc = (struct wmi_soc *) ctx;
1729 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05301730 wmi_buf_t evt_buf;
1731 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301732 uint32_t idx = 0;
1733 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301734
1735 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301736
1737 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
1738 if (wmi_handle == NULL) {
1739 qdf_print
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301740 ("unable to get wmi_handle to Endpoint %d\n",
1741 htc_packet->Endpoint);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301742 qdf_nbuf_free(evt_buf);
1743 return;
1744 }
1745
Govind Singhb53420c2016-03-09 14:32:57 +05301746 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301747 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301748 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05301749 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
1750 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301751 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301752 return;
1753 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301754 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301755 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301756 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301757
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001758#ifdef WMI_INTERFACE_EVENT_LOGGING
1759 if (wmi_handle->log_info.wmi_logging_enable) {
1760 uint8_t *data;
1761 data = qdf_nbuf_data(evt_buf);
1762
1763 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1764 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05301765 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
1766 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001767 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1768 }
1769#endif
1770
Govind Singhd52faac2016-03-09 12:03:29 +05301771 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301772 wmi_process_fw_event_worker_thread_ctx
1773 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301774 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1775 wmi_process_fw_event_default_ctx
1776 (wmi_handle, htc_packet, exec_ctx);
1777 } else {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301778 qdf_print("Invalid event context %d", exec_ctx);
Govind Singhb53420c2016-03-09 14:32:57 +05301779 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301780 }
Govind Singhd52faac2016-03-09 12:03:29 +05301781
Govind Singh6b411b52016-03-06 19:55:02 +05301782}
1783
1784/**
1785 * wmi_process_fw_event() - process any fw event
1786 * @wmi_handle: wmi handle
1787 * @evt_buf: fw event buffer
1788 *
Govind Singhd52faac2016-03-09 12:03:29 +05301789 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301790 *
1791 * Return: none
1792 */
1793void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1794{
1795 __wmi_control_rx(wmi_handle, evt_buf);
1796}
1797
1798/**
1799 * __wmi_control_rx() - process serialize wmi event callback
1800 * @wmi_handle: wmi handle
1801 * @evt_buf: fw event buffer
1802 *
1803 * Return: none
1804 */
1805void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1806{
1807 uint32_t id;
1808 uint8_t *data;
1809 uint32_t len;
1810 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301811#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301812 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301813#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301814 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301815
Govind Singhb53420c2016-03-09 14:32:57 +05301816 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301817
Govind Singhb53420c2016-03-09 14:32:57 +05301818 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05301819 goto end;
1820
Govind Singhb53420c2016-03-09 14:32:57 +05301821 data = qdf_nbuf_data(evt_buf);
1822 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301823
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301824#ifndef WMI_NON_TLV_SUPPORT
1825 if (wmi_handle->target_type == WMI_TLV_TARGET) {
1826 /* Validate and pad(if necessary) the TLVs */
1827 tlv_ok_status =
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301828 wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05301829 data, len, id,
1830 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301831 if (tlv_ok_status != 0) {
1832 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301833 "%s: Error: id=0x%x, wmitlv check status=%d",
1834 __func__, id, tlv_ok_status);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301835 goto end;
1836 }
Govind Singh6b411b52016-03-06 19:55:02 +05301837 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301838#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301839
Govind Singhd52faac2016-03-09 12:03:29 +05301840 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
1841 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05301842 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05301843 "%s : event handler is not registered: event id 0x%x",
Govind Singhd52faac2016-03-09 12:03:29 +05301844 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05301845 goto end;
1846 }
Govind Singhd52faac2016-03-09 12:03:29 +05301847#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301848 if (wmi_handle->log_info.wmi_logging_enable) {
1849 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1850 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301851 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05301852 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
1853 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301854 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05301855 WMI_EVENT_RECORD(wmi_handle, id, data +
1856 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301857 }
1858 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301859 }
Govind Singhd52faac2016-03-09 12:03:29 +05301860#endif
1861 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301862 if (wmi_handle->target_type == WMI_TLV_TARGET)
1863 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1864 wmi_cmd_struct_ptr, len);
1865 else
1866 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1867 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05301868
Govind Singh6b411b52016-03-06 19:55:02 +05301869end:
Govind Singhd52faac2016-03-09 12:03:29 +05301870 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301871#ifndef WMI_NON_TLV_SUPPORT
1872 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301873 wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301874#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301875
Govind Singhb53420c2016-03-09 14:32:57 +05301876 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301877
Govind Singh6b411b52016-03-06 19:55:02 +05301878}
1879
Arunk Khandavallib6ba21f2017-12-06 15:47:10 +05301880#define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
Govind Singh97b8e7c2017-09-07 18:23:39 +05301881
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05301882static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05301883{
1884 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Kabilan Kannanf1311ec2018-03-08 14:34:28 -08001885 "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
Govind Singh97b8e7c2017-09-07 18:23:39 +05301886 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
1887}
1888
1889#ifdef CONFIG_SLUB_DEBUG_ON
1890static void wmi_workqueue_watchdog_bite(void *arg)
1891{
Govind Singhc646e102017-11-21 10:53:40 +05301892 struct wmi_wq_dbg_info *info = arg;
1893
1894 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
1895 qdf_print_thread_trace(info->task);
1896
Govind Singh97b8e7c2017-09-07 18:23:39 +05301897 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1898 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
1899 QDF_BUG(0);
1900}
1901#else
1902static inline void wmi_workqueue_watchdog_bite(void *arg)
1903{
Govind Singhc646e102017-11-21 10:53:40 +05301904 struct wmi_wq_dbg_info *info = arg;
1905
1906 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301907}
1908#endif
1909
Govind Singh6b411b52016-03-06 19:55:02 +05301910/**
1911 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001912 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05301913 *
1914 * This function process any fw event to serialize it through rx worker thread.
1915 *
1916 * Return: none
1917 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001918static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05301919{
Govind Singh6b411b52016-03-06 19:55:02 +05301920 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001921 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05301922 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05301923 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05301924
Govind Singh97b8e7c2017-09-07 18:23:39 +05301925 /* initialize WMI workqueue watchdog timer */
1926 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05301927 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05301928 qdf_spin_lock_bh(&wmi->eventq_lock);
1929 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1930 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301931 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05301932 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05301933 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05301934 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05301935 info.wmi_wq = wmi->wmi_rx_work_queue;
1936 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05301937 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301938 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05301939 qdf_spin_lock_bh(&wmi->eventq_lock);
1940 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1941 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301942 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05301943 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05301944}
1945
Govind Singh6b411b52016-03-06 19:55:02 +05301946#ifdef FEATURE_RUNTIME_PM
1947/**
1948 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
1949 * @wmi_handle: wmi context
1950 */
Govind Singhd52faac2016-03-09 12:03:29 +05301951static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301952{
Govind Singhb53420c2016-03-09 14:32:57 +05301953 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05301954}
Govind Singhd52faac2016-03-09 12:03:29 +05301955
1956/**
1957 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
1958 * @wmi_handle: wmi context
1959 * @val: runtime pm progress flag
1960 */
1961void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
1962{
Govind Singhb53420c2016-03-09 14:32:57 +05301963 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05301964}
1965
1966/**
1967 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
1968 * @wmi_handle: wmi context
1969 */
1970inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
1971{
Govind Singhb53420c2016-03-09 14:32:57 +05301972 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05301973}
Govind Singh6b411b52016-03-06 19:55:02 +05301974#else
Govind Singhd52faac2016-03-09 12:03:29 +05301975static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301976{
1977}
1978#endif
1979
1980/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301981 * wmi_unified_get_soc_handle: Get WMI SoC handle
1982 * @param wmi_handle: WMI context got from wmi_attach
1983 *
1984 * return: Pointer to Soc handle
1985 */
1986void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
1987{
1988 return wmi_handle->soc;
1989}
1990
1991/**
1992 * wmi_interface_logging_init: Interface looging init
1993 * @param wmi_handle: Pointer to wmi handle object
1994 *
1995 * return: None
1996 */
1997#ifdef WMI_INTERFACE_EVENT_LOGGING
c_priysb5f94a82018-06-12 16:53:51 +05301998static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
1999 uint32_t pdev_idx)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302000{
2001 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2002 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
c_priysb5f94a82018-06-12 16:53:51 +05302003 wmi_debugfs_init(wmi_handle, pdev_idx);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302004 }
2005}
2006#else
c_priysb5f94a82018-06-12 16:53:51 +05302007static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
2008 uint32_t pdev_idx)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302009{
2010}
2011#endif
2012
2013/**
2014 * wmi_target_params_init: Target specific params init
2015 * @param wmi_soc: Pointer to wmi soc object
2016 * @param wmi_handle: Pointer to wmi handle object
2017 *
2018 * return: None
2019 */
2020#ifndef CONFIG_MCL
2021static inline void wmi_target_params_init(struct wmi_soc *soc,
2022 struct wmi_unified *wmi_handle)
2023{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302024 wmi_handle->pdev_param = soc->pdev_param;
2025 wmi_handle->vdev_param = soc->vdev_param;
Kris Muthusamy76e22412018-01-26 16:18:37 -08002026 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302027}
2028#else
2029static inline void wmi_target_params_init(struct wmi_soc *soc,
2030 struct wmi_unified *wmi_handle)
2031{
Kris Muthusamy76e22412018-01-26 16:18:37 -08002032 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302033}
2034#endif
2035
2036/**
2037 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2038 * @param wmi_soc: Pointer to wmi soc object
2039 * @param pdev_idx: pdev index
2040 *
2041 * return: Pointer to wmi handle or NULL on failure
2042 */
2043void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2044{
2045 struct wmi_unified *wmi_handle;
2046
2047 if (pdev_idx >= WMI_MAX_RADIOS)
2048 return NULL;
2049
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302050 if (soc->wmi_pdev[pdev_idx] == NULL) {
2051 wmi_handle =
2052 (struct wmi_unified *) qdf_mem_malloc(
2053 sizeof(struct wmi_unified));
2054 if (wmi_handle == NULL) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302055 qdf_print("allocation of wmi handle failed %zu",
2056 sizeof(struct wmi_unified));
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302057 return NULL;
2058 }
2059 wmi_handle->scn_handle = soc->scn_handle;
2060 wmi_handle->event_id = soc->event_id;
2061 wmi_handle->event_handler = soc->event_handler;
2062 wmi_handle->ctx = soc->ctx;
2063 wmi_handle->ops = soc->ops;
2064 qdf_spinlock_create(&wmi_handle->eventq_lock);
2065 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302066
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302067 qdf_create_work(0, &wmi_handle->rx_event_work,
2068 wmi_rx_event_work, wmi_handle);
2069 wmi_handle->wmi_rx_work_queue =
2070 qdf_create_workqueue("wmi_rx_event_work_queue");
2071 if (NULL == wmi_handle->wmi_rx_work_queue) {
2072 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2073 goto error;
2074 }
2075 wmi_handle->wmi_events = soc->wmi_events;
2076 wmi_target_params_init(soc, wmi_handle);
c_priysb5f94a82018-06-12 16:53:51 +05302077 wmi_handle->soc = soc;
2078 wmi_interface_logging_init(wmi_handle, pdev_idx);
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302079 qdf_atomic_init(&wmi_handle->pending_cmds);
2080 qdf_atomic_init(&wmi_handle->is_target_suspended);
2081 wmi_handle->target_type = soc->target_type;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302082 wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002083
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302084 soc->wmi_pdev[pdev_idx] = wmi_handle;
2085 } else
2086 wmi_handle = soc->wmi_pdev[pdev_idx];
2087
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302088 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302089 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2090 wmi_handle->htc_handle = soc->htc_handle;
2091 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302092
2093 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002094
2095error:
2096 qdf_mem_free(wmi_handle);
2097
2098 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302099}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302100qdf_export_symbol(wmi_unified_get_pdev_handle);
2101
2102static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
2103
2104void wmi_unified_register_module(enum wmi_target_type target_type,
2105 void (*wmi_attach)(wmi_unified_t wmi_handle))
2106{
2107 if (target_type < WMI_MAX_TARGET_TYPE)
2108 wmi_attach_register[target_type] = wmi_attach;
2109
2110 return;
2111}
2112qdf_export_symbol(wmi_unified_register_module);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302113
2114/**
Govind Singh6b411b52016-03-06 19:55:02 +05302115 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302116 * @scn_handle: handle to SCN
2117 * @osdev: OS device context
2118 * @target_type: TLV or not-TLV based target
2119 * @use_cookie: cookie based allocation enabled/disabled
2120 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302121 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302122 *
2123 * @Return: wmi handle.
2124 */
Govind Singhc458f382016-02-04 18:42:30 +05302125void *wmi_unified_attach(void *scn_handle,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302126 struct wmi_unified_attach_params *param)
Govind Singh6b411b52016-03-06 19:55:02 +05302127{
2128 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302129 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302130
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302131 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2132 if (soc == NULL) {
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302133 qdf_print("Allocation of wmi_soc failed %zu",
2134 sizeof(struct wmi_soc));
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302135 return NULL;
2136 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302137
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302138 wmi_handle =
2139 (struct wmi_unified *) qdf_mem_malloc(
2140 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302141 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302142 qdf_mem_free(soc);
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302143 qdf_print("allocation of wmi handle failed %zu",
2144 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302145 return NULL;
2146 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302147 wmi_handle->soc = soc;
c_priysb5f94a82018-06-12 16:53:51 +05302148 wmi_handle->soc->soc_idx = param->soc_id;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302149 wmi_handle->event_id = soc->event_id;
2150 wmi_handle->event_handler = soc->event_handler;
2151 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302152 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302153 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302154 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302155 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302156 qdf_atomic_init(&wmi_handle->pending_cmds);
2157 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302158 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302159 qdf_spinlock_create(&wmi_handle->eventq_lock);
2160 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002161 qdf_create_work(0, &wmi_handle->rx_event_work,
2162 wmi_rx_event_work, wmi_handle);
2163 wmi_handle->wmi_rx_work_queue =
2164 qdf_create_workqueue("wmi_rx_event_work_queue");
2165 if (NULL == wmi_handle->wmi_rx_work_queue) {
2166 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2167 goto error;
2168 }
c_priysb5f94a82018-06-12 16:53:51 +05302169 wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
Govind Singhc458f382016-02-04 18:42:30 +05302170 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302171 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302172 param->rx_ops->wma_process_fw_event_handler_cbk;
2173 wmi_handle->target_type = param->target_type;
2174 soc->target_type = param->target_type;
Abhiram Jogadenu429ab532018-05-14 17:13:28 +05302175
2176 if (param->target_type >= WMI_MAX_TARGET_TYPE)
2177 goto error;
2178
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302179 if (wmi_attach_register[param->target_type]) {
2180 wmi_attach_register[param->target_type](wmi_handle);
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302181 } else {
2182 WMI_LOGE("wmi attach is not registered");
2183 goto error;
2184 }
Govind Singhc458f382016-02-04 18:42:30 +05302185 /* Assign target cookie capablity */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302186 wmi_handle->use_cookie = param->use_cookie;
2187 wmi_handle->osdev = param->osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302188 wmi_handle->wmi_stopinprogress = 0;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302189 wmi_handle->wmi_max_cmds = param->max_commands;
2190 soc->wmi_max_cmds = param->max_commands;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302191 /* Increase the ref count once refcount infra is present */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302192 soc->wmi_psoc = param->psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302193 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302194
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302195 soc->ops = wmi_handle->ops;
2196 soc->wmi_pdev[0] = wmi_handle;
2197
Govind Singh6b411b52016-03-06 19:55:02 +05302198 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002199
2200error:
2201 qdf_mem_free(soc);
2202 qdf_mem_free(wmi_handle);
2203
2204 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302205}
2206
2207/**
2208 * wmi_unified_detach() - detach for unified WMI
2209 *
2210 * @wmi_handle : handle to wmi.
2211 *
2212 * @Return: none.
2213 */
2214void wmi_unified_detach(struct wmi_unified *wmi_handle)
2215{
2216 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302217 struct wmi_soc *soc;
2218 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302219
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302220 soc = wmi_handle->soc;
2221 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2222 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002223 qdf_flush_workqueue(0,
2224 soc->wmi_pdev[i]->wmi_rx_work_queue);
2225 qdf_destroy_workqueue(0,
2226 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302227 wmi_debugfs_remove(soc->wmi_pdev[i]);
2228 buf = qdf_nbuf_queue_remove(
2229 &soc->wmi_pdev[i]->event_queue);
2230 while (buf) {
2231 qdf_nbuf_free(buf);
2232 buf = qdf_nbuf_queue_remove(
2233 &soc->wmi_pdev[i]->event_queue);
2234 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002235
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302236 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002237
2238 /* Free events logs list */
2239 if (soc->wmi_pdev[i]->events_logs_list)
2240 qdf_mem_free(
2241 soc->wmi_pdev[i]->events_logs_list);
2242
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302243 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302244 qdf_mem_free(soc->wmi_pdev[i]);
2245 }
Govind Singh6b411b52016-03-06 19:55:02 +05302246 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302247 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302248
2249 if (soc->wmi_service_bitmap) {
2250 qdf_mem_free(soc->wmi_service_bitmap);
2251 soc->wmi_service_bitmap = NULL;
2252 }
2253
2254 if (soc->wmi_ext_service_bitmap) {
2255 qdf_mem_free(soc->wmi_ext_service_bitmap);
2256 soc->wmi_ext_service_bitmap = NULL;
2257 }
2258
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302259 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302260 soc->wmi_psoc = NULL;
2261 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302262}
2263
2264/**
2265 * wmi_unified_remove_work() - detach for WMI work
2266 * @wmi_handle: handle to WMI
2267 *
2268 * A function that does not fully detach WMI, but just remove work
2269 * queue items associated with it. This is used to make sure that
2270 * before any other processing code that may destroy related contexts
2271 * (HTC, etc), work queue processing on WMI has already been stopped.
2272 *
2273 * Return: None
2274 */
2275void
2276wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2277{
2278 wmi_buf_t buf;
2279
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002280 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302281 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2282 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302283 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302284 qdf_nbuf_free(buf);
2285 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302286 }
Govind Singhb53420c2016-03-09 14:32:57 +05302287 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302288}
2289
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302290/**
2291 * wmi_htc_tx_complete() - Process htc tx completion
2292 *
2293 * @ctx: handle to wmi
2294 * @htc_packet: pointer to htc packet
2295 *
2296 * @Return: none.
2297 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002298static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302299{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302300 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302301 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302302 u_int8_t *buf_ptr;
2303 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302304 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302305#ifdef WMI_INTERFACE_EVENT_LOGGING
2306 uint32_t cmd_id;
2307#endif
2308
2309 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302310 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2311 if (wmi_handle == NULL) {
2312 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2313 QDF_ASSERT(0);
2314 return;
2315 }
Govind Singh6b411b52016-03-06 19:55:02 +05302316#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302317 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302318 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2319 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302320
Govind Singhecf03cd2016-05-12 12:45:51 +05302321 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302322 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302323 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302324 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302325 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302326 qdf_nbuf_data(wmi_cmd_buf) +
2327 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302328 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302329 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302330 qdf_nbuf_data(wmi_cmd_buf) +
2331 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302332 }
2333
Govind Singhecf03cd2016-05-12 12:45:51 +05302334 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2335 }
Govind Singh6b411b52016-03-06 19:55:02 +05302336#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302337 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2338 len = qdf_nbuf_len(wmi_cmd_buf);
2339 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302340 qdf_nbuf_free(wmi_cmd_buf);
2341 qdf_mem_free(htc_pkt);
2342 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302343}
2344
2345/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302346 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302347 *
2348 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302349 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302350 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302351 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302352 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302353static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2354 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302355{
Govind Singh6b411b52016-03-06 19:55:02 +05302356 int status;
Manikandan Mohanf940db82017-04-13 20:19:26 -07002357 struct htc_service_connect_resp response;
2358 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302359
2360 OS_MEMZERO(&connect, sizeof(connect));
2361 OS_MEMZERO(&response, sizeof(response));
2362
2363 /* meta data is unused for now */
2364 connect.pMetaData = NULL;
2365 connect.MetaDataLength = 0;
2366 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302367 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302368 connect.EpCallbacks.EpTxCompleteMultiple =
2369 NULL /* Control path completion ar6000_tx_complete */;
2370 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2371 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2372 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2373 connect.EpCallbacks.EpTxComplete =
2374 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2375
2376 /* connect to control service */
Pratik Gandhicf3b8b92018-02-05 17:22:41 +05302377 connect.service_id = soc->svc_ids[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302378 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302379 &response);
2380
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302381
Govind Singh6b411b52016-03-06 19:55:02 +05302382 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302383 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302384 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302385 status);
2386 return status;
2387 }
Govind Singh6b411b52016-03-06 19:55:02 +05302388
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302389 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2390 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2391
2392 return 0;
2393}
2394
2395/**
2396 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2397 *
2398 * @wmi_handle: handle to WMI.
2399 *
2400 * @Return: status.
2401 */
2402QDF_STATUS
2403wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2404 void *htc_handle)
2405{
2406 uint32_t i;
2407 uint8_t wmi_ep_count;
2408
2409 wmi_handle->soc->htc_handle = htc_handle;
2410
2411 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2412 if (wmi_ep_count > WMI_MAX_RADIOS)
2413 return QDF_STATUS_E_FAULT;
2414
2415 for (i = 0; i < wmi_ep_count; i++)
2416 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2417
2418 wmi_handle->htc_handle = htc_handle;
2419 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2420 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2421
2422 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302423}
2424
2425/**
2426 * wmi_get_host_credits() - WMI API to get updated host_credits
2427 *
2428 * @wmi_handle: handle to WMI.
2429 *
2430 * @Return: updated host_credits.
2431 */
2432int wmi_get_host_credits(wmi_unified_t wmi_handle)
2433{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302434 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302435
2436 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2437 &host_credits);
2438 return host_credits;
2439}
2440
2441/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302442 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2443 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302444 *
2445 * @wmi_handle: handle to WMI.
2446 *
2447 * @Return: Pending Commands in the HTC queue.
2448 */
2449int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2450{
Govind Singhb53420c2016-03-09 14:32:57 +05302451 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302452}
2453
2454/**
2455 * wmi_set_target_suspend() - WMI API to set target suspend state
2456 *
2457 * @wmi_handle: handle to WMI.
2458 * @val: suspend state boolean.
2459 *
2460 * @Return: none.
2461 */
2462void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2463{
Govind Singhb53420c2016-03-09 14:32:57 +05302464 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302465}
2466
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302467/**
2468 * WMI API to set crash injection state
2469 * @param wmi_handle: handle to WMI.
2470 * @param val: crash injection state boolean.
2471 */
2472void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2473{
2474 wmi_handle->tag_crash_inject = flag;
2475}
2476
2477/**
2478 * WMI API to set bus suspend state
2479 * @param wmi_handle: handle to WMI.
2480 * @param val: suspend state boolean.
2481 */
2482void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2483{
2484 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2485}
2486
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302487void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2488{
2489 wmi_handle->tgt_force_assert_enable = val;
2490}
2491
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002492/**
2493 * wmi_stop() - generic function to block unified WMI command
2494 * @wmi_handle: handle to WMI.
2495 *
2496 * @Return: success always.
2497 */
2498int
2499wmi_stop(wmi_unified_t wmi_handle)
2500{
2501 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Aditya Sathish45d7ada2018-07-02 17:31:55 +05302502 "WMI Stop");
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002503 wmi_handle->wmi_stopinprogress = 1;
2504 return 0;
2505}
2506
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302507#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302508/**
2509 * API to flush all the previous packets associated with the wmi endpoint
2510 *
2511 * @param wmi_handle : handle to WMI.
2512 */
2513void
2514wmi_flush_endpoint(wmi_unified_t wmi_handle)
2515{
2516 htc_flush_endpoint(wmi_handle->htc_handle,
2517 wmi_handle->wmi_endpoint_id, 0);
2518}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302519qdf_export_symbol(wmi_flush_endpoint);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302520
2521/**
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302522 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2523 * By default pdev_id conversion is not done in WMI.
2524 * This API can be used enable conversion in WMI.
2525 * @param wmi_handle : handle to WMI
2526 * Return none
2527 */
2528void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2529{
2530 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302531 wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302532}
2533
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302534#endif