1  /* SPDX-License-Identifier: GPL-2.0-only */
2  /*
3   * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
4   */
5  
6  #ifndef _ICNSS_DEBUG_H
7  #define _ICNSS_DEBUG_H
8  
9  #include <linux/ipc_logging.h>
10  #include <linux/printk.h>
11  
12  #define NUM_LOG_PAGES			10
13  #define NUM_LOG_LONG_PAGES		4
14  
15  extern void *icnss_ipc_log_context;
16  extern void *icnss_ipc_log_long_context;
17  extern void *icnss_ipc_log_smp2p_context;
18  extern void *icnss_ipc_soc_wake_context;
19  
20  #if IS_ENABLED(CONFIG_IPC_LOGGING)
21  #define icnss_ipc_log_string(_x...)                                     \
22  	ipc_log_string(icnss_ipc_log_context, _x)
23  
24  #define icnss_ipc_log_long_string(_x...)                                \
25  	ipc_log_string(icnss_ipc_log_long_context, _x)
26  
27  #define icnss_ipc_log_smp2p_string(_x...)                                \
28  	ipc_log_string(icnss_ipc_log_smp2p_context, _x)
29  
30  #define icnss_ipc_soc_wake_string(_x...)                                \
31  	ipc_log_string(icnss_ipc_soc_wake_context, _x)
32  #else
33  #define icnss_ipc_log_string(_x...)
34  
35  #define icnss_ipc_log_long_string(_x...)
36  
37  #define icnss_ipc_log_smp2p_string(_x...)
38  
39  #define icnss_ipc_soc_wake_string(_x...)
40  #endif
41  
42  #define icnss_pr_err(_fmt, ...) do {                                    \
43  	printk("%s" pr_fmt(_fmt), KERN_ERR, ##__VA_ARGS__);             \
44  	icnss_ipc_log_string("%s" pr_fmt(_fmt), "",                     \
45  			     ##__VA_ARGS__);                            \
46  	} while (0)
47  
48  #define icnss_pr_warn(_fmt, ...) do {                                   \
49  	printk("%s" pr_fmt(_fmt), KERN_WARNING, ##__VA_ARGS__);         \
50  	icnss_ipc_log_string("%s" pr_fmt(_fmt), "",                     \
51  			     ##__VA_ARGS__);                            \
52  	} while (0)
53  
54  #define icnss_pr_info(_fmt, ...) do {                                   \
55  	printk("%s" pr_fmt(_fmt), KERN_INFO, ##__VA_ARGS__);            \
56  	icnss_ipc_log_string("%s" pr_fmt(_fmt), "",                     \
57  			     ##__VA_ARGS__);                            \
58  	} while (0)
59  
60  #define icnss_pr_dbg(_fmt, ...) do {                                    \
61  	pr_debug(_fmt, ##__VA_ARGS__);                                  \
62  	icnss_ipc_log_string(pr_fmt(_fmt), ##__VA_ARGS__);              \
63  	} while (0)
64  
65  #define icnss_pr_vdbg(_fmt, ...) do {                                   \
66  	pr_debug(_fmt, ##__VA_ARGS__);                                  \
67  	icnss_ipc_log_long_string(pr_fmt(_fmt), ##__VA_ARGS__);         \
68  	} while (0)
69  
70  #define icnss_pr_smp2p(_fmt, ...) do {                                  \
71  	pr_debug(_fmt, ##__VA_ARGS__);                                  \
72  	icnss_ipc_log_smp2p_string(pr_fmt(_fmt), ##__VA_ARGS__);        \
73  	} while (0)
74  
75  #define icnss_pr_soc_wake(_fmt, ...) do {                               \
76  	pr_debug(_fmt, ##__VA_ARGS__);                                  \
77  	icnss_ipc_soc_wake_string(pr_fmt(_fmt), ##__VA_ARGS__);         \
78  	} while (0)
79  
80  #ifdef CONFIG_ICNSS2_DEBUG
81  #define ICNSS_ASSERT(_condition) do {                                   \
82  		if (!(_condition)) {                                    \
83  			icnss_pr_err("ASSERT at line %d\n", __LINE__);  \
84  			BUG();                                          \
85  		}                                                       \
86  	} while (0)
87  #else
88  #define ICNSS_ASSERT(_condition) do { } while (0)
89  #endif
90  
91  #define icnss_fatal_err(_fmt, ...)                                      \
92  	icnss_pr_err("fatal: "_fmt, ##__VA_ARGS__)
93  
94  enum icnss_debug_quirks {
95  	HW_ALWAYS_ON,
96  	HW_DEBUG_ENABLE,
97  	SKIP_QMI,
98  	RECOVERY_DISABLE,
99  	SSR_ONLY,
100  	PDR_ONLY,
101  	FW_REJUVENATE_ENABLE,
102  };
103  
104  void icnss_debug_init(void);
105  void icnss_debug_deinit(void);
106  int icnss_debugfs_create(struct icnss_priv *priv);
107  void icnss_debugfs_destroy(struct icnss_priv *priv);
108  #endif /* _ICNSS_DEBUG_H */
109