error.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. #define SPRINTFCAT(str, format, param, max_alloc) \
  13. { \
  14. char *tmp; \
  15. \
  16. tmp = kmalloc(sizeof(format) + max_alloc, GFP_ATOMIC); \
  17. if (likely(tmp)) { \
  18. sprintf(tmp, format, param); \
  19. strcat(str, tmp); \
  20. kfree(tmp); \
  21. } else { \
  22. strcat(str, "kmalloc failure in SPRINTFCAT"); \
  23. } \
  24. }
  25. static void report_jump_idx(u32 status, char *outstr)
  26. {
  27. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  28. JRSTA_DECOERR_INDEX_SHIFT;
  29. if (status & JRSTA_DECOERR_JUMP)
  30. strcat(outstr, "jump tgt desc idx ");
  31. else
  32. strcat(outstr, "desc idx ");
  33. SPRINTFCAT(outstr, "%d: ", idx, sizeof("255"));
  34. }
  35. static void report_ccb_status(u32 status, char *outstr)
  36. {
  37. char *cha_id_list[] = {
  38. "",
  39. "AES",
  40. "DES, 3DES",
  41. "ARC4",
  42. "MD5, SHA-1, SH-224, SHA-256, SHA-384, SHA-512",
  43. "RNG",
  44. "SNOW f8",
  45. "Kasumi f8, f9",
  46. "All Public Key Algorithms",
  47. "CRC",
  48. "SNOW f9",
  49. };
  50. char *err_id_list[] = {
  51. "None. No error.",
  52. "Mode error.",
  53. "Data size error.",
  54. "Key size error.",
  55. "PKHA A memory size error.",
  56. "PKHA B memory size error.",
  57. "Data arrived out of sequence error.",
  58. "PKHA divide-by-zero error.",
  59. "PKHA modulus even error.",
  60. "DES key parity error.",
  61. "ICV check failed.",
  62. "Hardware error.",
  63. "Unsupported CCM AAD size.",
  64. "Class 1 CHA is not reset",
  65. "Invalid CHA combination was selected",
  66. "Invalid CHA selected.",
  67. };
  68. u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
  69. JRSTA_CCBERR_CHAID_SHIFT;
  70. u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
  71. report_jump_idx(status, outstr);
  72. if (cha_id < ARRAY_SIZE(cha_id_list)) {
  73. SPRINTFCAT(outstr, "%s: ", cha_id_list[cha_id],
  74. strlen(cha_id_list[cha_id]));
  75. } else {
  76. SPRINTFCAT(outstr, "unidentified cha_id value 0x%02x: ",
  77. cha_id, sizeof("ff"));
  78. }
  79. if (err_id < ARRAY_SIZE(err_id_list)) {
  80. SPRINTFCAT(outstr, "%s", err_id_list[err_id],
  81. strlen(err_id_list[err_id]));
  82. } else {
  83. SPRINTFCAT(outstr, "unidentified err_id value 0x%02x",
  84. err_id, sizeof("ff"));
  85. }
  86. }
  87. static void report_jump_status(u32 status, char *outstr)
  88. {
  89. SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
  90. }
  91. static void report_deco_status(u32 status, char *outstr)
  92. {
  93. const struct {
  94. u8 value;
  95. char *error_text;
  96. } desc_error_list[] = {
  97. { 0x00, "None. No error." },
  98. { 0x01, "SGT Length Error. The descriptor is trying to read "
  99. "more data than is contained in the SGT table." },
  100. { 0x02, "Reserved." },
  101. { 0x03, "Job Ring Control Error. There is a bad value in the "
  102. "Job Ring Control register." },
  103. { 0x04, "Invalid Descriptor Command. The Descriptor Command "
  104. "field is invalid." },
  105. { 0x05, "Reserved." },
  106. { 0x06, "Invalid KEY Command" },
  107. { 0x07, "Invalid LOAD Command" },
  108. { 0x08, "Invalid STORE Command" },
  109. { 0x09, "Invalid OPERATION Command" },
  110. { 0x0A, "Invalid FIFO LOAD Command" },
  111. { 0x0B, "Invalid FIFO STORE Command" },
  112. { 0x0C, "Invalid MOVE Command" },
  113. { 0x0D, "Invalid JUMP Command. A nonlocal JUMP Command is "
  114. "invalid because the target is not a Job Header "
  115. "Command, or the jump is from a Trusted Descriptor to "
  116. "a Job Descriptor, or because the target Descriptor "
  117. "contains a Shared Descriptor." },
  118. { 0x0E, "Invalid MATH Command" },
  119. { 0x0F, "Invalid SIGNATURE Command" },
  120. { 0x10, "Invalid Sequence Command. A SEQ IN PTR OR SEQ OUT PTR "
  121. "Command is invalid or a SEQ KEY, SEQ LOAD, SEQ FIFO "
  122. "LOAD, or SEQ FIFO STORE decremented the input or "
  123. "output sequence length below 0. This error may result "
  124. "if a built-in PROTOCOL Command has encountered a "
  125. "malformed PDU." },
  126. { 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
  127. { 0x12, "Shared Descriptor Header Error" },
  128. { 0x13, "Header Error. Invalid length or parity, or certain "
  129. "other problems." },
  130. { 0x14, "Burster Error. Burster has gotten to an illegal "
  131. "state" },
  132. { 0x15, "Context Register Length Error. The descriptor is "
  133. "trying to read or write past the end of the Context "
  134. "Register. A SEQ LOAD or SEQ STORE with the VLF bit "
  135. "set was executed with too large a length in the "
  136. "variable length register (VSOL for SEQ STORE or VSIL "
  137. "for SEQ LOAD)." },
  138. { 0x16, "DMA Error" },
  139. { 0x17, "Reserved." },
  140. { 0x1A, "Job failed due to JR reset" },
  141. { 0x1B, "Job failed due to Fail Mode" },
  142. { 0x1C, "DECO Watchdog timer timeout error" },
  143. { 0x1D, "DECO tried to copy a key from another DECO but the "
  144. "other DECO's Key Registers were locked" },
  145. { 0x1E, "DECO attempted to copy data from a DECO that had an "
  146. "unmasked Descriptor error" },
  147. { 0x1F, "LIODN error. DECO was trying to share from itself or "
  148. "from another DECO but the two Non-SEQ LIODN values "
  149. "didn't match or the 'shared from' DECO's Descriptor "
  150. "required that the SEQ LIODNs be the same and they "
  151. "aren't." },
  152. { 0x20, "DECO has completed a reset initiated via the DRR "
  153. "register" },
  154. { 0x21, "Nonce error. When using EKT (CCM) key encryption "
  155. "option in the FIFO STORE Command, the Nonce counter "
  156. "reached its maximum value and this encryption mode "
  157. "can no longer be used." },
  158. { 0x22, "Meta data is too large (> 511 bytes) for TLS decap "
  159. "(input frame; block ciphers) and IPsec decap (output "
  160. "frame, when doing the next header byte update) and "
  161. "DCRC (output frame)." },
  162. { 0x80, "DNR (do not run) error" },
  163. { 0x81, "undefined protocol command" },
  164. { 0x82, "invalid setting in PDB" },
  165. { 0x83, "Anti-replay LATE error" },
  166. { 0x84, "Anti-replay REPLAY error" },
  167. { 0x85, "Sequence number overflow" },
  168. { 0x86, "Sigver invalid signature" },
  169. { 0x87, "DSA Sign Illegal test descriptor" },
  170. { 0x88, "Protocol Format Error - A protocol has seen an error "
  171. "in the format of data received. When running RSA, "
  172. "this means that formatting with random padding was "
  173. "used, and did not follow the form: 0x00, 0x02, 8-to-N "
  174. "bytes of non-zero pad, 0x00, F data." },
  175. { 0x89, "Protocol Size Error - A protocol has seen an error in "
  176. "size. When running RSA, pdb size N < (size of F) when "
  177. "no formatting is used; or pdb size N < (F + 11) when "
  178. "formatting is used." },
  179. { 0xC1, "Blob Command error: Undefined mode" },
  180. { 0xC2, "Blob Command error: Secure Memory Blob mode error" },
  181. { 0xC4, "Blob Command error: Black Blob key or input size "
  182. "error" },
  183. { 0xC5, "Blob Command error: Invalid key destination" },
  184. { 0xC8, "Blob Command error: Trusted/Secure mode error" },
  185. { 0xF0, "IPsec TTL or hop limit field either came in as 0, "
  186. "or was decremented to 0" },
  187. { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
  188. };
  189. u8 desc_error = status & JRSTA_DECOERR_ERROR_MASK;
  190. int i;
  191. report_jump_idx(status, outstr);
  192. for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
  193. if (desc_error_list[i].value == desc_error)
  194. break;
  195. if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text) {
  196. SPRINTFCAT(outstr, "%s", desc_error_list[i].error_text,
  197. strlen(desc_error_list[i].error_text));
  198. } else {
  199. SPRINTFCAT(outstr, "unidentified error value 0x%02x",
  200. desc_error, sizeof("ff"));
  201. }
  202. }
  203. static void report_jr_status(u32 status, char *outstr)
  204. {
  205. SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
  206. }
  207. static void report_cond_code_status(u32 status, char *outstr)
  208. {
  209. SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
  210. }
  211. char *caam_jr_strstatus(char *outstr, u32 status)
  212. {
  213. struct stat_src {
  214. void (*report_ssed)(u32 status, char *outstr);
  215. char *error;
  216. } status_src[] = {
  217. { NULL, "No error" },
  218. { NULL, NULL },
  219. { report_ccb_status, "CCB" },
  220. { report_jump_status, "Jump" },
  221. { report_deco_status, "DECO" },
  222. { NULL, NULL },
  223. { report_jr_status, "Job Ring" },
  224. { report_cond_code_status, "Condition Code" },
  225. };
  226. u32 ssrc = status >> JRSTA_SSRC_SHIFT;
  227. sprintf(outstr, "%s: ", status_src[ssrc].error);
  228. if (status_src[ssrc].report_ssed)
  229. status_src[ssrc].report_ssed(status, outstr);
  230. return outstr;
  231. }
  232. EXPORT_SYMBOL(caam_jr_strstatus);