936b1b63005815a2eff3d7541d72043ae4707aca
[sfrench/cifs-2.6.git] / drivers / crypto / caam / sg_sw_sec4.h
1 /*
2  * CAAM/SEC 4.x functions for using scatterlists in caam driver
3  *
4  * Copyright 2008-2011 Freescale Semiconductor, Inc.
5  *
6  */
7
8 #ifndef _SG_SW_SEC4_H_
9 #define _SG_SW_SEC4_H_
10
11 #include "ctrl.h"
12 #include "regs.h"
13 #include "sg_sw_qm2.h"
14 #include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
15
16 struct sec4_sg_entry {
17         u64 ptr;
18         u32 len;
19         u32 bpid_offset;
20 };
21
22 /*
23  * convert single dma address to h/w link table format
24  */
25 static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
26                                       dma_addr_t dma, u32 len, u16 offset)
27 {
28         if (caam_dpaa2) {
29                 dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len,
30                                  offset);
31         } else {
32                 sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
33                 sec4_sg_ptr->len = cpu_to_caam32(len);
34                 sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset &
35                                                          SEC4_SG_OFFSET_MASK);
36         }
37 #ifdef DEBUG
38         print_hex_dump(KERN_ERR, "sec4_sg_ptr@: ",
39                        DUMP_PREFIX_ADDRESS, 16, 4, sec4_sg_ptr,
40                        sizeof(struct sec4_sg_entry), 1);
41 #endif
42 }
43
44 /*
45  * convert scatterlist to h/w link table format
46  * but does not have final bit; instead, returns last entry
47  */
48 static inline struct sec4_sg_entry *
49 sg_to_sec4_sg(struct scatterlist *sg, int sg_count,
50               struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
51 {
52         while (sg_count) {
53                 dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg),
54                                    sg_dma_len(sg), offset);
55                 sec4_sg_ptr++;
56                 sg = sg_next(sg);
57                 sg_count--;
58         }
59         return sec4_sg_ptr - 1;
60 }
61
62 static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
63 {
64         if (caam_dpaa2)
65                 dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
66         else
67                 sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
68 }
69
70 /*
71  * convert scatterlist to h/w link table format
72  * scatterlist must have been previously dma mapped
73  */
74 static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
75                                       struct sec4_sg_entry *sec4_sg_ptr,
76                                       u16 offset)
77 {
78         sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
79         sg_to_sec4_set_last(sec4_sg_ptr);
80 }
81
82 #endif /* _SG_SW_SEC4_H_ */