Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * AMCC SoC PPC4xx Crypto Driver
0004  *
0005  * Copyright (c) 2008 Applied Micro Circuits Corporation.
0006  * All rights reserved. James Hsiao <jhsiao@amcc.com>
0007  *
0008  * This filr defines the register set for Security Subsystem
0009  */
0010 
0011 #ifndef __CRYPTO4XX_REG_DEF_H__
0012 #define __CRYPTO4XX_REG_DEF_H__
0013 
0014 /* CRYPTO4XX Register offset */
0015 #define CRYPTO4XX_DESCRIPTOR            0x00000000
0016 #define CRYPTO4XX_CTRL_STAT         0x00000000
0017 #define CRYPTO4XX_SOURCE            0x00000004
0018 #define CRYPTO4XX_DEST              0x00000008
0019 #define CRYPTO4XX_SA                0x0000000C
0020 #define CRYPTO4XX_SA_LENGTH         0x00000010
0021 #define CRYPTO4XX_LENGTH            0x00000014
0022 
0023 #define CRYPTO4XX_PE_DMA_CFG            0x00000040
0024 #define CRYPTO4XX_PE_DMA_STAT           0x00000044
0025 #define CRYPTO4XX_PDR_BASE          0x00000048
0026 #define CRYPTO4XX_RDR_BASE          0x0000004c
0027 #define CRYPTO4XX_RING_SIZE         0x00000050
0028 #define CRYPTO4XX_RING_CTRL         0x00000054
0029 #define CRYPTO4XX_INT_RING_STAT         0x00000058
0030 #define CRYPTO4XX_EXT_RING_STAT         0x0000005c
0031 #define CRYPTO4XX_IO_THRESHOLD          0x00000060
0032 #define CRYPTO4XX_GATH_RING_BASE        0x00000064
0033 #define CRYPTO4XX_SCAT_RING_BASE        0x00000068
0034 #define CRYPTO4XX_PART_RING_SIZE        0x0000006c
0035 #define CRYPTO4XX_PART_RING_CFG             0x00000070
0036 
0037 #define CRYPTO4XX_PDR_BASE_UADDR        0x00000080
0038 #define CRYPTO4XX_RDR_BASE_UADDR        0x00000084
0039 #define CRYPTO4XX_PKT_SRC_UADDR         0x00000088
0040 #define CRYPTO4XX_PKT_DEST_UADDR        0x0000008c
0041 #define CRYPTO4XX_SA_UADDR          0x00000090
0042 #define CRYPTO4XX_GATH_RING_BASE_UADDR      0x000000A0
0043 #define CRYPTO4XX_SCAT_RING_BASE_UADDR      0x000000A4
0044 
0045 #define CRYPTO4XX_SEQ_RD            0x00000408
0046 #define CRYPTO4XX_SEQ_MASK_RD           0x0000040C
0047 
0048 #define CRYPTO4XX_SA_CMD_0          0x00010600
0049 #define CRYPTO4XX_SA_CMD_1          0x00010604
0050 
0051 #define CRYPTO4XX_STATE_PTR         0x000106dc
0052 #define CRYPTO4XX_STATE_IV          0x00010700
0053 #define CRYPTO4XX_STATE_HASH_BYTE_CNT_0     0x00010710
0054 #define CRYPTO4XX_STATE_HASH_BYTE_CNT_1     0x00010714
0055 
0056 #define CRYPTO4XX_STATE_IDIGEST_0       0x00010718
0057 #define CRYPTO4XX_STATE_IDIGEST_1       0x0001071c
0058 
0059 #define CRYPTO4XX_DATA_IN           0x00018000
0060 #define CRYPTO4XX_DATA_OUT          0x0001c000
0061 
0062 #define CRYPTO4XX_INT_UNMASK_STAT       0x000500a0
0063 #define CRYPTO4XX_INT_MASK_STAT         0x000500a4
0064 #define CRYPTO4XX_INT_CLR           0x000500a4
0065 #define CRYPTO4XX_INT_EN            0x000500a8
0066 
0067 #define CRYPTO4XX_INT_PKA           0x00000002
0068 #define CRYPTO4XX_INT_PDR_DONE          0x00008000
0069 #define CRYPTO4XX_INT_MA_WR_ERR         0x00020000
0070 #define CRYPTO4XX_INT_MA_RD_ERR         0x00010000
0071 #define CRYPTO4XX_INT_PE_ERR            0x00000200
0072 #define CRYPTO4XX_INT_USER_DMA_ERR      0x00000040
0073 #define CRYPTO4XX_INT_SLAVE_ERR         0x00000010
0074 #define CRYPTO4XX_INT_MASTER_ERR        0x00000008
0075 #define CRYPTO4XX_INT_ERROR         0x00030258
0076 
0077 #define CRYPTO4XX_INT_CFG           0x000500ac
0078 #define CRYPTO4XX_INT_DESCR_RD          0x000500b0
0079 #define CRYPTO4XX_INT_DESCR_CNT         0x000500b4
0080 #define CRYPTO4XX_INT_TIMEOUT_CNT       0x000500b8
0081 
0082 #define CRYPTO4XX_DEVICE_CTRL           0x00060080
0083 #define CRYPTO4XX_DEVICE_ID         0x00060084
0084 #define CRYPTO4XX_DEVICE_INFO           0x00060088
0085 #define CRYPTO4XX_DMA_USER_SRC          0x00060094
0086 #define CRYPTO4XX_DMA_USER_DEST         0x00060098
0087 #define CRYPTO4XX_DMA_USER_CMD          0x0006009C
0088 
0089 #define CRYPTO4XX_DMA_CFG               0x000600d4
0090 #define CRYPTO4XX_BYTE_ORDER_CFG        0x000600d8
0091 #define CRYPTO4XX_ENDIAN_CFG            0x000600d8
0092 
0093 #define CRYPTO4XX_PRNG_STAT         0x00070000
0094 #define CRYPTO4XX_PRNG_STAT_BUSY        0x1
0095 #define CRYPTO4XX_PRNG_CTRL         0x00070004
0096 #define CRYPTO4XX_PRNG_SEED_L           0x00070008
0097 #define CRYPTO4XX_PRNG_SEED_H           0x0007000c
0098 
0099 #define CRYPTO4XX_PRNG_RES_0            0x00070020
0100 #define CRYPTO4XX_PRNG_RES_1            0x00070024
0101 #define CRYPTO4XX_PRNG_RES_2            0x00070028
0102 #define CRYPTO4XX_PRNG_RES_3            0x0007002C
0103 
0104 #define CRYPTO4XX_PRNG_LFSR_L           0x00070030
0105 #define CRYPTO4XX_PRNG_LFSR_H           0x00070034
0106 
0107 /*
0108  * Initialize CRYPTO ENGINE registers, and memory bases.
0109  */
0110 #define PPC4XX_PDR_POLL             0x3ff
0111 #define PPC4XX_OUTPUT_THRESHOLD         2
0112 #define PPC4XX_INPUT_THRESHOLD          2
0113 #define PPC4XX_PD_SIZE              6
0114 #define PPC4XX_CTX_DONE_INT         0x2000
0115 #define PPC4XX_PD_DONE_INT          0x8000
0116 #define PPC4XX_TMO_ERR_INT          0x40000
0117 #define PPC4XX_BYTE_ORDER           0x22222
0118 #define PPC4XX_INTERRUPT_CLR            0x3ffff
0119 #define PPC4XX_PRNG_CTRL_AUTO_EN        0x3
0120 #define PPC4XX_DC_3DES_EN           1
0121 #define PPC4XX_TRNG_EN              0x00020000
0122 #define PPC4XX_INT_DESCR_CNT            7
0123 #define PPC4XX_INT_TIMEOUT_CNT          0
0124 #define PPC4XX_INT_TIMEOUT_CNT_REVB     0x3FF
0125 #define PPC4XX_INT_CFG              1
0126 /*
0127  * all follow define are ad hoc
0128  */
0129 #define PPC4XX_RING_RETRY           100
0130 #define PPC4XX_RING_POLL            100
0131 #define PPC4XX_SDR_SIZE             PPC4XX_NUM_SD
0132 #define PPC4XX_GDR_SIZE             PPC4XX_NUM_GD
0133 
0134 /*
0135   * Generic Security Association (SA) with all possible fields. These will
0136  * never likely used except for reference purpose. These structure format
0137  * can be not changed as the hardware expects them to be layout as defined.
0138  * Field can be removed or reduced but ordering can not be changed.
0139  */
0140 #define CRYPTO4XX_DMA_CFG_OFFSET        0x40
0141 union ce_pe_dma_cfg {
0142     struct {
0143         u32 rsv:7;
0144         u32 dir_host:1;
0145         u32 rsv1:2;
0146         u32 bo_td_en:1;
0147         u32 dis_pdr_upd:1;
0148         u32 bo_sgpd_en:1;
0149         u32 bo_data_en:1;
0150         u32 bo_sa_en:1;
0151         u32 bo_pd_en:1;
0152         u32 rsv2:4;
0153         u32 dynamic_sa_en:1;
0154         u32 pdr_mode:2;
0155         u32 pe_mode:1;
0156         u32 rsv3:5;
0157         u32 reset_sg:1;
0158         u32 reset_pdr:1;
0159         u32 reset_pe:1;
0160     } bf;
0161     u32 w;
0162 } __attribute__((packed));
0163 
0164 #define CRYPTO4XX_PDR_BASE_OFFSET       0x48
0165 #define CRYPTO4XX_RDR_BASE_OFFSET       0x4c
0166 #define CRYPTO4XX_RING_SIZE_OFFSET      0x50
0167 union ce_ring_size {
0168     struct {
0169         u32 ring_offset:16;
0170         u32 rsv:6;
0171         u32 ring_size:10;
0172     } bf;
0173     u32 w;
0174 } __attribute__((packed));
0175 
0176 #define CRYPTO4XX_RING_CONTROL_OFFSET       0x54
0177 union ce_ring_control {
0178     struct {
0179         u32 continuous:1;
0180         u32 rsv:5;
0181         u32 ring_retry_divisor:10;
0182         u32 rsv1:4;
0183         u32 ring_poll_divisor:10;
0184     } bf;
0185     u32 w;
0186 } __attribute__((packed));
0187 
0188 #define CRYPTO4XX_IO_THRESHOLD_OFFSET       0x60
0189 union ce_io_threshold {
0190     struct {
0191         u32 rsv:6;
0192         u32 output_threshold:10;
0193         u32 rsv1:6;
0194         u32 input_threshold:10;
0195     } bf;
0196     u32 w;
0197 } __attribute__((packed));
0198 
0199 #define CRYPTO4XX_GATHER_RING_BASE_OFFSET   0x64
0200 #define CRYPTO4XX_SCATTER_RING_BASE_OFFSET  0x68
0201 
0202 union ce_part_ring_size  {
0203     struct {
0204         u32 sdr_size:16;
0205         u32 gdr_size:16;
0206     } bf;
0207     u32 w;
0208 } __attribute__((packed));
0209 
0210 #define MAX_BURST_SIZE_32           0
0211 #define MAX_BURST_SIZE_64           1
0212 #define MAX_BURST_SIZE_128          2
0213 #define MAX_BURST_SIZE_256          3
0214 
0215 /* gather descriptor control length */
0216 struct gd_ctl_len {
0217     u32 len:16;
0218     u32 rsv:14;
0219     u32 done:1;
0220     u32 ready:1;
0221 } __attribute__((packed));
0222 
0223 struct ce_gd {
0224     u32 ptr;
0225     struct gd_ctl_len ctl_len;
0226 } __attribute__((packed));
0227 
0228 struct sd_ctl {
0229     u32 ctl:30;
0230     u32 done:1;
0231     u32 rdy:1;
0232 } __attribute__((packed));
0233 
0234 struct ce_sd {
0235     u32 ptr;
0236     struct sd_ctl ctl;
0237 } __attribute__((packed));
0238 
0239 #define PD_PAD_CTL_32   0x10
0240 #define PD_PAD_CTL_64   0x20
0241 #define PD_PAD_CTL_128  0x40
0242 #define PD_PAD_CTL_256  0x80
0243 union ce_pd_ctl {
0244     struct {
0245         u32 pd_pad_ctl:8;
0246         u32 status:8;
0247         u32 next_hdr:8;
0248         u32 rsv:2;
0249         u32 cached_sa:1;
0250         u32 hash_final:1;
0251         u32 init_arc4:1;
0252         u32 rsv1:1;
0253         u32 pe_done:1;
0254         u32 host_ready:1;
0255     } bf;
0256     u32 w;
0257 } __attribute__((packed));
0258 #define PD_CTL_HASH_FINAL   BIT(4)
0259 #define PD_CTL_PE_DONE      BIT(1)
0260 #define PD_CTL_HOST_READY   BIT(0)
0261 
0262 union ce_pd_ctl_len {
0263     struct {
0264         u32 bypass:8;
0265         u32 pe_done:1;
0266         u32 host_ready:1;
0267         u32 rsv:2;
0268         u32 pkt_len:20;
0269     } bf;
0270     u32 w;
0271 } __attribute__((packed));
0272 
0273 struct ce_pd {
0274     union ce_pd_ctl   pd_ctl;
0275     u32 src;
0276     u32 dest;
0277     u32 sa;                 /* get from ctx->sa_dma_addr */
0278     u32 sa_len;             /* only if dynamic sa is used */
0279     union ce_pd_ctl_len pd_ctl_len;
0280 
0281 } __attribute__((packed));
0282 #endif