xref: /linux/drivers/crypto/ccree/cc_lli_defs.h (revision 18dd574acdb70c9c5bc3878d4e98be88259a2fe3)
14c3f9727SGilad Ben-Yossef /* SPDX-License-Identifier: GPL-2.0 */
203963caeSGilad Ben-Yossef /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
34c3f9727SGilad Ben-Yossef 
44c3f9727SGilad Ben-Yossef #ifndef _CC_LLI_DEFS_H_
54c3f9727SGilad Ben-Yossef #define _CC_LLI_DEFS_H_
64c3f9727SGilad Ben-Yossef 
74c3f9727SGilad Ben-Yossef #include <linux/types.h>
84c3f9727SGilad Ben-Yossef 
94c3f9727SGilad Ben-Yossef /* Max DLLI size
104c3f9727SGilad Ben-Yossef  *  AKA CC_DSCRPTR_QUEUE_WORD1_DIN_SIZE_BIT_SIZE
114c3f9727SGilad Ben-Yossef  */
124c3f9727SGilad Ben-Yossef #define DLLI_SIZE_BIT_SIZE	0x18
134c3f9727SGilad Ben-Yossef 
144c3f9727SGilad Ben-Yossef #define CC_MAX_MLLI_ENTRY_SIZE 0xFFFF
154c3f9727SGilad Ben-Yossef 
164c3f9727SGilad Ben-Yossef #define LLI_MAX_NUM_OF_DATA_ENTRIES 128
17*18dd574aSGilad Ben-Yossef #define LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES 8
184c3f9727SGilad Ben-Yossef #define MLLI_TABLE_MIN_ALIGNMENT 4 /* 32 bit alignment */
194c3f9727SGilad Ben-Yossef #define MAX_NUM_OF_BUFFERS_IN_MLLI 4
204c3f9727SGilad Ben-Yossef #define MAX_NUM_OF_TOTAL_MLLI_ENTRIES \
214c3f9727SGilad Ben-Yossef 		(2 * LLI_MAX_NUM_OF_DATA_ENTRIES + \
224c3f9727SGilad Ben-Yossef 		 LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES)
234c3f9727SGilad Ben-Yossef 
244c3f9727SGilad Ben-Yossef /* Size of entry */
254c3f9727SGilad Ben-Yossef #define LLI_ENTRY_WORD_SIZE 2
264c3f9727SGilad Ben-Yossef #define LLI_ENTRY_BYTE_SIZE (LLI_ENTRY_WORD_SIZE * sizeof(u32))
274c3f9727SGilad Ben-Yossef 
284c3f9727SGilad Ben-Yossef /* Word0[31:0] = ADDR[31:0] */
294c3f9727SGilad Ben-Yossef #define LLI_WORD0_OFFSET 0
304c3f9727SGilad Ben-Yossef #define LLI_LADDR_BIT_OFFSET 0
314c3f9727SGilad Ben-Yossef #define LLI_LADDR_BIT_SIZE 32
324c3f9727SGilad Ben-Yossef /* Word1[31:16] = ADDR[47:32]; Word1[15:0] = SIZE */
334c3f9727SGilad Ben-Yossef #define LLI_WORD1_OFFSET 1
344c3f9727SGilad Ben-Yossef #define LLI_SIZE_BIT_OFFSET 0
354c3f9727SGilad Ben-Yossef #define LLI_SIZE_BIT_SIZE 16
364c3f9727SGilad Ben-Yossef #define LLI_HADDR_BIT_OFFSET 16
374c3f9727SGilad Ben-Yossef #define LLI_HADDR_BIT_SIZE 16
384c3f9727SGilad Ben-Yossef 
394c3f9727SGilad Ben-Yossef #define LLI_SIZE_MASK GENMASK((LLI_SIZE_BIT_SIZE - 1), LLI_SIZE_BIT_OFFSET)
404c3f9727SGilad Ben-Yossef #define LLI_HADDR_MASK GENMASK( \
414c3f9727SGilad Ben-Yossef 			       (LLI_HADDR_BIT_OFFSET + LLI_HADDR_BIT_SIZE - 1),\
424c3f9727SGilad Ben-Yossef 				LLI_HADDR_BIT_OFFSET)
434c3f9727SGilad Ben-Yossef 
444c3f9727SGilad Ben-Yossef static inline void cc_lli_set_addr(u32 *lli_p, dma_addr_t addr)
454c3f9727SGilad Ben-Yossef {
464c3f9727SGilad Ben-Yossef 	lli_p[LLI_WORD0_OFFSET] = (addr & U32_MAX);
474c3f9727SGilad Ben-Yossef #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
484c3f9727SGilad Ben-Yossef 	lli_p[LLI_WORD1_OFFSET] &= ~LLI_HADDR_MASK;
494c3f9727SGilad Ben-Yossef 	lli_p[LLI_WORD1_OFFSET] |= FIELD_PREP(LLI_HADDR_MASK, (addr >> 32));
504c3f9727SGilad Ben-Yossef #endif /* CONFIG_ARCH_DMA_ADDR_T_64BIT */
514c3f9727SGilad Ben-Yossef }
524c3f9727SGilad Ben-Yossef 
534c3f9727SGilad Ben-Yossef static inline void cc_lli_set_size(u32 *lli_p, u16 size)
544c3f9727SGilad Ben-Yossef {
554c3f9727SGilad Ben-Yossef 	lli_p[LLI_WORD1_OFFSET] &= ~LLI_SIZE_MASK;
564c3f9727SGilad Ben-Yossef 	lli_p[LLI_WORD1_OFFSET] |= FIELD_PREP(LLI_SIZE_MASK, size);
574c3f9727SGilad Ben-Yossef }
584c3f9727SGilad Ben-Yossef 
594c3f9727SGilad Ben-Yossef #endif /*_CC_LLI_DEFS_H_*/
60