blob: 1db454b923dd1e5cb5c48660051fd897643aaa2a [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
Rakesh Pillai05110462017-12-27 14:08:59 +05302 * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
Govind Singh6b411b52016-03-06 19:55:02 +05303 *
Govind Singh6b411b52016-03-06 19:55:02 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19/*
Govind Singh6b411b52016-03-06 19:55:02 +053020 * Host WMI unified implementation
21 */
Govind Singh6b411b52016-03-06 19:55:02 +053022#include "htc_api.h"
23#include "htc_api.h"
Govind Singh6b411b52016-03-06 19:55:02 +053024#include "wmi_unified_priv.h"
Pratik Gandhi67da1bb2018-01-30 19:05:41 +053025#include "qdf_module.h"
Govind Singh6b411b52016-03-06 19:55:02 +053026
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053027#ifndef WMI_NON_TLV_SUPPORT
28#include "wmi_tlv_helper.h"
29#endif
30
Govind Singhecf03cd2016-05-12 12:45:51 +053031#include <linux/debugfs.h>
32
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053033/* This check for CONFIG_WIN temporary added due to redeclaration compilation
34error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
35which gets included here through ol_if_athvar.h. Eventually it is expected that
36wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
37WMI_CMD_HDR to be defined here. */
38#ifdef CONFIG_WIN
39/* Copied from wmi.h */
40#undef MS
41#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
42#undef SM
43#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
44#undef WO
45#define WO(_f) ((_f##_OFFSET) >> 2)
46
47#undef GET_FIELD
Vivekc5823092018-03-22 23:27:21 +053048#define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053049#undef SET_FIELD
50#define SET_FIELD(_addr, _f, _val) \
Vivekc5823092018-03-22 23:27:21 +053051 (*((uint32_t *)(_addr) + WO(_f)) = \
52 (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053053
54#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
55 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
56
57#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
58 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
59
60#define WMI_EP_APASS 0x0
61#define WMI_EP_LPASS 0x1
62#define WMI_EP_SENSOR 0x2
63
64/*
65 * * Control Path
66 * */
67typedef PREPACK struct {
Vivekc5823092018-03-22 23:27:21 +053068 uint32_t commandId:24,
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053069 reserved:2, /* used for WMI endpoint ID */
70 plt_priv:6; /* platform private */
71} POSTPACK WMI_CMD_HDR; /* used for commands and events */
72
73#define WMI_CMD_HDR_COMMANDID_LSB 0
74#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
75#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
76#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
77#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
78#define WMI_CMD_HDR_PLT_PRIV_LSB 24
79#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
80#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
81/* end of copy wmi.h */
82#endif /* CONFIG_WIN */
83
Rachit Kankane799d2c92018-02-19 11:28:10 +053084#define WMI_MIN_HEAD_ROOM 64
85
86#ifdef WMI_INTERFACE_EVENT_LOGGING
Manikandan Mohan5826ae92016-06-08 16:29:39 -070087#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
88/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +053089static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -070090{
91 va_list args;
92
93 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +053094 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -070095 va_end(args);
96
Pratik Gandhi795ab912017-05-03 20:15:50 +053097 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -070098}
Pratik Gandhi795ab912017-05-03 20:15:50 +053099#else
100#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700101#endif
102
Govind Singhecf03cd2016-05-12 12:45:51 +0530103#ifndef MAX_WMI_INSTANCES
104#ifdef CONFIG_MCL
105#define MAX_WMI_INSTANCES 1
106#else
107#define MAX_WMI_INSTANCES 3
108#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530109#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530110#endif
111
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530112#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530113/* WMI commands */
114uint32_t g_wmi_command_buf_idx = 0;
115struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
116
117/* WMI commands TX completed */
118uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
119struct wmi_command_debug
120 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
121
122/* WMI events when processed */
123uint32_t g_wmi_event_buf_idx = 0;
124struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
125
126/* WMI events when queued */
127uint32_t g_wmi_rx_event_buf_idx = 0;
128struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530129#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530130
Govind Singhecf03cd2016-05-12 12:45:51 +0530131#define WMI_COMMAND_RECORD(h, a, b) { \
132 if (wmi_log_max_entry <= \
133 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
134 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
135 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
136 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
137 .command = a; \
138 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
139 wmi_command_log_buf_info.buf) \
140 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
141 b, wmi_record_max_length); \
142 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
143 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
144 time = qdf_get_log_timestamp(); \
145 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
146 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530147}
148
Govind Singhecf03cd2016-05-12 12:45:51 +0530149#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
150 if (wmi_log_max_entry <= \
151 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530152 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
153 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530154 ((struct wmi_command_debug *)h->log_info. \
155 wmi_command_tx_cmp_log_buf_info.buf) \
156 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
157 p_buf_tail_idx)]. \
158 command = a; \
159 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
160 wmi_command_tx_cmp_log_buf_info.buf) \
161 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
162 p_buf_tail_idx)]. \
163 data, b, wmi_record_max_length); \
164 ((struct wmi_command_debug *)h->log_info. \
165 wmi_command_tx_cmp_log_buf_info.buf) \
166 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
167 p_buf_tail_idx)]. \
168 time = qdf_get_log_timestamp(); \
169 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
170 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530171}
172
Govind Singhecf03cd2016-05-12 12:45:51 +0530173#define WMI_EVENT_RECORD(h, a, b) { \
174 if (wmi_log_max_entry <= \
175 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
176 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
177 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
178 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
179 event = a; \
180 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
181 wmi_event_log_buf_info.buf) \
182 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
183 wmi_record_max_length); \
184 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
185 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530186 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530187 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
188 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530189}
190
Govind Singhecf03cd2016-05-12 12:45:51 +0530191#define WMI_RX_EVENT_RECORD(h, a, b) { \
192 if (wmi_log_max_entry <= \
193 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
194 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
195 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
196 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
197 event = a; \
198 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
199 wmi_rx_event_log_buf_info.buf) \
200 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
201 data, b, wmi_record_max_length); \
202 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
203 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
204 time = qdf_get_log_timestamp(); \
205 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
206 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530207}
Govind Singh6b411b52016-03-06 19:55:02 +0530208
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530209#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530210uint32_t g_wmi_mgmt_command_buf_idx = 0;
211struct
212wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
213
214/* wmi_mgmt commands TX completed */
215uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
216struct wmi_command_debug
217wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
218
219/* wmi_mgmt events when processed */
220uint32_t g_wmi_mgmt_event_buf_idx = 0;
221struct wmi_event_debug
222wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530223#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530224
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530225#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
226 if (wmi_mgmt_log_max_entry <= \
227 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
228 *(h->log_info.wmi_mgmt_command_log_buf_info. \
229 p_buf_tail_idx) = 0; \
230 ((struct wmi_command_debug *)h->log_info. \
231 wmi_mgmt_command_log_buf_info.buf) \
232 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
233 command = a; \
234 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
235 wmi_mgmt_command_log_buf_info.buf) \
236 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
237 data, b, \
238 wmi_record_max_length); \
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 time = qdf_get_log_timestamp(); \
243 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
244 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530245}
246
Govind Singhecf03cd2016-05-12 12:45:51 +0530247#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
248 if (wmi_mgmt_log_max_entry <= \
249 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
250 p_buf_tail_idx)) \
251 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
252 p_buf_tail_idx) = 0; \
253 ((struct wmi_command_debug *)h->log_info. \
254 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
255 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
256 p_buf_tail_idx)].command = a; \
257 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
258 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
259 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
260 p_buf_tail_idx)].data, b, \
261 wmi_record_max_length); \
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)].time = \
266 qdf_get_log_timestamp(); \
267 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
268 p_buf_tail_idx))++; \
269 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530270}
271
Govind Singhecf03cd2016-05-12 12:45:51 +0530272#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
273 if (wmi_mgmt_log_max_entry <= \
274 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
275 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
276 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
277 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
278 .event = a; \
279 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
280 wmi_mgmt_event_log_buf_info.buf) \
281 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
282 data, b, wmi_record_max_length); \
283 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
284 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
285 time = qdf_get_log_timestamp(); \
286 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
287 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530288}
289
Govind Singhecf03cd2016-05-12 12:45:51 +0530290/* These are defined to made it as module param, which can be configured */
291uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
292uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
293uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
294uint32_t wmi_display_size = 100;
295
Govind Singhecf03cd2016-05-12 12:45:51 +0530296/**
297 * wmi_log_init() - Initialize WMI event logging
298 * @wmi_handle: WMI handle.
299 *
300 * Return: Initialization status
301 */
302#ifdef CONFIG_MCL
303static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
304{
305 struct wmi_log_buf_t *cmd_log_buf =
306 &wmi_handle->log_info.wmi_command_log_buf_info;
307 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
308 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
309
310 struct wmi_log_buf_t *event_log_buf =
311 &wmi_handle->log_info.wmi_event_log_buf_info;
312 struct wmi_log_buf_t *rx_event_log_buf =
313 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
314
315 struct wmi_log_buf_t *mgmt_cmd_log_buf =
316 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
317 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
318 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
319 struct wmi_log_buf_t *mgmt_event_log_buf =
320 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
321
322 /* WMI commands */
323 cmd_log_buf->length = 0;
324 cmd_log_buf->buf_tail_idx = 0;
325 cmd_log_buf->buf = wmi_command_log_buffer;
326 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700327 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530328
329 /* WMI commands TX completed */
330 cmd_tx_cmpl_log_buf->length = 0;
331 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
332 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
333 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700334 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530335
336 /* WMI events when processed */
337 event_log_buf->length = 0;
338 event_log_buf->buf_tail_idx = 0;
339 event_log_buf->buf = wmi_event_log_buffer;
340 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700341 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530342
343 /* WMI events when queued */
344 rx_event_log_buf->length = 0;
345 rx_event_log_buf->buf_tail_idx = 0;
346 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
347 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700348 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530349
350 /* WMI Management commands */
351 mgmt_cmd_log_buf->length = 0;
352 mgmt_cmd_log_buf->buf_tail_idx = 0;
353 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
354 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700355 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530356
357 /* WMI Management commands Tx completed*/
358 mgmt_cmd_tx_cmp_log_buf->length = 0;
359 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
360 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
361 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
362 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700363 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530364
365 /* WMI Management events when processed*/
366 mgmt_event_log_buf->length = 0;
367 mgmt_event_log_buf->buf_tail_idx = 0;
368 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
369 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700370 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530371
372 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
373 wmi_handle->log_info.wmi_logging_enable = 1;
374
375 return QDF_STATUS_SUCCESS;
376}
377#else
378static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
379{
380 struct wmi_log_buf_t *cmd_log_buf =
381 &wmi_handle->log_info.wmi_command_log_buf_info;
382 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
383 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
384
385 struct wmi_log_buf_t *event_log_buf =
386 &wmi_handle->log_info.wmi_event_log_buf_info;
387 struct wmi_log_buf_t *rx_event_log_buf =
388 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
389
390 struct wmi_log_buf_t *mgmt_cmd_log_buf =
391 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
392 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
393 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
394 struct wmi_log_buf_t *mgmt_event_log_buf =
395 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
396
397 wmi_handle->log_info.wmi_logging_enable = 0;
398
399 /* WMI commands */
400 cmd_log_buf->length = 0;
401 cmd_log_buf->buf_tail_idx = 0;
402 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
403 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700404 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530405
406 if (!cmd_log_buf->buf) {
407 qdf_print("no memory for WMI command log buffer..\n");
408 return QDF_STATUS_E_NOMEM;
409 }
410 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
411
412 /* WMI commands TX completed */
413 cmd_tx_cmpl_log_buf->length = 0;
414 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
415 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
416 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700417 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530418
419 if (!cmd_tx_cmpl_log_buf->buf) {
420 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
421 return QDF_STATUS_E_NOMEM;
422 }
423 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
424 &cmd_tx_cmpl_log_buf->buf_tail_idx;
425
426 /* WMI events when processed */
427 event_log_buf->length = 0;
428 event_log_buf->buf_tail_idx = 0;
429 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
430 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700431 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530432
433 if (!event_log_buf->buf) {
434 qdf_print("no memory for WMI Event log buffer..\n");
435 return QDF_STATUS_E_NOMEM;
436 }
437 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
438
439 /* WMI events when queued */
440 rx_event_log_buf->length = 0;
441 rx_event_log_buf->buf_tail_idx = 0;
442 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
443 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700444 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530445
446 if (!rx_event_log_buf->buf) {
447 qdf_print("no memory for WMI Event Rx log buffer..\n");
448 return QDF_STATUS_E_NOMEM;
449 }
450 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
451
452 /* WMI Management commands */
453 mgmt_cmd_log_buf->length = 0;
454 mgmt_cmd_log_buf->buf_tail_idx = 0;
455 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700456 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
457 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530458
459 if (!mgmt_cmd_log_buf->buf) {
460 qdf_print("no memory for WMI Management Command log buffer..\n");
461 return QDF_STATUS_E_NOMEM;
462 }
463 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
464
465 /* WMI Management commands Tx completed*/
466 mgmt_cmd_tx_cmp_log_buf->length = 0;
467 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
468 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
469 qdf_mem_malloc(
470 wmi_mgmt_log_max_entry *
471 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700472 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530473
474 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
475 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
476 return QDF_STATUS_E_NOMEM;
477 }
478 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
479 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
480
481 /* WMI Management events when processed*/
482 mgmt_event_log_buf->length = 0;
483 mgmt_event_log_buf->buf_tail_idx = 0;
484
485 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
486 wmi_mgmt_log_max_entry *
487 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700488 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530489
490 if (!mgmt_event_log_buf->buf) {
491 qdf_print("no memory for WMI Management Event log buffer..\n");
492 return QDF_STATUS_E_NOMEM;
493 }
494 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
495
496 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
497 wmi_handle->log_info.wmi_logging_enable = 1;
498
499 return QDF_STATUS_SUCCESS;
500}
501#endif
502
503/**
504 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
505 * event logging
506 * @wmi_handle: WMI handle.
507 *
508 * Return: None
509 */
510#ifndef CONFIG_MCL
511static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
512{
513 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
514 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
515 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
516 qdf_mem_free(
517 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
518 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
519 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
520 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
521 qdf_mem_free(
522 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
523 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
524 qdf_mem_free(
525 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
526 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
527 qdf_mem_free(
528 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
529 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
530 qdf_mem_free(
531 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
532 wmi_handle->log_info.wmi_logging_enable = 0;
533 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
534}
535#else
536static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
537{
538 /* Do Nothing */
539}
540#endif
541
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700542/**
543 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
544 * @log_buffer: the command log buffer metadata of the buffer to print
545 * @count: the maximum number of entries to print
546 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
547 * @print_priv: any data required by the print method, e.g. a file handle
548 *
549 * Return: None
550 */
551static void
552wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
553 qdf_abstract_print *print, void *print_priv)
554{
555 static const int data_len =
556 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
557 char str[128];
558 uint32_t idx;
559
560 if (count > log_buffer->size)
561 count = log_buffer->size;
562 if (count > log_buffer->length)
563 count = log_buffer->length;
564
565 /* subtract count from index, and wrap if necessary */
566 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
567 idx %= log_buffer->size;
568
569 print(print_priv, "Time (seconds) Cmd Id Payload");
570 while (count) {
571 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
572 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700573 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700574 int len = 0;
575 int i;
576
Dustin Brown8ea39122017-04-10 13:26:56 -0700577 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700578 len += scnprintf(str + len, sizeof(str) - len,
579 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700580 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700581 cmd_log->command, cmd_log->command);
582 for (i = 0; i < data_len; ++i) {
583 len += scnprintf(str + len, sizeof(str) - len,
584 "0x%08x ", cmd_log->data[i]);
585 }
586
587 print(print_priv, str);
588
589 --count;
590 ++idx;
591 if (idx >= log_buffer->size)
592 idx = 0;
593 }
594}
595
596/**
597 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
598 * @log_buffer: the event log buffer metadata of the buffer to print
599 * @count: the maximum number of entries to print
600 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
601 * @print_priv: any data required by the print method, e.g. a file handle
602 *
603 * Return: None
604 */
605static void
606wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
607 qdf_abstract_print *print, void *print_priv)
608{
609 static const int data_len =
610 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
611 char str[128];
612 uint32_t idx;
613
614 if (count > log_buffer->size)
615 count = log_buffer->size;
616 if (count > log_buffer->length)
617 count = log_buffer->length;
618
619 /* subtract count from index, and wrap if necessary */
620 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
621 idx %= log_buffer->size;
622
623 print(print_priv, "Time (seconds) Event Id Payload");
624 while (count) {
625 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
626 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700627 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700628 int len = 0;
629 int i;
630
Dustin Brown8ea39122017-04-10 13:26:56 -0700631 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700632 len += scnprintf(str + len, sizeof(str) - len,
633 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700634 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700635 event_log->event, event_log->event);
636 for (i = 0; i < data_len; ++i) {
637 len += scnprintf(str + len, sizeof(str) - len,
638 "0x%08x ", event_log->data[i]);
639 }
640
641 print(print_priv, str);
642
643 --count;
644 ++idx;
645 if (idx >= log_buffer->size)
646 idx = 0;
647 }
648}
649
650inline void
651wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
652 qdf_abstract_print *print, void *print_priv)
653{
654 wmi_print_cmd_log_buffer(
655 &wmi->log_info.wmi_command_log_buf_info,
656 count, print, print_priv);
657}
658
659inline void
660wmi_print_cmd_tx_cmp_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_tx_cmp_log_buf_info,
665 count, print, print_priv);
666}
667
668inline void
669wmi_print_mgmt_cmd_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_mgmt_command_log_buf_info,
674 count, print, print_priv);
675}
676
677inline void
678wmi_print_mgmt_cmd_tx_cmp_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_tx_cmp_log_buf_info,
683 count, print, print_priv);
684}
685
686inline void
687wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
688 qdf_abstract_print *print, void *print_priv)
689{
690 wmi_print_event_log_buffer(
691 &wmi->log_info.wmi_event_log_buf_info,
692 count, print, print_priv);
693}
694
695inline void
696wmi_print_rx_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_rx_event_log_buf_info,
701 count, print, print_priv);
702}
703
704inline void
705wmi_print_mgmt_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_mgmt_event_log_buf_info,
710 count, print, print_priv);
711}
712
Govind Singhecf03cd2016-05-12 12:45:51 +0530713#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530714const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530715#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530716const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530717#endif
718
719/* debugfs routines*/
720
721/**
722 * debug_wmi_##func_base##_show() - debugfs functions to display content of
723 * command and event buffers. Macro uses max buffer length to display
724 * buffer when it is wraparound.
725 *
726 * @m: debugfs handler to access wmi_handle
727 * @v: Variable arguments (not used)
728 *
729 * Return: Length of characters printed
730 */
731#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
732 static int debug_wmi_##func_base##_show(struct seq_file *m, \
733 void *v) \
734 { \
735 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
736 struct wmi_log_buf_t *wmi_log = \
737 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
738 int pos, nread, outlen; \
739 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800740 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530741 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530742 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
743 if (!wmi_log->length) { \
744 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530745 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530746 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530747 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530748 \
749 if (wmi_log->length <= wmi_ring_size) \
750 nread = wmi_log->length; \
751 else \
752 nread = wmi_ring_size; \
753 \
754 if (*(wmi_log->p_buf_tail_idx) == 0) \
755 /* tail can be 0 after wrap-around */ \
756 pos = wmi_ring_size - 1; \
757 else \
758 pos = *(wmi_log->p_buf_tail_idx) - 1; \
759 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530760 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530761 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530762 while (nread--) { \
763 struct wmi_command_debug *wmi_record; \
764 \
765 wmi_record = (struct wmi_command_debug *) \
766 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530767 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530768 (wmi_record->command)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800769 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
770 &usecs); \
771 outlen += \
772 wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
773 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530774 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530775 for (i = 0; i < (wmi_record_max_length/ \
776 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530777 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530778 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530779 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530780 \
781 if (pos == 0) \
782 pos = wmi_ring_size - 1; \
783 else \
784 pos--; \
785 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530786 return outlen; \
787 } \
788
789#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
790 static int debug_wmi_##func_base##_show(struct seq_file *m, \
791 void *v) \
792 { \
793 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
794 struct wmi_log_buf_t *wmi_log = \
795 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
796 int pos, nread, outlen; \
797 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800798 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530799 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530800 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
801 if (!wmi_log->length) { \
802 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530803 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530804 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530805 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530806 \
807 if (wmi_log->length <= wmi_ring_size) \
808 nread = wmi_log->length; \
809 else \
810 nread = wmi_ring_size; \
811 \
812 if (*(wmi_log->p_buf_tail_idx) == 0) \
813 /* tail can be 0 after wrap-around */ \
814 pos = wmi_ring_size - 1; \
815 else \
816 pos = *(wmi_log->p_buf_tail_idx) - 1; \
817 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530818 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530819 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530820 while (nread--) { \
821 struct wmi_event_debug *wmi_record; \
822 \
823 wmi_record = (struct wmi_event_debug *) \
824 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
nobelj2a6da6f2017-12-11 23:18:27 -0800825 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
826 &usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530827 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +0530828 (wmi_record->event)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800829 outlen += \
830 wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
831 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530832 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530833 for (i = 0; i < (wmi_record_max_length/ \
834 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530835 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530836 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530837 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530838 \
839 if (pos == 0) \
840 pos = wmi_ring_size - 1; \
841 else \
842 pos--; \
843 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530844 return outlen; \
845 }
846
847GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
848GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
849GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
850GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
851GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
852GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
853 wmi_display_size);
854GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
855
856/**
857 * debug_wmi_enable_show() - debugfs functions to display enable state of
858 * wmi logging feature.
859 *
860 * @m: debugfs handler to access wmi_handle
861 * @v: Variable arguments (not used)
862 *
863 * Return: always 1
864 */
865static int debug_wmi_enable_show(struct seq_file *m, void *v)
866{
867 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
868
Pratik Gandhi795ab912017-05-03 20:15:50 +0530869 return wmi_bp_seq_printf(m, "%d\n",
870 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530871}
872
873/**
874 * debug_wmi_log_size_show() - debugfs functions to display configured size of
875 * wmi logging command/event buffer and management command/event buffer.
876 *
877 * @m: debugfs handler to access wmi_handle
878 * @v: Variable arguments (not used)
879 *
880 * Return: Length of characters printed
881 */
882static int debug_wmi_log_size_show(struct seq_file *m, void *v)
883{
884
Pratik Gandhi795ab912017-05-03 20:15:50 +0530885 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
886 wmi_log_max_entry);
887 return wmi_bp_seq_printf(m,
888 "WMI management command/events log max size:%d\n",
889 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530890}
891
892/**
893 * debug_wmi_##func_base##_write() - debugfs functions to clear
894 * wmi logging command/event buffer and management command/event buffer.
895 *
896 * @file: file handler to access wmi_handle
897 * @buf: received data buffer
898 * @count: length of received buffer
899 * @ppos: Not used
900 *
901 * Return: count
902 */
903#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
904 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
905 const char __user *buf, \
906 size_t count, loff_t *ppos) \
907 { \
908 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530909 wmi_unified_t wmi_handle = \
910 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530911 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
912 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530913 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530914 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530915 if ((!buf) || (count > 50)) \
916 return -EFAULT; \
917 \
918 if (copy_from_user(locbuf, buf, count)) \
919 return -EFAULT; \
920 \
921 ret = sscanf(locbuf, "%d", &k); \
922 if ((ret != 1) || (k != 0)) { \
Govind Singhecf03cd2016-05-12 12:45:51 +0530923 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
924 return -EINVAL; \
925 } \
926 \
927 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
928 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
929 sizeof(struct wmi_record_type)); \
930 wmi_log->length = 0; \
931 *(wmi_log->p_buf_tail_idx) = 0; \
932 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
933 \
934 return count; \
935 }
936
937GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
938 wmi_command_debug);
939GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
940 wmi_command_debug);
941GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
942 wmi_event_debug);
943GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
944 wmi_event_debug);
945GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
946 wmi_command_debug);
947GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
948 wmi_mgmt_log_max_entry, wmi_command_debug);
949GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
950 wmi_event_debug);
951
952/**
953 * debug_wmi_enable_write() - debugfs functions to enable/disable
954 * wmi logging feature.
955 *
956 * @file: file handler to access wmi_handle
957 * @buf: received data buffer
958 * @count: length of received buffer
959 * @ppos: Not used
960 *
961 * Return: count
962 */
963static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
964 size_t count, loff_t *ppos)
965{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530966 wmi_unified_t wmi_handle =
967 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530968 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530969 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530970
Pratik Gandhi795ab912017-05-03 20:15:50 +0530971 if ((!buf) || (count > 50))
972 return -EFAULT;
973
974 if (copy_from_user(locbuf, buf, count))
975 return -EFAULT;
976
977 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530978 if ((ret != 1) || ((k != 0) && (k != 1)))
979 return -EINVAL;
980
981 wmi_handle->log_info.wmi_logging_enable = k;
982 return count;
983}
984
985/**
986 * debug_wmi_log_size_write() - reserved.
987 *
988 * @file: file handler to access wmi_handle
989 * @buf: received data buffer
990 * @count: length of received buffer
991 * @ppos: Not used
992 *
993 * Return: count
994 */
995static ssize_t debug_wmi_log_size_write(struct file *file,
996 const char __user *buf, size_t count, loff_t *ppos)
997{
998 return -EINVAL;
999}
1000
1001/* Structure to maintain debug information */
1002struct wmi_debugfs_info {
1003 const char *name;
1004 struct dentry *de[MAX_WMI_INSTANCES];
1005 const struct file_operations *ops;
1006};
1007
1008#define DEBUG_FOO(func_base) { .name = #func_base, \
1009 .ops = &debug_##func_base##_ops }
1010
1011/**
1012 * debug_##func_base##_open() - Open debugfs entry for respective command
1013 * and event buffer.
1014 *
1015 * @inode: node for debug dir entry
1016 * @file: file handler
1017 *
1018 * Return: open status
1019 */
1020#define GENERATE_DEBUG_STRUCTS(func_base) \
1021 static int debug_##func_base##_open(struct inode *inode, \
1022 struct file *file) \
1023 { \
1024 return single_open(file, debug_##func_base##_show, \
1025 inode->i_private); \
1026 } \
1027 \
1028 \
1029 static struct file_operations debug_##func_base##_ops = { \
1030 .open = debug_##func_base##_open, \
1031 .read = seq_read, \
1032 .llseek = seq_lseek, \
1033 .write = debug_##func_base##_write, \
1034 .release = single_release, \
1035 };
1036
1037GENERATE_DEBUG_STRUCTS(wmi_command_log);
1038GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1039GENERATE_DEBUG_STRUCTS(wmi_event_log);
1040GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1041GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1042GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1043GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1044GENERATE_DEBUG_STRUCTS(wmi_enable);
1045GENERATE_DEBUG_STRUCTS(wmi_log_size);
1046
1047struct wmi_debugfs_info wmi_debugfs_infos[] = {
1048 DEBUG_FOO(wmi_command_log),
1049 DEBUG_FOO(wmi_command_tx_cmp_log),
1050 DEBUG_FOO(wmi_event_log),
1051 DEBUG_FOO(wmi_rx_event_log),
1052 DEBUG_FOO(wmi_mgmt_command_log),
1053 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1054 DEBUG_FOO(wmi_mgmt_event_log),
1055 DEBUG_FOO(wmi_enable),
1056 DEBUG_FOO(wmi_log_size),
1057};
1058
1059#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1060 sizeof(wmi_debugfs_infos[0]))
1061
1062/**
1063 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1064 *
1065 * @wmi_handle: wmi handle
1066 * @par_entry: debug directory entry
1067 * @id: Index to debug info data array
1068 *
1069 * Return: none
1070 */
1071static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1072 struct dentry *par_entry, int id)
1073{
1074 int i;
1075
1076 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1077 goto out;
1078
1079 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1080
1081 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1082 wmi_debugfs_infos[i].name, 0644, par_entry,
1083 wmi_handle, wmi_debugfs_infos[i].ops);
1084
1085 if (wmi_debugfs_infos[i].de[id] == NULL) {
1086 qdf_print("%s: debug Entry creation failed!\n",
1087 __func__);
1088 goto out;
1089 }
1090 }
1091
1092 return;
1093
1094out:
1095 qdf_print("%s: debug Entry creation failed!\n", __func__);
1096 wmi_log_buffer_free(wmi_handle);
1097 return;
1098}
1099
1100/**
1101 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301102 * @wmi_handle: wmi handle
1103 * @dentry: debugfs directory entry
1104 * @id: Index to debug info data array
1105 *
1106 * Return: none
1107 */
Govind Singh06c18392016-06-10 10:33:19 +05301108static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301109{
1110 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301111 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301112 int id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301113
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301114 if (!wmi_handle->log_info.wmi_instance_id)
1115 return;
1116
1117 id = wmi_handle->log_info.wmi_instance_id - 1;
Govind Singhecf03cd2016-05-12 12:45:51 +05301118 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1119 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1120 if (wmi_debugfs_infos[i].de[id])
1121 wmi_debugfs_infos[i].de[id] = NULL;
1122 }
1123 }
1124
1125 if (dentry)
1126 debugfs_remove_recursive(dentry);
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301127
1128 if (wmi_handle->log_info.wmi_instance_id)
1129 wmi_handle->log_info.wmi_instance_id--;
Govind Singhecf03cd2016-05-12 12:45:51 +05301130}
1131
1132/**
1133 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1134 * create debugfs enteries.
1135 *
1136 * @h: wmi handler
1137 *
1138 * Return: init status
1139 */
1140static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1141{
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301142 int wmi_index = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301143
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301144 if (wmi_index < MAX_WMI_INSTANCES) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301145 wmi_handle->log_info.wmi_log_debugfs_dir =
1146 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1147
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301148 if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
1149 qdf_print("error while creating debugfs dir for %s\n",
1150 debugfs_dir[wmi_index]);
1151 return QDF_STATUS_E_FAILURE;
1152 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301153
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301154 wmi_debugfs_create(wmi_handle,
1155 wmi_handle->log_info.wmi_log_debugfs_dir,
1156 wmi_index);
1157 wmi_handle->log_info.wmi_instance_id++;
1158 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301159
1160 return QDF_STATUS_SUCCESS;
1161}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001162
1163/**
1164 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1165 *
1166 * @wmi_handle: wmi handle
1167 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001168 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001169 * @vdev_id: vdev id
1170 * @chanfreq: channel frequency
1171 *
1172 * Return: none
1173 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301174void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001175 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001176{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301177
1178 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1179
1180 data[0] = ((struct wmi_command_header *)header)->type;
1181 data[1] = ((struct wmi_command_header *)header)->sub_type;
1182 data[2] = vdev_id;
1183 data[3] = chanfreq;
1184
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001185 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1186
Rakesh Pillai05110462017-12-27 14:08:59 +05301187 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001188
1189 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1190}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001191#else
1192/**
1193 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1194 * @wmi_handle: wmi handle
1195 * @dentry: debugfs directory entry
1196 * @id: Index to debug info data array
1197 *
1198 * Return: none
1199 */
Govind Singh06c18392016-06-10 10:33:19 +05301200static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301201void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001202 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301203static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301204#endif /*WMI_INTERFACE_EVENT_LOGGING */
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301205qdf_export_symbol(wmi_mgmt_cmd_record);
Govind Singh6b411b52016-03-06 19:55:02 +05301206
Govind Singh6b411b52016-03-06 19:55:02 +05301207int wmi_get_host_credits(wmi_unified_t wmi_handle);
1208/* WMI buffer APIs */
1209
Shiva Krishna Pittala79293372018-04-02 17:23:42 +05301210#ifdef NBUF_MEMORY_DEBUG
Govind Singh6b411b52016-03-06 19:55:02 +05301211wmi_buf_t
1212wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301213 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301214{
1215 wmi_buf_t wmi_buf;
1216
1217 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301218 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301219 return NULL;
1220 }
1221
Govind Singhb53420c2016-03-09 14:32:57 +05301222 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301223 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1224 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1225 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301226
1227 if (!wmi_buf)
1228 return NULL;
1229
1230 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301231 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301232
1233 /*
1234 * Set the length of the buffer to match the allocation size.
1235 */
Govind Singhb53420c2016-03-09 14:32:57 +05301236 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301237
1238 return wmi_buf;
1239}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301240qdf_export_symbol(wmi_buf_alloc_debug);
Govind Singh6b411b52016-03-06 19:55:02 +05301241
1242void wmi_buf_free(wmi_buf_t net_buf)
1243{
Govind Singhb53420c2016-03-09 14:32:57 +05301244 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301245}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301246qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301247#else
1248wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1249{
1250 wmi_buf_t wmi_buf;
1251
1252 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301253 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301254 return NULL;
1255 }
1256
Govind Singhb53420c2016-03-09 14:32:57 +05301257 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301258 WMI_MIN_HEAD_ROOM, 4, false);
1259 if (!wmi_buf)
1260 return NULL;
1261
1262 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301263 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301264
1265 /*
1266 * Set the length of the buffer to match the allocation size.
1267 */
Govind Singhb53420c2016-03-09 14:32:57 +05301268 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301269 return wmi_buf;
1270}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301271qdf_export_symbol(wmi_buf_alloc);
Govind Singh6b411b52016-03-06 19:55:02 +05301272
1273void wmi_buf_free(wmi_buf_t net_buf)
1274{
Govind Singhb53420c2016-03-09 14:32:57 +05301275 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301276}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301277qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301278#endif
1279
1280/**
1281 * wmi_get_max_msg_len() - get maximum WMI message length
1282 * @wmi_handle: WMI handle.
1283 *
1284 * This function returns the maximum WMI message length
1285 *
1286 * Return: maximum WMI message length
1287 */
1288uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1289{
1290 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1291}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301292qdf_export_symbol(wmi_get_max_msg_len);
Govind Singh6b411b52016-03-06 19:55:02 +05301293
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301294#ifndef WMI_CMD_STRINGS
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301295static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301296{
1297 return "Invalid WMI cmd";
1298}
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301299
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301300#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301301
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301302#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301303static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1304{
1305 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1306 wmi_id_to_name(cmd_id), cmd_id, tag);
1307}
1308
Govind Singh6b411b52016-03-06 19:55:02 +05301309/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301310 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1311 * @cmd_id: command to check
1312 *
1313 * Return: true if the command is part of the resume sequence.
1314 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301315static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301316{
1317 switch (cmd_id) {
1318 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1319 case WMI_PDEV_RESUME_CMDID:
1320 return true;
1321
1322 default:
1323 return false;
1324 }
1325}
1326#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301327static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301328{
1329 return false;
1330}
1331#endif
1332
1333/**
Govind Singh6b411b52016-03-06 19:55:02 +05301334 * wmi_unified_cmd_send() - WMI command API
1335 * @wmi_handle: handle to wmi
1336 * @buf: wmi buf
1337 * @len: wmi buffer length
1338 * @cmd_id: wmi command id
1339 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001340 * Note, it is NOT safe to access buf after calling this function!
1341 *
Govind Singh6b411b52016-03-06 19:55:02 +05301342 * Return: 0 on success
1343 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001344QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1345 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301346{
1347 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301348 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301349 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301350
1351 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301352 htc_tag =
Vivekc5823092018-03-22 23:27:21 +05301353 (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301354 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301355 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301356 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301357 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301358 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301359 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301360 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301361 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301362 if (wmi_handle->wmi_stopinprogress) {
1363 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1364 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001365 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301366 }
Govind Singh6b411b52016-03-06 19:55:02 +05301367
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301368#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301369 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301370 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301371 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301372
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301373 if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301374 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301375 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301376 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301377 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301378 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301379 }
1380 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301381#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301382
Govind Singhb53420c2016-03-09 14:32:57 +05301383 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1384 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301385 "%s, Failed to send cmd %x, no memory",
1386 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301387 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301388 }
1389
Vignesh Viswanathan737cef72018-06-15 12:42:45 +05301390 qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
Govind Singhb53420c2016-03-09 14:32:57 +05301391 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301392
Govind Singhb53420c2016-03-09 14:32:57 +05301393 qdf_atomic_inc(&wmi_handle->pending_cmds);
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301394 if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
1395 wmi_handle->wmi_max_cmds) {
Govind Singhb53420c2016-03-09 14:32:57 +05301396 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301397 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301398 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301399 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301400 qdf_atomic_dec(&wmi_handle->pending_cmds);
1401 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301402 "%s: MAX %d WMI Pending cmds reached.", __func__,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301403 wmi_handle->wmi_max_cmds);
Govind Singhb53420c2016-03-09 14:32:57 +05301404 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301405 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301406 }
1407
Govind Singhb53420c2016-03-09 14:32:57 +05301408 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301409 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301410 qdf_atomic_dec(&wmi_handle->pending_cmds);
1411 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301412 "%s, Failed to alloc htc packet %x, no memory",
1413 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301414 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301415 }
1416
1417 SET_HTC_PACKET_INFO_TX(pkt,
1418 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301419 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301420 wmi_handle->wmi_endpoint_id, htc_tag);
1421
1422 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301423#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301424 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301425#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301426
1427#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301428 if (wmi_handle->log_info.wmi_logging_enable) {
1429 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
jiad36c94d22018-01-22 15:37:03 +08001430 /*
1431 * Record 16 bytes of WMI cmd data -
1432 * exclude TLV and WMI headers
1433 *
1434 * WMI mgmt command already recorded in wmi_mgmt_cmd_record
1435 */
1436 if (wmi_handle->ops->is_management_record(cmd_id) == false) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301437 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301438 qdf_nbuf_data(buf) +
1439 wmi_handle->log_info.buf_offset_command);
Govind Singhecf03cd2016-05-12 12:45:51 +05301440 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301441 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1442 }
Govind Singh6b411b52016-03-06 19:55:02 +05301443#endif
1444
1445 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1446
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301447 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301448 qdf_atomic_dec(&wmi_handle->pending_cmds);
1449 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301450 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07001451 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301452 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05301453 }
Govind Singh6b411b52016-03-06 19:55:02 +05301454
Govind Singhb53420c2016-03-09 14:32:57 +05301455 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301456}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301457qdf_export_symbol(wmi_unified_cmd_send);
Govind Singh6b411b52016-03-06 19:55:02 +05301458
1459/**
1460 * wmi_unified_get_event_handler_ix() - gives event handler's index
1461 * @wmi_handle: handle to wmi
1462 * @event_id: wmi event id
1463 *
1464 * Return: event handler's index
1465 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001466static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
1467 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301468{
1469 uint32_t idx = 0;
1470 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301471 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301472
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301473 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05301474 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1475 if (wmi_handle->event_id[idx] == event_id &&
1476 wmi_handle->event_handler[idx] != NULL) {
1477 return idx;
1478 }
1479 }
1480
1481 return invalid_idx;
1482}
1483
1484/**
Soumya Bhat488092d2017-03-22 14:41:01 +05301485 * wmi_unified_register_event() - register wmi event handler
1486 * @wmi_handle: handle to wmi
1487 * @event_id: wmi event id
1488 * @handler_func: wmi event handler function
1489 *
1490 * Return: 0 on success
1491 */
1492int wmi_unified_register_event(wmi_unified_t wmi_handle,
1493 uint32_t event_id,
1494 wmi_unified_event_handler handler_func)
1495{
1496 uint32_t idx = 0;
1497 uint32_t evt_id;
1498 struct wmi_soc *soc = wmi_handle->soc;
1499
1500 if (event_id >= wmi_events_max ||
1501 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1502 qdf_print("%s: Event id %d is unavailable\n",
1503 __func__, event_id);
1504 return QDF_STATUS_E_FAILURE;
1505 }
1506 evt_id = wmi_handle->wmi_events[event_id];
1507 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1508 qdf_print("%s : event handler already registered 0x%x\n",
1509 __func__, evt_id);
1510 return QDF_STATUS_E_FAILURE;
1511 }
1512 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
1513 qdf_print("%s : no more event handlers 0x%x\n",
1514 __func__, evt_id);
1515 return QDF_STATUS_E_FAILURE;
1516 }
1517 idx = soc->max_event_idx;
1518 wmi_handle->event_handler[idx] = handler_func;
1519 wmi_handle->event_id[idx] = evt_id;
1520 qdf_spin_lock_bh(&soc->ctx_lock);
1521 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
1522 qdf_spin_unlock_bh(&soc->ctx_lock);
1523 soc->max_event_idx++;
1524
1525 return 0;
1526}
1527
1528/**
Govind Singh6b411b52016-03-06 19:55:02 +05301529 * wmi_unified_register_event_handler() - register wmi event handler
1530 * @wmi_handle: handle to wmi
1531 * @event_id: wmi event id
1532 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301533 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301534 *
Soumya Bhat488092d2017-03-22 14:41:01 +05301535 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05301536 * Return: 0 on success
1537 */
1538int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301539 wmi_conv_event_id event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301540 wmi_unified_event_handler handler_func,
1541 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301542{
1543 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301544 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301545 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301546
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301547 if (event_id >= wmi_events_max ||
1548 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1549 qdf_print("%s: Event id %d is unavailable\n",
1550 __func__, event_id);
1551 return QDF_STATUS_E_FAILURE;
1552 }
1553 evt_id = wmi_handle->wmi_events[event_id];
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301554
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301555 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1556 qdf_print("%s : event handler already registered 0x%x\n",
1557 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301558 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301559 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301560 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301561 qdf_print("%s : no more event handlers 0x%x\n",
1562 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301563 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301564 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07001565 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
1566 "Registered event handler for event 0x%8x\n", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301567 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301568 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301569 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301570 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301571 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301572 qdf_spin_unlock_bh(&soc->ctx_lock);
1573 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05301574
1575 return 0;
1576}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301577qdf_export_symbol(wmi_unified_register_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301578
1579/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301580 * wmi_unified_unregister_event() - unregister wmi event handler
1581 * @wmi_handle: handle to wmi
1582 * @event_id: wmi event id
1583 *
1584 * Return: 0 on success
1585 */
1586int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
1587 uint32_t event_id)
1588{
1589 uint32_t idx = 0;
1590 uint32_t evt_id;
1591 struct wmi_soc *soc = wmi_handle->soc;
1592
1593 if (event_id >= wmi_events_max ||
1594 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1595 qdf_print("%s: Event id %d is unavailable\n",
1596 __func__, event_id);
1597 return QDF_STATUS_E_FAILURE;
1598 }
1599 evt_id = wmi_handle->wmi_events[event_id];
1600
1601 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
1602 if (idx == -1) {
1603 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1604 __func__, evt_id);
1605 return QDF_STATUS_E_FAILURE;
1606 }
1607 wmi_handle->event_handler[idx] = NULL;
1608 wmi_handle->event_id[idx] = 0;
1609 --soc->max_event_idx;
1610 wmi_handle->event_handler[idx] =
1611 wmi_handle->event_handler[soc->max_event_idx];
1612 wmi_handle->event_id[idx] =
1613 wmi_handle->event_id[soc->max_event_idx];
1614
1615 return 0;
1616}
1617
1618/**
Govind Singh6b411b52016-03-06 19:55:02 +05301619 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1620 * @wmi_handle: handle to wmi
1621 * @event_id: wmi event id
1622 *
1623 * Return: 0 on success
1624 */
1625int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301626 wmi_conv_event_id event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301627{
1628 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301629 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301630 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301631
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301632 if (event_id >= wmi_events_max ||
1633 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1634 qdf_print("%s: Event id %d is unavailable\n",
1635 __func__, event_id);
1636 return QDF_STATUS_E_FAILURE;
1637 }
1638 evt_id = wmi_handle->wmi_events[event_id];
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301639
1640 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301641 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301642 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1643 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301644 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301645 }
1646 wmi_handle->event_handler[idx] = NULL;
1647 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301648 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301649 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301650 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301651 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301652 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301653
1654 return 0;
1655}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301656qdf_export_symbol(wmi_unified_unregister_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301657
1658/**
Govind Singhd52faac2016-03-09 12:03:29 +05301659 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301660 * @wmi_handle: handle to wmi
1661 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301662 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301663 *
Govind Singhd52faac2016-03-09 12:03:29 +05301664 * Event process by below function will be in default caller context.
1665 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301666 *
1667 * Return: none
1668 */
Govind Singhd52faac2016-03-09 12:03:29 +05301669static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1670 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301671{
1672 wmi_buf_t evt_buf;
1673 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1674
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301675#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301676 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1677 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1678#else
Govind Singh5eb51532016-03-09 11:34:12 +05301679 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05301680 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301681#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301682
Govind Singh6b411b52016-03-06 19:55:02 +05301683 return;
1684}
1685
1686/**
1687 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1688 * @wmi_handle: handle to wmi
1689 * @htc_packet: pointer to htc packet
1690 *
1691 * Event process by below function will be in worker thread context.
1692 * Use this method for events which are not critical and not
1693 * handled in protocol stack.
1694 *
1695 * Return: none
1696 */
1697static void wmi_process_fw_event_worker_thread_ctx
1698 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
1699{
1700 wmi_buf_t evt_buf;
Govind Singh6b411b52016-03-06 19:55:02 +05301701
1702 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singh6b411b52016-03-06 19:55:02 +05301703
Govind Singhb53420c2016-03-09 14:32:57 +05301704 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1705 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1706 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001707 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
1708 &wmi_handle->rx_event_work);
1709
Govind Singh6b411b52016-03-06 19:55:02 +05301710 return;
1711}
1712
1713/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301714 * wmi_get_pdev_ep: Get wmi handle based on endpoint
1715 * @soc: handle to wmi soc
1716 * @ep: endpoint id
1717 *
1718 * Return: none
1719 */
1720static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
1721 HTC_ENDPOINT_ID ep)
1722{
1723 uint32_t i;
1724
1725 for (i = 0; i < WMI_MAX_RADIOS; i++)
1726 if (soc->wmi_endpoint_id[i] == ep)
1727 break;
1728
1729 if (i == WMI_MAX_RADIOS)
1730 return NULL;
1731
1732 return soc->wmi_pdev[i];
1733}
1734
1735/**
Govind Singhd52faac2016-03-09 12:03:29 +05301736 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301737 * @ctx: handle to wmi
1738 * @htc_packet: pointer to htc packet
1739 *
Govind Singh6b411b52016-03-06 19:55:02 +05301740 * Return: none
1741 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001742static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301743{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301744 struct wmi_soc *soc = (struct wmi_soc *) ctx;
1745 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05301746 wmi_buf_t evt_buf;
1747 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301748 uint32_t idx = 0;
1749 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301750
1751 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301752
1753 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
1754 if (wmi_handle == NULL) {
1755 qdf_print
1756 ("%s :unable to get wmi_handle to Endpoint %d\n",
1757 __func__, htc_packet->Endpoint);
1758 qdf_nbuf_free(evt_buf);
1759 return;
1760 }
1761
Govind Singhb53420c2016-03-09 14:32:57 +05301762 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301763 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301764 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05301765 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
1766 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301767 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301768 return;
1769 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301770 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301771 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301772 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301773
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001774#ifdef WMI_INTERFACE_EVENT_LOGGING
1775 if (wmi_handle->log_info.wmi_logging_enable) {
1776 uint8_t *data;
1777 data = qdf_nbuf_data(evt_buf);
1778
1779 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1780 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05301781 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
1782 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001783 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1784 }
1785#endif
1786
Govind Singhd52faac2016-03-09 12:03:29 +05301787 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301788 wmi_process_fw_event_worker_thread_ctx
1789 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301790 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1791 wmi_process_fw_event_default_ctx
1792 (wmi_handle, htc_packet, exec_ctx);
1793 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05301794 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
1795 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301796 }
Govind Singhd52faac2016-03-09 12:03:29 +05301797
Govind Singh6b411b52016-03-06 19:55:02 +05301798}
1799
1800/**
1801 * wmi_process_fw_event() - process any fw event
1802 * @wmi_handle: wmi handle
1803 * @evt_buf: fw event buffer
1804 *
Govind Singhd52faac2016-03-09 12:03:29 +05301805 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301806 *
1807 * Return: none
1808 */
1809void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1810{
1811 __wmi_control_rx(wmi_handle, evt_buf);
1812}
1813
1814/**
1815 * __wmi_control_rx() - process serialize wmi event callback
1816 * @wmi_handle: wmi handle
1817 * @evt_buf: fw event buffer
1818 *
1819 * Return: none
1820 */
1821void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1822{
1823 uint32_t id;
1824 uint8_t *data;
1825 uint32_t len;
1826 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301827#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301828 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301829#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301830 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301831
Govind Singhb53420c2016-03-09 14:32:57 +05301832 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301833
Govind Singhb53420c2016-03-09 14:32:57 +05301834 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05301835 goto end;
1836
Govind Singhb53420c2016-03-09 14:32:57 +05301837 data = qdf_nbuf_data(evt_buf);
1838 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301839
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301840#ifndef WMI_NON_TLV_SUPPORT
1841 if (wmi_handle->target_type == WMI_TLV_TARGET) {
1842 /* Validate and pad(if necessary) the TLVs */
1843 tlv_ok_status =
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301844 wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05301845 data, len, id,
1846 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301847 if (tlv_ok_status != 0) {
1848 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1849 "%s: Error: id=0x%d, wmitlv check status=%d\n",
1850 __func__, id, tlv_ok_status);
1851 goto end;
1852 }
Govind Singh6b411b52016-03-06 19:55:02 +05301853 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301854#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301855
Govind Singhd52faac2016-03-09 12:03:29 +05301856 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
1857 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05301858 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301859 "%s : event handler is not registered: event id 0x%x\n",
1860 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05301861 goto end;
1862 }
Govind Singhd52faac2016-03-09 12:03:29 +05301863#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301864 if (wmi_handle->log_info.wmi_logging_enable) {
1865 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1866 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301867 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05301868 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
1869 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301870 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05301871 WMI_EVENT_RECORD(wmi_handle, id, data +
1872 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301873 }
1874 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301875 }
Govind Singhd52faac2016-03-09 12:03:29 +05301876#endif
1877 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301878 if (wmi_handle->target_type == WMI_TLV_TARGET)
1879 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1880 wmi_cmd_struct_ptr, len);
1881 else
1882 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1883 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05301884
Govind Singh6b411b52016-03-06 19:55:02 +05301885end:
Govind Singhd52faac2016-03-09 12:03:29 +05301886 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301887#ifndef WMI_NON_TLV_SUPPORT
1888 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301889 wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301890#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301891
Govind Singhb53420c2016-03-09 14:32:57 +05301892 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301893
Govind Singh6b411b52016-03-06 19:55:02 +05301894}
1895
Arunk Khandavallib6ba21f2017-12-06 15:47:10 +05301896#define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
Govind Singh97b8e7c2017-09-07 18:23:39 +05301897
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05301898static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05301899{
1900 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Kabilan Kannanf1311ec2018-03-08 14:34:28 -08001901 "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
Govind Singh97b8e7c2017-09-07 18:23:39 +05301902 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
1903}
1904
1905#ifdef CONFIG_SLUB_DEBUG_ON
1906static void wmi_workqueue_watchdog_bite(void *arg)
1907{
Govind Singhc646e102017-11-21 10:53:40 +05301908 struct wmi_wq_dbg_info *info = arg;
1909
1910 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
1911 qdf_print_thread_trace(info->task);
1912
Govind Singh97b8e7c2017-09-07 18:23:39 +05301913 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1914 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
1915 QDF_BUG(0);
1916}
1917#else
1918static inline void wmi_workqueue_watchdog_bite(void *arg)
1919{
Govind Singhc646e102017-11-21 10:53:40 +05301920 struct wmi_wq_dbg_info *info = arg;
1921
1922 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301923}
1924#endif
1925
Govind Singh6b411b52016-03-06 19:55:02 +05301926/**
1927 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001928 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05301929 *
1930 * This function process any fw event to serialize it through rx worker thread.
1931 *
1932 * Return: none
1933 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001934static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05301935{
Govind Singh6b411b52016-03-06 19:55:02 +05301936 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001937 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05301938 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05301939 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05301940
Govind Singh97b8e7c2017-09-07 18:23:39 +05301941 /* initialize WMI workqueue watchdog timer */
1942 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05301943 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05301944 qdf_spin_lock_bh(&wmi->eventq_lock);
1945 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1946 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301947 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05301948 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05301949 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05301950 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05301951 info.wmi_wq = wmi->wmi_rx_work_queue;
1952 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05301953 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301954 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05301955 qdf_spin_lock_bh(&wmi->eventq_lock);
1956 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1957 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301958 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05301959 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05301960}
1961
Govind Singh6b411b52016-03-06 19:55:02 +05301962#ifdef FEATURE_RUNTIME_PM
1963/**
1964 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
1965 * @wmi_handle: wmi context
1966 */
Govind Singhd52faac2016-03-09 12:03:29 +05301967static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301968{
Govind Singhb53420c2016-03-09 14:32:57 +05301969 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05301970}
Govind Singhd52faac2016-03-09 12:03:29 +05301971
1972/**
1973 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
1974 * @wmi_handle: wmi context
1975 * @val: runtime pm progress flag
1976 */
1977void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
1978{
Govind Singhb53420c2016-03-09 14:32:57 +05301979 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05301980}
1981
1982/**
1983 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
1984 * @wmi_handle: wmi context
1985 */
1986inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
1987{
Govind Singhb53420c2016-03-09 14:32:57 +05301988 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05301989}
Govind Singh6b411b52016-03-06 19:55:02 +05301990#else
Govind Singhd52faac2016-03-09 12:03:29 +05301991static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301992{
1993}
1994#endif
1995
1996/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301997 * wmi_unified_get_soc_handle: Get WMI SoC handle
1998 * @param wmi_handle: WMI context got from wmi_attach
1999 *
2000 * return: Pointer to Soc handle
2001 */
2002void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2003{
2004 return wmi_handle->soc;
2005}
2006
2007/**
2008 * wmi_interface_logging_init: Interface looging init
2009 * @param wmi_handle: Pointer to wmi handle object
2010 *
2011 * return: None
2012 */
2013#ifdef WMI_INTERFACE_EVENT_LOGGING
2014static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2015{
2016 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2017 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2018 wmi_debugfs_init(wmi_handle);
2019 }
2020}
2021#else
Rachit Kankane799d2c92018-02-19 11:28:10 +05302022static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302023{
2024}
2025#endif
2026
2027/**
2028 * wmi_target_params_init: Target specific params init
2029 * @param wmi_soc: Pointer to wmi soc object
2030 * @param wmi_handle: Pointer to wmi handle object
2031 *
2032 * return: None
2033 */
2034#ifndef CONFIG_MCL
2035static inline void wmi_target_params_init(struct wmi_soc *soc,
2036 struct wmi_unified *wmi_handle)
2037{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302038 wmi_handle->pdev_param = soc->pdev_param;
2039 wmi_handle->vdev_param = soc->vdev_param;
Kris Muthusamy76e22412018-01-26 16:18:37 -08002040 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302041}
2042#else
2043static inline void wmi_target_params_init(struct wmi_soc *soc,
2044 struct wmi_unified *wmi_handle)
2045{
Kris Muthusamy76e22412018-01-26 16:18:37 -08002046 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302047}
2048#endif
2049
2050/**
2051 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2052 * @param wmi_soc: Pointer to wmi soc object
2053 * @param pdev_idx: pdev index
2054 *
2055 * return: Pointer to wmi handle or NULL on failure
2056 */
2057void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2058{
2059 struct wmi_unified *wmi_handle;
2060
2061 if (pdev_idx >= WMI_MAX_RADIOS)
2062 return NULL;
2063
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302064 if (soc->wmi_pdev[pdev_idx] == NULL) {
2065 wmi_handle =
2066 (struct wmi_unified *) qdf_mem_malloc(
2067 sizeof(struct wmi_unified));
2068 if (wmi_handle == NULL) {
2069 qdf_print("allocation of wmi handle failed %zu\n",
2070 sizeof(struct wmi_unified));
2071 return NULL;
2072 }
2073 wmi_handle->scn_handle = soc->scn_handle;
2074 wmi_handle->event_id = soc->event_id;
2075 wmi_handle->event_handler = soc->event_handler;
2076 wmi_handle->ctx = soc->ctx;
2077 wmi_handle->ops = soc->ops;
2078 qdf_spinlock_create(&wmi_handle->eventq_lock);
2079 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302080
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302081 qdf_create_work(0, &wmi_handle->rx_event_work,
2082 wmi_rx_event_work, wmi_handle);
2083 wmi_handle->wmi_rx_work_queue =
2084 qdf_create_workqueue("wmi_rx_event_work_queue");
2085 if (NULL == wmi_handle->wmi_rx_work_queue) {
2086 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2087 goto error;
2088 }
2089 wmi_handle->wmi_events = soc->wmi_events;
2090 wmi_target_params_init(soc, wmi_handle);
2091 wmi_interface_logging_init(wmi_handle);
2092 qdf_atomic_init(&wmi_handle->pending_cmds);
2093 qdf_atomic_init(&wmi_handle->is_target_suspended);
2094 wmi_handle->target_type = soc->target_type;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302095 wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302096 wmi_handle->soc = soc;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002097
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302098 soc->wmi_pdev[pdev_idx] = wmi_handle;
2099 } else
2100 wmi_handle = soc->wmi_pdev[pdev_idx];
2101
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302102 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302103 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2104 wmi_handle->htc_handle = soc->htc_handle;
2105 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302106
2107 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002108
2109error:
2110 qdf_mem_free(wmi_handle);
2111
2112 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302113}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302114qdf_export_symbol(wmi_unified_get_pdev_handle);
2115
2116static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
2117
2118void wmi_unified_register_module(enum wmi_target_type target_type,
2119 void (*wmi_attach)(wmi_unified_t wmi_handle))
2120{
2121 if (target_type < WMI_MAX_TARGET_TYPE)
2122 wmi_attach_register[target_type] = wmi_attach;
2123
2124 return;
2125}
2126qdf_export_symbol(wmi_unified_register_module);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302127
2128/**
Govind Singh6b411b52016-03-06 19:55:02 +05302129 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302130 * @scn_handle: handle to SCN
2131 * @osdev: OS device context
2132 * @target_type: TLV or not-TLV based target
2133 * @use_cookie: cookie based allocation enabled/disabled
2134 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302135 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302136 *
2137 * @Return: wmi handle.
2138 */
Govind Singhc458f382016-02-04 18:42:30 +05302139void *wmi_unified_attach(void *scn_handle,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302140 struct wmi_unified_attach_params *param)
Govind Singh6b411b52016-03-06 19:55:02 +05302141{
2142 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302143 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302144
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302145 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2146 if (soc == NULL) {
2147 qdf_print("Allocation of wmi_soc failed %zu\n",
2148 sizeof(struct wmi_soc));
2149 return NULL;
2150 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302151
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302152 wmi_handle =
2153 (struct wmi_unified *) qdf_mem_malloc(
2154 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302155 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302156 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302157 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302158 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302159 return NULL;
2160 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302161 wmi_handle->soc = soc;
2162 wmi_handle->event_id = soc->event_id;
2163 wmi_handle->event_handler = soc->event_handler;
2164 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302165 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302166 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302167 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302168 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302169 qdf_atomic_init(&wmi_handle->pending_cmds);
2170 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302171 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302172 qdf_spinlock_create(&wmi_handle->eventq_lock);
2173 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002174 qdf_create_work(0, &wmi_handle->rx_event_work,
2175 wmi_rx_event_work, wmi_handle);
2176 wmi_handle->wmi_rx_work_queue =
2177 qdf_create_workqueue("wmi_rx_event_work_queue");
2178 if (NULL == wmi_handle->wmi_rx_work_queue) {
2179 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2180 goto error;
2181 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302182 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302183 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302184 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302185 param->rx_ops->wma_process_fw_event_handler_cbk;
2186 wmi_handle->target_type = param->target_type;
2187 soc->target_type = param->target_type;
Abhiram Jogadenu429ab532018-05-14 17:13:28 +05302188
2189 if (param->target_type >= WMI_MAX_TARGET_TYPE)
2190 goto error;
2191
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302192 if (wmi_attach_register[param->target_type]) {
2193 wmi_attach_register[param->target_type](wmi_handle);
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302194 } else {
2195 WMI_LOGE("wmi attach is not registered");
2196 goto error;
2197 }
Govind Singhc458f382016-02-04 18:42:30 +05302198 /* Assign target cookie capablity */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302199 wmi_handle->use_cookie = param->use_cookie;
2200 wmi_handle->osdev = param->osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302201 wmi_handle->wmi_stopinprogress = 0;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302202 wmi_handle->wmi_max_cmds = param->max_commands;
2203 soc->wmi_max_cmds = param->max_commands;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302204 /* Increase the ref count once refcount infra is present */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302205 soc->wmi_psoc = param->psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302206 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302207
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302208 soc->ops = wmi_handle->ops;
2209 soc->wmi_pdev[0] = wmi_handle;
2210
Govind Singh6b411b52016-03-06 19:55:02 +05302211 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002212
2213error:
2214 qdf_mem_free(soc);
2215 qdf_mem_free(wmi_handle);
2216
2217 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302218}
2219
2220/**
2221 * wmi_unified_detach() - detach for unified WMI
2222 *
2223 * @wmi_handle : handle to wmi.
2224 *
2225 * @Return: none.
2226 */
2227void wmi_unified_detach(struct wmi_unified *wmi_handle)
2228{
2229 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302230 struct wmi_soc *soc;
2231 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302232
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302233 soc = wmi_handle->soc;
2234 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2235 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002236 qdf_flush_workqueue(0,
2237 soc->wmi_pdev[i]->wmi_rx_work_queue);
2238 qdf_destroy_workqueue(0,
2239 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302240 wmi_debugfs_remove(soc->wmi_pdev[i]);
2241 buf = qdf_nbuf_queue_remove(
2242 &soc->wmi_pdev[i]->event_queue);
2243 while (buf) {
2244 qdf_nbuf_free(buf);
2245 buf = qdf_nbuf_queue_remove(
2246 &soc->wmi_pdev[i]->event_queue);
2247 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002248
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302249 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002250
2251 /* Free events logs list */
2252 if (soc->wmi_pdev[i]->events_logs_list)
2253 qdf_mem_free(
2254 soc->wmi_pdev[i]->events_logs_list);
2255
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302256 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302257 qdf_mem_free(soc->wmi_pdev[i]);
2258 }
Govind Singh6b411b52016-03-06 19:55:02 +05302259 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302260 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302261
2262 if (soc->wmi_service_bitmap) {
2263 qdf_mem_free(soc->wmi_service_bitmap);
2264 soc->wmi_service_bitmap = NULL;
2265 }
2266
2267 if (soc->wmi_ext_service_bitmap) {
2268 qdf_mem_free(soc->wmi_ext_service_bitmap);
2269 soc->wmi_ext_service_bitmap = NULL;
2270 }
2271
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302272 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302273 soc->wmi_psoc = NULL;
2274 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302275}
2276
2277/**
2278 * wmi_unified_remove_work() - detach for WMI work
2279 * @wmi_handle: handle to WMI
2280 *
2281 * A function that does not fully detach WMI, but just remove work
2282 * queue items associated with it. This is used to make sure that
2283 * before any other processing code that may destroy related contexts
2284 * (HTC, etc), work queue processing on WMI has already been stopped.
2285 *
2286 * Return: None
2287 */
2288void
2289wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2290{
2291 wmi_buf_t buf;
2292
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002293 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302294 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2295 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302296 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302297 qdf_nbuf_free(buf);
2298 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302299 }
Govind Singhb53420c2016-03-09 14:32:57 +05302300 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302301}
2302
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302303/**
2304 * wmi_htc_tx_complete() - Process htc tx completion
2305 *
2306 * @ctx: handle to wmi
2307 * @htc_packet: pointer to htc packet
2308 *
2309 * @Return: none.
2310 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002311static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302312{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302313 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302314 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302315 u_int8_t *buf_ptr;
2316 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302317 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302318#ifdef WMI_INTERFACE_EVENT_LOGGING
2319 uint32_t cmd_id;
2320#endif
2321
2322 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302323 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2324 if (wmi_handle == NULL) {
2325 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2326 QDF_ASSERT(0);
2327 return;
2328 }
Govind Singh6b411b52016-03-06 19:55:02 +05302329#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302330 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302331 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2332 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302333
Govind Singhecf03cd2016-05-12 12:45:51 +05302334 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302335 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302336 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302337 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302338 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302339 qdf_nbuf_data(wmi_cmd_buf) +
2340 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302341 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302342 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302343 qdf_nbuf_data(wmi_cmd_buf) +
2344 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302345 }
2346
Govind Singhecf03cd2016-05-12 12:45:51 +05302347 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2348 }
Govind Singh6b411b52016-03-06 19:55:02 +05302349#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302350 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2351 len = qdf_nbuf_len(wmi_cmd_buf);
2352 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302353 qdf_nbuf_free(wmi_cmd_buf);
2354 qdf_mem_free(htc_pkt);
2355 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302356}
2357
2358/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302359 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302360 *
2361 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302362 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302363 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302364 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302365 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302366static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2367 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302368{
Govind Singh6b411b52016-03-06 19:55:02 +05302369 int status;
Manikandan Mohanf940db82017-04-13 20:19:26 -07002370 struct htc_service_connect_resp response;
2371 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302372
2373 OS_MEMZERO(&connect, sizeof(connect));
2374 OS_MEMZERO(&response, sizeof(response));
2375
2376 /* meta data is unused for now */
2377 connect.pMetaData = NULL;
2378 connect.MetaDataLength = 0;
2379 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302380 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302381 connect.EpCallbacks.EpTxCompleteMultiple =
2382 NULL /* Control path completion ar6000_tx_complete */;
2383 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2384 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2385 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2386 connect.EpCallbacks.EpTxComplete =
2387 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2388
2389 /* connect to control service */
Pratik Gandhicf3b8b92018-02-05 17:22:41 +05302390 connect.service_id = soc->svc_ids[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302391 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302392 &response);
2393
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302394
Govind Singh6b411b52016-03-06 19:55:02 +05302395 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302396 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302397 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302398 status);
2399 return status;
2400 }
Govind Singh6b411b52016-03-06 19:55:02 +05302401
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302402 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2403 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2404
2405 return 0;
2406}
2407
2408/**
2409 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2410 *
2411 * @wmi_handle: handle to WMI.
2412 *
2413 * @Return: status.
2414 */
2415QDF_STATUS
2416wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2417 void *htc_handle)
2418{
2419 uint32_t i;
2420 uint8_t wmi_ep_count;
2421
2422 wmi_handle->soc->htc_handle = htc_handle;
2423
2424 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2425 if (wmi_ep_count > WMI_MAX_RADIOS)
2426 return QDF_STATUS_E_FAULT;
2427
2428 for (i = 0; i < wmi_ep_count; i++)
2429 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2430
2431 wmi_handle->htc_handle = htc_handle;
2432 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2433 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2434
2435 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302436}
2437
2438/**
2439 * wmi_get_host_credits() - WMI API to get updated host_credits
2440 *
2441 * @wmi_handle: handle to WMI.
2442 *
2443 * @Return: updated host_credits.
2444 */
2445int wmi_get_host_credits(wmi_unified_t wmi_handle)
2446{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302447 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302448
2449 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2450 &host_credits);
2451 return host_credits;
2452}
2453
2454/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302455 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2456 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302457 *
2458 * @wmi_handle: handle to WMI.
2459 *
2460 * @Return: Pending Commands in the HTC queue.
2461 */
2462int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2463{
Govind Singhb53420c2016-03-09 14:32:57 +05302464 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302465}
2466
2467/**
2468 * wmi_set_target_suspend() - WMI API to set target suspend state
2469 *
2470 * @wmi_handle: handle to WMI.
2471 * @val: suspend state boolean.
2472 *
2473 * @Return: none.
2474 */
2475void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2476{
Govind Singhb53420c2016-03-09 14:32:57 +05302477 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302478}
2479
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302480/**
2481 * WMI API to set crash injection state
2482 * @param wmi_handle: handle to WMI.
2483 * @param val: crash injection state boolean.
2484 */
2485void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2486{
2487 wmi_handle->tag_crash_inject = flag;
2488}
2489
2490/**
2491 * WMI API to set bus suspend state
2492 * @param wmi_handle: handle to WMI.
2493 * @param val: suspend state boolean.
2494 */
2495void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2496{
2497 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2498}
2499
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302500void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2501{
2502 wmi_handle->tgt_force_assert_enable = val;
2503}
2504
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002505/**
2506 * wmi_stop() - generic function to block unified WMI command
2507 * @wmi_handle: handle to WMI.
2508 *
2509 * @Return: success always.
2510 */
2511int
2512wmi_stop(wmi_unified_t wmi_handle)
2513{
2514 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2515 "WMI Stop\n");
2516 wmi_handle->wmi_stopinprogress = 1;
2517 return 0;
2518}
2519
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302520#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302521/**
2522 * API to flush all the previous packets associated with the wmi endpoint
2523 *
2524 * @param wmi_handle : handle to WMI.
2525 */
2526void
2527wmi_flush_endpoint(wmi_unified_t wmi_handle)
2528{
2529 htc_flush_endpoint(wmi_handle->htc_handle,
2530 wmi_handle->wmi_endpoint_id, 0);
2531}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302532qdf_export_symbol(wmi_flush_endpoint);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302533
2534/**
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302535 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2536 * By default pdev_id conversion is not done in WMI.
2537 * This API can be used enable conversion in WMI.
2538 * @param wmi_handle : handle to WMI
2539 * Return none
2540 */
2541void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2542{
2543 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302544 wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302545}
2546
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302547#endif