xref: /dpdk/drivers/crypto/dpaa_sec/dpaa_sec.c (revision e58722218aa9ad6b527423f8b95e788e6c5a15b7)
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 
48e79416d1SHemant Agrawal static int
49e79416d1SHemant Agrawal dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess);
50e79416d1SHemant Agrawal 
51c3e85bdcSAkhil Goyal static inline void
52c3e85bdcSAkhil Goyal dpaa_sec_op_ending(struct dpaa_sec_op_ctx *ctx)
53c3e85bdcSAkhil Goyal {
54c3e85bdcSAkhil Goyal 	if (!ctx->fd_status) {
55c3e85bdcSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
56c3e85bdcSAkhil Goyal 	} else {
57f163231eSHemant Agrawal 		DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
58c3e85bdcSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
59c3e85bdcSAkhil Goyal 	}
60c3e85bdcSAkhil Goyal }
61c3e85bdcSAkhil Goyal 
62c3e85bdcSAkhil Goyal static inline struct dpaa_sec_op_ctx *
63f7a5752eSHemant Agrawal dpaa_sec_alloc_ctx(dpaa_sec_session *ses, int sg_count)
64c3e85bdcSAkhil Goyal {
65c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
66f7a5752eSHemant Agrawal 	int i, retval;
67c3e85bdcSAkhil Goyal 
682ffb940eSAkhil Goyal 	retval = rte_mempool_get(
692ffb940eSAkhil Goyal 			ses->qp[rte_lcore_id() % MAX_DPAA_CORES]->ctx_pool,
702ffb940eSAkhil Goyal 			(void **)(&ctx));
71c3e85bdcSAkhil Goyal 	if (!ctx || retval) {
72f163231eSHemant Agrawal 		DPAA_SEC_DP_WARN("Alloc sec descriptor failed!");
73c3e85bdcSAkhil Goyal 		return NULL;
74c3e85bdcSAkhil Goyal 	}
75c3e85bdcSAkhil Goyal 	/*
76c3e85bdcSAkhil Goyal 	 * Clear SG memory. There are 16 SG entries of 16 Bytes each.
77c3e85bdcSAkhil Goyal 	 * one call to dcbz_64() clear 64 bytes, hence calling it 4 times
78c3e85bdcSAkhil Goyal 	 * to clear all the SG entries. dpaa_sec_alloc_ctx() is called for
79c3e85bdcSAkhil Goyal 	 * each packet, memset is costlier than dcbz_64().
80c3e85bdcSAkhil Goyal 	 */
81f7a5752eSHemant Agrawal 	for (i = 0; i < sg_count && i < MAX_JOB_SG_ENTRIES; i += 4)
82f7a5752eSHemant Agrawal 		dcbz_64(&ctx->job.sg[i]);
83c3e85bdcSAkhil Goyal 
842ffb940eSAkhil Goyal 	ctx->ctx_pool = ses->qp[rte_lcore_id() % MAX_DPAA_CORES]->ctx_pool;
85f7a5752eSHemant Agrawal 	ctx->vtop_offset = (size_t) ctx - rte_mempool_virt2iova(ctx);
86c3e85bdcSAkhil Goyal 
87c3e85bdcSAkhil Goyal 	return ctx;
88c3e85bdcSAkhil Goyal }
89c3e85bdcSAkhil Goyal 
90c3e85bdcSAkhil Goyal static void
91c3e85bdcSAkhil Goyal ern_sec_fq_handler(struct qman_portal *qm __rte_unused,
92c3e85bdcSAkhil Goyal 		   struct qman_fq *fq,
93c3e85bdcSAkhil Goyal 		   const struct qm_mr_entry *msg)
94c3e85bdcSAkhil Goyal {
95f163231eSHemant Agrawal 	DPAA_SEC_DP_ERR("sec fq %d error, RC = %x, seqnum = %x\n",
96c3e85bdcSAkhil Goyal 			fq->fqid, msg->ern.rc, msg->ern.seqnum);
97c3e85bdcSAkhil Goyal }
98c3e85bdcSAkhil Goyal 
99c3e85bdcSAkhil Goyal /* initialize the queue with dest chan as caam chan so that
100c3e85bdcSAkhil Goyal  * all the packets in this queue could be dispatched into caam
101c3e85bdcSAkhil Goyal  */
102c3e85bdcSAkhil Goyal static int
103c4509373SSantosh Shukla dpaa_sec_init_rx(struct qman_fq *fq_in, rte_iova_t hwdesc,
104c3e85bdcSAkhil Goyal 		 uint32_t fqid_out)
105c3e85bdcSAkhil Goyal {
106c3e85bdcSAkhil Goyal 	struct qm_mcc_initfq fq_opts;
107c3e85bdcSAkhil Goyal 	uint32_t flags;
108c3e85bdcSAkhil Goyal 	int ret = -1;
109c3e85bdcSAkhil Goyal 
110c3e85bdcSAkhil Goyal 	/* Clear FQ options */
111c3e85bdcSAkhil Goyal 	memset(&fq_opts, 0x00, sizeof(struct qm_mcc_initfq));
112c3e85bdcSAkhil Goyal 
113c3e85bdcSAkhil Goyal 	flags = QMAN_INITFQ_FLAG_SCHED;
114c3e85bdcSAkhil Goyal 	fq_opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_CONTEXTA |
115c3e85bdcSAkhil Goyal 			  QM_INITFQ_WE_CONTEXTB;
116c3e85bdcSAkhil Goyal 
117c3e85bdcSAkhil Goyal 	qm_fqd_context_a_set64(&fq_opts.fqd, hwdesc);
118c3e85bdcSAkhil Goyal 	fq_opts.fqd.context_b = fqid_out;
119a8ee206aSHemant Agrawal 	fq_opts.fqd.dest.channel = dpaa_get_qm_channel_caam();
120c3e85bdcSAkhil Goyal 	fq_opts.fqd.dest.wq = 0;
121c3e85bdcSAkhil Goyal 
122c3e85bdcSAkhil Goyal 	fq_in->cb.ern  = ern_sec_fq_handler;
123c3e85bdcSAkhil Goyal 
124f163231eSHemant Agrawal 	DPAA_SEC_DEBUG("in-%x out-%x", fq_in->fqid, fqid_out);
125e79416d1SHemant Agrawal 
126c3e85bdcSAkhil Goyal 	ret = qman_init_fq(fq_in, flags, &fq_opts);
127c3e85bdcSAkhil Goyal 	if (unlikely(ret != 0))
128f163231eSHemant Agrawal 		DPAA_SEC_ERR("qman_init_fq failed %d", ret);
129c3e85bdcSAkhil Goyal 
130c3e85bdcSAkhil Goyal 	return ret;
131c3e85bdcSAkhil Goyal }
132c3e85bdcSAkhil Goyal 
133c3e85bdcSAkhil Goyal /* something is put into in_fq and caam put the crypto result into out_fq */
134c3e85bdcSAkhil Goyal static enum qman_cb_dqrr_result
135c3e85bdcSAkhil Goyal dqrr_out_fq_cb_rx(struct qman_portal *qm __always_unused,
136c3e85bdcSAkhil Goyal 		  struct qman_fq *fq __always_unused,
137c3e85bdcSAkhil Goyal 		  const struct qm_dqrr_entry *dqrr)
138c3e85bdcSAkhil Goyal {
139c3e85bdcSAkhil Goyal 	const struct qm_fd *fd;
140c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *job;
141c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
142c3e85bdcSAkhil Goyal 
143*e5872221SRohit Raj 	if (DPAA_PER_LCORE_DPAA_SEC_OP_NB >= DPAA_SEC_BURST)
144c3e85bdcSAkhil Goyal 		return qman_cb_dqrr_defer;
145c3e85bdcSAkhil Goyal 
146c3e85bdcSAkhil Goyal 	if (!(dqrr->stat & QM_DQRR_STAT_FD_VALID))
147c3e85bdcSAkhil Goyal 		return qman_cb_dqrr_consume;
148c3e85bdcSAkhil Goyal 
149c3e85bdcSAkhil Goyal 	fd = &dqrr->fd;
150c3e85bdcSAkhil Goyal 	/* sg is embedded in an op ctx,
151c3e85bdcSAkhil Goyal 	 * sg[0] is for output
152c3e85bdcSAkhil Goyal 	 * sg[1] for input
153c3e85bdcSAkhil Goyal 	 */
154ec861560SGagandeep Singh 	job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
1551f14d500SAkhil Goyal 
156c3e85bdcSAkhil Goyal 	ctx = container_of(job, struct dpaa_sec_op_ctx, job);
157c3e85bdcSAkhil Goyal 	ctx->fd_status = fd->status;
1581f14d500SAkhil Goyal 	if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1591f14d500SAkhil Goyal 		struct qm_sg_entry *sg_out;
1601f14d500SAkhil Goyal 		uint32_t len;
161fb5c100aSAkhil Goyal 		struct rte_mbuf *mbuf = (ctx->op->sym->m_dst == NULL) ?
162fb5c100aSAkhil Goyal 				ctx->op->sym->m_src : ctx->op->sym->m_dst;
1631f14d500SAkhil Goyal 
1641f14d500SAkhil Goyal 		sg_out = &job->sg[0];
1651f14d500SAkhil Goyal 		hw_sg_to_cpu(sg_out);
1661f14d500SAkhil Goyal 		len = sg_out->length;
167fb5c100aSAkhil Goyal 		mbuf->pkt_len = len;
168fb5c100aSAkhil Goyal 		while (mbuf->next != NULL) {
169fb5c100aSAkhil Goyal 			len -= mbuf->data_len;
170fb5c100aSAkhil Goyal 			mbuf = mbuf->next;
171fb5c100aSAkhil Goyal 		}
172fb5c100aSAkhil Goyal 		mbuf->data_len = len;
1731f14d500SAkhil Goyal 	}
174*e5872221SRohit Raj 	DPAA_PER_LCORE_RTE_CRYPTO_OP[DPAA_PER_LCORE_DPAA_SEC_OP_NB++] = ctx->op;
175c3e85bdcSAkhil Goyal 	dpaa_sec_op_ending(ctx);
176c3e85bdcSAkhil Goyal 
177c3e85bdcSAkhil Goyal 	return qman_cb_dqrr_consume;
178c3e85bdcSAkhil Goyal }
179c3e85bdcSAkhil Goyal 
180c3e85bdcSAkhil Goyal /* caam result is put into this queue */
181c3e85bdcSAkhil Goyal static int
182c3e85bdcSAkhil Goyal dpaa_sec_init_tx(struct qman_fq *fq)
183c3e85bdcSAkhil Goyal {
184c3e85bdcSAkhil Goyal 	int ret;
185c3e85bdcSAkhil Goyal 	struct qm_mcc_initfq opts;
186c3e85bdcSAkhil Goyal 	uint32_t flags;
187c3e85bdcSAkhil Goyal 
188c3e85bdcSAkhil Goyal 	flags = QMAN_FQ_FLAG_NO_ENQUEUE | QMAN_FQ_FLAG_LOCKED |
189c3e85bdcSAkhil Goyal 		QMAN_FQ_FLAG_DYNAMIC_FQID;
190c3e85bdcSAkhil Goyal 
191c3e85bdcSAkhil Goyal 	ret = qman_create_fq(0, flags, fq);
192c3e85bdcSAkhil Goyal 	if (unlikely(ret)) {
193f163231eSHemant Agrawal 		DPAA_SEC_ERR("qman_create_fq failed");
194c3e85bdcSAkhil Goyal 		return ret;
195c3e85bdcSAkhil Goyal 	}
196c3e85bdcSAkhil Goyal 
197c3e85bdcSAkhil Goyal 	memset(&opts, 0, sizeof(opts));
198c3e85bdcSAkhil Goyal 	opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
199c3e85bdcSAkhil Goyal 		       QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
200c3e85bdcSAkhil Goyal 
201c3e85bdcSAkhil Goyal 	/* opts.fqd.dest.channel = dpaa_sec_pool_chan; */
202c3e85bdcSAkhil Goyal 
203c3e85bdcSAkhil Goyal 	fq->cb.dqrr = dqrr_out_fq_cb_rx;
204c3e85bdcSAkhil Goyal 	fq->cb.ern  = ern_sec_fq_handler;
205c3e85bdcSAkhil Goyal 
206c3e85bdcSAkhil Goyal 	ret = qman_init_fq(fq, 0, &opts);
207c3e85bdcSAkhil Goyal 	if (unlikely(ret)) {
208f163231eSHemant Agrawal 		DPAA_SEC_ERR("unable to init caam source fq!");
209c3e85bdcSAkhil Goyal 		return ret;
210c3e85bdcSAkhil Goyal 	}
211c3e85bdcSAkhil Goyal 
212c3e85bdcSAkhil Goyal 	return ret;
213c3e85bdcSAkhil Goyal }
214c3e85bdcSAkhil Goyal 
2156290de2cSLukasz Wojciechowski static inline int is_aead(dpaa_sec_session *ses)
2166290de2cSLukasz Wojciechowski {
2176290de2cSLukasz Wojciechowski 	return ((ses->cipher_alg == 0) &&
2186290de2cSLukasz Wojciechowski 		(ses->auth_alg == 0) &&
2196290de2cSLukasz Wojciechowski 		(ses->aead_alg != 0));
2206290de2cSLukasz Wojciechowski }
2216290de2cSLukasz Wojciechowski 
222c3e85bdcSAkhil Goyal static inline int is_encode(dpaa_sec_session *ses)
223c3e85bdcSAkhil Goyal {
224c3e85bdcSAkhil Goyal 	return ses->dir == DIR_ENC;
225c3e85bdcSAkhil Goyal }
226c3e85bdcSAkhil Goyal 
227c3e85bdcSAkhil Goyal static inline int is_decode(dpaa_sec_session *ses)
228c3e85bdcSAkhil Goyal {
229c3e85bdcSAkhil Goyal 	return ses->dir == DIR_DEC;
230c3e85bdcSAkhil Goyal }
231c3e85bdcSAkhil Goyal 
232314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
233a1173d55SHemant Agrawal static int
234a1173d55SHemant Agrawal dpaa_sec_prep_pdcp_cdb(dpaa_sec_session *ses)
235a1173d55SHemant Agrawal {
236a1173d55SHemant Agrawal 	struct alginfo authdata = {0}, cipherdata = {0};
237a1173d55SHemant Agrawal 	struct sec_cdb *cdb = &ses->cdb;
2382e4cbdb4SVakul Garg 	struct alginfo *p_authdata = NULL;
239a1173d55SHemant Agrawal 	int32_t shared_desc_len = 0;
240a1173d55SHemant Agrawal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
241a1173d55SHemant Agrawal 	int swap = false;
242a1173d55SHemant Agrawal #else
243a1173d55SHemant Agrawal 	int swap = true;
244a1173d55SHemant Agrawal #endif
245a1173d55SHemant Agrawal 
246a1173d55SHemant Agrawal 	cipherdata.key = (size_t)ses->cipher_key.data;
247a1173d55SHemant Agrawal 	cipherdata.keylen = ses->cipher_key.length;
248a1173d55SHemant Agrawal 	cipherdata.key_enc_flags = 0;
249a1173d55SHemant Agrawal 	cipherdata.key_type = RTA_DATA_IMM;
2508524b44eSHemant Agrawal 	cipherdata.algtype = ses->cipher_key.alg;
2518524b44eSHemant Agrawal 	cipherdata.algmode = ses->cipher_key.algmode;
252a1173d55SHemant Agrawal 
2532e4cbdb4SVakul Garg 	if (ses->auth_alg) {
254a1173d55SHemant Agrawal 		authdata.key = (size_t)ses->auth_key.data;
255a1173d55SHemant Agrawal 		authdata.keylen = ses->auth_key.length;
256a1173d55SHemant Agrawal 		authdata.key_enc_flags = 0;
257a1173d55SHemant Agrawal 		authdata.key_type = RTA_DATA_IMM;
2588524b44eSHemant Agrawal 		authdata.algtype = ses->auth_key.alg;
2598524b44eSHemant Agrawal 		authdata.algmode = ses->auth_key.algmode;
260a1173d55SHemant Agrawal 
2612e4cbdb4SVakul Garg 		p_authdata = &authdata;
2622e4cbdb4SVakul Garg 	}
2632e4cbdb4SVakul Garg 
264f6ab96f1SAkhil Goyal 	if (rta_inline_pdcp_query(authdata.algtype,
265f6ab96f1SAkhil Goyal 				cipherdata.algtype,
266f6ab96f1SAkhil Goyal 				ses->pdcp.sn_size,
267f6ab96f1SAkhil Goyal 				ses->pdcp.hfn_ovd)) {
2682e4cbdb4SVakul Garg 		cipherdata.key =
269f6ab96f1SAkhil Goyal 			(size_t)rte_dpaa_mem_vtop((void *)
270f6ab96f1SAkhil Goyal 					(size_t)cipherdata.key);
271a1173d55SHemant Agrawal 		cipherdata.key_type = RTA_DATA_PTR;
272a1173d55SHemant Agrawal 	}
273a1173d55SHemant Agrawal 
2742e4cbdb4SVakul Garg 	if (ses->pdcp.domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
275a1173d55SHemant Agrawal 		if (ses->dir == DIR_ENC)
276a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_c_plane_encap(
277a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
278a1173d55SHemant Agrawal 					ses->pdcp.hfn,
279eac60082SVakul Garg 					ses->pdcp.sn_size,
280a1173d55SHemant Agrawal 					ses->pdcp.bearer,
281a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
282a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
283a1173d55SHemant Agrawal 					&cipherdata, &authdata,
284a1173d55SHemant Agrawal 					0);
285a1173d55SHemant Agrawal 		else if (ses->dir == DIR_DEC)
286a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_c_plane_decap(
287a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
288a1173d55SHemant Agrawal 					ses->pdcp.hfn,
289eac60082SVakul Garg 					ses->pdcp.sn_size,
290a1173d55SHemant Agrawal 					ses->pdcp.bearer,
291a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
292a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
293a1173d55SHemant Agrawal 					&cipherdata, &authdata,
294a1173d55SHemant Agrawal 					0);
295a1173d55SHemant Agrawal 	} else {
296a1173d55SHemant Agrawal 		if (ses->dir == DIR_ENC)
297a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_u_plane_encap(
298a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
299a1173d55SHemant Agrawal 					ses->pdcp.sn_size,
300a1173d55SHemant Agrawal 					ses->pdcp.hfn,
301a1173d55SHemant Agrawal 					ses->pdcp.bearer,
302a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
303a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
3042e4cbdb4SVakul Garg 					&cipherdata, p_authdata, 0);
305a1173d55SHemant Agrawal 		else if (ses->dir == DIR_DEC)
306a1173d55SHemant Agrawal 			shared_desc_len = cnstr_shdsc_pdcp_u_plane_decap(
307a1173d55SHemant Agrawal 					cdb->sh_desc, 1, swap,
308a1173d55SHemant Agrawal 					ses->pdcp.sn_size,
309a1173d55SHemant Agrawal 					ses->pdcp.hfn,
310a1173d55SHemant Agrawal 					ses->pdcp.bearer,
311a1173d55SHemant Agrawal 					ses->pdcp.pkt_dir,
312a1173d55SHemant Agrawal 					ses->pdcp.hfn_threshold,
3132e4cbdb4SVakul Garg 					&cipherdata, p_authdata, 0);
314a1173d55SHemant Agrawal 	}
315a1173d55SHemant Agrawal 	return shared_desc_len;
316a1173d55SHemant Agrawal }
317a1173d55SHemant Agrawal 
31805b12700SHemant Agrawal /* prepare ipsec proto command block of the session */
31905b12700SHemant Agrawal static int
32005b12700SHemant Agrawal dpaa_sec_prep_ipsec_cdb(dpaa_sec_session *ses)
32105b12700SHemant Agrawal {
32205b12700SHemant Agrawal 	struct alginfo cipherdata = {0}, authdata = {0};
32305b12700SHemant Agrawal 	struct sec_cdb *cdb = &ses->cdb;
32405b12700SHemant Agrawal 	int32_t shared_desc_len = 0;
32505b12700SHemant Agrawal 	int err;
32605b12700SHemant Agrawal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
32705b12700SHemant Agrawal 	int swap = false;
32805b12700SHemant Agrawal #else
32905b12700SHemant Agrawal 	int swap = true;
33005b12700SHemant Agrawal #endif
33105b12700SHemant Agrawal 
33205b12700SHemant Agrawal 	cipherdata.key = (size_t)ses->cipher_key.data;
33305b12700SHemant Agrawal 	cipherdata.keylen = ses->cipher_key.length;
33405b12700SHemant Agrawal 	cipherdata.key_enc_flags = 0;
33505b12700SHemant Agrawal 	cipherdata.key_type = RTA_DATA_IMM;
3368524b44eSHemant Agrawal 	cipherdata.algtype = ses->cipher_key.alg;
3378524b44eSHemant Agrawal 	cipherdata.algmode = ses->cipher_key.algmode;
33805b12700SHemant Agrawal 
3392c318722SHemant Agrawal 	if (ses->auth_key.length) {
34005b12700SHemant Agrawal 		authdata.key = (size_t)ses->auth_key.data;
34105b12700SHemant Agrawal 		authdata.keylen = ses->auth_key.length;
34205b12700SHemant Agrawal 		authdata.key_enc_flags = 0;
34305b12700SHemant Agrawal 		authdata.key_type = RTA_DATA_IMM;
3448524b44eSHemant Agrawal 		authdata.algtype = ses->auth_key.alg;
3458524b44eSHemant Agrawal 		authdata.algmode = ses->auth_key.algmode;
3462c318722SHemant Agrawal 	}
34705b12700SHemant Agrawal 
34805b12700SHemant Agrawal 	cdb->sh_desc[0] = cipherdata.keylen;
34905b12700SHemant Agrawal 	cdb->sh_desc[1] = authdata.keylen;
35005b12700SHemant Agrawal 	err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
351453b9593SAkhil Goyal 			       DESC_JOB_IO_LEN,
35205b12700SHemant Agrawal 			       (unsigned int *)cdb->sh_desc,
35305b12700SHemant Agrawal 			       &cdb->sh_desc[2], 2);
35405b12700SHemant Agrawal 
35505b12700SHemant Agrawal 	if (err < 0) {
35605b12700SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Incorrect key lengths");
35705b12700SHemant Agrawal 		return err;
35805b12700SHemant Agrawal 	}
35905b12700SHemant Agrawal 	if (cdb->sh_desc[2] & 1)
36005b12700SHemant Agrawal 		cipherdata.key_type = RTA_DATA_IMM;
36105b12700SHemant Agrawal 	else {
362ec861560SGagandeep Singh 		cipherdata.key = (size_t)rte_dpaa_mem_vtop(
36305b12700SHemant Agrawal 					(void *)(size_t)cipherdata.key);
36405b12700SHemant Agrawal 		cipherdata.key_type = RTA_DATA_PTR;
36505b12700SHemant Agrawal 	}
36605b12700SHemant Agrawal 	if (cdb->sh_desc[2] & (1<<1))
36705b12700SHemant Agrawal 		authdata.key_type = RTA_DATA_IMM;
36805b12700SHemant Agrawal 	else {
369ec861560SGagandeep Singh 		authdata.key = (size_t)rte_dpaa_mem_vtop(
37005b12700SHemant Agrawal 					(void *)(size_t)authdata.key);
37105b12700SHemant Agrawal 		authdata.key_type = RTA_DATA_PTR;
37205b12700SHemant Agrawal 	}
37305b12700SHemant Agrawal 
37405b12700SHemant Agrawal 	cdb->sh_desc[0] = 0;
37505b12700SHemant Agrawal 	cdb->sh_desc[1] = 0;
37605b12700SHemant Agrawal 	cdb->sh_desc[2] = 0;
37705b12700SHemant Agrawal 	if (ses->dir == DIR_ENC) {
37805b12700SHemant Agrawal 		shared_desc_len = cnstr_shdsc_ipsec_new_encap(
37905b12700SHemant Agrawal 				cdb->sh_desc,
38005b12700SHemant Agrawal 				true, swap, SHR_SERIAL,
38105b12700SHemant Agrawal 				&ses->encap_pdb,
38205b12700SHemant Agrawal 				(uint8_t *)&ses->ip4_hdr,
38305b12700SHemant Agrawal 				&cipherdata, &authdata);
38405b12700SHemant Agrawal 	} else if (ses->dir == DIR_DEC) {
38505b12700SHemant Agrawal 		shared_desc_len = cnstr_shdsc_ipsec_new_decap(
38605b12700SHemant Agrawal 				cdb->sh_desc,
38705b12700SHemant Agrawal 				true, swap, SHR_SERIAL,
38805b12700SHemant Agrawal 				&ses->decap_pdb,
38905b12700SHemant Agrawal 				&cipherdata, &authdata);
39005b12700SHemant Agrawal 	}
39105b12700SHemant Agrawal 	return shared_desc_len;
39205b12700SHemant Agrawal }
393314424b6SHemant Agrawal #endif
394c3e85bdcSAkhil Goyal /* prepare command block of the session */
395c3e85bdcSAkhil Goyal static int
396c3e85bdcSAkhil Goyal dpaa_sec_prep_cdb(dpaa_sec_session *ses)
397c3e85bdcSAkhil Goyal {
398c3e85bdcSAkhil Goyal 	struct alginfo alginfo_c = {0}, alginfo_a = {0}, alginfo = {0};
39922788c2cSSunil Kumar Kori 	int32_t shared_desc_len = 0;
400e79416d1SHemant Agrawal 	struct sec_cdb *cdb = &ses->cdb;
401c3e85bdcSAkhil Goyal 	int err;
402c3e85bdcSAkhil Goyal #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
403c3e85bdcSAkhil Goyal 	int swap = false;
404c3e85bdcSAkhil Goyal #else
405c3e85bdcSAkhil Goyal 	int swap = true;
406c3e85bdcSAkhil Goyal #endif
407c3e85bdcSAkhil Goyal 
408c3e85bdcSAkhil Goyal 	memset(cdb, 0, sizeof(struct sec_cdb));
409c3e85bdcSAkhil Goyal 
4108524b44eSHemant Agrawal 	switch (ses->ctxt) {
411314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
4128524b44eSHemant Agrawal 	case DPAA_SEC_IPSEC:
41305b12700SHemant Agrawal 		shared_desc_len = dpaa_sec_prep_ipsec_cdb(ses);
4148524b44eSHemant Agrawal 		break;
4158524b44eSHemant Agrawal 	case DPAA_SEC_PDCP:
416a1173d55SHemant Agrawal 		shared_desc_len = dpaa_sec_prep_pdcp_cdb(ses);
4178524b44eSHemant Agrawal 		break;
418314424b6SHemant Agrawal #endif
4198524b44eSHemant Agrawal 	case DPAA_SEC_CIPHER:
4200e5607e4SHemant Agrawal 		alginfo_c.key = (size_t)ses->cipher_key.data;
421c3e85bdcSAkhil Goyal 		alginfo_c.keylen = ses->cipher_key.length;
422c3e85bdcSAkhil Goyal 		alginfo_c.key_enc_flags = 0;
423c3e85bdcSAkhil Goyal 		alginfo_c.key_type = RTA_DATA_IMM;
4248524b44eSHemant Agrawal 		alginfo_c.algtype = ses->cipher_key.alg;
4258524b44eSHemant Agrawal 		alginfo_c.algmode = ses->cipher_key.algmode;
4268524b44eSHemant Agrawal 
427c5788a10SHemant Agrawal 		switch (ses->cipher_alg) {
428c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_AES_CBC:
429c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_3DES_CBC:
430c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_AES_CTR:
431c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_3DES_CTR:
432c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_blkcipher(
433c5788a10SHemant Agrawal 					cdb->sh_desc, true,
434c5788a10SHemant Agrawal 					swap, SHR_NEVER, &alginfo_c,
435c5788a10SHemant Agrawal 					ses->iv.length,
436c5788a10SHemant Agrawal 					ses->dir);
437c5788a10SHemant Agrawal 			break;
438c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
439c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_snow_f8(
440c5788a10SHemant Agrawal 					cdb->sh_desc, true, swap,
441c5788a10SHemant Agrawal 					&alginfo_c,
442c5788a10SHemant Agrawal 					ses->dir);
443c5788a10SHemant Agrawal 			break;
444c5788a10SHemant Agrawal 		case RTE_CRYPTO_CIPHER_ZUC_EEA3:
445c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_zuce(
446c5788a10SHemant Agrawal 					cdb->sh_desc, true, swap,
447c5788a10SHemant Agrawal 					&alginfo_c,
448c5788a10SHemant Agrawal 					ses->dir);
449c5788a10SHemant Agrawal 			break;
450c5788a10SHemant Agrawal 		default:
451c5788a10SHemant Agrawal 			DPAA_SEC_ERR("unsupported cipher alg %d",
452c5788a10SHemant Agrawal 				     ses->cipher_alg);
453c3e85bdcSAkhil Goyal 			return -ENOTSUP;
454c3e85bdcSAkhil Goyal 		}
4558524b44eSHemant Agrawal 		break;
4568524b44eSHemant Agrawal 	case DPAA_SEC_AUTH:
4570e5607e4SHemant Agrawal 		alginfo_a.key = (size_t)ses->auth_key.data;
458c3e85bdcSAkhil Goyal 		alginfo_a.keylen = ses->auth_key.length;
459c3e85bdcSAkhil Goyal 		alginfo_a.key_enc_flags = 0;
460c3e85bdcSAkhil Goyal 		alginfo_a.key_type = RTA_DATA_IMM;
4618524b44eSHemant Agrawal 		alginfo_a.algtype = ses->auth_key.alg;
4628524b44eSHemant Agrawal 		alginfo_a.algmode = ses->auth_key.algmode;
463c5788a10SHemant Agrawal 		switch (ses->auth_alg) {
464c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_MD5_HMAC:
465c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA1_HMAC:
466c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA224_HMAC:
467c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA256_HMAC:
468c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA384_HMAC:
469c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SHA512_HMAC:
470c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_hmac(
471c5788a10SHemant Agrawal 						cdb->sh_desc, true,
472c5788a10SHemant Agrawal 						swap, SHR_NEVER, &alginfo_a,
473c5788a10SHemant Agrawal 						!ses->dir,
474c5788a10SHemant Agrawal 						ses->digest_length);
475c5788a10SHemant Agrawal 			break;
476c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
477c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_snow_f9(
478c5788a10SHemant Agrawal 						cdb->sh_desc, true, swap,
479c5788a10SHemant Agrawal 						&alginfo_a,
480c5788a10SHemant Agrawal 						!ses->dir,
481c5788a10SHemant Agrawal 						ses->digest_length);
482c5788a10SHemant Agrawal 			break;
483c5788a10SHemant Agrawal 		case RTE_CRYPTO_AUTH_ZUC_EIA3:
484c5788a10SHemant Agrawal 			shared_desc_len = cnstr_shdsc_zuca(
485c5788a10SHemant Agrawal 						cdb->sh_desc, true, swap,
486c5788a10SHemant Agrawal 						&alginfo_a,
487c5788a10SHemant Agrawal 						!ses->dir,
488c5788a10SHemant Agrawal 						ses->digest_length);
489c5788a10SHemant Agrawal 			break;
490c5788a10SHemant Agrawal 		default:
491c5788a10SHemant Agrawal 			DPAA_SEC_ERR("unsupported auth alg %u", ses->auth_alg);
492c5788a10SHemant Agrawal 		}
4938524b44eSHemant Agrawal 		break;
4948524b44eSHemant Agrawal 	case DPAA_SEC_AEAD:
495c3e85bdcSAkhil Goyal 		if (alginfo.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
496f163231eSHemant Agrawal 			DPAA_SEC_ERR("not supported aead alg");
497c3e85bdcSAkhil Goyal 			return -ENOTSUP;
498c3e85bdcSAkhil Goyal 		}
4990e5607e4SHemant Agrawal 		alginfo.key = (size_t)ses->aead_key.data;
500c3e85bdcSAkhil Goyal 		alginfo.keylen = ses->aead_key.length;
501c3e85bdcSAkhil Goyal 		alginfo.key_enc_flags = 0;
502c3e85bdcSAkhil Goyal 		alginfo.key_type = RTA_DATA_IMM;
5038524b44eSHemant Agrawal 		alginfo.algtype = ses->aead_key.alg;
5048524b44eSHemant Agrawal 		alginfo.algmode = ses->aead_key.algmode;
505c3e85bdcSAkhil Goyal 
506c3e85bdcSAkhil Goyal 		if (ses->dir == DIR_ENC)
507c3e85bdcSAkhil Goyal 			shared_desc_len = cnstr_shdsc_gcm_encap(
5087449390bSAkhil Goyal 					cdb->sh_desc, true, swap, SHR_NEVER,
509c3e85bdcSAkhil Goyal 					&alginfo,
510c3e85bdcSAkhil Goyal 					ses->iv.length,
511c3e85bdcSAkhil Goyal 					ses->digest_length);
512c3e85bdcSAkhil Goyal 		else
513c3e85bdcSAkhil Goyal 			shared_desc_len = cnstr_shdsc_gcm_decap(
5147449390bSAkhil Goyal 					cdb->sh_desc, true, swap, SHR_NEVER,
515c3e85bdcSAkhil Goyal 					&alginfo,
516c3e85bdcSAkhil Goyal 					ses->iv.length,
517c3e85bdcSAkhil Goyal 					ses->digest_length);
5188524b44eSHemant Agrawal 		break;
5198524b44eSHemant Agrawal 	case DPAA_SEC_CIPHER_HASH:
5200e5607e4SHemant Agrawal 		alginfo_c.key = (size_t)ses->cipher_key.data;
521c3e85bdcSAkhil Goyal 		alginfo_c.keylen = ses->cipher_key.length;
522c3e85bdcSAkhil Goyal 		alginfo_c.key_enc_flags = 0;
523c3e85bdcSAkhil Goyal 		alginfo_c.key_type = RTA_DATA_IMM;
5248524b44eSHemant Agrawal 		alginfo_c.algtype = ses->cipher_key.alg;
5258524b44eSHemant Agrawal 		alginfo_c.algmode = ses->cipher_key.algmode;
526c3e85bdcSAkhil Goyal 
5270e5607e4SHemant Agrawal 		alginfo_a.key = (size_t)ses->auth_key.data;
528c3e85bdcSAkhil Goyal 		alginfo_a.keylen = ses->auth_key.length;
529c3e85bdcSAkhil Goyal 		alginfo_a.key_enc_flags = 0;
530c3e85bdcSAkhil Goyal 		alginfo_a.key_type = RTA_DATA_IMM;
5318524b44eSHemant Agrawal 		alginfo_a.algtype = ses->auth_key.alg;
5328524b44eSHemant Agrawal 		alginfo_a.algmode = ses->auth_key.algmode;
533c3e85bdcSAkhil Goyal 
534c3e85bdcSAkhil Goyal 		cdb->sh_desc[0] = alginfo_c.keylen;
535c3e85bdcSAkhil Goyal 		cdb->sh_desc[1] = alginfo_a.keylen;
536c3e85bdcSAkhil Goyal 		err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
537453b9593SAkhil Goyal 				       DESC_JOB_IO_LEN,
538c3e85bdcSAkhil Goyal 				       (unsigned int *)cdb->sh_desc,
539c3e85bdcSAkhil Goyal 				       &cdb->sh_desc[2], 2);
540c3e85bdcSAkhil Goyal 
541c3e85bdcSAkhil Goyal 		if (err < 0) {
542f163231eSHemant Agrawal 			DPAA_SEC_ERR("Crypto: Incorrect key lengths");
543c3e85bdcSAkhil Goyal 			return err;
544c3e85bdcSAkhil Goyal 		}
545c3e85bdcSAkhil Goyal 		if (cdb->sh_desc[2] & 1)
546c3e85bdcSAkhil Goyal 			alginfo_c.key_type = RTA_DATA_IMM;
547c3e85bdcSAkhil Goyal 		else {
548ec861560SGagandeep Singh 			alginfo_c.key = (size_t)rte_dpaa_mem_vtop(
5490e5607e4SHemant Agrawal 						(void *)(size_t)alginfo_c.key);
550c3e85bdcSAkhil Goyal 			alginfo_c.key_type = RTA_DATA_PTR;
551c3e85bdcSAkhil Goyal 		}
552c3e85bdcSAkhil Goyal 		if (cdb->sh_desc[2] & (1<<1))
553c3e85bdcSAkhil Goyal 			alginfo_a.key_type = RTA_DATA_IMM;
554c3e85bdcSAkhil Goyal 		else {
555ec861560SGagandeep Singh 			alginfo_a.key = (size_t)rte_dpaa_mem_vtop(
5560e5607e4SHemant Agrawal 						(void *)(size_t)alginfo_a.key);
557c3e85bdcSAkhil Goyal 			alginfo_a.key_type = RTA_DATA_PTR;
558c3e85bdcSAkhil Goyal 		}
559c3e85bdcSAkhil Goyal 		cdb->sh_desc[0] = 0;
560c3e85bdcSAkhil Goyal 		cdb->sh_desc[1] = 0;
561c3e85bdcSAkhil Goyal 		cdb->sh_desc[2] = 0;
5621f14d500SAkhil Goyal 		/* Auth_only_len is set as 0 here and it will be
5631f14d500SAkhil Goyal 		 * overwritten in fd for each packet.
564c3e85bdcSAkhil Goyal 		 */
565c3e85bdcSAkhil Goyal 		shared_desc_len = cnstr_shdsc_authenc(cdb->sh_desc,
5667449390bSAkhil Goyal 				true, swap, SHR_SERIAL, &alginfo_c, &alginfo_a,
5673394ed47SVakul Garg 				ses->iv.length,
568c3e85bdcSAkhil Goyal 				ses->digest_length, ses->dir);
5698524b44eSHemant Agrawal 		break;
5708524b44eSHemant Agrawal 	case DPAA_SEC_HASH_CIPHER:
5718524b44eSHemant Agrawal 	default:
5728524b44eSHemant Agrawal 		DPAA_SEC_ERR("error: Unsupported session");
5738524b44eSHemant Agrawal 		return -ENOTSUP;
574c3e85bdcSAkhil Goyal 	}
57522788c2cSSunil Kumar Kori 
57622788c2cSSunil Kumar Kori 	if (shared_desc_len < 0) {
577f163231eSHemant Agrawal 		DPAA_SEC_ERR("error in preparing command block");
57822788c2cSSunil Kumar Kori 		return shared_desc_len;
57922788c2cSSunil Kumar Kori 	}
58022788c2cSSunil Kumar Kori 
581c3e85bdcSAkhil Goyal 	cdb->sh_hdr.hi.field.idlen = shared_desc_len;
582c3e85bdcSAkhil Goyal 	cdb->sh_hdr.hi.word = rte_cpu_to_be_32(cdb->sh_hdr.hi.word);
583c3e85bdcSAkhil Goyal 	cdb->sh_hdr.lo.word = rte_cpu_to_be_32(cdb->sh_hdr.lo.word);
584c3e85bdcSAkhil Goyal 
585c3e85bdcSAkhil Goyal 	return 0;
586c3e85bdcSAkhil Goyal }
587c3e85bdcSAkhil Goyal 
588c3e85bdcSAkhil Goyal /* qp is lockless, should be accessed by only one thread */
589c3e85bdcSAkhil Goyal static int
590c3e85bdcSAkhil Goyal dpaa_sec_deq(struct dpaa_sec_qp *qp, struct rte_crypto_op **ops, int nb_ops)
591c3e85bdcSAkhil Goyal {
592c3e85bdcSAkhil Goyal 	struct qman_fq *fq;
5939a984458SAkhil Goyal 	unsigned int pkts = 0;
594f40d5a53SNipun Gupta 	int num_rx_bufs, ret;
5959a984458SAkhil Goyal 	struct qm_dqrr_entry *dq;
596f40d5a53SNipun Gupta 	uint32_t vdqcr_flags = 0;
597c3e85bdcSAkhil Goyal 
598c3e85bdcSAkhil Goyal 	fq = &qp->outq;
599f40d5a53SNipun Gupta 	/*
600f40d5a53SNipun Gupta 	 * Until request for four buffers, we provide exact number of buffers.
601f40d5a53SNipun Gupta 	 * Otherwise we do not set the QM_VDQCR_EXACT flag.
602f40d5a53SNipun Gupta 	 * Not setting QM_VDQCR_EXACT flag can provide two more buffers than
603f40d5a53SNipun Gupta 	 * requested, so we request two less in this case.
604f40d5a53SNipun Gupta 	 */
605f40d5a53SNipun Gupta 	if (nb_ops < 4) {
606f40d5a53SNipun Gupta 		vdqcr_flags = QM_VDQCR_EXACT;
607f40d5a53SNipun Gupta 		num_rx_bufs = nb_ops;
608f40d5a53SNipun Gupta 	} else {
609f40d5a53SNipun Gupta 		num_rx_bufs = nb_ops > DPAA_MAX_DEQUEUE_NUM_FRAMES ?
610f40d5a53SNipun Gupta 			(DPAA_MAX_DEQUEUE_NUM_FRAMES - 2) : (nb_ops - 2);
611f40d5a53SNipun Gupta 	}
612f40d5a53SNipun Gupta 	ret = qman_set_vdq(fq, num_rx_bufs, vdqcr_flags);
6139a984458SAkhil Goyal 	if (ret)
6149a984458SAkhil Goyal 		return 0;
615c3e85bdcSAkhil Goyal 
6169a984458SAkhil Goyal 	do {
6179a984458SAkhil Goyal 		const struct qm_fd *fd;
6189a984458SAkhil Goyal 		struct dpaa_sec_job *job;
6199a984458SAkhil Goyal 		struct dpaa_sec_op_ctx *ctx;
6209a984458SAkhil Goyal 		struct rte_crypto_op *op;
621c3e85bdcSAkhil Goyal 
6229a984458SAkhil Goyal 		dq = qman_dequeue(fq);
6239a984458SAkhil Goyal 		if (!dq)
6249a984458SAkhil Goyal 			continue;
6259a984458SAkhil Goyal 
6269a984458SAkhil Goyal 		fd = &dq->fd;
6279a984458SAkhil Goyal 		/* sg is embedded in an op ctx,
6289a984458SAkhil Goyal 		 * sg[0] is for output
6299a984458SAkhil Goyal 		 * sg[1] for input
6309a984458SAkhil Goyal 		 */
631ec861560SGagandeep Singh 		job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
6329a984458SAkhil Goyal 
6339a984458SAkhil Goyal 		ctx = container_of(job, struct dpaa_sec_op_ctx, job);
6349a984458SAkhil Goyal 		ctx->fd_status = fd->status;
6359a984458SAkhil Goyal 		op = ctx->op;
6369a984458SAkhil Goyal 		if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
6379a984458SAkhil Goyal 			struct qm_sg_entry *sg_out;
6389a984458SAkhil Goyal 			uint32_t len;
639fb5c100aSAkhil Goyal 			struct rte_mbuf *mbuf = (op->sym->m_dst == NULL) ?
640fb5c100aSAkhil Goyal 						op->sym->m_src : op->sym->m_dst;
6419a984458SAkhil Goyal 
6429a984458SAkhil Goyal 			sg_out = &job->sg[0];
6439a984458SAkhil Goyal 			hw_sg_to_cpu(sg_out);
6449a984458SAkhil Goyal 			len = sg_out->length;
645fb5c100aSAkhil Goyal 			mbuf->pkt_len = len;
646fb5c100aSAkhil Goyal 			while (mbuf->next != NULL) {
647fb5c100aSAkhil Goyal 				len -= mbuf->data_len;
648fb5c100aSAkhil Goyal 				mbuf = mbuf->next;
649fb5c100aSAkhil Goyal 			}
650fb5c100aSAkhil Goyal 			mbuf->data_len = len;
6519a984458SAkhil Goyal 		}
6529a984458SAkhil Goyal 		if (!ctx->fd_status) {
6539a984458SAkhil Goyal 			op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
6549a984458SAkhil Goyal 		} else {
655f163231eSHemant Agrawal 			DPAA_SEC_DP_WARN("SEC return err:0x%x", ctx->fd_status);
6569a984458SAkhil Goyal 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
6579a984458SAkhil Goyal 		}
6589a984458SAkhil Goyal 		ops[pkts++] = op;
6599a984458SAkhil Goyal 
6609a984458SAkhil Goyal 		/* report op status to sym->op and then free the ctx memeory */
6619a984458SAkhil Goyal 		rte_mempool_put(ctx->ctx_pool, (void *)ctx);
6629a984458SAkhil Goyal 
6639a984458SAkhil Goyal 		qman_dqrr_consume(fq, dq);
6649a984458SAkhil Goyal 	} while (fq->flags & QMAN_FQ_STATE_VDQCR);
6659a984458SAkhil Goyal 
6669a984458SAkhil Goyal 	return pkts;
667c3e85bdcSAkhil Goyal }
668c3e85bdcSAkhil Goyal 
669a74af788SAkhil Goyal static inline struct dpaa_sec_job *
670a74af788SAkhil Goyal build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
671a74af788SAkhil Goyal {
672a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
673a74af788SAkhil Goyal 	struct rte_mbuf *mbuf = sym->m_src;
674a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
675a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
676a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
677a74af788SAkhil Goyal 	phys_addr_t start_addr;
678a74af788SAkhil Goyal 	uint8_t *old_digest, extra_segs;
679c5788a10SHemant Agrawal 	int data_len, data_offset;
680c5788a10SHemant Agrawal 
681c5788a10SHemant Agrawal 	data_len = sym->auth.data.length;
682c5788a10SHemant Agrawal 	data_offset = sym->auth.data.offset;
683c5788a10SHemant Agrawal 
684c5788a10SHemant Agrawal 	if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
685c5788a10SHemant Agrawal 	    ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
686c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
687c5788a10SHemant Agrawal 			DPAA_SEC_ERR("AUTH: len/offset must be full bytes");
688c5788a10SHemant Agrawal 			return NULL;
689c5788a10SHemant Agrawal 		}
690c5788a10SHemant Agrawal 
691c5788a10SHemant Agrawal 		data_len = data_len >> 3;
692c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
693c5788a10SHemant Agrawal 	}
694a74af788SAkhil Goyal 
695a74af788SAkhil Goyal 	if (is_decode(ses))
696a74af788SAkhil Goyal 		extra_segs = 3;
697a74af788SAkhil Goyal 	else
698a74af788SAkhil Goyal 		extra_segs = 2;
699a74af788SAkhil Goyal 
700f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
701f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("Auth: Max sec segs supported is %d",
702a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
703a74af788SAkhil Goyal 		return NULL;
704a74af788SAkhil Goyal 	}
705f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, mbuf->nb_segs + extra_segs);
706a74af788SAkhil Goyal 	if (!ctx)
707a74af788SAkhil Goyal 		return NULL;
708a74af788SAkhil Goyal 
709a74af788SAkhil Goyal 	cf = &ctx->job;
710a74af788SAkhil Goyal 	ctx->op = op;
711a74af788SAkhil Goyal 	old_digest = ctx->digest;
712a74af788SAkhil Goyal 
713a74af788SAkhil Goyal 	/* output */
714a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
715a74af788SAkhil Goyal 	qm_sg_entry_set64(out_sg, sym->auth.digest.phys_addr);
716a74af788SAkhil Goyal 	out_sg->length = ses->digest_length;
717a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
718a74af788SAkhil Goyal 
719a74af788SAkhil Goyal 	/* input */
720a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
721a74af788SAkhil Goyal 	/* need to extend the input to a compound frame */
722a74af788SAkhil Goyal 	in_sg->extension = 1;
723a74af788SAkhil Goyal 	in_sg->final = 1;
724c5788a10SHemant Agrawal 	in_sg->length = data_len;
725ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
726a74af788SAkhil Goyal 
727a74af788SAkhil Goyal 	/* 1st seg */
728a74af788SAkhil Goyal 	sg = in_sg + 1;
729a74af788SAkhil Goyal 
730c5788a10SHemant Agrawal 	if (ses->iv.length) {
731c5788a10SHemant Agrawal 		uint8_t *iv_ptr;
732c5788a10SHemant Agrawal 
733c5788a10SHemant Agrawal 		iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
734c5788a10SHemant Agrawal 						   ses->iv.offset);
735c5788a10SHemant Agrawal 
736c5788a10SHemant Agrawal 		if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
737c5788a10SHemant Agrawal 			iv_ptr = conv_to_snow_f9_iv(iv_ptr);
738c5788a10SHemant Agrawal 			sg->length = 12;
739c5788a10SHemant Agrawal 		} else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
740c5788a10SHemant Agrawal 			iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
741c5788a10SHemant Agrawal 			sg->length = 8;
742c5788a10SHemant Agrawal 		} else {
743c5788a10SHemant Agrawal 			sg->length = ses->iv.length;
744c5788a10SHemant Agrawal 		}
745ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(iv_ptr));
746c5788a10SHemant Agrawal 		in_sg->length += sg->length;
747c5788a10SHemant Agrawal 		cpu_to_hw_sg(sg);
748c5788a10SHemant Agrawal 		sg++;
749c5788a10SHemant Agrawal 	}
750c5788a10SHemant Agrawal 
751c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
752c5788a10SHemant Agrawal 	sg->offset = data_offset;
753c5788a10SHemant Agrawal 
754c5788a10SHemant Agrawal 	if (data_len <= (mbuf->data_len - data_offset)) {
755c5788a10SHemant Agrawal 		sg->length = data_len;
756c5788a10SHemant Agrawal 	} else {
757c5788a10SHemant Agrawal 		sg->length = mbuf->data_len - data_offset;
758c5788a10SHemant Agrawal 
759c5788a10SHemant Agrawal 		/* remaining i/p segs */
760c5788a10SHemant Agrawal 		while ((data_len = data_len - sg->length) &&
761c5788a10SHemant Agrawal 		       (mbuf = mbuf->next)) {
762a74af788SAkhil Goyal 			cpu_to_hw_sg(sg);
763a74af788SAkhil Goyal 			sg++;
764a74af788SAkhil Goyal 			qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
765c5788a10SHemant Agrawal 			if (data_len > mbuf->data_len)
766a74af788SAkhil Goyal 				sg->length = mbuf->data_len;
767c5788a10SHemant Agrawal 			else
768c5788a10SHemant Agrawal 				sg->length = data_len;
769c5788a10SHemant Agrawal 		}
770a74af788SAkhil Goyal 	}
771a74af788SAkhil Goyal 
772a74af788SAkhil Goyal 	if (is_decode(ses)) {
773a74af788SAkhil Goyal 		/* Digest verification case */
774a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
775a74af788SAkhil Goyal 		sg++;
776a74af788SAkhil Goyal 		rte_memcpy(old_digest, sym->auth.digest.data,
777a74af788SAkhil Goyal 				ses->digest_length);
778ec861560SGagandeep Singh 		start_addr = rte_dpaa_mem_vtop(old_digest);
779a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, start_addr);
780a74af788SAkhil Goyal 		sg->length = ses->digest_length;
781a74af788SAkhil Goyal 		in_sg->length += ses->digest_length;
782a74af788SAkhil Goyal 	}
783a74af788SAkhil Goyal 	sg->final = 1;
784a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
785a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
786a74af788SAkhil Goyal 
787a74af788SAkhil Goyal 	return cf;
788a74af788SAkhil Goyal }
789a74af788SAkhil Goyal 
790c3e85bdcSAkhil Goyal /**
791c3e85bdcSAkhil Goyal  * packet looks like:
792c3e85bdcSAkhil Goyal  *		|<----data_len------->|
793c3e85bdcSAkhil Goyal  *    |ip_header|ah_header|icv|payload|
794c3e85bdcSAkhil Goyal  *              ^
795c3e85bdcSAkhil Goyal  *		|
796c3e85bdcSAkhil Goyal  *	   mbuf->pkt.data
797c3e85bdcSAkhil Goyal  */
798c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
799c3e85bdcSAkhil Goyal build_auth_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
800c3e85bdcSAkhil Goyal {
801c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
802c3e85bdcSAkhil Goyal 	struct rte_mbuf *mbuf = sym->m_src;
803c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
804c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
805c5788a10SHemant Agrawal 	struct qm_sg_entry *sg, *in_sg;
806c4509373SSantosh Shukla 	rte_iova_t start_addr;
807c3e85bdcSAkhil Goyal 	uint8_t *old_digest;
808c5788a10SHemant Agrawal 	int data_len, data_offset;
809c5788a10SHemant Agrawal 
810c5788a10SHemant Agrawal 	data_len = sym->auth.data.length;
811c5788a10SHemant Agrawal 	data_offset = sym->auth.data.offset;
812c5788a10SHemant Agrawal 
813c5788a10SHemant Agrawal 	if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
814c5788a10SHemant Agrawal 	    ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
815c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
816c5788a10SHemant Agrawal 			DPAA_SEC_ERR("AUTH: len/offset must be full bytes");
817c5788a10SHemant Agrawal 			return NULL;
818c5788a10SHemant Agrawal 		}
819c5788a10SHemant Agrawal 
820c5788a10SHemant Agrawal 		data_len = data_len >> 3;
821c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
822c5788a10SHemant Agrawal 	}
823c3e85bdcSAkhil Goyal 
824f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 4);
825c3e85bdcSAkhil Goyal 	if (!ctx)
826c3e85bdcSAkhil Goyal 		return NULL;
827c3e85bdcSAkhil Goyal 
828c3e85bdcSAkhil Goyal 	cf = &ctx->job;
829c3e85bdcSAkhil Goyal 	ctx->op = op;
830c3e85bdcSAkhil Goyal 	old_digest = ctx->digest;
831c3e85bdcSAkhil Goyal 
832bfa9a8a4SThomas Monjalon 	start_addr = rte_pktmbuf_iova(mbuf);
833c3e85bdcSAkhil Goyal 	/* output */
834c3e85bdcSAkhil Goyal 	sg = &cf->sg[0];
835c3e85bdcSAkhil Goyal 	qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
836c3e85bdcSAkhil Goyal 	sg->length = ses->digest_length;
837c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
838c3e85bdcSAkhil Goyal 
839c3e85bdcSAkhil Goyal 	/* input */
840c5788a10SHemant Agrawal 	in_sg = &cf->sg[1];
841c3e85bdcSAkhil Goyal 	/* need to extend the input to a compound frame */
842c5788a10SHemant Agrawal 	in_sg->extension = 1;
843c5788a10SHemant Agrawal 	in_sg->final = 1;
844c5788a10SHemant Agrawal 	in_sg->length = data_len;
845ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
846c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
847c5788a10SHemant Agrawal 
848c5788a10SHemant Agrawal 	if (ses->iv.length) {
849c5788a10SHemant Agrawal 		uint8_t *iv_ptr;
850c5788a10SHemant Agrawal 
851c5788a10SHemant Agrawal 		iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
852c5788a10SHemant Agrawal 						   ses->iv.offset);
853c5788a10SHemant Agrawal 
854c5788a10SHemant Agrawal 		if (ses->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
855c5788a10SHemant Agrawal 			iv_ptr = conv_to_snow_f9_iv(iv_ptr);
856c5788a10SHemant Agrawal 			sg->length = 12;
857c5788a10SHemant Agrawal 		} else if (ses->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
858c5788a10SHemant Agrawal 			iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
859c5788a10SHemant Agrawal 			sg->length = 8;
860c5788a10SHemant Agrawal 		} else {
861c5788a10SHemant Agrawal 			sg->length = ses->iv.length;
862c5788a10SHemant Agrawal 		}
863ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(iv_ptr));
864c5788a10SHemant Agrawal 		in_sg->length += sg->length;
865c5788a10SHemant Agrawal 		cpu_to_hw_sg(sg);
866c5788a10SHemant Agrawal 		sg++;
867c5788a10SHemant Agrawal 	}
868c5788a10SHemant Agrawal 
869c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
870c5788a10SHemant Agrawal 	sg->offset = data_offset;
871c5788a10SHemant Agrawal 	sg->length = data_len;
872c5788a10SHemant Agrawal 
873c5788a10SHemant Agrawal 	if (is_decode(ses)) {
874c5788a10SHemant Agrawal 		/* Digest verification case */
875c5788a10SHemant Agrawal 		cpu_to_hw_sg(sg);
876c3e85bdcSAkhil Goyal 		/* hash result or digest, save digest first */
877c3e85bdcSAkhil Goyal 		rte_memcpy(old_digest, sym->auth.digest.data,
878c3e85bdcSAkhil Goyal 				ses->digest_length);
879c3e85bdcSAkhil Goyal 		/* let's check digest by hw */
880ec861560SGagandeep Singh 		start_addr = rte_dpaa_mem_vtop(old_digest);
881c3e85bdcSAkhil Goyal 		sg++;
882c3e85bdcSAkhil Goyal 		qm_sg_entry_set64(sg, start_addr);
883c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
884c5788a10SHemant Agrawal 		in_sg->length += ses->digest_length;
885c3e85bdcSAkhil Goyal 	}
886c5788a10SHemant Agrawal 	sg->final = 1;
887c5788a10SHemant Agrawal 	cpu_to_hw_sg(sg);
888c5788a10SHemant Agrawal 	cpu_to_hw_sg(in_sg);
889c3e85bdcSAkhil Goyal 
890c3e85bdcSAkhil Goyal 	return cf;
891c3e85bdcSAkhil Goyal }
892c3e85bdcSAkhil Goyal 
893c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
894a74af788SAkhil Goyal build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
895a74af788SAkhil Goyal {
896a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
897a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
898a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
899a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
900a74af788SAkhil Goyal 	struct rte_mbuf *mbuf;
901a74af788SAkhil Goyal 	uint8_t req_segs;
902a74af788SAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
903a74af788SAkhil Goyal 			ses->iv.offset);
904c5788a10SHemant Agrawal 	int data_len, data_offset;
905c5788a10SHemant Agrawal 
906c5788a10SHemant Agrawal 	data_len = sym->cipher.data.length;
907c5788a10SHemant Agrawal 	data_offset = sym->cipher.data.offset;
908c5788a10SHemant Agrawal 
909c5788a10SHemant Agrawal 	if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
910c5788a10SHemant Agrawal 		ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
911c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
912c5788a10SHemant Agrawal 			DPAA_SEC_ERR("CIPHER: len/offset must be full bytes");
913c5788a10SHemant Agrawal 			return NULL;
914c5788a10SHemant Agrawal 		}
915c5788a10SHemant Agrawal 
916c5788a10SHemant Agrawal 		data_len = data_len >> 3;
917c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
918c5788a10SHemant Agrawal 	}
919a74af788SAkhil Goyal 
920a74af788SAkhil Goyal 	if (sym->m_dst) {
921a74af788SAkhil Goyal 		mbuf = sym->m_dst;
922a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 3;
923a74af788SAkhil Goyal 	} else {
924a74af788SAkhil Goyal 		mbuf = sym->m_src;
925a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs * 2 + 3;
926a74af788SAkhil Goyal 	}
927f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
928f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("Cipher: Max sec segs supported is %d",
929a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
930a74af788SAkhil Goyal 		return NULL;
931a74af788SAkhil Goyal 	}
932a74af788SAkhil Goyal 
933f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
934a74af788SAkhil Goyal 	if (!ctx)
935a74af788SAkhil Goyal 		return NULL;
936a74af788SAkhil Goyal 
937a74af788SAkhil Goyal 	cf = &ctx->job;
938a74af788SAkhil Goyal 	ctx->op = op;
939a74af788SAkhil Goyal 
940a74af788SAkhil Goyal 	/* output */
941a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
942a74af788SAkhil Goyal 	out_sg->extension = 1;
943c5788a10SHemant Agrawal 	out_sg->length = data_len;
944ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
945a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
946a74af788SAkhil Goyal 
947a74af788SAkhil Goyal 	/* 1st seg */
948a74af788SAkhil Goyal 	sg = &cf->sg[2];
949a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
950c5788a10SHemant Agrawal 	sg->length = mbuf->data_len - data_offset;
951c5788a10SHemant Agrawal 	sg->offset = data_offset;
952a74af788SAkhil Goyal 
953a74af788SAkhil Goyal 	/* Successive segs */
954a74af788SAkhil Goyal 	mbuf = mbuf->next;
955a74af788SAkhil Goyal 	while (mbuf) {
956a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
957a74af788SAkhil Goyal 		sg++;
958a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
959a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
960a74af788SAkhil Goyal 		mbuf = mbuf->next;
961a74af788SAkhil Goyal 	}
962a74af788SAkhil Goyal 	sg->final = 1;
963a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
964a74af788SAkhil Goyal 
965a74af788SAkhil Goyal 	/* input */
966a74af788SAkhil Goyal 	mbuf = sym->m_src;
967a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
968a74af788SAkhil Goyal 	in_sg->extension = 1;
969a74af788SAkhil Goyal 	in_sg->final = 1;
970c5788a10SHemant Agrawal 	in_sg->length = data_len + ses->iv.length;
971a74af788SAkhil Goyal 
972a74af788SAkhil Goyal 	sg++;
973ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
974a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
975a74af788SAkhil Goyal 
976a74af788SAkhil Goyal 	/* IV */
977ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
978a74af788SAkhil Goyal 	sg->length = ses->iv.length;
979a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
980a74af788SAkhil Goyal 
981a74af788SAkhil Goyal 	/* 1st seg */
982a74af788SAkhil Goyal 	sg++;
983a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
984c5788a10SHemant Agrawal 	sg->length = mbuf->data_len - data_offset;
985c5788a10SHemant Agrawal 	sg->offset = data_offset;
986a74af788SAkhil Goyal 
987a74af788SAkhil Goyal 	/* Successive segs */
988a74af788SAkhil Goyal 	mbuf = mbuf->next;
989a74af788SAkhil Goyal 	while (mbuf) {
990a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
991a74af788SAkhil Goyal 		sg++;
992a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
993a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
994a74af788SAkhil Goyal 		mbuf = mbuf->next;
995a74af788SAkhil Goyal 	}
996a74af788SAkhil Goyal 	sg->final = 1;
997a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
998a74af788SAkhil Goyal 
999a74af788SAkhil Goyal 	return cf;
1000a74af788SAkhil Goyal }
1001a74af788SAkhil Goyal 
1002a74af788SAkhil Goyal static inline struct dpaa_sec_job *
1003c3e85bdcSAkhil Goyal build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
1004c3e85bdcSAkhil Goyal {
1005c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1006c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1007c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1008c3e85bdcSAkhil Goyal 	struct qm_sg_entry *sg;
1009c4509373SSantosh Shukla 	rte_iova_t src_start_addr, dst_start_addr;
1010c3e85bdcSAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1011c3e85bdcSAkhil Goyal 			ses->iv.offset);
1012c5788a10SHemant Agrawal 	int data_len, data_offset;
1013c5788a10SHemant Agrawal 
1014c5788a10SHemant Agrawal 	data_len = sym->cipher.data.length;
1015c5788a10SHemant Agrawal 	data_offset = sym->cipher.data.offset;
1016c5788a10SHemant Agrawal 
1017c5788a10SHemant Agrawal 	if (ses->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1018c5788a10SHemant Agrawal 		ses->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1019c5788a10SHemant Agrawal 		if ((data_len & 7) || (data_offset & 7)) {
1020c5788a10SHemant Agrawal 			DPAA_SEC_ERR("CIPHER: len/offset must be full bytes");
1021c5788a10SHemant Agrawal 			return NULL;
1022c5788a10SHemant Agrawal 		}
1023c5788a10SHemant Agrawal 
1024c5788a10SHemant Agrawal 		data_len = data_len >> 3;
1025c5788a10SHemant Agrawal 		data_offset = data_offset >> 3;
1026c5788a10SHemant Agrawal 	}
1027c3e85bdcSAkhil Goyal 
1028f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 4);
1029c3e85bdcSAkhil Goyal 	if (!ctx)
1030c3e85bdcSAkhil Goyal 		return NULL;
1031c3e85bdcSAkhil Goyal 
1032c3e85bdcSAkhil Goyal 	cf = &ctx->job;
1033c3e85bdcSAkhil Goyal 	ctx->op = op;
1034a389434eSAlok Makhariya 
1035bfa9a8a4SThomas Monjalon 	src_start_addr = rte_pktmbuf_iova(sym->m_src);
1036a389434eSAlok Makhariya 
1037a389434eSAlok Makhariya 	if (sym->m_dst)
1038bfa9a8a4SThomas Monjalon 		dst_start_addr = rte_pktmbuf_iova(sym->m_dst);
1039a389434eSAlok Makhariya 	else
1040a389434eSAlok Makhariya 		dst_start_addr = src_start_addr;
1041c3e85bdcSAkhil Goyal 
1042c3e85bdcSAkhil Goyal 	/* output */
1043c3e85bdcSAkhil Goyal 	sg = &cf->sg[0];
1044c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, dst_start_addr + data_offset);
1045c5788a10SHemant Agrawal 	sg->length = data_len + ses->iv.length;
1046c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1047c3e85bdcSAkhil Goyal 
1048c3e85bdcSAkhil Goyal 	/* input */
1049c3e85bdcSAkhil Goyal 	sg = &cf->sg[1];
1050c3e85bdcSAkhil Goyal 
1051c3e85bdcSAkhil Goyal 	/* need to extend the input to a compound frame */
1052c3e85bdcSAkhil Goyal 	sg->extension = 1;
1053c3e85bdcSAkhil Goyal 	sg->final = 1;
1054c5788a10SHemant Agrawal 	sg->length = data_len + ses->iv.length;
1055ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(&cf->sg[2]));
1056c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1057c3e85bdcSAkhil Goyal 
1058c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
1059ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1060c3e85bdcSAkhil Goyal 	sg->length = ses->iv.length;
1061c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1062c3e85bdcSAkhil Goyal 
1063c3e85bdcSAkhil Goyal 	sg++;
1064c5788a10SHemant Agrawal 	qm_sg_entry_set64(sg, src_start_addr + data_offset);
1065c5788a10SHemant Agrawal 	sg->length = data_len;
1066c3e85bdcSAkhil Goyal 	sg->final = 1;
1067c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1068c3e85bdcSAkhil Goyal 
1069c3e85bdcSAkhil Goyal 	return cf;
1070c3e85bdcSAkhil Goyal }
1071c3e85bdcSAkhil Goyal 
1072c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
1073a74af788SAkhil Goyal build_cipher_auth_gcm_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1074a74af788SAkhil Goyal {
1075a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1076a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
1077a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1078a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
1079a74af788SAkhil Goyal 	struct rte_mbuf *mbuf;
1080a74af788SAkhil Goyal 	uint8_t req_segs;
1081a74af788SAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1082a74af788SAkhil Goyal 			ses->iv.offset);
1083a74af788SAkhil Goyal 
1084a74af788SAkhil Goyal 	if (sym->m_dst) {
1085a74af788SAkhil Goyal 		mbuf = sym->m_dst;
1086a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4;
1087a74af788SAkhil Goyal 	} else {
1088a74af788SAkhil Goyal 		mbuf = sym->m_src;
1089a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs * 2 + 4;
1090a74af788SAkhil Goyal 	}
1091a74af788SAkhil Goyal 
1092a74af788SAkhil Goyal 	if (ses->auth_only_len)
1093a74af788SAkhil Goyal 		req_segs++;
1094a74af788SAkhil Goyal 
1095f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
1096f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("AEAD: Max sec segs supported is %d",
1097a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
1098a74af788SAkhil Goyal 		return NULL;
1099a74af788SAkhil Goyal 	}
1100a74af788SAkhil Goyal 
1101f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
1102a74af788SAkhil Goyal 	if (!ctx)
1103a74af788SAkhil Goyal 		return NULL;
1104a74af788SAkhil Goyal 
1105a74af788SAkhil Goyal 	cf = &ctx->job;
1106a74af788SAkhil Goyal 	ctx->op = op;
1107a74af788SAkhil Goyal 
1108a74af788SAkhil Goyal 	rte_prefetch0(cf->sg);
1109a74af788SAkhil Goyal 
1110a74af788SAkhil Goyal 	/* output */
1111a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
1112a74af788SAkhil Goyal 	out_sg->extension = 1;
1113a74af788SAkhil Goyal 	if (is_encode(ses))
11147a4a6da4SVakul Garg 		out_sg->length = sym->aead.data.length + ses->digest_length;
1115a74af788SAkhil Goyal 	else
11167a4a6da4SVakul Garg 		out_sg->length = sym->aead.data.length;
1117a74af788SAkhil Goyal 
1118a74af788SAkhil Goyal 	/* output sg entries */
1119a74af788SAkhil Goyal 	sg = &cf->sg[2];
1120ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(sg));
1121a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
1122a74af788SAkhil Goyal 
1123a74af788SAkhil Goyal 	/* 1st seg */
1124a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
11257a4a6da4SVakul Garg 	sg->length = mbuf->data_len - sym->aead.data.offset;
11267a4a6da4SVakul Garg 	sg->offset = sym->aead.data.offset;
1127a74af788SAkhil Goyal 
1128a74af788SAkhil Goyal 	/* Successive segs */
1129a74af788SAkhil Goyal 	mbuf = mbuf->next;
1130a74af788SAkhil Goyal 	while (mbuf) {
1131a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1132a74af788SAkhil Goyal 		sg++;
1133a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1134a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1135a74af788SAkhil Goyal 		mbuf = mbuf->next;
1136a74af788SAkhil Goyal 	}
1137a74af788SAkhil Goyal 	sg->length -= ses->digest_length;
1138a74af788SAkhil Goyal 
1139a74af788SAkhil Goyal 	if (is_encode(ses)) {
1140a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1141a74af788SAkhil Goyal 		/* set auth output */
1142a74af788SAkhil Goyal 		sg++;
1143a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, sym->aead.digest.phys_addr);
1144a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1145a74af788SAkhil Goyal 	}
1146a74af788SAkhil Goyal 	sg->final = 1;
1147a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1148a74af788SAkhil Goyal 
1149a74af788SAkhil Goyal 	/* input */
1150a74af788SAkhil Goyal 	mbuf = sym->m_src;
1151a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
1152a74af788SAkhil Goyal 	in_sg->extension = 1;
1153a74af788SAkhil Goyal 	in_sg->final = 1;
1154a74af788SAkhil Goyal 	if (is_encode(ses))
1155a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->aead.data.length
1156a74af788SAkhil Goyal 							+ ses->auth_only_len;
1157a74af788SAkhil Goyal 	else
1158a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->aead.data.length
1159a74af788SAkhil Goyal 				+ ses->auth_only_len + ses->digest_length;
1160a74af788SAkhil Goyal 
1161a74af788SAkhil Goyal 	/* input sg entries */
1162a74af788SAkhil Goyal 	sg++;
1163ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
1164a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
1165a74af788SAkhil Goyal 
1166a74af788SAkhil Goyal 	/* 1st seg IV */
1167ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1168a74af788SAkhil Goyal 	sg->length = ses->iv.length;
1169a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1170a74af788SAkhil Goyal 
1171a74af788SAkhil Goyal 	/* 2nd seg auth only */
1172a74af788SAkhil Goyal 	if (ses->auth_only_len) {
1173a74af788SAkhil Goyal 		sg++;
1174ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(sym->aead.aad.data));
1175a74af788SAkhil Goyal 		sg->length = ses->auth_only_len;
1176a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1177a74af788SAkhil Goyal 	}
1178a74af788SAkhil Goyal 
1179a74af788SAkhil Goyal 	/* 3rd seg */
1180a74af788SAkhil Goyal 	sg++;
1181a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1182a74af788SAkhil Goyal 	sg->length = mbuf->data_len - sym->aead.data.offset;
1183a74af788SAkhil Goyal 	sg->offset = sym->aead.data.offset;
1184a74af788SAkhil Goyal 
1185a74af788SAkhil Goyal 	/* Successive segs */
1186a74af788SAkhil Goyal 	mbuf = mbuf->next;
1187a74af788SAkhil Goyal 	while (mbuf) {
1188a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1189a74af788SAkhil Goyal 		sg++;
1190a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1191a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1192a74af788SAkhil Goyal 		mbuf = mbuf->next;
1193a74af788SAkhil Goyal 	}
1194a74af788SAkhil Goyal 
1195a74af788SAkhil Goyal 	if (is_decode(ses)) {
1196a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1197a74af788SAkhil Goyal 		sg++;
1198a74af788SAkhil Goyal 		memcpy(ctx->digest, sym->aead.digest.data,
1199a74af788SAkhil Goyal 			ses->digest_length);
1200ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1201a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1202a74af788SAkhil Goyal 	}
1203a74af788SAkhil Goyal 	sg->final = 1;
1204a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1205a74af788SAkhil Goyal 
1206a74af788SAkhil Goyal 	return cf;
1207a74af788SAkhil Goyal }
1208a74af788SAkhil Goyal 
1209a74af788SAkhil Goyal static inline struct dpaa_sec_job *
1210c3e85bdcSAkhil Goyal build_cipher_auth_gcm(struct rte_crypto_op *op, dpaa_sec_session *ses)
1211c3e85bdcSAkhil Goyal {
1212c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1213c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1214c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1215c3e85bdcSAkhil Goyal 	struct qm_sg_entry *sg;
1216c3e85bdcSAkhil Goyal 	uint32_t length = 0;
1217c4509373SSantosh Shukla 	rte_iova_t src_start_addr, dst_start_addr;
1218c3e85bdcSAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1219c3e85bdcSAkhil Goyal 			ses->iv.offset);
1220c3e85bdcSAkhil Goyal 
1221116ff44aSHemant Agrawal 	src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off;
1222a389434eSAlok Makhariya 
1223a389434eSAlok Makhariya 	if (sym->m_dst)
1224116ff44aSHemant Agrawal 		dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off;
1225a389434eSAlok Makhariya 	else
1226a389434eSAlok Makhariya 		dst_start_addr = src_start_addr;
1227c3e85bdcSAkhil Goyal 
1228f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 7);
1229c3e85bdcSAkhil Goyal 	if (!ctx)
1230c3e85bdcSAkhil Goyal 		return NULL;
1231c3e85bdcSAkhil Goyal 
1232c3e85bdcSAkhil Goyal 	cf = &ctx->job;
1233c3e85bdcSAkhil Goyal 	ctx->op = op;
1234c3e85bdcSAkhil Goyal 
1235c3e85bdcSAkhil Goyal 	/* input */
1236c3e85bdcSAkhil Goyal 	rte_prefetch0(cf->sg);
1237c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
1238ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[1], rte_dpaa_mem_vtop(sg));
1239c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1240ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1241c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1242c3e85bdcSAkhil Goyal 		length += sg->length;
1243c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1244c3e85bdcSAkhil Goyal 
1245c3e85bdcSAkhil Goyal 		sg++;
1246c3e85bdcSAkhil Goyal 		if (ses->auth_only_len) {
1247c3e85bdcSAkhil Goyal 			qm_sg_entry_set64(sg,
1248ec861560SGagandeep Singh 					  rte_dpaa_mem_vtop(sym->aead.aad.data));
1249c3e85bdcSAkhil Goyal 			sg->length = ses->auth_only_len;
1250c3e85bdcSAkhil Goyal 			length += sg->length;
1251c3e85bdcSAkhil Goyal 			cpu_to_hw_sg(sg);
1252c3e85bdcSAkhil Goyal 			sg++;
1253c3e85bdcSAkhil Goyal 		}
1254a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset);
1255c3e85bdcSAkhil Goyal 		sg->length = sym->aead.data.length;
1256c3e85bdcSAkhil Goyal 		length += sg->length;
1257c3e85bdcSAkhil Goyal 		sg->final = 1;
1258c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1259c3e85bdcSAkhil Goyal 	} else {
1260ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1261c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1262c3e85bdcSAkhil Goyal 		length += sg->length;
1263c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1264c3e85bdcSAkhil Goyal 
1265c3e85bdcSAkhil Goyal 		sg++;
1266c3e85bdcSAkhil Goyal 		if (ses->auth_only_len) {
1267c3e85bdcSAkhil Goyal 			qm_sg_entry_set64(sg,
1268ec861560SGagandeep Singh 					  rte_dpaa_mem_vtop(sym->aead.aad.data));
1269c3e85bdcSAkhil Goyal 			sg->length = ses->auth_only_len;
1270c3e85bdcSAkhil Goyal 			length += sg->length;
1271c3e85bdcSAkhil Goyal 			cpu_to_hw_sg(sg);
1272c3e85bdcSAkhil Goyal 			sg++;
1273c3e85bdcSAkhil Goyal 		}
1274a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset);
1275c3e85bdcSAkhil Goyal 		sg->length = sym->aead.data.length;
1276c3e85bdcSAkhil Goyal 		length += sg->length;
1277c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1278c3e85bdcSAkhil Goyal 
1279c3e85bdcSAkhil Goyal 		memcpy(ctx->digest, sym->aead.digest.data,
1280c3e85bdcSAkhil Goyal 		       ses->digest_length);
1281c3e85bdcSAkhil Goyal 		sg++;
1282c3e85bdcSAkhil Goyal 
1283ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1284c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1285c3e85bdcSAkhil Goyal 		length += sg->length;
1286c3e85bdcSAkhil Goyal 		sg->final = 1;
1287c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1288c3e85bdcSAkhil Goyal 	}
1289c3e85bdcSAkhil Goyal 	/* input compound frame */
1290c3e85bdcSAkhil Goyal 	cf->sg[1].length = length;
1291c3e85bdcSAkhil Goyal 	cf->sg[1].extension = 1;
1292c3e85bdcSAkhil Goyal 	cf->sg[1].final = 1;
1293c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[1]);
1294c3e85bdcSAkhil Goyal 
1295c3e85bdcSAkhil Goyal 	/* output */
1296c3e85bdcSAkhil Goyal 	sg++;
1297ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[0], rte_dpaa_mem_vtop(sg));
1298c3e85bdcSAkhil Goyal 	qm_sg_entry_set64(sg,
12997a4a6da4SVakul Garg 		dst_start_addr + sym->aead.data.offset);
13007a4a6da4SVakul Garg 	sg->length = sym->aead.data.length;
1301c3e85bdcSAkhil Goyal 	length = sg->length;
1302c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1303c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1304c3e85bdcSAkhil Goyal 		/* set auth output */
1305c3e85bdcSAkhil Goyal 		sg++;
1306c3e85bdcSAkhil Goyal 		qm_sg_entry_set64(sg, sym->aead.digest.phys_addr);
1307c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1308c3e85bdcSAkhil Goyal 		length += sg->length;
1309c3e85bdcSAkhil Goyal 	}
1310c3e85bdcSAkhil Goyal 	sg->final = 1;
1311c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1312c3e85bdcSAkhil Goyal 
1313c3e85bdcSAkhil Goyal 	/* output compound frame */
1314c3e85bdcSAkhil Goyal 	cf->sg[0].length = length;
1315c3e85bdcSAkhil Goyal 	cf->sg[0].extension = 1;
1316c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[0]);
1317c3e85bdcSAkhil Goyal 
1318c3e85bdcSAkhil Goyal 	return cf;
1319c3e85bdcSAkhil Goyal }
1320c3e85bdcSAkhil Goyal 
1321c3e85bdcSAkhil Goyal static inline struct dpaa_sec_job *
1322a74af788SAkhil Goyal build_cipher_auth_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1323a74af788SAkhil Goyal {
1324a74af788SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1325a74af788SAkhil Goyal 	struct dpaa_sec_job *cf;
1326a74af788SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1327a74af788SAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
1328a74af788SAkhil Goyal 	struct rte_mbuf *mbuf;
1329a74af788SAkhil Goyal 	uint8_t req_segs;
1330a74af788SAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1331a74af788SAkhil Goyal 			ses->iv.offset);
1332a74af788SAkhil Goyal 
1333a74af788SAkhil Goyal 	if (sym->m_dst) {
1334a74af788SAkhil Goyal 		mbuf = sym->m_dst;
1335a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4;
1336a74af788SAkhil Goyal 	} else {
1337a74af788SAkhil Goyal 		mbuf = sym->m_src;
1338a74af788SAkhil Goyal 		req_segs = mbuf->nb_segs * 2 + 4;
1339a74af788SAkhil Goyal 	}
1340a74af788SAkhil Goyal 
1341f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
1342f163231eSHemant Agrawal 		DPAA_SEC_DP_ERR("Cipher-Auth: Max sec segs supported is %d",
1343a74af788SAkhil Goyal 				MAX_SG_ENTRIES);
1344a74af788SAkhil Goyal 		return NULL;
1345a74af788SAkhil Goyal 	}
1346a74af788SAkhil Goyal 
1347f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
1348a74af788SAkhil Goyal 	if (!ctx)
1349a74af788SAkhil Goyal 		return NULL;
1350a74af788SAkhil Goyal 
1351a74af788SAkhil Goyal 	cf = &ctx->job;
1352a74af788SAkhil Goyal 	ctx->op = op;
1353a74af788SAkhil Goyal 
1354a74af788SAkhil Goyal 	rte_prefetch0(cf->sg);
1355a74af788SAkhil Goyal 
1356a74af788SAkhil Goyal 	/* output */
1357a74af788SAkhil Goyal 	out_sg = &cf->sg[0];
1358a74af788SAkhil Goyal 	out_sg->extension = 1;
1359a74af788SAkhil Goyal 	if (is_encode(ses))
1360a74af788SAkhil Goyal 		out_sg->length = sym->auth.data.length + ses->digest_length;
1361a74af788SAkhil Goyal 	else
1362a74af788SAkhil Goyal 		out_sg->length = sym->auth.data.length;
1363a74af788SAkhil Goyal 
1364a74af788SAkhil Goyal 	/* output sg entries */
1365a74af788SAkhil Goyal 	sg = &cf->sg[2];
1366ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(sg));
1367a74af788SAkhil Goyal 	cpu_to_hw_sg(out_sg);
1368a74af788SAkhil Goyal 
1369a74af788SAkhil Goyal 	/* 1st seg */
1370a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1371a74af788SAkhil Goyal 	sg->length = mbuf->data_len - sym->auth.data.offset;
1372a74af788SAkhil Goyal 	sg->offset = sym->auth.data.offset;
1373a74af788SAkhil Goyal 
1374a74af788SAkhil Goyal 	/* Successive segs */
1375a74af788SAkhil Goyal 	mbuf = mbuf->next;
1376a74af788SAkhil Goyal 	while (mbuf) {
1377a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1378a74af788SAkhil Goyal 		sg++;
1379a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1380a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1381a74af788SAkhil Goyal 		mbuf = mbuf->next;
1382a74af788SAkhil Goyal 	}
1383a74af788SAkhil Goyal 	sg->length -= ses->digest_length;
1384a74af788SAkhil Goyal 
1385a74af788SAkhil Goyal 	if (is_encode(ses)) {
1386a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1387a74af788SAkhil Goyal 		/* set auth output */
1388a74af788SAkhil Goyal 		sg++;
1389a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
1390a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1391a74af788SAkhil Goyal 	}
1392a74af788SAkhil Goyal 	sg->final = 1;
1393a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1394a74af788SAkhil Goyal 
1395a74af788SAkhil Goyal 	/* input */
1396a74af788SAkhil Goyal 	mbuf = sym->m_src;
1397a74af788SAkhil Goyal 	in_sg = &cf->sg[1];
1398a74af788SAkhil Goyal 	in_sg->extension = 1;
1399a74af788SAkhil Goyal 	in_sg->final = 1;
1400a74af788SAkhil Goyal 	if (is_encode(ses))
1401a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->auth.data.length;
1402a74af788SAkhil Goyal 	else
1403a74af788SAkhil Goyal 		in_sg->length = ses->iv.length + sym->auth.data.length
1404a74af788SAkhil Goyal 						+ ses->digest_length;
1405a74af788SAkhil Goyal 
1406a74af788SAkhil Goyal 	/* input sg entries */
1407a74af788SAkhil Goyal 	sg++;
1408ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
1409a74af788SAkhil Goyal 	cpu_to_hw_sg(in_sg);
1410a74af788SAkhil Goyal 
1411a74af788SAkhil Goyal 	/* 1st seg IV */
1412ec861560SGagandeep Singh 	qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1413a74af788SAkhil Goyal 	sg->length = ses->iv.length;
1414a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1415a74af788SAkhil Goyal 
1416a74af788SAkhil Goyal 	/* 2nd seg */
1417a74af788SAkhil Goyal 	sg++;
1418a74af788SAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1419a74af788SAkhil Goyal 	sg->length = mbuf->data_len - sym->auth.data.offset;
1420a74af788SAkhil Goyal 	sg->offset = sym->auth.data.offset;
1421a74af788SAkhil Goyal 
1422a74af788SAkhil Goyal 	/* Successive segs */
1423a74af788SAkhil Goyal 	mbuf = mbuf->next;
1424a74af788SAkhil Goyal 	while (mbuf) {
1425a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1426a74af788SAkhil Goyal 		sg++;
1427a74af788SAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1428a74af788SAkhil Goyal 		sg->length = mbuf->data_len;
1429a74af788SAkhil Goyal 		mbuf = mbuf->next;
1430a74af788SAkhil Goyal 	}
1431a74af788SAkhil Goyal 
1432a74af788SAkhil Goyal 	sg->length -= ses->digest_length;
1433a74af788SAkhil Goyal 	if (is_decode(ses)) {
1434a74af788SAkhil Goyal 		cpu_to_hw_sg(sg);
1435a74af788SAkhil Goyal 		sg++;
1436a74af788SAkhil Goyal 		memcpy(ctx->digest, sym->auth.digest.data,
1437a74af788SAkhil Goyal 			ses->digest_length);
1438ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1439a74af788SAkhil Goyal 		sg->length = ses->digest_length;
1440a74af788SAkhil Goyal 	}
1441a74af788SAkhil Goyal 	sg->final = 1;
1442a74af788SAkhil Goyal 	cpu_to_hw_sg(sg);
1443a74af788SAkhil Goyal 
1444a74af788SAkhil Goyal 	return cf;
1445a74af788SAkhil Goyal }
1446a74af788SAkhil Goyal 
1447a74af788SAkhil Goyal static inline struct dpaa_sec_job *
1448c3e85bdcSAkhil Goyal build_cipher_auth(struct rte_crypto_op *op, dpaa_sec_session *ses)
1449c3e85bdcSAkhil Goyal {
1450c3e85bdcSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1451c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1452c3e85bdcSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1453c3e85bdcSAkhil Goyal 	struct qm_sg_entry *sg;
1454c4509373SSantosh Shukla 	rte_iova_t src_start_addr, dst_start_addr;
1455c3e85bdcSAkhil Goyal 	uint32_t length = 0;
1456c3e85bdcSAkhil Goyal 	uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1457c3e85bdcSAkhil Goyal 			ses->iv.offset);
1458c3e85bdcSAkhil Goyal 
1459455da545SSantosh Shukla 	src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off;
1460a389434eSAlok Makhariya 	if (sym->m_dst)
1461455da545SSantosh Shukla 		dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off;
1462a389434eSAlok Makhariya 	else
1463a389434eSAlok Makhariya 		dst_start_addr = src_start_addr;
1464c3e85bdcSAkhil Goyal 
1465f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 7);
1466c3e85bdcSAkhil Goyal 	if (!ctx)
1467c3e85bdcSAkhil Goyal 		return NULL;
1468c3e85bdcSAkhil Goyal 
1469c3e85bdcSAkhil Goyal 	cf = &ctx->job;
1470c3e85bdcSAkhil Goyal 	ctx->op = op;
1471c3e85bdcSAkhil Goyal 
1472c3e85bdcSAkhil Goyal 	/* input */
1473c3e85bdcSAkhil Goyal 	rte_prefetch0(cf->sg);
1474c3e85bdcSAkhil Goyal 	sg = &cf->sg[2];
1475ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[1], rte_dpaa_mem_vtop(sg));
1476c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1477ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1478c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1479c3e85bdcSAkhil Goyal 		length += sg->length;
1480c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1481c3e85bdcSAkhil Goyal 
1482c3e85bdcSAkhil Goyal 		sg++;
1483a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset);
1484c3e85bdcSAkhil Goyal 		sg->length = sym->auth.data.length;
1485c3e85bdcSAkhil Goyal 		length += sg->length;
1486c3e85bdcSAkhil Goyal 		sg->final = 1;
1487c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1488c3e85bdcSAkhil Goyal 	} else {
1489ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(IV_ptr));
1490c3e85bdcSAkhil Goyal 		sg->length = ses->iv.length;
1491c3e85bdcSAkhil Goyal 		length += sg->length;
1492c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1493c3e85bdcSAkhil Goyal 
1494c3e85bdcSAkhil Goyal 		sg++;
1495c3e85bdcSAkhil Goyal 
1496a389434eSAlok Makhariya 		qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset);
1497c3e85bdcSAkhil Goyal 		sg->length = sym->auth.data.length;
1498c3e85bdcSAkhil Goyal 		length += sg->length;
1499c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1500c3e85bdcSAkhil Goyal 
1501c3e85bdcSAkhil Goyal 		memcpy(ctx->digest, sym->auth.digest.data,
1502c3e85bdcSAkhil Goyal 		       ses->digest_length);
1503c3e85bdcSAkhil Goyal 		sg++;
1504c3e85bdcSAkhil Goyal 
1505ec861560SGagandeep Singh 		qm_sg_entry_set64(sg, rte_dpaa_mem_vtop(ctx->digest));
1506c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1507c3e85bdcSAkhil Goyal 		length += sg->length;
1508c3e85bdcSAkhil Goyal 		sg->final = 1;
1509c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1510c3e85bdcSAkhil Goyal 	}
1511c3e85bdcSAkhil Goyal 	/* input compound frame */
1512c3e85bdcSAkhil Goyal 	cf->sg[1].length = length;
1513c3e85bdcSAkhil Goyal 	cf->sg[1].extension = 1;
1514c3e85bdcSAkhil Goyal 	cf->sg[1].final = 1;
1515c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[1]);
1516c3e85bdcSAkhil Goyal 
1517c3e85bdcSAkhil Goyal 	/* output */
1518c3e85bdcSAkhil Goyal 	sg++;
1519ec861560SGagandeep Singh 	qm_sg_entry_set64(&cf->sg[0], rte_dpaa_mem_vtop(sg));
1520a389434eSAlok Makhariya 	qm_sg_entry_set64(sg, dst_start_addr + sym->cipher.data.offset);
1521c3e85bdcSAkhil Goyal 	sg->length = sym->cipher.data.length;
1522c3e85bdcSAkhil Goyal 	length = sg->length;
1523c3e85bdcSAkhil Goyal 	if (is_encode(ses)) {
1524c3e85bdcSAkhil Goyal 		cpu_to_hw_sg(sg);
1525c3e85bdcSAkhil Goyal 		/* set auth output */
1526c3e85bdcSAkhil Goyal 		sg++;
1527c3e85bdcSAkhil Goyal 		qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
1528c3e85bdcSAkhil Goyal 		sg->length = ses->digest_length;
1529c3e85bdcSAkhil Goyal 		length += sg->length;
1530c3e85bdcSAkhil Goyal 	}
1531c3e85bdcSAkhil Goyal 	sg->final = 1;
1532c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(sg);
1533c3e85bdcSAkhil Goyal 
1534c3e85bdcSAkhil Goyal 	/* output compound frame */
1535c3e85bdcSAkhil Goyal 	cf->sg[0].length = length;
1536c3e85bdcSAkhil Goyal 	cf->sg[0].extension = 1;
1537c3e85bdcSAkhil Goyal 	cpu_to_hw_sg(&cf->sg[0]);
1538c3e85bdcSAkhil Goyal 
1539c3e85bdcSAkhil Goyal 	return cf;
1540c3e85bdcSAkhil Goyal }
1541c3e85bdcSAkhil Goyal 
1542314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
15431f14d500SAkhil Goyal static inline struct dpaa_sec_job *
15441f14d500SAkhil Goyal build_proto(struct rte_crypto_op *op, dpaa_sec_session *ses)
15451f14d500SAkhil Goyal {
15461f14d500SAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
15471f14d500SAkhil Goyal 	struct dpaa_sec_job *cf;
15481f14d500SAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
15491f14d500SAkhil Goyal 	struct qm_sg_entry *sg;
15501f14d500SAkhil Goyal 	phys_addr_t src_start_addr, dst_start_addr;
15511f14d500SAkhil Goyal 
1552f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, 2);
15531f14d500SAkhil Goyal 	if (!ctx)
15541f14d500SAkhil Goyal 		return NULL;
15551f14d500SAkhil Goyal 	cf = &ctx->job;
15561f14d500SAkhil Goyal 	ctx->op = op;
15571f14d500SAkhil Goyal 
15581f14d500SAkhil Goyal 	src_start_addr = rte_pktmbuf_mtophys(sym->m_src);
15591f14d500SAkhil Goyal 
15601f14d500SAkhil Goyal 	if (sym->m_dst)
15611f14d500SAkhil Goyal 		dst_start_addr = rte_pktmbuf_mtophys(sym->m_dst);
15621f14d500SAkhil Goyal 	else
15631f14d500SAkhil Goyal 		dst_start_addr = src_start_addr;
15641f14d500SAkhil Goyal 
15651f14d500SAkhil Goyal 	/* input */
15661f14d500SAkhil Goyal 	sg = &cf->sg[1];
15671f14d500SAkhil Goyal 	qm_sg_entry_set64(sg, src_start_addr);
15681f14d500SAkhil Goyal 	sg->length = sym->m_src->pkt_len;
15691f14d500SAkhil Goyal 	sg->final = 1;
15701f14d500SAkhil Goyal 	cpu_to_hw_sg(sg);
15711f14d500SAkhil Goyal 
15721f14d500SAkhil Goyal 	sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK;
15731f14d500SAkhil Goyal 	/* output */
15741f14d500SAkhil Goyal 	sg = &cf->sg[0];
15751f14d500SAkhil Goyal 	qm_sg_entry_set64(sg, dst_start_addr);
15761f14d500SAkhil Goyal 	sg->length = sym->m_src->buf_len - sym->m_src->data_off;
15771f14d500SAkhil Goyal 	cpu_to_hw_sg(sg);
15781f14d500SAkhil Goyal 
15791f14d500SAkhil Goyal 	return cf;
15801f14d500SAkhil Goyal }
15811f14d500SAkhil Goyal 
1582fb5c100aSAkhil Goyal static inline struct dpaa_sec_job *
1583fb5c100aSAkhil Goyal build_proto_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1584fb5c100aSAkhil Goyal {
1585fb5c100aSAkhil Goyal 	struct rte_crypto_sym_op *sym = op->sym;
1586fb5c100aSAkhil Goyal 	struct dpaa_sec_job *cf;
1587fb5c100aSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
1588fb5c100aSAkhil Goyal 	struct qm_sg_entry *sg, *out_sg, *in_sg;
1589fb5c100aSAkhil Goyal 	struct rte_mbuf *mbuf;
1590fb5c100aSAkhil Goyal 	uint8_t req_segs;
1591fb5c100aSAkhil Goyal 	uint32_t in_len = 0, out_len = 0;
1592fb5c100aSAkhil Goyal 
1593fb5c100aSAkhil Goyal 	if (sym->m_dst)
1594fb5c100aSAkhil Goyal 		mbuf = sym->m_dst;
1595fb5c100aSAkhil Goyal 	else
1596fb5c100aSAkhil Goyal 		mbuf = sym->m_src;
1597fb5c100aSAkhil Goyal 
1598fb5c100aSAkhil Goyal 	req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 2;
1599f7a5752eSHemant Agrawal 	if (mbuf->nb_segs > MAX_SG_ENTRIES) {
1600fb5c100aSAkhil Goyal 		DPAA_SEC_DP_ERR("Proto: Max sec segs supported is %d",
1601fb5c100aSAkhil Goyal 				MAX_SG_ENTRIES);
1602fb5c100aSAkhil Goyal 		return NULL;
1603fb5c100aSAkhil Goyal 	}
1604fb5c100aSAkhil Goyal 
1605f7a5752eSHemant Agrawal 	ctx = dpaa_sec_alloc_ctx(ses, req_segs);
1606fb5c100aSAkhil Goyal 	if (!ctx)
1607fb5c100aSAkhil Goyal 		return NULL;
1608fb5c100aSAkhil Goyal 	cf = &ctx->job;
1609fb5c100aSAkhil Goyal 	ctx->op = op;
1610fb5c100aSAkhil Goyal 	/* output */
1611fb5c100aSAkhil Goyal 	out_sg = &cf->sg[0];
1612fb5c100aSAkhil Goyal 	out_sg->extension = 1;
1613ec861560SGagandeep Singh 	qm_sg_entry_set64(out_sg, rte_dpaa_mem_vtop(&cf->sg[2]));
1614fb5c100aSAkhil Goyal 
1615fb5c100aSAkhil Goyal 	/* 1st seg */
1616fb5c100aSAkhil Goyal 	sg = &cf->sg[2];
1617fb5c100aSAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1618fb5c100aSAkhil Goyal 	sg->offset = 0;
1619fb5c100aSAkhil Goyal 
1620fb5c100aSAkhil Goyal 	/* Successive segs */
1621fb5c100aSAkhil Goyal 	while (mbuf->next) {
1622fb5c100aSAkhil Goyal 		sg->length = mbuf->data_len;
1623fb5c100aSAkhil Goyal 		out_len += sg->length;
1624fb5c100aSAkhil Goyal 		mbuf = mbuf->next;
1625fb5c100aSAkhil Goyal 		cpu_to_hw_sg(sg);
1626fb5c100aSAkhil Goyal 		sg++;
1627fb5c100aSAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1628fb5c100aSAkhil Goyal 		sg->offset = 0;
1629fb5c100aSAkhil Goyal 	}
1630fb5c100aSAkhil Goyal 	sg->length = mbuf->buf_len - mbuf->data_off;
1631fb5c100aSAkhil Goyal 	out_len += sg->length;
1632fb5c100aSAkhil Goyal 	sg->final = 1;
1633fb5c100aSAkhil Goyal 	cpu_to_hw_sg(sg);
1634fb5c100aSAkhil Goyal 
1635fb5c100aSAkhil Goyal 	out_sg->length = out_len;
1636fb5c100aSAkhil Goyal 	cpu_to_hw_sg(out_sg);
1637fb5c100aSAkhil Goyal 
1638fb5c100aSAkhil Goyal 	/* input */
1639fb5c100aSAkhil Goyal 	mbuf = sym->m_src;
1640fb5c100aSAkhil Goyal 	in_sg = &cf->sg[1];
1641fb5c100aSAkhil Goyal 	in_sg->extension = 1;
1642fb5c100aSAkhil Goyal 	in_sg->final = 1;
1643fb5c100aSAkhil Goyal 	in_len = mbuf->data_len;
1644fb5c100aSAkhil Goyal 
1645fb5c100aSAkhil Goyal 	sg++;
1646ec861560SGagandeep Singh 	qm_sg_entry_set64(in_sg, rte_dpaa_mem_vtop(sg));
1647fb5c100aSAkhil Goyal 
1648fb5c100aSAkhil Goyal 	/* 1st seg */
1649fb5c100aSAkhil Goyal 	qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1650fb5c100aSAkhil Goyal 	sg->length = mbuf->data_len;
1651fb5c100aSAkhil Goyal 	sg->offset = 0;
1652fb5c100aSAkhil Goyal 
1653fb5c100aSAkhil Goyal 	/* Successive segs */
1654fb5c100aSAkhil Goyal 	mbuf = mbuf->next;
1655fb5c100aSAkhil Goyal 	while (mbuf) {
1656fb5c100aSAkhil Goyal 		cpu_to_hw_sg(sg);
1657fb5c100aSAkhil Goyal 		sg++;
1658fb5c100aSAkhil Goyal 		qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1659fb5c100aSAkhil Goyal 		sg->length = mbuf->data_len;
1660fb5c100aSAkhil Goyal 		sg->offset = 0;
1661fb5c100aSAkhil Goyal 		in_len += sg->length;
1662fb5c100aSAkhil Goyal 		mbuf = mbuf->next;
1663fb5c100aSAkhil Goyal 	}
1664fb5c100aSAkhil Goyal 	sg->final = 1;
1665fb5c100aSAkhil Goyal 	cpu_to_hw_sg(sg);
1666fb5c100aSAkhil Goyal 
1667fb5c100aSAkhil Goyal 	in_sg->length = in_len;
1668fb5c100aSAkhil Goyal 	cpu_to_hw_sg(in_sg);
1669fb5c100aSAkhil Goyal 
1670fb5c100aSAkhil Goyal 	sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK;
1671fb5c100aSAkhil Goyal 
1672fb5c100aSAkhil Goyal 	return cf;
1673fb5c100aSAkhil Goyal }
1674314424b6SHemant Agrawal #endif
1675fb5c100aSAkhil Goyal 
16769a984458SAkhil Goyal static uint16_t
16779a984458SAkhil Goyal dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
16789a984458SAkhil Goyal 		       uint16_t nb_ops)
1679c3e85bdcSAkhil Goyal {
16809a984458SAkhil Goyal 	/* Function to transmit the frames to given device and queuepair */
16819a984458SAkhil Goyal 	uint32_t loop;
16829a984458SAkhil Goyal 	struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp;
16839a984458SAkhil Goyal 	uint16_t num_tx = 0;
16849a984458SAkhil Goyal 	struct qm_fd fds[DPAA_SEC_BURST], *fd;
16859a984458SAkhil Goyal 	uint32_t frames_to_send;
16869a984458SAkhil Goyal 	struct rte_crypto_op *op;
1687c3e85bdcSAkhil Goyal 	struct dpaa_sec_job *cf;
1688c3e85bdcSAkhil Goyal 	dpaa_sec_session *ses;
16893394ed47SVakul Garg 	uint16_t auth_hdr_len, auth_tail_len;
16903394ed47SVakul Garg 	uint32_t index, flags[DPAA_SEC_BURST] = {0};
16919a984458SAkhil Goyal 	struct qman_fq *inq[DPAA_SEC_BURST];
1692c3e85bdcSAkhil Goyal 
16939a984458SAkhil Goyal 	while (nb_ops) {
16949a984458SAkhil Goyal 		frames_to_send = (nb_ops > DPAA_SEC_BURST) ?
16959a984458SAkhil Goyal 				DPAA_SEC_BURST : nb_ops;
16969a984458SAkhil Goyal 		for (loop = 0; loop < frames_to_send; loop++) {
16979a984458SAkhil Goyal 			op = *(ops++);
1698fe3688baSAkhil Goyal 			if (op->sym->m_src->seqn != 0) {
1699fe3688baSAkhil Goyal 				index = op->sym->m_src->seqn - 1;
1700fe3688baSAkhil Goyal 				if (DPAA_PER_LCORE_DQRR_HELD & (1 << index)) {
1701fe3688baSAkhil Goyal 					/* QM_EQCR_DCA_IDXMASK = 0x0f */
1702fe3688baSAkhil Goyal 					flags[loop] = ((index & 0x0f) << 8);
1703fe3688baSAkhil Goyal 					flags[loop] |= QMAN_ENQUEUE_FLAG_DCA;
1704fe3688baSAkhil Goyal 					DPAA_PER_LCORE_DQRR_SIZE--;
1705fe3688baSAkhil Goyal 					DPAA_PER_LCORE_DQRR_HELD &=
1706fe3688baSAkhil Goyal 								~(1 << index);
1707fe3688baSAkhil Goyal 				}
1708fe3688baSAkhil Goyal 			}
1709fe3688baSAkhil Goyal 
17109a984458SAkhil Goyal 			switch (op->sess_type) {
17119a984458SAkhil Goyal 			case RTE_CRYPTO_OP_WITH_SESSION:
17129a984458SAkhil Goyal 				ses = (dpaa_sec_session *)
1713012c5076SPablo de Lara 					get_sym_session_private_data(
17149a984458SAkhil Goyal 							op->sym->session,
17159a984458SAkhil Goyal 							cryptodev_driver_id);
17169a984458SAkhil Goyal 				break;
1717314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
17189a984458SAkhil Goyal 			case RTE_CRYPTO_OP_SECURITY_SESSION:
17199a984458SAkhil Goyal 				ses = (dpaa_sec_session *)
17209a984458SAkhil Goyal 					get_sec_session_private_data(
17211f14d500SAkhil Goyal 							op->sym->sec_session);
17229a984458SAkhil Goyal 				break;
1723314424b6SHemant Agrawal #endif
17249a984458SAkhil Goyal 			default:
1725f163231eSHemant Agrawal 				DPAA_SEC_DP_ERR(
17269a984458SAkhil Goyal 					"sessionless crypto op not supported");
17279a984458SAkhil Goyal 				frames_to_send = loop;
17289a984458SAkhil Goyal 				nb_ops = loop;
17299a984458SAkhil Goyal 				goto send_pkts;
17309a984458SAkhil Goyal 			}
1731e1e52232SHemant Agrawal 
1732e1e52232SHemant Agrawal 			if (!ses) {
1733e1e52232SHemant Agrawal 				DPAA_SEC_DP_ERR("session not available");
1734e1e52232SHemant Agrawal 				frames_to_send = loop;
1735e1e52232SHemant Agrawal 				nb_ops = loop;
1736e1e52232SHemant Agrawal 				goto send_pkts;
1737e1e52232SHemant Agrawal 			}
1738e1e52232SHemant Agrawal 
17394e694fe5SAkhil Goyal 			if (unlikely(!ses->qp[rte_lcore_id() % MAX_DPAA_CORES])) {
17409a984458SAkhil Goyal 				if (dpaa_sec_attach_sess_q(qp, ses)) {
17419a984458SAkhil Goyal 					frames_to_send = loop;
17429a984458SAkhil Goyal 					nb_ops = loop;
17439a984458SAkhil Goyal 					goto send_pkts;
17449a984458SAkhil Goyal 				}
17454e694fe5SAkhil Goyal 			} else if (unlikely(ses->qp[rte_lcore_id() %
17464e694fe5SAkhil Goyal 						MAX_DPAA_CORES] != qp)) {
17479198b2c2SAkhil Goyal 				DPAA_SEC_DP_ERR("Old:sess->qp = %p"
17484e694fe5SAkhil Goyal 					" New qp = %p\n",
17494e694fe5SAkhil Goyal 					ses->qp[rte_lcore_id() %
17504e694fe5SAkhil Goyal 					MAX_DPAA_CORES], qp);
17519198b2c2SAkhil Goyal 				frames_to_send = loop;
17529198b2c2SAkhil Goyal 				nb_ops = loop;
17539198b2c2SAkhil Goyal 				goto send_pkts;
1754c3e85bdcSAkhil Goyal 			}
1755c3e85bdcSAkhil Goyal 
17563394ed47SVakul Garg 			auth_hdr_len = op->sym->auth.data.length -
17579a984458SAkhil Goyal 						op->sym->cipher.data.length;
17583394ed47SVakul Garg 			auth_tail_len = 0;
17593394ed47SVakul Garg 
1760fb5c100aSAkhil Goyal 			if (rte_pktmbuf_is_contiguous(op->sym->m_src) &&
1761fb5c100aSAkhil Goyal 				  ((op->sym->m_dst == NULL) ||
1762fb5c100aSAkhil Goyal 				   rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
17638524b44eSHemant Agrawal 				switch (ses->ctxt) {
1764314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
17658524b44eSHemant Agrawal 				case DPAA_SEC_PDCP:
17668524b44eSHemant Agrawal 				case DPAA_SEC_IPSEC:
176705b12700SHemant Agrawal 					cf = build_proto(op, ses);
17688524b44eSHemant Agrawal 					break;
1769314424b6SHemant Agrawal #endif
17708524b44eSHemant Agrawal 				case DPAA_SEC_AUTH:
1771c3e85bdcSAkhil Goyal 					cf = build_auth_only(op, ses);
17728524b44eSHemant Agrawal 					break;
17738524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER:
1774c3e85bdcSAkhil Goyal 					cf = build_cipher_only(op, ses);
17758524b44eSHemant Agrawal 					break;
17768524b44eSHemant Agrawal 				case DPAA_SEC_AEAD:
1777c3e85bdcSAkhil Goyal 					cf = build_cipher_auth_gcm(op, ses);
17783394ed47SVakul Garg 					auth_hdr_len = ses->auth_only_len;
17798524b44eSHemant Agrawal 					break;
17808524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER_HASH:
17813394ed47SVakul Garg 					auth_hdr_len =
17823394ed47SVakul Garg 						op->sym->cipher.data.offset
17833394ed47SVakul Garg 						- op->sym->auth.data.offset;
17843394ed47SVakul Garg 					auth_tail_len =
17853394ed47SVakul Garg 						op->sym->auth.data.length
17863394ed47SVakul Garg 						- op->sym->cipher.data.length
17873394ed47SVakul Garg 						- auth_hdr_len;
1788c3e85bdcSAkhil Goyal 					cf = build_cipher_auth(op, ses);
17898524b44eSHemant Agrawal 					break;
17908524b44eSHemant Agrawal 				default:
1791f163231eSHemant Agrawal 					DPAA_SEC_DP_ERR("not supported ops");
17929a984458SAkhil Goyal 					frames_to_send = loop;
17939a984458SAkhil Goyal 					nb_ops = loop;
17949a984458SAkhil Goyal 					goto send_pkts;
1795c3e85bdcSAkhil Goyal 				}
1796a74af788SAkhil Goyal 			} else {
17978524b44eSHemant Agrawal 				switch (ses->ctxt) {
1798314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
17998524b44eSHemant Agrawal 				case DPAA_SEC_PDCP:
18008524b44eSHemant Agrawal 				case DPAA_SEC_IPSEC:
1801fb5c100aSAkhil Goyal 					cf = build_proto_sg(op, ses);
18028524b44eSHemant Agrawal 					break;
1803314424b6SHemant Agrawal #endif
18048524b44eSHemant Agrawal 				case DPAA_SEC_AUTH:
1805a74af788SAkhil Goyal 					cf = build_auth_only_sg(op, ses);
18068524b44eSHemant Agrawal 					break;
18078524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER:
1808a74af788SAkhil Goyal 					cf = build_cipher_only_sg(op, ses);
18098524b44eSHemant Agrawal 					break;
18108524b44eSHemant Agrawal 				case DPAA_SEC_AEAD:
1811a74af788SAkhil Goyal 					cf = build_cipher_auth_gcm_sg(op, ses);
18123394ed47SVakul Garg 					auth_hdr_len = ses->auth_only_len;
18138524b44eSHemant Agrawal 					break;
18148524b44eSHemant Agrawal 				case DPAA_SEC_CIPHER_HASH:
18153394ed47SVakul Garg 					auth_hdr_len =
18163394ed47SVakul Garg 						op->sym->cipher.data.offset
18173394ed47SVakul Garg 						- op->sym->auth.data.offset;
18183394ed47SVakul Garg 					auth_tail_len =
18193394ed47SVakul Garg 						op->sym->auth.data.length
18203394ed47SVakul Garg 						- op->sym->cipher.data.length
18213394ed47SVakul Garg 						- auth_hdr_len;
1822a74af788SAkhil Goyal 					cf = build_cipher_auth_sg(op, ses);
18238524b44eSHemant Agrawal 					break;
18248524b44eSHemant Agrawal 				default:
1825f163231eSHemant Agrawal 					DPAA_SEC_DP_ERR("not supported ops");
1826a74af788SAkhil Goyal 					frames_to_send = loop;
1827a74af788SAkhil Goyal 					nb_ops = loop;
1828a74af788SAkhil Goyal 					goto send_pkts;
1829a74af788SAkhil Goyal 				}
1830a74af788SAkhil Goyal 			}
18319a984458SAkhil Goyal 			if (unlikely(!cf)) {
18329a984458SAkhil Goyal 				frames_to_send = loop;
18339a984458SAkhil Goyal 				nb_ops = loop;
18349a984458SAkhil Goyal 				goto send_pkts;
18359a984458SAkhil Goyal 			}
1836c3e85bdcSAkhil Goyal 
18379a984458SAkhil Goyal 			fd = &fds[loop];
18384e694fe5SAkhil Goyal 			inq[loop] = ses->inq[rte_lcore_id() % MAX_DPAA_CORES];
18399a984458SAkhil Goyal 			fd->opaque_addr = 0;
18409a984458SAkhil Goyal 			fd->cmd = 0;
1841ec861560SGagandeep Singh 			qm_fd_addr_set64(fd, rte_dpaa_mem_vtop(cf->sg));
18429a984458SAkhil Goyal 			fd->_format1 = qm_fd_compound;
18439a984458SAkhil Goyal 			fd->length29 = 2 * sizeof(struct qm_sg_entry);
18443394ed47SVakul Garg 
18459a984458SAkhil Goyal 			/* Auth_only_len is set as 0 in descriptor and it is
18469a984458SAkhil Goyal 			 * overwritten here in the fd.cmd which will update
18479a984458SAkhil Goyal 			 * the DPOVRD reg.
1848c3e85bdcSAkhil Goyal 			 */
18493394ed47SVakul Garg 			if (auth_hdr_len || auth_tail_len) {
18503394ed47SVakul Garg 				fd->cmd = 0x80000000;
18513394ed47SVakul Garg 				fd->cmd |=
18523394ed47SVakul Garg 					((auth_tail_len << 16) | auth_hdr_len);
18533394ed47SVakul Garg 			}
1854c3e85bdcSAkhil Goyal 
1855314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
18566a0c9d36SAkhil Goyal 			/* In case of PDCP, per packet HFN is stored in
18576a0c9d36SAkhil Goyal 			 * mbuf priv after sym_op.
18586a0c9d36SAkhil Goyal 			 */
18598524b44eSHemant Agrawal 			if ((ses->ctxt == DPAA_SEC_PDCP) && ses->pdcp.hfn_ovd) {
18606a0c9d36SAkhil Goyal 				fd->cmd = 0x80000000 |
18616a0c9d36SAkhil Goyal 					*((uint32_t *)((uint8_t *)op +
18626a0c9d36SAkhil Goyal 					ses->pdcp.hfn_ovd_offset));
18638524b44eSHemant Agrawal 				DPAA_SEC_DP_DEBUG("Per packet HFN: %x, ovd:%u\n",
18646a0c9d36SAkhil Goyal 					*((uint32_t *)((uint8_t *)op +
18656a0c9d36SAkhil Goyal 					ses->pdcp.hfn_ovd_offset)),
18668524b44eSHemant Agrawal 					ses->pdcp.hfn_ovd);
18676a0c9d36SAkhil Goyal 			}
1868314424b6SHemant Agrawal #endif
18699a984458SAkhil Goyal 		}
18709a984458SAkhil Goyal send_pkts:
18719a984458SAkhil Goyal 		loop = 0;
18729a984458SAkhil Goyal 		while (loop < frames_to_send) {
18739a984458SAkhil Goyal 			loop += qman_enqueue_multi_fq(&inq[loop], &fds[loop],
1874fe3688baSAkhil Goyal 					&flags[loop], frames_to_send - loop);
18759a984458SAkhil Goyal 		}
18769a984458SAkhil Goyal 		nb_ops -= frames_to_send;
18779a984458SAkhil Goyal 		num_tx += frames_to_send;
1878c3e85bdcSAkhil Goyal 	}
1879c3e85bdcSAkhil Goyal 
1880c3e85bdcSAkhil Goyal 	dpaa_qp->tx_pkts += num_tx;
1881c3e85bdcSAkhil Goyal 	dpaa_qp->tx_errs += nb_ops - num_tx;
1882c3e85bdcSAkhil Goyal 
1883c3e85bdcSAkhil Goyal 	return num_tx;
1884c3e85bdcSAkhil Goyal }
1885c3e85bdcSAkhil Goyal 
1886c3e85bdcSAkhil Goyal static uint16_t
1887c3e85bdcSAkhil Goyal dpaa_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1888c3e85bdcSAkhil Goyal 		       uint16_t nb_ops)
1889c3e85bdcSAkhil Goyal {
1890c3e85bdcSAkhil Goyal 	uint16_t num_rx;
1891c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp;
1892c3e85bdcSAkhil Goyal 
1893c3e85bdcSAkhil Goyal 	num_rx = dpaa_sec_deq(dpaa_qp, ops, nb_ops);
1894c3e85bdcSAkhil Goyal 
1895c3e85bdcSAkhil Goyal 	dpaa_qp->rx_pkts += num_rx;
1896c3e85bdcSAkhil Goyal 	dpaa_qp->rx_errs += nb_ops - num_rx;
1897c3e85bdcSAkhil Goyal 
1898f163231eSHemant Agrawal 	DPAA_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1899c3e85bdcSAkhil Goyal 
1900c3e85bdcSAkhil Goyal 	return num_rx;
1901c3e85bdcSAkhil Goyal }
1902c3e85bdcSAkhil Goyal 
1903c3e85bdcSAkhil Goyal /** Release queue pair */
1904c3e85bdcSAkhil Goyal static int
1905c3e85bdcSAkhil Goyal dpaa_sec_queue_pair_release(struct rte_cryptodev *dev,
1906c3e85bdcSAkhil Goyal 			    uint16_t qp_id)
1907c3e85bdcSAkhil Goyal {
1908c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals;
1909c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *qp = NULL;
1910c3e85bdcSAkhil Goyal 
1911c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
1912c3e85bdcSAkhil Goyal 
1913f163231eSHemant Agrawal 	DPAA_SEC_DEBUG("dev =%p, queue =%d", dev, qp_id);
1914c3e85bdcSAkhil Goyal 
1915c3e85bdcSAkhil Goyal 	internals = dev->data->dev_private;
1916c3e85bdcSAkhil Goyal 	if (qp_id >= internals->max_nb_queue_pairs) {
1917f163231eSHemant Agrawal 		DPAA_SEC_ERR("Max supported qpid %d",
1918c3e85bdcSAkhil Goyal 			     internals->max_nb_queue_pairs);
1919c3e85bdcSAkhil Goyal 		return -EINVAL;
1920c3e85bdcSAkhil Goyal 	}
1921c3e85bdcSAkhil Goyal 
1922c3e85bdcSAkhil Goyal 	qp = &internals->qps[qp_id];
19232ffb940eSAkhil Goyal 	rte_mempool_free(qp->ctx_pool);
1924c3e85bdcSAkhil Goyal 	qp->internals = NULL;
1925c3e85bdcSAkhil Goyal 	dev->data->queue_pairs[qp_id] = NULL;
1926c3e85bdcSAkhil Goyal 
1927c3e85bdcSAkhil Goyal 	return 0;
1928c3e85bdcSAkhil Goyal }
1929c3e85bdcSAkhil Goyal 
1930c3e85bdcSAkhil Goyal /** Setup a queue pair */
1931c3e85bdcSAkhil Goyal static int
1932c3e85bdcSAkhil Goyal dpaa_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1933c3e85bdcSAkhil Goyal 		__rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1934725d2a7fSFan Zhang 		__rte_unused int socket_id)
1935c3e85bdcSAkhil Goyal {
1936c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals;
1937c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *qp = NULL;
19382ffb940eSAkhil Goyal 	char str[20];
1939c3e85bdcSAkhil Goyal 
1940f163231eSHemant Agrawal 	DPAA_SEC_DEBUG("dev =%p, queue =%d, conf =%p", dev, qp_id, qp_conf);
1941c3e85bdcSAkhil Goyal 
1942c3e85bdcSAkhil Goyal 	internals = dev->data->dev_private;
1943c3e85bdcSAkhil Goyal 	if (qp_id >= internals->max_nb_queue_pairs) {
1944f163231eSHemant Agrawal 		DPAA_SEC_ERR("Max supported qpid %d",
1945c3e85bdcSAkhil Goyal 			     internals->max_nb_queue_pairs);
1946c3e85bdcSAkhil Goyal 		return -EINVAL;
1947c3e85bdcSAkhil Goyal 	}
1948c3e85bdcSAkhil Goyal 
1949c3e85bdcSAkhil Goyal 	qp = &internals->qps[qp_id];
1950c3e85bdcSAkhil Goyal 	qp->internals = internals;
19512ffb940eSAkhil Goyal 	snprintf(str, sizeof(str), "ctx_pool_d%d_qp%d",
19522ffb940eSAkhil Goyal 			dev->data->dev_id, qp_id);
19532ffb940eSAkhil Goyal 	if (!qp->ctx_pool) {
19542ffb940eSAkhil Goyal 		qp->ctx_pool = rte_mempool_create((const char *)str,
19552ffb940eSAkhil Goyal 							CTX_POOL_NUM_BUFS,
19562ffb940eSAkhil Goyal 							CTX_POOL_BUF_SIZE,
19572ffb940eSAkhil Goyal 							CTX_POOL_CACHE_SIZE, 0,
19582ffb940eSAkhil Goyal 							NULL, NULL, NULL, NULL,
19592ffb940eSAkhil Goyal 							SOCKET_ID_ANY, 0);
19602ffb940eSAkhil Goyal 		if (!qp->ctx_pool) {
19612ffb940eSAkhil Goyal 			DPAA_SEC_ERR("%s create failed\n", str);
19622ffb940eSAkhil Goyal 			return -ENOMEM;
19632ffb940eSAkhil Goyal 		}
19642ffb940eSAkhil Goyal 	} else
19652ffb940eSAkhil Goyal 		DPAA_SEC_INFO("mempool already created for dev_id : %d, qp: %d",
19662ffb940eSAkhil Goyal 				dev->data->dev_id, qp_id);
1967c3e85bdcSAkhil Goyal 	dev->data->queue_pairs[qp_id] = qp;
1968c3e85bdcSAkhil Goyal 
1969c3e85bdcSAkhil Goyal 	return 0;
1970c3e85bdcSAkhil Goyal }
1971c3e85bdcSAkhil Goyal 
1972c3e85bdcSAkhil Goyal /** Returns the size of session structure */
1973c3e85bdcSAkhil Goyal static unsigned int
1974012c5076SPablo de Lara dpaa_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1975c3e85bdcSAkhil Goyal {
1976c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
1977c3e85bdcSAkhil Goyal 
1978c3e85bdcSAkhil Goyal 	return sizeof(dpaa_sec_session);
1979c3e85bdcSAkhil Goyal }
1980c3e85bdcSAkhil Goyal 
1981c3e85bdcSAkhil Goyal static int
1982c3e85bdcSAkhil Goyal dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
1983c3e85bdcSAkhil Goyal 		     struct rte_crypto_sym_xform *xform,
1984c3e85bdcSAkhil Goyal 		     dpaa_sec_session *session)
1985c3e85bdcSAkhil Goyal {
1986f73d6928SHemant Agrawal 	session->ctxt = DPAA_SEC_CIPHER;
1987c3e85bdcSAkhil Goyal 	session->cipher_alg = xform->cipher.algo;
1988c3e85bdcSAkhil Goyal 	session->iv.length = xform->cipher.iv.length;
1989c3e85bdcSAkhil Goyal 	session->iv.offset = xform->cipher.iv.offset;
1990c3e85bdcSAkhil Goyal 	session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1991c3e85bdcSAkhil Goyal 					       RTE_CACHE_LINE_SIZE);
1992c3e85bdcSAkhil Goyal 	if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
1993f163231eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for cipher key");
1994c3e85bdcSAkhil Goyal 		return -ENOMEM;
1995c3e85bdcSAkhil Goyal 	}
1996c3e85bdcSAkhil Goyal 	session->cipher_key.length = xform->cipher.key.length;
1997c3e85bdcSAkhil Goyal 
1998c3e85bdcSAkhil Goyal 	memcpy(session->cipher_key.data, xform->cipher.key.data,
1999c3e85bdcSAkhil Goyal 	       xform->cipher.key.length);
20008524b44eSHemant Agrawal 	switch (xform->cipher.algo) {
20018524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CBC:
20028524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
20038524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
20048524b44eSHemant Agrawal 		break;
20058524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_CBC:
20068524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_3DES;
20078524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
20088524b44eSHemant Agrawal 		break;
20098524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CTR:
20108524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
20118524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CTR;
20128524b44eSHemant Agrawal 		break;
20138524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
20148524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_SNOW_F8;
20158524b44eSHemant Agrawal 		break;
20168524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_ZUC_EEA3:
20178524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_ZUCE;
20188524b44eSHemant Agrawal 		break;
20198524b44eSHemant Agrawal 	default:
20208524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
20218524b44eSHemant Agrawal 			      xform->cipher.algo);
2022c08ced9aSAkhil Goyal 		return -ENOTSUP;
20238524b44eSHemant Agrawal 	}
2024c3e85bdcSAkhil Goyal 	session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2025c3e85bdcSAkhil Goyal 			DIR_ENC : DIR_DEC;
2026c3e85bdcSAkhil Goyal 
2027c3e85bdcSAkhil Goyal 	return 0;
2028c3e85bdcSAkhil Goyal }
2029c3e85bdcSAkhil Goyal 
2030c3e85bdcSAkhil Goyal static int
2031c3e85bdcSAkhil Goyal dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
2032c3e85bdcSAkhil Goyal 		   struct rte_crypto_sym_xform *xform,
2033c3e85bdcSAkhil Goyal 		   dpaa_sec_session *session)
2034c3e85bdcSAkhil Goyal {
2035f73d6928SHemant Agrawal 	session->ctxt = DPAA_SEC_AUTH;
2036c3e85bdcSAkhil Goyal 	session->auth_alg = xform->auth.algo;
2037c3e85bdcSAkhil Goyal 	session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
2038c3e85bdcSAkhil Goyal 					     RTE_CACHE_LINE_SIZE);
2039c3e85bdcSAkhil Goyal 	if (session->auth_key.data == NULL && xform->auth.key.length > 0) {
2040f163231eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for auth key");
2041c3e85bdcSAkhil Goyal 		return -ENOMEM;
2042c3e85bdcSAkhil Goyal 	}
2043c3e85bdcSAkhil Goyal 	session->auth_key.length = xform->auth.key.length;
2044c3e85bdcSAkhil Goyal 	session->digest_length = xform->auth.digest_length;
2045c5788a10SHemant Agrawal 	if (session->cipher_alg == RTE_CRYPTO_CIPHER_NULL) {
2046c5788a10SHemant Agrawal 		session->iv.offset = xform->auth.iv.offset;
2047c5788a10SHemant Agrawal 		session->iv.length = xform->auth.iv.length;
2048c5788a10SHemant Agrawal 	}
2049c3e85bdcSAkhil Goyal 
2050c3e85bdcSAkhil Goyal 	memcpy(session->auth_key.data, xform->auth.key.data,
2051c3e85bdcSAkhil Goyal 	       xform->auth.key.length);
20528524b44eSHemant Agrawal 
20538524b44eSHemant Agrawal 	switch (xform->auth.algo) {
20548524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1_HMAC:
20558524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA1;
20568524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20578524b44eSHemant Agrawal 		break;
20588524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5_HMAC:
20598524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_MD5;
20608524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20618524b44eSHemant Agrawal 		break;
20628524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224_HMAC:
20638524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA224;
20648524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20658524b44eSHemant Agrawal 		break;
20668524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA256_HMAC:
20678524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA256;
20688524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20698524b44eSHemant Agrawal 		break;
20708524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA384_HMAC:
20718524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA384;
20728524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20738524b44eSHemant Agrawal 		break;
20748524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA512_HMAC:
20758524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA512;
20768524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
20778524b44eSHemant Agrawal 		break;
20788524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
20798524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SNOW_F9;
20808524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_F9;
20818524b44eSHemant Agrawal 		break;
20828524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
20838524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_ZUCA;
20848524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_F9;
20858524b44eSHemant Agrawal 		break;
20868524b44eSHemant Agrawal 	default:
20878524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
20888524b44eSHemant Agrawal 			      xform->auth.algo);
2089c08ced9aSAkhil Goyal 		return -ENOTSUP;
20908524b44eSHemant Agrawal 	}
20918524b44eSHemant Agrawal 
2092c3e85bdcSAkhil Goyal 	session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2093c3e85bdcSAkhil Goyal 			DIR_ENC : DIR_DEC;
2094c3e85bdcSAkhil Goyal 
2095c3e85bdcSAkhil Goyal 	return 0;
2096c3e85bdcSAkhil Goyal }
2097c3e85bdcSAkhil Goyal 
2098c3e85bdcSAkhil Goyal static int
20998524b44eSHemant Agrawal dpaa_sec_chain_init(struct rte_cryptodev *dev __rte_unused,
21008524b44eSHemant Agrawal 		   struct rte_crypto_sym_xform *xform,
21018524b44eSHemant Agrawal 		   dpaa_sec_session *session)
21028524b44eSHemant Agrawal {
21038524b44eSHemant Agrawal 
21048524b44eSHemant Agrawal 	struct rte_crypto_cipher_xform *cipher_xform;
21058524b44eSHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform;
21068524b44eSHemant Agrawal 
2107f73d6928SHemant Agrawal 	session->ctxt = DPAA_SEC_CIPHER_HASH;
21088524b44eSHemant Agrawal 	if (session->auth_cipher_text) {
21098524b44eSHemant Agrawal 		cipher_xform = &xform->cipher;
21108524b44eSHemant Agrawal 		auth_xform = &xform->next->auth;
21118524b44eSHemant Agrawal 	} else {
21128524b44eSHemant Agrawal 		cipher_xform = &xform->next->cipher;
21138524b44eSHemant Agrawal 		auth_xform = &xform->auth;
21148524b44eSHemant Agrawal 	}
21158524b44eSHemant Agrawal 
21168524b44eSHemant Agrawal 	/* Set IV parameters */
21178524b44eSHemant Agrawal 	session->iv.offset = cipher_xform->iv.offset;
21188524b44eSHemant Agrawal 	session->iv.length = cipher_xform->iv.length;
21198524b44eSHemant Agrawal 
21208524b44eSHemant Agrawal 	session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
21218524b44eSHemant Agrawal 					       RTE_CACHE_LINE_SIZE);
21228524b44eSHemant Agrawal 	if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
21238524b44eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for cipher key");
2124c08ced9aSAkhil Goyal 		return -ENOMEM;
21258524b44eSHemant Agrawal 	}
21268524b44eSHemant Agrawal 	session->cipher_key.length = cipher_xform->key.length;
21278524b44eSHemant Agrawal 	session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
21288524b44eSHemant Agrawal 					     RTE_CACHE_LINE_SIZE);
21298524b44eSHemant Agrawal 	if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
21308524b44eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for auth key");
21318524b44eSHemant Agrawal 		return -ENOMEM;
21328524b44eSHemant Agrawal 	}
21338524b44eSHemant Agrawal 	session->auth_key.length = auth_xform->key.length;
21348524b44eSHemant Agrawal 	memcpy(session->cipher_key.data, cipher_xform->key.data,
21358524b44eSHemant Agrawal 	       cipher_xform->key.length);
21368524b44eSHemant Agrawal 	memcpy(session->auth_key.data, auth_xform->key.data,
21378524b44eSHemant Agrawal 	       auth_xform->key.length);
21388524b44eSHemant Agrawal 
21398524b44eSHemant Agrawal 	session->digest_length = auth_xform->digest_length;
21408524b44eSHemant Agrawal 	session->auth_alg = auth_xform->algo;
21418524b44eSHemant Agrawal 
21428524b44eSHemant Agrawal 	switch (auth_xform->algo) {
21438524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1_HMAC:
21448524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA1;
21458524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21468524b44eSHemant Agrawal 		break;
21478524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5_HMAC:
21488524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_MD5;
21498524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21508524b44eSHemant Agrawal 		break;
21518524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224_HMAC:
21528524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA224;
21538524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21548524b44eSHemant Agrawal 		break;
21558524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA256_HMAC:
21568524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA256;
21578524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21588524b44eSHemant Agrawal 		break;
21598524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA384_HMAC:
21608524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA384;
21618524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21628524b44eSHemant Agrawal 		break;
21638524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA512_HMAC:
21648524b44eSHemant Agrawal 		session->auth_key.alg = OP_ALG_ALGSEL_SHA512;
21658524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
21668524b44eSHemant Agrawal 		break;
21678524b44eSHemant Agrawal 	default:
21688524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported Auth specified %u",
21698524b44eSHemant Agrawal 			      auth_xform->algo);
2170c08ced9aSAkhil Goyal 		return -ENOTSUP;
21718524b44eSHemant Agrawal 	}
21728524b44eSHemant Agrawal 
21738524b44eSHemant Agrawal 	session->cipher_alg = cipher_xform->algo;
21748524b44eSHemant Agrawal 
21758524b44eSHemant Agrawal 	switch (cipher_xform->algo) {
21768524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CBC:
21778524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
21788524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
21798524b44eSHemant Agrawal 		break;
21808524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_CBC:
21818524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_3DES;
21828524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
21838524b44eSHemant Agrawal 		break;
21848524b44eSHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CTR:
21858524b44eSHemant Agrawal 		session->cipher_key.alg = OP_ALG_ALGSEL_AES;
21868524b44eSHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CTR;
21878524b44eSHemant Agrawal 		break;
21888524b44eSHemant Agrawal 	default:
21898524b44eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
21908524b44eSHemant Agrawal 			      cipher_xform->algo);
2191c08ced9aSAkhil Goyal 		return -ENOTSUP;
21928524b44eSHemant Agrawal 	}
21938524b44eSHemant Agrawal 	session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
21948524b44eSHemant Agrawal 				DIR_ENC : DIR_DEC;
21958524b44eSHemant Agrawal 	return 0;
21968524b44eSHemant Agrawal }
21978524b44eSHemant Agrawal 
21988524b44eSHemant Agrawal static int
2199c3e85bdcSAkhil Goyal dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
2200c3e85bdcSAkhil Goyal 		   struct rte_crypto_sym_xform *xform,
2201c3e85bdcSAkhil Goyal 		   dpaa_sec_session *session)
2202c3e85bdcSAkhil Goyal {
2203c3e85bdcSAkhil Goyal 	session->aead_alg = xform->aead.algo;
22048524b44eSHemant Agrawal 	session->ctxt = DPAA_SEC_AEAD;
2205c3e85bdcSAkhil Goyal 	session->iv.length = xform->aead.iv.length;
2206c3e85bdcSAkhil Goyal 	session->iv.offset = xform->aead.iv.offset;
2207c3e85bdcSAkhil Goyal 	session->auth_only_len = xform->aead.aad_length;
2208c3e85bdcSAkhil Goyal 	session->aead_key.data = rte_zmalloc(NULL, xform->aead.key.length,
2209c3e85bdcSAkhil Goyal 					     RTE_CACHE_LINE_SIZE);
2210c3e85bdcSAkhil Goyal 	if (session->aead_key.data == NULL && xform->aead.key.length > 0) {
2211f163231eSHemant Agrawal 		DPAA_SEC_ERR("No Memory for aead key\n");
2212c3e85bdcSAkhil Goyal 		return -ENOMEM;
2213c3e85bdcSAkhil Goyal 	}
2214c3e85bdcSAkhil Goyal 	session->aead_key.length = xform->aead.key.length;
2215c3e85bdcSAkhil Goyal 	session->digest_length = xform->aead.digest_length;
2216c3e85bdcSAkhil Goyal 
2217c3e85bdcSAkhil Goyal 	memcpy(session->aead_key.data, xform->aead.key.data,
2218c3e85bdcSAkhil Goyal 	       xform->aead.key.length);
22198524b44eSHemant Agrawal 
22208524b44eSHemant Agrawal 	switch (session->aead_alg) {
22218524b44eSHemant Agrawal 	case RTE_CRYPTO_AEAD_AES_GCM:
22228524b44eSHemant Agrawal 		session->aead_key.alg = OP_ALG_ALGSEL_AES;
22238524b44eSHemant Agrawal 		session->aead_key.algmode = OP_ALG_AAI_GCM;
22248524b44eSHemant Agrawal 		break;
22258524b44eSHemant Agrawal 	default:
22268524b44eSHemant Agrawal 		DPAA_SEC_ERR("unsupported AEAD alg %d", session->aead_alg);
2227c08ced9aSAkhil Goyal 		return -ENOTSUP;
22288524b44eSHemant Agrawal 	}
22298524b44eSHemant Agrawal 
2230c3e85bdcSAkhil Goyal 	session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2231c3e85bdcSAkhil Goyal 			DIR_ENC : DIR_DEC;
2232c3e85bdcSAkhil Goyal 
2233c3e85bdcSAkhil Goyal 	return 0;
2234c3e85bdcSAkhil Goyal }
2235c3e85bdcSAkhil Goyal 
2236e79416d1SHemant Agrawal static struct qman_fq *
2237e79416d1SHemant Agrawal dpaa_sec_attach_rxq(struct dpaa_sec_dev_private *qi)
2238c3e85bdcSAkhil Goyal {
2239e79416d1SHemant Agrawal 	unsigned int i;
2240c3e85bdcSAkhil Goyal 
2241fd900d38SGagandeep Singh 	for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) {
2242e79416d1SHemant Agrawal 		if (qi->inq_attach[i] == 0) {
2243e79416d1SHemant Agrawal 			qi->inq_attach[i] = 1;
2244e79416d1SHemant Agrawal 			return &qi->inq[i];
2245e79416d1SHemant Agrawal 		}
2246e79416d1SHemant Agrawal 	}
2247e621d970SAkhil Goyal 	DPAA_SEC_WARN("All session in use %u", qi->max_nb_sessions);
2248c3e85bdcSAkhil Goyal 
2249e79416d1SHemant Agrawal 	return NULL;
2250c3e85bdcSAkhil Goyal }
2251c3e85bdcSAkhil Goyal 
2252e79416d1SHemant Agrawal static int
2253e79416d1SHemant Agrawal dpaa_sec_detach_rxq(struct dpaa_sec_dev_private *qi, struct qman_fq *fq)
2254e79416d1SHemant Agrawal {
2255e79416d1SHemant Agrawal 	unsigned int i;
2256e79416d1SHemant Agrawal 
2257fd900d38SGagandeep Singh 	for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) {
2258e79416d1SHemant Agrawal 		if (&qi->inq[i] == fq) {
2259fd900d38SGagandeep Singh 			if (qman_retire_fq(fq, NULL) != 0)
2260fd900d38SGagandeep Singh 				DPAA_SEC_WARN("Queue is not retired\n");
2261b4053c4bSAlok Makhariya 			qman_oos_fq(fq);
2262e79416d1SHemant Agrawal 			qi->inq_attach[i] = 0;
2263e79416d1SHemant Agrawal 			return 0;
2264e79416d1SHemant Agrawal 		}
2265e79416d1SHemant Agrawal 	}
2266e79416d1SHemant Agrawal 	return -1;
2267e79416d1SHemant Agrawal }
2268e79416d1SHemant Agrawal 
2269e79416d1SHemant Agrawal static int
2270e79416d1SHemant Agrawal dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess)
2271e79416d1SHemant Agrawal {
2272e79416d1SHemant Agrawal 	int ret;
2273e79416d1SHemant Agrawal 
22744e694fe5SAkhil Goyal 	sess->qp[rte_lcore_id() % MAX_DPAA_CORES] = qp;
2275e79416d1SHemant Agrawal 	ret = dpaa_sec_prep_cdb(sess);
2276e79416d1SHemant Agrawal 	if (ret) {
2277f163231eSHemant Agrawal 		DPAA_SEC_ERR("Unable to prepare sec cdb");
2278c08ced9aSAkhil Goyal 		return ret;
2279e79416d1SHemant Agrawal 	}
2280*e5872221SRohit Raj 	if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
22815b0f1bd3SAshish Jain 		ret = rte_dpaa_portal_init((void *)0);
22825b0f1bd3SAshish Jain 		if (ret) {
2283f163231eSHemant Agrawal 			DPAA_SEC_ERR("Failure in affining portal");
22845b0f1bd3SAshish Jain 			return ret;
22855b0f1bd3SAshish Jain 		}
22865b0f1bd3SAshish Jain 	}
22874e694fe5SAkhil Goyal 	ret = dpaa_sec_init_rx(sess->inq[rte_lcore_id() % MAX_DPAA_CORES],
2288ec861560SGagandeep Singh 			       rte_dpaa_mem_vtop(&sess->cdb),
2289e79416d1SHemant Agrawal 			       qman_fq_fqid(&qp->outq));
2290e79416d1SHemant Agrawal 	if (ret)
2291f163231eSHemant Agrawal 		DPAA_SEC_ERR("Unable to init sec queue");
2292e79416d1SHemant Agrawal 
2293e79416d1SHemant Agrawal 	return ret;
2294c3e85bdcSAkhil Goyal }
2295c3e85bdcSAkhil Goyal 
22966290de2cSLukasz Wojciechowski static inline void
22976290de2cSLukasz Wojciechowski free_session_data(dpaa_sec_session *s)
22986290de2cSLukasz Wojciechowski {
22996290de2cSLukasz Wojciechowski 	if (is_aead(s))
23006290de2cSLukasz Wojciechowski 		rte_free(s->aead_key.data);
23016290de2cSLukasz Wojciechowski 	else {
23026290de2cSLukasz Wojciechowski 		rte_free(s->auth_key.data);
23036290de2cSLukasz Wojciechowski 		rte_free(s->cipher_key.data);
23046290de2cSLukasz Wojciechowski 	}
23056290de2cSLukasz Wojciechowski 	memset(s, 0, sizeof(dpaa_sec_session));
23066290de2cSLukasz Wojciechowski }
23076290de2cSLukasz Wojciechowski 
2308c3e85bdcSAkhil Goyal static int
2309c3e85bdcSAkhil Goyal dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
2310c3e85bdcSAkhil Goyal 			    struct rte_crypto_sym_xform *xform,	void *sess)
2311c3e85bdcSAkhil Goyal {
2312c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals = dev->data->dev_private;
2313c3e85bdcSAkhil Goyal 	dpaa_sec_session *session = sess;
23144e694fe5SAkhil Goyal 	uint32_t i;
2315f73d6928SHemant Agrawal 	int ret;
2316c3e85bdcSAkhil Goyal 
2317c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
2318c3e85bdcSAkhil Goyal 
2319c3e85bdcSAkhil Goyal 	if (unlikely(sess == NULL)) {
2320f163231eSHemant Agrawal 		DPAA_SEC_ERR("invalid session struct");
2321c3e85bdcSAkhil Goyal 		return -EINVAL;
2322c3e85bdcSAkhil Goyal 	}
2323b0894102SAkhil Goyal 	memset(session, 0, sizeof(dpaa_sec_session));
2324c3e85bdcSAkhil Goyal 
2325c3e85bdcSAkhil Goyal 	/* Default IV length = 0 */
2326c3e85bdcSAkhil Goyal 	session->iv.length = 0;
2327c3e85bdcSAkhil Goyal 
2328c3e85bdcSAkhil Goyal 	/* Cipher Only */
2329c3e85bdcSAkhil Goyal 	if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2330c3e85bdcSAkhil Goyal 		session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2331f73d6928SHemant Agrawal 		ret = dpaa_sec_cipher_init(dev, xform, session);
2332c3e85bdcSAkhil Goyal 
2333c3e85bdcSAkhil Goyal 	/* Authentication Only */
2334c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2335c3e85bdcSAkhil Goyal 		   xform->next == NULL) {
2336c3e85bdcSAkhil Goyal 		session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
23378524b44eSHemant Agrawal 		session->ctxt = DPAA_SEC_AUTH;
2338f73d6928SHemant Agrawal 		ret = dpaa_sec_auth_init(dev, xform, session);
2339c3e85bdcSAkhil Goyal 
2340c3e85bdcSAkhil Goyal 	/* Cipher then Authenticate */
2341c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2342c3e85bdcSAkhil Goyal 		   xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2343c3e85bdcSAkhil Goyal 		if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
23448524b44eSHemant Agrawal 			session->auth_cipher_text = 1;
2345f73d6928SHemant Agrawal 			if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2346f73d6928SHemant Agrawal 				ret = dpaa_sec_auth_init(dev, xform, session);
2347f73d6928SHemant Agrawal 			else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2348f73d6928SHemant Agrawal 				ret = dpaa_sec_cipher_init(dev, xform, session);
2349f73d6928SHemant Agrawal 			else
2350f73d6928SHemant Agrawal 				ret = dpaa_sec_chain_init(dev, xform, session);
2351c3e85bdcSAkhil Goyal 		} else {
2352f163231eSHemant Agrawal 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
2353c08ced9aSAkhil Goyal 			return -ENOTSUP;
2354c3e85bdcSAkhil Goyal 		}
2355c3e85bdcSAkhil Goyal 	/* Authenticate then Cipher */
2356c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2357c3e85bdcSAkhil Goyal 		   xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2358c3e85bdcSAkhil Goyal 		if (xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
23598524b44eSHemant Agrawal 			session->auth_cipher_text = 0;
2360f73d6928SHemant Agrawal 			if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2361f73d6928SHemant Agrawal 				ret = dpaa_sec_cipher_init(dev, xform, session);
2362f73d6928SHemant Agrawal 			else if (xform->next->cipher.algo
2363f73d6928SHemant Agrawal 					== RTE_CRYPTO_CIPHER_NULL)
2364f73d6928SHemant Agrawal 				ret = dpaa_sec_auth_init(dev, xform, session);
2365f73d6928SHemant Agrawal 			else
2366f73d6928SHemant Agrawal 				ret = dpaa_sec_chain_init(dev, xform, session);
2367c3e85bdcSAkhil Goyal 		} else {
2368f163231eSHemant Agrawal 			DPAA_SEC_ERR("Not supported: Auth then Cipher");
2369c08ced9aSAkhil Goyal 			return -ENOTSUP;
2370c3e85bdcSAkhil Goyal 		}
2371c3e85bdcSAkhil Goyal 
2372c3e85bdcSAkhil Goyal 	/* AEAD operation for AES-GCM kind of Algorithms */
2373c3e85bdcSAkhil Goyal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2374c3e85bdcSAkhil Goyal 		   xform->next == NULL) {
2375f73d6928SHemant Agrawal 		ret = dpaa_sec_aead_init(dev, xform, session);
2376c3e85bdcSAkhil Goyal 
2377c3e85bdcSAkhil Goyal 	} else {
2378f163231eSHemant Agrawal 		DPAA_SEC_ERR("Invalid crypto type");
2379c3e85bdcSAkhil Goyal 		return -EINVAL;
2380c3e85bdcSAkhil Goyal 	}
2381f73d6928SHemant Agrawal 	if (ret) {
2382f73d6928SHemant Agrawal 		DPAA_SEC_ERR("unable to init session");
2383f73d6928SHemant Agrawal 		goto err1;
2384f73d6928SHemant Agrawal 	}
2385f73d6928SHemant Agrawal 
23863b617ee7SAkhil Goyal 	rte_spinlock_lock(&internals->lock);
23874e694fe5SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
23884e694fe5SAkhil Goyal 		session->inq[i] = dpaa_sec_attach_rxq(internals);
23894e694fe5SAkhil Goyal 		if (session->inq[i] == NULL) {
2390f163231eSHemant Agrawal 			DPAA_SEC_ERR("unable to attach sec queue");
23914e694fe5SAkhil Goyal 			rte_spinlock_unlock(&internals->lock);
2392c08ced9aSAkhil Goyal 			ret = -EBUSY;
2393e79416d1SHemant Agrawal 			goto err1;
2394e79416d1SHemant Agrawal 		}
23954e694fe5SAkhil Goyal 	}
23964e694fe5SAkhil Goyal 	rte_spinlock_unlock(&internals->lock);
2397c3e85bdcSAkhil Goyal 
2398c3e85bdcSAkhil Goyal 	return 0;
2399e79416d1SHemant Agrawal 
2400e79416d1SHemant Agrawal err1:
24016290de2cSLukasz Wojciechowski 	free_session_data(session);
2402c08ced9aSAkhil Goyal 	return ret;
2403c3e85bdcSAkhil Goyal }
2404c3e85bdcSAkhil Goyal 
2405c3e85bdcSAkhil Goyal static int
2406012c5076SPablo de Lara dpaa_sec_sym_session_configure(struct rte_cryptodev *dev,
2407c3e85bdcSAkhil Goyal 		struct rte_crypto_sym_xform *xform,
2408c3e85bdcSAkhil Goyal 		struct rte_cryptodev_sym_session *sess,
2409c3e85bdcSAkhil Goyal 		struct rte_mempool *mempool)
2410c3e85bdcSAkhil Goyal {
2411c3e85bdcSAkhil Goyal 	void *sess_private_data;
2412c3e85bdcSAkhil Goyal 	int ret;
2413c3e85bdcSAkhil Goyal 
2414c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
2415c3e85bdcSAkhil Goyal 
2416c3e85bdcSAkhil Goyal 	if (rte_mempool_get(mempool, &sess_private_data)) {
2417f163231eSHemant Agrawal 		DPAA_SEC_ERR("Couldn't get object from session mempool");
2418c3e85bdcSAkhil Goyal 		return -ENOMEM;
2419c3e85bdcSAkhil Goyal 	}
2420c3e85bdcSAkhil Goyal 
2421c3e85bdcSAkhil Goyal 	ret = dpaa_sec_set_session_parameters(dev, xform, sess_private_data);
2422c3e85bdcSAkhil Goyal 	if (ret != 0) {
2423f163231eSHemant Agrawal 		DPAA_SEC_ERR("failed to configure session parameters");
2424c3e85bdcSAkhil Goyal 
2425c3e85bdcSAkhil Goyal 		/* Return session to mempool */
2426c3e85bdcSAkhil Goyal 		rte_mempool_put(mempool, sess_private_data);
2427c3e85bdcSAkhil Goyal 		return ret;
2428c3e85bdcSAkhil Goyal 	}
2429c3e85bdcSAkhil Goyal 
2430012c5076SPablo de Lara 	set_sym_session_private_data(sess, dev->driver_id,
2431c3e85bdcSAkhil Goyal 			sess_private_data);
2432c3e85bdcSAkhil Goyal 
2433e79416d1SHemant Agrawal 
2434c3e85bdcSAkhil Goyal 	return 0;
2435c3e85bdcSAkhil Goyal }
2436c3e85bdcSAkhil Goyal 
24373d0d5332SAkhil Goyal static inline void
24383d0d5332SAkhil Goyal free_session_memory(struct rte_cryptodev *dev, dpaa_sec_session *s)
2439c3e85bdcSAkhil Goyal {
2440e79416d1SHemant Agrawal 	struct dpaa_sec_dev_private *qi = dev->data->dev_private;
24413d0d5332SAkhil Goyal 	struct rte_mempool *sess_mp = rte_mempool_from_obj((void *)s);
24423d0d5332SAkhil Goyal 	uint8_t i;
2443e79416d1SHemant Agrawal 
2444e621d970SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
2445e621d970SAkhil Goyal 		if (s->inq[i])
2446e621d970SAkhil Goyal 			dpaa_sec_detach_rxq(qi, s->inq[i]);
2447e621d970SAkhil Goyal 		s->inq[i] = NULL;
2448e621d970SAkhil Goyal 		s->qp[i] = NULL;
2449e621d970SAkhil Goyal 	}
24506290de2cSLukasz Wojciechowski 	free_session_data(s);
24513d0d5332SAkhil Goyal 	rte_mempool_put(sess_mp, (void *)s);
24523d0d5332SAkhil Goyal }
24533d0d5332SAkhil Goyal 
24543d0d5332SAkhil Goyal /** Clear the memory of session so it doesn't leave key material behind */
24553d0d5332SAkhil Goyal static void
24563d0d5332SAkhil Goyal dpaa_sec_sym_session_clear(struct rte_cryptodev *dev,
24573d0d5332SAkhil Goyal 		struct rte_cryptodev_sym_session *sess)
24583d0d5332SAkhil Goyal {
24593d0d5332SAkhil Goyal 	PMD_INIT_FUNC_TRACE();
24603d0d5332SAkhil Goyal 	uint8_t index = dev->driver_id;
24613d0d5332SAkhil Goyal 	void *sess_priv = get_sym_session_private_data(sess, index);
24623d0d5332SAkhil Goyal 	dpaa_sec_session *s = (dpaa_sec_session *)sess_priv;
24633d0d5332SAkhil Goyal 
24643d0d5332SAkhil Goyal 	if (sess_priv) {
24653d0d5332SAkhil Goyal 		free_session_memory(dev, s);
2466012c5076SPablo de Lara 		set_sym_session_private_data(sess, index, NULL);
2467c3e85bdcSAkhil Goyal 	}
2468c3e85bdcSAkhil Goyal }
2469c3e85bdcSAkhil Goyal 
2470314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
2471c3e85bdcSAkhil Goyal static int
24722c318722SHemant Agrawal dpaa_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
24732c318722SHemant Agrawal 			struct rte_security_ipsec_xform *ipsec_xform,
24742c318722SHemant Agrawal 			dpaa_sec_session *session)
24751f14d500SAkhil Goyal {
24761f14d500SAkhil Goyal 	PMD_INIT_FUNC_TRACE();
24771f14d500SAkhil Goyal 
24782c318722SHemant Agrawal 	session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
24792c318722SHemant Agrawal 					       RTE_CACHE_LINE_SIZE);
24802c318722SHemant Agrawal 	if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
24812c318722SHemant Agrawal 		DPAA_SEC_ERR("No Memory for aead key");
2482c08ced9aSAkhil Goyal 		return -ENOMEM;
24831f14d500SAkhil Goyal 	}
24842c318722SHemant Agrawal 	memcpy(session->aead_key.data, aead_xform->key.data,
24852c318722SHemant Agrawal 	       aead_xform->key.length);
248605b12700SHemant Agrawal 
24872c318722SHemant Agrawal 	session->digest_length = aead_xform->digest_length;
24882c318722SHemant Agrawal 	session->aead_key.length = aead_xform->key.length;
24892c318722SHemant Agrawal 
24902c318722SHemant Agrawal 	switch (aead_xform->algo) {
24912c318722SHemant Agrawal 	case RTE_CRYPTO_AEAD_AES_GCM:
24922c318722SHemant Agrawal 		switch (session->digest_length) {
24932c318722SHemant Agrawal 		case 8:
24942c318722SHemant Agrawal 			session->aead_key.alg = OP_PCL_IPSEC_AES_GCM8;
24952c318722SHemant Agrawal 			break;
24962c318722SHemant Agrawal 		case 12:
24972c318722SHemant Agrawal 			session->aead_key.alg = OP_PCL_IPSEC_AES_GCM12;
24982c318722SHemant Agrawal 			break;
24992c318722SHemant Agrawal 		case 16:
25002c318722SHemant Agrawal 			session->aead_key.alg = OP_PCL_IPSEC_AES_GCM16;
25012c318722SHemant Agrawal 			break;
25022c318722SHemant Agrawal 		default:
25032c318722SHemant Agrawal 			DPAA_SEC_ERR("Crypto: Undefined GCM digest %d",
25042c318722SHemant Agrawal 				     session->digest_length);
2505c08ced9aSAkhil Goyal 			return -EINVAL;
25062c318722SHemant Agrawal 		}
25072c318722SHemant Agrawal 		if (session->dir == DIR_ENC) {
25082c318722SHemant Agrawal 			memcpy(session->encap_pdb.gcm.salt,
25092c318722SHemant Agrawal 				(uint8_t *)&(ipsec_xform->salt), 4);
25102c318722SHemant Agrawal 		} else {
25112c318722SHemant Agrawal 			memcpy(session->decap_pdb.gcm.salt,
25122c318722SHemant Agrawal 				(uint8_t *)&(ipsec_xform->salt), 4);
25132c318722SHemant Agrawal 		}
25142c318722SHemant Agrawal 		session->aead_key.algmode = OP_ALG_AAI_GCM;
25152c318722SHemant Agrawal 		session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
25162c318722SHemant Agrawal 		break;
25172c318722SHemant Agrawal 	default:
25182c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined AEAD specified %u",
25192c318722SHemant Agrawal 			      aead_xform->algo);
2520c08ced9aSAkhil Goyal 		return -ENOTSUP;
25212c318722SHemant Agrawal 	}
25222c318722SHemant Agrawal 	return 0;
25232c318722SHemant Agrawal }
25242c318722SHemant Agrawal 
25252c318722SHemant Agrawal static int
25262c318722SHemant Agrawal dpaa_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
25272c318722SHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform,
25281cdfbb0bSVakul Garg 	struct rte_security_ipsec_xform *ipsec_xform,
25292c318722SHemant Agrawal 	dpaa_sec_session *session)
25302c318722SHemant Agrawal {
25312c318722SHemant Agrawal 	if (cipher_xform) {
25321f14d500SAkhil Goyal 		session->cipher_key.data = rte_zmalloc(NULL,
25331f14d500SAkhil Goyal 						       cipher_xform->key.length,
25341f14d500SAkhil Goyal 						       RTE_CACHE_LINE_SIZE);
25351f14d500SAkhil Goyal 		if (session->cipher_key.data == NULL &&
25361f14d500SAkhil Goyal 				cipher_xform->key.length > 0) {
2537f163231eSHemant Agrawal 			DPAA_SEC_ERR("No Memory for cipher key");
25381f14d500SAkhil Goyal 			return -ENOMEM;
25391f14d500SAkhil Goyal 		}
25402c318722SHemant Agrawal 
25412c318722SHemant Agrawal 		session->cipher_key.length = cipher_xform->key.length;
254205b12700SHemant Agrawal 		memcpy(session->cipher_key.data, cipher_xform->key.data,
254305b12700SHemant Agrawal 				cipher_xform->key.length);
254405b12700SHemant Agrawal 		session->cipher_alg = cipher_xform->algo;
254505b12700SHemant Agrawal 	} else {
254605b12700SHemant Agrawal 		session->cipher_key.data = NULL;
254705b12700SHemant Agrawal 		session->cipher_key.length = 0;
254805b12700SHemant Agrawal 		session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
254905b12700SHemant Agrawal 	}
255005b12700SHemant Agrawal 
25512c318722SHemant Agrawal 	if (auth_xform) {
25521f14d500SAkhil Goyal 		session->auth_key.data = rte_zmalloc(NULL,
25531f14d500SAkhil Goyal 						auth_xform->key.length,
25541f14d500SAkhil Goyal 						RTE_CACHE_LINE_SIZE);
25551f14d500SAkhil Goyal 		if (session->auth_key.data == NULL &&
25561f14d500SAkhil Goyal 				auth_xform->key.length > 0) {
2557f163231eSHemant Agrawal 			DPAA_SEC_ERR("No Memory for auth key");
25581f14d500SAkhil Goyal 			return -ENOMEM;
25591f14d500SAkhil Goyal 		}
25602c318722SHemant Agrawal 		session->auth_key.length = auth_xform->key.length;
25611f14d500SAkhil Goyal 		memcpy(session->auth_key.data, auth_xform->key.data,
25621f14d500SAkhil Goyal 				auth_xform->key.length);
25632c318722SHemant Agrawal 		session->auth_alg = auth_xform->algo;
2564247b6908SHemant Agrawal 		session->digest_length = auth_xform->digest_length;
25652c318722SHemant Agrawal 	} else {
25662c318722SHemant Agrawal 		session->auth_key.data = NULL;
25672c318722SHemant Agrawal 		session->auth_key.length = 0;
25682c318722SHemant Agrawal 		session->auth_alg = RTE_CRYPTO_AUTH_NULL;
25692c318722SHemant Agrawal 	}
25701f14d500SAkhil Goyal 
25712c318722SHemant Agrawal 	switch (session->auth_alg) {
25728524b44eSHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1_HMAC:
25738524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA1_96;
25748524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25758524b44eSHemant Agrawal 		break;
25762c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5_HMAC:
25772c318722SHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_MD5_96;
25788524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25798524b44eSHemant Agrawal 		break;
25801f14d500SAkhil Goyal 	case RTE_CRYPTO_AUTH_SHA256_HMAC:
25818524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_256_128;
25828524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
2583247b6908SHemant Agrawal 		if (session->digest_length != 16)
2584247b6908SHemant Agrawal 			DPAA_SEC_WARN(
2585247b6908SHemant Agrawal 			"+++Using sha256-hmac truncated len is non-standard,"
2586247b6908SHemant Agrawal 			"it will not work with lookaside proto");
25878524b44eSHemant Agrawal 		break;
25881f14d500SAkhil Goyal 	case RTE_CRYPTO_AUTH_SHA384_HMAC:
25898524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_384_192;
25908524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25918524b44eSHemant Agrawal 		break;
25921f14d500SAkhil Goyal 	case RTE_CRYPTO_AUTH_SHA512_HMAC:
25938524b44eSHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_SHA2_512_256;
25948524b44eSHemant Agrawal 		session->auth_key.algmode = OP_ALG_AAI_HMAC;
25951f14d500SAkhil Goyal 		break;
25962c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_CMAC:
25972c318722SHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_AES_CMAC_96;
25982c318722SHemant Agrawal 		break;
25992c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_NULL:
26002c318722SHemant Agrawal 		session->auth_key.alg = OP_PCL_IPSEC_HMAC_NULL;
26012c318722SHemant Agrawal 		break;
26022c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224_HMAC:
26032c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
26042c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
26052c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA1:
26062c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA256:
26072c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA512:
26082c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA224:
26092c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_SHA384:
26102c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_MD5:
26112c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_GMAC:
26122c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_KASUMI_F9:
26132c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_AES_CBC_MAC:
26142c318722SHemant Agrawal 	case RTE_CRYPTO_AUTH_ZUC_EIA3:
2615f163231eSHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
26162c318722SHemant Agrawal 			      session->auth_alg);
2617c08ced9aSAkhil Goyal 		return -ENOTSUP;
26182c318722SHemant Agrawal 	default:
26192c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Auth specified %u",
26202c318722SHemant Agrawal 			      session->auth_alg);
2621c08ced9aSAkhil Goyal 		return -ENOTSUP;
26222c318722SHemant Agrawal 	}
26232c318722SHemant Agrawal 
26242c318722SHemant Agrawal 	switch (session->cipher_alg) {
26252c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CBC:
26262c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_AES_CBC;
26272c318722SHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
26282c318722SHemant Agrawal 		break;
26292c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_CBC:
26302c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_3DES;
26312c318722SHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CBC;
26322c318722SHemant Agrawal 		break;
26332c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_CTR:
26342c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_AES_CTR;
26352c318722SHemant Agrawal 		session->cipher_key.algmode = OP_ALG_AAI_CTR;
26361cdfbb0bSVakul Garg 		if (session->dir == DIR_ENC) {
26371cdfbb0bSVakul Garg 			session->encap_pdb.ctr.ctr_initial = 0x00000001;
26381cdfbb0bSVakul Garg 			session->encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
26391cdfbb0bSVakul Garg 		} else {
26401cdfbb0bSVakul Garg 			session->decap_pdb.ctr.ctr_initial = 0x00000001;
26411cdfbb0bSVakul Garg 			session->decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
26421cdfbb0bSVakul Garg 		}
26432c318722SHemant Agrawal 		break;
26442c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_NULL:
26452c318722SHemant Agrawal 		session->cipher_key.alg = OP_PCL_IPSEC_NULL;
26462c318722SHemant Agrawal 		break;
26472c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
26482c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_ZUC_EEA3:
26492c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_3DES_ECB:
26502c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_AES_ECB:
26512c318722SHemant Agrawal 	case RTE_CRYPTO_CIPHER_KASUMI_F8:
26522c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
26532c318722SHemant Agrawal 			      session->cipher_alg);
2654c08ced9aSAkhil Goyal 		return -ENOTSUP;
26552c318722SHemant Agrawal 	default:
26562c318722SHemant Agrawal 		DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
26572c318722SHemant Agrawal 			      session->cipher_alg);
2658c08ced9aSAkhil Goyal 		return -ENOTSUP;
26592c318722SHemant Agrawal 	}
26602c318722SHemant Agrawal 
26612c318722SHemant Agrawal 	return 0;
26622c318722SHemant Agrawal }
26632c318722SHemant Agrawal 
26642c318722SHemant Agrawal static int
26652c318722SHemant Agrawal dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
26662c318722SHemant Agrawal 			   struct rte_security_session_conf *conf,
26672c318722SHemant Agrawal 			   void *sess)
26682c318722SHemant Agrawal {
26692c318722SHemant Agrawal 	struct dpaa_sec_dev_private *internals = dev->data->dev_private;
26702c318722SHemant Agrawal 	struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
26712c318722SHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform = NULL;
26722c318722SHemant Agrawal 	struct rte_crypto_cipher_xform *cipher_xform = NULL;
26732c318722SHemant Agrawal 	struct rte_crypto_aead_xform *aead_xform = NULL;
26742c318722SHemant Agrawal 	dpaa_sec_session *session = (dpaa_sec_session *)sess;
26752c318722SHemant Agrawal 	uint32_t i;
26762c318722SHemant Agrawal 	int ret;
26772c318722SHemant Agrawal 
26782c318722SHemant Agrawal 	PMD_INIT_FUNC_TRACE();
26792c318722SHemant Agrawal 
26802c318722SHemant Agrawal 	memset(session, 0, sizeof(dpaa_sec_session));
26812c318722SHemant Agrawal 	session->proto_alg = conf->protocol;
26822c318722SHemant Agrawal 	session->ctxt = DPAA_SEC_IPSEC;
26832c318722SHemant Agrawal 
26842c318722SHemant Agrawal 	if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
26852c318722SHemant Agrawal 		session->dir = DIR_ENC;
26862c318722SHemant Agrawal 	else
26872c318722SHemant Agrawal 		session->dir = DIR_DEC;
26882c318722SHemant Agrawal 
26892c318722SHemant Agrawal 	if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
26902c318722SHemant Agrawal 		cipher_xform = &conf->crypto_xform->cipher;
26912c318722SHemant Agrawal 		if (conf->crypto_xform->next)
26922c318722SHemant Agrawal 			auth_xform = &conf->crypto_xform->next->auth;
26932c318722SHemant Agrawal 		ret = dpaa_sec_ipsec_proto_init(cipher_xform, auth_xform,
26941cdfbb0bSVakul Garg 					ipsec_xform, session);
26952c318722SHemant Agrawal 	} else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
26962c318722SHemant Agrawal 		auth_xform = &conf->crypto_xform->auth;
26972c318722SHemant Agrawal 		if (conf->crypto_xform->next)
26982c318722SHemant Agrawal 			cipher_xform = &conf->crypto_xform->next->cipher;
26992c318722SHemant Agrawal 		ret = dpaa_sec_ipsec_proto_init(cipher_xform, auth_xform,
27001cdfbb0bSVakul Garg 					ipsec_xform, session);
27012c318722SHemant Agrawal 	} else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
27022c318722SHemant Agrawal 		aead_xform = &conf->crypto_xform->aead;
27032c318722SHemant Agrawal 		ret = dpaa_sec_ipsec_aead_init(aead_xform,
27042c318722SHemant Agrawal 					ipsec_xform, session);
27052c318722SHemant Agrawal 	} else {
27062c318722SHemant Agrawal 		DPAA_SEC_ERR("XFORM not specified");
27072c318722SHemant Agrawal 		ret = -EINVAL;
27081f14d500SAkhil Goyal 		goto out;
27091f14d500SAkhil Goyal 	}
27102c318722SHemant Agrawal 	if (ret) {
27112c318722SHemant Agrawal 		DPAA_SEC_ERR("Failed to process xform");
27122c318722SHemant Agrawal 		goto out;
27131f14d500SAkhil Goyal 	}
27141f14d500SAkhil Goyal 
27151f14d500SAkhil Goyal 	if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
27165ab35d2eSAkhil Goyal 		if (ipsec_xform->tunnel.type ==
27175ab35d2eSAkhil Goyal 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
27181f14d500SAkhil Goyal 			session->ip4_hdr.ip_v = IPVERSION;
27191f14d500SAkhil Goyal 			session->ip4_hdr.ip_hl = 5;
27201f14d500SAkhil Goyal 			session->ip4_hdr.ip_len = rte_cpu_to_be_16(
27211f14d500SAkhil Goyal 						sizeof(session->ip4_hdr));
27221f14d500SAkhil Goyal 			session->ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
27231f14d500SAkhil Goyal 			session->ip4_hdr.ip_id = 0;
27241f14d500SAkhil Goyal 			session->ip4_hdr.ip_off = 0;
27251f14d500SAkhil Goyal 			session->ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
27261f14d500SAkhil Goyal 			session->ip4_hdr.ip_p = (ipsec_xform->proto ==
27275ab35d2eSAkhil Goyal 					RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
27285ab35d2eSAkhil Goyal 					IPPROTO_ESP : IPPROTO_AH;
27291f14d500SAkhil Goyal 			session->ip4_hdr.ip_sum = 0;
27305ab35d2eSAkhil Goyal 			session->ip4_hdr.ip_src =
27315ab35d2eSAkhil Goyal 					ipsec_xform->tunnel.ipv4.src_ip;
27325ab35d2eSAkhil Goyal 			session->ip4_hdr.ip_dst =
27335ab35d2eSAkhil Goyal 					ipsec_xform->tunnel.ipv4.dst_ip;
27341f14d500SAkhil Goyal 			session->ip4_hdr.ip_sum = calc_chksum((uint16_t *)
27351f14d500SAkhil Goyal 						(void *)&session->ip4_hdr,
27361f14d500SAkhil Goyal 						sizeof(struct ip));
27375ab35d2eSAkhil Goyal 			session->encap_pdb.ip_hdr_len = sizeof(struct ip);
27385ab35d2eSAkhil Goyal 		} else if (ipsec_xform->tunnel.type ==
27395ab35d2eSAkhil Goyal 				RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
27405ab35d2eSAkhil Goyal 			session->ip6_hdr.vtc_flow = rte_cpu_to_be_32(
27415ab35d2eSAkhil Goyal 				DPAA_IPv6_DEFAULT_VTC_FLOW |
27425ab35d2eSAkhil Goyal 				((ipsec_xform->tunnel.ipv6.dscp <<
27435ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_TC_SHIFT) &
27445ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_TC_MASK) |
27455ab35d2eSAkhil Goyal 				((ipsec_xform->tunnel.ipv6.flabel <<
27465ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_FL_SHIFT) &
27475ab35d2eSAkhil Goyal 					RTE_IPV6_HDR_FL_MASK));
27485ab35d2eSAkhil Goyal 			/* Payload length will be updated by HW */
27495ab35d2eSAkhil Goyal 			session->ip6_hdr.payload_len = 0;
27505ab35d2eSAkhil Goyal 			session->ip6_hdr.hop_limits =
27515ab35d2eSAkhil Goyal 					ipsec_xform->tunnel.ipv6.hlimit;
27525ab35d2eSAkhil Goyal 			session->ip6_hdr.proto = (ipsec_xform->proto ==
27535ab35d2eSAkhil Goyal 					RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
27545ab35d2eSAkhil Goyal 					IPPROTO_ESP : IPPROTO_AH;
27555ab35d2eSAkhil Goyal 			memcpy(&session->ip6_hdr.src_addr,
27565ab35d2eSAkhil Goyal 					&ipsec_xform->tunnel.ipv6.src_addr, 16);
27575ab35d2eSAkhil Goyal 			memcpy(&session->ip6_hdr.dst_addr,
27585ab35d2eSAkhil Goyal 					&ipsec_xform->tunnel.ipv6.dst_addr, 16);
27595ab35d2eSAkhil Goyal 			session->encap_pdb.ip_hdr_len =
27605ab35d2eSAkhil Goyal 						sizeof(struct rte_ipv6_hdr);
27615ab35d2eSAkhil Goyal 		}
27621f14d500SAkhil Goyal 		session->encap_pdb.options =
27631f14d500SAkhil Goyal 			(IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
27641f14d500SAkhil Goyal 			PDBOPTS_ESP_OIHI_PDB_INL |
27651f14d500SAkhil Goyal 			PDBOPTS_ESP_IVSRC |
276679fde9d0SAkhil Goyal 			PDBHMO_ESP_ENCAP_DTTL |
276779fde9d0SAkhil Goyal 			PDBHMO_ESP_SNR;
27680f318781SAkhil Goyal 		if (ipsec_xform->options.esn)
27690f318781SAkhil Goyal 			session->encap_pdb.options |= PDBOPTS_ESP_ESN;
27701f14d500SAkhil Goyal 		session->encap_pdb.spi = ipsec_xform->spi;
27712c318722SHemant Agrawal 
27721f14d500SAkhil Goyal 	} else if (ipsec_xform->direction ==
27731f14d500SAkhil Goyal 			RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
27745ab35d2eSAkhil Goyal 		if (ipsec_xform->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4)
27751f14d500SAkhil Goyal 			session->decap_pdb.options = sizeof(struct ip) << 16;
27765ab35d2eSAkhil Goyal 		else
27775ab35d2eSAkhil Goyal 			session->decap_pdb.options =
27785ab35d2eSAkhil Goyal 					sizeof(struct rte_ipv6_hdr) << 16;
27790f318781SAkhil Goyal 		if (ipsec_xform->options.esn)
27800f318781SAkhil Goyal 			session->decap_pdb.options |= PDBOPTS_ESP_ESN;
2781a37ce227SHemant Agrawal 		if (ipsec_xform->replay_win_sz) {
2782a37ce227SHemant Agrawal 			uint32_t win_sz;
2783a37ce227SHemant Agrawal 			win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
2784a37ce227SHemant Agrawal 
2785a37ce227SHemant Agrawal 			switch (win_sz) {
2786a37ce227SHemant Agrawal 			case 1:
2787a37ce227SHemant Agrawal 			case 2:
2788a37ce227SHemant Agrawal 			case 4:
2789a37ce227SHemant Agrawal 			case 8:
2790a37ce227SHemant Agrawal 			case 16:
2791a37ce227SHemant Agrawal 			case 32:
2792a37ce227SHemant Agrawal 				session->decap_pdb.options |= PDBOPTS_ESP_ARS32;
2793a37ce227SHemant Agrawal 				break;
2794a37ce227SHemant Agrawal 			case 64:
2795a37ce227SHemant Agrawal 				session->decap_pdb.options |= PDBOPTS_ESP_ARS64;
2796a37ce227SHemant Agrawal 				break;
2797a37ce227SHemant Agrawal 			default:
2798a37ce227SHemant Agrawal 				session->decap_pdb.options |=
2799a37ce227SHemant Agrawal 							PDBOPTS_ESP_ARS128;
2800a37ce227SHemant Agrawal 			}
2801a37ce227SHemant Agrawal 		}
28021f14d500SAkhil Goyal 	} else
28031f14d500SAkhil Goyal 		goto out;
28043b617ee7SAkhil Goyal 	rte_spinlock_lock(&internals->lock);
28054e694fe5SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
28064e694fe5SAkhil Goyal 		session->inq[i] = dpaa_sec_attach_rxq(internals);
28074e694fe5SAkhil Goyal 		if (session->inq[i] == NULL) {
2808f163231eSHemant Agrawal 			DPAA_SEC_ERR("unable to attach sec queue");
28094e694fe5SAkhil Goyal 			rte_spinlock_unlock(&internals->lock);
28101f14d500SAkhil Goyal 			goto out;
28111f14d500SAkhil Goyal 		}
28124e694fe5SAkhil Goyal 	}
28134e694fe5SAkhil Goyal 	rte_spinlock_unlock(&internals->lock);
28141f14d500SAkhil Goyal 
2815a1173d55SHemant Agrawal 	return 0;
2816a1173d55SHemant Agrawal out:
28176290de2cSLukasz Wojciechowski 	free_session_data(session);
2818a1173d55SHemant Agrawal 	return -1;
2819a1173d55SHemant Agrawal }
28201f14d500SAkhil Goyal 
2821a1173d55SHemant Agrawal static int
2822a1173d55SHemant Agrawal dpaa_sec_set_pdcp_session(struct rte_cryptodev *dev,
2823a1173d55SHemant Agrawal 			  struct rte_security_session_conf *conf,
2824a1173d55SHemant Agrawal 			  void *sess)
2825a1173d55SHemant Agrawal {
2826a1173d55SHemant Agrawal 	struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2827a1173d55SHemant Agrawal 	struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2828a1173d55SHemant Agrawal 	struct rte_crypto_auth_xform *auth_xform = NULL;
2829a1173d55SHemant Agrawal 	struct rte_crypto_cipher_xform *cipher_xform = NULL;
2830a1173d55SHemant Agrawal 	dpaa_sec_session *session = (dpaa_sec_session *)sess;
2831a1173d55SHemant Agrawal 	struct dpaa_sec_dev_private *dev_priv = dev->data->dev_private;
28324e694fe5SAkhil Goyal 	uint32_t i;
2833c08ced9aSAkhil Goyal 	int ret;
2834a1173d55SHemant Agrawal 
2835a1173d55SHemant Agrawal 	PMD_INIT_FUNC_TRACE();
2836a1173d55SHemant Agrawal 
2837a1173d55SHemant Agrawal 	memset(session, 0, sizeof(dpaa_sec_session));
2838a1173d55SHemant Agrawal 
2839a1173d55SHemant Agrawal 	/* find xfrm types */
2840a1173d55SHemant Agrawal 	if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2841a1173d55SHemant Agrawal 		cipher_xform = &xform->cipher;
2842a1173d55SHemant Agrawal 		if (xform->next != NULL)
2843a1173d55SHemant Agrawal 			auth_xform = &xform->next->auth;
2844a1173d55SHemant Agrawal 	} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2845a1173d55SHemant Agrawal 		auth_xform = &xform->auth;
2846a1173d55SHemant Agrawal 		if (xform->next != NULL)
2847a1173d55SHemant Agrawal 			cipher_xform = &xform->next->cipher;
2848a1173d55SHemant Agrawal 	} else {
2849a1173d55SHemant Agrawal 		DPAA_SEC_ERR("Invalid crypto type");
2850a1173d55SHemant Agrawal 		return -EINVAL;
2851a1173d55SHemant Agrawal 	}
2852a1173d55SHemant Agrawal 
2853a1173d55SHemant Agrawal 	session->proto_alg = conf->protocol;
28548524b44eSHemant Agrawal 	session->ctxt = DPAA_SEC_PDCP;
28558524b44eSHemant Agrawal 
2856a1173d55SHemant Agrawal 	if (cipher_xform) {
28578524b44eSHemant Agrawal 		switch (cipher_xform->algo) {
28588524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
28598524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_SNOW;
28608524b44eSHemant Agrawal 			break;
28618524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_ZUC_EEA3:
28628524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_ZUC;
28638524b44eSHemant Agrawal 			break;
28648524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_AES_CTR:
28658524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_AES;
28668524b44eSHemant Agrawal 			break;
28678524b44eSHemant Agrawal 		case RTE_CRYPTO_CIPHER_NULL:
28688524b44eSHemant Agrawal 			session->cipher_key.alg = PDCP_CIPHER_TYPE_NULL;
28698524b44eSHemant Agrawal 			break;
28708524b44eSHemant Agrawal 		default:
28718524b44eSHemant Agrawal 			DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
28728524b44eSHemant Agrawal 				      session->cipher_alg);
2873c08ced9aSAkhil Goyal 			return -EINVAL;
28748524b44eSHemant Agrawal 		}
28758524b44eSHemant Agrawal 
2876a1173d55SHemant Agrawal 		session->cipher_key.data = rte_zmalloc(NULL,
2877a1173d55SHemant Agrawal 					       cipher_xform->key.length,
2878a1173d55SHemant Agrawal 					       RTE_CACHE_LINE_SIZE);
2879a1173d55SHemant Agrawal 		if (session->cipher_key.data == NULL &&
2880a1173d55SHemant Agrawal 				cipher_xform->key.length > 0) {
2881a1173d55SHemant Agrawal 			DPAA_SEC_ERR("No Memory for cipher key");
2882a1173d55SHemant Agrawal 			return -ENOMEM;
2883a1173d55SHemant Agrawal 		}
2884a1173d55SHemant Agrawal 		session->cipher_key.length = cipher_xform->key.length;
2885a1173d55SHemant Agrawal 		memcpy(session->cipher_key.data, cipher_xform->key.data,
2886a1173d55SHemant Agrawal 			cipher_xform->key.length);
2887a1173d55SHemant Agrawal 		session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2888a1173d55SHemant Agrawal 					DIR_ENC : DIR_DEC;
2889a1173d55SHemant Agrawal 		session->cipher_alg = cipher_xform->algo;
2890a1173d55SHemant Agrawal 	} else {
2891a1173d55SHemant Agrawal 		session->cipher_key.data = NULL;
2892a1173d55SHemant Agrawal 		session->cipher_key.length = 0;
2893a1173d55SHemant Agrawal 		session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2894a1173d55SHemant Agrawal 		session->dir = DIR_ENC;
2895a1173d55SHemant Agrawal 	}
2896a1173d55SHemant Agrawal 
2897a1173d55SHemant Agrawal 	if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
2898eac60082SVakul Garg 		if (pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_5 &&
2899eac60082SVakul Garg 		    pdcp_xform->sn_size != RTE_SECURITY_PDCP_SN_SIZE_12) {
2900a1173d55SHemant Agrawal 			DPAA_SEC_ERR(
2901eac60082SVakul Garg 				"PDCP Seq Num size should be 5/12 bits for cmode");
2902c08ced9aSAkhil Goyal 			ret = -EINVAL;
2903a1173d55SHemant Agrawal 			goto out;
2904a1173d55SHemant Agrawal 		}
29052e4cbdb4SVakul Garg 	}
29062e4cbdb4SVakul Garg 
2907a1173d55SHemant Agrawal 	if (auth_xform) {
29088524b44eSHemant Agrawal 		switch (auth_xform->algo) {
29098524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
29108524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_SNOW;
29118524b44eSHemant Agrawal 			break;
29128524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_ZUC_EIA3:
29138524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_ZUC;
29148524b44eSHemant Agrawal 			break;
29158524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_AES_CMAC:
29168524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_AES;
29178524b44eSHemant Agrawal 			break;
29188524b44eSHemant Agrawal 		case RTE_CRYPTO_AUTH_NULL:
29198524b44eSHemant Agrawal 			session->auth_key.alg = PDCP_AUTH_TYPE_NULL;
29208524b44eSHemant Agrawal 			break;
29218524b44eSHemant Agrawal 		default:
29228524b44eSHemant Agrawal 			DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
29238524b44eSHemant Agrawal 				      session->auth_alg);
29248524b44eSHemant Agrawal 			rte_free(session->cipher_key.data);
2925c08ced9aSAkhil Goyal 			return -EINVAL;
29268524b44eSHemant Agrawal 		}
2927a1173d55SHemant Agrawal 		session->auth_key.data = rte_zmalloc(NULL,
2928a1173d55SHemant Agrawal 						     auth_xform->key.length,
2929a1173d55SHemant Agrawal 						     RTE_CACHE_LINE_SIZE);
29302e4cbdb4SVakul Garg 		if (!session->auth_key.data &&
2931a1173d55SHemant Agrawal 		    auth_xform->key.length > 0) {
2932a1173d55SHemant Agrawal 			DPAA_SEC_ERR("No Memory for auth key");
2933a1173d55SHemant Agrawal 			rte_free(session->cipher_key.data);
2934a1173d55SHemant Agrawal 			return -ENOMEM;
2935a1173d55SHemant Agrawal 		}
2936a1173d55SHemant Agrawal 		session->auth_key.length = auth_xform->key.length;
2937a1173d55SHemant Agrawal 		memcpy(session->auth_key.data, auth_xform->key.data,
2938a1173d55SHemant Agrawal 		       auth_xform->key.length);
2939a1173d55SHemant Agrawal 		session->auth_alg = auth_xform->algo;
2940a1173d55SHemant Agrawal 	} else {
2941a1173d55SHemant Agrawal 		session->auth_key.data = NULL;
2942a1173d55SHemant Agrawal 		session->auth_key.length = 0;
29432e4cbdb4SVakul Garg 		session->auth_alg = 0;
2944a1173d55SHemant Agrawal 	}
2945a1173d55SHemant Agrawal 	session->pdcp.domain = pdcp_xform->domain;
2946a1173d55SHemant Agrawal 	session->pdcp.bearer = pdcp_xform->bearer;
2947a1173d55SHemant Agrawal 	session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
2948a1173d55SHemant Agrawal 	session->pdcp.sn_size = pdcp_xform->sn_size;
2949a1173d55SHemant Agrawal 	session->pdcp.hfn = pdcp_xform->hfn;
2950a1173d55SHemant Agrawal 	session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
29516a0c9d36SAkhil Goyal 	session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
29526a0c9d36SAkhil Goyal 	session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
2953a1173d55SHemant Agrawal 
2954a1173d55SHemant Agrawal 	rte_spinlock_lock(&dev_priv->lock);
29554e694fe5SAkhil Goyal 	for (i = 0; i < MAX_DPAA_CORES; i++) {
29564e694fe5SAkhil Goyal 		session->inq[i] = dpaa_sec_attach_rxq(dev_priv);
29574e694fe5SAkhil Goyal 		if (session->inq[i] == NULL) {
2958a1173d55SHemant Agrawal 			DPAA_SEC_ERR("unable to attach sec queue");
29594e694fe5SAkhil Goyal 			rte_spinlock_unlock(&dev_priv->lock);
2960c08ced9aSAkhil Goyal 			ret = -EBUSY;
2961a1173d55SHemant Agrawal 			goto out;
2962a1173d55SHemant Agrawal 		}
29634e694fe5SAkhil Goyal 	}
29644e694fe5SAkhil Goyal 	rte_spinlock_unlock(&dev_priv->lock);
29651f14d500SAkhil Goyal 	return 0;
29661f14d500SAkhil Goyal out:
29671f14d500SAkhil Goyal 	rte_free(session->auth_key.data);
29681f14d500SAkhil Goyal 	rte_free(session->cipher_key.data);
29691f14d500SAkhil Goyal 	memset(session, 0, sizeof(dpaa_sec_session));
2970c08ced9aSAkhil Goyal 	return ret;
29711f14d500SAkhil Goyal }
29721f14d500SAkhil Goyal 
29731f14d500SAkhil Goyal static int
29741f14d500SAkhil Goyal dpaa_sec_security_session_create(void *dev,
29751f14d500SAkhil Goyal 				 struct rte_security_session_conf *conf,
29761f14d500SAkhil Goyal 				 struct rte_security_session *sess,
29771f14d500SAkhil Goyal 				 struct rte_mempool *mempool)
29781f14d500SAkhil Goyal {
29791f14d500SAkhil Goyal 	void *sess_private_data;
29801f14d500SAkhil Goyal 	struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
29811f14d500SAkhil Goyal 	int ret;
29821f14d500SAkhil Goyal 
29831f14d500SAkhil Goyal 	if (rte_mempool_get(mempool, &sess_private_data)) {
2984f163231eSHemant Agrawal 		DPAA_SEC_ERR("Couldn't get object from session mempool");
29851f14d500SAkhil Goyal 		return -ENOMEM;
29861f14d500SAkhil Goyal 	}
29871f14d500SAkhil Goyal 
29881f14d500SAkhil Goyal 	switch (conf->protocol) {
29891f14d500SAkhil Goyal 	case RTE_SECURITY_PROTOCOL_IPSEC:
29901f14d500SAkhil Goyal 		ret = dpaa_sec_set_ipsec_session(cdev, conf,
29911f14d500SAkhil Goyal 				sess_private_data);
29921f14d500SAkhil Goyal 		break;
2993a1173d55SHemant Agrawal 	case RTE_SECURITY_PROTOCOL_PDCP:
2994a1173d55SHemant Agrawal 		ret = dpaa_sec_set_pdcp_session(cdev, conf,
2995a1173d55SHemant Agrawal 				sess_private_data);
2996a1173d55SHemant Agrawal 		break;
29971f14d500SAkhil Goyal 	case RTE_SECURITY_PROTOCOL_MACSEC:
29981f14d500SAkhil Goyal 		return -ENOTSUP;
29991f14d500SAkhil Goyal 	default:
30001f14d500SAkhil Goyal 		return -EINVAL;
30011f14d500SAkhil Goyal 	}
30021f14d500SAkhil Goyal 	if (ret != 0) {
3003f163231eSHemant Agrawal 		DPAA_SEC_ERR("failed to configure session parameters");
30041f14d500SAkhil Goyal 		/* Return session to mempool */
30051f14d500SAkhil Goyal 		rte_mempool_put(mempool, sess_private_data);
30061f14d500SAkhil Goyal 		return ret;
30071f14d500SAkhil Goyal 	}
30081f14d500SAkhil Goyal 
30091f14d500SAkhil Goyal 	set_sec_session_private_data(sess, sess_private_data);
30101f14d500SAkhil Goyal 
30111f14d500SAkhil Goyal 	return ret;
30121f14d500SAkhil Goyal }
30131f14d500SAkhil Goyal 
30141f14d500SAkhil Goyal /** Clear the memory of session so it doesn't leave key material behind */
30151f14d500SAkhil Goyal static int
30161f14d500SAkhil Goyal dpaa_sec_security_session_destroy(void *dev __rte_unused,
30171f14d500SAkhil Goyal 		struct rte_security_session *sess)
30181f14d500SAkhil Goyal {
30191f14d500SAkhil Goyal 	PMD_INIT_FUNC_TRACE();
30201f14d500SAkhil Goyal 	void *sess_priv = get_sec_session_private_data(sess);
30211f14d500SAkhil Goyal 	dpaa_sec_session *s = (dpaa_sec_session *)sess_priv;
30221f14d500SAkhil Goyal 
30231f14d500SAkhil Goyal 	if (sess_priv) {
30243d0d5332SAkhil Goyal 		free_session_memory((struct rte_cryptodev *)dev, s);
30251f14d500SAkhil Goyal 		set_sec_session_private_data(sess, NULL);
30261f14d500SAkhil Goyal 	}
30271f14d500SAkhil Goyal 	return 0;
30281f14d500SAkhil Goyal }
3029314424b6SHemant Agrawal #endif
30301f14d500SAkhil Goyal static int
30312ffb940eSAkhil Goyal dpaa_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3032c3e85bdcSAkhil Goyal 		       struct rte_cryptodev_config *config __rte_unused)
3033c3e85bdcSAkhil Goyal {
3034c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3035c3e85bdcSAkhil Goyal 
3036c3e85bdcSAkhil Goyal 	return 0;
3037c3e85bdcSAkhil Goyal }
3038c3e85bdcSAkhil Goyal 
3039c3e85bdcSAkhil Goyal static int
3040c3e85bdcSAkhil Goyal dpaa_sec_dev_start(struct rte_cryptodev *dev __rte_unused)
3041c3e85bdcSAkhil Goyal {
3042c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3043c3e85bdcSAkhil Goyal 	return 0;
3044c3e85bdcSAkhil Goyal }
3045c3e85bdcSAkhil Goyal 
3046c3e85bdcSAkhil Goyal static void
3047c3e85bdcSAkhil Goyal dpaa_sec_dev_stop(struct rte_cryptodev *dev __rte_unused)
3048c3e85bdcSAkhil Goyal {
3049c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3050c3e85bdcSAkhil Goyal }
3051c3e85bdcSAkhil Goyal 
3052c3e85bdcSAkhil Goyal static int
30537e3e2954SAkhil Goyal dpaa_sec_dev_close(struct rte_cryptodev *dev)
3054c3e85bdcSAkhil Goyal {
3055c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
30567e3e2954SAkhil Goyal 
30577e3e2954SAkhil Goyal 	if (dev == NULL)
30587e3e2954SAkhil Goyal 		return -ENOMEM;
30597e3e2954SAkhil Goyal 
3060c3e85bdcSAkhil Goyal 	return 0;
3061c3e85bdcSAkhil Goyal }
3062c3e85bdcSAkhil Goyal 
3063c3e85bdcSAkhil Goyal static void
3064c3e85bdcSAkhil Goyal dpaa_sec_dev_infos_get(struct rte_cryptodev *dev,
3065c3e85bdcSAkhil Goyal 		       struct rte_cryptodev_info *info)
3066c3e85bdcSAkhil Goyal {
3067c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals = dev->data->dev_private;
3068c3e85bdcSAkhil Goyal 
3069c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3070c3e85bdcSAkhil Goyal 	if (info != NULL) {
3071c3e85bdcSAkhil Goyal 		info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3072c3e85bdcSAkhil Goyal 		info->feature_flags = dev->feature_flags;
3073c3e85bdcSAkhil Goyal 		info->capabilities = dpaa_sec_capabilities;
3074c3e85bdcSAkhil Goyal 		info->sym.max_nb_sessions = internals->max_nb_sessions;
3075c3e85bdcSAkhil Goyal 		info->driver_id = cryptodev_driver_id;
3076c3e85bdcSAkhil Goyal 	}
3077c3e85bdcSAkhil Goyal }
3078c3e85bdcSAkhil Goyal 
3079fe3688baSAkhil Goyal static enum qman_cb_dqrr_result
3080fe3688baSAkhil Goyal dpaa_sec_process_parallel_event(void *event,
3081fe3688baSAkhil Goyal 			struct qman_portal *qm __always_unused,
3082fe3688baSAkhil Goyal 			struct qman_fq *outq,
3083fe3688baSAkhil Goyal 			const struct qm_dqrr_entry *dqrr,
3084fe3688baSAkhil Goyal 			void **bufs)
3085fe3688baSAkhil Goyal {
3086fe3688baSAkhil Goyal 	const struct qm_fd *fd;
3087fe3688baSAkhil Goyal 	struct dpaa_sec_job *job;
3088fe3688baSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
3089fe3688baSAkhil Goyal 	struct rte_event *ev = (struct rte_event *)event;
3090fe3688baSAkhil Goyal 
3091fe3688baSAkhil Goyal 	fd = &dqrr->fd;
3092fe3688baSAkhil Goyal 
3093fe3688baSAkhil Goyal 	/* sg is embedded in an op ctx,
3094fe3688baSAkhil Goyal 	 * sg[0] is for output
3095fe3688baSAkhil Goyal 	 * sg[1] for input
3096fe3688baSAkhil Goyal 	 */
3097ec861560SGagandeep Singh 	job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
3098fe3688baSAkhil Goyal 
3099fe3688baSAkhil Goyal 	ctx = container_of(job, struct dpaa_sec_op_ctx, job);
3100fe3688baSAkhil Goyal 	ctx->fd_status = fd->status;
3101fe3688baSAkhil Goyal 	if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
3102fe3688baSAkhil Goyal 		struct qm_sg_entry *sg_out;
3103fe3688baSAkhil Goyal 		uint32_t len;
3104fe3688baSAkhil Goyal 
3105fe3688baSAkhil Goyal 		sg_out = &job->sg[0];
3106fe3688baSAkhil Goyal 		hw_sg_to_cpu(sg_out);
3107fe3688baSAkhil Goyal 		len = sg_out->length;
3108fe3688baSAkhil Goyal 		ctx->op->sym->m_src->pkt_len = len;
3109fe3688baSAkhil Goyal 		ctx->op->sym->m_src->data_len = len;
3110fe3688baSAkhil Goyal 	}
3111fe3688baSAkhil Goyal 	if (!ctx->fd_status) {
3112fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
3113fe3688baSAkhil Goyal 	} else {
3114fe3688baSAkhil Goyal 		DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
3115fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
3116fe3688baSAkhil Goyal 	}
3117fe3688baSAkhil Goyal 	ev->event_ptr = (void *)ctx->op;
3118fe3688baSAkhil Goyal 
3119fe3688baSAkhil Goyal 	ev->flow_id = outq->ev.flow_id;
3120fe3688baSAkhil Goyal 	ev->sub_event_type = outq->ev.sub_event_type;
3121fe3688baSAkhil Goyal 	ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3122fe3688baSAkhil Goyal 	ev->op = RTE_EVENT_OP_NEW;
3123fe3688baSAkhil Goyal 	ev->sched_type = outq->ev.sched_type;
3124fe3688baSAkhil Goyal 	ev->queue_id = outq->ev.queue_id;
3125fe3688baSAkhil Goyal 	ev->priority = outq->ev.priority;
3126fe3688baSAkhil Goyal 	*bufs = (void *)ctx->op;
3127fe3688baSAkhil Goyal 
3128fe3688baSAkhil Goyal 	rte_mempool_put(ctx->ctx_pool, (void *)ctx);
3129fe3688baSAkhil Goyal 
3130fe3688baSAkhil Goyal 	return qman_cb_dqrr_consume;
3131fe3688baSAkhil Goyal }
3132fe3688baSAkhil Goyal 
3133fe3688baSAkhil Goyal static enum qman_cb_dqrr_result
3134fe3688baSAkhil Goyal dpaa_sec_process_atomic_event(void *event,
3135fe3688baSAkhil Goyal 			struct qman_portal *qm __rte_unused,
3136fe3688baSAkhil Goyal 			struct qman_fq *outq,
3137fe3688baSAkhil Goyal 			const struct qm_dqrr_entry *dqrr,
3138fe3688baSAkhil Goyal 			void **bufs)
3139fe3688baSAkhil Goyal {
3140fe3688baSAkhil Goyal 	u8 index;
3141fe3688baSAkhil Goyal 	const struct qm_fd *fd;
3142fe3688baSAkhil Goyal 	struct dpaa_sec_job *job;
3143fe3688baSAkhil Goyal 	struct dpaa_sec_op_ctx *ctx;
3144fe3688baSAkhil Goyal 	struct rte_event *ev = (struct rte_event *)event;
3145fe3688baSAkhil Goyal 
3146fe3688baSAkhil Goyal 	fd = &dqrr->fd;
3147fe3688baSAkhil Goyal 
3148fe3688baSAkhil Goyal 	/* sg is embedded in an op ctx,
3149fe3688baSAkhil Goyal 	 * sg[0] is for output
3150fe3688baSAkhil Goyal 	 * sg[1] for input
3151fe3688baSAkhil Goyal 	 */
3152ec861560SGagandeep Singh 	job = rte_dpaa_mem_ptov(qm_fd_addr_get64(fd));
3153fe3688baSAkhil Goyal 
3154fe3688baSAkhil Goyal 	ctx = container_of(job, struct dpaa_sec_op_ctx, job);
3155fe3688baSAkhil Goyal 	ctx->fd_status = fd->status;
3156fe3688baSAkhil Goyal 	if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
3157fe3688baSAkhil Goyal 		struct qm_sg_entry *sg_out;
3158fe3688baSAkhil Goyal 		uint32_t len;
3159fe3688baSAkhil Goyal 
3160fe3688baSAkhil Goyal 		sg_out = &job->sg[0];
3161fe3688baSAkhil Goyal 		hw_sg_to_cpu(sg_out);
3162fe3688baSAkhil Goyal 		len = sg_out->length;
3163fe3688baSAkhil Goyal 		ctx->op->sym->m_src->pkt_len = len;
3164fe3688baSAkhil Goyal 		ctx->op->sym->m_src->data_len = len;
3165fe3688baSAkhil Goyal 	}
3166fe3688baSAkhil Goyal 	if (!ctx->fd_status) {
3167fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
3168fe3688baSAkhil Goyal 	} else {
3169fe3688baSAkhil Goyal 		DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
3170fe3688baSAkhil Goyal 		ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
3171fe3688baSAkhil Goyal 	}
3172fe3688baSAkhil Goyal 	ev->event_ptr = (void *)ctx->op;
3173fe3688baSAkhil Goyal 	ev->flow_id = outq->ev.flow_id;
3174fe3688baSAkhil Goyal 	ev->sub_event_type = outq->ev.sub_event_type;
3175fe3688baSAkhil Goyal 	ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3176fe3688baSAkhil Goyal 	ev->op = RTE_EVENT_OP_NEW;
3177fe3688baSAkhil Goyal 	ev->sched_type = outq->ev.sched_type;
3178fe3688baSAkhil Goyal 	ev->queue_id = outq->ev.queue_id;
3179fe3688baSAkhil Goyal 	ev->priority = outq->ev.priority;
3180fe3688baSAkhil Goyal 
3181fe3688baSAkhil Goyal 	/* Save active dqrr entries */
3182fe3688baSAkhil Goyal 	index = ((uintptr_t)dqrr >> 6) & (16/*QM_DQRR_SIZE*/ - 1);
3183fe3688baSAkhil Goyal 	DPAA_PER_LCORE_DQRR_SIZE++;
3184fe3688baSAkhil Goyal 	DPAA_PER_LCORE_DQRR_HELD |= 1 << index;
3185fe3688baSAkhil Goyal 	DPAA_PER_LCORE_DQRR_MBUF(index) = ctx->op->sym->m_src;
3186fe3688baSAkhil Goyal 	ev->impl_opaque = index + 1;
3187fe3688baSAkhil Goyal 	ctx->op->sym->m_src->seqn = (uint32_t)index + 1;
3188fe3688baSAkhil Goyal 	*bufs = (void *)ctx->op;
3189fe3688baSAkhil Goyal 
3190fe3688baSAkhil Goyal 	rte_mempool_put(ctx->ctx_pool, (void *)ctx);
3191fe3688baSAkhil Goyal 
3192fe3688baSAkhil Goyal 	return qman_cb_dqrr_defer;
3193fe3688baSAkhil Goyal }
3194fe3688baSAkhil Goyal 
3195fe3688baSAkhil Goyal int
3196fe3688baSAkhil Goyal dpaa_sec_eventq_attach(const struct rte_cryptodev *dev,
3197fe3688baSAkhil Goyal 		int qp_id,
3198fe3688baSAkhil Goyal 		uint16_t ch_id,
3199fe3688baSAkhil Goyal 		const struct rte_event *event)
3200fe3688baSAkhil Goyal {
3201fe3688baSAkhil Goyal 	struct dpaa_sec_qp *qp = dev->data->queue_pairs[qp_id];
3202fe3688baSAkhil Goyal 	struct qm_mcc_initfq opts = {0};
3203fe3688baSAkhil Goyal 
3204fe3688baSAkhil Goyal 	int ret;
3205fe3688baSAkhil Goyal 
3206fe3688baSAkhil Goyal 	opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
3207fe3688baSAkhil Goyal 		       QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
3208fe3688baSAkhil Goyal 	opts.fqd.dest.channel = ch_id;
3209fe3688baSAkhil Goyal 
3210fe3688baSAkhil Goyal 	switch (event->sched_type) {
3211fe3688baSAkhil Goyal 	case RTE_SCHED_TYPE_ATOMIC:
3212fe3688baSAkhil Goyal 		opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE;
3213fe3688baSAkhil Goyal 		/* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary
3214fe3688baSAkhil Goyal 		 * configuration with HOLD_ACTIVE setting
3215fe3688baSAkhil Goyal 		 */
3216fe3688baSAkhil Goyal 		opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK);
3217fe3688baSAkhil Goyal 		qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_atomic_event;
3218fe3688baSAkhil Goyal 		break;
3219fe3688baSAkhil Goyal 	case RTE_SCHED_TYPE_ORDERED:
3220fe3688baSAkhil Goyal 		DPAA_SEC_ERR("Ordered queue schedule type is not supported\n");
3221c08ced9aSAkhil Goyal 		return -ENOTSUP;
3222fe3688baSAkhil Goyal 	default:
3223fe3688baSAkhil Goyal 		opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
3224fe3688baSAkhil Goyal 		qp->outq.cb.dqrr_dpdk_cb = dpaa_sec_process_parallel_event;
3225fe3688baSAkhil Goyal 		break;
3226fe3688baSAkhil Goyal 	}
3227fe3688baSAkhil Goyal 
3228fe3688baSAkhil Goyal 	ret = qman_init_fq(&qp->outq, QMAN_INITFQ_FLAG_SCHED, &opts);
3229fe3688baSAkhil Goyal 	if (unlikely(ret)) {
3230fe3688baSAkhil Goyal 		DPAA_SEC_ERR("unable to init caam source fq!");
3231fe3688baSAkhil Goyal 		return ret;
3232fe3688baSAkhil Goyal 	}
3233fe3688baSAkhil Goyal 
3234fe3688baSAkhil Goyal 	memcpy(&qp->outq.ev, event, sizeof(struct rte_event));
3235fe3688baSAkhil Goyal 
3236fe3688baSAkhil Goyal 	return 0;
3237fe3688baSAkhil Goyal }
3238fe3688baSAkhil Goyal 
3239fe3688baSAkhil Goyal int
3240fe3688baSAkhil Goyal dpaa_sec_eventq_detach(const struct rte_cryptodev *dev,
3241fe3688baSAkhil Goyal 			int qp_id)
3242fe3688baSAkhil Goyal {
3243fe3688baSAkhil Goyal 	struct qm_mcc_initfq opts = {0};
3244fe3688baSAkhil Goyal 	int ret;
3245fe3688baSAkhil Goyal 	struct dpaa_sec_qp *qp = dev->data->queue_pairs[qp_id];
3246fe3688baSAkhil Goyal 
3247fe3688baSAkhil Goyal 	opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
3248fe3688baSAkhil Goyal 		       QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
3249fe3688baSAkhil Goyal 	qp->outq.cb.dqrr = dqrr_out_fq_cb_rx;
3250fe3688baSAkhil Goyal 	qp->outq.cb.ern  = ern_sec_fq_handler;
3251fe3688baSAkhil Goyal 	qman_retire_fq(&qp->outq, NULL);
3252fe3688baSAkhil Goyal 	qman_oos_fq(&qp->outq);
3253fe3688baSAkhil Goyal 	ret = qman_init_fq(&qp->outq, 0, &opts);
3254fe3688baSAkhil Goyal 	if (ret)
3255fe3688baSAkhil Goyal 		RTE_LOG(ERR, PMD, "Error in qman_init_fq: ret: %d\n", ret);
3256fe3688baSAkhil Goyal 	qp->outq.cb.dqrr = NULL;
3257fe3688baSAkhil Goyal 
3258fe3688baSAkhil Goyal 	return ret;
3259fe3688baSAkhil Goyal }
3260fe3688baSAkhil Goyal 
3261c3e85bdcSAkhil Goyal static struct rte_cryptodev_ops crypto_ops = {
3262c3e85bdcSAkhil Goyal 	.dev_configure	      = dpaa_sec_dev_configure,
3263c3e85bdcSAkhil Goyal 	.dev_start	      = dpaa_sec_dev_start,
3264c3e85bdcSAkhil Goyal 	.dev_stop	      = dpaa_sec_dev_stop,
3265c3e85bdcSAkhil Goyal 	.dev_close	      = dpaa_sec_dev_close,
3266c3e85bdcSAkhil Goyal 	.dev_infos_get        = dpaa_sec_dev_infos_get,
3267c3e85bdcSAkhil Goyal 	.queue_pair_setup     = dpaa_sec_queue_pair_setup,
3268c3e85bdcSAkhil Goyal 	.queue_pair_release   = dpaa_sec_queue_pair_release,
3269012c5076SPablo de Lara 	.sym_session_get_size     = dpaa_sec_sym_session_get_size,
3270012c5076SPablo de Lara 	.sym_session_configure    = dpaa_sec_sym_session_configure,
3271012c5076SPablo de Lara 	.sym_session_clear        = dpaa_sec_sym_session_clear
3272c3e85bdcSAkhil Goyal };
3273c3e85bdcSAkhil Goyal 
3274314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
32751f14d500SAkhil Goyal static const struct rte_security_capability *
32761f14d500SAkhil Goyal dpaa_sec_capabilities_get(void *device __rte_unused)
32771f14d500SAkhil Goyal {
32781f14d500SAkhil Goyal 	return dpaa_sec_security_cap;
32791f14d500SAkhil Goyal }
32801f14d500SAkhil Goyal 
3281b74fd6b8SFerruh Yigit static const struct rte_security_ops dpaa_sec_security_ops = {
32821f14d500SAkhil Goyal 	.session_create = dpaa_sec_security_session_create,
32831f14d500SAkhil Goyal 	.session_update = NULL,
32841f14d500SAkhil Goyal 	.session_stats_get = NULL,
32851f14d500SAkhil Goyal 	.session_destroy = dpaa_sec_security_session_destroy,
32861f14d500SAkhil Goyal 	.set_pkt_metadata = NULL,
32871f14d500SAkhil Goyal 	.capabilities_get = dpaa_sec_capabilities_get
32881f14d500SAkhil Goyal };
3289314424b6SHemant Agrawal #endif
3290c3e85bdcSAkhil Goyal static int
3291c3e85bdcSAkhil Goyal dpaa_sec_uninit(struct rte_cryptodev *dev)
3292c3e85bdcSAkhil Goyal {
3293debef417SShreyansh Jain 	struct dpaa_sec_dev_private *internals;
3294c3e85bdcSAkhil Goyal 
3295c3e85bdcSAkhil Goyal 	if (dev == NULL)
3296c3e85bdcSAkhil Goyal 		return -ENODEV;
3297c3e85bdcSAkhil Goyal 
3298debef417SShreyansh Jain 	internals = dev->data->dev_private;
32991f14d500SAkhil Goyal 	rte_free(dev->security_ctx);
33001f14d500SAkhil Goyal 
3301c3e85bdcSAkhil Goyal 	rte_free(internals);
3302c3e85bdcSAkhil Goyal 
3303f163231eSHemant Agrawal 	DPAA_SEC_INFO("Closing DPAA_SEC device %s on numa socket %u",
3304c3e85bdcSAkhil Goyal 		      dev->data->name, rte_socket_id());
3305c3e85bdcSAkhil Goyal 
3306c3e85bdcSAkhil Goyal 	return 0;
3307c3e85bdcSAkhil Goyal }
3308c3e85bdcSAkhil Goyal 
3309c3e85bdcSAkhil Goyal static int
3310c3e85bdcSAkhil Goyal dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
3311c3e85bdcSAkhil Goyal {
3312c3e85bdcSAkhil Goyal 	struct dpaa_sec_dev_private *internals;
3313314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
33141f14d500SAkhil Goyal 	struct rte_security_ctx *security_instance;
3315314424b6SHemant Agrawal #endif
3316c3e85bdcSAkhil Goyal 	struct dpaa_sec_qp *qp;
3317e79416d1SHemant Agrawal 	uint32_t i, flags;
3318c3e85bdcSAkhil Goyal 	int ret;
3319c3e85bdcSAkhil Goyal 
3320c3e85bdcSAkhil Goyal 	PMD_INIT_FUNC_TRACE();
3321c3e85bdcSAkhil Goyal 
3322c3e85bdcSAkhil Goyal 	cryptodev->driver_id = cryptodev_driver_id;
3323c3e85bdcSAkhil Goyal 	cryptodev->dev_ops = &crypto_ops;
3324c3e85bdcSAkhil Goyal 
3325c3e85bdcSAkhil Goyal 	cryptodev->enqueue_burst = dpaa_sec_enqueue_burst;
3326c3e85bdcSAkhil Goyal 	cryptodev->dequeue_burst = dpaa_sec_dequeue_burst;
3327c3e85bdcSAkhil Goyal 	cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3328c3e85bdcSAkhil Goyal 			RTE_CRYPTODEV_FF_HW_ACCELERATED |
33291f14d500SAkhil Goyal 			RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3330a74af788SAkhil Goyal 			RTE_CRYPTODEV_FF_SECURITY |
33312717246eSPablo de Lara 			RTE_CRYPTODEV_FF_IN_PLACE_SGL |
33322717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
33332717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
33342717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
33352717246eSPablo de Lara 			RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3336c3e85bdcSAkhil Goyal 
3337c3e85bdcSAkhil Goyal 	internals = cryptodev->data->dev_private;
3338e79416d1SHemant Agrawal 	internals->max_nb_queue_pairs = RTE_DPAA_MAX_NB_SEC_QPS;
3339c3e85bdcSAkhil Goyal 	internals->max_nb_sessions = RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS;
3340c3e85bdcSAkhil Goyal 
33411f14d500SAkhil Goyal 	/*
33421f14d500SAkhil Goyal 	 * For secondary processes, we don't initialise any further as primary
33431f14d500SAkhil Goyal 	 * has already done this work. Only check we don't need a different
33441f14d500SAkhil Goyal 	 * RX function
33451f14d500SAkhil Goyal 	 */
33461f14d500SAkhil Goyal 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3347f163231eSHemant Agrawal 		DPAA_SEC_WARN("Device already init by primary process");
33481f14d500SAkhil Goyal 		return 0;
33491f14d500SAkhil Goyal 	}
3350314424b6SHemant Agrawal #ifdef RTE_LIBRTE_SECURITY
33511f14d500SAkhil Goyal 	/* Initialize security_ctx only for primary process*/
33521f14d500SAkhil Goyal 	security_instance = rte_malloc("rte_security_instances_ops",
33531f14d500SAkhil Goyal 				sizeof(struct rte_security_ctx), 0);
33541f14d500SAkhil Goyal 	if (security_instance == NULL)
33551f14d500SAkhil Goyal 		return -ENOMEM;
33561f14d500SAkhil Goyal 	security_instance->device = (void *)cryptodev;
33571f14d500SAkhil Goyal 	security_instance->ops = &dpaa_sec_security_ops;
33581f14d500SAkhil Goyal 	security_instance->sess_cnt = 0;
33591f14d500SAkhil Goyal 	cryptodev->security_ctx = security_instance;
3360314424b6SHemant Agrawal #endif
33613b617ee7SAkhil Goyal 	rte_spinlock_init(&internals->lock);
3362c3e85bdcSAkhil Goyal 	for (i = 0; i < internals->max_nb_queue_pairs; i++) {
3363c3e85bdcSAkhil Goyal 		/* init qman fq for queue pair */
3364c3e85bdcSAkhil Goyal 		qp = &internals->qps[i];
3365c3e85bdcSAkhil Goyal 		ret = dpaa_sec_init_tx(&qp->outq);
3366c3e85bdcSAkhil Goyal 		if (ret) {
3367f163231eSHemant Agrawal 			DPAA_SEC_ERR("config tx of queue pair  %d", i);
3368c3e85bdcSAkhil Goyal 			goto init_error;
3369c3e85bdcSAkhil Goyal 		}
3370e79416d1SHemant Agrawal 	}
3371e79416d1SHemant Agrawal 
3372e79416d1SHemant Agrawal 	flags = QMAN_FQ_FLAG_LOCKED | QMAN_FQ_FLAG_DYNAMIC_FQID |
3373e79416d1SHemant Agrawal 		QMAN_FQ_FLAG_TO_DCPORTAL;
3374fd900d38SGagandeep Singh 	for (i = 0; i < RTE_DPAA_MAX_RX_QUEUE; i++) {
3375e79416d1SHemant Agrawal 		/* create rx qman fq for sessions*/
3376e79416d1SHemant Agrawal 		ret = qman_create_fq(0, flags, &internals->inq[i]);
3377e79416d1SHemant Agrawal 		if (unlikely(ret != 0)) {
3378f163231eSHemant Agrawal 			DPAA_SEC_ERR("sec qman_create_fq failed");
3379c3e85bdcSAkhil Goyal 			goto init_error;
3380c3e85bdcSAkhil Goyal 		}
3381c3e85bdcSAkhil Goyal 	}
3382c3e85bdcSAkhil Goyal 
3383f163231eSHemant Agrawal 	RTE_LOG(INFO, PMD, "%s cryptodev init\n", cryptodev->data->name);
3384c3e85bdcSAkhil Goyal 	return 0;
3385c3e85bdcSAkhil Goyal 
3386c3e85bdcSAkhil Goyal init_error:
3387f163231eSHemant Agrawal 	DPAA_SEC_ERR("driver %s: create failed\n", cryptodev->data->name);
3388c3e85bdcSAkhil Goyal 
33892eaf352dSLukasz Wojciechowski 	rte_free(cryptodev->security_ctx);
3390c3e85bdcSAkhil Goyal 	return -EFAULT;
3391c3e85bdcSAkhil Goyal }
3392c3e85bdcSAkhil Goyal 
3393c3e85bdcSAkhil Goyal static int
3394eb5a9a76SShreyansh Jain cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
3395c3e85bdcSAkhil Goyal 				struct rte_dpaa_device *dpaa_dev)
3396c3e85bdcSAkhil Goyal {
3397c3e85bdcSAkhil Goyal 	struct rte_cryptodev *cryptodev;
3398c3e85bdcSAkhil Goyal 	char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3399c3e85bdcSAkhil Goyal 
3400c3e85bdcSAkhil Goyal 	int retval;
3401c3e85bdcSAkhil Goyal 
34020964a951SHemant Agrawal 	snprintf(cryptodev_name, sizeof(cryptodev_name), "%s", dpaa_dev->name);
3403c3e85bdcSAkhil Goyal 
3404c3e85bdcSAkhil Goyal 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3405c3e85bdcSAkhil Goyal 	if (cryptodev == NULL)
3406c3e85bdcSAkhil Goyal 		return -ENOMEM;
3407c3e85bdcSAkhil Goyal 
3408c3e85bdcSAkhil Goyal 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3409c3e85bdcSAkhil Goyal 		cryptodev->data->dev_private = rte_zmalloc_socket(
3410c3e85bdcSAkhil Goyal 					"cryptodev private structure",
3411c3e85bdcSAkhil Goyal 					sizeof(struct dpaa_sec_dev_private),
3412c3e85bdcSAkhil Goyal 					RTE_CACHE_LINE_SIZE,
3413c3e85bdcSAkhil Goyal 					rte_socket_id());
3414c3e85bdcSAkhil Goyal 
3415c3e85bdcSAkhil Goyal 		if (cryptodev->data->dev_private == NULL)
3416c3e85bdcSAkhil Goyal 			rte_panic("Cannot allocate memzone for private "
3417c3e85bdcSAkhil Goyal 					"device data");
3418c3e85bdcSAkhil Goyal 	}
3419c3e85bdcSAkhil Goyal 
3420c3e85bdcSAkhil Goyal 	dpaa_dev->crypto_dev = cryptodev;
3421c3e85bdcSAkhil Goyal 	cryptodev->device = &dpaa_dev->device;
3422c3e85bdcSAkhil Goyal 
3423c3e85bdcSAkhil Goyal 	/* init user callbacks */
3424c3e85bdcSAkhil Goyal 	TAILQ_INIT(&(cryptodev->link_intr_cbs));
3425c3e85bdcSAkhil Goyal 
3426c3e85bdcSAkhil Goyal 	/* if sec device version is not configured */
3427c3e85bdcSAkhil Goyal 	if (!rta_get_sec_era()) {
3428c3e85bdcSAkhil Goyal 		const struct device_node *caam_node;
3429c3e85bdcSAkhil Goyal 
3430c3e85bdcSAkhil Goyal 		for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
3431c3e85bdcSAkhil Goyal 			const uint32_t *prop = of_get_property(caam_node,
3432c3e85bdcSAkhil Goyal 					"fsl,sec-era",
3433c3e85bdcSAkhil Goyal 					NULL);
3434c3e85bdcSAkhil Goyal 			if (prop) {
3435c3e85bdcSAkhil Goyal 				rta_set_sec_era(
3436c3e85bdcSAkhil Goyal 					INTL_SEC_ERA(rte_cpu_to_be_32(*prop)));
3437c3e85bdcSAkhil Goyal 				break;
3438c3e85bdcSAkhil Goyal 			}
3439c3e85bdcSAkhil Goyal 		}
3440c3e85bdcSAkhil Goyal 	}
3441c3e85bdcSAkhil Goyal 
3442*e5872221SRohit Raj 	if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
3443408077f2SHemant Agrawal 		retval = rte_dpaa_portal_init((void *)1);
3444408077f2SHemant Agrawal 		if (retval) {
3445408077f2SHemant Agrawal 			DPAA_SEC_ERR("Unable to initialize portal");
34462eaf352dSLukasz Wojciechowski 			goto out;
3447408077f2SHemant Agrawal 		}
3448408077f2SHemant Agrawal 	}
3449408077f2SHemant Agrawal 
3450c3e85bdcSAkhil Goyal 	/* Invoke PMD device initialization function */
3451c3e85bdcSAkhil Goyal 	retval = dpaa_sec_dev_init(cryptodev);
3452c3e85bdcSAkhil Goyal 	if (retval == 0)
3453c3e85bdcSAkhil Goyal 		return 0;
3454c3e85bdcSAkhil Goyal 
34552eaf352dSLukasz Wojciechowski 	retval = -ENXIO;
34562eaf352dSLukasz Wojciechowski out:
3457c3e85bdcSAkhil Goyal 	/* In case of error, cleanup is done */
3458c3e85bdcSAkhil Goyal 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3459c3e85bdcSAkhil Goyal 		rte_free(cryptodev->data->dev_private);
3460c3e85bdcSAkhil Goyal 
3461c3e85bdcSAkhil Goyal 	rte_cryptodev_pmd_release_device(cryptodev);
3462c3e85bdcSAkhil Goyal 
34632eaf352dSLukasz Wojciechowski 	return retval;
3464c3e85bdcSAkhil Goyal }
3465c3e85bdcSAkhil Goyal 
3466c3e85bdcSAkhil Goyal static int
3467c3e85bdcSAkhil Goyal cryptodev_dpaa_sec_remove(struct rte_dpaa_device *dpaa_dev)
3468c3e85bdcSAkhil Goyal {
3469c3e85bdcSAkhil Goyal 	struct rte_cryptodev *cryptodev;
3470c3e85bdcSAkhil Goyal 	int ret;
3471c3e85bdcSAkhil Goyal 
3472c3e85bdcSAkhil Goyal 	cryptodev = dpaa_dev->crypto_dev;
3473c3e85bdcSAkhil Goyal 	if (cryptodev == NULL)
3474c3e85bdcSAkhil Goyal 		return -ENODEV;
3475c3e85bdcSAkhil Goyal 
3476c3e85bdcSAkhil Goyal 	ret = dpaa_sec_uninit(cryptodev);
3477c3e85bdcSAkhil Goyal 	if (ret)
3478c3e85bdcSAkhil Goyal 		return ret;
3479c3e85bdcSAkhil Goyal 
3480f2f020d2SDeclan Doherty 	return rte_cryptodev_pmd_destroy(cryptodev);
3481c3e85bdcSAkhil Goyal }
3482c3e85bdcSAkhil Goyal 
3483c3e85bdcSAkhil Goyal static struct rte_dpaa_driver rte_dpaa_sec_driver = {
3484c3e85bdcSAkhil Goyal 	.drv_type = FSL_DPAA_CRYPTO,
3485c3e85bdcSAkhil Goyal 	.driver = {
3486c3e85bdcSAkhil Goyal 		.name = "DPAA SEC PMD"
3487c3e85bdcSAkhil Goyal 	},
3488c3e85bdcSAkhil Goyal 	.probe = cryptodev_dpaa_sec_probe,
3489c3e85bdcSAkhil Goyal 	.remove = cryptodev_dpaa_sec_remove,
3490c3e85bdcSAkhil Goyal };
3491c3e85bdcSAkhil Goyal 
3492c3e85bdcSAkhil Goyal static struct cryptodev_driver dpaa_sec_crypto_drv;
3493c3e85bdcSAkhil Goyal 
3494c3e85bdcSAkhil Goyal RTE_PMD_REGISTER_DPAA(CRYPTODEV_NAME_DPAA_SEC_PMD, rte_dpaa_sec_driver);
3495f737f5ceSFiona Trahe RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa_sec_crypto_drv, rte_dpaa_sec_driver.driver,
3496c3e85bdcSAkhil Goyal 		cryptodev_driver_id);
34979c99878aSJerin Jacob RTE_LOG_REGISTER(dpaa_logtype_sec, pmd.crypto.dpaa, NOTICE);
3498