18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CAAM/SEC 4.x functions for using scatterlists in caam driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2008-2011 Freescale Semiconductor, Inc. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _SG_SW_SEC4_H_ 108c2ecf20Sopenharmony_ci#define _SG_SW_SEC4_H_ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include "ctrl.h" 138c2ecf20Sopenharmony_ci#include "regs.h" 148c2ecf20Sopenharmony_ci#include "sg_sw_qm2.h" 158c2ecf20Sopenharmony_ci#include <soc/fsl/dpaa2-fd.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistruct sec4_sg_entry { 188c2ecf20Sopenharmony_ci u64 ptr; 198c2ecf20Sopenharmony_ci u32 len; 208c2ecf20Sopenharmony_ci u32 bpid_offset; 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci/* 248c2ecf20Sopenharmony_ci * convert single dma address to h/w link table format 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_cistatic inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr, 278c2ecf20Sopenharmony_ci dma_addr_t dma, u32 len, u16 offset) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci if (caam_dpaa2) { 308c2ecf20Sopenharmony_ci dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len, 318c2ecf20Sopenharmony_ci offset); 328c2ecf20Sopenharmony_ci } else { 338c2ecf20Sopenharmony_ci sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma); 348c2ecf20Sopenharmony_ci sec4_sg_ptr->len = cpu_to_caam32(len); 358c2ecf20Sopenharmony_ci sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset & 368c2ecf20Sopenharmony_ci SEC4_SG_OFFSET_MASK); 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci print_hex_dump_debug("sec4_sg_ptr@: ", DUMP_PREFIX_ADDRESS, 16, 4, 408c2ecf20Sopenharmony_ci sec4_sg_ptr, sizeof(struct sec4_sg_entry), 1); 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * convert scatterlist to h/w link table format 458c2ecf20Sopenharmony_ci * but does not have final bit; instead, returns last entry 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cistatic inline struct sec4_sg_entry * 488c2ecf20Sopenharmony_cisg_to_sec4_sg(struct scatterlist *sg, int len, 498c2ecf20Sopenharmony_ci struct sec4_sg_entry *sec4_sg_ptr, u16 offset) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci int ent_len; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci while (len) { 548c2ecf20Sopenharmony_ci ent_len = min_t(int, sg_dma_len(sg), len); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), ent_len, 578c2ecf20Sopenharmony_ci offset); 588c2ecf20Sopenharmony_ci sec4_sg_ptr++; 598c2ecf20Sopenharmony_ci sg = sg_next(sg); 608c2ecf20Sopenharmony_ci len -= ent_len; 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci return sec4_sg_ptr - 1; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci if (caam_dpaa2) 688c2ecf20Sopenharmony_ci dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true); 698c2ecf20Sopenharmony_ci else 708c2ecf20Sopenharmony_ci sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* 748c2ecf20Sopenharmony_ci * convert scatterlist to h/w link table format 758c2ecf20Sopenharmony_ci * scatterlist must have been previously dma mapped 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistatic inline void sg_to_sec4_sg_last(struct scatterlist *sg, int len, 788c2ecf20Sopenharmony_ci struct sec4_sg_entry *sec4_sg_ptr, 798c2ecf20Sopenharmony_ci u16 offset) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci sec4_sg_ptr = sg_to_sec4_sg(sg, len, sec4_sg_ptr, offset); 828c2ecf20Sopenharmony_ci sg_to_sec4_set_last(sec4_sg_ptr); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#endif /* _SG_SW_SEC4_H_ */ 86