b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #ifndef ASR_AES_H
|
| 2 | #define ASR_AES_H
|
| 3 |
|
| 4 | #include <linux/irq.h>
|
| 5 | #include <linux/interrupt.h>
|
| 6 | #include <linux/crypto.h>
|
| 7 | #include <crypto/aes.h>
|
| 8 | #include <crypto/scatterwalk.h>
|
| 9 | #include <crypto/algapi.h>
|
| 10 | #include <crypto/internal/skcipher.h>
|
| 11 |
|
| 12 | /* AES flags */
|
| 13 | #define AES_FLAGS_ENCRYPT (1 << 0)
|
| 14 | #define AES_FLAGS_ECB (0 << 1)
|
| 15 | #define AES_FLAGS_CBC (1 << 1)
|
| 16 | #define AES_FLAGS_OPMODE_MASK (3 << 1)
|
| 17 | #define AES_FLAGS_BUSY (1 << 3)
|
| 18 | #define AES_FLAGS_DMA (1 << 4)
|
| 19 |
|
| 20 | #define AES_FLAGS_MODE_MASK (AES_FLAGS_OPMODE_MASK | \
|
| 21 | AES_FLAGS_ENCRYPT)
|
| 22 |
|
| 23 | #define AES_FLAGS_PERSISTENT AES_FLAGS_BUSY
|
| 24 |
|
| 25 | #define BIT_SET (1)
|
| 26 | #define BIT_CLR (0)
|
| 27 |
|
| 28 | #define ASR_AES_QUEUE_LENGTH 50
|
| 29 | #define ASR_AES_PRIORITY 300
|
| 30 |
|
| 31 | #define ASR_AES_BUFFER_ORDER 2
|
| 32 | #define ASR_AES_BUFFER_SIZE (PAGE_SIZE << ASR_AES_BUFFER_ORDER)
|
| 33 | #define ASR_AES_DMA_THRESHOLD (256)
|
| 34 |
|
| 35 | #define ASR_AES_HWKEY (1 << 0)
|
| 36 |
|
| 37 | enum {
|
| 38 | AES_DECRYPT = 0,
|
| 39 | AES_ENCRYPT = 1,
|
| 40 | };
|
| 41 |
|
| 42 | struct asr_geu_aes;
|
| 43 |
|
| 44 | typedef int (*asr_aes_fn_t)(struct asr_geu_aes *);
|
| 45 | typedef irqreturn_t (*asr_geu_irq_t)(u32, void *);
|
| 46 |
|
| 47 | struct asr_aes_ctx {
|
| 48 | struct asr_geu_aes *dd;
|
| 49 | asr_aes_fn_t start;
|
| 50 | int keylen;
|
| 51 | u32 key[AES_KEYSIZE_256 / sizeof(u32)];
|
| 52 | u16 block_size;
|
| 53 | bool use_rkek;
|
| 54 | };
|
| 55 |
|
| 56 | struct asr_aes_reqctx {
|
| 57 | unsigned long mode;
|
| 58 | bool use_rkek;
|
| 59 | u32 lastc[AES_BLOCK_SIZE / sizeof(u32)];
|
| 60 | };
|
| 61 |
|
| 62 | struct asr_aes_dma {
|
| 63 | struct dma_chan *chan;
|
| 64 | struct scatterlist *sg;
|
| 65 | int nents;
|
| 66 | unsigned int remainder;
|
| 67 | unsigned int sg_len;
|
| 68 | };
|
| 69 |
|
| 70 | struct asr_geu_aes {
|
| 71 | struct device *dev;
|
| 72 |
|
| 73 | #ifndef CONFIG_OPTEE
|
| 74 | void __iomem *io_base;
|
| 75 | unsigned long phys_base;
|
| 76 | #endif
|
| 77 | struct crypto_async_request *areq;
|
| 78 |
|
| 79 | struct asr_aes_ctx *ctx;
|
| 80 |
|
| 81 | bool is_async;
|
| 82 | bool rkek_burned;
|
| 83 | unsigned long flags;
|
| 84 |
|
| 85 | spinlock_t lock;
|
| 86 | struct crypto_queue queue;
|
| 87 | struct tasklet_struct queue_task;
|
| 88 |
|
| 89 | int int_mode;
|
| 90 | asr_aes_fn_t resume;
|
| 91 | asr_aes_fn_t cpu_transfer_complete;
|
| 92 | asr_geu_irq_t aes_irq;
|
| 93 | struct tasklet_struct done_task;
|
| 94 |
|
| 95 | #ifndef CONFIG_OPTEE
|
| 96 | size_t total;
|
| 97 | size_t datalen;
|
| 98 | u32 *data;
|
| 99 |
|
| 100 | struct asr_aes_dma src;
|
| 101 | struct asr_aes_dma dst;
|
| 102 |
|
| 103 | size_t buflen;
|
| 104 | void *buf;
|
| 105 |
|
| 106 | struct scatterlist aligned_sg;
|
| 107 | struct scatterlist *real_dst;
|
| 108 | #endif
|
| 109 | };
|
| 110 |
|
| 111 | #endif |