blob: 86747a91ed5b2ae71c7ed843248ed834865e8607 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#ifndef ASR_CIPHER_H
2#define ASR_CIPHER_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/* CIHER flags */
13#define FLAGS_ENCRYPT (1 << 0)
14#define FLAGS_ECB (0 << 1)
15#define FLAGS_CBC (1 << 1)
16#define FLAGS_CTR (2 << 1)
17#define FLAGS_OPMODE_MASK (3 << 1)
18#define FLAGS_BUSY (1 << 3)
19#define FLAGS_AES (0 << 4)
20#define FLAGS_SM4 (1 << 4)
21
22#define CIPHER_FLAGS_PERSISTENT FLAGS_BUSY
23
24#define ASR_CIPHER_QUEUE_LENGTH 50
25#define ASR_CIPHER_PRIORITY 300
26
27#define ASR_CIPHER_BUFFER_ORDER 2
28#define ASR_CIPHER_BUFFER_SIZE (PAGE_SIZE << ASR_CIPHER_BUFFER_ORDER)
29
30enum SCA_MODE {
31 NORMAL_AES = 0,
32 SM4
33};
34
35enum SCA_ALG_STANDARD {
36 ECB = 0,
37 CTR,
38 CBC,
39 CBC_MAC,
40 CMAC,
41 GHASH,
42};
43
44struct sca_data {
45 int encrypt;
46 int alg_type;
47 int mode;
48 int is_last_blk;
49 bool use_rkek;
50};
51
52struct asr_te200_cipher;
53
54typedef int (*asr_cipher_fn_t)(struct asr_te200_cipher *dd);
55typedef irqreturn_t (*asr_cipher_irq_t)(void *);
56
57
58struct asr_cipher_ctx {
59 struct asr_te200_cipher *dd;
60 asr_cipher_fn_t start;
61 int keylen;
62 u32 key[AES_KEYSIZE_256 / sizeof(u32)];
63 u16 block_size;
64 bool use_rkek;
65};
66
67struct asr_cipher_reqctx {
68 unsigned long mode;
69 bool use_rkek;
70 u32 lastc[AES_BLOCK_SIZE / sizeof(u32)];
71};
72
73struct asr_te200_cipher {
74 struct device *dev;
75 struct crypto_async_request *areq;
76
77 void __iomem *io_base;
78 unsigned long phys_base;
79
80 struct asr_cipher_ctx *ctx;
81
82 bool is_async;
83 bool rkek_burned;
84 unsigned long flags;
85
86 spinlock_t lock;
87 struct mutex cipher_lock;
88 struct crypto_queue queue;
89 struct tasklet_struct queue_task;
90
91 asr_cipher_fn_t resume;
92 struct tasklet_struct done_task;
93
94 size_t total;
95 size_t datalen;
96 u32 *data;
97
98 size_t buflen;
99 void *buf;
100
101 struct scatterlist aligned_sg;
102 struct scatterlist *real_dst;
103};
104
105#endif