Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * CAAM/SEC 4.x functions for using scatterlists in caam driver
0004  *
0005  * Copyright 2008-2011 Freescale Semiconductor, Inc.
0006  *
0007  */
0008 
0009 #ifndef _SG_SW_SEC4_H_
0010 #define _SG_SW_SEC4_H_
0011 
0012 #include "ctrl.h"
0013 #include "regs.h"
0014 #include "sg_sw_qm2.h"
0015 #include <soc/fsl/dpaa2-fd.h>
0016 
0017 struct sec4_sg_entry {
0018     u64 ptr;
0019     u32 len;
0020     u32 bpid_offset;
0021 };
0022 
0023 /*
0024  * convert single dma address to h/w link table format
0025  */
0026 static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
0027                       dma_addr_t dma, u32 len, u16 offset)
0028 {
0029     if (caam_dpaa2) {
0030         dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len,
0031                  offset);
0032     } else {
0033         sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
0034         sec4_sg_ptr->len = cpu_to_caam32(len);
0035         sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset &
0036                              SEC4_SG_OFFSET_MASK);
0037     }
0038 
0039     print_hex_dump_debug("sec4_sg_ptr@: ", DUMP_PREFIX_ADDRESS, 16, 4,
0040                  sec4_sg_ptr, sizeof(struct sec4_sg_entry), 1);
0041 }
0042 
0043 /*
0044  * convert scatterlist to h/w link table format
0045  * but does not have final bit; instead, returns last entry
0046  */
0047 static inline struct sec4_sg_entry *
0048 sg_to_sec4_sg(struct scatterlist *sg, int len,
0049           struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
0050 {
0051     int ent_len;
0052 
0053     while (len) {
0054         ent_len = min_t(int, sg_dma_len(sg), len);
0055 
0056         dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), ent_len,
0057                    offset);
0058         sec4_sg_ptr++;
0059         sg = sg_next(sg);
0060         len -= ent_len;
0061     }
0062     return sec4_sg_ptr - 1;
0063 }
0064 
0065 static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
0066 {
0067     if (caam_dpaa2)
0068         dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
0069     else
0070         sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
0071 }
0072 
0073 /*
0074  * convert scatterlist to h/w link table format
0075  * scatterlist must have been previously dma mapped
0076  */
0077 static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int len,
0078                       struct sec4_sg_entry *sec4_sg_ptr,
0079                       u16 offset)
0080 {
0081     sec4_sg_ptr = sg_to_sec4_sg(sg, len, sec4_sg_ptr, offset);
0082     sg_to_sec4_set_last(sec4_sg_ptr);
0083 }
0084 
0085 #endif /* _SG_SW_SEC4_H_ */