PageRenderTime 62ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/crypto/caam/error.c

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