blob: e842fd226f1acef8e2118cc462fcff3ccde30087 [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"
Pratik Gandhi67da1bb2018-01-30 19:05:41 +053034#include "qdf_module.h"
Govind Singh6b411b52016-03-06 19:55:02 +053035
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053036#ifndef WMI_NON_TLV_SUPPORT
37#include "wmi_tlv_helper.h"
38#endif
39
Govind Singhecf03cd2016-05-12 12:45:51 +053040#include <linux/debugfs.h>
41
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053042/* This check for CONFIG_WIN temporary added due to redeclaration compilation
43error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
44which gets included here through ol_if_athvar.h. Eventually it is expected that
45wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
46WMI_CMD_HDR to be defined here. */
47#ifdef CONFIG_WIN
48/* Copied from wmi.h */
49#undef MS
50#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
51#undef SM
52#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
53#undef WO
54#define WO(_f) ((_f##_OFFSET) >> 2)
55
56#undef GET_FIELD
57#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
58#undef SET_FIELD
59#define SET_FIELD(_addr, _f, _val) \
60 (*((A_UINT32 *)(_addr) + WO(_f)) = \
61 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
62
63#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
64 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
65
66#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
67 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
68
69#define WMI_EP_APASS 0x0
70#define WMI_EP_LPASS 0x1
71#define WMI_EP_SENSOR 0x2
72
73/*
74 * * Control Path
75 * */
76typedef PREPACK struct {
77 A_UINT32 commandId:24,
78 reserved:2, /* used for WMI endpoint ID */
79 plt_priv:6; /* platform private */
80} POSTPACK WMI_CMD_HDR; /* used for commands and events */
81
82#define WMI_CMD_HDR_COMMANDID_LSB 0
83#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
84#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
85#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
86#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
87#define WMI_CMD_HDR_PLT_PRIV_LSB 24
88#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
89#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
90/* end of copy wmi.h */
91#endif /* CONFIG_WIN */
92
Rachit Kankane799d2c92018-02-19 11:28:10 +053093#define WMI_MIN_HEAD_ROOM 64
94
95#ifdef WMI_INTERFACE_EVENT_LOGGING
Manikandan Mohan5826ae92016-06-08 16:29:39 -070096#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
97/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +053098static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -070099{
100 va_list args;
101
102 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +0530103 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700104 va_end(args);
105
Pratik Gandhi795ab912017-05-03 20:15:50 +0530106 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700107}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530108#else
109#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700110#endif
111
Govind Singhecf03cd2016-05-12 12:45:51 +0530112#ifndef MAX_WMI_INSTANCES
113#ifdef CONFIG_MCL
114#define MAX_WMI_INSTANCES 1
115#else
116#define MAX_WMI_INSTANCES 3
117#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530118#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530119#endif
120
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530121#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530122/* WMI commands */
123uint32_t g_wmi_command_buf_idx = 0;
124struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
125
126/* WMI commands TX completed */
127uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
128struct wmi_command_debug
129 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
130
131/* WMI events when processed */
132uint32_t g_wmi_event_buf_idx = 0;
133struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
134
135/* WMI events when queued */
136uint32_t g_wmi_rx_event_buf_idx = 0;
137struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530138#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530139
Govind Singhecf03cd2016-05-12 12:45:51 +0530140#define WMI_COMMAND_RECORD(h, a, b) { \
141 if (wmi_log_max_entry <= \
142 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
143 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
144 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
145 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
146 .command = a; \
147 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
148 wmi_command_log_buf_info.buf) \
149 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
150 b, wmi_record_max_length); \
151 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
152 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
153 time = qdf_get_log_timestamp(); \
154 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
155 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530156}
157
Govind Singhecf03cd2016-05-12 12:45:51 +0530158#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
159 if (wmi_log_max_entry <= \
160 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530161 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
162 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530163 ((struct wmi_command_debug *)h->log_info. \
164 wmi_command_tx_cmp_log_buf_info.buf) \
165 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
166 p_buf_tail_idx)]. \
167 command = a; \
168 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
169 wmi_command_tx_cmp_log_buf_info.buf) \
170 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
171 p_buf_tail_idx)]. \
172 data, b, wmi_record_max_length); \
173 ((struct wmi_command_debug *)h->log_info. \
174 wmi_command_tx_cmp_log_buf_info.buf) \
175 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
176 p_buf_tail_idx)]. \
177 time = qdf_get_log_timestamp(); \
178 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
179 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530180}
181
Govind Singhecf03cd2016-05-12 12:45:51 +0530182#define WMI_EVENT_RECORD(h, a, b) { \
183 if (wmi_log_max_entry <= \
184 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
185 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
186 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
187 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
188 event = a; \
189 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
190 wmi_event_log_buf_info.buf) \
191 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
192 wmi_record_max_length); \
193 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
194 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530195 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530196 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
197 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530198}
199
Govind Singhecf03cd2016-05-12 12:45:51 +0530200#define WMI_RX_EVENT_RECORD(h, a, b) { \
201 if (wmi_log_max_entry <= \
202 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
203 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
204 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
205 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
206 event = a; \
207 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
208 wmi_rx_event_log_buf_info.buf) \
209 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
210 data, b, wmi_record_max_length); \
211 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
212 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
213 time = qdf_get_log_timestamp(); \
214 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
215 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530216}
Govind Singh6b411b52016-03-06 19:55:02 +0530217
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530218#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530219uint32_t g_wmi_mgmt_command_buf_idx = 0;
220struct
221wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
222
223/* wmi_mgmt commands TX completed */
224uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
225struct wmi_command_debug
226wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
227
228/* wmi_mgmt events when processed */
229uint32_t g_wmi_mgmt_event_buf_idx = 0;
230struct wmi_event_debug
231wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530232#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530233
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530234#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
235 if (wmi_mgmt_log_max_entry <= \
236 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
237 *(h->log_info.wmi_mgmt_command_log_buf_info. \
238 p_buf_tail_idx) = 0; \
239 ((struct wmi_command_debug *)h->log_info. \
240 wmi_mgmt_command_log_buf_info.buf) \
241 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
242 command = a; \
243 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
244 wmi_mgmt_command_log_buf_info.buf) \
245 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
246 data, b, \
247 wmi_record_max_length); \
248 ((struct wmi_command_debug *)h->log_info. \
249 wmi_mgmt_command_log_buf_info.buf) \
250 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
251 time = qdf_get_log_timestamp(); \
252 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
253 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530254}
255
Govind Singhecf03cd2016-05-12 12:45:51 +0530256#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
257 if (wmi_mgmt_log_max_entry <= \
258 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
259 p_buf_tail_idx)) \
260 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
261 p_buf_tail_idx) = 0; \
262 ((struct wmi_command_debug *)h->log_info. \
263 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
264 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
265 p_buf_tail_idx)].command = a; \
266 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
267 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
268 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
269 p_buf_tail_idx)].data, b, \
270 wmi_record_max_length); \
271 ((struct wmi_command_debug *)h->log_info. \
272 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
273 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
274 p_buf_tail_idx)].time = \
275 qdf_get_log_timestamp(); \
276 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
277 p_buf_tail_idx))++; \
278 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530279}
280
Govind Singhecf03cd2016-05-12 12:45:51 +0530281#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
282 if (wmi_mgmt_log_max_entry <= \
283 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
284 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
285 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
286 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
287 .event = a; \
288 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
289 wmi_mgmt_event_log_buf_info.buf) \
290 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
291 data, b, wmi_record_max_length); \
292 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
293 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
294 time = qdf_get_log_timestamp(); \
295 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
296 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530297}
298
Govind Singhecf03cd2016-05-12 12:45:51 +0530299/* These are defined to made it as module param, which can be configured */
300uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
301uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
302uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
303uint32_t wmi_display_size = 100;
304
Govind Singhecf03cd2016-05-12 12:45:51 +0530305/**
306 * wmi_log_init() - Initialize WMI event logging
307 * @wmi_handle: WMI handle.
308 *
309 * Return: Initialization status
310 */
311#ifdef CONFIG_MCL
312static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
313{
314 struct wmi_log_buf_t *cmd_log_buf =
315 &wmi_handle->log_info.wmi_command_log_buf_info;
316 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
317 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
318
319 struct wmi_log_buf_t *event_log_buf =
320 &wmi_handle->log_info.wmi_event_log_buf_info;
321 struct wmi_log_buf_t *rx_event_log_buf =
322 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
323
324 struct wmi_log_buf_t *mgmt_cmd_log_buf =
325 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
326 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
327 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
328 struct wmi_log_buf_t *mgmt_event_log_buf =
329 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
330
331 /* WMI commands */
332 cmd_log_buf->length = 0;
333 cmd_log_buf->buf_tail_idx = 0;
334 cmd_log_buf->buf = wmi_command_log_buffer;
335 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700336 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530337
338 /* WMI commands TX completed */
339 cmd_tx_cmpl_log_buf->length = 0;
340 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
341 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
342 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700343 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530344
345 /* WMI events when processed */
346 event_log_buf->length = 0;
347 event_log_buf->buf_tail_idx = 0;
348 event_log_buf->buf = wmi_event_log_buffer;
349 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700350 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530351
352 /* WMI events when queued */
353 rx_event_log_buf->length = 0;
354 rx_event_log_buf->buf_tail_idx = 0;
355 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
356 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700357 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530358
359 /* WMI Management commands */
360 mgmt_cmd_log_buf->length = 0;
361 mgmt_cmd_log_buf->buf_tail_idx = 0;
362 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
363 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700364 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530365
366 /* WMI Management commands Tx completed*/
367 mgmt_cmd_tx_cmp_log_buf->length = 0;
368 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
369 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
370 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
371 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700372 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530373
374 /* WMI Management events when processed*/
375 mgmt_event_log_buf->length = 0;
376 mgmt_event_log_buf->buf_tail_idx = 0;
377 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
378 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700379 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530380
381 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
382 wmi_handle->log_info.wmi_logging_enable = 1;
383
384 return QDF_STATUS_SUCCESS;
385}
386#else
387static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
388{
389 struct wmi_log_buf_t *cmd_log_buf =
390 &wmi_handle->log_info.wmi_command_log_buf_info;
391 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
392 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
393
394 struct wmi_log_buf_t *event_log_buf =
395 &wmi_handle->log_info.wmi_event_log_buf_info;
396 struct wmi_log_buf_t *rx_event_log_buf =
397 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
398
399 struct wmi_log_buf_t *mgmt_cmd_log_buf =
400 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
401 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
402 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
403 struct wmi_log_buf_t *mgmt_event_log_buf =
404 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
405
406 wmi_handle->log_info.wmi_logging_enable = 0;
407
408 /* WMI commands */
409 cmd_log_buf->length = 0;
410 cmd_log_buf->buf_tail_idx = 0;
411 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
412 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700413 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530414
415 if (!cmd_log_buf->buf) {
416 qdf_print("no memory for WMI command log buffer..\n");
417 return QDF_STATUS_E_NOMEM;
418 }
419 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
420
421 /* WMI commands TX completed */
422 cmd_tx_cmpl_log_buf->length = 0;
423 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
424 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
425 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700426 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530427
428 if (!cmd_tx_cmpl_log_buf->buf) {
429 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
430 return QDF_STATUS_E_NOMEM;
431 }
432 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
433 &cmd_tx_cmpl_log_buf->buf_tail_idx;
434
435 /* WMI events when processed */
436 event_log_buf->length = 0;
437 event_log_buf->buf_tail_idx = 0;
438 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
439 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700440 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530441
442 if (!event_log_buf->buf) {
443 qdf_print("no memory for WMI Event log buffer..\n");
444 return QDF_STATUS_E_NOMEM;
445 }
446 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
447
448 /* WMI events when queued */
449 rx_event_log_buf->length = 0;
450 rx_event_log_buf->buf_tail_idx = 0;
451 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
452 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700453 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530454
455 if (!rx_event_log_buf->buf) {
456 qdf_print("no memory for WMI Event Rx log buffer..\n");
457 return QDF_STATUS_E_NOMEM;
458 }
459 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
460
461 /* WMI Management commands */
462 mgmt_cmd_log_buf->length = 0;
463 mgmt_cmd_log_buf->buf_tail_idx = 0;
464 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700465 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
466 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530467
468 if (!mgmt_cmd_log_buf->buf) {
469 qdf_print("no memory for WMI Management Command log buffer..\n");
470 return QDF_STATUS_E_NOMEM;
471 }
472 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
473
474 /* WMI Management commands Tx completed*/
475 mgmt_cmd_tx_cmp_log_buf->length = 0;
476 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
477 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
478 qdf_mem_malloc(
479 wmi_mgmt_log_max_entry *
480 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700481 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530482
483 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
484 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
485 return QDF_STATUS_E_NOMEM;
486 }
487 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
488 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
489
490 /* WMI Management events when processed*/
491 mgmt_event_log_buf->length = 0;
492 mgmt_event_log_buf->buf_tail_idx = 0;
493
494 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
495 wmi_mgmt_log_max_entry *
496 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700497 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530498
499 if (!mgmt_event_log_buf->buf) {
500 qdf_print("no memory for WMI Management Event log buffer..\n");
501 return QDF_STATUS_E_NOMEM;
502 }
503 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
504
505 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
506 wmi_handle->log_info.wmi_logging_enable = 1;
507
508 return QDF_STATUS_SUCCESS;
509}
510#endif
511
512/**
513 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
514 * event logging
515 * @wmi_handle: WMI handle.
516 *
517 * Return: None
518 */
519#ifndef CONFIG_MCL
520static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
521{
522 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
523 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
524 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
525 qdf_mem_free(
526 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
527 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
528 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
529 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
530 qdf_mem_free(
531 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
532 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
533 qdf_mem_free(
534 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
535 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
536 qdf_mem_free(
537 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
538 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
539 qdf_mem_free(
540 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
541 wmi_handle->log_info.wmi_logging_enable = 0;
542 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
543}
544#else
545static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
546{
547 /* Do Nothing */
548}
549#endif
550
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700551/**
552 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
553 * @log_buffer: the command log buffer metadata of the buffer to print
554 * @count: the maximum number of entries to print
555 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
556 * @print_priv: any data required by the print method, e.g. a file handle
557 *
558 * Return: None
559 */
560static void
561wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
562 qdf_abstract_print *print, void *print_priv)
563{
564 static const int data_len =
565 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
566 char str[128];
567 uint32_t idx;
568
569 if (count > log_buffer->size)
570 count = log_buffer->size;
571 if (count > log_buffer->length)
572 count = log_buffer->length;
573
574 /* subtract count from index, and wrap if necessary */
575 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
576 idx %= log_buffer->size;
577
578 print(print_priv, "Time (seconds) Cmd Id Payload");
579 while (count) {
580 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
581 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700582 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700583 int len = 0;
584 int i;
585
Dustin Brown8ea39122017-04-10 13:26:56 -0700586 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700587 len += scnprintf(str + len, sizeof(str) - len,
588 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700589 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700590 cmd_log->command, cmd_log->command);
591 for (i = 0; i < data_len; ++i) {
592 len += scnprintf(str + len, sizeof(str) - len,
593 "0x%08x ", cmd_log->data[i]);
594 }
595
596 print(print_priv, str);
597
598 --count;
599 ++idx;
600 if (idx >= log_buffer->size)
601 idx = 0;
602 }
603}
604
605/**
606 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
607 * @log_buffer: the event log buffer metadata of the buffer to print
608 * @count: the maximum number of entries to print
609 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
610 * @print_priv: any data required by the print method, e.g. a file handle
611 *
612 * Return: None
613 */
614static void
615wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
616 qdf_abstract_print *print, void *print_priv)
617{
618 static const int data_len =
619 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
620 char str[128];
621 uint32_t idx;
622
623 if (count > log_buffer->size)
624 count = log_buffer->size;
625 if (count > log_buffer->length)
626 count = log_buffer->length;
627
628 /* subtract count from index, and wrap if necessary */
629 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
630 idx %= log_buffer->size;
631
632 print(print_priv, "Time (seconds) Event Id Payload");
633 while (count) {
634 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
635 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700636 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700637 int len = 0;
638 int i;
639
Dustin Brown8ea39122017-04-10 13:26:56 -0700640 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700641 len += scnprintf(str + len, sizeof(str) - len,
642 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700643 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700644 event_log->event, event_log->event);
645 for (i = 0; i < data_len; ++i) {
646 len += scnprintf(str + len, sizeof(str) - len,
647 "0x%08x ", event_log->data[i]);
648 }
649
650 print(print_priv, str);
651
652 --count;
653 ++idx;
654 if (idx >= log_buffer->size)
655 idx = 0;
656 }
657}
658
659inline void
660wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
661 qdf_abstract_print *print, void *print_priv)
662{
663 wmi_print_cmd_log_buffer(
664 &wmi->log_info.wmi_command_log_buf_info,
665 count, print, print_priv);
666}
667
668inline void
669wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
670 qdf_abstract_print *print, void *print_priv)
671{
672 wmi_print_cmd_log_buffer(
673 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
674 count, print, print_priv);
675}
676
677inline void
678wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
679 qdf_abstract_print *print, void *print_priv)
680{
681 wmi_print_cmd_log_buffer(
682 &wmi->log_info.wmi_mgmt_command_log_buf_info,
683 count, print, print_priv);
684}
685
686inline void
687wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
688 qdf_abstract_print *print, void *print_priv)
689{
690 wmi_print_cmd_log_buffer(
691 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
692 count, print, print_priv);
693}
694
695inline void
696wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
697 qdf_abstract_print *print, void *print_priv)
698{
699 wmi_print_event_log_buffer(
700 &wmi->log_info.wmi_event_log_buf_info,
701 count, print, print_priv);
702}
703
704inline void
705wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
706 qdf_abstract_print *print, void *print_priv)
707{
708 wmi_print_event_log_buffer(
709 &wmi->log_info.wmi_rx_event_log_buf_info,
710 count, print, print_priv);
711}
712
713inline void
714wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
715 qdf_abstract_print *print, void *print_priv)
716{
717 wmi_print_event_log_buffer(
718 &wmi->log_info.wmi_mgmt_event_log_buf_info,
719 count, print, print_priv);
720}
721
Govind Singhecf03cd2016-05-12 12:45:51 +0530722#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530723const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530724#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530725const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530726#endif
727
728/* debugfs routines*/
729
730/**
731 * debug_wmi_##func_base##_show() - debugfs functions to display content of
732 * command and event buffers. Macro uses max buffer length to display
733 * buffer when it is wraparound.
734 *
735 * @m: debugfs handler to access wmi_handle
736 * @v: Variable arguments (not used)
737 *
738 * Return: Length of characters printed
739 */
740#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
741 static int debug_wmi_##func_base##_show(struct seq_file *m, \
742 void *v) \
743 { \
744 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
745 struct wmi_log_buf_t *wmi_log = \
746 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
747 int pos, nread, outlen; \
748 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800749 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530750 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530751 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
752 if (!wmi_log->length) { \
753 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530754 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530755 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530756 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530757 \
758 if (wmi_log->length <= wmi_ring_size) \
759 nread = wmi_log->length; \
760 else \
761 nread = wmi_ring_size; \
762 \
763 if (*(wmi_log->p_buf_tail_idx) == 0) \
764 /* tail can be 0 after wrap-around */ \
765 pos = wmi_ring_size - 1; \
766 else \
767 pos = *(wmi_log->p_buf_tail_idx) - 1; \
768 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530769 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530770 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530771 while (nread--) { \
772 struct wmi_command_debug *wmi_record; \
773 \
774 wmi_record = (struct wmi_command_debug *) \
775 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530776 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530777 (wmi_record->command)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800778 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
779 &usecs); \
780 outlen += \
781 wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
782 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530783 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530784 for (i = 0; i < (wmi_record_max_length/ \
785 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530786 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530787 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530788 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530789 \
790 if (pos == 0) \
791 pos = wmi_ring_size - 1; \
792 else \
793 pos--; \
794 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530795 return outlen; \
796 } \
797
798#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
799 static int debug_wmi_##func_base##_show(struct seq_file *m, \
800 void *v) \
801 { \
802 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
803 struct wmi_log_buf_t *wmi_log = \
804 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
805 int pos, nread, outlen; \
806 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800807 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530808 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530809 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
810 if (!wmi_log->length) { \
811 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530812 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530813 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530814 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530815 \
816 if (wmi_log->length <= wmi_ring_size) \
817 nread = wmi_log->length; \
818 else \
819 nread = wmi_ring_size; \
820 \
821 if (*(wmi_log->p_buf_tail_idx) == 0) \
822 /* tail can be 0 after wrap-around */ \
823 pos = wmi_ring_size - 1; \
824 else \
825 pos = *(wmi_log->p_buf_tail_idx) - 1; \
826 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530827 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530828 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530829 while (nread--) { \
830 struct wmi_event_debug *wmi_record; \
831 \
832 wmi_record = (struct wmi_event_debug *) \
833 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
nobelj2a6da6f2017-12-11 23:18:27 -0800834 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
835 &usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530836 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +0530837 (wmi_record->event)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800838 outlen += \
839 wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
840 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530841 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530842 for (i = 0; i < (wmi_record_max_length/ \
843 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530844 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530845 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530846 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530847 \
848 if (pos == 0) \
849 pos = wmi_ring_size - 1; \
850 else \
851 pos--; \
852 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530853 return outlen; \
854 }
855
856GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
857GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
858GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
859GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
860GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
861GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
862 wmi_display_size);
863GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
864
865/**
866 * debug_wmi_enable_show() - debugfs functions to display enable state of
867 * wmi logging feature.
868 *
869 * @m: debugfs handler to access wmi_handle
870 * @v: Variable arguments (not used)
871 *
872 * Return: always 1
873 */
874static int debug_wmi_enable_show(struct seq_file *m, void *v)
875{
876 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
877
Pratik Gandhi795ab912017-05-03 20:15:50 +0530878 return wmi_bp_seq_printf(m, "%d\n",
879 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530880}
881
882/**
883 * debug_wmi_log_size_show() - debugfs functions to display configured size of
884 * wmi logging command/event buffer and management command/event buffer.
885 *
886 * @m: debugfs handler to access wmi_handle
887 * @v: Variable arguments (not used)
888 *
889 * Return: Length of characters printed
890 */
891static int debug_wmi_log_size_show(struct seq_file *m, void *v)
892{
893
Pratik Gandhi795ab912017-05-03 20:15:50 +0530894 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
895 wmi_log_max_entry);
896 return wmi_bp_seq_printf(m,
897 "WMI management command/events log max size:%d\n",
898 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530899}
900
901/**
902 * debug_wmi_##func_base##_write() - debugfs functions to clear
903 * wmi logging command/event buffer and management command/event buffer.
904 *
905 * @file: file handler to access wmi_handle
906 * @buf: received data buffer
907 * @count: length of received buffer
908 * @ppos: Not used
909 *
910 * Return: count
911 */
912#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
913 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
914 const char __user *buf, \
915 size_t count, loff_t *ppos) \
916 { \
917 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530918 wmi_unified_t wmi_handle = \
919 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530920 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
921 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530922 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530923 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530924 if ((!buf) || (count > 50)) \
925 return -EFAULT; \
926 \
927 if (copy_from_user(locbuf, buf, count)) \
928 return -EFAULT; \
929 \
930 ret = sscanf(locbuf, "%d", &k); \
931 if ((ret != 1) || (k != 0)) { \
Govind Singhecf03cd2016-05-12 12:45:51 +0530932 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
933 return -EINVAL; \
934 } \
935 \
936 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
937 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
938 sizeof(struct wmi_record_type)); \
939 wmi_log->length = 0; \
940 *(wmi_log->p_buf_tail_idx) = 0; \
941 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
942 \
943 return count; \
944 }
945
946GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
947 wmi_command_debug);
948GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
949 wmi_command_debug);
950GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
951 wmi_event_debug);
952GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
953 wmi_event_debug);
954GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
955 wmi_command_debug);
956GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
957 wmi_mgmt_log_max_entry, wmi_command_debug);
958GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
959 wmi_event_debug);
960
961/**
962 * debug_wmi_enable_write() - debugfs functions to enable/disable
963 * wmi logging feature.
964 *
965 * @file: file handler to access wmi_handle
966 * @buf: received data buffer
967 * @count: length of received buffer
968 * @ppos: Not used
969 *
970 * Return: count
971 */
972static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
973 size_t count, loff_t *ppos)
974{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530975 wmi_unified_t wmi_handle =
976 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530977 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530978 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530979
Pratik Gandhi795ab912017-05-03 20:15:50 +0530980 if ((!buf) || (count > 50))
981 return -EFAULT;
982
983 if (copy_from_user(locbuf, buf, count))
984 return -EFAULT;
985
986 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530987 if ((ret != 1) || ((k != 0) && (k != 1)))
988 return -EINVAL;
989
990 wmi_handle->log_info.wmi_logging_enable = k;
991 return count;
992}
993
994/**
995 * debug_wmi_log_size_write() - reserved.
996 *
997 * @file: file handler to access wmi_handle
998 * @buf: received data buffer
999 * @count: length of received buffer
1000 * @ppos: Not used
1001 *
1002 * Return: count
1003 */
1004static ssize_t debug_wmi_log_size_write(struct file *file,
1005 const char __user *buf, size_t count, loff_t *ppos)
1006{
1007 return -EINVAL;
1008}
1009
1010/* Structure to maintain debug information */
1011struct wmi_debugfs_info {
1012 const char *name;
1013 struct dentry *de[MAX_WMI_INSTANCES];
1014 const struct file_operations *ops;
1015};
1016
1017#define DEBUG_FOO(func_base) { .name = #func_base, \
1018 .ops = &debug_##func_base##_ops }
1019
1020/**
1021 * debug_##func_base##_open() - Open debugfs entry for respective command
1022 * and event buffer.
1023 *
1024 * @inode: node for debug dir entry
1025 * @file: file handler
1026 *
1027 * Return: open status
1028 */
1029#define GENERATE_DEBUG_STRUCTS(func_base) \
1030 static int debug_##func_base##_open(struct inode *inode, \
1031 struct file *file) \
1032 { \
1033 return single_open(file, debug_##func_base##_show, \
1034 inode->i_private); \
1035 } \
1036 \
1037 \
1038 static struct file_operations debug_##func_base##_ops = { \
1039 .open = debug_##func_base##_open, \
1040 .read = seq_read, \
1041 .llseek = seq_lseek, \
1042 .write = debug_##func_base##_write, \
1043 .release = single_release, \
1044 };
1045
1046GENERATE_DEBUG_STRUCTS(wmi_command_log);
1047GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1048GENERATE_DEBUG_STRUCTS(wmi_event_log);
1049GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1050GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1051GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1052GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1053GENERATE_DEBUG_STRUCTS(wmi_enable);
1054GENERATE_DEBUG_STRUCTS(wmi_log_size);
1055
1056struct wmi_debugfs_info wmi_debugfs_infos[] = {
1057 DEBUG_FOO(wmi_command_log),
1058 DEBUG_FOO(wmi_command_tx_cmp_log),
1059 DEBUG_FOO(wmi_event_log),
1060 DEBUG_FOO(wmi_rx_event_log),
1061 DEBUG_FOO(wmi_mgmt_command_log),
1062 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1063 DEBUG_FOO(wmi_mgmt_event_log),
1064 DEBUG_FOO(wmi_enable),
1065 DEBUG_FOO(wmi_log_size),
1066};
1067
1068#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1069 sizeof(wmi_debugfs_infos[0]))
1070
1071/**
1072 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1073 *
1074 * @wmi_handle: wmi handle
1075 * @par_entry: debug directory entry
1076 * @id: Index to debug info data array
1077 *
1078 * Return: none
1079 */
1080static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1081 struct dentry *par_entry, int id)
1082{
1083 int i;
1084
1085 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1086 goto out;
1087
1088 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1089
1090 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1091 wmi_debugfs_infos[i].name, 0644, par_entry,
1092 wmi_handle, wmi_debugfs_infos[i].ops);
1093
1094 if (wmi_debugfs_infos[i].de[id] == NULL) {
1095 qdf_print("%s: debug Entry creation failed!\n",
1096 __func__);
1097 goto out;
1098 }
1099 }
1100
1101 return;
1102
1103out:
1104 qdf_print("%s: debug Entry creation failed!\n", __func__);
1105 wmi_log_buffer_free(wmi_handle);
1106 return;
1107}
1108
1109/**
1110 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301111 * @wmi_handle: wmi handle
1112 * @dentry: debugfs directory entry
1113 * @id: Index to debug info data array
1114 *
1115 * Return: none
1116 */
Govind Singh06c18392016-06-10 10:33:19 +05301117static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301118{
1119 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301120 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301121 int id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301122
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301123 if (!wmi_handle->log_info.wmi_instance_id)
1124 return;
1125
1126 id = wmi_handle->log_info.wmi_instance_id - 1;
Govind Singhecf03cd2016-05-12 12:45:51 +05301127 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1128 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1129 if (wmi_debugfs_infos[i].de[id])
1130 wmi_debugfs_infos[i].de[id] = NULL;
1131 }
1132 }
1133
1134 if (dentry)
1135 debugfs_remove_recursive(dentry);
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301136
1137 if (wmi_handle->log_info.wmi_instance_id)
1138 wmi_handle->log_info.wmi_instance_id--;
Govind Singhecf03cd2016-05-12 12:45:51 +05301139}
1140
1141/**
1142 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1143 * create debugfs enteries.
1144 *
1145 * @h: wmi handler
1146 *
1147 * Return: init status
1148 */
1149static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1150{
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301151 int wmi_index = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301152
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301153 if (wmi_index < MAX_WMI_INSTANCES) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301154 wmi_handle->log_info.wmi_log_debugfs_dir =
1155 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1156
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301157 if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
1158 qdf_print("error while creating debugfs dir for %s\n",
1159 debugfs_dir[wmi_index]);
1160 return QDF_STATUS_E_FAILURE;
1161 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301162
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301163 wmi_debugfs_create(wmi_handle,
1164 wmi_handle->log_info.wmi_log_debugfs_dir,
1165 wmi_index);
1166 wmi_handle->log_info.wmi_instance_id++;
1167 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301168
1169 return QDF_STATUS_SUCCESS;
1170}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001171
1172/**
1173 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1174 *
1175 * @wmi_handle: wmi handle
1176 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001177 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001178 * @vdev_id: vdev id
1179 * @chanfreq: channel frequency
1180 *
1181 * Return: none
1182 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301183void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001184 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001185{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301186
1187 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1188
1189 data[0] = ((struct wmi_command_header *)header)->type;
1190 data[1] = ((struct wmi_command_header *)header)->sub_type;
1191 data[2] = vdev_id;
1192 data[3] = chanfreq;
1193
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001194 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1195
Rakesh Pillai05110462017-12-27 14:08:59 +05301196 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001197
1198 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1199}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001200#else
1201/**
1202 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1203 * @wmi_handle: wmi handle
1204 * @dentry: debugfs directory entry
1205 * @id: Index to debug info data array
1206 *
1207 * Return: none
1208 */
Govind Singh06c18392016-06-10 10:33:19 +05301209static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301210void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001211 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301212static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301213#endif /*WMI_INTERFACE_EVENT_LOGGING */
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301214qdf_export_symbol(wmi_mgmt_cmd_record);
Govind Singh6b411b52016-03-06 19:55:02 +05301215
Govind Singh6b411b52016-03-06 19:55:02 +05301216int wmi_get_host_credits(wmi_unified_t wmi_handle);
1217/* WMI buffer APIs */
1218
1219#ifdef MEMORY_DEBUG
1220wmi_buf_t
1221wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301222 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301223{
1224 wmi_buf_t wmi_buf;
1225
1226 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301227 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301228 return NULL;
1229 }
1230
Govind Singhb53420c2016-03-09 14:32:57 +05301231 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301232 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1233 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1234 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301235
1236 if (!wmi_buf)
1237 return NULL;
1238
1239 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301240 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301241
1242 /*
1243 * Set the length of the buffer to match the allocation size.
1244 */
Govind Singhb53420c2016-03-09 14:32:57 +05301245 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301246
1247 return wmi_buf;
1248}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301249qdf_export_symbol(wmi_buf_alloc_debug);
Govind Singh6b411b52016-03-06 19:55:02 +05301250
1251void wmi_buf_free(wmi_buf_t net_buf)
1252{
Govind Singhb53420c2016-03-09 14:32:57 +05301253 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301254}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301255qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301256#else
1257wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1258{
1259 wmi_buf_t wmi_buf;
1260
1261 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301262 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301263 return NULL;
1264 }
1265
Govind Singhb53420c2016-03-09 14:32:57 +05301266 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301267 WMI_MIN_HEAD_ROOM, 4, false);
1268 if (!wmi_buf)
1269 return NULL;
1270
1271 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301272 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301273
1274 /*
1275 * Set the length of the buffer to match the allocation size.
1276 */
Govind Singhb53420c2016-03-09 14:32:57 +05301277 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301278 return wmi_buf;
1279}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301280qdf_export_symbol(wmi_buf_alloc);
Govind Singh6b411b52016-03-06 19:55:02 +05301281
1282void wmi_buf_free(wmi_buf_t net_buf)
1283{
Govind Singhb53420c2016-03-09 14:32:57 +05301284 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301285}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301286qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301287#endif
1288
1289/**
1290 * wmi_get_max_msg_len() - get maximum WMI message length
1291 * @wmi_handle: WMI handle.
1292 *
1293 * This function returns the maximum WMI message length
1294 *
1295 * Return: maximum WMI message length
1296 */
1297uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1298{
1299 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1300}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301301qdf_export_symbol(wmi_get_max_msg_len);
Govind Singh6b411b52016-03-06 19:55:02 +05301302
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301303#ifndef WMI_CMD_STRINGS
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301304static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301305{
1306 return "Invalid WMI cmd";
1307}
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301308
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301309#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301310
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301311#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301312static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1313{
1314 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1315 wmi_id_to_name(cmd_id), cmd_id, tag);
1316}
1317
Govind Singh6b411b52016-03-06 19:55:02 +05301318/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301319 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1320 * @cmd_id: command to check
1321 *
1322 * Return: true if the command is part of the resume sequence.
1323 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301324static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301325{
1326 switch (cmd_id) {
1327 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1328 case WMI_PDEV_RESUME_CMDID:
1329 return true;
1330
1331 default:
1332 return false;
1333 }
1334}
1335#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301336static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301337{
1338 return false;
1339}
1340#endif
1341
1342/**
Govind Singh6b411b52016-03-06 19:55:02 +05301343 * wmi_unified_cmd_send() - WMI command API
1344 * @wmi_handle: handle to wmi
1345 * @buf: wmi buf
1346 * @len: wmi buffer length
1347 * @cmd_id: wmi command id
1348 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001349 * Note, it is NOT safe to access buf after calling this function!
1350 *
Govind Singh6b411b52016-03-06 19:55:02 +05301351 * Return: 0 on success
1352 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001353QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1354 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301355{
1356 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301357 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301358 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301359
1360 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301361 htc_tag =
1362 (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
1363 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301364 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301365 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301366 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301367 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301368 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301369 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301370 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301371 if (wmi_handle->wmi_stopinprogress) {
1372 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1373 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001374 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301375 }
Govind Singh6b411b52016-03-06 19:55:02 +05301376
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301377#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301378 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301379 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301380 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301381
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301382 if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301383 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301384 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301385 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301386 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301387 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301388 }
1389 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301390#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301391
Govind Singhb53420c2016-03-09 14:32:57 +05301392 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1393 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301394 "%s, Failed to send cmd %x, no memory",
1395 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301396 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301397 }
1398
Govind Singhb53420c2016-03-09 14:32:57 +05301399 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301400
Govind Singhb53420c2016-03-09 14:32:57 +05301401 qdf_atomic_inc(&wmi_handle->pending_cmds);
1402 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1403 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301404 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301405 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301406 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301407 qdf_atomic_dec(&wmi_handle->pending_cmds);
1408 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301409 "%s: MAX %d WMI Pending cmds reached.", __func__,
1410 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301411 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301412 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301413 }
1414
Govind Singhb53420c2016-03-09 14:32:57 +05301415 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301416 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301417 qdf_atomic_dec(&wmi_handle->pending_cmds);
1418 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301419 "%s, Failed to alloc htc packet %x, no memory",
1420 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301421 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301422 }
1423
1424 SET_HTC_PACKET_INFO_TX(pkt,
1425 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301426 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301427 wmi_handle->wmi_endpoint_id, htc_tag);
1428
1429 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301430#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301431 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301432#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301433
1434#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301435 if (wmi_handle->log_info.wmi_logging_enable) {
1436 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
jiad36c94d22018-01-22 15:37:03 +08001437 /*
1438 * Record 16 bytes of WMI cmd data -
1439 * exclude TLV and WMI headers
1440 *
1441 * WMI mgmt command already recorded in wmi_mgmt_cmd_record
1442 */
1443 if (wmi_handle->ops->is_management_record(cmd_id) == false) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301444 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301445 qdf_nbuf_data(buf) +
1446 wmi_handle->log_info.buf_offset_command);
Govind Singhecf03cd2016-05-12 12:45:51 +05301447 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301448 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1449 }
Govind Singh6b411b52016-03-06 19:55:02 +05301450#endif
1451
1452 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1453
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301454 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301455 qdf_atomic_dec(&wmi_handle->pending_cmds);
1456 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301457 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07001458 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301459 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05301460 }
Govind Singh6b411b52016-03-06 19:55:02 +05301461
Govind Singhb53420c2016-03-09 14:32:57 +05301462 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301463}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301464qdf_export_symbol(wmi_unified_cmd_send);
Govind Singh6b411b52016-03-06 19:55:02 +05301465
1466/**
1467 * wmi_unified_get_event_handler_ix() - gives event handler's index
1468 * @wmi_handle: handle to wmi
1469 * @event_id: wmi event id
1470 *
1471 * Return: event handler's index
1472 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001473static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
1474 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301475{
1476 uint32_t idx = 0;
1477 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301478 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301479
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301480 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05301481 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1482 if (wmi_handle->event_id[idx] == event_id &&
1483 wmi_handle->event_handler[idx] != NULL) {
1484 return idx;
1485 }
1486 }
1487
1488 return invalid_idx;
1489}
1490
1491/**
Soumya Bhat488092d2017-03-22 14:41:01 +05301492 * wmi_unified_register_event() - register wmi event handler
1493 * @wmi_handle: handle to wmi
1494 * @event_id: wmi event id
1495 * @handler_func: wmi event handler function
1496 *
1497 * Return: 0 on success
1498 */
1499int wmi_unified_register_event(wmi_unified_t wmi_handle,
1500 uint32_t event_id,
1501 wmi_unified_event_handler handler_func)
1502{
1503 uint32_t idx = 0;
1504 uint32_t evt_id;
1505 struct wmi_soc *soc = wmi_handle->soc;
1506
1507 if (event_id >= wmi_events_max ||
1508 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1509 qdf_print("%s: Event id %d is unavailable\n",
1510 __func__, event_id);
1511 return QDF_STATUS_E_FAILURE;
1512 }
1513 evt_id = wmi_handle->wmi_events[event_id];
1514 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1515 qdf_print("%s : event handler already registered 0x%x\n",
1516 __func__, evt_id);
1517 return QDF_STATUS_E_FAILURE;
1518 }
1519 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
1520 qdf_print("%s : no more event handlers 0x%x\n",
1521 __func__, evt_id);
1522 return QDF_STATUS_E_FAILURE;
1523 }
1524 idx = soc->max_event_idx;
1525 wmi_handle->event_handler[idx] = handler_func;
1526 wmi_handle->event_id[idx] = evt_id;
1527 qdf_spin_lock_bh(&soc->ctx_lock);
1528 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
1529 qdf_spin_unlock_bh(&soc->ctx_lock);
1530 soc->max_event_idx++;
1531
1532 return 0;
1533}
1534
1535/**
Govind Singh6b411b52016-03-06 19:55:02 +05301536 * wmi_unified_register_event_handler() - register wmi event handler
1537 * @wmi_handle: handle to wmi
1538 * @event_id: wmi event id
1539 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301540 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301541 *
Soumya Bhat488092d2017-03-22 14:41:01 +05301542 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05301543 * Return: 0 on success
1544 */
1545int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301546 wmi_conv_event_id event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301547 wmi_unified_event_handler handler_func,
1548 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301549{
1550 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301551 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301552 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301553
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301554 if (event_id >= wmi_events_max ||
1555 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1556 qdf_print("%s: Event id %d is unavailable\n",
1557 __func__, event_id);
1558 return QDF_STATUS_E_FAILURE;
1559 }
1560 evt_id = wmi_handle->wmi_events[event_id];
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301561
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301562 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1563 qdf_print("%s : event handler already registered 0x%x\n",
1564 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301565 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301566 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301567 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301568 qdf_print("%s : no more event handlers 0x%x\n",
1569 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301570 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301571 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07001572 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
1573 "Registered event handler for event 0x%8x\n", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301574 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301575 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301576 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301577 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301578 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301579 qdf_spin_unlock_bh(&soc->ctx_lock);
1580 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05301581
1582 return 0;
1583}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301584qdf_export_symbol(wmi_unified_register_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301585
1586/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301587 * wmi_unified_unregister_event() - unregister wmi event handler
1588 * @wmi_handle: handle to wmi
1589 * @event_id: wmi event id
1590 *
1591 * Return: 0 on success
1592 */
1593int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
1594 uint32_t event_id)
1595{
1596 uint32_t idx = 0;
1597 uint32_t evt_id;
1598 struct wmi_soc *soc = wmi_handle->soc;
1599
1600 if (event_id >= wmi_events_max ||
1601 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1602 qdf_print("%s: Event id %d is unavailable\n",
1603 __func__, event_id);
1604 return QDF_STATUS_E_FAILURE;
1605 }
1606 evt_id = wmi_handle->wmi_events[event_id];
1607
1608 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
1609 if (idx == -1) {
1610 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1611 __func__, evt_id);
1612 return QDF_STATUS_E_FAILURE;
1613 }
1614 wmi_handle->event_handler[idx] = NULL;
1615 wmi_handle->event_id[idx] = 0;
1616 --soc->max_event_idx;
1617 wmi_handle->event_handler[idx] =
1618 wmi_handle->event_handler[soc->max_event_idx];
1619 wmi_handle->event_id[idx] =
1620 wmi_handle->event_id[soc->max_event_idx];
1621
1622 return 0;
1623}
1624
1625/**
Govind Singh6b411b52016-03-06 19:55:02 +05301626 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1627 * @wmi_handle: handle to wmi
1628 * @event_id: wmi event id
1629 *
1630 * Return: 0 on success
1631 */
1632int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301633 wmi_conv_event_id event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301634{
1635 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301636 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301637 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301638
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301639 if (event_id >= wmi_events_max ||
1640 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1641 qdf_print("%s: Event id %d is unavailable\n",
1642 __func__, event_id);
1643 return QDF_STATUS_E_FAILURE;
1644 }
1645 evt_id = wmi_handle->wmi_events[event_id];
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301646
1647 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301648 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301649 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1650 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301651 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301652 }
1653 wmi_handle->event_handler[idx] = NULL;
1654 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301655 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301656 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301657 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301658 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301659 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301660
1661 return 0;
1662}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301663qdf_export_symbol(wmi_unified_unregister_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301664
1665/**
Govind Singhd52faac2016-03-09 12:03:29 +05301666 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301667 * @wmi_handle: handle to wmi
1668 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301669 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301670 *
Govind Singhd52faac2016-03-09 12:03:29 +05301671 * Event process by below function will be in default caller context.
1672 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301673 *
1674 * Return: none
1675 */
Govind Singhd52faac2016-03-09 12:03:29 +05301676static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1677 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301678{
1679 wmi_buf_t evt_buf;
1680 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1681
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301682#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301683 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1684 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1685#else
Govind Singh5eb51532016-03-09 11:34:12 +05301686 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301687 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301688#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301689
Govind Singh6b411b52016-03-06 19:55:02 +05301690 return;
1691}
1692
1693/**
1694 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1695 * @wmi_handle: handle to wmi
1696 * @htc_packet: pointer to htc packet
1697 *
1698 * Event process by below function will be in worker thread context.
1699 * Use this method for events which are not critical and not
1700 * handled in protocol stack.
1701 *
1702 * Return: none
1703 */
1704static void wmi_process_fw_event_worker_thread_ctx
1705 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1706{
1707 wmi_buf_t evt_buf;
Govind Singh6b411b52016-03-06 19:55:02 +05301708
1709 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singh6b411b52016-03-06 19:55:02 +05301710
Govind Singhb53420c2016-03-09 14:32:57 +05301711 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1712 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1713 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001714 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
1715 &wmi_handle->rx_event_work);
1716
Govind Singh6b411b52016-03-06 19:55:02 +05301717 return;
1718}
1719
1720/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301721 * wmi_get_pdev_ep: Get wmi handle based on endpoint
1722 * @soc: handle to wmi soc
1723 * @ep: endpoint id
1724 *
1725 * Return: none
1726 */
1727static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
1728 HTC_ENDPOINT_ID ep)
1729{
1730 uint32_t i;
1731
1732 for (i = 0; i < WMI_MAX_RADIOS; i++)
1733 if (soc->wmi_endpoint_id[i] == ep)
1734 break;
1735
1736 if (i == WMI_MAX_RADIOS)
1737 return NULL;
1738
1739 return soc->wmi_pdev[i];
1740}
1741
1742/**
Govind Singhd52faac2016-03-09 12:03:29 +05301743 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301744 * @ctx: handle to wmi
1745 * @htc_packet: pointer to htc packet
1746 *
Govind Singh6b411b52016-03-06 19:55:02 +05301747 * Return: none
1748 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001749static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301750{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301751 struct wmi_soc *soc = (struct wmi_soc *) ctx;
1752 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05301753 wmi_buf_t evt_buf;
1754 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301755 uint32_t idx = 0;
1756 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301757
1758 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301759
1760 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
1761 if (wmi_handle == NULL) {
1762 qdf_print
1763 ("%s :unable to get wmi_handle to Endpoint %d\n",
1764 __func__, htc_packet->Endpoint);
1765 qdf_nbuf_free(evt_buf);
1766 return;
1767 }
1768
Govind Singhb53420c2016-03-09 14:32:57 +05301769 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301770 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301771 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05301772 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
1773 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301774 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301775 return;
1776 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301777 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301778 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301779 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301780
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001781#ifdef WMI_INTERFACE_EVENT_LOGGING
1782 if (wmi_handle->log_info.wmi_logging_enable) {
1783 uint8_t *data;
1784 data = qdf_nbuf_data(evt_buf);
1785
1786 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1787 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05301788 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
1789 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001790 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1791 }
1792#endif
1793
Govind Singhd52faac2016-03-09 12:03:29 +05301794 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301795 wmi_process_fw_event_worker_thread_ctx
1796 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301797 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1798 wmi_process_fw_event_default_ctx
1799 (wmi_handle, htc_packet, exec_ctx);
1800 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05301801 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
1802 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301803 }
Govind Singhd52faac2016-03-09 12:03:29 +05301804
Govind Singh6b411b52016-03-06 19:55:02 +05301805}
1806
1807/**
1808 * wmi_process_fw_event() - process any fw event
1809 * @wmi_handle: wmi handle
1810 * @evt_buf: fw event buffer
1811 *
Govind Singhd52faac2016-03-09 12:03:29 +05301812 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301813 *
1814 * Return: none
1815 */
1816void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1817{
1818 __wmi_control_rx(wmi_handle, evt_buf);
1819}
1820
1821/**
1822 * __wmi_control_rx() - process serialize wmi event callback
1823 * @wmi_handle: wmi handle
1824 * @evt_buf: fw event buffer
1825 *
1826 * Return: none
1827 */
1828void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1829{
1830 uint32_t id;
1831 uint8_t *data;
1832 uint32_t len;
1833 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301834#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301835 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301836#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301837 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301838
Govind Singhb53420c2016-03-09 14:32:57 +05301839 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301840
Govind Singhb53420c2016-03-09 14:32:57 +05301841 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05301842 goto end;
1843
Govind Singhb53420c2016-03-09 14:32:57 +05301844 data = qdf_nbuf_data(evt_buf);
1845 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301846
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301847#ifndef WMI_NON_TLV_SUPPORT
1848 if (wmi_handle->target_type == WMI_TLV_TARGET) {
1849 /* Validate and pad(if necessary) the TLVs */
1850 tlv_ok_status =
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301851 wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05301852 data, len, id,
1853 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301854 if (tlv_ok_status != 0) {
1855 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1856 "%s: Error: id=0x%d, wmitlv check status=%d\n",
1857 __func__, id, tlv_ok_status);
1858 goto end;
1859 }
Govind Singh6b411b52016-03-06 19:55:02 +05301860 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301861#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301862
Govind Singhd52faac2016-03-09 12:03:29 +05301863 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
1864 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05301865 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301866 "%s : event handler is not registered: event id 0x%x\n",
1867 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05301868 goto end;
1869 }
Govind Singhd52faac2016-03-09 12:03:29 +05301870#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301871 if (wmi_handle->log_info.wmi_logging_enable) {
1872 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1873 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301874 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05301875 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
1876 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301877 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05301878 WMI_EVENT_RECORD(wmi_handle, id, data +
1879 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301880 }
1881 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301882 }
Govind Singhd52faac2016-03-09 12:03:29 +05301883#endif
1884 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301885 if (wmi_handle->target_type == WMI_TLV_TARGET)
1886 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1887 wmi_cmd_struct_ptr, len);
1888 else
1889 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1890 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05301891
Govind Singh6b411b52016-03-06 19:55:02 +05301892end:
Govind Singhd52faac2016-03-09 12:03:29 +05301893 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301894#ifndef WMI_NON_TLV_SUPPORT
1895 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301896 wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301897#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301898
Govind Singhb53420c2016-03-09 14:32:57 +05301899 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301900
Govind Singh6b411b52016-03-06 19:55:02 +05301901}
1902
Arunk Khandavallib6ba21f2017-12-06 15:47:10 +05301903#define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
Govind Singh97b8e7c2017-09-07 18:23:39 +05301904
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05301905static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05301906{
1907 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1908 "%s: Message type %x has exceeded its alloted time of %ds",
1909 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
1910}
1911
1912#ifdef CONFIG_SLUB_DEBUG_ON
1913static void wmi_workqueue_watchdog_bite(void *arg)
1914{
Govind Singhc646e102017-11-21 10:53:40 +05301915 struct wmi_wq_dbg_info *info = arg;
1916
1917 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
1918 qdf_print_thread_trace(info->task);
1919
Govind Singh97b8e7c2017-09-07 18:23:39 +05301920 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1921 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
1922 QDF_BUG(0);
1923}
1924#else
1925static inline void wmi_workqueue_watchdog_bite(void *arg)
1926{
Govind Singhc646e102017-11-21 10:53:40 +05301927 struct wmi_wq_dbg_info *info = arg;
1928
1929 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301930}
1931#endif
1932
Govind Singh6b411b52016-03-06 19:55:02 +05301933/**
1934 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001935 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05301936 *
1937 * This function process any fw event to serialize it through rx worker thread.
1938 *
1939 * Return: none
1940 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001941static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05301942{
Govind Singh6b411b52016-03-06 19:55:02 +05301943 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001944 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05301945 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05301946 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05301947
Govind Singh97b8e7c2017-09-07 18:23:39 +05301948 /* initialize WMI workqueue watchdog timer */
1949 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05301950 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05301951 qdf_spin_lock_bh(&wmi->eventq_lock);
1952 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1953 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301954 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05301955 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05301956 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05301957 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05301958 info.wmi_wq = wmi->wmi_rx_work_queue;
1959 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05301960 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301961 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05301962 qdf_spin_lock_bh(&wmi->eventq_lock);
1963 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1964 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301965 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05301966 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05301967}
1968
Govind Singh6b411b52016-03-06 19:55:02 +05301969#ifdef FEATURE_RUNTIME_PM
1970/**
1971 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
1972 * @wmi_handle: wmi context
1973 */
Govind Singhd52faac2016-03-09 12:03:29 +05301974static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301975{
Govind Singhb53420c2016-03-09 14:32:57 +05301976 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05301977}
Govind Singhd52faac2016-03-09 12:03:29 +05301978
1979/**
1980 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
1981 * @wmi_handle: wmi context
1982 * @val: runtime pm progress flag
1983 */
1984void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
1985{
Govind Singhb53420c2016-03-09 14:32:57 +05301986 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05301987}
1988
1989/**
1990 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
1991 * @wmi_handle: wmi context
1992 */
1993inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
1994{
Govind Singhb53420c2016-03-09 14:32:57 +05301995 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05301996}
Govind Singh6b411b52016-03-06 19:55:02 +05301997#else
Govind Singhd52faac2016-03-09 12:03:29 +05301998static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301999{
2000}
2001#endif
2002
2003/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302004 * wmi_unified_get_soc_handle: Get WMI SoC handle
2005 * @param wmi_handle: WMI context got from wmi_attach
2006 *
2007 * return: Pointer to Soc handle
2008 */
2009void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2010{
2011 return wmi_handle->soc;
2012}
2013
2014/**
2015 * wmi_interface_logging_init: Interface looging init
2016 * @param wmi_handle: Pointer to wmi handle object
2017 *
2018 * return: None
2019 */
2020#ifdef WMI_INTERFACE_EVENT_LOGGING
2021static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2022{
2023 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2024 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2025 wmi_debugfs_init(wmi_handle);
2026 }
2027}
2028#else
Rachit Kankane799d2c92018-02-19 11:28:10 +05302029static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302030{
2031}
2032#endif
2033
2034/**
2035 * wmi_target_params_init: Target specific params init
2036 * @param wmi_soc: Pointer to wmi soc object
2037 * @param wmi_handle: Pointer to wmi handle object
2038 *
2039 * return: None
2040 */
2041#ifndef CONFIG_MCL
2042static inline void wmi_target_params_init(struct wmi_soc *soc,
2043 struct wmi_unified *wmi_handle)
2044{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302045 wmi_handle->pdev_param = soc->pdev_param;
2046 wmi_handle->vdev_param = soc->vdev_param;
Kris Muthusamy76e22412018-01-26 16:18:37 -08002047 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302048}
2049#else
2050static inline void wmi_target_params_init(struct wmi_soc *soc,
2051 struct wmi_unified *wmi_handle)
2052{
Kris Muthusamy76e22412018-01-26 16:18:37 -08002053 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302054}
2055#endif
2056
2057/**
2058 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2059 * @param wmi_soc: Pointer to wmi soc object
2060 * @param pdev_idx: pdev index
2061 *
2062 * return: Pointer to wmi handle or NULL on failure
2063 */
2064void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2065{
2066 struct wmi_unified *wmi_handle;
2067
2068 if (pdev_idx >= WMI_MAX_RADIOS)
2069 return NULL;
2070
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302071 if (soc->wmi_pdev[pdev_idx] == NULL) {
2072 wmi_handle =
2073 (struct wmi_unified *) qdf_mem_malloc(
2074 sizeof(struct wmi_unified));
2075 if (wmi_handle == NULL) {
2076 qdf_print("allocation of wmi handle failed %zu\n",
2077 sizeof(struct wmi_unified));
2078 return NULL;
2079 }
2080 wmi_handle->scn_handle = soc->scn_handle;
2081 wmi_handle->event_id = soc->event_id;
2082 wmi_handle->event_handler = soc->event_handler;
2083 wmi_handle->ctx = soc->ctx;
2084 wmi_handle->ops = soc->ops;
2085 qdf_spinlock_create(&wmi_handle->eventq_lock);
2086 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302087
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302088 qdf_create_work(0, &wmi_handle->rx_event_work,
2089 wmi_rx_event_work, wmi_handle);
2090 wmi_handle->wmi_rx_work_queue =
2091 qdf_create_workqueue("wmi_rx_event_work_queue");
2092 if (NULL == wmi_handle->wmi_rx_work_queue) {
2093 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2094 goto error;
2095 }
2096 wmi_handle->wmi_events = soc->wmi_events;
2097 wmi_target_params_init(soc, wmi_handle);
2098 wmi_interface_logging_init(wmi_handle);
2099 qdf_atomic_init(&wmi_handle->pending_cmds);
2100 qdf_atomic_init(&wmi_handle->is_target_suspended);
2101 wmi_handle->target_type = soc->target_type;
2102 wmi_handle->soc = soc;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002103
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302104 soc->wmi_pdev[pdev_idx] = wmi_handle;
2105 } else
2106 wmi_handle = soc->wmi_pdev[pdev_idx];
2107
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302108 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302109 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2110 wmi_handle->htc_handle = soc->htc_handle;
2111 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302112
2113 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002114
2115error:
2116 qdf_mem_free(wmi_handle);
2117
2118 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302119}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302120qdf_export_symbol(wmi_unified_get_pdev_handle);
2121
2122static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
2123
2124void wmi_unified_register_module(enum wmi_target_type target_type,
2125 void (*wmi_attach)(wmi_unified_t wmi_handle))
2126{
2127 if (target_type < WMI_MAX_TARGET_TYPE)
2128 wmi_attach_register[target_type] = wmi_attach;
2129
2130 return;
2131}
2132qdf_export_symbol(wmi_unified_register_module);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302133
2134/**
Govind Singh6b411b52016-03-06 19:55:02 +05302135 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302136 * @scn_handle: handle to SCN
2137 * @osdev: OS device context
2138 * @target_type: TLV or not-TLV based target
2139 * @use_cookie: cookie based allocation enabled/disabled
2140 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302141 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302142 *
2143 * @Return: wmi handle.
2144 */
Govind Singhc458f382016-02-04 18:42:30 +05302145void *wmi_unified_attach(void *scn_handle,
2146 osdev_t osdev, enum wmi_target_type target_type,
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302147 bool use_cookie, struct wmi_rx_ops *rx_ops,
2148 struct wlan_objmgr_psoc *psoc)
Govind Singh6b411b52016-03-06 19:55:02 +05302149{
2150 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302151 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302152
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302153 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2154 if (soc == NULL) {
2155 qdf_print("Allocation of wmi_soc failed %zu\n",
2156 sizeof(struct wmi_soc));
2157 return NULL;
2158 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302159
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302160 wmi_handle =
2161 (struct wmi_unified *) qdf_mem_malloc(
2162 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302163 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302164 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302165 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302166 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302167 return NULL;
2168 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302169 wmi_handle->soc = soc;
2170 wmi_handle->event_id = soc->event_id;
2171 wmi_handle->event_handler = soc->event_handler;
2172 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302173 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302174 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302175 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302176 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302177 qdf_atomic_init(&wmi_handle->pending_cmds);
2178 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302179 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302180 qdf_spinlock_create(&wmi_handle->eventq_lock);
2181 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002182 qdf_create_work(0, &wmi_handle->rx_event_work,
2183 wmi_rx_event_work, wmi_handle);
2184 wmi_handle->wmi_rx_work_queue =
2185 qdf_create_workqueue("wmi_rx_event_work_queue");
2186 if (NULL == wmi_handle->wmi_rx_work_queue) {
2187 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2188 goto error;
2189 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302190 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302191 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302192 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2193 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302194 wmi_handle->target_type = target_type;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302195 soc->target_type = target_type;
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302196 if (wmi_attach_register[target_type]) {
2197 wmi_attach_register[target_type](wmi_handle);
2198 } else {
2199 WMI_LOGE("wmi attach is not registered");
2200 goto error;
2201 }
Govind Singhc458f382016-02-04 18:42:30 +05302202 /* Assign target cookie capablity */
2203 wmi_handle->use_cookie = use_cookie;
2204 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302205 wmi_handle->wmi_stopinprogress = 0;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302206 /* Increase the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302207 soc->wmi_psoc = psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302208 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302209
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302210 soc->ops = wmi_handle->ops;
2211 soc->wmi_pdev[0] = wmi_handle;
2212
Govind Singh6b411b52016-03-06 19:55:02 +05302213 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002214
2215error:
2216 qdf_mem_free(soc);
2217 qdf_mem_free(wmi_handle);
2218
2219 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302220}
2221
2222/**
2223 * wmi_unified_detach() - detach for unified WMI
2224 *
2225 * @wmi_handle : handle to wmi.
2226 *
2227 * @Return: none.
2228 */
2229void wmi_unified_detach(struct wmi_unified *wmi_handle)
2230{
2231 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302232 struct wmi_soc *soc;
2233 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302234
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302235 soc = wmi_handle->soc;
2236 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2237 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002238 qdf_flush_workqueue(0,
2239 soc->wmi_pdev[i]->wmi_rx_work_queue);
2240 qdf_destroy_workqueue(0,
2241 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302242 wmi_debugfs_remove(soc->wmi_pdev[i]);
2243 buf = qdf_nbuf_queue_remove(
2244 &soc->wmi_pdev[i]->event_queue);
2245 while (buf) {
2246 qdf_nbuf_free(buf);
2247 buf = qdf_nbuf_queue_remove(
2248 &soc->wmi_pdev[i]->event_queue);
2249 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002250
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302251 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002252
2253 /* Free events logs list */
2254 if (soc->wmi_pdev[i]->events_logs_list)
2255 qdf_mem_free(
2256 soc->wmi_pdev[i]->events_logs_list);
2257
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302258 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302259 qdf_mem_free(soc->wmi_pdev[i]);
2260 }
Govind Singh6b411b52016-03-06 19:55:02 +05302261 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302262 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302263
2264 if (soc->wmi_service_bitmap) {
2265 qdf_mem_free(soc->wmi_service_bitmap);
2266 soc->wmi_service_bitmap = NULL;
2267 }
2268
2269 if (soc->wmi_ext_service_bitmap) {
2270 qdf_mem_free(soc->wmi_ext_service_bitmap);
2271 soc->wmi_ext_service_bitmap = NULL;
2272 }
2273
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302274 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302275 soc->wmi_psoc = NULL;
2276 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302277}
2278
2279/**
2280 * wmi_unified_remove_work() - detach for WMI work
2281 * @wmi_handle: handle to WMI
2282 *
2283 * A function that does not fully detach WMI, but just remove work
2284 * queue items associated with it. This is used to make sure that
2285 * before any other processing code that may destroy related contexts
2286 * (HTC, etc), work queue processing on WMI has already been stopped.
2287 *
2288 * Return: None
2289 */
2290void
2291wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2292{
2293 wmi_buf_t buf;
2294
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002295 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302296 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2297 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302298 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302299 qdf_nbuf_free(buf);
2300 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302301 }
Govind Singhb53420c2016-03-09 14:32:57 +05302302 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302303}
2304
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302305/**
2306 * wmi_htc_tx_complete() - Process htc tx completion
2307 *
2308 * @ctx: handle to wmi
2309 * @htc_packet: pointer to htc packet
2310 *
2311 * @Return: none.
2312 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002313static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302314{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302315 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302316 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302317 u_int8_t *buf_ptr;
2318 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302319 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302320#ifdef WMI_INTERFACE_EVENT_LOGGING
2321 uint32_t cmd_id;
2322#endif
2323
2324 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302325 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2326 if (wmi_handle == NULL) {
2327 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2328 QDF_ASSERT(0);
2329 return;
2330 }
Govind Singh6b411b52016-03-06 19:55:02 +05302331#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302332 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302333 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2334 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302335
Govind Singhecf03cd2016-05-12 12:45:51 +05302336 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302337 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302338 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302339 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302340 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302341 qdf_nbuf_data(wmi_cmd_buf) +
2342 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302343 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302344 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302345 qdf_nbuf_data(wmi_cmd_buf) +
2346 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302347 }
2348
Govind Singhecf03cd2016-05-12 12:45:51 +05302349 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2350 }
Govind Singh6b411b52016-03-06 19:55:02 +05302351#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302352 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2353 len = qdf_nbuf_len(wmi_cmd_buf);
2354 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302355 qdf_nbuf_free(wmi_cmd_buf);
2356 qdf_mem_free(htc_pkt);
2357 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302358}
2359
2360/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302361 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302362 *
2363 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302364 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302365 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302366 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302367 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302368static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2369 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302370{
Govind Singh6b411b52016-03-06 19:55:02 +05302371 int status;
Manikandan Mohanf940db82017-04-13 20:19:26 -07002372 struct htc_service_connect_resp response;
2373 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302374
2375 OS_MEMZERO(&connect, sizeof(connect));
2376 OS_MEMZERO(&response, sizeof(response));
2377
2378 /* meta data is unused for now */
2379 connect.pMetaData = NULL;
2380 connect.MetaDataLength = 0;
2381 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302382 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302383 connect.EpCallbacks.EpTxCompleteMultiple =
2384 NULL /* Control path completion ar6000_tx_complete */;
2385 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2386 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2387 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2388 connect.EpCallbacks.EpTxComplete =
2389 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2390
2391 /* connect to control service */
Pratik Gandhicf3b8b92018-02-05 17:22:41 +05302392 connect.service_id = soc->svc_ids[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302393 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302394 &response);
2395
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302396
Govind Singh6b411b52016-03-06 19:55:02 +05302397 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302398 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302399 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302400 status);
2401 return status;
2402 }
Govind Singh6b411b52016-03-06 19:55:02 +05302403
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302404 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2405 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2406
2407 return 0;
2408}
2409
2410/**
2411 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2412 *
2413 * @wmi_handle: handle to WMI.
2414 *
2415 * @Return: status.
2416 */
2417QDF_STATUS
2418wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2419 void *htc_handle)
2420{
2421 uint32_t i;
2422 uint8_t wmi_ep_count;
2423
2424 wmi_handle->soc->htc_handle = htc_handle;
2425
2426 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2427 if (wmi_ep_count > WMI_MAX_RADIOS)
2428 return QDF_STATUS_E_FAULT;
2429
2430 for (i = 0; i < wmi_ep_count; i++)
2431 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2432
2433 wmi_handle->htc_handle = htc_handle;
2434 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2435 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2436
2437 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302438}
2439
2440/**
2441 * wmi_get_host_credits() - WMI API to get updated host_credits
2442 *
2443 * @wmi_handle: handle to WMI.
2444 *
2445 * @Return: updated host_credits.
2446 */
2447int wmi_get_host_credits(wmi_unified_t wmi_handle)
2448{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302449 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302450
2451 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2452 &host_credits);
2453 return host_credits;
2454}
2455
2456/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302457 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2458 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302459 *
2460 * @wmi_handle: handle to WMI.
2461 *
2462 * @Return: Pending Commands in the HTC queue.
2463 */
2464int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2465{
Govind Singhb53420c2016-03-09 14:32:57 +05302466 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302467}
2468
2469/**
2470 * wmi_set_target_suspend() - WMI API to set target suspend state
2471 *
2472 * @wmi_handle: handle to WMI.
2473 * @val: suspend state boolean.
2474 *
2475 * @Return: none.
2476 */
2477void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2478{
Govind Singhb53420c2016-03-09 14:32:57 +05302479 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302480}
2481
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302482/**
2483 * WMI API to set crash injection state
2484 * @param wmi_handle: handle to WMI.
2485 * @param val: crash injection state boolean.
2486 */
2487void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2488{
2489 wmi_handle->tag_crash_inject = flag;
2490}
2491
2492/**
2493 * WMI API to set bus suspend state
2494 * @param wmi_handle: handle to WMI.
2495 * @param val: suspend state boolean.
2496 */
2497void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2498{
2499 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2500}
2501
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302502void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2503{
2504 wmi_handle->tgt_force_assert_enable = val;
2505}
2506
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302507#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302508/**
2509 * API to flush all the previous packets associated with the wmi endpoint
2510 *
2511 * @param wmi_handle : handle to WMI.
2512 */
2513void
2514wmi_flush_endpoint(wmi_unified_t wmi_handle)
2515{
2516 htc_flush_endpoint(wmi_handle->htc_handle,
2517 wmi_handle->wmi_endpoint_id, 0);
2518}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302519qdf_export_symbol(wmi_flush_endpoint);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302520
2521/**
2522 * generic function to block unified WMI command
2523 * @param wmi_handle : handle to WMI.
2524 * @return 0 on success and -ve on failure.
2525 */
2526int
2527wmi_stop(wmi_unified_t wmi_handle)
2528{
2529 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2530 "WMI Stop\n");
2531 wmi_handle->wmi_stopinprogress = 1;
2532 return 0;
2533}
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302534
2535/**
2536 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2537 * By default pdev_id conversion is not done in WMI.
2538 * This API can be used enable conversion in WMI.
2539 * @param wmi_handle : handle to WMI
2540 * Return none
2541 */
2542void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2543{
2544 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302545 wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302546}
2547
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302548#endif