18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * CAAM Error Reporting
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2009-2011 Freescale Semiconductor, Inc.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "compat.h"
98c2ecf20Sopenharmony_ci#include "regs.h"
108c2ecf20Sopenharmony_ci#include "desc.h"
118c2ecf20Sopenharmony_ci#include "error.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifdef DEBUG
148c2ecf20Sopenharmony_ci#include <linux/highmem.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_civoid caam_dump_sg(const char *prefix_str, int prefix_type,
178c2ecf20Sopenharmony_ci		  int rowsize, int groupsize, struct scatterlist *sg,
188c2ecf20Sopenharmony_ci		  size_t tlen, bool ascii)
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	struct scatterlist *it;
218c2ecf20Sopenharmony_ci	void *it_page;
228c2ecf20Sopenharmony_ci	size_t len;
238c2ecf20Sopenharmony_ci	void *buf;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	for (it = sg; it && tlen > 0 ; it = sg_next(it)) {
268c2ecf20Sopenharmony_ci		/*
278c2ecf20Sopenharmony_ci		 * make sure the scatterlist's page
288c2ecf20Sopenharmony_ci		 * has a valid virtual memory mapping
298c2ecf20Sopenharmony_ci		 */
308c2ecf20Sopenharmony_ci		it_page = kmap_atomic(sg_page(it));
318c2ecf20Sopenharmony_ci		if (unlikely(!it_page)) {
328c2ecf20Sopenharmony_ci			pr_err("caam_dump_sg: kmap failed\n");
338c2ecf20Sopenharmony_ci			return;
348c2ecf20Sopenharmony_ci		}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci		buf = it_page + it->offset;
378c2ecf20Sopenharmony_ci		len = min_t(size_t, tlen, it->length);
388c2ecf20Sopenharmony_ci		print_hex_dump_debug(prefix_str, prefix_type, rowsize,
398c2ecf20Sopenharmony_ci				     groupsize, buf, len, ascii);
408c2ecf20Sopenharmony_ci		tlen -= len;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci		kunmap_atomic(it_page);
438c2ecf20Sopenharmony_ci	}
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci#else
468c2ecf20Sopenharmony_civoid caam_dump_sg(const char *prefix_str, int prefix_type,
478c2ecf20Sopenharmony_ci		  int rowsize, int groupsize, struct scatterlist *sg,
488c2ecf20Sopenharmony_ci		  size_t tlen, bool ascii)
498c2ecf20Sopenharmony_ci{}
508c2ecf20Sopenharmony_ci#endif /* DEBUG */
518c2ecf20Sopenharmony_ciEXPORT_SYMBOL(caam_dump_sg);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cibool caam_little_end;
548c2ecf20Sopenharmony_ciEXPORT_SYMBOL(caam_little_end);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cibool caam_imx;
578c2ecf20Sopenharmony_ciEXPORT_SYMBOL(caam_imx);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cisize_t caam_ptr_sz;
608c2ecf20Sopenharmony_ciEXPORT_SYMBOL(caam_ptr_sz);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic const struct {
638c2ecf20Sopenharmony_ci	u8 value;
648c2ecf20Sopenharmony_ci	const char *error_text;
658c2ecf20Sopenharmony_ci} desc_error_list[] = {
668c2ecf20Sopenharmony_ci	{ 0x00, "No error." },
678c2ecf20Sopenharmony_ci	{ 0x01, "SGT Length Error. The descriptor is trying to read more data than is contained in the SGT table." },
688c2ecf20Sopenharmony_ci	{ 0x02, "SGT Null Entry Error." },
698c2ecf20Sopenharmony_ci	{ 0x03, "Job Ring Control Error. There is a bad value in the Job Ring Control register." },
708c2ecf20Sopenharmony_ci	{ 0x04, "Invalid Descriptor Command. The Descriptor Command field is invalid." },
718c2ecf20Sopenharmony_ci	{ 0x05, "Reserved." },
728c2ecf20Sopenharmony_ci	{ 0x06, "Invalid KEY Command" },
738c2ecf20Sopenharmony_ci	{ 0x07, "Invalid LOAD Command" },
748c2ecf20Sopenharmony_ci	{ 0x08, "Invalid STORE Command" },
758c2ecf20Sopenharmony_ci	{ 0x09, "Invalid OPERATION Command" },
768c2ecf20Sopenharmony_ci	{ 0x0A, "Invalid FIFO LOAD Command" },
778c2ecf20Sopenharmony_ci	{ 0x0B, "Invalid FIFO STORE Command" },
788c2ecf20Sopenharmony_ci	{ 0x0C, "Invalid MOVE/MOVE_LEN Command" },
798c2ecf20Sopenharmony_ci	{ 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." },
808c2ecf20Sopenharmony_ci	{ 0x0E, "Invalid MATH Command" },
818c2ecf20Sopenharmony_ci	{ 0x0F, "Invalid SIGNATURE Command" },
828c2ecf20Sopenharmony_ci	{ 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." },
838c2ecf20Sopenharmony_ci	{ 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
848c2ecf20Sopenharmony_ci	{ 0x12, "Shared Descriptor Header Error" },
858c2ecf20Sopenharmony_ci	{ 0x13, "Header Error. Invalid length or parity, or certain other problems." },
868c2ecf20Sopenharmony_ci	{ 0x14, "Burster Error. Burster has gotten to an illegal state" },
878c2ecf20Sopenharmony_ci	{ 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)." },
888c2ecf20Sopenharmony_ci	{ 0x16, "DMA Error" },
898c2ecf20Sopenharmony_ci	{ 0x17, "Reserved." },
908c2ecf20Sopenharmony_ci	{ 0x1A, "Job failed due to JR reset" },
918c2ecf20Sopenharmony_ci	{ 0x1B, "Job failed due to Fail Mode" },
928c2ecf20Sopenharmony_ci	{ 0x1C, "DECO Watchdog timer timeout error" },
938c2ecf20Sopenharmony_ci	{ 0x1D, "DECO tried to copy a key from another DECO but the other DECO's Key Registers were locked" },
948c2ecf20Sopenharmony_ci	{ 0x1E, "DECO attempted to copy data from a DECO that had an unmasked Descriptor error" },
958c2ecf20Sopenharmony_ci	{ 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." },
968c2ecf20Sopenharmony_ci	{ 0x20, "DECO has completed a reset initiated via the DRR register" },
978c2ecf20Sopenharmony_ci	{ 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." },
988c2ecf20Sopenharmony_ci	{ 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)." },
998c2ecf20Sopenharmony_ci	{ 0x23, "Read Input Frame error" },
1008c2ecf20Sopenharmony_ci	{ 0x24, "JDKEK, TDKEK or TDSK not loaded error" },
1018c2ecf20Sopenharmony_ci	{ 0x80, "DNR (do not run) error" },
1028c2ecf20Sopenharmony_ci	{ 0x81, "undefined protocol command" },
1038c2ecf20Sopenharmony_ci	{ 0x82, "invalid setting in PDB" },
1048c2ecf20Sopenharmony_ci	{ 0x83, "Anti-replay LATE error" },
1058c2ecf20Sopenharmony_ci	{ 0x84, "Anti-replay REPLAY error" },
1068c2ecf20Sopenharmony_ci	{ 0x85, "Sequence number overflow" },
1078c2ecf20Sopenharmony_ci	{ 0x86, "Sigver invalid signature" },
1088c2ecf20Sopenharmony_ci	{ 0x87, "DSA Sign Illegal test descriptor" },
1098c2ecf20Sopenharmony_ci	{ 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." },
1108c2ecf20Sopenharmony_ci	{ 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." },
1118c2ecf20Sopenharmony_ci	{ 0xC1, "Blob Command error: Undefined mode" },
1128c2ecf20Sopenharmony_ci	{ 0xC2, "Blob Command error: Secure Memory Blob mode error" },
1138c2ecf20Sopenharmony_ci	{ 0xC4, "Blob Command error: Black Blob key or input size error" },
1148c2ecf20Sopenharmony_ci	{ 0xC5, "Blob Command error: Invalid key destination" },
1158c2ecf20Sopenharmony_ci	{ 0xC8, "Blob Command error: Trusted/Secure mode error" },
1168c2ecf20Sopenharmony_ci	{ 0xF0, "IPsec TTL or hop limit field either came in as 0, or was decremented to 0" },
1178c2ecf20Sopenharmony_ci	{ 0xF1, "3GPP HFN matches or exceeds the Threshold" },
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic const struct {
1218c2ecf20Sopenharmony_ci	u8 value;
1228c2ecf20Sopenharmony_ci	const char *error_text;
1238c2ecf20Sopenharmony_ci} qi_error_list[] = {
1248c2ecf20Sopenharmony_ci	{ 0x00, "No error" },
1258c2ecf20Sopenharmony_ci	{ 0x1F, "Job terminated by FQ or ICID flush" },
1268c2ecf20Sopenharmony_ci	{ 0x20, "FD format error"},
1278c2ecf20Sopenharmony_ci	{ 0x21, "FD command format error"},
1288c2ecf20Sopenharmony_ci	{ 0x23, "FL format error"},
1298c2ecf20Sopenharmony_ci	{ 0x25, "CRJD specified in FD, but not enabled in FLC"},
1308c2ecf20Sopenharmony_ci	{ 0x30, "Max. buffer size too small"},
1318c2ecf20Sopenharmony_ci	{ 0x31, "DHR exceeds max. buffer size (allocate mode, S/G format)"},
1328c2ecf20Sopenharmony_ci	{ 0x32, "SGT exceeds max. buffer size (allocate mode, S/G format"},
1338c2ecf20Sopenharmony_ci	{ 0x33, "Size over/underflow (allocate mode)"},
1348c2ecf20Sopenharmony_ci	{ 0x34, "Size over/underflow (reuse mode)"},
1358c2ecf20Sopenharmony_ci	{ 0x35, "Length exceeds max. short length (allocate mode, S/G/ format)"},
1368c2ecf20Sopenharmony_ci	{ 0x36, "Memory footprint exceeds max. value (allocate mode, S/G/ format)"},
1378c2ecf20Sopenharmony_ci	{ 0x41, "SBC frame format not supported (allocate mode)"},
1388c2ecf20Sopenharmony_ci	{ 0x42, "Pool 0 invalid / pool 1 size < pool 0 size (allocate mode)"},
1398c2ecf20Sopenharmony_ci	{ 0x43, "Annotation output enabled but ASAR = 0 (allocate mode)"},
1408c2ecf20Sopenharmony_ci	{ 0x44, "Unsupported or reserved frame format or SGHR = 1 (reuse mode)"},
1418c2ecf20Sopenharmony_ci	{ 0x45, "DHR correction underflow (reuse mode, single buffer format)"},
1428c2ecf20Sopenharmony_ci	{ 0x46, "Annotation length exceeds offset (reuse mode)"},
1438c2ecf20Sopenharmony_ci	{ 0x48, "Annotation output enabled but ASA limited by ASAR (reuse mode)"},
1448c2ecf20Sopenharmony_ci	{ 0x49, "Data offset correction exceeds input frame data length (reuse mode)"},
1458c2ecf20Sopenharmony_ci	{ 0x4B, "Annotation output enabled but ASA cannot be expanded (frame list)"},
1468c2ecf20Sopenharmony_ci	{ 0x51, "Unsupported IF reuse mode"},
1478c2ecf20Sopenharmony_ci	{ 0x52, "Unsupported FL use mode"},
1488c2ecf20Sopenharmony_ci	{ 0x53, "Unsupported RJD use mode"},
1498c2ecf20Sopenharmony_ci	{ 0x54, "Unsupported inline descriptor use mode"},
1508c2ecf20Sopenharmony_ci	{ 0xC0, "Table buffer pool 0 depletion"},
1518c2ecf20Sopenharmony_ci	{ 0xC1, "Table buffer pool 1 depletion"},
1528c2ecf20Sopenharmony_ci	{ 0xC2, "Data buffer pool 0 depletion, no OF allocated"},
1538c2ecf20Sopenharmony_ci	{ 0xC3, "Data buffer pool 1 depletion, no OF allocated"},
1548c2ecf20Sopenharmony_ci	{ 0xC4, "Data buffer pool 0 depletion, partial OF allocated"},
1558c2ecf20Sopenharmony_ci	{ 0xC5, "Data buffer pool 1 depletion, partial OF allocated"},
1568c2ecf20Sopenharmony_ci	{ 0xD0, "FLC read error"},
1578c2ecf20Sopenharmony_ci	{ 0xD1, "FL read error"},
1588c2ecf20Sopenharmony_ci	{ 0xD2, "FL write error"},
1598c2ecf20Sopenharmony_ci	{ 0xD3, "OF SGT write error"},
1608c2ecf20Sopenharmony_ci	{ 0xD4, "PTA read error"},
1618c2ecf20Sopenharmony_ci	{ 0xD5, "PTA write error"},
1628c2ecf20Sopenharmony_ci	{ 0xD6, "OF SGT F-bit write error"},
1638c2ecf20Sopenharmony_ci	{ 0xD7, "ASA write error"},
1648c2ecf20Sopenharmony_ci	{ 0xE1, "FLC[ICR]=0 ICID error"},
1658c2ecf20Sopenharmony_ci	{ 0xE2, "FLC[ICR]=1 ICID error"},
1668c2ecf20Sopenharmony_ci	{ 0xE4, "source of ICID flush not trusted (BDI = 0)"},
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistatic const char * const cha_id_list[] = {
1708c2ecf20Sopenharmony_ci	"",
1718c2ecf20Sopenharmony_ci	"AES",
1728c2ecf20Sopenharmony_ci	"DES",
1738c2ecf20Sopenharmony_ci	"ARC4",
1748c2ecf20Sopenharmony_ci	"MDHA",
1758c2ecf20Sopenharmony_ci	"RNG",
1768c2ecf20Sopenharmony_ci	"SNOW f8",
1778c2ecf20Sopenharmony_ci	"Kasumi f8/9",
1788c2ecf20Sopenharmony_ci	"PKHA",
1798c2ecf20Sopenharmony_ci	"CRCA",
1808c2ecf20Sopenharmony_ci	"SNOW f9",
1818c2ecf20Sopenharmony_ci	"ZUCE",
1828c2ecf20Sopenharmony_ci	"ZUCA",
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic const char * const err_id_list[] = {
1868c2ecf20Sopenharmony_ci	"No error.",
1878c2ecf20Sopenharmony_ci	"Mode error.",
1888c2ecf20Sopenharmony_ci	"Data size error.",
1898c2ecf20Sopenharmony_ci	"Key size error.",
1908c2ecf20Sopenharmony_ci	"PKHA A memory size error.",
1918c2ecf20Sopenharmony_ci	"PKHA B memory size error.",
1928c2ecf20Sopenharmony_ci	"Data arrived out of sequence error.",
1938c2ecf20Sopenharmony_ci	"PKHA divide-by-zero error.",
1948c2ecf20Sopenharmony_ci	"PKHA modulus even error.",
1958c2ecf20Sopenharmony_ci	"DES key parity error.",
1968c2ecf20Sopenharmony_ci	"ICV check failed.",
1978c2ecf20Sopenharmony_ci	"Hardware error.",
1988c2ecf20Sopenharmony_ci	"Unsupported CCM AAD size.",
1998c2ecf20Sopenharmony_ci	"Class 1 CHA is not reset",
2008c2ecf20Sopenharmony_ci	"Invalid CHA combination was selected",
2018c2ecf20Sopenharmony_ci	"Invalid CHA selected.",
2028c2ecf20Sopenharmony_ci};
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic const char * const rng_err_id_list[] = {
2058c2ecf20Sopenharmony_ci	"",
2068c2ecf20Sopenharmony_ci	"",
2078c2ecf20Sopenharmony_ci	"",
2088c2ecf20Sopenharmony_ci	"Instantiate",
2098c2ecf20Sopenharmony_ci	"Not instantiated",
2108c2ecf20Sopenharmony_ci	"Test instantiate",
2118c2ecf20Sopenharmony_ci	"Prediction resistance",
2128c2ecf20Sopenharmony_ci	"Prediction resistance and test request",
2138c2ecf20Sopenharmony_ci	"Uninstantiate",
2148c2ecf20Sopenharmony_ci	"Secure key generation",
2158c2ecf20Sopenharmony_ci	"",
2168c2ecf20Sopenharmony_ci	"Hardware error",
2178c2ecf20Sopenharmony_ci	"Continuous check"
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic int report_ccb_status(struct device *jrdev, const u32 status,
2218c2ecf20Sopenharmony_ci			     const char *error)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
2248c2ecf20Sopenharmony_ci		    JRSTA_CCBERR_CHAID_SHIFT;
2258c2ecf20Sopenharmony_ci	u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
2268c2ecf20Sopenharmony_ci	u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
2278c2ecf20Sopenharmony_ci		  JRSTA_DECOERR_INDEX_SHIFT;
2288c2ecf20Sopenharmony_ci	char *idx_str;
2298c2ecf20Sopenharmony_ci	const char *cha_str = "unidentified cha_id value 0x";
2308c2ecf20Sopenharmony_ci	char cha_err_code[3] = { 0 };
2318c2ecf20Sopenharmony_ci	const char *err_str = "unidentified err_id value 0x";
2328c2ecf20Sopenharmony_ci	char err_err_code[3] = { 0 };
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	if (status & JRSTA_DECOERR_JUMP)
2358c2ecf20Sopenharmony_ci		idx_str = "jump tgt desc idx";
2368c2ecf20Sopenharmony_ci	else
2378c2ecf20Sopenharmony_ci		idx_str = "desc idx";
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	if (cha_id < ARRAY_SIZE(cha_id_list))
2408c2ecf20Sopenharmony_ci		cha_str = cha_id_list[cha_id];
2418c2ecf20Sopenharmony_ci	else
2428c2ecf20Sopenharmony_ci		snprintf(cha_err_code, sizeof(cha_err_code), "%02x", cha_id);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	if ((cha_id << JRSTA_CCBERR_CHAID_SHIFT) == JRSTA_CCBERR_CHAID_RNG &&
2458c2ecf20Sopenharmony_ci	    err_id < ARRAY_SIZE(rng_err_id_list) &&
2468c2ecf20Sopenharmony_ci	    strlen(rng_err_id_list[err_id])) {
2478c2ecf20Sopenharmony_ci		/* RNG-only error */
2488c2ecf20Sopenharmony_ci		err_str = rng_err_id_list[err_id];
2498c2ecf20Sopenharmony_ci	} else {
2508c2ecf20Sopenharmony_ci		err_str = err_id_list[err_id];
2518c2ecf20Sopenharmony_ci	}
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	/*
2548c2ecf20Sopenharmony_ci	 * CCB ICV check failures are part of normal operation life;
2558c2ecf20Sopenharmony_ci	 * we leave the upper layers to do what they want with them.
2568c2ecf20Sopenharmony_ci	 */
2578c2ecf20Sopenharmony_ci	if (err_id == JRSTA_CCBERR_ERRID_ICVCHK)
2588c2ecf20Sopenharmony_ci		return -EBADMSG;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	dev_err_ratelimited(jrdev, "%08x: %s: %s %d: %s%s: %s%s\n", status,
2618c2ecf20Sopenharmony_ci			    error, idx_str, idx, cha_str, cha_err_code,
2628c2ecf20Sopenharmony_ci			    err_str, err_err_code);
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	return -EINVAL;
2658c2ecf20Sopenharmony_ci}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistatic int report_jump_status(struct device *jrdev, const u32 status,
2688c2ecf20Sopenharmony_ci			      const char *error)
2698c2ecf20Sopenharmony_ci{
2708c2ecf20Sopenharmony_ci	dev_err(jrdev, "%08x: %s: %s() not implemented\n",
2718c2ecf20Sopenharmony_ci		status, error, __func__);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	return -EINVAL;
2748c2ecf20Sopenharmony_ci}
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_cistatic int report_deco_status(struct device *jrdev, const u32 status,
2778c2ecf20Sopenharmony_ci			      const char *error)
2788c2ecf20Sopenharmony_ci{
2798c2ecf20Sopenharmony_ci	u8 err_id = status & JRSTA_DECOERR_ERROR_MASK;
2808c2ecf20Sopenharmony_ci	u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
2818c2ecf20Sopenharmony_ci		  JRSTA_DECOERR_INDEX_SHIFT;
2828c2ecf20Sopenharmony_ci	char *idx_str;
2838c2ecf20Sopenharmony_ci	const char *err_str = "unidentified error value 0x";
2848c2ecf20Sopenharmony_ci	char err_err_code[3] = { 0 };
2858c2ecf20Sopenharmony_ci	int i;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	if (status & JRSTA_DECOERR_JUMP)
2888c2ecf20Sopenharmony_ci		idx_str = "jump tgt desc idx";
2898c2ecf20Sopenharmony_ci	else
2908c2ecf20Sopenharmony_ci		idx_str = "desc idx";
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
2938c2ecf20Sopenharmony_ci		if (desc_error_list[i].value == err_id)
2948c2ecf20Sopenharmony_ci			break;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text)
2978c2ecf20Sopenharmony_ci		err_str = desc_error_list[i].error_text;
2988c2ecf20Sopenharmony_ci	else
2998c2ecf20Sopenharmony_ci		snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	dev_err(jrdev, "%08x: %s: %s %d: %s%s\n",
3028c2ecf20Sopenharmony_ci		status, error, idx_str, idx, err_str, err_err_code);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	return -EINVAL;
3058c2ecf20Sopenharmony_ci}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_cistatic int report_qi_status(struct device *qidev, const u32 status,
3088c2ecf20Sopenharmony_ci			    const char *error)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	u8 err_id = status & JRSTA_QIERR_ERROR_MASK;
3118c2ecf20Sopenharmony_ci	const char *err_str = "unidentified error value 0x";
3128c2ecf20Sopenharmony_ci	char err_err_code[3] = { 0 };
3138c2ecf20Sopenharmony_ci	int i;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(qi_error_list); i++)
3168c2ecf20Sopenharmony_ci		if (qi_error_list[i].value == err_id)
3178c2ecf20Sopenharmony_ci			break;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	if (i != ARRAY_SIZE(qi_error_list) && qi_error_list[i].error_text)
3208c2ecf20Sopenharmony_ci		err_str = qi_error_list[i].error_text;
3218c2ecf20Sopenharmony_ci	else
3228c2ecf20Sopenharmony_ci		snprintf(err_err_code, sizeof(err_err_code), "%02x", err_id);
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci	dev_err(qidev, "%08x: %s: %s%s\n",
3258c2ecf20Sopenharmony_ci		status, error, err_str, err_err_code);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	return -EINVAL;
3288c2ecf20Sopenharmony_ci}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic int report_jr_status(struct device *jrdev, const u32 status,
3318c2ecf20Sopenharmony_ci			    const char *error)
3328c2ecf20Sopenharmony_ci{
3338c2ecf20Sopenharmony_ci	dev_err(jrdev, "%08x: %s: %s() not implemented\n",
3348c2ecf20Sopenharmony_ci		status, error, __func__);
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	return -EINVAL;
3378c2ecf20Sopenharmony_ci}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistatic int report_cond_code_status(struct device *jrdev, const u32 status,
3408c2ecf20Sopenharmony_ci				   const char *error)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	dev_err(jrdev, "%08x: %s: %s() not implemented\n",
3438c2ecf20Sopenharmony_ci		status, error, __func__);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	return -EINVAL;
3468c2ecf20Sopenharmony_ci}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ciint caam_strstatus(struct device *jrdev, u32 status, bool qi_v2)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	static const struct stat_src {
3518c2ecf20Sopenharmony_ci		int (*report_ssed)(struct device *jrdev, const u32 status,
3528c2ecf20Sopenharmony_ci				   const char *error);
3538c2ecf20Sopenharmony_ci		const char *error;
3548c2ecf20Sopenharmony_ci	} status_src[16] = {
3558c2ecf20Sopenharmony_ci		{ NULL, "No error" },
3568c2ecf20Sopenharmony_ci		{ NULL, NULL },
3578c2ecf20Sopenharmony_ci		{ report_ccb_status, "CCB" },
3588c2ecf20Sopenharmony_ci		{ report_jump_status, "Jump" },
3598c2ecf20Sopenharmony_ci		{ report_deco_status, "DECO" },
3608c2ecf20Sopenharmony_ci		{ report_qi_status, "Queue Manager Interface" },
3618c2ecf20Sopenharmony_ci		{ report_jr_status, "Job Ring" },
3628c2ecf20Sopenharmony_ci		{ report_cond_code_status, "Condition Code" },
3638c2ecf20Sopenharmony_ci		{ NULL, NULL },
3648c2ecf20Sopenharmony_ci		{ NULL, NULL },
3658c2ecf20Sopenharmony_ci		{ NULL, NULL },
3668c2ecf20Sopenharmony_ci		{ NULL, NULL },
3678c2ecf20Sopenharmony_ci		{ NULL, NULL },
3688c2ecf20Sopenharmony_ci		{ NULL, NULL },
3698c2ecf20Sopenharmony_ci		{ NULL, NULL },
3708c2ecf20Sopenharmony_ci		{ NULL, NULL },
3718c2ecf20Sopenharmony_ci	};
3728c2ecf20Sopenharmony_ci	u32 ssrc = status >> JRSTA_SSRC_SHIFT;
3738c2ecf20Sopenharmony_ci	const char *error = status_src[ssrc].error;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	/*
3768c2ecf20Sopenharmony_ci	 * If there is an error handling function, call it to report the error.
3778c2ecf20Sopenharmony_ci	 * Otherwise print the error source name.
3788c2ecf20Sopenharmony_ci	 */
3798c2ecf20Sopenharmony_ci	if (status_src[ssrc].report_ssed)
3808c2ecf20Sopenharmony_ci		return status_src[ssrc].report_ssed(jrdev, status, error);
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	if (error)
3838c2ecf20Sopenharmony_ci		dev_err(jrdev, "%d: %s\n", ssrc, error);
3848c2ecf20Sopenharmony_ci	else
3858c2ecf20Sopenharmony_ci		dev_err(jrdev, "%d: unknown error source\n", ssrc);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	return -EINVAL;
3888c2ecf20Sopenharmony_ci}
3898c2ecf20Sopenharmony_ciEXPORT_SYMBOL(caam_strstatus);
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
3928c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("FSL CAAM error reporting");
3938c2ecf20Sopenharmony_ciMODULE_AUTHOR("Freescale Semiconductor");
394