PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/crypto/caam/error.c

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