1 /*
2 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 /**
21 * DOC: i_qdf_trace.h
22 *
23 * Linux-specific definitions for QDF trace
24 *
25 */
26
27 #if !defined(__I_QDF_TRACE_H)
28 #define __I_QDF_TRACE_H
29
30 /* older kernels have a bug in kallsyms, so ensure module.h is included */
31 #include <linux/module.h>
32 #include <linux/kallsyms.h>
33 #ifdef CONFIG_QCA_MINIDUMP
34 #include <linux/minidump_tlv.h>
35 #endif
36
37 /*
38 * The CONFIG_QCOM_MINIDUMP feature can only be used
39 * beginning with kernel version msm-4.19 since that is
40 * when msm_minidump_removerefion() was added.
41 */
42 #if IS_ENABLED(CONFIG_QCOM_MINIDUMP) && \
43 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
44 #if IS_ENABLED(CONFIG_QCOM_VA_MINIDUMP)
45 #define WLAN_QCOM_VA_MINIDUMP
46 #else
47 #define WLAN_QCOM_MINIDUMP
48 #endif
49
50 #include <soc/qcom/minidump.h>
51 #endif
52
53 #if !defined(__printf)
54 #define __printf(a, b)
55 #endif
56
57 /* QDF_TRACE is the macro invoked to add trace messages to code. See the
58 * documentation for qdf_trace_msg() for the parameters etc. for this function.
59 *
60 * NOTE: Code QDF_TRACE() macros into the source code. Do not code directly
61 * to the qdf_trace_msg() function.
62 *
63 * NOTE 2: qdf tracing is totally turned off if WLAN_DEBUG is *not* defined.
64 * This allows us to build 'performance' builds where we can measure performance
65 * without being bogged down by all the tracing in the code
66 */
67 #if defined(QDF_TRACE_PRINT_ENABLE)
68 #define qdf_trace(log_level, args...) \
69 do { \
70 extern int qdf_dbg_mask; \
71 if (qdf_dbg_mask >= log_level) { \
72 printk(args); \
73 printk("\n"); \
74 } \
75 } while (0)
76 #endif
77
78 #if defined(WLAN_DEBUG) || defined(DEBUG) || defined(QDF_TRACE_PRINT_ENABLE)
79 #define QDF_TRACE qdf_trace_msg
80 #define QDF_VTRACE qdf_vtrace_msg
81 #define QDF_TRACE_HEX_DUMP qdf_trace_hex_dump
82 #else
83 #define QDF_TRACE(arg ...) __qdf_trace_dummy(arg)
84 #define QDF_VTRACE(arg ...) __qdf_vtrace_dummy(arg)
85 #define QDF_TRACE_HEX_DUMP(arg ...) __qdf_trace_hexdump_dummy(arg)
86 #endif
87
88 #if defined(WLAN_DEBUG) || defined(DEBUG) || defined(QDF_TRACE_PRINT_ENABLE)
89 #define QDF_MAX_LOGS_PER_SEC 2
90 /**
91 * __QDF_TRACE_RATE_LIMITED() - rate limited version of QDF_TRACE
92 * @params: parameters to pass through to QDF_TRACE
93 *
94 * This API prevents logging a message more than QDF_MAX_LOGS_PER_SEC times per
95 * second. This means any subsequent calls to this API from the same location
96 * within 1/QDF_MAX_LOGS_PER_SEC seconds will be dropped.
97 *
98 * Return: return rate_limted as below:
99 * true if the logging message is bypassed
100 * false if the logging message is printed out
101 */
102 #define __QDF_TRACE_RATE_LIMITED(params...)\
103 ({\
104 static ulong __last_ticks;\
105 ulong __ticks = jiffies;\
106 bool rate_limited = true;\
107 if (time_after(__ticks,\
108 __last_ticks + HZ / QDF_MAX_LOGS_PER_SEC)) {\
109 QDF_TRACE(params);\
110 __last_ticks = __ticks;\
111 rate_limited = false;\
112 } \
113 rate_limited;\
114 })
115
116 #define __QDF_TRACE_HEX_DUMP_RATE_LIMITED(params...)\
117 do {\
118 static ulong __last_ticks;\
119 ulong __ticks = jiffies;\
120 if (time_after(__ticks,\
121 __last_ticks + HZ / QDF_MAX_LOGS_PER_SEC)) {\
122 QDF_TRACE_HEX_DUMP(params);\
123 __last_ticks = __ticks;\
124 } \
125 } while (0)
126 #else
127 #define __QDF_TRACE_RATE_LIMITED(arg ...) ({true; })
128 #define __QDF_TRACE_HEX_DUMP_RATE_LIMITED(arg ...)
129 #endif
130
131 #define __QDF_TRACE_NO_FL(log_level, module_id, format, args...) \
132 QDF_TRACE(module_id, log_level, format, ## args)
133
134 #define __QDF_TRACE_FL(log_level, module_id, format, args...) \
135 QDF_TRACE(module_id, log_level, FL(format), ## args)
136
137 #define __QDF_TRACE_RL(log_level, module_id, format, args...) \
138 __QDF_TRACE_RATE_LIMITED(module_id, log_level, FL(format), ## args)
139
140 #define __QDF_TRACE_RL_NO_FL(log_level, module_id, format, args...) \
141 __QDF_TRACE_RATE_LIMITED(module_id, log_level, format, ## args)
142
143 #define __QDF_TRACE_HEX_DUMP_RL(log_level, module_id, args...) \
144 __QDF_TRACE_HEX_DUMP_RATE_LIMITED(module_id, log_level, ## args)
145
__qdf_trace_noop(QDF_MODULE_ID module,const char * format,...)146 static inline void __qdf_trace_noop(QDF_MODULE_ID module,
147 const char *format, ...) { }
__qdf_trace_noop_ret(QDF_MODULE_ID module,const char * format,...)148 static inline bool __qdf_trace_noop_ret(QDF_MODULE_ID module,
149 const char *format, ...) {return true; }
__qdf_trace_dummy(QDF_MODULE_ID module,QDF_TRACE_LEVEL level,const char * format,...)150 static inline void __qdf_trace_dummy(QDF_MODULE_ID module,
151 QDF_TRACE_LEVEL level,
152 const char *format, ...) { }
__qdf_vtrace_dummy(QDF_MODULE_ID module,QDF_TRACE_LEVEL level,const char * str_format,va_list val)153 static inline void __qdf_vtrace_dummy(QDF_MODULE_ID module,
154 QDF_TRACE_LEVEL level,
155 const char *str_format, va_list val) { }
__qdf_trace_hexdump_dummy(QDF_MODULE_ID module,QDF_TRACE_LEVEL level,void * data,int buf_len)156 static inline void __qdf_trace_hexdump_dummy(QDF_MODULE_ID module,
157 QDF_TRACE_LEVEL level,
158 void *data, int buf_len) { }
159
160
161 #ifdef WLAN_LOG_FATAL
162 #define QDF_TRACE_FATAL(params...) \
163 __QDF_TRACE_FL(QDF_TRACE_LEVEL_FATAL, ## params)
164 #define QDF_TRACE_FATAL_NO_FL(params...) \
165 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_FATAL, ## params)
166 #define QDF_TRACE_FATAL_RL(params...) \
167 __QDF_TRACE_RL(QDF_TRACE_LEVEL_FATAL, ## params)
168 #define QDF_TRACE_FATAL_RL_NO_FL(params...) \
169 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_FATAL, ## params)
170 #define QDF_VTRACE_FATAL(module_id, fmt, args) \
171 QDF_VTRACE(module_id, QDF_TRACE_LEVEL_FATAL, fmt, args)
172 #define QDF_TRACE_HEX_DUMP_FATAL_RL(params...) \
173 __QDF_TRACE_HEX_DUMP_RL(QDF_TRACE_LEVEL_FATAL, ## params)
174 #else
175 #define QDF_TRACE_FATAL(params...) __qdf_trace_noop(params)
176 #define QDF_TRACE_FATAL_NO_FL(params...) __qdf_trace_noop(params)
177 #define QDF_TRACE_FATAL_RL(params...) __qdf_trace_noop_ret(params)
178 #define QDF_TRACE_FATAL_RL_NO_FL(params...) __qdf_trace_noop_ret(params)
179 #define QDF_VTRACE_FATAL(params...) __qdf_trace_noop(params)
180 #define QDF_TRACE_HEX_DUMP_FATAL_RL(params...) __qdf_trace_noop(params)
181 #endif
182
183 #ifdef WLAN_LOG_ERROR
184 #define QDF_TRACE_ERROR(params...) \
185 __QDF_TRACE_FL(QDF_TRACE_LEVEL_ERROR, ## params)
186 #define QDF_TRACE_ERROR_NO_FL(params...) \
187 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_ERROR, ## params)
188 #define QDF_TRACE_ERROR_RL(params...) \
189 __QDF_TRACE_RL(QDF_TRACE_LEVEL_ERROR, ## params)
190 #define QDF_TRACE_ERROR_RL_NO_FL(params...) \
191 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_ERROR, ## params)
192 #define QDF_VTRACE_ERROR(module_id, fmt, args) \
193 QDF_VTRACE(module_id, QDF_TRACE_LEVEL_ERROR, fmt, args)
194 #define QDF_TRACE_HEX_DUMP_ERROR_RL(params...) \
195 __QDF_TRACE_HEX_DUMP_RL(QDF_TRACE_LEVEL_ERROR, ## params)
196 #else
197 #define QDF_TRACE_ERROR(params...) __qdf_trace_noop(params)
198 #define QDF_TRACE_ERROR_NO_FL(params...) __qdf_trace_noop(params)
199 #define QDF_TRACE_ERROR_RL(params...) __qdf_trace_noop_ret(params)
200 #define QDF_TRACE_ERROR_RL_NO_FL(params...) __qdf_trace_noop_ret(params)
201 #define QDF_VTRACE_ERROR(params...) __qdf_trace_noop(params)
202 #define QDF_TRACE_HEX_DUMP_ERROR_RL(params...) __qdf_trace_noop(params)
203 #endif
204
205 #ifdef WLAN_LOG_WARN
206 #define QDF_TRACE_WARN(params...) \
207 __QDF_TRACE_FL(QDF_TRACE_LEVEL_WARN, ## params)
208 #define QDF_TRACE_WARN_NO_FL(params...) \
209 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_WARN, ## params)
210 #define QDF_TRACE_WARN_RL(params...) \
211 __QDF_TRACE_RL(QDF_TRACE_LEVEL_WARN, ## params)
212 #define QDF_TRACE_WARN_RL_NO_FL(params...) \
213 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_WARN, ## params)
214 #define QDF_VTRACE_WARN(module_id, fmt, args) \
215 QDF_VTRACE(module_id, QDF_TRACE_LEVEL_WARN, fmt, args)
216 #define QDF_TRACE_HEX_DUMP_WARN_RL(params...) \
217 __QDF_TRACE_HEX_DUMP_RL(QDF_TRACE_LEVEL_WARN, ## params)
218 #else
219 #define QDF_TRACE_WARN(params...) __qdf_trace_noop(params)
220 #define QDF_TRACE_WARN_NO_FL(params...) __qdf_trace_noop(params)
221 #define QDF_TRACE_WARN_RL(params...) __qdf_trace_noop_ret(params)
222 #define QDF_TRACE_WARN_RL_NO_FL(params...) __qdf_trace_noop_ret(params)
223 #define QDF_VTRACE_WARN(params...) __qdf_trace_noop(params)
224 #define QDF_TRACE_HEX_DUMP_WARN_RL(params...) __qdf_trace_noop(params)
225 #endif
226
227 #ifdef WLAN_LOG_INFO
228 #define QDF_TRACE_INFO(params...) \
229 __QDF_TRACE_FL(QDF_TRACE_LEVEL_INFO, ## params)
230 #define QDF_TRACE_INFO_NO_FL(params...) \
231 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_INFO, ## params)
232 #define QDF_TRACE_INFO_HIGH_NO_FL(params...) \
233 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_INFO_HIGH, ## params)
234 #define QDF_TRACE_INFO_RL(params...) \
235 __QDF_TRACE_RL(QDF_TRACE_LEVEL_INFO, ## params)
236 #define QDF_TRACE_INFO_RL_NO_FL(params...) \
237 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_INFO, ## params)
238 #define QDF_VTRACE_INFO(module_id, fmt, args) \
239 QDF_VTRACE(module_id, QDF_TRACE_LEVEL_INFO, fmt, args)
240 #define QDF_TRACE_HEX_DUMP_INFO_RL(params...) \
241 __QDF_TRACE_HEX_DUMP_RL(QDF_TRACE_LEVEL_INFO, ## params)
242 #else
243 #define QDF_TRACE_INFO(params...) __qdf_trace_noop(params)
244 #define QDF_TRACE_INFO_NO_FL(params...) __qdf_trace_noop(params)
245 #define QDF_TRACE_INFO_HIGH_NO_FL(params...) __qdf_trace_noop(params)
246 #define QDF_TRACE_INFO_RL(params...) __qdf_trace_noop_ret(params)
247 #define QDF_TRACE_INFO_RL_NO_FL(params...) __qdf_trace_noop_ret(params)
248 #define QDF_VTRACE_INFO(params...) __qdf_trace_noop(params)
249 #define QDF_TRACE_HEX_DUMP_INFO_RL(params...) __qdf_trace_noop(params)
250 #endif
251
252 #ifdef WLAN_LOG_DEBUG
253 #define QDF_TRACE_DEBUG(params...) \
254 __QDF_TRACE_FL(QDF_TRACE_LEVEL_DEBUG, ## params)
255 #define QDF_TRACE_DEBUG_NO_FL(params...) \
256 __QDF_TRACE_NO_FL(QDF_TRACE_LEVEL_DEBUG, ## params)
257 #define QDF_TRACE_DEBUG_RL(params...) \
258 __QDF_TRACE_RL(QDF_TRACE_LEVEL_DEBUG, ## params)
259 #define QDF_TRACE_DEBUG_RL_NO_FL(params...) \
260 __QDF_TRACE_RL_NO_FL(QDF_TRACE_LEVEL_DEBUG, ## params)
261 #define QDF_VTRACE_DEBUG(module_id, fmt, args) \
262 QDF_VTRACE(module_id, QDF_TRACE_LEVEL_DEBUG, fmt, args)
263 #define QDF_TRACE_HEX_DUMP_DEBUG_RL(params...) \
264 __QDF_TRACE_HEX_DUMP_RL(QDF_TRACE_LEVEL_DEBUG, ## params)
265 #else
266 #define QDF_TRACE_DEBUG(params...) __qdf_trace_noop(params)
267 #define QDF_TRACE_DEBUG_NO_FL(params...) __qdf_trace_noop(params)
268 #define QDF_TRACE_DEBUG_RL(params...) __qdf_trace_noop_ret(params)
269 #define QDF_TRACE_DEBUG_RL_NO_FL(params...) __qdf_trace_noop_ret(params)
270 #define QDF_VTRACE_DEBUG(params...) __qdf_trace_noop(params)
271 #define QDF_TRACE_HEX_DUMP_DEBUG_RL(params...) __qdf_trace_noop(params)
272 #endif
273
274 #ifdef WLAN_LOG_ENTER
275 #define QDF_TRACE_ENTER(params...) \
276 __QDF_TRACE_FL(QDF_TRACE_LEVEL_DEBUG, ## params)
277 #else
278 #define QDF_TRACE_ENTER(params...) __qdf_trace_noop(params)
279 #endif
280
281 #ifdef WLAN_LOG_EXIT
282 #define QDF_TRACE_EXIT(params...) \
283 __QDF_TRACE_FL(QDF_TRACE_LEVEL_DEBUG, ## params)
284 #else
285 #define QDF_TRACE_EXIT(params...) __qdf_trace_noop(params)
286 #endif
287
288 #define QDF_ENABLE_TRACING
289 #define qdf_scnprintf scnprintf
290
291 #ifdef QDF_ENABLE_TRACING
292
293 #ifdef WLAN_WARN_ON_ASSERT
294 #define QDF_ASSERT(_condition) \
295 do { \
296 if (!(_condition)) { \
297 pr_err("QDF ASSERT in %s Line %d\n", \
298 __func__, __LINE__); \
299 WARN_ON(1); \
300 } \
301 } while (0)
302 #else
303 #define QDF_ASSERT(_condition) \
304 do { \
305 if (!(_condition)) { \
306 /* no-op */ \
307 } \
308 } while (0)
309 #endif /* WLAN_WARN_ON_ASSERT */
310
311 /**
312 * qdf_trace_msg()- logging API
313 * @module: Module identifier. A member of the QDF_MODULE_ID enumeration that
314 * identifies the module issuing the trace message.
315 * @level: Trace level. A member of the QDF_TRACE_LEVEL enumeration indicating
316 * the severity of the condition causing the trace message to be issued.
317 * More severe conditions are more likely to be logged.
318 * @str_format: Format string. The message to be logged. This format string
319 * contains printf-like replacement parameters, which follow this
320 * parameter in the variable argument list.
321 *
322 * Users wishing to add tracing information to their code should use
323 * QDF_TRACE. QDF_TRACE() will compile into a call to qdf_trace_msg() when
324 * tracing is enabled.
325 *
326 * Return: nothing
327 */
328 void __printf(3, 4) qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
329 const char *str_format, ...);
330
331 /**
332 * qdf_vtrace_msg() - the va_list version of qdf_trace_msg
333 * @module: the calling module's Id
334 * @level: the logging level to log using
335 * @str_format: the log format string
336 * @val: the va_list containing the values to format according to str_format
337 *
338 * Return: None
339 */
340 void qdf_vtrace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
341 const char *str_format, va_list val);
342
343 #else
344
345 /* This code will be used for compilation if tracing is to be compiled out */
346 /* of the code so these functions/macros are 'do nothing' */
qdf_trace_msg(QDF_MODULE_ID module,QDF_TRACE_LEVEL level,const char * str_format,...)347 static inline void qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
348 const char *str_format, ...)
349 {
350 }
351
352 #define QDF_ASSERT(_condition)
353
354 #endif
355
356 #ifdef QDF_TRACE_PRINT_ENABLE
qdf_vprint(const char * fmt,va_list args)357 static inline void qdf_vprint(const char *fmt, va_list args)
358 {
359 QDF_VTRACE_INFO(QDF_MODULE_ID_ANY, fmt, args);
360 }
361 #else /* QDF_TRACE_PRINT_ENABLE */
qdf_vprint(const char * fmt,va_list args)362 static inline void qdf_vprint(const char *fmt, va_list args)
363 {
364 QDF_VTRACE_ERROR(QDF_MODULE_ID_QDF, fmt, args);
365 }
366 #endif
367
368 #ifdef PANIC_ON_BUG
369 #ifdef CONFIG_SLUB_DEBUG
370 /**
371 * __qdf_bug() - Calls BUG() when the PANIC_ON_BUG compilation option is enabled
372 *
373 * Note: Calling BUG() can cause a compiler to assume any following code is
374 * unreachable. Because these BUG's may or may not be enabled by the build
375 * configuration, this can cause developers some pain. Consider:
376 *
377 * bool bit;
378 *
379 * if (ptr)
380 * bit = ptr->returns_bool();
381 * else
382 * __qdf_bug();
383 *
384 * // do stuff with @bit
385 *
386 * return bit;
387 *
388 * In this case, @bit is potentially uninitialized when we return! However, the
389 * compiler can correctly assume this case is impossible when PANIC_ON_BUG is
390 * enabled. Because developers typically enable this feature, the "maybe
391 * uninitialized" warning will not be emitted, and the bug remains uncaught
392 * until someone tries to make a build without PANIC_ON_BUG.
393 *
394 * A simple workaround for this, is to put the definition of __qdf_bug in
395 * another compilation unit, which prevents the compiler from assuming
396 * subsequent code is unreachable. For CONFIG_SLUB_DEBUG, do this to catch more
397 * bugs. Otherwise, use the typical inlined approach.
398 *
399 * Return: None
400 */
401 void __qdf_bug(void);
402 #else /* CONFIG_SLUB_DEBUG */
__qdf_bug(void)403 static inline void __qdf_bug(void)
404 {
405 BUG();
406 }
407 #endif /* CONFIG_SLUB_DEBUG */
408
409 /**
410 * QDF_DEBUG_PANIC() - In debug builds, panic, otherwise do nothing
411 * @reason_fmt: a format string containing the reason for the panic
412 * @args: zero or more printf compatible logging arguments
413 *
414 * Return: None
415 */
416 #define QDF_DEBUG_PANIC(reason_fmt, args...) \
417 QDF_DEBUG_PANIC_FL(__func__, __LINE__, reason_fmt, ## args)
418
419 /**
420 * QDF_DEBUG_PANIC_FL() - In debug builds, panic, otherwise do nothing
421 * @func: origin function name to be logged
422 * @line: origin line number to be logged
423 * @fmt: printf compatible format string to be logged
424 * @args: zero or more printf compatible logging arguments
425 *
426 * Return: None
427 */
428 #define QDF_DEBUG_PANIC_FL(func, line, fmt, args...) \
429 do { \
430 pr_err("WLAN Panic @ %s:%d: " fmt "\n", func, line, ##args); \
431 __qdf_bug(); \
432 } while (false)
433
434 #define QDF_BUG(_condition) \
435 do { \
436 if (!(_condition)) { \
437 pr_err("QDF BUG in %s Line %d: Failed assertion '" \
438 #_condition "'\n", __func__, __LINE__); \
439 __qdf_bug(); \
440 } \
441 } while (0)
442
443 #define QDF_BUG_ON_ASSERT(_condition) \
444 do { \
445 if (!(_condition)) { \
446 __qdf_bug(); \
447 } \
448 } while (0)
449
450 #else /* PANIC_ON_BUG */
451
452 #define QDF_DEBUG_PANIC(reason...) \
453 do { \
454 /* no-op */ \
455 } while (false)
456
457 #define QDF_DEBUG_PANIC_FL(func, line, fmt, args...) \
458 do { \
459 /* no-op */ \
460 } while (false)
461
462 #define QDF_BUG(_condition) \
463 do { \
464 if (!(_condition)) { \
465 /* no-op */ \
466 } \
467 } while (0)
468
469 #define QDF_BUG_ON_ASSERT(_condition) \
470 do { \
471 if (!(_condition)) { \
472 /* no-op */ \
473 } \
474 } while (0)
475
476 #endif /* PANIC_ON_BUG */
477
478 #ifdef KSYM_SYMBOL_LEN
479 #define __QDF_SYMBOL_LEN KSYM_SYMBOL_LEN
480 #else
481 #define __QDF_SYMBOL_LEN 1
482 #endif
483
484 #ifdef CONFIG_QCA_MINIDUMP
485 static inline void
__qdf_minidump_init(void)486 __qdf_minidump_init(void)
487 {
488 }
489
490 static inline void
__qdf_minidump_deinit(void)491 __qdf_minidump_deinit(void)
492 {
493 }
494
495 static inline void
__qdf_minidump_log(void * start_addr,size_t size,const char * name)496 __qdf_minidump_log(void *start_addr, size_t size, const char *name)
497 {
498 if (minidump_fill_segments((const uintptr_t)start_addr, size,
499 QCA_WDT_LOG_DUMP_TYPE_WLAN_MOD,
500 name) < 0)
501 QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_INFO,
502 "%s: failed to log %pK (%s)\n",
503 __func__, start_addr, name);
504 }
505
506 static inline void
__qdf_minidump_remove(void * addr,size_t size,const char * name)507 __qdf_minidump_remove(void *addr, size_t size, const char *name)
508 {
509 minidump_remove_segments((const uintptr_t)addr);
510 }
511
512 #elif defined(WLAN_QCOM_MINIDUMP)
513 #define MAX_WLAN_MINIDUMP_ENTRIES 5
514
515 enum minidump_log_type {
516 MD_HTC_CREDIT = 0,
517 MD_WLAN_LOGS,
518 MD_WMI_TX_CMP,
519 MD_HAL_SOC,
520 MD_GWLAN_LOGS,
521 };
522
523 static const char *minidump_table[MAX_WLAN_MINIDUMP_ENTRIES];
524
qdf_get_name_idx(const char * name)525 static int qdf_get_name_idx(const char *name)
526 {
527 int i;
528 static const char * const wlan_str[] = {
529 [MD_HTC_CREDIT] = "htc_credit",
530 [MD_WLAN_LOGS] = "wlan_logs",
531 [MD_WMI_TX_CMP] = "wmi_tx_cmp",
532 [MD_HAL_SOC] = "hal_soc",
533 [MD_GWLAN_LOGS] = "gwlan_logging"
534 };
535
536 for (i = 0; i < ARRAY_SIZE(wlan_str); i++) {
537 if (strncmp(name, wlan_str[i], strlen(wlan_str[i])) == 0)
538 return i;
539 }
540
541 return -EINVAL;
542 }
543
544 static inline void
__qdf_minidump_log(void * start_addr,const size_t size,const char * name)545 __qdf_minidump_log(void *start_addr, const size_t size,
546 const char *name)
547 {
548 struct md_region md_entry;
549 int ret, index;
550
551 index = qdf_get_name_idx(name);
552 if (index < 0) {
553 QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_QDF,
554 "%s: invalid entry %s\n",
555 __func__, name);
556 QDF_DEBUG_PANIC("Unknown minidump entry");
557 return;
558 }
559 snprintf(md_entry.name, sizeof(md_entry.name), name);
560 md_entry.virt_addr = (uintptr_t)start_addr;
561 md_entry.phys_addr = virt_to_phys(start_addr);
562 md_entry.size = size;
563 ret = msm_minidump_add_region(&md_entry);
564 if (ret < 0) {
565 QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_QDF,
566 "%s: failed to log %pK (%s)\n",
567 __func__, start_addr, name);
568 minidump_table[index] = NULL;
569 } else {
570 minidump_table[index] = name;
571 }
572 }
573
574 static inline void
__qdf_minidump_remove(void * start_addr,const size_t size,const char * name)575 __qdf_minidump_remove(void *start_addr, const size_t size,
576 const char *name)
577 {
578 struct md_region md_entry;
579 int index;
580
581 index = qdf_get_name_idx(name);
582 if (index < 0 || !minidump_table[index]) {
583 QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_QDF,
584 "%s: entry was not added",
585 __func__);
586 return;
587 }
588 snprintf(md_entry.name, sizeof(md_entry.name), name);
589 md_entry.virt_addr = (uintptr_t)start_addr;
590 md_entry.phys_addr = virt_to_phys(start_addr);
591 md_entry.size = size;
592 msm_minidump_remove_region(&md_entry);
593 minidump_table[index] = NULL;
594 }
595
596 static inline void
__qdf_minidump_init(void)597 __qdf_minidump_init(void)
598 {
599 }
600
601 static inline void
__qdf_minidump_deinit(void)602 __qdf_minidump_deinit(void)
603 {
604 }
605
606 #elif defined(WLAN_QCOM_VA_MINIDUMP)
607 void __qdf_minidump_init(void);
608
609 void __qdf_minidump_deinit(void);
610
611 void __qdf_minidump_log(void *start_addr, size_t size, const char *name);
612
613 void __qdf_minidump_remove(void *addr, size_t size, const char *name);
614 #else
615 static inline
__qdf_minidump_init(void)616 void __qdf_minidump_init(void)
617 {
618 }
619
620 static inline
__qdf_minidump_deinit(void)621 void __qdf_minidump_deinit(void)
622 {
623 }
624
625 static inline
__qdf_minidump_log(void * start_addr,size_t size,const char * name)626 void __qdf_minidump_log(void *start_addr, size_t size, const char *name)
627 {
628 }
629
630 static inline
__qdf_minidump_remove(void * addr,size_t size,const char * name)631 void __qdf_minidump_remove(void *addr, size_t size, const char *name)
632 {
633 }
634 #endif
635 #endif /* __I_QDF_TRACE_H */
636