xref: /wlan-dirver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_trace.h (revision 3149adf58a329e17232a4c0e58d460d025edd55a)
1 /*
2  * Copyright (c) 2014-2018 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 
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 
28 /**
29  * DOC: i_qdf_trace.h
30  *
31  * Linux-specific definitions for QDF trace
32  *
33  */
34 
35 #if !defined(__I_QDF_TRACE_H)
36 #define __I_QDF_TRACE_H
37 
38 /* older kernels have a bug in kallsyms, so ensure module.h is included */
39 #include <linux/module.h>
40 #include <linux/kallsyms.h>
41 
42 #if !defined(__printf)
43 #define __printf(a, b)
44 #endif
45 
46 #ifdef CONFIG_MCL
47 /* QDF_TRACE is the macro invoked to add trace messages to code.  See the
48  * documenation for qdf_trace_msg() for the parameters etc. for this function.
49  *
50  * NOTE:  Code QDF_TRACE() macros into the source code.  Do not code directly
51  * to the qdf_trace_msg() function.
52  *
53  * NOTE 2:  qdf tracing is totally turned off if WLAN_DEBUG is *not* defined.
54  * This allows us to build 'performance' builds where we can measure performance
55  * without being bogged down by all the tracing in the code
56  */
57 #if defined(WLAN_DEBUG) || defined(DEBUG)
58 #define QDF_TRACE qdf_trace_msg
59 #define QDF_VTRACE qdf_vtrace_msg
60 #define QDF_TRACE_HEX_DUMP qdf_trace_hex_dump
61 #define QDF_TRACE_RATE_LIMITED(rate, module, level, format, ...)\
62 	do {\
63 		static int rate_limit;\
64 		rate_limit++;\
65 		if (rate)\
66 			if (0 == (rate_limit % rate))\
67 				qdf_trace_msg(module, level, format,\
68 						##__VA_ARGS__);\
69 	} while (0)
70 #else
71 #define QDF_TRACE(arg ...)
72 #define QDF_VTRACE(arg ...)
73 #define QDF_TRACE_HEX_DUMP(arg ...)
74 #define QDF_TRACE_RATE_LIMITED(arg ...)
75 #endif
76 #else /* CONFIG_MCL */
77 
78 #define qdf_trace(log_level, args...) \
79 		do {	\
80 			extern int qdf_dbg_mask; \
81 			if (qdf_dbg_mask >= log_level) { \
82 				printk(args); \
83 				printk("\n"); \
84 			} \
85 		} while (0)
86 
87 #define QDF_TRACE qdf_trace_msg
88 
89 #define QDF_TRACE_HEX_DUMP qdf_trace_hex_dump
90 #endif /* CONFIG_MCL */
91 
92 #define QDF_ENABLE_TRACING
93 #define qdf_scnprintf scnprintf
94 
95 #ifdef QDF_ENABLE_TRACING
96 
97 #define QDF_ASSERT(_condition) \
98 	do { \
99 		if (!(_condition)) { \
100 			pr_err("QDF ASSERT in %s Line %d\n", \
101 			       __func__, __LINE__); \
102 			WARN_ON(1); \
103 		} \
104 	} while (0)
105 
106 #else
107 
108 /* This code will be used for compilation if tracing is to be compiled out */
109 /* of the code so these functions/macros are 'do nothing' */
110 static inline void qdf_trace_msg(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
111 		   char *str_format, ...)
112 {
113 }
114 
115 #define QDF_ASSERT(_condition)
116 
117 #endif
118 
119 #ifdef PANIC_ON_BUG
120 #ifdef CONFIG_SLUB_DEBUG
121 /**
122  * QDF_DEBUG_PANIC() - Causes a panic if PANIC_ON_BUG option is enabled
123  *
124  * Note: Calling panic can cause a compiler to assume any following code is
125  * unreachable. Because these panics may or may not be enabled by the build
126  * configuration, this can cause developers some pain. Consider:
127  *
128  *	bool bit;
129  *
130  *	if (ptr)
131  *		bit = ptr->returns_bool();
132  *	else
133  *		panic();
134  *
135  *	// do stuff with @bit
136  *
137  *	return bit;
138  *
139  * In this case, @bit is potentially uninitialized when we return! However, the
140  * compiler can correctly assume this case is impossible when PANIC_ON_BUG is
141  * enabled. Because developers typically enable this feature, the "maybe
142  * uninitialized" warning will not be emitted, and the bug remains uncaught
143  * until someone tries to make a build without PANIC_ON_BUG.
144  *
145  * A simple workaround for this, is to put the definition of QDF_DEBUG_PANIC in
146  * another compilation unit, which prevents the compiler from assuming
147  * subsequent code is unreachable. For CONFIG_SLUB_DEBUG, do this to catch more
148  * bugs. Otherwise, use the typical inlined approach.
149  *
150  * Return: None
151  */
152 void QDF_DEBUG_PANIC(void);
153 #else
154 static inline void QDF_DEBUG_PANIC(void)
155 {
156 	BUG();
157 }
158 #endif /* CONFIG_SLUB_DEBUG */
159 #else
160 static inline void QDF_DEBUG_PANIC(void) { }
161 #endif /* PANIC_ON_BUG */
162 
163 #define QDF_BUG(_condition) \
164 	do { \
165 		if (!(_condition)) { \
166 			pr_err("QDF BUG in %s Line %d: Failed assertion '" \
167 			       #_condition "'\n", __func__, __LINE__); \
168 			QDF_DEBUG_PANIC(); \
169 		} \
170 	} while (0)
171 
172 #ifdef KSYM_SYMBOL_LEN
173 #define __QDF_SYMBOL_LEN KSYM_SYMBOL_LEN
174 #else
175 #define __QDF_SYMBOL_LEN 1
176 #endif
177 
178 #endif /* __I_QDF_TRACE_H */
179