mirror of
https://github.com/torvalds/linux.git
synced 2024-11-07 04:32:03 +00:00
crypto: caam - Pull all the error codes out
Pull the error code <-> error string mapping tables out of the function so the code becomes readable. This lets me see the real flesh of the functions, without all that flab clouding the view. Note: There is a checkpatch issue with quoted strings across multiple lines. I will fix that in a subsequent patch to keep the changes small and separate. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Horia Geanta <horia.geanta@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
fa9659cd4d
commit
9724d7adbb
@ -11,112 +11,6 @@
|
||||
#include "jr.h"
|
||||
#include "error.h"
|
||||
|
||||
#define SPRINTFCAT(str, format, param, max_alloc) \
|
||||
{ \
|
||||
char *tmp; \
|
||||
\
|
||||
tmp = kmalloc(sizeof(format) + max_alloc, GFP_ATOMIC); \
|
||||
sprintf(tmp, format, param); \
|
||||
strcat(str, tmp); \
|
||||
kfree(tmp); \
|
||||
}
|
||||
|
||||
static void report_jump_idx(u32 status, char *outstr)
|
||||
{
|
||||
u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
|
||||
JRSTA_DECOERR_INDEX_SHIFT;
|
||||
|
||||
if (status & JRSTA_DECOERR_JUMP)
|
||||
strcat(outstr, "jump tgt desc idx ");
|
||||
else
|
||||
strcat(outstr, "desc idx ");
|
||||
|
||||
SPRINTFCAT(outstr, "%d: ", idx, sizeof("255"));
|
||||
}
|
||||
|
||||
static void report_ccb_status(u32 status, char *outstr)
|
||||
{
|
||||
static const char * const cha_id_list[] = {
|
||||
"",
|
||||
"AES",
|
||||
"DES",
|
||||
"ARC4",
|
||||
"MDHA",
|
||||
"RNG",
|
||||
"SNOW f8",
|
||||
"Kasumi f8/9",
|
||||
"PKHA",
|
||||
"CRCA",
|
||||
"SNOW f9",
|
||||
"ZUCE",
|
||||
"ZUCA",
|
||||
};
|
||||
static const char * const err_id_list[] = {
|
||||
"No error.",
|
||||
"Mode error.",
|
||||
"Data size error.",
|
||||
"Key size error.",
|
||||
"PKHA A memory size error.",
|
||||
"PKHA B memory size error.",
|
||||
"Data arrived out of sequence error.",
|
||||
"PKHA divide-by-zero error.",
|
||||
"PKHA modulus even error.",
|
||||
"DES key parity error.",
|
||||
"ICV check failed.",
|
||||
"Hardware error.",
|
||||
"Unsupported CCM AAD size.",
|
||||
"Class 1 CHA is not reset",
|
||||
"Invalid CHA combination was selected",
|
||||
"Invalid CHA selected.",
|
||||
};
|
||||
static const char * const rng_err_id_list[] = {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"Instantiate",
|
||||
"Not instantiated",
|
||||
"Test instantiate",
|
||||
"Prediction resistance",
|
||||
"Prediction resistance and test request",
|
||||
"Uninstantiate",
|
||||
"Secure key generation",
|
||||
};
|
||||
u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
|
||||
JRSTA_CCBERR_CHAID_SHIFT;
|
||||
u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
|
||||
|
||||
report_jump_idx(status, outstr);
|
||||
|
||||
if (cha_id < ARRAY_SIZE(cha_id_list)) {
|
||||
SPRINTFCAT(outstr, "%s: ", cha_id_list[cha_id],
|
||||
strlen(cha_id_list[cha_id]));
|
||||
} else {
|
||||
SPRINTFCAT(outstr, "unidentified cha_id value 0x%02x: ",
|
||||
cha_id, sizeof("ff"));
|
||||
}
|
||||
|
||||
if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
|
||||
err_id < ARRAY_SIZE(rng_err_id_list) &&
|
||||
strlen(rng_err_id_list[err_id])) {
|
||||
/* RNG-only error */
|
||||
SPRINTFCAT(outstr, "%s", rng_err_id_list[err_id],
|
||||
strlen(rng_err_id_list[err_id]));
|
||||
} else if (err_id < ARRAY_SIZE(err_id_list)) {
|
||||
SPRINTFCAT(outstr, "%s", err_id_list[err_id],
|
||||
strlen(err_id_list[err_id]));
|
||||
} else {
|
||||
SPRINTFCAT(outstr, "unidentified err_id value 0x%02x",
|
||||
err_id, sizeof("ff"));
|
||||
}
|
||||
}
|
||||
|
||||
static void report_jump_status(u32 status, char *outstr)
|
||||
{
|
||||
SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
|
||||
}
|
||||
|
||||
static void report_deco_status(u32 status, char *outstr)
|
||||
{
|
||||
static const struct {
|
||||
u8 value;
|
||||
char *error_text;
|
||||
@ -215,6 +109,116 @@ static void report_deco_status(u32 status, char *outstr)
|
||||
"or was decremented to 0" },
|
||||
{ 0xF1, "3GPP HFN matches or exceeds the Threshold" },
|
||||
};
|
||||
|
||||
static const char * const cha_id_list[] = {
|
||||
"",
|
||||
"AES",
|
||||
"DES",
|
||||
"ARC4",
|
||||
"MDHA",
|
||||
"RNG",
|
||||
"SNOW f8",
|
||||
"Kasumi f8/9",
|
||||
"PKHA",
|
||||
"CRCA",
|
||||
"SNOW f9",
|
||||
"ZUCE",
|
||||
"ZUCA",
|
||||
};
|
||||
|
||||
static const char * const err_id_list[] = {
|
||||
"No error.",
|
||||
"Mode error.",
|
||||
"Data size error.",
|
||||
"Key size error.",
|
||||
"PKHA A memory size error.",
|
||||
"PKHA B memory size error.",
|
||||
"Data arrived out of sequence error.",
|
||||
"PKHA divide-by-zero error.",
|
||||
"PKHA modulus even error.",
|
||||
"DES key parity error.",
|
||||
"ICV check failed.",
|
||||
"Hardware error.",
|
||||
"Unsupported CCM AAD size.",
|
||||
"Class 1 CHA is not reset",
|
||||
"Invalid CHA combination was selected",
|
||||
"Invalid CHA selected.",
|
||||
};
|
||||
|
||||
static const char * const rng_err_id_list[] = {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"Instantiate",
|
||||
"Not instantiated",
|
||||
"Test instantiate",
|
||||
"Prediction resistance",
|
||||
"Prediction resistance and test request",
|
||||
"Uninstantiate",
|
||||
"Secure key generation",
|
||||
};
|
||||
|
||||
#define SPRINTFCAT(str, format, param, max_alloc) \
|
||||
{ \
|
||||
char *tmp; \
|
||||
\
|
||||
tmp = kmalloc(sizeof(format) + max_alloc, GFP_ATOMIC); \
|
||||
sprintf(tmp, format, param); \
|
||||
strcat(str, tmp); \
|
||||
kfree(tmp); \
|
||||
}
|
||||
|
||||
static void report_jump_idx(u32 status, char *outstr)
|
||||
{
|
||||
u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
|
||||
JRSTA_DECOERR_INDEX_SHIFT;
|
||||
|
||||
if (status & JRSTA_DECOERR_JUMP)
|
||||
strcat(outstr, "jump tgt desc idx ");
|
||||
else
|
||||
strcat(outstr, "desc idx ");
|
||||
|
||||
SPRINTFCAT(outstr, "%d: ", idx, sizeof("255"));
|
||||
}
|
||||
|
||||
static void report_ccb_status(u32 status, char *outstr)
|
||||
{
|
||||
u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
|
||||
JRSTA_CCBERR_CHAID_SHIFT;
|
||||
u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
|
||||
|
||||
report_jump_idx(status, outstr);
|
||||
|
||||
if (cha_id < ARRAY_SIZE(cha_id_list)) {
|
||||
SPRINTFCAT(outstr, "%s: ", cha_id_list[cha_id],
|
||||
strlen(cha_id_list[cha_id]));
|
||||
} else {
|
||||
SPRINTFCAT(outstr, "unidentified cha_id value 0x%02x: ",
|
||||
cha_id, sizeof("ff"));
|
||||
}
|
||||
|
||||
if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
|
||||
err_id < ARRAY_SIZE(rng_err_id_list) &&
|
||||
strlen(rng_err_id_list[err_id])) {
|
||||
/* RNG-only error */
|
||||
SPRINTFCAT(outstr, "%s", rng_err_id_list[err_id],
|
||||
strlen(rng_err_id_list[err_id]));
|
||||
} else if (err_id < ARRAY_SIZE(err_id_list)) {
|
||||
SPRINTFCAT(outstr, "%s", err_id_list[err_id],
|
||||
strlen(err_id_list[err_id]));
|
||||
} else {
|
||||
SPRINTFCAT(outstr, "unidentified err_id value 0x%02x",
|
||||
err_id, sizeof("ff"));
|
||||
}
|
||||
}
|
||||
|
||||
static void report_jump_status(u32 status, char *outstr)
|
||||
{
|
||||
SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
|
||||
}
|
||||
|
||||
static void report_deco_status(u32 status, char *outstr)
|
||||
{
|
||||
u8 desc_error = status & JRSTA_DECOERR_ERROR_MASK;
|
||||
int i;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user