1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __STARFIVE_STR_H__ 3 #define __STARFIVE_STR_H__ 4 5 #include <linux/delay.h> 6 #include <linux/dma-mapping.h> 7 #include <linux/dmaengine.h> 8 9 #include <crypto/engine.h> 10 #include <crypto/sha2.h> 11 #include <crypto/sm3.h> 12 13 #define STARFIVE_ALG_CR_OFFSET 0x0 14 #define STARFIVE_ALG_FIFO_OFFSET 0x4 15 #define STARFIVE_IE_MASK_OFFSET 0x8 16 #define STARFIVE_IE_FLAG_OFFSET 0xc 17 #define STARFIVE_DMA_IN_LEN_OFFSET 0x10 18 #define STARFIVE_DMA_OUT_LEN_OFFSET 0x14 19 20 #define STARFIVE_IE_MASK_HASH_DONE 0x4 21 #define STARFIVE_IE_FLAG_HASH_DONE 0x4 22 23 #define STARFIVE_MSG_BUFFER_SIZE SZ_16K 24 #define MAX_KEY_SIZE SHA512_BLOCK_SIZE 25 26 union starfive_hash_csr { 27 u32 v; 28 struct { 29 u32 start :1; 30 u32 reset :1; 31 u32 ie :1; 32 u32 firstb :1; 33 #define STARFIVE_HASH_SM3 0x0 34 #define STARFIVE_HASH_SHA224 0x3 35 #define STARFIVE_HASH_SHA256 0x4 36 #define STARFIVE_HASH_SHA384 0x5 37 #define STARFIVE_HASH_SHA512 0x6 38 #define STARFIVE_HASH_MODE_MASK 0x7 39 u32 mode :3; 40 u32 rsvd_1 :1; 41 u32 final :1; 42 u32 rsvd_2 :2; 43 #define STARFIVE_HASH_HMAC_FLAGS 0x800 44 u32 hmac :1; 45 u32 rsvd_3 :1; 46 #define STARFIVE_HASH_KEY_DONE BIT(13) 47 u32 key_done :1; 48 u32 key_flag :1; 49 u32 hmac_done :1; 50 #define STARFIVE_HASH_BUSY BIT(16) 51 u32 busy :1; 52 u32 hashdone :1; 53 u32 rsvd_4 :14; 54 }; 55 }; 56 57 58 union starfive_alg_cr { 59 u32 v; 60 struct { 61 u32 start :1; 62 u32 aes_dma_en :1; 63 u32 rsvd_0 :1; 64 u32 hash_dma_en :1; 65 u32 alg_done :1; 66 u32 rsvd_1 :3; 67 u32 clear :1; 68 u32 rsvd_2 :23; 69 }; 70 }; 71 72 struct starfive_cryp_ctx { 73 struct crypto_engine_ctx enginectx; 74 struct starfive_cryp_dev *cryp; 75 struct starfive_cryp_request_ctx *rctx; 76 77 unsigned int hash_mode; 78 u8 key[MAX_KEY_SIZE]; 79 int keylen; 80 bool is_hmac; 81 struct crypto_ahash *ahash_fbk; 82 }; 83 84 struct starfive_cryp_dev { 85 struct list_head list; 86 struct device *dev; 87 struct clk *hclk; 88 struct clk *ahb; 89 struct reset_control *rst; 90 91 void __iomem *base; 92 phys_addr_t phys_base; 93 94 u32 dma_maxburst; 95 struct dma_chan *tx; 96 struct dma_chan *rx; 97 struct dma_slave_config cfg_in; 98 struct dma_slave_config cfg_out; 99 struct crypto_engine *engine; 100 struct tasklet_struct hash_done; 101 int err; 102 union starfive_alg_cr alg_cr; 103 union { 104 struct ahash_request *hreq; 105 } req; 106 }; 107 108 struct starfive_cryp_request_ctx { 109 union { 110 union starfive_hash_csr hash; 111 } csr; 112 113 struct scatterlist *in_sg; 114 struct ahash_request ahash_fbk_req; 115 size_t total; 116 unsigned int blksize; 117 unsigned int digsize; 118 unsigned long in_sg_len; 119 }; 120 121 struct starfive_cryp_dev *starfive_cryp_find_dev(struct starfive_cryp_ctx *ctx); 122 123 int starfive_hash_register_algs(void); 124 void starfive_hash_unregister_algs(void); 125 126 void starfive_hash_done_task(unsigned long param); 127 #endif 128