error.c 7.3 KB

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