error.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * CAAM Error Reporting
  4. *
  5. * Copyright 2009-2014 Freescale Semiconductor, Inc.
  6. *
  7. * Derived from error.c file in linux drivers/crypto/caam
  8. */
  9. #include <common.h>
  10. #include <log.h>
  11. #include <malloc.h>
  12. #include "desc.h"
  13. #include "jr.h"
  14. #define CAAM_ERROR_STR_MAX 302
  15. #define JRSTA_SSRC_SHIFT 28
  16. #define JRSTA_CCBERR_CHAID_MASK 0x00f0
  17. #define JRSTA_CCBERR_CHAID_SHIFT 4
  18. #define JRSTA_CCBERR_ERRID_MASK 0x000
  19. #define JRSTA_CCBERR_CHAID_RNG (0x05 << JRSTA_CCBERR_CHAID_SHIFT)
  20. #define JRSTA_DECOERR_JUMP 0x08000000
  21. #define JRSTA_DECOERR_INDEX_SHIFT 8
  22. #define JRSTA_DECOERR_INDEX_MASK 0xff00
  23. #define JRSTA_DECOERR_ERROR_MASK 0x00ff
  24. static const struct {
  25. u8 value;
  26. const char *error_text;
  27. } desc_error_list[] = {
  28. { 0x00, "No error." },
  29. { 0x01, "SGT Length Error. The descriptor is trying to read" \
  30. " more data than is contained in the SGT table." },
  31. { 0x02, "SGT Null Entry Error." },
  32. { 0x03, "Job Ring Control Error. Bad value in Job Ring Control reg." },
  33. { 0x04, "Invalid Descriptor Command." },
  34. { 0x05, "Reserved." },
  35. { 0x06, "Invalid KEY Command" },
  36. { 0x07, "Invalid LOAD Command" },
  37. { 0x08, "Invalid STORE Command" },
  38. { 0x09, "Invalid OPERATION Command" },
  39. { 0x0A, "Invalid FIFO LOAD Command" },
  40. { 0x0B, "Invalid FIFO STORE Command" },
  41. { 0x0C, "Invalid MOVE/MOVE_LEN Command" },
  42. { 0x0D, "Invalid JUMP Command" },
  43. { 0x0E, "Invalid MATH Command" },
  44. { 0x0F, "Invalid SIGNATURE Command" },
  45. { 0x10, "Invalid Sequence Command" },
  46. { 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
  47. { 0x12, "Shared Descriptor Header Error" },
  48. { 0x13, "Header Error. Invalid length or parity, or other problems." },
  49. { 0x14, "Burster Error. Burster has gotten to an illegal state" },
  50. { 0x15, "Context Register Length Error" },
  51. { 0x16, "DMA Error" },
  52. { 0x17, "Reserved." },
  53. { 0x1A, "Job failed due to JR reset" },
  54. { 0x1B, "Job failed due to Fail Mode" },
  55. { 0x1C, "DECO Watchdog timer timeout error" },
  56. { 0x1D, "DECO tried to copy a key from another DECO but" \
  57. " the other DECO's Key Registers were locked" },
  58. { 0x1E, "DECO attempted to copy data from a DECO" \
  59. "that had an unmasked Descriptor error" },
  60. { 0x1F, "LIODN error" },
  61. { 0x20, "DECO has completed a reset initiated via the DRR register" },
  62. { 0x21, "Nonce error" },
  63. { 0x22, "Meta data is too large (> 511 bytes) for TLS decap" },
  64. { 0x23, "Read Input Frame error" },
  65. { 0x24, "JDKEK, TDKEK or TDSK not loaded error" },
  66. { 0x80, "DNR (do not run) error" },
  67. { 0x81, "undefined protocol command" },
  68. { 0x82, "invalid setting in PDB" },
  69. { 0x83, "Anti-replay LATE error" },
  70. { 0x84, "Anti-replay REPLAY error" },
  71. { 0x85, "Sequence number overflow" },
  72. { 0x86, "Sigver invalid signature" },
  73. { 0x87, "DSA Sign Illegal test descriptor" },
  74. { 0x88, "Protocol Format Error" },
  75. { 0x89, "Protocol Size Error" },
  76. { 0xC1, "Blob Command error: Undefined mode" },
  77. { 0xC2, "Blob Command error: Secure Memory Blob mode error" },
  78. { 0xC4, "Blob Command error: Black Blob key or input size error" },
  79. { 0xC5, "Blob Command error: Invalid key destination" },
  80. { 0xC8, "Blob Command error: Trusted/Secure mode error" },
  81. { 0xF0, "IPsec TTL or hop limit field is 0, or was decremented to 0" },
  82. { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
  83. };
  84. static const char * const cha_id_list[] = {
  85. "",
  86. "AES",
  87. "DES",
  88. "ARC4",
  89. "MDHA",
  90. "RNG",
  91. "SNOW f8",
  92. "Kasumi f8/9",
  93. "PKHA",
  94. "CRCA",
  95. "SNOW f9",
  96. "ZUCE",
  97. "ZUCA",
  98. };
  99. static const char * const err_id_list[] = {
  100. "No error.",
  101. "Mode error.",
  102. "Data size error.",
  103. "Key size error.",
  104. "PKHA A memory size error.",
  105. "PKHA B memory size error.",
  106. "Data arrived out of sequence error.",
  107. "PKHA divide-by-zero error.",
  108. "PKHA modulus even error.",
  109. "DES key parity error.",
  110. "ICV check failed.",
  111. "Hardware error.",
  112. "Unsupported CCM AAD size.",
  113. "Class 1 CHA is not reset",
  114. "Invalid CHA combination was selected",
  115. "Invalid CHA selected.",
  116. };
  117. static const char * const rng_err_id_list[] = {
  118. "",
  119. "",
  120. "",
  121. "Instantiate",
  122. "Not instantiated",
  123. "Test instantiate",
  124. "Prediction resistance",
  125. "Prediction resistance and test request",
  126. "Uninstantiate",
  127. "Secure key generation",
  128. };
  129. static void report_ccb_status(const u32 status,
  130. const char *error)
  131. {
  132. u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
  133. JRSTA_CCBERR_CHAID_SHIFT;
  134. u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
  135. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  136. JRSTA_DECOERR_INDEX_SHIFT;
  137. char *idx_str;
  138. const char *cha_str = "unidentified cha_id value 0x";
  139. char cha_err_code[3] = { 0 };
  140. const char *err_str = "unidentified err_id value 0x";
  141. char err_err_code[3] = { 0 };
  142. if (status & JRSTA_DECOERR_JUMP)
  143. idx_str = "jump tgt desc idx";
  144. else
  145. idx_str = "desc idx";
  146. if (cha_id < ARRAY_SIZE(cha_id_list))
  147. cha_str = cha_id_list[cha_id];
  148. else
  149. snprintf(cha_err_code, sizeof(cha_err_code), "%02x", cha_id);
  150. if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
  151. err_id < ARRAY_SIZE(rng_err_id_list) &&
  152. strlen(rng_err_id_list[err_id])) {
  153. /* RNG-only error */
  154. err_str = rng_err_id_list[err_id];
  155. } else if (err_id < ARRAY_SIZE(err_id_list)) {
  156. err_str = err_id_list[err_id];
  157. } else {
  158. snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
  159. }
  160. debug("%08x: %s: %s %d: %s%s: %s%s\n",
  161. status, error, idx_str, idx,
  162. cha_str, cha_err_code,
  163. err_str, err_err_code);
  164. }
  165. static void report_jump_status(const u32 status,
  166. const char *error)
  167. {
  168. debug("%08x: %s: %s() not implemented\n",
  169. status, error, __func__);
  170. }
  171. static void report_deco_status(const u32 status,
  172. const char *error)
  173. {
  174. u8 err_id = status & JRSTA_DECOERR_ERROR_MASK;
  175. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  176. JRSTA_DECOERR_INDEX_SHIFT;
  177. char *idx_str;
  178. const char *err_str = "unidentified error value 0x";
  179. char err_err_code[3] = { 0 };
  180. int i;
  181. if (status & JRSTA_DECOERR_JUMP)
  182. idx_str = "jump tgt desc idx";
  183. else
  184. idx_str = "desc idx";
  185. for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
  186. if (desc_error_list[i].value == err_id)
  187. break;
  188. if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text)
  189. err_str = desc_error_list[i].error_text;
  190. else
  191. snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
  192. debug("%08x: %s: %s %d: %s%s\n",
  193. status, error, idx_str, idx, err_str, err_err_code);
  194. }
  195. static void report_jr_status(const u32 status,
  196. const char *error)
  197. {
  198. debug("%08x: %s: %s() not implemented\n",
  199. status, error, __func__);
  200. }
  201. static void report_cond_code_status(const u32 status,
  202. const char *error)
  203. {
  204. debug("%08x: %s: %s() not implemented\n",
  205. status, error, __func__);
  206. }
  207. void caam_jr_strstatus(u32 status)
  208. {
  209. static const struct stat_src {
  210. void (*report_ssed)(const u32 status,
  211. const char *error);
  212. const char *error;
  213. } status_src[] = {
  214. { NULL, "No error" },
  215. { NULL, NULL },
  216. { report_ccb_status, "CCB" },
  217. { report_jump_status, "Jump" },
  218. { report_deco_status, "DECO" },
  219. { NULL, NULL },
  220. { report_jr_status, "Job Ring" },
  221. { report_cond_code_status, "Condition Code" },
  222. };
  223. u32 ssrc = status >> JRSTA_SSRC_SHIFT;
  224. const char *error = status_src[ssrc].error;
  225. /*
  226. * If there is no further error handling function, just
  227. * print the error code, error string and exit. Otherwise
  228. * call the handler function.
  229. */
  230. if (!status_src[ssrc].report_ssed)
  231. debug("%08x: %s:\n", status, status_src[ssrc].error);
  232. else
  233. status_src[ssrc].report_ssed(status, error);
  234. }