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