18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright 2015-2016 Freescale Semiconductor Inc. 48c2ecf20Sopenharmony_ci * Copyright 2017-2018 NXP 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef _CAAMALG_QI2_H_ 88c2ecf20Sopenharmony_ci#define _CAAMALG_QI2_H_ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <soc/fsl/dpaa2-io.h> 118c2ecf20Sopenharmony_ci#include <soc/fsl/dpaa2-fd.h> 128c2ecf20Sopenharmony_ci#include <linux/threads.h> 138c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 148c2ecf20Sopenharmony_ci#include "dpseci.h" 158c2ecf20Sopenharmony_ci#include "desc_constr.h" 168c2ecf20Sopenharmony_ci#include <crypto/skcipher.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define DPAA2_CAAM_STORE_SIZE 16 198c2ecf20Sopenharmony_ci/* NAPI weight *must* be a multiple of the store size. */ 208c2ecf20Sopenharmony_ci#define DPAA2_CAAM_NAPI_WEIGHT 512 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* The congestion entrance threshold was chosen so that on LS2088 238c2ecf20Sopenharmony_ci * we support the maximum throughput for the available memory 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci#define DPAA2_SEC_CONG_ENTRY_THRESH (128 * 1024 * 1024) 268c2ecf20Sopenharmony_ci#define DPAA2_SEC_CONG_EXIT_THRESH (DPAA2_SEC_CONG_ENTRY_THRESH * 9 / 10) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/** 298c2ecf20Sopenharmony_ci * dpaa2_caam_priv - driver private data 308c2ecf20Sopenharmony_ci * @dpseci_id: DPSECI object unique ID 318c2ecf20Sopenharmony_ci * @major_ver: DPSECI major version 328c2ecf20Sopenharmony_ci * @minor_ver: DPSECI minor version 338c2ecf20Sopenharmony_ci * @dpseci_attr: DPSECI attributes 348c2ecf20Sopenharmony_ci * @sec_attr: SEC engine attributes 358c2ecf20Sopenharmony_ci * @rx_queue_attr: array of Rx queue attributes 368c2ecf20Sopenharmony_ci * @tx_queue_attr: array of Tx queue attributes 378c2ecf20Sopenharmony_ci * @cscn_mem: pointer to memory region containing the congestion SCN 388c2ecf20Sopenharmony_ci * it's size is larger than to accommodate alignment 398c2ecf20Sopenharmony_ci * @cscn_mem_aligned: pointer to congestion SCN; it is computed as 408c2ecf20Sopenharmony_ci * PTR_ALIGN(cscn_mem, DPAA2_CSCN_ALIGN) 418c2ecf20Sopenharmony_ci * @cscn_dma: dma address used by the QMAN to write CSCN messages 428c2ecf20Sopenharmony_ci * @dev: device associated with the DPSECI object 438c2ecf20Sopenharmony_ci * @mc_io: pointer to MC portal's I/O object 448c2ecf20Sopenharmony_ci * @domain: IOMMU domain 458c2ecf20Sopenharmony_ci * @ppriv: per CPU pointers to privata data 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cistruct dpaa2_caam_priv { 488c2ecf20Sopenharmony_ci int dpsec_id; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci u16 major_ver; 518c2ecf20Sopenharmony_ci u16 minor_ver; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci struct dpseci_attr dpseci_attr; 548c2ecf20Sopenharmony_ci struct dpseci_sec_attr sec_attr; 558c2ecf20Sopenharmony_ci struct dpseci_rx_queue_attr rx_queue_attr[DPSECI_MAX_QUEUE_NUM]; 568c2ecf20Sopenharmony_ci struct dpseci_tx_queue_attr tx_queue_attr[DPSECI_MAX_QUEUE_NUM]; 578c2ecf20Sopenharmony_ci int num_pairs; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* congestion */ 608c2ecf20Sopenharmony_ci void *cscn_mem; 618c2ecf20Sopenharmony_ci void *cscn_mem_aligned; 628c2ecf20Sopenharmony_ci dma_addr_t cscn_dma; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci struct device *dev; 658c2ecf20Sopenharmony_ci struct fsl_mc_io *mc_io; 668c2ecf20Sopenharmony_ci struct iommu_domain *domain; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci struct dpaa2_caam_priv_per_cpu __percpu *ppriv; 698c2ecf20Sopenharmony_ci struct dentry *dfs_root; 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/** 738c2ecf20Sopenharmony_ci * dpaa2_caam_priv_per_cpu - per CPU private data 748c2ecf20Sopenharmony_ci * @napi: napi structure 758c2ecf20Sopenharmony_ci * @net_dev: netdev used by napi 768c2ecf20Sopenharmony_ci * @req_fqid: (virtual) request (Tx / enqueue) FQID 778c2ecf20Sopenharmony_ci * @rsp_fqid: (virtual) response (Rx / dequeue) FQID 788c2ecf20Sopenharmony_ci * @prio: internal queue number - index for dpaa2_caam_priv.*_queue_attr 798c2ecf20Sopenharmony_ci * @nctx: notification context of response FQ 808c2ecf20Sopenharmony_ci * @store: where dequeued frames are stored 818c2ecf20Sopenharmony_ci * @priv: backpointer to dpaa2_caam_priv 828c2ecf20Sopenharmony_ci * @dpio: portal used for data path operations 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_cistruct dpaa2_caam_priv_per_cpu { 858c2ecf20Sopenharmony_ci struct napi_struct napi; 868c2ecf20Sopenharmony_ci struct net_device net_dev; 878c2ecf20Sopenharmony_ci int req_fqid; 888c2ecf20Sopenharmony_ci int rsp_fqid; 898c2ecf20Sopenharmony_ci int prio; 908c2ecf20Sopenharmony_ci struct dpaa2_io_notification_ctx nctx; 918c2ecf20Sopenharmony_ci struct dpaa2_io_store *store; 928c2ecf20Sopenharmony_ci struct dpaa2_caam_priv *priv; 938c2ecf20Sopenharmony_ci struct dpaa2_io *dpio; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* Length of a single buffer in the QI driver memory cache */ 978c2ecf20Sopenharmony_ci#define CAAM_QI_MEMCACHE_SIZE 512 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* 1008c2ecf20Sopenharmony_ci * aead_edesc - s/w-extended aead descriptor 1018c2ecf20Sopenharmony_ci * @src_nents: number of segments in input scatterlist 1028c2ecf20Sopenharmony_ci * @dst_nents: number of segments in output scatterlist 1038c2ecf20Sopenharmony_ci * @iv_dma: dma address of iv for checking continuity and link table 1048c2ecf20Sopenharmony_ci * @qm_sg_bytes: length of dma mapped h/w link table 1058c2ecf20Sopenharmony_ci * @qm_sg_dma: bus physical mapped address of h/w link table 1068c2ecf20Sopenharmony_ci * @assoclen: associated data length, in CAAM endianness 1078c2ecf20Sopenharmony_ci * @assoclen_dma: bus physical mapped address of req->assoclen 1088c2ecf20Sopenharmony_ci * @sgt: the h/w link table, followed by IV 1098c2ecf20Sopenharmony_ci */ 1108c2ecf20Sopenharmony_cistruct aead_edesc { 1118c2ecf20Sopenharmony_ci int src_nents; 1128c2ecf20Sopenharmony_ci int dst_nents; 1138c2ecf20Sopenharmony_ci dma_addr_t iv_dma; 1148c2ecf20Sopenharmony_ci int qm_sg_bytes; 1158c2ecf20Sopenharmony_ci dma_addr_t qm_sg_dma; 1168c2ecf20Sopenharmony_ci unsigned int assoclen; 1178c2ecf20Sopenharmony_ci dma_addr_t assoclen_dma; 1188c2ecf20Sopenharmony_ci struct dpaa2_sg_entry sgt[]; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* 1228c2ecf20Sopenharmony_ci * skcipher_edesc - s/w-extended skcipher descriptor 1238c2ecf20Sopenharmony_ci * @src_nents: number of segments in input scatterlist 1248c2ecf20Sopenharmony_ci * @dst_nents: number of segments in output scatterlist 1258c2ecf20Sopenharmony_ci * @iv_dma: dma address of iv for checking continuity and link table 1268c2ecf20Sopenharmony_ci * @qm_sg_bytes: length of dma mapped qm_sg space 1278c2ecf20Sopenharmony_ci * @qm_sg_dma: I/O virtual address of h/w link table 1288c2ecf20Sopenharmony_ci * @sgt: the h/w link table, followed by IV 1298c2ecf20Sopenharmony_ci */ 1308c2ecf20Sopenharmony_cistruct skcipher_edesc { 1318c2ecf20Sopenharmony_ci int src_nents; 1328c2ecf20Sopenharmony_ci int dst_nents; 1338c2ecf20Sopenharmony_ci dma_addr_t iv_dma; 1348c2ecf20Sopenharmony_ci int qm_sg_bytes; 1358c2ecf20Sopenharmony_ci dma_addr_t qm_sg_dma; 1368c2ecf20Sopenharmony_ci struct dpaa2_sg_entry sgt[]; 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* 1408c2ecf20Sopenharmony_ci * ahash_edesc - s/w-extended ahash descriptor 1418c2ecf20Sopenharmony_ci * @qm_sg_dma: I/O virtual address of h/w link table 1428c2ecf20Sopenharmony_ci * @src_nents: number of segments in input scatterlist 1438c2ecf20Sopenharmony_ci * @qm_sg_bytes: length of dma mapped qm_sg space 1448c2ecf20Sopenharmony_ci * @sgt: pointer to h/w link table 1458c2ecf20Sopenharmony_ci */ 1468c2ecf20Sopenharmony_cistruct ahash_edesc { 1478c2ecf20Sopenharmony_ci dma_addr_t qm_sg_dma; 1488c2ecf20Sopenharmony_ci int src_nents; 1498c2ecf20Sopenharmony_ci int qm_sg_bytes; 1508c2ecf20Sopenharmony_ci struct dpaa2_sg_entry sgt[]; 1518c2ecf20Sopenharmony_ci}; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/** 1548c2ecf20Sopenharmony_ci * caam_flc - Flow Context (FLC) 1558c2ecf20Sopenharmony_ci * @flc: Flow Context options 1568c2ecf20Sopenharmony_ci * @sh_desc: Shared Descriptor 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_cistruct caam_flc { 1598c2ecf20Sopenharmony_ci u32 flc[16]; 1608c2ecf20Sopenharmony_ci u32 sh_desc[MAX_SDLEN]; 1618c2ecf20Sopenharmony_ci} ____cacheline_aligned; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cienum optype { 1648c2ecf20Sopenharmony_ci ENCRYPT = 0, 1658c2ecf20Sopenharmony_ci DECRYPT, 1668c2ecf20Sopenharmony_ci NUM_OP 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci/** 1708c2ecf20Sopenharmony_ci * caam_request - the request structure the driver application should fill while 1718c2ecf20Sopenharmony_ci * submitting a job to driver. 1728c2ecf20Sopenharmony_ci * @fd_flt: Frame list table defining input and output 1738c2ecf20Sopenharmony_ci * fd_flt[0] - FLE pointing to output buffer 1748c2ecf20Sopenharmony_ci * fd_flt[1] - FLE pointing to input buffer 1758c2ecf20Sopenharmony_ci * @fd_flt_dma: DMA address for the frame list table 1768c2ecf20Sopenharmony_ci * @flc: Flow Context 1778c2ecf20Sopenharmony_ci * @flc_dma: I/O virtual address of Flow Context 1788c2ecf20Sopenharmony_ci * @cbk: Callback function to invoke when job is completed 1798c2ecf20Sopenharmony_ci * @ctx: arbit context attached with request by the application 1808c2ecf20Sopenharmony_ci * @edesc: extended descriptor; points to one of {skcipher,aead}_edesc 1818c2ecf20Sopenharmony_ci */ 1828c2ecf20Sopenharmony_cistruct caam_request { 1838c2ecf20Sopenharmony_ci struct dpaa2_fl_entry fd_flt[2]; 1848c2ecf20Sopenharmony_ci dma_addr_t fd_flt_dma; 1858c2ecf20Sopenharmony_ci struct caam_flc *flc; 1868c2ecf20Sopenharmony_ci dma_addr_t flc_dma; 1878c2ecf20Sopenharmony_ci void (*cbk)(void *ctx, u32 err); 1888c2ecf20Sopenharmony_ci void *ctx; 1898c2ecf20Sopenharmony_ci void *edesc; 1908c2ecf20Sopenharmony_ci struct skcipher_request fallback_req; 1918c2ecf20Sopenharmony_ci}; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci/** 1948c2ecf20Sopenharmony_ci * dpaa2_caam_enqueue() - enqueue a crypto request 1958c2ecf20Sopenharmony_ci * @dev: device associated with the DPSECI object 1968c2ecf20Sopenharmony_ci * @req: pointer to caam_request 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_ciint dpaa2_caam_enqueue(struct device *dev, struct caam_request *req); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci#endif /* _CAAMALG_QI2_H_ */ 201