18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * AMCC SoC PPC4xx Crypto Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2008 Applied Micro Circuits Corporation.
68c2ecf20Sopenharmony_ci * All rights reserved. James Hsiao <jhsiao@amcc.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This filr defines the register set for Security Subsystem
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __CRYPTO4XX_REG_DEF_H__
128c2ecf20Sopenharmony_ci#define __CRYPTO4XX_REG_DEF_H__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* CRYPTO4XX Register offset */
158c2ecf20Sopenharmony_ci#define CRYPTO4XX_DESCRIPTOR			0x00000000
168c2ecf20Sopenharmony_ci#define CRYPTO4XX_CTRL_STAT			0x00000000
178c2ecf20Sopenharmony_ci#define CRYPTO4XX_SOURCE			0x00000004
188c2ecf20Sopenharmony_ci#define CRYPTO4XX_DEST				0x00000008
198c2ecf20Sopenharmony_ci#define CRYPTO4XX_SA				0x0000000C
208c2ecf20Sopenharmony_ci#define CRYPTO4XX_SA_LENGTH			0x00000010
218c2ecf20Sopenharmony_ci#define CRYPTO4XX_LENGTH			0x00000014
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define CRYPTO4XX_PE_DMA_CFG			0x00000040
248c2ecf20Sopenharmony_ci#define CRYPTO4XX_PE_DMA_STAT			0x00000044
258c2ecf20Sopenharmony_ci#define CRYPTO4XX_PDR_BASE			0x00000048
268c2ecf20Sopenharmony_ci#define CRYPTO4XX_RDR_BASE			0x0000004c
278c2ecf20Sopenharmony_ci#define CRYPTO4XX_RING_SIZE			0x00000050
288c2ecf20Sopenharmony_ci#define CRYPTO4XX_RING_CTRL			0x00000054
298c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_RING_STAT			0x00000058
308c2ecf20Sopenharmony_ci#define CRYPTO4XX_EXT_RING_STAT			0x0000005c
318c2ecf20Sopenharmony_ci#define CRYPTO4XX_IO_THRESHOLD			0x00000060
328c2ecf20Sopenharmony_ci#define CRYPTO4XX_GATH_RING_BASE		0x00000064
338c2ecf20Sopenharmony_ci#define CRYPTO4XX_SCAT_RING_BASE		0x00000068
348c2ecf20Sopenharmony_ci#define CRYPTO4XX_PART_RING_SIZE		0x0000006c
358c2ecf20Sopenharmony_ci#define CRYPTO4XX_PART_RING_CFG		        0x00000070
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define CRYPTO4XX_PDR_BASE_UADDR		0x00000080
388c2ecf20Sopenharmony_ci#define CRYPTO4XX_RDR_BASE_UADDR		0x00000084
398c2ecf20Sopenharmony_ci#define CRYPTO4XX_PKT_SRC_UADDR			0x00000088
408c2ecf20Sopenharmony_ci#define CRYPTO4XX_PKT_DEST_UADDR		0x0000008c
418c2ecf20Sopenharmony_ci#define CRYPTO4XX_SA_UADDR			0x00000090
428c2ecf20Sopenharmony_ci#define CRYPTO4XX_GATH_RING_BASE_UADDR		0x000000A0
438c2ecf20Sopenharmony_ci#define CRYPTO4XX_SCAT_RING_BASE_UADDR		0x000000A4
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define CRYPTO4XX_SEQ_RD			0x00000408
468c2ecf20Sopenharmony_ci#define CRYPTO4XX_SEQ_MASK_RD			0x0000040C
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define CRYPTO4XX_SA_CMD_0			0x00010600
498c2ecf20Sopenharmony_ci#define CRYPTO4XX_SA_CMD_1			0x00010604
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define CRYPTO4XX_STATE_PTR			0x000106dc
528c2ecf20Sopenharmony_ci#define CRYPTO4XX_STATE_IV			0x00010700
538c2ecf20Sopenharmony_ci#define CRYPTO4XX_STATE_HASH_BYTE_CNT_0		0x00010710
548c2ecf20Sopenharmony_ci#define CRYPTO4XX_STATE_HASH_BYTE_CNT_1		0x00010714
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define CRYPTO4XX_STATE_IDIGEST_0		0x00010718
578c2ecf20Sopenharmony_ci#define CRYPTO4XX_STATE_IDIGEST_1		0x0001071c
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define CRYPTO4XX_DATA_IN			0x00018000
608c2ecf20Sopenharmony_ci#define CRYPTO4XX_DATA_OUT			0x0001c000
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_UNMASK_STAT		0x000500a0
638c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_MASK_STAT			0x000500a4
648c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_CLR			0x000500a4
658c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_EN			0x000500a8
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_PKA			0x00000002
688c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_PDR_DONE			0x00008000
698c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_MA_WR_ERR			0x00020000
708c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_MA_RD_ERR			0x00010000
718c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_PE_ERR			0x00000200
728c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_USER_DMA_ERR		0x00000040
738c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_SLAVE_ERR			0x00000010
748c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_MASTER_ERR		0x00000008
758c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_ERROR			0x00030258
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_CFG			0x000500ac
788c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_DESCR_RD			0x000500b0
798c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_DESCR_CNT			0x000500b4
808c2ecf20Sopenharmony_ci#define CRYPTO4XX_INT_TIMEOUT_CNT		0x000500b8
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define CRYPTO4XX_DEVICE_CTRL			0x00060080
838c2ecf20Sopenharmony_ci#define CRYPTO4XX_DEVICE_ID			0x00060084
848c2ecf20Sopenharmony_ci#define CRYPTO4XX_DEVICE_INFO			0x00060088
858c2ecf20Sopenharmony_ci#define CRYPTO4XX_DMA_USER_SRC			0x00060094
868c2ecf20Sopenharmony_ci#define CRYPTO4XX_DMA_USER_DEST			0x00060098
878c2ecf20Sopenharmony_ci#define CRYPTO4XX_DMA_USER_CMD			0x0006009C
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define CRYPTO4XX_DMA_CFG	        	0x000600d4
908c2ecf20Sopenharmony_ci#define CRYPTO4XX_BYTE_ORDER_CFG 		0x000600d8
918c2ecf20Sopenharmony_ci#define CRYPTO4XX_ENDIAN_CFG			0x000600d8
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_STAT			0x00070000
948c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_STAT_BUSY		0x1
958c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_CTRL			0x00070004
968c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_SEED_L			0x00070008
978c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_SEED_H			0x0007000c
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_RES_0			0x00070020
1008c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_RES_1			0x00070024
1018c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_RES_2			0x00070028
1028c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_RES_3			0x0007002C
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_LFSR_L			0x00070030
1058c2ecf20Sopenharmony_ci#define CRYPTO4XX_PRNG_LFSR_H			0x00070034
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/**
1088c2ecf20Sopenharmony_ci * Initialize CRYPTO ENGINE registers, and memory bases.
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_ci#define PPC4XX_PDR_POLL				0x3ff
1118c2ecf20Sopenharmony_ci#define PPC4XX_OUTPUT_THRESHOLD			2
1128c2ecf20Sopenharmony_ci#define PPC4XX_INPUT_THRESHOLD			2
1138c2ecf20Sopenharmony_ci#define PPC4XX_PD_SIZE				6
1148c2ecf20Sopenharmony_ci#define PPC4XX_CTX_DONE_INT			0x2000
1158c2ecf20Sopenharmony_ci#define PPC4XX_PD_DONE_INT			0x8000
1168c2ecf20Sopenharmony_ci#define PPC4XX_TMO_ERR_INT			0x40000
1178c2ecf20Sopenharmony_ci#define PPC4XX_BYTE_ORDER			0x22222
1188c2ecf20Sopenharmony_ci#define PPC4XX_INTERRUPT_CLR			0x3ffff
1198c2ecf20Sopenharmony_ci#define PPC4XX_PRNG_CTRL_AUTO_EN		0x3
1208c2ecf20Sopenharmony_ci#define PPC4XX_DC_3DES_EN			1
1218c2ecf20Sopenharmony_ci#define PPC4XX_TRNG_EN				0x00020000
1228c2ecf20Sopenharmony_ci#define PPC4XX_INT_DESCR_CNT			7
1238c2ecf20Sopenharmony_ci#define PPC4XX_INT_TIMEOUT_CNT			0
1248c2ecf20Sopenharmony_ci#define PPC4XX_INT_TIMEOUT_CNT_REVB		0x3FF
1258c2ecf20Sopenharmony_ci#define PPC4XX_INT_CFG				1
1268c2ecf20Sopenharmony_ci/**
1278c2ecf20Sopenharmony_ci * all follow define are ad hoc
1288c2ecf20Sopenharmony_ci */
1298c2ecf20Sopenharmony_ci#define PPC4XX_RING_RETRY			100
1308c2ecf20Sopenharmony_ci#define PPC4XX_RING_POLL			100
1318c2ecf20Sopenharmony_ci#define PPC4XX_SDR_SIZE				PPC4XX_NUM_SD
1328c2ecf20Sopenharmony_ci#define PPC4XX_GDR_SIZE				PPC4XX_NUM_GD
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/**
1358c2ecf20Sopenharmony_ci  * Generic Security Association (SA) with all possible fields. These will
1368c2ecf20Sopenharmony_ci * never likely used except for reference purpose. These structure format
1378c2ecf20Sopenharmony_ci * can be not changed as the hardware expects them to be layout as defined.
1388c2ecf20Sopenharmony_ci * Field can be removed or reduced but ordering can not be changed.
1398c2ecf20Sopenharmony_ci */
1408c2ecf20Sopenharmony_ci#define CRYPTO4XX_DMA_CFG_OFFSET		0x40
1418c2ecf20Sopenharmony_ciunion ce_pe_dma_cfg {
1428c2ecf20Sopenharmony_ci	struct {
1438c2ecf20Sopenharmony_ci		u32 rsv:7;
1448c2ecf20Sopenharmony_ci		u32 dir_host:1;
1458c2ecf20Sopenharmony_ci		u32 rsv1:2;
1468c2ecf20Sopenharmony_ci		u32 bo_td_en:1;
1478c2ecf20Sopenharmony_ci		u32 dis_pdr_upd:1;
1488c2ecf20Sopenharmony_ci		u32 bo_sgpd_en:1;
1498c2ecf20Sopenharmony_ci		u32 bo_data_en:1;
1508c2ecf20Sopenharmony_ci		u32 bo_sa_en:1;
1518c2ecf20Sopenharmony_ci		u32 bo_pd_en:1;
1528c2ecf20Sopenharmony_ci		u32 rsv2:4;
1538c2ecf20Sopenharmony_ci		u32 dynamic_sa_en:1;
1548c2ecf20Sopenharmony_ci		u32 pdr_mode:2;
1558c2ecf20Sopenharmony_ci		u32 pe_mode:1;
1568c2ecf20Sopenharmony_ci		u32 rsv3:5;
1578c2ecf20Sopenharmony_ci		u32 reset_sg:1;
1588c2ecf20Sopenharmony_ci		u32 reset_pdr:1;
1598c2ecf20Sopenharmony_ci		u32 reset_pe:1;
1608c2ecf20Sopenharmony_ci	} bf;
1618c2ecf20Sopenharmony_ci    u32 w;
1628c2ecf20Sopenharmony_ci} __attribute__((packed));
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define CRYPTO4XX_PDR_BASE_OFFSET		0x48
1658c2ecf20Sopenharmony_ci#define CRYPTO4XX_RDR_BASE_OFFSET		0x4c
1668c2ecf20Sopenharmony_ci#define CRYPTO4XX_RING_SIZE_OFFSET		0x50
1678c2ecf20Sopenharmony_ciunion ce_ring_size {
1688c2ecf20Sopenharmony_ci	struct {
1698c2ecf20Sopenharmony_ci		u32 ring_offset:16;
1708c2ecf20Sopenharmony_ci		u32 rsv:6;
1718c2ecf20Sopenharmony_ci		u32 ring_size:10;
1728c2ecf20Sopenharmony_ci	} bf;
1738c2ecf20Sopenharmony_ci    u32 w;
1748c2ecf20Sopenharmony_ci} __attribute__((packed));
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define CRYPTO4XX_RING_CONTROL_OFFSET		0x54
1778c2ecf20Sopenharmony_ciunion ce_ring_control {
1788c2ecf20Sopenharmony_ci	struct {
1798c2ecf20Sopenharmony_ci		u32 continuous:1;
1808c2ecf20Sopenharmony_ci		u32 rsv:5;
1818c2ecf20Sopenharmony_ci		u32 ring_retry_divisor:10;
1828c2ecf20Sopenharmony_ci		u32 rsv1:4;
1838c2ecf20Sopenharmony_ci		u32 ring_poll_divisor:10;
1848c2ecf20Sopenharmony_ci	} bf;
1858c2ecf20Sopenharmony_ci    u32 w;
1868c2ecf20Sopenharmony_ci} __attribute__((packed));
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define CRYPTO4XX_IO_THRESHOLD_OFFSET		0x60
1898c2ecf20Sopenharmony_ciunion ce_io_threshold {
1908c2ecf20Sopenharmony_ci	struct {
1918c2ecf20Sopenharmony_ci		u32 rsv:6;
1928c2ecf20Sopenharmony_ci		u32 output_threshold:10;
1938c2ecf20Sopenharmony_ci		u32 rsv1:6;
1948c2ecf20Sopenharmony_ci		u32 input_threshold:10;
1958c2ecf20Sopenharmony_ci	} bf;
1968c2ecf20Sopenharmony_ci    u32 w;
1978c2ecf20Sopenharmony_ci} __attribute__((packed));
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci#define CRYPTO4XX_GATHER_RING_BASE_OFFSET	0x64
2008c2ecf20Sopenharmony_ci#define CRYPTO4XX_SCATTER_RING_BASE_OFFSET	0x68
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ciunion ce_part_ring_size  {
2038c2ecf20Sopenharmony_ci	struct {
2048c2ecf20Sopenharmony_ci		u32 sdr_size:16;
2058c2ecf20Sopenharmony_ci		u32 gdr_size:16;
2068c2ecf20Sopenharmony_ci	} bf;
2078c2ecf20Sopenharmony_ci    u32 w;
2088c2ecf20Sopenharmony_ci} __attribute__((packed));
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#define MAX_BURST_SIZE_32			0
2118c2ecf20Sopenharmony_ci#define MAX_BURST_SIZE_64			1
2128c2ecf20Sopenharmony_ci#define MAX_BURST_SIZE_128			2
2138c2ecf20Sopenharmony_ci#define MAX_BURST_SIZE_256			3
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/* gather descriptor control length */
2168c2ecf20Sopenharmony_cistruct gd_ctl_len {
2178c2ecf20Sopenharmony_ci	u32 len:16;
2188c2ecf20Sopenharmony_ci	u32 rsv:14;
2198c2ecf20Sopenharmony_ci	u32 done:1;
2208c2ecf20Sopenharmony_ci	u32 ready:1;
2218c2ecf20Sopenharmony_ci} __attribute__((packed));
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cistruct ce_gd {
2248c2ecf20Sopenharmony_ci	u32 ptr;
2258c2ecf20Sopenharmony_ci	struct gd_ctl_len ctl_len;
2268c2ecf20Sopenharmony_ci} __attribute__((packed));
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistruct sd_ctl {
2298c2ecf20Sopenharmony_ci	u32 ctl:30;
2308c2ecf20Sopenharmony_ci	u32 done:1;
2318c2ecf20Sopenharmony_ci	u32 rdy:1;
2328c2ecf20Sopenharmony_ci} __attribute__((packed));
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistruct ce_sd {
2358c2ecf20Sopenharmony_ci    u32 ptr;
2368c2ecf20Sopenharmony_ci	struct sd_ctl ctl;
2378c2ecf20Sopenharmony_ci} __attribute__((packed));
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci#define PD_PAD_CTL_32	0x10
2408c2ecf20Sopenharmony_ci#define PD_PAD_CTL_64	0x20
2418c2ecf20Sopenharmony_ci#define PD_PAD_CTL_128	0x40
2428c2ecf20Sopenharmony_ci#define PD_PAD_CTL_256	0x80
2438c2ecf20Sopenharmony_ciunion ce_pd_ctl {
2448c2ecf20Sopenharmony_ci	struct {
2458c2ecf20Sopenharmony_ci		u32 pd_pad_ctl:8;
2468c2ecf20Sopenharmony_ci		u32 status:8;
2478c2ecf20Sopenharmony_ci		u32 next_hdr:8;
2488c2ecf20Sopenharmony_ci		u32 rsv:2;
2498c2ecf20Sopenharmony_ci		u32 cached_sa:1;
2508c2ecf20Sopenharmony_ci		u32 hash_final:1;
2518c2ecf20Sopenharmony_ci		u32 init_arc4:1;
2528c2ecf20Sopenharmony_ci		u32 rsv1:1;
2538c2ecf20Sopenharmony_ci		u32 pe_done:1;
2548c2ecf20Sopenharmony_ci		u32 host_ready:1;
2558c2ecf20Sopenharmony_ci	} bf;
2568c2ecf20Sopenharmony_ci	u32 w;
2578c2ecf20Sopenharmony_ci} __attribute__((packed));
2588c2ecf20Sopenharmony_ci#define PD_CTL_HASH_FINAL	BIT(4)
2598c2ecf20Sopenharmony_ci#define PD_CTL_PE_DONE		BIT(1)
2608c2ecf20Sopenharmony_ci#define PD_CTL_HOST_READY	BIT(0)
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ciunion ce_pd_ctl_len {
2638c2ecf20Sopenharmony_ci	struct {
2648c2ecf20Sopenharmony_ci		u32 bypass:8;
2658c2ecf20Sopenharmony_ci		u32 pe_done:1;
2668c2ecf20Sopenharmony_ci		u32 host_ready:1;
2678c2ecf20Sopenharmony_ci		u32 rsv:2;
2688c2ecf20Sopenharmony_ci		u32 pkt_len:20;
2698c2ecf20Sopenharmony_ci	} bf;
2708c2ecf20Sopenharmony_ci	u32 w;
2718c2ecf20Sopenharmony_ci} __attribute__((packed));
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_cistruct ce_pd {
2748c2ecf20Sopenharmony_ci	union ce_pd_ctl   pd_ctl;
2758c2ecf20Sopenharmony_ci	u32 src;
2768c2ecf20Sopenharmony_ci	u32 dest;
2778c2ecf20Sopenharmony_ci	u32 sa;                 /* get from ctx->sa_dma_addr */
2788c2ecf20Sopenharmony_ci	u32 sa_len;             /* only if dynamic sa is used */
2798c2ecf20Sopenharmony_ci	union ce_pd_ctl_len pd_ctl_len;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci} __attribute__((packed));
2828c2ecf20Sopenharmony_ci#endif
283