blob: 3902cf3fdc46385b9ef10f0b3ed7a276dcaa8f8b [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 BYTES_TO_BITS 8
25#define WORK_BUF_SIZE 2048
26
27#define ASR_CIPHER_QUEUE_LENGTH 50
28#define ASR_CIPHER_PRIORITY 300
29
30#define ASR_CIPHER_BUFFER_ORDER 2
31#define ASR_CIPHER_BUFFER_SIZE (PAGE_SIZE << ASR_CIPHER_BUFFER_ORDER)
32
33typedef enum {
34 EXT_KEY = 0,
35 RK_KEY,
36 SSK_KEY,
37} AES_KEY_SELECT_T;
38
39typedef enum {
40 AES_128 = 128/8,
41 AES_192 = 192/8,
42 AES_256 = 256/8,
43} AES_KEY_LEN_T;
44
45typedef enum {
46 AES_ECB_ALG = 0,
47 AES_CBC_ALG,
48 AES_CTR_ALG,
49 AES_XTS_ALG,
50 AES_KEYWRAP,
51} AES_MODE_T;
52
53typedef enum {
54 AES_DECRYPT_OP = 0,
55 AES_ENCRYPT_OP,
56} AES_OP_MODE_T;
57
58typedef enum {
59 ENG_AES = 0,
60 ENG_DES,
61 ENG_RC4,
62} CRYPTO_ENG_SEL_T;
63
64typedef struct {
65 uint32_t paddr;
66 uint32_t size;
67 uint32_t next_desc;
68 uint32_t reserved;
69} DMA_DESC_T;
70
71struct rijndael_key {
72 uint8_t K[(60 + 60 + 4) * sizeof(uint32_t)];
73 uint32_t *eK;
74 uint32_t *dK;
75 int Nr;
76};
77
78typedef union Symmetric_key {
79 struct rijndael_key rijndael;
80} symmetric_key;
81
82struct asr_bcm_cipher;
83
84typedef int (*asr_cipher_fn_t)(struct asr_bcm_cipher *dd);
85typedef irqreturn_t (*asr_cipher_irq_t)(void *);
86
87
88struct asr_cipher_ctx {
89 struct asr_bcm_cipher *dd;
90 asr_cipher_fn_t start;
91 int keylen;
92 u32 key[AES_KEYSIZE_256 / sizeof(u32)];
93 u16 block_size;
94 bool use_rkek;
95};
96
97struct asr_cipher_reqctx {
98 unsigned long mode;
99 bool use_rkek;
100 u32 lastc[AES_BLOCK_SIZE / sizeof(u32)];
101};
102
103struct asr_bcm_cipher {
104 struct device *dev;
105 struct crypto_async_request *areq;
106
107 void __iomem *io_base;
108 unsigned long phys_base;
109
110 struct asr_cipher_ctx *ctx;
111
112 bool is_async;
113 bool rkek_burned;
114 unsigned long flags;
115
116 spinlock_t lock;
117 struct mutex cipher_lock;
118 struct crypto_queue queue;
119 struct tasklet_struct queue_task;
120
121 asr_cipher_fn_t resume;
122 struct tasklet_struct done_task;
123
124 size_t total;
125 size_t datalen;
126 u32 *data;
127
128 size_t buflen;
129 void *buf;
130
131 struct scatterlist aligned_sg;
132 struct scatterlist *real_dst;
133};
134
135#endif