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