error.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * CAAM Error Reporting
  4. *
  5. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  6. */
  7. #include "compat.h"
  8. #include "regs.h"
  9. #include "desc.h"
  10. #include "error.h"
  11. #ifdef DEBUG
  12. #include <linux/highmem.h>
  13. void caam_dump_sg(const char *prefix_str, int prefix_type,
  14. int rowsize, int groupsize, struct scatterlist *sg,
  15. size_t tlen, bool ascii)
  16. {
  17. struct scatterlist *it;
  18. void *it_page;
  19. size_t len;
  20. void *buf;
  21. for (it = sg; it && tlen > 0 ; it = sg_next(it)) {
  22. /*
  23. * make sure the scatterlist's page
  24. * has a valid virtual memory mapping
  25. */
  26. it_page = kmap_atomic(sg_page(it));
  27. if (unlikely(!it_page)) {
  28. pr_err("caam_dump_sg: kmap failed\n");
  29. return;
  30. }
  31. buf = it_page + it->offset;
  32. len = min_t(size_t, tlen, it->length);
  33. print_hex_dump_debug(prefix_str, prefix_type, rowsize,
  34. groupsize, buf, len, ascii);
  35. tlen -= len;
  36. kunmap_atomic(it_page);
  37. }
  38. }
  39. #else
  40. void caam_dump_sg(const char *prefix_str, int prefix_type,
  41. int rowsize, int groupsize, struct scatterlist *sg,
  42. size_t tlen, bool ascii)
  43. {}
  44. #endif /* DEBUG */
  45. EXPORT_SYMBOL(caam_dump_sg);
  46. bool caam_little_end;
  47. EXPORT_SYMBOL(caam_little_end);
  48. bool caam_imx;
  49. EXPORT_SYMBOL(caam_imx);
  50. size_t caam_ptr_sz;
  51. EXPORT_SYMBOL(caam_ptr_sz);
  52. static const struct {
  53. u8 value;
  54. const char *error_text;
  55. } desc_error_list[] = {
  56. { 0x00, "No error." },
  57. { 0x01, "SGT Length Error. The descriptor is trying to read more data than is contained in the SGT table." },
  58. { 0x02, "SGT Null Entry Error." },
  59. { 0x03, "Job Ring Control Error. There is a bad value in the Job Ring Control register." },
  60. { 0x04, "Invalid Descriptor Command. The Descriptor Command field is invalid." },
  61. { 0x05, "Reserved." },
  62. { 0x06, "Invalid KEY Command" },
  63. { 0x07, "Invalid LOAD Command" },
  64. { 0x08, "Invalid STORE Command" },
  65. { 0x09, "Invalid OPERATION Command" },
  66. { 0x0A, "Invalid FIFO LOAD Command" },
  67. { 0x0B, "Invalid FIFO STORE Command" },
  68. { 0x0C, "Invalid MOVE/MOVE_LEN Command" },
  69. { 0x0D, "Invalid JUMP Command. A nonlocal JUMP Command is invalid because the target is not a Job Header Command, or the jump is from a Trusted Descriptor to a Job Descriptor, or because the target Descriptor contains a Shared Descriptor." },
  70. { 0x0E, "Invalid MATH Command" },
  71. { 0x0F, "Invalid SIGNATURE Command" },
  72. { 0x10, "Invalid Sequence Command. A SEQ IN PTR OR SEQ OUT PTR Command is invalid or a SEQ KEY, SEQ LOAD, SEQ FIFO LOAD, or SEQ FIFO STORE decremented the input or output sequence length below 0. This error may result if a built-in PROTOCOL Command has encountered a malformed PDU." },
  73. { 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
  74. { 0x12, "Shared Descriptor Header Error" },
  75. { 0x13, "Header Error. Invalid length or parity, or certain other problems." },
  76. { 0x14, "Burster Error. Burster has gotten to an illegal state" },
  77. { 0x15, "Context Register Length Error. The descriptor is trying to read or write past the end of the Context Register. A SEQ LOAD or SEQ STORE with the VLF bit set was executed with too large a length in the variable length register (VSOL for SEQ STORE or VSIL for SEQ LOAD)." },
  78. { 0x16, "DMA Error" },
  79. { 0x17, "Reserved." },
  80. { 0x1A, "Job failed due to JR reset" },
  81. { 0x1B, "Job failed due to Fail Mode" },
  82. { 0x1C, "DECO Watchdog timer timeout error" },
  83. { 0x1D, "DECO tried to copy a key from another DECO but the other DECO's Key Registers were locked" },
  84. { 0x1E, "DECO attempted to copy data from a DECO that had an unmasked Descriptor error" },
  85. { 0x1F, "LIODN error. DECO was trying to share from itself or from another DECO but the two Non-SEQ LIODN values didn't match or the 'shared from' DECO's Descriptor required that the SEQ LIODNs be the same and they aren't." },
  86. { 0x20, "DECO has completed a reset initiated via the DRR register" },
  87. { 0x21, "Nonce error. When using EKT (CCM) key encryption option in the FIFO STORE Command, the Nonce counter reached its maximum value and this encryption mode can no longer be used." },
  88. { 0x22, "Meta data is too large (> 511 bytes) for TLS decap (input frame; block ciphers) and IPsec decap (output frame, when doing the next header byte update) and DCRC (output frame)." },
  89. { 0x23, "Read Input Frame error" },
  90. { 0x24, "JDKEK, TDKEK or TDSK not loaded error" },
  91. { 0x80, "DNR (do not run) error" },
  92. { 0x81, "undefined protocol command" },
  93. { 0x82, "invalid setting in PDB" },
  94. { 0x83, "Anti-replay LATE error" },
  95. { 0x84, "Anti-replay REPLAY error" },
  96. { 0x85, "Sequence number overflow" },
  97. { 0x86, "Sigver invalid signature" },
  98. { 0x87, "DSA Sign Illegal test descriptor" },
  99. { 0x88, "Protocol Format Error - A protocol has seen an error in the format of data received. When running RSA, this means that formatting with random padding was used, and did not follow the form: 0x00, 0x02, 8-to-N bytes of non-zero pad, 0x00, F data." },
  100. { 0x89, "Protocol Size Error - A protocol has seen an error in size. When running RSA, pdb size N < (size of F) when no formatting is used; or pdb size N < (F + 11) when formatting is used." },
  101. { 0xC1, "Blob Command error: Undefined mode" },
  102. { 0xC2, "Blob Command error: Secure Memory Blob mode error" },
  103. { 0xC4, "Blob Command error: Black Blob key or input size 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, or was decremented to 0" },
  107. { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
  108. };
  109. static const struct {
  110. u8 value;
  111. const char *error_text;
  112. } qi_error_list[] = {
  113. { 0x00, "No error" },
  114. { 0x1F, "Job terminated by FQ or ICID flush" },
  115. { 0x20, "FD format error"},
  116. { 0x21, "FD command format error"},
  117. { 0x23, "FL format error"},
  118. { 0x25, "CRJD specified in FD, but not enabled in FLC"},
  119. { 0x30, "Max. buffer size too small"},
  120. { 0x31, "DHR exceeds max. buffer size (allocate mode, S/G format)"},
  121. { 0x32, "SGT exceeds max. buffer size (allocate mode, S/G format"},
  122. { 0x33, "Size over/underflow (allocate mode)"},
  123. { 0x34, "Size over/underflow (reuse mode)"},
  124. { 0x35, "Length exceeds max. short length (allocate mode, S/G/ format)"},
  125. { 0x36, "Memory footprint exceeds max. value (allocate mode, S/G/ format)"},
  126. { 0x41, "SBC frame format not supported (allocate mode)"},
  127. { 0x42, "Pool 0 invalid / pool 1 size < pool 0 size (allocate mode)"},
  128. { 0x43, "Annotation output enabled but ASAR = 0 (allocate mode)"},
  129. { 0x44, "Unsupported or reserved frame format or SGHR = 1 (reuse mode)"},
  130. { 0x45, "DHR correction underflow (reuse mode, single buffer format)"},
  131. { 0x46, "Annotation length exceeds offset (reuse mode)"},
  132. { 0x48, "Annotation output enabled but ASA limited by ASAR (reuse mode)"},
  133. { 0x49, "Data offset correction exceeds input frame data length (reuse mode)"},
  134. { 0x4B, "Annotation output enabled but ASA cannot be expanded (frame list)"},
  135. { 0x51, "Unsupported IF reuse mode"},
  136. { 0x52, "Unsupported FL use mode"},
  137. { 0x53, "Unsupported RJD use mode"},
  138. { 0x54, "Unsupported inline descriptor use mode"},
  139. { 0xC0, "Table buffer pool 0 depletion"},
  140. { 0xC1, "Table buffer pool 1 depletion"},
  141. { 0xC2, "Data buffer pool 0 depletion, no OF allocated"},
  142. { 0xC3, "Data buffer pool 1 depletion, no OF allocated"},
  143. { 0xC4, "Data buffer pool 0 depletion, partial OF allocated"},
  144. { 0xC5, "Data buffer pool 1 depletion, partial OF allocated"},
  145. { 0xD0, "FLC read error"},
  146. { 0xD1, "FL read error"},
  147. { 0xD2, "FL write error"},
  148. { 0xD3, "OF SGT write error"},
  149. { 0xD4, "PTA read error"},
  150. { 0xD5, "PTA write error"},
  151. { 0xD6, "OF SGT F-bit write error"},
  152. { 0xD7, "ASA write error"},
  153. { 0xE1, "FLC[ICR]=0 ICID error"},
  154. { 0xE2, "FLC[ICR]=1 ICID error"},
  155. { 0xE4, "source of ICID flush not trusted (BDI = 0)"},
  156. };
  157. static const char * const cha_id_list[] = {
  158. "",
  159. "AES",
  160. "DES",
  161. "ARC4",
  162. "MDHA",
  163. "RNG",
  164. "SNOW f8",
  165. "Kasumi f8/9",
  166. "PKHA",
  167. "CRCA",
  168. "SNOW f9",
  169. "ZUCE",
  170. "ZUCA",
  171. };
  172. static const char * const err_id_list[] = {
  173. "No error.",
  174. "Mode error.",
  175. "Data size error.",
  176. "Key size error.",
  177. "PKHA A memory size error.",
  178. "PKHA B memory size error.",
  179. "Data arrived out of sequence error.",
  180. "PKHA divide-by-zero error.",
  181. "PKHA modulus even error.",
  182. "DES key parity error.",
  183. "ICV check failed.",
  184. "Hardware error.",
  185. "Unsupported CCM AAD size.",
  186. "Class 1 CHA is not reset",
  187. "Invalid CHA combination was selected",
  188. "Invalid CHA selected.",
  189. };
  190. static const char * const rng_err_id_list[] = {
  191. "",
  192. "",
  193. "",
  194. "Instantiate",
  195. "Not instantiated",
  196. "Test instantiate",
  197. "Prediction resistance",
  198. "Prediction resistance and test request",
  199. "Uninstantiate",
  200. "Secure key generation",
  201. };
  202. static int report_ccb_status(struct device *jrdev, const u32 status,
  203. const char *error)
  204. {
  205. u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
  206. JRSTA_CCBERR_CHAID_SHIFT;
  207. u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
  208. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  209. JRSTA_DECOERR_INDEX_SHIFT;
  210. char *idx_str;
  211. const char *cha_str = "unidentified cha_id value 0x";
  212. char cha_err_code[3] = { 0 };
  213. const char *err_str = "unidentified err_id value 0x";
  214. char err_err_code[3] = { 0 };
  215. if (status & JRSTA_DECOERR_JUMP)
  216. idx_str = "jump tgt desc idx";
  217. else
  218. idx_str = "desc idx";
  219. if (cha_id < ARRAY_SIZE(cha_id_list))
  220. cha_str = cha_id_list[cha_id];
  221. else
  222. snprintf(cha_err_code, sizeof(cha_err_code), "%02x", cha_id);
  223. if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
  224. err_id < ARRAY_SIZE(rng_err_id_list) &&
  225. strlen(rng_err_id_list[err_id])) {
  226. /* RNG-only error */
  227. err_str = rng_err_id_list[err_id];
  228. } else {
  229. err_str = err_id_list[err_id];
  230. }
  231. /*
  232. * CCB ICV check failures are part of normal operation life;
  233. * we leave the upper layers to do what they want with them.
  234. */
  235. if (err_id == JRSTA_CCBERR_ERRID_ICVCHK)
  236. return -EBADMSG;
  237. dev_err_ratelimited(jrdev, "%08x: %s: %s %d: %s%s: %s%s\n", status,
  238. error, idx_str, idx, cha_str, cha_err_code,
  239. err_str, err_err_code);
  240. return -EINVAL;
  241. }
  242. static int report_jump_status(struct device *jrdev, const u32 status,
  243. const char *error)
  244. {
  245. dev_err(jrdev, "%08x: %s: %s() not implemented\n",
  246. status, error, __func__);
  247. return -EINVAL;
  248. }
  249. static int report_deco_status(struct device *jrdev, const u32 status,
  250. const char *error)
  251. {
  252. u8 err_id = status & JRSTA_DECOERR_ERROR_MASK;
  253. u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
  254. JRSTA_DECOERR_INDEX_SHIFT;
  255. char *idx_str;
  256. const char *err_str = "unidentified error value 0x";
  257. char err_err_code[3] = { 0 };
  258. int i;
  259. if (status & JRSTA_DECOERR_JUMP)
  260. idx_str = "jump tgt desc idx";
  261. else
  262. idx_str = "desc idx";
  263. for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
  264. if (desc_error_list[i].value == err_id)
  265. break;
  266. if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text)
  267. err_str = desc_error_list[i].error_text;
  268. else
  269. snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
  270. dev_err(jrdev, "%08x: %s: %s %d: %s%s\n",
  271. status, error, idx_str, idx, err_str, err_err_code);
  272. return -EINVAL;
  273. }
  274. static int report_qi_status(struct device *qidev, const u32 status,
  275. const char *error)
  276. {
  277. u8 err_id = status & JRSTA_QIERR_ERROR_MASK;
  278. const char *err_str = "unidentified error value 0x";
  279. char err_err_code[3] = { 0 };
  280. int i;
  281. for (i = 0; i < ARRAY_SIZE(qi_error_list); i++)
  282. if (qi_error_list[i].value == err_id)
  283. break;
  284. if (i != ARRAY_SIZE(qi_error_list) && qi_error_list[i].error_text)
  285. err_str = qi_error_list[i].error_text;
  286. else
  287. snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
  288. dev_err(qidev, "%08x: %s: %s%s\n",
  289. status, error, err_str, err_err_code);
  290. return -EINVAL;
  291. }
  292. static int report_jr_status(struct device *jrdev, const u32 status,
  293. const char *error)
  294. {
  295. dev_err(jrdev, "%08x: %s: %s() not implemented\n",
  296. status, error, __func__);
  297. return -EINVAL;
  298. }
  299. static int report_cond_code_status(struct device *jrdev, const u32 status,
  300. const char *error)
  301. {
  302. dev_err(jrdev, "%08x: %s: %s() not implemented\n",
  303. status, error, __func__);
  304. return -EINVAL;
  305. }
  306. int caam_strstatus(struct device *jrdev, u32 status, bool qi_v2)
  307. {
  308. static const struct stat_src {
  309. int (*report_ssed)(struct device *jrdev, const u32 status,
  310. const char *error);
  311. const char *error;
  312. } status_src[16] = {
  313. { NULL, "No error" },
  314. { NULL, NULL },
  315. { report_ccb_status, "CCB" },
  316. { report_jump_status, "Jump" },
  317. { report_deco_status, "DECO" },
  318. { report_qi_status, "Queue Manager Interface" },
  319. { report_jr_status, "Job Ring" },
  320. { report_cond_code_status, "Condition Code" },
  321. { NULL, NULL },
  322. { NULL, NULL },
  323. { NULL, NULL },
  324. { NULL, NULL },
  325. { NULL, NULL },
  326. { NULL, NULL },
  327. { NULL, NULL },
  328. { NULL, NULL },
  329. };
  330. u32 ssrc = status >> JRSTA_SSRC_SHIFT;
  331. const char *error = status_src[ssrc].error;
  332. /*
  333. * If there is an error handling function, call it to report the error.
  334. * Otherwise print the error source name.
  335. */
  336. if (status_src[ssrc].report_ssed)
  337. return status_src[ssrc].report_ssed(jrdev, status, error);
  338. if (error)
  339. dev_err(jrdev, "%d: %s\n", ssrc, error);
  340. else
  341. dev_err(jrdev, "%d: unknown error source\n", ssrc);
  342. return -EINVAL;
  343. }
  344. EXPORT_SYMBOL(caam_strstatus);
  345. MODULE_LICENSE("GPL");
  346. MODULE_DESCRIPTION("FSL CAAM error reporting");
  347. MODULE_AUTHOR("Freescale Semiconductor");