This source file includes following definitions.
- hw_desc_init
- set_queue_last_ind_bit
- set_din_type
- set_din_no_dma
- set_cpp_crypto_key
- set_din_sram
- set_din_const
- set_din_not_last_indication
- set_dout_type
- set_dout_dlli
- set_dout_mlli
- set_dout_no_dma
- set_xor_val
- set_xor_active
- set_aes_not_hash_mode
- set_aes_xor_crypto_key
- set_dout_sram
- set_xex_data_unit_size
- set_multi2_num_rounds
- set_flow_mode
- set_cipher_mode
- set_hash_cipher_mode
- set_cipher_config0
- set_cipher_config1
- set_hw_crypto_key
- set_bytes_swap
- set_cmac_size0_mode
- set_key_size
- set_key_size_aes
- set_key_size_des
- set_setup_mode
- set_cipher_do
1
2
3
4 #ifndef __CC_HW_QUEUE_DEFS_H__
5 #define __CC_HW_QUEUE_DEFS_H__
6
7 #include <linux/types.h>
8
9 #include "cc_kernel_regs.h"
10 #include <linux/bitfield.h>
11
12
13
14
15
16 #define HW_DESC_SIZE_WORDS 6
17
18 #define HW_QUEUE_SLOTS_MAX 15
19
20 #define CC_REG_LOW(word, name) \
21 (CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SHIFT)
22
23 #define CC_REG_HIGH(word, name) \
24 (CC_REG_LOW(word, name) + \
25 CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SIZE - 1)
26
27 #define CC_GENMASK(word, name) \
28 GENMASK(CC_REG_HIGH(word, name), CC_REG_LOW(word, name))
29
30 #define WORD0_VALUE CC_GENMASK(0, VALUE)
31 #define WORD0_CPP_CIPHER_MODE CC_GENMASK(0, CPP_CIPHER_MODE)
32 #define WORD1_DIN_CONST_VALUE CC_GENMASK(1, DIN_CONST_VALUE)
33 #define WORD1_DIN_DMA_MODE CC_GENMASK(1, DIN_DMA_MODE)
34 #define WORD1_DIN_SIZE CC_GENMASK(1, DIN_SIZE)
35 #define WORD1_NOT_LAST CC_GENMASK(1, NOT_LAST)
36 #define WORD1_NS_BIT CC_GENMASK(1, NS_BIT)
37 #define WORD1_LOCK_QUEUE CC_GENMASK(1, LOCK_QUEUE)
38 #define WORD2_VALUE CC_GENMASK(2, VALUE)
39 #define WORD3_DOUT_DMA_MODE CC_GENMASK(3, DOUT_DMA_MODE)
40 #define WORD3_DOUT_LAST_IND CC_GENMASK(3, DOUT_LAST_IND)
41 #define WORD3_DOUT_SIZE CC_GENMASK(3, DOUT_SIZE)
42 #define WORD3_HASH_XOR_BIT CC_GENMASK(3, HASH_XOR_BIT)
43 #define WORD3_NS_BIT CC_GENMASK(3, NS_BIT)
44 #define WORD3_QUEUE_LAST_IND CC_GENMASK(3, QUEUE_LAST_IND)
45 #define WORD4_ACK_NEEDED CC_GENMASK(4, ACK_NEEDED)
46 #define WORD4_AES_SEL_N_HASH CC_GENMASK(4, AES_SEL_N_HASH)
47 #define WORD4_AES_XOR_CRYPTO_KEY CC_GENMASK(4, AES_XOR_CRYPTO_KEY)
48 #define WORD4_BYTES_SWAP CC_GENMASK(4, BYTES_SWAP)
49 #define WORD4_CIPHER_CONF0 CC_GENMASK(4, CIPHER_CONF0)
50 #define WORD4_CIPHER_CONF1 CC_GENMASK(4, CIPHER_CONF1)
51 #define WORD4_CIPHER_CONF2 CC_GENMASK(4, CIPHER_CONF2)
52 #define WORD4_CIPHER_DO CC_GENMASK(4, CIPHER_DO)
53 #define WORD4_CIPHER_MODE CC_GENMASK(4, CIPHER_MODE)
54 #define WORD4_CMAC_SIZE0 CC_GENMASK(4, CMAC_SIZE0)
55 #define WORD4_DATA_FLOW_MODE CC_GENMASK(4, DATA_FLOW_MODE)
56 #define WORD4_KEY_SIZE CC_GENMASK(4, KEY_SIZE)
57 #define WORD4_SETUP_OPERATION CC_GENMASK(4, SETUP_OPERATION)
58 #define WORD5_DIN_ADDR_HIGH CC_GENMASK(5, DIN_ADDR_HIGH)
59 #define WORD5_DOUT_ADDR_HIGH CC_GENMASK(5, DOUT_ADDR_HIGH)
60
61
62
63
64
65 struct cc_hw_desc {
66 union {
67 u32 word[HW_DESC_SIZE_WORDS];
68 u16 hword[HW_DESC_SIZE_WORDS * 2];
69 };
70 };
71
72 enum cc_axi_sec {
73 AXI_SECURE = 0,
74 AXI_NOT_SECURE = 1
75 };
76
77 enum cc_desc_direction {
78 DESC_DIRECTION_ILLEGAL = -1,
79 DESC_DIRECTION_ENCRYPT_ENCRYPT = 0,
80 DESC_DIRECTION_DECRYPT_DECRYPT = 1,
81 DESC_DIRECTION_DECRYPT_ENCRYPT = 3,
82 DESC_DIRECTION_END = S32_MAX,
83 };
84
85 enum cc_dma_mode {
86 DMA_MODE_NULL = -1,
87 NO_DMA = 0,
88 DMA_SRAM = 1,
89 DMA_DLLI = 2,
90 DMA_MLLI = 3,
91 DMA_MODE_END = S32_MAX,
92 };
93
94 enum cc_flow_mode {
95 FLOW_MODE_NULL = -1,
96
97 BYPASS = 0,
98 DIN_AES_DOUT = 1,
99 AES_to_HASH = 2,
100 AES_and_HASH = 3,
101 DIN_DES_DOUT = 4,
102 DES_to_HASH = 5,
103 DES_and_HASH = 6,
104 DIN_HASH = 7,
105 DIN_HASH_and_BYPASS = 8,
106 AESMAC_and_BYPASS = 9,
107 AES_to_HASH_and_DOUT = 10,
108 DIN_RC4_DOUT = 11,
109 DES_to_HASH_and_DOUT = 12,
110 AES_to_AES_to_HASH_and_DOUT = 13,
111 AES_to_AES_to_HASH = 14,
112 AES_to_HASH_and_AES = 15,
113 DIN_SM4_DOUT = 16,
114 DIN_AES_AESMAC = 17,
115 HASH_to_DOUT = 18,
116
117 S_DIN_to_AES = 32,
118 S_DIN_to_AES2 = 33,
119 S_DIN_to_DES = 34,
120 S_DIN_to_RC4 = 35,
121 S_DIN_to_SM4 = 36,
122 S_DIN_to_HASH = 37,
123 S_AES_to_DOUT = 38,
124 S_AES2_to_DOUT = 39,
125 S_SM4_to_DOUT = 40,
126 S_RC4_to_DOUT = 41,
127 S_DES_to_DOUT = 42,
128 S_HASH_to_DOUT = 43,
129 SET_FLOW_ID = 44,
130 FLOW_MODE_END = S32_MAX,
131 };
132
133 enum cc_setup_op {
134 SETUP_LOAD_NOP = 0,
135 SETUP_LOAD_STATE0 = 1,
136 SETUP_LOAD_STATE1 = 2,
137 SETUP_LOAD_STATE2 = 3,
138 SETUP_LOAD_KEY0 = 4,
139 SETUP_LOAD_XEX_KEY = 5,
140 SETUP_WRITE_STATE0 = 8,
141 SETUP_WRITE_STATE1 = 9,
142 SETUP_WRITE_STATE2 = 10,
143 SETUP_WRITE_STATE3 = 11,
144 SETUP_OP_END = S32_MAX,
145 };
146
147 enum cc_hash_conf_pad {
148 HASH_PADDING_DISABLED = 0,
149 HASH_PADDING_ENABLED = 1,
150 HASH_DIGEST_RESULT_LITTLE_ENDIAN = 2,
151 HASH_CONFIG1_PADDING_RESERVE32 = S32_MAX,
152 };
153
154 enum cc_aes_mac_selector {
155 AES_SK = 1,
156 AES_CMAC_INIT = 2,
157 AES_CMAC_SIZE0 = 3,
158 AES_MAC_END = S32_MAX,
159 };
160
161 #define HW_KEY_MASK_CIPHER_DO 0x3
162 #define HW_KEY_SHIFT_CIPHER_CFG2 2
163
164
165
166 enum cc_hw_crypto_key {
167 USER_KEY = 0,
168 ROOT_KEY = 1,
169 PROVISIONING_KEY = 2,
170 SESSION_KEY = 3,
171 RESERVED_KEY = 4,
172 PLATFORM_KEY = 5,
173 CUSTOMER_KEY = 6,
174 KFDE0_KEY = 7,
175 KFDE1_KEY = 9,
176 KFDE2_KEY = 10,
177 KFDE3_KEY = 11,
178 END_OF_KEYS = S32_MAX,
179 };
180
181 #define CC_NUM_HW_KEY_SLOTS 4
182 #define CC_FIRST_HW_KEY_SLOT 0
183 #define CC_LAST_HW_KEY_SLOT (CC_FIRST_HW_KEY_SLOT + CC_NUM_HW_KEY_SLOTS - 1)
184
185 #define CC_NUM_CPP_KEY_SLOTS 8
186 #define CC_FIRST_CPP_KEY_SLOT 16
187 #define CC_LAST_CPP_KEY_SLOT (CC_FIRST_CPP_KEY_SLOT + \
188 CC_NUM_CPP_KEY_SLOTS - 1)
189
190 enum cc_hw_aes_key_size {
191 AES_128_KEY = 0,
192 AES_192_KEY = 1,
193 AES_256_KEY = 2,
194 END_OF_AES_KEYS = S32_MAX,
195 };
196
197 enum cc_hash_cipher_pad {
198 DO_NOT_PAD = 0,
199 DO_PAD = 1,
200 HASH_CIPHER_DO_PADDING_RESERVE32 = S32_MAX,
201 };
202
203 #define CC_CPP_DIN_ADDR 0xFF00FF00UL
204 #define CC_CPP_DIN_SIZE 0xFF00FFUL
205
206
207
208
209
210
211
212
213
214 static inline void hw_desc_init(struct cc_hw_desc *pdesc)
215 {
216 memset(pdesc, 0, sizeof(struct cc_hw_desc));
217 }
218
219
220
221
222
223
224 static inline void set_queue_last_ind_bit(struct cc_hw_desc *pdesc)
225 {
226 pdesc->word[3] |= FIELD_PREP(WORD3_QUEUE_LAST_IND, 1);
227 }
228
229
230
231
232
233
234
235
236
237
238 static inline void set_din_type(struct cc_hw_desc *pdesc,
239 enum cc_dma_mode dma_mode, dma_addr_t addr,
240 u32 size, enum cc_axi_sec axi_sec)
241 {
242 pdesc->word[0] = (u32)addr;
243 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
244 pdesc->word[5] |= FIELD_PREP(WORD5_DIN_ADDR_HIGH, ((u16)(addr >> 32)));
245 #endif
246 pdesc->word[1] |= FIELD_PREP(WORD1_DIN_DMA_MODE, dma_mode) |
247 FIELD_PREP(WORD1_DIN_SIZE, size) |
248 FIELD_PREP(WORD1_NS_BIT, axi_sec);
249 }
250
251
252
253
254
255
256
257
258
259 static inline void set_din_no_dma(struct cc_hw_desc *pdesc, u32 addr, u32 size)
260 {
261 pdesc->word[0] = addr;
262 pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size);
263 }
264
265
266
267
268
269
270
271
272
273
274 static inline void set_cpp_crypto_key(struct cc_hw_desc *pdesc, u8 slot)
275 {
276 pdesc->word[0] |= CC_CPP_DIN_ADDR;
277
278 pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, CC_CPP_DIN_SIZE);
279 pdesc->word[1] |= FIELD_PREP(WORD1_LOCK_QUEUE, 1);
280
281 pdesc->word[4] |= FIELD_PREP(WORD4_SETUP_OPERATION, slot);
282 }
283
284
285
286
287
288
289
290
291
292
293 static inline void set_din_sram(struct cc_hw_desc *pdesc, dma_addr_t addr,
294 u32 size)
295 {
296 pdesc->word[0] = (u32)addr;
297 pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size) |
298 FIELD_PREP(WORD1_DIN_DMA_MODE, DMA_SRAM);
299 }
300
301
302
303
304
305
306
307
308 static inline void set_din_const(struct cc_hw_desc *pdesc, u32 val, u32 size)
309 {
310 pdesc->word[0] = val;
311 pdesc->word[1] |= FIELD_PREP(WORD1_DIN_CONST_VALUE, 1) |
312 FIELD_PREP(WORD1_DIN_DMA_MODE, DMA_SRAM) |
313 FIELD_PREP(WORD1_DIN_SIZE, size);
314 }
315
316
317
318
319
320
321 static inline void set_din_not_last_indication(struct cc_hw_desc *pdesc)
322 {
323 pdesc->word[1] |= FIELD_PREP(WORD1_NOT_LAST, 1);
324 }
325
326
327
328
329
330
331
332
333
334
335 static inline void set_dout_type(struct cc_hw_desc *pdesc,
336 enum cc_dma_mode dma_mode, dma_addr_t addr,
337 u32 size, enum cc_axi_sec axi_sec)
338 {
339 pdesc->word[2] = (u32)addr;
340 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
341 pdesc->word[5] |= FIELD_PREP(WORD5_DOUT_ADDR_HIGH, ((u16)(addr >> 32)));
342 #endif
343 pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_DMA_MODE, dma_mode) |
344 FIELD_PREP(WORD3_DOUT_SIZE, size) |
345 FIELD_PREP(WORD3_NS_BIT, axi_sec);
346 }
347
348
349
350
351
352
353
354
355
356
357
358 static inline void set_dout_dlli(struct cc_hw_desc *pdesc, dma_addr_t addr,
359 u32 size, enum cc_axi_sec axi_sec,
360 u32 last_ind)
361 {
362 set_dout_type(pdesc, DMA_DLLI, addr, size, axi_sec);
363 pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_LAST_IND, last_ind);
364 }
365
366
367
368
369
370
371
372
373
374
375
376 static inline void set_dout_mlli(struct cc_hw_desc *pdesc, dma_addr_t addr,
377 u32 size, enum cc_axi_sec axi_sec,
378 bool last_ind)
379 {
380 set_dout_type(pdesc, DMA_MLLI, addr, size, axi_sec);
381 pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_LAST_IND, last_ind);
382 }
383
384
385
386
387
388
389
390
391
392
393 static inline void set_dout_no_dma(struct cc_hw_desc *pdesc, u32 addr,
394 u32 size, bool write_enable)
395 {
396 pdesc->word[2] = addr;
397 pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_SIZE, size) |
398 FIELD_PREP(WORD3_DOUT_LAST_IND, write_enable);
399 }
400
401
402
403
404
405
406
407 static inline void set_xor_val(struct cc_hw_desc *pdesc, u32 val)
408 {
409 pdesc->word[2] = val;
410 }
411
412
413
414
415
416
417 static inline void set_xor_active(struct cc_hw_desc *pdesc)
418 {
419 pdesc->word[3] |= FIELD_PREP(WORD3_HASH_XOR_BIT, 1);
420 }
421
422
423
424
425
426
427
428 static inline void set_aes_not_hash_mode(struct cc_hw_desc *pdesc)
429 {
430 pdesc->word[4] |= FIELD_PREP(WORD4_AES_SEL_N_HASH, 1);
431 }
432
433
434
435
436
437
438 static inline void set_aes_xor_crypto_key(struct cc_hw_desc *pdesc)
439 {
440 pdesc->word[4] |= FIELD_PREP(WORD4_AES_XOR_CRYPTO_KEY, 1);
441 }
442
443
444
445
446
447
448
449
450
451
452 static inline void set_dout_sram(struct cc_hw_desc *pdesc, u32 addr, u32 size)
453 {
454 pdesc->word[2] = addr;
455 pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_DMA_MODE, DMA_SRAM) |
456 FIELD_PREP(WORD3_DOUT_SIZE, size);
457 }
458
459
460
461
462
463
464
465 static inline void set_xex_data_unit_size(struct cc_hw_desc *pdesc, u32 size)
466 {
467 pdesc->word[2] = size;
468 }
469
470
471
472
473
474
475
476 static inline void set_multi2_num_rounds(struct cc_hw_desc *pdesc, u32 num)
477 {
478 pdesc->word[2] = num;
479 }
480
481
482
483
484
485
486
487 static inline void set_flow_mode(struct cc_hw_desc *pdesc,
488 enum cc_flow_mode mode)
489 {
490 pdesc->word[4] |= FIELD_PREP(WORD4_DATA_FLOW_MODE, mode);
491 }
492
493
494
495
496
497
498
499 static inline void set_cipher_mode(struct cc_hw_desc *pdesc, int mode)
500 {
501 pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_MODE, mode);
502 }
503
504
505
506
507
508
509
510
511 static inline void set_hash_cipher_mode(struct cc_hw_desc *pdesc,
512 enum drv_cipher_mode cipher_mode,
513 enum drv_hash_mode hash_mode)
514 {
515 set_cipher_mode(pdesc, cipher_mode);
516 if (hash_mode == DRV_HASH_SM3)
517 set_aes_xor_crypto_key(pdesc);
518 }
519
520
521
522
523
524
525
526 static inline void set_cipher_config0(struct cc_hw_desc *pdesc, int mode)
527 {
528 pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF0, mode);
529 }
530
531
532
533
534
535
536
537 static inline void set_cipher_config1(struct cc_hw_desc *pdesc,
538 enum cc_hash_conf_pad config)
539 {
540 pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF1, config);
541 }
542
543
544
545
546
547
548
549 static inline void set_hw_crypto_key(struct cc_hw_desc *pdesc,
550 enum cc_hw_crypto_key hw_key)
551 {
552 pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_DO,
553 (hw_key & HW_KEY_MASK_CIPHER_DO)) |
554 FIELD_PREP(WORD4_CIPHER_CONF2,
555 (hw_key >> HW_KEY_SHIFT_CIPHER_CFG2));
556 }
557
558
559
560
561
562
563
564 static inline void set_bytes_swap(struct cc_hw_desc *pdesc, bool config)
565 {
566 pdesc->word[4] |= FIELD_PREP(WORD4_BYTES_SWAP, config);
567 }
568
569
570
571
572
573
574 static inline void set_cmac_size0_mode(struct cc_hw_desc *pdesc)
575 {
576 pdesc->word[4] |= FIELD_PREP(WORD4_CMAC_SIZE0, 1);
577 }
578
579
580
581
582
583
584
585 static inline void set_key_size(struct cc_hw_desc *pdesc, u32 size)
586 {
587 pdesc->word[4] |= FIELD_PREP(WORD4_KEY_SIZE, size);
588 }
589
590
591
592
593
594
595
596 static inline void set_key_size_aes(struct cc_hw_desc *pdesc, u32 size)
597 {
598 set_key_size(pdesc, ((size >> 3) - 2));
599 }
600
601
602
603
604
605
606
607 static inline void set_key_size_des(struct cc_hw_desc *pdesc, u32 size)
608 {
609 set_key_size(pdesc, ((size >> 3) - 1));
610 }
611
612
613
614
615
616
617
618 static inline void set_setup_mode(struct cc_hw_desc *pdesc,
619 enum cc_setup_op mode)
620 {
621 pdesc->word[4] |= FIELD_PREP(WORD4_SETUP_OPERATION, mode);
622 }
623
624
625
626
627
628
629
630 static inline void set_cipher_do(struct cc_hw_desc *pdesc,
631 enum cc_hash_cipher_pad config)
632 {
633 pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_DO,
634 (config & HW_KEY_MASK_CIPHER_DO));
635 }
636
637 #endif