1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #ifndef __ODM_DBG_H__
9 #define __ODM_DBG_H__
10 
11 
12 /*  */
13 /* Define the debug levels */
14 /*  */
15 /* 1.	DBG_TRACE and DBG_LOUD are used for normal cases. */
16 /* So that, they can help SW engineer to developed or trace states changed */
17 /* and also help HW enginner to trace every operation to and from HW, */
18 /* e.g IO, Tx, Rx. */
19 /*  */
20 /* 2.	DBG_WARNNING and DBG_SERIOUS are used for unusual or error cases, */
21 /* which help us to debug SW or HW. */
22 /*  */
23 /*  */
24 /*  */
25 /* Never used in a call to ODM_RT_TRACE()! */
26 /*  */
27 #define ODM_DBG_OFF					1
28 
29 /*  */
30 /* Fatal bug. */
31 /* For example, Tx/Rx/IO locked up, OS hangs, memory access violation, */
32 /* resource allocation failed, unexpected HW behavior, HW BUG and so on. */
33 /*  */
34 #define ODM_DBG_SERIOUS				2
35 
36 /*  */
37 /* Abnormal, rare, or unexpected cases. */
38 /* For example, */
39 /* IRP/Packet/OID canceled, */
40 /* device suprisely unremoved and so on. */
41 /*  */
42 #define ODM_DBG_WARNING				3
43 
44 /*  */
45 /* Normal case with useful information about current SW or HW state. */
46 /* For example, Tx/Rx descriptor to fill, Tx/Rx descriptor completed status, */
47 /* SW protocol state change, dynamic mechanism state change and so on. */
48 /*  */
49 #define ODM_DBG_LOUD				4
50 
51 /*  */
52 /* Normal case with detail execution flow or information. */
53 /*  */
54 #define ODM_DBG_TRACE				5
55 
56 /*  */
57 /*  Define the tracing components */
58 /*  */
59 /*  */
60 /* BB Functions */
61 #define ODM_COMP_DIG				BIT0
62 #define ODM_COMP_RA_MASK			BIT1
63 #define ODM_COMP_DYNAMIC_TXPWR		BIT2
64 #define ODM_COMP_FA_CNT				BIT3
65 #define ODM_COMP_RSSI_MONITOR		BIT4
66 #define ODM_COMP_CCK_PD				BIT5
67 #define ODM_COMP_ANT_DIV			BIT6
68 #define ODM_COMP_PWR_SAVE			BIT7
69 #define ODM_COMP_PWR_TRAIN			BIT8
70 #define ODM_COMP_RATE_ADAPTIVE		BIT9
71 #define ODM_COMP_PATH_DIV			BIT10
72 #define ODM_COMP_PSD				BIT11
73 #define ODM_COMP_DYNAMIC_PRICCA		BIT12
74 #define ODM_COMP_RXHP				BIT13
75 #define ODM_COMP_MP					BIT14
76 #define ODM_COMP_CFO_TRACKING		BIT15
77 /* MAC Functions */
78 #define ODM_COMP_EDCA_TURBO			BIT16
79 #define ODM_COMP_EARLY_MODE			BIT17
80 /* RF Functions */
81 #define ODM_COMP_TX_PWR_TRACK		BIT24
82 #define ODM_COMP_RX_GAIN_TRACK		BIT25
83 #define ODM_COMP_CALIBRATION		BIT26
84 /* Common Functions */
85 #define ODM_COMP_COMMON				BIT30
86 #define ODM_COMP_INIT				BIT31
87 
88 /*------------------------Export Marco Definition---------------------------*/
89 	#define DbgPrint printk
90 	#define RT_PRINTK(fmt, args...)\
91 		DbgPrint("%s(): " fmt, __func__, ## args)
92 	#define RT_DISP(dbgtype, dbgflag, printstr)
93 
94 #ifndef ASSERT
95 	#define ASSERT(expr)
96 #endif
97 
98 #if DBG
99 #define ODM_RT_TRACE(pDM_Odm, comp, level, fmt)\
100 	do {\
101 		if (\
102 			(comp & pDM_Odm->DebugComponents) &&\
103 			(level <= pDM_Odm->DebugLevel ||\
104 			 level == ODM_DBG_SERIOUS)\
105 		) {\
106 			RT_PRINTK fmt;\
107 		} \
108 	} while (0)
109 
110 #define ODM_RT_TRACE_F(pDM_Odm, comp, level, fmt)\
111 	do {\
112 		if (\
113 			(comp & pDM_Odm->DebugComponents) &&\
114 			(level <= pDM_Odm->DebugLevel)\
115 		) {\
116 			RT_PRINTK fmt;\
117 		} \
118 	} while (0)
119 
120 #define ODM_RT_ASSERT(pDM_Odm, expr, fmt)\
121 	do {\
122 		if (!expr) {\
123 			DbgPrint("Assertion failed! %s at ......\n", #expr);\
124 			DbgPrint(\
125 				"      ......%s,%s, line =%d\n",\
126 				__FILE__,\
127 				__func__,\
128 				__LINE__\
129 			);\
130 			RT_PRINTK fmt;\
131 			ASSERT(false);\
132 		} \
133 	} while (0)
134 #define ODM_dbg_enter() { DbgPrint("==> %s\n", __func__); }
135 #define ODM_dbg_exit() { DbgPrint("<== %s\n", __func__); }
136 #define ODM_dbg_trace(str) { DbgPrint("%s:%s\n", __func__, str); }
137 
138 #define ODM_PRINT_ADDR(pDM_Odm, comp, level, title_str, ptr)\
139 	do {\
140 		if (\
141 			(comp & pDM_Odm->DebugComponents) &&\
142 			(level <= pDM_Odm->DebugLevel)\
143 		) {\
144 			int __i;\
145 			u8 *__ptr = (u8 *)ptr;\
146 			DbgPrint("[ODM] ");\
147 			DbgPrint(title_str);\
148 			DbgPrint(" ");\
149 			for (__i = 0; __i < 6; __i++)\
150 				DbgPrint("%02X%s", __ptr[__i], (__i == 5) ? "" : "-");\
151 			DbgPrint("\n");\
152 		} \
153 	} while (0)
154 #else
155 #define ODM_RT_TRACE(pDM_Odm, comp, level, fmt)		no_printk fmt
156 #define ODM_RT_TRACE_F(pDM_Odm, comp, level, fmt)	no_printk fmt
157 #define ODM_RT_ASSERT(pDM_Odm, expr, fmt)		no_printk fmt
158 #define ODM_dbg_enter()					do {} while (0)
159 #define ODM_dbg_exit()					do {} while (0)
160 #define ODM_dbg_trace(str)				no_printk("%s", str)
161 #define ODM_PRINT_ADDR(pDM_Odm, comp, level, title_str, ptr) \
162 	no_printk("%s %p", title_str, ptr)
163 #endif
164 
165 void ODM_InitDebugSetting(PDM_ODM_T pDM_Odm);
166 
167 #endif	/*  __ODM_DBG_H__ */
168