Skip to content

Commit 4537992

Browse files
Cyrille Pitchenherbertx
authored andcommitted
crypto: atmel-aes - add debug facilities to monitor register accesses.
This feature should not be enabled in release but can be usefull for developers who need to monitor register accesses at some specific places. Set the AES_FLAGS_DUMP_REG flag inside dd->flags to start monitoring the I/O accesses, clear it to stop monitoring. Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent d441954 commit 4537992

1 file changed

Lines changed: 114 additions & 1 deletion

File tree

‎drivers/crypto/atmel-aes.c‎

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
#define AES_FLAGS_INIT BIT(2)
7777
#define AES_FLAGS_BUSY BIT(3)
78+
#define AES_FLAGS_DUMP_REG BIT(4)
7879

7980
#define AES_FLAGS_PERSISTENT (AES_FLAGS_INIT | AES_FLAGS_BUSY)
8081

@@ -197,16 +198,128 @@ static struct atmel_aes_drv atmel_aes = {
197198
.lock = __SPIN_LOCK_UNLOCKED(atmel_aes.lock),
198199
};
199200

201+
#ifdef VERBOSE_DEBUG
202+
static const char *atmel_aes_reg_name(u32 offset, char *tmp, size_t sz)
203+
{
204+
switch (offset) {
205+
case AES_CR:
206+
return "CR";
207+
208+
case AES_MR:
209+
return "MR";
210+
211+
case AES_ISR:
212+
return "ISR";
213+
214+
case AES_IMR:
215+
return "IMR";
216+
217+
case AES_IER:
218+
return "IER";
219+
220+
case AES_IDR:
221+
return "IDR";
222+
223+
case AES_KEYWR(0):
224+
case AES_KEYWR(1):
225+
case AES_KEYWR(2):
226+
case AES_KEYWR(3):
227+
case AES_KEYWR(4):
228+
case AES_KEYWR(5):
229+
case AES_KEYWR(6):
230+
case AES_KEYWR(7):
231+
snprintf(tmp, sz, "KEYWR[%u]", (offset - AES_KEYWR(0)) >> 2);
232+
break;
233+
234+
case AES_IDATAR(0):
235+
case AES_IDATAR(1):
236+
case AES_IDATAR(2):
237+
case AES_IDATAR(3):
238+
snprintf(tmp, sz, "IDATAR[%u]", (offset - AES_IDATAR(0)) >> 2);
239+
break;
240+
241+
case AES_ODATAR(0):
242+
case AES_ODATAR(1):
243+
case AES_ODATAR(2):
244+
case AES_ODATAR(3):
245+
snprintf(tmp, sz, "ODATAR[%u]", (offset - AES_ODATAR(0)) >> 2);
246+
break;
247+
248+
case AES_IVR(0):
249+
case AES_IVR(1):
250+
case AES_IVR(2):
251+
case AES_IVR(3):
252+
snprintf(tmp, sz, "IVR[%u]", (offset - AES_IVR(0)) >> 2);
253+
break;
254+
255+
case AES_AADLENR:
256+
return "AADLENR";
257+
258+
case AES_CLENR:
259+
return "CLENR";
260+
261+
case AES_GHASHR(0):
262+
case AES_GHASHR(1):
263+
case AES_GHASHR(2):
264+
case AES_GHASHR(3):
265+
snprintf(tmp, sz, "GHASHR[%u]", (offset - AES_GHASHR(0)) >> 2);
266+
break;
267+
268+
case AES_TAGR(0):
269+
case AES_TAGR(1):
270+
case AES_TAGR(2):
271+
case AES_TAGR(3):
272+
snprintf(tmp, sz, "TAGR[%u]", (offset - AES_TAGR(0)) >> 2);
273+
break;
274+
275+
case AES_CTRR:
276+
return "CTRR";
277+
278+
case AES_GCMHR(0):
279+
case AES_GCMHR(1):
280+
case AES_GCMHR(2):
281+
case AES_GCMHR(3):
282+
snprintf(tmp, sz, "GCMHR[%u]", (offset - AES_GCMHR(0)) >> 2);
283+
284+
default:
285+
snprintf(tmp, sz, "0x%02x", offset);
286+
break;
287+
}
288+
289+
return tmp;
290+
}
291+
#endif /* VERBOSE_DEBUG */
292+
200293
/* Shared functions */
201294

202295
static inline u32 atmel_aes_read(struct atmel_aes_dev *dd, u32 offset)
203296
{
204-
return readl_relaxed(dd->io_base + offset);
297+
u32 value = readl_relaxed(dd->io_base + offset);
298+
299+
#ifdef VERBOSE_DEBUG
300+
if (dd->flags & AES_FLAGS_DUMP_REG) {
301+
char tmp[16];
302+
303+
dev_vdbg(dd->dev, "read 0x%08x from %s\n", value,
304+
atmel_aes_reg_name(offset, tmp, sizeof(tmp)));
305+
}
306+
#endif /* VERBOSE_DEBUG */
307+
308+
return value;
205309
}
206310

207311
static inline void atmel_aes_write(struct atmel_aes_dev *dd,
208312
u32 offset, u32 value)
209313
{
314+
#ifdef VERBOSE_DEBUG
315+
if (dd->flags & AES_FLAGS_DUMP_REG) {
316+
char tmp[16];
317+
318+
dev_vdbg(dd->dev, "write 0x%08x into %s\n", value,
319+
atmel_aes_reg_name(offset, tmp));
320+
}
321+
#endif /* VERBOSE_DEBUG */
322+
210323
writel_relaxed(value, dd->io_base + offset);
211324
}
212325

0 commit comments

Comments
 (0)