blob: 01f9c35d6287f56874396f5095a879712801ff9c [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
Rakesh Pillai05110462017-12-27 14:08:59 +05302 * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
Govind Singh6b411b52016-03-06 19:55:02 +05303 *
Govind Singh6b411b52016-03-06 19:55:02 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19/*
Govind Singh6b411b52016-03-06 19:55:02 +053020 * Host WMI unified implementation
21 */
Govind Singh6b411b52016-03-06 19:55:02 +053022#include "htc_api.h"
23#include "htc_api.h"
Govind Singh6b411b52016-03-06 19:55:02 +053024#include "wmi_unified_priv.h"
Amar Singhal66d1ed52018-06-26 16:45:54 -070025#include "wmi_unified_api.h"
Pratik Gandhi67da1bb2018-01-30 19:05:41 +053026#include "qdf_module.h"
Govind Singh6b411b52016-03-06 19:55:02 +053027
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053028#ifndef WMI_NON_TLV_SUPPORT
29#include "wmi_tlv_helper.h"
30#endif
31
Govind Singhecf03cd2016-05-12 12:45:51 +053032#include <linux/debugfs.h>
33
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053034/* This check for CONFIG_WIN temporary added due to redeclaration compilation
35error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
36which gets included here through ol_if_athvar.h. Eventually it is expected that
37wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
38WMI_CMD_HDR to be defined here. */
39#ifdef CONFIG_WIN
40/* Copied from wmi.h */
41#undef MS
42#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
43#undef SM
44#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
45#undef WO
46#define WO(_f) ((_f##_OFFSET) >> 2)
47
48#undef GET_FIELD
Vivekc5823092018-03-22 23:27:21 +053049#define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053050#undef SET_FIELD
51#define SET_FIELD(_addr, _f, _val) \
Vivekc5823092018-03-22 23:27:21 +053052 (*((uint32_t *)(_addr) + WO(_f)) = \
53 (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053054
55#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
56 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
57
58#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
59 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
60
61#define WMI_EP_APASS 0x0
62#define WMI_EP_LPASS 0x1
63#define WMI_EP_SENSOR 0x2
64
65/*
66 * * Control Path
67 * */
68typedef PREPACK struct {
Vivekc5823092018-03-22 23:27:21 +053069 uint32_t commandId:24,
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053070 reserved:2, /* used for WMI endpoint ID */
71 plt_priv:6; /* platform private */
72} POSTPACK WMI_CMD_HDR; /* used for commands and events */
73
74#define WMI_CMD_HDR_COMMANDID_LSB 0
75#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
76#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
77#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
78#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
79#define WMI_CMD_HDR_PLT_PRIV_LSB 24
80#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
81#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
82/* end of copy wmi.h */
83#endif /* CONFIG_WIN */
84
Rachit Kankane799d2c92018-02-19 11:28:10 +053085#define WMI_MIN_HEAD_ROOM 64
86
87#ifdef WMI_INTERFACE_EVENT_LOGGING
Manikandan Mohan5826ae92016-06-08 16:29:39 -070088#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
89/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +053090static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -070091{
92 va_list args;
93
94 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +053095 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -070096 va_end(args);
97
Pratik Gandhi795ab912017-05-03 20:15:50 +053098 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -070099}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530100#else
101#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700102#endif
103
Govind Singhecf03cd2016-05-12 12:45:51 +0530104#ifndef MAX_WMI_INSTANCES
105#ifdef CONFIG_MCL
106#define MAX_WMI_INSTANCES 1
107#else
108#define MAX_WMI_INSTANCES 3
109#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530110#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530111#endif
112
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530113#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530114/* WMI commands */
115uint32_t g_wmi_command_buf_idx = 0;
116struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
117
118/* WMI commands TX completed */
119uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
120struct wmi_command_debug
121 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
122
123/* WMI events when processed */
124uint32_t g_wmi_event_buf_idx = 0;
125struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
126
127/* WMI events when queued */
128uint32_t g_wmi_rx_event_buf_idx = 0;
129struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530130#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530131
Govind Singhecf03cd2016-05-12 12:45:51 +0530132#define WMI_COMMAND_RECORD(h, a, b) { \
133 if (wmi_log_max_entry <= \
134 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
135 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
136 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
137 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
138 .command = a; \
139 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
140 wmi_command_log_buf_info.buf) \
141 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
142 b, wmi_record_max_length); \
143 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
144 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
145 time = qdf_get_log_timestamp(); \
146 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
147 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530148}
149
Govind Singhecf03cd2016-05-12 12:45:51 +0530150#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
151 if (wmi_log_max_entry <= \
152 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530153 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
154 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530155 ((struct wmi_command_debug *)h->log_info. \
156 wmi_command_tx_cmp_log_buf_info.buf) \
157 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
158 p_buf_tail_idx)]. \
159 command = a; \
160 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
161 wmi_command_tx_cmp_log_buf_info.buf) \
162 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
163 p_buf_tail_idx)]. \
164 data, b, wmi_record_max_length); \
165 ((struct wmi_command_debug *)h->log_info. \
166 wmi_command_tx_cmp_log_buf_info.buf) \
167 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
168 p_buf_tail_idx)]. \
169 time = qdf_get_log_timestamp(); \
170 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
171 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530172}
173
Govind Singhecf03cd2016-05-12 12:45:51 +0530174#define WMI_EVENT_RECORD(h, a, b) { \
175 if (wmi_log_max_entry <= \
176 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
177 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
178 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
179 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
180 event = a; \
181 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
182 wmi_event_log_buf_info.buf) \
183 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
184 wmi_record_max_length); \
185 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
186 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530187 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530188 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
189 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530190}
191
Govind Singhecf03cd2016-05-12 12:45:51 +0530192#define WMI_RX_EVENT_RECORD(h, a, b) { \
193 if (wmi_log_max_entry <= \
194 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
195 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
196 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
197 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
198 event = a; \
199 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
200 wmi_rx_event_log_buf_info.buf) \
201 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
202 data, b, wmi_record_max_length); \
203 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
204 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
205 time = qdf_get_log_timestamp(); \
206 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
207 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530208}
Govind Singh6b411b52016-03-06 19:55:02 +0530209
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530210#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530211uint32_t g_wmi_mgmt_command_buf_idx = 0;
212struct
213wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
214
215/* wmi_mgmt commands TX completed */
216uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
217struct wmi_command_debug
218wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
219
220/* wmi_mgmt events when processed */
221uint32_t g_wmi_mgmt_event_buf_idx = 0;
222struct wmi_event_debug
223wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530224#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530225
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530226#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
227 if (wmi_mgmt_log_max_entry <= \
228 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
229 *(h->log_info.wmi_mgmt_command_log_buf_info. \
230 p_buf_tail_idx) = 0; \
231 ((struct wmi_command_debug *)h->log_info. \
232 wmi_mgmt_command_log_buf_info.buf) \
233 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
234 command = a; \
235 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
236 wmi_mgmt_command_log_buf_info.buf) \
237 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
238 data, b, \
239 wmi_record_max_length); \
240 ((struct wmi_command_debug *)h->log_info. \
241 wmi_mgmt_command_log_buf_info.buf) \
242 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
243 time = qdf_get_log_timestamp(); \
244 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
245 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530246}
247
Govind Singhecf03cd2016-05-12 12:45:51 +0530248#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
249 if (wmi_mgmt_log_max_entry <= \
250 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
251 p_buf_tail_idx)) \
252 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
253 p_buf_tail_idx) = 0; \
254 ((struct wmi_command_debug *)h->log_info. \
255 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
256 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
257 p_buf_tail_idx)].command = a; \
258 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
259 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
260 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
261 p_buf_tail_idx)].data, b, \
262 wmi_record_max_length); \
263 ((struct wmi_command_debug *)h->log_info. \
264 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
265 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
266 p_buf_tail_idx)].time = \
267 qdf_get_log_timestamp(); \
268 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
269 p_buf_tail_idx))++; \
270 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530271}
272
Govind Singhecf03cd2016-05-12 12:45:51 +0530273#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
274 if (wmi_mgmt_log_max_entry <= \
275 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
276 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
277 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
278 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
279 .event = a; \
280 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
281 wmi_mgmt_event_log_buf_info.buf) \
282 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
283 data, b, wmi_record_max_length); \
284 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
285 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
286 time = qdf_get_log_timestamp(); \
287 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
288 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530289}
290
Govind Singhecf03cd2016-05-12 12:45:51 +0530291/* These are defined to made it as module param, which can be configured */
292uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
293uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
294uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
295uint32_t wmi_display_size = 100;
296
Govind Singhecf03cd2016-05-12 12:45:51 +0530297/**
298 * wmi_log_init() - Initialize WMI event logging
299 * @wmi_handle: WMI handle.
300 *
301 * Return: Initialization status
302 */
303#ifdef CONFIG_MCL
304static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
305{
306 struct wmi_log_buf_t *cmd_log_buf =
307 &wmi_handle->log_info.wmi_command_log_buf_info;
308 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
309 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
310
311 struct wmi_log_buf_t *event_log_buf =
312 &wmi_handle->log_info.wmi_event_log_buf_info;
313 struct wmi_log_buf_t *rx_event_log_buf =
314 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
315
316 struct wmi_log_buf_t *mgmt_cmd_log_buf =
317 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
318 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
319 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
320 struct wmi_log_buf_t *mgmt_event_log_buf =
321 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
322
323 /* WMI commands */
324 cmd_log_buf->length = 0;
325 cmd_log_buf->buf_tail_idx = 0;
326 cmd_log_buf->buf = wmi_command_log_buffer;
327 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700328 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530329
330 /* WMI commands TX completed */
331 cmd_tx_cmpl_log_buf->length = 0;
332 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
333 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
334 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700335 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530336
337 /* WMI events when processed */
338 event_log_buf->length = 0;
339 event_log_buf->buf_tail_idx = 0;
340 event_log_buf->buf = wmi_event_log_buffer;
341 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700342 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530343
344 /* WMI events when queued */
345 rx_event_log_buf->length = 0;
346 rx_event_log_buf->buf_tail_idx = 0;
347 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
348 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700349 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530350
351 /* WMI Management commands */
352 mgmt_cmd_log_buf->length = 0;
353 mgmt_cmd_log_buf->buf_tail_idx = 0;
354 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
355 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700356 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530357
358 /* WMI Management commands Tx completed*/
359 mgmt_cmd_tx_cmp_log_buf->length = 0;
360 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
361 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
362 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
363 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700364 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530365
366 /* WMI Management events when processed*/
367 mgmt_event_log_buf->length = 0;
368 mgmt_event_log_buf->buf_tail_idx = 0;
369 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
370 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700371 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530372
373 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
374 wmi_handle->log_info.wmi_logging_enable = 1;
375
376 return QDF_STATUS_SUCCESS;
377}
378#else
379static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
380{
381 struct wmi_log_buf_t *cmd_log_buf =
382 &wmi_handle->log_info.wmi_command_log_buf_info;
383 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
384 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
385
386 struct wmi_log_buf_t *event_log_buf =
387 &wmi_handle->log_info.wmi_event_log_buf_info;
388 struct wmi_log_buf_t *rx_event_log_buf =
389 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
390
391 struct wmi_log_buf_t *mgmt_cmd_log_buf =
392 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
393 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
394 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
395 struct wmi_log_buf_t *mgmt_event_log_buf =
396 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
397
398 wmi_handle->log_info.wmi_logging_enable = 0;
399
400 /* WMI commands */
401 cmd_log_buf->length = 0;
402 cmd_log_buf->buf_tail_idx = 0;
403 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
404 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700405 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530406
407 if (!cmd_log_buf->buf) {
408 qdf_print("no memory for WMI command log buffer..\n");
409 return QDF_STATUS_E_NOMEM;
410 }
411 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
412
413 /* WMI commands TX completed */
414 cmd_tx_cmpl_log_buf->length = 0;
415 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
416 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
417 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700418 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530419
420 if (!cmd_tx_cmpl_log_buf->buf) {
421 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
422 return QDF_STATUS_E_NOMEM;
423 }
424 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
425 &cmd_tx_cmpl_log_buf->buf_tail_idx;
426
427 /* WMI events when processed */
428 event_log_buf->length = 0;
429 event_log_buf->buf_tail_idx = 0;
430 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
431 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700432 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530433
434 if (!event_log_buf->buf) {
435 qdf_print("no memory for WMI Event log buffer..\n");
436 return QDF_STATUS_E_NOMEM;
437 }
438 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
439
440 /* WMI events when queued */
441 rx_event_log_buf->length = 0;
442 rx_event_log_buf->buf_tail_idx = 0;
443 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
444 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700445 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530446
447 if (!rx_event_log_buf->buf) {
448 qdf_print("no memory for WMI Event Rx log buffer..\n");
449 return QDF_STATUS_E_NOMEM;
450 }
451 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
452
453 /* WMI Management commands */
454 mgmt_cmd_log_buf->length = 0;
455 mgmt_cmd_log_buf->buf_tail_idx = 0;
456 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700457 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
458 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530459
460 if (!mgmt_cmd_log_buf->buf) {
461 qdf_print("no memory for WMI Management Command log buffer..\n");
462 return QDF_STATUS_E_NOMEM;
463 }
464 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
465
466 /* WMI Management commands Tx completed*/
467 mgmt_cmd_tx_cmp_log_buf->length = 0;
468 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
469 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
470 qdf_mem_malloc(
471 wmi_mgmt_log_max_entry *
472 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700473 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530474
475 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
476 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
477 return QDF_STATUS_E_NOMEM;
478 }
479 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
480 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
481
482 /* WMI Management events when processed*/
483 mgmt_event_log_buf->length = 0;
484 mgmt_event_log_buf->buf_tail_idx = 0;
485
486 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
487 wmi_mgmt_log_max_entry *
488 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700489 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530490
491 if (!mgmt_event_log_buf->buf) {
492 qdf_print("no memory for WMI Management Event log buffer..\n");
493 return QDF_STATUS_E_NOMEM;
494 }
495 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
496
497 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
498 wmi_handle->log_info.wmi_logging_enable = 1;
499
500 return QDF_STATUS_SUCCESS;
501}
502#endif
503
504/**
505 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
506 * event logging
507 * @wmi_handle: WMI handle.
508 *
509 * Return: None
510 */
511#ifndef CONFIG_MCL
512static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
513{
514 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
515 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
516 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
517 qdf_mem_free(
518 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
519 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
520 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
521 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
522 qdf_mem_free(
523 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
524 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
525 qdf_mem_free(
526 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
527 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
528 qdf_mem_free(
529 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
530 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
531 qdf_mem_free(
532 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
533 wmi_handle->log_info.wmi_logging_enable = 0;
534 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
535}
536#else
537static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
538{
539 /* Do Nothing */
540}
541#endif
542
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700543/**
544 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
545 * @log_buffer: the command log buffer metadata of the buffer to print
546 * @count: the maximum number of entries to print
547 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
548 * @print_priv: any data required by the print method, e.g. a file handle
549 *
550 * Return: None
551 */
552static void
553wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
554 qdf_abstract_print *print, void *print_priv)
555{
556 static const int data_len =
557 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
558 char str[128];
559 uint32_t idx;
560
561 if (count > log_buffer->size)
562 count = log_buffer->size;
563 if (count > log_buffer->length)
564 count = log_buffer->length;
565
566 /* subtract count from index, and wrap if necessary */
567 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
568 idx %= log_buffer->size;
569
570 print(print_priv, "Time (seconds) Cmd Id Payload");
571 while (count) {
572 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
573 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700574 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700575 int len = 0;
576 int i;
577
Dustin Brown8ea39122017-04-10 13:26:56 -0700578 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700579 len += scnprintf(str + len, sizeof(str) - len,
580 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700581 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700582 cmd_log->command, cmd_log->command);
583 for (i = 0; i < data_len; ++i) {
584 len += scnprintf(str + len, sizeof(str) - len,
585 "0x%08x ", cmd_log->data[i]);
586 }
587
588 print(print_priv, str);
589
590 --count;
591 ++idx;
592 if (idx >= log_buffer->size)
593 idx = 0;
594 }
595}
596
597/**
598 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
599 * @log_buffer: the event log buffer metadata of the buffer to print
600 * @count: the maximum number of entries to print
601 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
602 * @print_priv: any data required by the print method, e.g. a file handle
603 *
604 * Return: None
605 */
606static void
607wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
608 qdf_abstract_print *print, void *print_priv)
609{
610 static const int data_len =
611 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
612 char str[128];
613 uint32_t idx;
614
615 if (count > log_buffer->size)
616 count = log_buffer->size;
617 if (count > log_buffer->length)
618 count = log_buffer->length;
619
620 /* subtract count from index, and wrap if necessary */
621 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
622 idx %= log_buffer->size;
623
624 print(print_priv, "Time (seconds) Event Id Payload");
625 while (count) {
626 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
627 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700628 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700629 int len = 0;
630 int i;
631
Dustin Brown8ea39122017-04-10 13:26:56 -0700632 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700633 len += scnprintf(str + len, sizeof(str) - len,
634 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700635 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700636 event_log->event, event_log->event);
637 for (i = 0; i < data_len; ++i) {
638 len += scnprintf(str + len, sizeof(str) - len,
639 "0x%08x ", event_log->data[i]);
640 }
641
642 print(print_priv, str);
643
644 --count;
645 ++idx;
646 if (idx >= log_buffer->size)
647 idx = 0;
648 }
649}
650
651inline void
652wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
653 qdf_abstract_print *print, void *print_priv)
654{
655 wmi_print_cmd_log_buffer(
656 &wmi->log_info.wmi_command_log_buf_info,
657 count, print, print_priv);
658}
659
660inline void
661wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
662 qdf_abstract_print *print, void *print_priv)
663{
664 wmi_print_cmd_log_buffer(
665 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
666 count, print, print_priv);
667}
668
669inline void
670wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
671 qdf_abstract_print *print, void *print_priv)
672{
673 wmi_print_cmd_log_buffer(
674 &wmi->log_info.wmi_mgmt_command_log_buf_info,
675 count, print, print_priv);
676}
677
678inline void
679wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
680 qdf_abstract_print *print, void *print_priv)
681{
682 wmi_print_cmd_log_buffer(
683 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
684 count, print, print_priv);
685}
686
687inline void
688wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
689 qdf_abstract_print *print, void *print_priv)
690{
691 wmi_print_event_log_buffer(
692 &wmi->log_info.wmi_event_log_buf_info,
693 count, print, print_priv);
694}
695
696inline void
697wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
698 qdf_abstract_print *print, void *print_priv)
699{
700 wmi_print_event_log_buffer(
701 &wmi->log_info.wmi_rx_event_log_buf_info,
702 count, print, print_priv);
703}
704
705inline void
706wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
707 qdf_abstract_print *print, void *print_priv)
708{
709 wmi_print_event_log_buffer(
710 &wmi->log_info.wmi_mgmt_event_log_buf_info,
711 count, print, print_priv);
712}
713
Govind Singhecf03cd2016-05-12 12:45:51 +0530714#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530715const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530716#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530717const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530718#endif
719
720/* debugfs routines*/
721
722/**
723 * debug_wmi_##func_base##_show() - debugfs functions to display content of
724 * command and event buffers. Macro uses max buffer length to display
725 * buffer when it is wraparound.
726 *
727 * @m: debugfs handler to access wmi_handle
728 * @v: Variable arguments (not used)
729 *
730 * Return: Length of characters printed
731 */
732#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
733 static int debug_wmi_##func_base##_show(struct seq_file *m, \
734 void *v) \
735 { \
736 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
737 struct wmi_log_buf_t *wmi_log = \
738 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
739 int pos, nread, outlen; \
740 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800741 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530742 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530743 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
744 if (!wmi_log->length) { \
745 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530746 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530747 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530748 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530749 \
750 if (wmi_log->length <= wmi_ring_size) \
751 nread = wmi_log->length; \
752 else \
753 nread = wmi_ring_size; \
754 \
755 if (*(wmi_log->p_buf_tail_idx) == 0) \
756 /* tail can be 0 after wrap-around */ \
757 pos = wmi_ring_size - 1; \
758 else \
759 pos = *(wmi_log->p_buf_tail_idx) - 1; \
760 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530761 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530762 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530763 while (nread--) { \
764 struct wmi_command_debug *wmi_record; \
765 \
766 wmi_record = (struct wmi_command_debug *) \
767 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530768 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530769 (wmi_record->command)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800770 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
771 &usecs); \
772 outlen += \
773 wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
774 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530775 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530776 for (i = 0; i < (wmi_record_max_length/ \
777 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530778 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530779 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530780 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530781 \
782 if (pos == 0) \
783 pos = wmi_ring_size - 1; \
784 else \
785 pos--; \
786 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530787 return outlen; \
788 } \
789
790#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
791 static int debug_wmi_##func_base##_show(struct seq_file *m, \
792 void *v) \
793 { \
794 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
795 struct wmi_log_buf_t *wmi_log = \
796 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
797 int pos, nread, outlen; \
798 int i; \
nobelj2a6da6f2017-12-11 23:18:27 -0800799 uint64_t secs, usecs; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530800 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530801 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
802 if (!wmi_log->length) { \
803 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530804 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530805 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530806 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530807 \
808 if (wmi_log->length <= wmi_ring_size) \
809 nread = wmi_log->length; \
810 else \
811 nread = wmi_ring_size; \
812 \
813 if (*(wmi_log->p_buf_tail_idx) == 0) \
814 /* tail can be 0 after wrap-around */ \
815 pos = wmi_ring_size - 1; \
816 else \
817 pos = *(wmi_log->p_buf_tail_idx) - 1; \
818 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530819 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530820 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530821 while (nread--) { \
822 struct wmi_event_debug *wmi_record; \
823 \
824 wmi_record = (struct wmi_event_debug *) \
825 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
nobelj2a6da6f2017-12-11 23:18:27 -0800826 qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
827 &usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530828 outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
Govind Singhecf03cd2016-05-12 12:45:51 +0530829 (wmi_record->event)); \
nobelj2a6da6f2017-12-11 23:18:27 -0800830 outlen += \
831 wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
832 secs, usecs); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530833 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530834 for (i = 0; i < (wmi_record_max_length/ \
835 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530836 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530837 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530838 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530839 \
840 if (pos == 0) \
841 pos = wmi_ring_size - 1; \
842 else \
843 pos--; \
844 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530845 return outlen; \
846 }
847
848GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
849GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
850GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
851GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
852GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
853GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
854 wmi_display_size);
855GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
856
857/**
858 * debug_wmi_enable_show() - debugfs functions to display enable state of
859 * wmi logging feature.
860 *
861 * @m: debugfs handler to access wmi_handle
862 * @v: Variable arguments (not used)
863 *
864 * Return: always 1
865 */
866static int debug_wmi_enable_show(struct seq_file *m, void *v)
867{
868 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
869
Pratik Gandhi795ab912017-05-03 20:15:50 +0530870 return wmi_bp_seq_printf(m, "%d\n",
871 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530872}
873
874/**
875 * debug_wmi_log_size_show() - debugfs functions to display configured size of
876 * wmi logging command/event buffer and management command/event buffer.
877 *
878 * @m: debugfs handler to access wmi_handle
879 * @v: Variable arguments (not used)
880 *
881 * Return: Length of characters printed
882 */
883static int debug_wmi_log_size_show(struct seq_file *m, void *v)
884{
885
Pratik Gandhi795ab912017-05-03 20:15:50 +0530886 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
887 wmi_log_max_entry);
888 return wmi_bp_seq_printf(m,
889 "WMI management command/events log max size:%d\n",
890 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530891}
892
893/**
894 * debug_wmi_##func_base##_write() - debugfs functions to clear
895 * wmi logging command/event buffer and management command/event buffer.
896 *
897 * @file: file handler to access wmi_handle
898 * @buf: received data buffer
899 * @count: length of received buffer
900 * @ppos: Not used
901 *
902 * Return: count
903 */
904#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
905 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
906 const char __user *buf, \
907 size_t count, loff_t *ppos) \
908 { \
909 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530910 wmi_unified_t wmi_handle = \
911 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530912 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
913 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530914 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530915 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530916 if ((!buf) || (count > 50)) \
917 return -EFAULT; \
918 \
919 if (copy_from_user(locbuf, buf, count)) \
920 return -EFAULT; \
921 \
922 ret = sscanf(locbuf, "%d", &k); \
923 if ((ret != 1) || (k != 0)) { \
Govind Singhecf03cd2016-05-12 12:45:51 +0530924 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
925 return -EINVAL; \
926 } \
927 \
928 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
929 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
930 sizeof(struct wmi_record_type)); \
931 wmi_log->length = 0; \
932 *(wmi_log->p_buf_tail_idx) = 0; \
933 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
934 \
935 return count; \
936 }
937
938GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
939 wmi_command_debug);
940GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
941 wmi_command_debug);
942GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
943 wmi_event_debug);
944GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
945 wmi_event_debug);
946GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
947 wmi_command_debug);
948GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
949 wmi_mgmt_log_max_entry, wmi_command_debug);
950GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
951 wmi_event_debug);
952
953/**
954 * debug_wmi_enable_write() - debugfs functions to enable/disable
955 * wmi logging feature.
956 *
957 * @file: file handler to access wmi_handle
958 * @buf: received data buffer
959 * @count: length of received buffer
960 * @ppos: Not used
961 *
962 * Return: count
963 */
964static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
965 size_t count, loff_t *ppos)
966{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530967 wmi_unified_t wmi_handle =
968 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530969 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530970 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530971
Pratik Gandhi795ab912017-05-03 20:15:50 +0530972 if ((!buf) || (count > 50))
973 return -EFAULT;
974
975 if (copy_from_user(locbuf, buf, count))
976 return -EFAULT;
977
978 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530979 if ((ret != 1) || ((k != 0) && (k != 1)))
980 return -EINVAL;
981
982 wmi_handle->log_info.wmi_logging_enable = k;
983 return count;
984}
985
986/**
987 * debug_wmi_log_size_write() - reserved.
988 *
989 * @file: file handler to access wmi_handle
990 * @buf: received data buffer
991 * @count: length of received buffer
992 * @ppos: Not used
993 *
994 * Return: count
995 */
996static ssize_t debug_wmi_log_size_write(struct file *file,
997 const char __user *buf, size_t count, loff_t *ppos)
998{
999 return -EINVAL;
1000}
1001
1002/* Structure to maintain debug information */
1003struct wmi_debugfs_info {
1004 const char *name;
1005 struct dentry *de[MAX_WMI_INSTANCES];
1006 const struct file_operations *ops;
1007};
1008
1009#define DEBUG_FOO(func_base) { .name = #func_base, \
1010 .ops = &debug_##func_base##_ops }
1011
1012/**
1013 * debug_##func_base##_open() - Open debugfs entry for respective command
1014 * and event buffer.
1015 *
1016 * @inode: node for debug dir entry
1017 * @file: file handler
1018 *
1019 * Return: open status
1020 */
1021#define GENERATE_DEBUG_STRUCTS(func_base) \
1022 static int debug_##func_base##_open(struct inode *inode, \
1023 struct file *file) \
1024 { \
1025 return single_open(file, debug_##func_base##_show, \
1026 inode->i_private); \
1027 } \
1028 \
1029 \
1030 static struct file_operations debug_##func_base##_ops = { \
1031 .open = debug_##func_base##_open, \
1032 .read = seq_read, \
1033 .llseek = seq_lseek, \
1034 .write = debug_##func_base##_write, \
1035 .release = single_release, \
1036 };
1037
1038GENERATE_DEBUG_STRUCTS(wmi_command_log);
1039GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1040GENERATE_DEBUG_STRUCTS(wmi_event_log);
1041GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1042GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1043GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1044GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1045GENERATE_DEBUG_STRUCTS(wmi_enable);
1046GENERATE_DEBUG_STRUCTS(wmi_log_size);
1047
1048struct wmi_debugfs_info wmi_debugfs_infos[] = {
1049 DEBUG_FOO(wmi_command_log),
1050 DEBUG_FOO(wmi_command_tx_cmp_log),
1051 DEBUG_FOO(wmi_event_log),
1052 DEBUG_FOO(wmi_rx_event_log),
1053 DEBUG_FOO(wmi_mgmt_command_log),
1054 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1055 DEBUG_FOO(wmi_mgmt_event_log),
1056 DEBUG_FOO(wmi_enable),
1057 DEBUG_FOO(wmi_log_size),
1058};
1059
1060#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1061 sizeof(wmi_debugfs_infos[0]))
1062
1063/**
1064 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1065 *
1066 * @wmi_handle: wmi handle
1067 * @par_entry: debug directory entry
1068 * @id: Index to debug info data array
1069 *
1070 * Return: none
1071 */
1072static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1073 struct dentry *par_entry, int id)
1074{
1075 int i;
1076
1077 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1078 goto out;
1079
1080 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1081
1082 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1083 wmi_debugfs_infos[i].name, 0644, par_entry,
1084 wmi_handle, wmi_debugfs_infos[i].ops);
1085
1086 if (wmi_debugfs_infos[i].de[id] == NULL) {
1087 qdf_print("%s: debug Entry creation failed!\n",
1088 __func__);
1089 goto out;
1090 }
1091 }
1092
1093 return;
1094
1095out:
1096 qdf_print("%s: debug Entry creation failed!\n", __func__);
1097 wmi_log_buffer_free(wmi_handle);
1098 return;
1099}
1100
1101/**
1102 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301103 * @wmi_handle: wmi handle
1104 * @dentry: debugfs directory entry
1105 * @id: Index to debug info data array
1106 *
1107 * Return: none
1108 */
Govind Singh06c18392016-06-10 10:33:19 +05301109static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301110{
1111 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301112 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301113 int id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301114
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301115 if (!wmi_handle->log_info.wmi_instance_id)
1116 return;
1117
1118 id = wmi_handle->log_info.wmi_instance_id - 1;
Govind Singhecf03cd2016-05-12 12:45:51 +05301119 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1120 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1121 if (wmi_debugfs_infos[i].de[id])
1122 wmi_debugfs_infos[i].de[id] = NULL;
1123 }
1124 }
1125
1126 if (dentry)
1127 debugfs_remove_recursive(dentry);
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301128
1129 if (wmi_handle->log_info.wmi_instance_id)
1130 wmi_handle->log_info.wmi_instance_id--;
Govind Singhecf03cd2016-05-12 12:45:51 +05301131}
1132
1133/**
1134 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1135 * create debugfs enteries.
1136 *
1137 * @h: wmi handler
1138 *
1139 * Return: init status
1140 */
1141static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1142{
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301143 int wmi_index = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301144
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301145 if (wmi_index < MAX_WMI_INSTANCES) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301146 wmi_handle->log_info.wmi_log_debugfs_dir =
1147 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1148
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301149 if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
1150 qdf_print("error while creating debugfs dir for %s\n",
1151 debugfs_dir[wmi_index]);
1152 return QDF_STATUS_E_FAILURE;
1153 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301154
Rakesh Pillai24c7f8a2017-12-26 19:02:35 +05301155 wmi_debugfs_create(wmi_handle,
1156 wmi_handle->log_info.wmi_log_debugfs_dir,
1157 wmi_index);
1158 wmi_handle->log_info.wmi_instance_id++;
1159 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301160
1161 return QDF_STATUS_SUCCESS;
1162}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001163
1164/**
1165 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1166 *
1167 * @wmi_handle: wmi handle
1168 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001169 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001170 * @vdev_id: vdev id
1171 * @chanfreq: channel frequency
1172 *
1173 * Return: none
1174 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301175void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001176 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001177{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301178
1179 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1180
1181 data[0] = ((struct wmi_command_header *)header)->type;
1182 data[1] = ((struct wmi_command_header *)header)->sub_type;
1183 data[2] = vdev_id;
1184 data[3] = chanfreq;
1185
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001186 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1187
Rakesh Pillai05110462017-12-27 14:08:59 +05301188 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001189
1190 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1191}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001192#else
1193/**
1194 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1195 * @wmi_handle: wmi handle
1196 * @dentry: debugfs directory entry
1197 * @id: Index to debug info data array
1198 *
1199 * Return: none
1200 */
Govind Singh06c18392016-06-10 10:33:19 +05301201static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301202void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001203 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301204static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301205#endif /*WMI_INTERFACE_EVENT_LOGGING */
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301206qdf_export_symbol(wmi_mgmt_cmd_record);
Govind Singh6b411b52016-03-06 19:55:02 +05301207
Govind Singh6b411b52016-03-06 19:55:02 +05301208int wmi_get_host_credits(wmi_unified_t wmi_handle);
1209/* WMI buffer APIs */
1210
Shiva Krishna Pittala79293372018-04-02 17:23:42 +05301211#ifdef NBUF_MEMORY_DEBUG
Govind Singh6b411b52016-03-06 19:55:02 +05301212wmi_buf_t
Debasis Daseaf8a8b2018-04-04 17:17:55 +05301213wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len, uint8_t *file_name,
1214 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301215{
1216 wmi_buf_t wmi_buf;
1217
1218 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301219 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301220 return NULL;
1221 }
1222
Govind Singhb53420c2016-03-09 14:32:57 +05301223 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301224 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1225 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1226 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301227
1228 if (!wmi_buf)
1229 return NULL;
1230
1231 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301232 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301233
1234 /*
1235 * Set the length of the buffer to match the allocation size.
1236 */
Govind Singhb53420c2016-03-09 14:32:57 +05301237 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301238
1239 return wmi_buf;
1240}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301241qdf_export_symbol(wmi_buf_alloc_debug);
Govind Singh6b411b52016-03-06 19:55:02 +05301242
1243void wmi_buf_free(wmi_buf_t net_buf)
1244{
Govind Singhb53420c2016-03-09 14:32:57 +05301245 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301246}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301247qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301248#else
Debasis Daseaf8a8b2018-04-04 17:17:55 +05301249wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint32_t len)
Govind Singh6b411b52016-03-06 19:55:02 +05301250{
1251 wmi_buf_t wmi_buf;
1252
1253 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301254 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301255 return NULL;
1256 }
1257
Govind Singhb53420c2016-03-09 14:32:57 +05301258 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301259 WMI_MIN_HEAD_ROOM, 4, false);
1260 if (!wmi_buf)
1261 return NULL;
1262
1263 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301264 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301265
1266 /*
1267 * Set the length of the buffer to match the allocation size.
1268 */
Govind Singhb53420c2016-03-09 14:32:57 +05301269 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301270 return wmi_buf;
1271}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301272qdf_export_symbol(wmi_buf_alloc);
Govind Singh6b411b52016-03-06 19:55:02 +05301273
1274void wmi_buf_free(wmi_buf_t net_buf)
1275{
Govind Singhb53420c2016-03-09 14:32:57 +05301276 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301277}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301278qdf_export_symbol(wmi_buf_free);
Govind Singh6b411b52016-03-06 19:55:02 +05301279#endif
1280
1281/**
1282 * wmi_get_max_msg_len() - get maximum WMI message length
1283 * @wmi_handle: WMI handle.
1284 *
1285 * This function returns the maximum WMI message length
1286 *
1287 * Return: maximum WMI message length
1288 */
1289uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1290{
1291 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1292}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301293qdf_export_symbol(wmi_get_max_msg_len);
Govind Singh6b411b52016-03-06 19:55:02 +05301294
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301295#ifndef WMI_CMD_STRINGS
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301296static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301297{
1298 return "Invalid WMI cmd";
1299}
Ashish Kumar Dhanotiya4f873ff2017-03-16 18:03:32 +05301300
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301301#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301302
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301303#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301304static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1305{
1306 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1307 wmi_id_to_name(cmd_id), cmd_id, tag);
1308}
1309
Govind Singh6b411b52016-03-06 19:55:02 +05301310/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301311 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1312 * @cmd_id: command to check
1313 *
1314 * Return: true if the command is part of the resume sequence.
1315 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301316static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301317{
1318 switch (cmd_id) {
1319 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1320 case WMI_PDEV_RESUME_CMDID:
1321 return true;
1322
1323 default:
1324 return false;
1325 }
1326}
1327#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301328static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301329{
1330 return false;
1331}
1332#endif
1333
1334/**
Govind Singh6b411b52016-03-06 19:55:02 +05301335 * wmi_unified_cmd_send() - WMI command API
1336 * @wmi_handle: handle to wmi
1337 * @buf: wmi buf
1338 * @len: wmi buffer length
1339 * @cmd_id: wmi command id
1340 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001341 * Note, it is NOT safe to access buf after calling this function!
1342 *
Govind Singh6b411b52016-03-06 19:55:02 +05301343 * Return: 0 on success
1344 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001345QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1346 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301347{
1348 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301349 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301350 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301351
1352 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301353 htc_tag =
Vivekc5823092018-03-22 23:27:21 +05301354 (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301355 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301356 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301357 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301358 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301359 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301360 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301361 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301362 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301363 if (wmi_handle->wmi_stopinprogress) {
1364 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1365 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001366 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301367 }
Govind Singh6b411b52016-03-06 19:55:02 +05301368
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301369#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301370 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301371 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301372 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301373
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301374 if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301375 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301376 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301377 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301378 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301379 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301380 }
1381 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301382#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301383
Govind Singhb53420c2016-03-09 14:32:57 +05301384 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1385 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301386 "%s, Failed to send cmd %x, no memory",
1387 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301388 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301389 }
1390
Vignesh Viswanathan737cef72018-06-15 12:42:45 +05301391 qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
Govind Singhb53420c2016-03-09 14:32:57 +05301392 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301393
Govind Singhb53420c2016-03-09 14:32:57 +05301394 qdf_atomic_inc(&wmi_handle->pending_cmds);
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301395 if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
1396 wmi_handle->wmi_max_cmds) {
Govind Singhb53420c2016-03-09 14:32:57 +05301397 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301398 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301399 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301400 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301401 qdf_atomic_dec(&wmi_handle->pending_cmds);
1402 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301403 "%s: MAX %d WMI Pending cmds reached.", __func__,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05301404 wmi_handle->wmi_max_cmds);
Govind Singhb53420c2016-03-09 14:32:57 +05301405 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301406 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301407 }
1408
Govind Singhb53420c2016-03-09 14:32:57 +05301409 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301410 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301411 qdf_atomic_dec(&wmi_handle->pending_cmds);
1412 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301413 "%s, Failed to alloc htc packet %x, no memory",
1414 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301415 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301416 }
1417
1418 SET_HTC_PACKET_INFO_TX(pkt,
1419 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301420 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301421 wmi_handle->wmi_endpoint_id, htc_tag);
1422
1423 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301424#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301425 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301426#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301427
1428#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301429 if (wmi_handle->log_info.wmi_logging_enable) {
1430 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
jiad36c94d22018-01-22 15:37:03 +08001431 /*
1432 * Record 16 bytes of WMI cmd data -
1433 * exclude TLV and WMI headers
1434 *
1435 * WMI mgmt command already recorded in wmi_mgmt_cmd_record
1436 */
1437 if (wmi_handle->ops->is_management_record(cmd_id) == false) {
Govind Singhecf03cd2016-05-12 12:45:51 +05301438 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05301439 qdf_nbuf_data(buf) +
1440 wmi_handle->log_info.buf_offset_command);
Govind Singhecf03cd2016-05-12 12:45:51 +05301441 }
Govind Singhecf03cd2016-05-12 12:45:51 +05301442 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1443 }
Govind Singh6b411b52016-03-06 19:55:02 +05301444#endif
1445
1446 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
1447
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301448 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05301449 qdf_atomic_dec(&wmi_handle->pending_cmds);
1450 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301451 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07001452 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301453 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05301454 }
Govind Singh6b411b52016-03-06 19:55:02 +05301455
Govind Singhb53420c2016-03-09 14:32:57 +05301456 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05301457}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301458qdf_export_symbol(wmi_unified_cmd_send);
Govind Singh6b411b52016-03-06 19:55:02 +05301459
1460/**
1461 * wmi_unified_get_event_handler_ix() - gives event handler's index
1462 * @wmi_handle: handle to wmi
1463 * @event_id: wmi event id
1464 *
1465 * Return: event handler's index
1466 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001467static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
1468 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301469{
1470 uint32_t idx = 0;
1471 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301472 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301473
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301474 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05301475 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
1476 if (wmi_handle->event_id[idx] == event_id &&
1477 wmi_handle->event_handler[idx] != NULL) {
1478 return idx;
1479 }
1480 }
1481
1482 return invalid_idx;
1483}
1484
1485/**
Soumya Bhat488092d2017-03-22 14:41:01 +05301486 * wmi_unified_register_event() - register wmi event handler
1487 * @wmi_handle: handle to wmi
1488 * @event_id: wmi event id
1489 * @handler_func: wmi event handler function
1490 *
1491 * Return: 0 on success
1492 */
1493int wmi_unified_register_event(wmi_unified_t wmi_handle,
1494 uint32_t event_id,
1495 wmi_unified_event_handler handler_func)
1496{
1497 uint32_t idx = 0;
1498 uint32_t evt_id;
1499 struct wmi_soc *soc = wmi_handle->soc;
1500
1501 if (event_id >= wmi_events_max ||
1502 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1503 qdf_print("%s: Event id %d is unavailable\n",
1504 __func__, event_id);
1505 return QDF_STATUS_E_FAILURE;
1506 }
1507 evt_id = wmi_handle->wmi_events[event_id];
1508 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1509 qdf_print("%s : event handler already registered 0x%x\n",
1510 __func__, evt_id);
1511 return QDF_STATUS_E_FAILURE;
1512 }
1513 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
1514 qdf_print("%s : no more event handlers 0x%x\n",
1515 __func__, evt_id);
1516 return QDF_STATUS_E_FAILURE;
1517 }
1518 idx = soc->max_event_idx;
1519 wmi_handle->event_handler[idx] = handler_func;
1520 wmi_handle->event_id[idx] = evt_id;
1521 qdf_spin_lock_bh(&soc->ctx_lock);
1522 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
1523 qdf_spin_unlock_bh(&soc->ctx_lock);
1524 soc->max_event_idx++;
1525
1526 return 0;
1527}
1528
1529/**
Govind Singh6b411b52016-03-06 19:55:02 +05301530 * wmi_unified_register_event_handler() - register wmi event handler
1531 * @wmi_handle: handle to wmi
1532 * @event_id: wmi event id
1533 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05301534 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05301535 *
Soumya Bhat488092d2017-03-22 14:41:01 +05301536 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05301537 * Return: 0 on success
1538 */
1539int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301540 wmi_conv_event_id event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05301541 wmi_unified_event_handler handler_func,
1542 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301543{
1544 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301545 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301546 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301547
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301548 if (event_id >= wmi_events_max ||
1549 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1550 qdf_print("%s: Event id %d is unavailable\n",
1551 __func__, event_id);
1552 return QDF_STATUS_E_FAILURE;
1553 }
1554 evt_id = wmi_handle->wmi_events[event_id];
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301555
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301556 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
1557 qdf_print("%s : event handler already registered 0x%x\n",
1558 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301559 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301560 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301561 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301562 qdf_print("%s : no more event handlers 0x%x\n",
1563 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301564 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301565 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07001566 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
1567 "Registered event handler for event 0x%8x\n", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301568 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301569 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301570 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301571 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301572 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301573 qdf_spin_unlock_bh(&soc->ctx_lock);
1574 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05301575
1576 return 0;
1577}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301578qdf_export_symbol(wmi_unified_register_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301579
1580/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05301581 * wmi_unified_unregister_event() - unregister wmi event handler
1582 * @wmi_handle: handle to wmi
1583 * @event_id: wmi event id
1584 *
1585 * Return: 0 on success
1586 */
1587int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
1588 uint32_t event_id)
1589{
1590 uint32_t idx = 0;
1591 uint32_t evt_id;
1592 struct wmi_soc *soc = wmi_handle->soc;
1593
1594 if (event_id >= wmi_events_max ||
1595 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1596 qdf_print("%s: Event id %d is unavailable\n",
1597 __func__, event_id);
1598 return QDF_STATUS_E_FAILURE;
1599 }
1600 evt_id = wmi_handle->wmi_events[event_id];
1601
1602 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
1603 if (idx == -1) {
1604 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1605 __func__, evt_id);
1606 return QDF_STATUS_E_FAILURE;
1607 }
1608 wmi_handle->event_handler[idx] = NULL;
1609 wmi_handle->event_id[idx] = 0;
1610 --soc->max_event_idx;
1611 wmi_handle->event_handler[idx] =
1612 wmi_handle->event_handler[soc->max_event_idx];
1613 wmi_handle->event_id[idx] =
1614 wmi_handle->event_id[soc->max_event_idx];
1615
1616 return 0;
1617}
1618
1619/**
Govind Singh6b411b52016-03-06 19:55:02 +05301620 * wmi_unified_unregister_event_handler() - unregister wmi event handler
1621 * @wmi_handle: handle to wmi
1622 * @event_id: wmi event id
1623 *
1624 * Return: 0 on success
1625 */
1626int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05301627 wmi_conv_event_id event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301628{
1629 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301630 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301631 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05301632
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301633 if (event_id >= wmi_events_max ||
1634 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
1635 qdf_print("%s: Event id %d is unavailable\n",
1636 __func__, event_id);
1637 return QDF_STATUS_E_FAILURE;
1638 }
1639 evt_id = wmi_handle->wmi_events[event_id];
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301640
1641 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301642 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301643 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
1644 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301645 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05301646 }
1647 wmi_handle->event_handler[idx] = NULL;
1648 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301649 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05301650 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301651 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301652 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301653 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05301654
1655 return 0;
1656}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301657qdf_export_symbol(wmi_unified_unregister_event_handler);
Govind Singh6b411b52016-03-06 19:55:02 +05301658
1659/**
Govind Singhd52faac2016-03-09 12:03:29 +05301660 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301661 * @wmi_handle: handle to wmi
1662 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301663 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05301664 *
Govind Singhd52faac2016-03-09 12:03:29 +05301665 * Event process by below function will be in default caller context.
1666 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05301667 *
1668 * Return: none
1669 */
Govind Singhd52faac2016-03-09 12:03:29 +05301670static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
1671 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05301672{
1673 wmi_buf_t evt_buf;
1674 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
1675
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301676#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301677 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
1678 (wmi_handle->scn_handle, evt_buf, exec_ctx);
1679#else
Govind Singh5eb51532016-03-09 11:34:12 +05301680 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Amar Singhal66d1ed52018-06-26 16:45:54 -07001681 htc_packet, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301682#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301683
Govind Singh6b411b52016-03-06 19:55:02 +05301684 return;
1685}
1686
1687/**
1688 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
1689 * @wmi_handle: handle to wmi
1690 * @htc_packet: pointer to htc packet
1691 *
1692 * Event process by below function will be in worker thread context.
1693 * Use this method for events which are not critical and not
1694 * handled in protocol stack.
1695 *
1696 * Return: none
1697 */
Amar Singhal66d1ed52018-06-26 16:45:54 -07001698void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
1699 HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301700{
1701 wmi_buf_t evt_buf;
Govind Singh6b411b52016-03-06 19:55:02 +05301702
1703 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singh6b411b52016-03-06 19:55:02 +05301704
Govind Singhb53420c2016-03-09 14:32:57 +05301705 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
1706 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
1707 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001708 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
1709 &wmi_handle->rx_event_work);
1710
Govind Singh6b411b52016-03-06 19:55:02 +05301711 return;
1712}
1713
Amar Singhal66d1ed52018-06-26 16:45:54 -07001714qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
1715
Govind Singh6b411b52016-03-06 19:55:02 +05301716/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301717 * wmi_get_pdev_ep: Get wmi handle based on endpoint
1718 * @soc: handle to wmi soc
1719 * @ep: endpoint id
1720 *
1721 * Return: none
1722 */
1723static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
1724 HTC_ENDPOINT_ID ep)
1725{
1726 uint32_t i;
1727
1728 for (i = 0; i < WMI_MAX_RADIOS; i++)
1729 if (soc->wmi_endpoint_id[i] == ep)
1730 break;
1731
1732 if (i == WMI_MAX_RADIOS)
1733 return NULL;
1734
1735 return soc->wmi_pdev[i];
1736}
1737
1738/**
Govind Singhd52faac2016-03-09 12:03:29 +05301739 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05301740 * @ctx: handle to wmi
1741 * @htc_packet: pointer to htc packet
1742 *
Govind Singh6b411b52016-03-06 19:55:02 +05301743 * Return: none
1744 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07001745static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05301746{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301747 struct wmi_soc *soc = (struct wmi_soc *) ctx;
1748 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05301749 wmi_buf_t evt_buf;
1750 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05301751 uint32_t idx = 0;
1752 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05301753
1754 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301755
1756 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
1757 if (wmi_handle == NULL) {
1758 qdf_print
1759 ("%s :unable to get wmi_handle to Endpoint %d\n",
1760 __func__, htc_packet->Endpoint);
1761 qdf_nbuf_free(evt_buf);
1762 return;
1763 }
1764
Govind Singhb53420c2016-03-09 14:32:57 +05301765 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05301766 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301767 if (qdf_unlikely(idx == A_ERROR)) {
yeshwanth sriram guntuka0a050d72017-07-10 15:01:15 +05301768 WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
1769 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05301770 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301771 return;
1772 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301773 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301774 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05301775 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05301776
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001777#ifdef WMI_INTERFACE_EVENT_LOGGING
1778 if (wmi_handle->log_info.wmi_logging_enable) {
1779 uint8_t *data;
1780 data = qdf_nbuf_data(evt_buf);
1781
1782 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1783 /* Exclude 4 bytes of TLV header */
Rakesh Pillai05110462017-12-27 14:08:59 +05301784 WMI_RX_EVENT_RECORD(wmi_handle, id, data +
1785 wmi_handle->log_info.buf_offset_event);
Houston Hoffmanc85276b2017-10-11 14:50:30 -07001786 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1787 }
1788#endif
1789
Govind Singhd52faac2016-03-09 12:03:29 +05301790 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05301791 wmi_process_fw_event_worker_thread_ctx
1792 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05301793 } else if (exec_ctx > WMI_RX_WORK_CTX) {
1794 wmi_process_fw_event_default_ctx
1795 (wmi_handle, htc_packet, exec_ctx);
1796 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05301797 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
1798 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301799 }
Govind Singhd52faac2016-03-09 12:03:29 +05301800
Govind Singh6b411b52016-03-06 19:55:02 +05301801}
1802
1803/**
1804 * wmi_process_fw_event() - process any fw event
1805 * @wmi_handle: wmi handle
1806 * @evt_buf: fw event buffer
1807 *
Govind Singhd52faac2016-03-09 12:03:29 +05301808 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05301809 *
1810 * Return: none
1811 */
1812void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1813{
1814 __wmi_control_rx(wmi_handle, evt_buf);
1815}
1816
1817/**
1818 * __wmi_control_rx() - process serialize wmi event callback
1819 * @wmi_handle: wmi handle
1820 * @evt_buf: fw event buffer
1821 *
1822 * Return: none
1823 */
1824void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
1825{
1826 uint32_t id;
1827 uint8_t *data;
1828 uint32_t len;
1829 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301830#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05301831 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301832#endif
Govind Singhd52faac2016-03-09 12:03:29 +05301833 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301834
Govind Singhb53420c2016-03-09 14:32:57 +05301835 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301836
Govind Singhb53420c2016-03-09 14:32:57 +05301837 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05301838 goto end;
1839
Govind Singhb53420c2016-03-09 14:32:57 +05301840 data = qdf_nbuf_data(evt_buf);
1841 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301842
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301843#ifndef WMI_NON_TLV_SUPPORT
1844 if (wmi_handle->target_type == WMI_TLV_TARGET) {
1845 /* Validate and pad(if necessary) the TLVs */
1846 tlv_ok_status =
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301847 wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05301848 data, len, id,
1849 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301850 if (tlv_ok_status != 0) {
1851 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1852 "%s: Error: id=0x%d, wmitlv check status=%d\n",
1853 __func__, id, tlv_ok_status);
1854 goto end;
1855 }
Govind Singh6b411b52016-03-06 19:55:02 +05301856 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301857#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301858
Govind Singhd52faac2016-03-09 12:03:29 +05301859 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
1860 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05301861 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301862 "%s : event handler is not registered: event id 0x%x\n",
1863 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05301864 goto end;
1865 }
Govind Singhd52faac2016-03-09 12:03:29 +05301866#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301867 if (wmi_handle->log_info.wmi_logging_enable) {
1868 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1869 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301870 if (wmi_handle->ops->is_management_record(id)) {
Rakesh Pillai05110462017-12-27 14:08:59 +05301871 WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
1872 + wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301873 } else {
Rakesh Pillai05110462017-12-27 14:08:59 +05301874 WMI_EVENT_RECORD(wmi_handle, id, data +
1875 wmi_handle->log_info.buf_offset_event);
Govind Singhecf03cd2016-05-12 12:45:51 +05301876 }
1877 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301878 }
Govind Singhd52faac2016-03-09 12:03:29 +05301879#endif
1880 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301881 if (wmi_handle->target_type == WMI_TLV_TARGET)
1882 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1883 wmi_cmd_struct_ptr, len);
1884 else
1885 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
1886 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05301887
Govind Singh6b411b52016-03-06 19:55:02 +05301888end:
Govind Singhd52faac2016-03-09 12:03:29 +05301889 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301890#ifndef WMI_NON_TLV_SUPPORT
1891 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05301892 wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301893#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301894
Govind Singhb53420c2016-03-09 14:32:57 +05301895 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05301896
Govind Singh6b411b52016-03-06 19:55:02 +05301897}
1898
Arunk Khandavallib6ba21f2017-12-06 15:47:10 +05301899#define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
Govind Singh97b8e7c2017-09-07 18:23:39 +05301900
Surabhi Vishnoi209f7d42017-11-29 15:07:10 +05301901static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
Govind Singh97b8e7c2017-09-07 18:23:39 +05301902{
1903 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
Kabilan Kannanf1311ec2018-03-08 14:34:28 -08001904 "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
Govind Singh97b8e7c2017-09-07 18:23:39 +05301905 __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
1906}
1907
1908#ifdef CONFIG_SLUB_DEBUG_ON
1909static void wmi_workqueue_watchdog_bite(void *arg)
1910{
Govind Singhc646e102017-11-21 10:53:40 +05301911 struct wmi_wq_dbg_info *info = arg;
1912
1913 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
1914 qdf_print_thread_trace(info->task);
1915
Govind Singh97b8e7c2017-09-07 18:23:39 +05301916 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
1917 "%s: Going down for WMI WQ Watchdog Bite!", __func__);
1918 QDF_BUG(0);
1919}
1920#else
1921static inline void wmi_workqueue_watchdog_bite(void *arg)
1922{
Govind Singhc646e102017-11-21 10:53:40 +05301923 struct wmi_wq_dbg_info *info = arg;
1924
1925 wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301926}
1927#endif
1928
Govind Singh6b411b52016-03-06 19:55:02 +05301929/**
1930 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001931 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05301932 *
1933 * This function process any fw event to serialize it through rx worker thread.
1934 *
1935 * Return: none
1936 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001937static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05301938{
Govind Singh6b411b52016-03-06 19:55:02 +05301939 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07001940 struct wmi_unified *wmi = arg;
Govind Singh97b8e7c2017-09-07 18:23:39 +05301941 qdf_timer_t wd_timer;
Govind Singhc646e102017-11-21 10:53:40 +05301942 struct wmi_wq_dbg_info info;
Govind Singh6b411b52016-03-06 19:55:02 +05301943
Govind Singh97b8e7c2017-09-07 18:23:39 +05301944 /* initialize WMI workqueue watchdog timer */
1945 qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
Govind Singhc646e102017-11-21 10:53:40 +05301946 &info, QDF_TIMER_TYPE_SW);
Govind Singhb53420c2016-03-09 14:32:57 +05301947 qdf_spin_lock_bh(&wmi->eventq_lock);
1948 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1949 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301950 while (buf) {
Govind Singh97b8e7c2017-09-07 18:23:39 +05301951 qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
Govind Singhc646e102017-11-21 10:53:40 +05301952 info.wd_msg_type_id =
Govind Singh97b8e7c2017-09-07 18:23:39 +05301953 WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
Govind Singhc646e102017-11-21 10:53:40 +05301954 info.wmi_wq = wmi->wmi_rx_work_queue;
1955 info.task = qdf_get_current_task();
Govind Singh6b411b52016-03-06 19:55:02 +05301956 __wmi_control_rx(wmi, buf);
Govind Singh97b8e7c2017-09-07 18:23:39 +05301957 qdf_timer_stop(&wd_timer);
Govind Singhb53420c2016-03-09 14:32:57 +05301958 qdf_spin_lock_bh(&wmi->eventq_lock);
1959 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
1960 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05301961 }
Govind Singh97b8e7c2017-09-07 18:23:39 +05301962 qdf_timer_free(&wd_timer);
Govind Singh6b411b52016-03-06 19:55:02 +05301963}
1964
Govind Singh6b411b52016-03-06 19:55:02 +05301965#ifdef FEATURE_RUNTIME_PM
1966/**
1967 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
1968 * @wmi_handle: wmi context
1969 */
Govind Singhd52faac2016-03-09 12:03:29 +05301970static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301971{
Govind Singhb53420c2016-03-09 14:32:57 +05301972 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05301973}
Govind Singhd52faac2016-03-09 12:03:29 +05301974
1975/**
1976 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
1977 * @wmi_handle: wmi context
1978 * @val: runtime pm progress flag
1979 */
1980void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
1981{
Govind Singhb53420c2016-03-09 14:32:57 +05301982 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05301983}
1984
1985/**
1986 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
1987 * @wmi_handle: wmi context
1988 */
1989inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
1990{
Govind Singhb53420c2016-03-09 14:32:57 +05301991 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05301992}
Govind Singh6b411b52016-03-06 19:55:02 +05301993#else
Govind Singhd52faac2016-03-09 12:03:29 +05301994static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05301995{
1996}
1997#endif
1998
1999/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302000 * wmi_unified_get_soc_handle: Get WMI SoC handle
2001 * @param wmi_handle: WMI context got from wmi_attach
2002 *
2003 * return: Pointer to Soc handle
2004 */
2005void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2006{
2007 return wmi_handle->soc;
2008}
2009
2010/**
2011 * wmi_interface_logging_init: Interface looging init
2012 * @param wmi_handle: Pointer to wmi handle object
2013 *
2014 * return: None
2015 */
2016#ifdef WMI_INTERFACE_EVENT_LOGGING
2017static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2018{
2019 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2020 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2021 wmi_debugfs_init(wmi_handle);
2022 }
2023}
2024#else
Rachit Kankane799d2c92018-02-19 11:28:10 +05302025static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302026{
2027}
2028#endif
2029
2030/**
2031 * wmi_target_params_init: Target specific params init
2032 * @param wmi_soc: Pointer to wmi soc object
2033 * @param wmi_handle: Pointer to wmi handle object
2034 *
2035 * return: None
2036 */
2037#ifndef CONFIG_MCL
2038static inline void wmi_target_params_init(struct wmi_soc *soc,
2039 struct wmi_unified *wmi_handle)
2040{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302041 wmi_handle->pdev_param = soc->pdev_param;
2042 wmi_handle->vdev_param = soc->vdev_param;
Kris Muthusamy76e22412018-01-26 16:18:37 -08002043 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302044}
2045#else
2046static inline void wmi_target_params_init(struct wmi_soc *soc,
2047 struct wmi_unified *wmi_handle)
2048{
Kris Muthusamy76e22412018-01-26 16:18:37 -08002049 wmi_handle->services = soc->services;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302050}
2051#endif
2052
2053/**
2054 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2055 * @param wmi_soc: Pointer to wmi soc object
2056 * @param pdev_idx: pdev index
2057 *
2058 * return: Pointer to wmi handle or NULL on failure
2059 */
2060void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2061{
2062 struct wmi_unified *wmi_handle;
2063
2064 if (pdev_idx >= WMI_MAX_RADIOS)
2065 return NULL;
2066
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302067 if (soc->wmi_pdev[pdev_idx] == NULL) {
2068 wmi_handle =
2069 (struct wmi_unified *) qdf_mem_malloc(
2070 sizeof(struct wmi_unified));
2071 if (wmi_handle == NULL) {
2072 qdf_print("allocation of wmi handle failed %zu\n",
2073 sizeof(struct wmi_unified));
2074 return NULL;
2075 }
2076 wmi_handle->scn_handle = soc->scn_handle;
2077 wmi_handle->event_id = soc->event_id;
2078 wmi_handle->event_handler = soc->event_handler;
2079 wmi_handle->ctx = soc->ctx;
2080 wmi_handle->ops = soc->ops;
2081 qdf_spinlock_create(&wmi_handle->eventq_lock);
2082 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302083
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302084 qdf_create_work(0, &wmi_handle->rx_event_work,
2085 wmi_rx_event_work, wmi_handle);
2086 wmi_handle->wmi_rx_work_queue =
2087 qdf_create_workqueue("wmi_rx_event_work_queue");
2088 if (NULL == wmi_handle->wmi_rx_work_queue) {
2089 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2090 goto error;
2091 }
2092 wmi_handle->wmi_events = soc->wmi_events;
2093 wmi_target_params_init(soc, wmi_handle);
2094 wmi_interface_logging_init(wmi_handle);
2095 qdf_atomic_init(&wmi_handle->pending_cmds);
2096 qdf_atomic_init(&wmi_handle->is_target_suspended);
2097 wmi_handle->target_type = soc->target_type;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302098 wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302099 wmi_handle->soc = soc;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002100
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302101 soc->wmi_pdev[pdev_idx] = wmi_handle;
2102 } else
2103 wmi_handle = soc->wmi_pdev[pdev_idx];
2104
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302105 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302106 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2107 wmi_handle->htc_handle = soc->htc_handle;
2108 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302109
2110 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002111
2112error:
2113 qdf_mem_free(wmi_handle);
2114
2115 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302116}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302117qdf_export_symbol(wmi_unified_get_pdev_handle);
2118
2119static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
2120
2121void wmi_unified_register_module(enum wmi_target_type target_type,
2122 void (*wmi_attach)(wmi_unified_t wmi_handle))
2123{
2124 if (target_type < WMI_MAX_TARGET_TYPE)
2125 wmi_attach_register[target_type] = wmi_attach;
2126
2127 return;
2128}
2129qdf_export_symbol(wmi_unified_register_module);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302130
2131/**
Govind Singh6b411b52016-03-06 19:55:02 +05302132 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302133 * @scn_handle: handle to SCN
2134 * @osdev: OS device context
2135 * @target_type: TLV or not-TLV based target
2136 * @use_cookie: cookie based allocation enabled/disabled
2137 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302138 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302139 *
2140 * @Return: wmi handle.
2141 */
Govind Singhc458f382016-02-04 18:42:30 +05302142void *wmi_unified_attach(void *scn_handle,
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302143 struct wmi_unified_attach_params *param)
Govind Singh6b411b52016-03-06 19:55:02 +05302144{
2145 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302146 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302147
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302148 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2149 if (soc == NULL) {
2150 qdf_print("Allocation of wmi_soc failed %zu\n",
2151 sizeof(struct wmi_soc));
2152 return NULL;
2153 }
Mukul Sharma2c66f7e2017-11-03 19:26:54 +05302154
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302155 wmi_handle =
2156 (struct wmi_unified *) qdf_mem_malloc(
2157 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302158 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302159 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302160 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302161 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302162 return NULL;
2163 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302164 wmi_handle->soc = soc;
2165 wmi_handle->event_id = soc->event_id;
2166 wmi_handle->event_handler = soc->event_handler;
2167 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302168 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302169 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302170 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302171 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302172 qdf_atomic_init(&wmi_handle->pending_cmds);
2173 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302174 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302175 qdf_spinlock_create(&wmi_handle->eventq_lock);
2176 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002177 qdf_create_work(0, &wmi_handle->rx_event_work,
2178 wmi_rx_event_work, wmi_handle);
2179 wmi_handle->wmi_rx_work_queue =
2180 qdf_create_workqueue("wmi_rx_event_work_queue");
2181 if (NULL == wmi_handle->wmi_rx_work_queue) {
2182 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2183 goto error;
2184 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302185 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302186 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302187 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302188 param->rx_ops->wma_process_fw_event_handler_cbk;
2189 wmi_handle->target_type = param->target_type;
2190 soc->target_type = param->target_type;
Abhiram Jogadenu429ab532018-05-14 17:13:28 +05302191
2192 if (param->target_type >= WMI_MAX_TARGET_TYPE)
2193 goto error;
2194
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302195 if (wmi_attach_register[param->target_type]) {
2196 wmi_attach_register[param->target_type](wmi_handle);
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302197 } else {
2198 WMI_LOGE("wmi attach is not registered");
2199 goto error;
2200 }
Govind Singhc458f382016-02-04 18:42:30 +05302201 /* Assign target cookie capablity */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302202 wmi_handle->use_cookie = param->use_cookie;
2203 wmi_handle->osdev = param->osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302204 wmi_handle->wmi_stopinprogress = 0;
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302205 wmi_handle->wmi_max_cmds = param->max_commands;
2206 soc->wmi_max_cmds = param->max_commands;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302207 /* Increase the ref count once refcount infra is present */
Chaithanya Garrepalli6327e8a2017-12-01 14:55:26 +05302208 soc->wmi_psoc = param->psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302209 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302210
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302211 soc->ops = wmi_handle->ops;
2212 soc->wmi_pdev[0] = wmi_handle;
2213
Govind Singh6b411b52016-03-06 19:55:02 +05302214 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002215
2216error:
2217 qdf_mem_free(soc);
2218 qdf_mem_free(wmi_handle);
2219
2220 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302221}
2222
2223/**
2224 * wmi_unified_detach() - detach for unified WMI
2225 *
2226 * @wmi_handle : handle to wmi.
2227 *
2228 * @Return: none.
2229 */
2230void wmi_unified_detach(struct wmi_unified *wmi_handle)
2231{
2232 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302233 struct wmi_soc *soc;
2234 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302235
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302236 soc = wmi_handle->soc;
2237 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2238 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002239 qdf_flush_workqueue(0,
2240 soc->wmi_pdev[i]->wmi_rx_work_queue);
2241 qdf_destroy_workqueue(0,
2242 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302243 wmi_debugfs_remove(soc->wmi_pdev[i]);
2244 buf = qdf_nbuf_queue_remove(
2245 &soc->wmi_pdev[i]->event_queue);
2246 while (buf) {
2247 qdf_nbuf_free(buf);
2248 buf = qdf_nbuf_queue_remove(
2249 &soc->wmi_pdev[i]->event_queue);
2250 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002251
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302252 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002253
2254 /* Free events logs list */
2255 if (soc->wmi_pdev[i]->events_logs_list)
2256 qdf_mem_free(
2257 soc->wmi_pdev[i]->events_logs_list);
2258
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302259 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302260 qdf_mem_free(soc->wmi_pdev[i]);
2261 }
Govind Singh6b411b52016-03-06 19:55:02 +05302262 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302263 qdf_spinlock_destroy(&soc->ctx_lock);
Kiran Venkatappa7d739142017-09-01 17:02:34 +05302264
2265 if (soc->wmi_service_bitmap) {
2266 qdf_mem_free(soc->wmi_service_bitmap);
2267 soc->wmi_service_bitmap = NULL;
2268 }
2269
2270 if (soc->wmi_ext_service_bitmap) {
2271 qdf_mem_free(soc->wmi_ext_service_bitmap);
2272 soc->wmi_ext_service_bitmap = NULL;
2273 }
2274
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302275 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302276 soc->wmi_psoc = NULL;
2277 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302278}
2279
2280/**
2281 * wmi_unified_remove_work() - detach for WMI work
2282 * @wmi_handle: handle to WMI
2283 *
2284 * A function that does not fully detach WMI, but just remove work
2285 * queue items associated with it. This is used to make sure that
2286 * before any other processing code that may destroy related contexts
2287 * (HTC, etc), work queue processing on WMI has already been stopped.
2288 *
2289 * Return: None
2290 */
2291void
2292wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2293{
2294 wmi_buf_t buf;
2295
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002296 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302297 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2298 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302299 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302300 qdf_nbuf_free(buf);
2301 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302302 }
Govind Singhb53420c2016-03-09 14:32:57 +05302303 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302304}
2305
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302306/**
2307 * wmi_htc_tx_complete() - Process htc tx completion
2308 *
2309 * @ctx: handle to wmi
2310 * @htc_packet: pointer to htc packet
2311 *
2312 * @Return: none.
2313 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002314static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302315{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302316 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302317 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302318 u_int8_t *buf_ptr;
2319 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302320 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302321#ifdef WMI_INTERFACE_EVENT_LOGGING
2322 uint32_t cmd_id;
2323#endif
2324
2325 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302326 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2327 if (wmi_handle == NULL) {
2328 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2329 QDF_ASSERT(0);
2330 return;
2331 }
Govind Singh6b411b52016-03-06 19:55:02 +05302332#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302333 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302334 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2335 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302336
Govind Singhecf03cd2016-05-12 12:45:51 +05302337 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302338 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302339 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302340 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302341 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302342 qdf_nbuf_data(wmi_cmd_buf) +
2343 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302344 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302345 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
Rakesh Pillai05110462017-12-27 14:08:59 +05302346 qdf_nbuf_data(wmi_cmd_buf) +
2347 wmi_handle->log_info.buf_offset_command);
Govind Singh6b411b52016-03-06 19:55:02 +05302348 }
2349
Govind Singhecf03cd2016-05-12 12:45:51 +05302350 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2351 }
Govind Singh6b411b52016-03-06 19:55:02 +05302352#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302353 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2354 len = qdf_nbuf_len(wmi_cmd_buf);
2355 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302356 qdf_nbuf_free(wmi_cmd_buf);
2357 qdf_mem_free(htc_pkt);
2358 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302359}
2360
2361/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302362 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302363 *
2364 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302365 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302366 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302367 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302368 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302369static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2370 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302371{
Govind Singh6b411b52016-03-06 19:55:02 +05302372 int status;
Manikandan Mohanf940db82017-04-13 20:19:26 -07002373 struct htc_service_connect_resp response;
2374 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302375
2376 OS_MEMZERO(&connect, sizeof(connect));
2377 OS_MEMZERO(&response, sizeof(response));
2378
2379 /* meta data is unused for now */
2380 connect.pMetaData = NULL;
2381 connect.MetaDataLength = 0;
2382 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302383 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302384 connect.EpCallbacks.EpTxCompleteMultiple =
2385 NULL /* Control path completion ar6000_tx_complete */;
2386 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2387 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2388 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2389 connect.EpCallbacks.EpTxComplete =
2390 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2391
2392 /* connect to control service */
Pratik Gandhicf3b8b92018-02-05 17:22:41 +05302393 connect.service_id = soc->svc_ids[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302394 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302395 &response);
2396
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302397
Govind Singh6b411b52016-03-06 19:55:02 +05302398 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302399 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302400 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302401 status);
2402 return status;
2403 }
Govind Singh6b411b52016-03-06 19:55:02 +05302404
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302405 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2406 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2407
2408 return 0;
2409}
2410
2411/**
2412 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2413 *
2414 * @wmi_handle: handle to WMI.
2415 *
2416 * @Return: status.
2417 */
2418QDF_STATUS
2419wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2420 void *htc_handle)
2421{
2422 uint32_t i;
2423 uint8_t wmi_ep_count;
2424
2425 wmi_handle->soc->htc_handle = htc_handle;
2426
2427 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2428 if (wmi_ep_count > WMI_MAX_RADIOS)
2429 return QDF_STATUS_E_FAULT;
2430
2431 for (i = 0; i < wmi_ep_count; i++)
2432 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2433
2434 wmi_handle->htc_handle = htc_handle;
2435 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2436 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2437
2438 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302439}
2440
2441/**
2442 * wmi_get_host_credits() - WMI API to get updated host_credits
2443 *
2444 * @wmi_handle: handle to WMI.
2445 *
2446 * @Return: updated host_credits.
2447 */
2448int wmi_get_host_credits(wmi_unified_t wmi_handle)
2449{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302450 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302451
2452 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2453 &host_credits);
2454 return host_credits;
2455}
2456
2457/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302458 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2459 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302460 *
2461 * @wmi_handle: handle to WMI.
2462 *
2463 * @Return: Pending Commands in the HTC queue.
2464 */
2465int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2466{
Govind Singhb53420c2016-03-09 14:32:57 +05302467 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302468}
2469
2470/**
2471 * wmi_set_target_suspend() - WMI API to set target suspend state
2472 *
2473 * @wmi_handle: handle to WMI.
2474 * @val: suspend state boolean.
2475 *
2476 * @Return: none.
2477 */
2478void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2479{
Govind Singhb53420c2016-03-09 14:32:57 +05302480 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302481}
2482
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302483/**
2484 * WMI API to set crash injection state
2485 * @param wmi_handle: handle to WMI.
2486 * @param val: crash injection state boolean.
2487 */
2488void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2489{
2490 wmi_handle->tag_crash_inject = flag;
2491}
2492
2493/**
2494 * WMI API to set bus suspend state
2495 * @param wmi_handle: handle to WMI.
2496 * @param val: suspend state boolean.
2497 */
2498void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
2499{
2500 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
2501}
2502
Ravi Kumar Bokka7aec5b52016-11-09 18:07:56 +05302503void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
2504{
2505 wmi_handle->tgt_force_assert_enable = val;
2506}
2507
Kabilan Kannan66084ce2018-02-21 13:41:00 -08002508/**
2509 * wmi_stop() - generic function to block unified WMI command
2510 * @wmi_handle: handle to WMI.
2511 *
2512 * @Return: success always.
2513 */
2514int
2515wmi_stop(wmi_unified_t wmi_handle)
2516{
2517 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
2518 "WMI Stop\n");
2519 wmi_handle->wmi_stopinprogress = 1;
2520 return 0;
2521}
2522
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302523#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302524/**
2525 * API to flush all the previous packets associated with the wmi endpoint
2526 *
2527 * @param wmi_handle : handle to WMI.
2528 */
2529void
2530wmi_flush_endpoint(wmi_unified_t wmi_handle)
2531{
2532 htc_flush_endpoint(wmi_handle->htc_handle,
2533 wmi_handle->wmi_endpoint_id, 0);
2534}
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302535qdf_export_symbol(wmi_flush_endpoint);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302536
2537/**
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302538 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
2539 * By default pdev_id conversion is not done in WMI.
2540 * This API can be used enable conversion in WMI.
2541 * @param wmi_handle : handle to WMI
2542 * Return none
2543 */
2544void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
2545{
2546 if (wmi_handle->target_type == WMI_TLV_TARGET)
Pratik Gandhi67da1bb2018-01-30 19:05:41 +05302547 wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05302548}
2549
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302550#endif