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