error.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * CAAM Error Reporting
  3. *
  4. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  5. */
  6. #include "compat.h"
  7. #include "regs.h"
  8. #include "intern.h"
  9. #include "desc.h"
  10. #include "jr.h"
  11. #include "error.h"
  12. static const struct {
  13. u8 value;
  14. char *error_text;
  15. } desc_error_list[] = {
  16. { 0x00, "No error." },
  17. { 0x01, "SGT Length Error. The descriptor is trying to read "
  18. "more data than is contained in the SGT table." },
  19. { 0x02, "SGT Null Entry Error." },
  20. { 0x03, "Job Ring Control Error. There is a bad value in the "
  21. "Job Ring Control register." },
  22. { 0x04, "Invalid Descriptor Command. The Descriptor Command "
  23. "field is invalid." },
  24. { 0x05, "Reserved." },
  25. { 0x06, "Invalid KEY Command" },
  26. { 0x07, "Invalid LOAD Command" },
  27. { 0x08, "Invalid STORE Command" },
  28. { 0x09, "Invalid OPERATION Command" },
  29. { 0x0A, "Invalid FIFO LOAD Command" },
  30. { 0x0B, "Invalid FIFO STORE Command" },
  31. { 0x0C, "Invalid MOVE/MOVE_LEN Command" },
  32. { 0x0D, "Invalid JUMP Command. A nonlocal JUMP Command is "
  33. "invalid because the target is not a Job Header "
  34. "Command, or the jump is from a Trusted Descriptor to "
  35. "a Job Descriptor, or because the target Descriptor "
  36. "contains a Shared Descriptor." },
  37. { 0x0E, "Invalid MATH Command" },
  38. { 0x0F, "Invalid SIGNATURE Command" },
  39. { 0x10, "Invalid Sequence Command. A SEQ IN PTR OR SEQ OUT PTR "
  40. "Command is invalid or a SEQ KEY, SEQ LOAD, SEQ FIFO "
  41. "LOAD, or SEQ FIFO STORE decremented the input or "
  42. "output sequence length below 0. This error may result "
  43. "if a built-in PROTOCOL Command has encountered a "
  44. "malformed PDU." },
  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 certain "
  48. "other problems." },
  49. { 0x14, "Burster Error. Burster has gotten to an illegal "
  50. "state" },
  51. { 0x15, "Context Register Length Error. The descriptor is "
  52. "trying to read or write past the end of the Context "
  53. "Register. A SEQ LOAD or SEQ STORE with the VLF bit "
  54. "set was executed with too large a length in the "
  55. "variable length register (VSOL for SEQ STORE or VSIL "
  56. "for SEQ LOAD)." },
  57. { 0x16, "DMA Error" },
  58. { 0x17, "Reserved." },
  59. { 0x1A, "Job failed due to JR reset" },
  60. { 0x1B, "Job failed due to Fail Mode" },
  61. { 0x1C, "DECO Watchdog timer timeout error" },
  62. { 0x1D, "DECO tried to copy a key from another DECO but the "
  63. "other DECO's Key Registers were locked" },
  64. { 0x1E, "DECO attempted to copy data from a DECO that had an "
  65. "unmasked Descriptor error" },
  66. { 0x1F, "LIODN error. DECO was trying to share from itself or "
  67. "from another DECO but the two Non-SEQ LIODN values "
  68. "didn't match or the 'shared from' DECO's Descriptor "
  69. "required that the SEQ LIODNs be the same and they "
  70. "aren't." },
  71. { 0x20, "DECO has completed a reset initiated via the DRR "
  72. "register" },
  73. { 0x21, "Nonce error. When using EKT (CCM) key encryption "
  74. "option in the FIFO STORE Command, the Nonce counter "
  75. "reached its maximum value and this encryption mode "
  76. "can no longer be used." },
  77. { 0x22, "Meta data is too large (> 511 bytes) for TLS decap "
  78. "(input frame; block ciphers) and IPsec decap (output "
  79. "frame, when doing the next header byte update) and "
  80. "DCRC (output frame)." },
  81. { 0x23, "Read Input Frame error" },
  82. { 0x24, "JDKEK, TDKEK or TDSK not loaded error" },
  83. { 0x80, "DNR (do not run) error" },
  84. { 0x81, "undefined protocol command" },
  85. { 0x82, "invalid setting in PDB" },
  86. { 0x83, "Anti-replay LATE error" },
  87. { 0x84, "Anti-replay REPLAY error" },
  88. { 0x85, "Sequence number overflow" },
  89. { 0x86, "Sigver invalid signature" },
  90. { 0x87, "DSA Sign Illegal test descriptor" },
  91. { 0x88, "Protocol Format Error - A protocol has seen an error "
  92. "in the format of data received. When running RSA, "
  93. "this means that formatting with random padding was "
  94. "used, and did not follow the form: 0x00, 0x02, 8-to-N "
  95. "bytes of non-zero pad, 0x00, F data." },
  96. { 0x89, "Protocol Size Error - A protocol has seen an error in "
  97. "size. When running RSA, pdb size N < (size of F) when "
  98. "no formatting is used; or pdb size N < (F + 11) when "
  99. "formatting is used." },
  100. { 0xC1, "Blob Command error: Undefined mode" },
  101. { 0xC2, "Blob Command error: Secure Memory Blob mode error" },
  102. { 0xC4, "Blob Command error: Black Blob key or input size "
  103. "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, "
  107. "or was decremented to 0" },
  108. { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
  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. static const char * const err_id_list[] = {
  126. "No error.",
  127. "Mode error.",
  128. "Data size error.",
  129. "Key size error.",
  130. "PKHA A memory size error.",
  131. "PKHA B memory size error.",
  132. "Data arrived out of sequence error.",
  133. "PKHA divide-by-zero error.",
  134. "PKHA modulus even error.",
  135. "DES key parity error.",
  136. "ICV check failed.",
  137. "Hardware error.",
  138. "Unsupported CCM AAD size.",
  139. "Class 1 CHA is not reset",
  140. "Invalid CHA combination was selected",
  141. "Invalid CHA selected.",
  142. };
  143. static const char * const rng_err_id_list[] = {
  144. "",
  145. "",
  146. "",
  147. "Instantiate",
  148. "Not instantiated",
  149. "Test instantiate",
  150. "Prediction resistance",
  151. "Prediction resistance and test request",
  152. "Uninstantiate",
  153. "Secure key generation",
  154. };
  155. static void report_ccb_status(struct device *jrdev, u32 status,
  156. const char *error, char *__outstr)
  157. {
  158. u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
  159. JRSTA_CCBERR_CHAID_SHIFT;
  160. u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
  161. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  162. JRSTA_DECOERR_INDEX_SHIFT;
  163. char *idx_str;
  164. const char *cha_str = "unidentified cha_id value 0x";
  165. char cha_err_code[3] = { 0 };
  166. const char *err_str = "unidentified err_id value 0x";
  167. char err_err_code[3] = { 0 };
  168. if (status & JRSTA_DECOERR_JUMP)
  169. idx_str = "jump tgt desc idx";
  170. else
  171. idx_str = "desc idx";
  172. if (cha_id < ARRAY_SIZE(cha_id_list))
  173. cha_str = cha_id_list[cha_id];
  174. else
  175. snprintf(cha_err_code, sizeof(cha_err_code), "%02x", cha_id);
  176. if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
  177. err_id < ARRAY_SIZE(rng_err_id_list) &&
  178. strlen(rng_err_id_list[err_id])) {
  179. /* RNG-only error */
  180. err_str = rng_err_id_list[err_id];
  181. } else if (err_id < ARRAY_SIZE(err_id_list))
  182. err_str = err_id_list[err_id];
  183. else
  184. snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
  185. dev_err(jrdev, "%08x: %s: %s %d: %s%s: %s%s\n",
  186. status, error, idx_str, idx,
  187. cha_str, cha_err_code,
  188. err_str, err_err_code);
  189. }
  190. static void report_jump_status(struct device *jrdev, u32 status,
  191. const char *error, char *outstr)
  192. {
  193. dev_err(jrdev, "%08x: %s: %s() not implemented\n",
  194. status, error, __func__);
  195. }
  196. static void report_deco_status(struct device *jrdev, u32 status,
  197. const char *error, char *__outstr)
  198. {
  199. u8 err_id = status & JRSTA_DECOERR_ERROR_MASK;
  200. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  201. JRSTA_DECOERR_INDEX_SHIFT;
  202. char *idx_str;
  203. char *err_str = "unidentified error value 0x";
  204. char err_err_code[3] = { 0 };
  205. int i;
  206. if (status & JRSTA_DECOERR_JUMP)
  207. idx_str = "jump tgt desc idx";
  208. else
  209. idx_str = "desc idx";
  210. for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
  211. if (desc_error_list[i].value == err_id)
  212. break;
  213. if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text)
  214. err_str = desc_error_list[i].error_text;
  215. else
  216. snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
  217. dev_err(jrdev, "%08x: %s: %s %d: %s%s\n",
  218. status, error, idx_str, idx, err_str, err_err_code);
  219. }
  220. static void report_jr_status(struct device *jrdev, u32 status,
  221. const char *error, char *outstr)
  222. {
  223. dev_err(jrdev, "%08x: %s: %s() not implemented\n",
  224. status, error, __func__);
  225. }
  226. static void report_cond_code_status(struct device *jrdev, u32 status,
  227. const char *error, char *outstr)
  228. {
  229. dev_err(jrdev, "%08x: %s: %s() not implemented\n",
  230. status, error, __func__);
  231. }
  232. void caam_jr_strstatus(struct device *jrdev, u32 status)
  233. {
  234. static const struct stat_src {
  235. void (*report_ssed)(struct device *jrdev, u32 status,
  236. const char *error, char *outstr);
  237. const char *error;
  238. } status_src[] = {
  239. { NULL, "No error" },
  240. { NULL, NULL },
  241. { report_ccb_status, "CCB" },
  242. { report_jump_status, "Jump" },
  243. { report_deco_status, "DECO" },
  244. { NULL, NULL },
  245. { report_jr_status, "Job Ring" },
  246. { report_cond_code_status, "Condition Code" },
  247. };
  248. u32 ssrc = status >> JRSTA_SSRC_SHIFT;
  249. /*
  250. * If there is no further error handling function, just
  251. * print the error code, error string and exit.
  252. */
  253. if (!status_src[ssrc].report_ssed) {
  254. dev_err(jrdev, "%08x: %s: \n", status, status_src[ssrc].error);
  255. return;
  256. }
  257. status_src[ssrc].report_ssed(jrdev, status,
  258. status_src[ssrc].error, NULL);
  259. }
  260. EXPORT_SYMBOL(caam_jr_strstatus);