blob: 189ad99610ed1319569de2176d832bf163fb08b7 [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 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*
29 * Host WMI unified implementation
30 */
Govind Singh6b411b52016-03-06 19:55:02 +053031#include "htc_api.h"
32#include "htc_api.h"
Govind Singh6b411b52016-03-06 19:55:02 +053033#include "wmi_unified_priv.h"
Govind Singh6b411b52016-03-06 19:55:02 +053034
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053035#ifndef WMI_NON_TLV_SUPPORT
36#include "wmi_tlv_helper.h"
37#endif
38
Govind Singhecf03cd2016-05-12 12:45:51 +053039#include <linux/debugfs.h>
40
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053041/* This check for CONFIG_WIN temporary added due to redeclaration compilation
42error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
43which gets included here through ol_if_athvar.h. Eventually it is expected that
44wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
45WMI_CMD_HDR to be defined here. */
46#ifdef CONFIG_WIN
47/* Copied from wmi.h */
48#undef MS
49#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
50#undef SM
51#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
52#undef WO
53#define WO(_f) ((_f##_OFFSET) >> 2)
54
55#undef GET_FIELD
56#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
57#undef SET_FIELD
58#define SET_FIELD(_addr, _f, _val) \
59 (*((A_UINT32 *)(_addr) + WO(_f)) = \
60 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
61
62#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
63 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
64
65#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
66 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
67
68#define WMI_EP_APASS 0x0
69#define WMI_EP_LPASS 0x1
70#define WMI_EP_SENSOR 0x2
71
72/*
73 * * Control Path
74 * */
75typedef PREPACK struct {
76 A_UINT32 commandId:24,
77 reserved:2, /* used for WMI endpoint ID */
78 plt_priv:6; /* platform private */
79} POSTPACK WMI_CMD_HDR; /* used for commands and events */
80
81#define WMI_CMD_HDR_COMMANDID_LSB 0
82#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
83#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
84#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
85#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
86#define WMI_CMD_HDR_PLT_PRIV_LSB 24
87#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
88#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
89/* end of copy wmi.h */
90#endif /* CONFIG_WIN */
91
Manikandan Mohan5826ae92016-06-08 16:29:39 -070092#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
93/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +053094static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -070095{
96 va_list args;
97
98 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +053099 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700100 va_end(args);
101
Pratik Gandhi795ab912017-05-03 20:15:50 +0530102 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700103}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530104#else
105#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700106#endif
107
Govind Singh6b411b52016-03-06 19:55:02 +0530108#define WMI_MIN_HEAD_ROOM 64
109
110#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +0530111#ifndef MAX_WMI_INSTANCES
112#ifdef CONFIG_MCL
113#define MAX_WMI_INSTANCES 1
114#else
115#define MAX_WMI_INSTANCES 3
116#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530117#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530118#endif
119
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530120#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530121/* WMI commands */
122uint32_t g_wmi_command_buf_idx = 0;
123struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
124
125/* WMI commands TX completed */
126uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
127struct wmi_command_debug
128 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
129
130/* WMI events when processed */
131uint32_t g_wmi_event_buf_idx = 0;
132struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
133
134/* WMI events when queued */
135uint32_t g_wmi_rx_event_buf_idx = 0;
136struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530137#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530138
Govind Singhecf03cd2016-05-12 12:45:51 +0530139#define WMI_COMMAND_RECORD(h, a, b) { \
140 if (wmi_log_max_entry <= \
141 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
142 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
143 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
144 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
145 .command = a; \
146 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
147 wmi_command_log_buf_info.buf) \
148 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
149 b, wmi_record_max_length); \
150 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
151 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
152 time = qdf_get_log_timestamp(); \
153 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
154 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530155}
156
Govind Singhecf03cd2016-05-12 12:45:51 +0530157#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
158 if (wmi_log_max_entry <= \
159 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530160 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
161 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530162 ((struct wmi_command_debug *)h->log_info. \
163 wmi_command_tx_cmp_log_buf_info.buf) \
164 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
165 p_buf_tail_idx)]. \
166 command = a; \
167 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
168 wmi_command_tx_cmp_log_buf_info.buf) \
169 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
170 p_buf_tail_idx)]. \
171 data, b, wmi_record_max_length); \
172 ((struct wmi_command_debug *)h->log_info. \
173 wmi_command_tx_cmp_log_buf_info.buf) \
174 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
175 p_buf_tail_idx)]. \
176 time = qdf_get_log_timestamp(); \
177 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
178 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530179}
180
Govind Singhecf03cd2016-05-12 12:45:51 +0530181#define WMI_EVENT_RECORD(h, a, b) { \
182 if (wmi_log_max_entry <= \
183 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
184 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
185 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
186 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
187 event = a; \
188 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
189 wmi_event_log_buf_info.buf) \
190 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
191 wmi_record_max_length); \
192 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
193 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530194 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530195 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
196 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530197}
198
Govind Singhecf03cd2016-05-12 12:45:51 +0530199#define WMI_RX_EVENT_RECORD(h, a, b) { \
200 if (wmi_log_max_entry <= \
201 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
202 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
203 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
204 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
205 event = a; \
206 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
207 wmi_rx_event_log_buf_info.buf) \
208 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
209 data, b, wmi_record_max_length); \
210 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
211 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
212 time = qdf_get_log_timestamp(); \
213 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
214 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530215}
Govind Singh6b411b52016-03-06 19:55:02 +0530216
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530217#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530218uint32_t g_wmi_mgmt_command_buf_idx = 0;
219struct
220wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
221
222/* wmi_mgmt commands TX completed */
223uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
224struct wmi_command_debug
225wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
226
227/* wmi_mgmt events when processed */
228uint32_t g_wmi_mgmt_event_buf_idx = 0;
229struct wmi_event_debug
230wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530231#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530232
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530233#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
234 if (wmi_mgmt_log_max_entry <= \
235 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
236 *(h->log_info.wmi_mgmt_command_log_buf_info. \
237 p_buf_tail_idx) = 0; \
238 ((struct wmi_command_debug *)h->log_info. \
239 wmi_mgmt_command_log_buf_info.buf) \
240 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
241 command = a; \
242 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
243 wmi_mgmt_command_log_buf_info.buf) \
244 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
245 data, b, \
246 wmi_record_max_length); \
247 ((struct wmi_command_debug *)h->log_info. \
248 wmi_mgmt_command_log_buf_info.buf) \
249 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
250 time = qdf_get_log_timestamp(); \
251 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
252 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530253}
254
Govind Singhecf03cd2016-05-12 12:45:51 +0530255#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
256 if (wmi_mgmt_log_max_entry <= \
257 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
258 p_buf_tail_idx)) \
259 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
260 p_buf_tail_idx) = 0; \
261 ((struct wmi_command_debug *)h->log_info. \
262 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
263 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
264 p_buf_tail_idx)].command = a; \
265 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
266 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
267 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
268 p_buf_tail_idx)].data, b, \
269 wmi_record_max_length); \
270 ((struct wmi_command_debug *)h->log_info. \
271 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
272 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
273 p_buf_tail_idx)].time = \
274 qdf_get_log_timestamp(); \
275 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
276 p_buf_tail_idx))++; \
277 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530278}
279
Govind Singhecf03cd2016-05-12 12:45:51 +0530280#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
281 if (wmi_mgmt_log_max_entry <= \
282 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
283 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
284 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
285 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
286 .event = a; \
287 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
288 wmi_mgmt_event_log_buf_info.buf) \
289 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
290 data, b, wmi_record_max_length); \
291 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
292 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
293 time = qdf_get_log_timestamp(); \
294 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
295 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530296}
297
Govind Singhecf03cd2016-05-12 12:45:51 +0530298/* These are defined to made it as module param, which can be configured */
299uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
300uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
301uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
302uint32_t wmi_display_size = 100;
303
Govind Singhecf03cd2016-05-12 12:45:51 +0530304/**
305 * wmi_log_init() - Initialize WMI event logging
306 * @wmi_handle: WMI handle.
307 *
308 * Return: Initialization status
309 */
310#ifdef CONFIG_MCL
311static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
312{
313 struct wmi_log_buf_t *cmd_log_buf =
314 &wmi_handle->log_info.wmi_command_log_buf_info;
315 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
316 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
317
318 struct wmi_log_buf_t *event_log_buf =
319 &wmi_handle->log_info.wmi_event_log_buf_info;
320 struct wmi_log_buf_t *rx_event_log_buf =
321 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
322
323 struct wmi_log_buf_t *mgmt_cmd_log_buf =
324 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
325 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
326 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
327 struct wmi_log_buf_t *mgmt_event_log_buf =
328 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
329
330 /* WMI commands */
331 cmd_log_buf->length = 0;
332 cmd_log_buf->buf_tail_idx = 0;
333 cmd_log_buf->buf = wmi_command_log_buffer;
334 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700335 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530336
337 /* WMI commands TX completed */
338 cmd_tx_cmpl_log_buf->length = 0;
339 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
340 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
341 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700342 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530343
344 /* WMI events when processed */
345 event_log_buf->length = 0;
346 event_log_buf->buf_tail_idx = 0;
347 event_log_buf->buf = wmi_event_log_buffer;
348 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700349 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530350
351 /* WMI events when queued */
352 rx_event_log_buf->length = 0;
353 rx_event_log_buf->buf_tail_idx = 0;
354 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
355 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700356 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530357
358 /* WMI Management commands */
359 mgmt_cmd_log_buf->length = 0;
360 mgmt_cmd_log_buf->buf_tail_idx = 0;
361 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
362 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700363 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530364
365 /* WMI Management commands Tx completed*/
366 mgmt_cmd_tx_cmp_log_buf->length = 0;
367 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
368 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
369 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
370 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700371 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530372
373 /* WMI Management events when processed*/
374 mgmt_event_log_buf->length = 0;
375 mgmt_event_log_buf->buf_tail_idx = 0;
376 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
377 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700378 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530379
380 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
381 wmi_handle->log_info.wmi_logging_enable = 1;
382
383 return QDF_STATUS_SUCCESS;
384}
385#else
386static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
387{
388 struct wmi_log_buf_t *cmd_log_buf =
389 &wmi_handle->log_info.wmi_command_log_buf_info;
390 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
391 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
392
393 struct wmi_log_buf_t *event_log_buf =
394 &wmi_handle->log_info.wmi_event_log_buf_info;
395 struct wmi_log_buf_t *rx_event_log_buf =
396 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
397
398 struct wmi_log_buf_t *mgmt_cmd_log_buf =
399 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
400 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
401 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
402 struct wmi_log_buf_t *mgmt_event_log_buf =
403 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
404
405 wmi_handle->log_info.wmi_logging_enable = 0;
406
407 /* WMI commands */
408 cmd_log_buf->length = 0;
409 cmd_log_buf->buf_tail_idx = 0;
410 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
411 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700412 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530413
414 if (!cmd_log_buf->buf) {
415 qdf_print("no memory for WMI command log buffer..\n");
416 return QDF_STATUS_E_NOMEM;
417 }
418 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
419
420 /* WMI commands TX completed */
421 cmd_tx_cmpl_log_buf->length = 0;
422 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
423 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
424 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700425 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530426
427 if (!cmd_tx_cmpl_log_buf->buf) {
428 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
429 return QDF_STATUS_E_NOMEM;
430 }
431 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
432 &cmd_tx_cmpl_log_buf->buf_tail_idx;
433
434 /* WMI events when processed */
435 event_log_buf->length = 0;
436 event_log_buf->buf_tail_idx = 0;
437 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
438 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700439 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530440
441 if (!event_log_buf->buf) {
442 qdf_print("no memory for WMI Event log buffer..\n");
443 return QDF_STATUS_E_NOMEM;
444 }
445 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
446
447 /* WMI events when queued */
448 rx_event_log_buf->length = 0;
449 rx_event_log_buf->buf_tail_idx = 0;
450 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
451 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700452 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530453
454 if (!rx_event_log_buf->buf) {
455 qdf_print("no memory for WMI Event Rx log buffer..\n");
456 return QDF_STATUS_E_NOMEM;
457 }
458 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
459
460 /* WMI Management commands */
461 mgmt_cmd_log_buf->length = 0;
462 mgmt_cmd_log_buf->buf_tail_idx = 0;
463 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700464 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
465 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530466
467 if (!mgmt_cmd_log_buf->buf) {
468 qdf_print("no memory for WMI Management Command log buffer..\n");
469 return QDF_STATUS_E_NOMEM;
470 }
471 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
472
473 /* WMI Management commands Tx completed*/
474 mgmt_cmd_tx_cmp_log_buf->length = 0;
475 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
476 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
477 qdf_mem_malloc(
478 wmi_mgmt_log_max_entry *
479 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700480 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530481
482 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
483 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
484 return QDF_STATUS_E_NOMEM;
485 }
486 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
487 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
488
489 /* WMI Management events when processed*/
490 mgmt_event_log_buf->length = 0;
491 mgmt_event_log_buf->buf_tail_idx = 0;
492
493 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
494 wmi_mgmt_log_max_entry *
495 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700496 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530497
498 if (!mgmt_event_log_buf->buf) {
499 qdf_print("no memory for WMI Management Event log buffer..\n");
500 return QDF_STATUS_E_NOMEM;
501 }
502 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
503
504 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
505 wmi_handle->log_info.wmi_logging_enable = 1;
506
507 return QDF_STATUS_SUCCESS;
508}
509#endif
510
511/**
512 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
513 * event logging
514 * @wmi_handle: WMI handle.
515 *
516 * Return: None
517 */
518#ifndef CONFIG_MCL
519static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
520{
521 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
522 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
523 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
524 qdf_mem_free(
525 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
526 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
527 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
528 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
529 qdf_mem_free(
530 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
531 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
532 qdf_mem_free(
533 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
534 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
535 qdf_mem_free(
536 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
537 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
538 qdf_mem_free(
539 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
540 wmi_handle->log_info.wmi_logging_enable = 0;
541 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
542}
543#else
544static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
545{
546 /* Do Nothing */
547}
548#endif
549
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700550/**
551 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
552 * @log_buffer: the command log buffer metadata of the buffer to print
553 * @count: the maximum number of entries to print
554 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
555 * @print_priv: any data required by the print method, e.g. a file handle
556 *
557 * Return: None
558 */
559static void
560wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
561 qdf_abstract_print *print, void *print_priv)
562{
563 static const int data_len =
564 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
565 char str[128];
566 uint32_t idx;
567
568 if (count > log_buffer->size)
569 count = log_buffer->size;
570 if (count > log_buffer->length)
571 count = log_buffer->length;
572
573 /* subtract count from index, and wrap if necessary */
574 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
575 idx %= log_buffer->size;
576
577 print(print_priv, "Time (seconds) Cmd Id Payload");
578 while (count) {
579 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
580 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700581 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700582 int len = 0;
583 int i;
584
Dustin Brown8ea39122017-04-10 13:26:56 -0700585 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700586 len += scnprintf(str + len, sizeof(str) - len,
587 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700588 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700589 cmd_log->command, cmd_log->command);
590 for (i = 0; i < data_len; ++i) {
591 len += scnprintf(str + len, sizeof(str) - len,
592 "0x%08x ", cmd_log->data[i]);
593 }
594
595 print(print_priv, str);
596
597 --count;
598 ++idx;
599 if (idx >= log_buffer->size)
600 idx = 0;
601 }
602}
603
604/**
605 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
606 * @log_buffer: the event log buffer metadata of the buffer to print
607 * @count: the maximum number of entries to print
608 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
609 * @print_priv: any data required by the print method, e.g. a file handle
610 *
611 * Return: None
612 */
613static void
614wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
615 qdf_abstract_print *print, void *print_priv)
616{
617 static const int data_len =
618 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
619 char str[128];
620 uint32_t idx;
621
622 if (count > log_buffer->size)
623 count = log_buffer->size;
624 if (count > log_buffer->length)
625 count = log_buffer->length;
626
627 /* subtract count from index, and wrap if necessary */
628 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
629 idx %= log_buffer->size;
630
631 print(print_priv, "Time (seconds) Event Id Payload");
632 while (count) {
633 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
634 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700635 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700636 int len = 0;
637 int i;
638
Dustin Brown8ea39122017-04-10 13:26:56 -0700639 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700640 len += scnprintf(str + len, sizeof(str) - len,
641 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700642 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700643 event_log->event, event_log->event);
644 for (i = 0; i < data_len; ++i) {
645 len += scnprintf(str + len, sizeof(str) - len,
646 "0x%08x ", event_log->data[i]);
647 }
648
649 print(print_priv, str);
650
651 --count;
652 ++idx;
653 if (idx >= log_buffer->size)
654 idx = 0;
655 }
656}
657
658inline void
659wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
660 qdf_abstract_print *print, void *print_priv)
661{
662 wmi_print_cmd_log_buffer(
663 &wmi->log_info.wmi_command_log_buf_info,
664 count, print, print_priv);
665}
666
667inline void
668wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
669 qdf_abstract_print *print, void *print_priv)
670{
671 wmi_print_cmd_log_buffer(
672 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
673 count, print, print_priv);
674}
675
676inline void
677wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
678 qdf_abstract_print *print, void *print_priv)
679{
680 wmi_print_cmd_log_buffer(
681 &wmi->log_info.wmi_mgmt_command_log_buf_info,
682 count, print, print_priv);
683}
684
685inline void
686wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
687 qdf_abstract_print *print, void *print_priv)
688{
689 wmi_print_cmd_log_buffer(
690 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
691 count, print, print_priv);
692}
693
694inline void
695wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
696 qdf_abstract_print *print, void *print_priv)
697{
698 wmi_print_event_log_buffer(
699 &wmi->log_info.wmi_event_log_buf_info,
700 count, print, print_priv);
701}
702
703inline void
704wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
705 qdf_abstract_print *print, void *print_priv)
706{
707 wmi_print_event_log_buffer(
708 &wmi->log_info.wmi_rx_event_log_buf_info,
709 count, print, print_priv);
710}
711
712inline void
713wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
714 qdf_abstract_print *print, void *print_priv)
715{
716 wmi_print_event_log_buffer(
717 &wmi->log_info.wmi_mgmt_event_log_buf_info,
718 count, print, print_priv);
719}
720
Govind Singhecf03cd2016-05-12 12:45:51 +0530721#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530722const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530723#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530724const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530725#endif
726
727/* debugfs routines*/
728
729/**
730 * debug_wmi_##func_base##_show() - debugfs functions to display content of
731 * command and event buffers. Macro uses max buffer length to display
732 * buffer when it is wraparound.
733 *
734 * @m: debugfs handler to access wmi_handle
735 * @v: Variable arguments (not used)
736 *
737 * Return: Length of characters printed
738 */
739#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
740 static int debug_wmi_##func_base##_show(struct seq_file *m, \
741 void *v) \
742 { \
743 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
744 struct wmi_log_buf_t *wmi_log = \
745 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
746 int pos, nread, outlen; \
747 int i; \
748 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530749 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
750 if (!wmi_log->length) { \
751 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530752 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530753 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530754 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530755 \
756 if (wmi_log->length <= wmi_ring_size) \
757 nread = wmi_log->length; \
758 else \
759 nread = wmi_ring_size; \
760 \
761 if (*(wmi_log->p_buf_tail_idx) == 0) \
762 /* tail can be 0 after wrap-around */ \
763 pos = wmi_ring_size - 1; \
764 else \
765 pos = *(wmi_log->p_buf_tail_idx) - 1; \
766 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530767 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530768 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530769 while (nread--) { \
770 struct wmi_command_debug *wmi_record; \
771 \
772 wmi_record = (struct wmi_command_debug *) \
773 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530774 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530775 (wmi_record->command)); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530776 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530777 for (i = 0; i < (wmi_record_max_length/ \
778 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530779 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530780 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530781 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530782 \
783 if (pos == 0) \
784 pos = wmi_ring_size - 1; \
785 else \
786 pos--; \
787 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530788 return outlen; \
789 } \
790
791#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
792 static int debug_wmi_##func_base##_show(struct seq_file *m, \
793 void *v) \
794 { \
795 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
796 struct wmi_log_buf_t *wmi_log = \
797 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
798 int pos, nread, outlen; \
799 int i; \
800 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530801 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
802 if (!wmi_log->length) { \
803 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530804 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530805 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530806 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530807 \
808 if (wmi_log->length <= wmi_ring_size) \
809 nread = wmi_log->length; \
810 else \
811 nread = wmi_ring_size; \
812 \
813 if (*(wmi_log->p_buf_tail_idx) == 0) \
814 /* tail can be 0 after wrap-around */ \
815 pos = wmi_ring_size - 1; \
816 else \
817 pos = *(wmi_log->p_buf_tail_idx) - 1; \
818 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530819 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530820 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530821 while (nread--) { \
822 struct wmi_event_debug *wmi_record; \
823 \
824 wmi_record = (struct wmi_event_debug *) \
825 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530826 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +0530827 (wmi_record->event)); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530828 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530829 for (i = 0; i < (wmi_record_max_length/ \
830 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530831 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530832 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530833 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530834 \
835 if (pos == 0) \
836 pos = wmi_ring_size - 1; \
837 else \
838 pos--; \
839 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530840 return outlen; \
841 }
842
843GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
844GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
845GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
846GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
847GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
848GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
849 wmi_display_size);
850GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
851
852/**
853 * debug_wmi_enable_show() - debugfs functions to display enable state of
854 * wmi logging feature.
855 *
856 * @m: debugfs handler to access wmi_handle
857 * @v: Variable arguments (not used)
858 *
859 * Return: always 1
860 */
861static int debug_wmi_enable_show(struct seq_file *m, void *v)
862{
863 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
864
Pratik Gandhi795ab912017-05-03 20:15:50 +0530865 return wmi_bp_seq_printf(m, "%d\n",
866 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530867}
868
869/**
870 * debug_wmi_log_size_show() - debugfs functions to display configured size of
871 * wmi logging command/event buffer and management command/event buffer.
872 *
873 * @m: debugfs handler to access wmi_handle
874 * @v: Variable arguments (not used)
875 *
876 * Return: Length of characters printed
877 */
878static int debug_wmi_log_size_show(struct seq_file *m, void *v)
879{
880
Pratik Gandhi795ab912017-05-03 20:15:50 +0530881 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
882 wmi_log_max_entry);
883 return wmi_bp_seq_printf(m,
884 "WMI management command/events log max size:%d\n",
885 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530886}
887
888/**
889 * debug_wmi_##func_base##_write() - debugfs functions to clear
890 * wmi logging command/event buffer and management command/event buffer.
891 *
892 * @file: file handler to access wmi_handle
893 * @buf: received data buffer
894 * @count: length of received buffer
895 * @ppos: Not used
896 *
897 * Return: count
898 */
899#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
900 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
901 const char __user *buf, \
902 size_t count, loff_t *ppos) \
903 { \
904 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530905 wmi_unified_t wmi_handle = \
906 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530907 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
908 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530909 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530910 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530911 if ((!buf) || (count > 50)) \
912 return -EFAULT; \
913 \
914 if (copy_from_user(locbuf, buf, count)) \
915 return -EFAULT; \
916 \
917 ret = sscanf(locbuf, "%d", &k); \
918 if ((ret != 1) || (k != 0)) { \
Govind Singhecf03cd2016-05-12 12:45:51 +0530919 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
920 return -EINVAL; \
921 } \
922 \
923 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
924 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
925 sizeof(struct wmi_record_type)); \
926 wmi_log->length = 0; \
927 *(wmi_log->p_buf_tail_idx) = 0; \
928 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
929 \
930 return count; \
931 }
932
933GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
934 wmi_command_debug);
935GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
936 wmi_command_debug);
937GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
938 wmi_event_debug);
939GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
940 wmi_event_debug);
941GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
942 wmi_command_debug);
943GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
944 wmi_mgmt_log_max_entry, wmi_command_debug);
945GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
946 wmi_event_debug);
947
948/**
949 * debug_wmi_enable_write() - debugfs functions to enable/disable
950 * wmi logging feature.
951 *
952 * @file: file handler to access wmi_handle
953 * @buf: received data buffer
954 * @count: length of received buffer
955 * @ppos: Not used
956 *
957 * Return: count
958 */
959static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
960 size_t count, loff_t *ppos)
961{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530962 wmi_unified_t wmi_handle =
963 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530964 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530965 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530966
Pratik Gandhi795ab912017-05-03 20:15:50 +0530967 if ((!buf) || (count > 50))
968 return -EFAULT;
969
970 if (copy_from_user(locbuf, buf, count))
971 return -EFAULT;
972
973 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530974 if ((ret != 1) || ((k != 0) && (k != 1)))
975 return -EINVAL;
976
977 wmi_handle->log_info.wmi_logging_enable = k;
978 return count;
979}
980
981/**
982 * debug_wmi_log_size_write() - reserved.
983 *
984 * @file: file handler to access wmi_handle
985 * @buf: received data buffer
986 * @count: length of received buffer
987 * @ppos: Not used
988 *
989 * Return: count
990 */
991static ssize_t debug_wmi_log_size_write(struct file *file,
992 const char __user *buf, size_t count, loff_t *ppos)
993{
994 return -EINVAL;
995}
996
997/* Structure to maintain debug information */
998struct wmi_debugfs_info {
999 const char *name;
1000 struct dentry *de[MAX_WMI_INSTANCES];
1001 const struct file_operations *ops;
1002};
1003
1004#define DEBUG_FOO(func_base) { .name = #func_base, \
1005 .ops = &debug_##func_base##_ops }
1006
1007/**
1008 * debug_##func_base##_open() - Open debugfs entry for respective command
1009 * and event buffer.
1010 *
1011 * @inode: node for debug dir entry
1012 * @file: file handler
1013 *
1014 * Return: open status
1015 */
1016#define GENERATE_DEBUG_STRUCTS(func_base) \
1017 static int debug_##func_base##_open(struct inode *inode, \
1018 struct file *file) \
1019 { \
1020 return single_open(file, debug_##func_base##_show, \
1021 inode->i_private); \
1022 } \
1023 \
1024 \
1025 static struct file_operations debug_##func_base##_ops = { \
1026 .open = debug_##func_base##_open, \
1027 .read = seq_read, \
1028 .llseek = seq_lseek, \
1029 .write = debug_##func_base##_write, \
1030 .release = single_release, \
1031 };
1032
1033GENERATE_DEBUG_STRUCTS(wmi_command_log);
1034GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1035GENERATE_DEBUG_STRUCTS(wmi_event_log);
1036GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1037GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1038GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1039GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1040GENERATE_DEBUG_STRUCTS(wmi_enable);
1041GENERATE_DEBUG_STRUCTS(wmi_log_size);
1042
1043struct wmi_debugfs_info wmi_debugfs_infos[] = {
1044 DEBUG_FOO(wmi_command_log),
1045 DEBUG_FOO(wmi_command_tx_cmp_log),
1046 DEBUG_FOO(wmi_event_log),
1047 DEBUG_FOO(wmi_rx_event_log),
1048 DEBUG_FOO(wmi_mgmt_command_log),
1049 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1050 DEBUG_FOO(wmi_mgmt_event_log),
1051 DEBUG_FOO(wmi_enable),
1052 DEBUG_FOO(wmi_log_size),
1053};
1054
1055#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1056 sizeof(wmi_debugfs_infos[0]))
1057
1058/**
1059 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1060 *
1061 * @wmi_handle: wmi handle
1062 * @par_entry: debug directory entry
1063 * @id: Index to debug info data array
1064 *
1065 * Return: none
1066 */
1067static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1068 struct dentry *par_entry, int id)
1069{
1070 int i;
1071
1072 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1073 goto out;
1074
1075 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1076
1077 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1078 wmi_debugfs_infos[i].name, 0644, par_entry,
1079 wmi_handle, wmi_debugfs_infos[i].ops);
1080
1081 if (wmi_debugfs_infos[i].de[id] == NULL) {
1082 qdf_print("%s: debug Entry creation failed!\n",
1083 __func__);
1084 goto out;
1085 }
1086 }
1087
1088 return;
1089
1090out:
1091 qdf_print("%s: debug Entry creation failed!\n", __func__);
1092 wmi_log_buffer_free(wmi_handle);
1093 return;
1094}
1095
1096/**
1097 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301098 * @wmi_handle: wmi handle
1099 * @dentry: debugfs directory entry
1100 * @id: Index to debug info data array
1101 *
1102 * Return: none
1103 */
Govind Singh06c18392016-06-10 10:33:19 +05301104static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301105{
1106 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301107 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301108 int id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301109
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301110 if (!wmi_handle->log_info.wmi_instance_id)
1111 return;
1112
1113 id = wmi_handle->log_info.wmi_instance_id - 1;
Govind Singhecf03cd2016-05-12 12:45:51 +05301114 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1115 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1116 if (wmi_debugfs_infos[i].de[id])
1117 wmi_debugfs_infos[i].de[id] = NULL;
1118 }
1119 }
1120
1121 if (dentry)
1122 debugfs_remove_recursive(dentry);
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301123
1124 if (wmi_handle->log_info.wmi_instance_id)
1125 wmi_handle->log_info.wmi_instance_id--;
Govind Singhecf03cd2016-05-12 12:45:51 +05301126}
1127
1128/**
1129 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1130 * create debugfs enteries.
1131 *
1132 * @h: wmi handler
1133 *
1134 * Return: init status
1135 */
1136static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1137{
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301138 int wmi_index = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301139
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301140 if (wmi_index < MAX_WMI_INSTANCES) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301141 wmi_handle->log_info.wmi_log_debugfs_dir =
1142 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1143
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301144 if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
1145 qdf_print("error while creating debugfs dir for %s\n",
1146 debugfs_dir[wmi_index]);
1147 return QDF_STATUS_E_FAILURE;
1148 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301149
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301150 wmi_debugfs_create(wmi_handle,
1151 wmi_handle->log_info.wmi_log_debugfs_dir,
1152 wmi_index);
1153 wmi_handle->log_info.wmi_instance_id++;
1154 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301155
1156 return QDF_STATUS_SUCCESS;
1157}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001158
1159/**
1160 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1161 *
1162 * @wmi_handle: wmi handle
1163 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001164 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001165 * @vdev_id: vdev id
1166 * @chanfreq: channel frequency
1167 *
1168 * Return: none
1169 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301170void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001171 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001172{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301173
1174 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1175
1176 data[0] = ((struct wmi_command_header *)header)->type;
1177 data[1] = ((struct wmi_command_header *)header)->sub_type;
1178 data[2] = vdev_id;
1179 data[3] = chanfreq;
1180
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001181 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1182
Rakesh Pillai05110462017-12-27 14:08:59 +05301183 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001184
1185 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1186}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001187#else
1188/**
1189 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1190 * @wmi_handle: wmi handle
1191 * @dentry: debugfs directory entry
1192 * @id: Index to debug info data array
1193 *
1194 * Return: none
1195 */
Govind Singh06c18392016-06-10 10:33:19 +05301196static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301197void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001198 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301199static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301200#endif /*WMI_INTERFACE_EVENT_LOGGING */
1201
Govind Singh6b411b52016-03-06 19:55:02 +05301202int wmi_get_host_credits(wmi_unified_t wmi_handle);
1203/* WMI buffer APIs */
1204
1205#ifdef MEMORY_DEBUG
1206wmi_buf_t
1207wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301208 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301209{
1210 wmi_buf_t wmi_buf;
1211
1212 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301213 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301214 return NULL;
1215 }
1216
Govind Singhb53420c2016-03-09 14:32:57 +05301217 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301218 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1219 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1220 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301221
1222 if (!wmi_buf)
1223 return NULL;
1224
1225 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301226 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301227
1228 /*
1229 * Set the length of the buffer to match the allocation size.
1230 */
Govind Singhb53420c2016-03-09 14:32:57 +05301231 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301232
1233 return wmi_buf;
1234}
1235
1236void wmi_buf_free(wmi_buf_t net_buf)
1237{
Govind Singhb53420c2016-03-09 14:32:57 +05301238 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301239}
1240#else
1241wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1242{
1243 wmi_buf_t wmi_buf;
1244
1245 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301246 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301247 return NULL;
1248 }
1249
Govind Singhb53420c2016-03-09 14:32:57 +05301250 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301251 WMI_MIN_HEAD_ROOM, 4, false);
1252 if (!wmi_buf)
1253 return NULL;
1254
1255 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301256 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301257
1258 /*
1259 * Set the length of the buffer to match the allocation size.
1260 */
Govind Singhb53420c2016-03-09 14:32:57 +05301261 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301262 return wmi_buf;
1263}
1264
1265void wmi_buf_free(wmi_buf_t net_buf)
1266{
Govind Singhb53420c2016-03-09 14:32:57 +05301267 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301268}
1269#endif
1270
1271/**
1272 * wmi_get_max_msg_len() - get maximum WMI message length
1273 * @wmi_handle: WMI handle.
1274 *
1275 * This function returns the maximum WMI message length
1276 *
1277 * Return: maximum WMI message length
1278 */
1279uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1280{
1281 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1282}
1283
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301284#ifndef WMI_CMD_STRINGS
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301285static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301286{
1287 return "Invalid WMI cmd";
1288}
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301289
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301290#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301291
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301292#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301293static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1294{
1295 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1296 wmi_id_to_name(cmd_id), cmd_id, tag);
1297}
1298
Govind Singh6b411b52016-03-06 19:55:02 +05301299/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301300 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1301 * @cmd_id: command to check
1302 *
1303 * Return: true if the command is part of the resume sequence.
1304 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301305static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301306{
1307 switch (cmd_id) {
1308 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1309 case WMI_PDEV_RESUME_CMDID:
1310 return true;
1311
1312 default:
1313 return false;
1314 }
1315}
1316#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301317static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301318{
1319 return false;
1320}
1321#endif
1322
1323/**
Govind Singh6b411b52016-03-06 19:55:02 +05301324 * wmi_unified_cmd_send() - WMI command API
1325 * @wmi_handle: handle to wmi
1326 * @buf: wmi buf
1327 * @len: wmi buffer length
1328 * @cmd_id: wmi command id
1329 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001330 * Note, it is NOT safe to access buf after calling this function!
1331 *
Govind Singh6b411b52016-03-06 19:55:02 +05301332 * Return: 0 on success
1333 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001334QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1335 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301336{
1337 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301338 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301339 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301340
1341 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301342 htc_tag =
1343 (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
1344 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301345 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301346 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301347 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301348 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301349 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301350 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301351 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301352 if (wmi_handle->wmi_stopinprogress) {
1353 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1354 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001355 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301356 }
Govind Singh6b411b52016-03-06 19:55:02 +05301357
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301358#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301359 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301360 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301361 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301362
1363 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301364 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301365 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301366 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301367 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301368 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301369 }
1370 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301371#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301372
Govind Singhb53420c2016-03-09 14:32:57 +05301373 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1374 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301375 "%s, Failed to send cmd %x, no memory",
1376 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301377 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301378 }
1379
Govind Singhb53420c2016-03-09 14:32:57 +05301380 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301381
Govind Singhb53420c2016-03-09 14:32:57 +05301382 qdf_atomic_inc(&wmi_handle->pending_cmds);
1383 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1384 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301385 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301386 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301387 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301388 qdf_atomic_dec(&wmi_handle->pending_cmds);
1389 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301390 "%s: MAX %d WMI Pending cmds reached.", __func__,
1391 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301392 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301393 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301394 }
1395
Govind Singhb53420c2016-03-09 14:32:57 +05301396 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301397 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301398 qdf_atomic_dec(&wmi_handle->pending_cmds);
1399 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301400 "%s, Failed to alloc htc packet %x, no memory",
1401 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301402 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301403 }
1404
1405 SET_HTC_PACKET_INFO_TX(pkt,
1406 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301407 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301408 wmi_handle->wmi_endpoint_id, htc_tag);
1409
1410 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301411#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301412 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301413#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301414
1415#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301416 if (wmi_handle->log_info.wmi_logging_enable) {
1417 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301418 /*Record 16 bytes of WMI cmd data -
1419 * * exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301420 if (wmi_handle->ops->is_management_record(cmd_id)) {
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301421 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301422 qdf_nbuf_data(buf) +
1423 wmi_handle->log_info.buf_offset_command);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301424 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05301425 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301426 qdf_nbuf_data(buf) +
1427 wmi_handle->log_info.buf_offset_command);
Govind Singhecf03cd2016-05-12 12:45:51 +05301428 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301429 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1430 }
Govind Singh6b411b52016-03-06 19:55:02 +05301431#endif
1432
1433 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1434
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301435 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301436 qdf_atomic_dec(&wmi_handle->pending_cmds);
1437 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301438 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07001439 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301440 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05301441 }
Govind Singh6b411b52016-03-06 19:55:02 +05301442
Govind Singhb53420c2016-03-09 14:32:57 +05301443 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301444}
1445
1446/**
1447 * wmi_unified_get_event_handler_ix() - gives event handler's index
1448 * @wmi_handle: handle to wmi
1449 * @event_id: wmi event id
1450 *
1451 * Return: event handler's index
1452 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001453static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
1454 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301455{
1456 uint32_t idx = 0;
1457 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301458 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301459
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301460 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05301461 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1462 if (wmi_handle->event_id[idx] == event_id &&
1463 wmi_handle->event_handler[idx] != NULL) {
1464 return idx;
1465 }
1466 }
1467
1468 return invalid_idx;
1469}
1470
1471/**
Soumya Bhat488092d2017-03-22 14:41:01 +05301472 * wmi_unified_register_event() - register wmi event handler
1473 * @wmi_handle: handle to wmi
1474 * @event_id: wmi event id
1475 * @handler_func: wmi event handler function
1476 *
1477 * Return: 0 on success
1478 */
1479int wmi_unified_register_event(wmi_unified_t wmi_handle,
1480 uint32_t event_id,
1481 wmi_unified_event_handler handler_func)
1482{
1483 uint32_t idx = 0;
1484 uint32_t evt_id;
1485 struct wmi_soc *soc = wmi_handle->soc;
1486
1487 if (event_id >= wmi_events_max ||
1488 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1489 qdf_print("%s: Event id %d is unavailable\n",
1490 __func__, event_id);
1491 return QDF_STATUS_E_FAILURE;
1492 }
1493 evt_id = wmi_handle->wmi_events[event_id];
1494 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1495 qdf_print("%s : event handler already registered 0x%x\n",
1496 __func__, evt_id);
1497 return QDF_STATUS_E_FAILURE;
1498 }
1499 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
1500 qdf_print("%s : no more event handlers 0x%x\n",
1501 __func__, evt_id);
1502 return QDF_STATUS_E_FAILURE;
1503 }
1504 idx = soc->max_event_idx;
1505 wmi_handle->event_handler[idx] = handler_func;
1506 wmi_handle->event_id[idx] = evt_id;
1507 qdf_spin_lock_bh(&soc->ctx_lock);
1508 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
1509 qdf_spin_unlock_bh(&soc->ctx_lock);
1510 soc->max_event_idx++;
1511
1512 return 0;
1513}
1514
1515/**
Govind Singh6b411b52016-03-06 19:55:02 +05301516 * wmi_unified_register_event_handler() - register wmi event handler
1517 * @wmi_handle: handle to wmi
1518 * @event_id: wmi event id
1519 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301520 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301521 *
Soumya Bhat488092d2017-03-22 14:41:01 +05301522 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05301523 * Return: 0 on success
1524 */
1525int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301526 wmi_conv_event_id event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301527 wmi_unified_event_handler handler_func,
1528 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301529{
1530 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301531 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301532 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301533
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301534 if (event_id >= wmi_events_max ||
1535 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1536 qdf_print("%s: Event id %d is unavailable\n",
1537 __func__, event_id);
1538 return QDF_STATUS_E_FAILURE;
1539 }
1540 evt_id = wmi_handle->wmi_events[event_id];
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301541
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301542 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1543 qdf_print("%s : event handler already registered 0x%x\n",
1544 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301545 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301546 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301547 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301548 qdf_print("%s : no more event handlers 0x%x\n",
1549 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301550 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301551 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07001552 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
1553 "Registered event handler for event 0x%8x\n", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301554 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301555 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301556 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301557 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301558 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301559 qdf_spin_unlock_bh(&soc->ctx_lock);
1560 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05301561
1562 return 0;
1563}
1564
1565/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301566 * wmi_unified_unregister_event() - unregister wmi event handler
1567 * @wmi_handle: handle to wmi
1568 * @event_id: wmi event id
1569 *
1570 * Return: 0 on success
1571 */
1572int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
1573 uint32_t event_id)
1574{
1575 uint32_t idx = 0;
1576 uint32_t evt_id;
1577 struct wmi_soc *soc = wmi_handle->soc;
1578
1579 if (event_id >= wmi_events_max ||
1580 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1581 qdf_print("%s: Event id %d is unavailable\n",
1582 __func__, event_id);
1583 return QDF_STATUS_E_FAILURE;
1584 }
1585 evt_id = wmi_handle->wmi_events[event_id];
1586
1587 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
1588 if (idx == -1) {
1589 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1590 __func__, evt_id);
1591 return QDF_STATUS_E_FAILURE;
1592 }
1593 wmi_handle->event_handler[idx] = NULL;
1594 wmi_handle->event_id[idx] = 0;
1595 --soc->max_event_idx;
1596 wmi_handle->event_handler[idx] =
1597 wmi_handle->event_handler[soc->max_event_idx];
1598 wmi_handle->event_id[idx] =
1599 wmi_handle->event_id[soc->max_event_idx];
1600
1601 return 0;
1602}
1603
1604/**
Govind Singh6b411b52016-03-06 19:55:02 +05301605 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1606 * @wmi_handle: handle to wmi
1607 * @event_id: wmi event id
1608 *
1609 * Return: 0 on success
1610 */
1611int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301612 wmi_conv_event_id event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301613{
1614 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301615 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301616 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301617
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301618 if (event_id >= wmi_events_max ||
1619 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1620 qdf_print("%s: Event id %d is unavailable\n",
1621 __func__, event_id);
1622 return QDF_STATUS_E_FAILURE;
1623 }
1624 evt_id = wmi_handle->wmi_events[event_id];
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301625
1626 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301627 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301628 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1629 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301630 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301631 }
1632 wmi_handle->event_handler[idx] = NULL;
1633 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301634 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301635 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301636 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301637 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301638 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301639
1640 return 0;
1641}
1642
1643/**
Govind Singhd52faac2016-03-09 12:03:29 +05301644 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301645 * @wmi_handle: handle to wmi
1646 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301647 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301648 *
Govind Singhd52faac2016-03-09 12:03:29 +05301649 * Event process by below function will be in default caller context.
1650 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301651 *
1652 * Return: none
1653 */
Govind Singhd52faac2016-03-09 12:03:29 +05301654static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1655 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301656{
1657 wmi_buf_t evt_buf;
1658 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1659
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301660#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301661 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1662 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1663#else
Govind Singh5eb51532016-03-09 11:34:12 +05301664 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301665 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301666#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301667
Govind Singh6b411b52016-03-06 19:55:02 +05301668 return;
1669}
1670
1671/**
1672 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1673 * @wmi_handle: handle to wmi
1674 * @htc_packet: pointer to htc packet
1675 *
1676 * Event process by below function will be in worker thread context.
1677 * Use this method for events which are not critical and not
1678 * handled in protocol stack.
1679 *
1680 * Return: none
1681 */
1682static void wmi_process_fw_event_worker_thread_ctx
1683 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1684{
1685 wmi_buf_t evt_buf;
Govind Singh6b411b52016-03-06 19:55:02 +05301686
1687 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singh6b411b52016-03-06 19:55:02 +05301688
Govind Singhb53420c2016-03-09 14:32:57 +05301689 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1690 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1691 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001692 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
1693 &wmi_handle->rx_event_work);
1694
Govind Singh6b411b52016-03-06 19:55:02 +05301695 return;
1696}
1697
1698/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301699 * wmi_get_pdev_ep: Get wmi handle based on endpoint
1700 * @soc: handle to wmi soc
1701 * @ep: endpoint id
1702 *
1703 * Return: none
1704 */
1705static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
1706 HTC_ENDPOINT_ID ep)
1707{
1708 uint32_t i;
1709
1710 for (i = 0; i < WMI_MAX_RADIOS; i++)
1711 if (soc->wmi_endpoint_id[i] == ep)
1712 break;
1713
1714 if (i == WMI_MAX_RADIOS)
1715 return NULL;
1716
1717 return soc->wmi_pdev[i];
1718}
1719
1720/**
Govind Singhd52faac2016-03-09 12:03:29 +05301721 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301722 * @ctx: handle to wmi
1723 * @htc_packet: pointer to htc packet
1724 *
Govind Singh6b411b52016-03-06 19:55:02 +05301725 * Return: none
1726 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001727static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301728{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301729 struct wmi_soc *soc = (struct wmi_soc *) ctx;
1730 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05301731 wmi_buf_t evt_buf;
1732 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301733 uint32_t idx = 0;
1734 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301735
1736 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301737
1738 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
1739 if (wmi_handle == NULL) {
1740 qdf_print
1741 ("%s :unable to get wmi_handle to Endpoint %d\n",
1742 __func__, htc_packet->Endpoint);
1743 qdf_nbuf_free(evt_buf);
1744 return;
1745 }
1746
Govind Singhb53420c2016-03-09 14:32:57 +05301747 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301748 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301749 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05301750 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
1751 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301752 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301753 return;
1754 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301755 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301756 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301757 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301758
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001759#ifdef WMI_INTERFACE_EVENT_LOGGING
1760 if (wmi_handle->log_info.wmi_logging_enable) {
1761 uint8_t *data;
1762 data = qdf_nbuf_data(evt_buf);
1763
1764 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1765 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05301766 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
1767 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001768 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1769 }
1770#endif
1771
Govind Singhd52faac2016-03-09 12:03:29 +05301772 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301773 wmi_process_fw_event_worker_thread_ctx
1774 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301775 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1776 wmi_process_fw_event_default_ctx
1777 (wmi_handle, htc_packet, exec_ctx);
1778 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05301779 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
1780 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301781 }
Govind Singhd52faac2016-03-09 12:03:29 +05301782
Govind Singh6b411b52016-03-06 19:55:02 +05301783}
1784
1785/**
1786 * wmi_process_fw_event() - process any fw event
1787 * @wmi_handle: wmi handle
1788 * @evt_buf: fw event buffer
1789 *
Govind Singhd52faac2016-03-09 12:03:29 +05301790 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301791 *
1792 * Return: none
1793 */
1794void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1795{
1796 __wmi_control_rx(wmi_handle, evt_buf);
1797}
1798
1799/**
1800 * __wmi_control_rx() - process serialize wmi event callback
1801 * @wmi_handle: wmi handle
1802 * @evt_buf: fw event buffer
1803 *
1804 * Return: none
1805 */
1806void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1807{
1808 uint32_t id;
1809 uint8_t *data;
1810 uint32_t len;
1811 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301812#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301813 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301814#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301815 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301816
Govind Singhb53420c2016-03-09 14:32:57 +05301817 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301818
Govind Singhb53420c2016-03-09 14:32:57 +05301819 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05301820 goto end;
1821
Govind Singhb53420c2016-03-09 14:32:57 +05301822 data = qdf_nbuf_data(evt_buf);
1823 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301824
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301825#ifndef WMI_NON_TLV_SUPPORT
1826 if (wmi_handle->target_type == WMI_TLV_TARGET) {
1827 /* Validate and pad(if necessary) the TLVs */
1828 tlv_ok_status =
1829 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05301830 data, len, id,
1831 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301832 if (tlv_ok_status != 0) {
1833 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1834 "%s: Error: id=0x%d, wmitlv check status=%d\n",
1835 __func__, id, tlv_ok_status);
1836 goto end;
1837 }
Govind Singh6b411b52016-03-06 19:55:02 +05301838 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301839#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301840
Govind Singhd52faac2016-03-09 12:03:29 +05301841 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
1842 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05301843 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301844 "%s : event handler is not registered: event id 0x%x\n",
1845 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05301846 goto end;
1847 }
Govind Singhd52faac2016-03-09 12:03:29 +05301848#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301849 if (wmi_handle->log_info.wmi_logging_enable) {
1850 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1851 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301852 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05301853 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
1854 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301855 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05301856 WMI_EVENT_RECORD(wmi_handle, id, data +
1857 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301858 }
1859 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301860 }
Govind Singhd52faac2016-03-09 12:03:29 +05301861#endif
Adil Saeed Musthafa5ffc0c22017-07-30 09:52:43 -07001862 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
1863 "Calling handler for WMI Event ID:%x\n", id);
Govind Singhd52faac2016-03-09 12:03:29 +05301864 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301865 if (wmi_handle->target_type == WMI_TLV_TARGET)
1866 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1867 wmi_cmd_struct_ptr, len);
1868 else
1869 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1870 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05301871
Govind Singh6b411b52016-03-06 19:55:02 +05301872end:
Govind Singhd52faac2016-03-09 12:03:29 +05301873 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301874#ifndef WMI_NON_TLV_SUPPORT
1875 if (wmi_handle->target_type == WMI_TLV_TARGET)
1876 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
1877#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301878
Govind Singhb53420c2016-03-09 14:32:57 +05301879 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301880
Govind Singh6b411b52016-03-06 19:55:02 +05301881}
1882
Govind Singh97b8e7c2017-09-07 18:23:39 +05301883#define WMI_WQ_WD_TIMEOUT (10 * 1000) /* 10s */
1884
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05301885static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05301886{
1887 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1888 "%s: Message type %x has exceeded its alloted time of %ds",
1889 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
1890}
1891
1892#ifdef CONFIG_SLUB_DEBUG_ON
1893static void wmi_workqueue_watchdog_bite(void *arg)
1894{
Govind Singhc646e102017-11-21 10:53:40 +05301895 struct wmi_wq_dbg_info *info = arg;
1896
1897 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
1898 qdf_print_thread_trace(info->task);
1899
Govind Singh97b8e7c2017-09-07 18:23:39 +05301900 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1901 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
1902 QDF_BUG(0);
1903}
1904#else
1905static inline void wmi_workqueue_watchdog_bite(void *arg)
1906{
Govind Singhc646e102017-11-21 10:53:40 +05301907 struct wmi_wq_dbg_info *info = arg;
1908
1909 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301910}
1911#endif
1912
Govind Singh6b411b52016-03-06 19:55:02 +05301913/**
1914 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001915 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05301916 *
1917 * This function process any fw event to serialize it through rx worker thread.
1918 *
1919 * Return: none
1920 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001921static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05301922{
Govind Singh6b411b52016-03-06 19:55:02 +05301923 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001924 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05301925 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05301926 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05301927
Govind Singh97b8e7c2017-09-07 18:23:39 +05301928 /* initialize WMI workqueue watchdog timer */
1929 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05301930 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05301931 qdf_spin_lock_bh(&wmi->eventq_lock);
1932 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1933 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301934 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05301935 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05301936 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05301937 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05301938 info.wmi_wq = wmi->wmi_rx_work_queue;
1939 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05301940 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301941 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05301942 qdf_spin_lock_bh(&wmi->eventq_lock);
1943 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1944 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301945 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05301946 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05301947}
1948
Govind Singh6b411b52016-03-06 19:55:02 +05301949#ifdef FEATURE_RUNTIME_PM
1950/**
1951 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
1952 * @wmi_handle: wmi context
1953 */
Govind Singhd52faac2016-03-09 12:03:29 +05301954static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301955{
Govind Singhb53420c2016-03-09 14:32:57 +05301956 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05301957}
Govind Singhd52faac2016-03-09 12:03:29 +05301958
1959/**
1960 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
1961 * @wmi_handle: wmi context
1962 * @val: runtime pm progress flag
1963 */
1964void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
1965{
Govind Singhb53420c2016-03-09 14:32:57 +05301966 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05301967}
1968
1969/**
1970 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
1971 * @wmi_handle: wmi context
1972 */
1973inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
1974{
Govind Singhb53420c2016-03-09 14:32:57 +05301975 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05301976}
Govind Singh6b411b52016-03-06 19:55:02 +05301977#else
Govind Singhd52faac2016-03-09 12:03:29 +05301978static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301979{
1980}
1981#endif
1982
1983/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301984 * wmi_unified_get_soc_handle: Get WMI SoC handle
1985 * @param wmi_handle: WMI context got from wmi_attach
1986 *
1987 * return: Pointer to Soc handle
1988 */
1989void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
1990{
1991 return wmi_handle->soc;
1992}
1993
1994/**
1995 * wmi_interface_logging_init: Interface looging init
1996 * @param wmi_handle: Pointer to wmi handle object
1997 *
1998 * return: None
1999 */
2000#ifdef WMI_INTERFACE_EVENT_LOGGING
2001static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2002{
2003 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2004 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2005 wmi_debugfs_init(wmi_handle);
2006 }
2007}
2008#else
2009void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2010{
2011}
2012#endif
2013
2014/**
2015 * wmi_target_params_init: Target specific params init
2016 * @param wmi_soc: Pointer to wmi soc object
2017 * @param wmi_handle: Pointer to wmi handle object
2018 *
2019 * return: None
2020 */
2021#ifndef CONFIG_MCL
2022static inline void wmi_target_params_init(struct wmi_soc *soc,
2023 struct wmi_unified *wmi_handle)
2024{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302025 wmi_handle->pdev_param = soc->pdev_param;
2026 wmi_handle->vdev_param = soc->vdev_param;
2027 wmi_handle->services = soc->services;
2028}
2029#else
2030static inline void wmi_target_params_init(struct wmi_soc *soc,
2031 struct wmi_unified *wmi_handle)
2032{
2033}
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) {
2055 qdf_print("allocation of wmi handle failed %zu\n",
2056 sizeof(struct wmi_unified));
2057 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);
2077 wmi_interface_logging_init(wmi_handle);
2078 qdf_atomic_init(&wmi_handle->pending_cmds);
2079 qdf_atomic_init(&wmi_handle->is_target_suspended);
2080 wmi_handle->target_type = soc->target_type;
2081 wmi_handle->soc = soc;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002082
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302083 soc->wmi_pdev[pdev_idx] = wmi_handle;
2084 } else
2085 wmi_handle = soc->wmi_pdev[pdev_idx];
2086
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302087 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302088 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2089 wmi_handle->htc_handle = soc->htc_handle;
2090 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302091
2092 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002093
2094error:
2095 qdf_mem_free(wmi_handle);
2096
2097 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302098}
2099
2100/**
Govind Singh6b411b52016-03-06 19:55:02 +05302101 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302102 * @scn_handle: handle to SCN
2103 * @osdev: OS device context
2104 * @target_type: TLV or not-TLV based target
2105 * @use_cookie: cookie based allocation enabled/disabled
2106 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302107 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302108 *
2109 * @Return: wmi handle.
2110 */
Govind Singhc458f382016-02-04 18:42:30 +05302111void *wmi_unified_attach(void *scn_handle,
2112 osdev_t osdev, enum wmi_target_type target_type,
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302113 bool use_cookie, struct wmi_rx_ops *rx_ops,
2114 struct wlan_objmgr_psoc *psoc)
Govind Singh6b411b52016-03-06 19:55:02 +05302115{
2116 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302117 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302118
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302119 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2120 if (soc == NULL) {
2121 qdf_print("Allocation of wmi_soc failed %zu\n",
2122 sizeof(struct wmi_soc));
2123 return NULL;
2124 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302125
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302126 wmi_handle =
2127 (struct wmi_unified *) qdf_mem_malloc(
2128 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302129 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302130 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302131 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302132 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302133 return NULL;
2134 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302135 wmi_handle->soc = soc;
2136 wmi_handle->event_id = soc->event_id;
2137 wmi_handle->event_handler = soc->event_handler;
2138 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302139 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302140 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302141 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302142 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302143 qdf_atomic_init(&wmi_handle->pending_cmds);
2144 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302145 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302146 qdf_spinlock_create(&wmi_handle->eventq_lock);
2147 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002148 qdf_create_work(0, &wmi_handle->rx_event_work,
2149 wmi_rx_event_work, wmi_handle);
2150 wmi_handle->wmi_rx_work_queue =
2151 qdf_create_workqueue("wmi_rx_event_work_queue");
2152 if (NULL == wmi_handle->wmi_rx_work_queue) {
2153 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2154 goto error;
2155 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302156 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302157 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302158 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2159 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302160 wmi_handle->target_type = target_type;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302161 soc->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302162 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302163 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302164 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302165 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302166 /* Assign target cookie capablity */
2167 wmi_handle->use_cookie = use_cookie;
2168 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302169 wmi_handle->wmi_stopinprogress = 0;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302170 /* Increase the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302171 soc->wmi_psoc = psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302172 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302173
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302174 soc->ops = wmi_handle->ops;
2175 soc->wmi_pdev[0] = wmi_handle;
2176
Govind Singh6b411b52016-03-06 19:55:02 +05302177 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002178
2179error:
2180 qdf_mem_free(soc);
2181 qdf_mem_free(wmi_handle);
2182
2183 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302184}
2185
2186/**
2187 * wmi_unified_detach() - detach for unified WMI
2188 *
2189 * @wmi_handle : handle to wmi.
2190 *
2191 * @Return: none.
2192 */
2193void wmi_unified_detach(struct wmi_unified *wmi_handle)
2194{
2195 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302196 struct wmi_soc *soc;
2197 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302198
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302199 soc = wmi_handle->soc;
2200 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2201 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002202 qdf_flush_workqueue(0,
2203 soc->wmi_pdev[i]->wmi_rx_work_queue);
2204 qdf_destroy_workqueue(0,
2205 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302206 wmi_debugfs_remove(soc->wmi_pdev[i]);
2207 buf = qdf_nbuf_queue_remove(
2208 &soc->wmi_pdev[i]->event_queue);
2209 while (buf) {
2210 qdf_nbuf_free(buf);
2211 buf = qdf_nbuf_queue_remove(
2212 &soc->wmi_pdev[i]->event_queue);
2213 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002214
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302215 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002216
2217 /* Free events logs list */
2218 if (soc->wmi_pdev[i]->events_logs_list)
2219 qdf_mem_free(
2220 soc->wmi_pdev[i]->events_logs_list);
2221
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302222 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302223 qdf_mem_free(soc->wmi_pdev[i]);
2224 }
Govind Singh6b411b52016-03-06 19:55:02 +05302225 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302226 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302227
2228 if (soc->wmi_service_bitmap) {
2229 qdf_mem_free(soc->wmi_service_bitmap);
2230 soc->wmi_service_bitmap = NULL;
2231 }
2232
2233 if (soc->wmi_ext_service_bitmap) {
2234 qdf_mem_free(soc->wmi_ext_service_bitmap);
2235 soc->wmi_ext_service_bitmap = NULL;
2236 }
2237
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302238 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302239 soc->wmi_psoc = NULL;
2240 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302241}
2242
2243/**
2244 * wmi_unified_remove_work() - detach for WMI work
2245 * @wmi_handle: handle to WMI
2246 *
2247 * A function that does not fully detach WMI, but just remove work
2248 * queue items associated with it. This is used to make sure that
2249 * before any other processing code that may destroy related contexts
2250 * (HTC, etc), work queue processing on WMI has already been stopped.
2251 *
2252 * Return: None
2253 */
2254void
2255wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2256{
2257 wmi_buf_t buf;
2258
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002259 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302260 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2261 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302262 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302263 qdf_nbuf_free(buf);
2264 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302265 }
Govind Singhb53420c2016-03-09 14:32:57 +05302266 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302267}
2268
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302269/**
2270 * wmi_htc_tx_complete() - Process htc tx completion
2271 *
2272 * @ctx: handle to wmi
2273 * @htc_packet: pointer to htc packet
2274 *
2275 * @Return: none.
2276 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002277static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302278{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302279 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302280 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302281 u_int8_t *buf_ptr;
2282 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302283 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302284#ifdef WMI_INTERFACE_EVENT_LOGGING
2285 uint32_t cmd_id;
2286#endif
2287
2288 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302289 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2290 if (wmi_handle == NULL) {
2291 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2292 QDF_ASSERT(0);
2293 return;
2294 }
Govind Singh6b411b52016-03-06 19:55:02 +05302295#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302296 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302297 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2298 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302299
Govind Singhecf03cd2016-05-12 12:45:51 +05302300 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302301 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302302 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302303 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302304 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302305 qdf_nbuf_data(wmi_cmd_buf) +
2306 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302307 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302308 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302309 qdf_nbuf_data(wmi_cmd_buf) +
2310 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302311 }
2312
Govind Singhecf03cd2016-05-12 12:45:51 +05302313 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2314 }
Govind Singh6b411b52016-03-06 19:55:02 +05302315#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302316 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2317 len = qdf_nbuf_len(wmi_cmd_buf);
2318 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302319 qdf_nbuf_free(wmi_cmd_buf);
2320 qdf_mem_free(htc_pkt);
2321 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302322}
2323
2324/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302325 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302326 *
2327 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302328 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302329 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302330 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302331 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302332static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2333 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302334{
Govind Singh6b411b52016-03-06 19:55:02 +05302335 int status;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302336 uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
2337 WMI_CONTROL_SVC_WMAC2};
Manikandan Mohanf940db82017-04-13 20:19:26 -07002338 struct htc_service_connect_resp response;
2339 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302340
2341 OS_MEMZERO(&connect, sizeof(connect));
2342 OS_MEMZERO(&response, sizeof(response));
2343
2344 /* meta data is unused for now */
2345 connect.pMetaData = NULL;
2346 connect.MetaDataLength = 0;
2347 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302348 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302349 connect.EpCallbacks.EpTxCompleteMultiple =
2350 NULL /* Control path completion ar6000_tx_complete */;
2351 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2352 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2353 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2354 connect.EpCallbacks.EpTxComplete =
2355 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2356
2357 /* connect to control service */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302358 connect.service_id = svc_id[pdev_idx];
2359 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302360 &response);
2361
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302362
Govind Singh6b411b52016-03-06 19:55:02 +05302363 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302364 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302365 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302366 status);
2367 return status;
2368 }
Govind Singh6b411b52016-03-06 19:55:02 +05302369
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302370 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2371 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2372
2373 return 0;
2374}
2375
2376/**
2377 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2378 *
2379 * @wmi_handle: handle to WMI.
2380 *
2381 * @Return: status.
2382 */
2383QDF_STATUS
2384wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2385 void *htc_handle)
2386{
2387 uint32_t i;
2388 uint8_t wmi_ep_count;
2389
2390 wmi_handle->soc->htc_handle = htc_handle;
2391
2392 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2393 if (wmi_ep_count > WMI_MAX_RADIOS)
2394 return QDF_STATUS_E_FAULT;
2395
2396 for (i = 0; i < wmi_ep_count; i++)
2397 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2398
2399 wmi_handle->htc_handle = htc_handle;
2400 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2401 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2402
2403 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302404}
2405
2406/**
2407 * wmi_get_host_credits() - WMI API to get updated host_credits
2408 *
2409 * @wmi_handle: handle to WMI.
2410 *
2411 * @Return: updated host_credits.
2412 */
2413int wmi_get_host_credits(wmi_unified_t wmi_handle)
2414{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302415 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302416
2417 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2418 &host_credits);
2419 return host_credits;
2420}
2421
2422/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302423 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2424 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302425 *
2426 * @wmi_handle: handle to WMI.
2427 *
2428 * @Return: Pending Commands in the HTC queue.
2429 */
2430int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2431{
Govind Singhb53420c2016-03-09 14:32:57 +05302432 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302433}
2434
2435/**
2436 * wmi_set_target_suspend() - WMI API to set target suspend state
2437 *
2438 * @wmi_handle: handle to WMI.
2439 * @val: suspend state boolean.
2440 *
2441 * @Return: none.
2442 */
2443void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2444{
Govind Singhb53420c2016-03-09 14:32:57 +05302445 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302446}
2447
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302448/**
2449 * WMI API to set crash injection state
2450 * @param wmi_handle: handle to WMI.
2451 * @param val: crash injection state boolean.
2452 */
2453void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2454{
2455 wmi_handle->tag_crash_inject = flag;
2456}
2457
2458/**
2459 * WMI API to set bus suspend state
2460 * @param wmi_handle: handle to WMI.
2461 * @param val: suspend state boolean.
2462 */
2463void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2464{
2465 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2466}
2467
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302468void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2469{
2470 wmi_handle->tgt_force_assert_enable = val;
2471}
2472
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302473#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302474/**
2475 * API to flush all the previous packets associated with the wmi endpoint
2476 *
2477 * @param wmi_handle : handle to WMI.
2478 */
2479void
2480wmi_flush_endpoint(wmi_unified_t wmi_handle)
2481{
2482 htc_flush_endpoint(wmi_handle->htc_handle,
2483 wmi_handle->wmi_endpoint_id, 0);
2484}
2485
2486/**
2487 * generic function to block unified WMI command
2488 * @param wmi_handle : handle to WMI.
2489 * @return 0 on success and -ve on failure.
2490 */
2491int
2492wmi_stop(wmi_unified_t wmi_handle)
2493{
2494 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2495 "WMI Stop\n");
2496 wmi_handle->wmi_stopinprogress = 1;
2497 return 0;
2498}
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302499
2500/**
2501 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2502 * By default pdev_id conversion is not done in WMI.
2503 * This API can be used enable conversion in WMI.
2504 * @param wmi_handle : handle to WMI
2505 * Return none
2506 */
2507void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2508{
2509 if (wmi_handle->target_type == WMI_TLV_TARGET)
2510 wmi_tlv_pdev_id_conversion_enable(wmi_handle);
2511}
2512
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302513#endif