blob: 731c7484431603a4d6d00437e04b5944c80f1f9e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ruchika Guptab9eebfa2014-10-15 11:35:30 +05302/*
3 * CAAM Error Reporting
4 *
5 * Copyright 2009-2014 Freescale Semiconductor, Inc.
6 *
Ruchika Guptab9eebfa2014-10-15 11:35:30 +05307 * Derived from error.c file in linux drivers/crypto/caam
8 */
9
10#include <common.h>
11#include <malloc.h>
12#include "desc.h"
13#include "jr.h"
14
15#define CAAM_ERROR_STR_MAX 302
16
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)
22
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
27
28
29static const struct {
30 u8 value;
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" },
88};
89
90static const char * const cha_id_list[] = {
91 "",
92 "AES",
93 "DES",
94 "ARC4",
95 "MDHA",
96 "RNG",
97 "SNOW f8",
98 "Kasumi f8/9",
99 "PKHA",
100 "CRCA",
101 "SNOW f9",
102 "ZUCE",
103 "ZUCA",
104};
105
106static const char * const err_id_list[] = {
107 "No error.",
108 "Mode error.",
109 "Data size error.",
110 "Key size error.",
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.",
117 "ICV check failed.",
118 "Hardware error.",
119 "Unsupported CCM AAD size.",
120 "Class 1 CHA is not reset",
121 "Invalid CHA combination was selected",
122 "Invalid CHA selected.",
123};
124
125static const char * const rng_err_id_list[] = {
126 "",
127 "",
128 "",
129 "Instantiate",
130 "Not instantiated",
131 "Test instantiate",
132 "Prediction resistance",
133 "Prediction resistance and test request",
134 "Uninstantiate",
135 "Secure key generation",
136};
137
138static void report_ccb_status(const u32 status,
139 const char *error)
140{
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;
146 char *idx_str;
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 };
151
152 if (status & JRSTA_DECOERR_JUMP)
153 idx_str = "jump tgt desc idx";
154 else
155 idx_str = "desc idx";
156
157 if (cha_id < ARRAY_SIZE(cha_id_list))
158 cha_str = cha_id_list[cha_id];
159 else
160 snprintf(cha_err_code, sizeof(cha_err_code), "%02x", cha_id);
161
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])) {
165 /* RNG-only error */
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];
169 } else {
170 snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
171 }
172
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);
177}
178
179static void report_jump_status(const u32 status,
180 const char *error)
181{
182 debug("%08x: %s: %s() not implemented\n",
183 status, error, __func__);
184}
185
186static void report_deco_status(const u32 status,
187 const char *error)
188{
189 u8 err_id = status & JRSTA_DECOERR_ERROR_MASK;
190 u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
191 JRSTA_DECOERR_INDEX_SHIFT;
192 char *idx_str;
193 const char *err_str = "unidentified error value 0x";
194 char err_err_code[3] = { 0 };
195 int i;
196
197 if (status & JRSTA_DECOERR_JUMP)
198 idx_str = "jump tgt desc idx";
199 else
200 idx_str = "desc idx";
201
202 for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
203 if (desc_error_list[i].value == err_id)
204 break;
205
206 if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text)
207 err_str = desc_error_list[i].error_text;
208 else
209 snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
210
211 debug("%08x: %s: %s %d: %s%s\n",
212 status, error, idx_str, idx, err_str, err_err_code);
213}
214
215static void report_jr_status(const u32 status,
216 const char *error)
217{
218 debug("%08x: %s: %s() not implemented\n",
219 status, error, __func__);
220}
221
222static void report_cond_code_status(const u32 status,
223 const char *error)
224{
225 debug("%08x: %s: %s() not implemented\n",
226 status, error, __func__);
227}
228
229void caam_jr_strstatus(u32 status)
230{
231 static const struct stat_src {
232 void (*report_ssed)(const u32 status,
233 const char *error);
234 const char *error;
235 } status_src[] = {
236 { NULL, "No error" },
237 { NULL, NULL },
238 { report_ccb_status, "CCB" },
239 { report_jump_status, "Jump" },
240 { report_deco_status, "DECO" },
241 { NULL, NULL },
242 { report_jr_status, "Job Ring" },
243 { report_cond_code_status, "Condition Code" },
244 };
245 u32 ssrc = status >> JRSTA_SSRC_SHIFT;
246 const char *error = status_src[ssrc].error;
247
248 /*
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.
252 */
253 if (!status_src[ssrc].report_ssed)
254 debug("%08x: %s:\n", status, status_src[ssrc].error);
255 else
256 status_src[ssrc].report_ssed(status, error);
257}