4 * Copyright 2009-2014 Freescale Semiconductor, Inc.
6 * SPDX-License-Identifier: GPL-2.0+
8 * Derived from error.c file in linux drivers/crypto/caam
16 #define CAAM_ERROR_STR_MAX 302
18 #define JRSTA_SSRC_SHIFT 28
19 #define JRSTA_CCBERR_CHAID_MASK 0x00f0
20 #define JRSTA_CCBERR_CHAID_SHIFT 4
21 #define JRSTA_CCBERR_ERRID_MASK 0x000
22 #define JRSTA_CCBERR_CHAID_RNG (0x05 << JRSTA_CCBERR_CHAID_SHIFT)
24 #define JRSTA_DECOERR_JUMP 0x08000000
25 #define JRSTA_DECOERR_INDEX_SHIFT 8
26 #define JRSTA_DECOERR_INDEX_MASK 0xff00
27 #define JRSTA_DECOERR_ERROR_MASK 0x00ff
32 const char *error_text;
33 } desc_error_list[] = {
34 { 0x00, "No error." },
35 { 0x01, "SGT Length Error. The descriptor is trying to read" \
36 " more data than is contained in the SGT table." },
37 { 0x02, "SGT Null Entry Error." },
38 { 0x03, "Job Ring Control Error. Bad value in Job Ring Control reg." },
39 { 0x04, "Invalid Descriptor Command." },
40 { 0x05, "Reserved." },
41 { 0x06, "Invalid KEY Command" },
42 { 0x07, "Invalid LOAD Command" },
43 { 0x08, "Invalid STORE Command" },
44 { 0x09, "Invalid OPERATION Command" },
45 { 0x0A, "Invalid FIFO LOAD Command" },
46 { 0x0B, "Invalid FIFO STORE Command" },
47 { 0x0C, "Invalid MOVE/MOVE_LEN Command" },
48 { 0x0D, "Invalid JUMP Command" },
49 { 0x0E, "Invalid MATH Command" },
50 { 0x0F, "Invalid SIGNATURE Command" },
51 { 0x10, "Invalid Sequence Command" },
52 { 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
53 { 0x12, "Shared Descriptor Header Error" },
54 { 0x13, "Header Error. Invalid length or parity, or other problems." },
55 { 0x14, "Burster Error. Burster has gotten to an illegal state" },
56 { 0x15, "Context Register Length Error" },
57 { 0x16, "DMA Error" },
58 { 0x17, "Reserved." },
59 { 0x1A, "Job failed due to JR reset" },
60 { 0x1B, "Job failed due to Fail Mode" },
61 { 0x1C, "DECO Watchdog timer timeout error" },
62 { 0x1D, "DECO tried to copy a key from another DECO but" \
63 " the other DECO's Key Registers were locked" },
64 { 0x1E, "DECO attempted to copy data from a DECO" \
65 "that had an unmasked Descriptor error" },
66 { 0x1F, "LIODN error" },
67 { 0x20, "DECO has completed a reset initiated via the DRR register" },
68 { 0x21, "Nonce error" },
69 { 0x22, "Meta data is too large (> 511 bytes) for TLS decap" },
70 { 0x23, "Read Input Frame error" },
71 { 0x24, "JDKEK, TDKEK or TDSK not loaded error" },
72 { 0x80, "DNR (do not run) error" },
73 { 0x81, "undefined protocol command" },
74 { 0x82, "invalid setting in PDB" },
75 { 0x83, "Anti-replay LATE error" },
76 { 0x84, "Anti-replay REPLAY error" },
77 { 0x85, "Sequence number overflow" },
78 { 0x86, "Sigver invalid signature" },
79 { 0x87, "DSA Sign Illegal test descriptor" },
80 { 0x88, "Protocol Format Error" },
81 { 0x89, "Protocol Size Error" },
82 { 0xC1, "Blob Command error: Undefined mode" },
83 { 0xC2, "Blob Command error: Secure Memory Blob mode error" },
84 { 0xC4, "Blob Command error: Black Blob key or input size error" },
85 { 0xC5, "Blob Command error: Invalid key destination" },
86 { 0xC8, "Blob Command error: Trusted/Secure mode error" },
87 { 0xF0, "IPsec TTL or hop limit field is 0, or was decremented to 0" },
88 { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
91 static const char * const cha_id_list[] = {
107 static const char * const err_id_list[] = {
112 "PKHA A memory size error.",
113 "PKHA B memory size error.",
114 "Data arrived out of sequence error.",
115 "PKHA divide-by-zero error.",
116 "PKHA modulus even error.",
117 "DES key parity error.",
120 "Unsupported CCM AAD size.",
121 "Class 1 CHA is not reset",
122 "Invalid CHA combination was selected",
123 "Invalid CHA selected.",
126 static const char * const rng_err_id_list[] = {
133 "Prediction resistance",
134 "Prediction resistance and test request",
136 "Secure key generation",
139 static void report_ccb_status(const u32 status,
142 u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
143 JRSTA_CCBERR_CHAID_SHIFT;
144 u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
145 u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
146 JRSTA_DECOERR_INDEX_SHIFT;
148 const char *cha_str = "unidentified cha_id value 0x";
149 char cha_err_code[3] = { 0 };
150 const char *err_str = "unidentified err_id value 0x";
151 char err_err_code[3] = { 0 };
153 if (status & JRSTA_DECOERR_JUMP)
154 idx_str = "jump tgt desc idx";
156 idx_str = "desc idx";
158 if (cha_id < ARRAY_SIZE(cha_id_list))
159 cha_str = cha_id_list[cha_id];
161 snprintf(cha_err_code, sizeof(cha_err_code), "%02x", cha_id);
163 if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
164 err_id < ARRAY_SIZE(rng_err_id_list) &&
165 strlen(rng_err_id_list[err_id])) {
167 err_str = rng_err_id_list[err_id];
168 } else if (err_id < ARRAY_SIZE(err_id_list)) {
169 err_str = err_id_list[err_id];
171 snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
174 debug("%08x: %s: %s %d: %s%s: %s%s\n",
175 status, error, idx_str, idx,
176 cha_str, cha_err_code,
177 err_str, err_err_code);
180 static void report_jump_status(const u32 status,
183 debug("%08x: %s: %s() not implemented\n",
184 status, error, __func__);
187 static void report_deco_status(const u32 status,
190 u8 err_id = status & JRSTA_DECOERR_ERROR_MASK;
191 u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
192 JRSTA_DECOERR_INDEX_SHIFT;
194 const char *err_str = "unidentified error value 0x";
195 char err_err_code[3] = { 0 };
198 if (status & JRSTA_DECOERR_JUMP)
199 idx_str = "jump tgt desc idx";
201 idx_str = "desc idx";
203 for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
204 if (desc_error_list[i].value == err_id)
207 if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text)
208 err_str = desc_error_list[i].error_text;
210 snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
212 debug("%08x: %s: %s %d: %s%s\n",
213 status, error, idx_str, idx, err_str, err_err_code);
216 static void report_jr_status(const u32 status,
219 debug("%08x: %s: %s() not implemented\n",
220 status, error, __func__);
223 static void report_cond_code_status(const u32 status,
226 debug("%08x: %s: %s() not implemented\n",
227 status, error, __func__);
230 void caam_jr_strstatus(u32 status)
232 static const struct stat_src {
233 void (*report_ssed)(const u32 status,
237 { NULL, "No error" },
239 { report_ccb_status, "CCB" },
240 { report_jump_status, "Jump" },
241 { report_deco_status, "DECO" },
243 { report_jr_status, "Job Ring" },
244 { report_cond_code_status, "Condition Code" },
246 u32 ssrc = status >> JRSTA_SSRC_SHIFT;
247 const char *error = status_src[ssrc].error;
250 * If there is no further error handling function, just
251 * print the error code, error string and exit. Otherwise
252 * call the handler function.
254 if (!status_src[ssrc].report_ssed)
255 debug("%08x: %s:\n", status, status_src[ssrc].error);
257 status_src[ssrc].report_ssed(status, error);