blob: 3ce58332e1cf30da4a579341f731a1e9fe5f9117 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 *
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/*
Jeff Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
24 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
25 *
26 *
27 * Permission to use, copy, modify, and/or distribute this software for
28 * any purpose with or without fee is hereby granted, provided that the
29 * above copyright notice and this permission notice appear in all
30 * copies.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
33 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
35 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
36 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
40 */
41
42
43
44/**=========================================================================
45
46 \file wlan_qct_pal_trace.c
47
48 \brief Implementation trace/logging APIs PAL exports. wpt = (Wlan Pal Type) wpal = (Wlan PAL)
49
50 Definitions for Linux/Android platform
51
52 Copyright 2010-2011 (c) Qualcomm, Incorporated. All Rights Reserved.
53
54 Qualcomm Confidential and Proprietary.
55
56 ========================================================================*/
57
58#include "wlan_qct_pal_trace.h"
59#include "i_vos_types.h"
60
61#ifdef WLAN_DEBUG
62
63
64/*--------------------------------------------------------------------------
65 Preprocessor definitions and constants
66 ------------------------------------------------------------------------*/
67
68#define WPAL_TRACE_BUFFER_SIZE ( 512 )
69
70// macro to map wpal trace levels into the bitmask
71#define WPAL_TRACE_LEVEL_TO_MODULE_BITMASK( _level ) ( ( 1 << (_level) ) )
72
73typedef struct
74{
75 // Trace level for a module, as a bitmask. The bits in this mask
76 // are ordered by wpt_tracelevel. For example, each bit represents
77 // one of the bits in wpt_tracelevel that may be turned on to have
78 // traces at that level logged, i.e. if eWLAN_PAL_TRACE_LEVEL_ERROR is
79 // == 2, then if bit 2 (low order) is turned ON, then ERROR traces
80 // will be printed to the trace log.
81 //
82 // Note that all bits turned OFF means no traces.
83 wpt_uint16 moduleTraceLevel;
84
85 // 3 character string name for the module
86 wpt_uint8 moduleNameStr[ 4 ]; // 3 chars plus the NULL
87
88} moduleTraceInfo;
89
90
91// Array of static data that contains all of the per module trace
92// information. This includes the trace level for the module and
93// the 3 character 'name' of the module for marking the trace logs.
94moduleTraceInfo gTraceInfo[ eWLAN_MODULE_COUNT ] =
95{
96 { (1<<eWLAN_PAL_TRACE_LEVEL_FATAL)|(1<<eWLAN_PAL_TRACE_LEVEL_ERROR), "DAL" },
Madan Mohan Koyyalamudibf771072012-11-27 18:50:02 +053097 { (1<<eWLAN_PAL_TRACE_LEVEL_FATAL)|(1<<eWLAN_PAL_TRACE_LEVEL_ERROR), "CTL" },
Jeff Johnson295189b2012-06-20 16:38:30 -070098 { (1<<eWLAN_PAL_TRACE_LEVEL_FATAL)|(1<<eWLAN_PAL_TRACE_LEVEL_ERROR), "DAT" },
99 { (1<<eWLAN_PAL_TRACE_LEVEL_FATAL)|(1<<eWLAN_PAL_TRACE_LEVEL_ERROR), "PAL" },
100};
101
102
103// the trace level strings in an array. these are ordered in the same order
104// as the trace levels are defined in the enum (see wpt_tracelevel) so we
105// can index into this array with the level and get the right string. The
106// trace levels are...
107// none, Fatal, Error, Warning, Info, InfoHigh, InfoMed, InfoLow
108static const char * TRACE_LEVEL_STR[] = {
109 " ", "F ", "E ", "W ", "I ", "IH", "IM", "IL" };
110
111
112/*-------------------------------------------------------------------------
113 Functions
114 ------------------------------------------------------------------------*/
115static void wpalOutput(wpt_tracelevel level, char *strBuffer)
116{
117 switch(level)
118 {
119 default:
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700120 printk(KERN_CRIT "%s: Unknown trace level passed in!\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700121 // fall thru and use FATAL
122
123 case eWLAN_PAL_TRACE_LEVEL_FATAL:
124 printk(KERN_CRIT "%s\n", strBuffer);
125 break;
126
127 case eWLAN_PAL_TRACE_LEVEL_ERROR:
128 printk(KERN_ERR "%s\n", strBuffer);
129 break;
130
131 case eWLAN_PAL_TRACE_LEVEL_WARN:
132 printk(KERN_WARNING "%s\n", strBuffer);
133 break;
134
135 case eWLAN_PAL_TRACE_LEVEL_INFO:
136 printk(KERN_INFO "%s\n", strBuffer);
137 break;
138
139 case eWLAN_PAL_TRACE_LEVEL_INFO_HIGH:
140 printk(KERN_NOTICE "%s\n", strBuffer);
141 break;
142
143 case eWLAN_PAL_TRACE_LEVEL_INFO_MED:
144 printk(KERN_NOTICE "%s\n", strBuffer);
145 break;
146
147 case eWLAN_PAL_TRACE_LEVEL_INFO_LOW:
148 printk(KERN_INFO "%s\n", strBuffer);
149 break;
150 }
151}
152
153void wpalTraceSetLevel( wpt_moduleid module, wpt_tracelevel level,
154 wpt_boolean on )
155{
156 // Make sure the caller is passing in a valid LEVEL and MODULE.
157 if ( (eWLAN_PAL_TRACE_LEVEL_COUNT <= level) ||
158 (eWLAN_MODULE_COUNT <= module) )
159 {
160 return;
161 }
162
163 if ( eWLAN_PAL_TRACE_LEVEL_NONE == level )
164 {
165 // Treat 'none' differently. NONE means we have to turn off all
166 // the bits in the bit mask so none of the traces appear.
167 gTraceInfo[ module ].moduleTraceLevel = 0;
168 }
169 else if ( eWLAN_PAL_TRACE_LEVEL_ALL == level )
170 {
171 // Treat 'all' differently. ALL means we have to turn on all
172 // the bits in the bit mask so all of the traces appear.
173 gTraceInfo[ module ].moduleTraceLevel = 0xFFFF;
174 }
175 else
176 {
177 // We are turning a particular trace level on or off
178 if (on)
179 {
180 // Set the desired bit in the bit mask for the module trace level.
181 gTraceInfo[ module ].moduleTraceLevel |=
182 WPAL_TRACE_LEVEL_TO_MODULE_BITMASK( level );
183 }
184 else
185 {
186 // Clear the desired bit in the bit mask for the module trace level.
187 gTraceInfo[ module ].moduleTraceLevel &=
188 ~(WPAL_TRACE_LEVEL_TO_MODULE_BITMASK( level ));
189 }
190 }
191}
192
193wpt_boolean wpalTraceCheckLevel( wpt_moduleid module, wpt_tracelevel level )
194{
195 wpt_boolean traceOn = eWLAN_PAL_FALSE;
196
197 if ( ( eWLAN_PAL_TRACE_LEVEL_NONE == level ) ||
198 ( level >= eWLAN_PAL_TRACE_LEVEL_COUNT ))
199 {
200 traceOn = eWLAN_PAL_FALSE;
201 }
202 else
203 {
204 traceOn = ( level & gTraceInfo[ module ].moduleTraceLevel ) ? eWLAN_PAL_TRUE : eWLAN_PAL_FALSE;
205 }
206
207 return( traceOn );
208}
209
210void wpalTraceDisplay(void)
211{
212 wpt_moduleid moduleId;
213
214 printk(KERN_CRIT
215 " 1)FATAL 2)ERROR 3)WARN 4)INFO "
216 "5)INFO_H 6)INFO_M 7)INFO_L\n");
217 for (moduleId = 0; moduleId < eWLAN_MODULE_COUNT; ++moduleId)
218 {
219 printk(KERN_CRIT
220 "%2d)%s %s %s %s "
221 "%s %s %s %s\n",
222 (int)moduleId,
223 gTraceInfo[moduleId].moduleNameStr,
224 (gTraceInfo[moduleId].moduleTraceLevel &
225 (1 << eWLAN_PAL_TRACE_LEVEL_FATAL)) ? "X":" ",
226 (gTraceInfo[moduleId].moduleTraceLevel &
227 (1 << eWLAN_PAL_TRACE_LEVEL_ERROR)) ? "X":" ",
228 (gTraceInfo[moduleId].moduleTraceLevel &
229 (1 << eWLAN_PAL_TRACE_LEVEL_WARN)) ? "X":" ",
230 (gTraceInfo[moduleId].moduleTraceLevel &
231 (1 << eWLAN_PAL_TRACE_LEVEL_INFO)) ? "X":" ",
232 (gTraceInfo[moduleId].moduleTraceLevel &
233 (1 << eWLAN_PAL_TRACE_LEVEL_INFO_HIGH)) ? "X":" ",
234 (gTraceInfo[moduleId].moduleTraceLevel &
235 (1 << eWLAN_PAL_TRACE_LEVEL_INFO_MED)) ? "X":" ",
236 (gTraceInfo[moduleId].moduleTraceLevel &
237 (1 << eWLAN_PAL_TRACE_LEVEL_INFO_LOW)) ? "X":" "
238 );
239 }
240
241}
242
243/*----------------------------------------------------------------------------
244
245 \brief wpalTrace() - Externally called trace function
246
247 Checks the level of severity and accordingly prints the trace messages
248
249 \param module - module identifier. A member of the wpt_moduleid
250 enumeration that identifies the module issuing the trace message.
251
252 \param level - trace level. A member of the wpt_tracelevel
253 enumeration indicating the severity of the condition causing the
254 trace message to be issued. More severe conditions are more
255 likely to be logged.
256
257 \param strFormat - format string. The message to be logged. This format
258 string contains printf-like replacement parameters, which follow
259 this parameter in the variable argument list.
260
261 \return nothing
262
263 \sa
264
265 --------------------------------------------------------------------------*/
266void wpalTrace( wpt_moduleid module, wpt_tracelevel level, char *strFormat, ... )
267{
268 wpt_uint8 strBuffer[ WPAL_TRACE_BUFFER_SIZE ];
269 int n;
270
271 // Print the trace message when the desired level bit is set in the module
272 // tracel level mask.
273 if ( gTraceInfo[ module ].moduleTraceLevel & WPAL_TRACE_LEVEL_TO_MODULE_BITMASK( level ) )
274 {
275 va_list val;
276 va_start(val, strFormat);
277
278 // print the prefix string into the string buffer...
Ganesh K5079cf52012-12-12 16:31:30 -0800279 n = snprintf(strBuffer, WPAL_TRACE_BUFFER_SIZE, "wlan: [%d:%d:%2s:%3s] ",
Jeff Johnson295189b2012-06-20 16:38:30 -0700280 smp_processor_id(),
281 in_interrupt() ? 0 : current->pid,
282 (char *) TRACE_LEVEL_STR[ level ],
283 (char *) gTraceInfo[ module ].moduleNameStr);
284
285
286 // print the formatted log message after the prefix string.
287 // note we reserve space for the terminating NUL
288 vsnprintf(strBuffer + n, WPAL_TRACE_BUFFER_SIZE - n - 1, strFormat, val);
289 wpalOutput(level, strBuffer);
290 va_end(val);
291 }
292}
293
294/**----------------------------------------------------------------------------
295
296 \brief WPAL_DUMP() / wpalDump() - Trace / logging API
297
298 Users wishing to add tracing memory dumps to their code should use
299 WPAL_DUMP. WPAL_DUMP() will compile into a call to wpalDump() when
300 tracing is enabled.
301
302 \param module - module identifier. A member of the wpt_moduleid
303 enumeration that identifies the module performing the dump
304
305 \param level - trace level. A member of the wpt_tracelevel
306 enumeration indicating the severity of the condition causing the
307 memory to be dumped. More severe conditions are more
308 likely to be logged.
309
310 \param pMemory - memory. A pointer to the memory to be dumped
311
312 \param length - length. How many bytes of memory to be dumped
313
314 \return nothing
315
316 --------------------------------------------------------------------------*/
317// how many bytes do we output per line
318#define BYTES_PER_LINE 16
319
320// each byte takes 2 characters plus a space, plus need room for NUL
321#define CHARS_PER_LINE ((BYTES_PER_LINE * 3) + 1)
322
323void wpalDump( wpt_moduleid module, wpt_tracelevel level,
324 wpt_uint8 *pMemory, wpt_uint32 length)
325{
326 char strBuffer[CHARS_PER_LINE];
327 int n, num, offset;
328
329 // Dump the memory when the desired level bit is set in the module
330 // tracel level mask.
331 if ( gTraceInfo[ module ].moduleTraceLevel & WPAL_TRACE_LEVEL_TO_MODULE_BITMASK( level ) )
332 {
333 num = 0;
334 offset = 0;
335 while (length > 0)
336 {
337 n = snprintf(strBuffer + offset, CHARS_PER_LINE - offset - 1,
338 "%02X ", *pMemory);
339 offset += n;
340 num++;
341 length--;
342 pMemory++;
343 if (BYTES_PER_LINE == num)
344 {
345 wpalOutput(level, strBuffer);
346 num = 0;
347 offset = 0;
348 }
349 }
350
351 if (offset > 0)
352 {
353 // partial line remains
354 wpalOutput(level, strBuffer);
355 }
356 }
357}
358#endif //WLAN_DEBUG