162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * CAAM/SEC 4.x functions for using scatterlists in caam driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright 2008-2011 Freescale Semiconductor, Inc. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifndef _SG_SW_SEC4_H_ 1062306a36Sopenharmony_ci#define _SG_SW_SEC4_H_ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include "ctrl.h" 1362306a36Sopenharmony_ci#include "regs.h" 1462306a36Sopenharmony_ci#include "sg_sw_qm2.h" 1562306a36Sopenharmony_ci#include <soc/fsl/dpaa2-fd.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct sec4_sg_entry { 1862306a36Sopenharmony_ci u64 ptr; 1962306a36Sopenharmony_ci u32 len; 2062306a36Sopenharmony_ci u32 bpid_offset; 2162306a36Sopenharmony_ci}; 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci/* 2462306a36Sopenharmony_ci * convert single dma address to h/w link table format 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_cistatic inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr, 2762306a36Sopenharmony_ci dma_addr_t dma, u32 len, u16 offset) 2862306a36Sopenharmony_ci{ 2962306a36Sopenharmony_ci if (caam_dpaa2) { 3062306a36Sopenharmony_ci dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len, 3162306a36Sopenharmony_ci offset); 3262306a36Sopenharmony_ci } else { 3362306a36Sopenharmony_ci sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma); 3462306a36Sopenharmony_ci sec4_sg_ptr->len = cpu_to_caam32(len); 3562306a36Sopenharmony_ci sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset & 3662306a36Sopenharmony_ci SEC4_SG_OFFSET_MASK); 3762306a36Sopenharmony_ci } 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci print_hex_dump_debug("sec4_sg_ptr@: ", DUMP_PREFIX_ADDRESS, 16, 4, 4062306a36Sopenharmony_ci sec4_sg_ptr, sizeof(struct sec4_sg_entry), 1); 4162306a36Sopenharmony_ci} 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* 4462306a36Sopenharmony_ci * convert scatterlist to h/w link table format 4562306a36Sopenharmony_ci * but does not have final bit; instead, returns last entry 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_cistatic inline struct sec4_sg_entry * 4862306a36Sopenharmony_cisg_to_sec4_sg(struct scatterlist *sg, int len, 4962306a36Sopenharmony_ci struct sec4_sg_entry *sec4_sg_ptr, u16 offset) 5062306a36Sopenharmony_ci{ 5162306a36Sopenharmony_ci int ent_len; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci while (len) { 5462306a36Sopenharmony_ci ent_len = min_t(int, sg_dma_len(sg), len); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), ent_len, 5762306a36Sopenharmony_ci offset); 5862306a36Sopenharmony_ci sec4_sg_ptr++; 5962306a36Sopenharmony_ci sg = sg_next(sg); 6062306a36Sopenharmony_ci len -= ent_len; 6162306a36Sopenharmony_ci } 6262306a36Sopenharmony_ci return sec4_sg_ptr - 1; 6362306a36Sopenharmony_ci} 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_cistatic inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr) 6662306a36Sopenharmony_ci{ 6762306a36Sopenharmony_ci if (caam_dpaa2) 6862306a36Sopenharmony_ci dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true); 6962306a36Sopenharmony_ci else 7062306a36Sopenharmony_ci sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN); 7162306a36Sopenharmony_ci} 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* 7462306a36Sopenharmony_ci * convert scatterlist to h/w link table format 7562306a36Sopenharmony_ci * scatterlist must have been previously dma mapped 7662306a36Sopenharmony_ci */ 7762306a36Sopenharmony_cistatic inline void sg_to_sec4_sg_last(struct scatterlist *sg, int len, 7862306a36Sopenharmony_ci struct sec4_sg_entry *sec4_sg_ptr, 7962306a36Sopenharmony_ci u16 offset) 8062306a36Sopenharmony_ci{ 8162306a36Sopenharmony_ci sec4_sg_ptr = sg_to_sec4_sg(sg, len, sec4_sg_ptr, offset); 8262306a36Sopenharmony_ci sg_to_sec4_set_last(sec4_sg_ptr); 8362306a36Sopenharmony_ci} 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci#endif /* _SG_SW_SEC4_H_ */ 86