sg_sw_sec4.h 2.0 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
Y
Yuan Kang 已提交
2 3 4 5 6 7 8
/*
 * CAAM/SEC 4.x functions for using scatterlists in caam driver
 *
 * Copyright 2008-2011 Freescale Semiconductor, Inc.
 *
 */

9 10 11 12
#ifndef _SG_SW_SEC4_H_
#define _SG_SW_SEC4_H_

#include "ctrl.h"
13
#include "regs.h"
14
#include "sg_sw_qm2.h"
15
#include <soc/fsl/dpaa2-fd.h>
16

17 18 19 20 21
struct sec4_sg_entry {
	u64 ptr;
	u32 len;
	u32 bpid_offset;
};
Y
Yuan Kang 已提交
22 23 24 25

/*
 * convert single dma address to h/w link table format
 */
Y
Yuan Kang 已提交
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)
Y
Yuan Kang 已提交
28
{
29 30 31 32 33 34 35 36 37
	if (caam_dpaa2) {
		dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len,
				 offset);
	} else {
		sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
		sec4_sg_ptr->len = cpu_to_caam32(len);
		sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset &
							 SEC4_SG_OFFSET_MASK);
	}
Y
Yuan Kang 已提交
38
#ifdef DEBUG
Y
Yuan Kang 已提交
39 40 41
	print_hex_dump(KERN_ERR, "sec4_sg_ptr@: ",
		       DUMP_PREFIX_ADDRESS, 16, 4, sec4_sg_ptr,
		       sizeof(struct sec4_sg_entry), 1);
Y
Yuan Kang 已提交
42 43 44 45 46 47 48
#endif
}

/*
 * convert scatterlist to h/w link table format
 * but does not have final bit; instead, returns last entry
 */
Y
Yuan Kang 已提交
49 50
static inline struct sec4_sg_entry *
sg_to_sec4_sg(struct scatterlist *sg, int sg_count,
51
	      struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
Y
Yuan Kang 已提交
52 53
{
	while (sg_count) {
Y
Yuan Kang 已提交
54
		dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg),
Y
Yuan Kang 已提交
55
				   sg_dma_len(sg), offset);
Y
Yuan Kang 已提交
56
		sec4_sg_ptr++;
57
		sg = sg_next(sg);
Y
Yuan Kang 已提交
58 59
		sg_count--;
	}
Y
Yuan Kang 已提交
60
	return sec4_sg_ptr - 1;
Y
Yuan Kang 已提交
61 62
}

63 64 65 66 67 68 69 70
static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
{
	if (caam_dpaa2)
		dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
	else
		sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
}

Y
Yuan Kang 已提交
71 72 73 74
/*
 * convert scatterlist to h/w link table format
 * scatterlist must have been previously dma mapped
 */
Y
Yuan Kang 已提交
75 76
static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
				      struct sec4_sg_entry *sec4_sg_ptr,
77
				      u16 offset)
Y
Yuan Kang 已提交
78
{
Y
Yuan Kang 已提交
79
	sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
80
	sg_to_sec4_set_last(sec4_sg_ptr);
Y
Yuan Kang 已提交
81
}
82 83

#endif /* _SG_SW_SEC4_H_ */