blob: fda24aa2fc80218875cf4d2fbe37508241254945 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +05302 * Copyright (c) 2012-2015 The Linux Foundation. All rights reserved.
Kiet Lam1ed83fc2014-02-19 01:15:45 -08003 *
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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam1ed83fc2014-02-19 01:15:45 -080021
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
Jeff Johnson295189b2012-06-20 16:38:30 -070028/**=========================================================================
29
30 \file vos_trace.c
31
32 \brief virtual Operating System Servies (vOS)
33
34 Trace, logging, and debugging definitions and APIs
35
Jeff Johnson295189b2012-06-20 16:38:30 -070036
37 ========================================================================*/
38
39/*===========================================================================
40
41 EDIT HISTORY FOR FILE
42
43
44 This section contains comments describing changes made to the module.
45 Notice that changes are listed in reverse chronological order.
46
47
48 $Header:$ $DateTime: $ $Author: $
49
50
51 when who what, where, why
52 -------- --- --------------------------------------------------------
53 09/16/08 hvm Adding ability to set multiple trace levels per component
54 09/11/08 lac Added trace levels per component. Cleanup from review.
55 08/14/08 vpai Particular modules and desired level can be selected
56 06/20/08 vpai Created Module
57===========================================================================*/
58
59/*--------------------------------------------------------------------------
60 Include Files
61 ------------------------------------------------------------------------*/
62#include <vos_trace.h>
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -070063#include <aniGlobal.h>
Vinay Krishna Erannad938c422014-03-10 17:14:21 +053064#include <wlan_logging_sock_svc.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070065/*--------------------------------------------------------------------------
66 Preprocessor definitions and constants
67 ------------------------------------------------------------------------*/
68
69#define VOS_TRACE_BUFFER_SIZE ( 512 )
70
71// macro to map vos trace levels into the bitmask
72#define VOS_TRACE_LEVEL_TO_MODULE_BITMASK( _level ) ( ( 1 << (_level) ) )
73
74typedef struct
75{
76 // Trace level for a module, as a bitmask. The bits in this mask
77 // are ordered by VOS_TRACE_LEVEL. For example, each bit represents
78 // one of the bits in VOS_TRACE_LEVEL that may be turned on to have
79 // traces at that level logged, i.e. if VOS_TRACE_LEVEL_ERROR is
80 // == 2, then if bit 2 (low order) is turned ON, then ERROR traces
81 // will be printed to the trace log.
82 //
83 // Note that all bits turned OFF means no traces.
84 v_U16_t moduleTraceLevel;
85
86 // 3 character string name for the module
87 unsigned char moduleNameStr[ 4 ]; // 3 chars plus the NULL
88
89} moduleTraceInfo;
90
91#define VOS_DEFAULT_TRACE_LEVEL \
92 ((1<<VOS_TRACE_LEVEL_FATAL)|(1<<VOS_TRACE_LEVEL_ERROR))
93
94// Array of static data that contains all of the per module trace
95// information. This includes the trace level for the module and
96// the 3 character 'name' of the module for marking the trace logs.
97moduleTraceInfo gVosTraceInfo[ VOS_MODULE_ID_MAX ] =
98{
Mohit Khanna23863762012-09-11 17:40:09 -070099 [VOS_MODULE_ID_BAP] = { VOS_DEFAULT_TRACE_LEVEL, "BAP" },
100 [VOS_MODULE_ID_TL] = { VOS_DEFAULT_TRACE_LEVEL, "TL " },
Vinay Krishna Erannad938c422014-03-10 17:14:21 +0530101 [VOS_MODULE_ID_WDI] = { VOS_DEFAULT_TRACE_LEVEL, "WDI" },
Siddharth Bhal7bd19932015-03-03 16:54:36 +0530102 [VOS_MODULE_ID_SVC] = { VOS_DEFAULT_TRACE_LEVEL, "SVC" },
103 [VOS_MODULE_ID_RSV4] = { VOS_DEFAULT_TRACE_LEVEL, "RS4" },
Mohit Khanna23863762012-09-11 17:40:09 -0700104 [VOS_MODULE_ID_HDD] = { VOS_DEFAULT_TRACE_LEVEL, "HDD" },
105 [VOS_MODULE_ID_SME] = { VOS_DEFAULT_TRACE_LEVEL, "SME" },
106 [VOS_MODULE_ID_PE] = { VOS_DEFAULT_TRACE_LEVEL, "PE " },
Mohit Khanna23863762012-09-11 17:40:09 -0700107 [VOS_MODULE_ID_WDA] = { VOS_DEFAULT_TRACE_LEVEL, "WDA" },
Mohit Khanna23863762012-09-11 17:40:09 -0700108 [VOS_MODULE_ID_SYS] = { VOS_DEFAULT_TRACE_LEVEL, "SYS" },
Jeff Johnson295189b2012-06-20 16:38:30 -0700109 [VOS_MODULE_ID_VOSS] = { VOS_DEFAULT_TRACE_LEVEL, "VOS" },
Mohit Khanna23863762012-09-11 17:40:09 -0700110 [VOS_MODULE_ID_SAP] = { VOS_DEFAULT_TRACE_LEVEL, "SAP" },
111 [VOS_MODULE_ID_HDD_SOFTAP] = { VOS_DEFAULT_TRACE_LEVEL, "HSP" },
Katya Nigam70d68332013-09-16 16:49:45 +0530112 [VOS_MODULE_ID_PMC] = { VOS_DEFAULT_TRACE_LEVEL, "PMC" },
c_hpothu32490782014-03-14 19:14:34 +0530113 [VOS_MODULE_ID_HDD_DATA] = { VOS_DEFAULT_TRACE_LEVEL, "HDP" },
c_hpothu6d1d2a32014-03-18 20:17:03 +0530114 [VOS_MODULE_ID_HDD_SAP_DATA] = { VOS_DEFAULT_TRACE_LEVEL, "SDP" },
Jeff Johnson295189b2012-06-20 16:38:30 -0700115};
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700116/*-------------------------------------------------------------------------
117 Static and Global variables
118 ------------------------------------------------------------------------*/
119static spinlock_t ltraceLock;
Jeff Johnson295189b2012-06-20 16:38:30 -0700120
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700121static tvosTraceRecord gvosTraceTbl[MAX_VOS_TRACE_RECORDS];
122// Global vosTraceData
123static tvosTraceData gvosTraceData;
124/*
125 * all the call back functions for dumping MTRACE messages from ring buffer
126 * are stored in vostraceCBTable,these callbacks are initialized during init only
127 * so, we will make a copy of these call back functions and maintain in to
128 * vostraceRestoreCBTable. Incase if we make modifications to vostraceCBTable,
129 * we can certainly retrieve all the call back functions back from Restore Table
130 */
131static tpvosTraceCb vostraceCBTable[VOS_MODULE_ID_MAX];
132static tpvosTraceCb vostraceRestoreCBTable[VOS_MODULE_ID_MAX];
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +0530133static tp_vos_state_info_cb vos_state_info_table[VOS_MODULE_ID_MAX];
134
Jeff Johnson295189b2012-06-20 16:38:30 -0700135/*-------------------------------------------------------------------------
136 Functions
137 ------------------------------------------------------------------------*/
138void vos_trace_setLevel( VOS_MODULE_ID module, VOS_TRACE_LEVEL level )
139{
140 // Make sure the caller is passing in a valid LEVEL.
141 if ( level >= VOS_TRACE_LEVEL_MAX )
142 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700143 pr_err("%s: Invalid trace level %d passed in!\n", __func__, level);
Jeff Johnson295189b2012-06-20 16:38:30 -0700144 return;
145 }
146
147 // Treat 'none' differently. NONE means we have to run off all
148 // the bits in the bit mask so none of the traces appear. Anything other
149 // than 'none' means we need to turn ON a bit in the bitmask.
150 if ( VOS_TRACE_LEVEL_NONE == level )
151 {
152 gVosTraceInfo[ module ].moduleTraceLevel = VOS_TRACE_LEVEL_NONE;
153 }
154 else
155 {
156 // Set the desired bit in the bit mask for the module trace level.
157 gVosTraceInfo[ module ].moduleTraceLevel |= VOS_TRACE_LEVEL_TO_MODULE_BITMASK( level );
158 }
159}
160
161void vos_trace_setValue( VOS_MODULE_ID module, VOS_TRACE_LEVEL level, v_U8_t on)
162{
163 // Make sure the caller is passing in a valid LEVEL.
164 if ( level < 0 || level >= VOS_TRACE_LEVEL_MAX )
165 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700166 pr_err("%s: Invalid trace level %d passed in!\n", __func__, level);
Jeff Johnson295189b2012-06-20 16:38:30 -0700167 return;
168 }
169
170 // Make sure the caller is passing in a valid module.
171 if ( module < 0 || module >= VOS_MODULE_ID_MAX )
172 {
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700173 pr_err("%s: Invalid module id %d passed in!\n", __func__, module);
Jeff Johnson295189b2012-06-20 16:38:30 -0700174 return;
175 }
176
177 // Treat 'none' differently. NONE means we have to turn off all
178 // the bits in the bit mask so none of the traces appear.
179 if ( VOS_TRACE_LEVEL_NONE == level )
180 {
181 gVosTraceInfo[ module ].moduleTraceLevel = VOS_TRACE_LEVEL_NONE;
182 }
183 // Treat 'All' differently. All means we have to turn on all
184 // the bits in the bit mask so all of the traces appear.
185 else if ( VOS_TRACE_LEVEL_ALL == level )
186 {
187 gVosTraceInfo[ module ].moduleTraceLevel = 0xFFFF;
188 }
189
190 else
191 {
192 if (on)
193 // Set the desired bit in the bit mask for the module trace level.
194 gVosTraceInfo[ module ].moduleTraceLevel |= VOS_TRACE_LEVEL_TO_MODULE_BITMASK( level );
195 else
196 // Clear the desired bit in the bit mask for the module trace level.
197 gVosTraceInfo[ module ].moduleTraceLevel &= ~(VOS_TRACE_LEVEL_TO_MODULE_BITMASK( level ));
198 }
199}
200
201
202v_BOOL_t vos_trace_getLevel( VOS_MODULE_ID module, VOS_TRACE_LEVEL level )
203{
204 v_BOOL_t traceOn = VOS_FALSE;
205
206 if ( ( VOS_TRACE_LEVEL_NONE == level ) ||
207 ( VOS_TRACE_LEVEL_ALL == level ) ||
208 ( level >= VOS_TRACE_LEVEL_MAX ) )
209 {
210 traceOn = VOS_FALSE;
211 }
212 else
213 {
214 traceOn = ( level & gVosTraceInfo[ module ].moduleTraceLevel ) ? VOS_TRUE : VOS_FALSE;
215 }
216
217 return( traceOn );
218}
219
220void vos_snprintf(char *strBuffer, unsigned int size, char *strFormat, ...)
221{
222 va_list val;
223
224 va_start( val, strFormat );
225 snprintf (strBuffer, size, strFormat, val);
226 va_end( val );
227}
228
Jeff Johnson295189b2012-06-20 16:38:30 -0700229#ifdef VOS_ENABLE_TRACING
230
231/*----------------------------------------------------------------------------
232
233 \brief vos_trace_msg() - Externally called trace function
234
235 Checks the level of severity and accordingly prints the trace messages
236
237 \param module - module identifier. A member of the VOS_MODULE_ID
238 enumeration that identifies the module issuing the trace message.
239
240 \param level - trace level. A member of the VOS_TRACE_LEVEL
241 enumeration indicating the severity of the condition causing the
242 trace message to be issued. More severe conditions are more
243 likely to be logged.
244
245 \param strFormat - format string. The message to be logged. This format
246 string contains printf-like replacement parameters, which follow
247 this parameter in the variable argument list.
248
249 \return nothing
250
251 \sa
252
253 --------------------------------------------------------------------------*/
254void vos_trace_msg( VOS_MODULE_ID module, VOS_TRACE_LEVEL level, char *strFormat, ... )
255{
256 char strBuffer[VOS_TRACE_BUFFER_SIZE];
257 int n;
258
Gopichand Nakkalaa845f7a2012-12-31 16:14:20 -0800259 // Print the trace message when the desired level bit is set in the module
260 // tracel level mask.
261 if ( gVosTraceInfo[ module ].moduleTraceLevel & VOS_TRACE_LEVEL_TO_MODULE_BITMASK( level ) )
262 {
Madan Mohan Koyyalamudid5fba4a2013-01-16 04:33:09 +0530263 // the trace level strings in an array. these are ordered in the same order
264 // as the trace levels are defined in the enum (see VOS_TRACE_LEVEL) so we
265 // can index into this array with the level and get the right string. The
266 // vos trace levels are...
Varun Reddy Yeturuf68abd62013-02-11 14:05:06 -0800267 // none, Fatal, Error, Warning, Info, InfoHigh, InfoMed, InfoLow, Debug
268 static const char * TRACE_LEVEL_STR[] = { " ", "F ", "E ", "W ", "I ", "IH", "IM", "IL", "D" };
Madan Mohan Koyyalamudid5fba4a2013-01-16 04:33:09 +0530269 va_list val;
270 va_start(val, strFormat);
271
272 // print the prefix string into the string buffer...
Sushant Kaushik96e66942015-09-21 12:43:15 +0530273 n = snprintf(strBuffer, VOS_TRACE_BUFFER_SIZE, "wlan: [%2s:%3s] ",
Madan Mohan Koyyalamudid5fba4a2013-01-16 04:33:09 +0530274 (char *) TRACE_LEVEL_STR[ level ],
275 (char *) gVosTraceInfo[ module ].moduleNameStr );
276
277 // print the formatted log message after the prefix string.
Yue Ma68045742013-04-17 10:48:13 -0700278 if ((n >= 0) && (n < VOS_TRACE_BUFFER_SIZE))
Tushnim Bhattacharyya5dd94562013-03-20 20:15:03 -0700279 {
280 vsnprintf(strBuffer + n, VOS_TRACE_BUFFER_SIZE - n, strFormat, val );
Gopichand Nakkalad0774962013-05-24 11:32:21 +0530281
Vinay Krishna Erannad938c422014-03-10 17:14:21 +0530282#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
283 wlan_log_to_user(level, (char *)strBuffer, strlen(strBuffer));
284#else
Tushnim Bhattacharyya5dd94562013-03-20 20:15:03 -0700285 pr_err("%s\n", strBuffer);
Vinay Krishna Erannad938c422014-03-10 17:14:21 +0530286#endif
Tushnim Bhattacharyya5dd94562013-03-20 20:15:03 -0700287 }
Vinay Krishna Erannafeb893e2014-05-13 13:38:50 +0530288 va_end(val);
Jeff Johnson295189b2012-06-20 16:38:30 -0700289 }
290}
291
292void vos_trace_display(void)
293{
294 VOS_MODULE_ID moduleId;
295
Varun Reddy Yeturuf68abd62013-02-11 14:05:06 -0800296 pr_err(" 1)FATAL 2)ERROR 3)WARN 4)INFO 5)INFO_H 6)INFO_M 7)INFO_L 8)DEBUG\n");
Jeff Johnson295189b2012-06-20 16:38:30 -0700297 for (moduleId = 0; moduleId < VOS_MODULE_ID_MAX; ++moduleId)
298 {
Varun Reddy Yeturuf68abd62013-02-11 14:05:06 -0800299 pr_err("%2d)%s %s %s %s %s %s %s %s %s\n",
Jeff Johnson295189b2012-06-20 16:38:30 -0700300 (int)moduleId,
301 gVosTraceInfo[moduleId].moduleNameStr,
302 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_FATAL)) ? "X":" ",
303 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_ERROR)) ? "X":" ",
304 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_WARN)) ? "X":" ",
305 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_INFO)) ? "X":" ",
306 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_INFO_HIGH)) ? "X":" ",
307 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_INFO_MED)) ? "X":" ",
Varun Reddy Yeturuf68abd62013-02-11 14:05:06 -0800308 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_INFO_LOW)) ? "X":" ",
309 (gVosTraceInfo[moduleId].moduleTraceLevel & (1 << VOS_TRACE_LEVEL_DEBUG)) ? "X":" "
Jeff Johnson295189b2012-06-20 16:38:30 -0700310 );
311 }
312}
313
Madan Mohan Koyyalamudi99af06e2013-08-08 02:17:17 +0530314/*----------------------------------------------------------------------------
315
316 \brief vos_trace_hex_dump() - Externally called hex dump function
317
318 Checks the level of severity and accordingly prints the trace messages
319
320 \param module - module identifier. A member of the VOS_MODULE_ID
321 enumeration that identifies the module issuing the trace message.
322
323 \param level - trace level. A member of the VOS_TRACE_LEVEL
324 enumeration indicating the severity of the condition causing the
325 trace message to be issued. More severe conditions are more
326 likely to be logged.
327
328 \param data - . The base address of the buffer to be logged.
329
330 \param buf_len - . The size of the buffer to be logged.
331
332 \return nothing
333
334 \sa
335 --------------------------------------------------------------------------*/
336void vos_trace_hex_dump( VOS_MODULE_ID module, VOS_TRACE_LEVEL level,
337 void *data, int buf_len )
338{
339 char *buf = (char *)data;
340 int i;
341 for (i=0; (i+7)<buf_len; i+=8)
342 {
343 vos_trace_msg( module, level,
344 "%02x %02x %02x %02x %02x %02x %02x %02x \n",
345 buf[i],
346 buf[i+1],
347 buf[i+2],
348 buf[i+3],
349 buf[i+4],
350 buf[i+5],
351 buf[i+6],
352 buf[i+7]);
353 }
354
355 // Dump the bytes in the last line
356 for (; i < buf_len; i++)
357 {
358 vos_trace_msg( module, level, "%02x ", buf[i]);
359 if ((i+1) == buf_len)
360 vos_trace_msg( module, level, "\n");
361 }
362
363}
364
Jeff Johnson295189b2012-06-20 16:38:30 -0700365#endif
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700366
367/*-----------------------------------------------------------------------------
368 \brief vosTraceEnable() - Enable MTRACE for specific modules whose bits are
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530369 set in bitmask and enable is true. if enable is false it disables MTRACE for
370 that module. set the bitmask according to enum value of the modules.
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700371
372 this functions will be called when you issue ioctl as mentioned following
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530373 [iwpriv wlan0 setdumplog <value> <enable>].
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700374 <value> - Decimal number, i.e. 64 decimal value shows only SME module,
375 128 decimal value shows only PE module, 192 decimal value shows PE and SME.
376
377 \param - bitmask_of_moduleId - as explained above set bitmask according to
378 enum of the modules.
379 32 [dec] = 0010 0000 [bin] <enum of HDD is 5>
380 64 [dec] = 0100 0000 [bin] <enum of SME is 6>
381 128 [dec] = 1000 0000 [bin] <enum of PE is 7>
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530382 \param - enable - can be true or false.
383 True implies enabling MTRACE, false implies disabling MTRACE.
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700384 ---------------------------------------------------------------------------*/
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530385void vosTraceEnable(v_U32_t bitmask_of_moduleId, v_U8_t enable)
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700386{
387 int i;
388 if (bitmask_of_moduleId)
389 {
390 for (i=0; i<VOS_MODULE_ID_MAX; i++)
391 {
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530392 if (((bitmask_of_moduleId >> i) & 1 ))
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700393 {
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530394 if(enable)
395 {
396 if (NULL != vostraceRestoreCBTable[i])
397 {
398 vostraceCBTable[i] = vostraceRestoreCBTable[i];
399 }
400 }
401 else
402 {
403 vostraceRestoreCBTable[i] = vostraceCBTable[i];
404 vostraceCBTable[i] = NULL;
405 }
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700406 }
407 }
408 }
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530409
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700410 else
411 {
Katya Nigamc2f29dc2014-01-20 19:29:30 +0530412 if(enable)
413 {
414 for (i=0; i<VOS_MODULE_ID_MAX; i++)
415 {
416 if (NULL != vostraceRestoreCBTable[i])
417 {
418 vostraceCBTable[i] = vostraceRestoreCBTable[i];
419 }
420 }
421 }
422 else
423 {
424 for (i=0; i<VOS_MODULE_ID_MAX; i++)
425 {
426 vostraceRestoreCBTable[i] = vostraceCBTable[i];
427 vostraceCBTable[i] = NULL;
428 }
429 }
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700430 }
431}
432
433/*-----------------------------------------------------------------------------
434 \brief vosTraceInit() - Initializes vos trace structures and variables.
435
436 Called immediately after vos_preopen, so that we can start recording HDD
437 events ASAP.
438 ----------------------------------------------------------------------------*/
439void vosTraceInit()
440{
441 v_U8_t i;
442 gvosTraceData.head = INVALID_VOS_TRACE_ADDR;
443 gvosTraceData.tail = INVALID_VOS_TRACE_ADDR;
444 gvosTraceData.num = 0;
445 gvosTraceData.enable = TRUE;
446 gvosTraceData.dumpCount = DEFAULT_VOS_TRACE_DUMP_COUNT;
447 gvosTraceData.numSinceLastDump = 0;
448
449 for (i=0; i<VOS_MODULE_ID_MAX; i++)
450 {
451 vostraceCBTable[i] = NULL;
452 vostraceRestoreCBTable[i] = NULL;
453 }
454}
455
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +0530456void vos_register_debugcb_init()
457{
458 v_U8_t i;
459
460 for (i = 0; i < VOS_MODULE_ID_MAX; i++) {
461 vos_state_info_table[i] = NULL;
462 }
463}
464
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700465/*-----------------------------------------------------------------------------
466 \brief vos_trace() - puts the messages in to ring-buffer
467
468 This function will be called from each module who wants record the messages
469 in circular queue. Before calling this functions make sure you have
470 registered your module with voss through vosTraceRegister function.
471
472 \param module - enum of module, basically module id.
473 \param code -
474 \param session -
475 \param data - actual message contents.
476 ----------------------------------------------------------------------------*/
477void vos_trace(v_U8_t module, v_U8_t code, v_U8_t session, v_U32_t data)
478{
479 tpvosTraceRecord rec = NULL;
Pradeep Kumar Goudaguntae96cefb2014-04-02 14:31:34 +0530480 unsigned long flags;
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700481
482
483 if (!gvosTraceData.enable)
484 {
485 return;
486 }
487 //If module is not registered, don't record for that module.
488 if (NULL == vostraceCBTable[module])
489 {
490 return;
491 }
492
493 /* Aquire the lock so that only one thread at a time can fill the ring buffer */
Pradeep Kumar Goudaguntae96cefb2014-04-02 14:31:34 +0530494 spin_lock_irqsave(&ltraceLock, flags);
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700495
496 gvosTraceData.num++;
497
498 if (gvosTraceData.num > MAX_VOS_TRACE_RECORDS)
499 {
500 gvosTraceData.num = MAX_VOS_TRACE_RECORDS;
501 }
502
503 if (INVALID_VOS_TRACE_ADDR == gvosTraceData.head)
504 {
505 /* first record */
506 gvosTraceData.head = 0;
507 gvosTraceData.tail = 0;
508 }
509 else
510 {
511 /* queue is not empty */
512 v_U32_t tail = gvosTraceData.tail + 1;
513
514 if (MAX_VOS_TRACE_RECORDS == tail)
515 {
516 tail = 0;
517 }
518
519 if (gvosTraceData.head == tail)
520 {
521 /* full */
522 if (MAX_VOS_TRACE_RECORDS == ++gvosTraceData.head)
523 {
524 gvosTraceData.head = 0;
525 }
526 }
527
528 gvosTraceData.tail = tail;
529 }
530
531 rec = &gvosTraceTbl[gvosTraceData.tail];
532 rec->code = code;
533 rec->session = session;
534 rec->data = data;
535 rec->time = vos_timer_get_system_time();
536 rec->module = module;
537 gvosTraceData.numSinceLastDump ++;
Pradeep Kumar Goudaguntae96cefb2014-04-02 14:31:34 +0530538 spin_unlock_irqrestore(&ltraceLock, flags);
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700539}
540
541
542/*-----------------------------------------------------------------------------
543 \brief vos_trace_spin_lock_init() - Initializes the lock variable before use
544
545 This function will be called from vos_preOpen, we will have lock available
546 to use ASAP.
547 ----------------------------------------------------------------------------*/
548VOS_STATUS vos_trace_spin_lock_init()
549{
550 spin_lock_init(&ltraceLock);
551
552 return VOS_STATUS_SUCCESS;
553}
554
555/*-----------------------------------------------------------------------------
556 \brief vosTraceRegister() - Registers the call back functions to display the
557 messages in particular format mentioned in these call back functions.
558
559 this functions should be called by interested module in their init part as
560 we will be ready to register as soon as modules are up.
561
562 \param moduleID - enum value of module
563 \param vostraceCb - call back functions to display the messages in particular
564 format.
565 ----------------------------------------------------------------------------*/
566void vosTraceRegister(VOS_MODULE_ID moduleID, tpvosTraceCb vostraceCb)
567{
568 vostraceCBTable[moduleID] = vostraceCb;
569}
570
571/*------------------------------------------------------------------------------
572 \brief vosTraceDumpAll() - Dump data from ring buffer via call back functions
573 registered with VOSS
574
575 This function will be called up on issueing ioctl call as mentioned following
576 [iwpriv wlan0 dumplog 0 0 <n> <bitmask_of_module>]
577
578 <n> - number lines to dump starting from tail to head.
579
580 <bitmask_of_module> - if anybody wants to know how many messages were recorded
581 for particular module/s mentioned by setbit in bitmask from last <n> messages.
582 it is optional, if you don't provide then it will dump everything from buffer.
583
584 \param pMac - context of particular module
585 \param code -
586 \param session -
587 \param count - number of lines to dump starting from tail to head
588 ----------------------------------------------------------------------------*/
589void vosTraceDumpAll(void *pMac, v_U8_t code, v_U8_t session,
590 v_U32_t count, v_U32_t bitmask_of_module)
591{
592 tvosTraceRecord pRecord;
593 tANI_S32 i, tail;
594
595
596 if (!gvosTraceData.enable)
597 {
598 VOS_TRACE( VOS_MODULE_ID_SYS,
599 VOS_TRACE_LEVEL_ERROR, "Tracing Disabled");
600 return;
601 }
602
Abhishek Singhc7d6fbc2015-10-19 12:14:41 +0530603 VOS_TRACE( VOS_MODULE_ID_SYS, VOS_TRACE_LEVEL_INFO,
Leela Venkata Kiran Kumar Reddy Chirala57af2692013-04-10 22:39:51 -0700604 "Total Records: %d, Head: %d, Tail: %d",
605 gvosTraceData.num, gvosTraceData.head, gvosTraceData.tail);
606
607 /* Aquire the lock so that only one thread at a time can read the ring buffer */
608 spin_lock(&ltraceLock);
609
610 if (gvosTraceData.head != INVALID_VOS_TRACE_ADDR)
611 {
612 i = gvosTraceData.head;
613 tail = gvosTraceData.tail;
614
615 if (count)
616 {
617 if (count > gvosTraceData.num)
618 {
619 count = gvosTraceData.num;
620 }
621 if (tail >= (count - 1))
622 {
623 i = tail - count + 1;
624 }
625 else if (count != MAX_VOS_TRACE_RECORDS)
626 {
627 i = MAX_VOS_TRACE_RECORDS - ((count - 1) - tail);
628 }
629 }
630
631 pRecord = gvosTraceTbl[i];
632 /* right now we are not using numSinceLastDump member but in future
633 we might re-visit and use this member to track how many latest
634 messages got added while we were dumping from ring buffer */
635 gvosTraceData.numSinceLastDump = 0;
636 spin_unlock(&ltraceLock);
637 for (;;)
638 {
639 if ((code == 0 || (code == pRecord.code)) &&
640 (vostraceCBTable[pRecord.module] != NULL))
641 {
642 if (0 == bitmask_of_module)
643 {
644 vostraceCBTable[pRecord.module](pMac, &pRecord, (v_U16_t)i);
645 }
646 else
647 {
648 if (bitmask_of_module & (1 << pRecord.module))
649 {
650 vostraceCBTable[pRecord.module](pMac, &pRecord, (v_U16_t)i);
651 }
652 }
653 }
654
655 if (i == tail)
656 {
657 break;
658 }
659 i += 1;
660
661 spin_lock(&ltraceLock);
662 if (MAX_VOS_TRACE_RECORDS == i)
663 {
664 i = 0;
665 pRecord= gvosTraceTbl[0];
666 }
667 else
668 {
669 pRecord = gvosTraceTbl[i];
670 }
671 spin_unlock(&ltraceLock);
672 }
673 }
674 else
675 {
676 spin_unlock(&ltraceLock);
677 }
678}
Padma, Santhosh Kumar9093b202015-07-21 15:37:38 +0530679
680/**
681 * vos_register_debug_callback() - stores callback handlers to print
682 * state information
683 */
684void vos_register_debug_callback(VOS_MODULE_ID moduleID,
685 tp_vos_state_info_cb vos_state_infocb)
686{
687 vos_state_info_table[moduleID] = vos_state_infocb;
688}
689
690/**
691 * vos_state_info_dump_all() - it invokes callback of layer which registered
692 * its callback to print its state information.
693 * @cb_context: call back context to be passed
694 */
695void vos_state_info_dump_all()
696{
697 v_U8_t module;
698
699 for (module = 0; module < VOS_MODULE_ID_MAX; module++) {
700 if (NULL != vos_state_info_table[module])
701 vos_state_info_table[module]();
702 }
703}