162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2017 Marvell
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Antoine Tenart <antoine.tenart@free-electrons.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __SAFEXCEL_H__
962306a36Sopenharmony_ci#define __SAFEXCEL_H__
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <crypto/aead.h>
1262306a36Sopenharmony_ci#include <crypto/algapi.h>
1362306a36Sopenharmony_ci#include <crypto/internal/hash.h>
1462306a36Sopenharmony_ci#include <crypto/sha1.h>
1562306a36Sopenharmony_ci#include <crypto/sha2.h>
1662306a36Sopenharmony_ci#include <crypto/sha3.h>
1762306a36Sopenharmony_ci#include <crypto/skcipher.h>
1862306a36Sopenharmony_ci#include <linux/types.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define EIP197_HIA_VERSION_BE			0xca35
2162306a36Sopenharmony_ci#define EIP197_HIA_VERSION_LE			0x35ca
2262306a36Sopenharmony_ci#define EIP97_VERSION_LE			0x9e61
2362306a36Sopenharmony_ci#define EIP196_VERSION_LE			0x3bc4
2462306a36Sopenharmony_ci#define EIP197_VERSION_LE			0x3ac5
2562306a36Sopenharmony_ci#define EIP96_VERSION_LE			0x9f60
2662306a36Sopenharmony_ci#define EIP201_VERSION_LE			0x36c9
2762306a36Sopenharmony_ci#define EIP206_VERSION_LE			0x31ce
2862306a36Sopenharmony_ci#define EIP207_VERSION_LE			0x30cf
2962306a36Sopenharmony_ci#define EIP197_REG_LO16(reg)			(reg & 0xffff)
3062306a36Sopenharmony_ci#define EIP197_REG_HI16(reg)			((reg >> 16) & 0xffff)
3162306a36Sopenharmony_ci#define EIP197_VERSION_MASK(reg)		((reg >> 16) & 0xfff)
3262306a36Sopenharmony_ci#define EIP197_VERSION_SWAP(reg)		(((reg & 0xf0) << 4) | \
3362306a36Sopenharmony_ci						((reg >> 4) & 0xf0) | \
3462306a36Sopenharmony_ci						((reg >> 12) & 0xf))
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/* EIP197 HIA OPTIONS ENCODING */
3762306a36Sopenharmony_ci#define EIP197_HIA_OPT_HAS_PE_ARB		BIT(29)
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* EIP206 OPTIONS ENCODING */
4062306a36Sopenharmony_ci#define EIP206_OPT_ICE_TYPE(n)			((n>>8)&3)
4162306a36Sopenharmony_ci#define EIP206_OPT_OCE_TYPE(n)			((n>>10)&3)
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/* EIP197 OPTIONS ENCODING */
4462306a36Sopenharmony_ci#define EIP197_OPT_HAS_TRC			BIT(31)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/* Static configuration */
4762306a36Sopenharmony_ci#define EIP197_DEFAULT_RING_SIZE		400
4862306a36Sopenharmony_ci#define EIP197_EMB_TOKENS			4 /* Pad CD to 16 dwords */
4962306a36Sopenharmony_ci#define EIP197_MAX_TOKENS			16
5062306a36Sopenharmony_ci#define EIP197_MAX_RINGS			4
5162306a36Sopenharmony_ci#define EIP197_FETCH_DEPTH			2
5262306a36Sopenharmony_ci#define EIP197_MAX_BATCH_SZ			64
5362306a36Sopenharmony_ci#define EIP197_MAX_RING_AIC			14
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#define EIP197_GFP_FLAGS(base)	((base).flags & CRYPTO_TFM_REQ_MAY_SLEEP ? \
5662306a36Sopenharmony_ci				 GFP_KERNEL : GFP_ATOMIC)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* Custom on-stack requests (for invalidation) */
5962306a36Sopenharmony_ci#define EIP197_SKCIPHER_REQ_SIZE	sizeof(struct skcipher_request) + \
6062306a36Sopenharmony_ci					sizeof(struct safexcel_cipher_req)
6162306a36Sopenharmony_ci#define EIP197_AHASH_REQ_SIZE		sizeof(struct ahash_request) + \
6262306a36Sopenharmony_ci					sizeof(struct safexcel_ahash_req)
6362306a36Sopenharmony_ci#define EIP197_AEAD_REQ_SIZE		sizeof(struct aead_request) + \
6462306a36Sopenharmony_ci					sizeof(struct safexcel_cipher_req)
6562306a36Sopenharmony_ci#define EIP197_REQUEST_ON_STACK(name, type, size) \
6662306a36Sopenharmony_ci	char __##name##_desc[size] CRYPTO_MINALIGN_ATTR; \
6762306a36Sopenharmony_ci	struct type##_request *name = (void *)__##name##_desc
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* Xilinx dev board base offsets */
7062306a36Sopenharmony_ci#define EIP197_XLX_GPIO_BASE		0x200000
7162306a36Sopenharmony_ci#define EIP197_XLX_IRQ_BLOCK_ID_ADDR	0x2000
7262306a36Sopenharmony_ci#define EIP197_XLX_IRQ_BLOCK_ID_VALUE	0x1fc2
7362306a36Sopenharmony_ci#define EIP197_XLX_USER_INT_ENB_MSK	0x2004
7462306a36Sopenharmony_ci#define EIP197_XLX_USER_INT_ENB_SET	0x2008
7562306a36Sopenharmony_ci#define EIP197_XLX_USER_INT_ENB_CLEAR	0x200c
7662306a36Sopenharmony_ci#define EIP197_XLX_USER_INT_BLOCK	0x2040
7762306a36Sopenharmony_ci#define EIP197_XLX_USER_INT_PEND	0x2048
7862306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT0_ADDR	0x2080
7962306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT0_IDENT	0x03020100
8062306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT1_ADDR	0x2084
8162306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT1_IDENT	0x07060504
8262306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT2_ADDR	0x2088
8362306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT2_IDENT	0x0b0a0908
8462306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT3_ADDR	0x208c
8562306a36Sopenharmony_ci#define EIP197_XLX_USER_VECT_LUT3_IDENT	0x0f0e0d0c
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/* Helper defines for probe function */
8862306a36Sopenharmony_ci#define EIP197_IRQ_NUMBER(i, is_pci)	(i + is_pci)
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci/* Register base offsets */
9162306a36Sopenharmony_ci#define EIP197_HIA_AIC(priv)		((priv)->base + (priv)->offsets.hia_aic)
9262306a36Sopenharmony_ci#define EIP197_HIA_AIC_G(priv)		((priv)->base + (priv)->offsets.hia_aic_g)
9362306a36Sopenharmony_ci#define EIP197_HIA_AIC_R(priv)		((priv)->base + (priv)->offsets.hia_aic_r)
9462306a36Sopenharmony_ci#define EIP197_HIA_AIC_xDR(priv)	((priv)->base + (priv)->offsets.hia_aic_xdr)
9562306a36Sopenharmony_ci#define EIP197_HIA_DFE(priv)		((priv)->base + (priv)->offsets.hia_dfe)
9662306a36Sopenharmony_ci#define EIP197_HIA_DFE_THR(priv)	((priv)->base + (priv)->offsets.hia_dfe_thr)
9762306a36Sopenharmony_ci#define EIP197_HIA_DSE(priv)		((priv)->base + (priv)->offsets.hia_dse)
9862306a36Sopenharmony_ci#define EIP197_HIA_DSE_THR(priv)	((priv)->base + (priv)->offsets.hia_dse_thr)
9962306a36Sopenharmony_ci#define EIP197_HIA_GEN_CFG(priv)	((priv)->base + (priv)->offsets.hia_gen_cfg)
10062306a36Sopenharmony_ci#define EIP197_PE(priv)			((priv)->base + (priv)->offsets.pe)
10162306a36Sopenharmony_ci#define EIP197_GLOBAL(priv)		((priv)->base + (priv)->offsets.global)
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* EIP197 base offsets */
10462306a36Sopenharmony_ci#define EIP197_HIA_AIC_BASE		0x90000
10562306a36Sopenharmony_ci#define EIP197_HIA_AIC_G_BASE		0x90000
10662306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_BASE		0x90800
10762306a36Sopenharmony_ci#define EIP197_HIA_AIC_xDR_BASE		0x80000
10862306a36Sopenharmony_ci#define EIP197_HIA_DFE_BASE		0x8c000
10962306a36Sopenharmony_ci#define EIP197_HIA_DFE_THR_BASE		0x8c040
11062306a36Sopenharmony_ci#define EIP197_HIA_DSE_BASE		0x8d000
11162306a36Sopenharmony_ci#define EIP197_HIA_DSE_THR_BASE		0x8d040
11262306a36Sopenharmony_ci#define EIP197_HIA_GEN_CFG_BASE		0xf0000
11362306a36Sopenharmony_ci#define EIP197_PE_BASE			0xa0000
11462306a36Sopenharmony_ci#define EIP197_GLOBAL_BASE		0xf0000
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci/* EIP97 base offsets */
11762306a36Sopenharmony_ci#define EIP97_HIA_AIC_BASE		0x0
11862306a36Sopenharmony_ci#define EIP97_HIA_AIC_G_BASE		0x0
11962306a36Sopenharmony_ci#define EIP97_HIA_AIC_R_BASE		0x0
12062306a36Sopenharmony_ci#define EIP97_HIA_AIC_xDR_BASE		0x0
12162306a36Sopenharmony_ci#define EIP97_HIA_DFE_BASE		0xf000
12262306a36Sopenharmony_ci#define EIP97_HIA_DFE_THR_BASE		0xf200
12362306a36Sopenharmony_ci#define EIP97_HIA_DSE_BASE		0xf400
12462306a36Sopenharmony_ci#define EIP97_HIA_DSE_THR_BASE		0xf600
12562306a36Sopenharmony_ci#define EIP97_HIA_GEN_CFG_BASE		0x10000
12662306a36Sopenharmony_ci#define EIP97_PE_BASE			0x10000
12762306a36Sopenharmony_ci#define EIP97_GLOBAL_BASE		0x10000
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci/* CDR/RDR register offsets */
13062306a36Sopenharmony_ci#define EIP197_HIA_xDR_OFF(priv, r)		(EIP197_HIA_AIC_xDR(priv) + (r) * 0x1000)
13162306a36Sopenharmony_ci#define EIP197_HIA_CDR(priv, r)			(EIP197_HIA_xDR_OFF(priv, r))
13262306a36Sopenharmony_ci#define EIP197_HIA_RDR(priv, r)			(EIP197_HIA_xDR_OFF(priv, r) + 0x800)
13362306a36Sopenharmony_ci#define EIP197_HIA_xDR_RING_BASE_ADDR_LO	0x0000
13462306a36Sopenharmony_ci#define EIP197_HIA_xDR_RING_BASE_ADDR_HI	0x0004
13562306a36Sopenharmony_ci#define EIP197_HIA_xDR_RING_SIZE		0x0018
13662306a36Sopenharmony_ci#define EIP197_HIA_xDR_DESC_SIZE		0x001c
13762306a36Sopenharmony_ci#define EIP197_HIA_xDR_CFG			0x0020
13862306a36Sopenharmony_ci#define EIP197_HIA_xDR_DMA_CFG			0x0024
13962306a36Sopenharmony_ci#define EIP197_HIA_xDR_THRESH			0x0028
14062306a36Sopenharmony_ci#define EIP197_HIA_xDR_PREP_COUNT		0x002c
14162306a36Sopenharmony_ci#define EIP197_HIA_xDR_PROC_COUNT		0x0030
14262306a36Sopenharmony_ci#define EIP197_HIA_xDR_PREP_PNTR		0x0034
14362306a36Sopenharmony_ci#define EIP197_HIA_xDR_PROC_PNTR		0x0038
14462306a36Sopenharmony_ci#define EIP197_HIA_xDR_STAT			0x003c
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci/* register offsets */
14762306a36Sopenharmony_ci#define EIP197_HIA_DFE_CFG(n)			(0x0000 + (128 * (n)))
14862306a36Sopenharmony_ci#define EIP197_HIA_DFE_THR_CTRL(n)		(0x0000 + (128 * (n)))
14962306a36Sopenharmony_ci#define EIP197_HIA_DFE_THR_STAT(n)		(0x0004 + (128 * (n)))
15062306a36Sopenharmony_ci#define EIP197_HIA_DSE_CFG(n)			(0x0000 + (128 * (n)))
15162306a36Sopenharmony_ci#define EIP197_HIA_DSE_THR_CTRL(n)		(0x0000 + (128 * (n)))
15262306a36Sopenharmony_ci#define EIP197_HIA_DSE_THR_STAT(n)		(0x0004 + (128 * (n)))
15362306a36Sopenharmony_ci#define EIP197_HIA_RA_PE_CTRL(n)		(0x0010 + (8   * (n)))
15462306a36Sopenharmony_ci#define EIP197_HIA_RA_PE_STAT			0x0014
15562306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_OFF(r)			((r) * 0x1000)
15662306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_ENABLE_CTRL(r)		(0xe008 - EIP197_HIA_AIC_R_OFF(r))
15762306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_ENABLED_STAT(r)	(0xe010 - EIP197_HIA_AIC_R_OFF(r))
15862306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_ACK(r)			(0xe010 - EIP197_HIA_AIC_R_OFF(r))
15962306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_ENABLE_CLR(r)		(0xe014 - EIP197_HIA_AIC_R_OFF(r))
16062306a36Sopenharmony_ci#define EIP197_HIA_AIC_R_VERSION(r)		(0xe01c - EIP197_HIA_AIC_R_OFF(r))
16162306a36Sopenharmony_ci#define EIP197_HIA_AIC_G_ENABLE_CTRL		0xf808
16262306a36Sopenharmony_ci#define EIP197_HIA_AIC_G_ENABLED_STAT		0xf810
16362306a36Sopenharmony_ci#define EIP197_HIA_AIC_G_ACK			0xf810
16462306a36Sopenharmony_ci#define EIP197_HIA_MST_CTRL			0xfff4
16562306a36Sopenharmony_ci#define EIP197_HIA_OPTIONS			0xfff8
16662306a36Sopenharmony_ci#define EIP197_HIA_VERSION			0xfffc
16762306a36Sopenharmony_ci#define EIP197_PE_IN_DBUF_THRES(n)		(0x0000 + (0x2000 * (n)))
16862306a36Sopenharmony_ci#define EIP197_PE_IN_TBUF_THRES(n)		(0x0100 + (0x2000 * (n)))
16962306a36Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_RAM(n)		(0x0800 + (0x2000 * (n)))
17062306a36Sopenharmony_ci#define EIP197_PE_ICE_PUE_CTRL(n)		(0x0c80 + (0x2000 * (n)))
17162306a36Sopenharmony_ci#define EIP197_PE_ICE_PUTF_CTRL(n)		(0x0d00 + (0x2000 * (n)))
17262306a36Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL(n)		(0x0d04 + (0x2000 * (n)))
17362306a36Sopenharmony_ci#define EIP197_PE_ICE_FPP_CTRL(n)		(0x0d80 + (0x2000 * (n)))
17462306a36Sopenharmony_ci#define EIP197_PE_ICE_PPTF_CTRL(n)		(0x0e00 + (0x2000 * (n)))
17562306a36Sopenharmony_ci#define EIP197_PE_ICE_RAM_CTRL(n)		(0x0ff0 + (0x2000 * (n)))
17662306a36Sopenharmony_ci#define EIP197_PE_ICE_VERSION(n)		(0x0ffc + (0x2000 * (n)))
17762306a36Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL(n)		(0x1000 + (0x2000 * (n)))
17862306a36Sopenharmony_ci#define EIP197_PE_EIP96_FUNCTION_EN(n)		(0x1004 + (0x2000 * (n)))
17962306a36Sopenharmony_ci#define EIP197_PE_EIP96_CONTEXT_CTRL(n)		(0x1008 + (0x2000 * (n)))
18062306a36Sopenharmony_ci#define EIP197_PE_EIP96_CONTEXT_STAT(n)		(0x100c + (0x2000 * (n)))
18162306a36Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL2(n)		(0x102c + (0x2000 * (n)))
18262306a36Sopenharmony_ci#define EIP197_PE_EIP96_FUNCTION2_EN(n)		(0x1030 + (0x2000 * (n)))
18362306a36Sopenharmony_ci#define EIP197_PE_EIP96_OPTIONS(n)		(0x13f8 + (0x2000 * (n)))
18462306a36Sopenharmony_ci#define EIP197_PE_EIP96_VERSION(n)		(0x13fc + (0x2000 * (n)))
18562306a36Sopenharmony_ci#define EIP197_PE_OCE_VERSION(n)		(0x1bfc + (0x2000 * (n)))
18662306a36Sopenharmony_ci#define EIP197_PE_OUT_DBUF_THRES(n)		(0x1c00 + (0x2000 * (n)))
18762306a36Sopenharmony_ci#define EIP197_PE_OUT_TBUF_THRES(n)		(0x1d00 + (0x2000 * (n)))
18862306a36Sopenharmony_ci#define EIP197_PE_PSE_VERSION(n)		(0x1efc + (0x2000 * (n)))
18962306a36Sopenharmony_ci#define EIP197_PE_DEBUG(n)			(0x1ff4 + (0x2000 * (n)))
19062306a36Sopenharmony_ci#define EIP197_PE_OPTIONS(n)			(0x1ff8 + (0x2000 * (n)))
19162306a36Sopenharmony_ci#define EIP197_PE_VERSION(n)			(0x1ffc + (0x2000 * (n)))
19262306a36Sopenharmony_ci#define EIP197_MST_CTRL				0xfff4
19362306a36Sopenharmony_ci#define EIP197_OPTIONS				0xfff8
19462306a36Sopenharmony_ci#define EIP197_VERSION				0xfffc
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci/* EIP197-specific registers, no indirection */
19762306a36Sopenharmony_ci#define EIP197_CLASSIFICATION_RAMS		0xe0000
19862306a36Sopenharmony_ci#define EIP197_TRC_CTRL				0xf0800
19962306a36Sopenharmony_ci#define EIP197_TRC_LASTRES			0xf0804
20062306a36Sopenharmony_ci#define EIP197_TRC_REGINDEX			0xf0808
20162306a36Sopenharmony_ci#define EIP197_TRC_PARAMS			0xf0820
20262306a36Sopenharmony_ci#define EIP197_TRC_FREECHAIN			0xf0824
20362306a36Sopenharmony_ci#define EIP197_TRC_PARAMS2			0xf0828
20462306a36Sopenharmony_ci#define EIP197_TRC_ECCCTRL			0xf0830
20562306a36Sopenharmony_ci#define EIP197_TRC_ECCSTAT			0xf0834
20662306a36Sopenharmony_ci#define EIP197_TRC_ECCADMINSTAT			0xf0838
20762306a36Sopenharmony_ci#define EIP197_TRC_ECCDATASTAT			0xf083c
20862306a36Sopenharmony_ci#define EIP197_TRC_ECCDATA			0xf0840
20962306a36Sopenharmony_ci#define EIP197_STRC_CONFIG			0xf43f0
21062306a36Sopenharmony_ci#define EIP197_FLUE_CACHEBASE_LO(n)		(0xf6000 + (32 * (n)))
21162306a36Sopenharmony_ci#define EIP197_FLUE_CACHEBASE_HI(n)		(0xf6004 + (32 * (n)))
21262306a36Sopenharmony_ci#define EIP197_FLUE_CONFIG(n)			(0xf6010 + (32 * (n)))
21362306a36Sopenharmony_ci#define EIP197_FLUE_OFFSETS			0xf6808
21462306a36Sopenharmony_ci#define EIP197_FLUE_ARC4_OFFSET			0xf680c
21562306a36Sopenharmony_ci#define EIP197_FLUE_IFC_LUT(n)			(0xf6820 + (4 * (n)))
21662306a36Sopenharmony_ci#define EIP197_CS_RAM_CTRL			0xf7ff0
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci/* EIP197_HIA_xDR_DESC_SIZE */
21962306a36Sopenharmony_ci#define EIP197_xDR_DESC_MODE_64BIT		BIT(31)
22062306a36Sopenharmony_ci#define EIP197_CDR_DESC_MODE_ADCP		BIT(30)
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci/* EIP197_HIA_xDR_DMA_CFG */
22362306a36Sopenharmony_ci#define EIP197_HIA_xDR_WR_RES_BUF		BIT(22)
22462306a36Sopenharmony_ci#define EIP197_HIA_xDR_WR_CTRL_BUF		BIT(23)
22562306a36Sopenharmony_ci#define EIP197_HIA_xDR_WR_OWN_BUF		BIT(24)
22662306a36Sopenharmony_ci#define EIP197_HIA_xDR_CFG_WR_CACHE(n)		(((n) & 0x7) << 25)
22762306a36Sopenharmony_ci#define EIP197_HIA_xDR_CFG_RD_CACHE(n)		(((n) & 0x7) << 29)
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci/* EIP197_HIA_CDR_THRESH */
23062306a36Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_PROC_PKT(n)	(n)
23162306a36Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_PROC_MODE		BIT(22)
23262306a36Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_PKT_MODE		BIT(23)
23362306a36Sopenharmony_ci#define EIP197_HIA_CDR_THRESH_TIMEOUT(n)	((n) << 24) /* x256 clk cycles */
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci/* EIP197_HIA_RDR_THRESH */
23662306a36Sopenharmony_ci#define EIP197_HIA_RDR_THRESH_PROC_PKT(n)	(n)
23762306a36Sopenharmony_ci#define EIP197_HIA_RDR_THRESH_PKT_MODE		BIT(23)
23862306a36Sopenharmony_ci#define EIP197_HIA_RDR_THRESH_TIMEOUT(n)	((n) << 24) /* x256 clk cycles */
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci/* EIP197_HIA_xDR_PREP_COUNT */
24162306a36Sopenharmony_ci#define EIP197_xDR_PREP_CLR_COUNT		BIT(31)
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci/* EIP197_HIA_xDR_PROC_COUNT */
24462306a36Sopenharmony_ci#define EIP197_xDR_PROC_xD_PKT_OFFSET		24
24562306a36Sopenharmony_ci#define EIP197_xDR_PROC_xD_PKT_MASK		GENMASK(6, 0)
24662306a36Sopenharmony_ci#define EIP197_xDR_PROC_xD_PKT(n)		((n) << 24)
24762306a36Sopenharmony_ci#define EIP197_xDR_PROC_CLR_COUNT		BIT(31)
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/* EIP197_HIA_xDR_STAT */
25062306a36Sopenharmony_ci#define EIP197_xDR_DMA_ERR			BIT(0)
25162306a36Sopenharmony_ci#define EIP197_xDR_PREP_CMD_THRES		BIT(1)
25262306a36Sopenharmony_ci#define EIP197_xDR_ERR				BIT(2)
25362306a36Sopenharmony_ci#define EIP197_xDR_THRESH			BIT(4)
25462306a36Sopenharmony_ci#define EIP197_xDR_TIMEOUT			BIT(5)
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci#define EIP197_HIA_RA_PE_CTRL_RESET		BIT(31)
25762306a36Sopenharmony_ci#define EIP197_HIA_RA_PE_CTRL_EN		BIT(30)
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci/* EIP197_HIA_OPTIONS */
26062306a36Sopenharmony_ci#define EIP197_N_RINGS_OFFSET			0
26162306a36Sopenharmony_ci#define EIP197_N_RINGS_MASK			GENMASK(3, 0)
26262306a36Sopenharmony_ci#define EIP197_N_PES_OFFSET			4
26362306a36Sopenharmony_ci#define EIP197_N_PES_MASK			GENMASK(4, 0)
26462306a36Sopenharmony_ci#define EIP97_N_PES_MASK			GENMASK(2, 0)
26562306a36Sopenharmony_ci#define EIP197_HWDATAW_OFFSET			25
26662306a36Sopenharmony_ci#define EIP197_HWDATAW_MASK			GENMASK(3, 0)
26762306a36Sopenharmony_ci#define EIP97_HWDATAW_MASK			GENMASK(2, 0)
26862306a36Sopenharmony_ci#define EIP197_CFSIZE_OFFSET			9
26962306a36Sopenharmony_ci#define EIP197_CFSIZE_ADJUST			4
27062306a36Sopenharmony_ci#define EIP97_CFSIZE_OFFSET			8
27162306a36Sopenharmony_ci#define EIP197_CFSIZE_MASK			GENMASK(2, 0)
27262306a36Sopenharmony_ci#define EIP97_CFSIZE_MASK			GENMASK(3, 0)
27362306a36Sopenharmony_ci#define EIP197_RFSIZE_OFFSET			12
27462306a36Sopenharmony_ci#define EIP197_RFSIZE_ADJUST			4
27562306a36Sopenharmony_ci#define EIP97_RFSIZE_OFFSET			12
27662306a36Sopenharmony_ci#define EIP197_RFSIZE_MASK			GENMASK(2, 0)
27762306a36Sopenharmony_ci#define EIP97_RFSIZE_MASK			GENMASK(3, 0)
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci/* EIP197_HIA_AIC_R_ENABLE_CTRL */
28062306a36Sopenharmony_ci#define EIP197_CDR_IRQ(n)			BIT((n) * 2)
28162306a36Sopenharmony_ci#define EIP197_RDR_IRQ(n)			BIT((n) * 2 + 1)
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci/* EIP197_HIA_DFE/DSE_CFG */
28462306a36Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MIN_DATA_SIZE(n)	((n) << 0)
28562306a36Sopenharmony_ci#define EIP197_HIA_DxE_CFG_DATA_CACHE_CTRL(n)	(((n) & 0x7) << 4)
28662306a36Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MAX_DATA_SIZE(n)	((n) << 8)
28762306a36Sopenharmony_ci#define EIP197_HIA_DSE_CFG_ALWAYS_BUFFERABLE	GENMASK(15, 14)
28862306a36Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MIN_CTRL_SIZE(n)	((n) << 16)
28962306a36Sopenharmony_ci#define EIP197_HIA_DxE_CFG_CTRL_CACHE_CTRL(n)	(((n) & 0x7) << 20)
29062306a36Sopenharmony_ci#define EIP197_HIA_DxE_CFG_MAX_CTRL_SIZE(n)	((n) << 24)
29162306a36Sopenharmony_ci#define EIP197_HIA_DFE_CFG_DIS_DEBUG		GENMASK(31, 29)
29262306a36Sopenharmony_ci#define EIP197_HIA_DSE_CFG_EN_SINGLE_WR		BIT(29)
29362306a36Sopenharmony_ci#define EIP197_HIA_DSE_CFG_DIS_DEBUG		GENMASK(31, 30)
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci/* EIP197_HIA_DFE/DSE_THR_CTRL */
29662306a36Sopenharmony_ci#define EIP197_DxE_THR_CTRL_EN			BIT(30)
29762306a36Sopenharmony_ci#define EIP197_DxE_THR_CTRL_RESET_PE		BIT(31)
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci/* EIP197_PE_ICE_PUE/FPP_CTRL */
30062306a36Sopenharmony_ci#define EIP197_PE_ICE_UENG_START_OFFSET(n)	((n) << 16)
30162306a36Sopenharmony_ci#define EIP197_PE_ICE_UENG_INIT_ALIGN_MASK	0x7ff0
30262306a36Sopenharmony_ci#define EIP197_PE_ICE_UENG_DEBUG_RESET		BIT(3)
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci/* EIP197_HIA_AIC_G_ENABLED_STAT */
30562306a36Sopenharmony_ci#define EIP197_G_IRQ_DFE(n)			BIT((n) << 1)
30662306a36Sopenharmony_ci#define EIP197_G_IRQ_DSE(n)			BIT(((n) << 1) + 1)
30762306a36Sopenharmony_ci#define EIP197_G_IRQ_RING			BIT(16)
30862306a36Sopenharmony_ci#define EIP197_G_IRQ_PE(n)			BIT((n) + 20)
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci/* EIP197_HIA_MST_CTRL */
31162306a36Sopenharmony_ci#define RD_CACHE_3BITS				0x5
31262306a36Sopenharmony_ci#define WR_CACHE_3BITS				0x3
31362306a36Sopenharmony_ci#define RD_CACHE_4BITS				(RD_CACHE_3BITS << 1 | BIT(0))
31462306a36Sopenharmony_ci#define WR_CACHE_4BITS				(WR_CACHE_3BITS << 1 | BIT(0))
31562306a36Sopenharmony_ci#define EIP197_MST_CTRL_RD_CACHE(n)		(((n) & 0xf) << 0)
31662306a36Sopenharmony_ci#define EIP197_MST_CTRL_WD_CACHE(n)		(((n) & 0xf) << 4)
31762306a36Sopenharmony_ci#define EIP197_MST_CTRL_TX_MAX_CMD(n)		(((n) & 0xf) << 20)
31862306a36Sopenharmony_ci#define EIP197_MST_CTRL_BYTE_SWAP		BIT(24)
31962306a36Sopenharmony_ci#define EIP197_MST_CTRL_NO_BYTE_SWAP		BIT(25)
32062306a36Sopenharmony_ci#define EIP197_MST_CTRL_BYTE_SWAP_BITS          GENMASK(25, 24)
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci/* EIP197_PE_IN_DBUF/TBUF_THRES */
32362306a36Sopenharmony_ci#define EIP197_PE_IN_xBUF_THRES_MIN(n)		((n) << 8)
32462306a36Sopenharmony_ci#define EIP197_PE_IN_xBUF_THRES_MAX(n)		((n) << 12)
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci/* EIP197_PE_OUT_DBUF_THRES */
32762306a36Sopenharmony_ci#define EIP197_PE_OUT_DBUF_THRES_MIN(n)		((n) << 0)
32862306a36Sopenharmony_ci#define EIP197_PE_OUT_DBUF_THRES_MAX(n)		((n) << 4)
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci/* EIP197_PE_ICE_SCRATCH_CTRL */
33162306a36Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_TIMER		BIT(2)
33262306a36Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_TIMER_EN		BIT(3)
33362306a36Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_ACCESS	BIT(24)
33462306a36Sopenharmony_ci#define EIP197_PE_ICE_SCRATCH_CTRL_SCRATCH_ACCESS	BIT(25)
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci/* EIP197_PE_ICE_SCRATCH_RAM */
33762306a36Sopenharmony_ci#define EIP197_NUM_OF_SCRATCH_BLOCKS		32
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ci/* EIP197_PE_ICE_PUE/FPP_CTRL */
34062306a36Sopenharmony_ci#define EIP197_PE_ICE_x_CTRL_SW_RESET			BIT(0)
34162306a36Sopenharmony_ci#define EIP197_PE_ICE_x_CTRL_CLR_ECC_NON_CORR		BIT(14)
34262306a36Sopenharmony_ci#define EIP197_PE_ICE_x_CTRL_CLR_ECC_CORR		BIT(15)
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci/* EIP197_PE_ICE_RAM_CTRL */
34562306a36Sopenharmony_ci#define EIP197_PE_ICE_RAM_CTRL_PUE_PROG_EN	BIT(0)
34662306a36Sopenharmony_ci#define EIP197_PE_ICE_RAM_CTRL_FPP_PROG_EN	BIT(1)
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci/* EIP197_PE_EIP96_TOKEN_CTRL */
34962306a36Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL_CTX_UPDATES		BIT(16)
35062306a36Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL_NO_TOKEN_WAIT	BIT(17)
35162306a36Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL_ENABLE_TIMEOUT	BIT(22)
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_ci/* EIP197_PE_EIP96_FUNCTION_EN */
35462306a36Sopenharmony_ci#define EIP197_FUNCTION_ALL			0xffffffff
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ci/* EIP197_PE_EIP96_CONTEXT_CTRL */
35762306a36Sopenharmony_ci#define EIP197_CONTEXT_SIZE(n)			(n)
35862306a36Sopenharmony_ci#define EIP197_ADDRESS_MODE			BIT(8)
35962306a36Sopenharmony_ci#define EIP197_CONTROL_MODE			BIT(9)
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci/* EIP197_PE_EIP96_TOKEN_CTRL2 */
36262306a36Sopenharmony_ci#define EIP197_PE_EIP96_TOKEN_CTRL2_CTX_DONE	BIT(3)
36362306a36Sopenharmony_ci
36462306a36Sopenharmony_ci/* EIP197_PE_DEBUG */
36562306a36Sopenharmony_ci#define EIP197_DEBUG_OCE_BYPASS			BIT(1)
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci/* EIP197_STRC_CONFIG */
36862306a36Sopenharmony_ci#define EIP197_STRC_CONFIG_INIT			BIT(31)
36962306a36Sopenharmony_ci#define EIP197_STRC_CONFIG_LARGE_REC(s)		(s<<8)
37062306a36Sopenharmony_ci#define EIP197_STRC_CONFIG_SMALL_REC(s)		(s<<0)
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci/* EIP197_FLUE_CONFIG */
37362306a36Sopenharmony_ci#define EIP197_FLUE_CONFIG_MAGIC		0xc7000004
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci/* Context Control */
37662306a36Sopenharmony_cistruct safexcel_context_record {
37762306a36Sopenharmony_ci	__le32 control0;
37862306a36Sopenharmony_ci	__le32 control1;
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci	__le32 data[40];
38162306a36Sopenharmony_ci} __packed;
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci/* control0 */
38462306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_NULL_OUT		0x0
38562306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_NULL_IN		0x1
38662306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_OUT		0x2
38762306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_IN		0x3
38862306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_CRYPTO_OUT		0x4
38962306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_CRYPTO_IN		0x5
39062306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_ENCRYPT_HASH_OUT	0x6
39162306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_DECRYPT_HASH_IN	0x7
39262306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_ENCRYPT_OUT	0xe
39362306a36Sopenharmony_ci#define CONTEXT_CONTROL_TYPE_HASH_DECRYPT_IN	0xf
39462306a36Sopenharmony_ci#define CONTEXT_CONTROL_RESTART_HASH		BIT(4)
39562306a36Sopenharmony_ci#define CONTEXT_CONTROL_NO_FINISH_HASH		BIT(5)
39662306a36Sopenharmony_ci#define CONTEXT_CONTROL_SIZE(n)			((n) << 8)
39762306a36Sopenharmony_ci#define CONTEXT_CONTROL_KEY_EN			BIT(16)
39862306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_DES		(0x0 << 17)
39962306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_3DES		(0x2 << 17)
40062306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_AES128	(0x5 << 17)
40162306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_AES192	(0x6 << 17)
40262306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_AES256	(0x7 << 17)
40362306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_CHACHA20	(0x8 << 17)
40462306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SM4		(0xd << 17)
40562306a36Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_INITIAL		(0x0 << 21)
40662306a36Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_PRECOMPUTED	(0x1 << 21)
40762306a36Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_XCM		(0x2 << 21)
40862306a36Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_HMAC		(0x3 << 21)
40962306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_MD5		(0x0 << 23)
41062306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_CRC32	(0x0 << 23)
41162306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA1		(0x2 << 23)
41262306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA224	(0x4 << 23)
41362306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA256	(0x3 << 23)
41462306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA384	(0x6 << 23)
41562306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA512	(0x5 << 23)
41662306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_GHASH	(0x4 << 23)
41762306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_XCBC128	(0x1 << 23)
41862306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_XCBC192	(0x2 << 23)
41962306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_XCBC256	(0x3 << 23)
42062306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SM3		(0x7 << 23)
42162306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_256	(0xb << 23)
42262306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_224	(0xc << 23)
42362306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_512	(0xd << 23)
42462306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_SHA3_384	(0xe << 23)
42562306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_ALG_POLY1305	(0xf << 23)
42662306a36Sopenharmony_ci#define CONTEXT_CONTROL_INV_FR			(0x5 << 24)
42762306a36Sopenharmony_ci#define CONTEXT_CONTROL_INV_TR			(0x6 << 24)
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ci/* control1 */
43062306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_ECB		(0 << 0)
43162306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_CBC		(1 << 0)
43262306a36Sopenharmony_ci#define CONTEXT_CONTROL_CHACHA20_MODE_256_32	(2 << 0)
43362306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_OFB		(4 << 0)
43462306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_CFB		(5 << 0)
43562306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_CTR_LOAD	(6 << 0)
43662306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_XTS		(7 << 0)
43762306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_MODE_XCM		((6 << 0) | BIT(17))
43862306a36Sopenharmony_ci#define CONTEXT_CONTROL_CHACHA20_MODE_CALC_OTK	(12 << 0)
43962306a36Sopenharmony_ci#define CONTEXT_CONTROL_IV0			BIT(5)
44062306a36Sopenharmony_ci#define CONTEXT_CONTROL_IV1			BIT(6)
44162306a36Sopenharmony_ci#define CONTEXT_CONTROL_IV2			BIT(7)
44262306a36Sopenharmony_ci#define CONTEXT_CONTROL_IV3			BIT(8)
44362306a36Sopenharmony_ci#define CONTEXT_CONTROL_DIGEST_CNT		BIT(9)
44462306a36Sopenharmony_ci#define CONTEXT_CONTROL_COUNTER_MODE		BIT(10)
44562306a36Sopenharmony_ci#define CONTEXT_CONTROL_CRYPTO_STORE		BIT(12)
44662306a36Sopenharmony_ci#define CONTEXT_CONTROL_HASH_STORE		BIT(19)
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci#define EIP197_XCM_MODE_GCM			1
44962306a36Sopenharmony_ci#define EIP197_XCM_MODE_CCM			2
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci#define EIP197_AEAD_TYPE_IPSEC_ESP		2
45262306a36Sopenharmony_ci#define EIP197_AEAD_TYPE_IPSEC_ESP_GMAC		3
45362306a36Sopenharmony_ci#define EIP197_AEAD_IPSEC_IV_SIZE		8
45462306a36Sopenharmony_ci#define EIP197_AEAD_IPSEC_NONCE_SIZE		4
45562306a36Sopenharmony_ci#define EIP197_AEAD_IPSEC_COUNTER_SIZE		4
45662306a36Sopenharmony_ci#define EIP197_AEAD_IPSEC_CCM_NONCE_SIZE	3
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci/* The hash counter given to the engine in the context has a granularity of
45962306a36Sopenharmony_ci * 64 bits.
46062306a36Sopenharmony_ci */
46162306a36Sopenharmony_ci#define EIP197_COUNTER_BLOCK_SIZE		64
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci/* EIP197_CS_RAM_CTRL */
46462306a36Sopenharmony_ci#define EIP197_TRC_ENABLE_0			BIT(4)
46562306a36Sopenharmony_ci#define EIP197_TRC_ENABLE_1			BIT(5)
46662306a36Sopenharmony_ci#define EIP197_TRC_ENABLE_2			BIT(6)
46762306a36Sopenharmony_ci#define EIP197_TRC_ENABLE_MASK			GENMASK(6, 4)
46862306a36Sopenharmony_ci#define EIP197_CS_BANKSEL_MASK			GENMASK(14, 12)
46962306a36Sopenharmony_ci#define EIP197_CS_BANKSEL_OFS			12
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci/* EIP197_TRC_PARAMS */
47262306a36Sopenharmony_ci#define EIP197_TRC_PARAMS_SW_RESET		BIT(0)
47362306a36Sopenharmony_ci#define EIP197_TRC_PARAMS_DATA_ACCESS		BIT(2)
47462306a36Sopenharmony_ci#define EIP197_TRC_PARAMS_HTABLE_SZ(x)		((x) << 4)
47562306a36Sopenharmony_ci#define EIP197_TRC_PARAMS_BLK_TIMER_SPEED(x)	((x) << 10)
47662306a36Sopenharmony_ci#define EIP197_TRC_PARAMS_RC_SZ_LARGE(n)	((n) << 18)
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci/* EIP197_TRC_FREECHAIN */
47962306a36Sopenharmony_ci#define EIP197_TRC_FREECHAIN_HEAD_PTR(p)	(p)
48062306a36Sopenharmony_ci#define EIP197_TRC_FREECHAIN_TAIL_PTR(p)	((p) << 16)
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci/* EIP197_TRC_PARAMS2 */
48362306a36Sopenharmony_ci#define EIP197_TRC_PARAMS2_HTABLE_PTR(p)	(p)
48462306a36Sopenharmony_ci#define EIP197_TRC_PARAMS2_RC_SZ_SMALL(n)	((n) << 18)
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci/* Cache helpers */
48762306a36Sopenharmony_ci#define EIP197_MIN_DSIZE			1024
48862306a36Sopenharmony_ci#define EIP197_MIN_ASIZE			8
48962306a36Sopenharmony_ci#define EIP197_CS_TRC_REC_WC			64
49062306a36Sopenharmony_ci#define EIP197_CS_RC_SIZE			(4 * sizeof(u32))
49162306a36Sopenharmony_ci#define EIP197_CS_RC_NEXT(x)			(x)
49262306a36Sopenharmony_ci#define EIP197_CS_RC_PREV(x)			((x) << 10)
49362306a36Sopenharmony_ci#define EIP197_RC_NULL				0x3ff
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_ci/* Result data */
49662306a36Sopenharmony_cistruct result_data_desc {
49762306a36Sopenharmony_ci	u32 packet_length:17;
49862306a36Sopenharmony_ci	u32 error_code:15;
49962306a36Sopenharmony_ci
50062306a36Sopenharmony_ci	u32 bypass_length:4;
50162306a36Sopenharmony_ci	u32 e15:1;
50262306a36Sopenharmony_ci	u32 rsvd0:16;
50362306a36Sopenharmony_ci	u32 hash_bytes:1;
50462306a36Sopenharmony_ci	u32 hash_length:6;
50562306a36Sopenharmony_ci	u32 generic_bytes:1;
50662306a36Sopenharmony_ci	u32 checksum:1;
50762306a36Sopenharmony_ci	u32 next_header:1;
50862306a36Sopenharmony_ci	u32 length:1;
50962306a36Sopenharmony_ci
51062306a36Sopenharmony_ci	u16 application_id;
51162306a36Sopenharmony_ci	u16 rsvd1;
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_ci	u32 rsvd2[5];
51462306a36Sopenharmony_ci} __packed;
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ci/* Basic Result Descriptor format */
51862306a36Sopenharmony_cistruct safexcel_result_desc {
51962306a36Sopenharmony_ci	u32 particle_size:17;
52062306a36Sopenharmony_ci	u8 rsvd0:3;
52162306a36Sopenharmony_ci	u8 descriptor_overflow:1;
52262306a36Sopenharmony_ci	u8 buffer_overflow:1;
52362306a36Sopenharmony_ci	u8 last_seg:1;
52462306a36Sopenharmony_ci	u8 first_seg:1;
52562306a36Sopenharmony_ci	u16 result_size:8;
52662306a36Sopenharmony_ci
52762306a36Sopenharmony_ci	u32 rsvd1;
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci	u32 data_lo;
53062306a36Sopenharmony_ci	u32 data_hi;
53162306a36Sopenharmony_ci} __packed;
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ci/*
53462306a36Sopenharmony_ci * The EIP(1)97 only needs to fetch the descriptor part of
53562306a36Sopenharmony_ci * the result descriptor, not the result token part!
53662306a36Sopenharmony_ci */
53762306a36Sopenharmony_ci#define EIP197_RD64_FETCH_SIZE		(sizeof(struct safexcel_result_desc) /\
53862306a36Sopenharmony_ci					 sizeof(u32))
53962306a36Sopenharmony_ci#define EIP197_RD64_RESULT_SIZE		(sizeof(struct result_data_desc) /\
54062306a36Sopenharmony_ci					 sizeof(u32))
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_cistruct safexcel_token {
54362306a36Sopenharmony_ci	u32 packet_length:17;
54462306a36Sopenharmony_ci	u8 stat:2;
54562306a36Sopenharmony_ci	u16 instructions:9;
54662306a36Sopenharmony_ci	u8 opcode:4;
54762306a36Sopenharmony_ci} __packed;
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_ci#define EIP197_TOKEN_HASH_RESULT_VERIFY		BIT(16)
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci#define EIP197_TOKEN_CTX_OFFSET(x)		(x)
55262306a36Sopenharmony_ci#define EIP197_TOKEN_DIRECTION_EXTERNAL		BIT(11)
55362306a36Sopenharmony_ci#define EIP197_TOKEN_EXEC_IF_SUCCESSFUL		(0x1 << 12)
55462306a36Sopenharmony_ci
55562306a36Sopenharmony_ci#define EIP197_TOKEN_STAT_LAST_HASH		BIT(0)
55662306a36Sopenharmony_ci#define EIP197_TOKEN_STAT_LAST_PACKET		BIT(1)
55762306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_DIRECTION		0x0
55862306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_INSERT		0x2
55962306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_NOOP		EIP197_TOKEN_OPCODE_INSERT
56062306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_RETRIEVE		0x4
56162306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_INSERT_REMRES	0xa
56262306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_VERIFY		0xd
56362306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_CTX_ACCESS		0xe
56462306a36Sopenharmony_ci#define EIP197_TOKEN_OPCODE_BYPASS		GENMASK(3, 0)
56562306a36Sopenharmony_ci
56662306a36Sopenharmony_cistatic inline void eip197_noop_token(struct safexcel_token *token)
56762306a36Sopenharmony_ci{
56862306a36Sopenharmony_ci	token->opcode = EIP197_TOKEN_OPCODE_NOOP;
56962306a36Sopenharmony_ci	token->packet_length = BIT(2);
57062306a36Sopenharmony_ci	token->stat = 0;
57162306a36Sopenharmony_ci	token->instructions = 0;
57262306a36Sopenharmony_ci}
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_ci/* Instructions */
57562306a36Sopenharmony_ci#define EIP197_TOKEN_INS_INSERT_HASH_DIGEST	0x1c
57662306a36Sopenharmony_ci#define EIP197_TOKEN_INS_ORIGIN_IV0		0x14
57762306a36Sopenharmony_ci#define EIP197_TOKEN_INS_ORIGIN_TOKEN		0x1b
57862306a36Sopenharmony_ci#define EIP197_TOKEN_INS_ORIGIN_LEN(x)		((x) << 5)
57962306a36Sopenharmony_ci#define EIP197_TOKEN_INS_TYPE_OUTPUT		BIT(5)
58062306a36Sopenharmony_ci#define EIP197_TOKEN_INS_TYPE_HASH		BIT(6)
58162306a36Sopenharmony_ci#define EIP197_TOKEN_INS_TYPE_CRYPTO		BIT(7)
58262306a36Sopenharmony_ci#define EIP197_TOKEN_INS_LAST			BIT(8)
58362306a36Sopenharmony_ci
58462306a36Sopenharmony_ci/* Processing Engine Control Data  */
58562306a36Sopenharmony_cistruct safexcel_control_data_desc {
58662306a36Sopenharmony_ci	u32 packet_length:17;
58762306a36Sopenharmony_ci	u16 options:13;
58862306a36Sopenharmony_ci	u8 type:2;
58962306a36Sopenharmony_ci
59062306a36Sopenharmony_ci	u16 application_id;
59162306a36Sopenharmony_ci	u16 rsvd;
59262306a36Sopenharmony_ci
59362306a36Sopenharmony_ci	u32 context_lo;
59462306a36Sopenharmony_ci	u32 context_hi;
59562306a36Sopenharmony_ci
59662306a36Sopenharmony_ci	u32 control0;
59762306a36Sopenharmony_ci	u32 control1;
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci	u32 token[EIP197_EMB_TOKENS];
60062306a36Sopenharmony_ci} __packed;
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci#define EIP197_OPTION_MAGIC_VALUE	BIT(0)
60362306a36Sopenharmony_ci#define EIP197_OPTION_64BIT_CTX		BIT(1)
60462306a36Sopenharmony_ci#define EIP197_OPTION_RC_AUTO		(0x2 << 3)
60562306a36Sopenharmony_ci#define EIP197_OPTION_CTX_CTRL_IN_CMD	BIT(8)
60662306a36Sopenharmony_ci#define EIP197_OPTION_2_TOKEN_IV_CMD	GENMASK(11, 10)
60762306a36Sopenharmony_ci#define EIP197_OPTION_4_TOKEN_IV_CMD	GENMASK(11, 9)
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ci#define EIP197_TYPE_BCLA		0x0
61062306a36Sopenharmony_ci#define EIP197_TYPE_EXTENDED		0x3
61162306a36Sopenharmony_ci#define EIP197_CONTEXT_SMALL		0x2
61262306a36Sopenharmony_ci#define EIP197_CONTEXT_SIZE_MASK	0x3
61362306a36Sopenharmony_ci
61462306a36Sopenharmony_ci/* Basic Command Descriptor format */
61562306a36Sopenharmony_cistruct safexcel_command_desc {
61662306a36Sopenharmony_ci	u32 particle_size:17;
61762306a36Sopenharmony_ci	u8 rsvd0:5;
61862306a36Sopenharmony_ci	u8 last_seg:1;
61962306a36Sopenharmony_ci	u8 first_seg:1;
62062306a36Sopenharmony_ci	u8 additional_cdata_size:8;
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_ci	u32 rsvd1;
62362306a36Sopenharmony_ci
62462306a36Sopenharmony_ci	u32 data_lo;
62562306a36Sopenharmony_ci	u32 data_hi;
62662306a36Sopenharmony_ci
62762306a36Sopenharmony_ci	u32 atok_lo;
62862306a36Sopenharmony_ci	u32 atok_hi;
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci	struct safexcel_control_data_desc control_data;
63162306a36Sopenharmony_ci} __packed;
63262306a36Sopenharmony_ci
63362306a36Sopenharmony_ci#define EIP197_CD64_FETCH_SIZE		(sizeof(struct safexcel_command_desc) /\
63462306a36Sopenharmony_ci					sizeof(u32))
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_ci/*
63762306a36Sopenharmony_ci * Internal structures & functions
63862306a36Sopenharmony_ci */
63962306a36Sopenharmony_ci
64062306a36Sopenharmony_ci#define EIP197_FW_TERMINAL_NOPS		2
64162306a36Sopenharmony_ci#define EIP197_FW_START_POLLCNT		16
64262306a36Sopenharmony_ci#define EIP197_FW_PUE_READY		0x14
64362306a36Sopenharmony_ci#define EIP197_FW_FPP_READY		0x18
64462306a36Sopenharmony_ci
64562306a36Sopenharmony_cienum eip197_fw {
64662306a36Sopenharmony_ci	FW_IFPP = 0,
64762306a36Sopenharmony_ci	FW_IPUE,
64862306a36Sopenharmony_ci	FW_NB
64962306a36Sopenharmony_ci};
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_cistruct safexcel_desc_ring {
65262306a36Sopenharmony_ci	void *base;
65362306a36Sopenharmony_ci	void *shbase;
65462306a36Sopenharmony_ci	void *base_end;
65562306a36Sopenharmony_ci	void *shbase_end;
65662306a36Sopenharmony_ci	dma_addr_t base_dma;
65762306a36Sopenharmony_ci	dma_addr_t shbase_dma;
65862306a36Sopenharmony_ci
65962306a36Sopenharmony_ci	/* write and read pointers */
66062306a36Sopenharmony_ci	void *write;
66162306a36Sopenharmony_ci	void *shwrite;
66262306a36Sopenharmony_ci	void *read;
66362306a36Sopenharmony_ci
66462306a36Sopenharmony_ci	/* descriptor element offset */
66562306a36Sopenharmony_ci	unsigned int offset;
66662306a36Sopenharmony_ci	unsigned int shoffset;
66762306a36Sopenharmony_ci};
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_cienum safexcel_alg_type {
67062306a36Sopenharmony_ci	SAFEXCEL_ALG_TYPE_SKCIPHER,
67162306a36Sopenharmony_ci	SAFEXCEL_ALG_TYPE_AEAD,
67262306a36Sopenharmony_ci	SAFEXCEL_ALG_TYPE_AHASH,
67362306a36Sopenharmony_ci};
67462306a36Sopenharmony_ci
67562306a36Sopenharmony_cistruct safexcel_config {
67662306a36Sopenharmony_ci	u32 pes;
67762306a36Sopenharmony_ci	u32 rings;
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_ci	u32 cd_size;
68062306a36Sopenharmony_ci	u32 cd_offset;
68162306a36Sopenharmony_ci	u32 cdsh_offset;
68262306a36Sopenharmony_ci
68362306a36Sopenharmony_ci	u32 rd_size;
68462306a36Sopenharmony_ci	u32 rd_offset;
68562306a36Sopenharmony_ci	u32 res_offset;
68662306a36Sopenharmony_ci};
68762306a36Sopenharmony_ci
68862306a36Sopenharmony_cistruct safexcel_work_data {
68962306a36Sopenharmony_ci	struct work_struct work;
69062306a36Sopenharmony_ci	struct safexcel_crypto_priv *priv;
69162306a36Sopenharmony_ci	int ring;
69262306a36Sopenharmony_ci};
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_cistruct safexcel_ring {
69562306a36Sopenharmony_ci	spinlock_t lock;
69662306a36Sopenharmony_ci
69762306a36Sopenharmony_ci	struct workqueue_struct *workqueue;
69862306a36Sopenharmony_ci	struct safexcel_work_data work_data;
69962306a36Sopenharmony_ci
70062306a36Sopenharmony_ci	/* command/result rings */
70162306a36Sopenharmony_ci	struct safexcel_desc_ring cdr;
70262306a36Sopenharmony_ci	struct safexcel_desc_ring rdr;
70362306a36Sopenharmony_ci
70462306a36Sopenharmony_ci	/* result ring crypto API request */
70562306a36Sopenharmony_ci	struct crypto_async_request **rdr_req;
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci	/* queue */
70862306a36Sopenharmony_ci	struct crypto_queue queue;
70962306a36Sopenharmony_ci	spinlock_t queue_lock;
71062306a36Sopenharmony_ci
71162306a36Sopenharmony_ci	/* Number of requests in the engine. */
71262306a36Sopenharmony_ci	int requests;
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_ci	/* The ring is currently handling at least one request */
71562306a36Sopenharmony_ci	bool busy;
71662306a36Sopenharmony_ci
71762306a36Sopenharmony_ci	/* Store for current requests when bailing out of the dequeueing
71862306a36Sopenharmony_ci	 * function when no enough resources are available.
71962306a36Sopenharmony_ci	 */
72062306a36Sopenharmony_ci	struct crypto_async_request *req;
72162306a36Sopenharmony_ci	struct crypto_async_request *backlog;
72262306a36Sopenharmony_ci
72362306a36Sopenharmony_ci	/* irq of this ring */
72462306a36Sopenharmony_ci	int irq;
72562306a36Sopenharmony_ci};
72662306a36Sopenharmony_ci
72762306a36Sopenharmony_ci/* EIP integration context flags */
72862306a36Sopenharmony_cienum safexcel_eip_version {
72962306a36Sopenharmony_ci	/* Platform (EIP integration context) specifier */
73062306a36Sopenharmony_ci	EIP97IES_MRVL,
73162306a36Sopenharmony_ci	EIP197B_MRVL,
73262306a36Sopenharmony_ci	EIP197D_MRVL,
73362306a36Sopenharmony_ci	EIP197_DEVBRD,
73462306a36Sopenharmony_ci	EIP197C_MXL,
73562306a36Sopenharmony_ci};
73662306a36Sopenharmony_ci
73762306a36Sopenharmony_cistruct safexcel_priv_data {
73862306a36Sopenharmony_ci	enum safexcel_eip_version version;
73962306a36Sopenharmony_ci	bool fw_little_endian;
74062306a36Sopenharmony_ci};
74162306a36Sopenharmony_ci
74262306a36Sopenharmony_ci/* Priority we use for advertising our algorithms */
74362306a36Sopenharmony_ci#define SAFEXCEL_CRA_PRIORITY		300
74462306a36Sopenharmony_ci
74562306a36Sopenharmony_ci/* SM3 digest result for zero length message */
74662306a36Sopenharmony_ci#define EIP197_SM3_ZEROM_HASH	"\x1A\xB2\x1D\x83\x55\xCF\xA1\x7F" \
74762306a36Sopenharmony_ci				"\x8E\x61\x19\x48\x31\xE8\x1A\x8F" \
74862306a36Sopenharmony_ci				"\x22\xBE\xC8\xC7\x28\xFE\xFB\x74" \
74962306a36Sopenharmony_ci				"\x7E\xD0\x35\xEB\x50\x82\xAA\x2B"
75062306a36Sopenharmony_ci
75162306a36Sopenharmony_ci/* EIP algorithm presence flags */
75262306a36Sopenharmony_cienum safexcel_eip_algorithms {
75362306a36Sopenharmony_ci	SAFEXCEL_ALG_BC0      = BIT(5),
75462306a36Sopenharmony_ci	SAFEXCEL_ALG_SM4      = BIT(6),
75562306a36Sopenharmony_ci	SAFEXCEL_ALG_SM3      = BIT(7),
75662306a36Sopenharmony_ci	SAFEXCEL_ALG_CHACHA20 = BIT(8),
75762306a36Sopenharmony_ci	SAFEXCEL_ALG_POLY1305 = BIT(9),
75862306a36Sopenharmony_ci	SAFEXCEL_SEQMASK_256   = BIT(10),
75962306a36Sopenharmony_ci	SAFEXCEL_SEQMASK_384   = BIT(11),
76062306a36Sopenharmony_ci	SAFEXCEL_ALG_AES      = BIT(12),
76162306a36Sopenharmony_ci	SAFEXCEL_ALG_AES_XFB  = BIT(13),
76262306a36Sopenharmony_ci	SAFEXCEL_ALG_DES      = BIT(15),
76362306a36Sopenharmony_ci	SAFEXCEL_ALG_DES_XFB  = BIT(16),
76462306a36Sopenharmony_ci	SAFEXCEL_ALG_ARC4     = BIT(18),
76562306a36Sopenharmony_ci	SAFEXCEL_ALG_AES_XTS  = BIT(20),
76662306a36Sopenharmony_ci	SAFEXCEL_ALG_WIRELESS = BIT(21),
76762306a36Sopenharmony_ci	SAFEXCEL_ALG_MD5      = BIT(22),
76862306a36Sopenharmony_ci	SAFEXCEL_ALG_SHA1     = BIT(23),
76962306a36Sopenharmony_ci	SAFEXCEL_ALG_SHA2_256 = BIT(25),
77062306a36Sopenharmony_ci	SAFEXCEL_ALG_SHA2_512 = BIT(26),
77162306a36Sopenharmony_ci	SAFEXCEL_ALG_XCBC_MAC = BIT(27),
77262306a36Sopenharmony_ci	SAFEXCEL_ALG_CBC_MAC_ALL = BIT(29),
77362306a36Sopenharmony_ci	SAFEXCEL_ALG_GHASH    = BIT(30),
77462306a36Sopenharmony_ci	SAFEXCEL_ALG_SHA3     = BIT(31),
77562306a36Sopenharmony_ci};
77662306a36Sopenharmony_ci
77762306a36Sopenharmony_cistruct safexcel_register_offsets {
77862306a36Sopenharmony_ci	u32 hia_aic;
77962306a36Sopenharmony_ci	u32 hia_aic_g;
78062306a36Sopenharmony_ci	u32 hia_aic_r;
78162306a36Sopenharmony_ci	u32 hia_aic_xdr;
78262306a36Sopenharmony_ci	u32 hia_dfe;
78362306a36Sopenharmony_ci	u32 hia_dfe_thr;
78462306a36Sopenharmony_ci	u32 hia_dse;
78562306a36Sopenharmony_ci	u32 hia_dse_thr;
78662306a36Sopenharmony_ci	u32 hia_gen_cfg;
78762306a36Sopenharmony_ci	u32 pe;
78862306a36Sopenharmony_ci	u32 global;
78962306a36Sopenharmony_ci};
79062306a36Sopenharmony_ci
79162306a36Sopenharmony_cienum safexcel_flags {
79262306a36Sopenharmony_ci	EIP197_TRC_CACHE	= BIT(0),
79362306a36Sopenharmony_ci	SAFEXCEL_HW_EIP197	= BIT(1),
79462306a36Sopenharmony_ci	EIP197_PE_ARB		= BIT(2),
79562306a36Sopenharmony_ci	EIP197_ICE		= BIT(3),
79662306a36Sopenharmony_ci	EIP197_SIMPLE_TRC	= BIT(4),
79762306a36Sopenharmony_ci	EIP197_OCE		= BIT(5),
79862306a36Sopenharmony_ci};
79962306a36Sopenharmony_ci
80062306a36Sopenharmony_cistruct safexcel_hwconfig {
80162306a36Sopenharmony_ci	enum safexcel_eip_algorithms algo_flags;
80262306a36Sopenharmony_ci	int hwver;
80362306a36Sopenharmony_ci	int hiaver;
80462306a36Sopenharmony_ci	int ppver;
80562306a36Sopenharmony_ci	int icever;
80662306a36Sopenharmony_ci	int pever;
80762306a36Sopenharmony_ci	int ocever;
80862306a36Sopenharmony_ci	int psever;
80962306a36Sopenharmony_ci	int hwdataw;
81062306a36Sopenharmony_ci	int hwcfsize;
81162306a36Sopenharmony_ci	int hwrfsize;
81262306a36Sopenharmony_ci	int hwnumpes;
81362306a36Sopenharmony_ci	int hwnumrings;
81462306a36Sopenharmony_ci	int hwnumraic;
81562306a36Sopenharmony_ci};
81662306a36Sopenharmony_ci
81762306a36Sopenharmony_cistruct safexcel_crypto_priv {
81862306a36Sopenharmony_ci	void __iomem *base;
81962306a36Sopenharmony_ci	struct device *dev;
82062306a36Sopenharmony_ci	struct clk *clk;
82162306a36Sopenharmony_ci	struct clk *reg_clk;
82262306a36Sopenharmony_ci	struct safexcel_config config;
82362306a36Sopenharmony_ci
82462306a36Sopenharmony_ci	struct safexcel_priv_data *data;
82562306a36Sopenharmony_ci	struct safexcel_register_offsets offsets;
82662306a36Sopenharmony_ci	struct safexcel_hwconfig hwconfig;
82762306a36Sopenharmony_ci	u32 flags;
82862306a36Sopenharmony_ci
82962306a36Sopenharmony_ci	/* context DMA pool */
83062306a36Sopenharmony_ci	struct dma_pool *context_pool;
83162306a36Sopenharmony_ci
83262306a36Sopenharmony_ci	atomic_t ring_used;
83362306a36Sopenharmony_ci
83462306a36Sopenharmony_ci	struct safexcel_ring *ring;
83562306a36Sopenharmony_ci};
83662306a36Sopenharmony_ci
83762306a36Sopenharmony_cistruct safexcel_context {
83862306a36Sopenharmony_ci	int (*send)(struct crypto_async_request *req, int ring,
83962306a36Sopenharmony_ci		    int *commands, int *results);
84062306a36Sopenharmony_ci	int (*handle_result)(struct safexcel_crypto_priv *priv, int ring,
84162306a36Sopenharmony_ci			     struct crypto_async_request *req, bool *complete,
84262306a36Sopenharmony_ci			     int *ret);
84362306a36Sopenharmony_ci	struct safexcel_context_record *ctxr;
84462306a36Sopenharmony_ci	struct safexcel_crypto_priv *priv;
84562306a36Sopenharmony_ci	dma_addr_t ctxr_dma;
84662306a36Sopenharmony_ci
84762306a36Sopenharmony_ci	union {
84862306a36Sopenharmony_ci		__le32 le[SHA3_512_BLOCK_SIZE / 4];
84962306a36Sopenharmony_ci		__be32 be[SHA3_512_BLOCK_SIZE / 4];
85062306a36Sopenharmony_ci		u32 word[SHA3_512_BLOCK_SIZE / 4];
85162306a36Sopenharmony_ci		u8 byte[SHA3_512_BLOCK_SIZE];
85262306a36Sopenharmony_ci	} ipad, opad;
85362306a36Sopenharmony_ci
85462306a36Sopenharmony_ci	int ring;
85562306a36Sopenharmony_ci	bool needs_inv;
85662306a36Sopenharmony_ci	bool exit_inv;
85762306a36Sopenharmony_ci};
85862306a36Sopenharmony_ci
85962306a36Sopenharmony_ci#define HASH_CACHE_SIZE			SHA512_BLOCK_SIZE
86062306a36Sopenharmony_ci
86162306a36Sopenharmony_cistruct safexcel_ahash_export_state {
86262306a36Sopenharmony_ci	u64 len;
86362306a36Sopenharmony_ci	u64 processed;
86462306a36Sopenharmony_ci
86562306a36Sopenharmony_ci	u32 digest;
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_ci	u32 state[SHA512_DIGEST_SIZE / sizeof(u32)];
86862306a36Sopenharmony_ci	u8 cache[HASH_CACHE_SIZE];
86962306a36Sopenharmony_ci};
87062306a36Sopenharmony_ci
87162306a36Sopenharmony_ci/*
87262306a36Sopenharmony_ci * Template structure to describe the algorithms in order to register them.
87362306a36Sopenharmony_ci * It also has the purpose to contain our private structure and is actually
87462306a36Sopenharmony_ci * the only way I know in this framework to avoid having global pointers...
87562306a36Sopenharmony_ci */
87662306a36Sopenharmony_cistruct safexcel_alg_template {
87762306a36Sopenharmony_ci	struct safexcel_crypto_priv *priv;
87862306a36Sopenharmony_ci	enum safexcel_alg_type type;
87962306a36Sopenharmony_ci	enum safexcel_eip_algorithms algo_mask;
88062306a36Sopenharmony_ci	union {
88162306a36Sopenharmony_ci		struct skcipher_alg skcipher;
88262306a36Sopenharmony_ci		struct aead_alg aead;
88362306a36Sopenharmony_ci		struct ahash_alg ahash;
88462306a36Sopenharmony_ci	} alg;
88562306a36Sopenharmony_ci};
88662306a36Sopenharmony_ci
88762306a36Sopenharmony_civoid safexcel_dequeue(struct safexcel_crypto_priv *priv, int ring);
88862306a36Sopenharmony_ciint safexcel_rdesc_check_errors(struct safexcel_crypto_priv *priv,
88962306a36Sopenharmony_ci				void *rdp);
89062306a36Sopenharmony_civoid safexcel_complete(struct safexcel_crypto_priv *priv, int ring);
89162306a36Sopenharmony_ciint safexcel_invalidate_cache(struct crypto_async_request *async,
89262306a36Sopenharmony_ci			      struct safexcel_crypto_priv *priv,
89362306a36Sopenharmony_ci			      dma_addr_t ctxr_dma, int ring);
89462306a36Sopenharmony_ciint safexcel_init_ring_descriptors(struct safexcel_crypto_priv *priv,
89562306a36Sopenharmony_ci				   struct safexcel_desc_ring *cdr,
89662306a36Sopenharmony_ci				   struct safexcel_desc_ring *rdr);
89762306a36Sopenharmony_ciint safexcel_select_ring(struct safexcel_crypto_priv *priv);
89862306a36Sopenharmony_civoid *safexcel_ring_next_rptr(struct safexcel_crypto_priv *priv,
89962306a36Sopenharmony_ci			      struct safexcel_desc_ring *ring);
90062306a36Sopenharmony_civoid *safexcel_ring_first_rptr(struct safexcel_crypto_priv *priv, int  ring);
90162306a36Sopenharmony_civoid safexcel_ring_rollback_wptr(struct safexcel_crypto_priv *priv,
90262306a36Sopenharmony_ci				 struct safexcel_desc_ring *ring);
90362306a36Sopenharmony_cistruct safexcel_command_desc *safexcel_add_cdesc(struct safexcel_crypto_priv *priv,
90462306a36Sopenharmony_ci						 int ring_id,
90562306a36Sopenharmony_ci						 bool first, bool last,
90662306a36Sopenharmony_ci						 dma_addr_t data, u32 len,
90762306a36Sopenharmony_ci						 u32 full_data_len,
90862306a36Sopenharmony_ci						 dma_addr_t context,
90962306a36Sopenharmony_ci						 struct safexcel_token **atoken);
91062306a36Sopenharmony_cistruct safexcel_result_desc *safexcel_add_rdesc(struct safexcel_crypto_priv *priv,
91162306a36Sopenharmony_ci						 int ring_id,
91262306a36Sopenharmony_ci						bool first, bool last,
91362306a36Sopenharmony_ci						dma_addr_t data, u32 len);
91462306a36Sopenharmony_ciint safexcel_ring_first_rdr_index(struct safexcel_crypto_priv *priv,
91562306a36Sopenharmony_ci				  int ring);
91662306a36Sopenharmony_ciint safexcel_ring_rdr_rdesc_index(struct safexcel_crypto_priv *priv,
91762306a36Sopenharmony_ci				  int ring,
91862306a36Sopenharmony_ci				  struct safexcel_result_desc *rdesc);
91962306a36Sopenharmony_civoid safexcel_rdr_req_set(struct safexcel_crypto_priv *priv,
92062306a36Sopenharmony_ci			  int ring,
92162306a36Sopenharmony_ci			  struct safexcel_result_desc *rdesc,
92262306a36Sopenharmony_ci			  struct crypto_async_request *req);
92362306a36Sopenharmony_ciinline struct crypto_async_request *
92462306a36Sopenharmony_cisafexcel_rdr_req_get(struct safexcel_crypto_priv *priv, int ring);
92562306a36Sopenharmony_ciint safexcel_hmac_setkey(struct safexcel_context *base, const u8 *key,
92662306a36Sopenharmony_ci			 unsigned int keylen, const char *alg,
92762306a36Sopenharmony_ci			 unsigned int state_sz);
92862306a36Sopenharmony_ci
92962306a36Sopenharmony_ci/* available algorithms */
93062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_des;
93162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_des;
93262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_des3_ede;
93362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_des3_ede;
93462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_aes;
93562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_aes;
93662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cfb_aes;
93762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ofb_aes;
93862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ctr_aes;
93962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_md5;
94062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha1;
94162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha224;
94262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha256;
94362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha384;
94462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha512;
94562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_md5;
94662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha1;
94762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha224;
94862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha256;
94962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha384;
95062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha512;
95162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_aes;
95262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_aes;
95362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_aes;
95462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_aes;
95562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_aes;
95662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_des3_ede;
95762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_ctr_aes;
95862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_ctr_aes;
95962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_ctr_aes;
96062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_ctr_aes;
96162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_ctr_aes;
96262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_xts_aes;
96362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_gcm;
96462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ccm;
96562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_crc32;
96662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbcmac;
96762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_xcbcmac;
96862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cmac;
96962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_chacha20;
97062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_chachapoly;
97162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_chachapoly_esp;
97262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sm3;
97362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sm3;
97462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ecb_sm4;
97562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cbc_sm4;
97662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ofb_sm4;
97762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_cfb_sm4;
97862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_ctr_sm4;
97962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_sm4;
98062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sm3_cbc_sm4;
98162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_ctr_sm4;
98262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sm3_ctr_sm4;
98362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_224;
98462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_256;
98562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_384;
98662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_sha3_512;
98762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_224;
98862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_256;
98962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_384;
99062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_hmac_sha3_512;
99162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha1_cbc_des;
99262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_des3_ede;
99362306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_des3_ede;
99462306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_des3_ede;
99562306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_des3_ede;
99662306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha256_cbc_des;
99762306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha224_cbc_des;
99862306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha512_cbc_des;
99962306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_authenc_hmac_sha384_cbc_des;
100062306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_rfc4106_gcm;
100162306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_rfc4543_gcm;
100262306a36Sopenharmony_ciextern struct safexcel_alg_template safexcel_alg_rfc4309_ccm;
100362306a36Sopenharmony_ci
100462306a36Sopenharmony_ci#endif
1005