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