18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Marvell
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Antoine Tenart <antoine.tenart@free-electrons.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __SAFEXCEL_H__
98c2ecf20Sopenharmony_ci#define __SAFEXCEL_H__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <crypto/aead.h>
128c2ecf20Sopenharmony_ci#include <crypto/algapi.h>
138c2ecf20Sopenharmony_ci#include <crypto/internal/hash.h>
148c2ecf20Sopenharmony_ci#include <crypto/sha.h>
158c2ecf20Sopenharmony_ci#include <crypto/sha3.h>
168c2ecf20Sopenharmony_ci#include <crypto/skcipher.h>
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define EIP197_HIA_VERSION_BE			0xca35
208c2ecf20Sopenharmony_ci#define EIP197_HIA_VERSION_LE			0x35ca
218c2ecf20Sopenharmony_ci#define EIP97_VERSION_LE			0x9e61
228c2ecf20Sopenharmony_ci#define EIP196_VERSION_LE			0x3bc4
238c2ecf20Sopenharmony_ci#define EIP197_VERSION_LE			0x3ac5
248c2ecf20Sopenharmony_ci#define EIP96_VERSION_LE			0x9f60
258c2ecf20Sopenharmony_ci#define EIP201_VERSION_LE			0x36c9
268c2ecf20Sopenharmony_ci#define EIP206_VERSION_LE			0x31ce
278c2ecf20Sopenharmony_ci#define EIP207_VERSION_LE			0x30cf
288c2ecf20Sopenharmony_ci#define EIP197_REG_LO16(reg)			(reg & 0xffff)
298c2ecf20Sopenharmony_ci#define EIP197_REG_HI16(reg)			((reg >> 16) & 0xffff)
308c2ecf20Sopenharmony_ci#define EIP197_VERSION_MASK(reg)		((reg >> 16) & 0xfff)
318c2ecf20Sopenharmony_ci#define EIP197_VERSION_SWAP(reg)		(((reg & 0xf0) << 4) | \
328c2ecf20Sopenharmony_ci						((reg >> 4) & 0xf0) | \
338c2ecf20Sopenharmony_ci						((reg >> 12) & 0xf))
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* EIP197 HIA OPTIONS ENCODING */
368c2ecf20Sopenharmony_ci#define EIP197_HIA_OPT_HAS_PE_ARB		BIT(29)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* EIP206 OPTIONS ENCODING */
398c2ecf20Sopenharmony_ci#define EIP206_OPT_ICE_TYPE(n)			((n>>8)&3)
408c2ecf20Sopenharmony_ci#define EIP206_OPT_OCE_TYPE(n)			((n>>10)&3)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* EIP197 OPTIONS ENCODING */
438c2ecf20Sopenharmony_ci#define EIP197_OPT_HAS_TRC			BIT(31)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Static configuration */
468c2ecf20Sopenharmony_ci#define EIP197_DEFAULT_RING_SIZE		400
478c2ecf20Sopenharmony_ci#define EIP197_EMB_TOKENS			4 /* Pad CD to 16 dwords */
488c2ecf20Sopenharmony_ci#define EIP197_MAX_TOKENS			16
498c2ecf20Sopenharmony_ci#define EIP197_MAX_RINGS			4
508c2ecf20Sopenharmony_ci#define EIP197_FETCH_DEPTH			2
518c2ecf20Sopenharmony_ci#define EIP197_MAX_BATCH_SZ			64
528c2ecf20Sopenharmony_ci#define EIP197_MAX_RING_AIC			14
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define EIP197_GFP_FLAGS(base)	((base).flags & CRYPTO_TFM_REQ_MAY_SLEEP ? \
558c2ecf20Sopenharmony_ci				 GFP_KERNEL : GFP_ATOMIC)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Custom on-stack requests (for invalidation) */
588c2ecf20Sopenharmony_ci#define EIP197_SKCIPHER_REQ_SIZE	sizeof(struct skcipher_request) + \
598c2ecf20Sopenharmony_ci					sizeof(struct safexcel_cipher_req)
608c2ecf20Sopenharmony_ci#define EIP197_AHASH_REQ_SIZE		sizeof(struct ahash_request) + \
618c2ecf20Sopenharmony_ci					sizeof(struct safexcel_ahash_req)
628c2ecf20Sopenharmony_ci#define EIP197_AEAD_REQ_SIZE		sizeof(struct aead_request) + \
638c2ecf20Sopenharmony_ci					sizeof(struct safexcel_cipher_req)
648c2ecf20Sopenharmony_ci#define EIP197_REQUEST_ON_STACK(name, type, size) \
658c2ecf20Sopenharmony_ci	char __##name##_desc[size] CRYPTO_MINALIGN_ATTR; \
668c2ecf20Sopenharmony_ci	struct type##_request *name = (void *)__##name##_desc
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* Xilinx dev board base offsets */
698c2ecf20Sopenharmony_ci#define EIP197_XLX_GPIO_BASE		0x200000
708c2ecf20Sopenharmony_ci#define EIP197_XLX_IRQ_BLOCK_ID_ADDR	0x2000
718c2ecf20Sopenharmony_ci#define EIP197_XLX_IRQ_BLOCK_ID_VALUE	0x1fc2
728c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_INT_ENB_MSK	0x2004
738c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_INT_ENB_SET	0x2008
748c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_INT_ENB_CLEAR	0x200c
758c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_INT_BLOCK	0x2040
768c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_INT_PEND	0x2048
778c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT0_ADDR	0x2080
788c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT0_IDENT	0x03020100
798c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT1_ADDR	0x2084
808c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT1_IDENT	0x07060504
818c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT2_ADDR	0x2088
828c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT2_IDENT	0x0b0a0908
838c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT3_ADDR	0x208c
848c2ecf20Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT3_IDENT	0x0f0e0d0c
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/* Helper defines for probe function */
878c2ecf20Sopenharmony_ci#define EIP197_IRQ_NUMBER(i, is_pci)	(i + is_pci)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* Register base offsets */
908c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC(priv)		((priv)->base + (priv)->offsets.hia_aic)
918c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_G(priv)		((priv)->base + (priv)->offsets.hia_aic_g)
928c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R(priv)		((priv)->base + (priv)->offsets.hia_aic_r)
938c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_xDR(priv)	((priv)->base + (priv)->offsets.hia_aic_xdr)
948c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE(priv)		((priv)->base + (priv)->offsets.hia_dfe)
958c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_THR(priv)	((priv)->base + (priv)->offsets.hia_dfe_thr)
968c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE(priv)		((priv)->base + (priv)->offsets.hia_dse)
978c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_THR(priv)	((priv)->base + (priv)->offsets.hia_dse_thr)
988c2ecf20Sopenharmony_ci#define EIP197_HIA_GEN_CFG(priv)	((priv)->base + (priv)->offsets.hia_gen_cfg)
998c2ecf20Sopenharmony_ci#define EIP197_PE(priv)			((priv)->base + (priv)->offsets.pe)
1008c2ecf20Sopenharmony_ci#define EIP197_GLOBAL(priv)		((priv)->base + (priv)->offsets.global)
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* EIP197 base offsets */
1038c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_BASE		0x90000
1048c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_G_BASE		0x90000
1058c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_BASE		0x90800
1068c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_xDR_BASE		0x80000
1078c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_BASE		0x8c000
1088c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_THR_BASE		0x8c040
1098c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_BASE		0x8d000
1108c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_THR_BASE		0x8d040
1118c2ecf20Sopenharmony_ci#define EIP197_HIA_GEN_CFG_BASE		0xf0000
1128c2ecf20Sopenharmony_ci#define EIP197_PE_BASE			0xa0000
1138c2ecf20Sopenharmony_ci#define EIP197_GLOBAL_BASE		0xf0000
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* EIP97 base offsets */
1168c2ecf20Sopenharmony_ci#define EIP97_HIA_AIC_BASE		0x0
1178c2ecf20Sopenharmony_ci#define EIP97_HIA_AIC_G_BASE		0x0
1188c2ecf20Sopenharmony_ci#define EIP97_HIA_AIC_R_BASE		0x0
1198c2ecf20Sopenharmony_ci#define EIP97_HIA_AIC_xDR_BASE		0x0
1208c2ecf20Sopenharmony_ci#define EIP97_HIA_DFE_BASE		0xf000
1218c2ecf20Sopenharmony_ci#define EIP97_HIA_DFE_THR_BASE		0xf200
1228c2ecf20Sopenharmony_ci#define EIP97_HIA_DSE_BASE		0xf400
1238c2ecf20Sopenharmony_ci#define EIP97_HIA_DSE_THR_BASE		0xf600
1248c2ecf20Sopenharmony_ci#define EIP97_HIA_GEN_CFG_BASE		0x10000
1258c2ecf20Sopenharmony_ci#define EIP97_PE_BASE			0x10000
1268c2ecf20Sopenharmony_ci#define EIP97_GLOBAL_BASE		0x10000
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* CDR/RDR register offsets */
1298c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_OFF(priv, r)		(EIP197_HIA_AIC_xDR(priv) + (r) * 0x1000)
1308c2ecf20Sopenharmony_ci#define EIP197_HIA_CDR(priv, r)			(EIP197_HIA_xDR_OFF(priv, r))
1318c2ecf20Sopenharmony_ci#define EIP197_HIA_RDR(priv, r)			(EIP197_HIA_xDR_OFF(priv, r) + 0x800)
1328c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_RING_BASE_ADDR_LO	0x0000
1338c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_RING_BASE_ADDR_HI	0x0004
1348c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_RING_SIZE		0x0018
1358c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_DESC_SIZE		0x001c
1368c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_CFG			0x0020
1378c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_DMA_CFG			0x0024
1388c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_THRESH			0x0028
1398c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_PREP_COUNT		0x002c
1408c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_PROC_COUNT		0x0030
1418c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_PREP_PNTR		0x0034
1428c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_PROC_PNTR		0x0038
1438c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_STAT			0x003c
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* register offsets */
1468c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_CFG(n)			(0x0000 + (128 * (n)))
1478c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_THR_CTRL(n)		(0x0000 + (128 * (n)))
1488c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_THR_STAT(n)		(0x0004 + (128 * (n)))
1498c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_CFG(n)			(0x0000 + (128 * (n)))
1508c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_THR_CTRL(n)		(0x0000 + (128 * (n)))
1518c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_THR_STAT(n)		(0x0004 + (128 * (n)))
1528c2ecf20Sopenharmony_ci#define EIP197_HIA_RA_PE_CTRL(n)		(0x0010 + (8   * (n)))
1538c2ecf20Sopenharmony_ci#define EIP197_HIA_RA_PE_STAT			0x0014
1548c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_OFF(r)			((r) * 0x1000)
1558c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_ENABLE_CTRL(r)		(0xe008 - EIP197_HIA_AIC_R_OFF(r))
1568c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_ENABLED_STAT(r)	(0xe010 - EIP197_HIA_AIC_R_OFF(r))
1578c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_ACK(r)			(0xe010 - EIP197_HIA_AIC_R_OFF(r))
1588c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_ENABLE_CLR(r)		(0xe014 - EIP197_HIA_AIC_R_OFF(r))
1598c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_R_VERSION(r)		(0xe01c - EIP197_HIA_AIC_R_OFF(r))
1608c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_G_ENABLE_CTRL		0xf808
1618c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_G_ENABLED_STAT		0xf810
1628c2ecf20Sopenharmony_ci#define EIP197_HIA_AIC_G_ACK			0xf810
1638c2ecf20Sopenharmony_ci#define EIP197_HIA_MST_CTRL			0xfff4
1648c2ecf20Sopenharmony_ci#define EIP197_HIA_OPTIONS			0xfff8
1658c2ecf20Sopenharmony_ci#define EIP197_HIA_VERSION			0xfffc
1668c2ecf20Sopenharmony_ci#define EIP197_PE_IN_DBUF_THRES(n)		(0x0000 + (0x2000 * (n)))
1678c2ecf20Sopenharmony_ci#define EIP197_PE_IN_TBUF_THRES(n)		(0x0100 + (0x2000 * (n)))
1688c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_RAM(n)		(0x0800 + (0x2000 * (n)))
1698c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_PUE_CTRL(n)		(0x0c80 + (0x2000 * (n)))
1708c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_PUTF_CTRL(n)		(0x0d00 + (0x2000 * (n)))
1718c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL(n)		(0x0d04 + (0x2000 * (n)))
1728c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_FPP_CTRL(n)		(0x0d80 + (0x2000 * (n)))
1738c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_PPTF_CTRL(n)		(0x0e00 + (0x2000 * (n)))
1748c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_RAM_CTRL(n)		(0x0ff0 + (0x2000 * (n)))
1758c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_VERSION(n)		(0x0ffc + (0x2000 * (n)))
1768c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL(n)		(0x1000 + (0x2000 * (n)))
1778c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_FUNCTION_EN(n)		(0x1004 + (0x2000 * (n)))
1788c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_CONTEXT_CTRL(n)		(0x1008 + (0x2000 * (n)))
1798c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_CONTEXT_STAT(n)		(0x100c + (0x2000 * (n)))
1808c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL2(n)		(0x102c + (0x2000 * (n)))
1818c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_FUNCTION2_EN(n)		(0x1030 + (0x2000 * (n)))
1828c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_OPTIONS(n)		(0x13f8 + (0x2000 * (n)))
1838c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_VERSION(n)		(0x13fc + (0x2000 * (n)))
1848c2ecf20Sopenharmony_ci#define EIP197_PE_OCE_VERSION(n)		(0x1bfc + (0x2000 * (n)))
1858c2ecf20Sopenharmony_ci#define EIP197_PE_OUT_DBUF_THRES(n)		(0x1c00 + (0x2000 * (n)))
1868c2ecf20Sopenharmony_ci#define EIP197_PE_OUT_TBUF_THRES(n)		(0x1d00 + (0x2000 * (n)))
1878c2ecf20Sopenharmony_ci#define EIP197_PE_PSE_VERSION(n)		(0x1efc + (0x2000 * (n)))
1888c2ecf20Sopenharmony_ci#define EIP197_PE_DEBUG(n)			(0x1ff4 + (0x2000 * (n)))
1898c2ecf20Sopenharmony_ci#define EIP197_PE_OPTIONS(n)			(0x1ff8 + (0x2000 * (n)))
1908c2ecf20Sopenharmony_ci#define EIP197_PE_VERSION(n)			(0x1ffc + (0x2000 * (n)))
1918c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL				0xfff4
1928c2ecf20Sopenharmony_ci#define EIP197_OPTIONS				0xfff8
1938c2ecf20Sopenharmony_ci#define EIP197_VERSION				0xfffc
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/* EIP197-specific registers, no indirection */
1968c2ecf20Sopenharmony_ci#define EIP197_CLASSIFICATION_RAMS		0xe0000
1978c2ecf20Sopenharmony_ci#define EIP197_TRC_CTRL				0xf0800
1988c2ecf20Sopenharmony_ci#define EIP197_TRC_LASTRES			0xf0804
1998c2ecf20Sopenharmony_ci#define EIP197_TRC_REGINDEX			0xf0808
2008c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS			0xf0820
2018c2ecf20Sopenharmony_ci#define EIP197_TRC_FREECHAIN			0xf0824
2028c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS2			0xf0828
2038c2ecf20Sopenharmony_ci#define EIP197_TRC_ECCCTRL			0xf0830
2048c2ecf20Sopenharmony_ci#define EIP197_TRC_ECCSTAT			0xf0834
2058c2ecf20Sopenharmony_ci#define EIP197_TRC_ECCADMINSTAT			0xf0838
2068c2ecf20Sopenharmony_ci#define EIP197_TRC_ECCDATASTAT			0xf083c
2078c2ecf20Sopenharmony_ci#define EIP197_TRC_ECCDATA			0xf0840
2088c2ecf20Sopenharmony_ci#define EIP197_STRC_CONFIG			0xf43f0
2098c2ecf20Sopenharmony_ci#define EIP197_FLUE_CACHEBASE_LO(n)		(0xf6000 + (32 * (n)))
2108c2ecf20Sopenharmony_ci#define EIP197_FLUE_CACHEBASE_HI(n)		(0xf6004 + (32 * (n)))
2118c2ecf20Sopenharmony_ci#define EIP197_FLUE_CONFIG(n)			(0xf6010 + (32 * (n)))
2128c2ecf20Sopenharmony_ci#define EIP197_FLUE_OFFSETS			0xf6808
2138c2ecf20Sopenharmony_ci#define EIP197_FLUE_ARC4_OFFSET			0xf680c
2148c2ecf20Sopenharmony_ci#define EIP197_FLUE_IFC_LUT(n)			(0xf6820 + (4 * (n)))
2158c2ecf20Sopenharmony_ci#define EIP197_CS_RAM_CTRL			0xf7ff0
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/* EIP197_HIA_xDR_DESC_SIZE */
2188c2ecf20Sopenharmony_ci#define EIP197_xDR_DESC_MODE_64BIT		BIT(31)
2198c2ecf20Sopenharmony_ci#define EIP197_CDR_DESC_MODE_ADCP		BIT(30)
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/* EIP197_HIA_xDR_DMA_CFG */
2228c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_WR_RES_BUF		BIT(22)
2238c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_WR_CTRL_BUF		BIT(23)
2248c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_WR_OWN_BUF		BIT(24)
2258c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_CFG_WR_CACHE(n)		(((n) & 0x7) << 25)
2268c2ecf20Sopenharmony_ci#define EIP197_HIA_xDR_CFG_RD_CACHE(n)		(((n) & 0x7) << 29)
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* EIP197_HIA_CDR_THRESH */
2298c2ecf20Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_PROC_PKT(n)	(n)
2308c2ecf20Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_PROC_MODE		BIT(22)
2318c2ecf20Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_PKT_MODE		BIT(23)
2328c2ecf20Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_TIMEOUT(n)	((n) << 24) /* x256 clk cycles */
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci/* EIP197_HIA_RDR_THRESH */
2358c2ecf20Sopenharmony_ci#define EIP197_HIA_RDR_THRESH_PROC_PKT(n)	(n)
2368c2ecf20Sopenharmony_ci#define EIP197_HIA_RDR_THRESH_PKT_MODE		BIT(23)
2378c2ecf20Sopenharmony_ci#define EIP197_HIA_RDR_THRESH_TIMEOUT(n)	((n) << 24) /* x256 clk cycles */
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci/* EIP197_HIA_xDR_PREP_COUNT */
2408c2ecf20Sopenharmony_ci#define EIP197_xDR_PREP_CLR_COUNT		BIT(31)
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci/* EIP197_HIA_xDR_PROC_COUNT */
2438c2ecf20Sopenharmony_ci#define EIP197_xDR_PROC_xD_PKT_OFFSET		24
2448c2ecf20Sopenharmony_ci#define EIP197_xDR_PROC_xD_PKT_MASK		GENMASK(6, 0)
2458c2ecf20Sopenharmony_ci#define EIP197_xDR_PROC_xD_PKT(n)		((n) << 24)
2468c2ecf20Sopenharmony_ci#define EIP197_xDR_PROC_CLR_COUNT		BIT(31)
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci/* EIP197_HIA_xDR_STAT */
2498c2ecf20Sopenharmony_ci#define EIP197_xDR_DMA_ERR			BIT(0)
2508c2ecf20Sopenharmony_ci#define EIP197_xDR_PREP_CMD_THRES		BIT(1)
2518c2ecf20Sopenharmony_ci#define EIP197_xDR_ERR				BIT(2)
2528c2ecf20Sopenharmony_ci#define EIP197_xDR_THRESH			BIT(4)
2538c2ecf20Sopenharmony_ci#define EIP197_xDR_TIMEOUT			BIT(5)
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci#define EIP197_HIA_RA_PE_CTRL_RESET		BIT(31)
2568c2ecf20Sopenharmony_ci#define EIP197_HIA_RA_PE_CTRL_EN		BIT(30)
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci/* EIP197_HIA_OPTIONS */
2598c2ecf20Sopenharmony_ci#define EIP197_N_RINGS_OFFSET			0
2608c2ecf20Sopenharmony_ci#define EIP197_N_RINGS_MASK			GENMASK(3, 0)
2618c2ecf20Sopenharmony_ci#define EIP197_N_PES_OFFSET			4
2628c2ecf20Sopenharmony_ci#define EIP197_N_PES_MASK			GENMASK(4, 0)
2638c2ecf20Sopenharmony_ci#define EIP97_N_PES_MASK			GENMASK(2, 0)
2648c2ecf20Sopenharmony_ci#define EIP197_HWDATAW_OFFSET			25
2658c2ecf20Sopenharmony_ci#define EIP197_HWDATAW_MASK			GENMASK(3, 0)
2668c2ecf20Sopenharmony_ci#define EIP97_HWDATAW_MASK			GENMASK(2, 0)
2678c2ecf20Sopenharmony_ci#define EIP197_CFSIZE_OFFSET			9
2688c2ecf20Sopenharmony_ci#define EIP197_CFSIZE_ADJUST			4
2698c2ecf20Sopenharmony_ci#define EIP97_CFSIZE_OFFSET			8
2708c2ecf20Sopenharmony_ci#define EIP197_CFSIZE_MASK			GENMASK(2, 0)
2718c2ecf20Sopenharmony_ci#define EIP97_CFSIZE_MASK			GENMASK(3, 0)
2728c2ecf20Sopenharmony_ci#define EIP197_RFSIZE_OFFSET			12
2738c2ecf20Sopenharmony_ci#define EIP197_RFSIZE_ADJUST			4
2748c2ecf20Sopenharmony_ci#define EIP97_RFSIZE_OFFSET			12
2758c2ecf20Sopenharmony_ci#define EIP197_RFSIZE_MASK			GENMASK(2, 0)
2768c2ecf20Sopenharmony_ci#define EIP97_RFSIZE_MASK			GENMASK(3, 0)
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci/* EIP197_HIA_AIC_R_ENABLE_CTRL */
2798c2ecf20Sopenharmony_ci#define EIP197_CDR_IRQ(n)			BIT((n) * 2)
2808c2ecf20Sopenharmony_ci#define EIP197_RDR_IRQ(n)			BIT((n) * 2 + 1)
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/* EIP197_HIA_DFE/DSE_CFG */
2838c2ecf20Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MIN_DATA_SIZE(n)	((n) << 0)
2848c2ecf20Sopenharmony_ci#define EIP197_HIA_DxE_CFG_DATA_CACHE_CTRL(n)	(((n) & 0x7) << 4)
2858c2ecf20Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MAX_DATA_SIZE(n)	((n) << 8)
2868c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_CFG_ALWAYS_BUFFERABLE	GENMASK(15, 14)
2878c2ecf20Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MIN_CTRL_SIZE(n)	((n) << 16)
2888c2ecf20Sopenharmony_ci#define EIP197_HIA_DxE_CFG_CTRL_CACHE_CTRL(n)	(((n) & 0x7) << 20)
2898c2ecf20Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MAX_CTRL_SIZE(n)	((n) << 24)
2908c2ecf20Sopenharmony_ci#define EIP197_HIA_DFE_CFG_DIS_DEBUG		GENMASK(31, 29)
2918c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_CFG_EN_SINGLE_WR		BIT(29)
2928c2ecf20Sopenharmony_ci#define EIP197_HIA_DSE_CFG_DIS_DEBUG		GENMASK(31, 30)
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/* EIP197_HIA_DFE/DSE_THR_CTRL */
2958c2ecf20Sopenharmony_ci#define EIP197_DxE_THR_CTRL_EN			BIT(30)
2968c2ecf20Sopenharmony_ci#define EIP197_DxE_THR_CTRL_RESET_PE		BIT(31)
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci/* EIP197_PE_ICE_PUE/FPP_CTRL */
2998c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_UENG_START_OFFSET(n)	((n) << 16)
3008c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_UENG_INIT_ALIGN_MASK	0x7ff0
3018c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_UENG_DEBUG_RESET		BIT(3)
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/* EIP197_HIA_AIC_G_ENABLED_STAT */
3048c2ecf20Sopenharmony_ci#define EIP197_G_IRQ_DFE(n)			BIT((n) << 1)
3058c2ecf20Sopenharmony_ci#define EIP197_G_IRQ_DSE(n)			BIT(((n) << 1) + 1)
3068c2ecf20Sopenharmony_ci#define EIP197_G_IRQ_RING			BIT(16)
3078c2ecf20Sopenharmony_ci#define EIP197_G_IRQ_PE(n)			BIT((n) + 20)
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci/* EIP197_HIA_MST_CTRL */
3108c2ecf20Sopenharmony_ci#define RD_CACHE_3BITS				0x5
3118c2ecf20Sopenharmony_ci#define WR_CACHE_3BITS				0x3
3128c2ecf20Sopenharmony_ci#define RD_CACHE_4BITS				(RD_CACHE_3BITS << 1 | BIT(0))
3138c2ecf20Sopenharmony_ci#define WR_CACHE_4BITS				(WR_CACHE_3BITS << 1 | BIT(0))
3148c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL_RD_CACHE(n)		(((n) & 0xf) << 0)
3158c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL_WD_CACHE(n)		(((n) & 0xf) << 4)
3168c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL_TX_MAX_CMD(n)		(((n) & 0xf) << 20)
3178c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL_BYTE_SWAP		BIT(24)
3188c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL_NO_BYTE_SWAP		BIT(25)
3198c2ecf20Sopenharmony_ci#define EIP197_MST_CTRL_BYTE_SWAP_BITS          GENMASK(25, 24)
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci/* EIP197_PE_IN_DBUF/TBUF_THRES */
3228c2ecf20Sopenharmony_ci#define EIP197_PE_IN_xBUF_THRES_MIN(n)		((n) << 8)
3238c2ecf20Sopenharmony_ci#define EIP197_PE_IN_xBUF_THRES_MAX(n)		((n) << 12)
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci/* EIP197_PE_OUT_DBUF_THRES */
3268c2ecf20Sopenharmony_ci#define EIP197_PE_OUT_DBUF_THRES_MIN(n)		((n) << 0)
3278c2ecf20Sopenharmony_ci#define EIP197_PE_OUT_DBUF_THRES_MAX(n)		((n) << 4)
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci/* EIP197_PE_ICE_SCRATCH_CTRL */
3308c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_TIMER		BIT(2)
3318c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_TIMER_EN		BIT(3)
3328c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_ACCESS	BIT(24)
3338c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_SCRATCH_ACCESS	BIT(25)
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci/* EIP197_PE_ICE_SCRATCH_RAM */
3368c2ecf20Sopenharmony_ci#define EIP197_NUM_OF_SCRATCH_BLOCKS		32
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci/* EIP197_PE_ICE_PUE/FPP_CTRL */
3398c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_x_CTRL_SW_RESET			BIT(0)
3408c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_x_CTRL_CLR_ECC_NON_CORR		BIT(14)
3418c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_x_CTRL_CLR_ECC_CORR		BIT(15)
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/* EIP197_PE_ICE_RAM_CTRL */
3448c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_RAM_CTRL_PUE_PROG_EN	BIT(0)
3458c2ecf20Sopenharmony_ci#define EIP197_PE_ICE_RAM_CTRL_FPP_PROG_EN	BIT(1)
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/* EIP197_PE_EIP96_TOKEN_CTRL */
3488c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL_CTX_UPDATES		BIT(16)
3498c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL_NO_TOKEN_WAIT	BIT(17)
3508c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL_ENABLE_TIMEOUT	BIT(22)
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci/* EIP197_PE_EIP96_FUNCTION_EN */
3538c2ecf20Sopenharmony_ci#define EIP197_FUNCTION_ALL			0xffffffff
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci/* EIP197_PE_EIP96_CONTEXT_CTRL */
3568c2ecf20Sopenharmony_ci#define EIP197_CONTEXT_SIZE(n)			(n)
3578c2ecf20Sopenharmony_ci#define EIP197_ADDRESS_MODE			BIT(8)
3588c2ecf20Sopenharmony_ci#define EIP197_CONTROL_MODE			BIT(9)
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci/* EIP197_PE_EIP96_TOKEN_CTRL2 */
3618c2ecf20Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE	BIT(3)
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci/* EIP197_PE_DEBUG */
3648c2ecf20Sopenharmony_ci#define EIP197_DEBUG_OCE_BYPASS			BIT(1)
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci/* EIP197_STRC_CONFIG */
3678c2ecf20Sopenharmony_ci#define EIP197_STRC_CONFIG_INIT			BIT(31)
3688c2ecf20Sopenharmony_ci#define EIP197_STRC_CONFIG_LARGE_REC(s)		(s<<8)
3698c2ecf20Sopenharmony_ci#define EIP197_STRC_CONFIG_SMALL_REC(s)		(s<<0)
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci/* EIP197_FLUE_CONFIG */
3728c2ecf20Sopenharmony_ci#define EIP197_FLUE_CONFIG_MAGIC		0xc7000004
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci/* Context Control */
3758c2ecf20Sopenharmony_cistruct safexcel_context_record {
3768c2ecf20Sopenharmony_ci	__le32 control0;
3778c2ecf20Sopenharmony_ci	__le32 control1;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	__le32 data[40];
3808c2ecf20Sopenharmony_ci} __packed;
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci/* control0 */
3838c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_NULL_OUT		0x0
3848c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_NULL_IN		0x1
3858c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_OUT		0x2
3868c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_IN		0x3
3878c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_CRYPTO_OUT		0x4
3888c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_CRYPTO_IN		0x5
3898c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_ENCRYPT_HASH_OUT	0x6
3908c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_DECRYPT_HASH_IN	0x7
3918c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_ENCRYPT_OUT	0xe
3928c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_DECRYPT_IN	0xf
3938c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_RESTART_HASH		BIT(4)
3948c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_NO_FINISH_HASH		BIT(5)
3958c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_SIZE(n)			((n) << 8)
3968c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_KEY_EN			BIT(16)
3978c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_DES		(0x0 << 17)
3988c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_3DES		(0x2 << 17)
3998c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_AES128	(0x5 << 17)
4008c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_AES192	(0x6 << 17)
4018c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_AES256	(0x7 << 17)
4028c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_CHACHA20	(0x8 << 17)
4038c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SM4		(0xd << 17)
4048c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_INITIAL		(0x0 << 21)
4058c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_PRECOMPUTED	(0x1 << 21)
4068c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_XCM		(0x2 << 21)
4078c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_HMAC		(0x3 << 21)
4088c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_MD5		(0x0 << 23)
4098c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_CRC32	(0x0 << 23)
4108c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA1		(0x2 << 23)
4118c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA224	(0x4 << 23)
4128c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA256	(0x3 << 23)
4138c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA384	(0x6 << 23)
4148c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA512	(0x5 << 23)
4158c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_GHASH	(0x4 << 23)
4168c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_XCBC128	(0x1 << 23)
4178c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_XCBC192	(0x2 << 23)
4188c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_XCBC256	(0x3 << 23)
4198c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SM3		(0x7 << 23)
4208c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_256	(0xb << 23)
4218c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_224	(0xc << 23)
4228c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_512	(0xd << 23)
4238c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_384	(0xe << 23)
4248c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_POLY1305	(0xf << 23)
4258c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_INV_FR			(0x5 << 24)
4268c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_INV_TR			(0x6 << 24)
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/* control1 */
4298c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_ECB		(0 << 0)
4308c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_CBC		(1 << 0)
4318c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CHACHA20_MODE_256_32	(2 << 0)
4328c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_OFB		(4 << 0)
4338c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_CFB		(5 << 0)
4348c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_CTR_LOAD	(6 << 0)
4358c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_XTS		(7 << 0)
4368c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_XCM		((6 << 0) | BIT(17))
4378c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CHACHA20_MODE_CALC_OTK	(12 << 0)
4388c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_IV0			BIT(5)
4398c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_IV1			BIT(6)
4408c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_IV2			BIT(7)
4418c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_IV3			BIT(8)
4428c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_CNT		BIT(9)
4438c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_COUNTER_MODE		BIT(10)
4448c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_STORE		BIT(12)
4458c2ecf20Sopenharmony_ci#define CONTEXT_CONTROL_HASH_STORE		BIT(19)
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci#define EIP197_XCM_MODE_GCM			1
4488c2ecf20Sopenharmony_ci#define EIP197_XCM_MODE_CCM			2
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci#define EIP197_AEAD_TYPE_IPSEC_ESP		2
4518c2ecf20Sopenharmony_ci#define EIP197_AEAD_TYPE_IPSEC_ESP_GMAC		3
4528c2ecf20Sopenharmony_ci#define EIP197_AEAD_IPSEC_IV_SIZE		8
4538c2ecf20Sopenharmony_ci#define EIP197_AEAD_IPSEC_NONCE_SIZE		4
4548c2ecf20Sopenharmony_ci#define EIP197_AEAD_IPSEC_COUNTER_SIZE		4
4558c2ecf20Sopenharmony_ci#define EIP197_AEAD_IPSEC_CCM_NONCE_SIZE	3
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci/* The hash counter given to the engine in the context has a granularity of
4588c2ecf20Sopenharmony_ci * 64 bits.
4598c2ecf20Sopenharmony_ci */
4608c2ecf20Sopenharmony_ci#define EIP197_COUNTER_BLOCK_SIZE		64
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci/* EIP197_CS_RAM_CTRL */
4638c2ecf20Sopenharmony_ci#define EIP197_TRC_ENABLE_0			BIT(4)
4648c2ecf20Sopenharmony_ci#define EIP197_TRC_ENABLE_1			BIT(5)
4658c2ecf20Sopenharmony_ci#define EIP197_TRC_ENABLE_2			BIT(6)
4668c2ecf20Sopenharmony_ci#define EIP197_TRC_ENABLE_MASK			GENMASK(6, 4)
4678c2ecf20Sopenharmony_ci#define EIP197_CS_BANKSEL_MASK			GENMASK(14, 12)
4688c2ecf20Sopenharmony_ci#define EIP197_CS_BANKSEL_OFS			12
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci/* EIP197_TRC_PARAMS */
4718c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS_SW_RESET		BIT(0)
4728c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS_DATA_ACCESS		BIT(2)
4738c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS_HTABLE_SZ(x)		((x) << 4)
4748c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS_BLK_TIMER_SPEED(x)	((x) << 10)
4758c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS_RC_SZ_LARGE(n)	((n) << 18)
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci/* EIP197_TRC_FREECHAIN */
4788c2ecf20Sopenharmony_ci#define EIP197_TRC_FREECHAIN_HEAD_PTR(p)	(p)
4798c2ecf20Sopenharmony_ci#define EIP197_TRC_FREECHAIN_TAIL_PTR(p)	((p) << 16)
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/* EIP197_TRC_PARAMS2 */
4828c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS2_HTABLE_PTR(p)	(p)
4838c2ecf20Sopenharmony_ci#define EIP197_TRC_PARAMS2_RC_SZ_SMALL(n)	((n) << 18)
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/* Cache helpers */
4868c2ecf20Sopenharmony_ci#define EIP197_MIN_DSIZE			1024
4878c2ecf20Sopenharmony_ci#define EIP197_MIN_ASIZE			8
4888c2ecf20Sopenharmony_ci#define EIP197_CS_TRC_REC_WC			64
4898c2ecf20Sopenharmony_ci#define EIP197_CS_RC_SIZE			(4 * sizeof(u32))
4908c2ecf20Sopenharmony_ci#define EIP197_CS_RC_NEXT(x)			(x)
4918c2ecf20Sopenharmony_ci#define EIP197_CS_RC_PREV(x)			((x) << 10)
4928c2ecf20Sopenharmony_ci#define EIP197_RC_NULL				0x3ff
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci/* Result data */
4958c2ecf20Sopenharmony_cistruct result_data_desc {
4968c2ecf20Sopenharmony_ci	u32 packet_length:17;
4978c2ecf20Sopenharmony_ci	u32 error_code:15;
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci	u8 bypass_length:4;
5008c2ecf20Sopenharmony_ci	u8 e15:1;
5018c2ecf20Sopenharmony_ci	u16 rsvd0;
5028c2ecf20Sopenharmony_ci	u8 hash_bytes:1;
5038c2ecf20Sopenharmony_ci	u8 hash_length:6;
5048c2ecf20Sopenharmony_ci	u8 generic_bytes:1;
5058c2ecf20Sopenharmony_ci	u8 checksum:1;
5068c2ecf20Sopenharmony_ci	u8 next_header:1;
5078c2ecf20Sopenharmony_ci	u8 length:1;
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	u16 application_id;
5108c2ecf20Sopenharmony_ci	u16 rsvd1;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	u32 rsvd2[5];
5138c2ecf20Sopenharmony_ci} __packed;
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci/* Basic Result Descriptor format */
5178c2ecf20Sopenharmony_cistruct safexcel_result_desc {
5188c2ecf20Sopenharmony_ci	u32 particle_size:17;
5198c2ecf20Sopenharmony_ci	u8 rsvd0:3;
5208c2ecf20Sopenharmony_ci	u8 descriptor_overflow:1;
5218c2ecf20Sopenharmony_ci	u8 buffer_overflow:1;
5228c2ecf20Sopenharmony_ci	u8 last_seg:1;
5238c2ecf20Sopenharmony_ci	u8 first_seg:1;
5248c2ecf20Sopenharmony_ci	u16 result_size:8;
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci	u32 rsvd1;
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	u32 data_lo;
5298c2ecf20Sopenharmony_ci	u32 data_hi;
5308c2ecf20Sopenharmony_ci} __packed;
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci/*
5338c2ecf20Sopenharmony_ci * The EIP(1)97 only needs to fetch the descriptor part of
5348c2ecf20Sopenharmony_ci * the result descriptor, not the result token part!
5358c2ecf20Sopenharmony_ci */
5368c2ecf20Sopenharmony_ci#define EIP197_RD64_FETCH_SIZE		(sizeof(struct safexcel_result_desc) /\
5378c2ecf20Sopenharmony_ci					 sizeof(u32))
5388c2ecf20Sopenharmony_ci#define EIP197_RD64_RESULT_SIZE		(sizeof(struct result_data_desc) /\
5398c2ecf20Sopenharmony_ci					 sizeof(u32))
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_cistruct safexcel_token {
5428c2ecf20Sopenharmony_ci	u32 packet_length:17;
5438c2ecf20Sopenharmony_ci	u8 stat:2;
5448c2ecf20Sopenharmony_ci	u16 instructions:9;
5458c2ecf20Sopenharmony_ci	u8 opcode:4;
5468c2ecf20Sopenharmony_ci} __packed;
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci#define EIP197_TOKEN_HASH_RESULT_VERIFY		BIT(16)
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci#define EIP197_TOKEN_CTX_OFFSET(x)		(x)
5518c2ecf20Sopenharmony_ci#define EIP197_TOKEN_DIRECTION_EXTERNAL		BIT(11)
5528c2ecf20Sopenharmony_ci#define EIP197_TOKEN_EXEC_IF_SUCCESSFUL		(0x1 << 12)
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci#define EIP197_TOKEN_STAT_LAST_HASH		BIT(0)
5558c2ecf20Sopenharmony_ci#define EIP197_TOKEN_STAT_LAST_PACKET		BIT(1)
5568c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_DIRECTION		0x0
5578c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_INSERT		0x2
5588c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_NOOP		EIP197_TOKEN_OPCODE_INSERT
5598c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_RETRIEVE		0x4
5608c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_INSERT_REMRES	0xa
5618c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_VERIFY		0xd
5628c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_CTX_ACCESS		0xe
5638c2ecf20Sopenharmony_ci#define EIP197_TOKEN_OPCODE_BYPASS		GENMASK(3, 0)
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_cistatic inline void eip197_noop_token(struct safexcel_token *token)
5668c2ecf20Sopenharmony_ci{
5678c2ecf20Sopenharmony_ci	token->opcode = EIP197_TOKEN_OPCODE_NOOP;
5688c2ecf20Sopenharmony_ci	token->packet_length = BIT(2);
5698c2ecf20Sopenharmony_ci	token->stat = 0;
5708c2ecf20Sopenharmony_ci	token->instructions = 0;
5718c2ecf20Sopenharmony_ci}
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci/* Instructions */
5748c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_INSERT_HASH_DIGEST	0x1c
5758c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_ORIGIN_IV0		0x14
5768c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_ORIGIN_TOKEN		0x1b
5778c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_ORIGIN_LEN(x)		((x) << 5)
5788c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_TYPE_OUTPUT		BIT(5)
5798c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_TYPE_HASH		BIT(6)
5808c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_TYPE_CRYPTO		BIT(7)
5818c2ecf20Sopenharmony_ci#define EIP197_TOKEN_INS_LAST			BIT(8)
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci/* Processing Engine Control Data  */
5848c2ecf20Sopenharmony_cistruct safexcel_control_data_desc {
5858c2ecf20Sopenharmony_ci	u32 packet_length:17;
5868c2ecf20Sopenharmony_ci	u16 options:13;
5878c2ecf20Sopenharmony_ci	u8 type:2;
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	u16 application_id;
5908c2ecf20Sopenharmony_ci	u16 rsvd;
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci	u32 context_lo;
5938c2ecf20Sopenharmony_ci	u32 context_hi;
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci	u32 control0;
5968c2ecf20Sopenharmony_ci	u32 control1;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	u32 token[EIP197_EMB_TOKENS];
5998c2ecf20Sopenharmony_ci} __packed;
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci#define EIP197_OPTION_MAGIC_VALUE	BIT(0)
6028c2ecf20Sopenharmony_ci#define EIP197_OPTION_64BIT_CTX		BIT(1)
6038c2ecf20Sopenharmony_ci#define EIP197_OPTION_RC_AUTO		(0x2 << 3)
6048c2ecf20Sopenharmony_ci#define EIP197_OPTION_CTX_CTRL_IN_CMD	BIT(8)
6058c2ecf20Sopenharmony_ci#define EIP197_OPTION_2_TOKEN_IV_CMD	GENMASK(11, 10)
6068c2ecf20Sopenharmony_ci#define EIP197_OPTION_4_TOKEN_IV_CMD	GENMASK(11, 9)
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci#define EIP197_TYPE_BCLA		0x0
6098c2ecf20Sopenharmony_ci#define EIP197_TYPE_EXTENDED		0x3
6108c2ecf20Sopenharmony_ci#define EIP197_CONTEXT_SMALL		0x2
6118c2ecf20Sopenharmony_ci#define EIP197_CONTEXT_SIZE_MASK	0x3
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci/* Basic Command Descriptor format */
6148c2ecf20Sopenharmony_cistruct safexcel_command_desc {
6158c2ecf20Sopenharmony_ci	u32 particle_size:17;
6168c2ecf20Sopenharmony_ci	u8 rsvd0:5;
6178c2ecf20Sopenharmony_ci	u8 last_seg:1;
6188c2ecf20Sopenharmony_ci	u8 first_seg:1;
6198c2ecf20Sopenharmony_ci	u8 additional_cdata_size:8;
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	u32 rsvd1;
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci	u32 data_lo;
6248c2ecf20Sopenharmony_ci	u32 data_hi;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	u32 atok_lo;
6278c2ecf20Sopenharmony_ci	u32 atok_hi;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	struct safexcel_control_data_desc control_data;
6308c2ecf20Sopenharmony_ci} __packed;
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci#define EIP197_CD64_FETCH_SIZE		(sizeof(struct safexcel_command_desc) /\
6338c2ecf20Sopenharmony_ci					sizeof(u32))
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci/*
6368c2ecf20Sopenharmony_ci * Internal structures & functions
6378c2ecf20Sopenharmony_ci */
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci#define EIP197_FW_TERMINAL_NOPS		2
6408c2ecf20Sopenharmony_ci#define EIP197_FW_START_POLLCNT		16
6418c2ecf20Sopenharmony_ci#define EIP197_FW_PUE_READY		0x14
6428c2ecf20Sopenharmony_ci#define EIP197_FW_FPP_READY		0x18
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_cienum eip197_fw {
6458c2ecf20Sopenharmony_ci	FW_IFPP = 0,
6468c2ecf20Sopenharmony_ci	FW_IPUE,
6478c2ecf20Sopenharmony_ci	FW_NB
6488c2ecf20Sopenharmony_ci};
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_cistruct safexcel_desc_ring {
6518c2ecf20Sopenharmony_ci	void *base;
6528c2ecf20Sopenharmony_ci	void *shbase;
6538c2ecf20Sopenharmony_ci	void *base_end;
6548c2ecf20Sopenharmony_ci	void *shbase_end;
6558c2ecf20Sopenharmony_ci	dma_addr_t base_dma;
6568c2ecf20Sopenharmony_ci	dma_addr_t shbase_dma;
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci	/* write and read pointers */
6598c2ecf20Sopenharmony_ci	void *write;
6608c2ecf20Sopenharmony_ci	void *shwrite;
6618c2ecf20Sopenharmony_ci	void *read;
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci	/* descriptor element offset */
6648c2ecf20Sopenharmony_ci	unsigned int offset;
6658c2ecf20Sopenharmony_ci	unsigned int shoffset;
6668c2ecf20Sopenharmony_ci};
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cienum safexcel_alg_type {
6698c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_TYPE_SKCIPHER,
6708c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_TYPE_AEAD,
6718c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_TYPE_AHASH,
6728c2ecf20Sopenharmony_ci};
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_cistruct safexcel_config {
6758c2ecf20Sopenharmony_ci	u32 pes;
6768c2ecf20Sopenharmony_ci	u32 rings;
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	u32 cd_size;
6798c2ecf20Sopenharmony_ci	u32 cd_offset;
6808c2ecf20Sopenharmony_ci	u32 cdsh_offset;
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	u32 rd_size;
6838c2ecf20Sopenharmony_ci	u32 rd_offset;
6848c2ecf20Sopenharmony_ci	u32 res_offset;
6858c2ecf20Sopenharmony_ci};
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_cistruct safexcel_work_data {
6888c2ecf20Sopenharmony_ci	struct work_struct work;
6898c2ecf20Sopenharmony_ci	struct safexcel_crypto_priv *priv;
6908c2ecf20Sopenharmony_ci	int ring;
6918c2ecf20Sopenharmony_ci};
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_cistruct safexcel_ring {
6948c2ecf20Sopenharmony_ci	spinlock_t lock;
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	struct workqueue_struct *workqueue;
6978c2ecf20Sopenharmony_ci	struct safexcel_work_data work_data;
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	/* command/result rings */
7008c2ecf20Sopenharmony_ci	struct safexcel_desc_ring cdr;
7018c2ecf20Sopenharmony_ci	struct safexcel_desc_ring rdr;
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	/* result ring crypto API request */
7048c2ecf20Sopenharmony_ci	struct crypto_async_request **rdr_req;
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	/* queue */
7078c2ecf20Sopenharmony_ci	struct crypto_queue queue;
7088c2ecf20Sopenharmony_ci	spinlock_t queue_lock;
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	/* Number of requests in the engine. */
7118c2ecf20Sopenharmony_ci	int requests;
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ci	/* The ring is currently handling at least one request */
7148c2ecf20Sopenharmony_ci	bool busy;
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	/* Store for current requests when bailing out of the dequeueing
7178c2ecf20Sopenharmony_ci	 * function when no enough resources are available.
7188c2ecf20Sopenharmony_ci	 */
7198c2ecf20Sopenharmony_ci	struct crypto_async_request *req;
7208c2ecf20Sopenharmony_ci	struct crypto_async_request *backlog;
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	/* irq of this ring */
7238c2ecf20Sopenharmony_ci	int irq;
7248c2ecf20Sopenharmony_ci};
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci/* EIP integration context flags */
7278c2ecf20Sopenharmony_cienum safexcel_eip_version {
7288c2ecf20Sopenharmony_ci	/* Platform (EIP integration context) specifier */
7298c2ecf20Sopenharmony_ci	EIP97IES_MRVL,
7308c2ecf20Sopenharmony_ci	EIP197B_MRVL,
7318c2ecf20Sopenharmony_ci	EIP197D_MRVL,
7328c2ecf20Sopenharmony_ci	EIP197_DEVBRD
7338c2ecf20Sopenharmony_ci};
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci/* Priority we use for advertising our algorithms */
7368c2ecf20Sopenharmony_ci#define SAFEXCEL_CRA_PRIORITY		300
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci/* SM3 digest result for zero length message */
7398c2ecf20Sopenharmony_ci#define EIP197_SM3_ZEROM_HASH	"\x1A\xB2\x1D\x83\x55\xCF\xA1\x7F" \
7408c2ecf20Sopenharmony_ci				"\x8E\x61\x19\x48\x31\xE8\x1A\x8F" \
7418c2ecf20Sopenharmony_ci				"\x22\xBE\xC8\xC7\x28\xFE\xFB\x74" \
7428c2ecf20Sopenharmony_ci				"\x7E\xD0\x35\xEB\x50\x82\xAA\x2B"
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci/* EIP algorithm presence flags */
7458c2ecf20Sopenharmony_cienum safexcel_eip_algorithms {
7468c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_BC0      = BIT(5),
7478c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_SM4      = BIT(6),
7488c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_SM3      = BIT(7),
7498c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_CHACHA20 = BIT(8),
7508c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_POLY1305 = BIT(9),
7518c2ecf20Sopenharmony_ci	SAFEXCEL_SEQMASK_256   = BIT(10),
7528c2ecf20Sopenharmony_ci	SAFEXCEL_SEQMASK_384   = BIT(11),
7538c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_AES      = BIT(12),
7548c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_AES_XFB  = BIT(13),
7558c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_DES      = BIT(15),
7568c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_DES_XFB  = BIT(16),
7578c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_ARC4     = BIT(18),
7588c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_AES_XTS  = BIT(20),
7598c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_WIRELESS = BIT(21),
7608c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_MD5      = BIT(22),
7618c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_SHA1     = BIT(23),
7628c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_SHA2_256 = BIT(25),
7638c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_SHA2_512 = BIT(26),
7648c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_XCBC_MAC = BIT(27),
7658c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_CBC_MAC_ALL = BIT(29),
7668c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_GHASH    = BIT(30),
7678c2ecf20Sopenharmony_ci	SAFEXCEL_ALG_SHA3     = BIT(31),
7688c2ecf20Sopenharmony_ci};
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_cistruct safexcel_register_offsets {
7718c2ecf20Sopenharmony_ci	u32 hia_aic;
7728c2ecf20Sopenharmony_ci	u32 hia_aic_g;
7738c2ecf20Sopenharmony_ci	u32 hia_aic_r;
7748c2ecf20Sopenharmony_ci	u32 hia_aic_xdr;
7758c2ecf20Sopenharmony_ci	u32 hia_dfe;
7768c2ecf20Sopenharmony_ci	u32 hia_dfe_thr;
7778c2ecf20Sopenharmony_ci	u32 hia_dse;
7788c2ecf20Sopenharmony_ci	u32 hia_dse_thr;
7798c2ecf20Sopenharmony_ci	u32 hia_gen_cfg;
7808c2ecf20Sopenharmony_ci	u32 pe;
7818c2ecf20Sopenharmony_ci	u32 global;
7828c2ecf20Sopenharmony_ci};
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_cienum safexcel_flags {
7858c2ecf20Sopenharmony_ci	EIP197_TRC_CACHE	= BIT(0),
7868c2ecf20Sopenharmony_ci	SAFEXCEL_HW_EIP197	= BIT(1),
7878c2ecf20Sopenharmony_ci	EIP197_PE_ARB		= BIT(2),
7888c2ecf20Sopenharmony_ci	EIP197_ICE		= BIT(3),
7898c2ecf20Sopenharmony_ci	EIP197_SIMPLE_TRC	= BIT(4),
7908c2ecf20Sopenharmony_ci	EIP197_OCE		= BIT(5),
7918c2ecf20Sopenharmony_ci};
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_cistruct safexcel_hwconfig {
7948c2ecf20Sopenharmony_ci	enum safexcel_eip_algorithms algo_flags;
7958c2ecf20Sopenharmony_ci	int hwver;
7968c2ecf20Sopenharmony_ci	int hiaver;
7978c2ecf20Sopenharmony_ci	int ppver;
7988c2ecf20Sopenharmony_ci	int icever;
7998c2ecf20Sopenharmony_ci	int pever;
8008c2ecf20Sopenharmony_ci	int ocever;
8018c2ecf20Sopenharmony_ci	int psever;
8028c2ecf20Sopenharmony_ci	int hwdataw;
8038c2ecf20Sopenharmony_ci	int hwcfsize;
8048c2ecf20Sopenharmony_ci	int hwrfsize;
8058c2ecf20Sopenharmony_ci	int hwnumpes;
8068c2ecf20Sopenharmony_ci	int hwnumrings;
8078c2ecf20Sopenharmony_ci	int hwnumraic;
8088c2ecf20Sopenharmony_ci};
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_cistruct safexcel_crypto_priv {
8118c2ecf20Sopenharmony_ci	void __iomem *base;
8128c2ecf20Sopenharmony_ci	struct device *dev;
8138c2ecf20Sopenharmony_ci	struct clk *clk;
8148c2ecf20Sopenharmony_ci	struct clk *reg_clk;
8158c2ecf20Sopenharmony_ci	struct safexcel_config config;
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci	enum safexcel_eip_version version;
8188c2ecf20Sopenharmony_ci	struct safexcel_register_offsets offsets;
8198c2ecf20Sopenharmony_ci	struct safexcel_hwconfig hwconfig;
8208c2ecf20Sopenharmony_ci	u32 flags;
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci	/* context DMA pool */
8238c2ecf20Sopenharmony_ci	struct dma_pool *context_pool;
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_ci	atomic_t ring_used;
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ci	struct safexcel_ring *ring;
8288c2ecf20Sopenharmony_ci};
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_cistruct safexcel_context {
8318c2ecf20Sopenharmony_ci	int (*send)(struct crypto_async_request *req, int ring,
8328c2ecf20Sopenharmony_ci		    int *commands, int *results);
8338c2ecf20Sopenharmony_ci	int (*handle_result)(struct safexcel_crypto_priv *priv, int ring,
8348c2ecf20Sopenharmony_ci			     struct crypto_async_request *req, bool *complete,
8358c2ecf20Sopenharmony_ci			     int *ret);
8368c2ecf20Sopenharmony_ci	struct safexcel_context_record *ctxr;
8378c2ecf20Sopenharmony_ci	struct safexcel_crypto_priv *priv;
8388c2ecf20Sopenharmony_ci	dma_addr_t ctxr_dma;
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_ci	union {
8418c2ecf20Sopenharmony_ci		__le32 le[SHA3_512_BLOCK_SIZE / 4];
8428c2ecf20Sopenharmony_ci		__be32 be[SHA3_512_BLOCK_SIZE / 4];
8438c2ecf20Sopenharmony_ci		u32 word[SHA3_512_BLOCK_SIZE / 4];
8448c2ecf20Sopenharmony_ci		u8 byte[SHA3_512_BLOCK_SIZE];
8458c2ecf20Sopenharmony_ci	} ipad, opad;
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	int ring;
8488c2ecf20Sopenharmony_ci	bool needs_inv;
8498c2ecf20Sopenharmony_ci	bool exit_inv;
8508c2ecf20Sopenharmony_ci};
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci#define HASH_CACHE_SIZE			SHA512_BLOCK_SIZE
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_cistruct safexcel_ahash_export_state {
8558c2ecf20Sopenharmony_ci	u64 len;
8568c2ecf20Sopenharmony_ci	u64 processed;
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci	u32 digest;
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci	u32 state[SHA512_DIGEST_SIZE / sizeof(u32)];
8618c2ecf20Sopenharmony_ci	u8 cache[HASH_CACHE_SIZE];
8628c2ecf20Sopenharmony_ci};
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci/*
8658c2ecf20Sopenharmony_ci * Template structure to describe the algorithms in order to register them.
8668c2ecf20Sopenharmony_ci * It also has the purpose to contain our private structure and is actually
8678c2ecf20Sopenharmony_ci * the only way I know in this framework to avoid having global pointers...
8688c2ecf20Sopenharmony_ci */
8698c2ecf20Sopenharmony_cistruct safexcel_alg_template {
8708c2ecf20Sopenharmony_ci	struct safexcel_crypto_priv *priv;
8718c2ecf20Sopenharmony_ci	enum safexcel_alg_type type;
8728c2ecf20Sopenharmony_ci	enum safexcel_eip_algorithms algo_mask;
8738c2ecf20Sopenharmony_ci	union {
8748c2ecf20Sopenharmony_ci		struct skcipher_alg skcipher;
8758c2ecf20Sopenharmony_ci		struct aead_alg aead;
8768c2ecf20Sopenharmony_ci		struct ahash_alg ahash;
8778c2ecf20Sopenharmony_ci	} alg;
8788c2ecf20Sopenharmony_ci};
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_cistruct safexcel_inv_result {
8818c2ecf20Sopenharmony_ci	struct completion completion;
8828c2ecf20Sopenharmony_ci	int error;
8838c2ecf20Sopenharmony_ci};
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_civoid safexcel_dequeue(struct safexcel_crypto_priv *priv, int ring);
8868c2ecf20Sopenharmony_ciint safexcel_rdesc_check_errors(struct safexcel_crypto_priv *priv,
8878c2ecf20Sopenharmony_ci				void *rdp);
8888c2ecf20Sopenharmony_civoid safexcel_complete(struct safexcel_crypto_priv *priv, int ring);
8898c2ecf20Sopenharmony_ciint safexcel_invalidate_cache(struct crypto_async_request *async,
8908c2ecf20Sopenharmony_ci			      struct safexcel_crypto_priv *priv,
8918c2ecf20Sopenharmony_ci			      dma_addr_t ctxr_dma, int ring);
8928c2ecf20Sopenharmony_ciint safexcel_init_ring_descriptors(struct safexcel_crypto_priv *priv,
8938c2ecf20Sopenharmony_ci				   struct safexcel_desc_ring *cdr,
8948c2ecf20Sopenharmony_ci				   struct safexcel_desc_ring *rdr);
8958c2ecf20Sopenharmony_ciint safexcel_select_ring(struct safexcel_crypto_priv *priv);
8968c2ecf20Sopenharmony_civoid *safexcel_ring_next_rptr(struct safexcel_crypto_priv *priv,
8978c2ecf20Sopenharmony_ci			      struct safexcel_desc_ring *ring);
8988c2ecf20Sopenharmony_civoid *safexcel_ring_first_rptr(struct safexcel_crypto_priv *priv, int  ring);
8998c2ecf20Sopenharmony_civoid safexcel_ring_rollback_wptr(struct safexcel_crypto_priv *priv,
9008c2ecf20Sopenharmony_ci				 struct safexcel_desc_ring *ring);
9018c2ecf20Sopenharmony_cistruct safexcel_command_desc *safexcel_add_cdesc(struct safexcel_crypto_priv *priv,
9028c2ecf20Sopenharmony_ci						 int ring_id,
9038c2ecf20Sopenharmony_ci						 bool first, bool last,
9048c2ecf20Sopenharmony_ci						 dma_addr_t data, u32 len,
9058c2ecf20Sopenharmony_ci						 u32 full_data_len,
9068c2ecf20Sopenharmony_ci						 dma_addr_t context,
9078c2ecf20Sopenharmony_ci						 struct safexcel_token **atoken);
9088c2ecf20Sopenharmony_cistruct safexcel_result_desc *safexcel_add_rdesc(struct safexcel_crypto_priv *priv,
9098c2ecf20Sopenharmony_ci						 int ring_id,
9108c2ecf20Sopenharmony_ci						bool first, bool last,
9118c2ecf20Sopenharmony_ci						dma_addr_t data, u32 len);
9128c2ecf20Sopenharmony_ciint safexcel_ring_first_rdr_index(struct safexcel_crypto_priv *priv,
9138c2ecf20Sopenharmony_ci				  int ring);
9148c2ecf20Sopenharmony_ciint safexcel_ring_rdr_rdesc_index(struct safexcel_crypto_priv *priv,
9158c2ecf20Sopenharmony_ci				  int ring,
9168c2ecf20Sopenharmony_ci				  struct safexcel_result_desc *rdesc);
9178c2ecf20Sopenharmony_civoid safexcel_rdr_req_set(struct safexcel_crypto_priv *priv,
9188c2ecf20Sopenharmony_ci			  int ring,
9198c2ecf20Sopenharmony_ci			  struct safexcel_result_desc *rdesc,
9208c2ecf20Sopenharmony_ci			  struct crypto_async_request *req);
9218c2ecf20Sopenharmony_ciinline struct crypto_async_request *
9228c2ecf20Sopenharmony_cisafexcel_rdr_req_get(struct safexcel_crypto_priv *priv, int ring);
9238c2ecf20Sopenharmony_civoid safexcel_inv_complete(struct crypto_async_request *req, int error);
9248c2ecf20Sopenharmony_ciint safexcel_hmac_setkey(struct safexcel_context *base, const u8 *key,
9258c2ecf20Sopenharmony_ci			 unsigned int keylen, const char *alg,
9268c2ecf20Sopenharmony_ci			 unsigned int state_sz);
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci/* available algorithms */
9298c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_des;
9308c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_des;
9318c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_des3_ede;
9328c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_des3_ede;
9338c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_aes;
9348c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_aes;
9358c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cfb_aes;
9368c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ofb_aes;
9378c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ctr_aes;
9388c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_md5;
9398c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha1;
9408c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha224;
9418c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha256;
9428c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha384;
9438c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha512;
9448c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_md5;
9458c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha1;
9468c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha224;
9478c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha256;
9488c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha384;
9498c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha512;
9508c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_aes;
9518c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes;
9528c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_aes;
9538c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes;
9548c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_aes;
9558c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_des3_ede;
9568c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_ctr_aes;
9578c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_ctr_aes;
9588c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_ctr_aes;
9598c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_ctr_aes;
9608c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_ctr_aes;
9618c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_xts_aes;
9628c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_gcm;
9638c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ccm;
9648c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_crc32;
9658c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbcmac;
9668c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_xcbcmac;
9678c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cmac;
9688c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_chacha20;
9698c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_chachapoly;
9708c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_chachapoly_esp;
9718c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sm3;
9728c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sm3;
9738c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_sm4;
9748c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_sm4;
9758c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ofb_sm4;
9768c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cfb_sm4;
9778c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ctr_sm4;
9788c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_sm4;
9798c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sm3_cbc_sm4;
9808c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_ctr_sm4;
9818c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sm3_ctr_sm4;
9828c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_224;
9838c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_256;
9848c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_384;
9858c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_512;
9868c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_224;
9878c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_256;
9888c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_384;
9898c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_512;
9908c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_des;
9918c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_des3_ede;
9928c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_des3_ede;
9938c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_des3_ede;
9948c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_des3_ede;
9958c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_des;
9968c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_des;
9978c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_des;
9988c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_des;
9998c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_rfc4106_gcm;
10008c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_rfc4543_gcm;
10018c2ecf20Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_rfc4309_ccm;
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci#endif
1004