blob: cafd7255b23934395353299fee40593df14d5019 [file] [log] [blame]
Govind Singh6b411b52016-03-06 19:55:02 +05301/*
Paul Zhangd19abd82017-01-04 16:45:42 +08002 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
Govind Singh6b411b52016-03-06 19:55:02 +05303 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/*
29 * Host WMI unified implementation
30 */
Govind Singh6b411b52016-03-06 19:55:02 +053031#include "htc_api.h"
32#include "htc_api.h"
Govind Singh6b411b52016-03-06 19:55:02 +053033#include "wmi_unified_priv.h"
Govind Singh6b411b52016-03-06 19:55:02 +053034
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053035#ifndef WMI_NON_TLV_SUPPORT
36#include "wmi_tlv_helper.h"
37#endif
38
Govind Singhecf03cd2016-05-12 12:45:51 +053039#include <linux/debugfs.h>
40
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053041/* This check for CONFIG_WIN temporary added due to redeclaration compilation
42error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
43which gets included here through ol_if_athvar.h. Eventually it is expected that
44wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
45WMI_CMD_HDR to be defined here. */
46#ifdef CONFIG_WIN
47/* Copied from wmi.h */
48#undef MS
49#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
50#undef SM
51#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
52#undef WO
53#define WO(_f) ((_f##_OFFSET) >> 2)
54
55#undef GET_FIELD
56#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
57#undef SET_FIELD
58#define SET_FIELD(_addr, _f, _val) \
59 (*((A_UINT32 *)(_addr) + WO(_f)) = \
60 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
61
62#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
63 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
64
65#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
66 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
67
68#define WMI_EP_APASS 0x0
69#define WMI_EP_LPASS 0x1
70#define WMI_EP_SENSOR 0x2
71
72/*
73 * * Control Path
74 * */
75typedef PREPACK struct {
76 A_UINT32 commandId:24,
77 reserved:2, /* used for WMI endpoint ID */
78 plt_priv:6; /* platform private */
79} POSTPACK WMI_CMD_HDR; /* used for commands and events */
80
81#define WMI_CMD_HDR_COMMANDID_LSB 0
82#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
83#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
84#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
85#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
86#define WMI_CMD_HDR_PLT_PRIV_LSB 24
87#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
88#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
89/* end of copy wmi.h */
90#endif /* CONFIG_WIN */
91
Manikandan Mohan5826ae92016-06-08 16:29:39 -070092#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
93/* TODO Cleanup this backported function */
Pratik Gandhi795ab912017-05-03 20:15:50 +053094static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -070095{
96 va_list args;
97
98 va_start(args, f);
Pratik Gandhi795ab912017-05-03 20:15:50 +053099 seq_vprintf(m, f, args);
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700100 va_end(args);
101
Pratik Gandhi795ab912017-05-03 20:15:50 +0530102 return 0;
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700103}
Pratik Gandhi795ab912017-05-03 20:15:50 +0530104#else
105#define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700106#endif
107
Govind Singh6b411b52016-03-06 19:55:02 +0530108#define WMI_MIN_HEAD_ROOM 64
109
110#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +0530111#ifndef MAX_WMI_INSTANCES
112#ifdef CONFIG_MCL
113#define MAX_WMI_INSTANCES 1
114#else
115#define MAX_WMI_INSTANCES 3
116#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530117#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530118#endif
119
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530120#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530121/* WMI commands */
122uint32_t g_wmi_command_buf_idx = 0;
123struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
124
125/* WMI commands TX completed */
126uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
127struct wmi_command_debug
128 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
129
130/* WMI events when processed */
131uint32_t g_wmi_event_buf_idx = 0;
132struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
133
134/* WMI events when queued */
135uint32_t g_wmi_rx_event_buf_idx = 0;
136struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530137#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530138
Govind Singhecf03cd2016-05-12 12:45:51 +0530139#define WMI_COMMAND_RECORD(h, a, b) { \
140 if (wmi_log_max_entry <= \
141 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
142 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
143 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
144 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
145 .command = a; \
146 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
147 wmi_command_log_buf_info.buf) \
148 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
149 b, wmi_record_max_length); \
150 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
151 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
152 time = qdf_get_log_timestamp(); \
153 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
154 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530155}
156
Govind Singhecf03cd2016-05-12 12:45:51 +0530157#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
158 if (wmi_log_max_entry <= \
159 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530160 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
161 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530162 ((struct wmi_command_debug *)h->log_info. \
163 wmi_command_tx_cmp_log_buf_info.buf) \
164 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
165 p_buf_tail_idx)]. \
166 command = a; \
167 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
168 wmi_command_tx_cmp_log_buf_info.buf) \
169 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
170 p_buf_tail_idx)]. \
171 data, b, wmi_record_max_length); \
172 ((struct wmi_command_debug *)h->log_info. \
173 wmi_command_tx_cmp_log_buf_info.buf) \
174 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
175 p_buf_tail_idx)]. \
176 time = qdf_get_log_timestamp(); \
177 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
178 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530179}
180
Govind Singhecf03cd2016-05-12 12:45:51 +0530181#define WMI_EVENT_RECORD(h, a, b) { \
182 if (wmi_log_max_entry <= \
183 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
184 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
185 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
186 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
187 event = a; \
188 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
189 wmi_event_log_buf_info.buf) \
190 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
191 wmi_record_max_length); \
192 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
193 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530194 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530195 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
196 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530197}
198
Govind Singhecf03cd2016-05-12 12:45:51 +0530199#define WMI_RX_EVENT_RECORD(h, a, b) { \
200 if (wmi_log_max_entry <= \
201 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
202 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
203 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
204 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
205 event = a; \
206 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
207 wmi_rx_event_log_buf_info.buf) \
208 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
209 data, b, wmi_record_max_length); \
210 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
211 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
212 time = qdf_get_log_timestamp(); \
213 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
214 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530215}
Govind Singh6b411b52016-03-06 19:55:02 +0530216
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530217#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530218uint32_t g_wmi_mgmt_command_buf_idx = 0;
219struct
220wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
221
222/* wmi_mgmt commands TX completed */
223uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
224struct wmi_command_debug
225wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
226
227/* wmi_mgmt events when processed */
228uint32_t g_wmi_mgmt_event_buf_idx = 0;
229struct wmi_event_debug
230wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530231#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530232
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530233#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
234 if (wmi_mgmt_log_max_entry <= \
235 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
236 *(h->log_info.wmi_mgmt_command_log_buf_info. \
237 p_buf_tail_idx) = 0; \
238 ((struct wmi_command_debug *)h->log_info. \
239 wmi_mgmt_command_log_buf_info.buf) \
240 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
241 command = a; \
242 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
243 wmi_mgmt_command_log_buf_info.buf) \
244 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
245 data, b, \
246 wmi_record_max_length); \
247 ((struct wmi_command_debug *)h->log_info. \
248 wmi_mgmt_command_log_buf_info.buf) \
249 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
250 time = qdf_get_log_timestamp(); \
251 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
252 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530253}
254
Govind Singhecf03cd2016-05-12 12:45:51 +0530255#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
256 if (wmi_mgmt_log_max_entry <= \
257 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
258 p_buf_tail_idx)) \
259 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
260 p_buf_tail_idx) = 0; \
261 ((struct wmi_command_debug *)h->log_info. \
262 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
263 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
264 p_buf_tail_idx)].command = a; \
265 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
266 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
267 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
268 p_buf_tail_idx)].data, b, \
269 wmi_record_max_length); \
270 ((struct wmi_command_debug *)h->log_info. \
271 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
272 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
273 p_buf_tail_idx)].time = \
274 qdf_get_log_timestamp(); \
275 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
276 p_buf_tail_idx))++; \
277 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530278}
279
Govind Singhecf03cd2016-05-12 12:45:51 +0530280#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
281 if (wmi_mgmt_log_max_entry <= \
282 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
283 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
284 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
285 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
286 .event = a; \
287 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
288 wmi_mgmt_event_log_buf_info.buf) \
289 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
290 data, b, wmi_record_max_length); \
291 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
292 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
293 time = qdf_get_log_timestamp(); \
294 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
295 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530296}
297
Govind Singhecf03cd2016-05-12 12:45:51 +0530298/* These are defined to made it as module param, which can be configured */
299uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
300uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
301uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
302uint32_t wmi_display_size = 100;
303
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530304static uint8_t *wmi_id_to_name(uint32_t wmi_command);
Govind Singhecf03cd2016-05-12 12:45:51 +0530305
306/**
307 * wmi_log_init() - Initialize WMI event logging
308 * @wmi_handle: WMI handle.
309 *
310 * Return: Initialization status
311 */
312#ifdef CONFIG_MCL
313static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
314{
315 struct wmi_log_buf_t *cmd_log_buf =
316 &wmi_handle->log_info.wmi_command_log_buf_info;
317 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
318 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
319
320 struct wmi_log_buf_t *event_log_buf =
321 &wmi_handle->log_info.wmi_event_log_buf_info;
322 struct wmi_log_buf_t *rx_event_log_buf =
323 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
324
325 struct wmi_log_buf_t *mgmt_cmd_log_buf =
326 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
327 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
328 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
329 struct wmi_log_buf_t *mgmt_event_log_buf =
330 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
331
332 /* WMI commands */
333 cmd_log_buf->length = 0;
334 cmd_log_buf->buf_tail_idx = 0;
335 cmd_log_buf->buf = wmi_command_log_buffer;
336 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700337 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530338
339 /* WMI commands TX completed */
340 cmd_tx_cmpl_log_buf->length = 0;
341 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
342 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
343 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700344 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530345
346 /* WMI events when processed */
347 event_log_buf->length = 0;
348 event_log_buf->buf_tail_idx = 0;
349 event_log_buf->buf = wmi_event_log_buffer;
350 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700351 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530352
353 /* WMI events when queued */
354 rx_event_log_buf->length = 0;
355 rx_event_log_buf->buf_tail_idx = 0;
356 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
357 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700358 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530359
360 /* WMI Management commands */
361 mgmt_cmd_log_buf->length = 0;
362 mgmt_cmd_log_buf->buf_tail_idx = 0;
363 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
364 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700365 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530366
367 /* WMI Management commands Tx completed*/
368 mgmt_cmd_tx_cmp_log_buf->length = 0;
369 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
370 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
371 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
372 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700373 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530374
375 /* WMI Management events when processed*/
376 mgmt_event_log_buf->length = 0;
377 mgmt_event_log_buf->buf_tail_idx = 0;
378 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
379 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700380 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530381
382 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
383 wmi_handle->log_info.wmi_logging_enable = 1;
384
385 return QDF_STATUS_SUCCESS;
386}
387#else
388static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
389{
390 struct wmi_log_buf_t *cmd_log_buf =
391 &wmi_handle->log_info.wmi_command_log_buf_info;
392 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
393 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
394
395 struct wmi_log_buf_t *event_log_buf =
396 &wmi_handle->log_info.wmi_event_log_buf_info;
397 struct wmi_log_buf_t *rx_event_log_buf =
398 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
399
400 struct wmi_log_buf_t *mgmt_cmd_log_buf =
401 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
402 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
403 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
404 struct wmi_log_buf_t *mgmt_event_log_buf =
405 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
406
407 wmi_handle->log_info.wmi_logging_enable = 0;
408
409 /* WMI commands */
410 cmd_log_buf->length = 0;
411 cmd_log_buf->buf_tail_idx = 0;
412 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
413 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700414 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530415
416 if (!cmd_log_buf->buf) {
417 qdf_print("no memory for WMI command log buffer..\n");
418 return QDF_STATUS_E_NOMEM;
419 }
420 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
421
422 /* WMI commands TX completed */
423 cmd_tx_cmpl_log_buf->length = 0;
424 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
425 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
426 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700427 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530428
429 if (!cmd_tx_cmpl_log_buf->buf) {
430 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
431 return QDF_STATUS_E_NOMEM;
432 }
433 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
434 &cmd_tx_cmpl_log_buf->buf_tail_idx;
435
436 /* WMI events when processed */
437 event_log_buf->length = 0;
438 event_log_buf->buf_tail_idx = 0;
439 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
440 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700441 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530442
443 if (!event_log_buf->buf) {
444 qdf_print("no memory for WMI Event log buffer..\n");
445 return QDF_STATUS_E_NOMEM;
446 }
447 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
448
449 /* WMI events when queued */
450 rx_event_log_buf->length = 0;
451 rx_event_log_buf->buf_tail_idx = 0;
452 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
453 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700454 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530455
456 if (!rx_event_log_buf->buf) {
457 qdf_print("no memory for WMI Event Rx log buffer..\n");
458 return QDF_STATUS_E_NOMEM;
459 }
460 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
461
462 /* WMI Management commands */
463 mgmt_cmd_log_buf->length = 0;
464 mgmt_cmd_log_buf->buf_tail_idx = 0;
465 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700466 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
467 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530468
469 if (!mgmt_cmd_log_buf->buf) {
470 qdf_print("no memory for WMI Management Command log buffer..\n");
471 return QDF_STATUS_E_NOMEM;
472 }
473 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
474
475 /* WMI Management commands Tx completed*/
476 mgmt_cmd_tx_cmp_log_buf->length = 0;
477 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
478 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
479 qdf_mem_malloc(
480 wmi_mgmt_log_max_entry *
481 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700482 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530483
484 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
485 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
486 return QDF_STATUS_E_NOMEM;
487 }
488 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
489 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
490
491 /* WMI Management events when processed*/
492 mgmt_event_log_buf->length = 0;
493 mgmt_event_log_buf->buf_tail_idx = 0;
494
495 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
496 wmi_mgmt_log_max_entry *
497 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700498 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530499
500 if (!mgmt_event_log_buf->buf) {
501 qdf_print("no memory for WMI Management Event log buffer..\n");
502 return QDF_STATUS_E_NOMEM;
503 }
504 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
505
506 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
507 wmi_handle->log_info.wmi_logging_enable = 1;
508
509 return QDF_STATUS_SUCCESS;
510}
511#endif
512
513/**
514 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
515 * event logging
516 * @wmi_handle: WMI handle.
517 *
518 * Return: None
519 */
520#ifndef CONFIG_MCL
521static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
522{
523 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
524 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
525 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
526 qdf_mem_free(
527 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
528 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
529 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
530 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
531 qdf_mem_free(
532 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
533 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
534 qdf_mem_free(
535 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
536 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
537 qdf_mem_free(
538 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
539 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
540 qdf_mem_free(
541 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
542 wmi_handle->log_info.wmi_logging_enable = 0;
543 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
544}
545#else
546static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
547{
548 /* Do Nothing */
549}
550#endif
551
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700552/**
553 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
554 * @log_buffer: the command log buffer metadata of the buffer to print
555 * @count: the maximum number of entries to print
556 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
557 * @print_priv: any data required by the print method, e.g. a file handle
558 *
559 * Return: None
560 */
561static void
562wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
563 qdf_abstract_print *print, void *print_priv)
564{
565 static const int data_len =
566 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
567 char str[128];
568 uint32_t idx;
569
570 if (count > log_buffer->size)
571 count = log_buffer->size;
572 if (count > log_buffer->length)
573 count = log_buffer->length;
574
575 /* subtract count from index, and wrap if necessary */
576 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
577 idx %= log_buffer->size;
578
579 print(print_priv, "Time (seconds) Cmd Id Payload");
580 while (count) {
581 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
582 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700583 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700584 int len = 0;
585 int i;
586
Dustin Brown8ea39122017-04-10 13:26:56 -0700587 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700588 len += scnprintf(str + len, sizeof(str) - len,
589 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700590 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700591 cmd_log->command, cmd_log->command);
592 for (i = 0; i < data_len; ++i) {
593 len += scnprintf(str + len, sizeof(str) - len,
594 "0x%08x ", cmd_log->data[i]);
595 }
596
597 print(print_priv, str);
598
599 --count;
600 ++idx;
601 if (idx >= log_buffer->size)
602 idx = 0;
603 }
604}
605
606/**
607 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
608 * @log_buffer: the event log buffer metadata of the buffer to print
609 * @count: the maximum number of entries to print
610 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
611 * @print_priv: any data required by the print method, e.g. a file handle
612 *
613 * Return: None
614 */
615static void
616wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
617 qdf_abstract_print *print, void *print_priv)
618{
619 static const int data_len =
620 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
621 char str[128];
622 uint32_t idx;
623
624 if (count > log_buffer->size)
625 count = log_buffer->size;
626 if (count > log_buffer->length)
627 count = log_buffer->length;
628
629 /* subtract count from index, and wrap if necessary */
630 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
631 idx %= log_buffer->size;
632
633 print(print_priv, "Time (seconds) Event Id Payload");
634 while (count) {
635 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
636 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700637 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700638 int len = 0;
639 int i;
640
Dustin Brown8ea39122017-04-10 13:26:56 -0700641 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700642 len += scnprintf(str + len, sizeof(str) - len,
643 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700644 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700645 event_log->event, event_log->event);
646 for (i = 0; i < data_len; ++i) {
647 len += scnprintf(str + len, sizeof(str) - len,
648 "0x%08x ", event_log->data[i]);
649 }
650
651 print(print_priv, str);
652
653 --count;
654 ++idx;
655 if (idx >= log_buffer->size)
656 idx = 0;
657 }
658}
659
660inline void
661wmi_print_cmd_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_log_buf_info,
666 count, print, print_priv);
667}
668
669inline void
670wmi_print_cmd_tx_cmp_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_command_tx_cmp_log_buf_info,
675 count, print, print_priv);
676}
677
678inline void
679wmi_print_mgmt_cmd_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_log_buf_info,
684 count, print, print_priv);
685}
686
687inline void
688wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
689 qdf_abstract_print *print, void *print_priv)
690{
691 wmi_print_cmd_log_buffer(
692 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
693 count, print, print_priv);
694}
695
696inline void
697wmi_print_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_event_log_buf_info,
702 count, print, print_priv);
703}
704
705inline void
706wmi_print_rx_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_rx_event_log_buf_info,
711 count, print, print_priv);
712}
713
714inline void
715wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
716 qdf_abstract_print *print, void *print_priv)
717{
718 wmi_print_event_log_buffer(
719 &wmi->log_info.wmi_mgmt_event_log_buf_info,
720 count, print, print_priv);
721}
722
Govind Singhecf03cd2016-05-12 12:45:51 +0530723#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530724const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530725#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530726const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530727#endif
728
729/* debugfs routines*/
730
731/**
732 * debug_wmi_##func_base##_show() - debugfs functions to display content of
733 * command and event buffers. Macro uses max buffer length to display
734 * buffer when it is wraparound.
735 *
736 * @m: debugfs handler to access wmi_handle
737 * @v: Variable arguments (not used)
738 *
739 * Return: Length of characters printed
740 */
741#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
742 static int debug_wmi_##func_base##_show(struct seq_file *m, \
743 void *v) \
744 { \
745 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
746 struct wmi_log_buf_t *wmi_log = \
747 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
748 int pos, nread, outlen; \
749 int i; \
750 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530751 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
752 if (!wmi_log->length) { \
753 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530754 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530755 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530756 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530757 \
758 if (wmi_log->length <= wmi_ring_size) \
759 nread = wmi_log->length; \
760 else \
761 nread = wmi_ring_size; \
762 \
763 if (*(wmi_log->p_buf_tail_idx) == 0) \
764 /* tail can be 0 after wrap-around */ \
765 pos = wmi_ring_size - 1; \
766 else \
767 pos = *(wmi_log->p_buf_tail_idx) - 1; \
768 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530769 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530770 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530771 while (nread--) { \
772 struct wmi_command_debug *wmi_record; \
773 \
774 wmi_record = (struct wmi_command_debug *) \
775 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530776 outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530777 (wmi_record->command)); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530778 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530779 for (i = 0; i < (wmi_record_max_length/ \
780 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530781 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530782 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530783 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530784 \
785 if (pos == 0) \
786 pos = wmi_ring_size - 1; \
787 else \
788 pos--; \
789 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530790 return outlen; \
791 } \
792
793#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
794 static int debug_wmi_##func_base##_show(struct seq_file *m, \
795 void *v) \
796 { \
797 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
798 struct wmi_log_buf_t *wmi_log = \
799 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
800 int pos, nread, outlen; \
801 int i; \
802 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530803 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
804 if (!wmi_log->length) { \
805 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Pratik Gandhi795ab912017-05-03 20:15:50 +0530806 return wmi_bp_seq_printf(m, \
Govind Singhecf03cd2016-05-12 12:45:51 +0530807 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530808 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530809 \
810 if (wmi_log->length <= wmi_ring_size) \
811 nread = wmi_log->length; \
812 else \
813 nread = wmi_ring_size; \
814 \
815 if (*(wmi_log->p_buf_tail_idx) == 0) \
816 /* tail can be 0 after wrap-around */ \
817 pos = wmi_ring_size - 1; \
818 else \
819 pos = *(wmi_log->p_buf_tail_idx) - 1; \
820 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530821 outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530822 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530823 while (nread--) { \
824 struct wmi_event_debug *wmi_record; \
825 \
826 wmi_record = (struct wmi_event_debug *) \
827 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
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)); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530830 outlen += wmi_bp_seq_printf(m, "CMD = "); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530831 for (i = 0; i < (wmi_record_max_length/ \
832 sizeof(uint32_t)); i++) \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530833 outlen += wmi_bp_seq_printf(m, "%x ", \
Govind Singhecf03cd2016-05-12 12:45:51 +0530834 wmi_record->data[i]); \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530835 outlen += wmi_bp_seq_printf(m, "\n"); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530836 \
837 if (pos == 0) \
838 pos = wmi_ring_size - 1; \
839 else \
840 pos--; \
841 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530842 return outlen; \
843 }
844
845GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
846GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
847GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
848GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
849GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
850GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
851 wmi_display_size);
852GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
853
854/**
855 * debug_wmi_enable_show() - debugfs functions to display enable state of
856 * wmi logging feature.
857 *
858 * @m: debugfs handler to access wmi_handle
859 * @v: Variable arguments (not used)
860 *
861 * Return: always 1
862 */
863static int debug_wmi_enable_show(struct seq_file *m, void *v)
864{
865 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
866
Pratik Gandhi795ab912017-05-03 20:15:50 +0530867 return wmi_bp_seq_printf(m, "%d\n",
868 wmi_handle->log_info.wmi_logging_enable);
Govind Singhecf03cd2016-05-12 12:45:51 +0530869}
870
871/**
872 * debug_wmi_log_size_show() - debugfs functions to display configured size of
873 * wmi logging command/event buffer and management command/event buffer.
874 *
875 * @m: debugfs handler to access wmi_handle
876 * @v: Variable arguments (not used)
877 *
878 * Return: Length of characters printed
879 */
880static int debug_wmi_log_size_show(struct seq_file *m, void *v)
881{
882
Pratik Gandhi795ab912017-05-03 20:15:50 +0530883 wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
884 wmi_log_max_entry);
885 return wmi_bp_seq_printf(m,
886 "WMI management command/events log max size:%d\n",
887 wmi_mgmt_log_max_entry);
Govind Singhecf03cd2016-05-12 12:45:51 +0530888}
889
890/**
891 * debug_wmi_##func_base##_write() - debugfs functions to clear
892 * wmi logging command/event buffer and management command/event buffer.
893 *
894 * @file: file handler to access wmi_handle
895 * @buf: received data buffer
896 * @count: length of received buffer
897 * @ppos: Not used
898 *
899 * Return: count
900 */
901#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
902 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
903 const char __user *buf, \
904 size_t count, loff_t *ppos) \
905 { \
906 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530907 wmi_unified_t wmi_handle = \
908 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530909 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
910 wmi_##func_base##_buf_info; \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530911 char locbuf[50]; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530912 \
Pratik Gandhi795ab912017-05-03 20:15:50 +0530913 if ((!buf) || (count > 50)) \
914 return -EFAULT; \
915 \
916 if (copy_from_user(locbuf, buf, count)) \
917 return -EFAULT; \
918 \
919 ret = sscanf(locbuf, "%d", &k); \
920 if ((ret != 1) || (k != 0)) { \
Govind Singhecf03cd2016-05-12 12:45:51 +0530921 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
922 return -EINVAL; \
923 } \
924 \
925 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
926 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
927 sizeof(struct wmi_record_type)); \
928 wmi_log->length = 0; \
929 *(wmi_log->p_buf_tail_idx) = 0; \
930 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
931 \
932 return count; \
933 }
934
935GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
936 wmi_command_debug);
937GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
938 wmi_command_debug);
939GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
940 wmi_event_debug);
941GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
942 wmi_event_debug);
943GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
944 wmi_command_debug);
945GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
946 wmi_mgmt_log_max_entry, wmi_command_debug);
947GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
948 wmi_event_debug);
949
950/**
951 * debug_wmi_enable_write() - debugfs functions to enable/disable
952 * wmi logging feature.
953 *
954 * @file: file handler to access wmi_handle
955 * @buf: received data buffer
956 * @count: length of received buffer
957 * @ppos: Not used
958 *
959 * Return: count
960 */
961static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
962 size_t count, loff_t *ppos)
963{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530964 wmi_unified_t wmi_handle =
965 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530966 int k, ret;
Pratik Gandhi795ab912017-05-03 20:15:50 +0530967 char locbuf[50];
Govind Singhecf03cd2016-05-12 12:45:51 +0530968
Pratik Gandhi795ab912017-05-03 20:15:50 +0530969 if ((!buf) || (count > 50))
970 return -EFAULT;
971
972 if (copy_from_user(locbuf, buf, count))
973 return -EFAULT;
974
975 ret = sscanf(locbuf, "%d", &k);
Govind Singhecf03cd2016-05-12 12:45:51 +0530976 if ((ret != 1) || ((k != 0) && (k != 1)))
977 return -EINVAL;
978
979 wmi_handle->log_info.wmi_logging_enable = k;
980 return count;
981}
982
983/**
984 * debug_wmi_log_size_write() - reserved.
985 *
986 * @file: file handler to access wmi_handle
987 * @buf: received data buffer
988 * @count: length of received buffer
989 * @ppos: Not used
990 *
991 * Return: count
992 */
993static ssize_t debug_wmi_log_size_write(struct file *file,
994 const char __user *buf, size_t count, loff_t *ppos)
995{
996 return -EINVAL;
997}
998
999/* Structure to maintain debug information */
1000struct wmi_debugfs_info {
1001 const char *name;
1002 struct dentry *de[MAX_WMI_INSTANCES];
1003 const struct file_operations *ops;
1004};
1005
1006#define DEBUG_FOO(func_base) { .name = #func_base, \
1007 .ops = &debug_##func_base##_ops }
1008
1009/**
1010 * debug_##func_base##_open() - Open debugfs entry for respective command
1011 * and event buffer.
1012 *
1013 * @inode: node for debug dir entry
1014 * @file: file handler
1015 *
1016 * Return: open status
1017 */
1018#define GENERATE_DEBUG_STRUCTS(func_base) \
1019 static int debug_##func_base##_open(struct inode *inode, \
1020 struct file *file) \
1021 { \
1022 return single_open(file, debug_##func_base##_show, \
1023 inode->i_private); \
1024 } \
1025 \
1026 \
1027 static struct file_operations debug_##func_base##_ops = { \
1028 .open = debug_##func_base##_open, \
1029 .read = seq_read, \
1030 .llseek = seq_lseek, \
1031 .write = debug_##func_base##_write, \
1032 .release = single_release, \
1033 };
1034
1035GENERATE_DEBUG_STRUCTS(wmi_command_log);
1036GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1037GENERATE_DEBUG_STRUCTS(wmi_event_log);
1038GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1039GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1040GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1041GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1042GENERATE_DEBUG_STRUCTS(wmi_enable);
1043GENERATE_DEBUG_STRUCTS(wmi_log_size);
1044
1045struct wmi_debugfs_info wmi_debugfs_infos[] = {
1046 DEBUG_FOO(wmi_command_log),
1047 DEBUG_FOO(wmi_command_tx_cmp_log),
1048 DEBUG_FOO(wmi_event_log),
1049 DEBUG_FOO(wmi_rx_event_log),
1050 DEBUG_FOO(wmi_mgmt_command_log),
1051 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1052 DEBUG_FOO(wmi_mgmt_event_log),
1053 DEBUG_FOO(wmi_enable),
1054 DEBUG_FOO(wmi_log_size),
1055};
1056
1057#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1058 sizeof(wmi_debugfs_infos[0]))
1059
1060/**
1061 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1062 *
1063 * @wmi_handle: wmi handle
1064 * @par_entry: debug directory entry
1065 * @id: Index to debug info data array
1066 *
1067 * Return: none
1068 */
1069static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1070 struct dentry *par_entry, int id)
1071{
1072 int i;
1073
1074 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1075 goto out;
1076
1077 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1078
1079 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1080 wmi_debugfs_infos[i].name, 0644, par_entry,
1081 wmi_handle, wmi_debugfs_infos[i].ops);
1082
1083 if (wmi_debugfs_infos[i].de[id] == NULL) {
1084 qdf_print("%s: debug Entry creation failed!\n",
1085 __func__);
1086 goto out;
1087 }
1088 }
1089
1090 return;
1091
1092out:
1093 qdf_print("%s: debug Entry creation failed!\n", __func__);
1094 wmi_log_buffer_free(wmi_handle);
1095 return;
1096}
1097
1098/**
1099 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301100 * @wmi_handle: wmi handle
1101 * @dentry: debugfs directory entry
1102 * @id: Index to debug info data array
1103 *
1104 * Return: none
1105 */
Govind Singh06c18392016-06-10 10:33:19 +05301106static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301107{
1108 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301109 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
1110 int id = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301111
1112 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1113 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1114 if (wmi_debugfs_infos[i].de[id])
1115 wmi_debugfs_infos[i].de[id] = NULL;
1116 }
1117 }
1118
1119 if (dentry)
1120 debugfs_remove_recursive(dentry);
1121}
1122
1123/**
1124 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1125 * create debugfs enteries.
1126 *
1127 * @h: wmi handler
1128 *
1129 * Return: init status
1130 */
1131static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1132{
1133 static int wmi_index;
1134
1135 if (wmi_index < MAX_WMI_INSTANCES)
1136 wmi_handle->log_info.wmi_log_debugfs_dir =
1137 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1138
1139 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
1140 qdf_print("error while creating debugfs dir for %s\n",
1141 debugfs_dir[wmi_index]);
1142 return QDF_STATUS_E_FAILURE;
1143 }
1144
1145 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
1146 wmi_index);
1147 wmi_handle->log_info.wmi_instance_id = wmi_index++;
1148
1149 return QDF_STATUS_SUCCESS;
1150}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001151
1152/**
1153 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1154 *
1155 * @wmi_handle: wmi handle
1156 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001157 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001158 * @vdev_id: vdev id
1159 * @chanfreq: channel frequency
1160 *
1161 * Return: none
1162 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301163void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001164 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001165{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301166
1167 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1168
1169 data[0] = ((struct wmi_command_header *)header)->type;
1170 data[1] = ((struct wmi_command_header *)header)->sub_type;
1171 data[2] = vdev_id;
1172 data[3] = chanfreq;
1173
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001174 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1175
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301176 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001177
1178 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1179}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001180#else
1181/**
1182 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1183 * @wmi_handle: wmi handle
1184 * @dentry: debugfs directory entry
1185 * @id: Index to debug info data array
1186 *
1187 * Return: none
1188 */
Govind Singh06c18392016-06-10 10:33:19 +05301189static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301190void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001191 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301192static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301193#endif /*WMI_INTERFACE_EVENT_LOGGING */
1194
Govind Singh6b411b52016-03-06 19:55:02 +05301195int wmi_get_host_credits(wmi_unified_t wmi_handle);
1196/* WMI buffer APIs */
1197
1198#ifdef MEMORY_DEBUG
1199wmi_buf_t
1200wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301201 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301202{
1203 wmi_buf_t wmi_buf;
1204
1205 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301206 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301207 return NULL;
1208 }
1209
Govind Singhb53420c2016-03-09 14:32:57 +05301210 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301211 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1212 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1213 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301214
1215 if (!wmi_buf)
1216 return NULL;
1217
1218 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301219 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301220
1221 /*
1222 * Set the length of the buffer to match the allocation size.
1223 */
Govind Singhb53420c2016-03-09 14:32:57 +05301224 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301225
1226 return wmi_buf;
1227}
1228
1229void wmi_buf_free(wmi_buf_t net_buf)
1230{
Govind Singhb53420c2016-03-09 14:32:57 +05301231 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301232}
1233#else
1234wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1235{
1236 wmi_buf_t wmi_buf;
1237
1238 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301239 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301240 return NULL;
1241 }
1242
Govind Singhb53420c2016-03-09 14:32:57 +05301243 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301244 WMI_MIN_HEAD_ROOM, 4, false);
1245 if (!wmi_buf)
1246 return NULL;
1247
1248 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301249 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301250
1251 /*
1252 * Set the length of the buffer to match the allocation size.
1253 */
Govind Singhb53420c2016-03-09 14:32:57 +05301254 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301255 return wmi_buf;
1256}
1257
1258void wmi_buf_free(wmi_buf_t net_buf)
1259{
Govind Singhb53420c2016-03-09 14:32:57 +05301260 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301261}
1262#endif
1263
1264/**
1265 * wmi_get_max_msg_len() - get maximum WMI message length
1266 * @wmi_handle: WMI handle.
1267 *
1268 * This function returns the maximum WMI message length
1269 *
1270 * Return: maximum WMI message length
1271 */
1272uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1273{
1274 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1275}
1276
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301277#ifdef CONFIG_MCL
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301278static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +05301279{
1280 switch (wmi_command) {
1281 /* initialize the wlan sub system */
1282 CASE_RETURN_STRING(WMI_INIT_CMDID);
1283
1284 /* Scan specific commands */
1285
1286 /* start scan request to FW */
1287 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1288 /* stop scan request to FW */
1289 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1290 /* full list of channels as defined by the regulatory
1291 * that will be used by scanner */
1292 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1293 /* overwrite default priority table in scan scheduler */
1294 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1295 /* This command to adjust the priority and min.max_rest_time
1296 * of an on ongoing scan request.
1297 */
1298 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1299
1300 /* PDEV(physical device) specific commands */
1301 /* set regulatorty ctl id used by FW to determine the exact
1302 * ctl power limits */
1303 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1304 /* set channel. mainly used for supporting monitor mode */
1305 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1306 /* set pdev specific parameters */
1307 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1308 /* enable packet log */
1309 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1310 /* disable packet log*/
1311 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1312 /* set wmm parameters */
1313 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1314 /* set HT cap ie that needs to be carried probe requests
1315 * HT/VHT channels */
1316 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1317 /* set VHT cap ie that needs to be carried on probe
1318 * requests on VHT channels */
1319 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1320
1321 /* Command to send the DSCP-to-TID map to the target */
1322 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1323 /* set quiet ie parameters. primarily used in AP mode */
1324 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1325 /* Enable/Disable Green AP Power Save */
1326 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1327 /* get TPC config for the current operating channel */
1328 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1329
1330 /* set the base MAC address for the physical device before
1331 * a VDEV is created. For firmware that does not support
1332 * this feature and this command, the pdev MAC address will
1333 * not be changed. */
1334 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1335
1336 /* eeprom content dump , the same to bdboard data */
1337 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1338
1339 /* VDEV(virtual device) specific commands */
1340 /* vdev create */
1341 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1342 /* vdev delete */
1343 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1344 /* vdev start request */
1345 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1346 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1347 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1348 /* vdev up request */
1349 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1350 /* vdev stop request */
1351 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1352 /* vdev down request */
1353 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1354 /* set a vdev param */
1355 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1356 /* set a key (used for setting per peer unicast
1357 * and per vdev multicast) */
1358 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1359
1360 /* wnm sleep mode command */
1361 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1362 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1363 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1364 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1365 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1366 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1367
1368 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1369 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1370 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1371 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1372
1373 /* peer specific commands */
1374
1375 /** create a peer */
1376 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1377 /** delete a peer */
1378 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1379 /** flush specific tid queues of a peer */
1380 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1381 /** set a parameter of a peer */
1382 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1383 /* set peer to associated state. will cary all parameters
1384 * determined during assocication time */
1385 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1386 /* add a wds (4 address ) entry. used only for testing
1387 * WDS feature on AP products */
1388 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1389 /* remove wds (4 address ) entry. used only for testing WDS
1390 * feature on AP products */
1391 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1392 /* set up mcast info for multicast to unicast conversion */
1393 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1394 /* request peer info from FW to get PEER_INFO_EVENTID */
1395 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1396
1397 /* beacon/management specific commands */
1398
1399 /* transmit beacon by reference. used for transmitting beacon
1400 * on low latency interface like pcie */
1401 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1402 /* transmit beacon by value */
1403 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1404 /* set the beacon template. used in beacon offload mode to setup
1405 * the common beacon template with the FW to be used by FW to
1406 * generate beacons */
1407 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1408 /* set beacon filter with FW */
1409 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1410 /* enable/disable filtering of probe requests in the firmware */
1411 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1412 /* transmit management frame by value. will be deprecated */
1413 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1414 /* set the probe response template. used in beacon offload mode
1415 * to setup the common probe response template with the FW to
1416 * be used by FW to generate probe responses */
1417 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1418
1419 /* commands to directly control ba negotiation directly from
1420 * host. only used in test mode */
1421
1422 /* turn off FW Auto addba mode and let host control addba */
1423 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1424 /* send add ba request */
1425 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1426 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1427 /* send del ba */
1428 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1429 /* set add ba response will be used by FW to generate
1430 * addba response*/
1431 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1432 /* send single VHT MPDU with AMSDU */
1433 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1434
1435 /* Station power save specific config */
1436 /* enable/disable station powersave */
1437 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1438 /* set station power save specific parameter */
1439 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1440 /* set station mimo powersave mode */
1441 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1442
1443 /* DFS-specific commands */
1444 /* enable DFS (radar detection)*/
1445 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1446 /* disable DFS (radar detection)*/
1447 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1448 /* enable DFS phyerr/parse filter offload */
1449 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1450 /* enable DFS phyerr/parse filter offload */
1451 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1452
1453 /* Roaming specific commands */
1454 /* set roam scan mode */
1455 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1456 /* set roam scan rssi threshold below which roam
1457 * scan is enabled */
1458 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1459 /* set roam scan period for periodic roam scan mode */
1460 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1461 /* set roam scan trigger rssi change threshold */
1462 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1463 /* set roam AP profile */
1464 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1465 /* set channel list for roam scans */
1466 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1467 /* offload scan specific commands */
1468 /* set offload scan AP profile */
1469 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1470 /* remove offload scan AP profile */
1471 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1472 /* set offload scan period */
1473 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1474
1475 /* P2P specific commands */
1476 /* set P2P device info. FW will used by FW to create P2P IE
1477 * to be carried in probe response generated during p2p listen
1478 * and for p2p discoverability */
1479 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1480 /* enable/disable p2p discoverability on STA/AP VDEVs */
1481 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1482 /* set p2p ie to be carried in beacons generated by FW for GO */
1483 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1484 /* set p2p ie to be carried in probe response frames generated
1485 * by FW for GO */
1486 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1487 /* set the vendor specific p2p ie data.
1488 * FW will use this to parse the P2P NoA
1489 * attribute in the beacons/probe responses received.
1490 */
1491 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1492 /* set the configure of p2p find offload */
1493 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1494 /* set the vendor specific p2p ie data for p2p find offload */
1495 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1496 /* set the BSSID/device name pattern of p2p find offload */
1497 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1498 /* set OppPS related parameters **/
1499 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1500
1501 /* AP power save specific config
1502 * set AP power save specific param */
1503 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1504 /* set AP UAPSD coex pecific param */
1505 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1506
1507 /* Rate-control specific commands */
1508 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1509
1510 /* WLAN Profiling commands. */
1511 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1512 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1513 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1514 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1515 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1516
1517 /* Suspend resume command Ids */
1518 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1519 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1520
1521 /* Beacon filter commands */
1522 /* add a beacon filter */
1523 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1524 /* remove a beacon filter */
1525 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1526
1527 /* WOW Specific WMI commands */
1528 /* add pattern for awake */
1529 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1530 /* deleta a wake pattern */
1531 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1532 /* enable/deisable wake event */
1533 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1534 /* enable WOW */
1535 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1536 /* host woke up from sleep event to FW. Generated in response
1537 * to WOW Hardware event */
1538 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1539
1540 /* RTT measurement related cmd */
1541 /* reques to make an RTT measurement */
1542 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1543 /* reques to report a tsf measurement */
1544 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1545
1546 /* spectral scan command */
1547 /* configure spectral scan */
1548 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1549 /* enable/disable spectral scan and trigger */
1550 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1551
1552 /* F/W stats */
1553 /* one time request for stats */
1554 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1555 /* Push MCC Adaptive Scheduler Stats to Firmware */
1556 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1557
1558 /* ARP OFFLOAD REQUEST*/
1559 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1560
1561 /* Proactive ARP Response Add Pattern Command*/
1562 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1563
1564 /* Proactive ARP Response Del Pattern Command*/
1565 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1566
1567 /* NS offload confid*/
1568 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1569
1570 /* GTK offload Specific WMI commands */
1571 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1572
1573 /* CSA offload Specific WMI commands */
1574 /* csa offload enable */
1575 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1576 /* chan switch command */
1577 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1578
1579 /* Chatter commands */
1580 /* Change chatter mode of operation */
1581 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1582 /* chatter add coalescing filter command */
1583 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1584 /* chatter delete coalescing filter command */
1585 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1586 /* chatter coalecing query command */
1587 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1588
1589 /* addba specific commands */
1590 /* start the aggregation on this TID */
1591 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1592 /* stop the aggregation on this TID */
1593 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1594
1595 /* set station mimo powersave method */
1596 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1597 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1598 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1599 /* Configure the Keep Alive Parameters */
1600 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1601
1602 /* Request ssn from target for a sta/tid pair */
1603 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1604 /* misc command group */
1605 /* echo command mainly used for testing */
1606 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1607
1608 /* !!IMPORTANT!!
1609 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1610 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1611 * as we MUST have a fixed value here to maintain compatibility between
1612 * UTF and the ART2 driver
1613 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301614 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301615 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1616
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301617 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301618 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1619 /* QVIT specific command id */
1620 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1621 /* Factory Testing Mode request command
1622 * used for integrated chipsets */
1623 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1624 /* set and get keepalive parameters command */
1625 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1626 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1627 /* For fw recovery test command */
1628 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1629 /* Set Mcast/Bdcast filter */
1630 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1631 /* set thermal management params */
1632 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1633 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1634 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1635 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301636 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301637 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301638 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301639 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301640 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1641 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1642 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1643 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1644 /* GPIO Configuration */
1645 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1646 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1647
1648 /* Txbf configuration command */
1649 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1650
1651 /* FWTEST Commands */
1652 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1653 /* set NoA descs */
1654 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1655
1656 /* TDLS Configuration */
1657 /* enable/disable TDLS */
1658 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1659 /* set tdls peer state */
1660 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1661
1662 /* Resmgr Configuration */
1663 /* Adaptive OCS is enabled by default in the FW.
1664 * This command is used to disable FW based adaptive OCS.
1665 */
1666 CASE_RETURN_STRING
1667 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1668 /* set the requested channel time quota for the home channels */
1669 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1670 /* set the requested latency for the home channels */
1671 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1672
1673 /* STA SMPS Configuration */
1674 /* force SMPS mode */
1675 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1676 /* set SMPS parameters */
1677 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1678
1679 /* Wlan HB commands */
1680 /* enalbe/disable wlan HB */
1681 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1682 /* set tcp parameters for wlan HB */
1683 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1684 /* set tcp pkt filter for wlan HB */
1685 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1686 /* set udp parameters for wlan HB */
1687 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1688 /* set udp pkt filter for wlan HB */
1689 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1690
1691 /* Wlan RMC commands*/
1692 /* enable/disable RMC */
1693 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1694 /* configure action frame period */
1695 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1696 /* For debug/future enhancement purposes only,
1697 * configures/finetunes RMC algorithms */
1698 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1699
1700 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301701 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301702 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1703 /* Plumb routing table for MHF offload */
1704 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1705
1706 /* location scan commands */
1707 /* start batch scan */
1708 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1709 /* stop batch scan */
1710 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1711 /* get batch scan result */
1712 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1713 /* OEM related cmd */
1714 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1715 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1716 /* NAN request cmd */
1717 CASE_RETURN_STRING(WMI_NAN_CMDID);
1718 /* Modem power state cmd */
1719 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1720 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1721 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1722 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1723 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1724 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1725 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1726 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1727 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301728 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301729 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1730 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1731 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1732 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1733 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1734 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1735 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1736 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1737 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1738 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1739 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1740 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1741 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1742 CASE_RETURN_STRING
1743 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1744 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1745 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1746 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1747 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1748 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1749 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1750 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1751 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1752 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1753 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1754 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1755 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1756 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1757 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1758 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1759 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1760 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1761 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1762 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1763 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1764 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1765 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1766 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1767 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1768 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1769 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1770 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1771 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1772 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1773 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1774 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1775 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1776 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1777 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1778 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1779 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1780 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1781 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1782 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1783 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1784 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1785 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1786 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1787 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1788 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1789 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1790 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1791 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1792 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1793 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1794 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1795 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1796 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1797 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1798 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1799 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1800 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1801 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1802 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1803 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301804 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1805 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1806 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1807 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1808 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1809 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1810 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1811 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1812 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1813 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1814 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1815 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1816 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1817 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1818 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1819 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1820 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1821 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1822 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1823 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1824 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1825 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1826 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1827 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1828 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1829 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1830 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1831 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1832 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1833 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1834 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1835 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1836 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001837 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301838 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301839 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301840 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301841 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Himanshu Agarwaldc8d1ae2016-05-13 21:04:17 +05301842 CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
Himanshu Agarwalfc302f92016-05-30 21:06:16 +05301843 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
1844 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
Pradeep Reddy POTTETI18f8fbb2016-06-13 17:59:38 +05301845 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1846 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
Pradeep Reddy POTTETI4b997fd2016-06-20 13:25:31 +05301847 CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
Pradeep Reddy POTTETI10ca69d2016-06-20 14:50:42 +05301848 CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
Nitesh Shah70e11042016-06-29 20:16:16 +05301849 CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
1850 CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
Nitesh Shahc0482652016-07-08 11:45:33 +05301851 CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
Nitesh Shah33b95402016-07-21 17:25:55 +05301852 CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
1853 CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
Anurag Chouhan40865b42016-08-01 14:01:54 +05301854 CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
Anurag Chouhan7f6f1d52016-08-04 18:46:29 +05301855 CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
Manjeet Singhc026bde2016-09-01 16:42:29 +05301856 CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
Manjeet Singhbea16712016-08-18 15:50:30 +05301857 CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
1858 CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
Himanshu Agarwal91c9d672016-09-14 20:43:24 +05301859 CASE_RETURN_STRING(WMI_VDEV_ENCRYPT_DECRYPT_DATA_REQ_CMDID);
Sandeep Puligillaabcd0f52016-11-03 12:38:45 -07001860 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
1861 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_DISABLE_CMDID);
1862 CASE_RETURN_STRING(WMI_VDEV_ADFS_CH_CFG_CMDID);
1863 CASE_RETURN_STRING(WMI_VDEV_ADFS_OCAC_ABORT_CMDID);
Nishank Aggarwale6994d22016-11-08 13:34:12 +05301864 CASE_RETURN_STRING(WMI_SAR_LIMITS_CMDID);
Kiran Kumar Lokeredaf91e32017-04-24 00:56:03 -07001865 CASE_RETURN_STRING(WMI_SET_CURRENT_COUNTRY_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301866 }
1867
1868 return "Invalid WMI cmd";
1869}
1870
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001871#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301872static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301873{
1874 return "Invalid WMI cmd";
1875}
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301876#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301877
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301878#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301879static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
1880{
1881 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1882 wmi_id_to_name(cmd_id), cmd_id, tag);
1883}
1884
Govind Singh6b411b52016-03-06 19:55:02 +05301885/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301886 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1887 * @cmd_id: command to check
1888 *
1889 * Return: true if the command is part of the resume sequence.
1890 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301891static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301892{
1893 switch (cmd_id) {
1894 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1895 case WMI_PDEV_RESUME_CMDID:
1896 return true;
1897
1898 default:
1899 return false;
1900 }
1901}
1902#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301903static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301904{
1905 return false;
1906}
1907#endif
1908
1909/**
Govind Singh6b411b52016-03-06 19:55:02 +05301910 * wmi_unified_cmd_send() - WMI command API
1911 * @wmi_handle: handle to wmi
1912 * @buf: wmi buf
1913 * @len: wmi buffer length
1914 * @cmd_id: wmi command id
1915 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001916 * Note, it is NOT safe to access buf after calling this function!
1917 *
Govind Singh6b411b52016-03-06 19:55:02 +05301918 * Return: 0 on success
1919 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001920QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1921 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301922{
1923 HTC_PACKET *pkt;
Rakesh Pillai943a6c12017-06-22 12:52:31 +05301924 QDF_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301925 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301926
1927 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301928 htc_tag =
1929 (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
1930 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301931 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301932 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301933 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301934 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301935 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301936 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301937 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301938 if (wmi_handle->wmi_stopinprogress) {
1939 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1940 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001941 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301942 }
Govind Singh6b411b52016-03-06 19:55:02 +05301943
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301944#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301945 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301946 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301947 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301948
1949 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301950 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301951 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301952 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301953 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301954 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301955 }
1956 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301957#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301958
Govind Singhb53420c2016-03-09 14:32:57 +05301959 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1960 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301961 "%s, Failed to send cmd %x, no memory",
1962 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301963 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301964 }
1965
Govind Singhb53420c2016-03-09 14:32:57 +05301966 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301967
Govind Singhb53420c2016-03-09 14:32:57 +05301968 qdf_atomic_inc(&wmi_handle->pending_cmds);
1969 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1970 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301971 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301972 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301973 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301974 qdf_atomic_dec(&wmi_handle->pending_cmds);
1975 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301976 "%s: MAX %d WMI Pending cmds reached.", __func__,
1977 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301978 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301979 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301980 }
1981
Govind Singhb53420c2016-03-09 14:32:57 +05301982 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301983 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301984 qdf_atomic_dec(&wmi_handle->pending_cmds);
1985 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301986 "%s, Failed to alloc htc packet %x, no memory",
1987 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301988 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301989 }
1990
1991 SET_HTC_PACKET_INFO_TX(pkt,
1992 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301993 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301994 wmi_handle->wmi_endpoint_id, htc_tag);
1995
1996 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301997#ifdef CONFIG_MCL
Govind Singh2d8bfc62017-03-21 13:02:00 +05301998 wmi_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301999#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302000
2001#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302002 if (wmi_handle->log_info.wmi_logging_enable) {
2003 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05302004 /*Record 16 bytes of WMI cmd data -
2005 * * exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302006 if (wmi_handle->ops->is_management_record(cmd_id)) {
Pratik Gandhi29e33f02016-09-16 01:32:51 +05302007 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
2008 ((uint32_t *) qdf_nbuf_data(buf) +
2009 wmi_handle->log_info.buf_offset_command));
2010 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302011 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
2012 ((uint32_t *) qdf_nbuf_data(buf) +
2013 wmi_handle->log_info.buf_offset_command));
2014 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302015 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2016 }
Govind Singh6b411b52016-03-06 19:55:02 +05302017#endif
2018
2019 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
2020
Rakesh Pillai943a6c12017-06-22 12:52:31 +05302021 if (QDF_STATUS_SUCCESS != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05302022 qdf_atomic_dec(&wmi_handle->pending_cmds);
2023 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302024 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07002025 qdf_mem_free(pkt);
Rakesh Pillai943a6c12017-06-22 12:52:31 +05302026 return status;
Govind Singh6b411b52016-03-06 19:55:02 +05302027 }
Govind Singh6b411b52016-03-06 19:55:02 +05302028
Govind Singhb53420c2016-03-09 14:32:57 +05302029 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302030}
2031
2032/**
2033 * wmi_unified_get_event_handler_ix() - gives event handler's index
2034 * @wmi_handle: handle to wmi
2035 * @event_id: wmi event id
2036 *
2037 * Return: event handler's index
2038 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002039static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
2040 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302041{
2042 uint32_t idx = 0;
2043 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302044 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302045
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302046 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05302047 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
2048 if (wmi_handle->event_id[idx] == event_id &&
2049 wmi_handle->event_handler[idx] != NULL) {
2050 return idx;
2051 }
2052 }
2053
2054 return invalid_idx;
2055}
2056
2057/**
Soumya Bhat488092d2017-03-22 14:41:01 +05302058 * wmi_unified_register_event() - register wmi event handler
2059 * @wmi_handle: handle to wmi
2060 * @event_id: wmi event id
2061 * @handler_func: wmi event handler function
2062 *
2063 * Return: 0 on success
2064 */
2065int wmi_unified_register_event(wmi_unified_t wmi_handle,
2066 uint32_t event_id,
2067 wmi_unified_event_handler handler_func)
2068{
2069 uint32_t idx = 0;
2070 uint32_t evt_id;
2071 struct wmi_soc *soc = wmi_handle->soc;
2072
2073 if (event_id >= wmi_events_max ||
2074 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2075 qdf_print("%s: Event id %d is unavailable\n",
2076 __func__, event_id);
2077 return QDF_STATUS_E_FAILURE;
2078 }
2079 evt_id = wmi_handle->wmi_events[event_id];
2080 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2081 qdf_print("%s : event handler already registered 0x%x\n",
2082 __func__, evt_id);
2083 return QDF_STATUS_E_FAILURE;
2084 }
2085 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
2086 qdf_print("%s : no more event handlers 0x%x\n",
2087 __func__, evt_id);
2088 return QDF_STATUS_E_FAILURE;
2089 }
2090 idx = soc->max_event_idx;
2091 wmi_handle->event_handler[idx] = handler_func;
2092 wmi_handle->event_id[idx] = evt_id;
2093 qdf_spin_lock_bh(&soc->ctx_lock);
2094 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
2095 qdf_spin_unlock_bh(&soc->ctx_lock);
2096 soc->max_event_idx++;
2097
2098 return 0;
2099}
2100
2101/**
Govind Singh6b411b52016-03-06 19:55:02 +05302102 * wmi_unified_register_event_handler() - register wmi event handler
2103 * @wmi_handle: handle to wmi
2104 * @event_id: wmi event id
2105 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05302106 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05302107 *
Soumya Bhat488092d2017-03-22 14:41:01 +05302108 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05302109 * Return: 0 on success
2110 */
2111int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302112 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05302113 wmi_unified_event_handler handler_func,
2114 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302115{
2116 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302117 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302118 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302119
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302120#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302121 if (event_id >= wmi_events_max ||
2122 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2123 qdf_print("%s: Event id %d is unavailable\n",
2124 __func__, event_id);
2125 return QDF_STATUS_E_FAILURE;
2126 }
2127 evt_id = wmi_handle->wmi_events[event_id];
2128#else
2129 evt_id = event_id;
2130#endif
2131 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2132 qdf_print("%s : event handler already registered 0x%x\n",
2133 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302134 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302135 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302136 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302137 qdf_print("%s : no more event handlers 0x%x\n",
2138 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302139 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302140 }
Adil Saeed Musthafa4f2c98f2017-07-05 14:43:51 -07002141 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
2142 "Registered event handler for event 0x%8x\n", evt_id);
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302143 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302144 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302145 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302146 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302147 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302148 qdf_spin_unlock_bh(&soc->ctx_lock);
2149 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05302150
2151 return 0;
2152}
2153
2154/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05302155 * wmi_unified_unregister_event() - unregister wmi event handler
2156 * @wmi_handle: handle to wmi
2157 * @event_id: wmi event id
2158 *
2159 * Return: 0 on success
2160 */
2161int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
2162 uint32_t event_id)
2163{
2164 uint32_t idx = 0;
2165 uint32_t evt_id;
2166 struct wmi_soc *soc = wmi_handle->soc;
2167
2168 if (event_id >= wmi_events_max ||
2169 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2170 qdf_print("%s: Event id %d is unavailable\n",
2171 __func__, event_id);
2172 return QDF_STATUS_E_FAILURE;
2173 }
2174 evt_id = wmi_handle->wmi_events[event_id];
2175
2176 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
2177 if (idx == -1) {
2178 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2179 __func__, evt_id);
2180 return QDF_STATUS_E_FAILURE;
2181 }
2182 wmi_handle->event_handler[idx] = NULL;
2183 wmi_handle->event_id[idx] = 0;
2184 --soc->max_event_idx;
2185 wmi_handle->event_handler[idx] =
2186 wmi_handle->event_handler[soc->max_event_idx];
2187 wmi_handle->event_id[idx] =
2188 wmi_handle->event_id[soc->max_event_idx];
2189
2190 return 0;
2191}
2192
2193/**
Govind Singh6b411b52016-03-06 19:55:02 +05302194 * wmi_unified_unregister_event_handler() - unregister wmi event handler
2195 * @wmi_handle: handle to wmi
2196 * @event_id: wmi event id
2197 *
2198 * Return: 0 on success
2199 */
2200int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302201 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302202{
2203 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302204 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302205 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302206
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302207#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302208 if (event_id >= wmi_events_max ||
2209 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2210 qdf_print("%s: Event id %d is unavailable\n",
2211 __func__, event_id);
2212 return QDF_STATUS_E_FAILURE;
2213 }
2214 evt_id = wmi_handle->wmi_events[event_id];
2215#else
2216 evt_id = event_id;
2217#endif
2218
2219 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302220 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302221 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2222 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302223 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302224 }
2225 wmi_handle->event_handler[idx] = NULL;
2226 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302227 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302228 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302229 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302230 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302231 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302232
2233 return 0;
2234}
2235
2236/**
Govind Singhd52faac2016-03-09 12:03:29 +05302237 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302238 * @wmi_handle: handle to wmi
2239 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302240 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05302241 *
Govind Singhd52faac2016-03-09 12:03:29 +05302242 * Event process by below function will be in default caller context.
2243 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05302244 *
2245 * Return: none
2246 */
Govind Singhd52faac2016-03-09 12:03:29 +05302247static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
2248 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302249{
2250 wmi_buf_t evt_buf;
2251 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
2252
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302253#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302254 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
2255 (wmi_handle->scn_handle, evt_buf, exec_ctx);
2256#else
Govind Singh5eb51532016-03-09 11:34:12 +05302257 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05302258 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302259#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302260
Govind Singh6b411b52016-03-06 19:55:02 +05302261 return;
2262}
2263
2264/**
2265 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
2266 * @wmi_handle: handle to wmi
2267 * @htc_packet: pointer to htc packet
2268 *
2269 * Event process by below function will be in worker thread context.
2270 * Use this method for events which are not critical and not
2271 * handled in protocol stack.
2272 *
2273 * Return: none
2274 */
2275static void wmi_process_fw_event_worker_thread_ctx
2276 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
2277{
2278 wmi_buf_t evt_buf;
2279 uint32_t id;
2280 uint8_t *data;
2281
2282 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302283 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
2284 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302285
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302286#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302287 if (wmi_handle->log_info.wmi_logging_enable) {
2288 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2289 /* Exclude 4 bytes of TLV header */
2290 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2291 wmi_handle->log_info.buf_offset_event));
2292 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2293 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302294#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302295 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2296 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
2297 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002298 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
2299 &wmi_handle->rx_event_work);
2300
Govind Singh6b411b52016-03-06 19:55:02 +05302301 return;
2302}
2303
2304/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302305 * wmi_get_pdev_ep: Get wmi handle based on endpoint
2306 * @soc: handle to wmi soc
2307 * @ep: endpoint id
2308 *
2309 * Return: none
2310 */
2311static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
2312 HTC_ENDPOINT_ID ep)
2313{
2314 uint32_t i;
2315
2316 for (i = 0; i < WMI_MAX_RADIOS; i++)
2317 if (soc->wmi_endpoint_id[i] == ep)
2318 break;
2319
2320 if (i == WMI_MAX_RADIOS)
2321 return NULL;
2322
2323 return soc->wmi_pdev[i];
2324}
2325
2326/**
Govind Singhd52faac2016-03-09 12:03:29 +05302327 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302328 * @ctx: handle to wmi
2329 * @htc_packet: pointer to htc packet
2330 *
Govind Singh6b411b52016-03-06 19:55:02 +05302331 * Return: none
2332 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002333static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05302334{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302335 struct wmi_soc *soc = (struct wmi_soc *) ctx;
2336 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302337 wmi_buf_t evt_buf;
2338 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302339 uint32_t idx = 0;
2340 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302341
2342 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302343
2344 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
2345 if (wmi_handle == NULL) {
2346 qdf_print
2347 ("%s :unable to get wmi_handle to Endpoint %d\n",
2348 __func__, htc_packet->Endpoint);
2349 qdf_nbuf_free(evt_buf);
2350 return;
2351 }
2352
Govind Singhb53420c2016-03-09 14:32:57 +05302353 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302354 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302355 if (qdf_unlikely(idx == A_ERROR)) {
2356 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05302357 ("%s :event handler is not registered: event id 0x%x\n",
2358 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302359 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302360 return;
2361 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302362 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302363 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302364 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302365
2366 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302367 wmi_process_fw_event_worker_thread_ctx
2368 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302369 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2370 wmi_process_fw_event_default_ctx
2371 (wmi_handle, htc_packet, exec_ctx);
2372 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05302373 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
2374 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302375 }
Govind Singhd52faac2016-03-09 12:03:29 +05302376
Govind Singh6b411b52016-03-06 19:55:02 +05302377}
2378
2379/**
2380 * wmi_process_fw_event() - process any fw event
2381 * @wmi_handle: wmi handle
2382 * @evt_buf: fw event buffer
2383 *
Govind Singhd52faac2016-03-09 12:03:29 +05302384 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302385 *
2386 * Return: none
2387 */
2388void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2389{
2390 __wmi_control_rx(wmi_handle, evt_buf);
2391}
2392
2393/**
2394 * __wmi_control_rx() - process serialize wmi event callback
2395 * @wmi_handle: wmi handle
2396 * @evt_buf: fw event buffer
2397 *
2398 * Return: none
2399 */
2400void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2401{
2402 uint32_t id;
2403 uint8_t *data;
2404 uint32_t len;
2405 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302406#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302407 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302408#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302409 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302410
Govind Singhb53420c2016-03-09 14:32:57 +05302411 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302412
Govind Singhb53420c2016-03-09 14:32:57 +05302413 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302414 goto end;
2415
Govind Singhb53420c2016-03-09 14:32:57 +05302416 data = qdf_nbuf_data(evt_buf);
2417 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302418
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302419#ifndef WMI_NON_TLV_SUPPORT
2420 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2421 /* Validate and pad(if necessary) the TLVs */
2422 tlv_ok_status =
2423 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302424 data, len, id,
2425 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302426 if (tlv_ok_status != 0) {
2427 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2428 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2429 __func__, id, tlv_ok_status);
2430 goto end;
2431 }
Govind Singh6b411b52016-03-06 19:55:02 +05302432 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302433#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302434
Govind Singhd52faac2016-03-09 12:03:29 +05302435 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2436 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302437 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302438 "%s : event handler is not registered: event id 0x%x\n",
2439 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302440 goto end;
2441 }
Govind Singhd52faac2016-03-09 12:03:29 +05302442#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302443 if (wmi_handle->log_info.wmi_logging_enable) {
2444 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2445 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302446 if (wmi_handle->ops->is_management_record(id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302447 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2448 + wmi_handle->log_info.buf_offset_event));
2449 } else {
2450 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2451 wmi_handle->log_info.buf_offset_event));
2452 }
2453 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302454 }
Govind Singhd52faac2016-03-09 12:03:29 +05302455#endif
2456 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302457 if (wmi_handle->target_type == WMI_TLV_TARGET)
2458 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2459 wmi_cmd_struct_ptr, len);
2460 else
2461 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2462 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302463
Govind Singh6b411b52016-03-06 19:55:02 +05302464end:
Govind Singhd52faac2016-03-09 12:03:29 +05302465 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302466#ifndef WMI_NON_TLV_SUPPORT
2467 if (wmi_handle->target_type == WMI_TLV_TARGET)
2468 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2469#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302470
Govind Singhb53420c2016-03-09 14:32:57 +05302471 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302472
Govind Singh6b411b52016-03-06 19:55:02 +05302473}
2474
2475/**
2476 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002477 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05302478 *
2479 * This function process any fw event to serialize it through rx worker thread.
2480 *
2481 * Return: none
2482 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002483static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05302484{
Govind Singh6b411b52016-03-06 19:55:02 +05302485 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002486 struct wmi_unified *wmi = arg;
Govind Singh6b411b52016-03-06 19:55:02 +05302487
Govind Singhb53420c2016-03-09 14:32:57 +05302488 qdf_spin_lock_bh(&wmi->eventq_lock);
2489 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2490 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302491 while (buf) {
2492 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302493 qdf_spin_lock_bh(&wmi->eventq_lock);
2494 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2495 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302496 }
2497}
2498
Govind Singh6b411b52016-03-06 19:55:02 +05302499#ifdef FEATURE_RUNTIME_PM
2500/**
2501 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2502 * @wmi_handle: wmi context
2503 */
Govind Singhd52faac2016-03-09 12:03:29 +05302504static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302505{
Govind Singhb53420c2016-03-09 14:32:57 +05302506 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302507}
Govind Singhd52faac2016-03-09 12:03:29 +05302508
2509/**
2510 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2511 * @wmi_handle: wmi context
2512 * @val: runtime pm progress flag
2513 */
2514void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2515{
Govind Singhb53420c2016-03-09 14:32:57 +05302516 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302517}
2518
2519/**
2520 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2521 * @wmi_handle: wmi context
2522 */
2523inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2524{
Govind Singhb53420c2016-03-09 14:32:57 +05302525 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302526}
Govind Singh6b411b52016-03-06 19:55:02 +05302527#else
Govind Singhd52faac2016-03-09 12:03:29 +05302528static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302529{
2530}
2531#endif
2532
2533/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302534 * wmi_unified_get_soc_handle: Get WMI SoC handle
2535 * @param wmi_handle: WMI context got from wmi_attach
2536 *
2537 * return: Pointer to Soc handle
2538 */
2539void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2540{
2541 return wmi_handle->soc;
2542}
2543
2544/**
2545 * wmi_interface_logging_init: Interface looging init
2546 * @param wmi_handle: Pointer to wmi handle object
2547 *
2548 * return: None
2549 */
2550#ifdef WMI_INTERFACE_EVENT_LOGGING
2551static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2552{
2553 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2554 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2555 wmi_debugfs_init(wmi_handle);
2556 }
2557}
2558#else
2559void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2560{
2561}
2562#endif
2563
2564/**
2565 * wmi_target_params_init: Target specific params init
2566 * @param wmi_soc: Pointer to wmi soc object
2567 * @param wmi_handle: Pointer to wmi handle object
2568 *
2569 * return: None
2570 */
2571#ifndef CONFIG_MCL
2572static inline void wmi_target_params_init(struct wmi_soc *soc,
2573 struct wmi_unified *wmi_handle)
2574{
2575 /* WMI service bitmap recieved from target */
2576 wmi_handle->wmi_service_bitmap = soc->wmi_service_bitmap;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302577 wmi_handle->pdev_param = soc->pdev_param;
2578 wmi_handle->vdev_param = soc->vdev_param;
2579 wmi_handle->services = soc->services;
2580}
2581#else
2582static inline void wmi_target_params_init(struct wmi_soc *soc,
2583 struct wmi_unified *wmi_handle)
2584{
2585}
2586#endif
2587
2588/**
2589 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2590 * @param wmi_soc: Pointer to wmi soc object
2591 * @param pdev_idx: pdev index
2592 *
2593 * return: Pointer to wmi handle or NULL on failure
2594 */
2595void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2596{
2597 struct wmi_unified *wmi_handle;
2598
2599 if (pdev_idx >= WMI_MAX_RADIOS)
2600 return NULL;
2601
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302602 if (soc->wmi_pdev[pdev_idx] == NULL) {
2603 wmi_handle =
2604 (struct wmi_unified *) qdf_mem_malloc(
2605 sizeof(struct wmi_unified));
2606 if (wmi_handle == NULL) {
2607 qdf_print("allocation of wmi handle failed %zu\n",
2608 sizeof(struct wmi_unified));
2609 return NULL;
2610 }
2611 wmi_handle->scn_handle = soc->scn_handle;
2612 wmi_handle->event_id = soc->event_id;
2613 wmi_handle->event_handler = soc->event_handler;
2614 wmi_handle->ctx = soc->ctx;
2615 wmi_handle->ops = soc->ops;
2616 qdf_spinlock_create(&wmi_handle->eventq_lock);
2617 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302618
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302619 qdf_create_work(0, &wmi_handle->rx_event_work,
2620 wmi_rx_event_work, wmi_handle);
2621 wmi_handle->wmi_rx_work_queue =
2622 qdf_create_workqueue("wmi_rx_event_work_queue");
2623 if (NULL == wmi_handle->wmi_rx_work_queue) {
2624 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2625 goto error;
2626 }
2627 wmi_handle->wmi_events = soc->wmi_events;
2628 wmi_target_params_init(soc, wmi_handle);
2629 wmi_interface_logging_init(wmi_handle);
2630 qdf_atomic_init(&wmi_handle->pending_cmds);
2631 qdf_atomic_init(&wmi_handle->is_target_suspended);
2632 wmi_handle->target_type = soc->target_type;
2633 wmi_handle->soc = soc;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002634
Kiran Venkatappaea88a4e2017-06-15 17:27:38 +05302635 soc->wmi_pdev[pdev_idx] = wmi_handle;
2636 } else
2637 wmi_handle = soc->wmi_pdev[pdev_idx];
2638
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302639 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302640 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2641 wmi_handle->htc_handle = soc->htc_handle;
2642 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302643
2644 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002645
2646error:
2647 qdf_mem_free(wmi_handle);
2648
2649 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302650}
2651
2652/**
Govind Singh6b411b52016-03-06 19:55:02 +05302653 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302654 * @scn_handle: handle to SCN
2655 * @osdev: OS device context
2656 * @target_type: TLV or not-TLV based target
2657 * @use_cookie: cookie based allocation enabled/disabled
2658 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302659 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302660 *
2661 * @Return: wmi handle.
2662 */
Govind Singhc458f382016-02-04 18:42:30 +05302663void *wmi_unified_attach(void *scn_handle,
2664 osdev_t osdev, enum wmi_target_type target_type,
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302665 bool use_cookie, struct wmi_rx_ops *rx_ops,
2666 struct wlan_objmgr_psoc *psoc)
Govind Singh6b411b52016-03-06 19:55:02 +05302667{
2668 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302669 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302670
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302671 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2672 if (soc == NULL) {
2673 qdf_print("Allocation of wmi_soc failed %zu\n",
2674 sizeof(struct wmi_soc));
2675 return NULL;
2676 }
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302677#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05302678 wmi_handle =
2679 (struct wmi_unified *)os_malloc(NULL,
2680 sizeof(struct wmi_unified),
2681 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302682#else
2683 wmi_handle =
2684 (struct wmi_unified *) qdf_mem_malloc(
2685 sizeof(struct wmi_unified));
2686#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302687 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302688 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302689 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302690 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302691 return NULL;
2692 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302693 wmi_handle->soc = soc;
2694 wmi_handle->event_id = soc->event_id;
2695 wmi_handle->event_handler = soc->event_handler;
2696 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302697 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302698 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302699 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302700 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302701 qdf_atomic_init(&wmi_handle->pending_cmds);
2702 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302703 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302704 qdf_spinlock_create(&wmi_handle->eventq_lock);
2705 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002706 qdf_create_work(0, &wmi_handle->rx_event_work,
2707 wmi_rx_event_work, wmi_handle);
2708 wmi_handle->wmi_rx_work_queue =
2709 qdf_create_workqueue("wmi_rx_event_work_queue");
2710 if (NULL == wmi_handle->wmi_rx_work_queue) {
2711 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2712 goto error;
2713 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302714 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302715 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302716 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2717 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302718 wmi_handle->target_type = target_type;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302719 soc->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302720 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302721 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302722 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302723 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302724 /* Assign target cookie capablity */
2725 wmi_handle->use_cookie = use_cookie;
2726 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302727 wmi_handle->wmi_stopinprogress = 0;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302728 /* Increase the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302729 soc->wmi_psoc = psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302730 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302731
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302732 soc->ops = wmi_handle->ops;
2733 soc->wmi_pdev[0] = wmi_handle;
2734
Govind Singh6b411b52016-03-06 19:55:02 +05302735 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002736
2737error:
2738 qdf_mem_free(soc);
2739 qdf_mem_free(wmi_handle);
2740
2741 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302742}
2743
2744/**
2745 * wmi_unified_detach() - detach for unified WMI
2746 *
2747 * @wmi_handle : handle to wmi.
2748 *
2749 * @Return: none.
2750 */
2751void wmi_unified_detach(struct wmi_unified *wmi_handle)
2752{
2753 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302754 struct wmi_soc *soc;
2755 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302756
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302757 soc = wmi_handle->soc;
2758 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2759 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002760 qdf_flush_workqueue(0,
2761 soc->wmi_pdev[i]->wmi_rx_work_queue);
2762 qdf_destroy_workqueue(0,
2763 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302764 wmi_debugfs_remove(soc->wmi_pdev[i]);
2765 buf = qdf_nbuf_queue_remove(
2766 &soc->wmi_pdev[i]->event_queue);
2767 while (buf) {
2768 qdf_nbuf_free(buf);
2769 buf = qdf_nbuf_queue_remove(
2770 &soc->wmi_pdev[i]->event_queue);
2771 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002772
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302773 wmi_log_buffer_free(soc->wmi_pdev[i]);
Wu Gao21e69382017-06-23 16:39:17 +08002774
2775 /* Free events logs list */
2776 if (soc->wmi_pdev[i]->events_logs_list)
2777 qdf_mem_free(
2778 soc->wmi_pdev[i]->events_logs_list);
2779
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302780 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302781 qdf_mem_free(soc->wmi_pdev[i]);
2782 }
Govind Singh6b411b52016-03-06 19:55:02 +05302783 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302784 qdf_spinlock_destroy(&soc->ctx_lock);
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302785 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302786 soc->wmi_psoc = NULL;
2787 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302788}
2789
2790/**
2791 * wmi_unified_remove_work() - detach for WMI work
2792 * @wmi_handle: handle to WMI
2793 *
2794 * A function that does not fully detach WMI, but just remove work
2795 * queue items associated with it. This is used to make sure that
2796 * before any other processing code that may destroy related contexts
2797 * (HTC, etc), work queue processing on WMI has already been stopped.
2798 *
2799 * Return: None
2800 */
2801void
2802wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2803{
2804 wmi_buf_t buf;
2805
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002806 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302807 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2808 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302809 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302810 qdf_nbuf_free(buf);
2811 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302812 }
Govind Singhb53420c2016-03-09 14:32:57 +05302813 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302814}
2815
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302816/**
2817 * wmi_htc_tx_complete() - Process htc tx completion
2818 *
2819 * @ctx: handle to wmi
2820 * @htc_packet: pointer to htc packet
2821 *
2822 * @Return: none.
2823 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002824static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302825{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302826 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302827 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302828 u_int8_t *buf_ptr;
2829 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302830 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302831#ifdef WMI_INTERFACE_EVENT_LOGGING
2832 uint32_t cmd_id;
2833#endif
2834
2835 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302836 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2837 if (wmi_handle == NULL) {
2838 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2839 QDF_ASSERT(0);
2840 return;
2841 }
Govind Singh6b411b52016-03-06 19:55:02 +05302842#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302843 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302844 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2845 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302846
Govind Singhecf03cd2016-05-12 12:45:51 +05302847 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302848 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302849 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302850 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302851 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2852 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2853 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302854 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302855 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2856 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2857 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302858 }
2859
Govind Singhecf03cd2016-05-12 12:45:51 +05302860 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2861 }
Govind Singh6b411b52016-03-06 19:55:02 +05302862#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302863 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2864 len = qdf_nbuf_len(wmi_cmd_buf);
2865 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302866 qdf_nbuf_free(wmi_cmd_buf);
2867 qdf_mem_free(htc_pkt);
2868 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302869}
2870
2871/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302872 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302873 *
2874 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302875 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302876 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302877 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302878 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302879static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2880 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302881{
Govind Singh6b411b52016-03-06 19:55:02 +05302882 int status;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302883 uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
2884 WMI_CONTROL_SVC_WMAC2};
Manikandan Mohanf940db82017-04-13 20:19:26 -07002885 struct htc_service_connect_resp response;
2886 struct htc_service_connect_req connect;
Govind Singh6b411b52016-03-06 19:55:02 +05302887
2888 OS_MEMZERO(&connect, sizeof(connect));
2889 OS_MEMZERO(&response, sizeof(response));
2890
2891 /* meta data is unused for now */
2892 connect.pMetaData = NULL;
2893 connect.MetaDataLength = 0;
2894 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302895 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302896 connect.EpCallbacks.EpTxCompleteMultiple =
2897 NULL /* Control path completion ar6000_tx_complete */;
2898 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2899 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2900 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2901 connect.EpCallbacks.EpTxComplete =
2902 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2903
2904 /* connect to control service */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302905 connect.service_id = svc_id[pdev_idx];
2906 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302907 &response);
2908
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302909
Govind Singh6b411b52016-03-06 19:55:02 +05302910 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302911 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302912 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302913 status);
2914 return status;
2915 }
Govind Singh6b411b52016-03-06 19:55:02 +05302916
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302917 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2918 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2919
2920 return 0;
2921}
2922
2923/**
2924 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2925 *
2926 * @wmi_handle: handle to WMI.
2927 *
2928 * @Return: status.
2929 */
2930QDF_STATUS
2931wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2932 void *htc_handle)
2933{
2934 uint32_t i;
2935 uint8_t wmi_ep_count;
2936
2937 wmi_handle->soc->htc_handle = htc_handle;
2938
2939 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2940 if (wmi_ep_count > WMI_MAX_RADIOS)
2941 return QDF_STATUS_E_FAULT;
2942
2943 for (i = 0; i < wmi_ep_count; i++)
2944 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2945
2946 wmi_handle->htc_handle = htc_handle;
2947 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2948 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2949
2950 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302951}
2952
2953/**
2954 * wmi_get_host_credits() - WMI API to get updated host_credits
2955 *
2956 * @wmi_handle: handle to WMI.
2957 *
2958 * @Return: updated host_credits.
2959 */
2960int wmi_get_host_credits(wmi_unified_t wmi_handle)
2961{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302962 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302963
2964 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2965 &host_credits);
2966 return host_credits;
2967}
2968
2969/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302970 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2971 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302972 *
2973 * @wmi_handle: handle to WMI.
2974 *
2975 * @Return: Pending Commands in the HTC queue.
2976 */
2977int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2978{
Govind Singhb53420c2016-03-09 14:32:57 +05302979 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302980}
2981
2982/**
2983 * wmi_set_target_suspend() - WMI API to set target suspend state
2984 *
2985 * @wmi_handle: handle to WMI.
2986 * @val: suspend state boolean.
2987 *
2988 * @Return: none.
2989 */
2990void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2991{
Govind Singhb53420c2016-03-09 14:32:57 +05302992 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302993}
2994
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302995/**
2996 * WMI API to set crash injection state
2997 * @param wmi_handle: handle to WMI.
2998 * @param val: crash injection state boolean.
2999 */
3000void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
3001{
3002 wmi_handle->tag_crash_inject = flag;
3003}
3004
3005/**
3006 * WMI API to set bus suspend state
3007 * @param wmi_handle: handle to WMI.
3008 * @param val: suspend state boolean.
3009 */
3010void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
3011{
3012 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
3013}
3014
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05303015#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05303016/**
3017 * API to flush all the previous packets associated with the wmi endpoint
3018 *
3019 * @param wmi_handle : handle to WMI.
3020 */
3021void
3022wmi_flush_endpoint(wmi_unified_t wmi_handle)
3023{
3024 htc_flush_endpoint(wmi_handle->htc_handle,
3025 wmi_handle->wmi_endpoint_id, 0);
3026}
3027
3028/**
3029 * generic function to block unified WMI command
3030 * @param wmi_handle : handle to WMI.
3031 * @return 0 on success and -ve on failure.
3032 */
3033int
3034wmi_stop(wmi_unified_t wmi_handle)
3035{
3036 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
3037 "WMI Stop\n");
3038 wmi_handle->wmi_stopinprogress = 1;
3039 return 0;
3040}
Kiran Venkatappa1241bb82017-05-10 16:24:51 +05303041
3042/**
3043 * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
3044 * By default pdev_id conversion is not done in WMI.
3045 * This API can be used enable conversion in WMI.
3046 * @param wmi_handle : handle to WMI
3047 * Return none
3048 */
3049void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
3050{
3051 if (wmi_handle->target_type == WMI_TLV_TARGET)
3052 wmi_tlv_pdev_id_conversion_enable(wmi_handle);
3053}
3054
Govind Singhe7d9f3e2016-04-15 13:58:27 +05303055#endif