PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/crypto/caam/error.c

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