xref: /openbmc/linux/drivers/crypto/caam/error.c (revision 12eb4683)
1 /*
2  * CAAM Error Reporting
3  *
4  * Copyright 2009-2011 Freescale Semiconductor, Inc.
5  */
6 
7 #include "compat.h"
8 #include "regs.h"
9 #include "intern.h"
10 #include "desc.h"
11 #include "jr.h"
12 #include "error.h"
13 
14 #define SPRINTFCAT(str, format, param, max_alloc)		\
15 {								\
16 	char *tmp;						\
17 								\
18 	tmp = kmalloc(sizeof(format) + max_alloc, GFP_ATOMIC);	\
19 	sprintf(tmp, format, param);				\
20 	strcat(str, tmp);					\
21 	kfree(tmp);						\
22 }
23 
24 static void report_jump_idx(u32 status, char *outstr)
25 {
26 	u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
27 		  JRSTA_DECOERR_INDEX_SHIFT;
28 
29 	if (status & JRSTA_DECOERR_JUMP)
30 		strcat(outstr, "jump tgt desc idx ");
31 	else
32 		strcat(outstr, "desc idx ");
33 
34 	SPRINTFCAT(outstr, "%d: ", idx, sizeof("255"));
35 }
36 
37 static void report_ccb_status(u32 status, char *outstr)
38 {
39 	static const char * const cha_id_list[] = {
40 		"",
41 		"AES",
42 		"DES",
43 		"ARC4",
44 		"MDHA",
45 		"RNG",
46 		"SNOW f8",
47 		"Kasumi f8/9",
48 		"PKHA",
49 		"CRCA",
50 		"SNOW f9",
51 		"ZUCE",
52 		"ZUCA",
53 	};
54 	static const char * const err_id_list[] = {
55 		"No error.",
56 		"Mode error.",
57 		"Data size error.",
58 		"Key size error.",
59 		"PKHA A memory size error.",
60 		"PKHA B memory size error.",
61 		"Data arrived out of sequence error.",
62 		"PKHA divide-by-zero error.",
63 		"PKHA modulus even error.",
64 		"DES key parity error.",
65 		"ICV check failed.",
66 		"Hardware error.",
67 		"Unsupported CCM AAD size.",
68 		"Class 1 CHA is not reset",
69 		"Invalid CHA combination was selected",
70 		"Invalid CHA selected.",
71 	};
72 	static const char * const rng_err_id_list[] = {
73 		"",
74 		"",
75 		"",
76 		"Instantiate",
77 		"Not instantiated",
78 		"Test instantiate",
79 		"Prediction resistance",
80 		"Prediction resistance and test request",
81 		"Uninstantiate",
82 		"Secure key generation",
83 	};
84 	u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
85 		    JRSTA_CCBERR_CHAID_SHIFT;
86 	u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
87 
88 	report_jump_idx(status, outstr);
89 
90 	if (cha_id < ARRAY_SIZE(cha_id_list)) {
91 		SPRINTFCAT(outstr, "%s: ", cha_id_list[cha_id],
92 			   strlen(cha_id_list[cha_id]));
93 	} else {
94 		SPRINTFCAT(outstr, "unidentified cha_id value 0x%02x: ",
95 			   cha_id, sizeof("ff"));
96 	}
97 
98 	if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
99 	    err_id < ARRAY_SIZE(rng_err_id_list) &&
100 	    strlen(rng_err_id_list[err_id])) {
101 		/* RNG-only error */
102 		SPRINTFCAT(outstr, "%s", rng_err_id_list[err_id],
103 			   strlen(rng_err_id_list[err_id]));
104 	} else if (err_id < ARRAY_SIZE(err_id_list)) {
105 		SPRINTFCAT(outstr, "%s", err_id_list[err_id],
106 			   strlen(err_id_list[err_id]));
107 	} else {
108 		SPRINTFCAT(outstr, "unidentified err_id value 0x%02x",
109 			   err_id, sizeof("ff"));
110 	}
111 }
112 
113 static void report_jump_status(u32 status, char *outstr)
114 {
115 	SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
116 }
117 
118 static void report_deco_status(u32 status, char *outstr)
119 {
120 	static const struct {
121 		u8 value;
122 		char *error_text;
123 	} desc_error_list[] = {
124 		{ 0x00, "No error." },
125 		{ 0x01, "SGT Length Error. The descriptor is trying to read "
126 			"more data than is contained in the SGT table." },
127 		{ 0x02, "SGT Null Entry Error." },
128 		{ 0x03, "Job Ring Control Error. There is a bad value in the "
129 			"Job Ring Control register." },
130 		{ 0x04, "Invalid Descriptor Command. The Descriptor Command "
131 			"field is invalid." },
132 		{ 0x05, "Reserved." },
133 		{ 0x06, "Invalid KEY Command" },
134 		{ 0x07, "Invalid LOAD Command" },
135 		{ 0x08, "Invalid STORE Command" },
136 		{ 0x09, "Invalid OPERATION Command" },
137 		{ 0x0A, "Invalid FIFO LOAD Command" },
138 		{ 0x0B, "Invalid FIFO STORE Command" },
139 		{ 0x0C, "Invalid MOVE/MOVE_LEN Command" },
140 		{ 0x0D, "Invalid JUMP Command. A nonlocal JUMP Command is "
141 			"invalid because the target is not a Job Header "
142 			"Command, or the jump is from a Trusted Descriptor to "
143 			"a Job Descriptor, or because the target Descriptor "
144 			"contains a Shared Descriptor." },
145 		{ 0x0E, "Invalid MATH Command" },
146 		{ 0x0F, "Invalid SIGNATURE Command" },
147 		{ 0x10, "Invalid Sequence Command. A SEQ IN PTR OR SEQ OUT PTR "
148 			"Command is invalid or a SEQ KEY, SEQ LOAD, SEQ FIFO "
149 			"LOAD, or SEQ FIFO STORE decremented the input or "
150 			"output sequence length below 0. This error may result "
151 			"if a built-in PROTOCOL Command has encountered a "
152 			"malformed PDU." },
153 		{ 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
154 		{ 0x12, "Shared Descriptor Header Error" },
155 		{ 0x13, "Header Error. Invalid length or parity, or certain "
156 			"other problems." },
157 		{ 0x14, "Burster Error. Burster has gotten to an illegal "
158 			"state" },
159 		{ 0x15, "Context Register Length Error. The descriptor is "
160 			"trying to read or write past the end of the Context "
161 			"Register. A SEQ LOAD or SEQ STORE with the VLF bit "
162 			"set was executed with too large a length in the "
163 			"variable length register (VSOL for SEQ STORE or VSIL "
164 			"for SEQ LOAD)." },
165 		{ 0x16, "DMA Error" },
166 		{ 0x17, "Reserved." },
167 		{ 0x1A, "Job failed due to JR reset" },
168 		{ 0x1B, "Job failed due to Fail Mode" },
169 		{ 0x1C, "DECO Watchdog timer timeout error" },
170 		{ 0x1D, "DECO tried to copy a key from another DECO but the "
171 			"other DECO's Key Registers were locked" },
172 		{ 0x1E, "DECO attempted to copy data from a DECO that had an "
173 			"unmasked Descriptor error" },
174 		{ 0x1F, "LIODN error. DECO was trying to share from itself or "
175 			"from another DECO but the two Non-SEQ LIODN values "
176 			"didn't match or the 'shared from' DECO's Descriptor "
177 			"required that the SEQ LIODNs be the same and they "
178 			"aren't." },
179 		{ 0x20, "DECO has completed a reset initiated via the DRR "
180 			"register" },
181 		{ 0x21, "Nonce error. When using EKT (CCM) key encryption "
182 			"option in the FIFO STORE Command, the Nonce counter "
183 			"reached its maximum value and this encryption mode "
184 			"can no longer be used." },
185 		{ 0x22, "Meta data is too large (> 511 bytes) for TLS decap "
186 			"(input frame; block ciphers) and IPsec decap (output "
187 			"frame, when doing the next header byte update) and "
188 			"DCRC (output frame)." },
189 		{ 0x23, "Read Input Frame error" },
190 		{ 0x24, "JDKEK, TDKEK or TDSK not loaded error" },
191 		{ 0x80, "DNR (do not run) error" },
192 		{ 0x81, "undefined protocol command" },
193 		{ 0x82, "invalid setting in PDB" },
194 		{ 0x83, "Anti-replay LATE error" },
195 		{ 0x84, "Anti-replay REPLAY error" },
196 		{ 0x85, "Sequence number overflow" },
197 		{ 0x86, "Sigver invalid signature" },
198 		{ 0x87, "DSA Sign Illegal test descriptor" },
199 		{ 0x88, "Protocol Format Error - A protocol has seen an error "
200 			"in the format of data received. When running RSA, "
201 			"this means that formatting with random padding was "
202 			"used, and did not follow the form: 0x00, 0x02, 8-to-N "
203 			"bytes of non-zero pad, 0x00, F data." },
204 		{ 0x89, "Protocol Size Error - A protocol has seen an error in "
205 			"size. When running RSA, pdb size N < (size of F) when "
206 			"no formatting is used; or pdb size N < (F + 11) when "
207 			"formatting is used." },
208 		{ 0xC1, "Blob Command error: Undefined mode" },
209 		{ 0xC2, "Blob Command error: Secure Memory Blob mode error" },
210 		{ 0xC4, "Blob Command error: Black Blob key or input size "
211 			"error" },
212 		{ 0xC5, "Blob Command error: Invalid key destination" },
213 		{ 0xC8, "Blob Command error: Trusted/Secure mode error" },
214 		{ 0xF0, "IPsec TTL or hop limit field either came in as 0, "
215 			"or was decremented to 0" },
216 		{ 0xF1, "3GPP HFN matches or exceeds the Threshold" },
217 	};
218 	u8 desc_error = status & JRSTA_DECOERR_ERROR_MASK;
219 	int i;
220 
221 	report_jump_idx(status, outstr);
222 
223 	for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
224 		if (desc_error_list[i].value == desc_error)
225 			break;
226 
227 	if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text) {
228 		SPRINTFCAT(outstr, "%s", desc_error_list[i].error_text,
229 			   strlen(desc_error_list[i].error_text));
230 	} else {
231 		SPRINTFCAT(outstr, "unidentified error value 0x%02x",
232 			   desc_error, sizeof("ff"));
233 	}
234 }
235 
236 static void report_jr_status(u32 status, char *outstr)
237 {
238 	SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
239 }
240 
241 static void report_cond_code_status(u32 status, char *outstr)
242 {
243 	SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
244 }
245 
246 char *caam_jr_strstatus(char *outstr, u32 status)
247 {
248 	static const struct stat_src {
249 		void (*report_ssed)(u32 status, char *outstr);
250 		char *error;
251 	} status_src[] = {
252 		{ NULL, "No error" },
253 		{ NULL, NULL },
254 		{ report_ccb_status, "CCB" },
255 		{ report_jump_status, "Jump" },
256 		{ report_deco_status, "DECO" },
257 		{ NULL, NULL },
258 		{ report_jr_status, "Job Ring" },
259 		{ report_cond_code_status, "Condition Code" },
260 	};
261 	u32 ssrc = status >> JRSTA_SSRC_SHIFT;
262 
263 	sprintf(outstr, "%s: ", status_src[ssrc].error);
264 
265 	if (status_src[ssrc].report_ssed)
266 		status_src[ssrc].report_ssed(status, outstr);
267 
268 	return outstr;
269 }
270 EXPORT_SYMBOL(caam_jr_strstatus);
271