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