1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2019-2021 NXP
4  *
5  * Brief   CAAM driver trace include file.
6  *         Definition of the internal driver trace macros.
7  */
8 
9 #ifndef __CAAM_TRACE_H__
10 #define __CAAM_TRACE_H__
11 
12 #include <trace.h>
13 #include <util.h>
14 
15 #define CAAM_DBG_TRACE(var) (CFG_DBG_CAAM_TRACE & DBG_TRACE_##var)
16 #define CAAM_DBG_DESC(var)  (CFG_DBG_CAAM_DESC & DBG_TRACE_##var)
17 #define CAAM_DBG_BUF(var)   (CFG_DBG_CAAM_BUF & DBG_TRACE_##var)
18 
19 /*
20  * Debug Macros function of CAAM Debug Level setting
21  * CFG_DBG_CAAM_TRACE  Module print trace
22  * CFG_DBG_CAAM_DESC   Module descriptor dump
23  * CFG_DBG_CAAM_BUF    Module buffer dump
24  *
25  * A module is represented with the same bit in each configuration value.
26  * Module Bit definition is as follow:
27  */
28 #define DBG_TRACE_HAL	 BIT32(0)  /* HAL trace */
29 #define DBG_TRACE_CTRL	 BIT32(1)  /* Controller trace */
30 #define DBG_TRACE_MEM	 BIT32(2)  /* Memory utility trace */
31 #define DBG_TRACE_SGT	 BIT32(3)  /* Scatter Gather trace */
32 #define DBG_TRACE_PWR	 BIT32(4)  /* Power trace */
33 #define DBG_TRACE_JR	 BIT32(5)  /* Job Ring trace */
34 #define DBG_TRACE_RNG	 BIT32(6)  /* RNG trace */
35 #define DBG_TRACE_HASH	 BIT32(7)  /* Hash trace */
36 #define DBG_TRACE_RSA	 BIT32(8)  /* RSA trace */
37 #define DBG_TRACE_CIPHER BIT32(9)  /* Cipher dump Buffer */
38 #define DBG_TRACE_BLOB   BIT32(10) /* BLOB trace */
39 #define DBG_TRACE_DMAOBJ BIT32(11) /* DMA Object trace */
40 #define DBG_TRACE_ECC    BIT32(12) /* ECC trace */
41 #define DBG_TRACE_DH	 BIT32(13) /* DH trace */
42 #define DBG_TRACE_DSA	 BIT32(14) /* DSA trace */
43 
44 /* HAL */
45 #if CAAM_DBG_TRACE(HAL)
46 #define HAL_TRACE DRV_TRACE
47 #else
48 #define HAL_TRACE(...)
49 #endif
50 
51 /* Controller */
52 #if CAAM_DBG_TRACE(CTRL)
53 #define CTRL_TRACE DRV_TRACE
54 #else
55 #define CTRL_TRACE(...)
56 #endif
57 
58 /* Memory Utility */
59 #if CAAM_DBG_TRACE(MEM)
60 #define MEM_TRACE DRV_TRACE
61 #else
62 #define MEM_TRACE(...)
63 #endif
64 
65 /* Scatter Gether Table */
66 #if CAAM_DBG_TRACE(SGT)
67 #define SGT_TRACE DRV_TRACE
68 #else
69 #define SGT_TRACE(...)
70 #endif
71 
72 /* Power */
73 #if CAAM_DBG_TRACE(PWR)
74 #define PWR_TRACE DRV_TRACE
75 #else
76 #define PWR_TRACE(...)
77 #endif
78 
79 /* Job Ring */
80 #if CAAM_DBG_TRACE(JR)
81 #define JR_TRACE DRV_TRACE
82 #if CAAM_DBG_DESC(JR)
83 #define JR_DUMPDESC(desc)                                                      \
84 	do {                                                                   \
85 		JR_TRACE("Descriptor");                                        \
86 		DRV_DUMPDESC(desc);                                            \
87 	} while (0)
88 #else
89 #define JR_DUMPDESC(desc)
90 #endif
91 #else
92 #define JR_TRACE(...)
93 #define JR_DUMPDESC(desc)
94 #endif
95 
96 /* RNG */
97 #if CAAM_DBG_TRACE(RNG)
98 #define RNG_TRACE DRV_TRACE
99 #if CAAM_DBG_DESC(RNG)
100 #define RNG_DUMPDESC(desc)                                                     \
101 	do {                                                                   \
102 		RNG_TRACE("RNG Descriptor");                                   \
103 		DRV_DUMPDESC(desc);                                            \
104 	} while (0)
105 #else
106 #define RNG_DUMPDESC(desc)
107 #endif
108 #else
109 #define RNG_TRACE(...)
110 #define RNG_DUMPDESC(desc)
111 #endif
112 
113 /* Hash */
114 #if CAAM_DBG_TRACE(HASH)
115 #define HASH_TRACE DRV_TRACE
116 #if CAAM_DBG_DESC(HASH)
117 #define HASH_DUMPDESC(desc)                                                    \
118 	do {                                                                   \
119 		HASH_TRACE("HASH Descriptor");                                 \
120 		DRV_DUMPDESC(desc);                                            \
121 	} while (0)
122 #else
123 #define HASH_DUMPDESC(desc)
124 #endif
125 #if CAAM_DBG_BUF(HASH)
126 #define HASH_DUMPBUF DRV_DUMPBUF
127 #else
128 #define HASH_DUMPBUF(...)
129 #endif
130 #else
131 #define HASH_TRACE(...)
132 #define HASH_DUMPDESC(desc)
133 #define HASH_DUMPBUF(...)
134 #endif
135 
136 /* RSA */
137 #if CAAM_DBG_TRACE(RSA)
138 #define RSA_TRACE DRV_TRACE
139 #if CAAM_DBG_DESC(RSA)
140 #define RSA_DUMPDESC(desc)                                                     \
141 	do {                                                                   \
142 		RSA_TRACE("RSA Descriptor");                                   \
143 		DRV_DUMPDESC(desc);                                            \
144 	} while (0)
145 #else
146 #define RSA_DUMPDESC(desc)
147 #endif
148 #if CAAM_DBG_BUF(RSA)
149 #define RSA_DUMPBUF DRV_DUMPBUF
150 #else
151 #define RSA_DUMPBUF(...)
152 #endif
153 #else
154 #define RSA_TRACE(...)
155 #define RSA_DUMPDESC(desc)
156 #define RSA_DUMPBUF(...)
157 #endif
158 
159 /* Cipher */
160 #if CAAM_DBG_TRACE(CIPHER)
161 #define CIPHER_TRACE DRV_TRACE
162 #if CAAM_DBG_DESC(CIPHER)
163 #define CIPHER_DUMPDESC(desc)                                                  \
164 	do {                                                                   \
165 		CIPHER_TRACE("CIPHER Descriptor");                             \
166 		DRV_DUMPDESC(desc);                                            \
167 	} while (0)
168 #else
169 #define CIPHER_DUMPDESC(desc)
170 #endif
171 #if CAAM_DBG_BUF(CIPHER)
172 #define CIPHER_DUMPBUF DRV_DUMPBUF
173 #else
174 #define CIPHER_DUMPBUF(...)
175 #endif
176 #else
177 #define CIPHER_TRACE(...)
178 #define CIPHER_DUMPDESC(desc)
179 #define CIPHER_DUMPBUF(...)
180 #endif
181 
182 /* DMA Object */
183 #if CAAM_DBG_TRACE(DMAOBJ)
184 #define DMAOBJ_TRACE DRV_TRACE
185 #else
186 #define DMAOBJ_TRACE(...)
187 #endif
188 
189 /* ECC */
190 #if CAAM_DBG_TRACE(ECC)
191 #define ECC_TRACE DRV_TRACE
192 #if CAAM_DBG_DESC(ECC)
193 #define ECC_DUMPDESC(desc)                                                     \
194 	do {                                                                   \
195 		ECC_TRACE("ECC Descriptor");                                   \
196 		DRV_DUMPDESC(desc);                                            \
197 	} while (0)
198 #else
199 #define ECC_DUMPDESC(desc) do { } while (0)
200 #endif
201 #if CAAM_DBG_BUF(ECC)
202 #define ECC_DUMPBUF DRV_DUMPBUF
203 #else
204 #define ECC_DUMPBUF(...) do { } while (0)
205 #endif
206 #else
207 #define ECC_TRACE(...) do { } while (0)
208 #define ECC_DUMPDESC(desc) do { } while (0)
209 #define ECC_DUMPBUF(...) do { } while (0)
210 #endif
211 
212 /* DH */
213 #if CAAM_DBG_TRACE(DH)
214 #define DH_TRACE DRV_TRACE
215 #if CAAM_DBG_DESC(DH)
216 #define DH_DUMPDESC(desc)                                                      \
217 	{                                                                      \
218 		DH_TRACE("DH Descriptor");                                     \
219 		DRV_DUMPDESC(desc);                                            \
220 	}
221 #else
222 #define DH_DUMPDESC(desc)
223 #endif
224 #if CAAM_DBG_BUF(DH)
225 #define DH_DUMPBUF DRV_DUMPBUF
226 #else
227 #define DH_DUMPBUF(...)
228 #endif
229 #else
230 #define DH_TRACE(...)
231 #define DH_DUMPDESC(desc)
232 #define DH_DUMPBUF(...)
233 #endif
234 
235 /* DSA */
236 #if CAAM_DBG_TRACE(DSA)
237 #define DSA_TRACE DRV_TRACE
238 #if CAAM_DBG_DESC(DSA)
239 #define DSA_DUMPDESC(desc)                                                     \
240 	do {                                                                   \
241 		MP_TRACE("DSA Descriptor");                                    \
242 		DRV_DUMPDESC(desc);                                            \
243 	} while (0)
244 #else
245 #define DSA_DUMPDESC(desc)
246 #endif
247 #if CAAM_DBG_BUF(DSA)
248 #define DSA_DUMPBUF DRV_DUMPBUF
249 #else
250 #define DSA_DUMPBUF(...)
251 #endif
252 #else
253 #define DSA_TRACE(...)
254 #define DSA_DUMPDESC(desc)
255 #define DSA_DUMPBUF(...)
256 #endif
257 
258 #if (TRACE_LEVEL >= TRACE_DEBUG)
259 #define DRV_TRACE(...)                                                         \
260 	trace_printf(__func__, __LINE__, TRACE_DEBUG, true, __VA_ARGS__)
261 #define DRV_DUMPDESC(desc) dump_desc(desc)
262 
263 #define DRV_DUMPBUF(title, buf, len)                                           \
264 	do {                                                                   \
265 		__typeof__(buf) _buf = (buf);                                  \
266 		__typeof__(len) _len = (len);                                  \
267 									       \
268 		DRV_TRACE("%s @%p : %zu", title, _buf, _len);                  \
269 		dhex_dump(NULL, 0, 0, _buf, _len);                             \
270 	} while (0)
271 
272 #else
273 #define DRV_TRACE(...)
274 #define DRV_DUMPDESC(...)
275 #define DRV_DUMPBUF(...)
276 #endif
277 
278 /* BLOB */
279 #if CAAM_DBG_TRACE(BLOB)
280 #define BLOB_TRACE DRV_TRACE
281 #if CAAM_DBG_DESC(BLOB)
282 #define BLOB_DUMPDESC(desc)                                                    \
283 	do {                                                                   \
284 		BLOB_TRACE("BLOB Descriptor");                                 \
285 		DRV_DUMPDESC(desc);                                            \
286 	} while (0)
287 #else
288 #define BLOB_DUMPDESC(desc)
289 #endif
290 #if CAAM_DBG_BUF(BLOB)
291 #define BLOB_DUMPBUF DRV_DUMPBUF
292 #else
293 #define BLOB_DUMPBUF(...)
294 #endif
295 #else
296 #define BLOB_TRACE(...)
297 #define BLOB_DUMPDESC(desc)
298 #define BLOB_DUMPBUF(...)
299 #endif
300 
301 #endif /* CAAM_TRACE_H__ */
302