Linux 5.1.15
[linux/fpc-iii.git] / drivers / crypto / caam / sg_sw_sec4.h
blobdbfa9fce33e07d9df7de9e0cc62d853f5b0d094a
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * CAAM/SEC 4.x functions for using scatterlists in caam driver
5 * Copyright 2008-2011 Freescale Semiconductor, Inc.
7 */
9 #ifndef _SG_SW_SEC4_H_
10 #define _SG_SW_SEC4_H_
12 #include "ctrl.h"
13 #include "regs.h"
14 #include "sg_sw_qm2.h"
15 #include <soc/fsl/dpaa2-fd.h>
17 struct sec4_sg_entry {
18 u64 ptr;
19 u32 len;
20 u32 bpid_offset;
24 * convert single dma address to h/w link table format
26 static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
27 dma_addr_t dma, u32 len, u16 offset)
29 if (caam_dpaa2) {
30 dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len,
31 offset);
32 } else {
33 sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
34 sec4_sg_ptr->len = cpu_to_caam32(len);
35 sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset &
36 SEC4_SG_OFFSET_MASK);
38 #ifdef DEBUG
39 print_hex_dump(KERN_ERR, "sec4_sg_ptr@: ",
40 DUMP_PREFIX_ADDRESS, 16, 4, sec4_sg_ptr,
41 sizeof(struct sec4_sg_entry), 1);
42 #endif
46 * convert scatterlist to h/w link table format
47 * but does not have final bit; instead, returns last entry
49 static inline struct sec4_sg_entry *
50 sg_to_sec4_sg(struct scatterlist *sg, int sg_count,
51 struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
53 while (sg_count) {
54 dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg),
55 sg_dma_len(sg), offset);
56 sec4_sg_ptr++;
57 sg = sg_next(sg);
58 sg_count--;
60 return sec4_sg_ptr - 1;
63 static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
65 if (caam_dpaa2)
66 dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
67 else
68 sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
72 * convert scatterlist to h/w link table format
73 * scatterlist must have been previously dma mapped
75 static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
76 struct sec4_sg_entry *sec4_sg_ptr,
77 u16 offset)
79 sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
80 sg_to_sec4_set_last(sec4_sg_ptr);
83 #endif /* _SG_SW_SEC4_H_ */