xref: /wlan-driver/platform/cnss2/debug.h (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */
3 /* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */
4 
5 #ifndef _CNSS_DEBUG_H
6 #define _CNSS_DEBUG_H
7 
8 #include <linux/printk.h>
9 
10 enum log_level {
11 	EMERG_LOG = 0,
12 	ALERT_LOG = 1,
13 	CRIT_LOG = 2,
14 	ERR_LOG = 3,
15 	WARNING_LOG = 4,
16 	NOTICE_LOG = 5,
17 	INFO_LOG = 6,
18 	DEBUG_LOG = 7,
19 	DEBUG_HI_LOG = 8,
20 	MAX_LOG = 9,
21 };
22 
23 extern enum log_level cnss_kernel_log_level;
24 
25 #if IS_ENABLED(CONFIG_IPC_LOGGING)
26 #include <linux/ipc_logging.h>
27 #include <asm/current.h>
28 
29 extern void *cnss_ipc_log_context;
30 extern void *cnss_ipc_log_long_context;
31 extern enum log_level cnss_ipc_log_level;
32 
33 #ifdef CONFIG_CNSS2_DEBUG
34 #define CNSS_IPC_LOG_PAGES              100
35 #else
36 #define CNSS_IPC_LOG_PAGES              50
37 #endif
38 #define cnss_debug_log_print(_x...) \
39 		 cnss_debug_ipc_log_print(cnss_ipc_log_context, _x)
40 
41 #define cnss_debug_log_long_print(_x...) \
42 		 cnss_debug_ipc_log_print(cnss_ipc_log_long_context, _x)
43 #else
44 #define cnss_debug_log_print(_x...) \
45 		 cnss_debug_ipc_log_print((void *)NULL, _x)
46 #define cnss_debug_log_long_print(_x...) \
47 		 cnss_debug_ipc_log_print((void *)NULL, _x)
48 #endif
49 
50 #define proc_name (in_irq() ? "irq" : \
51 		   (in_softirq() ? "soft_irq" : current->comm))
52 
53 #define cnss_pr_err(_fmt, ...) \
54 	cnss_debug_log_print(proc_name, __func__, \
55 			     ERR_LOG, ERR_LOG, _fmt, ##__VA_ARGS__)
56 
57 #define cnss_pr_warn(_fmt, ...) \
58 	cnss_debug_log_print(proc_name, __func__, \
59 			     WARNING_LOG, WARNING_LOG, _fmt, ##__VA_ARGS__)
60 
61 #define cnss_pr_info(_fmt, ...) \
62 	cnss_debug_log_print(proc_name, __func__, \
63 			     INFO_LOG, INFO_LOG, _fmt, ##__VA_ARGS__)
64 
65 #define cnss_pr_dbg(_fmt, ...) \
66 	cnss_debug_log_print(proc_name, __func__, \
67 			     DEBUG_LOG, DEBUG_LOG, _fmt, ##__VA_ARGS__)
68 
69 #define cnss_pr_vdbg(_fmt, ...) \
70 	cnss_debug_log_long_print(proc_name, __func__, \
71 				  DEBUG_LOG, DEBUG_LOG, _fmt, ##__VA_ARGS__)
72 
73 #define cnss_pr_buf(_fmt, ...) \
74 	cnss_debug_log_long_print(proc_name, __func__, \
75 				  DEBUG_HI_LOG, DEBUG_LOG, _fmt, ##__VA_ARGS__)
76 #define cnss_pr_dbg_buf(_fmt, ...) \
77 	cnss_debug_log_long_print(proc_name, __func__, \
78 				  DEBUG_HI_LOG, DEBUG_HI_LOG, _fmt, ##__VA_ARGS__)
79 
80 #ifdef CONFIG_CNSS2_DEBUG
81 #define CNSS_ASSERT(_condition) do {					\
82 		if (!(_condition)) {					\
83 			cnss_pr_err("ASSERT at line %d\n",		\
84 				    __LINE__);				\
85 			BUG();						\
86 		}							\
87 	} while (0)
88 #else
89 #define CNSS_ASSERT(_condition) do {					\
90 		if (!(_condition)) {					\
91 			cnss_pr_err("ASSERT at line %d\n",		\
92 				    __LINE__);				\
93 			WARN_ON(1);					\
94 		}							\
95 	} while (0)
96 #endif
97 
98 #define cnss_fatal_err(_fmt, ...)					\
99 	cnss_pr_err("fatal: " _fmt, ##__VA_ARGS__)
100 
101 int cnss_debug_init(void);
102 void cnss_debug_deinit(void);
103 int cnss_debugfs_create(struct cnss_plat_data *plat_priv);
104 void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv);
105 void cnss_debug_ipc_log_print(void *log_ctx, char *process, const char *fn,
106 			      enum log_level kern_log_level,
107 			      enum log_level ipc_log_level, char *fmt, ...);
108 #endif /* _CNSS_DEBUG_H */
109