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