1 /* 2 * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: i_qdf_trace.h 21 * 22 * Linux-specific definitions for QDF trace 23 * 24 */ 25 26 #if !defined(__I_QDF_TRACE_H) 27 #define __I_QDF_TRACE_H 28 29 /* older kernels have a bug in kallsyms, so ensure module.h is included */ 30 #include <linux/module.h> 31 #include <linux/kallsyms.h> 32 #ifdef CONFIG_QCA_MINIDUMP 33 #include <linux/minidump_tlv.h> 34 #endif 35 36 #if !defined(__printf) 37 #define __printf(a, b) 38 #endif 39 40 /* QDF_TRACE is the macro invoked to add trace messages to code. See the 41 * documenation for qdf_trace_msg() for the parameters etc. for this function. 42 * 43 * NOTE: Code QDF_TRACE() macros into the source code. Do not code directly 44 * to the qdf_trace_msg() function. 45 * 46 * NOTE 2: qdf tracing is totally turned off if WLAN_DEBUG is *not* defined. 47 * This allows us to build 'performance' builds where we can measure performance 48 * without being bogged down by all the tracing in the code 49 */ 50 #if defined(QDF_TRACE_PRINT_ENABLE) 51 #define qdf_trace(log_level, args...) \ 52 do { \ 53 extern int qdf_dbg_mask; \ 54 if (qdf_dbg_mask >= log_level) { \ 55 printk(args); \ 56 printk("\n"); \ 57 } \ 58 } while (0) 59 #endif 60 61 #if defined(WLAN_DEBUG) || defined(DEBUG) || defined(QDF_TRACE_PRINT_ENABLE) 62 #define QDF_TRACE qdf_trace_msg 63 #define QDF_VTRACE qdf_vtrace_msg 64 #define QDF_TRACE_HEX_DUMP qdf_trace_hex_dump 65 #else 66 #define QDF_TRACE(arg ...) 67 #define QDF_VTRACE(arg ...) 68 #define QDF_TRACE_HEX_DUMP(arg ...) 69 #endif 70 71 #if defined(WLAN_DEBUG) || defined(DEBUG) || defined(QDF_TRACE_PRINT_ENABLE) 72 #define QDF_MAX_LOGS_PER_SEC 2 73 /** 74 * __QDF_TRACE_RATE_LIMITED() - rate limited version of QDF_TRACE 75 * @params: parameters to pass through to QDF_TRACE 76 * 77 * This API prevents logging a message more than QDF_MAX_LOGS_PER_SEC times per 78 * second. This means any subsequent calls to this API from the same location 79 * within 1/QDF_MAX_LOGS_PER_SEC seconds will be dropped. 80 * 81 * Return: None 82 */ 83 #define __QDF_TRACE_RATE_LIMITED(params...)\ 84 do {\ 85 static ulong __last_ticks;\ 86 ulong __ticks = jiffies;\ 87 if (time_after(__ticks,\ 88 __last_ticks + HZ / QDF_MAX_LOGS_PER_SEC)) {\ 89 QDF_TRACE(params);\ 90 __last_ticks = __ticks;\ 91 } \ 92 } while (0) 93 #else 94 #define __QDF_TRACE_RATE_LIMITED(arg ...) 95 #endif 96 97 #define __QDF_TRACE_NO_FL(log_level, module_id, format, args...) \ 98 QDF_TRACE(module_id, log_level, format, ## args) 99 100 #define __QDF_TRACE_FL(log_level, module_id, format, args...) \ 101 QDF_TRACE(module_id, log_level, FL(format), ## args) 102 103 #define __QDF_TRACE_RL(log_level, module_id, format, args...) \ 104 __QDF_TRACE_RATE_LIMITED(module_id, log_level, FL(format), ## args) 105 106 #define __QDF_TRACE_RL_NO_FL(log_level, module_id, format, args...) \ 107 __QDF_TRACE_RATE_LIMITED(module_id, log_level, format, ## args) 108 109 static inline void __qdf_trace_noop(QDF_MODULE_ID module, char *format, ...) { } 110 111 #ifdef WLAN_LOG_FATAL 112 #define QDF_TRACE_FATAL(params...) \ 113 __QDF_TRACE_FL(QDF_TRACE_LEVEL_FATAL, ## params) 114 #define QDF_TRACE_FATAL_NO_FL(params...) \ 115 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_FATAL, ## params) 116 #define QDF_TRACE_FATAL_RL(params...) \ 117 __QDF_TRACE_RL(QDF_TRACE_LEVEL_FATAL, ## params) 118 #define QDF_TRACE_FATAL_RL_NO_FL(params...) \ 119 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_FATAL, ## params) 120 #else 121 #define QDF_TRACE_FATAL(params...) __qdf_trace_noop(params) 122 #define QDF_TRACE_FATAL_NO_FL(params...) __qdf_trace_noop(params) 123 #define QDF_TRACE_FATAL_RL(params...) __qdf_trace_noop(params) 124 #define QDF_TRACE_FATAL_RL_NO_FL(params...) __qdf_trace_noop(params) 125 #endif 126 127 #ifdef WLAN_LOG_ERROR 128 #define QDF_TRACE_ERROR(params...) \ 129 __QDF_TRACE_FL(QDF_TRACE_LEVEL_ERROR, ## params) 130 #define QDF_TRACE_ERROR_NO_FL(params...) \ 131 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_ERROR, ## params) 132 #define QDF_TRACE_ERROR_RL(params...) \ 133 __QDF_TRACE_RL(QDF_TRACE_LEVEL_ERROR, ## params) 134 #define QDF_TRACE_ERROR_RL_NO_FL(params...) \ 135 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_ERROR, ## params) 136 #else 137 #define QDF_TRACE_ERROR(params...) __qdf_trace_noop(params) 138 #define QDF_TRACE_ERROR_NO_FL(params...) __qdf_trace_noop(params) 139 #define QDF_TRACE_ERROR_RL(params...) __qdf_trace_noop(params) 140 #define QDF_TRACE_ERROR_RL_NO_FL(params...) __qdf_trace_noop(params) 141 #endif 142 143 #ifdef WLAN_LOG_WARN 144 #define QDF_TRACE_WARN(params...) \ 145 __QDF_TRACE_FL(QDF_TRACE_LEVEL_WARN, ## params) 146 #define QDF_TRACE_WARN_NO_FL(params...) \ 147 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_WARN, ## params) 148 #define QDF_TRACE_WARN_RL(params...) \ 149 __QDF_TRACE_RL(QDF_TRACE_LEVEL_WARN, ## params) 150 #define QDF_TRACE_WARN_RL_NO_FL(params...) \ 151 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_WARN, ## params) 152 #else 153 #define QDF_TRACE_WARN(params...) __qdf_trace_noop(params) 154 #define QDF_TRACE_WARN_NO_FL(params...) __qdf_trace_noop(params) 155 #define QDF_TRACE_WARN_RL(params...) __qdf_trace_noop(params) 156 #define QDF_TRACE_WARN_RL_NO_FL(params...) __qdf_trace_noop(params) 157 #endif 158 159 #ifdef WLAN_LOG_INFO 160 #define QDF_TRACE_INFO(params...) \ 161 __QDF_TRACE_FL(QDF_TRACE_LEVEL_INFO, ## params) 162 #define QDF_TRACE_INFO_NO_FL(params...) \ 163 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_INFO, ## params) 164 #define QDF_TRACE_INFO_RL(params...) \ 165 __QDF_TRACE_RL(QDF_TRACE_LEVEL_INFO, ## params) 166 #define QDF_TRACE_INFO_RL_NO_FL(params...) \ 167 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_INFO, ## params) 168 #else 169 #define QDF_TRACE_INFO(params...) __qdf_trace_noop(params) 170 #define QDF_TRACE_INFO_NO_FL(params...) __qdf_trace_noop(params) 171 #define QDF_TRACE_INFO_RL(params...) __qdf_trace_noop(params) 172 #define QDF_TRACE_INFO_RL_NO_FL(params...) __qdf_trace_noop(params) 173 #endif 174 175 #ifdef WLAN_LOG_DEBUG 176 #define QDF_TRACE_DEBUG(params...) \ 177 __QDF_TRACE_FL(QDF_TRACE_LEVEL_DEBUG, ## params) 178 #define QDF_TRACE_DEBUG_NO_FL(params...) \ 179 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_DEBUG, ## params) 180 #define QDF_TRACE_DEBUG_RL(params...) \ 181 __QDF_TRACE_RL(QDF_TRACE_LEVEL_DEBUG, ## params) 182 #define QDF_TRACE_DEBUG_RL_NO_FL(params...) \ 183 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_DEBUG, ## params) 184 #else 185 #define QDF_TRACE_DEBUG(params...) __qdf_trace_noop(params) 186 #define QDF_TRACE_DEBUG_NO_FL(params...) __qdf_trace_noop(params) 187 #define QDF_TRACE_DEBUG_RL(params...) __qdf_trace_noop(params) 188 #define QDF_TRACE_DEBUG_RL_NO_FL(params...) __qdf_trace_noop(params) 189 #endif 190 191 #ifdef WLAN_LOG_ENTER 192 #define QDF_TRACE_ENTER(params...) \ 193 __QDF_TRACE_FL(QDF_TRACE_LEVEL_DEBUG, ## params) 194 #else 195 #define QDF_TRACE_ENTER(params...) __qdf_trace_noop(params) 196 #endif 197 198 #ifdef WLAN_LOG_EXIT 199 #define QDF_TRACE_EXIT(params...) \ 200 __QDF_TRACE_FL(QDF_TRACE_LEVEL_DEBUG, ## params) 201 #else 202 #define QDF_TRACE_EXIT(params...) __qdf_trace_noop(params) 203 #endif 204 205 #define QDF_ENABLE_TRACING 206 #define qdf_scnprintf scnprintf 207 208 #ifdef QDF_ENABLE_TRACING 209 210 #ifdef WLAN_WARN_ON_ASSERT 211 #define QDF_ASSERT(_condition) \ 212 do { \ 213 if (!(_condition)) { \ 214 pr_err("QDF ASSERT in %s Line %d\n", \ 215 __func__, __LINE__); \ 216 WARN_ON(1); \ 217 } \ 218 } while (0) 219 #else 220 #define QDF_ASSERT(_condition) \ 221 do { \ 222 if (!(_condition)) { \ 223 /* no-op */ \ 224 } \ 225 } while (0) 226 #endif /* WLAN_WARN_ON_ASSERT */ 227 /** 228 * qdf_trace_msg()- logging API 229 * @module: Module identifier. A member of the QDF_MODULE_ID enumeration that 230 * identifies the module issuing the trace message. 231 * @level: Trace level. A member of the QDF_TRACE_LEVEL enumeration indicating 232 * the severity of the condition causing the trace message to be issued. 233 * More severe conditions are more likely to be logged. 234 * @str_format: Format string. The message to be logged. This format string 235 * contains printf-like replacement parameters, which follow this 236 * parameter in the variable argument list. 237 * 238 * Users wishing to add tracing information to their code should use 239 * QDF_TRACE. QDF_TRACE() will compile into a call to qdf_trace_msg() when 240 * tracing is enabled. 241 * 242 * Return: nothing 243 * 244 * implemented in qdf_trace.c 245 */ 246 void __printf(3, 4) qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level, 247 const char *str_format, ...); 248 249 /** 250 * qdf_vtrace_msg() - the va_list version of qdf_trace_msg 251 * @module: the calling module's Id 252 * @level: the logging level to log using 253 * @str_format: the log format string 254 * @val: the va_list containing the values to format according to str_format 255 * 256 * Return: None 257 */ 258 void qdf_vtrace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level, 259 const char *str_format, va_list val); 260 261 #else 262 263 /* This code will be used for compilation if tracing is to be compiled out */ 264 /* of the code so these functions/macros are 'do nothing' */ 265 static inline void qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level, 266 const char *str_format, ...) 267 { 268 } 269 270 #define QDF_ASSERT(_condition) 271 272 #endif 273 274 #ifdef PANIC_ON_BUG 275 #ifdef CONFIG_SLUB_DEBUG 276 /** 277 * __qdf_bug() - Calls BUG() when the PANIC_ON_BUG compilation option is enabled 278 * 279 * Note: Calling BUG() can cause a compiler to assume any following code is 280 * unreachable. Because these BUG's may or may not be enabled by the build 281 * configuration, this can cause developers some pain. Consider: 282 * 283 * bool bit; 284 * 285 * if (ptr) 286 * bit = ptr->returns_bool(); 287 * else 288 * __qdf_bug(); 289 * 290 * // do stuff with @bit 291 * 292 * return bit; 293 * 294 * In this case, @bit is potentially uninitialized when we return! However, the 295 * compiler can correctly assume this case is impossible when PANIC_ON_BUG is 296 * enabled. Because developers typically enable this feature, the "maybe 297 * uninitialized" warning will not be emitted, and the bug remains uncaught 298 * until someone tries to make a build without PANIC_ON_BUG. 299 * 300 * A simple workaround for this, is to put the definition of __qdf_bug in 301 * another compilation unit, which prevents the compiler from assuming 302 * subsequent code is unreachable. For CONFIG_SLUB_DEBUG, do this to catch more 303 * bugs. Otherwise, use the typical inlined approach. 304 * 305 * Return: None 306 */ 307 void __qdf_bug(void); 308 #else /* CONFIG_SLUB_DEBUG */ 309 static inline void __qdf_bug(void) 310 { 311 BUG(); 312 } 313 #endif /* CONFIG_SLUB_DEBUG */ 314 315 /** 316 * QDF_DEBUG_PANIC() - In debug builds, panic, otherwise do nothing 317 * @reason_fmt: a format string containing the reason for the panic 318 * @args: zero or more printf compatible logging arguments 319 * 320 * Return: None 321 */ 322 #define QDF_DEBUG_PANIC(reason_fmt, args...) \ 323 QDF_DEBUG_PANIC_FL(__func__, __LINE__, reason_fmt, ## args) 324 325 /** 326 * QDF_DEBUG_PANIC_FL() - In debug builds, panic, otherwise do nothing 327 * @func: origin function name to be logged 328 * @line: origin line number to be logged 329 * @fmt: printf compatible format string to be logged 330 * @args: zero or more printf compatible logging arguments 331 * 332 * Return: None 333 */ 334 #define QDF_DEBUG_PANIC_FL(func, line, fmt, args...) \ 335 do { \ 336 pr_err("WLAN Panic @ %s:%d: " fmt "\n", func, line, ##args); \ 337 __qdf_bug(); \ 338 } while (false) 339 340 #define QDF_BUG(_condition) \ 341 do { \ 342 if (!(_condition)) { \ 343 pr_err("QDF BUG in %s Line %d: Failed assertion '" \ 344 #_condition "'\n", __func__, __LINE__); \ 345 __qdf_bug(); \ 346 } \ 347 } while (0) 348 349 #else /* PANIC_ON_BUG */ 350 351 #define QDF_DEBUG_PANIC(reason...) \ 352 do { \ 353 /* no-op */ \ 354 } while (false) 355 356 #define QDF_DEBUG_PANIC_FL(func, line, fmt, args...) \ 357 do { \ 358 /* no-op */ \ 359 } while (false) 360 361 #define QDF_BUG(_condition) \ 362 do { \ 363 if (!(_condition)) { \ 364 /* no-op */ \ 365 } \ 366 } while (0) 367 368 #endif /* PANIC_ON_BUG */ 369 370 #ifdef KSYM_SYMBOL_LEN 371 #define __QDF_SYMBOL_LEN KSYM_SYMBOL_LEN 372 #else 373 #define __QDF_SYMBOL_LEN 1 374 #endif 375 376 #ifdef CONFIG_QCA_MINIDUMP 377 static inline void 378 __qdf_minidump_log(void *start_addr, size_t size, const char *name) 379 { 380 if (fill_minidump_segments((uintptr_t)start_addr, size, 381 QCA_WDT_LOG_DUMP_TYPE_WLAN_MOD, (char *)name) < 0) 382 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO, 383 "%s: failed to log %pK (%s)\n", 384 __func__, start_addr, name); 385 } 386 387 static inline void 388 __qdf_minidump_remove(void *addr) 389 { 390 remove_minidump_segments((uintptr_t)addr); 391 } 392 #else 393 static inline void 394 __qdf_minidump_log(void *start_addr, size_t size, const char *name) {} 395 static inline void 396 __qdf_minidump_remove(void *addr) {} 397 #endif 398 #endif /* __I_QDF_TRACE_H */ 399