xref: /OK3568_Linux_fs/kernel/drivers/crypto/caam/caamalg_qi2.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2015-2016 Freescale Semiconductor Inc.
4*4882a593Smuzhiyun  * Copyright 2017-2018 NXP
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef _CAAMALG_QI2_H_
8*4882a593Smuzhiyun #define _CAAMALG_QI2_H_
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <soc/fsl/dpaa2-io.h>
11*4882a593Smuzhiyun #include <soc/fsl/dpaa2-fd.h>
12*4882a593Smuzhiyun #include <linux/threads.h>
13*4882a593Smuzhiyun #include <linux/netdevice.h>
14*4882a593Smuzhiyun #include "dpseci.h"
15*4882a593Smuzhiyun #include "desc_constr.h"
16*4882a593Smuzhiyun #include <crypto/skcipher.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define DPAA2_CAAM_STORE_SIZE	16
19*4882a593Smuzhiyun /* NAPI weight *must* be a multiple of the store size. */
20*4882a593Smuzhiyun #define DPAA2_CAAM_NAPI_WEIGHT	512
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* The congestion entrance threshold was chosen so that on LS2088
23*4882a593Smuzhiyun  * we support the maximum throughput for the available memory
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun #define DPAA2_SEC_CONG_ENTRY_THRESH	(128 * 1024 * 1024)
26*4882a593Smuzhiyun #define DPAA2_SEC_CONG_EXIT_THRESH	(DPAA2_SEC_CONG_ENTRY_THRESH * 9 / 10)
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /**
29*4882a593Smuzhiyun  * dpaa2_caam_priv - driver private data
30*4882a593Smuzhiyun  * @dpseci_id: DPSECI object unique ID
31*4882a593Smuzhiyun  * @major_ver: DPSECI major version
32*4882a593Smuzhiyun  * @minor_ver: DPSECI minor version
33*4882a593Smuzhiyun  * @dpseci_attr: DPSECI attributes
34*4882a593Smuzhiyun  * @sec_attr: SEC engine attributes
35*4882a593Smuzhiyun  * @rx_queue_attr: array of Rx queue attributes
36*4882a593Smuzhiyun  * @tx_queue_attr: array of Tx queue attributes
37*4882a593Smuzhiyun  * @cscn_mem: pointer to memory region containing the congestion SCN
38*4882a593Smuzhiyun  *	it's size is larger than to accommodate alignment
39*4882a593Smuzhiyun  * @cscn_mem_aligned: pointer to congestion SCN; it is computed as
40*4882a593Smuzhiyun  *	PTR_ALIGN(cscn_mem, DPAA2_CSCN_ALIGN)
41*4882a593Smuzhiyun  * @cscn_dma: dma address used by the QMAN to write CSCN messages
42*4882a593Smuzhiyun  * @dev: device associated with the DPSECI object
43*4882a593Smuzhiyun  * @mc_io: pointer to MC portal's I/O object
44*4882a593Smuzhiyun  * @domain: IOMMU domain
45*4882a593Smuzhiyun  * @ppriv: per CPU pointers to privata data
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun struct dpaa2_caam_priv {
48*4882a593Smuzhiyun 	int dpsec_id;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	u16 major_ver;
51*4882a593Smuzhiyun 	u16 minor_ver;
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	struct dpseci_attr dpseci_attr;
54*4882a593Smuzhiyun 	struct dpseci_sec_attr sec_attr;
55*4882a593Smuzhiyun 	struct dpseci_rx_queue_attr rx_queue_attr[DPSECI_MAX_QUEUE_NUM];
56*4882a593Smuzhiyun 	struct dpseci_tx_queue_attr tx_queue_attr[DPSECI_MAX_QUEUE_NUM];
57*4882a593Smuzhiyun 	int num_pairs;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	/* congestion */
60*4882a593Smuzhiyun 	void *cscn_mem;
61*4882a593Smuzhiyun 	void *cscn_mem_aligned;
62*4882a593Smuzhiyun 	dma_addr_t cscn_dma;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	struct device *dev;
65*4882a593Smuzhiyun 	struct fsl_mc_io *mc_io;
66*4882a593Smuzhiyun 	struct iommu_domain *domain;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	struct dpaa2_caam_priv_per_cpu __percpu *ppriv;
69*4882a593Smuzhiyun 	struct dentry *dfs_root;
70*4882a593Smuzhiyun };
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun  * dpaa2_caam_priv_per_cpu - per CPU private data
74*4882a593Smuzhiyun  * @napi: napi structure
75*4882a593Smuzhiyun  * @net_dev: netdev used by napi
76*4882a593Smuzhiyun  * @req_fqid: (virtual) request (Tx / enqueue) FQID
77*4882a593Smuzhiyun  * @rsp_fqid: (virtual) response (Rx / dequeue) FQID
78*4882a593Smuzhiyun  * @prio: internal queue number - index for dpaa2_caam_priv.*_queue_attr
79*4882a593Smuzhiyun  * @nctx: notification context of response FQ
80*4882a593Smuzhiyun  * @store: where dequeued frames are stored
81*4882a593Smuzhiyun  * @priv: backpointer to dpaa2_caam_priv
82*4882a593Smuzhiyun  * @dpio: portal used for data path operations
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun struct dpaa2_caam_priv_per_cpu {
85*4882a593Smuzhiyun 	struct napi_struct napi;
86*4882a593Smuzhiyun 	struct net_device net_dev;
87*4882a593Smuzhiyun 	int req_fqid;
88*4882a593Smuzhiyun 	int rsp_fqid;
89*4882a593Smuzhiyun 	int prio;
90*4882a593Smuzhiyun 	struct dpaa2_io_notification_ctx nctx;
91*4882a593Smuzhiyun 	struct dpaa2_io_store *store;
92*4882a593Smuzhiyun 	struct dpaa2_caam_priv *priv;
93*4882a593Smuzhiyun 	struct dpaa2_io *dpio;
94*4882a593Smuzhiyun };
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /* Length of a single buffer in the QI driver memory cache */
97*4882a593Smuzhiyun #define CAAM_QI_MEMCACHE_SIZE	512
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun  * aead_edesc - s/w-extended aead descriptor
101*4882a593Smuzhiyun  * @src_nents: number of segments in input scatterlist
102*4882a593Smuzhiyun  * @dst_nents: number of segments in output scatterlist
103*4882a593Smuzhiyun  * @iv_dma: dma address of iv for checking continuity and link table
104*4882a593Smuzhiyun  * @qm_sg_bytes: length of dma mapped h/w link table
105*4882a593Smuzhiyun  * @qm_sg_dma: bus physical mapped address of h/w link table
106*4882a593Smuzhiyun  * @assoclen: associated data length, in CAAM endianness
107*4882a593Smuzhiyun  * @assoclen_dma: bus physical mapped address of req->assoclen
108*4882a593Smuzhiyun  * @sgt: the h/w link table, followed by IV
109*4882a593Smuzhiyun  */
110*4882a593Smuzhiyun struct aead_edesc {
111*4882a593Smuzhiyun 	int src_nents;
112*4882a593Smuzhiyun 	int dst_nents;
113*4882a593Smuzhiyun 	dma_addr_t iv_dma;
114*4882a593Smuzhiyun 	int qm_sg_bytes;
115*4882a593Smuzhiyun 	dma_addr_t qm_sg_dma;
116*4882a593Smuzhiyun 	unsigned int assoclen;
117*4882a593Smuzhiyun 	dma_addr_t assoclen_dma;
118*4882a593Smuzhiyun 	struct dpaa2_sg_entry sgt[];
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /*
122*4882a593Smuzhiyun  * skcipher_edesc - s/w-extended skcipher descriptor
123*4882a593Smuzhiyun  * @src_nents: number of segments in input scatterlist
124*4882a593Smuzhiyun  * @dst_nents: number of segments in output scatterlist
125*4882a593Smuzhiyun  * @iv_dma: dma address of iv for checking continuity and link table
126*4882a593Smuzhiyun  * @qm_sg_bytes: length of dma mapped qm_sg space
127*4882a593Smuzhiyun  * @qm_sg_dma: I/O virtual address of h/w link table
128*4882a593Smuzhiyun  * @sgt: the h/w link table, followed by IV
129*4882a593Smuzhiyun  */
130*4882a593Smuzhiyun struct skcipher_edesc {
131*4882a593Smuzhiyun 	int src_nents;
132*4882a593Smuzhiyun 	int dst_nents;
133*4882a593Smuzhiyun 	dma_addr_t iv_dma;
134*4882a593Smuzhiyun 	int qm_sg_bytes;
135*4882a593Smuzhiyun 	dma_addr_t qm_sg_dma;
136*4882a593Smuzhiyun 	struct dpaa2_sg_entry sgt[];
137*4882a593Smuzhiyun };
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /*
140*4882a593Smuzhiyun  * ahash_edesc - s/w-extended ahash descriptor
141*4882a593Smuzhiyun  * @qm_sg_dma: I/O virtual address of h/w link table
142*4882a593Smuzhiyun  * @src_nents: number of segments in input scatterlist
143*4882a593Smuzhiyun  * @qm_sg_bytes: length of dma mapped qm_sg space
144*4882a593Smuzhiyun  * @sgt: pointer to h/w link table
145*4882a593Smuzhiyun  */
146*4882a593Smuzhiyun struct ahash_edesc {
147*4882a593Smuzhiyun 	dma_addr_t qm_sg_dma;
148*4882a593Smuzhiyun 	int src_nents;
149*4882a593Smuzhiyun 	int qm_sg_bytes;
150*4882a593Smuzhiyun 	struct dpaa2_sg_entry sgt[];
151*4882a593Smuzhiyun };
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /**
154*4882a593Smuzhiyun  * caam_flc - Flow Context (FLC)
155*4882a593Smuzhiyun  * @flc: Flow Context options
156*4882a593Smuzhiyun  * @sh_desc: Shared Descriptor
157*4882a593Smuzhiyun  */
158*4882a593Smuzhiyun struct caam_flc {
159*4882a593Smuzhiyun 	u32 flc[16];
160*4882a593Smuzhiyun 	u32 sh_desc[MAX_SDLEN];
161*4882a593Smuzhiyun } ____cacheline_aligned;
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun enum optype {
164*4882a593Smuzhiyun 	ENCRYPT = 0,
165*4882a593Smuzhiyun 	DECRYPT,
166*4882a593Smuzhiyun 	NUM_OP
167*4882a593Smuzhiyun };
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /**
170*4882a593Smuzhiyun  * caam_request - the request structure the driver application should fill while
171*4882a593Smuzhiyun  *                submitting a job to driver.
172*4882a593Smuzhiyun  * @fd_flt: Frame list table defining input and output
173*4882a593Smuzhiyun  *          fd_flt[0] - FLE pointing to output buffer
174*4882a593Smuzhiyun  *          fd_flt[1] - FLE pointing to input buffer
175*4882a593Smuzhiyun  * @fd_flt_dma: DMA address for the frame list table
176*4882a593Smuzhiyun  * @flc: Flow Context
177*4882a593Smuzhiyun  * @flc_dma: I/O virtual address of Flow Context
178*4882a593Smuzhiyun  * @cbk: Callback function to invoke when job is completed
179*4882a593Smuzhiyun  * @ctx: arbit context attached with request by the application
180*4882a593Smuzhiyun  * @edesc: extended descriptor; points to one of {skcipher,aead}_edesc
181*4882a593Smuzhiyun  */
182*4882a593Smuzhiyun struct caam_request {
183*4882a593Smuzhiyun 	struct dpaa2_fl_entry fd_flt[2];
184*4882a593Smuzhiyun 	dma_addr_t fd_flt_dma;
185*4882a593Smuzhiyun 	struct caam_flc *flc;
186*4882a593Smuzhiyun 	dma_addr_t flc_dma;
187*4882a593Smuzhiyun 	void (*cbk)(void *ctx, u32 err);
188*4882a593Smuzhiyun 	void *ctx;
189*4882a593Smuzhiyun 	void *edesc;
190*4882a593Smuzhiyun 	struct skcipher_request fallback_req;
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun /**
194*4882a593Smuzhiyun  * dpaa2_caam_enqueue() - enqueue a crypto request
195*4882a593Smuzhiyun  * @dev: device associated with the DPSECI object
196*4882a593Smuzhiyun  * @req: pointer to caam_request
197*4882a593Smuzhiyun  */
198*4882a593Smuzhiyun int dpaa2_caam_enqueue(struct device *dev, struct caam_request *req);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun #endif	/* _CAAMALG_QI2_H_ */
201