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