xref: /linux/drivers/crypto/caam/sg_sw_qm2.h (revision bd628c1bed7902ec1f24ba0fe70758949146abbe)
1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /*
3  * Copyright 2015-2016 Freescale Semiconductor, Inc.
4  * Copyright 2017 NXP
5  */
6 
7 #ifndef _SG_SW_QM2_H_
8 #define _SG_SW_QM2_H_
9 
10 #include <soc/fsl/dpaa2-fd.h>
11 
12 static inline void dma_to_qm_sg_one(struct dpaa2_sg_entry *qm_sg_ptr,
13 				    dma_addr_t dma, u32 len, u16 offset)
14 {
15 	dpaa2_sg_set_addr(qm_sg_ptr, dma);
16 	dpaa2_sg_set_format(qm_sg_ptr, dpaa2_sg_single);
17 	dpaa2_sg_set_final(qm_sg_ptr, false);
18 	dpaa2_sg_set_len(qm_sg_ptr, len);
19 	dpaa2_sg_set_bpid(qm_sg_ptr, 0);
20 	dpaa2_sg_set_offset(qm_sg_ptr, offset);
21 }
22 
23 /*
24  * convert scatterlist to h/w link table format
25  * but does not have final bit; instead, returns last entry
26  */
27 static inline struct dpaa2_sg_entry *
28 sg_to_qm_sg(struct scatterlist *sg, int sg_count,
29 	    struct dpaa2_sg_entry *qm_sg_ptr, u16 offset)
30 {
31 	while (sg_count && sg) {
32 		dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg),
33 				 sg_dma_len(sg), offset);
34 		qm_sg_ptr++;
35 		sg = sg_next(sg);
36 		sg_count--;
37 	}
38 	return qm_sg_ptr - 1;
39 }
40 
41 /*
42  * convert scatterlist to h/w link table format
43  * scatterlist must have been previously dma mapped
44  */
45 static inline void sg_to_qm_sg_last(struct scatterlist *sg, int sg_count,
46 				    struct dpaa2_sg_entry *qm_sg_ptr,
47 				    u16 offset)
48 {
49 	qm_sg_ptr = sg_to_qm_sg(sg, sg_count, qm_sg_ptr, offset);
50 	dpaa2_sg_set_final(qm_sg_ptr, true);
51 }
52 
53 #endif /* _SG_SW_QM2_H_ */
54