blob: 7ac4b75b5105cdd294ebd03a27ec3845eb6fdc39 [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 */
31#include "athdefs.h"
32#include "osapi_linux.h"
33#include "a_types.h"
34#include "a_debug.h"
35#include "ol_if_athvar.h"
36#include "ol_defines.h"
Govind Singh6b411b52016-03-06 19:55:02 +053037#include "htc_api.h"
38#include "htc_api.h"
39#include "dbglog_host.h"
Govind Singh6b411b52016-03-06 19:55:02 +053040#include "wmi_unified_priv.h"
Govind Singh5eb51532016-03-09 11:34:12 +053041#include "wmi_unified_param.h"
Govind Singh6b411b52016-03-06 19:55:02 +053042
Kiran Venkatappa23e6e082016-11-11 16:49:40 +053043#ifndef WMI_NON_TLV_SUPPORT
44#include "wmi_tlv_helper.h"
45#endif
46
Govind Singhecf03cd2016-05-12 12:45:51 +053047#include <linux/debugfs.h>
48
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +053049/* This check for CONFIG_WIN temporary added due to redeclaration compilation
50error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
51which gets included here through ol_if_athvar.h. Eventually it is expected that
52wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
53WMI_CMD_HDR to be defined here. */
54#ifdef CONFIG_WIN
55/* Copied from wmi.h */
56#undef MS
57#define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
58#undef SM
59#define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
60#undef WO
61#define WO(_f) ((_f##_OFFSET) >> 2)
62
63#undef GET_FIELD
64#define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
65#undef SET_FIELD
66#define SET_FIELD(_addr, _f, _val) \
67 (*((A_UINT32 *)(_addr) + WO(_f)) = \
68 (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
69
70#define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
71 GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
72
73#define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
74 SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
75
76#define WMI_EP_APASS 0x0
77#define WMI_EP_LPASS 0x1
78#define WMI_EP_SENSOR 0x2
79
80/*
81 * * Control Path
82 * */
83typedef PREPACK struct {
84 A_UINT32 commandId:24,
85 reserved:2, /* used for WMI endpoint ID */
86 plt_priv:6; /* platform private */
87} POSTPACK WMI_CMD_HDR; /* used for commands and events */
88
89#define WMI_CMD_HDR_COMMANDID_LSB 0
90#define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
91#define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
92#define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
93#define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
94#define WMI_CMD_HDR_PLT_PRIV_LSB 24
95#define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
96#define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
97/* end of copy wmi.h */
98#endif /* CONFIG_WIN */
99
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700100#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
101/* TODO Cleanup this backported function */
Jeff Johnson9366d7a2016-10-07 13:03:02 -0700102static int qcacld_bp_seq_printf(struct seq_file *m, const char *f, ...)
Manikandan Mohan5826ae92016-06-08 16:29:39 -0700103{
104 va_list args;
105
106 va_start(args, f);
107 seq_printf(m, f, args);
108 va_end(args);
109
110 return m->count;
111}
112
113#define seq_printf(m, fmt, ...) qcacld_bp_seq_printf((m), fmt, ##__VA_ARGS__)
114#endif
115
Govind Singh6b411b52016-03-06 19:55:02 +0530116#define WMI_MIN_HEAD_ROOM 64
117
118#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +0530119#ifndef MAX_WMI_INSTANCES
120#ifdef CONFIG_MCL
121#define MAX_WMI_INSTANCES 1
122#else
123#define MAX_WMI_INSTANCES 3
124#endif
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530125#define CUSTOM_MGMT_CMD_DATA_SIZE 4
Govind Singhecf03cd2016-05-12 12:45:51 +0530126#endif
127
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530128#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530129/* WMI commands */
130uint32_t g_wmi_command_buf_idx = 0;
131struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
132
133/* WMI commands TX completed */
134uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
135struct wmi_command_debug
136 wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
137
138/* WMI events when processed */
139uint32_t g_wmi_event_buf_idx = 0;
140struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
141
142/* WMI events when queued */
143uint32_t g_wmi_rx_event_buf_idx = 0;
144struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530145#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530146
Govind Singhecf03cd2016-05-12 12:45:51 +0530147#define WMI_COMMAND_RECORD(h, a, b) { \
148 if (wmi_log_max_entry <= \
149 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
150 *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
151 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
152 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
153 .command = a; \
154 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
155 wmi_command_log_buf_info.buf) \
156 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
157 b, wmi_record_max_length); \
158 ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
159 [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
160 time = qdf_get_log_timestamp(); \
161 (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
162 h->log_info.wmi_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530163}
164
Govind Singhecf03cd2016-05-12 12:45:51 +0530165#define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
166 if (wmi_log_max_entry <= \
167 *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530168 *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
169 p_buf_tail_idx) = 0; \
Govind Singhecf03cd2016-05-12 12:45:51 +0530170 ((struct wmi_command_debug *)h->log_info. \
171 wmi_command_tx_cmp_log_buf_info.buf) \
172 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
173 p_buf_tail_idx)]. \
174 command = a; \
175 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
176 wmi_command_tx_cmp_log_buf_info.buf) \
177 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
178 p_buf_tail_idx)]. \
179 data, b, wmi_record_max_length); \
180 ((struct wmi_command_debug *)h->log_info. \
181 wmi_command_tx_cmp_log_buf_info.buf) \
182 [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
183 p_buf_tail_idx)]. \
184 time = qdf_get_log_timestamp(); \
185 (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
186 h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530187}
188
Govind Singhecf03cd2016-05-12 12:45:51 +0530189#define WMI_EVENT_RECORD(h, a, b) { \
190 if (wmi_log_max_entry <= \
191 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
192 *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
193 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
194 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
195 event = a; \
196 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
197 wmi_event_log_buf_info.buf) \
198 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
199 wmi_record_max_length); \
200 ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
201 [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
Govind Singhb53420c2016-03-09 14:32:57 +0530202 qdf_get_log_timestamp(); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530203 (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
204 h->log_info.wmi_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530205}
206
Govind Singhecf03cd2016-05-12 12:45:51 +0530207#define WMI_RX_EVENT_RECORD(h, a, b) { \
208 if (wmi_log_max_entry <= \
209 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
210 *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
211 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
212 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
213 event = a; \
214 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
215 wmi_rx_event_log_buf_info.buf) \
216 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
217 data, b, wmi_record_max_length); \
218 ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
219 [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
220 time = qdf_get_log_timestamp(); \
221 (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
222 h->log_info.wmi_rx_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530223}
Govind Singh6b411b52016-03-06 19:55:02 +0530224
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530225#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +0530226uint32_t g_wmi_mgmt_command_buf_idx = 0;
227struct
228wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
229
230/* wmi_mgmt commands TX completed */
231uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
232struct wmi_command_debug
233wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
234
235/* wmi_mgmt events when processed */
236uint32_t g_wmi_mgmt_event_buf_idx = 0;
237struct wmi_event_debug
238wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530239#endif
Govind Singh6b411b52016-03-06 19:55:02 +0530240
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530241#define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
242 if (wmi_mgmt_log_max_entry <= \
243 *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
244 *(h->log_info.wmi_mgmt_command_log_buf_info. \
245 p_buf_tail_idx) = 0; \
246 ((struct wmi_command_debug *)h->log_info. \
247 wmi_mgmt_command_log_buf_info.buf) \
248 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
249 command = a; \
250 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
251 wmi_mgmt_command_log_buf_info.buf) \
252 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
253 data, b, \
254 wmi_record_max_length); \
255 ((struct wmi_command_debug *)h->log_info. \
256 wmi_mgmt_command_log_buf_info.buf) \
257 [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
258 time = qdf_get_log_timestamp(); \
259 (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
260 h->log_info.wmi_mgmt_command_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530261}
262
Govind Singhecf03cd2016-05-12 12:45:51 +0530263#define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
264 if (wmi_mgmt_log_max_entry <= \
265 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
266 p_buf_tail_idx)) \
267 *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
268 p_buf_tail_idx) = 0; \
269 ((struct wmi_command_debug *)h->log_info. \
270 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
271 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
272 p_buf_tail_idx)].command = a; \
273 qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
274 wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
275 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
276 p_buf_tail_idx)].data, b, \
277 wmi_record_max_length); \
278 ((struct wmi_command_debug *)h->log_info. \
279 wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
280 [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
281 p_buf_tail_idx)].time = \
282 qdf_get_log_timestamp(); \
283 (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
284 p_buf_tail_idx))++; \
285 h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530286}
287
Govind Singhecf03cd2016-05-12 12:45:51 +0530288#define WMI_MGMT_EVENT_RECORD(h, a, b) { \
289 if (wmi_mgmt_log_max_entry <= \
290 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
291 *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
292 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
293 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
294 .event = a; \
295 qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
296 wmi_mgmt_event_log_buf_info.buf) \
297 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
298 data, b, wmi_record_max_length); \
299 ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
300 [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
301 time = qdf_get_log_timestamp(); \
302 (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
303 h->log_info.wmi_mgmt_event_log_buf_info.length++; \
Govind Singh6b411b52016-03-06 19:55:02 +0530304}
305
Govind Singhecf03cd2016-05-12 12:45:51 +0530306/* These are defined to made it as module param, which can be configured */
307uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
308uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
309uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
310uint32_t wmi_display_size = 100;
311
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +0530312static uint8_t *wmi_id_to_name(uint32_t wmi_command);
Govind Singhecf03cd2016-05-12 12:45:51 +0530313
314/**
315 * wmi_log_init() - Initialize WMI event logging
316 * @wmi_handle: WMI handle.
317 *
318 * Return: Initialization status
319 */
320#ifdef CONFIG_MCL
321static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
322{
323 struct wmi_log_buf_t *cmd_log_buf =
324 &wmi_handle->log_info.wmi_command_log_buf_info;
325 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
326 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
327
328 struct wmi_log_buf_t *event_log_buf =
329 &wmi_handle->log_info.wmi_event_log_buf_info;
330 struct wmi_log_buf_t *rx_event_log_buf =
331 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
332
333 struct wmi_log_buf_t *mgmt_cmd_log_buf =
334 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
335 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
336 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
337 struct wmi_log_buf_t *mgmt_event_log_buf =
338 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
339
340 /* WMI commands */
341 cmd_log_buf->length = 0;
342 cmd_log_buf->buf_tail_idx = 0;
343 cmd_log_buf->buf = wmi_command_log_buffer;
344 cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700345 cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530346
347 /* WMI commands TX completed */
348 cmd_tx_cmpl_log_buf->length = 0;
349 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
350 cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
351 cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700352 cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530353
354 /* WMI events when processed */
355 event_log_buf->length = 0;
356 event_log_buf->buf_tail_idx = 0;
357 event_log_buf->buf = wmi_event_log_buffer;
358 event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700359 event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530360
361 /* WMI events when queued */
362 rx_event_log_buf->length = 0;
363 rx_event_log_buf->buf_tail_idx = 0;
364 rx_event_log_buf->buf = wmi_rx_event_log_buffer;
365 rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700366 rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530367
368 /* WMI Management commands */
369 mgmt_cmd_log_buf->length = 0;
370 mgmt_cmd_log_buf->buf_tail_idx = 0;
371 mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
372 mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700373 mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530374
375 /* WMI Management commands Tx completed*/
376 mgmt_cmd_tx_cmp_log_buf->length = 0;
377 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
378 mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
379 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
380 &g_wmi_mgmt_command_tx_cmp_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700381 mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530382
383 /* WMI Management events when processed*/
384 mgmt_event_log_buf->length = 0;
385 mgmt_event_log_buf->buf_tail_idx = 0;
386 mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
387 mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700388 mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
Govind Singhecf03cd2016-05-12 12:45:51 +0530389
390 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
391 wmi_handle->log_info.wmi_logging_enable = 1;
392
393 return QDF_STATUS_SUCCESS;
394}
395#else
396static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
397{
398 struct wmi_log_buf_t *cmd_log_buf =
399 &wmi_handle->log_info.wmi_command_log_buf_info;
400 struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
401 &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
402
403 struct wmi_log_buf_t *event_log_buf =
404 &wmi_handle->log_info.wmi_event_log_buf_info;
405 struct wmi_log_buf_t *rx_event_log_buf =
406 &wmi_handle->log_info.wmi_rx_event_log_buf_info;
407
408 struct wmi_log_buf_t *mgmt_cmd_log_buf =
409 &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
410 struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
411 &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
412 struct wmi_log_buf_t *mgmt_event_log_buf =
413 &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
414
415 wmi_handle->log_info.wmi_logging_enable = 0;
416
417 /* WMI commands */
418 cmd_log_buf->length = 0;
419 cmd_log_buf->buf_tail_idx = 0;
420 cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
421 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700422 cmd_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530423
424 if (!cmd_log_buf->buf) {
425 qdf_print("no memory for WMI command log buffer..\n");
426 return QDF_STATUS_E_NOMEM;
427 }
428 cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
429
430 /* WMI commands TX completed */
431 cmd_tx_cmpl_log_buf->length = 0;
432 cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
433 cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
434 wmi_log_max_entry * sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700435 cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530436
437 if (!cmd_tx_cmpl_log_buf->buf) {
438 qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
439 return QDF_STATUS_E_NOMEM;
440 }
441 cmd_tx_cmpl_log_buf->p_buf_tail_idx =
442 &cmd_tx_cmpl_log_buf->buf_tail_idx;
443
444 /* WMI events when processed */
445 event_log_buf->length = 0;
446 event_log_buf->buf_tail_idx = 0;
447 event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
448 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700449 event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530450
451 if (!event_log_buf->buf) {
452 qdf_print("no memory for WMI Event log buffer..\n");
453 return QDF_STATUS_E_NOMEM;
454 }
455 event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
456
457 /* WMI events when queued */
458 rx_event_log_buf->length = 0;
459 rx_event_log_buf->buf_tail_idx = 0;
460 rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
461 wmi_log_max_entry * sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700462 rx_event_log_buf->size = wmi_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530463
464 if (!rx_event_log_buf->buf) {
465 qdf_print("no memory for WMI Event Rx log buffer..\n");
466 return QDF_STATUS_E_NOMEM;
467 }
468 rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
469
470 /* WMI Management commands */
471 mgmt_cmd_log_buf->length = 0;
472 mgmt_cmd_log_buf->buf_tail_idx = 0;
473 mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700474 wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
475 mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530476
477 if (!mgmt_cmd_log_buf->buf) {
478 qdf_print("no memory for WMI Management Command log buffer..\n");
479 return QDF_STATUS_E_NOMEM;
480 }
481 mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
482
483 /* WMI Management commands Tx completed*/
484 mgmt_cmd_tx_cmp_log_buf->length = 0;
485 mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
486 mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
487 qdf_mem_malloc(
488 wmi_mgmt_log_max_entry *
489 sizeof(struct wmi_command_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700490 mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530491
492 if (!mgmt_cmd_tx_cmp_log_buf->buf) {
493 qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
494 return QDF_STATUS_E_NOMEM;
495 }
496 mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
497 &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
498
499 /* WMI Management events when processed*/
500 mgmt_event_log_buf->length = 0;
501 mgmt_event_log_buf->buf_tail_idx = 0;
502
503 mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
504 wmi_mgmt_log_max_entry *
505 sizeof(struct wmi_event_debug));
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700506 mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
Govind Singhecf03cd2016-05-12 12:45:51 +0530507
508 if (!mgmt_event_log_buf->buf) {
509 qdf_print("no memory for WMI Management Event log buffer..\n");
510 return QDF_STATUS_E_NOMEM;
511 }
512 mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
513
514 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
515 wmi_handle->log_info.wmi_logging_enable = 1;
516
517 return QDF_STATUS_SUCCESS;
518}
519#endif
520
521/**
522 * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
523 * event logging
524 * @wmi_handle: WMI handle.
525 *
526 * Return: None
527 */
528#ifndef CONFIG_MCL
529static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
530{
531 if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
532 qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
533 if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
534 qdf_mem_free(
535 wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
536 if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
537 qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
538 if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
539 qdf_mem_free(
540 wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
541 if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
542 qdf_mem_free(
543 wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
544 if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
545 qdf_mem_free(
546 wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
547 if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
548 qdf_mem_free(
549 wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
550 wmi_handle->log_info.wmi_logging_enable = 0;
551 qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
552}
553#else
554static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
555{
556 /* Do Nothing */
557}
558#endif
559
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700560/**
561 * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
562 * @log_buffer: the command log buffer metadata of the buffer to print
563 * @count: the maximum number of entries to print
564 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
565 * @print_priv: any data required by the print method, e.g. a file handle
566 *
567 * Return: None
568 */
569static void
570wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
571 qdf_abstract_print *print, void *print_priv)
572{
573 static const int data_len =
574 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
575 char str[128];
576 uint32_t idx;
577
578 if (count > log_buffer->size)
579 count = log_buffer->size;
580 if (count > log_buffer->length)
581 count = log_buffer->length;
582
583 /* subtract count from index, and wrap if necessary */
584 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
585 idx %= log_buffer->size;
586
587 print(print_priv, "Time (seconds) Cmd Id Payload");
588 while (count) {
589 struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
590 &((struct wmi_command_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700591 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700592 int len = 0;
593 int i;
594
Dustin Brown8ea39122017-04-10 13:26:56 -0700595 qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700596 len += scnprintf(str + len, sizeof(str) - len,
597 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700598 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700599 cmd_log->command, cmd_log->command);
600 for (i = 0; i < data_len; ++i) {
601 len += scnprintf(str + len, sizeof(str) - len,
602 "0x%08x ", cmd_log->data[i]);
603 }
604
605 print(print_priv, str);
606
607 --count;
608 ++idx;
609 if (idx >= log_buffer->size)
610 idx = 0;
611 }
612}
613
614/**
615 * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
616 * @log_buffer: the event log buffer metadata of the buffer to print
617 * @count: the maximum number of entries to print
618 * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
619 * @print_priv: any data required by the print method, e.g. a file handle
620 *
621 * Return: None
622 */
623static void
624wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
625 qdf_abstract_print *print, void *print_priv)
626{
627 static const int data_len =
628 WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
629 char str[128];
630 uint32_t idx;
631
632 if (count > log_buffer->size)
633 count = log_buffer->size;
634 if (count > log_buffer->length)
635 count = log_buffer->length;
636
637 /* subtract count from index, and wrap if necessary */
638 idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
639 idx %= log_buffer->size;
640
641 print(print_priv, "Time (seconds) Event Id Payload");
642 while (count) {
643 struct wmi_event_debug *event_log = (struct wmi_event_debug *)
644 &((struct wmi_event_debug *)log_buffer->buf)[idx];
Dustin Brown8ea39122017-04-10 13:26:56 -0700645 uint64_t secs, usecs;
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700646 int len = 0;
647 int i;
648
Dustin Brown8ea39122017-04-10 13:26:56 -0700649 qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700650 len += scnprintf(str + len, sizeof(str) - len,
651 "% 8lld.%06lld %6u (0x%06x) ",
Dustin Brown8ea39122017-04-10 13:26:56 -0700652 secs, usecs,
Dustin Brownf24bf9b2017-04-03 17:00:07 -0700653 event_log->event, event_log->event);
654 for (i = 0; i < data_len; ++i) {
655 len += scnprintf(str + len, sizeof(str) - len,
656 "0x%08x ", event_log->data[i]);
657 }
658
659 print(print_priv, str);
660
661 --count;
662 ++idx;
663 if (idx >= log_buffer->size)
664 idx = 0;
665 }
666}
667
668inline void
669wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
670 qdf_abstract_print *print, void *print_priv)
671{
672 wmi_print_cmd_log_buffer(
673 &wmi->log_info.wmi_command_log_buf_info,
674 count, print, print_priv);
675}
676
677inline void
678wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
679 qdf_abstract_print *print, void *print_priv)
680{
681 wmi_print_cmd_log_buffer(
682 &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
683 count, print, print_priv);
684}
685
686inline void
687wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
688 qdf_abstract_print *print, void *print_priv)
689{
690 wmi_print_cmd_log_buffer(
691 &wmi->log_info.wmi_mgmt_command_log_buf_info,
692 count, print, print_priv);
693}
694
695inline void
696wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
697 qdf_abstract_print *print, void *print_priv)
698{
699 wmi_print_cmd_log_buffer(
700 &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
701 count, print, print_priv);
702}
703
704inline void
705wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
706 qdf_abstract_print *print, void *print_priv)
707{
708 wmi_print_event_log_buffer(
709 &wmi->log_info.wmi_event_log_buf_info,
710 count, print, print_priv);
711}
712
713inline void
714wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
715 qdf_abstract_print *print, void *print_priv)
716{
717 wmi_print_event_log_buffer(
718 &wmi->log_info.wmi_rx_event_log_buf_info,
719 count, print, print_priv);
720}
721
722inline void
723wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
724 qdf_abstract_print *print, void *print_priv)
725{
726 wmi_print_event_log_buffer(
727 &wmi->log_info.wmi_mgmt_event_log_buf_info,
728 count, print, print_priv);
729}
730
Govind Singhecf03cd2016-05-12 12:45:51 +0530731#ifdef CONFIG_MCL
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530732const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530733#else
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530734const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
Govind Singhecf03cd2016-05-12 12:45:51 +0530735#endif
736
737/* debugfs routines*/
738
739/**
740 * debug_wmi_##func_base##_show() - debugfs functions to display content of
741 * command and event buffers. Macro uses max buffer length to display
742 * buffer when it is wraparound.
743 *
744 * @m: debugfs handler to access wmi_handle
745 * @v: Variable arguments (not used)
746 *
747 * Return: Length of characters printed
748 */
749#define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
750 static int debug_wmi_##func_base##_show(struct seq_file *m, \
751 void *v) \
752 { \
753 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
754 struct wmi_log_buf_t *wmi_log = \
755 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
756 int pos, nread, outlen; \
757 int i; \
758 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530759 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
760 if (!wmi_log->length) { \
761 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Govind Singhecf03cd2016-05-12 12:45:51 +0530762 return seq_printf(m, \
763 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530764 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530765 \
766 if (wmi_log->length <= wmi_ring_size) \
767 nread = wmi_log->length; \
768 else \
769 nread = wmi_ring_size; \
770 \
771 if (*(wmi_log->p_buf_tail_idx) == 0) \
772 /* tail can be 0 after wrap-around */ \
773 pos = wmi_ring_size - 1; \
774 else \
775 pos = *(wmi_log->p_buf_tail_idx) - 1; \
776 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530777 outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
778 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530779 while (nread--) { \
780 struct wmi_command_debug *wmi_record; \
781 \
782 wmi_record = (struct wmi_command_debug *) \
783 &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
784 outlen += seq_printf(m, "CMD ID = %x\n", \
785 (wmi_record->command)); \
786 outlen += seq_printf(m, "CMD = "); \
787 for (i = 0; i < (wmi_record_max_length/ \
788 sizeof(uint32_t)); i++) \
789 outlen += seq_printf(m, "%x ", \
790 wmi_record->data[i]); \
791 outlen += seq_printf(m, "\n"); \
792 \
793 if (pos == 0) \
794 pos = wmi_ring_size - 1; \
795 else \
796 pos--; \
797 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530798 \
799 return outlen; \
800 } \
801
802#define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
803 static int debug_wmi_##func_base##_show(struct seq_file *m, \
804 void *v) \
805 { \
806 wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
807 struct wmi_log_buf_t *wmi_log = \
808 &wmi_handle->log_info.wmi_##func_base##_buf_info;\
809 int pos, nread, outlen; \
810 int i; \
811 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530812 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
813 if (!wmi_log->length) { \
814 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
Govind Singhecf03cd2016-05-12 12:45:51 +0530815 return seq_printf(m, \
816 "no elements to read from ring buffer!\n"); \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530817 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530818 \
819 if (wmi_log->length <= wmi_ring_size) \
820 nread = wmi_log->length; \
821 else \
822 nread = wmi_ring_size; \
823 \
824 if (*(wmi_log->p_buf_tail_idx) == 0) \
825 /* tail can be 0 after wrap-around */ \
826 pos = wmi_ring_size - 1; \
827 else \
828 pos = *(wmi_log->p_buf_tail_idx) - 1; \
829 \
Pratik Gandhi29e33f02016-09-16 01:32:51 +0530830 outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
831 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
Govind Singhecf03cd2016-05-12 12:45:51 +0530832 while (nread--) { \
833 struct wmi_event_debug *wmi_record; \
834 \
835 wmi_record = (struct wmi_event_debug *) \
836 &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
837 outlen += seq_printf(m, "Event ID = %x\n", \
838 (wmi_record->event)); \
839 outlen += seq_printf(m, "CMD = "); \
840 for (i = 0; i < (wmi_record_max_length/ \
841 sizeof(uint32_t)); i++) \
842 outlen += seq_printf(m, "%x ", \
843 wmi_record->data[i]); \
844 outlen += seq_printf(m, "\n"); \
845 \
846 if (pos == 0) \
847 pos = wmi_ring_size - 1; \
848 else \
849 pos--; \
850 } \
Govind Singhecf03cd2016-05-12 12:45:51 +0530851 \
852 return outlen; \
853 }
854
855GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
856GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
857GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
858GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
859GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
860GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
861 wmi_display_size);
862GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
863
864/**
865 * debug_wmi_enable_show() - debugfs functions to display enable state of
866 * wmi logging feature.
867 *
868 * @m: debugfs handler to access wmi_handle
869 * @v: Variable arguments (not used)
870 *
871 * Return: always 1
872 */
873static int debug_wmi_enable_show(struct seq_file *m, void *v)
874{
875 wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
876
877 return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
878
879}
880
881/**
882 * debug_wmi_log_size_show() - debugfs functions to display configured size of
883 * wmi logging command/event buffer and management command/event buffer.
884 *
885 * @m: debugfs handler to access wmi_handle
886 * @v: Variable arguments (not used)
887 *
888 * Return: Length of characters printed
889 */
890static int debug_wmi_log_size_show(struct seq_file *m, void *v)
891{
892
893 seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
894 return seq_printf(m, "WMI management command/events log max size:%d\n",
895 wmi_mgmt_log_max_entry);
896}
897
898/**
899 * debug_wmi_##func_base##_write() - debugfs functions to clear
900 * wmi logging command/event buffer and management command/event buffer.
901 *
902 * @file: file handler to access wmi_handle
903 * @buf: received data buffer
904 * @count: length of received buffer
905 * @ppos: Not used
906 *
907 * Return: count
908 */
909#define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
910 static ssize_t debug_wmi_##func_base##_write(struct file *file, \
911 const char __user *buf, \
912 size_t count, loff_t *ppos) \
913 { \
914 int k, ret; \
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530915 wmi_unified_t wmi_handle = \
916 ((struct seq_file *)file->private_data)->private;\
Govind Singhecf03cd2016-05-12 12:45:51 +0530917 struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
918 wmi_##func_base##_buf_info; \
919 \
920 ret = sscanf(buf, "%d", &k); \
921 if ((ret != 1) || (k != 0)) { \
922 qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
923 return -EINVAL; \
924 } \
925 \
926 qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
927 qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
928 sizeof(struct wmi_record_type)); \
929 wmi_log->length = 0; \
930 *(wmi_log->p_buf_tail_idx) = 0; \
931 qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
932 \
933 return count; \
934 }
935
936GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
937 wmi_command_debug);
938GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
939 wmi_command_debug);
940GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
941 wmi_event_debug);
942GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
943 wmi_event_debug);
944GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
945 wmi_command_debug);
946GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
947 wmi_mgmt_log_max_entry, wmi_command_debug);
948GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
949 wmi_event_debug);
950
951/**
952 * debug_wmi_enable_write() - debugfs functions to enable/disable
953 * wmi logging feature.
954 *
955 * @file: file handler to access wmi_handle
956 * @buf: received data buffer
957 * @count: length of received buffer
958 * @ppos: Not used
959 *
960 * Return: count
961 */
962static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
963 size_t count, loff_t *ppos)
964{
Pratik Gandhidad75ff2017-01-16 12:50:27 +0530965 wmi_unified_t wmi_handle =
966 ((struct seq_file *)file->private_data)->private;
Govind Singhecf03cd2016-05-12 12:45:51 +0530967 int k, ret;
968
969 ret = sscanf(buf, "%d", &k);
970 if ((ret != 1) || ((k != 0) && (k != 1)))
971 return -EINVAL;
972
973 wmi_handle->log_info.wmi_logging_enable = k;
974 return count;
975}
976
977/**
978 * debug_wmi_log_size_write() - reserved.
979 *
980 * @file: file handler to access wmi_handle
981 * @buf: received data buffer
982 * @count: length of received buffer
983 * @ppos: Not used
984 *
985 * Return: count
986 */
987static ssize_t debug_wmi_log_size_write(struct file *file,
988 const char __user *buf, size_t count, loff_t *ppos)
989{
990 return -EINVAL;
991}
992
993/* Structure to maintain debug information */
994struct wmi_debugfs_info {
995 const char *name;
996 struct dentry *de[MAX_WMI_INSTANCES];
997 const struct file_operations *ops;
998};
999
1000#define DEBUG_FOO(func_base) { .name = #func_base, \
1001 .ops = &debug_##func_base##_ops }
1002
1003/**
1004 * debug_##func_base##_open() - Open debugfs entry for respective command
1005 * and event buffer.
1006 *
1007 * @inode: node for debug dir entry
1008 * @file: file handler
1009 *
1010 * Return: open status
1011 */
1012#define GENERATE_DEBUG_STRUCTS(func_base) \
1013 static int debug_##func_base##_open(struct inode *inode, \
1014 struct file *file) \
1015 { \
1016 return single_open(file, debug_##func_base##_show, \
1017 inode->i_private); \
1018 } \
1019 \
1020 \
1021 static struct file_operations debug_##func_base##_ops = { \
1022 .open = debug_##func_base##_open, \
1023 .read = seq_read, \
1024 .llseek = seq_lseek, \
1025 .write = debug_##func_base##_write, \
1026 .release = single_release, \
1027 };
1028
1029GENERATE_DEBUG_STRUCTS(wmi_command_log);
1030GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
1031GENERATE_DEBUG_STRUCTS(wmi_event_log);
1032GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
1033GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
1034GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
1035GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
1036GENERATE_DEBUG_STRUCTS(wmi_enable);
1037GENERATE_DEBUG_STRUCTS(wmi_log_size);
1038
1039struct wmi_debugfs_info wmi_debugfs_infos[] = {
1040 DEBUG_FOO(wmi_command_log),
1041 DEBUG_FOO(wmi_command_tx_cmp_log),
1042 DEBUG_FOO(wmi_event_log),
1043 DEBUG_FOO(wmi_rx_event_log),
1044 DEBUG_FOO(wmi_mgmt_command_log),
1045 DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
1046 DEBUG_FOO(wmi_mgmt_event_log),
1047 DEBUG_FOO(wmi_enable),
1048 DEBUG_FOO(wmi_log_size),
1049};
1050
1051#define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
1052 sizeof(wmi_debugfs_infos[0]))
1053
1054/**
1055 * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
1056 *
1057 * @wmi_handle: wmi handle
1058 * @par_entry: debug directory entry
1059 * @id: Index to debug info data array
1060 *
1061 * Return: none
1062 */
1063static void wmi_debugfs_create(wmi_unified_t wmi_handle,
1064 struct dentry *par_entry, int id)
1065{
1066 int i;
1067
1068 if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
1069 goto out;
1070
1071 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1072
1073 wmi_debugfs_infos[i].de[id] = debugfs_create_file(
1074 wmi_debugfs_infos[i].name, 0644, par_entry,
1075 wmi_handle, wmi_debugfs_infos[i].ops);
1076
1077 if (wmi_debugfs_infos[i].de[id] == NULL) {
1078 qdf_print("%s: debug Entry creation failed!\n",
1079 __func__);
1080 goto out;
1081 }
1082 }
1083
1084 return;
1085
1086out:
1087 qdf_print("%s: debug Entry creation failed!\n", __func__);
1088 wmi_log_buffer_free(wmi_handle);
1089 return;
1090}
1091
1092/**
1093 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
Govind Singhecf03cd2016-05-12 12:45:51 +05301094 * @wmi_handle: wmi handle
1095 * @dentry: debugfs directory entry
1096 * @id: Index to debug info data array
1097 *
1098 * Return: none
1099 */
Govind Singh06c18392016-06-10 10:33:19 +05301100static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
Govind Singhecf03cd2016-05-12 12:45:51 +05301101{
1102 int i;
Govind Singh06c18392016-06-10 10:33:19 +05301103 struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
1104 int id = wmi_handle->log_info.wmi_instance_id;
Govind Singhecf03cd2016-05-12 12:45:51 +05301105
1106 if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
1107 for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
1108 if (wmi_debugfs_infos[i].de[id])
1109 wmi_debugfs_infos[i].de[id] = NULL;
1110 }
1111 }
1112
1113 if (dentry)
1114 debugfs_remove_recursive(dentry);
1115}
1116
1117/**
1118 * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
1119 * create debugfs enteries.
1120 *
1121 * @h: wmi handler
1122 *
1123 * Return: init status
1124 */
1125static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
1126{
1127 static int wmi_index;
1128
1129 if (wmi_index < MAX_WMI_INSTANCES)
1130 wmi_handle->log_info.wmi_log_debugfs_dir =
1131 debugfs_create_dir(debugfs_dir[wmi_index], NULL);
1132
1133 if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
1134 qdf_print("error while creating debugfs dir for %s\n",
1135 debugfs_dir[wmi_index]);
1136 return QDF_STATUS_E_FAILURE;
1137 }
1138
1139 wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
1140 wmi_index);
1141 wmi_handle->log_info.wmi_instance_id = wmi_index++;
1142
1143 return QDF_STATUS_SUCCESS;
1144}
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001145
1146/**
1147 * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
1148 *
1149 * @wmi_handle: wmi handle
1150 * @cmd: mgmt command
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001151 * @header: pointer to 802.11 header
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001152 * @vdev_id: vdev id
1153 * @chanfreq: channel frequency
1154 *
1155 * Return: none
1156 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301157void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001158 void *header, uint32_t vdev_id, uint32_t chanfreq)
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001159{
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301160
1161 uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
1162
1163 data[0] = ((struct wmi_command_header *)header)->type;
1164 data[1] = ((struct wmi_command_header *)header)->sub_type;
1165 data[2] = vdev_id;
1166 data[3] = chanfreq;
1167
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001168 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
1169
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301170 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, data);
Sandeep Puligillab74958d2016-06-13 15:42:55 -07001171
1172 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
1173}
Rajeev Kumarae91c402016-05-25 16:07:23 -07001174#else
1175/**
1176 * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
1177 * @wmi_handle: wmi handle
1178 * @dentry: debugfs directory entry
1179 * @id: Index to debug info data array
1180 *
1181 * Return: none
1182 */
Govind Singh06c18392016-06-10 10:33:19 +05301183static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301184void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
Sandeep Puligilla828a45f2016-07-19 13:20:57 -07001185 void *header, uint32_t vdev_id, uint32_t chanfreq) { }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301186static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
Govind Singh6b411b52016-03-06 19:55:02 +05301187#endif /*WMI_INTERFACE_EVENT_LOGGING */
1188
Govind Singh6b411b52016-03-06 19:55:02 +05301189int wmi_get_host_credits(wmi_unified_t wmi_handle);
1190/* WMI buffer APIs */
1191
1192#ifdef MEMORY_DEBUG
1193wmi_buf_t
1194wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
Govind Singhecf03cd2016-05-12 12:45:51 +05301195 uint32_t line_num)
Govind Singh6b411b52016-03-06 19:55:02 +05301196{
1197 wmi_buf_t wmi_buf;
1198
1199 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301200 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301201 return NULL;
1202 }
1203
Govind Singhb53420c2016-03-09 14:32:57 +05301204 wmi_buf = qdf_nbuf_alloc_debug(NULL,
Govind Singhecf03cd2016-05-12 12:45:51 +05301205 roundup(len + WMI_MIN_HEAD_ROOM, 4),
1206 WMI_MIN_HEAD_ROOM, 4, false, file_name,
1207 line_num);
Govind Singh6b411b52016-03-06 19:55:02 +05301208
1209 if (!wmi_buf)
1210 return NULL;
1211
1212 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301213 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301214
1215 /*
1216 * Set the length of the buffer to match the allocation size.
1217 */
Govind Singhb53420c2016-03-09 14:32:57 +05301218 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301219
1220 return wmi_buf;
1221}
1222
1223void wmi_buf_free(wmi_buf_t net_buf)
1224{
Govind Singhb53420c2016-03-09 14:32:57 +05301225 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301226}
1227#else
1228wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
1229{
1230 wmi_buf_t wmi_buf;
1231
1232 if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
Govind Singhb53420c2016-03-09 14:32:57 +05301233 QDF_ASSERT(0);
Govind Singh6b411b52016-03-06 19:55:02 +05301234 return NULL;
1235 }
1236
Govind Singhb53420c2016-03-09 14:32:57 +05301237 wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
Govind Singh6b411b52016-03-06 19:55:02 +05301238 WMI_MIN_HEAD_ROOM, 4, false);
1239 if (!wmi_buf)
1240 return NULL;
1241
1242 /* Clear the wmi buffer */
Govind Singhb53420c2016-03-09 14:32:57 +05301243 OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
Govind Singh6b411b52016-03-06 19:55:02 +05301244
1245 /*
1246 * Set the length of the buffer to match the allocation size.
1247 */
Govind Singhb53420c2016-03-09 14:32:57 +05301248 qdf_nbuf_set_pktlen(wmi_buf, len);
Govind Singh6b411b52016-03-06 19:55:02 +05301249 return wmi_buf;
1250}
1251
1252void wmi_buf_free(wmi_buf_t net_buf)
1253{
Govind Singhb53420c2016-03-09 14:32:57 +05301254 qdf_nbuf_free(net_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301255}
1256#endif
1257
1258/**
1259 * wmi_get_max_msg_len() - get maximum WMI message length
1260 * @wmi_handle: WMI handle.
1261 *
1262 * This function returns the maximum WMI message length
1263 *
1264 * Return: maximum WMI message length
1265 */
1266uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
1267{
1268 return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
1269}
1270
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301271#ifdef CONFIG_MCL
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301272static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singh6b411b52016-03-06 19:55:02 +05301273{
1274 switch (wmi_command) {
1275 /* initialize the wlan sub system */
1276 CASE_RETURN_STRING(WMI_INIT_CMDID);
1277
1278 /* Scan specific commands */
1279
1280 /* start scan request to FW */
1281 CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
1282 /* stop scan request to FW */
1283 CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
1284 /* full list of channels as defined by the regulatory
1285 * that will be used by scanner */
1286 CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
1287 /* overwrite default priority table in scan scheduler */
1288 CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
1289 /* This command to adjust the priority and min.max_rest_time
1290 * of an on ongoing scan request.
1291 */
1292 CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
1293
1294 /* PDEV(physical device) specific commands */
1295 /* set regulatorty ctl id used by FW to determine the exact
1296 * ctl power limits */
1297 CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
1298 /* set channel. mainly used for supporting monitor mode */
1299 CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
1300 /* set pdev specific parameters */
1301 CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
1302 /* enable packet log */
1303 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
1304 /* disable packet log*/
1305 CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
1306 /* set wmm parameters */
1307 CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
1308 /* set HT cap ie that needs to be carried probe requests
1309 * HT/VHT channels */
1310 CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
1311 /* set VHT cap ie that needs to be carried on probe
1312 * requests on VHT channels */
1313 CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
1314
1315 /* Command to send the DSCP-to-TID map to the target */
1316 CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
1317 /* set quiet ie parameters. primarily used in AP mode */
1318 CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
1319 /* Enable/Disable Green AP Power Save */
1320 CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
1321 /* get TPC config for the current operating channel */
1322 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
1323
1324 /* set the base MAC address for the physical device before
1325 * a VDEV is created. For firmware that does not support
1326 * this feature and this command, the pdev MAC address will
1327 * not be changed. */
1328 CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
1329
1330 /* eeprom content dump , the same to bdboard data */
1331 CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
1332
1333 /* VDEV(virtual device) specific commands */
1334 /* vdev create */
1335 CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
1336 /* vdev delete */
1337 CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
1338 /* vdev start request */
1339 CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
1340 /* vdev restart request (RX only, NO TX, used for CAC period)*/
1341 CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
1342 /* vdev up request */
1343 CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
1344 /* vdev stop request */
1345 CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
1346 /* vdev down request */
1347 CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
1348 /* set a vdev param */
1349 CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
1350 /* set a key (used for setting per peer unicast
1351 * and per vdev multicast) */
1352 CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
1353
1354 /* wnm sleep mode command */
1355 CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
1356 CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
1357 CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
1358 CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
1359 CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
1360 CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
1361
1362 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
1363 CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
1364 CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
1365 CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
1366
1367 /* peer specific commands */
1368
1369 /** create a peer */
1370 CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
1371 /** delete a peer */
1372 CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
1373 /** flush specific tid queues of a peer */
1374 CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
1375 /** set a parameter of a peer */
1376 CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
1377 /* set peer to associated state. will cary all parameters
1378 * determined during assocication time */
1379 CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
1380 /* add a wds (4 address ) entry. used only for testing
1381 * WDS feature on AP products */
1382 CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
1383 /* remove wds (4 address ) entry. used only for testing WDS
1384 * feature on AP products */
1385 CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
1386 /* set up mcast info for multicast to unicast conversion */
1387 CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
1388 /* request peer info from FW to get PEER_INFO_EVENTID */
1389 CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
1390
1391 /* beacon/management specific commands */
1392
1393 /* transmit beacon by reference. used for transmitting beacon
1394 * on low latency interface like pcie */
1395 CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
1396 /* transmit beacon by value */
1397 CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
1398 /* set the beacon template. used in beacon offload mode to setup
1399 * the common beacon template with the FW to be used by FW to
1400 * generate beacons */
1401 CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
1402 /* set beacon filter with FW */
1403 CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
1404 /* enable/disable filtering of probe requests in the firmware */
1405 CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
1406 /* transmit management frame by value. will be deprecated */
1407 CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
1408 /* set the probe response template. used in beacon offload mode
1409 * to setup the common probe response template with the FW to
1410 * be used by FW to generate probe responses */
1411 CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
1412
1413 /* commands to directly control ba negotiation directly from
1414 * host. only used in test mode */
1415
1416 /* turn off FW Auto addba mode and let host control addba */
1417 CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
1418 /* send add ba request */
1419 CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
1420 CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
1421 /* send del ba */
1422 CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
1423 /* set add ba response will be used by FW to generate
1424 * addba response*/
1425 CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
1426 /* send single VHT MPDU with AMSDU */
1427 CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
1428
1429 /* Station power save specific config */
1430 /* enable/disable station powersave */
1431 CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
1432 /* set station power save specific parameter */
1433 CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
1434 /* set station mimo powersave mode */
1435 CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
1436
1437 /* DFS-specific commands */
1438 /* enable DFS (radar detection)*/
1439 CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
1440 /* disable DFS (radar detection)*/
1441 CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
1442 /* enable DFS phyerr/parse filter offload */
1443 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
1444 /* enable DFS phyerr/parse filter offload */
1445 CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
1446
1447 /* Roaming specific commands */
1448 /* set roam scan mode */
1449 CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
1450 /* set roam scan rssi threshold below which roam
1451 * scan is enabled */
1452 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
1453 /* set roam scan period for periodic roam scan mode */
1454 CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
1455 /* set roam scan trigger rssi change threshold */
1456 CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
1457 /* set roam AP profile */
1458 CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
1459 /* set channel list for roam scans */
1460 CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
1461 /* offload scan specific commands */
1462 /* set offload scan AP profile */
1463 CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
1464 /* remove offload scan AP profile */
1465 CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
1466 /* set offload scan period */
1467 CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
1468
1469 /* P2P specific commands */
1470 /* set P2P device info. FW will used by FW to create P2P IE
1471 * to be carried in probe response generated during p2p listen
1472 * and for p2p discoverability */
1473 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
1474 /* enable/disable p2p discoverability on STA/AP VDEVs */
1475 CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
1476 /* set p2p ie to be carried in beacons generated by FW for GO */
1477 CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
1478 /* set p2p ie to be carried in probe response frames generated
1479 * by FW for GO */
1480 CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
1481 /* set the vendor specific p2p ie data.
1482 * FW will use this to parse the P2P NoA
1483 * attribute in the beacons/probe responses received.
1484 */
1485 CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
1486 /* set the configure of p2p find offload */
1487 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
1488 /* set the vendor specific p2p ie data for p2p find offload */
1489 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
1490 /* set the BSSID/device name pattern of p2p find offload */
1491 CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
1492 /* set OppPS related parameters **/
1493 CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
1494
1495 /* AP power save specific config
1496 * set AP power save specific param */
1497 CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
1498 /* set AP UAPSD coex pecific param */
1499 CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
1500
1501 /* Rate-control specific commands */
1502 CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
1503
1504 /* WLAN Profiling commands. */
1505 CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
1506 CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
1507 CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
1508 CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
1509 CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
1510
1511 /* Suspend resume command Ids */
1512 CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
1513 CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
1514
1515 /* Beacon filter commands */
1516 /* add a beacon filter */
1517 CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
1518 /* remove a beacon filter */
1519 CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
1520
1521 /* WOW Specific WMI commands */
1522 /* add pattern for awake */
1523 CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
1524 /* deleta a wake pattern */
1525 CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
1526 /* enable/deisable wake event */
1527 CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
1528 /* enable WOW */
1529 CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
1530 /* host woke up from sleep event to FW. Generated in response
1531 * to WOW Hardware event */
1532 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
1533
1534 /* RTT measurement related cmd */
1535 /* reques to make an RTT measurement */
1536 CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
1537 /* reques to report a tsf measurement */
1538 CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
1539
1540 /* spectral scan command */
1541 /* configure spectral scan */
1542 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
1543 /* enable/disable spectral scan and trigger */
1544 CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
1545
1546 /* F/W stats */
1547 /* one time request for stats */
1548 CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
1549 /* Push MCC Adaptive Scheduler Stats to Firmware */
1550 CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
1551
1552 /* ARP OFFLOAD REQUEST*/
1553 CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
1554
1555 /* Proactive ARP Response Add Pattern Command*/
1556 CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1557
1558 /* Proactive ARP Response Del Pattern Command*/
1559 CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
1560
1561 /* NS offload confid*/
1562 CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
1563
1564 /* GTK offload Specific WMI commands */
1565 CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
1566
1567 /* CSA offload Specific WMI commands */
1568 /* csa offload enable */
1569 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
1570 /* chan switch command */
1571 CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
1572
1573 /* Chatter commands */
1574 /* Change chatter mode of operation */
1575 CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
1576 /* chatter add coalescing filter command */
1577 CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
1578 /* chatter delete coalescing filter command */
1579 CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
1580 /* chatter coalecing query command */
1581 CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
1582
1583 /* addba specific commands */
1584 /* start the aggregation on this TID */
1585 CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
1586 /* stop the aggregation on this TID */
1587 CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
1588
1589 /* set station mimo powersave method */
1590 CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
1591 /* Configure the Station UAPSD AC Auto Trigger Parameters */
1592 CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
1593 /* Configure the Keep Alive Parameters */
1594 CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
1595
1596 /* Request ssn from target for a sta/tid pair */
1597 CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
1598 /* misc command group */
1599 /* echo command mainly used for testing */
1600 CASE_RETURN_STRING(WMI_ECHO_CMDID);
1601
1602 /* !!IMPORTANT!!
1603 * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
1604 * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1605 * as we MUST have a fixed value here to maintain compatibility between
1606 * UTF and the ART2 driver
1607 */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301608 /* UTF WMI commands */
Govind Singh6b411b52016-03-06 19:55:02 +05301609 CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
1610
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301611 /* set debug log config */
Govind Singh6b411b52016-03-06 19:55:02 +05301612 CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
1613 /* QVIT specific command id */
1614 CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
1615 /* Factory Testing Mode request command
1616 * used for integrated chipsets */
1617 CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
1618 /* set and get keepalive parameters command */
1619 CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
1620 CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
1621 /* For fw recovery test command */
1622 CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
1623 /* Set Mcast/Bdcast filter */
1624 CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
1625 /* set thermal management params */
1626 CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
1627 CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
1628 CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
1629 CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
Sreelakshmi Konamki57a2c042016-04-14 18:04:17 +05301630 CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
Anurag Chouhan25689392016-04-18 17:10:41 +05301631 CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
Anurag Chouhan7dd65542016-04-18 17:27:12 +05301632 CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
Anurag Chouhanb4a65bc2016-04-21 16:26:34 +05301633 CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301634 CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
1635 CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
1636 CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
1637 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
1638 /* GPIO Configuration */
1639 CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
1640 CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
1641
1642 /* Txbf configuration command */
1643 CASE_RETURN_STRING(WMI_TXBF_CMDID);
1644
1645 /* FWTEST Commands */
1646 CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
1647 /* set NoA descs */
1648 CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
1649
1650 /* TDLS Configuration */
1651 /* enable/disable TDLS */
1652 CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
1653 /* set tdls peer state */
1654 CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
1655
1656 /* Resmgr Configuration */
1657 /* Adaptive OCS is enabled by default in the FW.
1658 * This command is used to disable FW based adaptive OCS.
1659 */
1660 CASE_RETURN_STRING
1661 (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
1662 /* set the requested channel time quota for the home channels */
1663 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
1664 /* set the requested latency for the home channels */
1665 CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
1666
1667 /* STA SMPS Configuration */
1668 /* force SMPS mode */
1669 CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
1670 /* set SMPS parameters */
1671 CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
1672
1673 /* Wlan HB commands */
1674 /* enalbe/disable wlan HB */
1675 CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
1676 /* set tcp parameters for wlan HB */
1677 CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
1678 /* set tcp pkt filter for wlan HB */
1679 CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
1680 /* set udp parameters for wlan HB */
1681 CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
1682 /* set udp pkt filter for wlan HB */
1683 CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
1684
1685 /* Wlan RMC commands*/
1686 /* enable/disable RMC */
1687 CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
1688 /* configure action frame period */
1689 CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
1690 /* For debug/future enhancement purposes only,
1691 * configures/finetunes RMC algorithms */
1692 CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
1693
1694 /* WLAN MHF offload commands */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301695 /* enable/disable MHF offload */
Govind Singh6b411b52016-03-06 19:55:02 +05301696 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
1697 /* Plumb routing table for MHF offload */
1698 CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
1699
1700 /* location scan commands */
1701 /* start batch scan */
1702 CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
1703 /* stop batch scan */
1704 CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
1705 /* get batch scan result */
1706 CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
1707 /* OEM related cmd */
1708 CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
1709 CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
1710 /* NAN request cmd */
1711 CASE_RETURN_STRING(WMI_NAN_CMDID);
1712 /* Modem power state cmd */
1713 CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
1714 CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
1715 CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
1716 CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
1717 CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
1718 CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
1719 CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
1720 CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
1721 CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
Sreelakshmi Konamki084f3d32016-04-14 17:46:26 +05301722 CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301723 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
1724 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
1725 CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
1726 CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
1727 CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
1728 CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
1729 CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
1730 CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
1731 CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
1732 CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
1733 CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
1734 CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
1735 CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
1736 CASE_RETURN_STRING
1737 (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
1738 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
1739 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
1740 CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
1741 CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
1742 CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
1743 CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
1744 CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
1745 CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
1746 CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
1747 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
1748 CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
1749 CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
1750 CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
1751 CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
1752 CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
1753 CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
1754 CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
1755 CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
1756 CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
1757 CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
1758 CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
1759 CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
1760 CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
1761 CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
1762 CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
1763 CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
1764 CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
1765 CASE_RETURN_STRING(WMI_APFIND_CMDID);
1766 CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
1767 CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
1768 CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
1769 CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
1770 CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
1771 CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
1772 CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
1773 CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
1774 CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
1775 CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
1776 CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
1777 CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
1778 CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
1779 CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
1780 CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
1781 CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
1782 CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
1783 CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
1784 CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
1785 CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
1786 CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
1787 CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
1788 CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
1789 CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
1790 CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
1791 CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
1792 CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
1793 CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
1794 CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
1795 CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
1796 CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
1797 CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
Govind Singh8b1466e2016-03-16 16:27:50 +05301798 CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
1799 CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
1800 CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
1801 CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
1802 CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
1803 CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
1804 CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
1805 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
1806 CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
1807 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
1808 CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
1809 CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
1810 CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
1811 CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
1812 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
1813 CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
1814 CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
1815 CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
1816 CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
1817 CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
1818 CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
1819 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
1820 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
1821 CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
1822 CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
1823 CASE_RETURN_STRING(WMI_FWTEST_CMDID);
1824 CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
1825 CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
1826 CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
1827 CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
1828 CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
1829 CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
1830 CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
Naveen Rawat8cf610b2016-04-14 20:10:15 -07001831 CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
Sandeep Puligillacc28f4e2016-04-16 13:35:09 +05301832 CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
Krishna Kumaar Natarajanc285c102016-04-16 14:09:58 +05301833 CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
Krishna Kumaar Natarajan0d2a1bd2016-04-16 16:47:07 +05301834 CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
Himanshu Agarwalde992722016-05-13 20:31:57 +05301835 CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
Himanshu Agarwaldc8d1ae2016-05-13 21:04:17 +05301836 CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
Himanshu Agarwalfc302f92016-05-30 21:06:16 +05301837 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
1838 CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
Pradeep Reddy POTTETI18f8fbb2016-06-13 17:59:38 +05301839 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
1840 CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
Pradeep Reddy POTTETI4b997fd2016-06-20 13:25:31 +05301841 CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
Pradeep Reddy POTTETI10ca69d2016-06-20 14:50:42 +05301842 CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
Nitesh Shah70e11042016-06-29 20:16:16 +05301843 CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
1844 CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
Nitesh Shahc0482652016-07-08 11:45:33 +05301845 CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
Nitesh Shah33b95402016-07-21 17:25:55 +05301846 CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
1847 CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
Anurag Chouhan40865b42016-08-01 14:01:54 +05301848 CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
Anurag Chouhan7f6f1d52016-08-04 18:46:29 +05301849 CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
Manjeet Singhc026bde2016-09-01 16:42:29 +05301850 CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
Manjeet Singhbea16712016-08-18 15:50:30 +05301851 CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
1852 CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
Himanshu Agarwal91c9d672016-09-14 20:43:24 +05301853 CASE_RETURN_STRING(WMI_VDEV_ENCRYPT_DECRYPT_DATA_REQ_CMDID);
Sandeep Puligillaabcd0f52016-11-03 12:38:45 -07001854 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
1855 CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_DISABLE_CMDID);
1856 CASE_RETURN_STRING(WMI_VDEV_ADFS_CH_CFG_CMDID);
1857 CASE_RETURN_STRING(WMI_VDEV_ADFS_OCAC_ABORT_CMDID);
Nishank Aggarwale6994d22016-11-08 13:34:12 +05301858 CASE_RETURN_STRING(WMI_SAR_LIMITS_CMDID);
Govind Singh6b411b52016-03-06 19:55:02 +05301859 }
1860
1861 return "Invalid WMI cmd";
1862}
1863
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301864static inline void wma_log_cmd_id(uint32_t cmd_id, uint32_t tag)
Govind Singh6b411b52016-03-06 19:55:02 +05301865{
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301866 WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
1867 wmi_id_to_name(cmd_id), cmd_id, tag);
Govind Singh6b411b52016-03-06 19:55:02 +05301868}
Houston Hoffman0a0b2d02016-06-08 20:00:03 -07001869#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301870static uint8_t *wmi_id_to_name(uint32_t wmi_command)
Govind Singhecf03cd2016-05-12 12:45:51 +05301871{
1872 return "Invalid WMI cmd";
1873}
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301874#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301875
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301876#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05301877/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301878 * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
1879 * @cmd_id: command to check
1880 *
1881 * Return: true if the command is part of the resume sequence.
1882 */
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301883static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301884{
1885 switch (cmd_id) {
1886 case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
1887 case WMI_PDEV_RESUME_CMDID:
1888 return true;
1889
1890 default:
1891 return false;
1892 }
1893}
1894#else
Himanshu Agarwal7c83dcd2016-07-19 15:41:51 +05301895static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301896{
1897 return false;
1898}
1899#endif
1900
1901/**
Govind Singh6b411b52016-03-06 19:55:02 +05301902 * wmi_unified_cmd_send() - WMI command API
1903 * @wmi_handle: handle to wmi
1904 * @buf: wmi buf
1905 * @len: wmi buffer length
1906 * @cmd_id: wmi command id
1907 *
Dustin Brown4103e4a2016-11-14 16:11:26 -08001908 * Note, it is NOT safe to access buf after calling this function!
1909 *
Govind Singh6b411b52016-03-06 19:55:02 +05301910 * Return: 0 on success
1911 */
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001912QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
1913 uint32_t len, uint32_t cmd_id)
Govind Singh6b411b52016-03-06 19:55:02 +05301914{
1915 HTC_PACKET *pkt;
1916 A_STATUS status;
Govind Singhd52faac2016-03-09 12:03:29 +05301917 uint16_t htc_tag = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05301918
1919 if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05301920 htc_tag =
1921 (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
1922 wmi_handle, buf, cmd_id);
Govind Singhb53420c2016-03-09 14:32:57 +05301923 } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301924 (!wmi_is_pm_resume_cmd(cmd_id))) {
Govind Singhb53420c2016-03-09 14:32:57 +05301925 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301926 "%s: Target is suspended", __func__);
Govind Singhb53420c2016-03-09 14:32:57 +05301927 QDF_ASSERT(0);
Govind Singh67922e82016-04-01 16:48:57 +05301928 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301929 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301930 if (wmi_handle->wmi_stopinprogress) {
1931 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
1932 "WMI stop in progress\n");
Houston Hoffmancdd5eda2016-09-27 23:29:49 -07001933 return QDF_STATUS_E_INVAL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301934 }
Govind Singh6b411b52016-03-06 19:55:02 +05301935
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301936#ifndef WMI_NON_TLV_SUPPORT
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301937 /* Do sanity check on the TLV parameter structure */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301938 if (wmi_handle->target_type == WMI_TLV_TARGET) {
Govind Singhb53420c2016-03-09 14:32:57 +05301939 void *buf_ptr = (void *)qdf_nbuf_data(buf);
Govind Singh6b411b52016-03-06 19:55:02 +05301940
1941 if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
Govind Singhecf03cd2016-05-12 12:45:51 +05301942 != 0) {
Govind Singhb53420c2016-03-09 14:32:57 +05301943 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301944 "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
Govind Singh6b411b52016-03-06 19:55:02 +05301945 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301946 return QDF_STATUS_E_INVAL;
Govind Singh6b411b52016-03-06 19:55:02 +05301947 }
1948 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301949#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301950
Govind Singhb53420c2016-03-09 14:32:57 +05301951 if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
1952 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301953 "%s, Failed to send cmd %x, no memory",
1954 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301955 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301956 }
1957
Govind Singhb53420c2016-03-09 14:32:57 +05301958 WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
Govind Singh6b411b52016-03-06 19:55:02 +05301959
Govind Singhb53420c2016-03-09 14:32:57 +05301960 qdf_atomic_inc(&wmi_handle->pending_cmds);
1961 if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
1962 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301963 "\n%s: hostcredits = %d", __func__,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301964 wmi_get_host_credits(wmi_handle));
Govind Singh6b411b52016-03-06 19:55:02 +05301965 htc_dump_counter_info(wmi_handle->htc_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05301966 qdf_atomic_dec(&wmi_handle->pending_cmds);
1967 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Mukul Sharma7da24ca2016-10-12 23:50:13 +05301968 "%s: MAX %d WMI Pending cmds reached.", __func__,
1969 WMI_MAX_CMDS);
Govind Singhb53420c2016-03-09 14:32:57 +05301970 QDF_BUG(0);
Govind Singh67922e82016-04-01 16:48:57 +05301971 return QDF_STATUS_E_BUSY;
Govind Singh6b411b52016-03-06 19:55:02 +05301972 }
1973
Govind Singhb53420c2016-03-09 14:32:57 +05301974 pkt = qdf_mem_malloc(sizeof(*pkt));
Govind Singh6b411b52016-03-06 19:55:02 +05301975 if (!pkt) {
Govind Singhb53420c2016-03-09 14:32:57 +05301976 qdf_atomic_dec(&wmi_handle->pending_cmds);
1977 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05301978 "%s, Failed to alloc htc packet %x, no memory",
1979 __func__, cmd_id);
Govind Singh67922e82016-04-01 16:48:57 +05301980 return QDF_STATUS_E_NOMEM;
Govind Singh6b411b52016-03-06 19:55:02 +05301981 }
1982
1983 SET_HTC_PACKET_INFO_TX(pkt,
1984 NULL,
Govind Singhb53420c2016-03-09 14:32:57 +05301985 qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
Govind Singh6b411b52016-03-06 19:55:02 +05301986 wmi_handle->wmi_endpoint_id, htc_tag);
1987
1988 SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05301989#ifdef CONFIG_MCL
Sarada Prasanna Garnayakf1cf0a62016-10-18 15:20:22 +05301990 wma_log_cmd_id(cmd_id, htc_tag);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05301991#endif
Govind Singh6b411b52016-03-06 19:55:02 +05301992
1993#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05301994 if (wmi_handle->log_info.wmi_logging_enable) {
1995 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301996 /*Record 16 bytes of WMI cmd data -
1997 * * exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05301998 if (wmi_handle->ops->is_management_record(cmd_id)) {
Pratik Gandhi29e33f02016-09-16 01:32:51 +05301999 WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
2000 ((uint32_t *) qdf_nbuf_data(buf) +
2001 wmi_handle->log_info.buf_offset_command));
2002 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302003 WMI_COMMAND_RECORD(wmi_handle, cmd_id,
2004 ((uint32_t *) qdf_nbuf_data(buf) +
2005 wmi_handle->log_info.buf_offset_command));
2006 }
Govind Singhecf03cd2016-05-12 12:45:51 +05302007 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2008 }
Govind Singh6b411b52016-03-06 19:55:02 +05302009#endif
2010
2011 status = htc_send_pkt(wmi_handle->htc_handle, pkt);
2012
2013 if (A_OK != status) {
Govind Singhb53420c2016-03-09 14:32:57 +05302014 qdf_atomic_dec(&wmi_handle->pending_cmds);
2015 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302016 "%s %d, htc_send_pkt failed", __func__, __LINE__);
Houston Hoffman40805b82016-10-13 15:30:52 -07002017 qdf_mem_free(pkt);
2018
Govind Singh6b411b52016-03-06 19:55:02 +05302019 }
2020 if (status)
Govind Singhb53420c2016-03-09 14:32:57 +05302021 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302022
Govind Singhb53420c2016-03-09 14:32:57 +05302023 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302024}
2025
2026/**
2027 * wmi_unified_get_event_handler_ix() - gives event handler's index
2028 * @wmi_handle: handle to wmi
2029 * @event_id: wmi event id
2030 *
2031 * Return: event handler's index
2032 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002033static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
2034 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302035{
2036 uint32_t idx = 0;
2037 int32_t invalid_idx = -1;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302038 struct wmi_soc *soc = wmi_handle->soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302039
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302040 for (idx = 0; (idx < soc->max_event_idx &&
Govind Singh6b411b52016-03-06 19:55:02 +05302041 idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
2042 if (wmi_handle->event_id[idx] == event_id &&
2043 wmi_handle->event_handler[idx] != NULL) {
2044 return idx;
2045 }
2046 }
2047
2048 return invalid_idx;
2049}
2050
2051/**
Soumya Bhat488092d2017-03-22 14:41:01 +05302052 * wmi_unified_register_event() - register wmi event handler
2053 * @wmi_handle: handle to wmi
2054 * @event_id: wmi event id
2055 * @handler_func: wmi event handler function
2056 *
2057 * Return: 0 on success
2058 */
2059int wmi_unified_register_event(wmi_unified_t wmi_handle,
2060 uint32_t event_id,
2061 wmi_unified_event_handler handler_func)
2062{
2063 uint32_t idx = 0;
2064 uint32_t evt_id;
2065 struct wmi_soc *soc = wmi_handle->soc;
2066
2067 if (event_id >= wmi_events_max ||
2068 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2069 qdf_print("%s: Event id %d is unavailable\n",
2070 __func__, event_id);
2071 return QDF_STATUS_E_FAILURE;
2072 }
2073 evt_id = wmi_handle->wmi_events[event_id];
2074 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2075 qdf_print("%s : event handler already registered 0x%x\n",
2076 __func__, evt_id);
2077 return QDF_STATUS_E_FAILURE;
2078 }
2079 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
2080 qdf_print("%s : no more event handlers 0x%x\n",
2081 __func__, evt_id);
2082 return QDF_STATUS_E_FAILURE;
2083 }
2084 idx = soc->max_event_idx;
2085 wmi_handle->event_handler[idx] = handler_func;
2086 wmi_handle->event_id[idx] = evt_id;
2087 qdf_spin_lock_bh(&soc->ctx_lock);
2088 wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
2089 qdf_spin_unlock_bh(&soc->ctx_lock);
2090 soc->max_event_idx++;
2091
2092 return 0;
2093}
2094
2095/**
Govind Singh6b411b52016-03-06 19:55:02 +05302096 * wmi_unified_register_event_handler() - register wmi event handler
2097 * @wmi_handle: handle to wmi
2098 * @event_id: wmi event id
2099 * @handler_func: wmi event handler function
Govind Singhd52faac2016-03-09 12:03:29 +05302100 * @rx_ctx: rx execution context for wmi rx events
Govind Singh6b411b52016-03-06 19:55:02 +05302101 *
Soumya Bhat488092d2017-03-22 14:41:01 +05302102 * This API is to support legacy requirements. Will be deprecated in future.
Govind Singh6b411b52016-03-06 19:55:02 +05302103 * Return: 0 on success
2104 */
2105int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302106 uint32_t event_id,
Govind Singhd52faac2016-03-09 12:03:29 +05302107 wmi_unified_event_handler handler_func,
2108 uint8_t rx_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302109{
2110 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302111 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302112 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302113
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302114#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302115 if (event_id >= wmi_events_max ||
2116 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2117 qdf_print("%s: Event id %d is unavailable\n",
2118 __func__, event_id);
2119 return QDF_STATUS_E_FAILURE;
2120 }
2121 evt_id = wmi_handle->wmi_events[event_id];
2122#else
2123 evt_id = event_id;
2124#endif
2125 if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
2126 qdf_print("%s : event handler already registered 0x%x\n",
2127 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302128 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302129 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302130 if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302131 qdf_print("%s : no more event handlers 0x%x\n",
2132 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302133 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302134 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302135 idx = soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302136 wmi_handle->event_handler[idx] = handler_func;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302137 wmi_handle->event_id[idx] = evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302138 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302139 wmi_handle->ctx[idx] = rx_ctx;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302140 qdf_spin_unlock_bh(&soc->ctx_lock);
2141 soc->max_event_idx++;
Govind Singh6b411b52016-03-06 19:55:02 +05302142
2143 return 0;
2144}
2145
2146/**
Soumya Bhat8eb0b932017-03-27 12:26:56 +05302147 * wmi_unified_unregister_event() - unregister wmi event handler
2148 * @wmi_handle: handle to wmi
2149 * @event_id: wmi event id
2150 *
2151 * Return: 0 on success
2152 */
2153int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
2154 uint32_t event_id)
2155{
2156 uint32_t idx = 0;
2157 uint32_t evt_id;
2158 struct wmi_soc *soc = wmi_handle->soc;
2159
2160 if (event_id >= wmi_events_max ||
2161 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2162 qdf_print("%s: Event id %d is unavailable\n",
2163 __func__, event_id);
2164 return QDF_STATUS_E_FAILURE;
2165 }
2166 evt_id = wmi_handle->wmi_events[event_id];
2167
2168 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
2169 if (idx == -1) {
2170 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2171 __func__, evt_id);
2172 return QDF_STATUS_E_FAILURE;
2173 }
2174 wmi_handle->event_handler[idx] = NULL;
2175 wmi_handle->event_id[idx] = 0;
2176 --soc->max_event_idx;
2177 wmi_handle->event_handler[idx] =
2178 wmi_handle->event_handler[soc->max_event_idx];
2179 wmi_handle->event_id[idx] =
2180 wmi_handle->event_id[soc->max_event_idx];
2181
2182 return 0;
2183}
2184
2185/**
Govind Singh6b411b52016-03-06 19:55:02 +05302186 * wmi_unified_unregister_event_handler() - unregister wmi event handler
2187 * @wmi_handle: handle to wmi
2188 * @event_id: wmi event id
2189 *
2190 * Return: 0 on success
2191 */
2192int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302193 uint32_t event_id)
Govind Singh6b411b52016-03-06 19:55:02 +05302194{
2195 uint32_t idx = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302196 uint32_t evt_id;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302197 struct wmi_soc *soc = wmi_handle->soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302198
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302199#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302200 if (event_id >= wmi_events_max ||
2201 wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
2202 qdf_print("%s: Event id %d is unavailable\n",
2203 __func__, event_id);
2204 return QDF_STATUS_E_FAILURE;
2205 }
2206 evt_id = wmi_handle->wmi_events[event_id];
2207#else
2208 evt_id = event_id;
2209#endif
2210
2211 idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
Govind Singh6b411b52016-03-06 19:55:02 +05302212 if (idx == -1) {
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302213 qdf_print("%s : event handler is not registered: evt id 0x%x\n",
2214 __func__, evt_id);
Govind Singhb53420c2016-03-09 14:32:57 +05302215 return QDF_STATUS_E_FAILURE;
Govind Singh6b411b52016-03-06 19:55:02 +05302216 }
2217 wmi_handle->event_handler[idx] = NULL;
2218 wmi_handle->event_id[idx] = 0;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302219 --soc->max_event_idx;
Govind Singh6b411b52016-03-06 19:55:02 +05302220 wmi_handle->event_handler[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302221 wmi_handle->event_handler[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302222 wmi_handle->event_id[idx] =
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302223 wmi_handle->event_id[soc->max_event_idx];
Govind Singh6b411b52016-03-06 19:55:02 +05302224
2225 return 0;
2226}
2227
2228/**
Govind Singhd52faac2016-03-09 12:03:29 +05302229 * wmi_process_fw_event_default_ctx() - process in default caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302230 * @wmi_handle: handle to wmi
2231 * @htc_packet: pointer to htc packet
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302232 * @exec_ctx: execution context for wmi fw event
Govind Singh6b411b52016-03-06 19:55:02 +05302233 *
Govind Singhd52faac2016-03-09 12:03:29 +05302234 * Event process by below function will be in default caller context.
2235 * wmi internally provides rx work thread processing context.
Govind Singh6b411b52016-03-06 19:55:02 +05302236 *
2237 * Return: none
2238 */
Govind Singhd52faac2016-03-09 12:03:29 +05302239static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
2240 HTC_PACKET *htc_packet, uint8_t exec_ctx)
Govind Singh6b411b52016-03-06 19:55:02 +05302241{
2242 wmi_buf_t evt_buf;
2243 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
2244
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302245#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302246 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
2247 (wmi_handle->scn_handle, evt_buf, exec_ctx);
2248#else
Govind Singh5eb51532016-03-09 11:34:12 +05302249 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
Govind Singhd52faac2016-03-09 12:03:29 +05302250 evt_buf, exec_ctx);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302251#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302252
Govind Singh6b411b52016-03-06 19:55:02 +05302253 return;
2254}
2255
2256/**
2257 * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
2258 * @wmi_handle: handle to wmi
2259 * @htc_packet: pointer to htc packet
2260 *
2261 * Event process by below function will be in worker thread context.
2262 * Use this method for events which are not critical and not
2263 * handled in protocol stack.
2264 *
2265 * Return: none
2266 */
2267static void wmi_process_fw_event_worker_thread_ctx
2268 (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
2269{
2270 wmi_buf_t evt_buf;
2271 uint32_t id;
2272 uint8_t *data;
2273
2274 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Govind Singhb53420c2016-03-09 14:32:57 +05302275 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
2276 data = qdf_nbuf_data(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302277
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302278#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302279 if (wmi_handle->log_info.wmi_logging_enable) {
2280 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2281 /* Exclude 4 bytes of TLV header */
2282 WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2283 wmi_handle->log_info.buf_offset_event));
2284 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2285 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302286#endif
Govind Singhb53420c2016-03-09 14:32:57 +05302287 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2288 qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
2289 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002290 qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
2291 &wmi_handle->rx_event_work);
2292
Govind Singh6b411b52016-03-06 19:55:02 +05302293 return;
2294}
2295
2296/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302297 * wmi_get_pdev_ep: Get wmi handle based on endpoint
2298 * @soc: handle to wmi soc
2299 * @ep: endpoint id
2300 *
2301 * Return: none
2302 */
2303static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
2304 HTC_ENDPOINT_ID ep)
2305{
2306 uint32_t i;
2307
2308 for (i = 0; i < WMI_MAX_RADIOS; i++)
2309 if (soc->wmi_endpoint_id[i] == ep)
2310 break;
2311
2312 if (i == WMI_MAX_RADIOS)
2313 return NULL;
2314
2315 return soc->wmi_pdev[i];
2316}
2317
2318/**
Govind Singhd52faac2016-03-09 12:03:29 +05302319 * wmi_control_rx() - process fw events callbacks
Govind Singh6b411b52016-03-06 19:55:02 +05302320 * @ctx: handle to wmi
2321 * @htc_packet: pointer to htc packet
2322 *
Govind Singh6b411b52016-03-06 19:55:02 +05302323 * Return: none
2324 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002325static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
Govind Singh6b411b52016-03-06 19:55:02 +05302326{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302327 struct wmi_soc *soc = (struct wmi_soc *) ctx;
2328 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302329 wmi_buf_t evt_buf;
2330 uint32_t id;
Govind Singhd52faac2016-03-09 12:03:29 +05302331 uint32_t idx = 0;
2332 enum wmi_rx_exec_ctx exec_ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302333
2334 evt_buf = (wmi_buf_t) htc_packet->pPktContext;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302335
2336 wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
2337 if (wmi_handle == NULL) {
2338 qdf_print
2339 ("%s :unable to get wmi_handle to Endpoint %d\n",
2340 __func__, htc_packet->Endpoint);
2341 qdf_nbuf_free(evt_buf);
2342 return;
2343 }
2344
Govind Singhb53420c2016-03-09 14:32:57 +05302345 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singhd52faac2016-03-09 12:03:29 +05302346 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302347 if (qdf_unlikely(idx == A_ERROR)) {
2348 qdf_print
Govind Singhd52faac2016-03-09 12:03:29 +05302349 ("%s :event handler is not registered: event id 0x%x\n",
2350 __func__, id);
Govind Singhb53420c2016-03-09 14:32:57 +05302351 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302352 return;
2353 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302354 qdf_spin_lock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302355 exec_ctx = wmi_handle->ctx[idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302356 qdf_spin_unlock_bh(&soc->ctx_lock);
Govind Singhd52faac2016-03-09 12:03:29 +05302357
2358 if (exec_ctx == WMI_RX_WORK_CTX) {
Govind Singh6b411b52016-03-06 19:55:02 +05302359 wmi_process_fw_event_worker_thread_ctx
2360 (wmi_handle, htc_packet);
Govind Singhd52faac2016-03-09 12:03:29 +05302361 } else if (exec_ctx > WMI_RX_WORK_CTX) {
2362 wmi_process_fw_event_default_ctx
2363 (wmi_handle, htc_packet, exec_ctx);
2364 } else {
Govind Singhb53420c2016-03-09 14:32:57 +05302365 qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
2366 qdf_nbuf_free(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302367 }
Govind Singhd52faac2016-03-09 12:03:29 +05302368
Govind Singh6b411b52016-03-06 19:55:02 +05302369}
2370
2371/**
2372 * wmi_process_fw_event() - process any fw event
2373 * @wmi_handle: wmi handle
2374 * @evt_buf: fw event buffer
2375 *
Govind Singhd52faac2016-03-09 12:03:29 +05302376 * This function process fw event in caller context
Govind Singh6b411b52016-03-06 19:55:02 +05302377 *
2378 * Return: none
2379 */
2380void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2381{
2382 __wmi_control_rx(wmi_handle, evt_buf);
2383}
2384
2385/**
2386 * __wmi_control_rx() - process serialize wmi event callback
2387 * @wmi_handle: wmi handle
2388 * @evt_buf: fw event buffer
2389 *
2390 * Return: none
2391 */
2392void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
2393{
2394 uint32_t id;
2395 uint8_t *data;
2396 uint32_t len;
2397 void *wmi_cmd_struct_ptr = NULL;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302398#ifndef WMI_NON_TLV_SUPPORT
Govind Singh6b411b52016-03-06 19:55:02 +05302399 int tlv_ok_status = 0;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302400#endif
Govind Singhd52faac2016-03-09 12:03:29 +05302401 uint32_t idx = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302402
Govind Singhb53420c2016-03-09 14:32:57 +05302403 id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302404
Govind Singhb53420c2016-03-09 14:32:57 +05302405 if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
Govind Singh6b411b52016-03-06 19:55:02 +05302406 goto end;
2407
Govind Singhb53420c2016-03-09 14:32:57 +05302408 data = qdf_nbuf_data(evt_buf);
2409 len = qdf_nbuf_len(evt_buf);
Govind Singh6b411b52016-03-06 19:55:02 +05302410
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302411#ifndef WMI_NON_TLV_SUPPORT
2412 if (wmi_handle->target_type == WMI_TLV_TARGET) {
2413 /* Validate and pad(if necessary) the TLVs */
2414 tlv_ok_status =
2415 wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
Govind Singh6b411b52016-03-06 19:55:02 +05302416 data, len, id,
2417 &wmi_cmd_struct_ptr);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302418 if (tlv_ok_status != 0) {
2419 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
2420 "%s: Error: id=0x%d, wmitlv check status=%d\n",
2421 __func__, id, tlv_ok_status);
2422 goto end;
2423 }
Govind Singh6b411b52016-03-06 19:55:02 +05302424 }
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302425#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302426
Govind Singhd52faac2016-03-09 12:03:29 +05302427 idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
2428 if (idx == A_ERROR) {
Govind Singhb53420c2016-03-09 14:32:57 +05302429 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
Govind Singhd52faac2016-03-09 12:03:29 +05302430 "%s : event handler is not registered: event id 0x%x\n",
2431 __func__, id);
Govind Singh6b411b52016-03-06 19:55:02 +05302432 goto end;
2433 }
Govind Singhd52faac2016-03-09 12:03:29 +05302434#ifdef WMI_INTERFACE_EVENT_LOGGING
Govind Singhecf03cd2016-05-12 12:45:51 +05302435 if (wmi_handle->log_info.wmi_logging_enable) {
2436 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
2437 /* Exclude 4 bytes of TLV header */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302438 if (wmi_handle->ops->is_management_record(id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302439 WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
2440 + wmi_handle->log_info.buf_offset_event));
2441 } else {
2442 WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
2443 wmi_handle->log_info.buf_offset_event));
2444 }
2445 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302446 }
Govind Singhd52faac2016-03-09 12:03:29 +05302447#endif
2448 /* Call the WMI registered event handler */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302449 if (wmi_handle->target_type == WMI_TLV_TARGET)
2450 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2451 wmi_cmd_struct_ptr, len);
2452 else
2453 wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
2454 data, len);
Govind Singhd52faac2016-03-09 12:03:29 +05302455
Govind Singh6b411b52016-03-06 19:55:02 +05302456end:
Govind Singhd52faac2016-03-09 12:03:29 +05302457 /* Free event buffer and allocated event tlv */
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302458#ifndef WMI_NON_TLV_SUPPORT
2459 if (wmi_handle->target_type == WMI_TLV_TARGET)
2460 wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
2461#endif
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302462
Govind Singhb53420c2016-03-09 14:32:57 +05302463 qdf_nbuf_free(evt_buf);
Govind Singhd52faac2016-03-09 12:03:29 +05302464
Govind Singh6b411b52016-03-06 19:55:02 +05302465}
2466
2467/**
2468 * wmi_rx_event_work() - process rx event in rx work queue context
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002469 * @arg: opaque pointer to wmi handle
Govind Singh6b411b52016-03-06 19:55:02 +05302470 *
2471 * This function process any fw event to serialize it through rx worker thread.
2472 *
2473 * Return: none
2474 */
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002475static void wmi_rx_event_work(void *arg)
Govind Singh6b411b52016-03-06 19:55:02 +05302476{
Govind Singh6b411b52016-03-06 19:55:02 +05302477 wmi_buf_t buf;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002478 struct wmi_unified *wmi = arg;
Govind Singh6b411b52016-03-06 19:55:02 +05302479
Govind Singhb53420c2016-03-09 14:32:57 +05302480 qdf_spin_lock_bh(&wmi->eventq_lock);
2481 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2482 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302483 while (buf) {
2484 __wmi_control_rx(wmi, buf);
Govind Singhb53420c2016-03-09 14:32:57 +05302485 qdf_spin_lock_bh(&wmi->eventq_lock);
2486 buf = qdf_nbuf_queue_remove(&wmi->event_queue);
2487 qdf_spin_unlock_bh(&wmi->eventq_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302488 }
2489}
2490
Govind Singh6b411b52016-03-06 19:55:02 +05302491#ifdef FEATURE_RUNTIME_PM
2492/**
2493 * wmi_runtime_pm_init() - initialize runtime pm wmi variables
2494 * @wmi_handle: wmi context
2495 */
Govind Singhd52faac2016-03-09 12:03:29 +05302496static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302497{
Govind Singhb53420c2016-03-09 14:32:57 +05302498 qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
Govind Singh6b411b52016-03-06 19:55:02 +05302499}
Govind Singhd52faac2016-03-09 12:03:29 +05302500
2501/**
2502 * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
2503 * @wmi_handle: wmi context
2504 * @val: runtime pm progress flag
2505 */
2506void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
2507{
Govind Singhb53420c2016-03-09 14:32:57 +05302508 qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
Govind Singhd52faac2016-03-09 12:03:29 +05302509}
2510
2511/**
2512 * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
2513 * @wmi_handle: wmi context
2514 */
2515inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
2516{
Govind Singhb53420c2016-03-09 14:32:57 +05302517 return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
Govind Singhd52faac2016-03-09 12:03:29 +05302518}
Govind Singh6b411b52016-03-06 19:55:02 +05302519#else
Govind Singhd52faac2016-03-09 12:03:29 +05302520static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
Govind Singh6b411b52016-03-06 19:55:02 +05302521{
2522}
2523#endif
2524
2525/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302526 * wmi_unified_get_soc_handle: Get WMI SoC handle
2527 * @param wmi_handle: WMI context got from wmi_attach
2528 *
2529 * return: Pointer to Soc handle
2530 */
2531void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
2532{
2533 return wmi_handle->soc;
2534}
2535
2536/**
2537 * wmi_interface_logging_init: Interface looging init
2538 * @param wmi_handle: Pointer to wmi handle object
2539 *
2540 * return: None
2541 */
2542#ifdef WMI_INTERFACE_EVENT_LOGGING
2543static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2544{
2545 if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
2546 qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
2547 wmi_debugfs_init(wmi_handle);
2548 }
2549}
2550#else
2551void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
2552{
2553}
2554#endif
2555
2556/**
2557 * wmi_target_params_init: Target specific params init
2558 * @param wmi_soc: Pointer to wmi soc object
2559 * @param wmi_handle: Pointer to wmi handle object
2560 *
2561 * return: None
2562 */
2563#ifndef CONFIG_MCL
2564static inline void wmi_target_params_init(struct wmi_soc *soc,
2565 struct wmi_unified *wmi_handle)
2566{
2567 /* WMI service bitmap recieved from target */
2568 wmi_handle->wmi_service_bitmap = soc->wmi_service_bitmap;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302569 wmi_handle->pdev_param = soc->pdev_param;
2570 wmi_handle->vdev_param = soc->vdev_param;
2571 wmi_handle->services = soc->services;
2572}
2573#else
2574static inline void wmi_target_params_init(struct wmi_soc *soc,
2575 struct wmi_unified *wmi_handle)
2576{
2577}
2578#endif
2579
2580/**
2581 * wmi_unified_get_pdev_handle: Get WMI SoC handle
2582 * @param wmi_soc: Pointer to wmi soc object
2583 * @param pdev_idx: pdev index
2584 *
2585 * return: Pointer to wmi handle or NULL on failure
2586 */
2587void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
2588{
2589 struct wmi_unified *wmi_handle;
2590
2591 if (pdev_idx >= WMI_MAX_RADIOS)
2592 return NULL;
2593
2594 /* If wmi pdev is already allocated, just return the handle */
2595 if (soc->wmi_pdev[pdev_idx] != NULL)
2596 return soc->wmi_pdev[pdev_idx];
2597
2598 wmi_handle =
2599 (struct wmi_unified *) qdf_mem_malloc(
2600 sizeof(struct wmi_unified));
2601 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302602 qdf_print("allocation of wmi handle failed %zu\n",
2603 sizeof(struct wmi_unified));
2604 return NULL;
2605 }
2606 wmi_handle->scn_handle = soc->scn_handle;
2607 wmi_handle->event_id = soc->event_id;
2608 wmi_handle->event_handler = soc->event_handler;
2609 wmi_handle->ctx = soc->ctx;
2610 wmi_handle->ops = soc->ops;
2611 qdf_spinlock_create(&wmi_handle->eventq_lock);
2612 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002613
2614 qdf_create_work(0, &wmi_handle->rx_event_work,
2615 wmi_rx_event_work, wmi_handle);
2616 wmi_handle->wmi_rx_work_queue =
2617 qdf_create_workqueue("wmi_rx_event_work_queue");
2618 if (NULL == wmi_handle->wmi_rx_work_queue) {
2619 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2620 goto error;
2621 }
Soumya Bhat488092d2017-03-22 14:41:01 +05302622 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302623 wmi_target_params_init(soc, wmi_handle);
2624 wmi_interface_logging_init(wmi_handle);
2625 qdf_atomic_init(&wmi_handle->pending_cmds);
2626 qdf_atomic_init(&wmi_handle->is_target_suspended);
2627 wmi_handle->target_type = soc->target_type;
2628 wmi_handle->wmi_stopinprogress = 0;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302629 wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
2630 wmi_handle->htc_handle = soc->htc_handle;
2631 wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302632 wmi_handle->soc = soc;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302633
2634 soc->wmi_pdev[pdev_idx] = wmi_handle;
2635
2636 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002637
2638error:
2639 qdf_mem_free(wmi_handle);
2640
2641 return NULL;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302642}
2643
2644/**
Govind Singh6b411b52016-03-06 19:55:02 +05302645 * wmi_unified_attach() - attach for unified WMI
Govind Singhc458f382016-02-04 18:42:30 +05302646 * @scn_handle: handle to SCN
2647 * @osdev: OS device context
2648 * @target_type: TLV or not-TLV based target
2649 * @use_cookie: cookie based allocation enabled/disabled
2650 * @ops: umac rx callbacks
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302651 * @psoc: objmgr psoc
Govind Singh6b411b52016-03-06 19:55:02 +05302652 *
2653 * @Return: wmi handle.
2654 */
Govind Singhc458f382016-02-04 18:42:30 +05302655void *wmi_unified_attach(void *scn_handle,
2656 osdev_t osdev, enum wmi_target_type target_type,
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302657 bool use_cookie, struct wmi_rx_ops *rx_ops,
2658 struct wlan_objmgr_psoc *psoc)
Govind Singh6b411b52016-03-06 19:55:02 +05302659{
2660 struct wmi_unified *wmi_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302661 struct wmi_soc *soc;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302662
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302663 soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
2664 if (soc == NULL) {
2665 qdf_print("Allocation of wmi_soc failed %zu\n",
2666 sizeof(struct wmi_soc));
2667 return NULL;
2668 }
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05302669#ifdef CONFIG_MCL
Govind Singh6b411b52016-03-06 19:55:02 +05302670 wmi_handle =
2671 (struct wmi_unified *)os_malloc(NULL,
2672 sizeof(struct wmi_unified),
2673 GFP_ATOMIC);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302674#else
2675 wmi_handle =
2676 (struct wmi_unified *) qdf_mem_malloc(
2677 sizeof(struct wmi_unified));
2678#endif
Govind Singh6b411b52016-03-06 19:55:02 +05302679 if (wmi_handle == NULL) {
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302680 qdf_mem_free(soc);
Govind Singhb53420c2016-03-09 14:32:57 +05302681 qdf_print("allocation of wmi handle failed %zu\n",
Govind Singhd52faac2016-03-09 12:03:29 +05302682 sizeof(struct wmi_unified));
Govind Singh6b411b52016-03-06 19:55:02 +05302683 return NULL;
2684 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302685 wmi_handle->soc = soc;
2686 wmi_handle->event_id = soc->event_id;
2687 wmi_handle->event_handler = soc->event_handler;
2688 wmi_handle->ctx = soc->ctx;
Soumya Bhat488092d2017-03-22 14:41:01 +05302689 wmi_handle->wmi_events = soc->wmi_events;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302690 wmi_target_params_init(soc, wmi_handle);
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302691 wmi_handle->scn_handle = scn_handle;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302692 soc->scn_handle = scn_handle;
Govind Singhb53420c2016-03-09 14:32:57 +05302693 qdf_atomic_init(&wmi_handle->pending_cmds);
2694 qdf_atomic_init(&wmi_handle->is_target_suspended);
Govind Singh6b411b52016-03-06 19:55:02 +05302695 wmi_runtime_pm_init(wmi_handle);
Govind Singhb53420c2016-03-09 14:32:57 +05302696 qdf_spinlock_create(&wmi_handle->eventq_lock);
2697 qdf_nbuf_queue_init(&wmi_handle->event_queue);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002698 qdf_create_work(0, &wmi_handle->rx_event_work,
2699 wmi_rx_event_work, wmi_handle);
2700 wmi_handle->wmi_rx_work_queue =
2701 qdf_create_workqueue("wmi_rx_event_work_queue");
2702 if (NULL == wmi_handle->wmi_rx_work_queue) {
2703 WMI_LOGE("failed to create wmi_rx_event_work_queue");
2704 goto error;
2705 }
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302706 wmi_interface_logging_init(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302707 /* Attach mc_thread context processing function */
Govind Singh5eb51532016-03-09 11:34:12 +05302708 wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
2709 rx_ops->wma_process_fw_event_handler_cbk;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302710 wmi_handle->target_type = target_type;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302711 soc->target_type = target_type;
Govind Singhc458f382016-02-04 18:42:30 +05302712 if (target_type == WMI_TLV_TARGET)
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302713 wmi_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302714 else
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302715 wmi_non_tlv_attach(wmi_handle);
Govind Singhc458f382016-02-04 18:42:30 +05302716 /* Assign target cookie capablity */
2717 wmi_handle->use_cookie = use_cookie;
2718 wmi_handle->osdev = osdev;
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302719 wmi_handle->wmi_stopinprogress = 0;
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302720 /* Increase the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302721 soc->wmi_psoc = psoc;
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302722 qdf_spinlock_create(&soc->ctx_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302723
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302724 soc->ops = wmi_handle->ops;
2725 soc->wmi_pdev[0] = wmi_handle;
2726
Govind Singh6b411b52016-03-06 19:55:02 +05302727 return wmi_handle;
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002728
2729error:
2730 qdf_mem_free(soc);
2731 qdf_mem_free(wmi_handle);
2732
2733 return NULL;
Govind Singh6b411b52016-03-06 19:55:02 +05302734}
2735
2736/**
2737 * wmi_unified_detach() - detach for unified WMI
2738 *
2739 * @wmi_handle : handle to wmi.
2740 *
2741 * @Return: none.
2742 */
2743void wmi_unified_detach(struct wmi_unified *wmi_handle)
2744{
2745 wmi_buf_t buf;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302746 struct wmi_soc *soc;
2747 uint8_t i;
Govind Singh6b411b52016-03-06 19:55:02 +05302748
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302749 soc = wmi_handle->soc;
2750 for (i = 0; i < WMI_MAX_RADIOS; i++) {
2751 if (soc->wmi_pdev[i]) {
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002752 qdf_flush_workqueue(0,
2753 soc->wmi_pdev[i]->wmi_rx_work_queue);
2754 qdf_destroy_workqueue(0,
2755 soc->wmi_pdev[i]->wmi_rx_work_queue);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302756 wmi_debugfs_remove(soc->wmi_pdev[i]);
2757 buf = qdf_nbuf_queue_remove(
2758 &soc->wmi_pdev[i]->event_queue);
2759 while (buf) {
2760 qdf_nbuf_free(buf);
2761 buf = qdf_nbuf_queue_remove(
2762 &soc->wmi_pdev[i]->event_queue);
2763 }
Rajeev Kumarae91c402016-05-25 16:07:23 -07002764
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302765 wmi_log_buffer_free(soc->wmi_pdev[i]);
2766 qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302767 qdf_mem_free(soc->wmi_pdev[i]);
2768 }
Govind Singh6b411b52016-03-06 19:55:02 +05302769 }
Kiran Venkatappaf285aba2017-03-20 20:38:44 +05302770 qdf_spinlock_destroy(&soc->ctx_lock);
Mukul Sharmaf8a17082017-01-30 19:55:40 +05302771 /* Decrease the ref count once refcount infra is present */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302772 soc->wmi_psoc = NULL;
2773 qdf_mem_free(soc);
Govind Singh6b411b52016-03-06 19:55:02 +05302774}
2775
2776/**
2777 * wmi_unified_remove_work() - detach for WMI work
2778 * @wmi_handle: handle to WMI
2779 *
2780 * A function that does not fully detach WMI, but just remove work
2781 * queue items associated with it. This is used to make sure that
2782 * before any other processing code that may destroy related contexts
2783 * (HTC, etc), work queue processing on WMI has already been stopped.
2784 *
2785 * Return: None
2786 */
2787void
2788wmi_unified_remove_work(struct wmi_unified *wmi_handle)
2789{
2790 wmi_buf_t buf;
2791
Govind Singhb53420c2016-03-09 14:32:57 +05302792 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302793 "Enter: %s", __func__);
Rajeev Kumar2ec8d472017-03-29 17:14:14 -07002794 qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
Govind Singhb53420c2016-03-09 14:32:57 +05302795 qdf_spin_lock_bh(&wmi_handle->eventq_lock);
2796 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302797 while (buf) {
Govind Singhb53420c2016-03-09 14:32:57 +05302798 qdf_nbuf_free(buf);
2799 buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
Govind Singh6b411b52016-03-06 19:55:02 +05302800 }
Govind Singhb53420c2016-03-09 14:32:57 +05302801 qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
2802 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
Govind Singh6b411b52016-03-06 19:55:02 +05302803 "Done: %s", __func__);
2804}
2805
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302806/**
2807 * wmi_htc_tx_complete() - Process htc tx completion
2808 *
2809 * @ctx: handle to wmi
2810 * @htc_packet: pointer to htc packet
2811 *
2812 * @Return: none.
2813 */
Jeff Johnson9366d7a2016-10-07 13:03:02 -07002814static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
Govind Singh6b411b52016-03-06 19:55:02 +05302815{
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302816 struct wmi_soc *soc = (struct wmi_soc *) ctx;
Govind Singh6b411b52016-03-06 19:55:02 +05302817 wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
Govind Singh82ea3262016-09-02 15:24:25 +05302818 u_int8_t *buf_ptr;
2819 u_int32_t len;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302820 struct wmi_unified *wmi_handle;
Govind Singh6b411b52016-03-06 19:55:02 +05302821#ifdef WMI_INTERFACE_EVENT_LOGGING
2822 uint32_t cmd_id;
2823#endif
2824
2825 ASSERT(wmi_cmd_buf);
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302826 wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
2827 if (wmi_handle == NULL) {
2828 WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
2829 QDF_ASSERT(0);
2830 return;
2831 }
Govind Singh6b411b52016-03-06 19:55:02 +05302832#ifdef WMI_INTERFACE_EVENT_LOGGING
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302833 if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302834 cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
2835 WMI_CMD_HDR, COMMANDID);
Govind Singh6b411b52016-03-06 19:55:02 +05302836
Govind Singhecf03cd2016-05-12 12:45:51 +05302837 qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
Govind Singh6b411b52016-03-06 19:55:02 +05302838 /* Record 16 bytes of WMI cmd tx complete data
Govind Singhecf03cd2016-05-12 12:45:51 +05302839 - exclude TLV and WMI headers */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302840 if (wmi_handle->ops->is_management_record(cmd_id)) {
Govind Singhecf03cd2016-05-12 12:45:51 +05302841 WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2842 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2843 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302844 } else {
Govind Singhecf03cd2016-05-12 12:45:51 +05302845 WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
2846 ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
2847 wmi_handle->log_info.buf_offset_command));
Govind Singh6b411b52016-03-06 19:55:02 +05302848 }
2849
Govind Singhecf03cd2016-05-12 12:45:51 +05302850 qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
2851 }
Govind Singh6b411b52016-03-06 19:55:02 +05302852#endif
Govind Singh82ea3262016-09-02 15:24:25 +05302853 buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
2854 len = qdf_nbuf_len(wmi_cmd_buf);
2855 qdf_mem_zero(buf_ptr, len);
Govind Singhb53420c2016-03-09 14:32:57 +05302856 qdf_nbuf_free(wmi_cmd_buf);
2857 qdf_mem_free(htc_pkt);
2858 qdf_atomic_dec(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302859}
2860
2861/**
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302862 * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
Govind Singh6b411b52016-03-06 19:55:02 +05302863 *
2864 * @wmi_handle: handle to WMI.
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302865 * @pdev_idx: Pdev index
Govind Singh6b411b52016-03-06 19:55:02 +05302866 *
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302867 * @Return: status.
Govind Singh6b411b52016-03-06 19:55:02 +05302868 */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302869static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
2870 uint32_t pdev_idx)
Govind Singh6b411b52016-03-06 19:55:02 +05302871{
Govind Singh6b411b52016-03-06 19:55:02 +05302872 int status;
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302873 uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
2874 WMI_CONTROL_SVC_WMAC2};
Govind Singh6b411b52016-03-06 19:55:02 +05302875 HTC_SERVICE_CONNECT_RESP response;
2876 HTC_SERVICE_CONNECT_REQ connect;
2877
2878 OS_MEMZERO(&connect, sizeof(connect));
2879 OS_MEMZERO(&response, sizeof(response));
2880
2881 /* meta data is unused for now */
2882 connect.pMetaData = NULL;
2883 connect.MetaDataLength = 0;
2884 /* these fields are the same for all service endpoints */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302885 connect.EpCallbacks.pContext = soc;
Govind Singh6b411b52016-03-06 19:55:02 +05302886 connect.EpCallbacks.EpTxCompleteMultiple =
2887 NULL /* Control path completion ar6000_tx_complete */;
2888 connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
2889 connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
2890 connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
2891 connect.EpCallbacks.EpTxComplete =
2892 wmi_htc_tx_complete /* ar6000_tx_queue_full */;
2893
2894 /* connect to control service */
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302895 connect.service_id = svc_id[pdev_idx];
2896 status = htc_connect_service(soc->htc_handle, &connect,
Govind Singh6b411b52016-03-06 19:55:02 +05302897 &response);
2898
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302899
Govind Singh6b411b52016-03-06 19:55:02 +05302900 if (status != EOK) {
Govind Singhb53420c2016-03-09 14:32:57 +05302901 qdf_print
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302902 ("Failed to connect to WMI CONTROL service status:%d\n",
Govind Singh6b411b52016-03-06 19:55:02 +05302903 status);
2904 return status;
2905 }
Govind Singh6b411b52016-03-06 19:55:02 +05302906
Kiran Venkatappa5bffce52017-02-10 16:57:59 +05302907 soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
2908 soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
2909
2910 return 0;
2911}
2912
2913/**
2914 * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
2915 *
2916 * @wmi_handle: handle to WMI.
2917 *
2918 * @Return: status.
2919 */
2920QDF_STATUS
2921wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
2922 void *htc_handle)
2923{
2924 uint32_t i;
2925 uint8_t wmi_ep_count;
2926
2927 wmi_handle->soc->htc_handle = htc_handle;
2928
2929 wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
2930 if (wmi_ep_count > WMI_MAX_RADIOS)
2931 return QDF_STATUS_E_FAULT;
2932
2933 for (i = 0; i < wmi_ep_count; i++)
2934 wmi_connect_pdev_htc_service(wmi_handle->soc, i);
2935
2936 wmi_handle->htc_handle = htc_handle;
2937 wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
2938 wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
2939
2940 return QDF_STATUS_SUCCESS;
Govind Singh6b411b52016-03-06 19:55:02 +05302941}
2942
2943/**
2944 * wmi_get_host_credits() - WMI API to get updated host_credits
2945 *
2946 * @wmi_handle: handle to WMI.
2947 *
2948 * @Return: updated host_credits.
2949 */
2950int wmi_get_host_credits(wmi_unified_t wmi_handle)
2951{
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302952 int host_credits = 0;
Govind Singh6b411b52016-03-06 19:55:02 +05302953
2954 htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
2955 &host_credits);
2956 return host_credits;
2957}
2958
2959/**
Govind Singhe7d9f3e2016-04-15 13:58:27 +05302960 * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
2961 * queue
Govind Singh6b411b52016-03-06 19:55:02 +05302962 *
2963 * @wmi_handle: handle to WMI.
2964 *
2965 * @Return: Pending Commands in the HTC queue.
2966 */
2967int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
2968{
Govind Singhb53420c2016-03-09 14:32:57 +05302969 return qdf_atomic_read(&wmi_handle->pending_cmds);
Govind Singh6b411b52016-03-06 19:55:02 +05302970}
2971
2972/**
2973 * wmi_set_target_suspend() - WMI API to set target suspend state
2974 *
2975 * @wmi_handle: handle to WMI.
2976 * @val: suspend state boolean.
2977 *
2978 * @Return: none.
2979 */
2980void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
2981{
Govind Singhb53420c2016-03-09 14:32:57 +05302982 qdf_atomic_set(&wmi_handle->is_target_suspended, val);
Govind Singh6b411b52016-03-06 19:55:02 +05302983}
2984
Sarada Prasanna Garnayak17b9e9e2017-01-05 19:30:07 +05302985/**
2986 * WMI API to set crash injection state
2987 * @param wmi_handle: handle to WMI.
2988 * @param val: crash injection state boolean.
2989 */
2990void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
2991{
2992 wmi_handle->tag_crash_inject = flag;
2993}
2994
2995/**
2996 * WMI API to set bus suspend state
2997 * @param wmi_handle: handle to WMI.
2998 * @param val: suspend state boolean.
2999 */
3000void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
3001{
3002 qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
3003}
3004
Kiran Venkatappa1d5f5ab2016-08-09 22:52:35 +05303005#ifndef CONFIG_MCL
Govind Singhe7d9f3e2016-04-15 13:58:27 +05303006/**
3007 * API to flush all the previous packets associated with the wmi endpoint
3008 *
3009 * @param wmi_handle : handle to WMI.
3010 */
3011void
3012wmi_flush_endpoint(wmi_unified_t wmi_handle)
3013{
3014 htc_flush_endpoint(wmi_handle->htc_handle,
3015 wmi_handle->wmi_endpoint_id, 0);
3016}
3017
3018/**
3019 * generic function to block unified WMI command
3020 * @param wmi_handle : handle to WMI.
3021 * @return 0 on success and -ve on failure.
3022 */
3023int
3024wmi_stop(wmi_unified_t wmi_handle)
3025{
3026 QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
3027 "WMI Stop\n");
3028 wmi_handle->wmi_stopinprogress = 1;
3029 return 0;
3030}
3031#endif