blob: e586ffab83585a60e40c6b55206945abc5067ac4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Yuan Kanga299c832012-06-22 19:48:46 -05002/*
3 * CAAM/SEC 4.x functions for using scatterlists in caam driver
4 *
5 * Copyright 2008-2011 Freescale Semiconductor, Inc.
6 *
7 */
8
Horia Geantă297b9ce2017-07-18 18:30:47 +03009#ifndef _SG_SW_SEC4_H_
10#define _SG_SW_SEC4_H_
11
12#include "ctrl.h"
Horia Geantă261ea052016-05-19 18:11:26 +030013#include "regs.h"
Horia Geantă297b9ce2017-07-18 18:30:47 +030014#include "sg_sw_qm2.h"
15#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
Horia Geantă261ea052016-05-19 18:11:26 +030016
Horia Geantăe25ff922016-11-09 10:46:22 +020017struct sec4_sg_entry {
18 u64 ptr;
19 u32 len;
20 u32 bpid_offset;
21};
Yuan Kanga299c832012-06-22 19:48:46 -050022
23/*
24 * convert single dma address to h/w link table format
25 */
26static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
Cristian Stoicabd52f1c2016-05-19 18:11:18 +030027 dma_addr_t dma, u32 len, u16 offset)
Yuan Kanga299c832012-06-22 19:48:46 -050028{
Horia Geantă297b9ce2017-07-18 18:30:47 +030029 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 }
Yuan Kanga299c832012-06-22 19:48:46 -050038#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
43}
44
45/*
46 * convert scatterlist to h/w link table format
47 * but does not have final bit; instead, returns last entry
48 */
49static inline struct sec4_sg_entry *
50sg_to_sec4_sg(struct scatterlist *sg, int sg_count,
Cristian Stoicabd52f1c2016-05-19 18:11:18 +030051 struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
Yuan Kanga299c832012-06-22 19:48:46 -050052{
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++;
Cristian Stoica5be4d4c2015-01-20 10:06:16 +020057 sg = sg_next(sg);
Yuan Kanga299c832012-06-22 19:48:46 -050058 sg_count--;
59 }
60 return sec4_sg_ptr - 1;
61}
62
Horia Geantă297b9ce2017-07-18 18:30:47 +030063static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
64{
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);
69}
70
Yuan Kanga299c832012-06-22 19:48:46 -050071/*
72 * convert scatterlist to h/w link table format
73 * scatterlist must have been previously dma mapped
74 */
75static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
76 struct sec4_sg_entry *sec4_sg_ptr,
Cristian Stoicabd52f1c2016-05-19 18:11:18 +030077 u16 offset)
Yuan Kanga299c832012-06-22 19:48:46 -050078{
79 sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
Horia Geantă297b9ce2017-07-18 18:30:47 +030080 sg_to_sec4_set_last(sec4_sg_ptr);
Yuan Kanga299c832012-06-22 19:48:46 -050081}
Horia Geantă297b9ce2017-07-18 18:30:47 +030082
83#endif /* _SG_SW_SEC4_H_ */