xref: /dpdk/drivers/crypto/dpaa_sec/dpaa_sec.c (revision f6ab96f13d7a23b39fb5135b64ed8e99c425c7a9)
1d81734caSHemant Agrawal /* SPDX-License-Identifier: BSD-3-Clause
2c3e85bdcSAkhil Goyal  *
3c3e85bdcSAkhil Goyal  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4e621d970SAkhil Goyal  *   Copyright 2017-2019 NXP
5c3e85bdcSAkhil Goyal  *
6c3e85bdcSAkhil Goyal  */
7c3e85bdcSAkhil Goyal 
8c3e85bdcSAkhil Goyal #include <fcntl.h>
9c3e85bdcSAkhil Goyal #include <unistd.h>
10c3e85bdcSAkhil Goyal #include <sched.h>
11c3e85bdcSAkhil Goyal #include <net/if.h>
12c3e85bdcSAkhil Goyal 
13c3e85bdcSAkhil Goyal #include <rte_byteorder.h>
14c3e85bdcSAkhil Goyal #include <rte_common.h>
15c3e85bdcSAkhil Goyal #include <rte_cryptodev_pmd.h>
16c3e85bdcSAkhil Goyal #include <rte_crypto.h>
17c3e85bdcSAkhil Goyal #include <rte_cryptodev.h>
18314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
191f14d500SAkhil Goyal #include <rte_security_driver.h>
20314424b6SHemant Agrawal #endif
21c3e85bdcSAkhil Goyal #include <rte_cycles.h>
22c3e85bdcSAkhil Goyal #include <rte_dev.h>
23c3e85bdcSAkhil Goyal #include <rte_kvargs.h>
24c3e85bdcSAkhil Goyal #include <rte_malloc.h>
25c3e85bdcSAkhil Goyal #include <rte_mbuf.h>
26c3e85bdcSAkhil Goyal #include <rte_memcpy.h>
27c3e85bdcSAkhil Goyal #include <rte_string_fns.h>
283b617ee7SAkhil Goyal #include <rte_spinlock.h>
29c3e85bdcSAkhil Goyal 
30c3e85bdcSAkhil Goyal #include <fsl_usd.h>
31c3e85bdcSAkhil Goyal #include <fsl_qman.h>
328c83f28cSHemant Agrawal #include <dpaa_of.h>
33c3e85bdcSAkhil Goyal 
34c3e85bdcSAkhil Goyal /* RTA header files */
35c0ded849SHemant Agrawal #include <desc/common.h>
36c0ded849SHemant Agrawal #include <desc/algo.h>
37c0ded849SHemant Agrawal #include <desc/ipsec.h>
38c0ded849SHemant Agrawal #include <desc/pdcp.h>
39c3e85bdcSAkhil Goyal 
40c3e85bdcSAkhil Goyal #include <rte_dpaa_bus.h>
41c3e85bdcSAkhil Goyal #include <dpaa_sec.h>
42fe3688baSAkhil Goyal #include <dpaa_sec_event.h>
43c3e85bdcSAkhil Goyal #include <dpaa_sec_log.h>
4412e58429SThierry Herbelot #include <dpaax_iova_table.h>
45c3e85bdcSAkhil Goyal 
46c3e85bdcSAkhil Goyal static uint8_t cryptodev_driver_id;
47c3e85bdcSAkhil Goyal 
48c3e85bdcSAkhil Goyal static __thread struct rte_crypto_op **dpaa_sec_ops;
49c3e85bdcSAkhil Goyal static __thread int dpaa_sec_op_nb;
50c3e85bdcSAkhil Goyal 
51e79416d1SHemant Agrawal static int
52e79416d1SHemant Agrawal dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess);
53e79416d1SHemant Agrawal 
54c3e85bdcSAkhil Goyal static inline void
55c3e85bdcSAkhil Goyal dpaa_sec_op_ending(struct dpaa_sec_op_ctx *ctx)
56c3e85bdcSAkhil Goyal {
57c3e85bdcSAkhil Goyal 	if (!ctx->fd_status) {
58c3e85bdcSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
59c3e85bdcSAkhil Goyal 	} else {
60f163231eSHemant Agrawal 		DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
61c3e85bdcSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
62c3e85bdcSAkhil Goyal 	}
63c3e85bdcSAkhil Goyal }
64c3e85bdcSAkhil Goyal 
65c3e85bdcSAkhil Goyal static inline struct dpaa_sec_op_ctx *
66f7a5752eSHemant Agrawal dpaa_sec_alloc_ctx(dpaa_sec_session *ses, int sg_count)
67c3e85bdcSAkhil Goyal {
68c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
69f7a5752eSHemant Agrawal 	int i, retval;
70c3e85bdcSAkhil Goyal 
712ffb940eSAkhil Goyal 	retval = rte_mempool_get(
722ffb940eSAkhil Goyal 			ses->qp[rte_lcore_id() % MAX_DPAA_CORES]->ctx_pool,
732ffb940eSAkhil Goyal 			(void **)(&ctx));
74c3e85bdcSAkhil Goyal 	if (!ctx || retval) {
75f163231eSHemant Agrawal 		DPAA_SEC_DP_WARN("Alloc sec descriptor failed!");
76c3e85bdcSAkhil Goyal 		return NULL;
77c3e85bdcSAkhil Goyal 	}
78c3e85bdcSAkhil Goyal 	/*
79c3e85bdcSAkhil Goyal 	 * Clear SG memory. There are 16 SG entries of 16 Bytes each.
80c3e85bdcSAkhil Goyal 	 * one call to dcbz_64() clear 64 bytes, hence calling it 4 times
81c3e85bdcSAkhil Goyal 	 * to clear all the SG entries. dpaa_sec_alloc_ctx() is called for
82c3e85bdcSAkhil Goyal 	 * each packet, memset is costlier than dcbz_64().
83c3e85bdcSAkhil Goyal 	 */
84f7a5752eSHemant Agrawal 	for (i = 0; i < sg_count && i < MAX_JOB_SG_ENTRIES; i += 4)
85f7a5752eSHemant Agrawal 		dcbz_64(&ctx->job.sg[i]);
86c3e85bdcSAkhil Goyal 
872ffb940eSAkhil Goyal 	ctx->ctx_pool = ses->qp[rte_lcore_id() % MAX_DPAA_CORES]->ctx_pool;
88f7a5752eSHemant Agrawal 	ctx->vtop_offset = (size_t) ctx - rte_mempool_virt2iova(ctx);
89c3e85bdcSAkhil Goyal 
90c3e85bdcSAkhil Goyal 	return ctx;
91c3e85bdcSAkhil Goyal }
92c3e85bdcSAkhil Goyal 
93c3e85bdcSAkhil Goyal static void
94c3e85bdcSAkhil Goyal ern_sec_fq_handler(struct qman_portal *qm __rte_unused,
95c3e85bdcSAkhil Goyal 		   struct qman_fq *fq,
96c3e85bdcSAkhil Goyal 		   const struct qm_mr_entry *msg)
97c3e85bdcSAkhil Goyal {
98f163231eSHemant Agrawal 	DPAA_SEC_DP_ERR("sec fq %d error, RC = %x, seqnum = %x\n",
99c3e85bdcSAkhil Goyal 			fq->fqid, msg->ern.rc, msg->ern.seqnum);
100c3e85bdcSAkhil Goyal }
101c3e85bdcSAkhil Goyal 
102c3e85bdcSAkhil Goyal /* initialize the queue with dest chan as caam chan so that
103c3e85bdcSAkhil Goyal  * all the packets in this queue could be dispatched into caam
104c3e85bdcSAkhil Goyal  */
105c3e85bdcSAkhil Goyal static int
106c4509373SSantosh Shukla dpaa_sec_init_rx(struct qman_fq *fq_in, rte_iova_t hwdesc,
107c3e85bdcSAkhil Goyal 		 uint32_t fqid_out)
108c3e85bdcSAkhil Goyal {
109c3e85bdcSAkhil Goyal 	struct qm_mcc_initfq fq_opts;
110c3e85bdcSAkhil Goyal 	uint32_t flags;
111c3e85bdcSAkhil Goyal 	int ret = -1;
112c3e85bdcSAkhil Goyal 
113c3e85bdcSAkhil Goyal 	/* Clear FQ options */
114c3e85bdcSAkhil Goyal 	memset(&fq_opts, 0x00, sizeof(struct qm_mcc_initfq));
115c3e85bdcSAkhil Goyal 
116c3e85bdcSAkhil Goyal 	flags = QMAN_INITFQ_FLAG_SCHED;
117c3e85bdcSAkhil Goyal 	fq_opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_CONTEXTA |
118c3e85bdcSAkhil Goyal 			  QM_INITFQ_WE_CONTEXTB;
119c3e85bdcSAkhil Goyal 
120c3e85bdcSAkhil Goyal 	qm_fqd_context_a_set64(&fq_opts.fqd, hwdesc);
121c3e85bdcSAkhil Goyal 	fq_opts.fqd.context_b = fqid_out;
122a8ee206aSHemant Agrawal 	fq_opts.fqd.dest.channel = dpaa_get_qm_channel_caam();
123c3e85bdcSAkhil Goyal 	fq_opts.fqd.dest.wq = 0;
124c3e85bdcSAkhil Goyal 
125c3e85bdcSAkhil Goyal 	fq_in->cb.ern  = ern_sec_fq_handler;
126c3e85bdcSAkhil Goyal 
127f163231eSHemant Agrawal 	DPAA_SEC_DEBUG("in-%x out-%x", fq_in->fqid, fqid_out);
128e79416d1SHemant Agrawal 
129c3e85bdcSAkhil Goyal 	ret = qman_init_fq(fq_in, flags, &fq_opts);
130c3e85bdcSAkhil Goyal 	if (unlikely(ret != 0))
131f163231eSHemant Agrawal 		DPAA_SEC_ERR("qman_init_fq failed %d", ret);
132c3e85bdcSAkhil Goyal 
133c3e85bdcSAkhil Goyal 	return ret;
134c3e85bdcSAkhil Goyal }
135c3e85bdcSAkhil Goyal 
136c3e85bdcSAkhil Goyal /* something is put into in_fq and caam put the crypto result into out_fq */
137c3e85bdcSAkhil Goyal static enum qman_cb_dqrr_result
138c3e85bdcSAkhil Goyal dqrr_out_fq_cb_rx(struct qman_portal *qm __always_unused,
139c3e85bdcSAkhil Goyal 		  struct qman_fq *fq __always_unused,
140c3e85bdcSAkhil Goyal 		  const struct qm_dqrr_entry *dqrr)
141c3e85bdcSAkhil Goyal {
142c3e85bdcSAkhil Goyal 	const struct qm_fd *fd;
143c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *job;
144c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
145c3e85bdcSAkhil Goyal 
146c3e85bdcSAkhil Goyal 	if (dpaa_sec_op_nb >= DPAA_SEC_BURST)
147c3e85bdcSAkhil Goyal 		return qman_cb_dqrr_defer;
148c3e85bdcSAkhil Goyal 
149c3e85bdcSAkhil Goyal 	if (!(dqrr->stat & QM_DQRR_STAT_FD_VALID))
150c3e85bdcSAkhil Goyal 		return qman_cb_dqrr_consume;
151c3e85bdcSAkhil Goyal 
152c3e85bdcSAkhil Goyal 	fd = &dqrr->fd;
153c3e85bdcSAkhil Goyal 	/* sg is embedded in an op ctx,
154c3e85bdcSAkhil Goyal 	 * sg[0] is for output
155c3e85bdcSAkhil Goyal 	 * sg[1] for input
156c3e85bdcSAkhil Goyal 	 */
157ec861560SGagandeep Singh 	job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
1581f14d500SAkhil Goyal 
159c3e85bdcSAkhil Goyal 	ctx = container_of(job, struct dpaa_sec_op_ctx, job);
160c3e85bdcSAkhil Goyal 	ctx->fd_status = fd->status;
1611f14d500SAkhil Goyal 	if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1621f14d500SAkhil Goyal 		struct qm_sg_entry *sg_out;
1631f14d500SAkhil Goyal 		uint32_t len;
164fb5c100aSAkhil Goyal 		struct rte_mbuf *mbuf = (ctx->op->sym->m_dst == NULL) ?
165fb5c100aSAkhil Goyal 				ctx->op->sym->m_src : ctx->op->sym->m_dst;
1661f14d500SAkhil Goyal 
1671f14d500SAkhil Goyal 		sg_out = &job->sg[0];
1681f14d500SAkhil Goyal 		hw_sg_to_cpu(sg_out);
1691f14d500SAkhil Goyal 		len = sg_out->length;
170fb5c100aSAkhil Goyal 		mbuf->pkt_len = len;
171fb5c100aSAkhil Goyal 		while (mbuf->next != NULL) {
172fb5c100aSAkhil Goyal 			len -= mbuf->data_len;
173fb5c100aSAkhil Goyal 			mbuf = mbuf->next;
174fb5c100aSAkhil Goyal 		}
175fb5c100aSAkhil Goyal 		mbuf->data_len = len;
1761f14d500SAkhil Goyal 	}
177c3e85bdcSAkhil Goyal 	dpaa_sec_ops[dpaa_sec_op_nb++] = ctx->op;
178c3e85bdcSAkhil Goyal 	dpaa_sec_op_ending(ctx);
179c3e85bdcSAkhil Goyal 
180c3e85bdcSAkhil Goyal 	return qman_cb_dqrr_consume;
181c3e85bdcSAkhil Goyal }
182c3e85bdcSAkhil Goyal 
183c3e85bdcSAkhil Goyal /* caam result is put into this queue */
184c3e85bdcSAkhil Goyal static int
185c3e85bdcSAkhil Goyal dpaa_sec_init_tx(struct qman_fq *fq)
186c3e85bdcSAkhil Goyal {
187c3e85bdcSAkhil Goyal 	int ret;
188c3e85bdcSAkhil Goyal 	struct qm_mcc_initfq opts;
189c3e85bdcSAkhil Goyal 	uint32_t flags;
190c3e85bdcSAkhil Goyal 
191c3e85bdcSAkhil Goyal 	flags = QMAN_FQ_FLAG_NO_ENQUEUE | QMAN_FQ_FLAG_LOCKED |
192c3e85bdcSAkhil Goyal 		QMAN_FQ_FLAG_DYNAMIC_FQID;
193c3e85bdcSAkhil Goyal 
194c3e85bdcSAkhil Goyal 	ret = qman_create_fq(0, flags, fq);
195c3e85bdcSAkhil Goyal 	if (unlikely(ret)) {
196f163231eSHemant Agrawal 		DPAA_SEC_ERR("qman_create_fq failed");
197c3e85bdcSAkhil Goyal 		return ret;
198c3e85bdcSAkhil Goyal 	}
199c3e85bdcSAkhil Goyal 
200c3e85bdcSAkhil Goyal 	memset(&opts, 0, sizeof(opts));
201c3e85bdcSAkhil Goyal 	opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
202c3e85bdcSAkhil Goyal 		       QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
203c3e85bdcSAkhil Goyal 
204c3e85bdcSAkhil Goyal 	/* opts.fqd.dest.channel = dpaa_sec_pool_chan; */
205c3e85bdcSAkhil Goyal 
206c3e85bdcSAkhil Goyal 	fq->cb.dqrr = dqrr_out_fq_cb_rx;
207c3e85bdcSAkhil Goyal 	fq->cb.ern  = ern_sec_fq_handler;
208c3e85bdcSAkhil Goyal 
209c3e85bdcSAkhil Goyal 	ret = qman_init_fq(fq, 0, &opts);
210c3e85bdcSAkhil Goyal 	if (unlikely(ret)) {
211f163231eSHemant Agrawal 		DPAA_SEC_ERR("unable to init caam source fq!");
212c3e85bdcSAkhil Goyal 		return ret;
213c3e85bdcSAkhil Goyal 	}
214c3e85bdcSAkhil Goyal 
215c3e85bdcSAkhil Goyal 	return ret;
216c3e85bdcSAkhil Goyal }
217c3e85bdcSAkhil Goyal 
2186290de2cSLukasz Wojciechowski static inline int is_aead(dpaa_sec_session *ses)
2196290de2cSLukasz Wojciechowski {
2206290de2cSLukasz Wojciechowski 	return ((ses->cipher_alg == 0) &&
2216290de2cSLukasz Wojciechowski 		(ses->auth_alg == 0) &&
2226290de2cSLukasz Wojciechowski 		(ses->aead_alg != 0));
2236290de2cSLukasz Wojciechowski }
2246290de2cSLukasz Wojciechowski 
225c3e85bdcSAkhil Goyal static inline int is_encode(dpaa_sec_session *ses)
226c3e85bdcSAkhil Goyal {
227c3e85bdcSAkhil Goyal 	return ses->dir == DIR_ENC;
228c3e85bdcSAkhil Goyal }
229c3e85bdcSAkhil Goyal 
230c3e85bdcSAkhil Goyal static inline int is_decode(dpaa_sec_session *ses)
231c3e85bdcSAkhil Goyal {
232c3e85bdcSAkhil Goyal 	return ses->dir == DIR_DEC;
233c3e85bdcSAkhil Goyal }
234c3e85bdcSAkhil Goyal 
235314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
236a1173d55SHemant Agrawal static int
237a1173d55SHemant Agrawal dpaa_sec_prep_pdcp_cdb(dpaa_sec_session *ses)
238a1173d55SHemant Agrawal {
239a1173d55SHemant Agrawal 	struct alginfo authdata = {0}, cipherdata = {0};
240a1173d55SHemant Agrawal 	struct sec_cdb *cdb = &ses->cdb;
2412e4cbdb4SVakul Garg 	struct alginfo *p_authdata = NULL;
242a1173d55SHemant Agrawal 	int32_t shared_desc_len = 0;
243a1173d55SHemant Agrawal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
244a1173d55SHemant Agrawal 	int swap = false;
245a1173d55SHemant Agrawal #else
246a1173d55SHemant Agrawal 	int swap = true;
247a1173d55SHemant Agrawal #endif
248a1173d55SHemant Agrawal 
249a1173d55SHemant Agrawal 	cipherdata.key = (size_t)ses->cipher_key.data;
250a1173d55SHemant Agrawal 	cipherdata.keylen = ses->cipher_key.length;
251a1173d55SHemant Agrawal 	cipherdata.key_enc_flags = 0;
252a1173d55SHemant Agrawal 	cipherdata.key_type = RTA_DATA_IMM;
2538524b44eSHemant Agrawal 	cipherdata.algtype = ses->cipher_key.alg;
2548524b44eSHemant Agrawal 	cipherdata.algmode = ses->cipher_key.algmode;
255a1173d55SHemant Agrawal 
2562e4cbdb4SVakul Garg 	if (ses->auth_alg) {
257a1173d55SHemant Agrawal 		authdata.key = (size_t)ses->auth_key.data;
258a1173d55SHemant Agrawal 		authdata.keylen = ses->auth_key.length;
259a1173d55SHemant Agrawal 		authdata.key_enc_flags = 0;
260a1173d55SHemant Agrawal 		authdata.key_type = RTA_DATA_IMM;
2618524b44eSHemant Agrawal 		authdata.algtype = ses->auth_key.alg;
2628524b44eSHemant Agrawal 		authdata.algmode = ses->auth_key.algmode;
263a1173d55SHemant Agrawal 
2642e4cbdb4SVakul Garg 		p_authdata = &authdata;
2652e4cbdb4SVakul Garg 	}
2662e4cbdb4SVakul Garg 
267*f6ab96f1SAkhil Goyal 	if (rta_inline_pdcp_query(authdata.algtype,
268*f6ab96f1SAkhil Goyal 				cipherdata.algtype,
269*f6ab96f1SAkhil Goyal 				ses->pdcp.sn_size,
270*f6ab96f1SAkhil Goyal 				ses->pdcp.hfn_ovd)) {
2712e4cbdb4SVakul Garg 		cipherdata.key =
272*f6ab96f1SAkhil Goyal 			(size_t)rte_dpaa_mem_vtop((void *)
273*f6ab96f1SAkhil Goyal 					(size_t)cipherdata.key);
274a1173d55SHemant Agrawal 		cipherdata.key_type = RTA_DATA_PTR;
275a1173d55SHemant Agrawal 	}
276a1173d55SHemant Agrawal 
2772e4cbdb4SVakul Garg 	if (ses->pdcp.domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
278a1173d55SHemant Agrawal 		if (ses->dir == DIR_ENC)
279a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_c_plane_encap(
280a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
281a1173d55SHemant Agrawal 					ses->pdcp.hfn,
282eac60082SVakul Garg 					ses->pdcp.sn_size,
283a1173d55SHemant Agrawal 					ses->pdcp.bearer,
284a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
285a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
286a1173d55SHemant Agrawal 					&cipherdata, &authdata,
287a1173d55SHemant Agrawal 					0);
288a1173d55SHemant Agrawal 		else if (ses->dir == DIR_DEC)
289a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_c_plane_decap(
290a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
291a1173d55SHemant Agrawal 					ses->pdcp.hfn,
292eac60082SVakul Garg 					ses->pdcp.sn_size,
293a1173d55SHemant Agrawal 					ses->pdcp.bearer,
294a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
295a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
296a1173d55SHemant Agrawal 					&cipherdata, &authdata,
297a1173d55SHemant Agrawal 					0);
298a1173d55SHemant Agrawal 	} else {
299a1173d55SHemant Agrawal 		if (ses->dir == DIR_ENC)
300a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_u_plane_encap(
301a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
302a1173d55SHemant Agrawal 					ses->pdcp.sn_size,
303a1173d55SHemant Agrawal 					ses->pdcp.hfn,
304a1173d55SHemant Agrawal 					ses->pdcp.bearer,
305a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
306a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
3072e4cbdb4SVakul Garg 					&cipherdata, p_authdata, 0);
308a1173d55SHemant Agrawal 		else if (ses->dir == DIR_DEC)
309a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_u_plane_decap(
310a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
311a1173d55SHemant Agrawal 					ses->pdcp.sn_size,
312a1173d55SHemant Agrawal 					ses->pdcp.hfn,
313a1173d55SHemant Agrawal 					ses->pdcp.bearer,
314a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
315a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
3162e4cbdb4SVakul Garg 					&cipherdata, p_authdata, 0);
317a1173d55SHemant Agrawal 	}
318a1173d55SHemant Agrawal 	return shared_desc_len;
319a1173d55SHemant Agrawal }
320a1173d55SHemant Agrawal 
32105b12700SHemant Agrawal /* prepare ipsec proto command block of the session */
32205b12700SHemant Agrawal static int
32305b12700SHemant Agrawal dpaa_sec_prep_ipsec_cdb(dpaa_sec_session *ses)
32405b12700SHemant Agrawal {
32505b12700SHemant Agrawal 	struct alginfo cipherdata = {0}, authdata = {0};
32605b12700SHemant Agrawal 	struct sec_cdb *cdb = &ses->cdb;
32705b12700SHemant Agrawal 	int32_t shared_desc_len = 0;
32805b12700SHemant Agrawal 	int err;
32905b12700SHemant Agrawal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
33005b12700SHemant Agrawal 	int swap = false;
33105b12700SHemant Agrawal #else
33205b12700SHemant Agrawal 	int swap = true;
33305b12700SHemant Agrawal #endif
33405b12700SHemant Agrawal 
33505b12700SHemant Agrawal 	cipherdata.key = (size_t)ses->cipher_key.data;
33605b12700SHemant Agrawal 	cipherdata.keylen = ses->cipher_key.length;
33705b12700SHemant Agrawal 	cipherdata.key_enc_flags = 0;
33805b12700SHemant Agrawal 	cipherdata.key_type = RTA_DATA_IMM;
3398524b44eSHemant Agrawal 	cipherdata.algtype = ses->cipher_key.alg;
3408524b44eSHemant Agrawal 	cipherdata.algmode = ses->cipher_key.algmode;
34105b12700SHemant Agrawal 
3422c318722SHemant Agrawal 	if (ses->auth_key.length) {
34305b12700SHemant Agrawal 		authdata.key = (size_t)ses->auth_key.data;
34405b12700SHemant Agrawal 		authdata.keylen = ses->auth_key.length;
34505b12700SHemant Agrawal 		authdata.key_enc_flags = 0;
34605b12700SHemant Agrawal 		authdata.key_type = RTA_DATA_IMM;
3478524b44eSHemant Agrawal 		authdata.algtype = ses->auth_key.alg;
3488524b44eSHemant Agrawal 		authdata.algmode = ses->auth_key.algmode;
3492c318722SHemant Agrawal 	}
35005b12700SHemant Agrawal 
35105b12700SHemant Agrawal 	cdb->sh_desc[0] = cipherdata.keylen;
35205b12700SHemant Agrawal 	cdb->sh_desc[1] = authdata.keylen;
35305b12700SHemant Agrawal 	err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
35405b12700SHemant Agrawal 			       MIN_JOB_DESC_SIZE,
35505b12700SHemant Agrawal 			       (unsigned int *)cdb->sh_desc,
35605b12700SHemant Agrawal 			       &cdb->sh_desc[2], 2);
35705b12700SHemant Agrawal 
35805b12700SHemant Agrawal 	if (err < 0) {
35905b12700SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Incorrect key lengths");
36005b12700SHemant Agrawal 		return err;
36105b12700SHemant Agrawal 	}
36205b12700SHemant Agrawal 	if (cdb->sh_desc[2] & 1)
36305b12700SHemant Agrawal 		cipherdata.key_type = RTA_DATA_IMM;
36405b12700SHemant Agrawal 	else {
365ec861560SGagandeep Singh 		cipherdata.key = (size_t)rte_dpaa_mem_vtop(
36605b12700SHemant Agrawal 					(void *)(size_t)cipherdata.key);
36705b12700SHemant Agrawal 		cipherdata.key_type = RTA_DATA_PTR;
36805b12700SHemant Agrawal 	}
36905b12700SHemant Agrawal 	if (cdb->sh_desc[2] & (1<<1))
37005b12700SHemant Agrawal 		authdata.key_type = RTA_DATA_IMM;
37105b12700SHemant Agrawal 	else {
372ec861560SGagandeep Singh 		authdata.key = (size_t)rte_dpaa_mem_vtop(
37305b12700SHemant Agrawal 					(void *)(size_t)authdata.key);
37405b12700SHemant Agrawal 		authdata.key_type = RTA_DATA_PTR;
37505b12700SHemant Agrawal 	}
37605b12700SHemant Agrawal 
37705b12700SHemant Agrawal 	cdb->sh_desc[0] = 0;
37805b12700SHemant Agrawal 	cdb->sh_desc[1] = 0;
37905b12700SHemant Agrawal 	cdb->sh_desc[2] = 0;
38005b12700SHemant Agrawal 	if (ses->dir == DIR_ENC) {
38105b12700SHemant Agrawal 		shared_desc_len = cnstr_shdsc_ipsec_new_encap(
38205b12700SHemant Agrawal 				cdb->sh_desc,
38305b12700SHemant Agrawal 				true, swap, SHR_SERIAL,
38405b12700SHemant Agrawal 				&ses->encap_pdb,
38505b12700SHemant Agrawal 				(uint8_t *)&ses->ip4_hdr,
38605b12700SHemant Agrawal 				&cipherdata, &authdata);
38705b12700SHemant Agrawal 	} else if (ses->dir == DIR_DEC) {
38805b12700SHemant Agrawal 		shared_desc_len = cnstr_shdsc_ipsec_new_decap(
38905b12700SHemant Agrawal 				cdb->sh_desc,
39005b12700SHemant Agrawal 				true, swap, SHR_SERIAL,
39105b12700SHemant Agrawal 				&ses->decap_pdb,
39205b12700SHemant Agrawal 				&cipherdata, &authdata);
39305b12700SHemant Agrawal 	}
39405b12700SHemant Agrawal 	return shared_desc_len;
39505b12700SHemant Agrawal }
396314424b6SHemant Agrawal #endif
397c3e85bdcSAkhil Goyal /* prepare command block of the session */
398c3e85bdcSAkhil Goyal static int
399c3e85bdcSAkhil Goyal dpaa_sec_prep_cdb(dpaa_sec_session *ses)
400c3e85bdcSAkhil Goyal {
401c3e85bdcSAkhil Goyal 	struct alginfo alginfo_c = {0}, alginfo_a = {0}, alginfo = {0};
40222788c2cSSunil Kumar Kori 	int32_t shared_desc_len = 0;
403e79416d1SHemant Agrawal 	struct sec_cdb *cdb = &ses->cdb;
404c3e85bdcSAkhil Goyal 	int err;
405c3e85bdcSAkhil Goyal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
406c3e85bdcSAkhil Goyal 	int swap = false;
407c3e85bdcSAkhil Goyal #else
408c3e85bdcSAkhil Goyal 	int swap = true;
409c3e85bdcSAkhil Goyal #endif
410c3e85bdcSAkhil Goyal 
411c3e85bdcSAkhil Goyal 	memset(cdb, 0, sizeof(struct sec_cdb));
412c3e85bdcSAkhil Goyal 
4138524b44eSHemant Agrawal 	switch (ses->ctxt) {
414314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
4158524b44eSHemant Agrawal 	case DPAA_SEC_IPSEC:
41605b12700SHemant Agrawal 		shared_desc_len = dpaa_sec_prep_ipsec_cdb(ses);
4178524b44eSHemant Agrawal 		break;
4188524b44eSHemant Agrawal 	case DPAA_SEC_PDCP:
419a1173d55SHemant Agrawal 		shared_desc_len = dpaa_sec_prep_pdcp_cdb(ses);
4208524b44eSHemant Agrawal 		break;
421314424b6SHemant Agrawal #endif
4228524b44eSHemant Agrawal 	case DPAA_SEC_CIPHER:
4230e5607e4SHemant Agrawal 		alginfo_c.key = (size_t)ses->cipher_key.data;
424c3e85bdcSAkhil Goyal 		alginfo_c.keylen = ses->cipher_key.length;
425c3e85bdcSAkhil Goyal 		alginfo_c.key_enc_flags = 0;
426c3e85bdcSAkhil Goyal 		alginfo_c.key_type = RTA_DATA_IMM;
4278524b44eSHemant Agrawal 		alginfo_c.algtype = ses->cipher_key.alg;
4288524b44eSHemant Agrawal 		alginfo_c.algmode = ses->cipher_key.algmode;
4298524b44eSHemant Agrawal 
430c5788a10SHemant Agrawal 		switch (ses->cipher_alg) {
431c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_AES_CBC:
432c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_3DES_CBC:
433c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_AES_CTR:
434c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_3DES_CTR:
435c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_blkcipher(
436c5788a10SHemant Agrawal 					cdb->sh_desc, true,
437c5788a10SHemant Agrawal 					swap, SHR_NEVER, &alginfo_c,
438c5788a10SHemant Agrawal 					ses->iv.length,
439c5788a10SHemant Agrawal 					ses->dir);
440c5788a10SHemant Agrawal 			break;
441c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
442c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_snow_f8(
443c5788a10SHemant Agrawal 					cdb->sh_desc, true, swap,
444c5788a10SHemant Agrawal 					&alginfo_c,
445c5788a10SHemant Agrawal 					ses->dir);
446c5788a10SHemant Agrawal 			break;
447c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_ZUC_EEA3:
448c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_zuce(
449c5788a10SHemant Agrawal 					cdb->sh_desc, true, swap,
450c5788a10SHemant Agrawal 					&alginfo_c,
451c5788a10SHemant Agrawal 					ses->dir);
452c5788a10SHemant Agrawal 			break;
453c5788a10SHemant Agrawal 		default:
454c5788a10SHemant Agrawal 			DPAA_SEC_ERR("unsupported cipher alg %d",
455c5788a10SHemant Agrawal 				     ses->cipher_alg);
456c3e85bdcSAkhil Goyal 			return -ENOTSUP;
457c3e85bdcSAkhil Goyal 		}
4588524b44eSHemant Agrawal 		break;
4598524b44eSHemant Agrawal 	case DPAA_SEC_AUTH:
4600e5607e4SHemant Agrawal 		alginfo_a.key = (size_t)ses->auth_key.data;
461c3e85bdcSAkhil Goyal 		alginfo_a.keylen = ses->auth_key.length;
462c3e85bdcSAkhil Goyal 		alginfo_a.key_enc_flags = 0;
463c3e85bdcSAkhil Goyal 		alginfo_a.key_type = RTA_DATA_IMM;
4648524b44eSHemant Agrawal 		alginfo_a.algtype = ses->auth_key.alg;
4658524b44eSHemant Agrawal 		alginfo_a.algmode = ses->auth_key.algmode;
466c5788a10SHemant Agrawal 		switch (ses->auth_alg) {
467c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_MD5_HMAC:
468c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA1_HMAC:
469c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA224_HMAC:
470c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA256_HMAC:
471c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA384_HMAC:
472c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA512_HMAC:
473c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_hmac(
474c5788a10SHemant Agrawal 						cdb->sh_desc, true,
475c5788a10SHemant Agrawal 						swap, SHR_NEVER, &alginfo_a,
476c5788a10SHemant Agrawal 						!ses->dir,
477c5788a10SHemant Agrawal 						ses->digest_length);
478c5788a10SHemant Agrawal 			break;
479c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
480c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_snow_f9(
481c5788a10SHemant Agrawal 						cdb->sh_desc, true, swap,
482c5788a10SHemant Agrawal 						&alginfo_a,
483c5788a10SHemant Agrawal 						!ses->dir,
484c5788a10SHemant Agrawal 						ses->digest_length);
485c5788a10SHemant Agrawal 			break;
486c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_ZUC_EIA3:
487c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_zuca(
488c5788a10SHemant Agrawal 						cdb->sh_desc, true, swap,
489c5788a10SHemant Agrawal 						&alginfo_a,
490c5788a10SHemant Agrawal 						!ses->dir,
491c5788a10SHemant Agrawal 						ses->digest_length);
492c5788a10SHemant Agrawal 			break;
493c5788a10SHemant Agrawal 		default:
494c5788a10SHemant Agrawal 			DPAA_SEC_ERR("unsupported auth alg %u", ses->auth_alg);
495c5788a10SHemant Agrawal 		}
4968524b44eSHemant Agrawal 		break;
4978524b44eSHemant Agrawal 	case DPAA_SEC_AEAD:
498c3e85bdcSAkhil Goyal 		if (alginfo.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
499f163231eSHemant Agrawal 			DPAA_SEC_ERR("not supported aead alg");
500c3e85bdcSAkhil Goyal 			return -ENOTSUP;
501c3e85bdcSAkhil Goyal 		}
5020e5607e4SHemant Agrawal 		alginfo.key = (size_t)ses->aead_key.data;
503c3e85bdcSAkhil Goyal 		alginfo.keylen = ses->aead_key.length;
504c3e85bdcSAkhil Goyal 		alginfo.key_enc_flags = 0;
505c3e85bdcSAkhil Goyal 		alginfo.key_type = RTA_DATA_IMM;
5068524b44eSHemant Agrawal 		alginfo.algtype = ses->aead_key.alg;
5078524b44eSHemant Agrawal 		alginfo.algmode = ses->aead_key.algmode;
508c3e85bdcSAkhil Goyal 
509c3e85bdcSAkhil Goyal 		if (ses->dir == DIR_ENC)
510c3e85bdcSAkhil Goyal 			shared_desc_len = cnstr_shdsc_gcm_encap(
5117449390bSAkhil Goyal 					cdb->sh_desc, true, swap, SHR_NEVER,
512c3e85bdcSAkhil Goyal 					&alginfo,
513c3e85bdcSAkhil Goyal 					ses->iv.length,
514c3e85bdcSAkhil Goyal 					ses->digest_length);
515c3e85bdcSAkhil Goyal 		else
516c3e85bdcSAkhil Goyal 			shared_desc_len = cnstr_shdsc_gcm_decap(
5177449390bSAkhil Goyal 					cdb->sh_desc, true, swap, SHR_NEVER,
518c3e85bdcSAkhil Goyal 					&alginfo,
519c3e85bdcSAkhil Goyal 					ses->iv.length,
520c3e85bdcSAkhil Goyal 					ses->digest_length);
5218524b44eSHemant Agrawal 		break;
5228524b44eSHemant Agrawal 	case DPAA_SEC_CIPHER_HASH:
5230e5607e4SHemant Agrawal 		alginfo_c.key = (size_t)ses->cipher_key.data;
524c3e85bdcSAkhil Goyal 		alginfo_c.keylen = ses->cipher_key.length;
525c3e85bdcSAkhil Goyal 		alginfo_c.key_enc_flags = 0;
526c3e85bdcSAkhil Goyal 		alginfo_c.key_type = RTA_DATA_IMM;
5278524b44eSHemant Agrawal 		alginfo_c.algtype = ses->cipher_key.alg;
5288524b44eSHemant Agrawal 		alginfo_c.algmode = ses->cipher_key.algmode;
529c3e85bdcSAkhil Goyal 
5300e5607e4SHemant Agrawal 		alginfo_a.key = (size_t)ses->auth_key.data;
531c3e85bdcSAkhil Goyal 		alginfo_a.keylen = ses->auth_key.length;
532c3e85bdcSAkhil Goyal 		alginfo_a.key_enc_flags = 0;
533c3e85bdcSAkhil Goyal 		alginfo_a.key_type = RTA_DATA_IMM;
5348524b44eSHemant Agrawal 		alginfo_a.algtype = ses->auth_key.alg;
5358524b44eSHemant Agrawal 		alginfo_a.algmode = ses->auth_key.algmode;
536c3e85bdcSAkhil Goyal 
537c3e85bdcSAkhil Goyal 		cdb->sh_desc[0] = alginfo_c.keylen;
538c3e85bdcSAkhil Goyal 		cdb->sh_desc[1] = alginfo_a.keylen;
539c3e85bdcSAkhil Goyal 		err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
540c3e85bdcSAkhil Goyal 				       MIN_JOB_DESC_SIZE,
541c3e85bdcSAkhil Goyal 				       (unsigned int *)cdb->sh_desc,
542c3e85bdcSAkhil Goyal 				       &cdb->sh_desc[2], 2);
543c3e85bdcSAkhil Goyal 
544c3e85bdcSAkhil Goyal 		if (err < 0) {
545f163231eSHemant Agrawal 			DPAA_SEC_ERR("Crypto: Incorrect key lengths");
546c3e85bdcSAkhil Goyal 			return err;
547c3e85bdcSAkhil Goyal 		}
548c3e85bdcSAkhil Goyal 		if (cdb->sh_desc[2] & 1)
549c3e85bdcSAkhil Goyal 			alginfo_c.key_type = RTA_DATA_IMM;
550c3e85bdcSAkhil Goyal 		else {
551ec861560SGagandeep Singh 			alginfo_c.key = (size_t)rte_dpaa_mem_vtop(
5520e5607e4SHemant Agrawal 						(void *)(size_t)alginfo_c.key);
553c3e85bdcSAkhil Goyal 			alginfo_c.key_type = RTA_DATA_PTR;
554c3e85bdcSAkhil Goyal 		}
555c3e85bdcSAkhil Goyal 		if (cdb->sh_desc[2] & (1<<1))
556c3e85bdcSAkhil Goyal 			alginfo_a.key_type = RTA_DATA_IMM;
557c3e85bdcSAkhil Goyal 		else {
558ec861560SGagandeep Singh 			alginfo_a.key = (size_t)rte_dpaa_mem_vtop(
5590e5607e4SHemant Agrawal 						(void *)(size_t)alginfo_a.key);
560c3e85bdcSAkhil Goyal 			alginfo_a.key_type = RTA_DATA_PTR;
561c3e85bdcSAkhil Goyal 		}
562c3e85bdcSAkhil Goyal 		cdb->sh_desc[0] = 0;
563c3e85bdcSAkhil Goyal 		cdb->sh_desc[1] = 0;
564c3e85bdcSAkhil Goyal 		cdb->sh_desc[2] = 0;
5651f14d500SAkhil Goyal 		/* Auth_only_len is set as 0 here and it will be
5661f14d500SAkhil Goyal 		 * overwritten in fd for each packet.
567c3e85bdcSAkhil Goyal 		 */
568c3e85bdcSAkhil Goyal 		shared_desc_len = cnstr_shdsc_authenc(cdb->sh_desc,
5697449390bSAkhil Goyal 				true, swap, SHR_SERIAL, &alginfo_c, &alginfo_a,
5703394ed47SVakul Garg 				ses->iv.length,
571c3e85bdcSAkhil Goyal 				ses->digest_length, ses->dir);
5728524b44eSHemant Agrawal 		break;
5738524b44eSHemant Agrawal 	case DPAA_SEC_HASH_CIPHER:
5748524b44eSHemant Agrawal 	default:
5758524b44eSHemant Agrawal 		DPAA_SEC_ERR("error: Unsupported session");
5768524b44eSHemant Agrawal 		return -ENOTSUP;
577c3e85bdcSAkhil Goyal 	}
57822788c2cSSunil Kumar Kori 
57922788c2cSSunil Kumar Kori 	if (shared_desc_len < 0) {
580f163231eSHemant Agrawal 		DPAA_SEC_ERR("error in preparing command block");
58122788c2cSSunil Kumar Kori 		return shared_desc_len;
58222788c2cSSunil Kumar Kori 	}
58322788c2cSSunil Kumar Kori 
584c3e85bdcSAkhil Goyal 	cdb->sh_hdr.hi.field.idlen = shared_desc_len;
585c3e85bdcSAkhil Goyal 	cdb->sh_hdr.hi.word = rte_cpu_to_be_32(cdb->sh_hdr.hi.word);
586c3e85bdcSAkhil Goyal 	cdb->sh_hdr.lo.word = rte_cpu_to_be_32(cdb->sh_hdr.lo.word);
587c3e85bdcSAkhil Goyal 
588c3e85bdcSAkhil Goyal 	return 0;
589c3e85bdcSAkhil Goyal }
590c3e85bdcSAkhil Goyal 
591c3e85bdcSAkhil Goyal /* qp is lockless, should be accessed by only one thread */
592c3e85bdcSAkhil Goyal static int
593c3e85bdcSAkhil Goyal dpaa_sec_deq(struct dpaa_sec_qp *qp, struct rte_crypto_op **ops, int nb_ops)
594c3e85bdcSAkhil Goyal {
595c3e85bdcSAkhil Goyal 	struct qman_fq *fq;
5969a984458SAkhil Goyal 	unsigned int pkts = 0;
597f40d5a53SNipun Gupta 	int num_rx_bufs, ret;
5989a984458SAkhil Goyal 	struct qm_dqrr_entry *dq;
599f40d5a53SNipun Gupta 	uint32_t vdqcr_flags = 0;
600c3e85bdcSAkhil Goyal 
601c3e85bdcSAkhil Goyal 	fq = &qp->outq;
602f40d5a53SNipun Gupta 	/*
603f40d5a53SNipun Gupta 	 * Until request for four buffers, we provide exact number of buffers.
604f40d5a53SNipun Gupta 	 * Otherwise we do not set the QM_VDQCR_EXACT flag.
605f40d5a53SNipun Gupta 	 * Not setting QM_VDQCR_EXACT flag can provide two more buffers than
606f40d5a53SNipun Gupta 	 * requested, so we request two less in this case.
607f40d5a53SNipun Gupta 	 */
608f40d5a53SNipun Gupta 	if (nb_ops < 4) {
609f40d5a53SNipun Gupta 		vdqcr_flags = QM_VDQCR_EXACT;
610f40d5a53SNipun Gupta 		num_rx_bufs = nb_ops;
611f40d5a53SNipun Gupta 	} else {
612f40d5a53SNipun Gupta 		num_rx_bufs = nb_ops > DPAA_MAX_DEQUEUE_NUM_FRAMES ?
613f40d5a53SNipun Gupta 			(DPAA_MAX_DEQUEUE_NUM_FRAMES - 2) : (nb_ops - 2);
614f40d5a53SNipun Gupta 	}
615f40d5a53SNipun Gupta 	ret = qman_set_vdq(fq, num_rx_bufs, vdqcr_flags);
6169a984458SAkhil Goyal 	if (ret)
6179a984458SAkhil Goyal 		return 0;
618c3e85bdcSAkhil Goyal 
6199a984458SAkhil Goyal 	do {
6209a984458SAkhil Goyal 		const struct qm_fd *fd;
6219a984458SAkhil Goyal 		struct dpaa_sec_job *job;
6229a984458SAkhil Goyal 		struct dpaa_sec_op_ctx *ctx;
6239a984458SAkhil Goyal 		struct rte_crypto_op *op;
624c3e85bdcSAkhil Goyal 
6259a984458SAkhil Goyal 		dq = qman_dequeue(fq);
6269a984458SAkhil Goyal 		if (!dq)
6279a984458SAkhil Goyal 			continue;
6289a984458SAkhil Goyal 
6299a984458SAkhil Goyal 		fd = &dq->fd;
6309a984458SAkhil Goyal 		/* sg is embedded in an op ctx,
6319a984458SAkhil Goyal 		 * sg[0] is for output
6329a984458SAkhil Goyal 		 * sg[1] for input
6339a984458SAkhil Goyal 		 */
634ec861560SGagandeep Singh 		job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
6359a984458SAkhil Goyal 
6369a984458SAkhil Goyal 		ctx = container_of(job, struct dpaa_sec_op_ctx, job);
6379a984458SAkhil Goyal 		ctx->fd_status = fd->status;
6389a984458SAkhil Goyal 		op = ctx->op;
6399a984458SAkhil Goyal 		if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
6409a984458SAkhil Goyal 			struct qm_sg_entry *sg_out;
6419a984458SAkhil Goyal 			uint32_t len;
642fb5c100aSAkhil Goyal 			struct rte_mbuf *mbuf = (op->sym->m_dst == NULL) ?
643fb5c100aSAkhil Goyal 						op->sym->m_src : op->sym->m_dst;
6449a984458SAkhil Goyal 
6459a984458SAkhil Goyal 			sg_out = &job->sg[0];
6469a984458SAkhil Goyal 			hw_sg_to_cpu(sg_out);
6479a984458SAkhil Goyal 			len = sg_out->length;
648fb5c100aSAkhil Goyal 			mbuf->pkt_len = len;
649fb5c100aSAkhil Goyal 			while (mbuf->next != NULL) {
650fb5c100aSAkhil Goyal 				len -= mbuf->data_len;
651fb5c100aSAkhil Goyal 				mbuf = mbuf->next;
652fb5c100aSAkhil Goyal 			}
653fb5c100aSAkhil Goyal 			mbuf->data_len = len;
6549a984458SAkhil Goyal 		}
6559a984458SAkhil Goyal 		if (!ctx->fd_status) {
6569a984458SAkhil Goyal 			op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
6579a984458SAkhil Goyal 		} else {
658f163231eSHemant Agrawal 			DPAA_SEC_DP_WARN("SEC return err:0x%x", ctx->fd_status);
6599a984458SAkhil Goyal 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
6609a984458SAkhil Goyal 		}
6619a984458SAkhil Goyal 		ops[pkts++] = op;
6629a984458SAkhil Goyal 
6639a984458SAkhil Goyal 		/* report op status to sym->op and then free the ctx memeory */
6649a984458SAkhil Goyal 		rte_mempool_put(ctx->ctx_pool, (void *)ctx);
6659a984458SAkhil Goyal 
6669a984458SAkhil Goyal 		qman_dqrr_consume(fq, dq);
6679a984458SAkhil Goyal 	} while (fq->flags & QMAN_FQ_STATE_VDQCR);
6689a984458SAkhil Goyal 
6699a984458SAkhil Goyal 	return pkts;
670c3e85bdcSAkhil Goyal }
671c3e85bdcSAkhil Goyal 
672a74af788SAkhil Goyal static inline struct dpaa_sec_job *
673a74af788SAkhil Goyal build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
674a74af788SAkhil Goyal {
675a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
676a74af788SAkhil Goyal 	struct rte_mbuf *mbuf = sym->m_src;
677a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
678a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
679a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
680a74af788SAkhil Goyal 	phys_addr_t start_addr;
681a74af788SAkhil Goyal 	uint8_t *old_digest, extra_segs;
682c5788a10SHemant Agrawal 	int data_len, data_offset;
683c5788a10SHemant Agrawal 
684c5788a10SHemant Agrawal 	data_len = sym->auth.data.length;
685c5788a10SHemant Agrawal 	data_offset = sym->auth.data.offset;
686c5788a10SHemant Agrawal 
687c5788a10SHemant Agrawal 	if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
688c5788a10SHemant Agrawal 	    ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
689c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
690c5788a10SHemant Agrawal 			DPAA_SEC_ERR("AUTH: len/offset must be full bytes");
691c5788a10SHemant Agrawal 			return NULL;
692c5788a10SHemant Agrawal 		}
693c5788a10SHemant Agrawal 
694c5788a10SHemant Agrawal 		data_len = data_len >> 3;
695c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
696c5788a10SHemant Agrawal 	}
697a74af788SAkhil Goyal 
698a74af788SAkhil Goyal 	if (is_decode(ses))
699a74af788SAkhil Goyal 		extra_segs = 3;
700a74af788SAkhil Goyal 	else
701a74af788SAkhil Goyal 		extra_segs = 2;
702a74af788SAkhil Goyal 
703f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
704f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("Auth: Max sec segs supported is %d",
705a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
706a74af788SAkhil Goyal 		return NULL;
707a74af788SAkhil Goyal 	}
708f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, mbuf->nb_segs + extra_segs);
709a74af788SAkhil Goyal 	if (!ctx)
710a74af788SAkhil Goyal 		return NULL;
711a74af788SAkhil Goyal 
712a74af788SAkhil Goyal 	cf = &ctx->job;
713a74af788SAkhil Goyal 	ctx->op = op;
714a74af788SAkhil Goyal 	old_digest = ctx->digest;
715a74af788SAkhil Goyal 
716a74af788SAkhil Goyal 	/* output */
717a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
718a74af788SAkhil Goyal 	qm_sg_entry_set64(out_sg, sym->auth.digest.phys_addr);
719a74af788SAkhil Goyal 	out_sg->length = ses->digest_length;
720a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
721a74af788SAkhil Goyal 
722a74af788SAkhil Goyal 	/* input */
723a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
724a74af788SAkhil Goyal 	/* need to extend the input to a compound frame */
725a74af788SAkhil Goyal 	in_sg->extension = 1;
726a74af788SAkhil Goyal 	in_sg->final = 1;
727c5788a10SHemant Agrawal 	in_sg->length = data_len;
728ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
729a74af788SAkhil Goyal 
730a74af788SAkhil Goyal 	/* 1st seg */
731a74af788SAkhil Goyal 	sg = in_sg + 1;
732a74af788SAkhil Goyal 
733c5788a10SHemant Agrawal 	if (ses->iv.length) {
734c5788a10SHemant Agrawal 		uint8_t *iv_ptr;
735c5788a10SHemant Agrawal 
736c5788a10SHemant Agrawal 		iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
737c5788a10SHemant Agrawal 						   ses->iv.offset);
738c5788a10SHemant Agrawal 
739c5788a10SHemant Agrawal 		if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
740c5788a10SHemant Agrawal 			iv_ptr = conv_to_snow_f9_iv(iv_ptr);
741c5788a10SHemant Agrawal 			sg->length = 12;
742c5788a10SHemant Agrawal 		} else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
743c5788a10SHemant Agrawal 			iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
744c5788a10SHemant Agrawal 			sg->length = 8;
745c5788a10SHemant Agrawal 		} else {
746c5788a10SHemant Agrawal 			sg->length = ses->iv.length;
747c5788a10SHemant Agrawal 		}
748ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(iv_ptr));
749c5788a10SHemant Agrawal 		in_sg->length += sg->length;
750c5788a10SHemant Agrawal 		cpu_to_hw_sg(sg);
751c5788a10SHemant Agrawal 		sg++;
752c5788a10SHemant Agrawal 	}
753c5788a10SHemant Agrawal 
754c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
755c5788a10SHemant Agrawal 	sg->offset = data_offset;
756c5788a10SHemant Agrawal 
757c5788a10SHemant Agrawal 	if (data_len <= (mbuf->data_len - data_offset)) {
758c5788a10SHemant Agrawal 		sg->length = data_len;
759c5788a10SHemant Agrawal 	} else {
760c5788a10SHemant Agrawal 		sg->length = mbuf->data_len - data_offset;
761c5788a10SHemant Agrawal 
762c5788a10SHemant Agrawal 		/* remaining i/p segs */
763c5788a10SHemant Agrawal 		while ((data_len = data_len - sg->length) &&
764c5788a10SHemant Agrawal 		       (mbuf = mbuf->next)) {
765a74af788SAkhil Goyal 			cpu_to_hw_sg(sg);
766a74af788SAkhil Goyal 			sg++;
767a74af788SAkhil Goyal 			qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
768c5788a10SHemant Agrawal 			if (data_len > mbuf->data_len)
769a74af788SAkhil Goyal 				sg->length = mbuf->data_len;
770c5788a10SHemant Agrawal 			else
771c5788a10SHemant Agrawal 				sg->length = data_len;
772c5788a10SHemant Agrawal 		}
773a74af788SAkhil Goyal 	}
774a74af788SAkhil Goyal 
775a74af788SAkhil Goyal 	if (is_decode(ses)) {
776a74af788SAkhil Goyal 		/* Digest verification case */
777a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
778a74af788SAkhil Goyal 		sg++;
779a74af788SAkhil Goyal 		rte_memcpy(old_digest, sym->auth.digest.data,
780a74af788SAkhil Goyal 				ses->digest_length);
781ec861560SGagandeep Singh 		start_addr = rte_dpaa_mem_vtop(old_digest);
782a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, start_addr);
783a74af788SAkhil Goyal 		sg->length = ses->digest_length;
784a74af788SAkhil Goyal 		in_sg->length += ses->digest_length;
785a74af788SAkhil Goyal 	}
786a74af788SAkhil Goyal 	sg->final = 1;
787a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
788a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
789a74af788SAkhil Goyal 
790a74af788SAkhil Goyal 	return cf;
791a74af788SAkhil Goyal }
792a74af788SAkhil Goyal 
793c3e85bdcSAkhil Goyal /**
794c3e85bdcSAkhil Goyal  * packet looks like:
795c3e85bdcSAkhil Goyal  *		|<----data_len------->|
796c3e85bdcSAkhil Goyal  *    |ip_header|ah_header|icv|payload|
797c3e85bdcSAkhil Goyal  *              ^
798c3e85bdcSAkhil Goyal  *		|
799c3e85bdcSAkhil Goyal  *	   mbuf->pkt.data
800c3e85bdcSAkhil Goyal  */
801c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
802c3e85bdcSAkhil Goyal build_auth_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
803c3e85bdcSAkhil Goyal {
804c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
805c3e85bdcSAkhil Goyal 	struct rte_mbuf *mbuf = sym->m_src;
806c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
807c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
808c5788a10SHemant Agrawal 	struct qm_sg_entry *sg, *in_sg;
809c4509373SSantosh Shukla 	rte_iova_t start_addr;
810c3e85bdcSAkhil Goyal 	uint8_t *old_digest;
811c5788a10SHemant Agrawal 	int data_len, data_offset;
812c5788a10SHemant Agrawal 
813c5788a10SHemant Agrawal 	data_len = sym->auth.data.length;
814c5788a10SHemant Agrawal 	data_offset = sym->auth.data.offset;
815c5788a10SHemant Agrawal 
816c5788a10SHemant Agrawal 	if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
817c5788a10SHemant Agrawal 	    ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
818c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
819c5788a10SHemant Agrawal 			DPAA_SEC_ERR("AUTH: len/offset must be full bytes");
820c5788a10SHemant Agrawal 			return NULL;
821c5788a10SHemant Agrawal 		}
822c5788a10SHemant Agrawal 
823c5788a10SHemant Agrawal 		data_len = data_len >> 3;
824c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
825c5788a10SHemant Agrawal 	}
826c3e85bdcSAkhil Goyal 
827f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 4);
828c3e85bdcSAkhil Goyal 	if (!ctx)
829c3e85bdcSAkhil Goyal 		return NULL;
830c3e85bdcSAkhil Goyal 
831c3e85bdcSAkhil Goyal 	cf = &ctx->job;
832c3e85bdcSAkhil Goyal 	ctx->op = op;
833c3e85bdcSAkhil Goyal 	old_digest = ctx->digest;
834c3e85bdcSAkhil Goyal 
835bfa9a8a4SThomas Monjalon 	start_addr = rte_pktmbuf_iova(mbuf);
836c3e85bdcSAkhil Goyal 	/* output */
837c3e85bdcSAkhil Goyal 	sg = &cf->sg[0];
838c3e85bdcSAkhil Goyal 	qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
839c3e85bdcSAkhil Goyal 	sg->length = ses->digest_length;
840c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
841c3e85bdcSAkhil Goyal 
842c3e85bdcSAkhil Goyal 	/* input */
843c5788a10SHemant Agrawal 	in_sg = &cf->sg[1];
844c3e85bdcSAkhil Goyal 	/* need to extend the input to a compound frame */
845c5788a10SHemant Agrawal 	in_sg->extension = 1;
846c5788a10SHemant Agrawal 	in_sg->final = 1;
847c5788a10SHemant Agrawal 	in_sg->length = data_len;
848ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
849c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
850c5788a10SHemant Agrawal 
851c5788a10SHemant Agrawal 	if (ses->iv.length) {
852c5788a10SHemant Agrawal 		uint8_t *iv_ptr;
853c5788a10SHemant Agrawal 
854c5788a10SHemant Agrawal 		iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
855c5788a10SHemant Agrawal 						   ses->iv.offset);
856c5788a10SHemant Agrawal 
857c5788a10SHemant Agrawal 		if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
858c5788a10SHemant Agrawal 			iv_ptr = conv_to_snow_f9_iv(iv_ptr);
859c5788a10SHemant Agrawal 			sg->length = 12;
860c5788a10SHemant Agrawal 		} else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
861c5788a10SHemant Agrawal 			iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
862c5788a10SHemant Agrawal 			sg->length = 8;
863c5788a10SHemant Agrawal 		} else {
864c5788a10SHemant Agrawal 			sg->length = ses->iv.length;
865c5788a10SHemant Agrawal 		}
866ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(iv_ptr));
867c5788a10SHemant Agrawal 		in_sg->length += sg->length;
868c5788a10SHemant Agrawal 		cpu_to_hw_sg(sg);
869c5788a10SHemant Agrawal 		sg++;
870c5788a10SHemant Agrawal 	}
871c5788a10SHemant Agrawal 
872c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
873c5788a10SHemant Agrawal 	sg->offset = data_offset;
874c5788a10SHemant Agrawal 	sg->length = data_len;
875c5788a10SHemant Agrawal 
876c5788a10SHemant Agrawal 	if (is_decode(ses)) {
877c5788a10SHemant Agrawal 		/* Digest verification case */
878c5788a10SHemant Agrawal 		cpu_to_hw_sg(sg);
879c3e85bdcSAkhil Goyal 		/* hash result or digest, save digest first */
880c3e85bdcSAkhil Goyal 		rte_memcpy(old_digest, sym->auth.digest.data,
881c3e85bdcSAkhil Goyal 				ses->digest_length);
882c3e85bdcSAkhil Goyal 		/* let's check digest by hw */
883ec861560SGagandeep Singh 		start_addr = rte_dpaa_mem_vtop(old_digest);
884c3e85bdcSAkhil Goyal 		sg++;
885c3e85bdcSAkhil Goyal 		qm_sg_entry_set64(sg, start_addr);
886c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
887c5788a10SHemant Agrawal 		in_sg->length += ses->digest_length;
888c3e85bdcSAkhil Goyal 	}
889c5788a10SHemant Agrawal 	sg->final = 1;
890c5788a10SHemant Agrawal 	cpu_to_hw_sg(sg);
891c5788a10SHemant Agrawal 	cpu_to_hw_sg(in_sg);
892c3e85bdcSAkhil Goyal 
893c3e85bdcSAkhil Goyal 	return cf;
894c3e85bdcSAkhil Goyal }
895c3e85bdcSAkhil Goyal 
896c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
897a74af788SAkhil Goyal build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
898a74af788SAkhil Goyal {
899a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
900a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
901a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
902a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
903a74af788SAkhil Goyal 	struct rte_mbuf *mbuf;
904a74af788SAkhil Goyal 	uint8_t req_segs;
905a74af788SAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
906a74af788SAkhil Goyal 			ses->iv.offset);
907c5788a10SHemant Agrawal 	int data_len, data_offset;
908c5788a10SHemant Agrawal 
909c5788a10SHemant Agrawal 	data_len = sym->cipher.data.length;
910c5788a10SHemant Agrawal 	data_offset = sym->cipher.data.offset;
911c5788a10SHemant Agrawal 
912c5788a10SHemant Agrawal 	if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
913c5788a10SHemant Agrawal 		ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
914c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
915c5788a10SHemant Agrawal 			DPAA_SEC_ERR("CIPHER: len/offset must be full bytes");
916c5788a10SHemant Agrawal 			return NULL;
917c5788a10SHemant Agrawal 		}
918c5788a10SHemant Agrawal 
919c5788a10SHemant Agrawal 		data_len = data_len >> 3;
920c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
921c5788a10SHemant Agrawal 	}
922a74af788SAkhil Goyal 
923a74af788SAkhil Goyal 	if (sym->m_dst) {
924a74af788SAkhil Goyal 		mbuf = sym->m_dst;
925a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 3;
926a74af788SAkhil Goyal 	} else {
927a74af788SAkhil Goyal 		mbuf = sym->m_src;
928a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs * 2 + 3;
929a74af788SAkhil Goyal 	}
930f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
931f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("Cipher: Max sec segs supported is %d",
932a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
933a74af788SAkhil Goyal 		return NULL;
934a74af788SAkhil Goyal 	}
935a74af788SAkhil Goyal 
936f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
937a74af788SAkhil Goyal 	if (!ctx)
938a74af788SAkhil Goyal 		return NULL;
939a74af788SAkhil Goyal 
940a74af788SAkhil Goyal 	cf = &ctx->job;
941a74af788SAkhil Goyal 	ctx->op = op;
942a74af788SAkhil Goyal 
943a74af788SAkhil Goyal 	/* output */
944a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
945a74af788SAkhil Goyal 	out_sg->extension = 1;
946c5788a10SHemant Agrawal 	out_sg->length = data_len;
947ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
948a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
949a74af788SAkhil Goyal 
950a74af788SAkhil Goyal 	/* 1st seg */
951a74af788SAkhil Goyal 	sg = &cf->sg[2];
952a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
953c5788a10SHemant Agrawal 	sg->length = mbuf->data_len - data_offset;
954c5788a10SHemant Agrawal 	sg->offset = data_offset;
955a74af788SAkhil Goyal 
956a74af788SAkhil Goyal 	/* Successive segs */
957a74af788SAkhil Goyal 	mbuf = mbuf->next;
958a74af788SAkhil Goyal 	while (mbuf) {
959a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
960a74af788SAkhil Goyal 		sg++;
961a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
962a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
963a74af788SAkhil Goyal 		mbuf = mbuf->next;
964a74af788SAkhil Goyal 	}
965a74af788SAkhil Goyal 	sg->final = 1;
966a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
967a74af788SAkhil Goyal 
968a74af788SAkhil Goyal 	/* input */
969a74af788SAkhil Goyal 	mbuf = sym->m_src;
970a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
971a74af788SAkhil Goyal 	in_sg->extension = 1;
972a74af788SAkhil Goyal 	in_sg->final = 1;
973c5788a10SHemant Agrawal 	in_sg->length = data_len + ses->iv.length;
974a74af788SAkhil Goyal 
975a74af788SAkhil Goyal 	sg++;
976ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
977a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
978a74af788SAkhil Goyal 
979a74af788SAkhil Goyal 	/* IV */
980ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
981a74af788SAkhil Goyal 	sg->length = ses->iv.length;
982a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
983a74af788SAkhil Goyal 
984a74af788SAkhil Goyal 	/* 1st seg */
985a74af788SAkhil Goyal 	sg++;
986a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
987c5788a10SHemant Agrawal 	sg->length = mbuf->data_len - data_offset;
988c5788a10SHemant Agrawal 	sg->offset = data_offset;
989a74af788SAkhil Goyal 
990a74af788SAkhil Goyal 	/* Successive segs */
991a74af788SAkhil Goyal 	mbuf = mbuf->next;
992a74af788SAkhil Goyal 	while (mbuf) {
993a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
994a74af788SAkhil Goyal 		sg++;
995a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
996a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
997a74af788SAkhil Goyal 		mbuf = mbuf->next;
998a74af788SAkhil Goyal 	}
999a74af788SAkhil Goyal 	sg->final = 1;
1000a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1001a74af788SAkhil Goyal 
1002a74af788SAkhil Goyal 	return cf;
1003a74af788SAkhil Goyal }
1004a74af788SAkhil Goyal 
1005a74af788SAkhil Goyal static inline struct dpaa_sec_job *
1006c3e85bdcSAkhil Goyal build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
1007c3e85bdcSAkhil Goyal {
1008c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1009c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1010c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1011c3e85bdcSAkhil Goyal 	struct qm_sg_entry *sg;
1012c4509373SSantosh Shukla 	rte_iova_t src_start_addr, dst_start_addr;
1013c3e85bdcSAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1014c3e85bdcSAkhil Goyal 			ses->iv.offset);
1015c5788a10SHemant Agrawal 	int data_len, data_offset;
1016c5788a10SHemant Agrawal 
1017c5788a10SHemant Agrawal 	data_len = sym->cipher.data.length;
1018c5788a10SHemant Agrawal 	data_offset = sym->cipher.data.offset;
1019c5788a10SHemant Agrawal 
1020c5788a10SHemant Agrawal 	if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1021c5788a10SHemant Agrawal 		ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1022c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
1023c5788a10SHemant Agrawal 			DPAA_SEC_ERR("CIPHER: len/offset must be full bytes");
1024c5788a10SHemant Agrawal 			return NULL;
1025c5788a10SHemant Agrawal 		}
1026c5788a10SHemant Agrawal 
1027c5788a10SHemant Agrawal 		data_len = data_len >> 3;
1028c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
1029c5788a10SHemant Agrawal 	}
1030c3e85bdcSAkhil Goyal 
1031f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 4);
1032c3e85bdcSAkhil Goyal 	if (!ctx)
1033c3e85bdcSAkhil Goyal 		return NULL;
1034c3e85bdcSAkhil Goyal 
1035c3e85bdcSAkhil Goyal 	cf = &ctx->job;
1036c3e85bdcSAkhil Goyal 	ctx->op = op;
1037a389434eSAlok Makhariya 
1038bfa9a8a4SThomas Monjalon 	src_start_addr = rte_pktmbuf_iova(sym->m_src);
1039a389434eSAlok Makhariya 
1040a389434eSAlok Makhariya 	if (sym->m_dst)
1041bfa9a8a4SThomas Monjalon 		dst_start_addr = rte_pktmbuf_iova(sym->m_dst);
1042a389434eSAlok Makhariya 	else
1043a389434eSAlok Makhariya 		dst_start_addr = src_start_addr;
1044c3e85bdcSAkhil Goyal 
1045c3e85bdcSAkhil Goyal 	/* output */
1046c3e85bdcSAkhil Goyal 	sg = &cf->sg[0];
1047c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, dst_start_addr + data_offset);
1048c5788a10SHemant Agrawal 	sg->length = data_len + ses->iv.length;
1049c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1050c3e85bdcSAkhil Goyal 
1051c3e85bdcSAkhil Goyal 	/* input */
1052c3e85bdcSAkhil Goyal 	sg = &cf->sg[1];
1053c3e85bdcSAkhil Goyal 
1054c3e85bdcSAkhil Goyal 	/* need to extend the input to a compound frame */
1055c3e85bdcSAkhil Goyal 	sg->extension = 1;
1056c3e85bdcSAkhil Goyal 	sg->final = 1;
1057c5788a10SHemant Agrawal 	sg->length = data_len + ses->iv.length;
1058ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(&cf->sg[2]));
1059c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1060c3e85bdcSAkhil Goyal 
1061c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
1062ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1063c3e85bdcSAkhil Goyal 	sg->length = ses->iv.length;
1064c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1065c3e85bdcSAkhil Goyal 
1066c3e85bdcSAkhil Goyal 	sg++;
1067c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, src_start_addr + data_offset);
1068c5788a10SHemant Agrawal 	sg->length = data_len;
1069c3e85bdcSAkhil Goyal 	sg->final = 1;
1070c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1071c3e85bdcSAkhil Goyal 
1072c3e85bdcSAkhil Goyal 	return cf;
1073c3e85bdcSAkhil Goyal }
1074c3e85bdcSAkhil Goyal 
1075c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
1076a74af788SAkhil Goyal build_cipher_auth_gcm_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1077a74af788SAkhil Goyal {
1078a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1079a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
1080a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1081a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
1082a74af788SAkhil Goyal 	struct rte_mbuf *mbuf;
1083a74af788SAkhil Goyal 	uint8_t req_segs;
1084a74af788SAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1085a74af788SAkhil Goyal 			ses->iv.offset);
1086a74af788SAkhil Goyal 
1087a74af788SAkhil Goyal 	if (sym->m_dst) {
1088a74af788SAkhil Goyal 		mbuf = sym->m_dst;
1089a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4;
1090a74af788SAkhil Goyal 	} else {
1091a74af788SAkhil Goyal 		mbuf = sym->m_src;
1092a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs * 2 + 4;
1093a74af788SAkhil Goyal 	}
1094a74af788SAkhil Goyal 
1095a74af788SAkhil Goyal 	if (ses->auth_only_len)
1096a74af788SAkhil Goyal 		req_segs++;
1097a74af788SAkhil Goyal 
1098f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
1099f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("AEAD: Max sec segs supported is %d",
1100a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
1101a74af788SAkhil Goyal 		return NULL;
1102a74af788SAkhil Goyal 	}
1103a74af788SAkhil Goyal 
1104f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
1105a74af788SAkhil Goyal 	if (!ctx)
1106a74af788SAkhil Goyal 		return NULL;
1107a74af788SAkhil Goyal 
1108a74af788SAkhil Goyal 	cf = &ctx->job;
1109a74af788SAkhil Goyal 	ctx->op = op;
1110a74af788SAkhil Goyal 
1111a74af788SAkhil Goyal 	rte_prefetch0(cf->sg);
1112a74af788SAkhil Goyal 
1113a74af788SAkhil Goyal 	/* output */
1114a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
1115a74af788SAkhil Goyal 	out_sg->extension = 1;
1116a74af788SAkhil Goyal 	if (is_encode(ses))
11177a4a6da4SVakul Garg 		out_sg->length = sym->aead.data.length + ses->digest_length;
1118a74af788SAkhil Goyal 	else
11197a4a6da4SVakul Garg 		out_sg->length = sym->aead.data.length;
1120a74af788SAkhil Goyal 
1121a74af788SAkhil Goyal 	/* output sg entries */
1122a74af788SAkhil Goyal 	sg = &cf->sg[2];
1123ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(sg));
1124a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
1125a74af788SAkhil Goyal 
1126a74af788SAkhil Goyal 	/* 1st seg */
1127a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
11287a4a6da4SVakul Garg 	sg->length = mbuf->data_len - sym->aead.data.offset;
11297a4a6da4SVakul Garg 	sg->offset = sym->aead.data.offset;
1130a74af788SAkhil Goyal 
1131a74af788SAkhil Goyal 	/* Successive segs */
1132a74af788SAkhil Goyal 	mbuf = mbuf->next;
1133a74af788SAkhil Goyal 	while (mbuf) {
1134a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1135a74af788SAkhil Goyal 		sg++;
1136a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1137a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1138a74af788SAkhil Goyal 		mbuf = mbuf->next;
1139a74af788SAkhil Goyal 	}
1140a74af788SAkhil Goyal 	sg->length -= ses->digest_length;
1141a74af788SAkhil Goyal 
1142a74af788SAkhil Goyal 	if (is_encode(ses)) {
1143a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1144a74af788SAkhil Goyal 		/* set auth output */
1145a74af788SAkhil Goyal 		sg++;
1146a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, sym->aead.digest.phys_addr);
1147a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1148a74af788SAkhil Goyal 	}
1149a74af788SAkhil Goyal 	sg->final = 1;
1150a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1151a74af788SAkhil Goyal 
1152a74af788SAkhil Goyal 	/* input */
1153a74af788SAkhil Goyal 	mbuf = sym->m_src;
1154a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
1155a74af788SAkhil Goyal 	in_sg->extension = 1;
1156a74af788SAkhil Goyal 	in_sg->final = 1;
1157a74af788SAkhil Goyal 	if (is_encode(ses))
1158a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->aead.data.length
1159a74af788SAkhil Goyal 							+ ses->auth_only_len;
1160a74af788SAkhil Goyal 	else
1161a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->aead.data.length
1162a74af788SAkhil Goyal 				+ ses->auth_only_len + ses->digest_length;
1163a74af788SAkhil Goyal 
1164a74af788SAkhil Goyal 	/* input sg entries */
1165a74af788SAkhil Goyal 	sg++;
1166ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
1167a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
1168a74af788SAkhil Goyal 
1169a74af788SAkhil Goyal 	/* 1st seg IV */
1170ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1171a74af788SAkhil Goyal 	sg->length = ses->iv.length;
1172a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1173a74af788SAkhil Goyal 
1174a74af788SAkhil Goyal 	/* 2nd seg auth only */
1175a74af788SAkhil Goyal 	if (ses->auth_only_len) {
1176a74af788SAkhil Goyal 		sg++;
1177ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(sym->aead.aad.data));
1178a74af788SAkhil Goyal 		sg->length = ses->auth_only_len;
1179a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1180a74af788SAkhil Goyal 	}
1181a74af788SAkhil Goyal 
1182a74af788SAkhil Goyal 	/* 3rd seg */
1183a74af788SAkhil Goyal 	sg++;
1184a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1185a74af788SAkhil Goyal 	sg->length = mbuf->data_len - sym->aead.data.offset;
1186a74af788SAkhil Goyal 	sg->offset = sym->aead.data.offset;
1187a74af788SAkhil Goyal 
1188a74af788SAkhil Goyal 	/* Successive segs */
1189a74af788SAkhil Goyal 	mbuf = mbuf->next;
1190a74af788SAkhil Goyal 	while (mbuf) {
1191a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1192a74af788SAkhil Goyal 		sg++;
1193a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1194a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1195a74af788SAkhil Goyal 		mbuf = mbuf->next;
1196a74af788SAkhil Goyal 	}
1197a74af788SAkhil Goyal 
1198a74af788SAkhil Goyal 	if (is_decode(ses)) {
1199a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1200a74af788SAkhil Goyal 		sg++;
1201a74af788SAkhil Goyal 		memcpy(ctx->digest, sym->aead.digest.data,
1202a74af788SAkhil Goyal 			ses->digest_length);
1203ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1204a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1205a74af788SAkhil Goyal 	}
1206a74af788SAkhil Goyal 	sg->final = 1;
1207a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1208a74af788SAkhil Goyal 
1209a74af788SAkhil Goyal 	return cf;
1210a74af788SAkhil Goyal }
1211a74af788SAkhil Goyal 
1212a74af788SAkhil Goyal static inline struct dpaa_sec_job *
1213c3e85bdcSAkhil Goyal build_cipher_auth_gcm(struct rte_crypto_op *op, dpaa_sec_session *ses)
1214c3e85bdcSAkhil Goyal {
1215c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1216c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1217c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1218c3e85bdcSAkhil Goyal 	struct qm_sg_entry *sg;
1219c3e85bdcSAkhil Goyal 	uint32_t length = 0;
1220c4509373SSantosh Shukla 	rte_iova_t src_start_addr, dst_start_addr;
1221c3e85bdcSAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1222c3e85bdcSAkhil Goyal 			ses->iv.offset);
1223c3e85bdcSAkhil Goyal 
1224116ff44aSHemant Agrawal 	src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off;
1225a389434eSAlok Makhariya 
1226a389434eSAlok Makhariya 	if (sym->m_dst)
1227116ff44aSHemant Agrawal 		dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off;
1228a389434eSAlok Makhariya 	else
1229a389434eSAlok Makhariya 		dst_start_addr = src_start_addr;
1230c3e85bdcSAkhil Goyal 
1231f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 7);
1232c3e85bdcSAkhil Goyal 	if (!ctx)
1233c3e85bdcSAkhil Goyal 		return NULL;
1234c3e85bdcSAkhil Goyal 
1235c3e85bdcSAkhil Goyal 	cf = &ctx->job;
1236c3e85bdcSAkhil Goyal 	ctx->op = op;
1237c3e85bdcSAkhil Goyal 
1238c3e85bdcSAkhil Goyal 	/* input */
1239c3e85bdcSAkhil Goyal 	rte_prefetch0(cf->sg);
1240c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
1241ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[1], rte_dpaa_mem_vtop(sg));
1242c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1243ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1244c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1245c3e85bdcSAkhil Goyal 		length += sg->length;
1246c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1247c3e85bdcSAkhil Goyal 
1248c3e85bdcSAkhil Goyal 		sg++;
1249c3e85bdcSAkhil Goyal 		if (ses->auth_only_len) {
1250c3e85bdcSAkhil Goyal 			qm_sg_entry_set64(sg,
1251ec861560SGagandeep Singh 					  rte_dpaa_mem_vtop(sym->aead.aad.data));
1252c3e85bdcSAkhil Goyal 			sg->length = ses->auth_only_len;
1253c3e85bdcSAkhil Goyal 			length += sg->length;
1254c3e85bdcSAkhil Goyal 			cpu_to_hw_sg(sg);
1255c3e85bdcSAkhil Goyal 			sg++;
1256c3e85bdcSAkhil Goyal 		}
1257a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset);
1258c3e85bdcSAkhil Goyal 		sg->length = sym->aead.data.length;
1259c3e85bdcSAkhil Goyal 		length += sg->length;
1260c3e85bdcSAkhil Goyal 		sg->final = 1;
1261c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1262c3e85bdcSAkhil Goyal 	} else {
1263ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1264c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1265c3e85bdcSAkhil Goyal 		length += sg->length;
1266c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1267c3e85bdcSAkhil Goyal 
1268c3e85bdcSAkhil Goyal 		sg++;
1269c3e85bdcSAkhil Goyal 		if (ses->auth_only_len) {
1270c3e85bdcSAkhil Goyal 			qm_sg_entry_set64(sg,
1271ec861560SGagandeep Singh 					  rte_dpaa_mem_vtop(sym->aead.aad.data));
1272c3e85bdcSAkhil Goyal 			sg->length = ses->auth_only_len;
1273c3e85bdcSAkhil Goyal 			length += sg->length;
1274c3e85bdcSAkhil Goyal 			cpu_to_hw_sg(sg);
1275c3e85bdcSAkhil Goyal 			sg++;
1276c3e85bdcSAkhil Goyal 		}
1277a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset);
1278c3e85bdcSAkhil Goyal 		sg->length = sym->aead.data.length;
1279c3e85bdcSAkhil Goyal 		length += sg->length;
1280c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1281c3e85bdcSAkhil Goyal 
1282c3e85bdcSAkhil Goyal 		memcpy(ctx->digest, sym->aead.digest.data,
1283c3e85bdcSAkhil Goyal 		       ses->digest_length);
1284c3e85bdcSAkhil Goyal 		sg++;
1285c3e85bdcSAkhil Goyal 
1286ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1287c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1288c3e85bdcSAkhil Goyal 		length += sg->length;
1289c3e85bdcSAkhil Goyal 		sg->final = 1;
1290c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1291c3e85bdcSAkhil Goyal 	}
1292c3e85bdcSAkhil Goyal 	/* input compound frame */
1293c3e85bdcSAkhil Goyal 	cf->sg[1].length = length;
1294c3e85bdcSAkhil Goyal 	cf->sg[1].extension = 1;
1295c3e85bdcSAkhil Goyal 	cf->sg[1].final = 1;
1296c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[1]);
1297c3e85bdcSAkhil Goyal 
1298c3e85bdcSAkhil Goyal 	/* output */
1299c3e85bdcSAkhil Goyal 	sg++;
1300ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[0], rte_dpaa_mem_vtop(sg));
1301c3e85bdcSAkhil Goyal 	qm_sg_entry_set64(sg,
13027a4a6da4SVakul Garg 		dst_start_addr + sym->aead.data.offset);
13037a4a6da4SVakul Garg 	sg->length = sym->aead.data.length;
1304c3e85bdcSAkhil Goyal 	length = sg->length;
1305c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1306c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1307c3e85bdcSAkhil Goyal 		/* set auth output */
1308c3e85bdcSAkhil Goyal 		sg++;
1309c3e85bdcSAkhil Goyal 		qm_sg_entry_set64(sg, sym->aead.digest.phys_addr);
1310c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1311c3e85bdcSAkhil Goyal 		length += sg->length;
1312c3e85bdcSAkhil Goyal 	}
1313c3e85bdcSAkhil Goyal 	sg->final = 1;
1314c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1315c3e85bdcSAkhil Goyal 
1316c3e85bdcSAkhil Goyal 	/* output compound frame */
1317c3e85bdcSAkhil Goyal 	cf->sg[0].length = length;
1318c3e85bdcSAkhil Goyal 	cf->sg[0].extension = 1;
1319c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[0]);
1320c3e85bdcSAkhil Goyal 
1321c3e85bdcSAkhil Goyal 	return cf;
1322c3e85bdcSAkhil Goyal }
1323c3e85bdcSAkhil Goyal 
1324c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
1325a74af788SAkhil Goyal build_cipher_auth_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1326a74af788SAkhil Goyal {
1327a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1328a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
1329a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1330a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
1331a74af788SAkhil Goyal 	struct rte_mbuf *mbuf;
1332a74af788SAkhil Goyal 	uint8_t req_segs;
1333a74af788SAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1334a74af788SAkhil Goyal 			ses->iv.offset);
1335a74af788SAkhil Goyal 
1336a74af788SAkhil Goyal 	if (sym->m_dst) {
1337a74af788SAkhil Goyal 		mbuf = sym->m_dst;
1338a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4;
1339a74af788SAkhil Goyal 	} else {
1340a74af788SAkhil Goyal 		mbuf = sym->m_src;
1341a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs * 2 + 4;
1342a74af788SAkhil Goyal 	}
1343a74af788SAkhil Goyal 
1344f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
1345f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("Cipher-Auth: Max sec segs supported is %d",
1346a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
1347a74af788SAkhil Goyal 		return NULL;
1348a74af788SAkhil Goyal 	}
1349a74af788SAkhil Goyal 
1350f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
1351a74af788SAkhil Goyal 	if (!ctx)
1352a74af788SAkhil Goyal 		return NULL;
1353a74af788SAkhil Goyal 
1354a74af788SAkhil Goyal 	cf = &ctx->job;
1355a74af788SAkhil Goyal 	ctx->op = op;
1356a74af788SAkhil Goyal 
1357a74af788SAkhil Goyal 	rte_prefetch0(cf->sg);
1358a74af788SAkhil Goyal 
1359a74af788SAkhil Goyal 	/* output */
1360a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
1361a74af788SAkhil Goyal 	out_sg->extension = 1;
1362a74af788SAkhil Goyal 	if (is_encode(ses))
1363a74af788SAkhil Goyal 		out_sg->length = sym->auth.data.length + ses->digest_length;
1364a74af788SAkhil Goyal 	else
1365a74af788SAkhil Goyal 		out_sg->length = sym->auth.data.length;
1366a74af788SAkhil Goyal 
1367a74af788SAkhil Goyal 	/* output sg entries */
1368a74af788SAkhil Goyal 	sg = &cf->sg[2];
1369ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(sg));
1370a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
1371a74af788SAkhil Goyal 
1372a74af788SAkhil Goyal 	/* 1st seg */
1373a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1374a74af788SAkhil Goyal 	sg->length = mbuf->data_len - sym->auth.data.offset;
1375a74af788SAkhil Goyal 	sg->offset = sym->auth.data.offset;
1376a74af788SAkhil Goyal 
1377a74af788SAkhil Goyal 	/* Successive segs */
1378a74af788SAkhil Goyal 	mbuf = mbuf->next;
1379a74af788SAkhil Goyal 	while (mbuf) {
1380a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1381a74af788SAkhil Goyal 		sg++;
1382a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1383a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1384a74af788SAkhil Goyal 		mbuf = mbuf->next;
1385a74af788SAkhil Goyal 	}
1386a74af788SAkhil Goyal 	sg->length -= ses->digest_length;
1387a74af788SAkhil Goyal 
1388a74af788SAkhil Goyal 	if (is_encode(ses)) {
1389a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1390a74af788SAkhil Goyal 		/* set auth output */
1391a74af788SAkhil Goyal 		sg++;
1392a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
1393a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1394a74af788SAkhil Goyal 	}
1395a74af788SAkhil Goyal 	sg->final = 1;
1396a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1397a74af788SAkhil Goyal 
1398a74af788SAkhil Goyal 	/* input */
1399a74af788SAkhil Goyal 	mbuf = sym->m_src;
1400a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
1401a74af788SAkhil Goyal 	in_sg->extension = 1;
1402a74af788SAkhil Goyal 	in_sg->final = 1;
1403a74af788SAkhil Goyal 	if (is_encode(ses))
1404a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->auth.data.length;
1405a74af788SAkhil Goyal 	else
1406a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->auth.data.length
1407a74af788SAkhil Goyal 						+ ses->digest_length;
1408a74af788SAkhil Goyal 
1409a74af788SAkhil Goyal 	/* input sg entries */
1410a74af788SAkhil Goyal 	sg++;
1411ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
1412a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
1413a74af788SAkhil Goyal 
1414a74af788SAkhil Goyal 	/* 1st seg IV */
1415ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1416a74af788SAkhil Goyal 	sg->length = ses->iv.length;
1417a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1418a74af788SAkhil Goyal 
1419a74af788SAkhil Goyal 	/* 2nd seg */
1420a74af788SAkhil Goyal 	sg++;
1421a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1422a74af788SAkhil Goyal 	sg->length = mbuf->data_len - sym->auth.data.offset;
1423a74af788SAkhil Goyal 	sg->offset = sym->auth.data.offset;
1424a74af788SAkhil Goyal 
1425a74af788SAkhil Goyal 	/* Successive segs */
1426a74af788SAkhil Goyal 	mbuf = mbuf->next;
1427a74af788SAkhil Goyal 	while (mbuf) {
1428a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1429a74af788SAkhil Goyal 		sg++;
1430a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1431a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1432a74af788SAkhil Goyal 		mbuf = mbuf->next;
1433a74af788SAkhil Goyal 	}
1434a74af788SAkhil Goyal 
1435a74af788SAkhil Goyal 	sg->length -= ses->digest_length;
1436a74af788SAkhil Goyal 	if (is_decode(ses)) {
1437a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1438a74af788SAkhil Goyal 		sg++;
1439a74af788SAkhil Goyal 		memcpy(ctx->digest, sym->auth.digest.data,
1440a74af788SAkhil Goyal 			ses->digest_length);
1441ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1442a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1443a74af788SAkhil Goyal 	}
1444a74af788SAkhil Goyal 	sg->final = 1;
1445a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1446a74af788SAkhil Goyal 
1447a74af788SAkhil Goyal 	return cf;
1448a74af788SAkhil Goyal }
1449a74af788SAkhil Goyal 
1450a74af788SAkhil Goyal static inline struct dpaa_sec_job *
1451c3e85bdcSAkhil Goyal build_cipher_auth(struct rte_crypto_op *op, dpaa_sec_session *ses)
1452c3e85bdcSAkhil Goyal {
1453c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1454c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1455c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1456c3e85bdcSAkhil Goyal 	struct qm_sg_entry *sg;
1457c4509373SSantosh Shukla 	rte_iova_t src_start_addr, dst_start_addr;
1458c3e85bdcSAkhil Goyal 	uint32_t length = 0;
1459c3e85bdcSAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1460c3e85bdcSAkhil Goyal 			ses->iv.offset);
1461c3e85bdcSAkhil Goyal 
1462455da545SSantosh Shukla 	src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off;
1463a389434eSAlok Makhariya 	if (sym->m_dst)
1464455da545SSantosh Shukla 		dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off;
1465a389434eSAlok Makhariya 	else
1466a389434eSAlok Makhariya 		dst_start_addr = src_start_addr;
1467c3e85bdcSAkhil Goyal 
1468f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 7);
1469c3e85bdcSAkhil Goyal 	if (!ctx)
1470c3e85bdcSAkhil Goyal 		return NULL;
1471c3e85bdcSAkhil Goyal 
1472c3e85bdcSAkhil Goyal 	cf = &ctx->job;
1473c3e85bdcSAkhil Goyal 	ctx->op = op;
1474c3e85bdcSAkhil Goyal 
1475c3e85bdcSAkhil Goyal 	/* input */
1476c3e85bdcSAkhil Goyal 	rte_prefetch0(cf->sg);
1477c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
1478ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[1], rte_dpaa_mem_vtop(sg));
1479c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1480ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1481c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1482c3e85bdcSAkhil Goyal 		length += sg->length;
1483c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1484c3e85bdcSAkhil Goyal 
1485c3e85bdcSAkhil Goyal 		sg++;
1486a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset);
1487c3e85bdcSAkhil Goyal 		sg->length = sym->auth.data.length;
1488c3e85bdcSAkhil Goyal 		length += sg->length;
1489c3e85bdcSAkhil Goyal 		sg->final = 1;
1490c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1491c3e85bdcSAkhil Goyal 	} else {
1492ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1493c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1494c3e85bdcSAkhil Goyal 		length += sg->length;
1495c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1496c3e85bdcSAkhil Goyal 
1497c3e85bdcSAkhil Goyal 		sg++;
1498c3e85bdcSAkhil Goyal 
1499a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset);
1500c3e85bdcSAkhil Goyal 		sg->length = sym->auth.data.length;
1501c3e85bdcSAkhil Goyal 		length += sg->length;
1502c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1503c3e85bdcSAkhil Goyal 
1504c3e85bdcSAkhil Goyal 		memcpy(ctx->digest, sym->auth.digest.data,
1505c3e85bdcSAkhil Goyal 		       ses->digest_length);
1506c3e85bdcSAkhil Goyal 		sg++;
1507c3e85bdcSAkhil Goyal 
1508ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1509c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1510c3e85bdcSAkhil Goyal 		length += sg->length;
1511c3e85bdcSAkhil Goyal 		sg->final = 1;
1512c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1513c3e85bdcSAkhil Goyal 	}
1514c3e85bdcSAkhil Goyal 	/* input compound frame */
1515c3e85bdcSAkhil Goyal 	cf->sg[1].length = length;
1516c3e85bdcSAkhil Goyal 	cf->sg[1].extension = 1;
1517c3e85bdcSAkhil Goyal 	cf->sg[1].final = 1;
1518c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[1]);
1519c3e85bdcSAkhil Goyal 
1520c3e85bdcSAkhil Goyal 	/* output */
1521c3e85bdcSAkhil Goyal 	sg++;
1522ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[0], rte_dpaa_mem_vtop(sg));
1523a389434eSAlok Makhariya 	qm_sg_entry_set64(sg, dst_start_addr + sym->cipher.data.offset);
1524c3e85bdcSAkhil Goyal 	sg->length = sym->cipher.data.length;
1525c3e85bdcSAkhil Goyal 	length = sg->length;
1526c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1527c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1528c3e85bdcSAkhil Goyal 		/* set auth output */
1529c3e85bdcSAkhil Goyal 		sg++;
1530c3e85bdcSAkhil Goyal 		qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
1531c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1532c3e85bdcSAkhil Goyal 		length += sg->length;
1533c3e85bdcSAkhil Goyal 	}
1534c3e85bdcSAkhil Goyal 	sg->final = 1;
1535c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1536c3e85bdcSAkhil Goyal 
1537c3e85bdcSAkhil Goyal 	/* output compound frame */
1538c3e85bdcSAkhil Goyal 	cf->sg[0].length = length;
1539c3e85bdcSAkhil Goyal 	cf->sg[0].extension = 1;
1540c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[0]);
1541c3e85bdcSAkhil Goyal 
1542c3e85bdcSAkhil Goyal 	return cf;
1543c3e85bdcSAkhil Goyal }
1544c3e85bdcSAkhil Goyal 
1545314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
15461f14d500SAkhil Goyal static inline struct dpaa_sec_job *
15471f14d500SAkhil Goyal build_proto(struct rte_crypto_op *op, dpaa_sec_session *ses)
15481f14d500SAkhil Goyal {
15491f14d500SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
15501f14d500SAkhil Goyal 	struct dpaa_sec_job *cf;
15511f14d500SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
15521f14d500SAkhil Goyal 	struct qm_sg_entry *sg;
15531f14d500SAkhil Goyal 	phys_addr_t src_start_addr, dst_start_addr;
15541f14d500SAkhil Goyal 
1555f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 2);
15561f14d500SAkhil Goyal 	if (!ctx)
15571f14d500SAkhil Goyal 		return NULL;
15581f14d500SAkhil Goyal 	cf = &ctx->job;
15591f14d500SAkhil Goyal 	ctx->op = op;
15601f14d500SAkhil Goyal 
15611f14d500SAkhil Goyal 	src_start_addr = rte_pktmbuf_mtophys(sym->m_src);
15621f14d500SAkhil Goyal 
15631f14d500SAkhil Goyal 	if (sym->m_dst)
15641f14d500SAkhil Goyal 		dst_start_addr = rte_pktmbuf_mtophys(sym->m_dst);
15651f14d500SAkhil Goyal 	else
15661f14d500SAkhil Goyal 		dst_start_addr = src_start_addr;
15671f14d500SAkhil Goyal 
15681f14d500SAkhil Goyal 	/* input */
15691f14d500SAkhil Goyal 	sg = &cf->sg[1];
15701f14d500SAkhil Goyal 	qm_sg_entry_set64(sg, src_start_addr);
15711f14d500SAkhil Goyal 	sg->length = sym->m_src->pkt_len;
15721f14d500SAkhil Goyal 	sg->final = 1;
15731f14d500SAkhil Goyal 	cpu_to_hw_sg(sg);
15741f14d500SAkhil Goyal 
15751f14d500SAkhil Goyal 	sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK;
15761f14d500SAkhil Goyal 	/* output */
15771f14d500SAkhil Goyal 	sg = &cf->sg[0];
15781f14d500SAkhil Goyal 	qm_sg_entry_set64(sg, dst_start_addr);
15791f14d500SAkhil Goyal 	sg->length = sym->m_src->buf_len - sym->m_src->data_off;
15801f14d500SAkhil Goyal 	cpu_to_hw_sg(sg);
15811f14d500SAkhil Goyal 
15821f14d500SAkhil Goyal 	return cf;
15831f14d500SAkhil Goyal }
15841f14d500SAkhil Goyal 
1585fb5c100aSAkhil Goyal static inline struct dpaa_sec_job *
1586fb5c100aSAkhil Goyal build_proto_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1587fb5c100aSAkhil Goyal {
1588fb5c100aSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1589fb5c100aSAkhil Goyal 	struct dpaa_sec_job *cf;
1590fb5c100aSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1591fb5c100aSAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
1592fb5c100aSAkhil Goyal 	struct rte_mbuf *mbuf;
1593fb5c100aSAkhil Goyal 	uint8_t req_segs;
1594fb5c100aSAkhil Goyal 	uint32_t in_len = 0, out_len = 0;
1595fb5c100aSAkhil Goyal 
1596fb5c100aSAkhil Goyal 	if (sym->m_dst)
1597fb5c100aSAkhil Goyal 		mbuf = sym->m_dst;
1598fb5c100aSAkhil Goyal 	else
1599fb5c100aSAkhil Goyal 		mbuf = sym->m_src;
1600fb5c100aSAkhil Goyal 
1601fb5c100aSAkhil Goyal 	req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 2;
1602f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
1603fb5c100aSAkhil Goyal 		DPAA_SEC_DP_ERR("Proto: Max sec segs supported is %d",
1604fb5c100aSAkhil Goyal 				MAX_SG_ENTRIES);
1605fb5c100aSAkhil Goyal 		return NULL;
1606fb5c100aSAkhil Goyal 	}
1607fb5c100aSAkhil Goyal 
1608f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
1609fb5c100aSAkhil Goyal 	if (!ctx)
1610fb5c100aSAkhil Goyal 		return NULL;
1611fb5c100aSAkhil Goyal 	cf = &ctx->job;
1612fb5c100aSAkhil Goyal 	ctx->op = op;
1613fb5c100aSAkhil Goyal 	/* output */
1614fb5c100aSAkhil Goyal 	out_sg = &cf->sg[0];
1615fb5c100aSAkhil Goyal 	out_sg->extension = 1;
1616ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
1617fb5c100aSAkhil Goyal 
1618fb5c100aSAkhil Goyal 	/* 1st seg */
1619fb5c100aSAkhil Goyal 	sg = &cf->sg[2];
1620fb5c100aSAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1621fb5c100aSAkhil Goyal 	sg->offset = 0;
1622fb5c100aSAkhil Goyal 
1623fb5c100aSAkhil Goyal 	/* Successive segs */
1624fb5c100aSAkhil Goyal 	while (mbuf->next) {
1625fb5c100aSAkhil Goyal 		sg->length = mbuf->data_len;
1626fb5c100aSAkhil Goyal 		out_len += sg->length;
1627fb5c100aSAkhil Goyal 		mbuf = mbuf->next;
1628fb5c100aSAkhil Goyal 		cpu_to_hw_sg(sg);
1629fb5c100aSAkhil Goyal 		sg++;
1630fb5c100aSAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1631fb5c100aSAkhil Goyal 		sg->offset = 0;
1632fb5c100aSAkhil Goyal 	}
1633fb5c100aSAkhil Goyal 	sg->length = mbuf->buf_len - mbuf->data_off;
1634fb5c100aSAkhil Goyal 	out_len += sg->length;
1635fb5c100aSAkhil Goyal 	sg->final = 1;
1636fb5c100aSAkhil Goyal 	cpu_to_hw_sg(sg);
1637fb5c100aSAkhil Goyal 
1638fb5c100aSAkhil Goyal 	out_sg->length = out_len;
1639fb5c100aSAkhil Goyal 	cpu_to_hw_sg(out_sg);
1640fb5c100aSAkhil Goyal 
1641fb5c100aSAkhil Goyal 	/* input */
1642fb5c100aSAkhil Goyal 	mbuf = sym->m_src;
1643fb5c100aSAkhil Goyal 	in_sg = &cf->sg[1];
1644fb5c100aSAkhil Goyal 	in_sg->extension = 1;
1645fb5c100aSAkhil Goyal 	in_sg->final = 1;
1646fb5c100aSAkhil Goyal 	in_len = mbuf->data_len;
1647fb5c100aSAkhil Goyal 
1648fb5c100aSAkhil Goyal 	sg++;
1649ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
1650fb5c100aSAkhil Goyal 
1651fb5c100aSAkhil Goyal 	/* 1st seg */
1652fb5c100aSAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1653fb5c100aSAkhil Goyal 	sg->length = mbuf->data_len;
1654fb5c100aSAkhil Goyal 	sg->offset = 0;
1655fb5c100aSAkhil Goyal 
1656fb5c100aSAkhil Goyal 	/* Successive segs */
1657fb5c100aSAkhil Goyal 	mbuf = mbuf->next;
1658fb5c100aSAkhil Goyal 	while (mbuf) {
1659fb5c100aSAkhil Goyal 		cpu_to_hw_sg(sg);
1660fb5c100aSAkhil Goyal 		sg++;
1661fb5c100aSAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1662fb5c100aSAkhil Goyal 		sg->length = mbuf->data_len;
1663fb5c100aSAkhil Goyal 		sg->offset = 0;
1664fb5c100aSAkhil Goyal 		in_len += sg->length;
1665fb5c100aSAkhil Goyal 		mbuf = mbuf->next;
1666fb5c100aSAkhil Goyal 	}
1667fb5c100aSAkhil Goyal 	sg->final = 1;
1668fb5c100aSAkhil Goyal 	cpu_to_hw_sg(sg);
1669fb5c100aSAkhil Goyal 
1670fb5c100aSAkhil Goyal 	in_sg->length = in_len;
1671fb5c100aSAkhil Goyal 	cpu_to_hw_sg(in_sg);
1672fb5c100aSAkhil Goyal 
1673fb5c100aSAkhil Goyal 	sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK;
1674fb5c100aSAkhil Goyal 
1675fb5c100aSAkhil Goyal 	return cf;
1676fb5c100aSAkhil Goyal }
1677314424b6SHemant Agrawal #endif
1678fb5c100aSAkhil Goyal 
16799a984458SAkhil Goyal static uint16_t
16809a984458SAkhil Goyal dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
16819a984458SAkhil Goyal 		       uint16_t nb_ops)
1682c3e85bdcSAkhil Goyal {
16839a984458SAkhil Goyal 	/* Function to transmit the frames to given device and queuepair */
16849a984458SAkhil Goyal 	uint32_t loop;
16859a984458SAkhil Goyal 	struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp;
16869a984458SAkhil Goyal 	uint16_t num_tx = 0;
16879a984458SAkhil Goyal 	struct qm_fd fds[DPAA_SEC_BURST], *fd;
16889a984458SAkhil Goyal 	uint32_t frames_to_send;
16899a984458SAkhil Goyal 	struct rte_crypto_op *op;
1690c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1691c3e85bdcSAkhil Goyal 	dpaa_sec_session *ses;
16923394ed47SVakul Garg 	uint16_t auth_hdr_len, auth_tail_len;
16933394ed47SVakul Garg 	uint32_t index, flags[DPAA_SEC_BURST] = {0};
16949a984458SAkhil Goyal 	struct qman_fq *inq[DPAA_SEC_BURST];
1695c3e85bdcSAkhil Goyal 
16969a984458SAkhil Goyal 	while (nb_ops) {
16979a984458SAkhil Goyal 		frames_to_send = (nb_ops > DPAA_SEC_BURST) ?
16989a984458SAkhil Goyal 				DPAA_SEC_BURST : nb_ops;
16999a984458SAkhil Goyal 		for (loop = 0; loop < frames_to_send; loop++) {
17009a984458SAkhil Goyal 			op = *(ops++);
1701fe3688baSAkhil Goyal 			if (op->sym->m_src->seqn != 0) {
1702fe3688baSAkhil Goyal 				index = op->sym->m_src->seqn - 1;
1703fe3688baSAkhil Goyal 				if (DPAA_PER_LCORE_DQRR_HELD & (1 << index)) {
1704fe3688baSAkhil Goyal 					/* QM_EQCR_DCA_IDXMASK = 0x0f */
1705fe3688baSAkhil Goyal 					flags[loop] = ((index & 0x0f) << 8);
1706fe3688baSAkhil Goyal 					flags[loop] |= QMAN_ENQUEUE_FLAG_DCA;
1707fe3688baSAkhil Goyal 					DPAA_PER_LCORE_DQRR_SIZE--;
1708fe3688baSAkhil Goyal 					DPAA_PER_LCORE_DQRR_HELD &=
1709fe3688baSAkhil Goyal 								~(1 << index);
1710fe3688baSAkhil Goyal 				}
1711fe3688baSAkhil Goyal 			}
1712fe3688baSAkhil Goyal 
17139a984458SAkhil Goyal 			switch (op->sess_type) {
17149a984458SAkhil Goyal 			case RTE_CRYPTO_OP_WITH_SESSION:
17159a984458SAkhil Goyal 				ses = (dpaa_sec_session *)
1716012c5076SPablo de Lara 					get_sym_session_private_data(
17179a984458SAkhil Goyal 							op->sym->session,
17189a984458SAkhil Goyal 							cryptodev_driver_id);
17199a984458SAkhil Goyal 				break;
1720314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
17219a984458SAkhil Goyal 			case RTE_CRYPTO_OP_SECURITY_SESSION:
17229a984458SAkhil Goyal 				ses = (dpaa_sec_session *)
17239a984458SAkhil Goyal 					get_sec_session_private_data(
17241f14d500SAkhil Goyal 							op->sym->sec_session);
17259a984458SAkhil Goyal 				break;
1726314424b6SHemant Agrawal #endif
17279a984458SAkhil Goyal 			default:
1728f163231eSHemant Agrawal 				DPAA_SEC_DP_ERR(
17299a984458SAkhil Goyal 					"sessionless crypto op not supported");
17309a984458SAkhil Goyal 				frames_to_send = loop;
17319a984458SAkhil Goyal 				nb_ops = loop;
17329a984458SAkhil Goyal 				goto send_pkts;
17339a984458SAkhil Goyal 			}
1734e1e52232SHemant Agrawal 
1735e1e52232SHemant Agrawal 			if (!ses) {
1736e1e52232SHemant Agrawal 				DPAA_SEC_DP_ERR("session not available");
1737e1e52232SHemant Agrawal 				frames_to_send = loop;
1738e1e52232SHemant Agrawal 				nb_ops = loop;
1739e1e52232SHemant Agrawal 				goto send_pkts;
1740e1e52232SHemant Agrawal 			}
1741e1e52232SHemant Agrawal 
17424e694fe5SAkhil Goyal 			if (unlikely(!ses->qp[rte_lcore_id() % MAX_DPAA_CORES])) {
17439a984458SAkhil Goyal 				if (dpaa_sec_attach_sess_q(qp, ses)) {
17449a984458SAkhil Goyal 					frames_to_send = loop;
17459a984458SAkhil Goyal 					nb_ops = loop;
17469a984458SAkhil Goyal 					goto send_pkts;
17479a984458SAkhil Goyal 				}
17484e694fe5SAkhil Goyal 			} else if (unlikely(ses->qp[rte_lcore_id() %
17494e694fe5SAkhil Goyal 						MAX_DPAA_CORES] != qp)) {
17509198b2c2SAkhil Goyal 				DPAA_SEC_DP_ERR("Old:sess->qp = %p"
17514e694fe5SAkhil Goyal 					" New qp = %p\n",
17524e694fe5SAkhil Goyal 					ses->qp[rte_lcore_id() %
17534e694fe5SAkhil Goyal 					MAX_DPAA_CORES], qp);
17549198b2c2SAkhil Goyal 				frames_to_send = loop;
17559198b2c2SAkhil Goyal 				nb_ops = loop;
17569198b2c2SAkhil Goyal 				goto send_pkts;
1757c3e85bdcSAkhil Goyal 			}
1758c3e85bdcSAkhil Goyal 
17593394ed47SVakul Garg 			auth_hdr_len = op->sym->auth.data.length -
17609a984458SAkhil Goyal 						op->sym->cipher.data.length;
17613394ed47SVakul Garg 			auth_tail_len = 0;
17623394ed47SVakul Garg 
1763fb5c100aSAkhil Goyal 			if (rte_pktmbuf_is_contiguous(op->sym->m_src) &&
1764fb5c100aSAkhil Goyal 				  ((op->sym->m_dst == NULL) ||
1765fb5c100aSAkhil Goyal 				   rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
17668524b44eSHemant Agrawal 				switch (ses->ctxt) {
1767314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
17688524b44eSHemant Agrawal 				case DPAA_SEC_PDCP:
17698524b44eSHemant Agrawal 				case DPAA_SEC_IPSEC:
177005b12700SHemant Agrawal 					cf = build_proto(op, ses);
17718524b44eSHemant Agrawal 					break;
1772314424b6SHemant Agrawal #endif
17738524b44eSHemant Agrawal 				case DPAA_SEC_AUTH:
1774c3e85bdcSAkhil Goyal 					cf = build_auth_only(op, ses);
17758524b44eSHemant Agrawal 					break;
17768524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER:
1777c3e85bdcSAkhil Goyal 					cf = build_cipher_only(op, ses);
17788524b44eSHemant Agrawal 					break;
17798524b44eSHemant Agrawal 				case DPAA_SEC_AEAD:
1780c3e85bdcSAkhil Goyal 					cf = build_cipher_auth_gcm(op, ses);
17813394ed47SVakul Garg 					auth_hdr_len = ses->auth_only_len;
17828524b44eSHemant Agrawal 					break;
17838524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER_HASH:
17843394ed47SVakul Garg 					auth_hdr_len =
17853394ed47SVakul Garg 						op->sym->cipher.data.offset
17863394ed47SVakul Garg 						- op->sym->auth.data.offset;
17873394ed47SVakul Garg 					auth_tail_len =
17883394ed47SVakul Garg 						op->sym->auth.data.length
17893394ed47SVakul Garg 						- op->sym->cipher.data.length
17903394ed47SVakul Garg 						- auth_hdr_len;
1791c3e85bdcSAkhil Goyal 					cf = build_cipher_auth(op, ses);
17928524b44eSHemant Agrawal 					break;
17938524b44eSHemant Agrawal 				default:
1794f163231eSHemant Agrawal 					DPAA_SEC_DP_ERR("not supported ops");
17959a984458SAkhil Goyal 					frames_to_send = loop;
17969a984458SAkhil Goyal 					nb_ops = loop;
17979a984458SAkhil Goyal 					goto send_pkts;
1798c3e85bdcSAkhil Goyal 				}
1799a74af788SAkhil Goyal 			} else {
18008524b44eSHemant Agrawal 				switch (ses->ctxt) {
1801314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
18028524b44eSHemant Agrawal 				case DPAA_SEC_PDCP:
18038524b44eSHemant Agrawal 				case DPAA_SEC_IPSEC:
1804fb5c100aSAkhil Goyal 					cf = build_proto_sg(op, ses);
18058524b44eSHemant Agrawal 					break;
1806314424b6SHemant Agrawal #endif
18078524b44eSHemant Agrawal 				case DPAA_SEC_AUTH:
1808a74af788SAkhil Goyal 					cf = build_auth_only_sg(op, ses);
18098524b44eSHemant Agrawal 					break;
18108524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER:
1811a74af788SAkhil Goyal 					cf = build_cipher_only_sg(op, ses);
18128524b44eSHemant Agrawal 					break;
18138524b44eSHemant Agrawal 				case DPAA_SEC_AEAD:
1814a74af788SAkhil Goyal 					cf = build_cipher_auth_gcm_sg(op, ses);
18153394ed47SVakul Garg 					auth_hdr_len = ses->auth_only_len;
18168524b44eSHemant Agrawal 					break;
18178524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER_HASH:
18183394ed47SVakul Garg 					auth_hdr_len =
18193394ed47SVakul Garg 						op->sym->cipher.data.offset
18203394ed47SVakul Garg 						- op->sym->auth.data.offset;
18213394ed47SVakul Garg 					auth_tail_len =
18223394ed47SVakul Garg 						op->sym->auth.data.length
18233394ed47SVakul Garg 						- op->sym->cipher.data.length
18243394ed47SVakul Garg 						- auth_hdr_len;
1825a74af788SAkhil Goyal 					cf = build_cipher_auth_sg(op, ses);
18268524b44eSHemant Agrawal 					break;
18278524b44eSHemant Agrawal 				default:
1828f163231eSHemant Agrawal 					DPAA_SEC_DP_ERR("not supported ops");
1829a74af788SAkhil Goyal 					frames_to_send = loop;
1830a74af788SAkhil Goyal 					nb_ops = loop;
1831a74af788SAkhil Goyal 					goto send_pkts;
1832a74af788SAkhil Goyal 				}
1833a74af788SAkhil Goyal 			}
18349a984458SAkhil Goyal 			if (unlikely(!cf)) {
18359a984458SAkhil Goyal 				frames_to_send = loop;
18369a984458SAkhil Goyal 				nb_ops = loop;
18379a984458SAkhil Goyal 				goto send_pkts;
18389a984458SAkhil Goyal 			}
1839c3e85bdcSAkhil Goyal 
18409a984458SAkhil Goyal 			fd = &fds[loop];
18414e694fe5SAkhil Goyal 			inq[loop] = ses->inq[rte_lcore_id() % MAX_DPAA_CORES];
18429a984458SAkhil Goyal 			fd->opaque_addr = 0;
18439a984458SAkhil Goyal 			fd->cmd = 0;
1844ec861560SGagandeep Singh 			qm_fd_addr_set64(fd, rte_dpaa_mem_vtop(cf->sg));
18459a984458SAkhil Goyal 			fd->_format1 = qm_fd_compound;
18469a984458SAkhil Goyal 			fd->length29 = 2 * sizeof(struct qm_sg_entry);
18473394ed47SVakul Garg 
18489a984458SAkhil Goyal 			/* Auth_only_len is set as 0 in descriptor and it is
18499a984458SAkhil Goyal 			 * overwritten here in the fd.cmd which will update
18509a984458SAkhil Goyal 			 * the DPOVRD reg.
1851c3e85bdcSAkhil Goyal 			 */
18523394ed47SVakul Garg 			if (auth_hdr_len || auth_tail_len) {
18533394ed47SVakul Garg 				fd->cmd = 0x80000000;
18543394ed47SVakul Garg 				fd->cmd |=
18553394ed47SVakul Garg 					((auth_tail_len << 16) | auth_hdr_len);
18563394ed47SVakul Garg 			}
1857c3e85bdcSAkhil Goyal 
1858314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
18596a0c9d36SAkhil Goyal 			/* In case of PDCP, per packet HFN is stored in
18606a0c9d36SAkhil Goyal 			 * mbuf priv after sym_op.
18616a0c9d36SAkhil Goyal 			 */
18628524b44eSHemant Agrawal 			if ((ses->ctxt == DPAA_SEC_PDCP) && ses->pdcp.hfn_ovd) {
18636a0c9d36SAkhil Goyal 				fd->cmd = 0x80000000 |
18646a0c9d36SAkhil Goyal 					*((uint32_t *)((uint8_t *)op +
18656a0c9d36SAkhil Goyal 					ses->pdcp.hfn_ovd_offset));
18668524b44eSHemant Agrawal 				DPAA_SEC_DP_DEBUG("Per packet HFN: %x, ovd:%u\n",
18676a0c9d36SAkhil Goyal 					*((uint32_t *)((uint8_t *)op +
18686a0c9d36SAkhil Goyal 					ses->pdcp.hfn_ovd_offset)),
18698524b44eSHemant Agrawal 					ses->pdcp.hfn_ovd);
18706a0c9d36SAkhil Goyal 			}
1871314424b6SHemant Agrawal #endif
18729a984458SAkhil Goyal 		}
18739a984458SAkhil Goyal send_pkts:
18749a984458SAkhil Goyal 		loop = 0;
18759a984458SAkhil Goyal 		while (loop < frames_to_send) {
18769a984458SAkhil Goyal 			loop += qman_enqueue_multi_fq(&inq[loop], &fds[loop],
1877fe3688baSAkhil Goyal 					&flags[loop], frames_to_send - loop);
18789a984458SAkhil Goyal 		}
18799a984458SAkhil Goyal 		nb_ops -= frames_to_send;
18809a984458SAkhil Goyal 		num_tx += frames_to_send;
1881c3e85bdcSAkhil Goyal 	}
1882c3e85bdcSAkhil Goyal 
1883c3e85bdcSAkhil Goyal 	dpaa_qp->tx_pkts += num_tx;
1884c3e85bdcSAkhil Goyal 	dpaa_qp->tx_errs += nb_ops - num_tx;
1885c3e85bdcSAkhil Goyal 
1886c3e85bdcSAkhil Goyal 	return num_tx;
1887c3e85bdcSAkhil Goyal }
1888c3e85bdcSAkhil Goyal 
1889c3e85bdcSAkhil Goyal static uint16_t
1890c3e85bdcSAkhil Goyal dpaa_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1891c3e85bdcSAkhil Goyal 		       uint16_t nb_ops)
1892c3e85bdcSAkhil Goyal {
1893c3e85bdcSAkhil Goyal 	uint16_t num_rx;
1894c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp;
1895c3e85bdcSAkhil Goyal 
1896c3e85bdcSAkhil Goyal 	num_rx = dpaa_sec_deq(dpaa_qp, ops, nb_ops);
1897c3e85bdcSAkhil Goyal 
1898c3e85bdcSAkhil Goyal 	dpaa_qp->rx_pkts += num_rx;
1899c3e85bdcSAkhil Goyal 	dpaa_qp->rx_errs += nb_ops - num_rx;
1900c3e85bdcSAkhil Goyal 
1901f163231eSHemant Agrawal 	DPAA_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1902c3e85bdcSAkhil Goyal 
1903c3e85bdcSAkhil Goyal 	return num_rx;
1904c3e85bdcSAkhil Goyal }
1905c3e85bdcSAkhil Goyal 
1906c3e85bdcSAkhil Goyal /** Release queue pair */
1907c3e85bdcSAkhil Goyal static int
1908c3e85bdcSAkhil Goyal dpaa_sec_queue_pair_release(struct rte_cryptodev *dev,
1909c3e85bdcSAkhil Goyal 			    uint16_t qp_id)
1910c3e85bdcSAkhil Goyal {
1911c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals;
1912c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *qp = NULL;
1913c3e85bdcSAkhil Goyal 
1914c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
1915c3e85bdcSAkhil Goyal 
1916f163231eSHemant Agrawal 	DPAA_SEC_DEBUG("dev =%p, queue =%d", dev, qp_id);
1917c3e85bdcSAkhil Goyal 
1918c3e85bdcSAkhil Goyal 	internals = dev->data->dev_private;
1919c3e85bdcSAkhil Goyal 	if (qp_id >= internals->max_nb_queue_pairs) {
1920f163231eSHemant Agrawal 		DPAA_SEC_ERR("Max supported qpid %d",
1921c3e85bdcSAkhil Goyal 			     internals->max_nb_queue_pairs);
1922c3e85bdcSAkhil Goyal 		return -EINVAL;
1923c3e85bdcSAkhil Goyal 	}
1924c3e85bdcSAkhil Goyal 
1925c3e85bdcSAkhil Goyal 	qp = &internals->qps[qp_id];
19262ffb940eSAkhil Goyal 	rte_mempool_free(qp->ctx_pool);
1927c3e85bdcSAkhil Goyal 	qp->internals = NULL;
1928c3e85bdcSAkhil Goyal 	dev->data->queue_pairs[qp_id] = NULL;
1929c3e85bdcSAkhil Goyal 
1930c3e85bdcSAkhil Goyal 	return 0;
1931c3e85bdcSAkhil Goyal }
1932c3e85bdcSAkhil Goyal 
1933c3e85bdcSAkhil Goyal /** Setup a queue pair */
1934c3e85bdcSAkhil Goyal static int
1935c3e85bdcSAkhil Goyal dpaa_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1936c3e85bdcSAkhil Goyal 		__rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1937725d2a7fSFan Zhang 		__rte_unused int socket_id)
1938c3e85bdcSAkhil Goyal {
1939c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals;
1940c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *qp = NULL;
19412ffb940eSAkhil Goyal 	char str[20];
1942c3e85bdcSAkhil Goyal 
1943f163231eSHemant Agrawal 	DPAA_SEC_DEBUG("dev =%p, queue =%d, conf =%p", dev, qp_id, qp_conf);
1944c3e85bdcSAkhil Goyal 
1945c3e85bdcSAkhil Goyal 	internals = dev->data->dev_private;
1946c3e85bdcSAkhil Goyal 	if (qp_id >= internals->max_nb_queue_pairs) {
1947f163231eSHemant Agrawal 		DPAA_SEC_ERR("Max supported qpid %d",
1948c3e85bdcSAkhil Goyal 			     internals->max_nb_queue_pairs);
1949c3e85bdcSAkhil Goyal 		return -EINVAL;
1950c3e85bdcSAkhil Goyal 	}
1951c3e85bdcSAkhil Goyal 
1952c3e85bdcSAkhil Goyal 	qp = &internals->qps[qp_id];
1953c3e85bdcSAkhil Goyal 	qp->internals = internals;
19542ffb940eSAkhil Goyal 	snprintf(str, sizeof(str), "ctx_pool_d%d_qp%d",
19552ffb940eSAkhil Goyal 			dev->data->dev_id, qp_id);
19562ffb940eSAkhil Goyal 	if (!qp->ctx_pool) {
19572ffb940eSAkhil Goyal 		qp->ctx_pool = rte_mempool_create((const char *)str,
19582ffb940eSAkhil Goyal 							CTX_POOL_NUM_BUFS,
19592ffb940eSAkhil Goyal 							CTX_POOL_BUF_SIZE,
19602ffb940eSAkhil Goyal 							CTX_POOL_CACHE_SIZE, 0,
19612ffb940eSAkhil Goyal 							NULL, NULL, NULL, NULL,
19622ffb940eSAkhil Goyal 							SOCKET_ID_ANY, 0);
19632ffb940eSAkhil Goyal 		if (!qp->ctx_pool) {
19642ffb940eSAkhil Goyal 			DPAA_SEC_ERR("%s create failed\n", str);
19652ffb940eSAkhil Goyal 			return -ENOMEM;
19662ffb940eSAkhil Goyal 		}
19672ffb940eSAkhil Goyal 	} else
19682ffb940eSAkhil Goyal 		DPAA_SEC_INFO("mempool already created for dev_id : %d, qp: %d",
19692ffb940eSAkhil Goyal 				dev->data->dev_id, qp_id);
1970c3e85bdcSAkhil Goyal 	dev->data->queue_pairs[qp_id] = qp;
1971c3e85bdcSAkhil Goyal 
1972c3e85bdcSAkhil Goyal 	return 0;
1973c3e85bdcSAkhil Goyal }
1974c3e85bdcSAkhil Goyal 
1975c3e85bdcSAkhil Goyal /** Returns the size of session structure */
1976c3e85bdcSAkhil Goyal static unsigned int
1977012c5076SPablo de Lara dpaa_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1978c3e85bdcSAkhil Goyal {
1979c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
1980c3e85bdcSAkhil Goyal 
1981c3e85bdcSAkhil Goyal 	return sizeof(dpaa_sec_session);
1982c3e85bdcSAkhil Goyal }
1983c3e85bdcSAkhil Goyal 
1984c3e85bdcSAkhil Goyal static int
1985c3e85bdcSAkhil Goyal dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
1986c3e85bdcSAkhil Goyal 		     struct rte_crypto_sym_xform *xform,
1987c3e85bdcSAkhil Goyal 		     dpaa_sec_session *session)
1988c3e85bdcSAkhil Goyal {
1989f73d6928SHemant Agrawal 	session->ctxt = DPAA_SEC_CIPHER;
1990c3e85bdcSAkhil Goyal 	session->cipher_alg = xform->cipher.algo;
1991c3e85bdcSAkhil Goyal 	session->iv.length = xform->cipher.iv.length;
1992c3e85bdcSAkhil Goyal 	session->iv.offset = xform->cipher.iv.offset;
1993c3e85bdcSAkhil Goyal 	session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1994c3e85bdcSAkhil Goyal 					       RTE_CACHE_LINE_SIZE);
1995c3e85bdcSAkhil Goyal 	if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
1996f163231eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for cipher key");
1997c3e85bdcSAkhil Goyal 		return -ENOMEM;
1998c3e85bdcSAkhil Goyal 	}
1999c3e85bdcSAkhil Goyal 	session->cipher_key.length = xform->cipher.key.length;
2000c3e85bdcSAkhil Goyal 
2001c3e85bdcSAkhil Goyal 	memcpy(session->cipher_key.data, xform->cipher.key.data,
2002c3e85bdcSAkhil Goyal 	       xform->cipher.key.length);
20038524b44eSHemant Agrawal 	switch (xform->cipher.algo) {
20048524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CBC:
20058524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
20068524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
20078524b44eSHemant Agrawal 		break;
20088524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_CBC:
20098524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_3DES;
20108524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
20118524b44eSHemant Agrawal 		break;
20128524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CTR:
20138524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
20148524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CTR;
20158524b44eSHemant Agrawal 		break;
20168524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
20178524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_SNOW_F8;
20188524b44eSHemant Agrawal 		break;
20198524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_ZUC_EEA3:
20208524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_ZUCE;
20218524b44eSHemant Agrawal 		break;
20228524b44eSHemant Agrawal 	default:
20238524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
20248524b44eSHemant Agrawal 			      xform->cipher.algo);
2025c08ced9aSAkhil Goyal 		return -ENOTSUP;
20268524b44eSHemant Agrawal 	}
2027c3e85bdcSAkhil Goyal 	session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2028c3e85bdcSAkhil Goyal 			DIR_ENC : DIR_DEC;
2029c3e85bdcSAkhil Goyal 
2030c3e85bdcSAkhil Goyal 	return 0;
2031c3e85bdcSAkhil Goyal }
2032c3e85bdcSAkhil Goyal 
2033c3e85bdcSAkhil Goyal static int
2034c3e85bdcSAkhil Goyal dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
2035c3e85bdcSAkhil Goyal 		   struct rte_crypto_sym_xform *xform,
2036c3e85bdcSAkhil Goyal 		   dpaa_sec_session *session)
2037c3e85bdcSAkhil Goyal {
2038f73d6928SHemant Agrawal 	session->ctxt = DPAA_SEC_AUTH;
2039c3e85bdcSAkhil Goyal 	session->auth_alg = xform->auth.algo;
2040c3e85bdcSAkhil Goyal 	session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
2041c3e85bdcSAkhil Goyal 					     RTE_CACHE_LINE_SIZE);
2042c3e85bdcSAkhil Goyal 	if (session->auth_key.data == NULL && xform->auth.key.length > 0) {
2043f163231eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for auth key");
2044c3e85bdcSAkhil Goyal 		return -ENOMEM;
2045c3e85bdcSAkhil Goyal 	}
2046c3e85bdcSAkhil Goyal 	session->auth_key.length = xform->auth.key.length;
2047c3e85bdcSAkhil Goyal 	session->digest_length = xform->auth.digest_length;
2048c5788a10SHemant Agrawal 	if (session->cipher_alg == RTE_CRYPTO_CIPHER_NULL) {
2049c5788a10SHemant Agrawal 		session->iv.offset = xform->auth.iv.offset;
2050c5788a10SHemant Agrawal 		session->iv.length = xform->auth.iv.length;
2051c5788a10SHemant Agrawal 	}
2052c3e85bdcSAkhil Goyal 
2053c3e85bdcSAkhil Goyal 	memcpy(session->auth_key.data, xform->auth.key.data,
2054c3e85bdcSAkhil Goyal 	       xform->auth.key.length);
20558524b44eSHemant Agrawal 
20568524b44eSHemant Agrawal 	switch (xform->auth.algo) {
20578524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1_HMAC:
20588524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA1;
20598524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20608524b44eSHemant Agrawal 		break;
20618524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5_HMAC:
20628524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_MD5;
20638524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20648524b44eSHemant Agrawal 		break;
20658524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224_HMAC:
20668524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA224;
20678524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20688524b44eSHemant Agrawal 		break;
20698524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA256_HMAC:
20708524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA256;
20718524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20728524b44eSHemant Agrawal 		break;
20738524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA384_HMAC:
20748524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA384;
20758524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20768524b44eSHemant Agrawal 		break;
20778524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA512_HMAC:
20788524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA512;
20798524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20808524b44eSHemant Agrawal 		break;
20818524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
20828524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SNOW_F9;
20838524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_F9;
20848524b44eSHemant Agrawal 		break;
20858524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
20868524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_ZUCA;
20878524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_F9;
20888524b44eSHemant Agrawal 		break;
20898524b44eSHemant Agrawal 	default:
20908524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
20918524b44eSHemant Agrawal 			      xform->auth.algo);
2092c08ced9aSAkhil Goyal 		return -ENOTSUP;
20938524b44eSHemant Agrawal 	}
20948524b44eSHemant Agrawal 
2095c3e85bdcSAkhil Goyal 	session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2096c3e85bdcSAkhil Goyal 			DIR_ENC : DIR_DEC;
2097c3e85bdcSAkhil Goyal 
2098c3e85bdcSAkhil Goyal 	return 0;
2099c3e85bdcSAkhil Goyal }
2100c3e85bdcSAkhil Goyal 
2101c3e85bdcSAkhil Goyal static int
21028524b44eSHemant Agrawal dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
21038524b44eSHemant Agrawal 		   struct rte_crypto_sym_xform *xform,
21048524b44eSHemant Agrawal 		   dpaa_sec_session *session)
21058524b44eSHemant Agrawal {
21068524b44eSHemant Agrawal 
21078524b44eSHemant Agrawal 	struct rte_crypto_cipher_xform *cipher_xform;
21088524b44eSHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform;
21098524b44eSHemant Agrawal 
2110f73d6928SHemant Agrawal 	session->ctxt = DPAA_SEC_CIPHER_HASH;
21118524b44eSHemant Agrawal 	if (session->auth_cipher_text) {
21128524b44eSHemant Agrawal 		cipher_xform = &xform->cipher;
21138524b44eSHemant Agrawal 		auth_xform = &xform->next->auth;
21148524b44eSHemant Agrawal 	} else {
21158524b44eSHemant Agrawal 		cipher_xform = &xform->next->cipher;
21168524b44eSHemant Agrawal 		auth_xform = &xform->auth;
21178524b44eSHemant Agrawal 	}
21188524b44eSHemant Agrawal 
21198524b44eSHemant Agrawal 	/* Set IV parameters */
21208524b44eSHemant Agrawal 	session->iv.offset = cipher_xform->iv.offset;
21218524b44eSHemant Agrawal 	session->iv.length = cipher_xform->iv.length;
21228524b44eSHemant Agrawal 
21238524b44eSHemant Agrawal 	session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
21248524b44eSHemant Agrawal 					       RTE_CACHE_LINE_SIZE);
21258524b44eSHemant Agrawal 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
21268524b44eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for cipher key");
2127c08ced9aSAkhil Goyal 		return -ENOMEM;
21288524b44eSHemant Agrawal 	}
21298524b44eSHemant Agrawal 	session->cipher_key.length = cipher_xform->key.length;
21308524b44eSHemant Agrawal 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
21318524b44eSHemant Agrawal 					     RTE_CACHE_LINE_SIZE);
21328524b44eSHemant Agrawal 	if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
21338524b44eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for auth key");
21348524b44eSHemant Agrawal 		return -ENOMEM;
21358524b44eSHemant Agrawal 	}
21368524b44eSHemant Agrawal 	session->auth_key.length = auth_xform->key.length;
21378524b44eSHemant Agrawal 	memcpy(session->cipher_key.data, cipher_xform->key.data,
21388524b44eSHemant Agrawal 	       cipher_xform->key.length);
21398524b44eSHemant Agrawal 	memcpy(session->auth_key.data, auth_xform->key.data,
21408524b44eSHemant Agrawal 	       auth_xform->key.length);
21418524b44eSHemant Agrawal 
21428524b44eSHemant Agrawal 	session->digest_length = auth_xform->digest_length;
21438524b44eSHemant Agrawal 	session->auth_alg = auth_xform->algo;
21448524b44eSHemant Agrawal 
21458524b44eSHemant Agrawal 	switch (auth_xform->algo) {
21468524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1_HMAC:
21478524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA1;
21488524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21498524b44eSHemant Agrawal 		break;
21508524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5_HMAC:
21518524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_MD5;
21528524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21538524b44eSHemant Agrawal 		break;
21548524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224_HMAC:
21558524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA224;
21568524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21578524b44eSHemant Agrawal 		break;
21588524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA256_HMAC:
21598524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA256;
21608524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21618524b44eSHemant Agrawal 		break;
21628524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA384_HMAC:
21638524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA384;
21648524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21658524b44eSHemant Agrawal 		break;
21668524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA512_HMAC:
21678524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA512;
21688524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21698524b44eSHemant Agrawal 		break;
21708524b44eSHemant Agrawal 	default:
21718524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
21728524b44eSHemant Agrawal 			      auth_xform->algo);
2173c08ced9aSAkhil Goyal 		return -ENOTSUP;
21748524b44eSHemant Agrawal 	}
21758524b44eSHemant Agrawal 
21768524b44eSHemant Agrawal 	session->cipher_alg = cipher_xform->algo;
21778524b44eSHemant Agrawal 
21788524b44eSHemant Agrawal 	switch (cipher_xform->algo) {
21798524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CBC:
21808524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
21818524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
21828524b44eSHemant Agrawal 		break;
21838524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_CBC:
21848524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_3DES;
21858524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
21868524b44eSHemant Agrawal 		break;
21878524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CTR:
21888524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
21898524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CTR;
21908524b44eSHemant Agrawal 		break;
21918524b44eSHemant Agrawal 	default:
21928524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
21938524b44eSHemant Agrawal 			      cipher_xform->algo);
2194c08ced9aSAkhil Goyal 		return -ENOTSUP;
21958524b44eSHemant Agrawal 	}
21968524b44eSHemant Agrawal 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
21978524b44eSHemant Agrawal 				DIR_ENC : DIR_DEC;
21988524b44eSHemant Agrawal 	return 0;
21998524b44eSHemant Agrawal }
22008524b44eSHemant Agrawal 
22018524b44eSHemant Agrawal static int
2202c3e85bdcSAkhil Goyal dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
2203c3e85bdcSAkhil Goyal 		   struct rte_crypto_sym_xform *xform,
2204c3e85bdcSAkhil Goyal 		   dpaa_sec_session *session)
2205c3e85bdcSAkhil Goyal {
2206c3e85bdcSAkhil Goyal 	session->aead_alg = xform->aead.algo;
22078524b44eSHemant Agrawal 	session->ctxt = DPAA_SEC_AEAD;
2208c3e85bdcSAkhil Goyal 	session->iv.length = xform->aead.iv.length;
2209c3e85bdcSAkhil Goyal 	session->iv.offset = xform->aead.iv.offset;
2210c3e85bdcSAkhil Goyal 	session->auth_only_len = xform->aead.aad_length;
2211c3e85bdcSAkhil Goyal 	session->aead_key.data = rte_zmalloc(NULL, xform->aead.key.length,
2212c3e85bdcSAkhil Goyal 					     RTE_CACHE_LINE_SIZE);
2213c3e85bdcSAkhil Goyal 	if (session->aead_key.data == NULL && xform->aead.key.length > 0) {
2214f163231eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for aead key\n");
2215c3e85bdcSAkhil Goyal 		return -ENOMEM;
2216c3e85bdcSAkhil Goyal 	}
2217c3e85bdcSAkhil Goyal 	session->aead_key.length = xform->aead.key.length;
2218c3e85bdcSAkhil Goyal 	session->digest_length = xform->aead.digest_length;
2219c3e85bdcSAkhil Goyal 
2220c3e85bdcSAkhil Goyal 	memcpy(session->aead_key.data, xform->aead.key.data,
2221c3e85bdcSAkhil Goyal 	       xform->aead.key.length);
22228524b44eSHemant Agrawal 
22238524b44eSHemant Agrawal 	switch (session->aead_alg) {
22248524b44eSHemant Agrawal 	case RTE_CRYPTO_AEAD_AES_GCM:
22258524b44eSHemant Agrawal 		session->aead_key.alg = OP_ALG_ALGSEL_AES;
22268524b44eSHemant Agrawal 		session->aead_key.algmode = OP_ALG_AAI_GCM;
22278524b44eSHemant Agrawal 		break;
22288524b44eSHemant Agrawal 	default:
22298524b44eSHemant Agrawal 		DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
2230c08ced9aSAkhil Goyal 		return -ENOTSUP;
22318524b44eSHemant Agrawal 	}
22328524b44eSHemant Agrawal 
2233c3e85bdcSAkhil Goyal 	session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2234c3e85bdcSAkhil Goyal 			DIR_ENC : DIR_DEC;
2235c3e85bdcSAkhil Goyal 
2236c3e85bdcSAkhil Goyal 	return 0;
2237c3e85bdcSAkhil Goyal }
2238c3e85bdcSAkhil Goyal 
2239e79416d1SHemant Agrawal static struct qman_fq *
2240e79416d1SHemant Agrawal dpaa_sec_attach_rxq(struct dpaa_sec_dev_private *qi)
2241c3e85bdcSAkhil Goyal {
2242e79416d1SHemant Agrawal 	unsigned int i;
2243c3e85bdcSAkhil Goyal 
2244fd900d38SGagandeep Singh 	for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) {
2245e79416d1SHemant Agrawal 		if (qi->inq_attach[i] == 0) {
2246e79416d1SHemant Agrawal 			qi->inq_attach[i] = 1;
2247e79416d1SHemant Agrawal 			return &qi->inq[i];
2248e79416d1SHemant Agrawal 		}
2249e79416d1SHemant Agrawal 	}
2250e621d970SAkhil Goyal 	DPAA_SEC_WARN("All session in use %u", qi->max_nb_sessions);
2251c3e85bdcSAkhil Goyal 
2252e79416d1SHemant Agrawal 	return NULL;
2253c3e85bdcSAkhil Goyal }
2254c3e85bdcSAkhil Goyal 
2255e79416d1SHemant Agrawal static int
2256e79416d1SHemant Agrawal dpaa_sec_detach_rxq(struct dpaa_sec_dev_private *qi, struct qman_fq *fq)
2257e79416d1SHemant Agrawal {
2258e79416d1SHemant Agrawal 	unsigned int i;
2259e79416d1SHemant Agrawal 
2260fd900d38SGagandeep Singh 	for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) {
2261e79416d1SHemant Agrawal 		if (&qi->inq[i] == fq) {
2262fd900d38SGagandeep Singh 			if (qman_retire_fq(fq, NULL) != 0)
2263fd900d38SGagandeep Singh 				DPAA_SEC_WARN("Queue is not retired\n");
2264b4053c4bSAlok Makhariya 			qman_oos_fq(fq);
2265e79416d1SHemant Agrawal 			qi->inq_attach[i] = 0;
2266e79416d1SHemant Agrawal 			return 0;
2267e79416d1SHemant Agrawal 		}
2268e79416d1SHemant Agrawal 	}
2269e79416d1SHemant Agrawal 	return -1;
2270e79416d1SHemant Agrawal }
2271e79416d1SHemant Agrawal 
2272e79416d1SHemant Agrawal static int
2273e79416d1SHemant Agrawal dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess)
2274e79416d1SHemant Agrawal {
2275e79416d1SHemant Agrawal 	int ret;
2276e79416d1SHemant Agrawal 
22774e694fe5SAkhil Goyal 	sess->qp[rte_lcore_id() % MAX_DPAA_CORES] = qp;
2278e79416d1SHemant Agrawal 	ret = dpaa_sec_prep_cdb(sess);
2279e79416d1SHemant Agrawal 	if (ret) {
2280f163231eSHemant Agrawal 		DPAA_SEC_ERR("Unable to prepare sec cdb");
2281c08ced9aSAkhil Goyal 		return ret;
2282e79416d1SHemant Agrawal 	}
22835b0f1bd3SAshish Jain 	if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
22845b0f1bd3SAshish Jain 		ret = rte_dpaa_portal_init((void *)0);
22855b0f1bd3SAshish Jain 		if (ret) {
2286f163231eSHemant Agrawal 			DPAA_SEC_ERR("Failure in affining portal");
22875b0f1bd3SAshish Jain 			return ret;
22885b0f1bd3SAshish Jain 		}
22895b0f1bd3SAshish Jain 	}
22904e694fe5SAkhil Goyal 	ret = dpaa_sec_init_rx(sess->inq[rte_lcore_id() % MAX_DPAA_CORES],
2291ec861560SGagandeep Singh 			       rte_dpaa_mem_vtop(&sess->cdb),
2292e79416d1SHemant Agrawal 			       qman_fq_fqid(&qp->outq));
2293e79416d1SHemant Agrawal 	if (ret)
2294f163231eSHemant Agrawal 		DPAA_SEC_ERR("Unable to init sec queue");
2295e79416d1SHemant Agrawal 
2296e79416d1SHemant Agrawal 	return ret;
2297c3e85bdcSAkhil Goyal }
2298c3e85bdcSAkhil Goyal 
22996290de2cSLukasz Wojciechowski static inline void
23006290de2cSLukasz Wojciechowski free_session_data(dpaa_sec_session *s)
23016290de2cSLukasz Wojciechowski {
23026290de2cSLukasz Wojciechowski 	if (is_aead(s))
23036290de2cSLukasz Wojciechowski 		rte_free(s->aead_key.data);
23046290de2cSLukasz Wojciechowski 	else {
23056290de2cSLukasz Wojciechowski 		rte_free(s->auth_key.data);
23066290de2cSLukasz Wojciechowski 		rte_free(s->cipher_key.data);
23076290de2cSLukasz Wojciechowski 	}
23086290de2cSLukasz Wojciechowski 	memset(s, 0, sizeof(dpaa_sec_session));
23096290de2cSLukasz Wojciechowski }
23106290de2cSLukasz Wojciechowski 
2311c3e85bdcSAkhil Goyal static int
2312c3e85bdcSAkhil Goyal dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
2313c3e85bdcSAkhil Goyal 			    struct rte_crypto_sym_xform *xform,	void *sess)
2314c3e85bdcSAkhil Goyal {
2315c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals = dev->data->dev_private;
2316c3e85bdcSAkhil Goyal 	dpaa_sec_session *session = sess;
23174e694fe5SAkhil Goyal 	uint32_t i;
2318f73d6928SHemant Agrawal 	int ret;
2319c3e85bdcSAkhil Goyal 
2320c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
2321c3e85bdcSAkhil Goyal 
2322c3e85bdcSAkhil Goyal 	if (unlikely(sess == NULL)) {
2323f163231eSHemant Agrawal 		DPAA_SEC_ERR("invalid session struct");
2324c3e85bdcSAkhil Goyal 		return -EINVAL;
2325c3e85bdcSAkhil Goyal 	}
2326b0894102SAkhil Goyal 	memset(session, 0, sizeof(dpaa_sec_session));
2327c3e85bdcSAkhil Goyal 
2328c3e85bdcSAkhil Goyal 	/* Default IV length = 0 */
2329c3e85bdcSAkhil Goyal 	session->iv.length = 0;
2330c3e85bdcSAkhil Goyal 
2331c3e85bdcSAkhil Goyal 	/* Cipher Only */
2332c3e85bdcSAkhil Goyal 	if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2333c3e85bdcSAkhil Goyal 		session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2334f73d6928SHemant Agrawal 		ret = dpaa_sec_cipher_init(dev, xform, session);
2335c3e85bdcSAkhil Goyal 
2336c3e85bdcSAkhil Goyal 	/* Authentication Only */
2337c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2338c3e85bdcSAkhil Goyal 		   xform->next == NULL) {
2339c3e85bdcSAkhil Goyal 		session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
23408524b44eSHemant Agrawal 		session->ctxt = DPAA_SEC_AUTH;
2341f73d6928SHemant Agrawal 		ret = dpaa_sec_auth_init(dev, xform, session);
2342c3e85bdcSAkhil Goyal 
2343c3e85bdcSAkhil Goyal 	/* Cipher then Authenticate */
2344c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2345c3e85bdcSAkhil Goyal 		   xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2346c3e85bdcSAkhil Goyal 		if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
23478524b44eSHemant Agrawal 			session->auth_cipher_text = 1;
2348f73d6928SHemant Agrawal 			if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2349f73d6928SHemant Agrawal 				ret = dpaa_sec_auth_init(dev, xform, session);
2350f73d6928SHemant Agrawal 			else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2351f73d6928SHemant Agrawal 				ret = dpaa_sec_cipher_init(dev, xform, session);
2352f73d6928SHemant Agrawal 			else
2353f73d6928SHemant Agrawal 				ret = dpaa_sec_chain_init(dev, xform, session);
2354c3e85bdcSAkhil Goyal 		} else {
2355f163231eSHemant Agrawal 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
2356c08ced9aSAkhil Goyal 			return -ENOTSUP;
2357c3e85bdcSAkhil Goyal 		}
2358c3e85bdcSAkhil Goyal 	/* Authenticate then Cipher */
2359c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2360c3e85bdcSAkhil Goyal 		   xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2361c3e85bdcSAkhil Goyal 		if (xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
23628524b44eSHemant Agrawal 			session->auth_cipher_text = 0;
2363f73d6928SHemant Agrawal 			if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2364f73d6928SHemant Agrawal 				ret = dpaa_sec_cipher_init(dev, xform, session);
2365f73d6928SHemant Agrawal 			else if (xform->next->cipher.algo
2366f73d6928SHemant Agrawal 					== RTE_CRYPTO_CIPHER_NULL)
2367f73d6928SHemant Agrawal 				ret = dpaa_sec_auth_init(dev, xform, session);
2368f73d6928SHemant Agrawal 			else
2369f73d6928SHemant Agrawal 				ret = dpaa_sec_chain_init(dev, xform, session);
2370c3e85bdcSAkhil Goyal 		} else {
2371f163231eSHemant Agrawal 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
2372c08ced9aSAkhil Goyal 			return -ENOTSUP;
2373c3e85bdcSAkhil Goyal 		}
2374c3e85bdcSAkhil Goyal 
2375c3e85bdcSAkhil Goyal 	/* AEAD operation for AES-GCM kind of Algorithms */
2376c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2377c3e85bdcSAkhil Goyal 		   xform->next == NULL) {
2378f73d6928SHemant Agrawal 		ret = dpaa_sec_aead_init(dev, xform, session);
2379c3e85bdcSAkhil Goyal 
2380c3e85bdcSAkhil Goyal 	} else {
2381f163231eSHemant Agrawal 		DPAA_SEC_ERR("Invalid crypto type");
2382c3e85bdcSAkhil Goyal 		return -EINVAL;
2383c3e85bdcSAkhil Goyal 	}
2384f73d6928SHemant Agrawal 	if (ret) {
2385f73d6928SHemant Agrawal 		DPAA_SEC_ERR("unable to init session");
2386f73d6928SHemant Agrawal 		goto err1;
2387f73d6928SHemant Agrawal 	}
2388f73d6928SHemant Agrawal 
23893b617ee7SAkhil Goyal 	rte_spinlock_lock(&internals->lock);
23904e694fe5SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
23914e694fe5SAkhil Goyal 		session->inq[i] = dpaa_sec_attach_rxq(internals);
23924e694fe5SAkhil Goyal 		if (session->inq[i] == NULL) {
2393f163231eSHemant Agrawal 			DPAA_SEC_ERR("unable to attach sec queue");
23944e694fe5SAkhil Goyal 			rte_spinlock_unlock(&internals->lock);
2395c08ced9aSAkhil Goyal 			ret = -EBUSY;
2396e79416d1SHemant Agrawal 			goto err1;
2397e79416d1SHemant Agrawal 		}
23984e694fe5SAkhil Goyal 	}
23994e694fe5SAkhil Goyal 	rte_spinlock_unlock(&internals->lock);
2400c3e85bdcSAkhil Goyal 
2401c3e85bdcSAkhil Goyal 	return 0;
2402e79416d1SHemant Agrawal 
2403e79416d1SHemant Agrawal err1:
24046290de2cSLukasz Wojciechowski 	free_session_data(session);
2405c08ced9aSAkhil Goyal 	return ret;
2406c3e85bdcSAkhil Goyal }
2407c3e85bdcSAkhil Goyal 
2408c3e85bdcSAkhil Goyal static int
2409012c5076SPablo de Lara dpaa_sec_sym_session_configure(struct rte_cryptodev *dev,
2410c3e85bdcSAkhil Goyal 		struct rte_crypto_sym_xform *xform,
2411c3e85bdcSAkhil Goyal 		struct rte_cryptodev_sym_session *sess,
2412c3e85bdcSAkhil Goyal 		struct rte_mempool *mempool)
2413c3e85bdcSAkhil Goyal {
2414c3e85bdcSAkhil Goyal 	void *sess_private_data;
2415c3e85bdcSAkhil Goyal 	int ret;
2416c3e85bdcSAkhil Goyal 
2417c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
2418c3e85bdcSAkhil Goyal 
2419c3e85bdcSAkhil Goyal 	if (rte_mempool_get(mempool, &sess_private_data)) {
2420f163231eSHemant Agrawal 		DPAA_SEC_ERR("Couldn't get object from session mempool");
2421c3e85bdcSAkhil Goyal 		return -ENOMEM;
2422c3e85bdcSAkhil Goyal 	}
2423c3e85bdcSAkhil Goyal 
2424c3e85bdcSAkhil Goyal 	ret = dpaa_sec_set_session_parameters(dev, xform, sess_private_data);
2425c3e85bdcSAkhil Goyal 	if (ret != 0) {
2426f163231eSHemant Agrawal 		DPAA_SEC_ERR("failed to configure session parameters");
2427c3e85bdcSAkhil Goyal 
2428c3e85bdcSAkhil Goyal 		/* Return session to mempool */
2429c3e85bdcSAkhil Goyal 		rte_mempool_put(mempool, sess_private_data);
2430c3e85bdcSAkhil Goyal 		return ret;
2431c3e85bdcSAkhil Goyal 	}
2432c3e85bdcSAkhil Goyal 
2433012c5076SPablo de Lara 	set_sym_session_private_data(sess, dev->driver_id,
2434c3e85bdcSAkhil Goyal 			sess_private_data);
2435c3e85bdcSAkhil Goyal 
2436e79416d1SHemant Agrawal 
2437c3e85bdcSAkhil Goyal 	return 0;
2438c3e85bdcSAkhil Goyal }
2439c3e85bdcSAkhil Goyal 
24403d0d5332SAkhil Goyal static inline void
24413d0d5332SAkhil Goyal free_session_memory(struct rte_cryptodev *dev, dpaa_sec_session *s)
2442c3e85bdcSAkhil Goyal {
2443e79416d1SHemant Agrawal 	struct dpaa_sec_dev_private *qi = dev->data->dev_private;
24443d0d5332SAkhil Goyal 	struct rte_mempool *sess_mp = rte_mempool_from_obj((void *)s);
24453d0d5332SAkhil Goyal 	uint8_t i;
2446e79416d1SHemant Agrawal 
2447e621d970SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
2448e621d970SAkhil Goyal 		if (s->inq[i])
2449e621d970SAkhil Goyal 			dpaa_sec_detach_rxq(qi, s->inq[i]);
2450e621d970SAkhil Goyal 		s->inq[i] = NULL;
2451e621d970SAkhil Goyal 		s->qp[i] = NULL;
2452e621d970SAkhil Goyal 	}
24536290de2cSLukasz Wojciechowski 	free_session_data(s);
24543d0d5332SAkhil Goyal 	rte_mempool_put(sess_mp, (void *)s);
24553d0d5332SAkhil Goyal }
24563d0d5332SAkhil Goyal 
24573d0d5332SAkhil Goyal /** Clear the memory of session so it doesn't leave key material behind */
24583d0d5332SAkhil Goyal static void
24593d0d5332SAkhil Goyal dpaa_sec_sym_session_clear(struct rte_cryptodev *dev,
24603d0d5332SAkhil Goyal 		struct rte_cryptodev_sym_session *sess)
24613d0d5332SAkhil Goyal {
24623d0d5332SAkhil Goyal 	PMD_INIT_FUNC_TRACE();
24633d0d5332SAkhil Goyal 	uint8_t index = dev->driver_id;
24643d0d5332SAkhil Goyal 	void *sess_priv = get_sym_session_private_data(sess, index);
24653d0d5332SAkhil Goyal 	dpaa_sec_session *s = (dpaa_sec_session *)sess_priv;
24663d0d5332SAkhil Goyal 
24673d0d5332SAkhil Goyal 	if (sess_priv) {
24683d0d5332SAkhil Goyal 		free_session_memory(dev, s);
2469012c5076SPablo de Lara 		set_sym_session_private_data(sess, index, NULL);
2470c3e85bdcSAkhil Goyal 	}
2471c3e85bdcSAkhil Goyal }
2472c3e85bdcSAkhil Goyal 
2473314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
2474c3e85bdcSAkhil Goyal static int
24752c318722SHemant Agrawal dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
24762c318722SHemant Agrawal 			struct rte_security_ipsec_xform *ipsec_xform,
24772c318722SHemant Agrawal 			dpaa_sec_session *session)
24781f14d500SAkhil Goyal {
24791f14d500SAkhil Goyal 	PMD_INIT_FUNC_TRACE();
24801f14d500SAkhil Goyal 
24812c318722SHemant Agrawal 	session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
24822c318722SHemant Agrawal 					       RTE_CACHE_LINE_SIZE);
24832c318722SHemant Agrawal 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
24842c318722SHemant Agrawal 		DPAA_SEC_ERR("No Memory for aead key");
2485c08ced9aSAkhil Goyal 		return -ENOMEM;
24861f14d500SAkhil Goyal 	}
24872c318722SHemant Agrawal 	memcpy(session->aead_key.data, aead_xform->key.data,
24882c318722SHemant Agrawal 	       aead_xform->key.length);
248905b12700SHemant Agrawal 
24902c318722SHemant Agrawal 	session->digest_length = aead_xform->digest_length;
24912c318722SHemant Agrawal 	session->aead_key.length = aead_xform->key.length;
24922c318722SHemant Agrawal 
24932c318722SHemant Agrawal 	switch (aead_xform->algo) {
24942c318722SHemant Agrawal 	case RTE_CRYPTO_AEAD_AES_GCM:
24952c318722SHemant Agrawal 		switch (session->digest_length) {
24962c318722SHemant Agrawal 		case 8:
24972c318722SHemant Agrawal 			session->aead_key.alg = OP_PCL_IPSEC_AES_GCM8;
24982c318722SHemant Agrawal 			break;
24992c318722SHemant Agrawal 		case 12:
25002c318722SHemant Agrawal 			session->aead_key.alg = OP_PCL_IPSEC_AES_GCM12;
25012c318722SHemant Agrawal 			break;
25022c318722SHemant Agrawal 		case 16:
25032c318722SHemant Agrawal 			session->aead_key.alg = OP_PCL_IPSEC_AES_GCM16;
25042c318722SHemant Agrawal 			break;
25052c318722SHemant Agrawal 		default:
25062c318722SHemant Agrawal 			DPAA_SEC_ERR("Crypto: Undefined GCM digest %d",
25072c318722SHemant Agrawal 				     session->digest_length);
2508c08ced9aSAkhil Goyal 			return -EINVAL;
25092c318722SHemant Agrawal 		}
25102c318722SHemant Agrawal 		if (session->dir == DIR_ENC) {
25112c318722SHemant Agrawal 			memcpy(session->encap_pdb.gcm.salt,
25122c318722SHemant Agrawal 				(uint8_t *)&(ipsec_xform->salt), 4);
25132c318722SHemant Agrawal 		} else {
25142c318722SHemant Agrawal 			memcpy(session->decap_pdb.gcm.salt,
25152c318722SHemant Agrawal 				(uint8_t *)&(ipsec_xform->salt), 4);
25162c318722SHemant Agrawal 		}
25172c318722SHemant Agrawal 		session->aead_key.algmode = OP_ALG_AAI_GCM;
25182c318722SHemant Agrawal 		session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
25192c318722SHemant Agrawal 		break;
25202c318722SHemant Agrawal 	default:
25212c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined AEAD specified %u",
25222c318722SHemant Agrawal 			      aead_xform->algo);
2523c08ced9aSAkhil Goyal 		return -ENOTSUP;
25242c318722SHemant Agrawal 	}
25252c318722SHemant Agrawal 	return 0;
25262c318722SHemant Agrawal }
25272c318722SHemant Agrawal 
25282c318722SHemant Agrawal static int
25292c318722SHemant Agrawal dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
25302c318722SHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform,
25311cdfbb0bSVakul Garg 	struct rte_security_ipsec_xform *ipsec_xform,
25322c318722SHemant Agrawal 	dpaa_sec_session *session)
25332c318722SHemant Agrawal {
25342c318722SHemant Agrawal 	if (cipher_xform) {
25351f14d500SAkhil Goyal 		session->cipher_key.data = rte_zmalloc(NULL,
25361f14d500SAkhil Goyal 						       cipher_xform->key.length,
25371f14d500SAkhil Goyal 						       RTE_CACHE_LINE_SIZE);
25381f14d500SAkhil Goyal 		if (session->cipher_key.data == NULL &&
25391f14d500SAkhil Goyal 				cipher_xform->key.length > 0) {
2540f163231eSHemant Agrawal 			DPAA_SEC_ERR("No Memory for cipher key");
25411f14d500SAkhil Goyal 			return -ENOMEM;
25421f14d500SAkhil Goyal 		}
25432c318722SHemant Agrawal 
25442c318722SHemant Agrawal 		session->cipher_key.length = cipher_xform->key.length;
254505b12700SHemant Agrawal 		memcpy(session->cipher_key.data, cipher_xform->key.data,
254605b12700SHemant Agrawal 				cipher_xform->key.length);
254705b12700SHemant Agrawal 		session->cipher_alg = cipher_xform->algo;
254805b12700SHemant Agrawal 	} else {
254905b12700SHemant Agrawal 		session->cipher_key.data = NULL;
255005b12700SHemant Agrawal 		session->cipher_key.length = 0;
255105b12700SHemant Agrawal 		session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
255205b12700SHemant Agrawal 	}
255305b12700SHemant Agrawal 
25542c318722SHemant Agrawal 	if (auth_xform) {
25551f14d500SAkhil Goyal 		session->auth_key.data = rte_zmalloc(NULL,
25561f14d500SAkhil Goyal 						auth_xform->key.length,
25571f14d500SAkhil Goyal 						RTE_CACHE_LINE_SIZE);
25581f14d500SAkhil Goyal 		if (session->auth_key.data == NULL &&
25591f14d500SAkhil Goyal 				auth_xform->key.length > 0) {
2560f163231eSHemant Agrawal 			DPAA_SEC_ERR("No Memory for auth key");
25611f14d500SAkhil Goyal 			return -ENOMEM;
25621f14d500SAkhil Goyal 		}
25632c318722SHemant Agrawal 		session->auth_key.length = auth_xform->key.length;
25641f14d500SAkhil Goyal 		memcpy(session->auth_key.data, auth_xform->key.data,
25651f14d500SAkhil Goyal 				auth_xform->key.length);
25662c318722SHemant Agrawal 		session->auth_alg = auth_xform->algo;
2567247b6908SHemant Agrawal 		session->digest_length = auth_xform->digest_length;
25682c318722SHemant Agrawal 	} else {
25692c318722SHemant Agrawal 		session->auth_key.data = NULL;
25702c318722SHemant Agrawal 		session->auth_key.length = 0;
25712c318722SHemant Agrawal 		session->auth_alg = RTE_CRYPTO_AUTH_NULL;
25722c318722SHemant Agrawal 	}
25731f14d500SAkhil Goyal 
25742c318722SHemant Agrawal 	switch (session->auth_alg) {
25758524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1_HMAC:
25768524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA1_96;
25778524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25788524b44eSHemant Agrawal 		break;
25792c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5_HMAC:
25802c318722SHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_MD5_96;
25818524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25828524b44eSHemant Agrawal 		break;
25831f14d500SAkhil Goyal 	case RTE_CRYPTO_AUTH_SHA256_HMAC:
25848524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_256_128;
25858524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
2586247b6908SHemant Agrawal 		if (session->digest_length != 16)
2587247b6908SHemant Agrawal 			DPAA_SEC_WARN(
2588247b6908SHemant Agrawal 			"+++Using sha256-hmac truncated len is non-standard,"
2589247b6908SHemant Agrawal 			"it will not work with lookaside proto");
25908524b44eSHemant Agrawal 		break;
25911f14d500SAkhil Goyal 	case RTE_CRYPTO_AUTH_SHA384_HMAC:
25928524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_384_192;
25938524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25948524b44eSHemant Agrawal 		break;
25951f14d500SAkhil Goyal 	case RTE_CRYPTO_AUTH_SHA512_HMAC:
25968524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_512_256;
25978524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25981f14d500SAkhil Goyal 		break;
25992c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_CMAC:
26002c318722SHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_AES_CMAC_96;
26012c318722SHemant Agrawal 		break;
26022c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_NULL:
26032c318722SHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_NULL;
26042c318722SHemant Agrawal 		break;
26052c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224_HMAC:
26062c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
26072c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
26082c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1:
26092c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA256:
26102c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA512:
26112c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224:
26122c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA384:
26132c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5:
26142c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_GMAC:
26152c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_KASUMI_F9:
26162c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_CBC_MAC:
26172c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
2618f163231eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
26192c318722SHemant Agrawal 			      session->auth_alg);
2620c08ced9aSAkhil Goyal 		return -ENOTSUP;
26212c318722SHemant Agrawal 	default:
26222c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Auth specified %u",
26232c318722SHemant Agrawal 			      session->auth_alg);
2624c08ced9aSAkhil Goyal 		return -ENOTSUP;
26252c318722SHemant Agrawal 	}
26262c318722SHemant Agrawal 
26272c318722SHemant Agrawal 	switch (session->cipher_alg) {
26282c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CBC:
26292c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_AES_CBC;
26302c318722SHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
26312c318722SHemant Agrawal 		break;
26322c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_CBC:
26332c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_3DES;
26342c318722SHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
26352c318722SHemant Agrawal 		break;
26362c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CTR:
26372c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_AES_CTR;
26382c318722SHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CTR;
26391cdfbb0bSVakul Garg 		if (session->dir == DIR_ENC) {
26401cdfbb0bSVakul Garg 			session->encap_pdb.ctr.ctr_initial = 0x00000001;
26411cdfbb0bSVakul Garg 			session->encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
26421cdfbb0bSVakul Garg 		} else {
26431cdfbb0bSVakul Garg 			session->decap_pdb.ctr.ctr_initial = 0x00000001;
26441cdfbb0bSVakul Garg 			session->decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
26451cdfbb0bSVakul Garg 		}
26462c318722SHemant Agrawal 		break;
26472c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_NULL:
26482c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_NULL;
26492c318722SHemant Agrawal 		break;
26502c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
26512c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_ZUC_EEA3:
26522c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_ECB:
26532c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_ECB:
26542c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
26552c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
26562c318722SHemant Agrawal 			      session->cipher_alg);
2657c08ced9aSAkhil Goyal 		return -ENOTSUP;
26582c318722SHemant Agrawal 	default:
26592c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
26602c318722SHemant Agrawal 			      session->cipher_alg);
2661c08ced9aSAkhil Goyal 		return -ENOTSUP;
26622c318722SHemant Agrawal 	}
26632c318722SHemant Agrawal 
26642c318722SHemant Agrawal 	return 0;
26652c318722SHemant Agrawal }
26662c318722SHemant Agrawal 
26672c318722SHemant Agrawal static int
26682c318722SHemant Agrawal dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
26692c318722SHemant Agrawal 			   struct rte_security_session_conf *conf,
26702c318722SHemant Agrawal 			   void *sess)
26712c318722SHemant Agrawal {
26722c318722SHemant Agrawal 	struct dpaa_sec_dev_private *internals = dev->data->dev_private;
26732c318722SHemant Agrawal 	struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
26742c318722SHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform = NULL;
26752c318722SHemant Agrawal 	struct rte_crypto_cipher_xform *cipher_xform = NULL;
26762c318722SHemant Agrawal 	struct rte_crypto_aead_xform *aead_xform = NULL;
26772c318722SHemant Agrawal 	dpaa_sec_session *session = (dpaa_sec_session *)sess;
26782c318722SHemant Agrawal 	uint32_t i;
26792c318722SHemant Agrawal 	int ret;
26802c318722SHemant Agrawal 
26812c318722SHemant Agrawal 	PMD_INIT_FUNC_TRACE();
26822c318722SHemant Agrawal 
26832c318722SHemant Agrawal 	memset(session, 0, sizeof(dpaa_sec_session));
26842c318722SHemant Agrawal 	session->proto_alg = conf->protocol;
26852c318722SHemant Agrawal 	session->ctxt = DPAA_SEC_IPSEC;
26862c318722SHemant Agrawal 
26872c318722SHemant Agrawal 	if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
26882c318722SHemant Agrawal 		session->dir = DIR_ENC;
26892c318722SHemant Agrawal 	else
26902c318722SHemant Agrawal 		session->dir = DIR_DEC;
26912c318722SHemant Agrawal 
26922c318722SHemant Agrawal 	if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
26932c318722SHemant Agrawal 		cipher_xform = &conf->crypto_xform->cipher;
26942c318722SHemant Agrawal 		if (conf->crypto_xform->next)
26952c318722SHemant Agrawal 			auth_xform = &conf->crypto_xform->next->auth;
26962c318722SHemant Agrawal 		ret = dpaa_sec_ipsec_proto_init(cipher_xform, auth_xform,
26971cdfbb0bSVakul Garg 					ipsec_xform, session);
26982c318722SHemant Agrawal 	} else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
26992c318722SHemant Agrawal 		auth_xform = &conf->crypto_xform->auth;
27002c318722SHemant Agrawal 		if (conf->crypto_xform->next)
27012c318722SHemant Agrawal 			cipher_xform = &conf->crypto_xform->next->cipher;
27022c318722SHemant Agrawal 		ret = dpaa_sec_ipsec_proto_init(cipher_xform, auth_xform,
27031cdfbb0bSVakul Garg 					ipsec_xform, session);
27042c318722SHemant Agrawal 	} else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
27052c318722SHemant Agrawal 		aead_xform = &conf->crypto_xform->aead;
27062c318722SHemant Agrawal 		ret = dpaa_sec_ipsec_aead_init(aead_xform,
27072c318722SHemant Agrawal 					ipsec_xform, session);
27082c318722SHemant Agrawal 	} else {
27092c318722SHemant Agrawal 		DPAA_SEC_ERR("XFORM not specified");
27102c318722SHemant Agrawal 		ret = -EINVAL;
27111f14d500SAkhil Goyal 		goto out;
27121f14d500SAkhil Goyal 	}
27132c318722SHemant Agrawal 	if (ret) {
27142c318722SHemant Agrawal 		DPAA_SEC_ERR("Failed to process xform");
27152c318722SHemant Agrawal 		goto out;
27161f14d500SAkhil Goyal 	}
27171f14d500SAkhil Goyal 
27181f14d500SAkhil Goyal 	if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
27195ab35d2eSAkhil Goyal 		if (ipsec_xform->tunnel.type ==
27205ab35d2eSAkhil Goyal 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
27211f14d500SAkhil Goyal 			session->ip4_hdr.ip_v = IPVERSION;
27221f14d500SAkhil Goyal 			session->ip4_hdr.ip_hl = 5;
27231f14d500SAkhil Goyal 			session->ip4_hdr.ip_len = rte_cpu_to_be_16(
27241f14d500SAkhil Goyal 						sizeof(session->ip4_hdr));
27251f14d500SAkhil Goyal 			session->ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
27261f14d500SAkhil Goyal 			session->ip4_hdr.ip_id = 0;
27271f14d500SAkhil Goyal 			session->ip4_hdr.ip_off = 0;
27281f14d500SAkhil Goyal 			session->ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
27291f14d500SAkhil Goyal 			session->ip4_hdr.ip_p = (ipsec_xform->proto ==
27305ab35d2eSAkhil Goyal 					RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
27315ab35d2eSAkhil Goyal 					IPPROTO_ESP : IPPROTO_AH;
27321f14d500SAkhil Goyal 			session->ip4_hdr.ip_sum = 0;
27335ab35d2eSAkhil Goyal 			session->ip4_hdr.ip_src =
27345ab35d2eSAkhil Goyal 					ipsec_xform->tunnel.ipv4.src_ip;
27355ab35d2eSAkhil Goyal 			session->ip4_hdr.ip_dst =
27365ab35d2eSAkhil Goyal 					ipsec_xform->tunnel.ipv4.dst_ip;
27371f14d500SAkhil Goyal 			session->ip4_hdr.ip_sum = calc_chksum((uint16_t *)
27381f14d500SAkhil Goyal 						(void *)&session->ip4_hdr,
27391f14d500SAkhil Goyal 						sizeof(struct ip));
27405ab35d2eSAkhil Goyal 			session->encap_pdb.ip_hdr_len = sizeof(struct ip);
27415ab35d2eSAkhil Goyal 		} else if (ipsec_xform->tunnel.type ==
27425ab35d2eSAkhil Goyal 				RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
27435ab35d2eSAkhil Goyal 			session->ip6_hdr.vtc_flow = rte_cpu_to_be_32(
27445ab35d2eSAkhil Goyal 				DPAA_IPv6_DEFAULT_VTC_FLOW |
27455ab35d2eSAkhil Goyal 				((ipsec_xform->tunnel.ipv6.dscp <<
27465ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_TC_SHIFT) &
27475ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_TC_MASK) |
27485ab35d2eSAkhil Goyal 				((ipsec_xform->tunnel.ipv6.flabel <<
27495ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_FL_SHIFT) &
27505ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_FL_MASK));
27515ab35d2eSAkhil Goyal 			/* Payload length will be updated by HW */
27525ab35d2eSAkhil Goyal 			session->ip6_hdr.payload_len = 0;
27535ab35d2eSAkhil Goyal 			session->ip6_hdr.hop_limits =
27545ab35d2eSAkhil Goyal 					ipsec_xform->tunnel.ipv6.hlimit;
27555ab35d2eSAkhil Goyal 			session->ip6_hdr.proto = (ipsec_xform->proto ==
27565ab35d2eSAkhil Goyal 					RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
27575ab35d2eSAkhil Goyal 					IPPROTO_ESP : IPPROTO_AH;
27585ab35d2eSAkhil Goyal 			memcpy(&session->ip6_hdr.src_addr,
27595ab35d2eSAkhil Goyal 					&ipsec_xform->tunnel.ipv6.src_addr, 16);
27605ab35d2eSAkhil Goyal 			memcpy(&session->ip6_hdr.dst_addr,
27615ab35d2eSAkhil Goyal 					&ipsec_xform->tunnel.ipv6.dst_addr, 16);
27625ab35d2eSAkhil Goyal 			session->encap_pdb.ip_hdr_len =
27635ab35d2eSAkhil Goyal 						sizeof(struct rte_ipv6_hdr);
27645ab35d2eSAkhil Goyal 		}
27651f14d500SAkhil Goyal 		session->encap_pdb.options =
27661f14d500SAkhil Goyal 			(IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
27671f14d500SAkhil Goyal 			PDBOPTS_ESP_OIHI_PDB_INL |
27681f14d500SAkhil Goyal 			PDBOPTS_ESP_IVSRC |
276979fde9d0SAkhil Goyal 			PDBHMO_ESP_ENCAP_DTTL |
277079fde9d0SAkhil Goyal 			PDBHMO_ESP_SNR;
27710f318781SAkhil Goyal 		if (ipsec_xform->options.esn)
27720f318781SAkhil Goyal 			session->encap_pdb.options |= PDBOPTS_ESP_ESN;
27731f14d500SAkhil Goyal 		session->encap_pdb.spi = ipsec_xform->spi;
27742c318722SHemant Agrawal 
27751f14d500SAkhil Goyal 	} else if (ipsec_xform->direction ==
27761f14d500SAkhil Goyal 			RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
27775ab35d2eSAkhil Goyal 		if (ipsec_xform->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4)
27781f14d500SAkhil Goyal 			session->decap_pdb.options = sizeof(struct ip) << 16;
27795ab35d2eSAkhil Goyal 		else
27805ab35d2eSAkhil Goyal 			session->decap_pdb.options =
27815ab35d2eSAkhil Goyal 					sizeof(struct rte_ipv6_hdr) << 16;
27820f318781SAkhil Goyal 		if (ipsec_xform->options.esn)
27830f318781SAkhil Goyal 			session->decap_pdb.options |= PDBOPTS_ESP_ESN;
2784a37ce227SHemant Agrawal 		if (ipsec_xform->replay_win_sz) {
2785a37ce227SHemant Agrawal 			uint32_t win_sz;
2786a37ce227SHemant Agrawal 			win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
2787a37ce227SHemant Agrawal 
2788a37ce227SHemant Agrawal 			switch (win_sz) {
2789a37ce227SHemant Agrawal 			case 1:
2790a37ce227SHemant Agrawal 			case 2:
2791a37ce227SHemant Agrawal 			case 4:
2792a37ce227SHemant Agrawal 			case 8:
2793a37ce227SHemant Agrawal 			case 16:
2794a37ce227SHemant Agrawal 			case 32:
2795a37ce227SHemant Agrawal 				session->decap_pdb.options |= PDBOPTS_ESP_ARS32;
2796a37ce227SHemant Agrawal 				break;
2797a37ce227SHemant Agrawal 			case 64:
2798a37ce227SHemant Agrawal 				session->decap_pdb.options |= PDBOPTS_ESP_ARS64;
2799a37ce227SHemant Agrawal 				break;
2800a37ce227SHemant Agrawal 			default:
2801a37ce227SHemant Agrawal 				session->decap_pdb.options |=
2802a37ce227SHemant Agrawal 							PDBOPTS_ESP_ARS128;
2803a37ce227SHemant Agrawal 			}
2804a37ce227SHemant Agrawal 		}
28051f14d500SAkhil Goyal 	} else
28061f14d500SAkhil Goyal 		goto out;
28073b617ee7SAkhil Goyal 	rte_spinlock_lock(&internals->lock);
28084e694fe5SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
28094e694fe5SAkhil Goyal 		session->inq[i] = dpaa_sec_attach_rxq(internals);
28104e694fe5SAkhil Goyal 		if (session->inq[i] == NULL) {
2811f163231eSHemant Agrawal 			DPAA_SEC_ERR("unable to attach sec queue");
28124e694fe5SAkhil Goyal 			rte_spinlock_unlock(&internals->lock);
28131f14d500SAkhil Goyal 			goto out;
28141f14d500SAkhil Goyal 		}
28154e694fe5SAkhil Goyal 	}
28164e694fe5SAkhil Goyal 	rte_spinlock_unlock(&internals->lock);
28171f14d500SAkhil Goyal 
2818a1173d55SHemant Agrawal 	return 0;
2819a1173d55SHemant Agrawal out:
28206290de2cSLukasz Wojciechowski 	free_session_data(session);
2821a1173d55SHemant Agrawal 	return -1;
2822a1173d55SHemant Agrawal }
28231f14d500SAkhil Goyal 
2824a1173d55SHemant Agrawal static int
2825a1173d55SHemant Agrawal dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
2826a1173d55SHemant Agrawal 			  struct rte_security_session_conf *conf,
2827a1173d55SHemant Agrawal 			  void *sess)
2828a1173d55SHemant Agrawal {
2829a1173d55SHemant Agrawal 	struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2830a1173d55SHemant Agrawal 	struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2831a1173d55SHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform = NULL;
2832a1173d55SHemant Agrawal 	struct rte_crypto_cipher_xform *cipher_xform = NULL;
2833a1173d55SHemant Agrawal 	dpaa_sec_session *session = (dpaa_sec_session *)sess;
2834a1173d55SHemant Agrawal 	struct dpaa_sec_dev_private *dev_priv = dev->data->dev_private;
28354e694fe5SAkhil Goyal 	uint32_t i;
2836c08ced9aSAkhil Goyal 	int ret;
2837a1173d55SHemant Agrawal 
2838a1173d55SHemant Agrawal 	PMD_INIT_FUNC_TRACE();
2839a1173d55SHemant Agrawal 
2840a1173d55SHemant Agrawal 	memset(session, 0, sizeof(dpaa_sec_session));
2841a1173d55SHemant Agrawal 
2842a1173d55SHemant Agrawal 	/* find xfrm types */
2843a1173d55SHemant Agrawal 	if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2844a1173d55SHemant Agrawal 		cipher_xform = &xform->cipher;
2845a1173d55SHemant Agrawal 		if (xform->next != NULL)
2846a1173d55SHemant Agrawal 			auth_xform = &xform->next->auth;
2847a1173d55SHemant Agrawal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2848a1173d55SHemant Agrawal 		auth_xform = &xform->auth;
2849a1173d55SHemant Agrawal 		if (xform->next != NULL)
2850a1173d55SHemant Agrawal 			cipher_xform = &xform->next->cipher;
2851a1173d55SHemant Agrawal 	} else {
2852a1173d55SHemant Agrawal 		DPAA_SEC_ERR("Invalid crypto type");
2853a1173d55SHemant Agrawal 		return -EINVAL;
2854a1173d55SHemant Agrawal 	}
2855a1173d55SHemant Agrawal 
2856a1173d55SHemant Agrawal 	session->proto_alg = conf->protocol;
28578524b44eSHemant Agrawal 	session->ctxt = DPAA_SEC_PDCP;
28588524b44eSHemant Agrawal 
2859a1173d55SHemant Agrawal 	if (cipher_xform) {
28608524b44eSHemant Agrawal 		switch (cipher_xform->algo) {
28618524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
28628524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_SNOW;
28638524b44eSHemant Agrawal 			break;
28648524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_ZUC_EEA3:
28658524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_ZUC;
28668524b44eSHemant Agrawal 			break;
28678524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_AES_CTR:
28688524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_AES;
28698524b44eSHemant Agrawal 			break;
28708524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_NULL:
28718524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_NULL;
28728524b44eSHemant Agrawal 			break;
28738524b44eSHemant Agrawal 		default:
28748524b44eSHemant Agrawal 			DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
28758524b44eSHemant Agrawal 				      session->cipher_alg);
2876c08ced9aSAkhil Goyal 			return -EINVAL;
28778524b44eSHemant Agrawal 		}
28788524b44eSHemant Agrawal 
2879a1173d55SHemant Agrawal 		session->cipher_key.data = rte_zmalloc(NULL,
2880a1173d55SHemant Agrawal 					       cipher_xform->key.length,
2881a1173d55SHemant Agrawal 					       RTE_CACHE_LINE_SIZE);
2882a1173d55SHemant Agrawal 		if (session->cipher_key.data == NULL &&
2883a1173d55SHemant Agrawal 				cipher_xform->key.length > 0) {
2884a1173d55SHemant Agrawal 			DPAA_SEC_ERR("No Memory for cipher key");
2885a1173d55SHemant Agrawal 			return -ENOMEM;
2886a1173d55SHemant Agrawal 		}
2887a1173d55SHemant Agrawal 		session->cipher_key.length = cipher_xform->key.length;
2888a1173d55SHemant Agrawal 		memcpy(session->cipher_key.data, cipher_xform->key.data,
2889a1173d55SHemant Agrawal 			cipher_xform->key.length);
2890a1173d55SHemant Agrawal 		session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2891a1173d55SHemant Agrawal 					DIR_ENC : DIR_DEC;
2892a1173d55SHemant Agrawal 		session->cipher_alg = cipher_xform->algo;
2893a1173d55SHemant Agrawal 	} else {
2894a1173d55SHemant Agrawal 		session->cipher_key.data = NULL;
2895a1173d55SHemant Agrawal 		session->cipher_key.length = 0;
2896a1173d55SHemant Agrawal 		session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2897a1173d55SHemant Agrawal 		session->dir = DIR_ENC;
2898a1173d55SHemant Agrawal 	}
2899a1173d55SHemant Agrawal 
2900a1173d55SHemant Agrawal 	if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
2901eac60082SVakul Garg 		if (pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_5 &&
2902eac60082SVakul Garg 		    pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_12) {
2903a1173d55SHemant Agrawal 			DPAA_SEC_ERR(
2904eac60082SVakul Garg 				"PDCP Seq Num size should be 5/12 bits for cmode");
2905c08ced9aSAkhil Goyal 			ret = -EINVAL;
2906a1173d55SHemant Agrawal 			goto out;
2907a1173d55SHemant Agrawal 		}
29082e4cbdb4SVakul Garg 	}
29092e4cbdb4SVakul Garg 
2910a1173d55SHemant Agrawal 	if (auth_xform) {
29118524b44eSHemant Agrawal 		switch (auth_xform->algo) {
29128524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
29138524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_SNOW;
29148524b44eSHemant Agrawal 			break;
29158524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_ZUC_EIA3:
29168524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_ZUC;
29178524b44eSHemant Agrawal 			break;
29188524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_AES_CMAC:
29198524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_AES;
29208524b44eSHemant Agrawal 			break;
29218524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_NULL:
29228524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_NULL;
29238524b44eSHemant Agrawal 			break;
29248524b44eSHemant Agrawal 		default:
29258524b44eSHemant Agrawal 			DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
29268524b44eSHemant Agrawal 				      session->auth_alg);
29278524b44eSHemant Agrawal 			rte_free(session->cipher_key.data);
2928c08ced9aSAkhil Goyal 			return -EINVAL;
29298524b44eSHemant Agrawal 		}
2930a1173d55SHemant Agrawal 		session->auth_key.data = rte_zmalloc(NULL,
2931a1173d55SHemant Agrawal 						     auth_xform->key.length,
2932a1173d55SHemant Agrawal 						     RTE_CACHE_LINE_SIZE);
29332e4cbdb4SVakul Garg 		if (!session->auth_key.data &&
2934a1173d55SHemant Agrawal 		    auth_xform->key.length > 0) {
2935a1173d55SHemant Agrawal 			DPAA_SEC_ERR("No Memory for auth key");
2936a1173d55SHemant Agrawal 			rte_free(session->cipher_key.data);
2937a1173d55SHemant Agrawal 			return -ENOMEM;
2938a1173d55SHemant Agrawal 		}
2939a1173d55SHemant Agrawal 		session->auth_key.length = auth_xform->key.length;
2940a1173d55SHemant Agrawal 		memcpy(session->auth_key.data, auth_xform->key.data,
2941a1173d55SHemant Agrawal 		       auth_xform->key.length);
2942a1173d55SHemant Agrawal 		session->auth_alg = auth_xform->algo;
2943a1173d55SHemant Agrawal 	} else {
2944a1173d55SHemant Agrawal 		session->auth_key.data = NULL;
2945a1173d55SHemant Agrawal 		session->auth_key.length = 0;
29462e4cbdb4SVakul Garg 		session->auth_alg = 0;
2947a1173d55SHemant Agrawal 	}
2948a1173d55SHemant Agrawal 	session->pdcp.domain = pdcp_xform->domain;
2949a1173d55SHemant Agrawal 	session->pdcp.bearer = pdcp_xform->bearer;
2950a1173d55SHemant Agrawal 	session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
2951a1173d55SHemant Agrawal 	session->pdcp.sn_size = pdcp_xform->sn_size;
2952a1173d55SHemant Agrawal 	session->pdcp.hfn = pdcp_xform->hfn;
2953a1173d55SHemant Agrawal 	session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
29546a0c9d36SAkhil Goyal 	session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
29556a0c9d36SAkhil Goyal 	session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
2956a1173d55SHemant Agrawal 
2957a1173d55SHemant Agrawal 	rte_spinlock_lock(&dev_priv->lock);
29584e694fe5SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
29594e694fe5SAkhil Goyal 		session->inq[i] = dpaa_sec_attach_rxq(dev_priv);
29604e694fe5SAkhil Goyal 		if (session->inq[i] == NULL) {
2961a1173d55SHemant Agrawal 			DPAA_SEC_ERR("unable to attach sec queue");
29624e694fe5SAkhil Goyal 			rte_spinlock_unlock(&dev_priv->lock);
2963c08ced9aSAkhil Goyal 			ret = -EBUSY;
2964a1173d55SHemant Agrawal 			goto out;
2965a1173d55SHemant Agrawal 		}
29664e694fe5SAkhil Goyal 	}
29674e694fe5SAkhil Goyal 	rte_spinlock_unlock(&dev_priv->lock);
29681f14d500SAkhil Goyal 	return 0;
29691f14d500SAkhil Goyal out:
29701f14d500SAkhil Goyal 	rte_free(session->auth_key.data);
29711f14d500SAkhil Goyal 	rte_free(session->cipher_key.data);
29721f14d500SAkhil Goyal 	memset(session, 0, sizeof(dpaa_sec_session));
2973c08ced9aSAkhil Goyal 	return ret;
29741f14d500SAkhil Goyal }
29751f14d500SAkhil Goyal 
29761f14d500SAkhil Goyal static int
29771f14d500SAkhil Goyal dpaa_sec_security_session_create(void *dev,
29781f14d500SAkhil Goyal 				 struct rte_security_session_conf *conf,
29791f14d500SAkhil Goyal 				 struct rte_security_session *sess,
29801f14d500SAkhil Goyal 				 struct rte_mempool *mempool)
29811f14d500SAkhil Goyal {
29821f14d500SAkhil Goyal 	void *sess_private_data;
29831f14d500SAkhil Goyal 	struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
29841f14d500SAkhil Goyal 	int ret;
29851f14d500SAkhil Goyal 
29861f14d500SAkhil Goyal 	if (rte_mempool_get(mempool, &sess_private_data)) {
2987f163231eSHemant Agrawal 		DPAA_SEC_ERR("Couldn't get object from session mempool");
29881f14d500SAkhil Goyal 		return -ENOMEM;
29891f14d500SAkhil Goyal 	}
29901f14d500SAkhil Goyal 
29911f14d500SAkhil Goyal 	switch (conf->protocol) {
29921f14d500SAkhil Goyal 	case RTE_SECURITY_PROTOCOL_IPSEC:
29931f14d500SAkhil Goyal 		ret = dpaa_sec_set_ipsec_session(cdev, conf,
29941f14d500SAkhil Goyal 				sess_private_data);
29951f14d500SAkhil Goyal 		break;
2996a1173d55SHemant Agrawal 	case RTE_SECURITY_PROTOCOL_PDCP:
2997a1173d55SHemant Agrawal 		ret = dpaa_sec_set_pdcp_session(cdev, conf,
2998a1173d55SHemant Agrawal 				sess_private_data);
2999a1173d55SHemant Agrawal 		break;
30001f14d500SAkhil Goyal 	case RTE_SECURITY_PROTOCOL_MACSEC:
30011f14d500SAkhil Goyal 		return -ENOTSUP;
30021f14d500SAkhil Goyal 	default:
30031f14d500SAkhil Goyal 		return -EINVAL;
30041f14d500SAkhil Goyal 	}
30051f14d500SAkhil Goyal 	if (ret != 0) {
3006f163231eSHemant Agrawal 		DPAA_SEC_ERR("failed to configure session parameters");
30071f14d500SAkhil Goyal 		/* Return session to mempool */
30081f14d500SAkhil Goyal 		rte_mempool_put(mempool, sess_private_data);
30091f14d500SAkhil Goyal 		return ret;
30101f14d500SAkhil Goyal 	}
30111f14d500SAkhil Goyal 
30121f14d500SAkhil Goyal 	set_sec_session_private_data(sess, sess_private_data);
30131f14d500SAkhil Goyal 
30141f14d500SAkhil Goyal 	return ret;
30151f14d500SAkhil Goyal }
30161f14d500SAkhil Goyal 
30171f14d500SAkhil Goyal /** Clear the memory of session so it doesn't leave key material behind */
30181f14d500SAkhil Goyal static int
30191f14d500SAkhil Goyal dpaa_sec_security_session_destroy(void *dev __rte_unused,
30201f14d500SAkhil Goyal 		struct rte_security_session *sess)
30211f14d500SAkhil Goyal {
30221f14d500SAkhil Goyal 	PMD_INIT_FUNC_TRACE();
30231f14d500SAkhil Goyal 	void *sess_priv = get_sec_session_private_data(sess);
30241f14d500SAkhil Goyal 	dpaa_sec_session *s = (dpaa_sec_session *)sess_priv;
30251f14d500SAkhil Goyal 
30261f14d500SAkhil Goyal 	if (sess_priv) {
30273d0d5332SAkhil Goyal 		free_session_memory((struct rte_cryptodev *)dev, s);
30281f14d500SAkhil Goyal 		set_sec_session_private_data(sess, NULL);
30291f14d500SAkhil Goyal 	}
30301f14d500SAkhil Goyal 	return 0;
30311f14d500SAkhil Goyal }
3032314424b6SHemant Agrawal #endif
30331f14d500SAkhil Goyal static int
30342ffb940eSAkhil Goyal dpaa_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3035c3e85bdcSAkhil Goyal 		       struct rte_cryptodev_config *config __rte_unused)
3036c3e85bdcSAkhil Goyal {
3037c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3038c3e85bdcSAkhil Goyal 
3039c3e85bdcSAkhil Goyal 	return 0;
3040c3e85bdcSAkhil Goyal }
3041c3e85bdcSAkhil Goyal 
3042c3e85bdcSAkhil Goyal static int
3043c3e85bdcSAkhil Goyal dpaa_sec_dev_start(struct rte_cryptodev *dev __rte_unused)
3044c3e85bdcSAkhil Goyal {
3045c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3046c3e85bdcSAkhil Goyal 	return 0;
3047c3e85bdcSAkhil Goyal }
3048c3e85bdcSAkhil Goyal 
3049c3e85bdcSAkhil Goyal static void
3050c3e85bdcSAkhil Goyal dpaa_sec_dev_stop(struct rte_cryptodev *dev __rte_unused)
3051c3e85bdcSAkhil Goyal {
3052c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3053c3e85bdcSAkhil Goyal }
3054c3e85bdcSAkhil Goyal 
3055c3e85bdcSAkhil Goyal static int
30567e3e2954SAkhil Goyal dpaa_sec_dev_close(struct rte_cryptodev *dev)
3057c3e85bdcSAkhil Goyal {
3058c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
30597e3e2954SAkhil Goyal 
30607e3e2954SAkhil Goyal 	if (dev == NULL)
30617e3e2954SAkhil Goyal 		return -ENOMEM;
30627e3e2954SAkhil Goyal 
3063c3e85bdcSAkhil Goyal 	return 0;
3064c3e85bdcSAkhil Goyal }
3065c3e85bdcSAkhil Goyal 
3066c3e85bdcSAkhil Goyal static void
3067c3e85bdcSAkhil Goyal dpaa_sec_dev_infos_get(struct rte_cryptodev *dev,
3068c3e85bdcSAkhil Goyal 		       struct rte_cryptodev_info *info)
3069c3e85bdcSAkhil Goyal {
3070c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals = dev->data->dev_private;
3071c3e85bdcSAkhil Goyal 
3072c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3073c3e85bdcSAkhil Goyal 	if (info != NULL) {
3074c3e85bdcSAkhil Goyal 		info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3075c3e85bdcSAkhil Goyal 		info->feature_flags = dev->feature_flags;
3076c3e85bdcSAkhil Goyal 		info->capabilities = dpaa_sec_capabilities;
3077c3e85bdcSAkhil Goyal 		info->sym.max_nb_sessions = internals->max_nb_sessions;
3078c3e85bdcSAkhil Goyal 		info->driver_id = cryptodev_driver_id;
3079c3e85bdcSAkhil Goyal 	}
3080c3e85bdcSAkhil Goyal }
3081c3e85bdcSAkhil Goyal 
3082fe3688baSAkhil Goyal static enum qman_cb_dqrr_result
3083fe3688baSAkhil Goyal dpaa_sec_process_parallel_event(void *event,
3084fe3688baSAkhil Goyal 			struct qman_portal *qm __always_unused,
3085fe3688baSAkhil Goyal 			struct qman_fq *outq,
3086fe3688baSAkhil Goyal 			const struct qm_dqrr_entry *dqrr,
3087fe3688baSAkhil Goyal 			void **bufs)
3088fe3688baSAkhil Goyal {
3089fe3688baSAkhil Goyal 	const struct qm_fd *fd;
3090fe3688baSAkhil Goyal 	struct dpaa_sec_job *job;
3091fe3688baSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
3092fe3688baSAkhil Goyal 	struct rte_event *ev = (struct rte_event *)event;
3093fe3688baSAkhil Goyal 
3094fe3688baSAkhil Goyal 	fd = &dqrr->fd;
3095fe3688baSAkhil Goyal 
3096fe3688baSAkhil Goyal 	/* sg is embedded in an op ctx,
3097fe3688baSAkhil Goyal 	 * sg[0] is for output
3098fe3688baSAkhil Goyal 	 * sg[1] for input
3099fe3688baSAkhil Goyal 	 */
3100ec861560SGagandeep Singh 	job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
3101fe3688baSAkhil Goyal 
3102fe3688baSAkhil Goyal 	ctx = container_of(job, struct dpaa_sec_op_ctx, job);
3103fe3688baSAkhil Goyal 	ctx->fd_status = fd->status;
3104fe3688baSAkhil Goyal 	if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
3105fe3688baSAkhil Goyal 		struct qm_sg_entry *sg_out;
3106fe3688baSAkhil Goyal 		uint32_t len;
3107fe3688baSAkhil Goyal 
3108fe3688baSAkhil Goyal 		sg_out = &job->sg[0];
3109fe3688baSAkhil Goyal 		hw_sg_to_cpu(sg_out);
3110fe3688baSAkhil Goyal 		len = sg_out->length;
3111fe3688baSAkhil Goyal 		ctx->op->sym->m_src->pkt_len = len;
3112fe3688baSAkhil Goyal 		ctx->op->sym->m_src->data_len = len;
3113fe3688baSAkhil Goyal 	}
3114fe3688baSAkhil Goyal 	if (!ctx->fd_status) {
3115fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
3116fe3688baSAkhil Goyal 	} else {
3117fe3688baSAkhil Goyal 		DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
3118fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
3119fe3688baSAkhil Goyal 	}
3120fe3688baSAkhil Goyal 	ev->event_ptr = (void *)ctx->op;
3121fe3688baSAkhil Goyal 
3122fe3688baSAkhil Goyal 	ev->flow_id = outq->ev.flow_id;
3123fe3688baSAkhil Goyal 	ev->sub_event_type = outq->ev.sub_event_type;
3124fe3688baSAkhil Goyal 	ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3125fe3688baSAkhil Goyal 	ev->op = RTE_EVENT_OP_NEW;
3126fe3688baSAkhil Goyal 	ev->sched_type = outq->ev.sched_type;
3127fe3688baSAkhil Goyal 	ev->queue_id = outq->ev.queue_id;
3128fe3688baSAkhil Goyal 	ev->priority = outq->ev.priority;
3129fe3688baSAkhil Goyal 	*bufs = (void *)ctx->op;
3130fe3688baSAkhil Goyal 
3131fe3688baSAkhil Goyal 	rte_mempool_put(ctx->ctx_pool, (void *)ctx);
3132fe3688baSAkhil Goyal 
3133fe3688baSAkhil Goyal 	return qman_cb_dqrr_consume;
3134fe3688baSAkhil Goyal }
3135fe3688baSAkhil Goyal 
3136fe3688baSAkhil Goyal static enum qman_cb_dqrr_result
3137fe3688baSAkhil Goyal dpaa_sec_process_atomic_event(void *event,
3138fe3688baSAkhil Goyal 			struct qman_portal *qm __rte_unused,
3139fe3688baSAkhil Goyal 			struct qman_fq *outq,
3140fe3688baSAkhil Goyal 			const struct qm_dqrr_entry *dqrr,
3141fe3688baSAkhil Goyal 			void **bufs)
3142fe3688baSAkhil Goyal {
3143fe3688baSAkhil Goyal 	u8 index;
3144fe3688baSAkhil Goyal 	const struct qm_fd *fd;
3145fe3688baSAkhil Goyal 	struct dpaa_sec_job *job;
3146fe3688baSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
3147fe3688baSAkhil Goyal 	struct rte_event *ev = (struct rte_event *)event;
3148fe3688baSAkhil Goyal 
3149fe3688baSAkhil Goyal 	fd = &dqrr->fd;
3150fe3688baSAkhil Goyal 
3151fe3688baSAkhil Goyal 	/* sg is embedded in an op ctx,
3152fe3688baSAkhil Goyal 	 * sg[0] is for output
3153fe3688baSAkhil Goyal 	 * sg[1] for input
3154fe3688baSAkhil Goyal 	 */
3155ec861560SGagandeep Singh 	job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
3156fe3688baSAkhil Goyal 
3157fe3688baSAkhil Goyal 	ctx = container_of(job, struct dpaa_sec_op_ctx, job);
3158fe3688baSAkhil Goyal 	ctx->fd_status = fd->status;
3159fe3688baSAkhil Goyal 	if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
3160fe3688baSAkhil Goyal 		struct qm_sg_entry *sg_out;
3161fe3688baSAkhil Goyal 		uint32_t len;
3162fe3688baSAkhil Goyal 
3163fe3688baSAkhil Goyal 		sg_out = &job->sg[0];
3164fe3688baSAkhil Goyal 		hw_sg_to_cpu(sg_out);
3165fe3688baSAkhil Goyal 		len = sg_out->length;
3166fe3688baSAkhil Goyal 		ctx->op->sym->m_src->pkt_len = len;
3167fe3688baSAkhil Goyal 		ctx->op->sym->m_src->data_len = len;
3168fe3688baSAkhil Goyal 	}
3169fe3688baSAkhil Goyal 	if (!ctx->fd_status) {
3170fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
3171fe3688baSAkhil Goyal 	} else {
3172fe3688baSAkhil Goyal 		DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
3173fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
3174fe3688baSAkhil Goyal 	}
3175fe3688baSAkhil Goyal 	ev->event_ptr = (void *)ctx->op;
3176fe3688baSAkhil Goyal 	ev->flow_id = outq->ev.flow_id;
3177fe3688baSAkhil Goyal 	ev->sub_event_type = outq->ev.sub_event_type;
3178fe3688baSAkhil Goyal 	ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3179fe3688baSAkhil Goyal 	ev->op = RTE_EVENT_OP_NEW;
3180fe3688baSAkhil Goyal 	ev->sched_type = outq->ev.sched_type;
3181fe3688baSAkhil Goyal 	ev->queue_id = outq->ev.queue_id;
3182fe3688baSAkhil Goyal 	ev->priority = outq->ev.priority;
3183fe3688baSAkhil Goyal 
3184fe3688baSAkhil Goyal 	/* Save active dqrr entries */
3185fe3688baSAkhil Goyal 	index = ((uintptr_t)dqrr >> 6) & (16/*QM_DQRR_SIZE*/ - 1);
3186fe3688baSAkhil Goyal 	DPAA_PER_LCORE_DQRR_SIZE++;
3187fe3688baSAkhil Goyal 	DPAA_PER_LCORE_DQRR_HELD |= 1 << index;
3188fe3688baSAkhil Goyal 	DPAA_PER_LCORE_DQRR_MBUF(index) = ctx->op->sym->m_src;
3189fe3688baSAkhil Goyal 	ev->impl_opaque = index + 1;
3190fe3688baSAkhil Goyal 	ctx->op->sym->m_src->seqn = (uint32_t)index + 1;
3191fe3688baSAkhil Goyal 	*bufs = (void *)ctx->op;
3192fe3688baSAkhil Goyal 
3193fe3688baSAkhil Goyal 	rte_mempool_put(ctx->ctx_pool, (void *)ctx);
3194fe3688baSAkhil Goyal 
3195fe3688baSAkhil Goyal 	return qman_cb_dqrr_defer;
3196fe3688baSAkhil Goyal }
3197fe3688baSAkhil Goyal 
3198fe3688baSAkhil Goyal int
3199fe3688baSAkhil Goyal dpaa_sec_eventq_attach(const struct rte_cryptodev *dev,
3200fe3688baSAkhil Goyal 		int qp_id,
3201fe3688baSAkhil Goyal 		uint16_t ch_id,
3202fe3688baSAkhil Goyal 		const struct rte_event *event)
3203fe3688baSAkhil Goyal {
3204fe3688baSAkhil Goyal 	struct dpaa_sec_qp *qp = dev->data->queue_pairs[qp_id];
3205fe3688baSAkhil Goyal 	struct qm_mcc_initfq opts = {0};
3206fe3688baSAkhil Goyal 
3207fe3688baSAkhil Goyal 	int ret;
3208fe3688baSAkhil Goyal 
3209fe3688baSAkhil Goyal 	opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
3210fe3688baSAkhil Goyal 		       QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
3211fe3688baSAkhil Goyal 	opts.fqd.dest.channel = ch_id;
3212fe3688baSAkhil Goyal 
3213fe3688baSAkhil Goyal 	switch (event->sched_type) {
3214fe3688baSAkhil Goyal 	case RTE_SCHED_TYPE_ATOMIC:
3215fe3688baSAkhil Goyal 		opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE;
3216fe3688baSAkhil Goyal 		/* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary
3217fe3688baSAkhil Goyal 		 * configuration with HOLD_ACTIVE setting
3218fe3688baSAkhil Goyal 		 */
3219fe3688baSAkhil Goyal 		opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK);
3220fe3688baSAkhil Goyal 		qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_atomic_event;
3221fe3688baSAkhil Goyal 		break;
3222fe3688baSAkhil Goyal 	case RTE_SCHED_TYPE_ORDERED:
3223fe3688baSAkhil Goyal 		DPAA_SEC_ERR("Ordered queue schedule type is not supported\n");
3224c08ced9aSAkhil Goyal 		return -ENOTSUP;
3225fe3688baSAkhil Goyal 	default:
3226fe3688baSAkhil Goyal 		opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
3227fe3688baSAkhil Goyal 		qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_parallel_event;
3228fe3688baSAkhil Goyal 		break;
3229fe3688baSAkhil Goyal 	}
3230fe3688baSAkhil Goyal 
3231fe3688baSAkhil Goyal 	ret = qman_init_fq(&qp->outq, QMAN_INITFQ_FLAG_SCHED, &opts);
3232fe3688baSAkhil Goyal 	if (unlikely(ret)) {
3233fe3688baSAkhil Goyal 		DPAA_SEC_ERR("unable to init caam source fq!");
3234fe3688baSAkhil Goyal 		return ret;
3235fe3688baSAkhil Goyal 	}
3236fe3688baSAkhil Goyal 
3237fe3688baSAkhil Goyal 	memcpy(&qp->outq.ev, event, sizeof(struct rte_event));
3238fe3688baSAkhil Goyal 
3239fe3688baSAkhil Goyal 	return 0;
3240fe3688baSAkhil Goyal }
3241fe3688baSAkhil Goyal 
3242fe3688baSAkhil Goyal int
3243fe3688baSAkhil Goyal dpaa_sec_eventq_detach(const struct rte_cryptodev *dev,
3244fe3688baSAkhil Goyal 			int qp_id)
3245fe3688baSAkhil Goyal {
3246fe3688baSAkhil Goyal 	struct qm_mcc_initfq opts = {0};
3247fe3688baSAkhil Goyal 	int ret;
3248fe3688baSAkhil Goyal 	struct dpaa_sec_qp *qp = dev->data->queue_pairs[qp_id];
3249fe3688baSAkhil Goyal 
3250fe3688baSAkhil Goyal 	opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
3251fe3688baSAkhil Goyal 		       QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
3252fe3688baSAkhil Goyal 	qp->outq.cb.dqrr = dqrr_out_fq_cb_rx;
3253fe3688baSAkhil Goyal 	qp->outq.cb.ern  = ern_sec_fq_handler;
3254fe3688baSAkhil Goyal 	qman_retire_fq(&qp->outq, NULL);
3255fe3688baSAkhil Goyal 	qman_oos_fq(&qp->outq);
3256fe3688baSAkhil Goyal 	ret = qman_init_fq(&qp->outq, 0, &opts);
3257fe3688baSAkhil Goyal 	if (ret)
3258fe3688baSAkhil Goyal 		RTE_LOG(ERR, PMD, "Error in qman_init_fq: ret: %d\n", ret);
3259fe3688baSAkhil Goyal 	qp->outq.cb.dqrr = NULL;
3260fe3688baSAkhil Goyal 
3261fe3688baSAkhil Goyal 	return ret;
3262fe3688baSAkhil Goyal }
3263fe3688baSAkhil Goyal 
3264c3e85bdcSAkhil Goyal static struct rte_cryptodev_ops crypto_ops = {
3265c3e85bdcSAkhil Goyal 	.dev_configure	      = dpaa_sec_dev_configure,
3266c3e85bdcSAkhil Goyal 	.dev_start	      = dpaa_sec_dev_start,
3267c3e85bdcSAkhil Goyal 	.dev_stop	      = dpaa_sec_dev_stop,
3268c3e85bdcSAkhil Goyal 	.dev_close	      = dpaa_sec_dev_close,
3269c3e85bdcSAkhil Goyal 	.dev_infos_get        = dpaa_sec_dev_infos_get,
3270c3e85bdcSAkhil Goyal 	.queue_pair_setup     = dpaa_sec_queue_pair_setup,
3271c3e85bdcSAkhil Goyal 	.queue_pair_release   = dpaa_sec_queue_pair_release,
3272012c5076SPablo de Lara 	.sym_session_get_size     = dpaa_sec_sym_session_get_size,
3273012c5076SPablo de Lara 	.sym_session_configure    = dpaa_sec_sym_session_configure,
3274012c5076SPablo de Lara 	.sym_session_clear        = dpaa_sec_sym_session_clear
3275c3e85bdcSAkhil Goyal };
3276c3e85bdcSAkhil Goyal 
3277314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
32781f14d500SAkhil Goyal static const struct rte_security_capability *
32791f14d500SAkhil Goyal dpaa_sec_capabilities_get(void *device __rte_unused)
32801f14d500SAkhil Goyal {
32811f14d500SAkhil Goyal 	return dpaa_sec_security_cap;
32821f14d500SAkhil Goyal }
32831f14d500SAkhil Goyal 
3284b74fd6b8SFerruh Yigit static const struct rte_security_ops dpaa_sec_security_ops = {
32851f14d500SAkhil Goyal 	.session_create = dpaa_sec_security_session_create,
32861f14d500SAkhil Goyal 	.session_update = NULL,
32871f14d500SAkhil Goyal 	.session_stats_get = NULL,
32881f14d500SAkhil Goyal 	.session_destroy = dpaa_sec_security_session_destroy,
32891f14d500SAkhil Goyal 	.set_pkt_metadata = NULL,
32901f14d500SAkhil Goyal 	.capabilities_get = dpaa_sec_capabilities_get
32911f14d500SAkhil Goyal };
3292314424b6SHemant Agrawal #endif
3293c3e85bdcSAkhil Goyal static int
3294c3e85bdcSAkhil Goyal dpaa_sec_uninit(struct rte_cryptodev *dev)
3295c3e85bdcSAkhil Goyal {
3296debef417SShreyansh Jain 	struct dpaa_sec_dev_private *internals;
3297c3e85bdcSAkhil Goyal 
3298c3e85bdcSAkhil Goyal 	if (dev == NULL)
3299c3e85bdcSAkhil Goyal 		return -ENODEV;
3300c3e85bdcSAkhil Goyal 
3301debef417SShreyansh Jain 	internals = dev->data->dev_private;
33021f14d500SAkhil Goyal 	rte_free(dev->security_ctx);
33031f14d500SAkhil Goyal 
3304c3e85bdcSAkhil Goyal 	rte_free(internals);
3305c3e85bdcSAkhil Goyal 
3306f163231eSHemant Agrawal 	DPAA_SEC_INFO("Closing DPAA_SEC device %s on numa socket %u",
3307c3e85bdcSAkhil Goyal 		      dev->data->name, rte_socket_id());
3308c3e85bdcSAkhil Goyal 
3309c3e85bdcSAkhil Goyal 	return 0;
3310c3e85bdcSAkhil Goyal }
3311c3e85bdcSAkhil Goyal 
3312c3e85bdcSAkhil Goyal static int
3313c3e85bdcSAkhil Goyal dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
3314c3e85bdcSAkhil Goyal {
3315c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals;
3316314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
33171f14d500SAkhil Goyal 	struct rte_security_ctx *security_instance;
3318314424b6SHemant Agrawal #endif
3319c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *qp;
3320e79416d1SHemant Agrawal 	uint32_t i, flags;
3321c3e85bdcSAkhil Goyal 	int ret;
3322c3e85bdcSAkhil Goyal 
3323c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3324c3e85bdcSAkhil Goyal 
3325c3e85bdcSAkhil Goyal 	cryptodev->driver_id = cryptodev_driver_id;
3326c3e85bdcSAkhil Goyal 	cryptodev->dev_ops = &crypto_ops;
3327c3e85bdcSAkhil Goyal 
3328c3e85bdcSAkhil Goyal 	cryptodev->enqueue_burst = dpaa_sec_enqueue_burst;
3329c3e85bdcSAkhil Goyal 	cryptodev->dequeue_burst = dpaa_sec_dequeue_burst;
3330c3e85bdcSAkhil Goyal 	cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3331c3e85bdcSAkhil Goyal 			RTE_CRYPTODEV_FF_HW_ACCELERATED |
33321f14d500SAkhil Goyal 			RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3333a74af788SAkhil Goyal 			RTE_CRYPTODEV_FF_SECURITY |
33342717246eSPablo de Lara 			RTE_CRYPTODEV_FF_IN_PLACE_SGL |
33352717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
33362717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
33372717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
33382717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3339c3e85bdcSAkhil Goyal 
3340c3e85bdcSAkhil Goyal 	internals = cryptodev->data->dev_private;
3341e79416d1SHemant Agrawal 	internals->max_nb_queue_pairs = RTE_DPAA_MAX_NB_SEC_QPS;
3342c3e85bdcSAkhil Goyal 	internals->max_nb_sessions = RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS;
3343c3e85bdcSAkhil Goyal 
33441f14d500SAkhil Goyal 	/*
33451f14d500SAkhil Goyal 	 * For secondary processes, we don't initialise any further as primary
33461f14d500SAkhil Goyal 	 * has already done this work. Only check we don't need a different
33471f14d500SAkhil Goyal 	 * RX function
33481f14d500SAkhil Goyal 	 */
33491f14d500SAkhil Goyal 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3350f163231eSHemant Agrawal 		DPAA_SEC_WARN("Device already init by primary process");
33511f14d500SAkhil Goyal 		return 0;
33521f14d500SAkhil Goyal 	}
3353314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
33541f14d500SAkhil Goyal 	/* Initialize security_ctx only for primary process*/
33551f14d500SAkhil Goyal 	security_instance = rte_malloc("rte_security_instances_ops",
33561f14d500SAkhil Goyal 				sizeof(struct rte_security_ctx), 0);
33571f14d500SAkhil Goyal 	if (security_instance == NULL)
33581f14d500SAkhil Goyal 		return -ENOMEM;
33591f14d500SAkhil Goyal 	security_instance->device = (void *)cryptodev;
33601f14d500SAkhil Goyal 	security_instance->ops = &dpaa_sec_security_ops;
33611f14d500SAkhil Goyal 	security_instance->sess_cnt = 0;
33621f14d500SAkhil Goyal 	cryptodev->security_ctx = security_instance;
3363314424b6SHemant Agrawal #endif
33643b617ee7SAkhil Goyal 	rte_spinlock_init(&internals->lock);
3365c3e85bdcSAkhil Goyal 	for (i = 0; i < internals->max_nb_queue_pairs; i++) {
3366c3e85bdcSAkhil Goyal 		/* init qman fq for queue pair */
3367c3e85bdcSAkhil Goyal 		qp = &internals->qps[i];
3368c3e85bdcSAkhil Goyal 		ret = dpaa_sec_init_tx(&qp->outq);
3369c3e85bdcSAkhil Goyal 		if (ret) {
3370f163231eSHemant Agrawal 			DPAA_SEC_ERR("config tx of queue pair  %d", i);
3371c3e85bdcSAkhil Goyal 			goto init_error;
3372c3e85bdcSAkhil Goyal 		}
3373e79416d1SHemant Agrawal 	}
3374e79416d1SHemant Agrawal 
3375e79416d1SHemant Agrawal 	flags = QMAN_FQ_FLAG_LOCKED | QMAN_FQ_FLAG_DYNAMIC_FQID |
3376e79416d1SHemant Agrawal 		QMAN_FQ_FLAG_TO_DCPORTAL;
3377fd900d38SGagandeep Singh 	for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) {
3378e79416d1SHemant Agrawal 		/* create rx qman fq for sessions*/
3379e79416d1SHemant Agrawal 		ret = qman_create_fq(0, flags, &internals->inq[i]);
3380e79416d1SHemant Agrawal 		if (unlikely(ret != 0)) {
3381f163231eSHemant Agrawal 			DPAA_SEC_ERR("sec qman_create_fq failed");
3382c3e85bdcSAkhil Goyal 			goto init_error;
3383c3e85bdcSAkhil Goyal 		}
3384c3e85bdcSAkhil Goyal 	}
3385c3e85bdcSAkhil Goyal 
3386f163231eSHemant Agrawal 	RTE_LOG(INFO, PMD, "%s cryptodev init\n", cryptodev->data->name);
3387c3e85bdcSAkhil Goyal 	return 0;
3388c3e85bdcSAkhil Goyal 
3389c3e85bdcSAkhil Goyal init_error:
3390f163231eSHemant Agrawal 	DPAA_SEC_ERR("driver %s: create failed\n", cryptodev->data->name);
3391c3e85bdcSAkhil Goyal 
33922eaf352dSLukasz Wojciechowski 	rte_free(cryptodev->security_ctx);
3393c3e85bdcSAkhil Goyal 	return -EFAULT;
3394c3e85bdcSAkhil Goyal }
3395c3e85bdcSAkhil Goyal 
3396c3e85bdcSAkhil Goyal static int
3397eb5a9a76SShreyansh Jain cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
3398c3e85bdcSAkhil Goyal 				struct rte_dpaa_device *dpaa_dev)
3399c3e85bdcSAkhil Goyal {
3400c3e85bdcSAkhil Goyal 	struct rte_cryptodev *cryptodev;
3401c3e85bdcSAkhil Goyal 	char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3402c3e85bdcSAkhil Goyal 
3403c3e85bdcSAkhil Goyal 	int retval;
3404c3e85bdcSAkhil Goyal 
34050964a951SHemant Agrawal 	snprintf(cryptodev_name, sizeof(cryptodev_name), "%s", dpaa_dev->name);
3406c3e85bdcSAkhil Goyal 
3407c3e85bdcSAkhil Goyal 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3408c3e85bdcSAkhil Goyal 	if (cryptodev == NULL)
3409c3e85bdcSAkhil Goyal 		return -ENOMEM;
3410c3e85bdcSAkhil Goyal 
3411c3e85bdcSAkhil Goyal 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3412c3e85bdcSAkhil Goyal 		cryptodev->data->dev_private = rte_zmalloc_socket(
3413c3e85bdcSAkhil Goyal 					"cryptodev private structure",
3414c3e85bdcSAkhil Goyal 					sizeof(struct dpaa_sec_dev_private),
3415c3e85bdcSAkhil Goyal 					RTE_CACHE_LINE_SIZE,
3416c3e85bdcSAkhil Goyal 					rte_socket_id());
3417c3e85bdcSAkhil Goyal 
3418c3e85bdcSAkhil Goyal 		if (cryptodev->data->dev_private == NULL)
3419c3e85bdcSAkhil Goyal 			rte_panic("Cannot allocate memzone for private "
3420c3e85bdcSAkhil Goyal 					"device data");
3421c3e85bdcSAkhil Goyal 	}
3422c3e85bdcSAkhil Goyal 
3423c3e85bdcSAkhil Goyal 	dpaa_dev->crypto_dev = cryptodev;
3424c3e85bdcSAkhil Goyal 	cryptodev->device = &dpaa_dev->device;
3425c3e85bdcSAkhil Goyal 
3426c3e85bdcSAkhil Goyal 	/* init user callbacks */
3427c3e85bdcSAkhil Goyal 	TAILQ_INIT(&(cryptodev->link_intr_cbs));
3428c3e85bdcSAkhil Goyal 
3429c3e85bdcSAkhil Goyal 	/* if sec device version is not configured */
3430c3e85bdcSAkhil Goyal 	if (!rta_get_sec_era()) {
3431c3e85bdcSAkhil Goyal 		const struct device_node *caam_node;
3432c3e85bdcSAkhil Goyal 
3433c3e85bdcSAkhil Goyal 		for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
3434c3e85bdcSAkhil Goyal 			const uint32_t *prop = of_get_property(caam_node,
3435c3e85bdcSAkhil Goyal 					"fsl,sec-era",
3436c3e85bdcSAkhil Goyal 					NULL);
3437c3e85bdcSAkhil Goyal 			if (prop) {
3438c3e85bdcSAkhil Goyal 				rta_set_sec_era(
3439c3e85bdcSAkhil Goyal 					INTL_SEC_ERA(rte_cpu_to_be_32(*prop)));
3440c3e85bdcSAkhil Goyal 				break;
3441c3e85bdcSAkhil Goyal 			}
3442c3e85bdcSAkhil Goyal 		}
3443c3e85bdcSAkhil Goyal 	}
3444c3e85bdcSAkhil Goyal 
3445408077f2SHemant Agrawal 	if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
3446408077f2SHemant Agrawal 		retval = rte_dpaa_portal_init((void *)1);
3447408077f2SHemant Agrawal 		if (retval) {
3448408077f2SHemant Agrawal 			DPAA_SEC_ERR("Unable to initialize portal");
34492eaf352dSLukasz Wojciechowski 			goto out;
3450408077f2SHemant Agrawal 		}
3451408077f2SHemant Agrawal 	}
3452408077f2SHemant Agrawal 
3453c3e85bdcSAkhil Goyal 	/* Invoke PMD device initialization function */
3454c3e85bdcSAkhil Goyal 	retval = dpaa_sec_dev_init(cryptodev);
3455c3e85bdcSAkhil Goyal 	if (retval == 0)
3456c3e85bdcSAkhil Goyal 		return 0;
3457c3e85bdcSAkhil Goyal 
34582eaf352dSLukasz Wojciechowski 	retval = -ENXIO;
34592eaf352dSLukasz Wojciechowski out:
3460c3e85bdcSAkhil Goyal 	/* In case of error, cleanup is done */
3461c3e85bdcSAkhil Goyal 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3462c3e85bdcSAkhil Goyal 		rte_free(cryptodev->data->dev_private);
3463c3e85bdcSAkhil Goyal 
3464c3e85bdcSAkhil Goyal 	rte_cryptodev_pmd_release_device(cryptodev);
3465c3e85bdcSAkhil Goyal 
34662eaf352dSLukasz Wojciechowski 	return retval;
3467c3e85bdcSAkhil Goyal }
3468c3e85bdcSAkhil Goyal 
3469c3e85bdcSAkhil Goyal static int
3470c3e85bdcSAkhil Goyal cryptodev_dpaa_sec_remove(struct rte_dpaa_device *dpaa_dev)
3471c3e85bdcSAkhil Goyal {
3472c3e85bdcSAkhil Goyal 	struct rte_cryptodev *cryptodev;
3473c3e85bdcSAkhil Goyal 	int ret;
3474c3e85bdcSAkhil Goyal 
3475c3e85bdcSAkhil Goyal 	cryptodev = dpaa_dev->crypto_dev;
3476c3e85bdcSAkhil Goyal 	if (cryptodev == NULL)
3477c3e85bdcSAkhil Goyal 		return -ENODEV;
3478c3e85bdcSAkhil Goyal 
3479c3e85bdcSAkhil Goyal 	ret = dpaa_sec_uninit(cryptodev);
3480c3e85bdcSAkhil Goyal 	if (ret)
3481c3e85bdcSAkhil Goyal 		return ret;
3482c3e85bdcSAkhil Goyal 
3483f2f020d2SDeclan Doherty 	return rte_cryptodev_pmd_destroy(cryptodev);
3484c3e85bdcSAkhil Goyal }
3485c3e85bdcSAkhil Goyal 
3486c3e85bdcSAkhil Goyal static struct rte_dpaa_driver rte_dpaa_sec_driver = {
3487c3e85bdcSAkhil Goyal 	.drv_type = FSL_DPAA_CRYPTO,
3488c3e85bdcSAkhil Goyal 	.driver = {
3489c3e85bdcSAkhil Goyal 		.name = "DPAA SEC PMD"
3490c3e85bdcSAkhil Goyal 	},
3491c3e85bdcSAkhil Goyal 	.probe = cryptodev_dpaa_sec_probe,
3492c3e85bdcSAkhil Goyal 	.remove = cryptodev_dpaa_sec_remove,
3493c3e85bdcSAkhil Goyal };
3494c3e85bdcSAkhil Goyal 
3495c3e85bdcSAkhil Goyal static struct cryptodev_driver dpaa_sec_crypto_drv;
3496c3e85bdcSAkhil Goyal 
3497c3e85bdcSAkhil Goyal RTE_PMD_REGISTER_DPAA(CRYPTODEV_NAME_DPAA_SEC_PMD, rte_dpaa_sec_driver);
3498f737f5ceSFiona Trahe RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa_sec_crypto_drv, rte_dpaa_sec_driver.driver,
3499c3e85bdcSAkhil Goyal 		cryptodev_driver_id);
35009c99878aSJerin Jacob RTE_LOG_REGISTER(dpaa_logtype_sec, pmd.crypto.dpaa, NOTICE);
3501