xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/phl_debug.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 - 2021 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef _PHL_DEBUG_H_
16 #define _PHL_DEBUG_H_
17 
18 /* phl log level */
19 enum {
20 	_PHL_NONE_ = 0,
21 	_PHL_ALWAYS_ = 1,
22 	_PHL_ERR_ = 2,
23 	_PHL_WARNING_ = 3,
24 	_PHL_INFO_ = 4,
25 	_PHL_DEBUG_ = 5,
26 	_PHL_MAX_ = 6
27 };
28 
29 #define PHL_PREFIX "PHL: "
30 #define HALPS_PREFIX "HALPS:"
31 
32 #define	PHL_DBG_OUTBUF(max_buff_len, used_len, buff_addr, remain_len, fmt, ...)\
33 	do {									\
34 		u32 *used_len_tmp = &(used_len);				\
35 		if (*used_len_tmp < max_buff_len)				\
36 			*used_len_tmp += _os_snprintf(buff_addr, remain_len, fmt, ##__VA_ARGS__);\
37 	} while (0)
38 
39 #ifdef CONFIG_RTW_DEBUG
40 
41 /*Define the tracing components*/
42 #define COMP_PHL_DBG BIT0		/* For function call tracing. */
43 #define COMP_PHL_RECV BIT1
44 #define COMP_PHL_XMIT BIT2
45 #define COMP_PHL_MAC BIT3
46 #define COMP_PHL_SOUND BIT4
47 #define COMP_PHL_WOW BIT5
48 #define COMP_PHL_TRIG BIT6
49 #define COMP_PHL_PKTOFLD BIT7
50 #define COMP_PHL_FSM BIT8
51 #define COMP_PHL_PS BIT9
52 #define COMP_PHL_PSTS BIT10
53 #define COMP_PHL_BB BIT11
54 #define COMP_PHL_RF BIT12
55 #define COMP_PHL_LED BIT13
56 #define COMP_PHL_MCC BIT14
57 #define COMP_PHL_P2PPS BIT15
58 #define COMP_PHL_ECSA BIT16
59 #define COMP_PHL_CMDDISP BIT17
60 #define COMP_PHL_BTC BIT18
61 #define COMP_PHL_TWT BIT19
62 
63 extern u32 phl_log_components;
64 extern u8 phl_log_level;
65 #define DEBUG_MAX_NAME_LEN 50
66 
67 struct dbg_alloc_buf {
68 	_os_list list;
69 	u8 file_name[DEBUG_MAX_NAME_LEN];
70 	u8 func_name[DEBUG_MAX_NAME_LEN];
71 	u32 line_num;
72 	u32 buf_size;
73 	u8 *buf_ptr;
74 };
75 
76 struct dbg_mem_ctx {
77 	_os_list alloc_buf_list;
78 	_os_lock alloc_buf_list_lock;
79 	u32 alloc_buf_cnt;
80 };
81 
82 
83 #undef PHL_TRACE
84 #define PHL_TRACE(comp, level, fmt, ...)     \
85 	do {\
86 		if(((comp) & phl_log_components) && (level <= phl_log_level)) {\
87 			_os_dbgdump(PHL_PREFIX fmt, ##__VA_ARGS__);\
88 		} \
89 	} while (0)
90 
91 #undef PHL_DATA
92 #define PHL_DATA(comp, level, fmt, ...)     \
93 	do {\
94 		if(((comp) & phl_log_components) && (level <= phl_log_level)) {\
95 			_os_dbgdump_c(fmt, ##__VA_ARGS__);\
96 		} \
97 	} while (0)
98 
99 #undef PHL_ASSERT
100 #define PHL_ASSERT(fmt, ...) \
101 	do {\
102 			PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "ERROR " fmt, ##__VA_ARGS__);\
103 			_os_assert(true); \
104 	} while (0)
105 
106 
107 #undef PHL_PRINT
108 #define PHL_PRINT(fmt, ...)     \
109 	do {\
110 			PHL_TRACE(COMP_PHL_DBG, _PHL_ALWAYS_, fmt, ##__VA_ARGS__);\
111 	} while (0)
112 
113 #undef PHL_ERR
114 #define PHL_ERR(fmt, ...)     \
115 	do {\
116 			PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "ERROR " fmt, ##__VA_ARGS__);\
117 	} while (0)
118 
119 #undef PHL_WARN
120 #define PHL_WARN(fmt, ...)     \
121 	do {\
122 			PHL_TRACE(COMP_PHL_DBG, _PHL_WARNING_, "WARN " fmt, ##__VA_ARGS__);\
123 	} while (0)
124 
125 #undef PHL_INFO
126 #define PHL_INFO(fmt, ...)     \
127 	do {\
128 			PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, fmt, ##__VA_ARGS__);\
129 	} while (0)
130 
131 #undef PHL_DBG
132 #define PHL_DBG(fmt, ...)     \
133 	do {\
134 			PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, fmt, ##__VA_ARGS__);\
135 	} while (0)
136 
137 #define FUNCIN() PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, "Enter %s\n", __FUNCTION__)
138 #define FUNCOUT() PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, "Leave %s\n", __FUNCTION__)
139 #define FUNCIN_WSTS(_sts) PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, "Enter with 0x%08X %s\n", _sts, __FUNCTION__)
140 #define FUNCOUT_WSTS(_sts) PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, "Leave with 0x%08X %s\n", _sts, __FUNCTION__)
141 
142 void debug_dump_data(u8 *buf, u32 buf_len, const char *prefix);
143 void rt_alloc_dbg_buf(void *phl, u8 *buf_ptr, u32 buf_size,
144 		const u8 *file_name, u32 line_num, const u8 *func_name);
145 void rt_free_dbg_buf(void *phl, u8 *buf_ptr, u32 buf_size,
146 		const u8 *file_name, u32 line_num, const u8 *func_name);
147 void rt_mem_dbg_init(void *phl);
148 void rt_mem_dbg_deinit(void *phl);
149 u32 rtw_phl_dbg_ctrl_comp(u8 ctrl, u32 comp_bit);
150 void debug_dump_mac_address(u8 *mac_addr);
151 
152 #define phl_ops_error_msg(ops_fun)	  \
153 	PHL_ERR("### %s - Please hook phl_hci_ops.%s ###\n", __func__, ops_fun)
154 
155 #define hal_error_msg(ops_fun)		\
156 	PHL_PRINT("### %s - Error : Please hook hal_ops.%s ###\n", __FUNCTION__, ops_fun)
157 
158 #else  /* CONFIG_RTW_DEBUG */
159 
160 #define PHL_TRACE(comp, level, fmt, ...)
161 #define PHL_PRINT(fmt, ...)
162 #define PHL_ERR(fmt, ...)
163 #define PHL_WARN(fmt, ...)
164 #define PHL_INFO(fmt, ...)
165 #define PHL_DBG(fmt, ...)
166 #define PHL_DATA(fmt, ...)
167 #define PHL_ASSERT(fmt, ...)
168 #define FUNCIN()
169 #define FUNCOUT()
170 #define FUNCIN_WSTS(_sts)
171 #define FUNCOUT_WSTS(_sts)
172 #define debug_dump_data(_buf, _buf_len, _prefix)
173 #define debug_dump_mac_address(_mac_addr)
174 #define rt_alloc_dbg_buf(_phl, _buf, _buf_size, _file_name, _line_num, \
175 			_func_name)
176 #define rt_free_dbg_buf(_phl, _buf, _buf_size, _file_name, _line_num, \
177 			_func_name)
178 #define rt_mem_dbg_init(_phl)
179 #define rt_mem_dbg_deinit(_phl)
180 
181 #define rtw_phl_dbg_ctrl_comp(_ctrl, _comp_bit) 0
182 #define phl_ops_error_msg(ops_fun) do {} while (0)
183 #define hal_error_msg(ops_fun) do {} while (0)
184 
185 #endif  /* CONFIG_RTW_DEBUG */
186 #endif	/* _PHL_DEBUG_H_ */
187