crypto: caam - use len instead of nents for bulding HW S/G table
[linux-2.6-block.git] / drivers / crypto / caam / sg_sw_sec4.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
4c1ec1f9
YK
2/*
3 * CAAM/SEC 4.x functions for using scatterlists in caam driver
4 *
5 * Copyright 2008-2011 Freescale Semiconductor, Inc.
6 *
7 */
8
297b9ceb
HG
9#ifndef _SG_SW_SEC4_H_
10#define _SG_SW_SEC4_H_
11
12#include "ctrl.h"
261ea058 13#include "regs.h"
297b9ceb 14#include "sg_sw_qm2.h"
c89105c9 15#include <soc/fsl/dpaa2-fd.h>
261ea058 16
e25ff92e
HG
17struct sec4_sg_entry {
18 u64 ptr;
19 u32 len;
20 u32 bpid_offset;
21};
4c1ec1f9
YK
22
23/*
24 * convert single dma address to h/w link table format
25 */
a299c837 26static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
bd52f1c2 27 dma_addr_t dma, u32 len, u16 offset)
4c1ec1f9 28{
297b9ceb
HG
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);
37 }
6e005503
SH
38
39 print_hex_dump_debug("sec4_sg_ptr@: ", DUMP_PREFIX_ADDRESS, 16, 4,
40 sec4_sg_ptr, sizeof(struct sec4_sg_entry), 1);
4c1ec1f9
YK
41}
42
43/*
44 * convert scatterlist to h/w link table format
45 * but does not have final bit; instead, returns last entry
46 */
a299c837 47static inline struct sec4_sg_entry *
059d73ee 48sg_to_sec4_sg(struct scatterlist *sg, int len,
bd52f1c2 49 struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
4c1ec1f9 50{
059d73ee
HG
51 int ent_len;
52
53 while (len) {
54 ent_len = min_t(int, sg_dma_len(sg), len);
55
56 dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), ent_len,
57 offset);
a299c837 58 sec4_sg_ptr++;
5be4d4c9 59 sg = sg_next(sg);
059d73ee 60 len -= ent_len;
4c1ec1f9 61 }
a299c837 62 return sec4_sg_ptr - 1;
4c1ec1f9
YK
63}
64
297b9ceb
HG
65static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
66{
67 if (caam_dpaa2)
68 dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
69 else
70 sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
71}
72
4c1ec1f9
YK
73/*
74 * convert scatterlist to h/w link table format
75 * scatterlist must have been previously dma mapped
76 */
059d73ee 77static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int len,
a299c837 78 struct sec4_sg_entry *sec4_sg_ptr,
bd52f1c2 79 u16 offset)
4c1ec1f9 80{
059d73ee 81 sec4_sg_ptr = sg_to_sec4_sg(sg, len, sec4_sg_ptr, offset);
297b9ceb 82 sg_to_sec4_set_last(sec4_sg_ptr);
4c1ec1f9 83}
297b9ceb
HG
84
85#endif /* _SG_SW_SEC4_H_ */